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
|
|---|---|---|---|---|---|---|---|---|
wmpluto/esp-idf
|
components/idf_test/integration_test/TestCaseScript/UDPStress/UDPThroughput.py
|
15
|
12108
|
import os
import time
import random
import threading
import socket
from TCAction import TCActionBase
from NativeLog import NativeLog
from NativeLog import ThroughputResult
from Utility import RSSICalibrator
from Utility import MakeFolder
LOG_FOLDER = os.path.join("Performance", "Throughput")
AP_PROP_KEY = ("ssid", "password", "apc")
class SendThread(threading.Thread):
def __init__(self, sock, send_len, target_addr):
threading.Thread.__init__(self)
self.setDaemon(True)
self.sock = sock
self.send_len = send_len
self.target_addr = target_addr
self.exit_event = threading.Event()
pass
def exit(self):
self.exit_event.set()
def run(self):
data = "A" * self.send_len
if self.sock is None:
return
while True:
if self.exit_event.isSet() is True:
break
try:
self.sock.sendto(data, self.target_addr)
except StandardError:
break
pass
class RecvThread(threading.Thread):
def __init__(self, sock):
threading.Thread.__init__(self)
self.setDaemon(True)
self.sock = sock
self.exit_event = threading.Event()
self.calc_event = threading.Event()
self.bytes_recv = 0
def start_calc(self):
self.calc_event.set()
def stop_calc(self):
self.calc_event.clear()
self.exit_event.set()
def run(self):
if self.sock is None:
return
while True:
if self.exit_event.isSet() is True:
break
try:
data, addr = self.sock.recvfrom(65535)
except StandardError:
break
if self.calc_event.isSet() is True:
self.bytes_recv += len(data)
def get_bytes_recv(self):
return self.bytes_recv
pass
class TestCase(TCActionBase.CommonTCActionBase):
def __init__(self, test_case, test_env, timeout=30, log_path=TCActionBase.LOG_PATH):
TCActionBase.CommonTCActionBase.__init__(self, test_case, test_env, timeout=timeout, log_path=log_path)
self.performance_folder_path = log_path
self.att_test_list = range(60)
# load param from excel
cmd_set = test_case["cmd set"]
for i in range(1, len(cmd_set)):
if cmd_set[i][0] != "dummy":
cmd_string = "self." + cmd_set[i][0]
exec cmd_string
self.result_cntx = TCActionBase.ResultCheckContext(self, test_env, self.tc_name)
pass
def execute(self):
TCActionBase.TCActionBase.execute(self)
self.result_cntx.start()
try:
# configurable params
ap_list = self.get_parameter("shield_box_ap_list")
pc_ip = self.get_parameter("pc_ip")
send_len = self.send_len
att_test_list = self.att_test_list
tx_enable = self.tx_enable
rx_enable = self.rx_enable
measure_period = self.measure_period
# configurable params
except StandardError, e:
NativeLog.add_trace_critical("Error configuration for TCPThroughput script, error is %s" % e)
raise StandardError("Error configuration")
udp_port = random.randint(40000, 50000)
# init throughput result data
test_item = ""
if tx_enable is True:
test_item += "Tx"
if rx_enable is True:
test_item += "Rx"
if test_item == "":
raise StandardError("no throughput test item")
folder_path = os.path.join(self.performance_folder_path, LOG_FOLDER)
file_name = os.path.join(folder_path,
"UDPThroughput_%s_%s" % (test_item, time.strftime("%d%H%M%S", time.localtime())))
result = ThroughputResult.ThroughputResult(file_name)
# restart before executing throughput
checker_stings = ["R SSC1 C !!!ready!!!"]
test_action_string = ["SSC SSC1 reboot"]
fail_string = "Fail, Fail to reboot"
if self.load_and_exe_one_step(checker_stings, test_action_string, fail_string) is False:
self.result_cntx.set_result("Fail")
return
# disable recv print during throughput test
checker_stings = ["R SSC1 C +RECVPRINT"]
test_action_string = ["SSC SSC1 soc -R -o 0"]
fail_string = "Fail, Fail to disable recv print"
if self.load_and_exe_one_step(checker_stings, test_action_string, fail_string) is False:
self.result_cntx.set_result("Fail")
return
ret = True
for ap_prop in ap_list:
ssid = ap_prop[0]
password = ap_prop[1]
apc = ap_prop[2]
if ap_prop[1] == "":
# set a default string for open ap
password = "1"
# switch off all outlet, switch on AP outlet
outlet_config_dict = dict.fromkeys(range(1, 9), "OFF")
outlet_config_dict[apc] = "ON"
apc_cmd = "APC <APC1>"
for outlet in outlet_config_dict:
apc_cmd += " %s %s" % (outlet_config_dict[outlet], outlet)
checker_stings = ["P PC_COM L OK"]
fail_string = "Fail, Fail to switch apc"
if self.load_and_exe_one_step(checker_stings, [apc_cmd], fail_string) is False:
ret = False
break
# wait AP ready
time.sleep(20)
# create server
udp_sock = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)
udp_sock.bind((pc_ip, udp_port))
udp_sock.settimeout(1)
if tx_enable is True:
result.add_test_item(ssid + "_tx")
if rx_enable is True:
result.add_test_item(ssid + "_rx")
# create RSSI Calibrator
calibrator = RSSICalibrator.Calibrator()
for att_value in att_test_list:
# step 0 set att value
checker_stings = ["R PC_COM L OK"]
test_action_string = ["ATT <att_port> %s" % att_value]
fail_string = "Fail, Fail to set att value"
if self.load_and_exe_one_step(checker_stings, test_action_string, fail_string) is False:
ret = False
break
# continue
# step 1 get AP RSSI
checker_stings = ["R SSC1 A <rssi>:\+SCAN:%s,[:\d\w]+,\d+,\d+,([-\d]+)\r" % ssid]
test_action_string = ["SSC SSC1 sta -S -s %s" % ssid]
fail_string = "Fail, Fail to scan"
rssi = scan_count = 0
for i in range(3):
if self.load_and_exe_one_step(checker_stings, test_action_string, fail_string) is False:
continue
rssi += int(self.test_env.get_variable_by_name("rssi")[1])
scan_count += 1
rssi = calibrator.calibrate_rssi(float(rssi)/scan_count if scan_count > 0 else 0, att_value)
# step 2 connect to AP
checker_stings = ["R SSC1 C +JAP:CONNECTED"]
test_action_string = ["SSC SSC1 sta -C -s %s -p %s" % (ssid, password)]
fail_string = "Fail, Fail to JAP"
if self.load_and_exe_one_step(checker_stings, test_action_string, fail_string,
check_freq=1, check_time=30) is False:
if rssi < -89:
continue
else:
ret = False
break
# continue
checker_stings = ["R SSC1 A <target_ip>:STAIP:(\d+\.\d+\.\d+\.\d+)"]
test_action_string = ["SSC SSC1 ip -Q"]
fail_string = "Fail, Fail to get ip"
if self.load_and_exe_one_step(checker_stings, test_action_string, fail_string,
check_freq=1, check_time=30) is False:
if rssi < -89:
continue
else:
ret = False
break
# continue
target_ip = self.get_parameter("target_ip")
# step 3 close all connections
checker_stings = ["R SSC1 C +CLOSEALL"]
test_action_string = ["SSC SSC1 soc -T"]
fail_string = "Fail, Fail to close socket"
if self.load_and_exe_one_step(checker_stings, test_action_string, fail_string) is False:
ret = False
break
# continue
# step 4 create UDP socket
checker_stings = ["R SSC1 A <client_sock>:\+BIND:(\d+),OK"]
test_action_string = ["SSC SSC1 soc -B -t UDP -i %s -p %s" % (target_ip, udp_port)]
fail_string = "Fail, Fail to bind"
if self.load_and_exe_one_step(checker_stings, test_action_string, fail_string) is False:
ret = False
break
# continue
# step 5 do throughput test
send_thread = SendThread(udp_sock if rx_enable is True else None,
send_len, (target_ip, udp_port))
send_thread.start()
recv_thread = RecvThread(udp_sock if tx_enable is True else None)
recv_thread.start()
if tx_enable is True:
# do send from target
test_action_string = ["SSC SSC1 soc -S -s <client_sock> -l %s -n 10000000 -i %s -p %s"
% (send_len, pc_ip, udp_port)]
fail_string = "Fail, Fail to send"
if self.load_and_exe_one_step([], test_action_string, fail_string) is False:
pass
# start throughput calculate
recv_thread.start_calc()
# sleep for measure period
time.sleep(measure_period)
# stop throughput calculate
recv_thread.stop_calc()
send_thread.exit()
send_thread.join()
recv_thread.join()
# output throughput result
# in Mbps
if rx_enable is True:
# get received data len from PC
self.load_and_exe_one_step(["R SSC1 A <recv_len>:RECVLEN:(\d+)"],
["SSC SSC1 soc -Q -s <client_sock> -o 1"],
"Fail, Fail to get recv data len")
try:
rx_data_len = int(self.get_parameter("recv_len"))
except StandardError:
rx_data_len = 0
result.log_throughput(ssid + "_rx", rssi, att_value,
float(rx_data_len * 8) / (measure_period * 1000000))
if recv_thread.get_bytes_recv() > 0:
result.log_throughput(ssid + "_tx", rssi, att_value,
float(recv_thread.get_bytes_recv() * 8) / (measure_period * 1000000))
result.output_to_file()
pass
udp_sock.close()
if not ret:
NativeLog.add_trace_critical("Test SUC for %s" % ssid)
elif ret:
NativeLog.add_trace_critical("Test FAIL for %s!!!" % ssid)
if ret:
self.result_cntx.set_result("Succeed")
else:
self.result_cntx.set_result("Fail")
# finally, execute done
def result_check(self, port_name, data):
TCActionBase.CommonTCActionBase.result_check(self, port_name, data)
self.result_cntx.append_data(port_name, data)
def main():
pass
if __name__ == '__main__':
main()
|
apache-2.0
|
[
646,
747,
199,
646,
900,
199,
646,
2196,
199,
646,
5796,
199,
646,
2838,
199,
199,
504,
377,
3263,
414,
492,
377,
3263,
414,
1563,
199,
504,
653,
1905,
2445,
492,
653,
1905,
2445,
199,
504,
653,
1905,
2445,
492,
3868,
3202,
524,
2889,
199,
504,
20511,
492,
30331,
948,
25530,
9043,
199,
504,
20511,
492,
4155,
7850,
421,
199,
4947,
63,
19041,
275,
747,
14,
515,
14,
904,
480,
25635,
401,
298,
26732,
524,
531,
421,
199,
1282,
63,
19926,
63,
3078,
275,
1689,
23283,
401,
298,
2060,
401,
298,
439,
67,
531,
421,
199,
533,
10217,
4436,
8,
12562,
14,
4436,
304,
272,
347,
636,
826,
721,
277,
12,
6771,
12,
3222,
63,
552,
12,
1347,
63,
2697,
304,
267,
5796,
14,
4436,
855,
826,
721,
277,
9,
267,
291,
14,
409,
20555,
8,
549,
9,
267,
291,
14,
5096,
275,
6771,
267,
291,
14,
2254,
63,
552,
275,
3222,
63,
552,
267,
291,
14,
1375,
63,
2697,
275,
1347,
63,
2697,
267,
291,
14,
2224,
63,
1430,
275,
5796,
14,
2390,
342,
267,
986,
339,
347,
4458,
8,
277,
304,
267,
291,
14,
2224,
63,
1430,
14,
409,
342,
339,
347,
1255,
8,
277,
304,
267,
666,
275,
298,
33,
2,
627,
291,
14,
2254,
63,
552,
267,
340,
291,
14,
5096,
365,
488,
26,
288,
372,
267,
1830,
715,
26,
288,
340,
291,
14,
2224,
63,
1430,
14,
374,
1084,
342,
365,
715,
26,
355,
2059,
288,
862,
26,
355,
291,
14,
5096,
14,
23267,
8,
576,
12,
291,
14,
1375,
63,
2697,
9,
288,
871,
29912,
26,
355,
2059,
272,
986,
421,
199,
533,
799,
5107,
4436,
8,
12562,
14,
4436,
304,
272,
347,
636,
826,
721,
277,
12,
6771,
304,
267,
5796,
14,
4436,
855,
826,
721,
277,
9,
267,
291,
14,
409,
20555,
8,
549,
9,
267,
291,
14,
5096,
275,
6771,
267,
291,
14,
2224,
63,
1430,
275,
5796,
14,
2390,
342,
267,
291,
14,
8104,
63,
1430,
275,
5796,
14,
2390,
342,
267,
291,
14,
2394,
63,
7637,
275,
378,
339,
347,
1343,
63,
8104,
8,
277,
304,
267,
291,
14,
8104,
63,
1430,
14,
409,
342,
339,
347,
3631,
63,
8104,
8,
277,
304,
267,
291,
14,
8104,
63,
1430,
14,
3584,
342,
267,
291,
14,
2224,
63,
1430,
14,
409,
342,
339,
347,
1255,
8,
277,
304,
267,
340,
291,
14,
5096,
365,
488,
26,
288,
372,
267,
1830,
715,
26,
288,
340,
291,
14,
2224,
63,
1430,
14,
374,
1084,
342,
365,
715,
26,
355,
2059,
288,
862,
26,
355,
666,
12,
5552,
275,
291,
14,
5096,
14,
7637,
504,
8,
26439,
9,
288,
871,
29912,
26,
355,
2059,
288,
340,
291,
14,
8104,
63,
1430,
14,
374,
1084,
342,
365,
715,
26,
355,
291,
14,
2394,
63,
7637,
847,
822,
8,
576,
9,
339,
347,
664,
63,
2394,
63,
7637,
8,
277,
304,
267,
372,
291,
14,
2394,
63,
7637,
272,
986,
421,
199,
533,
7640,
8,
52,
3263,
414,
1563,
14,
7844,
52,
3263,
414,
1563,
304,
339,
347,
636,
826,
721,
277,
12,
511,
63,
2546,
12,
511,
63,
1813,
12,
2653,
29,
1216,
12,
943,
63,
515,
29,
52,
3263,
414,
1563,
14,
4947,
63,
3243,
304,
267,
377,
3263,
414,
1563,
14,
7844,
52,
3263,
414,
1563,
855,
826,
721,
277,
12,
511,
63,
2546,
12,
511,
63,
1813,
12,
2653,
29,
2593,
12,
943,
63,
515,
29,
793,
63,
515,
9,
267,
291,
14,
20576,
63,
3741,
63,
515,
275,
943,
63,
515,
267,
291,
14,
6796,
63,
396,
63,
513,
275,
1425,
8,
2259,
9,
267,
327,
2248,
1215,
687,
444,
6067,
267,
2088,
63,
409,
275,
511,
63,
2546,
905,
1760,
663,
937,
267,
367,
284,
315,
1425,
8,
17,
12,
822,
8,
1760,
63,
409,
2298,
288,
340,
2088,
63,
409,
59,
73,
1527,
16,
61,
1137,
298,
5869,
582,
355,
2088,
63,
875,
275,
298,
277,
2122,
435,
2088,
63,
409,
59,
73,
1527,
16,
61,
355,
2146,
2088,
63,
875,
267,
291,
14,
1099,
63,
6507,
88,
275,
377,
3263,
414,
1563,
14,
2889,
1799,
2998,
8,
277,
12,
511,
63,
1813,
12,
291,
14,
3641,
63,
354,
9,
267,
986,
339,
347,
5341,
8,
277,
304,
267,
377,
3263,
414,
1563,
14,
52,
3263,
414,
1563,
14,
2526,
8,
277,
9,
267,
291,
14,
1099,
63,
6507,
88,
14,
928,
342,
398,
862,
26,
288,
327,
30241,
1862,
288,
2771,
63,
513,
275,
291,
14,
362,
63,
5329,
480,
29880,
63,
1977,
63,
439,
63,
513,
531,
288,
13171,
63,
711,
275,
291,
14,
362,
63,
5329,
480,
2352,
63,
711,
531,
288,
3222,
63,
552,
275,
291,
14,
2254,
63,
552,
288,
15115,
63,
396,
63,
513,
275,
291,
14,
6796,
63,
396,
63,
513,
288,
4773,
63,
4296,
275,
291,
14,
2347,
63,
4296,
288,
12951,
63,
4296,
275,
291,
14,
6872,
63,
4296,
288,
9775,
63,
5191,
275,
291,
14,
9580,
63,
5191,
288,
327,
30241,
1862,
267,
871,
29912,
12,
325,
26,
288,
653,
1905,
2445,
14,
525,
63,
3446,
63,
13138,
480,
547,
2897,
367,
13488,
26732,
524,
2884,
12,
1125,
365,
450,
83,
2,
450,
325,
9,
288,
746,
29912,
480,
547,
2897,
531,
398,
18419,
63,
719,
275,
2196,
14,
8393,
8,
20,
993,
12,
959,
993,
9,
398,
327,
4205,
4012,
524,
754,
666,
267,
511,
63,
1053,
275,
3087,
267,
340,
4773,
63,
4296,
365,
715,
26,
288,
511,
63,
1053,
847,
298,
8052,
2,
267,
340,
12951,
63,
4296,
365,
715,
26,
288,
511,
63,
1053,
847,
298,
13840,
2,
267,
340,
511,
63,
1053,
508,
10812,
288,
746,
29912,
480,
889,
4012,
524,
511,
1242,
531,
398,
4922,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
20576,
63,
3741,
63,
515,
12,
5051,
63,
19041,
9,
267,
570,
63,
354,
275,
747,
14,
515,
14,
904,
8,
3741,
63,
515,
12,
639,
298,
17457,
26732,
524,
4970,
83,
4970,
83,
2,
450,
334,
396,
63,
1053,
12,
900,
14,
6205,
3647,
68,
5,
40,
5,
45,
5,
51,
401,
900,
14,
15198,
16890,
398,
754,
275,
3868,
3202,
524,
2889,
14,
26732,
524,
2889,
8,
493
] |
[
747,
199,
646,
900,
199,
646,
2196,
199,
646,
5796,
199,
646,
2838,
199,
199,
504,
377,
3263,
414,
492,
377,
3263,
414,
1563,
199,
504,
653,
1905,
2445,
492,
653,
1905,
2445,
199,
504,
653,
1905,
2445,
492,
3868,
3202,
524,
2889,
199,
504,
20511,
492,
30331,
948,
25530,
9043,
199,
504,
20511,
492,
4155,
7850,
421,
199,
4947,
63,
19041,
275,
747,
14,
515,
14,
904,
480,
25635,
401,
298,
26732,
524,
531,
421,
199,
1282,
63,
19926,
63,
3078,
275,
1689,
23283,
401,
298,
2060,
401,
298,
439,
67,
531,
421,
199,
533,
10217,
4436,
8,
12562,
14,
4436,
304,
272,
347,
636,
826,
721,
277,
12,
6771,
12,
3222,
63,
552,
12,
1347,
63,
2697,
304,
267,
5796,
14,
4436,
855,
826,
721,
277,
9,
267,
291,
14,
409,
20555,
8,
549,
9,
267,
291,
14,
5096,
275,
6771,
267,
291,
14,
2254,
63,
552,
275,
3222,
63,
552,
267,
291,
14,
1375,
63,
2697,
275,
1347,
63,
2697,
267,
291,
14,
2224,
63,
1430,
275,
5796,
14,
2390,
342,
267,
986,
339,
347,
4458,
8,
277,
304,
267,
291,
14,
2224,
63,
1430,
14,
409,
342,
339,
347,
1255,
8,
277,
304,
267,
666,
275,
298,
33,
2,
627,
291,
14,
2254,
63,
552,
267,
340,
291,
14,
5096,
365,
488,
26,
288,
372,
267,
1830,
715,
26,
288,
340,
291,
14,
2224,
63,
1430,
14,
374,
1084,
342,
365,
715,
26,
355,
2059,
288,
862,
26,
355,
291,
14,
5096,
14,
23267,
8,
576,
12,
291,
14,
1375,
63,
2697,
9,
288,
871,
29912,
26,
355,
2059,
272,
986,
421,
199,
533,
799,
5107,
4436,
8,
12562,
14,
4436,
304,
272,
347,
636,
826,
721,
277,
12,
6771,
304,
267,
5796,
14,
4436,
855,
826,
721,
277,
9,
267,
291,
14,
409,
20555,
8,
549,
9,
267,
291,
14,
5096,
275,
6771,
267,
291,
14,
2224,
63,
1430,
275,
5796,
14,
2390,
342,
267,
291,
14,
8104,
63,
1430,
275,
5796,
14,
2390,
342,
267,
291,
14,
2394,
63,
7637,
275,
378,
339,
347,
1343,
63,
8104,
8,
277,
304,
267,
291,
14,
8104,
63,
1430,
14,
409,
342,
339,
347,
3631,
63,
8104,
8,
277,
304,
267,
291,
14,
8104,
63,
1430,
14,
3584,
342,
267,
291,
14,
2224,
63,
1430,
14,
409,
342,
339,
347,
1255,
8,
277,
304,
267,
340,
291,
14,
5096,
365,
488,
26,
288,
372,
267,
1830,
715,
26,
288,
340,
291,
14,
2224,
63,
1430,
14,
374,
1084,
342,
365,
715,
26,
355,
2059,
288,
862,
26,
355,
666,
12,
5552,
275,
291,
14,
5096,
14,
7637,
504,
8,
26439,
9,
288,
871,
29912,
26,
355,
2059,
288,
340,
291,
14,
8104,
63,
1430,
14,
374,
1084,
342,
365,
715,
26,
355,
291,
14,
2394,
63,
7637,
847,
822,
8,
576,
9,
339,
347,
664,
63,
2394,
63,
7637,
8,
277,
304,
267,
372,
291,
14,
2394,
63,
7637,
272,
986,
421,
199,
533,
7640,
8,
52,
3263,
414,
1563,
14,
7844,
52,
3263,
414,
1563,
304,
339,
347,
636,
826,
721,
277,
12,
511,
63,
2546,
12,
511,
63,
1813,
12,
2653,
29,
1216,
12,
943,
63,
515,
29,
52,
3263,
414,
1563,
14,
4947,
63,
3243,
304,
267,
377,
3263,
414,
1563,
14,
7844,
52,
3263,
414,
1563,
855,
826,
721,
277,
12,
511,
63,
2546,
12,
511,
63,
1813,
12,
2653,
29,
2593,
12,
943,
63,
515,
29,
793,
63,
515,
9,
267,
291,
14,
20576,
63,
3741,
63,
515,
275,
943,
63,
515,
267,
291,
14,
6796,
63,
396,
63,
513,
275,
1425,
8,
2259,
9,
267,
327,
2248,
1215,
687,
444,
6067,
267,
2088,
63,
409,
275,
511,
63,
2546,
905,
1760,
663,
937,
267,
367,
284,
315,
1425,
8,
17,
12,
822,
8,
1760,
63,
409,
2298,
288,
340,
2088,
63,
409,
59,
73,
1527,
16,
61,
1137,
298,
5869,
582,
355,
2088,
63,
875,
275,
298,
277,
2122,
435,
2088,
63,
409,
59,
73,
1527,
16,
61,
355,
2146,
2088,
63,
875,
267,
291,
14,
1099,
63,
6507,
88,
275,
377,
3263,
414,
1563,
14,
2889,
1799,
2998,
8,
277,
12,
511,
63,
1813,
12,
291,
14,
3641,
63,
354,
9,
267,
986,
339,
347,
5341,
8,
277,
304,
267,
377,
3263,
414,
1563,
14,
52,
3263,
414,
1563,
14,
2526,
8,
277,
9,
267,
291,
14,
1099,
63,
6507,
88,
14,
928,
342,
398,
862,
26,
288,
327,
30241,
1862,
288,
2771,
63,
513,
275,
291,
14,
362,
63,
5329,
480,
29880,
63,
1977,
63,
439,
63,
513,
531,
288,
13171,
63,
711,
275,
291,
14,
362,
63,
5329,
480,
2352,
63,
711,
531,
288,
3222,
63,
552,
275,
291,
14,
2254,
63,
552,
288,
15115,
63,
396,
63,
513,
275,
291,
14,
6796,
63,
396,
63,
513,
288,
4773,
63,
4296,
275,
291,
14,
2347,
63,
4296,
288,
12951,
63,
4296,
275,
291,
14,
6872,
63,
4296,
288,
9775,
63,
5191,
275,
291,
14,
9580,
63,
5191,
288,
327,
30241,
1862,
267,
871,
29912,
12,
325,
26,
288,
653,
1905,
2445,
14,
525,
63,
3446,
63,
13138,
480,
547,
2897,
367,
13488,
26732,
524,
2884,
12,
1125,
365,
450,
83,
2,
450,
325,
9,
288,
746,
29912,
480,
547,
2897,
531,
398,
18419,
63,
719,
275,
2196,
14,
8393,
8,
20,
993,
12,
959,
993,
9,
398,
327,
4205,
4012,
524,
754,
666,
267,
511,
63,
1053,
275,
3087,
267,
340,
4773,
63,
4296,
365,
715,
26,
288,
511,
63,
1053,
847,
298,
8052,
2,
267,
340,
12951,
63,
4296,
365,
715,
26,
288,
511,
63,
1053,
847,
298,
13840,
2,
267,
340,
511,
63,
1053,
508,
10812,
288,
746,
29912,
480,
889,
4012,
524,
511,
1242,
531,
398,
4922,
63,
515,
275,
747,
14,
515,
14,
904,
8,
277,
14,
20576,
63,
3741,
63,
515,
12,
5051,
63,
19041,
9,
267,
570,
63,
354,
275,
747,
14,
515,
14,
904,
8,
3741,
63,
515,
12,
639,
298,
17457,
26732,
524,
4970,
83,
4970,
83,
2,
450,
334,
396,
63,
1053,
12,
900,
14,
6205,
3647,
68,
5,
40,
5,
45,
5,
51,
401,
900,
14,
15198,
16890,
398,
754,
275,
3868,
3202,
524,
2889,
14,
26732,
524,
2889,
8,
493,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
richardotis/scipy
|
scipy/linalg/tests/test_build.py
|
78
|
1776
|
from __future__ import division, print_function, absolute_import
from subprocess import call, PIPE, Popen
import sys
import re
from numpy.testing import TestCase, dec
from numpy.compat import asbytes
from scipy.linalg import _flapack as flapack
# XXX: this is copied from numpy trunk. Can be removed when we will depend on
# numpy 1.3
class FindDependenciesLdd:
def __init__(self):
self.cmd = ['ldd']
try:
st = call(self.cmd, stdout=PIPE, stderr=PIPE)
except OSError:
raise RuntimeError("command %s cannot be run" % self.cmd)
def get_dependencies(self, file):
p = Popen(self.cmd + [file], stdout=PIPE, stderr=PIPE)
stdout, stderr = p.communicate()
if not (p.returncode == 0):
raise RuntimeError("Failed to check dependencies for %s" % file)
return stdout
def grep_dependencies(self, file, deps):
stdout = self.get_dependencies(file)
rdeps = dict([(asbytes(dep), re.compile(asbytes(dep))) for dep in deps])
founds = []
for l in stdout.splitlines():
for k, v in rdeps.items():
if v.search(l):
founds.append(k)
return founds
class TestF77Mismatch(TestCase):
@dec.skipif(not(sys.platform[:5] == 'linux'),
"Skipping fortran compiler mismatch on non Linux platform")
def test_lapack(self):
f = FindDependenciesLdd()
deps = f.grep_dependencies(flapack.__file__,
['libg2c', 'libgfortran'])
self.assertFalse(len(deps) > 1,
"""Both g77 and gfortran runtimes linked in scipy.linalg.flapack ! This is
likely to cause random crashes and wrong results. See numpy INSTALL.txt for
more information.""")
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
4629,
12,
870,
63,
1593,
12,
3679,
63,
646,
199,
199,
504,
3873,
492,
1240,
12,
22773,
12,
13995,
199,
646,
984,
199,
646,
295,
199,
199,
504,
2680,
14,
4776,
492,
7640,
12,
9700,
199,
504,
2680,
14,
5819,
492,
28217,
199,
199,
504,
7026,
14,
10096,
492,
485,
14163,
1389,
465,
17566,
1389,
199,
199,
3,
5787,
26,
642,
365,
8876,
687,
2680,
24764,
14,
6855,
506,
4829,
1380,
781,
911,
11687,
641,
199,
3,
2680,
413,
14,
19,
421,
199,
533,
6668,
11927,
44,
617,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1760,
275,
788,
76,
617,
418,
398,
862,
26,
288,
410,
275,
1240,
8,
277,
14,
1760,
12,
3839,
29,
6089,
12,
4635,
29,
6089,
9,
267,
871,
6440,
26,
288,
746,
6064,
480,
1531,
450,
83,
3913,
506,
1255,
2,
450,
291,
14,
1760,
9,
339,
347,
664,
63,
5714,
8,
277,
12,
570,
304,
267,
299,
275,
13995,
8,
277,
14,
1760,
435,
359,
493,
467,
3839,
29,
6089,
12,
4635,
29,
6089,
9,
267,
3839,
12,
4635,
275,
299,
14,
10664,
342,
267,
340,
440,
334,
80,
14,
9913,
508,
378,
304,
288,
746,
6064,
480,
4276,
370,
1104,
5124,
367,
450,
83,
2,
450,
570,
9,
398,
372,
3839,
339,
347,
20595,
63,
5714,
8,
277,
12,
570,
12,
10140,
304,
267,
3839,
275,
291,
14,
362,
63,
5714,
8,
493,
9,
398,
519,
5846,
275,
1211,
7694,
305,
2394,
8,
2601,
395,
295,
14,
2014,
8,
305,
2394,
8,
2601,
1724,
367,
2657,
315,
10140,
566,
267,
1911,
83,
275,
942,
267,
367,
634,
315,
3839,
14,
7644,
837,
288,
367,
1022,
12,
373,
315,
519,
5846,
14,
1744,
837,
355,
340,
373,
14,
1733,
8,
76,
304,
490,
1911,
83,
14,
740,
8,
75,
9,
398,
372,
1911,
83,
421,
199,
533,
1379,
38,
1138,
23055,
8,
1746,
304,
272,
768,
7778,
14,
22696,
8,
1397,
8,
1274,
14,
3246,
1491,
21,
61,
508,
283,
5135,
659,
355,
298,
18297,
289,
14522,
6365,
15015,
641,
2222,
10130,
4298,
531,
272,
347,
511,
63,
26760,
8,
277,
304,
267,
289,
275,
6668,
11927,
44,
617,
342,
267,
10140,
275,
289,
14,
25914,
63,
5714,
8,
14163,
1389,
855,
493,
3108,
3521,
788,
773,
71,
18,
67,
297,
283,
773,
7102,
14522,
1105,
267,
291,
14,
3334,
8,
552,
8,
5846,
9,
690,
413,
12,
199,
624,
18088,
486,
1138,
436,
486,
18496,
1255,
4508,
10632,
315,
7026,
14,
10096,
14,
14163,
1389,
8546,
961,
365,
199,
24227,
370,
7675,
2196,
2467,
9030,
436,
6835,
2058,
14,
1666,
2680,
20514,
1761,
14,
2424,
367,
199,
6878,
2556,
24887,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
3679,
63,
646,
199,
199,
504,
3873,
492,
1240,
12,
22773,
12,
13995,
199,
646,
984,
199,
646,
295,
199,
199,
504,
2680,
14,
4776,
492,
7640,
12,
9700,
199,
504,
2680,
14,
5819,
492,
28217,
199,
199,
504,
7026,
14,
10096,
492,
485,
14163,
1389,
465,
17566,
1389,
199,
199,
3,
5787,
26,
642,
365,
8876,
687,
2680,
24764,
14,
6855,
506,
4829,
1380,
781,
911,
11687,
641,
199,
3,
2680,
413,
14,
19,
421,
199,
533,
6668,
11927,
44,
617,
26,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
1760,
275,
788,
76,
617,
418,
398,
862,
26,
288,
410,
275,
1240,
8,
277,
14,
1760,
12,
3839,
29,
6089,
12,
4635,
29,
6089,
9,
267,
871,
6440,
26,
288,
746,
6064,
480,
1531,
450,
83,
3913,
506,
1255,
2,
450,
291,
14,
1760,
9,
339,
347,
664,
63,
5714,
8,
277,
12,
570,
304,
267,
299,
275,
13995,
8,
277,
14,
1760,
435,
359,
493,
467,
3839,
29,
6089,
12,
4635,
29,
6089,
9,
267,
3839,
12,
4635,
275,
299,
14,
10664,
342,
267,
340,
440,
334,
80,
14,
9913,
508,
378,
304,
288,
746,
6064,
480,
4276,
370,
1104,
5124,
367,
450,
83,
2,
450,
570,
9,
398,
372,
3839,
339,
347,
20595,
63,
5714,
8,
277,
12,
570,
12,
10140,
304,
267,
3839,
275,
291,
14,
362,
63,
5714,
8,
493,
9,
398,
519,
5846,
275,
1211,
7694,
305,
2394,
8,
2601,
395,
295,
14,
2014,
8,
305,
2394,
8,
2601,
1724,
367,
2657,
315,
10140,
566,
267,
1911,
83,
275,
942,
267,
367,
634,
315,
3839,
14,
7644,
837,
288,
367,
1022,
12,
373,
315,
519,
5846,
14,
1744,
837,
355,
340,
373,
14,
1733,
8,
76,
304,
490,
1911,
83,
14,
740,
8,
75,
9,
398,
372,
1911,
83,
421,
199,
533,
1379,
38,
1138,
23055,
8,
1746,
304,
272,
768,
7778,
14,
22696,
8,
1397,
8,
1274,
14,
3246,
1491,
21,
61,
508,
283,
5135,
659,
355,
298,
18297,
289,
14522,
6365,
15015,
641,
2222,
10130,
4298,
531,
272,
347,
511,
63,
26760,
8,
277,
304,
267,
289,
275,
6668,
11927,
44,
617,
342,
267,
10140,
275,
289,
14,
25914,
63,
5714,
8,
14163,
1389,
855,
493,
3108,
3521,
788,
773,
71,
18,
67,
297,
283,
773,
7102,
14522,
1105,
267,
291,
14,
3334,
8,
552,
8,
5846,
9,
690,
413,
12,
199,
624,
18088,
486,
1138,
436,
486,
18496,
1255,
4508,
10632,
315,
7026,
14,
10096,
14,
14163,
1389,
8546,
961,
365,
199,
24227,
370,
7675,
2196,
2467,
9030,
436,
6835,
2058,
14,
1666,
2680,
20514,
1761,
14,
2424,
367,
199,
6878,
2556,
24887,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
bitspill/electrum-doged
|
lib/wallet.py
|
6
|
68691
|
#!/usr/bin/env python
#
# Electrum - lightweight Bitcoin client
# Copyright (C) 2011 thomasv@gitorious
#
# 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 sys
import os
import hashlib
import ast
import threading
import random
import time
import math
import json
import copy
from util import print_msg, print_error, NotEnoughFunds
from util import profiler
from bitcoin import *
from account import *
from version import *
from transaction import Transaction
from plugins import run_hook
import bitcoin
from synchronizer import WalletSynchronizer
from mnemonic import Mnemonic
# internal ID for imported account
IMPORTED_ACCOUNT = '/x'
class WalletStorage(object):
def __init__(self, path):
self.lock = threading.RLock()
self.data = {}
self.path = path
self.file_exists = False
print_error( "wallet path", self.path )
if self.path:
self.read(self.path)
def read(self, path):
"""Read the contents of the wallet file."""
try:
with open(self.path, "r") as f:
data = f.read()
except IOError:
return
try:
self.data = json.loads(data)
except:
try:
d = ast.literal_eval(data) #parse raw data from reading wallet file
except Exception as e:
raise IOError("Cannot read wallet file '%s'" % self.path)
self.data = {}
# In old versions of Electrum labels were latin1 encoded, this fixes breakage.
labels = d.get('labels', {})
for i, label in labels.items():
try:
unicode(label)
except UnicodeDecodeError:
d['labels'][i] = unicode(label.decode('latin1'))
for key, value in d.items():
try:
json.dumps(key)
json.dumps(value)
except:
print_error('Failed to convert label to json format', key)
continue
self.data[key] = value
self.file_exists = True
def get(self, key, default=None):
with self.lock:
v = self.data.get(key)
if v is None:
v = default
else:
v = copy.deepcopy(v)
return v
def put(self, key, value, save = True):
try:
json.dumps(key)
json.dumps(value)
except:
print_error("json error: cannot save", key)
return
with self.lock:
if value is not None:
self.data[key] = copy.deepcopy(value)
elif key in self.data:
self.data.pop(key)
if save:
self.write()
def write(self):
assert not threading.currentThread().isDaemon()
temp_path = "%s.tmp.%s" % (self.path, os.getpid())
s = json.dumps(self.data, indent=4, sort_keys=True)
with open(temp_path, "w") as f:
f.write(s)
f.flush()
os.fsync(f.fileno())
# perform atomic write on POSIX systems
try:
os.rename(temp_path, self.path)
except:
os.remove(self.path)
os.rename(temp_path, self.path)
if 'ANDROID_DATA' not in os.environ:
import stat
os.chmod(self.path,stat.S_IREAD | stat.S_IWRITE)
class Abstract_Wallet(object):
"""
Wallet classes are created to handle various address generation methods.
Completion states (watching-only, single account, no seed, etc) are handled inside classes.
"""
def __init__(self, storage):
self.storage = storage
self.electrum_version = ELECTRUM_VERSION
self.gap_limit_for_change = 3 # constant
# saved fields
self.seed_version = storage.get('seed_version', NEW_SEED_VERSION)
self.use_change = storage.get('use_change',True)
self.use_encryption = storage.get('use_encryption', False)
self.seed = storage.get('seed', '') # encrypted
self.labels = storage.get('labels', {})
self.frozen_addresses = storage.get('frozen_addresses',[])
self.stored_height = storage.get('stored_height', 0) # last known height (for offline mode)
self.history = storage.get('addr_history',{}) # address -> list(txid, height)
self.fee_per_kb = int(storage.get('fee_per_kb', RECOMMENDED_FEE))
# This attribute is set when wallet.start_threads is called.
self.synchronizer = None
# imported_keys is deprecated. The GUI should call convert_imported_keys
self.imported_keys = self.storage.get('imported_keys',{})
self.load_accounts()
self.load_transactions()
# spv
self.verifier = None
# Transactions pending verification. Each value is the transaction height. Access with self.lock.
self.unverified_tx = {}
# Verified transactions. Each value is a (height, timestamp, block_pos) tuple. Access with self.lock.
self.verified_tx = storage.get('verified_tx3',{})
# there is a difference between wallet.up_to_date and interface.is_up_to_date()
# interface.is_up_to_date() returns true when all requests have been answered and processed
# wallet.up_to_date is true when the wallet is synchronized (stronger requirement)
self.up_to_date = False
self.lock = threading.Lock()
self.transaction_lock = threading.Lock()
self.tx_event = threading.Event()
# save wallet type the first time
if self.storage.get('wallet_type') is None:
self.storage.put('wallet_type', self.wallet_type, True)
@profiler
def load_transactions(self):
self.txi = self.storage.get('txi', {})
self.txo = self.storage.get('txo', {})
self.pruned_txo = self.storage.get('pruned_txo', {})
tx_list = self.storage.get('transactions', {})
self.transactions = {}
for tx_hash, raw in tx_list.items():
tx = Transaction(raw)
self.transactions[tx_hash] = tx
if self.txi.get(tx_hash) is None and self.txo.get(tx_hash) is None:
print_error("removing unreferenced tx", tx_hash)
self.transactions.pop(tx_hash)
@profiler
def save_transactions(self):
with self.transaction_lock:
tx = {}
for k,v in self.transactions.items():
tx[k] = str(v)
# Flush storage only with the last put
self.storage.put('transactions', tx, False)
self.storage.put('txi', self.txi, False)
self.storage.put('txo', self.txo, False)
self.storage.put('pruned_txo', self.pruned_txo, True)
def clear_history(self):
with self.transaction_lock:
self.txi = {}
self.txo = {}
self.pruned_txo = {}
self.history = {}
self.save_transactions()
# wizard action
def get_action(self):
pass
def basename(self):
return os.path.basename(self.storage.path)
def convert_imported_keys(self, password):
for k, v in self.imported_keys.items():
sec = pw_decode(v, password)
pubkey = public_key_from_private_key(sec)
address = public_key_to_bc_address(pubkey.decode('hex'))
if address != k:
raise InvalidPassword()
self.import_key(sec, password)
self.imported_keys.pop(k)
self.storage.put('imported_keys', self.imported_keys)
def load_accounts(self):
self.accounts = {}
d = self.storage.get('accounts', {})
for k, v in d.items():
if self.wallet_type == 'old' and k in [0, '0']:
v['mpk'] = self.storage.get('master_public_key')
self.accounts['0'] = OldAccount(v)
elif v.get('imported'):
self.accounts[k] = ImportedAccount(v)
elif v.get('xpub3'):
self.accounts[k] = BIP32_Account_2of3(v)
elif v.get('xpub2'):
self.accounts[k] = BIP32_Account_2of2(v)
elif v.get('xpub'):
self.accounts[k] = BIP32_Account(v)
elif v.get('pending'):
try:
self.accounts[k] = PendingAccount(v)
except:
pass
else:
print_error("cannot load account", v)
def synchronize(self):
pass
def can_create_accounts(self):
return False
def set_up_to_date(self,b):
with self.lock: self.up_to_date = b
def is_up_to_date(self):
with self.lock: return self.up_to_date
def update(self):
self.up_to_date = False
while not self.is_up_to_date():
time.sleep(0.1)
def is_imported(self, addr):
account = self.accounts.get(IMPORTED_ACCOUNT)
if account:
return addr in account.get_addresses(0)
else:
return False
def has_imported_keys(self):
account = self.accounts.get(IMPORTED_ACCOUNT)
return account is not None
def import_key(self, sec, password):
try:
pubkey = public_key_from_private_key(sec)
address = public_key_to_bc_address(pubkey.decode('hex'))
except Exception:
raise Exception('Invalid private key')
if self.is_mine(address):
raise Exception('Address already in wallet')
if self.accounts.get(IMPORTED_ACCOUNT) is None:
self.accounts[IMPORTED_ACCOUNT] = ImportedAccount({'imported':{}})
self.accounts[IMPORTED_ACCOUNT].add(address, pubkey, sec, password)
self.save_accounts()
if self.synchronizer:
self.synchronizer.add(address)
return address
def delete_imported_key(self, addr):
account = self.accounts[IMPORTED_ACCOUNT]
account.remove(addr)
if not account.get_addresses(0):
self.accounts.pop(IMPORTED_ACCOUNT)
self.save_accounts()
def set_label(self, name, text = None):
changed = False
old_text = self.labels.get(name)
if text:
if old_text != text:
self.labels[name] = text
changed = True
else:
if old_text:
self.labels.pop(name)
changed = True
if changed:
self.storage.put('labels', self.labels, True)
run_hook('set_label', name, text, changed)
return changed
def addresses(self, include_change = True):
return list(addr for acc in self.accounts for addr in self.get_account_addresses(acc, include_change))
def is_mine(self, address):
return address in self.addresses(True)
def is_change(self, address):
if not self.is_mine(address): return False
acct, s = self.get_address_index(address)
if s is None: return False
return s[0] == 1
def get_address_index(self, address):
for acc_id in self.accounts:
for for_change in [0,1]:
addresses = self.accounts[acc_id].get_addresses(for_change)
if address in addresses:
return acc_id, (for_change, addresses.index(address))
raise Exception("Address not found", address)
def get_private_key(self, address, password):
if self.is_watching_only():
return []
account_id, sequence = self.get_address_index(address)
return self.accounts[account_id].get_private_key(sequence, self, password)
def get_public_keys(self, address):
account_id, sequence = self.get_address_index(address)
return self.accounts[account_id].get_pubkeys(*sequence)
def sign_message(self, address, message, password):
keys = self.get_private_key(address, password)
assert len(keys) == 1
sec = keys[0]
key = regenerate_key(sec)
compressed = is_compressed(sec)
return key.sign_message(message, compressed, address)
def decrypt_message(self, pubkey, message, password):
address = public_key_to_bc_address(pubkey.decode('hex'))
keys = self.get_private_key(address, password)
secret = keys[0]
ec = regenerate_key(secret)
decrypted = ec.decrypt_message(message)
return decrypted
def add_unverified_tx(self, tx_hash, tx_height):
if tx_height > 0:
with self.lock:
self.unverified_tx[tx_hash] = tx_height
def add_verified_tx(self, tx_hash, info):
with self.lock:
self.verified_tx[tx_hash] = info # (tx_height, timestamp, pos)
self.storage.put('verified_tx3', self.verified_tx, True)
self.network.trigger_callback('updated')
def get_unverified_txs(self):
'''Returns a list of tuples (tx_hash, height) that are unverified and not beyond local height'''
txs = []
with self.lock:
for tx_hash, tx_height in self.unverified_tx.items():
# do not request merkle branch before headers are available
if tx_hash not in self.verified_tx and tx_height <= self.get_local_height():
txs.append((tx_hash, tx_height))
return txs
def undo_verifications(self, height):
'''Used by the verifier when a reorg has happened'''
txs = []
with self.lock:
for tx_hash, item in self.verified_tx:
tx_height, timestamp, pos = item
if tx_height >= height:
self.verified_tx.pop(tx_hash, None)
txs.append(tx_hash)
return txs
def get_local_height(self):
""" return last known height if we are offline """
return self.network.get_local_height() if self.network else self.stored_height
def get_confirmations(self, tx):
""" return the number of confirmations of a monitored transaction. """
with self.lock:
if tx in self.verified_tx:
height, timestamp, pos = self.verified_tx[tx]
conf = (self.get_local_height() - height + 1)
if conf <= 0: timestamp = None
elif tx in self.unverified_tx:
conf = -1
timestamp = None
else:
conf = 0
timestamp = None
return conf, timestamp
def get_txpos(self, tx_hash):
"return position, even if the tx is unverified"
with self.lock:
x = self.verified_tx.get(tx_hash)
y = self.unverified_tx.get(tx_hash)
if x:
height, timestamp, pos = x
return height, pos
elif y:
return y, 0
else:
return 1e12, 0
def is_found(self):
return self.history.values() != [[]] * len(self.history)
def get_num_tx(self, address):
""" return number of transactions where address is involved """
return len(self.history.get(address, []))
def get_tx_delta(self, tx_hash, address):
"effect of tx on address"
# pruned
if tx_hash in self.pruned_txo.values():
return None
delta = 0
# substract the value of coins sent from address
d = self.txi.get(tx_hash, {}).get(address, [])
for n, v in d:
delta -= v
# add the value of the coins received at address
d = self.txo.get(tx_hash, {}).get(address, [])
for n, v, cb in d:
delta += v
return delta
def get_wallet_delta(self, tx):
""" effect of tx on wallet """
addresses = self.addresses(True)
is_relevant = False
is_send = False
is_pruned = False
is_partial = False
v_in = v_out = v_out_mine = 0
for item in tx.inputs:
addr = item.get('address')
if addr in addresses:
is_send = True
is_relevant = True
d = self.txo.get(item['prevout_hash'], {}).get(addr, [])
for n, v, cb in d:
if n == item['prevout_n']:
value = v
break
else:
value = None
if value is None:
is_pruned = True
else:
v_in += value
else:
is_partial = True
if not is_send:
is_partial = False
for addr, value in tx.get_outputs():
v_out += value
if addr in addresses:
v_out_mine += value
is_relevant = True
if is_pruned:
# some inputs are mine:
fee = None
if is_send:
v = v_out_mine - v_out
else:
# no input is mine
v = v_out_mine
else:
v = v_out_mine - v_in
if is_partial:
# some inputs are mine, but not all
fee = None
is_send = v < 0
else:
# all inputs are mine
fee = v_out - v_in
return is_relevant, is_send, v, fee
def get_addr_io(self, address):
h = self.history.get(address, [])
received = {}
sent = {}
for tx_hash, height in h:
l = self.txo.get(tx_hash, {}).get(address, [])
for n, v, is_cb in l:
received[tx_hash + ':%d'%n] = (height, v, is_cb)
for tx_hash, height in h:
l = self.txi.get(tx_hash, {}).get(address, [])
for txi, v in l:
sent[txi] = height
return received, sent
def get_addr_utxo(self, address):
coins, spent = self.get_addr_io(address)
for txi in spent:
coins.pop(txi)
return coins
# return the total amount ever received by an address
def get_addr_received(self, address):
received, sent = self.get_addr_io(address)
return sum([v for height, v, is_cb in received.values()])
# return the balance of a bitcoin address: confirmed and matured, unconfirmed, unmatured
def get_addr_balance(self, address):
received, sent = self.get_addr_io(address)
c = u = x = 0
for txo, (tx_height, v, is_cb) in received.items():
if is_cb and tx_height + COINBASE_MATURITY > self.get_local_height():
x += v
elif tx_height > 0:
c += v
else:
u += v
if txo in sent:
if sent[txo] > 0:
c -= v
else:
u -= v
return c, u, x
def get_spendable_coins(self, domain=None):
coins = []
if domain is None:
domain = self.addresses(True)
for addr in domain:
c = self.get_addr_utxo(addr)
for txo, v in c.items():
tx_height, value, is_cb = v
if is_cb and tx_height + COINBASE_MATURITY > self.get_local_height():
continue
prevout_hash, prevout_n = txo.split(':')
output = {
'address':addr,
'value':value,
'prevout_n':int(prevout_n),
'prevout_hash':prevout_hash,
'height':tx_height,
'coinbase':is_cb
}
coins.append((tx_height, output))
continue
# sort by age
if coins:
coins = sorted(coins)
if coins[-1][0] != 0:
while coins[0][0] == 0:
coins = coins[1:] + [ coins[0] ]
return [value for height, value in coins]
def get_account_name(self, k):
return self.labels.get(k, self.accounts[k].get_name(k))
def get_account_names(self):
account_names = {}
for k in self.accounts.keys():
account_names[k] = self.get_account_name(k)
return account_names
def get_account_addresses(self, acc_id, include_change=True):
if acc_id is None:
addr_list = self.addresses(include_change)
elif acc_id in self.accounts:
acc = self.accounts[acc_id]
addr_list = acc.get_addresses(0)
if include_change:
addr_list += acc.get_addresses(1)
return addr_list
def get_account_from_address(self, addr):
"Returns the account that contains this address, or None"
for acc_id in self.accounts: # similar to get_address_index but simpler
if addr in self.get_account_addresses(acc_id):
return acc_id
return None
def get_account_balance(self, account):
return self.get_balance(self.get_account_addresses(account))
def get_frozen_balance(self):
return self.get_balance(self.frozen_addresses)
def get_balance(self, domain=None):
if domain is None:
domain = self.addresses(True)
cc = uu = xx = 0
for addr in domain:
c, u, x = self.get_addr_balance(addr)
cc += c
uu += u
xx += x
return cc, uu, xx
def set_fee(self, fee):
if self.fee_per_kb != fee:
self.fee_per_kb = fee
self.storage.put('fee_per_kb', self.fee_per_kb, True)
def get_address_history(self, address):
with self.lock:
return self.history.get(address, [])
def get_status(self, h):
if not h:
return None
status = ''
for tx_hash, height in h:
status += tx_hash + ':%d:' % height
return hashlib.sha256( status ).digest().encode('hex')
def find_pay_to_pubkey_address(self, prevout_hash, prevout_n):
dd = self.txo.get(prevout_hash, {})
for addr, l in dd.items():
for n, v, is_cb in l:
if n == prevout_n:
print_error("found pay-to-pubkey address:", addr)
return addr
def add_transaction(self, tx_hash, tx, tx_height):
is_coinbase = tx.inputs[0].get('is_coinbase') == True
with self.transaction_lock:
# add inputs
self.txi[tx_hash] = d = {}
for txi in tx.inputs:
addr = txi.get('address')
if not txi.get('is_coinbase'):
prevout_hash = txi['prevout_hash']
prevout_n = txi['prevout_n']
ser = prevout_hash + ':%d'%prevout_n
if addr == "(pubkey)":
addr = self.find_pay_to_pubkey_address(prevout_hash, prevout_n)
# find value from prev output
if addr and self.is_mine(addr):
dd = self.txo.get(prevout_hash, {})
for n, v, is_cb in dd.get(addr, []):
if n == prevout_n:
if d.get(addr) is None:
d[addr] = []
d[addr].append((ser, v))
break
else:
self.pruned_txo[ser] = tx_hash
# add outputs
self.txo[tx_hash] = d = {}
for n, txo in enumerate(tx.outputs):
ser = tx_hash + ':%d'%n
_type, x, v = txo
if _type == 'address':
addr = x
elif _type == 'pubkey':
addr = public_key_to_bc_address(x.decode('hex'))
else:
addr = None
if addr and self.is_mine(addr):
if d.get(addr) is None:
d[addr] = []
d[addr].append((n, v, is_coinbase))
# give v to txi that spends me
next_tx = self.pruned_txo.get(ser)
if next_tx is not None:
self.pruned_txo.pop(ser)
dd = self.txi.get(next_tx, {})
if dd.get(addr) is None:
dd[addr] = []
dd[addr].append((ser, v))
# save
self.transactions[tx_hash] = tx
def remove_transaction(self, tx_hash, tx_height):
with self.transaction_lock:
print_error("removing tx from history", tx_hash)
#tx = self.transactions.pop(tx_hash)
for ser, hh in self.pruned_txo.items():
if hh == tx_hash:
self.pruned_txo.pop(ser)
# add tx to pruned_txo, and undo the txi addition
for next_tx, dd in self.txi.items():
for addr, l in dd.items():
ll = l[:]
for item in ll:
ser, v = item
prev_hash, prev_n = ser.split(':')
if prev_hash == tx_hash:
l.remove(item)
self.pruned_txo[ser] = next_tx
if l == []:
dd.pop(addr)
else:
dd[addr] = l
self.txi.pop(tx_hash)
self.txo.pop(tx_hash)
def receive_tx_callback(self, tx_hash, tx, tx_height):
self.add_transaction(tx_hash, tx, tx_height)
#self.network.pending_transactions_for_notifications.append(tx)
self.add_unverified_tx(tx_hash, tx_height)
def receive_history_callback(self, addr, hist):
with self.lock:
old_hist = self.history.get(addr, [])
for tx_hash, height in old_hist:
if (tx_hash, height) not in hist:
self.remove_transaction(tx_hash, height)
self.history[addr] = hist
self.storage.put('addr_history', self.history, True)
for tx_hash, tx_height in hist:
# add it in case it was previously unconfirmed
self.add_unverified_tx (tx_hash, tx_height)
# if addr is new, we have to recompute txi and txo
tx = self.transactions.get(tx_hash)
if tx is not None and self.txi.get(tx_hash, {}).get(addr) is None and self.txo.get(tx_hash, {}).get(addr) is None:
tx.deserialize()
self.add_transaction(tx_hash, tx, tx_height)
def get_history(self, domain=None):
from collections import defaultdict
# get domain
if domain is None:
domain = self.get_account_addresses(None)
# 1. Get the history of each address in the domain, maintain the
# delta of a tx as the sum of its deltas on domain addresses
tx_deltas = defaultdict(int)
for addr in domain:
h = self.get_address_history(addr)
for tx_hash, height in h:
delta = self.get_tx_delta(tx_hash, addr)
if delta is None or tx_deltas[tx_hash] is None:
tx_deltas[tx_hash] = None
else:
tx_deltas[tx_hash] += delta
# 2. create sorted history
history = []
for tx_hash, delta in tx_deltas.items():
conf, timestamp = self.get_confirmations(tx_hash)
history.append((tx_hash, conf, delta, timestamp))
history.sort(key = lambda x: self.get_txpos(x[0]))
history.reverse()
# 3. add balance
c, u, x = self.get_balance(domain)
balance = c + u + x
h2 = []
for item in history:
tx_hash, conf, delta, timestamp = item
h2.append((tx_hash, conf, delta, timestamp, balance))
if balance is None or delta is None:
balance = None
else:
balance -= delta
h2.reverse()
# fixme: this may happen if history is incomplete
if balance not in [None, 0]:
print_error("Error: history not synchronized")
return []
return h2
def get_label(self, tx_hash):
label = self.labels.get(tx_hash)
is_default = (label == '') or (label is None)
if is_default:
label = self.get_default_label(tx_hash)
return label, is_default
def get_default_label(self, tx_hash):
if self.txi.get(tx_hash) == {}:
d = self.txo.get(tx_hash, {})
labels = []
for addr in d.keys():
label = self.labels.get(addr)
if label:
labels.append(label)
return ', '.join(labels)
return ''
def get_tx_fee(self, tx):
# this method can be overloaded
return tx.get_fee()
def estimated_fee(self, tx):
estimated_size = len(tx.serialize(-1))/2
fee = int(self.fee_per_kb*estimated_size/1000.)
if fee < MIN_RELAY_TX_FEE: # tx.required_fee(self):
fee = MIN_RELAY_TX_FEE
if fee < tx.required_fee(self): # check fee meets the required fee
fee = tx.required_fee(self)
return fee
def make_unsigned_transaction(self, outputs, fixed_fee=None, change_addr=None, domain=None, coins=None ):
# check outputs
for type, data, value in outputs:
if type == 'address':
assert is_address(data), "Address " + data + " is invalid!"
# get coins
if not coins:
if domain is None:
domain = self.addresses(True)
for i in self.frozen_addresses:
if i in domain:
domain.remove(i)
coins = self.get_spendable_coins(domain)
amount = sum(map(lambda x:x[2], outputs))
total = fee = 0
inputs = []
tx = Transaction.from_io(inputs, outputs)
for item in coins:
v = item.get('value')
total += v
self.add_input_info(item)
tx.add_input(item)
fee = fixed_fee if fixed_fee is not None else self.estimated_fee(tx)
if total >= amount + fee: break
else:
raise NotEnoughFunds()
# change address
if not change_addr:
# send change to one of the accounts involved in the tx
address = inputs[0].get('address')
account, _ = self.get_address_index(address)
if not self.use_change or not self.accounts[account].has_change():
change_addr = address
else:
change_addr = self.accounts[account].get_addresses(1)[-self.gap_limit_for_change]
# if change is above dust threshold, add a change output.
change_amount = total - ( amount + fee )
if fixed_fee is not None and change_amount > 0:
# Insert the change output at a random position in the outputs
posn = random.randint(0, len(tx.outputs))
tx.outputs[posn:posn] = [( 'address', change_addr, change_amount)]
elif change_amount > DUST_THRESHOLD:
# Insert the change output at a random position in the outputs
posn = random.randint(0, len(tx.outputs))
tx.outputs[posn:posn] = [( 'address', change_addr, change_amount)]
# recompute fee including change output
fee = self.estimated_fee(tx)
# remove change output
tx.outputs.pop(posn)
# if change is still above dust threshold, re-add change output.
change_amount = total - ( amount + fee )
if change_amount > DUST_THRESHOLD:
tx.outputs[posn:posn] = [( 'address', change_addr, change_amount)]
print_error('change', change_amount)
else:
print_error('not keeping dust', change_amount)
else:
print_error('not keeping dust', change_amount)
run_hook('make_unsigned_transaction', tx)
return tx
def mktx(self, outputs, password, fee=None, change_addr=None, domain= None, coins = None ):
tx = self.make_unsigned_transaction(outputs, fee, change_addr, domain, coins)
self.sign_transaction(tx, password)
return tx
def add_input_info(self, txin):
address = txin['address']
account_id, sequence = self.get_address_index(address)
account = self.accounts[account_id]
redeemScript = account.redeem_script(*sequence)
pubkeys = account.get_pubkeys(*sequence)
x_pubkeys = account.get_xpubkeys(*sequence)
# sort pubkeys and x_pubkeys, using the order of pubkeys
pubkeys, x_pubkeys = zip( *sorted(zip(pubkeys, x_pubkeys)))
txin['pubkeys'] = list(pubkeys)
txin['x_pubkeys'] = list(x_pubkeys)
txin['signatures'] = [None] * len(pubkeys)
if redeemScript:
txin['redeemScript'] = redeemScript
txin['num_sig'] = 2
else:
txin['redeemPubkey'] = account.get_pubkey(*sequence)
txin['num_sig'] = 1
def sign_transaction(self, tx, password):
if self.is_watching_only():
return
# check that the password is correct. This will raise if it's not.
self.check_password(password)
keypairs = {}
x_pubkeys = tx.inputs_to_sign()
for x in x_pubkeys:
sec = self.get_private_key_from_xpubkey(x, password)
if sec:
keypairs[ x ] = sec
if keypairs:
tx.sign(keypairs)
run_hook('sign_transaction', tx, password)
def sendtx(self, tx):
# synchronous
h = self.send_tx(tx)
self.tx_event.wait()
return self.receive_tx(h, tx)
def send_tx(self, tx):
# asynchronous
self.tx_event.clear()
self.network.send([('blockchain.transaction.broadcast', [str(tx)])], self.on_broadcast)
return tx.hash()
def on_broadcast(self, r):
self.tx_result = r.get('result')
self.tx_event.set()
def receive_tx(self, tx_hash, tx):
out = self.tx_result
if out != tx_hash:
return False, "error: " + out
run_hook('receive_tx', tx, self)
return True, out
def update_password(self, old_password, new_password):
if new_password == '':
new_password = None
if self.has_seed():
decoded = self.get_seed(old_password)
self.seed = pw_encode( decoded, new_password)
self.storage.put('seed', self.seed, True)
imported_account = self.accounts.get(IMPORTED_ACCOUNT)
if imported_account:
imported_account.update_password(old_password, new_password)
self.save_accounts()
if hasattr(self, 'master_private_keys'):
for k, v in self.master_private_keys.items():
b = pw_decode(v, old_password)
c = pw_encode(b, new_password)
self.master_private_keys[k] = c
self.storage.put('master_private_keys', self.master_private_keys, True)
self.use_encryption = (new_password != None)
self.storage.put('use_encryption', self.use_encryption,True)
def freeze(self,addr):
if self.is_mine(addr) and addr not in self.frozen_addresses:
self.frozen_addresses.append(addr)
self.storage.put('frozen_addresses', self.frozen_addresses, True)
return True
else:
return False
def unfreeze(self,addr):
if self.is_mine(addr) and addr in self.frozen_addresses:
self.frozen_addresses.remove(addr)
self.storage.put('frozen_addresses', self.frozen_addresses, True)
return True
else:
return False
def set_verifier(self, verifier):
self.verifier = verifier
# review transactions that are in the history
for addr, hist in self.history.items():
for tx_hash, tx_height in hist:
# add it in case it was previously unconfirmed
self.add_unverified_tx (tx_hash, tx_height)
# if we are on a pruning server, remove unverified transactions
with self.lock:
vr = self.verified_tx.keys() + self.unverified_tx.keys()
for tx_hash in self.transactions.keys():
if tx_hash not in vr:
print_error("removing transaction", tx_hash)
self.transactions.pop(tx_hash)
def check_new_history(self, addr, hist):
# check that all tx in hist are relevant
for tx_hash, height in hist:
tx = self.transactions.get(tx_hash)
if not tx:
continue
if not tx.has_address(addr):
return False
# check that we are not "orphaning" a transaction
old_hist = self.history.get(addr,[])
for tx_hash, height in old_hist:
if tx_hash in map(lambda x:x[0], hist):
continue
found = False
for _addr, _hist in self.history.items():
if _addr == addr:
continue
_tx_hist = map(lambda x:x[0], _hist)
if tx_hash in _tx_hist:
found = True
break
if not found:
tx = self.transactions.get(tx_hash)
# tx might not be there
if not tx: continue
# already verified?
with self.lock:
if tx_hash in self.verified_tx:
continue
# unconfirmed tx
print_error("new history is orphaning transaction:", tx_hash)
# check that all outputs are not mine, request histories
ext_requests = []
for _addr in tx.get_output_addresses():
# assert not self.is_mine(_addr)
ext_requests.append( ('blockchain.address.get_history', [_addr]) )
ext_h = self.network.synchronous_get(ext_requests)
print_error("sync:", ext_requests, ext_h)
height = None
for h in ext_h:
for item in h:
if item.get('tx_hash') == tx_hash:
height = item.get('height')
if height:
print_error("found height for", tx_hash, height)
self.add_unverified_tx(tx_hash, height)
else:
print_error("removing orphaned tx from history", tx_hash)
self.transactions.pop(tx_hash)
return True
def start_threads(self, network):
from verifier import SPV
self.network = network
if self.network is not None:
self.verifier = SPV(self.network, self)
self.verifier.start()
self.set_verifier(self.verifier)
self.synchronizer = WalletSynchronizer(self, network)
self.synchronizer.start()
else:
self.verifier = None
self.synchronizer =None
def stop_threads(self):
if self.network:
self.verifier.stop()
self.synchronizer.stop()
self.storage.put('stored_height', self.get_local_height(), True)
def restore(self, cb):
pass
def get_accounts(self):
return self.accounts
def add_account(self, account_id, account):
self.accounts[account_id] = account
self.save_accounts()
def save_accounts(self):
d = {}
for k, v in self.accounts.items():
d[k] = v.dump()
self.storage.put('accounts', d, True)
def can_import(self):
return not self.is_watching_only()
def can_export(self):
return not self.is_watching_only()
def is_used(self, address):
h = self.history.get(address,[])
c, u, x = self.get_addr_balance(address)
return len(h), len(h) > 0 and c == -u
def address_is_old(self, address, age_limit=2):
age = -1
h = self.history.get(address, [])
for tx_hash, tx_height in h:
if tx_height == 0:
tx_age = 0
else:
tx_age = self.get_local_height() - tx_height + 1
if tx_age > age:
age = tx_age
return age > age_limit
def can_sign(self, tx):
if self.is_watching_only():
return False
if tx.is_complete():
return False
for x in tx.inputs_to_sign():
if self.can_sign_xpubkey(x):
return True
return False
def get_private_key_from_xpubkey(self, x_pubkey, password):
if x_pubkey[0:2] in ['02','03','04']:
addr = bitcoin.public_key_to_bc_address(x_pubkey.decode('hex'))
if self.is_mine(addr):
return self.get_private_key(addr, password)[0]
elif x_pubkey[0:2] == 'ff':
xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
for k, v in self.master_public_keys.items():
if v == xpub:
xprv = self.get_master_private_key(k, password)
if xprv:
_, _, _, c, k = deserialize_xkey(xprv)
return bip32_private_key(sequence, k, c)
elif x_pubkey[0:2] == 'fe':
xpub, sequence = OldAccount.parse_xpubkey(x_pubkey)
for k, account in self.accounts.items():
if xpub in account.get_master_pubkeys():
pk = account.get_private_key(sequence, self, password)
return pk[0]
elif x_pubkey[0:2] == 'fd':
addrtype = ord(x_pubkey[2:4].decode('hex'))
addr = hash_160_to_bc_address(x_pubkey[4:].decode('hex'), addrtype)
if self.is_mine(addr):
return self.get_private_key(addr, password)[0]
else:
raise BaseException("z")
def can_sign_xpubkey(self, x_pubkey):
if x_pubkey[0:2] in ['02','03','04']:
addr = bitcoin.public_key_to_bc_address(x_pubkey.decode('hex'))
return self.is_mine(addr)
elif x_pubkey[0:2] == 'ff':
if not isinstance(self, BIP32_Wallet): return False
xpub, sequence = BIP32_Account.parse_xpubkey(x_pubkey)
return xpub in [ self.master_public_keys[k] for k in self.master_private_keys.keys() ]
elif x_pubkey[0:2] == 'fe':
if not isinstance(self, OldWallet): return False
xpub, sequence = OldAccount.parse_xpubkey(x_pubkey)
return xpub == self.get_master_public_key()
elif x_pubkey[0:2] == 'fd':
addrtype = ord(x_pubkey[2:4].decode('hex'))
addr = hash_160_to_bc_address(x_pubkey[4:].decode('hex'), addrtype)
return self.is_mine(addr)
else:
raise BaseException("z")
def is_watching_only(self):
False
def can_change_password(self):
return not self.is_watching_only()
class Imported_Wallet(Abstract_Wallet):
wallet_type = 'imported'
def __init__(self, storage):
Abstract_Wallet.__init__(self, storage)
a = self.accounts.get(IMPORTED_ACCOUNT)
if not a:
self.accounts[IMPORTED_ACCOUNT] = ImportedAccount({'imported':{}})
def is_watching_only(self):
acc = self.accounts[IMPORTED_ACCOUNT]
n = acc.keypairs.values()
return n == [[None, None]] * len(n)
def has_seed(self):
return False
def is_deterministic(self):
return False
def check_password(self, password):
self.accounts[IMPORTED_ACCOUNT].get_private_key((0,0), self, password)
def is_used(self, address):
h = self.history.get(address,[])
return len(h), False
def get_master_public_keys(self):
return {}
def is_beyond_limit(self, address, account, is_change):
return False
class Deterministic_Wallet(Abstract_Wallet):
def __init__(self, storage):
Abstract_Wallet.__init__(self, storage)
def has_seed(self):
return self.seed != ''
def is_deterministic(self):
return True
def is_watching_only(self):
return not self.has_seed()
def add_seed(self, seed, password):
if self.seed:
raise Exception("a seed exists")
self.seed_version, self.seed = self.format_seed(seed)
if password:
self.seed = pw_encode( self.seed, password)
self.use_encryption = True
else:
self.use_encryption = False
self.storage.put('seed', self.seed, False)
self.storage.put('seed_version', self.seed_version, False)
self.storage.put('use_encryption', self.use_encryption,True)
def get_seed(self, password):
return pw_decode(self.seed, password)
def get_mnemonic(self, password):
return self.get_seed(password)
def change_gap_limit(self, value):
assert isinstance(value, int), 'gap limit must be of type int, not of %s'%type(value)
if value >= self.gap_limit:
self.gap_limit = value
self.storage.put('gap_limit', self.gap_limit, True)
return True
elif value >= self.min_acceptable_gap():
for key, account in self.accounts.items():
addresses = account.get_addresses(False)
k = self.num_unused_trailing_addresses(addresses)
n = len(addresses) - k + value
account.receiving_pubkeys = account.receiving_pubkeys[0:n]
account.receiving_addresses = account.receiving_addresses[0:n]
self.gap_limit = value
self.storage.put('gap_limit', self.gap_limit, True)
self.save_accounts()
return True
else:
return False
def num_unused_trailing_addresses(self, addresses):
k = 0
for a in addresses[::-1]:
if self.history.get(a):break
k = k + 1
return k
def min_acceptable_gap(self):
# fixme: this assumes wallet is synchronized
n = 0
nmax = 0
for account in self.accounts.values():
addresses = account.get_addresses(0)
k = self.num_unused_trailing_addresses(addresses)
for a in addresses[0:-k]:
if self.history.get(a):
n = 0
else:
n += 1
if n > nmax: nmax = n
return nmax + 1
def default_account(self):
return self.accounts['0']
def create_new_address(self, account=None, for_change=0):
if account is None:
account = self.default_account()
address = account.create_new_address(for_change)
self.add_address(address)
return address
def add_address(self, address):
if address not in self.history:
self.history[address] = []
if self.synchronizer:
self.synchronizer.add(address)
self.save_accounts()
def synchronize(self):
with self.lock:
for account in self.accounts.values():
account.synchronize(self)
def restore(self, callback):
from i18n import _
def wait_for_wallet():
self.set_up_to_date(False)
while not self.is_up_to_date():
msg = "%s\n%s %d"%(
_("Please wait..."),
_("Addresses generated:"),
len(self.addresses(True)))
apply(callback, (msg,))
time.sleep(0.1)
def wait_for_network():
while not self.network.is_connected():
msg = "%s \n" % (_("Connecting..."))
apply(callback, (msg,))
time.sleep(0.1)
# wait until we are connected, because the user might have selected another server
if self.network:
wait_for_network()
wait_for_wallet()
else:
self.synchronize()
def is_beyond_limit(self, address, account, is_change):
if type(account) == ImportedAccount:
return False
addr_list = account.get_addresses(is_change)
i = addr_list.index(address)
prev_addresses = addr_list[:max(0, i)]
limit = self.gap_limit_for_change if is_change else self.gap_limit
if len(prev_addresses) < limit:
return False
prev_addresses = prev_addresses[max(0, i - limit):]
for addr in prev_addresses:
if self.history.get(addr):
return False
return True
def get_action(self):
if not self.get_master_public_key():
return 'create_seed'
if not self.accounts:
return 'create_accounts'
def get_master_public_keys(self):
out = {}
for k, account in self.accounts.items():
name = self.get_account_name(k)
mpk_text = '\n\n'.join( account.get_master_pubkeys() )
out[name] = mpk_text
return out
class BIP32_Wallet(Deterministic_Wallet):
# abstract class, bip32 logic
root_name = 'x/'
def __init__(self, storage):
Deterministic_Wallet.__init__(self, storage)
self.master_public_keys = storage.get('master_public_keys', {})
self.master_private_keys = storage.get('master_private_keys', {})
self.gap_limit = storage.get('gap_limit', 20)
def is_watching_only(self):
return not bool(self.master_private_keys)
def can_import(self):
return False
def get_master_public_key(self):
return self.master_public_keys.get(self.root_name)
def get_master_private_key(self, account, password):
k = self.master_private_keys.get(account)
if not k: return
xprv = pw_decode(k, password)
try:
deserialize_xkey(xprv)
except:
raise InvalidPassword()
return xprv
def check_password(self, password):
xpriv = self.get_master_private_key(self.root_name, password)
xpub = self.master_public_keys[self.root_name]
if deserialize_xkey(xpriv)[3] != deserialize_xkey(xpub)[3]:
raise InvalidPassword()
def add_master_public_key(self, name, xpub):
if xpub in self.master_public_keys.values():
raise BaseException('Duplicate master public key')
self.master_public_keys[name] = xpub
self.storage.put('master_public_keys', self.master_public_keys, True)
def add_master_private_key(self, name, xpriv, password):
self.master_private_keys[name] = pw_encode(xpriv, password)
self.storage.put('master_private_keys', self.master_private_keys, True)
def derive_xkeys(self, root, derivation, password):
x = self.master_private_keys[root]
root_xprv = pw_decode(x, password)
xprv, xpub = bip32_private_derivation(root_xprv, root, derivation)
return xpub, xprv
def create_master_keys(self, password):
seed = self.get_seed(password)
self.add_cosigner_seed(seed, self.root_name, password)
def add_cosigner_seed(self, seed, name, password, passphrase=''):
# we don't store the seed, only the master xpriv
xprv, xpub = bip32_root(self.mnemonic_to_seed(seed, passphrase))
xprv, xpub = bip32_private_derivation(xprv, "m/", self.root_derivation)
self.add_master_public_key(name, xpub)
self.add_master_private_key(name, xprv, password)
def add_cosigner_xpub(self, seed, name):
# store only master xpub
xprv, xpub = bip32_root(self.mnemonic_to_seed(seed,''))
xprv, xpub = bip32_private_derivation(xprv, "m/", self.root_derivation)
self.add_master_public_key(name, xpub)
def mnemonic_to_seed(self, seed, password):
return Mnemonic.mnemonic_to_seed(seed, password)
def make_seed(self, lang=None):
return Mnemonic(lang).make_seed()
def format_seed(self, seed):
return NEW_SEED_VERSION, ' '.join(seed.split())
class BIP32_Simple_Wallet(BIP32_Wallet):
# Wallet with a single BIP32 account, no seed
# gap limit 20
wallet_type = 'xpub'
def create_xprv_wallet(self, xprv, password):
xpub = bitcoin.xpub_from_xprv(xprv)
account = BIP32_Account({'xpub':xpub})
self.storage.put('seed_version', self.seed_version, True)
self.add_master_private_key(self.root_name, xprv, password)
self.add_master_public_key(self.root_name, xpub)
self.add_account('0', account)
self.use_encryption = (password != None)
self.storage.put('use_encryption', self.use_encryption,True)
def create_xpub_wallet(self, xpub):
account = BIP32_Account({'xpub':xpub})
self.storage.put('seed_version', self.seed_version, True)
self.add_master_public_key(self.root_name, xpub)
self.add_account('0', account)
class BIP32_HD_Wallet(BIP32_Wallet):
# wallet that can create accounts
def __init__(self, storage):
self.next_account = storage.get('next_account2', None)
BIP32_Wallet.__init__(self, storage)
def can_create_accounts(self):
return self.root_name in self.master_private_keys.keys()
def addresses(self, b=True):
l = BIP32_Wallet.addresses(self, b)
if self.next_account:
_, _, _, next_address = self.next_account
if next_address not in l:
l.append(next_address)
return l
def get_address_index(self, address):
if self.next_account:
next_id, next_xpub, next_pubkey, next_address = self.next_account
if address == next_address:
return next_id, (0,0)
return BIP32_Wallet.get_address_index(self, address)
def num_accounts(self):
keys = []
for k, v in self.accounts.items():
if type(v) != BIP32_Account:
continue
keys.append(k)
i = 0
while True:
account_id = '%d'%i
if account_id not in keys:
break
i += 1
return i
def get_next_account(self, password):
account_id = '%d'%self.num_accounts()
derivation = self.root_name + "%d'"%int(account_id)
xpub, xprv = self.derive_xkeys(self.root_name, derivation, password)
self.add_master_public_key(derivation, xpub)
if xprv:
self.add_master_private_key(derivation, xprv, password)
account = BIP32_Account({'xpub':xpub})
addr, pubkey = account.first_address()
self.add_address(addr)
return account_id, xpub, pubkey, addr
def create_main_account(self, password):
# First check the password is valid (this raises if it isn't).
self.check_password(password)
assert self.num_accounts() == 0
self.create_account('Main account', password)
def create_account(self, name, password):
account_id, xpub, _, _ = self.get_next_account(password)
account = BIP32_Account({'xpub':xpub})
self.add_account(account_id, account)
self.set_label(account_id, name)
# add address of the next account
self.next_account = self.get_next_account(password)
self.storage.put('next_account2', self.next_account)
def account_is_pending(self, k):
return type(self.accounts.get(k)) == PendingAccount
def delete_pending_account(self, k):
assert type(self.accounts.get(k)) == PendingAccount
self.accounts.pop(k)
self.save_accounts()
def create_pending_account(self, name, password):
if self.next_account is None:
self.next_account = self.get_next_account(password)
self.storage.put('next_account2', self.next_account)
next_id, next_xpub, next_pubkey, next_address = self.next_account
if name:
self.set_label(next_id, name)
self.accounts[next_id] = PendingAccount({'pending':True, 'address':next_address, 'pubkey':next_pubkey})
self.save_accounts()
def synchronize(self):
# synchronize existing accounts
BIP32_Wallet.synchronize(self)
if self.next_account is None and not self.use_encryption:
try:
self.next_account = self.get_next_account(None)
self.storage.put('next_account2', self.next_account)
except:
print_error('cannot get next account')
# check pending account
if self.next_account is not None:
next_id, next_xpub, next_pubkey, next_address = self.next_account
if self.address_is_old(next_address):
print_error("creating account", next_id)
self.add_account(next_id, BIP32_Account({'xpub':next_xpub}))
# here the user should get a notification
self.next_account = None
self.storage.put('next_account2', self.next_account)
elif self.history.get(next_address, []):
if next_id not in self.accounts:
print_error("create pending account", next_id)
self.accounts[next_id] = PendingAccount({'pending':True, 'address':next_address, 'pubkey':next_pubkey})
self.save_accounts()
class NewWallet(BIP32_Wallet, Mnemonic):
# Standard wallet
root_derivation = "m/"
wallet_type = 'standard'
def create_main_account(self, password):
xpub = self.master_public_keys.get("x/")
account = BIP32_Account({'xpub':xpub})
self.add_account('0', account)
class Wallet_2of2(BIP32_Wallet, Mnemonic):
# Wallet with multisig addresses.
root_name = "x1/"
root_derivation = "m/"
wallet_type = '2of2'
def create_main_account(self, password):
xpub1 = self.master_public_keys.get("x1/")
xpub2 = self.master_public_keys.get("x2/")
account = BIP32_Account_2of2({'xpub':xpub1, 'xpub2':xpub2})
self.add_account('0', account)
def get_master_public_keys(self):
return self.master_public_keys
def get_action(self):
xpub1 = self.master_public_keys.get("x1/")
xpub2 = self.master_public_keys.get("x2/")
if xpub1 is None:
return 'create_seed'
if xpub2 is None:
return 'add_cosigner'
if not self.accounts:
return 'create_accounts'
class Wallet_2of3(Wallet_2of2):
# multisig 2 of 3
wallet_type = '2of3'
def create_main_account(self, password):
xpub1 = self.master_public_keys.get("x1/")
xpub2 = self.master_public_keys.get("x2/")
xpub3 = self.master_public_keys.get("x3/")
account = BIP32_Account_2of3({'xpub':xpub1, 'xpub2':xpub2, 'xpub3':xpub3})
self.add_account('0', account)
def get_action(self):
xpub1 = self.master_public_keys.get("x1/")
xpub2 = self.master_public_keys.get("x2/")
xpub3 = self.master_public_keys.get("x3/")
if xpub1 is None:
return 'create_seed'
if xpub2 is None or xpub3 is None:
return 'add_two_cosigners'
if not self.accounts:
return 'create_accounts'
class OldWallet(Deterministic_Wallet):
wallet_type = 'old'
def __init__(self, storage):
Deterministic_Wallet.__init__(self, storage)
self.gap_limit = storage.get('gap_limit', 5)
def make_seed(self):
import old_mnemonic
seed = random_seed(128)
return ' '.join(old_mnemonic.mn_encode(seed))
def format_seed(self, seed):
import old_mnemonic
# see if seed was entered as hex
seed = seed.strip()
try:
assert seed
seed.decode('hex')
return OLD_SEED_VERSION, str(seed)
except Exception:
pass
words = seed.split()
seed = old_mnemonic.mn_decode(words)
if not seed:
raise Exception("Invalid seed")
return OLD_SEED_VERSION, seed
def create_master_keys(self, password):
seed = self.get_seed(password)
mpk = OldAccount.mpk_from_seed(seed)
self.storage.put('master_public_key', mpk, True)
def get_master_public_key(self):
return self.storage.get("master_public_key")
def get_master_public_keys(self):
return {'Main Account':self.get_master_public_key()}
def create_main_account(self, password):
mpk = self.storage.get("master_public_key")
self.create_account(mpk)
def create_account(self, mpk):
self.accounts['0'] = OldAccount({'mpk':mpk, 0:[], 1:[]})
self.save_accounts()
def create_watching_only_wallet(self, mpk):
self.seed_version = OLD_SEED_VERSION
self.storage.put('seed_version', self.seed_version, False)
self.storage.put('master_public_key', mpk, True)
self.create_account(mpk)
def get_seed(self, password):
seed = pw_decode(self.seed, password).encode('utf8')
return seed
def check_password(self, password):
seed = self.get_seed(password)
self.accounts['0'].check_seed(seed)
def get_mnemonic(self, password):
import old_mnemonic
s = self.get_seed(password)
return ' '.join(old_mnemonic.mn_encode(s))
wallet_types = [
# category type description constructor
('standard', 'old', ("Old wallet"), OldWallet),
('standard', 'xpub', ("BIP32 Import"), BIP32_Simple_Wallet),
('standard', 'standard', ("Standard wallet"), NewWallet),
('standard', 'imported', ("Imported wallet"), Imported_Wallet),
('multisig', '2of2', ("Multisig wallet (2 of 2)"), Wallet_2of2),
('multisig', '2of3', ("Multisig wallet (2 of 3)"), Wallet_2of3)
]
# former WalletFactory
class Wallet(object):
"""The main wallet "entry point".
This class is actually a factory that will return a wallet of the correct
type when passed a WalletStorage instance."""
def __new__(self, storage):
seed_version = storage.get('seed_version')
if not seed_version:
seed_version = OLD_SEED_VERSION if len(storage.get('master_public_key','')) == 128 else NEW_SEED_VERSION
if seed_version not in [OLD_SEED_VERSION, NEW_SEED_VERSION]:
msg = "Your wallet has an unsupported seed version."
msg += '\n\nWallet file: %s' % os.path.abspath(storage.path)
if seed_version in [5, 7, 8, 9, 10]:
msg += "\n\nTo open this wallet, try 'git checkout seed_v%d'"%seed_version
if seed_version == 6:
# version 1.9.8 created v6 wallets when an incorrect seed was entered in the restore dialog
msg += '\n\nThis file was created because of a bug in version 1.9.8.'
if storage.get('master_public_keys') is None and storage.get('master_private_keys') is None and storage.get('imported_keys') is None:
# pbkdf2 was not included with the binaries, and wallet creation aborted.
msg += "\nIt does not contain any keys, and can safely be removed."
else:
# creation was complete if electrum was run from source
msg += "\nPlease open this file with Electrum 1.9.8, and move your coins to a new wallet."
raise BaseException(msg)
wallet_type = storage.get('wallet_type')
if wallet_type:
for cat, t, name, c in wallet_types:
if t == wallet_type:
WalletClass = c
break
else:
raise BaseException('unknown wallet type', wallet_type)
else:
if seed_version == OLD_SEED_VERSION:
WalletClass = OldWallet
else:
WalletClass = NewWallet
return WalletClass(storage)
@classmethod
def is_seed(self, seed):
if not seed:
return False
elif is_old_seed(seed):
return True
elif is_new_seed(seed):
return True
else:
return False
@classmethod
def is_old_mpk(self, mpk):
try:
int(mpk, 16)
assert len(mpk) == 128
return True
except:
return False
@classmethod
def is_xpub(self, text):
try:
assert text[0:4] in ('xpub', 'Ltub')
deserialize_xkey(text)
return True
except:
return False
@classmethod
def is_xprv(self, text):
try:
assert text[0:4] in ('xprv', 'Ltpv')
deserialize_xkey(text)
return True
except:
return False
@classmethod
def is_address(self, text):
if not text:
return False
for x in text.split():
if not bitcoin.is_address(x):
return False
return True
@classmethod
def is_private_key(self, text):
if not text:
return False
for x in text.split():
if not bitcoin.is_private_key(x):
return False
return True
@classmethod
def from_seed(self, seed, password, storage):
if is_old_seed(seed):
klass = OldWallet
elif is_new_seed(seed):
klass = NewWallet
w = klass(storage)
w.add_seed(seed, password)
w.create_master_keys(password)
w.create_main_account(password)
return w
@classmethod
def from_address(self, text, storage):
w = Imported_Wallet(storage)
for x in text.split():
w.accounts[IMPORTED_ACCOUNT].add(x, None, None, None)
w.save_accounts()
return w
@classmethod
def from_private_key(self, text, password, storage):
w = Imported_Wallet(storage)
w.update_password(None, password)
for x in text.split():
w.import_key(x, password)
return w
@classmethod
def from_old_mpk(self, mpk, storage):
w = OldWallet(storage)
w.seed = ''
w.create_watching_only_wallet(mpk)
return w
@classmethod
def from_xpub(self, xpub, storage):
w = BIP32_Simple_Wallet(storage)
w.create_xpub_wallet(xpub)
return w
@classmethod
def from_xprv(self, xprv, password, storage):
w = BIP32_Simple_Wallet(storage)
w.create_xprv_wallet(xprv, password)
return w
@classmethod
def from_multisig(klass, key_list, password, storage):
if len(key_list) == 2:
self = Wallet_2of2(storage)
elif len(key_list) == 3:
self = Wallet_2of3(storage)
key_list = sorted(key_list, key = lambda x: klass.is_xpub(x))
for i, text in enumerate(key_list):
assert klass.is_seed(text) or klass.is_xprv(text) or klass.is_xpub(text)
name = "x%d/"%(i+1)
if klass.is_seed(text):
if name == 'x1/':
self.add_seed(text, password)
self.create_master_keys(password)
else:
self.add_cosigner_seed(text, name, password)
elif klass.is_xprv(text):
xpub = bitcoin.xpub_from_xprv(text)
self.add_master_public_key(name, xpub)
self.add_master_private_key(name, text, password)
elif klass.is_xpub(text):
self.add_master_public_key(name, text)
self.use_encryption = (password != None)
self.storage.put('use_encryption', self.use_encryption, True)
self.create_main_account(password)
return self
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
662,
1264,
28430,
446,
10540,
3463,
21158,
1890,
199,
3,
1898,
334,
35,
9,
7760,
294,
676,
305,
86,
32,
3187,
16039,
1785,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
984,
199,
646,
747,
199,
646,
8337,
199,
646,
6073,
199,
646,
5796,
199,
646,
2196,
199,
646,
900,
199,
646,
3473,
199,
646,
2022,
199,
646,
1331,
199,
199,
504,
4884,
492,
870,
63,
1328,
12,
870,
63,
705,
12,
2832,
1327,
4937,
32197,
83,
199,
504,
4884,
492,
23173,
199,
199,
504,
27214,
492,
627,
199,
504,
2933,
492,
627,
199,
504,
1015,
492,
627,
199,
199,
504,
6008,
492,
18244,
199,
504,
8963,
492,
1255,
63,
3664,
199,
646,
27214,
199,
504,
15354,
1793,
492,
644,
9478,
21814,
1793,
199,
504,
18250,
16082,
492,
603,
685,
16082,
4388,
199,
3,
5007,
2870,
367,
8439,
2933,
199,
17576,
1149,
63,
18928,
275,
1994,
88,
7,
421,
199,
533,
644,
9478,
6408,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
931,
304,
267,
291,
14,
831,
275,
5796,
14,
30550,
342,
267,
291,
14,
576,
275,
1052,
267,
291,
14,
515,
275,
931,
267,
291,
14,
493,
63,
2444,
275,
756,
267,
870,
63,
705,
8,
298,
13892,
931,
401,
291,
14,
515,
776,
267,
340,
291,
14,
515,
26,
288,
291,
14,
739,
8,
277,
14,
515,
9,
339,
347,
1586,
8,
277,
12,
931,
304,
267,
408,
3284,
314,
4072,
402,
314,
20534,
570,
1041,
267,
862,
26,
288,
543,
1551,
8,
277,
14,
515,
12,
298,
82,
531,
465,
289,
26,
355,
666,
275,
289,
14,
739,
342,
267,
871,
5925,
26,
288,
372,
267,
862,
26,
288,
291,
14,
576,
275,
2022,
14,
3640,
8,
576,
9,
267,
871,
26,
288,
862,
26,
355,
366,
275,
6073,
14,
8939,
63,
2579,
8,
576,
9,
221,
327,
1122,
3066,
666,
687,
7664,
20534,
570,
288,
871,
2186,
465,
325,
26,
355,
746,
5925,
480,
6612,
1586,
20534,
570,
1543,
83,
4065,
450,
291,
14,
515,
9,
288,
291,
14,
576,
275,
1052,
288,
327,
1010,
2269,
5459,
402,
662,
1264,
28430,
3628,
4898,
16899,
17,
5737,
12,
642,
25079,
2059,
474,
14,
288,
3628,
275,
366,
14,
362,
360,
3512,
297,
5009,
288,
367,
284,
12,
1768,
315,
3628,
14,
1744,
837,
355,
862,
26,
490,
2649,
8,
1302,
9,
355,
871,
18965,
26,
490,
366,
459,
3512,
3488,
73,
61,
275,
2649,
8,
1302,
14,
2708,
360,
10378,
17,
1333,
288,
367,
790,
12,
574,
315,
366,
14,
1744,
837,
355,
862,
26,
490,
2022,
14,
4180,
8,
498,
9,
490,
2022,
14,
4180,
8,
585,
9,
355,
871,
26,
490,
870,
63,
705,
360,
4276,
370,
3957,
1768,
370,
2022,
1475,
297,
790,
9,
490,
1980,
355,
291,
14,
576,
59,
498,
61,
275,
574,
267,
291,
14,
493,
63,
2444,
275,
715,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
543,
291,
14,
831,
26,
288,
373,
275,
291,
14,
576,
14,
362,
8,
498,
9,
288,
340,
373,
365,
488,
26,
355,
373,
275,
849,
288,
587,
26,
355,
373,
275,
1331,
14,
8293,
8,
86,
9,
288,
372,
373,
339,
347,
5324,
8,
277,
12,
790,
12,
574,
12,
3354,
275,
715,
304,
267,
862,
26,
288,
2022,
14,
4180,
8,
498,
9,
288,
2022,
14,
4180,
8,
585,
9,
267,
871,
26,
288,
870,
63,
705,
480,
1001,
1125,
26,
3913,
3354,
401,
790,
9,
288,
372,
267,
543,
291,
14,
831,
26,
288,
340,
574,
365,
440,
488,
26,
355,
291,
14,
576,
59,
498,
61,
275,
1331,
14,
8293,
8,
585,
9,
288,
916,
790,
315,
291,
14,
576,
26,
355,
291,
14,
576,
14,
1935,
8,
498,
9,
288,
340,
3354,
26,
355,
291,
14,
952,
342,
339,
347,
2218,
8,
277,
304,
267,
702,
440,
5796,
14,
1818,
4436,
1252,
374,
20555,
342,
267,
2388,
63,
515,
275,
2071,
83,
14,
2791,
4111,
83,
2,
450,
334,
277,
14,
515,
12,
747,
14,
17829,
1012,
267,
308,
275,
2022,
14,
4180,
8,
277,
14,
576,
12,
4363,
29,
20,
12,
4069,
63,
1612,
29,
549,
9,
267,
543,
1551,
8,
808,
63,
515,
12,
298,
87,
531,
465,
289,
26,
288,
289,
14,
952,
8,
83,
9,
288,
289,
14,
4939,
342,
288,
747,
14,
2319,
1870,
8,
70,
14,
9843,
1012,
267,
327,
5147,
15374,
2218,
641,
18169,
10460,
267,
862,
26,
288,
747,
14,
8165,
8,
808,
63,
515,
12,
291,
14,
515,
9,
267,
871,
26,
288,
747,
14,
2168,
8,
277,
14,
515,
9,
288,
747,
14,
8165,
8,
808,
63,
515,
12,
291,
14,
515,
9,
267,
340,
283,
25658,
63,
3998,
7,
440,
315,
747,
14,
2314,
26,
288,
492,
5672,
288,
747,
14,
11693,
8,
277,
14,
515,
12,
3736,
14,
51,
63,
41,
5670,
1204,
5672,
14,
51,
63,
41,
10387,
9,
4388,
199,
533,
11836,
63,
55,
9478,
8,
785,
304,
272,
408,
272,
644,
9478,
3992,
787,
2737,
370,
2429,
7750,
2287,
10152,
3102,
14,
272,
12515,
296,
6363,
334,
6821,
316,
13,
2118,
12,
2849,
2933,
12,
949,
6347,
12,
5423,
9,
787,
8860,
6272,
3992,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
662,
1264,
28430,
446,
10540,
3463,
21158,
1890,
199,
3,
1898,
334,
35,
9,
7760,
294,
676,
305,
86,
32,
3187,
16039,
1785,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
646,
984,
199,
646,
747,
199,
646,
8337,
199,
646,
6073,
199,
646,
5796,
199,
646,
2196,
199,
646,
900,
199,
646,
3473,
199,
646,
2022,
199,
646,
1331,
199,
199,
504,
4884,
492,
870,
63,
1328,
12,
870,
63,
705,
12,
2832,
1327,
4937,
32197,
83,
199,
504,
4884,
492,
23173,
199,
199,
504,
27214,
492,
627,
199,
504,
2933,
492,
627,
199,
504,
1015,
492,
627,
199,
199,
504,
6008,
492,
18244,
199,
504,
8963,
492,
1255,
63,
3664,
199,
646,
27214,
199,
504,
15354,
1793,
492,
644,
9478,
21814,
1793,
199,
504,
18250,
16082,
492,
603,
685,
16082,
4388,
199,
3,
5007,
2870,
367,
8439,
2933,
199,
17576,
1149,
63,
18928,
275,
1994,
88,
7,
421,
199,
533,
644,
9478,
6408,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
931,
304,
267,
291,
14,
831,
275,
5796,
14,
30550,
342,
267,
291,
14,
576,
275,
1052,
267,
291,
14,
515,
275,
931,
267,
291,
14,
493,
63,
2444,
275,
756,
267,
870,
63,
705,
8,
298,
13892,
931,
401,
291,
14,
515,
776,
267,
340,
291,
14,
515,
26,
288,
291,
14,
739,
8,
277,
14,
515,
9,
339,
347,
1586,
8,
277,
12,
931,
304,
267,
408,
3284,
314,
4072,
402,
314,
20534,
570,
1041,
267,
862,
26,
288,
543,
1551,
8,
277,
14,
515,
12,
298,
82,
531,
465,
289,
26,
355,
666,
275,
289,
14,
739,
342,
267,
871,
5925,
26,
288,
372,
267,
862,
26,
288,
291,
14,
576,
275,
2022,
14,
3640,
8,
576,
9,
267,
871,
26,
288,
862,
26,
355,
366,
275,
6073,
14,
8939,
63,
2579,
8,
576,
9,
221,
327,
1122,
3066,
666,
687,
7664,
20534,
570,
288,
871,
2186,
465,
325,
26,
355,
746,
5925,
480,
6612,
1586,
20534,
570,
1543,
83,
4065,
450,
291,
14,
515,
9,
288,
291,
14,
576,
275,
1052,
288,
327,
1010,
2269,
5459,
402,
662,
1264,
28430,
3628,
4898,
16899,
17,
5737,
12,
642,
25079,
2059,
474,
14,
288,
3628,
275,
366,
14,
362,
360,
3512,
297,
5009,
288,
367,
284,
12,
1768,
315,
3628,
14,
1744,
837,
355,
862,
26,
490,
2649,
8,
1302,
9,
355,
871,
18965,
26,
490,
366,
459,
3512,
3488,
73,
61,
275,
2649,
8,
1302,
14,
2708,
360,
10378,
17,
1333,
288,
367,
790,
12,
574,
315,
366,
14,
1744,
837,
355,
862,
26,
490,
2022,
14,
4180,
8,
498,
9,
490,
2022,
14,
4180,
8,
585,
9,
355,
871,
26,
490,
870,
63,
705,
360,
4276,
370,
3957,
1768,
370,
2022,
1475,
297,
790,
9,
490,
1980,
355,
291,
14,
576,
59,
498,
61,
275,
574,
267,
291,
14,
493,
63,
2444,
275,
715,
339,
347,
664,
8,
277,
12,
790,
12,
849,
29,
403,
304,
267,
543,
291,
14,
831,
26,
288,
373,
275,
291,
14,
576,
14,
362,
8,
498,
9,
288,
340,
373,
365,
488,
26,
355,
373,
275,
849,
288,
587,
26,
355,
373,
275,
1331,
14,
8293,
8,
86,
9,
288,
372,
373,
339,
347,
5324,
8,
277,
12,
790,
12,
574,
12,
3354,
275,
715,
304,
267,
862,
26,
288,
2022,
14,
4180,
8,
498,
9,
288,
2022,
14,
4180,
8,
585,
9,
267,
871,
26,
288,
870,
63,
705,
480,
1001,
1125,
26,
3913,
3354,
401,
790,
9,
288,
372,
267,
543,
291,
14,
831,
26,
288,
340,
574,
365,
440,
488,
26,
355,
291,
14,
576,
59,
498,
61,
275,
1331,
14,
8293,
8,
585,
9,
288,
916,
790,
315,
291,
14,
576,
26,
355,
291,
14,
576,
14,
1935,
8,
498,
9,
288,
340,
3354,
26,
355,
291,
14,
952,
342,
339,
347,
2218,
8,
277,
304,
267,
702,
440,
5796,
14,
1818,
4436,
1252,
374,
20555,
342,
267,
2388,
63,
515,
275,
2071,
83,
14,
2791,
4111,
83,
2,
450,
334,
277,
14,
515,
12,
747,
14,
17829,
1012,
267,
308,
275,
2022,
14,
4180,
8,
277,
14,
576,
12,
4363,
29,
20,
12,
4069,
63,
1612,
29,
549,
9,
267,
543,
1551,
8,
808,
63,
515,
12,
298,
87,
531,
465,
289,
26,
288,
289,
14,
952,
8,
83,
9,
288,
289,
14,
4939,
342,
288,
747,
14,
2319,
1870,
8,
70,
14,
9843,
1012,
267,
327,
5147,
15374,
2218,
641,
18169,
10460,
267,
862,
26,
288,
747,
14,
8165,
8,
808,
63,
515,
12,
291,
14,
515,
9,
267,
871,
26,
288,
747,
14,
2168,
8,
277,
14,
515,
9,
288,
747,
14,
8165,
8,
808,
63,
515,
12,
291,
14,
515,
9,
267,
340,
283,
25658,
63,
3998,
7,
440,
315,
747,
14,
2314,
26,
288,
492,
5672,
288,
747,
14,
11693,
8,
277,
14,
515,
12,
3736,
14,
51,
63,
41,
5670,
1204,
5672,
14,
51,
63,
41,
10387,
9,
4388,
199,
533,
11836,
63,
55,
9478,
8,
785,
304,
272,
408,
272,
644,
9478,
3992,
787,
2737,
370,
2429,
7750,
2287,
10152,
3102,
14,
272,
12515,
296,
6363,
334,
6821,
316,
13,
2118,
12,
2849,
2933,
12,
949,
6347,
12,
5423,
9,
787,
8860,
6272,
3992,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
noba3/KoTos
|
addons/script.module.universal/lib/universal/_common.py
|
4
|
5388
|
'''
universal XBMC module
Copyright (C) 2013 the-one @ XUNITYTALK.COM
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
'''
import os
from t0mm0.common.addon import Addon
import xbmc
import xbmcvfs
import xbmcgui
addon = Addon('script.module.universal')
addon_path = addon.get_path()
default_path = 'special://profile/addon_data/script.module.universal/'
db_path = addon.get_setting('local_save_location')
use_remote_db = addon.get_setting('use_remote_db')
db_address = addon.get_setting('db_address')
db_port = addon.get_setting('db_port')
if db_port: db_address = '%s:%s' %(db_address,db_port)
db_user = addon.get_setting('db_user')
db_pass = addon.get_setting('db_pass')
db_name = addon.get_setting('db_name')
def make_dir(mypath, dirname):
''' Creates sub-directories if they are not found. '''
subpath = os.path.join(mypath, dirname)
if not xbmcvfs.exists(subpath):
try:
xbmcvfs.mkdirs(subpath)
except:
xbmcvfs.mkdir(subpath)
return subpath
def bool2str(myinput):
if myinput is False: return 'false'
elif myinput is True: return 'true'
def str2bool(myinput):
if myinput == 'false': return False
elif myinput == 'true': return True
def str_conv(data):
if isinstance(data, str):
# Must be encoded in UTF-8
data = data.decode('utf8')
import unicodedata
data = unicodedata.normalize('NFKD', data).encode('ascii','ignore')
data = data.decode('string-escape')
return data
def encode_dict(dict):
out_dict = {}
for k, v in dict.iteritems():
v = str_conv(v)
if v.find(',') >= 0:
v = v.replace(',', '<comma>')
if v.find("'") >= 0:
v = v.replace("'", '<squot>')
if v.find('"') >= 0:
v = v.replace('"', '<dquot>')
if v.find('{') >= 0:
v = v.replace('{', '<ltbrc>')
if v.find('}') >= 0:
v = v.replace('}', '<rtbrc>')
if v.find(':') >= 0:
v = v.replace(':', '<colon>')
out_dict[k] = v
return out_dict
def decode_dict(dict):
out_dict = {}
for k, v in dict.iteritems():
v = str_conv(v)
if v.find('<comma>') >= 0:
v = v.replace('<comma>', ',')
if v.find("<squot>") >= 0:
v = v.replace("<squot>", "'")
if v.find('<dquot>') >= 0:
v = v.replace("<dquot>", '"')
if v.find('<ltbrc>') >= 0:
v = v.replace('<ltbrc>', '{')
if v.find('<rtbrc>') >= 0:
v = v.replace('<rtbrc>', '}')
if v.find('<colon>') >= 0:
v = v.replace('<colon>', ':')
out_dict[k] = v
return out_dict
def dict_to_paramstr(dict):
out_dict = {}
for k, v in dict.iteritems():
if isinstance(v, unicode):
v = v.encode('utf8')
elif isinstance(v, str):
# Must be encoded in UTF-8
v.decode('utf8')
out_dict[k] = v
import urllib
return urllib.urlencode(out_dict)
def notify(addon_id, typeq, title, message, times, line2='', line3=''):
addon_tmp = Addon(addon_id)
if title == '' :
title='[B]' + addon_tmp.get_name() + '[/B]'
if typeq == 'small':
if times == '':
times='5000'
smallicon= addon_tmp.get_icon()
xbmc.executebuiltin("XBMC.Notification("+title+","+message+","+times+","+smallicon+")")
elif typeq == 'big':
dialog = xbmcgui.Dialog()
dialog.ok(' '+title+' ', ' '+message+' ', line2, line3)
else:
dialog = xbmcgui.Dialog()
dialog.ok(' '+title+' ', ' '+message+' ')
def TextBoxes(heading,anounce):
class TextBox():
"""Thanks to BSTRDMKR for this code:)"""
# constants
WINDOW = 10147
CONTROL_LABEL = 1
CONTROL_TEXTBOX = 5
def __init__( self, *args, **kwargs):
# activate the text viewer window
xbmc.executebuiltin( "ActivateWindow(%d)" % ( self.WINDOW, ) )
# get window
self.win = xbmcgui.Window( self.WINDOW )
# give window time to initialize
xbmc.sleep( 500 )
self.setControls()
xbmc.sleep( 500 )
def setControls( self ):
# set heading
self.win.getControl( self.CONTROL_LABEL ).setLabel(heading)
try:
f = open(anounce)
text = f.read()
except:
text=anounce
self.win.getControl( self.CONTROL_TEXTBOX ).setText(text)
return
TextBox()
|
gpl-2.0
|
[
2344,
272,
17508,
1323,
28994,
859,
272,
1898,
334,
35,
9,
6171,
314,
13,
368,
768,
1323,
1734,
1922,
52,
748,
43,
14,
11265,
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,
199,
199,
646,
747,
258,
199,
504,
307,
16,
596,
16,
14,
2330,
14,
9291,
492,
29366,
199,
646,
11709,
199,
646,
10346,
77,
5107,
2319,
199,
646,
26418,
199,
199,
9291,
275,
29366,
360,
1579,
14,
578,
14,
24866,
358,
199,
9291,
63,
515,
275,
13553,
14,
362,
63,
515,
342,
199,
199,
885,
63,
515,
275,
283,
6664,
921,
2913,
15,
9291,
63,
576,
15,
1579,
14,
578,
14,
24866,
4805,
199,
199,
697,
63,
515,
275,
13553,
14,
362,
63,
6031,
360,
1832,
63,
2117,
63,
1985,
358,
199,
1180,
63,
3846,
63,
697,
275,
13553,
14,
362,
63,
6031,
360,
1180,
63,
3846,
63,
697,
358,
199,
697,
63,
1562,
275,
13553,
14,
362,
63,
6031,
360,
697,
63,
1562,
358,
199,
697,
63,
719,
275,
13553,
14,
362,
63,
6031,
360,
697,
63,
719,
358,
199,
692,
1592,
63,
719,
26,
1592,
63,
1562,
275,
1543,
83,
2689,
83,
7,
2818,
697,
63,
1562,
12,
697,
63,
719,
9,
199,
697,
63,
751,
275,
13553,
14,
362,
63,
6031,
360,
697,
63,
751,
358,
199,
697,
63,
1529,
275,
13553,
14,
362,
63,
6031,
360,
697,
63,
1529,
358,
199,
697,
63,
354,
275,
13553,
14,
362,
63,
6031,
360,
697,
63,
354,
358,
199,
199,
318,
1852,
63,
694,
8,
1662,
515,
12,
9017,
304,
272,
1449,
10560,
1007,
13,
12629,
340,
2985,
787,
440,
1911,
14,
1449,
272,
25582,
275,
747,
14,
515,
14,
904,
8,
1662,
515,
12,
9017,
9,
272,
340,
440,
10346,
77,
5107,
2319,
14,
2444,
8,
954,
515,
304,
4960,
862,
26,
288,
10346,
77,
5107,
2319,
14,
3880,
3220,
8,
954,
515,
9,
267,
871,
26,
288,
10346,
77,
5107,
2319,
14,
8215,
8,
954,
515,
9,
272,
372,
25582,
1362,
199,
318,
2155,
18,
495,
8,
1662,
1210,
304,
14821,
340,
3002,
1210,
365,
756,
26,
372,
283,
3910,
7,
272,
916,
3002,
1210,
365,
715,
26,
372,
283,
2052,
7,
1362,
199,
318,
620,
18,
2245,
8,
1662,
1210,
304,
14821,
340,
3002,
1210,
508,
283,
3910,
356,
372,
756,
272,
916,
3002,
1210,
508,
283,
2052,
356,
372,
715,
1362,
199,
318,
620,
63,
5598,
8,
576,
304,
272,
340,
1228,
8,
576,
12,
620,
304,
267,
327,
9498,
506,
5737,
315,
9094,
13,
24,
267,
666,
275,
666,
14,
2708,
360,
1624,
24,
358,
507,
272,
492,
23128,
272,
666,
275,
23128,
14,
7721,
360,
19749,
13368,
297,
666,
680,
2143,
360,
4371,
1673,
4247,
358,
507,
272,
666,
275,
666,
14,
2708,
360,
875,
13,
3765,
358,
5493,
372,
666,
268,
199,
318,
3752,
63,
807,
8,
807,
304,
272,
734,
63,
807,
275,
1052,
272,
367,
1022,
12,
373,
315,
1211,
14,
4611,
837,
267,
373,
275,
620,
63,
5598,
8,
86,
9,
267,
340,
373,
14,
1623,
11917,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
32718,
2650,
13184,
5971,
267,
340,
373,
14,
1623,
480,
9859,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
27769,
2650,
83,
5184,
5971,
267,
340,
373,
14,
1623,
25441,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
20630,
2650,
68,
5184,
5971,
267,
340,
373,
14,
1623,
11117,
358,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
11117,
297,
2650,
4116,
66,
1195,
5971,
267,
340,
373,
14,
1623,
31358,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
360,
7293,
2650,
2591,
66,
1195,
5971,
267,
340,
373,
14,
1623,
11633,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
16451,
2650,
12167,
5971,
267,
734,
63,
807,
59,
75,
61,
275,
373,
272,
372,
734,
63,
807,
1362,
199,
318,
4849,
63,
807,
8,
807,
304,
272,
734,
63,
807,
275,
1052,
272,
367,
1022,
12,
373,
315,
1211,
14,
4611,
837,
267,
373,
275,
620,
63,
5598,
8,
86,
9,
267,
340,
373,
14,
1623,
4827,
13184,
5971,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
4827,
13184,
4206,
1656,
358,
267,
340,
373,
14,
1623,
6757,
83,
5184,
9579,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
6757,
83,
5184,
7166,
3546,
531,
267,
340,
373,
14,
1623,
4827,
68,
5184,
5971,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
6757,
68,
5184,
7166,
5522,
358,
267,
340,
373,
14,
1623,
4827,
4116,
66,
1195,
5971,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
4827,
4116,
66,
1195,
4206,
5041,
358,
267,
340,
373,
14,
1623,
4827,
2591,
66,
1195,
5971,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
4827,
2591,
66,
1195,
4206,
283,
12216,
267,
340,
373,
14,
1623,
4827,
12167,
5971,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
4827,
12167,
4206,
7596,
358,
18418,
734,
63,
807,
59,
75,
61,
275,
373,
272,
372,
734,
63,
807,
258,
199,
199,
318,
1211,
63,
475,
63,
635,
495,
8,
807,
304,
272,
734,
63,
807,
275,
1052,
272,
367,
1022,
12,
373,
315,
1211,
14,
4611,
837,
267,
340,
1228,
8,
86,
12,
2649,
304,
288,
373,
275,
373,
14,
2143,
360,
1624,
24,
358,
267,
916,
1228,
8,
86,
12,
620,
304,
288,
327,
9498,
506,
5737,
315,
9094,
13,
24,
288,
373,
14,
2708,
360,
1624,
24
] |
[
272,
17508,
1323,
28994,
859,
272,
1898,
334,
35,
9,
6171,
314,
13,
368,
768,
1323,
1734,
1922,
52,
748,
43,
14,
11265,
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,
199,
199,
646,
747,
258,
199,
504,
307,
16,
596,
16,
14,
2330,
14,
9291,
492,
29366,
199,
646,
11709,
199,
646,
10346,
77,
5107,
2319,
199,
646,
26418,
199,
199,
9291,
275,
29366,
360,
1579,
14,
578,
14,
24866,
358,
199,
9291,
63,
515,
275,
13553,
14,
362,
63,
515,
342,
199,
199,
885,
63,
515,
275,
283,
6664,
921,
2913,
15,
9291,
63,
576,
15,
1579,
14,
578,
14,
24866,
4805,
199,
199,
697,
63,
515,
275,
13553,
14,
362,
63,
6031,
360,
1832,
63,
2117,
63,
1985,
358,
199,
1180,
63,
3846,
63,
697,
275,
13553,
14,
362,
63,
6031,
360,
1180,
63,
3846,
63,
697,
358,
199,
697,
63,
1562,
275,
13553,
14,
362,
63,
6031,
360,
697,
63,
1562,
358,
199,
697,
63,
719,
275,
13553,
14,
362,
63,
6031,
360,
697,
63,
719,
358,
199,
692,
1592,
63,
719,
26,
1592,
63,
1562,
275,
1543,
83,
2689,
83,
7,
2818,
697,
63,
1562,
12,
697,
63,
719,
9,
199,
697,
63,
751,
275,
13553,
14,
362,
63,
6031,
360,
697,
63,
751,
358,
199,
697,
63,
1529,
275,
13553,
14,
362,
63,
6031,
360,
697,
63,
1529,
358,
199,
697,
63,
354,
275,
13553,
14,
362,
63,
6031,
360,
697,
63,
354,
358,
199,
199,
318,
1852,
63,
694,
8,
1662,
515,
12,
9017,
304,
272,
1449,
10560,
1007,
13,
12629,
340,
2985,
787,
440,
1911,
14,
1449,
272,
25582,
275,
747,
14,
515,
14,
904,
8,
1662,
515,
12,
9017,
9,
272,
340,
440,
10346,
77,
5107,
2319,
14,
2444,
8,
954,
515,
304,
4960,
862,
26,
288,
10346,
77,
5107,
2319,
14,
3880,
3220,
8,
954,
515,
9,
267,
871,
26,
288,
10346,
77,
5107,
2319,
14,
8215,
8,
954,
515,
9,
272,
372,
25582,
1362,
199,
318,
2155,
18,
495,
8,
1662,
1210,
304,
14821,
340,
3002,
1210,
365,
756,
26,
372,
283,
3910,
7,
272,
916,
3002,
1210,
365,
715,
26,
372,
283,
2052,
7,
1362,
199,
318,
620,
18,
2245,
8,
1662,
1210,
304,
14821,
340,
3002,
1210,
508,
283,
3910,
356,
372,
756,
272,
916,
3002,
1210,
508,
283,
2052,
356,
372,
715,
1362,
199,
318,
620,
63,
5598,
8,
576,
304,
272,
340,
1228,
8,
576,
12,
620,
304,
267,
327,
9498,
506,
5737,
315,
9094,
13,
24,
267,
666,
275,
666,
14,
2708,
360,
1624,
24,
358,
507,
272,
492,
23128,
272,
666,
275,
23128,
14,
7721,
360,
19749,
13368,
297,
666,
680,
2143,
360,
4371,
1673,
4247,
358,
507,
272,
666,
275,
666,
14,
2708,
360,
875,
13,
3765,
358,
5493,
372,
666,
268,
199,
318,
3752,
63,
807,
8,
807,
304,
272,
734,
63,
807,
275,
1052,
272,
367,
1022,
12,
373,
315,
1211,
14,
4611,
837,
267,
373,
275,
620,
63,
5598,
8,
86,
9,
267,
340,
373,
14,
1623,
11917,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
32718,
2650,
13184,
5971,
267,
340,
373,
14,
1623,
480,
9859,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
27769,
2650,
83,
5184,
5971,
267,
340,
373,
14,
1623,
25441,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
20630,
2650,
68,
5184,
5971,
267,
340,
373,
14,
1623,
11117,
358,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
11117,
297,
2650,
4116,
66,
1195,
5971,
267,
340,
373,
14,
1623,
31358,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
360,
7293,
2650,
2591,
66,
1195,
5971,
267,
340,
373,
14,
1623,
11633,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
16451,
2650,
12167,
5971,
267,
734,
63,
807,
59,
75,
61,
275,
373,
272,
372,
734,
63,
807,
1362,
199,
318,
4849,
63,
807,
8,
807,
304,
272,
734,
63,
807,
275,
1052,
272,
367,
1022,
12,
373,
315,
1211,
14,
4611,
837,
267,
373,
275,
620,
63,
5598,
8,
86,
9,
267,
340,
373,
14,
1623,
4827,
13184,
5971,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
4827,
13184,
4206,
1656,
358,
267,
340,
373,
14,
1623,
6757,
83,
5184,
9579,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
6757,
83,
5184,
7166,
3546,
531,
267,
340,
373,
14,
1623,
4827,
68,
5184,
5971,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
6757,
68,
5184,
7166,
5522,
358,
267,
340,
373,
14,
1623,
4827,
4116,
66,
1195,
5971,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
4827,
4116,
66,
1195,
4206,
5041,
358,
267,
340,
373,
14,
1623,
4827,
2591,
66,
1195,
5971,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
4827,
2591,
66,
1195,
4206,
283,
12216,
267,
340,
373,
14,
1623,
4827,
12167,
5971,
2356,
378,
26,
288,
373,
275,
373,
14,
1814,
4827,
12167,
4206,
7596,
358,
18418,
734,
63,
807,
59,
75,
61,
275,
373,
272,
372,
734,
63,
807,
258,
199,
199,
318,
1211,
63,
475,
63,
635,
495,
8,
807,
304,
272,
734,
63,
807,
275,
1052,
272,
367,
1022,
12,
373,
315,
1211,
14,
4611,
837,
267,
340,
1228,
8,
86,
12,
2649,
304,
288,
373,
275,
373,
14,
2143,
360,
1624,
24,
358,
267,
916,
1228,
8,
86,
12,
620,
304,
288,
327,
9498,
506,
5737,
315,
9094,
13,
24,
288,
373,
14,
2708,
360,
1624,
24,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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.py
|
5
|
1332
|
# Copyright 2013-2020 Lawrence Livermore National Security, LLC and other
# Spack Project Developers. See the top-level COPYRIGHT file for details.
#
# SPDX-License-Identifier: (Apache-2.0 OR MIT)
from spack import *
class RParty(RPackage):
"""A computational toolbox for recursive partitioning."""
homepage = "https://cloud.r-project.org/package=party"
url = "https://cloud.r-project.org/src/contrib/party_1.1-2.tar.gz"
list_url = "https://cloud.r-project.org/src/contrib/Archive/party"
version('1.3-3', sha256='9f72eea02d43a4cee105790ae7185b0478deb6011ab049cc9d31a0df3abf7ce9')
version('1.3-2', sha256='9f350fa21114151c49bccc3d5f8536dbc5a608cfd88f60461c9805a4c630510b')
version('1.1-2', sha256='c3632b4b02dc12ec949e2ee5b24004e4a4768b0bc9737432e9a85acbc2ed0e74')
depends_on('r@2.14.0:', when='@:1.2-2', type=('build', 'run'))
depends_on('r@3.0.0:', when='@1.2-3:', type=('build', 'run'))
depends_on('r-mvtnorm@1.0-2:', type=('build', 'run'))
depends_on('r-modeltools@0.2-21:', type=('build', 'run'))
depends_on('r-strucchange', type=('build', 'run'))
depends_on('r-survival@2.37-7:', type=('build', 'run'))
depends_on('r-coin@1.1-0:', type=('build', 'run'))
depends_on('r-zoo', type=('build', 'run'))
depends_on('r-sandwich@1.1-1:', type=('build', 'run'))
|
lgpl-2.1
|
[
3,
1898,
6171,
13,
13934,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
436,
1163,
199,
3,
428,
1389,
7290,
23493,
14,
1666,
314,
2746,
13,
1896,
5877,
570,
367,
2436,
14,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
334,
28993,
13,
18,
14,
16,
1549,
10697,
9,
199,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
820,
25233,
8,
50,
8599,
304,
272,
408,
33,
28319,
6279,
4744,
1977,
367,
9133,
6484,
316,
1041,
339,
26586,
275,
298,
2859,
921,
4091,
14,
82,
13,
1715,
14,
1308,
15,
2491,
29,
7522,
2,
272,
1166,
420,
275,
298,
2859,
921,
4091,
14,
82,
13,
1715,
14,
1308,
15,
2164,
15,
2828,
15,
7522,
63,
17,
14,
17,
13,
18,
14,
5369,
14,
6838,
2,
272,
769,
63,
633,
275,
298,
2859,
921,
4091,
14,
82,
13,
1715,
14,
1308,
15,
2164,
15,
2828,
15,
13042,
15,
7522,
2,
339,
1015,
360,
17,
14,
19,
13,
19,
297,
7793,
3912,
534,
25,
70,
2819,
1024,
65,
996,
68,
2824,
65,
20,
29377,
709,
1641,
2710,
3624,
23,
10233,
66,
966,
2277,
16762,
22,
13059,
371,
12809,
2055,
25,
68,
2192,
65,
16,
1587,
19,
32706,
23,
301,
25,
358,
272,
1015,
360,
17,
14,
19,
13,
18,
297,
7793,
3912,
534,
25,
70,
13595,
667,
12832,
1079,
12768,
67,
1887,
66,
19504,
19,
68,
21,
70,
2426,
1344,
16845,
21,
65,
32700,
27901,
1299,
70,
30320,
2976,
67,
25,
13027,
65,
20,
67,
22,
11565,
709,
66,
358,
272,
1015,
360,
17,
14,
17,
13,
18,
297,
7793,
3912,
534,
67,
1344,
708,
66,
20,
66,
996,
3833,
713,
825,
15674,
69,
18,
1024,
21,
66,
1194,
7979,
69,
20,
65,
20,
14408,
66,
16,
3776,
2576,
9880,
708,
69,
25,
65,
2426,
645,
3776,
18,
379,
16,
69,
1342,
358,
339,
8350,
63,
265,
360,
82,
32,
18,
14,
1079,
14,
16,
6536,
1380,
534,
32,
26,
17,
14,
18,
13,
18,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
32,
19,
14,
16,
14,
16,
6536,
1380,
534,
32,
17,
14,
18,
13,
19,
6536,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
77,
5941,
4791,
32,
17,
14,
16,
13,
18,
6536,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
1238,
2537,
32,
16,
14,
18,
13,
2025,
6536,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
9853,
1461,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
5105,
433,
637,
32,
18,
14,
1401,
13,
23,
6536,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
9061,
32,
17,
14,
17,
13,
16,
6536,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
90,
1534,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
83,
460,
87,
1158,
32,
17,
14,
17,
13,
17,
6536,
730,
7782,
1506,
297,
283,
1065,
1333,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6171,
13,
13934,
7964,
29590,
491,
4380,
6878,
20548,
13863,
12,
20376,
436,
1163,
199,
3,
428,
1389,
7290,
23493,
14,
1666,
314,
2746,
13,
1896,
5877,
570,
367,
2436,
14,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
334,
28993,
13,
18,
14,
16,
1549,
10697,
9,
199,
199,
504,
308,
1389,
492,
627,
421,
199,
533,
820,
25233,
8,
50,
8599,
304,
272,
408,
33,
28319,
6279,
4744,
1977,
367,
9133,
6484,
316,
1041,
339,
26586,
275,
298,
2859,
921,
4091,
14,
82,
13,
1715,
14,
1308,
15,
2491,
29,
7522,
2,
272,
1166,
420,
275,
298,
2859,
921,
4091,
14,
82,
13,
1715,
14,
1308,
15,
2164,
15,
2828,
15,
7522,
63,
17,
14,
17,
13,
18,
14,
5369,
14,
6838,
2,
272,
769,
63,
633,
275,
298,
2859,
921,
4091,
14,
82,
13,
1715,
14,
1308,
15,
2164,
15,
2828,
15,
13042,
15,
7522,
2,
339,
1015,
360,
17,
14,
19,
13,
19,
297,
7793,
3912,
534,
25,
70,
2819,
1024,
65,
996,
68,
2824,
65,
20,
29377,
709,
1641,
2710,
3624,
23,
10233,
66,
966,
2277,
16762,
22,
13059,
371,
12809,
2055,
25,
68,
2192,
65,
16,
1587,
19,
32706,
23,
301,
25,
358,
272,
1015,
360,
17,
14,
19,
13,
18,
297,
7793,
3912,
534,
25,
70,
13595,
667,
12832,
1079,
12768,
67,
1887,
66,
19504,
19,
68,
21,
70,
2426,
1344,
16845,
21,
65,
32700,
27901,
1299,
70,
30320,
2976,
67,
25,
13027,
65,
20,
67,
22,
11565,
709,
66,
358,
272,
1015,
360,
17,
14,
17,
13,
18,
297,
7793,
3912,
534,
67,
1344,
708,
66,
20,
66,
996,
3833,
713,
825,
15674,
69,
18,
1024,
21,
66,
1194,
7979,
69,
20,
65,
20,
14408,
66,
16,
3776,
2576,
9880,
708,
69,
25,
65,
2426,
645,
3776,
18,
379,
16,
69,
1342,
358,
339,
8350,
63,
265,
360,
82,
32,
18,
14,
1079,
14,
16,
6536,
1380,
534,
32,
26,
17,
14,
18,
13,
18,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
32,
19,
14,
16,
14,
16,
6536,
1380,
534,
32,
17,
14,
18,
13,
19,
6536,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
77,
5941,
4791,
32,
17,
14,
16,
13,
18,
6536,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
1238,
2537,
32,
16,
14,
18,
13,
2025,
6536,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
9853,
1461,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
5105,
433,
637,
32,
18,
14,
1401,
13,
23,
6536,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
9061,
32,
17,
14,
17,
13,
16,
6536,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
90,
1534,
297,
730,
7782,
1506,
297,
283,
1065,
1333,
272,
8350,
63,
265,
360,
82,
13,
83,
460,
87,
1158,
32,
17,
14,
17,
13,
17,
6536,
730,
7782,
1506,
297,
283,
1065,
1333,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
ioam/topographica
|
models/stevens.jn13/jn13_figures/lib/rasterplots.py
|
3
|
5394
|
"""
Rasterplots
Utilities for raster image manipulation (e.g. OR maps) using
PIL/Pillow and Numpy. Used for visualizing orientation maps (with and
without selectivity), polar FFT spectra and afferent model weight
patterns.
"""
import Image
import ImageOps
import numpy as np
import colorsys
rgb_to_hsv = np.vectorize(colorsys.rgb_to_hsv)
hsv_to_rgb = np.vectorize(colorsys.hsv_to_rgb)
def black_selectivity(image, whitelevel=0.2):
"""
Makes zero selectivity black for publication. Swaps saturation and
value and scales saturation by the whitelevel.
"""
whitefactor = 1.0 / whitelevel # 25% multiplies by 4.0
image_rgba = image.convert('RGBA')
arr = np.asarray(image_rgba).astype('float')
r, g, b, a = np.rollaxis(arr, axis=-1)
h, s, v = rgb_to_hsv(r, g, b) # s is [0,1] all v are 255.0
s *= (255.0 * whitefactor)
r, g, b = hsv_to_rgb(h, (v / 255.0), np.clip(s, 0, 255.0))
arr_stack = np.dstack((r, g, b, a))
return Image.fromarray(arr_stack.astype('uint8'), 'RGBA')
def OR_map(preference, selectivity=None):
"""
Supply the raw preference and (optionally) selectivity. Note that
selectivity multiplier affects the raw selectivity data and is
therefore automatically applied.
"""
shape = preference.shape
if selectivity is None:
selectivity = np.ones(shape, dtype=np.float64)
else:
assert preference.shape == selectivity.shape, \
"Preference and selectivity shapes must match."
value = np.ones(shape, dtype=np.int64) * 255
channels = (preference, selectivity, value)
rgb_channels = hsv_to_rgb(*channels)
arr_stack = np.dstack(rgb_channels)
return Image.fromarray(arr_stack.astype('uint8'), 'RGB')
def greyscale(arr):
"""
Converts a numpy 2D array of floats between 0.0 and 1.0 to a PIL
greyscale image.
"""
return Image.fromarray(np.uint8(arr*255))
def cf_image(cfs, coords, width=None, height=None, pos=(0,0),
size=26, border=5, bg=(0,0,0), colmap=None):
"""
Returns a PIL image showing the selected connection fields (CFS)
as supplied by extract_CFs. Does not support non-square CF
shapes.
'cfs' is an ndarray of N dstacked cfs, each of shape (X,X): (X,X,N)
'coords' is an ndarray of N coordinates: (N,2)
'width' and 'height' are either None (full) of integer grid sizes
'pos' is the starting position of the block, (x,y)
'size' and 'border' are the cf image size and the border size in pixels.
'colmap' is an RGB array shape (N,M,3) with values between 0.0 and 1.0.
"""
normalize = lambda arr: (arr - arr.min()) / (arr.max() - arr.min())
cf_im = lambda cf, size: greyscale(normalize(cf)).resize((size,size),
Image.NEAREST)
(posx, posy) = pos
(d1,d2) = zip(*coords)
density = len(set(d1))
assert density == len(set(d2)), "Not implemented for non-square sets"
height = density if height is None else height
width = density if width is None else width
assert height>0 and width>0, "Height and width must be None or greater than zero"
assert posx+width <= density, "X position and width greater than density"
assert posy+height <= density, "Y position and width greater than density"
# Functions mapping original coordinates onto consecutive grid indices
fst_map = dict(((ind,i) for (i,ind) in enumerate(sorted(set(d1)))))
snd_map = dict(((ind,i) for (i,ind) in enumerate(sorted(set(d2)))))
# Generating a dictionary from the grid coordinates to the CF index
mapped_coords = [(fst_map[fst],snd_map[snd]) for [fst,snd] in coords]
indexed_coords = dict((coord,i) for (i, coord) in enumerate(mapped_coords))
# Initialising the image
imwidth = width*size+(width-1)*border
imheight = height*size+(height-1)*border
cf_block = Image.new('RGB', (imwidth, imheight), bg)
# Building image row by row, top to bottom.
for yind in range(height):
for xind in range(width):
# Swapped coordinate system
cf_ind = indexed_coords[(yind+posy, xind+posx)]
# Get color from the color map if available
if colmap is not None:
crd1, crd2 = coords[cf_ind]
r,g,b = colmap[crd1, crd2, :]
color = (r*255,g*255,b*255)
else:
color = (255, 255, 255)
cf = cfs[:,:,cf_ind]
(cf_dim1, cf_dim2) = cf.shape
assert cf_dim1 == cf_dim2, "Only supports square CFs."
cf_image = ImageOps.colorize(cf_im(cf, size), (0, 0, 0, 0), color)
xoffset = xind*border
yoffset = yind*border
paste_coord = (xoffset+xind*size, yoffset+yind*size)
cf_block.paste(cf_image, paste_coord)
return cf_block
def resize(image, size, filter_type=Image.NEAREST):
"""
Resizes the given image to the given size using the specified
filter. Default is box filter (no interpolation) appropriate for
simulated orientation maps.
"""
return image.resize(size, filter_type)
#########################
# DEPRACATION FUNCTIONS #
#########################
def greyscale_image(array2D, normalize=False, scale_factor=255):
raise Exception("Use greyscale instead")
#########################
#########################
#########################
|
bsd-3-clause
|
[
624,
199,
13284,
13701,
199,
199,
22905,
367,
19775,
1834,
26212,
334,
69,
14,
71,
14,
1549,
9033,
9,
1808,
199,
48,
1193,
15,
48,
382,
674,
436,
20535,
14,
8051,
367,
13104,
9147,
16774,
9033,
334,
1045,
436,
199,
7395,
542,
10251,
4191,
395,
29167,
29484,
30900,
345,
436,
282,
2026,
640,
1402,
5401,
199,
7435,
14,
199,
624,
199,
199,
646,
6047,
199,
646,
6047,
16452,
199,
646,
2680,
465,
980,
199,
646,
3164,
1274,
199,
199,
10090,
63,
475,
63,
72,
2772,
275,
980,
14,
4106,
794,
8,
2326,
1274,
14,
10090,
63,
475,
63,
72,
2772,
9,
199,
72,
2772,
63,
475,
63,
10090,
275,
980,
14,
4106,
794,
8,
2326,
1274,
14,
72,
2772,
63,
475,
63,
10090,
9,
421,
199,
318,
12136,
63,
261,
10251,
4191,
8,
1569,
12,
10424,
1896,
29,
16,
14,
18,
304,
2043,
408,
2043,
23365,
4697,
542,
10251,
4191,
12136,
367,
31997,
14,
16666,
7461,
21845,
1542,
436,
2043,
574,
436,
29823,
21845,
1542,
701,
314,
10424,
1896,
14,
2043,
408,
2043,
10424,
4778,
275,
413,
14,
16,
1182,
10424,
1896,
221,
327,
5661,
5,
8897,
6528,
701,
841,
14,
16,
2043,
1834,
63,
22118,
275,
1834,
14,
3916,
360,
21631,
358,
2043,
7953,
275,
980,
14,
8748,
8,
1569,
63,
22118,
680,
6041,
360,
1609,
358,
8410,
519,
12,
486,
12,
330,
12,
282,
275,
980,
14,
8459,
416,
7291,
8,
5250,
12,
3114,
4022,
17,
9,
2043,
394,
12,
308,
12,
373,
275,
15180,
63,
475,
63,
72,
2772,
8,
82,
12,
486,
12,
330,
9,
257,
327,
308,
365,
359,
16,
12,
17,
61,
1006,
373,
787,
5450,
14,
16,
2043,
308,
9000,
334,
2299,
14,
16,
627,
10424,
4778,
9,
2043,
519,
12,
486,
12,
330,
275,
394,
2772,
63,
475,
63,
10090,
8,
72,
12,
334,
86,
1182,
5450,
14,
16,
395,
980,
14,
7548,
8,
83,
12,
378,
12,
5450,
14,
16,
430,
2043,
7953,
63,
2340,
275,
980,
14,
68,
2340,
1332,
82,
12,
486,
12,
330,
12,
282,
430,
2043,
372,
6047,
14,
504,
1144,
8,
5250,
63,
2340,
14,
6041,
360,
1635,
24,
659,
283,
21631,
358,
199,
199,
318,
1549,
63,
1130,
8,
14994,
12,
542,
10251,
4191,
29,
403,
304,
272,
408,
272,
6820,
19786,
314,
3066,
16705,
436,
334,
1422,
1183,
9,
542,
10251,
4191,
14,
3390,
626,
272,
542,
10251,
4191,
22215,
29476,
314,
3066,
542,
10251,
4191,
666,
436,
365,
272,
16119,
5847,
6781,
14,
272,
408,
272,
2215,
275,
16705,
14,
1392,
272,
340,
542,
10251,
4191,
365,
488,
26,
267,
542,
10251,
4191,
275,
980,
14,
4548,
8,
1392,
12,
2152,
29,
1590,
14,
1609,
772,
9,
272,
587,
26,
267,
702,
16705,
14,
1392,
508,
542,
10251,
4191,
14,
1392,
12,
971,
288,
298,
25258,
436,
542,
10251,
4191,
11751,
1471,
1336,
2122,
272,
574,
275,
980,
14,
4548,
8,
1392,
12,
2152,
29,
1590,
14,
442,
772,
9,
627,
5450,
339,
9245,
275,
334,
14994,
12,
542,
10251,
4191,
12,
574,
9,
272,
15180,
63,
6324,
275,
394,
2772,
63,
475,
63,
10090,
2031,
6324,
9,
272,
7953,
63,
2340,
275,
980,
14,
68,
2340,
8,
10090,
63,
6324,
9,
272,
372,
6047,
14,
504,
1144,
8,
5250,
63,
2340,
14,
6041,
360,
1635,
24,
659,
283,
12067,
358,
199,
199,
318,
30357,
3467,
8,
5250,
304,
272,
408,
272,
19107,
282,
2680,
499,
36,
1625,
402,
15657,
3382,
378,
14,
16,
436,
413,
14,
16,
370,
282,
14937,
272,
30357,
3467,
1834,
14,
272,
408,
272,
372,
6047,
14,
504,
1144,
8,
1590,
14,
1635,
24,
8,
5250,
10,
2299,
430,
421,
199,
318,
3980,
63,
1569,
8,
2177,
83,
12,
13259,
12,
3462,
29,
403,
12,
4569,
29,
403,
12,
2086,
2687,
16,
12,
16,
395,
221,
1467,
1568,
29,
1479,
12,
9162,
29,
21,
12,
12994,
2687,
16,
12,
16,
12,
16,
395,
1048,
1130,
29,
403,
304,
272,
408,
272,
1803,
282,
14937,
1834,
21207,
314,
4895,
1950,
1504,
334,
5487,
51,
9,
272,
465,
6841,
701,
5536,
63,
5487,
83,
14,
12078,
440,
2291,
2222,
13,
9646,
6035,
272,
11751,
14,
339,
283,
2177,
83,
7,
365,
376,
6800,
402,
653,
366,
27266,
286,
2319,
12,
1924,
402,
2215,
334,
56,
12,
56,
304,
334,
56,
12,
56,
12,
46,
9,
272,
283,
8032,
7,
365,
376,
6800,
402,
653,
8983,
26,
334,
46,
12,
18,
9,
272,
283,
2063,
7,
436,
283,
3333,
7,
787,
1902,
488,
334,
2861,
9,
402,
3000,
6068,
10627,
272,
283,
1712,
7,
365,
314,
6617,
3421,
402,
314,
1853,
12,
334,
88,
12,
89,
9,
272,
283,
890,
7,
436,
283,
8665,
7,
787,
314,
3980,
1834,
1568,
436,
314,
9162,
1568,
315,
11094,
14,
272,
283,
761,
1130,
7,
365,
376,
19013,
1625,
2215,
334,
46,
12,
45,
12,
19,
9,
543,
1338,
3382,
378,
14,
16,
436,
413,
14,
16,
14,
272,
408,
272,
7666,
275,
2400,
7953,
26,
334,
5250,
446,
7953,
14,
827,
1012,
1182,
334,
5250,
14,
988,
342,
446,
7953,
14,
827,
1012,
272,
3980,
63,
1017,
275,
2400,
3980,
12,
1568,
26,
30357,
3467,
8,
7721,
8,
2177,
4992,
8709,
1332,
890,
12,
890,
395,
221,
18193,
6047,
14,
6388,
689,
1719,
9,
272,
334,
32405,
12,
2086,
89,
9,
275,
2086,
272,
334,
68,
17,
12,
68,
18,
9,
275,
3482,
2031,
8032,
9,
272,
13650,
275,
822,
8,
409,
8,
68,
17,
430,
272,
702,
13650,
508,
822,
8,
409,
8,
68,
18,
1826,
298,
1763,
6366,
367,
2222,
13,
9646,
5951,
2,
272,
4569,
275,
13650,
340,
4569,
365,
488,
587,
4569,
272,
3462,
275,
13650,
340,
3462,
365,
488,
587,
3462,
272,
702,
4569,
30,
16,
436,
3462,
30,
16,
12,
298,
8436,
436,
3462,
1471,
506,
488,
503,
8932,
2419,
4697,
2,
272,
702,
2086,
88,
11,
2063,
2695,
13650,
12,
298,
56,
3421,
436,
3462,
8932,
2419,
13650,
2,
272,
702,
2086,
89,
11,
3333,
2695,
13650,
12,
298,
57,
3421,
436,
3462,
8932,
2419,
13650,
2,
272,
327,
17471,
4412,
3379,
8983,
14602,
23376,
6068,
4918,
272,
289,
270,
63,
1130,
275,
221,
1211,
12925,
688,
12,
73,
9
] |
[
199,
13284,
13701,
199,
199,
22905,
367,
19775,
1834,
26212,
334,
69,
14,
71,
14,
1549,
9033,
9,
1808,
199,
48,
1193,
15,
48,
382,
674,
436,
20535,
14,
8051,
367,
13104,
9147,
16774,
9033,
334,
1045,
436,
199,
7395,
542,
10251,
4191,
395,
29167,
29484,
30900,
345,
436,
282,
2026,
640,
1402,
5401,
199,
7435,
14,
199,
624,
199,
199,
646,
6047,
199,
646,
6047,
16452,
199,
646,
2680,
465,
980,
199,
646,
3164,
1274,
199,
199,
10090,
63,
475,
63,
72,
2772,
275,
980,
14,
4106,
794,
8,
2326,
1274,
14,
10090,
63,
475,
63,
72,
2772,
9,
199,
72,
2772,
63,
475,
63,
10090,
275,
980,
14,
4106,
794,
8,
2326,
1274,
14,
72,
2772,
63,
475,
63,
10090,
9,
421,
199,
318,
12136,
63,
261,
10251,
4191,
8,
1569,
12,
10424,
1896,
29,
16,
14,
18,
304,
2043,
408,
2043,
23365,
4697,
542,
10251,
4191,
12136,
367,
31997,
14,
16666,
7461,
21845,
1542,
436,
2043,
574,
436,
29823,
21845,
1542,
701,
314,
10424,
1896,
14,
2043,
408,
2043,
10424,
4778,
275,
413,
14,
16,
1182,
10424,
1896,
221,
327,
5661,
5,
8897,
6528,
701,
841,
14,
16,
2043,
1834,
63,
22118,
275,
1834,
14,
3916,
360,
21631,
358,
2043,
7953,
275,
980,
14,
8748,
8,
1569,
63,
22118,
680,
6041,
360,
1609,
358,
8410,
519,
12,
486,
12,
330,
12,
282,
275,
980,
14,
8459,
416,
7291,
8,
5250,
12,
3114,
4022,
17,
9,
2043,
394,
12,
308,
12,
373,
275,
15180,
63,
475,
63,
72,
2772,
8,
82,
12,
486,
12,
330,
9,
257,
327,
308,
365,
359,
16,
12,
17,
61,
1006,
373,
787,
5450,
14,
16,
2043,
308,
9000,
334,
2299,
14,
16,
627,
10424,
4778,
9,
2043,
519,
12,
486,
12,
330,
275,
394,
2772,
63,
475,
63,
10090,
8,
72,
12,
334,
86,
1182,
5450,
14,
16,
395,
980,
14,
7548,
8,
83,
12,
378,
12,
5450,
14,
16,
430,
2043,
7953,
63,
2340,
275,
980,
14,
68,
2340,
1332,
82,
12,
486,
12,
330,
12,
282,
430,
2043,
372,
6047,
14,
504,
1144,
8,
5250,
63,
2340,
14,
6041,
360,
1635,
24,
659,
283,
21631,
358,
199,
199,
318,
1549,
63,
1130,
8,
14994,
12,
542,
10251,
4191,
29,
403,
304,
272,
408,
272,
6820,
19786,
314,
3066,
16705,
436,
334,
1422,
1183,
9,
542,
10251,
4191,
14,
3390,
626,
272,
542,
10251,
4191,
22215,
29476,
314,
3066,
542,
10251,
4191,
666,
436,
365,
272,
16119,
5847,
6781,
14,
272,
408,
272,
2215,
275,
16705,
14,
1392,
272,
340,
542,
10251,
4191,
365,
488,
26,
267,
542,
10251,
4191,
275,
980,
14,
4548,
8,
1392,
12,
2152,
29,
1590,
14,
1609,
772,
9,
272,
587,
26,
267,
702,
16705,
14,
1392,
508,
542,
10251,
4191,
14,
1392,
12,
971,
288,
298,
25258,
436,
542,
10251,
4191,
11751,
1471,
1336,
2122,
272,
574,
275,
980,
14,
4548,
8,
1392,
12,
2152,
29,
1590,
14,
442,
772,
9,
627,
5450,
339,
9245,
275,
334,
14994,
12,
542,
10251,
4191,
12,
574,
9,
272,
15180,
63,
6324,
275,
394,
2772,
63,
475,
63,
10090,
2031,
6324,
9,
272,
7953,
63,
2340,
275,
980,
14,
68,
2340,
8,
10090,
63,
6324,
9,
272,
372,
6047,
14,
504,
1144,
8,
5250,
63,
2340,
14,
6041,
360,
1635,
24,
659,
283,
12067,
358,
199,
199,
318,
30357,
3467,
8,
5250,
304,
272,
408,
272,
19107,
282,
2680,
499,
36,
1625,
402,
15657,
3382,
378,
14,
16,
436,
413,
14,
16,
370,
282,
14937,
272,
30357,
3467,
1834,
14,
272,
408,
272,
372,
6047,
14,
504,
1144,
8,
1590,
14,
1635,
24,
8,
5250,
10,
2299,
430,
421,
199,
318,
3980,
63,
1569,
8,
2177,
83,
12,
13259,
12,
3462,
29,
403,
12,
4569,
29,
403,
12,
2086,
2687,
16,
12,
16,
395,
221,
1467,
1568,
29,
1479,
12,
9162,
29,
21,
12,
12994,
2687,
16,
12,
16,
12,
16,
395,
1048,
1130,
29,
403,
304,
272,
408,
272,
1803,
282,
14937,
1834,
21207,
314,
4895,
1950,
1504,
334,
5487,
51,
9,
272,
465,
6841,
701,
5536,
63,
5487,
83,
14,
12078,
440,
2291,
2222,
13,
9646,
6035,
272,
11751,
14,
339,
283,
2177,
83,
7,
365,
376,
6800,
402,
653,
366,
27266,
286,
2319,
12,
1924,
402,
2215,
334,
56,
12,
56,
304,
334,
56,
12,
56,
12,
46,
9,
272,
283,
8032,
7,
365,
376,
6800,
402,
653,
8983,
26,
334,
46,
12,
18,
9,
272,
283,
2063,
7,
436,
283,
3333,
7,
787,
1902,
488,
334,
2861,
9,
402,
3000,
6068,
10627,
272,
283,
1712,
7,
365,
314,
6617,
3421,
402,
314,
1853,
12,
334,
88,
12,
89,
9,
272,
283,
890,
7,
436,
283,
8665,
7,
787,
314,
3980,
1834,
1568,
436,
314,
9162,
1568,
315,
11094,
14,
272,
283,
761,
1130,
7,
365,
376,
19013,
1625,
2215,
334,
46,
12,
45,
12,
19,
9,
543,
1338,
3382,
378,
14,
16,
436,
413,
14,
16,
14,
272,
408,
272,
7666,
275,
2400,
7953,
26,
334,
5250,
446,
7953,
14,
827,
1012,
1182,
334,
5250,
14,
988,
342,
446,
7953,
14,
827,
1012,
272,
3980,
63,
1017,
275,
2400,
3980,
12,
1568,
26,
30357,
3467,
8,
7721,
8,
2177,
4992,
8709,
1332,
890,
12,
890,
395,
221,
18193,
6047,
14,
6388,
689,
1719,
9,
272,
334,
32405,
12,
2086,
89,
9,
275,
2086,
272,
334,
68,
17,
12,
68,
18,
9,
275,
3482,
2031,
8032,
9,
272,
13650,
275,
822,
8,
409,
8,
68,
17,
430,
272,
702,
13650,
508,
822,
8,
409,
8,
68,
18,
1826,
298,
1763,
6366,
367,
2222,
13,
9646,
5951,
2,
272,
4569,
275,
13650,
340,
4569,
365,
488,
587,
4569,
272,
3462,
275,
13650,
340,
3462,
365,
488,
587,
3462,
272,
702,
4569,
30,
16,
436,
3462,
30,
16,
12,
298,
8436,
436,
3462,
1471,
506,
488,
503,
8932,
2419,
4697,
2,
272,
702,
2086,
88,
11,
2063,
2695,
13650,
12,
298,
56,
3421,
436,
3462,
8932,
2419,
13650,
2,
272,
702,
2086,
89,
11,
3333,
2695,
13650,
12,
298,
57,
3421,
436,
3462,
8932,
2419,
13650,
2,
272,
327,
17471,
4412,
3379,
8983,
14602,
23376,
6068,
4918,
272,
289,
270,
63,
1130,
275,
221,
1211,
12925,
688,
12,
73,
9,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
irblsensitivity/irblsensitivity
|
scripts/translation/firstry.py
|
1
|
18562
|
#-*- coding: utf-8 -*-
'''
Created on 2017. 11. 06
Updated on 2017. 11. 06
'''
from __future__ import print_function
import os
import cgi
import re
import time
import codecs
import sys
import subprocess
import math
import dateutil.parser
from datetime import datetime
from commons import Subjects
from xml.etree import ElementTree
from features.Corpus import Corpus
from bs4 import BeautifulSoup
from unidiff import PatchSet
from utils import Progress
from repository.GitLog import GitLog
from repository.BugFilter import BugFilter
from repository.GitVersion import GitVersion
###############################################################
# make bug information
###############################################################
def load_file_corpus(_filepath):
data = {}
f = open(_filepath, 'r')
while True:
line = f.readline()
if line is None or line == "":break
identifier, words = line.split('\t')
identifier = identifier.replace('/','.')
idx = identifier.find('org.')
if idx >= 0:
identifier = identifier[idx:]
data[identifier] = words.split(' ')
return data
def load_bug_corpus(_filename):
'''
return words for each items(ex. file, bug report...)
:param _filename:
:return: {'itemID1':['word1', 'word2',....], 'itemID2':[]....}
'''
f = open(_filename, 'r')
lines = f.readlines()
f.close()
corpus = {}
for line in lines:
idx = line.find('\t')
key = int(line[:idx])
words = line[idx + 1:-1]
words = words.strip().split(' ') if len(words) > 0 else []
# remove blank items
idx = 0
while idx < len(words):
if words[idx] == '':
del words[idx]
else:
idx += 1
corpus[key] = words
return corpus
###############################################################
# make comment information
###############################################################
def load_bug_xml(_filepath):
'''
get bugs information according to _selector from bug repository XML file
:param _repo:
:param _selector:
:return:
'''
bug = {}
try:
root = ElementTree.parse(_filepath).getroot()
itemtag = root[0].find('item') #channel > item
bug['title'] = itemtag.find('title').text
bug['desc'] = itemtag.find('description').text
bug['comments'] = []
comments = itemtag.find('comments')
if comments is not None:
for comment in comments:
cID = int(comment.attrib['id'])
cTime = dateutil.parser.parse(comment.attrib['created'])
cTime = time.mktime(cTime.timetuple())
# cTime = datetime.strptime(comment.attrib['created'], "%a, %d %b %Y %H:%M:%S")
cAuthor = comment.attrib['author']
cText = comment.text
bug['comments'].append({'id':cID, 'timestamp':cTime, 'author':cAuthor, 'text':cText})
except Exception as e:
print(e)
return bug
def make_comment_corpus(_project, _bugIDs, _bugPath, _featurePath):
corpusPath = os.path.join(_featurePath, 'bugs', '_corpus')
if os.path.exists(corpusPath) is False:
os.makedirs(corpusPath)
result_file = os.path.join(corpusPath, 'comments.corpus')
if os.path.exists(result_file) is True:
return True
corpus = Corpus(_camelSplit=False)
f = codecs.open(result_file, 'w', 'UTF-8')
count = 0
progress = Progress(u'[%s] making comment corpus' % _project, 2, 10, True)
progress.set_upperbound(len(_bugIDs))
progress.start()
for bugID in _bugIDs:
# print(u'[%s] Working %d ...' % (_project, bugID), end=u'')
# load XML
filepath = os.path.join(_bugPath, 'bugs', '%s-%d.xml'% (_project, bugID))
bug = load_bug_xml(filepath)
if len(bug['comments']) == 0:
print(u'!', end=u'') #\t\tNo comment!')
count +=1
# make Corpus
for comment in bug['comments']:
# Convert some formats (date and text...)
# re.sub = remove compound character except english caracter and numbers and some special characters
text = BeautifulSoup(comment['text'], "html.parser").get_text()
text = cgi.escape(re.sub(r'[^\x00-\x80]+', '', text))
text = cgi.escape(re.sub(chr(27), '', text))
comment_corpus = corpus.make_text_corpus(text)
corpus_text = ' '.join(comment_corpus)
f.write('%d\t%d\t%d\t%s\t%s\n' % (bugID, comment['id'], comment['timestamp'], comment['author'], corpus_text))
progress.check()
f.close()
progress.done()
print(u'missed bugs : %d' % count)
pass
def load_comment_corpus(_project, _bugIDs, _bugPath, _featurePath, _force=False):
corpusPath = os.path.join(_featurePath, 'bugs', '_corpus', 'comments.corpus')
if _force is True or os.path.exists(corpusPath) is False:
make_comment_corpus(_project, _bugIDs, _bugPath, _featurePath)
data = {}
f = codecs.open(corpusPath, 'r', 'UTF-8')
while True:
line = f.readline()
if line is None or line=="": break
line = line[:-1]
items = line.split('\t')
bugID = int(items[0])
if bugID not in data: data[bugID] = []
corpus = items[4].split(' ') if len(items[4]) > 0 else[]
data[bugID].append({'id':items[1], 'timestamp':items[2], 'author':items[3], 'corpus':corpus})
f.close()
return data
###############################################################
# make comment information
###############################################################
def get_patches(_hash, _gitPath):
'''
_hash에 해당하는 patch정보를 로드
commit log는 제외되어있음.
:return:
'''
# check this branch
command = [u'git', u'log', u'-1', u'-U', _hash]
result = subprocess.check_output(command, stderr=sys.stderr, cwd=_gitPath)
if result is None:
print(u'Failed')
return False
# if the head is not up-to-date, checkout up-to-date
# common_log_msg = result[:result.find('diff --git ')] # common_log_msg가 포함되어있음. log_msg를 처리하려면 분석하면 됨.
result = result[result.find('diff --git '):].strip()
result = re.sub(r'[^\x00-\x80]+', '', result)
result = result.decode('UTF-8', 'ignore')
patch = PatchSet(result.split('\n'))
return patch
def make_hunk(_bug, _gitPath):
'''
:param _bug: {'commits':[list of commit hash], 'files':[list of related files]}
:param _gitPath:
:return:
'''
changes = {}
fixed_files = [item['name'] for item in _bug['files']]
for commit in _bug['commits']:
patches = get_patches(commit, _gitPath)
for patch in patches:
classpath = patch.path.replace('/', '.')
classpath = classpath[classpath.find('org.'):]
if classpath not in fixed_files:continue
hunk_text = u''
for hunk in patch:
# related method name + codes with linesep
hunk_text += hunk.section_header + reduce(lambda x, y: str(x) + os.linesep + str(y), hunk) + os.linesep
changes[classpath] = hunk_text
return changes
def make_hunk_corpus(_project, _bugs, _gitPath, _featurePath):
# sources의 버전은 고려하지 않음 (commit log의 hunk와 비교하므로 버전은 제외함
# bugID와 관련된 수정된 파일들과 commit 목록을 가져옴 (commit hash가 포함되어야 함)
# create hunk corpus path
corpusPath = os.path.join(_featurePath, 'bugs', '_corpus')
if os.path.exists(corpusPath) is False:
os.makedirs(corpusPath)
f = codecs.open(os.path.join(corpusPath, 'hunk.corpus'), 'w', 'UTF-8')
# create hunk and save
progress = Progress(u'[%s] making hunk corpus' % _project, 2, 10, True)
progress.set_upperbound(len(_bugs))
progress.start()
for bugID, info in _bugs.iteritems():
#_bugs : {bugID:{'hash':[], 'files':[{'type:'M', 'name':'fileclass'}, ...]
#print('[Hunk] working %d' % bugID)
# make hunk
hunks = make_hunk(info, _gitPath)
# make hunk corpus
corpus = Corpus(_camelSplit=False)
for classpath, hunk_text in hunks.iteritems():
terms = corpus.make_text_corpus(hunk_text)
terms_text = ' '.join(terms)
f.write('%d\t%s\t%s\n' % (bugID, classpath, terms_text))
progress.check()
f.close()
progress.done()
pass
def load_hunk_corpus(_project, _bugs, _gitPath, _featurePath, _force=False):
'''
각 버그리포트 별로 정답파일들의 변경된 hunk들에 대해서 corpus를 생성.
:param _bugID:
:param _gitPath:
:param _featurePath:
:return:
'''
#check the path
corpusPath = os.path.join(_featurePath, 'bugs', '_corpus', 'hunk.corpus')
if _force is True or os.path.exists(corpusPath) is False:
make_hunk_corpus(_project, _bugs, _gitPath, _featurePath)
# load hunk corpus
data = {}
f = codecs.open(corpusPath, 'r', 'UTF-8')
while True:
line = f.readline()
if line is None or line == "": break
line = line[:-1]
items = line.split('\t')
bugID = int(items[0])
classpath = items[1]
corpus = items[2].split(' ') if len(items[2]) > 0 else []
# Add to data
if bugID not in data: data[bugID] = {}
data[bugID][classpath] = corpus
f.close()
return data
def make_bug_hash(_project, _bugIDs, _bugPath, _gitPath, _featurePath):
'''
:param _project:
:param _bugIDs:
:param _bugPath:
:param _gitPath:
:param _featurePath:
:return: {bugID:{'commits':[commit hash list], 'files':[{'type':'M', 'name':'fileclass'}, ...]
'''
gitlogPath = os.path.join(_featurePath, 'bugs', '_corpus', u'.git.log')
gitversionPath = os.path.join(_featurePath, 'bugs', '_corpus', u'.git_version.txt')
gitLog = GitLog(_project, _gitPath, gitlogPath)
gitVersion = GitVersion(_project, _gitPath, gitversionPath)
bugFilter = BugFilter(_project, os.path.join(_bugPath, u'bugs'))
print(u'[%s] start making bug infromation *************' % (_project))
logs = gitLog.load()
tagmaps = gitVersion.load()
items, dupgroups = bugFilter.run(logs, tagmaps)
print(u'[%s] start making bug infromation ************* Done' % (_project))
# making bugs
bugs = {}
for item in items:
bugID = int(item['id'][item['id'].find('-')+1:])
if bugID not in _bugIDs: continue
if item['id'] not in logs:
print('**********item ID %s not exists in logs! It\'s wired' % item['id'])
bugs[bugID] = {'commits':[] , 'files':[]}
continue
commits = logs[item['id']]
hash_list = [commit['hash'] for commit in commits]
files = []
for fileitem in item['fixedFiles']:
if fileitem['name'].find('test') >= 0: continue
if fileitem['name'].find('Test') >= 0: continue
files.append(fileitem)
if len(hash_list)==0 or len(files) ==0: continue
bugs[bugID] = {'commits':hash_list , 'files':files}
os.remove(gitlogPath)
os.remove(gitversionPath)
print(u'[%s] making hash info for bugs ************* Done' % (_project))
from utils.PrettyStringBuilder import PrettyStringBuilder
builder = PrettyStringBuilder()
text = builder.get_dicttext(bugs, _indent=1)
f = codecs.open(os.path.join(_featurePath, 'bugs', '.bug.hash'), 'w', 'UTF-8')
f.write(text)
f.close()
return bugs
def load_bug_hash(_project, _bugIDs, _bugPath, _gitPath, _featurePath, _force=False):
bugHashPath = os.path.join(_featurePath, 'bugs', '.bug.hash')
if _force is True or os.path.exists(bugHashPath) is False:
make_bug_hash(_project, _bugIDs, _bugPath, _gitPath, _featurePath)
f = codecs.open(bugHashPath, 'r', 'UTF-8')
text = f.read()
f.close()
return eval(text)
###############################################################
# make comment information
###############################################################
def make_IDF(descriptions, comments, hunks):
document_count = 0
# description IDF
IDF = {}
for bugID in descriptions:
document_count += 1
unique_terms = set(descriptions[bugID])
for term in unique_terms:
IDF[term] = (IDF[term] + 1) if term in IDF else 1
# comments IDF
for bugID in comments:
for comment in comments[bugID]:
document_count += 1
unique_terms = set(comment['corpus'])
for term in unique_terms:
IDF[term] = (IDF[term] + 1) if term in IDF else 1
# hunk IDF
for bugID in hunks:
for filepath, corpus in hunks[bugID].iteritems():
document_count += 1
unique_terms = set(corpus)
for term in unique_terms:
IDF[term] = (IDF[term] + 1) if term in IDF else 1
print('len of all tokens is : %d' % len(IDF))
return document_count, IDF
def get_TF(_corpus):
TF = {}
# hunk IDF
for term in _corpus:
TF[term] = (TF[term]+1)if term in TF else 1
return TF
def get_TFIDF(_TF, _IDF, _nD):
'''
basic TF-IDF
:param _TF:
:param _IDF:
:param _nD:
:return:
'''
TFIDF = {}
for term, count in _TF.iteritems():
TFIDF[term] = float(count) * (1.0 + math.log(float(_nD) / _IDF[term])) #basic TF-IDF
return TFIDF
def get_similarity(_vectorA, _vectorB):
'''
return sparse vector's similarity between vA and vB
:param _vectorA:
:param _vectorB:
:return:
'''
common_set = set(_vectorA.keys()) & set(_vectorB.keys())
# A dot B
product = sum(_vectorA[term] * _vectorB[term] for term in common_set)
# |A|, |B|
valueA = sum(_vectorA[term] * _vectorA[term] for term in _vectorA)
valueB = sum(_vectorB[term] * _vectorB[term] for term in _vectorB)
if valueA == 0 or valueB ==0:
return 0
return product / (valueA * valueB)
def calculate_similarity(_group, _project, _descs, _comments, _hunks, _featurePath):
# calculated Number of Documents, Number of IDF
nD, nIDF = make_IDF(_descs, _comments, _hunks) # number of Documents, number of IDF
for term in nIDF:
print(u'%s\t%d' % (term, nIDF[term]))
progress = Progress("[%s] calculating similarity for reports and comments" % _project, 2, 10, True)
progress.set_upperbound(len(_descs))
progress.start()
output = codecs.open(os.path.join(_featurePath, 'bugs', 'comments.similarity'), 'w', 'UTF-8')
output.write(u'Group\tProject\tBugID\tCommentID\tTimestamp\tAuthor\tSimilarity\n')
# for each bug report,
for bugID in _descs:
# except for reports which have no comments
if bugID in _comments:
tfA = get_TF(_descs[bugID])
vectorA = get_TFIDF(tfA, nIDF, nD)
for comment in _comments[bugID]:
tfB = get_TF(comment['corpus'])
vectorB = get_TFIDF(tfB, nIDF, nD)
similarity = get_similarity(vectorA, vectorB)
output.write(u'%s\t%s\t%d\t%s\t%s\t%s\t%.8f\n' %
(_group, _project, bugID,
comment['id'],
datetime.fromtimestamp(int(comment['timestamp'])).strftime("%Y-%m-%d %H:%M:%S"),
comment['author'], similarity))
output.flush()
progress.check()
output.close()
progress.done()
progress = Progress("[%s] calculating similarity for reports and file hunks" % _project, 2, 10, True)
progress.set_upperbound(len(_descs))
progress.start()
output = codecs.open(os.path.join(_featurePath, 'bugs', 'hunks.similarity'), 'w', 'UTF-8')
output.write(u'Group\tProject\tBugID\tClassPath\tSimilarity\n')
# for each bug report,
for bugID in _descs:
# except for reports which have no comments
if bugID in _hunks:
tfA = get_TF(_descs[bugID])
vectorA = get_TFIDF(tfA, nIDF, nD)
for classpath, corpus in _hunks[bugID].iteritems():
tfB = get_TF(corpus)
vectorB = get_TFIDF(tfB, nIDF, nD)
similarity = get_similarity(vectorA, vectorB)
output.write(u'%s\t%s\t%d\t%s\t%.8f\n' %
(_group, _project, bugID, classpath, similarity))
output.flush()
progress.check()
output.close()
progress.done()
progress = Progress("[%s] calculating similarity for comments and file hunks" % _project, 2, 10, True)
progress.set_upperbound(len(_descs))
progress.start()
output = codecs.open(os.path.join(_featurePath, 'bugs', 'comments_hunks.similarity'), 'w', 'UTF-8')
output.write(u'Group\tProject\tBugID\tCommentID\tTimestamp\tAuthor\tClassPath\tSimilarity\n')
# for each bug report,
for bugID in _descs:
# except for reports which have no comments
if bugID in _comments and bugID in _hunks:
for comment in _comments[bugID]:
tfA = get_TF(comment['corpus'])
vectorA = get_TFIDF(tfA, nIDF, nD)
for classpath, corpus in _hunks[bugID].iteritems():
tfB = get_TF(corpus)
vectorB = get_TFIDF(tfB, nIDF, nD)
similarity = get_similarity(vectorA, vectorB)
output.write(u'%s\t%s\t%d\t%s\t%s\t%s\t%s\t%.8f\n' %
(_group, _project, bugID,
comment['id'],
datetime.fromtimestamp(int(comment['timestamp'])).strftime("%Y-%m-%d %H:%M:%S"),
comment['author'], classpath, similarity))
output.flush()
progress.check()
output.close()
progress.done()
###############################################################
# main routine
###############################################################
def make(_group, _project, _bugIDs, _bugPath, _gitPath, _featurePath, _isDesc, _isCamel, _force=False):
# comment가 없거나 file이 매핑이 안된다거나...한 버그리포트들은 미리 제거해야되지 않을까?
# descriptions = {bugID:[corpus], bugID:[corpus], ...}
descriptions = load_bug_corpus(os.path.join(_featurePath, 'bugs', '_corpus', 'desc.corpus'))
# comments 가 존재하지 않는 151개 버그리포트는 제외됨.
# comments = {bugID:{'id':CommentID, 'timestamp':timestamp, 'author':Author, 'corpus':[corpus]}, ...}
comments = load_comment_corpus(_project, _bugIDs, _bugPath, _featurePath, _force=_force)
# bugs = {bugID:{'commits':[], 'files':[{'type':'M', 'name':'org....java'}]}, ...}
bugs = load_bug_hash(_project, _bugIDs, _bugPath, _gitPath, _featurePath, _force=_force)
# hunks = {bugID:{'classpath':[corpus], 'classpath':[corpus], ...}, ...}
hunks = load_hunk_corpus(_project, bugs, _gitPath, _featurePath, _force = _force)
# calculated Number of Documents, Number of IDF
calculate_similarity(_group, _project, descriptions, comments, hunks, _featurePath)
pass
#####################################
# command
#####################################
def work():
import json
S = Subjects()
desc = True
camel = False
for group in ['Apache']:#S.groups:#S.groups: #['Commons']:#
for project in ['CAMEL'] : #S.projects[group]:#S.projects[group]: ['CODEC']
make(group, project, S.bugs[project]['all'],
S.getPath_bugrepo(group,project),
S.getPath_gitrepo(group, project),
S.getPath_featurebase(group, project),
_isDesc=desc,
_isCamel=camel,
_force = True)
###############################################################################################################
###############################################################################################################
if __name__ == "__main__":
'''
'''
work()
pass
|
apache-2.0
|
[
3,
13,
1837,
2803,
26,
2774,
13,
24,
1882,
202,
199,
2344,
202,
199,
10502,
641,
9708,
14,
4119,
14,
24293,
202,
199,
19920,
641,
9708,
14,
4119,
14,
24293,
202,
199,
2344,
202,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
202,
199,
646,
747,
202,
199,
646,
16004,
202,
199,
646,
295,
202,
199,
646,
900,
202,
199,
646,
6010,
202,
199,
646,
984,
202,
199,
646,
3873,
202,
199,
646,
3473,
202,
199,
646,
22208,
14,
2087,
202,
199,
504,
2197,
492,
2197,
202,
199,
504,
2863,
83,
492,
26793,
83,
202,
199,
504,
2748,
14,
9464,
492,
13139,
202,
199,
504,
4534,
14,
26424,
492,
7499,
8843,
202,
199,
504,
9922,
20,
492,
17132,
202,
199,
504,
15439,
3028,
492,
19292,
1084,
202,
199,
504,
3778,
492,
21211,
202,
199,
504,
7611,
14,
14686,
2445,
492,
12579,
2445,
202,
199,
504,
7611,
14,
17545,
4131,
492,
21605,
4131,
202,
199,
504,
7611,
14,
14686,
3353,
492,
12579,
3353,
8065,
199,
26207,
14776,
202,
199,
3,
1852,
6519,
2556,
202,
199,
26207,
14776,
202,
199,
318,
2248,
63,
493,
63,
16780,
1547,
7218,
304,
1223,
198,
576,
275,
1052,
1223,
198,
70,
275,
1551,
1547,
7218,
12,
283,
82,
358,
1223,
198,
6710,
715,
26,
4122,
198,
604,
275,
289,
14,
6407,
342,
4122,
198,
692,
1004,
365,
488,
503,
1004,
508,
10812,
4785,
26045,
198,
5364,
12,
5932,
275,
1004,
14,
1294,
2258,
84,
358,
4122,
198,
5364,
275,
5148,
14,
1814,
10998,
1370,
358,
4122,
198,
2996,
275,
5148,
14,
1623,
360,
1308,
2659,
4122,
198,
692,
4280,
2356,
378,
26,
7903,
198,
5364,
275,
5148,
59,
2996,
2938,
8065,
507,
198,
576,
59,
5364,
61,
275,
5932,
14,
1294,
360,
5320,
1223,
198,
1107,
666,
8065,
199,
318,
2248,
63,
1266,
63,
16780,
1547,
1501,
304,
1223,
198,
2344,
1223,
198,
1107,
5932,
367,
1924,
2974,
8,
476,
14,
570,
12,
6519,
3622,
11965,
10060,
198,
26,
635,
485,
1501,
26,
1223,
198,
26,
1107,
26,
791,
1053,
998,
17,
21662,
1027,
17,
297,
283,
1027,
18,
297,
4496,
467,
283,
1053,
998,
18,
356,
8607,
4496,
93,
1223,
198,
2344,
1223,
198,
70,
275,
1551,
1547,
1501,
12,
283,
82,
358,
1223,
198,
1278,
275,
289,
14,
9684,
342,
1223,
198,
70,
14,
1600,
342,
10060,
198,
16780,
275,
1052,
1223,
198,
509,
1004,
315,
2385,
26,
4122,
198,
2996,
275,
1004,
14,
1623,
2258,
84,
358,
4122,
198,
498,
275,
1109,
8,
604,
1491,
2996,
566,
4122,
198,
3148,
275,
1004,
59,
2996,
435,
413,
6809,
17,
61,
4122,
198,
3148,
275,
5932,
14,
1913,
1252,
1294,
360,
5320,
340,
822,
8,
3148,
9,
690,
378,
587,
942,
4122,
198,
3,
2813,
4596,
2974,
4122,
198,
2996,
275,
378,
4122,
198,
6710,
4280,
665,
822,
8,
3148,
304,
7903,
198,
692,
5932,
59,
2996,
61,
508,
8061,
13610,
198,
2264,
5932,
59,
2996,
61,
7903,
198,
2836,
26,
13610,
198,
2996,
847,
413,
4122,
198,
16780,
59,
498,
61,
275,
5932,
10060,
198,
1107,
16831,
8065,
199,
26207,
14776,
202,
199,
3,
1852,
3721,
2556,
202,
199,
26207,
14776,
202,
199,
318,
2248,
63,
1266,
63,
1652,
1547,
7218,
304,
1223,
198,
2344,
1223,
198,
362,
18227,
2556,
7182,
370,
485,
6662,
687,
6519,
7611,
4692,
570,
1223,
198,
26,
635,
485,
3417,
26,
1223,
198,
26,
635,
485,
6662,
26,
1223,
198,
26,
1107,
26,
1223,
198,
2344,
1223,
198,
1266,
275,
1052,
1223,
198,
893,
26,
4122,
198,
1231,
275,
13139,
14,
1122,
1547,
7218,
680,
24544,
342,
26045,
198,
1053,
1450,
275,
1738,
59,
16,
1055,
1623,
360,
1053,
358,
221,
327,
2775,
690,
1242,
4122,
198,
1266,
459,
1213,
418,
275,
1242,
1450,
14,
1623,
360,
1213,
1959,
505,
4122,
198,
1266,
459,
3257,
418,
275,
1242,
1450,
14,
1623,
360,
1802,
1959,
505,
8065,
507,
198,
1266,
459,
6223,
418,
275,
942,
4122,
198,
6223,
275,
1242,
1450,
14,
1623,
360,
6223,
358,
4122,
198,
692,
6786,
365,
440,
488,
26,
7903,
198,
509,
3721,
315,
6786,
26,
13610,
198,
67,
998,
275,
1109,
8,
3349,
14,
6640,
459,
344,
1105,
13610,
198,
67,
1366,
275,
22208,
14,
2087,
14,
1122,
8,
3349,
14,
6640,
459,
3966,
1105,
13610,
198,
67,
1366,
275,
900,
14,
23456,
8,
67,
1366,
14,
22309,
1012,
13610,
198,
3,
286,
1366,
275,
2197,
14,
9866,
8,
3349,
14,
6640,
459,
3966,
995,
2071,
65,
12,
450,
68,
450,
66,
450,
57,
450,
40,
2689,
45,
2689,
51,
531,
13610,
198,
67,
5949,
275,
3721,
14,
6640,
459,
2502,
418,
13610,
198,
67,
1872,
275,
3721,
14,
505,
13610,
198,
1266,
459,
6223,
2278,
740,
3252,
344,
356,
67,
998,
12,
283,
3954,
356,
67,
1366,
12,
283,
2502,
356,
67,
5949,
12,
283,
505,
356,
67,
1872,
1552,
1223,
198,
2590,
2186,
465,
221,
325,
26,
4122,
198,
1361,
8,
69,
9,
10060,
198,
1107,
6519,
8065,
199,
318,
1852,
63,
3349,
63,
16780,
1547,
1715,
12,
485,
1266,
12818,
12,
485,
1266,
2042,
12,
485,
4445,
2042,
304,
1223,
198,
16780,
2042,
275,
747,
14,
515,
14,
904,
1547,
4445,
2042,
12,
283,
13017,
297,
2513,
16780,
358,
1223,
198,
692,
747,
14,
515,
14,
2444,
8,
16780,
2042,
9,
365,
756,
26,
4122,
198,
736,
14,
8347,
8,
16780,
2042,
9,
10060,
198,
1099,
63,
493,
275,
747,
14,
515,
14,
904,
8,
16780,
2042,
12,
283,
6223,
14,
16780,
358,
1223,
198,
692,
747,
14,
515,
14,
2444,
8,
1099,
63,
493,
9,
365,
715,
26,
4122,
198,
1107,
715,
10060,
198,
16780,
275,
7499,
8843,
1547,
22997,
8862,
29,
797,
9,
1223,
198,
70,
275,
6010,
14,
1490,
8,
1099,
63,
493,
12,
283,
87,
297,
283,
6610,
13,
24,
358,
1223,
198,
835,
275,
378,
1223,
198,
5734,
275,
21211,
8,
85,
3894,
5,
83,
61,
10663,
3721,
16831,
7,
450,
485,
1715,
12,
499,
12,
1616,
12,
715,
9,
1223,
198,
5734,
14,
409,
63,
4142,
3556,
8,
552,
1547,
1266,
12818,
430,
1223,
198,
5734,
14,
928,
342,
1223,
198,
509,
6519,
998,
315,
485,
1266,
12818,
26,
4122,
198,
3,
870,
8,
85,
3894,
5,
83
] |
[
13,
1837,
2803,
26,
2774,
13,
24,
1882,
202,
199,
2344,
202,
199,
10502,
641,
9708,
14,
4119,
14,
24293,
202,
199,
19920,
641,
9708,
14,
4119,
14,
24293,
202,
199,
2344,
202,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
202,
199,
646,
747,
202,
199,
646,
16004,
202,
199,
646,
295,
202,
199,
646,
900,
202,
199,
646,
6010,
202,
199,
646,
984,
202,
199,
646,
3873,
202,
199,
646,
3473,
202,
199,
646,
22208,
14,
2087,
202,
199,
504,
2197,
492,
2197,
202,
199,
504,
2863,
83,
492,
26793,
83,
202,
199,
504,
2748,
14,
9464,
492,
13139,
202,
199,
504,
4534,
14,
26424,
492,
7499,
8843,
202,
199,
504,
9922,
20,
492,
17132,
202,
199,
504,
15439,
3028,
492,
19292,
1084,
202,
199,
504,
3778,
492,
21211,
202,
199,
504,
7611,
14,
14686,
2445,
492,
12579,
2445,
202,
199,
504,
7611,
14,
17545,
4131,
492,
21605,
4131,
202,
199,
504,
7611,
14,
14686,
3353,
492,
12579,
3353,
8065,
199,
26207,
14776,
202,
199,
3,
1852,
6519,
2556,
202,
199,
26207,
14776,
202,
199,
318,
2248,
63,
493,
63,
16780,
1547,
7218,
304,
1223,
198,
576,
275,
1052,
1223,
198,
70,
275,
1551,
1547,
7218,
12,
283,
82,
358,
1223,
198,
6710,
715,
26,
4122,
198,
604,
275,
289,
14,
6407,
342,
4122,
198,
692,
1004,
365,
488,
503,
1004,
508,
10812,
4785,
26045,
198,
5364,
12,
5932,
275,
1004,
14,
1294,
2258,
84,
358,
4122,
198,
5364,
275,
5148,
14,
1814,
10998,
1370,
358,
4122,
198,
2996,
275,
5148,
14,
1623,
360,
1308,
2659,
4122,
198,
692,
4280,
2356,
378,
26,
7903,
198,
5364,
275,
5148,
59,
2996,
2938,
8065,
507,
198,
576,
59,
5364,
61,
275,
5932,
14,
1294,
360,
5320,
1223,
198,
1107,
666,
8065,
199,
318,
2248,
63,
1266,
63,
16780,
1547,
1501,
304,
1223,
198,
2344,
1223,
198,
1107,
5932,
367,
1924,
2974,
8,
476,
14,
570,
12,
6519,
3622,
11965,
10060,
198,
26,
635,
485,
1501,
26,
1223,
198,
26,
1107,
26,
791,
1053,
998,
17,
21662,
1027,
17,
297,
283,
1027,
18,
297,
4496,
467,
283,
1053,
998,
18,
356,
8607,
4496,
93,
1223,
198,
2344,
1223,
198,
70,
275,
1551,
1547,
1501,
12,
283,
82,
358,
1223,
198,
1278,
275,
289,
14,
9684,
342,
1223,
198,
70,
14,
1600,
342,
10060,
198,
16780,
275,
1052,
1223,
198,
509,
1004,
315,
2385,
26,
4122,
198,
2996,
275,
1004,
14,
1623,
2258,
84,
358,
4122,
198,
498,
275,
1109,
8,
604,
1491,
2996,
566,
4122,
198,
3148,
275,
1004,
59,
2996,
435,
413,
6809,
17,
61,
4122,
198,
3148,
275,
5932,
14,
1913,
1252,
1294,
360,
5320,
340,
822,
8,
3148,
9,
690,
378,
587,
942,
4122,
198,
3,
2813,
4596,
2974,
4122,
198,
2996,
275,
378,
4122,
198,
6710,
4280,
665,
822,
8,
3148,
304,
7903,
198,
692,
5932,
59,
2996,
61,
508,
8061,
13610,
198,
2264,
5932,
59,
2996,
61,
7903,
198,
2836,
26,
13610,
198,
2996,
847,
413,
4122,
198,
16780,
59,
498,
61,
275,
5932,
10060,
198,
1107,
16831,
8065,
199,
26207,
14776,
202,
199,
3,
1852,
3721,
2556,
202,
199,
26207,
14776,
202,
199,
318,
2248,
63,
1266,
63,
1652,
1547,
7218,
304,
1223,
198,
2344,
1223,
198,
362,
18227,
2556,
7182,
370,
485,
6662,
687,
6519,
7611,
4692,
570,
1223,
198,
26,
635,
485,
3417,
26,
1223,
198,
26,
635,
485,
6662,
26,
1223,
198,
26,
1107,
26,
1223,
198,
2344,
1223,
198,
1266,
275,
1052,
1223,
198,
893,
26,
4122,
198,
1231,
275,
13139,
14,
1122,
1547,
7218,
680,
24544,
342,
26045,
198,
1053,
1450,
275,
1738,
59,
16,
1055,
1623,
360,
1053,
358,
221,
327,
2775,
690,
1242,
4122,
198,
1266,
459,
1213,
418,
275,
1242,
1450,
14,
1623,
360,
1213,
1959,
505,
4122,
198,
1266,
459,
3257,
418,
275,
1242,
1450,
14,
1623,
360,
1802,
1959,
505,
8065,
507,
198,
1266,
459,
6223,
418,
275,
942,
4122,
198,
6223,
275,
1242,
1450,
14,
1623,
360,
6223,
358,
4122,
198,
692,
6786,
365,
440,
488,
26,
7903,
198,
509,
3721,
315,
6786,
26,
13610,
198,
67,
998,
275,
1109,
8,
3349,
14,
6640,
459,
344,
1105,
13610,
198,
67,
1366,
275,
22208,
14,
2087,
14,
1122,
8,
3349,
14,
6640,
459,
3966,
1105,
13610,
198,
67,
1366,
275,
900,
14,
23456,
8,
67,
1366,
14,
22309,
1012,
13610,
198,
3,
286,
1366,
275,
2197,
14,
9866,
8,
3349,
14,
6640,
459,
3966,
995,
2071,
65,
12,
450,
68,
450,
66,
450,
57,
450,
40,
2689,
45,
2689,
51,
531,
13610,
198,
67,
5949,
275,
3721,
14,
6640,
459,
2502,
418,
13610,
198,
67,
1872,
275,
3721,
14,
505,
13610,
198,
1266,
459,
6223,
2278,
740,
3252,
344,
356,
67,
998,
12,
283,
3954,
356,
67,
1366,
12,
283,
2502,
356,
67,
5949,
12,
283,
505,
356,
67,
1872,
1552,
1223,
198,
2590,
2186,
465,
221,
325,
26,
4122,
198,
1361,
8,
69,
9,
10060,
198,
1107,
6519,
8065,
199,
318,
1852,
63,
3349,
63,
16780,
1547,
1715,
12,
485,
1266,
12818,
12,
485,
1266,
2042,
12,
485,
4445,
2042,
304,
1223,
198,
16780,
2042,
275,
747,
14,
515,
14,
904,
1547,
4445,
2042,
12,
283,
13017,
297,
2513,
16780,
358,
1223,
198,
692,
747,
14,
515,
14,
2444,
8,
16780,
2042,
9,
365,
756,
26,
4122,
198,
736,
14,
8347,
8,
16780,
2042,
9,
10060,
198,
1099,
63,
493,
275,
747,
14,
515,
14,
904,
8,
16780,
2042,
12,
283,
6223,
14,
16780,
358,
1223,
198,
692,
747,
14,
515,
14,
2444,
8,
1099,
63,
493,
9,
365,
715,
26,
4122,
198,
1107,
715,
10060,
198,
16780,
275,
7499,
8843,
1547,
22997,
8862,
29,
797,
9,
1223,
198,
70,
275,
6010,
14,
1490,
8,
1099,
63,
493,
12,
283,
87,
297,
283,
6610,
13,
24,
358,
1223,
198,
835,
275,
378,
1223,
198,
5734,
275,
21211,
8,
85,
3894,
5,
83,
61,
10663,
3721,
16831,
7,
450,
485,
1715,
12,
499,
12,
1616,
12,
715,
9,
1223,
198,
5734,
14,
409,
63,
4142,
3556,
8,
552,
1547,
1266,
12818,
430,
1223,
198,
5734,
14,
928,
342,
1223,
198,
509,
6519,
998,
315,
485,
1266,
12818,
26,
4122,
198,
3,
870,
8,
85,
3894,
5,
83,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
schlueter/ansible
|
lib/ansible/modules/cloud/amazon/sts_assume_role.py
|
12
|
6436
|
#!/usr/bin/python
# Copyright: Ansible Project
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['stableinterface'],
'supported_by': 'certified'}
DOCUMENTATION = '''
---
module: sts_assume_role
short_description: Assume a role using AWS Security Token Service and obtain temporary credentials
description:
- Assume a role using AWS Security Token Service and obtain temporary credentials
version_added: "2.0"
author:
- Boris Ekelchik (@bekelchik)
- Marek Piatek (@piontas)
options:
role_arn:
description:
- The Amazon Resource Name (ARN) of the role that the caller is
assuming (http://docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html#Identifiers_ARNs)
required: true
role_session_name:
description:
- Name of the role's session - will be used by CloudTrail
required: true
policy:
description:
- Supplemental policy to use in addition to assumed role's policies.
required: false
default: null
duration_seconds:
description:
- The duration, in seconds, of the role session. The value can range from 900 seconds (15 minutes) to 3600 seconds (1 hour).
By default, the value is set to 3600 seconds.
required: false
default: null
external_id:
description:
- A unique identifier that is used by third parties to assume a role in their customers' accounts.
required: false
default: null
mfa_serial_number:
description:
- The identification number of the MFA device that is associated with the user who is making the AssumeRole call.
required: false
default: null
mfa_token:
description:
- The value provided by the MFA device, if the trust policy of the role being assumed requires MFA.
required: false
default: null
notes:
- In order to use the assumed role in a following playbook task you must pass the access_key, access_secret and access_token
extends_documentation_fragment:
- aws
- ec2
requirements:
- boto3
- botocore
- python >= 2.6
'''
RETURN = '''
sts_creds:
description: The temporary security credentials, which include an access key ID, a secret access key, and a security (or session) token
returned: always
type: dict
sample:
access_key: XXXXXXXXXXXXXXXXXXXX
expiration: 2017-11-11T11:11:11+00:00
secret_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
session_token: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
sts_user:
description: The Amazon Resource Name (ARN) and the assumed role ID
returned: always
type: dict
sample:
assumed_role_id: arn:aws:sts::123456789012:assumed-role/demo/Bob
arn: ARO123EXAMPLE123:Bob
changed:
description: True if obtaining the credentials succeeds
type: bool
returned: always
'''
EXAMPLES = '''
# Note: These examples do not set authentication details, see the AWS Guide for details.
# Assume an existing role (more details: http://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRole.html)
sts_assume_role:
role_arn: "arn:aws:iam::123456789012:role/someRole"
role_session_name: "someRoleSession"
register: assumed_role
# Use the assumed role above to tag an instance in account 123456789012
ec2_tag:
aws_access_key: "{{ assumed_role.sts_creds.access_key }}"
aws_secret_key: "{{ assumed_role.sts_creds.secret_key }}"
security_token: "{{ assumed_role.sts_creds.session_token }}"
resource: i-xyzxyz01
state: present
tags:
MyNewTag: value
'''
from ansible.module_utils.aws.core import AnsibleAWSModule
from ansible.module_utils.ec2 import (boto3_conn, get_aws_connection_info,
ec2_argument_spec, camel_dict_to_snake_dict)
try:
from botocore.exceptions import ClientError, ParamValidationError
except ImportError:
pass # caught by imported AnsibleAWSModule
def _parse_response(response):
credentials = response.get('Credentials', {})
user = response.get('AssumedRoleUser', {})
sts_cred = {
'access_key': credentials.get('AccessKeyId'),
'secret_key': credentials.get('SecretAccessKey'),
'session_token': credentials.get('SessionToken'),
'expiration': credentials.get('Expiration')
}
sts_user = camel_dict_to_snake_dict(user)
return sts_cred, sts_user
def assume_role_policy(connection, module):
params = {
'RoleArn': module.params.get('role_arn'),
'RoleSessionName': module.params.get('role_session_name'),
'Policy': module.params.get('policy'),
'DurationSeconds': module.params.get('duration_seconds'),
'ExternalId': module.params.get('external_id'),
'SerialNumber': module.params.get('mfa_serial_number'),
'TokenCode': module.params.get('mfa_token')
}
changed = False
kwargs = dict((k, v) for k, v in params.items() if v is not None)
try:
response = connection.assume_role(**kwargs)
changed = True
except (ClientError, ParamValidationError) as e:
module.fail_json_aws(e)
sts_cred, sts_user = _parse_response(response)
module.exit_json(changed=changed, sts_creds=sts_cred, sts_user=sts_user)
def main():
argument_spec = ec2_argument_spec()
argument_spec.update(
dict(
role_arn=dict(required=True, default=None),
role_session_name=dict(required=True, default=None),
duration_seconds=dict(required=False, default=None, type='int'),
external_id=dict(required=False, default=None),
policy=dict(required=False, default=None),
mfa_serial_number=dict(required=False, default=None),
mfa_token=dict(required=False, default=None)
)
)
module = AnsibleAWSModule(argument_spec=argument_spec)
region, ec2_url, aws_connect_kwargs = get_aws_connection_info(module, boto3=True)
if region:
connection = boto3_conn(module, conn_type='client', resource='sts',
region=region, endpoint=ec2_url, **aws_connect_kwargs)
else:
module.fail_json(msg="region must be specified")
assume_role_policy(connection, module)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
26,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
2247,
8981,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
23014,
63,
21946,
63,
3756,
199,
3612,
63,
1802,
26,
16269,
282,
4719,
1808,
10168,
13863,
8767,
7591,
436,
3332,
7937,
6235,
199,
1802,
26,
272,
446,
16269,
282,
4719,
1808,
10168,
13863,
8767,
7591,
436,
3332,
7937,
6235,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
2502,
26,
272,
446,
699,
269,
374,
662,
75,
352,
335,
3258,
8593,
1235,
75,
352,
335,
3258,
9,
272,
446,
603,
1530,
75,
19835,
323,
75,
8593,
1038,
1888,
305,
9,
199,
1419,
26,
523,
4719,
63,
1060,
26,
272,
1369,
26,
489,
446,
710,
14347,
7337,
2812,
334,
26513,
9,
402,
314,
4719,
626,
314,
8025,
365,
267,
18002,
334,
1014,
921,
4757,
14,
7231,
14,
15144,
14,
957,
15,
41,
1156,
15,
7410,
15,
1899,
4324,
271,
15,
10369,
63,
41,
8577,
14,
1360,
3,
41,
8577,
63,
689,
2438,
9,
272,
1415,
26,
2549,
523,
4719,
63,
1730,
63,
354,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
4719,
1159,
2351,
446,
911,
506,
1202,
701,
8142,
2437,
382,
272,
1415,
26,
2549,
523,
4592,
26,
272,
1369,
26,
489,
446,
29083,
968,
279,
4592,
370,
675,
315,
10234,
370,
10826,
4719,
1159,
14118,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
7373,
63,
4515,
26,
272,
1369,
26,
489,
446,
710,
7373,
12,
315,
4696,
12,
402,
314,
4719,
2351,
14,
710,
574,
883,
1425,
687,
27151,
4696,
334,
1046,
9395,
9,
370,
15751,
4696,
334,
17,
6925,
680,
267,
4885,
849,
12,
314,
574,
365,
663,
370,
15751,
4696,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
5957,
63,
344,
26,
272,
1369,
26,
489,
446,
437,
3747,
5148,
626,
365,
1202,
701,
10919,
623,
1417,
370,
5534,
282,
4719,
315,
3932,
286,
28078,
7,
12639,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
333,
667,
63,
2171,
63,
1955,
26,
272,
1369,
26,
489,
446,
710,
29193,
1329,
402,
314,
603,
2078,
2243,
626,
365,
4568,
543,
314,
922,
3963,
365,
10663,
314,
16269,
7422,
1240,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
333,
667,
63,
1418,
26,
272,
1369,
26,
489,
446,
710,
574,
2741,
701,
314,
603,
2078,
2243,
12,
340,
314,
16822,
4592,
402,
314,
4719,
3769,
10826,
5074,
603,
2078,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
199,
5983,
26,
523,
446,
1010,
1865,
370,
675,
314,
10826,
4719,
315,
282,
2569,
15695,
2120,
1265,
1471,
986,
314,
2879,
63,
498,
12,
2879,
63,
4731,
436,
2879,
63,
1418,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
11488,
272,
446,
7062,
18,
199,
7538,
26,
272,
446,
6055,
19,
272,
446,
21199,
272,
446,
2366,
2356,
499,
14,
22,
199,
2344,
199,
199,
9677,
275,
1449,
199,
10329,
63,
15226,
26,
272,
1369,
26,
710,
7937,
6391,
6235,
12,
1314,
2387,
376,
2879,
790,
2870,
12,
282,
7565,
2879,
790,
12,
436,
282,
6391,
334,
269,
2351,
9,
1526,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
489,
2879,
63,
498,
26,
5787,
25837,
56,
489,
15399,
26,
9708,
13,
845,
13,
845,
52,
845,
26,
845,
26,
845,
11,
383,
26,
383,
489,
7565,
63,
498,
26,
5787,
25837,
25837,
6873,
56,
489,
2351,
63,
1418,
26,
5787,
25837,
25837,
25837,
13312,
2483,
199,
10329,
63,
751,
26,
272,
1369,
26,
710,
14347,
7337,
2812,
334,
26513,
9,
436,
314,
10826,
4719,
2870,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
489,
10826,
63,
3756,
63,
344,
26,
601,
78,
26,
7231,
26,
10329,
447,
11272,
11533,
26,
21946,
68,
13,
3756,
15,
8768,
15,
22593,
489,
601,
78,
26,
437,
1092,
4288,
26900,
4288,
26,
22593,
199,
2489,
26,
272,
1369,
26,
715,
340,
12408,
314,
6235,
24611,
272,
730,
26,
2155,
272,
2138,
26,
3544,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
3390,
26,
5723,
7251,
886,
440,
663,
6299,
2436,
12,
1937,
314,
10168,
15423,
367,
2436,
14,
199,
199,
3,
16269,
376,
3411,
4719,
334,
6878,
2436,
26,
1455,
921,
4757,
14,
7231,
14,
15144,
14,
957,
15,
840,
51,
15,
7410,
15,
3735,
5083,
15,
3735,
63,
9824,
940,
7422,
14,
1360,
9,
199,
10329,
63,
21946,
63,
3756,
26,
523,
4719,
63,
1060,
26,
298,
1060,
26,
7231,
26,
17741,
447,
11272,
11533,
26,
3756,
15,
3972,
7422,
2,
523,
4719,
63,
1730,
63,
354,
26,
298,
3972,
7422,
4434,
2,
199,
2683,
26,
10826,
63,
3756,
199,
199,
3,
3645,
314,
10826,
4719,
3432,
370,
1947,
376,
1256,
315,
2933,
32695,
11533,
199,
825,
18,
63,
1450,
26,
523,
11488,
63,
2732,
63,
498,
26,
7370,
10826,
63,
3756,
14,
10329,
63,
15226,
14,
2732,
63,
498,
7820,
523,
11488,
63,
4731,
63,
498,
26,
7370,
10826,
63,
3756,
14,
10329,
63,
15226,
14,
4731,
63,
498,
7820,
523,
6391,
63,
1418,
26,
7370,
10826,
63,
3756,
14,
10329,
63,
15226,
14,
1730,
63,
1418,
7820,
523,
2073,
26,
284,
13,
8568,
8568,
614,
523,
1174,
26,
3451,
523,
3762,
26,
272,
4932,
4665,
1931,
26,
574,
199,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
7231,
14,
1018,
492,
2622,
13226,
2377,
199,
504,
3242,
14,
578,
63,
1208,
14,
825,
18,
492,
334,
10914,
19,
63,
1631,
12,
664,
63,
7231,
63,
2105,
63,
815,
12,
4228,
7062,
18,
63,
2094,
63,
1650,
12,
31129,
63,
807,
63,
475,
63,
21415,
63,
807,
9,
199,
199,
893,
26
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
26,
2622,
7290,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
11989,
3266,
995,
490,
283,
4946,
63,
991,
356,
283,
2247,
8981,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
23014,
63,
21946,
63,
3756,
199,
3612,
63,
1802,
26,
16269,
282,
4719,
1808,
10168,
13863,
8767,
7591,
436,
3332,
7937,
6235,
199,
1802,
26,
272,
446,
16269,
282,
4719,
1808,
10168,
13863,
8767,
7591,
436,
3332,
7937,
6235,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
2502,
26,
272,
446,
699,
269,
374,
662,
75,
352,
335,
3258,
8593,
1235,
75,
352,
335,
3258,
9,
272,
446,
603,
1530,
75,
19835,
323,
75,
8593,
1038,
1888,
305,
9,
199,
1419,
26,
523,
4719,
63,
1060,
26,
272,
1369,
26,
489,
446,
710,
14347,
7337,
2812,
334,
26513,
9,
402,
314,
4719,
626,
314,
8025,
365,
267,
18002,
334,
1014,
921,
4757,
14,
7231,
14,
15144,
14,
957,
15,
41,
1156,
15,
7410,
15,
1899,
4324,
271,
15,
10369,
63,
41,
8577,
14,
1360,
3,
41,
8577,
63,
689,
2438,
9,
272,
1415,
26,
2549,
523,
4719,
63,
1730,
63,
354,
26,
272,
1369,
26,
489,
446,
2812,
402,
314,
4719,
1159,
2351,
446,
911,
506,
1202,
701,
8142,
2437,
382,
272,
1415,
26,
2549,
523,
4592,
26,
272,
1369,
26,
489,
446,
29083,
968,
279,
4592,
370,
675,
315,
10234,
370,
10826,
4719,
1159,
14118,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
7373,
63,
4515,
26,
272,
1369,
26,
489,
446,
710,
7373,
12,
315,
4696,
12,
402,
314,
4719,
2351,
14,
710,
574,
883,
1425,
687,
27151,
4696,
334,
1046,
9395,
9,
370,
15751,
4696,
334,
17,
6925,
680,
267,
4885,
849,
12,
314,
574,
365,
663,
370,
15751,
4696,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
5957,
63,
344,
26,
272,
1369,
26,
489,
446,
437,
3747,
5148,
626,
365,
1202,
701,
10919,
623,
1417,
370,
5534,
282,
4719,
315,
3932,
286,
28078,
7,
12639,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
333,
667,
63,
2171,
63,
1955,
26,
272,
1369,
26,
489,
446,
710,
29193,
1329,
402,
314,
603,
2078,
2243,
626,
365,
4568,
543,
314,
922,
3963,
365,
10663,
314,
16269,
7422,
1240,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
523,
333,
667,
63,
1418,
26,
272,
1369,
26,
489,
446,
710,
574,
2741,
701,
314,
603,
2078,
2243,
12,
340,
314,
16822,
4592,
402,
314,
4719,
3769,
10826,
5074,
603,
2078,
14,
272,
1415,
26,
3055,
272,
849,
26,
2973,
199,
5983,
26,
523,
446,
1010,
1865,
370,
675,
314,
10826,
4719,
315,
282,
2569,
15695,
2120,
1265,
1471,
986,
314,
2879,
63,
498,
12,
2879,
63,
4731,
436,
2879,
63,
1418,
199,
11036,
63,
9970,
63,
7677,
26,
272,
446,
11488,
272,
446,
7062,
18,
199,
7538,
26,
272,
446,
6055,
19,
272,
446,
21199,
272,
446,
2366,
2356,
499,
14,
22,
199,
2344,
199,
199,
9677,
275,
1449,
199,
10329,
63,
15226,
26,
272,
1369,
26,
710,
7937,
6391,
6235,
12,
1314,
2387,
376,
2879,
790,
2870,
12,
282,
7565,
2879,
790,
12,
436,
282,
6391,
334,
269,
2351,
9,
1526,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
489,
2879,
63,
498,
26,
5787,
25837,
56,
489,
15399,
26,
9708,
13,
845,
13,
845,
52,
845,
26,
845,
26,
845,
11,
383,
26,
383,
489,
7565,
63,
498,
26,
5787,
25837,
25837,
6873,
56,
489,
2351,
63,
1418,
26,
5787,
25837,
25837,
25837,
13312,
2483,
199,
10329,
63,
751,
26,
272,
1369,
26,
710,
14347,
7337,
2812,
334,
26513,
9,
436,
314,
10826,
4719,
2870,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
489,
10826,
63,
3756,
63,
344,
26,
601,
78,
26,
7231,
26,
10329,
447,
11272,
11533,
26,
21946,
68,
13,
3756,
15,
8768,
15,
22593,
489,
601,
78,
26,
437,
1092,
4288,
26900,
4288,
26,
22593,
199,
2489,
26,
272,
1369,
26,
715,
340,
12408,
314,
6235,
24611,
272,
730,
26,
2155,
272,
2138,
26,
3544,
199,
2344,
199,
199,
8918,
275,
1449,
199,
3,
3390,
26,
5723,
7251,
886,
440,
663,
6299,
2436,
12,
1937,
314,
10168,
15423,
367,
2436,
14,
199,
199,
3,
16269,
376,
3411,
4719,
334,
6878,
2436,
26,
1455,
921,
4757,
14,
7231,
14,
15144,
14,
957,
15,
840,
51,
15,
7410,
15,
3735,
5083,
15,
3735,
63,
9824,
940,
7422,
14,
1360,
9,
199,
10329,
63,
21946,
63,
3756,
26,
523,
4719,
63,
1060,
26,
298,
1060,
26,
7231,
26,
17741,
447,
11272,
11533,
26,
3756,
15,
3972,
7422,
2,
523,
4719,
63,
1730,
63,
354,
26,
298,
3972,
7422,
4434,
2,
199,
2683,
26,
10826,
63,
3756,
199,
199,
3,
3645,
314,
10826,
4719,
3432,
370,
1947,
376,
1256,
315,
2933,
32695,
11533,
199,
825,
18,
63,
1450,
26,
523,
11488,
63,
2732,
63,
498,
26,
7370,
10826,
63,
3756,
14,
10329,
63,
15226,
14,
2732,
63,
498,
7820,
523,
11488,
63,
4731,
63,
498,
26,
7370,
10826,
63,
3756,
14,
10329,
63,
15226,
14,
4731,
63,
498,
7820,
523,
6391,
63,
1418,
26,
7370,
10826,
63,
3756,
14,
10329,
63,
15226,
14,
1730,
63,
1418,
7820,
523,
2073,
26,
284,
13,
8568,
8568,
614,
523,
1174,
26,
3451,
523,
3762,
26,
272,
4932,
4665,
1931,
26,
574,
199,
199,
2344,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
7231,
14,
1018,
492,
2622,
13226,
2377,
199,
504,
3242,
14,
578,
63,
1208,
14,
825,
18,
492,
334,
10914,
19,
63,
1631,
12,
664,
63,
7231,
63,
2105,
63,
815,
12,
4228,
7062,
18,
63,
2094,
63,
1650,
12,
31129,
63,
807,
63,
475,
63,
21415,
63,
807,
9,
199,
199,
893,
26,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
lz1988/django-web2015
|
build/lib/django/contrib/admindocs/urls.py
|
317
|
1092
|
from django.conf.urls import patterns, url
from django.contrib.admindocs import views
urlpatterns = patterns('',
url('^$',
views.doc_index,
name='django-admindocs-docroot'
),
url('^bookmarklets/$',
views.bookmarklets,
name='django-admindocs-bookmarklets'
),
url('^tags/$',
views.template_tag_index,
name='django-admindocs-tags'
),
url('^filters/$',
views.template_filter_index,
name='django-admindocs-filters'
),
url('^views/$',
views.view_index,
name='django-admindocs-views-index'
),
url('^views/(?P<view>[^/]+)/$',
views.view_detail,
name='django-admindocs-views-detail'
),
url('^models/$',
views.model_index,
name='django-admindocs-models-index'
),
url('^models/(?P<app_label>[^\.]+)\.(?P<model_name>[^/]+)/$',
views.model_detail,
name='django-admindocs-models-detail'
),
url('^templates/(?P<template>.*)/$',
views.template_detail,
name='django-admindocs-templates'
),
)
|
bsd-2-clause
|
[
504,
1639,
14,
2190,
14,
3603,
492,
7970,
12,
1166,
199,
504,
1639,
14,
2828,
14,
14464,
688,
14851,
492,
6858,
199,
199,
20050,
275,
7970,
8594,
272,
1166,
9097,
4268,
267,
6858,
14,
1301,
63,
1080,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
1301,
1231,
7,
272,
2318,
272,
1166,
9097,
17341,
16537,
10884,
267,
6858,
14,
17341,
16537,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
17341,
16537,
7,
272,
2318,
272,
1166,
9097,
2969,
10884,
267,
6858,
14,
1160,
63,
1450,
63,
1080,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
2969,
7,
272,
2318,
272,
1166,
9097,
4273,
10884,
267,
6858,
14,
1160,
63,
1541,
63,
1080,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
4273,
7,
272,
2318,
272,
1166,
9097,
4196,
10884,
267,
6858,
14,
1345,
63,
1080,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
4196,
13,
1080,
7,
272,
2318,
272,
1166,
9097,
4196,
9448,
48,
28,
1345,
26906,
2447,
4268,
267,
6858,
14,
1345,
63,
5506,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
4196,
13,
5506,
7,
272,
2318,
272,
1166,
9097,
992,
10884,
267,
6858,
14,
1238,
63,
1080,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
992,
13,
1080,
7,
272,
2318,
272,
1166,
9097,
992,
9448,
48,
28,
571,
63,
1302,
13489,
4537,
18096,
14,
2229,
48,
28,
1238,
63,
354,
26906,
2447,
4268,
267,
6858,
14,
1238,
63,
5506,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
992,
13,
5506,
7,
272,
2318,
272,
1166,
9097,
5876,
9448,
48,
28,
1160,
23742,
2447,
4268,
267,
6858,
14,
1160,
63,
5506,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
5876,
7,
272,
2318,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
2190,
14,
3603,
492,
7970,
12,
1166,
199,
504,
1639,
14,
2828,
14,
14464,
688,
14851,
492,
6858,
199,
199,
20050,
275,
7970,
8594,
272,
1166,
9097,
4268,
267,
6858,
14,
1301,
63,
1080,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
1301,
1231,
7,
272,
2318,
272,
1166,
9097,
17341,
16537,
10884,
267,
6858,
14,
17341,
16537,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
17341,
16537,
7,
272,
2318,
272,
1166,
9097,
2969,
10884,
267,
6858,
14,
1160,
63,
1450,
63,
1080,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
2969,
7,
272,
2318,
272,
1166,
9097,
4273,
10884,
267,
6858,
14,
1160,
63,
1541,
63,
1080,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
4273,
7,
272,
2318,
272,
1166,
9097,
4196,
10884,
267,
6858,
14,
1345,
63,
1080,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
4196,
13,
1080,
7,
272,
2318,
272,
1166,
9097,
4196,
9448,
48,
28,
1345,
26906,
2447,
4268,
267,
6858,
14,
1345,
63,
5506,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
4196,
13,
5506,
7,
272,
2318,
272,
1166,
9097,
992,
10884,
267,
6858,
14,
1238,
63,
1080,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
992,
13,
1080,
7,
272,
2318,
272,
1166,
9097,
992,
9448,
48,
28,
571,
63,
1302,
13489,
4537,
18096,
14,
2229,
48,
28,
1238,
63,
354,
26906,
2447,
4268,
267,
6858,
14,
1238,
63,
5506,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
992,
13,
5506,
7,
272,
2318,
272,
1166,
9097,
5876,
9448,
48,
28,
1160,
23742,
2447,
4268,
267,
6858,
14,
1160,
63,
5506,
12,
267,
536,
534,
1176,
13,
14464,
688,
14851,
13,
5876,
7,
272,
2318,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
trhd/meson
|
mesonbuild/coredata.py
|
2
|
19655
|
# Copyright 2012-2017 The Meson development team
# 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 pickle, os, uuid
import sys
from pathlib import PurePath
from collections import OrderedDict
from .mesonlib import MesonException, commonpath
from .mesonlib import default_libdir, default_libexecdir, default_prefix
import ast
version = '0.45.0.dev1'
backendlist = ['ninja', 'vs', 'vs2010', 'vs2015', 'vs2017', 'xcode']
class UserOption:
def __init__(self, name, description, choices):
super().__init__()
self.name = name
self.choices = choices
self.description = description
# Check that the input is a valid value and return the
# "cleaned" or "native" version. For example the Boolean
# option could take the string "true" and return True.
def validate_value(self, value):
raise RuntimeError('Derived option class did not override validate_value.')
class UserStringOption(UserOption):
def __init__(self, name, description, value, choices=None):
super().__init__(name, description, choices)
self.set_value(value)
def validate(self, value):
if not isinstance(value, str):
raise MesonException('Value "%s" for string option "%s" is not a string.' % (str(value), self.name))
def set_value(self, newvalue):
self.validate(newvalue)
self.value = newvalue
def validate_value(self, value):
self.validate(value)
return value
class UserBooleanOption(UserOption):
def __init__(self, name, description, value):
super().__init__(name, description, [True, False])
self.set_value(value)
def tobool(self, thing):
if isinstance(thing, bool):
return thing
if thing.lower() == 'true':
return True
if thing.lower() == 'false':
return False
raise MesonException('Value %s is not boolean (true or false).' % thing)
def set_value(self, newvalue):
self.value = self.tobool(newvalue)
def __bool__(self):
return self.value
def validate_value(self, value):
return self.tobool(value)
class UserIntegerOption(UserOption):
def __init__(self, name, description, min_value, max_value, value):
super().__init__(name, description, [True, False])
self.min_value = min_value
self.max_value = max_value
self.set_value(value)
def set_value(self, newvalue):
if isinstance(newvalue, str):
newvalue = self.toint(newvalue)
if not isinstance(newvalue, int):
raise MesonException('New value for integer option is not an integer.')
if self.min_value is not None and newvalue < self.min_value:
raise MesonException('New value %d is less than minimum value %d.' % (newvalue, self.min_value))
if self.max_value is not None and newvalue > self.max_value:
raise MesonException('New value %d is more than maximum value %d.' % (newvalue, self.max_value))
self.value = newvalue
def toint(self, valuestring):
try:
return int(valuestring)
except:
raise MesonException('Value string "%s" is not convertable to an integer.' % valuestring)
def validate_value(self, value):
return self.toint(value)
class UserComboOption(UserOption):
def __init__(self, name, description, choices, value):
super().__init__(name, description, choices)
if not isinstance(self.choices, list):
raise MesonException('Combo choices must be an array.')
for i in self.choices:
if not isinstance(i, str):
raise MesonException('Combo choice elements must be strings.')
self.set_value(value)
def set_value(self, newvalue):
if newvalue not in self.choices:
optionsstring = ', '.join(['"%s"' % (item,) for item in self.choices])
raise MesonException('Value "%s" for combo option "%s" is not one of the choices. Possible choices are: %s.' % (newvalue, self.name, optionsstring))
self.value = newvalue
def validate_value(self, value):
if value not in self.choices:
raise MesonException('Value %s not one of accepted values.' % value)
return value
class UserArrayOption(UserOption):
def __init__(self, name, description, value, **kwargs):
super().__init__(name, description, kwargs.get('choices', []))
self.set_value(value, user_input=False)
def validate(self, value, user_input):
# User input is for options defined on the command line (via -D
# options). Users can put their input in as a comma separated
# string, but for defining options in meson_options.txt the format
# should match that of a combo
if not user_input:
if isinstance(value, str):
if not value.startswith('['):
raise MesonException('Valuestring does not define an array: ' + value)
newvalue = ast.literal_eval(value)
else:
newvalue = value
else:
assert isinstance(value, str)
if value.startswith('['):
newvalue = ast.literal_eval(value)
else:
newvalue = [v.strip() for v in value.split(',')]
if not isinstance(newvalue, list):
raise MesonException('"{0}" should be a string array, but it is not'.format(str(newvalue)))
for i in newvalue:
if not isinstance(i, str):
raise MesonException('String array element "{0}" is not a string.'.format(str(newvalue)))
if self.choices:
bad = [x for x in newvalue if x not in self.choices]
if bad:
raise MesonException('Options "{}" are not in allowed choices: "{}"'.format(
', '.join(bad), ', '.join(self.choices)))
return newvalue
def set_value(self, newvalue, user_input=True):
self.value = self.validate(newvalue, user_input)
def validate_value(self, value):
self.validate(value)
return value
# This class contains all data that must persist over multiple
# invocations of Meson. It is roughly the same thing as
# cmakecache.
class CoreData:
def __init__(self, options):
self.guid = str(uuid.uuid4()).upper()
self.test_guid = str(uuid.uuid4()).upper()
self.regen_guid = str(uuid.uuid4()).upper()
self.target_guids = {}
self.version = version
self.init_builtins(options)
self.init_backend_options(self.builtins['backend'].value)
self.user_options = {}
self.compiler_options = {}
self.base_options = {}
# These external_*args, are set via env vars CFLAGS, LDFLAGS, etc
# but only when not cross-compiling.
self.external_preprocess_args = {} # CPPFLAGS only
self.external_args = {} # CPPFLAGS + CFLAGS
self.external_link_args = {} # CFLAGS + LDFLAGS (with MSVC: only LDFLAGS)
self.cross_file = self.__load_cross_file(options.cross_file)
self.wrap_mode = options.wrap_mode
self.compilers = OrderedDict()
self.cross_compilers = OrderedDict()
self.deps = OrderedDict()
self.modules = {}
# Only to print a warning if it changes between Meson invocations.
self.pkgconf_envvar = os.environ.get('PKG_CONFIG_PATH', '')
@staticmethod
def __load_cross_file(filename):
"""Try to load the cross file.
If the filename is None return None. If the filename is an absolute
(after resolving variables and ~), return that absolute path. Next,
check if the file is relative to the current source dir. If the path
still isn't resolved do the following:
Linux + BSD:
- $XDG_DATA_HOME/meson/cross (or ~/.local/share/meson/cross if
undefined)
- $XDG_DATA_DIRS/meson/cross (or
/usr/local/share/meson/cross:/usr/share/meson/cross if undefined)
- Error
*:
- Error
BSD follows the Linux path and will honor XDG_* if set. This simplifies
the implementation somewhat, especially since most BSD users wont set
those environment variables.
"""
if filename is None:
return None
filename = os.path.expanduser(os.path.expandvars(filename))
if os.path.isabs(filename):
return filename
path_to_try = os.path.abspath(filename)
if os.path.exists(path_to_try):
return path_to_try
if sys.platform == 'linux' or 'bsd' in sys.platform.lower():
paths = [
os.environ.get('XDG_DATA_HOME', os.path.expanduser('~/.local/share')),
] + os.environ.get('XDG_DATA_DIRS', '/usr/local/share:/usr/share').split(':')
for path in paths:
path_to_try = os.path.join(path, 'meson', 'cross', filename)
if os.path.exists(path_to_try):
return path_to_try
raise MesonException('Cannot find specified cross file: ' + filename)
raise MesonException('Cannot find specified cross file: ' + filename)
def sanitize_prefix(self, prefix):
if not os.path.isabs(prefix):
raise MesonException('prefix value {!r} must be an absolute path'
''.format(prefix))
if prefix.endswith('/') or prefix.endswith('\\'):
# On Windows we need to preserve the trailing slash if the
# string is of type 'C:\' because 'C:' is not an absolute path.
if len(prefix) == 3 and prefix[1] == ':':
pass
# If prefix is a single character, preserve it since it is
# the root directory.
elif len(prefix) == 1:
pass
else:
prefix = prefix[:-1]
return prefix
def sanitize_dir_option_value(self, prefix, option, value):
'''
If the option is an installation directory option and the value is an
absolute path, check that it resides within prefix and return the value
as a path relative to the prefix.
This way everyone can do f.ex, get_option('libdir') and be sure to get
the library directory relative to prefix.
'''
if option.endswith('dir') and os.path.isabs(value) and \
option not in builtin_dir_noprefix_options:
# Value must be a subdir of the prefix
# commonpath will always return a path in the native format, so we
# must use pathlib.PurePath to do the same conversion before
# comparing.
if commonpath([value, prefix]) != str(PurePath(prefix)):
m = 'The value of the {!r} option is {!r} which must be a ' \
'subdir of the prefix {!r}.\nNote that if you pass a ' \
'relative path, it is assumed to be a subdir of prefix.'
raise MesonException(m.format(option, value, prefix))
# Convert path to be relative to prefix
skip = len(prefix) + 1
value = value[skip:]
return value
def init_builtins(self, options):
self.builtins = {}
# Sanitize prefix
options.prefix = self.sanitize_prefix(options.prefix)
# Initialize other builtin options
for key in get_builtin_options():
if hasattr(options, key):
value = getattr(options, key)
value = self.sanitize_dir_option_value(options.prefix, key, value)
setattr(options, key, value)
else:
value = get_builtin_option_default(key, prefix=options.prefix)
args = [key] + builtin_options[key][1:-1] + [value]
self.builtins[key] = builtin_options[key][0](*args)
def init_backend_options(self, backend_name):
self.backend_options = {}
if backend_name == 'ninja':
self.backend_options['backend_max_links'] = UserIntegerOption('backend_max_links',
'Maximum number of linker processes to run or 0 for no limit',
0, None, 0)
def get_builtin_option(self, optname):
if optname in self.builtins:
return self.builtins[optname].value
raise RuntimeError('Tried to get unknown builtin option %s.' % optname)
def set_builtin_option(self, optname, value):
if optname == 'prefix':
value = self.sanitize_prefix(value)
elif optname in self.builtins:
prefix = self.builtins['prefix'].value
value = self.sanitize_dir_option_value(prefix, optname, value)
else:
raise RuntimeError('Tried to set unknown builtin option %s.' % optname)
self.builtins[optname].set_value(value)
def validate_option_value(self, option_name, override_value):
for opts in (self.builtins, self.base_options, self.compiler_options, self.user_options):
if option_name in opts:
opt = opts[option_name]
return opt.validate_value(override_value)
raise MesonException('Tried to validate unknown option %s.' % option_name)
def load(filename):
load_fail_msg = 'Coredata file {!r} is corrupted. Try with a fresh build tree.'.format(filename)
try:
with open(filename, 'rb') as f:
obj = pickle.load(f)
except pickle.UnpicklingError:
raise MesonException(load_fail_msg)
if not isinstance(obj, CoreData):
raise MesonException(load_fail_msg)
if obj.version != version:
raise MesonException('Build directory has been generated with Meson version %s, which is incompatible with current version %s.\nPlease delete this build directory AND create a new one.' %
(obj.version, version))
return obj
def save(obj, filename):
if obj.version != version:
raise MesonException('Fatal version mismatch corruption.')
with open(filename, 'wb') as f:
pickle.dump(obj, f)
def get_builtin_options():
return list(builtin_options.keys())
def is_builtin_option(optname):
return optname in get_builtin_options()
def get_builtin_option_choices(optname):
if is_builtin_option(optname):
if builtin_options[optname][0] == UserStringOption:
return None
elif builtin_options[optname][0] == UserBooleanOption:
return [True, False]
else:
return builtin_options[optname][2]
else:
raise RuntimeError('Tried to get the supported values for an unknown builtin option \'%s\'.' % optname)
def get_builtin_option_description(optname):
if is_builtin_option(optname):
return builtin_options[optname][1]
else:
raise RuntimeError('Tried to get the description for an unknown builtin option \'%s\'.' % optname)
def get_builtin_option_default(optname, prefix='', noneIfSuppress=False):
if is_builtin_option(optname):
o = builtin_options[optname]
if o[0] == UserComboOption:
return o[3]
if optname in builtin_dir_noprefix_options:
if noneIfSuppress:
# Return None if argparse defaulting should be suppressed for
# this option (so we can determine the default later based on
# prefix)
return None
elif prefix in builtin_dir_noprefix_options[optname]:
return builtin_dir_noprefix_options[optname][prefix]
return o[2]
else:
raise RuntimeError('Tried to get the default value for an unknown builtin option \'%s\'.' % optname)
builtin_options = {
'buildtype': [UserComboOption, 'Build type to use.', ['plain', 'debug', 'debugoptimized', 'release', 'minsize'], 'debug'],
'strip': [UserBooleanOption, 'Strip targets on install.', False],
'unity': [UserComboOption, 'Unity build.', ['on', 'off', 'subprojects'], 'off'],
'prefix': [UserStringOption, 'Installation prefix.', default_prefix()],
'libdir': [UserStringOption, 'Library directory.', default_libdir()],
'libexecdir': [UserStringOption, 'Library executable directory.', default_libexecdir()],
'bindir': [UserStringOption, 'Executable directory.', 'bin'],
'sbindir': [UserStringOption, 'System executable directory.', 'sbin'],
'includedir': [UserStringOption, 'Header file directory.', 'include'],
'datadir': [UserStringOption, 'Data file directory.', 'share'],
'mandir': [UserStringOption, 'Manual page directory.', 'share/man'],
'infodir': [UserStringOption, 'Info page directory.', 'share/info'],
'localedir': [UserStringOption, 'Locale data directory.', 'share/locale'],
'sysconfdir': [UserStringOption, 'Sysconf data directory.', 'etc'],
'localstatedir': [UserStringOption, 'Localstate data directory.', 'var'],
'sharedstatedir': [UserStringOption, 'Architecture-independent data directory.', 'com'],
'werror': [UserBooleanOption, 'Treat warnings as errors.', False],
'warning_level': [UserComboOption, 'Compiler warning level to use.', ['1', '2', '3'], '1'],
'layout': [UserComboOption, 'Build directory layout.', ['mirror', 'flat'], 'mirror'],
'default_library': [UserComboOption, 'Default library type.', ['shared', 'static'], 'shared'],
'backend': [UserComboOption, 'Backend to use.', backendlist, 'ninja'],
'stdsplit': [UserBooleanOption, 'Split stdout and stderr in test logs.', True],
'errorlogs': [UserBooleanOption, "Whether to print the logs from failing tests.", True],
}
# Special prefix-dependent defaults for installation directories that reside in
# a path outside of the prefix in FHS and common usage.
builtin_dir_noprefix_options = {
'sysconfdir': {'/usr': '/etc'},
'localstatedir': {'/usr': '/var', '/usr/local': '/var/local'},
'sharedstatedir': {'/usr': '/var/lib', '/usr/local': '/var/local/lib'},
}
forbidden_target_names = {'clean': None,
'clean-ctlist': None,
'clean-gcno': None,
'clean-gcda': None,
'coverage': None,
'coverage-text': None,
'coverage-xml': None,
'coverage-html': None,
'phony': None,
'PHONY': None,
'all': None,
'test': None,
'benchmark': None,
'install': None,
'uninstall': None,
'build.ninja': None,
'scan-build': None,
'reconfigure': None,
'dist': None,
'distcheck': None,
}
|
apache-2.0
|
[
199,
3,
1898,
6029,
13,
10680,
710,
603,
397,
265,
16367,
8099,
199,
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,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
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,
5927,
12,
747,
12,
5377,
199,
646,
984,
199,
504,
32212,
492,
510,
608,
2042,
199,
504,
5055,
492,
8773,
199,
504,
1275,
278,
834,
773,
492,
603,
397,
265,
1726,
12,
2863,
515,
199,
504,
1275,
278,
834,
773,
492,
849,
63,
30789,
12,
849,
63,
773,
1628,
694,
12,
849,
63,
1861,
199,
646,
6073,
199,
199,
1023,
275,
283,
16,
14,
2322,
14,
16,
14,
2374,
17,
7,
199,
4620,
513,
275,
788,
8675,
297,
283,
3122,
297,
283,
3122,
6542,
297,
283,
3122,
7806,
297,
283,
3122,
10680,
297,
283,
8701,
418,
199,
199,
533,
2876,
2602,
26,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1369,
12,
3415,
304,
267,
1613,
11027,
826,
4533,
267,
291,
14,
354,
275,
536,
267,
291,
14,
4577,
275,
3415,
267,
291,
14,
1802,
275,
1369,
339,
327,
2670,
626,
314,
1324,
365,
282,
1686,
574,
436,
372,
314,
272,
327,
298,
8275,
2,
503,
298,
6106,
2,
1015,
14,
2104,
2893,
314,
9411,
272,
327,
945,
4293,
5452,
314,
1059,
298,
2052,
2,
436,
372,
715,
14,
272,
347,
4107,
63,
585,
8,
277,
12,
574,
304,
267,
746,
6064,
360,
17793,
12905,
945,
1021,
8103,
440,
4278,
4107,
63,
585,
2659,
199,
199,
533,
2876,
1558,
2602,
8,
1899,
2602,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1369,
12,
574,
12,
3415,
29,
403,
304,
267,
1613,
11027,
826,
721,
354,
12,
1369,
12,
3415,
9,
267,
291,
14,
409,
63,
585,
8,
585,
9,
339,
347,
4107,
8,
277,
12,
574,
304,
267,
340,
440,
1228,
8,
585,
12,
620,
304,
288,
746,
603,
397,
265,
1726,
360,
1110,
2071,
83,
2,
367,
1059,
945,
2071,
83,
2,
365,
440,
282,
1059,
3530,
450,
334,
495,
8,
585,
395,
291,
14,
354,
430,
339,
347,
663,
63,
585,
8,
277,
12,
892,
585,
304,
267,
291,
14,
3502,
8,
1222,
585,
9,
267,
291,
14,
585,
275,
892,
585,
339,
347,
4107,
63,
585,
8,
277,
12,
574,
304,
267,
291,
14,
3502,
8,
585,
9,
267,
372,
574,
199,
199,
533,
2876,
4082,
2602,
8,
1899,
2602,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1369,
12,
574,
304,
267,
1613,
11027,
826,
721,
354,
12,
1369,
12,
359,
549,
12,
756,
566,
267,
291,
14,
409,
63,
585,
8,
585,
9,
339,
347,
370,
2245,
8,
277,
12,
8377,
304,
267,
340,
1228,
8,
2127,
12,
2155,
304,
288,
372,
8377,
267,
340,
8377,
14,
2325,
342,
508,
283,
2052,
356,
288,
372,
715,
267,
340,
8377,
14,
2325,
342,
508,
283,
3910,
356,
288,
372,
756,
267,
746,
603,
397,
265,
1726,
360,
1110,
450,
83,
365,
440,
5046,
334,
2052,
503,
3055,
28823,
450,
8377,
9,
339,
347,
663,
63,
585,
8,
277,
12,
892,
585,
304,
267,
291,
14,
585,
275,
291,
14,
475,
2245,
8,
1222,
585,
9,
339,
347,
636,
2245,
721,
277,
304,
267,
372,
291,
14,
585,
339,
347,
4107,
63,
585,
8,
277,
12,
574,
304,
267,
372,
291,
14,
475,
2245,
8,
585,
9,
199,
199,
533,
2876,
2674,
2602,
8,
1899,
2602,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1369,
12,
1748,
63,
585,
12,
1390,
63,
585,
12,
574,
304,
267,
1613,
11027,
826,
721,
354,
12,
1369,
12,
359,
549,
12,
756,
566,
267,
291,
14,
827,
63,
585,
275,
1748,
63,
585,
267,
291,
14,
988,
63,
585,
275,
1390,
63,
585,
267,
291,
14,
409,
63,
585,
8,
585,
9,
339,
347,
663,
63,
585,
8,
277,
12,
892,
585,
304,
267,
340,
1228,
8,
1222,
585,
12,
620,
304,
288,
892,
585,
275,
291,
14,
475,
442,
8,
1222,
585,
9,
267,
340,
440,
1228,
8,
1222,
585,
12,
1109,
304,
288,
746,
603,
397,
265,
1726,
360,
4665,
574,
367,
3000,
945,
365,
440,
376,
3000,
2659,
267,
340,
291,
14,
827,
63,
585,
365,
440,
488,
436,
892,
585,
665,
291,
14,
827,
63,
585,
26,
288,
746,
603,
397,
265,
1726,
360,
4665,
574,
450,
68,
365,
6656,
2419,
7481,
574,
450,
68,
3530,
450,
334,
1222,
585,
12,
291,
14,
827,
63,
585,
430,
267,
340,
291,
14,
988,
63,
585,
365,
440,
488,
436,
892,
585,
690,
291,
14,
988,
63,
585,
26,
288,
746,
603,
397,
265,
1726,
360,
4665,
574,
450,
68,
365,
1655,
2419,
5696,
574,
450,
68,
3530,
450,
334,
1222,
585,
12,
291,
14,
988,
63,
585,
430,
267,
291,
14,
585,
275,
892,
585,
339,
347,
370,
442,
8,
277,
12,
574,
875,
304,
267,
862,
26,
288,
372,
1109,
8,
585,
875,
9,
267,
871,
26,
288,
746,
603,
397,
265,
1726,
360,
1110,
1059,
2071,
83,
2,
365,
440,
3818,
1224,
370,
376,
3000,
3530,
450,
574,
875,
9,
339,
347,
4107,
63,
585,
8,
277,
12,
574,
304,
267,
372,
291,
14,
475,
442,
8,
585,
9,
199,
199,
533,
2876,
12413,
2602,
8,
1899,
2602,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1369,
12,
3415,
12,
574,
304,
267,
1613,
11027,
826,
721,
354,
12,
1369,
12,
3415,
9,
267,
340,
440,
1228,
8,
277,
14,
4577,
12,
769,
304,
288,
746,
603,
397,
265,
1726,
360,
12413,
3415,
1471,
506,
376,
1625
] |
[
3,
1898,
6029,
13,
10680,
710,
603,
397,
265,
16367,
8099,
199,
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,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
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,
5927,
12,
747,
12,
5377,
199,
646,
984,
199,
504,
32212,
492,
510,
608,
2042,
199,
504,
5055,
492,
8773,
199,
504,
1275,
278,
834,
773,
492,
603,
397,
265,
1726,
12,
2863,
515,
199,
504,
1275,
278,
834,
773,
492,
849,
63,
30789,
12,
849,
63,
773,
1628,
694,
12,
849,
63,
1861,
199,
646,
6073,
199,
199,
1023,
275,
283,
16,
14,
2322,
14,
16,
14,
2374,
17,
7,
199,
4620,
513,
275,
788,
8675,
297,
283,
3122,
297,
283,
3122,
6542,
297,
283,
3122,
7806,
297,
283,
3122,
10680,
297,
283,
8701,
418,
199,
199,
533,
2876,
2602,
26,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1369,
12,
3415,
304,
267,
1613,
11027,
826,
4533,
267,
291,
14,
354,
275,
536,
267,
291,
14,
4577,
275,
3415,
267,
291,
14,
1802,
275,
1369,
339,
327,
2670,
626,
314,
1324,
365,
282,
1686,
574,
436,
372,
314,
272,
327,
298,
8275,
2,
503,
298,
6106,
2,
1015,
14,
2104,
2893,
314,
9411,
272,
327,
945,
4293,
5452,
314,
1059,
298,
2052,
2,
436,
372,
715,
14,
272,
347,
4107,
63,
585,
8,
277,
12,
574,
304,
267,
746,
6064,
360,
17793,
12905,
945,
1021,
8103,
440,
4278,
4107,
63,
585,
2659,
199,
199,
533,
2876,
1558,
2602,
8,
1899,
2602,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1369,
12,
574,
12,
3415,
29,
403,
304,
267,
1613,
11027,
826,
721,
354,
12,
1369,
12,
3415,
9,
267,
291,
14,
409,
63,
585,
8,
585,
9,
339,
347,
4107,
8,
277,
12,
574,
304,
267,
340,
440,
1228,
8,
585,
12,
620,
304,
288,
746,
603,
397,
265,
1726,
360,
1110,
2071,
83,
2,
367,
1059,
945,
2071,
83,
2,
365,
440,
282,
1059,
3530,
450,
334,
495,
8,
585,
395,
291,
14,
354,
430,
339,
347,
663,
63,
585,
8,
277,
12,
892,
585,
304,
267,
291,
14,
3502,
8,
1222,
585,
9,
267,
291,
14,
585,
275,
892,
585,
339,
347,
4107,
63,
585,
8,
277,
12,
574,
304,
267,
291,
14,
3502,
8,
585,
9,
267,
372,
574,
199,
199,
533,
2876,
4082,
2602,
8,
1899,
2602,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1369,
12,
574,
304,
267,
1613,
11027,
826,
721,
354,
12,
1369,
12,
359,
549,
12,
756,
566,
267,
291,
14,
409,
63,
585,
8,
585,
9,
339,
347,
370,
2245,
8,
277,
12,
8377,
304,
267,
340,
1228,
8,
2127,
12,
2155,
304,
288,
372,
8377,
267,
340,
8377,
14,
2325,
342,
508,
283,
2052,
356,
288,
372,
715,
267,
340,
8377,
14,
2325,
342,
508,
283,
3910,
356,
288,
372,
756,
267,
746,
603,
397,
265,
1726,
360,
1110,
450,
83,
365,
440,
5046,
334,
2052,
503,
3055,
28823,
450,
8377,
9,
339,
347,
663,
63,
585,
8,
277,
12,
892,
585,
304,
267,
291,
14,
585,
275,
291,
14,
475,
2245,
8,
1222,
585,
9,
339,
347,
636,
2245,
721,
277,
304,
267,
372,
291,
14,
585,
339,
347,
4107,
63,
585,
8,
277,
12,
574,
304,
267,
372,
291,
14,
475,
2245,
8,
585,
9,
199,
199,
533,
2876,
2674,
2602,
8,
1899,
2602,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1369,
12,
1748,
63,
585,
12,
1390,
63,
585,
12,
574,
304,
267,
1613,
11027,
826,
721,
354,
12,
1369,
12,
359,
549,
12,
756,
566,
267,
291,
14,
827,
63,
585,
275,
1748,
63,
585,
267,
291,
14,
988,
63,
585,
275,
1390,
63,
585,
267,
291,
14,
409,
63,
585,
8,
585,
9,
339,
347,
663,
63,
585,
8,
277,
12,
892,
585,
304,
267,
340,
1228,
8,
1222,
585,
12,
620,
304,
288,
892,
585,
275,
291,
14,
475,
442,
8,
1222,
585,
9,
267,
340,
440,
1228,
8,
1222,
585,
12,
1109,
304,
288,
746,
603,
397,
265,
1726,
360,
4665,
574,
367,
3000,
945,
365,
440,
376,
3000,
2659,
267,
340,
291,
14,
827,
63,
585,
365,
440,
488,
436,
892,
585,
665,
291,
14,
827,
63,
585,
26,
288,
746,
603,
397,
265,
1726,
360,
4665,
574,
450,
68,
365,
6656,
2419,
7481,
574,
450,
68,
3530,
450,
334,
1222,
585,
12,
291,
14,
827,
63,
585,
430,
267,
340,
291,
14,
988,
63,
585,
365,
440,
488,
436,
892,
585,
690,
291,
14,
988,
63,
585,
26,
288,
746,
603,
397,
265,
1726,
360,
4665,
574,
450,
68,
365,
1655,
2419,
5696,
574,
450,
68,
3530,
450,
334,
1222,
585,
12,
291,
14,
988,
63,
585,
430,
267,
291,
14,
585,
275,
892,
585,
339,
347,
370,
442,
8,
277,
12,
574,
875,
304,
267,
862,
26,
288,
372,
1109,
8,
585,
875,
9,
267,
871,
26,
288,
746,
603,
397,
265,
1726,
360,
1110,
1059,
2071,
83,
2,
365,
440,
3818,
1224,
370,
376,
3000,
3530,
450,
574,
875,
9,
339,
347,
4107,
63,
585,
8,
277,
12,
574,
304,
267,
372,
291,
14,
475,
442,
8,
585,
9,
199,
199,
533,
2876,
12413,
2602,
8,
1899,
2602,
304,
272,
347,
636,
826,
721,
277,
12,
536,
12,
1369,
12,
3415,
12,
574,
304,
267,
1613,
11027,
826,
721,
354,
12,
1369,
12,
3415,
9,
267,
340,
440,
1228,
8,
277,
14,
4577,
12,
769,
304,
288,
746,
603,
397,
265,
1726,
360,
12413,
3415,
1471,
506,
376,
1625,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bright-sparks/chromium-spacewalk
|
webkit/tools/layout_tests/PRESUBMIT.py
|
87
|
2098
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""test_expectations.txt presubmit script.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts for
details on the presubmit API built into gcl.
"""
TEST_EXPECTATIONS_FILENAMES = ['test_expectations.txt', 'TestExpectations']
def LintTestFiles(input_api, output_api):
current_dir = str(input_api.PresubmitLocalPath())
# Set 'webkit/tools/layout_tests' in include path.
python_paths = [
current_dir,
input_api.os_path.join(current_dir, '..', '..', '..', 'tools', 'python')
]
env = input_api.environ.copy()
if env.get('PYTHONPATH'):
python_paths.append(env['PYTHONPATH'])
env['PYTHONPATH'] = input_api.os_path.pathsep.join(python_paths)
args = [
input_api.python_executable,
input_api.os_path.join(current_dir, 'run_webkit_tests.py'),
'--lint-test-files'
]
subproc = input_api.subprocess.Popen(
args,
cwd=current_dir,
env=env,
stdin=input_api.subprocess.PIPE,
stdout=input_api.subprocess.PIPE,
stderr=input_api.subprocess.STDOUT)
stdout_data = subproc.communicate()[0]
# TODO(ukai): consolidate run_webkit_tests --lint-test-files reports.
is_error = lambda line: (input_api.re.match('^Line:', line) or
input_api.re.search('ERROR Line:', line))
error = filter(is_error, stdout_data.splitlines())
if error:
return [output_api.PresubmitError('Lint error\n%s' % '\n'.join(error),
long_text=stdout_data)]
return []
def LintTestExpectations(input_api, output_api):
for path in input_api.LocalPaths():
if input_api.os_path.basename(path) in TEST_EXPECTATIONS_FILENAMES:
return LintTestFiles(input_api, output_api)
return []
def CheckChangeOnUpload(input_api, output_api):
return LintTestExpectations(input_api, output_api)
def CheckChangeOnCommit(input_api, output_api):
return LintTestExpectations(input_api, output_api)
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
396,
63,
15752,
14,
2424,
23895,
2884,
14,
199,
199,
9295,
1455,
921,
2374,
14,
13211,
14,
1308,
15,
23826,
15,
1917,
13,
14543,
15,
27834,
2537,
15,
80,
15527,
13,
6429,
367,
199,
5087,
641,
314,
23895,
3261,
6137,
1901,
486,
429,
14,
199,
624,
199,
199,
2864,
63,
16957,
12969,
63,
5110,
742,
31819,
275,
788,
396,
63,
15752,
14,
2424,
297,
283,
774,
31323,
418,
199,
199,
318,
491,
442,
774,
5535,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
1453,
63,
694,
275,
620,
8,
1210,
63,
1246,
14,
30607,
26453,
1012,
523,
327,
2494,
283,
12554,
15,
2537,
15,
4209,
63,
2219,
7,
315,
2387,
931,
14,
523,
2366,
63,
3771,
275,
359,
489,
1453,
63,
694,
12,
489,
1324,
63,
1246,
14,
736,
63,
515,
14,
904,
8,
1818,
63,
694,
12,
19155,
19155,
19155,
283,
2537,
297,
283,
1548,
358,
523,
1622,
523,
2589,
275,
1324,
63,
1246,
14,
2314,
14,
1574,
342,
523,
340,
2589,
14,
362,
360,
29266,
735,
272,
2366,
63,
3771,
14,
740,
8,
1813,
459,
29266,
1105,
523,
2589,
459,
29266,
418,
275,
1324,
63,
1246,
14,
736,
63,
515,
14,
17843,
14,
904,
8,
1548,
63,
3771,
9,
523,
1249,
275,
359,
489,
1324,
63,
1246,
14,
1548,
63,
5904,
12,
489,
1324,
63,
1246,
14,
736,
63,
515,
14,
904,
8,
1818,
63,
694,
12,
283,
1065,
63,
12554,
63,
2219,
14,
647,
659,
489,
2850,
3854,
13,
396,
13,
1725,
7,
523,
1622,
523,
1007,
4687,
275,
1324,
63,
1246,
14,
5781,
14,
7942,
8,
489,
1249,
12,
489,
8288,
29,
1818,
63,
694,
12,
489,
2589,
29,
1813,
12,
489,
9009,
29,
1210,
63,
1246,
14,
5781,
14,
6089,
12,
489,
3839,
29,
1210,
63,
1246,
14,
5781,
14,
6089,
12,
489,
4635,
29,
1210,
63,
1246,
14,
5781,
14,
13850,
9,
523,
3839,
63,
576,
275,
1007,
4687,
14,
10664,
3430,
16,
61,
523,
327,
3254,
8,
3210,
5789,
304,
406,
28335,
602,
1255,
63,
12554,
63,
2219,
1553,
3854,
13,
396,
13,
1725,
13924,
14,
523,
365,
63,
705,
275,
2400,
1004,
26,
334,
1210,
63,
1246,
14,
264,
14,
1431,
9097,
3049,
6536,
1004,
9,
503,
2574,
1324,
63,
1246,
14,
264,
14,
1733,
360,
3170,
7030,
6536,
1004,
430,
523,
1125,
275,
2457,
8,
374,
63,
705,
12,
3839,
63,
576,
14,
7644,
1012,
523,
340,
1125,
26,
272,
372,
359,
1199,
63,
1246,
14,
30607,
547,
360,
44,
442,
1125,
60,
78,
5,
83,
7,
450,
1557,
78,
1370,
904,
8,
705,
395,
4228,
1846,
63,
505,
29,
2703,
63,
576,
1874,
523,
372,
942,
199,
199,
318,
491,
442,
774,
31323,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
367,
931,
315,
1324,
63,
1246,
14,
5339,
11804,
837,
272,
340,
1324,
63,
1246,
14,
736,
63,
515,
14,
4846,
8,
515,
9,
315,
7393,
63,
16957,
12969,
63,
5110,
742,
31819,
26,
489,
372,
491,
442,
774,
5535,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
9,
523,
372,
942,
421,
199,
318,
2670,
4001,
3314,
10301,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
372,
491,
442,
774,
31323,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
9,
199,
199,
318,
2670,
4001,
3314,
11421,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
372,
491,
442,
774,
31323,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
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
] |
[
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
396,
63,
15752,
14,
2424,
23895,
2884,
14,
199,
199,
9295,
1455,
921,
2374,
14,
13211,
14,
1308,
15,
23826,
15,
1917,
13,
14543,
15,
27834,
2537,
15,
80,
15527,
13,
6429,
367,
199,
5087,
641,
314,
23895,
3261,
6137,
1901,
486,
429,
14,
199,
624,
199,
199,
2864,
63,
16957,
12969,
63,
5110,
742,
31819,
275,
788,
396,
63,
15752,
14,
2424,
297,
283,
774,
31323,
418,
199,
199,
318,
491,
442,
774,
5535,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
1453,
63,
694,
275,
620,
8,
1210,
63,
1246,
14,
30607,
26453,
1012,
523,
327,
2494,
283,
12554,
15,
2537,
15,
4209,
63,
2219,
7,
315,
2387,
931,
14,
523,
2366,
63,
3771,
275,
359,
489,
1453,
63,
694,
12,
489,
1324,
63,
1246,
14,
736,
63,
515,
14,
904,
8,
1818,
63,
694,
12,
19155,
19155,
19155,
283,
2537,
297,
283,
1548,
358,
523,
1622,
523,
2589,
275,
1324,
63,
1246,
14,
2314,
14,
1574,
342,
523,
340,
2589,
14,
362,
360,
29266,
735,
272,
2366,
63,
3771,
14,
740,
8,
1813,
459,
29266,
1105,
523,
2589,
459,
29266,
418,
275,
1324,
63,
1246,
14,
736,
63,
515,
14,
17843,
14,
904,
8,
1548,
63,
3771,
9,
523,
1249,
275,
359,
489,
1324,
63,
1246,
14,
1548,
63,
5904,
12,
489,
1324,
63,
1246,
14,
736,
63,
515,
14,
904,
8,
1818,
63,
694,
12,
283,
1065,
63,
12554,
63,
2219,
14,
647,
659,
489,
2850,
3854,
13,
396,
13,
1725,
7,
523,
1622,
523,
1007,
4687,
275,
1324,
63,
1246,
14,
5781,
14,
7942,
8,
489,
1249,
12,
489,
8288,
29,
1818,
63,
694,
12,
489,
2589,
29,
1813,
12,
489,
9009,
29,
1210,
63,
1246,
14,
5781,
14,
6089,
12,
489,
3839,
29,
1210,
63,
1246,
14,
5781,
14,
6089,
12,
489,
4635,
29,
1210,
63,
1246,
14,
5781,
14,
13850,
9,
523,
3839,
63,
576,
275,
1007,
4687,
14,
10664,
3430,
16,
61,
523,
327,
3254,
8,
3210,
5789,
304,
406,
28335,
602,
1255,
63,
12554,
63,
2219,
1553,
3854,
13,
396,
13,
1725,
13924,
14,
523,
365,
63,
705,
275,
2400,
1004,
26,
334,
1210,
63,
1246,
14,
264,
14,
1431,
9097,
3049,
6536,
1004,
9,
503,
2574,
1324,
63,
1246,
14,
264,
14,
1733,
360,
3170,
7030,
6536,
1004,
430,
523,
1125,
275,
2457,
8,
374,
63,
705,
12,
3839,
63,
576,
14,
7644,
1012,
523,
340,
1125,
26,
272,
372,
359,
1199,
63,
1246,
14,
30607,
547,
360,
44,
442,
1125,
60,
78,
5,
83,
7,
450,
1557,
78,
1370,
904,
8,
705,
395,
4228,
1846,
63,
505,
29,
2703,
63,
576,
1874,
523,
372,
942,
199,
199,
318,
491,
442,
774,
31323,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
367,
931,
315,
1324,
63,
1246,
14,
5339,
11804,
837,
272,
340,
1324,
63,
1246,
14,
736,
63,
515,
14,
4846,
8,
515,
9,
315,
7393,
63,
16957,
12969,
63,
5110,
742,
31819,
26,
489,
372,
491,
442,
774,
5535,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
9,
523,
372,
942,
421,
199,
318,
2670,
4001,
3314,
10301,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
372,
491,
442,
774,
31323,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
9,
199,
199,
318,
2670,
4001,
3314,
11421,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
304,
523,
372,
491,
442,
774,
31323,
8,
1210,
63,
1246,
12,
1072,
63,
1246,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bobeirasa/virtualenvs
|
pygeckozabbix/lib/python2.7/site-packages/requests/packages/charade/__init__.py
|
49
|
2286
|
######################## BEGIN LICENSE BLOCK ########################
# 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 #########################
__version__ = "1.0.3"
from sys import version_info
def detect(aBuf):
if ((version_info < (3, 0) and isinstance(aBuf, unicode)) or
(version_info >= (3, 0) and not isinstance(aBuf, bytes))):
raise ValueError('Expected a bytes object, not a unicode object')
from . import universaldetector
u = universaldetector.UniversalDetector()
u.reset()
u.feed(aBuf)
u.close()
return u.result
def _description_of(path):
"""Return a string describing the probable encoding of a file."""
from charade.universaldetector import UniversalDetector
u = UniversalDetector()
for line in open(path, 'rb'):
u.feed(line)
u.close()
result = u.result
if result['encoding']:
return '%s: %s with confidence %s' % (path,
result['encoding'],
result['confidence'])
else:
return '%s: no result' % path
def charade_cli():
"""
Script which takes one or more file paths and reports on their detected
encodings
Example::
% chardetect.py somefile someotherfile
somefile: windows-1252 with confidence 0.5
someotherfile: ascii with confidence 1.0
"""
from sys import argv
for path in argv[1:]:
print(_description_of(path))
|
mit
|
[
6565,
16427,
5113,
8068,
11945,
202,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
202,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
202,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
202,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
202,
199,
3,
202,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
202,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
202,
199,
3,
202,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
202,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
202,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
202,
199,
3,
11315,
13,
10067,
221,
8217,
202,
199,
19054,
7729,
5113,
8068,
21186,
2999,
199,
363,
1023,
363,
275,
298,
17,
14,
16,
14,
19,
2,
202,
199,
504,
984,
492,
1015,
63,
815,
8065,
199,
318,
9696,
8,
22353,
304,
1128,
340,
3666,
1023,
63,
815,
665,
334,
19,
12,
378,
9,
436,
1228,
8,
22353,
12,
2649,
430,
503,
1675,
334,
1023,
63,
815,
2356,
334,
19,
12,
378,
9,
436,
440,
1228,
8,
22353,
12,
2783,
15206,
1039,
746,
1722,
360,
6964,
282,
2783,
909,
12,
440,
282,
2649,
909,
358,
2958,
687,
1275,
492,
17508,
19401,
1128,
399,
275,
17508,
19401,
14,
1358,
10959,
24402,
342,
1128,
399,
14,
3958,
342,
1128,
399,
14,
3871,
8,
22353,
9,
1128,
399,
14,
1600,
342,
1128,
372,
399,
14,
1099,
2999,
199,
318,
485,
1802,
63,
1618,
8,
515,
304,
1128,
408,
1767,
282,
1059,
13660,
314,
5128,
461,
2644,
402,
282,
570,
1041,
1128,
687,
1495,
9587,
14,
24866,
19401,
492,
29347,
24402,
2958,
399,
275,
29347,
24402,
342,
1128,
367,
1004,
315,
1551,
8,
515,
12,
283,
4848,
735,
1039,
399,
14,
3871,
8,
604,
9,
1128,
399,
14,
1600,
342,
1128,
754,
275,
399,
14,
1099,
1128,
340,
754,
459,
2991,
2565,
1039,
372,
1543,
83,
26,
450,
83,
543,
15197,
450,
83,
7,
450,
334,
515,
12,
202,
6343,
754,
459,
2991,
995,
202,
6343,
754,
459,
13969,
1105,
1128,
587,
26,
1039,
372,
1543,
83,
26,
949,
754,
7,
450,
931,
8065,
199,
318,
1495,
9587,
63,
2764,
837,
1128,
408,
1128,
14914,
1314,
6181,
1373,
503,
1655,
570,
3792,
436,
13924,
641,
3932,
10501,
1128,
14134,
2958,
5679,
447,
4341,
450,
1495,
13552,
14,
647,
2005,
493,
2005,
1848,
493,
1039,
2005,
493,
26,
10061,
13,
19364,
543,
15197,
378,
14,
21,
1039,
2005,
1848,
493,
26,
13294,
543,
15197,
413,
14,
16,
2958,
408,
1128,
687,
984,
492,
9238,
1128,
367,
931,
315,
9238,
59,
17,
10688,
1039,
870,
1547,
1802,
63,
1618,
8,
515,
430,
8740,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
202,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
202,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
202,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
202,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
202,
199,
3,
202,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
202,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
202,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
202,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
202,
199,
3,
202,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
202,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
202,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
202,
199,
3,
11315,
13,
10067,
221,
8217,
202,
199,
19054,
7729,
5113,
8068,
21186,
2999,
199,
363,
1023,
363,
275,
298,
17,
14,
16,
14,
19,
2,
202,
199,
504,
984,
492,
1015,
63,
815,
8065,
199,
318,
9696,
8,
22353,
304,
1128,
340,
3666,
1023,
63,
815,
665,
334,
19,
12,
378,
9,
436,
1228,
8,
22353,
12,
2649,
430,
503,
1675,
334,
1023,
63,
815,
2356,
334,
19,
12,
378,
9,
436,
440,
1228,
8,
22353,
12,
2783,
15206,
1039,
746,
1722,
360,
6964,
282,
2783,
909,
12,
440,
282,
2649,
909,
358,
2958,
687,
1275,
492,
17508,
19401,
1128,
399,
275,
17508,
19401,
14,
1358,
10959,
24402,
342,
1128,
399,
14,
3958,
342,
1128,
399,
14,
3871,
8,
22353,
9,
1128,
399,
14,
1600,
342,
1128,
372,
399,
14,
1099,
2999,
199,
318,
485,
1802,
63,
1618,
8,
515,
304,
1128,
408,
1767,
282,
1059,
13660,
314,
5128,
461,
2644,
402,
282,
570,
1041,
1128,
687,
1495,
9587,
14,
24866,
19401,
492,
29347,
24402,
2958,
399,
275,
29347,
24402,
342,
1128,
367,
1004,
315,
1551,
8,
515,
12,
283,
4848,
735,
1039,
399,
14,
3871,
8,
604,
9,
1128,
399,
14,
1600,
342,
1128,
754,
275,
399,
14,
1099,
1128,
340,
754,
459,
2991,
2565,
1039,
372,
1543,
83,
26,
450,
83,
543,
15197,
450,
83,
7,
450,
334,
515,
12,
202,
6343,
754,
459,
2991,
995,
202,
6343,
754,
459,
13969,
1105,
1128,
587,
26,
1039,
372,
1543,
83,
26,
949,
754,
7,
450,
931,
8065,
199,
318,
1495,
9587,
63,
2764,
837,
1128,
408,
1128,
14914,
1314,
6181,
1373,
503,
1655,
570,
3792,
436,
13924,
641,
3932,
10501,
1128,
14134,
2958,
5679,
447,
4341,
450,
1495,
13552,
14,
647,
2005,
493,
2005,
1848,
493,
1039,
2005,
493,
26,
10061,
13,
19364,
543,
15197,
378,
14,
21,
1039,
2005,
1848,
493,
26,
13294,
543,
15197,
413,
14,
16,
2958,
408,
1128,
687,
984,
492,
9238,
1128,
367,
931,
315,
9238,
59,
17,
10688,
1039,
870,
1547,
1802,
63,
1618,
8,
515,
430,
8740,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0
] |
espadrine/opera
|
chromium/src/third_party/WebKit/Tools/Scripts/webkitpy/common/read_checksum_from_png.py
|
207
|
1877
|
# Copyright (c) 2011 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.
def read_checksum(filehandle):
# We expect the comment to be at the beginning of the file.
data = filehandle.read(2048)
comment_key = 'tEXtchecksum\x00'
comment_pos = data.find(comment_key)
if comment_pos == -1:
return
checksum_pos = comment_pos + len(comment_key)
return data[checksum_pos:checksum_pos + 32]
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
7760,
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,
421,
199,
318,
1586,
63,
8928,
8,
493,
2479,
304,
272,
327,
2136,
4282,
314,
3721,
370,
506,
737,
314,
9608,
402,
314,
570,
14,
272,
666,
275,
570,
2479,
14,
739,
8,
18343,
9,
272,
3721,
63,
498,
275,
283,
84,
1438,
84,
8928,
60,
88,
383,
7,
272,
3721,
63,
1712,
275,
666,
14,
1623,
8,
3349,
63,
498,
9,
272,
340,
3721,
63,
1712,
508,
446,
17,
26,
267,
372,
339,
9040,
63,
1712,
275,
3721,
63,
1712,
435,
822,
8,
3349,
63,
498,
9,
272,
372,
666,
59,
8928,
63,
1712,
26,
8928,
63,
1712,
435,
4337,
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
] |
[
1898,
334,
67,
9,
7760,
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,
421,
199,
318,
1586,
63,
8928,
8,
493,
2479,
304,
272,
327,
2136,
4282,
314,
3721,
370,
506,
737,
314,
9608,
402,
314,
570,
14,
272,
666,
275,
570,
2479,
14,
739,
8,
18343,
9,
272,
3721,
63,
498,
275,
283,
84,
1438,
84,
8928,
60,
88,
383,
7,
272,
3721,
63,
1712,
275,
666,
14,
1623,
8,
3349,
63,
498,
9,
272,
340,
3721,
63,
1712,
508,
446,
17,
26,
267,
372,
339,
9040,
63,
1712,
275,
3721,
63,
1712,
435,
822,
8,
3349,
63,
498,
9,
272,
372,
666,
59,
8928,
63,
1712,
26,
8928,
63,
1712,
435,
4337,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
koddas/python-backend
|
src/test.py
|
1
|
1313
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from unicorns import storage
from unicorns.Unicorn import Unicorn
storage.setup()
unicorns = storage.fetch_unicorns()
for unicorn in unicorns:
print(str(unicorn.id) + ': ' + unicorn.name)
print("")
unicorn = storage.fetch_unicorn(3)
print(str(unicorn.id) + ': ' + unicorn.name)
print("Inrapporterad av: " + unicorn.reported_by)
print("")
unicorn.reported_by = 'Batman'
storage.update_unicorn(unicorn)
unicorn = storage.fetch_unicorn(3)
print(str(unicorn.id) + ': ' + unicorn.name)
print("Inrapporterad av: " + unicorn.reported_by)
print("")
unicorn = Unicorn()
unicorn.name = 'Konstig enhörning'
unicorn.description = 'Det här är ingen vacker enhörning'
unicorn.reported_by = 'Johan'
unicorn.spotted_where.name = 'Niagara'
unicorn.spotted_where.lat = 55.609183
unicorn.spotted_where.lon = 12.994875
unicorn.spotted_when = '2015-09-22 20:14:00'
unicorn.image = 'https://pbs.twimg.com/profile_images/512349801929650177/_hfDmaho.jpeg'
storage.add_unicorn(unicorn)
unicorn = storage.fetch_unicorn(5)
print(str(unicorn.id) + ': ' + unicorn.name)
print("")
unicorns = storage.fetch_unicorns()
print("Antal enhörningar: " + str(len(unicorns)))
storage.delete_unicorn(5)
unicorns = storage.fetch_unicorns()
print("Antal enhörningar: " + str(len(unicorns)))
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
625,
530,
269,
561,
492,
4887,
199,
504,
625,
530,
269,
561,
14,
1358,
530,
6161,
492,
1910,
530,
6161,
421,
199,
3494,
14,
2758,
342,
199,
199,
5209,
269,
561,
275,
4887,
14,
3535,
63,
5209,
269,
561,
342,
199,
509,
625,
530,
6161,
315,
625,
530,
269,
561,
26,
272,
870,
8,
495,
8,
29067,
14,
344,
9,
435,
7596,
283,
435,
625,
530,
6161,
14,
354,
9,
199,
1361,
10804,
199,
199,
29067,
275,
4887,
14,
3535,
63,
29067,
8,
19,
9,
199,
1361,
8,
495,
8,
29067,
14,
344,
9,
435,
7596,
283,
435,
625,
530,
6161,
14,
354,
9,
199,
1361,
480,
607,
345,
802,
269,
2967,
68,
2289,
26,
298,
435,
625,
530,
6161,
14,
1155,
1376,
63,
991,
9,
199,
1361,
10804,
199,
199,
29067,
14,
1155,
1376,
63,
991,
275,
283,
34,
292,
1237,
7,
199,
3494,
14,
873,
63,
29067,
8,
29067,
9,
199,
29067,
275,
4887,
14,
3535,
63,
29067,
8,
19,
9,
199,
1361,
8,
495,
8,
29067,
14,
344,
9,
435,
7596,
283,
435,
625,
530,
6161,
14,
354,
9,
199,
1361,
480,
607,
345,
802,
269,
2967,
68,
2289,
26,
298,
435,
625,
530,
6161,
14,
1155,
1376,
63,
991,
9,
199,
1361,
10804,
199,
199,
29067,
275,
1910,
530,
6161,
342,
199,
29067,
14,
354,
275,
283,
43,
265,
270,
528,
655,
72,
14614,
82,
1835,
7,
199,
29067,
14,
1802,
275,
283,
21097,
394,
13733,
82,
13333,
98,
82,
315,
2268,
373,
564,
281,
655,
72,
14614,
82,
1835,
7,
199,
29067,
14,
1155,
1376,
63,
991,
275,
283,
5691,
19262,
7,
199,
29067,
14,
15185,
471,
63,
4509,
14,
354,
275,
283,
20959,
643,
17956,
7,
199,
29067,
14,
15185,
471,
63,
4509,
14,
4452,
275,
12766,
14,
14520,
12363,
199,
29067,
14,
15185,
471,
63,
4509,
14,
5298,
275,
3144,
14,
14966,
13357,
199,
29067,
14,
15185,
471,
63,
6526,
275,
283,
7806,
13,
1643,
13,
1081,
3388,
26,
1079,
26,
383,
7,
199,
29067,
14,
1569,
275,
283,
2859,
921,
80,
1533,
14,
8122,
4060,
14,
957,
15,
2913,
63,
4782,
15,
21,
4321,
2905,
12512,
26163,
614,
1138,
15607,
9188,
36,
391,
526,
14,
14230,
7,
199,
3494,
14,
525,
63,
29067,
8,
29067,
9,
199,
29067,
275,
4887,
14,
3535,
63,
29067,
8,
21,
9,
199,
1361,
8,
495,
8,
29067,
14,
344,
9,
435,
7596,
283,
435,
625,
530,
6161,
14,
354,
9,
199,
1361,
10804,
199,
199,
5209,
269,
561,
275,
4887,
14,
3535,
63,
5209,
269,
561,
342,
199,
1361,
480,
31935,
279,
655,
72,
14614,
82,
1835,
285,
26,
298,
435,
620,
8,
552,
8,
5209,
269,
561,
1724,
199,
3494,
14,
1807,
63,
29067,
8,
21,
9,
199,
5209,
269,
561,
275,
4887,
14,
3535,
63,
5209,
269,
561,
342,
199,
1361,
480,
31935,
279,
655,
72,
14614,
82,
1835,
285,
26,
298,
435,
620,
8,
552,
8,
5209,
269,
561,
1724,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
625,
530,
269,
561,
492,
4887,
199,
504,
625,
530,
269,
561,
14,
1358,
530,
6161,
492,
1910,
530,
6161,
421,
199,
3494,
14,
2758,
342,
199,
199,
5209,
269,
561,
275,
4887,
14,
3535,
63,
5209,
269,
561,
342,
199,
509,
625,
530,
6161,
315,
625,
530,
269,
561,
26,
272,
870,
8,
495,
8,
29067,
14,
344,
9,
435,
7596,
283,
435,
625,
530,
6161,
14,
354,
9,
199,
1361,
10804,
199,
199,
29067,
275,
4887,
14,
3535,
63,
29067,
8,
19,
9,
199,
1361,
8,
495,
8,
29067,
14,
344,
9,
435,
7596,
283,
435,
625,
530,
6161,
14,
354,
9,
199,
1361,
480,
607,
345,
802,
269,
2967,
68,
2289,
26,
298,
435,
625,
530,
6161,
14,
1155,
1376,
63,
991,
9,
199,
1361,
10804,
199,
199,
29067,
14,
1155,
1376,
63,
991,
275,
283,
34,
292,
1237,
7,
199,
3494,
14,
873,
63,
29067,
8,
29067,
9,
199,
29067,
275,
4887,
14,
3535,
63,
29067,
8,
19,
9,
199,
1361,
8,
495,
8,
29067,
14,
344,
9,
435,
7596,
283,
435,
625,
530,
6161,
14,
354,
9,
199,
1361,
480,
607,
345,
802,
269,
2967,
68,
2289,
26,
298,
435,
625,
530,
6161,
14,
1155,
1376,
63,
991,
9,
199,
1361,
10804,
199,
199,
29067,
275,
1910,
530,
6161,
342,
199,
29067,
14,
354,
275,
283,
43,
265,
270,
528,
655,
72,
14614,
82,
1835,
7,
199,
29067,
14,
1802,
275,
283,
21097,
394,
13733,
82,
13333,
98,
82,
315,
2268,
373,
564,
281,
655,
72,
14614,
82,
1835,
7,
199,
29067,
14,
1155,
1376,
63,
991,
275,
283,
5691,
19262,
7,
199,
29067,
14,
15185,
471,
63,
4509,
14,
354,
275,
283,
20959,
643,
17956,
7,
199,
29067,
14,
15185,
471,
63,
4509,
14,
4452,
275,
12766,
14,
14520,
12363,
199,
29067,
14,
15185,
471,
63,
4509,
14,
5298,
275,
3144,
14,
14966,
13357,
199,
29067,
14,
15185,
471,
63,
6526,
275,
283,
7806,
13,
1643,
13,
1081,
3388,
26,
1079,
26,
383,
7,
199,
29067,
14,
1569,
275,
283,
2859,
921,
80,
1533,
14,
8122,
4060,
14,
957,
15,
2913,
63,
4782,
15,
21,
4321,
2905,
12512,
26163,
614,
1138,
15607,
9188,
36,
391,
526,
14,
14230,
7,
199,
3494,
14,
525,
63,
29067,
8,
29067,
9,
199,
29067,
275,
4887,
14,
3535,
63,
29067,
8,
21,
9,
199,
1361,
8,
495,
8,
29067,
14,
344,
9,
435,
7596,
283,
435,
625,
530,
6161,
14,
354,
9,
199,
1361,
10804,
199,
199,
5209,
269,
561,
275,
4887,
14,
3535,
63,
5209,
269,
561,
342,
199,
1361,
480,
31935,
279,
655,
72,
14614,
82,
1835,
285,
26,
298,
435,
620,
8,
552,
8,
5209,
269,
561,
1724,
199,
3494,
14,
1807,
63,
29067,
8,
21,
9,
199,
5209,
269,
561,
275,
4887,
14,
3535,
63,
5209,
269,
561,
342,
199,
1361,
480,
31935,
279,
655,
72,
14614,
82,
1835,
285,
26,
298,
435,
620,
8,
552,
8,
5209,
269,
561,
1724,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
huggingface/pytorch-transformers
|
src/transformers/utils/versions.py
|
1
|
4611
|
# Copyright 2020 The HuggingFace Team. 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 working with package versions
"""
import operator
import re
import sys
from typing import Optional
from packaging import version
# The package importlib_metadata is in a different place, depending on the python version.
if sys.version_info < (3, 8):
import importlib_metadata
else:
import importlib.metadata as importlib_metadata
ops = {
"<": operator.lt,
"<=": operator.le,
"==": operator.eq,
"!=": operator.ne,
">=": operator.ge,
">": operator.gt,
}
def _compare_versions(op, got_ver, want_ver, requirement, pkg, hint):
if got_ver is None:
raise ValueError("got_ver is None")
if want_ver is None:
raise ValueError("want_ver is None")
if not ops[op](version.parse(got_ver), version.parse(want_ver)):
raise ImportError(
f"{requirement} is required for a normal functioning of this module, but found {pkg}=={got_ver}.{hint}"
)
def require_version(requirement: str, hint: Optional[str] = None) -> None:
"""
Perform a runtime check of the dependency versions, using the exact same syntax used by pip.
The installed module version comes from the `site-packages` dir via `importlib_metadata`.
Args:
requirement (:obj:`str`): pip style definition, e.g., "tokenizers==0.9.4", "tqdm>=4.27", "numpy"
hint (:obj:`str`, `optional`): what suggestion to print in case of requirements not being met
Example::
require_version("pandas>1.1.2")
require_version("numpy>1.18.5", "this is important to have for whatever reason")
"""
hint = f"\n{hint}" if hint is not None else ""
# non-versioned check
if re.match(r"^[\w_\-\d]+$", requirement):
pkg, op, want_ver = requirement, None, None
else:
match = re.findall(r"^([^!=<>\s]+)([\s!=<>]{1,2}.+)", requirement)
if not match:
raise ValueError(
f"requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but got {requirement}"
)
pkg, want_full = match[0]
want_range = want_full.split(",") # there could be multiple requirements
wanted = {}
for w in want_range:
match = re.findall(r"^([\s!=<>]{1,2})(.+)", w)
if not match:
raise ValueError(
f"requirement needs to be in the pip package format, .e.g., package_a==1.23, or package_b>=1.23, but got {requirement}"
)
op, want_ver = match[0]
wanted[op] = want_ver
if op not in ops:
raise ValueError(f"{requirement}: need one of {list(ops.keys())}, but got {op}")
# special case
if pkg == "python":
got_ver = ".".join([str(x) for x in sys.version_info[:3]])
for op, want_ver in wanted.items():
_compare_versions(op, got_ver, want_ver, requirement, pkg, hint)
return
# check if any version is installed
try:
got_ver = importlib_metadata.version(pkg)
except importlib_metadata.PackageNotFoundError:
raise importlib_metadata.PackageNotFoundError(
f"The '{requirement}' distribution was not found and is required by this application. {hint}"
)
# check that the right version is installed if version number or a range was provided
if want_ver is not None:
for op, want_ver in wanted.items():
_compare_versions(op, got_ver, want_ver, requirement, pkg, hint)
def require_version_core(requirement):
"""require_version wrapper which emits a core-specific hint on failure"""
hint = "Try: pip install transformers -U or pip install -e '.[dev]' if you're working with git master"
return require_version(requirement, hint)
def require_version_examples(requirement):
"""require_version wrapper which emits examples-specific hint on failure"""
hint = "Try: pip install -r examples/requirements.txt"
return require_version(requirement, hint)
|
apache-2.0
|
[
3,
1898,
25455,
710,
869,
1518,
1540,
13414,
11682,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
22905,
367,
6449,
543,
2559,
5459,
199,
624,
199,
199,
646,
4182,
199,
646,
295,
199,
646,
984,
199,
504,
14090,
492,
4879,
199,
199,
504,
27369,
492,
1015,
421,
199,
3,
710,
2559,
14802,
63,
2343,
365,
315,
282,
3365,
4192,
12,
10298,
641,
314,
2366,
1015,
14,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
1695,
304,
272,
492,
14802,
63,
2343,
199,
2836,
26,
272,
492,
14802,
14,
2343,
465,
14802,
63,
2343,
421,
199,
1483,
275,
469,
272,
3886,
582,
4182,
14,
4116,
12,
272,
3886,
29,
582,
4182,
14,
274,
12,
272,
298,
389,
582,
4182,
14,
4077,
12,
272,
298,
1111,
582,
4182,
14,
685,
12,
272,
298,
8119,
582,
4182,
14,
303,
12,
272,
25366,
4182,
14,
3308,
12,
199,
93,
421,
199,
318,
485,
5785,
63,
6234,
8,
411,
12,
4788,
63,
422,
12,
2934,
63,
422,
12,
10685,
12,
5496,
12,
8328,
304,
272,
340,
4788,
63,
422,
365,
488,
26,
267,
746,
1722,
480,
7808,
63,
422,
365,
488,
531,
272,
340,
2934,
63,
422,
365,
488,
26,
267,
746,
1722,
480,
7051,
63,
422,
365,
488,
531,
272,
340,
440,
4156,
59,
411,
8738,
1023,
14,
1122,
8,
7808,
63,
422,
395,
1015,
14,
1122,
8,
7051,
63,
422,
2298,
267,
746,
3545,
8,
288,
289,
14381,
12434,
93,
365,
1415,
367,
282,
3293,
805,
316,
402,
642,
859,
12,
1325,
1911,
469,
4600,
93,
389,
91,
7808,
63,
422,
26944,
6479,
7063,
267,
776,
421,
199,
318,
4409,
63,
1023,
8,
12434,
26,
620,
12,
8328,
26,
4879,
59,
495,
61,
275,
488,
9,
1035,
488,
26,
272,
408,
272,
14795,
282,
8836,
1104,
402,
314,
5936,
5459,
12,
1808,
314,
5835,
2011,
6302,
1202,
701,
7305,
14,
339,
710,
4903,
859,
1015,
12477,
687,
314,
658,
2124,
13,
5154,
64,
2935,
4799,
658,
25893,
63,
2343,
2313,
339,
3033,
26,
267,
10685,
18479,
1113,
1705,
495,
25452,
7305,
3449,
5492,
12,
325,
14,
71,
2020,
221,
298,
1418,
6315,
389,
16,
14,
25,
14,
20,
401,
298,
84,
81,
6428,
8119,
20,
14,
1465,
401,
298,
4714,
2,
267,
8328,
18479,
1113,
1705,
495,
3559,
658,
4144,
25452,
4052,
18453,
1636,
370,
870,
315,
1930,
402,
9760,
440,
3769,
7647,
339,
5679,
447,
10817,
4409,
63,
1023,
480,
15718,
30,
17,
14,
17,
14,
18,
531,
2126,
4409,
63,
1023,
480,
4714,
30,
17,
14,
1085,
14,
21,
401,
298,
3749,
365,
11012,
370,
1172,
367,
15685,
4499,
531,
339,
408,
339,
8328,
275,
289,
3212,
78,
91,
6479,
7063,
340,
8328,
365,
440,
488,
587,
3087,
339,
327,
2222,
13,
24155,
1104,
272,
340,
295,
14,
1431,
8,
82,
16136,
7023,
87,
18005,
2696,
68,
2807,
11918,
10685,
304,
267,
5496,
12,
1687,
12,
2934,
63,
422,
275,
10685,
12,
488,
12,
488,
272,
587,
26,
267,
1336,
275,
295,
14,
6452,
8,
82,
16136,
7059,
1111,
28,
3072,
83,
11896,
16510,
83,
1111,
16137,
8194,
17,
12,
18,
5565,
11,
4186,
10685,
9,
267,
340,
440,
1336,
26,
288,
746,
1722,
8,
355,
289,
2,
12434,
4839,
370,
506,
315,
314,
7305,
2559,
1475,
12,
1275,
69,
14,
71,
2020,
2559,
63,
65,
389,
17,
14,
1789,
12,
503,
2559,
63,
66,
8119,
17,
14,
1789,
12,
1325,
4788,
469,
12434,
7063,
288,
776,
267,
5496,
12,
2934,
63,
2861,
275,
1336,
59,
16,
61,
267,
2934,
63,
1842,
275,
2934,
63,
2861,
14,
1294,
20324,
221,
327,
2337,
4293,
506,
3663,
9760,
267,
13632,
275,
1052,
267,
367,
336,
315,
2934,
63,
1842,
26,
288,
1336,
275,
295,
14,
6452,
8,
82,
16136,
16510,
83,
1111,
16137,
8194,
17,
12,
18,
1552,
8,
6977,
4186,
336,
9,
288,
340,
440,
1336,
26,
355,
746,
1722,
8,
490,
289,
2,
12434,
4839,
370,
506,
315,
314,
7305,
2559,
1475,
12,
1275,
69,
14,
71,
2020,
2559,
63,
65,
389,
17,
14,
1789,
12,
503,
2559,
63,
66,
8119,
17,
14,
1789,
12,
1325,
4788,
469,
12434,
7063,
355,
776,
288,
1687,
12,
2934,
63,
422,
275,
1336,
59,
16,
61,
288,
13632,
59,
411,
61,
275,
2934,
63,
422,
288,
340,
1687,
440,
315,
4156,
26,
355,
746,
1722,
8,
70,
14381,
12434,
9160,
1929,
1373,
402,
469,
513,
8,
1483,
14,
1612,
1012,
1386,
1325,
4788,
469,
411,
15412,
339,
327,
4539,
1930,
272,
340,
5496,
508,
298,
1548,
582,
267,
4788,
63,
422,
275,
32443,
904,
779,
495,
8,
88,
9,
367,
671,
315,
984,
14,
1023,
63,
815,
1491,
19,
3934,
267,
367,
1687,
12,
2934,
63,
422,
315,
13632,
14,
1744,
837,
288,
485,
5785,
63,
6234,
8,
411,
12,
4788,
63,
422,
12,
2934,
63,
422,
12,
10685,
12,
5496,
12,
8328,
9,
267,
372,
339,
327,
1104,
340,
1263,
1015,
365,
4903,
272,
862,
26,
267,
4788,
63,
422,
275,
14802,
63,
2343,
14,
1023,
8,
4600,
9,
272,
871,
14802,
63,
2343,
14,
8599,
10870,
26,
267,
746,
14802,
63,
2343,
14,
8599,
10870,
8,
288,
289,
2,
1918,
5041,
12434,
6834,
4084,
1990,
440,
1911,
436,
365,
1415,
701,
642,
4223,
14,
469,
6479,
7063,
267,
776,
339,
327,
1104,
626,
314,
2451,
1015,
365,
4903,
340,
1015,
1329,
503,
282,
1425,
1990,
2741,
272,
340,
2934,
63,
422,
365
] |
[
1898,
25455,
710,
869,
1518,
1540,
13414,
11682,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
22905,
367,
6449,
543,
2559,
5459,
199,
624,
199,
199,
646,
4182,
199,
646,
295,
199,
646,
984,
199,
504,
14090,
492,
4879,
199,
199,
504,
27369,
492,
1015,
421,
199,
3,
710,
2559,
14802,
63,
2343,
365,
315,
282,
3365,
4192,
12,
10298,
641,
314,
2366,
1015,
14,
199,
692,
984,
14,
1023,
63,
815,
665,
334,
19,
12,
1695,
304,
272,
492,
14802,
63,
2343,
199,
2836,
26,
272,
492,
14802,
14,
2343,
465,
14802,
63,
2343,
421,
199,
1483,
275,
469,
272,
3886,
582,
4182,
14,
4116,
12,
272,
3886,
29,
582,
4182,
14,
274,
12,
272,
298,
389,
582,
4182,
14,
4077,
12,
272,
298,
1111,
582,
4182,
14,
685,
12,
272,
298,
8119,
582,
4182,
14,
303,
12,
272,
25366,
4182,
14,
3308,
12,
199,
93,
421,
199,
318,
485,
5785,
63,
6234,
8,
411,
12,
4788,
63,
422,
12,
2934,
63,
422,
12,
10685,
12,
5496,
12,
8328,
304,
272,
340,
4788,
63,
422,
365,
488,
26,
267,
746,
1722,
480,
7808,
63,
422,
365,
488,
531,
272,
340,
2934,
63,
422,
365,
488,
26,
267,
746,
1722,
480,
7051,
63,
422,
365,
488,
531,
272,
340,
440,
4156,
59,
411,
8738,
1023,
14,
1122,
8,
7808,
63,
422,
395,
1015,
14,
1122,
8,
7051,
63,
422,
2298,
267,
746,
3545,
8,
288,
289,
14381,
12434,
93,
365,
1415,
367,
282,
3293,
805,
316,
402,
642,
859,
12,
1325,
1911,
469,
4600,
93,
389,
91,
7808,
63,
422,
26944,
6479,
7063,
267,
776,
421,
199,
318,
4409,
63,
1023,
8,
12434,
26,
620,
12,
8328,
26,
4879,
59,
495,
61,
275,
488,
9,
1035,
488,
26,
272,
408,
272,
14795,
282,
8836,
1104,
402,
314,
5936,
5459,
12,
1808,
314,
5835,
2011,
6302,
1202,
701,
7305,
14,
339,
710,
4903,
859,
1015,
12477,
687,
314,
658,
2124,
13,
5154,
64,
2935,
4799,
658,
25893,
63,
2343,
2313,
339,
3033,
26,
267,
10685,
18479,
1113,
1705,
495,
25452,
7305,
3449,
5492,
12,
325,
14,
71,
2020,
221,
298,
1418,
6315,
389,
16,
14,
25,
14,
20,
401,
298,
84,
81,
6428,
8119,
20,
14,
1465,
401,
298,
4714,
2,
267,
8328,
18479,
1113,
1705,
495,
3559,
658,
4144,
25452,
4052,
18453,
1636,
370,
870,
315,
1930,
402,
9760,
440,
3769,
7647,
339,
5679,
447,
10817,
4409,
63,
1023,
480,
15718,
30,
17,
14,
17,
14,
18,
531,
2126,
4409,
63,
1023,
480,
4714,
30,
17,
14,
1085,
14,
21,
401,
298,
3749,
365,
11012,
370,
1172,
367,
15685,
4499,
531,
339,
408,
339,
8328,
275,
289,
3212,
78,
91,
6479,
7063,
340,
8328,
365,
440,
488,
587,
3087,
339,
327,
2222,
13,
24155,
1104,
272,
340,
295,
14,
1431,
8,
82,
16136,
7023,
87,
18005,
2696,
68,
2807,
11918,
10685,
304,
267,
5496,
12,
1687,
12,
2934,
63,
422,
275,
10685,
12,
488,
12,
488,
272,
587,
26,
267,
1336,
275,
295,
14,
6452,
8,
82,
16136,
7059,
1111,
28,
3072,
83,
11896,
16510,
83,
1111,
16137,
8194,
17,
12,
18,
5565,
11,
4186,
10685,
9,
267,
340,
440,
1336,
26,
288,
746,
1722,
8,
355,
289,
2,
12434,
4839,
370,
506,
315,
314,
7305,
2559,
1475,
12,
1275,
69,
14,
71,
2020,
2559,
63,
65,
389,
17,
14,
1789,
12,
503,
2559,
63,
66,
8119,
17,
14,
1789,
12,
1325,
4788,
469,
12434,
7063,
288,
776,
267,
5496,
12,
2934,
63,
2861,
275,
1336,
59,
16,
61,
267,
2934,
63,
1842,
275,
2934,
63,
2861,
14,
1294,
20324,
221,
327,
2337,
4293,
506,
3663,
9760,
267,
13632,
275,
1052,
267,
367,
336,
315,
2934,
63,
1842,
26,
288,
1336,
275,
295,
14,
6452,
8,
82,
16136,
16510,
83,
1111,
16137,
8194,
17,
12,
18,
1552,
8,
6977,
4186,
336,
9,
288,
340,
440,
1336,
26,
355,
746,
1722,
8,
490,
289,
2,
12434,
4839,
370,
506,
315,
314,
7305,
2559,
1475,
12,
1275,
69,
14,
71,
2020,
2559,
63,
65,
389,
17,
14,
1789,
12,
503,
2559,
63,
66,
8119,
17,
14,
1789,
12,
1325,
4788,
469,
12434,
7063,
355,
776,
288,
1687,
12,
2934,
63,
422,
275,
1336,
59,
16,
61,
288,
13632,
59,
411,
61,
275,
2934,
63,
422,
288,
340,
1687,
440,
315,
4156,
26,
355,
746,
1722,
8,
70,
14381,
12434,
9160,
1929,
1373,
402,
469,
513,
8,
1483,
14,
1612,
1012,
1386,
1325,
4788,
469,
411,
15412,
339,
327,
4539,
1930,
272,
340,
5496,
508,
298,
1548,
582,
267,
4788,
63,
422,
275,
32443,
904,
779,
495,
8,
88,
9,
367,
671,
315,
984,
14,
1023,
63,
815,
1491,
19,
3934,
267,
367,
1687,
12,
2934,
63,
422,
315,
13632,
14,
1744,
837,
288,
485,
5785,
63,
6234,
8,
411,
12,
4788,
63,
422,
12,
2934,
63,
422,
12,
10685,
12,
5496,
12,
8328,
9,
267,
372,
339,
327,
1104,
340,
1263,
1015,
365,
4903,
272,
862,
26,
267,
4788,
63,
422,
275,
14802,
63,
2343,
14,
1023,
8,
4600,
9,
272,
871,
14802,
63,
2343,
14,
8599,
10870,
26,
267,
746,
14802,
63,
2343,
14,
8599,
10870,
8,
288,
289,
2,
1918,
5041,
12434,
6834,
4084,
1990,
440,
1911,
436,
365,
1415,
701,
642,
4223,
14,
469,
6479,
7063,
267,
776,
339,
327,
1104,
626,
314,
2451,
1015,
365,
4903,
340,
1015,
1329,
503,
282,
1425,
1990,
2741,
272,
340,
2934,
63,
422,
365,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
shangwuhencc/scikit-learn
|
examples/applications/face_recognition.py
|
191
|
5513
|
"""
===================================================
Faces recognition example using eigenfaces and SVMs
===================================================
The dataset used in this example is a preprocessed excerpt of the
"Labeled Faces in the Wild", aka LFW_:
http://vis-www.cs.umass.edu/lfw/lfw-funneled.tgz (233MB)
.. _LFW: http://vis-www.cs.umass.edu/lfw/
Expected results for the top 5 most represented people in the dataset::
precision recall f1-score support
Ariel Sharon 0.67 0.92 0.77 13
Colin Powell 0.75 0.78 0.76 60
Donald Rumsfeld 0.78 0.67 0.72 27
George W Bush 0.86 0.86 0.86 146
Gerhard Schroeder 0.76 0.76 0.76 25
Hugo Chavez 0.67 0.67 0.67 15
Tony Blair 0.81 0.69 0.75 36
avg / total 0.80 0.80 0.80 322
"""
from __future__ import print_function
from time import time
import logging
import matplotlib.pyplot as plt
from sklearn.cross_validation import train_test_split
from sklearn.datasets import fetch_lfw_people
from sklearn.grid_search import GridSearchCV
from sklearn.metrics import classification_report
from sklearn.metrics import confusion_matrix
from sklearn.decomposition import RandomizedPCA
from sklearn.svm import SVC
print(__doc__)
# Display progress logs on stdout
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
###############################################################################
# Download the data, if not already on disk and load it as numpy arrays
lfw_people = fetch_lfw_people(min_faces_per_person=70, resize=0.4)
# introspect the images arrays to find the shapes (for plotting)
n_samples, h, w = lfw_people.images.shape
# for machine learning we use the 2 data directly (as relative pixel
# positions info is ignored by this model)
X = lfw_people.data
n_features = X.shape[1]
# the label to predict is the id of the person
y = lfw_people.target
target_names = lfw_people.target_names
n_classes = target_names.shape[0]
print("Total dataset size:")
print("n_samples: %d" % n_samples)
print("n_features: %d" % n_features)
print("n_classes: %d" % n_classes)
###############################################################################
# Split into a training set and a test set using a stratified k fold
# split into a training and testing set
X_train, X_test, y_train, y_test = train_test_split(
X, y, test_size=0.25, random_state=42)
###############################################################################
# Compute a PCA (eigenfaces) on the face dataset (treated as unlabeled
# dataset): unsupervised feature extraction / dimensionality reduction
n_components = 150
print("Extracting the top %d eigenfaces from %d faces"
% (n_components, X_train.shape[0]))
t0 = time()
pca = RandomizedPCA(n_components=n_components, whiten=True).fit(X_train)
print("done in %0.3fs" % (time() - t0))
eigenfaces = pca.components_.reshape((n_components, h, w))
print("Projecting the input data on the eigenfaces orthonormal basis")
t0 = time()
X_train_pca = pca.transform(X_train)
X_test_pca = pca.transform(X_test)
print("done in %0.3fs" % (time() - t0))
###############################################################################
# Train a SVM classification model
print("Fitting the classifier to the training set")
t0 = time()
param_grid = {'C': [1e3, 5e3, 1e4, 5e4, 1e5],
'gamma': [0.0001, 0.0005, 0.001, 0.005, 0.01, 0.1], }
clf = GridSearchCV(SVC(kernel='rbf', class_weight='balanced'), param_grid)
clf = clf.fit(X_train_pca, y_train)
print("done in %0.3fs" % (time() - t0))
print("Best estimator found by grid search:")
print(clf.best_estimator_)
###############################################################################
# Quantitative evaluation of the model quality on the test set
print("Predicting people's names on the test set")
t0 = time()
y_pred = clf.predict(X_test_pca)
print("done in %0.3fs" % (time() - t0))
print(classification_report(y_test, y_pred, target_names=target_names))
print(confusion_matrix(y_test, y_pred, labels=range(n_classes)))
###############################################################################
# Qualitative evaluation of the predictions using matplotlib
def plot_gallery(images, titles, h, w, n_row=3, n_col=4):
"""Helper function to plot a gallery of portraits"""
plt.figure(figsize=(1.8 * n_col, 2.4 * n_row))
plt.subplots_adjust(bottom=0, left=.01, right=.99, top=.90, hspace=.35)
for i in range(n_row * n_col):
plt.subplot(n_row, n_col, i + 1)
plt.imshow(images[i].reshape((h, w)), cmap=plt.cm.gray)
plt.title(titles[i], size=12)
plt.xticks(())
plt.yticks(())
# plot the result of the prediction on a portion of the test set
def title(y_pred, y_test, target_names, i):
pred_name = target_names[y_pred[i]].rsplit(' ', 1)[-1]
true_name = target_names[y_test[i]].rsplit(' ', 1)[-1]
return 'predicted: %s\ntrue: %s' % (pred_name, true_name)
prediction_titles = [title(y_pred, y_test, target_names, i)
for i in range(y_pred.shape[0])]
plot_gallery(X_test, prediction_titles, h, w)
# plot the gallery of the most significative eigenfaces
eigenface_titles = ["eigenface %d" % i for i in range(eigenfaces.shape[0])]
plot_gallery(eigenfaces, eigenface_titles, h, w)
plt.show()
|
bsd-3-clause
|
[
624,
199,
12813,
5918,
199,
1906,
823,
17319,
15415,
2893,
1808,
11471,
4309,
436,
428,
6849,
83,
199,
12813,
5918,
199,
199,
1918,
4789,
1202,
315,
642,
2893,
365,
282,
876,
7292,
444,
2247,
541,
402,
314,
199,
2,
26545,
10859,
823,
315,
314,
644,
668,
401,
282,
7351,
491,
19445,
10388,
819,
1455,
921,
5068,
13,
1544,
14,
1259,
14,
453,
405,
14,
8654,
15,
31624,
15,
31624,
13,
7036,
685,
1146,
14,
27220,
334,
10034,
4567,
9,
199,
199,
703,
485,
15965,
55,
26,
1455,
921,
5068,
13,
1544,
14,
1259,
14,
453,
405,
14,
8654,
15,
31624,
15,
199,
199,
6964,
2058,
367,
314,
2746,
959,
4750,
11159,
13135,
315,
314,
4789,
447,
199,
673,
7151,
259,
26174,
221,
289,
17,
13,
3397,
257,
2291,
10813,
31153,
352,
5244,
285,
265,
755,
378,
14,
1822,
420,
378,
14,
2942,
420,
378,
14,
1138,
263,
4944,
1362,
3626,
262,
510,
583,
1697,
755,
378,
14,
2194,
420,
378,
14,
2277,
420,
378,
14,
2114,
263,
5212,
523,
7529,
27075,
820,
453,
7646,
457,
755,
378,
14,
2277,
420,
378,
14,
1822,
420,
378,
14,
2819,
263,
8087,
272,
5346,
24591,
644,
699,
2084,
755,
378,
14,
1184,
420,
378,
14,
1184,
420,
378,
14,
1184,
755,
31263,
199,
27866,
8726,
22985,
293,
69,
424,
755,
378,
14,
2114,
420,
378,
14,
2114,
420,
378,
14,
2114,
263,
5661,
489,
869,
1518,
79,
2799,
811,
90,
755,
378,
14,
1822,
420,
378,
14,
1822,
420,
378,
14,
1822,
263,
4114,
2126,
377,
5220,
699,
416,
723,
755,
378,
14,
2835,
420,
378,
14,
1876,
420,
378,
14,
2194,
263,
8780,
2541,
12402,
1182,
3141,
755,
378,
14,
1257,
420,
378,
14,
1257,
420,
378,
14,
1257,
755,
650,
1081,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
900,
492,
900,
199,
646,
2050,
199,
646,
8027,
14,
13563,
465,
4488,
199,
199,
504,
6357,
14,
7925,
63,
6136,
492,
3560,
63,
396,
63,
1294,
199,
504,
6357,
14,
12281,
492,
5267,
63,
31624,
63,
13562,
199,
504,
6357,
14,
3825,
63,
1733,
492,
32570,
199,
504,
6357,
14,
6759,
492,
12505,
63,
3070,
199,
504,
6357,
14,
6759,
492,
26314,
63,
3642,
199,
504,
6357,
14,
31384,
492,
9571,
1759,
23852,
199,
504,
6357,
14,
16820,
492,
428,
9454,
421,
199,
1361,
3460,
1301,
3368,
199,
199,
3,
12175,
6696,
9610,
641,
3839,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
4531,
12,
1475,
29342,
18331,
9,
83,
2818,
1188,
9,
83,
358,
421,
199,
11490,
199,
3,
17955,
314,
666,
12,
340,
440,
2575,
641,
4543,
436,
2248,
652,
465,
2680,
6572,
199,
199,
31624,
63,
13562,
275,
5267,
63,
31624,
63,
13562,
8,
827,
63,
4309,
63,
529,
63,
5484,
29,
2760,
12,
15210,
29,
16,
14,
20,
9,
199,
199,
3,
1109,
21302,
314,
5935,
6572,
370,
2342,
314,
11751,
334,
509,
25174,
9,
199,
78,
63,
3356,
12,
394,
12,
336,
275,
14642,
87,
63,
13562,
14,
4782,
14,
1392,
199,
199,
3,
367,
6844,
9328,
781,
675,
314,
499,
666,
5370,
334,
305,
3847,
7148,
199,
3,
12266,
2256,
365,
5525,
701,
642,
1402,
9,
199,
56,
275,
14642,
87,
63,
13562,
14,
576,
199,
78,
63,
3179,
275,
1323,
14,
1392,
59,
17,
61,
199,
199,
3,
314,
1768,
370,
12610,
365,
314,
1305,
402,
314,
4954,
199,
89,
275,
14642,
87,
63,
13562,
14,
1375,
199,
1375,
63,
1247,
275,
14642,
87,
63,
13562,
14,
1375,
63,
1247,
199,
78,
63,
2888,
275,
1347,
63,
1247,
14,
1392,
59,
16,
61,
199,
199,
1361,
480,
7316,
4789,
1568,
9107,
199,
1361,
480,
78,
63,
3356,
26,
450,
68,
2,
450,
302,
63,
3356,
9,
199,
1361,
480,
78,
63,
3179,
26,
450,
68,
2,
450,
302,
63,
3179,
9,
199,
1361,
480,
78,
63,
2888,
26,
450,
68,
2,
450,
302,
63,
2888,
9,
421,
199,
11490,
199,
3,
11740,
1901,
282,
6093,
663,
436,
282,
511,
663,
1808,
282,
20370,
8981,
1022,
20675,
199,
199,
3,
3715,
1901,
282,
6093,
436,
5343,
663,
199,
56,
63,
2834,
12,
1323,
63,
396,
12,
612,
63,
2834,
12,
612,
63,
396,
275,
3560,
63,
396,
63,
1294,
8,
272,
1323,
12,
612,
12,
511,
63,
890,
29,
16,
14,
821,
12,
2196,
63,
929,
29,
2260,
9,
421,
199,
11490,
199,
3,
8354,
282,
25266,
334,
19545,
4309,
9,
641,
314,
8870,
4789,
334,
84,
9640,
465,
625,
21242,
199,
3,
4789,
304,
625,
4792,
17311,
3878,
19967,
1182,
6240,
6712,
16773,
199,
78,
63,
4608,
275,
14711,
199,
199,
1361,
480,
12147,
316,
314,
2746,
450,
68,
11471,
4309,
687,
450,
68,
21143,
2,
489,
450,
334,
78,
63,
4608,
12,
1323,
63,
2834,
14,
1392,
59,
16,
2459,
199,
84,
16,
275,
900,
342,
199,
19247,
275,
9571,
1759,
23852,
8,
78,
63,
4608,
29,
78,
63,
4608,
12,
704,
25840,
29,
549,
680,
3269,
8,
56,
63,
2834,
9,
199,
1361,
480,
4456,
315,
450,
16,
14,
19,
2319,
2,
450,
334,
521,
342,
446,
307,
16,
430,
199,
199,
19545,
4309,
275,
29518,
14,
4608,
3754,
5217,
1332,
78,
63,
4608,
12,
394,
12,
336,
430,
199,
199,
1361,
480,
4761,
316,
314,
1324,
666,
641,
314,
11471,
4309,
503,
898,
1783,
5597,
531,
199,
84,
16,
275,
900,
342,
199,
56,
63,
2834,
63,
19247,
275,
29518,
14,
4711,
8,
56,
63,
2834,
9,
199,
56,
63,
396,
63,
19247,
275,
29518,
14,
4711,
8,
56,
63,
396,
9,
199,
1361,
480,
4456,
315,
450,
16,
14,
19,
2319,
2,
450,
334,
521,
342,
446,
307,
16,
430,
421,
199,
11490,
199,
3,
16732,
282,
428,
6849,
12505,
1402,
199,
199,
1361,
480,
13776,
1337,
314,
12429,
370,
314,
6093,
663,
531,
199,
84,
16,
275,
900,
342,
199,
635,
63,
3825,
275,
791,
35,
356,
359,
17,
69,
19,
12,
959,
69,
19,
12,
413,
69,
20,
12,
959,
69,
20,
12,
413,
69,
21,
467,
1598,
283,
7325,
356,
359,
16,
14,
4183,
12,
378,
14,
15646,
12,
378,
14,
4587,
12,
378,
14,
7972,
12,
378,
14,
614,
12,
378,
14
] |
[
199,
12813,
5918,
199,
1906,
823,
17319,
15415,
2893,
1808,
11471,
4309,
436,
428,
6849,
83,
199,
12813,
5918,
199,
199,
1918,
4789,
1202,
315,
642,
2893,
365,
282,
876,
7292,
444,
2247,
541,
402,
314,
199,
2,
26545,
10859,
823,
315,
314,
644,
668,
401,
282,
7351,
491,
19445,
10388,
819,
1455,
921,
5068,
13,
1544,
14,
1259,
14,
453,
405,
14,
8654,
15,
31624,
15,
31624,
13,
7036,
685,
1146,
14,
27220,
334,
10034,
4567,
9,
199,
199,
703,
485,
15965,
55,
26,
1455,
921,
5068,
13,
1544,
14,
1259,
14,
453,
405,
14,
8654,
15,
31624,
15,
199,
199,
6964,
2058,
367,
314,
2746,
959,
4750,
11159,
13135,
315,
314,
4789,
447,
199,
673,
7151,
259,
26174,
221,
289,
17,
13,
3397,
257,
2291,
10813,
31153,
352,
5244,
285,
265,
755,
378,
14,
1822,
420,
378,
14,
2942,
420,
378,
14,
1138,
263,
4944,
1362,
3626,
262,
510,
583,
1697,
755,
378,
14,
2194,
420,
378,
14,
2277,
420,
378,
14,
2114,
263,
5212,
523,
7529,
27075,
820,
453,
7646,
457,
755,
378,
14,
2277,
420,
378,
14,
1822,
420,
378,
14,
2819,
263,
8087,
272,
5346,
24591,
644,
699,
2084,
755,
378,
14,
1184,
420,
378,
14,
1184,
420,
378,
14,
1184,
755,
31263,
199,
27866,
8726,
22985,
293,
69,
424,
755,
378,
14,
2114,
420,
378,
14,
2114,
420,
378,
14,
2114,
263,
5661,
489,
869,
1518,
79,
2799,
811,
90,
755,
378,
14,
1822,
420,
378,
14,
1822,
420,
378,
14,
1822,
263,
4114,
2126,
377,
5220,
699,
416,
723,
755,
378,
14,
2835,
420,
378,
14,
1876,
420,
378,
14,
2194,
263,
8780,
2541,
12402,
1182,
3141,
755,
378,
14,
1257,
420,
378,
14,
1257,
420,
378,
14,
1257,
755,
650,
1081,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
900,
492,
900,
199,
646,
2050,
199,
646,
8027,
14,
13563,
465,
4488,
199,
199,
504,
6357,
14,
7925,
63,
6136,
492,
3560,
63,
396,
63,
1294,
199,
504,
6357,
14,
12281,
492,
5267,
63,
31624,
63,
13562,
199,
504,
6357,
14,
3825,
63,
1733,
492,
32570,
199,
504,
6357,
14,
6759,
492,
12505,
63,
3070,
199,
504,
6357,
14,
6759,
492,
26314,
63,
3642,
199,
504,
6357,
14,
31384,
492,
9571,
1759,
23852,
199,
504,
6357,
14,
16820,
492,
428,
9454,
421,
199,
1361,
3460,
1301,
3368,
199,
199,
3,
12175,
6696,
9610,
641,
3839,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
4531,
12,
1475,
29342,
18331,
9,
83,
2818,
1188,
9,
83,
358,
421,
199,
11490,
199,
3,
17955,
314,
666,
12,
340,
440,
2575,
641,
4543,
436,
2248,
652,
465,
2680,
6572,
199,
199,
31624,
63,
13562,
275,
5267,
63,
31624,
63,
13562,
8,
827,
63,
4309,
63,
529,
63,
5484,
29,
2760,
12,
15210,
29,
16,
14,
20,
9,
199,
199,
3,
1109,
21302,
314,
5935,
6572,
370,
2342,
314,
11751,
334,
509,
25174,
9,
199,
78,
63,
3356,
12,
394,
12,
336,
275,
14642,
87,
63,
13562,
14,
4782,
14,
1392,
199,
199,
3,
367,
6844,
9328,
781,
675,
314,
499,
666,
5370,
334,
305,
3847,
7148,
199,
3,
12266,
2256,
365,
5525,
701,
642,
1402,
9,
199,
56,
275,
14642,
87,
63,
13562,
14,
576,
199,
78,
63,
3179,
275,
1323,
14,
1392,
59,
17,
61,
199,
199,
3,
314,
1768,
370,
12610,
365,
314,
1305,
402,
314,
4954,
199,
89,
275,
14642,
87,
63,
13562,
14,
1375,
199,
1375,
63,
1247,
275,
14642,
87,
63,
13562,
14,
1375,
63,
1247,
199,
78,
63,
2888,
275,
1347,
63,
1247,
14,
1392,
59,
16,
61,
199,
199,
1361,
480,
7316,
4789,
1568,
9107,
199,
1361,
480,
78,
63,
3356,
26,
450,
68,
2,
450,
302,
63,
3356,
9,
199,
1361,
480,
78,
63,
3179,
26,
450,
68,
2,
450,
302,
63,
3179,
9,
199,
1361,
480,
78,
63,
2888,
26,
450,
68,
2,
450,
302,
63,
2888,
9,
421,
199,
11490,
199,
3,
11740,
1901,
282,
6093,
663,
436,
282,
511,
663,
1808,
282,
20370,
8981,
1022,
20675,
199,
199,
3,
3715,
1901,
282,
6093,
436,
5343,
663,
199,
56,
63,
2834,
12,
1323,
63,
396,
12,
612,
63,
2834,
12,
612,
63,
396,
275,
3560,
63,
396,
63,
1294,
8,
272,
1323,
12,
612,
12,
511,
63,
890,
29,
16,
14,
821,
12,
2196,
63,
929,
29,
2260,
9,
421,
199,
11490,
199,
3,
8354,
282,
25266,
334,
19545,
4309,
9,
641,
314,
8870,
4789,
334,
84,
9640,
465,
625,
21242,
199,
3,
4789,
304,
625,
4792,
17311,
3878,
19967,
1182,
6240,
6712,
16773,
199,
78,
63,
4608,
275,
14711,
199,
199,
1361,
480,
12147,
316,
314,
2746,
450,
68,
11471,
4309,
687,
450,
68,
21143,
2,
489,
450,
334,
78,
63,
4608,
12,
1323,
63,
2834,
14,
1392,
59,
16,
2459,
199,
84,
16,
275,
900,
342,
199,
19247,
275,
9571,
1759,
23852,
8,
78,
63,
4608,
29,
78,
63,
4608,
12,
704,
25840,
29,
549,
680,
3269,
8,
56,
63,
2834,
9,
199,
1361,
480,
4456,
315,
450,
16,
14,
19,
2319,
2,
450,
334,
521,
342,
446,
307,
16,
430,
199,
199,
19545,
4309,
275,
29518,
14,
4608,
3754,
5217,
1332,
78,
63,
4608,
12,
394,
12,
336,
430,
199,
199,
1361,
480,
4761,
316,
314,
1324,
666,
641,
314,
11471,
4309,
503,
898,
1783,
5597,
531,
199,
84,
16,
275,
900,
342,
199,
56,
63,
2834,
63,
19247,
275,
29518,
14,
4711,
8,
56,
63,
2834,
9,
199,
56,
63,
396,
63,
19247,
275,
29518,
14,
4711,
8,
56,
63,
396,
9,
199,
1361,
480,
4456,
315,
450,
16,
14,
19,
2319,
2,
450,
334,
521,
342,
446,
307,
16,
430,
421,
199,
11490,
199,
3,
16732,
282,
428,
6849,
12505,
1402,
199,
199,
1361,
480,
13776,
1337,
314,
12429,
370,
314,
6093,
663,
531,
199,
84,
16,
275,
900,
342,
199,
635,
63,
3825,
275,
791,
35,
356,
359,
17,
69,
19,
12,
959,
69,
19,
12,
413,
69,
20,
12,
959,
69,
20,
12,
413,
69,
21,
467,
1598,
283,
7325,
356,
359,
16,
14,
4183,
12,
378,
14,
15646,
12,
378,
14,
4587,
12,
378,
14,
7972,
12,
378,
14,
614,
12,
378,
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,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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
] |
StevenBlack/phantomjs
|
src/qt/qtwebkit/Tools/Scripts/webkitpy/common/checkout/commitinfo_unittest.py
|
124
|
3032
|
# Copyright (C) 2010 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import unittest2 as unittest
from webkitpy.common.checkout.commitinfo import CommitInfo
from webkitpy.common.config.committers import CommitterList, Committer, Reviewer
class CommitInfoTest(unittest.TestCase):
def test_commit_info_creation(self):
author = Committer("Author", "author@example.com")
committer = Committer("Committer", "committer@example.com")
reviewer = Reviewer("Reviewer", "reviewer@example.com")
committer_list = CommitterList(committers=[author, committer], reviewers=[reviewer])
changelog_data = {
"bug_id": 1234,
"author_name": "Committer",
"author_email": "author@example.com",
"author": author,
"reviewer_text": "Reviewer",
"reviewer": reviewer,
}
commit = CommitInfo(123, "committer@example.com", changelog_data, committer_list)
self.assertEqual(commit.revision(), 123)
self.assertEqual(commit.bug_id(), 1234)
self.assertEqual(commit.author_name(), "Committer")
self.assertEqual(commit.author_email(), "author@example.com")
self.assertEqual(commit.author(), author)
self.assertEqual(commit.reviewer_text(), "Reviewer")
self.assertEqual(commit.reviewer(), reviewer)
self.assertEqual(commit.committer(), committer)
self.assertEqual(commit.committer_email(), "committer@example.com")
self.assertEqual(commit.responsible_parties(), set([author, committer, reviewer]))
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
259,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2882,
18,
465,
2882,
199,
199,
504,
18007,
14,
2330,
14,
12891,
14,
3543,
815,
492,
21447,
2354,
199,
504,
18007,
14,
2330,
14,
888,
14,
3543,
878,
492,
21447,
351,
1296,
12,
21447,
351,
12,
799,
16645,
199,
199,
533,
21447,
2354,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
3543,
63,
815,
63,
8782,
8,
277,
304,
267,
4132,
275,
21447,
351,
480,
5949,
401,
298,
2502,
32,
2694,
14,
957,
531,
267,
5532,
351,
275,
21447,
351,
480,
11421,
351,
401,
298,
3543,
351,
32,
2694,
14,
957,
531,
267,
11248,
281,
275,
799,
16645,
480,
497,
16645,
401,
298,
23492,
32,
2694,
14,
957,
531,
267,
5532,
351,
63,
513,
275,
21447,
351,
1296,
8,
3543,
878,
1524,
2502,
12,
5532,
351,
467,
11248,
1192,
1524,
23492,
566,
398,
1570,
793,
63,
576,
275,
469,
288,
298,
1266,
63,
344,
582,
14763,
12,
288,
298,
2502,
63,
354,
582,
298,
11421,
351,
401,
288,
298,
2502,
63,
2123,
582,
298,
2502,
32,
2694,
14,
957,
401,
288,
298,
2502,
582,
4132,
12,
288,
298,
23492,
63,
505,
582,
298,
497,
16645,
401,
288,
298,
23492,
582,
11248,
281,
12,
267,
789,
267,
5532,
275,
21447,
2354,
8,
4288,
12,
298,
3543,
351,
32,
2694,
14,
957,
401,
1570,
793,
63,
576,
12,
5532,
351,
63,
513,
9,
398,
291,
14,
629,
8,
3543,
14,
5792,
1062,
11869,
9,
267,
291,
14,
629,
8,
3543,
14,
1266,
63,
344,
1062,
14763,
9,
267,
291,
14,
629,
8,
3543,
14,
2502,
63,
354,
1062,
298,
11421,
351,
531,
267,
291,
14,
629,
8,
3543,
14,
2502,
63,
2123,
1062,
298,
2502,
32,
2694,
14,
957,
531,
267,
291,
14,
629,
8,
3543,
14,
2502,
1062,
4132,
9,
267,
291,
14,
629,
8,
3543,
14,
23492,
63,
505,
1062,
298,
497,
16645,
531,
267,
291,
14,
629,
8,
3543,
14,
23492,
1062,
11248,
281,
9,
267,
291,
14,
629,
8,
3543,
14,
3543,
351,
1062,
5532,
351,
9,
267,
291,
14,
629,
8,
3543,
14,
3543,
351,
63,
2123,
1062,
298,
3543,
351,
32,
2694,
14,
957,
531,
267,
291,
14,
629,
8,
3543,
14,
3853,
1164,
63,
462,
1417,
1062,
663,
779,
2502,
12,
5532,
351,
12,
11248,
281,
2459,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
35,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
259,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
259,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
259,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2882,
18,
465,
2882,
199,
199,
504,
18007,
14,
2330,
14,
12891,
14,
3543,
815,
492,
21447,
2354,
199,
504,
18007,
14,
2330,
14,
888,
14,
3543,
878,
492,
21447,
351,
1296,
12,
21447,
351,
12,
799,
16645,
199,
199,
533,
21447,
2354,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
3543,
63,
815,
63,
8782,
8,
277,
304,
267,
4132,
275,
21447,
351,
480,
5949,
401,
298,
2502,
32,
2694,
14,
957,
531,
267,
5532,
351,
275,
21447,
351,
480,
11421,
351,
401,
298,
3543,
351,
32,
2694,
14,
957,
531,
267,
11248,
281,
275,
799,
16645,
480,
497,
16645,
401,
298,
23492,
32,
2694,
14,
957,
531,
267,
5532,
351,
63,
513,
275,
21447,
351,
1296,
8,
3543,
878,
1524,
2502,
12,
5532,
351,
467,
11248,
1192,
1524,
23492,
566,
398,
1570,
793,
63,
576,
275,
469,
288,
298,
1266,
63,
344,
582,
14763,
12,
288,
298,
2502,
63,
354,
582,
298,
11421,
351,
401,
288,
298,
2502,
63,
2123,
582,
298,
2502,
32,
2694,
14,
957,
401,
288,
298,
2502,
582,
4132,
12,
288,
298,
23492,
63,
505,
582,
298,
497,
16645,
401,
288,
298,
23492,
582,
11248,
281,
12,
267,
789,
267,
5532,
275,
21447,
2354,
8,
4288,
12,
298,
3543,
351,
32,
2694,
14,
957,
401,
1570,
793,
63,
576,
12,
5532,
351,
63,
513,
9,
398,
291,
14,
629,
8,
3543,
14,
5792,
1062,
11869,
9,
267,
291,
14,
629,
8,
3543,
14,
1266,
63,
344,
1062,
14763,
9,
267,
291,
14,
629,
8,
3543,
14,
2502,
63,
354,
1062,
298,
11421,
351,
531,
267,
291,
14,
629,
8,
3543,
14,
2502,
63,
2123,
1062,
298,
2502,
32,
2694,
14,
957,
531,
267,
291,
14,
629,
8,
3543,
14,
2502,
1062,
4132,
9,
267,
291,
14,
629,
8,
3543,
14,
23492,
63,
505,
1062,
298,
497,
16645,
531,
267,
291,
14,
629,
8,
3543,
14,
23492,
1062,
11248,
281,
9,
267,
291,
14,
629,
8,
3543,
14,
3543,
351,
1062,
5532,
351,
9,
267,
291,
14,
629,
8,
3543,
14,
3543,
351,
63,
2123,
1062,
298,
3543,
351,
32,
2694,
14,
957,
531,
267,
291,
14,
629,
8,
3543,
14,
3853,
1164,
63,
462,
1417,
1062,
663,
779,
2502,
12,
5532,
351,
12,
11248,
281,
2459,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
sonnyhu/scikit-learn
|
sklearn/externals/joblib/disk.py
|
95
|
3235
|
"""
Disk management utilities.
"""
# Authors: Gael Varoquaux <gael dot varoquaux at normalesup dot org>
# Lars Buitinck
# Copyright (c) 2010 Gael Varoquaux
# License: BSD Style, 3 clauses.
import errno
import os
import shutil
import sys
import time
def disk_used(path):
""" Return the disk usage in a directory."""
size = 0
for file in os.listdir(path) + ['.']:
stat = os.stat(os.path.join(path, file))
if hasattr(stat, 'st_blocks'):
size += stat.st_blocks * 512
else:
# on some platform st_blocks is not available (e.g., Windows)
# approximate by rounding to next multiple of 512
size += (stat.st_size // 512 + 1) * 512
# We need to convert to int to avoid having longs on some systems (we
# don't want longs to avoid problems we SQLite)
return int(size / 1024.)
def memstr_to_bytes(text):
""" Convert a memory text to its value in bytes.
"""
kilo = 1024
units = dict(K=kilo, M=kilo ** 2, G=kilo ** 3)
try:
size = int(units[text[-1]] * float(text[:-1]))
except (KeyError, ValueError):
raise ValueError(
"Invalid literal for size give: %s (type %s) should be "
"alike '10G', '500M', '50K'." % (text, type(text)))
return size
def mkdirp(d):
"""Ensure directory d exists (like mkdir -p on Unix)
No guarantee that the directory is writable.
"""
try:
os.makedirs(d)
except OSError as e:
if e.errno != errno.EEXIST:
raise
# if a rmtree operation fails in rm_subdirs, wait for this much time (in secs),
# then retry once. if it still fails, raise the exception
RM_SUBDIRS_RETRY_TIME = 0.1
def rm_subdirs(path, onerror=None):
"""Remove all subdirectories in this path.
The directory indicated by `path` is left in place, and its subdirectories
are erased.
If onerror is set, it is called to handle the error with arguments (func,
path, exc_info) where func is os.listdir, os.remove, or os.rmdir;
path is the argument to that function that caused it to fail; and
exc_info is a tuple returned by sys.exc_info(). If onerror is None,
an exception is raised.
"""
# NOTE this code is adapted from the one in shutil.rmtree, and is
# just as fast
names = []
try:
names = os.listdir(path)
except os.error as err:
if onerror is not None:
onerror(os.listdir, path, sys.exc_info())
else:
raise
for name in names:
fullname = os.path.join(path, name)
if os.path.isdir(fullname):
if onerror is not None:
shutil.rmtree(fullname, False, onerror)
else:
# allow the rmtree to fail once, wait and re-try.
# if the error is raised again, fail
err_count = 0
while True:
try:
shutil.rmtree(fullname, False, None)
break
except os.error:
if err_count > 0:
raise
err_count += 1
time.sleep(RM_SUBDIRS_RETRY_TIME)
|
bsd-3-clause
|
[
624,
199,
10690,
10041,
15841,
14,
199,
624,
199,
199,
3,
6642,
26,
9647,
352,
21084,
79,
392,
10962,
665,
5294,
352,
6308,
2729,
79,
392,
10962,
737,
6590,
17667,
1961,
6308,
5981,
30,
199,
3,
3515,
491,
4291,
4779,
390,
262,
346,
199,
3,
1898,
334,
67,
9,
7129,
9647,
352,
21084,
79,
392,
10962,
199,
3,
844,
26,
6289,
19442,
12,
650,
25089,
14,
421,
199,
646,
7554,
199,
646,
747,
199,
646,
5145,
199,
646,
984,
199,
646,
900,
421,
199,
318,
4543,
63,
2972,
8,
515,
304,
272,
408,
1432,
314,
4543,
4503,
315,
282,
2082,
1041,
272,
1568,
275,
378,
272,
367,
570,
315,
747,
14,
7374,
8,
515,
9,
435,
18953,
2565,
267,
5672,
275,
747,
14,
3736,
8,
736,
14,
515,
14,
904,
8,
515,
12,
570,
430,
267,
340,
2688,
8,
3736,
12,
283,
270,
63,
4166,
735,
288,
1568,
847,
5672,
14,
270,
63,
4166,
627,
10574,
267,
587,
26,
288,
327,
641,
2005,
4298,
410,
63,
4166,
365,
440,
2808,
334,
69,
14,
71,
2020,
5417,
9,
288,
327,
19917,
701,
18100,
370,
2163,
3663,
402,
10574,
288,
1568,
847,
334,
3736,
14,
270,
63,
890,
5001,
10574,
435,
413,
9,
627,
10574,
272,
327,
2136,
1929,
370,
3957,
370,
1109,
370,
5126,
9445,
6132,
458,
641,
2005,
10460,
334,
1129,
272,
327,
2793,
1133,
2934,
6132,
458,
370,
5126,
8826,
781,
19245,
9,
272,
372,
1109,
8,
890,
1182,
6619,
4959,
421,
199,
318,
7573,
495,
63,
475,
63,
2394,
8,
505,
304,
272,
408,
7905,
282,
4402,
1318,
370,
2399,
574,
315,
2783,
14,
272,
408,
272,
1022,
11737,
275,
6619,
272,
6204,
275,
1211,
8,
43,
29,
8810,
320,
12,
603,
29,
8810,
320,
1011,
499,
12,
598,
29,
8810,
320,
1011,
650,
9,
272,
862,
26,
267,
1568,
275,
1109,
8,
5260,
59,
505,
1988,
17,
2677,
627,
2069,
8,
505,
4439,
17,
2459,
272,
871,
334,
10230,
12,
1722,
304,
267,
746,
1722,
8,
288,
298,
3364,
8785,
367,
1568,
8120,
26,
450,
83,
334,
466,
450,
83,
9,
1077,
506,
298,
288,
298,
279,
7455,
283,
709,
39,
297,
283,
5783,
45,
297,
283,
1400,
43,
16669,
450,
334,
505,
12,
730,
8,
505,
1724,
272,
372,
1568,
421,
199,
318,
20366,
80,
8,
68,
304,
272,
408,
13913,
2082,
366,
3495,
334,
2930,
20366,
446,
80,
641,
13074,
9,
272,
3091,
24197,
626,
314,
2082,
365,
17267,
14,
272,
408,
272,
862,
26,
267,
747,
14,
8347,
8,
68,
9,
272,
871,
6440,
465,
325,
26,
267,
340,
325,
14,
7931,
1137,
7554,
14,
28596,
26,
288,
746,
421,
199,
3,
340,
282,
20978,
3439,
6918,
315,
14267,
63,
954,
3220,
12,
3618,
367,
642,
8298,
900,
334,
262,
20091,
395,
199,
3,
2066,
7269,
5403,
14,
340,
652,
5139,
6918,
12,
746,
314,
1919,
199,
11026,
63,
6348,
14455,
63,
27778,
63,
4961,
275,
378,
14,
17,
421,
199,
318,
14267,
63,
954,
3220,
8,
515,
12,
22852,
29,
403,
304,
272,
408,
5587,
1006,
24799,
315,
642,
931,
14,
339,
710,
2082,
22141,
701,
658,
515,
64,
365,
3602,
315,
4192,
12,
436,
2399,
24799,
272,
787,
9266,
11185,
14,
339,
982,
22852,
365,
663,
12,
652,
365,
2797,
370,
2429,
314,
1125,
543,
2368,
334,
1532,
12,
272,
931,
12,
3178,
63,
815,
9,
2382,
2562,
365,
747,
14,
7374,
12,
747,
14,
2168,
12,
503,
747,
14,
19405,
27,
272,
931,
365,
314,
1423,
370,
626,
805,
626,
18104,
652,
370,
2449,
27,
436,
272,
3178,
63,
815,
365,
282,
2008,
2138,
701,
984,
14,
2804,
63,
815,
1252,
221,
982,
22852,
365,
488,
12,
272,
376,
1919,
365,
4915,
14,
272,
408,
339,
327,
6944,
642,
1233,
365,
26266,
687,
314,
1373,
315,
5145,
14,
9242,
12,
436,
365,
272,
327,
2951,
465,
7377,
339,
1561,
275,
942,
272,
862,
26,
267,
1561,
275,
747,
14,
7374,
8,
515,
9,
272,
871,
747,
14,
705,
465,
2329,
26,
267,
340,
22852,
365,
440,
488,
26,
288,
22852,
8,
736,
14,
7374,
12,
931,
12,
984,
14,
2804,
63,
815,
1012,
267,
587,
26,
288,
746,
339,
367,
536,
315,
1561,
26,
267,
11064,
275,
747,
14,
515,
14,
904,
8,
515,
12,
536,
9,
267,
340,
747,
14,
515,
14,
6027,
8,
9930,
304,
288,
340,
22852,
365,
440,
488,
26,
355,
5145,
14,
9242,
8,
9930,
12,
756,
12,
22852,
9,
288,
587,
26,
355,
327,
2040,
314,
20978,
370,
2449,
5403,
12,
3618,
436,
295,
13,
893,
14,
355,
327,
340,
314,
1125,
365,
4915,
4020,
12,
2449,
355,
2329,
63,
835,
275,
378,
355,
1830,
715,
26,
490,
862,
26,
717,
5145,
14,
9242,
8,
9930,
12,
756,
12,
488,
9,
717,
2059,
490,
871,
747,
14,
705,
26,
717,
340,
2329,
63,
835,
690,
378,
26,
1169,
746,
717,
2329,
63,
835,
847,
413,
717,
900,
14,
4532,
8,
11026,
63,
6348,
14455,
63,
27778,
63,
4961,
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
] |
[
199,
10690,
10041,
15841,
14,
199,
624,
199,
199,
3,
6642,
26,
9647,
352,
21084,
79,
392,
10962,
665,
5294,
352,
6308,
2729,
79,
392,
10962,
737,
6590,
17667,
1961,
6308,
5981,
30,
199,
3,
3515,
491,
4291,
4779,
390,
262,
346,
199,
3,
1898,
334,
67,
9,
7129,
9647,
352,
21084,
79,
392,
10962,
199,
3,
844,
26,
6289,
19442,
12,
650,
25089,
14,
421,
199,
646,
7554,
199,
646,
747,
199,
646,
5145,
199,
646,
984,
199,
646,
900,
421,
199,
318,
4543,
63,
2972,
8,
515,
304,
272,
408,
1432,
314,
4543,
4503,
315,
282,
2082,
1041,
272,
1568,
275,
378,
272,
367,
570,
315,
747,
14,
7374,
8,
515,
9,
435,
18953,
2565,
267,
5672,
275,
747,
14,
3736,
8,
736,
14,
515,
14,
904,
8,
515,
12,
570,
430,
267,
340,
2688,
8,
3736,
12,
283,
270,
63,
4166,
735,
288,
1568,
847,
5672,
14,
270,
63,
4166,
627,
10574,
267,
587,
26,
288,
327,
641,
2005,
4298,
410,
63,
4166,
365,
440,
2808,
334,
69,
14,
71,
2020,
5417,
9,
288,
327,
19917,
701,
18100,
370,
2163,
3663,
402,
10574,
288,
1568,
847,
334,
3736,
14,
270,
63,
890,
5001,
10574,
435,
413,
9,
627,
10574,
272,
327,
2136,
1929,
370,
3957,
370,
1109,
370,
5126,
9445,
6132,
458,
641,
2005,
10460,
334,
1129,
272,
327,
2793,
1133,
2934,
6132,
458,
370,
5126,
8826,
781,
19245,
9,
272,
372,
1109,
8,
890,
1182,
6619,
4959,
421,
199,
318,
7573,
495,
63,
475,
63,
2394,
8,
505,
304,
272,
408,
7905,
282,
4402,
1318,
370,
2399,
574,
315,
2783,
14,
272,
408,
272,
1022,
11737,
275,
6619,
272,
6204,
275,
1211,
8,
43,
29,
8810,
320,
12,
603,
29,
8810,
320,
1011,
499,
12,
598,
29,
8810,
320,
1011,
650,
9,
272,
862,
26,
267,
1568,
275,
1109,
8,
5260,
59,
505,
1988,
17,
2677,
627,
2069,
8,
505,
4439,
17,
2459,
272,
871,
334,
10230,
12,
1722,
304,
267,
746,
1722,
8,
288,
298,
3364,
8785,
367,
1568,
8120,
26,
450,
83,
334,
466,
450,
83,
9,
1077,
506,
298,
288,
298,
279,
7455,
283,
709,
39,
297,
283,
5783,
45,
297,
283,
1400,
43,
16669,
450,
334,
505,
12,
730,
8,
505,
1724,
272,
372,
1568,
421,
199,
318,
20366,
80,
8,
68,
304,
272,
408,
13913,
2082,
366,
3495,
334,
2930,
20366,
446,
80,
641,
13074,
9,
272,
3091,
24197,
626,
314,
2082,
365,
17267,
14,
272,
408,
272,
862,
26,
267,
747,
14,
8347,
8,
68,
9,
272,
871,
6440,
465,
325,
26,
267,
340,
325,
14,
7931,
1137,
7554,
14,
28596,
26,
288,
746,
421,
199,
3,
340,
282,
20978,
3439,
6918,
315,
14267,
63,
954,
3220,
12,
3618,
367,
642,
8298,
900,
334,
262,
20091,
395,
199,
3,
2066,
7269,
5403,
14,
340,
652,
5139,
6918,
12,
746,
314,
1919,
199,
11026,
63,
6348,
14455,
63,
27778,
63,
4961,
275,
378,
14,
17,
421,
199,
318,
14267,
63,
954,
3220,
8,
515,
12,
22852,
29,
403,
304,
272,
408,
5587,
1006,
24799,
315,
642,
931,
14,
339,
710,
2082,
22141,
701,
658,
515,
64,
365,
3602,
315,
4192,
12,
436,
2399,
24799,
272,
787,
9266,
11185,
14,
339,
982,
22852,
365,
663,
12,
652,
365,
2797,
370,
2429,
314,
1125,
543,
2368,
334,
1532,
12,
272,
931,
12,
3178,
63,
815,
9,
2382,
2562,
365,
747,
14,
7374,
12,
747,
14,
2168,
12,
503,
747,
14,
19405,
27,
272,
931,
365,
314,
1423,
370,
626,
805,
626,
18104,
652,
370,
2449,
27,
436,
272,
3178,
63,
815,
365,
282,
2008,
2138,
701,
984,
14,
2804,
63,
815,
1252,
221,
982,
22852,
365,
488,
12,
272,
376,
1919,
365,
4915,
14,
272,
408,
339,
327,
6944,
642,
1233,
365,
26266,
687,
314,
1373,
315,
5145,
14,
9242,
12,
436,
365,
272,
327,
2951,
465,
7377,
339,
1561,
275,
942,
272,
862,
26,
267,
1561,
275,
747,
14,
7374,
8,
515,
9,
272,
871,
747,
14,
705,
465,
2329,
26,
267,
340,
22852,
365,
440,
488,
26,
288,
22852,
8,
736,
14,
7374,
12,
931,
12,
984,
14,
2804,
63,
815,
1012,
267,
587,
26,
288,
746,
339,
367,
536,
315,
1561,
26,
267,
11064,
275,
747,
14,
515,
14,
904,
8,
515,
12,
536,
9,
267,
340,
747,
14,
515,
14,
6027,
8,
9930,
304,
288,
340,
22852,
365,
440,
488,
26,
355,
5145,
14,
9242,
8,
9930,
12,
756,
12,
22852,
9,
288,
587,
26,
355,
327,
2040,
314,
20978,
370,
2449,
5403,
12,
3618,
436,
295,
13,
893,
14,
355,
327,
340,
314,
1125,
365,
4915,
4020,
12,
2449,
355,
2329,
63,
835,
275,
378,
355,
1830,
715,
26,
490,
862,
26,
717,
5145,
14,
9242,
8,
9930,
12,
756,
12,
488,
9,
717,
2059,
490,
871,
747,
14,
705,
26,
717,
340,
2329,
63,
835,
690,
378,
26,
1169,
746,
717,
2329,
63,
835,
847,
413,
717,
900,
14,
4532,
8,
11026,
63,
6348,
14455,
63,
27778,
63,
4961,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dyoung418/tensorflow
|
tensorflow/python/kernel_tests/dynamic_partition_op_test.py
|
97
|
6138
|
# Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for the DynamicPartition op."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from six.moves import xrange # pylint: disable=redefined-builtin
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import dtypes
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import data_flow_ops
from tensorflow.python.ops import gradients_impl
import tensorflow.python.ops.data_flow_grad # pylint: disable=unused-import
from tensorflow.python.platform import test
class DynamicPartitionTest(test.TestCase):
def testSimpleOneDimensional(self):
with self.test_session() as sess:
data = constant_op.constant([0, 13, 2, 39, 4, 17])
indices = constant_op.constant([0, 0, 2, 3, 2, 1])
partitions = data_flow_ops.dynamic_partition(
data, indices, num_partitions=4)
partition_vals = sess.run(partitions)
self.assertAllEqual([0, 13], partition_vals[0])
self.assertAllEqual([17], partition_vals[1])
self.assertAllEqual([2, 4], partition_vals[2])
self.assertAllEqual([39], partition_vals[3])
# Vector data input to DynamicPartition results in
# `num_partitions` vectors of unknown length.
self.assertEqual([None], partitions[0].get_shape().as_list())
self.assertEqual([None], partitions[1].get_shape().as_list())
self.assertEqual([None], partitions[2].get_shape().as_list())
self.assertEqual([None], partitions[3].get_shape().as_list())
def testSimpleTwoDimensional(self):
with self.test_session() as sess:
data = constant_op.constant([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11],
[12, 13, 14], [15, 16, 17]])
indices = constant_op.constant([0, 0, 2, 3, 2, 1])
partitions = data_flow_ops.dynamic_partition(
data, indices, num_partitions=4)
partition_vals = sess.run(partitions)
self.assertAllEqual([[0, 1, 2], [3, 4, 5]], partition_vals[0])
self.assertAllEqual([[15, 16, 17]], partition_vals[1])
self.assertAllEqual([[6, 7, 8], [12, 13, 14]], partition_vals[2])
self.assertAllEqual([[9, 10, 11]], partition_vals[3])
# Vector data input to DynamicPartition results in
# `num_partitions` matrices with an unknown number of rows, and 3 columns.
self.assertEqual([None, 3], partitions[0].get_shape().as_list())
self.assertEqual([None, 3], partitions[1].get_shape().as_list())
self.assertEqual([None, 3], partitions[2].get_shape().as_list())
self.assertEqual([None, 3], partitions[3].get_shape().as_list())
def testHigherRank(self):
np.random.seed(7)
with self.test_session() as sess:
for n in 2, 3:
for shape in (4,), (4, 5), (4, 5, 2):
partitions = np.random.randint(n, size=np.prod(shape)).reshape(shape)
for extra_shape in (), (6,), (6, 7):
data = np.random.randn(*(shape + extra_shape))
partitions_t = constant_op.constant(partitions, dtype=dtypes.int32)
data_t = constant_op.constant(data)
outputs = data_flow_ops.dynamic_partition(
data_t, partitions_t, num_partitions=n)
self.assertEqual(n, len(outputs))
outputs_val = sess.run(outputs)
for i, output in enumerate(outputs_val):
self.assertAllEqual(output, data[partitions == i])
# Test gradients
outputs_grad = [7 * output for output in outputs_val]
grads = gradients_impl.gradients(outputs, [data_t, partitions_t],
outputs_grad)
self.assertEqual(grads[1], None) # Partitions has no gradients
self.assertAllEqual(7 * data, sess.run(grads[0]))
def testErrorIndexOutOfRange(self):
with self.test_session() as sess:
data = constant_op.constant([[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11],
[12, 13, 14]])
indices = constant_op.constant([0, 2, 99, 2, 2])
partitions = data_flow_ops.dynamic_partition(
data, indices, num_partitions=4)
with self.assertRaisesOpError(r"partitions\[2\] = 99 is not in \[0, 4\)"):
sess.run(partitions)
def testScalarIndexOutOfRange(self):
with self.test_session() as sess:
bad = 17
data = np.zeros(5)
partitions = data_flow_ops.dynamic_partition(data, bad, num_partitions=7)
with self.assertRaisesOpError(r"partitions = 17 is not in \[0, 7\)"):
sess.run(partitions)
def testHigherRankIndexOutOfRange(self):
with self.test_session() as sess:
shape = (2, 3)
indices = array_ops.placeholder(shape=shape, dtype=np.int32)
data = np.zeros(shape + (5,))
partitions = data_flow_ops.dynamic_partition(
data, indices, num_partitions=7)
for i in xrange(2):
for j in xrange(3):
bad = np.zeros(shape, dtype=np.int32)
bad[i, j] = 17
with self.assertRaisesOpError(
r"partitions\[%d,%d\] = 17 is not in \[0, 7\)" % (i, j)):
sess.run(partitions, feed_dict={indices: bad})
def testErrorWrongDimsIndices(self):
data = constant_op.constant([[0], [1], [2]])
indices = constant_op.constant([[0], [0]])
with self.assertRaises(ValueError):
data_flow_ops.dynamic_partition(data, indices, num_partitions=4)
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
314,
21907,
13068,
1687,
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,
504,
3816,
14,
4912,
492,
4945,
221,
327,
4287,
26,
3507,
29,
27913,
13,
5351,
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,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
666,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
12661,
63,
5472,
199,
646,
3228,
14,
1548,
14,
1483,
14,
576,
63,
1659,
63,
6017,
221,
327,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
21907,
13068,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
3184,
4395,
17905,
279,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
342,
465,
4043,
26,
489,
666,
275,
4413,
63,
411,
14,
4083,
779,
16,
12,
4944,
12,
499,
12,
10551,
12,
841,
12,
5557,
566,
489,
4918,
275,
4413,
63,
411,
14,
4083,
779,
16,
12,
378,
12,
499,
12,
650,
12,
499,
12,
413,
566,
489,
16394,
275,
666,
63,
1659,
63,
1483,
14,
7764,
63,
5312,
8,
881,
666,
12,
4918,
12,
1967,
63,
12553,
29,
20,
9,
489,
6484,
63,
3643,
275,
4043,
14,
1065,
8,
12553,
9,
339,
291,
14,
7069,
779,
16,
12,
4944,
467,
6484,
63,
3643,
59,
16,
566,
272,
291,
14,
7069,
779,
1196,
467,
6484,
63,
3643,
59,
17,
566,
272,
291,
14,
7069,
779,
18,
12,
841,
467,
6484,
63,
3643,
59,
18,
566,
272,
291,
14,
7069,
779,
1355,
467,
6484,
63,
3643,
59,
19,
566,
272,
327,
11388,
666,
1324,
370,
21907,
13068,
2058,
315,
272,
327,
658,
1507,
63,
12553,
64,
11102,
402,
5809,
2582,
14,
272,
291,
14,
629,
779,
403,
467,
16394,
59,
16,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
272,
291,
14,
629,
779,
403,
467,
16394,
59,
17,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
272,
291,
14,
629,
779,
403,
467,
16394,
59,
18,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
272,
291,
14,
629,
779,
403,
467,
16394,
59,
19,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
819,
347,
511,
3184,
11467,
17905,
279,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
342,
465,
4043,
26,
489,
666,
275,
4413,
63,
411,
14,
4083,
4038,
16,
12,
413,
12,
499,
467,
359,
19,
12,
841,
12,
959,
467,
359,
22,
12,
1520,
12,
1695,
467,
359,
25,
12,
1616,
12,
4119,
467,
3521,
359,
713,
12,
4944,
12,
4329,
467,
359,
1046,
12,
3193,
12,
5557,
3934,
489,
4918,
275,
4413,
63,
411,
14,
4083,
779,
16,
12,
378,
12,
499,
12,
650,
12,
499,
12,
413,
566,
489,
16394,
275,
666,
63,
1659,
63,
1483,
14,
7764,
63,
5312,
8,
881,
666,
12,
4918,
12,
1967,
63,
12553,
29,
20,
9,
489,
6484,
63,
3643,
275,
4043,
14,
1065,
8,
12553,
9,
339,
291,
14,
7069,
4038,
16,
12,
413,
12,
499,
467,
359,
19,
12,
841,
12,
959,
2365,
6484,
63,
3643,
59,
16,
566,
272,
291,
14,
7069,
4038,
1046,
12,
3193,
12,
5557,
2365,
6484,
63,
3643,
59,
17,
566,
272,
291,
14,
7069,
4038,
22,
12,
1520,
12,
1695,
467,
359,
713,
12,
4944,
12,
4329,
2365,
6484,
63,
3643,
59,
18,
566,
272,
291,
14,
7069,
4038,
25,
12,
1616,
12,
4119,
2365,
6484,
63,
3643,
59,
19,
566,
272,
327,
11388,
666,
1324,
370,
21907,
13068,
2058,
315,
272,
327,
658,
1507,
63,
12553,
64,
12627,
543,
376,
5809,
1329,
402,
4730,
12,
436,
650,
4362,
14,
272,
291,
14,
629,
779,
403,
12,
650,
467,
16394,
59,
16,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
272,
291,
14,
629,
779,
403,
12,
650,
467,
16394,
59,
17,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
272,
291,
14,
629,
779,
403,
12,
650,
467,
16394,
59,
18,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
272,
291,
14,
629,
779,
403,
12,
650,
467,
16394,
59,
19,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
819,
347,
511,
11688,
281,
19486,
8,
277,
304,
272,
980,
14,
2355,
14,
5176,
8,
23,
9,
272,
543,
291,
14,
396,
63,
1730,
342,
465,
4043,
26,
489,
367,
302,
315,
499,
12,
650,
26,
267,
367,
2215,
315,
334,
20,
4706,
334,
20,
12,
959,
395,
334,
20,
12,
959,
12,
499,
304,
881,
16394,
275,
980,
14,
2355,
14,
8393,
8,
78,
12,
1568,
29,
1590,
14,
8788,
8,
1392,
4992,
5217,
8,
1392,
9,
881,
367,
2402,
63,
1392,
315,
11969,
334,
22,
4706,
334,
22,
12,
1520,
304,
288,
666,
275,
980,
14,
2355,
14,
10843,
29316,
1392,
435,
2402,
63,
1392,
430,
288,
16394,
63,
84,
275,
4413,
63,
411,
14,
4083,
8,
12553,
12,
2152,
29,
5717,
14,
442,
708,
9,
288,
666,
63,
84,
275,
4413,
63,
411,
14,
4083,
8,
576,
9,
288,
4704,
275,
666,
63,
1659,
63
] |
[
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
314,
21907,
13068,
1687,
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,
504,
3816,
14,
4912,
492,
4945,
221,
327,
4287,
26,
3507,
29,
27913,
13,
5351,
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,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
666,
63,
1659,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
12661,
63,
5472,
199,
646,
3228,
14,
1548,
14,
1483,
14,
576,
63,
1659,
63,
6017,
221,
327,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
533,
21907,
13068,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
3184,
4395,
17905,
279,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
342,
465,
4043,
26,
489,
666,
275,
4413,
63,
411,
14,
4083,
779,
16,
12,
4944,
12,
499,
12,
10551,
12,
841,
12,
5557,
566,
489,
4918,
275,
4413,
63,
411,
14,
4083,
779,
16,
12,
378,
12,
499,
12,
650,
12,
499,
12,
413,
566,
489,
16394,
275,
666,
63,
1659,
63,
1483,
14,
7764,
63,
5312,
8,
881,
666,
12,
4918,
12,
1967,
63,
12553,
29,
20,
9,
489,
6484,
63,
3643,
275,
4043,
14,
1065,
8,
12553,
9,
339,
291,
14,
7069,
779,
16,
12,
4944,
467,
6484,
63,
3643,
59,
16,
566,
272,
291,
14,
7069,
779,
1196,
467,
6484,
63,
3643,
59,
17,
566,
272,
291,
14,
7069,
779,
18,
12,
841,
467,
6484,
63,
3643,
59,
18,
566,
272,
291,
14,
7069,
779,
1355,
467,
6484,
63,
3643,
59,
19,
566,
272,
327,
11388,
666,
1324,
370,
21907,
13068,
2058,
315,
272,
327,
658,
1507,
63,
12553,
64,
11102,
402,
5809,
2582,
14,
272,
291,
14,
629,
779,
403,
467,
16394,
59,
16,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
272,
291,
14,
629,
779,
403,
467,
16394,
59,
17,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
272,
291,
14,
629,
779,
403,
467,
16394,
59,
18,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
272,
291,
14,
629,
779,
403,
467,
16394,
59,
19,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
819,
347,
511,
3184,
11467,
17905,
279,
8,
277,
304,
272,
543,
291,
14,
396,
63,
1730,
342,
465,
4043,
26,
489,
666,
275,
4413,
63,
411,
14,
4083,
4038,
16,
12,
413,
12,
499,
467,
359,
19,
12,
841,
12,
959,
467,
359,
22,
12,
1520,
12,
1695,
467,
359,
25,
12,
1616,
12,
4119,
467,
3521,
359,
713,
12,
4944,
12,
4329,
467,
359,
1046,
12,
3193,
12,
5557,
3934,
489,
4918,
275,
4413,
63,
411,
14,
4083,
779,
16,
12,
378,
12,
499,
12,
650,
12,
499,
12,
413,
566,
489,
16394,
275,
666,
63,
1659,
63,
1483,
14,
7764,
63,
5312,
8,
881,
666,
12,
4918,
12,
1967,
63,
12553,
29,
20,
9,
489,
6484,
63,
3643,
275,
4043,
14,
1065,
8,
12553,
9,
339,
291,
14,
7069,
4038,
16,
12,
413,
12,
499,
467,
359,
19,
12,
841,
12,
959,
2365,
6484,
63,
3643,
59,
16,
566,
272,
291,
14,
7069,
4038,
1046,
12,
3193,
12,
5557,
2365,
6484,
63,
3643,
59,
17,
566,
272,
291,
14,
7069,
4038,
22,
12,
1520,
12,
1695,
467,
359,
713,
12,
4944,
12,
4329,
2365,
6484,
63,
3643,
59,
18,
566,
272,
291,
14,
7069,
4038,
25,
12,
1616,
12,
4119,
2365,
6484,
63,
3643,
59,
19,
566,
272,
327,
11388,
666,
1324,
370,
21907,
13068,
2058,
315,
272,
327,
658,
1507,
63,
12553,
64,
12627,
543,
376,
5809,
1329,
402,
4730,
12,
436,
650,
4362,
14,
272,
291,
14,
629,
779,
403,
12,
650,
467,
16394,
59,
16,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
272,
291,
14,
629,
779,
403,
12,
650,
467,
16394,
59,
17,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
272,
291,
14,
629,
779,
403,
12,
650,
467,
16394,
59,
18,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
272,
291,
14,
629,
779,
403,
12,
650,
467,
16394,
59,
19,
1055,
362,
63,
1392,
1252,
305,
63,
513,
1012,
819,
347,
511,
11688,
281,
19486,
8,
277,
304,
272,
980,
14,
2355,
14,
5176,
8,
23,
9,
272,
543,
291,
14,
396,
63,
1730,
342,
465,
4043,
26,
489,
367,
302,
315,
499,
12,
650,
26,
267,
367,
2215,
315,
334,
20,
4706,
334,
20,
12,
959,
395,
334,
20,
12,
959,
12,
499,
304,
881,
16394,
275,
980,
14,
2355,
14,
8393,
8,
78,
12,
1568,
29,
1590,
14,
8788,
8,
1392,
4992,
5217,
8,
1392,
9,
881,
367,
2402,
63,
1392,
315,
11969,
334,
22,
4706,
334,
22,
12,
1520,
304,
288,
666,
275,
980,
14,
2355,
14,
10843,
29316,
1392,
435,
2402,
63,
1392,
430,
288,
16394,
63,
84,
275,
4413,
63,
411,
14,
4083,
8,
12553,
12,
2152,
29,
5717,
14,
442,
708,
9,
288,
666,
63,
84,
275,
4413,
63,
411,
14,
4083,
8,
576,
9,
288,
4704,
275,
666,
63,
1659,
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,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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
] |
wheever/AFProxy
|
PageFilter.py
|
1
|
1740
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
import logging
from Exceptions import *
from ListFile import parse_line_to_regex, ListFiles
from colorama import init, Fore, Back, Style
init(autoreset=True)
logger = logging.getLogger('__main__')
# Class method action() will be passed with the http request object,
# with below attributes:
#
# .url
# .
class PageFilter:
"Basic web page filter class"
active = False
# Default matching all urls
urls = ('*',)
string_subs = ()
regex_subs = ()
@classmethod
def init(cls):
pass
@classmethod
def urlMatched(cls, url):
for filter_url in cls.urls:
if re.match(parse_line_to_regex(filter_url),
url.split('//', maxsplit=1)[1]):
return True
@classmethod
def action(cls, req):
if cls.urlMatched(req.url):
page = req.data
for pattern, repl in cls.string_subs:
page = page.replace(pattern, repl)
for pattern, repl in cls.regex_subs:
page = re.sub(pattern, repl, page)
req.data = page
logger.info('PageFilter: [%s]' % cls.name)
class NoIframeJS(PageFilter):
name = "Remove All JS and Iframe"
active = True
urls = ('.badsite.org',
'andyou.net/.*\.jpe?g',
'gotyou.com/viewer\.php.*\.jpe?g')
regex_subs = ((br'(?si)<(script|iframe)\s+.*?</\1>', br'<!-- \1 removed by FILTER: no-js-iframe -->'),
)
class ImgDinoFix(PageFilter):
name = "imgdino.com img fix"
active = True
urls = ('imgdino.com/viewer\.php.*\.jpg',
'imgtiger.com/viewer\.php.*\.jpg')
string_subs = ((b'-250px 0 0 285px', b''),)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
295,
199,
646,
2050,
199,
504,
24873,
492,
627,
199,
504,
3820,
1173,
492,
2198,
63,
604,
63,
475,
63,
3821,
12,
3820,
5535,
199,
199,
504,
3164,
14541,
492,
4205,
12,
21684,
12,
10257,
12,
19442,
199,
826,
8,
27082,
409,
29,
549,
9,
199,
199,
2921,
275,
2050,
14,
5572,
10714,
973,
13766,
199,
199,
3,
8089,
1083,
1595,
342,
911,
506,
3032,
543,
314,
1455,
1056,
909,
12,
199,
3,
543,
5084,
3004,
26,
199,
3,
199,
3,
1275,
633,
199,
3,
1275,
199,
533,
10331,
4131,
26,
272,
298,
6845,
3330,
2034,
2457,
1021,
2,
272,
4702,
275,
756,
272,
327,
3758,
4877,
1006,
8187,
272,
8187,
275,
661,
7693,
9,
272,
1059,
63,
9841,
275,
6248,
272,
5163,
63,
9841,
275,
6248,
339,
768,
3744,
272,
347,
4205,
8,
1886,
304,
267,
986,
339,
768,
3744,
272,
347,
1166,
4486,
379,
8,
1886,
12,
1166,
304,
267,
367,
2457,
63,
633,
315,
843,
14,
3603,
26,
288,
340,
295,
14,
1431,
8,
1122,
63,
604,
63,
475,
63,
3821,
8,
1541,
63,
633,
395,
717,
1166,
14,
1294,
15079,
297,
1390,
1294,
29,
17,
2788,
17,
4682,
355,
372,
715,
339,
768,
3744,
272,
347,
1595,
8,
1886,
12,
2648,
304,
267,
340,
843,
14,
633,
4486,
379,
8,
2103,
14,
633,
304,
288,
2034,
275,
2648,
14,
576,
288,
367,
3851,
12,
20265,
315,
843,
14,
875,
63,
9841,
26,
355,
2034,
275,
2034,
14,
1814,
8,
3401,
12,
20265,
9,
288,
367,
3851,
12,
20265,
315,
843,
14,
3821,
63,
9841,
26,
355,
2034,
275,
295,
14,
954,
8,
3401,
12,
20265,
12,
2034,
9,
288,
2648,
14,
576,
275,
2034,
288,
2512,
14,
815,
360,
3276,
4131,
26,
8978,
83,
6616,
450,
843,
14,
354,
9,
199,
199,
533,
3091,
41,
1943,
11378,
8,
3276,
4131,
304,
272,
536,
275,
298,
5587,
2900,
18001,
436,
982,
1186,
2,
272,
4702,
275,
715,
272,
8187,
275,
23500,
4087,
2124,
14,
1308,
297,
1779,
283,
460,
13297,
14,
846,
15,
24736,
74,
321,
31,
71,
297,
1779,
283,
7808,
13297,
14,
957,
15,
16645,
4537,
8624,
24736,
74,
321,
31,
71,
358,
272,
5163,
63,
9841,
275,
3666,
3289,
10120,
338,
21528,
8,
1579,
92,
20052,
2862,
83,
11,
6697,
1108,
60,
17,
4206,
11665,
7601,
17722,
971,
17,
4829,
701,
23244,
26,
949,
13,
3596,
13,
20052,
10541,
659,
2116,
776,
199,
199,
533,
473,
6649,
36,
10175,
11985,
8,
3276,
4131,
304,
272,
536,
275,
298,
4060,
68,
10175,
14,
957,
6050,
5325,
2,
272,
4702,
275,
715,
272,
8187,
275,
661,
4060,
68,
10175,
14,
957,
15,
16645,
4537,
8624,
24736,
8476,
297,
1779,
283,
4060,
280,
836,
14,
957,
15,
16645,
4537,
8624,
24736,
8476,
358,
272,
1059,
63,
9841,
275,
3666,
66,
12418,
7991,
5326,
378,
378,
499,
2426,
5326,
297,
330,
7,
659,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
295,
199,
646,
2050,
199,
504,
24873,
492,
627,
199,
504,
3820,
1173,
492,
2198,
63,
604,
63,
475,
63,
3821,
12,
3820,
5535,
199,
199,
504,
3164,
14541,
492,
4205,
12,
21684,
12,
10257,
12,
19442,
199,
826,
8,
27082,
409,
29,
549,
9,
199,
199,
2921,
275,
2050,
14,
5572,
10714,
973,
13766,
199,
199,
3,
8089,
1083,
1595,
342,
911,
506,
3032,
543,
314,
1455,
1056,
909,
12,
199,
3,
543,
5084,
3004,
26,
199,
3,
199,
3,
1275,
633,
199,
3,
1275,
199,
533,
10331,
4131,
26,
272,
298,
6845,
3330,
2034,
2457,
1021,
2,
272,
4702,
275,
756,
272,
327,
3758,
4877,
1006,
8187,
272,
8187,
275,
661,
7693,
9,
272,
1059,
63,
9841,
275,
6248,
272,
5163,
63,
9841,
275,
6248,
339,
768,
3744,
272,
347,
4205,
8,
1886,
304,
267,
986,
339,
768,
3744,
272,
347,
1166,
4486,
379,
8,
1886,
12,
1166,
304,
267,
367,
2457,
63,
633,
315,
843,
14,
3603,
26,
288,
340,
295,
14,
1431,
8,
1122,
63,
604,
63,
475,
63,
3821,
8,
1541,
63,
633,
395,
717,
1166,
14,
1294,
15079,
297,
1390,
1294,
29,
17,
2788,
17,
4682,
355,
372,
715,
339,
768,
3744,
272,
347,
1595,
8,
1886,
12,
2648,
304,
267,
340,
843,
14,
633,
4486,
379,
8,
2103,
14,
633,
304,
288,
2034,
275,
2648,
14,
576,
288,
367,
3851,
12,
20265,
315,
843,
14,
875,
63,
9841,
26,
355,
2034,
275,
2034,
14,
1814,
8,
3401,
12,
20265,
9,
288,
367,
3851,
12,
20265,
315,
843,
14,
3821,
63,
9841,
26,
355,
2034,
275,
295,
14,
954,
8,
3401,
12,
20265,
12,
2034,
9,
288,
2648,
14,
576,
275,
2034,
288,
2512,
14,
815,
360,
3276,
4131,
26,
8978,
83,
6616,
450,
843,
14,
354,
9,
199,
199,
533,
3091,
41,
1943,
11378,
8,
3276,
4131,
304,
272,
536,
275,
298,
5587,
2900,
18001,
436,
982,
1186,
2,
272,
4702,
275,
715,
272,
8187,
275,
23500,
4087,
2124,
14,
1308,
297,
1779,
283,
460,
13297,
14,
846,
15,
24736,
74,
321,
31,
71,
297,
1779,
283,
7808,
13297,
14,
957,
15,
16645,
4537,
8624,
24736,
74,
321,
31,
71,
358,
272,
5163,
63,
9841,
275,
3666,
3289,
10120,
338,
21528,
8,
1579,
92,
20052,
2862,
83,
11,
6697,
1108,
60,
17,
4206,
11665,
7601,
17722,
971,
17,
4829,
701,
23244,
26,
949,
13,
3596,
13,
20052,
10541,
659,
2116,
776,
199,
199,
533,
473,
6649,
36,
10175,
11985,
8,
3276,
4131,
304,
272,
536,
275,
298,
4060,
68,
10175,
14,
957,
6050,
5325,
2,
272,
4702,
275,
715,
272,
8187,
275,
661,
4060,
68,
10175,
14,
957,
15,
16645,
4537,
8624,
24736,
8476,
297,
1779,
283,
4060,
280,
836,
14,
957,
15,
16645,
4537,
8624,
24736,
8476,
358,
272,
1059,
63,
9841,
275,
3666,
66,
12418,
7991,
5326,
378,
378,
499,
2426,
5326,
297,
330,
7,
659,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
adrianmoisey/github3.py
|
tests/unit/test_repos_repo.py
|
3
|
5882
|
from github3.repos.repo import Repository
from .helper import UnitHelper
class TestRepository(UnitHelper):
described_class = Repository
example_data = {
"id": 1296269,
"owner": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"name": "Hello-World",
"full_name": "octocat/Hello-World",
"description": "This your first repo!",
"private": False,
"fork": False,
"url": "https://api.github.com/repos/octocat/Hello-World",
"html_url": "https://github.com/octocat/Hello-World",
"clone_url": "https://github.com/octocat/Hello-World.git",
"git_url": "git://github.com/octocat/Hello-World.git",
"ssh_url": "git@github.com:octocat/Hello-World.git",
"svn_url": "https://svn.github.com/octocat/Hello-World",
"mirror_url": "git://git.example.com/octocat/Hello-World",
"homepage": "https://github.com",
"language": None,
"forks": 9,
"forks_count": 9,
"watchers": 80,
"watchers_count": 80,
"size": 108,
"master_branch": "master",
"open_issues": 0,
"open_issues_count": 0,
"pushed_at": "2011-01-26T19:06:43Z",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:14:43Z",
"organization": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat",
"type": "Organization"
},
"parent": {
"id": 1296269,
"owner": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"name": "Hello-World",
"full_name": "octocat/Hello-World",
"description": "This your first repo!",
"private": False,
"fork": True,
"url": "https://api.github.com/repos/octocat/Hello-World",
"html_url": "https://github.com/octocat/Hello-World",
"clone_url": "https://github.com/octocat/Hello-World.git",
"git_url": "git://github.com/octocat/Hello-World.git",
"ssh_url": "git@github.com:octocat/Hello-World.git",
"svn_url": "https://svn.github.com/octocat/Hello-World",
"mirror_url": "git://git.example.com/octocat/Hello-World",
"homepage": "https://github.com",
"language": None,
"forks": 9,
"forks_count": 9,
"watchers": 80,
"watchers_count": 80,
"size": 108,
"master_branch": "master",
"open_issues": 0,
"open_issues_count": 0,
"pushed_at": "2011-01-26T19:06:43Z",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:14:43Z"
},
"source": {
"id": 1296269,
"owner": {
"login": "octocat",
"id": 1,
"avatar_url": "https://github.com/images/error/octocat.gif",
"gravatar_id": "somehexcode",
"url": "https://api.github.com/users/octocat"
},
"name": "Hello-World",
"full_name": "octocat/Hello-World",
"description": "This your first repo!",
"private": False,
"fork": True,
"url": "https://api.github.com/repos/octocat/Hello-World",
"html_url": "https://github.com/octocat/Hello-World",
"clone_url": "https://github.com/octocat/Hello-World.git",
"git_url": "git://github.com/octocat/Hello-World.git",
"ssh_url": "git@github.com:octocat/Hello-World.git",
"svn_url": "https://svn.github.com/octocat/Hello-World",
"mirror_url": "git://git.example.com/octocat/Hello-World",
"homepage": "https://github.com",
"language": None,
"forks": 9,
"forks_count": 9,
"watchers": 80,
"watchers_count": 80,
"size": 108,
"master_branch": "master",
"open_issues": 0,
"open_issues_count": 0,
"pushed_at": "2011-01-26T19:06:43Z",
"created_at": "2011-01-26T19:01:12Z",
"updated_at": "2011-01-26T19:14:43Z"
},
"has_issues": True,
"has_wiki": True,
"has_downloads": True
}
def test_asset(self):
"""Test retrieving an asset uses the right headers
The Releases section of the API is still in Beta and uses custom
headers
"""
assert self.instance.asset(0) is None
assert self.session.get.call_count == 0
self.instance.asset(1)
url = self.example_data['url'] + '/releases/assets/1'
self.session.get.assert_called_once_with(
url, headers={'Accept': 'application/vnd.github.manifold-preview'}
)
def test_latest_pages_build(self):
"""Test retrieving the most recent pages build."""
url = self.example_data['url'] + '/pages/builds/latest'
self.instance.latest_pages_build()
self.session.get.assert_called_once_with(url)
def test_pages(self):
"""Test retrieving information about a repository's page."""
url = self.example_data['url'] + '/pages'
self.instance.pages()
self.session.get.assert_called_once_with(url)
|
bsd-3-clause
|
[
504,
12869,
19,
14,
11857,
14,
3417,
492,
24426,
199,
199,
504,
1275,
3676,
492,
12008,
4433,
421,
199,
533,
1379,
15614,
8,
5072,
4433,
304,
272,
11736,
63,
533,
275,
24426,
272,
2893,
63,
576,
275,
469,
267,
298,
344,
582,
413,
11700,
12442,
12,
267,
298,
4597,
582,
469,
288,
298,
2886,
582,
298,
15560,
679,
292,
401,
288,
298,
344,
582,
413,
12,
288,
298,
14584,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
4782,
15,
705,
15,
15560,
679,
292,
63,
72,
18869,
14,
14513,
401,
288,
298,
926,
28694,
63,
344,
582,
298,
3972,
4097,
600,
401,
288,
298,
633,
582,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
3707,
15,
15560,
679,
292,
2,
288,
1660,
267,
298,
354,
582,
298,
6257,
13,
15943,
401,
267,
298,
2861,
63,
354,
582,
298,
15560,
679,
292,
15,
6257,
13,
15943,
401,
267,
298,
1802,
582,
298,
2765,
2195,
1642,
3831,
17716,
267,
298,
4239,
582,
756,
12,
267,
298,
11796,
582,
756,
12,
267,
298,
633,
582,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
267,
298,
1360,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
267,
298,
6311,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
14,
3187,
401,
267,
298,
3187,
63,
633,
582,
298,
3187,
921,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
14,
3187,
401,
267,
298,
5510,
63,
633,
582,
298,
3187,
32,
5031,
14,
957,
26,
15560,
679,
292,
15,
6257,
13,
15943,
14,
3187,
401,
267,
298,
6836,
63,
633,
582,
298,
2859,
921,
6836,
14,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
267,
298,
12324,
63,
633,
582,
298,
3187,
921,
3187,
14,
2694,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
267,
298,
25539,
582,
298,
2859,
921,
5031,
14,
957,
401,
267,
298,
3671,
582,
488,
12,
267,
298,
509,
6080,
582,
1749,
12,
267,
298,
509,
6080,
63,
835,
582,
1749,
12,
267,
298,
6821,
1192,
582,
5939,
12,
267,
298,
6821,
1192,
63,
835,
582,
5939,
12,
267,
298,
890,
582,
24579,
12,
267,
298,
4133,
63,
4694,
582,
298,
4133,
401,
267,
298,
1490,
63,
10115,
582,
378,
12,
267,
298,
1490,
63,
10115,
63,
835,
582,
378,
12,
267,
298,
5335,
379,
63,
292,
582,
298,
8128,
13,
614,
13,
1479,
52,
1167,
26,
1690,
26,
2824,
58,
401,
267,
298,
3966,
63,
292,
582,
298,
8128,
13,
614,
13,
1479,
52,
1167,
26,
614,
26,
713,
58,
401,
267,
298,
5334,
63,
292,
582,
298,
8128,
13,
614,
13,
1479,
52,
1167,
26,
1079,
26,
2824,
58,
401,
267,
298,
9071,
582,
469,
288,
298,
2886,
582,
298,
15560,
679,
292,
401,
288,
298,
344,
582,
413,
12,
288,
298,
14584,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
4782,
15,
705,
15,
15560,
679,
292,
63,
72,
18869,
14,
14513,
401,
288,
298,
926,
28694,
63,
344,
582,
298,
3972,
4097,
600,
401,
288,
298,
633,
582,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
3707,
15,
15560,
679,
292,
401,
288,
298,
466,
582,
298,
15928,
2,
288,
1660,
267,
298,
1708,
582,
469,
288,
298,
344,
582,
413,
11700,
12442,
12,
288,
298,
4597,
582,
469,
355,
298,
2886,
582,
298,
15560,
679,
292,
401,
355,
298,
344,
582,
413,
12,
355,
298,
14584,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
4782,
15,
705,
15,
15560,
679,
292,
14,
14513,
401,
355,
298,
926,
28694,
63,
344,
582,
298,
3972,
4097,
600,
401,
355,
298,
633,
582,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
3707,
15,
15560,
679,
292,
2,
355,
1660,
288,
298,
354,
582,
298,
6257,
13,
15943,
401,
288,
298,
2861,
63,
354,
582,
298,
15560,
679,
292,
15,
6257,
13,
15943,
401,
288,
298,
1802,
582,
298,
2765,
2195,
1642,
3831,
17716,
288,
298,
4239,
582,
756,
12,
288,
298,
11796,
582,
715,
12,
288,
298,
633,
582,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
288,
298,
1360,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
288,
298,
6311,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
14,
3187,
401,
288,
298,
3187,
63,
633,
582,
298,
3187,
921,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
14,
3187,
401,
288,
298,
5510,
63,
633,
582,
298,
3187,
32,
5031,
14,
957,
26,
15560,
679,
292,
15,
6257,
13,
15943,
14,
3187,
401,
288,
298,
6836,
63,
633,
582,
298,
2859,
921,
6836,
14,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
288,
298,
12324,
63,
633,
582,
298,
3187,
921,
3187,
14,
2694,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
288,
298,
25539,
582,
298,
2859,
921,
5031,
14,
957,
401,
288,
298,
3671,
582,
488,
12,
288,
298,
509,
6080,
582,
1749,
12,
288,
298,
509,
6080,
63,
835,
582,
1749,
12,
288,
298,
6821,
1192,
582,
5939,
12,
288,
298,
6821,
1192,
63,
835,
582,
5939,
12,
288,
298,
890,
582,
24579,
12,
288,
298,
4133,
63,
4694,
582,
298,
4133,
401,
288,
298,
1490,
63,
10115,
582,
378,
12,
288,
298,
1490,
63,
10115,
63,
835,
582,
378,
12,
288,
298,
5335,
379,
63,
292,
582,
298,
8128,
13,
614,
13,
1479,
52,
1167,
26,
1690,
26,
2824,
58,
401,
288,
298,
3966,
63,
292,
582,
298,
8128,
13,
614,
13,
1479,
52,
1167,
26,
614,
26,
713,
58,
401,
288,
298,
5334,
63,
292,
582,
298,
8128,
13,
614,
13,
1479,
52,
1167,
26,
1079,
26,
2824,
58,
2,
288,
1660,
267,
298,
1365,
582,
469,
288,
298,
344,
582,
413,
11700,
12442,
12,
288,
298,
4597,
582,
469,
355,
298,
2886,
582,
298,
15560,
679,
292
] |
[
12869,
19,
14,
11857,
14,
3417,
492,
24426,
199,
199,
504,
1275,
3676,
492,
12008,
4433,
421,
199,
533,
1379,
15614,
8,
5072,
4433,
304,
272,
11736,
63,
533,
275,
24426,
272,
2893,
63,
576,
275,
469,
267,
298,
344,
582,
413,
11700,
12442,
12,
267,
298,
4597,
582,
469,
288,
298,
2886,
582,
298,
15560,
679,
292,
401,
288,
298,
344,
582,
413,
12,
288,
298,
14584,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
4782,
15,
705,
15,
15560,
679,
292,
63,
72,
18869,
14,
14513,
401,
288,
298,
926,
28694,
63,
344,
582,
298,
3972,
4097,
600,
401,
288,
298,
633,
582,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
3707,
15,
15560,
679,
292,
2,
288,
1660,
267,
298,
354,
582,
298,
6257,
13,
15943,
401,
267,
298,
2861,
63,
354,
582,
298,
15560,
679,
292,
15,
6257,
13,
15943,
401,
267,
298,
1802,
582,
298,
2765,
2195,
1642,
3831,
17716,
267,
298,
4239,
582,
756,
12,
267,
298,
11796,
582,
756,
12,
267,
298,
633,
582,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
267,
298,
1360,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
267,
298,
6311,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
14,
3187,
401,
267,
298,
3187,
63,
633,
582,
298,
3187,
921,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
14,
3187,
401,
267,
298,
5510,
63,
633,
582,
298,
3187,
32,
5031,
14,
957,
26,
15560,
679,
292,
15,
6257,
13,
15943,
14,
3187,
401,
267,
298,
6836,
63,
633,
582,
298,
2859,
921,
6836,
14,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
267,
298,
12324,
63,
633,
582,
298,
3187,
921,
3187,
14,
2694,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
267,
298,
25539,
582,
298,
2859,
921,
5031,
14,
957,
401,
267,
298,
3671,
582,
488,
12,
267,
298,
509,
6080,
582,
1749,
12,
267,
298,
509,
6080,
63,
835,
582,
1749,
12,
267,
298,
6821,
1192,
582,
5939,
12,
267,
298,
6821,
1192,
63,
835,
582,
5939,
12,
267,
298,
890,
582,
24579,
12,
267,
298,
4133,
63,
4694,
582,
298,
4133,
401,
267,
298,
1490,
63,
10115,
582,
378,
12,
267,
298,
1490,
63,
10115,
63,
835,
582,
378,
12,
267,
298,
5335,
379,
63,
292,
582,
298,
8128,
13,
614,
13,
1479,
52,
1167,
26,
1690,
26,
2824,
58,
401,
267,
298,
3966,
63,
292,
582,
298,
8128,
13,
614,
13,
1479,
52,
1167,
26,
614,
26,
713,
58,
401,
267,
298,
5334,
63,
292,
582,
298,
8128,
13,
614,
13,
1479,
52,
1167,
26,
1079,
26,
2824,
58,
401,
267,
298,
9071,
582,
469,
288,
298,
2886,
582,
298,
15560,
679,
292,
401,
288,
298,
344,
582,
413,
12,
288,
298,
14584,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
4782,
15,
705,
15,
15560,
679,
292,
63,
72,
18869,
14,
14513,
401,
288,
298,
926,
28694,
63,
344,
582,
298,
3972,
4097,
600,
401,
288,
298,
633,
582,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
3707,
15,
15560,
679,
292,
401,
288,
298,
466,
582,
298,
15928,
2,
288,
1660,
267,
298,
1708,
582,
469,
288,
298,
344,
582,
413,
11700,
12442,
12,
288,
298,
4597,
582,
469,
355,
298,
2886,
582,
298,
15560,
679,
292,
401,
355,
298,
344,
582,
413,
12,
355,
298,
14584,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
4782,
15,
705,
15,
15560,
679,
292,
14,
14513,
401,
355,
298,
926,
28694,
63,
344,
582,
298,
3972,
4097,
600,
401,
355,
298,
633,
582,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
3707,
15,
15560,
679,
292,
2,
355,
1660,
288,
298,
354,
582,
298,
6257,
13,
15943,
401,
288,
298,
2861,
63,
354,
582,
298,
15560,
679,
292,
15,
6257,
13,
15943,
401,
288,
298,
1802,
582,
298,
2765,
2195,
1642,
3831,
17716,
288,
298,
4239,
582,
756,
12,
288,
298,
11796,
582,
715,
12,
288,
298,
633,
582,
298,
2859,
921,
1246,
14,
5031,
14,
957,
15,
11857,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
288,
298,
1360,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
288,
298,
6311,
63,
633,
582,
298,
2859,
921,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
14,
3187,
401,
288,
298,
3187,
63,
633,
582,
298,
3187,
921,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
14,
3187,
401,
288,
298,
5510,
63,
633,
582,
298,
3187,
32,
5031,
14,
957,
26,
15560,
679,
292,
15,
6257,
13,
15943,
14,
3187,
401,
288,
298,
6836,
63,
633,
582,
298,
2859,
921,
6836,
14,
5031,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
288,
298,
12324,
63,
633,
582,
298,
3187,
921,
3187,
14,
2694,
14,
957,
15,
15560,
679,
292,
15,
6257,
13,
15943,
401,
288,
298,
25539,
582,
298,
2859,
921,
5031,
14,
957,
401,
288,
298,
3671,
582,
488,
12,
288,
298,
509,
6080,
582,
1749,
12,
288,
298,
509,
6080,
63,
835,
582,
1749,
12,
288,
298,
6821,
1192,
582,
5939,
12,
288,
298,
6821,
1192,
63,
835,
582,
5939,
12,
288,
298,
890,
582,
24579,
12,
288,
298,
4133,
63,
4694,
582,
298,
4133,
401,
288,
298,
1490,
63,
10115,
582,
378,
12,
288,
298,
1490,
63,
10115,
63,
835,
582,
378,
12,
288,
298,
5335,
379,
63,
292,
582,
298,
8128,
13,
614,
13,
1479,
52,
1167,
26,
1690,
26,
2824,
58,
401,
288,
298,
3966,
63,
292,
582,
298,
8128,
13,
614,
13,
1479,
52,
1167,
26,
614,
26,
713,
58,
401,
288,
298,
5334,
63,
292,
582,
298,
8128,
13,
614,
13,
1479,
52,
1167,
26,
1079,
26,
2824,
58,
2,
288,
1660,
267,
298,
1365,
582,
469,
288,
298,
344,
582,
413,
11700,
12442,
12,
288,
298,
4597,
582,
469,
355,
298,
2886,
582,
298,
15560,
679,
292,
0
] |
[
1,
1,
1,
1,
1,
1,
1,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m8992
|
tools/perf/scripts/python/syscall-counts.py
|
11181
|
1522
|
# system call counts
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Displays system-wide system call totals, broken down by syscall.
# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
from Util import syscall_name
usage = "perf script -s syscall-counts.py [comm]\n";
for_comm = None
if len(sys.argv) > 2:
sys.exit(usage)
if len(sys.argv) > 1:
for_comm = sys.argv[1]
syscalls = autodict()
def trace_begin():
print "Press control+C to stop and show the summary"
def trace_end():
print_syscall_totals()
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, args):
if for_comm is not None:
if common_comm != for_comm:
return
try:
syscalls[id] += 1
except TypeError:
syscalls[id] = 1
def print_syscall_totals():
if for_comm is not None:
print "\nsyscall events for %s:\n\n" % (for_comm),
else:
print "\nsyscall events:\n\n",
print "%-40s %10s\n" % ("event", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"-----------"),
for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
reverse = True):
print "%-40s %10d\n" % (syscall_name(id), val),
|
gpl-2.0
|
[
3,
2656,
1240,
8242,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
1871,
221,
3837,
275,
715,
304,
6722,
870,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2656,
1240,
8242,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
504,
21248,
492,
18901,
63,
354,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1361,
298,
14414,
3304,
11,
35,
370,
3631,
436,
2498,
314,
6212,
2,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
1871,
221,
3837,
275,
715,
304,
6722,
870,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
levibostian/myBlanky
|
googleAppEngine/google/appengine/api/search/expression_parser.py
|
15
|
2287
|
#!/usr/bin/env python
#
# Copyright 2007 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
"""Wrapper for ExpressionParser."""
from google.appengine._internal import antlr3
from google.appengine.api.search import ExpressionLexer
from google.appengine.api.search import ExpressionParser
class ExpressionException(Exception):
"""An error occurred while parsing the expression input string."""
class ExpressionLexerWithErrors(ExpressionLexer.ExpressionLexer):
"""An overridden Lexer that raises exceptions."""
def emitErrorMessage(self, msg):
"""Raise an exception if the input fails to parse correctly.
Overriding the default, which normally just prints a message to
stderr.
Arguments:
msg: the error message
Raises:
ExpressionException: always.
"""
raise ExpressionException(msg)
class ExpressionParserWithErrors(ExpressionParser.ExpressionParser):
"""An overridden Parser that raises exceptions."""
def emitErrorMessage(self, msg):
"""Raise an exception if the input fails to parse correctly.
Overriding the default, which normally just prints a message to
stderr.
Arguments:
msg: the error message
Raises:
ExpressionException: always.
"""
raise ExpressionException(msg)
def CreateParser(expression):
"""Creates a Expression Parser."""
input_string = antlr3.ANTLRStringStream(expression)
lexer = ExpressionLexerWithErrors(input_string)
tokens = antlr3.CommonTokenStream(lexer)
parser = ExpressionParserWithErrors(tokens)
return parser
def Parse(expression):
"""Parses an expression and returns the ANTLR tree."""
parser = CreateParser(expression)
try:
return parser.expression()
except Exception, e:
raise ExpressionException(e.message)
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
6905,
199,
624,
4590,
367,
22013,
2842,
1041,
421,
199,
504,
6233,
14,
15358,
423,
4672,
492,
27384,
7493,
19,
199,
504,
6233,
14,
15358,
14,
1246,
14,
1733,
492,
22013,
5838,
199,
504,
6233,
14,
15358,
14,
1246,
14,
1733,
492,
22013,
2842,
421,
199,
533,
22013,
1726,
8,
1726,
304,
523,
408,
2493,
1125,
8920,
1830,
6057,
314,
3965,
1324,
1059,
1041,
421,
199,
533,
22013,
5838,
3007,
9298,
8,
9093,
5838,
14,
9093,
5838,
304,
523,
408,
2493,
10087,
21125,
626,
6534,
4967,
1041,
819,
347,
8689,
547,
2209,
8,
277,
12,
1499,
304,
272,
408,
18111,
376,
1919,
340,
314,
1324,
6918,
370,
2198,
6657,
14,
339,
7259,
15526,
314,
849,
12,
1314,
12252,
2951,
14767,
282,
1245,
370,
272,
4635,
14,
339,
7628,
26,
489,
1499,
26,
314,
1125,
1245,
272,
6218,
26,
489,
22013,
1726,
26,
3544,
14,
272,
408,
272,
746,
22013,
1726,
8,
1328,
9,
421,
199,
533,
22013,
2842,
3007,
9298,
8,
9093,
2842,
14,
9093,
2842,
304,
523,
408,
2493,
10087,
10191,
626,
6534,
4967,
1041,
819,
347,
8689,
547,
2209,
8,
277,
12,
1499,
304,
272,
408,
18111,
376,
1919,
340,
314,
1324,
6918,
370,
2198,
6657,
14,
339,
7259,
15526,
314,
849,
12,
1314,
12252,
2951,
14767,
282,
1245,
370,
272,
4635,
14,
339,
7628,
26,
489,
1499,
26,
314,
1125,
1245,
272,
6218,
26,
489,
22013,
1726,
26,
3544,
14,
272,
408,
272,
746,
22013,
1726,
8,
1328,
9,
421,
199,
318,
2790,
2842,
8,
5599,
304,
523,
408,
10607,
282,
22013,
10191,
1041,
523,
1324,
63,
875,
275,
27384,
7493,
19,
14,
1441,
17665,
1558,
3296,
8,
5599,
9,
523,
10426,
275,
22013,
5838,
3007,
9298,
8,
1210,
63,
875,
9,
523,
4645,
275,
27384,
7493,
19,
14,
7844,
3264,
3296,
8,
11729,
9,
523,
1798,
275,
22013,
2842,
3007,
9298,
8,
4504,
9,
523,
372,
1798,
421,
199,
318,
6077,
8,
5599,
304,
523,
408,
23400,
376,
3965,
436,
2529,
314,
1261,
7308,
50,
3123,
1041,
523,
1798,
275,
2790,
2842,
8,
5599,
9,
523,
862,
26,
272,
372,
1798,
14,
5599,
342,
523,
871,
2186,
12,
325,
26,
272,
746,
22013,
1726,
8,
69,
14,
1188,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
10219,
4475,
3277,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
6905,
199,
624,
4590,
367,
22013,
2842,
1041,
421,
199,
504,
6233,
14,
15358,
423,
4672,
492,
27384,
7493,
19,
199,
504,
6233,
14,
15358,
14,
1246,
14,
1733,
492,
22013,
5838,
199,
504,
6233,
14,
15358,
14,
1246,
14,
1733,
492,
22013,
2842,
421,
199,
533,
22013,
1726,
8,
1726,
304,
523,
408,
2493,
1125,
8920,
1830,
6057,
314,
3965,
1324,
1059,
1041,
421,
199,
533,
22013,
5838,
3007,
9298,
8,
9093,
5838,
14,
9093,
5838,
304,
523,
408,
2493,
10087,
21125,
626,
6534,
4967,
1041,
819,
347,
8689,
547,
2209,
8,
277,
12,
1499,
304,
272,
408,
18111,
376,
1919,
340,
314,
1324,
6918,
370,
2198,
6657,
14,
339,
7259,
15526,
314,
849,
12,
1314,
12252,
2951,
14767,
282,
1245,
370,
272,
4635,
14,
339,
7628,
26,
489,
1499,
26,
314,
1125,
1245,
272,
6218,
26,
489,
22013,
1726,
26,
3544,
14,
272,
408,
272,
746,
22013,
1726,
8,
1328,
9,
421,
199,
533,
22013,
2842,
3007,
9298,
8,
9093,
2842,
14,
9093,
2842,
304,
523,
408,
2493,
10087,
10191,
626,
6534,
4967,
1041,
819,
347,
8689,
547,
2209,
8,
277,
12,
1499,
304,
272,
408,
18111,
376,
1919,
340,
314,
1324,
6918,
370,
2198,
6657,
14,
339,
7259,
15526,
314,
849,
12,
1314,
12252,
2951,
14767,
282,
1245,
370,
272,
4635,
14,
339,
7628,
26,
489,
1499,
26,
314,
1125,
1245,
272,
6218,
26,
489,
22013,
1726,
26,
3544,
14,
272,
408,
272,
746,
22013,
1726,
8,
1328,
9,
421,
199,
318,
2790,
2842,
8,
5599,
304,
523,
408,
10607,
282,
22013,
10191,
1041,
523,
1324,
63,
875,
275,
27384,
7493,
19,
14,
1441,
17665,
1558,
3296,
8,
5599,
9,
523,
10426,
275,
22013,
5838,
3007,
9298,
8,
1210,
63,
875,
9,
523,
4645,
275,
27384,
7493,
19,
14,
7844,
3264,
3296,
8,
11729,
9,
523,
1798,
275,
22013,
2842,
3007,
9298,
8,
4504,
9,
523,
372,
1798,
421,
199,
318,
6077,
8,
5599,
304,
523,
408,
23400,
376,
3965,
436,
2529,
314,
1261,
7308,
50,
3123,
1041,
523,
1798,
275,
2790,
2842,
8,
5599,
9,
523,
862,
26,
272,
372,
1798,
14,
5599,
342,
523,
871,
2186,
12,
325,
26,
272,
746,
22013,
1726,
8,
69,
14,
1188,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
sowe9385/qiime
|
scripts/estimate_observation_richness.py
|
15
|
7487
|
#!/usr/bin/env python
from __future__ import division
__author__ = "Jai Ram Rideout"
__copyright__ = "Copyright 2013, The QIIME Project"
__credits__ = ["Jai Ram Rideout"]
__license__ = "GPL"
__version__ = "1.9.1-dev"
__maintainer__ = "Jai Ram Rideout"
__email__ = "jai.rideout@gmail.com"
from os.path import join
from biom import load_table
from skbio.util import create_dir
from qiime.util import (parse_command_line_parameters, get_options_lookup,
make_option)
from qiime.estimate_observation_richness import (
Chao1MultinomialPointEstimator,
ObservationRichnessEstimator)
options_lookup = get_options_lookup()
script_info = {}
script_info[
'brief_description'] = ("Estimates the observation (e.g., OTU) richness "
"of samples in a BIOM table")
script_info['script_description'] = """
This script provides estimates of the observation (e.g., OTU) richness (i.e.
number of observations) given a sampling depth (i.e. number of
individuals/sequences per sample). Estimators are provided for both
interpolation/rarefaction and extrapolation.
Interpolation/rarefaction applies when the richness is estimated for a
*smaller* number of individuals than the original number of individuals in that
sample. We refer to this original sampling depth as the "reference sampling
depth" or "reference sample size".
Extrapolation applies when the richness is estimated for a *larger* number of
individuals than the reference sample size.
This script currently only provides a single unified estimation model for
interpolation and extrapolation. This model is the individual-based multinomial
model, which uses Chao1 to estimate the full richness of the sample. Please
refer to Colwell et al. (2012) for more details; equations 4, 5, 9, 10, 15a,
and 15b are used in this script.
For each interpolation/extrapolation point, the estimate, its unconditional
standard error, and confidence interval are reported. The script currently only
outputs this information to a table, which can be easily viewed in a program
such as Excel. Other output formats, such as plots, may be added in the future.
If an estimate is reported as "N/A", not enough information was present to
compute an estimate. This can occur when extrapolating if a sample does not
contain any singletons or doubletons, or if there is exactly one singleton and
no doubletons. A singleton is defined as an observation with exactly one
individual/sequence in the sample. A doubleton is defined as an observation
with exactly two individuals/sequences in the sample.
IMPORTANT: If you use the results of this script in any published works, please
be sure to cite the Colwell et al. (2012) paper, as well as QIIME (see
http://qiime.org for details).
In addition to Colwell et al. (2012), the following resources were extremely
useful while implementing and testing these estimators, so it is appropriate to
also acknowledge them here:
- Hsieh et al. (2013)
- Shen et al. (2003)
- Colwell (2013)
References:
Chao, A., N. J. Gotelli, T. C. Hsieh, E. L. Sander, K. H. Ma, R. K. Colwell, and A. M. Ellison 2013. Rarefaction and extrapolation with Hill numbers: a unified framework for sampling and estimation in biodiversity studies, Ecological Monographs (under revision).
Colwell, R. K. 2013. EstimateS: Statistical estimation of species richness and shared species from samples. Version 9. User's Guide and application published at: http://purl.oclc.org/estimates.
Colwell, R. K., A. Chao, N. J. Gotelli, S. Y. Lin, C. X. Mao, R. L. Chazdon, and J. T. Longino. 2012. Models and estimators linking individual-based and sample-based rarefaction, extrapolation and comparison of assemblages. Journal of Plant Ecology 5:3-21.
Hsieh, T. C., K. H. Ma, and A. Chao. 2013. iNEXT online: interpolation and extrapolation (Version 1.0) [Software]. Available from http://chao.stat.nthu.edu.tw/inext/.
Shen T-J, Chao A, Lin C- F. Predicting the number of new species in further taxonomic sampling. Ecology 2003;84:798-804.
"""
script_info['script_usage'] = []
script_info['script_usage'].append((
"Interpolation and extrapolation of richness",
"Estimate the richness of each sample in the input BIOM table using the "
"default sampling depth range, which includes interpolation and "
"extrapolation.",
"%prog -i otu_table.biom -o estimates_out"))
script_info['output_description'] = """
A single file containing tabular data in TSV format is created in the output
directory. Other output formats may be added in the future.
"""
script_info['required_options'] = [
make_option('-i', '--otu_table_fp', type='existing_filepath',
help='path to the input BIOM table (e.g., the output from '
'make_otu_table.py). IMPORTANT: This table should contain '
'observation *counts* (integers), NOT relative abundances '
'(fractions)'),
options_lookup['output_dir']
]
script_info['optional_options'] = [
make_option('-m', '--min', type='int',
help='the number of individuals (e.g. sequences) per sample '
'to start performing estimations at [default: %default]',
default=1),
make_option('-x', '--max', type='int',
help='the number of individuals (e.g. sequences) per sample '
'to stop performing estimations at. By default, the base '
'sample size will be used, which is defined in Chao et al. '
'(2013) as "double the smallest reference sample size or the '
'maximum reference sample size, whichever is larger '
'[default: base sample size]', default=None),
make_option('-n', '--num_steps', type='int',
help='the number of steps to make between -m/--min and '
'-x/--max. Increasing this number will result in smoother '
'curves, but will also increase the amount of time needed to '
'run the script. Note that the reference sample size for each '
'sample will be included if it does not fall within the '
'min/max/num_steps range [default: %default]',
default=10),
make_option('-c', '--confidence_level', type='float',
help='the confidence level of the unconditional confidence '
'interval for each estimate. Must be a value between 0 and 1 '
'(exclusive). For example, a 95% unconditional confidence '
'interval would be 0.95 [default: %default]', default=0.95)
]
script_info['version'] = __version__
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
# Create the output dir if it doesn't already exist.
output_dir = opts.output_dir
try:
create_dir(output_dir)
except:
option_parser.error("Could not create or access output directory "
"specified with the -o/--output_dir option.")
otu_table_fp = opts.otu_table_fp
table = load_table(otu_table_fp)
estimator = ObservationRichnessEstimator(table,
Chao1MultinomialPointEstimator)
results = estimator(opts.min, opts.max, opts.num_steps,
opts.confidence_level)
out_fp = join(output_dir, 'estimates_table.txt')
with open(out_fp, 'w') as out_f:
results.toTable(out_f)
if __name__ == "__main__":
main()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
363,
2502,
363,
275,
298,
42,
5789,
820,
455,
820,
2655,
548,
2,
199,
363,
7307,
363,
275,
298,
7384,
6171,
12,
710,
1413,
41,
3465,
7290,
2,
199,
363,
22461,
363,
275,
2097,
42,
5789,
820,
455,
820,
2655,
548,
937,
199,
363,
1682,
363,
275,
298,
12006,
2,
199,
363,
1023,
363,
275,
298,
17,
14,
25,
14,
17,
13,
2374,
2,
199,
363,
26665,
363,
275,
298,
42,
5789,
820,
455,
820,
2655,
548,
2,
199,
363,
2123,
363,
275,
298,
3387,
73,
14,
2188,
548,
32,
6799,
14,
957,
2,
199,
199,
504,
747,
14,
515,
492,
4263,
199,
504,
12111,
676,
492,
2248,
63,
1224,
199,
504,
11448,
2308,
14,
1974,
492,
1218,
63,
694,
199,
504,
31402,
1036,
14,
1974,
492,
334,
1122,
63,
1531,
63,
604,
63,
3214,
12,
664,
63,
1419,
63,
3892,
12,
717,
1852,
63,
1422,
9,
199,
199,
504,
31402,
1036,
14,
21196,
63,
24299,
63,
10399,
4171,
492,
334,
272,
445,
2411,
79,
17,
30233,
16956,
3428,
13183,
12,
272,
17985,
8213,
50,
1158,
4171,
13183,
9,
199,
199,
1419,
63,
3892,
275,
664,
63,
1419,
63,
3892,
342,
199,
199,
1579,
63,
815,
275,
1052,
199,
1579,
63,
815,
59,
272,
283,
19127,
63,
1802,
418,
275,
1689,
9169,
18187,
314,
20038,
334,
69,
14,
71,
2020,
593,
21364,
9,
30162,
4171,
298,
1169,
298,
1618,
5845,
315,
282,
699,
2090,
45,
1817,
531,
199,
1579,
63,
815,
459,
1579,
63,
1802,
418,
275,
408,
199,
2765,
2884,
6571,
23505,
402,
314,
20038,
334,
69,
14,
71,
2020,
593,
21364,
9,
30162,
4171,
334,
73,
14,
69,
14,
199,
1955,
402,
19739,
9,
1627,
282,
15877,
5818,
334,
73,
14,
69,
14,
1329,
402,
199,
23001,
83,
15,
13436,
1126,
2690,
680,
15896,
9095,
787,
2741,
367,
3865,
199,
21080,
15,
345,
264,
17287,
436,
31964,
10410,
14,
199,
199,
32653,
15,
345,
264,
17287,
12966,
1380,
314,
30162,
4171,
365,
20077,
367,
282,
199,
10,
24460,
1435,
10,
1329,
402,
8212,
83,
2419,
314,
3379,
1329,
402,
8212,
83,
315,
626,
199,
3271,
14,
2136,
10618,
370,
642,
3379,
15877,
5818,
465,
314,
298,
4443,
15877,
199,
4631,
2,
503,
298,
4443,
2690,
1568,
1674,
199,
199,
4942,
1330,
10410,
12966,
1380,
314,
30162,
4171,
365,
20077,
367,
282,
627,
9828,
836,
10,
1329,
402,
199,
23001,
83,
2419,
314,
3659,
2690,
1568,
14,
199,
199,
2765,
2884,
5544,
1454,
6571,
282,
2849,
25344,
27156,
1402,
367,
199,
21080,
436,
31964,
10410,
14,
961,
1402,
365,
314,
8212,
13,
6788,
20861,
16956,
199,
1238,
12,
1314,
4440,
445,
2411,
79,
17,
370,
14497,
314,
2615,
30162,
4171,
402,
314,
2690,
14,
7754,
199,
21928,
370,
3626,
20501,
10844,
741,
14,
334,
7409,
9,
367,
1655,
2436,
27,
26426,
841,
12,
959,
12,
1749,
12,
1616,
12,
4114,
65,
12,
199,
460,
4114,
66,
787,
1202,
315,
642,
2884,
14,
199,
199,
1858,
1924,
14046,
15,
832,
1330,
10410,
2376,
12,
314,
14497,
12,
2399,
625,
14353,
199,
6807,
1125,
12,
436,
15197,
6252,
787,
14581,
14,
710,
2884,
5544,
1454,
199,
4467,
642,
2556,
370,
282,
1817,
12,
1314,
883,
506,
16174,
2455,
379,
315,
282,
2240,
199,
10180,
465,
27832,
14,
5439,
1072,
6752,
12,
4066,
465,
19695,
12,
1443,
506,
3483,
315,
314,
6466,
14,
199,
199,
3917,
376,
14497,
365,
14581,
465,
298,
46,
15,
33,
401,
440,
8321,
2556,
1990,
3451,
370,
199,
3357,
376,
14497,
14,
961,
883,
4781,
1380,
31964,
393,
1958,
340,
282,
2690,
1630,
440,
199,
7747,
1263,
19768,
83,
503,
4270,
1860,
83,
12,
503,
340,
2337,
365,
8840,
1373,
19768,
436,
199,
889,
4270,
1860,
83,
14,
437,
19768,
365,
3247,
465,
376,
20038,
543,
8840,
1373,
199,
23001,
15,
4041,
315,
314,
2690,
14,
437,
4270,
1860,
365,
3247,
465,
376,
20038,
199,
1045,
8840,
2877,
8212,
83,
15,
13436,
315,
314,
2690,
14,
199,
199,
17576,
1441,
26,
982,
1265,
675,
314,
2058,
402,
642,
2884,
315,
1263,
3267,
5419,
12,
8749,
199,
1235,
3238,
370,
286,
1175,
314,
3626,
20501,
10844,
741,
14,
334,
7409,
9,
15220,
12,
465,
5521,
465,
1413,
41,
3465,
334,
3239,
199,
1014,
921,
23104,
1036,
14,
1308,
367,
2436,
680,
199,
199,
607,
10234,
370,
3626,
20501,
10844,
741,
14,
334,
7409,
395,
314,
2569,
5944,
4898,
30503,
590,
199,
1180,
1893,
1830,
18234,
436,
5343,
3520,
23155,
12,
880,
652,
365,
5827,
370,
199,
12344,
19807,
23504,
3062,
2348,
26,
199,
199,
13,
869,
23994,
72,
10844,
741,
14,
334,
6965,
9,
199,
13,
5244,
287,
10844,
741,
14,
334,
17919,
9,
199,
13,
3626,
20501,
334,
6965,
9,
199,
199,
15242,
26,
199,
199,
1049,
8035,
12,
437,
2020,
653,
14,
1603,
14,
598,
1583,
13876,
12,
377,
14,
445,
14,
869,
23994,
72,
12,
662,
14,
491,
14,
428,
11438,
12,
1804,
14,
869,
14,
16593,
12,
820,
14,
1804,
14,
3626,
20501,
12,
436,
437,
14,
603,
14,
13096,
317,
834,
6171,
14,
820,
1530,
17287,
436,
31964,
10410,
543,
869,
778,
5579,
26,
282,
25344,
10059,
367,
15877,
436,
27156,
315,
28897,
328,
422,
3677,
410,
14525,
397,
12,
662,
331,
7954,
10953,
79,
16670,
334,
7138,
6974,
680,
199,
199,
2001,
20501,
12,
820,
14,
1804,
14,
6171,
14,
15896,
6897,
51,
26,
7083,
30364,
27156,
402,
20340,
30162,
4171,
436,
5709,
20340,
687,
5845,
14,
3394,
1749,
14,
2876,
1159,
15423,
436,
4223,
3267,
737,
26,
1455,
921,
80,
633,
14,
79,
23066,
14,
1308,
15,
597,
18187,
14,
199,
199,
2001,
20501,
12,
820,
14,
1804,
2020,
437,
14,
445,
2411,
79,
12,
653,
14,
1603,
14,
598,
1583,
13876,
12,
428,
14,
1488,
14,
29730,
12,
445,
14,
1323,
14,
603,
8035,
12,
820,
14,
491,
14,
445,
22133,
13196,
12,
436,
1603,
14,
377,
14,
491,
265,
903,
79,
14,
6029,
14,
29941,
436,
23155,
25833,
8212,
13,
6788,
436,
2690,
13,
6788,
24063,
17287,
12,
31964,
10410,
436,
9132,
402,
465,
8946,
416,
3389,
14,
22142,
402,
7497,
867,
662,
331,
4956,
959,
26
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
363,
2502,
363,
275,
298,
42,
5789,
820,
455,
820,
2655,
548,
2,
199,
363,
7307,
363,
275,
298,
7384,
6171,
12,
710,
1413,
41,
3465,
7290,
2,
199,
363,
22461,
363,
275,
2097,
42,
5789,
820,
455,
820,
2655,
548,
937,
199,
363,
1682,
363,
275,
298,
12006,
2,
199,
363,
1023,
363,
275,
298,
17,
14,
25,
14,
17,
13,
2374,
2,
199,
363,
26665,
363,
275,
298,
42,
5789,
820,
455,
820,
2655,
548,
2,
199,
363,
2123,
363,
275,
298,
3387,
73,
14,
2188,
548,
32,
6799,
14,
957,
2,
199,
199,
504,
747,
14,
515,
492,
4263,
199,
504,
12111,
676,
492,
2248,
63,
1224,
199,
504,
11448,
2308,
14,
1974,
492,
1218,
63,
694,
199,
504,
31402,
1036,
14,
1974,
492,
334,
1122,
63,
1531,
63,
604,
63,
3214,
12,
664,
63,
1419,
63,
3892,
12,
717,
1852,
63,
1422,
9,
199,
199,
504,
31402,
1036,
14,
21196,
63,
24299,
63,
10399,
4171,
492,
334,
272,
445,
2411,
79,
17,
30233,
16956,
3428,
13183,
12,
272,
17985,
8213,
50,
1158,
4171,
13183,
9,
199,
199,
1419,
63,
3892,
275,
664,
63,
1419,
63,
3892,
342,
199,
199,
1579,
63,
815,
275,
1052,
199,
1579,
63,
815,
59,
272,
283,
19127,
63,
1802,
418,
275,
1689,
9169,
18187,
314,
20038,
334,
69,
14,
71,
2020,
593,
21364,
9,
30162,
4171,
298,
1169,
298,
1618,
5845,
315,
282,
699,
2090,
45,
1817,
531,
199,
1579,
63,
815,
459,
1579,
63,
1802,
418,
275,
408,
199,
2765,
2884,
6571,
23505,
402,
314,
20038,
334,
69,
14,
71,
2020,
593,
21364,
9,
30162,
4171,
334,
73,
14,
69,
14,
199,
1955,
402,
19739,
9,
1627,
282,
15877,
5818,
334,
73,
14,
69,
14,
1329,
402,
199,
23001,
83,
15,
13436,
1126,
2690,
680,
15896,
9095,
787,
2741,
367,
3865,
199,
21080,
15,
345,
264,
17287,
436,
31964,
10410,
14,
199,
199,
32653,
15,
345,
264,
17287,
12966,
1380,
314,
30162,
4171,
365,
20077,
367,
282,
199,
10,
24460,
1435,
10,
1329,
402,
8212,
83,
2419,
314,
3379,
1329,
402,
8212,
83,
315,
626,
199,
3271,
14,
2136,
10618,
370,
642,
3379,
15877,
5818,
465,
314,
298,
4443,
15877,
199,
4631,
2,
503,
298,
4443,
2690,
1568,
1674,
199,
199,
4942,
1330,
10410,
12966,
1380,
314,
30162,
4171,
365,
20077,
367,
282,
627,
9828,
836,
10,
1329,
402,
199,
23001,
83,
2419,
314,
3659,
2690,
1568,
14,
199,
199,
2765,
2884,
5544,
1454,
6571,
282,
2849,
25344,
27156,
1402,
367,
199,
21080,
436,
31964,
10410,
14,
961,
1402,
365,
314,
8212,
13,
6788,
20861,
16956,
199,
1238,
12,
1314,
4440,
445,
2411,
79,
17,
370,
14497,
314,
2615,
30162,
4171,
402,
314,
2690,
14,
7754,
199,
21928,
370,
3626,
20501,
10844,
741,
14,
334,
7409,
9,
367,
1655,
2436,
27,
26426,
841,
12,
959,
12,
1749,
12,
1616,
12,
4114,
65,
12,
199,
460,
4114,
66,
787,
1202,
315,
642,
2884,
14,
199,
199,
1858,
1924,
14046,
15,
832,
1330,
10410,
2376,
12,
314,
14497,
12,
2399,
625,
14353,
199,
6807,
1125,
12,
436,
15197,
6252,
787,
14581,
14,
710,
2884,
5544,
1454,
199,
4467,
642,
2556,
370,
282,
1817,
12,
1314,
883,
506,
16174,
2455,
379,
315,
282,
2240,
199,
10180,
465,
27832,
14,
5439,
1072,
6752,
12,
4066,
465,
19695,
12,
1443,
506,
3483,
315,
314,
6466,
14,
199,
199,
3917,
376,
14497,
365,
14581,
465,
298,
46,
15,
33,
401,
440,
8321,
2556,
1990,
3451,
370,
199,
3357,
376,
14497,
14,
961,
883,
4781,
1380,
31964,
393,
1958,
340,
282,
2690,
1630,
440,
199,
7747,
1263,
19768,
83,
503,
4270,
1860,
83,
12,
503,
340,
2337,
365,
8840,
1373,
19768,
436,
199,
889,
4270,
1860,
83,
14,
437,
19768,
365,
3247,
465,
376,
20038,
543,
8840,
1373,
199,
23001,
15,
4041,
315,
314,
2690,
14,
437,
4270,
1860,
365,
3247,
465,
376,
20038,
199,
1045,
8840,
2877,
8212,
83,
15,
13436,
315,
314,
2690,
14,
199,
199,
17576,
1441,
26,
982,
1265,
675,
314,
2058,
402,
642,
2884,
315,
1263,
3267,
5419,
12,
8749,
199,
1235,
3238,
370,
286,
1175,
314,
3626,
20501,
10844,
741,
14,
334,
7409,
9,
15220,
12,
465,
5521,
465,
1413,
41,
3465,
334,
3239,
199,
1014,
921,
23104,
1036,
14,
1308,
367,
2436,
680,
199,
199,
607,
10234,
370,
3626,
20501,
10844,
741,
14,
334,
7409,
395,
314,
2569,
5944,
4898,
30503,
590,
199,
1180,
1893,
1830,
18234,
436,
5343,
3520,
23155,
12,
880,
652,
365,
5827,
370,
199,
12344,
19807,
23504,
3062,
2348,
26,
199,
199,
13,
869,
23994,
72,
10844,
741,
14,
334,
6965,
9,
199,
13,
5244,
287,
10844,
741,
14,
334,
17919,
9,
199,
13,
3626,
20501,
334,
6965,
9,
199,
199,
15242,
26,
199,
199,
1049,
8035,
12,
437,
2020,
653,
14,
1603,
14,
598,
1583,
13876,
12,
377,
14,
445,
14,
869,
23994,
72,
12,
662,
14,
491,
14,
428,
11438,
12,
1804,
14,
869,
14,
16593,
12,
820,
14,
1804,
14,
3626,
20501,
12,
436,
437,
14,
603,
14,
13096,
317,
834,
6171,
14,
820,
1530,
17287,
436,
31964,
10410,
543,
869,
778,
5579,
26,
282,
25344,
10059,
367,
15877,
436,
27156,
315,
28897,
328,
422,
3677,
410,
14525,
397,
12,
662,
331,
7954,
10953,
79,
16670,
334,
7138,
6974,
680,
199,
199,
2001,
20501,
12,
820,
14,
1804,
14,
6171,
14,
15896,
6897,
51,
26,
7083,
30364,
27156,
402,
20340,
30162,
4171,
436,
5709,
20340,
687,
5845,
14,
3394,
1749,
14,
2876,
1159,
15423,
436,
4223,
3267,
737,
26,
1455,
921,
80,
633,
14,
79,
23066,
14,
1308,
15,
597,
18187,
14,
199,
199,
2001,
20501,
12,
820,
14,
1804,
2020,
437,
14,
445,
2411,
79,
12,
653,
14,
1603,
14,
598,
1583,
13876,
12,
428,
14,
1488,
14,
29730,
12,
445,
14,
1323,
14,
603,
8035,
12,
820,
14,
491,
14,
445,
22133,
13196,
12,
436,
1603,
14,
377,
14,
491,
265,
903,
79,
14,
6029,
14,
29941,
436,
23155,
25833,
8212,
13,
6788,
436,
2690,
13,
6788,
24063,
17287,
12,
31964,
10410,
436,
9132,
402,
465,
8946,
416,
3389,
14,
22142,
402,
7497,
867,
662,
331,
4956,
959,
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,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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
] |
Evervolv/android_external_chromium_org
|
chrome/common/extensions/PRESUBMIT.py
|
31
|
6071
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Presubmit script for changes affecting extensions.
See http://dev.chromium.org/developers/how-tos/depottools/presubmit-scripts
for more details about the presubmit API built into gcl.
"""
import fnmatch
import os
import re
EXTENSIONS_PATH = os.path.join('chrome', 'common', 'extensions')
DOCS_PATH = os.path.join(EXTENSIONS_PATH, 'docs')
SERVER2_PATH = os.path.join(DOCS_PATH, 'server2')
API_PATH = os.path.join(EXTENSIONS_PATH, 'api')
TEMPLATES_PATH = os.path.join(DOCS_PATH, 'templates')
PRIVATE_TEMPLATES_PATH = os.path.join(TEMPLATES_PATH, 'private')
PUBLIC_TEMPLATES_PATH = os.path.join(TEMPLATES_PATH, 'public')
INTROS_PATH = os.path.join(TEMPLATES_PATH, 'intros')
ARTICLES_PATH = os.path.join(TEMPLATES_PATH, 'articles')
LOCAL_PUBLIC_TEMPLATES_PATH = os.path.join('docs',
'templates',
'public')
def _ReadFile(filename):
with open(filename) as f:
return f.read()
def _ListFilesInPublic():
all_files = []
for path, dirs, files in os.walk(LOCAL_PUBLIC_TEMPLATES_PATH):
all_files.extend(
os.path.join(path, filename)[len(LOCAL_PUBLIC_TEMPLATES_PATH + os.sep):]
for filename in files)
return all_files
def _UnixName(name):
name = os.path.splitext(name)[0]
s1 = re.sub('([a-z])([A-Z])', r'\1_\2', name)
s2 = re.sub('([A-Z]+)([A-Z][a-z])', r'\1_\2', s1)
return s2.replace('.', '_').lower()
def _FindMatchingTemplates(template_name, template_path_list):
matches = []
unix_name = _UnixName(template_name)
for template in template_path_list:
if unix_name == _UnixName(template.split(os.sep)[-1]):
matches.append(template)
return matches
def _SanitizeAPIName(name, api_path):
if not api_path.endswith(os.sep):
api_path += os.sep
filename = os.path.splitext(name)[0][len(api_path):].replace(os.sep, '_')
if 'experimental' in filename:
filename = 'experimental_' + filename.replace('experimental_', '')
return filename
def _CreateIntegrationTestArgs(affected_files):
if (any(fnmatch.fnmatch(name, '%s*.py' % SERVER2_PATH)
for name in affected_files) or
any(fnmatch.fnmatch(name, '%s*' % PRIVATE_TEMPLATES_PATH)
for name in affected_files)):
return ['-a']
args = []
for name in affected_files:
if (fnmatch.fnmatch(name, '%s*' % PUBLIC_TEMPLATES_PATH) or
fnmatch.fnmatch(name, '%s*' % INTROS_PATH) or
fnmatch.fnmatch(name, '%s*' % ARTICLES_PATH)):
args.extend(_FindMatchingTemplates(name.split(os.sep)[-1],
_ListFilesInPublic()))
if fnmatch.fnmatch(name, '%s*' % API_PATH):
args.extend(_FindMatchingTemplates(_SanitizeAPIName(name, API_PATH),
_ListFilesInPublic()))
return args
def _CheckHeadingIDs(input_api):
ids_re = re.compile('<h[23].*id=.*?>')
headings_re = re.compile('<h[23].*?>')
bad_files = []
for name in input_api.AbsoluteLocalPaths():
if not os.path.exists(name):
continue
if (fnmatch.fnmatch(name, '*%s*' % INTROS_PATH) or
fnmatch.fnmatch(name, '*%s*' % ARTICLES_PATH)):
contents = input_api.ReadFile(name)
if (len(re.findall(headings_re, contents)) !=
len(re.findall(ids_re, contents))):
bad_files.append(name)
return bad_files
def _CheckLinks(input_api, output_api, results):
for affected_file in input_api.AffectedFiles():
name = affected_file.LocalPath()
absolute_path = affected_file.AbsoluteLocalPath()
if not os.path.exists(absolute_path):
continue
if (fnmatch.fnmatch(name, '%s*' % PUBLIC_TEMPLATES_PATH) or
fnmatch.fnmatch(name, '%s*' % INTROS_PATH) or
fnmatch.fnmatch(name, '%s*' % ARTICLES_PATH) or
fnmatch.fnmatch(name, '%s*' % API_PATH)):
contents = _ReadFile(absolute_path)
args = []
if input_api.platform == 'win32':
args = [input_api.python_executable]
args.extend([os.path.join('docs', 'server2', 'link_converter.py'),
'-o',
'-f',
absolute_path])
output = input_api.subprocess.check_output(
args,
cwd=input_api.PresubmitLocalPath(),
universal_newlines=True)
if output != contents:
changes = ''
for i, (line1, line2) in enumerate(
zip(contents.split('\n'), output.split('\n'))):
if line1 != line2:
changes = ('%s\nLine %d:\n-%s\n+%s\n' %
(changes, i + 1, line1, line2))
if changes:
results.append(output_api.PresubmitPromptWarning(
'File %s may have an old-style <a> link to an API page. Please '
'run docs/server2/link_converter.py to convert the link[s], or '
'convert them manually.\n\nSuggested changes are: %s' %
(name, changes)))
def _CheckChange(input_api, output_api):
results = [
output_api.PresubmitError('File %s needs an id for each heading.' % name)
for name in _CheckHeadingIDs(input_api)]
try:
integration_test = []
# From depot_tools/presubmit_canned_checks.py:529
if input_api.platform == 'win32':
integration_test = [input_api.python_executable]
integration_test.append(
os.path.join('docs', 'server2', 'integration_test.py'))
integration_test.extend(_CreateIntegrationTestArgs(input_api.LocalPaths()))
input_api.subprocess.check_call(integration_test,
cwd=input_api.PresubmitLocalPath())
except input_api.subprocess.CalledProcessError:
results.append(output_api.PresubmitError('IntegrationTest failed!'))
_CheckLinks(input_api, output_api, results)
return results
def CheckChangeOnUpload(input_api, output_api):
return _CheckChange(input_api, output_api)
def CheckChangeOnCommit(input_api, output_api):
return _CheckChange(input_api, output_api)
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
30607,
2884,
367,
4493,
12787,
316,
5478,
14,
199,
199,
9295,
1455,
921,
2374,
14,
13211,
14,
1308,
15,
23826,
15,
1917,
13,
14543,
15,
27834,
2537,
15,
80,
15527,
13,
6429,
199,
509,
1655,
2436,
3595,
314,
23895,
3261,
6137,
1901,
486,
429,
14,
199,
624,
199,
646,
15951,
199,
646,
747,
199,
646,
295,
199,
199,
18451,
63,
3243,
275,
747,
14,
515,
14,
904,
360,
9887,
297,
283,
2330,
297,
283,
5359,
358,
199,
30072,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
18451,
63,
3243,
12,
283,
4757,
358,
199,
6613,
18,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
30072,
63,
3243,
12,
283,
1000,
18,
358,
199,
3735,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
18451,
63,
3243,
12,
283,
1246,
358,
199,
25437,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
30072,
63,
3243,
12,
283,
5876,
358,
199,
18748,
63,
25437,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
25437,
63,
3243,
12,
283,
4239,
358,
199,
19476,
63,
25437,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
25437,
63,
3243,
12,
283,
3455,
358,
199,
2919,
1092,
51,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
25437,
63,
3243,
12,
283,
442,
4796,
358,
199,
2294,
948,
11344,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
25437,
63,
3243,
12,
283,
19813,
358,
199,
199,
7486,
63,
19476,
63,
25437,
63,
3243,
275,
747,
14,
515,
14,
904,
360,
4757,
297,
5644,
283,
5876,
297,
5644,
283,
3455,
358,
199,
199,
318,
485,
32356,
8,
1501,
304,
523,
543,
1551,
8,
1501,
9,
465,
289,
26,
272,
372,
289,
14,
739,
342,
199,
199,
318,
485,
1296,
5535,
607,
9885,
837,
523,
1006,
63,
1725,
275,
942,
523,
367,
931,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
7486,
63,
19476,
63,
25437,
63,
3243,
304,
272,
1006,
63,
1725,
14,
2880,
8,
267,
747,
14,
515,
14,
904,
8,
515,
12,
1788,
2788,
552,
8,
7486,
63,
19476,
63,
25437,
63,
3243,
435,
747,
14,
4127,
15405,
267,
367,
1788,
315,
1584,
9,
523,
372,
1006,
63,
1725,
199,
199,
318,
485,
21607,
985,
8,
354,
304,
523,
536,
275,
747,
14,
515,
14,
7973,
8,
354,
2788,
16,
61,
523,
308,
17,
275,
295,
14,
954,
360,
779,
65,
13,
90,
566,
779,
33,
13,
58,
22206,
519,
1154,
17,
18005,
18,
297,
536,
9,
523,
308,
18,
275,
295,
14,
954,
360,
779,
33,
13,
58,
11896,
779,
33,
13,
58,
1527,
65,
13,
90,
22206,
519,
1154,
17,
18005,
18,
297,
308,
17,
9,
523,
372,
308,
18,
14,
1814,
14078,
2513,
1959,
2325,
342,
199,
199,
318,
485,
6591,
14215,
17969,
8,
1160,
63,
354,
12,
1978,
63,
515,
63,
513,
304,
523,
4450,
275,
942,
523,
16572,
63,
354,
275,
485,
21607,
985,
8,
1160,
63,
354,
9,
523,
367,
1978,
315,
1978,
63,
515,
63,
513,
26,
272,
340,
16572,
63,
354,
508,
485,
21607,
985,
8,
1160,
14,
1294,
8,
736,
14,
4127,
15786,
17,
4682,
489,
4450,
14,
740,
8,
1160,
9,
523,
372,
4450,
199,
199,
318,
485,
51,
12531,
1282,
568,
313,
8,
354,
12,
2986,
63,
515,
304,
523,
340,
440,
2986,
63,
515,
14,
4130,
8,
736,
14,
4127,
304,
272,
2986,
63,
515,
847,
747,
14,
4127,
523,
1788,
275,
747,
14,
515,
14,
7973,
8,
354,
2788,
16,
1527,
552,
8,
1246,
63,
515,
304,
1055,
1814,
8,
736,
14,
4127,
12,
18962,
523,
340,
283,
18924,
7,
315,
1788,
26,
272,
1788,
275,
283,
18924,
8650,
435,
1788,
14,
1814,
360,
18924,
14474,
4074,
523,
372,
1788,
199,
199,
318,
485,
2499,
20405,
774,
6213,
8,
26653,
63,
1725,
304,
523,
340,
334,
1629,
8,
15359,
14,
15359,
8,
354,
12,
1543,
83,
4856,
647,
7,
450,
23578,
18,
63,
3243,
9,
268,
367,
536,
315,
16955,
63,
1725,
9,
503,
489,
1263,
8,
15359,
14,
15359,
8,
354,
12,
1543,
83,
10223,
450,
28644,
1951,
63,
25437,
63,
3243,
9,
881,
367,
536,
315,
16955,
63,
1725,
2298,
272,
372,
11573,
65,
418,
523,
1249,
275,
942,
523,
367,
536,
315,
16955,
63,
1725,
26,
272,
340,
334,
15359,
14,
15359,
8,
354,
12,
1543,
83,
10223,
450,
21755,
63,
25437,
63,
3243,
9,
503,
267,
15951,
14,
15359,
8,
354,
12,
1543,
83,
10223,
450,
16429,
1092,
51,
63,
3243,
9,
503,
267,
15951,
14,
15359,
8,
354,
12,
1543,
83,
10223,
450,
4160,
52,
948,
11344,
63,
3243,
2298,
489,
1249,
14,
2880,
1547,
6591,
14215,
17969,
8,
354,
14,
1294,
8,
736,
14,
4127,
15786,
17,
467,
1460,
485,
1296,
5535,
607,
9885,
4059,
272,
340,
15951,
14,
15359,
8,
354,
12,
1543,
83,
10223,
450,
3261,
63,
3243,
304,
489,
1249,
14,
2880,
1547,
6591,
14215,
17969,
1547,
51,
12531,
1282,
568,
313,
8,
354,
12,
3261,
63,
3243,
395,
1460,
485,
1296,
5535,
607,
9885,
4059,
523,
372,
1249,
199,
199,
318,
485,
1799,
23818,
12818,
8,
1210,
63,
1246,
304,
523,
2762,
63,
264,
275,
295,
14,
2014,
4827,
72,
59,
1789,
1055,
10,
344,
29,
6697,
5971,
523,
26967,
63,
264,
275,
295,
14,
2014,
4827,
72,
59,
1789,
1055,
15279,
5971,
523,
4875,
63,
1725,
275,
942,
523,
367,
536,
315,
1324,
63,
1246,
14,
24677,
5339,
11804,
837,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
354,
304,
489,
1980,
272,
340,
334,
15359,
14,
15359,
8,
354,
12,
6438,
5,
83,
10223,
450,
16429,
1092,
51,
63,
3243,
9,
503,
267,
15951,
14,
15359,
8,
354,
12,
6438,
5,
83,
10223,
450,
4160,
52,
948,
11344,
63,
3243,
2298,
489,
4072,
275,
1324,
63,
1246,
14,
32356,
8,
354,
9,
489,
340,
334,
552,
8,
264,
14,
6452,
8,
2993,
780,
63,
264,
12,
4072,
430,
1137,
881,
822,
8,
264,
14,
6452,
8
] |
[
1898,
334,
67,
9,
6029,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
30607,
2884,
367,
4493,
12787,
316,
5478,
14,
199,
199,
9295,
1455,
921,
2374,
14,
13211,
14,
1308,
15,
23826,
15,
1917,
13,
14543,
15,
27834,
2537,
15,
80,
15527,
13,
6429,
199,
509,
1655,
2436,
3595,
314,
23895,
3261,
6137,
1901,
486,
429,
14,
199,
624,
199,
646,
15951,
199,
646,
747,
199,
646,
295,
199,
199,
18451,
63,
3243,
275,
747,
14,
515,
14,
904,
360,
9887,
297,
283,
2330,
297,
283,
5359,
358,
199,
30072,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
18451,
63,
3243,
12,
283,
4757,
358,
199,
6613,
18,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
30072,
63,
3243,
12,
283,
1000,
18,
358,
199,
3735,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
18451,
63,
3243,
12,
283,
1246,
358,
199,
25437,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
30072,
63,
3243,
12,
283,
5876,
358,
199,
18748,
63,
25437,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
25437,
63,
3243,
12,
283,
4239,
358,
199,
19476,
63,
25437,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
25437,
63,
3243,
12,
283,
3455,
358,
199,
2919,
1092,
51,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
25437,
63,
3243,
12,
283,
442,
4796,
358,
199,
2294,
948,
11344,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
25437,
63,
3243,
12,
283,
19813,
358,
199,
199,
7486,
63,
19476,
63,
25437,
63,
3243,
275,
747,
14,
515,
14,
904,
360,
4757,
297,
5644,
283,
5876,
297,
5644,
283,
3455,
358,
199,
199,
318,
485,
32356,
8,
1501,
304,
523,
543,
1551,
8,
1501,
9,
465,
289,
26,
272,
372,
289,
14,
739,
342,
199,
199,
318,
485,
1296,
5535,
607,
9885,
837,
523,
1006,
63,
1725,
275,
942,
523,
367,
931,
12,
7606,
12,
1584,
315,
747,
14,
7757,
8,
7486,
63,
19476,
63,
25437,
63,
3243,
304,
272,
1006,
63,
1725,
14,
2880,
8,
267,
747,
14,
515,
14,
904,
8,
515,
12,
1788,
2788,
552,
8,
7486,
63,
19476,
63,
25437,
63,
3243,
435,
747,
14,
4127,
15405,
267,
367,
1788,
315,
1584,
9,
523,
372,
1006,
63,
1725,
199,
199,
318,
485,
21607,
985,
8,
354,
304,
523,
536,
275,
747,
14,
515,
14,
7973,
8,
354,
2788,
16,
61,
523,
308,
17,
275,
295,
14,
954,
360,
779,
65,
13,
90,
566,
779,
33,
13,
58,
22206,
519,
1154,
17,
18005,
18,
297,
536,
9,
523,
308,
18,
275,
295,
14,
954,
360,
779,
33,
13,
58,
11896,
779,
33,
13,
58,
1527,
65,
13,
90,
22206,
519,
1154,
17,
18005,
18,
297,
308,
17,
9,
523,
372,
308,
18,
14,
1814,
14078,
2513,
1959,
2325,
342,
199,
199,
318,
485,
6591,
14215,
17969,
8,
1160,
63,
354,
12,
1978,
63,
515,
63,
513,
304,
523,
4450,
275,
942,
523,
16572,
63,
354,
275,
485,
21607,
985,
8,
1160,
63,
354,
9,
523,
367,
1978,
315,
1978,
63,
515,
63,
513,
26,
272,
340,
16572,
63,
354,
508,
485,
21607,
985,
8,
1160,
14,
1294,
8,
736,
14,
4127,
15786,
17,
4682,
489,
4450,
14,
740,
8,
1160,
9,
523,
372,
4450,
199,
199,
318,
485,
51,
12531,
1282,
568,
313,
8,
354,
12,
2986,
63,
515,
304,
523,
340,
440,
2986,
63,
515,
14,
4130,
8,
736,
14,
4127,
304,
272,
2986,
63,
515,
847,
747,
14,
4127,
523,
1788,
275,
747,
14,
515,
14,
7973,
8,
354,
2788,
16,
1527,
552,
8,
1246,
63,
515,
304,
1055,
1814,
8,
736,
14,
4127,
12,
18962,
523,
340,
283,
18924,
7,
315,
1788,
26,
272,
1788,
275,
283,
18924,
8650,
435,
1788,
14,
1814,
360,
18924,
14474,
4074,
523,
372,
1788,
199,
199,
318,
485,
2499,
20405,
774,
6213,
8,
26653,
63,
1725,
304,
523,
340,
334,
1629,
8,
15359,
14,
15359,
8,
354,
12,
1543,
83,
4856,
647,
7,
450,
23578,
18,
63,
3243,
9,
268,
367,
536,
315,
16955,
63,
1725,
9,
503,
489,
1263,
8,
15359,
14,
15359,
8,
354,
12,
1543,
83,
10223,
450,
28644,
1951,
63,
25437,
63,
3243,
9,
881,
367,
536,
315,
16955,
63,
1725,
2298,
272,
372,
11573,
65,
418,
523,
1249,
275,
942,
523,
367,
536,
315,
16955,
63,
1725,
26,
272,
340,
334,
15359,
14,
15359,
8,
354,
12,
1543,
83,
10223,
450,
21755,
63,
25437,
63,
3243,
9,
503,
267,
15951,
14,
15359,
8,
354,
12,
1543,
83,
10223,
450,
16429,
1092,
51,
63,
3243,
9,
503,
267,
15951,
14,
15359,
8,
354,
12,
1543,
83,
10223,
450,
4160,
52,
948,
11344,
63,
3243,
2298,
489,
1249,
14,
2880,
1547,
6591,
14215,
17969,
8,
354,
14,
1294,
8,
736,
14,
4127,
15786,
17,
467,
1460,
485,
1296,
5535,
607,
9885,
4059,
272,
340,
15951,
14,
15359,
8,
354,
12,
1543,
83,
10223,
450,
3261,
63,
3243,
304,
489,
1249,
14,
2880,
1547,
6591,
14215,
17969,
1547,
51,
12531,
1282,
568,
313,
8,
354,
12,
3261,
63,
3243,
395,
1460,
485,
1296,
5535,
607,
9885,
4059,
523,
372,
1249,
199,
199,
318,
485,
1799,
23818,
12818,
8,
1210,
63,
1246,
304,
523,
2762,
63,
264,
275,
295,
14,
2014,
4827,
72,
59,
1789,
1055,
10,
344,
29,
6697,
5971,
523,
26967,
63,
264,
275,
295,
14,
2014,
4827,
72,
59,
1789,
1055,
15279,
5971,
523,
4875,
63,
1725,
275,
942,
523,
367,
536,
315,
1324,
63,
1246,
14,
24677,
5339,
11804,
837,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
354,
304,
489,
1980,
272,
340,
334,
15359,
14,
15359,
8,
354,
12,
6438,
5,
83,
10223,
450,
16429,
1092,
51,
63,
3243,
9,
503,
267,
15951,
14,
15359,
8,
354,
12,
6438,
5,
83,
10223,
450,
4160,
52,
948,
11344,
63,
3243,
2298,
489,
4072,
275,
1324,
63,
1246,
14,
32356,
8,
354,
9,
489,
340,
334,
552,
8,
264,
14,
6452,
8,
2993,
780,
63,
264,
12,
4072,
430,
1137,
881,
822,
8,
264,
14,
6452,
8,
0
] |
[
1,
1,
1,
1,
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l
|
youtube_dl/extractor/vimple.py
|
121
|
1911
|
from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import int_or_none
class SprutoBaseIE(InfoExtractor):
def _extract_spruto(self, spruto, video_id):
playlist = spruto['playlist'][0]
title = playlist['title']
video_id = playlist.get('videoId') or video_id
thumbnail = playlist.get('posterUrl') or playlist.get('thumbnailUrl')
duration = int_or_none(playlist.get('duration'))
formats = [{
'url': f['url'],
} for f in playlist['video']]
self._sort_formats(formats)
return {
'id': video_id,
'title': title,
'thumbnail': thumbnail,
'duration': duration,
'formats': formats,
}
class VimpleIE(SprutoBaseIE):
IE_DESC = 'Vimple - one-click video hosting'
_VALID_URL = r'https?://(?:player\.vimple\.ru/iframe|vimple\.ru)/(?P<id>[\da-f-]{32,36})'
_TESTS = [
{
'url': 'http://vimple.ru/c0f6b1687dcd4000a97ebe70068039cf',
'md5': '2e750a330ed211d3fd41821c6ad9a279',
'info_dict': {
'id': 'c0f6b168-7dcd-4000-a97e-be70068039cf',
'ext': 'mp4',
'title': 'Sunset',
'duration': 20,
'thumbnail': 're:https?://.*?\.jpg',
},
}, {
'url': 'http://player.vimple.ru/iframe/52e1beec-1314-4a83-aeac-c61562eadbf9',
'only_matching': True,
}
]
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(
'http://player.vimple.ru/iframe/%s' % video_id, video_id)
spruto = self._parse_json(
self._search_regex(
r'sprutoData\s*:\s*({.+?}),\r\n', webpage, 'spruto data'),
video_id)
return self._extract_spruto(spruto, video_id)
|
unlicense
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
1109,
63,
269,
63,
3592,
421,
199,
533,
428,
2700,
1283,
1563,
4332,
8,
18283,
304,
272,
347,
485,
5005,
63,
681,
82,
1283,
8,
277,
12,
2249,
82,
1283,
12,
3991,
63,
344,
304,
267,
13210,
275,
2249,
82,
1283,
459,
10411,
3488,
16,
61,
267,
2538,
275,
13210,
459,
1213,
418,
267,
3991,
63,
344,
275,
13210,
14,
362,
360,
3722,
1304,
358,
503,
3991,
63,
344,
267,
10062,
275,
13210,
14,
362,
360,
20801,
6417,
358,
503,
13210,
14,
362,
360,
8311,
6417,
358,
267,
7373,
275,
1109,
63,
269,
63,
3592,
8,
10411,
14,
362,
360,
5553,
1333,
398,
6752,
275,
8910,
288,
283,
633,
356,
289,
459,
633,
995,
267,
789,
367,
289,
315,
13210,
459,
3722,
6538,
267,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
8311,
356,
10062,
12,
288,
283,
5553,
356,
7373,
12,
288,
283,
6321,
356,
6752,
12,
267,
789,
421,
199,
533,
812,
1729,
4332,
8,
51,
2700,
1283,
1563,
4332,
304,
272,
15292,
63,
15119,
275,
283,
54,
1729,
446,
1373,
13,
4891,
3991,
1591,
316,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
6147,
4537,
433,
575,
4537,
6558,
15,
20052,
92,
433,
575,
4537,
6558,
2447,
2229,
48,
28,
344,
24693,
983,
13,
70,
13,
8194,
708,
12,
1344,
29668,
272,
485,
7569,
275,
359,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
433,
575,
14,
6558,
15,
67,
16,
70,
22,
66,
975,
1555,
68,
2866,
23641,
65,
2576,
69,
1235,
23,
8010,
20016,
2177,
297,
288,
283,
1064,
21,
356,
283,
18,
69,
27045,
65,
14137,
379,
12832,
68,
19,
2592,
24456,
2025,
67,
22,
350,
25,
65,
12987,
297,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
67,
16,
70,
22,
66,
6568,
13,
23,
68,
2866,
13,
23641,
13,
65,
2576,
69,
13,
1235,
23,
8010,
20016,
2177,
297,
355,
283,
832,
356,
283,
311,
20,
297,
355,
283,
1213,
356,
283,
51,
16787,
297,
355,
283,
5553,
356,
3388,
12,
355,
283,
8311,
356,
283,
264,
26,
2859,
14144,
6697,
4537,
8476,
297,
288,
1660,
267,
1660,
469,
288,
283,
633,
356,
283,
1014,
921,
6147,
14,
433,
575,
14,
6558,
15,
20052,
15,
2528,
69,
17,
1235,
825,
13,
969,
1079,
13,
20,
65,
2658,
13,
3624,
645,
13,
67,
28249,
2789,
69,
350,
4361,
25,
297,
288,
283,
2118,
63,
9467,
356,
715,
12,
267,
789,
272,
1622,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
398,
9248,
275,
291,
423,
4249,
63,
12022,
8,
288,
283,
1014,
921,
6147,
14,
433,
575,
14,
6558,
15,
20052,
3149,
83,
7,
450,
3991,
63,
344,
12,
3991,
63,
344,
9,
398,
2249,
82,
1283,
275,
291,
423,
1122,
63,
1001,
8,
288,
291,
423,
1733,
63,
3821,
8,
355,
519,
1159,
2700,
1283,
1451,
60,
83,
10,
3427,
83,
10,
2561,
11198,
8688,
60,
82,
60,
78,
297,
9248,
12,
283,
681,
82,
1283,
666,
659,
288,
3991,
63,
344,
9,
398,
372,
291,
423,
5005,
63,
681,
82,
1283,
8,
681,
82,
1283,
12,
3991,
63,
344,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1275,
2330,
492,
21298,
199,
504,
2508,
1208,
492,
1109,
63,
269,
63,
3592,
421,
199,
533,
428,
2700,
1283,
1563,
4332,
8,
18283,
304,
272,
347,
485,
5005,
63,
681,
82,
1283,
8,
277,
12,
2249,
82,
1283,
12,
3991,
63,
344,
304,
267,
13210,
275,
2249,
82,
1283,
459,
10411,
3488,
16,
61,
267,
2538,
275,
13210,
459,
1213,
418,
267,
3991,
63,
344,
275,
13210,
14,
362,
360,
3722,
1304,
358,
503,
3991,
63,
344,
267,
10062,
275,
13210,
14,
362,
360,
20801,
6417,
358,
503,
13210,
14,
362,
360,
8311,
6417,
358,
267,
7373,
275,
1109,
63,
269,
63,
3592,
8,
10411,
14,
362,
360,
5553,
1333,
398,
6752,
275,
8910,
288,
283,
633,
356,
289,
459,
633,
995,
267,
789,
367,
289,
315,
13210,
459,
3722,
6538,
267,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
8311,
356,
10062,
12,
288,
283,
5553,
356,
7373,
12,
288,
283,
6321,
356,
6752,
12,
267,
789,
421,
199,
533,
812,
1729,
4332,
8,
51,
2700,
1283,
1563,
4332,
304,
272,
15292,
63,
15119,
275,
283,
54,
1729,
446,
1373,
13,
4891,
3991,
1591,
316,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
6147,
4537,
433,
575,
4537,
6558,
15,
20052,
92,
433,
575,
4537,
6558,
2447,
2229,
48,
28,
344,
24693,
983,
13,
70,
13,
8194,
708,
12,
1344,
29668,
272,
485,
7569,
275,
359,
267,
469,
288,
283,
633,
356,
283,
1014,
921,
433,
575,
14,
6558,
15,
67,
16,
70,
22,
66,
975,
1555,
68,
2866,
23641,
65,
2576,
69,
1235,
23,
8010,
20016,
2177,
297,
288,
283,
1064,
21,
356,
283,
18,
69,
27045,
65,
14137,
379,
12832,
68,
19,
2592,
24456,
2025,
67,
22,
350,
25,
65,
12987,
297,
288,
283,
815,
63,
807,
356,
469,
355,
283,
344,
356,
283,
67,
16,
70,
22,
66,
6568,
13,
23,
68,
2866,
13,
23641,
13,
65,
2576,
69,
13,
1235,
23,
8010,
20016,
2177,
297,
355,
283,
832,
356,
283,
311,
20,
297,
355,
283,
1213,
356,
283,
51,
16787,
297,
355,
283,
5553,
356,
3388,
12,
355,
283,
8311,
356,
283,
264,
26,
2859,
14144,
6697,
4537,
8476,
297,
288,
1660,
267,
1660,
469,
288,
283,
633,
356,
283,
1014,
921,
6147,
14,
433,
575,
14,
6558,
15,
20052,
15,
2528,
69,
17,
1235,
825,
13,
969,
1079,
13,
20,
65,
2658,
13,
3624,
645,
13,
67,
28249,
2789,
69,
350,
4361,
25,
297,
288,
283,
2118,
63,
9467,
356,
715,
12,
267,
789,
272,
1622,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
398,
9248,
275,
291,
423,
4249,
63,
12022,
8,
288,
283,
1014,
921,
6147,
14,
433,
575,
14,
6558,
15,
20052,
3149,
83,
7,
450,
3991,
63,
344,
12,
3991,
63,
344,
9,
398,
2249,
82,
1283,
275,
291,
423,
1122,
63,
1001,
8,
288,
291,
423,
1733,
63,
3821,
8,
355,
519,
1159,
2700,
1283,
1451,
60,
83,
10,
3427,
83,
10,
2561,
11198,
8688,
60,
82,
60,
78,
297,
9248,
12,
283,
681,
82,
1283,
666,
659,
288,
3991,
63,
344,
9,
398,
372,
291,
423,
5005,
63,
681,
82,
1283,
8,
681,
82,
1283,
12,
3991,
63,
344,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
guoyu07/metagoofil
|
hachoir_core/field/integer.py
|
73
|
1848
|
"""
Integer field classes:
- UInt8, UInt16, UInt24, UInt32, UInt64: unsigned integer of 8, 16, 32, 64 bits ;
- Int8, Int16, Int24, Int32, Int64: signed integer of 8, 16, 32, 64 bits.
"""
from hachoir_core.field import Bits, FieldError
class GenericInteger(Bits):
"""
Generic integer class used to generate other classes.
"""
def __init__(self, parent, name, signed, size, description=None):
if not (8 <= size <= 16384):
raise FieldError("Invalid integer size (%s): have to be in 8..16384" % size)
Bits.__init__(self, parent, name, size, description)
self.signed = signed
def createValue(self):
return self._parent.stream.readInteger(
self.absolute_address, self.signed, self._size, self._parent.endian)
def integerFactory(name, is_signed, size, doc):
class Integer(GenericInteger):
__doc__ = doc
static_size = size
def __init__(self, parent, name, description=None):
GenericInteger.__init__(self, parent, name, is_signed, size, description)
cls = Integer
cls.__name__ = name
return cls
UInt8 = integerFactory("UInt8", False, 8, "Unsigned integer of 8 bits")
UInt16 = integerFactory("UInt16", False, 16, "Unsigned integer of 16 bits")
UInt24 = integerFactory("UInt24", False, 24, "Unsigned integer of 24 bits")
UInt32 = integerFactory("UInt32", False, 32, "Unsigned integer of 32 bits")
UInt64 = integerFactory("UInt64", False, 64, "Unsigned integer of 64 bits")
Int8 = integerFactory("Int8", True, 8, "Signed integer of 8 bits")
Int16 = integerFactory("Int16", True, 16, "Signed integer of 16 bits")
Int24 = integerFactory("Int24", True, 24, "Signed integer of 24 bits")
Int32 = integerFactory("Int32", True, 32, "Signed integer of 32 bits")
Int64 = integerFactory("Int64", True, 64, "Signed integer of 64 bits")
|
gpl-2.0
|
[
624,
199,
2674,
901,
3992,
26,
199,
13,
10666,
24,
12,
10666,
975,
12,
10666,
1194,
12,
10666,
708,
12,
10666,
772,
26,
7381,
3000,
402,
1695,
12,
3193,
12,
4337,
12,
5049,
5821,
8700,
199,
13,
9805,
24,
12,
9805,
975,
12,
9805,
1194,
12,
9805,
708,
12,
9805,
772,
26,
10514,
3000,
402,
1695,
12,
3193,
12,
4337,
12,
5049,
5821,
14,
199,
624,
199,
199,
504,
394,
21301,
63,
1018,
14,
698,
492,
26612,
12,
27691,
199,
199,
533,
8307,
2674,
8,
10787,
304,
272,
408,
272,
8307,
3000,
1021,
1202,
370,
3550,
1163,
3992,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
536,
12,
10514,
12,
1568,
12,
1369,
29,
403,
304,
267,
340,
440,
334,
24,
2695,
1568,
2695,
24619,
1349,
304,
288,
746,
27691,
480,
3364,
3000,
1568,
4366,
83,
304,
1172,
370,
506,
315,
1695,
703,
975,
8188,
2,
450,
1568,
9,
267,
26612,
855,
826,
721,
277,
12,
1676,
12,
536,
12,
1568,
12,
1369,
9,
267,
291,
14,
1737,
275,
10514,
339,
347,
1218,
1110,
8,
277,
304,
267,
372,
291,
423,
1708,
14,
1745,
14,
739,
2674,
8,
288,
291,
14,
6116,
63,
1562,
12,
291,
14,
1737,
12,
291,
423,
890,
12,
291,
423,
1708,
14,
15009,
9,
199,
199,
318,
3000,
2927,
8,
354,
12,
365,
63,
1737,
12,
1568,
12,
1382,
304,
272,
1021,
7225,
8,
9417,
2674,
304,
267,
636,
1301,
363,
275,
1382,
267,
2955,
63,
890,
275,
1568,
267,
347,
636,
826,
721,
277,
12,
1676,
12,
536,
12,
1369,
29,
403,
304,
288,
8307,
2674,
855,
826,
721,
277,
12,
1676,
12,
536,
12,
365,
63,
1737,
12,
1568,
12,
1369,
9,
272,
843,
275,
7225,
272,
843,
855,
354,
363,
275,
536,
272,
372,
843,
199,
199,
13304,
24,
275,
3000,
2927,
480,
13304,
24,
401,
756,
12,
1695,
12,
298,
25269,
3000,
402,
1695,
5821,
531,
199,
13304,
975,
275,
3000,
2927,
480,
13304,
975,
401,
756,
12,
3193,
12,
298,
25269,
3000,
402,
3193,
5821,
531,
199,
13304,
1194,
275,
3000,
2927,
480,
13304,
1194,
401,
756,
12,
5504,
12,
298,
25269,
3000,
402,
5504,
5821,
531,
199,
13304,
708,
275,
3000,
2927,
480,
13304,
708,
401,
756,
12,
4337,
12,
298,
25269,
3000,
402,
4337,
5821,
531,
199,
13304,
772,
275,
3000,
2927,
480,
13304,
772,
401,
756,
12,
5049,
12,
298,
25269,
3000,
402,
5049,
5821,
531,
199,
199,
3241,
24,
275,
3000,
2927,
480,
3241,
24,
401,
715,
12,
1695,
12,
298,
23013,
3000,
402,
1695,
5821,
531,
199,
3241,
975,
275,
3000,
2927,
480,
3241,
975,
401,
715,
12,
3193,
12,
298,
23013,
3000,
402,
3193,
5821,
531,
199,
3241,
1194,
275,
3000,
2927,
480,
3241,
1194,
401,
715,
12,
5504,
12,
298,
23013,
3000,
402,
5504,
5821,
531,
199,
3241,
708,
275,
3000,
2927,
480,
3241,
708,
401,
715,
12,
4337,
12,
298,
23013,
3000,
402,
4337,
5821,
531,
199,
3241,
772,
275,
3000,
2927,
480,
3241,
772,
401,
715,
12,
5049,
12,
298,
23013,
3000,
402,
5049,
5821,
531,
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
] |
[
199,
2674,
901,
3992,
26,
199,
13,
10666,
24,
12,
10666,
975,
12,
10666,
1194,
12,
10666,
708,
12,
10666,
772,
26,
7381,
3000,
402,
1695,
12,
3193,
12,
4337,
12,
5049,
5821,
8700,
199,
13,
9805,
24,
12,
9805,
975,
12,
9805,
1194,
12,
9805,
708,
12,
9805,
772,
26,
10514,
3000,
402,
1695,
12,
3193,
12,
4337,
12,
5049,
5821,
14,
199,
624,
199,
199,
504,
394,
21301,
63,
1018,
14,
698,
492,
26612,
12,
27691,
199,
199,
533,
8307,
2674,
8,
10787,
304,
272,
408,
272,
8307,
3000,
1021,
1202,
370,
3550,
1163,
3992,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1676,
12,
536,
12,
10514,
12,
1568,
12,
1369,
29,
403,
304,
267,
340,
440,
334,
24,
2695,
1568,
2695,
24619,
1349,
304,
288,
746,
27691,
480,
3364,
3000,
1568,
4366,
83,
304,
1172,
370,
506,
315,
1695,
703,
975,
8188,
2,
450,
1568,
9,
267,
26612,
855,
826,
721,
277,
12,
1676,
12,
536,
12,
1568,
12,
1369,
9,
267,
291,
14,
1737,
275,
10514,
339,
347,
1218,
1110,
8,
277,
304,
267,
372,
291,
423,
1708,
14,
1745,
14,
739,
2674,
8,
288,
291,
14,
6116,
63,
1562,
12,
291,
14,
1737,
12,
291,
423,
890,
12,
291,
423,
1708,
14,
15009,
9,
199,
199,
318,
3000,
2927,
8,
354,
12,
365,
63,
1737,
12,
1568,
12,
1382,
304,
272,
1021,
7225,
8,
9417,
2674,
304,
267,
636,
1301,
363,
275,
1382,
267,
2955,
63,
890,
275,
1568,
267,
347,
636,
826,
721,
277,
12,
1676,
12,
536,
12,
1369,
29,
403,
304,
288,
8307,
2674,
855,
826,
721,
277,
12,
1676,
12,
536,
12,
365,
63,
1737,
12,
1568,
12,
1369,
9,
272,
843,
275,
7225,
272,
843,
855,
354,
363,
275,
536,
272,
372,
843,
199,
199,
13304,
24,
275,
3000,
2927,
480,
13304,
24,
401,
756,
12,
1695,
12,
298,
25269,
3000,
402,
1695,
5821,
531,
199,
13304,
975,
275,
3000,
2927,
480,
13304,
975,
401,
756,
12,
3193,
12,
298,
25269,
3000,
402,
3193,
5821,
531,
199,
13304,
1194,
275,
3000,
2927,
480,
13304,
1194,
401,
756,
12,
5504,
12,
298,
25269,
3000,
402,
5504,
5821,
531,
199,
13304,
708,
275,
3000,
2927,
480,
13304,
708,
401,
756,
12,
4337,
12,
298,
25269,
3000,
402,
4337,
5821,
531,
199,
13304,
772,
275,
3000,
2927,
480,
13304,
772,
401,
756,
12,
5049,
12,
298,
25269,
3000,
402,
5049,
5821,
531,
199,
199,
3241,
24,
275,
3000,
2927,
480,
3241,
24,
401,
715,
12,
1695,
12,
298,
23013,
3000,
402,
1695,
5821,
531,
199,
3241,
975,
275,
3000,
2927,
480,
3241,
975,
401,
715,
12,
3193,
12,
298,
23013,
3000,
402,
3193,
5821,
531,
199,
3241,
1194,
275,
3000,
2927,
480,
3241,
1194,
401,
715,
12,
5504,
12,
298,
23013,
3000,
402,
5504,
5821,
531,
199,
3241,
708,
275,
3000,
2927,
480,
3241,
708,
401,
715,
12,
4337,
12,
298,
23013,
3000,
402,
4337,
5821,
531,
199,
3241,
772,
275,
3000,
2927,
480,
3241,
772,
401,
715,
12,
5049,
12,
298,
23013,
3000,
402,
5049,
5821,
531,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
GNOME/orca
|
test/keystrokes/helpcontent/load_no_sayall.py
|
3
|
1232
|
#!/usr/bin/python
"""Test of learn mode."""
from macaroon.playback import *
import utils
sequence = MacroSequence()
sequence.append(KeyPressAction(0, None, "KP_Insert"))
sequence.append(TypeAction("h"))
sequence.append(KeyReleaseAction(0, None, "KP_Insert"))
sequence.append(PauseAction(2000))
sequence.append(utils.StartRecordingAction())
sequence.append(KeyComboAction("F1"))
sequence.append(utils.AssertPresentationAction(
"1. F1 for help",
["BRAILLE LINE: 'yelp application Orca Screen Reader frame'",
" VISIBLE: 'Orca Screen Reader frame', cursor=1",
"BRAILLE LINE: ' Orca's logo Orca Screen Reader h1'",
" VISIBLE: 'Orca's logo Orca Screen Reader h', cursor=1",
"BRAILLE LINE: 'Finished loading Orca Screen Reader.'",
" VISIBLE: 'Finished loading Orca Screen Rea', cursor=0",
"BRAILLE LINE: ' Orca's logo Orca Screen Reader h1'",
" VISIBLE: 'Orca's logo Orca Screen Reader h', cursor=1",
"SPEECH OUTPUT: 'F1 '",
"SPEECH OUTPUT: 'Orca Screen Reader frame'",
"SPEECH OUTPUT: 'Finished loading Orca Screen Reader.' voice=system"]))
sequence.append(KeyComboAction("<Alt>F4"))
sequence.append(utils.AssertionSummaryAction())
sequence.start()
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
624,
774,
402,
12537,
818,
1041,
199,
199,
504,
4497,
285,
79,
265,
14,
2802,
894,
492,
627,
199,
646,
3778,
199,
199,
4041,
275,
10444,
293,
5826,
342,
199,
199,
4041,
14,
740,
8,
1197,
14414,
3310,
8,
16,
12,
488,
12,
298,
24974,
63,
9971,
2237,
199,
4041,
14,
740,
8,
804,
3310,
480,
72,
2237,
199,
4041,
14,
740,
8,
1197,
9625,
3310,
8,
16,
12,
488,
12,
298,
24974,
63,
9971,
2237,
199,
199,
4041,
14,
740,
8,
30851,
3310,
8,
8269,
430,
199,
199,
4041,
14,
740,
8,
1208,
14,
3162,
26040,
3310,
1012,
199,
4041,
14,
740,
8,
1197,
12413,
3310,
480,
38,
17,
2237,
199,
4041,
14,
740,
8,
1208,
14,
9699,
19794,
425,
3310,
8,
272,
298,
17,
14,
481,
17,
367,
1720,
401,
272,
2097,
34,
2847,
1193,
906,
13587,
26,
221,
283,
89,
1357,
4223,
4236,
696,
17804,
23099,
2787,
4662,
1362,
298,
258,
812,
1311,
7187,
26,
221,
283,
2844,
696,
17804,
23099,
2787,
297,
3920,
29,
17,
401,
1362,
298,
34,
2847,
1193,
906,
13587,
26,
221,
283,
4236,
696,
1159,
23623,
4236,
696,
17804,
23099,
394,
17,
4662,
1362,
298,
258,
812,
1311,
7187,
26,
221,
283,
2844,
696,
1159,
23623,
4236,
696,
17804,
23099,
394,
297,
3920,
29,
17,
401,
1362,
298,
34,
2847,
1193,
906,
13587,
26,
221,
283,
13430,
8697,
4236,
696,
17804,
23099,
26849,
1362,
298,
258,
812,
1311,
7187,
26,
221,
283,
13430,
8697,
4236,
696,
17804,
799,
65,
297,
3920,
29,
16,
401,
1362,
298,
34,
2847,
1193,
906,
13587,
26,
221,
283,
4236,
696,
1159,
23623,
4236,
696,
17804,
23099,
394,
17,
4662,
1362,
298,
258,
812,
1311,
7187,
26,
221,
283,
2844,
696,
1159,
23623,
4236,
696,
17804,
23099,
394,
297,
3920,
29,
17,
401,
1362,
298,
14179,
25126,
18746,
26,
283,
38,
17,
283,
401,
1362,
298,
14179,
25126,
18746,
26,
283,
2844,
696,
17804,
23099,
2787,
4662,
1362,
298,
14179,
25126,
18746,
26,
283,
13430,
8697,
4236,
696,
17804,
23099,
3530,
26563,
29,
2253,
13045,
199,
199,
4041,
14,
740,
8,
1197,
12413,
3310,
6757,
16985,
30,
38,
20,
2237,
199,
4041,
14,
740,
8,
1208,
14,
26860,
10407,
3310,
1012,
199,
4041,
14,
928,
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
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
624,
774,
402,
12537,
818,
1041,
199,
199,
504,
4497,
285,
79,
265,
14,
2802,
894,
492,
627,
199,
646,
3778,
199,
199,
4041,
275,
10444,
293,
5826,
342,
199,
199,
4041,
14,
740,
8,
1197,
14414,
3310,
8,
16,
12,
488,
12,
298,
24974,
63,
9971,
2237,
199,
4041,
14,
740,
8,
804,
3310,
480,
72,
2237,
199,
4041,
14,
740,
8,
1197,
9625,
3310,
8,
16,
12,
488,
12,
298,
24974,
63,
9971,
2237,
199,
199,
4041,
14,
740,
8,
30851,
3310,
8,
8269,
430,
199,
199,
4041,
14,
740,
8,
1208,
14,
3162,
26040,
3310,
1012,
199,
4041,
14,
740,
8,
1197,
12413,
3310,
480,
38,
17,
2237,
199,
4041,
14,
740,
8,
1208,
14,
9699,
19794,
425,
3310,
8,
272,
298,
17,
14,
481,
17,
367,
1720,
401,
272,
2097,
34,
2847,
1193,
906,
13587,
26,
221,
283,
89,
1357,
4223,
4236,
696,
17804,
23099,
2787,
4662,
1362,
298,
258,
812,
1311,
7187,
26,
221,
283,
2844,
696,
17804,
23099,
2787,
297,
3920,
29,
17,
401,
1362,
298,
34,
2847,
1193,
906,
13587,
26,
221,
283,
4236,
696,
1159,
23623,
4236,
696,
17804,
23099,
394,
17,
4662,
1362,
298,
258,
812,
1311,
7187,
26,
221,
283,
2844,
696,
1159,
23623,
4236,
696,
17804,
23099,
394,
297,
3920,
29,
17,
401,
1362,
298,
34,
2847,
1193,
906,
13587,
26,
221,
283,
13430,
8697,
4236,
696,
17804,
23099,
26849,
1362,
298,
258,
812,
1311,
7187,
26,
221,
283,
13430,
8697,
4236,
696,
17804,
799,
65,
297,
3920,
29,
16,
401,
1362,
298,
34,
2847,
1193,
906,
13587,
26,
221,
283,
4236,
696,
1159,
23623,
4236,
696,
17804,
23099,
394,
17,
4662,
1362,
298,
258,
812,
1311,
7187,
26,
221,
283,
2844,
696,
1159,
23623,
4236,
696,
17804,
23099,
394,
297,
3920,
29,
17,
401,
1362,
298,
14179,
25126,
18746,
26,
283,
38,
17,
283,
401,
1362,
298,
14179,
25126,
18746,
26,
283,
2844,
696,
17804,
23099,
2787,
4662,
1362,
298,
14179,
25126,
18746,
26,
283,
13430,
8697,
4236,
696,
17804,
23099,
3530,
26563,
29,
2253,
13045,
199,
199,
4041,
14,
740,
8,
1197,
12413,
3310,
6757,
16985,
30,
38,
20,
2237,
199,
4041,
14,
740,
8,
1208,
14,
26860,
10407,
3310,
1012,
199,
4041,
14,
928,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
hehongliang/tensorflow
|
tensorflow/python/kernel_tests/qr_op_test.py
|
2
|
8827
|
# 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 tensorflow.ops.math_ops.matrix_inverse."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import numpy as np
from tensorflow.python.framework import constant_op
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import gradient_checker
from tensorflow.python.ops import linalg_ops
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import random_ops
from tensorflow.python.platform import test
def _AddTest(test_class, op_name, testcase_name, fn):
test_name = "_".join(["test", op_name, testcase_name])
if hasattr(test_class, test_name):
raise RuntimeError("Test %s defined more than once" % test_name)
setattr(test_class, test_name, fn)
class QrOpTest(test.TestCase):
def testWrongDimensions(self):
# The input to qr should be a tensor of at least rank 2.
scalar = constant_op.constant(1.)
with self.assertRaisesRegexp(ValueError,
"Shape must be at least rank 2 but is rank 0"):
linalg_ops.qr(scalar)
vector = constant_op.constant([1., 2.])
with self.assertRaisesRegexp(ValueError,
"Shape must be at least rank 2 but is rank 1"):
linalg_ops.qr(vector)
def testConcurrentExecutesWithoutError(self):
with self.session(use_gpu=True) as sess:
all_ops = []
for full_matrices_ in True, False:
for rows_ in 4, 5:
for cols_ in 4, 5:
matrix1 = random_ops.random_normal([rows_, cols_], seed=42)
matrix2 = random_ops.random_normal([rows_, cols_], seed=42)
q1, r1 = linalg_ops.qr(matrix1, full_matrices=full_matrices_)
q2, r2 = linalg_ops.qr(matrix2, full_matrices=full_matrices_)
all_ops += [q1, r1, q2, r2]
val = sess.run(all_ops)
for i in range(8):
q = 4 * i
self.assertAllEqual(val[q], val[q + 2]) # q1 == q2
self.assertAllEqual(val[q + 1], val[q + 3]) # r1 == r2
def _GetQrOpTest(dtype_, shape_, full_matrices_, use_static_shape_):
is_complex = dtype_ in (np.complex64, np.complex128)
is_single = dtype_ in (np.float32, np.complex64)
def CompareOrthogonal(self, x, y, rank):
if is_single:
atol = 5e-4
else:
atol = 5e-14
# We only compare the first 'rank' orthogonal vectors since the
# remainder form an arbitrary orthonormal basis for the
# (row- or column-) null space, whose exact value depends on
# implementation details. Notice that since we check that the
# matrices of singular vectors are unitary elsewhere, we do
# implicitly test that the trailing vectors of x and y span the
# same space.
x = x[..., 0:rank]
y = y[..., 0:rank]
# Q is only unique up to sign (complex phase factor for complex matrices),
# so we normalize the sign first.
sum_of_ratios = np.sum(np.divide(y, x), -2, keepdims=True)
phases = np.divide(sum_of_ratios, np.abs(sum_of_ratios))
x *= phases
self.assertAllClose(x, y, atol=atol)
def CheckApproximation(self, a, q, r):
if is_single:
tol = 1e-5
else:
tol = 1e-14
# Tests that a ~= q*r.
a_recon = math_ops.matmul(q, r)
self.assertAllClose(a_recon.eval(), a, rtol=tol, atol=tol)
def CheckUnitary(self, x):
# Tests that x[...,:,:]^H * x[...,:,:] is close to the identity.
xx = math_ops.matmul(x, x, adjoint_a=True)
identity = array_ops.matrix_band_part(array_ops.ones_like(xx), 0, 0)
if is_single:
tol = 1e-5
else:
tol = 1e-14
self.assertAllClose(identity.eval(), self.evaluate(xx), atol=tol)
def Test(self):
np.random.seed(1)
x_np = np.random.uniform(
low=-1.0, high=1.0, size=np.prod(shape_)).reshape(shape_).astype(dtype_)
if is_complex:
x_np += 1j * np.random.uniform(
low=-1.0, high=1.0,
size=np.prod(shape_)).reshape(shape_).astype(dtype_)
with self.session(use_gpu=True) as sess:
if use_static_shape_:
x_tf = constant_op.constant(x_np)
else:
x_tf = array_ops.placeholder(dtype_)
q_tf, r_tf = linalg_ops.qr(x_tf, full_matrices=full_matrices_)
if use_static_shape_:
q_tf_val, r_tf_val = sess.run([q_tf, r_tf])
else:
q_tf_val, r_tf_val = sess.run([q_tf, r_tf], feed_dict={x_tf: x_np})
q_dims = q_tf_val.shape
np_q = np.ndarray(q_dims, dtype_)
np_q_reshape = np.reshape(np_q, (-1, q_dims[-2], q_dims[-1]))
new_first_dim = np_q_reshape.shape[0]
x_reshape = np.reshape(x_np, (-1, x_np.shape[-2], x_np.shape[-1]))
for i in range(new_first_dim):
if full_matrices_:
np_q_reshape[i, :, :], _ = np.linalg.qr(
x_reshape[i, :, :], mode="complete")
else:
np_q_reshape[i, :, :], _ = np.linalg.qr(
x_reshape[i, :, :], mode="reduced")
np_q = np.reshape(np_q_reshape, q_dims)
CompareOrthogonal(self, np_q, q_tf_val, min(shape_[-2:]))
CheckApproximation(self, x_np, q_tf_val, r_tf_val)
CheckUnitary(self, q_tf_val)
return Test
class QrGradOpTest(test.TestCase):
pass
def _GetQrGradOpTest(dtype_, shape_, full_matrices_):
def Test(self):
np.random.seed(42)
a = np.random.uniform(low=-1.0, high=1.0, size=shape_).astype(dtype_)
if dtype_ in [np.complex64, np.complex128]:
a += 1j * np.random.uniform(
low=-1.0, high=1.0, size=shape_).astype(dtype_)
# Optimal stepsize for central difference is O(epsilon^{1/3}).
epsilon = np.finfo(dtype_).eps
delta = 0.1 * epsilon**(1.0 / 3.0)
if dtype_ in [np.float32, np.complex64]:
tol = 3e-2
else:
tol = 1e-6
with self.session(use_gpu=True):
tf_a = constant_op.constant(a)
tf_b = linalg_ops.qr(tf_a, full_matrices=full_matrices_)
for b in tf_b:
x_init = np.random.uniform(
low=-1.0, high=1.0, size=shape_).astype(dtype_)
if dtype_ in [np.complex64, np.complex128]:
x_init += 1j * np.random.uniform(
low=-1.0, high=1.0, size=shape_).astype(dtype_)
theoretical, numerical = gradient_checker.compute_gradient(
tf_a,
tf_a.get_shape().as_list(),
b,
b.get_shape().as_list(),
x_init_value=x_init,
delta=delta)
self.assertAllClose(theoretical, numerical, atol=tol, rtol=tol)
return Test
if __name__ == "__main__":
for dtype in np.float32, np.float64, np.complex64, np.complex128:
for rows in 1, 2, 5, 10, 32, 100:
for cols in 1, 2, 5, 10, 32, 100:
for full_matrices in False, True:
for batch_dims in [(), (3,)] + [(3, 2)] * (max(rows, cols) < 10):
for use_static_shape in True, False:
shape = batch_dims + (rows, cols)
name = "%s_%s_full_%s_static_%s" % (dtype.__name__,
"_".join(map(str, shape)),
full_matrices,
use_static_shape)
_AddTest(QrOpTest, "Qr", name,
_GetQrOpTest(dtype, shape, full_matrices,
use_static_shape))
# TODO(pfau): Get working with complex types.
# TODO(pfau): Get working with full_matrices when rows != cols
# TODO(pfau): Get working when rows < cols
# TODO(pfau): Get working with shapeholders (dynamic shapes)
for full_matrices in False, True:
for dtype in np.float32, np.float64:
for rows in 1, 2, 5, 10:
for cols in 1, 2, 5, 10:
if rows == cols or (not full_matrices and rows > cols):
for batch_dims in [(), (3,)] + [(3, 2)] * (max(rows, cols) < 10):
shape = batch_dims + (rows, cols)
name = "%s_%s_full_%s" % (dtype.__name__,
"_".join(map(str, shape)),
full_matrices)
_AddTest(QrGradOpTest, "QrGrad", name,
_GetQrGradOpTest(dtype, shape, full_matrices))
test.main()
|
apache-2.0
|
[
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
3228,
14,
1483,
14,
3442,
63,
1483,
14,
3642,
63,
11668,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
6709,
63,
6743,
199,
504,
3228,
14,
1548,
14,
1483,
492,
16727,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
318,
485,
1123,
774,
8,
396,
63,
533,
12,
1687,
63,
354,
12,
16228,
63,
354,
12,
4325,
304,
523,
511,
63,
354,
275,
2668,
1674,
904,
5234,
396,
401,
1687,
63,
354,
12,
16228,
63,
354,
566,
523,
340,
2688,
8,
396,
63,
533,
12,
511,
63,
354,
304,
272,
746,
6064,
480,
774,
450,
83,
3247,
1655,
2419,
5403,
2,
450,
511,
63,
354,
9,
523,
5371,
8,
396,
63,
533,
12,
511,
63,
354,
12,
4325,
9,
421,
199,
533,
1413,
82,
4619,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
14858,
23370,
8,
277,
304,
272,
327,
710,
1324,
370,
29757,
1077,
506,
282,
2345,
402,
737,
5210,
6915,
499,
14,
272,
6917,
275,
4413,
63,
411,
14,
4083,
8,
17,
4959,
272,
543,
291,
14,
10835,
8,
3393,
12,
639,
298,
7238,
1471,
506,
737,
5210,
6915,
499,
1325,
365,
6915,
378,
2349,
489,
16727,
63,
1483,
14,
16596,
8,
7033,
9,
272,
5477,
275,
4413,
63,
411,
14,
4083,
779,
17,
2020,
499,
14444,
272,
543,
291,
14,
10835,
8,
3393,
12,
639,
298,
7238,
1471,
506,
737,
5210,
6915,
499,
1325,
365,
6915,
413,
2349,
489,
16727,
63,
1483,
14,
16596,
8,
4106,
9,
819,
347,
511,
714,
1818,
4858,
3862,
12450,
547,
8,
277,
304,
272,
543,
291,
14,
1730,
8,
1180,
63,
6477,
29,
549,
9,
465,
4043,
26,
489,
1006,
63,
1483,
275,
942,
489,
367,
2615,
63,
19032,
63,
315,
715,
12,
756,
26,
267,
367,
4730,
63,
315,
841,
12,
959,
26,
881,
367,
8850,
63,
315,
841,
12,
959,
26,
288,
3634,
17,
275,
2196,
63,
1483,
14,
2355,
63,
3302,
779,
3838,
3131,
8850,
63,
467,
6347,
29,
2260,
9,
288,
3634,
18,
275,
2196,
63,
1483,
14,
2355,
63,
3302,
779,
3838,
3131,
8850,
63,
467,
6347,
29,
2260,
9,
288,
1894,
17,
12,
519,
17,
275,
16727,
63,
1483,
14,
16596,
8,
3642,
17,
12,
2615,
63,
19032,
29,
2861,
63,
19032,
4602,
288,
1894,
18,
12,
519,
18,
275,
16727,
63,
1483,
14,
16596,
8,
3642,
18,
12,
2615,
63,
19032,
29,
2861,
63,
19032,
4602,
288,
1006,
63,
1483,
847,
359,
81,
17,
12,
519,
17,
12,
1894,
18,
12,
519,
18,
61,
489,
1139,
275,
4043,
14,
1065,
8,
452,
63,
1483,
9,
489,
367,
284,
315,
1425,
8,
24,
304,
267,
1894,
275,
841,
627,
284,
267,
291,
14,
7069,
8,
637,
59,
81,
467,
1139,
59,
81,
435,
499,
566,
221,
327,
1894,
17,
508,
1894,
18,
267,
291,
14,
7069,
8,
637,
59,
81,
435,
413,
467,
1139,
59,
81,
435,
650,
566,
221,
327,
519,
17,
508,
519,
18,
421,
199,
318,
485,
1002,
49,
82,
4619,
774,
8,
2271,
3131,
2215,
3131,
2615,
63,
19032,
3131,
675,
63,
1986,
63,
1392,
7822,
819,
365,
63,
5254,
275,
2152,
63,
315,
334,
1590,
14,
5254,
772,
12,
980,
14,
5254,
3933,
9,
523,
365,
63,
4780,
275,
2152,
63,
315,
334,
1590,
14,
1609,
708,
12,
980,
14,
5254,
772,
9,
819,
347,
18955,
2844,
273,
19133,
8,
277,
12,
671,
12,
612,
12,
6915,
304,
272,
340,
365,
63,
4780,
26,
489,
9543,
275,
959,
69,
13,
20,
272,
587,
26,
489,
9543,
275,
959,
69,
13,
1079,
272,
327,
2136,
1454,
6540,
314,
1642,
283,
4648,
7,
29069,
11102,
3967,
314,
272,
327,
15748,
1824,
376,
9697,
503,
898,
1783,
5597,
367,
314,
272,
327,
334,
1143,
13,
503,
2763,
13,
9,
2973,
4601,
12,
7447,
5835,
574,
8350,
641,
272,
327,
4514,
2436,
14,
3091,
3548,
626,
3967,
781,
1104,
626,
314,
272,
327,
12627,
402,
15823,
11102,
787,
4137,
695,
25320,
12,
781,
886,
272,
327,
19796,
511,
626,
314,
8520,
11102,
402,
671,
436,
612,
13598,
314,
272,
327,
2011,
4601,
14,
272,
671,
275,
671,
18999,
378,
26,
4648,
61,
272,
612,
275,
612,
18999,
378,
26,
4648,
61,
272,
327,
1413,
365,
1454,
3747,
1536,
370,
2070,
334,
5254,
7669,
6535,
367,
6114,
12627,
395,
272,
327,
880,
781,
7666,
314,
2070,
1642,
14,
272,
3089,
63,
1618,
63,
345,
9636,
275,
980,
14,
1838,
8,
1590,
14,
16081,
8,
89,
12,
671,
395,
446,
18,
12,
18492,
29,
549,
9,
272,
22587,
275,
980,
14,
16081,
8,
1838,
63,
1618,
63,
345,
9636,
12,
980,
14,
2101,
8,
1838,
63,
1618,
63,
345,
9636,
430,
272,
671,
9000,
22587,
272,
291,
14,
7260,
8,
88,
12,
612,
12,
9543,
29,
24504,
9,
819,
347,
2670,
25923,
20030,
8,
277,
12,
282
] |
[
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
3228,
14,
1483,
14,
3442,
63,
1483,
14,
3642,
63,
11668,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
6709,
63,
6743,
199,
504,
3228,
14,
1548,
14,
1483,
492,
16727,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
3473,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
2196,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
421,
199,
318,
485,
1123,
774,
8,
396,
63,
533,
12,
1687,
63,
354,
12,
16228,
63,
354,
12,
4325,
304,
523,
511,
63,
354,
275,
2668,
1674,
904,
5234,
396,
401,
1687,
63,
354,
12,
16228,
63,
354,
566,
523,
340,
2688,
8,
396,
63,
533,
12,
511,
63,
354,
304,
272,
746,
6064,
480,
774,
450,
83,
3247,
1655,
2419,
5403,
2,
450,
511,
63,
354,
9,
523,
5371,
8,
396,
63,
533,
12,
511,
63,
354,
12,
4325,
9,
421,
199,
533,
1413,
82,
4619,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
14858,
23370,
8,
277,
304,
272,
327,
710,
1324,
370,
29757,
1077,
506,
282,
2345,
402,
737,
5210,
6915,
499,
14,
272,
6917,
275,
4413,
63,
411,
14,
4083,
8,
17,
4959,
272,
543,
291,
14,
10835,
8,
3393,
12,
639,
298,
7238,
1471,
506,
737,
5210,
6915,
499,
1325,
365,
6915,
378,
2349,
489,
16727,
63,
1483,
14,
16596,
8,
7033,
9,
272,
5477,
275,
4413,
63,
411,
14,
4083,
779,
17,
2020,
499,
14444,
272,
543,
291,
14,
10835,
8,
3393,
12,
639,
298,
7238,
1471,
506,
737,
5210,
6915,
499,
1325,
365,
6915,
413,
2349,
489,
16727,
63,
1483,
14,
16596,
8,
4106,
9,
819,
347,
511,
714,
1818,
4858,
3862,
12450,
547,
8,
277,
304,
272,
543,
291,
14,
1730,
8,
1180,
63,
6477,
29,
549,
9,
465,
4043,
26,
489,
1006,
63,
1483,
275,
942,
489,
367,
2615,
63,
19032,
63,
315,
715,
12,
756,
26,
267,
367,
4730,
63,
315,
841,
12,
959,
26,
881,
367,
8850,
63,
315,
841,
12,
959,
26,
288,
3634,
17,
275,
2196,
63,
1483,
14,
2355,
63,
3302,
779,
3838,
3131,
8850,
63,
467,
6347,
29,
2260,
9,
288,
3634,
18,
275,
2196,
63,
1483,
14,
2355,
63,
3302,
779,
3838,
3131,
8850,
63,
467,
6347,
29,
2260,
9,
288,
1894,
17,
12,
519,
17,
275,
16727,
63,
1483,
14,
16596,
8,
3642,
17,
12,
2615,
63,
19032,
29,
2861,
63,
19032,
4602,
288,
1894,
18,
12,
519,
18,
275,
16727,
63,
1483,
14,
16596,
8,
3642,
18,
12,
2615,
63,
19032,
29,
2861,
63,
19032,
4602,
288,
1006,
63,
1483,
847,
359,
81,
17,
12,
519,
17,
12,
1894,
18,
12,
519,
18,
61,
489,
1139,
275,
4043,
14,
1065,
8,
452,
63,
1483,
9,
489,
367,
284,
315,
1425,
8,
24,
304,
267,
1894,
275,
841,
627,
284,
267,
291,
14,
7069,
8,
637,
59,
81,
467,
1139,
59,
81,
435,
499,
566,
221,
327,
1894,
17,
508,
1894,
18,
267,
291,
14,
7069,
8,
637,
59,
81,
435,
413,
467,
1139,
59,
81,
435,
650,
566,
221,
327,
519,
17,
508,
519,
18,
421,
199,
318,
485,
1002,
49,
82,
4619,
774,
8,
2271,
3131,
2215,
3131,
2615,
63,
19032,
3131,
675,
63,
1986,
63,
1392,
7822,
819,
365,
63,
5254,
275,
2152,
63,
315,
334,
1590,
14,
5254,
772,
12,
980,
14,
5254,
3933,
9,
523,
365,
63,
4780,
275,
2152,
63,
315,
334,
1590,
14,
1609,
708,
12,
980,
14,
5254,
772,
9,
819,
347,
18955,
2844,
273,
19133,
8,
277,
12,
671,
12,
612,
12,
6915,
304,
272,
340,
365,
63,
4780,
26,
489,
9543,
275,
959,
69,
13,
20,
272,
587,
26,
489,
9543,
275,
959,
69,
13,
1079,
272,
327,
2136,
1454,
6540,
314,
1642,
283,
4648,
7,
29069,
11102,
3967,
314,
272,
327,
15748,
1824,
376,
9697,
503,
898,
1783,
5597,
367,
314,
272,
327,
334,
1143,
13,
503,
2763,
13,
9,
2973,
4601,
12,
7447,
5835,
574,
8350,
641,
272,
327,
4514,
2436,
14,
3091,
3548,
626,
3967,
781,
1104,
626,
314,
272,
327,
12627,
402,
15823,
11102,
787,
4137,
695,
25320,
12,
781,
886,
272,
327,
19796,
511,
626,
314,
8520,
11102,
402,
671,
436,
612,
13598,
314,
272,
327,
2011,
4601,
14,
272,
671,
275,
671,
18999,
378,
26,
4648,
61,
272,
612,
275,
612,
18999,
378,
26,
4648,
61,
272,
327,
1413,
365,
1454,
3747,
1536,
370,
2070,
334,
5254,
7669,
6535,
367,
6114,
12627,
395,
272,
327,
880,
781,
7666,
314,
2070,
1642,
14,
272,
3089,
63,
1618,
63,
345,
9636,
275,
980,
14,
1838,
8,
1590,
14,
16081,
8,
89,
12,
671,
395,
446,
18,
12,
18492,
29,
549,
9,
272,
22587,
275,
980,
14,
16081,
8,
1838,
63,
1618,
63,
345,
9636,
12,
980,
14,
2101,
8,
1838,
63,
1618,
63,
345,
9636,
430,
272,
671,
9000,
22587,
272,
291,
14,
7260,
8,
88,
12,
612,
12,
9543,
29,
24504,
9,
819,
347,
2670,
25923,
20030,
8,
277,
12,
282,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Shyam10/kivy
|
kivy/gesture.py
|
50
|
14632
|
'''
Gesture recognition
===================
This class allows you to easily create new
gestures and compare them::
from kivy.gesture import Gesture, GestureDatabase
# Create a gesture
g = Gesture()
g.add_stroke(point_list=[(1,1), (3,4), (2,1)])
g.normalize()
# Add it to the database
gdb = GestureDatabase()
gdb.add_gesture(g)
# And for the next gesture, try to find it!
g2 = Gesture()
# ...
gdb.find(g2)
.. warning::
You don't really want to do this: it's more of an example of how
to construct gestures dynamically. Typically, you would
need a lot more points, so it's better to record gestures in a file and
reload them to compare later. Look in the examples/gestures directory for
an example of how to do that.
'''
__all__ = ('Gesture', 'GestureDatabase', 'GesturePoint', 'GestureStroke')
import pickle
import base64
import zlib
import math
from kivy.vector import Vector
from io import BytesIO
class GestureDatabase(object):
'''Class to handle a gesture database.'''
def __init__(self):
self.db = []
def add_gesture(self, gesture):
'''Add a new gesture to the database.'''
self.db.append(gesture)
def find(self, gesture, minscore=0.9, rotation_invariant=True):
'''Find a matching gesture in the database.'''
if not gesture:
return
best = None
bestscore = minscore
for g in self.db:
score = g.get_score(gesture, rotation_invariant)
if score < bestscore:
continue
bestscore = score
best = g
if not best:
return
return (bestscore, best)
def gesture_to_str(self, gesture):
'''Convert a gesture into a unique string.'''
io = BytesIO()
p = pickle.Pickler(io)
p.dump(gesture)
data = base64.b64encode(zlib.compress(io.getvalue(), 9))
return data
def str_to_gesture(self, data):
'''Convert a unique string to a gesture.'''
io = BytesIO(zlib.decompress(base64.b64decode(data)))
p = pickle.Unpickler(io)
gesture = p.load()
return gesture
class GesturePoint:
def __init__(self, x, y):
'''Stores the x,y coordinates of a point in the gesture.'''
self.x = float(x)
self.y = float(y)
def scale(self, factor):
''' Scales the point by the given factor.'''
self.x *= factor
self.y *= factor
return self
def __repr__(self):
return 'Mouse_point: %f,%f' % (self.x, self.y)
class GestureStroke:
''' Gestures can be made up of multiple strokes.'''
def __init__(self):
''' A stroke in the gesture.'''
self.points = list()
self.screenpoints = list()
# These return the min and max coordinates of the stroke
@property
def max_x(self):
if len(self.points) == 0:
return 0
return max(self.points, key=lambda pt: pt.x).x
@property
def min_x(self):
if len(self.points) == 0:
return 0
return min(self.points, key=lambda pt: pt.x).x
@property
def max_y(self):
if len(self.points) == 0:
return 0
return max(self.points, key=lambda pt: pt.y).y
@property
def min_y(self):
if len(self.points) == 0:
return 0
return min(self.points, key=lambda pt: pt.y).y
def add_point(self, x, y):
'''
add_point(x=x_pos, y=y_pos)
Adds a point to the stroke.
'''
self.points.append(GesturePoint(x, y))
self.screenpoints.append((x, y))
def scale_stroke(self, scale_factor):
'''
scale_stroke(scale_factor=float)
Scales the stroke down by scale_factor.
'''
self.points = [pt.scale(scale_factor) for pt in self.points]
def points_distance(self, point1, point2):
'''
points_distance(point1=GesturePoint, point2=GesturePoint)
Returns the distance between two GesturePoints.
'''
x = point1.x - point2.x
y = point1.y - point2.y
return math.sqrt(x * x + y * y)
def stroke_length(self, point_list=None):
'''Finds the length of the stroke. If a point list is given,
finds the length of that list.
'''
if point_list is None:
point_list = self.points
gesture_length = 0.0
if len(point_list) <= 1: # If there is only one point -> no length
return gesture_length
for i in range(len(point_list) - 1):
gesture_length += self.points_distance(
point_list[i], point_list[i + 1])
return gesture_length
def normalize_stroke(self, sample_points=32):
'''Normalizes strokes so that every stroke has a standard number of
points. Returns True if stroke is normalized, False if it can't be
normalized. sample_points controls the resolution of the stroke.
'''
# If there is only one point or the length is 0, don't normalize
if len(self.points) <= 1 or self.stroke_length(self.points) == 0.0:
return False
# Calculate how long each point should be in the stroke
target_stroke_size = \
self.stroke_length(self.points) / float(sample_points)
new_points = list()
new_points.append(self.points[0])
# We loop on the points
prev = self.points[0]
src_distance = 0.0
dst_distance = target_stroke_size
for curr in self.points[1:]:
d = self.points_distance(prev, curr)
if d > 0:
prev = curr
src_distance = src_distance + d
# The new point need to be inserted into the
# segment [prev, curr]
while dst_distance < src_distance:
x_dir = curr.x - prev.x
y_dir = curr.y - prev.y
ratio = (src_distance - dst_distance) / d
to_x = x_dir * ratio + prev.x
to_y = y_dir * ratio + prev.y
new_points.append(GesturePoint(to_x, to_y))
dst_distance = self.stroke_length(self.points) / \
float(sample_points) * len(new_points)
# If this happens, we are into troubles...
if not len(new_points) == sample_points:
raise ValueError('Invalid number of strokes points; got '
'%d while it should be %d' %
(len(new_points), sample_points))
self.points = new_points
return True
def center_stroke(self, offset_x, offset_y):
'''Centers the stroke by offseting the points.'''
for point in self.points:
point.x -= offset_x
point.y -= offset_y
class Gesture:
'''A python implementation of a gesture recognition algorithm by
Oleg Dopertchouk: http://www.gamedev.net/reference/articles/article2039.asp
Implemented by Jeiel Aranal (chemikhazi@gmail.com),
released into the public domain.
'''
# Tolerance for evaluation using the '==' operator
DEFAULT_TOLERANCE = 0.1
def __init__(self, tolerance=None):
'''
Gesture([tolerance=float])
Creates a new gesture with an optional matching tolerance value.
'''
self.width = 0.
self.height = 0.
self.gesture_product = 0.
self.strokes = list()
if tolerance is None:
self.tolerance = Gesture.DEFAULT_TOLERANCE
else:
self.tolerance = tolerance
def _scale_gesture(self):
''' Scales down the gesture to a unit of 1.'''
# map() creates a list of min/max coordinates of the strokes
# in the gesture and min()/max() pulls the lowest/highest value
min_x = min([stroke.min_x for stroke in self.strokes])
max_x = max([stroke.max_x for stroke in self.strokes])
min_y = min([stroke.min_y for stroke in self.strokes])
max_y = max([stroke.max_y for stroke in self.strokes])
x_len = max_x - min_x
self.width = x_len
y_len = max_y - min_y
self.height = y_len
scale_factor = max(x_len, y_len)
if scale_factor <= 0.0:
return False
scale_factor = 1.0 / scale_factor
for stroke in self.strokes:
stroke.scale_stroke(scale_factor)
return True
def _center_gesture(self):
''' Centers the Gesture.points of the gesture.'''
total_x = 0.0
total_y = 0.0
total_points = 0
for stroke in self.strokes:
# adds up all the points inside the stroke
stroke_y = sum([pt.y for pt in stroke.points])
stroke_x = sum([pt.x for pt in stroke.points])
total_y += stroke_y
total_x += stroke_x
total_points += len(stroke.points)
if total_points == 0:
return False
# Average to get the offset
total_x /= total_points
total_y /= total_points
# Apply the offset to the strokes
for stroke in self.strokes:
stroke.center_stroke(total_x, total_y)
return True
def add_stroke(self, point_list=None):
'''Adds a stroke to the gesture and returns the Stroke instance.
Optional point_list argument is a list of the mouse points for
the stroke.
'''
self.strokes.append(GestureStroke())
if isinstance(point_list, list) or isinstance(point_list, tuple):
for point in point_list:
if isinstance(point, GesturePoint):
self.strokes[-1].points.append(point)
elif isinstance(point, list) or isinstance(point, tuple):
if len(point) != 2:
raise ValueError("Stroke entry must have 2 values max")
self.strokes[-1].add_point(point[0], point[1])
else:
raise TypeError("The point list should either be "
"tuples of x and y or a list of "
"GesturePoint objects")
elif point_list is not None:
raise ValueError("point_list should be a tuple/list")
return self.strokes[-1]
def normalize(self, stroke_samples=32):
'''Runs the gesture normalization algorithm and calculates the dot
product with self.
'''
if not self._scale_gesture() or not self._center_gesture():
self.gesture_product = False
return False
for stroke in self.strokes:
stroke.normalize_stroke(stroke_samples)
self.gesture_product = self.dot_product(self)
def get_rigid_rotation(self, dstpts):
'''
Extract the rotation to apply to a group of points to minimize the
distance to a second group of points. The two groups of points are
assumed to be centered. This is a simple version that just picks
an angle based on the first point of the gesture.
'''
if len(self.strokes) < 1 or len(self.strokes[0].points) < 1:
return 0
if len(dstpts.strokes) < 1 or len(dstpts.strokes[0].points) < 1:
return 0
p = dstpts.strokes[0].points[0]
target = Vector([p.x, p.y])
source = Vector([p.x, p.y])
return source.angle(target)
def dot_product(self, comparison_gesture):
''' Calculates the dot product of the gesture with another gesture.'''
if len(comparison_gesture.strokes) != len(self.strokes):
return -1
if getattr(comparison_gesture, 'gesture_product', True) is False or \
getattr(self, 'gesture_product', True) is False:
return -1
dot_product = 0.0
for stroke_index, (my_stroke, cmp_stroke) in enumerate(
list(zip(self.strokes, comparison_gesture.strokes))):
for pt_index, (my_point, cmp_point) in enumerate(
list(zip(my_stroke.points, cmp_stroke.points))):
dot_product += (my_point.x * cmp_point.x +
my_point.y * cmp_point.y)
return dot_product
def rotate(self, angle):
g = Gesture()
for stroke in self.strokes:
tmp = []
for j in stroke.points:
v = Vector([j.x, j.y]).rotate(angle)
tmp.append(v)
g.add_stroke(tmp)
g.gesture_product = g.dot_product(g)
return g
def get_score(self, comparison_gesture, rotation_invariant=True):
''' Returns the matching score of the gesture against another gesture.
'''
if isinstance(comparison_gesture, Gesture):
if rotation_invariant:
# get orientation
angle = self.get_rigid_rotation(comparison_gesture)
# rotate the gesture to be in the same frame.
comparison_gesture = comparison_gesture.rotate(angle)
# this is the normal "orientation" code.
score = self.dot_product(comparison_gesture)
if score <= 0:
return score
score /= math.sqrt(
self.gesture_product * comparison_gesture.gesture_product)
return score
def __eq__(self, comparison_gesture):
''' Allows easy comparisons between gesture instances.'''
if isinstance(comparison_gesture, Gesture):
# If the gestures don't have the same number of strokes, its
# definitely not the same gesture
score = self.get_score(comparison_gesture)
if (score > (1.0 - self.tolerance) and
score < (1.0 + self.tolerance)):
return True
else:
return False
else:
return NotImplemented
def __ne__(self, comparison_gesture):
result = self.__eq__(comparison_gesture)
if result is NotImplemented:
return result
else:
return not result
def __lt__(self, comparison_gesture):
raise TypeError("Gesture cannot be evaluated with <")
def __gt__(self, comparison_gesture):
raise TypeError("Gesture cannot be evaluated with >")
def __le__(self, comparison_gesture):
raise TypeError("Gesture cannot be evaluated with <=")
def __ge__(self, comparison_gesture):
raise TypeError("Gesture cannot be evaluated with >=")
|
mit
|
[
2344,
199,
39,
597,
608,
17319,
15415,
199,
1280,
5918,
199,
199,
2765,
1021,
6127,
1265,
370,
16174,
1218,
892,
199,
3199,
1482,
436,
6540,
3062,
447,
339,
687,
17227,
14,
3199,
608,
492,
598,
597,
608,
12,
598,
597,
608,
7243,
339,
327,
2790,
282,
2312,
270,
608,
272,
486,
275,
598,
597,
608,
342,
272,
486,
14,
525,
63,
11473,
8,
1403,
63,
513,
17497,
17,
12,
17,
395,
334,
19,
12,
20,
395,
334,
18,
12,
17,
3948,
272,
486,
14,
7721,
342,
339,
327,
2654,
652,
370,
314,
3050,
272,
12124,
275,
598,
597,
608,
7243,
342,
272,
12124,
14,
525,
63,
3199,
608,
8,
71,
9,
339,
327,
6061,
367,
314,
2163,
2312,
270,
608,
12,
862,
370,
2342,
652,
1,
272,
486,
18,
275,
598,
597,
608,
342,
272,
327,
2263,
272,
12124,
14,
1623,
8,
71,
18,
9,
199,
199,
703,
5721,
447,
8410,
2047,
2793,
1133,
7710,
2934,
370,
886,
642,
26,
652,
1159,
1655,
402,
376,
2893,
402,
4212,
2043,
370,
6982,
2312,
270,
1482,
18774,
14,
26914,
12,
1265,
3955,
2043,
1929,
282,
13918,
1655,
4501,
12,
880,
652,
1159,
8034,
370,
2777,
2312,
270,
1482,
315,
282,
570,
436,
2043,
13101,
3062,
370,
6540,
2945,
14,
12077,
315,
314,
7251,
15,
3199,
1482,
2082,
367,
2043,
376,
2893,
402,
4212,
370,
886,
626,
14,
199,
199,
2344,
199,
199,
363,
452,
363,
275,
661,
39,
597,
608,
297,
283,
39,
597,
608,
7243,
297,
283,
39,
597,
608,
3428,
297,
283,
39,
597,
608,
32492,
358,
199,
199,
646,
5927,
199,
646,
1300,
772,
199,
646,
12472,
199,
646,
3473,
199,
199,
504,
17227,
14,
4106,
492,
11388,
199,
199,
504,
5890,
492,
11808,
421,
199,
533,
598,
597,
608,
7243,
8,
785,
304,
272,
1449,
2543,
370,
2429,
282,
2312,
270,
608,
3050,
10595,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
697,
275,
942,
339,
347,
1050,
63,
3199,
608,
8,
277,
12,
2312,
270,
608,
304,
267,
1449,
1123,
282,
892,
2312,
270,
608,
370,
314,
3050,
10595,
267,
291,
14,
697,
14,
740,
8,
3199,
608,
9,
339,
347,
2342,
8,
277,
12,
2312,
270,
608,
12,
1748,
3397,
29,
16,
14,
25,
12,
13038,
63,
262,
8759,
29,
549,
304,
267,
1449,
6591,
282,
4877,
2312,
270,
608,
315,
314,
3050,
10595,
267,
340,
440,
2312,
270,
608,
26,
288,
372,
398,
5526,
275,
488,
267,
5526,
3397,
275,
1748,
3397,
267,
367,
486,
315,
291,
14,
697,
26,
288,
5396,
275,
486,
14,
362,
63,
3397,
8,
3199,
608,
12,
13038,
63,
262,
8759,
9,
288,
340,
5396,
665,
5526,
3397,
26,
355,
1980,
288,
5526,
3397,
275,
5396,
288,
5526,
275,
486,
267,
340,
440,
5526,
26,
288,
372,
267,
372,
334,
7010,
3397,
12,
5526,
9,
339,
347,
2312,
270,
608,
63,
475,
63,
495,
8,
277,
12,
2312,
270,
608,
304,
267,
1449,
7306,
282,
2312,
270,
608,
1901,
282,
3747,
1059,
10595,
267,
5890,
275,
11808,
342,
267,
299,
275,
5927,
14,
8587,
1435,
8,
2308,
9,
267,
299,
14,
2724,
8,
3199,
608,
9,
267,
666,
275,
1300,
772,
14,
66,
772,
2143,
8,
15371,
14,
6447,
8,
2308,
14,
7150,
1062,
1749,
430,
267,
372,
666,
339,
347,
620,
63,
475,
63,
3199,
608,
8,
277,
12,
666,
304,
267,
1449,
7306,
282,
3747,
1059,
370,
282,
2312,
270,
608,
10595,
267,
5890,
275,
11808,
8,
15371,
14,
14954,
8,
1095,
772,
14,
66,
772,
2708,
8,
576,
1724,
267,
299,
275,
5927,
14,
1358,
23468,
8,
2308,
9,
267,
2312,
270,
608,
275,
299,
14,
912,
342,
267,
372,
2312,
270,
608,
421,
199,
533,
598,
597,
608,
3428,
26,
339,
347,
636,
826,
721,
277,
12,
671,
12,
612,
304,
267,
1449,
4759,
470,
314,
671,
12,
89,
8983,
402,
282,
2376,
315,
314,
2312,
270,
608,
10595,
267,
291,
14,
88,
275,
2069,
8,
88,
9,
267,
291,
14,
89,
275,
2069,
8,
89,
9,
339,
347,
4666,
8,
277,
12,
6535,
304,
267,
1449,
22869,
83,
314,
2376,
701,
314,
1627,
6535,
10595,
267,
291,
14,
88,
9000,
6535,
267,
291,
14,
89,
9000,
6535,
267,
372,
291,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
17141,
63,
1403,
26,
450,
70,
8719,
70,
7,
450,
334,
277,
14,
88,
12,
291,
14,
89,
9,
421,
199,
533,
598,
597,
608,
32492,
26,
272,
1449,
598,
597,
1482,
883,
506,
6326,
1536,
402,
3663,
410,
293,
9246,
10595,
339,
347,
636,
826,
721,
277,
304,
267,
1449,
437,
22824,
315,
314,
2312,
270,
608,
10595,
267,
291,
14,
3438,
275,
769,
342,
267,
291,
14,
5410,
3438,
275,
769,
342,
339,
327,
5723,
372,
314,
1748,
436,
1390,
8983,
402,
314,
22824,
272,
768,
1829,
272,
347,
1390,
63,
88,
8,
277,
304,
267,
340,
822,
8,
277,
14,
3438,
9,
508,
378,
26,
288,
372,
378,
267,
372,
1390,
8,
277,
14,
3438,
12,
790,
29,
2734,
10063,
26,
10063,
14,
88,
680,
88,
339,
768,
1829,
272,
347,
1748,
63,
88,
8,
277,
304,
267,
340,
822,
8,
277,
14,
3438,
9,
508,
378,
26,
288,
372,
378,
267,
372,
1748,
8,
277,
14,
3438,
12,
790,
29,
2734,
10063,
26,
10063,
14,
88,
680,
88,
339,
768,
1829,
272,
347,
1390,
63,
89,
8,
277,
304,
267,
340,
822,
8,
277,
14,
3438,
9,
508,
378,
26,
288,
372,
378,
267,
372,
1390,
8,
277,
14,
3438,
12,
790,
29,
2734,
10063,
26,
10063,
14,
89,
680,
89,
339,
768,
1829,
272,
347,
1748,
63,
89,
8,
277,
304,
267,
340,
822,
8,
277,
14,
3438,
9,
508,
378,
26,
288,
372,
378,
267,
372,
1748,
8,
277,
14,
3438,
12,
790,
29,
2734,
10063,
26,
10063,
14,
89,
680,
89,
339,
347,
1050,
63,
1403,
8,
277,
12,
671,
12,
612,
304,
267,
1449,
267,
1050,
63,
1403,
8,
88,
29,
88,
63,
1712,
12,
612,
29,
89,
63,
1712,
9,
267,
15747,
282,
2376,
370,
314,
22824,
14,
267,
1449,
267,
291,
14,
3438,
14,
740,
8,
39,
597,
608,
3428,
8,
88,
12,
612,
430,
267,
291
] |
[
199,
39,
597,
608,
17319,
15415,
199,
1280,
5918,
199,
199,
2765,
1021,
6127,
1265,
370,
16174,
1218,
892,
199,
3199,
1482,
436,
6540,
3062,
447,
339,
687,
17227,
14,
3199,
608,
492,
598,
597,
608,
12,
598,
597,
608,
7243,
339,
327,
2790,
282,
2312,
270,
608,
272,
486,
275,
598,
597,
608,
342,
272,
486,
14,
525,
63,
11473,
8,
1403,
63,
513,
17497,
17,
12,
17,
395,
334,
19,
12,
20,
395,
334,
18,
12,
17,
3948,
272,
486,
14,
7721,
342,
339,
327,
2654,
652,
370,
314,
3050,
272,
12124,
275,
598,
597,
608,
7243,
342,
272,
12124,
14,
525,
63,
3199,
608,
8,
71,
9,
339,
327,
6061,
367,
314,
2163,
2312,
270,
608,
12,
862,
370,
2342,
652,
1,
272,
486,
18,
275,
598,
597,
608,
342,
272,
327,
2263,
272,
12124,
14,
1623,
8,
71,
18,
9,
199,
199,
703,
5721,
447,
8410,
2047,
2793,
1133,
7710,
2934,
370,
886,
642,
26,
652,
1159,
1655,
402,
376,
2893,
402,
4212,
2043,
370,
6982,
2312,
270,
1482,
18774,
14,
26914,
12,
1265,
3955,
2043,
1929,
282,
13918,
1655,
4501,
12,
880,
652,
1159,
8034,
370,
2777,
2312,
270,
1482,
315,
282,
570,
436,
2043,
13101,
3062,
370,
6540,
2945,
14,
12077,
315,
314,
7251,
15,
3199,
1482,
2082,
367,
2043,
376,
2893,
402,
4212,
370,
886,
626,
14,
199,
199,
2344,
199,
199,
363,
452,
363,
275,
661,
39,
597,
608,
297,
283,
39,
597,
608,
7243,
297,
283,
39,
597,
608,
3428,
297,
283,
39,
597,
608,
32492,
358,
199,
199,
646,
5927,
199,
646,
1300,
772,
199,
646,
12472,
199,
646,
3473,
199,
199,
504,
17227,
14,
4106,
492,
11388,
199,
199,
504,
5890,
492,
11808,
421,
199,
533,
598,
597,
608,
7243,
8,
785,
304,
272,
1449,
2543,
370,
2429,
282,
2312,
270,
608,
3050,
10595,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
697,
275,
942,
339,
347,
1050,
63,
3199,
608,
8,
277,
12,
2312,
270,
608,
304,
267,
1449,
1123,
282,
892,
2312,
270,
608,
370,
314,
3050,
10595,
267,
291,
14,
697,
14,
740,
8,
3199,
608,
9,
339,
347,
2342,
8,
277,
12,
2312,
270,
608,
12,
1748,
3397,
29,
16,
14,
25,
12,
13038,
63,
262,
8759,
29,
549,
304,
267,
1449,
6591,
282,
4877,
2312,
270,
608,
315,
314,
3050,
10595,
267,
340,
440,
2312,
270,
608,
26,
288,
372,
398,
5526,
275,
488,
267,
5526,
3397,
275,
1748,
3397,
267,
367,
486,
315,
291,
14,
697,
26,
288,
5396,
275,
486,
14,
362,
63,
3397,
8,
3199,
608,
12,
13038,
63,
262,
8759,
9,
288,
340,
5396,
665,
5526,
3397,
26,
355,
1980,
288,
5526,
3397,
275,
5396,
288,
5526,
275,
486,
267,
340,
440,
5526,
26,
288,
372,
267,
372,
334,
7010,
3397,
12,
5526,
9,
339,
347,
2312,
270,
608,
63,
475,
63,
495,
8,
277,
12,
2312,
270,
608,
304,
267,
1449,
7306,
282,
2312,
270,
608,
1901,
282,
3747,
1059,
10595,
267,
5890,
275,
11808,
342,
267,
299,
275,
5927,
14,
8587,
1435,
8,
2308,
9,
267,
299,
14,
2724,
8,
3199,
608,
9,
267,
666,
275,
1300,
772,
14,
66,
772,
2143,
8,
15371,
14,
6447,
8,
2308,
14,
7150,
1062,
1749,
430,
267,
372,
666,
339,
347,
620,
63,
475,
63,
3199,
608,
8,
277,
12,
666,
304,
267,
1449,
7306,
282,
3747,
1059,
370,
282,
2312,
270,
608,
10595,
267,
5890,
275,
11808,
8,
15371,
14,
14954,
8,
1095,
772,
14,
66,
772,
2708,
8,
576,
1724,
267,
299,
275,
5927,
14,
1358,
23468,
8,
2308,
9,
267,
2312,
270,
608,
275,
299,
14,
912,
342,
267,
372,
2312,
270,
608,
421,
199,
533,
598,
597,
608,
3428,
26,
339,
347,
636,
826,
721,
277,
12,
671,
12,
612,
304,
267,
1449,
4759,
470,
314,
671,
12,
89,
8983,
402,
282,
2376,
315,
314,
2312,
270,
608,
10595,
267,
291,
14,
88,
275,
2069,
8,
88,
9,
267,
291,
14,
89,
275,
2069,
8,
89,
9,
339,
347,
4666,
8,
277,
12,
6535,
304,
267,
1449,
22869,
83,
314,
2376,
701,
314,
1627,
6535,
10595,
267,
291,
14,
88,
9000,
6535,
267,
291,
14,
89,
9000,
6535,
267,
372,
291,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
283,
17141,
63,
1403,
26,
450,
70,
8719,
70,
7,
450,
334,
277,
14,
88,
12,
291,
14,
89,
9,
421,
199,
533,
598,
597,
608,
32492,
26,
272,
1449,
598,
597,
1482,
883,
506,
6326,
1536,
402,
3663,
410,
293,
9246,
10595,
339,
347,
636,
826,
721,
277,
304,
267,
1449,
437,
22824,
315,
314,
2312,
270,
608,
10595,
267,
291,
14,
3438,
275,
769,
342,
267,
291,
14,
5410,
3438,
275,
769,
342,
339,
327,
5723,
372,
314,
1748,
436,
1390,
8983,
402,
314,
22824,
272,
768,
1829,
272,
347,
1390,
63,
88,
8,
277,
304,
267,
340,
822,
8,
277,
14,
3438,
9,
508,
378,
26,
288,
372,
378,
267,
372,
1390,
8,
277,
14,
3438,
12,
790,
29,
2734,
10063,
26,
10063,
14,
88,
680,
88,
339,
768,
1829,
272,
347,
1748,
63,
88,
8,
277,
304,
267,
340,
822,
8,
277,
14,
3438,
9,
508,
378,
26,
288,
372,
378,
267,
372,
1748,
8,
277,
14,
3438,
12,
790,
29,
2734,
10063,
26,
10063,
14,
88,
680,
88,
339,
768,
1829,
272,
347,
1390,
63,
89,
8,
277,
304,
267,
340,
822,
8,
277,
14,
3438,
9,
508,
378,
26,
288,
372,
378,
267,
372,
1390,
8,
277,
14,
3438,
12,
790,
29,
2734,
10063,
26,
10063,
14,
89,
680,
89,
339,
768,
1829,
272,
347,
1748,
63,
89,
8,
277,
304,
267,
340,
822,
8,
277,
14,
3438,
9,
508,
378,
26,
288,
372,
378,
267,
372,
1748,
8,
277,
14,
3438,
12,
790,
29,
2734,
10063,
26,
10063,
14,
89,
680,
89,
339,
347,
1050,
63,
1403,
8,
277,
12,
671,
12,
612,
304,
267,
1449,
267,
1050,
63,
1403,
8,
88,
29,
88,
63,
1712,
12,
612,
29,
89,
63,
1712,
9,
267,
15747,
282,
2376,
370,
314,
22824,
14,
267,
1449,
267,
291,
14,
3438,
14,
740,
8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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Spicyharambe/spni.github.io
|
opponents/make_images.py
|
1
|
6566
|
import os
import os.path
import sys
import time
import PIL.Image
setup_string_33 = "33***bc185.500.0.0.1_ga0*0*0*0*0*0*0*0*0#/]ua1.0.0.0_ub_uc7.0.30_ud7.0"
setup_string_36 = "36***bc185.500.0.0.1_ga0*0*0*0*0*0*0*0*0#/]a00_b00_c00_d00_w00_x00_y00_z00_ua1.0.0.0_ub_u0_v0_uc7.0.30_ud7.0"
#create error if not exist (not on windows)
if not getattr(__builtins__, "WindowsError", None):
class WindowsError(OSError): pass
#open image file that kkl has made, waiting until it exists and can be opened properly
def open_image_file(filename):
retry_limit = 50 #try 50 times / 10 seconds
retry = 0
while True:
try:
image_file = PIL.Image.open(filename)
return image_file
except IOError:
retry += 1
if retry >= retry_limit:
#opening the image file failed, abort the process
raise
time.sleep(0.2) #wait for the file to be available
#wait for the text file to be deleted before trying to open the image
def wait_for_file_deletion(filename):
while os.path.isfile(filename):
time.sleep(0.2)
#delete a file without caring if it exists
def delete_file(filename):
try:
os.remove(filename)
except (WindowsError, OSError):
pass
#check if the string starts with a kisekae version string (a number, followed by at least two *'s)
def starts_with_version_string(s):
#check for numbers
i = 0
found_digit = False
while i < len(s):
if s[i].isdigit():
found_digit = True #found at least one digit
elif not found_digit:
return False #not a digit, and we haven't found a digit yet, so it's not a version string
else:
break #this isn't a digit, but we found one previously, so proceed to the next stage of the check
i += 1
#we need at least 2 characters left in the string for there to be two *'s left
if len(s) - i < 2:
return False
#check for the two *'s
return s[i] == '*' and s[i+1] == '*'
#get the version string appropriate for the version of image codes used
def get_setup_string(image_list):
if len(image_list) <= 0:
return setup_string_33 #use default string
first_code = image_list[0][1] #get the first image value in the list [0], then the second part of the value (the image description string) [1]
if first_code.startswith("33"):
return setup_string_33
elif first_code.startswith("36"):
return setup_string_36
return setup_string_33 #default setup string
#use the image data to create the images using kkl, and move them to the specified directory
def create_images(image_list, output_directory):
if sys.platform == 'darwin':
kkl_dir = os.path.join( os.path.expanduser("~") , "Library", "Application Support" , "kkl" , "Local Store" )
else :
kkl_dir = os.getenv('APPDATA') + "\\kkl\\Local Store"
separator = "#/]"
#kk version strings
single_version = "33**"
scene_version = single_version + "*"
#the *0*0*0*0*0*0*0*0 removes any extra characters from the previous scene
#there are 9 possible characters, so 8 *'s are needed to remove any extras
#char_removal = "*0*0*0*0*0*0*0*0"
#this scene description removes the foreground crowd, removes the censorship icon, and sets appropriate zoom & screen position settings
scene_str = separator+"ua1.0.31.32_ub_uc8.0.30_ud7.3"
crop_pixels = (0, 0, 600, 1400)
#setup the scene before drawing the requested pictures
#this sets the character position, zoom level, distables interactivity, sets the zoom level and screen position, and removes censor icon
#get a setup string, based on the version of the image descriptions being used
setup_scene = get_setup_string(image_list)
setup_filename = os.path.join(kkl_dir ,"scene_setup_file.txt")
delete_file(os.path.join(kkl_dir , "scene_setup_file..png"))
with open(setup_filename, "w") as f:
f.write(setup_scene)
wait_for_file_deletion(setup_filename)
for image_filename, image_data in image_list:
kkl_basename = os.path.join(kkl_dir , image_filename)
data_filename = kkl_basename + ".txt"
image_kkl_filename = kkl_basename +"..png"
#user can set their own crop values, for easier centering of images
#should have a format of:
#crop_pixels=0, 0, 600, 1400
#or
#crop_pixels=0,0
#to have the other sizes set to automatically produce a 600x1400 pixel image
#note that these values can go off the side of the screen
if image_filename == "crop_pixels":
parts = image_data.split(",")
new_pixels = [int(part.strip()) for part in parts]
if len(parts) < 3:
new_pixels.append(new_pixels[0]+600)
if len(parts) < 4:
new_pixels.append(new_pixels[1]+1400)
crop_pixels = tuple(new_pixels)
#print "new crop pixels:",crop_pixels
continue
#ensure that the correct version string is used
if not starts_with_version_string(image_data):
#assume that no version data is available
image_data = single_version + image_data
write_data = image_data
#print write_data,"\n\n"
#the conversion doesn't always work properly if the image file already exists
delete_file(image_kkl_filename)
#write the image data where kkl can find it
with open(data_filename, "w") as data_file:
data_file.write(write_data)
wait_for_file_deletion(data_filename)
#open the image file produced, waiting until kkl has finished making it
#there are two .'s in the output filename, I don't know why.
image = open_image_file(image_kkl_filename)
#crop the image, and save it to the specified output directory
cropped_image = image.crop( crop_pixels ) #crop to the size used by the game
cropped_image.save(os.path.join(output_directory , image_filename + ".png")) #save to output directory
image.close()
cropped_image.close()
#read image data in from
def read_image_data(filename):
image_data_list = list()
with open(filename, "r") as f:
for line_number, line in enumerate(f):
line = line.strip()
if len(line) <= 0 or line[0] == '#':
continue
try:
image_filename, image_data = line.split("=", 1)
except ValueError:
print "Error - unable to split line number %d: \"%s\"" % (line_number, line)
continue
image_filename = image_filename.strip()
image_data = image_data.strip()
image_data_list.append((image_filename, image_data))
return image_data_list
def make_images(image_data_file, output_directory):
image_data_list = read_image_data(image_data_file)
create_images(image_data_list, output_directory)
#python make_images.xml <character_image_file.txt> <output_directory>
if __name__ == "__main__":
output_directory = "."
if len(sys.argv) > 2:
output_directory = sys.argv[2]
make_images(sys.argv[1], output_directory)
|
mit
|
[
646,
747,
199,
646,
747,
14,
515,
199,
646,
984,
199,
646,
900,
199,
646,
14937,
14,
3491,
199,
199,
2758,
63,
875,
63,
1153,
275,
298,
1153,
9153,
3776,
10233,
14,
5783,
14,
16,
14,
16,
14,
17,
63,
5294,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
3,
15,
61,
1458,
17,
14,
16,
14,
16,
14,
16,
63,
456,
63,
947,
23,
14,
16,
14,
1216,
63,
1181,
23,
14,
16,
2,
199,
2758,
63,
875,
63,
1344,
275,
298,
1344,
9153,
3776,
10233,
14,
5783,
14,
16,
14,
16,
14,
17,
63,
5294,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
3,
15,
61,
65,
383,
63,
66,
383,
63,
67,
383,
63,
68,
383,
63,
87,
383,
63,
88,
383,
63,
89,
383,
63,
90,
383,
63,
1458,
17,
14,
16,
14,
16,
14,
16,
63,
456,
63,
85,
16,
63,
86,
16,
63,
947,
23,
14,
16,
14,
1216,
63,
1181,
23,
14,
16,
2,
421,
199,
3,
981,
1125,
340,
440,
2187,
334,
1397,
641,
10061,
9,
199,
692,
440,
2519,
3460,
10372,
3108,
298,
8647,
547,
401,
488,
304,
272,
1021,
23950,
8,
16719,
304,
986,
199,
199,
3,
1490,
1834,
570,
626,
1022,
9503,
965,
6326,
12,
10923,
5133,
652,
3495,
436,
883,
506,
12123,
7684,
199,
318,
1551,
63,
1569,
63,
493,
8,
1501,
304,
199,
198,
7154,
63,
3097,
275,
5238,
327,
893,
5238,
5431,
1182,
1616,
4696,
199,
198,
7154,
275,
378,
199,
198,
6710,
715,
26,
507,
198,
893,
26,
686,
198,
1569,
63,
493,
275,
14937,
14,
3491,
14,
1490,
8,
1501,
9,
686,
198,
1107,
1834,
63,
493,
1585,
507,
198,
2590,
5925,
26,
686,
198,
7154,
847,
413,
686,
198,
692,
7269,
2356,
7269,
63,
3097,
26,
1585,
198,
3,
21849,
314,
1834,
570,
3405,
12,
12004,
314,
2112,
1585,
198,
3730,
1871,
686,
198,
521,
14,
4532,
8,
16,
14,
18,
9,
327,
2573,
367,
314,
570,
370,
506,
2808,
199,
199,
3,
2573,
367,
314,
1318,
570,
370,
506,
5463,
2544,
9936,
370,
1551,
314,
1834,
199,
318,
3618,
63,
509,
63,
493,
63,
14281,
8,
1501,
304,
199,
198,
6710,
747,
14,
515,
14,
6292,
8,
1501,
304,
507,
198,
521,
14,
4532,
8,
16,
14,
18,
9,
199,
199,
3,
1807,
282,
570,
1928,
286,
9332,
340,
652,
3495,
199,
318,
3145,
63,
493,
8,
1501,
304,
199,
198,
893,
26,
507,
198,
736,
14,
2168,
8,
1501,
9,
199,
198,
2590,
334,
8647,
547,
12,
6440,
304,
507,
198,
1529,
199,
199,
3,
1074,
340,
314,
1059,
9174,
543,
282,
1022,
572,
75,
3624,
1015,
1059,
334,
65,
1329,
12,
9437,
701,
737,
5210,
2877,
627,
7,
83,
9,
199,
318,
9174,
63,
1045,
63,
1023,
63,
875,
8,
83,
304,
199,
198,
3,
1074,
367,
5579,
199,
198,
73,
275,
378,
199,
198,
4214,
63,
8573,
275,
756,
199,
198,
6710,
284,
665,
822,
8,
83,
304,
507,
198,
692,
308,
59,
73,
1055,
13896,
837,
686,
198,
4214,
63,
8573,
275,
715,
327,
4214,
737,
5210,
1373,
10964,
507,
198,
4164,
440,
1911,
63,
8573,
26,
686,
198,
1107,
756,
327,
1397,
282,
10964,
12,
436,
781,
19051,
1133,
1911,
282,
10964,
5966,
12,
880,
652,
1159,
440,
282,
1015,
1059,
507,
198,
2836,
26,
686,
198,
4785,
327,
3749,
5712,
1133,
282,
10964,
12,
1325,
781,
1911,
1373,
10889,
12,
880,
20320,
370,
314,
2163,
9546,
402,
314,
1104,
507,
198,
73,
847,
413,
199,
198,
3,
1129,
1929,
737,
5210,
499,
4110,
3602,
315,
314,
1059,
367,
2337,
370,
506,
2877,
627,
7,
83,
3602,
199,
198,
692,
822,
8,
83,
9,
446,
284,
665,
499,
26,
507,
198,
1107,
756,
199,
198,
3,
1074,
367,
314,
2877,
627,
7,
83,
199,
198,
1107,
308,
59,
73,
61,
508,
13626,
436,
308,
59,
73,
11,
17,
61,
508,
13626,
199,
199,
3,
362,
314,
1015,
1059,
5827,
367,
314,
1015,
402,
1834,
9479,
1202,
199,
318,
664,
63,
2758,
63,
875,
8,
1569,
63,
513,
304,
199,
198,
692,
822,
8,
1569,
63,
513,
9,
2695,
378,
26,
507,
198,
1107,
3272,
63,
875,
63,
1153,
327,
1180,
849,
1059,
18118,
198,
2246,
63,
600,
275,
1834,
63,
513,
59,
16,
1527,
17,
61,
327,
362,
314,
1642,
1834,
574,
315,
314,
769,
359,
16,
467,
2066,
314,
3499,
1777,
402,
314,
574,
334,
1589,
1834,
1369,
1059,
9,
359,
17,
61,
8299,
198,
692,
1642,
63,
600,
14,
2460,
480,
1153,
2349,
507,
198,
1107,
3272,
63,
875,
63,
1153,
199,
198,
4164,
1642,
63,
600,
14,
2460,
480,
1344,
2349,
507,
198,
1107,
3272,
63,
875,
63,
1344,
18118,
198,
1107,
3272,
63,
875,
63,
1153,
327,
885,
3272,
1059,
28550,
199,
3,
1180,
314,
1834,
666,
370,
1218,
314,
5935,
1808,
1022,
9503,
12,
436,
4057,
3062,
370,
314,
2013,
2082,
199,
318,
1218,
63,
4782,
8,
1569,
63,
513,
12,
1072,
63,
3619,
304,
199,
198,
692,
984,
14,
3246,
508,
283,
13245,
356,
507,
198,
75,
9503,
63,
694,
275,
747,
14,
515,
14,
904,
8,
747,
14,
515,
14,
12131,
20793,
531,
2360,
298,
7424,
401,
298,
5039,
12502,
2,
2360,
298,
75,
9503,
2,
2360,
298,
5339,
13874,
2,
776,
199,
198,
2836,
520,
507,
198,
75,
9503,
63,
694,
275,
747,
14,
12959,
360,
28057,
358,
435,
9926,
75,
9503,
1103,
5339,
13874,
2,
8299,
198,
9896,
275,
5426,
15,
8480,
8299,
198,
3,
16247,
1015,
3326,
199,
198,
4780,
63,
1023,
275,
298,
1153,
538,
2,
199,
198,
10436,
63,
1023,
275,
2849,
63,
1023,
435,
22423,
8299,
198,
3,
1589,
627,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
14185,
1263,
2402,
4110,
687,
314,
4136,
13856,
199,
198,
3,
16990,
787,
1749,
3962,
4110,
12,
880,
1695,
627,
7,
83,
787,
4346,
370,
2813,
1263,
13751,
199,
198,
3,
1560,
63,
25818,
275,
8969,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
2,
8299,
198,
3
] |
[
747,
199,
646,
747,
14,
515,
199,
646,
984,
199,
646,
900,
199,
646,
14937,
14,
3491,
199,
199,
2758,
63,
875,
63,
1153,
275,
298,
1153,
9153,
3776,
10233,
14,
5783,
14,
16,
14,
16,
14,
17,
63,
5294,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
3,
15,
61,
1458,
17,
14,
16,
14,
16,
14,
16,
63,
456,
63,
947,
23,
14,
16,
14,
1216,
63,
1181,
23,
14,
16,
2,
199,
2758,
63,
875,
63,
1344,
275,
298,
1344,
9153,
3776,
10233,
14,
5783,
14,
16,
14,
16,
14,
17,
63,
5294,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
3,
15,
61,
65,
383,
63,
66,
383,
63,
67,
383,
63,
68,
383,
63,
87,
383,
63,
88,
383,
63,
89,
383,
63,
90,
383,
63,
1458,
17,
14,
16,
14,
16,
14,
16,
63,
456,
63,
85,
16,
63,
86,
16,
63,
947,
23,
14,
16,
14,
1216,
63,
1181,
23,
14,
16,
2,
421,
199,
3,
981,
1125,
340,
440,
2187,
334,
1397,
641,
10061,
9,
199,
692,
440,
2519,
3460,
10372,
3108,
298,
8647,
547,
401,
488,
304,
272,
1021,
23950,
8,
16719,
304,
986,
199,
199,
3,
1490,
1834,
570,
626,
1022,
9503,
965,
6326,
12,
10923,
5133,
652,
3495,
436,
883,
506,
12123,
7684,
199,
318,
1551,
63,
1569,
63,
493,
8,
1501,
304,
199,
198,
7154,
63,
3097,
275,
5238,
327,
893,
5238,
5431,
1182,
1616,
4696,
199,
198,
7154,
275,
378,
199,
198,
6710,
715,
26,
507,
198,
893,
26,
686,
198,
1569,
63,
493,
275,
14937,
14,
3491,
14,
1490,
8,
1501,
9,
686,
198,
1107,
1834,
63,
493,
1585,
507,
198,
2590,
5925,
26,
686,
198,
7154,
847,
413,
686,
198,
692,
7269,
2356,
7269,
63,
3097,
26,
1585,
198,
3,
21849,
314,
1834,
570,
3405,
12,
12004,
314,
2112,
1585,
198,
3730,
1871,
686,
198,
521,
14,
4532,
8,
16,
14,
18,
9,
327,
2573,
367,
314,
570,
370,
506,
2808,
199,
199,
3,
2573,
367,
314,
1318,
570,
370,
506,
5463,
2544,
9936,
370,
1551,
314,
1834,
199,
318,
3618,
63,
509,
63,
493,
63,
14281,
8,
1501,
304,
199,
198,
6710,
747,
14,
515,
14,
6292,
8,
1501,
304,
507,
198,
521,
14,
4532,
8,
16,
14,
18,
9,
199,
199,
3,
1807,
282,
570,
1928,
286,
9332,
340,
652,
3495,
199,
318,
3145,
63,
493,
8,
1501,
304,
199,
198,
893,
26,
507,
198,
736,
14,
2168,
8,
1501,
9,
199,
198,
2590,
334,
8647,
547,
12,
6440,
304,
507,
198,
1529,
199,
199,
3,
1074,
340,
314,
1059,
9174,
543,
282,
1022,
572,
75,
3624,
1015,
1059,
334,
65,
1329,
12,
9437,
701,
737,
5210,
2877,
627,
7,
83,
9,
199,
318,
9174,
63,
1045,
63,
1023,
63,
875,
8,
83,
304,
199,
198,
3,
1074,
367,
5579,
199,
198,
73,
275,
378,
199,
198,
4214,
63,
8573,
275,
756,
199,
198,
6710,
284,
665,
822,
8,
83,
304,
507,
198,
692,
308,
59,
73,
1055,
13896,
837,
686,
198,
4214,
63,
8573,
275,
715,
327,
4214,
737,
5210,
1373,
10964,
507,
198,
4164,
440,
1911,
63,
8573,
26,
686,
198,
1107,
756,
327,
1397,
282,
10964,
12,
436,
781,
19051,
1133,
1911,
282,
10964,
5966,
12,
880,
652,
1159,
440,
282,
1015,
1059,
507,
198,
2836,
26,
686,
198,
4785,
327,
3749,
5712,
1133,
282,
10964,
12,
1325,
781,
1911,
1373,
10889,
12,
880,
20320,
370,
314,
2163,
9546,
402,
314,
1104,
507,
198,
73,
847,
413,
199,
198,
3,
1129,
1929,
737,
5210,
499,
4110,
3602,
315,
314,
1059,
367,
2337,
370,
506,
2877,
627,
7,
83,
3602,
199,
198,
692,
822,
8,
83,
9,
446,
284,
665,
499,
26,
507,
198,
1107,
756,
199,
198,
3,
1074,
367,
314,
2877,
627,
7,
83,
199,
198,
1107,
308,
59,
73,
61,
508,
13626,
436,
308,
59,
73,
11,
17,
61,
508,
13626,
199,
199,
3,
362,
314,
1015,
1059,
5827,
367,
314,
1015,
402,
1834,
9479,
1202,
199,
318,
664,
63,
2758,
63,
875,
8,
1569,
63,
513,
304,
199,
198,
692,
822,
8,
1569,
63,
513,
9,
2695,
378,
26,
507,
198,
1107,
3272,
63,
875,
63,
1153,
327,
1180,
849,
1059,
18118,
198,
2246,
63,
600,
275,
1834,
63,
513,
59,
16,
1527,
17,
61,
327,
362,
314,
1642,
1834,
574,
315,
314,
769,
359,
16,
467,
2066,
314,
3499,
1777,
402,
314,
574,
334,
1589,
1834,
1369,
1059,
9,
359,
17,
61,
8299,
198,
692,
1642,
63,
600,
14,
2460,
480,
1153,
2349,
507,
198,
1107,
3272,
63,
875,
63,
1153,
199,
198,
4164,
1642,
63,
600,
14,
2460,
480,
1344,
2349,
507,
198,
1107,
3272,
63,
875,
63,
1344,
18118,
198,
1107,
3272,
63,
875,
63,
1153,
327,
885,
3272,
1059,
28550,
199,
3,
1180,
314,
1834,
666,
370,
1218,
314,
5935,
1808,
1022,
9503,
12,
436,
4057,
3062,
370,
314,
2013,
2082,
199,
318,
1218,
63,
4782,
8,
1569,
63,
513,
12,
1072,
63,
3619,
304,
199,
198,
692,
984,
14,
3246,
508,
283,
13245,
356,
507,
198,
75,
9503,
63,
694,
275,
747,
14,
515,
14,
904,
8,
747,
14,
515,
14,
12131,
20793,
531,
2360,
298,
7424,
401,
298,
5039,
12502,
2,
2360,
298,
75,
9503,
2,
2360,
298,
5339,
13874,
2,
776,
199,
198,
2836,
520,
507,
198,
75,
9503,
63,
694,
275,
747,
14,
12959,
360,
28057,
358,
435,
9926,
75,
9503,
1103,
5339,
13874,
2,
8299,
198,
9896,
275,
5426,
15,
8480,
8299,
198,
3,
16247,
1015,
3326,
199,
198,
4780,
63,
1023,
275,
298,
1153,
538,
2,
199,
198,
10436,
63,
1023,
275,
2849,
63,
1023,
435,
22423,
8299,
198,
3,
1589,
627,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
10,
16,
14185,
1263,
2402,
4110,
687,
314,
4136,
13856,
199,
198,
3,
16990,
787,
1749,
3962,
4110,
12,
880,
1695,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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
] |
xbianonpi/Sick-Beard-TPB
|
lib/html5lib/treewalkers/dom.py
|
97
|
1297
|
from xml.dom import Node
import gettext
_ = gettext.gettext
import _base
from html5lib.constants import voidElements
class TreeWalker(_base.NonRecursiveTreeWalker):
def getNodeDetails(self, node):
if node.nodeType == Node.DOCUMENT_TYPE_NODE:
return _base.DOCTYPE, node.name, node.publicId, node.systemId
elif node.nodeType in (Node.TEXT_NODE, Node.CDATA_SECTION_NODE):
return _base.TEXT, node.nodeValue
elif node.nodeType == Node.ELEMENT_NODE:
attrs = {}
for attr in node.attributes.keys():
attr = node.getAttributeNode(attr)
attrs[(attr.namespaceURI,attr.localName)] = attr.value
return (_base.ELEMENT, node.namespaceURI, node.nodeName,
attrs, node.hasChildNodes())
elif node.nodeType == Node.COMMENT_NODE:
return _base.COMMENT, node.nodeValue
elif node.nodeType in (Node.DOCUMENT_NODE, Node.DOCUMENT_FRAGMENT_NODE):
return (_base.DOCUMENT,)
else:
return _base.UNKNOWN, node.nodeType
def getFirstChild(self, node):
return node.firstChild
def getNextSibling(self, node):
return node.nextSibling
def getParentNode(self, node):
return node.parentNode
|
gpl-3.0
|
[
504,
2748,
14,
4556,
492,
5013,
199,
199,
646,
9796,
199,
63,
275,
9796,
14,
5152,
199,
199,
646,
485,
1095,
199,
504,
3517,
21,
773,
14,
5559,
492,
2309,
6255,
199,
199,
533,
12178,
26020,
1547,
1095,
14,
6932,
25122,
3987,
26020,
304,
272,
347,
664,
1716,
11347,
8,
277,
12,
1031,
304,
267,
340,
1031,
14,
12412,
508,
5013,
14,
7884,
63,
2711,
63,
8063,
26,
288,
372,
485,
1095,
14,
16556,
12,
1031,
14,
354,
12,
1031,
14,
25311,
12,
1031,
14,
20150,
398,
916,
1031,
14,
12412,
315,
334,
1716,
14,
3876,
63,
8063,
12,
5013,
14,
14049,
63,
13835,
63,
8063,
304,
288,
372,
485,
1095,
14,
3876,
12,
1031,
14,
17240,
398,
916,
1031,
14,
12412,
508,
5013,
14,
12535,
63,
8063,
26,
288,
3290,
275,
1052,
288,
367,
1921,
315,
1031,
14,
2987,
14,
1612,
837,
355,
1921,
275,
1031,
14,
12956,
1716,
8,
962,
9,
355,
3290,
7528,
962,
14,
27855,
12,
962,
14,
31317,
1874,
275,
1921,
14,
585,
288,
372,
6110,
1095,
14,
12535,
12,
1031,
14,
27855,
12,
1031,
14,
13777,
12,
15324,
3290,
12,
1031,
14,
1989,
3493,
6300,
1012,
398,
916,
1031,
14,
12412,
508,
5013,
14,
10973,
63,
8063,
26,
288,
372,
485,
1095,
14,
10973,
12,
1031,
14,
17240,
398,
916,
1031,
14,
12412,
315,
334,
1716,
14,
7884,
63,
8063,
12,
5013,
14,
7884,
63,
28147,
63,
8063,
304,
288,
372,
6110,
1095,
14,
7884,
4258,
398,
587,
26,
288,
372,
485,
1095,
14,
11588,
12,
1031,
14,
12412,
339,
347,
664,
7147,
3493,
8,
277,
12,
1031,
304,
267,
372,
1031,
14,
22262,
339,
347,
664,
5765,
16016,
8,
277,
12,
1031,
304,
267,
372,
1031,
14,
30336,
339,
347,
664,
6652,
1716,
8,
277,
12,
1031,
304,
267,
372,
1031,
14,
24899,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2748,
14,
4556,
492,
5013,
199,
199,
646,
9796,
199,
63,
275,
9796,
14,
5152,
199,
199,
646,
485,
1095,
199,
504,
3517,
21,
773,
14,
5559,
492,
2309,
6255,
199,
199,
533,
12178,
26020,
1547,
1095,
14,
6932,
25122,
3987,
26020,
304,
272,
347,
664,
1716,
11347,
8,
277,
12,
1031,
304,
267,
340,
1031,
14,
12412,
508,
5013,
14,
7884,
63,
2711,
63,
8063,
26,
288,
372,
485,
1095,
14,
16556,
12,
1031,
14,
354,
12,
1031,
14,
25311,
12,
1031,
14,
20150,
398,
916,
1031,
14,
12412,
315,
334,
1716,
14,
3876,
63,
8063,
12,
5013,
14,
14049,
63,
13835,
63,
8063,
304,
288,
372,
485,
1095,
14,
3876,
12,
1031,
14,
17240,
398,
916,
1031,
14,
12412,
508,
5013,
14,
12535,
63,
8063,
26,
288,
3290,
275,
1052,
288,
367,
1921,
315,
1031,
14,
2987,
14,
1612,
837,
355,
1921,
275,
1031,
14,
12956,
1716,
8,
962,
9,
355,
3290,
7528,
962,
14,
27855,
12,
962,
14,
31317,
1874,
275,
1921,
14,
585,
288,
372,
6110,
1095,
14,
12535,
12,
1031,
14,
27855,
12,
1031,
14,
13777,
12,
15324,
3290,
12,
1031,
14,
1989,
3493,
6300,
1012,
398,
916,
1031,
14,
12412,
508,
5013,
14,
10973,
63,
8063,
26,
288,
372,
485,
1095,
14,
10973,
12,
1031,
14,
17240,
398,
916,
1031,
14,
12412,
315,
334,
1716,
14,
7884,
63,
8063,
12,
5013,
14,
7884,
63,
28147,
63,
8063,
304,
288,
372,
6110,
1095,
14,
7884,
4258,
398,
587,
26,
288,
372,
485,
1095,
14,
11588,
12,
1031,
14,
12412,
339,
347,
664,
7147,
3493,
8,
277,
12,
1031,
304,
267,
372,
1031,
14,
22262,
339,
347,
664,
5765,
16016,
8,
277,
12,
1031,
304,
267,
372,
1031,
14,
30336,
339,
347,
664,
6652,
1716,
8,
277,
12,
1031,
304,
267,
372,
1031,
14,
24899,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
lixt/lily2-gem5
|
src/arch/x86/isa/insts/simd128/floating_point/data_reordering/__init__.py
|
91
|
2324
|
# Copyright (c) 2007 The Hewlett-Packard Development Company
# All rights reserved.
#
# The license below extends only to copyright in the software and shall
# not be construed as granting a license to any other intellectual
# property including but not limited to intellectual property relating
# to a hardware implementation of the functionality of the software
# licensed hereunder. You may use the software subject to the license
# terms below provided that you ensure that this notice is replicated
# unmodified and in its entirety in all distributions of the software,
# modified or unmodified, in source code or in binary form.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Gabe Black
categories = ["unpack_and_interleave",
"shuffle"]
microcode = '''
# SSE instructions
'''
for category in categories:
exec "import %s as cat" % category
microcode += cat.microcode
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
10219,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
199,
8906,
275,
2097,
5301,
63,
460,
63,
1058,
12422,
401,
1598,
298,
11777,
937,
199,
199,
6453,
600,
275,
1449,
199,
3,
428,
899,
15794,
199,
2344,
199,
509,
4637,
315,
9695,
26,
272,
2146,
298,
646,
450,
83,
465,
6230,
2,
450,
4637,
272,
9967,
600,
847,
6230,
14,
6453,
600,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
10219,
710,
27849,
13,
29471,
15290,
15878,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
710,
4190,
5084,
16879,
1454,
370,
4248,
315,
314,
2032,
436,
10989,
199,
3,
440,
506,
950,
431,
68,
465,
16085,
316,
282,
4190,
370,
1263,
1163,
27925,
1264,
1061,
199,
3,
3324,
5893,
1325,
440,
13988,
370,
27925,
1264,
1061,
3324,
4668,
1958,
199,
3,
370,
282,
14991,
4514,
402,
314,
9330,
402,
314,
2032,
199,
3,
18233,
2348,
7138,
14,
221,
2047,
1443,
675,
314,
2032,
5420,
370,
314,
4190,
199,
3,
2895,
5084,
2741,
626,
1265,
4868,
626,
642,
4245,
365,
32436,
199,
3,
24214,
436,
315,
2399,
8039,
369,
315,
1006,
10208,
402,
314,
2032,
12,
199,
3,
6042,
503,
24214,
12,
315,
1350,
1233,
503,
315,
3366,
1824,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
598,
7570,
30593,
199,
199,
8906,
275,
2097,
5301,
63,
460,
63,
1058,
12422,
401,
1598,
298,
11777,
937,
199,
199,
6453,
600,
275,
1449,
199,
3,
428,
899,
15794,
199,
2344,
199,
509,
4637,
315,
9695,
26,
272,
2146,
298,
646,
450,
83,
465,
6230,
2,
450,
4637,
272,
9967,
600,
847,
6230,
14,
6453,
600,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
|
'''
Take picture
============
.. author:: Mathieu Virbel <mat@kivy.org>
Little example to demonstrate how to start an Intent, and get the result.
When you use the Android.startActivityForResult(), the result will be dispatched
into onActivityResult. You can catch the event with the android.activity API
from python-for-android project.
If you want to compile it, don't forget to add the CAMERA permission::
./build.py --name 'TakePicture' --package org.test.takepicture \
--permission CAMERA --version 1 \
--private ~/code/kivy/examples/android/takepicture \
debug installd
'''
__version__ = '0.1'
from kivy.app import App
from os.path import exists
from jnius import autoclass, cast
from android import activity
from functools import partial
from kivy.clock import Clock
from kivy.uix.scatter import Scatter
from kivy.properties import StringProperty
Intent = autoclass('android.content.Intent')
PythonActivity = autoclass('org.renpy.android.PythonActivity')
MediaStore = autoclass('android.provider.MediaStore')
Uri = autoclass('android.net.Uri')
class Picture(Scatter):
source = StringProperty(None)
class TakePictureApp(App):
def build(self):
self.index = 0
activity.bind(on_activity_result=self.on_activity_result)
def get_filename(self):
while True:
self.index += 1
fn = '/sdcard/takepicture{}.png'.format(self.index)
if not exists(fn):
return fn
def take_picture(self):
intent = Intent(MediaStore.ACTION_IMAGE_CAPTURE)
self.last_fn = self.get_filename()
self.uri = Uri.parse('file://' + self.last_fn)
self.uri = cast('android.os.Parcelable', self.uri)
intent.putExtra(MediaStore.EXTRA_OUTPUT, self.uri)
PythonActivity.mActivity.startActivityForResult(intent, 0x123)
def on_activity_result(self, requestCode, resultCode, intent):
if requestCode == 0x123:
Clock.schedule_once(partial(self.add_picture, self.last_fn), 0)
def add_picture(self, fn, *args):
self.root.add_widget(Picture(source=fn, center=self.root.center))
def on_pause(self):
return True
TakePictureApp().run()
|
mit
|
[
2344,
199,
27200,
24945,
199,
5769,
199,
199,
703,
4132,
447,
21066,
29364,
812,
723,
20621,
665,
569,
32,
16941,
14,
1308,
30,
199,
199,
44,
390,
1118,
2893,
370,
23789,
18161,
4212,
370,
1343,
376,
1010,
767,
12,
436,
664,
314,
754,
14,
199,
11423,
1265,
675,
314,
14694,
14,
928,
14350,
1858,
2889,
1062,
314,
754,
911,
506,
7634,
379,
199,
9924,
641,
14350,
2889,
14,
2047,
883,
8579,
314,
1566,
543,
314,
15516,
14,
8240,
3261,
199,
504,
2366,
13,
509,
13,
6238,
2199,
14,
199,
199,
3917,
1265,
2934,
370,
6555,
652,
12,
2793,
1133,
19459,
370,
1050,
314,
445,
1156,
540,
33,
4983,
447,
339,
16605,
1506,
14,
647,
1553,
354,
283,
27200,
29439,
7,
1553,
2491,
5981,
14,
396,
14,
11066,
12538,
971,
288,
1553,
5693,
445,
1156,
540,
33,
1553,
1023,
413,
971,
288,
1553,
4239,
6146,
15,
600,
15,
16941,
15,
8589,
15,
6238,
15,
11066,
12538,
971,
288,
3105,
3907,
68,
199,
199,
2344,
199,
199,
363,
1023,
363,
275,
283,
16,
14,
17,
7,
199,
199,
504,
17227,
14,
571,
492,
4693,
199,
504,
747,
14,
515,
492,
3495,
199,
504,
1335,
8445,
527,
492,
2599,
533,
12,
9106,
199,
504,
15516,
492,
10679,
199,
504,
9143,
492,
7417,
199,
504,
17227,
14,
9597,
492,
32425,
199,
504,
17227,
14,
24263,
14,
13512,
492,
428,
20569,
199,
504,
17227,
14,
3282,
492,
2624,
3697,
421,
199,
607,
767,
275,
2599,
533,
360,
6238,
14,
1317,
14,
607,
767,
358,
199,
4718,
14350,
275,
2599,
533,
360,
1308,
14,
828,
647,
14,
6238,
14,
4718,
14350,
358,
199,
11398,
5502,
275,
2599,
533,
360,
6238,
14,
3780,
14,
11398,
5502,
358,
199,
14014,
275,
2599,
533,
360,
6238,
14,
846,
14,
14014,
358,
421,
199,
533,
19835,
5722,
8,
51,
20569,
304,
272,
1350,
275,
2624,
3697,
8,
403,
9,
421,
199,
533,
18146,
29439,
2640,
8,
2640,
304,
272,
347,
1900,
8,
277,
304,
267,
291,
14,
1080,
275,
378,
267,
10679,
14,
3409,
8,
265,
63,
8240,
63,
1099,
29,
277,
14,
265,
63,
8240,
63,
1099,
9,
339,
347,
664,
63,
1501,
8,
277,
304,
267,
1830,
715,
26,
288,
291,
14,
1080,
847,
413,
288,
4325,
275,
1994,
83,
3833,
1005,
15,
11066,
12538,
31270,
4524,
1370,
908,
8,
277,
14,
1080,
9,
288,
340,
440,
3495,
8,
2324,
304,
355,
372,
4325,
339,
347,
5452,
63,
12538,
8,
277,
304,
267,
21020,
275,
1010,
767,
8,
11398,
5502,
14,
10052,
63,
9438,
63,
28342,
3942,
9,
267,
291,
14,
2019,
63,
2324,
275,
291,
14,
362,
63,
1501,
342,
267,
291,
14,
2302,
275,
738,
322,
14,
1122,
360,
493,
22399,
435,
291,
14,
2019,
63,
2324,
9,
267,
291,
14,
2302,
275,
9106,
360,
6238,
14,
736,
14,
1262,
6067,
461,
297,
291,
14,
2302,
9,
267,
21020,
14,
524,
7426,
8,
11398,
5502,
14,
18555,
63,
8414,
12,
291,
14,
2302,
9,
267,
2018,
14350,
14,
77,
14350,
14,
928,
14350,
1858,
2889,
8,
17456,
12,
378,
88,
4288,
9,
339,
347,
641,
63,
8240,
63,
1099,
8,
277,
12,
1056,
3034,
12,
754,
3034,
12,
21020,
304,
267,
340,
1056,
3034,
508,
378,
88,
4288,
26,
288,
32425,
14,
7211,
63,
5089,
8,
6672,
8,
277,
14,
525,
63,
12538,
12,
291,
14,
2019,
63,
2324,
395,
378,
9,
339,
347,
1050,
63,
12538,
8,
277,
12,
4325,
12,
627,
589,
304,
267,
291,
14,
1231,
14,
525,
63,
3440,
8,
29439,
8,
1365,
29,
2324,
12,
8126,
29,
277,
14,
1231,
14,
4218,
430,
339,
347,
641,
63,
11241,
8,
277,
304,
267,
372,
715,
199,
199,
27200,
29439,
2640,
1252,
1065,
342,
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
] |
[
199,
27200,
24945,
199,
5769,
199,
199,
703,
4132,
447,
21066,
29364,
812,
723,
20621,
665,
569,
32,
16941,
14,
1308,
30,
199,
199,
44,
390,
1118,
2893,
370,
23789,
18161,
4212,
370,
1343,
376,
1010,
767,
12,
436,
664,
314,
754,
14,
199,
11423,
1265,
675,
314,
14694,
14,
928,
14350,
1858,
2889,
1062,
314,
754,
911,
506,
7634,
379,
199,
9924,
641,
14350,
2889,
14,
2047,
883,
8579,
314,
1566,
543,
314,
15516,
14,
8240,
3261,
199,
504,
2366,
13,
509,
13,
6238,
2199,
14,
199,
199,
3917,
1265,
2934,
370,
6555,
652,
12,
2793,
1133,
19459,
370,
1050,
314,
445,
1156,
540,
33,
4983,
447,
339,
16605,
1506,
14,
647,
1553,
354,
283,
27200,
29439,
7,
1553,
2491,
5981,
14,
396,
14,
11066,
12538,
971,
288,
1553,
5693,
445,
1156,
540,
33,
1553,
1023,
413,
971,
288,
1553,
4239,
6146,
15,
600,
15,
16941,
15,
8589,
15,
6238,
15,
11066,
12538,
971,
288,
3105,
3907,
68,
199,
199,
2344,
199,
199,
363,
1023,
363,
275,
283,
16,
14,
17,
7,
199,
199,
504,
17227,
14,
571,
492,
4693,
199,
504,
747,
14,
515,
492,
3495,
199,
504,
1335,
8445,
527,
492,
2599,
533,
12,
9106,
199,
504,
15516,
492,
10679,
199,
504,
9143,
492,
7417,
199,
504,
17227,
14,
9597,
492,
32425,
199,
504,
17227,
14,
24263,
14,
13512,
492,
428,
20569,
199,
504,
17227,
14,
3282,
492,
2624,
3697,
421,
199,
607,
767,
275,
2599,
533,
360,
6238,
14,
1317,
14,
607,
767,
358,
199,
4718,
14350,
275,
2599,
533,
360,
1308,
14,
828,
647,
14,
6238,
14,
4718,
14350,
358,
199,
11398,
5502,
275,
2599,
533,
360,
6238,
14,
3780,
14,
11398,
5502,
358,
199,
14014,
275,
2599,
533,
360,
6238,
14,
846,
14,
14014,
358,
421,
199,
533,
19835,
5722,
8,
51,
20569,
304,
272,
1350,
275,
2624,
3697,
8,
403,
9,
421,
199,
533,
18146,
29439,
2640,
8,
2640,
304,
272,
347,
1900,
8,
277,
304,
267,
291,
14,
1080,
275,
378,
267,
10679,
14,
3409,
8,
265,
63,
8240,
63,
1099,
29,
277,
14,
265,
63,
8240,
63,
1099,
9,
339,
347,
664,
63,
1501,
8,
277,
304,
267,
1830,
715,
26,
288,
291,
14,
1080,
847,
413,
288,
4325,
275,
1994,
83,
3833,
1005,
15,
11066,
12538,
31270,
4524,
1370,
908,
8,
277,
14,
1080,
9,
288,
340,
440,
3495,
8,
2324,
304,
355,
372,
4325,
339,
347,
5452,
63,
12538,
8,
277,
304,
267,
21020,
275,
1010,
767,
8,
11398,
5502,
14,
10052,
63,
9438,
63,
28342,
3942,
9,
267,
291,
14,
2019,
63,
2324,
275,
291,
14,
362,
63,
1501,
342,
267,
291,
14,
2302,
275,
738,
322,
14,
1122,
360,
493,
22399,
435,
291,
14,
2019,
63,
2324,
9,
267,
291,
14,
2302,
275,
9106,
360,
6238,
14,
736,
14,
1262,
6067,
461,
297,
291,
14,
2302,
9,
267,
21020,
14,
524,
7426,
8,
11398,
5502,
14,
18555,
63,
8414,
12,
291,
14,
2302,
9,
267,
2018,
14350,
14,
77,
14350,
14,
928,
14350,
1858,
2889,
8,
17456,
12,
378,
88,
4288,
9,
339,
347,
641,
63,
8240,
63,
1099,
8,
277,
12,
1056,
3034,
12,
754,
3034,
12,
21020,
304,
267,
340,
1056,
3034,
508,
378,
88,
4288,
26,
288,
32425,
14,
7211,
63,
5089,
8,
6672,
8,
277,
14,
525,
63,
12538,
12,
291,
14,
2019,
63,
2324,
395,
378,
9,
339,
347,
1050,
63,
12538,
8,
277,
12,
4325,
12,
627,
589,
304,
267,
291,
14,
1231,
14,
525,
63,
3440,
8,
29439,
8,
1365,
29,
2324,
12,
8126,
29,
277,
14,
1231,
14,
4218,
430,
339,
347,
641,
63,
11241,
8,
277,
304,
267,
372,
715,
199,
199,
27200,
29439,
2640,
1252,
1065,
342,
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,
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
] |
2ndQuadrant/ansible
|
test/units/modules/network/enos/test_enos_config.py
|
45
|
5170
|
#
# (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/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import json
from units.compat.mock import patch
from ansible.modules.network.enos import enos_config
from .enos_module import TestEnosModule, load_fixture
from units.modules.utils import set_module_args
class TestEnosConfigModule(TestEnosModule):
module = enos_config
def setUp(self):
self.patcher_get_config = patch('ansible.modules.network.enos.enos_config.get_config')
self.mock_get_config = self.patcher_get_config.start()
self.patcher_exec_command = patch('ansible.modules.network.enos.enos_config.load_config')
self.mock_exec_command = self.patcher_exec_command.start()
def tearDown(self):
self.patcher_get_config.stop()
self.patcher_exec_command.stop()
def load_fixtures(self, commands=None):
config_file = 'enos_config_config.cfg'
self.mock_get_config.return_value = load_fixture(config_file)
self.mock_exec_command.return_value = 'dummy diff'
def test_enos_config_unchanged(self):
src = load_fixture('enos_config_config.cfg')
set_module_args(dict(src=src))
self.execute_module()
def test_enos_config_src(self):
src = load_fixture('enos_config_src.cfg')
set_module_args(dict(src=src))
commands = ['hostname foo', 'interface ip 13',
'no ip ospf enable']
self.execute_module(changed=True, commands=commands)
def test_enos_config_backup(self):
set_module_args(dict(backup=True))
result = self.execute_module()
self.assertIn('__backup__', result)
def test_enos_config_lines_wo_parents(self):
set_module_args(dict(lines=['hostname foo']))
commands = ['hostname foo']
self.execute_module(changed=True, commands=commands)
def test_enos_config_lines_w_parents(self):
set_module_args(dict(lines=['shutdown'], parents=['interface ip 13']))
commands = ['interface ip 13', 'shutdown']
self.execute_module(changed=True, commands=commands)
def test_enos_config_before(self):
set_module_args(dict(lines=['hostname foo'], before=['test1', 'test2']))
commands = ['test1', 'test2', 'hostname foo']
self.execute_module(changed=True, commands=commands, sort=False)
def test_enos_config_after(self):
set_module_args(dict(lines=['hostname foo'], after=['test1', 'test2']))
commands = ['hostname foo', 'test1', 'test2']
self.execute_module(changed=True, commands=commands, sort=False)
def test_enos_config_before_after_no_change(self):
set_module_args(dict(lines=['hostname router'],
before=['test1', 'test2'],
after=['test3', 'test4']))
self.execute_module()
def test_enos_config_config(self):
config = 'hostname localhost'
set_module_args(dict(lines=['hostname router'], config=config))
commands = ['hostname router']
self.execute_module(changed=True, commands=commands)
def test_enos_config_replace_block(self):
lines = ['description test string', 'test string']
parents = ['interface ip 13']
set_module_args(dict(lines=lines, replace='block', parents=parents))
commands = parents + lines
self.execute_module(changed=True, commands=commands)
def test_enos_config_match_none(self):
lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string']
parents = ['interface ip 13']
set_module_args(dict(lines=lines, parents=parents, match='none'))
commands = parents + lines
self.execute_module(changed=True, commands=commands, sort=False)
def test_enos_config_match_strict(self):
lines = ['ip address 1.2.3.4 255.255.255.0', 'exit']
parents = ['interface ip 13']
set_module_args(dict(lines=lines, parents=parents, match='strict'))
commands = parents + ['exit']
self.execute_module(changed=True, commands=commands, sort=False)
def test_enos_config_match_exact(self):
lines = ['ip address 1.2.3.4 255.255.255.0', 'description test string',
'shutdown']
parents = ['interface ip 13']
set_module_args(dict(lines=lines, parents=parents, match='exact'))
commands = parents + lines
self.execute_module(changed=True, commands=commands, sort=False)
|
gpl-3.0
|
[
3,
199,
3,
334,
67,
9,
7800,
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,
646,
2022,
199,
199,
504,
6204,
14,
5819,
14,
1805,
492,
3371,
199,
504,
3242,
14,
3112,
14,
1200,
14,
287,
736,
492,
655,
736,
63,
888,
199,
504,
1275,
287,
736,
63,
578,
492,
1379,
1327,
736,
2377,
12,
2248,
63,
5997,
199,
199,
504,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
421,
199,
533,
1379,
1327,
736,
2028,
2377,
8,
774,
1327,
736,
2377,
304,
339,
859,
275,
655,
736,
63,
888,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
11238,
63,
362,
63,
888,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
287,
736,
14,
287,
736,
63,
888,
14,
362,
63,
888,
358,
267,
291,
14,
1805,
63,
362,
63,
888,
275,
291,
14,
11238,
63,
362,
63,
888,
14,
928,
342,
267,
291,
14,
11238,
63,
1628,
63,
1531,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
287,
736,
14,
287,
736,
63,
888,
14,
912,
63,
888,
358,
267,
291,
14,
1805,
63,
1628,
63,
1531,
275,
291,
14,
11238,
63,
1628,
63,
1531,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
11238,
63,
362,
63,
888,
14,
2379,
342,
267,
291,
14,
11238,
63,
1628,
63,
1531,
14,
2379,
342,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
304,
267,
1101,
63,
493,
275,
283,
287,
736,
63,
888,
63,
888,
14,
4128,
7,
267,
291,
14,
1805,
63,
362,
63,
888,
14,
1107,
63,
585,
275,
2248,
63,
5997,
8,
888,
63,
493,
9,
267,
291,
14,
1805,
63,
1628,
63,
1531,
14,
1107,
63,
585,
275,
283,
5869,
3915,
7,
339,
347,
511,
63,
287,
736,
63,
888,
63,
16914,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
287,
736,
63,
888,
63,
888,
14,
4128,
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,
287,
736,
63,
888,
63,
2164,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
287,
736,
63,
888,
63,
2164,
14,
4128,
358,
267,
663,
63,
578,
63,
589,
8,
807,
8,
2164,
29,
2164,
430,
267,
3718,
275,
788,
4269,
3925,
297,
283,
3266,
3384,
4944,
297,
490,
283,
889,
3384,
26494,
4756,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
63,
287,
736,
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,
287,
736,
63,
888,
63,
1278,
63,
2027,
63,
8859,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
4269,
3925,
5156,
267,
3718,
275,
788,
4269,
3925,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
63,
287,
736,
63,
888,
63,
1278,
63,
87,
63,
8859,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
8831,
995,
8623,
2968,
3266,
3384,
4944,
5156,
267,
3718,
275,
788,
3266,
3384,
4944,
297,
283,
8831,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
63,
287,
736,
63,
888,
63,
5182,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
4269,
3925,
995,
2544,
2968,
396,
17,
297,
283,
396,
18,
5156,
267,
3718,
275,
788,
396,
17,
297,
283,
396,
18,
297,
283,
4269,
3925,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
12,
4069,
29,
797,
9,
339,
347,
511,
63,
287,
736,
63,
888,
63,
4399,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
4269,
3925,
995,
2410,
2968,
396,
17,
297,
283,
396,
18,
5156,
267,
3718,
275,
788,
4269,
3925,
297,
283,
396,
17,
297,
283,
396,
18,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
12,
4069,
29,
797,
9,
339,
347,
511,
63,
287,
736,
63,
888,
63,
5182,
63,
4399,
63,
889,
63,
1461,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
4269,
6197,
995,
2490,
2544,
2968,
396,
17,
297,
283,
396,
18,
995,
2490,
2410,
2968,
396,
19,
297,
283,
396,
20,
5156,
267,
291,
14,
2526,
63,
578,
342,
339,
347,
511,
63,
287,
736,
63,
888,
63,
888,
8,
277,
304,
267,
1101,
275,
283,
4269,
11667,
7,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
4269,
6197,
995,
1101,
29,
888,
430,
267,
3718,
275,
788,
4269,
6197,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511
] |
[
199,
3,
334,
67,
9,
7800,
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,
646,
2022,
199,
199,
504,
6204,
14,
5819,
14,
1805,
492,
3371,
199,
504,
3242,
14,
3112,
14,
1200,
14,
287,
736,
492,
655,
736,
63,
888,
199,
504,
1275,
287,
736,
63,
578,
492,
1379,
1327,
736,
2377,
12,
2248,
63,
5997,
199,
199,
504,
6204,
14,
3112,
14,
1208,
492,
663,
63,
578,
63,
589,
421,
199,
533,
1379,
1327,
736,
2028,
2377,
8,
774,
1327,
736,
2377,
304,
339,
859,
275,
655,
736,
63,
888,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
11238,
63,
362,
63,
888,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
287,
736,
14,
287,
736,
63,
888,
14,
362,
63,
888,
358,
267,
291,
14,
1805,
63,
362,
63,
888,
275,
291,
14,
11238,
63,
362,
63,
888,
14,
928,
342,
267,
291,
14,
11238,
63,
1628,
63,
1531,
275,
3371,
360,
4853,
14,
3112,
14,
1200,
14,
287,
736,
14,
287,
736,
63,
888,
14,
912,
63,
888,
358,
267,
291,
14,
1805,
63,
1628,
63,
1531,
275,
291,
14,
11238,
63,
1628,
63,
1531,
14,
928,
342,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
11238,
63,
362,
63,
888,
14,
2379,
342,
267,
291,
14,
11238,
63,
1628,
63,
1531,
14,
2379,
342,
339,
347,
2248,
63,
8769,
8,
277,
12,
3718,
29,
403,
304,
267,
1101,
63,
493,
275,
283,
287,
736,
63,
888,
63,
888,
14,
4128,
7,
267,
291,
14,
1805,
63,
362,
63,
888,
14,
1107,
63,
585,
275,
2248,
63,
5997,
8,
888,
63,
493,
9,
267,
291,
14,
1805,
63,
1628,
63,
1531,
14,
1107,
63,
585,
275,
283,
5869,
3915,
7,
339,
347,
511,
63,
287,
736,
63,
888,
63,
16914,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
287,
736,
63,
888,
63,
888,
14,
4128,
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,
287,
736,
63,
888,
63,
2164,
8,
277,
304,
267,
2928,
275,
2248,
63,
5997,
360,
287,
736,
63,
888,
63,
2164,
14,
4128,
358,
267,
663,
63,
578,
63,
589,
8,
807,
8,
2164,
29,
2164,
430,
267,
3718,
275,
788,
4269,
3925,
297,
283,
3266,
3384,
4944,
297,
490,
283,
889,
3384,
26494,
4756,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
63,
287,
736,
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,
287,
736,
63,
888,
63,
1278,
63,
2027,
63,
8859,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
4269,
3925,
5156,
267,
3718,
275,
788,
4269,
3925,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
63,
287,
736,
63,
888,
63,
1278,
63,
87,
63,
8859,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
8831,
995,
8623,
2968,
3266,
3384,
4944,
5156,
267,
3718,
275,
788,
3266,
3384,
4944,
297,
283,
8831,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
63,
287,
736,
63,
888,
63,
5182,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
4269,
3925,
995,
2544,
2968,
396,
17,
297,
283,
396,
18,
5156,
267,
3718,
275,
788,
396,
17,
297,
283,
396,
18,
297,
283,
4269,
3925,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
12,
4069,
29,
797,
9,
339,
347,
511,
63,
287,
736,
63,
888,
63,
4399,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
4269,
3925,
995,
2410,
2968,
396,
17,
297,
283,
396,
18,
5156,
267,
3718,
275,
788,
4269,
3925,
297,
283,
396,
17,
297,
283,
396,
18,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
12,
4069,
29,
797,
9,
339,
347,
511,
63,
287,
736,
63,
888,
63,
5182,
63,
4399,
63,
889,
63,
1461,
8,
277,
304,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
4269,
6197,
995,
2490,
2544,
2968,
396,
17,
297,
283,
396,
18,
995,
2490,
2410,
2968,
396,
19,
297,
283,
396,
20,
5156,
267,
291,
14,
2526,
63,
578,
342,
339,
347,
511,
63,
287,
736,
63,
888,
63,
888,
8,
277,
304,
267,
1101,
275,
283,
4269,
11667,
7,
267,
663,
63,
578,
63,
589,
8,
807,
8,
1278,
2968,
4269,
6197,
995,
1101,
29,
888,
430,
267,
3718,
275,
788,
4269,
6197,
418,
267,
291,
14,
2526,
63,
578,
8,
2489,
29,
549,
12,
3718,
29,
4405,
9,
339,
347,
511,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
madafoo/cjdns
|
node_build/dependencies/libuv/build/gyp/test/lib/TestGyp.py
|
46
|
50586
|
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
TestGyp.py: a testing framework for GYP integration tests.
"""
import collections
from contextlib import contextmanager
import itertools
import os
import random
import re
import shutil
import stat
import subprocess
import sys
import tempfile
import time
import TestCmd
import TestCommon
from TestCommon import __all__
__all__.extend([
'TestGyp',
])
def remove_debug_line_numbers(contents):
"""Function to remove the line numbers from the debug output
of gyp and thus reduce the extreme fragility of the stdout
comparison tests.
"""
lines = contents.splitlines()
# split each line on ":"
lines = [l.split(":", 3) for l in lines]
# join each line back together while ignoring the
# 3rd column which is the line number
lines = [len(l) > 3 and ":".join(l[3:]) or l for l in lines]
return "\n".join(lines)
def match_modulo_line_numbers(contents_a, contents_b):
"""File contents matcher that ignores line numbers."""
contents_a = remove_debug_line_numbers(contents_a)
contents_b = remove_debug_line_numbers(contents_b)
return TestCommon.match_exact(contents_a, contents_b)
@contextmanager
def LocalEnv(local_env):
"""Context manager to provide a local OS environment."""
old_env = os.environ.copy()
os.environ.update(local_env)
try:
yield
finally:
os.environ.clear()
os.environ.update(old_env)
class TestGypBase(TestCommon.TestCommon):
"""
Class for controlling end-to-end tests of gyp generators.
Instantiating this class will create a temporary directory and
arrange for its destruction (via the TestCmd superclass) and
copy all of the non-gyptest files in the directory hierarchy of the
executing script.
The default behavior is to test the 'gyp' or 'gyp.bat' file in the
current directory. An alternative may be specified explicitly on
instantiation, or by setting the TESTGYP_GYP environment variable.
This class should be subclassed for each supported gyp generator
(format). Various abstract methods below define calling signatures
used by the test scripts to invoke builds on the generated build
configuration and to run executables generated by those builds.
"""
formats = []
build_tool = None
build_tool_list = []
_exe = TestCommon.exe_suffix
_obj = TestCommon.obj_suffix
shobj_ = TestCommon.shobj_prefix
_shobj = TestCommon.shobj_suffix
lib_ = TestCommon.lib_prefix
_lib = TestCommon.lib_suffix
dll_ = TestCommon.dll_prefix
_dll = TestCommon.dll_suffix
# Constants to represent different targets.
ALL = '__all__'
DEFAULT = '__default__'
# Constants for different target types.
EXECUTABLE = '__executable__'
STATIC_LIB = '__static_lib__'
SHARED_LIB = '__shared_lib__'
def __init__(self, gyp=None, *args, **kw):
self.origin_cwd = os.path.abspath(os.path.dirname(sys.argv[0]))
self.extra_args = sys.argv[1:]
if not gyp:
gyp = os.environ.get('TESTGYP_GYP')
if not gyp:
if sys.platform == 'win32':
gyp = 'gyp.bat'
else:
gyp = 'gyp'
self.gyp = os.path.abspath(gyp)
self.no_parallel = False
self.formats = [self.format]
self.initialize_build_tool()
kw.setdefault('match', TestCommon.match_exact)
# Put test output in out/testworkarea by default.
# Use temporary names so there are no collisions.
workdir = os.path.join('out', kw.get('workdir', 'testworkarea'))
# Create work area if it doesn't already exist.
if not os.path.isdir(workdir):
os.makedirs(workdir)
kw['workdir'] = tempfile.mktemp(prefix='testgyp.', dir=workdir)
formats = kw.pop('formats', [])
super(TestGypBase, self).__init__(*args, **kw)
real_format = self.format.split('-')[-1]
excluded_formats = set([f for f in formats if f[0] == '!'])
included_formats = set(formats) - excluded_formats
if ('!'+real_format in excluded_formats or
included_formats and real_format not in included_formats):
msg = 'Invalid test for %r format; skipping test.\n'
self.skip_test(msg % self.format)
self.copy_test_configuration(self.origin_cwd, self.workdir)
self.set_configuration(None)
# Set $HOME so that gyp doesn't read the user's actual
# ~/.gyp/include.gypi file, which may contain variables
# and other settings that would change the output.
os.environ['HOME'] = self.workpath()
# Clear $GYP_DEFINES for the same reason.
if 'GYP_DEFINES' in os.environ:
del os.environ['GYP_DEFINES']
# Override the user's language settings, which could
# otherwise make the output vary from what is expected.
os.environ['LC_ALL'] = 'C'
def built_file_must_exist(self, name, type=None, **kw):
"""
Fails the test if the specified built file name does not exist.
"""
return self.must_exist(self.built_file_path(name, type, **kw))
def built_file_must_not_exist(self, name, type=None, **kw):
"""
Fails the test if the specified built file name exists.
"""
return self.must_not_exist(self.built_file_path(name, type, **kw))
def built_file_must_match(self, name, contents, **kw):
"""
Fails the test if the contents of the specified built file name
do not match the specified contents.
"""
return self.must_match(self.built_file_path(name, **kw), contents)
def built_file_must_not_match(self, name, contents, **kw):
"""
Fails the test if the contents of the specified built file name
match the specified contents.
"""
return self.must_not_match(self.built_file_path(name, **kw), contents)
def built_file_must_not_contain(self, name, contents, **kw):
"""
Fails the test if the specified built file name contains the specified
contents.
"""
return self.must_not_contain(self.built_file_path(name, **kw), contents)
def copy_test_configuration(self, source_dir, dest_dir):
"""
Copies the test configuration from the specified source_dir
(the directory in which the test script lives) to the
specified dest_dir (a temporary working directory).
This ignores all files and directories that begin with
the string 'gyptest', and all '.svn' subdirectories.
"""
for root, dirs, files in os.walk(source_dir):
if '.svn' in dirs:
dirs.remove('.svn')
dirs = [ d for d in dirs if not d.startswith('gyptest') ]
files = [ f for f in files if not f.startswith('gyptest') ]
for dirname in dirs:
source = os.path.join(root, dirname)
destination = source.replace(source_dir, dest_dir)
os.mkdir(destination)
if sys.platform != 'win32':
shutil.copystat(source, destination)
for filename in files:
source = os.path.join(root, filename)
destination = source.replace(source_dir, dest_dir)
shutil.copy2(source, destination)
def initialize_build_tool(self):
"""
Initializes the .build_tool attribute.
Searches the .build_tool_list for an executable name on the user's
$PATH. The first tool on the list is used as-is if nothing is found
on the current $PATH.
"""
for build_tool in self.build_tool_list:
if not build_tool:
continue
if os.path.isabs(build_tool):
self.build_tool = build_tool
return
build_tool = self.where_is(build_tool)
if build_tool:
self.build_tool = build_tool
return
if self.build_tool_list:
self.build_tool = self.build_tool_list[0]
def relocate(self, source, destination):
"""
Renames (relocates) the specified source (usually a directory)
to the specified destination, creating the destination directory
first if necessary.
Note: Don't use this as a generic "rename" operation. In the
future, "relocating" parts of a GYP tree may affect the state of
the test to modify the behavior of later method calls.
"""
destination_dir = os.path.dirname(destination)
if not os.path.exists(destination_dir):
self.subdir(destination_dir)
os.rename(source, destination)
def report_not_up_to_date(self):
"""
Reports that a build is not up-to-date.
This provides common reporting for formats that have complicated
conditions for checking whether a build is up-to-date. Formats
that expect exact output from the command (make) can
just set stdout= when they call the run_build() method.
"""
print "Build is not up-to-date:"
print self.banner('STDOUT ')
print self.stdout()
stderr = self.stderr()
if stderr:
print self.banner('STDERR ')
print stderr
def run_gyp(self, gyp_file, *args, **kw):
"""
Runs gyp against the specified gyp_file with the specified args.
"""
# When running gyp, and comparing its output we use a comparitor
# that ignores the line numbers that gyp logs in its debug output.
if kw.pop('ignore_line_numbers', False):
kw.setdefault('match', match_modulo_line_numbers)
# TODO: --depth=. works around Chromium-specific tree climbing.
depth = kw.pop('depth', '.')
run_args = ['--depth='+depth]
run_args.extend(['--format='+f for f in self.formats]);
run_args.append(gyp_file)
if self.no_parallel:
run_args += ['--no-parallel']
# TODO: if extra_args contains a '--build' flag
# we really want that to only apply to the last format (self.format).
run_args.extend(self.extra_args)
# Default xcode_ninja_target_pattern to ^.*$ to fix xcode-ninja tests
xcode_ninja_target_pattern = kw.pop('xcode_ninja_target_pattern', '.*')
run_args.extend(
['-G', 'xcode_ninja_target_pattern=%s' % xcode_ninja_target_pattern])
run_args.extend(args)
return self.run(program=self.gyp, arguments=run_args, **kw)
def run(self, *args, **kw):
"""
Executes a program by calling the superclass .run() method.
This exists to provide a common place to filter out keyword
arguments implemented in this layer, without having to update
the tool-specific subclasses or clutter the tests themselves
with platform-specific code.
"""
if kw.has_key('SYMROOT'):
del kw['SYMROOT']
super(TestGypBase, self).run(*args, **kw)
def set_configuration(self, configuration):
"""
Sets the configuration, to be used for invoking the build
tool and testing potential built output.
"""
self.configuration = configuration
def configuration_dirname(self):
if self.configuration:
return self.configuration.split('|')[0]
else:
return 'Default'
def configuration_buildname(self):
if self.configuration:
return self.configuration
else:
return 'Default'
#
# Abstract methods to be defined by format-specific subclasses.
#
def build(self, gyp_file, target=None, **kw):
"""
Runs a build of the specified target against the configuration
generated from the specified gyp_file.
A 'target' argument of None or the special value TestGyp.DEFAULT
specifies the default argument for the underlying build tool.
A 'target' argument of TestGyp.ALL specifies the 'all' target
(if any) of the underlying build tool.
"""
raise NotImplementedError
def built_file_path(self, name, type=None, **kw):
"""
Returns a path to the specified file name, of the specified type.
"""
raise NotImplementedError
def built_file_basename(self, name, type=None, **kw):
"""
Returns the base name of the specified file name, of the specified type.
A bare=True keyword argument specifies that prefixes and suffixes shouldn't
be applied.
"""
if not kw.get('bare'):
if type == self.EXECUTABLE:
name = name + self._exe
elif type == self.STATIC_LIB:
name = self.lib_ + name + self._lib
elif type == self.SHARED_LIB:
name = self.dll_ + name + self._dll
return name
def run_built_executable(self, name, *args, **kw):
"""
Runs an executable program built from a gyp-generated configuration.
The specified name should be independent of any particular generator.
Subclasses should find the output executable in the appropriate
output build directory, tack on any necessary executable suffix, etc.
"""
raise NotImplementedError
def up_to_date(self, gyp_file, target=None, **kw):
"""
Verifies that a build of the specified target is up to date.
The subclass should implement this by calling build()
(or a reasonable equivalent), checking whatever conditions
will tell it the build was an "up to date" null build, and
failing if it isn't.
"""
raise NotImplementedError
class TestGypGypd(TestGypBase):
"""
Subclass for testing the GYP 'gypd' generator (spit out the
internal data structure as pretty-printed Python).
"""
format = 'gypd'
def __init__(self, gyp=None, *args, **kw):
super(TestGypGypd, self).__init__(*args, **kw)
# gypd implies the use of 'golden' files, so parallelizing conflicts as it
# causes ordering changes.
self.no_parallel = True
class TestGypCustom(TestGypBase):
"""
Subclass for testing the GYP with custom generator
"""
def __init__(self, gyp=None, *args, **kw):
self.format = kw.pop("format")
super(TestGypCustom, self).__init__(*args, **kw)
class TestGypAndroid(TestGypBase):
"""
Subclass for testing the GYP Android makefile generator. Note that
build/envsetup.sh and lunch must have been run before running tests.
"""
format = 'android'
# Note that we can't use mmm as the build tool because ...
# - it builds all targets, whereas we need to pass a target
# - it is a function, whereas the test runner assumes the build tool is a file
# Instead we use make and duplicate the logic from mmm.
build_tool_list = ['make']
# We use our custom target 'gyp_all_modules', as opposed to the 'all_modules'
# target used by mmm, to build only those targets which are part of the gyp
# target 'all'.
ALL = 'gyp_all_modules'
def __init__(self, gyp=None, *args, **kw):
# Android requires build and test output to be inside its source tree.
# We use the following working directory for the test's source, but the
# test's build output still goes to $ANDROID_PRODUCT_OUT.
# Note that some tests explicitly set format='gypd' to invoke the gypd
# backend. This writes to the source tree, but there's no way around this.
kw['workdir'] = os.path.join('/tmp', 'gyptest',
kw.get('workdir', 'testworkarea'))
# We need to remove all gyp outputs from out/. Ths is because some tests
# don't have rules to regenerate output, so they will simply re-use stale
# output if present. Since the test working directory gets regenerated for
# each test run, this can confuse things.
# We don't have a list of build outputs because we don't know which
# dependent targets were built. Instead we delete all gyp-generated output.
# This may be excessive, but should be safe.
out_dir = os.environ['ANDROID_PRODUCT_OUT']
obj_dir = os.path.join(out_dir, 'obj')
shutil.rmtree(os.path.join(obj_dir, 'GYP'), ignore_errors = True)
for x in ['EXECUTABLES', 'STATIC_LIBRARIES', 'SHARED_LIBRARIES']:
for d in os.listdir(os.path.join(obj_dir, x)):
if d.endswith('_gyp_intermediates'):
shutil.rmtree(os.path.join(obj_dir, x, d), ignore_errors = True)
for x in [os.path.join('obj', 'lib'), os.path.join('system', 'lib')]:
for d in os.listdir(os.path.join(out_dir, x)):
if d.endswith('_gyp.so'):
os.remove(os.path.join(out_dir, x, d))
super(TestGypAndroid, self).__init__(*args, **kw)
self._adb_path = os.path.join(os.environ['ANDROID_HOST_OUT'], 'bin', 'adb')
self._device_serial = None
adb_devices_out = self._call_adb(['devices'])
devices = [l.split()[0] for l in adb_devices_out.splitlines()[1:-1]
if l.split()[1] == 'device']
if len(devices) == 0:
self._device_serial = None
else:
if len(devices) > 1:
self._device_serial = random.choice(devices)
else:
self._device_serial = devices[0]
self._call_adb(['root'])
self._to_install = set()
def target_name(self, target):
if target == self.ALL:
return self.ALL
# The default target is 'droid'. However, we want to use our special target
# to build only the gyp target 'all'.
if target in (None, self.DEFAULT):
return self.ALL
return target
_INSTALLABLE_PREFIX = 'Install: '
def build(self, gyp_file, target=None, **kw):
"""
Runs a build using the Android makefiles generated from the specified
gyp_file. This logic is taken from Android's mmm.
"""
arguments = kw.get('arguments', [])[:]
arguments.append(self.target_name(target))
arguments.append('-C')
arguments.append(os.environ['ANDROID_BUILD_TOP'])
kw['arguments'] = arguments
chdir = kw.get('chdir', '')
makefile = os.path.join(self.workdir, chdir, 'GypAndroid.mk')
os.environ['ONE_SHOT_MAKEFILE'] = makefile
result = self.run(program=self.build_tool, **kw)
for l in self.stdout().splitlines():
if l.startswith(TestGypAndroid._INSTALLABLE_PREFIX):
self._to_install.add(os.path.abspath(os.path.join(
os.environ['ANDROID_BUILD_TOP'],
l[len(TestGypAndroid._INSTALLABLE_PREFIX):])))
del os.environ['ONE_SHOT_MAKEFILE']
return result
def android_module(self, group, name, subdir):
if subdir:
name = '%s_%s' % (subdir, name)
if group == 'SHARED_LIBRARIES':
name = 'lib_%s' % name
return '%s_gyp' % name
def intermediates_dir(self, group, module_name):
return os.path.join(os.environ['ANDROID_PRODUCT_OUT'], 'obj', group,
'%s_intermediates' % module_name)
def built_file_path(self, name, type=None, **kw):
"""
Returns a path to the specified file name, of the specified type,
as built by Android. Note that we don't support the configuration
parameter.
"""
# Built files are in $ANDROID_PRODUCT_OUT. This requires copying logic from
# the Android build system.
if type == None or type == self.EXECUTABLE:
return os.path.join(os.environ['ANDROID_PRODUCT_OUT'], 'obj', 'GYP',
'shared_intermediates', name)
subdir = kw.get('subdir')
if type == self.STATIC_LIB:
group = 'STATIC_LIBRARIES'
module_name = self.android_module(group, name, subdir)
return os.path.join(self.intermediates_dir(group, module_name),
'%s.a' % module_name)
if type == self.SHARED_LIB:
group = 'SHARED_LIBRARIES'
module_name = self.android_module(group, name, subdir)
return os.path.join(self.intermediates_dir(group, module_name), 'LINKED',
'%s.so' % module_name)
assert False, 'Unhandled type'
def _adb_failure(self, command, msg, stdout, stderr):
""" Reports a failed adb command and fails the containing test.
Args:
command: The adb command that failed.
msg: The error description.
stdout: The standard output.
stderr: The standard error.
"""
print '%s failed%s' % (' '.join(command), ': %s' % msg if msg else '')
print self.banner('STDOUT ')
stdout.seek(0)
print stdout.read()
print self.banner('STDERR ')
stderr.seek(0)
print stderr.read()
self.fail_test()
def _call_adb(self, command, timeout=15, retry=3):
""" Calls the provided adb command.
If the command fails, the test fails.
Args:
command: The adb command to call.
Returns:
The command's output.
"""
with tempfile.TemporaryFile(bufsize=0) as adb_out:
with tempfile.TemporaryFile(bufsize=0) as adb_err:
adb_command = [self._adb_path]
if self._device_serial:
adb_command += ['-s', self._device_serial]
is_shell = (command[0] == 'shell')
if is_shell:
command = [command[0], '%s; echo "\n$?";' % ' '.join(command[1:])]
adb_command += command
for attempt in xrange(1, retry + 1):
adb_out.seek(0)
adb_out.truncate(0)
adb_err.seek(0)
adb_err.truncate(0)
proc = subprocess.Popen(adb_command, stdout=adb_out, stderr=adb_err)
deadline = time.time() + timeout
timed_out = False
while proc.poll() is None and not timed_out:
time.sleep(1)
timed_out = time.time() > deadline
if timed_out:
print 'Timeout for command %s (attempt %d of %s)' % (
adb_command, attempt, retry)
try:
proc.kill()
except:
pass
else:
break
if proc.returncode != 0: # returncode is None in the case of a timeout.
self._adb_failure(
adb_command, 'retcode=%s' % proc.returncode, adb_out, adb_err)
return
adb_out.seek(0)
output = adb_out.read()
if is_shell:
output = output.splitlines(True)
try:
output[-2] = output[-2].rstrip('\r\n')
output, rc = (''.join(output[:-1]), int(output[-1]))
except ValueError:
self._adb_failure(adb_command, 'unexpected output format',
adb_out, adb_err)
if rc != 0:
self._adb_failure(adb_command, 'exited with %d' % rc, adb_out,
adb_err)
return output
def run_built_executable(self, name, *args, **kw):
"""
Runs an executable program built from a gyp-generated configuration.
"""
match = kw.pop('match', self.match)
executable_file = self.built_file_path(name, type=self.EXECUTABLE, **kw)
if executable_file not in self._to_install:
self.fail_test()
if not self._device_serial:
self.skip_test(message='No devices attached.\n')
storage = self._call_adb(['shell', 'echo', '$ANDROID_DATA']).strip()
if not len(storage):
self.fail_test()
installed = set()
try:
for i in self._to_install:
a = os.path.abspath(
os.path.join(os.environ['ANDROID_BUILD_TOP'], i))
dest = '%s/%s' % (storage, os.path.basename(a))
self._call_adb(['push', os.path.abspath(a), dest])
installed.add(dest)
if i == executable_file:
device_executable = dest
self._call_adb(['shell', 'chmod', '755', device_executable])
out = self._call_adb(
['shell', 'LD_LIBRARY_PATH=$LD_LIBRARY_PATH:%s' % storage,
device_executable],
timeout=60,
retry=1)
out = out.replace('\r\n', '\n')
self._complete(out, kw.pop('stdout', None), None, None, None, match)
finally:
if len(installed):
self._call_adb(['shell', 'rm'] + list(installed))
def match_single_line(self, lines = None, expected_line = None):
"""
Checks that specified line appears in the text.
"""
for line in lines.split('\n'):
if line == expected_line:
return 1
return
def up_to_date(self, gyp_file, target=None, **kw):
"""
Verifies that a build of the specified target is up to date.
"""
kw['stdout'] = ("make: Nothing to be done for `%s'." %
self.target_name(target))
# We need to supply a custom matcher, since we don't want to depend on the
# exact stdout string.
kw['match'] = self.match_single_line
return self.build(gyp_file, target, **kw)
class TestGypCMake(TestGypBase):
"""
Subclass for testing the GYP CMake generator, using cmake's ninja backend.
"""
format = 'cmake'
build_tool_list = ['cmake']
ALL = 'all'
def cmake_build(self, gyp_file, target=None, **kw):
arguments = kw.get('arguments', [])[:]
self.build_tool_list = ['cmake']
self.initialize_build_tool()
chdir = os.path.join(kw.get('chdir', '.'),
'out',
self.configuration_dirname())
kw['chdir'] = chdir
arguments.append('-G')
arguments.append('Ninja')
kw['arguments'] = arguments
stderr = kw.get('stderr', None)
if stderr:
kw['stderr'] = stderr.split('$$$')[0]
self.run(program=self.build_tool, **kw)
def ninja_build(self, gyp_file, target=None, **kw):
arguments = kw.get('arguments', [])[:]
self.build_tool_list = ['ninja']
self.initialize_build_tool()
# Add a -C output/path to the command line.
arguments.append('-C')
arguments.append(os.path.join('out', self.configuration_dirname()))
if target not in (None, self.DEFAULT):
arguments.append(target)
kw['arguments'] = arguments
stderr = kw.get('stderr', None)
if stderr:
stderrs = stderr.split('$$$')
kw['stderr'] = stderrs[1] if len(stderrs) > 1 else ''
return self.run(program=self.build_tool, **kw)
def build(self, gyp_file, target=None, status=0, **kw):
# Two tools must be run to build, cmake and the ninja.
# Allow cmake to succeed when the overall expectation is to fail.
if status is None:
kw['status'] = None
else:
if not isinstance(status, collections.Iterable): status = (status,)
kw['status'] = list(itertools.chain((0,), status))
self.cmake_build(gyp_file, target, **kw)
kw['status'] = status
self.ninja_build(gyp_file, target, **kw)
def run_built_executable(self, name, *args, **kw):
# Enclosing the name in a list avoids prepending the original dir.
program = [self.built_file_path(name, type=self.EXECUTABLE, **kw)]
if sys.platform == 'darwin':
configuration = self.configuration_dirname()
os.environ['DYLD_LIBRARY_PATH'] = os.path.join('out', configuration)
return self.run(program=program, *args, **kw)
def built_file_path(self, name, type=None, **kw):
result = []
chdir = kw.get('chdir')
if chdir:
result.append(chdir)
result.append('out')
result.append(self.configuration_dirname())
if type == self.STATIC_LIB:
if sys.platform != 'darwin':
result.append('obj.target')
elif type == self.SHARED_LIB:
if sys.platform != 'darwin' and sys.platform != 'win32':
result.append('lib.target')
subdir = kw.get('subdir')
if subdir and type != self.SHARED_LIB:
result.append(subdir)
result.append(self.built_file_basename(name, type, **kw))
return self.workpath(*result)
def up_to_date(self, gyp_file, target=None, **kw):
result = self.ninja_build(gyp_file, target, **kw)
if not result:
stdout = self.stdout()
if 'ninja: no work to do' not in stdout:
self.report_not_up_to_date()
self.fail_test()
return result
class TestGypMake(TestGypBase):
"""
Subclass for testing the GYP Make generator.
"""
format = 'make'
build_tool_list = ['make']
ALL = 'all'
def build(self, gyp_file, target=None, **kw):
"""
Runs a Make build using the Makefiles generated from the specified
gyp_file.
"""
arguments = kw.get('arguments', [])[:]
if self.configuration:
arguments.append('BUILDTYPE=' + self.configuration)
if target not in (None, self.DEFAULT):
arguments.append(target)
# Sub-directory builds provide per-gyp Makefiles (i.e.
# Makefile.gyp_filename), so use that if there is no Makefile.
chdir = kw.get('chdir', '')
if not os.path.exists(os.path.join(chdir, 'Makefile')):
print "NO Makefile in " + os.path.join(chdir, 'Makefile')
arguments.insert(0, '-f')
arguments.insert(1, os.path.splitext(gyp_file)[0] + '.Makefile')
kw['arguments'] = arguments
return self.run(program=self.build_tool, **kw)
def up_to_date(self, gyp_file, target=None, **kw):
"""
Verifies that a build of the specified Make target is up to date.
"""
if target in (None, self.DEFAULT):
message_target = 'all'
else:
message_target = target
kw['stdout'] = "make: Nothing to be done for `%s'.\n" % message_target
return self.build(gyp_file, target, **kw)
def run_built_executable(self, name, *args, **kw):
"""
Runs an executable built by Make.
"""
configuration = self.configuration_dirname()
libdir = os.path.join('out', configuration, 'lib')
# TODO(piman): when everything is cross-compile safe, remove lib.target
if sys.platform == 'darwin':
# Mac puts target shared libraries right in the product directory.
configuration = self.configuration_dirname()
os.environ['DYLD_LIBRARY_PATH'] = (
libdir + '.host:' + os.path.join('out', configuration))
else:
os.environ['LD_LIBRARY_PATH'] = libdir + '.host:' + libdir + '.target'
# Enclosing the name in a list avoids prepending the original dir.
program = [self.built_file_path(name, type=self.EXECUTABLE, **kw)]
return self.run(program=program, *args, **kw)
def built_file_path(self, name, type=None, **kw):
"""
Returns a path to the specified file name, of the specified type,
as built by Make.
Built files are in the subdirectory 'out/{configuration}'.
The default is 'out/Default'.
A chdir= keyword argument specifies the source directory
relative to which the output subdirectory can be found.
"type" values of STATIC_LIB or SHARED_LIB append the necessary
prefixes and suffixes to a platform-independent library base name.
A subdir= keyword argument specifies a library subdirectory within
the default 'obj.target'.
"""
result = []
chdir = kw.get('chdir')
if chdir:
result.append(chdir)
configuration = self.configuration_dirname()
result.extend(['out', configuration])
if type == self.STATIC_LIB and sys.platform != 'darwin':
result.append('obj.target')
elif type == self.SHARED_LIB and sys.platform != 'darwin':
result.append('lib.target')
subdir = kw.get('subdir')
if subdir and type != self.SHARED_LIB:
result.append(subdir)
result.append(self.built_file_basename(name, type, **kw))
return self.workpath(*result)
def ConvertToCygpath(path):
"""Convert to cygwin path if we are using cygwin."""
if sys.platform == 'cygwin':
p = subprocess.Popen(['cygpath', path], stdout=subprocess.PIPE)
path = p.communicate()[0].strip()
return path
def FindMSBuildInstallation(msvs_version = 'auto'):
"""Returns path to MSBuild for msvs_version or latest available.
Looks in the registry to find install location of MSBuild.
MSBuild before v4.0 will not build c++ projects, so only use newer versions.
"""
import TestWin
registry = TestWin.Registry()
msvs_to_msbuild = {
'2013': r'12.0',
'2012': r'4.0', # Really v4.0.30319 which comes with .NET 4.5.
'2010': r'4.0'}
msbuild_basekey = r'HKLM\SOFTWARE\Microsoft\MSBuild\ToolsVersions'
if not registry.KeyExists(msbuild_basekey):
print 'Error: could not find MSBuild base registry entry'
return None
msbuild_version = None
if msvs_version in msvs_to_msbuild:
msbuild_test_version = msvs_to_msbuild[msvs_version]
if registry.KeyExists(msbuild_basekey + '\\' + msbuild_test_version):
msbuild_version = msbuild_test_version
else:
print ('Warning: Environment variable GYP_MSVS_VERSION specifies "%s" '
'but corresponding MSBuild "%s" was not found.' %
(msvs_version, msbuild_version))
if not msbuild_version:
for msvs_version in sorted(msvs_to_msbuild, reverse=True):
msbuild_test_version = msvs_to_msbuild[msvs_version]
if registry.KeyExists(msbuild_basekey + '\\' + msbuild_test_version):
msbuild_version = msbuild_test_version
break
if not msbuild_version:
print 'Error: could not find MSBuild registry entry'
return None
msbuild_path = registry.GetValue(msbuild_basekey + '\\' + msbuild_version,
'MSBuildToolsPath')
if not msbuild_path:
print 'Error: could not get MSBuild registry entry value'
return None
return os.path.join(msbuild_path, 'MSBuild.exe')
def FindVisualStudioInstallation():
"""Returns appropriate values for .build_tool and .uses_msbuild fields
of TestGypBase for Visual Studio.
We use the value specified by GYP_MSVS_VERSION. If not specified, we
search %PATH% and %PATHEXT% for a devenv.{exe,bat,...} executable.
Failing that, we search for likely deployment paths.
"""
possible_roots = ['%s:\\Program Files%s' % (chr(drive), suffix)
for drive in range(ord('C'), ord('Z') + 1)
for suffix in ['', ' (x86)']]
possible_paths = {
'2013': r'Microsoft Visual Studio 12.0\Common7\IDE\devenv.com',
'2012': r'Microsoft Visual Studio 11.0\Common7\IDE\devenv.com',
'2010': r'Microsoft Visual Studio 10.0\Common7\IDE\devenv.com',
'2008': r'Microsoft Visual Studio 9.0\Common7\IDE\devenv.com',
'2005': r'Microsoft Visual Studio 8\Common7\IDE\devenv.com'}
possible_roots = [ConvertToCygpath(r) for r in possible_roots]
msvs_version = 'auto'
for flag in (f for f in sys.argv if f.startswith('msvs_version=')):
msvs_version = flag.split('=')[-1]
msvs_version = os.environ.get('GYP_MSVS_VERSION', msvs_version)
if msvs_version in possible_paths:
# Check that the path to the specified GYP_MSVS_VERSION exists.
path = possible_paths[msvs_version]
for r in possible_roots:
build_tool = os.path.join(r, path)
if os.path.exists(build_tool):
uses_msbuild = msvs_version >= '2010'
msbuild_path = FindMSBuildInstallation(msvs_version)
return build_tool, uses_msbuild, msbuild_path
else:
print ('Warning: Environment variable GYP_MSVS_VERSION specifies "%s" '
'but corresponding "%s" was not found.' % (msvs_version, path))
# Neither GYP_MSVS_VERSION nor the path help us out. Iterate through
# the choices looking for a match.
for version in sorted(possible_paths, reverse=True):
path = possible_paths[version]
for r in possible_roots:
build_tool = os.path.join(r, path)
if os.path.exists(build_tool):
uses_msbuild = msvs_version >= '2010'
msbuild_path = FindMSBuildInstallation(msvs_version)
return build_tool, uses_msbuild, msbuild_path
print 'Error: could not find devenv'
sys.exit(1)
class TestGypOnMSToolchain(TestGypBase):
"""
Common subclass for testing generators that target the Microsoft Visual
Studio toolchain (cl, link, dumpbin, etc.)
"""
@staticmethod
def _ComputeVsvarsPath(devenv_path):
devenv_dir = os.path.split(devenv_path)[0]
vsvars_path = os.path.join(devenv_path, '../../Tools/vsvars32.bat')
return vsvars_path
def initialize_build_tool(self):
super(TestGypOnMSToolchain, self).initialize_build_tool()
if sys.platform in ('win32', 'cygwin'):
build_tools = FindVisualStudioInstallation()
self.devenv_path, self.uses_msbuild, self.msbuild_path = build_tools
self.vsvars_path = TestGypOnMSToolchain._ComputeVsvarsPath(
self.devenv_path)
def run_dumpbin(self, *dumpbin_args):
"""Run the dumpbin tool with the specified arguments, and capturing and
returning stdout."""
assert sys.platform in ('win32', 'cygwin')
cmd = os.environ.get('COMSPEC', 'cmd.exe')
arguments = [cmd, '/c', self.vsvars_path, '&&', 'dumpbin']
arguments.extend(dumpbin_args)
proc = subprocess.Popen(arguments, stdout=subprocess.PIPE)
output = proc.communicate()[0]
assert not proc.returncode
return output
class TestGypNinja(TestGypOnMSToolchain):
"""
Subclass for testing the GYP Ninja generator.
"""
format = 'ninja'
build_tool_list = ['ninja']
ALL = 'all'
DEFAULT = 'all'
def run_gyp(self, gyp_file, *args, **kw):
TestGypBase.run_gyp(self, gyp_file, *args, **kw)
def build(self, gyp_file, target=None, **kw):
arguments = kw.get('arguments', [])[:]
# Add a -C output/path to the command line.
arguments.append('-C')
arguments.append(os.path.join('out', self.configuration_dirname()))
if target is None:
target = 'all'
arguments.append(target)
kw['arguments'] = arguments
return self.run(program=self.build_tool, **kw)
def run_built_executable(self, name, *args, **kw):
# Enclosing the name in a list avoids prepending the original dir.
program = [self.built_file_path(name, type=self.EXECUTABLE, **kw)]
if sys.platform == 'darwin':
configuration = self.configuration_dirname()
os.environ['DYLD_LIBRARY_PATH'] = os.path.join('out', configuration)
return self.run(program=program, *args, **kw)
def built_file_path(self, name, type=None, **kw):
result = []
chdir = kw.get('chdir')
if chdir:
result.append(chdir)
result.append('out')
result.append(self.configuration_dirname())
if type == self.STATIC_LIB:
if sys.platform != 'darwin':
result.append('obj')
elif type == self.SHARED_LIB:
if sys.platform != 'darwin' and sys.platform != 'win32':
result.append('lib')
subdir = kw.get('subdir')
if subdir and type != self.SHARED_LIB:
result.append(subdir)
result.append(self.built_file_basename(name, type, **kw))
return self.workpath(*result)
def up_to_date(self, gyp_file, target=None, **kw):
result = self.build(gyp_file, target, **kw)
if not result:
stdout = self.stdout()
if 'ninja: no work to do' not in stdout:
self.report_not_up_to_date()
self.fail_test()
return result
class TestGypMSVS(TestGypOnMSToolchain):
"""
Subclass for testing the GYP Visual Studio generator.
"""
format = 'msvs'
u = r'=== Build: 0 succeeded, 0 failed, (\d+) up-to-date, 0 skipped ==='
up_to_date_re = re.compile(u, re.M)
# Initial None element will indicate to our .initialize_build_tool()
# method below that 'devenv' was not found on %PATH%.
#
# Note: we must use devenv.com to be able to capture build output.
# Directly executing devenv.exe only sends output to BuildLog.htm.
build_tool_list = [None, 'devenv.com']
def initialize_build_tool(self):
super(TestGypMSVS, self).initialize_build_tool()
self.build_tool = self.devenv_path
def build(self, gyp_file, target=None, rebuild=False, clean=False, **kw):
"""
Runs a Visual Studio build using the configuration generated
from the specified gyp_file.
"""
configuration = self.configuration_buildname()
if clean:
build = '/Clean'
elif rebuild:
build = '/Rebuild'
else:
build = '/Build'
arguments = kw.get('arguments', [])[:]
arguments.extend([gyp_file.replace('.gyp', '.sln'),
build, configuration])
# Note: the Visual Studio generator doesn't add an explicit 'all'
# target, so we just treat it the same as the default.
if target not in (None, self.ALL, self.DEFAULT):
arguments.extend(['/Project', target])
if self.configuration:
arguments.extend(['/ProjectConfig', self.configuration])
kw['arguments'] = arguments
return self.run(program=self.build_tool, **kw)
def up_to_date(self, gyp_file, target=None, **kw):
"""
Verifies that a build of the specified Visual Studio target is up to date.
Beware that VS2010 will behave strangely if you build under
C:\USERS\yourname\AppData\Local. It will cause needless work. The ouptut
will be "1 succeeded and 0 up to date". MSBuild tracing reveals that:
"Project 'C:\Users\...\AppData\Local\...vcxproj' not up to date because
'C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 10.0\VC\BIN\1033\CLUI.DLL'
was modified at 02/21/2011 17:03:30, which is newer than '' which was
modified at 01/01/0001 00:00:00.
The workaround is to specify a workdir when instantiating the test, e.g.
test = TestGyp.TestGyp(workdir='workarea')
"""
result = self.build(gyp_file, target, **kw)
if not result:
stdout = self.stdout()
m = self.up_to_date_re.search(stdout)
up_to_date = m and int(m.group(1)) > 0
if not up_to_date:
self.report_not_up_to_date()
self.fail_test()
return result
def run_built_executable(self, name, *args, **kw):
"""
Runs an executable built by Visual Studio.
"""
configuration = self.configuration_dirname()
# Enclosing the name in a list avoids prepending the original dir.
program = [self.built_file_path(name, type=self.EXECUTABLE, **kw)]
return self.run(program=program, *args, **kw)
def built_file_path(self, name, type=None, **kw):
"""
Returns a path to the specified file name, of the specified type,
as built by Visual Studio.
Built files are in a subdirectory that matches the configuration
name. The default is 'Default'.
A chdir= keyword argument specifies the source directory
relative to which the output subdirectory can be found.
"type" values of STATIC_LIB or SHARED_LIB append the necessary
prefixes and suffixes to a platform-independent library base name.
"""
result = []
chdir = kw.get('chdir')
if chdir:
result.append(chdir)
result.append(self.configuration_dirname())
if type == self.STATIC_LIB:
result.append('lib')
result.append(self.built_file_basename(name, type, **kw))
return self.workpath(*result)
class TestGypMSVSNinja(TestGypNinja):
"""
Subclass for testing the GYP Visual Studio Ninja generator.
"""
format = 'msvs-ninja'
def initialize_build_tool(self):
super(TestGypMSVSNinja, self).initialize_build_tool()
# When using '--build', make sure ninja is first in the format list.
self.formats.insert(0, 'ninja')
def build(self, gyp_file, target=None, rebuild=False, clean=False, **kw):
"""
Runs a Visual Studio build using the configuration generated
from the specified gyp_file.
"""
arguments = kw.get('arguments', [])[:]
if target in (None, self.ALL, self.DEFAULT):
# Note: the Visual Studio generator doesn't add an explicit 'all' target.
# This will build each project. This will work if projects are hermetic,
# but may fail if they are not (a project may run more than once).
# It would be nice to supply an all.metaproj for MSBuild.
arguments.extend([gyp_file.replace('.gyp', '.sln')])
else:
# MSBuild documentation claims that one can specify a sln but then build a
# project target like 'msbuild a.sln /t:proj:target' but this format only
# supports 'Clean', 'Rebuild', and 'Publish' (with none meaning Default).
# This limitation is due to the .sln -> .sln.metaproj conversion.
# The ':' is not special, 'proj:target' is a target in the metaproj.
arguments.extend([target+'.vcxproj'])
if clean:
build = 'Clean'
elif rebuild:
build = 'Rebuild'
else:
build = 'Build'
arguments.extend(['/target:'+build])
configuration = self.configuration_buildname()
config = configuration.split('|')
arguments.extend(['/property:Configuration='+config[0]])
if len(config) > 1:
arguments.extend(['/property:Platform='+config[1]])
arguments.extend(['/property:BuildInParallel=false'])
arguments.extend(['/verbosity:minimal'])
kw['arguments'] = arguments
return self.run(program=self.msbuild_path, **kw)
class TestGypXcode(TestGypBase):
"""
Subclass for testing the GYP Xcode generator.
"""
format = 'xcode'
build_tool_list = ['xcodebuild']
phase_script_execution = ("\n"
"PhaseScriptExecution /\\S+/Script-[0-9A-F]+\\.sh\n"
" cd /\\S+\n"
" /bin/sh -c /\\S+/Script-[0-9A-F]+\\.sh\n"
"(make: Nothing to be done for `all'\\.\n)?")
strip_up_to_date_expressions = [
# Various actions or rules can run even when the overall build target
# is up to date. Strip those phases' GYP-generated output.
re.compile(phase_script_execution, re.S),
# The message from distcc_pump can trail the "BUILD SUCCEEDED"
# message, so strip that, too.
re.compile('__________Shutting down distcc-pump include server\n', re.S),
]
up_to_date_endings = (
'Checking Dependencies...\n** BUILD SUCCEEDED **\n', # Xcode 3.0/3.1
'Check dependencies\n** BUILD SUCCEEDED **\n\n', # Xcode 3.2
'Check dependencies\n\n\n** BUILD SUCCEEDED **\n\n', # Xcode 4.2
'Check dependencies\n\n** BUILD SUCCEEDED **\n\n', # Xcode 5.0
)
def build(self, gyp_file, target=None, **kw):
"""
Runs an xcodebuild using the .xcodeproj generated from the specified
gyp_file.
"""
# Be sure we're working with a copy of 'arguments' since we modify it.
# The caller may not be expecting it to be modified.
arguments = kw.get('arguments', [])[:]
arguments.extend(['-project', gyp_file.replace('.gyp', '.xcodeproj')])
if target == self.ALL:
arguments.append('-alltargets',)
elif target not in (None, self.DEFAULT):
arguments.extend(['-target', target])
if self.configuration:
arguments.extend(['-configuration', self.configuration])
symroot = kw.get('SYMROOT', '$SRCROOT/build')
if symroot:
arguments.append('SYMROOT='+symroot)
kw['arguments'] = arguments
# Work around spurious stderr output from Xcode 4, http://crbug.com/181012
match = kw.pop('match', self.match)
def match_filter_xcode(actual, expected):
if actual:
if not TestCmd.is_List(actual):
actual = actual.split('\n')
if not TestCmd.is_List(expected):
expected = expected.split('\n')
actual = [a for a in actual
if 'No recorder, buildTask: <Xcode3BuildTask:' not in a]
return match(actual, expected)
kw['match'] = match_filter_xcode
return self.run(program=self.build_tool, **kw)
def up_to_date(self, gyp_file, target=None, **kw):
"""
Verifies that a build of the specified Xcode target is up to date.
"""
result = self.build(gyp_file, target, **kw)
if not result:
output = self.stdout()
for expression in self.strip_up_to_date_expressions:
output = expression.sub('', output)
if not output.endswith(self.up_to_date_endings):
self.report_not_up_to_date()
self.fail_test()
return result
def run_built_executable(self, name, *args, **kw):
"""
Runs an executable built by xcodebuild.
"""
configuration = self.configuration_dirname()
os.environ['DYLD_LIBRARY_PATH'] = os.path.join('build', configuration)
# Enclosing the name in a list avoids prepending the original dir.
program = [self.built_file_path(name, type=self.EXECUTABLE, **kw)]
return self.run(program=program, *args, **kw)
def built_file_path(self, name, type=None, **kw):
"""
Returns a path to the specified file name, of the specified type,
as built by Xcode.
Built files are in the subdirectory 'build/{configuration}'.
The default is 'build/Default'.
A chdir= keyword argument specifies the source directory
relative to which the output subdirectory can be found.
"type" values of STATIC_LIB or SHARED_LIB append the necessary
prefixes and suffixes to a platform-independent library base name.
"""
result = []
chdir = kw.get('chdir')
if chdir:
result.append(chdir)
configuration = self.configuration_dirname()
result.extend(['build', configuration])
result.append(self.built_file_basename(name, type, **kw))
return self.workpath(*result)
class TestGypXcodeNinja(TestGypXcode):
"""
Subclass for testing the GYP Xcode Ninja generator.
"""
format = 'xcode-ninja'
def initialize_build_tool(self):
super(TestGypXcodeNinja, self).initialize_build_tool()
# When using '--build', make sure ninja is first in the format list.
self.formats.insert(0, 'ninja')
def build(self, gyp_file, target=None, **kw):
"""
Runs an xcodebuild using the .xcodeproj generated from the specified
gyp_file.
"""
build_config = self.configuration
if build_config and build_config.endswith(('-iphoneos',
'-iphonesimulator')):
build_config, sdk = self.configuration.split('-')
kw['arguments'] = kw.get('arguments', []) + ['-sdk', sdk]
with self._build_configuration(build_config):
return super(TestGypXcodeNinja, self).build(
gyp_file.replace('.gyp', '.ninja.gyp'), target, **kw)
@contextmanager
def _build_configuration(self, build_config):
config = self.configuration
self.configuration = build_config
try:
yield
finally:
self.configuration = config
def built_file_path(self, name, type=None, **kw):
result = []
chdir = kw.get('chdir')
if chdir:
result.append(chdir)
result.append('out')
result.append(self.configuration_dirname())
subdir = kw.get('subdir')
if subdir and type != self.SHARED_LIB:
result.append(subdir)
result.append(self.built_file_basename(name, type, **kw))
return self.workpath(*result)
def up_to_date(self, gyp_file, target=None, **kw):
result = self.build(gyp_file, target, **kw)
if not result:
stdout = self.stdout()
if 'ninja: no work to do' not in stdout:
self.report_not_up_to_date()
self.fail_test()
return result
def run_built_executable(self, name, *args, **kw):
"""
Runs an executable built by xcodebuild + ninja.
"""
configuration = self.configuration_dirname()
os.environ['DYLD_LIBRARY_PATH'] = os.path.join('out', configuration)
# Enclosing the name in a list avoids prepending the original dir.
program = [self.built_file_path(name, type=self.EXECUTABLE, **kw)]
return self.run(program=program, *args, **kw)
format_class_list = [
TestGypGypd,
TestGypAndroid,
TestGypCMake,
TestGypMake,
TestGypMSVS,
TestGypMSVSNinja,
TestGypNinja,
TestGypXcode,
TestGypXcodeNinja,
]
def TestGyp(*args, **kw):
"""
Returns an appropriate TestGyp* instance for a specified GYP format.
"""
format = kw.pop('format', os.environ.get('TESTGYP_FORMAT'))
for format_class in format_class_list:
if format == format_class.format:
return format_class(*args, **kw)
raise Exception, "unknown format %r" % format
|
gpl-3.0
|
[
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
774,
13899,
14,
647,
26,
221,
282,
5343,
10059,
367,
25686,
13150,
2295,
14,
199,
624,
199,
199,
646,
5055,
199,
504,
15502,
492,
27608,
199,
646,
7975,
199,
646,
747,
199,
646,
2196,
199,
646,
295,
199,
646,
5145,
199,
646,
5672,
199,
646,
3873,
199,
646,
984,
199,
646,
5549,
199,
646,
900,
199,
199,
646,
1379,
7874,
199,
646,
1379,
7844,
199,
504,
1379,
7844,
492,
636,
452,
363,
199,
199,
363,
452,
4343,
2880,
779,
523,
283,
774,
13899,
297,
199,
566,
421,
199,
318,
2813,
63,
1757,
63,
604,
63,
10548,
8,
4407,
304,
523,
408,
3481,
370,
2813,
314,
1004,
5579,
687,
314,
3105,
1072,
523,
402,
4902,
436,
12850,
7114,
314,
30503,
11101,
2012,
402,
314,
3839,
523,
9132,
2295,
14,
523,
408,
523,
2385,
275,
4072,
14,
7644,
342,
523,
327,
3715,
1924,
1004,
641,
14725,
523,
2385,
275,
359,
76,
14,
1294,
480,
6783,
650,
9,
367,
634,
315,
2385,
61,
523,
327,
4263,
1924,
1004,
1771,
10451,
1830,
17289,
314,
523,
327,
650,
6883,
2763,
1314,
365,
314,
1004,
1329,
523,
2385,
275,
359,
552,
8,
76,
9,
690,
650,
436,
7244,
1674,
904,
8,
76,
59,
19,
5728,
503,
634,
367,
634,
315,
2385,
61,
523,
372,
1867,
78,
1674,
904,
8,
1278,
9,
421,
199,
318,
1336,
63,
1494,
13957,
63,
604,
63,
10548,
8,
4407,
63,
65,
12,
4072,
63,
66,
304,
523,
408,
1173,
4072,
15990,
626,
24010,
1004,
5579,
1041,
523,
4072,
63,
65,
275,
2813,
63,
1757,
63,
604,
63,
10548,
8,
4407,
63,
65,
9,
523,
4072,
63,
66,
275,
2813,
63,
1757,
63,
604,
63,
10548,
8,
4407,
63,
66,
9,
523,
372,
1379,
7844,
14,
1431,
63,
7327,
8,
4407,
63,
65,
12,
4072,
63,
66,
9,
421,
199,
32,
14237,
199,
318,
10111,
7744,
8,
1832,
63,
1813,
304,
523,
408,
2998,
5256,
370,
5647,
282,
2257,
4403,
3734,
1041,
523,
2269,
63,
1813,
275,
747,
14,
2314,
14,
1574,
342,
523,
747,
14,
2314,
14,
873,
8,
1832,
63,
1813,
9,
523,
862,
26,
272,
1995,
523,
3753,
26,
272,
747,
14,
2314,
14,
3584,
342,
272,
747,
14,
2314,
14,
873,
8,
1753,
63,
1813,
9,
421,
199,
533,
25688,
1563,
8,
774,
7844,
14,
774,
7844,
304,
523,
408,
523,
8089,
367,
30350,
1284,
13,
475,
13,
500,
2295,
402,
4902,
16952,
14,
819,
14089,
4466,
1958,
642,
1021,
911,
1218,
282,
7937,
2082,
436,
523,
601,
1842,
367,
2399,
477,
4742,
334,
12897,
314,
1379,
7874,
17035,
9,
436,
523,
1331,
1006,
402,
314,
2222,
13,
6179,
396,
1584,
315,
314,
2082,
14446,
402,
314,
523,
14043,
2884,
14,
819,
710,
849,
5953,
365,
370,
511,
314,
283,
6179,
7,
503,
283,
6179,
14,
13475,
7,
570,
315,
314,
523,
1453,
2082,
14,
221,
1626,
13943,
1443,
506,
2013,
7662,
641,
523,
26621,
12,
503,
701,
4260,
314,
7393,
14884,
63,
14884,
3734,
1750,
14,
819,
961,
1021,
1077,
506,
1007,
28271,
367,
1924,
3748,
4902,
4306,
523,
334,
908,
680,
221,
21107,
1785,
9006,
3102,
5084,
5627,
6358,
17597,
523,
1202,
701,
314,
511,
10554,
370,
12677,
14723,
641,
314,
4046,
1900,
523,
2897,
436,
370,
1255,
31172,
4046,
701,
5204,
14723,
14,
523,
408,
819,
6752,
275,
942,
523,
1900,
63,
3557,
275,
488,
523,
1900,
63,
3557,
63,
513,
275,
942,
819,
485,
5803,
275,
1379,
7844,
14,
5803,
63,
4511,
523,
485,
1113,
275,
1379,
7844,
14,
1113,
63,
4511,
523,
930,
468,
63,
275,
1379,
7844,
14,
13927,
468,
63,
1861,
523,
485,
13927,
468,
275,
1379,
7844,
14,
13927,
468,
63,
4511,
523,
1973,
63,
275,
1379,
7844,
14,
773,
63,
1861,
523,
485,
773,
275,
1379,
7844,
14,
773,
63,
4511,
523,
17112,
63,
275,
1379,
7844,
14,
9259,
63,
1861,
523,
485,
9259,
275,
1379,
7844,
14,
9259,
63,
4511,
819,
327,
22296,
370,
2954,
3365,
4545,
14,
523,
11727,
275,
2560,
452,
12217,
523,
6186,
275,
2560,
885,
12217,
819,
327,
22296,
367,
3365,
1347,
2943,
14,
523,
3651,
4220,
934,
2617,
275,
2560,
5904,
12217,
523,
27815,
63,
5617,
275,
2560,
1986,
63,
773,
12217,
523,
4410,
689,
1149,
63,
5617,
275,
2560,
5555,
63,
773,
12217,
819,
347,
636,
826,
721,
277,
12,
4902,
29,
403,
12,
627,
589,
12,
1011,
829,
304,
272,
291,
14,
6493,
63,
6525,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
2459,
272,
291,
14,
2911,
63,
589,
275,
984,
14,
3020,
59,
17,
2938,
339,
340,
440,
4902,
26,
489,
4902,
275,
747,
14,
2314,
14,
362,
360,
2864,
14884,
63,
14884,
358,
489,
340,
440,
4902,
26,
267,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
881,
4902,
275,
283,
6179,
14,
13475,
7,
267,
587,
26,
881,
4902,
275,
283,
6179,
7,
272,
291,
14,
6179,
275,
747,
14,
515,
14,
4832,
8,
6179,
9,
272,
291,
14,
889,
63,
11887,
275,
756,
339,
291,
14,
6321,
275,
359,
277,
14,
908,
61,
339,
291,
14,
8489,
63,
1506,
63,
3557,
342,
339,
4775,
14,
5486,
360,
1431,
297,
1379,
7844,
14,
1431,
63,
7327,
9,
339,
327,
16280,
511,
1072,
315,
734,
15,
396,
800,
6789,
701,
849,
14,
272,
327,
3645,
7937,
1561,
880,
2337,
787,
949,
30063,
14,
272,
1736,
694,
275,
747,
14,
515,
14,
904,
360,
548,
297,
4775,
14,
362,
360,
19132,
297,
283,
396,
800,
6789,
1333,
272,
327,
2790,
1736,
9150,
340,
652,
3181,
1133,
2575,
2187,
14,
272,
340,
440,
747,
14,
515,
14,
6027,
8,
19132,
304,
489,
747,
14,
8347,
8,
19132,
9,
339,
4775,
459,
19132,
418,
275,
5549,
14,
22136,
8,
1861,
534,
396,
6179,
3130,
2935,
29,
19132,
9,
339,
6752,
275,
4775,
14,
1935,
360,
6321,
297,
3073,
339,
1613,
8,
774,
13899,
1563,
12,
291,
2843,
826,
9308,
589,
12
] |
[
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
199,
774,
13899,
14,
647,
26,
221,
282,
5343,
10059,
367,
25686,
13150,
2295,
14,
199,
624,
199,
199,
646,
5055,
199,
504,
15502,
492,
27608,
199,
646,
7975,
199,
646,
747,
199,
646,
2196,
199,
646,
295,
199,
646,
5145,
199,
646,
5672,
199,
646,
3873,
199,
646,
984,
199,
646,
5549,
199,
646,
900,
199,
199,
646,
1379,
7874,
199,
646,
1379,
7844,
199,
504,
1379,
7844,
492,
636,
452,
363,
199,
199,
363,
452,
4343,
2880,
779,
523,
283,
774,
13899,
297,
199,
566,
421,
199,
318,
2813,
63,
1757,
63,
604,
63,
10548,
8,
4407,
304,
523,
408,
3481,
370,
2813,
314,
1004,
5579,
687,
314,
3105,
1072,
523,
402,
4902,
436,
12850,
7114,
314,
30503,
11101,
2012,
402,
314,
3839,
523,
9132,
2295,
14,
523,
408,
523,
2385,
275,
4072,
14,
7644,
342,
523,
327,
3715,
1924,
1004,
641,
14725,
523,
2385,
275,
359,
76,
14,
1294,
480,
6783,
650,
9,
367,
634,
315,
2385,
61,
523,
327,
4263,
1924,
1004,
1771,
10451,
1830,
17289,
314,
523,
327,
650,
6883,
2763,
1314,
365,
314,
1004,
1329,
523,
2385,
275,
359,
552,
8,
76,
9,
690,
650,
436,
7244,
1674,
904,
8,
76,
59,
19,
5728,
503,
634,
367,
634,
315,
2385,
61,
523,
372,
1867,
78,
1674,
904,
8,
1278,
9,
421,
199,
318,
1336,
63,
1494,
13957,
63,
604,
63,
10548,
8,
4407,
63,
65,
12,
4072,
63,
66,
304,
523,
408,
1173,
4072,
15990,
626,
24010,
1004,
5579,
1041,
523,
4072,
63,
65,
275,
2813,
63,
1757,
63,
604,
63,
10548,
8,
4407,
63,
65,
9,
523,
4072,
63,
66,
275,
2813,
63,
1757,
63,
604,
63,
10548,
8,
4407,
63,
66,
9,
523,
372,
1379,
7844,
14,
1431,
63,
7327,
8,
4407,
63,
65,
12,
4072,
63,
66,
9,
421,
199,
32,
14237,
199,
318,
10111,
7744,
8,
1832,
63,
1813,
304,
523,
408,
2998,
5256,
370,
5647,
282,
2257,
4403,
3734,
1041,
523,
2269,
63,
1813,
275,
747,
14,
2314,
14,
1574,
342,
523,
747,
14,
2314,
14,
873,
8,
1832,
63,
1813,
9,
523,
862,
26,
272,
1995,
523,
3753,
26,
272,
747,
14,
2314,
14,
3584,
342,
272,
747,
14,
2314,
14,
873,
8,
1753,
63,
1813,
9,
421,
199,
533,
25688,
1563,
8,
774,
7844,
14,
774,
7844,
304,
523,
408,
523,
8089,
367,
30350,
1284,
13,
475,
13,
500,
2295,
402,
4902,
16952,
14,
819,
14089,
4466,
1958,
642,
1021,
911,
1218,
282,
7937,
2082,
436,
523,
601,
1842,
367,
2399,
477,
4742,
334,
12897,
314,
1379,
7874,
17035,
9,
436,
523,
1331,
1006,
402,
314,
2222,
13,
6179,
396,
1584,
315,
314,
2082,
14446,
402,
314,
523,
14043,
2884,
14,
819,
710,
849,
5953,
365,
370,
511,
314,
283,
6179,
7,
503,
283,
6179,
14,
13475,
7,
570,
315,
314,
523,
1453,
2082,
14,
221,
1626,
13943,
1443,
506,
2013,
7662,
641,
523,
26621,
12,
503,
701,
4260,
314,
7393,
14884,
63,
14884,
3734,
1750,
14,
819,
961,
1021,
1077,
506,
1007,
28271,
367,
1924,
3748,
4902,
4306,
523,
334,
908,
680,
221,
21107,
1785,
9006,
3102,
5084,
5627,
6358,
17597,
523,
1202,
701,
314,
511,
10554,
370,
12677,
14723,
641,
314,
4046,
1900,
523,
2897,
436,
370,
1255,
31172,
4046,
701,
5204,
14723,
14,
523,
408,
819,
6752,
275,
942,
523,
1900,
63,
3557,
275,
488,
523,
1900,
63,
3557,
63,
513,
275,
942,
819,
485,
5803,
275,
1379,
7844,
14,
5803,
63,
4511,
523,
485,
1113,
275,
1379,
7844,
14,
1113,
63,
4511,
523,
930,
468,
63,
275,
1379,
7844,
14,
13927,
468,
63,
1861,
523,
485,
13927,
468,
275,
1379,
7844,
14,
13927,
468,
63,
4511,
523,
1973,
63,
275,
1379,
7844,
14,
773,
63,
1861,
523,
485,
773,
275,
1379,
7844,
14,
773,
63,
4511,
523,
17112,
63,
275,
1379,
7844,
14,
9259,
63,
1861,
523,
485,
9259,
275,
1379,
7844,
14,
9259,
63,
4511,
819,
327,
22296,
370,
2954,
3365,
4545,
14,
523,
11727,
275,
2560,
452,
12217,
523,
6186,
275,
2560,
885,
12217,
819,
327,
22296,
367,
3365,
1347,
2943,
14,
523,
3651,
4220,
934,
2617,
275,
2560,
5904,
12217,
523,
27815,
63,
5617,
275,
2560,
1986,
63,
773,
12217,
523,
4410,
689,
1149,
63,
5617,
275,
2560,
5555,
63,
773,
12217,
819,
347,
636,
826,
721,
277,
12,
4902,
29,
403,
12,
627,
589,
12,
1011,
829,
304,
272,
291,
14,
6493,
63,
6525,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
8,
1274,
14,
3020,
59,
16,
2459,
272,
291,
14,
2911,
63,
589,
275,
984,
14,
3020,
59,
17,
2938,
339,
340,
440,
4902,
26,
489,
4902,
275,
747,
14,
2314,
14,
362,
360,
2864,
14884,
63,
14884,
358,
489,
340,
440,
4902,
26,
267,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
881,
4902,
275,
283,
6179,
14,
13475,
7,
267,
587,
26,
881,
4902,
275,
283,
6179,
7,
272,
291,
14,
6179,
275,
747,
14,
515,
14,
4832,
8,
6179,
9,
272,
291,
14,
889,
63,
11887,
275,
756,
339,
291,
14,
6321,
275,
359,
277,
14,
908,
61,
339,
291,
14,
8489,
63,
1506,
63,
3557,
342,
339,
4775,
14,
5486,
360,
1431,
297,
1379,
7844,
14,
1431,
63,
7327,
9,
339,
327,
16280,
511,
1072,
315,
734,
15,
396,
800,
6789,
701,
849,
14,
272,
327,
3645,
7937,
1561,
880,
2337,
787,
949,
30063,
14,
272,
1736,
694,
275,
747,
14,
515,
14,
904,
360,
548,
297,
4775,
14,
362,
360,
19132,
297,
283,
396,
800,
6789,
1333,
272,
327,
2790,
1736,
9150,
340,
652,
3181,
1133,
2575,
2187,
14,
272,
340,
440,
747,
14,
515,
14,
6027,
8,
19132,
304,
489,
747,
14,
8347,
8,
19132,
9,
339,
4775,
459,
19132,
418,
275,
5549,
14,
22136,
8,
1861,
534,
396,
6179,
3130,
2935,
29,
19132,
9,
339,
6752,
275,
4775,
14,
1935,
360,
6321,
297,
3073,
339,
1613,
8,
774,
13899,
1563,
12,
291,
2843,
826,
9308,
589,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
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sumexp.py
|
1
|
7948
|
import numpy as np
from scipy._lib._util import _asarray_validated
__all__ = ["logsumexp", "softmax", "log_softmax"]
def logsumexp(a, axis=None, b=None, keepdims=False, return_sign=False):
"""Compute the log of the sum of exponentials of input elements.
Parameters
----------
a : array_like
Input array.
axis : None or int or tuple of ints, optional
Axis or axes over which the sum is taken. By default `axis` is None,
and all elements are summed.
.. versionadded:: 0.11.0
keepdims : bool, optional
If this is set to True, the axes which are reduced are left in the
result as dimensions with size one. With this option, the result
will broadcast correctly against the original array.
.. versionadded:: 0.15.0
b : array-like, optional
Scaling factor for exp(`a`) must be of the same shape as `a` or
broadcastable to `a`. These values may be negative in order to
implement subtraction.
.. versionadded:: 0.12.0
return_sign : bool, optional
If this is set to True, the result will be a pair containing sign
information; if False, results that are negative will be returned
as NaN. Default is False (no sign information).
.. versionadded:: 0.16.0
Returns
-------
res : ndarray
The result, ``np.log(np.sum(np.exp(a)))`` calculated in a numerically
more stable way. If `b` is given then ``np.log(np.sum(b*np.exp(a)))``
is returned.
sgn : ndarray
If return_sign is True, this will be an array of floating-point
numbers matching res and +1, 0, or -1 depending on the sign
of the result. If False, only one result is returned.
See Also
--------
numpy.logaddexp, numpy.logaddexp2
Notes
-----
NumPy has a logaddexp function which is very similar to `logsumexp`, but
only handles two arguments. `logaddexp.reduce` is similar to this
function, but may be less stable.
Examples
--------
>>> from scipy.special import logsumexp
>>> a = np.arange(10)
>>> np.log(np.sum(np.exp(a)))
9.4586297444267107
>>> logsumexp(a)
9.4586297444267107
With weights
>>> a = np.arange(10)
>>> b = np.arange(10, 0, -1)
>>> logsumexp(a, b=b)
9.9170178533034665
>>> np.log(np.sum(b*np.exp(a)))
9.9170178533034647
Returning a sign flag
>>> logsumexp([1,2],b=[1,-1],return_sign=True)
(1.5413248546129181, -1.0)
Notice that `logsumexp` does not directly support masked arrays. To use it
on a masked array, convert the mask into zero weights:
>>> a = np.ma.array([np.log(2), 2, np.log(3)],
... mask=[False, True, False])
>>> b = (~a.mask).astype(int)
>>> logsumexp(a.data, b=b), np.log(5)
1.6094379124341005, 1.6094379124341005
"""
a = _asarray_validated(a, check_finite=False)
if b is not None:
a, b = np.broadcast_arrays(a, b)
if np.any(b == 0):
a = a + 0. # promote to at least float
a[b == 0] = -np.inf
a_max = np.amax(a, axis=axis, keepdims=True)
if a_max.ndim > 0:
a_max[~np.isfinite(a_max)] = 0
elif not np.isfinite(a_max):
a_max = 0
if b is not None:
b = np.asarray(b)
tmp = b * np.exp(a - a_max)
else:
tmp = np.exp(a - a_max)
# suppress warnings about log of zero
with np.errstate(divide='ignore'):
s = np.sum(tmp, axis=axis, keepdims=keepdims)
if return_sign:
sgn = np.sign(s)
s *= sgn # /= makes more sense but we need zero -> zero
out = np.log(s)
if not keepdims:
a_max = np.squeeze(a_max, axis=axis)
out += a_max
if return_sign:
return out, sgn
else:
return out
def softmax(x, axis=None):
r"""
Softmax function
The softmax function transforms each element of a collection by
computing the exponential of each element divided by the sum of the
exponentials of all the elements. That is, if `x` is a one-dimensional
numpy array::
softmax(x) = np.exp(x)/sum(np.exp(x))
Parameters
----------
x : array_like
Input array.
axis : int or tuple of ints, optional
Axis to compute values along. Default is None and softmax will be
computed over the entire array `x`.
Returns
-------
s : ndarray
An array the same shape as `x`. The result will sum to 1 along the
specified axis.
Notes
-----
The formula for the softmax function :math:`\sigma(x)` for a vector
:math:`x = \{x_0, x_1, ..., x_{n-1}\}` is
.. math:: \sigma(x)_j = \frac{e^{x_j}}{\sum_k e^{x_k}}
The `softmax` function is the gradient of `logsumexp`.
.. versionadded:: 1.2.0
Examples
--------
>>> from scipy.special import softmax
>>> np.set_printoptions(precision=5)
>>> x = np.array([[1, 0.5, 0.2, 3],
... [1, -1, 7, 3],
... [2, 12, 13, 3]])
...
Compute the softmax transformation over the entire array.
>>> m = softmax(x)
>>> m
array([[ 4.48309e-06, 2.71913e-06, 2.01438e-06, 3.31258e-05],
[ 4.48309e-06, 6.06720e-07, 1.80861e-03, 3.31258e-05],
[ 1.21863e-05, 2.68421e-01, 7.29644e-01, 3.31258e-05]])
>>> m.sum()
1.0000000000000002
Compute the softmax transformation along the first axis (i.e., the columns).
>>> m = softmax(x, axis=0)
>>> m
array([[ 2.11942e-01, 1.01300e-05, 2.75394e-06, 3.33333e-01],
[ 2.11942e-01, 2.26030e-06, 2.47262e-03, 3.33333e-01],
[ 5.76117e-01, 9.99988e-01, 9.97525e-01, 3.33333e-01]])
>>> m.sum(axis=0)
array([ 1., 1., 1., 1.])
Compute the softmax transformation along the second axis (i.e., the rows).
>>> m = softmax(x, axis=1)
>>> m
array([[ 1.05877e-01, 6.42177e-02, 4.75736e-02, 7.82332e-01],
[ 2.42746e-03, 3.28521e-04, 9.79307e-01, 1.79366e-02],
[ 1.22094e-05, 2.68929e-01, 7.31025e-01, 3.31885e-05]])
>>> m.sum(axis=1)
array([ 1., 1., 1.])
"""
# compute in log space for numerical stability
return np.exp(x - logsumexp(x, axis=axis, keepdims=True))
def log_softmax(x, axis=None):
r"""
Logarithm of softmax function::
log_softmax(x) = log(softmax(x))
Parameters
----------
x : array_like
Input array.
axis : int or tuple of ints, optional
Axis to compute values along. Default is None and softmax will be
computed over the entire array `x`.
Returns
-------
s : ndarray or scalar
An array with the same shape as `x`. Exponential of the result will sum to 1 along the
specified axis. If `x` is a scalar, a scalar is returned.
Notes
-----
`log_softmax` is more accurate than ``np.log(softmax(x))`` with inputs that make
`softmax` saturate (see examples below).
.. versionadded:: 1.5.0
Examples
--------
>>> from scipy.special import log_softmax
>>> from scipy.special import softmax
>>> np.set_printoptions(precision=5)
>>> x = np.array([1000.0, 1.0])
>>> y = log_softmax(x)
>>> y
array([ 0., -999.])
>>> with np.errstate(divide='ignore'):
... y = np.log(softmax(x))
...
>>> y
array([ 0., -inf])
"""
x = _asarray_validated(x, check_finite=False)
x_max = np.amax(x, axis=axis, keepdims=True)
if x_max.ndim > 0:
x_max[~np.isfinite(x_max)] = 0
elif not np.isfinite(x_max):
x_max = 0
tmp = x - x_max
exp_tmp = np.exp(tmp)
# suppress warnings about log of zero
with np.errstate(divide='ignore'):
s = np.sum(exp_tmp, axis=axis, keepdims=True)
out = np.log(s)
out = tmp - out
return out
|
bsd-3-clause
|
[
646,
2680,
465,
980,
199,
504,
7026,
423,
773,
423,
1974,
492,
485,
8748,
63,
24372,
199,
199,
363,
452,
363,
275,
2097,
7270,
940,
9290,
401,
298,
16395,
401,
298,
793,
63,
16395,
937,
421,
199,
318,
9610,
940,
9290,
8,
65,
12,
3114,
29,
403,
12,
330,
29,
403,
12,
18492,
29,
797,
12,
372,
63,
1037,
29,
797,
304,
272,
408,
8564,
314,
943,
402,
314,
3089,
402,
23160,
83,
402,
1324,
4008,
14,
339,
3897,
272,
4143,
272,
282,
520,
1625,
63,
2930,
267,
6924,
1625,
14,
272,
3114,
520,
488,
503,
1109,
503,
2008,
402,
14526,
12,
2716,
267,
23205,
503,
7824,
1806,
1314,
314,
3089,
365,
9394,
14,
4885,
849,
658,
3127,
64,
365,
488,
12,
267,
436,
1006,
4008,
787,
3089,
3594,
14,
398,
2508,
7445,
447,
378,
14,
845,
14,
16,
272,
18492,
520,
2155,
12,
2716,
267,
982,
642,
365,
663,
370,
715,
12,
314,
7824,
1314,
787,
14953,
787,
3602,
315,
314,
267,
754,
465,
7365,
543,
1568,
1373,
14,
8777,
642,
945,
12,
314,
754,
267,
911,
11180,
6657,
6169,
314,
3379,
1625,
14,
398,
2508,
7445,
447,
378,
14,
1046,
14,
16,
272,
330,
520,
1625,
13,
2930,
12,
2716,
267,
17619,
316,
6535,
367,
1437,
8,
64,
65,
10522,
1471,
506,
402,
314,
2011,
2215,
465,
658,
65,
64,
503,
267,
11180,
461,
370,
658,
65,
2313,
5723,
1338,
1443,
506,
6946,
315,
1865,
370,
267,
5669,
1007,
26137,
14,
398,
2508,
7445,
447,
378,
14,
713,
14,
16,
272,
372,
63,
1037,
520,
2155,
12,
2716,
267,
982,
642,
365,
663,
370,
715,
12,
314,
754,
911,
506,
282,
4092,
3035,
2070,
267,
2556,
27,
340,
756,
12,
2058,
626,
787,
6946,
911,
506,
2138,
267,
465,
16046,
14,
3758,
365,
756,
334,
889,
2070,
2556,
680,
398,
2508,
7445,
447,
378,
14,
975,
14,
16,
339,
1803,
272,
5514,
272,
522,
520,
6800,
267,
710,
754,
12,
1124,
1590,
14,
793,
8,
1590,
14,
1838,
8,
1590,
14,
1474,
8,
65,
1724,
1040,
12950,
315,
282,
8950,
1183,
267,
1655,
17830,
4340,
14,
982,
658,
66,
64,
365,
1627,
2066,
1124,
1590,
14,
793,
8,
1590,
14,
1838,
8,
66,
10,
1590,
14,
1474,
8,
65,
1724,
1040,
267,
365,
2138,
14,
272,
308,
784,
520,
6800,
267,
982,
372,
63,
1037,
365,
715,
12,
642,
911,
506,
376,
1625,
402,
8402,
13,
1403,
267,
5579,
4877,
522,
436,
435,
17,
12,
378,
12,
503,
446,
17,
10298,
641,
314,
2070,
267,
402,
314,
754,
14,
982,
756,
12,
1454,
1373,
754,
365,
2138,
14,
339,
1666,
6121,
272,
3001,
272,
2680,
14,
793,
350,
31450,
12,
2680,
14,
793,
350,
31450,
18,
339,
8144,
272,
9063,
272,
20602,
965,
282,
943,
350,
31450,
805,
1314,
365,
7437,
8545,
370,
658,
7270,
940,
9290,
3559,
1325,
272,
1454,
10022,
2877,
2368,
14,
658,
793,
350,
31450,
14,
5270,
64,
365,
8545,
370,
642,
272,
805,
12,
1325,
1443,
506,
6656,
17830,
14,
339,
6058,
272,
3001,
272,
1306,
687,
7026,
14,
6664,
492,
9610,
940,
9290,
272,
1306,
282,
275,
980,
14,
5605,
8,
709,
9,
272,
1306,
980,
14,
793,
8,
1590,
14,
1838,
8,
1590,
14,
1474,
8,
65,
1724,
272,
1749,
14,
2322,
1184,
1398,
1342,
1602,
13406,
7555,
272,
1306,
9610,
940,
9290,
8,
65,
9,
272,
1749,
14,
2322,
1184,
1398,
1342,
1602,
13406,
7555,
339,
8777,
4931,
339,
1306,
282,
275,
980,
14,
5605,
8,
709,
9,
272,
1306,
330,
275,
980,
14,
5605,
8,
709,
12,
378,
12,
446,
17,
9,
272,
1306,
9610,
940,
9290,
8,
65,
12,
330,
29,
66,
9,
272,
1749,
14,
29702,
614,
19312,
14137,
1082,
16373,
272,
1306,
980,
14,
793,
8,
1590,
14,
1838,
8,
66,
10,
1590,
14,
1474,
8,
65,
1724,
272,
1749,
14,
29702,
614,
19312,
14137,
1082,
8557,
339,
1432,
316,
282,
2070,
3305,
339,
1306,
9610,
940,
9290,
779,
17,
12,
18,
467,
66,
1524,
17,
3057,
17,
467,
1107,
63,
1037,
29,
549,
9,
272,
334,
17,
14,
1477,
6557,
2006,
18163,
7263,
12851,
12,
446,
17,
14,
16,
9,
339,
3091,
3548,
626,
658,
7270,
940,
9290,
64,
1630,
440,
5370,
2291,
9742,
6572,
14,
4005,
675,
652,
272,
641,
282,
9742,
1625,
12,
3957,
314,
3656,
1901,
4697,
4931,
26,
339,
1306,
282,
275,
980,
14,
391,
14,
1144,
779,
1590,
14,
793,
8,
18,
395,
499,
12,
980,
14,
793,
8,
19,
4360,
272,
2263,
8295,
3656,
1524,
797,
12,
715,
12,
756,
566,
272,
1306,
330,
275,
31742,
65,
14,
2629,
680,
6041,
8,
442,
9,
272,
1306,
9610,
940,
9290,
8,
65,
14,
576,
12,
330,
29,
66,
395,
980,
14,
793,
8,
21,
9,
272,
413,
14,
14520,
20,
12015,
7214,
1082,
1960,
21,
12,
413,
14,
14520,
20,
12015,
7214,
1082,
1960,
21,
339,
408,
272,
282,
275,
485,
8748,
63,
24372,
8,
65,
12,
1104,
63,
8005,
29,
797,
9,
272,
340,
330,
365,
440,
488,
26,
267,
282,
12,
330,
275,
980,
14,
10786,
63,
10095,
8,
65,
12,
330,
9,
267,
340,
980,
14,
1629,
8,
66,
508,
378,
304,
288,
282,
275,
282,
435,
378,
14,
221,
327,
10016,
370,
737,
5210,
2069,
288,
282,
59,
66,
508,
378,
61,
275,
446,
1590,
14,
4904,
339,
282,
63,
988,
275,
980,
14,
65,
988,
8,
65,
12,
3114,
29,
3127,
12,
18492,
29,
549,
9,
339,
340,
282,
63,
988,
14,
8322,
690,
378,
26,
267,
282,
63,
988,
19911,
1590,
14,
30276,
8,
65,
63,
988,
1874,
275,
378,
272,
916,
440,
980,
14,
30276,
8,
65,
63,
988,
304,
267,
282,
63,
988,
275,
378,
339,
340,
330,
365,
440,
488,
26,
267,
330,
275,
980,
14,
8748,
8,
66,
9,
267,
3529,
275,
330,
627,
980,
14,
1474,
8,
65,
446,
282,
63,
988,
9,
272,
587,
26,
267,
3529,
275,
980,
14,
1474,
8,
65,
446,
282,
63,
988,
9,
339,
327,
15678,
3598,
3595,
943,
402,
4697,
272,
543,
980,
14,
1508,
929,
8,
16081,
534,
4247,
735,
267,
308,
275,
980,
14,
1838,
8,
2791,
12,
3114,
29,
3127,
12,
18492,
29
] |
[
2680,
465,
980,
199,
504,
7026,
423,
773,
423,
1974,
492,
485,
8748,
63,
24372,
199,
199,
363,
452,
363,
275,
2097,
7270,
940,
9290,
401,
298,
16395,
401,
298,
793,
63,
16395,
937,
421,
199,
318,
9610,
940,
9290,
8,
65,
12,
3114,
29,
403,
12,
330,
29,
403,
12,
18492,
29,
797,
12,
372,
63,
1037,
29,
797,
304,
272,
408,
8564,
314,
943,
402,
314,
3089,
402,
23160,
83,
402,
1324,
4008,
14,
339,
3897,
272,
4143,
272,
282,
520,
1625,
63,
2930,
267,
6924,
1625,
14,
272,
3114,
520,
488,
503,
1109,
503,
2008,
402,
14526,
12,
2716,
267,
23205,
503,
7824,
1806,
1314,
314,
3089,
365,
9394,
14,
4885,
849,
658,
3127,
64,
365,
488,
12,
267,
436,
1006,
4008,
787,
3089,
3594,
14,
398,
2508,
7445,
447,
378,
14,
845,
14,
16,
272,
18492,
520,
2155,
12,
2716,
267,
982,
642,
365,
663,
370,
715,
12,
314,
7824,
1314,
787,
14953,
787,
3602,
315,
314,
267,
754,
465,
7365,
543,
1568,
1373,
14,
8777,
642,
945,
12,
314,
754,
267,
911,
11180,
6657,
6169,
314,
3379,
1625,
14,
398,
2508,
7445,
447,
378,
14,
1046,
14,
16,
272,
330,
520,
1625,
13,
2930,
12,
2716,
267,
17619,
316,
6535,
367,
1437,
8,
64,
65,
10522,
1471,
506,
402,
314,
2011,
2215,
465,
658,
65,
64,
503,
267,
11180,
461,
370,
658,
65,
2313,
5723,
1338,
1443,
506,
6946,
315,
1865,
370,
267,
5669,
1007,
26137,
14,
398,
2508,
7445,
447,
378,
14,
713,
14,
16,
272,
372,
63,
1037,
520,
2155,
12,
2716,
267,
982,
642,
365,
663,
370,
715,
12,
314,
754,
911,
506,
282,
4092,
3035,
2070,
267,
2556,
27,
340,
756,
12,
2058,
626,
787,
6946,
911,
506,
2138,
267,
465,
16046,
14,
3758,
365,
756,
334,
889,
2070,
2556,
680,
398,
2508,
7445,
447,
378,
14,
975,
14,
16,
339,
1803,
272,
5514,
272,
522,
520,
6800,
267,
710,
754,
12,
1124,
1590,
14,
793,
8,
1590,
14,
1838,
8,
1590,
14,
1474,
8,
65,
1724,
1040,
12950,
315,
282,
8950,
1183,
267,
1655,
17830,
4340,
14,
982,
658,
66,
64,
365,
1627,
2066,
1124,
1590,
14,
793,
8,
1590,
14,
1838,
8,
66,
10,
1590,
14,
1474,
8,
65,
1724,
1040,
267,
365,
2138,
14,
272,
308,
784,
520,
6800,
267,
982,
372,
63,
1037,
365,
715,
12,
642,
911,
506,
376,
1625,
402,
8402,
13,
1403,
267,
5579,
4877,
522,
436,
435,
17,
12,
378,
12,
503,
446,
17,
10298,
641,
314,
2070,
267,
402,
314,
754,
14,
982,
756,
12,
1454,
1373,
754,
365,
2138,
14,
339,
1666,
6121,
272,
3001,
272,
2680,
14,
793,
350,
31450,
12,
2680,
14,
793,
350,
31450,
18,
339,
8144,
272,
9063,
272,
20602,
965,
282,
943,
350,
31450,
805,
1314,
365,
7437,
8545,
370,
658,
7270,
940,
9290,
3559,
1325,
272,
1454,
10022,
2877,
2368,
14,
658,
793,
350,
31450,
14,
5270,
64,
365,
8545,
370,
642,
272,
805,
12,
1325,
1443,
506,
6656,
17830,
14,
339,
6058,
272,
3001,
272,
1306,
687,
7026,
14,
6664,
492,
9610,
940,
9290,
272,
1306,
282,
275,
980,
14,
5605,
8,
709,
9,
272,
1306,
980,
14,
793,
8,
1590,
14,
1838,
8,
1590,
14,
1474,
8,
65,
1724,
272,
1749,
14,
2322,
1184,
1398,
1342,
1602,
13406,
7555,
272,
1306,
9610,
940,
9290,
8,
65,
9,
272,
1749,
14,
2322,
1184,
1398,
1342,
1602,
13406,
7555,
339,
8777,
4931,
339,
1306,
282,
275,
980,
14,
5605,
8,
709,
9,
272,
1306,
330,
275,
980,
14,
5605,
8,
709,
12,
378,
12,
446,
17,
9,
272,
1306,
9610,
940,
9290,
8,
65,
12,
330,
29,
66,
9,
272,
1749,
14,
29702,
614,
19312,
14137,
1082,
16373,
272,
1306,
980,
14,
793,
8,
1590,
14,
1838,
8,
66,
10,
1590,
14,
1474,
8,
65,
1724,
272,
1749,
14,
29702,
614,
19312,
14137,
1082,
8557,
339,
1432,
316,
282,
2070,
3305,
339,
1306,
9610,
940,
9290,
779,
17,
12,
18,
467,
66,
1524,
17,
3057,
17,
467,
1107,
63,
1037,
29,
549,
9,
272,
334,
17,
14,
1477,
6557,
2006,
18163,
7263,
12851,
12,
446,
17,
14,
16,
9,
339,
3091,
3548,
626,
658,
7270,
940,
9290,
64,
1630,
440,
5370,
2291,
9742,
6572,
14,
4005,
675,
652,
272,
641,
282,
9742,
1625,
12,
3957,
314,
3656,
1901,
4697,
4931,
26,
339,
1306,
282,
275,
980,
14,
391,
14,
1144,
779,
1590,
14,
793,
8,
18,
395,
499,
12,
980,
14,
793,
8,
19,
4360,
272,
2263,
8295,
3656,
1524,
797,
12,
715,
12,
756,
566,
272,
1306,
330,
275,
31742,
65,
14,
2629,
680,
6041,
8,
442,
9,
272,
1306,
9610,
940,
9290,
8,
65,
14,
576,
12,
330,
29,
66,
395,
980,
14,
793,
8,
21,
9,
272,
413,
14,
14520,
20,
12015,
7214,
1082,
1960,
21,
12,
413,
14,
14520,
20,
12015,
7214,
1082,
1960,
21,
339,
408,
272,
282,
275,
485,
8748,
63,
24372,
8,
65,
12,
1104,
63,
8005,
29,
797,
9,
272,
340,
330,
365,
440,
488,
26,
267,
282,
12,
330,
275,
980,
14,
10786,
63,
10095,
8,
65,
12,
330,
9,
267,
340,
980,
14,
1629,
8,
66,
508,
378,
304,
288,
282,
275,
282,
435,
378,
14,
221,
327,
10016,
370,
737,
5210,
2069,
288,
282,
59,
66,
508,
378,
61,
275,
446,
1590,
14,
4904,
339,
282,
63,
988,
275,
980,
14,
65,
988,
8,
65,
12,
3114,
29,
3127,
12,
18492,
29,
549,
9,
339,
340,
282,
63,
988,
14,
8322,
690,
378,
26,
267,
282,
63,
988,
19911,
1590,
14,
30276,
8,
65,
63,
988,
1874,
275,
378,
272,
916,
440,
980,
14,
30276,
8,
65,
63,
988,
304,
267,
282,
63,
988,
275,
378,
339,
340,
330,
365,
440,
488,
26,
267,
330,
275,
980,
14,
8748,
8,
66,
9,
267,
3529,
275,
330,
627,
980,
14,
1474,
8,
65,
446,
282,
63,
988,
9,
272,
587,
26,
267,
3529,
275,
980,
14,
1474,
8,
65,
446,
282,
63,
988,
9,
339,
327,
15678,
3598,
3595,
943,
402,
4697,
272,
543,
980,
14,
1508,
929,
8,
16081,
534,
4247,
735,
267,
308,
275,
980,
14,
1838,
8,
2791,
12,
3114,
29,
3127,
12,
18492,
29,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
dongweiming/flask_reveal
|
social/backends/twilio.py
|
1
|
1310
|
"""
Twilio support
"""
from re import sub
from social.p3 import urlencode
from social.backends.base import BaseAuth
class TwilioAuth(BaseAuth):
name = 'twilio'
ID_KEY = 'AccountSid'
def get_user_details(self, response):
"""Return twilio details, Twilio only provides AccountSID as
parameters."""
# /complete/twilio/?AccountSid=ACc65ea16c9ebd4d4684edf814995b27e
return {'username': response['AccountSid'],
'email': '',
'fullname': '',
'first_name': '',
'last_name': ''}
def auth_url(self):
"""Return authorization redirect url."""
key, secret = self.get_key_and_secret()
callback = self.strategy.build_absolute_uri(self.redirect_uri)
callback = sub(r'^https', 'http', callback)
query = urlencode({'cb': callback})
return 'https://www.twilio.com/authorize/%s?%s' % (key, query)
def auth_complete(self, *args, **kwargs):
"""Completes loging process, must return user instance"""
account_sid = self.data.get('AccountSid')
if not account_sid:
raise ValueError('No AccountSid returned')
kwargs.update({'response': self.data, 'backend': self})
return self.strategy.authenticate(*args, **kwargs)
|
bsd-3-clause
|
[
624,
199,
22879,
23533,
2291,
199,
624,
199,
504,
295,
492,
1007,
199,
199,
504,
20295,
14,
80,
19,
492,
16511,
199,
504,
20295,
14,
7765,
14,
1095,
492,
3523,
2817,
421,
199,
533,
377,
87,
23533,
2817,
8,
1563,
2817,
304,
272,
536,
275,
283,
8122,
23533,
7,
272,
2870,
63,
3078,
275,
283,
6009,
26686,
7,
339,
347,
664,
63,
751,
63,
5087,
8,
277,
12,
1177,
304,
267,
408,
1767,
8900,
23533,
2436,
12,
377,
87,
23533,
1454,
6571,
9973,
19514,
465,
267,
2633,
1041,
267,
327,
1182,
4883,
15,
8122,
23533,
10197,
6009,
26686,
29,
1348,
67,
2182,
4489,
975,
67,
25,
2871,
68,
20,
68,
2466,
1349,
27680,
29153,
14732,
66,
1465,
69,
267,
372,
791,
2473,
356,
1177,
459,
6009,
26686,
995,
355,
283,
2123,
356,
3260,
355,
283,
9930,
356,
3260,
355,
283,
2246,
63,
354,
356,
3260,
355,
283,
2019,
63,
354,
356,
28174,
339,
347,
1790,
63,
633,
8,
277,
304,
267,
408,
1767,
13448,
4660,
1166,
1041,
267,
790,
12,
7565,
275,
291,
14,
362,
63,
498,
63,
460,
63,
4731,
342,
267,
3233,
275,
291,
14,
8590,
14,
1506,
63,
6116,
63,
2302,
8,
277,
14,
4876,
63,
2302,
9,
267,
3233,
275,
1007,
8,
82,
4289,
2859,
297,
283,
1014,
297,
3233,
9,
267,
1827,
275,
16511,
3252,
2894,
356,
3233,
1552,
267,
372,
283,
2859,
921,
1544,
14,
8122,
23533,
14,
957,
15,
14204,
3149,
83,
25790,
83,
7,
450,
334,
498,
12,
1827,
9,
339,
347,
1790,
63,
4883,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
6600,
744,
943,
316,
2112,
12,
1471,
372,
922,
1256,
624,
267,
2933,
63,
4148,
275,
291,
14,
576,
14,
362,
360,
6009,
26686,
358,
267,
340,
440,
2933,
63,
4148,
26,
288,
746,
1722,
360,
1944,
9973,
26686,
2138,
358,
267,
2074,
14,
873,
3252,
1310,
356,
291,
14,
576,
12,
283,
4620,
356,
291,
1552,
267,
372,
291,
14,
8590,
14,
13975,
2031,
589,
12,
1011,
958,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
22879,
23533,
2291,
199,
624,
199,
504,
295,
492,
1007,
199,
199,
504,
20295,
14,
80,
19,
492,
16511,
199,
504,
20295,
14,
7765,
14,
1095,
492,
3523,
2817,
421,
199,
533,
377,
87,
23533,
2817,
8,
1563,
2817,
304,
272,
536,
275,
283,
8122,
23533,
7,
272,
2870,
63,
3078,
275,
283,
6009,
26686,
7,
339,
347,
664,
63,
751,
63,
5087,
8,
277,
12,
1177,
304,
267,
408,
1767,
8900,
23533,
2436,
12,
377,
87,
23533,
1454,
6571,
9973,
19514,
465,
267,
2633,
1041,
267,
327,
1182,
4883,
15,
8122,
23533,
10197,
6009,
26686,
29,
1348,
67,
2182,
4489,
975,
67,
25,
2871,
68,
20,
68,
2466,
1349,
27680,
29153,
14732,
66,
1465,
69,
267,
372,
791,
2473,
356,
1177,
459,
6009,
26686,
995,
355,
283,
2123,
356,
3260,
355,
283,
9930,
356,
3260,
355,
283,
2246,
63,
354,
356,
3260,
355,
283,
2019,
63,
354,
356,
28174,
339,
347,
1790,
63,
633,
8,
277,
304,
267,
408,
1767,
13448,
4660,
1166,
1041,
267,
790,
12,
7565,
275,
291,
14,
362,
63,
498,
63,
460,
63,
4731,
342,
267,
3233,
275,
291,
14,
8590,
14,
1506,
63,
6116,
63,
2302,
8,
277,
14,
4876,
63,
2302,
9,
267,
3233,
275,
1007,
8,
82,
4289,
2859,
297,
283,
1014,
297,
3233,
9,
267,
1827,
275,
16511,
3252,
2894,
356,
3233,
1552,
267,
372,
283,
2859,
921,
1544,
14,
8122,
23533,
14,
957,
15,
14204,
3149,
83,
25790,
83,
7,
450,
334,
498,
12,
1827,
9,
339,
347,
1790,
63,
4883,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
6600,
744,
943,
316,
2112,
12,
1471,
372,
922,
1256,
624,
267,
2933,
63,
4148,
275,
291,
14,
576,
14,
362,
360,
6009,
26686,
358,
267,
340,
440,
2933,
63,
4148,
26,
288,
746,
1722,
360,
1944,
9973,
26686,
2138,
358,
267,
2074,
14,
873,
3252,
1310,
356,
291,
14,
576,
12,
283,
4620,
356,
291,
1552,
267,
372,
291,
14,
8590,
14,
13975,
2031,
589,
12,
1011,
958,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
shivam1111/odoo
|
addons/website/tests/test_crawl.py
|
251
|
3415
|
# -*- coding: utf-8 -*-
import logging
import urlparse
import time
import lxml.html
import openerp
import re
_logger = logging.getLogger(__name__)
class Crawler(openerp.tests.HttpCase):
""" Test suite crawling an openerp CMS instance and checking that all
internal links lead to a 200 response.
If a username and a password are provided, authenticates the user before
starting the crawl
"""
at_install = False
post_install = True
def crawl(self, url, seen=None, msg=''):
if seen == None:
seen = set()
url_slug = re.sub(r"[/](([^/=?&]+-)?[0-9]+)([/]|$)", '/<slug>/', url)
url_slug = re.sub(r"([^/=?&]+)=[^/=?&]+", '\g<1>=param', url_slug)
if url_slug in seen:
return seen
else:
seen.add(url_slug)
_logger.info("%s %s", msg, url)
r = self.url_open(url)
code = r.getcode()
self.assertIn( code, xrange(200, 300), "%s Fetching %s returned error response (%d)" % (msg, url, code))
if r.info().gettype() == 'text/html':
doc = lxml.html.fromstring(r.read())
for link in doc.xpath('//a[@href]'):
href = link.get('href')
parts = urlparse.urlsplit(href)
# href with any fragment removed
href = urlparse.urlunsplit((
parts.scheme,
parts.netloc,
parts.path,
parts.query,
''
))
# FIXME: handle relative link (not parts.path.startswith /)
if parts.netloc or \
not parts.path.startswith('/') or \
parts.path == '/web' or\
parts.path.startswith('/web/') or \
parts.path.startswith('/en_US/') or \
(parts.scheme and parts.scheme not in ('http', 'https')):
continue
self.crawl(href, seen, msg)
return seen
def test_10_crawl_public(self):
t0 = time.time()
t0_sql = self.registry.test_cr.sql_log_count
seen = self.crawl('/', msg='Anonymous Coward')
count = len(seen)
duration = time.time() - t0
sql = self.registry.test_cr.sql_log_count - t0_sql
_logger.log(25, "public crawled %s urls in %.2fs %s queries, %.3fs %.2fq per request, ", count, duration, sql, duration/count, float(sql)/count)
def test_20_crawl_demo(self):
t0 = time.time()
t0_sql = self.registry.test_cr.sql_log_count
self.authenticate('demo', 'demo')
seen = self.crawl('/', msg='demo')
count = len(seen)
duration = time.time() - t0
sql = self.registry.test_cr.sql_log_count - t0_sql
_logger.log(25, "demo crawled %s urls in %.2fs %s queries, %.3fs %.2fq per request", count, duration, sql, duration/count, float(sql)/count)
def test_30_crawl_admin(self):
t0 = time.time()
t0_sql = self.registry.test_cr.sql_log_count
self.authenticate('admin', 'admin')
seen = self.crawl('/', msg='admin')
count = len(seen)
duration = time.time() - t0
sql = self.registry.test_cr.sql_log_count - t0_sql
_logger.log(25, "admin crawled %s urls in %.2fs %s queries, %.3fs %.2fq per request", count, duration, sql, duration/count, float(sql)/count)
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2050,
199,
646,
7097,
199,
646,
900,
199,
199,
646,
14490,
14,
1360,
199,
199,
646,
5166,
199,
646,
295,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
445,
16057,
8,
11267,
14,
2219,
14,
5779,
1538,
304,
272,
408,
1379,
5241,
286,
1773,
2983,
376,
5166,
29554,
1256,
436,
7907,
626,
1006,
272,
5007,
6220,
12690,
370,
282,
1926,
1177,
14,
339,
982,
282,
3434,
436,
282,
2505,
787,
2741,
12,
28532,
2335,
314,
922,
2544,
272,
6617,
314,
286,
22910,
272,
408,
339,
737,
63,
3174,
275,
756,
272,
2963,
63,
3174,
275,
715,
339,
347,
286,
22910,
8,
277,
12,
1166,
12,
6775,
29,
403,
12,
1499,
9280,
267,
340,
6775,
508,
488,
26,
288,
6775,
275,
663,
342,
398,
1166,
63,
5464,
275,
295,
14,
954,
8,
82,
22774,
15,
8738,
7059,
15,
18048,
6,
2807,
13,
5547,
59,
16,
13,
25,
11896,
779,
15,
11752,
4,
4186,
1994,
28,
5464,
30,
3678,
1166,
9,
267,
1166,
63,
5464,
275,
295,
14,
954,
8,
82,
2,
7059,
15,
18048,
6,
11896,
1524,
62,
15,
18048,
6,
2807,
401,
1557,
71,
28,
17,
8119,
635,
297,
1166,
63,
5464,
9,
267,
340,
1166,
63,
5464,
315,
6775,
26,
288,
372,
6775,
267,
587,
26,
288,
6775,
14,
525,
8,
633,
63,
5464,
9,
398,
485,
2921,
14,
815,
3647,
83,
450,
83,
401,
1499,
12,
1166,
9,
267,
519,
275,
291,
14,
633,
63,
1490,
8,
633,
9,
267,
1233,
275,
519,
14,
362,
600,
342,
267,
291,
14,
4080,
8,
1233,
12,
4945,
8,
1840,
12,
9601,
395,
2071,
83,
16347,
316,
450,
83,
2138,
1125,
1177,
4366,
68,
2924,
450,
334,
1328,
12,
1166,
12,
1233,
430,
398,
340,
519,
14,
815,
1252,
362,
466,
342,
508,
283,
505,
15,
1360,
356,
288,
1382,
275,
14490,
14,
1360,
14,
13521,
8,
82,
14,
739,
1012,
288,
367,
2142,
315,
1382,
14,
8006,
15079,
65,
14251,
6399,
61,
735,
355,
4369,
275,
2142,
14,
362,
360,
6399,
358,
2234,
4184,
275,
7097,
14,
29491,
8,
6399,
9,
355,
327,
4369,
543,
1263,
7956,
4829,
355,
4369,
275,
7097,
14,
633,
30038,
1332,
490,
4184,
14,
5512,
12,
490,
4184,
14,
12652,
12,
490,
4184,
14,
515,
12,
490,
4184,
14,
1131,
12,
490,
2125,
355,
5082,
2234,
327,
7600,
26,
2429,
3847,
2142,
334,
1397,
4184,
14,
515,
14,
2460,
1182,
9,
355,
340,
4184,
14,
12652,
503,
971,
490,
440,
4184,
14,
515,
14,
2460,
7825,
503,
971,
490,
4184,
14,
515,
508,
1994,
2520,
7,
503,
60,
490,
4184,
14,
515,
14,
2460,
2336,
2520,
6217,
503,
971,
490,
4184,
14,
515,
14,
2460,
2336,
287,
63,
1668,
6217,
503,
971,
490,
334,
4181,
14,
5512,
436,
4184,
14,
5512,
440,
315,
661,
1014,
297,
283,
2859,
8109,
490,
1980,
2234,
291,
14,
67,
22910,
8,
6399,
12,
6775,
12,
1499,
9,
267,
372,
6775,
2378,
347,
511,
63,
709,
63,
67,
22910,
63,
3455,
8,
277,
304,
267,
307,
16,
275,
900,
14,
521,
342,
267,
307,
16,
63,
3009,
275,
291,
14,
5189,
14,
396,
63,
1556,
14,
3009,
63,
793,
63,
835,
267,
6775,
275,
291,
14,
67,
22910,
10998,
1499,
534,
23902,
445,
583,
1005,
358,
267,
2338,
275,
822,
8,
8606,
9,
267,
7373,
275,
900,
14,
521,
342,
446,
307,
16,
267,
3875,
275,
291,
14,
5189,
14,
396,
63,
1556,
14,
3009,
63,
793,
63,
835,
446,
307,
16,
63,
3009,
267,
485,
2921,
14,
793,
8,
821,
12,
298,
3455,
286,
1773,
1146,
450,
83,
8187,
315,
10536,
18,
2319,
450,
83,
9212,
12,
10536,
19,
2319,
10536,
18,
11878,
1126,
1056,
12,
3872,
2338,
12,
7373,
12,
3875,
12,
7373,
15,
835,
12,
2069,
8,
3009,
2447,
835,
9,
339,
347,
511,
63,
1165,
63,
67,
22910,
63,
8768,
8,
277,
304,
267,
307,
16,
275,
900,
14,
521,
342,
267,
307,
16,
63,
3009,
275,
291,
14,
5189,
14,
396,
63,
1556,
14,
3009,
63,
793,
63,
835,
267,
291,
14,
13975,
360,
8768,
297,
283,
8768,
358,
267,
6775,
275,
291,
14,
67,
22910,
10998,
1499,
534,
8768,
358,
267,
2338,
275,
822,
8,
8606,
9,
267,
7373,
275,
900,
14,
521,
342,
446,
307,
16,
267,
3875,
275,
291,
14,
5189,
14,
396,
63,
1556,
14,
3009,
63,
793,
63,
835,
446,
307,
16,
63,
3009,
267,
485,
2921,
14,
793,
8,
821,
12,
298,
8768,
286,
1773,
1146,
450,
83,
8187,
315,
10536,
18,
2319,
450,
83,
9212,
12,
10536,
19,
2319,
10536,
18,
11878,
1126,
1056,
401,
2338,
12,
7373,
12,
3875,
12,
7373,
15,
835,
12,
2069,
8,
3009,
2447,
835,
9,
339,
347,
511,
63,
1216,
63,
67,
22910,
63,
2113,
8,
277,
304,
267,
307,
16,
275,
900,
14,
521,
342,
267,
307,
16,
63,
3009,
275,
291,
14,
5189,
14,
396,
63,
1556,
14,
3009,
63,
793,
63,
835,
267,
291,
14,
13975,
360,
2113,
297,
283,
2113,
358,
267,
6775,
275,
291,
14,
67,
22910,
10998,
1499,
534,
2113,
358,
267,
2338,
275,
822,
8,
8606,
9,
267,
7373,
275,
900,
14,
521,
342,
446,
307,
16,
267,
3875,
275,
291,
14,
5189,
14,
396,
63,
1556,
14,
3009,
63,
793,
63,
835,
446,
307,
16,
63,
3009,
267,
485,
2921,
14,
793,
8,
821,
12,
298,
2113,
286,
1773,
1146,
450,
83,
8187,
315,
10536,
18,
2319,
450,
83,
9212,
12,
10536,
19,
2319,
10536,
18,
11878,
1126,
1056,
401,
2338,
12,
7373,
12,
3875,
12,
7373,
15,
835,
12,
2069,
8,
3009,
2447,
835,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2050,
199,
646,
7097,
199,
646,
900,
199,
199,
646,
14490,
14,
1360,
199,
199,
646,
5166,
199,
646,
295,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
445,
16057,
8,
11267,
14,
2219,
14,
5779,
1538,
304,
272,
408,
1379,
5241,
286,
1773,
2983,
376,
5166,
29554,
1256,
436,
7907,
626,
1006,
272,
5007,
6220,
12690,
370,
282,
1926,
1177,
14,
339,
982,
282,
3434,
436,
282,
2505,
787,
2741,
12,
28532,
2335,
314,
922,
2544,
272,
6617,
314,
286,
22910,
272,
408,
339,
737,
63,
3174,
275,
756,
272,
2963,
63,
3174,
275,
715,
339,
347,
286,
22910,
8,
277,
12,
1166,
12,
6775,
29,
403,
12,
1499,
9280,
267,
340,
6775,
508,
488,
26,
288,
6775,
275,
663,
342,
398,
1166,
63,
5464,
275,
295,
14,
954,
8,
82,
22774,
15,
8738,
7059,
15,
18048,
6,
2807,
13,
5547,
59,
16,
13,
25,
11896,
779,
15,
11752,
4,
4186,
1994,
28,
5464,
30,
3678,
1166,
9,
267,
1166,
63,
5464,
275,
295,
14,
954,
8,
82,
2,
7059,
15,
18048,
6,
11896,
1524,
62,
15,
18048,
6,
2807,
401,
1557,
71,
28,
17,
8119,
635,
297,
1166,
63,
5464,
9,
267,
340,
1166,
63,
5464,
315,
6775,
26,
288,
372,
6775,
267,
587,
26,
288,
6775,
14,
525,
8,
633,
63,
5464,
9,
398,
485,
2921,
14,
815,
3647,
83,
450,
83,
401,
1499,
12,
1166,
9,
267,
519,
275,
291,
14,
633,
63,
1490,
8,
633,
9,
267,
1233,
275,
519,
14,
362,
600,
342,
267,
291,
14,
4080,
8,
1233,
12,
4945,
8,
1840,
12,
9601,
395,
2071,
83,
16347,
316,
450,
83,
2138,
1125,
1177,
4366,
68,
2924,
450,
334,
1328,
12,
1166,
12,
1233,
430,
398,
340,
519,
14,
815,
1252,
362,
466,
342,
508,
283,
505,
15,
1360,
356,
288,
1382,
275,
14490,
14,
1360,
14,
13521,
8,
82,
14,
739,
1012,
288,
367,
2142,
315,
1382,
14,
8006,
15079,
65,
14251,
6399,
61,
735,
355,
4369,
275,
2142,
14,
362,
360,
6399,
358,
2234,
4184,
275,
7097,
14,
29491,
8,
6399,
9,
355,
327,
4369,
543,
1263,
7956,
4829,
355,
4369,
275,
7097,
14,
633,
30038,
1332,
490,
4184,
14,
5512,
12,
490,
4184,
14,
12652,
12,
490,
4184,
14,
515,
12,
490,
4184,
14,
1131,
12,
490,
2125,
355,
5082,
2234,
327,
7600,
26,
2429,
3847,
2142,
334,
1397,
4184,
14,
515,
14,
2460,
1182,
9,
355,
340,
4184,
14,
12652,
503,
971,
490,
440,
4184,
14,
515,
14,
2460,
7825,
503,
971,
490,
4184,
14,
515,
508,
1994,
2520,
7,
503,
60,
490,
4184,
14,
515,
14,
2460,
2336,
2520,
6217,
503,
971,
490,
4184,
14,
515,
14,
2460,
2336,
287,
63,
1668,
6217,
503,
971,
490,
334,
4181,
14,
5512,
436,
4184,
14,
5512,
440,
315,
661,
1014,
297,
283,
2859,
8109,
490,
1980,
2234,
291,
14,
67,
22910,
8,
6399,
12,
6775,
12,
1499,
9,
267,
372,
6775,
2378,
347,
511,
63,
709,
63,
67,
22910,
63,
3455,
8,
277,
304,
267,
307,
16,
275,
900,
14,
521,
342,
267,
307,
16,
63,
3009,
275,
291,
14,
5189,
14,
396,
63,
1556,
14,
3009,
63,
793,
63,
835,
267,
6775,
275,
291,
14,
67,
22910,
10998,
1499,
534,
23902,
445,
583,
1005,
358,
267,
2338,
275,
822,
8,
8606,
9,
267,
7373,
275,
900,
14,
521,
342,
446,
307,
16,
267,
3875,
275,
291,
14,
5189,
14,
396,
63,
1556,
14,
3009,
63,
793,
63,
835,
446,
307,
16,
63,
3009,
267,
485,
2921,
14,
793,
8,
821,
12,
298,
3455,
286,
1773,
1146,
450,
83,
8187,
315,
10536,
18,
2319,
450,
83,
9212,
12,
10536,
19,
2319,
10536,
18,
11878,
1126,
1056,
12,
3872,
2338,
12,
7373,
12,
3875,
12,
7373,
15,
835,
12,
2069,
8,
3009,
2447,
835,
9,
339,
347,
511,
63,
1165,
63,
67,
22910,
63,
8768,
8,
277,
304,
267,
307,
16,
275,
900,
14,
521,
342,
267,
307,
16,
63,
3009,
275,
291,
14,
5189,
14,
396,
63,
1556,
14,
3009,
63,
793,
63,
835,
267,
291,
14,
13975,
360,
8768,
297,
283,
8768,
358,
267,
6775,
275,
291,
14,
67,
22910,
10998,
1499,
534,
8768,
358,
267,
2338,
275,
822,
8,
8606,
9,
267,
7373,
275,
900,
14,
521,
342,
446,
307,
16,
267,
3875,
275,
291,
14,
5189,
14,
396,
63,
1556,
14,
3009,
63,
793,
63,
835,
446,
307,
16,
63,
3009,
267,
485,
2921,
14,
793,
8,
821,
12,
298,
8768,
286,
1773,
1146,
450,
83,
8187,
315,
10536,
18,
2319,
450,
83,
9212,
12,
10536,
19,
2319,
10536,
18,
11878,
1126,
1056,
401,
2338,
12,
7373,
12,
3875,
12,
7373,
15,
835,
12,
2069,
8,
3009,
2447,
835,
9,
339,
347,
511,
63,
1216,
63,
67,
22910,
63,
2113,
8,
277,
304,
267,
307,
16,
275,
900,
14,
521,
342,
267,
307,
16,
63,
3009,
275,
291,
14,
5189,
14,
396,
63,
1556,
14,
3009,
63,
793,
63,
835,
267,
291,
14,
13975,
360,
2113,
297,
283,
2113,
358,
267,
6775,
275,
291,
14,
67,
22910,
10998,
1499,
534,
2113,
358,
267,
2338,
275,
822,
8,
8606,
9,
267,
7373,
275,
900,
14,
521,
342,
446,
307,
16,
267,
3875,
275,
291,
14,
5189,
14,
396,
63,
1556,
14,
3009,
63,
793,
63,
835,
446,
307,
16,
63,
3009,
267,
485,
2921,
14,
793,
8,
821,
12,
298,
2113,
286,
1773,
1146,
450,
83,
8187,
315,
10536,
18,
2319,
450,
83,
9212,
12,
10536,
19,
2319,
10536,
18,
11878,
1126,
1056,
401,
2338,
12,
7373,
12,
3875,
12,
7373,
15,
835,
12,
2069,
8,
3009,
2447,
835,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
post-order.'''
def dfs(n):
c = n.firstChild
while c is not None:
for m in dfs(c):
yield m
c = c.next
yield n
for n in dfs(node):
yield n
def preOrderNodes(node):
'''Iterator through all nodes in the sub-tree rooted in node in
pre-order.'''
def dfs(n):
yield n
c = n.firstChild
while c is not None:
for m in dfs(c):
yield m
c = c.next
for n in dfs(node):
yield n
def leaves(node):
'Iterator through all leaves in the tree rooted in node.'
for n in postOrderNodes(node):
if n.isLeaf:
yield n
def innerNodes(node):
'Iterator through all inner nodes in the tree rooted in node.'
for n in postOrderNodes(node):
if not n.isLeaf:
yield n
def children(node):
'Iterate through all immediate children of node.'
c = node.firstChild
while c is not None:
yield c
c = c.next
class SuffixTree(_suffix_tree.SuffixTree):
"""A higher-level wrapper around the C suffix tree type,
_suffix_tree.SuffixTree. This class adds a few methods to the suffix
tree, methods that are more easily expressed in Python than in C, and
that can be written using the primitives exported from C. """
def __init__(self,s,t='$'):
'''Build a suffix tree from the input string s. The string
must not contain the special symbol $.'''
if t in s:
raise "The suffix tree string must not contain terminal symbol!"
_suffix_tree.SuffixTree.__init__(self,s,t)
def generatePostOrderNodes(self):
'Iterator through all nodes in the tree in post-order.'
for n in postOrderNodes(self.root):
yield n
def generatePreOrderNodes(self):
'Iterator through all nodes in the tree in pre-order.'
for n in preOrderNodes(self.root):
yield n
def generateLeaves(self):
'Iterator through all leaves in the tree.'
for n in leaves(self.root):
yield n
def generateInnerNodes(self):
'Iterator through all leaves in the tree.'
for n in innerNodes(self.root):
yield n
# set class properties
postOrderNodes = property(generatePostOrderNodes, None, None,
"postOrderNodes")
preOrderNodes = property(generatePreOrderNodes, None, None,
"preOrderNodes")
leaves = property(generateLeaves, None, None, "leaves")
innerNodes = property(generateInnerNodes, None, None, "innerNodes")
class GeneralisedSuffixTree(SuffixTree):
"""A suffix tree for a set of strings."""
def __init__(self,sequences):
'''Build a generalised suffix tree. The strings must not
contain the special symbols $ or ascii numbers from 1 to the number of
sequences.'''
self.sequences = sequences
self.startPositions = [0]
concatString = ''
for i in xrange(len(sequences)):
if chr(i+1) in sequences[i]:
raise "The suffix tree string must not contain chr(%d)!"%(i+1)
concatString += sequences[i]+chr(i+1)
self.startPositions += [len(concatString)]
self.startPositions += [self.startPositions[-1]+1] # empty string
self.sequences += ['']
SuffixTree.__init__(self,concatString)
self._annotateNodes()
def _translateIndex(self,idx):
'Translate a concat-string index into a (stringNo,idx) pair.'
for i in xrange(len(self.startPositions)-1):
if self.startPositions[i] <= idx < self.startPositions[i+1]:
return (i,idx-self.startPositions[i])
raise IndexError, "Index out of range: "+str(idx)
def _annotateNodes(self):
for n in self.postOrderNodes:
if n.isLeaf:
seq,idx = self._translateIndex(n.index)
n.pathIndices = [(seq, idx)]
n.sequences = [seq]
else:
pathIndices = [] ; sequences = []
c = n.firstChild
while c is not None:
pathIndices += c.pathIndices
sequences += c.sequences
c = c.next
seqsInSubtree = {}
for s in sequences:
seqsInSubtree[s] = 1
n.pathIndices = pathIndices
n.sequences = [s for s in seqsInSubtree]
def sharedSubstrings(self,minimumLength=0):
'''Iterator through shared sub-strings. Returned as a list of triples
(sequence,from,to).'''
for n in self.innerNodes:
if len(n.sequences) == len(self.sequences) - 1:
l = len(n.pathLabel)
if l >= minimumLength:
yield [(seq, idx, idx+l) for (seq,idx) in n.pathIndices]
def simple_test():
print 'SIMPLE TEST'
st = SuffixTree('mississippi','#')
assert st.string == 'mississippi#'
st = SuffixTree('mississippi')
assert st.string == 'mississippi$'
r = st.root
assert st.root == r
assert st.root.parent is None
assert st.root.firstChild.parent is not None
assert st.root.firstChild.parent == st.root
for n in st.postOrderNodes:
assert st.string[n.start:n.end+1] == n.edgeLabel
# collect path labels
for n in st.preOrderNodes:
p = n.parent
if p is None: # the root
n._pathLabel = ''
else:
n._pathLabel = p._pathLabel + n.edgeLabel
for n in st.postOrderNodes:
assert n.pathLabel == n._pathLabel
for l in st.leaves:
print 'leaf:', '"'+l.pathLabel+'"', ':', '"'+l.edgeLabel+'"'
for n in st.innerNodes:
print 'inner:', '"'+n.edgeLabel+'"'
print 'done.\n\n'
del st
def generalised_test():
print 'GENERALISED TEST'
sequences = ['xabxa','babxba']
st = GeneralisedSuffixTree(sequences)
for shared in st.sharedSubstrings():
print '-'*70
for seq,start,stop in shared:
print seq, '['+str(start)+':'+str(stop)+']',
print sequences[seq][start:stop],
print sequences[seq][:start]+'|'+sequences[seq][start:stop]+\
'|'+sequences[seq][stop:]
print '='*70
for shared in st.sharedSubstrings(2):
print '-'*70
for seq,start,stop in shared:
print seq, '['+str(start)+':'+str(stop)+']',
print sequences[seq][start:stop],
print sequences[seq][:start]+'|'+sequences[seq][start:stop]+\
'|'+sequences[seq][stop:]
print '='*70
print 'done.\n\n'
def test():
simple_test()
generalised_test()
if __name__ == '__main__':
test()
|
mit
|
[
199,
646,
485,
4511,
63,
2350,
199,
199,
318,
2963,
4738,
6300,
8,
932,
304,
272,
1449,
3585,
4012,
1006,
3380,
315,
314,
1007,
13,
2350,
882,
5731,
315,
1031,
315,
272,
2963,
13,
1648,
10595,
272,
347,
366,
2319,
8,
78,
304,
267,
286,
275,
302,
14,
22262,
267,
1830,
286,
365,
440,
488,
26,
288,
367,
333,
315,
366,
2319,
8,
67,
304,
355,
1995,
333,
288,
286,
275,
286,
14,
2184,
267,
1995,
302,
272,
367,
302,
315,
366,
2319,
8,
932,
304,
267,
1995,
302,
199,
199,
318,
876,
4738,
6300,
8,
932,
304,
272,
1449,
3585,
4012,
1006,
3380,
315,
314,
1007,
13,
2350,
882,
5731,
315,
1031,
315,
272,
876,
13,
1648,
10595,
272,
347,
366,
2319,
8,
78,
304,
267,
1995,
302,
267,
286,
275,
302,
14,
22262,
267,
1830,
286,
365,
440,
488,
26,
288,
367,
333,
315,
366,
2319,
8,
67,
304,
355,
1995,
333,
288,
286,
275,
286,
14,
2184,
272,
367,
302,
315,
366,
2319,
8,
932,
304,
267,
1995,
302,
199,
199,
318,
16733,
8,
932,
304,
272,
283,
3585,
4012,
1006,
16733,
315,
314,
3123,
882,
5731,
315,
1031,
3530,
272,
367,
302,
315,
2963,
4738,
6300,
8,
932,
304,
267,
340,
302,
14,
374,
20475,
26,
288,
1995,
302,
199,
199,
318,
6506,
6300,
8,
932,
304,
272,
283,
3585,
4012,
1006,
6506,
3380,
315,
314,
3123,
882,
5731,
315,
1031,
3530,
272,
367,
302,
315,
2963,
4738,
6300,
8,
932,
304,
267,
340,
440,
302,
14,
374,
20475,
26,
288,
1995,
302,
199,
199,
318,
4978,
8,
932,
304,
272,
283,
3315,
323,
4012,
1006,
8569,
4978,
402,
1031,
3530,
272,
286,
275,
1031,
14,
22262,
272,
1830,
286,
365,
440,
488,
26,
267,
1995,
286,
267,
286,
275,
286,
14,
2184,
421,
199,
533,
428,
2875,
3987,
1547,
4511,
63,
2350,
14,
20126,
3987,
304,
339,
408,
33,
10948,
13,
1896,
4975,
6818,
314,
445,
4739,
3123,
730,
12,
199,
63,
4511,
63,
2350,
14,
20126,
3987,
14,
221,
961,
1021,
9584,
282,
9284,
3102,
370,
314,
4739,
199,
2350,
12,
3102,
626,
787,
1655,
16174,
19147,
315,
2018,
2419,
315,
445,
12,
436,
199,
9099,
883,
506,
5313,
1808,
314,
1979,
22337,
16629,
687,
445,
14,
221,
408,
25979,
347,
636,
826,
721,
277,
12,
83,
12,
84,
24269,
735,
267,
1449,
3425,
282,
4739,
3123,
687,
314,
1324,
1059,
308,
14,
710,
1059,
199,
7790,
440,
1395,
314,
4539,
5272,
2672,
10595,
267,
340,
307,
315,
308,
26,
288,
746,
298,
1918,
4739,
3123,
1059,
1471,
440,
1395,
11167,
5272,
9539,
267,
485,
4511,
63,
2350,
14,
20126,
3987,
855,
826,
721,
277,
12,
83,
12,
84,
9,
339,
347,
3550,
6564,
4738,
6300,
8,
277,
304,
267,
283,
3585,
4012,
1006,
3380,
315,
314,
3123,
315,
2963,
13,
1648,
3530,
267,
367,
302,
315,
2963,
4738,
6300,
8,
277,
14,
1231,
304,
288,
1995,
302,
339,
347,
3550,
2398,
4738,
6300,
8,
277,
304,
267,
283,
3585,
4012,
1006,
3380,
315,
314,
3123,
315,
876,
13,
1648,
3530,
267,
367,
302,
315,
876,
4738,
6300,
8,
277,
14,
1231,
304,
288,
1995,
302,
339,
347,
3550,
2553,
7047,
8,
277,
304,
267,
283,
3585,
4012,
1006,
16733,
315,
314,
3123,
3530,
267,
367,
302,
315,
16733,
8,
277,
14,
1231,
304,
288,
1995,
302,
339,
347,
3550,
22964,
6300,
8,
277,
304,
267,
283,
3585,
4012,
1006,
16733,
315,
314,
3123,
3530,
267,
367,
302,
315,
6506,
6300,
8,
277,
14,
1231,
304,
288,
1995,
302,
339,
327,
663,
1021,
4382,
272,
2963,
4738,
6300,
275,
3324,
8,
4208,
6564,
4738,
6300,
12,
488,
12,
488,
12,
2892,
298,
1932,
4738,
6300,
531,
272,
876,
4738,
6300,
275,
3324,
8,
4208,
2398,
4738,
6300,
12,
488,
12,
488,
12,
2490,
298,
657,
4738,
6300,
531,
2286,
16733,
275,
3324,
8,
4208,
2553,
7047,
12,
488,
12,
488,
12,
298,
16554,
531,
272,
6506,
6300,
275,
3324,
8,
4208,
22964,
6300,
12,
488,
12,
488,
12,
298,
5216,
6300,
531,
199,
199,
533,
1696,
9096,
20126,
3987,
8,
20126,
3987,
304,
339,
408,
33,
4739,
3123,
367,
282,
663,
402,
3326,
1041,
339,
347,
636,
826,
721,
277,
12,
13436,
304,
18418,
1449,
3425,
282,
8605,
9096,
4739,
3123,
14,
221,
710,
3326,
1471,
440,
199,
7747,
314,
4539,
6698,
2672,
503,
13294,
5579,
687,
413,
370,
314,
1329,
402,
199,
13436,
10595,
398,
291,
14,
13436,
275,
8013,
267,
291,
14,
928,
32650,
275,
359,
16,
61,
267,
17159,
1558,
275,
2125,
267,
367,
284,
315,
4945,
8,
552,
8,
13436,
2298,
288,
340,
8678,
8,
73,
11,
17,
9,
315,
8013,
59,
73,
2189,
355,
746,
298,
1918,
4739,
3123,
1059,
1471,
440,
1395,
8678,
4042,
68,
9,
9539,
2840,
73,
11,
17,
9,
288,
17159,
1558,
847,
8013,
59,
73,
2807,
10194,
8,
73,
11,
17,
9,
288,
291,
14,
928,
32650,
847,
359,
552,
8,
9419,
1558,
1874,
398,
291,
14,
928,
32650,
847,
359,
277,
14,
928,
32650,
1988,
17,
2807,
17,
61,
327,
2701,
1059,
267,
291,
14,
13436,
847,
24506,
398,
428,
2875,
3987,
855,
826,
721,
277,
12,
9419,
1558,
9,
267,
291,
423,
10898,
6300,
342,
2378,
347,
485,
5275,
2681,
8,
277,
12,
2996,
304,
267,
283,
18355,
282,
17159,
13,
875,
1478,
1901,
282,
334,
875,
1944,
12,
2996,
9,
4092,
3530,
267,
367,
284,
315,
4945,
8,
552,
8,
277,
14,
928,
32650,
7216,
17,
304,
288,
340,
291,
14,
928,
32650,
59,
73,
61,
2695,
4280,
665,
291,
14,
928,
32650,
59,
73,
11,
17,
2189,
355,
372,
334,
73,
12,
2996,
13,
277,
14,
928,
32650,
59,
73,
566,
267,
746,
7888,
12,
298,
2681,
734,
402,
1425,
26,
7210,
495,
8,
2996,
9,
339,
347,
485,
10898,
6300,
8,
277,
304,
267,
367,
302,
315,
291,
14,
1932,
4738,
6300,
26,
288,
340,
302,
14,
374,
20475,
26,
355,
5412,
12,
2996,
275,
291,
423,
5275,
2681,
8,
78,
14,
1080,
9,
355,
302,
14,
515,
18488,
275,
3842,
3610,
12,
4280,
1874,
355,
302,
14,
13436,
275,
359,
3610,
61,
288,
587,
26,
355,
931,
18488,
275,
942,
8700,
8013
] |
[
646,
485,
4511,
63,
2350,
199,
199,
318,
2963,
4738,
6300,
8,
932,
304,
272,
1449,
3585,
4012,
1006,
3380,
315,
314,
1007,
13,
2350,
882,
5731,
315,
1031,
315,
272,
2963,
13,
1648,
10595,
272,
347,
366,
2319,
8,
78,
304,
267,
286,
275,
302,
14,
22262,
267,
1830,
286,
365,
440,
488,
26,
288,
367,
333,
315,
366,
2319,
8,
67,
304,
355,
1995,
333,
288,
286,
275,
286,
14,
2184,
267,
1995,
302,
272,
367,
302,
315,
366,
2319,
8,
932,
304,
267,
1995,
302,
199,
199,
318,
876,
4738,
6300,
8,
932,
304,
272,
1449,
3585,
4012,
1006,
3380,
315,
314,
1007,
13,
2350,
882,
5731,
315,
1031,
315,
272,
876,
13,
1648,
10595,
272,
347,
366,
2319,
8,
78,
304,
267,
1995,
302,
267,
286,
275,
302,
14,
22262,
267,
1830,
286,
365,
440,
488,
26,
288,
367,
333,
315,
366,
2319,
8,
67,
304,
355,
1995,
333,
288,
286,
275,
286,
14,
2184,
272,
367,
302,
315,
366,
2319,
8,
932,
304,
267,
1995,
302,
199,
199,
318,
16733,
8,
932,
304,
272,
283,
3585,
4012,
1006,
16733,
315,
314,
3123,
882,
5731,
315,
1031,
3530,
272,
367,
302,
315,
2963,
4738,
6300,
8,
932,
304,
267,
340,
302,
14,
374,
20475,
26,
288,
1995,
302,
199,
199,
318,
6506,
6300,
8,
932,
304,
272,
283,
3585,
4012,
1006,
6506,
3380,
315,
314,
3123,
882,
5731,
315,
1031,
3530,
272,
367,
302,
315,
2963,
4738,
6300,
8,
932,
304,
267,
340,
440,
302,
14,
374,
20475,
26,
288,
1995,
302,
199,
199,
318,
4978,
8,
932,
304,
272,
283,
3315,
323,
4012,
1006,
8569,
4978,
402,
1031,
3530,
272,
286,
275,
1031,
14,
22262,
272,
1830,
286,
365,
440,
488,
26,
267,
1995,
286,
267,
286,
275,
286,
14,
2184,
421,
199,
533,
428,
2875,
3987,
1547,
4511,
63,
2350,
14,
20126,
3987,
304,
339,
408,
33,
10948,
13,
1896,
4975,
6818,
314,
445,
4739,
3123,
730,
12,
199,
63,
4511,
63,
2350,
14,
20126,
3987,
14,
221,
961,
1021,
9584,
282,
9284,
3102,
370,
314,
4739,
199,
2350,
12,
3102,
626,
787,
1655,
16174,
19147,
315,
2018,
2419,
315,
445,
12,
436,
199,
9099,
883,
506,
5313,
1808,
314,
1979,
22337,
16629,
687,
445,
14,
221,
408,
25979,
347,
636,
826,
721,
277,
12,
83,
12,
84,
24269,
735,
267,
1449,
3425,
282,
4739,
3123,
687,
314,
1324,
1059,
308,
14,
710,
1059,
199,
7790,
440,
1395,
314,
4539,
5272,
2672,
10595,
267,
340,
307,
315,
308,
26,
288,
746,
298,
1918,
4739,
3123,
1059,
1471,
440,
1395,
11167,
5272,
9539,
267,
485,
4511,
63,
2350,
14,
20126,
3987,
855,
826,
721,
277,
12,
83,
12,
84,
9,
339,
347,
3550,
6564,
4738,
6300,
8,
277,
304,
267,
283,
3585,
4012,
1006,
3380,
315,
314,
3123,
315,
2963,
13,
1648,
3530,
267,
367,
302,
315,
2963,
4738,
6300,
8,
277,
14,
1231,
304,
288,
1995,
302,
339,
347,
3550,
2398,
4738,
6300,
8,
277,
304,
267,
283,
3585,
4012,
1006,
3380,
315,
314,
3123,
315,
876,
13,
1648,
3530,
267,
367,
302,
315,
876,
4738,
6300,
8,
277,
14,
1231,
304,
288,
1995,
302,
339,
347,
3550,
2553,
7047,
8,
277,
304,
267,
283,
3585,
4012,
1006,
16733,
315,
314,
3123,
3530,
267,
367,
302,
315,
16733,
8,
277,
14,
1231,
304,
288,
1995,
302,
339,
347,
3550,
22964,
6300,
8,
277,
304,
267,
283,
3585,
4012,
1006,
16733,
315,
314,
3123,
3530,
267,
367,
302,
315,
6506,
6300,
8,
277,
14,
1231,
304,
288,
1995,
302,
339,
327,
663,
1021,
4382,
272,
2963,
4738,
6300,
275,
3324,
8,
4208,
6564,
4738,
6300,
12,
488,
12,
488,
12,
2892,
298,
1932,
4738,
6300,
531,
272,
876,
4738,
6300,
275,
3324,
8,
4208,
2398,
4738,
6300,
12,
488,
12,
488,
12,
2490,
298,
657,
4738,
6300,
531,
2286,
16733,
275,
3324,
8,
4208,
2553,
7047,
12,
488,
12,
488,
12,
298,
16554,
531,
272,
6506,
6300,
275,
3324,
8,
4208,
22964,
6300,
12,
488,
12,
488,
12,
298,
5216,
6300,
531,
199,
199,
533,
1696,
9096,
20126,
3987,
8,
20126,
3987,
304,
339,
408,
33,
4739,
3123,
367,
282,
663,
402,
3326,
1041,
339,
347,
636,
826,
721,
277,
12,
13436,
304,
18418,
1449,
3425,
282,
8605,
9096,
4739,
3123,
14,
221,
710,
3326,
1471,
440,
199,
7747,
314,
4539,
6698,
2672,
503,
13294,
5579,
687,
413,
370,
314,
1329,
402,
199,
13436,
10595,
398,
291,
14,
13436,
275,
8013,
267,
291,
14,
928,
32650,
275,
359,
16,
61,
267,
17159,
1558,
275,
2125,
267,
367,
284,
315,
4945,
8,
552,
8,
13436,
2298,
288,
340,
8678,
8,
73,
11,
17,
9,
315,
8013,
59,
73,
2189,
355,
746,
298,
1918,
4739,
3123,
1059,
1471,
440,
1395,
8678,
4042,
68,
9,
9539,
2840,
73,
11,
17,
9,
288,
17159,
1558,
847,
8013,
59,
73,
2807,
10194,
8,
73,
11,
17,
9,
288,
291,
14,
928,
32650,
847,
359,
552,
8,
9419,
1558,
1874,
398,
291,
14,
928,
32650,
847,
359,
277,
14,
928,
32650,
1988,
17,
2807,
17,
61,
327,
2701,
1059,
267,
291,
14,
13436,
847,
24506,
398,
428,
2875,
3987,
855,
826,
721,
277,
12,
9419,
1558,
9,
267,
291,
423,
10898,
6300,
342,
2378,
347,
485,
5275,
2681,
8,
277,
12,
2996,
304,
267,
283,
18355,
282,
17159,
13,
875,
1478,
1901,
282,
334,
875,
1944,
12,
2996,
9,
4092,
3530,
267,
367,
284,
315,
4945,
8,
552,
8,
277,
14,
928,
32650,
7216,
17,
304,
288,
340,
291,
14,
928,
32650,
59,
73,
61,
2695,
4280,
665,
291,
14,
928,
32650,
59,
73,
11,
17,
2189,
355,
372,
334,
73,
12,
2996,
13,
277,
14,
928,
32650,
59,
73,
566,
267,
746,
7888,
12,
298,
2681,
734,
402,
1425,
26,
7210,
495,
8,
2996,
9,
339,
347,
485,
10898,
6300,
8,
277,
304,
267,
367,
302,
315,
291,
14,
1932,
4738,
6300,
26,
288,
340,
302,
14,
374,
20475,
26,
355,
5412,
12,
2996,
275,
291,
423,
5275,
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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
] |
ziir/gandi.cli
|
gandi/cli/tests/fixtures/_hosting.py
|
1
|
49432
|
try:
# python3
from xmlrpc.client import DateTime
except ImportError:
# python2
from xmlrpclib import DateTime
def image_list(options):
ret = [{'author_id': 248842,
'datacenter_id': 3,
'date_created': DateTime('20130902T15:04:18'),
'date_updated': DateTime('20130903T12:14:30'),
'disk_id': 527489,
'id': 131,
'kernel_version': '3.2-i386',
'label': 'Fedora 17 32 bits',
'os_arch': 'x86-32',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 3,
'date_created': DateTime('20130902T15:04:18'),
'date_updated': DateTime('20130903T12:14:30'),
'disk_id': 527490,
'id': 132,
'kernel_version': '3.2-x86_64',
'label': 'Fedora 17 64 bits',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 3,
'date_created': DateTime('20130902T15:04:18'),
'date_updated': DateTime('20130903T12:14:30'),
'disk_id': 527491,
'id': 133,
'kernel_version': '3.2-i386',
'label': 'OpenSUSE 12.2 32 bits',
'os_arch': 'x86-32',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 3,
'date_created': DateTime('20130902T15:04:18'),
'date_updated': DateTime('20130903T12:14:30'),
'disk_id': 527494,
'id': 134,
'kernel_version': '3.2-x86_64',
'label': 'OpenSUSE 12.2 64 bits',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 3,
'date_created': DateTime('20130902T15:04:18'),
'date_updated': DateTime('20130903T12:14:30'),
'disk_id': 726224,
'id': 149,
'kernel_version': '2.6.32',
'label': 'CentOS 5 32 bits',
'os_arch': 'x86-32',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 3,
'date_created': DateTime('20130902T15:04:18'),
'date_updated': DateTime('20130903T12:14:30'),
'disk_id': 726225,
'id': 150,
'kernel_version': '2.6.32-x86_64',
'label': 'CentOS 5 64 bits',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 3,
'date_created': DateTime('20130902T15:04:18'),
'date_updated': DateTime('20130903T12:14:30'),
'disk_id': 726230,
'id': 151,
'kernel_version': '3.2-i386',
'label': 'ArchLinux 32 bits',
'os_arch': 'x86-32',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 3,
'date_created': DateTime('20130902T15:04:18'),
'date_updated': DateTime('20130903T12:14:30'),
'disk_id': 726233,
'id': 152,
'kernel_version': '3.2-x86_64',
'label': 'ArchLinux 64 bits',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 2,
'date_created': DateTime('20140417T18:38:53'),
'date_updated': DateTime('20141030T10:38:45'),
'disk_id': 1401491,
'id': 161,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Debian 7 64 bits (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 1,
'date_created': DateTime('20140417T18:38:53'),
'date_updated': DateTime('20141030T18:06:44'),
'disk_id': 1349810,
'id': 162,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Debian 7 64 bits (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 3,
'date_created': DateTime('20140417T18:38:53'),
'date_updated': DateTime('20141030T10:38:45'),
'disk_id': 1401327,
'id': 167,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Debian 7 64 bits (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 1,
'date_created': DateTime('20141203T14:15:28'),
'date_updated': DateTime('20150116T11:24:56'),
'disk_id': 3315704,
'id': 172,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Debian 8 (testing) 64 bits (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 2,
'date_created': DateTime('20141203T14:15:28'),
'date_updated': DateTime('20150116T11:24:56'),
'disk_id': 3315992,
'id': 176,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Debian 8 (testing) 64 bits (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 3,
'date_created': DateTime('20141203T14:15:28'),
'date_updated': DateTime('20150116T11:24:56'),
'disk_id': 3316076,
'id': 180,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Debian 8 (testing) 64 bits (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 1,
'date_created': DateTime('20141203T14:15:28'),
'date_updated': DateTime('20150116T11:24:56'),
'disk_id': 3315748,
'id': 184,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Ubuntu 14.04 64 bits LTS (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 2,
'date_created': DateTime('20141203T14:15:28'),
'date_updated': DateTime('20150116T11:24:56'),
'disk_id': 3316144,
'id': 188,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Ubuntu 14.04 64 bits LTS (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 3,
'date_created': DateTime('20141203T14:15:28'),
'date_updated': DateTime('20150116T11:24:56'),
'disk_id': 3316160,
'id': 192,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Ubuntu 14.04 64 bits LTS (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 1,
'date_created': None,
'date_updated': DateTime('20150116T11:24:56'),
'disk_id': 2876292,
'id': 196,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'CentOS 7 64 bits (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 2,
'date_created': None,
'date_updated': DateTime('20150116T11:24:56'),
'disk_id': 4744388,
'id': 200,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'CentOS 7 64 bits (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 3,
'date_created': None,
'date_updated': DateTime('20150116T11:24:56'),
'disk_id': 4744392,
'id': 204,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'CentOS 7 64 bits (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
{'author_id': 248842,
'datacenter_id': 4,
'date_created': DateTime('20140417T18:38:53'),
'date_updated': DateTime('20141030T10:38:45'),
'disk_id': 1401492,
'id': 163,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Debian 7 64 bits (HVM)',
'os_arch': 'x86-64',
'size': 3072,
'visibility': 'all'},
]
for fkey in options:
ret = [dc for dc in ret if dc[fkey] == options[fkey]]
return ret
def datacenter_list(options):
ret = [{'iso': 'FR',
'name': 'Equinix Paris',
'id': 1,
'country': 'France',
'dc_code': 'FR-SD2'},
{'iso': 'US',
'name': 'Level3 Baltimore',
'id': 2,
'country': 'United States of America',
'dc_code': 'US-BA1'},
{'iso': 'LU',
'name': 'Bissen',
'id': 3,
'country': 'Luxembourg',
'dc_code': 'LU-BI1'},
{'iso': 'FR',
'name': 'France, Paris',
'id': 4,
'country': 'France',
'dc_code': 'FR-SD3'}]
options.pop('sort_by', None)
for fkey in options:
ret = [dc for dc in ret if dc[fkey] == options[fkey]]
return ret
def disk_list(options):
disks = [{'can_snapshot': True,
'datacenter_id': 3,
'date_created': DateTime('20150319T11:10:34'),
'date_updated': DateTime('20150319T11:10:58'),
'id': 4969232,
'is_boot_disk': True,
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Debian 7 64 bits (HVM)',
'name': 'sys_1426759833',
'size': 3072,
'snapshot_profile_id': None,
'snapshots_id': [],
'source': 1401327,
'state': 'created',
'total_size': 3072,
'type': 'data',
'visibility': 'private',
'vms_id': [152966]},
{'can_snapshot': True,
'datacenter_id': 1,
'date_created': DateTime('20150319T11:14:13'),
'date_updated': DateTime('20150319T11:14:29'),
'id': 4969249,
'is_boot_disk': True,
'kernel_cmdline': {'console': 'ttyS0',
'nosep': True,
'ro': True,
'root': '/dev/sda'},
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Debian 7 64 bits (HVM)',
'name': 'sys_server01',
'size': 3072,
'snapshot_profile_id': None,
'snapshots_id': [],
'source': 1349810,
'state': 'created',
'total_size': 3072,
'type': 'data',
'visibility': 'private',
'vms_id': [152967]},
{'can_snapshot': True,
'datacenter_id': 1,
'date_created': DateTime('20150319T15:39:54'),
'date_updated': DateTime('20150319T15:40:24'),
'id': 4970079,
'is_boot_disk': False,
'kernel_version': None,
'label': None,
'name': 'data',
'size': 3072,
'snapshot_profile_id': 1,
'snapshots_id': [663497],
'source': None,
'state': 'created',
'total_size': 3072,
'type': 'data',
'visibility': 'private',
'vms_id': [152967]},
{'can_snapshot': False,
'datacenter_id': 1,
'date_created': DateTime('20140826T00:00:00'),
'date_updated': DateTime('20140826T00:00:00'),
'id': 663497,
'is_boot_disk': False,
'kernel_version': '3.2-x86_64',
'label': 'Debian 7 64 bits',
'name': 'snaptest',
'size': 3072,
'snapshot_profile_id': None,
'snapshots_id': [],
'source': 4970079,
'state': 'created',
'total_size': 3072,
'type': 'snapshot',
'visibility': 'private',
'vms_id': []}]
options.pop('items_per_page', None)
for fkey in options:
ret = []
for disk in disks:
if isinstance(options[fkey], list):
if disk[fkey] in options[fkey]:
ret.append(disk)
elif disk[fkey] == options[fkey]:
ret.append(disk)
disks = ret
return disks
def disk_info(id):
disks = disk_list({})
disks = dict([(disk['id'], disk) for disk in disks])
return disks[id]
def disk_update(disk_id, options):
return {'id': 200, 'step': 'WAIT'}
def disk_delete(disk_id):
return {'id': 200, 'step': 'WAIT'}
def disk_rollback_from(disk_id):
return {'id': 200, 'step': 'WAIT'}
def disk_create_from(options, disk_id):
return {'id': 200, 'step': 'WAIT'}
def disk_create(options):
return {'id': 200, 'step': 'WAIT', 'disk_id': 9000}
def vm_list(options):
ret = [{'ai_active': 0,
'console': 0,
'cores': 1,
'datacenter_id': 3,
'date_created': DateTime('20141008T16:13:59'),
'date_updated': DateTime('20150319T11:11:31'),
'description': None,
'disks_id': [4969232],
'flex_shares': 0,
'hostname': 'vm1426759833',
'id': 152966,
'ifaces_id': [156572],
'memory': 256,
'state': 'running',
'vm_max_memory': 2048},
{'ai_active': 0,
'console': 0,
'cores': 1,
'datacenter_id': 1,
'date_created': DateTime('20150319T11:14:13'),
'date_updated': DateTime('20150319T11:14:55'),
'description': None,
'disks_id': [4969249],
'flex_shares': 0,
'hostname': 'server01',
'id': 152967,
'ifaces_id': [156573],
'memory': 256,
'state': 'running',
'vm_max_memory': 2048},
{'ai_active': 0,
'console': 0,
'cores': 1,
'datacenter_id': 1,
'date_created': DateTime('20150319T11:14:13'),
'date_updated': DateTime('20150319T11:14:55'),
'description': None,
'disks_id': [4969250],
'flex_shares': 0,
'hostname': 'server02',
'id': 152968,
'ifaces_id': [156574],
'memory': 256,
'state': 'halted',
'vm_max_memory': 2048}]
options.pop('items_per_page', None)
for fkey in options:
ret = [vm for vm in ret if vm[fkey] == options[fkey]]
return ret
def vm_info(id):
ret = [{'ai_active': 0,
'console': 0,
'console_url': 'console.gandi.net',
'cores': 1,
'datacenter_id': 3,
'date_created': DateTime('20150319T11:10:34'),
'date_updated': DateTime('20150319T11:11:31'),
'description': None,
'disks': [{'can_snapshot': True,
'datacenter_id': 3,
'date_created': DateTime('20150319T11:10:34'),
'date_updated': DateTime('20150319T11:10:58'),
'id': 4969232,
'is_boot_disk': True,
'kernel_cmdline': {'console': 'ttyS0',
'nosep': True,
'ro': True,
'root': '/dev/sda'},
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Debian 7 64 bits (HVM)',
'name': 'sys_1426759833',
'size': 3072,
'snapshot_profile': None,
'snapshots_id': [],
'source': 1401327,
'state': 'created',
'total_size': 3072,
'type': 'data',
'visibility': 'private',
'vms_id': [152966]}],
'disks_id': [4969232],
'flex_shares': 0,
'graph_urls': {'vcpu': [''], 'vdi': [''], 'vif': ['']},
'hostname': 'vm1426759833',
'id': 152966,
'ifaces': [{'bandwidth': 102400.0,
'datacenter_id': 3,
'date_created': DateTime('20150319T11:10:34'),
'date_updated': DateTime('20150319T11:10:35'),
'id': 156572,
'ips': [{'datacenter_id': 3,
'date_created': DateTime('20150319T11:10:34'),
'date_updated': DateTime('20150319T11:10:36'),
'id': 204557,
'iface_id': 156572,
'ip': '2001:4b98:dc2:43:216:3eff:fece:e25f',
'num': 0,
'reverse': 'xvm6-dc2-fece-e25f.ghst.net',
'state': 'created',
'version': 6}],
'ips_id': [204557],
'num': 0,
'state': 'used',
'type': 'public',
'vlan': None,
'vm_id': 152966}],
'ifaces_id': [156572],
'memory': 256,
'probes': [],
'state': 'running',
'triggers': [],
'vm_max_memory': 2048},
{'ai_active': 0,
'console': 0,
'console_url': 'console.gandi.net',
'cores': 1,
'datacenter_id': 1,
'date_created': DateTime('20150319T11:14:13'),
'date_updated': DateTime('20150319T11:14:55'),
'description': None,
'disks': [{'can_snapshot': True,
'datacenter_id': 1,
'date_created': DateTime('20150319T11:14:13'),
'date_updated': DateTime('20150319T11:14:29'),
'id': 4969249,
'is_boot_disk': True,
'kernel_cmdline': {'console': 'ttyS0',
'nosep': True,
'ro': True,
'root': '/dev/sda'},
'kernel_version': '3.12-x86_64 (hvm)',
'label': 'Debian 7 64 bits (HVM)',
'name': 'sys_server01',
'size': 3072,
'snapshot_profile': None,
'snapshots_id': [],
'source': 1349810,
'state': 'created',
'total_size': 3072,
'type': 'data',
'visibility': 'private',
'vms_id': [152967]}],
'disks_id': [4969249],
'flex_shares': 0,
'graph_urls': {'vcpu': [''], 'vdi': [''], 'vif': ['']},
'hostname': 'server01',
'id': 152967,
'ifaces': [{'bandwidth': 102400.0,
'datacenter_id': 1,
'date_created': DateTime('20150319T11:14:13'),
'date_updated': DateTime('20150319T11:14:16'),
'id': 156573,
'ips': [{'datacenter_id': 1,
'date_created': DateTime('20150317T16:20:10'),
'date_updated': DateTime('20150319T11:14:13'),
'id': 203968,
'iface_id': 156573,
'ip': '95.142.160.181',
'num': 0,
'reverse': 'xvm-160-181.dc0.ghst.net',
'state': 'created',
'version': 4},
{'datacenter_id': 1,
'date_created': DateTime('20150319T11:14:16'),
'date_updated': DateTime('20150319T11:14:16'),
'id': 204558,
'iface_id': 156573,
'ip': '2001:4b98:dc0:47:216:3eff:feb2:3862',
'num': 1,
'reverse': 'xvm6-dc0-feb2-3862.ghst.net',
'state': 'created',
'version': 6}],
'ips_id': [203968, 204558],
'num': 0,
'state': 'used',
'type': 'public',
'vlan': None,
'vm_id': 152967}],
'ifaces_id': [156573],
'memory': 256,
'probes': [],
'state': 'running',
'triggers': [],
'vm_max_memory': 2048},
{'ai_active': 0,
'console': 0,
'console_url': 'console.gandi.net',
'cores': 1,
'datacenter_id': 4,
'date_created': DateTime('20160115T162658'),
'date_updated': DateTime('20160115T162658'),
'description': None,
'disks': [],
'disks_id': [4969250],
'flex_shares': 0,
'graph_urls': {'vcpu': [''], 'vdi': [''], 'vif': ['', '']},
'hostname': 'server02',
'hvm_state': 'unknown',
'id': 152968,
'ifaces': [{'bandwidth': 102400.0,
'datacenter_id': 4,
'date_created': DateTime('20160115T162658'),
'date_updated': DateTime('20160115T162658'),
'id': 1274919,
'ips': [{'datacenter_id': 4,
'date_created': DateTime('20160115T162658'),
'date_updated': DateTime('20160115T162658'),
'id': 351155,
'iface_id': 1274919,
'ip': '213.167.231.3',
'num': 0,
'reverse': 'xvm-231-3.sd3.ghst.net',
'state': 'created',
'version': 4},
{'datacenter_id': 4,
'date_created': DateTime('20160115T162658'),
'date_updated': DateTime('20160115T162658'),
'id': 352862,
'iface_id': 1274919,
'ip': '2001:4b98:c001:1:216:3eff:fec5:c104',
'num': 1,
'reverse': 'xvm6-c001-fec5-c104.ghst.net',
'state': 'created',
'version': 6}],
'ips_id': [351155, 352862],
'num': 0,
'state': 'used',
'type': 'public',
'vlan': {'id': 717, 'name': 'pouet'},
'vm_id': 227627},
{'bandwidth': 102400.0,
'datacenter_id': 4,
'date_created': DateTime('20160115T162658'),
'date_updated': DateTime('20160115T162658'),
'id': 1416,
'ips': [{'datacenter_id': 1,
'date_created': DateTime('20160115T162658'),
'date_updated': DateTime('20160115T162702'),
'id': 2361,
'iface_id': 1416,
'ip': '192.168.232.252',
'num': 0,
'reverse': '',
'state': 'created',
'version': 4}],
'ips_id': [2361],
'num': 1,
'state': 'used',
'type': 'private',
'vlan': {'id': 717, 'name': 'pouet'},
'vm_id': 227627}],
'ifaces_id': [1274919, 1416],
'memory': 236,
'probes': [],
'state': 'halted',
'triggers': [],
'vm_max_memory': 2048}]
vms = dict([(vm['id'], vm) for vm in ret])
return vms[id]
def metric_query(query):
vif_bytes_all = [
{'direction': ['in'],
'metric': 'vif.bytes',
'points': [{'timestamp': '2015-03-18T10:00:00', 'value': 24420.0},
{'timestamp': '2015-03-18T11:00:00', 'value': 22370.0},
{'timestamp': '2015-03-18T12:00:00', 'value': 46680.0},
{'timestamp': '2015-03-18T13:00:00', 'value': 61664.0},
{'timestamp': '2015-03-18T14:00:00', 'value': 142789.0},
{'timestamp': '2015-03-18T15:00:00', 'value': 35633.0},
{'timestamp': '2015-03-18T16:00:00', 'value': 213987.0},
{'timestamp': '2015-03-18T17:00:00', 'value': 80055.0},
{'timestamp': '2015-03-18T18:00:00', 'value': 57690.0},
{'timestamp': '2015-03-18T19:00:00', 'value': 83508.0},
{'timestamp': '2015-03-18T20:00:00', 'value': 115038.0},
{'timestamp': '2015-03-18T21:00:00', 'value': 71923.0},
{'timestamp': '2015-03-18T22:00:00', 'value': 259466.0},
{'timestamp': '2015-03-18T23:00:00', 'value': 301198.0},
{'timestamp': '2015-03-19T00:00:00', 'value': 69579.0},
{'timestamp': '2015-03-19T01:00:00', 'value': 99998.0},
{'timestamp': '2015-03-19T02:00:00', 'value': 53706.0},
{'timestamp': '2015-03-19T03:00:00', 'value': 55539.0},
{'timestamp': '2015-03-19T04:00:00', 'value': 60018.0},
{'timestamp': '2015-03-19T05:00:00', 'value': 23000.0},
{'timestamp': '2015-03-19T06:00:00', 'value': 57812.0},
{'timestamp': '2015-03-19T07:00:00', 'value': 984992.0},
{'timestamp': '2015-03-19T08:00:00', 'value': 315608.0},
{'timestamp': '2015-03-19T09:00:00', 'value': 77852.0}],
'resource_id': 152967,
'resource_type': 'vm',
'type': ['public']},
{'direction': ['out'],
'metric': 'vif.bytes',
'points': [{'timestamp': '2015-03-18T10:00:00', 'value': 5335.0},
{'timestamp': '2015-03-18T11:00:00', 'value': 8763.0},
{'timestamp': '2015-03-18T12:00:00', 'value': 43790.0},
{'timestamp': '2015-03-18T13:00:00', 'value': 73345.0},
{'timestamp': '2015-03-18T14:00:00', 'value': 259536.0},
{'timestamp': '2015-03-18T15:00:00', 'value': 18595.0},
{'timestamp': '2015-03-18T16:00:00', 'value': 751379.0},
{'timestamp': '2015-03-18T17:00:00', 'value': 150840.0},
{'timestamp': '2015-03-18T18:00:00', 'value': 43115.0},
{'timestamp': '2015-03-18T19:00:00', 'value': 593737.0},
{'timestamp': '2015-03-18T20:00:00', 'value': 619675.0},
{'timestamp': '2015-03-18T21:00:00', 'value': 67605.0},
{'timestamp': '2015-03-18T22:00:00', 'value': 300711.0},
{'timestamp': '2015-03-18T23:00:00', 'value': 380400.0},
{'timestamp': '2015-03-19T00:00:00', 'value': 62705.0},
{'timestamp': '2015-03-19T01:00:00', 'value': 100512.0},
{'timestamp': '2015-03-19T02:00:00', 'value': 47963.0},
{'timestamp': '2015-03-19T03:00:00', 'value': 50301.0},
{'timestamp': '2015-03-19T04:00:00', 'value': 48572.0},
{'timestamp': '2015-03-19T05:00:00', 'value': 6263.0},
{'timestamp': '2015-03-19T06:00:00', 'value': 67014.0},
{'timestamp': '2015-03-19T07:00:00', 'value': 777215.0},
{'timestamp': '2015-03-19T08:00:00', 'value': 495497.0},
{'timestamp': '2015-03-19T09:00:00', 'value': 660825.0}],
'resource_id': 152967,
'resource_type': 'vm',
'type': ['public']}]
vbd_bytes_all = [
{'direction': ['read'],
'metric': 'vbd.bytes',
'points': [{'timestamp': '2015-03-18T10:00:00', 'value': 13824000.0},
{'timestamp': '2015-03-18T11:00:00', 'value': 5644288.0},
{'timestamp': '2015-03-18T12:00:00', 'value': 0.0},
{'timestamp': '2015-03-18T13:00:00', 'value': 13516800.0},
{'timestamp': '2015-03-18T14:00:00', 'value': 27918336.0},
{'timestamp': '2015-03-18T15:00:00', 'value': 9150464.0},
{'timestamp': '2015-03-18T16:00:00', 'value': 64323584.0},
{'timestamp': '2015-03-18T17:00:00', 'value': 29974528.0},
{'timestamp': '2015-03-18T18:00:00', 'value': 761856.0},
{'timestamp': '2015-03-18T19:00:00', 'value': 41775104.0},
{'timestamp': '2015-03-18T20:00:00', 'value': 14286848.0},
{'timestamp': '2015-03-18T21:00:00', 'value': 1073152.0},
{'timestamp': '2015-03-18T22:00:00', 'value': 387248128.0},
{'timestamp': '2015-03-18T23:00:00', 'value': 13754368.0},
{'timestamp': '2015-03-19T00:00:00', 'value': 2056192.0},
{'timestamp': '2015-03-19T01:00:00', 'value': 9990144.0},
{'timestamp': '2015-03-19T02:00:00', 'value': 643072.0},
{'timestamp': '2015-03-19T03:00:00', 'value': 6148096.0},
{'timestamp': '2015-03-19T04:00:00', 'value': 8974336.0},
{'timestamp': '2015-03-19T05:00:00', 'value': 782336.0},
{'timestamp': '2015-03-19T06:00:00', 'value': 12214272.0},
{'timestamp': '2015-03-19T07:00:00', 'value': 29261824.0},
{'timestamp': '2015-03-19T08:00:00', 'value': 144080896.0},
{'timestamp': '2015-03-19T09:00:00', 'value': 39198720.0}],
'resource_id': 152967,
'resource_type': 'vm'},
{'direction': ['write'],
'metric': 'vbd.bytes',
'points': [{'timestamp': '2015-03-18T10:00:00', 'value': 217088.0},
{'timestamp': '2015-03-18T11:00:00', 'value': 229376.0},
{'timestamp': '2015-03-18T12:00:00', 'value': 401408.0},
{'timestamp': '2015-03-18T13:00:00', 'value': 577536.0},
{'timestamp': '2015-03-18T14:00:00', 'value': 3862528.0},
{'timestamp': '2015-03-18T15:00:00', 'value': 217088.0},
{'timestamp': '2015-03-18T16:00:00', 'value': 2363392.0},
{'timestamp': '2015-03-18T17:00:00', 'value': 1773568.0},
{'timestamp': '2015-03-18T18:00:00', 'value': 217088.0},
{'timestamp': '2015-03-18T19:00:00', 'value': 3153920.0},
{'timestamp': '2015-03-18T20:00:00', 'value': 2039808.0},
{'timestamp': '2015-03-18T21:00:00', 'value': 606208.0},
{'timestamp': '2015-03-18T22:00:00', 'value': 12505088.0},
{'timestamp': '2015-03-18T23:00:00', 'value': 675840.0},
{'timestamp': '2015-03-19T00:00:00', 'value': 602112.0},
{'timestamp': '2015-03-19T01:00:00', 'value': 598016.0},
{'timestamp': '2015-03-19T02:00:00', 'value': 483328.0},
{'timestamp': '2015-03-19T03:00:00', 'value': 462848.0},
{'timestamp': '2015-03-19T04:00:00', 'value': 471040.0},
{'timestamp': '2015-03-19T05:00:00', 'value': 487424.0},
{'timestamp': '2015-03-19T06:00:00', 'value': 499712.0},
{'timestamp': '2015-03-19T07:00:00', 'value': 42958848.0},
{'timestamp': '2015-03-19T08:00:00', 'value': 6299648.0},
{'timestamp': '2015-03-19T09:00:00', 'value': 3862528.0}],
'resource_id': 152967,
'resource_type': 'vm'}]
vfs_df_bytes_all = [
{'metric': 'vfs.df.bytes',
'points': [{'timestamp': '2015-11-18T07:19:00',
'value': 10679488512.0},
{'timestamp': '2015-11-18T07:20:00'}],
'resource_id': 163744,
'resource_type': 'paas',
'size': ['free']},
{'metric': 'vfs.df.bytes',
'points': [{'timestamp': '2015-11-18T07:19:00',
'value': 57929728.0},
{'timestamp': '2015-11-18T07:20:00'}],
'resource_id': 163744,
'resource_type': 'paas',
'size': ['used']}]
webacc_requests_cache_all = [
{'cache': ['miss'],
'metric': 'webacc.requests',
'points': [{'timestamp': '2015-11-17T00:00:00', 'value': 2.0},
{'timestamp': '2015-11-18T00:00:00'}],
'resource_id': 163744,
'resource_type': 'paas',
'status': ['2xx']}]
metrics = {'vif.bytes.all': vif_bytes_all,
'vbd.bytes.all': vbd_bytes_all,
'vfs.df.bytes.all': vfs_df_bytes_all,
'webacc.requests.cache.all': webacc_requests_cache_all}
metrics = [item for item in metrics[query['query']]
if item['resource_id'] == query['resource_id'][0]]
return metrics
def disk_list_kernels(dc_id):
ret = {
1: {'linux': ['2.6.18 (deprecated)',
'2.6.27-compat-sysfs (deprecated)',
'2.6.32',
'2.6.27 (deprecated)',
'2.6.32-x86_64',
'2.6.36 (deprecated)',
'2.6.32-x86_64-grsec',
'2.6.36-x86_64 (deprecated)',
'3.2-i386',
'3.2-x86_64',
'3.2-x86_64-grsec',
'3.10-x86_64',
'3.10-i386'],
'linux-hvm': ['3.12-x86_64 (hvm)', 'grub', 'raw']},
2: {'linux': ['2.6.18 (deprecated)',
'2.6.27-compat-sysfs (deprecated)',
'2.6.32',
'2.6.27 (deprecated)',
'2.6.32-x86_64',
'2.6.36 (deprecated)',
'2.6.32-x86_64-grsec',
'2.6.36-x86_64 (deprecated)',
'3.2-i386',
'3.2-x86_64',
'3.2-x86_64-grsec',
'3.10-x86_64',
'3.10-i386'],
'linux-hvm': ['3.12-x86_64 (hvm)', 'grub', 'raw']},
3: {'linux': ['2.6.32',
'2.6.27 (deprecated)',
'2.6.32-x86_64',
'2.6.32-x86_64-grsec',
'3.2-i386',
'3.2-x86_64',
'3.2-x86_64-grsec',
'3.10-x86_64',
'3.10-i386'],
'linux-hvm': ['3.12-x86_64 (hvm)', 'grub', 'raw']},
4: {'linux': ['2.6.32',
'2.6.27 (deprecated)',
'2.6.32-x86_64',
'2.6.32-x86_64-grsec',
'3.2-i386',
'3.2-x86_64',
'3.2-x86_64-grsec',
'3.10-x86_64',
'3.10-i386'],
'linux-hvm': ['3.12-x86_64 (hvm)', 'grub', 'raw']}}
return ret[dc_id]
def account_info():
return {'average_credit_cost': 0.0,
'credits': 2335360,
'cycle_day': 23,
'date_credits_expiration': DateTime('20160319T10:07:24'),
'fullname': 'Peter Parker',
'handle': 'PXP561-GANDI',
'id': 2920674,
'products': None,
'rating_enabled': True,
'resources': {'available': None,
'expired': None,
'granted': None,
'used': None},
'share_definition': None}
def rating_list():
return [{'bw_out': None,
'cpu': {'default': 168},
'disk_data': {'default': 135},
'disk_snapshot': None,
'disk_snapshot_auto': None,
'instance': {'default': 0},
'ip': {'v4_public': 210, 'v6': 0},
'ram': {'default': 120},
'rproxy': None,
'rproxy_server': None,
'rproxy_ssl': None,
'timestamp': DateTime('20150319T15:07:24')}]
def vm_disk_detach(vm_id, disk_id):
if vm_id == 152967 and disk_id == 4970079:
return {'id': 200, 'step': 'WAIT'}
def vm_iface_detach(vm_id, iface_id):
if vm_id == 152967 and iface_id == 156573:
return {'id': 200, 'step': 'WAIT'}
def vm_iface_attach(vm_id, iface_id):
if vm_id == 152966 and iface_id == 156573:
return {'id': 200, 'step': 'WAIT'}
if vm_id == 152967 and iface_id == 156572:
return {'id': 200, 'step': 'WAIT'}
if vm_id == 152967 and iface_id == 156573:
return {'id': 200, 'step': 'WAIT', 'iface_id': 156573}
def vm_disk_attach(vm_id, disk_id, options):
if vm_id == 152967 and disk_id == 663497:
return {'id': 200, 'step': 'WAIT'}
if vm_id == 152966 and disk_id == 4970079:
return {'id': 200, 'step': 'WAIT'}
if vm_id == 152967 and disk_id == 9000:
return {'id': 200, 'step': 'WAIT'}
def vm_stop(vm_id):
if vm_id in (152967, 152966):
return {'id': 200, 'step': 'WAIT'}
def vm_start(vm_id):
if vm_id in (152967, 152966):
return {'id': 200, 'step': 'WAIT'}
def vm_reboot(vm_id):
if vm_id in (152967, 152966):
return {'id': 200, 'step': 'WAIT'}
def vm_delete(vm_id):
if vm_id in (152968, 152967, 152966):
return {'id': 200, 'step': 'WAIT'}
def vm_update(vm_id, options):
if vm_id in (152967, 152966):
return {'id': 200, 'step': 'WAIT'}
def vm_create_from(vm_spec, disk_spec, src_disk_id):
return [{'id': 300, 'step': 'WAIT'}]
def vlan_list(options):
ret = [{'datacenter_id': 1,
'gateway': '10.7.13.254',
'id': 123,
'name': 'vlantest',
'state': 'created',
'subnet': '10.7.13.0/24',
'uuid': 321},
{'datacenter_id': 1,
'gateway': '192.168.232.254',
'id': 717,
'name': 'pouet',
'state': 'created',
'subnet': '192.168.232.0/24',
'uuid': 720},
{'datacenter_id': 4,
'gateway': '10.7.242.254',
'id': 999,
'name': 'intranet',
'state': 'created',
'subnet': '10.7.242.0/24',
'uuid': 421}]
options.pop('items_per_page', None)
for fkey in options:
ret = [vlan for vlan in ret if vlan[fkey] == options[fkey]]
return ret
def vlan_info(id):
vlans = vlan_list({})
vlans = dict([(vlan['id'], vlan) for vlan in vlans])
return vlans[id]
def vlan_delete(vlan_id):
return {'id': 200, 'step': 'WAIT'}
def vlan_create(options):
return {'id': 200, 'step': 'WAIT'}
def vlan_update(vlan_id, options):
return {'id': 200, 'step': 'WAIT'}
def iface_create(options):
if 'ip' in options:
return {'id': 200, 'step': 'WAIT', 'iface_id': 156572}
return {'id': 200, 'step': 'WAIT', 'iface_id': 156573}
def iface_delete(ip_id):
return {'id': 200, 'step': 'WAIT'}
def iface_list(options):
ret = [{'bandwidth': 102400.0,
'datacenter_id': 1,
'date_created': DateTime('20140423T00:00:00'),
'date_updated': DateTime('20140423T00:00:00'),
'id': 156573,
'ips_id': [203968, 204558],
'ips': [{'datacenter_id': 1,
'date_created': DateTime('20150317T16:20:10'),
'date_updated': DateTime('20150319T11:14:13'),
'id': 203968,
'iface_id': 156573,
'ip': '95.142.160.181',
'num': 0,
'reverse': 'xvm-160-181.dc0.ghst.net',
'state': 'created',
'version': 4},
{'datacenter_id': 1,
'date_created': DateTime('20150319T11:14:16'),
'date_updated': DateTime('20150319T11:14:16'),
'id': 204558,
'iface_id': 156573,
'ip': '2001:4b98:dc0:47:216:3eff:feb2:3862',
'num': 1,
'reverse': 'xvm6-dc0-feb2-3862.ghst.net',
'state': 'created',
'version': 6}],
'num': 0,
'state': 'used',
'type': 'public',
'vlan': None,
'vm_id': 152967},
{'bandwidth': 102400.0,
'datacenter_id': 1,
'date_created': DateTime('20141009T00:00:00'),
'date_updated': DateTime('20141105T00:00:00'),
'id': 1416,
'ips_id': [2361],
'ips': [{'datacenter_id': 1,
'date_created': DateTime('20160115T162658'),
'date_updated': DateTime('20160115T162702'),
'id': 2361,
'iface_id': 1416,
'ip': '192.168.232.252',
'num': 0,
'reverse': '',
'state': 'created',
'version': 4}],
'num': None,
'state': 'used',
'type': 'private',
'vlan': {'id': 717, 'name': 'pouet'},
'vm_id': 152968},
{'bandwidth': 204800.0,
'datacenter_id': 1,
'date_created': DateTime('20150105T00:00:00'),
'date_updated': DateTime('20150105T00:00:00'),
'id': 1914,
'ips': [{'datacenter_id': 1,
'date_created': DateTime('20160115T162658'),
'date_updated': DateTime('20160115T162702'),
'id': 2361,
'iface_id': 1914,
'ip': '192.168.232.253',
'num': 0,
'reverse': '',
'state': 'created',
'version': 4}],
'ips_id': [2361],
'num': None,
'state': 'used',
'type': 'private',
'vlan': {'id': 717, 'name': 'pouet'},
'vm_id': 152968},
{'bandwidth': 204800.0,
'datacenter_id': 1,
'date_created': DateTime('20150105T00:00:00'),
'date_updated': DateTime('20150105T00:00:00'),
'id': 156572,
'ips_id': [204557],
'ips': [{'datacenter_id': 3,
'date_created': DateTime('20150319T11:10:34'),
'date_updated': DateTime('20150319T11:10:36'),
'id': 204557,
'iface_id': 156572,
'ip': '10.50.10.10',
'num': 0,
'reverse': 'xvm6-dc2-fece-e25f.ghst.net',
'state': 'created',
'version': 4}],
'num': None,
'state': 'free',
'type': 'private',
'vlan': None,
'vm_id': None}]
options.pop('items_per_page', None)
for fkey in options:
if fkey == 'vlan':
ret_ = []
for iface in ret:
if iface['vlan'] and iface['vlan']['name'] == options['vlan']:
ret_.append(iface)
ret = ret_
elif fkey == 'vlan_id':
ret_ = []
for iface in ret:
if iface['vlan'] and iface['vlan']['id'] == options['vlan_id']:
ret_.append(iface)
ret = ret_
else:
ret = [iface for iface in ret if iface[fkey] == options[fkey]]
return ret
def iface_info(iface_id):
ifaces = iface_list({})
ifaces = dict([(iface['id'], iface) for iface in ifaces])
return ifaces[iface_id]
def ip_list(options):
ips = [{'datacenter_id': 1,
'date_created': DateTime('20150317T16:20:10'),
'date_updated': DateTime('20150319T11:14:13'),
'id': 203968,
'iface_id': 156573,
'ip': '95.142.160.181',
'num': 0,
'reverse': 'xvm-160-181.dc0.ghst.net',
'state': 'created',
'version': 4},
{'datacenter_id': 3,
'date_created': DateTime('20150319T11:10:34'),
'date_updated': DateTime('20150319T11:10:36'),
'id': 204557,
'iface_id': 156572,
'ip': '2001:4b98:dc2:43:216:3eff:fece:e25f',
'num': 0,
'reverse': 'xvm6-dc2-fece-e25f.ghst.net',
'state': 'created',
'version': 6},
{'datacenter_id': 1,
'date_created': DateTime('20150319T11:14:16'),
'date_updated': DateTime('20150319T11:14:16'),
'id': 204558,
'iface_id': 156573,
'ip': '2001:4b98:dc0:47:216:3eff:feb2:3862',
'num': 1,
'reverse': 'xvm6-dc0-feb2-3862.ghst.net',
'state': 'created',
'version': 6},
{'datacenter_id': 1,
'date_created': DateTime('20160115T162658'),
'date_updated': DateTime('20160115T162702'),
'id': 2361,
'iface_id': 1914,
'ip': '192.168.232.253',
'num': 0,
'reverse': '',
'state': 'created',
'version': 4},
{'datacenter_id': 1,
'date_created': DateTime('20160115T162658'),
'date_updated': DateTime('20160115T162702'),
'id': 2361,
'iface_id': 1416,
'ip': '192.168.232.252',
'num': 0,
'reverse': '',
'state': 'created',
'version': 4}]
options.pop('items_per_page', None)
for fkey in options:
ret = []
for ip in ips:
if isinstance(options[fkey], list):
if ip[fkey] in options[fkey]:
ret.append(ip)
elif ip[fkey] == options[fkey]:
ret.append(ip)
ips = ret
return ips
def ip_info(ip_id):
ips = ip_list({})
ips = dict([(ip['id'], ip) for ip in ips])
return ips[ip_id]
def ip_update(ip_id, options):
return {'id': 200, 'step': 'WAIT'}
def ssh_list(options):
ret = [{'fingerprint': 'b3:11:67:10:2e:1b:a5:66:ed:16:24:98:3e:2e:ed:f5',
'id': 134,
'name': 'default'},
{'fingerprint': '09:11:21:e3:90:3c:7d:d5:06:d9:6f:f9:36:e1:99:a6',
'id': 141,
'name': 'mysecretkey'}]
options.pop('items_per_page', None)
for fkey in options:
ret = [vm for vm in ret if vm[fkey] == options[fkey]]
return ret
def snapshotprofile_list(options):
ret = [{'id': 1,
'kept_total': 2,
'name': 'minimal',
'quota_factor': 1.2,
'schedules': [{'kept_version': 2, 'name': 'daily'}]},
{'id': 2,
'kept_total': 7,
'name': 'full_week',
'quota_factor': 1.7,
'schedules': [{'kept_version': 7, 'name': 'daily'}]},
{'id': 3,
'kept_total': 10,
'name': 'security',
'quota_factor': 2.0,
'schedules': [{'kept_version': 3, 'name': 'hourly6'},
{'kept_version': 6, 'name': 'daily'},
{'kept_version': 1, 'name': 'weekly4'}]}]
for fkey in options:
ret = [snp for snp in ret if snp[fkey] == options[fkey]]
return ret
|
gpl-3.0
|
[
893,
26,
272,
327,
2366,
19,
272,
687,
15432,
14,
1258,
492,
13686,
199,
2590,
3545,
26,
272,
327,
2366,
18,
272,
687,
19122,
492,
13686,
421,
199,
318,
1834,
63,
513,
8,
1419,
304,
339,
2203,
275,
9016,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
959,
9014,
1407,
12,
288,
283,
344,
356,
30542,
12,
288,
283,
4989,
63,
1023,
356,
283,
19,
14,
18,
13,
73,
8040,
297,
288,
283,
1302,
356,
283,
38,
379,
11131,
5557,
4337,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
708,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
959,
9014,
2710,
12,
288,
283,
344,
356,
27207,
12,
288,
283,
4989,
63,
1023,
356,
283,
19,
14,
18,
13,
88,
1184,
63,
772,
297,
288,
283,
1302,
356,
283,
38,
379,
11131,
5557,
5049,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
772,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
959,
9014,
3328,
12,
288,
283,
344,
356,
28416,
12,
288,
283,
4989,
63,
1023,
356,
283,
19,
14,
18,
13,
73,
8040,
297,
288,
283,
1302,
356,
283,
4299,
51,
4701,
3144,
14,
18,
4337,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
708,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
959,
9014,
2635,
12,
288,
283,
344,
356,
25956,
12,
288,
283,
4989,
63,
1023,
356,
283,
19,
14,
18,
13,
88,
1184,
63,
772,
297,
288,
283,
1302,
356,
283,
4299,
51,
4701,
3144,
14,
18,
5049,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
772,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
1520,
1479,
8731,
12,
288,
283,
344,
356,
28528,
12,
288,
283,
4989,
63,
1023,
356,
283,
18,
14,
22,
14,
708,
297,
288,
283,
1302,
356,
283,
22744,
3100,
959,
4337,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
708,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
1520,
1479,
10932,
12,
288,
283,
344,
356,
14711,
12,
288,
283,
4989,
63,
1023,
356,
283,
18,
14,
22,
14,
708,
13,
88,
1184,
63,
772,
297,
288,
283,
1302,
356,
283,
22744,
3100,
959,
5049,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
772,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
1520,
1479,
9687,
12,
288,
283,
344,
356,
413,
2869,
12,
288,
283,
4989,
63,
1023,
356,
283,
19,
14,
18,
13,
73,
8040,
297,
288,
283,
1302,
356,
283,
8438,
14091,
4337,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
708,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
1520,
1479,
10034,
12,
288,
283,
344,
356,
413,
2528,
12,
288,
283,
4989,
63,
1023,
356,
283,
19,
14,
18,
13,
88,
1184,
63,
772,
297,
288,
283,
1302,
356,
283,
8438,
14091,
5049,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
772,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791
] |
[
26,
272,
327,
2366,
19,
272,
687,
15432,
14,
1258,
492,
13686,
199,
2590,
3545,
26,
272,
327,
2366,
18,
272,
687,
19122,
492,
13686,
421,
199,
318,
1834,
63,
513,
8,
1419,
304,
339,
2203,
275,
9016,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
959,
9014,
1407,
12,
288,
283,
344,
356,
30542,
12,
288,
283,
4989,
63,
1023,
356,
283,
19,
14,
18,
13,
73,
8040,
297,
288,
283,
1302,
356,
283,
38,
379,
11131,
5557,
4337,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
708,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
959,
9014,
2710,
12,
288,
283,
344,
356,
27207,
12,
288,
283,
4989,
63,
1023,
356,
283,
19,
14,
18,
13,
88,
1184,
63,
772,
297,
288,
283,
1302,
356,
283,
38,
379,
11131,
5557,
5049,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
772,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
959,
9014,
3328,
12,
288,
283,
344,
356,
28416,
12,
288,
283,
4989,
63,
1023,
356,
283,
19,
14,
18,
13,
73,
8040,
297,
288,
283,
1302,
356,
283,
4299,
51,
4701,
3144,
14,
18,
4337,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
708,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
959,
9014,
2635,
12,
288,
283,
344,
356,
25956,
12,
288,
283,
4989,
63,
1023,
356,
283,
19,
14,
18,
13,
88,
1184,
63,
772,
297,
288,
283,
1302,
356,
283,
4299,
51,
4701,
3144,
14,
18,
5049,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
772,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
1520,
1479,
8731,
12,
288,
283,
344,
356,
28528,
12,
288,
283,
4989,
63,
1023,
356,
283,
18,
14,
22,
14,
708,
297,
288,
283,
1302,
356,
283,
22744,
3100,
959,
4337,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
708,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
1520,
1479,
10932,
12,
288,
283,
344,
356,
14711,
12,
288,
283,
4989,
63,
1023,
356,
283,
18,
14,
22,
14,
708,
13,
88,
1184,
63,
772,
297,
288,
283,
1302,
356,
283,
22744,
3100,
959,
5049,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
772,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
1520,
1479,
9687,
12,
288,
283,
344,
356,
413,
2869,
12,
288,
283,
4989,
63,
1023,
356,
283,
19,
14,
18,
13,
73,
8040,
297,
288,
283,
1302,
356,
283,
8438,
14091,
4337,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
708,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
2502,
63,
344,
356,
5504,
1299,
2260,
12,
288,
283,
17770,
63,
344,
356,
650,
12,
288,
283,
602,
63,
3966,
356,
13686,
360,
1797,
10556,
996,
52,
1046,
26,
966,
26,
1085,
659,
288,
283,
602,
63,
5334,
356,
13686,
360,
1797,
10556,
1644,
52,
713,
26,
1079,
26,
1216,
659,
288,
283,
4032,
63,
344,
356,
1520,
1479,
10034,
12,
288,
283,
344,
356,
413,
2528,
12,
288,
283,
4989,
63,
1023,
356,
283,
19,
14,
18,
13,
88,
1184,
63,
772,
297,
288,
283,
1302,
356,
283,
8438,
14091,
5049,
5821,
297,
288,
283,
736,
63,
1047,
356,
283,
88,
1184,
13,
772,
297,
288,
283,
890,
356,
650,
20281,
12,
288,
283,
11269,
356,
283,
452,
2267,
1779,
791,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
blaercom/django-guardian
|
guardian/templatetags/guardian_tags.py
|
10
|
2739
|
"""
``django-guardian`` template tags. To use in a template just put the following
*load* tag inside a template::
{% load guardian_tags %}
"""
from django import template
from guardian.exceptions import NotUserNorGroup
from guardian.core import ObjectPermissionChecker
from guardian.models import User, Group, AnonymousUser
register = template.Library()
class ObjectPermissionsNode(template.Node):
def __init__(self, for_whom, obj, context_var):
self.for_whom = template.Variable(for_whom)
self.obj = template.Variable(obj)
self.context_var = context_var
def render(self, context):
for_whom = self.for_whom.resolve(context)
if isinstance(for_whom, User):
self.user = for_whom
self.group = None
elif isinstance(for_whom, AnonymousUser):
self.user = User.get_anonymous()
self.group = None
elif isinstance(for_whom, Group):
self.user = None
self.group = for_whom
else:
raise NotUserNorGroup("User or Group instance required (got %s)"
% for_whom.__class__)
obj = self.obj.resolve(context)
check = ObjectPermissionChecker(for_whom)
perms = check.get_perms(obj)
context[self.context_var] = perms
return ''
@register.tag
def get_obj_perms(parser, token):
"""
Returns a list of permissions (as ``codename`` strings) for a given
``user``/``group`` and ``obj`` (Model instance).
Parses ``get_obj_perms`` tag which should be in format::
{% get_obj_perms user/group for obj as "context_var" %}
Example of usage (assuming ``flatpage`` and ``perm`` objects are
available from *context*)::
{% get_obj_perms request.user for flatpage as "flatpage_perms" %}
{% if "delete_flatpage" in flatpage_perms %}
<a href="/pages/delete?target={{ flatpage.url }}">Remove page</a>
{% endif %}
.. note::
Please remember that superusers would always get full list of permissions
for a given object.
"""
bits = token.split_contents()
format = '{% get_obj_perms user/group for obj as "context_var" %}'
if len(bits) != 6 or bits[2] != 'for' or bits[4] != 'as':
raise template.TemplateSyntaxError("get_obj_perms tag should be in "
"format: %s" % format)
for_whom = bits[1]
obj = bits[3]
context_var = bits[5]
if context_var[0] != context_var[-1] or context_var[0] not in ('"', "'"):
raise template.TemplateSyntaxError("get_obj_perms tag's context_var "
"argument should be in quotes")
context_var = context_var[1:-1]
return ObjectPermissionsNode(for_whom, obj, context_var)
|
bsd-2-clause
|
[
624,
199,
1040,
1176,
13,
6051,
31186,
1040,
1978,
3762,
14,
4005,
675,
315,
282,
1978,
2951,
5324,
314,
2569,
199,
10,
912,
10,
1947,
6272,
282,
1978,
447,
339,
7749,
2248,
8129,
31186,
63,
2969,
3674,
199,
199,
624,
199,
504,
1639,
492,
1978,
199,
199,
504,
8129,
31186,
14,
3924,
492,
2832,
1899,
23008,
2448,
199,
504,
8129,
31186,
14,
1018,
492,
6935,
7980,
3048,
199,
504,
8129,
31186,
14,
992,
492,
2876,
12,
5611,
12,
29952,
199,
199,
2683,
275,
1978,
14,
7424,
342,
199,
199,
533,
6935,
17004,
1716,
8,
1160,
14,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
367,
63,
11345,
77,
12,
1559,
12,
1067,
63,
1391,
304,
267,
291,
14,
509,
63,
11345,
77,
275,
1978,
14,
2773,
8,
509,
63,
11345,
77,
9,
267,
291,
14,
1113,
275,
1978,
14,
2773,
8,
1113,
9,
267,
291,
14,
1100,
63,
1391,
275,
1067,
63,
1391,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
367,
63,
11345,
77,
275,
291,
14,
509,
63,
11345,
77,
14,
6983,
8,
1100,
9,
267,
340,
1228,
8,
509,
63,
11345,
77,
12,
2876,
304,
288,
291,
14,
751,
275,
367,
63,
11345,
77,
288,
291,
14,
923,
275,
488,
267,
916,
1228,
8,
509,
63,
11345,
77,
12,
29952,
304,
288,
291,
14,
751,
275,
2876,
14,
362,
63,
12628,
342,
288,
291,
14,
923,
275,
488,
267,
916,
1228,
8,
509,
63,
11345,
77,
12,
5611,
304,
288,
291,
14,
751,
275,
488,
288,
291,
14,
923,
275,
367,
63,
11345,
77,
267,
587,
26,
288,
746,
2832,
1899,
23008,
2448,
480,
1899,
503,
5611,
1256,
1415,
334,
7808,
450,
83,
2924,
355,
450,
367,
63,
11345,
77,
855,
533,
3368,
267,
1559,
275,
291,
14,
1113,
14,
6983,
8,
1100,
9,
398,
1104,
275,
6935,
7980,
3048,
8,
509,
63,
11345,
77,
9,
267,
17340,
275,
1104,
14,
362,
63,
12068,
8,
1113,
9,
398,
1067,
59,
277,
14,
1100,
63,
1391,
61,
275,
17340,
267,
372,
2125,
199,
199,
32,
2683,
14,
1450,
199,
318,
664,
63,
1113,
63,
12068,
8,
2087,
12,
1526,
304,
272,
408,
272,
1803,
282,
769,
402,
3443,
334,
305,
1124,
11879,
1040,
3326,
9,
367,
282,
1627,
272,
1124,
751,
1040,
15,
1040,
923,
1040,
436,
1124,
1113,
1040,
334,
1685,
1256,
680,
339,
29968,
1124,
362,
63,
1113,
63,
12068,
1040,
1947,
1314,
1077,
506,
315,
1475,
447,
398,
7749,
664,
63,
1113,
63,
12068,
922,
15,
923,
367,
1559,
465,
298,
1100,
63,
1391,
2,
3674,
339,
5679,
402,
4503,
334,
405,
12848,
1124,
26587,
1040,
436,
1124,
8220,
1040,
2251,
787,
272,
2808,
687,
627,
1100,
10,
304,
26,
398,
7749,
664,
63,
1113,
63,
12068,
1056,
14,
751,
367,
6829,
1606,
465,
298,
26587,
63,
12068,
2,
3674,
398,
7749,
340,
298,
1807,
63,
26587,
2,
315,
6829,
1606,
63,
12068,
3674,
288,
665,
65,
4369,
9555,
5856,
15,
1807,
31,
1375,
3126,
91,
6829,
1606,
14,
633,
3586,
1743,
5587,
2034,
1108,
65,
30,
267,
7749,
14454,
3674,
339,
2508,
5317,
447,
2126,
7754,
21027,
626,
1613,
3707,
3955,
3544,
664,
2615,
769,
402,
3443,
2126,
367,
282,
1627,
909,
14,
339,
408,
272,
5821,
275,
1526,
14,
1294,
63,
4407,
342,
272,
1475,
275,
12100,
664,
63,
1113,
63,
12068,
922,
15,
923,
367,
1559,
465,
298,
1100,
63,
1391,
2,
25509,
272,
340,
822,
8,
5609,
9,
1137,
1227,
503,
5821,
59,
18,
61,
1137,
283,
509,
7,
503,
5821,
59,
20,
61,
1137,
283,
305,
356,
267,
746,
1978,
14,
20837,
480,
362,
63,
1113,
63,
12068,
1947,
1077,
506,
315,
298,
288,
298,
908,
26,
450,
83,
2,
450,
1475,
9,
339,
367,
63,
11345,
77,
275,
5821,
59,
17,
61,
272,
1559,
275,
5821,
59,
19,
61,
272,
1067,
63,
1391,
275,
5821,
59,
21,
61,
272,
340,
1067,
63,
1391,
59,
16,
61,
1137,
1067,
63,
1391,
1988,
17,
61,
503,
1067,
63,
1391,
59,
16,
61,
440,
315,
661,
6949,
3546,
2349,
267,
746,
1978,
14,
20837,
480,
362,
63,
1113,
63,
12068,
1947,
1159,
1067,
63,
1391,
298,
288,
298,
2094,
1077,
506,
315,
9344,
531,
272,
1067,
63,
1391,
275,
1067,
63,
1391,
59,
17,
6809,
17,
61,
272,
372,
6935,
17004,
1716,
8,
509,
63,
11345,
77,
12,
1559,
12,
1067,
63,
1391,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
1040,
1176,
13,
6051,
31186,
1040,
1978,
3762,
14,
4005,
675,
315,
282,
1978,
2951,
5324,
314,
2569,
199,
10,
912,
10,
1947,
6272,
282,
1978,
447,
339,
7749,
2248,
8129,
31186,
63,
2969,
3674,
199,
199,
624,
199,
504,
1639,
492,
1978,
199,
199,
504,
8129,
31186,
14,
3924,
492,
2832,
1899,
23008,
2448,
199,
504,
8129,
31186,
14,
1018,
492,
6935,
7980,
3048,
199,
504,
8129,
31186,
14,
992,
492,
2876,
12,
5611,
12,
29952,
199,
199,
2683,
275,
1978,
14,
7424,
342,
199,
199,
533,
6935,
17004,
1716,
8,
1160,
14,
1716,
304,
272,
347,
636,
826,
721,
277,
12,
367,
63,
11345,
77,
12,
1559,
12,
1067,
63,
1391,
304,
267,
291,
14,
509,
63,
11345,
77,
275,
1978,
14,
2773,
8,
509,
63,
11345,
77,
9,
267,
291,
14,
1113,
275,
1978,
14,
2773,
8,
1113,
9,
267,
291,
14,
1100,
63,
1391,
275,
1067,
63,
1391,
339,
347,
3795,
8,
277,
12,
1067,
304,
267,
367,
63,
11345,
77,
275,
291,
14,
509,
63,
11345,
77,
14,
6983,
8,
1100,
9,
267,
340,
1228,
8,
509,
63,
11345,
77,
12,
2876,
304,
288,
291,
14,
751,
275,
367,
63,
11345,
77,
288,
291,
14,
923,
275,
488,
267,
916,
1228,
8,
509,
63,
11345,
77,
12,
29952,
304,
288,
291,
14,
751,
275,
2876,
14,
362,
63,
12628,
342,
288,
291,
14,
923,
275,
488,
267,
916,
1228,
8,
509,
63,
11345,
77,
12,
5611,
304,
288,
291,
14,
751,
275,
488,
288,
291,
14,
923,
275,
367,
63,
11345,
77,
267,
587,
26,
288,
746,
2832,
1899,
23008,
2448,
480,
1899,
503,
5611,
1256,
1415,
334,
7808,
450,
83,
2924,
355,
450,
367,
63,
11345,
77,
855,
533,
3368,
267,
1559,
275,
291,
14,
1113,
14,
6983,
8,
1100,
9,
398,
1104,
275,
6935,
7980,
3048,
8,
509,
63,
11345,
77,
9,
267,
17340,
275,
1104,
14,
362,
63,
12068,
8,
1113,
9,
398,
1067,
59,
277,
14,
1100,
63,
1391,
61,
275,
17340,
267,
372,
2125,
199,
199,
32,
2683,
14,
1450,
199,
318,
664,
63,
1113,
63,
12068,
8,
2087,
12,
1526,
304,
272,
408,
272,
1803,
282,
769,
402,
3443,
334,
305,
1124,
11879,
1040,
3326,
9,
367,
282,
1627,
272,
1124,
751,
1040,
15,
1040,
923,
1040,
436,
1124,
1113,
1040,
334,
1685,
1256,
680,
339,
29968,
1124,
362,
63,
1113,
63,
12068,
1040,
1947,
1314,
1077,
506,
315,
1475,
447,
398,
7749,
664,
63,
1113,
63,
12068,
922,
15,
923,
367,
1559,
465,
298,
1100,
63,
1391,
2,
3674,
339,
5679,
402,
4503,
334,
405,
12848,
1124,
26587,
1040,
436,
1124,
8220,
1040,
2251,
787,
272,
2808,
687,
627,
1100,
10,
304,
26,
398,
7749,
664,
63,
1113,
63,
12068,
1056,
14,
751,
367,
6829,
1606,
465,
298,
26587,
63,
12068,
2,
3674,
398,
7749,
340,
298,
1807,
63,
26587,
2,
315,
6829,
1606,
63,
12068,
3674,
288,
665,
65,
4369,
9555,
5856,
15,
1807,
31,
1375,
3126,
91,
6829,
1606,
14,
633,
3586,
1743,
5587,
2034,
1108,
65,
30,
267,
7749,
14454,
3674,
339,
2508,
5317,
447,
2126,
7754,
21027,
626,
1613,
3707,
3955,
3544,
664,
2615,
769,
402,
3443,
2126,
367,
282,
1627,
909,
14,
339,
408,
272,
5821,
275,
1526,
14,
1294,
63,
4407,
342,
272,
1475,
275,
12100,
664,
63,
1113,
63,
12068,
922,
15,
923,
367,
1559,
465,
298,
1100,
63,
1391,
2,
25509,
272,
340,
822,
8,
5609,
9,
1137,
1227,
503,
5821,
59,
18,
61,
1137,
283,
509,
7,
503,
5821,
59,
20,
61,
1137,
283,
305,
356,
267,
746,
1978,
14,
20837,
480,
362,
63,
1113,
63,
12068,
1947,
1077,
506,
315,
298,
288,
298,
908,
26,
450,
83,
2,
450,
1475,
9,
339,
367,
63,
11345,
77,
275,
5821,
59,
17,
61,
272,
1559,
275,
5821,
59,
19,
61,
272,
1067,
63,
1391,
275,
5821,
59,
21,
61,
272,
340,
1067,
63,
1391,
59,
16,
61,
1137,
1067,
63,
1391,
1988,
17,
61,
503,
1067,
63,
1391,
59,
16,
61,
440,
315,
661,
6949,
3546,
2349,
267,
746,
1978,
14,
20837,
480,
362,
63,
1113,
63,
12068,
1947,
1159,
1067,
63,
1391,
298,
288,
298,
2094,
1077,
506,
315,
9344,
531,
272,
1067,
63,
1391,
275,
1067,
63,
1391,
59,
17,
6809,
17,
61,
272,
372,
6935,
17004,
1716,
8,
509,
63,
11345,
77,
12,
1559,
12,
1067,
63,
1391,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dqnykamp/sympy
|
sympy/polys/agca/tests/test_modules.py
|
121
|
13526
|
"""Test modules.py code."""
from sympy.polys.agca.modules import FreeModule, ModuleOrder, FreeModulePolyRing
from sympy.polys import CoercionFailed, QQ, lex, grlex, ilex, ZZ
from sympy.abc import x, y, z
from sympy.utilities.pytest import raises
from sympy import S
def test_FreeModuleElement():
M = QQ.old_poly_ring(x).free_module(3)
e = M.convert([1, x, x**2])
f = [QQ.old_poly_ring(x).convert(1), QQ.old_poly_ring(x).convert(x), QQ.old_poly_ring(x).convert(x**2)]
assert list(e) == f
assert f[0] == e[0]
assert f[1] == e[1]
assert f[2] == e[2]
raises(IndexError, lambda: e[3])
g = M.convert([x, 0, 0])
assert e + g == M.convert([x + 1, x, x**2])
assert f + g == M.convert([x + 1, x, x**2])
assert -e == M.convert([-1, -x, -x**2])
assert e - g == M.convert([1 - x, x, x**2])
assert e != g
assert M.convert([x, x, x]) / QQ.old_poly_ring(x).convert(x) == [1, 1, 1]
R = QQ.old_poly_ring(x, order="ilex")
assert R.free_module(1).convert([x]) / R.convert(x) == [1]
def test_FreeModule():
M1 = FreeModule(QQ.old_poly_ring(x), 2)
assert M1 == FreeModule(QQ.old_poly_ring(x), 2)
assert M1 != FreeModule(QQ.old_poly_ring(y), 2)
assert M1 != FreeModule(QQ.old_poly_ring(x), 3)
M2 = FreeModule(QQ.old_poly_ring(x, order="ilex"), 2)
assert [x, 1] in M1
assert [x] not in M1
assert [2, y] not in M1
assert [1/(x + 1), 2] not in M1
e = M1.convert([x, x**2 + 1])
X = QQ.old_poly_ring(x).convert(x)
assert e == [X, X**2 + 1]
assert e == [x, x**2 + 1]
assert 2*e == [2*x, 2*x**2 + 2]
assert e*2 == [2*x, 2*x**2 + 2]
assert e/2 == [x/2, (x**2 + 1)/2]
assert x*e == [x**2, x**3 + x]
assert e*x == [x**2, x**3 + x]
assert X*e == [x**2, x**3 + x]
assert e*X == [x**2, x**3 + x]
assert [x, 1] in M2
assert [x] not in M2
assert [2, y] not in M2
assert [1/(x + 1), 2] in M2
e = M2.convert([x, x**2 + 1])
X = QQ.old_poly_ring(x, order="ilex").convert(x)
assert e == [X, X**2 + 1]
assert e == [x, x**2 + 1]
assert 2*e == [2*x, 2*x**2 + 2]
assert e*2 == [2*x, 2*x**2 + 2]
assert e/2 == [x/2, (x**2 + 1)/2]
assert x*e == [x**2, x**3 + x]
assert e*x == [x**2, x**3 + x]
assert e/(1 + x) == [x/(1 + x), (x**2 + 1)/(1 + x)]
assert X*e == [x**2, x**3 + x]
assert e*X == [x**2, x**3 + x]
M3 = FreeModule(QQ.old_poly_ring(x, y), 2)
assert M3.convert(e) == M3.convert([x, x**2 + 1])
assert not M3.is_submodule(0)
assert not M3.is_zero()
raises(NotImplementedError, lambda: ZZ.old_poly_ring(x).free_module(2))
raises(NotImplementedError, lambda: FreeModulePolyRing(ZZ, 2))
raises(CoercionFailed, lambda: M1.convert(QQ.old_poly_ring(x).free_module(3)
.convert([1, 2, 3])))
raises(CoercionFailed, lambda: M3.convert(1))
def test_ModuleOrder():
o1 = ModuleOrder(lex, grlex, False)
o2 = ModuleOrder(ilex, lex, False)
assert o1 == ModuleOrder(lex, grlex, False)
assert (o1 != ModuleOrder(lex, grlex, False)) is False
assert o1 != o2
assert o1((1, 2, 3)) == (1, (5, (2, 3)))
assert o2((1, 2, 3)) == (-1, (2, 3))
def test_SubModulePolyRing_global():
R = QQ.old_poly_ring(x, y)
F = R.free_module(3)
Fd = F.submodule([1, 0, 0], [1, 2, 0], [1, 2, 3])
M = F.submodule([x**2 + y**2, 1, 0], [x, y, 1])
assert F == Fd
assert Fd == F
assert F != M
assert M != F
assert Fd != M
assert M != Fd
assert Fd == F.submodule(*F.basis())
assert Fd.is_full_module()
assert not M.is_full_module()
assert not Fd.is_zero()
assert not M.is_zero()
assert Fd.submodule().is_zero()
assert M.contains([x**2 + y**2 + x, 1 + y, 1])
assert not M.contains([x**2 + y**2 + x, 1 + y, 2])
assert M.contains([y**2, 1 - x*y, -x])
assert not F.submodule([1 + x, 0, 0]) == F.submodule([1, 0, 0])
assert F.submodule([1, 0, 0], [0, 1, 0]).union(F.submodule([0, 0, 1])) == F
assert not M.is_submodule(0)
m = F.convert([x**2 + y**2, 1, 0])
n = M.convert(m)
assert m.module is F
assert n.module is M
raises(ValueError, lambda: M.submodule([1, 0, 0]))
raises(TypeError, lambda: M.union(1))
raises(ValueError, lambda: M.union(R.free_module(1).submodule([x])))
assert F.submodule([x, x, x]) != F.submodule([x, x, x], order="ilex")
def test_SubModulePolyRing_local():
R = QQ.old_poly_ring(x, y, order=ilex)
F = R.free_module(3)
Fd = F.submodule([1 + x, 0, 0], [1 + y, 2 + 2*y, 0], [1, 2, 3])
M = F.submodule([x**2 + y**2, 1, 0], [x, y, 1])
assert F == Fd
assert Fd == F
assert F != M
assert M != F
assert Fd != M
assert M != Fd
assert Fd == F.submodule(*F.basis())
assert Fd.is_full_module()
assert not M.is_full_module()
assert not Fd.is_zero()
assert not M.is_zero()
assert Fd.submodule().is_zero()
assert M.contains([x**2 + y**2 + x, 1 + y, 1])
assert not M.contains([x**2 + y**2 + x, 1 + y, 2])
assert M.contains([y**2, 1 - x*y, -x])
assert F.submodule([1 + x, 0, 0]) == F.submodule([1, 0, 0])
assert F.submodule(
[1, 0, 0], [0, 1, 0]).union(F.submodule([0, 0, 1 + x*y])) == F
raises(ValueError, lambda: M.submodule([1, 0, 0]))
def test_SubModulePolyRing_nontriv_global():
R = QQ.old_poly_ring(x, y, z)
F = R.free_module(1)
def contains(I, f):
return F.submodule(*[[g] for g in I]).contains([f])
assert contains([x, y], x)
assert contains([x, y], x + y)
assert not contains([x, y], 1)
assert not contains([x, y], z)
assert contains([x**2 + y, x**2 + x], x - y)
assert not contains([x + y + z, x*y + x*z + y*z, x*y*z], x**2)
assert contains([x + y + z, x*y + x*z + y*z, x*y*z], x**3)
assert contains([x + y + z, x*y + x*z + y*z, x*y*z], x**4)
assert not contains([x + y + z, x*y + x*z + y*z, x*y*z], x*y**2)
assert contains([x + y + z, x*y + x*z + y*z, x*y*z], x**4 + y**3 + 2*z*y*x)
assert contains([x + y + z, x*y + x*z + y*z, x*y*z], x*y*z)
assert contains([x, 1 + x + y, 5 - 7*y], 1)
assert contains(
[x**3 + y**3, y**3 + z**3, z**3 + x**3, x**2*y + x**2*z + y**2*z],
x**3)
assert not contains(
[x**3 + y**3, y**3 + z**3, z**3 + x**3, x**2*y + x**2*z + y**2*z],
x**2 + y**2)
# compare local order
assert not contains([x*(1 + x + y), y*(1 + z)], x)
assert not contains([x*(1 + x + y), y*(1 + z)], x + y)
def test_SubModulePolyRing_nontriv_local():
R = QQ.old_poly_ring(x, y, z, order=ilex)
F = R.free_module(1)
def contains(I, f):
return F.submodule(*[[g] for g in I]).contains([f])
assert contains([x, y], x)
assert contains([x, y], x + y)
assert not contains([x, y], 1)
assert not contains([x, y], z)
assert contains([x**2 + y, x**2 + x], x - y)
assert not contains([x + y + z, x*y + x*z + y*z, x*y*z], x**2)
assert contains([x*(1 + x + y), y*(1 + z)], x)
assert contains([x*(1 + x + y), y*(1 + z)], x + y)
def test_syzygy():
R = QQ.old_poly_ring(x, y, z)
M = R.free_module(1).submodule([x*y], [y*z], [x*z])
S = R.free_module(3).submodule([0, x, -y], [z, -x, 0])
assert M.syzygy_module() == S
M2 = M / ([x*y*z],)
S2 = R.free_module(3).submodule([z, 0, 0], [0, x, 0], [0, 0, y])
assert M2.syzygy_module() == S2
F = R.free_module(3)
assert F.submodule(*F.basis()).syzygy_module() == F.submodule()
R2 = QQ.old_poly_ring(x, y, z) / [x*y*z]
M3 = R2.free_module(1).submodule([x*y], [y*z], [x*z])
S3 = R2.free_module(3).submodule([z, 0, 0], [0, x, 0], [0, 0, y])
assert M3.syzygy_module() == S3
def test_in_terms_of_generators():
R = QQ.old_poly_ring(x, order="ilex")
M = R.free_module(2).submodule([2*x, 0], [1, 2])
assert M.in_terms_of_generators(
[x, x]) == [R.convert(S(1)/4), R.convert(x/2)]
raises(ValueError, lambda: M.in_terms_of_generators([1, 0]))
M = R.free_module(2) / ([x, 0], [1, 1])
SM = M.submodule([1, x])
assert SM.in_terms_of_generators([2, 0]) == [R.convert(-2/(x - 1))]
R = QQ.old_poly_ring(x, y) / [x**2 - y**2]
M = R.free_module(2)
SM = M.submodule([x, 0], [0, y])
assert SM.in_terms_of_generators(
[x**2, x**2]) == [R.convert(x), R.convert(y)]
def test_QuotientModuleElement():
R = QQ.old_poly_ring(x)
F = R.free_module(3)
N = F.submodule([1, x, x**2])
M = F/N
e = M.convert([x**2, 2, 0])
assert M.convert([x + 1, x**2 + x, x**3 + x**2]) == 0
assert e == [x**2, 2, 0] + N == F.convert([x**2, 2, 0]) + N == \
M.convert(F.convert([x**2, 2, 0]))
assert M.convert([x**2 + 1, 2*x + 2, x**2]) == e + [0, x, 0] == \
e + M.convert([0, x, 0]) == e + F.convert([0, x, 0])
assert M.convert([x**2 + 1, 2, x**2]) == e - [0, x, 0] == \
e - M.convert([0, x, 0]) == e - F.convert([0, x, 0])
assert M.convert([0, 2, 0]) == M.convert([x**2, 4, 0]) - e == \
[x**2, 4, 0] - e == F.convert([x**2, 4, 0]) - e
assert M.convert([x**3 + x**2, 2*x + 2, 0]) == (1 + x)*e == \
R.convert(1 + x)*e == e*(1 + x) == e*R.convert(1 + x)
assert -e == [-x**2, -2, 0]
f = [x, x, 0] + N
assert M.convert([1, 1, 0]) == f / x == f / R.convert(x)
M2 = F/[(2, 2*x, 2*x**2), (0, 0, 1)]
G = R.free_module(2)
M3 = G/[[1, x]]
M4 = F.submodule([1, x, x**2], [1, 0, 0]) / N
raises(CoercionFailed, lambda: M.convert(G.convert([1, x])))
raises(CoercionFailed, lambda: M.convert(M3.convert([1, x])))
raises(CoercionFailed, lambda: M.convert(M2.convert([1, x, x])))
assert M2.convert(M.convert([2, x, x**2])) == [2, x, 0]
assert M.convert(M4.convert([2, 0, 0])) == [2, 0, 0]
def test_QuotientModule():
R = QQ.old_poly_ring(x)
F = R.free_module(3)
N = F.submodule([1, x, x**2])
M = F/N
assert M != F
assert M != N
assert M == F / [(1, x, x**2)]
assert not M.is_zero()
assert (F / F.basis()).is_zero()
SQ = F.submodule([1, x, x**2], [2, 0, 0]) / N
assert SQ == M.submodule([2, x, x**2])
assert SQ != M.submodule([2, 1, 0])
assert SQ != M
assert M.is_submodule(SQ)
assert not SQ.is_full_module()
raises(ValueError, lambda: N/F)
raises(ValueError, lambda: F.submodule([2, 0, 0]) / N)
raises(ValueError, lambda: R.free_module(2)/F)
raises(CoercionFailed, lambda: F.convert(M.convert([1, x, x**2])))
M1 = F / [[1, 1, 1]]
M2 = M1.submodule([1, 0, 0], [0, 1, 0])
assert M1 == M2
def test_ModulesQuotientRing():
R = QQ.old_poly_ring(x, y, order=(("lex", x), ("ilex", y))) / [x**2 + 1]
M1 = R.free_module(2)
assert M1 == R.free_module(2)
assert M1 != QQ.old_poly_ring(x).free_module(2)
assert M1 != R.free_module(3)
assert [x, 1] in M1
assert [x] not in M1
assert [1/(R.convert(x) + 1), 2] in M1
assert [1, 2/(1 + y)] in M1
assert [1, 2/y] not in M1
assert M1.convert([x**2, y]) == [-1, y]
F = R.free_module(3)
Fd = F.submodule([x**2, 0, 0], [1, 2, 0], [1, 2, 3])
M = F.submodule([x**2 + y**2, 1, 0], [x, y, 1])
assert F == Fd
assert Fd == F
assert F != M
assert M != F
assert Fd != M
assert M != Fd
assert Fd == F.submodule(*F.basis())
assert Fd.is_full_module()
assert not M.is_full_module()
assert not Fd.is_zero()
assert not M.is_zero()
assert Fd.submodule().is_zero()
assert M.contains([x**2 + y**2 + x, -x**2 + y, 1])
assert not M.contains([x**2 + y**2 + x, 1 + y, 2])
assert M.contains([y**2, 1 - x*y, -x])
assert F.submodule([x, 0, 0]) == F.submodule([1, 0, 0])
assert not F.submodule([y, 0, 0]) == F.submodule([1, 0, 0])
assert F.submodule([1, 0, 0], [0, 1, 0]).union(F.submodule([0, 0, 1])) == F
assert not M.is_submodule(0)
def test_module_mul():
R = QQ.old_poly_ring(x)
M = R.free_module(2)
S1 = M.submodule([x, 0], [0, x])
S2 = M.submodule([x**2, 0], [0, x**2])
I = R.ideal(x)
assert I*M == M*I == S1 == x*M == M*x
assert I*S1 == S2 == x*S1
def test_intersection():
# SCA, example 2.8.5
F = QQ.old_poly_ring(x, y).free_module(2)
M1 = F.submodule([x, y], [y, 1])
M2 = F.submodule([0, y - 1], [x, 1], [y, x])
I = F.submodule([x, y], [y**2 - y, y - 1], [x*y + y, x + 1])
I1, rel1, rel2 = M1.intersect(M2, relations=True)
assert I1 == M2.intersect(M1) == I
for i, g in enumerate(I1.gens):
assert g == sum(c*x for c, x in zip(rel1[i], M1.gens)) \
== sum(d*y for d, y in zip(rel2[i], M2.gens))
assert F.submodule([x, y]).intersect(F.submodule([y, x])).is_zero()
def test_quotient():
# SCA, example 2.8.6
R = QQ.old_poly_ring(x, y, z)
F = R.free_module(2)
assert F.submodule([x*y, x*z], [y*z, x*y]).module_quotient(
F.submodule([y, z], [z, y])) == QQ.old_poly_ring(x, y, z).ideal(x**2*y**2 - x*y*z**2)
assert F.submodule([x, y]).module_quotient(F.submodule()).is_whole_ring()
M = F.submodule([x**2, x**2], [y**2, y**2])
N = F.submodule([x + y, x + y])
q, rel = M.module_quotient(N, relations=True)
assert q == R.ideal(y**2, x - y)
for i, g in enumerate(q.gens):
assert g*N.gens[0] == sum(c*x for c, x in zip(rel[i], M.gens))
def test_groebner_extendend():
M = QQ.old_poly_ring(x, y, z).free_module(3).submodule([x + 1, y, 1], [x*y, z, z**2])
G, R = M._groebner_vec(extended=True)
for i, g in enumerate(G):
assert g == sum(c*gen for c, gen in zip(R[i], M.gens))
|
bsd-3-clause
|
[
624,
774,
4621,
14,
647,
1233,
1041,
199,
199,
504,
5840,
14,
15743,
14,
643,
696,
14,
3112,
492,
2868,
2377,
12,
5673,
4738,
12,
2868,
2377,
12747,
15420,
199,
504,
5840,
14,
15743,
492,
1849,
281,
9718,
4276,
12,
16679,
12,
7103,
12,
7192,
3113,
12,
284,
3113,
12,
11739,
199,
504,
5840,
14,
3175,
492,
671,
12,
612,
12,
1315,
199,
504,
5840,
14,
16355,
14,
4462,
492,
6534,
199,
504,
5840,
492,
428,
421,
199,
318,
511,
63,
10146,
2377,
2162,
837,
272,
603,
275,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
680,
4624,
63,
578,
8,
19,
9,
272,
325,
275,
603,
14,
3916,
779,
17,
12,
671,
12,
671,
538,
18,
566,
272,
289,
275,
359,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
88,
680,
3916,
8,
17,
395,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
680,
3916,
8,
88,
395,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
680,
3916,
8,
88,
538,
18,
1874,
272,
702,
769,
8,
69,
9,
508,
289,
272,
702,
289,
59,
16,
61,
508,
325,
59,
16,
61,
272,
702,
289,
59,
17,
61,
508,
325,
59,
17,
61,
272,
702,
289,
59,
18,
61,
508,
325,
59,
18,
61,
272,
6534,
8,
12129,
12,
2400,
26,
325,
59,
19,
566,
339,
486,
275,
603,
14,
3916,
779,
88,
12,
378,
12,
378,
566,
272,
702,
325,
435,
486,
508,
603,
14,
3916,
779,
88,
435,
413,
12,
671,
12,
671,
538,
18,
566,
272,
702,
289,
435,
486,
508,
603,
14,
3916,
779,
88,
435,
413,
12,
671,
12,
671,
538,
18,
566,
272,
702,
446,
69,
508,
603,
14,
3916,
11468,
17,
12,
446,
88,
12,
446,
88,
538,
18,
566,
272,
702,
325,
446,
486,
508,
603,
14,
3916,
779,
17,
446,
671,
12,
671,
12,
671,
538,
18,
566,
272,
702,
325,
1137,
486,
339,
702,
603,
14,
3916,
779,
88,
12,
671,
12,
671,
566,
1182,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
680,
3916,
8,
88,
9,
508,
359,
17,
12,
413,
12,
413,
61,
272,
820,
275,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
12,
1865,
628,
441,
88,
531,
272,
702,
820,
14,
4624,
63,
578,
8,
17,
680,
3916,
779,
88,
566,
1182,
820,
14,
3916,
8,
88,
9,
508,
359,
17,
61,
421,
199,
318,
511,
63,
10146,
2377,
837,
272,
603,
17,
275,
2868,
2377,
8,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
88,
395,
499,
9,
272,
702,
603,
17,
508,
2868,
2377,
8,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
88,
395,
499,
9,
272,
702,
603,
17,
1137,
2868,
2377,
8,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
89,
395,
499,
9,
272,
702,
603,
17,
1137,
2868,
2377,
8,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
88,
395,
650,
9,
272,
603,
18,
275,
2868,
2377,
8,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
88,
12,
1865,
628,
441,
88,
1288,
499,
9,
339,
702,
359,
88,
12,
413,
61,
315,
603,
17,
272,
702,
359,
88,
61,
440,
315,
603,
17,
272,
702,
359,
18,
12,
612,
61,
440,
315,
603,
17,
272,
702,
359,
17,
7985,
88,
435,
413,
395,
499,
61,
440,
315,
603,
17,
339,
325,
275,
603,
17,
14,
3916,
779,
88,
12,
671,
538,
18,
435,
413,
566,
272,
1323,
275,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
680,
3916,
8,
88,
9,
272,
702,
325,
508,
359,
56,
12,
1323,
538,
18,
435,
413,
61,
272,
702,
325,
508,
359,
88,
12,
671,
538,
18,
435,
413,
61,
272,
702,
499,
10,
69,
508,
359,
18,
10,
88,
12,
499,
10,
88,
538,
18,
435,
499,
61,
272,
702,
325,
10,
18,
508,
359,
18,
10,
88,
12,
499,
10,
88,
538,
18,
435,
499,
61,
272,
702,
325,
15,
18,
508,
359,
88,
15,
18,
12,
334,
88,
538,
18,
435,
413,
2447,
18,
61,
272,
702,
671,
10,
69,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
272,
702,
325,
10,
88,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
272,
702,
1323,
10,
69,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
272,
702,
325,
10,
56,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
339,
702,
359,
88,
12,
413,
61,
315,
603,
18,
272,
702,
359,
88,
61,
440,
315,
603,
18,
272,
702,
359,
18,
12,
612,
61,
440,
315,
603,
18,
272,
702,
359,
17,
7985,
88,
435,
413,
395,
499,
61,
315,
603,
18,
339,
325,
275,
603,
18,
14,
3916,
779,
88,
12,
671,
538,
18,
435,
413,
566,
272,
1323,
275,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
12,
1865,
628,
441,
88,
3471,
3916,
8,
88,
9,
272,
702,
325,
508,
359,
56,
12,
1323,
538,
18,
435,
413,
61,
272,
702,
325,
508,
359,
88,
12,
671,
538,
18,
435,
413,
61,
272,
702,
499,
10,
69,
508,
359,
18,
10,
88,
12,
499,
10,
88,
538,
18,
435,
499,
61,
272,
702,
325,
10,
18,
508,
359,
18,
10,
88,
12,
499,
10,
88,
538,
18,
435,
499,
61,
272,
702,
325,
15,
18,
508,
359,
88,
15,
18,
12,
334,
88,
538,
18,
435,
413,
2447,
18,
61,
272,
702,
671,
10,
69,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
272,
702,
325,
10,
88,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
272,
702,
325,
7985,
17,
435,
671,
9,
508,
359,
88,
7985,
17,
435,
671,
395,
334,
88,
538,
18,
435,
413,
15136,
17,
435,
671,
1874,
272,
702,
1323,
10,
69,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
272,
702,
325,
10,
56,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
339,
603,
19,
275,
2868,
2377,
8,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
88,
12,
612,
395,
499,
9,
272,
702,
603,
19,
14,
3916,
8
] |
[
774,
4621,
14,
647,
1233,
1041,
199,
199,
504,
5840,
14,
15743,
14,
643,
696,
14,
3112,
492,
2868,
2377,
12,
5673,
4738,
12,
2868,
2377,
12747,
15420,
199,
504,
5840,
14,
15743,
492,
1849,
281,
9718,
4276,
12,
16679,
12,
7103,
12,
7192,
3113,
12,
284,
3113,
12,
11739,
199,
504,
5840,
14,
3175,
492,
671,
12,
612,
12,
1315,
199,
504,
5840,
14,
16355,
14,
4462,
492,
6534,
199,
504,
5840,
492,
428,
421,
199,
318,
511,
63,
10146,
2377,
2162,
837,
272,
603,
275,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
680,
4624,
63,
578,
8,
19,
9,
272,
325,
275,
603,
14,
3916,
779,
17,
12,
671,
12,
671,
538,
18,
566,
272,
289,
275,
359,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
88,
680,
3916,
8,
17,
395,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
680,
3916,
8,
88,
395,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
680,
3916,
8,
88,
538,
18,
1874,
272,
702,
769,
8,
69,
9,
508,
289,
272,
702,
289,
59,
16,
61,
508,
325,
59,
16,
61,
272,
702,
289,
59,
17,
61,
508,
325,
59,
17,
61,
272,
702,
289,
59,
18,
61,
508,
325,
59,
18,
61,
272,
6534,
8,
12129,
12,
2400,
26,
325,
59,
19,
566,
339,
486,
275,
603,
14,
3916,
779,
88,
12,
378,
12,
378,
566,
272,
702,
325,
435,
486,
508,
603,
14,
3916,
779,
88,
435,
413,
12,
671,
12,
671,
538,
18,
566,
272,
702,
289,
435,
486,
508,
603,
14,
3916,
779,
88,
435,
413,
12,
671,
12,
671,
538,
18,
566,
272,
702,
446,
69,
508,
603,
14,
3916,
11468,
17,
12,
446,
88,
12,
446,
88,
538,
18,
566,
272,
702,
325,
446,
486,
508,
603,
14,
3916,
779,
17,
446,
671,
12,
671,
12,
671,
538,
18,
566,
272,
702,
325,
1137,
486,
339,
702,
603,
14,
3916,
779,
88,
12,
671,
12,
671,
566,
1182,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
680,
3916,
8,
88,
9,
508,
359,
17,
12,
413,
12,
413,
61,
272,
820,
275,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
12,
1865,
628,
441,
88,
531,
272,
702,
820,
14,
4624,
63,
578,
8,
17,
680,
3916,
779,
88,
566,
1182,
820,
14,
3916,
8,
88,
9,
508,
359,
17,
61,
421,
199,
318,
511,
63,
10146,
2377,
837,
272,
603,
17,
275,
2868,
2377,
8,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
88,
395,
499,
9,
272,
702,
603,
17,
508,
2868,
2377,
8,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
88,
395,
499,
9,
272,
702,
603,
17,
1137,
2868,
2377,
8,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
89,
395,
499,
9,
272,
702,
603,
17,
1137,
2868,
2377,
8,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
88,
395,
650,
9,
272,
603,
18,
275,
2868,
2377,
8,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
88,
12,
1865,
628,
441,
88,
1288,
499,
9,
339,
702,
359,
88,
12,
413,
61,
315,
603,
17,
272,
702,
359,
88,
61,
440,
315,
603,
17,
272,
702,
359,
18,
12,
612,
61,
440,
315,
603,
17,
272,
702,
359,
17,
7985,
88,
435,
413,
395,
499,
61,
440,
315,
603,
17,
339,
325,
275,
603,
17,
14,
3916,
779,
88,
12,
671,
538,
18,
435,
413,
566,
272,
1323,
275,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
680,
3916,
8,
88,
9,
272,
702,
325,
508,
359,
56,
12,
1323,
538,
18,
435,
413,
61,
272,
702,
325,
508,
359,
88,
12,
671,
538,
18,
435,
413,
61,
272,
702,
499,
10,
69,
508,
359,
18,
10,
88,
12,
499,
10,
88,
538,
18,
435,
499,
61,
272,
702,
325,
10,
18,
508,
359,
18,
10,
88,
12,
499,
10,
88,
538,
18,
435,
499,
61,
272,
702,
325,
15,
18,
508,
359,
88,
15,
18,
12,
334,
88,
538,
18,
435,
413,
2447,
18,
61,
272,
702,
671,
10,
69,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
272,
702,
325,
10,
88,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
272,
702,
1323,
10,
69,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
272,
702,
325,
10,
56,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
339,
702,
359,
88,
12,
413,
61,
315,
603,
18,
272,
702,
359,
88,
61,
440,
315,
603,
18,
272,
702,
359,
18,
12,
612,
61,
440,
315,
603,
18,
272,
702,
359,
17,
7985,
88,
435,
413,
395,
499,
61,
315,
603,
18,
339,
325,
275,
603,
18,
14,
3916,
779,
88,
12,
671,
538,
18,
435,
413,
566,
272,
1323,
275,
16679,
14,
1753,
63,
6023,
63,
5985,
8,
88,
12,
1865,
628,
441,
88,
3471,
3916,
8,
88,
9,
272,
702,
325,
508,
359,
56,
12,
1323,
538,
18,
435,
413,
61,
272,
702,
325,
508,
359,
88,
12,
671,
538,
18,
435,
413,
61,
272,
702,
499,
10,
69,
508,
359,
18,
10,
88,
12,
499,
10,
88,
538,
18,
435,
499,
61,
272,
702,
325,
10,
18,
508,
359,
18,
10,
88,
12,
499,
10,
88,
538,
18,
435,
499,
61,
272,
702,
325,
15,
18,
508,
359,
88,
15,
18,
12,
334,
88,
538,
18,
435,
413,
2447,
18,
61,
272,
702,
671,
10,
69,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
272,
702,
325,
10,
88,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
272,
702,
325,
7985,
17,
435,
671,
9,
508,
359,
88,
7985,
17,
435,
671,
395,
334,
88,
538,
18,
435,
413,
15136,
17,
435,
671,
1874,
272,
702,
1323,
10,
69,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
272,
702,
325,
10,
56,
508,
359,
88,
538,
18,
12,
671,
538,
19,
435,
671,
61,
339,
603,
19,
275,
2868,
2377,
8,
12917,
14,
1753,
63,
6023,
63,
5985,
8,
88,
12,
612,
395,
499,
9,
272,
702,
603,
19,
14,
3916,
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
] |
mbr0wn/gnuradio
|
grc/converter/cheetah_converter.py
|
5
|
8212
|
# Copyright 2016 Free Software Foundation, Inc.
# This file is part of GNU Radio
#
# SPDX-License-Identifier: GPL-2.0-or-later
#
import collections
import re
import string
delims = {'(': ')', '[': ']', '{': '}', '': ', #\\*:'}
identifier_start = '_' + string.ascii_letters + ''.join(delims.keys())
string_delims = '"\''
cheetah_substitution = re.compile(
r'^\$((?P<d1>\()|(?P<d2>\{)|(?P<d3>\[)|)'
r'(?P<arg>[_a-zA-Z][_a-zA-Z0-9]*(?:\.[_a-zA-Z][_a-zA-Z0-9]*)?)(?P<eval>\(\))?'
r'(?(d1)\)|(?(d2)\}|(?(d3)\]|)))$'
)
cheetah_inline_if = re.compile(r'#if (?P<cond>.*) then (?P<then>.*?) ?else (?P<else>.*?) ?(#|$)')
class Python(object):
start = ''
end = ''
nested_start = ''
nested_end = ''
eval = ''
type = str # yaml_output.Eval
class FormatString(Python):
start = '{'
end = '}'
nested_start = '{'
nested_end = '}'
eval = ':eval'
type = str
class Mako(Python):
start = '${'
end = '}'
nested_start = ''
nested_end = ''
type = str
class Converter(object):
def __init__(self, names):
self.stats = collections.defaultdict(int)
self.names = set(names)
self.extended = set(self._iter_identifiers(names))
@staticmethod
def _iter_identifiers(names):
if not isinstance(names, dict):
names = {name: {} for name in names}
for key, sub_keys in names.items():
yield key
for sub_key in sub_keys:
yield '{}.{}'.format(key, sub_key)
def to_python(self, expr):
return self.convert(expr=expr, spec=Python)
def to_python_dec(self, expr):
converted = self.convert(expr=expr, spec=Python)
if converted and converted != expr:
converted = '${ ' + converted.strip() + ' }'
return converted
def to_format_string(self, expr):
return self.convert(expr=expr, spec=FormatString)
def to_mako(self, expr):
return self.convert(expr=expr, spec=Mako)
def convert(self, expr, spec=Python):
if not expr:
return ''
elif '$' not in expr:
return expr
try:
return self.convert_simple(expr, spec)
except ValueError:
pass
try:
if '#if' in expr and '\n' not in expr:
expr = self.convert_inline_conditional(expr, spec)
return self.convert_hard(expr, spec)
except ValueError:
return 'Cheetah! ' + expr
def convert_simple(self, expr, spec=Python):
match = cheetah_substitution.match(expr)
if not match:
raise ValueError('Not a simple substitution: ' + expr)
identifier = match.group('arg')
if identifier not in self.extended:
raise NameError('Unknown substitution {!r}'.format(identifier))
if match.group('eval'):
identifier += spec.eval
out = spec.start + identifier + spec.end
if '$' in out or '#' in out:
raise ValueError('Failed to convert: ' + expr)
self.stats['simple'] += 1
return spec.type(out)
def convert_hard(self, expr, spec=Python):
lines = '\n'.join(self.convert_hard_line(line, spec) for line in expr.split('\n'))
if spec == Mako:
# no line-continuation before a mako control structure
lines = re.sub(r'\\\n(\s*%)', r'\n\1', lines)
return lines
def convert_hard_line(self, expr, spec=Python):
if spec == Mako:
if '#set' in expr:
ws, set_, statement = expr.partition('#set ')
return ws + '<% ' + self.to_python(statement) + ' %>'
if '#if' in expr:
ws, if_, condition = expr.partition('#if ')
return ws + '% if ' + self.to_python(condition) + ':'
if '#else if' in expr:
ws, elif_, condition = expr.partition('#else if ')
return ws + '% elif ' + self.to_python(condition) + ':'
if '#else' in expr:
return expr.replace('#else', '% else:')
if '#end if' in expr:
return expr.replace('#end if', '% endif')
if '#slurp' in expr:
expr = expr.split('#slurp', 1)[0] + '\\'
return self.convert_hard_replace(expr, spec)
def convert_hard_replace(self, expr, spec=Python):
counts = collections.Counter()
def all_delims_closed():
for opener_, closer_ in delims.items():
if counts[opener_] != counts[closer_]:
return False
return True
def extra_close():
for opener_, closer_ in delims.items():
if counts[opener_] < counts[closer_]:
return True
return False
out = []
delim_to_find = False
pos = 0
char = ''
in_string = None
while pos < len(expr):
prev, char = char, expr[pos]
counts.update(char)
if char in string_delims:
if not in_string:
in_string = char
elif char == in_string:
in_string = None
out.append(char)
pos += 1
continue
if in_string:
out.append(char)
pos += 1
continue
if char == '$':
pass # no output
elif prev == '$':
if char not in identifier_start: # not a substitution
out.append('$' + char) # now print the $ we skipped over
elif not delim_to_find: # start of a substitution
try:
delim_to_find = delims[char]
out.append(spec.start)
except KeyError:
if char in identifier_start:
delim_to_find = delims['']
out.append(spec.start)
out.append(char)
counts.clear()
counts.update(char)
else: # nested substitution: simply match known variable names
found = False
for known_identifier in self.names:
if expr[pos:].startswith(known_identifier):
found = True
break
if found:
out.append(spec.nested_start)
out.append(known_identifier)
out.append(spec.nested_end)
pos += len(known_identifier)
continue
elif delim_to_find and char in delim_to_find and all_delims_closed(): # end of substitution
out.append(spec.end)
if char in delims['']:
out.append(char)
delim_to_find = False
elif delim_to_find and char in ')]}' and extra_close(): # end of substitution
out.append(spec.end)
out.append(char)
delim_to_find = False
else:
out.append(char)
pos += 1
if delim_to_find == delims['']:
out.append(spec.end)
out = ''.join(out)
# fix: eval stuff
out = re.sub(r'(?P<arg>' + r'|'.join(self.extended) + r')\(\)', r'\g<arg>', out)
self.stats['hard'] += 1
return spec.type(out)
def convert_inline_conditional(self, expr, spec=Python):
if spec == FormatString:
raise ValueError('No conditionals in format strings: ' + expr)
matcher = r'\g<then> if \g<cond> else \g<else>'
if spec == Python:
matcher = '(' + matcher + ')'
expr = cheetah_inline_if.sub(matcher, expr)
return spec.type(self.convert_hard(expr, spec))
class DummyConverter(object):
def __init__(self, names={}):
pass
def to_python(self, expr):
return expr
def to_format_string(self, expr):
return expr
def to_mako(self, expr):
return expr
|
gpl-3.0
|
[
3,
1898,
7800,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
14629,
13,
18,
14,
16,
13,
269,
13,
18103,
199,
3,
421,
199,
646,
5055,
199,
646,
295,
199,
646,
1059,
199,
199,
6933,
706,
275,
791,
6176,
283,
3196,
6730,
356,
283,
4300,
5041,
356,
283,
7293,
8061,
1656,
327,
1103,
19429,
936,
199,
5364,
63,
928,
275,
14135,
435,
1059,
14,
4371,
63,
16415,
435,
6522,
904,
8,
6933,
706,
14,
1612,
1012,
199,
875,
63,
6933,
706,
275,
283,
3212,
891,
199,
199,
595,
1841,
72,
63,
30809,
275,
295,
14,
2014,
8,
272,
519,
15542,
4,
17304,
48,
28,
68,
17,
3072,
342,
92,
2229,
48,
28,
68,
18,
3072,
91,
25963,
48,
28,
68,
19,
3072,
59,
8636,
3171,
272,
519,
10120,
48,
28,
1273,
9514,
63,
65,
13,
6353,
13,
58,
1527,
63,
65,
13,
6353,
13,
58,
16,
13,
25,
3672,
15840,
14,
13040,
65,
13,
6353,
13,
58,
1527,
63,
65,
13,
6353,
13,
58,
16,
13,
25,
3672,
5547,
18168,
48,
28,
2579,
3072,
2961,
430,
14069,
272,
519,
10120,
8,
68,
17,
2862,
25963,
8,
68,
18,
2862,
22441,
2229,
8,
68,
19,
2862,
11752,
1724,
12913,
199,
9,
199,
595,
1841,
72,
63,
6460,
63,
692,
275,
295,
14,
2014,
8,
82,
11525,
692,
7558,
48,
28,
2067,
26343,
2066,
7558,
48,
28,
12726,
27124,
9,
5805,
2836,
7558,
48,
28,
2836,
27124,
9,
5805,
27496,
92,
4,
5942,
421,
199,
533,
2018,
8,
785,
304,
272,
1343,
275,
2125,
272,
1284,
275,
2125,
272,
6032,
63,
928,
275,
2125,
272,
6032,
63,
500,
275,
2125,
272,
3468,
275,
2125,
272,
730,
275,
620,
221,
327,
8864,
63,
1199,
14,
10006,
421,
199,
533,
9701,
1558,
8,
4718,
304,
272,
1343,
275,
26109,
272,
1284,
275,
23618,
272,
6032,
63,
928,
275,
26109,
272,
6032,
63,
500,
275,
23618,
272,
3468,
275,
7596,
2579,
7,
272,
730,
275,
620,
421,
199,
533,
603,
23564,
8,
4718,
304,
272,
1343,
275,
4505,
1445,
272,
1284,
275,
23618,
272,
6032,
63,
928,
275,
2125,
272,
6032,
63,
500,
275,
2125,
272,
730,
275,
620,
421,
199,
533,
11801,
351,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1561,
304,
267,
291,
14,
3200,
275,
5055,
14,
21501,
8,
442,
9,
267,
291,
14,
1247,
275,
663,
8,
1247,
9,
267,
291,
14,
10525,
275,
663,
8,
277,
423,
1661,
63,
14227,
8,
1247,
430,
339,
768,
4639,
272,
347,
485,
1661,
63,
14227,
8,
1247,
304,
267,
340,
440,
1228,
8,
1247,
12,
1211,
304,
288,
1561,
275,
469,
354,
26,
1052,
367,
536,
315,
1561,
93,
267,
367,
790,
12,
1007,
63,
1612,
315,
1561,
14,
1744,
837,
288,
1995,
790,
288,
367,
1007,
63,
498,
315,
1007,
63,
1612,
26,
355,
1995,
9005,
14,
11123,
908,
8,
498,
12,
1007,
63,
498,
9,
339,
347,
370,
63,
1548,
8,
277,
12,
5348,
304,
267,
372,
291,
14,
3916,
8,
3684,
29,
3684,
12,
3158,
29,
4718,
9,
339,
347,
370,
63,
1548,
63,
7778,
8,
277,
12,
5348,
304,
267,
6702,
275,
291,
14,
3916,
8,
3684,
29,
3684,
12,
3158,
29,
4718,
9,
267,
340,
6702,
436,
6702,
1137,
5348,
26,
288,
6702,
275,
20044,
283,
435,
6702,
14,
1913,
342,
435,
283,
789,
7,
267,
372,
6702,
339,
347,
370,
63,
908,
63,
875,
8,
277,
12,
5348,
304,
267,
372,
291,
14,
3916,
8,
3684,
29,
3684,
12,
3158,
29,
3484,
1558,
9,
339,
347,
370,
63,
19491,
8,
277,
12,
5348,
304,
267,
372,
291,
14,
3916,
8,
3684,
29,
3684,
12,
3158,
29,
45,
23564,
9,
339,
347,
3957,
8,
277,
12,
5348,
12,
3158,
29,
4718,
304,
267,
340,
440,
5348,
26,
288,
372,
2125,
398,
916,
25271,
440,
315,
5348,
26,
288,
372,
5348,
398,
862,
26,
288,
372,
291,
14,
3916,
63,
4129,
8,
3684,
12,
3158,
9,
267,
871,
1722,
26,
288,
986,
398,
862,
26,
288,
340,
3943,
692,
7,
315,
5348,
436,
1557,
78,
7,
440,
315,
5348,
26,
355,
5348,
275,
291,
14,
3916,
63,
6460,
63,
14353,
8,
3684,
12,
3158,
9,
288,
372,
291,
14,
3916,
63,
8726,
8,
3684,
12,
3158,
9,
267,
871,
1722,
26,
288,
372,
283,
20335,
1841,
72,
1,
283,
435,
5348,
339,
347,
3957,
63,
4129,
8,
277,
12,
5348,
12,
3158,
29,
4718,
304,
267,
1336,
275,
17546,
1841,
72,
63,
30809,
14,
1431,
8,
3684,
9,
267,
340,
440,
1336,
26,
288,
746,
1722,
360,
1763,
282,
3486,
20584,
26,
283,
435,
5348,
9,
398,
5148,
275,
1336,
14,
923,
360,
1273,
358,
267,
340,
5148,
440,
315,
291,
14,
10525,
26,
288,
746,
12746,
360,
5912,
20584,
18776,
82,
5285,
908,
8,
5364,
430,
267,
340,
1336,
14,
923,
360,
2579,
735,
288,
5148,
847,
3158,
14,
2579,
398,
734,
275,
3158,
14,
928,
435,
5148,
435,
3158,
14,
500,
267,
340,
25271,
315,
734,
503,
19619,
315,
734,
26,
288,
746,
1722,
360,
4276,
370,
3957,
26,
283,
435,
5348,
9,
398,
291,
14,
3200,
459,
4129,
418,
847,
413,
267,
372,
3158,
14,
466,
8,
548,
9,
339,
347,
3957,
63,
8726,
8,
277,
12,
5348,
12,
3158,
29,
4718,
304,
267,
2385,
275,
1557,
78,
1370,
904,
8,
277,
14,
3916,
63,
8726,
63,
604,
8,
604,
12,
3158,
9,
367,
1004,
315,
5348,
14,
1294,
2258,
78,
1333,
267,
340,
3158,
508,
603,
23564,
26,
288,
327,
949,
1004,
13,
20305,
2544,
282,
26834,
3304,
5523,
288,
2385,
275,
295,
14,
954,
8,
82,
32190,
78,
2961,
83,
32639,
3196,
519,
1154,
78,
60,
17,
297,
2385,
9,
267,
372,
2385,
339,
347,
3957,
63,
8726,
63,
604,
8,
277,
12,
5348,
12,
3158,
29,
4718,
304,
267,
340,
3158,
508,
603,
23564,
26,
288,
340,
3943,
409,
7,
315,
5348,
26,
355,
10900,
12,
663,
3131,
5164,
275,
5348,
14,
5312,
7863,
409,
5320,
355,
372,
10900,
435,
18342,
283,
435,
291,
14,
475,
63,
1548,
8,
6242,
9,
435,
283,
450,
3524,
953
] |
[
1898,
7800,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
199,
3,
6988,
19596,
13,
3761,
13,
7544,
26,
14629,
13,
18,
14,
16,
13,
269,
13,
18103,
199,
3,
421,
199,
646,
5055,
199,
646,
295,
199,
646,
1059,
199,
199,
6933,
706,
275,
791,
6176,
283,
3196,
6730,
356,
283,
4300,
5041,
356,
283,
7293,
8061,
1656,
327,
1103,
19429,
936,
199,
5364,
63,
928,
275,
14135,
435,
1059,
14,
4371,
63,
16415,
435,
6522,
904,
8,
6933,
706,
14,
1612,
1012,
199,
875,
63,
6933,
706,
275,
283,
3212,
891,
199,
199,
595,
1841,
72,
63,
30809,
275,
295,
14,
2014,
8,
272,
519,
15542,
4,
17304,
48,
28,
68,
17,
3072,
342,
92,
2229,
48,
28,
68,
18,
3072,
91,
25963,
48,
28,
68,
19,
3072,
59,
8636,
3171,
272,
519,
10120,
48,
28,
1273,
9514,
63,
65,
13,
6353,
13,
58,
1527,
63,
65,
13,
6353,
13,
58,
16,
13,
25,
3672,
15840,
14,
13040,
65,
13,
6353,
13,
58,
1527,
63,
65,
13,
6353,
13,
58,
16,
13,
25,
3672,
5547,
18168,
48,
28,
2579,
3072,
2961,
430,
14069,
272,
519,
10120,
8,
68,
17,
2862,
25963,
8,
68,
18,
2862,
22441,
2229,
8,
68,
19,
2862,
11752,
1724,
12913,
199,
9,
199,
595,
1841,
72,
63,
6460,
63,
692,
275,
295,
14,
2014,
8,
82,
11525,
692,
7558,
48,
28,
2067,
26343,
2066,
7558,
48,
28,
12726,
27124,
9,
5805,
2836,
7558,
48,
28,
2836,
27124,
9,
5805,
27496,
92,
4,
5942,
421,
199,
533,
2018,
8,
785,
304,
272,
1343,
275,
2125,
272,
1284,
275,
2125,
272,
6032,
63,
928,
275,
2125,
272,
6032,
63,
500,
275,
2125,
272,
3468,
275,
2125,
272,
730,
275,
620,
221,
327,
8864,
63,
1199,
14,
10006,
421,
199,
533,
9701,
1558,
8,
4718,
304,
272,
1343,
275,
26109,
272,
1284,
275,
23618,
272,
6032,
63,
928,
275,
26109,
272,
6032,
63,
500,
275,
23618,
272,
3468,
275,
7596,
2579,
7,
272,
730,
275,
620,
421,
199,
533,
603,
23564,
8,
4718,
304,
272,
1343,
275,
4505,
1445,
272,
1284,
275,
23618,
272,
6032,
63,
928,
275,
2125,
272,
6032,
63,
500,
275,
2125,
272,
730,
275,
620,
421,
199,
533,
11801,
351,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1561,
304,
267,
291,
14,
3200,
275,
5055,
14,
21501,
8,
442,
9,
267,
291,
14,
1247,
275,
663,
8,
1247,
9,
267,
291,
14,
10525,
275,
663,
8,
277,
423,
1661,
63,
14227,
8,
1247,
430,
339,
768,
4639,
272,
347,
485,
1661,
63,
14227,
8,
1247,
304,
267,
340,
440,
1228,
8,
1247,
12,
1211,
304,
288,
1561,
275,
469,
354,
26,
1052,
367,
536,
315,
1561,
93,
267,
367,
790,
12,
1007,
63,
1612,
315,
1561,
14,
1744,
837,
288,
1995,
790,
288,
367,
1007,
63,
498,
315,
1007,
63,
1612,
26,
355,
1995,
9005,
14,
11123,
908,
8,
498,
12,
1007,
63,
498,
9,
339,
347,
370,
63,
1548,
8,
277,
12,
5348,
304,
267,
372,
291,
14,
3916,
8,
3684,
29,
3684,
12,
3158,
29,
4718,
9,
339,
347,
370,
63,
1548,
63,
7778,
8,
277,
12,
5348,
304,
267,
6702,
275,
291,
14,
3916,
8,
3684,
29,
3684,
12,
3158,
29,
4718,
9,
267,
340,
6702,
436,
6702,
1137,
5348,
26,
288,
6702,
275,
20044,
283,
435,
6702,
14,
1913,
342,
435,
283,
789,
7,
267,
372,
6702,
339,
347,
370,
63,
908,
63,
875,
8,
277,
12,
5348,
304,
267,
372,
291,
14,
3916,
8,
3684,
29,
3684,
12,
3158,
29,
3484,
1558,
9,
339,
347,
370,
63,
19491,
8,
277,
12,
5348,
304,
267,
372,
291,
14,
3916,
8,
3684,
29,
3684,
12,
3158,
29,
45,
23564,
9,
339,
347,
3957,
8,
277,
12,
5348,
12,
3158,
29,
4718,
304,
267,
340,
440,
5348,
26,
288,
372,
2125,
398,
916,
25271,
440,
315,
5348,
26,
288,
372,
5348,
398,
862,
26,
288,
372,
291,
14,
3916,
63,
4129,
8,
3684,
12,
3158,
9,
267,
871,
1722,
26,
288,
986,
398,
862,
26,
288,
340,
3943,
692,
7,
315,
5348,
436,
1557,
78,
7,
440,
315,
5348,
26,
355,
5348,
275,
291,
14,
3916,
63,
6460,
63,
14353,
8,
3684,
12,
3158,
9,
288,
372,
291,
14,
3916,
63,
8726,
8,
3684,
12,
3158,
9,
267,
871,
1722,
26,
288,
372,
283,
20335,
1841,
72,
1,
283,
435,
5348,
339,
347,
3957,
63,
4129,
8,
277,
12,
5348,
12,
3158,
29,
4718,
304,
267,
1336,
275,
17546,
1841,
72,
63,
30809,
14,
1431,
8,
3684,
9,
267,
340,
440,
1336,
26,
288,
746,
1722,
360,
1763,
282,
3486,
20584,
26,
283,
435,
5348,
9,
398,
5148,
275,
1336,
14,
923,
360,
1273,
358,
267,
340,
5148,
440,
315,
291,
14,
10525,
26,
288,
746,
12746,
360,
5912,
20584,
18776,
82,
5285,
908,
8,
5364,
430,
267,
340,
1336,
14,
923,
360,
2579,
735,
288,
5148,
847,
3158,
14,
2579,
398,
734,
275,
3158,
14,
928,
435,
5148,
435,
3158,
14,
500,
267,
340,
25271,
315,
734,
503,
19619,
315,
734,
26,
288,
746,
1722,
360,
4276,
370,
3957,
26,
283,
435,
5348,
9,
398,
291,
14,
3200,
459,
4129,
418,
847,
413,
267,
372,
3158,
14,
466,
8,
548,
9,
339,
347,
3957,
63,
8726,
8,
277,
12,
5348,
12,
3158,
29,
4718,
304,
267,
2385,
275,
1557,
78,
1370,
904,
8,
277,
14,
3916,
63,
8726,
63,
604,
8,
604,
12,
3158,
9,
367,
1004,
315,
5348,
14,
1294,
2258,
78,
1333,
267,
340,
3158,
508,
603,
23564,
26,
288,
327,
949,
1004,
13,
20305,
2544,
282,
26834,
3304,
5523,
288,
2385,
275,
295,
14,
954,
8,
82,
32190,
78,
2961,
83,
32639,
3196,
519,
1154,
78,
60,
17,
297,
2385,
9,
267,
372,
2385,
339,
347,
3957,
63,
8726,
63,
604,
8,
277,
12,
5348,
12,
3158,
29,
4718,
304,
267,
340,
3158,
508,
603,
23564,
26,
288,
340,
3943,
409,
7,
315,
5348,
26,
355,
10900,
12,
663,
3131,
5164,
275,
5348,
14,
5312,
7863,
409,
5320,
355,
372,
10900,
435,
18342,
283,
435,
291,
14,
475,
63,
1548,
8,
6242,
9,
435,
283,
450,
3524,
953,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
DOCUMENTATION = '''
---
module: vmware_dvswitch
short_description: Create or remove a distributed vSwitch
description:
- Create or remove a distributed vSwitch
version_added: 2.0
author: "Joseph Callen (@jcpowermac)"
notes:
- Tested on vSphere 5.5
requirements:
- "python >= 2.6"
- PyVmomi
options:
hostname:
description:
- The hostname or IP address of the vSphere vCenter API server
required: True
username:
description:
- The username of the vSphere vCenter
required: True
aliases: ['user', 'admin']
password:
description:
- The password of the vSphere vCenter
required: True
aliases: ['pass', 'pwd']
datacenter_name:
description:
- The name of the datacenter that will contain the dvSwitch
required: True
switch_name:
description:
- The name of the switch to create or remove
required: True
mtu:
description:
- The switch maximum transmission unit
required: True
uplink_quantity:
description:
- Quantity of uplink per ESXi host added to the switch
required: True
discovery_proto:
description:
- Link discovery protocol between Cisco and Link Layer discovery
choices:
- 'cdp'
- 'lldp'
required: True
discovery_operation:
description:
- Select the discovery operation
choices:
- 'both'
- 'none'
- 'advertise'
- 'listen'
state:
description:
- Create or remove dvSwitch
default: 'present'
choices:
- 'present'
- 'absent'
required: False
'''
EXAMPLES = '''
- name: Create dvswitch
local_action:
module: vmware_dvswitch
hostname: vcenter_ip_or_hostname
username: vcenter_username
password: vcenter_password
datacenter_name: datacenter
switch_name: dvSwitch
mtu: 9000
uplink_quantity: 2
discovery_proto: lldp
discovery_operation: both
state: present
'''
try:
from pyVmomi import vim, vmodl
HAS_PYVMOMI = True
except ImportError:
HAS_PYVMOMI = False
def create_dvswitch(network_folder, switch_name, mtu, uplink_quantity, discovery_proto, discovery_operation):
result = None
changed = False
spec = vim.DistributedVirtualSwitch.CreateSpec()
spec.configSpec = vim.dvs.VmwareDistributedVirtualSwitch.ConfigSpec()
spec.configSpec.uplinkPortPolicy = vim.DistributedVirtualSwitch.NameArrayUplinkPortPolicy()
spec.configSpec.linkDiscoveryProtocolConfig = vim.host.LinkDiscoveryProtocolConfig()
spec.configSpec.name = switch_name
spec.configSpec.maxMtu = mtu
spec.configSpec.linkDiscoveryProtocolConfig.protocol = discovery_proto
spec.configSpec.linkDiscoveryProtocolConfig.operation = discovery_operation
spec.productInfo = vim.dvs.ProductSpec()
spec.productInfo.name = "DVS"
spec.productInfo.vendor = "VMware"
for count in range(1, uplink_quantity+1):
spec.configSpec.uplinkPortPolicy.uplinkPortName.append("uplink%d" % count)
task = network_folder.CreateDVS_Task(spec)
changed, result = wait_for_task(task)
return changed, result
def state_exit_unchanged(module):
module.exit_json(changed=False)
def state_destroy_dvs(module):
dvs = module.params['dvs']
task = dvs.Destroy_Task()
changed, result = wait_for_task(task)
module.exit_json(changed=changed, result=str(result))
def state_update_dvs(module):
module.exit_json(changed=False, msg="Currently not implemented.")
def state_create_dvs(module):
switch_name = module.params['switch_name']
datacenter_name = module.params['datacenter_name']
content = module.params['content']
mtu = module.params['mtu']
uplink_quantity = module.params['uplink_quantity']
discovery_proto = module.params['discovery_proto']
discovery_operation = module.params['discovery_operation']
changed = True
result = None
if not module.check_mode:
dc = find_datacenter_by_name(content, datacenter_name)
changed, result = create_dvswitch(dc.networkFolder, switch_name,
mtu, uplink_quantity, discovery_proto,
discovery_operation)
module.exit_json(changed=changed, result=str(result))
def check_dvs_configuration(module):
switch_name = module.params['switch_name']
content = connect_to_api(module)
module.params['content'] = content
dvs = find_dvs_by_name(content, switch_name)
if dvs is None:
return 'absent'
else:
module.params['dvs'] = dvs
return 'present'
def main():
argument_spec = vmware_argument_spec()
argument_spec.update(dict(datacenter_name=dict(required=True, type='str'),
switch_name=dict(required=True, type='str'),
mtu=dict(required=True, type='int'),
uplink_quantity=dict(required=True, type='int'),
discovery_proto=dict(required=True, choices=['cdp', 'lldp'], type='str'),
discovery_operation=dict(required=True, choices=['both', 'none', 'advertise', 'listen'], type='str'),
state=dict(default='present', choices=['present', 'absent'], type='str')))
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
if not HAS_PYVMOMI:
module.fail_json(msg='pyvmomi is required for this module')
try:
# Currently state_update_dvs is not implemented.
dvs_states = {
'absent': {
'present': state_destroy_dvs,
'absent': state_exit_unchanged,
},
'present': {
'update': state_update_dvs,
'present': state_exit_unchanged,
'absent': state_create_dvs,
}
}
dvs_states[module.params['state']][check_dvs_configuration(module)](module)
except vmodl.RuntimeFault as runtime_fault:
module.fail_json(msg=runtime_fault.msg)
except vmodl.MethodFault as method_fault:
module.fail_json(msg=method_fault.msg)
except Exception as e:
module.fail_json(msg=str(e))
from ansible.module_utils.vmware import *
from ansible.module_utils.basic import *
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6900,
12,
1603,
3362,
838,
445,
7670,
665,
74,
915,
552,
6248,
28308,
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,
8948,
275,
1449,
199,
2595,
199,
578,
26,
19365,
63,
68,
23201,
199,
3612,
63,
1802,
26,
2790,
503,
2813,
282,
1854,
373,
10167,
199,
1802,
26,
272,
446,
2790,
503,
2813,
282,
1854,
373,
10167,
199,
1023,
63,
3270,
26,
499,
14,
16,
199,
2502,
26,
298,
42,
3362,
838,
445,
7670,
8593,
22760,
5652,
3088,
2924,
199,
5983,
26,
272,
446,
30568,
641,
373,
22385,
959,
14,
21,
199,
7538,
26,
272,
446,
298,
1548,
2356,
499,
14,
22,
2,
272,
446,
1611,
54,
28603,
199,
1419,
26,
272,
6246,
26,
267,
1369,
26,
288,
446,
710,
6246,
503,
3531,
2287,
402,
314,
373,
22385,
373,
13551,
3261,
1654,
267,
1415,
26,
715,
272,
3434,
26,
267,
1369,
26,
288,
446,
710,
3434,
402,
314,
373,
22385,
373,
13551,
267,
1415,
26,
715,
267,
5481,
26,
788,
751,
297,
283,
2113,
418,
272,
2505,
26,
267,
1369,
26,
288,
446,
710,
2505,
402,
314,
373,
22385,
373,
13551,
267,
1415,
26,
715,
267,
5481,
26,
788,
1529,
297,
283,
14258,
418,
272,
16606,
63,
354,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
16606,
626,
911,
1395,
314,
26869,
10167,
267,
1415,
26,
715,
272,
6258,
63,
354,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
6258,
370,
1218,
503,
2813,
267,
1415,
26,
715,
272,
28270,
26,
267,
1369,
26,
288,
446,
710,
6258,
5696,
1752,
2250,
4137,
267,
1415,
26,
715,
272,
1536,
1073,
63,
10577,
26,
267,
1369,
26,
288,
446,
31951,
402,
1536,
1073,
1126,
10427,
14828,
1591,
3483,
370,
314,
6258,
267,
1415,
26,
715,
272,
13172,
63,
2625,
26,
267,
1369,
26,
288,
446,
10967,
13172,
4113,
3382,
28356,
436,
10967,
11915,
13172,
267,
3415,
26,
288,
446,
283,
2866,
80,
7,
288,
446,
283,
24319,
7,
267,
1415,
26,
715,
272,
13172,
63,
5735,
26,
267,
1369,
26,
288,
446,
9496,
314,
13172,
3439,
267,
3415,
26,
288,
446,
283,
10727,
7,
288,
446,
283,
3592,
7,
288,
446,
283,
24576,
261,
7,
288,
446,
283,
5859,
7,
272,
1174,
26,
267,
1369,
26,
288,
446,
2790,
503,
2813,
26869,
10167,
267,
849,
26,
283,
1881,
7,
267,
3415,
26,
288,
446,
283,
1881,
7,
288,
446,
283,
5575,
7,
267,
1415,
26,
756,
199,
2344,
199,
8918,
275,
1449,
199,
13,
536,
26,
2790,
366,
23201,
523,
2257,
63,
1287,
26,
272,
859,
26,
19365,
63,
68,
23201,
272,
6246,
26,
27127,
63,
711,
63,
269,
63,
4269,
272,
3434,
26,
27127,
63,
2473,
272,
2505,
26,
27127,
63,
2060,
272,
16606,
63,
354,
26,
16606,
272,
6258,
63,
354,
26,
26869,
10167,
272,
28270,
26,
1749,
1493,
272,
1536,
1073,
63,
10577,
26,
499,
272,
13172,
63,
2625,
26,
28768,
272,
13172,
63,
5735,
26,
3865,
272,
1174,
26,
3451,
199,
2344,
199,
199,
893,
26,
272,
687,
1134,
54,
28603,
492,
6695,
12,
373,
1494,
76,
272,
7509,
63,
4521,
54,
2679,
10709,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
4521,
54,
2679,
10709,
275,
756,
421,
199,
318,
1218,
63,
68,
23201,
8,
1200,
63,
3741,
12,
6258,
63,
354,
12,
28270,
12,
1536,
1073,
63,
10577,
12,
13172,
63,
2625,
12,
13172,
63,
5735,
304,
339,
754,
275,
488,
272,
2896,
275,
756,
339,
3158,
275,
6695,
14,
27398,
8735,
10167,
14,
2499,
5307,
342,
272,
3158,
14,
888,
5307,
275,
6695,
14,
68,
3122,
14,
17402,
1068,
27398,
8735,
10167,
14,
2028,
5307,
342,
272,
3158,
14,
888,
5307,
14,
28816,
4313,
4845,
275,
6695,
14,
27398,
8735,
10167,
14,
985,
3836,
29523,
4313,
4845,
342,
272,
3158,
14,
888,
5307,
14,
1073,
2825,
6913,
3658,
2028,
275,
6695,
14,
1102,
14,
3834,
2825,
6913,
3658,
2028,
342,
339,
3158,
14,
888,
5307,
14,
354,
275,
6258,
63,
354,
272,
3158,
14,
888,
5307,
14,
988,
45,
10963,
275,
28270,
272,
3158,
14,
888,
5307,
14,
1073,
2825,
6913,
3658,
2028,
14,
3922,
275,
13172,
63,
2625,
272,
3158,
14,
888,
5307,
14,
1073,
2825,
6913,
3658,
2028,
14,
5735,
275,
13172,
63,
5735,
272,
3158,
14,
2558,
2354,
275,
6695,
14,
68,
3122,
14,
5884,
5307,
342,
272,
3158,
14,
2558,
2354,
14,
354,
275,
298,
6741,
51,
2,
272,
3158,
14,
2558,
2354,
14,
9884,
275,
298,
6849,
1068,
2,
339,
367,
2338,
315,
1425,
8,
17,
12,
1536,
1073,
63,
10577,
11,
17,
304,
267,
3158,
14,
888,
5307,
14,
28816,
4313,
4845,
14,
28816,
4313,
985,
14,
740,
480,
28816,
5,
68,
2,
450,
2338,
9,
339,
2120,
275,
2784,
63,
3741,
14,
2499,
6741,
51,
63,
4476,
8,
1650,
9,
272,
2896,
12,
754,
275,
3618,
63,
509,
63,
1765,
8,
1765,
9,
272,
372,
2896,
12,
754,
421,
199,
318,
1174,
63,
2224,
63,
16914,
8,
578,
304,
272,
859,
14,
2224,
63,
1001,
8,
2489,
29,
797,
9,
421,
199,
318,
1174,
63,
7237,
63,
68,
3122,
8,
578,
304,
272,
366,
3122,
275,
859,
14,
1162,
459,
68
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6900,
12,
1603,
3362,
838,
445,
7670,
665,
74,
915,
552,
6248,
28308,
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,
8948,
275,
1449,
199,
2595,
199,
578,
26,
19365,
63,
68,
23201,
199,
3612,
63,
1802,
26,
2790,
503,
2813,
282,
1854,
373,
10167,
199,
1802,
26,
272,
446,
2790,
503,
2813,
282,
1854,
373,
10167,
199,
1023,
63,
3270,
26,
499,
14,
16,
199,
2502,
26,
298,
42,
3362,
838,
445,
7670,
8593,
22760,
5652,
3088,
2924,
199,
5983,
26,
272,
446,
30568,
641,
373,
22385,
959,
14,
21,
199,
7538,
26,
272,
446,
298,
1548,
2356,
499,
14,
22,
2,
272,
446,
1611,
54,
28603,
199,
1419,
26,
272,
6246,
26,
267,
1369,
26,
288,
446,
710,
6246,
503,
3531,
2287,
402,
314,
373,
22385,
373,
13551,
3261,
1654,
267,
1415,
26,
715,
272,
3434,
26,
267,
1369,
26,
288,
446,
710,
3434,
402,
314,
373,
22385,
373,
13551,
267,
1415,
26,
715,
267,
5481,
26,
788,
751,
297,
283,
2113,
418,
272,
2505,
26,
267,
1369,
26,
288,
446,
710,
2505,
402,
314,
373,
22385,
373,
13551,
267,
1415,
26,
715,
267,
5481,
26,
788,
1529,
297,
283,
14258,
418,
272,
16606,
63,
354,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
16606,
626,
911,
1395,
314,
26869,
10167,
267,
1415,
26,
715,
272,
6258,
63,
354,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
6258,
370,
1218,
503,
2813,
267,
1415,
26,
715,
272,
28270,
26,
267,
1369,
26,
288,
446,
710,
6258,
5696,
1752,
2250,
4137,
267,
1415,
26,
715,
272,
1536,
1073,
63,
10577,
26,
267,
1369,
26,
288,
446,
31951,
402,
1536,
1073,
1126,
10427,
14828,
1591,
3483,
370,
314,
6258,
267,
1415,
26,
715,
272,
13172,
63,
2625,
26,
267,
1369,
26,
288,
446,
10967,
13172,
4113,
3382,
28356,
436,
10967,
11915,
13172,
267,
3415,
26,
288,
446,
283,
2866,
80,
7,
288,
446,
283,
24319,
7,
267,
1415,
26,
715,
272,
13172,
63,
5735,
26,
267,
1369,
26,
288,
446,
9496,
314,
13172,
3439,
267,
3415,
26,
288,
446,
283,
10727,
7,
288,
446,
283,
3592,
7,
288,
446,
283,
24576,
261,
7,
288,
446,
283,
5859,
7,
272,
1174,
26,
267,
1369,
26,
288,
446,
2790,
503,
2813,
26869,
10167,
267,
849,
26,
283,
1881,
7,
267,
3415,
26,
288,
446,
283,
1881,
7,
288,
446,
283,
5575,
7,
267,
1415,
26,
756,
199,
2344,
199,
8918,
275,
1449,
199,
13,
536,
26,
2790,
366,
23201,
523,
2257,
63,
1287,
26,
272,
859,
26,
19365,
63,
68,
23201,
272,
6246,
26,
27127,
63,
711,
63,
269,
63,
4269,
272,
3434,
26,
27127,
63,
2473,
272,
2505,
26,
27127,
63,
2060,
272,
16606,
63,
354,
26,
16606,
272,
6258,
63,
354,
26,
26869,
10167,
272,
28270,
26,
1749,
1493,
272,
1536,
1073,
63,
10577,
26,
499,
272,
13172,
63,
2625,
26,
28768,
272,
13172,
63,
5735,
26,
3865,
272,
1174,
26,
3451,
199,
2344,
199,
199,
893,
26,
272,
687,
1134,
54,
28603,
492,
6695,
12,
373,
1494,
76,
272,
7509,
63,
4521,
54,
2679,
10709,
275,
715,
199,
2590,
3545,
26,
272,
7509,
63,
4521,
54,
2679,
10709,
275,
756,
421,
199,
318,
1218,
63,
68,
23201,
8,
1200,
63,
3741,
12,
6258,
63,
354,
12,
28270,
12,
1536,
1073,
63,
10577,
12,
13172,
63,
2625,
12,
13172,
63,
5735,
304,
339,
754,
275,
488,
272,
2896,
275,
756,
339,
3158,
275,
6695,
14,
27398,
8735,
10167,
14,
2499,
5307,
342,
272,
3158,
14,
888,
5307,
275,
6695,
14,
68,
3122,
14,
17402,
1068,
27398,
8735,
10167,
14,
2028,
5307,
342,
272,
3158,
14,
888,
5307,
14,
28816,
4313,
4845,
275,
6695,
14,
27398,
8735,
10167,
14,
985,
3836,
29523,
4313,
4845,
342,
272,
3158,
14,
888,
5307,
14,
1073,
2825,
6913,
3658,
2028,
275,
6695,
14,
1102,
14,
3834,
2825,
6913,
3658,
2028,
342,
339,
3158,
14,
888,
5307,
14,
354,
275,
6258,
63,
354,
272,
3158,
14,
888,
5307,
14,
988,
45,
10963,
275,
28270,
272,
3158,
14,
888,
5307,
14,
1073,
2825,
6913,
3658,
2028,
14,
3922,
275,
13172,
63,
2625,
272,
3158,
14,
888,
5307,
14,
1073,
2825,
6913,
3658,
2028,
14,
5735,
275,
13172,
63,
5735,
272,
3158,
14,
2558,
2354,
275,
6695,
14,
68,
3122,
14,
5884,
5307,
342,
272,
3158,
14,
2558,
2354,
14,
354,
275,
298,
6741,
51,
2,
272,
3158,
14,
2558,
2354,
14,
9884,
275,
298,
6849,
1068,
2,
339,
367,
2338,
315,
1425,
8,
17,
12,
1536,
1073,
63,
10577,
11,
17,
304,
267,
3158,
14,
888,
5307,
14,
28816,
4313,
4845,
14,
28816,
4313,
985,
14,
740,
480,
28816,
5,
68,
2,
450,
2338,
9,
339,
2120,
275,
2784,
63,
3741,
14,
2499,
6741,
51,
63,
4476,
8,
1650,
9,
272,
2896,
12,
754,
275,
3618,
63,
509,
63,
1765,
8,
1765,
9,
272,
372,
2896,
12,
754,
421,
199,
318,
1174,
63,
2224,
63,
16914,
8,
578,
304,
272,
859,
14,
2224,
63,
1001,
8,
2489,
29,
797,
9,
421,
199,
318,
1174,
63,
7237,
63,
68,
3122,
8,
578,
304,
272,
366,
3122,
275,
859,
14,
1162,
459,
68,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fbossy/SickRage
|
lib/stevedore/dispatch.py
|
58
|
8975
|
import logging
from .enabled import EnabledExtensionManager
LOG = logging.getLogger(__name__)
class DispatchExtensionManager(EnabledExtensionManager):
"""Loads all plugins and filters on execution.
This is useful for long-running processes that need to pass
different inputs to different extensions.
:param namespace: The namespace for the entry points.
:type namespace: str
:param check_func: Function to determine which extensions to load.
:type check_func: callable
:param invoke_on_load: Boolean controlling whether to invoke the
object returned by the entry point after the driver is loaded.
:type invoke_on_load: bool
:param invoke_args: Positional arguments to pass when invoking
the object returned by the entry point. Only used if invoke_on_load
is True.
:type invoke_args: tuple
:param invoke_kwds: Named arguments to pass when invoking
the object returned by the entry point. Only used if invoke_on_load
is True.
:type invoke_kwds: dict
:param propagate_map_exceptions: Boolean controlling whether exceptions
are propagated up through the map call or whether they are logged and
then ignored
:type invoke_on_load: bool
"""
def map(self, filter_func, func, *args, **kwds):
"""Iterate over the extensions invoking func() for any where
filter_func() returns True.
The signature of filter_func() should be::
def filter_func(ext, *args, **kwds):
pass
The first argument to filter_func(), 'ext', is the
:class:`~stevedore.extension.Extension`
instance. filter_func() should return True if the extension
should be invoked for the input arguments.
The signature for func() should be::
def func(ext, *args, **kwds):
pass
The first argument to func(), 'ext', is the
:class:`~stevedore.extension.Extension` instance.
Exceptions raised from within func() are propagated up and
processing stopped if self.propagate_map_exceptions is True,
otherwise they are logged and ignored.
:param filter_func: Callable to test each extension.
:param func: Callable to invoke for each extension.
:param args: Variable arguments to pass to func()
:param kwds: Keyword arguments to pass to func()
:returns: List of values returned from func()
"""
if not self.extensions:
# FIXME: Use a more specific exception class here.
raise RuntimeError('No %s extensions found' % self.namespace)
response = []
for e in self.extensions:
if filter_func(e, *args, **kwds):
self._invoke_one_plugin(response.append, func, e, args, kwds)
return response
def map_method(self, filter_func, method_name, *args, **kwds):
"""Iterate over the extensions invoking each one's object method called
`method_name` for any where filter_func() returns True.
This is equivalent of using :meth:`map` with func set to
`lambda x: x.obj.method_name()`
while being more convenient.
Exceptions raised from within the called method are propagated up
and processing stopped if self.propagate_map_exceptions is True,
otherwise they are logged and ignored.
.. versionadded:: 0.12
:param filter_func: Callable to test each extension.
:param method_name: The extension method name to call
for each extension.
:param args: Variable arguments to pass to method
:param kwds: Keyword arguments to pass to method
:returns: List of values returned from methods
"""
return self.map(filter_func, self._call_extension_method,
method_name, *args, **kwds)
class NameDispatchExtensionManager(DispatchExtensionManager):
"""Loads all plugins and filters on execution.
This is useful for long-running processes that need to pass
different inputs to different extensions and can predict the name
of the extensions before calling them.
The check_func argument should return a boolean, with ``True``
indicating that the extension should be loaded and made available
and ``False`` indicating that the extension should be ignored.
:param namespace: The namespace for the entry points.
:type namespace: str
:param check_func: Function to determine which extensions to load.
:type check_func: callable
:param invoke_on_load: Boolean controlling whether to invoke the
object returned by the entry point after the driver is loaded.
:type invoke_on_load: bool
:param invoke_args: Positional arguments to pass when invoking
the object returned by the entry point. Only used if invoke_on_load
is True.
:type invoke_args: tuple
:param invoke_kwds: Named arguments to pass when invoking
the object returned by the entry point. Only used if invoke_on_load
is True.
:type invoke_kwds: dict
:param propagate_map_exceptions: Boolean controlling whether exceptions
are propagated up through the map call or whether they are logged and
then ignored
:type invoke_on_load: bool
:param on_load_failure_callback: Callback function that will be called when
a entrypoint can not be loaded. The arguments that will be provided
when this is called (when an entrypoint fails to load) are
(manager, entrypoint, exception)
:type on_load_failure_callback: function
:param verify_requirements: Use setuptools to enforce the
dependencies of the plugin(s) being loaded. Defaults to False.
:type verify_requirements: bool
"""
def __init__(self, namespace, check_func, invoke_on_load=False,
invoke_args=(), invoke_kwds={},
propagate_map_exceptions=False,
on_load_failure_callback=None,
verify_requirements=False):
super(NameDispatchExtensionManager, self).__init__(
namespace=namespace,
check_func=check_func,
invoke_on_load=invoke_on_load,
invoke_args=invoke_args,
invoke_kwds=invoke_kwds,
propagate_map_exceptions=propagate_map_exceptions,
on_load_failure_callback=on_load_failure_callback,
verify_requirements=verify_requirements,
)
def _init_plugins(self, extensions):
super(NameDispatchExtensionManager, self)._init_plugins(extensions)
self.by_name = dict((e.name, e) for e in self.extensions)
def map(self, names, func, *args, **kwds):
"""Iterate over the extensions invoking func() for any where
the name is in the given list of names.
The signature for func() should be::
def func(ext, *args, **kwds):
pass
The first argument to func(), 'ext', is the
:class:`~stevedore.extension.Extension` instance.
Exceptions raised from within func() are propagated up and
processing stopped if self.propagate_map_exceptions is True,
otherwise they are logged and ignored.
:param names: List or set of name(s) of extension(s) to invoke.
:param func: Callable to invoke for each extension.
:param args: Variable arguments to pass to func()
:param kwds: Keyword arguments to pass to func()
:returns: List of values returned from func()
"""
response = []
for name in names:
try:
e = self.by_name[name]
except KeyError:
LOG.debug('Missing extension %r being ignored', name)
else:
self._invoke_one_plugin(response.append, func, e, args, kwds)
return response
def map_method(self, names, method_name, *args, **kwds):
"""Iterate over the extensions invoking each one's object method called
`method_name` for any where the name is in the given list of names.
This is equivalent of using :meth:`map` with func set to
`lambda x: x.obj.method_name()`
while being more convenient.
Exceptions raised from within the called method are propagated up
and processing stopped if self.propagate_map_exceptions is True,
otherwise they are logged and ignored.
.. versionadded:: 0.12
:param names: List or set of name(s) of extension(s) to invoke.
:param method_name: The extension method name
to call for each extension.
:param args: Variable arguments to pass to method
:param kwds: Keyword arguments to pass to method
:returns: List of values returned from methods
"""
return self.map(names, self._call_extension_method,
method_name, *args, **kwds)
|
gpl-3.0
|
[
646,
2050,
199,
199,
504,
1275,
3827,
492,
3447,
1909,
6382,
2988,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
28626,
6382,
2988,
8,
6589,
6382,
2988,
304,
272,
408,
30777,
1006,
8963,
436,
4766,
641,
6451,
14,
339,
961,
365,
2997,
367,
1846,
13,
5720,
10358,
626,
1929,
370,
986,
272,
3365,
4153,
370,
3365,
5478,
14,
339,
520,
635,
3231,
26,
710,
3231,
367,
314,
2397,
4501,
14,
272,
520,
466,
3231,
26,
620,
272,
520,
635,
1104,
63,
1532,
26,
6801,
370,
6705,
1314,
5478,
370,
2248,
14,
272,
520,
466,
1104,
63,
1532,
26,
4550,
272,
520,
635,
12677,
63,
265,
63,
912,
26,
9411,
30350,
3775,
370,
12677,
314,
267,
909,
2138,
701,
314,
2397,
2376,
2410,
314,
5253,
365,
6511,
14,
272,
520,
466,
12677,
63,
265,
63,
912,
26,
2155,
272,
520,
635,
12677,
63,
589,
26,
15483,
279,
2368,
370,
986,
1380,
26750,
267,
314,
909,
2138,
701,
314,
2397,
2376,
14,
5972,
1202,
340,
12677,
63,
265,
63,
912,
267,
365,
715,
14,
272,
520,
466,
12677,
63,
589,
26,
2008,
272,
520,
635,
12677,
63,
10340,
26,
16198,
2368,
370,
986,
1380,
26750,
267,
314,
909,
2138,
701,
314,
2397,
2376,
14,
5972,
1202,
340,
12677,
63,
265,
63,
912,
267,
365,
715,
14,
272,
520,
466,
12677,
63,
10340,
26,
1211,
272,
520,
635,
19843,
63,
1130,
63,
3924,
26,
9411,
30350,
3775,
4967,
267,
787,
25350,
1536,
4012,
314,
2341,
1240,
503,
3775,
2985,
787,
10367,
436,
267,
2066,
5525,
272,
520,
466,
12677,
63,
265,
63,
912,
26,
2155,
272,
408,
339,
347,
2341,
8,
277,
12,
2457,
63,
1532,
12,
2562,
12,
627,
589,
12,
1011,
10340,
304,
267,
408,
3315,
323,
1806,
314,
5478,
26750,
2562,
342,
367,
1263,
2382,
267,
2457,
63,
1532,
342,
2529,
715,
14,
398,
710,
4955,
402,
2457,
63,
1532,
342,
1077,
506,
447,
953,
347,
2457,
63,
1532,
8,
832,
12,
627,
589,
12,
1011,
10340,
304,
355,
986,
398,
710,
1642,
1423,
370,
2457,
63,
1532,
1062,
283,
832,
297,
365,
314,
267,
520,
533,
6054,
1597,
1354,
720,
14,
3435,
14,
6382,
64,
267,
1256,
14,
2457,
63,
1532,
342,
1077,
372,
715,
340,
314,
3329,
267,
1077,
506,
10302,
367,
314,
1324,
2368,
14,
398,
710,
4955,
367,
2562,
342,
1077,
506,
447,
953,
347,
2562,
8,
832,
12,
627,
589,
12,
1011,
10340,
304,
355,
986,
398,
710,
1642,
1423,
370,
2562,
1062,
283,
832,
297,
365,
314,
267,
520,
533,
6054,
1597,
1354,
720,
14,
3435,
14,
6382,
64,
1256,
14,
398,
24873,
4915,
687,
4453,
2562,
342,
787,
25350,
1536,
436,
267,
6661,
15248,
340,
291,
14,
19432,
63,
1130,
63,
3924,
365,
715,
12,
267,
4257,
2985,
787,
10367,
436,
5525,
14,
398,
520,
635,
2457,
63,
1532,
26,
16975,
370,
511,
1924,
3329,
14,
267,
520,
635,
2562,
26,
16975,
370,
12677,
367,
1924,
3329,
14,
267,
520,
635,
1249,
26,
4905,
2368,
370,
986,
370,
2562,
342,
267,
520,
635,
16286,
26,
6431,
2368,
370,
986,
370,
2562,
342,
267,
520,
5808,
26,
3820,
402,
1338,
2138,
687,
2562,
342,
267,
408,
267,
340,
440,
291,
14,
5359,
26,
288,
327,
7600,
26,
3645,
282,
1655,
2488,
1919,
1021,
2348,
14,
288,
746,
6064,
360,
1944,
450,
83,
5478,
1911,
7,
450,
291,
14,
3251,
9,
267,
1177,
275,
942,
267,
367,
325,
315,
291,
14,
5359,
26,
288,
340,
2457,
63,
1532,
8,
69,
12,
627,
589,
12,
1011,
10340,
304,
355,
291,
423,
15195,
63,
368,
63,
2718,
8,
1310,
14,
740,
12,
2562,
12,
325,
12,
1249,
12,
16286,
9,
267,
372,
1177,
339,
347,
2341,
63,
765,
8,
277,
12,
2457,
63,
1532,
12,
1083,
63,
354,
12,
627,
589,
12,
1011,
10340,
304,
267,
408,
3315,
323,
1806,
314,
5478,
26750,
1924,
1373,
1159,
909,
1083,
2797,
267,
658,
765,
63,
354,
64,
367,
1263,
2382,
2457,
63,
1532,
342,
2529,
715,
14,
398,
961,
365,
7353,
402,
1808,
520,
5247,
1705,
1130,
64,
543,
2562,
663,
370,
267,
658,
2734,
671,
26,
671,
14,
1113,
14,
765,
63,
354,
11995,
267,
1830,
3769,
1655,
22700,
14,
398,
24873,
4915,
687,
4453,
314,
2797,
1083,
787,
25350,
1536,
267,
436,
6661,
15248,
340,
291,
14,
19432,
63,
1130,
63,
3924,
365,
715,
12,
267,
4257,
2985,
787,
10367,
436,
5525,
14,
398,
2508,
7445,
447,
378,
14,
713,
398,
520,
635,
2457,
63,
1532,
26,
16975,
370,
511,
1924,
3329,
14,
267,
520,
635,
1083,
63,
354,
26,
710,
3329,
1083,
536,
370,
1240,
1169,
367,
1924,
3329,
14,
267,
520,
635,
1249,
26,
4905,
2368,
370,
986,
370,
1083,
267,
520,
635,
16286,
26,
6431,
2368,
370,
986,
370,
1083,
267,
520,
5808,
26,
3820,
402,
1338,
2138,
687,
3102,
267,
408,
267,
372,
291,
14,
1130,
8,
1541,
63,
1532,
12,
291,
423,
1250,
63,
3435,
63,
765,
12,
717,
1083,
63,
354,
12,
627,
589,
12,
1011,
10340,
9,
421,
199,
533,
2812,
20628,
6382,
2988,
8,
20628,
6382,
2988,
304,
272,
408,
30777,
1006,
8963,
436,
4766,
641,
6451,
14,
339,
961,
365,
2997,
367,
1846,
13,
5720,
10358,
626,
1929,
370,
986,
272,
3365,
4153,
370,
3365,
5478,
436,
883,
12610,
314,
536,
272,
402,
314,
5478,
2544,
6358,
3062,
14,
339,
710,
1104,
63,
1532,
1423,
1077,
372,
282,
5046,
12,
543,
1124,
549,
1040,
272,
9297,
626,
314,
3329,
1077,
506,
6511,
436,
6326,
2808,
272,
436,
1124,
797,
1040,
9297,
626,
314,
3329,
1077,
506,
5525,
14,
339,
520,
635,
3231,
26,
710,
3231,
367,
314,
2397,
4501,
14,
272,
520,
466,
3231,
26,
620,
272,
520,
635,
1104,
63,
1532,
26,
6801,
370,
6705,
1314,
5478,
370,
2248,
14,
272,
520,
466,
1104,
63,
1532,
26,
4550,
272,
520,
635,
12677,
63,
265,
63,
912,
26,
9411,
30350,
3775,
370,
12677,
314,
267,
909,
2138,
701,
314,
2397,
2376,
2410,
314,
5253,
365,
6511,
14,
272,
520,
466,
12677,
63,
265,
63,
912,
26,
2155,
272,
520,
635,
12677,
63,
589,
26,
15483,
279,
2368,
370,
986,
1380,
26750,
267,
314,
909,
2138,
701,
314
] |
[
2050,
199,
199,
504,
1275,
3827,
492,
3447,
1909,
6382,
2988,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
28626,
6382,
2988,
8,
6589,
6382,
2988,
304,
272,
408,
30777,
1006,
8963,
436,
4766,
641,
6451,
14,
339,
961,
365,
2997,
367,
1846,
13,
5720,
10358,
626,
1929,
370,
986,
272,
3365,
4153,
370,
3365,
5478,
14,
339,
520,
635,
3231,
26,
710,
3231,
367,
314,
2397,
4501,
14,
272,
520,
466,
3231,
26,
620,
272,
520,
635,
1104,
63,
1532,
26,
6801,
370,
6705,
1314,
5478,
370,
2248,
14,
272,
520,
466,
1104,
63,
1532,
26,
4550,
272,
520,
635,
12677,
63,
265,
63,
912,
26,
9411,
30350,
3775,
370,
12677,
314,
267,
909,
2138,
701,
314,
2397,
2376,
2410,
314,
5253,
365,
6511,
14,
272,
520,
466,
12677,
63,
265,
63,
912,
26,
2155,
272,
520,
635,
12677,
63,
589,
26,
15483,
279,
2368,
370,
986,
1380,
26750,
267,
314,
909,
2138,
701,
314,
2397,
2376,
14,
5972,
1202,
340,
12677,
63,
265,
63,
912,
267,
365,
715,
14,
272,
520,
466,
12677,
63,
589,
26,
2008,
272,
520,
635,
12677,
63,
10340,
26,
16198,
2368,
370,
986,
1380,
26750,
267,
314,
909,
2138,
701,
314,
2397,
2376,
14,
5972,
1202,
340,
12677,
63,
265,
63,
912,
267,
365,
715,
14,
272,
520,
466,
12677,
63,
10340,
26,
1211,
272,
520,
635,
19843,
63,
1130,
63,
3924,
26,
9411,
30350,
3775,
4967,
267,
787,
25350,
1536,
4012,
314,
2341,
1240,
503,
3775,
2985,
787,
10367,
436,
267,
2066,
5525,
272,
520,
466,
12677,
63,
265,
63,
912,
26,
2155,
272,
408,
339,
347,
2341,
8,
277,
12,
2457,
63,
1532,
12,
2562,
12,
627,
589,
12,
1011,
10340,
304,
267,
408,
3315,
323,
1806,
314,
5478,
26750,
2562,
342,
367,
1263,
2382,
267,
2457,
63,
1532,
342,
2529,
715,
14,
398,
710,
4955,
402,
2457,
63,
1532,
342,
1077,
506,
447,
953,
347,
2457,
63,
1532,
8,
832,
12,
627,
589,
12,
1011,
10340,
304,
355,
986,
398,
710,
1642,
1423,
370,
2457,
63,
1532,
1062,
283,
832,
297,
365,
314,
267,
520,
533,
6054,
1597,
1354,
720,
14,
3435,
14,
6382,
64,
267,
1256,
14,
2457,
63,
1532,
342,
1077,
372,
715,
340,
314,
3329,
267,
1077,
506,
10302,
367,
314,
1324,
2368,
14,
398,
710,
4955,
367,
2562,
342,
1077,
506,
447,
953,
347,
2562,
8,
832,
12,
627,
589,
12,
1011,
10340,
304,
355,
986,
398,
710,
1642,
1423,
370,
2562,
1062,
283,
832,
297,
365,
314,
267,
520,
533,
6054,
1597,
1354,
720,
14,
3435,
14,
6382,
64,
1256,
14,
398,
24873,
4915,
687,
4453,
2562,
342,
787,
25350,
1536,
436,
267,
6661,
15248,
340,
291,
14,
19432,
63,
1130,
63,
3924,
365,
715,
12,
267,
4257,
2985,
787,
10367,
436,
5525,
14,
398,
520,
635,
2457,
63,
1532,
26,
16975,
370,
511,
1924,
3329,
14,
267,
520,
635,
2562,
26,
16975,
370,
12677,
367,
1924,
3329,
14,
267,
520,
635,
1249,
26,
4905,
2368,
370,
986,
370,
2562,
342,
267,
520,
635,
16286,
26,
6431,
2368,
370,
986,
370,
2562,
342,
267,
520,
5808,
26,
3820,
402,
1338,
2138,
687,
2562,
342,
267,
408,
267,
340,
440,
291,
14,
5359,
26,
288,
327,
7600,
26,
3645,
282,
1655,
2488,
1919,
1021,
2348,
14,
288,
746,
6064,
360,
1944,
450,
83,
5478,
1911,
7,
450,
291,
14,
3251,
9,
267,
1177,
275,
942,
267,
367,
325,
315,
291,
14,
5359,
26,
288,
340,
2457,
63,
1532,
8,
69,
12,
627,
589,
12,
1011,
10340,
304,
355,
291,
423,
15195,
63,
368,
63,
2718,
8,
1310,
14,
740,
12,
2562,
12,
325,
12,
1249,
12,
16286,
9,
267,
372,
1177,
339,
347,
2341,
63,
765,
8,
277,
12,
2457,
63,
1532,
12,
1083,
63,
354,
12,
627,
589,
12,
1011,
10340,
304,
267,
408,
3315,
323,
1806,
314,
5478,
26750,
1924,
1373,
1159,
909,
1083,
2797,
267,
658,
765,
63,
354,
64,
367,
1263,
2382,
2457,
63,
1532,
342,
2529,
715,
14,
398,
961,
365,
7353,
402,
1808,
520,
5247,
1705,
1130,
64,
543,
2562,
663,
370,
267,
658,
2734,
671,
26,
671,
14,
1113,
14,
765,
63,
354,
11995,
267,
1830,
3769,
1655,
22700,
14,
398,
24873,
4915,
687,
4453,
314,
2797,
1083,
787,
25350,
1536,
267,
436,
6661,
15248,
340,
291,
14,
19432,
63,
1130,
63,
3924,
365,
715,
12,
267,
4257,
2985,
787,
10367,
436,
5525,
14,
398,
2508,
7445,
447,
378,
14,
713,
398,
520,
635,
2457,
63,
1532,
26,
16975,
370,
511,
1924,
3329,
14,
267,
520,
635,
1083,
63,
354,
26,
710,
3329,
1083,
536,
370,
1240,
1169,
367,
1924,
3329,
14,
267,
520,
635,
1249,
26,
4905,
2368,
370,
986,
370,
1083,
267,
520,
635,
16286,
26,
6431,
2368,
370,
986,
370,
1083,
267,
520,
5808,
26,
3820,
402,
1338,
2138,
687,
3102,
267,
408,
267,
372,
291,
14,
1130,
8,
1541,
63,
1532,
12,
291,
423,
1250,
63,
3435,
63,
765,
12,
717,
1083,
63,
354,
12,
627,
589,
12,
1011,
10340,
9,
421,
199,
533,
2812,
20628,
6382,
2988,
8,
20628,
6382,
2988,
304,
272,
408,
30777,
1006,
8963,
436,
4766,
641,
6451,
14,
339,
961,
365,
2997,
367,
1846,
13,
5720,
10358,
626,
1929,
370,
986,
272,
3365,
4153,
370,
3365,
5478,
436,
883,
12610,
314,
536,
272,
402,
314,
5478,
2544,
6358,
3062,
14,
339,
710,
1104,
63,
1532,
1423,
1077,
372,
282,
5046,
12,
543,
1124,
549,
1040,
272,
9297,
626,
314,
3329,
1077,
506,
6511,
436,
6326,
2808,
272,
436,
1124,
797,
1040,
9297,
626,
314,
3329,
1077,
506,
5525,
14,
339,
520,
635,
3231,
26,
710,
3231,
367,
314,
2397,
4501,
14,
272,
520,
466,
3231,
26,
620,
272,
520,
635,
1104,
63,
1532,
26,
6801,
370,
6705,
1314,
5478,
370,
2248,
14,
272,
520,
466,
1104,
63,
1532,
26,
4550,
272,
520,
635,
12677,
63,
265,
63,
912,
26,
9411,
30350,
3775,
370,
12677,
314,
267,
909,
2138,
701,
314,
2397,
2376,
2410,
314,
5253,
365,
6511,
14,
272,
520,
466,
12677,
63,
265,
63,
912,
26,
2155,
272,
520,
635,
12677,
63,
589,
26,
15483,
279,
2368,
370,
986,
1380,
26750,
267,
314,
909,
2138,
701,
314,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
maciek263/django2
|
myvenv/Lib/site-packages/django/db/models/deletion.py
|
83
|
13766
|
from collections import OrderedDict
from itertools import chain
from operator import attrgetter
from django.db import IntegrityError, connections, transaction
from django.db.models import signals, sql
from django.utils import six
class ProtectedError(IntegrityError):
def __init__(self, msg, protected_objects):
self.protected_objects = protected_objects
super(ProtectedError, self).__init__(msg, protected_objects)
def CASCADE(collector, field, sub_objs, using):
collector.collect(sub_objs, source=field.rel.to,
source_attr=field.name, nullable=field.null)
if field.null and not connections[using].features.can_defer_constraint_checks:
collector.add_field_update(field, None, sub_objs)
def PROTECT(collector, field, sub_objs, using):
raise ProtectedError("Cannot delete some instances of model '%s' because "
"they are referenced through a protected foreign key: '%s.%s'" % (
field.rel.to.__name__, sub_objs[0].__class__.__name__, field.name
),
sub_objs
)
def SET(value):
if callable(value):
def set_on_delete(collector, field, sub_objs, using):
collector.add_field_update(field, value(), sub_objs)
else:
def set_on_delete(collector, field, sub_objs, using):
collector.add_field_update(field, value, sub_objs)
set_on_delete.deconstruct = lambda: ('django.db.models.SET', (value,), {})
return set_on_delete
def SET_NULL(collector, field, sub_objs, using):
collector.add_field_update(field, None, sub_objs)
def SET_DEFAULT(collector, field, sub_objs, using):
collector.add_field_update(field, field.get_default(), sub_objs)
def DO_NOTHING(collector, field, sub_objs, using):
pass
def get_candidate_relations_to_delete(opts):
# Collect models that contain candidate relations to delete. This may include
# relations coming from proxy models.
candidate_models = {opts}
candidate_models = candidate_models.union(opts.concrete_model._meta.proxied_children)
# For each model, get all candidate fields.
candidate_model_fields = chain.from_iterable(
opts.get_fields(include_hidden=True) for opts in candidate_models
)
# The candidate relations are the ones that come from N-1 and 1-1 relations.
# N-N (i.e., many-to-many) relations aren't candidates for deletion.
return (
f for f in candidate_model_fields
if f.auto_created and not f.concrete and (f.one_to_one or f.one_to_many)
)
class Collector(object):
def __init__(self, using):
self.using = using
# Initially, {model: {instances}}, later values become lists.
self.data = {}
self.field_updates = {} # {model: {(field, value): {instances}}}
# fast_deletes is a list of queryset-likes that can be deleted without
# fetching the objects into memory.
self.fast_deletes = []
# Tracks deletion-order dependency for databases without transactions
# or ability to defer constraint checks. Only concrete model classes
# should be included, as the dependencies exist only between actual
# database tables; proxy models are represented here by their concrete
# parent.
self.dependencies = {} # {model: {models}}
def add(self, objs, source=None, nullable=False, reverse_dependency=False):
"""
Adds 'objs' to the collection of objects to be deleted. If the call is
the result of a cascade, 'source' should be the model that caused it,
and 'nullable' should be set to True if the relation can be null.
Returns a list of all objects that were not already collected.
"""
if not objs:
return []
new_objs = []
model = objs[0].__class__
instances = self.data.setdefault(model, set())
for obj in objs:
if obj not in instances:
new_objs.append(obj)
instances.update(new_objs)
# Nullable relationships can be ignored -- they are nulled out before
# deleting, and therefore do not affect the order in which objects have
# to be deleted.
if source is not None and not nullable:
if reverse_dependency:
source, model = model, source
self.dependencies.setdefault(
source._meta.concrete_model, set()).add(model._meta.concrete_model)
return new_objs
def add_field_update(self, field, value, objs):
"""
Schedules a field update. 'objs' must be a homogeneous iterable
collection of model instances (e.g. a QuerySet).
"""
if not objs:
return
model = objs[0].__class__
self.field_updates.setdefault(
model, {}).setdefault(
(field, value), set()).update(objs)
def can_fast_delete(self, objs, from_field=None):
"""
Determines if the objects in the given queryset-like can be
fast-deleted. This can be done if there are no cascades, no
parents and no signal listeners for the object class.
The 'from_field' tells where we are coming from - we need this to
determine if the objects are in fact to be deleted. Allows also
skipping parent -> child -> parent chain preventing fast delete of
the child.
"""
if from_field and from_field.rel.on_delete is not CASCADE:
return False
if not (hasattr(objs, 'model') and hasattr(objs, '_raw_delete')):
return False
model = objs.model
if (signals.pre_delete.has_listeners(model)
or signals.post_delete.has_listeners(model)
or signals.m2m_changed.has_listeners(model)):
return False
# The use of from_field comes from the need to avoid cascade back to
# parent when parent delete is cascading to child.
opts = model._meta
if any(link != from_field for link in opts.concrete_model._meta.parents.values()):
return False
# Foreign keys pointing to this model, both from m2m and other
# models.
for related in get_candidate_relations_to_delete(opts):
if related.field.rel.on_delete is not DO_NOTHING:
return False
for field in model._meta.virtual_fields:
if hasattr(field, 'bulk_related_objects'):
# It's something like generic foreign key.
return False
return True
def get_del_batches(self, objs, field):
"""
Returns the objs in suitably sized batches for the used connection.
"""
conn_batch_size = max(
connections[self.using].ops.bulk_batch_size([field.name], objs), 1)
if len(objs) > conn_batch_size:
return [objs[i:i + conn_batch_size]
for i in range(0, len(objs), conn_batch_size)]
else:
return [objs]
def collect(self, objs, source=None, nullable=False, collect_related=True,
source_attr=None, reverse_dependency=False):
"""
Adds 'objs' to the collection of objects to be deleted as well as all
parent instances. 'objs' must be a homogeneous iterable collection of
model instances (e.g. a QuerySet). If 'collect_related' is True,
related objects will be handled by their respective on_delete handler.
If the call is the result of a cascade, 'source' should be the model
that caused it and 'nullable' should be set to True, if the relation
can be null.
If 'reverse_dependency' is True, 'source' will be deleted before the
current model, rather than after. (Needed for cascading to parent
models, the one case in which the cascade follows the forwards
direction of an FK rather than the reverse direction.)
"""
if self.can_fast_delete(objs):
self.fast_deletes.append(objs)
return
new_objs = self.add(objs, source, nullable,
reverse_dependency=reverse_dependency)
if not new_objs:
return
model = new_objs[0].__class__
# Recursively collect concrete model's parent models, but not their
# related objects. These will be found by meta.get_fields()
concrete_model = model._meta.concrete_model
for ptr in six.itervalues(concrete_model._meta.parents):
if ptr:
# FIXME: This seems to be buggy and execute a query for each
# parent object fetch. We have the parent data in the obj,
# but we don't have a nice way to turn that data into parent
# object instance.
parent_objs = [getattr(obj, ptr.name) for obj in new_objs]
self.collect(parent_objs, source=model,
source_attr=ptr.rel.related_name,
collect_related=False,
reverse_dependency=True)
if collect_related:
for related in get_candidate_relations_to_delete(model._meta):
field = related.field
if field.rel.on_delete == DO_NOTHING:
continue
batches = self.get_del_batches(new_objs, field)
for batch in batches:
sub_objs = self.related_objects(related, batch)
if self.can_fast_delete(sub_objs, from_field=field):
self.fast_deletes.append(sub_objs)
elif sub_objs:
field.rel.on_delete(self, field, sub_objs, self.using)
for field in model._meta.virtual_fields:
if hasattr(field, 'bulk_related_objects'):
# Its something like generic foreign key.
sub_objs = field.bulk_related_objects(new_objs, self.using)
self.collect(sub_objs,
source=model,
source_attr=field.rel.related_name,
nullable=True)
def related_objects(self, related, objs):
"""
Gets a QuerySet of objects related to ``objs`` via the relation ``related``.
"""
return related.related_model._base_manager.using(self.using).filter(
**{"%s__in" % related.field.name: objs}
)
def instances_with_model(self):
for model, instances in six.iteritems(self.data):
for obj in instances:
yield model, obj
def sort(self):
sorted_models = []
concrete_models = set()
models = list(self.data)
while len(sorted_models) < len(models):
found = False
for model in models:
if model in sorted_models:
continue
dependencies = self.dependencies.get(model._meta.concrete_model)
if not (dependencies and dependencies.difference(concrete_models)):
sorted_models.append(model)
concrete_models.add(model._meta.concrete_model)
found = True
if not found:
return
self.data = OrderedDict((model, self.data[model])
for model in sorted_models)
def delete(self):
# sort instance collections
for model, instances in self.data.items():
self.data[model] = sorted(instances, key=attrgetter("pk"))
# if possible, bring the models in an order suitable for databases that
# don't support transactions or cannot defer constraint checks until the
# end of a transaction.
self.sort()
with transaction.atomic(using=self.using, savepoint=False):
# send pre_delete signals
for model, obj in self.instances_with_model():
if not model._meta.auto_created:
signals.pre_delete.send(
sender=model, instance=obj, using=self.using
)
# fast deletes
for qs in self.fast_deletes:
qs._raw_delete(using=self.using)
# update fields
for model, instances_for_fieldvalues in six.iteritems(self.field_updates):
query = sql.UpdateQuery(model)
for (field, value), instances in six.iteritems(instances_for_fieldvalues):
query.update_batch([obj.pk for obj in instances],
{field.name: value}, self.using)
# reverse instance collections
for instances in six.itervalues(self.data):
instances.reverse()
# delete instances
for model, instances in six.iteritems(self.data):
query = sql.DeleteQuery(model)
pk_list = [obj.pk for obj in instances]
query.delete_batch(pk_list, self.using)
if not model._meta.auto_created:
for obj in instances:
signals.post_delete.send(
sender=model, instance=obj, using=self.using
)
# update collected instances
for model, instances_for_fieldvalues in six.iteritems(self.field_updates):
for (field, value), instances in six.iteritems(instances_for_fieldvalues):
for obj in instances:
setattr(obj, field.attname, value)
for model, instances in six.iteritems(self.data):
for instance in instances:
setattr(instance, model._meta.pk.attname, None)
|
mit
|
[
504,
5055,
492,
8773,
199,
504,
7975,
492,
6036,
199,
504,
4182,
492,
21829,
199,
199,
504,
1639,
14,
697,
492,
26864,
12,
6947,
12,
6008,
199,
504,
1639,
14,
697,
14,
992,
492,
10166,
12,
3875,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
533,
2165,
4530,
547,
8,
24823,
304,
272,
347,
636,
826,
721,
277,
12,
1499,
12,
17819,
63,
1462,
304,
267,
291,
14,
6798,
63,
1462,
275,
17819,
63,
1462,
267,
1613,
8,
919,
4530,
547,
12,
291,
2843,
826,
721,
1328,
12,
17819,
63,
1462,
9,
421,
199,
318,
27751,
9947,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
272,
14910,
14,
7112,
8,
954,
63,
8718,
12,
1350,
29,
698,
14,
3369,
14,
475,
12,
1993,
1350,
63,
962,
29,
698,
14,
354,
12,
7854,
29,
698,
14,
2307,
9,
272,
340,
901,
14,
2307,
436,
440,
6947,
59,
4941,
1055,
3179,
14,
2425,
63,
11610,
63,
5631,
63,
8625,
26,
267,
14910,
14,
525,
63,
698,
63,
873,
8,
698,
12,
488,
12,
1007,
63,
8718,
9,
421,
199,
318,
3611,
52,
3582,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
272,
746,
2165,
4530,
547,
480,
6612,
3145,
2005,
4454,
402,
1402,
1543,
83,
7,
2952,
298,
267,
298,
29002,
787,
11812,
4012,
282,
17819,
11608,
790,
26,
1543,
83,
4111,
83,
4065,
450,
334,
288,
901,
14,
3369,
14,
475,
855,
354,
3108,
1007,
63,
8718,
59,
16,
17979,
533,
4914,
354,
3108,
901,
14,
354,
267,
2318,
267,
1007,
63,
8718,
272,
776,
421,
199,
318,
11543,
8,
585,
304,
272,
340,
4550,
8,
585,
304,
267,
347,
663,
63,
265,
63,
1807,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
288,
14910,
14,
525,
63,
698,
63,
873,
8,
698,
12,
574,
1062,
1007,
63,
8718,
9,
272,
587,
26,
267,
347,
663,
63,
265,
63,
1807,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
288,
14910,
14,
525,
63,
698,
63,
873,
8,
698,
12,
574,
12,
1007,
63,
8718,
9,
272,
663,
63,
265,
63,
1807,
14,
23693,
275,
2400,
26,
661,
1176,
14,
697,
14,
992,
14,
3597,
297,
334,
585,
4706,
5009,
272,
372,
663,
63,
265,
63,
1807,
421,
199,
318,
11543,
63,
8084,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
272,
14910,
14,
525,
63,
698,
63,
873,
8,
698,
12,
488,
12,
1007,
63,
8718,
9,
421,
199,
318,
11543,
63,
3472,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
272,
14910,
14,
525,
63,
698,
63,
873,
8,
698,
12,
901,
14,
362,
63,
885,
1062,
1007,
63,
8718,
9,
421,
199,
318,
3506,
63,
4609,
40,
1206,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
272,
986,
421,
199,
318,
664,
63,
9007,
63,
15741,
63,
475,
63,
1807,
8,
3291,
304,
272,
327,
19649,
1709,
626,
1395,
7627,
16109,
370,
3145,
14,
961,
1443,
2387,
272,
327,
16109,
17262,
687,
4566,
1709,
14,
272,
7627,
63,
992,
275,
469,
3291,
93,
272,
7627,
63,
992,
275,
7627,
63,
992,
14,
8888,
8,
3291,
14,
13455,
63,
1238,
423,
2024,
14,
8221,
5299,
63,
3223,
9,
272,
327,
2104,
1924,
1402,
12,
664,
1006,
7627,
1504,
14,
272,
7627,
63,
1238,
63,
955,
275,
6036,
14,
504,
63,
8147,
8,
267,
3999,
14,
362,
63,
955,
8,
2613,
63,
5642,
29,
549,
9,
367,
3999,
315,
7627,
63,
992,
272,
776,
272,
327,
710,
7627,
16109,
787,
314,
7869,
626,
11492,
687,
653,
13,
17,
436,
413,
13,
17,
16109,
14,
272,
327,
653,
13,
46,
221,
334,
73,
14,
69,
2020,
5002,
13,
475,
13,
3479,
9,
16109,
10621,
1133,
15101,
367,
14068,
14,
272,
372,
334,
267,
289,
367,
289,
315,
7627,
63,
1238,
63,
955,
267,
340,
289,
14,
2495,
63,
3966,
436,
440,
289,
14,
13455,
436,
334,
70,
14,
368,
63,
475,
63,
368,
503,
289,
14,
368,
63,
475,
63,
3479,
9,
272,
776,
421,
199,
533,
3626,
3283,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1808,
304,
267,
291,
14,
4941,
275,
1808,
267,
327,
21412,
1183,
12,
469,
1238,
26,
469,
5990,
13459,
2945,
1338,
8649,
5548,
14,
267,
291,
14,
576,
275,
1052,
267,
291,
14,
698,
63,
7618,
275,
1052,
221,
327,
469,
1238,
26,
26458,
698,
12,
574,
304,
469,
5990,
4863,
93,
267,
327,
7377,
63,
26289,
365,
282,
769,
402,
7594,
13,
29572,
626,
883,
506,
5463,
1928,
267,
327,
21239,
314,
2251,
1901,
4402,
14,
267,
291,
14,
7015,
63,
26289,
275,
942,
398,
327,
12643,
5618,
14068,
13,
1648,
5936,
367,
16219,
1928,
15809,
267,
327,
503,
21255,
370,
10133,
5828,
5920,
14,
5972,
13801,
1402,
3992,
267,
327,
1077,
506,
5120,
12,
465,
314,
5124,
2187,
1454,
3382,
3503,
267,
327,
3050,
6716,
27,
4566,
1709,
787,
11159,
2348,
701,
3932,
13801,
267,
327,
1676,
14,
267,
291,
14,
5714,
275,
1052,
221,
327,
469,
1238,
26,
469,
992,
4863,
339,
347,
1050,
8,
277,
12,
13474,
12,
1350,
29,
403,
12,
7854,
29,
797,
12,
3837,
63,
8575,
29,
797,
304,
267,
408,
267,
15747,
283,
8718,
7,
370,
314,
3245,
402,
2251,
370,
506,
5463,
14,
221,
982,
314,
1240,
365,
267,
314,
754,
402,
282,
22809,
12,
283,
1365,
7,
1077,
506,
314,
1402,
626,
18104,
652,
12,
267,
436,
283,
16375,
7,
1077,
506,
663,
370,
715,
340,
314,
5850,
883,
506,
2973,
14,
398,
1803,
282,
769,
402,
1006,
2251,
626,
4898,
440,
2575,
13736,
14,
267,
408,
267,
340,
440,
13474,
26,
288,
372,
942,
267,
892,
63,
8718,
275,
942,
267,
1402,
275,
13474,
59,
16,
17979,
533,
363,
267,
4454,
275,
291,
14,
576,
14,
5486,
8,
1238,
12,
663,
1012,
267,
367,
1559,
315,
13474,
26,
288,
340,
1559,
440,
315,
4454,
26,
355,
892,
63,
8718,
14,
740,
8,
1113,
9,
267,
4454,
14,
873,
8,
1222,
63,
8718,
9,
267,
327,
12119,
461,
20045,
883,
506,
5525,
1553,
2985,
787,
302,
348,
1146,
734,
2544,
267,
327,
13794,
12,
436
] |
[
5055,
492,
8773,
199,
504,
7975,
492,
6036,
199,
504,
4182,
492,
21829,
199,
199,
504,
1639,
14,
697,
492,
26864,
12,
6947,
12,
6008,
199,
504,
1639,
14,
697,
14,
992,
492,
10166,
12,
3875,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
533,
2165,
4530,
547,
8,
24823,
304,
272,
347,
636,
826,
721,
277,
12,
1499,
12,
17819,
63,
1462,
304,
267,
291,
14,
6798,
63,
1462,
275,
17819,
63,
1462,
267,
1613,
8,
919,
4530,
547,
12,
291,
2843,
826,
721,
1328,
12,
17819,
63,
1462,
9,
421,
199,
318,
27751,
9947,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
272,
14910,
14,
7112,
8,
954,
63,
8718,
12,
1350,
29,
698,
14,
3369,
14,
475,
12,
1993,
1350,
63,
962,
29,
698,
14,
354,
12,
7854,
29,
698,
14,
2307,
9,
272,
340,
901,
14,
2307,
436,
440,
6947,
59,
4941,
1055,
3179,
14,
2425,
63,
11610,
63,
5631,
63,
8625,
26,
267,
14910,
14,
525,
63,
698,
63,
873,
8,
698,
12,
488,
12,
1007,
63,
8718,
9,
421,
199,
318,
3611,
52,
3582,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
272,
746,
2165,
4530,
547,
480,
6612,
3145,
2005,
4454,
402,
1402,
1543,
83,
7,
2952,
298,
267,
298,
29002,
787,
11812,
4012,
282,
17819,
11608,
790,
26,
1543,
83,
4111,
83,
4065,
450,
334,
288,
901,
14,
3369,
14,
475,
855,
354,
3108,
1007,
63,
8718,
59,
16,
17979,
533,
4914,
354,
3108,
901,
14,
354,
267,
2318,
267,
1007,
63,
8718,
272,
776,
421,
199,
318,
11543,
8,
585,
304,
272,
340,
4550,
8,
585,
304,
267,
347,
663,
63,
265,
63,
1807,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
288,
14910,
14,
525,
63,
698,
63,
873,
8,
698,
12,
574,
1062,
1007,
63,
8718,
9,
272,
587,
26,
267,
347,
663,
63,
265,
63,
1807,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
288,
14910,
14,
525,
63,
698,
63,
873,
8,
698,
12,
574,
12,
1007,
63,
8718,
9,
272,
663,
63,
265,
63,
1807,
14,
23693,
275,
2400,
26,
661,
1176,
14,
697,
14,
992,
14,
3597,
297,
334,
585,
4706,
5009,
272,
372,
663,
63,
265,
63,
1807,
421,
199,
318,
11543,
63,
8084,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
272,
14910,
14,
525,
63,
698,
63,
873,
8,
698,
12,
488,
12,
1007,
63,
8718,
9,
421,
199,
318,
11543,
63,
3472,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
272,
14910,
14,
525,
63,
698,
63,
873,
8,
698,
12,
901,
14,
362,
63,
885,
1062,
1007,
63,
8718,
9,
421,
199,
318,
3506,
63,
4609,
40,
1206,
8,
10946,
12,
901,
12,
1007,
63,
8718,
12,
1808,
304,
272,
986,
421,
199,
318,
664,
63,
9007,
63,
15741,
63,
475,
63,
1807,
8,
3291,
304,
272,
327,
19649,
1709,
626,
1395,
7627,
16109,
370,
3145,
14,
961,
1443,
2387,
272,
327,
16109,
17262,
687,
4566,
1709,
14,
272,
7627,
63,
992,
275,
469,
3291,
93,
272,
7627,
63,
992,
275,
7627,
63,
992,
14,
8888,
8,
3291,
14,
13455,
63,
1238,
423,
2024,
14,
8221,
5299,
63,
3223,
9,
272,
327,
2104,
1924,
1402,
12,
664,
1006,
7627,
1504,
14,
272,
7627,
63,
1238,
63,
955,
275,
6036,
14,
504,
63,
8147,
8,
267,
3999,
14,
362,
63,
955,
8,
2613,
63,
5642,
29,
549,
9,
367,
3999,
315,
7627,
63,
992,
272,
776,
272,
327,
710,
7627,
16109,
787,
314,
7869,
626,
11492,
687,
653,
13,
17,
436,
413,
13,
17,
16109,
14,
272,
327,
653,
13,
46,
221,
334,
73,
14,
69,
2020,
5002,
13,
475,
13,
3479,
9,
16109,
10621,
1133,
15101,
367,
14068,
14,
272,
372,
334,
267,
289,
367,
289,
315,
7627,
63,
1238,
63,
955,
267,
340,
289,
14,
2495,
63,
3966,
436,
440,
289,
14,
13455,
436,
334,
70,
14,
368,
63,
475,
63,
368,
503,
289,
14,
368,
63,
475,
63,
3479,
9,
272,
776,
421,
199,
533,
3626,
3283,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1808,
304,
267,
291,
14,
4941,
275,
1808,
267,
327,
21412,
1183,
12,
469,
1238,
26,
469,
5990,
13459,
2945,
1338,
8649,
5548,
14,
267,
291,
14,
576,
275,
1052,
267,
291,
14,
698,
63,
7618,
275,
1052,
221,
327,
469,
1238,
26,
26458,
698,
12,
574,
304,
469,
5990,
4863,
93,
267,
327,
7377,
63,
26289,
365,
282,
769,
402,
7594,
13,
29572,
626,
883,
506,
5463,
1928,
267,
327,
21239,
314,
2251,
1901,
4402,
14,
267,
291,
14,
7015,
63,
26289,
275,
942,
398,
327,
12643,
5618,
14068,
13,
1648,
5936,
367,
16219,
1928,
15809,
267,
327,
503,
21255,
370,
10133,
5828,
5920,
14,
5972,
13801,
1402,
3992,
267,
327,
1077,
506,
5120,
12,
465,
314,
5124,
2187,
1454,
3382,
3503,
267,
327,
3050,
6716,
27,
4566,
1709,
787,
11159,
2348,
701,
3932,
13801,
267,
327,
1676,
14,
267,
291,
14,
5714,
275,
1052,
221,
327,
469,
1238,
26,
469,
992,
4863,
339,
347,
1050,
8,
277,
12,
13474,
12,
1350,
29,
403,
12,
7854,
29,
797,
12,
3837,
63,
8575,
29,
797,
304,
267,
408,
267,
15747,
283,
8718,
7,
370,
314,
3245,
402,
2251,
370,
506,
5463,
14,
221,
982,
314,
1240,
365,
267,
314,
754,
402,
282,
22809,
12,
283,
1365,
7,
1077,
506,
314,
1402,
626,
18104,
652,
12,
267,
436,
283,
16375,
7,
1077,
506,
663,
370,
715,
340,
314,
5850,
883,
506,
2973,
14,
398,
1803,
282,
769,
402,
1006,
2251,
626,
4898,
440,
2575,
13736,
14,
267,
408,
267,
340,
440,
13474,
26,
288,
372,
942,
267,
892,
63,
8718,
275,
942,
267,
1402,
275,
13474,
59,
16,
17979,
533,
363,
267,
4454,
275,
291,
14,
576,
14,
5486,
8,
1238,
12,
663,
1012,
267,
367,
1559,
315,
13474,
26,
288,
340,
1559,
440,
315,
4454,
26,
355,
892,
63,
8718,
14,
740,
8,
1113,
9,
267,
4454,
14,
873,
8,
1222,
63,
8718,
9,
267,
327,
12119,
461,
20045,
883,
506,
5525,
1553,
2985,
787,
302,
348,
1146,
734,
2544,
267,
327,
13794,
12,
436,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Sheeo/pygit2
|
test/test_diff.py
|
2
|
12085
|
# -*- coding: UTF-8 -*-
#
# Copyright 2010-2015 The pygit2 contributors
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License, version 2,
# as published by the Free Software Foundation.
#
# In addition to the permissions in the GNU General Public License,
# the authors give you unlimited permission to link the compiled
# version of this file into combinations with other programs,
# and to distribute those combinations without any restriction
# coming from the use of this file. (The General Public License
# restrictions do apply in other respects; for example, they cover
# modification of the file, and distribution when not linked into
# a combined executable.)
#
# This file 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; see the file COPYING. If not, write to
# the Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
"""Tests for Diff objects."""
from __future__ import absolute_import
from __future__ import unicode_literals
import unittest
import pygit2
from pygit2 import GIT_DIFF_INCLUDE_UNMODIFIED
from pygit2 import GIT_DIFF_IGNORE_WHITESPACE, GIT_DIFF_IGNORE_WHITESPACE_EOL
from pygit2 import GIT_DIFF_SHOW_BINARY
from pygit2 import GIT_DELTA_RENAMED
from . import utils
from itertools import chain
COMMIT_SHA1_1 = '5fe808e8953c12735680c257f56600cb0de44b10'
COMMIT_SHA1_2 = 'c2792cfa289ae6321ecf2cd5806c2194b0fd070c'
COMMIT_SHA1_3 = '2cdae28389c059815e951d0bb9eed6533f61a46b'
COMMIT_SHA1_4 = 'ccca47fbb26183e71a7a46d165299b84e2e6c0b3'
COMMIT_SHA1_5 = '056e626e51b1fc1ee2182800e399ed8d84c8f082'
COMMIT_SHA1_6 = 'f5e5aa4e36ab0fe62ee1ccc6eb8f79b866863b87'
COMMIT_SHA1_7 = '784855caf26449a1914d2cf62d12b9374d76ae78'
PATCH = """diff --git a/a b/a
index 7f129fd..af431f2 100644
--- a/a
+++ b/a
@@ -1 +1 @@
-a contents 2
+a contents
diff --git a/c/d b/c/d
deleted file mode 100644
index 297efb8..0000000
--- a/c/d
+++ /dev/null
@@ -1 +0,0 @@
-c/d contents
"""
PATCH_BINARY = """diff --git a/binary_file b/binary_file
index 86e5c10..b835d73 100644
Binary files a/binary_file and b/binary_file differ
"""
PATCH_BINARY_SHOW = """diff --git a/binary_file b/binary_file
index 86e5c1008b5ce635d3e3fffa4434c5eccd8f00b6..b835d73543244b6694f36a8c5dfdffb71b153db7 100644
GIT binary patch
literal 8
Pc${NM%FIhFs^kIy3n&7R
literal 8
Pc${NM&PdElPvrst3ey5{
"""
DIFF_HEAD_TO_INDEX_EXPECTED = [
'staged_changes',
'staged_changes_file_deleted',
'staged_changes_file_modified',
'staged_delete',
'staged_delete_file_modified',
'staged_new',
'staged_new_file_deleted',
'staged_new_file_modified'
]
DIFF_HEAD_TO_WORKDIR_EXPECTED = [
'file_deleted',
'modified_file',
'staged_changes',
'staged_changes_file_deleted',
'staged_changes_file_modified',
'staged_delete',
'staged_delete_file_modified',
'subdir/deleted_file',
'subdir/modified_file'
]
DIFF_INDEX_TO_WORK_EXPECTED = [
'file_deleted',
'modified_file',
'staged_changes_file_deleted',
'staged_changes_file_modified',
'staged_new_file_deleted',
'staged_new_file_modified',
'subdir/deleted_file',
'subdir/modified_file'
]
HUNK_EXPECTED = """- a contents 2
+ a contents
"""
STATS_EXPECTED = """ a | 2 +-
c/d | 1 -
2 files changed, 1 insertion(+), 2 deletions(-)
delete mode 100644 c/d
"""
class DiffDirtyTest(utils.DirtyRepoTestCase):
def test_diff_empty_index(self):
repo = self.repo
head = repo[repo.lookup_reference('HEAD').resolve().target]
diff = head.tree.diff_to_index(repo.index)
files = [patch.delta.new_file.path for patch in diff]
self.assertEqual(DIFF_HEAD_TO_INDEX_EXPECTED, files)
diff = repo.diff('HEAD', cached=True)
files = [patch.delta.new_file.path for patch in diff]
self.assertEqual(DIFF_HEAD_TO_INDEX_EXPECTED, files)
def test_workdir_to_tree(self):
repo = self.repo
head = repo[repo.lookup_reference('HEAD').resolve().target]
diff = head.tree.diff_to_workdir()
files = [patch.delta.new_file.path for patch in diff]
self.assertEqual(DIFF_HEAD_TO_WORKDIR_EXPECTED, files)
diff = repo.diff('HEAD')
files = [patch.delta.new_file.path for patch in diff]
self.assertEqual(DIFF_HEAD_TO_WORKDIR_EXPECTED, files)
def test_index_to_workdir(self):
diff = self.repo.diff()
files = [patch.delta.new_file.path for patch in diff]
self.assertEqual(DIFF_INDEX_TO_WORK_EXPECTED, files)
class DiffTest(utils.BareRepoTestCase):
def test_diff_invalid(self):
commit_a = self.repo[COMMIT_SHA1_1]
commit_b = self.repo[COMMIT_SHA1_2]
self.assertRaises(TypeError, commit_a.tree.diff_to_tree, commit_b)
self.assertRaises(TypeError, commit_a.tree.diff_to_index, commit_b)
def test_diff_empty_index(self):
repo = self.repo
head = repo[repo.lookup_reference('HEAD').resolve().target]
diff = self.repo.index.diff_to_tree(head.tree)
files = [patch.delta.new_file.path.split('/')[0] for patch in diff]
self.assertEqual([x.name for x in head.tree], files)
diff = head.tree.diff_to_index(repo.index)
files = [patch.delta.new_file.path.split('/')[0] for patch in diff]
self.assertEqual([x.name for x in head.tree], files)
diff = repo.diff('HEAD', cached=True)
files = [patch.delta.new_file.path.split('/')[0] for patch in diff]
self.assertEqual([x.name for x in head.tree], files)
def test_diff_tree(self):
commit_a = self.repo[COMMIT_SHA1_1]
commit_b = self.repo[COMMIT_SHA1_2]
def _test(diff):
# self.assertIsNotNone is 2.7 only
self.assertTrue(diff is not None)
# self.assertIn is 2.7 only
self.assertEqual(2, sum(map(lambda x: len(x.hunks), diff)))
patch = diff[0]
hunk = patch.hunks[0]
self.assertEqual(hunk.old_start, 1)
self.assertEqual(hunk.old_lines, 1)
self.assertEqual(hunk.new_start, 1)
self.assertEqual(hunk.new_lines, 1)
self.assertEqual(patch.delta.old_file.path, 'a')
self.assertEqual(patch.delta.new_file.path, 'a')
self.assertEqual(patch.delta.is_binary, False)
_test(commit_a.tree.diff_to_tree(commit_b.tree))
_test(self.repo.diff(COMMIT_SHA1_1, COMMIT_SHA1_2))
def test_diff_empty_tree(self):
commit_a = self.repo[COMMIT_SHA1_1]
diff = commit_a.tree.diff_to_tree()
def get_context_for_lines(diff):
hunks = chain(*map(lambda x: x.hunks, [p for p in diff]))
lines = chain(*map(lambda x: x.lines, hunks))
return map(lambda x: x.origin, lines)
entries = [p.delta.new_file.path for p in diff]
self.assertAll(lambda x: commit_a.tree[x], entries)
self.assertAll(lambda x: '-' == x, get_context_for_lines(diff))
diff_swaped = commit_a.tree.diff_to_tree(swap=True)
entries = [p.delta.new_file.path for p in diff_swaped]
self.assertAll(lambda x: commit_a.tree[x], entries)
self.assertAll(lambda x: '+' == x, get_context_for_lines(diff_swaped))
def test_diff_revparse(self):
diff = self.repo.diff('HEAD', 'HEAD~6')
self.assertEqual(type(diff), pygit2.Diff)
def test_diff_tree_opts(self):
commit_c = self.repo[COMMIT_SHA1_3]
commit_d = self.repo[COMMIT_SHA1_4]
for flag in [GIT_DIFF_IGNORE_WHITESPACE,
GIT_DIFF_IGNORE_WHITESPACE_EOL]:
diff = commit_c.tree.diff_to_tree(commit_d.tree, flag)
self.assertTrue(diff is not None)
self.assertEqual(0, len(diff[0].hunks))
diff = commit_c.tree.diff_to_tree(commit_d.tree)
self.assertTrue(diff is not None)
self.assertEqual(1, len(diff[0].hunks))
def test_diff_merge(self):
commit_a = self.repo[COMMIT_SHA1_1]
commit_b = self.repo[COMMIT_SHA1_2]
commit_c = self.repo[COMMIT_SHA1_3]
diff_b = commit_a.tree.diff_to_tree(commit_b.tree)
# self.assertIsNotNone is 2.7 only
self.assertTrue(diff_b is not None)
diff_c = commit_b.tree.diff_to_tree(commit_c.tree)
# self.assertIsNotNone is 2.7 only
self.assertTrue(diff_c is not None)
# assertIn / assertNotIn are 2.7 only
self.assertFalse('b' in [patch.delta.new_file.path for patch in diff_b])
self.assertTrue('b' in [patch.delta.new_file.path for patch in diff_c])
diff_b.merge(diff_c)
# assertIn is 2.7 only
self.assertTrue('b' in [patch.delta.new_file.path for patch in diff_b])
patch = diff_b[0]
hunk = patch.hunks[0]
self.assertEqual(hunk.old_start, 1)
self.assertEqual(hunk.old_lines, 1)
self.assertEqual(hunk.new_start, 1)
self.assertEqual(hunk.new_lines, 1)
self.assertEqual(patch.delta.old_file.path, 'a')
self.assertEqual(patch.delta.new_file.path, 'a')
def test_diff_patch(self):
commit_a = self.repo[COMMIT_SHA1_1]
commit_b = self.repo[COMMIT_SHA1_2]
diff = commit_a.tree.diff_to_tree(commit_b.tree)
self.assertEqual(diff.patch, PATCH)
self.assertEqual(len(diff), len([patch for patch in diff]))
def test_diff_ids(self):
commit_a = self.repo[COMMIT_SHA1_1]
commit_b = self.repo[COMMIT_SHA1_2]
patch = commit_a.tree.diff_to_tree(commit_b.tree)[0]
self.assertEqual(patch.delta.old_file.id.hex,
'7f129fd57e31e935c6d60a0c794efe4e6927664b')
self.assertEqual(patch.delta.new_file.id.hex,
'af431f20fc541ed6d5afede3e2dc7160f6f01f16')
def test_hunk_content(self):
commit_a = self.repo[COMMIT_SHA1_1]
commit_b = self.repo[COMMIT_SHA1_2]
patch = commit_a.tree.diff_to_tree(commit_b.tree)[0]
hunk = patch.hunks[0]
lines = ('{0} {1}'.format(x.origin, x.content) for x in hunk.lines)
self.assertEqual(HUNK_EXPECTED, ''.join(lines))
def test_find_similar(self):
commit_a = self.repo[COMMIT_SHA1_6]
commit_b = self.repo[COMMIT_SHA1_7]
#~ Must pass GIT_DIFF_INCLUDE_UNMODIFIED if you expect to emulate
#~ --find-copies-harder during rename transformion...
diff = commit_a.tree.diff_to_tree(commit_b.tree,
GIT_DIFF_INCLUDE_UNMODIFIED)
self.assertAll(lambda x: x.delta.status != GIT_DELTA_RENAMED, diff)
self.assertAll(lambda x: x.delta.status_char() != 'R', diff)
diff.find_similar()
self.assertAny(lambda x: x.delta.status == GIT_DELTA_RENAMED, diff)
self.assertAny(lambda x: x.delta.status_char() == 'R', diff)
def test_diff_stats(self):
commit_a = self.repo[COMMIT_SHA1_1]
commit_b = self.repo[COMMIT_SHA1_2]
diff = commit_a.tree.diff_to_tree(commit_b.tree)
stats = diff.stats
self.assertEqual(1, stats.insertions)
self.assertEqual(2, stats.deletions)
self.assertEqual(2, stats.files_changed)
formatted = stats.format(format=pygit2.GIT_DIFF_STATS_FULL |
pygit2.GIT_DIFF_STATS_INCLUDE_SUMMARY,
width=80)
self.assertEqual(STATS_EXPECTED, formatted)
class BinaryDiffTest(utils.BinaryFileRepoTestCase):
def test_binary_diff(self):
repo = self.repo
diff = repo.diff('HEAD', 'HEAD^')
self.assertEqual(PATCH_BINARY, diff.patch)
diff = repo.diff('HEAD', 'HEAD^', flags=GIT_DIFF_SHOW_BINARY)
self.assertEqual(PATCH_BINARY_SHOW, diff.patch)
if __name__ == '__main__':
unittest.main()
|
gpl-2.0
|
[
3,
1882,
2803,
26,
9094,
13,
24,
1882,
199,
3,
199,
3,
1898,
7129,
13,
7806,
710,
1134,
3187,
18,
8417,
199,
3,
199,
3,
961,
570,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
12,
1015,
499,
12,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
1010,
10234,
370,
314,
3443,
315,
314,
1664,
1696,
1684,
844,
12,
199,
3,
314,
11462,
8120,
1265,
625,
14136,
4983,
370,
2142,
314,
10311,
199,
3,
1015,
402,
642,
570,
1901,
15821,
543,
1163,
18572,
12,
199,
3,
436,
370,
11207,
5204,
15821,
1928,
1263,
10588,
199,
3,
17262,
687,
314,
675,
402,
642,
570,
14,
221,
334,
1918,
1696,
1684,
844,
199,
3,
24488,
886,
4838,
315,
1163,
14021,
83,
27,
367,
2893,
12,
2985,
8486,
199,
3,
7100,
402,
314,
570,
12,
436,
4084,
1380,
440,
10632,
1901,
199,
3,
282,
12149,
7286,
4959,
199,
3,
199,
3,
961,
570,
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,
642,
2240,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
8026,
11236,
14259,
12,
12066,
11844,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
199,
624,
2925,
367,
27134,
2251,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2882,
199,
646,
1134,
3187,
18,
199,
504,
1134,
3187,
18,
492,
598,
649,
63,
10596,
63,
18171,
63,
1734,
30389,
199,
504,
1134,
3187,
18,
492,
598,
649,
63,
10596,
63,
11209,
63,
20620,
12,
598,
649,
63,
10596,
63,
11209,
63,
20620,
63,
37,
2228,
199,
504,
1134,
3187,
18,
492,
598,
649,
63,
10596,
63,
19085,
63,
13246,
199,
504,
1134,
3187,
18,
492,
598,
649,
63,
4424,
6166,
63,
50,
742,
1156,
1149,
199,
504,
1275,
492,
3778,
199,
504,
7975,
492,
6036,
421,
199,
23446,
63,
8461,
17,
63,
17,
275,
283,
21,
771,
11292,
69,
1407,
2481,
67,
4195,
13251,
1257,
67,
11551,
70,
29982,
383,
2894,
16,
271,
1602,
66,
709,
7,
199,
23446,
63,
8461,
17,
63,
18,
275,
283,
67,
1465,
2942,
67,
667,
20919,
3624,
22,
12638,
32430,
18,
2866,
21,
11901,
67,
8867,
20,
66,
16,
2592,
19235,
67,
7,
199,
23446,
63,
8461,
17,
63,
19,
275,
283,
18,
67,
9747,
16029,
1407,
67,
16,
15897,
1046,
69,
26525,
68,
16,
2501,
25,
69,
379,
2182,
1153,
70,
2976,
65,
2466,
66,
7,
199,
23446,
63,
8461,
17,
63,
20,
275,
283,
2055,
696,
2417,
70,
2501,
1479,
12363,
69,
3172,
65,
23,
65,
2466,
68,
975,
2528,
1020,
66,
1349,
69,
18,
69,
22,
67,
16,
66,
19,
7,
199,
23446,
63,
8461,
17,
63,
21,
275,
283,
25369,
69,
28926,
69,
2869,
66,
17,
3003,
17,
1024,
9252,
1651,
383,
69,
10936,
379,
24,
68,
1349,
67,
24,
70,
19171,
7,
199,
23446,
63,
8461,
17,
63,
22,
275,
283,
70,
21,
69,
21,
2158,
20,
69,
1344,
371,
16,
771,
2789,
1024,
17,
19504,
22,
2871,
24,
70,
1965,
66,
1184,
10253,
19,
66,
1555,
7,
199,
23446,
63,
8461,
17,
63,
23,
275,
283,
28394,
12593,
27956,
9408,
1887,
65,
1167,
1079,
68,
18,
2177,
2789,
68,
713,
66,
3129,
1342,
68,
2114,
3624,
2277,
7,
421,
199,
17073,
275,
408,
3028,
1553,
3187,
282,
15,
65,
330,
15,
65,
199,
1080,
1520,
70,
7263,
2592,
703,
2756,
32042,
70,
18,
2948,
10893,
199,
2595,
282,
15,
65,
199,
4176,
11,
330,
15,
65,
199,
7492,
446,
17,
435,
17,
13365,
199,
13,
65,
4072,
499,
199,
11,
65,
4072,
199,
3028,
1553,
3187,
282,
15,
67,
15,
68,
330,
15,
67,
15,
68,
199,
6062,
570,
818,
2948,
10893,
199,
1080,
499,
2576,
2829,
66,
24,
703,
9084,
199,
2595,
282,
15,
67,
15,
68,
199,
4176,
11,
1182,
2374,
15,
2307,
199,
7492,
446,
17,
435,
16,
12,
16,
13365,
199,
13,
67,
15,
68,
4072,
199,
624,
199,
199,
17073,
63,
13246,
275,
408,
3028,
1553,
3187,
282,
15,
3008,
63,
493,
330,
15,
3008,
63,
493,
199,
1080,
10300,
69,
21,
67,
709,
703,
66,
32065,
68,
2898,
2948,
10893,
199,
6636,
1584,
282,
15,
3008,
63,
493,
436,
330,
15,
3008,
63,
493,
14460,
199,
624,
199,
199,
17073,
63,
13246,
63,
19085,
275,
408,
3028,
1553,
3187,
282,
15,
3008,
63,
493,
330,
15,
3008,
63,
493,
199,
1080,
10300,
69,
21,
67,
1960,
24,
66,
21,
301,
31062,
68,
19,
69,
19,
556,
667,
1602,
1082,
67,
21,
825,
2866,
24,
70,
383,
66,
22,
703,
66,
32065,
68,
31327,
10657,
1602,
66,
1272,
2635,
70,
1344,
65,
24,
67,
21,
1587,
23425,
66,
3172,
66,
12034,
697,
23,
2948,
10893,
199,
20072,
3366,
3371,
199,
8939,
1695,
199,
48,
67,
10545,
21942,
5,
1976,
72,
19239,
62,
75,
41,
89,
19,
78,
6,
23,
50,
199,
199,
8939,
1695,
199,
48,
67,
10545,
21942,
6,
48,
68,
10420,
48,
86,
8332,
19,
14655,
21,
91,
199,
199,
624,
199,
199,
10596,
63,
5211,
63,
2566,
63,
10215,
63,
22358,
275,
359,
272,
283,
270,
6028,
63,
6627,
297,
272,
283,
270,
6028,
63,
6627,
63,
493,
63,
6062,
297,
272,
283,
270,
6028,
63,
6627,
63,
493,
63,
5540,
297,
272,
283,
270,
6028,
63,
1807,
297,
272,
283,
270,
6028,
63,
1807,
63,
493,
63,
5540,
297,
272,
283,
270,
6028,
63,
1222,
297,
272,
283,
270,
6028,
63,
1222,
63,
493,
63,
6062,
297,
272,
283,
270,
6028,
63,
1222,
63,
493,
63,
5540,
7,
199,
61,
199,
199,
10596,
63,
5211,
63,
2566,
63,
8406,
3022,
63,
22358,
275,
359
] |
[
1882,
2803,
26,
9094,
13,
24,
1882,
199,
3,
199,
3,
1898,
7129,
13,
7806,
710,
1134,
3187,
18,
8417,
199,
3,
199,
3,
961,
570,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
12,
1015,
499,
12,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
1010,
10234,
370,
314,
3443,
315,
314,
1664,
1696,
1684,
844,
12,
199,
3,
314,
11462,
8120,
1265,
625,
14136,
4983,
370,
2142,
314,
10311,
199,
3,
1015,
402,
642,
570,
1901,
15821,
543,
1163,
18572,
12,
199,
3,
436,
370,
11207,
5204,
15821,
1928,
1263,
10588,
199,
3,
17262,
687,
314,
675,
402,
642,
570,
14,
221,
334,
1918,
1696,
1684,
844,
199,
3,
24488,
886,
4838,
315,
1163,
14021,
83,
27,
367,
2893,
12,
2985,
8486,
199,
3,
7100,
402,
314,
570,
12,
436,
4084,
1380,
440,
10632,
1901,
199,
3,
282,
12149,
7286,
4959,
199,
3,
199,
3,
961,
570,
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,
642,
2240,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
8026,
11236,
14259,
12,
12066,
11844,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
199,
624,
2925,
367,
27134,
2251,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2882,
199,
646,
1134,
3187,
18,
199,
504,
1134,
3187,
18,
492,
598,
649,
63,
10596,
63,
18171,
63,
1734,
30389,
199,
504,
1134,
3187,
18,
492,
598,
649,
63,
10596,
63,
11209,
63,
20620,
12,
598,
649,
63,
10596,
63,
11209,
63,
20620,
63,
37,
2228,
199,
504,
1134,
3187,
18,
492,
598,
649,
63,
10596,
63,
19085,
63,
13246,
199,
504,
1134,
3187,
18,
492,
598,
649,
63,
4424,
6166,
63,
50,
742,
1156,
1149,
199,
504,
1275,
492,
3778,
199,
504,
7975,
492,
6036,
421,
199,
23446,
63,
8461,
17,
63,
17,
275,
283,
21,
771,
11292,
69,
1407,
2481,
67,
4195,
13251,
1257,
67,
11551,
70,
29982,
383,
2894,
16,
271,
1602,
66,
709,
7,
199,
23446,
63,
8461,
17,
63,
18,
275,
283,
67,
1465,
2942,
67,
667,
20919,
3624,
22,
12638,
32430,
18,
2866,
21,
11901,
67,
8867,
20,
66,
16,
2592,
19235,
67,
7,
199,
23446,
63,
8461,
17,
63,
19,
275,
283,
18,
67,
9747,
16029,
1407,
67,
16,
15897,
1046,
69,
26525,
68,
16,
2501,
25,
69,
379,
2182,
1153,
70,
2976,
65,
2466,
66,
7,
199,
23446,
63,
8461,
17,
63,
20,
275,
283,
2055,
696,
2417,
70,
2501,
1479,
12363,
69,
3172,
65,
23,
65,
2466,
68,
975,
2528,
1020,
66,
1349,
69,
18,
69,
22,
67,
16,
66,
19,
7,
199,
23446,
63,
8461,
17,
63,
21,
275,
283,
25369,
69,
28926,
69,
2869,
66,
17,
3003,
17,
1024,
9252,
1651,
383,
69,
10936,
379,
24,
68,
1349,
67,
24,
70,
19171,
7,
199,
23446,
63,
8461,
17,
63,
22,
275,
283,
70,
21,
69,
21,
2158,
20,
69,
1344,
371,
16,
771,
2789,
1024,
17,
19504,
22,
2871,
24,
70,
1965,
66,
1184,
10253,
19,
66,
1555,
7,
199,
23446,
63,
8461,
17,
63,
23,
275,
283,
28394,
12593,
27956,
9408,
1887,
65,
1167,
1079,
68,
18,
2177,
2789,
68,
713,
66,
3129,
1342,
68,
2114,
3624,
2277,
7,
421,
199,
17073,
275,
408,
3028,
1553,
3187,
282,
15,
65,
330,
15,
65,
199,
1080,
1520,
70,
7263,
2592,
703,
2756,
32042,
70,
18,
2948,
10893,
199,
2595,
282,
15,
65,
199,
4176,
11,
330,
15,
65,
199,
7492,
446,
17,
435,
17,
13365,
199,
13,
65,
4072,
499,
199,
11,
65,
4072,
199,
3028,
1553,
3187,
282,
15,
67,
15,
68,
330,
15,
67,
15,
68,
199,
6062,
570,
818,
2948,
10893,
199,
1080,
499,
2576,
2829,
66,
24,
703,
9084,
199,
2595,
282,
15,
67,
15,
68,
199,
4176,
11,
1182,
2374,
15,
2307,
199,
7492,
446,
17,
435,
16,
12,
16,
13365,
199,
13,
67,
15,
68,
4072,
199,
624,
199,
199,
17073,
63,
13246,
275,
408,
3028,
1553,
3187,
282,
15,
3008,
63,
493,
330,
15,
3008,
63,
493,
199,
1080,
10300,
69,
21,
67,
709,
703,
66,
32065,
68,
2898,
2948,
10893,
199,
6636,
1584,
282,
15,
3008,
63,
493,
436,
330,
15,
3008,
63,
493,
14460,
199,
624,
199,
199,
17073,
63,
13246,
63,
19085,
275,
408,
3028,
1553,
3187,
282,
15,
3008,
63,
493,
330,
15,
3008,
63,
493,
199,
1080,
10300,
69,
21,
67,
1960,
24,
66,
21,
301,
31062,
68,
19,
69,
19,
556,
667,
1602,
1082,
67,
21,
825,
2866,
24,
70,
383,
66,
22,
703,
66,
32065,
68,
31327,
10657,
1602,
66,
1272,
2635,
70,
1344,
65,
24,
67,
21,
1587,
23425,
66,
3172,
66,
12034,
697,
23,
2948,
10893,
199,
20072,
3366,
3371,
199,
8939,
1695,
199,
48,
67,
10545,
21942,
5,
1976,
72,
19239,
62,
75,
41,
89,
19,
78,
6,
23,
50,
199,
199,
8939,
1695,
199,
48,
67,
10545,
21942,
6,
48,
68,
10420,
48,
86,
8332,
19,
14655,
21,
91,
199,
199,
624,
199,
199,
10596,
63,
5211,
63,
2566,
63,
10215,
63,
22358,
275,
359,
272,
283,
270,
6028,
63,
6627,
297,
272,
283,
270,
6028,
63,
6627,
63,
493,
63,
6062,
297,
272,
283,
270,
6028,
63,
6627,
63,
493,
63,
5540,
297,
272,
283,
270,
6028,
63,
1807,
297,
272,
283,
270,
6028,
63,
1807,
63,
493,
63,
5540,
297,
272,
283,
270,
6028,
63,
1222,
297,
272,
283,
270,
6028,
63,
1222,
63,
493,
63,
6062,
297,
272,
283,
270,
6028,
63,
1222,
63,
493,
63,
5540,
7,
199,
61,
199,
199,
10596,
63,
5211,
63,
2566,
63,
8406,
3022,
63,
22358,
275,
359,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dbaxa/GitPython
|
git/refs/remote.py
|
3
|
1569
|
from head import Head
from git.util import join_path
from gitdb.util import join
import os
__all__ = ["RemoteReference"]
class RemoteReference(Head):
"""Represents a reference pointing to a remote head."""
_common_path_default = Head._remote_common_path_default
@classmethod
def iter_items(cls, repo, common_path = None, remote=None):
"""Iterate remote references, and if given, constrain them to the given remote"""
common_path = common_path or cls._common_path_default
if remote is not None:
common_path = join_path(common_path, str(remote))
# END handle remote constraint
return super(RemoteReference, cls).iter_items(repo, common_path)
@classmethod
def delete(cls, repo, *refs, **kwargs):
"""Delete the given remote references.
:note:
kwargs are given for compatability with the base class method as we
should not narrow the signature."""
repo.git.branch("-d", "-r", *refs)
# the official deletion method will ignore remote symbolic refs - these
# are generally ignored in the refs/ folder. We don't though
# and delete remainders manually
for ref in refs:
try:
os.remove(join(repo.git_dir, ref.path))
except OSError:
pass
# END for each ref
@classmethod
def create(cls, *args, **kwargs):
"""Used to disable this method"""
raise TypeError("Cannot explicitly create remote references")
|
bsd-3-clause
|
[
504,
4854,
492,
5311,
350,
199,
504,
6135,
14,
1974,
492,
4263,
63,
515,
199,
504,
6135,
697,
14,
1974,
492,
4263,
199,
199,
646,
747,
421,
199,
363,
452,
363,
275,
2097,
6713,
5083,
937,
10813,
199,
533,
17283,
5083,
8,
11664,
304,
272,
408,
18089,
282,
3659,
20686,
370,
282,
3982,
4854,
1041,
272,
485,
2330,
63,
515,
63,
885,
275,
5311,
350,
423,
3846,
63,
2330,
63,
515,
63,
885,
17635,
768,
3744,
272,
347,
2740,
63,
1744,
8,
1886,
12,
3831,
12,
2863,
63,
515,
275,
488,
12,
3982,
29,
403,
304,
267,
408,
3315,
323,
3982,
6941,
12,
436,
340,
1627,
12,
950,
6322,
3062,
370,
314,
1627,
3982,
624,
267,
2863,
63,
515,
275,
2863,
63,
515,
503,
843,
423,
2330,
63,
515,
63,
885,
267,
340,
3982,
365,
440,
488,
26,
288,
2863,
63,
515,
275,
4263,
63,
515,
8,
2330,
63,
515,
12,
620,
8,
3846,
430,
267,
327,
7729,
2429,
3982,
5828,
267,
372,
1613,
8,
6713,
5083,
12,
843,
680,
1661,
63,
1744,
8,
3417,
12,
2863,
63,
515,
9,
2286,
768,
3744,
272,
347,
3145,
8,
1886,
12,
3831,
12,
627,
7655,
12,
1011,
958,
304,
267,
408,
5392,
314,
1627,
3982,
6941,
14,
267,
520,
4610,
26,
288,
2074,
787,
1627,
367,
1013,
1936,
2012,
543,
314,
1300,
1021,
1083,
465,
781,
7205,
1077,
440,
31530,
314,
4955,
1041,
267,
3831,
14,
3187,
14,
4694,
6096,
68,
401,
3905,
82,
401,
627,
7655,
9,
267,
327,
314,
25410,
14068,
1083,
911,
3686,
3982,
13673,
15749,
446,
3520,
4960,
327,
787,
16711,
5525,
315,
314,
15749,
15,
4922,
14,
2136,
2793,
1133,
10617,
4960,
327,
436,
3145,
5706,
7735,
10250,
267,
367,
2984,
315,
15749,
26,
288,
862,
26,
355,
747,
14,
2168,
8,
904,
8,
3417,
14,
3187,
63,
694,
12,
2984,
14,
515,
430,
288,
871,
6440,
26,
355,
986,
267,
327,
7729,
367,
1924,
2984,
5493,
768,
3744,
272,
347,
1218,
8,
1886,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
9167,
370,
3507,
642,
1083,
624,
267,
746,
3146,
480,
6612,
7662,
1218,
3982,
6941,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4854,
492,
5311,
350,
199,
504,
6135,
14,
1974,
492,
4263,
63,
515,
199,
504,
6135,
697,
14,
1974,
492,
4263,
199,
199,
646,
747,
421,
199,
363,
452,
363,
275,
2097,
6713,
5083,
937,
10813,
199,
533,
17283,
5083,
8,
11664,
304,
272,
408,
18089,
282,
3659,
20686,
370,
282,
3982,
4854,
1041,
272,
485,
2330,
63,
515,
63,
885,
275,
5311,
350,
423,
3846,
63,
2330,
63,
515,
63,
885,
17635,
768,
3744,
272,
347,
2740,
63,
1744,
8,
1886,
12,
3831,
12,
2863,
63,
515,
275,
488,
12,
3982,
29,
403,
304,
267,
408,
3315,
323,
3982,
6941,
12,
436,
340,
1627,
12,
950,
6322,
3062,
370,
314,
1627,
3982,
624,
267,
2863,
63,
515,
275,
2863,
63,
515,
503,
843,
423,
2330,
63,
515,
63,
885,
267,
340,
3982,
365,
440,
488,
26,
288,
2863,
63,
515,
275,
4263,
63,
515,
8,
2330,
63,
515,
12,
620,
8,
3846,
430,
267,
327,
7729,
2429,
3982,
5828,
267,
372,
1613,
8,
6713,
5083,
12,
843,
680,
1661,
63,
1744,
8,
3417,
12,
2863,
63,
515,
9,
2286,
768,
3744,
272,
347,
3145,
8,
1886,
12,
3831,
12,
627,
7655,
12,
1011,
958,
304,
267,
408,
5392,
314,
1627,
3982,
6941,
14,
267,
520,
4610,
26,
288,
2074,
787,
1627,
367,
1013,
1936,
2012,
543,
314,
1300,
1021,
1083,
465,
781,
7205,
1077,
440,
31530,
314,
4955,
1041,
267,
3831,
14,
3187,
14,
4694,
6096,
68,
401,
3905,
82,
401,
627,
7655,
9,
267,
327,
314,
25410,
14068,
1083,
911,
3686,
3982,
13673,
15749,
446,
3520,
4960,
327,
787,
16711,
5525,
315,
314,
15749,
15,
4922,
14,
2136,
2793,
1133,
10617,
4960,
327,
436,
3145,
5706,
7735,
10250,
267,
367,
2984,
315,
15749,
26,
288,
862,
26,
355,
747,
14,
2168,
8,
904,
8,
3417,
14,
3187,
63,
694,
12,
2984,
14,
515,
430,
288,
871,
6440,
26,
355,
986,
267,
327,
7729,
367,
1924,
2984,
5493,
768,
3744,
272,
347,
1218,
8,
1886,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
9167,
370,
3507,
642,
1083,
624,
267,
746,
3146,
480,
6612,
7662,
1218,
3982,
6941,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
morelab/weblabdeusto
|
server/src/test/unit/weblab/core/test_wsgi_manager.py
|
3
|
1543
|
from __future__ import print_function, unicode_literals
import unittest
import requests
import time
from voodoo.configuration import ConfigurationManager
import test.unit.configuration as configuration_module
from test.util.module_disposer import uses_module
from test.util.ports import new as new_port
import weblab.core.wsgi_manager as wsgi_manager
import weblab.configuration_doc as configuration_doc
class HelloWorldApp(object):
def __call__(self, environ, start_response):
start_response(str('200 OK'), [(str('Content-Type'), str('text/plain'))])
yield str('Hello World\n')
class WsgiManagerTest(unittest.TestCase):
def setUp(self):
self.cfg_manager = ConfigurationManager()
self.cfg_manager.append_module(configuration_module)
self.cfg_manager._set_value(configuration_doc.FACADE_TIMEOUT, 0.001)
self.current_port = new_port()
self.cfg_manager._set_value(configuration_doc.CORE_FACADE_PORT, self.current_port)
app = HelloWorldApp()
self.server = wsgi_manager.WebLabWsgiServer(self.cfg_manager, application = app)
@uses_module(wsgi_manager)
def test_server(self):
self.server.start()
try:
time.sleep(0.1)
text = requests.get('http://127.0.0.1:%s/' % self.current_port, timeout = 10).text
self.assertEquals("Hello World\n", text)
finally:
self.server.stop()
def suite():
return unittest.makeSuite(WsgiManagerTest)
if __name__ == '__main__':
unittest.main()
|
bsd-2-clause
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
2649,
63,
5955,
199,
646,
2882,
199,
646,
4145,
199,
646,
900,
199,
199,
504,
14164,
22058,
14,
4758,
492,
11595,
2988,
199,
199,
646,
511,
14,
3248,
14,
4758,
465,
2897,
63,
578,
199,
504,
511,
14,
1974,
14,
578,
63,
2297,
555,
332,
492,
4440,
63,
578,
199,
504,
511,
14,
1974,
14,
5203,
492,
892,
465,
892,
63,
719,
199,
646,
3330,
5561,
14,
1018,
14,
6508,
63,
2609,
465,
12464,
63,
2609,
199,
646,
3330,
5561,
14,
4758,
63,
1301,
465,
2897,
63,
1301,
421,
199,
533,
23833,
15943,
2640,
8,
785,
304,
272,
347,
636,
1250,
721,
277,
12,
6160,
12,
1343,
63,
1310,
304,
267,
1343,
63,
1310,
8,
495,
360,
1840,
9949,
659,
3842,
495,
360,
2714,
13,
804,
659,
620,
360,
505,
15,
6104,
1333,
566,
267,
1995,
620,
360,
6257,
13064,
60,
78,
358,
199,
199,
533,
644,
5395,
2988,
774,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
4128,
63,
2609,
275,
11595,
2988,
342,
267,
291,
14,
4128,
63,
2609,
14,
740,
63,
578,
8,
4758,
63,
578,
9,
398,
291,
14,
4128,
63,
2609,
423,
409,
63,
585,
8,
4758,
63,
1301,
14,
38,
32295,
1093,
63,
8899,
12,
378,
14,
4587,
9,
398,
291,
14,
1818,
63,
719,
275,
892,
63,
719,
342,
267,
291,
14,
4128,
63,
2609,
423,
409,
63,
585,
8,
4758,
63,
1301,
14,
24428,
63,
38,
32295,
1093,
63,
3657,
12,
291,
14,
1818,
63,
719,
9,
398,
1145,
275,
23833,
15943,
2640,
342,
267,
291,
14,
1000,
275,
12464,
63,
2609,
14,
5926,
22511,
55,
5395,
3120,
8,
277,
14,
4128,
63,
2609,
12,
221,
4223,
275,
1145,
9,
2378,
768,
5589,
63,
578,
8,
6508,
63,
2609,
9,
272,
347,
511,
63,
1000,
8,
277,
304,
267,
291,
14,
1000,
14,
928,
342,
267,
862,
26,
288,
900,
14,
4532,
8,
16,
14,
17,
9,
288,
1318,
275,
4145,
14,
362,
360,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
2689,
83,
4805,
450,
291,
14,
1818,
63,
719,
12,
2653,
275,
1616,
680,
505,
288,
291,
14,
2947,
480,
6257,
13064,
60,
78,
401,
1318,
9,
267,
3753,
26,
288,
291,
14,
1000,
14,
2379,
342,
199,
199,
318,
5241,
837,
272,
372,
2882,
14,
18275,
8,
55,
5395,
2988,
774,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
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
] |
[
636,
2443,
363,
492,
870,
63,
1593,
12,
2649,
63,
5955,
199,
646,
2882,
199,
646,
4145,
199,
646,
900,
199,
199,
504,
14164,
22058,
14,
4758,
492,
11595,
2988,
199,
199,
646,
511,
14,
3248,
14,
4758,
465,
2897,
63,
578,
199,
504,
511,
14,
1974,
14,
578,
63,
2297,
555,
332,
492,
4440,
63,
578,
199,
504,
511,
14,
1974,
14,
5203,
492,
892,
465,
892,
63,
719,
199,
646,
3330,
5561,
14,
1018,
14,
6508,
63,
2609,
465,
12464,
63,
2609,
199,
646,
3330,
5561,
14,
4758,
63,
1301,
465,
2897,
63,
1301,
421,
199,
533,
23833,
15943,
2640,
8,
785,
304,
272,
347,
636,
1250,
721,
277,
12,
6160,
12,
1343,
63,
1310,
304,
267,
1343,
63,
1310,
8,
495,
360,
1840,
9949,
659,
3842,
495,
360,
2714,
13,
804,
659,
620,
360,
505,
15,
6104,
1333,
566,
267,
1995,
620,
360,
6257,
13064,
60,
78,
358,
199,
199,
533,
644,
5395,
2988,
774,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
4128,
63,
2609,
275,
11595,
2988,
342,
267,
291,
14,
4128,
63,
2609,
14,
740,
63,
578,
8,
4758,
63,
578,
9,
398,
291,
14,
4128,
63,
2609,
423,
409,
63,
585,
8,
4758,
63,
1301,
14,
38,
32295,
1093,
63,
8899,
12,
378,
14,
4587,
9,
398,
291,
14,
1818,
63,
719,
275,
892,
63,
719,
342,
267,
291,
14,
4128,
63,
2609,
423,
409,
63,
585,
8,
4758,
63,
1301,
14,
24428,
63,
38,
32295,
1093,
63,
3657,
12,
291,
14,
1818,
63,
719,
9,
398,
1145,
275,
23833,
15943,
2640,
342,
267,
291,
14,
1000,
275,
12464,
63,
2609,
14,
5926,
22511,
55,
5395,
3120,
8,
277,
14,
4128,
63,
2609,
12,
221,
4223,
275,
1145,
9,
2378,
768,
5589,
63,
578,
8,
6508,
63,
2609,
9,
272,
347,
511,
63,
1000,
8,
277,
304,
267,
291,
14,
1000,
14,
928,
342,
267,
862,
26,
288,
900,
14,
4532,
8,
16,
14,
17,
9,
288,
1318,
275,
4145,
14,
362,
360,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
2689,
83,
4805,
450,
291,
14,
1818,
63,
719,
12,
2653,
275,
1616,
680,
505,
288,
291,
14,
2947,
480,
6257,
13064,
60,
78,
401,
1318,
9,
267,
3753,
26,
288,
291,
14,
1000,
14,
2379,
342,
199,
199,
318,
5241,
837,
272,
372,
2882,
14,
18275,
8,
55,
5395,
2988,
774,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
bdang2012/taiga-back-casting
|
taiga/base/utils/signals.py
|
1
|
1646
|
# Copyright (C) 2014-2015 Andrey Antukh <niwi@niwi.be>
# Copyright (C) 2014-2015 Jesús Espino <jespinog@gmail.com>
# Copyright (C) 2014-2015 David Barragán <bameda@dbarragan.com>
# Copyright (C) 2014-2015 Anler Hernández <hello@anler.me>
# 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 django.utils.translation import ugettext as _
from contextlib import contextmanager
@contextmanager
def without_signals(*disablers):
for disabler in disablers:
if not (isinstance(disabler, list) or isinstance(disabler, tuple)) or len(disabler) == 0:
raise ValueError("The parameters must be lists of at least one parameter (the signal).")
signal, *ids = disabler
signal.backup_receivers = signal.receivers
signal.receivers = list(filter(lambda x: x[0][0] not in ids, signal.receivers))
try:
yield
except Exception as e:
raise e
finally:
for disabler in disablers:
signal, *ids = disabler
signal.receivers = signal.backup_receivers
|
agpl-3.0
|
[
3,
1898,
334,
35,
9,
6927,
13,
7806,
6061,
17885,
437,
343,
3210,
72,
665,
8445,
14249,
32,
8445,
14249,
14,
1235,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
7806,
1603,
397,
24602,
83,
662,
681,
10175,
665,
74,
397,
7751,
974,
32,
6799,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
7806,
20232,
12377,
2527,
11302,
78,
665,
66,
313,
983,
32,
697,
285,
2527,
290,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
7806,
1626,
1435,
18769,
78,
11302,
78,
271,
90,
665,
5006,
32,
290,
1435,
14,
278,
30,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
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,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
199,
504,
15502,
492,
27608,
421,
199,
32,
14237,
199,
318,
1928,
63,
10458,
2031,
5993,
2393,
304,
272,
367,
3507,
82,
315,
3507,
2393,
26,
267,
340,
440,
334,
6074,
8,
5993,
82,
12,
769,
9,
503,
1228,
8,
5993,
82,
12,
2008,
430,
503,
822,
8,
5993,
82,
9,
508,
378,
26,
288,
746,
1722,
480,
1918,
2633,
1471,
506,
5548,
402,
737,
5210,
1373,
2725,
334,
1589,
4673,
26744,
398,
4673,
12,
627,
1580,
275,
3507,
82,
267,
4673,
14,
5751,
63,
29494,
275,
4673,
14,
29494,
267,
4673,
14,
29494,
275,
769,
8,
1541,
8,
2734,
671,
26,
671,
59,
16,
1527,
16,
61,
440,
315,
2762,
12,
4673,
14,
29494,
430,
339,
862,
26,
267,
1995,
272,
871,
2186,
465,
325,
26,
267,
746,
325,
272,
3753,
26,
267,
367,
3507,
82,
315,
3507,
2393,
26,
288,
4673,
12,
627,
1580,
275,
3507,
82,
288,
4673,
14,
29494,
275,
4673,
14,
5751,
63,
29494,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6927,
13,
7806,
6061,
17885,
437,
343,
3210,
72,
665,
8445,
14249,
32,
8445,
14249,
14,
1235,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
7806,
1603,
397,
24602,
83,
662,
681,
10175,
665,
74,
397,
7751,
974,
32,
6799,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
7806,
20232,
12377,
2527,
11302,
78,
665,
66,
313,
983,
32,
697,
285,
2527,
290,
14,
957,
30,
199,
3,
1898,
334,
35,
9,
6927,
13,
7806,
1626,
1435,
18769,
78,
11302,
78,
271,
90,
665,
5006,
32,
290,
1435,
14,
278,
30,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
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,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
199,
504,
15502,
492,
27608,
421,
199,
32,
14237,
199,
318,
1928,
63,
10458,
2031,
5993,
2393,
304,
272,
367,
3507,
82,
315,
3507,
2393,
26,
267,
340,
440,
334,
6074,
8,
5993,
82,
12,
769,
9,
503,
1228,
8,
5993,
82,
12,
2008,
430,
503,
822,
8,
5993,
82,
9,
508,
378,
26,
288,
746,
1722,
480,
1918,
2633,
1471,
506,
5548,
402,
737,
5210,
1373,
2725,
334,
1589,
4673,
26744,
398,
4673,
12,
627,
1580,
275,
3507,
82,
267,
4673,
14,
5751,
63,
29494,
275,
4673,
14,
29494,
267,
4673,
14,
29494,
275,
769,
8,
1541,
8,
2734,
671,
26,
671,
59,
16,
1527,
16,
61,
440,
315,
2762,
12,
4673,
14,
29494,
430,
339,
862,
26,
267,
1995,
272,
871,
2186,
465,
325,
26,
267,
746,
325,
272,
3753,
26,
267,
367,
3507,
82,
315,
3507,
2393,
26,
288,
4673,
12,
627,
1580,
275,
3507,
82,
288,
4673,
14,
29494,
275,
4673,
14,
5751,
63,
29494,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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
|
from django.db import connection
from django.db.models import Max
from django.test import TestCase
from .models import Cash, CashModel
class FromDBValueTest(TestCase):
def setUp(self):
CashModel.objects.create(cash='12.50')
def test_simple_load(self):
instance = CashModel.objects.get()
self.assertIsInstance(instance.cash, Cash)
def test_values_list(self):
values_list = CashModel.objects.values_list('cash', flat=True)
self.assertIsInstance(values_list[0], Cash)
def test_values(self):
values = CashModel.objects.values('cash')
self.assertIsInstance(values[0]['cash'], Cash)
def test_aggregation(self):
maximum = CashModel.objects.aggregate(m=Max('cash'))['m']
self.assertIsInstance(maximum, Cash)
def test_defer(self):
instance = CashModel.objects.defer('cash').get()
self.assertIsInstance(instance.cash, Cash)
def test_connection(self):
instance = CashModel.objects.get()
self.assertEqual(instance.cash.vendor, connection.vendor)
|
bsd-3-clause
|
[
504,
1639,
14,
697,
492,
1950,
199,
504,
1639,
14,
697,
14,
992,
492,
8228,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
445,
1119,
12,
445,
1119,
1685,
421,
199,
533,
11606,
2846,
1110,
774,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
445,
1119,
1685,
14,
1462,
14,
981,
8,
20084,
534,
713,
14,
1400,
358,
339,
347,
511,
63,
4129,
63,
912,
8,
277,
304,
267,
1256,
275,
445,
1119,
1685,
14,
1462,
14,
362,
342,
267,
291,
14,
6926,
8,
842,
14,
20084,
12,
445,
1119,
9,
339,
347,
511,
63,
1459,
63,
513,
8,
277,
304,
267,
1338,
63,
513,
275,
445,
1119,
1685,
14,
1462,
14,
1459,
63,
513,
360,
20084,
297,
6829,
29,
549,
9,
267,
291,
14,
6926,
8,
1459,
63,
513,
59,
16,
467,
445,
1119,
9,
339,
347,
511,
63,
1459,
8,
277,
304,
267,
1338,
275,
445,
1119,
1685,
14,
1462,
14,
1459,
360,
20084,
358,
267,
291,
14,
6926,
8,
1459,
59,
16,
2733,
20084,
995,
445,
1119,
9,
339,
347,
511,
63,
21016,
8,
277,
304,
267,
5696,
275,
445,
1119,
1685,
14,
1462,
14,
7516,
8,
77,
29,
4261,
360,
20084,
1333,
459,
77,
418,
267,
291,
14,
6926,
8,
11555,
12,
445,
1119,
9,
339,
347,
511,
63,
11610,
8,
277,
304,
267,
1256,
275,
445,
1119,
1685,
14,
1462,
14,
11610,
360,
20084,
1959,
362,
342,
267,
291,
14,
6926,
8,
842,
14,
20084,
12,
445,
1119,
9,
339,
347,
511,
63,
2105,
8,
277,
304,
267,
1256,
275,
445,
1119,
1685,
14,
1462,
14,
362,
342,
267,
291,
14,
629,
8,
842,
14,
20084,
14,
9884,
12,
1950,
14,
9884,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
697,
492,
1950,
199,
504,
1639,
14,
697,
14,
992,
492,
8228,
199,
504,
1639,
14,
396,
492,
7640,
199,
199,
504,
1275,
992,
492,
445,
1119,
12,
445,
1119,
1685,
421,
199,
533,
11606,
2846,
1110,
774,
8,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
445,
1119,
1685,
14,
1462,
14,
981,
8,
20084,
534,
713,
14,
1400,
358,
339,
347,
511,
63,
4129,
63,
912,
8,
277,
304,
267,
1256,
275,
445,
1119,
1685,
14,
1462,
14,
362,
342,
267,
291,
14,
6926,
8,
842,
14,
20084,
12,
445,
1119,
9,
339,
347,
511,
63,
1459,
63,
513,
8,
277,
304,
267,
1338,
63,
513,
275,
445,
1119,
1685,
14,
1462,
14,
1459,
63,
513,
360,
20084,
297,
6829,
29,
549,
9,
267,
291,
14,
6926,
8,
1459,
63,
513,
59,
16,
467,
445,
1119,
9,
339,
347,
511,
63,
1459,
8,
277,
304,
267,
1338,
275,
445,
1119,
1685,
14,
1462,
14,
1459,
360,
20084,
358,
267,
291,
14,
6926,
8,
1459,
59,
16,
2733,
20084,
995,
445,
1119,
9,
339,
347,
511,
63,
21016,
8,
277,
304,
267,
5696,
275,
445,
1119,
1685,
14,
1462,
14,
7516,
8,
77,
29,
4261,
360,
20084,
1333,
459,
77,
418,
267,
291,
14,
6926,
8,
11555,
12,
445,
1119,
9,
339,
347,
511,
63,
11610,
8,
277,
304,
267,
1256,
275,
445,
1119,
1685,
14,
1462,
14,
11610,
360,
20084,
1959,
362,
342,
267,
291,
14,
6926,
8,
842,
14,
20084,
12,
445,
1119,
9,
339,
347,
511,
63,
2105,
8,
277,
304,
267,
1256,
275,
445,
1119,
1685,
14,
1462,
14,
362,
342,
267,
291,
14,
629,
8,
842,
14,
20084,
14,
9884,
12,
1950,
14,
9884,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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0,
0,
0,
0
] |
mattclark/osf.io
|
osf/models/tag.py
|
28
|
1187
|
from django.db import models
from .base import BaseModel
class TagManager(models.Manager):
"""Manager that filters out system tags by default.
"""
def get_queryset(self):
return super(TagManager, self).get_queryset().filter(system=False)
class Tag(BaseModel):
name = models.CharField(db_index=True, max_length=1024)
system = models.BooleanField(default=False)
objects = TagManager()
all_tags = models.Manager()
def __unicode__(self):
if self.system:
return 'System Tag: {}'.format(self.name)
return u'{}'.format(self.name)
def _natural_key(self):
return hash(self.name + str(self.system))
@property
def _id(self):
return self.name.lower()
@classmethod
def load(cls, data, system=False):
"""For compatibility with v1: the tag name used to be the _id,
so we make Tag.load('tagname') work as if `name` were the primary key.
"""
try:
return cls.all_tags.get(system=system, name=data)
except cls.DoesNotExist:
return None
class Meta:
unique_together = ('name', 'system')
ordering = ('name', )
|
apache-2.0
|
[
504,
1639,
14,
697,
492,
1709,
199,
199,
504,
1275,
1095,
492,
3523,
1685,
421,
199,
533,
8053,
2988,
8,
992,
14,
2988,
304,
272,
408,
2988,
626,
4766,
734,
2656,
3762,
701,
849,
14,
272,
408,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
1613,
8,
1931,
2988,
12,
291,
680,
362,
63,
7924,
1252,
1541,
8,
2253,
29,
797,
9,
199,
199,
533,
8053,
8,
27687,
304,
272,
536,
275,
1709,
14,
2183,
8,
697,
63,
1080,
29,
549,
12,
1390,
63,
1267,
29,
7727,
9,
272,
2656,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
339,
2251,
275,
8053,
2988,
342,
272,
1006,
63,
2969,
275,
1709,
14,
2988,
342,
339,
347,
636,
2975,
721,
277,
304,
267,
340,
291,
14,
2253,
26,
288,
372,
283,
3989,
8053,
26,
9499,
908,
8,
277,
14,
354,
9,
267,
372,
399,
7,
11123,
908,
8,
277,
14,
354,
9,
339,
347,
485,
15759,
63,
498,
8,
277,
304,
267,
372,
2631,
8,
277,
14,
354,
435,
620,
8,
277,
14,
2253,
430,
339,
768,
1829,
272,
347,
485,
344,
8,
277,
304,
267,
372,
291,
14,
354,
14,
2325,
342,
339,
768,
3744,
272,
347,
2248,
8,
1886,
12,
666,
12,
2656,
29,
797,
304,
267,
408,
1858,
7163,
543,
373,
17,
26,
314,
1947,
536,
1202,
370,
506,
314,
485,
344,
12,
267,
880,
781,
1852,
8053,
14,
912,
360,
24173,
358,
1736,
465,
340,
658,
354,
64,
4898,
314,
5062,
790,
14,
267,
408,
267,
862,
26,
288,
372,
843,
14,
452,
63,
2969,
14,
362,
8,
2253,
29,
2253,
12,
536,
29,
576,
9,
267,
871,
843,
14,
7400,
26,
288,
372,
488,
339,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
661,
354,
297,
283,
2253,
358,
267,
7794,
275,
661,
354,
297,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
697,
492,
1709,
199,
199,
504,
1275,
1095,
492,
3523,
1685,
421,
199,
533,
8053,
2988,
8,
992,
14,
2988,
304,
272,
408,
2988,
626,
4766,
734,
2656,
3762,
701,
849,
14,
272,
408,
339,
347,
664,
63,
7924,
8,
277,
304,
267,
372,
1613,
8,
1931,
2988,
12,
291,
680,
362,
63,
7924,
1252,
1541,
8,
2253,
29,
797,
9,
199,
199,
533,
8053,
8,
27687,
304,
272,
536,
275,
1709,
14,
2183,
8,
697,
63,
1080,
29,
549,
12,
1390,
63,
1267,
29,
7727,
9,
272,
2656,
275,
1709,
14,
5036,
8,
885,
29,
797,
9,
339,
2251,
275,
8053,
2988,
342,
272,
1006,
63,
2969,
275,
1709,
14,
2988,
342,
339,
347,
636,
2975,
721,
277,
304,
267,
340,
291,
14,
2253,
26,
288,
372,
283,
3989,
8053,
26,
9499,
908,
8,
277,
14,
354,
9,
267,
372,
399,
7,
11123,
908,
8,
277,
14,
354,
9,
339,
347,
485,
15759,
63,
498,
8,
277,
304,
267,
372,
2631,
8,
277,
14,
354,
435,
620,
8,
277,
14,
2253,
430,
339,
768,
1829,
272,
347,
485,
344,
8,
277,
304,
267,
372,
291,
14,
354,
14,
2325,
342,
339,
768,
3744,
272,
347,
2248,
8,
1886,
12,
666,
12,
2656,
29,
797,
304,
267,
408,
1858,
7163,
543,
373,
17,
26,
314,
1947,
536,
1202,
370,
506,
314,
485,
344,
12,
267,
880,
781,
1852,
8053,
14,
912,
360,
24173,
358,
1736,
465,
340,
658,
354,
64,
4898,
314,
5062,
790,
14,
267,
408,
267,
862,
26,
288,
372,
843,
14,
452,
63,
2969,
14,
362,
8,
2253,
29,
2253,
12,
536,
29,
576,
9,
267,
871,
843,
14,
7400,
26,
288,
372,
488,
339,
1021,
6288,
26,
267,
3747,
63,
6314,
275,
661,
354,
297,
283,
2253,
358,
267,
7794,
275,
661,
354,
297,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1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csantos/QGIS
|
python/plugins/processing/algs/gdal/gdaltindex.py
|
3
|
2813
|
# -*- coding: utf-8 -*-
"""
***************************************************************************
gdaltindex.py
---------------------
Date : February 2015
Copyright : (C) 2015 by Pedro Venancio
Email : pedrongvenancio at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Pedro Venancio'
__date__ = 'February 2015'
__copyright__ = '(C) 2015, Pedro Venancio'
# This will get replaced with a git SHA1 when you do a git archive
__revision__ = '$Format:%H$'
from processing.algs.gdal.GdalAlgorithm import GdalAlgorithm
from processing.core.outputs import OutputVector
from processing.core.parameters import ParameterBoolean
from processing.core.parameters import ParameterMultipleInput
from processing.core.parameters import ParameterString
from processing.algs.gdal.GdalUtils import GdalUtils
import os
class gdaltindex(GdalAlgorithm):
INPUT = 'INPUT'
OUTPUT = 'OUTPUT'
FIELD_NAME = 'FIELD_NAME'
PROJ_DIFFERENCE = 'PROJ_DIFFERENCE'
def defineCharacteristics(self):
self.name = 'Tile Index'
self.group = '[GDAL] Miscellaneous'
self.addParameter(ParameterMultipleInput(self.INPUT,
self.tr('Input layers'), ParameterMultipleInput.TYPE_RASTER))
self.addParameter(ParameterString(self.FIELD_NAME,
self.tr('Tile index field'),
'location', optional=True))
self.addParameter(ParameterBoolean(self.PROJ_DIFFERENCE,
self.tr('Skip files with different projection reference'), False))
self.addOutput(OutputVector(gdaltindex.OUTPUT, self.tr('Tile index')))
def getConsoleCommands(self):
fieldName = str(self.getParameterValue(self.FIELD_NAME))
arguments = []
if len(fieldName) > 0:
arguments.append('-tileindex')
arguments.append(fieldName)
if self.getParameterValue(gdaltindex.PROJ_DIFFERENCE):
arguments.append('-skip_different_projection')
arguments.append(unicode(self.getOutputValue(gdaltindex.OUTPUT)))
arguments.extend(unicode(self.getParameterValue(gdaltindex.INPUT)).split(';'))
return ['gdaltindex', GdalUtils.escapeAndJoin(arguments)]
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
24714,
4478,
1080,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
21141,
26709,
6900,
272,
1898,
3322,
520,
334,
35,
9,
6900,
701,
510,
379,
293,
812,
287,
290,
10377,
272,
11426,
4483,
520,
299,
379,
4716,
1856,
290,
10377,
737,
29712,
6308,
2414,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
48,
379,
293,
812,
287,
290,
10377,
7,
199,
363,
602,
363,
275,
283,
27717,
26709,
6900,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6900,
12,
510,
379,
293,
812,
287,
290,
10377,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
421,
199,
504,
6661,
14,
31128,
14,
11600,
14,
39,
12390,
11570,
492,
598,
12390,
11570,
199,
504,
6661,
14,
1018,
14,
4467,
492,
7242,
3646,
199,
504,
6661,
14,
1018,
14,
3214,
492,
12009,
4082,
199,
504,
6661,
14,
1018,
14,
3214,
492,
12009,
8433,
3205,
199,
504,
6661,
14,
1018,
14,
3214,
492,
12009,
1558,
199,
504,
6661,
14,
31128,
14,
11600,
14,
39,
12390,
7535,
492,
598,
12390,
7535,
199,
199,
646,
747,
199,
199,
533,
24714,
4478,
1080,
8,
39,
12390,
11570,
304,
339,
21955,
275,
283,
7321,
7,
272,
18746,
275,
283,
8414,
7,
272,
26130,
63,
2339,
275,
283,
8609,
63,
2339,
7,
272,
3611,
42,
63,
10596,
540,
6013,
275,
283,
2514,
42,
63,
10596,
540,
6013,
7,
339,
347,
5627,
1610,
29867,
8,
277,
304,
267,
291,
14,
354,
275,
283,
29746,
5499,
7,
267,
291,
14,
923,
275,
6730,
17835,
61,
12481,
19549,
7,
267,
291,
14,
26895,
8,
4720,
8433,
3205,
8,
277,
14,
7321,
12,
288,
291,
14,
454,
360,
3205,
9393,
659,
12009,
8433,
3205,
14,
2711,
63,
2847,
14471,
430,
267,
291,
14,
26895,
8,
4720,
1558,
8,
277,
14,
8609,
63,
2339,
12,
288,
291,
14,
454,
360,
29746,
1478,
901,
659,
288,
283,
1985,
297,
2716,
29,
549,
430,
267,
291,
14,
26895,
8,
4720,
4082,
8,
277,
14,
2514,
42,
63,
10596,
540,
6013,
12,
288,
291,
14,
454,
360,
7738,
1584,
543,
3365,
14777,
3659,
659,
756,
430,
267,
291,
14,
525,
2959,
8,
2959,
3646,
8,
7136,
4478,
1080,
14,
8414,
12,
291,
14,
454,
360,
29746,
1478,
7058,
339,
347,
664,
9270,
14680,
8,
277,
304,
267,
901,
985,
275,
620,
8,
277,
14,
362,
24637,
8,
277,
14,
8609,
63,
2339,
430,
398,
2368,
275,
942,
267,
340,
822,
8,
698,
985,
9,
690,
378,
26,
288,
2368,
14,
740,
3654,
7172,
1080,
358,
288,
2368,
14,
740,
8,
698,
985,
9,
267,
340,
291,
14,
362,
24637,
8,
7136,
4478,
1080,
14,
2514,
42,
63,
10596,
540,
6013,
304,
288,
2368,
14,
740,
3654,
2759,
63,
14020,
63,
16539,
358,
267,
2368,
14,
740,
8,
2975,
8,
277,
14,
362,
2959,
1110,
8,
7136,
4478,
1080,
14,
8414,
1724,
267,
2368,
14,
2880,
8,
2975,
8,
277,
14,
362,
24637,
8,
7136,
4478,
1080,
14,
7321,
4992,
1294,
25282,
1333,
7318,
372,
788,
7136,
4478,
1080,
297,
598,
12390,
7535,
14,
3765,
3325,
13005,
8,
4958,
1874,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
24714,
4478,
1080,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
21141,
26709,
6900,
272,
1898,
3322,
520,
334,
35,
9,
6900,
701,
510,
379,
293,
812,
287,
290,
10377,
272,
11426,
4483,
520,
299,
379,
4716,
1856,
290,
10377,
737,
29712,
6308,
2414,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
48,
379,
293,
812,
287,
290,
10377,
7,
199,
363,
602,
363,
275,
283,
27717,
26709,
6900,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6900,
12,
510,
379,
293,
812,
287,
290,
10377,
7,
199,
199,
3,
961,
911,
664,
8717,
543,
282,
6135,
12002,
17,
1380,
1265,
886,
282,
6135,
6359,
199,
199,
363,
5792,
363,
275,
4505,
3484,
2689,
40,
12913,
421,
199,
504,
6661,
14,
31128,
14,
11600,
14,
39,
12390,
11570,
492,
598,
12390,
11570,
199,
504,
6661,
14,
1018,
14,
4467,
492,
7242,
3646,
199,
504,
6661,
14,
1018,
14,
3214,
492,
12009,
4082,
199,
504,
6661,
14,
1018,
14,
3214,
492,
12009,
8433,
3205,
199,
504,
6661,
14,
1018,
14,
3214,
492,
12009,
1558,
199,
504,
6661,
14,
31128,
14,
11600,
14,
39,
12390,
7535,
492,
598,
12390,
7535,
199,
199,
646,
747,
199,
199,
533,
24714,
4478,
1080,
8,
39,
12390,
11570,
304,
339,
21955,
275,
283,
7321,
7,
272,
18746,
275,
283,
8414,
7,
272,
26130,
63,
2339,
275,
283,
8609,
63,
2339,
7,
272,
3611,
42,
63,
10596,
540,
6013,
275,
283,
2514,
42,
63,
10596,
540,
6013,
7,
339,
347,
5627,
1610,
29867,
8,
277,
304,
267,
291,
14,
354,
275,
283,
29746,
5499,
7,
267,
291,
14,
923,
275,
6730,
17835,
61,
12481,
19549,
7,
267,
291,
14,
26895,
8,
4720,
8433,
3205,
8,
277,
14,
7321,
12,
288,
291,
14,
454,
360,
3205,
9393,
659,
12009,
8433,
3205,
14,
2711,
63,
2847,
14471,
430,
267,
291,
14,
26895,
8,
4720,
1558,
8,
277,
14,
8609,
63,
2339,
12,
288,
291,
14,
454,
360,
29746,
1478,
901,
659,
288,
283,
1985,
297,
2716,
29,
549,
430,
267,
291,
14,
26895,
8,
4720,
4082,
8,
277,
14,
2514,
42,
63,
10596,
540,
6013,
12,
288,
291,
14,
454,
360,
7738,
1584,
543,
3365,
14777,
3659,
659,
756,
430,
267,
291,
14,
525,
2959,
8,
2959,
3646,
8,
7136,
4478,
1080,
14,
8414,
12,
291,
14,
454,
360,
29746,
1478,
7058,
339,
347,
664,
9270,
14680,
8,
277,
304,
267,
901,
985,
275,
620,
8,
277,
14,
362,
24637,
8,
277,
14,
8609,
63,
2339,
430,
398,
2368,
275,
942,
267,
340,
822,
8,
698,
985,
9,
690,
378,
26,
288,
2368,
14,
740,
3654,
7172,
1080,
358,
288,
2368,
14,
740,
8,
698,
985,
9,
267,
340,
291,
14,
362,
24637,
8,
7136,
4478,
1080,
14,
2514,
42,
63,
10596,
540,
6013,
304,
288,
2368,
14,
740,
3654,
2759,
63,
14020,
63,
16539,
358,
267,
2368,
14,
740,
8,
2975,
8,
277,
14,
362,
2959,
1110,
8,
7136,
4478,
1080,
14,
8414,
1724,
267,
2368,
14,
2880,
8,
2975,
8,
277,
14,
362,
24637,
8,
7136,
4478,
1080,
14,
7321,
4992,
1294,
25282,
1333,
7318,
372,
788,
7136,
4478,
1080,
297,
598,
12390,
7535,
14,
3765,
3325,
13005,
8,
4958,
1874,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
hurricup/intellij-community
|
python/testData/inspections/PyMissingConstructorInspection/py3k.py
|
83
|
1072
|
class A(object):
def __init__(self):
pass
class AA(A):
def __init__(self):
A.__init__(self)
print("Constructor AA was called")
class B(A):
def <warning descr="Call to __init__ of super class is missed">__init__</warning>(self):
print("Constructor B was called")
class C(B):
def __init__(self):
super(C, self).__init__()
print("Constructor C was called")
class A2:
def __init__(self):
print("A2 __init__")
class B2(A2):
def __init__(self):
A2.__init__(self)
print("Constructor B was called")
class C2(B2):
def <warning descr="Call to __init__ of super class is missed">__init__</warning>(self):
print("Constructor C2 was called")
class D2(C2):
def __init__(self):
super(C2, self).__init__()
print("Constructor D2 was called")
class E2(A2):
def __init__(self):
super().__init__()
print("Constructor E2 was called")
class F2(A2):
def <warning descr="Call to __init__ of super class is missed">__init__</warning>(self):
super(D2, self).__init__()
print("Constructor F2 was called")
|
apache-2.0
|
[
533,
437,
8,
785,
304,
523,
347,
636,
826,
721,
277,
304,
272,
986,
199,
199,
533,
437,
33,
8,
33,
304,
523,
347,
636,
826,
721,
277,
304,
272,
437,
855,
826,
721,
277,
9,
272,
870,
480,
11447,
437,
33,
1990,
2797,
531,
199,
199,
533,
699,
8,
33,
304,
523,
347,
665,
3764,
16193,
628,
2176,
370,
636,
826,
363,
402,
1613,
1021,
365,
3201,
939,
1743,
363,
826,
363,
1108,
3764,
13661,
277,
304,
272,
870,
480,
11447,
699,
1990,
2797,
531,
199,
199,
533,
445,
8,
34,
304,
523,
347,
636,
826,
721,
277,
304,
272,
1613,
8,
35,
12,
291,
2843,
826,
4533,
272,
870,
480,
11447,
445,
1990,
2797,
531,
421,
199,
533,
437,
18,
26,
523,
347,
636,
826,
721,
277,
304,
272,
870,
480,
33,
18,
636,
826,
18617,
421,
199,
533,
699,
18,
8,
33,
18,
304,
523,
347,
636,
826,
721,
277,
304,
272,
437,
18,
855,
826,
721,
277,
9,
272,
870,
480,
11447,
699,
1990,
2797,
531,
199,
199,
533,
445,
18,
8,
34,
18,
304,
523,
347,
665,
3764,
16193,
628,
2176,
370,
636,
826,
363,
402,
1613,
1021,
365,
3201,
939,
1743,
363,
826,
363,
1108,
3764,
13661,
277,
304,
272,
870,
480,
11447,
445,
18,
1990,
2797,
531,
199,
199,
533,
577,
18,
8,
35,
18,
304,
523,
347,
636,
826,
721,
277,
304,
272,
1613,
8,
35,
18,
12,
291,
2843,
826,
4533,
272,
870,
480,
11447,
577,
18,
1990,
2797,
531,
199,
199,
533,
662,
18,
8,
33,
18,
304,
523,
347,
636,
826,
721,
277,
304,
272,
1613,
11027,
826,
4533,
272,
870,
480,
11447,
662,
18,
1990,
2797,
531,
199,
199,
533,
481,
18,
8,
33,
18,
304,
523,
347,
665,
3764,
16193,
628,
2176,
370,
636,
826,
363,
402,
1613,
1021,
365,
3201,
939,
1743,
363,
826,
363,
1108,
3764,
13661,
277,
304,
272,
1613,
8,
36,
18,
12,
291,
2843,
826,
4533,
272,
870,
480,
11447,
481,
18,
1990,
2797,
531,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
437,
8,
785,
304,
523,
347,
636,
826,
721,
277,
304,
272,
986,
199,
199,
533,
437,
33,
8,
33,
304,
523,
347,
636,
826,
721,
277,
304,
272,
437,
855,
826,
721,
277,
9,
272,
870,
480,
11447,
437,
33,
1990,
2797,
531,
199,
199,
533,
699,
8,
33,
304,
523,
347,
665,
3764,
16193,
628,
2176,
370,
636,
826,
363,
402,
1613,
1021,
365,
3201,
939,
1743,
363,
826,
363,
1108,
3764,
13661,
277,
304,
272,
870,
480,
11447,
699,
1990,
2797,
531,
199,
199,
533,
445,
8,
34,
304,
523,
347,
636,
826,
721,
277,
304,
272,
1613,
8,
35,
12,
291,
2843,
826,
4533,
272,
870,
480,
11447,
445,
1990,
2797,
531,
421,
199,
533,
437,
18,
26,
523,
347,
636,
826,
721,
277,
304,
272,
870,
480,
33,
18,
636,
826,
18617,
421,
199,
533,
699,
18,
8,
33,
18,
304,
523,
347,
636,
826,
721,
277,
304,
272,
437,
18,
855,
826,
721,
277,
9,
272,
870,
480,
11447,
699,
1990,
2797,
531,
199,
199,
533,
445,
18,
8,
34,
18,
304,
523,
347,
665,
3764,
16193,
628,
2176,
370,
636,
826,
363,
402,
1613,
1021,
365,
3201,
939,
1743,
363,
826,
363,
1108,
3764,
13661,
277,
304,
272,
870,
480,
11447,
445,
18,
1990,
2797,
531,
199,
199,
533,
577,
18,
8,
35,
18,
304,
523,
347,
636,
826,
721,
277,
304,
272,
1613,
8,
35,
18,
12,
291,
2843,
826,
4533,
272,
870,
480,
11447,
577,
18,
1990,
2797,
531,
199,
199,
533,
662,
18,
8,
33,
18,
304,
523,
347,
636,
826,
721,
277,
304,
272,
1613,
11027,
826,
4533,
272,
870,
480,
11447,
662,
18,
1990,
2797,
531,
199,
199,
533,
481,
18,
8,
33,
18,
304,
523,
347,
665,
3764,
16193,
628,
2176,
370,
636,
826,
363,
402,
1613,
1021,
365,
3201,
939,
1743,
363,
826,
363,
1108,
3764,
13661,
277,
304,
272,
1613,
8,
36,
18,
12,
291,
2843,
826,
4533,
272,
870,
480,
11447,
481,
18,
1990,
2797,
531,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
falkolab/titanium_mobile
|
support/module/module.py
|
34
|
13545
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Module Project Create Script
#
import os, sys, shutil, string, uuid, re, zipfile, glob
from string import capitalize
from StringIO import StringIO
from datetime import date
template_dir = os.path.abspath(os.path.dirname(sys._getframe(0).f_code.co_filename))
sdk_dir = os.path.dirname(template_dir)
sys.path.append(sdk_dir)
from manifest import Manifest
from tiapp import TiAppXML
ignoreFiles = ['.gitignore', '.cvsignore', '.DS_Store'];
ignoreDirs = ['.git','.svn','_svn','CVS'];
nonFilterFiles = ['.png','.gif','.jpg','.zip','.a','.o', '.jar']
class ModulePlatform(object):
def __init__(self, project_dir, config, module):
self.project_dir = project_dir
self.config = config
self.module = module
@classmethod
def create_platform(cls, platform, project_dir, config, module):
platform = platform.lower()
platform_dir = os.path.join(template_dir, platform)
sys.path.append(platform_dir)
platform_module_class = getattr(__import__(platform), platform)
return platform_module_class(project_dir, config, module)
def replace_tokens(self, string):
return string
def get_file_dest(self, to_path):
return to_path
def get_gitignore(self):
return []
def finished(self):
pass
class ModuleProject(object):
def __init__(self,platform,project_dir,config):
self.project_short_name = config['name']
self.project_name = config['name']
self.platform = platform
self.module_id = config['id']
self.module_name = self.generate_module_name(self.module_id)
self.sdk_version = os.path.basename(sdk_dir)
self.guid = str(uuid.uuid4())
self.project_dir = project_dir
self.module_name_camel = camelcase(self.project_name)
self.sdk = None
if config.has_key('sdk'):
self.sdk = config['sdk']
self.platform_delegate = ModulePlatform.create_platform(platform, project_dir, config, self)
platform_dir = os.path.join(template_dir, platform.lower())
all_templates_dir = os.path.join(template_dir,'all')
if os.path.exists(all_templates_dir):
self.copy_template_files(all_templates_dir)
templates_dir = os.path.join(platform_dir,'templates')
if os.path.exists(templates_dir):
self.copy_template_files(templates_dir)
self.generate_gitignore()
self.platform_delegate.finished()
def replace_tokens(self, string):
string = string.replace('___PROJECTNAMEASIDENTIFIER___',self.module_name)
string = string.replace('___MODULE_NAME_CAMEL___', self.module_name_camel)
string = string.replace('___MODULE_ID_AS_FOLDER___', self.module_id.replace('.', os.path.sep))
string = string.replace('___PROJECTNAME___',self.project_name)
string = string.replace('__MODULE_ID__',self.module_id)
string = string.replace('__PROJECT_SHORT_NAME__',self.project_short_name)
string = string.replace('__PROJECT_SHORT_NAME_LOWER__',self.project_short_name.lower())
string = string.replace('__VERSION__',self.sdk_version)
string = string.replace('__SDK__',sdk_dir)
string = string.replace('__SDK_ROOT__',os.path.split(sdk_dir)[0].replace(os.path.expanduser('~'),'~',1))
string = string.replace('__PLATFORM__',self.platform)
string = string.replace('__GUID__',self.guid)
string = string.replace('__YEAR__', str(date.today().year))
string = self.platform_delegate.replace_tokens(string)
return string
def get_file_dest(self, template_dir, from_path):
file_dest = os.path.expanduser(from_path.replace(template_dir, self.project_dir, 1))
return self.platform_delegate.get_file_dest(file_dest)
def copy_template_files(self, template_dir):
for root, dirs, files in os.walk(template_dir):
for name in ignoreDirs:
if name in dirs:
dirs.remove(name) # don't visit ignored directories
for file in files:
if file in ignoreFiles:
continue
prefix = root[len(template_dir):]
from_ = os.path.join(root, file)
to_ = self.get_file_dest(template_dir, from_)
to_ = self.replace_tokens(to_)
to_directory = os.path.expanduser(os.path.split(to_)[0])
if not os.path.exists(to_directory):
os.makedirs(to_directory)
fp = os.path.splitext(file)
filter = True
if len(fp)>1 and fp[1] in nonFilterFiles:
# if a non-filter file, just copy
filter = False
if os.path.exists(to_): os.remove(to_)
shutil.copy(from_,to_)
if filter:
contents = open(from_).read()
tof = open(to_,'w')
contents = self.replace_tokens(contents)
tof.write(contents)
tof.close()
def generate_module_name(self,name):
modulename = ''
for token in name.split('.'):
modulename += token[0:1].upper() + token[1:]
return modulename
def generate_gitignore(self):
git = os.path.join(self.project_dir,'.gitignore')
git_file = open(git,'w+')
git_file.write("tmp\n")
git_file.write("bin\n")
git_file.write("build\n")
git_file.write("*.zip\n")
for ignore in self.platform_delegate.get_gitignore():
git_file.write(ignore+'\n')
git_file.close()
class Module(object):
def __init__(self, path, manifest):
self.path = path
self.manifest = manifest
self.jar = None
module_jar = self.get_resource(manifest.name + '.jar')
if os.path.exists(module_jar):
self.jar = module_jar
else:
# To account for Linux filename case-sensitivity,
# we began to force our external module jars to be lower-case,
# so give that a shot here.
module_jar = self.get_resource(manifest.name.lower() + '.jar')
if os.path.exists(module_jar):
self.jar = module_jar
self.lib = None
module_lib = self.get_resource('lib%s.a' % manifest.moduleid)
if os.path.exists(module_lib):
self.lib = module_lib
self.xml = None
module_xml = self.get_resource('timodule.xml')
if os.path.exists(module_xml):
self.xml = TiAppXML(module_xml, parse_only=True)
self.js = None
module_js = self.get_resource('%s.js' % manifest.moduleid)
if os.path.exists(module_js):
self.js = module_js
def get_resource(self, *path):
return os.path.join(self.path, *path)
class ModuleDetector(object):
def __init__(self, project_dir):
self.project_dir = project_dir
self.modules = self.detect_modules()
def auto_install_modules(self, dir):
for module_zip in glob.glob(os.path.join(dir, '*-*-*.zip')):
# in development we store mobilesdk zips in the same place that module zips go
if os.path.basename(module_zip).startswith('mobilesdk-'):
continue
print '[INFO] Installing module: %s' % module_zip
module_zf = zipfile.ZipFile(module_zip)
for name in module_zf.namelist():
if name.endswith('/'): continue
destdir = os.path.join(dir, os.path.dirname(name.replace('/', os.path.sep)))
if not os.path.exists(destdir):
os.makedirs(destdir)
destfile = open(os.path.join(destdir, os.path.basename(name)), 'wb')
destfile.write(module_zf.read(name))
destfile.close()
module_zf.close()
os.remove(module_zip)
def get_modules(self, modules_dir, auto_install=True):
print '[DEBUG] Detecting modules in %s' % modules_dir
modules = []
if auto_install:
parent_dir = os.path.dirname(os.path.abspath(modules_dir))
self.auto_install_modules(parent_dir)
if not os.path.exists(modules_dir): return modules
for platform in os.listdir(modules_dir):
platform_dir = os.path.join(modules_dir, platform)
if not os.path.isdir(platform_dir): continue
if platform in ['osx', 'win32', 'linux']: continue # skip desktop modules
# iterate through the platform directory so we can get versioned modules too
for root, dirs, files in os.walk(platform_dir):
dirs.sort(reverse=True)
for module_dir in dirs:
module_dir = os.path.join(root, module_dir)
manifest_file = os.path.join(module_dir, 'manifest')
if not os.path.exists(manifest_file): continue
manifest = Manifest(manifest_file)
print '[DEBUG] Detected module for %s: %s %s @ %s' % (manifest.platform, manifest.moduleid, manifest.version, module_dir)
modules.append(Module(module_dir, manifest))
return modules
def detect_modules(self):
system_modules_dir = os.path.abspath(os.path.join(sdk_dir, '..', '..', '..', 'modules'))
modules = self.get_modules(os.path.join(self.project_dir, 'modules'))
modules.extend(self.get_modules(system_modules_dir, auto_install=True))
return modules
def is_any(self, module_dep, property):
value = module_dep[property]
return value == None or value == ''
def get_desc(self, module_dep, property):
if self.is_any(module_dep, property):
return '<any %s>' % property
return module_dep[property]
def find_app_modules(self, tiapp, platform, app_deploy_type):
missing = []
modules = []
if 'modules' not in tiapp.properties: return missing, modules
for module_dep in tiapp.properties['modules']:
module_platform = module_dep.get('platform')
if not self.is_any(module_dep, 'platform') and \
module_platform != 'commonjs' and \
module_platform != platform:
continue
version_desc = self.get_desc(module_dep, 'version')
platform_desc = self.get_desc(module_dep, 'platform')
print '[DEBUG] Looking for Titanium Module id: %s, version: %s, platform: %s' % (module_dep['id'], version_desc, platform_desc)
module = self.find_module(id=module_dep['id'], version=module_dep['version'], platform=module_dep['platform'])
if module == None:
print '[WARN] Could not find Titanium Module id: %s, version: %s, platform: %s' % (module_dep['id'], version_desc, platform_desc)
missing.append(module_dep)
else:
valid_module_already_exists = 0
for i in range(len(modules)):
stored_module = modules[i]
# find a duplicate instance of the module already stored
if (stored_module.manifest.moduleid == module.manifest.moduleid) and \
(stored_module.manifest.platform == module.manifest.platform):
# does the new module have a "real" deploy type set?
if module_dep['deploy-type']:
# if the stored module has a default deploy type and the new module has a real deploy type
# make sure the stored module is still valid. IE: the default only works for !production
# when other entries for this module have a real deploy type so the stored module must be
# removed
if (stored_module.deploy_type == None) and (app_deploy_type == 'production'):
# remove the stored module from the stored list
del modules[i]
else:
valid_module_already_exists = 1
else:
valid_module_already_exists = 1
break
if valid_module_already_exists == 0:
is_valid_deploy_type = 0
# if the module doesn't have a "real" deploy type set then it is valid for all app
# deploy types
if module_dep['deploy-type']:
# make sure that the specified module deploy type is valid based on the deploy type of the app
if ((app_deploy_type == 'production') and (module_dep['deploy-type'] == 'production')) or \
((app_deploy_type != 'production') and (module_dep['deploy-type'] != 'production')):
is_valid_deploy_type = 1
else:
print '[DEBUG] Not including module as there is no valid module deploy type for the app deploy type: %s' % app_deploy_type
else:
is_valid_deploy_type = 1
if is_valid_deploy_type:
module.deploy_type = module_dep['deploy-type']
modules.append(module)
return missing, modules
def find_module(self, id, name=None, version=None, platform=None):
for module in self.modules:
manifest = module.manifest
id_matches = manifest.moduleid == id
name_matches = name == None or name == "" or manifest.name == name
version_matches = version == None or version == "" or manifest.version == version
platform_matches = platform == None or platform == "" or manifest.platform == platform
if id_matches and name_matches and version_matches and platform_matches:
return module
return None
def usage(prop,required,optional=None):
print "Couldn't find required '%s' argument" % prop
print
print "Usage: %s <options>" % os.path.basename(sys.argv[0])
print
print "Required arguments:\n"
for key in required:
disp = key + ' <value>'
print " --%s %s" % (string.ljust(disp,20),required[key])
if optional:
print
print "Optional arguments:\n"
for key in optional:
disp = key + ' <value>'
print " --%s %s" % (string.ljust(disp,20),optional[key])
sys.exit(1)
def sysargs_to_dict(args,required=None,optional=None):
c = 1
props = {}
while c < len(args):
key = args[c]
if key[0:2]=='--': key = key[2:]
value = None
if c + 1 < len(args):
value = args[c+1]
props[key]=value
c = c + 2
if required:
for key in required:
if not props.has_key(key):
usage(key, required, optional)
return props
def camelcase(value):
return "".join([capitalize(w) for w in re.split(re.compile("[\W_]*"), value)])
def main(args):
required_opts = {
'name':'the name of the module',
'directory':'the directory to create the module',
'platform':'the platform: such as android, iphone, blackberry, etc',
'id':'the module id in dotted notation: such as com.yourcompany.foo'
}
optional_opts = {
'sdk':'the platform sdk path'
}
config = sysargs_to_dict(args,required_opts,optional_opts)
module_name = config['name']
project_dir = os.path.join(os.path.abspath(os.path.expanduser(config['directory'])),module_name)
if os.path.exists(project_dir):
print "Error. Directory already exists: %s" % project_dir
sys.exit(1)
module = ModuleProject(config['platform'],project_dir,config)
if __name__ == "__main__":
main(sys.argv)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
221,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
5673,
7290,
2790,
14914,
199,
3,
199,
199,
646,
747,
12,
984,
12,
5145,
12,
1059,
12,
5377,
12,
295,
12,
10392,
12,
5739,
199,
504,
1059,
492,
17094,
794,
199,
504,
5228,
492,
5228,
199,
504,
2197,
492,
1434,
199,
199,
1160,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
8,
1274,
423,
20912,
8,
16,
680,
70,
63,
600,
14,
331,
63,
1501,
430,
199,
9277,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
1160,
63,
694,
9,
199,
1274,
14,
515,
14,
740,
8,
9277,
63,
694,
9,
199,
504,
7712,
492,
4688,
3944,
199,
504,
3367,
571,
492,
377,
73,
2640,
4317,
199,
199,
4247,
5535,
275,
18953,
71,
5277,
7160,
297,
1987,
5107,
1037,
720,
297,
1987,
3177,
63,
5502,
418,
27,
199,
4247,
17051,
275,
18953,
3187,
26409,
6836,
1673,
63,
6836,
1673,
35,
7428,
418,
27,
199,
2865,
4131,
5535,
275,
18953,
4524,
26409,
14513,
26409,
8476,
26409,
3065,
26409,
65,
26409,
79,
297,
1987,
7338,
418,
199,
199,
533,
5673,
10397,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
12,
2199,
63,
694,
12,
1101,
12,
859,
304,
507,
198,
277,
14,
1715,
63,
694,
275,
2199,
63,
694,
507,
198,
277,
14,
888,
275,
1101,
507,
198,
277,
14,
578,
275,
859,
8299,
198,
32,
3744,
199,
198,
318,
1218,
63,
3246,
8,
1886,
12,
4298,
12,
2199,
63,
694,
12,
1101,
12,
859,
304,
507,
198,
3246,
275,
4298,
14,
2325,
342,
507,
198,
3246,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1160,
63,
694,
12,
4298,
9,
507,
198,
1274,
14,
515,
14,
740,
8,
3246,
63,
694,
9,
507,
198,
3246,
63,
578,
63,
533,
275,
2519,
3460,
646,
721,
3246,
395,
4298,
9,
507,
198,
1107,
4298,
63,
578,
63,
533,
8,
1715,
63,
694,
12,
1101,
12,
859,
9,
8299,
198,
318,
3350,
63,
4504,
8,
277,
12,
1059,
304,
507,
198,
1107,
1059,
8299,
198,
318,
664,
63,
493,
63,
2614,
8,
277,
12,
370,
63,
515,
304,
507,
198,
1107,
370,
63,
515,
18118,
198,
318,
664,
63,
71,
5277,
7160,
8,
277,
304,
507,
198,
1107,
942,
8299,
198,
318,
9158,
8,
277,
304,
507,
198,
1529,
507,
199,
533,
5673,
4761,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
12,
3246,
12,
1715,
63,
694,
12,
888,
304,
507,
198,
277,
14,
1715,
63,
3612,
63,
354,
275,
1101,
459,
354,
418,
507,
198,
277,
14,
1715,
63,
354,
275,
1101,
459,
354,
418,
507,
198,
277,
14,
3246,
275,
4298,
507,
198,
277,
14,
578,
63,
344,
275,
1101,
459,
344,
418,
507,
198,
277,
14,
578,
63,
354,
275,
291,
14,
4208,
63,
578,
63,
354,
8,
277,
14,
578,
63,
344,
9,
507,
198,
277,
14,
9277,
63,
1023,
275,
747,
14,
515,
14,
4846,
8,
9277,
63,
694,
9,
507,
198,
277,
14,
9473,
275,
620,
8,
2580,
14,
2580,
20,
1012,
507,
198,
277,
14,
1715,
63,
694,
275,
2199,
63,
694,
507,
198,
277,
14,
578,
63,
354,
63,
22997,
275,
31129,
2546,
8,
277,
14,
1715,
63,
354,
9,
507,
198,
277,
14,
9277,
275,
488,
507,
198,
692,
1101,
14,
1989,
63,
498,
360,
9277,
735,
686,
198,
277,
14,
9277,
275,
1101,
459,
9277,
418,
28550,
198,
277,
14,
3246,
63,
15286,
275,
5673,
10397,
14,
981,
63,
3246,
8,
3246,
12,
2199,
63,
694,
12,
1101,
12,
291,
9,
507,
198,
3246,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1160,
63,
694,
12,
4298,
14,
2325,
1012,
9068,
198,
452,
63,
5876,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1160,
63,
694,
2584,
452,
358,
507,
198,
692,
747,
14,
515,
14,
2444,
8,
452,
63,
5876,
63,
694,
304,
686,
198,
277,
14,
1574,
63,
1160,
63,
1725,
8,
452,
63,
5876,
63,
694,
9,
2742,
198,
5876,
63,
694,
275,
747,
14,
515,
14,
904,
8,
3246,
63,
694,
2584,
5876,
358,
507,
198,
692,
747,
14,
515,
14,
2444,
8,
5876,
63,
694,
304,
686,
198,
277,
14,
1574,
63,
1160,
63,
1725,
8,
5876,
63,
694,
9,
2742,
198,
277,
14,
4208,
63,
71,
5277,
7160,
342,
507,
198,
277,
14,
3246,
63,
15286,
14,
8669,
342,
8299,
198,
318,
3350,
63,
4504,
8,
277,
12,
1059,
304,
507,
198,
875,
275,
1059,
14,
1814,
360,
8989,
10797,
2339,
1179,
22698,
8989,
297,
277,
14,
578,
63,
354,
9,
507,
198,
875,
275,
1059,
14,
1814,
360,
8989,
10001,
63,
2339,
63,
35,
1991,
44,
8989,
297,
291,
14,
578,
63,
354,
63,
22997,
9,
507,
198,
875,
275,
1059,
14,
1814,
360,
8989,
10001,
63,
998,
63,
1179,
63,
19041,
8989,
297,
291,
14,
578,
63,
344,
14,
1814,
14078,
747,
14,
515,
14,
4127,
430,
507,
198,
875,
275,
1059,
14,
1814,
360,
8989,
10797,
2339,
8989,
297,
277,
14,
1715,
63,
354,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
10001,
63,
998,
7500,
277,
14,
578,
63,
344,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
10797,
63,
13003,
63,
2339,
7500,
277,
14,
1715,
63,
3612,
63,
354,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
10797,
63,
13003,
63,
2339,
63,
5896,
540,
7500,
277,
14,
1715,
63,
3612,
63,
354,
14,
2325,
1012,
507,
198,
875,
275,
1059,
14,
1814,
10714,
4612,
7500,
277,
14,
9277,
63,
1023,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
14939,
7500,
9277,
63,
694,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
14939,
63,
5441,
7500,
736,
14,
515,
14,
1294,
8,
9277,
63,
694,
2788,
16,
1055,
1814,
8,
736,
14,
515,
14,
12131,
21114,
659,
27547,
297,
17,
430,
507,
198,
875,
275,
1059,
14,
1814,
10714,
17805,
7500,
277,
14,
3246,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
17856,
7500,
277,
14,
9473,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
19216,
7500,
620,
8,
602,
14,
8136,
1252
] |
[
2647,
15,
1393,
15,
1813,
2366,
221,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
5673,
7290,
2790,
14914,
199,
3,
199,
199,
646,
747,
12,
984,
12,
5145,
12,
1059,
12,
5377,
12,
295,
12,
10392,
12,
5739,
199,
504,
1059,
492,
17094,
794,
199,
504,
5228,
492,
5228,
199,
504,
2197,
492,
1434,
199,
199,
1160,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
8,
1274,
423,
20912,
8,
16,
680,
70,
63,
600,
14,
331,
63,
1501,
430,
199,
9277,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
1160,
63,
694,
9,
199,
1274,
14,
515,
14,
740,
8,
9277,
63,
694,
9,
199,
504,
7712,
492,
4688,
3944,
199,
504,
3367,
571,
492,
377,
73,
2640,
4317,
199,
199,
4247,
5535,
275,
18953,
71,
5277,
7160,
297,
1987,
5107,
1037,
720,
297,
1987,
3177,
63,
5502,
418,
27,
199,
4247,
17051,
275,
18953,
3187,
26409,
6836,
1673,
63,
6836,
1673,
35,
7428,
418,
27,
199,
2865,
4131,
5535,
275,
18953,
4524,
26409,
14513,
26409,
8476,
26409,
3065,
26409,
65,
26409,
79,
297,
1987,
7338,
418,
199,
199,
533,
5673,
10397,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
12,
2199,
63,
694,
12,
1101,
12,
859,
304,
507,
198,
277,
14,
1715,
63,
694,
275,
2199,
63,
694,
507,
198,
277,
14,
888,
275,
1101,
507,
198,
277,
14,
578,
275,
859,
8299,
198,
32,
3744,
199,
198,
318,
1218,
63,
3246,
8,
1886,
12,
4298,
12,
2199,
63,
694,
12,
1101,
12,
859,
304,
507,
198,
3246,
275,
4298,
14,
2325,
342,
507,
198,
3246,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1160,
63,
694,
12,
4298,
9,
507,
198,
1274,
14,
515,
14,
740,
8,
3246,
63,
694,
9,
507,
198,
3246,
63,
578,
63,
533,
275,
2519,
3460,
646,
721,
3246,
395,
4298,
9,
507,
198,
1107,
4298,
63,
578,
63,
533,
8,
1715,
63,
694,
12,
1101,
12,
859,
9,
8299,
198,
318,
3350,
63,
4504,
8,
277,
12,
1059,
304,
507,
198,
1107,
1059,
8299,
198,
318,
664,
63,
493,
63,
2614,
8,
277,
12,
370,
63,
515,
304,
507,
198,
1107,
370,
63,
515,
18118,
198,
318,
664,
63,
71,
5277,
7160,
8,
277,
304,
507,
198,
1107,
942,
8299,
198,
318,
9158,
8,
277,
304,
507,
198,
1529,
507,
199,
533,
5673,
4761,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
12,
3246,
12,
1715,
63,
694,
12,
888,
304,
507,
198,
277,
14,
1715,
63,
3612,
63,
354,
275,
1101,
459,
354,
418,
507,
198,
277,
14,
1715,
63,
354,
275,
1101,
459,
354,
418,
507,
198,
277,
14,
3246,
275,
4298,
507,
198,
277,
14,
578,
63,
344,
275,
1101,
459,
344,
418,
507,
198,
277,
14,
578,
63,
354,
275,
291,
14,
4208,
63,
578,
63,
354,
8,
277,
14,
578,
63,
344,
9,
507,
198,
277,
14,
9277,
63,
1023,
275,
747,
14,
515,
14,
4846,
8,
9277,
63,
694,
9,
507,
198,
277,
14,
9473,
275,
620,
8,
2580,
14,
2580,
20,
1012,
507,
198,
277,
14,
1715,
63,
694,
275,
2199,
63,
694,
507,
198,
277,
14,
578,
63,
354,
63,
22997,
275,
31129,
2546,
8,
277,
14,
1715,
63,
354,
9,
507,
198,
277,
14,
9277,
275,
488,
507,
198,
692,
1101,
14,
1989,
63,
498,
360,
9277,
735,
686,
198,
277,
14,
9277,
275,
1101,
459,
9277,
418,
28550,
198,
277,
14,
3246,
63,
15286,
275,
5673,
10397,
14,
981,
63,
3246,
8,
3246,
12,
2199,
63,
694,
12,
1101,
12,
291,
9,
507,
198,
3246,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1160,
63,
694,
12,
4298,
14,
2325,
1012,
9068,
198,
452,
63,
5876,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1160,
63,
694,
2584,
452,
358,
507,
198,
692,
747,
14,
515,
14,
2444,
8,
452,
63,
5876,
63,
694,
304,
686,
198,
277,
14,
1574,
63,
1160,
63,
1725,
8,
452,
63,
5876,
63,
694,
9,
2742,
198,
5876,
63,
694,
275,
747,
14,
515,
14,
904,
8,
3246,
63,
694,
2584,
5876,
358,
507,
198,
692,
747,
14,
515,
14,
2444,
8,
5876,
63,
694,
304,
686,
198,
277,
14,
1574,
63,
1160,
63,
1725,
8,
5876,
63,
694,
9,
2742,
198,
277,
14,
4208,
63,
71,
5277,
7160,
342,
507,
198,
277,
14,
3246,
63,
15286,
14,
8669,
342,
8299,
198,
318,
3350,
63,
4504,
8,
277,
12,
1059,
304,
507,
198,
875,
275,
1059,
14,
1814,
360,
8989,
10797,
2339,
1179,
22698,
8989,
297,
277,
14,
578,
63,
354,
9,
507,
198,
875,
275,
1059,
14,
1814,
360,
8989,
10001,
63,
2339,
63,
35,
1991,
44,
8989,
297,
291,
14,
578,
63,
354,
63,
22997,
9,
507,
198,
875,
275,
1059,
14,
1814,
360,
8989,
10001,
63,
998,
63,
1179,
63,
19041,
8989,
297,
291,
14,
578,
63,
344,
14,
1814,
14078,
747,
14,
515,
14,
4127,
430,
507,
198,
875,
275,
1059,
14,
1814,
360,
8989,
10797,
2339,
8989,
297,
277,
14,
1715,
63,
354,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
10001,
63,
998,
7500,
277,
14,
578,
63,
344,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
10797,
63,
13003,
63,
2339,
7500,
277,
14,
1715,
63,
3612,
63,
354,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
10797,
63,
13003,
63,
2339,
63,
5896,
540,
7500,
277,
14,
1715,
63,
3612,
63,
354,
14,
2325,
1012,
507,
198,
875,
275,
1059,
14,
1814,
10714,
4612,
7500,
277,
14,
9277,
63,
1023,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
14939,
7500,
9277,
63,
694,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
14939,
63,
5441,
7500,
736,
14,
515,
14,
1294,
8,
9277,
63,
694,
2788,
16,
1055,
1814,
8,
736,
14,
515,
14,
12131,
21114,
659,
27547,
297,
17,
430,
507,
198,
875,
275,
1059,
14,
1814,
10714,
17805,
7500,
277,
14,
3246,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
17856,
7500,
277,
14,
9473,
9,
507,
198,
875,
275,
1059,
14,
1814,
10714,
19216,
7500,
620,
8,
602,
14,
8136,
1252,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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python
#pylint: disable=missing-docstring
#################################################################
# DO NOT MODIFY THIS HEADER #
# MOOSE - Multiphysics Object Oriented Simulation Environment #
# #
# (c) 2010 Battelle Energy Alliance, LLC #
# ALL RIGHTS RESERVED #
# #
# Prepared by Battelle Energy Alliance, LLC #
# Under Contract No. DE-AC07-05ID14517 #
# With the U. S. Department of Energy #
# #
# See COPYRIGHT for full restrictions #
#################################################################
import chigger
reader = chigger.exodus.ExodusReader('../input/mug_blocks_out.e')
mug = chigger.exodus.ExodusResult(reader, color=[1,0,0])
window = chigger.RenderWindow(mug, size=[300,300], test=True)
window.write('color.png')
window.start()
|
lgpl-2.1
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
26324,
26,
3507,
29,
4752,
13,
12485,
199,
3060,
3,
199,
3,
7861,
3506,
2845,
10362,
1914,
18114,
5749,
13053,
540,
7861,
327,
199,
3,
221,
603,
5757,
899,
446,
6879,
24724,
6935,
593,
322,
287,
471,
10751,
5332,
9711,
221,
327,
199,
3,
2476,
17388,
327,
199,
3,
3322,
334,
67,
9,
7129,
699,
292,
14146,
274,
662,
1372,
4312,
4580,
3636,
12,
20376,
3777,
327,
199,
3,
10473,
11727,
7052,
51,
12565,
540,
14112,
10473,
327,
199,
3,
2476,
17388,
327,
199,
3,
3698,
5543,
9508,
701,
699,
292,
14146,
274,
662,
1372,
4312,
4580,
3636,
12,
20376,
3698,
327,
199,
3,
3777,
25010,
1448,
6908,
3091,
14,
3265,
13,
1348,
1780,
13,
1717,
998,
11731,
1196,
4519,
327,
199,
3,
4519,
8777,
314,
738,
14,
428,
14,
1487,
12493,
402,
662,
1372,
4312,
4519,
327,
199,
3,
2476,
17388,
327,
199,
3,
4519,
1666,
5877,
367,
2615,
24488,
4519,
327,
199,
3060,
3,
199,
646,
682,
528,
836,
199,
5503,
275,
682,
528,
836,
14,
476,
364,
527,
14,
920,
364,
527,
5929,
24592,
1210,
15,
77,
1518,
63,
4166,
63,
548,
14,
69,
358,
199,
77,
1518,
275,
682,
528,
836,
14,
476,
364,
527,
14,
920,
364,
527,
2889,
8,
5503,
12,
3164,
1524,
17,
12,
16,
12,
16,
566,
199,
3806,
275,
682,
528,
836,
14,
9216,
4301,
8,
77,
1518,
12,
1568,
1524,
5863,
12,
5863,
467,
511,
29,
549,
9,
199,
3806,
14,
952,
360,
2326,
14,
4524,
358,
199,
3806,
14,
928,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
26324,
26,
3507,
29,
4752,
13,
12485,
199,
3060,
3,
199,
3,
7861,
3506,
2845,
10362,
1914,
18114,
5749,
13053,
540,
7861,
327,
199,
3,
221,
603,
5757,
899,
446,
6879,
24724,
6935,
593,
322,
287,
471,
10751,
5332,
9711,
221,
327,
199,
3,
2476,
17388,
327,
199,
3,
3322,
334,
67,
9,
7129,
699,
292,
14146,
274,
662,
1372,
4312,
4580,
3636,
12,
20376,
3777,
327,
199,
3,
10473,
11727,
7052,
51,
12565,
540,
14112,
10473,
327,
199,
3,
2476,
17388,
327,
199,
3,
3698,
5543,
9508,
701,
699,
292,
14146,
274,
662,
1372,
4312,
4580,
3636,
12,
20376,
3698,
327,
199,
3,
3777,
25010,
1448,
6908,
3091,
14,
3265,
13,
1348,
1780,
13,
1717,
998,
11731,
1196,
4519,
327,
199,
3,
4519,
8777,
314,
738,
14,
428,
14,
1487,
12493,
402,
662,
1372,
4312,
4519,
327,
199,
3,
2476,
17388,
327,
199,
3,
4519,
1666,
5877,
367,
2615,
24488,
4519,
327,
199,
3060,
3,
199,
646,
682,
528,
836,
199,
5503,
275,
682,
528,
836,
14,
476,
364,
527,
14,
920,
364,
527,
5929,
24592,
1210,
15,
77,
1518,
63,
4166,
63,
548,
14,
69,
358,
199,
77,
1518,
275,
682,
528,
836,
14,
476,
364,
527,
14,
920,
364,
527,
2889,
8,
5503,
12,
3164,
1524,
17,
12,
16,
12,
16,
566,
199,
3806,
275,
682,
528,
836,
14,
9216,
4301,
8,
77,
1518,
12,
1568,
1524,
5863,
12,
5863,
467,
511,
29,
549,
9,
199,
3806,
14,
952,
360,
2326,
14,
4524,
358,
199,
3806,
14,
928,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,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
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
husk00/audiogames
|
2.1-argentina/src/lib/readgamestart.py
|
3
|
1784
|
# readgamestart.py
import GameLogic
import socket
import OSC
import Game
import bge
def receive_osc(data, port):
try:
# getting first data value from buffer
data, port = GameLogic.socket.recvfrom(1024)
# keep trying to get new data until buffer is empty
try:
trash = data
while True:
data = trash
trash, port = GameLogic.socket.recvfrom(1024)
# print deleted values
#print ("trash= ", trash)
except:
# we force this exception to happen
# that way we know the buffer is empty
pass
except Exception as E:
pass
return data
def main():
# Get controller and owner
controller = GameLogic.getCurrentController()
owner = controller.owner
# Set init
ip = '127.0.0.1' ### escucha router
port = 8889
data = 0
# Connect Blender only one time
if not owner['connected']:
owner['connected'] = True
print ("Blender Connected game_start ", owner.name)
print(port)
GameLogic.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
GameLogic.socket.bind((ip, port))
GameLogic.socket.setblocking(0)
GameLogic.socket.settimeout(0.02)
# If Blender connected, get osc
else:
# Get hand wii osc from pd
data = receive_osc(data, port)
#print(data)
if data != 0:
d = OSC.decodeOSC(data)
#print("decoded: ",d)
if d[0] == "/game/start":
#print ("start",d[2])
if d[2] == 1:
Game.start = True
if d[2] == 0:
Game.start = False
|
gpl-3.0
|
[
3,
1586,
5097,
928,
14,
647,
199,
646,
25132,
32140,
199,
646,
2838,
199,
646,
4403,
35,
199,
646,
25132,
199,
646,
330,
303,
199,
199,
318,
9128,
63,
26737,
8,
576,
12,
1844,
304,
272,
862,
26,
267,
327,
10232,
1642,
666,
574,
687,
3335,
267,
666,
12,
1844,
275,
25132,
32140,
14,
3450,
14,
7637,
504,
8,
7727,
9,
523,
267,
327,
4215,
9936,
370,
664,
892,
666,
5133,
3335,
365,
2701,
267,
862,
26,
288,
5651,
1119,
275,
666,
288,
1830,
715,
26,
355,
666,
275,
5651,
1119,
355,
5651,
1119,
12,
1844,
275,
25132,
32140,
14,
3450,
14,
7637,
504,
8,
7727,
9,
355,
327,
870,
5463,
1338,
355,
327,
1361,
1689,
28272,
29,
3872,
5651,
1119,
9,
267,
871,
26,
288,
327,
781,
3542,
642,
1919,
370,
5992,
288,
327,
626,
4340,
781,
5715,
314,
3335,
365,
2701,
288,
986,
20950,
871,
2186,
465,
662,
26,
267,
986,
20950,
372,
666,
199,
199,
318,
2446,
837,
272,
327,
2372,
7614,
436,
5771,
272,
7614,
275,
25132,
32140,
14,
16662,
7506,
342,
272,
5771,
275,
7614,
14,
4597,
2286,
327,
2494,
4205,
272,
3384,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
221,
6754,
14683,
2133,
65,
6197,
272,
1844,
275,
10523,
1407,
5493,
666,
275,
378,
13857,
327,
15175,
699,
24912,
1454,
1373,
900,
272,
340,
440,
5771,
459,
7113,
2565,
2728,
5771,
459,
7113,
418,
275,
715,
267,
870,
1689,
34,
24912,
1448,
4636,
9219,
63,
928,
3872,
5771,
14,
354,
9,
267,
870,
8,
719,
9,
267,
25132,
32140,
14,
3450,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
9,
267,
25132,
32140,
14,
3450,
14,
3409,
1332,
711,
12,
1844,
430,
267,
25132,
32140,
14,
3450,
14,
409,
13091,
8,
16,
9,
267,
25132,
32140,
14,
3450,
14,
24630,
8,
16,
14,
996,
9,
2541,
272,
327,
982,
699,
24912,
8539,
12,
664,
31920,
272,
587,
26,
267,
327,
2372,
4926,
336,
5908,
31920,
687,
6454,
267,
666,
275,
9128,
63,
26737,
8,
576,
12,
1844,
9,
267,
327,
1361,
8,
576,
9,
267,
340,
666,
1137,
378,
26,
288,
366,
275,
4403,
35,
14,
2708,
31799,
8,
576,
9,
288,
327,
1361,
480,
16167,
26,
3872,
68,
9,
288,
340,
366,
59,
16,
61,
508,
3286,
5097,
15,
928,
582,
355,
327,
1361,
1689,
928,
401,
68,
59,
18,
566,
355,
340,
366,
59,
18,
61,
508,
413,
26,
490,
25132,
14,
928,
275,
715,
355,
340,
366,
59,
18,
61,
508,
378,
26,
490,
25132,
14,
928,
275,
756,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1586,
5097,
928,
14,
647,
199,
646,
25132,
32140,
199,
646,
2838,
199,
646,
4403,
35,
199,
646,
25132,
199,
646,
330,
303,
199,
199,
318,
9128,
63,
26737,
8,
576,
12,
1844,
304,
272,
862,
26,
267,
327,
10232,
1642,
666,
574,
687,
3335,
267,
666,
12,
1844,
275,
25132,
32140,
14,
3450,
14,
7637,
504,
8,
7727,
9,
523,
267,
327,
4215,
9936,
370,
664,
892,
666,
5133,
3335,
365,
2701,
267,
862,
26,
288,
5651,
1119,
275,
666,
288,
1830,
715,
26,
355,
666,
275,
5651,
1119,
355,
5651,
1119,
12,
1844,
275,
25132,
32140,
14,
3450,
14,
7637,
504,
8,
7727,
9,
355,
327,
870,
5463,
1338,
355,
327,
1361,
1689,
28272,
29,
3872,
5651,
1119,
9,
267,
871,
26,
288,
327,
781,
3542,
642,
1919,
370,
5992,
288,
327,
626,
4340,
781,
5715,
314,
3335,
365,
2701,
288,
986,
20950,
871,
2186,
465,
662,
26,
267,
986,
20950,
372,
666,
199,
199,
318,
2446,
837,
272,
327,
2372,
7614,
436,
5771,
272,
7614,
275,
25132,
32140,
14,
16662,
7506,
342,
272,
5771,
275,
7614,
14,
4597,
2286,
327,
2494,
4205,
272,
3384,
275,
283,
4195,
14,
16,
14,
16,
14,
17,
7,
221,
6754,
14683,
2133,
65,
6197,
272,
1844,
275,
10523,
1407,
5493,
666,
275,
378,
13857,
327,
15175,
699,
24912,
1454,
1373,
900,
272,
340,
440,
5771,
459,
7113,
2565,
2728,
5771,
459,
7113,
418,
275,
715,
267,
870,
1689,
34,
24912,
1448,
4636,
9219,
63,
928,
3872,
5771,
14,
354,
9,
267,
870,
8,
719,
9,
267,
25132,
32140,
14,
3450,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
9,
267,
25132,
32140,
14,
3450,
14,
3409,
1332,
711,
12,
1844,
430,
267,
25132,
32140,
14,
3450,
14,
409,
13091,
8,
16,
9,
267,
25132,
32140,
14,
3450,
14,
24630,
8,
16,
14,
996,
9,
2541,
272,
327,
982,
699,
24912,
8539,
12,
664,
31920,
272,
587,
26,
267,
327,
2372,
4926,
336,
5908,
31920,
687,
6454,
267,
666,
275,
9128,
63,
26737,
8,
576,
12,
1844,
9,
267,
327,
1361,
8,
576,
9,
267,
340,
666,
1137,
378,
26,
288,
366,
275,
4403,
35,
14,
2708,
31799,
8,
576,
9,
288,
327,
1361,
480,
16167,
26,
3872,
68,
9,
288,
340,
366,
59,
16,
61,
508,
3286,
5097,
15,
928,
582,
355,
327,
1361,
1689,
928,
401,
68,
59,
18,
566,
355,
340,
366,
59,
18,
61,
508,
413,
26,
490,
25132,
14,
928,
275,
715,
355,
340,
366,
59,
18,
61,
508,
378,
26,
490,
25132,
14,
928,
275,
756,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
uwosh/UWOshCommitteeOnCommittees
|
content/College.py
|
1
|
3093
|
# -*- coding: utf-8 -*-
#
# File: College.py
#
# Copyright (c) 2007 by []
# Generator: ArchGenXML Version 1.5.2
# http://plone.org/products/archgenxml
#
# GNU General Public License (GPL)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA.
#
__author__ = """unknown <unknown>"""
__docformat__ = 'plaintext'
from AccessControl import ClassSecurityInfo
from Products.Archetypes.atapi import *
from Products.UWOshCommitteeOnCommittees.content.Constituency import Constituency
from Products.ATBackRef.BackReferenceField import BackReferenceField, BackReferenceWidget
from Products.UWOshCommitteeOnCommittees.config import *
##code-section module-header #fill in your manual code here
##/code-section module-header
schema = Schema((
ReferenceField(
name='departments',
widget=ReferenceWidget(
label='Departments',
label_msgid='UWOshCommitteeOnCommittees_label_departments',
i18n_domain='UWOshCommitteeOnCommittees',
),
allowed_types=('Department',),
multiValued=1,
relationship='college_department'
),
),
)
##code-section after-local-schema #fill in your manual code here
##/code-section after-local-schema
College_schema = BaseFolderSchema.copy() + \
getattr(Constituency, 'schema', Schema(())).copy() + \
schema.copy()
##code-section after-schema #fill in your manual code here
##/code-section after-schema
class College(BaseFolder, Constituency):
"""
"""
security = ClassSecurityInfo()
__implements__ = (getattr(BaseFolder,'__implements__',()),) + (getattr(Constituency,'__implements__',()),)
# This name appears in the 'add' box
archetype_name = 'College'
meta_type = 'College'
portal_type = 'College'
allowed_content_types = ['Division'] + list(getattr(Constituency, 'allowed_content_types', []))
filter_content_types = 1
global_allow = 1
#content_icon = 'College.gif'
immediate_view = 'base_view'
default_view = 'base_view'
suppl_views = ()
typeDescription = "College"
typeDescMsgId = 'description_edit_college'
_at_rename_after_creation = True
schema = College_schema
##code-section class-header #fill in your manual code here
##/code-section class-header
# Methods
registerType(College, PROJECTNAME)
# end of class College
##code-section module-footer #fill in your manual code here
##/code-section module-footer
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3814,
26,
3626,
274,
303,
14,
647,
199,
3,
199,
3,
1898,
334,
67,
9,
10219,
701,
942,
199,
3,
15042,
26,
19521,
8168,
4317,
3394,
413,
14,
21,
14,
18,
199,
3,
3322,
1455,
921,
1168,
368,
14,
1308,
15,
13336,
15,
1047,
2268,
1652,
199,
3,
199,
3,
1664,
1696,
1684,
844,
334,
12006,
9,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
199,
363,
2502,
363,
275,
408,
5187,
665,
5187,
11193,
199,
363,
21841,
363,
275,
283,
17426,
7,
199,
199,
504,
11003,
3717,
492,
8089,
7676,
2354,
199,
504,
32411,
14,
1596,
595,
1313,
14,
419,
1038,
492,
627,
199,
504,
32411,
14,
53,
11325,
609,
11421,
15557,
3314,
11421,
266,
397,
14,
1317,
14,
714,
6329,
85,
9501,
492,
1448,
6329,
85,
9501,
199,
504,
32411,
14,
619,
4540,
2891,
14,
4540,
5083,
792,
492,
10257,
5083,
792,
12,
10257,
5083,
3339,
199,
504,
32411,
14,
53,
11325,
609,
11421,
15557,
3314,
11421,
266,
397,
14,
888,
492,
627,
199,
199,
309,
600,
13,
2792,
859,
13,
1291,
327,
4498,
315,
2195,
8722,
1233,
2348,
199,
309,
15,
600,
13,
2792,
859,
13,
1291,
199,
199,
3629,
275,
13268,
1332,
339,
10944,
792,
8,
267,
536,
534,
27532,
1470,
297,
267,
3938,
29,
5083,
3339,
8,
288,
1768,
534,
872,
2064,
1470,
297,
288,
1768,
63,
15245,
534,
53,
11325,
609,
11421,
15557,
3314,
11421,
266,
397,
63,
1302,
63,
27532,
1470,
297,
288,
284,
1085,
78,
63,
2261,
534,
53,
11325,
609,
11421,
15557,
3314,
11421,
266,
397,
297,
267,
2318,
267,
4370,
63,
1313,
7782,
872,
12493,
5529,
267,
3510,
1110,
68,
29,
17,
12,
267,
8931,
534,
761,
274,
303,
63,
19623,
7,
272,
2318,
199,
199,
395,
199,
9,
199,
199,
309,
600,
13,
2792,
2410,
13,
1832,
13,
3629,
327,
4498,
315,
2195,
8722,
1233,
2348,
199,
309,
15,
600,
13,
2792,
2410,
13,
1832,
13,
3629,
199,
199,
2001,
274,
303,
63,
3629,
275,
3523,
7850,
6700,
14,
1574,
342,
435,
971,
272,
2519,
8,
714,
6329,
85,
9501,
12,
283,
3629,
297,
13268,
8,
4059,
14,
1574,
342,
435,
971,
272,
4177,
14,
1574,
342,
199,
199,
309,
600,
13,
2792,
2410,
13,
3629,
327,
4498,
315,
2195,
8722,
1233,
2348,
199,
309,
15,
600,
13,
2792,
2410,
13,
3629,
199,
199,
533,
3626,
274,
303,
8,
1563,
7850,
12,
1448,
6329,
85,
9501,
304,
272,
408,
272,
408,
272,
6391,
275,
8089,
7676,
2354,
342,
272,
636,
24900,
363,
275,
334,
5675,
8,
1563,
7850,
2584,
363,
24900,
7500,
4000,
9,
435,
334,
5675,
8,
714,
6329,
85,
9501,
2584,
363,
24900,
7500,
4000,
9,
339,
327,
961,
536,
11337,
315,
314,
283,
525,
7,
5689,
272,
601,
595,
466,
63,
354,
275,
283,
2001,
274,
303,
7,
339,
3404,
63,
466,
275,
283,
2001,
274,
303,
7,
272,
18428,
63,
466,
275,
283,
2001,
274,
303,
7,
272,
4370,
63,
1317,
63,
1313,
275,
788,
16979,
418,
435,
769,
8,
5675,
8,
714,
6329,
85,
9501,
12,
283,
6541,
63,
1317,
63,
1313,
297,
15927,
272,
2457,
63,
1317,
63,
1313,
275,
413,
272,
2288,
63,
3306,
275,
413,
272,
327,
1317,
63,
4677,
275,
283,
2001,
274,
303,
14,
14513,
7,
272,
8569,
63,
1345,
275,
283,
1095,
63,
1345,
7,
272,
849,
63,
1345,
275,
283,
1095,
63,
1345,
7,
272,
1029,
1168,
63,
4196,
275,
6248,
272,
730,
5831,
275,
298,
2001,
274,
303,
2,
272,
730,
9921,
6173,
1304,
275,
283,
1802,
63,
3773,
63,
761,
274,
303,
7,
339,
485,
292,
63,
8165,
63,
4399,
63,
8782,
275,
715,
339,
4177,
275,
3626,
274,
303,
63,
3629,
339,
925,
600,
13,
2792,
1021,
13,
1291,
327,
4498,
315,
2195,
8722,
1233,
2348,
272,
925,
15,
600,
13,
2792,
1021,
13,
1291,
339,
327,
17653,
421,
199,
2683,
804,
8,
2001,
274,
303,
12,
21915,
2339,
9,
199,
3,
1284,
402,
1021,
3626,
274,
303,
199,
199,
309,
600,
13,
2792,
859,
13,
12781,
327,
4498,
315,
2195,
8722,
1233,
2348,
199,
309,
15,
600,
13,
2792,
859,
13,
12781,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
3814,
26,
3626,
274,
303,
14,
647,
199,
3,
199,
3,
1898,
334,
67,
9,
10219,
701,
942,
199,
3,
15042,
26,
19521,
8168,
4317,
3394,
413,
14,
21,
14,
18,
199,
3,
3322,
1455,
921,
1168,
368,
14,
1308,
15,
13336,
15,
1047,
2268,
1652,
199,
3,
199,
3,
1664,
1696,
1684,
844,
334,
12006,
9,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
199,
3,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
199,
3,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
12,
8217,
14,
199,
3,
199,
199,
363,
2502,
363,
275,
408,
5187,
665,
5187,
11193,
199,
363,
21841,
363,
275,
283,
17426,
7,
199,
199,
504,
11003,
3717,
492,
8089,
7676,
2354,
199,
504,
32411,
14,
1596,
595,
1313,
14,
419,
1038,
492,
627,
199,
504,
32411,
14,
53,
11325,
609,
11421,
15557,
3314,
11421,
266,
397,
14,
1317,
14,
714,
6329,
85,
9501,
492,
1448,
6329,
85,
9501,
199,
504,
32411,
14,
619,
4540,
2891,
14,
4540,
5083,
792,
492,
10257,
5083,
792,
12,
10257,
5083,
3339,
199,
504,
32411,
14,
53,
11325,
609,
11421,
15557,
3314,
11421,
266,
397,
14,
888,
492,
627,
199,
199,
309,
600,
13,
2792,
859,
13,
1291,
327,
4498,
315,
2195,
8722,
1233,
2348,
199,
309,
15,
600,
13,
2792,
859,
13,
1291,
199,
199,
3629,
275,
13268,
1332,
339,
10944,
792,
8,
267,
536,
534,
27532,
1470,
297,
267,
3938,
29,
5083,
3339,
8,
288,
1768,
534,
872,
2064,
1470,
297,
288,
1768,
63,
15245,
534,
53,
11325,
609,
11421,
15557,
3314,
11421,
266,
397,
63,
1302,
63,
27532,
1470,
297,
288,
284,
1085,
78,
63,
2261,
534,
53,
11325,
609,
11421,
15557,
3314,
11421,
266,
397,
297,
267,
2318,
267,
4370,
63,
1313,
7782,
872,
12493,
5529,
267,
3510,
1110,
68,
29,
17,
12,
267,
8931,
534,
761,
274,
303,
63,
19623,
7,
272,
2318,
199,
199,
395,
199,
9,
199,
199,
309,
600,
13,
2792,
2410,
13,
1832,
13,
3629,
327,
4498,
315,
2195,
8722,
1233,
2348,
199,
309,
15,
600,
13,
2792,
2410,
13,
1832,
13,
3629,
199,
199,
2001,
274,
303,
63,
3629,
275,
3523,
7850,
6700,
14,
1574,
342,
435,
971,
272,
2519,
8,
714,
6329,
85,
9501,
12,
283,
3629,
297,
13268,
8,
4059,
14,
1574,
342,
435,
971,
272,
4177,
14,
1574,
342,
199,
199,
309,
600,
13,
2792,
2410,
13,
3629,
327,
4498,
315,
2195,
8722,
1233,
2348,
199,
309,
15,
600,
13,
2792,
2410,
13,
3629,
199,
199,
533,
3626,
274,
303,
8,
1563,
7850,
12,
1448,
6329,
85,
9501,
304,
272,
408,
272,
408,
272,
6391,
275,
8089,
7676,
2354,
342,
272,
636,
24900,
363,
275,
334,
5675,
8,
1563,
7850,
2584,
363,
24900,
7500,
4000,
9,
435,
334,
5675,
8,
714,
6329,
85,
9501,
2584,
363,
24900,
7500,
4000,
9,
339,
327,
961,
536,
11337,
315,
314,
283,
525,
7,
5689,
272,
601,
595,
466,
63,
354,
275,
283,
2001,
274,
303,
7,
339,
3404,
63,
466,
275,
283,
2001,
274,
303,
7,
272,
18428,
63,
466,
275,
283,
2001,
274,
303,
7,
272,
4370,
63,
1317,
63,
1313,
275,
788,
16979,
418,
435,
769,
8,
5675,
8,
714,
6329,
85,
9501,
12,
283,
6541,
63,
1317,
63,
1313,
297,
15927,
272,
2457,
63,
1317,
63,
1313,
275,
413,
272,
2288,
63,
3306,
275,
413,
272,
327,
1317,
63,
4677,
275,
283,
2001,
274,
303,
14,
14513,
7,
272,
8569,
63,
1345,
275,
283,
1095,
63,
1345,
7,
272,
849,
63,
1345,
275,
283,
1095,
63,
1345,
7,
272,
1029,
1168,
63,
4196,
275,
6248,
272,
730,
5831,
275,
298,
2001,
274,
303,
2,
272,
730,
9921,
6173,
1304,
275,
283,
1802,
63,
3773,
63,
761,
274,
303,
7,
339,
485,
292,
63,
8165,
63,
4399,
63,
8782,
275,
715,
339,
4177,
275,
3626,
274,
303,
63,
3629,
339,
925,
600,
13,
2792,
1021,
13,
1291,
327,
4498,
315,
2195,
8722,
1233,
2348,
272,
925,
15,
600,
13,
2792,
1021,
13,
1291,
339,
327,
17653,
421,
199,
2683,
804,
8,
2001,
274,
303,
12,
21915,
2339,
9,
199,
3,
1284,
402,
1021,
3626,
274,
303,
199,
199,
309,
600,
13,
2792,
859,
13,
12781,
327,
4498,
315,
2195,
8722,
1233,
2348,
199,
309,
15,
600,
13,
2792,
859,
13,
12781,
6905,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
codeforamerica/epa_python
|
setup.py
|
1
|
6118
|
#!/usr/bin/env python
"""
Author: Zach Williams, <zach AT codeforamerica DOT org>
Copyright (c) 2011, Code for America. 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 Code for America 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.
"""
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
long_description = """
EPA Python API wrapper
======================
Python wrapper for the multiple APIs available through the EPA's
website.
Documentation for the APIs can be found here:
[http://www.epa.gov/enviro/facts/ef_restful.html](http://www.epa.gov/enviro/facts/ef_restful.html)
APIs
----
### RADInfo
>>> from epa.radinfo import RADInfo
>>> r = RADInfo()
>>> # An empty method returns a dict of available columns.
... r.facility_type()
>>> # A method call without a value returns info about that column.
... r.facility_type('cit_ref_code')
>>> # Find information on a facility in a certain city.
... r.facility('city_name', 'Berkeley')
{'data': {'about': "Berkeley's Radiation Facility"}}
>>> # Find all the radiation facilities in Texas.
... r.facility('state_code', 'TX')
{'all': {'seven': 'Texas facilities'}}
>>> # Integer values are converted to strings automatically.
... r.regulation('part_id', 61)
>>> r.regulation('title_id', '40')
>>> # Search for the CIT_REF_CODE of a RAD NPL facility.
... r.regulation('cit_ref_code', '40CFR300')
>>> data = r.regulatory_program('sec_cit_ref_flag', 'N')
>>> data['Count']
100
>>> new_data = r.regulatory_program('sec_cit_ref_code', 'N', count=200)
>>> new_data['Count']
190
>>> data = r.regulatory_program('cit_ref_code', '40CFR300', start=50)
>>> data['Count']
8
>>> # Find geographic information.
... r.geo('geometric_type_code', '001')
### GICS
>>> from epa.gics import GICS
>>> g = GICS()
>>> # List construction projects that are 91% complete.
... g.construction('complete_percent', 91)
>>> # Find all the construction projects at a specific facility.
... data = g.construction('facility_number', 190226001)
>>> data['Count']
8
>>> # Search for a specific grant's milestones.
... g.milestone('grant_number', 190709130)
>>> # Find all ADMIN COMPLETE milestones.
... g.milestone('milestone_type', 'ADMIN COMPLETE')
>>> # Search for milestones on a specific DD-MON-YY date.
... g.milestone('milestone_date', '16-MAR-01')
>>> # Find descriptions for a status code.
... g.status('status_code', 'AF')
>>> # Find grants on a specific date.
... g.grant('award_accept_date', '12-MAR-01')
>>> # Find grants for a specific city.
... g.grant('projecty_city_name', 'San Francisco')
>>> # Search the GICS API's grants for a specific state.
... g.grant('project_state_code', 'TX', count=500)
>>> # Find an applicant in a specific zipcode.
... g.applicant('zip_code', 94105)
### PCS
>>> from epa.pcs import PCS
>>> p = PCS()
>>> # Search for facilities in a city.
... p.facility('location_city', 'San Francisco')
>>> # Find a facility in a particular zipcode.
... p.facility('location_zip_code', 76108)
>>> # Find a sludge facility in a specific state.
... p.sludge('handler_state', 'NY')
>>> p.pipe_schedule('discharge_num', 333)
>>> p.pipe_schedule('npdes', 'GMG290024')
>>> p.dmr_measurement('discharge_num', '001')
>>> # Find the inspections that took place on a specific date.
... p.inspection('insp_date', '16-MAR-01')
>>> p.enforcement_action('ea_code', '09')
Copyright
---------
Copyright (c) 2011 Code for America Laboratories.
See LICENSE for details.
"""
setup(name="epa",
version="1.3",
description=("Python wrapper for the multiple APIs available through "
"the EPA's website."),
long_description=long_description,
keywords="epa, EPA, environment",
author="Zach Williams",
author_email="zach@codeforamerica.org",
url="https://github.com/codeforamerica/epa_python",
license="BSD",
packages=["epa", "epa.pcs", "epa.gics", "epa.envirofacts",
"epa.envirofacts.api", "epa.envirofacts.api.xml2dict",
"epa.radinfo", "epa.tests"],
classifiers=['Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Natural Language :: English',
'Operating System :: OS Independent',
'Programming Language :: Python :: 2',
'Topic :: Internet',
'Topic :: Internet :: WWW/HTTP',
],
test_suite="test.py",
tests_require=["mock", "Mock"])
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
5949,
26,
3107,
1225,
644,
8148,
19470,
12,
665,
90,
1225,
15059,
512,
318,
269,
313,
7127,
15854,
5981,
30,
199,
199,
7384,
334,
67,
9,
7760,
12,
5495,
367,
437,
8534,
14,
2900,
4481,
4644,
14,
199,
199,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
20945,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
199,
497,
5613,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
199,
513,
402,
3704,
436,
314,
2569,
6450,
14,
6823,
315,
3366,
1824,
199,
7790,
9172,
314,
3432,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
199,
21589,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
199,
1589,
4084,
14,
11443,
314,
536,
402,
5495,
367,
437,
8534,
6590,
314,
1561,
402,
2399,
199,
21630,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
199,
15619,
1928,
2488,
6791,
5313,
4983,
14,
5749,
4141,
2281,
7049,
199,
8285,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
199,
55,
2007,
2563,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
2990,
1634,
199,
31461,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
199,
8193,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
199,
568,
6098,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
12728,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3998,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
2673,
2477,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
199,
726,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
199,
1554,
54,
9359,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
624,
421,
199,
893,
26,
272,
687,
9116,
492,
3272,
199,
2590,
3545,
26,
272,
687,
7065,
14,
1018,
492,
3272,
421,
199,
2809,
63,
1802,
275,
408,
199,
6102,
33,
2018,
3261,
4975,
199,
1280,
23476,
199,
199,
4718,
4975,
367,
314,
3663,
15913,
2808,
4012,
314,
662,
8470,
1159,
199,
7360,
14,
199,
199,
17763,
367,
314,
15913,
883,
506,
1911,
2348,
26,
221,
199,
59,
1014,
921,
1544,
14,
69,
387,
14,
16294,
15,
287,
433,
293,
15,
5047,
15,
2829,
63,
3911,
1893,
14,
1360,
8738,
1014,
921,
1544,
14,
69,
387,
14,
16294,
15,
287,
433,
293,
15,
5047,
15,
2829,
63,
3911,
1893,
14,
1360,
9,
421,
199,
1282,
1831,
199,
375,
199,
199,
5680,
820,
1554,
2354,
339,
1306,
687,
325,
387,
14,
9525,
815,
492,
820,
1554,
2354,
272,
1306,
519,
275,
820,
1554,
2354,
342,
339,
1306,
327,
1626,
2701,
1083,
2529,
282,
1211,
402,
2808,
4362,
14,
272,
2263,
519,
14,
22354,
63,
466,
342,
339,
1306,
327,
437,
1083,
1240,
1928,
282,
574,
2529,
2256,
3595,
626,
2763,
14,
272,
2263,
519,
14,
22354,
63,
466,
360,
14422,
63,
1121,
63,
600,
358,
339,
1306,
327,
6668,
2556,
641,
282,
21395,
315,
282,
9842,
14492,
14,
272,
2263,
519,
14,
22354,
360,
3690,
63,
354,
297,
283,
24947,
415,
15515,
358,
272,
791,
576,
356,
791,
10254,
356,
298,
24947,
415,
15515,
1159,
3898,
328,
425,
10859,
12498,
32655,
339,
1306,
327,
6668,
1006,
314,
14070,
425,
30242,
7999,
315,
20566,
305,
14,
272,
2263,
519,
14,
22354,
360,
929,
63,
600,
297,
283,
10051,
358,
272,
791,
452,
356,
791,
27346,
356,
283,
30121,
30242,
7999,
18620,
339,
1306,
327,
7225,
1338,
787,
6702,
370,
3326,
5847,
14,
272,
2263,
519,
14,
1135,
5332,
360,
2064,
63,
344,
297,
17017,
9,
339,
1306,
519,
14,
1135,
5332,
360,
1213,
63,
344,
297,
283,
2167,
358,
339,
1306,
327,
8730,
367,
314,
445,
649,
63,
8279,
63,
6012,
402,
282,
820,
1554,
653,
2749,
21395,
14,
272,
2263,
519,
14,
1135,
5332,
360,
14422,
63,
1121,
63,
600,
297,
283,
2167,
35,
5372,
5863,
358,
339,
1306,
666,
275,
519,
14,
1135,
6109,
89,
63,
6815,
360,
3321,
63,
14422,
63,
1121,
63,
4173,
297,
283,
46,
358,
272,
1306,
666,
459,
2353,
418,
272,
2948,
339,
1306,
892,
63,
576,
275,
519,
14,
1135,
6109,
89,
63,
6815,
360,
3321,
63,
14422,
63,
1121,
63,
600,
297,
283,
46,
297,
2338,
29,
1840,
9,
272,
1306,
892,
63,
576,
459,
2353,
418,
272,
29682,
339,
1306,
666,
275,
519,
14,
1135,
6109,
89,
63,
6815,
360,
14422,
63,
1121,
63,
600,
297,
283,
2167,
35,
5372,
5863,
297,
1343,
29,
1400,
9,
272,
1306,
666,
459,
2353,
418,
272,
1695,
339,
1306,
327,
6668,
25637,
2556,
14,
272,
2263,
519,
14,
6721,
360,
31509,
63,
466,
63,
600,
297,
283,
4587,
358,
421,
199,
5680,
598,
21174,
339,
1306,
687,
325,
387,
14,
71,
2932,
492,
598,
21174,
272,
1306,
486,
275,
598,
21174,
342,
339,
1306,
327,
3820,
14538,
11336,
626,
787,
21358,
5,
4890,
14,
272,
2263,
486,
14,
12708,
360,
4883,
63,
7045,
297,
21358,
9,
339,
1306,
327,
6668,
1006,
314,
14538,
11336,
737,
282,
2488,
21395,
14,
272,
2263,
666,
275,
486,
14,
12708,
360,
22354,
63,
1955,
297,
5851,
996,
1479,
4587,
9,
272,
1306,
666,
459,
2353,
418,
272,
1695,
339,
1306,
327,
8730,
367,
282,
2488,
16085,
1159,
333,
24156,
14,
272,
2263,
486,
14,
25324,
360,
17362,
63,
1955,
297,
5851,
1780,
1643,
9056,
9,
339,
1306,
327,
6668,
1006,
29948,
5099,
3950,
5248,
333,
24156,
14,
272,
2263,
486,
14,
25324,
360,
25324,
63,
466,
297,
283,
14288,
5099,
3950,
5248,
358,
339,
1306,
327,
8730,
367,
333,
24156,
641,
282,
2488,
29662,
13,
11710,
13,
7080,
1434,
14,
272,
2263,
486,
14,
25324,
360,
25324,
63,
602,
297,
283,
975,
13,
45,
689,
13,
614,
358,
339,
1306,
327,
6668,
18714,
367,
282,
2004,
1233,
14,
272,
2263,
486,
14,
1205,
360,
1205,
63,
600,
297,
283,
5699,
358,
339,
1306,
327,
6668,
7192,
2285,
641,
282,
2488,
1434,
14,
272,
2263,
486,
14
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
624,
199,
5949,
26,
3107,
1225,
644,
8148,
19470,
12,
665,
90,
1225,
15059,
512,
318,
269,
313,
7127,
15854,
5981,
30,
199,
199,
7384,
334,
67,
9,
7760,
12,
5495,
367,
437,
8534,
14,
2900,
4481,
4644,
14,
199,
199,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
20945,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
199,
497,
5613,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
199,
513,
402,
3704,
436,
314,
2569,
6450,
14,
6823,
315,
3366,
1824,
199,
7790,
9172,
314,
3432,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
199,
21589,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
199,
1589,
4084,
14,
11443,
314,
536,
402,
5495,
367,
437,
8534,
6590,
314,
1561,
402,
2399,
199,
21630,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
199,
15619,
1928,
2488,
6791,
5313,
4983,
14,
5749,
4141,
2281,
7049,
199,
8285,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
199,
55,
2007,
2563,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
2990,
1634,
199,
31461,
2401,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
199,
8193,
7000,
2334,
5877,
29785,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
199,
568,
6098,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
199,
12728,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3998,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
2673,
2477,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
199,
726,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
199,
1554,
54,
9359,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
624,
421,
199,
893,
26,
272,
687,
9116,
492,
3272,
199,
2590,
3545,
26,
272,
687,
7065,
14,
1018,
492,
3272,
421,
199,
2809,
63,
1802,
275,
408,
199,
6102,
33,
2018,
3261,
4975,
199,
1280,
23476,
199,
199,
4718,
4975,
367,
314,
3663,
15913,
2808,
4012,
314,
662,
8470,
1159,
199,
7360,
14,
199,
199,
17763,
367,
314,
15913,
883,
506,
1911,
2348,
26,
221,
199,
59,
1014,
921,
1544,
14,
69,
387,
14,
16294,
15,
287,
433,
293,
15,
5047,
15,
2829,
63,
3911,
1893,
14,
1360,
8738,
1014,
921,
1544,
14,
69,
387,
14,
16294,
15,
287,
433,
293,
15,
5047,
15,
2829,
63,
3911,
1893,
14,
1360,
9,
421,
199,
1282,
1831,
199,
375,
199,
199,
5680,
820,
1554,
2354,
339,
1306,
687,
325,
387,
14,
9525,
815,
492,
820,
1554,
2354,
272,
1306,
519,
275,
820,
1554,
2354,
342,
339,
1306,
327,
1626,
2701,
1083,
2529,
282,
1211,
402,
2808,
4362,
14,
272,
2263,
519,
14,
22354,
63,
466,
342,
339,
1306,
327,
437,
1083,
1240,
1928,
282,
574,
2529,
2256,
3595,
626,
2763,
14,
272,
2263,
519,
14,
22354,
63,
466,
360,
14422,
63,
1121,
63,
600,
358,
339,
1306,
327,
6668,
2556,
641,
282,
21395,
315,
282,
9842,
14492,
14,
272,
2263,
519,
14,
22354,
360,
3690,
63,
354,
297,
283,
24947,
415,
15515,
358,
272,
791,
576,
356,
791,
10254,
356,
298,
24947,
415,
15515,
1159,
3898,
328,
425,
10859,
12498,
32655,
339,
1306,
327,
6668,
1006,
314,
14070,
425,
30242,
7999,
315,
20566,
305,
14,
272,
2263,
519,
14,
22354,
360,
929,
63,
600,
297,
283,
10051,
358,
272,
791,
452,
356,
791,
27346,
356,
283,
30121,
30242,
7999,
18620,
339,
1306,
327,
7225,
1338,
787,
6702,
370,
3326,
5847,
14,
272,
2263,
519,
14,
1135,
5332,
360,
2064,
63,
344,
297,
17017,
9,
339,
1306,
519,
14,
1135,
5332,
360,
1213,
63,
344,
297,
283,
2167,
358,
339,
1306,
327,
8730,
367,
314,
445,
649,
63,
8279,
63,
6012,
402,
282,
820,
1554,
653,
2749,
21395,
14,
272,
2263,
519,
14,
1135,
5332,
360,
14422,
63,
1121,
63,
600,
297,
283,
2167,
35,
5372,
5863,
358,
339,
1306,
666,
275,
519,
14,
1135,
6109,
89,
63,
6815,
360,
3321,
63,
14422,
63,
1121,
63,
4173,
297,
283,
46,
358,
272,
1306,
666,
459,
2353,
418,
272,
2948,
339,
1306,
892,
63,
576,
275,
519,
14,
1135,
6109,
89,
63,
6815,
360,
3321,
63,
14422,
63,
1121,
63,
600,
297,
283,
46,
297,
2338,
29,
1840,
9,
272,
1306,
892,
63,
576,
459,
2353,
418,
272,
29682,
339,
1306,
666,
275,
519,
14,
1135,
6109,
89,
63,
6815,
360,
14422,
63,
1121,
63,
600,
297,
283,
2167,
35,
5372,
5863,
297,
1343,
29,
1400,
9,
272,
1306,
666,
459,
2353,
418,
272,
1695,
339,
1306,
327,
6668,
25637,
2556,
14,
272,
2263,
519,
14,
6721,
360,
31509,
63,
466,
63,
600,
297,
283,
4587,
358,
421,
199,
5680,
598,
21174,
339,
1306,
687,
325,
387,
14,
71,
2932,
492,
598,
21174,
272,
1306,
486,
275,
598,
21174,
342,
339,
1306,
327,
3820,
14538,
11336,
626,
787,
21358,
5,
4890,
14,
272,
2263,
486,
14,
12708,
360,
4883,
63,
7045,
297,
21358,
9,
339,
1306,
327,
6668,
1006,
314,
14538,
11336,
737,
282,
2488,
21395,
14,
272,
2263,
666,
275,
486,
14,
12708,
360,
22354,
63,
1955,
297,
5851,
996,
1479,
4587,
9,
272,
1306,
666,
459,
2353,
418,
272,
1695,
339,
1306,
327,
8730,
367,
282,
2488,
16085,
1159,
333,
24156,
14,
272,
2263,
486,
14,
25324,
360,
17362,
63,
1955,
297,
5851,
1780,
1643,
9056,
9,
339,
1306,
327,
6668,
1006,
29948,
5099,
3950,
5248,
333,
24156,
14,
272,
2263,
486,
14,
25324,
360,
25324,
63,
466,
297,
283,
14288,
5099,
3950,
5248,
358,
339,
1306,
327,
8730,
367,
333,
24156,
641,
282,
2488,
29662,
13,
11710,
13,
7080,
1434,
14,
272,
2263,
486,
14,
25324,
360,
25324,
63,
602,
297,
283,
975,
13,
45,
689,
13,
614,
358,
339,
1306,
327,
6668,
18714,
367,
282,
2004,
1233,
14,
272,
2263,
486,
14,
1205,
360,
1205,
63,
600,
297,
283,
5699,
358,
339,
1306,
327,
6668,
7192,
2285,
641,
282,
2488,
1434,
14,
272,
2263,
486,
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,
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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
] |
d-mittal/pystruct
|
pystruct/models/latent_graph_crf.py
|
3
|
8415
|
import numbers
import numpy as np
from scipy import sparse
from sklearn.cluster import KMeans
from . import GraphCRF
from ..inference import inference_dispatch
def kmeans_init(X, Y, all_edges, n_labels, n_states_per_label,
symmetric=True):
all_feats = []
# iterate over samples
for x, y, edges in zip(X, Y, all_edges):
# first, get neighbor counts from nodes
n_nodes = x.shape[0]
labels_one_hot = np.zeros((n_nodes, n_labels), dtype=np.int)
y = y.ravel()
gx = np.ogrid[:n_nodes]
labels_one_hot[gx, y] = 1
size = np.prod(y.shape)
graphs = [sparse.coo_matrix((np.ones(e.shape[0]), e.T), (size, size))
for e in edges]
if symmetric:
directions = [g + g.T for g in graphs]
else:
directions = [T for g in graphs for T in [g, g.T]]
neighbors = [s * labels_one_hot.reshape(size, -1) for s in directions]
neighbors = np.hstack(neighbors)
# normalize (for borders)
neighbors /= np.maximum(neighbors.sum(axis=1)[:, np.newaxis], 1)
# add unaries
features = np.hstack([x, neighbors])
all_feats.append(features)
all_feats_stacked = np.vstack(all_feats)
Y_stacked = np.hstack(Y).ravel()
# for each state, run k-means over whole dataset
H = [np.zeros(y.shape, dtype=np.int) for y in Y]
label_indices = np.hstack([0, np.cumsum(n_states_per_label)])
for label in np.unique(Y_stacked):
try:
km = KMeans(n_clusters=n_states_per_label[label])
except TypeError:
# for old versions :-/
km = KMeans(k=n_states_per_label[label])
indicator = Y_stacked == label
f = all_feats_stacked[indicator]
km.fit(f)
for feats_sample, y, h in zip(all_feats, Y, H):
indicator_sample = y.ravel() == label
if np.any(indicator_sample):
pred = km.predict(feats_sample[indicator_sample]).astype(np.int)
h.ravel()[indicator_sample] = pred + label_indices[label]
return H
class LatentGraphCRF(GraphCRF):
"""CRF with latent states for variables.
This is also called "hidden dynamics CRF".
For each output variable there is an additional variable which
can encode additional states and interactions.
Parameters
----------
n_labels : int
Number of states of output variables.
n_featues : int or None (default=None).
Number of input features per input variable.
``None`` means it is equal to ``n_labels``.
n_states_per_label : int or list (default=2)
Number of latent states associated with each observable state.
Can be either an integer, which means the same number
of hidden states will be used for all observable states, or a list
of integers of length ``n_labels``.
inference_method : string, default="ad3"
Function to call to do inference and loss-augmented inference.
Possible values are:
- 'max-product' for max-product belief propagation.
Recommended for chains an trees. Loopy belief propagatin in case of a general graph.
- 'lp' for Linear Programming relaxation using cvxopt.
- 'ad3' for AD3 dual decomposition.
- 'qpbo' for QPBO + alpha expansion.
- 'ogm' for OpenGM inference algorithms.
"""
def __init__(self, n_labels=None, n_features=None, n_states_per_label=2,
inference_method=None):
self.n_labels = n_labels
self.n_states_per_label = n_states_per_label
GraphCRF.__init__(self, n_states=None, n_features=n_features,
inference_method=inference_method)
def _set_size_joint_feature(self):
if None in [self.n_features, self.n_labels]:
return
if isinstance(self.n_states_per_label, numbers.Integral):
# same for all labels
n_states_per_label = np.array([
self.n_states_per_label for i in range(self.n_labels)])
else:
n_states_per_label = np.array(self.n_states_per_label)
if len(n_states_per_label) != self.n_labels:
raise ValueError("states_per_label must be integer"
"or array-like of length n_labels. Got %s"
% str(n_states_per_label))
self.n_states_per_label = n_states_per_label
self.n_states = np.sum(n_states_per_label)
# compute mapping from latent states to labels
ranges = np.cumsum(n_states_per_label)
states_map = np.zeros(self.n_states, dtype=np.int)
for l in range(1, self.n_labels):
states_map[ranges[l - 1]: ranges[l]] = l
self._states_map = states_map
GraphCRF._set_size_joint_feature(self)
def initialize(self, X, Y):
n_features = X[0][0].shape[1]
if self.n_features is None:
self.n_features = n_features
elif self.n_features != n_features:
raise ValueError("Expected %d features, got %d"
% (self.n_features, n_features))
n_labels = len(np.unique(np.hstack([y.ravel() for y in Y])))
if self.n_labels is None:
self.n_labels = n_labels
elif self.n_labels != n_labels:
raise ValueError("Expected %d states, got %d"
% (self.n_labels, n_labels))
self._set_size_joint_feature()
self._set_class_weight()
def label_from_latent(self, h):
return self._states_map[h]
def init_latent(self, X, Y):
# treat all edges the same
edges = [[self._get_edges(x)] for x in X]
features = np.array([self._get_features(x) for x in X])
return kmeans_init(features, Y, edges, n_labels=self.n_labels,
n_states_per_label=self.n_states_per_label)
def loss_augmented_inference(self, x, h, w, relaxed=False,
return_energy=False):
self.inference_calls += 1
self._check_size_w(w)
unary_potentials = self._get_unary_potentials(x, w)
pairwise_potentials = self._get_pairwise_potentials(x, w)
edges = self._get_edges(x)
# do loss-augmentation
for l in np.arange(self.n_states):
# for each class, decrement features
# for loss-agumention
unary_potentials[self.label_from_latent(h)
!= self.label_from_latent(l), l] += 1.
return inference_dispatch(unary_potentials, pairwise_potentials, edges,
self.inference_method, relaxed=relaxed,
return_energy=return_energy)
def latent(self, x, y, w):
unary_potentials = self._get_unary_potentials(x, w)
# forbid h that is incompoatible with y
# by modifying unary params
other_states = self._states_map != y[:, np.newaxis]
max_entry = np.maximum(np.max(unary_potentials), 1)
unary_potentials[other_states] = -1e2 * max_entry
pairwise_potentials = self._get_pairwise_potentials(x, w)
edges = self._get_edges(x)
h = inference_dispatch(unary_potentials, pairwise_potentials, edges,
self.inference_method, relaxed=False)
if (self.label_from_latent(h) != y).any():
print("inconsistent h and y")
h = np.hstack([0, np.cumsum(self.n_states_per_label)])[y]
return h
def loss(self, h, h_hat):
if isinstance(h_hat, tuple):
return self.continuous_loss(h, h_hat[0])
return GraphCRF.loss(self, self.label_from_latent(h),
self.label_from_latent(h_hat))
def continuous_loss(self, y, y_hat):
# continuous version of the loss
# y_hat is the result of linear programming
y_hat_org = np.zeros((y_hat.shape[0], self.n_labels))
for s in range(self.n_states):
y_hat_org[:, self._states_map[s]] += y_hat[:, s]
y_org = self.label_from_latent(y)
return GraphCRF.continuous_loss(self, y_org, y_hat_org)
def base_loss(self, y, y_hat):
if isinstance(y_hat, tuple):
return GraphCRF.continuous_loss(self, y, y_hat)
return GraphCRF.loss(self, y, y_hat)
|
bsd-2-clause
|
[
646,
5579,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
7026,
492,
5178,
199,
504,
6357,
14,
4201,
492,
1804,
21190,
199,
199,
504,
1275,
492,
11513,
2944,
38,
199,
504,
2508,
20580,
492,
17353,
63,
6052,
421,
199,
318,
1022,
11579,
63,
826,
8,
56,
12,
1488,
12,
1006,
63,
6929,
12,
302,
63,
3512,
12,
302,
63,
4981,
63,
529,
63,
1302,
12,
355,
16371,
29,
549,
304,
272,
1006,
63,
29255,
275,
942,
272,
327,
13974,
1806,
5845,
272,
367,
671,
12,
612,
12,
8207,
315,
3482,
8,
56,
12,
1488,
12,
1006,
63,
6929,
304,
267,
327,
1642,
12,
664,
15503,
8242,
687,
3380,
267,
302,
63,
2415,
275,
671,
14,
1392,
59,
16,
61,
267,
3628,
63,
368,
63,
8885,
275,
980,
14,
4250,
1332,
78,
63,
2415,
12,
302,
63,
3512,
395,
2152,
29,
1590,
14,
442,
9,
267,
612,
275,
612,
14,
11186,
342,
267,
486,
88,
275,
980,
14,
974,
1677,
1491,
78,
63,
2415,
61,
267,
3628,
63,
368,
63,
8885,
59,
20777,
12,
612,
61,
275,
413,
398,
1568,
275,
980,
14,
8788,
8,
89,
14,
1392,
9,
267,
18312,
275,
359,
4421,
14,
22684,
63,
3642,
1332,
1590,
14,
4548,
8,
69,
14,
1392,
59,
16,
2522,
325,
14,
52,
395,
334,
890,
12,
1568,
430,
2116,
367,
325,
315,
8207,
61,
267,
340,
16371,
26,
288,
28820,
275,
359,
71,
435,
486,
14,
52,
367,
486,
315,
18312,
61,
267,
587,
26,
288,
28820,
275,
359,
52,
367,
486,
315,
18312,
367,
377,
315,
359,
71,
12,
486,
14,
52,
2677,
267,
15845,
275,
359,
83,
627,
3628,
63,
368,
63,
8885,
14,
5217,
8,
890,
12,
446,
17,
9,
367,
308,
315,
28820,
61,
267,
15845,
275,
980,
14,
20949,
8,
11113,
9,
267,
327,
7666,
334,
509,
9162,
83,
9,
267,
15845,
12257,
980,
14,
11555,
8,
11113,
14,
1838,
8,
3127,
29,
17,
24517,
980,
14,
14483,
467,
413,
9,
398,
327,
1050,
625,
3433,
267,
4534,
275,
980,
14,
20949,
779,
88,
12,
15845,
566,
267,
1006,
63,
29255,
14,
740,
8,
3179,
9,
272,
1006,
63,
29255,
63,
27266,
275,
980,
14,
20221,
8,
452,
63,
29255,
9,
272,
1488,
63,
27266,
275,
980,
14,
20949,
8,
57,
680,
11186,
342,
272,
327,
367,
1924,
1174,
12,
1255,
1022,
13,
11579,
1806,
8852,
4789,
272,
869,
275,
359,
1590,
14,
4250,
8,
89,
14,
1392,
12,
2152,
29,
1590,
14,
442,
9,
367,
612,
315,
1488,
61,
272,
1768,
63,
4108,
275,
980,
14,
20949,
779,
16,
12,
980,
14,
23916,
8,
78,
63,
4981,
63,
529,
63,
1302,
3948,
272,
367,
1768,
315,
980,
14,
3235,
8,
57,
63,
27266,
304,
267,
862,
26,
288,
16155,
275,
1804,
21190,
8,
78,
63,
9170,
29,
78,
63,
4981,
63,
529,
63,
1302,
59,
1302,
566,
267,
871,
3146,
26,
288,
327,
367,
2269,
5459,
22901,
15,
288,
16155,
275,
1804,
21190,
8,
75,
29,
78,
63,
4981,
63,
529,
63,
1302,
59,
1302,
566,
267,
16385,
275,
1488,
63,
27266,
508,
1768,
267,
289,
275,
1006,
63,
29255,
63,
27266,
59,
15785,
61,
267,
16155,
14,
3269,
8,
70,
9,
267,
367,
1964,
1956,
63,
3271,
12,
612,
12,
394,
315,
3482,
8,
452,
63,
29255,
12,
1488,
12,
869,
304,
288,
16385,
63,
3271,
275,
612,
14,
11186,
342,
508,
1768,
288,
340,
980,
14,
1629,
8,
15785,
63,
3271,
304,
355,
8869,
275,
16155,
14,
6892,
8,
29255,
63,
3271,
59,
15785,
63,
3271,
6575,
6041,
8,
1590,
14,
442,
9,
355,
394,
14,
11186,
3430,
15785,
63,
3271,
61,
275,
8869,
435,
1768,
63,
4108,
59,
1302,
61,
272,
372,
869,
421,
199,
533,
491,
323,
343,
4578,
2944,
38,
8,
4578,
2944,
38,
304,
272,
408,
2944,
38,
543,
2465,
343,
6363,
367,
2860,
14,
339,
961,
365,
2597,
2797,
298,
5642,
31388,
2932,
445,
11778,
1674,
272,
2104,
1924,
1072,
1750,
2337,
365,
376,
4722,
1750,
1314,
272,
883,
3752,
4722,
6363,
436,
315,
22990,
14,
339,
3897,
272,
4143,
272,
302,
63,
3512,
520,
1109,
267,
4860,
402,
6363,
402,
1072,
2860,
14,
339,
302,
63,
11873,
10138,
520,
1109,
503,
488,
334,
885,
29,
403,
680,
267,
4860,
402,
1324,
4534,
1126,
1324,
1750,
14,
267,
1124,
403,
1040,
4910,
652,
365,
4472,
370,
1124,
78,
63,
3512,
4345,
339,
302,
63,
4981,
63,
529,
63,
1302,
520,
1109,
503,
769,
334,
885,
29,
18,
9,
267,
4860,
402,
2465,
343,
6363,
4568,
543,
1924,
2607,
29454,
1174,
14,
267,
6855,
506,
1902,
376,
3000,
12,
1314,
4910,
314,
2011,
1329,
267,
402,
8752,
6363,
911,
506,
1202,
367,
1006,
2607,
29454,
6363,
12,
503,
282,
769,
267,
402,
9446,
402,
2582,
1124,
78,
63,
3512,
4345,
339,
17353,
63,
765,
520,
1059,
12,
849,
628,
350,
19,
2,
267,
6801,
370,
1240,
370,
886,
17353,
436,
5621,
13,
20669,
2509,
17353,
14,
267,
18558,
1338,
787,
26,
953,
446,
283,
988,
13,
2558,
7,
367,
1390,
13,
2558,
506,
317,
2829,
17012,
14,
355,
799,
11902,
367,
30640,
376,
14416,
14,
3835,
927,
506,
317,
2829,
20796,
14667,
315,
1930,
402,
282,
8605,
3343,
14,
288,
446,
283,
10343,
7,
367,
12489,
2165,
9258,
13773,
88,
425,
1808,
6277,
88,
2992,
14,
288,
446,
283,
350,
19,
7,
367,
16271,
19,
21164,
22706,
14,
288,
446,
283,
15202,
656,
7,
367,
1413,
48,
3973,
435,
5131,
14819,
14,
288,
446,
283,
974,
77,
7,
367,
3232,
22636,
17353,
18036,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
302,
63,
3512,
29,
403,
12,
302,
63,
3179,
29,
403,
12,
302,
63,
4981,
63,
529,
63,
1302,
29,
18,
12,
326,
17353,
63,
765,
29,
403,
304,
267,
291,
14,
78,
63,
3512,
275,
302,
63,
3512,
267,
291,
14,
78,
63,
4981,
63,
529,
63,
1302,
275,
302,
63,
4981,
63,
529,
63,
1302,
267,
11513,
2944,
38,
855,
826,
721,
277,
12,
302,
63,
4981,
29,
403,
12,
302,
63,
3179,
29,
78,
63,
3179,
12,
2079,
17353,
63,
765,
29,
20580,
63,
765,
9,
339,
347,
485,
409,
63,
890,
63,
10153,
63,
4445
] |
[
5579,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
7026,
492,
5178,
199,
504,
6357,
14,
4201,
492,
1804,
21190,
199,
199,
504,
1275,
492,
11513,
2944,
38,
199,
504,
2508,
20580,
492,
17353,
63,
6052,
421,
199,
318,
1022,
11579,
63,
826,
8,
56,
12,
1488,
12,
1006,
63,
6929,
12,
302,
63,
3512,
12,
302,
63,
4981,
63,
529,
63,
1302,
12,
355,
16371,
29,
549,
304,
272,
1006,
63,
29255,
275,
942,
272,
327,
13974,
1806,
5845,
272,
367,
671,
12,
612,
12,
8207,
315,
3482,
8,
56,
12,
1488,
12,
1006,
63,
6929,
304,
267,
327,
1642,
12,
664,
15503,
8242,
687,
3380,
267,
302,
63,
2415,
275,
671,
14,
1392,
59,
16,
61,
267,
3628,
63,
368,
63,
8885,
275,
980,
14,
4250,
1332,
78,
63,
2415,
12,
302,
63,
3512,
395,
2152,
29,
1590,
14,
442,
9,
267,
612,
275,
612,
14,
11186,
342,
267,
486,
88,
275,
980,
14,
974,
1677,
1491,
78,
63,
2415,
61,
267,
3628,
63,
368,
63,
8885,
59,
20777,
12,
612,
61,
275,
413,
398,
1568,
275,
980,
14,
8788,
8,
89,
14,
1392,
9,
267,
18312,
275,
359,
4421,
14,
22684,
63,
3642,
1332,
1590,
14,
4548,
8,
69,
14,
1392,
59,
16,
2522,
325,
14,
52,
395,
334,
890,
12,
1568,
430,
2116,
367,
325,
315,
8207,
61,
267,
340,
16371,
26,
288,
28820,
275,
359,
71,
435,
486,
14,
52,
367,
486,
315,
18312,
61,
267,
587,
26,
288,
28820,
275,
359,
52,
367,
486,
315,
18312,
367,
377,
315,
359,
71,
12,
486,
14,
52,
2677,
267,
15845,
275,
359,
83,
627,
3628,
63,
368,
63,
8885,
14,
5217,
8,
890,
12,
446,
17,
9,
367,
308,
315,
28820,
61,
267,
15845,
275,
980,
14,
20949,
8,
11113,
9,
267,
327,
7666,
334,
509,
9162,
83,
9,
267,
15845,
12257,
980,
14,
11555,
8,
11113,
14,
1838,
8,
3127,
29,
17,
24517,
980,
14,
14483,
467,
413,
9,
398,
327,
1050,
625,
3433,
267,
4534,
275,
980,
14,
20949,
779,
88,
12,
15845,
566,
267,
1006,
63,
29255,
14,
740,
8,
3179,
9,
272,
1006,
63,
29255,
63,
27266,
275,
980,
14,
20221,
8,
452,
63,
29255,
9,
272,
1488,
63,
27266,
275,
980,
14,
20949,
8,
57,
680,
11186,
342,
272,
327,
367,
1924,
1174,
12,
1255,
1022,
13,
11579,
1806,
8852,
4789,
272,
869,
275,
359,
1590,
14,
4250,
8,
89,
14,
1392,
12,
2152,
29,
1590,
14,
442,
9,
367,
612,
315,
1488,
61,
272,
1768,
63,
4108,
275,
980,
14,
20949,
779,
16,
12,
980,
14,
23916,
8,
78,
63,
4981,
63,
529,
63,
1302,
3948,
272,
367,
1768,
315,
980,
14,
3235,
8,
57,
63,
27266,
304,
267,
862,
26,
288,
16155,
275,
1804,
21190,
8,
78,
63,
9170,
29,
78,
63,
4981,
63,
529,
63,
1302,
59,
1302,
566,
267,
871,
3146,
26,
288,
327,
367,
2269,
5459,
22901,
15,
288,
16155,
275,
1804,
21190,
8,
75,
29,
78,
63,
4981,
63,
529,
63,
1302,
59,
1302,
566,
267,
16385,
275,
1488,
63,
27266,
508,
1768,
267,
289,
275,
1006,
63,
29255,
63,
27266,
59,
15785,
61,
267,
16155,
14,
3269,
8,
70,
9,
267,
367,
1964,
1956,
63,
3271,
12,
612,
12,
394,
315,
3482,
8,
452,
63,
29255,
12,
1488,
12,
869,
304,
288,
16385,
63,
3271,
275,
612,
14,
11186,
342,
508,
1768,
288,
340,
980,
14,
1629,
8,
15785,
63,
3271,
304,
355,
8869,
275,
16155,
14,
6892,
8,
29255,
63,
3271,
59,
15785,
63,
3271,
6575,
6041,
8,
1590,
14,
442,
9,
355,
394,
14,
11186,
3430,
15785,
63,
3271,
61,
275,
8869,
435,
1768,
63,
4108,
59,
1302,
61,
272,
372,
869,
421,
199,
533,
491,
323,
343,
4578,
2944,
38,
8,
4578,
2944,
38,
304,
272,
408,
2944,
38,
543,
2465,
343,
6363,
367,
2860,
14,
339,
961,
365,
2597,
2797,
298,
5642,
31388,
2932,
445,
11778,
1674,
272,
2104,
1924,
1072,
1750,
2337,
365,
376,
4722,
1750,
1314,
272,
883,
3752,
4722,
6363,
436,
315,
22990,
14,
339,
3897,
272,
4143,
272,
302,
63,
3512,
520,
1109,
267,
4860,
402,
6363,
402,
1072,
2860,
14,
339,
302,
63,
11873,
10138,
520,
1109,
503,
488,
334,
885,
29,
403,
680,
267,
4860,
402,
1324,
4534,
1126,
1324,
1750,
14,
267,
1124,
403,
1040,
4910,
652,
365,
4472,
370,
1124,
78,
63,
3512,
4345,
339,
302,
63,
4981,
63,
529,
63,
1302,
520,
1109,
503,
769,
334,
885,
29,
18,
9,
267,
4860,
402,
2465,
343,
6363,
4568,
543,
1924,
2607,
29454,
1174,
14,
267,
6855,
506,
1902,
376,
3000,
12,
1314,
4910,
314,
2011,
1329,
267,
402,
8752,
6363,
911,
506,
1202,
367,
1006,
2607,
29454,
6363,
12,
503,
282,
769,
267,
402,
9446,
402,
2582,
1124,
78,
63,
3512,
4345,
339,
17353,
63,
765,
520,
1059,
12,
849,
628,
350,
19,
2,
267,
6801,
370,
1240,
370,
886,
17353,
436,
5621,
13,
20669,
2509,
17353,
14,
267,
18558,
1338,
787,
26,
953,
446,
283,
988,
13,
2558,
7,
367,
1390,
13,
2558,
506,
317,
2829,
17012,
14,
355,
799,
11902,
367,
30640,
376,
14416,
14,
3835,
927,
506,
317,
2829,
20796,
14667,
315,
1930,
402,
282,
8605,
3343,
14,
288,
446,
283,
10343,
7,
367,
12489,
2165,
9258,
13773,
88,
425,
1808,
6277,
88,
2992,
14,
288,
446,
283,
350,
19,
7,
367,
16271,
19,
21164,
22706,
14,
288,
446,
283,
15202,
656,
7,
367,
1413,
48,
3973,
435,
5131,
14819,
14,
288,
446,
283,
974,
77,
7,
367,
3232,
22636,
17353,
18036,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
302,
63,
3512,
29,
403,
12,
302,
63,
3179,
29,
403,
12,
302,
63,
4981,
63,
529,
63,
1302,
29,
18,
12,
326,
17353,
63,
765,
29,
403,
304,
267,
291,
14,
78,
63,
3512,
275,
302,
63,
3512,
267,
291,
14,
78,
63,
4981,
63,
529,
63,
1302,
275,
302,
63,
4981,
63,
529,
63,
1302,
267,
11513,
2944,
38,
855,
826,
721,
277,
12,
302,
63,
4981,
29,
403,
12,
302,
63,
3179,
29,
78,
63,
3179,
12,
2079,
17353,
63,
765,
29,
20580,
63,
765,
9,
339,
347,
485,
409,
63,
890,
63,
10153,
63,
4445,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
40223246/0622cdb-Final-TEST2-1
|
static/Brython3.1.1-20150328-091302/Lib/xml/sax/_exceptions.py
|
625
|
4885
|
"""Different kinds of SAX Exceptions"""
#in brython the 4 lines below causes an $globals['Exception'] error
#import sys
#if sys.platform[:4] == "java":
# from java.lang import Exception
#del sys
# ===== SAXEXCEPTION =====
class SAXException(Exception):
"""Encapsulate an XML error or warning. This class can contain
basic error or warning information from either the XML parser or
the application: you can subclass it to provide additional
functionality, or to add localization. Note that although you will
receive a SAXException as the argument to the handlers in the
ErrorHandler interface, you are not actually required to raise
the exception; instead, you can simply read the information in
it."""
def __init__(self, msg, exception=None):
"""Creates an exception. The message is required, but the exception
is optional."""
self._msg = msg
self._exception = exception
Exception.__init__(self, msg)
def getMessage(self):
"Return a message for this exception."
return self._msg
def getException(self):
"Return the embedded exception, or None if there was none."
return self._exception
def __str__(self):
"Create a string representation of the exception."
return self._msg
def __getitem__(self, ix):
"""Avoids weird error messages if someone does exception[ix] by
mistake, since Exception has __getitem__ defined."""
raise AttributeError("__getitem__")
# ===== SAXPARSEEXCEPTION =====
class SAXParseException(SAXException):
"""Encapsulate an XML parse error or warning.
This exception will include information for locating the error in
the original XML document. Note that although the application will
receive a SAXParseException as the argument to the handlers in the
ErrorHandler interface, the application is not actually required
to raise the exception; instead, it can simply read the
information in it and take a different action.
Since this exception is a subclass of SAXException, it inherits
the ability to wrap another exception."""
def __init__(self, msg, exception, locator):
"Creates the exception. The exception parameter is allowed to be None."
SAXException.__init__(self, msg, exception)
self._locator = locator
# We need to cache this stuff at construction time.
# If this exception is raised, the objects through which we must
# traverse to get this information may be deleted by the time
# it gets caught.
self._systemId = self._locator.getSystemId()
self._colnum = self._locator.getColumnNumber()
self._linenum = self._locator.getLineNumber()
def getColumnNumber(self):
"""The column number of the end of the text where the exception
occurred."""
return self._colnum
def getLineNumber(self):
"The line number of the end of the text where the exception occurred."
return self._linenum
def getPublicId(self):
"Get the public identifier of the entity where the exception occurred."
return self._locator.getPublicId()
def getSystemId(self):
"Get the system identifier of the entity where the exception occurred."
return self._systemId
def __str__(self):
"Create a string representation of the exception."
sysid = self.getSystemId()
if sysid is None:
sysid = "<unknown>"
linenum = self.getLineNumber()
if linenum is None:
linenum = "?"
colnum = self.getColumnNumber()
if colnum is None:
colnum = "?"
return "%s:%s:%s: %s" % (sysid, linenum, colnum, self._msg)
# ===== SAXNOTRECOGNIZEDEXCEPTION =====
class SAXNotRecognizedException(SAXException):
"""Exception class for an unrecognized identifier.
An XMLReader will raise this exception when it is confronted with an
unrecognized feature or property. SAX applications and extensions may
use this class for similar purposes."""
pass
# ===== SAXNOTSUPPORTEDEXCEPTION =====
class SAXNotSupportedException(SAXException):
"""Exception class for an unsupported operation.
An XMLReader will raise this exception when a service it cannot
perform is requested (specifically setting a state or value). SAX
applications and extensions may use this class for similar
purposes."""
pass
# ===== SAXNOTSUPPORTEDEXCEPTION =====
class SAXReaderNotAvailable(SAXNotSupportedException):
"""Exception class for a missing driver.
An XMLReader module (driver) should raise this exception when it
is first imported, e.g. when a support module cannot be imported.
It also may be raised during parsing, e.g. if executing an external
program is not permitted."""
pass
|
gpl-3.0
|
[
624,
31409,
24241,
402,
19310,
24873,
624,
199,
3,
262,
330,
23196,
314,
841,
2385,
5084,
14486,
376,
2672,
8473,
459,
1726,
418,
1125,
199,
3,
646,
984,
199,
3,
692,
984,
14,
3246,
1491,
20,
61,
508,
298,
6138,
582,
199,
3,
259,
687,
12120,
14,
4159,
492,
2186,
199,
3,
2264,
984,
199,
199,
3,
9310,
19310,
15375,
9310,
199,
199,
533,
19310,
1726,
8,
1726,
304,
272,
408,
1327,
12029,
5434,
376,
4692,
1125,
503,
5721,
14,
961,
1021,
883,
1395,
272,
5678,
1125,
503,
5721,
2556,
687,
1902,
314,
4692,
1798,
503,
272,
314,
4223,
26,
1265,
883,
5516,
652,
370,
5647,
4722,
272,
9330,
12,
503,
370,
1050,
2257,
2072,
14,
3390,
626,
22160,
1265,
911,
272,
9128,
282,
19310,
1726,
465,
314,
1423,
370,
314,
8297,
315,
314,
272,
4520,
2461,
3217,
12,
1265,
787,
440,
5965,
1415,
370,
746,
272,
314,
1919,
27,
3140,
12,
1265,
883,
9329,
1586,
314,
2556,
315,
272,
652,
1041,
339,
347,
636,
826,
721,
277,
12,
1499,
12,
1919,
29,
403,
304,
267,
408,
10607,
376,
1919,
14,
710,
1245,
365,
1415,
12,
1325,
314,
1919,
267,
365,
2716,
1041,
267,
291,
423,
1328,
275,
1499,
267,
291,
423,
1971,
275,
1919,
267,
2186,
855,
826,
721,
277,
12,
1499,
9,
339,
347,
664,
2209,
8,
277,
304,
267,
298,
1767,
282,
1245,
367,
642,
1919,
2122,
267,
372,
291,
423,
1328,
339,
347,
664,
1726,
8,
277,
304,
267,
298,
1767,
314,
12169,
1919,
12,
503,
488,
340,
2337,
1990,
7179,
2122,
267,
372,
291,
423,
1971,
339,
347,
636,
495,
721,
277,
304,
267,
298,
2499,
282,
1059,
6025,
402,
314,
1919,
2122,
267,
372,
291,
423,
1328,
339,
347,
636,
6095,
721,
277,
12,
20593,
304,
267,
408,
33,
1647,
83,
22965,
1125,
3788,
340,
17122,
1630,
1919,
59,
1148,
61,
701,
267,
27572,
1728,
12,
3967,
2186,
965,
636,
6095,
363,
3247,
1041,
267,
746,
4281,
16232,
6095,
18617,
421,
199,
3,
9310,
19310,
23354,
15375,
9310,
199,
199,
533,
19310,
4003,
1726,
8,
4251,
56,
1726,
304,
272,
408,
1327,
12029,
5434,
376,
4692,
2198,
1125,
503,
5721,
14,
339,
961,
1919,
911,
2387,
2556,
367,
4355,
1958,
314,
1125,
315,
272,
314,
3379,
4692,
2213,
14,
3390,
626,
22160,
314,
4223,
911,
272,
9128,
282,
19310,
4003,
1726,
465,
314,
1423,
370,
314,
8297,
315,
314,
272,
4520,
2461,
3217,
12,
314,
4223,
365,
440,
5965,
1415,
272,
370,
746,
314,
1919,
27,
3140,
12,
652,
883,
9329,
1586,
314,
272,
2556,
315,
652,
436,
5452,
282,
3365,
1595,
14,
339,
9336,
642,
1919,
365,
282,
5516,
402,
19310,
1726,
12,
652,
21592,
272,
314,
21255,
370,
4816,
4573,
1919,
1041,
339,
347,
636,
826,
721,
277,
12,
1499,
12,
1919,
12,
14067,
304,
267,
298,
10607,
314,
1919,
14,
710,
1919,
2725,
365,
4370,
370,
506,
488,
2122,
267,
19310,
1726,
855,
826,
721,
277,
12,
1499,
12,
1919,
9,
267,
291,
423,
6354,
275,
14067,
398,
327,
2136,
1929,
370,
2581,
642,
8292,
737,
14538,
900,
14,
267,
327,
982,
642,
1919,
365,
4915,
12,
314,
2251,
4012,
1314,
781,
1471,
267,
327,
24749,
370,
664,
642,
2556,
1443,
506,
5463,
701,
314,
900,
267,
327,
652,
7545,
15604,
14,
267,
291,
423,
20150,
275,
291,
423,
6354,
14,
362,
28440,
342,
267,
291,
423,
761,
1507,
275,
291,
423,
6354,
14,
362,
4547,
3259,
342,
267,
291,
423,
19466,
275,
291,
423,
6354,
14,
362,
3049,
3259,
342,
339,
347,
664,
4547,
3259,
8,
277,
304,
267,
408,
1918,
2763,
1329,
402,
314,
1284,
402,
314,
1318,
2382,
314,
1919,
267,
8920,
1041,
267,
372,
291,
423,
761,
1507,
339,
347,
664,
3049,
3259,
8,
277,
304,
267,
298,
1918,
1004,
1329,
402,
314,
1284,
402,
314,
1318,
2382,
314,
1919,
8920,
2122,
267,
372,
291,
423,
19466,
339,
347,
664,
9885,
1304,
8,
277,
304,
267,
298,
1002,
314,
4575,
5148,
402,
314,
4642,
2382,
314,
1919,
8920,
2122,
267,
372,
291,
423,
6354,
14,
362,
9885,
1304,
342,
339,
347,
664,
28440,
8,
277,
304,
267,
298,
1002,
314,
2656,
5148,
402,
314,
4642,
2382,
314,
1919,
8920,
2122,
267,
372,
291,
423,
20150,
339,
347,
636,
495,
721,
277,
304,
267,
298,
2499,
282,
1059,
6025,
402,
314,
1919,
2122,
267,
1847,
4148,
275,
291,
14,
362,
28440,
342,
267,
340,
1847,
4148,
365,
488,
26,
288,
1847,
4148,
275,
3886,
5187,
4335,
267,
13434,
275,
291,
14,
362,
3049,
3259,
342,
267,
340,
13434,
365,
488,
26,
288,
13434,
275,
29325,
267,
1048,
1507,
275,
291,
14,
362,
4547,
3259,
342,
267,
340,
1048,
1507,
365,
488,
26,
288,
1048,
1507,
275,
29325,
267,
372,
2071,
83,
2689,
83,
2689,
83,
26,
450,
83,
2,
450,
334,
1786,
4148,
12,
13434,
12,
1048,
1507,
12,
291,
423,
1328,
9,
421,
199,
3,
9310,
19310,
4609,
907,
1439,
15306,
11025,
7746,
7177,
1075,
9310,
199,
199,
533,
19310,
1763,
497,
9659,
1726,
8,
4251,
56,
1726,
304,
272,
408,
1726,
1021,
367,
376,
24718,
5148,
14,
339,
1626,
4692,
5929,
911,
746,
642,
1919,
1380,
652,
365,
3743,
2641,
471,
543,
376,
272,
24718,
3878,
503,
3324,
14,
19310,
13103,
436,
5478,
1443,
272,
675,
642,
1021,
367,
8545,
12901,
1041,
272,
986,
421,
199,
3,
9310,
19310,
4609,
10640,
37,
7746,
7177,
1075,
9310,
199,
199,
533,
19310,
26077,
1726,
8,
4251,
56,
1726,
304,
272,
408,
1726,
1021,
367,
376,
16313,
3439,
14,
339,
1626,
4692,
5929,
911,
746,
642,
1919,
1380,
282,
2435,
652,
3913,
272,
5147,
365,
5839,
334,
6100,
1183,
4260,
282,
1174,
503,
574,
680,
19310,
272,
13103,
436,
5478,
1443,
675,
642,
1021,
367,
8545,
272,
12901,
1041,
339,
986,
199,
3,
9310,
19310,
4609,
10640,
37,
7746,
7177,
1075,
9310,
199,
199,
533,
19310,
5929,
1763,
11464,
8,
4251,
56,
26077,
1726,
304,
272,
408,
1726,
1021,
367,
282,
4124,
5253,
14,
339,
1626,
4692,
5929,
859,
334,
3090,
9,
1077,
746,
642,
1919,
1380,
652,
272,
365,
1642,
8439,
12,
325,
14,
71,
14,
1380,
282,
2291,
859,
3913,
506,
8439,
14,
272,
2779,
2597,
1443,
506,
4915,
5309,
6057
] |
[
31409,
24241,
402,
19310,
24873,
624,
199,
3,
262,
330,
23196,
314,
841,
2385,
5084,
14486,
376,
2672,
8473,
459,
1726,
418,
1125,
199,
3,
646,
984,
199,
3,
692,
984,
14,
3246,
1491,
20,
61,
508,
298,
6138,
582,
199,
3,
259,
687,
12120,
14,
4159,
492,
2186,
199,
3,
2264,
984,
199,
199,
3,
9310,
19310,
15375,
9310,
199,
199,
533,
19310,
1726,
8,
1726,
304,
272,
408,
1327,
12029,
5434,
376,
4692,
1125,
503,
5721,
14,
961,
1021,
883,
1395,
272,
5678,
1125,
503,
5721,
2556,
687,
1902,
314,
4692,
1798,
503,
272,
314,
4223,
26,
1265,
883,
5516,
652,
370,
5647,
4722,
272,
9330,
12,
503,
370,
1050,
2257,
2072,
14,
3390,
626,
22160,
1265,
911,
272,
9128,
282,
19310,
1726,
465,
314,
1423,
370,
314,
8297,
315,
314,
272,
4520,
2461,
3217,
12,
1265,
787,
440,
5965,
1415,
370,
746,
272,
314,
1919,
27,
3140,
12,
1265,
883,
9329,
1586,
314,
2556,
315,
272,
652,
1041,
339,
347,
636,
826,
721,
277,
12,
1499,
12,
1919,
29,
403,
304,
267,
408,
10607,
376,
1919,
14,
710,
1245,
365,
1415,
12,
1325,
314,
1919,
267,
365,
2716,
1041,
267,
291,
423,
1328,
275,
1499,
267,
291,
423,
1971,
275,
1919,
267,
2186,
855,
826,
721,
277,
12,
1499,
9,
339,
347,
664,
2209,
8,
277,
304,
267,
298,
1767,
282,
1245,
367,
642,
1919,
2122,
267,
372,
291,
423,
1328,
339,
347,
664,
1726,
8,
277,
304,
267,
298,
1767,
314,
12169,
1919,
12,
503,
488,
340,
2337,
1990,
7179,
2122,
267,
372,
291,
423,
1971,
339,
347,
636,
495,
721,
277,
304,
267,
298,
2499,
282,
1059,
6025,
402,
314,
1919,
2122,
267,
372,
291,
423,
1328,
339,
347,
636,
6095,
721,
277,
12,
20593,
304,
267,
408,
33,
1647,
83,
22965,
1125,
3788,
340,
17122,
1630,
1919,
59,
1148,
61,
701,
267,
27572,
1728,
12,
3967,
2186,
965,
636,
6095,
363,
3247,
1041,
267,
746,
4281,
16232,
6095,
18617,
421,
199,
3,
9310,
19310,
23354,
15375,
9310,
199,
199,
533,
19310,
4003,
1726,
8,
4251,
56,
1726,
304,
272,
408,
1327,
12029,
5434,
376,
4692,
2198,
1125,
503,
5721,
14,
339,
961,
1919,
911,
2387,
2556,
367,
4355,
1958,
314,
1125,
315,
272,
314,
3379,
4692,
2213,
14,
3390,
626,
22160,
314,
4223,
911,
272,
9128,
282,
19310,
4003,
1726,
465,
314,
1423,
370,
314,
8297,
315,
314,
272,
4520,
2461,
3217,
12,
314,
4223,
365,
440,
5965,
1415,
272,
370,
746,
314,
1919,
27,
3140,
12,
652,
883,
9329,
1586,
314,
272,
2556,
315,
652,
436,
5452,
282,
3365,
1595,
14,
339,
9336,
642,
1919,
365,
282,
5516,
402,
19310,
1726,
12,
652,
21592,
272,
314,
21255,
370,
4816,
4573,
1919,
1041,
339,
347,
636,
826,
721,
277,
12,
1499,
12,
1919,
12,
14067,
304,
267,
298,
10607,
314,
1919,
14,
710,
1919,
2725,
365,
4370,
370,
506,
488,
2122,
267,
19310,
1726,
855,
826,
721,
277,
12,
1499,
12,
1919,
9,
267,
291,
423,
6354,
275,
14067,
398,
327,
2136,
1929,
370,
2581,
642,
8292,
737,
14538,
900,
14,
267,
327,
982,
642,
1919,
365,
4915,
12,
314,
2251,
4012,
1314,
781,
1471,
267,
327,
24749,
370,
664,
642,
2556,
1443,
506,
5463,
701,
314,
900,
267,
327,
652,
7545,
15604,
14,
267,
291,
423,
20150,
275,
291,
423,
6354,
14,
362,
28440,
342,
267,
291,
423,
761,
1507,
275,
291,
423,
6354,
14,
362,
4547,
3259,
342,
267,
291,
423,
19466,
275,
291,
423,
6354,
14,
362,
3049,
3259,
342,
339,
347,
664,
4547,
3259,
8,
277,
304,
267,
408,
1918,
2763,
1329,
402,
314,
1284,
402,
314,
1318,
2382,
314,
1919,
267,
8920,
1041,
267,
372,
291,
423,
761,
1507,
339,
347,
664,
3049,
3259,
8,
277,
304,
267,
298,
1918,
1004,
1329,
402,
314,
1284,
402,
314,
1318,
2382,
314,
1919,
8920,
2122,
267,
372,
291,
423,
19466,
339,
347,
664,
9885,
1304,
8,
277,
304,
267,
298,
1002,
314,
4575,
5148,
402,
314,
4642,
2382,
314,
1919,
8920,
2122,
267,
372,
291,
423,
6354,
14,
362,
9885,
1304,
342,
339,
347,
664,
28440,
8,
277,
304,
267,
298,
1002,
314,
2656,
5148,
402,
314,
4642,
2382,
314,
1919,
8920,
2122,
267,
372,
291,
423,
20150,
339,
347,
636,
495,
721,
277,
304,
267,
298,
2499,
282,
1059,
6025,
402,
314,
1919,
2122,
267,
1847,
4148,
275,
291,
14,
362,
28440,
342,
267,
340,
1847,
4148,
365,
488,
26,
288,
1847,
4148,
275,
3886,
5187,
4335,
267,
13434,
275,
291,
14,
362,
3049,
3259,
342,
267,
340,
13434,
365,
488,
26,
288,
13434,
275,
29325,
267,
1048,
1507,
275,
291,
14,
362,
4547,
3259,
342,
267,
340,
1048,
1507,
365,
488,
26,
288,
1048,
1507,
275,
29325,
267,
372,
2071,
83,
2689,
83,
2689,
83,
26,
450,
83,
2,
450,
334,
1786,
4148,
12,
13434,
12,
1048,
1507,
12,
291,
423,
1328,
9,
421,
199,
3,
9310,
19310,
4609,
907,
1439,
15306,
11025,
7746,
7177,
1075,
9310,
199,
199,
533,
19310,
1763,
497,
9659,
1726,
8,
4251,
56,
1726,
304,
272,
408,
1726,
1021,
367,
376,
24718,
5148,
14,
339,
1626,
4692,
5929,
911,
746,
642,
1919,
1380,
652,
365,
3743,
2641,
471,
543,
376,
272,
24718,
3878,
503,
3324,
14,
19310,
13103,
436,
5478,
1443,
272,
675,
642,
1021,
367,
8545,
12901,
1041,
272,
986,
421,
199,
3,
9310,
19310,
4609,
10640,
37,
7746,
7177,
1075,
9310,
199,
199,
533,
19310,
26077,
1726,
8,
4251,
56,
1726,
304,
272,
408,
1726,
1021,
367,
376,
16313,
3439,
14,
339,
1626,
4692,
5929,
911,
746,
642,
1919,
1380,
282,
2435,
652,
3913,
272,
5147,
365,
5839,
334,
6100,
1183,
4260,
282,
1174,
503,
574,
680,
19310,
272,
13103,
436,
5478,
1443,
675,
642,
1021,
367,
8545,
272,
12901,
1041,
339,
986,
199,
3,
9310,
19310,
4609,
10640,
37,
7746,
7177,
1075,
9310,
199,
199,
533,
19310,
5929,
1763,
11464,
8,
4251,
56,
26077,
1726,
304,
272,
408,
1726,
1021,
367,
282,
4124,
5253,
14,
339,
1626,
4692,
5929,
859,
334,
3090,
9,
1077,
746,
642,
1919,
1380,
652,
272,
365,
1642,
8439,
12,
325,
14,
71,
14,
1380,
282,
2291,
859,
3913,
506,
8439,
14,
272,
2779,
2597,
1443,
506,
4915,
5309,
6057,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
progrium/growl
|
external_dependencies/simple-mailer.py
|
1
|
2584
|
#!/usr/bin/env python
# Usage: simple-mailer [--[no-]tls] username[:password]@server[:port] from to subject
import optparse
parser = optparse.OptionParser(usage='%prog [options] username[:password]@server[:port] from to subject', description='Sends an email message, reading the password (unless specified on the command line) and body from standard input. The server and port are those of the SMTP server you want to use, and the username is the one you want to log in to that server with.\n' 'Putting the password on the command line is not recommended, as that makes it visible to other processes.')
parser.add_option('--tls', action='store_true', default=True, help='Enable TLS (default)')
parser.add_option('--no-tls', action='store_false', dest='tls', help='Disable TLS')
parser.add_option('--user-agent', default=None, help='Set the User-Agent string')
import sys
opts, args = parser.parse_args()
try:
hostspec, from_addr, to_addr, subject = args
except ValueError:
parser.print_help()
sys.exit(0)
u_p, s_p = hostspec.rsplit('@', 1)
try:
username, password = u_p.split(':')
except ValueError:
username = u_p
import getpass
password = getpass.getpass() if sys.stdin.isatty() else sys.stdin.readline().rstrip('\n')
else:
print >>sys.stderr, 'warning: including the password on the command line is insecure (it will show up in ps)'
try:
hostname, portstr = s_p.split(':')
except ValueError:
hostname = s_p
port = 587 if opts.tls else 25
else:
port = int(portstr)
major, minor, incremental, type, iteration = sys.version_info
python_version = '.'.join(map(str, [major, minor, incremental]))
user_agent_product_tokens = ['simple-mailer/1.0', 'python-smtplib/' + python_version]
if opts.user_agent:
if '/' not in opts.user_agent:
# SMTP doesn't really define the User-Agent header, which is why this is a soft warning and not a hard error.
print >>sys.stderr, 'warning: user-agent product token "%s" is not a valid product token, at least by the HTTP definition' % (opts.user_agent,)
user_agent_product_tokens.insert(0, opts.user_agent)
import smtplib
smtp = smtplib.SMTP(hostname, port)
smtp.ehlo()
if opts.tls:
smtp.starttls()
smtp.ehlo()
smtp.login(username, password)
del password
msg_lines = []
msg_lines.append('From: ' + from_addr + '\r\n')
msg_lines.append('To: ' + to_addr + '\r\n')
msg_lines.append('Subject: ' + subject + '\r\n')
msg_lines.append('User-Agent: ' + ' '.join(user_agent_product_tokens) + '\r\n')
msg_lines += (line.rstrip('\r\n') + '\r\n' for line in sys.stdin)
smtp.sendmail(from_addr, [to_addr], ''.join(msg_lines))
smtp.quit()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
11028,
26,
3486,
13,
391,
3566,
19344,
59,
889,
13,
61,
9945,
61,
3434,
1491,
2060,
61,
32,
1000,
1491,
719,
61,
687,
370,
5420,
199,
199,
646,
8691,
199,
2087,
275,
8691,
14,
14553,
8,
3807,
9569,
6595,
359,
1419,
61,
3434,
1491,
2060,
61,
32,
1000,
1491,
719,
61,
687,
370,
5420,
297,
1369,
534,
26276,
376,
3031,
1245,
12,
7664,
314,
2505,
334,
18447,
2013,
641,
314,
1414,
1004,
9,
436,
2396,
687,
4465,
1324,
14,
710,
1654,
436,
1844,
787,
5204,
402,
314,
19810,
1654,
1265,
2934,
370,
675,
12,
436,
314,
3434,
365,
314,
1373,
1265,
2934,
370,
943,
315,
370,
626,
1654,
543,
3134,
78,
7,
283,
18989,
1337,
314,
2505,
641,
314,
1414,
1004,
365,
440,
14318,
12,
465,
626,
7704,
652,
8917,
370,
1163,
10358,
2659,
199,
2087,
14,
525,
63,
1422,
4517,
9945,
297,
1595,
534,
1617,
63,
2052,
297,
849,
29,
549,
12,
1720,
534,
6476,
12213,
334,
885,
5942,
199,
2087,
14,
525,
63,
1422,
4517,
889,
13,
9945,
297,
1595,
534,
1617,
63,
3910,
297,
2053,
534,
9945,
297,
1720,
534,
13707,
12213,
358,
199,
2087,
14,
525,
63,
1422,
4517,
751,
13,
4054,
297,
849,
29,
403,
12,
1720,
534,
1084,
314,
2876,
13,
7788,
1059,
358,
199,
199,
646,
984,
199,
3291,
12,
1249,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
893,
26,
199,
198,
1102,
1650,
12,
687,
63,
2697,
12,
370,
63,
2697,
12,
5420,
275,
1249,
199,
2590,
1722,
26,
199,
198,
2087,
14,
1361,
63,
3437,
342,
199,
198,
1274,
14,
2224,
8,
16,
9,
199,
199,
85,
63,
80,
12,
308,
63,
80,
275,
1591,
1650,
14,
13490,
16591,
297,
413,
9,
199,
893,
26,
199,
198,
2473,
12,
2505,
275,
399,
63,
80,
14,
1294,
11633,
199,
2590,
1722,
26,
199,
198,
2473,
275,
399,
63,
80,
199,
198,
646,
18354,
199,
198,
2060,
275,
18354,
14,
27481,
342,
340,
984,
14,
6626,
14,
21122,
342,
587,
984,
14,
6626,
14,
6407,
1252,
6735,
2258,
78,
358,
199,
2836,
26,
199,
198,
1361,
4331,
1274,
14,
3083,
12,
283,
3764,
26,
5893,
314,
2505,
641,
314,
1414,
1004,
365,
26097,
334,
390,
911,
2498,
1536,
315,
7347,
3171,
199,
893,
26,
199,
198,
4269,
12,
1844,
495,
275,
308,
63,
80,
14,
1294,
11633,
199,
2590,
1722,
26,
199,
198,
4269,
275,
308,
63,
80,
199,
198,
719,
275,
959,
1555,
340,
3999,
14,
9945,
587,
5661,
199,
2836,
26,
199,
198,
719,
275,
1109,
8,
719,
495,
9,
199,
199,
8452,
12,
12612,
12,
16316,
12,
730,
12,
8494,
275,
984,
14,
1023,
63,
815,
199,
1548,
63,
1023,
275,
15671,
904,
8,
1130,
8,
495,
12,
359,
8452,
12,
12612,
12,
16316,
2459,
199,
751,
63,
4054,
63,
2558,
63,
4504,
275,
788,
4129,
13,
391,
3566,
15,
17,
14,
16,
297,
283,
1548,
13,
15592,
773,
4805,
435,
2366,
63,
1023,
61,
199,
692,
3999,
14,
751,
63,
4054,
26,
199,
198,
692,
7324,
440,
315,
3999,
14,
751,
63,
4054,
26,
507,
198,
3,
19810,
3181,
1133,
7710,
5627,
314,
2876,
13,
7788,
1406,
12,
1314,
365,
10842,
642,
365,
282,
11620,
5721,
436,
440,
282,
7508,
1125,
14,
507,
198,
1361,
4331,
1274,
14,
3083,
12,
283,
3764,
26,
922,
13,
4054,
3336,
1526,
2071,
83,
2,
365,
440,
282,
1686,
3336,
1526,
12,
737,
5210,
701,
314,
3101,
5492,
7,
450,
334,
3291,
14,
751,
63,
4054,
4258,
199,
198,
751,
63,
4054,
63,
2558,
63,
4504,
14,
3176,
8,
16,
12,
3999,
14,
751,
63,
4054,
9,
199,
199,
646,
30475,
199,
15592,
275,
30475,
14,
20927,
8,
4269,
12,
1844,
9,
199,
15592,
14,
24528,
320,
342,
199,
692,
3999,
14,
9945,
26,
199,
198,
15592,
14,
928,
9945,
342,
199,
198,
15592,
14,
24528,
320,
342,
199,
15592,
14,
2886,
8,
2473,
12,
2505,
9,
199,
2264,
2505,
199,
199,
1328,
63,
1278,
275,
942,
199,
1328,
63,
1278,
14,
740,
360,
2532,
26,
283,
435,
687,
63,
2697,
435,
1557,
82,
60,
78,
358,
199,
1328,
63,
1278,
14,
740,
360,
1378,
26,
283,
435,
370,
63,
2697,
435,
1557,
82,
60,
78,
358,
199,
1328,
63,
1278,
14,
740,
360,
13528,
26,
283,
435,
5420,
435,
1557,
82,
60,
78,
358,
199,
1328,
63,
1278,
14,
740,
360,
1899,
13,
7788,
26,
283,
435,
283,
1987,
904,
8,
751,
63,
4054,
63,
2558,
63,
4504,
9,
435,
1557,
82,
60,
78,
358,
199,
1328,
63,
1278,
847,
334,
604,
14,
6735,
2258,
82,
60,
78,
358,
435,
1557,
82,
60,
78,
7,
367,
1004,
315,
984,
14,
6626,
9,
199,
15592,
14,
2254,
1198,
8,
504,
63,
2697,
12,
359,
475,
63,
2697,
467,
6522,
904,
8,
1328,
63,
1278,
430,
199,
15592,
14,
10589,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
11028,
26,
3486,
13,
391,
3566,
19344,
59,
889,
13,
61,
9945,
61,
3434,
1491,
2060,
61,
32,
1000,
1491,
719,
61,
687,
370,
5420,
199,
199,
646,
8691,
199,
2087,
275,
8691,
14,
14553,
8,
3807,
9569,
6595,
359,
1419,
61,
3434,
1491,
2060,
61,
32,
1000,
1491,
719,
61,
687,
370,
5420,
297,
1369,
534,
26276,
376,
3031,
1245,
12,
7664,
314,
2505,
334,
18447,
2013,
641,
314,
1414,
1004,
9,
436,
2396,
687,
4465,
1324,
14,
710,
1654,
436,
1844,
787,
5204,
402,
314,
19810,
1654,
1265,
2934,
370,
675,
12,
436,
314,
3434,
365,
314,
1373,
1265,
2934,
370,
943,
315,
370,
626,
1654,
543,
3134,
78,
7,
283,
18989,
1337,
314,
2505,
641,
314,
1414,
1004,
365,
440,
14318,
12,
465,
626,
7704,
652,
8917,
370,
1163,
10358,
2659,
199,
2087,
14,
525,
63,
1422,
4517,
9945,
297,
1595,
534,
1617,
63,
2052,
297,
849,
29,
549,
12,
1720,
534,
6476,
12213,
334,
885,
5942,
199,
2087,
14,
525,
63,
1422,
4517,
889,
13,
9945,
297,
1595,
534,
1617,
63,
3910,
297,
2053,
534,
9945,
297,
1720,
534,
13707,
12213,
358,
199,
2087,
14,
525,
63,
1422,
4517,
751,
13,
4054,
297,
849,
29,
403,
12,
1720,
534,
1084,
314,
2876,
13,
7788,
1059,
358,
199,
199,
646,
984,
199,
3291,
12,
1249,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
893,
26,
199,
198,
1102,
1650,
12,
687,
63,
2697,
12,
370,
63,
2697,
12,
5420,
275,
1249,
199,
2590,
1722,
26,
199,
198,
2087,
14,
1361,
63,
3437,
342,
199,
198,
1274,
14,
2224,
8,
16,
9,
199,
199,
85,
63,
80,
12,
308,
63,
80,
275,
1591,
1650,
14,
13490,
16591,
297,
413,
9,
199,
893,
26,
199,
198,
2473,
12,
2505,
275,
399,
63,
80,
14,
1294,
11633,
199,
2590,
1722,
26,
199,
198,
2473,
275,
399,
63,
80,
199,
198,
646,
18354,
199,
198,
2060,
275,
18354,
14,
27481,
342,
340,
984,
14,
6626,
14,
21122,
342,
587,
984,
14,
6626,
14,
6407,
1252,
6735,
2258,
78,
358,
199,
2836,
26,
199,
198,
1361,
4331,
1274,
14,
3083,
12,
283,
3764,
26,
5893,
314,
2505,
641,
314,
1414,
1004,
365,
26097,
334,
390,
911,
2498,
1536,
315,
7347,
3171,
199,
893,
26,
199,
198,
4269,
12,
1844,
495,
275,
308,
63,
80,
14,
1294,
11633,
199,
2590,
1722,
26,
199,
198,
4269,
275,
308,
63,
80,
199,
198,
719,
275,
959,
1555,
340,
3999,
14,
9945,
587,
5661,
199,
2836,
26,
199,
198,
719,
275,
1109,
8,
719,
495,
9,
199,
199,
8452,
12,
12612,
12,
16316,
12,
730,
12,
8494,
275,
984,
14,
1023,
63,
815,
199,
1548,
63,
1023,
275,
15671,
904,
8,
1130,
8,
495,
12,
359,
8452,
12,
12612,
12,
16316,
2459,
199,
751,
63,
4054,
63,
2558,
63,
4504,
275,
788,
4129,
13,
391,
3566,
15,
17,
14,
16,
297,
283,
1548,
13,
15592,
773,
4805,
435,
2366,
63,
1023,
61,
199,
692,
3999,
14,
751,
63,
4054,
26,
199,
198,
692,
7324,
440,
315,
3999,
14,
751,
63,
4054,
26,
507,
198,
3,
19810,
3181,
1133,
7710,
5627,
314,
2876,
13,
7788,
1406,
12,
1314,
365,
10842,
642,
365,
282,
11620,
5721,
436,
440,
282,
7508,
1125,
14,
507,
198,
1361,
4331,
1274,
14,
3083,
12,
283,
3764,
26,
922,
13,
4054,
3336,
1526,
2071,
83,
2,
365,
440,
282,
1686,
3336,
1526,
12,
737,
5210,
701,
314,
3101,
5492,
7,
450,
334,
3291,
14,
751,
63,
4054,
4258,
199,
198,
751,
63,
4054,
63,
2558,
63,
4504,
14,
3176,
8,
16,
12,
3999,
14,
751,
63,
4054,
9,
199,
199,
646,
30475,
199,
15592,
275,
30475,
14,
20927,
8,
4269,
12,
1844,
9,
199,
15592,
14,
24528,
320,
342,
199,
692,
3999,
14,
9945,
26,
199,
198,
15592,
14,
928,
9945,
342,
199,
198,
15592,
14,
24528,
320,
342,
199,
15592,
14,
2886,
8,
2473,
12,
2505,
9,
199,
2264,
2505,
199,
199,
1328,
63,
1278,
275,
942,
199,
1328,
63,
1278,
14,
740,
360,
2532,
26,
283,
435,
687,
63,
2697,
435,
1557,
82,
60,
78,
358,
199,
1328,
63,
1278,
14,
740,
360,
1378,
26,
283,
435,
370,
63,
2697,
435,
1557,
82,
60,
78,
358,
199,
1328,
63,
1278,
14,
740,
360,
13528,
26,
283,
435,
5420,
435,
1557,
82,
60,
78,
358,
199,
1328,
63,
1278,
14,
740,
360,
1899,
13,
7788,
26,
283,
435,
283,
1987,
904,
8,
751,
63,
4054,
63,
2558,
63,
4504,
9,
435,
1557,
82,
60,
78,
358,
199,
1328,
63,
1278,
847,
334,
604,
14,
6735,
2258,
82,
60,
78,
358,
435,
1557,
82,
60,
78,
7,
367,
1004,
315,
984,
14,
6626,
9,
199,
15592,
14,
2254,
1198,
8,
504,
63,
2697,
12,
359,
475,
63,
2697,
467,
6522,
904,
8,
1328,
63,
1278,
430,
199,
15592,
14,
10589,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
benoitbryon/xal
|
setup.py
|
1
|
2352
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Python packaging."""
import os
import sys
from setuptools import setup
from setuptools.command.test import test as TestCommand
class Tox(TestCommand):
"""Test command that runs tox."""
def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
self.test_suite = True
def run_tests(self):
import tox # import here, cause outside the eggs aren't loaded.
errno = tox.cmdline(self.test_args)
sys.exit(errno)
#: Absolute path to directory containing setup.py file.
here = os.path.abspath(os.path.dirname(__file__))
#: Boolean, ``True`` if environment is running Python version 2.
IS_PYTHON2 = sys.version_info[0] == 2
# Data for use in setup.
NAME = 'xal'
DESCRIPTION = 'Execution abstraction layer for high-level system scripts.'
README = open(os.path.join(here, 'README.rst')).read()
VERSION = open(os.path.join(here, 'VERSION')).read().strip()
AUTHOR = u'Benoît Bryon'
EMAIL = 'benoit@marmelune.net'
LICENSE = 'BSD'
URL = 'https://{name}.readthedocs.org/'.format(name=NAME)
CLASSIFIERS = [
'Development Status :: 1 - Planning',
'License :: OSI Approved :: BSD License',
'Intended Audience :: Developers',
'Programming Language :: Python :: 2.7',
]
KEYWORDS = [
'shell',
'path',
'subprocess',
'fabric',
]
PACKAGES = [NAME.replace('-', '_')]
REQUIREMENTS = [
'setuptools',
]
if IS_PYTHON2:
REQUIREMENTS.extend([
'mock',
'pathlib',
])
ENTRY_POINTS = {}
TEST_REQUIREMENTS = ['tox']
CMDCLASS = {'test': Tox}
EXTRA_REQUIREMENTS = {
'test': TEST_REQUIREMENTS,
'local': [],
'ssh': ['fabric', 'fabtools'],
}
if __name__ == '__main__': # Do not run setup() when we import this module.
setup(
name=NAME,
version=VERSION,
description=DESCRIPTION,
long_description=README,
classifiers=CLASSIFIERS,
keywords=' '.join(KEYWORDS),
author=AUTHOR,
author_email=EMAIL,
url=URL,
license=LICENSE,
packages=PACKAGES,
include_package_data=True,
zip_safe=False,
install_requires=REQUIREMENTS,
entry_points=ENTRY_POINTS,
tests_require=TEST_REQUIREMENTS,
cmdclass=CMDCLASS,
extras_require=EXTRA_REQUIREMENTS,
)
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
4718,
27369,
1041,
199,
646,
747,
199,
646,
984,
199,
199,
504,
9116,
492,
3272,
199,
504,
9116,
14,
1531,
14,
396,
492,
511,
465,
1379,
3110,
421,
199,
533,
4005,
88,
8,
774,
3110,
304,
272,
408,
774,
1414,
626,
7858,
370,
88,
1041,
272,
347,
17284,
63,
1419,
8,
277,
304,
267,
1379,
3110,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
396,
63,
589,
275,
942,
267,
291,
14,
396,
63,
5768,
275,
715,
339,
347,
1255,
63,
2219,
8,
277,
304,
267,
492,
370,
88,
221,
327,
492,
2348,
12,
7675,
9682,
314,
22151,
10621,
1133,
6511,
14,
267,
7554,
275,
370,
88,
14,
15612,
8,
277,
14,
396,
63,
589,
9,
267,
984,
14,
2224,
8,
7931,
9,
421,
199,
12573,
24964,
931,
370,
2082,
3035,
3272,
14,
647,
570,
14,
199,
1681,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
12573,
9411,
12,
1124,
549,
1040,
340,
3734,
365,
3879,
2018,
1015,
499,
14,
199,
1311,
63,
11720,
18,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
421,
199,
3,
3918,
367,
675,
315,
3272,
14,
199,
2339,
275,
283,
88,
279,
7,
199,
17705,
275,
283,
11310,
2236,
29639,
4045,
367,
4721,
13,
1896,
2656,
10554,
3530,
199,
18195,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
1681,
12,
283,
18195,
14,
8332,
11103,
739,
342,
199,
4612,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
1681,
12,
283,
4612,
11103,
739,
1252,
1913,
342,
199,
27938,
275,
399,
7,
31231,
79,
128,
107,
84,
699,
651,
265,
7,
199,
10089,
275,
283,
18486,
79,
390,
32,
4584,
26908,
11474,
14,
846,
7,
199,
3961,
275,
283,
15400,
7,
199,
2632,
275,
283,
2859,
20193,
354,
5565,
25085,
14,
1308,
15,
1370,
908,
8,
354,
29,
2339,
9,
199,
31163,
1976,
3960,
275,
359,
272,
283,
23753,
9795,
3800,
413,
446,
7497,
11495,
297,
272,
283,
3761,
3800,
25718,
26330,
3800,
6289,
844,
297,
272,
283,
23910,
23975,
3800,
23493,
297,
272,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
199,
61,
199,
32187,
275,
359,
272,
283,
5641,
297,
272,
283,
515,
297,
272,
283,
5781,
297,
272,
283,
4991,
297,
199,
61,
199,
6961,
5383,
275,
359,
2339,
14,
1814,
13858,
2513,
5440,
199,
29168,
20967,
275,
359,
272,
283,
13623,
297,
199,
61,
199,
692,
2281,
63,
11720,
18,
26,
272,
17023,
21201,
20967,
14,
2880,
779,
267,
283,
1805,
297,
267,
283,
515,
773,
297,
272,
4794,
199,
7285,
63,
7217,
51,
275,
1052,
199,
2864,
63,
29168,
20967,
275,
788,
475,
88,
418,
199,
9744,
6885,
275,
791,
396,
356,
4005,
88,
93,
199,
18555,
63,
29168,
20967,
275,
469,
272,
283,
396,
356,
7393,
63,
29168,
20967,
12,
272,
283,
1832,
356,
990,
272,
283,
5510,
356,
788,
4991,
297,
283,
21159,
2537,
995,
199,
93,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
221,
327,
4226,
440,
1255,
3272,
342,
1380,
781,
492,
642,
859,
14,
272,
3272,
8,
267,
536,
29,
2339,
12,
267,
1015,
29,
4612,
12,
267,
1369,
29,
17705,
12,
267,
1846,
63,
1802,
29,
18195,
12,
267,
19137,
29,
31163,
1976,
3960,
12,
267,
7681,
534,
1987,
904,
8,
32187,
395,
267,
4132,
29,
27938,
12,
267,
4132,
63,
2123,
29,
10089,
12,
267,
1166,
29,
2632,
12,
267,
4190,
29,
3961,
12,
267,
6117,
29,
6961,
5383,
12,
267,
2387,
63,
2491,
63,
576,
29,
549,
12,
267,
3482,
63,
3489,
29,
797,
12,
267,
3907,
63,
6537,
29,
29168,
20967,
12,
267,
2397,
63,
3438,
29,
7285,
63,
7217,
51,
12,
267,
2295,
63,
4365,
29,
2864,
63,
29168,
20967,
12,
267,
2088,
533,
29,
9744,
6885,
12,
267,
13751,
63,
4365,
29,
18555,
63,
29168,
20967,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
624,
4718,
27369,
1041,
199,
646,
747,
199,
646,
984,
199,
199,
504,
9116,
492,
3272,
199,
504,
9116,
14,
1531,
14,
396,
492,
511,
465,
1379,
3110,
421,
199,
533,
4005,
88,
8,
774,
3110,
304,
272,
408,
774,
1414,
626,
7858,
370,
88,
1041,
272,
347,
17284,
63,
1419,
8,
277,
304,
267,
1379,
3110,
14,
14450,
63,
1419,
8,
277,
9,
267,
291,
14,
396,
63,
589,
275,
942,
267,
291,
14,
396,
63,
5768,
275,
715,
339,
347,
1255,
63,
2219,
8,
277,
304,
267,
492,
370,
88,
221,
327,
492,
2348,
12,
7675,
9682,
314,
22151,
10621,
1133,
6511,
14,
267,
7554,
275,
370,
88,
14,
15612,
8,
277,
14,
396,
63,
589,
9,
267,
984,
14,
2224,
8,
7931,
9,
421,
199,
12573,
24964,
931,
370,
2082,
3035,
3272,
14,
647,
570,
14,
199,
1681,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
12573,
9411,
12,
1124,
549,
1040,
340,
3734,
365,
3879,
2018,
1015,
499,
14,
199,
1311,
63,
11720,
18,
275,
984,
14,
1023,
63,
815,
59,
16,
61,
508,
499,
421,
199,
3,
3918,
367,
675,
315,
3272,
14,
199,
2339,
275,
283,
88,
279,
7,
199,
17705,
275,
283,
11310,
2236,
29639,
4045,
367,
4721,
13,
1896,
2656,
10554,
3530,
199,
18195,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
1681,
12,
283,
18195,
14,
8332,
11103,
739,
342,
199,
4612,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
1681,
12,
283,
4612,
11103,
739,
1252,
1913,
342,
199,
27938,
275,
399,
7,
31231,
79,
128,
107,
84,
699,
651,
265,
7,
199,
10089,
275,
283,
18486,
79,
390,
32,
4584,
26908,
11474,
14,
846,
7,
199,
3961,
275,
283,
15400,
7,
199,
2632,
275,
283,
2859,
20193,
354,
5565,
25085,
14,
1308,
15,
1370,
908,
8,
354,
29,
2339,
9,
199,
31163,
1976,
3960,
275,
359,
272,
283,
23753,
9795,
3800,
413,
446,
7497,
11495,
297,
272,
283,
3761,
3800,
25718,
26330,
3800,
6289,
844,
297,
272,
283,
23910,
23975,
3800,
23493,
297,
272,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
199,
61,
199,
32187,
275,
359,
272,
283,
5641,
297,
272,
283,
515,
297,
272,
283,
5781,
297,
272,
283,
4991,
297,
199,
61,
199,
6961,
5383,
275,
359,
2339,
14,
1814,
13858,
2513,
5440,
199,
29168,
20967,
275,
359,
272,
283,
13623,
297,
199,
61,
199,
692,
2281,
63,
11720,
18,
26,
272,
17023,
21201,
20967,
14,
2880,
779,
267,
283,
1805,
297,
267,
283,
515,
773,
297,
272,
4794,
199,
7285,
63,
7217,
51,
275,
1052,
199,
2864,
63,
29168,
20967,
275,
788,
475,
88,
418,
199,
9744,
6885,
275,
791,
396,
356,
4005,
88,
93,
199,
18555,
63,
29168,
20967,
275,
469,
272,
283,
396,
356,
7393,
63,
29168,
20967,
12,
272,
283,
1832,
356,
990,
272,
283,
5510,
356,
788,
4991,
297,
283,
21159,
2537,
995,
199,
93,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
221,
327,
4226,
440,
1255,
3272,
342,
1380,
781,
492,
642,
859,
14,
272,
3272,
8,
267,
536,
29,
2339,
12,
267,
1015,
29,
4612,
12,
267,
1369,
29,
17705,
12,
267,
1846,
63,
1802,
29,
18195,
12,
267,
19137,
29,
31163,
1976,
3960,
12,
267,
7681,
534,
1987,
904,
8,
32187,
395,
267,
4132,
29,
27938,
12,
267,
4132,
63,
2123,
29,
10089,
12,
267,
1166,
29,
2632,
12,
267,
4190,
29,
3961,
12,
267,
6117,
29,
6961,
5383,
12,
267,
2387,
63,
2491,
63,
576,
29,
549,
12,
267,
3482,
63,
3489,
29,
797,
12,
267,
3907,
63,
6537,
29,
29168,
20967,
12,
267,
2397,
63,
3438,
29,
7285,
63,
7217,
51,
12,
267,
2295,
63,
4365,
29,
2864,
63,
29168,
20967,
12,
267,
2088,
533,
29,
9744,
6885,
12,
267,
13751,
63,
4365,
29,
18555,
63,
29168,
20967,
12,
272,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
vipul-sharma20/oh-mainline
|
vendor/packages/twisted/twisted/mail/pop3.py
|
17
|
33601
|
# -*- test-case-name: twisted.mail.test.test_pop3 -*-
#
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Post-office Protocol version 3
@author: Glyph Lefkowitz
@author: Jp Calderone
"""
import string
import base64
import binascii
import warnings
from zope.interface import implements, Interface
from twisted.mail import smtp
from twisted.protocols import basic
from twisted.protocols import policies
from twisted.internet import task
from twisted.internet import defer
from twisted.internet import interfaces
from twisted.python import log
from twisted.python.hashlib import md5
from twisted import cred
import twisted.cred.error
import twisted.cred.credentials
##
## Authentication
##
class APOPCredentials:
implements(cred.credentials.IUsernamePassword)
def __init__(self, magic, username, digest):
self.magic = magic
self.username = username
self.digest = digest
def checkPassword(self, password):
seed = self.magic + password
myDigest = md5(seed).hexdigest()
return myDigest == self.digest
class _HeadersPlusNLines:
def __init__(self, f, n):
self.f = f
self.n = n
self.linecount = 0
self.headers = 1
self.done = 0
self.buf = ''
def read(self, bytes):
if self.done:
return ''
data = self.f.read(bytes)
if not data:
return data
if self.headers:
df, sz = data.find('\r\n\r\n'), 4
if df == -1:
df, sz = data.find('\n\n'), 2
if df != -1:
df += sz
val = data[:df]
data = data[df:]
self.linecount = 1
self.headers = 0
else:
val = ''
if self.linecount > 0:
dsplit = (self.buf+data).split('\n')
self.buf = dsplit[-1]
for ln in dsplit[:-1]:
if self.linecount > self.n:
self.done = 1
return val
val += (ln + '\n')
self.linecount += 1
return val
else:
return data
class _POP3MessageDeleted(Exception):
"""
Internal control-flow exception. Indicates the file of a deleted message
was requested.
"""
class POP3Error(Exception):
pass
class _IteratorBuffer(object):
bufSize = 0
def __init__(self, write, iterable, memoryBufferSize=None):
"""
Create a _IteratorBuffer.
@param write: A one-argument callable which will be invoked with a list
of strings which have been buffered.
@param iterable: The source of input strings as any iterable.
@param memoryBufferSize: The upper limit on buffered string length,
beyond which the buffer will be flushed to the writer.
"""
self.lines = []
self.write = write
self.iterator = iter(iterable)
if memoryBufferSize is None:
memoryBufferSize = 2 ** 16
self.memoryBufferSize = memoryBufferSize
def __iter__(self):
return self
def next(self):
try:
v = self.iterator.next()
except StopIteration:
if self.lines:
self.write(self.lines)
# Drop some references, in case they're edges in a cycle.
del self.iterator, self.lines, self.write
raise
else:
if v is not None:
self.lines.append(v)
self.bufSize += len(v)
if self.bufSize > self.memoryBufferSize:
self.write(self.lines)
self.lines = []
self.bufSize = 0
def iterateLineGenerator(proto, gen):
"""
Hook the given protocol instance up to the given iterator with an
_IteratorBuffer and schedule the result to be exhausted via the protocol.
@type proto: L{POP3}
@type gen: iterator
@rtype: L{twisted.internet.defer.Deferred}
"""
coll = _IteratorBuffer(proto.transport.writeSequence, gen)
return proto.schedule(coll)
def successResponse(response):
"""
Format the given object as a positive response.
"""
response = str(response)
return '+OK %s\r\n' % (response,)
def formatStatResponse(msgs):
"""
Format the list of message sizes appropriately for a STAT response.
Yields None until it finishes computing a result, then yields a str
instance that is suitable for use as a response to the STAT command.
Intended to be used with a L{twisted.internet.task.Cooperator}.
"""
i = 0
bytes = 0
for size in msgs:
i += 1
bytes += size
yield None
yield successResponse('%d %d' % (i, bytes))
def formatListLines(msgs):
"""
Format a list of message sizes appropriately for the lines of a LIST
response.
Yields str instances formatted appropriately for use as lines in the
response to the LIST command. Does not include the trailing '.'.
"""
i = 0
for size in msgs:
i += 1
yield '%d %d\r\n' % (i, size)
def formatListResponse(msgs):
"""
Format a list of message sizes appropriately for a complete LIST response.
Yields str instances formatted appropriately for use as a LIST command
response.
"""
yield successResponse(len(msgs))
for ele in formatListLines(msgs):
yield ele
yield '.\r\n'
def formatUIDListLines(msgs, getUidl):
"""
Format the list of message sizes appropriately for the lines of a UIDL
response.
Yields str instances formatted appropriately for use as lines in the
response to the UIDL command. Does not include the trailing '.'.
"""
for i, m in enumerate(msgs):
if m is not None:
uid = getUidl(i)
yield '%d %s\r\n' % (i + 1, uid)
def formatUIDListResponse(msgs, getUidl):
"""
Format a list of message sizes appropriately for a complete UIDL response.
Yields str instances formatted appropriately for use as a UIDL command
response.
"""
yield successResponse('')
for ele in formatUIDListLines(msgs, getUidl):
yield ele
yield '.\r\n'
class POP3(basic.LineOnlyReceiver, policies.TimeoutMixin):
"""
POP3 server protocol implementation.
@ivar portal: A reference to the L{twisted.cred.portal.Portal} instance we
will authenticate through.
@ivar factory: A L{twisted.mail.pop3.IServerFactory} which will be used to
determine some extended behavior of the server.
@ivar timeOut: An integer which defines the minimum amount of time which
may elapse without receiving any traffic after which the client will be
disconnected.
@ivar schedule: A one-argument callable which should behave like
L{twisted.internet.task.coiterate}.
"""
implements(interfaces.IProducer)
magic = None
_userIs = None
_onLogout = None
AUTH_CMDS = ['CAPA', 'USER', 'PASS', 'APOP', 'AUTH', 'RPOP', 'QUIT']
portal = None
factory = None
# The mailbox we're serving
mbox = None
# Set this pretty low -- POP3 clients are expected to log in, download
# everything, and log out.
timeOut = 300
# Current protocol state
state = "COMMAND"
# PIPELINE
blocked = None
# Cooperate and suchlike.
schedule = staticmethod(task.coiterate)
# Message index of the highest retrieved message.
_highest = 0
def connectionMade(self):
if self.magic is None:
self.magic = self.generateMagic()
self.successResponse(self.magic)
self.setTimeout(self.timeOut)
if getattr(self.factory, 'noisy', True):
log.msg("New connection from " + str(self.transport.getPeer()))
def connectionLost(self, reason):
if self._onLogout is not None:
self._onLogout()
self._onLogout = None
self.setTimeout(None)
def generateMagic(self):
return smtp.messageid()
def successResponse(self, message=''):
self.transport.write(successResponse(message))
def failResponse(self, message=''):
self.sendLine('-ERR ' + str(message))
# def sendLine(self, line):
# print 'S:', repr(line)
# basic.LineOnlyReceiver.sendLine(self, line)
def lineReceived(self, line):
# print 'C:', repr(line)
self.resetTimeout()
getattr(self, 'state_' + self.state)(line)
def _unblock(self, _):
commands = self.blocked
self.blocked = None
while commands and self.blocked is None:
cmd, args = commands.pop(0)
self.processCommand(cmd, *args)
if self.blocked is not None:
self.blocked.extend(commands)
def state_COMMAND(self, line):
try:
return self.processCommand(*line.split(' '))
except (ValueError, AttributeError, POP3Error, TypeError), e:
log.err()
self.failResponse('bad protocol or server: %s: %s' % (e.__class__.__name__, e))
def processCommand(self, command, *args):
if self.blocked is not None:
self.blocked.append((command, args))
return
command = string.upper(command)
authCmd = command in self.AUTH_CMDS
if not self.mbox and not authCmd:
raise POP3Error("not authenticated yet: cannot do " + command)
f = getattr(self, 'do_' + command, None)
if f:
return f(*args)
raise POP3Error("Unknown protocol command: " + command)
def listCapabilities(self):
baseCaps = [
"TOP",
"USER",
"UIDL",
"PIPELINE",
"CELERITY",
"AUSPEX",
"POTENCE",
]
if IServerFactory.providedBy(self.factory):
# Oh my god. We can't just loop over a list of these because
# each has spectacularly different return value semantics!
try:
v = self.factory.cap_IMPLEMENTATION()
except NotImplementedError:
pass
except:
log.err()
else:
baseCaps.append("IMPLEMENTATION " + str(v))
try:
v = self.factory.cap_EXPIRE()
except NotImplementedError:
pass
except:
log.err()
else:
if v is None:
v = "NEVER"
if self.factory.perUserExpiration():
if self.mbox:
v = str(self.mbox.messageExpiration)
else:
v = str(v) + " USER"
v = str(v)
baseCaps.append("EXPIRE " + v)
try:
v = self.factory.cap_LOGIN_DELAY()
except NotImplementedError:
pass
except:
log.err()
else:
if self.factory.perUserLoginDelay():
if self.mbox:
v = str(self.mbox.loginDelay)
else:
v = str(v) + " USER"
v = str(v)
baseCaps.append("LOGIN-DELAY " + v)
try:
v = self.factory.challengers
except AttributeError:
pass
except:
log.err()
else:
baseCaps.append("SASL " + ' '.join(v.keys()))
return baseCaps
def do_CAPA(self):
self.successResponse("I can do the following:")
for cap in self.listCapabilities():
self.sendLine(cap)
self.sendLine(".")
def do_AUTH(self, args=None):
if not getattr(self.factory, 'challengers', None):
self.failResponse("AUTH extension unsupported")
return
if args is None:
self.successResponse("Supported authentication methods:")
for a in self.factory.challengers:
self.sendLine(a.upper())
self.sendLine(".")
return
auth = self.factory.challengers.get(args.strip().upper())
if not self.portal or not auth:
self.failResponse("Unsupported SASL selected")
return
self._auth = auth()
chal = self._auth.getChallenge()
self.sendLine('+ ' + base64.encodestring(chal).rstrip('\n'))
self.state = 'AUTH'
def state_AUTH(self, line):
self.state = "COMMAND"
try:
parts = base64.decodestring(line).split(None, 1)
except binascii.Error:
self.failResponse("Invalid BASE64 encoding")
else:
if len(parts) != 2:
self.failResponse("Invalid AUTH response")
return
self._auth.username = parts[0]
self._auth.response = parts[1]
d = self.portal.login(self._auth, None, IMailbox)
d.addCallback(self._cbMailbox, parts[0])
d.addErrback(self._ebMailbox)
d.addErrback(self._ebUnexpected)
def do_APOP(self, user, digest):
d = defer.maybeDeferred(self.authenticateUserAPOP, user, digest)
d.addCallbacks(self._cbMailbox, self._ebMailbox, callbackArgs=(user,)
).addErrback(self._ebUnexpected)
def _cbMailbox(self, (interface, avatar, logout), user):
if interface is not IMailbox:
self.failResponse('Authentication failed')
log.err("_cbMailbox() called with an interface other than IMailbox")
return
self.mbox = avatar
self._onLogout = logout
self.successResponse('Authentication succeeded')
if getattr(self.factory, 'noisy', True):
log.msg("Authenticated login for " + user)
def _ebMailbox(self, failure):
failure = failure.trap(cred.error.LoginDenied, cred.error.LoginFailed)
if issubclass(failure, cred.error.LoginDenied):
self.failResponse("Access denied: " + str(failure))
elif issubclass(failure, cred.error.LoginFailed):
self.failResponse('Authentication failed')
if getattr(self.factory, 'noisy', True):
log.msg("Denied login attempt from " + str(self.transport.getPeer()))
def _ebUnexpected(self, failure):
self.failResponse('Server error: ' + failure.getErrorMessage())
log.err(failure)
def do_USER(self, user):
self._userIs = user
self.successResponse('USER accepted, send PASS')
def do_PASS(self, password):
if self._userIs is None:
self.failResponse("USER required before PASS")
return
user = self._userIs
self._userIs = None
d = defer.maybeDeferred(self.authenticateUserPASS, user, password)
d.addCallbacks(self._cbMailbox, self._ebMailbox, callbackArgs=(user,)
).addErrback(self._ebUnexpected)
def _longOperation(self, d):
# Turn off timeouts and block further processing until the Deferred
# fires, then reverse those changes.
timeOut = self.timeOut
self.setTimeout(None)
self.blocked = []
d.addCallback(self._unblock)
d.addCallback(lambda ign: self.setTimeout(timeOut))
return d
def _coiterate(self, gen):
return self.schedule(_IteratorBuffer(self.transport.writeSequence, gen))
def do_STAT(self):
d = defer.maybeDeferred(self.mbox.listMessages)
def cbMessages(msgs):
return self._coiterate(formatStatResponse(msgs))
def ebMessages(err):
self.failResponse(err.getErrorMessage())
log.msg("Unexpected do_STAT failure:")
log.err(err)
return self._longOperation(d.addCallbacks(cbMessages, ebMessages))
def do_LIST(self, i=None):
if i is None:
d = defer.maybeDeferred(self.mbox.listMessages)
def cbMessages(msgs):
return self._coiterate(formatListResponse(msgs))
def ebMessages(err):
self.failResponse(err.getErrorMessage())
log.msg("Unexpected do_LIST failure:")
log.err(err)
return self._longOperation(d.addCallbacks(cbMessages, ebMessages))
else:
try:
i = int(i)
if i < 1:
raise ValueError()
except ValueError:
self.failResponse("Invalid message-number: %r" % (i,))
else:
d = defer.maybeDeferred(self.mbox.listMessages, i - 1)
def cbMessage(msg):
self.successResponse('%d %d' % (i, msg))
def ebMessage(err):
errcls = err.check(ValueError, IndexError)
if errcls is not None:
if errcls is IndexError:
# IndexError was supported for a while, but really
# shouldn't be. One error condition, one exception
# type.
warnings.warn(
"twisted.mail.pop3.IMailbox.listMessages may not "
"raise IndexError for out-of-bounds message numbers: "
"raise ValueError instead.",
PendingDeprecationWarning)
self.failResponse("Invalid message-number: %r" % (i,))
else:
self.failResponse(err.getErrorMessage())
log.msg("Unexpected do_LIST failure:")
log.err(err)
return self._longOperation(d.addCallbacks(cbMessage, ebMessage))
def do_UIDL(self, i=None):
if i is None:
d = defer.maybeDeferred(self.mbox.listMessages)
def cbMessages(msgs):
return self._coiterate(formatUIDListResponse(msgs, self.mbox.getUidl))
def ebMessages(err):
self.failResponse(err.getErrorMessage())
log.msg("Unexpected do_UIDL failure:")
log.err(err)
return self._longOperation(d.addCallbacks(cbMessages, ebMessages))
else:
try:
i = int(i)
if i < 1:
raise ValueError()
except ValueError:
self.failResponse("Bad message number argument")
else:
try:
msg = self.mbox.getUidl(i - 1)
except IndexError:
# XXX TODO See above comment regarding IndexError.
warnings.warn(
"twisted.mail.pop3.IMailbox.getUidl may not "
"raise IndexError for out-of-bounds message numbers: "
"raise ValueError instead.",
PendingDeprecationWarning)
self.failResponse("Bad message number argument")
except ValueError:
self.failResponse("Bad message number argument")
else:
self.successResponse(str(msg))
def _getMessageFile(self, i):
"""
Retrieve the size and contents of a given message, as a two-tuple.
@param i: The number of the message to operate on. This is a base-ten
string representation starting at 1.
@return: A Deferred which fires with a two-tuple of an integer and a
file-like object.
"""
try:
msg = int(i) - 1
if msg < 0:
raise ValueError()
except ValueError:
self.failResponse("Bad message number argument")
return defer.succeed(None)
sizeDeferred = defer.maybeDeferred(self.mbox.listMessages, msg)
def cbMessageSize(size):
if not size:
return defer.fail(_POP3MessageDeleted())
fileDeferred = defer.maybeDeferred(self.mbox.getMessage, msg)
fileDeferred.addCallback(lambda fObj: (size, fObj))
return fileDeferred
def ebMessageSomething(err):
errcls = err.check(_POP3MessageDeleted, ValueError, IndexError)
if errcls is _POP3MessageDeleted:
self.failResponse("message deleted")
elif errcls in (ValueError, IndexError):
if errcls is IndexError:
# XXX TODO See above comment regarding IndexError.
warnings.warn(
"twisted.mail.pop3.IMailbox.listMessages may not "
"raise IndexError for out-of-bounds message numbers: "
"raise ValueError instead.",
PendingDeprecationWarning)
self.failResponse("Bad message number argument")
else:
log.msg("Unexpected _getMessageFile failure:")
log.err(err)
return None
sizeDeferred.addCallback(cbMessageSize)
sizeDeferred.addErrback(ebMessageSomething)
return sizeDeferred
def _sendMessageContent(self, i, fpWrapper, successResponse):
d = self._getMessageFile(i)
def cbMessageFile(info):
if info is None:
# Some error occurred - a failure response has been sent
# already, just give up.
return
self._highest = max(self._highest, int(i))
resp, fp = info
fp = fpWrapper(fp)
self.successResponse(successResponse(resp))
s = basic.FileSender()
d = s.beginFileTransfer(fp, self.transport, self.transformChunk)
def cbFileTransfer(lastsent):
if lastsent != '\n':
line = '\r\n.'
else:
line = '.'
self.sendLine(line)
def ebFileTransfer(err):
self.transport.loseConnection()
log.msg("Unexpected error in _sendMessageContent:")
log.err(err)
d.addCallback(cbFileTransfer)
d.addErrback(ebFileTransfer)
return d
return self._longOperation(d.addCallback(cbMessageFile))
def do_TOP(self, i, size):
try:
size = int(size)
if size < 0:
raise ValueError
except ValueError:
self.failResponse("Bad line count argument")
else:
return self._sendMessageContent(
i,
lambda fp: _HeadersPlusNLines(fp, size),
lambda size: "Top of message follows")
def do_RETR(self, i):
return self._sendMessageContent(
i,
lambda fp: fp,
lambda size: "%d" % (size,))
def transformChunk(self, chunk):
return chunk.replace('\n', '\r\n').replace('\r\n.', '\r\n..')
def finishedFileTransfer(self, lastsent):
if lastsent != '\n':
line = '\r\n.'
else:
line = '.'
self.sendLine(line)
def do_DELE(self, i):
i = int(i)-1
self.mbox.deleteMessage(i)
self.successResponse()
def do_NOOP(self):
"""Perform no operation. Return a success code"""
self.successResponse()
def do_RSET(self):
"""Unset all deleted message flags"""
try:
self.mbox.undeleteMessages()
except:
log.err()
self.failResponse()
else:
self._highest = 0
self.successResponse()
def do_LAST(self):
"""
Return the index of the highest message yet downloaded.
"""
self.successResponse(self._highest)
def do_RPOP(self, user):
self.failResponse('permission denied, sucker')
def do_QUIT(self):
if self.mbox:
self.mbox.sync()
self.successResponse()
self.transport.loseConnection()
def authenticateUserAPOP(self, user, digest):
"""Perform authentication of an APOP login.
@type user: C{str}
@param user: The name of the user attempting to log in.
@type digest: C{str}
@param digest: The response string with which the user replied.
@rtype: C{Deferred}
@return: A deferred whose callback is invoked if the login is
successful, and whose errback will be invoked otherwise. The
callback will be passed a 3-tuple consisting of IMailbox,
an object implementing IMailbox, and a zero-argument callable
to be invoked when this session is terminated.
"""
if self.portal is not None:
return self.portal.login(
APOPCredentials(self.magic, user, digest),
None,
IMailbox
)
raise cred.error.UnauthorizedLogin()
def authenticateUserPASS(self, user, password):
"""Perform authentication of a username/password login.
@type user: C{str}
@param user: The name of the user attempting to log in.
@type password: C{str}
@param password: The password to attempt to authenticate with.
@rtype: C{Deferred}
@return: A deferred whose callback is invoked if the login is
successful, and whose errback will be invoked otherwise. The
callback will be passed a 3-tuple consisting of IMailbox,
an object implementing IMailbox, and a zero-argument callable
to be invoked when this session is terminated.
"""
if self.portal is not None:
return self.portal.login(
cred.credentials.UsernamePassword(user, password),
None,
IMailbox
)
raise cred.error.UnauthorizedLogin()
class IServerFactory(Interface):
"""Interface for querying additional parameters of this POP3 server.
Any cap_* method may raise NotImplementedError if the particular
capability is not supported. If cap_EXPIRE() does not raise
NotImplementedError, perUserExpiration() must be implemented, otherwise
they are optional. If cap_LOGIN_DELAY() is implemented,
perUserLoginDelay() must be implemented, otherwise they are optional.
@ivar challengers: A dictionary mapping challenger names to classes
implementing C{IUsernameHashedPassword}.
"""
def cap_IMPLEMENTATION():
"""Return a string describing this POP3 server implementation."""
def cap_EXPIRE():
"""Return the minimum number of days messages are retained."""
def perUserExpiration():
"""Indicate whether message expiration is per-user.
@return: True if it is, false otherwise.
"""
def cap_LOGIN_DELAY():
"""Return the minimum number of seconds between client logins."""
def perUserLoginDelay():
"""Indicate whether the login delay period is per-user.
@return: True if it is, false otherwise.
"""
class IMailbox(Interface):
"""
@type loginDelay: C{int}
@ivar loginDelay: The number of seconds between allowed logins for the
user associated with this mailbox. None
@type messageExpiration: C{int}
@ivar messageExpiration: The number of days messages in this mailbox will
remain on the server before being deleted.
"""
def listMessages(index=None):
"""Retrieve the size of one or more messages.
@type index: C{int} or C{None}
@param index: The number of the message for which to retrieve the
size (starting at 0), or None to retrieve the size of all messages.
@rtype: C{int} or any iterable of C{int} or a L{Deferred} which fires
with one of these.
@return: The number of octets in the specified message, or an iterable
of integers representing the number of octets in all the messages. Any
value which would have referred to a deleted message should be set to 0.
@raise ValueError: if C{index} is greater than the index of any message
in the mailbox.
"""
def getMessage(index):
"""Retrieve a file-like object for a particular message.
@type index: C{int}
@param index: The number of the message to retrieve
@rtype: A file-like object
@return: A file containing the message data with lines delimited by
C{\\n}.
"""
def getUidl(index):
"""Get a unique identifier for a particular message.
@type index: C{int}
@param index: The number of the message for which to retrieve a UIDL
@rtype: C{str}
@return: A string of printable characters uniquely identifying for all
time the specified message.
@raise ValueError: if C{index} is greater than the index of any message
in the mailbox.
"""
def deleteMessage(index):
"""Delete a particular message.
This must not change the number of messages in this mailbox. Further
requests for the size of deleted messages should return 0. Further
requests for the message itself may raise an exception.
@type index: C{int}
@param index: The number of the message to delete.
"""
def undeleteMessages():
"""
Undelete any messages which have been marked for deletion since the
most recent L{sync} call.
Any message which can be undeleted should be returned to its
original position in the message sequence and retain its original
UID.
"""
def sync():
"""Perform checkpointing.
This method will be called to indicate the mailbox should attempt to
clean up any remaining deleted messages.
"""
class Mailbox:
implements(IMailbox)
def listMessages(self, i=None):
return []
def getMessage(self, i):
raise ValueError
def getUidl(self, i):
raise ValueError
def deleteMessage(self, i):
raise ValueError
def undeleteMessages(self):
pass
def sync(self):
pass
NONE, SHORT, FIRST_LONG, LONG = range(4)
NEXT = {}
NEXT[NONE] = NONE
NEXT[SHORT] = NONE
NEXT[FIRST_LONG] = LONG
NEXT[LONG] = NONE
class POP3Client(basic.LineOnlyReceiver):
mode = SHORT
command = 'WELCOME'
import re
welcomeRe = re.compile('<(.*)>')
def __init__(self):
import warnings
warnings.warn("twisted.mail.pop3.POP3Client is deprecated, "
"please use twisted.mail.pop3.AdvancedPOP3Client "
"instead.", DeprecationWarning,
stacklevel=3)
def sendShort(self, command, params=None):
if params is not None:
self.sendLine('%s %s' % (command, params))
else:
self.sendLine(command)
self.command = command
self.mode = SHORT
def sendLong(self, command, params):
if params:
self.sendLine('%s %s' % (command, params))
else:
self.sendLine(command)
self.command = command
self.mode = FIRST_LONG
def handle_default(self, line):
if line[:-4] == '-ERR':
self.mode = NONE
def handle_WELCOME(self, line):
code, data = line.split(' ', 1)
if code != '+OK':
self.transport.loseConnection()
else:
m = self.welcomeRe.match(line)
if m:
self.welcomeCode = m.group(1)
def _dispatch(self, command, default, *args):
try:
method = getattr(self, 'handle_'+command, default)
if method is not None:
method(*args)
except:
log.err()
def lineReceived(self, line):
if self.mode == SHORT or self.mode == FIRST_LONG:
self.mode = NEXT[self.mode]
self._dispatch(self.command, self.handle_default, line)
elif self.mode == LONG:
if line == '.':
self.mode = NEXT[self.mode]
self._dispatch(self.command+'_end', None)
return
if line[:1] == '.':
line = line[1:]
self._dispatch(self.command+"_continue", None, line)
def apopAuthenticate(self, user, password, magic):
digest = md5(magic + password).hexdigest()
self.apop(user, digest)
def apop(self, user, digest):
self.sendLong('APOP', ' '.join((user, digest)))
def retr(self, i):
self.sendLong('RETR', i)
def dele(self, i):
self.sendShort('DELE', i)
def list(self, i=''):
self.sendLong('LIST', i)
def uidl(self, i=''):
self.sendLong('UIDL', i)
def user(self, name):
self.sendShort('USER', name)
def pass_(self, pass_):
self.sendShort('PASS', pass_)
def quit(self):
self.sendShort('QUIT')
from twisted.mail.pop3client import POP3Client as AdvancedPOP3Client
from twisted.mail.pop3client import POP3ClientError
from twisted.mail.pop3client import InsecureAuthenticationDisallowed
from twisted.mail.pop3client import ServerErrorResponse
from twisted.mail.pop3client import LineTooLong
__all__ = [
# Interfaces
'IMailbox', 'IServerFactory',
# Exceptions
'POP3Error', 'POP3ClientError', 'InsecureAuthenticationDisallowed',
'ServerErrorResponse', 'LineTooLong',
# Protocol classes
'POP3', 'POP3Client', 'AdvancedPOP3Client',
# Misc
'APOPCredentials', 'Mailbox']
|
agpl-3.0
|
[
3,
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
1198,
14,
396,
14,
396,
63,
1935,
19,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
199,
6564,
13,
18812,
11557,
1015,
650,
199,
199,
32,
2502,
26,
598,
7234,
491,
2829,
75,
583,
23751,
199,
32,
2502,
26,
1603,
80,
8256,
424,
368,
199,
624,
199,
199,
646,
1059,
199,
646,
1300,
772,
199,
646,
14755,
199,
646,
3598,
199,
199,
504,
20110,
14,
3266,
492,
9031,
12,
14816,
199,
199,
504,
7390,
14,
1198,
492,
14400,
199,
504,
7390,
14,
16541,
492,
5678,
199,
504,
7390,
14,
16541,
492,
14118,
199,
504,
7390,
14,
4901,
492,
2120,
199,
504,
7390,
14,
4901,
492,
10133,
199,
504,
7390,
14,
4901,
492,
8386,
199,
504,
7390,
14,
1548,
492,
943,
199,
504,
7390,
14,
1548,
14,
24722,
492,
6128,
21,
199,
199,
504,
7390,
492,
22314,
199,
646,
7390,
14,
18639,
14,
705,
199,
646,
7390,
14,
18639,
14,
6942,
199,
199,
309,
199,
309,
15995,
199,
309,
199,
533,
437,
1512,
4222,
264,
3802,
26,
272,
9031,
8,
18639,
14,
6942,
14,
41,
13355,
6139,
9,
339,
347,
636,
826,
721,
277,
12,
10628,
12,
3434,
12,
10017,
304,
267,
291,
14,
11523,
275,
10628,
267,
291,
14,
2473,
275,
3434,
267,
291,
14,
5671,
275,
10017,
339,
347,
1104,
6139,
8,
277,
12,
2505,
304,
267,
6347,
275,
291,
14,
11523,
435,
2505,
267,
3002,
18541,
275,
6128,
21,
8,
5176,
680,
11453,
342,
267,
372,
3002,
18541,
508,
291,
14,
5671,
421,
199,
533,
485,
9883,
25800,
46,
9863,
26,
272,
347,
636,
826,
721,
277,
12,
289,
12,
302,
304,
267,
291,
14,
70,
275,
289,
267,
291,
14,
78,
275,
302,
267,
291,
14,
604,
835,
275,
378,
267,
291,
14,
2139,
275,
413,
267,
291,
14,
4456,
275,
378,
267,
291,
14,
1436,
275,
2125,
339,
347,
1586,
8,
277,
12,
2783,
304,
267,
340,
291,
14,
4456,
26,
288,
372,
2125,
267,
666,
275,
291,
14,
70,
14,
739,
8,
2394,
9,
267,
340,
440,
666,
26,
288,
372,
666,
267,
340,
291,
14,
2139,
26,
288,
4051,
12,
17176,
275,
666,
14,
1623,
2258,
82,
60,
78,
60,
82,
60,
78,
659,
841,
288,
340,
4051,
508,
446,
17,
26,
355,
4051,
12,
17176,
275,
666,
14,
1623,
2258,
78,
60,
78,
659,
499,
288,
340,
4051,
1137,
446,
17,
26,
355,
4051,
847,
17176,
355,
1139,
275,
666,
1491,
1587,
61,
355,
666,
275,
666,
59,
1587,
2938,
355,
291,
14,
604,
835,
275,
413,
355,
291,
14,
2139,
275,
378,
267,
587,
26,
288,
1139,
275,
2125,
267,
340,
291,
14,
604,
835,
690,
378,
26,
288,
366,
1294,
275,
334,
277,
14,
1436,
11,
576,
680,
1294,
2258,
78,
358,
288,
291,
14,
1436,
275,
366,
1294,
1988,
17,
61,
288,
367,
10359,
315,
366,
1294,
4439,
17,
2189,
355,
340,
291,
14,
604,
835,
690,
291,
14,
78,
26,
490,
291,
14,
4456,
275,
413,
490,
372,
1139,
355,
1139,
847,
334,
6066,
435,
1557,
78,
358,
355,
291,
14,
604,
835,
847,
413,
288,
372,
1139,
267,
587,
26,
288,
372,
666,
4388,
199,
533,
485,
13531,
19,
2209,
17735,
8,
1726,
304,
272,
408,
272,
12624,
3304,
13,
1659,
1919,
14,
221,
19334,
314,
570,
402,
282,
5463,
1245,
272,
1990,
5839,
14,
272,
408,
421,
199,
533,
510,
1938,
19,
547,
8,
1726,
304,
272,
986,
4388,
199,
533,
485,
3585,
3299,
8,
785,
304,
272,
4123,
2320,
275,
378,
339,
347,
636,
826,
721,
277,
12,
2218,
12,
6076,
12,
4402,
3299,
2320,
29,
403,
304,
267,
408,
267,
2790,
282,
485,
3585,
3299,
14,
398,
768,
635,
2218,
26,
437,
1373,
13,
2094,
4550,
1314,
911,
506,
10302,
543,
282,
769,
267,
402,
3326,
1314,
1172,
2757,
20224,
14,
398,
768,
635,
6076,
26,
710,
1350,
402,
1324,
3326,
465,
1263,
6076,
14,
398,
768,
635,
4402,
3299,
2320,
26,
710,
7008,
2304,
641,
20224,
1059,
2582,
12,
267,
20561,
1314,
314,
3335,
911,
506,
8976,
379,
370,
314,
7060,
14,
267,
408,
267,
291,
14,
1278,
275,
942,
267,
291,
14,
952,
275,
2218,
267,
291,
14,
5778,
275,
2740,
8,
8147,
9,
267,
340,
4402,
3299,
2320,
365,
488,
26,
288,
4402,
3299,
2320,
275,
499,
1011,
3193,
267,
291,
14,
4844,
3299,
2320,
275,
4402,
3299,
2320,
2378,
347,
636,
1661,
721,
277,
304,
267,
372,
291,
2378,
347,
2163,
8,
277,
304,
267,
862,
26,
288,
373,
275,
291,
14,
5778,
14,
2184,
342,
267,
871,
10852,
26,
288,
340,
291,
14,
1278,
26,
355,
291,
14,
952,
8,
277,
14,
1278,
9,
288,
327,
18110,
2005,
6941,
12,
315,
1930,
2985,
3984,
8207,
315,
282,
8643,
14,
288,
2150,
291,
14,
5778,
12,
291,
14,
1278,
12,
291,
14,
952,
288,
746,
267,
587,
26,
288,
340,
373,
365,
440,
488,
26,
355,
291,
14,
1278,
14,
740,
8,
86,
9,
355,
291,
14,
1436,
2320,
847,
822,
8,
86,
9,
355,
340,
291,
14,
1436,
2320,
690,
291,
14,
4844,
3299,
2320,
26,
490,
291,
14,
952,
8,
277,
14,
1278,
9,
490,
291,
14,
1278,
275,
942,
490,
291,
14,
1436,
2320,
275,
378,
4388,
199,
318,
13974,
3049,
7599,
8,
2625,
12,
3805,
304,
272,
408,
272,
24837,
314,
1627,
4113,
1256,
1536,
370,
314,
1627,
6122,
543,
376,
272,
485,
3585,
3299,
436,
8732,
314,
754,
370,
506,
31103,
4799,
314,
4113,
14,
339,
768,
466,
4104,
26,
491,
91,
13531,
19,
93,
272,
768,
466,
3805,
26,
6122,
272,
768,
4500,
26,
491,
91,
12145,
14,
4901,
14,
11610,
14,
9937,
93,
272,
408,
272,
23721,
275,
485,
3585,
3299,
8,
2625,
14,
5545,
14,
952,
5826,
12,
3805,
9,
272,
372,
4104,
14,
7211,
8,
15772,
9,
4388,
199,
318,
3182,
2364,
8,
1310,
304,
272,
408,
272,
9701,
314,
1627,
909,
465,
282,
7317,
1177,
14,
272,
408,
272,
1177,
275,
620,
8,
1310,
9,
272,
372,
6681,
3593,
450,
83,
60,
82,
60,
78,
7,
450,
334,
1310,
4258
] |
[
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
1198,
14,
396,
14,
396,
63,
1935,
19,
1882,
199,
3,
199,
3,
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
421,
199,
624,
199,
6564,
13,
18812,
11557,
1015,
650,
199,
199,
32,
2502,
26,
598,
7234,
491,
2829,
75,
583,
23751,
199,
32,
2502,
26,
1603,
80,
8256,
424,
368,
199,
624,
199,
199,
646,
1059,
199,
646,
1300,
772,
199,
646,
14755,
199,
646,
3598,
199,
199,
504,
20110,
14,
3266,
492,
9031,
12,
14816,
199,
199,
504,
7390,
14,
1198,
492,
14400,
199,
504,
7390,
14,
16541,
492,
5678,
199,
504,
7390,
14,
16541,
492,
14118,
199,
504,
7390,
14,
4901,
492,
2120,
199,
504,
7390,
14,
4901,
492,
10133,
199,
504,
7390,
14,
4901,
492,
8386,
199,
504,
7390,
14,
1548,
492,
943,
199,
504,
7390,
14,
1548,
14,
24722,
492,
6128,
21,
199,
199,
504,
7390,
492,
22314,
199,
646,
7390,
14,
18639,
14,
705,
199,
646,
7390,
14,
18639,
14,
6942,
199,
199,
309,
199,
309,
15995,
199,
309,
199,
533,
437,
1512,
4222,
264,
3802,
26,
272,
9031,
8,
18639,
14,
6942,
14,
41,
13355,
6139,
9,
339,
347,
636,
826,
721,
277,
12,
10628,
12,
3434,
12,
10017,
304,
267,
291,
14,
11523,
275,
10628,
267,
291,
14,
2473,
275,
3434,
267,
291,
14,
5671,
275,
10017,
339,
347,
1104,
6139,
8,
277,
12,
2505,
304,
267,
6347,
275,
291,
14,
11523,
435,
2505,
267,
3002,
18541,
275,
6128,
21,
8,
5176,
680,
11453,
342,
267,
372,
3002,
18541,
508,
291,
14,
5671,
421,
199,
533,
485,
9883,
25800,
46,
9863,
26,
272,
347,
636,
826,
721,
277,
12,
289,
12,
302,
304,
267,
291,
14,
70,
275,
289,
267,
291,
14,
78,
275,
302,
267,
291,
14,
604,
835,
275,
378,
267,
291,
14,
2139,
275,
413,
267,
291,
14,
4456,
275,
378,
267,
291,
14,
1436,
275,
2125,
339,
347,
1586,
8,
277,
12,
2783,
304,
267,
340,
291,
14,
4456,
26,
288,
372,
2125,
267,
666,
275,
291,
14,
70,
14,
739,
8,
2394,
9,
267,
340,
440,
666,
26,
288,
372,
666,
267,
340,
291,
14,
2139,
26,
288,
4051,
12,
17176,
275,
666,
14,
1623,
2258,
82,
60,
78,
60,
82,
60,
78,
659,
841,
288,
340,
4051,
508,
446,
17,
26,
355,
4051,
12,
17176,
275,
666,
14,
1623,
2258,
78,
60,
78,
659,
499,
288,
340,
4051,
1137,
446,
17,
26,
355,
4051,
847,
17176,
355,
1139,
275,
666,
1491,
1587,
61,
355,
666,
275,
666,
59,
1587,
2938,
355,
291,
14,
604,
835,
275,
413,
355,
291,
14,
2139,
275,
378,
267,
587,
26,
288,
1139,
275,
2125,
267,
340,
291,
14,
604,
835,
690,
378,
26,
288,
366,
1294,
275,
334,
277,
14,
1436,
11,
576,
680,
1294,
2258,
78,
358,
288,
291,
14,
1436,
275,
366,
1294,
1988,
17,
61,
288,
367,
10359,
315,
366,
1294,
4439,
17,
2189,
355,
340,
291,
14,
604,
835,
690,
291,
14,
78,
26,
490,
291,
14,
4456,
275,
413,
490,
372,
1139,
355,
1139,
847,
334,
6066,
435,
1557,
78,
358,
355,
291,
14,
604,
835,
847,
413,
288,
372,
1139,
267,
587,
26,
288,
372,
666,
4388,
199,
533,
485,
13531,
19,
2209,
17735,
8,
1726,
304,
272,
408,
272,
12624,
3304,
13,
1659,
1919,
14,
221,
19334,
314,
570,
402,
282,
5463,
1245,
272,
1990,
5839,
14,
272,
408,
421,
199,
533,
510,
1938,
19,
547,
8,
1726,
304,
272,
986,
4388,
199,
533,
485,
3585,
3299,
8,
785,
304,
272,
4123,
2320,
275,
378,
339,
347,
636,
826,
721,
277,
12,
2218,
12,
6076,
12,
4402,
3299,
2320,
29,
403,
304,
267,
408,
267,
2790,
282,
485,
3585,
3299,
14,
398,
768,
635,
2218,
26,
437,
1373,
13,
2094,
4550,
1314,
911,
506,
10302,
543,
282,
769,
267,
402,
3326,
1314,
1172,
2757,
20224,
14,
398,
768,
635,
6076,
26,
710,
1350,
402,
1324,
3326,
465,
1263,
6076,
14,
398,
768,
635,
4402,
3299,
2320,
26,
710,
7008,
2304,
641,
20224,
1059,
2582,
12,
267,
20561,
1314,
314,
3335,
911,
506,
8976,
379,
370,
314,
7060,
14,
267,
408,
267,
291,
14,
1278,
275,
942,
267,
291,
14,
952,
275,
2218,
267,
291,
14,
5778,
275,
2740,
8,
8147,
9,
267,
340,
4402,
3299,
2320,
365,
488,
26,
288,
4402,
3299,
2320,
275,
499,
1011,
3193,
267,
291,
14,
4844,
3299,
2320,
275,
4402,
3299,
2320,
2378,
347,
636,
1661,
721,
277,
304,
267,
372,
291,
2378,
347,
2163,
8,
277,
304,
267,
862,
26,
288,
373,
275,
291,
14,
5778,
14,
2184,
342,
267,
871,
10852,
26,
288,
340,
291,
14,
1278,
26,
355,
291,
14,
952,
8,
277,
14,
1278,
9,
288,
327,
18110,
2005,
6941,
12,
315,
1930,
2985,
3984,
8207,
315,
282,
8643,
14,
288,
2150,
291,
14,
5778,
12,
291,
14,
1278,
12,
291,
14,
952,
288,
746,
267,
587,
26,
288,
340,
373,
365,
440,
488,
26,
355,
291,
14,
1278,
14,
740,
8,
86,
9,
355,
291,
14,
1436,
2320,
847,
822,
8,
86,
9,
355,
340,
291,
14,
1436,
2320,
690,
291,
14,
4844,
3299,
2320,
26,
490,
291,
14,
952,
8,
277,
14,
1278,
9,
490,
291,
14,
1278,
275,
942,
490,
291,
14,
1436,
2320,
275,
378,
4388,
199,
318,
13974,
3049,
7599,
8,
2625,
12,
3805,
304,
272,
408,
272,
24837,
314,
1627,
4113,
1256,
1536,
370,
314,
1627,
6122,
543,
376,
272,
485,
3585,
3299,
436,
8732,
314,
754,
370,
506,
31103,
4799,
314,
4113,
14,
339,
768,
466,
4104,
26,
491,
91,
13531,
19,
93,
272,
768,
466,
3805,
26,
6122,
272,
768,
4500,
26,
491,
91,
12145,
14,
4901,
14,
11610,
14,
9937,
93,
272,
408,
272,
23721,
275,
485,
3585,
3299,
8,
2625,
14,
5545,
14,
952,
5826,
12,
3805,
9,
272,
372,
4104,
14,
7211,
8,
15772,
9,
4388,
199,
318,
3182,
2364,
8,
1310,
304,
272,
408,
272,
9701,
314,
1627,
909,
465,
282,
7317,
1177,
14,
272,
408,
272,
1177,
275,
620,
8,
1310,
9,
272,
372,
6681,
3593,
450,
83,
60,
82,
60,
78,
7,
450,
334,
1310,
4258,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
supertanglang/shadowsocks
|
shadowsocks/eventloop.py
|
51
|
7513
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright 2013-2015 clowwindy
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# from ssloop
# https://github.com/clowwindy/ssloop
from __future__ import absolute_import, division, print_function, \
with_statement
import os
import socket
import select
import errno
import logging
from collections import defaultdict
from shadowsocks import shell
__all__ = ['EventLoop', 'POLL_NULL', 'POLL_IN', 'POLL_OUT', 'POLL_ERR',
'POLL_HUP', 'POLL_NVAL', 'EVENT_NAMES']
POLL_NULL = 0x00
POLL_IN = 0x01
POLL_OUT = 0x04
POLL_ERR = 0x08
POLL_HUP = 0x10
POLL_NVAL = 0x20
EVENT_NAMES = {
POLL_NULL: 'POLL_NULL',
POLL_IN: 'POLL_IN',
POLL_OUT: 'POLL_OUT',
POLL_ERR: 'POLL_ERR',
POLL_HUP: 'POLL_HUP',
POLL_NVAL: 'POLL_NVAL',
}
class EpollLoop(object):
def __init__(self):
self._epoll = select.epoll()
def poll(self, timeout):
return self._epoll.poll(timeout)
def add_fd(self, fd, mode):
self._epoll.register(fd, mode)
def remove_fd(self, fd):
self._epoll.unregister(fd)
def modify_fd(self, fd, mode):
self._epoll.modify(fd, mode)
class KqueueLoop(object):
MAX_EVENTS = 1024
def __init__(self):
self._kqueue = select.kqueue()
self._fds = {}
def _control(self, fd, mode, flags):
events = []
if mode & POLL_IN:
events.append(select.kevent(fd, select.KQ_FILTER_READ, flags))
if mode & POLL_OUT:
events.append(select.kevent(fd, select.KQ_FILTER_WRITE, flags))
for e in events:
self._kqueue.control([e], 0)
def poll(self, timeout):
if timeout < 0:
timeout = None # kqueue behaviour
events = self._kqueue.control(None, KqueueLoop.MAX_EVENTS, timeout)
results = defaultdict(lambda: POLL_NULL)
for e in events:
fd = e.ident
if e.filter == select.KQ_FILTER_READ:
results[fd] |= POLL_IN
elif e.filter == select.KQ_FILTER_WRITE:
results[fd] |= POLL_OUT
return results.items()
def add_fd(self, fd, mode):
self._fds[fd] = mode
self._control(fd, mode, select.KQ_EV_ADD)
def remove_fd(self, fd):
self._control(fd, self._fds[fd], select.KQ_EV_DELETE)
del self._fds[fd]
def modify_fd(self, fd, mode):
self.remove_fd(fd)
self.add_fd(fd, mode)
class SelectLoop(object):
def __init__(self):
self._r_list = set()
self._w_list = set()
self._x_list = set()
def poll(self, timeout):
r, w, x = select.select(self._r_list, self._w_list, self._x_list,
timeout)
results = defaultdict(lambda: POLL_NULL)
for p in [(r, POLL_IN), (w, POLL_OUT), (x, POLL_ERR)]:
for fd in p[0]:
results[fd] |= p[1]
return results.items()
def add_fd(self, fd, mode):
if mode & POLL_IN:
self._r_list.add(fd)
if mode & POLL_OUT:
self._w_list.add(fd)
if mode & POLL_ERR:
self._x_list.add(fd)
def remove_fd(self, fd):
if fd in self._r_list:
self._r_list.remove(fd)
if fd in self._w_list:
self._w_list.remove(fd)
if fd in self._x_list:
self._x_list.remove(fd)
def modify_fd(self, fd, mode):
self.remove_fd(fd)
self.add_fd(fd, mode)
class EventLoop(object):
def __init__(self):
self._iterating = False
if hasattr(select, 'epoll'):
self._impl = EpollLoop()
model = 'epoll'
elif hasattr(select, 'kqueue'):
self._impl = KqueueLoop()
model = 'kqueue'
elif hasattr(select, 'select'):
self._impl = SelectLoop()
model = 'select'
else:
raise Exception('can not find any available functions in select '
'package')
self._fd_to_f = {}
self._handlers = []
self._ref_handlers = []
self._handlers_to_remove = []
logging.debug('using event model: %s', model)
def poll(self, timeout=None):
events = self._impl.poll(timeout)
return [(self._fd_to_f[fd], fd, event) for fd, event in events]
def add(self, f, mode):
fd = f.fileno()
self._fd_to_f[fd] = f
self._impl.add_fd(fd, mode)
def remove(self, f):
fd = f.fileno()
del self._fd_to_f[fd]
self._impl.remove_fd(fd)
def modify(self, f, mode):
fd = f.fileno()
self._impl.modify_fd(fd, mode)
def add_handler(self, handler, ref=True):
self._handlers.append(handler)
if ref:
# when all ref handlers are removed, loop stops
self._ref_handlers.append(handler)
def remove_handler(self, handler):
if handler in self._ref_handlers:
self._ref_handlers.remove(handler)
if self._iterating:
self._handlers_to_remove.append(handler)
else:
self._handlers.remove(handler)
def run(self):
events = []
while self._ref_handlers:
try:
events = self.poll(1)
except (OSError, IOError) as e:
if errno_from_exception(e) in (errno.EPIPE, errno.EINTR):
# EPIPE: Happens when the client closes the connection
# EINTR: Happens when received a signal
# handles them as soon as possible
logging.debug('poll:%s', e)
else:
logging.error('poll:%s', e)
import traceback
traceback.print_exc()
continue
self._iterating = True
for handler in self._handlers:
# TODO when there are a lot of handlers
try:
handler(events)
except (OSError, IOError) as e:
shell.print_exception(e)
if self._handlers_to_remove:
for handler in self._handlers_to_remove:
self._handlers.remove(handler)
self._handlers_to_remove = []
self._iterating = False
# from tornado
def errno_from_exception(e):
"""Provides the errno from an Exception object.
There are cases that the errno attribute was not set so we pull
the errno out of the args but if someone instatiates an Exception
without any args you will get a tuple error. So this function
abstracts all that behavior to give you a safe way to get the
errno.
"""
if hasattr(e, 'errno'):
return e.errno
elif e.args:
return e.args[0]
else:
return None
# from tornado
def get_sock_error(sock):
error_number = sock.getsockopt(socket.SOL_SOCKET, socket.SO_ERROR)
return socket.error(error_number, os.strerror(error_number))
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6171,
13,
7806,
286,
674,
11530,
89,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
3,
687,
10110,
3813,
199,
3,
4178,
921,
5031,
14,
957,
15,
67,
674,
11530,
89,
15,
385,
3813,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
971,
272,
543,
63,
6242,
199,
199,
646,
747,
199,
646,
2838,
199,
646,
3504,
199,
646,
7554,
199,
646,
2050,
199,
504,
5055,
492,
10018,
199,
199,
504,
15084,
21234,
492,
5218,
421,
199,
363,
452,
363,
275,
788,
2390,
7382,
297,
283,
16428,
63,
8084,
297,
283,
16428,
63,
568,
297,
283,
16428,
63,
1877,
297,
283,
16428,
63,
2666,
297,
1779,
283,
16428,
63,
40,
2160,
297,
283,
16428,
63,
46,
3204,
297,
283,
8193,
63,
14546,
418,
199,
199,
16428,
63,
8084,
275,
378,
88,
383,
199,
16428,
63,
568,
275,
378,
88,
614,
199,
16428,
63,
1877,
275,
378,
88,
966,
199,
16428,
63,
2666,
275,
378,
88,
2036,
199,
16428,
63,
40,
2160,
275,
378,
88,
709,
199,
16428,
63,
46,
3204,
275,
378,
88,
1165,
421,
199,
8193,
63,
14546,
275,
469,
272,
25480,
44,
63,
8084,
26,
283,
16428,
63,
8084,
297,
272,
25480,
44,
63,
568,
26,
283,
16428,
63,
568,
297,
272,
25480,
44,
63,
1877,
26,
283,
16428,
63,
1877,
297,
272,
25480,
44,
63,
2666,
26,
283,
16428,
63,
2666,
297,
272,
25480,
44,
63,
40,
2160,
26,
283,
16428,
63,
40,
2160,
297,
272,
25480,
44,
63,
46,
3204,
26,
283,
16428,
63,
46,
3204,
297,
199,
93,
421,
199,
533,
662,
6843,
7382,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1545,
14385,
275,
3504,
14,
1545,
14385,
342,
339,
347,
11271,
8,
277,
12,
2653,
304,
267,
372,
291,
423,
1545,
14385,
14,
6843,
8,
2593,
9,
339,
347,
1050,
63,
2592,
8,
277,
12,
6111,
12,
818,
304,
267,
291,
423,
1545,
14385,
14,
2683,
8,
2592,
12,
818,
9,
339,
347,
2813,
63,
2592,
8,
277,
12,
6111,
304,
267,
291,
423,
1545,
14385,
14,
18408,
8,
2592,
9,
339,
347,
2811,
63,
2592,
8,
277,
12,
6111,
12,
818,
304,
267,
291,
423,
1545,
14385,
14,
8951,
8,
2592,
12,
818,
9,
421,
199,
533,
1804,
1825,
7382,
8,
785,
304,
339,
9141,
63,
8193,
51,
275,
6619,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
75,
1825,
275,
3504,
14,
75,
1825,
342,
267,
291,
423,
14240,
275,
1052,
339,
347,
485,
2785,
8,
277,
12,
6111,
12,
818,
12,
3285,
304,
267,
4474,
275,
942,
267,
340,
818,
1253,
25480,
44,
63,
568,
26,
288,
4474,
14,
740,
8,
2416,
14,
415,
782,
8,
2592,
12,
3504,
14,
24817,
63,
9905,
63,
5670,
12,
3285,
430,
267,
340,
818,
1253,
25480,
44,
63,
1877,
26,
288,
4474,
14,
740,
8,
2416,
14,
415,
782,
8,
2592,
12,
3504,
14,
24817,
63,
9905,
63,
10387,
12,
3285,
430,
267,
367,
325,
315,
4474,
26,
288,
291,
423,
75,
1825,
14,
2785,
779,
69,
467,
378,
9,
339,
347,
11271,
8,
277,
12,
2653,
304,
267,
340,
2653,
665,
378,
26,
288,
2653,
275,
488,
221,
327,
1022,
1825,
13942,
267,
4474,
275,
291,
423,
75,
1825,
14,
2785,
8,
403,
12,
1804,
1825,
7382,
14,
4283,
63,
8193,
51,
12,
2653,
9,
267,
2058,
275,
10018,
8,
2734,
26,
25480,
44,
63,
8084,
9,
267,
367,
325,
315,
4474,
26,
288,
6111,
275,
325,
14,
5425,
288,
340,
325,
14,
1541,
508,
3504,
14,
24817,
63,
9905,
63,
5670,
26,
355,
2058,
59,
2592,
61,
8901,
25480,
44,
63,
568,
288,
916,
325,
14,
1541,
508,
3504,
14,
24817,
63,
9905,
63,
10387,
26,
355,
2058,
59,
2592,
61,
8901,
25480,
44,
63,
1877,
267,
372,
2058,
14,
1744,
342,
339,
347,
1050,
63,
2592,
8,
277,
12,
6111,
12,
818,
304,
267,
291,
423,
14240,
59,
2592,
61,
275,
818,
267,
291,
423,
2785,
8,
2592,
12,
818,
12,
3504,
14,
24817,
63,
18015,
63,
9732,
9,
339,
347,
2813,
63,
2592,
8,
277,
12,
6111,
304,
267,
291,
423,
2785,
8,
2592,
12,
291,
423,
14240,
59,
2592,
467,
3504,
14,
24817,
63,
18015,
63,
7014,
9,
267,
2150,
291,
423,
14240,
59,
2592,
61,
339,
347,
2811,
63,
2592,
8,
277,
12,
6111,
12,
818,
304,
267,
291,
14,
2168,
63,
2592,
8,
2592,
9,
267,
291,
14,
525,
63,
2592,
8,
2592,
12,
818,
9,
421,
199,
533,
9496,
7382,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
82,
63,
513,
275,
663,
342,
267,
291,
423,
87,
63,
513,
275,
663,
342,
267,
291,
423,
88,
63,
513,
275,
663,
342,
339,
347,
11271,
8,
277,
12,
2653,
304,
267,
519,
12,
336,
12,
671,
275,
3504,
14,
2416,
8,
277,
423,
82,
63,
513,
12,
291,
423,
87,
63,
513,
12,
291,
423,
88,
63,
513,
12,
1816,
2653,
9,
267,
2058,
275,
10018,
8,
2734,
26,
25480,
44,
63,
8084,
9,
267,
367,
299,
315,
3842,
82,
12,
25480,
44,
63,
568,
395,
334,
87,
12,
25480,
44,
63,
1877,
395,
334,
88,
12,
25480,
44,
63,
2666,
19532,
288,
367,
6111,
315,
299,
59,
16,
2189,
355,
2058,
59
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
6171,
13,
7806,
286,
674,
11530,
89,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
3,
687,
10110,
3813,
199,
3,
4178,
921,
5031,
14,
957,
15,
67,
674,
11530,
89,
15,
385,
3813,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
12,
971,
272,
543,
63,
6242,
199,
199,
646,
747,
199,
646,
2838,
199,
646,
3504,
199,
646,
7554,
199,
646,
2050,
199,
504,
5055,
492,
10018,
199,
199,
504,
15084,
21234,
492,
5218,
421,
199,
363,
452,
363,
275,
788,
2390,
7382,
297,
283,
16428,
63,
8084,
297,
283,
16428,
63,
568,
297,
283,
16428,
63,
1877,
297,
283,
16428,
63,
2666,
297,
1779,
283,
16428,
63,
40,
2160,
297,
283,
16428,
63,
46,
3204,
297,
283,
8193,
63,
14546,
418,
199,
199,
16428,
63,
8084,
275,
378,
88,
383,
199,
16428,
63,
568,
275,
378,
88,
614,
199,
16428,
63,
1877,
275,
378,
88,
966,
199,
16428,
63,
2666,
275,
378,
88,
2036,
199,
16428,
63,
40,
2160,
275,
378,
88,
709,
199,
16428,
63,
46,
3204,
275,
378,
88,
1165,
421,
199,
8193,
63,
14546,
275,
469,
272,
25480,
44,
63,
8084,
26,
283,
16428,
63,
8084,
297,
272,
25480,
44,
63,
568,
26,
283,
16428,
63,
568,
297,
272,
25480,
44,
63,
1877,
26,
283,
16428,
63,
1877,
297,
272,
25480,
44,
63,
2666,
26,
283,
16428,
63,
2666,
297,
272,
25480,
44,
63,
40,
2160,
26,
283,
16428,
63,
40,
2160,
297,
272,
25480,
44,
63,
46,
3204,
26,
283,
16428,
63,
46,
3204,
297,
199,
93,
421,
199,
533,
662,
6843,
7382,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
1545,
14385,
275,
3504,
14,
1545,
14385,
342,
339,
347,
11271,
8,
277,
12,
2653,
304,
267,
372,
291,
423,
1545,
14385,
14,
6843,
8,
2593,
9,
339,
347,
1050,
63,
2592,
8,
277,
12,
6111,
12,
818,
304,
267,
291,
423,
1545,
14385,
14,
2683,
8,
2592,
12,
818,
9,
339,
347,
2813,
63,
2592,
8,
277,
12,
6111,
304,
267,
291,
423,
1545,
14385,
14,
18408,
8,
2592,
9,
339,
347,
2811,
63,
2592,
8,
277,
12,
6111,
12,
818,
304,
267,
291,
423,
1545,
14385,
14,
8951,
8,
2592,
12,
818,
9,
421,
199,
533,
1804,
1825,
7382,
8,
785,
304,
339,
9141,
63,
8193,
51,
275,
6619,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
75,
1825,
275,
3504,
14,
75,
1825,
342,
267,
291,
423,
14240,
275,
1052,
339,
347,
485,
2785,
8,
277,
12,
6111,
12,
818,
12,
3285,
304,
267,
4474,
275,
942,
267,
340,
818,
1253,
25480,
44,
63,
568,
26,
288,
4474,
14,
740,
8,
2416,
14,
415,
782,
8,
2592,
12,
3504,
14,
24817,
63,
9905,
63,
5670,
12,
3285,
430,
267,
340,
818,
1253,
25480,
44,
63,
1877,
26,
288,
4474,
14,
740,
8,
2416,
14,
415,
782,
8,
2592,
12,
3504,
14,
24817,
63,
9905,
63,
10387,
12,
3285,
430,
267,
367,
325,
315,
4474,
26,
288,
291,
423,
75,
1825,
14,
2785,
779,
69,
467,
378,
9,
339,
347,
11271,
8,
277,
12,
2653,
304,
267,
340,
2653,
665,
378,
26,
288,
2653,
275,
488,
221,
327,
1022,
1825,
13942,
267,
4474,
275,
291,
423,
75,
1825,
14,
2785,
8,
403,
12,
1804,
1825,
7382,
14,
4283,
63,
8193,
51,
12,
2653,
9,
267,
2058,
275,
10018,
8,
2734,
26,
25480,
44,
63,
8084,
9,
267,
367,
325,
315,
4474,
26,
288,
6111,
275,
325,
14,
5425,
288,
340,
325,
14,
1541,
508,
3504,
14,
24817,
63,
9905,
63,
5670,
26,
355,
2058,
59,
2592,
61,
8901,
25480,
44,
63,
568,
288,
916,
325,
14,
1541,
508,
3504,
14,
24817,
63,
9905,
63,
10387,
26,
355,
2058,
59,
2592,
61,
8901,
25480,
44,
63,
1877,
267,
372,
2058,
14,
1744,
342,
339,
347,
1050,
63,
2592,
8,
277,
12,
6111,
12,
818,
304,
267,
291,
423,
14240,
59,
2592,
61,
275,
818,
267,
291,
423,
2785,
8,
2592,
12,
818,
12,
3504,
14,
24817,
63,
18015,
63,
9732,
9,
339,
347,
2813,
63,
2592,
8,
277,
12,
6111,
304,
267,
291,
423,
2785,
8,
2592,
12,
291,
423,
14240,
59,
2592,
467,
3504,
14,
24817,
63,
18015,
63,
7014,
9,
267,
2150,
291,
423,
14240,
59,
2592,
61,
339,
347,
2811,
63,
2592,
8,
277,
12,
6111,
12,
818,
304,
267,
291,
14,
2168,
63,
2592,
8,
2592,
9,
267,
291,
14,
525,
63,
2592,
8,
2592,
12,
818,
9,
421,
199,
533,
9496,
7382,
8,
785,
304,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
82,
63,
513,
275,
663,
342,
267,
291,
423,
87,
63,
513,
275,
663,
342,
267,
291,
423,
88,
63,
513,
275,
663,
342,
339,
347,
11271,
8,
277,
12,
2653,
304,
267,
519,
12,
336,
12,
671,
275,
3504,
14,
2416,
8,
277,
423,
82,
63,
513,
12,
291,
423,
87,
63,
513,
12,
291,
423,
88,
63,
513,
12,
1816,
2653,
9,
267,
2058,
275,
10018,
8,
2734,
26,
25480,
44,
63,
8084,
9,
267,
367,
299,
315,
3842,
82,
12,
25480,
44,
63,
568,
395,
334,
87,
12,
25480,
44,
63,
1877,
395,
334,
88,
12,
25480,
44,
63,
2666,
19532,
288,
367,
6111,
315,
299,
59,
16,
2189,
355,
2058,
59,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
svanschalkwyk/datafari
|
debian7/elk/kibana/node/lib/node_modules/npm/node_modules/node-gyp/gyp/buildbot/buildbot_run.py
|
270
|
8338
|
#!/usr/bin/env python
# Copyright (c) 2012 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Argument-less script to select what to run on the buildbots."""
import filecmp
import os
import shutil
import subprocess
import sys
if sys.platform in ['win32', 'cygwin']:
EXE_SUFFIX = '.exe'
else:
EXE_SUFFIX = ''
BUILDBOT_DIR = os.path.dirname(os.path.abspath(__file__))
TRUNK_DIR = os.path.dirname(BUILDBOT_DIR)
ROOT_DIR = os.path.dirname(TRUNK_DIR)
ANDROID_DIR = os.path.join(ROOT_DIR, 'android')
CMAKE_DIR = os.path.join(ROOT_DIR, 'cmake')
CMAKE_BIN_DIR = os.path.join(CMAKE_DIR, 'bin')
OUT_DIR = os.path.join(TRUNK_DIR, 'out')
def CallSubProcess(*args, **kwargs):
"""Wrapper around subprocess.call which treats errors as build exceptions."""
with open(os.devnull) as devnull_fd:
retcode = subprocess.call(stdin=devnull_fd, *args, **kwargs)
if retcode != 0:
print '@@@STEP_EXCEPTION@@@'
sys.exit(1)
def PrepareCmake():
"""Build CMake 2.8.8 since the version in Precise is 2.8.7."""
if os.environ['BUILDBOT_CLOBBER'] == '1':
print '@@@BUILD_STEP Clobber CMake checkout@@@'
shutil.rmtree(CMAKE_DIR)
# We always build CMake 2.8.8, so no need to do anything
# if the directory already exists.
if os.path.isdir(CMAKE_DIR):
return
print '@@@BUILD_STEP Initialize CMake checkout@@@'
os.mkdir(CMAKE_DIR)
print '@@@BUILD_STEP Sync CMake@@@'
CallSubProcess(
['git', 'clone',
'--depth', '1',
'--single-branch',
'--branch', 'v2.8.8',
'--',
'git://cmake.org/cmake.git',
CMAKE_DIR],
cwd=CMAKE_DIR)
print '@@@BUILD_STEP Build CMake@@@'
CallSubProcess(
['/bin/bash', 'bootstrap', '--prefix=%s' % CMAKE_DIR],
cwd=CMAKE_DIR)
CallSubProcess( ['make', 'cmake'], cwd=CMAKE_DIR)
_ANDROID_SETUP = 'source build/envsetup.sh && lunch full-eng'
def PrepareAndroidTree():
"""Prepare an Android tree to run 'android' format tests."""
if os.environ['BUILDBOT_CLOBBER'] == '1':
print '@@@BUILD_STEP Clobber Android checkout@@@'
shutil.rmtree(ANDROID_DIR)
# (Re)create the directory so that the following steps will succeed.
if not os.path.isdir(ANDROID_DIR):
os.mkdir(ANDROID_DIR)
# We use a manifest from the gyp project listing pinned revisions of AOSP to
# use, to ensure that we test against a stable target. This needs to be
# updated to pick up new build system changes sometimes, so we must test if
# it has changed.
manifest_filename = 'aosp_manifest.xml'
gyp_manifest = os.path.join(BUILDBOT_DIR, manifest_filename)
android_manifest = os.path.join(ANDROID_DIR, '.repo', 'manifests',
manifest_filename)
manifest_is_current = (os.path.isfile(android_manifest) and
filecmp.cmp(gyp_manifest, android_manifest))
if not manifest_is_current:
# It's safe to repeat these steps, so just do them again to make sure we are
# in a good state.
print '@@@BUILD_STEP Initialize Android checkout@@@'
CallSubProcess(
['repo', 'init',
'-u', 'https://android.googlesource.com/platform/manifest',
'-b', 'master',
'-g', 'all,-notdefault,-device,-darwin,-mips,-x86'],
cwd=ANDROID_DIR)
shutil.copy(gyp_manifest, android_manifest)
print '@@@BUILD_STEP Sync Android@@@'
CallSubProcess(['repo', 'sync', '-j4', '-m', manifest_filename],
cwd=ANDROID_DIR)
# If we already built the system image successfully and didn't sync to a new
# version of the source, skip running the build again as it's expensive even
# when there's nothing to do.
system_img = os.path.join(ANDROID_DIR, 'out', 'target', 'product', 'generic',
'system.img')
if manifest_is_current and os.path.isfile(system_img):
return
print '@@@BUILD_STEP Build Android@@@'
CallSubProcess(
['/bin/bash',
'-c', '%s && make -j4' % _ANDROID_SETUP],
cwd=ANDROID_DIR)
def StartAndroidEmulator():
"""Start an android emulator from the built android tree."""
print '@@@BUILD_STEP Start Android emulator@@@'
CallSubProcess(['/bin/bash', '-c',
'%s && adb kill-server ' % _ANDROID_SETUP],
cwd=ANDROID_DIR)
# If taskset is available, use it to force adbd to run only on one core, as,
# sadly, it improves its reliability (see crbug.com/268450).
adbd_wrapper = ''
with open(os.devnull, 'w') as devnull_fd:
if subprocess.call(['which', 'taskset'], stdout=devnull_fd) == 0:
adbd_wrapper = 'taskset -c 0'
CallSubProcess(['/bin/bash', '-c',
'%s && %s adb start-server ' % (_ANDROID_SETUP, adbd_wrapper)],
cwd=ANDROID_DIR)
subprocess.Popen(
['/bin/bash', '-c',
'%s && emulator -no-window' % _ANDROID_SETUP],
cwd=ANDROID_DIR)
CallSubProcess(
['/bin/bash', '-c',
'%s && adb wait-for-device' % _ANDROID_SETUP],
cwd=ANDROID_DIR)
def StopAndroidEmulator():
"""Stop all android emulators."""
print '@@@BUILD_STEP Stop Android emulator@@@'
# If this fails, it's because there is no emulator running.
subprocess.call(['pkill', 'emulator.*'])
def GypTestFormat(title, format=None, msvs_version=None, tests=[]):
"""Run the gyp tests for a given format, emitting annotator tags.
See annotator docs at:
https://sites.google.com/a/chromium.org/dev/developers/testing/chromium-build-infrastructure/buildbot-annotations
Args:
format: gyp format to test.
Returns:
0 for sucesss, 1 for failure.
"""
if not format:
format = title
print '@@@BUILD_STEP ' + title + '@@@'
sys.stdout.flush()
env = os.environ.copy()
if msvs_version:
env['GYP_MSVS_VERSION'] = msvs_version
command = ' '.join(
[sys.executable, 'gyp/gyptest.py',
'--all',
'--passed',
'--format', format,
'--path', CMAKE_BIN_DIR,
'--chdir', 'gyp'] + tests)
if format == 'android':
# gyptest needs the environment setup from envsetup/lunch in order to build
# using the 'android' backend, so this is done in a single shell.
retcode = subprocess.call(
['/bin/bash',
'-c', '%s && cd %s && %s' % (_ANDROID_SETUP, ROOT_DIR, command)],
cwd=ANDROID_DIR, env=env)
else:
retcode = subprocess.call(command, cwd=ROOT_DIR, env=env, shell=True)
if retcode:
# Emit failure tag, and keep going.
print '@@@STEP_FAILURE@@@'
return 1
return 0
def GypBuild():
# Dump out/ directory.
print '@@@BUILD_STEP cleanup@@@'
print 'Removing %s...' % OUT_DIR
shutil.rmtree(OUT_DIR, ignore_errors=True)
print 'Done.'
retcode = 0
# The Android gyp bot runs on linux so this must be tested first.
if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-android':
PrepareAndroidTree()
StartAndroidEmulator()
try:
retcode += GypTestFormat('android')
finally:
StopAndroidEmulator()
elif sys.platform.startswith('linux'):
retcode += GypTestFormat('ninja')
retcode += GypTestFormat('make')
PrepareCmake()
retcode += GypTestFormat('cmake')
elif sys.platform == 'darwin':
retcode += GypTestFormat('ninja')
retcode += GypTestFormat('xcode')
retcode += GypTestFormat('make')
elif sys.platform == 'win32':
retcode += GypTestFormat('ninja')
if os.environ['BUILDBOT_BUILDERNAME'] == 'gyp-win64':
retcode += GypTestFormat('msvs-ninja-2013', format='msvs-ninja',
msvs_version='2013',
tests=[
r'test\generator-output\gyptest-actions.py',
r'test\generator-output\gyptest-relocate.py',
r'test\generator-output\gyptest-rules.py'])
retcode += GypTestFormat('msvs-2013', format='msvs', msvs_version='2013')
else:
raise Exception('Unknown platform')
if retcode:
# TODO(bradnelson): once the annotator supports a postscript (section for
# after the build proper that could be used for cumulative failures),
# use that instead of this. This isolates the final return value so
# that it isn't misattributed to the last stage.
print '@@@BUILD_STEP failures@@@'
sys.exit(retcode)
if __name__ == '__main__':
GypBuild()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
421,
199,
624,
5201,
13,
2003,
2884,
370,
3504,
4052,
370,
1255,
641,
314,
21306,
83,
1041,
421,
199,
646,
570,
5730,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
421,
199,
692,
984,
14,
3246,
315,
788,
2676,
708,
297,
283,
16680,
2565,
523,
3651,
37,
63,
12273,
275,
1987,
5803,
7,
199,
2836,
26,
523,
3651,
37,
63,
12273,
275,
2125,
421,
199,
18637,
2846,
1387,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
1766,
8019,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
18637,
2846,
1387,
63,
3022,
9,
199,
5441,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
1766,
8019,
63,
3022,
9,
199,
25658,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
283,
6238,
358,
199,
30250,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
283,
16472,
358,
199,
30250,
63,
9431,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
30250,
63,
3022,
12,
283,
1393,
358,
199,
1877,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
1766,
8019,
63,
3022,
12,
283,
548,
358,
421,
199,
318,
6523,
2610,
3498,
2031,
589,
12,
1011,
958,
304,
523,
408,
4590,
6818,
3873,
14,
1250,
1314,
20991,
1956,
2552,
465,
1900,
4967,
1041,
523,
543,
1551,
8,
736,
14,
19778,
9,
465,
4866,
2307,
63,
2592,
26,
272,
17375,
275,
3873,
14,
1250,
8,
6626,
29,
19778,
63,
2592,
12,
627,
589,
12,
1011,
958,
9,
523,
340,
17375,
1137,
378,
26,
272,
870,
283,
25673,
17988,
63,
15375,
25673,
7,
272,
984,
14,
2224,
8,
17,
9,
421,
199,
318,
17008,
35,
1875,
837,
523,
408,
3425,
21355,
499,
14,
24,
14,
24,
3967,
314,
1015,
315,
5543,
11900,
365,
499,
14,
24,
14,
23,
1041,
523,
340,
747,
14,
2314,
459,
18637,
2846,
1387,
63,
10353,
5342,
540,
418,
508,
283,
17,
356,
272,
870,
283,
25673,
8248,
63,
17988,
445,
22669,
21355,
15243,
25673,
7,
272,
5145,
14,
9242,
8,
30250,
63,
3022,
9,
819,
327,
2136,
3544,
1900,
21355,
499,
14,
24,
14,
24,
12,
880,
949,
1929,
370,
886,
7003,
523,
327,
340,
314,
2082,
2575,
3495,
14,
523,
340,
747,
14,
515,
14,
6027,
8,
30250,
63,
3022,
304,
272,
372,
819,
870,
283,
25673,
8248,
63,
17988,
11578,
21355,
15243,
25673,
7,
523,
747,
14,
8215,
8,
30250,
63,
3022,
9,
819,
870,
283,
25673,
8248,
63,
17988,
22407,
21355,
25673,
7,
523,
6523,
2610,
3498,
8,
489,
788,
3187,
297,
283,
6311,
297,
2126,
2850,
4631,
297,
283,
17,
297,
2126,
2850,
4780,
13,
4694,
297,
2126,
2850,
4694,
297,
283,
86,
18,
14,
24,
14,
24,
297,
2126,
2850,
297,
2126,
283,
3187,
921,
16472,
14,
1308,
15,
16472,
14,
3187,
297,
2126,
445,
18421,
63,
3022,
467,
489,
8288,
29,
30250,
63,
3022,
9,
819,
870,
283,
25673,
8248,
63,
17988,
6516,
21355,
25673,
7,
523,
6523,
2610,
3498,
8,
489,
18744,
1393,
15,
16408,
297,
283,
11146,
297,
2850,
1861,
2458,
83,
7,
450,
445,
18421,
63,
3022,
467,
489,
8288,
29,
30250,
63,
3022,
9,
819,
6523,
2610,
3498,
8,
788,
1875,
297,
283,
16472,
995,
8288,
29,
30250,
63,
3022,
9,
421,
199,
63,
25658,
63,
20836,
275,
283,
1365,
1900,
15,
1813,
2758,
14,
609,
10883,
634,
4689,
2615,
13,
7420,
7,
421,
199,
318,
17008,
20762,
3987,
837,
523,
408,
22281,
376,
14694,
3123,
370,
1255,
283,
6238,
7,
1475,
2295,
1041,
523,
340,
747,
14,
2314,
459,
18637,
2846,
1387,
63,
10353,
5342,
540,
418,
508,
283,
17,
356,
272,
870,
283,
25673,
8248,
63,
17988,
445,
22669,
14694,
15243,
25673,
7,
272,
5145,
14,
9242,
8,
25658,
63,
3022,
9,
819,
327,
334,
497,
9,
981,
314,
2082,
880,
626,
314,
2569,
7124,
911,
17961,
14,
523,
340,
440,
747,
14,
515,
14,
6027,
8,
25658,
63,
3022,
304,
272,
747,
14,
8215,
8,
25658,
63,
3022,
9,
819,
327,
2136,
675,
282,
7712,
687,
314,
4902,
2199,
13778,
10713,
7439,
22164,
402,
437,
3100,
48,
370,
523,
327,
675,
12,
370,
4868,
626,
781,
511,
6169,
282,
17830,
1347,
14,
961,
4839,
370,
506,
523,
327,
4588,
370,
3732,
1536,
892,
1900,
2656,
4493,
15026,
12,
880,
781,
1471,
511,
340,
523,
327,
652,
965,
2896,
14,
523,
7712,
63,
1501,
275,
283,
8035,
681,
63,
6418,
14,
1652,
7,
523,
4902,
63,
6418,
275,
747,
14,
515,
14,
904,
8,
18637,
2846,
1387,
63,
3022,
12,
7712,
63,
1501,
9,
523,
15516,
63,
6418,
275,
747,
14,
515,
14,
904,
8,
25658,
63,
3022,
12,
1987,
3417,
297,
283,
6418,
83,
297,
3303,
7712,
63,
1501,
9,
523,
7712,
63,
374,
63,
1818,
275,
334,
736,
14,
515,
14,
6292,
8,
6238,
63,
6418,
9,
436,
586,
570,
5730,
14,
5730,
8,
6179,
63,
6418,
12,
15516,
63,
6418,
430,
523,
340,
440,
7712,
63,
374,
63,
1818,
26,
272,
327,
2779,
1159,
5048,
370,
11982,
3520,
7124,
12,
880,
2951,
886,
3062,
4020,
370,
1852,
3238,
781,
787,
272,
327,
315,
282,
6954,
1174,
14,
272,
870,
283,
25673,
8248,
63,
17988,
11578,
14694,
15243,
25673,
7,
272,
6523,
2610,
3498,
8,
267,
788,
3417,
297,
283,
826,
297,
268,
2475,
85,
297,
283,
2859,
921,
6238,
14,
3098,
1365,
14,
957,
15,
3246,
15,
6418,
297,
268,
2475,
66,
297,
283,
4133,
297,
268,
2475,
71,
297,
283,
452,
3057,
1397,
885,
3057,
1782,
3057,
13245,
3057,
77,
6142,
3057,
88,
1184,
995,
267,
8288,
29,
25658,
63,
3022,
9,
272,
5145,
14,
1574,
8,
6179,
63,
6418,
12,
15516,
63,
6418,
9,
339,
870,
283,
25673,
8248,
63,
17988,
22407,
14694,
25673,
7,
272,
6523,
2610,
3498,
2941,
3417,
297,
283,
5186,
297,
2475,
74,
20,
297,
2475,
77,
297,
7712,
63,
1501
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
421,
199,
624,
5201,
13,
2003,
2884,
370,
3504,
4052,
370,
1255,
641,
314,
21306,
83,
1041,
421,
199,
646,
570,
5730,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
421,
199,
692,
984,
14,
3246,
315,
788,
2676,
708,
297,
283,
16680,
2565,
523,
3651,
37,
63,
12273,
275,
1987,
5803,
7,
199,
2836,
26,
523,
3651,
37,
63,
12273,
275,
2125,
421,
199,
18637,
2846,
1387,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
199,
1766,
8019,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
18637,
2846,
1387,
63,
3022,
9,
199,
5441,
63,
3022,
275,
747,
14,
515,
14,
3475,
8,
1766,
8019,
63,
3022,
9,
199,
25658,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
283,
6238,
358,
199,
30250,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
5441,
63,
3022,
12,
283,
16472,
358,
199,
30250,
63,
9431,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
30250,
63,
3022,
12,
283,
1393,
358,
199,
1877,
63,
3022,
275,
747,
14,
515,
14,
904,
8,
1766,
8019,
63,
3022,
12,
283,
548,
358,
421,
199,
318,
6523,
2610,
3498,
2031,
589,
12,
1011,
958,
304,
523,
408,
4590,
6818,
3873,
14,
1250,
1314,
20991,
1956,
2552,
465,
1900,
4967,
1041,
523,
543,
1551,
8,
736,
14,
19778,
9,
465,
4866,
2307,
63,
2592,
26,
272,
17375,
275,
3873,
14,
1250,
8,
6626,
29,
19778,
63,
2592,
12,
627,
589,
12,
1011,
958,
9,
523,
340,
17375,
1137,
378,
26,
272,
870,
283,
25673,
17988,
63,
15375,
25673,
7,
272,
984,
14,
2224,
8,
17,
9,
421,
199,
318,
17008,
35,
1875,
837,
523,
408,
3425,
21355,
499,
14,
24,
14,
24,
3967,
314,
1015,
315,
5543,
11900,
365,
499,
14,
24,
14,
23,
1041,
523,
340,
747,
14,
2314,
459,
18637,
2846,
1387,
63,
10353,
5342,
540,
418,
508,
283,
17,
356,
272,
870,
283,
25673,
8248,
63,
17988,
445,
22669,
21355,
15243,
25673,
7,
272,
5145,
14,
9242,
8,
30250,
63,
3022,
9,
819,
327,
2136,
3544,
1900,
21355,
499,
14,
24,
14,
24,
12,
880,
949,
1929,
370,
886,
7003,
523,
327,
340,
314,
2082,
2575,
3495,
14,
523,
340,
747,
14,
515,
14,
6027,
8,
30250,
63,
3022,
304,
272,
372,
819,
870,
283,
25673,
8248,
63,
17988,
11578,
21355,
15243,
25673,
7,
523,
747,
14,
8215,
8,
30250,
63,
3022,
9,
819,
870,
283,
25673,
8248,
63,
17988,
22407,
21355,
25673,
7,
523,
6523,
2610,
3498,
8,
489,
788,
3187,
297,
283,
6311,
297,
2126,
2850,
4631,
297,
283,
17,
297,
2126,
2850,
4780,
13,
4694,
297,
2126,
2850,
4694,
297,
283,
86,
18,
14,
24,
14,
24,
297,
2126,
2850,
297,
2126,
283,
3187,
921,
16472,
14,
1308,
15,
16472,
14,
3187,
297,
2126,
445,
18421,
63,
3022,
467,
489,
8288,
29,
30250,
63,
3022,
9,
819,
870,
283,
25673,
8248,
63,
17988,
6516,
21355,
25673,
7,
523,
6523,
2610,
3498,
8,
489,
18744,
1393,
15,
16408,
297,
283,
11146,
297,
2850,
1861,
2458,
83,
7,
450,
445,
18421,
63,
3022,
467,
489,
8288,
29,
30250,
63,
3022,
9,
819,
6523,
2610,
3498,
8,
788,
1875,
297,
283,
16472,
995,
8288,
29,
30250,
63,
3022,
9,
421,
199,
63,
25658,
63,
20836,
275,
283,
1365,
1900,
15,
1813,
2758,
14,
609,
10883,
634,
4689,
2615,
13,
7420,
7,
421,
199,
318,
17008,
20762,
3987,
837,
523,
408,
22281,
376,
14694,
3123,
370,
1255,
283,
6238,
7,
1475,
2295,
1041,
523,
340,
747,
14,
2314,
459,
18637,
2846,
1387,
63,
10353,
5342,
540,
418,
508,
283,
17,
356,
272,
870,
283,
25673,
8248,
63,
17988,
445,
22669,
14694,
15243,
25673,
7,
272,
5145,
14,
9242,
8,
25658,
63,
3022,
9,
819,
327,
334,
497,
9,
981,
314,
2082,
880,
626,
314,
2569,
7124,
911,
17961,
14,
523,
340,
440,
747,
14,
515,
14,
6027,
8,
25658,
63,
3022,
304,
272,
747,
14,
8215,
8,
25658,
63,
3022,
9,
819,
327,
2136,
675,
282,
7712,
687,
314,
4902,
2199,
13778,
10713,
7439,
22164,
402,
437,
3100,
48,
370,
523,
327,
675,
12,
370,
4868,
626,
781,
511,
6169,
282,
17830,
1347,
14,
961,
4839,
370,
506,
523,
327,
4588,
370,
3732,
1536,
892,
1900,
2656,
4493,
15026,
12,
880,
781,
1471,
511,
340,
523,
327,
652,
965,
2896,
14,
523,
7712,
63,
1501,
275,
283,
8035,
681,
63,
6418,
14,
1652,
7,
523,
4902,
63,
6418,
275,
747,
14,
515,
14,
904,
8,
18637,
2846,
1387,
63,
3022,
12,
7712,
63,
1501,
9,
523,
15516,
63,
6418,
275,
747,
14,
515,
14,
904,
8,
25658,
63,
3022,
12,
1987,
3417,
297,
283,
6418,
83,
297,
3303,
7712,
63,
1501,
9,
523,
7712,
63,
374,
63,
1818,
275,
334,
736,
14,
515,
14,
6292,
8,
6238,
63,
6418,
9,
436,
586,
570,
5730,
14,
5730,
8,
6179,
63,
6418,
12,
15516,
63,
6418,
430,
523,
340,
440,
7712,
63,
374,
63,
1818,
26,
272,
327,
2779,
1159,
5048,
370,
11982,
3520,
7124,
12,
880,
2951,
886,
3062,
4020,
370,
1852,
3238,
781,
787,
272,
327,
315,
282,
6954,
1174,
14,
272,
870,
283,
25673,
8248,
63,
17988,
11578,
14694,
15243,
25673,
7,
272,
6523,
2610,
3498,
8,
267,
788,
3417,
297,
283,
826,
297,
268,
2475,
85,
297,
283,
2859,
921,
6238,
14,
3098,
1365,
14,
957,
15,
3246,
15,
6418,
297,
268,
2475,
66,
297,
283,
4133,
297,
268,
2475,
71,
297,
283,
452,
3057,
1397,
885,
3057,
1782,
3057,
13245,
3057,
77,
6142,
3057,
88,
1184,
995,
267,
8288,
29,
25658,
63,
3022,
9,
272,
5145,
14,
1574,
8,
6179,
63,
6418,
12,
15516,
63,
6418,
9,
339,
870,
283,
25673,
8248,
63,
17988,
22407,
14694,
25673,
7,
272,
6523,
2610,
3498,
2941,
3417,
297,
283,
5186,
297,
2475,
74,
20,
297,
2475,
77,
297,
7712,
63,
1501,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mbaijal/incubator-mxnet
|
example/image-classification/train_imagenet.py
|
4
|
2563
|
# 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
import argparse
import logging
logging.basicConfig(level=logging.DEBUG)
from common import find_mxnet, data, fit
from common.util import download_file
import mxnet as mx
def set_imagenet_aug(aug):
# standard data augmentation setting for imagenet training
aug.set_defaults(rgb_mean='123.68,116.779,103.939', rgb_std='58.393,57.12,57.375')
aug.set_defaults(random_crop=0, random_resized_crop=1, random_mirror=1)
aug.set_defaults(min_random_area=0.08)
aug.set_defaults(max_random_aspect_ratio=4./3., min_random_aspect_ratio=3./4.)
aug.set_defaults(brightness=0.4, contrast=0.4, saturation=0.4, pca_noise=0.1)
if __name__ == '__main__':
# parse args
parser = argparse.ArgumentParser(description="train imagenet-1k",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
fit.add_fit_args(parser)
data.add_data_args(parser)
data.add_data_aug_args(parser)
# uncomment to set standard augmentations for imagenet training
# set_imagenet_aug(parser)
parser.set_defaults(
# network
network = 'resnet',
num_layers = 50,
# data
num_classes = 1000,
num_examples = 1281167,
image_shape = '3,224,224',
min_random_scale = 1, # if input image has min size k, suggest to use
# 256.0/x, e.g. 0.533 for 480
# train
num_epochs = 80,
lr_step_epochs = '30,60',
dtype = 'float32'
)
args = parser.parse_args()
# load network
from importlib import import_module
net = import_module('symbols.'+args.network)
sym = net.get_symbol(**vars(args))
# train
fit.fit(args, sym, data.get_rec_iter)
|
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,
199,
646,
747,
199,
646,
7534,
199,
646,
2050,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
5287,
9,
199,
504,
2863,
492,
2342,
63,
9457,
846,
12,
666,
12,
5542,
199,
504,
2863,
14,
1974,
492,
5235,
63,
493,
199,
646,
8728,
846,
465,
8728,
199,
199,
318,
663,
63,
11744,
2268,
386,
63,
20669,
8,
20669,
304,
272,
327,
4465,
666,
18336,
3117,
4260,
367,
18884,
2268,
386,
6093,
272,
18336,
14,
409,
63,
4322,
8,
10090,
63,
3670,
534,
4288,
14,
2333,
12,
7524,
14,
14580,
12,
8845,
14,
31281,
297,
15180,
63,
1516,
534,
2010,
14,
15490,
12,
1641,
14,
713,
12,
1641,
14,
9946,
358,
272,
18336,
14,
409,
63,
4322,
8,
2355,
63,
15816,
29,
16,
12,
2196,
63,
264,
15308,
63,
15816,
29,
17,
12,
2196,
63,
12324,
29,
17,
9,
272,
18336,
14,
409,
63,
4322,
8,
827,
63,
2355,
63,
6789,
29,
16,
14,
2036,
9,
272,
18336,
14,
409,
63,
4322,
8,
988,
63,
2355,
63,
18658,
63,
6884,
29,
20,
13186,
19,
2020,
1748,
63,
2355,
63,
18658,
63,
6884,
29,
19,
13186,
20,
4959,
272,
18336,
14,
409,
63,
4322,
8,
22298,
29,
16,
14,
20,
12,
30347,
29,
16,
14,
20,
12,
21845,
1542,
29,
16,
14,
20,
12,
29518,
63,
11838,
29,
16,
14,
17,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
327,
2198,
1249,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
628,
2834,
18884,
2268,
386,
13,
17,
75,
401,
3660,
9698,
63,
533,
29,
18978,
14,
5201,
16986,
22779,
9,
272,
5542,
14,
525,
63,
3269,
63,
589,
8,
2087,
9,
272,
666,
14,
525,
63,
576,
63,
589,
8,
2087,
9,
272,
666,
14,
525,
63,
576,
63,
20669,
63,
589,
8,
2087,
9,
272,
327,
625,
3349,
370,
663,
4465,
18336,
434,
1298,
367,
18884,
2268,
386,
6093,
272,
327,
663,
63,
11744,
2268,
386,
63,
20669,
8,
2087,
9,
272,
1798,
14,
409,
63,
4322,
8,
267,
327,
2784,
267,
2784,
3515,
275,
283,
28998,
297,
267,
1967,
63,
4359,
755,
275,
5238,
12,
267,
327,
666,
267,
1967,
63,
2888,
420,
275,
5198,
12,
267,
1967,
63,
8589,
258,
275,
7960,
845,
1822,
12,
267,
1834,
63,
1392,
420,
275,
283,
19,
12,
8731,
12,
8731,
297,
267,
1748,
63,
2355,
63,
3467,
275,
413,
12,
327,
340,
1324,
1834,
965,
1748,
1568,
1022,
12,
18453,
370,
675,
2892,
327,
7633,
14,
16,
15,
88,
12,
325,
14,
71,
14,
378,
14,
25293,
367,
29504,
267,
327,
3560,
267,
1967,
63,
13161,
755,
275,
5939,
12,
267,
13645,
63,
2926,
63,
13161,
257,
275,
283,
1216,
12,
2259,
297,
267,
2152,
3322,
275,
283,
1609,
708,
7,
272,
776,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
327,
2248,
2784,
272,
687,
14802,
492,
492,
63,
578,
272,
1851,
275,
492,
63,
578,
360,
7450,
3530,
11,
589,
14,
1200,
9,
272,
4678,
275,
1851,
14,
362,
63,
5155,
3682,
2936,
8,
589,
430,
339,
327,
3560,
272,
5542,
14,
3269,
8,
589,
12,
4678,
12,
666,
14,
362,
63,
2761,
63,
1661,
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
] |
[
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
503,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
1854,
543,
642,
1736,
367,
4722,
2556,
199,
3,
12602,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
370,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
543,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
257,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
199,
3,
2032,
1854,
1334,
314,
844,
365,
1854,
641,
376,
199,
3,
298,
1179,
2281,
2,
4207,
12,
2428,
2990,
1549,
4217,
1634,
1821,
199,
3,
3826,
12,
1902,
4056,
503,
2478,
14,
221,
1666,
314,
844,
367,
314,
199,
3,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
646,
747,
199,
646,
7534,
199,
646,
2050,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
5287,
9,
199,
504,
2863,
492,
2342,
63,
9457,
846,
12,
666,
12,
5542,
199,
504,
2863,
14,
1974,
492,
5235,
63,
493,
199,
646,
8728,
846,
465,
8728,
199,
199,
318,
663,
63,
11744,
2268,
386,
63,
20669,
8,
20669,
304,
272,
327,
4465,
666,
18336,
3117,
4260,
367,
18884,
2268,
386,
6093,
272,
18336,
14,
409,
63,
4322,
8,
10090,
63,
3670,
534,
4288,
14,
2333,
12,
7524,
14,
14580,
12,
8845,
14,
31281,
297,
15180,
63,
1516,
534,
2010,
14,
15490,
12,
1641,
14,
713,
12,
1641,
14,
9946,
358,
272,
18336,
14,
409,
63,
4322,
8,
2355,
63,
15816,
29,
16,
12,
2196,
63,
264,
15308,
63,
15816,
29,
17,
12,
2196,
63,
12324,
29,
17,
9,
272,
18336,
14,
409,
63,
4322,
8,
827,
63,
2355,
63,
6789,
29,
16,
14,
2036,
9,
272,
18336,
14,
409,
63,
4322,
8,
988,
63,
2355,
63,
18658,
63,
6884,
29,
20,
13186,
19,
2020,
1748,
63,
2355,
63,
18658,
63,
6884,
29,
19,
13186,
20,
4959,
272,
18336,
14,
409,
63,
4322,
8,
22298,
29,
16,
14,
20,
12,
30347,
29,
16,
14,
20,
12,
21845,
1542,
29,
16,
14,
20,
12,
29518,
63,
11838,
29,
16,
14,
17,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
327,
2198,
1249,
272,
1798,
275,
7534,
14,
10730,
8,
1802,
628,
2834,
18884,
2268,
386,
13,
17,
75,
401,
3660,
9698,
63,
533,
29,
18978,
14,
5201,
16986,
22779,
9,
272,
5542,
14,
525,
63,
3269,
63,
589,
8,
2087,
9,
272,
666,
14,
525,
63,
576,
63,
589,
8,
2087,
9,
272,
666,
14,
525,
63,
576,
63,
20669,
63,
589,
8,
2087,
9,
272,
327,
625,
3349,
370,
663,
4465,
18336,
434,
1298,
367,
18884,
2268,
386,
6093,
272,
327,
663,
63,
11744,
2268,
386,
63,
20669,
8,
2087,
9,
272,
1798,
14,
409,
63,
4322,
8,
267,
327,
2784,
267,
2784,
3515,
275,
283,
28998,
297,
267,
1967,
63,
4359,
755,
275,
5238,
12,
267,
327,
666,
267,
1967,
63,
2888,
420,
275,
5198,
12,
267,
1967,
63,
8589,
258,
275,
7960,
845,
1822,
12,
267,
1834,
63,
1392,
420,
275,
283,
19,
12,
8731,
12,
8731,
297,
267,
1748,
63,
2355,
63,
3467,
275,
413,
12,
327,
340,
1324,
1834,
965,
1748,
1568,
1022,
12,
18453,
370,
675,
2892,
327,
7633,
14,
16,
15,
88,
12,
325,
14,
71,
14,
378,
14,
25293,
367,
29504,
267,
327,
3560,
267,
1967,
63,
13161,
755,
275,
5939,
12,
267,
13645,
63,
2926,
63,
13161,
257,
275,
283,
1216,
12,
2259,
297,
267,
2152,
3322,
275,
283,
1609,
708,
7,
272,
776,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
327,
2248,
2784,
272,
687,
14802,
492,
492,
63,
578,
272,
1851,
275,
492,
63,
578,
360,
7450,
3530,
11,
589,
14,
1200,
9,
272,
4678,
275,
1851,
14,
362,
63,
5155,
3682,
2936,
8,
589,
430,
339,
327,
3560,
272,
5542,
14,
3269,
8,
589,
12,
4678,
12,
666,
14,
362,
63,
2761,
63,
1661,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
igabriel85/dmon-adp
|
adpengine/multiprocRun.py
|
1
|
1604
|
import multiprocessing
import time
def test(times, processID):
print "Starting engine Point process %s" % processID
time.sleep(times)
print "Exit process %s" % processID
class AdpPointProcess():
def __init__(self, engine, processID):
self.processID = processID
self.engine = engine
def run(self):
print "Starting engine point process %s" % self.processID
p = multiprocessing.Process(target=self.engine.detectPointAnomalies)
return p
class AdpTrainProcess():
def __init__(self, engine, processID):
self.processID = processID
self.engine = engine
def run(self):
# time.sleep(10)
print "Starting engine Train process %s" % self.processID
p = multiprocessing.Process(target=self.engine.trainMethod)
return p
class AdpDetectProcess():
def __init__(self, engine, processID):
self.processID = processID
self.engine = engine
def run(self):
p = multiprocessing.Process(target=self.engine.detectAnomalies)
return p
# jobs = []
# testProcess = AdpPointProcess('engine', 'PointProcess')
# testProcess2 = AdpTrainProcess('engine', 'TrainProcess')
# testProcess3 = AdpDetectProcess('engine', 'Detect')
# initProcess = testProcess.run()
# jobs.append(initProcess)
# initProcess2 = testProcess2.run()
# jobs.append(initProcess2)
# initProcess3 = testProcess3.run()
# jobs.append(initProcess3)
#
# initProcess.start()
# initProcess2.start()
# initProcess3.start()
#
# for j in jobs:
# j.join()
# print '%s.exitcode = %s' % (j.name, j.exitcode)
|
apache-2.0
|
[
646,
12866,
199,
646,
900,
421,
199,
318,
511,
8,
4508,
12,
2112,
998,
304,
272,
870,
298,
14139,
6869,
7584,
2112,
450,
83,
2,
450,
2112,
998,
272,
900,
14,
4532,
8,
4508,
9,
272,
870,
298,
6699,
2112,
450,
83,
2,
450,
2112,
998,
421,
199,
533,
4431,
80,
3428,
3498,
837,
272,
347,
636,
826,
721,
277,
12,
6869,
12,
2112,
998,
304,
267,
291,
14,
1412,
998,
275,
2112,
998,
267,
291,
14,
3908,
275,
6869,
339,
347,
1255,
8,
277,
304,
267,
870,
298,
14139,
6869,
2376,
2112,
450,
83,
2,
450,
291,
14,
1412,
998,
267,
299,
275,
12866,
14,
3498,
8,
1375,
29,
277,
14,
3908,
14,
13552,
3428,
2493,
676,
279,
1500,
9,
267,
372,
299,
421,
199,
533,
4431,
80,
18591,
3498,
837,
272,
347,
636,
826,
721,
277,
12,
6869,
12,
2112,
998,
304,
267,
291,
14,
1412,
998,
275,
2112,
998,
267,
291,
14,
3908,
275,
6869,
339,
347,
1255,
8,
277,
304,
267,
327,
900,
14,
4532,
8,
709,
9,
267,
870,
298,
14139,
6869,
16732,
2112,
450,
83,
2,
450,
291,
14,
1412,
998,
267,
299,
275,
12866,
14,
3498,
8,
1375,
29,
277,
14,
3908,
14,
2834,
3767,
9,
267,
372,
299,
421,
199,
533,
4431,
80,
20064,
3498,
837,
272,
347,
636,
826,
721,
277,
12,
6869,
12,
2112,
998,
304,
267,
291,
14,
1412,
998,
275,
2112,
998,
267,
291,
14,
3908,
275,
6869,
339,
347,
1255,
8,
277,
304,
267,
299,
275,
12866,
14,
3498,
8,
1375,
29,
277,
14,
3908,
14,
13552,
2493,
676,
279,
1500,
9,
267,
372,
299,
421,
199,
3,
9643,
275,
942,
199,
3,
511,
3498,
275,
4431,
80,
3428,
3498,
360,
3908,
297,
283,
3428,
3498,
358,
199,
3,
511,
3498,
18,
275,
4431,
80,
18591,
3498,
360,
3908,
297,
283,
18591,
3498,
358,
199,
3,
511,
3498,
19,
275,
4431,
80,
20064,
3498,
360,
3908,
297,
283,
20064,
358,
199,
3,
4205,
3498,
275,
511,
3498,
14,
1065,
342,
199,
3,
9643,
14,
740,
8,
826,
3498,
9,
199,
3,
4205,
3498,
18,
275,
511,
3498,
18,
14,
1065,
342,
199,
3,
9643,
14,
740,
8,
826,
3498,
18,
9,
199,
3,
4205,
3498,
19,
275,
511,
3498,
19,
14,
1065,
342,
199,
3,
9643,
14,
740,
8,
826,
3498,
19,
9,
199,
3,
199,
3,
4205,
3498,
14,
928,
342,
199,
3,
4205,
3498,
18,
14,
928,
342,
199,
3,
4205,
3498,
19,
14,
928,
342,
199,
3,
199,
3,
367,
1335,
315,
9643,
26,
199,
3,
258,
1335,
14,
904,
342,
199,
3,
258,
870,
1543,
83,
14,
2224,
600,
275,
450,
83,
7,
450,
334,
74,
14,
354,
12,
1335,
14,
2224,
600,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
12866,
199,
646,
900,
421,
199,
318,
511,
8,
4508,
12,
2112,
998,
304,
272,
870,
298,
14139,
6869,
7584,
2112,
450,
83,
2,
450,
2112,
998,
272,
900,
14,
4532,
8,
4508,
9,
272,
870,
298,
6699,
2112,
450,
83,
2,
450,
2112,
998,
421,
199,
533,
4431,
80,
3428,
3498,
837,
272,
347,
636,
826,
721,
277,
12,
6869,
12,
2112,
998,
304,
267,
291,
14,
1412,
998,
275,
2112,
998,
267,
291,
14,
3908,
275,
6869,
339,
347,
1255,
8,
277,
304,
267,
870,
298,
14139,
6869,
2376,
2112,
450,
83,
2,
450,
291,
14,
1412,
998,
267,
299,
275,
12866,
14,
3498,
8,
1375,
29,
277,
14,
3908,
14,
13552,
3428,
2493,
676,
279,
1500,
9,
267,
372,
299,
421,
199,
533,
4431,
80,
18591,
3498,
837,
272,
347,
636,
826,
721,
277,
12,
6869,
12,
2112,
998,
304,
267,
291,
14,
1412,
998,
275,
2112,
998,
267,
291,
14,
3908,
275,
6869,
339,
347,
1255,
8,
277,
304,
267,
327,
900,
14,
4532,
8,
709,
9,
267,
870,
298,
14139,
6869,
16732,
2112,
450,
83,
2,
450,
291,
14,
1412,
998,
267,
299,
275,
12866,
14,
3498,
8,
1375,
29,
277,
14,
3908,
14,
2834,
3767,
9,
267,
372,
299,
421,
199,
533,
4431,
80,
20064,
3498,
837,
272,
347,
636,
826,
721,
277,
12,
6869,
12,
2112,
998,
304,
267,
291,
14,
1412,
998,
275,
2112,
998,
267,
291,
14,
3908,
275,
6869,
339,
347,
1255,
8,
277,
304,
267,
299,
275,
12866,
14,
3498,
8,
1375,
29,
277,
14,
3908,
14,
13552,
2493,
676,
279,
1500,
9,
267,
372,
299,
421,
199,
3,
9643,
275,
942,
199,
3,
511,
3498,
275,
4431,
80,
3428,
3498,
360,
3908,
297,
283,
3428,
3498,
358,
199,
3,
511,
3498,
18,
275,
4431,
80,
18591,
3498,
360,
3908,
297,
283,
18591,
3498,
358,
199,
3,
511,
3498,
19,
275,
4431,
80,
20064,
3498,
360,
3908,
297,
283,
20064,
358,
199,
3,
4205,
3498,
275,
511,
3498,
14,
1065,
342,
199,
3,
9643,
14,
740,
8,
826,
3498,
9,
199,
3,
4205,
3498,
18,
275,
511,
3498,
18,
14,
1065,
342,
199,
3,
9643,
14,
740,
8,
826,
3498,
18,
9,
199,
3,
4205,
3498,
19,
275,
511,
3498,
19,
14,
1065,
342,
199,
3,
9643,
14,
740,
8,
826,
3498,
19,
9,
199,
3,
199,
3,
4205,
3498,
14,
928,
342,
199,
3,
4205,
3498,
18,
14,
928,
342,
199,
3,
4205,
3498,
19,
14,
928,
342,
199,
3,
199,
3,
367,
1335,
315,
9643,
26,
199,
3,
258,
1335,
14,
904,
342,
199,
3,
258,
870,
1543,
83,
14,
2224,
600,
275,
450,
83,
7,
450,
334,
74,
14,
354,
12,
1335,
14,
2224,
600,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
40223144/2015cd_midterm
|
static/Brython3.1.1-20150328-091302/Lib/browser/indexed_db.py
|
632
|
3008
|
class EventListener:
def __init__(self, events=[]):
self._events=events
def append(self, event):
self._events.append(event)
def fire(self, e):
for _event in self._events:
_event(e)
class IndexedDB:
def __init__(self):
if not __BRYTHON__.has_indexedDB:
raise NotImplementedError("Your browser doesn't support indexedDB")
return
self._indexedDB=__BRYTHON__.indexedDB()
self._db=None
self._version=None
def _onsuccess(self, event):
self._db=event.target.result
def open(self, name, onsuccess, version=1.0, onerror=None,
onupgradeneeded=None):
self._version=version
_result=self._indexedDB.open(name, version)
_success=EventListener([self._onsuccess, onsuccess])
_result.onsuccess=_success.fire
_result.onupgradeneeded=onupgradeneeded
#if onerror is None:
def onerror(e):
print("onerror: %s:%s" % (e.type, e.target.result))
def onblocked(e):
print("blocked: %s:%s" % (e.type, e.result))
_result.onerror=onerror
_result.onblocked=onblocked
def transaction(self, entities, mode='read'):
return Transaction(self._db.transaction(entities, mode))
class Transaction:
def __init__(self, transaction):
self._transaction=transaction
def objectStore(self, name):
return ObjectStore(self._transaction.objectStore(name))
class ObjectStore:
def __init__(self, objectStore):
self._objectStore=objectStore
self._data=[]
def clear(self, onsuccess=None, onerror=None):
_result=self._objectStore.clear()
if onsuccess is not None:
_result.onsuccess=onsuccess
if onerror is not None:
_result.onerror=onerror
def _helper(self, func, object, onsuccess=None, onerror=None):
_result=func(object)
if onsuccess is not None:
_result.onsuccess=onsuccess
if onerror is not None:
_result.onerror=onerror
def put(self, obj, key=None, onsuccess=None, onerror=None):
_r = self._objectStore.put(obj, key)
_r.onsuccess = onsuccess
_r.onerror = onerror
def add(self, obj, key, onsuccess=None, onerror=None):
_r = self._objectStore.add(obj, key)
_r.onsuccess = onsuccess
_r.onerror = onerror
#self._helper(self._objectStore.add, object, onsuccess, onerror)
def delete(self, index, onsuccess=None, onerror=None):
self._helper(self._objectStore.delete, index, onsuccess, onerror)
def query(self, *args):
self._data=[]
def onsuccess(event):
cursor=event.target.result
if cursor is not None:
self._data.append(cursor.value)
getattr(cursor,"continue")() # cursor.continue() is illegal
self._objectStore.openCursor(args).onsuccess=onsuccess
def fetchall(self):
yield self._data
def get(self, key, onsuccess=None, onerror=None):
self._helper(self._objectStore.get, key, onsuccess, onerror)
|
gpl-3.0
|
[
533,
6763,
10464,
26,
523,
347,
636,
826,
721,
277,
12,
4474,
17894,
489,
291,
423,
4368,
29,
4368,
819,
347,
5666,
8,
277,
12,
1566,
304,
489,
291,
423,
4368,
14,
740,
8,
1430,
9,
819,
347,
8344,
8,
277,
12,
325,
304,
489,
367,
485,
1430,
315,
291,
423,
4368,
26,
881,
485,
1430,
8,
69,
9,
199,
199,
533,
26437,
2846,
26,
523,
347,
636,
826,
721,
277,
304,
489,
340,
440,
636,
34,
5782,
8472,
4343,
1989,
63,
16821,
2846,
26,
268,
746,
4279,
480,
14398,
7042,
3181,
1133,
2291,
15235,
2846,
531,
268,
372,
2541,
291,
423,
16821,
2846,
18971,
34,
5782,
8472,
4343,
16821,
2846,
342,
489,
291,
423,
697,
29,
403,
489,
291,
423,
1023,
29,
403,
819,
347,
485,
265,
3742,
8,
277,
12,
1566,
304,
489,
291,
423,
697,
29,
1430,
14,
1375,
14,
1099,
819,
347,
1551,
8,
277,
12,
536,
12,
641,
3742,
12,
1015,
29,
17,
14,
16,
12,
22852,
29,
403,
12,
221,
1779,
641,
9375,
11368,
29,
403,
304,
489,
291,
423,
1023,
29,
1023,
489,
485,
1099,
29,
277,
423,
16821,
2846,
14,
1490,
8,
354,
12,
1015,
9,
489,
485,
3742,
29,
2390,
10464,
779,
277,
423,
265,
3742,
12,
641,
3742,
566,
489,
485,
1099,
14,
265,
3742,
3699,
3742,
14,
8935,
489,
485,
1099,
14,
265,
9375,
11368,
29,
265,
9375,
11368,
2541,
327,
692,
22852,
365,
488,
26,
489,
347,
22852,
8,
69,
304,
881,
870,
480,
265,
705,
26,
450,
83,
2689,
83,
2,
450,
221,
334,
69,
14,
466,
12,
325,
14,
1375,
14,
1099,
430,
2541,
347,
641,
17726,
8,
69,
304,
881,
870,
480,
17726,
26,
450,
83,
2689,
83,
2,
450,
221,
334,
69,
14,
466,
12,
325,
14,
1099,
430,
2541,
485,
1099,
14,
265,
705,
29,
265,
705,
489,
485,
1099,
14,
265,
17726,
29,
265,
17726,
819,
347,
6008,
8,
277,
12,
9045,
12,
818,
534,
739,
735,
489,
372,
18244,
8,
277,
423,
697,
14,
5945,
8,
8327,
12,
818,
430,
199,
199,
533,
18244,
26,
819,
347,
636,
826,
721,
277,
12,
6008,
304,
489,
291,
423,
5945,
29,
5945,
819,
347,
909,
5502,
8,
277,
12,
536,
304,
489,
372,
6935,
5502,
8,
277,
423,
5945,
14,
785,
5502,
8,
354,
430,
199,
199,
533,
6935,
5502,
26,
819,
347,
636,
826,
721,
277,
12,
909,
5502,
304,
489,
291,
423,
785,
5502,
29,
785,
5502,
489,
291,
423,
576,
9811,
819,
347,
5436,
8,
277,
12,
641,
3742,
29,
403,
12,
22852,
29,
403,
304,
489,
485,
1099,
29,
277,
423,
785,
5502,
14,
3584,
342,
2541,
340,
641,
3742,
365,
440,
488,
26,
268,
485,
1099,
14,
265,
3742,
29,
265,
3742,
2541,
340,
22852,
365,
440,
488,
26,
268,
485,
1099,
14,
265,
705,
29,
265,
705,
819,
347,
485,
3676,
8,
277,
12,
2562,
12,
909,
12,
641,
3742,
29,
403,
12,
22852,
29,
403,
304,
489,
485,
1099,
29,
1532,
8,
785,
9,
2541,
340,
641,
3742,
365,
440,
488,
26,
268,
485,
1099,
14,
265,
3742,
29,
265,
3742,
2541,
340,
22852,
365,
440,
488,
26,
268,
485,
1099,
14,
265,
705,
29,
265,
705,
819,
347,
5324,
8,
277,
12,
1559,
12,
790,
29,
403,
12,
641,
3742,
29,
403,
12,
22852,
29,
403,
304,
489,
485,
82,
275,
291,
423,
785,
5502,
14,
524,
8,
1113,
12,
790,
9,
489,
485,
82,
14,
265,
3742,
275,
641,
3742,
489,
485,
82,
14,
265,
705,
275,
22852,
819,
347,
1050,
8,
277,
12,
1559,
12,
790,
12,
641,
3742,
29,
403,
12,
22852,
29,
403,
304,
489,
485,
82,
275,
291,
423,
785,
5502,
14,
525,
8,
1113,
12,
790,
9,
489,
485,
82,
14,
265,
3742,
275,
641,
3742,
489,
485,
82,
14,
265,
705,
275,
22852,
489,
327,
277,
423,
3676,
8,
277,
423,
785,
5502,
14,
525,
12,
909,
12,
641,
3742,
12,
22852,
9,
819,
347,
3145,
8,
277,
12,
1478,
12,
641,
3742,
29,
403,
12,
22852,
29,
403,
304,
15166,
291,
423,
3676,
8,
277,
423,
785,
5502,
14,
1807,
12,
1478,
12,
641,
3742,
12,
22852,
9,
489,
523,
347,
1827,
8,
277,
12,
627,
589,
304,
489,
291,
423,
576,
9811,
489,
347,
641,
3742,
8,
1430,
304,
881,
3920,
29,
1430,
14,
1375,
14,
1099,
881,
340,
3920,
365,
440,
488,
26,
1467,
291,
423,
576,
14,
740,
8,
3937,
14,
585,
9,
1467,
2519,
8,
3937,
4589,
6958,
531,
342,
327,
3920,
14,
6958,
342,
365,
20282,
2541,
291,
423,
785,
5502,
14,
1490,
8993,
8,
589,
680,
265,
3742,
29,
265,
3742,
819,
347,
5267,
452,
8,
277,
304,
489,
1995,
291,
423,
576,
819,
347,
664,
8,
277,
12,
790,
12,
641,
3742,
29,
403,
12,
22852,
29,
403,
304,
489,
291,
423,
3676,
8,
277,
423,
785,
5502,
14,
362,
12,
790,
12,
641,
3742,
12,
22852,
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
] |
[
6763,
10464,
26,
523,
347,
636,
826,
721,
277,
12,
4474,
17894,
489,
291,
423,
4368,
29,
4368,
819,
347,
5666,
8,
277,
12,
1566,
304,
489,
291,
423,
4368,
14,
740,
8,
1430,
9,
819,
347,
8344,
8,
277,
12,
325,
304,
489,
367,
485,
1430,
315,
291,
423,
4368,
26,
881,
485,
1430,
8,
69,
9,
199,
199,
533,
26437,
2846,
26,
523,
347,
636,
826,
721,
277,
304,
489,
340,
440,
636,
34,
5782,
8472,
4343,
1989,
63,
16821,
2846,
26,
268,
746,
4279,
480,
14398,
7042,
3181,
1133,
2291,
15235,
2846,
531,
268,
372,
2541,
291,
423,
16821,
2846,
18971,
34,
5782,
8472,
4343,
16821,
2846,
342,
489,
291,
423,
697,
29,
403,
489,
291,
423,
1023,
29,
403,
819,
347,
485,
265,
3742,
8,
277,
12,
1566,
304,
489,
291,
423,
697,
29,
1430,
14,
1375,
14,
1099,
819,
347,
1551,
8,
277,
12,
536,
12,
641,
3742,
12,
1015,
29,
17,
14,
16,
12,
22852,
29,
403,
12,
221,
1779,
641,
9375,
11368,
29,
403,
304,
489,
291,
423,
1023,
29,
1023,
489,
485,
1099,
29,
277,
423,
16821,
2846,
14,
1490,
8,
354,
12,
1015,
9,
489,
485,
3742,
29,
2390,
10464,
779,
277,
423,
265,
3742,
12,
641,
3742,
566,
489,
485,
1099,
14,
265,
3742,
3699,
3742,
14,
8935,
489,
485,
1099,
14,
265,
9375,
11368,
29,
265,
9375,
11368,
2541,
327,
692,
22852,
365,
488,
26,
489,
347,
22852,
8,
69,
304,
881,
870,
480,
265,
705,
26,
450,
83,
2689,
83,
2,
450,
221,
334,
69,
14,
466,
12,
325,
14,
1375,
14,
1099,
430,
2541,
347,
641,
17726,
8,
69,
304,
881,
870,
480,
17726,
26,
450,
83,
2689,
83,
2,
450,
221,
334,
69,
14,
466,
12,
325,
14,
1099,
430,
2541,
485,
1099,
14,
265,
705,
29,
265,
705,
489,
485,
1099,
14,
265,
17726,
29,
265,
17726,
819,
347,
6008,
8,
277,
12,
9045,
12,
818,
534,
739,
735,
489,
372,
18244,
8,
277,
423,
697,
14,
5945,
8,
8327,
12,
818,
430,
199,
199,
533,
18244,
26,
819,
347,
636,
826,
721,
277,
12,
6008,
304,
489,
291,
423,
5945,
29,
5945,
819,
347,
909,
5502,
8,
277,
12,
536,
304,
489,
372,
6935,
5502,
8,
277,
423,
5945,
14,
785,
5502,
8,
354,
430,
199,
199,
533,
6935,
5502,
26,
819,
347,
636,
826,
721,
277,
12,
909,
5502,
304,
489,
291,
423,
785,
5502,
29,
785,
5502,
489,
291,
423,
576,
9811,
819,
347,
5436,
8,
277,
12,
641,
3742,
29,
403,
12,
22852,
29,
403,
304,
489,
485,
1099,
29,
277,
423,
785,
5502,
14,
3584,
342,
2541,
340,
641,
3742,
365,
440,
488,
26,
268,
485,
1099,
14,
265,
3742,
29,
265,
3742,
2541,
340,
22852,
365,
440,
488,
26,
268,
485,
1099,
14,
265,
705,
29,
265,
705,
819,
347,
485,
3676,
8,
277,
12,
2562,
12,
909,
12,
641,
3742,
29,
403,
12,
22852,
29,
403,
304,
489,
485,
1099,
29,
1532,
8,
785,
9,
2541,
340,
641,
3742,
365,
440,
488,
26,
268,
485,
1099,
14,
265,
3742,
29,
265,
3742,
2541,
340,
22852,
365,
440,
488,
26,
268,
485,
1099,
14,
265,
705,
29,
265,
705,
819,
347,
5324,
8,
277,
12,
1559,
12,
790,
29,
403,
12,
641,
3742,
29,
403,
12,
22852,
29,
403,
304,
489,
485,
82,
275,
291,
423,
785,
5502,
14,
524,
8,
1113,
12,
790,
9,
489,
485,
82,
14,
265,
3742,
275,
641,
3742,
489,
485,
82,
14,
265,
705,
275,
22852,
819,
347,
1050,
8,
277,
12,
1559,
12,
790,
12,
641,
3742,
29,
403,
12,
22852,
29,
403,
304,
489,
485,
82,
275,
291,
423,
785,
5502,
14,
525,
8,
1113,
12,
790,
9,
489,
485,
82,
14,
265,
3742,
275,
641,
3742,
489,
485,
82,
14,
265,
705,
275,
22852,
489,
327,
277,
423,
3676,
8,
277,
423,
785,
5502,
14,
525,
12,
909,
12,
641,
3742,
12,
22852,
9,
819,
347,
3145,
8,
277,
12,
1478,
12,
641,
3742,
29,
403,
12,
22852,
29,
403,
304,
15166,
291,
423,
3676,
8,
277,
423,
785,
5502,
14,
1807,
12,
1478,
12,
641,
3742,
12,
22852,
9,
489,
523,
347,
1827,
8,
277,
12,
627,
589,
304,
489,
291,
423,
576,
9811,
489,
347,
641,
3742,
8,
1430,
304,
881,
3920,
29,
1430,
14,
1375,
14,
1099,
881,
340,
3920,
365,
440,
488,
26,
1467,
291,
423,
576,
14,
740,
8,
3937,
14,
585,
9,
1467,
2519,
8,
3937,
4589,
6958,
531,
342,
327,
3920,
14,
6958,
342,
365,
20282,
2541,
291,
423,
785,
5502,
14,
1490,
8993,
8,
589,
680,
265,
3742,
29,
265,
3742,
819,
347,
5267,
452,
8,
277,
304,
489,
1995,
291,
423,
576,
819,
347,
664,
8,
277,
12,
790,
12,
641,
3742,
29,
403,
12,
22852,
29,
403,
304,
489,
291,
423,
3676,
8,
277,
423,
785,
5502,
14,
362,
12,
790,
12,
641,
3742,
12,
22852,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
40223225/2015cd_midterm
|
static/Brython3.1.1-20150328-091302/Lib/shutil.py
|
720
|
39101
|
"""Utility functions for copying and archiving files and directory trees.
XXX The functions here don't copy the resource fork or other metadata on Mac.
"""
import os
import sys
import stat
from os.path import abspath
import fnmatch
import collections
import errno
import tarfile
try:
import bz2
del bz2
_BZ2_SUPPORTED = True
except ImportError:
_BZ2_SUPPORTED = False
try:
from pwd import getpwnam
except ImportError:
getpwnam = None
try:
from grp import getgrnam
except ImportError:
getgrnam = None
__all__ = ["copyfileobj", "copyfile", "copymode", "copystat", "copy", "copy2",
"copytree", "move", "rmtree", "Error", "SpecialFileError",
"ExecError", "make_archive", "get_archive_formats",
"register_archive_format", "unregister_archive_format",
"get_unpack_formats", "register_unpack_format",
"unregister_unpack_format", "unpack_archive",
"ignore_patterns", "chown", "which"]
# disk_usage is added later, if available on the platform
class Error(EnvironmentError):
pass
class SpecialFileError(EnvironmentError):
"""Raised when trying to do a kind of operation (e.g. copying) which is
not supported on a special file (e.g. a named pipe)"""
class ExecError(EnvironmentError):
"""Raised when a command could not be executed"""
class ReadError(EnvironmentError):
"""Raised when an archive cannot be read"""
class RegistryError(Exception):
"""Raised when a registry operation with the archiving
and unpacking registeries fails"""
try:
WindowsError
except NameError:
WindowsError = None
def copyfileobj(fsrc, fdst, length=16*1024):
"""copy data from file-like object fsrc to file-like object fdst"""
while 1:
buf = fsrc.read(length)
if not buf:
break
fdst.write(buf)
def _samefile(src, dst):
# Macintosh, Unix.
if hasattr(os.path, 'samefile'):
try:
return os.path.samefile(src, dst)
except OSError:
return False
# All other platforms: check for same pathname.
return (os.path.normcase(os.path.abspath(src)) ==
os.path.normcase(os.path.abspath(dst)))
def copyfile(src, dst, *, follow_symlinks=True):
"""Copy data from src to dst.
If follow_symlinks is not set and src is a symbolic link, a new
symlink will be created instead of copying the file it points to.
"""
if _samefile(src, dst):
raise Error("`%s` and `%s` are the same file" % (src, dst))
for fn in [src, dst]:
try:
st = os.stat(fn)
except OSError:
# File most likely does not exist
pass
else:
# XXX What about other special files? (sockets, devices...)
if stat.S_ISFIFO(st.st_mode):
raise SpecialFileError("`%s` is a named pipe" % fn)
if not follow_symlinks and os.path.islink(src):
os.symlink(os.readlink(src), dst)
else:
with open(src, 'rb') as fsrc:
with open(dst, 'wb') as fdst:
copyfileobj(fsrc, fdst)
return dst
def copymode(src, dst, *, follow_symlinks=True):
"""Copy mode bits from src to dst.
If follow_symlinks is not set, symlinks aren't followed if and only
if both `src` and `dst` are symlinks. If `lchmod` isn't available
(e.g. Linux) this method does nothing.
"""
if not follow_symlinks and os.path.islink(src) and os.path.islink(dst):
if hasattr(os, 'lchmod'):
stat_func, chmod_func = os.lstat, os.lchmod
else:
return
elif hasattr(os, 'chmod'):
stat_func, chmod_func = os.stat, os.chmod
else:
return
st = stat_func(src)
chmod_func(dst, stat.S_IMODE(st.st_mode))
if hasattr(os, 'listxattr'):
def _copyxattr(src, dst, *, follow_symlinks=True):
"""Copy extended filesystem attributes from `src` to `dst`.
Overwrite existing attributes.
If `follow_symlinks` is false, symlinks won't be followed.
"""
try:
names = os.listxattr(src, follow_symlinks=follow_symlinks)
except OSError as e:
if e.errno not in (errno.ENOTSUP, errno.ENODATA):
raise
return
for name in names:
try:
value = os.getxattr(src, name, follow_symlinks=follow_symlinks)
os.setxattr(dst, name, value, follow_symlinks=follow_symlinks)
except OSError as e:
if e.errno not in (errno.EPERM, errno.ENOTSUP, errno.ENODATA):
raise
else:
def _copyxattr(*args, **kwargs):
pass
def copystat(src, dst, *, follow_symlinks=True):
"""Copy all stat info (mode bits, atime, mtime, flags) from src to dst.
If the optional flag `follow_symlinks` is not set, symlinks aren't followed if and
only if both `src` and `dst` are symlinks.
"""
def _nop(*args, ns=None, follow_symlinks=None):
pass
# follow symlinks (aka don't not follow symlinks)
follow = follow_symlinks or not (os.path.islink(src) and os.path.islink(dst))
if follow:
# use the real function if it exists
def lookup(name):
return getattr(os, name, _nop)
else:
# use the real function only if it exists
# *and* it supports follow_symlinks
def lookup(name):
fn = getattr(os, name, _nop)
if fn in os.supports_follow_symlinks:
return fn
return _nop
st = lookup("stat")(src, follow_symlinks=follow)
mode = stat.S_IMODE(st.st_mode)
lookup("utime")(dst, ns=(st.st_atime_ns, st.st_mtime_ns),
follow_symlinks=follow)
try:
lookup("chmod")(dst, mode, follow_symlinks=follow)
except NotImplementedError:
# if we got a NotImplementedError, it's because
# * follow_symlinks=False,
# * lchown() is unavailable, and
# * either
# * fchownat() is unavailable or
# * fchownat() doesn't implement AT_SYMLINK_NOFOLLOW.
# (it returned ENOSUP.)
# therefore we're out of options--we simply cannot chown the
# symlink. give up, suppress the error.
# (which is what shutil always did in this circumstance.)
pass
if hasattr(st, 'st_flags'):
try:
lookup("chflags")(dst, st.st_flags, follow_symlinks=follow)
except OSError as why:
for err in 'EOPNOTSUPP', 'ENOTSUP':
if hasattr(errno, err) and why.errno == getattr(errno, err):
break
else:
raise
_copyxattr(src, dst, follow_symlinks=follow)
def copy(src, dst, *, follow_symlinks=True):
"""Copy data and mode bits ("cp src dst"). Return the file's destination.
The destination may be a directory.
If follow_symlinks is false, symlinks won't be followed. This
resembles GNU's "cp -P src dst".
"""
if os.path.isdir(dst):
dst = os.path.join(dst, os.path.basename(src))
copyfile(src, dst, follow_symlinks=follow_symlinks)
copymode(src, dst, follow_symlinks=follow_symlinks)
return dst
def copy2(src, dst, *, follow_symlinks=True):
"""Copy data and all stat info ("cp -p src dst"). Return the file's
destination."
The destination may be a directory.
If follow_symlinks is false, symlinks won't be followed. This
resembles GNU's "cp -P src dst".
"""
if os.path.isdir(dst):
dst = os.path.join(dst, os.path.basename(src))
copyfile(src, dst, follow_symlinks=follow_symlinks)
copystat(src, dst, follow_symlinks=follow_symlinks)
return dst
def ignore_patterns(*patterns):
"""Function that can be used as copytree() ignore parameter.
Patterns is a sequence of glob-style patterns
that are used to exclude files"""
def _ignore_patterns(path, names):
ignored_names = []
for pattern in patterns:
ignored_names.extend(fnmatch.filter(names, pattern))
return set(ignored_names)
return _ignore_patterns
def copytree(src, dst, symlinks=False, ignore=None, copy_function=copy2,
ignore_dangling_symlinks=False):
"""Recursively copy a directory tree.
The destination directory must not already exist.
If exception(s) occur, an Error is raised with a list of reasons.
If the optional symlinks flag is true, symbolic links in the
source tree result in symbolic links in the destination tree; if
it is false, the contents of the files pointed to by symbolic
links are copied. If the file pointed by the symlink doesn't
exist, an exception will be added in the list of errors raised in
an Error exception at the end of the copy process.
You can set the optional ignore_dangling_symlinks flag to true if you
want to silence this exception. Notice that this has no effect on
platforms that don't support os.symlink.
The optional ignore argument is a callable. If given, it
is called with the `src` parameter, which is the directory
being visited by copytree(), and `names` which is the list of
`src` contents, as returned by os.listdir():
callable(src, names) -> ignored_names
Since copytree() is called recursively, the callable will be
called once for each directory that is copied. It returns a
list of names relative to the `src` directory that should
not be copied.
The optional copy_function argument is a callable that will be used
to copy each file. It will be called with the source path and the
destination path as arguments. By default, copy2() is used, but any
function that supports the same signature (like copy()) can be used.
"""
names = os.listdir(src)
if ignore is not None:
ignored_names = ignore(src, names)
else:
ignored_names = set()
os.makedirs(dst)
errors = []
for name in names:
if name in ignored_names:
continue
srcname = os.path.join(src, name)
dstname = os.path.join(dst, name)
try:
if os.path.islink(srcname):
linkto = os.readlink(srcname)
if symlinks:
# We can't just leave it to `copy_function` because legacy
# code with a custom `copy_function` may rely on copytree
# doing the right thing.
os.symlink(linkto, dstname)
copystat(srcname, dstname, follow_symlinks=not symlinks)
else:
# ignore dangling symlink if the flag is on
if not os.path.exists(linkto) and ignore_dangling_symlinks:
continue
# otherwise let the copy occurs. copy2 will raise an error
copy_function(srcname, dstname)
elif os.path.isdir(srcname):
copytree(srcname, dstname, symlinks, ignore, copy_function)
else:
# Will raise a SpecialFileError for unsupported file types
copy_function(srcname, dstname)
# catch the Error from the recursive copytree so that we can
# continue with other files
except Error as err:
errors.extend(err.args[0])
except EnvironmentError as why:
errors.append((srcname, dstname, str(why)))
try:
copystat(src, dst)
except OSError as why:
if WindowsError is not None and isinstance(why, WindowsError):
# Copying file access times may fail on Windows
pass
else:
errors.append((src, dst, str(why)))
if errors:
raise Error(errors)
return dst
# version vulnerable to race conditions
def _rmtree_unsafe(path, onerror):
try:
if os.path.islink(path):
# symlinks to directories are forbidden, see bug #1669
raise OSError("Cannot call rmtree on a symbolic link")
except OSError:
onerror(os.path.islink, path, sys.exc_info())
# can't continue even if onerror hook returns
return
names = []
try:
names = os.listdir(path)
except os.error:
onerror(os.listdir, path, sys.exc_info())
for name in names:
fullname = os.path.join(path, name)
try:
mode = os.lstat(fullname).st_mode
except os.error:
mode = 0
if stat.S_ISDIR(mode):
_rmtree_unsafe(fullname, onerror)
else:
try:
os.unlink(fullname)
except os.error:
onerror(os.unlink, fullname, sys.exc_info())
try:
os.rmdir(path)
except os.error:
onerror(os.rmdir, path, sys.exc_info())
# Version using fd-based APIs to protect against races
def _rmtree_safe_fd(topfd, path, onerror):
names = []
try:
names = os.listdir(topfd)
except OSError as err:
err.filename = path
onerror(os.listdir, path, sys.exc_info())
for name in names:
fullname = os.path.join(path, name)
try:
orig_st = os.stat(name, dir_fd=topfd, follow_symlinks=False)
mode = orig_st.st_mode
except OSError:
mode = 0
if stat.S_ISDIR(mode):
try:
dirfd = os.open(name, os.O_RDONLY, dir_fd=topfd)
except OSError:
onerror(os.open, fullname, sys.exc_info())
else:
try:
if os.path.samestat(orig_st, os.fstat(dirfd)):
_rmtree_safe_fd(dirfd, fullname, onerror)
try:
os.rmdir(name, dir_fd=topfd)
except OSError:
onerror(os.rmdir, fullname, sys.exc_info())
else:
try:
# This can only happen if someone replaces
# a directory with a symlink after the call to
# stat.S_ISDIR above.
raise OSError("Cannot call rmtree on a symbolic "
"link")
except OSError:
onerror(os.path.islink, fullname, sys.exc_info())
finally:
os.close(dirfd)
else:
try:
os.unlink(name, dir_fd=topfd)
except OSError:
onerror(os.unlink, fullname, sys.exc_info())
_use_fd_functions = ({os.open, os.stat, os.unlink, os.rmdir} <=
os.supports_dir_fd and
os.listdir in os.supports_fd and
os.stat in os.supports_follow_symlinks)
def rmtree(path, ignore_errors=False, onerror=None):
"""Recursively delete a directory tree.
If ignore_errors is set, errors are ignored; otherwise, if onerror
is set, it is called to handle the error with arguments (func,
path, exc_info) where func is platform and implementation dependent;
path is the argument to that function that caused it to fail; and
exc_info is a tuple returned by sys.exc_info(). If ignore_errors
is false and onerror is None, an exception is raised.
"""
if ignore_errors:
def onerror(*args):
pass
elif onerror is None:
def onerror(*args):
raise
if _use_fd_functions:
# While the unsafe rmtree works fine on bytes, the fd based does not.
if isinstance(path, bytes):
path = os.fsdecode(path)
# Note: To guard against symlink races, we use the standard
# lstat()/open()/fstat() trick.
try:
orig_st = os.lstat(path)
except Exception:
onerror(os.lstat, path, sys.exc_info())
return
try:
fd = os.open(path, os.O_RDONLY)
except Exception:
onerror(os.lstat, path, sys.exc_info())
return
try:
if os.path.samestat(orig_st, os.fstat(fd)):
_rmtree_safe_fd(fd, path, onerror)
try:
os.rmdir(path)
except os.error:
onerror(os.rmdir, path, sys.exc_info())
else:
try:
# symlinks to directories are forbidden, see bug #1669
raise OSError("Cannot call rmtree on a symbolic link")
except OSError:
onerror(os.path.islink, path, sys.exc_info())
finally:
os.close(fd)
else:
return _rmtree_unsafe(path, onerror)
# Allow introspection of whether or not the hardening against symlink
# attacks is supported on the current platform
rmtree.avoids_symlink_attacks = _use_fd_functions
def _basename(path):
# A basename() variant which first strips the trailing slash, if present.
# Thus we always get the last component of the path, even for directories.
return os.path.basename(path.rstrip(os.path.sep))
def move(src, dst):
"""Recursively move a file or directory to another location. This is
similar to the Unix "mv" command. Return the file or directory's
destination.
If the destination is a directory or a symlink to a directory, the source
is moved inside the directory. The destination path must not already
exist.
If the destination already exists but is not a directory, it may be
overwritten depending on os.rename() semantics.
If the destination is on our current filesystem, then rename() is used.
Otherwise, src is copied to the destination and then removed. Symlinks are
recreated under the new name if os.rename() fails because of cross
filesystem renames.
A lot more could be done here... A look at a mv.c shows a lot of
the issues this implementation glosses over.
"""
real_dst = dst
if os.path.isdir(dst):
if _samefile(src, dst):
# We might be on a case insensitive filesystem,
# perform the rename anyway.
os.rename(src, dst)
return
real_dst = os.path.join(dst, _basename(src))
if os.path.exists(real_dst):
raise Error("Destination path '%s' already exists" % real_dst)
try:
os.rename(src, real_dst)
except OSError:
if os.path.islink(src):
linkto = os.readlink(src)
os.symlink(linkto, real_dst)
os.unlink(src)
elif os.path.isdir(src):
if _destinsrc(src, dst):
raise Error("Cannot move a directory '%s' into itself '%s'." % (src, dst))
copytree(src, real_dst, symlinks=True)
rmtree(src)
else:
copy2(src, real_dst)
os.unlink(src)
return real_dst
def _destinsrc(src, dst):
src = abspath(src)
dst = abspath(dst)
if not src.endswith(os.path.sep):
src += os.path.sep
if not dst.endswith(os.path.sep):
dst += os.path.sep
return dst.startswith(src)
def _get_gid(name):
"""Returns a gid, given a group name."""
if getgrnam is None or name is None:
return None
try:
result = getgrnam(name)
except KeyError:
result = None
if result is not None:
return result[2]
return None
def _get_uid(name):
"""Returns an uid, given a user name."""
if getpwnam is None or name is None:
return None
try:
result = getpwnam(name)
except KeyError:
result = None
if result is not None:
return result[2]
return None
def _make_tarball(base_name, base_dir, compress="gzip", verbose=0, dry_run=0,
owner=None, group=None, logger=None):
"""Create a (possibly compressed) tar file from all the files under
'base_dir'.
'compress' must be "gzip" (the default), "bzip2", or None.
'owner' and 'group' can be used to define an owner and a group for the
archive that is being built. If not provided, the current owner and group
will be used.
The output tar file will be named 'base_name' + ".tar", possibly plus
the appropriate compression extension (".gz", or ".bz2").
Returns the output filename.
"""
tar_compression = {'gzip': 'gz', None: ''}
compress_ext = {'gzip': '.gz'}
if _BZ2_SUPPORTED:
tar_compression['bzip2'] = 'bz2'
compress_ext['bzip2'] = '.bz2'
# flags for compression program, each element of list will be an argument
if compress is not None and compress not in compress_ext:
raise ValueError("bad value for 'compress', or compression format not "
"supported : {0}".format(compress))
archive_name = base_name + '.tar' + compress_ext.get(compress, '')
archive_dir = os.path.dirname(archive_name)
if not os.path.exists(archive_dir):
if logger is not None:
logger.info("creating %s", archive_dir)
if not dry_run:
os.makedirs(archive_dir)
# creating the tarball
if logger is not None:
logger.info('Creating tar archive')
uid = _get_uid(owner)
gid = _get_gid(group)
def _set_uid_gid(tarinfo):
if gid is not None:
tarinfo.gid = gid
tarinfo.gname = group
if uid is not None:
tarinfo.uid = uid
tarinfo.uname = owner
return tarinfo
if not dry_run:
tar = tarfile.open(archive_name, 'w|%s' % tar_compression[compress])
try:
tar.add(base_dir, filter=_set_uid_gid)
finally:
tar.close()
return archive_name
def _call_external_zip(base_dir, zip_filename, verbose=False, dry_run=False):
# XXX see if we want to keep an external call here
if verbose:
zipoptions = "-r"
else:
zipoptions = "-rq"
from distutils.errors import DistutilsExecError
from distutils.spawn import spawn
try:
spawn(["zip", zipoptions, zip_filename, base_dir], dry_run=dry_run)
except DistutilsExecError:
# XXX really should distinguish between "couldn't find
# external 'zip' command" and "zip failed".
raise ExecError("unable to create zip file '%s': "
"could neither import the 'zipfile' module nor "
"find a standalone zip utility") % zip_filename
def _make_zipfile(base_name, base_dir, verbose=0, dry_run=0, logger=None):
"""Create a zip file from all the files under 'base_dir'.
The output zip file will be named 'base_name' + ".zip". Uses either the
"zipfile" Python module (if available) or the InfoZIP "zip" utility
(if installed and found on the default search path). If neither tool is
available, raises ExecError. Returns the name of the output zip
file.
"""
zip_filename = base_name + ".zip"
archive_dir = os.path.dirname(base_name)
if not os.path.exists(archive_dir):
if logger is not None:
logger.info("creating %s", archive_dir)
if not dry_run:
os.makedirs(archive_dir)
# If zipfile module is not available, try spawning an external 'zip'
# command.
try:
import zipfile
except ImportError:
zipfile = None
if zipfile is None:
_call_external_zip(base_dir, zip_filename, verbose, dry_run)
else:
if logger is not None:
logger.info("creating '%s' and adding '%s' to it",
zip_filename, base_dir)
if not dry_run:
zip = zipfile.ZipFile(zip_filename, "w",
compression=zipfile.ZIP_DEFLATED)
for dirpath, dirnames, filenames in os.walk(base_dir):
for name in filenames:
path = os.path.normpath(os.path.join(dirpath, name))
if os.path.isfile(path):
zip.write(path, path)
if logger is not None:
logger.info("adding '%s'", path)
zip.close()
return zip_filename
_ARCHIVE_FORMATS = {
'gztar': (_make_tarball, [('compress', 'gzip')], "gzip'ed tar-file"),
'tar': (_make_tarball, [('compress', None)], "uncompressed tar file"),
'zip': (_make_zipfile, [], "ZIP file")
}
if _BZ2_SUPPORTED:
_ARCHIVE_FORMATS['bztar'] = (_make_tarball, [('compress', 'bzip2')],
"bzip2'ed tar-file")
def get_archive_formats():
"""Returns a list of supported formats for archiving and unarchiving.
Each element of the returned sequence is a tuple (name, description)
"""
formats = [(name, registry[2]) for name, registry in
_ARCHIVE_FORMATS.items()]
formats.sort()
return formats
def register_archive_format(name, function, extra_args=None, description=''):
"""Registers an archive format.
name is the name of the format. function is the callable that will be
used to create archives. If provided, extra_args is a sequence of
(name, value) tuples that will be passed as arguments to the callable.
description can be provided to describe the format, and will be returned
by the get_archive_formats() function.
"""
if extra_args is None:
extra_args = []
if not callable(function):
raise TypeError('The %s object is not callable' % function)
if not isinstance(extra_args, (tuple, list)):
raise TypeError('extra_args needs to be a sequence')
for element in extra_args:
if not isinstance(element, (tuple, list)) or len(element) !=2:
raise TypeError('extra_args elements are : (arg_name, value)')
_ARCHIVE_FORMATS[name] = (function, extra_args, description)
def unregister_archive_format(name):
del _ARCHIVE_FORMATS[name]
def make_archive(base_name, format, root_dir=None, base_dir=None, verbose=0,
dry_run=0, owner=None, group=None, logger=None):
"""Create an archive file (eg. zip or tar).
'base_name' is the name of the file to create, minus any format-specific
extension; 'format' is the archive format: one of "zip", "tar", "bztar"
or "gztar".
'root_dir' is a directory that will be the root directory of the
archive; ie. we typically chdir into 'root_dir' before creating the
archive. 'base_dir' is the directory where we start archiving from;
ie. 'base_dir' will be the common prefix of all files and
directories in the archive. 'root_dir' and 'base_dir' both default
to the current directory. Returns the name of the archive file.
'owner' and 'group' are used when creating a tar archive. By default,
uses the current owner and group.
"""
save_cwd = os.getcwd()
if root_dir is not None:
if logger is not None:
logger.debug("changing into '%s'", root_dir)
base_name = os.path.abspath(base_name)
if not dry_run:
os.chdir(root_dir)
if base_dir is None:
base_dir = os.curdir
kwargs = {'dry_run': dry_run, 'logger': logger}
try:
format_info = _ARCHIVE_FORMATS[format]
except KeyError:
raise ValueError("unknown archive format '%s'" % format)
func = format_info[0]
for arg, val in format_info[1]:
kwargs[arg] = val
if format != 'zip':
kwargs['owner'] = owner
kwargs['group'] = group
try:
filename = func(base_name, base_dir, **kwargs)
finally:
if root_dir is not None:
if logger is not None:
logger.debug("changing back to '%s'", save_cwd)
os.chdir(save_cwd)
return filename
def get_unpack_formats():
"""Returns a list of supported formats for unpacking.
Each element of the returned sequence is a tuple
(name, extensions, description)
"""
formats = [(name, info[0], info[3]) for name, info in
_UNPACK_FORMATS.items()]
formats.sort()
return formats
def _check_unpack_options(extensions, function, extra_args):
"""Checks what gets registered as an unpacker."""
# first make sure no other unpacker is registered for this extension
existing_extensions = {}
for name, info in _UNPACK_FORMATS.items():
for ext in info[0]:
existing_extensions[ext] = name
for extension in extensions:
if extension in existing_extensions:
msg = '%s is already registered for "%s"'
raise RegistryError(msg % (extension,
existing_extensions[extension]))
if not callable(function):
raise TypeError('The registered function must be a callable')
def register_unpack_format(name, extensions, function, extra_args=None,
description=''):
"""Registers an unpack format.
`name` is the name of the format. `extensions` is a list of extensions
corresponding to the format.
`function` is the callable that will be
used to unpack archives. The callable will receive archives to unpack.
If it's unable to handle an archive, it needs to raise a ReadError
exception.
If provided, `extra_args` is a sequence of
(name, value) tuples that will be passed as arguments to the callable.
description can be provided to describe the format, and will be returned
by the get_unpack_formats() function.
"""
if extra_args is None:
extra_args = []
_check_unpack_options(extensions, function, extra_args)
_UNPACK_FORMATS[name] = extensions, function, extra_args, description
def unregister_unpack_format(name):
"""Removes the pack format from the registery."""
del _UNPACK_FORMATS[name]
def _ensure_directory(path):
"""Ensure that the parent directory of `path` exists"""
dirname = os.path.dirname(path)
if not os.path.isdir(dirname):
os.makedirs(dirname)
def _unpack_zipfile(filename, extract_dir):
"""Unpack zip `filename` to `extract_dir`
"""
try:
import zipfile
except ImportError:
raise ReadError('zlib not supported, cannot unpack this archive.')
if not zipfile.is_zipfile(filename):
raise ReadError("%s is not a zip file" % filename)
zip = zipfile.ZipFile(filename)
try:
for info in zip.infolist():
name = info.filename
# don't extract absolute paths or ones with .. in them
if name.startswith('/') or '..' in name:
continue
target = os.path.join(extract_dir, *name.split('/'))
if not target:
continue
_ensure_directory(target)
if not name.endswith('/'):
# file
data = zip.read(info.filename)
f = open(target, 'wb')
try:
f.write(data)
finally:
f.close()
del data
finally:
zip.close()
def _unpack_tarfile(filename, extract_dir):
"""Unpack tar/tar.gz/tar.bz2 `filename` to `extract_dir`
"""
try:
tarobj = tarfile.open(filename)
except tarfile.TarError:
raise ReadError(
"%s is not a compressed or uncompressed tar file" % filename)
try:
tarobj.extractall(extract_dir)
finally:
tarobj.close()
_UNPACK_FORMATS = {
'gztar': (['.tar.gz', '.tgz'], _unpack_tarfile, [], "gzip'ed tar-file"),
'tar': (['.tar'], _unpack_tarfile, [], "uncompressed tar file"),
'zip': (['.zip'], _unpack_zipfile, [], "ZIP file")
}
if _BZ2_SUPPORTED:
_UNPACK_FORMATS['bztar'] = (['.bz2'], _unpack_tarfile, [],
"bzip2'ed tar-file")
def _find_unpack_format(filename):
for name, info in _UNPACK_FORMATS.items():
for extension in info[0]:
if filename.endswith(extension):
return name
return None
def unpack_archive(filename, extract_dir=None, format=None):
"""Unpack an archive.
`filename` is the name of the archive.
`extract_dir` is the name of the target directory, where the archive
is unpacked. If not provided, the current working directory is used.
`format` is the archive format: one of "zip", "tar", or "gztar". Or any
other registered format. If not provided, unpack_archive will use the
filename extension and see if an unpacker was registered for that
extension.
In case none is found, a ValueError is raised.
"""
if extract_dir is None:
extract_dir = os.getcwd()
if format is not None:
try:
format_info = _UNPACK_FORMATS[format]
except KeyError:
raise ValueError("Unknown unpack format '{0}'".format(format))
func = format_info[1]
func(filename, extract_dir, **dict(format_info[2]))
else:
# we need to look at the registered unpackers supported extensions
format = _find_unpack_format(filename)
if format is None:
raise ReadError("Unknown archive format '{0}'".format(filename))
func = _UNPACK_FORMATS[format][1]
kwargs = dict(_UNPACK_FORMATS[format][2])
func(filename, extract_dir, **kwargs)
if hasattr(os, 'statvfs'):
__all__.append('disk_usage')
_ntuple_diskusage = collections.namedtuple('usage', 'total used free')
def disk_usage(path):
"""Return disk usage statistics about the given path.
Returned value is a named tuple with attributes 'total', 'used' and
'free', which are the amount of total, used and free space, in bytes.
"""
st = os.statvfs(path)
free = st.f_bavail * st.f_frsize
total = st.f_blocks * st.f_frsize
used = (st.f_blocks - st.f_bfree) * st.f_frsize
return _ntuple_diskusage(total, used, free)
elif os.name == 'nt':
import nt
__all__.append('disk_usage')
_ntuple_diskusage = collections.namedtuple('usage', 'total used free')
def disk_usage(path):
"""Return disk usage statistics about the given path.
Returned values is a named tuple with attributes 'total', 'used' and
'free', which are the amount of total, used and free space, in bytes.
"""
total, free = nt._getdiskusage(path)
used = total - free
return _ntuple_diskusage(total, used, free)
def chown(path, user=None, group=None):
"""Change owner user and group of the given path.
user and group can be the uid/gid or the user/group names, and in that case,
they are converted to their respective uid/gid.
"""
if user is None and group is None:
raise ValueError("user and/or group must be set")
_user = user
_group = group
# -1 means don't change it
if user is None:
_user = -1
# user can either be an int (the uid) or a string (the system username)
elif isinstance(user, str):
_user = _get_uid(user)
if _user is None:
raise LookupError("no such user: {!r}".format(user))
if group is None:
_group = -1
elif not isinstance(group, int):
_group = _get_gid(group)
if _group is None:
raise LookupError("no such group: {!r}".format(group))
os.chown(path, _user, _group)
def get_terminal_size(fallback=(80, 24)):
"""Get the size of the terminal window.
For each of the two dimensions, the environment variable, COLUMNS
and LINES respectively, is checked. If the variable is defined and
the value is a positive integer, it is used.
When COLUMNS or LINES is not defined, which is the common case,
the terminal connected to sys.__stdout__ is queried
by invoking os.get_terminal_size.
If the terminal size cannot be successfully queried, either because
the system doesn't support querying, or because we are not
connected to a terminal, the value given in fallback parameter
is used. Fallback defaults to (80, 24) which is the default
size used by many terminal emulators.
The value returned is a named tuple of type os.terminal_size.
"""
# columns, lines are the working values
try:
columns = int(os.environ['COLUMNS'])
except (KeyError, ValueError):
columns = 0
try:
lines = int(os.environ['LINES'])
except (KeyError, ValueError):
lines = 0
# only query if necessary
if columns <= 0 or lines <= 0:
try:
size = os.get_terminal_size(sys.__stdout__.fileno())
except (NameError, OSError):
size = os.terminal_size(fallback)
if columns <= 0:
columns = size.columns
if lines <= 0:
lines = size.lines
return os.terminal_size((columns, lines))
def which(cmd, mode=os.F_OK | os.X_OK, path=None):
"""Given a command, mode, and a PATH string, return the path which
conforms to the given mode on the PATH, or None if there is no such
file.
`mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
of os.environ.get("PATH"), or can be overridden with a custom search
path.
"""
# Check that a given file can be accessed with the correct mode.
# Additionally check that `file` is not a directory, as on Windows
# directories pass the os.access check.
def _access_check(fn, mode):
return (os.path.exists(fn) and os.access(fn, mode)
and not os.path.isdir(fn))
# If we're given a path with a directory part, look it up directly rather
# than referring to PATH directories. This includes checking relative to the
# current directory, e.g. ./script
if os.path.dirname(cmd):
if _access_check(cmd, mode):
return cmd
return None
if path is None:
path = os.environ.get("PATH", os.defpath)
if not path:
return None
path = path.split(os.pathsep)
if sys.platform == "win32":
# The current directory takes precedence on Windows.
if not os.curdir in path:
path.insert(0, os.curdir)
# PATHEXT is necessary to check on Windows.
pathext = os.environ.get("PATHEXT", "").split(os.pathsep)
# See if the given file matches any of the expected path extensions.
# This will allow us to short circuit when given "python.exe".
# If it does match, only test that one, otherwise we have to try
# others.
if any(cmd.lower().endswith(ext.lower()) for ext in pathext):
files = [cmd]
else:
files = [cmd + ext for ext in pathext]
else:
# On other platforms you don't have things like PATHEXT to tell you
# what file suffixes are executable, so just pass on cmd as-is.
files = [cmd]
seen = set()
for dir in path:
normdir = os.path.normcase(dir)
if not normdir in seen:
seen.add(normdir)
for thefile in files:
name = os.path.join(dir, thefile)
if _access_check(name, mode):
return name
return None
|
gpl-3.0
|
[
624,
17505,
3423,
367,
16743,
436,
3819,
12616,
1584,
436,
2082,
14416,
14,
199,
199,
13933,
710,
3423,
2348,
2793,
1133,
1331,
314,
2073,
14926,
503,
1163,
3341,
641,
10444,
14,
199,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
646,
5672,
199,
504,
747,
14,
515,
492,
19529,
199,
646,
15951,
199,
646,
5055,
199,
646,
7554,
199,
646,
13608,
199,
199,
893,
26,
272,
492,
15055,
18,
272,
2150,
15055,
18,
272,
485,
21338,
18,
63,
15925,
275,
715,
199,
2590,
3545,
26,
272,
485,
21338,
18,
63,
15925,
275,
756,
199,
199,
893,
26,
272,
687,
14374,
492,
664,
80,
3501,
455,
199,
2590,
3545,
26,
272,
664,
80,
3501,
455,
275,
488,
199,
199,
893,
26,
272,
687,
18598,
492,
664,
2587,
17811,
199,
2590,
3545,
26,
272,
664,
2587,
17811,
275,
488,
199,
199,
363,
452,
363,
275,
2097,
1574,
9234,
401,
298,
21997,
401,
298,
1574,
632,
401,
298,
1574,
3736,
401,
298,
1574,
401,
298,
1574,
18,
401,
1779,
298,
29296,
401,
298,
1185,
401,
298,
9242,
401,
298,
547,
401,
298,
12246,
25212,
401,
1779,
298,
4858,
547,
401,
298,
1875,
63,
6404,
401,
298,
362,
63,
6404,
63,
6321,
401,
1779,
298,
2683,
63,
6404,
63,
908,
401,
298,
18408,
63,
6404,
63,
908,
401,
1779,
298,
362,
63,
5301,
63,
6321,
401,
298,
2683,
63,
5301,
63,
908,
401,
1779,
298,
18408,
63,
5301,
63,
908,
401,
298,
5301,
63,
6404,
401,
1779,
298,
4247,
63,
7435,
401,
298,
20933,
401,
298,
6777,
937,
1779,
327,
4543,
63,
3807,
365,
3483,
2945,
12,
340,
2808,
641,
314,
4298,
199,
199,
533,
4520,
8,
8263,
547,
304,
272,
986,
199,
199,
533,
12568,
25212,
8,
8263,
547,
304,
272,
408,
16894,
1380,
9936,
370,
886,
282,
4928,
402,
3439,
334,
69,
14,
71,
14,
16743,
9,
1314,
365,
272,
440,
3748,
641,
282,
4539,
570,
334,
69,
14,
71,
14,
282,
4310,
5200,
9471,
199,
199,
533,
9434,
547,
8,
8263,
547,
304,
272,
408,
16894,
1380,
282,
1414,
4293,
440,
506,
7934,
624,
199,
199,
533,
5574,
547,
8,
8263,
547,
304,
272,
408,
16894,
1380,
376,
6359,
3913,
506,
1586,
624,
199,
199,
533,
20738,
547,
8,
1726,
304,
272,
408,
16894,
1380,
282,
7086,
3439,
543,
314,
3819,
12616,
272,
436,
7787,
316,
1295,
29729,
1996,
6918,
624,
421,
199,
893,
26,
272,
23950,
199,
2590,
12746,
26,
272,
23950,
275,
488,
199,
199,
318,
1331,
9234,
8,
70,
2164,
12,
289,
5119,
12,
2582,
29,
975,
10,
7727,
304,
272,
408,
1574,
666,
687,
570,
13,
2930,
909,
289,
2164,
370,
570,
13,
2930,
909,
289,
5119,
624,
272,
1830,
413,
26,
267,
4123,
275,
289,
2164,
14,
739,
8,
1267,
9,
267,
340,
440,
4123,
26,
288,
2059,
267,
289,
5119,
14,
952,
8,
1436,
9,
199,
199,
318,
485,
7191,
493,
8,
2164,
12,
5042,
304,
272,
327,
10444,
9924,
609,
12,
13074,
14,
272,
340,
2688,
8,
736,
14,
515,
12,
283,
7191,
493,
735,
267,
862,
26,
288,
372,
747,
14,
515,
14,
7191,
493,
8,
2164,
12,
5042,
9,
267,
871,
6440,
26,
288,
372,
756,
339,
327,
2900,
1163,
10677,
26,
1104,
367,
2011,
11776,
14,
272,
372,
334,
736,
14,
515,
14,
21288,
8,
736,
14,
515,
14,
4832,
8,
2164,
430,
508,
288,
747,
14,
515,
14,
21288,
8,
736,
14,
515,
14,
4832,
8,
5119,
1724,
199,
199,
318,
1331,
493,
8,
2164,
12,
5042,
12,
9889,
2035,
63,
19522,
29,
549,
304,
272,
408,
5116,
666,
687,
2928,
370,
5042,
14,
339,
982,
2035,
63,
19522,
365,
440,
663,
436,
2928,
365,
282,
13673,
2142,
12,
282,
892,
272,
15296,
911,
506,
2737,
3140,
402,
16743,
314,
570,
652,
4501,
370,
14,
339,
408,
272,
340,
485,
7191,
493,
8,
2164,
12,
5042,
304,
267,
746,
4520,
32684,
5,
83,
64,
436,
18633,
83,
64,
787,
314,
2011,
570,
2,
450,
334,
2164,
12,
5042,
430,
339,
367,
4325,
315,
359,
2164,
12,
5042,
2189,
267,
862,
26,
288,
410,
275,
747,
14,
3736,
8,
2324,
9,
267,
871,
6440,
26,
288,
327,
3814,
4750,
12060,
1630,
440,
2187,
288,
986,
267,
587,
26,
288,
327,
5787,
14791,
3595,
1163,
4539,
1584,
31,
334,
20517,
12,
7256,
11965,
288,
340,
5672,
14,
51,
63,
1311,
20925,
8,
270,
14,
270,
63,
632,
304,
355,
746,
12568,
25212,
32684,
5,
83,
64,
365,
282,
4310,
5200,
2,
450,
4325,
9,
339,
340,
440,
2035,
63,
19522,
436,
747,
14,
515,
14,
20719,
8,
2164,
304,
267,
747,
14,
13380,
8,
736,
14,
31654,
8,
2164,
395,
5042,
9,
272,
587,
26,
267,
543,
1551,
8,
2164,
12,
283,
4848,
358,
465,
289,
2164,
26,
288,
543,
1551,
8,
5119,
12,
283,
6603,
358,
465,
289,
5119,
26,
355,
1331,
9234,
8,
70,
2164,
12,
289,
5119,
9,
272,
372,
5042,
199,
199,
318,
1331,
632,
8,
2164,
12,
5042,
12,
9889,
2035,
63,
19522,
29,
549,
304,
272,
408,
5116,
818,
5821,
687,
2928,
370,
5042,
14,
339,
982,
2035,
63,
19522,
365,
440,
663,
12,
19891,
10621,
1133,
9437,
340,
436,
1454,
272,
340,
3865,
658,
2164,
64,
436,
658,
5119,
64,
787,
19891,
14,
221,
982,
658,
76,
11693,
64,
5712,
1133,
2808,
272,
334,
69,
14,
71,
14,
10130,
9,
642,
1083,
1630,
6548,
14,
339,
408,
272,
340,
440,
2035,
63,
19522,
436,
747,
14,
515,
14,
20719,
8,
2164,
9,
436,
747,
14,
515,
14,
20719,
8,
5119,
304,
267,
340,
2688,
8,
736,
12,
283,
76,
11693,
735,
288,
5672,
63,
1532,
12,
30106,
63,
1532,
275,
747,
14,
26956,
12,
747,
14,
76,
11693,
267,
587,
26,
288,
372,
272,
916,
2688,
8,
736,
12,
283,
11693,
735,
267,
5672,
63,
1532,
12,
30106,
63,
1532,
275,
747,
14,
3736,
12,
747,
14,
11693,
272,
587,
26,
267,
372,
339,
410,
275,
5672,
63,
1532,
8,
2164,
9,
272,
30106,
63,
1532,
8,
5119,
12,
5672,
14,
51,
63,
1469,
9125,
8,
270,
14,
270,
63,
632,
430,
199,
199,
692,
2688,
8,
736,
12,
283,
513,
30986,
735,
272,
347,
485,
1574
] |
[
17505,
3423,
367,
16743,
436,
3819,
12616,
1584,
436,
2082,
14416,
14,
199,
199,
13933,
710,
3423,
2348,
2793,
1133,
1331,
314,
2073,
14926,
503,
1163,
3341,
641,
10444,
14,
199,
199,
624,
199,
199,
646,
747,
199,
646,
984,
199,
646,
5672,
199,
504,
747,
14,
515,
492,
19529,
199,
646,
15951,
199,
646,
5055,
199,
646,
7554,
199,
646,
13608,
199,
199,
893,
26,
272,
492,
15055,
18,
272,
2150,
15055,
18,
272,
485,
21338,
18,
63,
15925,
275,
715,
199,
2590,
3545,
26,
272,
485,
21338,
18,
63,
15925,
275,
756,
199,
199,
893,
26,
272,
687,
14374,
492,
664,
80,
3501,
455,
199,
2590,
3545,
26,
272,
664,
80,
3501,
455,
275,
488,
199,
199,
893,
26,
272,
687,
18598,
492,
664,
2587,
17811,
199,
2590,
3545,
26,
272,
664,
2587,
17811,
275,
488,
199,
199,
363,
452,
363,
275,
2097,
1574,
9234,
401,
298,
21997,
401,
298,
1574,
632,
401,
298,
1574,
3736,
401,
298,
1574,
401,
298,
1574,
18,
401,
1779,
298,
29296,
401,
298,
1185,
401,
298,
9242,
401,
298,
547,
401,
298,
12246,
25212,
401,
1779,
298,
4858,
547,
401,
298,
1875,
63,
6404,
401,
298,
362,
63,
6404,
63,
6321,
401,
1779,
298,
2683,
63,
6404,
63,
908,
401,
298,
18408,
63,
6404,
63,
908,
401,
1779,
298,
362,
63,
5301,
63,
6321,
401,
298,
2683,
63,
5301,
63,
908,
401,
1779,
298,
18408,
63,
5301,
63,
908,
401,
298,
5301,
63,
6404,
401,
1779,
298,
4247,
63,
7435,
401,
298,
20933,
401,
298,
6777,
937,
1779,
327,
4543,
63,
3807,
365,
3483,
2945,
12,
340,
2808,
641,
314,
4298,
199,
199,
533,
4520,
8,
8263,
547,
304,
272,
986,
199,
199,
533,
12568,
25212,
8,
8263,
547,
304,
272,
408,
16894,
1380,
9936,
370,
886,
282,
4928,
402,
3439,
334,
69,
14,
71,
14,
16743,
9,
1314,
365,
272,
440,
3748,
641,
282,
4539,
570,
334,
69,
14,
71,
14,
282,
4310,
5200,
9471,
199,
199,
533,
9434,
547,
8,
8263,
547,
304,
272,
408,
16894,
1380,
282,
1414,
4293,
440,
506,
7934,
624,
199,
199,
533,
5574,
547,
8,
8263,
547,
304,
272,
408,
16894,
1380,
376,
6359,
3913,
506,
1586,
624,
199,
199,
533,
20738,
547,
8,
1726,
304,
272,
408,
16894,
1380,
282,
7086,
3439,
543,
314,
3819,
12616,
272,
436,
7787,
316,
1295,
29729,
1996,
6918,
624,
421,
199,
893,
26,
272,
23950,
199,
2590,
12746,
26,
272,
23950,
275,
488,
199,
199,
318,
1331,
9234,
8,
70,
2164,
12,
289,
5119,
12,
2582,
29,
975,
10,
7727,
304,
272,
408,
1574,
666,
687,
570,
13,
2930,
909,
289,
2164,
370,
570,
13,
2930,
909,
289,
5119,
624,
272,
1830,
413,
26,
267,
4123,
275,
289,
2164,
14,
739,
8,
1267,
9,
267,
340,
440,
4123,
26,
288,
2059,
267,
289,
5119,
14,
952,
8,
1436,
9,
199,
199,
318,
485,
7191,
493,
8,
2164,
12,
5042,
304,
272,
327,
10444,
9924,
609,
12,
13074,
14,
272,
340,
2688,
8,
736,
14,
515,
12,
283,
7191,
493,
735,
267,
862,
26,
288,
372,
747,
14,
515,
14,
7191,
493,
8,
2164,
12,
5042,
9,
267,
871,
6440,
26,
288,
372,
756,
339,
327,
2900,
1163,
10677,
26,
1104,
367,
2011,
11776,
14,
272,
372,
334,
736,
14,
515,
14,
21288,
8,
736,
14,
515,
14,
4832,
8,
2164,
430,
508,
288,
747,
14,
515,
14,
21288,
8,
736,
14,
515,
14,
4832,
8,
5119,
1724,
199,
199,
318,
1331,
493,
8,
2164,
12,
5042,
12,
9889,
2035,
63,
19522,
29,
549,
304,
272,
408,
5116,
666,
687,
2928,
370,
5042,
14,
339,
982,
2035,
63,
19522,
365,
440,
663,
436,
2928,
365,
282,
13673,
2142,
12,
282,
892,
272,
15296,
911,
506,
2737,
3140,
402,
16743,
314,
570,
652,
4501,
370,
14,
339,
408,
272,
340,
485,
7191,
493,
8,
2164,
12,
5042,
304,
267,
746,
4520,
32684,
5,
83,
64,
436,
18633,
83,
64,
787,
314,
2011,
570,
2,
450,
334,
2164,
12,
5042,
430,
339,
367,
4325,
315,
359,
2164,
12,
5042,
2189,
267,
862,
26,
288,
410,
275,
747,
14,
3736,
8,
2324,
9,
267,
871,
6440,
26,
288,
327,
3814,
4750,
12060,
1630,
440,
2187,
288,
986,
267,
587,
26,
288,
327,
5787,
14791,
3595,
1163,
4539,
1584,
31,
334,
20517,
12,
7256,
11965,
288,
340,
5672,
14,
51,
63,
1311,
20925,
8,
270,
14,
270,
63,
632,
304,
355,
746,
12568,
25212,
32684,
5,
83,
64,
365,
282,
4310,
5200,
2,
450,
4325,
9,
339,
340,
440,
2035,
63,
19522,
436,
747,
14,
515,
14,
20719,
8,
2164,
304,
267,
747,
14,
13380,
8,
736,
14,
31654,
8,
2164,
395,
5042,
9,
272,
587,
26,
267,
543,
1551,
8,
2164,
12,
283,
4848,
358,
465,
289,
2164,
26,
288,
543,
1551,
8,
5119,
12,
283,
6603,
358,
465,
289,
5119,
26,
355,
1331,
9234,
8,
70,
2164,
12,
289,
5119,
9,
272,
372,
5042,
199,
199,
318,
1331,
632,
8,
2164,
12,
5042,
12,
9889,
2035,
63,
19522,
29,
549,
304,
272,
408,
5116,
818,
5821,
687,
2928,
370,
5042,
14,
339,
982,
2035,
63,
19522,
365,
440,
663,
12,
19891,
10621,
1133,
9437,
340,
436,
1454,
272,
340,
3865,
658,
2164,
64,
436,
658,
5119,
64,
787,
19891,
14,
221,
982,
658,
76,
11693,
64,
5712,
1133,
2808,
272,
334,
69,
14,
71,
14,
10130,
9,
642,
1083,
1630,
6548,
14,
339,
408,
272,
340,
440,
2035,
63,
19522,
436,
747,
14,
515,
14,
20719,
8,
2164,
9,
436,
747,
14,
515,
14,
20719,
8,
5119,
304,
267,
340,
2688,
8,
736,
12,
283,
76,
11693,
735,
288,
5672,
63,
1532,
12,
30106,
63,
1532,
275,
747,
14,
26956,
12,
747,
14,
76,
11693,
267,
587,
26,
288,
372,
272,
916,
2688,
8,
736,
12,
283,
11693,
735,
267,
5672,
63,
1532,
12,
30106,
63,
1532,
275,
747,
14,
3736,
12,
747,
14,
11693,
272,
587,
26,
267,
372,
339,
410,
275,
5672,
63,
1532,
8,
2164,
9,
272,
30106,
63,
1532,
8,
5119,
12,
5672,
14,
51,
63,
1469,
9125,
8,
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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
] |
mcardillo55/django
|
tests/urlpatterns_reverse/erroneous_urls.py
|
199
|
1350
|
import warnings
from django.conf.urls import url
from django.utils.deprecation import RemovedInDjango110Warning
from . import views
# Test deprecated behavior of passing strings as view to url().
# Some of these can be removed in Django 1.10 as they aren't convertable to
# callables.
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=RemovedInDjango110Warning)
urlpatterns = [
# View has erroneous import
url(r'erroneous_inner/$', views.erroneous_view),
# Module has erroneous import
url(r'erroneous_outer/$', 'urlpatterns_reverse.erroneous_views_module.erroneous_view'),
# Module is an unqualified string
url(r'erroneous_unqualified/$', 'unqualified_view'),
# View does not exist
url(r'missing_inner/$', 'urlpatterns_reverse.views.missing_view'),
# View is not a callable (string import; arbitrary Python object)
url(r'uncallable-dotted/$', 'urlpatterns_reverse.views.uncallable'),
# View is not a callable (explicit import; arbitrary Python object)
url(r'uncallable-object/$', views.uncallable),
# Module does not exist
url(r'missing_outer/$', 'urlpatterns_reverse.missing_module.missing_view'),
# Regex contains an error (refs #6170)
url(r'(regex_error/$', views.empty_view),
]
|
bsd-3-clause
|
[
646,
3598,
199,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
6019,
3849,
199,
199,
504,
1275,
492,
6858,
199,
199,
3,
1379,
5906,
5953,
402,
9476,
3326,
465,
2455,
370,
1166,
1252,
199,
3,
6601,
402,
3520,
883,
506,
4829,
315,
5634,
413,
14,
709,
465,
2985,
10621,
1133,
3818,
1224,
370,
199,
3,
28041,
14,
199,
1045,
3598,
14,
9341,
63,
5451,
837,
272,
3598,
14,
23945,
360,
4247,
297,
4637,
29,
497,
19797,
6019,
3849,
9,
272,
26177,
275,
359,
267,
327,
10935,
965,
2329,
368,
1785,
492,
267,
1166,
8,
82,
7,
1508,
368,
1785,
63,
5216,
10884,
6858,
14,
1508,
368,
1785,
63,
1345,
395,
267,
327,
5673,
965,
2329,
368,
1785,
492,
267,
1166,
8,
82,
7,
1508,
368,
1785,
63,
7837,
10884,
283,
20050,
63,
4471,
14,
1508,
368,
1785,
63,
4196,
63,
578,
14,
1508,
368,
1785,
63,
1345,
659,
267,
327,
5673,
365,
376,
625,
11661,
1059,
267,
1166,
8,
82,
7,
1508,
368,
1785,
63,
324,
11661,
10884,
283,
324,
11661,
63,
1345,
659,
267,
327,
10935,
1630,
440,
2187,
267,
1166,
8,
82,
6704,
374,
1044,
63,
5216,
10884,
283,
20050,
63,
4471,
14,
4196,
14,
4752,
63,
1345,
659,
267,
327,
10935,
365,
440,
282,
4550,
334,
875,
492,
27,
9697,
2018,
909,
9,
267,
1166,
8,
82,
7,
1097,
452,
461,
13,
19404,
10884,
283,
20050,
63,
4471,
14,
4196,
14,
1097,
452,
461,
659,
267,
327,
10935,
365,
440,
282,
4550,
334,
10306,
492,
27,
9697,
2018,
909,
9,
267,
1166,
8,
82,
7,
1097,
452,
461,
13,
785,
10884,
6858,
14,
1097,
452,
461,
395,
267,
327,
5673,
1630,
440,
2187,
267,
1166,
8,
82,
6704,
374,
1044,
63,
7837,
10884,
283,
20050,
63,
4471,
14,
4752,
63,
578,
14,
4752,
63,
1345,
659,
267,
327,
12939,
3509,
376,
1125,
334,
7655,
327,
22,
11010,
9,
267,
1166,
8,
82,
6774,
3821,
63,
705,
10884,
6858,
14,
1667,
63,
1345,
395,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3598,
199,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
6019,
3849,
199,
199,
504,
1275,
492,
6858,
199,
199,
3,
1379,
5906,
5953,
402,
9476,
3326,
465,
2455,
370,
1166,
1252,
199,
3,
6601,
402,
3520,
883,
506,
4829,
315,
5634,
413,
14,
709,
465,
2985,
10621,
1133,
3818,
1224,
370,
199,
3,
28041,
14,
199,
1045,
3598,
14,
9341,
63,
5451,
837,
272,
3598,
14,
23945,
360,
4247,
297,
4637,
29,
497,
19797,
6019,
3849,
9,
272,
26177,
275,
359,
267,
327,
10935,
965,
2329,
368,
1785,
492,
267,
1166,
8,
82,
7,
1508,
368,
1785,
63,
5216,
10884,
6858,
14,
1508,
368,
1785,
63,
1345,
395,
267,
327,
5673,
965,
2329,
368,
1785,
492,
267,
1166,
8,
82,
7,
1508,
368,
1785,
63,
7837,
10884,
283,
20050,
63,
4471,
14,
1508,
368,
1785,
63,
4196,
63,
578,
14,
1508,
368,
1785,
63,
1345,
659,
267,
327,
5673,
365,
376,
625,
11661,
1059,
267,
1166,
8,
82,
7,
1508,
368,
1785,
63,
324,
11661,
10884,
283,
324,
11661,
63,
1345,
659,
267,
327,
10935,
1630,
440,
2187,
267,
1166,
8,
82,
6704,
374,
1044,
63,
5216,
10884,
283,
20050,
63,
4471,
14,
4196,
14,
4752,
63,
1345,
659,
267,
327,
10935,
365,
440,
282,
4550,
334,
875,
492,
27,
9697,
2018,
909,
9,
267,
1166,
8,
82,
7,
1097,
452,
461,
13,
19404,
10884,
283,
20050,
63,
4471,
14,
4196,
14,
1097,
452,
461,
659,
267,
327,
10935,
365,
440,
282,
4550,
334,
10306,
492,
27,
9697,
2018,
909,
9,
267,
1166,
8,
82,
7,
1097,
452,
461,
13,
785,
10884,
6858,
14,
1097,
452,
461,
395,
267,
327,
5673,
1630,
440,
2187,
267,
1166,
8,
82,
6704,
374,
1044,
63,
7837,
10884,
283,
20050,
63,
4471,
14,
4752,
63,
578,
14,
4752,
63,
1345,
659,
267,
327,
12939,
3509,
376,
1125,
334,
7655,
327,
22,
11010,
9,
267,
1166,
8,
82,
6774,
3821,
63,
705,
10884,
6858,
14,
1667,
63,
1345,
395,
272,
1622,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
oleg-alexandrov/StereoPipeline
|
src/asp/Python/asp_string_utils.py
|
2
|
4239
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# __BEGIN_LICENSE__
# Copyright (c) 2009-2013, United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration. All
# rights reserved.
#
# The NGT platform is 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.
# __END_LICENSE__
"""
Functions to help with string parsing.
"""
from __future__ import print_function
import sys, os, re, string, time, shlex
def isNumber(text):
"""Returns True if the text is a number"""
try:
float(text)
except ValueError: # Not a number
return False
return True # No error, the number must have converted
def convertToFloatIfNumber(text):
"""If the text is a number returns float(text), otherwise just text"""
try:
a = float(text)
except ValueError: # Not a number
return text
return a # No error, the number must have converted
def getLineAfterText(text, prefix, startPos=0, includeText=False):
"""Extracts the remainder of a line after a prefix"""
# StartPos = index in the text to start looking at
# Find the prefix
prefixLoc = text.find(prefix, startPos)
if prefixLoc < 0:
raise Exception('Desired text not found: ' + prefix)
# Find the bounds after the prefix
prefixEnd = prefixLoc + len(prefix)
nextEnd = text.find('\n', prefixEnd)
if nextEnd == -1: # If there was no trailing \n, use one past last character.
nextEnd = len(text)
# Check that we found the bounds
if (prefixEnd < startPos) or (nextEnd <= prefixEnd):
raise Exception('Desired text not found: ' + prefix)
# Extract the text
if includeText:
return text[prefixLoc:nextEnd]
else:
return text[prefixEnd:nextEnd]
def getNumbersInParentheses(text):
"""Returns all sets of numbers in parentheses"""
numberSets = []
# Find all number sets in the text
parenGroups = re.findall( r'\([ \d.,-]*\)', text)
for p in parenGroups:
numberText = p[1:-1] # Remove ()
numberList = numberText.split(',')
numbers = []
for n in numberList: # Convert strings to floats
numbers.append(float(n))
numberSets.append(numbers) # Add this set of numbers to output list
# If only one set of numbers return a list
if len(numberSets) == 1:
return numberSets[0]
else: # Otherwise return a list of lists
return numberSets
def getNumberAfterEqualSign(text, lineStart=0):
"""Extracts a number after an '=' sign on a line"""
# LineStart = index in the text to start looking at
numberText = getLineAfterText(text, '=', lineStart, False)
return convertToFloatIfNumber(numberText)
# The following functions are useful for going between string and list
# representations of command line arguments
def isString(a):
"""Returns true if the object is a string"""
# Python 2/3 compatibilty
try:
basestring
except NameError:
basestring = str
return isinstance(a, basestring)
def argListToString(argList):
"""Converts a list of arguments into a single argument string"""
string = ""
for arg in argList:
stringVersion = str(arg)
# Wrap arguments with spaces in them in "" so they stay together
if stringVersion.find(' ') >= 0:
stringVersion = '"' + stringVersion + '" '
if string == "":
string = stringVersion
else:
string = string + ' ' + stringVersion
return string
def stringToArgList(string):
"""Converts a single argument string into a list of arguments"""
return shlex.split(string)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
636,
15947,
63,
3961,
363,
199,
3,
221,
1898,
334,
67,
9,
8937,
13,
6965,
12,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
221,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
14,
2900,
199,
3,
221,
4481,
4644,
14,
199,
3,
199,
3,
221,
710,
653,
8391,
4298,
365,
18233,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
221,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
199,
3,
221,
844,
14,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
221,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
3,
636,
3902,
63,
3961,
363,
199,
199,
624,
2043,
17471,
370,
1720,
543,
1059,
6057,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
12,
747,
12,
295,
12,
1059,
12,
900,
12,
16701,
199,
199,
318,
365,
3259,
8,
505,
304,
272,
408,
3407,
715,
340,
314,
1318,
365,
282,
1329,
624,
2286,
862,
26,
267,
2069,
8,
505,
9,
272,
871,
1722,
26,
327,
2832,
282,
1329,
267,
372,
756,
272,
372,
715,
327,
3091,
1125,
12,
314,
1329,
1471,
1172,
6702,
199,
199,
318,
3957,
1378,
5136,
3917,
3259,
8,
505,
304,
272,
408,
3917,
314,
1318,
365,
282,
1329,
2529,
2069,
8,
505,
395,
4257,
2951,
1318,
624,
2286,
862,
26,
267,
282,
275,
2069,
8,
505,
9,
272,
871,
1722,
26,
327,
2832,
282,
1329,
267,
372,
1318,
272,
372,
282,
327,
3091,
1125,
12,
314,
1329,
1471,
1172,
6702,
199,
199,
318,
664,
3049,
10881,
1872,
8,
505,
12,
2403,
12,
1343,
6981,
29,
16,
12,
2387,
1872,
29,
797,
304,
272,
408,
12147,
83,
314,
15748,
402,
282,
1004,
2410,
282,
2403,
624,
272,
327,
7707,
6981,
275,
1478,
315,
314,
1318,
370,
1343,
10023,
737,
2286,
327,
6668,
314,
2403,
272,
2403,
3040,
275,
1318,
14,
1623,
8,
1861,
12,
1343,
6981,
9,
272,
340,
2403,
3040,
665,
378,
26,
267,
746,
2186,
360,
872,
5381,
1318,
440,
1911,
26,
283,
435,
2403,
9,
2286,
327,
6668,
314,
10461,
2410,
314,
2403,
272,
2403,
3005,
275,
2403,
3040,
435,
822,
8,
1861,
9,
272,
2163,
3005,
257,
275,
1318,
14,
1623,
2258,
78,
297,
2403,
3005,
9,
272,
340,
2163,
3005,
508,
446,
17,
26,
327,
982,
2337,
1990,
949,
8520,
971,
78,
12,
675,
1373,
13541,
2061,
4528,
14,
267,
2163,
3005,
275,
822,
8,
505,
9,
18407,
327,
2670,
626,
781,
1911,
314,
10461,
272,
340,
334,
1861,
3005,
665,
1343,
6981,
9,
503,
334,
2184,
3005,
2695,
2403,
3005,
304,
267,
746,
2186,
360,
872,
5381,
1318,
440,
1911,
26,
283,
435,
2403,
9,
2286,
327,
12892,
314,
1318,
272,
340,
2387,
1872,
26,
267,
372,
1318,
59,
1861,
3040,
26,
2184,
3005,
61,
272,
587,
26,
267,
372,
1318,
59,
1861,
3005,
26,
2184,
3005,
61,
1362,
199,
318,
664,
22951,
607,
4232,
828,
15528,
8,
505,
304,
272,
408,
3407,
1006,
5951,
402,
5579,
315,
23592,
624,
2286,
1329,
9899,
275,
942,
2286,
327,
6668,
1006,
1329,
5951,
315,
314,
1318,
272,
13566,
10177,
275,
295,
14,
6452,
8,
519,
1154,
779,
971,
68,
2020,
13,
25739,
3196,
1318,
9,
18407,
367,
299,
315,
13566,
10177,
26,
267,
1329,
1872,
275,
299,
59,
17,
6809,
17,
61,
327,
5852,
6248,
267,
1329,
1296,
275,
1329,
1872,
14,
1294,
11917,
267,
5579,
275,
942,
267,
367,
302,
315,
1329,
1296,
26,
327,
7905,
3326,
370,
15657,
288,
5579,
14,
740,
8,
1609,
8,
78,
430,
267,
1329,
9899,
14,
740,
8,
10548,
9,
327,
2654,
642,
663,
402,
5579,
370,
1072,
769,
339,
327,
982,
1454,
1373,
663,
402,
5579,
372,
282,
769,
272,
340,
822,
8,
1955,
9899,
9,
508,
413,
26,
267,
372,
1329,
9899,
59,
16,
61,
272,
587,
26,
327,
6630,
372,
282,
769,
402,
5548,
267,
372,
1329,
9899,
16872,
199,
318,
664,
3259,
10881,
591,
4940,
8,
505,
12,
1004,
3162,
29,
16,
304,
272,
408,
12147,
83,
282,
1329,
2410,
376,
14051,
2070,
641,
282,
1004,
624,
272,
327,
7030,
3162,
275,
1478,
315,
314,
1318,
370,
1343,
10023,
737,
2286,
1329,
1872,
275,
664,
3049,
10881,
1872,
8,
505,
12,
6291,
1004,
3162,
12,
756,
9,
339,
372,
3957,
1378,
5136,
3917,
3259,
8,
1955,
1872,
9,
421,
199,
3,
710,
2569,
3423,
787,
2997,
367,
9995,
3382,
1059,
436,
769,
199,
3,
221,
30580,
402,
1414,
1004,
2368,
199,
318,
365,
1558,
8,
65,
304,
272,
408,
3407,
2549,
340,
314,
909,
365,
282,
1059,
624,
339,
327,
2018,
499,
15,
19,
1013,
2159,
66,
382,
369,
272,
862,
26,
267,
7116,
272,
871,
12746,
26,
267,
7116,
275,
620,
5493,
372,
1228,
8,
65,
12,
7116,
9,
199,
199,
318,
1680,
1296,
7756,
8,
1273,
1296,
304,
272,
408,
17729,
282,
769,
402,
2368,
1901,
282,
2849,
1423,
1059,
624,
339,
1059,
275,
3087,
272,
367,
1680,
315,
1680,
1296,
26,
267,
1059,
3353,
275,
620,
8,
1273,
9,
398,
327,
20322,
2368,
543,
7883,
315,
3062,
315,
3087,
880,
2985,
25578,
10451,
267,
340,
1059,
3353,
14,
1623,
360,
5320,
2356,
378,
26,
288,
1059,
3353,
275,
14788,
435,
1059,
3353,
435,
5522,
283,
398,
340,
1059,
508,
10812,
288,
1059,
275,
1059,
3353,
267,
587,
26,
288,
1059,
275,
1059,
435,
283,
283,
435,
1059,
3353,
5493,
372,
1059,
199,
199,
318,
1059,
1378,
6373,
1296,
8,
875,
304,
272,
408,
17729,
282,
2849,
1423,
1059,
1901,
282,
769,
402,
2368,
624,
272
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
636,
15947,
63,
3961,
363,
199,
3,
221,
1898,
334,
67,
9,
8937,
13,
6965,
12,
1910,
5703,
24230,
598,
27639,
465,
11159,
701,
314,
199,
3,
221,
30660,
402,
314,
20548,
437,
281,
265,
3844,
7769,
436,
19326,
9516,
4633,
14,
2900,
199,
3,
221,
4481,
4644,
14,
199,
3,
199,
3,
221,
710,
653,
8391,
4298,
365,
18233,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
3,
221,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
199,
3,
221,
844,
14,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
221,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
3,
636,
3902,
63,
3961,
363,
199,
199,
624,
2043,
17471,
370,
1720,
543,
1059,
6057,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
984,
12,
747,
12,
295,
12,
1059,
12,
900,
12,
16701,
199,
199,
318,
365,
3259,
8,
505,
304,
272,
408,
3407,
715,
340,
314,
1318,
365,
282,
1329,
624,
2286,
862,
26,
267,
2069,
8,
505,
9,
272,
871,
1722,
26,
327,
2832,
282,
1329,
267,
372,
756,
272,
372,
715,
327,
3091,
1125,
12,
314,
1329,
1471,
1172,
6702,
199,
199,
318,
3957,
1378,
5136,
3917,
3259,
8,
505,
304,
272,
408,
3917,
314,
1318,
365,
282,
1329,
2529,
2069,
8,
505,
395,
4257,
2951,
1318,
624,
2286,
862,
26,
267,
282,
275,
2069,
8,
505,
9,
272,
871,
1722,
26,
327,
2832,
282,
1329,
267,
372,
1318,
272,
372,
282,
327,
3091,
1125,
12,
314,
1329,
1471,
1172,
6702,
199,
199,
318,
664,
3049,
10881,
1872,
8,
505,
12,
2403,
12,
1343,
6981,
29,
16,
12,
2387,
1872,
29,
797,
304,
272,
408,
12147,
83,
314,
15748,
402,
282,
1004,
2410,
282,
2403,
624,
272,
327,
7707,
6981,
275,
1478,
315,
314,
1318,
370,
1343,
10023,
737,
2286,
327,
6668,
314,
2403,
272,
2403,
3040,
275,
1318,
14,
1623,
8,
1861,
12,
1343,
6981,
9,
272,
340,
2403,
3040,
665,
378,
26,
267,
746,
2186,
360,
872,
5381,
1318,
440,
1911,
26,
283,
435,
2403,
9,
2286,
327,
6668,
314,
10461,
2410,
314,
2403,
272,
2403,
3005,
275,
2403,
3040,
435,
822,
8,
1861,
9,
272,
2163,
3005,
257,
275,
1318,
14,
1623,
2258,
78,
297,
2403,
3005,
9,
272,
340,
2163,
3005,
508,
446,
17,
26,
327,
982,
2337,
1990,
949,
8520,
971,
78,
12,
675,
1373,
13541,
2061,
4528,
14,
267,
2163,
3005,
275,
822,
8,
505,
9,
18407,
327,
2670,
626,
781,
1911,
314,
10461,
272,
340,
334,
1861,
3005,
665,
1343,
6981,
9,
503,
334,
2184,
3005,
2695,
2403,
3005,
304,
267,
746,
2186,
360,
872,
5381,
1318,
440,
1911,
26,
283,
435,
2403,
9,
2286,
327,
12892,
314,
1318,
272,
340,
2387,
1872,
26,
267,
372,
1318,
59,
1861,
3040,
26,
2184,
3005,
61,
272,
587,
26,
267,
372,
1318,
59,
1861,
3005,
26,
2184,
3005,
61,
1362,
199,
318,
664,
22951,
607,
4232,
828,
15528,
8,
505,
304,
272,
408,
3407,
1006,
5951,
402,
5579,
315,
23592,
624,
2286,
1329,
9899,
275,
942,
2286,
327,
6668,
1006,
1329,
5951,
315,
314,
1318,
272,
13566,
10177,
275,
295,
14,
6452,
8,
519,
1154,
779,
971,
68,
2020,
13,
25739,
3196,
1318,
9,
18407,
367,
299,
315,
13566,
10177,
26,
267,
1329,
1872,
275,
299,
59,
17,
6809,
17,
61,
327,
5852,
6248,
267,
1329,
1296,
275,
1329,
1872,
14,
1294,
11917,
267,
5579,
275,
942,
267,
367,
302,
315,
1329,
1296,
26,
327,
7905,
3326,
370,
15657,
288,
5579,
14,
740,
8,
1609,
8,
78,
430,
267,
1329,
9899,
14,
740,
8,
10548,
9,
327,
2654,
642,
663,
402,
5579,
370,
1072,
769,
339,
327,
982,
1454,
1373,
663,
402,
5579,
372,
282,
769,
272,
340,
822,
8,
1955,
9899,
9,
508,
413,
26,
267,
372,
1329,
9899,
59,
16,
61,
272,
587,
26,
327,
6630,
372,
282,
769,
402,
5548,
267,
372,
1329,
9899,
16872,
199,
318,
664,
3259,
10881,
591,
4940,
8,
505,
12,
1004,
3162,
29,
16,
304,
272,
408,
12147,
83,
282,
1329,
2410,
376,
14051,
2070,
641,
282,
1004,
624,
272,
327,
7030,
3162,
275,
1478,
315,
314,
1318,
370,
1343,
10023,
737,
2286,
1329,
1872,
275,
664,
3049,
10881,
1872,
8,
505,
12,
6291,
1004,
3162,
12,
756,
9,
339,
372,
3957,
1378,
5136,
3917,
3259,
8,
1955,
1872,
9,
421,
199,
3,
710,
2569,
3423,
787,
2997,
367,
9995,
3382,
1059,
436,
769,
199,
3,
221,
30580,
402,
1414,
1004,
2368,
199,
318,
365,
1558,
8,
65,
304,
272,
408,
3407,
2549,
340,
314,
909,
365,
282,
1059,
624,
339,
327,
2018,
499,
15,
19,
1013,
2159,
66,
382,
369,
272,
862,
26,
267,
7116,
272,
871,
12746,
26,
267,
7116,
275,
620,
5493,
372,
1228,
8,
65,
12,
7116,
9,
199,
199,
318,
1680,
1296,
7756,
8,
1273,
1296,
304,
272,
408,
17729,
282,
769,
402,
2368,
1901,
282,
2849,
1423,
1059,
624,
339,
1059,
275,
3087,
272,
367,
1680,
315,
1680,
1296,
26,
267,
1059,
3353,
275,
620,
8,
1273,
9,
398,
327,
20322,
2368,
543,
7883,
315,
3062,
315,
3087,
880,
2985,
25578,
10451,
267,
340,
1059,
3353,
14,
1623,
360,
5320,
2356,
378,
26,
288,
1059,
3353,
275,
14788,
435,
1059,
3353,
435,
5522,
283,
398,
340,
1059,
508,
10812,
288,
1059,
275,
1059,
3353,
267,
587,
26,
288,
1059,
275,
1059,
435,
283,
283,
435,
1059,
3353,
5493,
372,
1059,
199,
199,
318,
1059,
1378,
6373,
1296,
8,
875,
304,
272,
408,
17729,
282,
2849,
1423,
1059,
1901,
282,
769,
402,
2368,
624,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
apcrumbleton/google-python-exercises
|
termux/basic/solution/list1.py
|
209
|
3656
|
#!/usr/bin/python -tt
# Copyright 2010 Google Inc.
# Licensed under the Apache License, Version 2.0
# http://www.apache.org/licenses/LICENSE-2.0
# Google's Python Class
# http://code.google.com/edu/languages/google-python-class/
# Basic list exercises
# Fill in the code for the functions below. main() is already set up
# to call the functions with a few different inputs,
# printing 'OK' when each function is correct.
# The starter code for each function includes a 'return'
# which is just a placeholder for your code.
# It's ok if you do not complete all the functions, and there
# are some additional functions to try in list2.py.
# A. match_ends
# Given a list of strings, return the count of the number of
# strings where the string length is 2 or more and the first
# and last chars of the string are the same.
# Note: python does not have a ++ operator, but += works.
def match_ends(words):
# +++your code here+++
# LAB(begin solution)
count = 0
for word in words:
if len(word) >= 2 and word[0] == word[-1]:
count = count + 1
return count
# LAB(replace solution)
# return
# LAB(end solution)
# B. front_x
# Given a list of strings, return a list with the strings
# in sorted order, except group all the strings that begin with 'x' first.
# e.g. ['mix', 'xyz', 'apple', 'xanadu', 'aardvark'] yields
# ['xanadu', 'xyz', 'aardvark', 'apple', 'mix']
# Hint: this can be done by making 2 lists and sorting each of them
# before combining them.
def front_x(words):
# +++your code here+++
# LAB(begin solution)
# Put each word into the x_list or the other_list.
x_list = []
other_list = []
for w in words:
if w.startswith('x'):
x_list.append(w)
else:
other_list.append(w)
return sorted(x_list) + sorted(other_list)
# LAB(replace solution)
# return
# LAB(end solution)
# LAB(begin solution)
# Extract the last element from a tuple -- used for custom sorting below.
def last(a):
return a[-1]
# LAB(end solution)
# C. sort_last
# Given a list of non-empty tuples, return a list sorted in increasing
# order by the last element in each tuple.
# e.g. [(1, 7), (1, 3), (3, 4, 5), (2, 2)] yields
# [(2, 2), (1, 3), (3, 4, 5), (1, 7)]
# Hint: use a custom key= function to extract the last element form each tuple.
def sort_last(tuples):
# +++your code here+++
# LAB(begin solution)
return sorted(tuples, key=last)
# LAB(replace solution)
# return
# LAB(end solution)
# Simple provided test() function used in main() to print
# what each function returns vs. what it's supposed to return.
def test(got, expected):
if got == expected:
prefix = ' OK '
else:
prefix = ' X '
print '%s got: %s expected: %s' % (prefix, repr(got), repr(expected))
# Calls the above functions with interesting inputs.
def main():
print 'match_ends'
test(match_ends(['aba', 'xyz', 'aa', 'x', 'bbb']), 3)
test(match_ends(['', 'x', 'xy', 'xyx', 'xx']), 2)
test(match_ends(['aaa', 'be', 'abc', 'hello']), 1)
print
print 'front_x'
test(front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa']),
['xaa', 'xzz', 'axx', 'bbb', 'ccc'])
test(front_x(['ccc', 'bbb', 'aaa', 'xcc', 'xaa']),
['xaa', 'xcc', 'aaa', 'bbb', 'ccc'])
test(front_x(['mix', 'xyz', 'apple', 'xanadu', 'aardvark']),
['xanadu', 'xyz', 'aardvark', 'apple', 'mix'])
print
print 'sort_last'
test(sort_last([(1, 3), (3, 2), (2, 1)]),
[(2, 1), (3, 2), (1, 3)])
test(sort_last([(2, 3), (1, 2), (3, 1)]),
[(3, 1), (1, 2), (2, 3)])
test(sort_last([(1, 7), (1, 3), (3, 4, 5), (2, 2)]),
[(2, 2), (1, 3), (3, 4, 5), (1, 7)])
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
446,
6215,
199,
3,
1898,
7129,
4475,
3277,
14,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
3,
4475,
1159,
2018,
8089,
199,
3,
1455,
921,
600,
14,
3098,
14,
957,
15,
8654,
15,
13209,
15,
3098,
13,
1548,
13,
533,
15,
199,
199,
3,
10082,
769,
444,
281,
559,
874,
199,
3,
24797,
315,
314,
1233,
367,
314,
3423,
5084,
14,
2446,
342,
365,
2575,
663,
1536,
199,
3,
370,
1240,
314,
3423,
543,
282,
9284,
3365,
4153,
12,
199,
3,
16116,
283,
3593,
7,
1380,
1924,
805,
365,
3211,
14,
199,
3,
710,
14664,
351,
1233,
367,
1924,
805,
6952,
282,
283,
1107,
7,
199,
3,
1314,
365,
2951,
282,
10069,
367,
2195,
1233,
14,
199,
3,
2779,
1159,
4112,
340,
1265,
886,
440,
4890,
1006,
314,
3423,
12,
436,
2337,
199,
3,
787,
2005,
4722,
3423,
370,
862,
315,
769,
18,
14,
647,
14,
199,
199,
3,
437,
14,
1336,
63,
3198,
199,
3,
9138,
282,
769,
402,
3326,
12,
372,
314,
2338,
402,
314,
1329,
402,
199,
3,
3326,
2382,
314,
1059,
2582,
365,
499,
503,
1655,
436,
314,
1642,
199,
3,
436,
2061,
8365,
402,
314,
1059,
787,
314,
2011,
14,
199,
3,
3390,
26,
2366,
1630,
440,
1172,
282,
32629,
4182,
12,
1325,
847,
5419,
14,
199,
318,
1336,
63,
3198,
8,
3148,
304,
523,
327,
435,
4176,
12695,
1233,
2348,
4176,
11,
523,
327,
491,
1217,
8,
5037,
8744,
9,
523,
2338,
275,
378,
523,
367,
4349,
315,
5932,
26,
272,
340,
822,
8,
1027,
9,
2356,
499,
436,
4349,
59,
16,
61,
508,
4349,
1988,
17,
2189,
489,
2338,
275,
2338,
435,
413,
523,
372,
2338,
523,
327,
491,
1217,
8,
1814,
8744,
9,
523,
327,
372,
523,
327,
491,
1217,
8,
500,
8744,
9,
421,
199,
3,
699,
14,
13738,
63,
88,
199,
3,
9138,
282,
769,
402,
3326,
12,
372,
282,
769,
543,
314,
3326,
199,
3,
315,
3355,
1865,
12,
871,
1572,
1006,
314,
3326,
626,
5386,
543,
283,
88,
7,
1642,
14,
199,
3,
325,
14,
71,
14,
788,
13979,
297,
283,
8568,
297,
283,
12820,
297,
283,
88,
290,
350,
85,
297,
283,
65,
1005,
86,
1096,
418,
14801,
199,
3,
788,
88,
290,
350,
85,
297,
283,
8568,
297,
283,
65,
1005,
86,
1096,
297,
283,
12820,
297,
283,
13979,
418,
199,
3,
869,
442,
26,
642,
883,
506,
4224,
701,
10663,
499,
5548,
436,
13351,
1924,
402,
3062,
199,
3,
2544,
29391,
3062,
14,
199,
318,
13738,
63,
88,
8,
3148,
304,
523,
327,
435,
4176,
12695,
1233,
2348,
4176,
11,
523,
327,
491,
1217,
8,
5037,
8744,
9,
523,
327,
16280,
1924,
4349,
1901,
314,
671,
63,
513,
503,
314,
1163,
63,
513,
14,
523,
671,
63,
513,
275,
942,
523,
1163,
63,
513,
275,
942,
523,
367,
336,
315,
5932,
26,
272,
340,
336,
14,
2460,
360,
88,
735,
489,
671,
63,
513,
14,
740,
8,
87,
9,
272,
587,
26,
489,
1163,
63,
513,
14,
740,
8,
87,
9,
523,
372,
3355,
8,
88,
63,
513,
9,
435,
3355,
8,
1848,
63,
513,
9,
523,
327,
491,
1217,
8,
1814,
8744,
9,
523,
327,
372,
523,
327,
491,
1217,
8,
500,
8744,
9,
421,
199,
3,
491,
1217,
8,
5037,
8744,
9,
199,
3,
12892,
314,
2061,
1819,
687,
282,
2008,
1553,
1202,
367,
3537,
13351,
5084,
14,
199,
318,
2061,
8,
65,
304,
523,
372,
282,
1988,
17,
61,
199,
3,
491,
1217,
8,
500,
8744,
9,
199,
199,
3,
445,
14,
4069,
63,
2019,
199,
3,
9138,
282,
769,
402,
2222,
13,
1667,
6346,
12,
372,
282,
769,
3355,
315,
22255,
199,
3,
1865,
701,
314,
2061,
1819,
315,
1924,
2008,
14,
199,
3,
325,
14,
71,
14,
3842,
17,
12,
1520,
395,
334,
17,
12,
650,
395,
334,
19,
12,
841,
12,
959,
395,
334,
18,
12,
499,
1874,
14801,
199,
3,
3842,
18,
12,
499,
395,
334,
17,
12,
650,
395,
334,
19,
12,
841,
12,
959,
395,
334,
17,
12,
1520,
1874,
199,
3,
869,
442,
26,
675,
282,
3537,
790,
29,
805,
370,
5536,
314,
2061,
1819,
1824,
1924,
2008,
14,
199,
318,
4069,
63,
2019,
8,
11760,
304,
523,
327,
435,
4176,
12695,
1233,
2348,
4176,
11,
523,
327,
491,
1217,
8,
5037,
8744,
9,
523,
372,
3355,
8,
11760,
12,
790,
29,
2019,
9,
523,
327,
491,
1217,
8,
1814,
8744,
9,
523,
327,
372,
523,
327,
491,
1217,
8,
500,
8744,
9,
421,
199,
3,
5870,
2741,
511,
342,
805,
1202,
315,
2446,
342,
370,
870,
199,
3,
4052,
1924,
805,
2529,
8118,
14,
4052,
652,
1159,
20042,
370,
372,
14,
199,
318,
511,
8,
7808,
12,
1420,
304,
523,
340,
4788,
508,
1420,
26,
272,
2403,
275,
283,
9949,
283,
523,
587,
26,
272,
2403,
275,
283,
221,
1323,
283,
523,
870,
1543,
83,
4788,
26,
450,
83,
1420,
26,
450,
83,
7,
450,
334,
1861,
12,
4700,
8,
7808,
395,
4700,
8,
2062,
430,
421,
199,
3,
28055,
314,
3432,
3423,
543,
19604,
4153,
14,
199,
318,
2446,
837,
523,
870,
283,
1431,
63,
3198,
7,
523,
511,
8,
1431,
63,
3198,
2941,
20338,
297,
283,
8568,
297,
283,
2158,
297,
283,
88,
297,
283,
19482,
3815,
650,
9,
523,
511,
8,
1431,
63,
3198,
2941,
297,
283,
88,
297,
283,
1702,
297,
283,
1702,
88,
297,
283,
2154,
3815,
499,
9,
523,
511,
8,
1431,
63,
3198,
2941,
11629,
297,
283,
1235,
297,
283,
3175,
297,
283,
5006,
3815,
413,
9,
819,
870,
523,
870,
283,
14708,
63,
88,
7,
523,
511,
8,
14708,
63,
88,
2941,
19482,
297,
283,
19504,
297,
283,
1219,
88,
297,
283,
88,
4348,
297,
283,
10117,
3815,
2126,
788,
10117,
297,
283,
88,
4348,
297,
283,
1219,
88,
297,
283,
19482,
297,
283,
19504,
1105,
523,
511,
8,
14708,
63,
88,
2941,
19504,
297,
283,
19482,
297,
283,
11629,
297,
283,
11022,
297,
283,
10117,
3815,
2126,
788,
10117,
297,
283,
11022,
297,
283,
11629,
297,
283,
19482,
297
] |
[
2647,
15,
1393,
15,
1548,
446,
6215,
199,
3,
1898,
7129,
4475,
3277,
14,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
3,
4475,
1159,
2018,
8089,
199,
3,
1455,
921,
600,
14,
3098,
14,
957,
15,
8654,
15,
13209,
15,
3098,
13,
1548,
13,
533,
15,
199,
199,
3,
10082,
769,
444,
281,
559,
874,
199,
3,
24797,
315,
314,
1233,
367,
314,
3423,
5084,
14,
2446,
342,
365,
2575,
663,
1536,
199,
3,
370,
1240,
314,
3423,
543,
282,
9284,
3365,
4153,
12,
199,
3,
16116,
283,
3593,
7,
1380,
1924,
805,
365,
3211,
14,
199,
3,
710,
14664,
351,
1233,
367,
1924,
805,
6952,
282,
283,
1107,
7,
199,
3,
1314,
365,
2951,
282,
10069,
367,
2195,
1233,
14,
199,
3,
2779,
1159,
4112,
340,
1265,
886,
440,
4890,
1006,
314,
3423,
12,
436,
2337,
199,
3,
787,
2005,
4722,
3423,
370,
862,
315,
769,
18,
14,
647,
14,
199,
199,
3,
437,
14,
1336,
63,
3198,
199,
3,
9138,
282,
769,
402,
3326,
12,
372,
314,
2338,
402,
314,
1329,
402,
199,
3,
3326,
2382,
314,
1059,
2582,
365,
499,
503,
1655,
436,
314,
1642,
199,
3,
436,
2061,
8365,
402,
314,
1059,
787,
314,
2011,
14,
199,
3,
3390,
26,
2366,
1630,
440,
1172,
282,
32629,
4182,
12,
1325,
847,
5419,
14,
199,
318,
1336,
63,
3198,
8,
3148,
304,
523,
327,
435,
4176,
12695,
1233,
2348,
4176,
11,
523,
327,
491,
1217,
8,
5037,
8744,
9,
523,
2338,
275,
378,
523,
367,
4349,
315,
5932,
26,
272,
340,
822,
8,
1027,
9,
2356,
499,
436,
4349,
59,
16,
61,
508,
4349,
1988,
17,
2189,
489,
2338,
275,
2338,
435,
413,
523,
372,
2338,
523,
327,
491,
1217,
8,
1814,
8744,
9,
523,
327,
372,
523,
327,
491,
1217,
8,
500,
8744,
9,
421,
199,
3,
699,
14,
13738,
63,
88,
199,
3,
9138,
282,
769,
402,
3326,
12,
372,
282,
769,
543,
314,
3326,
199,
3,
315,
3355,
1865,
12,
871,
1572,
1006,
314,
3326,
626,
5386,
543,
283,
88,
7,
1642,
14,
199,
3,
325,
14,
71,
14,
788,
13979,
297,
283,
8568,
297,
283,
12820,
297,
283,
88,
290,
350,
85,
297,
283,
65,
1005,
86,
1096,
418,
14801,
199,
3,
788,
88,
290,
350,
85,
297,
283,
8568,
297,
283,
65,
1005,
86,
1096,
297,
283,
12820,
297,
283,
13979,
418,
199,
3,
869,
442,
26,
642,
883,
506,
4224,
701,
10663,
499,
5548,
436,
13351,
1924,
402,
3062,
199,
3,
2544,
29391,
3062,
14,
199,
318,
13738,
63,
88,
8,
3148,
304,
523,
327,
435,
4176,
12695,
1233,
2348,
4176,
11,
523,
327,
491,
1217,
8,
5037,
8744,
9,
523,
327,
16280,
1924,
4349,
1901,
314,
671,
63,
513,
503,
314,
1163,
63,
513,
14,
523,
671,
63,
513,
275,
942,
523,
1163,
63,
513,
275,
942,
523,
367,
336,
315,
5932,
26,
272,
340,
336,
14,
2460,
360,
88,
735,
489,
671,
63,
513,
14,
740,
8,
87,
9,
272,
587,
26,
489,
1163,
63,
513,
14,
740,
8,
87,
9,
523,
372,
3355,
8,
88,
63,
513,
9,
435,
3355,
8,
1848,
63,
513,
9,
523,
327,
491,
1217,
8,
1814,
8744,
9,
523,
327,
372,
523,
327,
491,
1217,
8,
500,
8744,
9,
421,
199,
3,
491,
1217,
8,
5037,
8744,
9,
199,
3,
12892,
314,
2061,
1819,
687,
282,
2008,
1553,
1202,
367,
3537,
13351,
5084,
14,
199,
318,
2061,
8,
65,
304,
523,
372,
282,
1988,
17,
61,
199,
3,
491,
1217,
8,
500,
8744,
9,
199,
199,
3,
445,
14,
4069,
63,
2019,
199,
3,
9138,
282,
769,
402,
2222,
13,
1667,
6346,
12,
372,
282,
769,
3355,
315,
22255,
199,
3,
1865,
701,
314,
2061,
1819,
315,
1924,
2008,
14,
199,
3,
325,
14,
71,
14,
3842,
17,
12,
1520,
395,
334,
17,
12,
650,
395,
334,
19,
12,
841,
12,
959,
395,
334,
18,
12,
499,
1874,
14801,
199,
3,
3842,
18,
12,
499,
395,
334,
17,
12,
650,
395,
334,
19,
12,
841,
12,
959,
395,
334,
17,
12,
1520,
1874,
199,
3,
869,
442,
26,
675,
282,
3537,
790,
29,
805,
370,
5536,
314,
2061,
1819,
1824,
1924,
2008,
14,
199,
318,
4069,
63,
2019,
8,
11760,
304,
523,
327,
435,
4176,
12695,
1233,
2348,
4176,
11,
523,
327,
491,
1217,
8,
5037,
8744,
9,
523,
372,
3355,
8,
11760,
12,
790,
29,
2019,
9,
523,
327,
491,
1217,
8,
1814,
8744,
9,
523,
327,
372,
523,
327,
491,
1217,
8,
500,
8744,
9,
421,
199,
3,
5870,
2741,
511,
342,
805,
1202,
315,
2446,
342,
370,
870,
199,
3,
4052,
1924,
805,
2529,
8118,
14,
4052,
652,
1159,
20042,
370,
372,
14,
199,
318,
511,
8,
7808,
12,
1420,
304,
523,
340,
4788,
508,
1420,
26,
272,
2403,
275,
283,
9949,
283,
523,
587,
26,
272,
2403,
275,
283,
221,
1323,
283,
523,
870,
1543,
83,
4788,
26,
450,
83,
1420,
26,
450,
83,
7,
450,
334,
1861,
12,
4700,
8,
7808,
395,
4700,
8,
2062,
430,
421,
199,
3,
28055,
314,
3432,
3423,
543,
19604,
4153,
14,
199,
318,
2446,
837,
523,
870,
283,
1431,
63,
3198,
7,
523,
511,
8,
1431,
63,
3198,
2941,
20338,
297,
283,
8568,
297,
283,
2158,
297,
283,
88,
297,
283,
19482,
3815,
650,
9,
523,
511,
8,
1431,
63,
3198,
2941,
297,
283,
88,
297,
283,
1702,
297,
283,
1702,
88,
297,
283,
2154,
3815,
499,
9,
523,
511,
8,
1431,
63,
3198,
2941,
11629,
297,
283,
1235,
297,
283,
3175,
297,
283,
5006,
3815,
413,
9,
819,
870,
523,
870,
283,
14708,
63,
88,
7,
523,
511,
8,
14708,
63,
88,
2941,
19482,
297,
283,
19504,
297,
283,
1219,
88,
297,
283,
88,
4348,
297,
283,
10117,
3815,
2126,
788,
10117,
297,
283,
88,
4348,
297,
283,
1219,
88,
297,
283,
19482,
297,
283,
19504,
1105,
523,
511,
8,
14708,
63,
88,
2941,
19504,
297,
283,
19482,
297,
283,
11629,
297,
283,
11022,
297,
283,
10117,
3815,
2126,
788,
10117,
297,
283,
11022,
297,
283,
11629,
297,
283,
19482,
297,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
v-iam/azure-sdk-for-python
|
azure-batch/azure/batch/models/pool_patch_options.py
|
3
|
3076
|
# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for
# license information.
#
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.
# --------------------------------------------------------------------------
from msrest.serialization import Model
class PoolPatchOptions(Model):
"""Additional parameters for the Pool_patch operation.
:param timeout: The maximum time that the server can spend processing the
request, in seconds. The default is 30 seconds. Default value: 30 .
:type timeout: int
:param client_request_id: The caller-generated request identity, in the
form of a GUID with no decoration such as curly braces, e.g.
9C4D50EE-2D56-4CD3-8152-34347DC9F2B0.
:type client_request_id: str
:param return_client_request_id: Whether the server should return the
client-request-id in the response. Default value: False .
:type return_client_request_id: bool
:param ocp_date: The time the request was issued. Client libraries
typically set this to the current system clock time; set it explicitly if
you are calling the REST API directly.
:type ocp_date: datetime
:param if_match: An ETag value associated with the version of the resource
known to the client. The operation will be performed only if the
resource's current ETag on the service exactly matches the value specified
by the client.
:type if_match: str
:param if_none_match: An ETag value associated with the version of the
resource known to the client. The operation will be performed only if the
resource's current ETag on the service does not match the value specified
by the client.
:type if_none_match: str
:param if_modified_since: A timestamp indicating the last modified time of
the resource known to the client. The operation will be performed only if
the resource on the service has been modified since the specified time.
:type if_modified_since: datetime
:param if_unmodified_since: A timestamp indicating the last modified time
of the resource known to the client. The operation will be performed only
if the resource on the service has not been modified since the specified
time.
:type if_unmodified_since: datetime
"""
def __init__(self, timeout=30, client_request_id=None, return_client_request_id=False, ocp_date=None, if_match=None, if_none_match=None, if_modified_since=None, if_unmodified_since=None):
self.timeout = timeout
self.client_request_id = client_request_id
self.return_client_request_id = return_client_request_id
self.ocp_date = ocp_date
self.if_match = if_match
self.if_none_match = if_none_match
self.if_modified_since = if_modified_since
self.if_unmodified_since = if_unmodified_since
|
mit
|
[
3,
2803,
29,
1624,
13,
24,
199,
3,
24775,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
199,
3,
4190,
2556,
14,
199,
3,
199,
3,
5495,
4046,
701,
15332,
334,
50,
9,
9195,
13726,
5495,
15042,
14,
199,
3,
18784,
1443,
7675,
8927,
5953,
436,
911,
506,
14669,
340,
314,
1233,
365,
199,
3,
31904,
14,
199,
3,
24775,
199,
199,
504,
6605,
3911,
14,
12161,
492,
5822,
421,
199,
533,
15553,
11173,
4558,
8,
1685,
304,
272,
408,
8824,
2633,
367,
314,
15553,
63,
2068,
3439,
14,
339,
520,
635,
2653,
26,
710,
5696,
900,
626,
314,
1654,
883,
26387,
6661,
314,
1362,
1056,
12,
315,
4696,
14,
710,
849,
365,
4233,
4696,
14,
3758,
574,
26,
4233,
1275,
272,
520,
466,
2653,
26,
1109,
272,
520,
635,
1890,
63,
1069,
63,
344,
26,
710,
8025,
13,
10176,
1056,
8503,
12,
315,
314,
1362,
1824,
402,
282,
21645,
543,
949,
5509,
425,
4066,
465,
1094,
590,
27158,
12,
325,
14,
71,
14,
1362,
1749,
35,
20,
36,
1400,
8699,
13,
18,
36,
1367,
13,
20,
7695,
19,
13,
24,
11024,
13,
1082,
12532,
5196,
25,
38,
18,
34,
16,
14,
272,
520,
466,
1890,
63,
1069,
63,
344,
26,
620,
272,
520,
635,
372,
63,
1258,
63,
1069,
63,
344,
26,
7480,
314,
1654,
1077,
372,
314,
1362,
1890,
13,
1069,
13,
344,
315,
314,
1177,
14,
3758,
574,
26,
756,
1275,
272,
520,
466,
372,
63,
1258,
63,
1069,
63,
344,
26,
2155,
272,
520,
635,
312,
1850,
63,
602,
26,
710,
900,
314,
1056,
1990,
21117,
14,
6810,
8363,
1362,
13609,
663,
642,
370,
314,
1453,
2656,
12516,
900,
27,
663,
652,
7662,
340,
1362,
1265,
787,
6358,
314,
14880,
3261,
5370,
14,
272,
520,
466,
312,
1850,
63,
602,
26,
2197,
272,
520,
635,
340,
63,
1431,
26,
1626,
662,
1931,
574,
4568,
543,
314,
1015,
402,
314,
2073,
1362,
6040,
370,
314,
1890,
14,
710,
3439,
911,
506,
10585,
1454,
340,
314,
1362,
2073,
1159,
1453,
662,
1931,
641,
314,
2435,
8840,
4450,
314,
574,
2013,
1362,
701,
314,
1890,
14,
272,
520,
466,
340,
63,
1431,
26,
620,
272,
520,
635,
340,
63,
3592,
63,
1431,
26,
1626,
662,
1931,
574,
4568,
543,
314,
1015,
402,
314,
1362,
2073,
6040,
370,
314,
1890,
14,
710,
3439,
911,
506,
10585,
1454,
340,
314,
1362,
2073,
1159,
1453,
662,
1931,
641,
314,
2435,
1630,
440,
1336,
314,
574,
2013,
1362,
701,
314,
1890,
14,
272,
520,
466,
340,
63,
3592,
63,
1431,
26,
620,
272,
520,
635,
340,
63,
5540,
63,
8585,
26,
437,
4913,
9297,
314,
2061,
6042,
900,
402,
1362,
314,
2073,
6040,
370,
314,
1890,
14,
710,
3439,
911,
506,
10585,
1454,
340,
1362,
314,
2073,
641,
314,
2435,
965,
2757,
6042,
3967,
314,
2013,
900,
14,
272,
520,
466,
340,
63,
5540,
63,
8585,
26,
2197,
272,
520,
635,
340,
63,
324,
5540,
63,
8585,
26,
437,
4913,
9297,
314,
2061,
6042,
900,
1362,
402,
314,
2073,
6040,
370,
314,
1890,
14,
710,
3439,
911,
506,
10585,
1454,
1362,
340,
314,
2073,
641,
314,
2435,
965,
440,
2757,
6042,
3967,
314,
2013,
1362,
900,
14,
272,
520,
466,
340,
63,
324,
5540,
63,
8585,
26,
2197,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2653,
29,
1216,
12,
1890,
63,
1069,
63,
344,
29,
403,
12,
372,
63,
1258,
63,
1069,
63,
344,
29,
797,
12,
312,
1850,
63,
602,
29,
403,
12,
340,
63,
1431,
29,
403,
12,
340,
63,
3592,
63,
1431,
29,
403,
12,
340,
63,
5540,
63,
8585,
29,
403,
12,
340,
63,
324,
5540,
63,
8585,
29,
403,
304,
267,
291,
14,
2593,
275,
2653,
267,
291,
14,
1258,
63,
1069,
63,
344,
275,
1890,
63,
1069,
63,
344,
267,
291,
14,
1107,
63,
1258,
63,
1069,
63,
344,
275,
372,
63,
1258,
63,
1069,
63,
344,
267,
291,
14,
679,
80,
63,
602,
275,
312,
1850,
63,
602,
267,
291,
14,
692,
63,
1431,
275,
340,
63,
1431,
267,
291,
14,
692,
63,
3592,
63,
1431,
275,
340,
63,
3592,
63,
1431,
267,
291,
14,
692,
63,
5540,
63,
8585,
275,
340,
63,
5540,
63,
8585,
267,
291,
14,
692,
63,
324,
5540,
63,
8585,
275,
340,
63,
324,
5540,
63,
8585,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
29,
1624,
13,
24,
199,
3,
24775,
199,
3,
1898,
334,
67,
9,
15332,
11098,
14,
2900,
4481,
4644,
14,
199,
3,
3909,
1334,
314,
10697,
844,
14,
1666,
844,
14,
2424,
315,
314,
2199,
1738,
367,
199,
3,
4190,
2556,
14,
199,
3,
199,
3,
5495,
4046,
701,
15332,
334,
50,
9,
9195,
13726,
5495,
15042,
14,
199,
3,
18784,
1443,
7675,
8927,
5953,
436,
911,
506,
14669,
340,
314,
1233,
365,
199,
3,
31904,
14,
199,
3,
24775,
199,
199,
504,
6605,
3911,
14,
12161,
492,
5822,
421,
199,
533,
15553,
11173,
4558,
8,
1685,
304,
272,
408,
8824,
2633,
367,
314,
15553,
63,
2068,
3439,
14,
339,
520,
635,
2653,
26,
710,
5696,
900,
626,
314,
1654,
883,
26387,
6661,
314,
1362,
1056,
12,
315,
4696,
14,
710,
849,
365,
4233,
4696,
14,
3758,
574,
26,
4233,
1275,
272,
520,
466,
2653,
26,
1109,
272,
520,
635,
1890,
63,
1069,
63,
344,
26,
710,
8025,
13,
10176,
1056,
8503,
12,
315,
314,
1362,
1824,
402,
282,
21645,
543,
949,
5509,
425,
4066,
465,
1094,
590,
27158,
12,
325,
14,
71,
14,
1362,
1749,
35,
20,
36,
1400,
8699,
13,
18,
36,
1367,
13,
20,
7695,
19,
13,
24,
11024,
13,
1082,
12532,
5196,
25,
38,
18,
34,
16,
14,
272,
520,
466,
1890,
63,
1069,
63,
344,
26,
620,
272,
520,
635,
372,
63,
1258,
63,
1069,
63,
344,
26,
7480,
314,
1654,
1077,
372,
314,
1362,
1890,
13,
1069,
13,
344,
315,
314,
1177,
14,
3758,
574,
26,
756,
1275,
272,
520,
466,
372,
63,
1258,
63,
1069,
63,
344,
26,
2155,
272,
520,
635,
312,
1850,
63,
602,
26,
710,
900,
314,
1056,
1990,
21117,
14,
6810,
8363,
1362,
13609,
663,
642,
370,
314,
1453,
2656,
12516,
900,
27,
663,
652,
7662,
340,
1362,
1265,
787,
6358,
314,
14880,
3261,
5370,
14,
272,
520,
466,
312,
1850,
63,
602,
26,
2197,
272,
520,
635,
340,
63,
1431,
26,
1626,
662,
1931,
574,
4568,
543,
314,
1015,
402,
314,
2073,
1362,
6040,
370,
314,
1890,
14,
710,
3439,
911,
506,
10585,
1454,
340,
314,
1362,
2073,
1159,
1453,
662,
1931,
641,
314,
2435,
8840,
4450,
314,
574,
2013,
1362,
701,
314,
1890,
14,
272,
520,
466,
340,
63,
1431,
26,
620,
272,
520,
635,
340,
63,
3592,
63,
1431,
26,
1626,
662,
1931,
574,
4568,
543,
314,
1015,
402,
314,
1362,
2073,
6040,
370,
314,
1890,
14,
710,
3439,
911,
506,
10585,
1454,
340,
314,
1362,
2073,
1159,
1453,
662,
1931,
641,
314,
2435,
1630,
440,
1336,
314,
574,
2013,
1362,
701,
314,
1890,
14,
272,
520,
466,
340,
63,
3592,
63,
1431,
26,
620,
272,
520,
635,
340,
63,
5540,
63,
8585,
26,
437,
4913,
9297,
314,
2061,
6042,
900,
402,
1362,
314,
2073,
6040,
370,
314,
1890,
14,
710,
3439,
911,
506,
10585,
1454,
340,
1362,
314,
2073,
641,
314,
2435,
965,
2757,
6042,
3967,
314,
2013,
900,
14,
272,
520,
466,
340,
63,
5540,
63,
8585,
26,
2197,
272,
520,
635,
340,
63,
324,
5540,
63,
8585,
26,
437,
4913,
9297,
314,
2061,
6042,
900,
1362,
402,
314,
2073,
6040,
370,
314,
1890,
14,
710,
3439,
911,
506,
10585,
1454,
1362,
340,
314,
2073,
641,
314,
2435,
965,
440,
2757,
6042,
3967,
314,
2013,
1362,
900,
14,
272,
520,
466,
340,
63,
324,
5540,
63,
8585,
26,
2197,
272,
408,
339,
347,
636,
826,
721,
277,
12,
2653,
29,
1216,
12,
1890,
63,
1069,
63,
344,
29,
403,
12,
372,
63,
1258,
63,
1069,
63,
344,
29,
797,
12,
312,
1850,
63,
602,
29,
403,
12,
340,
63,
1431,
29,
403,
12,
340,
63,
3592,
63,
1431,
29,
403,
12,
340,
63,
5540,
63,
8585,
29,
403,
12,
340,
63,
324,
5540,
63,
8585,
29,
403,
304,
267,
291,
14,
2593,
275,
2653,
267,
291,
14,
1258,
63,
1069,
63,
344,
275,
1890,
63,
1069,
63,
344,
267,
291,
14,
1107,
63,
1258,
63,
1069,
63,
344,
275,
372,
63,
1258,
63,
1069,
63,
344,
267,
291,
14,
679,
80,
63,
602,
275,
312,
1850,
63,
602,
267,
291,
14,
692,
63,
1431,
275,
340,
63,
1431,
267,
291,
14,
692,
63,
3592,
63,
1431,
275,
340,
63,
3592,
63,
1431,
267,
291,
14,
692,
63,
5540,
63,
8585,
275,
340,
63,
5540,
63,
8585,
267,
291,
14,
692,
63,
324,
5540,
63,
8585,
275,
340,
63,
324,
5540,
63,
8585,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
xinjiguaike/edx-platform
|
common/djangoapps/course_modes/migrations/0002_auto__add_field_coursemode_currency.py
|
114
|
1475
|
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'CourseMode.currency'
db.add_column('course_modes_coursemode', 'currency',
self.gf('django.db.models.fields.CharField')(default='usd', max_length=8),
keep_default=False)
def backwards(self, orm):
# Deleting field 'CourseMode.currency'
db.delete_column('course_modes_coursemode', 'currency')
models = {
'course_modes.coursemode': {
'Meta': {'object_name': 'CourseMode'},
'course_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'currency': ('django.db.models.fields.CharField', [], {'default': "'usd'", 'max_length': '8'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'min_price': ('django.db.models.fields.IntegerField', [], {'default': '0'}),
'mode_display_name': ('django.db.models.fields.CharField', [], {'max_length': '255'}),
'mode_slug': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'suggested_prices': ('django.db.models.fields.CommaSeparatedIntegerField', [], {'default': "''", 'max_length': '255', 'blank': 'True'})
}
}
complete_apps = ['course_modes']
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
12934,
901,
283,
6979,
1385,
14,
4968,
7,
267,
1592,
14,
525,
63,
2301,
360,
1972,
63,
10433,
63,
1972,
632,
297,
283,
4968,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
885,
534,
31597,
297,
1390,
63,
1267,
29,
24,
395,
1993,
4215,
63,
885,
29,
797,
9,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
901,
283,
6979,
1385,
14,
4968,
7,
267,
1592,
14,
1807,
63,
2301,
360,
1972,
63,
10433,
63,
1972,
632,
297,
283,
4968,
358,
2378,
1709,
275,
469,
267,
283,
1972,
63,
10433,
14,
1972,
632,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
6979,
1385,
2267,
288,
283,
1972,
63,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2299,
297,
283,
697,
63,
1080,
356,
283,
549,
1604,
288,
283,
4968,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
885,
356,
3546,
31597,
4662,
283,
988,
63,
1267,
356,
283,
24,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
827,
63,
4777,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
16,
1604,
288,
283,
632,
63,
2918,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2299,
1604,
288,
283,
632,
63,
5464,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
29833,
63,
32434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
25732,
20727,
3901,
297,
990,
791,
885,
356,
19605,
283,
988,
63,
1267,
356,
283,
2299,
297,
283,
2500,
356,
283,
549,
3071,
267,
789,
272,
789,
339,
4890,
63,
5181,
275,
788,
1972,
63,
10433,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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,
901,
283,
6979,
1385,
14,
4968,
7,
267,
1592,
14,
525,
63,
2301,
360,
1972,
63,
10433,
63,
1972,
632,
297,
283,
4968,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
7533,
885,
534,
31597,
297,
1390,
63,
1267,
29,
24,
395,
1993,
4215,
63,
885,
29,
797,
9,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
15920,
901,
283,
6979,
1385,
14,
4968,
7,
267,
1592,
14,
1807,
63,
2301,
360,
1972,
63,
10433,
63,
1972,
632,
297,
283,
4968,
358,
2378,
1709,
275,
469,
267,
283,
1972,
63,
10433,
14,
1972,
632,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
6979,
1385,
2267,
288,
283,
1972,
63,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2299,
297,
283,
697,
63,
1080,
356,
283,
549,
1604,
288,
283,
4968,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
885,
356,
3546,
31597,
4662,
283,
988,
63,
1267,
356,
283,
24,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
827,
63,
4777,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
3901,
297,
990,
791,
885,
356,
283,
16,
1604,
288,
283,
632,
63,
2918,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
2299,
1604,
288,
283,
632,
63,
5464,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
29833,
63,
32434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
25732,
20727,
3901,
297,
990,
791,
885,
356,
19605,
283,
988,
63,
1267,
356,
283,
2299,
297,
283,
2500,
356,
283,
549,
3071,
267,
789,
272,
789,
339,
4890,
63,
5181,
275,
788,
1972,
63,
10433,
418,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
AlexDoul/PyQt4
|
examples/itemviews/simpledommodel.py
|
20
|
7108
|
#!/usr/bin/env python
#############################################################################
##
## Copyright (C) 2010 Riverbank Computing Limited.
## Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
## All rights reserved.
##
## This file is part of the examples of PyQt.
##
## $QT_BEGIN_LICENSE:BSD$
## You may use this file under the terms of the BSD license as follows:
##
## "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 Nokia Corporation and its Subsidiary(-ies) 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."
## $QT_END_LICENSE$
##
#############################################################################
# This is only needed for Python v2 but is harmless for Python v3.
import sip
sip.setapi('QString', 2)
from PyQt4 import QtCore, QtGui, QtXml
class DomItem(object):
def __init__(self, node, row, parent=None):
self.domNode = node
# Record the item's location within its parent.
self.rowNumber = row
self.parentItem = parent
self.childItems = {}
def node(self):
return self.domNode
def parent(self):
return self.parentItem
def child(self, i):
if i in self.childItems:
return self.childItems[i]
if i >= 0 and i < self.domNode.childNodes().count():
childNode = self.domNode.childNodes().item(i)
childItem = DomItem(childNode, i, self)
self.childItems[i] = childItem
return childItem
return None
def row(self):
return self.rowNumber
class DomModel(QtCore.QAbstractItemModel):
def __init__(self, document, parent=None):
super(DomModel, self).__init__(parent)
self.domDocument = document
self.rootItem = DomItem(self.domDocument, 0)
def columnCount(self, parent):
return 3
def data(self, index, role):
if not index.isValid():
return None
if role != QtCore.Qt.DisplayRole:
return None
item = index.internalPointer()
node = item.node()
attributes = []
attributeMap = node.attributes()
if index.column() == 0:
return node.nodeName()
elif index.column() == 1:
for i in range(0, attributeMap.count()):
attribute = attributeMap.item(i)
attributes.append(attribute.nodeName() + '="' +
attribute.nodeValue() + '"')
return " ".join(attributes)
if index.column() == 2:
value = node.nodeValue()
if value is None:
return ''
return ' '.join(node.nodeValue().split('\n'))
return None
def flags(self, index):
if not index.isValid():
return QtCore.Qt.NoItemFlags
return QtCore.Qt.ItemIsEnabled | QtCore.Qt.ItemIsSelectable
def headerData(self, section, orientation, role):
if orientation == QtCore.Qt.Horizontal and role == QtCore.Qt.DisplayRole:
if section == 0:
return "Name"
if section == 1:
return "Attributes"
if section == 2:
return "Value"
return None
def index(self, row, column, parent):
if not self.hasIndex(row, column, parent):
return QtCore.QModelIndex()
if not parent.isValid():
parentItem = self.rootItem
else:
parentItem = parent.internalPointer()
childItem = parentItem.child(row)
if childItem:
return self.createIndex(row, column, childItem)
else:
return QtCore.QModelIndex()
def parent(self, child):
if not child.isValid():
return QtCore.QModelIndex()
childItem = child.internalPointer()
parentItem = childItem.parent()
if not parentItem or parentItem == self.rootItem:
return QtCore.QModelIndex()
return self.createIndex(parentItem.row(), 0, parentItem)
def rowCount(self, parent):
if parent.column() > 0:
return 0
if not parent.isValid():
parentItem = self.rootItem
else:
parentItem = parent.internalPointer()
return parentItem.node().childNodes().count()
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.fileMenu = self.menuBar().addMenu("&File")
self.fileMenu.addAction("&Open...", self.openFile, "Ctrl+O")
self.fileMenu.addAction("E&xit", self.close, "Ctrl+Q")
self.xmlPath = ""
self.model = DomModel(QtXml.QDomDocument(), self)
self.view = QtGui.QTreeView(self)
self.view.setModel(self.model)
self.setCentralWidget(self.view)
self.setWindowTitle("Simple DOM Model")
def openFile(self):
filePath = QtGui.QFileDialog.getOpenFileName(self, "Open File",
self.xmlPath, "XML files (*.xml);;HTML files (*.html);;"
"SVG files (*.svg);;User Interface files (*.ui)")
if filePath:
f = QtCore.QFile(filePath)
if f.open(QtCore.QIODevice.ReadOnly):
document = QtXml.QDomDocument()
if document.setContent(f):
newModel = DomModel(document, self)
self.view.setModel(newModel)
self.model = newModel
self.xmlPath = filePath
f.close()
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.resize(640, 480)
window.show()
sys.exit(app.exec_())
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
421,
199,
31635,
199,
309,
199,
309,
1898,
334,
35,
9,
7129,
820,
4380,
9860,
27799,
23954,
14,
199,
309,
1898,
334,
35,
9,
7129,
653,
745,
4674,
11098,
436,
15,
269,
2399,
1007,
338,
328,
695,
2801,
1500,
680,
199,
309,
2900,
4481,
4644,
14,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
314,
7251,
402,
14084,
14,
199,
309,
199,
309,
2672,
19229,
63,
15947,
63,
3961,
26,
15400,
4,
199,
309,
2047,
1443,
675,
642,
570,
1334,
314,
2895,
402,
314,
6289,
4190,
465,
11924,
26,
199,
309,
199,
309,
298,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
309,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
309,
7647,
26,
199,
309,
257,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
309,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
309,
257,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
309,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
309,
258,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
309,
258,
4084,
14,
199,
309,
257,
627,
11443,
314,
536,
402,
653,
745,
4674,
11098,
436,
2399,
4804,
338,
328,
695,
2801,
1500,
9,
6590,
199,
309,
258,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
199,
309,
258,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
309,
258,
4983,
14,
199,
309,
199,
309,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
309,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
309,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
309,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
309,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
309,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
309,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
309,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
309,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
309,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
309,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
2122,
199,
309,
2672,
19229,
63,
3902,
63,
3961,
4,
199,
309,
199,
31635,
421,
199,
3,
961,
365,
1454,
4346,
367,
2018,
373,
18,
1325,
365,
394,
5362,
2003,
367,
2018,
373,
19,
14,
199,
646,
25342,
199,
17839,
14,
409,
1246,
360,
49,
1558,
297,
499,
9,
199,
199,
504,
14084,
20,
492,
10565,
12,
5928,
12,
3959,
8672,
421,
199,
533,
577,
676,
2081,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1031,
12,
1962,
12,
1676,
29,
403,
304,
267,
291,
14,
4556,
1716,
275,
1031,
267,
327,
12651,
314,
1242,
1159,
2909,
4453,
2399,
1676,
14,
267,
291,
14,
1143,
3259,
275,
1962,
267,
291,
14,
1708,
2081,
275,
1676,
267,
291,
14,
1739,
7412,
275,
1052,
339,
347,
1031,
8,
277,
304,
267,
372,
291,
14,
4556,
1716,
339,
347,
1676,
8,
277,
304,
267,
372,
291,
14,
1708,
2081,
339,
347,
1982,
8,
277,
12,
284,
304,
267,
340,
284,
315,
291,
14,
1739,
7412,
26,
288,
372,
291,
14,
1739,
7412,
59,
73,
61,
398,
340,
284,
2356,
378,
436,
284,
665,
291,
14,
4556,
1716,
14,
10626,
1252,
835,
837,
288,
29694,
275,
291,
14,
4556,
1716,
14,
10626,
1252,
1053,
8,
73,
9,
288,
1982,
2081,
275,
577,
676,
2081,
8,
1739,
1716,
12,
284,
12,
291,
9,
288,
291,
14,
1739,
7412,
59,
73,
61,
275,
1982,
2081,
288,
372,
1982,
2081,
398,
372,
488,
339,
347,
1962,
8,
277,
304,
267,
372,
291,
14,
1143,
3259,
421,
199,
533,
577,
676,
1685,
8,
10901,
14,
49,
8458,
2081,
1685,
304,
272,
347,
636,
826,
721,
277,
12,
2213,
12,
1676,
29,
403,
304,
267,
1613,
8,
20106,
1685,
12,
291,
2843,
826,
721,
1708,
9,
398,
291,
14,
4556,
5564,
275,
2213,
398,
291,
14,
1231,
2081,
275,
577,
676,
2081,
8,
277,
14,
4556,
5564,
12,
378,
9,
339,
347,
2763,
2353,
8,
277,
12,
1676,
304,
267,
372,
650,
339,
347,
666,
8,
277,
12,
1478,
12,
4719,
304,
267,
340,
440,
1478,
14,
18728,
837,
288,
372,
488,
398,
340,
4719,
1137,
10565,
14,
4238,
14,
7687,
7422,
26,
288,
372,
488,
398,
1242,
275,
1478,
14,
4672,
12190,
342,
398,
1031,
275,
1242,
14,
932,
342,
267,
3004,
275,
942,
267,
2225,
2956,
275,
1031,
14,
2987,
342,
398,
340,
1478,
14,
2301,
342,
508,
378,
26,
288,
372,
1031,
14,
13777,
342,
2728,
916,
1478,
14,
2301,
342,
508,
413,
26,
288,
367,
284,
315,
1425,
8,
16,
12,
2225,
2956,
14,
835,
5109,
355,
2225,
275,
2225,
2956,
14,
1053,
8,
73,
9,
355,
3004,
14,
740,
8,
3215,
14,
13777,
342,
435,
283,
26957,
435,
3303,
2225,
14,
17240,
342,
435,
5522,
358,
953,
372,
298,
3680,
904,
8,
2987,
9,
398,
340,
1478,
14,
2301,
342,
508,
499,
26,
288,
574,
275,
1031,
14,
17240,
342,
288,
340,
574,
365,
488,
26,
355,
372,
2125,
953,
372,
283,
1987,
904,
8,
932,
14,
17240,
1252,
1294,
2258,
78,
1333,
398,
372,
488,
339,
347,
3285,
8,
277,
12,
1478,
304,
267,
340,
440,
1478,
14,
18728,
837,
288,
372,
10565,
14,
4238,
14,
1944,
2081,
6381,
398,
372,
10565,
14,
4238,
14,
2081,
1831,
6589,
1204,
10565,
14,
4238,
14,
2081,
1831,
5446,
461,
339,
347,
1406,
1451,
8,
277,
12,
3420,
12,
16774,
12,
4719,
304,
267,
340,
16774,
508,
10565,
14,
4238,
14,
19918,
436,
4719,
508,
10565,
14,
4238,
14,
7687,
7422,
26,
288,
340,
3420,
508,
378,
26,
355,
372,
298,
985,
2,
953,
340,
3420,
508,
413,
26,
355,
372,
298,
5379,
2,
953,
340
] |
[
2647,
15,
1393,
15,
1813,
2366,
421,
199,
31635,
199,
309,
199,
309,
1898,
334,
35,
9,
7129,
820,
4380,
9860,
27799,
23954,
14,
199,
309,
1898,
334,
35,
9,
7129,
653,
745,
4674,
11098,
436,
15,
269,
2399,
1007,
338,
328,
695,
2801,
1500,
680,
199,
309,
2900,
4481,
4644,
14,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
314,
7251,
402,
14084,
14,
199,
309,
199,
309,
2672,
19229,
63,
15947,
63,
3961,
26,
15400,
4,
199,
309,
2047,
1443,
675,
642,
570,
1334,
314,
2895,
402,
314,
6289,
4190,
465,
11924,
26,
199,
309,
199,
309,
298,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
309,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
309,
7647,
26,
199,
309,
257,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
309,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
309,
257,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
309,
258,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
199,
309,
258,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
309,
258,
4084,
14,
199,
309,
257,
627,
11443,
314,
536,
402,
653,
745,
4674,
11098,
436,
2399,
4804,
338,
328,
695,
2801,
1500,
9,
6590,
199,
309,
258,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
199,
309,
258,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
199,
309,
258,
4983,
14,
199,
309,
199,
309,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
309,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
309,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
309,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
309,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
309,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
309,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
309,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
309,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
309,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
309,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
2122,
199,
309,
2672,
19229,
63,
3902,
63,
3961,
4,
199,
309,
199,
31635,
421,
199,
3,
961,
365,
1454,
4346,
367,
2018,
373,
18,
1325,
365,
394,
5362,
2003,
367,
2018,
373,
19,
14,
199,
646,
25342,
199,
17839,
14,
409,
1246,
360,
49,
1558,
297,
499,
9,
199,
199,
504,
14084,
20,
492,
10565,
12,
5928,
12,
3959,
8672,
421,
199,
533,
577,
676,
2081,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
1031,
12,
1962,
12,
1676,
29,
403,
304,
267,
291,
14,
4556,
1716,
275,
1031,
267,
327,
12651,
314,
1242,
1159,
2909,
4453,
2399,
1676,
14,
267,
291,
14,
1143,
3259,
275,
1962,
267,
291,
14,
1708,
2081,
275,
1676,
267,
291,
14,
1739,
7412,
275,
1052,
339,
347,
1031,
8,
277,
304,
267,
372,
291,
14,
4556,
1716,
339,
347,
1676,
8,
277,
304,
267,
372,
291,
14,
1708,
2081,
339,
347,
1982,
8,
277,
12,
284,
304,
267,
340,
284,
315,
291,
14,
1739,
7412,
26,
288,
372,
291,
14,
1739,
7412,
59,
73,
61,
398,
340,
284,
2356,
378,
436,
284,
665,
291,
14,
4556,
1716,
14,
10626,
1252,
835,
837,
288,
29694,
275,
291,
14,
4556,
1716,
14,
10626,
1252,
1053,
8,
73,
9,
288,
1982,
2081,
275,
577,
676,
2081,
8,
1739,
1716,
12,
284,
12,
291,
9,
288,
291,
14,
1739,
7412,
59,
73,
61,
275,
1982,
2081,
288,
372,
1982,
2081,
398,
372,
488,
339,
347,
1962,
8,
277,
304,
267,
372,
291,
14,
1143,
3259,
421,
199,
533,
577,
676,
1685,
8,
10901,
14,
49,
8458,
2081,
1685,
304,
272,
347,
636,
826,
721,
277,
12,
2213,
12,
1676,
29,
403,
304,
267,
1613,
8,
20106,
1685,
12,
291,
2843,
826,
721,
1708,
9,
398,
291,
14,
4556,
5564,
275,
2213,
398,
291,
14,
1231,
2081,
275,
577,
676,
2081,
8,
277,
14,
4556,
5564,
12,
378,
9,
339,
347,
2763,
2353,
8,
277,
12,
1676,
304,
267,
372,
650,
339,
347,
666,
8,
277,
12,
1478,
12,
4719,
304,
267,
340,
440,
1478,
14,
18728,
837,
288,
372,
488,
398,
340,
4719,
1137,
10565,
14,
4238,
14,
7687,
7422,
26,
288,
372,
488,
398,
1242,
275,
1478,
14,
4672,
12190,
342,
398,
1031,
275,
1242,
14,
932,
342,
267,
3004,
275,
942,
267,
2225,
2956,
275,
1031,
14,
2987,
342,
398,
340,
1478,
14,
2301,
342,
508,
378,
26,
288,
372,
1031,
14,
13777,
342,
2728,
916,
1478,
14,
2301,
342,
508,
413,
26,
288,
367,
284,
315,
1425,
8,
16,
12,
2225,
2956,
14,
835,
5109,
355,
2225,
275,
2225,
2956,
14,
1053,
8,
73,
9,
355,
3004,
14,
740,
8,
3215,
14,
13777,
342,
435,
283,
26957,
435,
3303,
2225,
14,
17240,
342,
435,
5522,
358,
953,
372,
298,
3680,
904,
8,
2987,
9,
398,
340,
1478,
14,
2301,
342,
508,
499,
26,
288,
574,
275,
1031,
14,
17240,
342,
288,
340,
574,
365,
488,
26,
355,
372,
2125,
953,
372,
283,
1987,
904,
8,
932,
14,
17240,
1252,
1294,
2258,
78,
1333,
398,
372,
488,
339,
347,
3285,
8,
277,
12,
1478,
304,
267,
340,
440,
1478,
14,
18728,
837,
288,
372,
10565,
14,
4238,
14,
1944,
2081,
6381,
398,
372,
10565,
14,
4238,
14,
2081,
1831,
6589,
1204,
10565,
14,
4238,
14,
2081,
1831,
5446,
461,
339,
347,
1406,
1451,
8,
277,
12,
3420,
12,
16774,
12,
4719,
304,
267,
340,
16774,
508,
10565,
14,
4238,
14,
19918,
436,
4719,
508,
10565,
14,
4238,
14,
7687,
7422,
26,
288,
340,
3420,
508,
378,
26,
355,
372,
298,
985,
2,
953,
340,
3420,
508,
413,
26,
355,
372,
298,
5379,
2,
953,
340,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
timpalpant/calibre
|
src/calibre/srv/sendfile.py
|
14
|
4930
|
#!/usr/bin/env python2
# vim:fileencoding=utf-8
from __future__ import (unicode_literals, division, absolute_import,
print_function)
__license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
import os, ctypes, errno, socket
from io import DEFAULT_BUFFER_SIZE
from select import select
from calibre.constants import islinux, isosx
from calibre.srv.utils import eintr_retry_call
def file_metadata(fileobj):
try:
fd = fileobj.fileno()
return os.fstat(fd)
except Exception:
pass
def copy_range(src_file, start, size, dest):
total_sent = 0
src_file.seek(start)
while size > 0:
data = eintr_retry_call(src_file.read, min(size, DEFAULT_BUFFER_SIZE))
if len(data) == 0:
break # EOF
dest.write(data)
size -= len(data)
total_sent += len(data)
del data
return total_sent
class CannotSendfile(Exception):
pass
class SendfileInterrupted(Exception):
pass
sendfile_to_socket = sendfile_to_socket_async = None
if isosx:
libc = ctypes.CDLL(None, use_errno=True)
sendfile = ctypes.CFUNCTYPE(
ctypes.c_int, ctypes.c_int, ctypes.c_int, ctypes.c_int64, ctypes.POINTER(ctypes.c_int64), ctypes.c_void_p, ctypes.c_int, use_errno=True)(
('sendfile', libc))
del libc
def sendfile_to_socket(fileobj, offset, size, socket_file):
timeout = socket_file.gettimeout()
if timeout == 0:
return copy_range(fileobj, offset, size, socket_file)
num_bytes = ctypes.c_int64(size)
total_sent = 0
while size > 0:
num_bytes.value = size
r, w, x = select([], [socket_file], [], timeout)
if not w:
raise socket.timeout('timed out in sendfile() waiting for socket to become writeable')
ret = sendfile(fileobj.fileno(), socket_file.fileno(), offset, ctypes.byref(num_bytes), None, 0)
if ret != 0:
err = ctypes.get_errno()
if err in (errno.EBADF, errno.ENOTSUP, errno.ENOTSOCK, errno.EOPNOTSUPP):
return copy_range(fileobj, offset, size, socket_file)
if err not in (errno.EINTR, errno.EAGAIN):
raise IOError((err, os.strerror(err)))
if num_bytes.value == 0:
break # EOF
total_sent += num_bytes.value
size -= num_bytes.value
offset += num_bytes.value
return total_sent
def sendfile_to_socket_async(fileobj, offset, size, socket_file):
num_bytes = ctypes.c_int64(size)
ret = sendfile(fileobj.fileno(), socket_file.fileno(), offset, ctypes.byref(num_bytes), None, 0)
if ret != 0:
err = ctypes.get_errno()
if err in (errno.EBADF, errno.ENOTSUP, errno.ENOTSOCK, errno.EOPNOTSUPP):
raise CannotSendfile()
if err == errno.EINTR:
raise SendfileInterrupted()
if err != errno.EAGAIN:
raise IOError((err, os.strerror(err)))
return num_bytes.value
elif islinux:
libc = ctypes.CDLL(None, use_errno=True)
sendfile = ctypes.CFUNCTYPE(
ctypes.c_ssize_t, ctypes.c_int, ctypes.c_int, ctypes.POINTER(ctypes.c_int64), ctypes.c_size_t, use_errno=True)(('sendfile64', libc))
del libc
def sendfile_to_socket(fileobj, offset, size, socket_file):
off = ctypes.c_int64(offset)
timeout = socket_file.gettimeout()
if timeout == 0:
return copy_range(fileobj, off.value, size, socket_file)
total_sent = 0
while size > 0:
r, w, x = select([], [socket_file], [], timeout)
if not w:
raise socket.timeout('timed out in sendfile() waiting for socket to become writeable')
sent = sendfile(socket_file.fileno(), fileobj.fileno(), ctypes.byref(off), size)
if sent < 0:
err = ctypes.get_errno()
if err in (errno.ENOSYS, errno.EINVAL):
return copy_range(fileobj, off.value, size, socket_file)
if err not in (errno.EINTR, errno.EAGAIN):
raise IOError((err, os.strerror(err)))
elif sent == 0:
break # EOF
else:
size -= sent
total_sent += sent
return total_sent
def sendfile_to_socket_async(fileobj, offset, size, socket_file):
off = ctypes.c_int64(offset)
sent = sendfile(socket_file.fileno(), fileobj.fileno(), ctypes.byref(off), size)
if sent < 0:
err = ctypes.get_errno()
if err in (errno.ENOSYS, errno.EINVAL):
raise CannotSendfile()
if err in (errno.EINTR, errno.EAGAIN):
raise SendfileInterrupted()
raise IOError((err, os.strerror(err)))
return sent
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
18,
199,
3,
6695,
26,
493,
2991,
29,
1624,
13,
24,
199,
504,
636,
2443,
363,
492,
334,
2975,
63,
5955,
12,
4629,
12,
3679,
63,
646,
12,
717,
870,
63,
1593,
9,
199,
199,
363,
1682,
363,
275,
283,
12006,
373,
19,
7,
199,
363,
7307,
363,
275,
283,
7806,
12,
1804,
79,
5017,
3971,
31876,
665,
7697,
5017,
737,
20817,
5017,
1939,
31876,
14,
846,
3524,
199,
199,
646,
747,
12,
5577,
12,
7554,
12,
2838,
199,
504,
5890,
492,
6186,
63,
10960,
63,
4305,
199,
504,
3504,
492,
3504,
199,
199,
504,
19238,
14,
5559,
492,
365,
5135,
12,
365,
28197,
199,
504,
19238,
14,
15165,
14,
1208,
492,
325,
442,
82,
63,
7154,
63,
1250,
199,
199,
318,
570,
63,
2343,
8,
9234,
304,
272,
862,
26,
267,
6111,
275,
11099,
14,
9843,
342,
267,
372,
747,
14,
32127,
8,
2592,
9,
272,
871,
2186,
26,
267,
986,
199,
199,
318,
1331,
63,
1842,
8,
2164,
63,
493,
12,
1343,
12,
1568,
12,
2053,
304,
272,
3141,
63,
1150,
275,
378,
272,
2928,
63,
493,
14,
5507,
8,
928,
9,
272,
1830,
1568,
690,
378,
26,
267,
666,
275,
325,
442,
82,
63,
7154,
63,
1250,
8,
2164,
63,
493,
14,
739,
12,
1748,
8,
890,
12,
6186,
63,
10960,
63,
4305,
430,
267,
340,
822,
8,
576,
9,
508,
378,
26,
288,
2059,
221,
327,
9027,
267,
2053,
14,
952,
8,
576,
9,
267,
1568,
4862,
822,
8,
576,
9,
267,
3141,
63,
1150,
847,
822,
8,
576,
9,
267,
2150,
666,
272,
372,
3141,
63,
1150,
199,
199,
533,
18435,
6795,
493,
8,
1726,
304,
272,
986,
199,
199,
533,
10217,
493,
2620,
15692,
8,
1726,
304,
272,
986,
199,
199,
2254,
493,
63,
475,
63,
3450,
275,
3222,
493,
63,
475,
63,
3450,
63,
4146,
275,
488,
199,
199,
692,
365,
28197,
26,
272,
1973,
67,
275,
5577,
14,
7695,
4464,
8,
403,
12,
675,
63,
7931,
29,
549,
9,
272,
3222,
493,
275,
5577,
14,
5487,
10637,
8,
267,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
442,
772,
12,
5577,
14,
11260,
8,
9798,
14,
67,
63,
442,
772,
395,
5577,
14,
67,
63,
1647,
63,
80,
12,
5577,
14,
67,
63,
442,
12,
675,
63,
7931,
29,
549,
5130,
288,
661,
2254,
493,
297,
1973,
67,
430,
272,
2150,
1973,
67,
339,
347,
3222,
493,
63,
475,
63,
3450,
8,
9234,
12,
3268,
12,
1568,
12,
2838,
63,
493,
304,
267,
2653,
275,
2838,
63,
493,
14,
362,
2593,
342,
267,
340,
2653,
508,
378,
26,
288,
372,
1331,
63,
1842,
8,
9234,
12,
3268,
12,
1568,
12,
2838,
63,
493,
9,
267,
1967,
63,
2394,
275,
5577,
14,
67,
63,
442,
772,
8,
890,
9,
267,
3141,
63,
1150,
275,
378,
267,
1830,
1568,
690,
378,
26,
288,
1967,
63,
2394,
14,
585,
275,
1568,
288,
519,
12,
336,
12,
671,
275,
3504,
8798,
359,
3450,
63,
493,
467,
990,
2653,
9,
288,
340,
440,
336,
26,
355,
746,
2838,
14,
2593,
360,
26687,
734,
315,
3222,
493,
342,
10923,
367,
2838,
370,
8649,
2218,
461,
358,
288,
2203,
275,
3222,
493,
8,
9234,
14,
9843,
1062,
2838,
63,
493,
14,
9843,
1062,
3268,
12,
5577,
14,
20447,
8,
1507,
63,
2394,
395,
488,
12,
378,
9,
288,
340,
2203,
1137,
378,
26,
355,
2329,
275,
5577,
14,
362,
63,
7931,
342,
355,
340,
2329,
315,
334,
7931,
14,
37,
9439,
38,
12,
7554,
14,
32710,
7380,
12,
7554,
14,
32710,
9469,
12,
7554,
14,
37,
1938,
4609,
7380,
48,
304,
490,
372,
1331,
63,
1842,
8,
9234,
12,
3268,
12,
1568,
12,
2838,
63,
493,
9,
355,
340,
2329,
440,
315,
334,
7931,
14,
37,
19652,
12,
7554,
14,
37,
1254,
9021,
304,
490,
746,
5925,
1332,
1508,
12,
747,
14,
20395,
8,
1508,
1724,
288,
340,
1967,
63,
2394,
14,
585,
508,
378,
26,
355,
2059,
221,
327,
9027,
288,
3141,
63,
1150,
847,
1967,
63,
2394,
14,
585,
288,
1568,
4862,
1967,
63,
2394,
14,
585,
288,
3268,
847,
1967,
63,
2394,
14,
585,
267,
372,
3141,
63,
1150,
339,
347,
3222,
493,
63,
475,
63,
3450,
63,
4146,
8,
9234,
12,
3268,
12,
1568,
12,
2838,
63,
493,
304,
267,
1967,
63,
2394,
275,
5577,
14,
67,
63,
442,
772,
8,
890,
9,
267,
2203,
275,
3222,
493,
8,
9234,
14,
9843,
1062,
2838,
63,
493,
14,
9843,
1062,
3268,
12,
5577,
14,
20447,
8,
1507,
63,
2394,
395,
488,
12,
378,
9,
267,
340,
2203,
1137,
378,
26,
288,
2329,
275,
5577,
14,
362,
63,
7931,
342,
288,
340,
2329,
315,
334,
7931,
14,
37,
9439,
38,
12,
7554,
14,
32710,
7380,
12,
7554,
14,
32710,
9469,
12,
7554,
14,
37,
1938,
4609,
7380,
48,
304,
355,
746,
18435,
6795,
493,
342,
288,
340,
2329,
508,
7554,
14,
37,
19652,
26,
355,
746,
10217,
493,
2620,
15692,
342,
288,
340,
2329,
1137,
7554,
14,
37,
1254,
9021,
26,
355,
746,
5925,
1332,
1508,
12,
747,
14,
20395,
8,
1508,
1724,
267,
372,
1967,
63,
2394,
14,
585,
199,
199,
4164,
365,
5135,
26,
272,
1973,
67,
275,
5577,
14,
7695,
4464,
8,
403,
12,
675,
63,
7931,
29,
549,
9,
272,
3222,
493,
275,
5577,
14,
5487,
10637,
8,
267,
5577,
14,
67,
63,
30104,
63,
84,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
11260,
8,
9798,
14,
67,
63,
442,
772,
395,
5577,
14,
67,
63,
890,
63,
84,
12,
675,
63,
7931,
29,
549,
9,
4725,
2254,
493,
772,
297,
1973,
67,
430,
272,
2150,
1973,
67,
339,
347,
3222,
493,
63,
475,
63,
3450,
8,
9234,
12,
3268,
12,
1568,
12,
2838,
63,
493,
304,
267,
2331,
275,
5577,
14,
67,
63,
442,
772,
8,
2743,
9,
267,
2653,
275,
2838,
63,
493,
14,
362,
2593,
342,
267,
340,
2653,
508,
378,
26,
288,
372,
1331,
63,
1842,
8,
9234,
12,
2331,
14,
585,
12,
1568,
12,
2838,
63,
493,
9,
267,
3141,
63,
1150,
275
] |
[
2647,
15,
1393,
15,
1813,
2366,
18,
199,
3,
6695,
26,
493,
2991,
29,
1624,
13,
24,
199,
504,
636,
2443,
363,
492,
334,
2975,
63,
5955,
12,
4629,
12,
3679,
63,
646,
12,
717,
870,
63,
1593,
9,
199,
199,
363,
1682,
363,
275,
283,
12006,
373,
19,
7,
199,
363,
7307,
363,
275,
283,
7806,
12,
1804,
79,
5017,
3971,
31876,
665,
7697,
5017,
737,
20817,
5017,
1939,
31876,
14,
846,
3524,
199,
199,
646,
747,
12,
5577,
12,
7554,
12,
2838,
199,
504,
5890,
492,
6186,
63,
10960,
63,
4305,
199,
504,
3504,
492,
3504,
199,
199,
504,
19238,
14,
5559,
492,
365,
5135,
12,
365,
28197,
199,
504,
19238,
14,
15165,
14,
1208,
492,
325,
442,
82,
63,
7154,
63,
1250,
199,
199,
318,
570,
63,
2343,
8,
9234,
304,
272,
862,
26,
267,
6111,
275,
11099,
14,
9843,
342,
267,
372,
747,
14,
32127,
8,
2592,
9,
272,
871,
2186,
26,
267,
986,
199,
199,
318,
1331,
63,
1842,
8,
2164,
63,
493,
12,
1343,
12,
1568,
12,
2053,
304,
272,
3141,
63,
1150,
275,
378,
272,
2928,
63,
493,
14,
5507,
8,
928,
9,
272,
1830,
1568,
690,
378,
26,
267,
666,
275,
325,
442,
82,
63,
7154,
63,
1250,
8,
2164,
63,
493,
14,
739,
12,
1748,
8,
890,
12,
6186,
63,
10960,
63,
4305,
430,
267,
340,
822,
8,
576,
9,
508,
378,
26,
288,
2059,
221,
327,
9027,
267,
2053,
14,
952,
8,
576,
9,
267,
1568,
4862,
822,
8,
576,
9,
267,
3141,
63,
1150,
847,
822,
8,
576,
9,
267,
2150,
666,
272,
372,
3141,
63,
1150,
199,
199,
533,
18435,
6795,
493,
8,
1726,
304,
272,
986,
199,
199,
533,
10217,
493,
2620,
15692,
8,
1726,
304,
272,
986,
199,
199,
2254,
493,
63,
475,
63,
3450,
275,
3222,
493,
63,
475,
63,
3450,
63,
4146,
275,
488,
199,
199,
692,
365,
28197,
26,
272,
1973,
67,
275,
5577,
14,
7695,
4464,
8,
403,
12,
675,
63,
7931,
29,
549,
9,
272,
3222,
493,
275,
5577,
14,
5487,
10637,
8,
267,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
442,
772,
12,
5577,
14,
11260,
8,
9798,
14,
67,
63,
442,
772,
395,
5577,
14,
67,
63,
1647,
63,
80,
12,
5577,
14,
67,
63,
442,
12,
675,
63,
7931,
29,
549,
5130,
288,
661,
2254,
493,
297,
1973,
67,
430,
272,
2150,
1973,
67,
339,
347,
3222,
493,
63,
475,
63,
3450,
8,
9234,
12,
3268,
12,
1568,
12,
2838,
63,
493,
304,
267,
2653,
275,
2838,
63,
493,
14,
362,
2593,
342,
267,
340,
2653,
508,
378,
26,
288,
372,
1331,
63,
1842,
8,
9234,
12,
3268,
12,
1568,
12,
2838,
63,
493,
9,
267,
1967,
63,
2394,
275,
5577,
14,
67,
63,
442,
772,
8,
890,
9,
267,
3141,
63,
1150,
275,
378,
267,
1830,
1568,
690,
378,
26,
288,
1967,
63,
2394,
14,
585,
275,
1568,
288,
519,
12,
336,
12,
671,
275,
3504,
8798,
359,
3450,
63,
493,
467,
990,
2653,
9,
288,
340,
440,
336,
26,
355,
746,
2838,
14,
2593,
360,
26687,
734,
315,
3222,
493,
342,
10923,
367,
2838,
370,
8649,
2218,
461,
358,
288,
2203,
275,
3222,
493,
8,
9234,
14,
9843,
1062,
2838,
63,
493,
14,
9843,
1062,
3268,
12,
5577,
14,
20447,
8,
1507,
63,
2394,
395,
488,
12,
378,
9,
288,
340,
2203,
1137,
378,
26,
355,
2329,
275,
5577,
14,
362,
63,
7931,
342,
355,
340,
2329,
315,
334,
7931,
14,
37,
9439,
38,
12,
7554,
14,
32710,
7380,
12,
7554,
14,
32710,
9469,
12,
7554,
14,
37,
1938,
4609,
7380,
48,
304,
490,
372,
1331,
63,
1842,
8,
9234,
12,
3268,
12,
1568,
12,
2838,
63,
493,
9,
355,
340,
2329,
440,
315,
334,
7931,
14,
37,
19652,
12,
7554,
14,
37,
1254,
9021,
304,
490,
746,
5925,
1332,
1508,
12,
747,
14,
20395,
8,
1508,
1724,
288,
340,
1967,
63,
2394,
14,
585,
508,
378,
26,
355,
2059,
221,
327,
9027,
288,
3141,
63,
1150,
847,
1967,
63,
2394,
14,
585,
288,
1568,
4862,
1967,
63,
2394,
14,
585,
288,
3268,
847,
1967,
63,
2394,
14,
585,
267,
372,
3141,
63,
1150,
339,
347,
3222,
493,
63,
475,
63,
3450,
63,
4146,
8,
9234,
12,
3268,
12,
1568,
12,
2838,
63,
493,
304,
267,
1967,
63,
2394,
275,
5577,
14,
67,
63,
442,
772,
8,
890,
9,
267,
2203,
275,
3222,
493,
8,
9234,
14,
9843,
1062,
2838,
63,
493,
14,
9843,
1062,
3268,
12,
5577,
14,
20447,
8,
1507,
63,
2394,
395,
488,
12,
378,
9,
267,
340,
2203,
1137,
378,
26,
288,
2329,
275,
5577,
14,
362,
63,
7931,
342,
288,
340,
2329,
315,
334,
7931,
14,
37,
9439,
38,
12,
7554,
14,
32710,
7380,
12,
7554,
14,
32710,
9469,
12,
7554,
14,
37,
1938,
4609,
7380,
48,
304,
355,
746,
18435,
6795,
493,
342,
288,
340,
2329,
508,
7554,
14,
37,
19652,
26,
355,
746,
10217,
493,
2620,
15692,
342,
288,
340,
2329,
1137,
7554,
14,
37,
1254,
9021,
26,
355,
746,
5925,
1332,
1508,
12,
747,
14,
20395,
8,
1508,
1724,
267,
372,
1967,
63,
2394,
14,
585,
199,
199,
4164,
365,
5135,
26,
272,
1973,
67,
275,
5577,
14,
7695,
4464,
8,
403,
12,
675,
63,
7931,
29,
549,
9,
272,
3222,
493,
275,
5577,
14,
5487,
10637,
8,
267,
5577,
14,
67,
63,
30104,
63,
84,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
67,
63,
442,
12,
5577,
14,
11260,
8,
9798,
14,
67,
63,
442,
772,
395,
5577,
14,
67,
63,
890,
63,
84,
12,
675,
63,
7931,
29,
549,
9,
4725,
2254,
493,
772,
297,
1973,
67,
430,
272,
2150,
1973,
67,
339,
347,
3222,
493,
63,
475,
63,
3450,
8,
9234,
12,
3268,
12,
1568,
12,
2838,
63,
493,
304,
267,
2331,
275,
5577,
14,
67,
63,
442,
772,
8,
2743,
9,
267,
2653,
275,
2838,
63,
493,
14,
362,
2593,
342,
267,
340,
2653,
508,
378,
26,
288,
372,
1331,
63,
1842,
8,
9234,
12,
2331,
14,
585,
12,
1568,
12,
2838,
63,
493,
9,
267,
3141,
63,
1150,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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demo/text_demo.py
|
32
|
10572
|
###
## * << Haru Free PDF Library 2.0.0 >> -- text_demo.c
## *
## * Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
## *
## * Permission to use, copy, modify, distribute and sell this software
## * and its documentation for any purpose is hereby granted without fee,
## * provided that the above copyright notice appear in all copies and
## * that both that copyright notice and this permission notice appear
## * in supporting documentation.
## * It is provided "as is" without express or implied warranty.
## *
##
## port to python by Li Jun
## http://groups.google.com/group/pythoncia
import os, sys
from ctypes import *
up=2
def setlibpath(up):
import sys
path=os.path.normpath(os.path.split(os.path.realpath(__file__))[0]+'\..'*up)
if path not in sys.path:
sys.path.append(path)
setlibpath(up)
from haru import *
from haru.c_func import *
from haru.hpdf_errorcode import *
from grid_sheet import *
from math import *
@HPDF_Error_Handler(None, HPDF_UINT, HPDF_UINT, c_void_p)
def error_handler (error_no, detail_no, user_data):
global pdf
printf ("ERROR: %s, detail_no=%u\n", error_detail[error_no],
detail_no)
HPDF_Free (pdf)
sys.exit(1)
def show_stripe_pattern (page, x, y):
iy = 0
while (iy < 50):
HPDF_Page_SetRGBStroke (page, 0.0, 0.0, 0.5)
HPDF_Page_SetLineWidth (page, 1)
HPDF_Page_MoveTo (page, x, y + iy)
HPDF_Page_LineTo (page, x + HPDF_Page_TextWidth (page, "ABCabc123"),
y + iy)
HPDF_Page_Stroke (page)
iy += 3
HPDF_Page_SetLineWidth (page, 2.5)
def show_description (page, x, y, text):
fsize = HPDF_Page_GetCurrentFontSize (page)
font = HPDF_Page_GetCurrentFont (page)
c = HPDF_Page_GetRGBFill (page)
HPDF_Page_BeginText (page)
HPDF_Page_SetRGBFill (page, 0, 0, 0)
HPDF_Page_SetTextRenderingMode (page, HPDF_FILL)
HPDF_Page_SetFontAndSize (page, font, 10)
HPDF_Page_TextOut (page, x, y - 12, text)
HPDF_Page_EndText (page)
HPDF_Page_SetFontAndSize (page, font, fsize)
HPDF_Page_SetRGBFill (page, c.r, c.g, c.b)
def main ():
global pdf
page_title = "Text Demo"
samp_text = "abcdefgABCDEFG123!#$%&+-@?"
samp_text2 = "The quick brown fox jumps over the lazy dog."
fname=os.path.realpath(sys.argv[0])
fname=fname[:fname.rfind('.')]+'.pdf'
pdf = HPDF_New (error_handler, NULL)
if (not pdf):
printf ("error: cannot create PdfDoc object\n")
return 1
# set compression mode
HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL)
# create default-font
font = HPDF_GetFont (pdf, "Helvetica", NULL)
# add a new page object.
page = HPDF_AddPage (pdf)
# draw grid to the page
print_grid (pdf, page)
# print the lines of the page.
HPDF_Page_SetLineWidth (page, 1)
HPDF_Page_Rectangle (page, 50, 50, HPDF_Page_GetWidth(page) - 100,
HPDF_Page_GetHeight (page) - 110)
HPDF_Page_Stroke (page)
# print the title of the page (with positioning center).
HPDF_Page_SetFontAndSize (page, font, 24)
tw = HPDF_Page_TextWidth (page, page_title)
HPDF_Page_BeginText (page)
HPDF_Page_TextOut (page, (HPDF_Page_GetWidth(page) - tw) / 2,
HPDF_Page_GetHeight (page) - 50, page_title)
HPDF_Page_EndText (page)
HPDF_Page_BeginText (page)
HPDF_Page_MoveTextPos (page, 60, HPDF_Page_GetHeight(page) - 60)
# font size
fsize = 8
while (fsize < 60):
# set style and size of font.
HPDF_Page_SetFontAndSize(page, font, fsize)
# set the position of the text.
HPDF_Page_MoveTextPos (page, 0, -5 - fsize)
# measure the number of characters which included in the page.
buf= samp_text
length = HPDF_Page_MeasureText (page, samp_text,
HPDF_Page_GetWidth(page) - 120, HPDF_FALSE, NULL)
# truncate the text.
buf='%*s\0' %(int(length), buf)
HPDF_Page_ShowText (page, buf)
# print the description.
HPDF_Page_MoveTextPos (page, 0, -10)
HPDF_Page_SetFontAndSize(page, font, 8)
buf="Fontsize=%.0f" %fsize
HPDF_Page_ShowText (page, buf)
fsize *= 1.5
# font color
HPDF_Page_SetFontAndSize(page, font, 8)
HPDF_Page_MoveTextPos (page, 0, -30)
HPDF_Page_ShowText (page, "Font color")
HPDF_Page_SetFontAndSize (page, font, 18)
HPDF_Page_MoveTextPos (page, 0, -20)
length = len (samp_text)
for i in range(length):
buf=[None ,None]
r = i / float(length)
g = 1 - (i / float(length))
buf[0] = samp_text[i]
buf[1] = '\0'
HPDF_Page_SetRGBFill (page, r, g, 0.0)
HPDF_Page_ShowText (page, buf)
HPDF_Page_MoveTextPos (page, 0, -25)
for i in range(length):
buf=[None ,None]
r = i / float(length)
b = 1 - (i / float(length))
buf[0] = samp_text[i]
buf[1] = '\0'
HPDF_Page_SetRGBFill (page, r, 0.0, b)
HPDF_Page_ShowText (page, buf)
HPDF_Page_MoveTextPos (page, 0, -25)
for i in range(length):
buf=[None ,None]
b = i / float(length)
g = 1 - (i / float(length))
buf[0] = samp_text[i]
buf[1] = '\0'
HPDF_Page_SetRGBFill (page, 0.0, g, b)
HPDF_Page_ShowText (page, buf)
HPDF_Page_EndText (page)
ypos = 450
#
# Font rendering mode
#
HPDF_Page_SetFontAndSize(page, font, 32)
HPDF_Page_SetRGBFill (page, 0.5, 0.5, 0.0)
HPDF_Page_SetLineWidth (page, 1.5)
# PDF_FILL
show_description (page, 60, ypos,
"RenderingMode=PDF_FILL")
HPDF_Page_SetTextRenderingMode (page, HPDF_FILL)
HPDF_Page_BeginText (page)
HPDF_Page_TextOut (page, 60, ypos, "ABCabc123")
HPDF_Page_EndText (page)
# PDF_STROKE
show_description (page, 60, ypos - 50,
"RenderingMode=PDF_STROKE")
HPDF_Page_SetTextRenderingMode (page, HPDF_STROKE)
HPDF_Page_BeginText (page)
HPDF_Page_TextOut (page, 60, ypos - 50, "ABCabc123")
HPDF_Page_EndText (page)
# PDF_FILL_THEN_STROKE
show_description (page, 60, ypos - 100,
"RenderingMode=PDF_FILL_THEN_STROKE")
HPDF_Page_SetTextRenderingMode (page, HPDF_FILL_THEN_STROKE)
HPDF_Page_BeginText (page)
HPDF_Page_TextOut (page, 60, ypos - 100, "ABCabc123")
HPDF_Page_EndText (page)
# PDF_FILL_CLIPPING
show_description (page, 60, ypos - 150,
"RenderingMode=PDF_FILL_CLIPPING")
HPDF_Page_GSave (page)
HPDF_Page_SetTextRenderingMode (page, HPDF_FILL_CLIPPING)
HPDF_Page_BeginText (page)
HPDF_Page_TextOut (page, 60, ypos - 150, "ABCabc123")
HPDF_Page_EndText (page)
show_stripe_pattern (page, 60, ypos - 150)
HPDF_Page_GRestore (page)
# PDF_STROKE_CLIPPING
show_description (page, 60, ypos - 200,
"RenderingMode=PDF_STROKE_CLIPPING")
HPDF_Page_GSave (page)
HPDF_Page_SetTextRenderingMode (page, HPDF_STROKE_CLIPPING)
HPDF_Page_BeginText (page)
HPDF_Page_TextOut (page, 60, ypos - 200, "ABCabc123")
HPDF_Page_EndText (page)
show_stripe_pattern (page, 60, ypos - 200)
HPDF_Page_GRestore (page)
# PDF_FILL_STROKE_CLIPPING
show_description (page, 60, ypos - 250,
"RenderingMode=PDF_FILL_STROKE_CLIPPING")
HPDF_Page_GSave (page)
HPDF_Page_SetTextRenderingMode (page, HPDF_FILL_STROKE_CLIPPING)
HPDF_Page_BeginText (page)
HPDF_Page_TextOut (page, 60, ypos - 250, "ABCabc123")
HPDF_Page_EndText (page)
show_stripe_pattern (page, 60, ypos - 250)
HPDF_Page_GRestore (page)
# Reset text attributes
HPDF_Page_SetTextRenderingMode (page, HPDF_FILL)
HPDF_Page_SetRGBFill (page, 0, 0, 0)
HPDF_Page_SetFontAndSize(page, font, 30)
#
# Rotating text
#
angle1 = 30; # A rotation of 30 degrees.
rad1 = angle1 / 180 * 3.141592; # Calcurate the radian value.
show_description (page, 320, ypos - 60, "Rotating text")
HPDF_Page_BeginText (page)
HPDF_Page_SetTextMatrix (page, cos(rad1), sin(rad1), -sin(rad1), cos(rad1),
330, ypos - 60)
HPDF_Page_ShowText (page, "ABCabc123")
HPDF_Page_EndText (page)
#
# Skewing text.
#
show_description (page, 320, ypos - 120, "Skewing text")
HPDF_Page_BeginText (page)
angle1 = 10
angle2 = 20
rad1 = angle1 / 180 * 3.141592
rad2 = angle2 / 180 * 3.141592
HPDF_Page_SetTextMatrix (page, 1, tan(rad1), tan(rad2), 1, 320, ypos - 120)
HPDF_Page_ShowText (page, "ABCabc123")
HPDF_Page_EndText (page)
#
# scaling text (X direction)
#
show_description (page, 320, ypos - 175, "Scaling text (X direction)")
HPDF_Page_BeginText (page)
HPDF_Page_SetTextMatrix (page, 1.5, 0, 0, 1, 320, ypos - 175)
HPDF_Page_ShowText (page, "ABCabc12")
HPDF_Page_EndText (page)
#
# scaling text (Y direction)
#
show_description (page, 320, ypos - 250, "Scaling text (Y direction)")
HPDF_Page_BeginText (page)
HPDF_Page_SetTextMatrix (page, 1, 0, 0, 2, 320, ypos - 250)
HPDF_Page_ShowText (page, "ABCabc123")
HPDF_Page_EndText (page)
#
# char spacing, word spacing
#
show_description (page, 60, 140, "char-spacing 0")
show_description (page, 60, 100, "char-spacing 1.5")
show_description (page, 60, 60, "char-spacing 1.5, word-spacing 2.5")
HPDF_Page_SetFontAndSize (page, font, 20)
HPDF_Page_SetRGBFill (page, 0.1, 0.3, 0.1)
## char-spacing 0
HPDF_Page_BeginText (page)
HPDF_Page_TextOut (page, 60, 140, samp_text2)
HPDF_Page_EndText (page)
# char-spacing 1.5
HPDF_Page_SetCharSpace (page, 1.5)
HPDF_Page_BeginText (page)
HPDF_Page_TextOut (page, 60, 100, samp_text2)
HPDF_Page_EndText (page)
# char-spacing 1.5, word-spacing 3.5
HPDF_Page_SetWordSpace (page, 2.5)
HPDF_Page_BeginText (page)
HPDF_Page_TextOut (page, 60, 60, samp_text2)
HPDF_Page_EndText (page)
# save the document to a file
HPDF_SaveToFile (pdf, fname)
# clean up
HPDF_Free (pdf)
return 0
main()
|
gpl-3.0
|
[
5680,
202,
199,
309,
627,
5213,
25378,
85,
2868,
15537,
11243,
499,
14,
16,
14,
16,
4331,
1553,
1318,
63,
8768,
14,
67,
202,
199,
309,
627,
202,
199,
309,
627,
1898,
334,
67,
9,
21300,
13,
7968,
17415,
5812,
1804,
25264,
665,
31613,
5812,
63,
75,
25264,
32,
597,
14,
5812,
13,
526,
14,
685,
14,
11538,
30,
202,
199,
309,
627,
202,
199,
309,
627,
8779,
370,
675,
12,
1331,
12,
2811,
12,
11207,
436,
12743,
642,
2032,
202,
199,
309,
627,
436,
2399,
3794,
367,
1263,
12016,
365,
11882,
10009,
1928,
14751,
12,
202,
199,
309,
627,
2741,
626,
314,
3432,
4248,
4245,
7468,
315,
1006,
6866,
436,
202,
199,
309,
627,
626,
3865,
626,
4248,
4245,
436,
642,
4983,
4245,
7468,
202,
199,
309,
627,
315,
21038,
3794,
14,
202,
199,
309,
627,
2779,
365,
2741,
298,
305,
365,
2,
1928,
4056,
503,
2478,
3750,
14,
202,
199,
309,
627,
202,
199,
309,
2999,
199,
309,
1844,
370,
2366,
701,
24157,
1603,
324,
202,
199,
309,
1455,
921,
2634,
14,
3098,
14,
957,
15,
923,
15,
1548,
16521,
2999,
199,
646,
747,
12,
984,
2999,
199,
504,
5577,
492,
627,
202,
199,
384,
29,
18,
202,
199,
318,
663,
773,
515,
8,
384,
304,
1128,
492,
984,
1128,
931,
29,
736,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
59,
16,
2807,
1154,
703,
16804,
384,
9,
1128,
340,
931,
440,
315,
984,
14,
515,
26,
1039,
984,
14,
515,
14,
740,
8,
515,
9,
2999,
199,
409,
773,
515,
8,
384,
9,
2999,
199,
504,
12159,
85,
492,
627,
202,
199,
504,
12159,
85,
14,
67,
63,
1532,
492,
627,
202,
199,
504,
12159,
85,
14,
72,
5607,
63,
28857,
492,
627,
202,
199,
504,
6068,
63,
5069,
492,
627,
2999,
199,
504,
3473,
492,
627,
2999,
199,
32,
14036,
63,
547,
63,
2461,
8,
403,
12,
24006,
63,
17459,
12,
24006,
63,
17459,
12,
286,
63,
1647,
63,
80,
9,
202,
199,
318,
1125,
63,
2232,
334,
705,
63,
889,
12,
10093,
63,
889,
12,
922,
63,
576,
304,
1128,
2288,
11249,
1128,
870,
70,
1689,
3170,
26,
450,
83,
12,
10093,
63,
889,
2458,
85,
60,
78,
401,
1125,
63,
5506,
59,
705,
63,
889,
467,
2628,
10093,
63,
889,
9,
1128,
24006,
63,
10146,
334,
5607,
9,
1128,
984,
14,
2224,
8,
17,
9,
2999,
199,
318,
2498,
63,
19025,
63,
3401,
221,
334,
1606,
12,
671,
12,
612,
304,
1128,
284,
89,
275,
378,
2958,
1830,
334,
31256,
665,
5238,
304,
1039,
24006,
63,
3276,
63,
1084,
12067,
32492,
334,
1606,
12,
378,
14,
16,
12,
378,
14,
16,
12,
378,
14,
21,
9,
1039,
24006,
63,
3276,
63,
1084,
3049,
6216,
334,
1606,
12,
413,
9,
1039,
24006,
63,
3276,
63,
10370,
1378,
334,
1606,
12,
671,
12,
612,
435,
284,
89,
9,
1039,
24006,
63,
3276,
63,
19885,
334,
1606,
12,
671,
435,
24006,
63,
3276,
63,
1872,
6216,
334,
1606,
12,
298,
8390,
3175,
4288,
1288,
4906,
612,
435,
284,
89,
9,
1039,
24006,
63,
3276,
63,
32492,
334,
1606,
9,
1039,
284,
89,
847,
650,
2958,
24006,
63,
3276,
63,
1084,
3049,
6216,
334,
1606,
12,
499,
14,
21,
9,
8065,
199,
318,
2498,
63,
1802,
221,
334,
1606,
12,
671,
12,
612,
12,
1318,
304,
1128,
289,
890,
275,
24006,
63,
3276,
63,
29058,
6986,
2320,
334,
1606,
9,
1128,
5023,
275,
24006,
63,
3276,
63,
29058,
6986,
334,
1606,
9,
1128,
286,
275,
24006,
63,
3276,
63,
1002,
12067,
12914,
334,
1606,
9,
2958,
24006,
63,
3276,
63,
5595,
1872,
334,
1606,
9,
1128,
24006,
63,
3276,
63,
1084,
12067,
12914,
334,
1606,
12,
378,
12,
378,
12,
378,
9,
1128,
24006,
63,
3276,
63,
1084,
1872,
9216,
316,
1385,
334,
1606,
12,
24006,
63,
5110,
44,
9,
1128,
24006,
63,
3276,
63,
1084,
6986,
3325,
2320,
334,
1606,
12,
5023,
12,
1616,
9,
1128,
24006,
63,
3276,
63,
1872,
2204,
334,
1606,
12,
671,
12,
612,
446,
3144,
12,
1318,
9,
1128,
24006,
63,
3276,
63,
3005,
1872,
334,
1606,
9,
2958,
24006,
63,
3276,
63,
1084,
6986,
3325,
2320,
334,
1606,
12,
5023,
12,
289,
890,
9,
1128,
24006,
63,
3276,
63,
1084,
12067,
12914,
334,
1606,
12,
286,
14,
82,
12,
286,
14,
71,
12,
286,
14,
66,
9,
1223,
8065,
199,
318,
2446,
23390,
1128,
2288,
11249,
2958,
2034,
63,
1213,
275,
298,
1872,
28939,
2,
18801,
2937,
311,
63,
505,
275,
298,
10678,
71,
22897,
4288,
1,
3,
22074,
6,
16341,
32,
13472,
1128,
2937,
311,
63,
505,
18,
275,
298,
1918,
12530,
330,
18406,
7090,
88,
14882,
83,
1806,
314,
9617,
23454,
2122,
2958,
6748,
29,
736,
14,
515,
14,
11091,
8,
1274,
14,
3020,
59,
16,
566,
1128,
6748,
29,
5252,
1491,
5252,
14,
14542,
7563,
2807,
1370,
5607,
7,
2958,
11249,
275,
24006,
63,
4665,
334,
705,
63,
2232,
12,
5962,
9,
1128,
340,
334,
1397,
11249,
304,
1039,
870,
70,
1689,
705,
26,
3913,
1218,
510,
1587,
3768,
909,
60,
78,
531,
1039,
372,
413,
2958,
327,
663,
10291,
818,
1128,
24006,
63,
1084,
25551,
1385,
334,
5607,
12,
24006,
63,
6790,
63,
1761,
9,
2958,
327,
1218,
849,
13,
4246,
1128,
5023,
275,
24006,
63,
1002,
6986,
334,
5607,
12,
298,
40,
25911,
401,
5962,
9,
2958,
327,
1050,
282,
892,
2034,
909,
14,
1128,
2034,
275,
24006,
63,
1123,
3276,
334,
5607,
9,
2958,
327,
5954,
6068,
370,
314,
2034,
1128,
870,
63,
3825,
221,
334,
5607,
12,
2034,
9,
2958,
327,
870,
314,
2385,
402,
314,
2034,
14,
1128,
24006,
63,
3276,
63,
1084,
3049,
6216,
334,
1606,
12,
413,
9,
1128,
24006,
63,
3276,
63,
18127,
334,
1606,
12,
5238,
12,
5238,
12,
24006,
63,
3276,
63,
1002,
6216,
8,
1606,
9,
446,
2948,
12,
2628,
24006,
63,
3276,
63,
1002,
8436,
334,
1606,
9,
446,
16814,
9,
1128,
24006,
63,
3276,
63,
32492,
334,
1606,
9,
18801,
327,
870,
314,
2538,
402,
314,
2034,
334,
1045,
3421,
316,
8126,
680,
1128,
24006,
63,
3276,
63,
1084,
6986,
3325,
2320,
334,
1606,
12,
5023,
12
] |
[
202,
199,
309,
627,
5213,
25378,
85,
2868,
15537,
11243,
499,
14,
16,
14,
16,
4331,
1553,
1318,
63,
8768,
14,
67,
202,
199,
309,
627,
202,
199,
309,
627,
1898,
334,
67,
9,
21300,
13,
7968,
17415,
5812,
1804,
25264,
665,
31613,
5812,
63,
75,
25264,
32,
597,
14,
5812,
13,
526,
14,
685,
14,
11538,
30,
202,
199,
309,
627,
202,
199,
309,
627,
8779,
370,
675,
12,
1331,
12,
2811,
12,
11207,
436,
12743,
642,
2032,
202,
199,
309,
627,
436,
2399,
3794,
367,
1263,
12016,
365,
11882,
10009,
1928,
14751,
12,
202,
199,
309,
627,
2741,
626,
314,
3432,
4248,
4245,
7468,
315,
1006,
6866,
436,
202,
199,
309,
627,
626,
3865,
626,
4248,
4245,
436,
642,
4983,
4245,
7468,
202,
199,
309,
627,
315,
21038,
3794,
14,
202,
199,
309,
627,
2779,
365,
2741,
298,
305,
365,
2,
1928,
4056,
503,
2478,
3750,
14,
202,
199,
309,
627,
202,
199,
309,
2999,
199,
309,
1844,
370,
2366,
701,
24157,
1603,
324,
202,
199,
309,
1455,
921,
2634,
14,
3098,
14,
957,
15,
923,
15,
1548,
16521,
2999,
199,
646,
747,
12,
984,
2999,
199,
504,
5577,
492,
627,
202,
199,
384,
29,
18,
202,
199,
318,
663,
773,
515,
8,
384,
304,
1128,
492,
984,
1128,
931,
29,
736,
14,
515,
14,
9267,
8,
736,
14,
515,
14,
1294,
8,
736,
14,
515,
14,
11091,
3460,
493,
8964,
59,
16,
2807,
1154,
703,
16804,
384,
9,
1128,
340,
931,
440,
315,
984,
14,
515,
26,
1039,
984,
14,
515,
14,
740,
8,
515,
9,
2999,
199,
409,
773,
515,
8,
384,
9,
2999,
199,
504,
12159,
85,
492,
627,
202,
199,
504,
12159,
85,
14,
67,
63,
1532,
492,
627,
202,
199,
504,
12159,
85,
14,
72,
5607,
63,
28857,
492,
627,
202,
199,
504,
6068,
63,
5069,
492,
627,
2999,
199,
504,
3473,
492,
627,
2999,
199,
32,
14036,
63,
547,
63,
2461,
8,
403,
12,
24006,
63,
17459,
12,
24006,
63,
17459,
12,
286,
63,
1647,
63,
80,
9,
202,
199,
318,
1125,
63,
2232,
334,
705,
63,
889,
12,
10093,
63,
889,
12,
922,
63,
576,
304,
1128,
2288,
11249,
1128,
870,
70,
1689,
3170,
26,
450,
83,
12,
10093,
63,
889,
2458,
85,
60,
78,
401,
1125,
63,
5506,
59,
705,
63,
889,
467,
2628,
10093,
63,
889,
9,
1128,
24006,
63,
10146,
334,
5607,
9,
1128,
984,
14,
2224,
8,
17,
9,
2999,
199,
318,
2498,
63,
19025,
63,
3401,
221,
334,
1606,
12,
671,
12,
612,
304,
1128,
284,
89,
275,
378,
2958,
1830,
334,
31256,
665,
5238,
304,
1039,
24006,
63,
3276,
63,
1084,
12067,
32492,
334,
1606,
12,
378,
14,
16,
12,
378,
14,
16,
12,
378,
14,
21,
9,
1039,
24006,
63,
3276,
63,
1084,
3049,
6216,
334,
1606,
12,
413,
9,
1039,
24006,
63,
3276,
63,
10370,
1378,
334,
1606,
12,
671,
12,
612,
435,
284,
89,
9,
1039,
24006,
63,
3276,
63,
19885,
334,
1606,
12,
671,
435,
24006,
63,
3276,
63,
1872,
6216,
334,
1606,
12,
298,
8390,
3175,
4288,
1288,
4906,
612,
435,
284,
89,
9,
1039,
24006,
63,
3276,
63,
32492,
334,
1606,
9,
1039,
284,
89,
847,
650,
2958,
24006,
63,
3276,
63,
1084,
3049,
6216,
334,
1606,
12,
499,
14,
21,
9,
8065,
199,
318,
2498,
63,
1802,
221,
334,
1606,
12,
671,
12,
612,
12,
1318,
304,
1128,
289,
890,
275,
24006,
63,
3276,
63,
29058,
6986,
2320,
334,
1606,
9,
1128,
5023,
275,
24006,
63,
3276,
63,
29058,
6986,
334,
1606,
9,
1128,
286,
275,
24006,
63,
3276,
63,
1002,
12067,
12914,
334,
1606,
9,
2958,
24006,
63,
3276,
63,
5595,
1872,
334,
1606,
9,
1128,
24006,
63,
3276,
63,
1084,
12067,
12914,
334,
1606,
12,
378,
12,
378,
12,
378,
9,
1128,
24006,
63,
3276,
63,
1084,
1872,
9216,
316,
1385,
334,
1606,
12,
24006,
63,
5110,
44,
9,
1128,
24006,
63,
3276,
63,
1084,
6986,
3325,
2320,
334,
1606,
12,
5023,
12,
1616,
9,
1128,
24006,
63,
3276,
63,
1872,
2204,
334,
1606,
12,
671,
12,
612,
446,
3144,
12,
1318,
9,
1128,
24006,
63,
3276,
63,
3005,
1872,
334,
1606,
9,
2958,
24006,
63,
3276,
63,
1084,
6986,
3325,
2320,
334,
1606,
12,
5023,
12,
289,
890,
9,
1128,
24006,
63,
3276,
63,
1084,
12067,
12914,
334,
1606,
12,
286,
14,
82,
12,
286,
14,
71,
12,
286,
14,
66,
9,
1223,
8065,
199,
318,
2446,
23390,
1128,
2288,
11249,
2958,
2034,
63,
1213,
275,
298,
1872,
28939,
2,
18801,
2937,
311,
63,
505,
275,
298,
10678,
71,
22897,
4288,
1,
3,
22074,
6,
16341,
32,
13472,
1128,
2937,
311,
63,
505,
18,
275,
298,
1918,
12530,
330,
18406,
7090,
88,
14882,
83,
1806,
314,
9617,
23454,
2122,
2958,
6748,
29,
736,
14,
515,
14,
11091,
8,
1274,
14,
3020,
59,
16,
566,
1128,
6748,
29,
5252,
1491,
5252,
14,
14542,
7563,
2807,
1370,
5607,
7,
2958,
11249,
275,
24006,
63,
4665,
334,
705,
63,
2232,
12,
5962,
9,
1128,
340,
334,
1397,
11249,
304,
1039,
870,
70,
1689,
705,
26,
3913,
1218,
510,
1587,
3768,
909,
60,
78,
531,
1039,
372,
413,
2958,
327,
663,
10291,
818,
1128,
24006,
63,
1084,
25551,
1385,
334,
5607,
12,
24006,
63,
6790,
63,
1761,
9,
2958,
327,
1218,
849,
13,
4246,
1128,
5023,
275,
24006,
63,
1002,
6986,
334,
5607,
12,
298,
40,
25911,
401,
5962,
9,
2958,
327,
1050,
282,
892,
2034,
909,
14,
1128,
2034,
275,
24006,
63,
1123,
3276,
334,
5607,
9,
2958,
327,
5954,
6068,
370,
314,
2034,
1128,
870,
63,
3825,
221,
334,
5607,
12,
2034,
9,
2958,
327,
870,
314,
2385,
402,
314,
2034,
14,
1128,
24006,
63,
3276,
63,
1084,
3049,
6216,
334,
1606,
12,
413,
9,
1128,
24006,
63,
3276,
63,
18127,
334,
1606,
12,
5238,
12,
5238,
12,
24006,
63,
3276,
63,
1002,
6216,
8,
1606,
9,
446,
2948,
12,
2628,
24006,
63,
3276,
63,
1002,
8436,
334,
1606,
9,
446,
16814,
9,
1128,
24006,
63,
3276,
63,
32492,
334,
1606,
9,
18801,
327,
870,
314,
2538,
402,
314,
2034,
334,
1045,
3421,
316,
8126,
680,
1128,
24006,
63,
3276,
63,
1084,
6986,
3325,
2320,
334,
1606,
12,
5023,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
sdague/home-assistant
|
homeassistant/components/clicksend_tts/notify.py
|
21
|
3260
|
"""clicksend_tts platform for notify component."""
import json
import logging
from aiohttp.hdrs import CONTENT_TYPE
import requests
import voluptuous as vol
from homeassistant.components.notify import PLATFORM_SCHEMA, BaseNotificationService
from homeassistant.const import (
CONF_API_KEY,
CONF_RECIPIENT,
CONF_USERNAME,
CONTENT_TYPE_JSON,
HTTP_OK,
)
import homeassistant.helpers.config_validation as cv
_LOGGER = logging.getLogger(__name__)
BASE_API_URL = "https://rest.clicksend.com/v3"
HEADERS = {CONTENT_TYPE: CONTENT_TYPE_JSON}
CONF_LANGUAGE = "language"
CONF_VOICE = "voice"
CONF_CALLER = "caller"
DEFAULT_LANGUAGE = "en-us"
DEFAULT_VOICE = "female"
TIMEOUT = 5
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
{
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_API_KEY): cv.string,
vol.Required(CONF_RECIPIENT): cv.string,
vol.Optional(CONF_LANGUAGE, default=DEFAULT_LANGUAGE): cv.string,
vol.Optional(CONF_VOICE, default=DEFAULT_VOICE): cv.string,
vol.Optional(CONF_CALLER): cv.string,
}
)
def get_service(hass, config, discovery_info=None):
"""Get the ClickSend notification service."""
if not _authenticate(config):
_LOGGER.error("You are not authorized to access ClickSend")
return None
return ClicksendNotificationService(config)
class ClicksendNotificationService(BaseNotificationService):
"""Implementation of a notification service for the ClickSend service."""
def __init__(self, config):
"""Initialize the service."""
self.username = config[CONF_USERNAME]
self.api_key = config[CONF_API_KEY]
self.recipient = config[CONF_RECIPIENT]
self.language = config[CONF_LANGUAGE]
self.voice = config[CONF_VOICE]
self.caller = config.get(CONF_CALLER)
if self.caller is None:
self.caller = self.recipient
def send_message(self, message="", **kwargs):
"""Send a voice call to a user."""
data = {
"messages": [
{
"source": "hass.notify",
"from": self.caller,
"to": self.recipient,
"body": message,
"lang": self.language,
"voice": self.voice,
}
]
}
api_url = f"{BASE_API_URL}/voice/send"
resp = requests.post(
api_url,
data=json.dumps(data),
headers=HEADERS,
auth=(self.username, self.api_key),
timeout=TIMEOUT,
)
if resp.status_code == HTTP_OK:
return
obj = json.loads(resp.text)
response_msg = obj["response_msg"]
response_code = obj["response_code"]
_LOGGER.error(
"Error %s : %s (Code %s)", resp.status_code, response_msg, response_code
)
def _authenticate(config):
"""Authenticate with ClickSend."""
api_url = f"{BASE_API_URL}/account"
resp = requests.get(
api_url,
headers=HEADERS,
auth=(config.get(CONF_USERNAME), config.get(CONF_API_KEY)),
timeout=TIMEOUT,
)
if resp.status_code != HTTP_OK:
return False
return True
|
apache-2.0
|
[
624,
4891,
2254,
63,
84,
1086,
4298,
367,
11705,
3931,
1041,
199,
646,
2022,
199,
646,
2050,
199,
199,
504,
30274,
14,
29885,
492,
29417,
63,
2711,
199,
646,
4145,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
6814,
492,
21966,
63,
10926,
12,
3523,
11598,
3167,
199,
504,
8846,
14,
1297,
492,
334,
272,
6392,
63,
3735,
63,
3078,
12,
272,
6392,
63,
9481,
1772,
25451,
12,
272,
6392,
63,
11958,
12,
272,
29417,
63,
2711,
63,
6243,
12,
272,
3101,
63,
3593,
12,
199,
9,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
5825,
63,
3735,
63,
2632,
275,
298,
2859,
921,
3911,
14,
4891,
2254,
14,
957,
15,
86,
19,
2,
199,
199,
21178,
275,
469,
9663,
63,
2711,
26,
29417,
63,
2711,
63,
6243,
93,
199,
199,
3103,
63,
13947,
275,
298,
3671,
2,
199,
3103,
63,
10662,
4047,
275,
298,
3789,
2,
199,
3103,
63,
11978,
540,
275,
298,
11219,
2,
199,
199,
3472,
63,
13947,
275,
298,
287,
13,
527,
2,
199,
3472,
63,
10662,
4047,
275,
298,
771,
17667,
2,
199,
8899,
275,
959,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
8,
272,
469,
267,
5236,
14,
8030,
8,
3103,
63,
11958,
304,
6277,
14,
875,
12,
267,
5236,
14,
8030,
8,
3103,
63,
3735,
63,
3078,
304,
6277,
14,
875,
12,
267,
5236,
14,
8030,
8,
3103,
63,
9481,
1772,
25451,
304,
6277,
14,
875,
12,
267,
5236,
14,
7012,
8,
3103,
63,
13947,
12,
849,
29,
3472,
63,
13947,
304,
6277,
14,
875,
12,
267,
5236,
14,
7012,
8,
3103,
63,
10662,
4047,
12,
849,
29,
3472,
63,
10662,
4047,
304,
6277,
14,
875,
12,
267,
5236,
14,
7012,
8,
3103,
63,
11978,
540,
304,
6277,
14,
875,
12,
272,
789,
199,
9,
421,
199,
318,
664,
63,
1364,
8,
5387,
12,
1101,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1002,
314,
26147,
6795,
6955,
2435,
1041,
272,
340,
440,
485,
13975,
8,
888,
304,
267,
485,
10186,
14,
705,
480,
5556,
787,
440,
18788,
370,
2879,
26147,
6795,
531,
267,
372,
488,
339,
372,
26147,
2254,
11598,
3167,
8,
888,
9,
421,
199,
533,
26147,
2254,
11598,
3167,
8,
1563,
11598,
3167,
304,
272,
408,
7921,
402,
282,
6955,
2435,
367,
314,
26147,
6795,
2435,
1041,
339,
347,
636,
826,
721,
277,
12,
1101,
304,
267,
408,
9345,
314,
2435,
1041,
267,
291,
14,
2473,
275,
1101,
59,
3103,
63,
11958,
61,
267,
291,
14,
1246,
63,
498,
275,
1101,
59,
3103,
63,
3735,
63,
3078,
61,
267,
291,
14,
10043,
275,
1101,
59,
3103,
63,
9481,
1772,
25451,
61,
267,
291,
14,
3671,
275,
1101,
59,
3103,
63,
13947,
61,
267,
291,
14,
3789,
275,
1101,
59,
3103,
63,
10662,
4047,
61,
267,
291,
14,
11219,
275,
1101,
14,
362,
8,
3103,
63,
11978,
540,
9,
267,
340,
291,
14,
11219,
365,
488,
26,
288,
291,
14,
11219,
275,
291,
14,
10043,
339,
347,
3222,
63,
1188,
8,
277,
12,
1245,
8772,
1011,
958,
304,
267,
408,
6795,
282,
26563,
1240,
370,
282,
922,
1041,
267,
666,
275,
469,
288,
298,
3431,
582,
359,
355,
469,
490,
298,
1365,
582,
298,
5387,
14,
6814,
401,
490,
298,
504,
582,
291,
14,
11219,
12,
490,
298,
475,
582,
291,
14,
10043,
12,
490,
298,
2030,
582,
1245,
12,
490,
298,
4159,
582,
291,
14,
3671,
12,
490,
298,
3789,
582,
291,
14,
3789,
12,
355,
789,
288,
1622,
267,
789,
267,
2986,
63,
633,
275,
289,
14381,
5825,
63,
3735,
63,
2632,
5995,
3789,
15,
2254,
2,
267,
3085,
275,
4145,
14,
1932,
8,
288,
2986,
63,
633,
12,
288,
666,
29,
1001,
14,
4180,
8,
576,
395,
288,
2323,
29,
21178,
12,
288,
1790,
2687,
277,
14,
2473,
12,
291,
14,
1246,
63,
498,
395,
288,
2653,
29,
8899,
12,
267,
776,
398,
340,
3085,
14,
1205,
63,
600,
508,
3101,
63,
3593,
26,
288,
372,
267,
1559,
275,
2022,
14,
3640,
8,
4518,
14,
505,
9,
267,
1177,
63,
1328,
275,
1559,
905,
1310,
63,
1328,
937,
267,
1177,
63,
600,
275,
1559,
905,
1310,
63,
600,
937,
267,
485,
10186,
14,
705,
8,
288,
298,
547,
450,
83,
520,
450,
83,
334,
3034,
450,
83,
4186,
3085,
14,
1205,
63,
600,
12,
1177,
63,
1328,
12,
1177,
63,
600,
267,
776,
421,
199,
318,
485,
13975,
8,
888,
304,
272,
408,
21476,
543,
26147,
6795,
1041,
272,
2986,
63,
633,
275,
289,
14381,
5825,
63,
3735,
63,
2632,
5995,
2048,
2,
272,
3085,
275,
4145,
14,
362,
8,
267,
2986,
63,
633,
12,
267,
2323,
29,
21178,
12,
267,
1790,
2687,
888,
14,
362,
8,
3103,
63,
11958,
395,
1101,
14,
362,
8,
3103,
63,
3735,
63,
3078,
1826,
267,
2653,
29,
8899,
12,
272,
776,
339,
340,
3085,
14,
1205,
63,
600,
1137,
3101,
63,
3593,
26,
267,
372,
756,
339,
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
] |
[
4891,
2254,
63,
84,
1086,
4298,
367,
11705,
3931,
1041,
199,
646,
2022,
199,
646,
2050,
199,
199,
504,
30274,
14,
29885,
492,
29417,
63,
2711,
199,
646,
4145,
199,
646,
30291,
465,
5236,
199,
199,
504,
8846,
14,
4608,
14,
6814,
492,
21966,
63,
10926,
12,
3523,
11598,
3167,
199,
504,
8846,
14,
1297,
492,
334,
272,
6392,
63,
3735,
63,
3078,
12,
272,
6392,
63,
9481,
1772,
25451,
12,
272,
6392,
63,
11958,
12,
272,
29417,
63,
2711,
63,
6243,
12,
272,
3101,
63,
3593,
12,
199,
9,
199,
646,
8846,
14,
7546,
14,
888,
63,
6136,
465,
6277,
199,
199,
63,
10186,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
5825,
63,
3735,
63,
2632,
275,
298,
2859,
921,
3911,
14,
4891,
2254,
14,
957,
15,
86,
19,
2,
199,
199,
21178,
275,
469,
9663,
63,
2711,
26,
29417,
63,
2711,
63,
6243,
93,
199,
199,
3103,
63,
13947,
275,
298,
3671,
2,
199,
3103,
63,
10662,
4047,
275,
298,
3789,
2,
199,
3103,
63,
11978,
540,
275,
298,
11219,
2,
199,
199,
3472,
63,
13947,
275,
298,
287,
13,
527,
2,
199,
3472,
63,
10662,
4047,
275,
298,
771,
17667,
2,
199,
8899,
275,
959,
199,
199,
17805,
63,
10926,
275,
21966,
63,
10926,
14,
2880,
8,
272,
469,
267,
5236,
14,
8030,
8,
3103,
63,
11958,
304,
6277,
14,
875,
12,
267,
5236,
14,
8030,
8,
3103,
63,
3735,
63,
3078,
304,
6277,
14,
875,
12,
267,
5236,
14,
8030,
8,
3103,
63,
9481,
1772,
25451,
304,
6277,
14,
875,
12,
267,
5236,
14,
7012,
8,
3103,
63,
13947,
12,
849,
29,
3472,
63,
13947,
304,
6277,
14,
875,
12,
267,
5236,
14,
7012,
8,
3103,
63,
10662,
4047,
12,
849,
29,
3472,
63,
10662,
4047,
304,
6277,
14,
875,
12,
267,
5236,
14,
7012,
8,
3103,
63,
11978,
540,
304,
6277,
14,
875,
12,
272,
789,
199,
9,
421,
199,
318,
664,
63,
1364,
8,
5387,
12,
1101,
12,
13172,
63,
815,
29,
403,
304,
272,
408,
1002,
314,
26147,
6795,
6955,
2435,
1041,
272,
340,
440,
485,
13975,
8,
888,
304,
267,
485,
10186,
14,
705,
480,
5556,
787,
440,
18788,
370,
2879,
26147,
6795,
531,
267,
372,
488,
339,
372,
26147,
2254,
11598,
3167,
8,
888,
9,
421,
199,
533,
26147,
2254,
11598,
3167,
8,
1563,
11598,
3167,
304,
272,
408,
7921,
402,
282,
6955,
2435,
367,
314,
26147,
6795,
2435,
1041,
339,
347,
636,
826,
721,
277,
12,
1101,
304,
267,
408,
9345,
314,
2435,
1041,
267,
291,
14,
2473,
275,
1101,
59,
3103,
63,
11958,
61,
267,
291,
14,
1246,
63,
498,
275,
1101,
59,
3103,
63,
3735,
63,
3078,
61,
267,
291,
14,
10043,
275,
1101,
59,
3103,
63,
9481,
1772,
25451,
61,
267,
291,
14,
3671,
275,
1101,
59,
3103,
63,
13947,
61,
267,
291,
14,
3789,
275,
1101,
59,
3103,
63,
10662,
4047,
61,
267,
291,
14,
11219,
275,
1101,
14,
362,
8,
3103,
63,
11978,
540,
9,
267,
340,
291,
14,
11219,
365,
488,
26,
288,
291,
14,
11219,
275,
291,
14,
10043,
339,
347,
3222,
63,
1188,
8,
277,
12,
1245,
8772,
1011,
958,
304,
267,
408,
6795,
282,
26563,
1240,
370,
282,
922,
1041,
267,
666,
275,
469,
288,
298,
3431,
582,
359,
355,
469,
490,
298,
1365,
582,
298,
5387,
14,
6814,
401,
490,
298,
504,
582,
291,
14,
11219,
12,
490,
298,
475,
582,
291,
14,
10043,
12,
490,
298,
2030,
582,
1245,
12,
490,
298,
4159,
582,
291,
14,
3671,
12,
490,
298,
3789,
582,
291,
14,
3789,
12,
355,
789,
288,
1622,
267,
789,
267,
2986,
63,
633,
275,
289,
14381,
5825,
63,
3735,
63,
2632,
5995,
3789,
15,
2254,
2,
267,
3085,
275,
4145,
14,
1932,
8,
288,
2986,
63,
633,
12,
288,
666,
29,
1001,
14,
4180,
8,
576,
395,
288,
2323,
29,
21178,
12,
288,
1790,
2687,
277,
14,
2473,
12,
291,
14,
1246,
63,
498,
395,
288,
2653,
29,
8899,
12,
267,
776,
398,
340,
3085,
14,
1205,
63,
600,
508,
3101,
63,
3593,
26,
288,
372,
267,
1559,
275,
2022,
14,
3640,
8,
4518,
14,
505,
9,
267,
1177,
63,
1328,
275,
1559,
905,
1310,
63,
1328,
937,
267,
1177,
63,
600,
275,
1559,
905,
1310,
63,
600,
937,
267,
485,
10186,
14,
705,
8,
288,
298,
547,
450,
83,
520,
450,
83,
334,
3034,
450,
83,
4186,
3085,
14,
1205,
63,
600,
12,
1177,
63,
1328,
12,
1177,
63,
600,
267,
776,
421,
199,
318,
485,
13975,
8,
888,
304,
272,
408,
21476,
543,
26147,
6795,
1041,
272,
2986,
63,
633,
275,
289,
14381,
5825,
63,
3735,
63,
2632,
5995,
2048,
2,
272,
3085,
275,
4145,
14,
362,
8,
267,
2986,
63,
633,
12,
267,
2323,
29,
21178,
12,
267,
1790,
2687,
888,
14,
362,
8,
3103,
63,
11958,
395,
1101,
14,
362,
8,
3103,
63,
3735,
63,
3078,
1826,
267,
2653,
29,
8899,
12,
272,
776,
339,
340,
3085,
14,
1205,
63,
600,
1137,
3101,
63,
3593,
26,
267,
372,
756,
339,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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y-0.95.1/build/lib/geopy/geocoders/openmapquest.py
|
14
|
2474
|
try:
import json
except ImportError:
try:
import simplejson as json
except ImportError:
from django.utils import simplejson as json
from urllib import urlencode
from urllib2 import urlopen
from geopy.geocoders.base import Geocoder
from geopy.util import logger, decode_page, join_filter
class OpenMapQuest(Geocoder):
"""Geocoder using the MapQuest Open Platform Web Services."""
def __init__(self, api_key='', format_string='%s'):
"""Initialize an Open MapQuest geocoder with location-specific
address information, no API Key is needed by the Nominatim based
platform.
``format_string`` is a string containing '%s' where the string to
geocode should be interpolated before querying the geocoder.
For example: '%s, Mountain View, CA'. The default is just '%s'.
"""
self.api_key = api_key
self.format_string = format_string
self.url = "http://open.mapquestapi.com/nominatim/v1/search?format=json&%s"
def geocode(self, string, exactly_one=True):
if isinstance(string, unicode):
string = string.encode('utf-8')
params = {'q': self.format_string % string}
url = self.url % urlencode(params)
logger.debug("Fetching %s..." % url)
page = urlopen(url)
return self.parse_json(page, exactly_one)
def parse_json(self, page, exactly_one=True):
"""Parse display name, latitude, and longitude from an JSON response."""
if not isinstance(page, basestring):
page = decode_page(page)
resources = json.loads(page)
if exactly_one and len(resources) != 1:
from warnings import warn
warn("Didn't find exactly one resource!" + \
"(Found %d.), use exactly_one=False\n" % len(resources)
)
def parse_resource(resource):
location = resource['display_name']
latitude = resource['lat'] or None
longitude = resource['lon'] or None
if latitude and longitude:
latitude = float(latitude)
longitude = float(longitude)
return (location, (latitude, longitude))
if exactly_one:
return parse_resource(resources[0])
else:
return [parse_resource(resource) for resource in resources]
|
mit
|
[
893,
26,
272,
492,
2022,
199,
2590,
3545,
26,
272,
862,
26,
267,
492,
13804,
465,
2022,
272,
871,
3545,
26,
267,
687,
1639,
14,
1208,
492,
13804,
465,
2022,
199,
199,
504,
4011,
492,
16511,
199,
504,
4011,
18,
492,
18279,
199,
199,
504,
2312,
927,
14,
6721,
2693,
83,
14,
1095,
492,
8875,
2693,
199,
504,
2312,
927,
14,
1974,
492,
2512,
12,
4849,
63,
1606,
12,
4263,
63,
1541,
199,
199,
533,
3232,
2956,
49,
5291,
8,
10748,
2693,
304,
272,
408,
10748,
2693,
1808,
314,
9672,
49,
5291,
3232,
16078,
6001,
21813,
1041,
2286,
347,
636,
826,
721,
277,
12,
2986,
63,
498,
4581,
1475,
63,
875,
9569,
83,
735,
267,
408,
9345,
376,
3232,
9672,
49,
5291,
8509,
2693,
543,
2909,
13,
6100,
267,
2287,
2556,
12,
949,
3261,
2606,
365,
4346,
701,
314,
653,
676,
262,
24218,
4079,
267,
4298,
14,
2728,
1124,
908,
63,
875,
1040,
365,
282,
1059,
3035,
1543,
83,
7,
2382,
314,
1059,
370,
267,
8509,
600,
1077,
506,
23005,
972,
2544,
27405,
314,
8509,
2693,
14,
267,
2104,
2893,
26,
1543,
83,
12,
3930,
324,
877,
10935,
12,
7240,
1370,
710,
849,
365,
2951,
1543,
83,
1370,
267,
408,
2728,
291,
14,
1246,
63,
498,
275,
2986,
63,
498,
267,
291,
14,
908,
63,
875,
275,
1475,
63,
875,
267,
291,
14,
633,
275,
298,
1014,
921,
1490,
14,
1130,
613,
1246,
14,
957,
15,
15998,
262,
24218,
15,
86,
17,
15,
1733,
31,
908,
29,
1001,
6,
5,
83,
2,
2286,
347,
8509,
600,
8,
277,
12,
1059,
12,
8840,
63,
368,
29,
549,
304,
267,
340,
1228,
8,
875,
12,
2649,
304,
288,
1059,
275,
1059,
14,
2143,
360,
1624,
13,
24,
358,
267,
1862,
275,
791,
81,
356,
291,
14,
908,
63,
875,
450,
1059,
93,
267,
1166,
275,
291,
14,
633,
450,
16511,
8,
1162,
9,
2728,
2512,
14,
1757,
480,
11135,
316,
450,
83,
11500,
450,
1166,
9,
267,
2034,
275,
18279,
8,
633,
9,
2728,
372,
291,
14,
1122,
63,
1001,
8,
1606,
12,
8840,
63,
368,
9,
2286,
347,
2198,
63,
1001,
8,
277,
12,
2034,
12,
8840,
63,
368,
29,
549,
304,
267,
408,
4003,
2929,
536,
12,
18896,
12,
436,
18154,
687,
376,
4840,
1177,
1041,
267,
340,
440,
1228,
8,
1606,
12,
7116,
304,
288,
2034,
275,
4849,
63,
1606,
8,
1606,
9,
267,
5944,
275,
2022,
14,
3640,
8,
1606,
9,
2728,
340,
8840,
63,
368,
436,
822,
8,
4435,
9,
1137,
413,
26,
288,
687,
3598,
492,
7987,
288,
7987,
480,
17366,
78,
1133,
2342,
8840,
1373,
2073,
9539,
435,
971,
355,
7340,
3601,
450,
68,
15631,
675,
8840,
63,
368,
29,
797,
60,
78,
2,
450,
822,
8,
4435,
9,
288,
776,
10631,
347,
2198,
63,
1927,
8,
1927,
304,
288,
2909,
275,
2073,
459,
2918,
63,
354,
418,
7846,
18896,
275,
2073,
459,
4452,
418,
503,
488,
288,
18154,
275,
2073,
459,
5298,
418,
503,
488,
288,
340,
18896,
436,
18154,
26,
355,
18896,
275,
2069,
8,
13331,
9,
355,
18154,
275,
2069,
8,
13803,
9,
7846,
372,
334,
1985,
12,
334,
13331,
12,
18154,
430,
2728,
340,
8840,
63,
368,
26,
288,
372,
2198,
63,
1927,
8,
4435,
59,
16,
566,
267,
587,
26,
288,
372,
359,
1122,
63,
1927,
8,
1927,
9,
367,
2073,
315,
5944,
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
] |
[
26,
272,
492,
2022,
199,
2590,
3545,
26,
272,
862,
26,
267,
492,
13804,
465,
2022,
272,
871,
3545,
26,
267,
687,
1639,
14,
1208,
492,
13804,
465,
2022,
199,
199,
504,
4011,
492,
16511,
199,
504,
4011,
18,
492,
18279,
199,
199,
504,
2312,
927,
14,
6721,
2693,
83,
14,
1095,
492,
8875,
2693,
199,
504,
2312,
927,
14,
1974,
492,
2512,
12,
4849,
63,
1606,
12,
4263,
63,
1541,
199,
199,
533,
3232,
2956,
49,
5291,
8,
10748,
2693,
304,
272,
408,
10748,
2693,
1808,
314,
9672,
49,
5291,
3232,
16078,
6001,
21813,
1041,
2286,
347,
636,
826,
721,
277,
12,
2986,
63,
498,
4581,
1475,
63,
875,
9569,
83,
735,
267,
408,
9345,
376,
3232,
9672,
49,
5291,
8509,
2693,
543,
2909,
13,
6100,
267,
2287,
2556,
12,
949,
3261,
2606,
365,
4346,
701,
314,
653,
676,
262,
24218,
4079,
267,
4298,
14,
2728,
1124,
908,
63,
875,
1040,
365,
282,
1059,
3035,
1543,
83,
7,
2382,
314,
1059,
370,
267,
8509,
600,
1077,
506,
23005,
972,
2544,
27405,
314,
8509,
2693,
14,
267,
2104,
2893,
26,
1543,
83,
12,
3930,
324,
877,
10935,
12,
7240,
1370,
710,
849,
365,
2951,
1543,
83,
1370,
267,
408,
2728,
291,
14,
1246,
63,
498,
275,
2986,
63,
498,
267,
291,
14,
908,
63,
875,
275,
1475,
63,
875,
267,
291,
14,
633,
275,
298,
1014,
921,
1490,
14,
1130,
613,
1246,
14,
957,
15,
15998,
262,
24218,
15,
86,
17,
15,
1733,
31,
908,
29,
1001,
6,
5,
83,
2,
2286,
347,
8509,
600,
8,
277,
12,
1059,
12,
8840,
63,
368,
29,
549,
304,
267,
340,
1228,
8,
875,
12,
2649,
304,
288,
1059,
275,
1059,
14,
2143,
360,
1624,
13,
24,
358,
267,
1862,
275,
791,
81,
356,
291,
14,
908,
63,
875,
450,
1059,
93,
267,
1166,
275,
291,
14,
633,
450,
16511,
8,
1162,
9,
2728,
2512,
14,
1757,
480,
11135,
316,
450,
83,
11500,
450,
1166,
9,
267,
2034,
275,
18279,
8,
633,
9,
2728,
372,
291,
14,
1122,
63,
1001,
8,
1606,
12,
8840,
63,
368,
9,
2286,
347,
2198,
63,
1001,
8,
277,
12,
2034,
12,
8840,
63,
368,
29,
549,
304,
267,
408,
4003,
2929,
536,
12,
18896,
12,
436,
18154,
687,
376,
4840,
1177,
1041,
267,
340,
440,
1228,
8,
1606,
12,
7116,
304,
288,
2034,
275,
4849,
63,
1606,
8,
1606,
9,
267,
5944,
275,
2022,
14,
3640,
8,
1606,
9,
2728,
340,
8840,
63,
368,
436,
822,
8,
4435,
9,
1137,
413,
26,
288,
687,
3598,
492,
7987,
288,
7987,
480,
17366,
78,
1133,
2342,
8840,
1373,
2073,
9539,
435,
971,
355,
7340,
3601,
450,
68,
15631,
675,
8840,
63,
368,
29,
797,
60,
78,
2,
450,
822,
8,
4435,
9,
288,
776,
10631,
347,
2198,
63,
1927,
8,
1927,
304,
288,
2909,
275,
2073,
459,
2918,
63,
354,
418,
7846,
18896,
275,
2073,
459,
4452,
418,
503,
488,
288,
18154,
275,
2073,
459,
5298,
418,
503,
488,
288,
340,
18896,
436,
18154,
26,
355,
18896,
275,
2069,
8,
13331,
9,
355,
18154,
275,
2069,
8,
13803,
9,
7846,
372,
334,
1985,
12,
334,
13331,
12,
18154,
430,
2728,
340,
8840,
63,
368,
26,
288,
372,
2198,
63,
1927,
8,
4435,
59,
16,
566,
267,
587,
26,
288,
372,
359,
1122,
63,
1927,
8,
1927,
9,
367,
2073,
315,
5944,
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,
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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
] |
kubeflow/kfp-tekton
|
backend/api/python_http_client/test/test_api_report_run_metrics_request.py
|
2
|
1852
|
# coding: utf-8
"""
Kubeflow Pipelines API
This file contains REST API specification for Kubeflow Pipelines. The file is autogenerated from the swagger definition.
Contact: kubeflow-pipelines@google.com
Generated by: https://openapi-generator.tech
"""
from __future__ import absolute_import
import unittest
import datetime
import kfp_server_api
from kfp_server_api.models.api_report_run_metrics_request import ApiReportRunMetricsRequest # noqa: E501
from kfp_server_api.rest import ApiException
class TestApiReportRunMetricsRequest(unittest.TestCase):
"""ApiReportRunMetricsRequest unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional):
"""Test ApiReportRunMetricsRequest
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# model = kfp_server_api.models.api_report_run_metrics_request.ApiReportRunMetricsRequest() # noqa: E501
if include_optional :
return ApiReportRunMetricsRequest(
run_id = '0',
metrics = [
kfp_server_api.models.api_run_metric.apiRunMetric(
name = '0',
node_id = '0',
number_value = 1.337,
format = 'UNSPECIFIED', )
]
)
else :
return ApiReportRunMetricsRequest(
)
def testApiReportRunMetricsRequest(self):
"""Test ApiReportRunMetricsRequest"""
inst_req_only = self.make_instance(include_optional=False)
inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
199,
624,
272,
1804,
3375,
1659,
16850,
1278,
3261,
339,
961,
570,
3509,
14880,
3261,
8929,
367,
1804,
3375,
1659,
16850,
1278,
14,
710,
570,
365,
18392,
687,
314,
5584,
16267,
5492,
14,
339,
18684,
26,
23091,
1659,
13,
4990,
1278,
32,
3098,
14,
957,
272,
17065,
701,
26,
4178,
921,
1490,
1246,
13,
4679,
14,
15970,
199,
624,
421,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2882,
199,
646,
2197,
199,
199,
646,
1022,
3997,
63,
1000,
63,
1246,
199,
504,
1022,
3997,
63,
1000,
63,
1246,
14,
992,
14,
1246,
63,
3070,
63,
1065,
63,
6759,
63,
1069,
492,
13986,
7457,
2540,
17213,
2017,
221,
327,
8151,
26,
662,
8216,
199,
504,
1022,
3997,
63,
1000,
63,
1246,
14,
3911,
492,
13986,
1726,
199,
199,
533,
1379,
7394,
7457,
2540,
17213,
2017,
8,
2796,
14,
1746,
304,
272,
408,
7394,
7457,
2540,
17213,
2017,
4137,
511,
22312,
624,
339,
347,
3613,
8,
277,
304,
267,
986,
339,
347,
6766,
8,
277,
304,
267,
986,
339,
347,
1852,
63,
842,
8,
277,
12,
2387,
63,
4144,
304,
267,
408,
774,
13986,
7457,
2540,
17213,
2017,
288,
2387,
63,
1422,
365,
282,
5046,
12,
1380,
756,
1454,
1415,
288,
1862,
787,
5120,
12,
1380,
715,
3865,
1415,
436,
288,
2716,
1862,
787,
5120,
408,
267,
327,
1402,
275,
1022,
3997,
63,
1000,
63,
1246,
14,
992,
14,
1246,
63,
3070,
63,
1065,
63,
6759,
63,
1069,
14,
7394,
7457,
2540,
17213,
2017,
342,
221,
327,
8151,
26,
662,
8216,
267,
340,
2387,
63,
4144,
520,
288,
372,
13986,
7457,
2540,
17213,
2017,
8,
355,
1255,
63,
344,
275,
283,
16,
297,
8892,
7186,
275,
359,
490,
1022,
3997,
63,
1000,
63,
1246,
14,
992,
14,
1246,
63,
1065,
63,
5165,
14,
1246,
2540,
11119,
8,
717,
536,
275,
283,
16,
297,
12723,
1031,
63,
344,
275,
283,
16,
297,
12723,
1329,
63,
585,
275,
413,
14,
11062,
12,
12723,
1475,
275,
283,
1734,
22917,
19679,
297,
776,
490,
1622,
288,
776,
267,
587,
520,
288,
372,
13986,
7457,
2540,
17213,
2017,
8,
267,
776,
339,
347,
511,
7394,
7457,
2540,
17213,
2017,
8,
277,
304,
267,
408,
774,
13986,
7457,
2540,
17213,
2017,
624,
267,
2727,
63,
2103,
63,
2118,
275,
291,
14,
1875,
63,
842,
8,
2613,
63,
4144,
29,
797,
9,
267,
2727,
63,
2103,
63,
460,
63,
4144,
275,
291,
14,
1875,
63,
842,
8,
2613,
63,
4144,
29,
549,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2803,
26,
2774,
13,
24,
199,
199,
624,
272,
1804,
3375,
1659,
16850,
1278,
3261,
339,
961,
570,
3509,
14880,
3261,
8929,
367,
1804,
3375,
1659,
16850,
1278,
14,
710,
570,
365,
18392,
687,
314,
5584,
16267,
5492,
14,
339,
18684,
26,
23091,
1659,
13,
4990,
1278,
32,
3098,
14,
957,
272,
17065,
701,
26,
4178,
921,
1490,
1246,
13,
4679,
14,
15970,
199,
624,
421,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2882,
199,
646,
2197,
199,
199,
646,
1022,
3997,
63,
1000,
63,
1246,
199,
504,
1022,
3997,
63,
1000,
63,
1246,
14,
992,
14,
1246,
63,
3070,
63,
1065,
63,
6759,
63,
1069,
492,
13986,
7457,
2540,
17213,
2017,
221,
327,
8151,
26,
662,
8216,
199,
504,
1022,
3997,
63,
1000,
63,
1246,
14,
3911,
492,
13986,
1726,
199,
199,
533,
1379,
7394,
7457,
2540,
17213,
2017,
8,
2796,
14,
1746,
304,
272,
408,
7394,
7457,
2540,
17213,
2017,
4137,
511,
22312,
624,
339,
347,
3613,
8,
277,
304,
267,
986,
339,
347,
6766,
8,
277,
304,
267,
986,
339,
347,
1852,
63,
842,
8,
277,
12,
2387,
63,
4144,
304,
267,
408,
774,
13986,
7457,
2540,
17213,
2017,
288,
2387,
63,
1422,
365,
282,
5046,
12,
1380,
756,
1454,
1415,
288,
1862,
787,
5120,
12,
1380,
715,
3865,
1415,
436,
288,
2716,
1862,
787,
5120,
408,
267,
327,
1402,
275,
1022,
3997,
63,
1000,
63,
1246,
14,
992,
14,
1246,
63,
3070,
63,
1065,
63,
6759,
63,
1069,
14,
7394,
7457,
2540,
17213,
2017,
342,
221,
327,
8151,
26,
662,
8216,
267,
340,
2387,
63,
4144,
520,
288,
372,
13986,
7457,
2540,
17213,
2017,
8,
355,
1255,
63,
344,
275,
283,
16,
297,
8892,
7186,
275,
359,
490,
1022,
3997,
63,
1000,
63,
1246,
14,
992,
14,
1246,
63,
1065,
63,
5165,
14,
1246,
2540,
11119,
8,
717,
536,
275,
283,
16,
297,
12723,
1031,
63,
344,
275,
283,
16,
297,
12723,
1329,
63,
585,
275,
413,
14,
11062,
12,
12723,
1475,
275,
283,
1734,
22917,
19679,
297,
776,
490,
1622,
288,
776,
267,
587,
520,
288,
372,
13986,
7457,
2540,
17213,
2017,
8,
267,
776,
339,
347,
511,
7394,
7457,
2540,
17213,
2017,
8,
277,
304,
267,
408,
774,
13986,
7457,
2540,
17213,
2017,
624,
267,
2727,
63,
2103,
63,
2118,
275,
291,
14,
1875,
63,
842,
8,
2613,
63,
4144,
29,
797,
9,
267,
2727,
63,
2103,
63,
460,
63,
4144,
275,
291,
14,
1875,
63,
842,
8,
2613,
63,
4144,
29,
549,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
takeshineshiro/neutron
|
neutron/tests/functional/agent/linux/helpers.py
|
26
|
1408
|
# Copyright (c) 2014 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import os
import fixtures
class RecursivePermDirFixture(fixtures.Fixture):
"""Ensure at least perms permissions on directory and ancestors."""
def __init__(self, directory, perms):
super(RecursivePermDirFixture, self).__init__()
self.directory = directory
self.least_perms = perms
def _setUp(self):
previous_directory = None
current_directory = self.directory
while previous_directory != current_directory:
perms = os.stat(current_directory).st_mode
if perms & self.least_perms != self.least_perms:
os.chmod(current_directory, perms | self.least_perms)
previous_directory = current_directory
current_directory = os.path.dirname(current_directory)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6927,
9572,
13002,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
646,
747,
199,
199,
646,
15188,
421,
199,
533,
18306,
3398,
23554,
3567,
12812,
8,
8769,
14,
12812,
304,
272,
408,
13913,
737,
5210,
17340,
3443,
641,
2082,
436,
20158,
1041,
339,
347,
636,
826,
721,
277,
12,
2082,
12,
17340,
304,
267,
1613,
8,
25122,
23554,
3567,
12812,
12,
291,
2843,
826,
4533,
267,
291,
14,
3619,
275,
2082,
267,
291,
14,
11790,
63,
12068,
275,
17340,
339,
347,
485,
5996,
8,
277,
304,
267,
4136,
63,
3619,
275,
488,
267,
1453,
63,
3619,
275,
291,
14,
3619,
267,
1830,
4136,
63,
3619,
1137,
1453,
63,
3619,
26,
288,
17340,
275,
747,
14,
3736,
8,
1818,
63,
3619,
680,
270,
63,
632,
288,
340,
17340,
1253,
291,
14,
11790,
63,
12068,
1137,
291,
14,
11790,
63,
12068,
26,
355,
747,
14,
11693,
8,
1818,
63,
3619,
12,
17340,
1204,
291,
14,
11790,
63,
12068,
9,
288,
4136,
63,
3619,
275,
1453,
63,
3619,
288,
1453,
63,
3619,
275,
747,
14,
515,
14,
3475,
8,
1818,
63,
3619,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
6927,
9572,
13002,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
646,
747,
199,
199,
646,
15188,
421,
199,
533,
18306,
3398,
23554,
3567,
12812,
8,
8769,
14,
12812,
304,
272,
408,
13913,
737,
5210,
17340,
3443,
641,
2082,
436,
20158,
1041,
339,
347,
636,
826,
721,
277,
12,
2082,
12,
17340,
304,
267,
1613,
8,
25122,
23554,
3567,
12812,
12,
291,
2843,
826,
4533,
267,
291,
14,
3619,
275,
2082,
267,
291,
14,
11790,
63,
12068,
275,
17340,
339,
347,
485,
5996,
8,
277,
304,
267,
4136,
63,
3619,
275,
488,
267,
1453,
63,
3619,
275,
291,
14,
3619,
267,
1830,
4136,
63,
3619,
1137,
1453,
63,
3619,
26,
288,
17340,
275,
747,
14,
3736,
8,
1818,
63,
3619,
680,
270,
63,
632,
288,
340,
17340,
1253,
291,
14,
11790,
63,
12068,
1137,
291,
14,
11790,
63,
12068,
26,
355,
747,
14,
11693,
8,
1818,
63,
3619,
12,
17340,
1204,
291,
14,
11790,
63,
12068,
9,
288,
4136,
63,
3619,
275,
1453,
63,
3619,
288,
1453,
63,
3619,
275,
747,
14,
515,
14,
3475,
8,
1818,
63,
3619,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jmagnusson/pip
|
pip/_vendor/html5lib/treebuilders/dom.py
|
920
|
8469
|
from __future__ import absolute_import, division, unicode_literals
from xml.dom import minidom, Node
import weakref
from . import _base
from .. import constants
from ..constants import namespaces
from ..utils import moduleFactoryFactory
def getDomBuilder(DomImplementation):
Dom = DomImplementation
class AttrList(object):
def __init__(self, element):
self.element = element
def __iter__(self):
return list(self.element.attributes.items()).__iter__()
def __setitem__(self, name, value):
self.element.setAttribute(name, value)
def __len__(self):
return len(list(self.element.attributes.items()))
def items(self):
return [(item[0], item[1]) for item in
list(self.element.attributes.items())]
def keys(self):
return list(self.element.attributes.keys())
def __getitem__(self, name):
return self.element.getAttribute(name)
def __contains__(self, name):
if isinstance(name, tuple):
raise NotImplementedError
else:
return self.element.hasAttribute(name)
class NodeBuilder(_base.Node):
def __init__(self, element):
_base.Node.__init__(self, element.nodeName)
self.element = element
namespace = property(lambda self: hasattr(self.element, "namespaceURI")
and self.element.namespaceURI or None)
def appendChild(self, node):
node.parent = self
self.element.appendChild(node.element)
def insertText(self, data, insertBefore=None):
text = self.element.ownerDocument.createTextNode(data)
if insertBefore:
self.element.insertBefore(text, insertBefore.element)
else:
self.element.appendChild(text)
def insertBefore(self, node, refNode):
self.element.insertBefore(node.element, refNode.element)
node.parent = self
def removeChild(self, node):
if node.element.parentNode == self.element:
self.element.removeChild(node.element)
node.parent = None
def reparentChildren(self, newParent):
while self.element.hasChildNodes():
child = self.element.firstChild
self.element.removeChild(child)
newParent.element.appendChild(child)
self.childNodes = []
def getAttributes(self):
return AttrList(self.element)
def setAttributes(self, attributes):
if attributes:
for name, value in list(attributes.items()):
if isinstance(name, tuple):
if name[0] is not None:
qualifiedName = (name[0] + ":" + name[1])
else:
qualifiedName = name[1]
self.element.setAttributeNS(name[2], qualifiedName,
value)
else:
self.element.setAttribute(
name, value)
attributes = property(getAttributes, setAttributes)
def cloneNode(self):
return NodeBuilder(self.element.cloneNode(False))
def hasContent(self):
return self.element.hasChildNodes()
def getNameTuple(self):
if self.namespace is None:
return namespaces["html"], self.name
else:
return self.namespace, self.name
nameTuple = property(getNameTuple)
class TreeBuilder(_base.TreeBuilder):
def documentClass(self):
self.dom = Dom.getDOMImplementation().createDocument(None, None, None)
return weakref.proxy(self)
def insertDoctype(self, token):
name = token["name"]
publicId = token["publicId"]
systemId = token["systemId"]
domimpl = Dom.getDOMImplementation()
doctype = domimpl.createDocumentType(name, publicId, systemId)
self.document.appendChild(NodeBuilder(doctype))
if Dom == minidom:
doctype.ownerDocument = self.dom
def elementClass(self, name, namespace=None):
if namespace is None and self.defaultNamespace is None:
node = self.dom.createElement(name)
else:
node = self.dom.createElementNS(namespace, name)
return NodeBuilder(node)
def commentClass(self, data):
return NodeBuilder(self.dom.createComment(data))
def fragmentClass(self):
return NodeBuilder(self.dom.createDocumentFragment())
def appendChild(self, node):
self.dom.appendChild(node.element)
def testSerializer(self, element):
return testSerializer(element)
def getDocument(self):
return self.dom
def getFragment(self):
return _base.TreeBuilder.getFragment(self).element
def insertText(self, data, parent=None):
data = data
if parent != self:
_base.TreeBuilder.insertText(self, data, parent)
else:
# HACK: allow text nodes as children of the document node
if hasattr(self.dom, '_child_node_types'):
if Node.TEXT_NODE not in self.dom._child_node_types:
self.dom._child_node_types = list(self.dom._child_node_types)
self.dom._child_node_types.append(Node.TEXT_NODE)
self.dom.appendChild(self.dom.createTextNode(data))
implementation = DomImplementation
name = None
def testSerializer(element):
element.normalize()
rv = []
def serializeElement(element, indent=0):
if element.nodeType == Node.DOCUMENT_TYPE_NODE:
if element.name:
if element.publicId or element.systemId:
publicId = element.publicId or ""
systemId = element.systemId or ""
rv.append("""|%s<!DOCTYPE %s "%s" "%s">""" %
(' ' * indent, element.name, publicId, systemId))
else:
rv.append("|%s<!DOCTYPE %s>" % (' ' * indent, element.name))
else:
rv.append("|%s<!DOCTYPE >" % (' ' * indent,))
elif element.nodeType == Node.DOCUMENT_NODE:
rv.append("#document")
elif element.nodeType == Node.DOCUMENT_FRAGMENT_NODE:
rv.append("#document-fragment")
elif element.nodeType == Node.COMMENT_NODE:
rv.append("|%s<!-- %s -->" % (' ' * indent, element.nodeValue))
elif element.nodeType == Node.TEXT_NODE:
rv.append("|%s\"%s\"" % (' ' * indent, element.nodeValue))
else:
if (hasattr(element, "namespaceURI") and
element.namespaceURI is not None):
name = "%s %s" % (constants.prefixes[element.namespaceURI],
element.nodeName)
else:
name = element.nodeName
rv.append("|%s<%s>" % (' ' * indent, name))
if element.hasAttributes():
attributes = []
for i in range(len(element.attributes)):
attr = element.attributes.item(i)
name = attr.nodeName
value = attr.value
ns = attr.namespaceURI
if ns:
name = "%s %s" % (constants.prefixes[ns], attr.localName)
else:
name = attr.nodeName
attributes.append((name, value))
for name, value in sorted(attributes):
rv.append('|%s%s="%s"' % (' ' * (indent + 2), name, value))
indent += 2
for child in element.childNodes:
serializeElement(child, indent)
serializeElement(element, 0)
return "\n".join(rv)
return locals()
# The actual means to get a module!
getDomModule = moduleFactoryFactory(getDomBuilder)
|
mit
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
421,
199,
504,
2748,
14,
4556,
492,
19165,
12,
5013,
199,
646,
13852,
199,
199,
504,
1275,
492,
485,
1095,
199,
504,
2508,
492,
5262,
199,
504,
2508,
5559,
492,
10747,
199,
504,
2508,
1208,
492,
859,
2927,
2927,
421,
199,
318,
664,
20106,
6437,
8,
20106,
7921,
304,
272,
577,
676,
275,
577,
676,
7921,
339,
1021,
20516,
1296,
8,
785,
304,
267,
347,
636,
826,
721,
277,
12,
1819,
304,
288,
291,
14,
2108,
275,
1819,
398,
347,
636,
1661,
721,
277,
304,
288,
372,
769,
8,
277,
14,
2108,
14,
2987,
14,
1744,
342,
2843,
1661,
4533,
398,
347,
636,
8617,
721,
277,
12,
536,
12,
574,
304,
288,
291,
14,
2108,
14,
17618,
8,
354,
12,
574,
9,
398,
347,
636,
552,
721,
277,
304,
288,
372,
822,
8,
513,
8,
277,
14,
2108,
14,
2987,
14,
1744,
4059,
398,
347,
2974,
8,
277,
304,
288,
372,
3842,
1053,
59,
16,
467,
1242,
59,
17,
566,
367,
1242,
315,
490,
769,
8,
277,
14,
2108,
14,
2987,
14,
1744,
24821,
398,
347,
2883,
8,
277,
304,
288,
372,
769,
8,
277,
14,
2108,
14,
2987,
14,
1612,
1012,
398,
347,
636,
6095,
721,
277,
12,
536,
304,
288,
372,
291,
14,
2108,
14,
12956,
8,
354,
9,
398,
347,
636,
6134,
721,
277,
12,
536,
304,
288,
340,
1228,
8,
354,
12,
2008,
304,
355,
746,
4279,
288,
587,
26,
355,
372,
291,
14,
2108,
14,
1989,
1646,
8,
354,
9,
339,
1021,
5013,
6437,
1547,
1095,
14,
1716,
304,
267,
347,
636,
826,
721,
277,
12,
1819,
304,
288,
485,
1095,
14,
1716,
855,
826,
721,
277,
12,
1819,
14,
13777,
9,
288,
291,
14,
2108,
275,
1819,
398,
3231,
275,
3324,
8,
2734,
291,
26,
2688,
8,
277,
14,
2108,
12,
298,
27855,
531,
2490,
436,
291,
14,
2108,
14,
27855,
503,
488,
9,
398,
347,
5666,
3493,
8,
277,
12,
1031,
304,
288,
1031,
14,
1708,
275,
291,
288,
291,
14,
2108,
14,
14988,
8,
932,
14,
2108,
9,
398,
347,
5518,
1872,
8,
277,
12,
666,
12,
5518,
13569,
29,
403,
304,
288,
1318,
275,
291,
14,
2108,
14,
30518,
14,
981,
32540,
8,
576,
9,
288,
340,
5518,
13569,
26,
355,
291,
14,
2108,
14,
3176,
13569,
8,
505,
12,
5518,
13569,
14,
2108,
9,
288,
587,
26,
355,
291,
14,
2108,
14,
14988,
8,
505,
9,
398,
347,
5518,
13569,
8,
277,
12,
1031,
12,
2984,
1716,
304,
288,
291,
14,
2108,
14,
3176,
13569,
8,
932,
14,
2108,
12,
2984,
1716,
14,
2108,
9,
288,
1031,
14,
1708,
275,
291,
398,
347,
2813,
3493,
8,
277,
12,
1031,
304,
288,
340,
1031,
14,
2108,
14,
24899,
508,
291,
14,
2108,
26,
355,
291,
14,
2108,
14,
2168,
3493,
8,
932,
14,
2108,
9,
288,
1031,
14,
1708,
275,
488,
398,
347,
295,
1708,
7139,
8,
277,
12,
892,
6652,
304,
288,
1830,
291,
14,
2108,
14,
1989,
3493,
6300,
837,
355,
1982,
275,
291,
14,
2108,
14,
22262,
355,
291,
14,
2108,
14,
2168,
3493,
8,
1739,
9,
355,
892,
6652,
14,
2108,
14,
14988,
8,
1739,
9,
288,
291,
14,
10626,
275,
942,
398,
347,
664,
5379,
8,
277,
304,
288,
372,
20516,
1296,
8,
277,
14,
2108,
9,
398,
347,
663,
5379,
8,
277,
12,
3004,
304,
288,
340,
3004,
26,
355,
367,
536,
12,
574,
315,
769,
8,
2987,
14,
1744,
5109,
490,
340,
1228,
8,
354,
12,
2008,
304,
717,
340,
536,
59,
16,
61,
365,
440,
488,
26,
1169,
12313,
985,
275,
334,
354,
59,
16,
61,
435,
14725,
435,
536,
59,
17,
566,
717,
587,
26,
1169,
12313,
985,
275,
536,
59,
17,
61,
717,
291,
14,
2108,
14,
17618,
2709,
8,
354,
59,
18,
467,
12313,
985,
12,
8105,
574,
9,
490,
587,
26,
717,
291,
14,
2108,
14,
17618,
8,
1169,
536,
12,
574,
9,
267,
3004,
275,
3324,
8,
362,
5379,
12,
663,
5379,
9,
398,
347,
7289,
1716,
8,
277,
304,
288,
372,
5013,
6437,
8,
277,
14,
2108,
14,
6311,
1716,
8,
797,
430,
398,
347,
28770,
8,
277,
304,
288,
372,
291,
14,
2108,
14,
1989,
3493,
6300,
342,
398,
347,
664,
985,
7075,
8,
277,
304,
288,
340,
291,
14,
3251,
365,
488,
26,
355,
372,
10747,
905,
1360,
2255,
291,
14,
354,
288,
587,
26,
355,
372,
291,
14,
3251,
12,
291,
14,
354,
398,
536,
7075,
275,
3324,
8,
16405,
7075,
9,
339,
1021,
12178,
6437,
1547,
1095,
14,
20437,
304,
267,
347,
2213,
2543,
8,
277,
304,
288,
291,
14,
4556,
275,
577,
676,
14,
362,
10462,
7921,
1252,
981,
5564,
8,
403,
12,
488,
12,
488,
9,
288,
372,
13852,
14,
3280,
8,
277,
9,
398,
347,
5518,
21629,
8,
277,
12,
1526,
304,
288,
536,
275,
1526,
905,
354,
937,
288,
25753,
275,
1526,
905,
25311,
937,
288,
22873,
275,
1526,
905,
20150,
937,
953,
8266,
5472,
275,
577,
676,
14,
362,
10462,
7921,
342,
288,
13265,
275,
8266,
5472,
14,
981,
5564,
804,
8,
354,
12,
25753,
12,
22873,
9,
288,
291,
14,
3554,
14,
14988,
8,
1716,
6437,
8,
6356,
430,
288,
340,
577,
676,
508,
19165,
26,
355,
13265,
14,
30518,
275,
291,
14,
4556,
398,
347,
1819,
2543,
8,
277,
12,
536,
12,
3231,
29,
403,
304,
288,
340,
3231,
365,
488,
436,
291,
14,
885,
8814,
365,
488,
26,
355,
1031,
275,
291,
14,
4556,
14,
20296,
8,
354,
9,
288,
587,
26,
355,
1031,
275,
291,
14,
4556,
14,
20296,
2709,
8,
3251,
12,
536,
9,
953,
372,
5013,
6437,
8,
932,
9,
398,
347,
3721,
2543,
8,
277,
12,
666,
304,
288,
372,
5013,
6437,
8,
277,
14,
4556,
14,
981,
7488,
8,
576,
430,
398,
347,
7956,
2543,
8,
277,
304,
288,
372,
5013,
6437,
8,
277,
14,
4556,
14,
981,
5564,
11080,
1012,
398,
347,
5666,
3493,
8,
277,
12,
1031,
304,
288,
291,
14,
4556,
14,
14988,
8,
932,
14,
2108,
9,
398,
347,
511,
7299,
8,
277,
12,
1819,
304,
288,
372,
511,
7299,
8,
2108,
9,
398,
347,
664
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
421,
199,
504,
2748,
14,
4556,
492,
19165,
12,
5013,
199,
646,
13852,
199,
199,
504,
1275,
492,
485,
1095,
199,
504,
2508,
492,
5262,
199,
504,
2508,
5559,
492,
10747,
199,
504,
2508,
1208,
492,
859,
2927,
2927,
421,
199,
318,
664,
20106,
6437,
8,
20106,
7921,
304,
272,
577,
676,
275,
577,
676,
7921,
339,
1021,
20516,
1296,
8,
785,
304,
267,
347,
636,
826,
721,
277,
12,
1819,
304,
288,
291,
14,
2108,
275,
1819,
398,
347,
636,
1661,
721,
277,
304,
288,
372,
769,
8,
277,
14,
2108,
14,
2987,
14,
1744,
342,
2843,
1661,
4533,
398,
347,
636,
8617,
721,
277,
12,
536,
12,
574,
304,
288,
291,
14,
2108,
14,
17618,
8,
354,
12,
574,
9,
398,
347,
636,
552,
721,
277,
304,
288,
372,
822,
8,
513,
8,
277,
14,
2108,
14,
2987,
14,
1744,
4059,
398,
347,
2974,
8,
277,
304,
288,
372,
3842,
1053,
59,
16,
467,
1242,
59,
17,
566,
367,
1242,
315,
490,
769,
8,
277,
14,
2108,
14,
2987,
14,
1744,
24821,
398,
347,
2883,
8,
277,
304,
288,
372,
769,
8,
277,
14,
2108,
14,
2987,
14,
1612,
1012,
398,
347,
636,
6095,
721,
277,
12,
536,
304,
288,
372,
291,
14,
2108,
14,
12956,
8,
354,
9,
398,
347,
636,
6134,
721,
277,
12,
536,
304,
288,
340,
1228,
8,
354,
12,
2008,
304,
355,
746,
4279,
288,
587,
26,
355,
372,
291,
14,
2108,
14,
1989,
1646,
8,
354,
9,
339,
1021,
5013,
6437,
1547,
1095,
14,
1716,
304,
267,
347,
636,
826,
721,
277,
12,
1819,
304,
288,
485,
1095,
14,
1716,
855,
826,
721,
277,
12,
1819,
14,
13777,
9,
288,
291,
14,
2108,
275,
1819,
398,
3231,
275,
3324,
8,
2734,
291,
26,
2688,
8,
277,
14,
2108,
12,
298,
27855,
531,
2490,
436,
291,
14,
2108,
14,
27855,
503,
488,
9,
398,
347,
5666,
3493,
8,
277,
12,
1031,
304,
288,
1031,
14,
1708,
275,
291,
288,
291,
14,
2108,
14,
14988,
8,
932,
14,
2108,
9,
398,
347,
5518,
1872,
8,
277,
12,
666,
12,
5518,
13569,
29,
403,
304,
288,
1318,
275,
291,
14,
2108,
14,
30518,
14,
981,
32540,
8,
576,
9,
288,
340,
5518,
13569,
26,
355,
291,
14,
2108,
14,
3176,
13569,
8,
505,
12,
5518,
13569,
14,
2108,
9,
288,
587,
26,
355,
291,
14,
2108,
14,
14988,
8,
505,
9,
398,
347,
5518,
13569,
8,
277,
12,
1031,
12,
2984,
1716,
304,
288,
291,
14,
2108,
14,
3176,
13569,
8,
932,
14,
2108,
12,
2984,
1716,
14,
2108,
9,
288,
1031,
14,
1708,
275,
291,
398,
347,
2813,
3493,
8,
277,
12,
1031,
304,
288,
340,
1031,
14,
2108,
14,
24899,
508,
291,
14,
2108,
26,
355,
291,
14,
2108,
14,
2168,
3493,
8,
932,
14,
2108,
9,
288,
1031,
14,
1708,
275,
488,
398,
347,
295,
1708,
7139,
8,
277,
12,
892,
6652,
304,
288,
1830,
291,
14,
2108,
14,
1989,
3493,
6300,
837,
355,
1982,
275,
291,
14,
2108,
14,
22262,
355,
291,
14,
2108,
14,
2168,
3493,
8,
1739,
9,
355,
892,
6652,
14,
2108,
14,
14988,
8,
1739,
9,
288,
291,
14,
10626,
275,
942,
398,
347,
664,
5379,
8,
277,
304,
288,
372,
20516,
1296,
8,
277,
14,
2108,
9,
398,
347,
663,
5379,
8,
277,
12,
3004,
304,
288,
340,
3004,
26,
355,
367,
536,
12,
574,
315,
769,
8,
2987,
14,
1744,
5109,
490,
340,
1228,
8,
354,
12,
2008,
304,
717,
340,
536,
59,
16,
61,
365,
440,
488,
26,
1169,
12313,
985,
275,
334,
354,
59,
16,
61,
435,
14725,
435,
536,
59,
17,
566,
717,
587,
26,
1169,
12313,
985,
275,
536,
59,
17,
61,
717,
291,
14,
2108,
14,
17618,
2709,
8,
354,
59,
18,
467,
12313,
985,
12,
8105,
574,
9,
490,
587,
26,
717,
291,
14,
2108,
14,
17618,
8,
1169,
536,
12,
574,
9,
267,
3004,
275,
3324,
8,
362,
5379,
12,
663,
5379,
9,
398,
347,
7289,
1716,
8,
277,
304,
288,
372,
5013,
6437,
8,
277,
14,
2108,
14,
6311,
1716,
8,
797,
430,
398,
347,
28770,
8,
277,
304,
288,
372,
291,
14,
2108,
14,
1989,
3493,
6300,
342,
398,
347,
664,
985,
7075,
8,
277,
304,
288,
340,
291,
14,
3251,
365,
488,
26,
355,
372,
10747,
905,
1360,
2255,
291,
14,
354,
288,
587,
26,
355,
372,
291,
14,
3251,
12,
291,
14,
354,
398,
536,
7075,
275,
3324,
8,
16405,
7075,
9,
339,
1021,
12178,
6437,
1547,
1095,
14,
20437,
304,
267,
347,
2213,
2543,
8,
277,
304,
288,
291,
14,
4556,
275,
577,
676,
14,
362,
10462,
7921,
1252,
981,
5564,
8,
403,
12,
488,
12,
488,
9,
288,
372,
13852,
14,
3280,
8,
277,
9,
398,
347,
5518,
21629,
8,
277,
12,
1526,
304,
288,
536,
275,
1526,
905,
354,
937,
288,
25753,
275,
1526,
905,
25311,
937,
288,
22873,
275,
1526,
905,
20150,
937,
953,
8266,
5472,
275,
577,
676,
14,
362,
10462,
7921,
342,
288,
13265,
275,
8266,
5472,
14,
981,
5564,
804,
8,
354,
12,
25753,
12,
22873,
9,
288,
291,
14,
3554,
14,
14988,
8,
1716,
6437,
8,
6356,
430,
288,
340,
577,
676,
508,
19165,
26,
355,
13265,
14,
30518,
275,
291,
14,
4556,
398,
347,
1819,
2543,
8,
277,
12,
536,
12,
3231,
29,
403,
304,
288,
340,
3231,
365,
488,
436,
291,
14,
885,
8814,
365,
488,
26,
355,
1031,
275,
291,
14,
4556,
14,
20296,
8,
354,
9,
288,
587,
26,
355,
1031,
275,
291,
14,
4556,
14,
20296,
2709,
8,
3251,
12,
536,
9,
953,
372,
5013,
6437,
8,
932,
9,
398,
347,
3721,
2543,
8,
277,
12,
666,
304,
288,
372,
5013,
6437,
8,
277,
14,
4556,
14,
981,
7488,
8,
576,
430,
398,
347,
7956,
2543,
8,
277,
304,
288,
372,
5013,
6437,
8,
277,
14,
4556,
14,
981,
5564,
11080,
1012,
398,
347,
5666,
3493,
8,
277,
12,
1031,
304,
288,
291,
14,
4556,
14,
14988,
8,
932,
14,
2108,
9,
398,
347,
511,
7299,
8,
277,
12,
1819,
304,
288,
372,
511,
7299,
8,
2108,
9,
398,
347,
664,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
asreimer/davitpy_asr
|
gme/base/fillGmedb.py
|
3
|
2982
|
# Copyright (C) 2012 VT SuperDARN Lab
# Full license can be found in LICENSE.txt
#
# 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/>.
def fillGmeDb(time='recent'):
import gme, os
import pydarn.sdio.dbUtils as dbu
from multiprocessing import Process
import datetime as dt
now = dt.datetime.now()
if(time == 'recent'):
sYear = dt.datetime.now().year-5
#fill the omni database
p0 = Process(target=gme.mapOmniMongo, args=(sYear,now.year,1))
#fill the omni database
p1 = Process(target=gme.mapOmniMongo, args=(sYear,now.year))
#fill the poes database
p2 = Process(target=gme.mapPoesMongo, args=(sYear,now.year))
#fill the kp database
p3 = Process(target=gme.mapKpMongo, args=(sYear,now.year))
#fill the kp database
p4 = Process(target=gme.mapDstMongo, args=(sYear,now.year))
#fill the kp database
p5 = Process(target=gme.mapAeMongo, args=(sYear,now.year))
#fill the kp database
p6 = Process(target=gme.mapSymAsyMongo, args=(sYear,now.year))
else:
db = dbu.getDbConn(username=os.environ['DBWRITEUSER'],password=os.environ['DBWRITEPASS'],dbName='gme')
db.command('repairDatabase')
#fill the omni database
p0 = Process(target=gme.mapOmniMongo, args=(1995,now.year,1))
#fill the omni database
p1 = Process(target=gme.mapOmniMongo, args=(1995,now.year))
#fill the poes database
p2 = Process(target=gme.mapPoesMongo, args=(1998,now.year))
#fill the kp database
p3 = Process(target=gme.mapKpMongo, args=(1980,now.year))
#fill the kp database
p4 = Process(target=gme.mapDstMongo, args=(1980,now.year))
#fill the kp database
p5 = Process(target=gme.mapAeMongo, args=(1980,now.year))
#fill the kp database
p6 = Process(target=gme.mapSymAsyMongo, args=(1980,now.year))
try: p0.start()
except Exception,e:
print e
print 'problem filling Omni db'
try: p1.start()
except Exception,e:
print e
print 'problem filling Omni db'
try: p2.start()
except Exception,e:
print e
print 'problem filling Poes db'
try: p3.start()
except Exception,e:
print e
print 'problem filling Kp db'
try: p4.start()
except Exception,e:
print e
print 'problem filling Dst db'
try: p5.start()
except Exception,e:
print e
print 'problem filling AE db'
try: p6.start()
except Exception,e:
print e
print 'problem filling AE db'
p0.join()
p1.join()
p2.join()
p3.join()
p4.join()
p5.join()
p6.join()
|
gpl-3.0
|
[
3,
1898,
334,
35,
9,
6029,
221,
812,
52,
17897,
36,
26513,
16871,
199,
3,
16579,
4190,
883,
506,
1911,
315,
5113,
14,
2424,
199,
3,
221,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
318,
5554,
39,
278,
8882,
8,
521,
534,
14951,
735,
199,
198,
646,
486,
278,
12,
747,
199,
198,
646,
1134,
68,
1060,
14,
83,
3006,
14,
697,
7535,
465,
366,
464,
199,
198,
504,
12866,
492,
7132,
199,
198,
646,
2197,
465,
4487,
199,
198,
2131,
275,
4487,
14,
2083,
14,
2131,
342,
8299,
198,
692,
8,
521,
508,
283,
14951,
735,
507,
198,
83,
15731,
275,
4487,
14,
2083,
14,
2131,
1252,
3403,
13,
21,
507,
198,
3,
4498,
314,
30511,
8445,
3050,
507,
198,
80,
16,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
29197,
8445,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
12,
17,
430,
507,
198,
3,
4498,
314,
30511,
8445,
3050,
507,
198,
80,
17,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
29197,
8445,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1115,
397,
3050,
507,
198,
80,
18,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
1575,
397,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
19,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
43,
80,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
20,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
31413,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
21,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
33,
69,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
22,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
16594,
33,
1786,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
430,
199,
198,
2836,
26,
507,
198,
697,
275,
366,
464,
14,
362,
8882,
6805,
8,
2473,
29,
736,
14,
2314,
459,
2846,
10387,
3791,
995,
2060,
29,
736,
14,
2314,
459,
2846,
10387,
6909,
995,
697,
985,
534,
71,
278,
358,
507,
198,
697,
14,
1531,
360,
25279,
7243,
358,
507,
198,
3,
4498,
314,
30511,
8445,
3050,
507,
198,
80,
16,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
29197,
8445,
20393,
12,
1249,
2687,
7155,
21,
12,
2131,
14,
3403,
12,
17,
430,
507,
198,
3,
4498,
314,
30511,
8445,
3050,
507,
198,
80,
17,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
29197,
8445,
20393,
12,
1249,
2687,
7155,
21,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1115,
397,
3050,
507,
198,
80,
18,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
1575,
397,
20393,
12,
1249,
2687,
23756,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
19,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
43,
80,
20393,
12,
1249,
2687,
26981,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
20,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
31413,
20393,
12,
1249,
2687,
26981,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
21,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
33,
69,
20393,
12,
1249,
2687,
26981,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
22,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
16594,
33,
1786,
20393,
12,
1249,
2687,
26981,
12,
2131,
14,
3403,
430,
18118,
198,
893,
26,
299,
16,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
593,
77,
8445,
1592,
7,
18118,
198,
893,
26,
299,
17,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
593,
77,
8445,
1592,
7,
18118,
198,
893,
26,
299,
18,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
4376,
397,
1592,
7,
18118,
198,
893,
26,
299,
19,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
1804,
80,
1592,
7,
18118,
198,
893,
26,
299,
20,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
577,
270,
1592,
7,
18118,
198,
893,
26,
299,
21,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
24475,
1592,
7,
18118,
198,
893,
26,
299,
22,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
24475,
1592,
7,
686,
18118,
198,
80,
16,
14,
904,
342,
199,
198,
80,
17,
14,
904,
342,
199,
198,
80,
18,
14,
904,
342,
199,
198,
80,
19,
14,
904,
342,
199,
198,
80
] |
[
1898,
334,
35,
9,
6029,
221,
812,
52,
17897,
36,
26513,
16871,
199,
3,
16579,
4190,
883,
506,
1911,
315,
5113,
14,
2424,
199,
3,
221,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
318,
5554,
39,
278,
8882,
8,
521,
534,
14951,
735,
199,
198,
646,
486,
278,
12,
747,
199,
198,
646,
1134,
68,
1060,
14,
83,
3006,
14,
697,
7535,
465,
366,
464,
199,
198,
504,
12866,
492,
7132,
199,
198,
646,
2197,
465,
4487,
199,
198,
2131,
275,
4487,
14,
2083,
14,
2131,
342,
8299,
198,
692,
8,
521,
508,
283,
14951,
735,
507,
198,
83,
15731,
275,
4487,
14,
2083,
14,
2131,
1252,
3403,
13,
21,
507,
198,
3,
4498,
314,
30511,
8445,
3050,
507,
198,
80,
16,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
29197,
8445,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
12,
17,
430,
507,
198,
3,
4498,
314,
30511,
8445,
3050,
507,
198,
80,
17,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
29197,
8445,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1115,
397,
3050,
507,
198,
80,
18,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
1575,
397,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
19,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
43,
80,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
20,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
31413,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
21,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
33,
69,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
22,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
16594,
33,
1786,
20393,
12,
1249,
2687,
83,
15731,
12,
2131,
14,
3403,
430,
199,
198,
2836,
26,
507,
198,
697,
275,
366,
464,
14,
362,
8882,
6805,
8,
2473,
29,
736,
14,
2314,
459,
2846,
10387,
3791,
995,
2060,
29,
736,
14,
2314,
459,
2846,
10387,
6909,
995,
697,
985,
534,
71,
278,
358,
507,
198,
697,
14,
1531,
360,
25279,
7243,
358,
507,
198,
3,
4498,
314,
30511,
8445,
3050,
507,
198,
80,
16,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
29197,
8445,
20393,
12,
1249,
2687,
7155,
21,
12,
2131,
14,
3403,
12,
17,
430,
507,
198,
3,
4498,
314,
30511,
8445,
3050,
507,
198,
80,
17,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
29197,
8445,
20393,
12,
1249,
2687,
7155,
21,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1115,
397,
3050,
507,
198,
80,
18,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
1575,
397,
20393,
12,
1249,
2687,
23756,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
19,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
43,
80,
20393,
12,
1249,
2687,
26981,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
20,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
31413,
20393,
12,
1249,
2687,
26981,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
21,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
33,
69,
20393,
12,
1249,
2687,
26981,
12,
2131,
14,
3403,
430,
507,
198,
3,
4498,
314,
1022,
80,
3050,
507,
198,
80,
22,
275,
7132,
8,
1375,
29,
71,
278,
14,
1130,
16594,
33,
1786,
20393,
12,
1249,
2687,
26981,
12,
2131,
14,
3403,
430,
18118,
198,
893,
26,
299,
16,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
593,
77,
8445,
1592,
7,
18118,
198,
893,
26,
299,
17,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
593,
77,
8445,
1592,
7,
18118,
198,
893,
26,
299,
18,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
4376,
397,
1592,
7,
18118,
198,
893,
26,
299,
19,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
1804,
80,
1592,
7,
18118,
198,
893,
26,
299,
20,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
577,
270,
1592,
7,
18118,
198,
893,
26,
299,
21,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
24475,
1592,
7,
18118,
198,
893,
26,
299,
22,
14,
928,
342,
199,
198,
2590,
2186,
12,
69,
26,
507,
198,
1361,
325,
507,
198,
1361,
283,
6462,
32499,
24475,
1592,
7,
686,
18118,
198,
80,
16,
14,
904,
342,
199,
198,
80,
17,
14,
904,
342,
199,
198,
80,
18,
14,
904,
342,
199,
198,
80,
19,
14,
904,
342,
199,
198,
80,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Edraak/edraak-platform
|
openedx/core/djangoapps/video_config/forms.py
|
14
|
1326
|
"""
Defines a form for providing validation of HLS Playback course-specific configuration.
"""
import logging
from django import forms
from opaque_keys import InvalidKeyError
from opaque_keys.edx.locator import CourseLocator
from openedx.core.djangoapps.video_config.models import (
CourseHLSPlaybackEnabledFlag,
CourseVideoTranscriptEnabledFlag,
)
from openedx.core.lib.courses import clean_course_id
from xmodule.modulestore.django import modulestore
log = logging.getLogger(__name__)
class CourseSpecificFlagAdminBaseForm(forms.ModelForm):
"""
Form for course-specific feature configuration.
"""
# Make abstract base class
class Meta(object):
abstract = True
def clean_course_id(self):
"""
Validate the course id
"""
return clean_course_id(self)
class CourseHLSPlaybackFlagAdminForm(CourseSpecificFlagAdminBaseForm):
"""
Form for course-specific HLS Playback configuration.
"""
class Meta(object):
model = CourseHLSPlaybackEnabledFlag
fields = '__all__'
class CourseVideoTranscriptFlagAdminForm(CourseSpecificFlagAdminBaseForm):
"""
Form for course-specific Video Transcript configuration.
"""
class Meta(object):
model = CourseVideoTranscriptEnabledFlag
fields = '__all__'
|
agpl-3.0
|
[
624,
199,
23891,
282,
1824,
367,
13070,
6411,
402,
869,
5296,
16527,
894,
2518,
13,
6100,
2897,
14,
199,
624,
199,
646,
2050,
199,
199,
504,
1639,
492,
4513,
199,
504,
15058,
63,
1612,
492,
6378,
10230,
199,
504,
15058,
63,
1612,
14,
8268,
14,
6354,
492,
31480,
199,
199,
504,
22709,
14,
1018,
14,
16432,
14,
3722,
63,
888,
14,
992,
492,
334,
272,
5531,
40,
5296,
9651,
894,
6589,
5318,
12,
272,
5531,
9166,
14612,
1579,
6589,
5318,
12,
199,
9,
199,
504,
22709,
14,
1018,
14,
773,
14,
11653,
492,
3633,
63,
1972,
63,
344,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
5531,
16786,
5318,
4880,
1563,
2821,
8,
3351,
14,
15937,
304,
272,
408,
272,
8204,
367,
2518,
13,
6100,
3878,
2897,
14,
272,
408,
339,
327,
4155,
9006,
1300,
1021,
272,
1021,
6288,
8,
785,
304,
267,
9006,
275,
715,
339,
347,
3633,
63,
1972,
63,
344,
8,
277,
304,
267,
408,
267,
12134,
314,
2518,
1305,
267,
408,
267,
372,
3633,
63,
1972,
63,
344,
8,
277,
9,
421,
199,
533,
5531,
40,
5296,
9651,
894,
5318,
4880,
2821,
8,
6979,
16786,
5318,
4880,
1563,
2821,
304,
272,
408,
272,
8204,
367,
2518,
13,
6100,
869,
5296,
16527,
894,
2897,
14,
272,
408,
339,
1021,
6288,
8,
785,
304,
267,
1402,
275,
5531,
40,
5296,
9651,
894,
6589,
5318,
267,
1504,
275,
2560,
452,
12217,
421,
199,
533,
5531,
9166,
14612,
1579,
5318,
4880,
2821,
8,
6979,
16786,
5318,
4880,
1563,
2821,
304,
272,
408,
272,
8204,
367,
2518,
13,
6100,
15709,
19894,
1579,
2897,
14,
272,
408,
339,
1021,
6288,
8,
785,
304,
267,
1402,
275,
5531,
9166,
14612,
1579,
6589,
5318,
267,
1504,
275,
2560,
452,
12217,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
23891,
282,
1824,
367,
13070,
6411,
402,
869,
5296,
16527,
894,
2518,
13,
6100,
2897,
14,
199,
624,
199,
646,
2050,
199,
199,
504,
1639,
492,
4513,
199,
504,
15058,
63,
1612,
492,
6378,
10230,
199,
504,
15058,
63,
1612,
14,
8268,
14,
6354,
492,
31480,
199,
199,
504,
22709,
14,
1018,
14,
16432,
14,
3722,
63,
888,
14,
992,
492,
334,
272,
5531,
40,
5296,
9651,
894,
6589,
5318,
12,
272,
5531,
9166,
14612,
1579,
6589,
5318,
12,
199,
9,
199,
504,
22709,
14,
1018,
14,
773,
14,
11653,
492,
3633,
63,
1972,
63,
344,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
5531,
16786,
5318,
4880,
1563,
2821,
8,
3351,
14,
15937,
304,
272,
408,
272,
8204,
367,
2518,
13,
6100,
3878,
2897,
14,
272,
408,
339,
327,
4155,
9006,
1300,
1021,
272,
1021,
6288,
8,
785,
304,
267,
9006,
275,
715,
339,
347,
3633,
63,
1972,
63,
344,
8,
277,
304,
267,
408,
267,
12134,
314,
2518,
1305,
267,
408,
267,
372,
3633,
63,
1972,
63,
344,
8,
277,
9,
421,
199,
533,
5531,
40,
5296,
9651,
894,
5318,
4880,
2821,
8,
6979,
16786,
5318,
4880,
1563,
2821,
304,
272,
408,
272,
8204,
367,
2518,
13,
6100,
869,
5296,
16527,
894,
2897,
14,
272,
408,
339,
1021,
6288,
8,
785,
304,
267,
1402,
275,
5531,
40,
5296,
9651,
894,
6589,
5318,
267,
1504,
275,
2560,
452,
12217,
421,
199,
533,
5531,
9166,
14612,
1579,
5318,
4880,
2821,
8,
6979,
16786,
5318,
4880,
1563,
2821,
304,
272,
408,
272,
8204,
367,
2518,
13,
6100,
15709,
19894,
1579,
2897,
14,
272,
408,
339,
1021,
6288,
8,
785,
304,
267,
1402,
275,
5531,
9166,
14612,
1579,
6589,
5318,
267,
1504,
275,
2560,
452,
12217,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
ABoothInTheWild/baseball-research
|
NBA/NBA_17/nba2017SeasonResults.py
|
1
|
2218
|
# -*- coding: utf-8 -*-
"""
Created on Fri Sep 07 14:28:16 2018
@author: Alexander
"""
# -*- coding: utf-8 -*-
"""
Created on Fri Jul 27 15:01:09 2018
@author: abooth
"""
from xmlstats import xmlstats
import numpy as np
import pandas as pd
access_token = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
user_agent = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
stats = xmlstats.Xmlstats(access_token, user_agent)
datetest = "20171017"
standingsOnDate = stats.standings(date=datetest, sport="nba")
sum([standing.won for standing in standingsOnDate.standing]) #3
teamIds = np.sort(np.array([standing.team_id for standing in standingsOnDate.standing]))
teamWins = []
teamLosses = []
for teamId in teamIds:
teamWins.extend([standing.won for standing in standingsOnDate.standing if standing.team_id == teamId])
teamLosses.extend([standing.lost for standing in standingsOnDate.standing if standing.team_id == teamId])
df = pd.DataFrame(np.column_stack([teamIds,teamWins, teamLosses]),
columns = ['xmlstatsTeamId','Wins'+datetest, 'Losses'+datetest])
from datetime import timedelta, date
import time
#https://stackoverflow.com/questions/1060279/iterating-through-a-range-of-dates-in-python
def daterange(start_date, end_date):
for n in range(int ((end_date - start_date).days)):
yield start_date + timedelta(n)
seasonResults = pd.DataFrame({'xmlstatsTeamId':teamIds})
start_date = date(2017, 10, 17)
end_date = date(2018, 4, 12)
for single_date in daterange(start_date, end_date):
date_format = single_date.strftime("%Y%m%d")
standingsOnDate = stats.standings(date=date_format, sport="nba")
teamWins = []
teamLosses = []
for teamId in teamIds:
teamWins.extend([standing.won for standing in standingsOnDate.standing if standing.team_id == teamId])
teamLosses.extend([standing.lost for standing in standingsOnDate.standing if standing.team_id == teamId])
seasonResults["Wins_"+date_format] = teamWins
seasonResults["Losses_"+date_format] = teamLosses
print(date_format)
time.sleep(12) #6 requests a minute
seasonResults.to_csv("nba2017SeasonResults.csv", index=False)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
202,
199,
624,
202,
199,
10502,
641,
31712,
428,
1545,
24937,
4329,
26,
1651,
26,
975,
14894,
2999,
199,
32,
2502,
26,
22986,
11438,
202,
199,
624,
2999,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
202,
199,
624,
202,
199,
10502,
641,
31712,
1603,
348,
8087,
4114,
26,
614,
26,
1643,
14894,
2999,
199,
32,
2502,
26,
282,
15056,
273,
202,
199,
624,
2999,
199,
504,
2748,
3200,
492,
2748,
3200,
202,
199,
646,
2680,
465,
980,
202,
199,
646,
10634,
465,
6454,
2999,
199,
2732,
63,
1418,
275,
283,
25837,
25837,
13312,
56,
7,
202,
199,
751,
63,
4054,
275,
283,
25837,
25837,
6873,
7,
2999,
199,
3200,
275,
2748,
3200,
14,
8672,
3200,
8,
2732,
63,
1418,
12,
922,
63,
4054,
9,
2999,
199,
602,
396,
275,
298,
1797,
3172,
9570,
2,
202,
199,
7935,
780,
3314,
2506,
275,
5020,
14,
7935,
780,
8,
602,
29,
602,
396,
12,
308,
719,
628,
78,
2470,
531,
2999,
199,
1838,
779,
18126,
14,
87,
265,
367,
10584,
316,
315,
10584,
780,
3314,
2506,
14,
18126,
566,
327,
19,
2999,
199,
5969,
11506,
275,
980,
14,
3191,
8,
1590,
14,
1144,
779,
18126,
14,
5969,
63,
344,
367,
10584,
316,
315,
10584,
780,
3314,
2506,
14,
18126,
2459,
2999,
199,
5969,
55,
3617,
275,
942,
202,
199,
5969,
44,
736,
874,
275,
942,
202,
199,
509,
8099,
1304,
315,
8099,
11506,
26,
1128,
8099,
55,
3617,
14,
2880,
779,
18126,
14,
87,
265,
367,
10584,
316,
315,
10584,
780,
3314,
2506,
14,
18126,
340,
10584,
316,
14,
5969,
63,
344,
508,
8099,
1304,
566,
1128,
8099,
44,
736,
874,
14,
2880,
779,
18126,
14,
22031,
367,
10584,
316,
315,
10584,
780,
3314,
2506,
14,
18126,
340,
10584,
316,
14,
5969,
63,
344,
508,
8099,
1304,
566,
2999,
199,
1587,
275,
6454,
14,
9205,
8,
1590,
14,
2301,
63,
2340,
779,
5969,
11506,
12,
5969,
55,
3617,
12,
8099,
44,
736,
874,
2522,
28086,
4362,
275,
788,
1652,
3200,
13126,
1304,
1673,
55,
3617,
6828,
602,
396,
12,
283,
44,
736,
874,
6828,
602,
396,
566,
2999,
199,
504,
2197,
492,
6871,
12,
1434,
202,
199,
646,
900,
2999,
199,
3,
2859,
921,
23153,
14,
957,
15,
16069,
15,
7357,
996,
1965,
15,
1661,
1958,
13,
8304,
13,
65,
13,
1842,
13,
1618,
13,
9356,
13,
262,
13,
1548,
202,
199,
318,
1434,
1842,
8,
928,
63,
602,
12,
1284,
63,
602,
304,
1128,
367,
302,
315,
1425,
8,
442,
3666,
500,
63,
602,
446,
1343,
63,
602,
680,
4899,
2298,
1039,
1995,
1343,
63,
602,
435,
6871,
8,
78,
9,
2999,
199,
12605,
6579,
275,
6454,
14,
9205,
3252,
1652,
3200,
13126,
1304,
356,
5969,
11506,
1552,
202,
199,
928,
63,
602,
275,
1434,
8,
10680,
12,
1616,
12,
5557,
9,
202,
199,
500,
63,
602,
275,
1434,
8,
12682,
12,
841,
12,
3144,
9,
202,
199,
509,
2849,
63,
602,
315,
1434,
1842,
8,
928,
63,
602,
12,
1284,
63,
602,
304,
1128,
1434,
63,
908,
275,
2849,
63,
602,
14,
6205,
3647,
57,
5,
77,
5,
68,
531,
1128,
10584,
780,
3314,
2506,
275,
5020,
14,
7935,
780,
8,
602,
29,
602,
63,
908,
12,
308,
719,
628,
78,
2470,
531,
1128,
8099,
55,
3617,
275,
942,
1128,
8099,
44,
736,
874,
275,
942,
1128,
367,
8099,
1304,
315,
8099,
11506,
26,
1039,
8099,
55,
3617,
14,
2880,
779,
18126,
14,
87,
265,
367,
10584,
316,
315,
10584,
780,
3314,
2506,
14,
18126,
340,
10584,
316,
14,
5969,
63,
344,
508,
8099,
1304,
566,
1039,
8099,
44,
736,
874,
14,
2880,
779,
18126,
14,
22031,
367,
10584,
316,
315,
10584,
780,
3314,
2506,
14,
18126,
340,
10584,
316,
14,
5969,
63,
344,
508,
8099,
1304,
566,
1128,
14718,
6579,
905,
55,
3617,
63,
7709,
602,
63,
908,
61,
275,
8099,
55,
3617,
1128,
14718,
6579,
905,
44,
736,
874,
63,
7709,
602,
63,
908,
61,
275,
8099,
44,
736,
874,
1128,
870,
8,
602,
63,
908,
9,
1128,
900,
14,
4532,
8,
713,
9,
327,
22,
4145,
282,
12709,
2999,
199,
12605,
6579,
14,
475,
63,
4737,
480,
78,
2470,
10680,
28905,
6579,
14,
4737,
401,
1478,
29,
797,
9,
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
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
202,
199,
624,
202,
199,
10502,
641,
31712,
428,
1545,
24937,
4329,
26,
1651,
26,
975,
14894,
2999,
199,
32,
2502,
26,
22986,
11438,
202,
199,
624,
2999,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
202,
199,
624,
202,
199,
10502,
641,
31712,
1603,
348,
8087,
4114,
26,
614,
26,
1643,
14894,
2999,
199,
32,
2502,
26,
282,
15056,
273,
202,
199,
624,
2999,
199,
504,
2748,
3200,
492,
2748,
3200,
202,
199,
646,
2680,
465,
980,
202,
199,
646,
10634,
465,
6454,
2999,
199,
2732,
63,
1418,
275,
283,
25837,
25837,
13312,
56,
7,
202,
199,
751,
63,
4054,
275,
283,
25837,
25837,
6873,
7,
2999,
199,
3200,
275,
2748,
3200,
14,
8672,
3200,
8,
2732,
63,
1418,
12,
922,
63,
4054,
9,
2999,
199,
602,
396,
275,
298,
1797,
3172,
9570,
2,
202,
199,
7935,
780,
3314,
2506,
275,
5020,
14,
7935,
780,
8,
602,
29,
602,
396,
12,
308,
719,
628,
78,
2470,
531,
2999,
199,
1838,
779,
18126,
14,
87,
265,
367,
10584,
316,
315,
10584,
780,
3314,
2506,
14,
18126,
566,
327,
19,
2999,
199,
5969,
11506,
275,
980,
14,
3191,
8,
1590,
14,
1144,
779,
18126,
14,
5969,
63,
344,
367,
10584,
316,
315,
10584,
780,
3314,
2506,
14,
18126,
2459,
2999,
199,
5969,
55,
3617,
275,
942,
202,
199,
5969,
44,
736,
874,
275,
942,
202,
199,
509,
8099,
1304,
315,
8099,
11506,
26,
1128,
8099,
55,
3617,
14,
2880,
779,
18126,
14,
87,
265,
367,
10584,
316,
315,
10584,
780,
3314,
2506,
14,
18126,
340,
10584,
316,
14,
5969,
63,
344,
508,
8099,
1304,
566,
1128,
8099,
44,
736,
874,
14,
2880,
779,
18126,
14,
22031,
367,
10584,
316,
315,
10584,
780,
3314,
2506,
14,
18126,
340,
10584,
316,
14,
5969,
63,
344,
508,
8099,
1304,
566,
2999,
199,
1587,
275,
6454,
14,
9205,
8,
1590,
14,
2301,
63,
2340,
779,
5969,
11506,
12,
5969,
55,
3617,
12,
8099,
44,
736,
874,
2522,
28086,
4362,
275,
788,
1652,
3200,
13126,
1304,
1673,
55,
3617,
6828,
602,
396,
12,
283,
44,
736,
874,
6828,
602,
396,
566,
2999,
199,
504,
2197,
492,
6871,
12,
1434,
202,
199,
646,
900,
2999,
199,
3,
2859,
921,
23153,
14,
957,
15,
16069,
15,
7357,
996,
1965,
15,
1661,
1958,
13,
8304,
13,
65,
13,
1842,
13,
1618,
13,
9356,
13,
262,
13,
1548,
202,
199,
318,
1434,
1842,
8,
928,
63,
602,
12,
1284,
63,
602,
304,
1128,
367,
302,
315,
1425,
8,
442,
3666,
500,
63,
602,
446,
1343,
63,
602,
680,
4899,
2298,
1039,
1995,
1343,
63,
602,
435,
6871,
8,
78,
9,
2999,
199,
12605,
6579,
275,
6454,
14,
9205,
3252,
1652,
3200,
13126,
1304,
356,
5969,
11506,
1552,
202,
199,
928,
63,
602,
275,
1434,
8,
10680,
12,
1616,
12,
5557,
9,
202,
199,
500,
63,
602,
275,
1434,
8,
12682,
12,
841,
12,
3144,
9,
202,
199,
509,
2849,
63,
602,
315,
1434,
1842,
8,
928,
63,
602,
12,
1284,
63,
602,
304,
1128,
1434,
63,
908,
275,
2849,
63,
602,
14,
6205,
3647,
57,
5,
77,
5,
68,
531,
1128,
10584,
780,
3314,
2506,
275,
5020,
14,
7935,
780,
8,
602,
29,
602,
63,
908,
12,
308,
719,
628,
78,
2470,
531,
1128,
8099,
55,
3617,
275,
942,
1128,
8099,
44,
736,
874,
275,
942,
1128,
367,
8099,
1304,
315,
8099,
11506,
26,
1039,
8099,
55,
3617,
14,
2880,
779,
18126,
14,
87,
265,
367,
10584,
316,
315,
10584,
780,
3314,
2506,
14,
18126,
340,
10584,
316,
14,
5969,
63,
344,
508,
8099,
1304,
566,
1039,
8099,
44,
736,
874,
14,
2880,
779,
18126,
14,
22031,
367,
10584,
316,
315,
10584,
780,
3314,
2506,
14,
18126,
340,
10584,
316,
14,
5969,
63,
344,
508,
8099,
1304,
566,
1128,
14718,
6579,
905,
55,
3617,
63,
7709,
602,
63,
908,
61,
275,
8099,
55,
3617,
1128,
14718,
6579,
905,
44,
736,
874,
63,
7709,
602,
63,
908,
61,
275,
8099,
44,
736,
874,
1128,
870,
8,
602,
63,
908,
9,
1128,
900,
14,
4532,
8,
713,
9,
327,
22,
4145,
282,
12709,
2999,
199,
12605,
6579,
14,
475,
63,
4737,
480,
78,
2470,
10680,
28905,
6579,
14,
4737,
401,
1478,
29,
797,
9,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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/contrib/test_attach_interfaces.py
|
33
|
20522
|
# Copyright 2012 SINA Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from oslo_config import cfg
from nova.api.openstack.compute.contrib import attach_interfaces \
as attach_interfaces_v2
from nova.api.openstack.compute.plugins.v3 import attach_interfaces \
as attach_interfaces_v21
from nova.compute import api as compute_api
from nova import exception
from nova.network import api as network_api
from nova import objects
from nova import test
from nova.tests.unit.api.openstack import fakes
from nova.tests.unit import fake_network_cache_model
from webob import exc
CONF = cfg.CONF
FAKE_UUID1 = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
FAKE_UUID2 = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'
FAKE_PORT_ID1 = '11111111-1111-1111-1111-111111111111'
FAKE_PORT_ID2 = '22222222-2222-2222-2222-222222222222'
FAKE_PORT_ID3 = '33333333-3333-3333-3333-333333333333'
FAKE_NOT_FOUND_PORT_ID = '00000000-0000-0000-0000-000000000000'
FAKE_NET_ID1 = '44444444-4444-4444-4444-444444444444'
FAKE_NET_ID2 = '55555555-5555-5555-5555-555555555555'
FAKE_NET_ID3 = '66666666-6666-6666-6666-666666666666'
FAKE_BAD_NET_ID = '00000000-0000-0000-0000-000000000000'
port_data1 = {
"id": FAKE_PORT_ID1,
"network_id": FAKE_NET_ID1,
"admin_state_up": True,
"status": "ACTIVE",
"mac_address": "aa:aa:aa:aa:aa:aa",
"fixed_ips": ["10.0.1.2"],
"device_id": FAKE_UUID1,
}
port_data2 = {
"id": FAKE_PORT_ID2,
"network_id": FAKE_NET_ID2,
"admin_state_up": True,
"status": "ACTIVE",
"mac_address": "bb:bb:bb:bb:bb:bb",
"fixed_ips": ["10.0.2.2"],
"device_id": FAKE_UUID1,
}
port_data3 = {
"id": FAKE_PORT_ID3,
"network_id": FAKE_NET_ID3,
"admin_state_up": True,
"status": "ACTIVE",
"mac_address": "bb:bb:bb:bb:bb:bb",
"fixed_ips": ["10.0.2.2"],
"device_id": '',
}
fake_networks = [FAKE_NET_ID1, FAKE_NET_ID2]
ports = [port_data1, port_data2, port_data3]
def fake_list_ports(self, *args, **kwargs):
result = []
for port in ports:
if port['device_id'] == kwargs['device_id']:
result.append(port)
return {'ports': result}
def fake_show_port(self, context, port_id, **kwargs):
for port in ports:
if port['id'] == port_id:
return {'port': port}
else:
raise exception.PortNotFound(port_id=port_id)
def fake_attach_interface(self, context, instance, network_id, port_id,
requested_ip='192.168.1.3'):
if not network_id:
# if no network_id is given when add a port to an instance, use the
# first default network.
network_id = fake_networks[0]
if network_id == FAKE_BAD_NET_ID:
raise exception.NetworkNotFound(network_id=network_id)
if not port_id:
port_id = ports[fake_networks.index(network_id)]['id']
if port_id == FAKE_NOT_FOUND_PORT_ID:
raise exception.PortNotFound(port_id=port_id)
vif = fake_network_cache_model.new_vif()
vif['id'] = port_id
vif['network']['id'] = network_id
vif['network']['subnets'][0]['ips'][0]['address'] = requested_ip
return vif
def fake_detach_interface(self, context, instance, port_id):
for port in ports:
if port['id'] == port_id:
return
raise exception.PortNotFound(port_id=port_id)
def fake_get_instance(self, *args, **kwargs):
return objects.Instance(uuid=FAKE_UUID1)
class InterfaceAttachTestsV21(test.NoDBTestCase):
controller_cls = attach_interfaces_v21.InterfaceAttachmentController
validate_exc = exception.ValidationError
in_use_exc = exc.HTTPConflict
not_found_exc = exc.HTTPNotFound
not_usable_exc = exc.HTTPBadRequest
def setUp(self):
super(InterfaceAttachTestsV21, self).setUp()
self.flags(auth_strategy=None, group='neutron')
self.flags(url='http://anyhost/', group='neutron')
self.flags(timeout=30, group='neutron')
self.stubs.Set(network_api.API, 'show_port', fake_show_port)
self.stubs.Set(network_api.API, 'list_ports', fake_list_ports)
self.stubs.Set(compute_api.API, 'get', fake_get_instance)
self.expected_show = {'interfaceAttachment':
{'net_id': FAKE_NET_ID1,
'port_id': FAKE_PORT_ID1,
'mac_addr': port_data1['mac_address'],
'port_state': port_data1['status'],
'fixed_ips': port_data1['fixed_ips'],
}}
self.attachments = self.controller_cls()
self.req = fakes.HTTPRequest.blank('')
@mock.patch.object(compute_api.API, 'get',
side_effect=exception.InstanceNotFound(instance_id=''))
def _test_instance_not_found(self, func, args, mock_get, kwargs=None):
if not kwargs:
kwargs = {}
self.assertRaises(exc.HTTPNotFound, func, self.req, *args, **kwargs)
def test_show_instance_not_found(self):
self._test_instance_not_found(self.attachments.show, ('fake', 'fake'))
def test_index_instance_not_found(self):
self._test_instance_not_found(self.attachments.index, ('fake', ))
def test_detach_interface_instance_not_found(self):
self._test_instance_not_found(self.attachments.delete,
('fake', 'fake'))
def test_attach_interface_instance_not_found(self):
self._test_instance_not_found(self.attachments.create, ('fake', ),
kwargs={'body': {'interfaceAttachment': {}}})
def test_show(self):
result = self.attachments.show(self.req, FAKE_UUID1, FAKE_PORT_ID1)
self.assertEqual(self.expected_show, result)
def test_show_with_port_not_found(self):
self.assertRaises(exc.HTTPNotFound,
self.attachments.show, self.req, FAKE_UUID2,
FAKE_PORT_ID1)
@mock.patch.object(network_api.API, 'show_port',
side_effect=exception.Forbidden)
def test_show_forbidden(self, show_port_mock):
self.assertRaises(exc.HTTPForbidden,
self.attachments.show, self.req, FAKE_UUID1,
FAKE_PORT_ID1)
def test_delete(self):
self.stubs.Set(compute_api.API, 'detach_interface',
fake_detach_interface)
result = self.attachments.delete(self.req, FAKE_UUID1, FAKE_PORT_ID1)
# NOTE: on v2.1, http status code is set as wsgi_code of API
# method instead of status_int in a response object.
if isinstance(self.attachments,
attach_interfaces_v21.InterfaceAttachmentController):
status_int = self.attachments.delete.wsgi_code
else:
status_int = result.status_int
self.assertEqual(202, status_int)
def test_detach_interface_instance_locked(self):
def fake_detach_interface_from_locked_server(self, context,
instance, port_id):
raise exception.InstanceIsLocked(instance_uuid=FAKE_UUID1)
self.stubs.Set(compute_api.API,
'detach_interface',
fake_detach_interface_from_locked_server)
self.assertRaises(exc.HTTPConflict,
self.attachments.delete,
self.req,
FAKE_UUID1,
FAKE_PORT_ID1)
def test_delete_interface_not_found(self):
self.stubs.Set(compute_api.API, 'detach_interface',
fake_detach_interface)
self.assertRaises(exc.HTTPNotFound,
self.attachments.delete,
self.req,
FAKE_UUID1,
'invaid-port-id')
def test_attach_interface_instance_locked(self):
def fake_attach_interface_to_locked_server(self, context,
instance, network_id, port_id, requested_ip):
raise exception.InstanceIsLocked(instance_uuid=FAKE_UUID1)
self.stubs.Set(compute_api.API,
'attach_interface',
fake_attach_interface_to_locked_server)
body = {}
self.assertRaises(exc.HTTPConflict,
self.attachments.create, self.req, FAKE_UUID1,
body=body)
def test_attach_interface_without_network_id(self):
self.stubs.Set(compute_api.API, 'attach_interface',
fake_attach_interface)
body = {}
result = self.attachments.create(self.req, FAKE_UUID1, body=body)
self.assertEqual(result['interfaceAttachment']['net_id'],
FAKE_NET_ID1)
def test_attach_interface_with_network_id(self):
self.stubs.Set(compute_api.API, 'attach_interface',
fake_attach_interface)
body = {'interfaceAttachment': {'net_id': FAKE_NET_ID2}}
result = self.attachments.create(self.req, FAKE_UUID1, body=body)
self.assertEqual(result['interfaceAttachment']['net_id'],
FAKE_NET_ID2)
def _attach_interface_bad_request_case(self, body):
self.stubs.Set(compute_api.API, 'attach_interface',
fake_attach_interface)
self.assertRaises(exc.HTTPBadRequest,
self.attachments.create, self.req, FAKE_UUID1,
body=body)
def _attach_interface_not_found_case(self, body):
self.stubs.Set(compute_api.API, 'attach_interface',
fake_attach_interface)
self.assertRaises(self.not_found_exc,
self.attachments.create, self.req, FAKE_UUID1,
body=body)
def test_attach_interface_with_port_and_network_id(self):
body = {
'interfaceAttachment': {
'port_id': FAKE_PORT_ID1,
'net_id': FAKE_NET_ID2
}
}
self._attach_interface_bad_request_case(body)
def test_attach_interface_with_not_found_network_id(self):
body = {
'interfaceAttachment': {
'net_id': FAKE_BAD_NET_ID
}
}
self._attach_interface_not_found_case(body)
def test_attach_interface_with_not_found_port_id(self):
body = {
'interfaceAttachment': {
'port_id': FAKE_NOT_FOUND_PORT_ID
}
}
self._attach_interface_not_found_case(body)
def test_attach_interface_with_invalid_state(self):
def fake_attach_interface_invalid_state(*args, **kwargs):
raise exception.InstanceInvalidState(
instance_uuid='', attr='', state='',
method='attach_interface')
self.stubs.Set(compute_api.API, 'attach_interface',
fake_attach_interface_invalid_state)
body = {'interfaceAttachment': {'net_id': FAKE_NET_ID1}}
self.assertRaises(exc.HTTPConflict,
self.attachments.create, self.req, FAKE_UUID1,
body=body)
@mock.patch.object(compute_api.API, 'attach_interface',
side_effect=NotImplementedError())
def test_attach_interface_with_not_implemented(self, _mock):
body = {'interfaceAttachment': {'net_id': FAKE_NET_ID1}}
self.assertRaises(exc.HTTPNotImplemented,
self.attachments.create, self.req, FAKE_UUID1,
body=body)
def test_detach_interface_with_invalid_state(self):
def fake_detach_interface_invalid_state(*args, **kwargs):
raise exception.InstanceInvalidState(
instance_uuid='', attr='', state='',
method='detach_interface')
self.stubs.Set(compute_api.API, 'detach_interface',
fake_detach_interface_invalid_state)
self.assertRaises(exc.HTTPConflict,
self.attachments.delete,
self.req,
FAKE_UUID1,
FAKE_NET_ID1)
@mock.patch.object(compute_api.API, 'detach_interface',
side_effect=NotImplementedError())
def test_detach_interface_with_not_implemented(self, _mock):
self.assertRaises(exc.HTTPNotImplemented,
self.attachments.delete,
self.req, FAKE_UUID1, FAKE_NET_ID1)
def test_attach_interface_invalid_fixed_ip(self):
body = {
'interfaceAttachment': {
'net_id': FAKE_NET_ID1,
'fixed_ips': [{'ip_address': 'invalid_ip'}]
}
}
self.assertRaises(self.validate_exc,
self.attachments.create, self.req, FAKE_UUID1,
body=body)
@mock.patch.object(compute_api.API, 'get')
@mock.patch.object(compute_api.API, 'attach_interface')
def test_attach_interface_fixed_ip_already_in_use(self,
attach_mock,
get_mock):
fake_instance = objects.Instance(uuid=FAKE_UUID1)
get_mock.return_value = fake_instance
attach_mock.side_effect = exception.FixedIpAlreadyInUse(
address='10.0.2.2', instance_uuid=FAKE_UUID1)
body = {}
self.assertRaises(self.in_use_exc,
self.attachments.create, self.req, FAKE_UUID1,
body=body)
ctxt = self.req.environ['nova.context']
attach_mock.assert_called_once_with(ctxt, fake_instance, None,
None, None)
get_mock.assert_called_once_with(ctxt, FAKE_UUID1,
want_objects=True,
expected_attrs=None)
@mock.patch.object(compute_api.API, 'get')
@mock.patch.object(compute_api.API, 'attach_interface')
def test_attach_interface_port_in_use(self,
attach_mock,
get_mock):
fake_instance = objects.Instance(uuid=FAKE_UUID1)
get_mock.return_value = fake_instance
attach_mock.side_effect = exception.PortInUse(
port_id=FAKE_PORT_ID1)
body = {}
self.assertRaises(self.in_use_exc,
self.attachments.create, self.req, FAKE_UUID1,
body=body)
ctxt = self.req.environ['nova.context']
attach_mock.assert_called_once_with(ctxt, fake_instance, None,
None, None)
get_mock.assert_called_once_with(ctxt, FAKE_UUID1,
want_objects=True,
expected_attrs=None)
@mock.patch.object(compute_api.API, 'get')
@mock.patch.object(compute_api.API, 'attach_interface')
def test_attach_interface_port_not_usable(self,
attach_mock,
get_mock):
fake_instance = objects.Instance(uuid=FAKE_UUID1)
get_mock.return_value = fake_instance
attach_mock.side_effect = exception.PortNotUsable(
port_id=FAKE_PORT_ID1,
instance=fake_instance.uuid)
body = {}
self.assertRaises(self.not_usable_exc,
self.attachments.create, self.req, FAKE_UUID1,
body=body)
ctxt = self.req.environ['nova.context']
attach_mock.assert_called_once_with(ctxt, fake_instance, None,
None, None)
get_mock.assert_called_once_with(ctxt, FAKE_UUID1,
want_objects=True,
expected_attrs=None)
@mock.patch.object(compute_api.API, 'get')
@mock.patch.object(compute_api.API, 'attach_interface')
def test_attach_interface_no_more_fixed_ips(self,
attach_mock,
get_mock):
fake_instance = objects.Instance(uuid=FAKE_UUID1)
get_mock.return_value = fake_instance
attach_mock.side_effect = exception.NoMoreFixedIps(
net=FAKE_NET_ID1)
body = {}
self.assertRaises(exc.HTTPBadRequest,
self.attachments.create, self.req, FAKE_UUID1,
body=body)
ctxt = self.req.environ['nova.context']
attach_mock.assert_called_once_with(ctxt, fake_instance, None,
None, None)
get_mock.assert_called_once_with(ctxt, FAKE_UUID1,
want_objects=True,
expected_attrs=None)
def _test_attach_interface_with_invalid_parameter(self, param):
self.stubs.Set(compute_api.API, 'attach_interface',
fake_attach_interface)
body = {'interface_attachment': param}
self.assertRaises(exception.ValidationError,
self.attachments.create, self.req, FAKE_UUID1,
body=body)
def test_attach_interface_instance_with_non_uuid_net_id(self):
param = {'net_id': 'non_uuid'}
self._test_attach_interface_with_invalid_parameter(param)
def test_attach_interface_instance_with_non_uuid_port_id(self):
param = {'port_id': 'non_uuid'}
self._test_attach_interface_with_invalid_parameter(param)
def test_attach_interface_instance_with_non_array_fixed_ips(self):
param = {'fixed_ips': 'non_array'}
self._test_attach_interface_with_invalid_parameter(param)
class InterfaceAttachTestsV2(InterfaceAttachTestsV21):
controller_cls = attach_interfaces_v2.InterfaceAttachmentController
validate_exc = exc.HTTPBadRequest
in_use_exc = exc.HTTPBadRequest
def test_attach_interface_instance_with_non_uuid_net_id(self):
pass
def test_attach_interface_instance_with_non_uuid_port_id(self):
pass
def test_attach_interface_instance_with_non_array_fixed_ips(self):
pass
class AttachInterfacesPolicyEnforcementv21(test.NoDBTestCase):
def setUp(self):
super(AttachInterfacesPolicyEnforcementv21, self).setUp()
self.controller = \
attach_interfaces_v21.InterfaceAttachmentController()
self.req = fakes.HTTPRequest.blank('')
self.rule_name = "os_compute_api:os-attach-interfaces"
self.policy.set_rules({self.rule_name: "project:non_fake"})
def test_index_attach_interfaces_policy_failed(self):
exc = self.assertRaises(
exception.PolicyNotAuthorized,
self.controller.index, self.req, fakes.FAKE_UUID)
self.assertEqual(
"Policy doesn't allow %s to be performed." % self.rule_name,
exc.format_message())
def test_show_attach_interfaces_policy_failed(self):
exc = self.assertRaises(
exception.PolicyNotAuthorized,
self.controller.show, self.req, fakes.FAKE_UUID, FAKE_PORT_ID1)
self.assertEqual(
"Policy doesn't allow %s to be performed." % self.rule_name,
exc.format_message())
def test_create_attach_interfaces_policy_failed(self):
exc = self.assertRaises(
exception.PolicyNotAuthorized,
self.controller.create, self.req, fakes.FAKE_UUID, body={})
self.assertEqual(
"Policy doesn't allow %s to be performed." % self.rule_name,
exc.format_message())
def test_delete_attach_interfaces_policy_failed(self):
exc = self.assertRaises(
exception.PolicyNotAuthorized,
self.controller.delete, self.req, fakes.FAKE_UUID, FAKE_PORT_ID1)
self.assertEqual(
"Policy doesn't allow %s to be performed." % self.rule_name,
exc.format_message())
|
apache-2.0
|
[
3,
1898,
6029,
428,
568,
33,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
2828,
492,
6554,
63,
7436,
971,
272,
465,
6554,
63,
7436,
63,
86,
18,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
5265,
14,
86,
19,
492,
6554,
63,
7436,
971,
272,
465,
6554,
63,
7436,
63,
86,
2025,
199,
504,
5913,
14,
3357,
492,
2986,
465,
4526,
63,
1246,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
1200,
492,
2986,
465,
2784,
63,
1246,
199,
504,
5913,
492,
2251,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
14,
3248,
14,
1246,
14,
8512,
492,
14063,
199,
504,
5913,
14,
2219,
14,
3248,
492,
4026,
63,
1200,
63,
1637,
63,
1238,
199,
199,
504,
14568,
492,
3178,
421,
199,
3103,
275,
4810,
14,
3103,
199,
199,
14623,
63,
8757,
17,
275,
283,
10980,
13,
6000,
13,
6000,
13,
6000,
13,
10980,
6000,
7,
199,
14623,
63,
8757,
18,
275,
283,
31703,
13,
14923,
13,
14923,
13,
14923,
13,
31703,
14923,
7,
199,
199,
14623,
63,
3657,
63,
998,
17,
275,
283,
14757,
13,
6984,
13,
6984,
13,
6984,
13,
14757,
6984,
7,
199,
14623,
63,
3657,
63,
998,
18,
275,
283,
21109,
13,
9993,
13,
9993,
13,
9993,
13,
21109,
9993,
7,
199,
14623,
63,
3657,
63,
998,
19,
275,
283,
15093,
13,
6772,
13,
6772,
13,
6772,
13,
15093,
6772,
7,
199,
14623,
63,
4609,
63,
13945,
63,
3657,
63,
998,
275,
283,
3607,
13,
993,
13,
993,
13,
993,
13,
15672,
7,
199,
199,
14623,
63,
7278,
63,
998,
17,
275,
283,
22872,
22872,
13,
22872,
13,
22872,
13,
22872,
13,
22872,
22872,
22872,
7,
199,
14623,
63,
7278,
63,
998,
18,
275,
283,
19161,
19161,
13,
19161,
13,
19161,
13,
19161,
13,
19161,
19161,
19161,
7,
199,
14623,
63,
7278,
63,
998,
19,
275,
283,
14936,
13,
6997,
13,
6997,
13,
6997,
13,
24741,
7,
199,
14623,
63,
9439,
63,
7278,
63,
998,
275,
283,
3607,
13,
993,
13,
993,
13,
993,
13,
15672,
7,
199,
199,
719,
63,
576,
17,
275,
469,
272,
298,
344,
582,
25699,
63,
3657,
63,
998,
17,
12,
272,
298,
1200,
63,
344,
582,
25699,
63,
7278,
63,
998,
17,
12,
272,
298,
2113,
63,
929,
63,
384,
582,
715,
12,
272,
298,
1205,
582,
298,
10401,
401,
272,
298,
3088,
63,
1562,
582,
298,
2158,
26,
2158,
26,
2158,
26,
2158,
26,
2158,
26,
2158,
401,
272,
298,
5964,
63,
6142,
582,
2097,
709,
14,
16,
14,
17,
14,
18,
2255,
272,
298,
1782,
63,
344,
582,
25699,
63,
8757,
17,
12,
199,
93,
199,
199,
719,
63,
576,
18,
275,
469,
272,
298,
344,
582,
25699,
63,
3657,
63,
998,
18,
12,
272,
298,
1200,
63,
344,
582,
25699,
63,
7278,
63,
998,
18,
12,
272,
298,
2113,
63,
929,
63,
384,
582,
715,
12,
272,
298,
1205,
582,
298,
10401,
401,
272,
298,
3088,
63,
1562,
582,
298,
2501,
26,
2501,
26,
2501,
26,
2501,
26,
2501,
26,
2501,
401,
272,
298,
5964,
63,
6142,
582,
2097,
709,
14,
16,
14,
18,
14,
18,
2255,
272,
298,
1782,
63,
344,
582,
25699,
63,
8757,
17,
12,
199,
93,
199,
199,
719,
63,
576,
19,
275,
469,
272,
298,
344,
582,
25699,
63,
3657,
63,
998,
19,
12,
272,
298,
1200,
63,
344,
582,
25699,
63,
7278,
63,
998,
19,
12,
272,
298,
2113,
63,
929,
63,
384,
582,
715,
12,
272,
298,
1205,
582,
298,
10401,
401,
272,
298,
3088,
63,
1562,
582,
298,
2501,
26,
2501,
26,
2501,
26,
2501,
26,
2501,
26,
2501,
401,
272,
298,
5964,
63,
6142,
582,
2097,
709,
14,
16,
14,
18,
14,
18,
2255,
272,
298,
1782,
63,
344,
582,
3260,
199,
93,
199,
199,
3183,
63,
7642,
275,
359,
14623,
63,
7278,
63,
998,
17,
12,
25699,
63,
7278,
63,
998,
18,
61,
199,
5203,
275,
359,
719,
63,
576,
17,
12,
1844,
63,
576,
18,
12,
1844,
63,
576,
19,
61,
421,
199,
318,
4026,
63,
513,
63,
5203,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
754,
275,
942,
272,
367,
1844,
315,
8873,
26,
267,
340,
1844,
459,
1782,
63,
344,
418,
508,
2074,
459,
1782,
63,
344,
2565,
288,
754,
14,
740,
8,
719,
9,
272,
372,
791,
5203,
356,
754,
93,
421,
199,
318,
4026,
63,
2384,
63,
719,
8,
277,
12,
1067,
12,
1844,
63,
344,
12,
1011,
958,
304,
272,
367,
1844,
315,
8873,
26,
267,
340,
1844,
459,
344,
418,
508,
1844,
63,
344,
26,
288,
372,
791,
719,
356,
1844,
93,
272,
587,
26,
267,
746,
1919,
14,
4313,
4667,
8,
719,
63,
344,
29,
719,
63,
344,
9,
421,
199,
318,
4026,
63,
5040,
63,
3266,
8,
277,
12,
1067,
12,
1256,
12,
2784,
63,
344,
12,
1844,
63,
344,
12,
2079,
5839,
63,
711,
534,
5756,
14,
6568,
14,
17,
14,
19,
735,
272,
340,
440,
2784,
63,
344,
26,
267,
327,
340,
949,
2784,
63,
344,
365,
1627,
1380,
1050,
282,
1844,
370,
376,
1256,
12,
675,
314,
267,
327,
1642,
849,
2784,
14,
267,
2784,
63,
344,
275,
4026,
63,
7642,
59,
16,
61,
272,
340,
2784,
63,
344
] |
[
1898,
6029,
428,
568,
33,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
504,
11258,
63,
888,
492,
4810,
199,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
2828,
492,
6554,
63,
7436,
971,
272,
465,
6554,
63,
7436,
63,
86,
18,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
5265,
14,
86,
19,
492,
6554,
63,
7436,
971,
272,
465,
6554,
63,
7436,
63,
86,
2025,
199,
504,
5913,
14,
3357,
492,
2986,
465,
4526,
63,
1246,
199,
504,
5913,
492,
1919,
199,
504,
5913,
14,
1200,
492,
2986,
465,
2784,
63,
1246,
199,
504,
5913,
492,
2251,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
14,
3248,
14,
1246,
14,
8512,
492,
14063,
199,
504,
5913,
14,
2219,
14,
3248,
492,
4026,
63,
1200,
63,
1637,
63,
1238,
199,
199,
504,
14568,
492,
3178,
421,
199,
3103,
275,
4810,
14,
3103,
199,
199,
14623,
63,
8757,
17,
275,
283,
10980,
13,
6000,
13,
6000,
13,
6000,
13,
10980,
6000,
7,
199,
14623,
63,
8757,
18,
275,
283,
31703,
13,
14923,
13,
14923,
13,
14923,
13,
31703,
14923,
7,
199,
199,
14623,
63,
3657,
63,
998,
17,
275,
283,
14757,
13,
6984,
13,
6984,
13,
6984,
13,
14757,
6984,
7,
199,
14623,
63,
3657,
63,
998,
18,
275,
283,
21109,
13,
9993,
13,
9993,
13,
9993,
13,
21109,
9993,
7,
199,
14623,
63,
3657,
63,
998,
19,
275,
283,
15093,
13,
6772,
13,
6772,
13,
6772,
13,
15093,
6772,
7,
199,
14623,
63,
4609,
63,
13945,
63,
3657,
63,
998,
275,
283,
3607,
13,
993,
13,
993,
13,
993,
13,
15672,
7,
199,
199,
14623,
63,
7278,
63,
998,
17,
275,
283,
22872,
22872,
13,
22872,
13,
22872,
13,
22872,
13,
22872,
22872,
22872,
7,
199,
14623,
63,
7278,
63,
998,
18,
275,
283,
19161,
19161,
13,
19161,
13,
19161,
13,
19161,
13,
19161,
19161,
19161,
7,
199,
14623,
63,
7278,
63,
998,
19,
275,
283,
14936,
13,
6997,
13,
6997,
13,
6997,
13,
24741,
7,
199,
14623,
63,
9439,
63,
7278,
63,
998,
275,
283,
3607,
13,
993,
13,
993,
13,
993,
13,
15672,
7,
199,
199,
719,
63,
576,
17,
275,
469,
272,
298,
344,
582,
25699,
63,
3657,
63,
998,
17,
12,
272,
298,
1200,
63,
344,
582,
25699,
63,
7278,
63,
998,
17,
12,
272,
298,
2113,
63,
929,
63,
384,
582,
715,
12,
272,
298,
1205,
582,
298,
10401,
401,
272,
298,
3088,
63,
1562,
582,
298,
2158,
26,
2158,
26,
2158,
26,
2158,
26,
2158,
26,
2158,
401,
272,
298,
5964,
63,
6142,
582,
2097,
709,
14,
16,
14,
17,
14,
18,
2255,
272,
298,
1782,
63,
344,
582,
25699,
63,
8757,
17,
12,
199,
93,
199,
199,
719,
63,
576,
18,
275,
469,
272,
298,
344,
582,
25699,
63,
3657,
63,
998,
18,
12,
272,
298,
1200,
63,
344,
582,
25699,
63,
7278,
63,
998,
18,
12,
272,
298,
2113,
63,
929,
63,
384,
582,
715,
12,
272,
298,
1205,
582,
298,
10401,
401,
272,
298,
3088,
63,
1562,
582,
298,
2501,
26,
2501,
26,
2501,
26,
2501,
26,
2501,
26,
2501,
401,
272,
298,
5964,
63,
6142,
582,
2097,
709,
14,
16,
14,
18,
14,
18,
2255,
272,
298,
1782,
63,
344,
582,
25699,
63,
8757,
17,
12,
199,
93,
199,
199,
719,
63,
576,
19,
275,
469,
272,
298,
344,
582,
25699,
63,
3657,
63,
998,
19,
12,
272,
298,
1200,
63,
344,
582,
25699,
63,
7278,
63,
998,
19,
12,
272,
298,
2113,
63,
929,
63,
384,
582,
715,
12,
272,
298,
1205,
582,
298,
10401,
401,
272,
298,
3088,
63,
1562,
582,
298,
2501,
26,
2501,
26,
2501,
26,
2501,
26,
2501,
26,
2501,
401,
272,
298,
5964,
63,
6142,
582,
2097,
709,
14,
16,
14,
18,
14,
18,
2255,
272,
298,
1782,
63,
344,
582,
3260,
199,
93,
199,
199,
3183,
63,
7642,
275,
359,
14623,
63,
7278,
63,
998,
17,
12,
25699,
63,
7278,
63,
998,
18,
61,
199,
5203,
275,
359,
719,
63,
576,
17,
12,
1844,
63,
576,
18,
12,
1844,
63,
576,
19,
61,
421,
199,
318,
4026,
63,
513,
63,
5203,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
272,
754,
275,
942,
272,
367,
1844,
315,
8873,
26,
267,
340,
1844,
459,
1782,
63,
344,
418,
508,
2074,
459,
1782,
63,
344,
2565,
288,
754,
14,
740,
8,
719,
9,
272,
372,
791,
5203,
356,
754,
93,
421,
199,
318,
4026,
63,
2384,
63,
719,
8,
277,
12,
1067,
12,
1844,
63,
344,
12,
1011,
958,
304,
272,
367,
1844,
315,
8873,
26,
267,
340,
1844,
459,
344,
418,
508,
1844,
63,
344,
26,
288,
372,
791,
719,
356,
1844,
93,
272,
587,
26,
267,
746,
1919,
14,
4313,
4667,
8,
719,
63,
344,
29,
719,
63,
344,
9,
421,
199,
318,
4026,
63,
5040,
63,
3266,
8,
277,
12,
1067,
12,
1256,
12,
2784,
63,
344,
12,
1844,
63,
344,
12,
2079,
5839,
63,
711,
534,
5756,
14,
6568,
14,
17,
14,
19,
735,
272,
340,
440,
2784,
63,
344,
26,
267,
327,
340,
949,
2784,
63,
344,
365,
1627,
1380,
1050,
282,
1844,
370,
376,
1256,
12,
675,
314,
267,
327,
1642,
849,
2784,
14,
267,
2784,
63,
344,
275,
4026,
63,
7642,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
dhananjay92/servo
|
tests/wpt/harness/wptrunner/hosts.py
|
196
|
3292
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import unicode_literals
class HostsLine(object):
def __init__(self, ip_address, canonical_hostname, aliases=None, comment=None):
self.ip_address = ip_address
self.canonical_hostname = canonical_hostname
self.aliases = aliases if aliases is not None else []
self.comment = comment
if self.ip_address is None:
assert self.canonical_hostname is None
assert not self.aliases
assert self.comment is not None
@classmethod
def from_string(cls, line):
if not line.strip():
return
line = line.strip()
ip_address = None
canonical_hostname = None
aliases = []
comment = None
comment_parts = line.split("#", 1)
if len(comment_parts) > 1:
comment = comment_parts[1]
data = comment_parts[0].strip()
if data:
fields = data.split()
if len(fields) < 2:
raise ValueError("Invalid hosts line")
ip_address = fields[0]
canonical_hostname = fields[1]
aliases = fields[2:]
return cls(ip_address, canonical_hostname, aliases, comment)
class HostsFile(object):
def __init__(self):
self.data = []
self.by_hostname = {}
def set_host(self, host):
if host.canonical_hostname is None:
self.data.append(host)
elif host.canonical_hostname in self.by_hostname:
old_host = self.by_hostname[host.canonical_hostname]
old_host.ip_address = host.ip_address
old_host.aliases = host.aliases
old_host.comment = host.comment
else:
self.data.append(host)
self.by_hostname[host.canonical_hostname] = host
@classmethod
def from_file(cls, f):
rv = cls()
for line in f:
host = HostsLine.from_string(line)
if host is not None:
rv.set_host(host)
return rv
def to_string(self):
field_widths = [0, 0]
for line in self.data:
if line.ip_address is not None:
field_widths[0] = max(field_widths[0], len(line.ip_address))
field_widths[1] = max(field_widths[1], len(line.canonical_hostname))
lines = []
for host in self.data:
line = ""
if host.ip_address is not None:
ip_string = host.ip_address.ljust(field_widths[0])
hostname_str = host.canonical_hostname
if host.aliases:
hostname_str = "%s %s" % (hostname_str.ljust(field_widths[1]),
" ".join(host.aliases))
line = "%s %s" % (ip_string, hostname_str)
if host.comment:
if line:
line += " "
line += "#%s" % host.comment
lines.append(line)
lines.append("")
return "\n".join(lines)
def to_file(self, f):
f.write(self.to_string().encode("utf8"))
|
mpl-2.0
|
[
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
421,
199,
533,
10891,
83,
3049,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
3384,
63,
1562,
12,
11358,
63,
4269,
12,
5481,
29,
403,
12,
3721,
29,
403,
304,
267,
291,
14,
711,
63,
1562,
275,
3384,
63,
1562,
267,
291,
14,
13109,
63,
4269,
275,
11358,
63,
4269,
267,
291,
14,
8602,
275,
5481,
340,
5481,
365,
440,
488,
587,
942,
267,
291,
14,
3349,
275,
3721,
267,
340,
291,
14,
711,
63,
1562,
365,
488,
26,
288,
702,
291,
14,
13109,
63,
4269,
365,
488,
288,
702,
440,
291,
14,
8602,
288,
702,
291,
14,
3349,
365,
440,
488,
339,
768,
3744,
272,
347,
687,
63,
875,
8,
1886,
12,
1004,
304,
267,
340,
440,
1004,
14,
1913,
837,
288,
372,
398,
1004,
275,
1004,
14,
1913,
342,
398,
3384,
63,
1562,
275,
488,
267,
11358,
63,
4269,
275,
488,
267,
5481,
275,
942,
267,
3721,
275,
488,
398,
3721,
63,
4181,
275,
1004,
14,
1294,
10064,
401,
413,
9,
267,
340,
822,
8,
3349,
63,
4181,
9,
690,
413,
26,
288,
3721,
275,
3721,
63,
4181,
59,
17,
61,
398,
666,
275,
3721,
63,
4181,
59,
16,
1055,
1913,
342,
398,
340,
666,
26,
288,
1504,
275,
666,
14,
1294,
342,
288,
340,
822,
8,
955,
9,
665,
499,
26,
355,
746,
1722,
480,
3364,
7057,
1004,
531,
953,
3384,
63,
1562,
275,
1504,
59,
16,
61,
288,
11358,
63,
4269,
275,
1504,
59,
17,
61,
288,
5481,
275,
1504,
59,
18,
2938,
398,
372,
843,
8,
711,
63,
1562,
12,
11358,
63,
4269,
12,
5481,
12,
3721,
9,
421,
199,
533,
10891,
83,
1173,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
576,
275,
942,
267,
291,
14,
991,
63,
4269,
275,
1052,
339,
347,
663,
63,
1102,
8,
277,
12,
1591,
304,
267,
340,
1591,
14,
13109,
63,
4269,
365,
488,
26,
288,
291,
14,
576,
14,
740,
8,
1102,
9,
267,
916,
1591,
14,
13109,
63,
4269,
315,
291,
14,
991,
63,
4269,
26,
288,
2269,
63,
1102,
275,
291,
14,
991,
63,
4269,
59,
1102,
14,
13109,
63,
4269,
61,
288,
2269,
63,
1102,
14,
711,
63,
1562,
275,
1591,
14,
711,
63,
1562,
288,
2269,
63,
1102,
14,
8602,
275,
1591,
14,
8602,
288,
2269,
63,
1102,
14,
3349,
275,
1591,
14,
3349,
267,
587,
26,
288,
291,
14,
576,
14,
740,
8,
1102,
9,
288,
291,
14,
991,
63,
4269,
59,
1102,
14,
13109,
63,
4269,
61,
275,
1591,
339,
768,
3744,
272,
347,
687,
63,
493,
8,
1886,
12,
289,
304,
267,
4336,
275,
843,
342,
267,
367,
1004,
315,
289,
26,
288,
1591,
275,
10891,
83,
3049,
14,
504,
63,
875,
8,
604,
9,
288,
340,
1591,
365,
440,
488,
26,
355,
4336,
14,
409,
63,
1102,
8,
1102,
9,
267,
372,
4336,
339,
347,
370,
63,
875,
8,
277,
304,
267,
901,
63,
22209,
275,
359,
16,
12,
378,
61,
267,
367,
1004,
315,
291,
14,
576,
26,
288,
340,
1004,
14,
711,
63,
1562,
365,
440,
488,
26,
355,
901,
63,
22209,
59,
16,
61,
275,
1390,
8,
698,
63,
22209,
59,
16,
467,
822,
8,
604,
14,
711,
63,
1562,
430,
355,
901,
63,
22209,
59,
17,
61,
275,
1390,
8,
698,
63,
22209,
59,
17,
467,
822,
8,
604,
14,
13109,
63,
4269,
430,
398,
2385,
275,
942,
398,
367,
1591,
315,
291,
14,
576,
26,
288,
1004,
275,
3087,
288,
340,
1591,
14,
711,
63,
1562,
365,
440,
488,
26,
355,
3384,
63,
875,
275,
1591,
14,
711,
63,
1562,
14,
19996,
8,
698,
63,
22209,
59,
16,
566,
355,
6246,
63,
495,
275,
1591,
14,
13109,
63,
4269,
355,
340,
1591,
14,
8602,
26,
490,
6246,
63,
495,
275,
2071,
83,
450,
83,
2,
450,
334,
4269,
63,
495,
14,
19996,
8,
698,
63,
22209,
59,
17,
2522,
6343,
298,
3680,
904,
8,
1102,
14,
8602,
430,
355,
1004,
275,
2071,
83,
450,
83,
2,
450,
334,
711,
63,
875,
12,
6246,
63,
495,
9,
288,
340,
1591,
14,
3349,
26,
355,
340,
1004,
26,
490,
1004,
847,
298,
298,
355,
1004,
847,
5426,
5,
83,
2,
450,
1591,
14,
3349,
288,
2385,
14,
740,
8,
604,
9,
398,
2385,
14,
740,
10804,
398,
372,
1867,
78,
1674,
904,
8,
1278,
9,
339,
347,
370,
63,
493,
8,
277,
12,
289,
304,
267,
289,
14,
952,
8,
277,
14,
475,
63,
875,
1252,
2143,
480,
1624,
24,
2237,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
421,
199,
533,
10891,
83,
3049,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
3384,
63,
1562,
12,
11358,
63,
4269,
12,
5481,
29,
403,
12,
3721,
29,
403,
304,
267,
291,
14,
711,
63,
1562,
275,
3384,
63,
1562,
267,
291,
14,
13109,
63,
4269,
275,
11358,
63,
4269,
267,
291,
14,
8602,
275,
5481,
340,
5481,
365,
440,
488,
587,
942,
267,
291,
14,
3349,
275,
3721,
267,
340,
291,
14,
711,
63,
1562,
365,
488,
26,
288,
702,
291,
14,
13109,
63,
4269,
365,
488,
288,
702,
440,
291,
14,
8602,
288,
702,
291,
14,
3349,
365,
440,
488,
339,
768,
3744,
272,
347,
687,
63,
875,
8,
1886,
12,
1004,
304,
267,
340,
440,
1004,
14,
1913,
837,
288,
372,
398,
1004,
275,
1004,
14,
1913,
342,
398,
3384,
63,
1562,
275,
488,
267,
11358,
63,
4269,
275,
488,
267,
5481,
275,
942,
267,
3721,
275,
488,
398,
3721,
63,
4181,
275,
1004,
14,
1294,
10064,
401,
413,
9,
267,
340,
822,
8,
3349,
63,
4181,
9,
690,
413,
26,
288,
3721,
275,
3721,
63,
4181,
59,
17,
61,
398,
666,
275,
3721,
63,
4181,
59,
16,
1055,
1913,
342,
398,
340,
666,
26,
288,
1504,
275,
666,
14,
1294,
342,
288,
340,
822,
8,
955,
9,
665,
499,
26,
355,
746,
1722,
480,
3364,
7057,
1004,
531,
953,
3384,
63,
1562,
275,
1504,
59,
16,
61,
288,
11358,
63,
4269,
275,
1504,
59,
17,
61,
288,
5481,
275,
1504,
59,
18,
2938,
398,
372,
843,
8,
711,
63,
1562,
12,
11358,
63,
4269,
12,
5481,
12,
3721,
9,
421,
199,
533,
10891,
83,
1173,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
576,
275,
942,
267,
291,
14,
991,
63,
4269,
275,
1052,
339,
347,
663,
63,
1102,
8,
277,
12,
1591,
304,
267,
340,
1591,
14,
13109,
63,
4269,
365,
488,
26,
288,
291,
14,
576,
14,
740,
8,
1102,
9,
267,
916,
1591,
14,
13109,
63,
4269,
315,
291,
14,
991,
63,
4269,
26,
288,
2269,
63,
1102,
275,
291,
14,
991,
63,
4269,
59,
1102,
14,
13109,
63,
4269,
61,
288,
2269,
63,
1102,
14,
711,
63,
1562,
275,
1591,
14,
711,
63,
1562,
288,
2269,
63,
1102,
14,
8602,
275,
1591,
14,
8602,
288,
2269,
63,
1102,
14,
3349,
275,
1591,
14,
3349,
267,
587,
26,
288,
291,
14,
576,
14,
740,
8,
1102,
9,
288,
291,
14,
991,
63,
4269,
59,
1102,
14,
13109,
63,
4269,
61,
275,
1591,
339,
768,
3744,
272,
347,
687,
63,
493,
8,
1886,
12,
289,
304,
267,
4336,
275,
843,
342,
267,
367,
1004,
315,
289,
26,
288,
1591,
275,
10891,
83,
3049,
14,
504,
63,
875,
8,
604,
9,
288,
340,
1591,
365,
440,
488,
26,
355,
4336,
14,
409,
63,
1102,
8,
1102,
9,
267,
372,
4336,
339,
347,
370,
63,
875,
8,
277,
304,
267,
901,
63,
22209,
275,
359,
16,
12,
378,
61,
267,
367,
1004,
315,
291,
14,
576,
26,
288,
340,
1004,
14,
711,
63,
1562,
365,
440,
488,
26,
355,
901,
63,
22209,
59,
16,
61,
275,
1390,
8,
698,
63,
22209,
59,
16,
467,
822,
8,
604,
14,
711,
63,
1562,
430,
355,
901,
63,
22209,
59,
17,
61,
275,
1390,
8,
698,
63,
22209,
59,
17,
467,
822,
8,
604,
14,
13109,
63,
4269,
430,
398,
2385,
275,
942,
398,
367,
1591,
315,
291,
14,
576,
26,
288,
1004,
275,
3087,
288,
340,
1591,
14,
711,
63,
1562,
365,
440,
488,
26,
355,
3384,
63,
875,
275,
1591,
14,
711,
63,
1562,
14,
19996,
8,
698,
63,
22209,
59,
16,
566,
355,
6246,
63,
495,
275,
1591,
14,
13109,
63,
4269,
355,
340,
1591,
14,
8602,
26,
490,
6246,
63,
495,
275,
2071,
83,
450,
83,
2,
450,
334,
4269,
63,
495,
14,
19996,
8,
698,
63,
22209,
59,
17,
2522,
6343,
298,
3680,
904,
8,
1102,
14,
8602,
430,
355,
1004,
275,
2071,
83,
450,
83,
2,
450,
334,
711,
63,
875,
12,
6246,
63,
495,
9,
288,
340,
1591,
14,
3349,
26,
355,
340,
1004,
26,
490,
1004,
847,
298,
298,
355,
1004,
847,
5426,
5,
83,
2,
450,
1591,
14,
3349,
288,
2385,
14,
740,
8,
604,
9,
398,
2385,
14,
740,
10804,
398,
372,
1867,
78,
1674,
904,
8,
1278,
9,
339,
347,
370,
63,
493,
8,
277,
12,
289,
304,
267,
289,
14,
952,
8,
277,
14,
475,
63,
875,
1252,
2143,
480,
1624,
24,
2237,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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 -*-
"""
werkzeug.wrappers
~~~~~~~~~~~~~~~~~
The wrappers are simple request and response objects which you can
subclass to do whatever you want them to do. The request object contains
the information transmitted by the client (webbrowser) and the response
object contains all the information sent back to the browser.
An important detail is that the request object is created with the WSGI
environ and will act as high-level proxy whereas the response object is an
actual WSGI application.
Like everything else in Werkzeug these objects will work correctly with
unicode data. Incoming form data parsed by the response object will be
decoded into an unicode object if possible and if it makes sense.
:copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""
from functools import update_wrapper
from datetime import datetime, timedelta
from werkzeug.http import HTTP_STATUS_CODES, \
parse_accept_header, parse_cache_control_header, parse_etags, \
parse_date, generate_etag, is_resource_modified, unquote_etag, \
quote_etag, parse_set_header, parse_authorization_header, \
parse_www_authenticate_header, remove_entity_headers, \
parse_options_header, dump_options_header, http_date, \
parse_if_range_header, parse_cookie, dump_cookie, \
parse_range_header, parse_content_range_header, dump_header
from werkzeug.urls import url_decode, iri_to_uri, url_join
from werkzeug.formparser import FormDataParser, default_stream_factory
from werkzeug.utils import cached_property, environ_property, \
header_property, get_content_type
from werkzeug.wsgi import get_current_url, get_host, \
ClosingIterator, get_input_stream, get_content_length
from werkzeug.datastructures import MultiDict, CombinedMultiDict, Headers, \
EnvironHeaders, ImmutableMultiDict, ImmutableTypeConversionDict, \
ImmutableList, MIMEAccept, CharsetAccept, LanguageAccept, \
ResponseCacheControl, RequestCacheControl, CallbackDict, \
ContentRange, iter_multi_items
from werkzeug._internal import _get_environ
from werkzeug._compat import to_bytes, string_types, text_type, \
integer_types, wsgi_decoding_dance, wsgi_get_bytes, \
to_unicode, to_native, BytesIO
def _run_wsgi_app(*args):
"""This function replaces itself to ensure that the test module is not
imported unless required. DO NOT USE!
"""
global _run_wsgi_app
from werkzeug.test import run_wsgi_app as _run_wsgi_app
return _run_wsgi_app(*args)
def _warn_if_string(iterable):
"""Helper for the response objects to check if the iterable returned
to the WSGI server is not a string.
"""
if isinstance(iterable, string_types):
from warnings import warn
warn(Warning('response iterable was set to a string. This appears '
'to work but means that the server will send the '
'data to the client char, by char. This is almost '
'never intended behavior, use response.data to assign '
'strings to the response object.'), stacklevel=2)
def _assert_not_shallow(request):
if request.shallow:
raise RuntimeError('A shallow request tried to consume '
'form data. If you really want to do '
'that, set `shallow` to False.')
def _iter_encoded(iterable, charset):
for item in iterable:
if isinstance(item, text_type):
yield item.encode(charset)
else:
yield item
class BaseRequest(object):
"""Very basic request object. This does not implement advanced stuff like
entity tag parsing or cache controls. The request object is created with
the WSGI environment as first argument and will add itself to the WSGI
environment as ``'werkzeug.request'`` unless it's created with
`populate_request` set to False.
There are a couple of mixins available that add additional functionality
to the request object, there is also a class called `Request` which
subclasses `BaseRequest` and all the important mixins.
It's a good idea to create a custom subclass of the :class:`BaseRequest`
and add missing functionality either via mixins or direct implementation.
Here an example for such subclasses::
from werkzeug.wrappers import BaseRequest, ETagRequestMixin
class Request(BaseRequest, ETagRequestMixin):
pass
Request objects are **read only**. As of 0.5 modifications are not
allowed in any place. Unlike the lower level parsing functions the
request object will use immutable objects everywhere possible.
Per default the request object will assume all the text data is `utf-8`
encoded. Please refer to `the unicode chapter <unicode.txt>`_ for more
details about customizing the behavior.
Per default the request object will be added to the WSGI
environment as `werkzeug.request` to support the debugging system.
If you don't want that, set `populate_request` to `False`.
If `shallow` is `True` the environment is initialized as shallow
object around the environ. Every operation that would modify the
environ in any way (such as consuming form data) raises an exception
unless the `shallow` attribute is explicitly set to `False`. This
is useful for middlewares where you don't want to consume the form
data by accident. A shallow request is not populated to the WSGI
environment.
.. versionchanged:: 0.5
read-only mode was enforced by using immutables classes for all
data.
"""
#: the charset for the request, defaults to utf-8
charset = 'utf-8'
#: the error handling procedure for errors, defaults to 'replace'
encoding_errors = 'replace'
#: the maximum content length. This is forwarded to the form data
#: parsing function (:func:`parse_form_data`). When set and the
#: :attr:`form` or :attr:`files` attribute is accessed and the
#: parsing fails because more than the specified value is transmitted
#: a :exc:`~werkzeug.exceptions.RequestEntityTooLarge` exception is raised.
#:
#: Have a look at :ref:`dealing-with-request-data` for more details.
#:
#: .. versionadded:: 0.5
max_content_length = None
#: the maximum form field size. This is forwarded to the form data
#: parsing function (:func:`parse_form_data`). When set and the
#: :attr:`form` or :attr:`files` attribute is accessed and the
#: data in memory for post data is longer than the specified value a
#: :exc:`~werkzeug.exceptions.RequestEntityTooLarge` exception is raised.
#:
#: Have a look at :ref:`dealing-with-request-data` for more details.
#:
#: .. versionadded:: 0.5
max_form_memory_size = None
#: the class to use for `args` and `form`. The default is an
#: :class:`~werkzeug.datastructures.ImmutableMultiDict` which supports
#: multiple values per key. alternatively it makes sense to use an
#: :class:`~werkzeug.datastructures.ImmutableOrderedMultiDict` which
#: preserves order or a :class:`~werkzeug.datastructures.ImmutableDict`
#: which is the fastest but only remembers the last key. It is also
#: possible to use mutable structures, but this is not recommended.
#:
#: .. versionadded:: 0.6
parameter_storage_class = ImmutableMultiDict
#: the type to be used for list values from the incoming WSGI environment.
#: By default an :class:`~werkzeug.datastructures.ImmutableList` is used
#: (for example for :attr:`access_list`).
#:
#: .. versionadded:: 0.6
list_storage_class = ImmutableList
#: the type to be used for dict values from the incoming WSGI environment.
#: By default an
#: :class:`~werkzeug.datastructures.ImmutableTypeConversionDict` is used
#: (for example for :attr:`cookies`).
#:
#: .. versionadded:: 0.6
dict_storage_class = ImmutableTypeConversionDict
#: The form data parser that shoud be used. Can be replaced to customize
#: the form date parsing.
form_data_parser_class = FormDataParser
#: Optionally a list of hosts that is trusted by this request. By default
#: all hosts are trusted which means that whatever the client sends the
#: host is will be accepted.
#:
#: This is the recommended setup as a webserver should manually be set up
#: to only route correct hosts to the application, and remove the
#: `X-Forwarded-Host` header if it is not being used (see
#: :func:`werkzeug.wsgi.get_host`).
#:
#: .. versionadded:: 0.9
trusted_hosts = None
#: Indicates whether the data descriptor should be allowed to read and
#: buffer up the input stream. By default it's enabled.
#:
#: .. versionadded:: 0.9
disable_data_descriptor = False
def __init__(self, environ, populate_request=True, shallow=False):
self.environ = environ
if populate_request and not shallow:
self.environ['werkzeug.request'] = self
self.shallow = shallow
def __repr__(self):
# make sure the __repr__ even works if the request was created
# from an invalid WSGI environment. If we display the request
# in a debug session we don't want the repr to blow up.
args = []
try:
args.append("'%s'" % to_native(self.url, self.url_charset))
args.append('[%s]' % self.method)
except Exception:
args.append('(invalid WSGI environ)')
return '<%s %s>' % (
self.__class__.__name__,
' '.join(args)
)
@property
def url_charset(self):
"""The charset that is assumed for URLs. Defaults to the value
of :attr:`charset`.
.. versionadded:: 0.6
"""
return self.charset
@classmethod
def from_values(cls, *args, **kwargs):
"""Create a new request object based on the values provided. If
environ is given missing values are filled from there. This method is
useful for small scripts when you need to simulate a request from an URL.
Do not use this method for unittesting, there is a full featured client
object (:class:`Client`) that allows to create multipart requests,
support for cookies etc.
This accepts the same options as the
:class:`~werkzeug.test.EnvironBuilder`.
.. versionchanged:: 0.5
This method now accepts the same arguments as
:class:`~werkzeug.test.EnvironBuilder`. Because of this the
`environ` parameter is now called `environ_overrides`.
:return: request object
"""
from werkzeug.test import EnvironBuilder
charset = kwargs.pop('charset', cls.charset)
kwargs['charset'] = charset
builder = EnvironBuilder(*args, **kwargs)
try:
return builder.get_request(cls)
finally:
builder.close()
@classmethod
def application(cls, f):
"""Decorate a function as responder that accepts the request as first
argument. This works like the :func:`responder` decorator but the
function is passed the request object as first argument and the
request object will be closed automatically::
@Request.application
def my_wsgi_app(request):
return Response('Hello World!')
:param f: the WSGI callable to decorate
:return: a new WSGI callable
"""
#: return a callable that wraps the -2nd argument with the request
#: and calls the function with all the arguments up to that one and
#: the request. The return value is then called with the latest
#: two arguments. This makes it possible to use this decorator for
#: both methods and standalone WSGI functions.
def application(*args):
request = cls(args[-2])
with request:
return f(*args[:-2] + (request,))(*args[-2:])
return update_wrapper(application, f)
def _get_file_stream(self, total_content_length, content_type, filename=None,
content_length=None):
"""Called to get a stream for the file upload.
This must provide a file-like class with `read()`, `readline()`
and `seek()` methods that is both writeable and readable.
The default implementation returns a temporary file if the total
content length is higher than 500KB. Because many browsers do not
provide a content length for the files only the total content
length matters.
:param total_content_length: the total content length of all the
data in the request combined. This value
is guaranteed to be there.
:param content_type: the mimetype of the uploaded file.
:param filename: the filename of the uploaded file. May be `None`.
:param content_length: the length of this file. This value is usually
not provided because webbrowsers do not provide
this value.
"""
return default_stream_factory(total_content_length, content_type,
filename, content_length)
@property
def want_form_data_parsed(self):
"""Returns True if the request method carries content. As of
Werkzeug 0.9 this will be the case if a content type is transmitted.
.. versionadded:: 0.8
"""
return bool(self.environ.get('CONTENT_TYPE'))
def make_form_data_parser(self):
"""Creates the form data parser. Instanciates the
:attr:`form_data_parser_class` with some parameters.
.. versionadded:: 0.8
"""
return self.form_data_parser_class(self._get_file_stream,
self.charset,
self.encoding_errors,
self.max_form_memory_size,
self.max_content_length,
self.parameter_storage_class)
def _load_form_data(self):
"""Method used internally to retrieve submitted data. After calling
this sets `form` and `files` on the request object to multi dicts
filled with the incoming form data. As a matter of fact the input
stream will be empty afterwards. You can also call this method to
force the parsing of the form data.
.. versionadded:: 0.8
"""
# abort early if we have already consumed the stream
if 'form' in self.__dict__:
return
_assert_not_shallow(self)
if self.want_form_data_parsed:
content_type = self.environ.get('CONTENT_TYPE', '')
content_length = get_content_length(self.environ)
mimetype, options = parse_options_header(content_type)
parser = self.make_form_data_parser()
data = parser.parse(self._get_stream_for_parsing(),
mimetype, content_length, options)
else:
data = (self.stream, self.parameter_storage_class(),
self.parameter_storage_class())
# inject the values into the instance dict so that we bypass
# our cached_property non-data descriptor.
d = self.__dict__
d['stream'], d['form'], d['files'] = data
def _get_stream_for_parsing(self):
"""This is the same as accessing :attr:`stream` with the difference
that if it finds cached data from calling :meth:`get_data` first it
will create a new stream out of the cached data.
.. versionadded:: 0.9.3
"""
cached_data = getattr(self, '_cached_data', None)
if cached_data is not None:
return BytesIO(cached_data)
return self.stream
def close(self):
"""Closes associated resources of this request object. This
closes all file handles explicitly. You can also use the request
object in a with statement with will automatically close it.
.. versionadded:: 0.9
"""
files = self.__dict__.get('files')
for key, value in iter_multi_items(files or ()):
value.close()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
self.close()
@cached_property
def stream(self):
"""The stream to read incoming data from. Unlike :attr:`input_stream`
this stream is properly guarded that you can't accidentally read past
the length of the input. Werkzeug will internally always refer to
this stream to read data which makes it possible to wrap this
object with a stream that does filtering.
.. versionchanged:: 0.9
This stream is now always available but might be consumed by the
form parser later on. Previously the stream was only set if no
parsing happened.
"""
_assert_not_shallow(self)
return get_input_stream(self.environ)
input_stream = environ_property('wsgi.input', 'The WSGI input stream.\n'
'In general it\'s a bad idea to use this one because you can easily '
'read past the boundary. Use the :attr:`stream` instead.')
@cached_property
def args(self):
"""The parsed URL parameters. By default an
:class:`~werkzeug.datastructures.ImmutableMultiDict`
is returned from this function. This can be changed by setting
:attr:`parameter_storage_class` to a different type. This might
be necessary if the order of the form data is important.
"""
return url_decode(wsgi_get_bytes(self.environ.get('QUERY_STRING', '')),
self.url_charset, errors=self.encoding_errors,
cls=self.parameter_storage_class)
@cached_property
def data(self):
if self.disable_data_descriptor:
raise AttributeError('data descriptor is disabled')
# XXX: this should eventually be deprecated.
# We trigger form data parsing first which means that the descriptor
# will not cache the data that would otherwise be .form or .files
# data. This restores the behavior that was there in Werkzeug
# before 0.9. New code should use :meth:`get_data` explicitly as
# this will make behavior explicit.
return self.get_data(parse_form_data=True)
def get_data(self, cache=True, as_text=False, parse_form_data=False):
"""This reads the buffered incoming data from the client into one
bytestring. By default this is cached but that behavior can be
changed by setting `cache` to `False`.
Usually it's a bad idea to call this method without checking the
content length first as a client could send dozens of megabytes or more
to cause memory problems on the server.
Note that if the form data was already parsed this method will not
return anything as form data parsing does not cache the data like
this method does. To implicitly invoke form data parsing function
set `parse_form_data` to `True`. When this is done the return value
of this method will be an empty string if the form parser handles
the data. This generally is not necessary as if the whole data is
cached (which is the default) the form parser will used the cached
data to parse the form data. Please be generally aware of checking
the content length first in any case before calling this method
to avoid exhausting server memory.
If `as_text` is set to `True` the return value will be a decoded
unicode string.
.. versionadded:: 0.9
"""
rv = getattr(self, '_cached_data', None)
if rv is None:
if parse_form_data:
self._load_form_data()
rv = self.stream.read()
if cache:
self._cached_data = rv
if as_text:
rv = rv.decode(self.charset, self.encoding_errors)
return rv
@cached_property
def form(self):
"""The form parameters. By default an
:class:`~werkzeug.datastructures.ImmutableMultiDict`
is returned from this function. This can be changed by setting
:attr:`parameter_storage_class` to a different type. This might
be necessary if the order of the form data is important.
"""
self._load_form_data()
return self.form
@cached_property
def values(self):
"""Combined multi dict for :attr:`args` and :attr:`form`."""
args = []
for d in self.args, self.form:
if not isinstance(d, MultiDict):
d = MultiDict(d)
args.append(d)
return CombinedMultiDict(args)
@cached_property
def files(self):
""":class:`~werkzeug.datastructures.MultiDict` object containing
all uploaded files. Each key in :attr:`files` is the name from the
``<input type="file" name="">``. Each value in :attr:`files` is a
Werkzeug :class:`~werkzeug.datastructures.FileStorage` object.
Note that :attr:`files` will only contain data if the request method was
POST, PUT or PATCH and the ``<form>`` that posted to the request had
``enctype="multipart/form-data"``. It will be empty otherwise.
See the :class:`~werkzeug.datastructures.MultiDict` /
:class:`~werkzeug.datastructures.FileStorage` documentation for
more details about the used data structure.
"""
self._load_form_data()
return self.files
@cached_property
def cookies(self):
"""Read only access to the retrieved cookie values as dictionary."""
return parse_cookie(self.environ, self.charset,
self.encoding_errors,
cls=self.dict_storage_class)
@cached_property
def headers(self):
"""The headers from the WSGI environ as immutable
:class:`~werkzeug.datastructures.EnvironHeaders`.
"""
return EnvironHeaders(self.environ)
@cached_property
def path(self):
"""Requested path as unicode. This works a bit like the regular path
info in the WSGI environment but will always include a leading slash,
even if the URL root is accessed.
"""
raw_path = wsgi_decoding_dance(self.environ.get('PATH_INFO') or '',
self.charset, self.encoding_errors)
return '/' + raw_path.lstrip('/')
@cached_property
def full_path(self):
"""Requested path as unicode, including the query string."""
return self.path + u'?' + to_unicode(self.query_string, self.url_charset)
@cached_property
def script_root(self):
"""The root path of the script without the trailing slash."""
raw_path = wsgi_decoding_dance(self.environ.get('SCRIPT_NAME') or '',
self.charset, self.encoding_errors)
return raw_path.rstrip('/')
@cached_property
def url(self):
"""The reconstructed current URL as IRI.
See also: :attr:`trusted_hosts`.
"""
return get_current_url(self.environ,
trusted_hosts=self.trusted_hosts)
@cached_property
def base_url(self):
"""Like :attr:`url` but without the querystring
See also: :attr:`trusted_hosts`.
"""
return get_current_url(self.environ, strip_querystring=True,
trusted_hosts=self.trusted_hosts)
@cached_property
def url_root(self):
"""The full URL root (with hostname), this is the application
root as IRI.
See also: :attr:`trusted_hosts`.
"""
return get_current_url(self.environ, True,
trusted_hosts=self.trusted_hosts)
@cached_property
def host_url(self):
"""Just the host with scheme as IRI.
See also: :attr:`trusted_hosts`.
"""
return get_current_url(self.environ, host_only=True,
trusted_hosts=self.trusted_hosts)
@cached_property
def host(self):
"""Just the host including the port if available.
See also: :attr:`trusted_hosts`.
"""
return get_host(self.environ, trusted_hosts=self.trusted_hosts)
query_string = environ_property('QUERY_STRING', '', read_only=True,
load_func=wsgi_get_bytes, doc=
'''The URL parameters as raw bytestring.''')
method = environ_property('REQUEST_METHOD', 'GET', read_only=True,
load_func=lambda x: x.upper(), doc=
'''The transmission method. (For example ``'GET'`` or ``'POST'``).''')
@cached_property
def access_route(self):
"""If a forwarded header exists this is a list of all ip addresses
from the client ip to the last proxy server.
"""
if 'HTTP_X_FORWARDED_FOR' in self.environ:
addr = self.environ['HTTP_X_FORWARDED_FOR'].split(',')
return self.list_storage_class([x.strip() for x in addr])
elif 'REMOTE_ADDR' in self.environ:
return self.list_storage_class([self.environ['REMOTE_ADDR']])
return self.list_storage_class()
@property
def remote_addr(self):
"""The remote address of the client."""
return self.environ.get('REMOTE_ADDR')
remote_user = environ_property('REMOTE_USER', doc='''
If the server supports user authentication, and the script is
protected, this attribute contains the username the user has
authenticated as.''')
scheme = environ_property('wsgi.url_scheme', doc='''
URL scheme (http or https).
.. versionadded:: 0.7''')
is_xhr = property(lambda x: x.environ.get('HTTP_X_REQUESTED_WITH', '')
.lower() == 'xmlhttprequest', doc='''
True if the request was triggered via a JavaScript XMLHttpRequest.
This only works with libraries that support the `X-Requested-With`
header and set it to "XMLHttpRequest". Libraries that do that are
prototype, jQuery and Mochikit and probably some more.''')
is_secure = property(lambda x: x.environ['wsgi.url_scheme'] == 'https',
doc='`True` if the request is secure.')
is_multithread = environ_property('wsgi.multithread', doc='''
boolean that is `True` if the application is served by
a multithreaded WSGI server.''')
is_multiprocess = environ_property('wsgi.multiprocess', doc='''
boolean that is `True` if the application is served by
a WSGI server that spawns multiple processes.''')
is_run_once = environ_property('wsgi.run_once', doc='''
boolean that is `True` if the application will be executed only
once in a process lifetime. This is the case for CGI for example,
but it's not guaranteed that the exeuction only happens one time.''')
class BaseResponse(object):
"""Base response class. The most important fact about a response object
is that it's a regular WSGI application. It's initialized with a couple
of response parameters (headers, body, status code etc.) and will start a
valid WSGI response when called with the environ and start response
callable.
Because it's a WSGI application itself processing usually ends before the
actual response is sent to the server. This helps debugging systems
because they can catch all the exceptions before responses are started.
Here a small example WSGI application that takes advantage of the
response objects::
from werkzeug.wrappers import BaseResponse as Response
def index():
return Response('Index page')
def application(environ, start_response):
path = environ.get('PATH_INFO') or '/'
if path == '/':
response = index()
else:
response = Response('Not Found', status=404)
return response(environ, start_response)
Like :class:`BaseRequest` which object is lacking a lot of functionality
implemented in mixins. This gives you a better control about the actual
API of your response objects, so you can create subclasses and add custom
functionality. A full featured response object is available as
:class:`Response` which implements a couple of useful mixins.
To enforce a new type of already existing responses you can use the
:meth:`force_type` method. This is useful if you're working with different
subclasses of response objects and you want to post process them with a
know interface.
Per default the request object will assume all the text data is `utf-8`
encoded. Please refer to `the unicode chapter <unicode.txt>`_ for more
details about customizing the behavior.
Response can be any kind of iterable or string. If it's a string it's
considered being an iterable with one item which is the string passed.
Headers can be a list of tuples or a
:class:`~werkzeug.datastructures.Headers` object.
Special note for `mimetype` and `content_type`: For most mime types
`mimetype` and `content_type` work the same, the difference affects
only 'text' mimetypes. If the mimetype passed with `mimetype` is a
mimetype starting with `text/`, the charset parameter of the response
object is appended to it. In contrast the `content_type` parameter is
always added as header unmodified.
.. versionchanged:: 0.5
the `direct_passthrough` parameter was added.
:param response: a string or response iterable.
:param status: a string with a status or an integer with the status code.
:param headers: a list of headers or a
:class:`~werkzeug.datastructures.Headers` object.
:param mimetype: the mimetype for the request. See notice above.
:param content_type: the content type for the request. See notice above.
:param direct_passthrough: if set to `True` :meth:`iter_encoded` is not
called before iteration which makes it
possible to pass special iterators though
unchanged (see :func:`wrap_file` for more
details.)
"""
#: the charset of the response.
charset = 'utf-8'
#: the default status if none is provided.
default_status = 200
#: the default mimetype if none is provided.
default_mimetype = 'text/plain'
#: if set to `False` accessing properties on the response object will
#: not try to consume the response iterator and convert it into a list.
#:
#: .. versionadded:: 0.6.2
#:
#: That attribute was previously called `implicit_seqence_conversion`.
#: (Notice the typo). If you did use this feature, you have to adapt
#: your code to the name change.
implicit_sequence_conversion = True
#: Should this response object correct the location header to be RFC
#: conformant? This is true by default.
#:
#: .. versionadded:: 0.8
autocorrect_location_header = True
#: Should this response object automatically set the content-length
#: header if possible? This is true by default.
#:
#: .. versionadded:: 0.8
automatically_set_content_length = True
def __init__(self, response=None, status=None, headers=None,
mimetype=None, content_type=None, direct_passthrough=False):
if isinstance(headers, Headers):
self.headers = headers
elif not headers:
self.headers = Headers()
else:
self.headers = Headers(headers)
if content_type is None:
if mimetype is None and 'content-type' not in self.headers:
mimetype = self.default_mimetype
if mimetype is not None:
mimetype = get_content_type(mimetype, self.charset)
content_type = mimetype
if content_type is not None:
self.headers['Content-Type'] = content_type
if status is None:
status = self.default_status
if isinstance(status, integer_types):
self.status_code = status
else:
self.status = status
self.direct_passthrough = direct_passthrough
self._on_close = []
# we set the response after the headers so that if a class changes
# the charset attribute, the data is set in the correct charset.
if response is None:
self.response = []
elif isinstance(response, (text_type, bytes, bytearray)):
self.set_data(response)
else:
self.response = response
def call_on_close(self, func):
"""Adds a function to the internal list of functions that should
be called as part of closing down the response. Since 0.7 this
function also returns the function that was passed so that this
can be used as a decorator.
.. versionadded:: 0.6
"""
self._on_close.append(func)
return func
def __repr__(self):
if self.is_sequence:
body_info = '%d bytes' % sum(map(len, self.iter_encoded()))
else:
body_info = self.is_streamed and 'streamed' or 'likely-streamed'
return '<%s %s [%s]>' % (
self.__class__.__name__,
body_info,
self.status
)
@classmethod
def force_type(cls, response, environ=None):
"""Enforce that the WSGI response is a response object of the current
type. Werkzeug will use the :class:`BaseResponse` internally in many
situations like the exceptions. If you call :meth:`get_response` on an
exception you will get back a regular :class:`BaseResponse` object, even
if you are using a custom subclass.
This method can enforce a given response type, and it will also
convert arbitrary WSGI callables into response objects if an environ
is provided::
# convert a Werkzeug response object into an instance of the
# MyResponseClass subclass.
response = MyResponseClass.force_type(response)
# convert any WSGI application into a response object
response = MyResponseClass.force_type(response, environ)
This is especially useful if you want to post-process responses in
the main dispatcher and use functionality provided by your subclass.
Keep in mind that this will modify response objects in place if
possible!
:param response: a response object or wsgi application.
:param environ: a WSGI environment object.
:return: a response object.
"""
if not isinstance(response, BaseResponse):
if environ is None:
raise TypeError('cannot convert WSGI application into '
'response objects without an environ')
response = BaseResponse(*_run_wsgi_app(response, environ))
response.__class__ = cls
return response
@classmethod
def from_app(cls, app, environ, buffered=False):
"""Create a new response object from an application output. This
works best if you pass it an application that returns a generator all
the time. Sometimes applications may use the `write()` callable
returned by the `start_response` function. This tries to resolve such
edge cases automatically. But if you don't get the expected output
you should set `buffered` to `True` which enforces buffering.
:param app: the WSGI application to execute.
:param environ: the WSGI environment to execute against.
:param buffered: set to `True` to enforce buffering.
:return: a response object.
"""
return cls(*_run_wsgi_app(app, environ, buffered))
def _get_status_code(self):
return self._status_code
def _set_status_code(self, code):
self._status_code = code
try:
self._status = '%d %s' % (code, HTTP_STATUS_CODES[code].upper())
except KeyError:
self._status = '%d UNKNOWN' % code
status_code = property(_get_status_code, _set_status_code,
doc='The HTTP Status code as number')
del _get_status_code, _set_status_code
def _get_status(self):
return self._status
def _set_status(self, value):
self._status = to_native(value)
try:
self._status_code = int(self._status.split(None, 1)[0])
except ValueError:
self._status_code = 0
self._status = '0 %s' % self._status
status = property(_get_status, _set_status, doc='The HTTP Status code')
del _get_status, _set_status
def get_data(self, as_text=False):
"""The string representation of the request body. Whenever you call
this property the request iterable is encoded and flattened. This
can lead to unwanted behavior if you stream big data.
This behavior can be disabled by setting
:attr:`implicit_sequence_conversion` to `False`.
If `as_text` is set to `True` the return value will be a decoded
unicode string.
.. versionadded:: 0.9
"""
self._ensure_sequence()
rv = b''.join(self.iter_encoded())
if as_text:
rv = rv.decode(self.charset)
return rv
def set_data(self, value):
"""Sets a new string as response. The value set must either by a
unicode or bytestring. If a unicode string is set it's encoded
automatically to the charset of the response (utf-8 by default).
.. versionadded:: 0.9
"""
# if an unicode string is set, it's encoded directly so that we
# can set the content length
if isinstance(value, text_type):
value = value.encode(self.charset)
else:
value = bytes(value)
self.response = [value]
if self.automatically_set_content_length:
self.headers['Content-Length'] = str(len(value))
data = property(get_data, set_data, doc='''
A descriptor that calls :meth:`get_data` and :meth:`set_data`. This
should not be used and will eventually get deprecated.
''')
def calculate_content_length(self):
"""Returns the content length if available or `None` otherwise."""
try:
self._ensure_sequence()
except RuntimeError:
return None
return sum(len(x) for x in self.response)
def _ensure_sequence(self, mutable=False):
"""This method can be called by methods that need a sequence. If
`mutable` is true, it will also ensure that the response sequence
is a standard Python list.
.. versionadded:: 0.6
"""
if self.is_sequence:
# if we need a mutable object, we ensure it's a list.
if mutable and not isinstance(self.response, list):
self.response = list(self.response)
return
if self.direct_passthrough:
raise RuntimeError('Attempted implicit sequence conversion '
'but the response object is in direct '
'passthrough mode.')
if not self.implicit_sequence_conversion:
raise RuntimeError('The response object required the iterable '
'to be a sequence, but the implicit '
'conversion was disabled. Call '
'make_sequence() yourself.')
self.make_sequence()
def make_sequence(self):
"""Converts the response iterator in a list. By default this happens
automatically if required. If `implicit_sequence_conversion` is
disabled, this method is not automatically called and some properties
might raise exceptions. This also encodes all the items.
.. versionadded:: 0.6
"""
if not self.is_sequence:
# if we consume an iterable we have to ensure that the close
# method of the iterable is called if available when we tear
# down the response
close = getattr(self.response, 'close', None)
self.response = list(self.iter_encoded())
if close is not None:
self.call_on_close(close)
def iter_encoded(self):
"""Iter the response encoded with the encoding of the response.
If the response object is invoked as WSGI application the return
value of this method is used as application iterator unless
:attr:`direct_passthrough` was activated.
"""
if __debug__:
_warn_if_string(self.response)
# Encode in a separate function so that self.response is fetched
# early. This allows us to wrap the response with the return
# value from get_app_iter or iter_encoded.
return _iter_encoded(self.response, self.charset)
def set_cookie(self, key, value='', max_age=None, expires=None,
path='/', domain=None, secure=None, httponly=False):
"""Sets a cookie. The parameters are the same as in the cookie `Morsel`
object in the Python standard library but it accepts unicode data, too.
:param key: the key (name) of the cookie to be set.
:param value: the value of the cookie.
:param max_age: should be a number of seconds, or `None` (default) if
the cookie should last only as long as the client's
browser session.
:param expires: should be a `datetime` object or UNIX timestamp.
:param domain: if you want to set a cross-domain cookie. For example,
``domain=".example.com"`` will set a cookie that is
readable by the domain ``www.example.com``,
``foo.example.com`` etc. Otherwise, a cookie will only
be readable by the domain that set it.
:param path: limits the cookie to a given path, per default it will
span the whole domain.
"""
self.headers.add('Set-Cookie', dump_cookie(key, value, max_age,
expires, path, domain, secure, httponly,
self.charset))
def delete_cookie(self, key, path='/', domain=None):
"""Delete a cookie. Fails silently if key doesn't exist.
:param key: the key (name) of the cookie to be deleted.
:param path: if the cookie that should be deleted was limited to a
path, the path has to be defined here.
:param domain: if the cookie that should be deleted was limited to a
domain, that domain has to be defined here.
"""
self.set_cookie(key, expires=0, max_age=0, path=path, domain=domain)
@property
def is_streamed(self):
"""If the response is streamed (the response is not an iterable with
a length information) this property is `True`. In this case streamed
means that there is no information about the number of iterations.
This is usually `True` if a generator is passed to the response object.
This is useful for checking before applying some sort of post
filtering that should not take place for streamed responses.
"""
try:
len(self.response)
except (TypeError, AttributeError):
return True
return False
@property
def is_sequence(self):
"""If the iterator is buffered, this property will be `True`. A
response object will consider an iterator to be buffered if the
response attribute is a list or tuple.
.. versionadded:: 0.6
"""
return isinstance(self.response, (tuple, list))
def close(self):
"""Close the wrapped response if possible. You can also use the object
in a with statement which will automatically close it.
.. versionadded:: 0.9
Can now be used in a with statement.
"""
if hasattr(self.response, 'close'):
self.response.close()
for func in self._on_close:
func()
def __enter__(self):
return self
def __exit__(self, exc_type, exc_value, tb):
self.close()
def freeze(self):
"""Call this method if you want to make your response object ready for
being pickled. This buffers the generator if there is one. It will
also set the `Content-Length` header to the length of the body.
.. versionchanged:: 0.6
The `Content-Length` header is now set.
"""
# we explicitly set the length to a list of the *encoded* response
# iterator. Even if the implicit sequence conversion is disabled.
self.response = list(self.iter_encoded())
self.headers['Content-Length'] = str(sum(map(len, self.response)))
def get_wsgi_headers(self, environ):
"""This is automatically called right before the response is started
and returns headers modified for the given environment. It returns a
copy of the headers from the response with some modifications applied
if necessary.
For example the location header (if present) is joined with the root
URL of the environment. Also the content length is automatically set
to zero here for certain status codes.
.. versionchanged:: 0.6
Previously that function was called `fix_headers` and modified
the response object in place. Also since 0.6, IRIs in location
and content-location headers are handled properly.
Also starting with 0.6, Werkzeug will attempt to set the content
length if it is able to figure it out on its own. This is the
case if all the strings in the response iterable are already
encoded and the iterable is buffered.
:param environ: the WSGI environment of the request.
:return: returns a new :class:`~werkzeug.datastructures.Headers`
object.
"""
headers = Headers(self.headers)
location = None
content_location = None
content_length = None
status = self.status_code
# iterate over the headers to find all values in one go. Because
# get_wsgi_headers is used each response that gives us a tiny
# speedup.
for key, value in headers:
ikey = key.lower()
if ikey == u'location':
location = value
elif ikey == u'content-location':
content_location = value
elif ikey == u'content-length':
content_length = value
# make sure the location header is an absolute URL
if location is not None:
old_location = location
if isinstance(location, text_type):
# Safe conversion is necessary here as we might redirect
# to a broken URI scheme (for instance itms-services).
location = iri_to_uri(location, safe_conversion=True)
if self.autocorrect_location_header:
current_url = get_current_url(environ, root_only=True)
if isinstance(current_url, text_type):
current_url = iri_to_uri(current_url)
location = url_join(current_url, location)
if location != old_location:
headers['Location'] = location
# make sure the content location is a URL
if content_location is not None and \
isinstance(content_location, text_type):
headers['Content-Location'] = iri_to_uri(content_location)
# remove entity headers and set content length to zero if needed.
# Also update content_length accordingly so that the automatic
# content length detection does not trigger in the following
# code.
if 100 <= status < 200 or status == 204:
headers['Content-Length'] = content_length = u'0'
elif status == 304:
remove_entity_headers(headers)
# if we can determine the content length automatically, we
# should try to do that. But only if this does not involve
# flattening the iterator or encoding of unicode strings in
# the response. We however should not do that if we have a 304
# response.
if self.automatically_set_content_length and \
self.is_sequence and content_length is None and status != 304:
try:
content_length = sum(len(to_bytes(x, 'ascii'))
for x in self.response)
except UnicodeError:
# aha, something non-bytestringy in there, too bad, we
# can't safely figure out the length of the response.
pass
else:
headers['Content-Length'] = str(content_length)
return headers
def get_app_iter(self, environ):
"""Returns the application iterator for the given environ. Depending
on the request method and the current status code the return value
might be an empty response rather than the one from the response.
If the request method is `HEAD` or the status code is in a range
where the HTTP specification requires an empty response, an empty
iterable is returned.
.. versionadded:: 0.6
:param environ: the WSGI environment of the request.
:return: a response iterable.
"""
status = self.status_code
if environ['REQUEST_METHOD'] == 'HEAD' or \
100 <= status < 200 or status in (204, 304):
iterable = ()
elif self.direct_passthrough:
if __debug__:
_warn_if_string(self.response)
return self.response
else:
iterable = self.iter_encoded()
return ClosingIterator(iterable, self.close)
def get_wsgi_response(self, environ):
"""Returns the final WSGI response as tuple. The first item in
the tuple is the application iterator, the second the status and
the third the list of headers. The response returned is created
specially for the given environment. For example if the request
method in the WSGI environment is ``'HEAD'`` the response will
be empty and only the headers and status code will be present.
.. versionadded:: 0.6
:param environ: the WSGI environment of the request.
:return: an ``(app_iter, status, headers)`` tuple.
"""
headers = self.get_wsgi_headers(environ)
app_iter = self.get_app_iter(environ)
return app_iter, self.status, headers.to_wsgi_list()
def __call__(self, environ, start_response):
"""Process this response as WSGI application.
:param environ: the WSGI environment.
:param start_response: the response callable provided by the WSGI
server.
:return: an application iterator
"""
app_iter, status, headers = self.get_wsgi_response(environ)
start_response(status, headers)
return app_iter
class AcceptMixin(object):
"""A mixin for classes with an :attr:`~BaseResponse.environ` attribute
to get all the HTTP accept headers as
:class:`~werkzeug.datastructures.Accept` objects (or subclasses
thereof).
"""
@cached_property
def accept_mimetypes(self):
"""List of mimetypes this client supports as
:class:`~werkzeug.datastructures.MIMEAccept` object.
"""
return parse_accept_header(self.environ.get('HTTP_ACCEPT'), MIMEAccept)
@cached_property
def accept_charsets(self):
"""List of charsets this client supports as
:class:`~werkzeug.datastructures.CharsetAccept` object.
"""
return parse_accept_header(self.environ.get('HTTP_ACCEPT_CHARSET'),
CharsetAccept)
@cached_property
def accept_encodings(self):
"""List of encodings this client accepts. Encodings in a HTTP term
are compression encodings such as gzip. For charsets have a look at
:attr:`accept_charset`.
"""
return parse_accept_header(self.environ.get('HTTP_ACCEPT_ENCODING'))
@cached_property
def accept_languages(self):
"""List of languages this client accepts as
:class:`~werkzeug.datastructures.LanguageAccept` object.
.. versionchanged 0.5
In previous versions this was a regular
:class:`~werkzeug.datastructures.Accept` object.
"""
return parse_accept_header(self.environ.get('HTTP_ACCEPT_LANGUAGE'),
LanguageAccept)
class ETagRequestMixin(object):
"""Add entity tag and cache descriptors to a request object or object with
a WSGI environment available as :attr:`~BaseRequest.environ`. This not
only provides access to etags but also to the cache control header.
"""
@cached_property
def cache_control(self):
"""A :class:`~werkzeug.datastructures.RequestCacheControl` object
for the incoming cache control headers.
"""
cache_control = self.environ.get('HTTP_CACHE_CONTROL')
return parse_cache_control_header(cache_control, None,
RequestCacheControl)
@cached_property
def if_match(self):
"""An object containing all the etags in the `If-Match` header.
:rtype: :class:`~werkzeug.datastructures.ETags`
"""
return parse_etags(self.environ.get('HTTP_IF_MATCH'))
@cached_property
def if_none_match(self):
"""An object containing all the etags in the `If-None-Match` header.
:rtype: :class:`~werkzeug.datastructures.ETags`
"""
return parse_etags(self.environ.get('HTTP_IF_NONE_MATCH'))
@cached_property
def if_modified_since(self):
"""The parsed `If-Modified-Since` header as datetime object."""
return parse_date(self.environ.get('HTTP_IF_MODIFIED_SINCE'))
@cached_property
def if_unmodified_since(self):
"""The parsed `If-Unmodified-Since` header as datetime object."""
return parse_date(self.environ.get('HTTP_IF_UNMODIFIED_SINCE'))
@cached_property
def if_range(self):
"""The parsed `If-Range` header.
.. versionadded:: 0.7
:rtype: :class:`~werkzeug.datastructures.IfRange`
"""
return parse_if_range_header(self.environ.get('HTTP_IF_RANGE'))
@cached_property
def range(self):
"""The parsed `Range` header.
.. versionadded:: 0.7
:rtype: :class:`~werkzeug.datastructures.Range`
"""
return parse_range_header(self.environ.get('HTTP_RANGE'))
class UserAgentMixin(object):
"""Adds a `user_agent` attribute to the request object which contains the
parsed user agent of the browser that triggered the request as a
:class:`~werkzeug.useragents.UserAgent` object.
"""
@cached_property
def user_agent(self):
"""The current user agent."""
from werkzeug.useragents import UserAgent
return UserAgent(self.environ)
class AuthorizationMixin(object):
"""Adds an :attr:`authorization` property that represents the parsed
value of the `Authorization` header as
:class:`~werkzeug.datastructures.Authorization` object.
"""
@cached_property
def authorization(self):
"""The `Authorization` object in parsed form."""
header = self.environ.get('HTTP_AUTHORIZATION')
return parse_authorization_header(header)
class StreamOnlyMixin(object):
"""If mixed in before the request object this will change the bahavior
of it to disable handling of form parsing. This disables the
:attr:`files`, :attr:`form` attributes and will just provide a
:attr:`stream` attribute that however is always available.
.. versionadded:: 0.9
"""
disable_data_descriptor = True
want_form_data_parsed = False
class ETagResponseMixin(object):
"""Adds extra functionality to a response object for etag and cache
handling. This mixin requires an object with at least a `headers`
object that implements a dict like interface similar to
:class:`~werkzeug.datastructures.Headers`.
If you want the :meth:`freeze` method to automatically add an etag, you
have to mixin this method before the response base class. The default
response class does not do that.
"""
@property
def cache_control(self):
"""The Cache-Control general-header field is used to specify
directives that MUST be obeyed by all caching mechanisms along the
request/response chain.
"""
def on_update(cache_control):
if not cache_control and 'cache-control' in self.headers:
del self.headers['cache-control']
elif cache_control:
self.headers['Cache-Control'] = cache_control.to_header()
return parse_cache_control_header(self.headers.get('cache-control'),
on_update,
ResponseCacheControl)
def make_conditional(self, request_or_environ):
"""Make the response conditional to the request. This method works
best if an etag was defined for the response already. The `add_etag`
method can be used to do that. If called without etag just the date
header is set.
This does nothing if the request method in the request or environ is
anything but GET or HEAD.
It does not remove the body of the response because that's something
the :meth:`__call__` function does for us automatically.
Returns self so that you can do ``return resp.make_conditional(req)``
but modifies the object in-place.
:param request_or_environ: a request object or WSGI environment to be
used to make the response conditional
against.
"""
environ = _get_environ(request_or_environ)
if environ['REQUEST_METHOD'] in ('GET', 'HEAD'):
# if the date is not in the headers, add it now. We however
# will not override an already existing header. Unfortunately
# this header will be overriden by many WSGI servers including
# wsgiref.
if 'date' not in self.headers:
self.headers['Date'] = http_date()
if self.automatically_set_content_length and 'content-length' not in self.headers:
length = self.calculate_content_length()
if length is not None:
self.headers['Content-Length'] = length
if not is_resource_modified(environ, self.headers.get('etag'), None,
self.headers.get('last-modified')):
self.status_code = 304
return self
def add_etag(self, overwrite=False, weak=False):
"""Add an etag for the current response if there is none yet."""
if overwrite or 'etag' not in self.headers:
self.set_etag(generate_etag(self.get_data()), weak)
def set_etag(self, etag, weak=False):
"""Set the etag, and override the old one if there was one."""
self.headers['ETag'] = quote_etag(etag, weak)
def get_etag(self):
"""Return a tuple in the form ``(etag, is_weak)``. If there is no
ETag the return value is ``(None, None)``.
"""
return unquote_etag(self.headers.get('ETag'))
def freeze(self, no_etag=False):
"""Call this method if you want to make your response object ready for
pickeling. This buffers the generator if there is one. This also
sets the etag unless `no_etag` is set to `True`.
"""
if not no_etag:
self.add_etag()
super(ETagResponseMixin, self).freeze()
accept_ranges = header_property('Accept-Ranges', doc='''
The `Accept-Ranges` header. Even though the name would indicate
that multiple values are supported, it must be one string token only.
The values ``'bytes'`` and ``'none'`` are common.
.. versionadded:: 0.7''')
def _get_content_range(self):
def on_update(rng):
if not rng:
del self.headers['content-range']
else:
self.headers['Content-Range'] = rng.to_header()
rv = parse_content_range_header(self.headers.get('content-range'),
on_update)
# always provide a content range object to make the descriptor
# more user friendly. It provides an unset() method that can be
# used to remove the header quickly.
if rv is None:
rv = ContentRange(None, None, None, on_update=on_update)
return rv
def _set_content_range(self, value):
if not value:
del self.headers['content-range']
elif isinstance(value, string_types):
self.headers['Content-Range'] = value
else:
self.headers['Content-Range'] = value.to_header()
content_range = property(_get_content_range, _set_content_range, doc='''
The `Content-Range` header as
:class:`~werkzeug.datastructures.ContentRange` object. Even if the
header is not set it wil provide such an object for easier
manipulation.
.. versionadded:: 0.7''')
del _get_content_range, _set_content_range
class ResponseStream(object):
"""A file descriptor like object used by the :class:`ResponseStreamMixin` to
represent the body of the stream. It directly pushes into the response
iterable of the response object.
"""
mode = 'wb+'
def __init__(self, response):
self.response = response
self.closed = False
def write(self, value):
if self.closed:
raise ValueError('I/O operation on closed file')
self.response._ensure_sequence(mutable=True)
self.response.response.append(value)
self.response.headers.pop('Content-Length', None)
def writelines(self, seq):
for item in seq:
self.write(item)
def close(self):
self.closed = True
def flush(self):
if self.closed:
raise ValueError('I/O operation on closed file')
def isatty(self):
if self.closed:
raise ValueError('I/O operation on closed file')
return False
@property
def encoding(self):
return self.response.charset
class ResponseStreamMixin(object):
"""Mixin for :class:`BaseRequest` subclasses. Classes that inherit from
this mixin will automatically get a :attr:`stream` property that provides
a write-only interface to the response iterable.
"""
@cached_property
def stream(self):
"""The response iterable as write-only stream."""
return ResponseStream(self)
class CommonRequestDescriptorsMixin(object):
"""A mixin for :class:`BaseRequest` subclasses. Request objects that
mix this class in will automatically get descriptors for a couple of
HTTP headers with automatic type conversion.
.. versionadded:: 0.5
"""
content_type = environ_property('CONTENT_TYPE', doc='''
The Content-Type entity-header field indicates the media type of
the entity-body sent to the recipient or, in the case of the HEAD
method, the media type that would have been sent had the request
been a GET.''')
@cached_property
def content_length(self):
"""The Content-Length entity-header field indicates the size of the
entity-body in bytes or, in the case of the HEAD method, the size of
the entity-body that would have been sent had the request been a
GET.
"""
return get_content_length(self.environ)
content_encoding = environ_property('HTTP_CONTENT_ENCODING', doc='''
The Content-Encoding entity-header field is used as a modifier to the
media-type. When present, its value indicates what additional content
codings have been applied to the entity-body, and thus what decoding
mechanisms must be applied in order to obtain the media-type
referenced by the Content-Type header field.
.. versionadded:: 0.9''')
content_md5 = environ_property('HTTP_CONTENT_MD5', doc='''
The Content-MD5 entity-header field, as defined in RFC 1864, is an
MD5 digest of the entity-body for the purpose of providing an
end-to-end message integrity check (MIC) of the entity-body. (Note:
a MIC is good for detecting accidental modification of the
entity-body in transit, but is not proof against malicious attacks.)
.. versionadded:: 0.9''')
referrer = environ_property('HTTP_REFERER', doc='''
The Referer[sic] request-header field allows the client to specify,
for the server's benefit, the address (URI) of the resource from which
the Request-URI was obtained (the "referrer", although the header
field is misspelled).''')
date = environ_property('HTTP_DATE', None, parse_date, doc='''
The Date general-header field represents the date and time at which
the message was originated, having the same semantics as orig-date
in RFC 822.''')
max_forwards = environ_property('HTTP_MAX_FORWARDS', None, int, doc='''
The Max-Forwards request-header field provides a mechanism with the
TRACE and OPTIONS methods to limit the number of proxies or gateways
that can forward the request to the next inbound server.''')
def _parse_content_type(self):
if not hasattr(self, '_parsed_content_type'):
self._parsed_content_type = \
parse_options_header(self.environ.get('CONTENT_TYPE', ''))
@property
def mimetype(self):
"""Like :attr:`content_type` but without parameters (eg, without
charset, type etc.). For example if the content
type is ``text/html; charset=utf-8`` the mimetype would be
``'text/html'``.
"""
self._parse_content_type()
return self._parsed_content_type[0]
@property
def mimetype_params(self):
"""The mimetype parameters as dict. For example if the content
type is ``text/html; charset=utf-8`` the params would be
``{'charset': 'utf-8'}``.
"""
self._parse_content_type()
return self._parsed_content_type[1]
@cached_property
def pragma(self):
"""The Pragma general-header field is used to include
implementation-specific directives that might apply to any recipient
along the request/response chain. All pragma directives specify
optional behavior from the viewpoint of the protocol; however, some
systems MAY require that behavior be consistent with the directives.
"""
return parse_set_header(self.environ.get('HTTP_PRAGMA', ''))
class CommonResponseDescriptorsMixin(object):
"""A mixin for :class:`BaseResponse` subclasses. Response objects that
mix this class in will automatically get descriptors for a couple of
HTTP headers with automatic type conversion.
"""
def _get_mimetype(self):
ct = self.headers.get('content-type')
if ct:
return ct.split(';')[0].strip()
def _set_mimetype(self, value):
self.headers['Content-Type'] = get_content_type(value, self.charset)
def _get_mimetype_params(self):
def on_update(d):
self.headers['Content-Type'] = \
dump_options_header(self.mimetype, d)
d = parse_options_header(self.headers.get('content-type', ''))[1]
return CallbackDict(d, on_update)
mimetype = property(_get_mimetype, _set_mimetype, doc='''
The mimetype (content type without charset etc.)''')
mimetype_params = property(_get_mimetype_params, doc='''
The mimetype parameters as dict. For example if the content
type is ``text/html; charset=utf-8`` the params would be
``{'charset': 'utf-8'}``.
.. versionadded:: 0.5
''')
location = header_property('Location', doc='''
The Location response-header field is used to redirect the recipient
to a location other than the Request-URI for completion of the request
or identification of a new resource.''')
age = header_property('Age', None, parse_date, http_date, doc='''
The Age response-header field conveys the sender's estimate of the
amount of time since the response (or its revalidation) was
generated at the origin server.
Age values are non-negative decimal integers, representing time in
seconds.''')
content_type = header_property('Content-Type', doc='''
The Content-Type entity-header field indicates the media type of the
entity-body sent to the recipient or, in the case of the HEAD method,
the media type that would have been sent had the request been a GET.
''')
content_length = header_property('Content-Length', None, int, str, doc='''
The Content-Length entity-header field indicates the size of the
entity-body, in decimal number of OCTETs, sent to the recipient or,
in the case of the HEAD method, the size of the entity-body that would
have been sent had the request been a GET.''')
content_location = header_property('Content-Location', doc='''
The Content-Location entity-header field MAY be used to supply the
resource location for the entity enclosed in the message when that
entity is accessible from a location separate from the requested
resource's URI.''')
content_encoding = header_property('Content-Encoding', doc='''
The Content-Encoding entity-header field is used as a modifier to the
media-type. When present, its value indicates what additional content
codings have been applied to the entity-body, and thus what decoding
mechanisms must be applied in order to obtain the media-type
referenced by the Content-Type header field.''')
content_md5 = header_property('Content-MD5', doc='''
The Content-MD5 entity-header field, as defined in RFC 1864, is an
MD5 digest of the entity-body for the purpose of providing an
end-to-end message integrity check (MIC) of the entity-body. (Note:
a MIC is good for detecting accidental modification of the
entity-body in transit, but is not proof against malicious attacks.)
''')
date = header_property('Date', None, parse_date, http_date, doc='''
The Date general-header field represents the date and time at which
the message was originated, having the same semantics as orig-date
in RFC 822.''')
expires = header_property('Expires', None, parse_date, http_date, doc='''
The Expires entity-header field gives the date/time after which the
response is considered stale. A stale cache entry may not normally be
returned by a cache.''')
last_modified = header_property('Last-Modified', None, parse_date,
http_date, doc='''
The Last-Modified entity-header field indicates the date and time at
which the origin server believes the variant was last modified.''')
def _get_retry_after(self):
value = self.headers.get('retry-after')
if value is None:
return
elif value.isdigit():
return datetime.utcnow() + timedelta(seconds=int(value))
return parse_date(value)
def _set_retry_after(self, value):
if value is None:
if 'retry-after' in self.headers:
del self.headers['retry-after']
return
elif isinstance(value, datetime):
value = http_date(value)
else:
value = str(value)
self.headers['Retry-After'] = value
retry_after = property(_get_retry_after, _set_retry_after, doc='''
The Retry-After response-header field can be used with a 503 (Service
Unavailable) response to indicate how long the service is expected
to be unavailable to the requesting client.
Time in seconds until expiration or date.''')
def _set_property(name, doc=None):
def fget(self):
def on_update(header_set):
if not header_set and name in self.headers:
del self.headers[name]
elif header_set:
self.headers[name] = header_set.to_header()
return parse_set_header(self.headers.get(name), on_update)
def fset(self, value):
if not value:
del self.headers[name]
elif isinstance(value, string_types):
self.headers[name] = value
else:
self.headers[name] = dump_header(value)
return property(fget, fset, doc=doc)
vary = _set_property('Vary', doc='''
The Vary field value indicates the set of request-header fields that
fully determines, while the response is fresh, whether a cache is
permitted to use the response to reply to a subsequent request
without revalidation.''')
content_language = _set_property('Content-Language', doc='''
The Content-Language entity-header field describes the natural
language(s) of the intended audience for the enclosed entity. Note
that this might not be equivalent to all the languages used within
the entity-body.''')
allow = _set_property('Allow', doc='''
The Allow entity-header field lists the set of methods supported
by the resource identified by the Request-URI. The purpose of this
field is strictly to inform the recipient of valid methods
associated with the resource. An Allow header field MUST be
present in a 405 (Method Not Allowed) response.''')
del _set_property, _get_mimetype, _set_mimetype, _get_retry_after, \
_set_retry_after
class WWWAuthenticateMixin(object):
"""Adds a :attr:`www_authenticate` property to a response object."""
@property
def www_authenticate(self):
"""The `WWW-Authenticate` header in a parsed form."""
def on_update(www_auth):
if not www_auth and 'www-authenticate' in self.headers:
del self.headers['www-authenticate']
elif www_auth:
self.headers['WWW-Authenticate'] = www_auth.to_header()
header = self.headers.get('www-authenticate')
return parse_www_authenticate_header(header, on_update)
class Request(BaseRequest, AcceptMixin, ETagRequestMixin,
UserAgentMixin, AuthorizationMixin,
CommonRequestDescriptorsMixin):
"""Full featured request object implementing the following mixins:
- :class:`AcceptMixin` for accept header parsing
- :class:`ETagRequestMixin` for etag and cache control handling
- :class:`UserAgentMixin` for user agent introspection
- :class:`AuthorizationMixin` for http auth handling
- :class:`CommonRequestDescriptorsMixin` for common headers
"""
class PlainRequest(StreamOnlyMixin, Request):
"""A request object without special form parsing capabilities.
.. versionadded:: 0.9
"""
class Response(BaseResponse, ETagResponseMixin, ResponseStreamMixin,
CommonResponseDescriptorsMixin,
WWWAuthenticateMixin):
"""Full featured response object implementing the following mixins:
- :class:`ETagResponseMixin` for etag and cache control handling
- :class:`ResponseStreamMixin` to add support for the `stream` property
- :class:`CommonResponseDescriptorsMixin` for various HTTP descriptors
- :class:`WWWAuthenticateMixin` for HTTP authentication support
"""
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
21148,
272,
18294,
94,
339,
710,
17995,
787,
3486,
1056,
436,
1177,
2251,
1314,
1265,
883,
272,
5516,
370,
886,
15685,
1265,
2934,
3062,
370,
886,
14,
221,
710,
1056,
909,
3509,
272,
314,
2556,
29818,
701,
314,
1890,
334,
1129,
29063,
9,
436,
314,
1177,
272,
909,
3509,
1006,
314,
2556,
4847,
1771,
370,
314,
7042,
14,
339,
1626,
11012,
10093,
365,
626,
314,
1056,
909,
365,
2737,
543,
314,
9279,
272,
6160,
436,
911,
2454,
465,
4721,
13,
1896,
4566,
29781,
314,
1177,
909,
365,
376,
272,
3503,
9279,
4223,
14,
339,
16485,
8137,
587,
315,
22798,
3520,
2251,
911,
1736,
6657,
543,
272,
2649,
666,
14,
221,
1010,
7909,
1824,
666,
4565,
701,
314,
1177,
909,
911,
506,
272,
11203,
1901,
376,
2649,
909,
340,
3962,
436,
340,
652,
7704,
12249,
14,
2378,
520,
7307,
26,
334,
67,
9,
6927,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
504,
9143,
492,
1678,
63,
5029,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
504,
10380,
14,
1014,
492,
3101,
63,
6305,
63,
15639,
12,
971,
1362,
2198,
63,
5694,
63,
1291,
12,
2198,
63,
1637,
63,
2785,
63,
1291,
12,
2198,
63,
1841,
458,
12,
971,
1362,
2198,
63,
602,
12,
3550,
63,
11304,
12,
365,
63,
1927,
63,
5540,
12,
14342,
63,
11304,
12,
971,
1362,
6313,
63,
11304,
12,
2198,
63,
409,
63,
1291,
12,
2198,
63,
15846,
63,
1291,
12,
971,
1362,
2198,
63,
1544,
63,
13975,
63,
1291,
12,
2813,
63,
4502,
63,
2139,
12,
971,
1362,
2198,
63,
1419,
63,
1291,
12,
5461,
63,
1419,
63,
1291,
12,
1455,
63,
602,
12,
971,
1362,
2198,
63,
692,
63,
1842,
63,
1291,
12,
2198,
63,
5306,
12,
5461,
63,
5306,
12,
971,
1362,
2198,
63,
1842,
63,
1291,
12,
2198,
63,
1317,
63,
1842,
63,
1291,
12,
5461,
63,
1291,
199,
504,
10380,
14,
3603,
492,
1166,
63,
2708,
12,
24086,
63,
475,
63,
2302,
12,
1166,
63,
904,
199,
504,
10380,
14,
509,
311,
285,
332,
492,
8204,
1451,
2842,
12,
849,
63,
1745,
63,
3702,
199,
504,
10380,
14,
1208,
492,
6328,
63,
1829,
12,
6160,
63,
1829,
12,
971,
1362,
1406,
63,
1829,
12,
664,
63,
1317,
63,
466,
199,
504,
10380,
14,
6508,
492,
664,
63,
1818,
63,
633,
12,
664,
63,
1102,
12,
971,
1362,
5980,
1044,
3585,
12,
664,
63,
1210,
63,
1745,
12,
664,
63,
1317,
63,
1267,
199,
504,
10380,
14,
23004,
492,
29393,
12,
22170,
379,
21365,
12,
21391,
12,
971,
1362,
3447,
1489,
9883,
12,
25609,
21365,
12,
25609,
804,
20403,
2141,
12,
971,
1362,
25609,
1296,
12,
14735,
8422,
12,
29392,
8422,
12,
8466,
8422,
12,
971,
1362,
7232,
4437,
3717,
12,
4784,
4437,
3717,
12,
17555,
2141,
12,
971,
1362,
6646,
4709,
12,
2740,
63,
3029,
63,
1744,
199,
504,
10380,
423,
4672,
492,
485,
362,
63,
2314,
199,
504,
10380,
423,
5819,
492,
370,
63,
2394,
12,
1059,
63,
1313,
12,
1318,
63,
466,
12,
971,
1362,
3000,
63,
1313,
12,
12464,
63,
12796,
63,
20327,
12,
12464,
63,
362,
63,
2394,
12,
971,
1362,
370,
63,
2975,
12,
370,
63,
6106,
12,
11808,
421,
199,
318,
485,
1065,
63,
6508,
63,
571,
2031,
589,
304,
272,
408,
2765,
805,
19058,
6337,
370,
4868,
626,
314,
511,
859,
365,
440,
272,
8439,
7444,
1415,
14,
221,
3506,
2845,
4815,
1,
272,
408,
272,
2288,
485,
1065,
63,
6508,
63,
571,
272,
687,
10380,
14,
396,
492,
1255,
63,
6508,
63,
571,
465,
485,
1065,
63,
6508,
63,
571,
272,
372,
485,
1065,
63,
6508,
63,
571,
2031,
589,
9,
421,
199,
318,
485,
4050,
63,
692,
63,
875,
8,
8147,
304,
272,
408,
4433,
367,
314,
1177,
2251,
370,
1104,
340,
314,
6076,
2138,
272,
370,
314,
9279,
1654,
365,
440,
282,
1059,
14,
272,
408,
272,
340,
1228,
8,
8147,
12,
1059,
63,
1313,
304,
267,
687,
3598,
492,
7987,
267,
7987,
8,
3849,
360,
1310,
6076,
1990,
663,
370,
282,
1059,
14,
221,
961,
11337,
283,
2151,
283,
475,
1736,
1325,
4910,
626,
314,
1654,
911,
3222,
314,
283,
2151,
283,
576,
370,
314,
1890,
1495,
12,
701,
1495,
14,
221,
961,
365,
18871,
283,
2151,
283,
18178,
11619,
5953,
12,
675,
1177,
14,
576,
370,
5090,
283,
2151,
283,
5465,
370,
314,
1177,
909,
8038,
13232,
29,
18,
9,
421,
199,
318,
485,
479,
63,
1397,
63,
609,
3306,
8,
1069,
304,
272,
340,
1056,
14,
609,
3306,
26,
267,
746,
6064,
360,
33,
23834,
1056,
16416,
370,
9451,
283,
2574,
283,
964,
666,
14,
221,
982,
1265,
7710,
2934,
370,
886,
283,
2574,
283,
9099,
12,
663,
658,
609,
3306,
64,
370,
756,
2659,
421,
199,
318,
485,
1661,
63,
8167,
8,
8147,
12,
5960,
304,
272,
367,
1242,
315,
6076,
26,
267,
340,
1228,
8,
1053,
12,
1318,
63,
466,
304,
288,
1995,
1242,
14,
2143,
8,
6043,
9,
267,
587,
26,
288,
1995,
1242,
421,
199,
533,
3523,
2017,
8,
785,
304,
272,
408,
54,
994,
5678,
1056,
909,
14,
221,
961,
1630,
440,
5669,
19472,
8292,
2839,
272,
4642,
1947,
6057,
503,
2581,
13467,
14,
221,
710,
1056,
909,
365,
2737,
543,
272,
314,
9279,
3734,
465,
1642,
1423,
436,
911,
1050,
6337,
370,
314,
9279,
272,
3734,
465,
12692,
17719,
14,
1069,
14700,
7444,
652,
1159,
2737,
543,
272,
658,
13817,
63,
1069,
64,
663,
370,
756,
14,
339,
6006,
787,
282,
17535,
402,
13667,
3617,
2808,
626,
1050,
4722,
9330,
272,
370,
314,
1056,
909,
12,
2337,
365,
2597,
282,
1021,
2797,
658,
2017,
64,
1314,
272,
9180,
658,
1563,
2017,
64,
436,
1006,
314,
11012,
13667,
3617,
14,
339,
2779,
1159,
282,
6954,
16819,
370,
1218,
282,
3537,
5516,
402,
314,
520,
533,
1705,
1563,
2017,
64,
272,
436,
1050,
4124,
9330,
1902,
4799,
13667,
3617,
503,
4125,
4514,
14,
272,
11842,
376,
2893,
367,
4066,
9180,
447,
398,
687,
10380,
14,
21148,
492,
3523,
2017,
12,
662,
1931,
2017,
4256,
398,
1021
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
10380,
14,
21148,
272,
18294,
94,
339,
710,
17995,
787,
3486,
1056,
436,
1177,
2251,
1314,
1265,
883,
272,
5516,
370,
886,
15685,
1265,
2934,
3062,
370,
886,
14,
221,
710,
1056,
909,
3509,
272,
314,
2556,
29818,
701,
314,
1890,
334,
1129,
29063,
9,
436,
314,
1177,
272,
909,
3509,
1006,
314,
2556,
4847,
1771,
370,
314,
7042,
14,
339,
1626,
11012,
10093,
365,
626,
314,
1056,
909,
365,
2737,
543,
314,
9279,
272,
6160,
436,
911,
2454,
465,
4721,
13,
1896,
4566,
29781,
314,
1177,
909,
365,
376,
272,
3503,
9279,
4223,
14,
339,
16485,
8137,
587,
315,
22798,
3520,
2251,
911,
1736,
6657,
543,
272,
2649,
666,
14,
221,
1010,
7909,
1824,
666,
4565,
701,
314,
1177,
909,
911,
506,
272,
11203,
1901,
376,
2649,
909,
340,
3962,
436,
340,
652,
7704,
12249,
14,
2378,
520,
7307,
26,
334,
67,
9,
6927,
701,
314,
22798,
11682,
12,
1937,
10610,
367,
1655,
2436,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
624,
199,
504,
9143,
492,
1678,
63,
5029,
199,
504,
2197,
492,
2197,
12,
6871,
199,
199,
504,
10380,
14,
1014,
492,
3101,
63,
6305,
63,
15639,
12,
971,
1362,
2198,
63,
5694,
63,
1291,
12,
2198,
63,
1637,
63,
2785,
63,
1291,
12,
2198,
63,
1841,
458,
12,
971,
1362,
2198,
63,
602,
12,
3550,
63,
11304,
12,
365,
63,
1927,
63,
5540,
12,
14342,
63,
11304,
12,
971,
1362,
6313,
63,
11304,
12,
2198,
63,
409,
63,
1291,
12,
2198,
63,
15846,
63,
1291,
12,
971,
1362,
2198,
63,
1544,
63,
13975,
63,
1291,
12,
2813,
63,
4502,
63,
2139,
12,
971,
1362,
2198,
63,
1419,
63,
1291,
12,
5461,
63,
1419,
63,
1291,
12,
1455,
63,
602,
12,
971,
1362,
2198,
63,
692,
63,
1842,
63,
1291,
12,
2198,
63,
5306,
12,
5461,
63,
5306,
12,
971,
1362,
2198,
63,
1842,
63,
1291,
12,
2198,
63,
1317,
63,
1842,
63,
1291,
12,
5461,
63,
1291,
199,
504,
10380,
14,
3603,
492,
1166,
63,
2708,
12,
24086,
63,
475,
63,
2302,
12,
1166,
63,
904,
199,
504,
10380,
14,
509,
311,
285,
332,
492,
8204,
1451,
2842,
12,
849,
63,
1745,
63,
3702,
199,
504,
10380,
14,
1208,
492,
6328,
63,
1829,
12,
6160,
63,
1829,
12,
971,
1362,
1406,
63,
1829,
12,
664,
63,
1317,
63,
466,
199,
504,
10380,
14,
6508,
492,
664,
63,
1818,
63,
633,
12,
664,
63,
1102,
12,
971,
1362,
5980,
1044,
3585,
12,
664,
63,
1210,
63,
1745,
12,
664,
63,
1317,
63,
1267,
199,
504,
10380,
14,
23004,
492,
29393,
12,
22170,
379,
21365,
12,
21391,
12,
971,
1362,
3447,
1489,
9883,
12,
25609,
21365,
12,
25609,
804,
20403,
2141,
12,
971,
1362,
25609,
1296,
12,
14735,
8422,
12,
29392,
8422,
12,
8466,
8422,
12,
971,
1362,
7232,
4437,
3717,
12,
4784,
4437,
3717,
12,
17555,
2141,
12,
971,
1362,
6646,
4709,
12,
2740,
63,
3029,
63,
1744,
199,
504,
10380,
423,
4672,
492,
485,
362,
63,
2314,
199,
504,
10380,
423,
5819,
492,
370,
63,
2394,
12,
1059,
63,
1313,
12,
1318,
63,
466,
12,
971,
1362,
3000,
63,
1313,
12,
12464,
63,
12796,
63,
20327,
12,
12464,
63,
362,
63,
2394,
12,
971,
1362,
370,
63,
2975,
12,
370,
63,
6106,
12,
11808,
421,
199,
318,
485,
1065,
63,
6508,
63,
571,
2031,
589,
304,
272,
408,
2765,
805,
19058,
6337,
370,
4868,
626,
314,
511,
859,
365,
440,
272,
8439,
7444,
1415,
14,
221,
3506,
2845,
4815,
1,
272,
408,
272,
2288,
485,
1065,
63,
6508,
63,
571,
272,
687,
10380,
14,
396,
492,
1255,
63,
6508,
63,
571,
465,
485,
1065,
63,
6508,
63,
571,
272,
372,
485,
1065,
63,
6508,
63,
571,
2031,
589,
9,
421,
199,
318,
485,
4050,
63,
692,
63,
875,
8,
8147,
304,
272,
408,
4433,
367,
314,
1177,
2251,
370,
1104,
340,
314,
6076,
2138,
272,
370,
314,
9279,
1654,
365,
440,
282,
1059,
14,
272,
408,
272,
340,
1228,
8,
8147,
12,
1059,
63,
1313,
304,
267,
687,
3598,
492,
7987,
267,
7987,
8,
3849,
360,
1310,
6076,
1990,
663,
370,
282,
1059,
14,
221,
961,
11337,
283,
2151,
283,
475,
1736,
1325,
4910,
626,
314,
1654,
911,
3222,
314,
283,
2151,
283,
576,
370,
314,
1890,
1495,
12,
701,
1495,
14,
221,
961,
365,
18871,
283,
2151,
283,
18178,
11619,
5953,
12,
675,
1177,
14,
576,
370,
5090,
283,
2151,
283,
5465,
370,
314,
1177,
909,
8038,
13232,
29,
18,
9,
421,
199,
318,
485,
479,
63,
1397,
63,
609,
3306,
8,
1069,
304,
272,
340,
1056,
14,
609,
3306,
26,
267,
746,
6064,
360,
33,
23834,
1056,
16416,
370,
9451,
283,
2574,
283,
964,
666,
14,
221,
982,
1265,
7710,
2934,
370,
886,
283,
2574,
283,
9099,
12,
663,
658,
609,
3306,
64,
370,
756,
2659,
421,
199,
318,
485,
1661,
63,
8167,
8,
8147,
12,
5960,
304,
272,
367,
1242,
315,
6076,
26,
267,
340,
1228,
8,
1053,
12,
1318,
63,
466,
304,
288,
1995,
1242,
14,
2143,
8,
6043,
9,
267,
587,
26,
288,
1995,
1242,
421,
199,
533,
3523,
2017,
8,
785,
304,
272,
408,
54,
994,
5678,
1056,
909,
14,
221,
961,
1630,
440,
5669,
19472,
8292,
2839,
272,
4642,
1947,
6057,
503,
2581,
13467,
14,
221,
710,
1056,
909,
365,
2737,
543,
272,
314,
9279,
3734,
465,
1642,
1423,
436,
911,
1050,
6337,
370,
314,
9279,
272,
3734,
465,
12692,
17719,
14,
1069,
14700,
7444,
652,
1159,
2737,
543,
272,
658,
13817,
63,
1069,
64,
663,
370,
756,
14,
339,
6006,
787,
282,
17535,
402,
13667,
3617,
2808,
626,
1050,
4722,
9330,
272,
370,
314,
1056,
909,
12,
2337,
365,
2597,
282,
1021,
2797,
658,
2017,
64,
1314,
272,
9180,
658,
1563,
2017,
64,
436,
1006,
314,
11012,
13667,
3617,
14,
339,
2779,
1159,
282,
6954,
16819,
370,
1218,
282,
3537,
5516,
402,
314,
520,
533,
1705,
1563,
2017,
64,
272,
436,
1050,
4124,
9330,
1902,
4799,
13667,
3617,
503,
4125,
4514,
14,
272,
11842,
376,
2893,
367,
4066,
9180,
447,
398,
687,
10380,
14,
21148,
492,
3523,
2017,
12,
662,
1931,
2017,
4256,
398,
1021,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
googleapis/python-aiplatform
|
google/cloud/aiplatform_v1/services/job_service/transports/grpc_asyncio.py
|
1
|
39034
|
# -*- coding: utf-8 -*-
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import warnings
from typing import Awaitable, Callable, Dict, Optional, Sequence, Tuple, Union
from google.api_core import gapic_v1 # type: ignore
from google.api_core import grpc_helpers_async # type: ignore
from google.api_core import operations_v1 # type: ignore
from google.auth import credentials as ga_credentials # type: ignore
from google.auth.transport.grpc import SslCredentials # type: ignore
import packaging.version
import grpc # type: ignore
from grpc.experimental import aio # type: ignore
from google.cloud.aiplatform_v1.types import batch_prediction_job
from google.cloud.aiplatform_v1.types import (
batch_prediction_job as gca_batch_prediction_job,
)
from google.cloud.aiplatform_v1.types import custom_job
from google.cloud.aiplatform_v1.types import custom_job as gca_custom_job
from google.cloud.aiplatform_v1.types import data_labeling_job
from google.cloud.aiplatform_v1.types import data_labeling_job as gca_data_labeling_job
from google.cloud.aiplatform_v1.types import hyperparameter_tuning_job
from google.cloud.aiplatform_v1.types import (
hyperparameter_tuning_job as gca_hyperparameter_tuning_job,
)
from google.cloud.aiplatform_v1.types import job_service
from google.longrunning import operations_pb2 # type: ignore
from google.protobuf import empty_pb2 # type: ignore
from .base import JobServiceTransport, DEFAULT_CLIENT_INFO
from .grpc import JobServiceGrpcTransport
class JobServiceGrpcAsyncIOTransport(JobServiceTransport):
"""gRPC AsyncIO backend transport for JobService.
A service for creating and managing Vertex AI's jobs.
This class defines the same methods as the primary client, so the
primary client can load the underlying transport implementation
and call it.
It sends protocol buffers over the wire using gRPC (which is built on
top of HTTP/2); the ``grpcio`` package must be installed.
"""
_grpc_channel: aio.Channel
_stubs: Dict[str, Callable] = {}
@classmethod
def create_channel(
cls,
host: str = "aiplatform.googleapis.com",
credentials: ga_credentials.Credentials = None,
credentials_file: Optional[str] = None,
scopes: Optional[Sequence[str]] = None,
quota_project_id: Optional[str] = None,
**kwargs,
) -> aio.Channel:
"""Create and return a gRPC AsyncIO channel object.
Args:
host (Optional[str]): The host for the channel to use.
credentials (Optional[~.Credentials]): The
authorization credentials to attach to requests. These
credentials identify this application to the service. If
none are specified, the client will attempt to ascertain
the credentials from the environment.
credentials_file (Optional[str]): A file with credentials that can
be loaded with :func:`google.auth.load_credentials_from_file`.
This argument is ignored if ``channel`` is provided.
scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
service. These are only used when credentials are not specified and
are passed to :func:`google.auth.default`.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
kwargs (Optional[dict]): Keyword arguments, which are passed to the
channel creation.
Returns:
aio.Channel: A gRPC AsyncIO channel object.
"""
self_signed_jwt_kwargs = cls._get_self_signed_jwt_kwargs(host, scopes)
return grpc_helpers_async.create_channel(
host,
credentials=credentials,
credentials_file=credentials_file,
quota_project_id=quota_project_id,
**self_signed_jwt_kwargs,
**kwargs,
)
def __init__(
self,
*,
host: str = "aiplatform.googleapis.com",
credentials: ga_credentials.Credentials = None,
credentials_file: Optional[str] = None,
scopes: Optional[Sequence[str]] = None,
channel: aio.Channel = None,
api_mtls_endpoint: str = None,
client_cert_source: Callable[[], Tuple[bytes, bytes]] = None,
ssl_channel_credentials: grpc.ChannelCredentials = None,
client_cert_source_for_mtls: Callable[[], Tuple[bytes, bytes]] = None,
quota_project_id=None,
client_info: gapic_v1.client_info.ClientInfo = DEFAULT_CLIENT_INFO,
) -> None:
"""Instantiate the transport.
Args:
host (Optional[str]):
The hostname to connect to.
credentials (Optional[google.auth.credentials.Credentials]): The
authorization credentials to attach to requests. These
credentials identify the application to the service; if none
are specified, the client will attempt to ascertain the
credentials from the environment.
This argument is ignored if ``channel`` is provided.
credentials_file (Optional[str]): A file with credentials that can
be loaded with :func:`google.auth.load_credentials_from_file`.
This argument is ignored if ``channel`` is provided.
scopes (Optional[Sequence[str]]): A optional list of scopes needed for this
service. These are only used when credentials are not specified and
are passed to :func:`google.auth.default`.
channel (Optional[aio.Channel]): A ``Channel`` instance through
which to make calls.
api_mtls_endpoint (Optional[str]): Deprecated. The mutual TLS endpoint.
If provided, it overrides the ``host`` argument and tries to create
a mutual TLS channel with client SSL credentials from
``client_cert_source`` or applicatin default SSL credentials.
client_cert_source (Optional[Callable[[], Tuple[bytes, bytes]]]):
Deprecated. A callback to provide client SSL certificate bytes and
private key bytes, both in PEM format. It is ignored if
``api_mtls_endpoint`` is None.
ssl_channel_credentials (grpc.ChannelCredentials): SSL credentials
for grpc channel. It is ignored if ``channel`` is provided.
client_cert_source_for_mtls (Optional[Callable[[], Tuple[bytes, bytes]]]):
A callback to provide client certificate bytes and private key bytes,
both in PEM format. It is used to configure mutual TLS channel. It is
ignored if ``channel`` or ``ssl_channel_credentials`` is provided.
quota_project_id (Optional[str]): An optional project to use for billing
and quota.
client_info (google.api_core.gapic_v1.client_info.ClientInfo):
The client info used to send a user-agent string along with
API requests. If ``None``, then default info will be used.
Generally, you only need to set this if you're developing
your own client library.
Raises:
google.auth.exceptions.MutualTlsChannelError: If mutual TLS transport
creation failed for any reason.
google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials``
and ``credentials_file`` are passed.
"""
self._grpc_channel = None
self._ssl_channel_credentials = ssl_channel_credentials
self._stubs: Dict[str, Callable] = {}
self._operations_client = None
if api_mtls_endpoint:
warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning)
if client_cert_source:
warnings.warn("client_cert_source is deprecated", DeprecationWarning)
if channel:
# Ignore credentials if a channel was passed.
credentials = False
# If a channel was explicitly provided, set it.
self._grpc_channel = channel
self._ssl_channel_credentials = None
else:
if api_mtls_endpoint:
host = api_mtls_endpoint
# Create SSL credentials with client_cert_source or application
# default SSL credentials.
if client_cert_source:
cert, key = client_cert_source()
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
certificate_chain=cert, private_key=key
)
else:
self._ssl_channel_credentials = SslCredentials().ssl_credentials
else:
if client_cert_source_for_mtls and not ssl_channel_credentials:
cert, key = client_cert_source_for_mtls()
self._ssl_channel_credentials = grpc.ssl_channel_credentials(
certificate_chain=cert, private_key=key
)
# The base transport sets the host, credentials and scopes
super().__init__(
host=host,
credentials=credentials,
credentials_file=credentials_file,
scopes=scopes,
quota_project_id=quota_project_id,
client_info=client_info,
)
if not self._grpc_channel:
self._grpc_channel = type(self).create_channel(
self._host,
credentials=self._credentials,
credentials_file=credentials_file,
scopes=self._scopes,
ssl_credentials=self._ssl_channel_credentials,
quota_project_id=quota_project_id,
options=[
("grpc.max_send_message_length", -1),
("grpc.max_receive_message_length", -1),
],
)
# Wrap messages. This must be done after self._grpc_channel exists
self._prep_wrapped_messages(client_info)
@property
def grpc_channel(self) -> aio.Channel:
"""Create the channel designed to connect to this service.
This property caches on the instance; repeated calls return
the same channel.
"""
# Return the channel from cache.
return self._grpc_channel
@property
def operations_client(self) -> operations_v1.OperationsAsyncClient:
"""Create the client designed to process long-running operations.
This property caches on the instance; repeated calls return the same
client.
"""
# Sanity check: Only create a new client if we do not already have one.
if self._operations_client is None:
self._operations_client = operations_v1.OperationsAsyncClient(
self.grpc_channel
)
# Return the client from cache.
return self._operations_client
@property
def create_custom_job(
self,
) -> Callable[
[job_service.CreateCustomJobRequest], Awaitable[gca_custom_job.CustomJob]
]:
r"""Return a callable for the create custom job method over gRPC.
Creates a CustomJob. A created CustomJob right away
will be attempted to be run.
Returns:
Callable[[~.CreateCustomJobRequest],
Awaitable[~.CustomJob]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "create_custom_job" not in self._stubs:
self._stubs["create_custom_job"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/CreateCustomJob",
request_serializer=job_service.CreateCustomJobRequest.serialize,
response_deserializer=gca_custom_job.CustomJob.deserialize,
)
return self._stubs["create_custom_job"]
@property
def get_custom_job(
self,
) -> Callable[[job_service.GetCustomJobRequest], Awaitable[custom_job.CustomJob]]:
r"""Return a callable for the get custom job method over gRPC.
Gets a CustomJob.
Returns:
Callable[[~.GetCustomJobRequest],
Awaitable[~.CustomJob]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "get_custom_job" not in self._stubs:
self._stubs["get_custom_job"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/GetCustomJob",
request_serializer=job_service.GetCustomJobRequest.serialize,
response_deserializer=custom_job.CustomJob.deserialize,
)
return self._stubs["get_custom_job"]
@property
def list_custom_jobs(
self,
) -> Callable[
[job_service.ListCustomJobsRequest],
Awaitable[job_service.ListCustomJobsResponse],
]:
r"""Return a callable for the list custom jobs method over gRPC.
Lists CustomJobs in a Location.
Returns:
Callable[[~.ListCustomJobsRequest],
Awaitable[~.ListCustomJobsResponse]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "list_custom_jobs" not in self._stubs:
self._stubs["list_custom_jobs"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/ListCustomJobs",
request_serializer=job_service.ListCustomJobsRequest.serialize,
response_deserializer=job_service.ListCustomJobsResponse.deserialize,
)
return self._stubs["list_custom_jobs"]
@property
def delete_custom_job(
self,
) -> Callable[
[job_service.DeleteCustomJobRequest], Awaitable[operations_pb2.Operation]
]:
r"""Return a callable for the delete custom job method over gRPC.
Deletes a CustomJob.
Returns:
Callable[[~.DeleteCustomJobRequest],
Awaitable[~.Operation]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "delete_custom_job" not in self._stubs:
self._stubs["delete_custom_job"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/DeleteCustomJob",
request_serializer=job_service.DeleteCustomJobRequest.serialize,
response_deserializer=operations_pb2.Operation.FromString,
)
return self._stubs["delete_custom_job"]
@property
def cancel_custom_job(
self,
) -> Callable[[job_service.CancelCustomJobRequest], Awaitable[empty_pb2.Empty]]:
r"""Return a callable for the cancel custom job method over gRPC.
Cancels a CustomJob. Starts asynchronous cancellation on the
CustomJob. The server makes a best effort to cancel the job, but
success is not guaranteed. Clients can use
[JobService.GetCustomJob][google.cloud.aiplatform.v1.JobService.GetCustomJob]
or other methods to check whether the cancellation succeeded or
whether the job completed despite cancellation. On successful
cancellation, the CustomJob is not deleted; instead it becomes a
job with a
[CustomJob.error][google.cloud.aiplatform.v1.CustomJob.error]
value with a [google.rpc.Status.code][google.rpc.Status.code] of
1, corresponding to ``Code.CANCELLED``, and
[CustomJob.state][google.cloud.aiplatform.v1.CustomJob.state] is
set to ``CANCELLED``.
Returns:
Callable[[~.CancelCustomJobRequest],
Awaitable[~.Empty]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "cancel_custom_job" not in self._stubs:
self._stubs["cancel_custom_job"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/CancelCustomJob",
request_serializer=job_service.CancelCustomJobRequest.serialize,
response_deserializer=empty_pb2.Empty.FromString,
)
return self._stubs["cancel_custom_job"]
@property
def create_data_labeling_job(
self,
) -> Callable[
[job_service.CreateDataLabelingJobRequest],
Awaitable[gca_data_labeling_job.DataLabelingJob],
]:
r"""Return a callable for the create data labeling job method over gRPC.
Creates a DataLabelingJob.
Returns:
Callable[[~.CreateDataLabelingJobRequest],
Awaitable[~.DataLabelingJob]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "create_data_labeling_job" not in self._stubs:
self._stubs["create_data_labeling_job"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/CreateDataLabelingJob",
request_serializer=job_service.CreateDataLabelingJobRequest.serialize,
response_deserializer=gca_data_labeling_job.DataLabelingJob.deserialize,
)
return self._stubs["create_data_labeling_job"]
@property
def get_data_labeling_job(
self,
) -> Callable[
[job_service.GetDataLabelingJobRequest],
Awaitable[data_labeling_job.DataLabelingJob],
]:
r"""Return a callable for the get data labeling job method over gRPC.
Gets a DataLabelingJob.
Returns:
Callable[[~.GetDataLabelingJobRequest],
Awaitable[~.DataLabelingJob]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "get_data_labeling_job" not in self._stubs:
self._stubs["get_data_labeling_job"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/GetDataLabelingJob",
request_serializer=job_service.GetDataLabelingJobRequest.serialize,
response_deserializer=data_labeling_job.DataLabelingJob.deserialize,
)
return self._stubs["get_data_labeling_job"]
@property
def list_data_labeling_jobs(
self,
) -> Callable[
[job_service.ListDataLabelingJobsRequest],
Awaitable[job_service.ListDataLabelingJobsResponse],
]:
r"""Return a callable for the list data labeling jobs method over gRPC.
Lists DataLabelingJobs in a Location.
Returns:
Callable[[~.ListDataLabelingJobsRequest],
Awaitable[~.ListDataLabelingJobsResponse]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "list_data_labeling_jobs" not in self._stubs:
self._stubs["list_data_labeling_jobs"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/ListDataLabelingJobs",
request_serializer=job_service.ListDataLabelingJobsRequest.serialize,
response_deserializer=job_service.ListDataLabelingJobsResponse.deserialize,
)
return self._stubs["list_data_labeling_jobs"]
@property
def delete_data_labeling_job(
self,
) -> Callable[
[job_service.DeleteDataLabelingJobRequest], Awaitable[operations_pb2.Operation]
]:
r"""Return a callable for the delete data labeling job method over gRPC.
Deletes a DataLabelingJob.
Returns:
Callable[[~.DeleteDataLabelingJobRequest],
Awaitable[~.Operation]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "delete_data_labeling_job" not in self._stubs:
self._stubs["delete_data_labeling_job"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/DeleteDataLabelingJob",
request_serializer=job_service.DeleteDataLabelingJobRequest.serialize,
response_deserializer=operations_pb2.Operation.FromString,
)
return self._stubs["delete_data_labeling_job"]
@property
def cancel_data_labeling_job(
self,
) -> Callable[
[job_service.CancelDataLabelingJobRequest], Awaitable[empty_pb2.Empty]
]:
r"""Return a callable for the cancel data labeling job method over gRPC.
Cancels a DataLabelingJob. Success of cancellation is
not guaranteed.
Returns:
Callable[[~.CancelDataLabelingJobRequest],
Awaitable[~.Empty]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "cancel_data_labeling_job" not in self._stubs:
self._stubs["cancel_data_labeling_job"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/CancelDataLabelingJob",
request_serializer=job_service.CancelDataLabelingJobRequest.serialize,
response_deserializer=empty_pb2.Empty.FromString,
)
return self._stubs["cancel_data_labeling_job"]
@property
def create_hyperparameter_tuning_job(
self,
) -> Callable[
[job_service.CreateHyperparameterTuningJobRequest],
Awaitable[gca_hyperparameter_tuning_job.HyperparameterTuningJob],
]:
r"""Return a callable for the create hyperparameter tuning
job method over gRPC.
Creates a HyperparameterTuningJob
Returns:
Callable[[~.CreateHyperparameterTuningJobRequest],
Awaitable[~.HyperparameterTuningJob]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "create_hyperparameter_tuning_job" not in self._stubs:
self._stubs[
"create_hyperparameter_tuning_job"
] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/CreateHyperparameterTuningJob",
request_serializer=job_service.CreateHyperparameterTuningJobRequest.serialize,
response_deserializer=gca_hyperparameter_tuning_job.HyperparameterTuningJob.deserialize,
)
return self._stubs["create_hyperparameter_tuning_job"]
@property
def get_hyperparameter_tuning_job(
self,
) -> Callable[
[job_service.GetHyperparameterTuningJobRequest],
Awaitable[hyperparameter_tuning_job.HyperparameterTuningJob],
]:
r"""Return a callable for the get hyperparameter tuning job method over gRPC.
Gets a HyperparameterTuningJob
Returns:
Callable[[~.GetHyperparameterTuningJobRequest],
Awaitable[~.HyperparameterTuningJob]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "get_hyperparameter_tuning_job" not in self._stubs:
self._stubs[
"get_hyperparameter_tuning_job"
] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/GetHyperparameterTuningJob",
request_serializer=job_service.GetHyperparameterTuningJobRequest.serialize,
response_deserializer=hyperparameter_tuning_job.HyperparameterTuningJob.deserialize,
)
return self._stubs["get_hyperparameter_tuning_job"]
@property
def list_hyperparameter_tuning_jobs(
self,
) -> Callable[
[job_service.ListHyperparameterTuningJobsRequest],
Awaitable[job_service.ListHyperparameterTuningJobsResponse],
]:
r"""Return a callable for the list hyperparameter tuning
jobs method over gRPC.
Lists HyperparameterTuningJobs in a Location.
Returns:
Callable[[~.ListHyperparameterTuningJobsRequest],
Awaitable[~.ListHyperparameterTuningJobsResponse]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "list_hyperparameter_tuning_jobs" not in self._stubs:
self._stubs[
"list_hyperparameter_tuning_jobs"
] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/ListHyperparameterTuningJobs",
request_serializer=job_service.ListHyperparameterTuningJobsRequest.serialize,
response_deserializer=job_service.ListHyperparameterTuningJobsResponse.deserialize,
)
return self._stubs["list_hyperparameter_tuning_jobs"]
@property
def delete_hyperparameter_tuning_job(
self,
) -> Callable[
[job_service.DeleteHyperparameterTuningJobRequest],
Awaitable[operations_pb2.Operation],
]:
r"""Return a callable for the delete hyperparameter tuning
job method over gRPC.
Deletes a HyperparameterTuningJob.
Returns:
Callable[[~.DeleteHyperparameterTuningJobRequest],
Awaitable[~.Operation]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "delete_hyperparameter_tuning_job" not in self._stubs:
self._stubs[
"delete_hyperparameter_tuning_job"
] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/DeleteHyperparameterTuningJob",
request_serializer=job_service.DeleteHyperparameterTuningJobRequest.serialize,
response_deserializer=operations_pb2.Operation.FromString,
)
return self._stubs["delete_hyperparameter_tuning_job"]
@property
def cancel_hyperparameter_tuning_job(
self,
) -> Callable[
[job_service.CancelHyperparameterTuningJobRequest], Awaitable[empty_pb2.Empty]
]:
r"""Return a callable for the cancel hyperparameter tuning
job method over gRPC.
Cancels a HyperparameterTuningJob. Starts asynchronous
cancellation on the HyperparameterTuningJob. The server makes a
best effort to cancel the job, but success is not guaranteed.
Clients can use
[JobService.GetHyperparameterTuningJob][google.cloud.aiplatform.v1.JobService.GetHyperparameterTuningJob]
or other methods to check whether the cancellation succeeded or
whether the job completed despite cancellation. On successful
cancellation, the HyperparameterTuningJob is not deleted;
instead it becomes a job with a
[HyperparameterTuningJob.error][google.cloud.aiplatform.v1.HyperparameterTuningJob.error]
value with a [google.rpc.Status.code][google.rpc.Status.code] of
1, corresponding to ``Code.CANCELLED``, and
[HyperparameterTuningJob.state][google.cloud.aiplatform.v1.HyperparameterTuningJob.state]
is set to ``CANCELLED``.
Returns:
Callable[[~.CancelHyperparameterTuningJobRequest],
Awaitable[~.Empty]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "cancel_hyperparameter_tuning_job" not in self._stubs:
self._stubs[
"cancel_hyperparameter_tuning_job"
] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/CancelHyperparameterTuningJob",
request_serializer=job_service.CancelHyperparameterTuningJobRequest.serialize,
response_deserializer=empty_pb2.Empty.FromString,
)
return self._stubs["cancel_hyperparameter_tuning_job"]
@property
def create_batch_prediction_job(
self,
) -> Callable[
[job_service.CreateBatchPredictionJobRequest],
Awaitable[gca_batch_prediction_job.BatchPredictionJob],
]:
r"""Return a callable for the create batch prediction job method over gRPC.
Creates a BatchPredictionJob. A BatchPredictionJob
once created will right away be attempted to start.
Returns:
Callable[[~.CreateBatchPredictionJobRequest],
Awaitable[~.BatchPredictionJob]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "create_batch_prediction_job" not in self._stubs:
self._stubs["create_batch_prediction_job"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/CreateBatchPredictionJob",
request_serializer=job_service.CreateBatchPredictionJobRequest.serialize,
response_deserializer=gca_batch_prediction_job.BatchPredictionJob.deserialize,
)
return self._stubs["create_batch_prediction_job"]
@property
def get_batch_prediction_job(
self,
) -> Callable[
[job_service.GetBatchPredictionJobRequest],
Awaitable[batch_prediction_job.BatchPredictionJob],
]:
r"""Return a callable for the get batch prediction job method over gRPC.
Gets a BatchPredictionJob
Returns:
Callable[[~.GetBatchPredictionJobRequest],
Awaitable[~.BatchPredictionJob]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "get_batch_prediction_job" not in self._stubs:
self._stubs["get_batch_prediction_job"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/GetBatchPredictionJob",
request_serializer=job_service.GetBatchPredictionJobRequest.serialize,
response_deserializer=batch_prediction_job.BatchPredictionJob.deserialize,
)
return self._stubs["get_batch_prediction_job"]
@property
def list_batch_prediction_jobs(
self,
) -> Callable[
[job_service.ListBatchPredictionJobsRequest],
Awaitable[job_service.ListBatchPredictionJobsResponse],
]:
r"""Return a callable for the list batch prediction jobs method over gRPC.
Lists BatchPredictionJobs in a Location.
Returns:
Callable[[~.ListBatchPredictionJobsRequest],
Awaitable[~.ListBatchPredictionJobsResponse]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "list_batch_prediction_jobs" not in self._stubs:
self._stubs["list_batch_prediction_jobs"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/ListBatchPredictionJobs",
request_serializer=job_service.ListBatchPredictionJobsRequest.serialize,
response_deserializer=job_service.ListBatchPredictionJobsResponse.deserialize,
)
return self._stubs["list_batch_prediction_jobs"]
@property
def delete_batch_prediction_job(
self,
) -> Callable[
[job_service.DeleteBatchPredictionJobRequest],
Awaitable[operations_pb2.Operation],
]:
r"""Return a callable for the delete batch prediction job method over gRPC.
Deletes a BatchPredictionJob. Can only be called on
jobs that already finished.
Returns:
Callable[[~.DeleteBatchPredictionJobRequest],
Awaitable[~.Operation]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "delete_batch_prediction_job" not in self._stubs:
self._stubs["delete_batch_prediction_job"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/DeleteBatchPredictionJob",
request_serializer=job_service.DeleteBatchPredictionJobRequest.serialize,
response_deserializer=operations_pb2.Operation.FromString,
)
return self._stubs["delete_batch_prediction_job"]
@property
def cancel_batch_prediction_job(
self,
) -> Callable[
[job_service.CancelBatchPredictionJobRequest], Awaitable[empty_pb2.Empty]
]:
r"""Return a callable for the cancel batch prediction job method over gRPC.
Cancels a BatchPredictionJob.
Starts asynchronous cancellation on the BatchPredictionJob. The
server makes the best effort to cancel the job, but success is
not guaranteed. Clients can use
[JobService.GetBatchPredictionJob][google.cloud.aiplatform.v1.JobService.GetBatchPredictionJob]
or other methods to check whether the cancellation succeeded or
whether the job completed despite cancellation. On a successful
cancellation, the BatchPredictionJob is not deleted;instead its
[BatchPredictionJob.state][google.cloud.aiplatform.v1.BatchPredictionJob.state]
is set to ``CANCELLED``. Any files already outputted by the job
are not deleted.
Returns:
Callable[[~.CancelBatchPredictionJobRequest],
Awaitable[~.Empty]]:
A function that, when called, will call the underlying RPC
on the server.
"""
# Generate a "stub function" on-the-fly which will actually make
# the request.
# gRPC handles serialization and deserialization, so we just need
# to pass in the functions for each.
if "cancel_batch_prediction_job" not in self._stubs:
self._stubs["cancel_batch_prediction_job"] = self.grpc_channel.unary_unary(
"/google.cloud.aiplatform.v1.JobService/CancelBatchPredictionJob",
request_serializer=job_service.CancelBatchPredictionJobRequest.serialize,
response_deserializer=empty_pb2.Empty.FromString,
)
return self._stubs["cancel_batch_prediction_job"]
__all__ = ("JobServiceGrpcAsyncIOTransport",)
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
25455,
4475,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
646,
3598,
199,
504,
14090,
492,
437,
2573,
461,
12,
16975,
12,
7448,
12,
4879,
12,
10975,
12,
11634,
12,
15961,
199,
199,
504,
6233,
14,
1246,
63,
1018,
492,
16301,
530,
63,
86,
17,
221,
327,
730,
26,
3686,
199,
504,
6233,
14,
1246,
63,
1018,
492,
19753,
63,
7546,
63,
4146,
221,
327,
730,
26,
3686,
199,
504,
6233,
14,
1246,
63,
1018,
492,
5331,
63,
86,
17,
221,
327,
730,
26,
3686,
199,
504,
6233,
14,
1178,
492,
6235,
465,
16072,
63,
6942,
221,
327,
730,
26,
3686,
199,
504,
6233,
14,
1178,
14,
5545,
14,
15391,
492,
428,
2482,
13428,
221,
327,
730,
26,
3686,
199,
646,
27369,
14,
1023,
199,
199,
646,
19753,
221,
327,
730,
26,
3686,
199,
504,
19753,
14,
18924,
492,
282,
2308,
221,
327,
730,
26,
3686,
199,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
3522,
63,
14845,
63,
2423,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
334,
272,
3522,
63,
14845,
63,
2423,
465,
486,
696,
63,
2912,
63,
14845,
63,
2423,
12,
199,
9,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
3537,
63,
2423,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
3537,
63,
2423,
465,
486,
696,
63,
4229,
63,
2423,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
666,
63,
1302,
316,
63,
2423,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
666,
63,
1302,
316,
63,
2423,
465,
486,
696,
63,
576,
63,
1302,
316,
63,
2423,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
10342,
5329,
63,
10032,
316,
63,
2423,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
334,
272,
10342,
5329,
63,
10032,
316,
63,
2423,
465,
486,
696,
63,
9547,
5329,
63,
10032,
316,
63,
2423,
12,
199,
9,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
3906,
63,
1364,
199,
504,
6233,
14,
2809,
5720,
492,
5331,
63,
3317,
18,
221,
327,
730,
26,
3686,
199,
504,
6233,
14,
7204,
492,
2701,
63,
3317,
18,
221,
327,
730,
26,
3686,
199,
504,
1275,
1095,
492,
15057,
3167,
7836,
12,
6186,
63,
9901,
63,
4531,
199,
504,
1275,
15391,
492,
15057,
3167,
39,
4354,
7836,
421,
199,
533,
15057,
3167,
39,
4354,
12807,
41,
1387,
4808,
8,
6694,
3167,
7836,
304,
272,
408,
71,
8171,
15223,
2090,
4865,
7773,
367,
15057,
3167,
14,
339,
437,
2435,
367,
6425,
436,
28453,
5444,
3858,
437,
41,
1159,
9643,
14,
339,
961,
1021,
7890,
314,
2011,
3102,
465,
314,
5062,
1890,
12,
880,
314,
272,
5062,
1890,
883,
2248,
314,
8793,
7773,
4514,
272,
436,
1240,
652,
14,
339,
2779,
16178,
4113,
19383,
1806,
314,
11799,
1808,
30700,
334,
6777,
365,
6137,
641,
272,
2746,
402,
3101,
15,
18,
2736,
314,
1124,
12599,
10377,
1040,
2559,
1471,
506,
4903,
14,
272,
408,
339,
485,
15391,
63,
2775,
26,
282,
2308,
14,
5358,
272,
485,
8957,
26,
7448,
59,
495,
12,
16975,
61,
275,
1052,
339,
768,
3744,
272,
347,
1218,
63,
2775,
8,
267,
843,
12,
267,
1591,
26,
620,
275,
298,
65,
711,
76,
2140,
14,
17533,
14,
957,
401,
267,
6235,
26,
16072,
63,
6942,
14,
13428,
275,
488,
12,
267,
6235,
63,
493,
26,
4879,
59,
495,
61,
275,
488,
12,
267,
14570,
26,
4879,
59,
5826,
59,
495,
2677,
275,
488,
12,
267,
12132,
63,
1715,
63,
344,
26,
4879,
59,
495,
61,
275,
488,
12,
267,
1011,
958,
12,
272,
776,
1035,
282,
2308,
14,
5358,
26,
267,
408,
2499,
436,
372,
282,
30700,
15223,
2090,
3623,
909,
14,
267,
3033,
26,
288,
1591,
334,
7012,
59,
495,
4682,
710,
1591,
367,
314,
3623,
370,
675,
14,
288,
6235,
334,
7012,
19911,
14,
13428,
4682,
710,
355,
13448,
6235,
370,
6554,
370,
4145,
14,
5723,
355,
6235,
10405,
642,
4223,
370,
314,
2435,
14,
982,
355,
7179,
787,
2013,
12,
314,
1890,
911,
7427,
370,
465,
20226,
355,
314,
6235,
687,
314,
3734,
14,
288,
6235,
63,
493,
334,
7012,
59,
495,
4682,
437,
570,
543,
6235,
626,
883,
355,
506,
6511,
543,
520,
1532,
1705,
3098,
14,
1178,
14,
912,
63,
6942,
63,
504,
63,
493,
2313,
355,
961,
1423,
365,
5525,
340,
1124,
2775,
1040,
365,
2741,
14,
288,
14570,
334,
7012,
59,
5826,
59,
495,
2677,
304,
437,
2716,
769,
402,
14570,
4346,
367,
642,
355,
2435,
14,
5723,
787,
1454,
1202,
1380,
6235,
787,
440,
2013,
436,
355,
787,
3032,
370,
520,
1532,
1705,
3098,
14,
1178,
14,
885,
2313,
288,
12132,
63,
1715,
63,
344,
334,
7012,
59,
495,
4682,
1626,
2716,
2199,
370,
675,
367,
32663,
355,
436,
12132,
14,
288,
2074,
334,
7012,
59,
807,
4682,
6431,
2368,
12,
1314,
787,
3032,
370,
314,
355,
3623,
7143,
14,
267,
1803,
26,
288,
282,
2308,
14,
5358,
26,
437,
30700,
15223,
2090,
3623,
909,
14,
267,
408,
398,
291,
63,
1737,
63,
30033,
63,
958
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
25455,
4475,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
199,
646,
3598,
199,
504,
14090,
492,
437,
2573,
461,
12,
16975,
12,
7448,
12,
4879,
12,
10975,
12,
11634,
12,
15961,
199,
199,
504,
6233,
14,
1246,
63,
1018,
492,
16301,
530,
63,
86,
17,
221,
327,
730,
26,
3686,
199,
504,
6233,
14,
1246,
63,
1018,
492,
19753,
63,
7546,
63,
4146,
221,
327,
730,
26,
3686,
199,
504,
6233,
14,
1246,
63,
1018,
492,
5331,
63,
86,
17,
221,
327,
730,
26,
3686,
199,
504,
6233,
14,
1178,
492,
6235,
465,
16072,
63,
6942,
221,
327,
730,
26,
3686,
199,
504,
6233,
14,
1178,
14,
5545,
14,
15391,
492,
428,
2482,
13428,
221,
327,
730,
26,
3686,
199,
646,
27369,
14,
1023,
199,
199,
646,
19753,
221,
327,
730,
26,
3686,
199,
504,
19753,
14,
18924,
492,
282,
2308,
221,
327,
730,
26,
3686,
199,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
3522,
63,
14845,
63,
2423,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
334,
272,
3522,
63,
14845,
63,
2423,
465,
486,
696,
63,
2912,
63,
14845,
63,
2423,
12,
199,
9,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
3537,
63,
2423,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
3537,
63,
2423,
465,
486,
696,
63,
4229,
63,
2423,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
666,
63,
1302,
316,
63,
2423,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
666,
63,
1302,
316,
63,
2423,
465,
486,
696,
63,
576,
63,
1302,
316,
63,
2423,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
10342,
5329,
63,
10032,
316,
63,
2423,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
334,
272,
10342,
5329,
63,
10032,
316,
63,
2423,
465,
486,
696,
63,
9547,
5329,
63,
10032,
316,
63,
2423,
12,
199,
9,
199,
504,
6233,
14,
4091,
14,
65,
711,
76,
2140,
63,
86,
17,
14,
1313,
492,
3906,
63,
1364,
199,
504,
6233,
14,
2809,
5720,
492,
5331,
63,
3317,
18,
221,
327,
730,
26,
3686,
199,
504,
6233,
14,
7204,
492,
2701,
63,
3317,
18,
221,
327,
730,
26,
3686,
199,
504,
1275,
1095,
492,
15057,
3167,
7836,
12,
6186,
63,
9901,
63,
4531,
199,
504,
1275,
15391,
492,
15057,
3167,
39,
4354,
7836,
421,
199,
533,
15057,
3167,
39,
4354,
12807,
41,
1387,
4808,
8,
6694,
3167,
7836,
304,
272,
408,
71,
8171,
15223,
2090,
4865,
7773,
367,
15057,
3167,
14,
339,
437,
2435,
367,
6425,
436,
28453,
5444,
3858,
437,
41,
1159,
9643,
14,
339,
961,
1021,
7890,
314,
2011,
3102,
465,
314,
5062,
1890,
12,
880,
314,
272,
5062,
1890,
883,
2248,
314,
8793,
7773,
4514,
272,
436,
1240,
652,
14,
339,
2779,
16178,
4113,
19383,
1806,
314,
11799,
1808,
30700,
334,
6777,
365,
6137,
641,
272,
2746,
402,
3101,
15,
18,
2736,
314,
1124,
12599,
10377,
1040,
2559,
1471,
506,
4903,
14,
272,
408,
339,
485,
15391,
63,
2775,
26,
282,
2308,
14,
5358,
272,
485,
8957,
26,
7448,
59,
495,
12,
16975,
61,
275,
1052,
339,
768,
3744,
272,
347,
1218,
63,
2775,
8,
267,
843,
12,
267,
1591,
26,
620,
275,
298,
65,
711,
76,
2140,
14,
17533,
14,
957,
401,
267,
6235,
26,
16072,
63,
6942,
14,
13428,
275,
488,
12,
267,
6235,
63,
493,
26,
4879,
59,
495,
61,
275,
488,
12,
267,
14570,
26,
4879,
59,
5826,
59,
495,
2677,
275,
488,
12,
267,
12132,
63,
1715,
63,
344,
26,
4879,
59,
495,
61,
275,
488,
12,
267,
1011,
958,
12,
272,
776,
1035,
282,
2308,
14,
5358,
26,
267,
408,
2499,
436,
372,
282,
30700,
15223,
2090,
3623,
909,
14,
267,
3033,
26,
288,
1591,
334,
7012,
59,
495,
4682,
710,
1591,
367,
314,
3623,
370,
675,
14,
288,
6235,
334,
7012,
19911,
14,
13428,
4682,
710,
355,
13448,
6235,
370,
6554,
370,
4145,
14,
5723,
355,
6235,
10405,
642,
4223,
370,
314,
2435,
14,
982,
355,
7179,
787,
2013,
12,
314,
1890,
911,
7427,
370,
465,
20226,
355,
314,
6235,
687,
314,
3734,
14,
288,
6235,
63,
493,
334,
7012,
59,
495,
4682,
437,
570,
543,
6235,
626,
883,
355,
506,
6511,
543,
520,
1532,
1705,
3098,
14,
1178,
14,
912,
63,
6942,
63,
504,
63,
493,
2313,
355,
961,
1423,
365,
5525,
340,
1124,
2775,
1040,
365,
2741,
14,
288,
14570,
334,
7012,
59,
5826,
59,
495,
2677,
304,
437,
2716,
769,
402,
14570,
4346,
367,
642,
355,
2435,
14,
5723,
787,
1454,
1202,
1380,
6235,
787,
440,
2013,
436,
355,
787,
3032,
370,
520,
1532,
1705,
3098,
14,
1178,
14,
885,
2313,
288,
12132,
63,
1715,
63,
344,
334,
7012,
59,
495,
4682,
1626,
2716,
2199,
370,
675,
367,
32663,
355,
436,
12132,
14,
288,
2074,
334,
7012,
59,
807,
4682,
6431,
2368,
12,
1314,
787,
3032,
370,
314,
355,
3623,
7143,
14,
267,
1803,
26,
288,
282,
2308,
14,
5358,
26,
437,
30700,
15223,
2090,
3623,
909,
14,
267,
408,
398,
291,
63,
1737,
63,
30033,
63,
958,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
KyleJamesWalker/ansible
|
lib/ansible/plugins/connection/accelerate.py
|
36
|
13975
|
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import base64
import json
import os
import socket
import struct
import time
from ansible import constants as C
from ansible.errors import AnsibleError, AnsibleFileNotFound, AnsibleConnectionFailure
from ansible.module_utils._text import to_bytes
from ansible.parsing.utils.jsonify import jsonify
from ansible.plugins.connection import ConnectionBase
from ansible.utils.encrypt import key_for_hostname, keyczar_encrypt, keyczar_decrypt
try:
from __main__ import display
except ImportError:
from ansible.utils.display import Display
display = Display()
# the chunk size to read and send, assuming mtu 1500 and
# leaving room for base64 (+33%) encoding and header (8 bytes)
# ((1400-8)/4)*3) = 1044
# which leaves room for the TCP/IP header. We set this to a
# multiple of the value to speed up file reads.
CHUNK_SIZE=1044*20
class Connection(ConnectionBase):
''' raw socket accelerated connection '''
transport = 'accelerate'
has_pipelining = False
become_methods = frozenset(C.BECOME_METHODS).difference(['runas'])
def __init__(self, *args, **kwargs):
super(Connection, self).__init__(*args, **kwargs)
self.conn = None
self.key = key_for_hostname(self._play_context.remote_addr)
def _connect(self):
''' activates the connection object '''
if not self._connected:
wrong_user = False
tries = 3
self.conn = socket.socket()
self.conn.settimeout(C.ACCELERATE_CONNECT_TIMEOUT)
display.vvvv("attempting connection to %s via the accelerated port %d" % (self._play_context.remote_addr, self._play_context.accelerate_port),
host=self._play_context.remote_addr)
while tries > 0:
try:
self.conn.connect((self._play_context.remote_addr,self._play_context.accelerate_port))
break
except socket.error:
display.vvvv("connection to %s failed, retrying..." % self._play_context.remote_addr, host=self._play_context.remote_addr)
time.sleep(0.1)
tries -= 1
if tries == 0:
display.vvv("Could not connect via the accelerated connection, exceeded # of tries", host=self._play_context.remote_addr)
raise AnsibleConnectionFailure("Failed to connect to %s on the accelerated port %s" % (self._play_context.remote_addr,
self._play_context.accelerate_port))
elif wrong_user:
display.vvv("Restarting daemon with a different remote_user", host=self._play_context.remote_addr)
raise AnsibleError("The accelerated daemon was started on the remote with a different user")
self.conn.settimeout(C.ACCELERATE_TIMEOUT)
if not self.validate_user():
# the accelerated daemon was started with a
# different remote_user. The above command
# should have caused the accelerate daemon to
# shutdown, so we'll reconnect.
wrong_user = True
self._connected = True
return self
def transport_test(self, connect_timeout):
''' Test the transport mechanism, if available '''
host = self._play_context.remote_addr
port = int(self._play_context.accelerate_port or 5099)
display.vvv("attempting transport test to %s:%s" % (host, port))
sock = socket.create_connection((host, port), connect_timeout)
sock.close()
def send_data(self, data):
packed_len = struct.pack('!Q',len(data))
return self.conn.sendall(packed_len + data)
def recv_data(self):
header_len = 8 # size of a packed unsigned long long
data = b""
try:
display.vvvv("in recv_data(), waiting for the header", host=self._play_context.remote_addr)
while len(data) < header_len:
d = self.conn.recv(header_len - len(data))
if not d:
display.vvvv("received nothing, bailing out", host=self._play_context.remote_addr)
return None
data += d
display.vvvv("got the header, unpacking", host=self._play_context.remote_addr)
data_len = struct.unpack('!Q',data[:header_len])[0]
data = data[header_len:]
display.vvvv("data received so far (expecting %d): %d" % (data_len, len(data)), host=self._play_context.remote_addr)
while len(data) < data_len:
d = self.conn.recv(data_len - len(data))
if not d:
display.vvvv("received nothing, bailing out", host=self._play_context.remote_addr)
return None
display.vvvv("received %d bytes" % (len(d)), host=self._play_context.remote_addr)
data += d
display.vvvv("received all of the data, returning", host=self._play_context.remote_addr)
return data
except socket.timeout:
raise AnsibleError("timed out while waiting to receive data")
def validate_user(self):
'''
Checks the remote uid of the accelerated daemon vs. the
one specified for this play and will cause the accel
daemon to exit if they don't match
'''
display.vvvv("sending request for validate_user", host=self._play_context.remote_addr)
data = dict(
mode='validate_user',
username=self._play_context.remote_user,
)
data = jsonify(data)
data = keyczar_encrypt(self.key, data)
if self.send_data(data):
raise AnsibleError("Failed to send command to %s" % self._play_context.remote_addr)
display.vvvv("waiting for validate_user response", host=self._play_context.remote_addr)
while True:
# we loop here while waiting for the response, because a
# long running command may cause us to receive keepalive packets
# ({"pong":"true"}) rather than the response we want.
response = self.recv_data()
if not response:
raise AnsibleError("Failed to get a response from %s" % self._play_context.remote_addr)
response = keyczar_decrypt(self.key, response)
response = json.loads(response)
if "pong" in response:
# it's a keepalive, go back to waiting
display.vvvv("received a keepalive packet", host=self._play_context.remote_addr)
continue
else:
display.vvvv("received the validate_user response: %s" % (response), host=self._play_context.remote_addr)
break
if response.get('failed'):
return False
else:
return response.get('rc') == 0
def exec_command(self, cmd, in_data=None, sudoable=True):
''' run a command on the remote host '''
super(Connection, self).exec_command(cmd, in_data=in_data, sudoable=sudoable)
if in_data:
raise AnsibleError("Internal Error: this module does not support optimized module pipelining")
display.vvv("EXEC COMMAND %s" % cmd, host=self._play_context.remote_addr)
data = dict(
mode='command',
cmd=cmd,
executable=C.DEFAULT_EXECUTABLE,
)
data = jsonify(data)
data = keyczar_encrypt(self.key, data)
if self.send_data(data):
raise AnsibleError("Failed to send command to %s" % self._play_context.remote_addr)
while True:
# we loop here while waiting for the response, because a
# long running command may cause us to receive keepalive packets
# ({"pong":"true"}) rather than the response we want.
response = self.recv_data()
if not response:
raise AnsibleError("Failed to get a response from %s" % self._play_context.remote_addr)
response = keyczar_decrypt(self.key, response)
response = json.loads(response)
if "pong" in response:
# it's a keepalive, go back to waiting
display.vvvv("received a keepalive packet", host=self._play_context.remote_addr)
continue
else:
display.vvvv("received the response", host=self._play_context.remote_addr)
break
return (response.get('rc', None), response.get('stdout', ''), response.get('stderr', ''))
def put_file(self, in_path, out_path):
''' transfer a file from local to remote '''
display.vvv("PUT %s TO %s" % (in_path, out_path), host=self._play_context.remote_addr)
in_path = to_bytes(in_path, errors='surrogate_or_strict')
if not os.path.exists(in_path):
raise AnsibleFileNotFound("file or module does not exist: %s" % in_path)
fd = file(in_path, 'rb')
fstat = os.stat(in_path)
try:
display.vvv("PUT file is %d bytes" % fstat.st_size, host=self._play_context.remote_addr)
last = False
while fd.tell() <= fstat.st_size and not last:
display.vvvv("file position currently %ld, file size is %ld" % (fd.tell(), fstat.st_size), host=self._play_context.remote_addr)
data = fd.read(CHUNK_SIZE)
if fd.tell() >= fstat.st_size:
last = True
data = dict(mode='put', data=base64.b64encode(data), out_path=out_path, last=last)
if self._play_context.become:
data['user'] = self._play_context.become_user
data = jsonify(data)
data = keyczar_encrypt(self.key, data)
if self.send_data(data):
raise AnsibleError("failed to send the file to %s" % self._play_context.remote_addr)
response = self.recv_data()
if not response:
raise AnsibleError("Failed to get a response from %s" % self._play_context.remote_addr)
response = keyczar_decrypt(self.key, response)
response = json.loads(response)
if response.get('failed',False):
raise AnsibleError("failed to put the file in the requested location")
finally:
fd.close()
display.vvvv("waiting for final response after PUT", host=self._play_context.remote_addr)
response = self.recv_data()
if not response:
raise AnsibleError("Failed to get a response from %s" % self._play_context.remote_addr)
response = keyczar_decrypt(self.key, response)
response = json.loads(response)
if response.get('failed',False):
raise AnsibleError("failed to put the file in the requested location")
def fetch_file(self, in_path, out_path):
''' save a remote file to the specified path '''
display.vvv("FETCH %s TO %s" % (in_path, out_path), host=self._play_context.remote_addr)
data = dict(mode='fetch', in_path=in_path)
data = jsonify(data)
data = keyczar_encrypt(self.key, data)
if self.send_data(data):
raise AnsibleError("failed to initiate the file fetch with %s" % self._play_context.remote_addr)
fh = open(to_bytes(out_path, errors='surrogate_or_strict'), "w")
try:
bytes = 0
while True:
response = self.recv_data()
if not response:
raise AnsibleError("Failed to get a response from %s" % self._play_context.remote_addr)
response = keyczar_decrypt(self.key, response)
response = json.loads(response)
if response.get('failed', False):
raise AnsibleError("Error during file fetch, aborting")
out = base64.b64decode(response['data'])
fh.write(out)
bytes += len(out)
# send an empty response back to signify we
# received the last chunk without errors
data = jsonify(dict())
data = keyczar_encrypt(self.key, data)
if self.send_data(data):
raise AnsibleError("failed to send ack during file fetch")
if response.get('last', False):
break
finally:
# we don't currently care about this final response,
# we just receive it and drop it. It may be used at some
# point in the future or we may just have the put/fetch
# operations not send back a final response at all
response = self.recv_data()
display.vvv("FETCH wrote %d bytes to %s" % (bytes, out_path), host=self._play_context.remote_addr)
fh.close()
def close(self):
''' terminate the connection '''
# Be a good citizen
try:
self.conn.close()
except:
pass
|
gpl-3.0
|
[
3,
334,
67,
9,
6029,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
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,
1300,
772,
199,
646,
2022,
199,
646,
747,
199,
646,
2838,
199,
646,
2702,
199,
646,
900,
199,
199,
504,
3242,
492,
5262,
465,
445,
199,
504,
3242,
14,
2550,
492,
13358,
12,
2622,
1173,
4667,
12,
2622,
3225,
6782,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
2394,
199,
504,
3242,
14,
11059,
14,
1208,
14,
1001,
2021,
492,
23819,
199,
504,
3242,
14,
5265,
14,
2105,
492,
8113,
1563,
199,
504,
3242,
14,
1208,
14,
11929,
492,
790,
63,
509,
63,
4269,
12,
790,
16823,
285,
63,
11929,
12,
790,
16823,
285,
63,
15682,
421,
199,
893,
26,
272,
687,
636,
973,
363,
492,
2929,
199,
2590,
3545,
26,
272,
687,
3242,
14,
1208,
14,
2918,
492,
12175,
272,
2929,
275,
12175,
342,
199,
199,
3,
314,
3728,
1568,
370,
1586,
436,
3222,
12,
18002,
28270,
24970,
436,
199,
3,
23188,
14726,
367,
1300,
772,
334,
11,
1153,
5,
9,
2644,
436,
1406,
334,
24,
2783,
9,
199,
3,
3666,
1079,
383,
13,
24,
2447,
20,
3342,
19,
9,
275,
413,
9111,
199,
3,
1314,
16733,
14726,
367,
314,
13488,
15,
1772,
1406,
14,
2136,
663,
642,
370,
282,
199,
3,
3663,
402,
314,
574,
370,
8112,
1536,
570,
11597,
14,
199,
20512,
63,
4305,
29,
709,
1602,
10,
1165,
421,
199,
533,
8113,
8,
3225,
1563,
304,
272,
1449,
3066,
2838,
1066,
15730,
1950,
1449,
339,
7773,
275,
283,
645,
11338,
323,
7,
272,
965,
63,
4990,
30176,
275,
756,
272,
8649,
63,
2474,
275,
9522,
8,
35,
14,
6773,
1439,
3635,
63,
18383,
680,
9196,
2941,
1065,
305,
1105,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
398,
1613,
8,
3225,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
398,
291,
14,
1631,
275,
488,
267,
291,
14,
498,
275,
790,
63,
509,
63,
4269,
8,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
9,
339,
347,
485,
2242,
8,
277,
304,
267,
1449,
6633,
86,
2335,
314,
1950,
909,
1449,
398,
340,
440,
291,
423,
7113,
26,
288,
6835,
63,
751,
275,
756,
288,
11275,
275,
650,
288,
291,
14,
1631,
275,
2838,
14,
3450,
342,
288,
291,
14,
1631,
14,
24630,
8,
35,
14,
1348,
2089,
19650,
1951,
63,
14657,
63,
8899,
9,
288,
2929,
14,
30448,
480,
8739,
1337,
1950,
370,
450,
83,
4799,
314,
1066,
15730,
1844,
450,
68,
2,
450,
334,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
12,
291,
423,
2802,
63,
1100,
14,
645,
11338,
323,
63,
719,
395,
586,
1591,
29,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
9,
288,
1830,
11275,
690,
378,
26,
355,
862,
26,
490,
291,
14,
1631,
14,
2242,
1332,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
12,
277,
423,
2802,
63,
1100,
14,
645,
11338,
323,
63,
719,
430,
490,
2059,
355,
871,
2838,
14,
705,
26,
490,
2929,
14,
30448,
480,
2105,
370,
450,
83,
3405,
12,
7269,
316,
11500,
450,
291,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
12,
1591,
29,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
9,
490,
900,
14,
4532,
8,
16,
14,
17,
9,
490,
11275,
4862,
413,
288,
340,
11275,
508,
378,
26,
355,
2929,
14,
24622,
480,
6531,
440,
4907,
4799,
314,
1066,
15730,
1950,
12,
22007,
327,
402,
11275,
401,
1591,
29,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
9,
355,
746,
2622,
3225,
6782,
480,
4276,
370,
4907,
370,
450,
83,
641,
314,
1066,
15730,
1844,
450,
83,
2,
450,
334,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
12,
12268,
9668,
291,
423,
2802,
63,
1100,
14,
645,
11338,
323,
63,
719,
430,
288,
916,
6835,
63,
751,
26,
355,
2929,
14,
24622,
480,
497,
15769,
11128,
543,
282,
3365,
3982,
63,
751,
401,
1591,
29,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
9,
355,
746,
13358,
480,
1918,
1066,
15730,
11128,
1990,
8239,
641,
314,
3982,
543,
282,
3365,
922,
531,
953,
291,
14,
1631,
14,
24630,
8,
35,
14,
1348,
2089,
19650,
1951,
63,
8899,
9,
288,
340,
440,
291,
14,
3502,
63,
751,
837,
355,
327,
314,
1066,
15730,
11128,
1990,
8239,
543,
282,
355,
327,
3365,
3982,
63,
751,
14,
710,
3432,
1414,
355,
327,
1077,
1172,
18104,
314,
1066,
11338,
323,
11128,
370,
355,
327,
12842,
12,
880,
781,
7171,
30882,
14,
355,
6835,
63,
751,
275,
715,
398,
291,
423,
7113,
275,
715,
267,
372,
291,
339,
347,
7773,
63,
396,
8,
277,
12,
4907,
63,
2593,
304,
267,
1449,
1379,
314,
7773,
14729,
12,
340,
2808,
1449,
267,
1591,
275,
291,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
267,
1844,
275,
1109,
8,
277,
423,
2802,
63,
1100,
14,
645,
11338,
323,
63,
719,
503,
5238,
1020,
9,
267,
2929,
14,
24622,
480,
8739,
1337,
7773,
511,
370,
450,
83,
2689,
83,
2,
450,
334,
1102,
12,
1844,
430
] |
[
334,
67,
9,
6029,
12,
16922,
22453,
665,
22333,
14,
24247,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
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,
1300,
772,
199,
646,
2022,
199,
646,
747,
199,
646,
2838,
199,
646,
2702,
199,
646,
900,
199,
199,
504,
3242,
492,
5262,
465,
445,
199,
504,
3242,
14,
2550,
492,
13358,
12,
2622,
1173,
4667,
12,
2622,
3225,
6782,
199,
504,
3242,
14,
578,
63,
1208,
423,
505,
492,
370,
63,
2394,
199,
504,
3242,
14,
11059,
14,
1208,
14,
1001,
2021,
492,
23819,
199,
504,
3242,
14,
5265,
14,
2105,
492,
8113,
1563,
199,
504,
3242,
14,
1208,
14,
11929,
492,
790,
63,
509,
63,
4269,
12,
790,
16823,
285,
63,
11929,
12,
790,
16823,
285,
63,
15682,
421,
199,
893,
26,
272,
687,
636,
973,
363,
492,
2929,
199,
2590,
3545,
26,
272,
687,
3242,
14,
1208,
14,
2918,
492,
12175,
272,
2929,
275,
12175,
342,
199,
199,
3,
314,
3728,
1568,
370,
1586,
436,
3222,
12,
18002,
28270,
24970,
436,
199,
3,
23188,
14726,
367,
1300,
772,
334,
11,
1153,
5,
9,
2644,
436,
1406,
334,
24,
2783,
9,
199,
3,
3666,
1079,
383,
13,
24,
2447,
20,
3342,
19,
9,
275,
413,
9111,
199,
3,
1314,
16733,
14726,
367,
314,
13488,
15,
1772,
1406,
14,
2136,
663,
642,
370,
282,
199,
3,
3663,
402,
314,
574,
370,
8112,
1536,
570,
11597,
14,
199,
20512,
63,
4305,
29,
709,
1602,
10,
1165,
421,
199,
533,
8113,
8,
3225,
1563,
304,
272,
1449,
3066,
2838,
1066,
15730,
1950,
1449,
339,
7773,
275,
283,
645,
11338,
323,
7,
272,
965,
63,
4990,
30176,
275,
756,
272,
8649,
63,
2474,
275,
9522,
8,
35,
14,
6773,
1439,
3635,
63,
18383,
680,
9196,
2941,
1065,
305,
1105,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
398,
1613,
8,
3225,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
398,
291,
14,
1631,
275,
488,
267,
291,
14,
498,
275,
790,
63,
509,
63,
4269,
8,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
9,
339,
347,
485,
2242,
8,
277,
304,
267,
1449,
6633,
86,
2335,
314,
1950,
909,
1449,
398,
340,
440,
291,
423,
7113,
26,
288,
6835,
63,
751,
275,
756,
288,
11275,
275,
650,
288,
291,
14,
1631,
275,
2838,
14,
3450,
342,
288,
291,
14,
1631,
14,
24630,
8,
35,
14,
1348,
2089,
19650,
1951,
63,
14657,
63,
8899,
9,
288,
2929,
14,
30448,
480,
8739,
1337,
1950,
370,
450,
83,
4799,
314,
1066,
15730,
1844,
450,
68,
2,
450,
334,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
12,
291,
423,
2802,
63,
1100,
14,
645,
11338,
323,
63,
719,
395,
586,
1591,
29,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
9,
288,
1830,
11275,
690,
378,
26,
355,
862,
26,
490,
291,
14,
1631,
14,
2242,
1332,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
12,
277,
423,
2802,
63,
1100,
14,
645,
11338,
323,
63,
719,
430,
490,
2059,
355,
871,
2838,
14,
705,
26,
490,
2929,
14,
30448,
480,
2105,
370,
450,
83,
3405,
12,
7269,
316,
11500,
450,
291,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
12,
1591,
29,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
9,
490,
900,
14,
4532,
8,
16,
14,
17,
9,
490,
11275,
4862,
413,
288,
340,
11275,
508,
378,
26,
355,
2929,
14,
24622,
480,
6531,
440,
4907,
4799,
314,
1066,
15730,
1950,
12,
22007,
327,
402,
11275,
401,
1591,
29,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
9,
355,
746,
2622,
3225,
6782,
480,
4276,
370,
4907,
370,
450,
83,
641,
314,
1066,
15730,
1844,
450,
83,
2,
450,
334,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
12,
12268,
9668,
291,
423,
2802,
63,
1100,
14,
645,
11338,
323,
63,
719,
430,
288,
916,
6835,
63,
751,
26,
355,
2929,
14,
24622,
480,
497,
15769,
11128,
543,
282,
3365,
3982,
63,
751,
401,
1591,
29,
277,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
9,
355,
746,
13358,
480,
1918,
1066,
15730,
11128,
1990,
8239,
641,
314,
3982,
543,
282,
3365,
922,
531,
953,
291,
14,
1631,
14,
24630,
8,
35,
14,
1348,
2089,
19650,
1951,
63,
8899,
9,
288,
340,
440,
291,
14,
3502,
63,
751,
837,
355,
327,
314,
1066,
15730,
11128,
1990,
8239,
543,
282,
355,
327,
3365,
3982,
63,
751,
14,
710,
3432,
1414,
355,
327,
1077,
1172,
18104,
314,
1066,
11338,
323,
11128,
370,
355,
327,
12842,
12,
880,
781,
7171,
30882,
14,
355,
6835,
63,
751,
275,
715,
398,
291,
423,
7113,
275,
715,
267,
372,
291,
339,
347,
7773,
63,
396,
8,
277,
12,
4907,
63,
2593,
304,
267,
1449,
1379,
314,
7773,
14729,
12,
340,
2808,
1449,
267,
1591,
275,
291,
423,
2802,
63,
1100,
14,
3846,
63,
2697,
267,
1844,
275,
1109,
8,
277,
423,
2802,
63,
1100,
14,
645,
11338,
323,
63,
719,
503,
5238,
1020,
9,
267,
2929,
14,
24622,
480,
8739,
1337,
7773,
511,
370,
450,
83,
2689,
83,
2,
450,
334,
1102,
12,
1844,
430,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wgcv/SWW-Crashphone
|
lib/python2.7/site-packages/django/contrib/gis/gdal/geomtype.py
|
90
|
2983
|
from django.contrib.gis.gdal.error import OGRException
from django.utils import six
class OGRGeomType(object):
"Encapulates OGR Geometry Types."
wkb25bit = -2147483648
# Dictionary of acceptable OGRwkbGeometryType s and their string names.
_types = {0: 'Unknown',
1: 'Point',
2: 'LineString',
3: 'Polygon',
4: 'MultiPoint',
5: 'MultiLineString',
6: 'MultiPolygon',
7: 'GeometryCollection',
100: 'None',
101: 'LinearRing',
1 + wkb25bit: 'Point25D',
2 + wkb25bit: 'LineString25D',
3 + wkb25bit: 'Polygon25D',
4 + wkb25bit: 'MultiPoint25D',
5 + wkb25bit: 'MultiLineString25D',
6 + wkb25bit: 'MultiPolygon25D',
7 + wkb25bit: 'GeometryCollection25D',
}
# Reverse type dictionary, keyed by lower-case of the name.
_str_types = dict((v.lower(), k) for k, v in _types.items())
def __init__(self, type_input):
"Figures out the correct OGR Type based upon the input."
if isinstance(type_input, OGRGeomType):
num = type_input.num
elif isinstance(type_input, six.string_types):
type_input = type_input.lower()
if type_input == 'geometry':
type_input = 'unknown'
num = self._str_types.get(type_input, None)
if num is None:
raise OGRException('Invalid OGR String Type "%s"' % type_input)
elif isinstance(type_input, int):
if type_input not in self._types:
raise OGRException('Invalid OGR Integer Type: %d' % type_input)
num = type_input
else:
raise TypeError('Invalid OGR input type given.')
# Setting the OGR geometry type number.
self.num = num
def __str__(self):
"Returns the value of the name property."
return self.name
def __eq__(self, other):
"""
Does an equivalence test on the OGR type with the given
other OGRGeomType, the short-hand string, or the integer.
"""
if isinstance(other, OGRGeomType):
return self.num == other.num
elif isinstance(other, six.string_types):
return self.name.lower() == other.lower()
elif isinstance(other, int):
return self.num == other
else:
return False
def __ne__(self, other):
return not (self == other)
@property
def name(self):
"Returns a short-hand string form of the OGR Geometry type."
return self._types[self.num]
@property
def django(self):
"Returns the Django GeometryField for this OGR Type."
s = self.name.replace('25D', '')
if s in ('LinearRing', 'None'):
return None
elif s == 'Unknown':
s = 'Geometry'
return s + 'Field'
|
apache-2.0
|
[
504,
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
19746,
907,
16010,
199,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
533,
25756,
8,
785,
304,
272,
298,
1327,
2874,
15409,
10904,
10579,
18851,
2122,
339,
24249,
821,
2075,
275,
446,
22519,
10552,
339,
327,
11932,
402,
14712,
10904,
18914,
6831,
804,
308,
436,
3932,
1059,
1561,
14,
272,
485,
1313,
275,
469,
16,
26,
283,
5912,
297,
1598,
413,
26,
283,
3428,
297,
1598,
499,
26,
283,
22134,
297,
1598,
650,
26,
283,
12367,
297,
1598,
841,
26,
283,
3947,
3428,
297,
1598,
959,
26,
283,
3947,
22134,
297,
1598,
1227,
26,
283,
3947,
12367,
297,
1598,
1520,
26,
283,
6831,
7768,
297,
1598,
2948,
26,
283,
403,
297,
1598,
14313,
26,
283,
10608,
15420,
297,
1598,
413,
435,
24249,
821,
2075,
26,
283,
3428,
821,
36,
297,
1598,
499,
435,
24249,
821,
2075,
26,
283,
22134,
821,
36,
297,
1598,
650,
435,
24249,
821,
2075,
26,
283,
12367,
821,
36,
297,
1598,
841,
435,
24249,
821,
2075,
26,
283,
3947,
3428,
821,
36,
297,
1598,
959,
435,
24249,
821,
2075,
26,
283,
3947,
22134,
821,
36,
297,
1598,
1227,
435,
24249,
821,
2075,
26,
283,
3947,
12367,
821,
36,
297,
1598,
1520,
435,
24249,
821,
2075,
26,
283,
6831,
7768,
821,
36,
297,
1598,
789,
272,
327,
22734,
730,
2600,
12,
19272,
701,
5117,
13,
2546,
402,
314,
536,
14,
272,
485,
495,
63,
1313,
275,
1211,
1332,
86,
14,
2325,
1062,
1022,
9,
367,
1022,
12,
373,
315,
485,
1313,
14,
1744,
1012,
339,
347,
636,
826,
721,
277,
12,
730,
63,
1210,
304,
267,
298,
38,
528,
1482,
734,
314,
3211,
10904,
2434,
4079,
12188,
314,
1324,
2122,
267,
340,
1228,
8,
466,
63,
1210,
12,
25756,
304,
288,
1967,
275,
730,
63,
1210,
14,
1507,
267,
916,
1228,
8,
466,
63,
1210,
12,
3816,
14,
875,
63,
1313,
304,
288,
730,
63,
1210,
275,
730,
63,
1210,
14,
2325,
342,
288,
340,
730,
63,
1210,
508,
283,
7660,
356,
355,
730,
63,
1210,
275,
283,
5187,
7,
288,
1967,
275,
291,
423,
495,
63,
1313,
14,
362,
8,
466,
63,
1210,
12,
488,
9,
288,
340,
1967,
365,
488,
26,
355,
746,
19746,
907,
16010,
360,
3364,
10904,
2624,
2434,
2071,
83,
4507,
450,
730,
63,
1210,
9,
267,
916,
1228,
8,
466,
63,
1210,
12,
1109,
304,
288,
340,
730,
63,
1210,
440,
315,
291,
423,
1313,
26,
355,
746,
19746,
907,
16010,
360,
3364,
10904,
7225,
2434,
26,
450,
68,
7,
450,
730,
63,
1210,
9,
288,
1967,
275,
730,
63,
1210,
267,
587,
26,
288,
746,
3146,
360,
3364,
10904,
1324,
730,
1627,
2659,
398,
327,
13510,
314,
10904,
3400,
730,
1329,
14,
267,
291,
14,
1507,
275,
1967,
339,
347,
636,
495,
721,
277,
304,
267,
298,
3407,
314,
574,
402,
314,
536,
3324,
2122,
267,
372,
291,
14,
354,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
408,
267,
12078,
376,
325,
22810,
511,
641,
314,
10904,
730,
543,
314,
1627,
267,
1163,
25756,
12,
314,
3974,
13,
6868,
1059,
12,
503,
314,
3000,
14,
267,
408,
267,
340,
1228,
8,
1848,
12,
25756,
304,
288,
372,
291,
14,
1507,
508,
1163,
14,
1507,
267,
916,
1228,
8,
1848,
12,
3816,
14,
875,
63,
1313,
304,
288,
372,
291,
14,
354,
14,
2325,
342,
508,
1163,
14,
2325,
342,
267,
916,
1228,
8,
1848,
12,
1109,
304,
288,
372,
291,
14,
1507,
508,
1163,
267,
587,
26,
288,
372,
756,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
334,
277,
508,
1163,
9,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
298,
3407,
282,
3974,
13,
6868,
1059,
1824,
402,
314,
10904,
10579,
730,
2122,
267,
372,
291,
423,
1313,
59,
277,
14,
1507,
61,
339,
768,
1829,
272,
347,
1639,
8,
277,
304,
267,
298,
3407,
314,
5634,
30490,
367,
642,
10904,
2434,
2122,
267,
308,
275,
291,
14,
354,
14,
1814,
360,
821,
36,
297,
4074,
267,
340,
308,
315,
661,
10608,
15420,
297,
283,
403,
735,
288,
372,
488,
267,
916,
308,
508,
283,
5912,
356,
288,
308,
275,
283,
6831,
7,
267,
372,
308,
435,
283,
792,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
2828,
14,
5668,
14,
11600,
14,
705,
492,
19746,
907,
16010,
199,
199,
504,
1639,
14,
1208,
492,
3816,
421,
199,
533,
25756,
8,
785,
304,
272,
298,
1327,
2874,
15409,
10904,
10579,
18851,
2122,
339,
24249,
821,
2075,
275,
446,
22519,
10552,
339,
327,
11932,
402,
14712,
10904,
18914,
6831,
804,
308,
436,
3932,
1059,
1561,
14,
272,
485,
1313,
275,
469,
16,
26,
283,
5912,
297,
1598,
413,
26,
283,
3428,
297,
1598,
499,
26,
283,
22134,
297,
1598,
650,
26,
283,
12367,
297,
1598,
841,
26,
283,
3947,
3428,
297,
1598,
959,
26,
283,
3947,
22134,
297,
1598,
1227,
26,
283,
3947,
12367,
297,
1598,
1520,
26,
283,
6831,
7768,
297,
1598,
2948,
26,
283,
403,
297,
1598,
14313,
26,
283,
10608,
15420,
297,
1598,
413,
435,
24249,
821,
2075,
26,
283,
3428,
821,
36,
297,
1598,
499,
435,
24249,
821,
2075,
26,
283,
22134,
821,
36,
297,
1598,
650,
435,
24249,
821,
2075,
26,
283,
12367,
821,
36,
297,
1598,
841,
435,
24249,
821,
2075,
26,
283,
3947,
3428,
821,
36,
297,
1598,
959,
435,
24249,
821,
2075,
26,
283,
3947,
22134,
821,
36,
297,
1598,
1227,
435,
24249,
821,
2075,
26,
283,
3947,
12367,
821,
36,
297,
1598,
1520,
435,
24249,
821,
2075,
26,
283,
6831,
7768,
821,
36,
297,
1598,
789,
272,
327,
22734,
730,
2600,
12,
19272,
701,
5117,
13,
2546,
402,
314,
536,
14,
272,
485,
495,
63,
1313,
275,
1211,
1332,
86,
14,
2325,
1062,
1022,
9,
367,
1022,
12,
373,
315,
485,
1313,
14,
1744,
1012,
339,
347,
636,
826,
721,
277,
12,
730,
63,
1210,
304,
267,
298,
38,
528,
1482,
734,
314,
3211,
10904,
2434,
4079,
12188,
314,
1324,
2122,
267,
340,
1228,
8,
466,
63,
1210,
12,
25756,
304,
288,
1967,
275,
730,
63,
1210,
14,
1507,
267,
916,
1228,
8,
466,
63,
1210,
12,
3816,
14,
875,
63,
1313,
304,
288,
730,
63,
1210,
275,
730,
63,
1210,
14,
2325,
342,
288,
340,
730,
63,
1210,
508,
283,
7660,
356,
355,
730,
63,
1210,
275,
283,
5187,
7,
288,
1967,
275,
291,
423,
495,
63,
1313,
14,
362,
8,
466,
63,
1210,
12,
488,
9,
288,
340,
1967,
365,
488,
26,
355,
746,
19746,
907,
16010,
360,
3364,
10904,
2624,
2434,
2071,
83,
4507,
450,
730,
63,
1210,
9,
267,
916,
1228,
8,
466,
63,
1210,
12,
1109,
304,
288,
340,
730,
63,
1210,
440,
315,
291,
423,
1313,
26,
355,
746,
19746,
907,
16010,
360,
3364,
10904,
7225,
2434,
26,
450,
68,
7,
450,
730,
63,
1210,
9,
288,
1967,
275,
730,
63,
1210,
267,
587,
26,
288,
746,
3146,
360,
3364,
10904,
1324,
730,
1627,
2659,
398,
327,
13510,
314,
10904,
3400,
730,
1329,
14,
267,
291,
14,
1507,
275,
1967,
339,
347,
636,
495,
721,
277,
304,
267,
298,
3407,
314,
574,
402,
314,
536,
3324,
2122,
267,
372,
291,
14,
354,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
408,
267,
12078,
376,
325,
22810,
511,
641,
314,
10904,
730,
543,
314,
1627,
267,
1163,
25756,
12,
314,
3974,
13,
6868,
1059,
12,
503,
314,
3000,
14,
267,
408,
267,
340,
1228,
8,
1848,
12,
25756,
304,
288,
372,
291,
14,
1507,
508,
1163,
14,
1507,
267,
916,
1228,
8,
1848,
12,
3816,
14,
875,
63,
1313,
304,
288,
372,
291,
14,
354,
14,
2325,
342,
508,
1163,
14,
2325,
342,
267,
916,
1228,
8,
1848,
12,
1109,
304,
288,
372,
291,
14,
1507,
508,
1163,
267,
587,
26,
288,
372,
756,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
334,
277,
508,
1163,
9,
339,
768,
1829,
272,
347,
536,
8,
277,
304,
267,
298,
3407,
282,
3974,
13,
6868,
1059,
1824,
402,
314,
10904,
10579,
730,
2122,
267,
372,
291,
423,
1313,
59,
277,
14,
1507,
61,
339,
768,
1829,
272,
347,
1639,
8,
277,
304,
267,
298,
3407,
314,
5634,
30490,
367,
642,
10904,
2434,
2122,
267,
308,
275,
291,
14,
354,
14,
1814,
360,
821,
36,
297,
4074,
267,
340,
308,
315,
661,
10608,
15420,
297,
283,
403,
735,
288,
372,
488,
267,
916,
308,
508,
283,
5912,
356,
288,
308,
275,
283,
6831,
7,
267,
372,
308,
435,
283,
792,
7,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
tylertian/Openstack
|
openstack F/glance/glance/api/common.py
|
1
|
2790
|
# Copyright 2012 OpenStack LLC.
# 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 errno
from glance.common import exception
from glance.openstack.common import log as logging
LOG = logging.getLogger(__name__)
def size_checked_iter(response, image_meta, expected_size, image_iter,
notifier):
image_id = image_meta['id']
bytes_written = 0
def notify_image_sent_hook(env):
image_send_notification(bytes_written, expected_size,
image_meta, response.request, notifier)
# Add hook to process after response is fully sent
if 'eventlet.posthooks' in response.request.environ:
response.request.environ['eventlet.posthooks'].append(
(notify_image_sent_hook, (), {}))
try:
for chunk in image_iter:
yield chunk
bytes_written += len(chunk)
except Exception, err:
msg = _("An error occurred reading from backend storage "
"for image %(image_id)s: %(err)s") % locals()
LOG.error(msg)
raise
if expected_size != bytes_written:
msg = _("Backend storage for image %(image_id)s "
"disconnected after writing only %(bytes_written)d "
"bytes") % locals()
LOG.error(msg)
raise exception.GlanceException(_("Corrupt image download for "
"image %(image_id)s") % locals())
def image_send_notification(bytes_written, expected_size, image_meta, request,
notifier):
"""Send an image.send message to the notifier."""
try:
context = request.context
payload = {
'bytes_sent': bytes_written,
'image_id': image_meta['id'],
'owner_id': image_meta['owner'],
'receiver_tenant_id': context.tenant,
'receiver_user_id': context.user,
'destination_ip': request.remote_addr,
}
if bytes_written != expected_size:
notify = notifier.error
else:
notify = notifier.info
notify('image.send', payload)
except Exception, err:
msg = _("An error occurred during image.send"
" notification: %(err)s") % locals()
LOG.error(msg)
|
apache-2.0
|
[
3,
1898,
6029,
14260,
20376,
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,
7554,
199,
199,
504,
21785,
14,
2330,
492,
1919,
199,
504,
21785,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
1568,
63,
10718,
63,
1661,
8,
1310,
12,
1834,
63,
2024,
12,
1420,
63,
890,
12,
1834,
63,
1661,
12,
267,
30154,
304,
272,
1834,
63,
344,
275,
1834,
63,
2024,
459,
344,
418,
272,
2783,
63,
8938,
275,
378,
339,
347,
11705,
63,
1569,
63,
1150,
63,
3664,
8,
1813,
304,
267,
1834,
63,
2254,
63,
6761,
8,
2394,
63,
8938,
12,
1420,
63,
890,
12,
355,
1834,
63,
2024,
12,
1177,
14,
1069,
12,
30154,
9,
339,
327,
2654,
5759,
370,
2112,
2410,
1177,
365,
9999,
4847,
272,
340,
283,
1430,
2723,
14,
1932,
7922,
7,
315,
1177,
14,
1069,
14,
2314,
26,
267,
1177,
14,
1069,
14,
2314,
459,
1430,
2723,
14,
1932,
7922,
2278,
740,
8,
288,
334,
6814,
63,
1569,
63,
1150,
63,
3664,
12,
11969,
17003,
339,
862,
26,
267,
367,
3728,
315,
1834,
63,
1661,
26,
288,
1995,
3728,
288,
2783,
63,
8938,
847,
822,
8,
4604,
9,
272,
871,
2186,
12,
2329,
26,
267,
1499,
275,
3824,
2493,
1125,
8920,
7664,
687,
4865,
4887,
298,
355,
298,
509,
1834,
2818,
1569,
63,
344,
9,
83,
26,
2818,
1508,
9,
83,
531,
450,
9480,
342,
267,
5051,
14,
705,
8,
1328,
9,
267,
746,
339,
340,
1420,
63,
890,
1137,
2783,
63,
8938,
26,
267,
1499,
275,
3824,
8447,
4887,
367,
1834,
2818,
1569,
63,
344,
9,
83,
298,
355,
298,
27476,
2410,
3575,
1454,
2818,
2394,
63,
8938,
9,
68,
298,
355,
298,
2394,
531,
450,
9480,
342,
267,
5051,
14,
705,
8,
1328,
9,
267,
746,
1919,
14,
17541,
554,
1726,
6115,
8380,
6987,
1834,
5235,
367,
298,
5101,
298,
1569,
2818,
1569,
63,
344,
9,
83,
531,
450,
9480,
1012,
421,
199,
318,
1834,
63,
2254,
63,
6761,
8,
2394,
63,
8938,
12,
1420,
63,
890,
12,
1834,
63,
2024,
12,
1056,
12,
267,
30154,
304,
272,
408,
6795,
376,
1834,
14,
2254,
1245,
370,
314,
30154,
1041,
272,
862,
26,
267,
1067,
275,
1056,
14,
1100,
267,
4886,
275,
469,
288,
283,
2394,
63,
1150,
356,
2783,
63,
8938,
12,
288,
283,
1569,
63,
344,
356,
1834,
63,
2024,
459,
344,
995,
288,
283,
4597,
63,
344,
356,
1834,
63,
2024,
459,
4597,
995,
288,
283,
10244,
63,
4647,
63,
344,
356,
1067,
14,
4647,
12,
288,
283,
10244,
63,
751,
63,
344,
356,
1067,
14,
751,
12,
288,
283,
6881,
63,
711,
356,
1056,
14,
3846,
63,
2697,
12,
267,
789,
267,
340,
2783,
63,
8938,
1137,
1420,
63,
890,
26,
288,
11705,
275,
30154,
14,
705,
267,
587,
26,
288,
11705,
275,
30154,
14,
815,
398,
11705,
360,
1569,
14,
2254,
297,
4886,
9,
339,
871,
2186,
12,
2329,
26,
267,
1499,
275,
3824,
2493,
1125,
8920,
5309,
1834,
14,
2254,
2,
355,
298,
6955,
26,
2818,
1508,
9,
83,
531,
450,
9480,
342,
267,
5051,
14,
705,
8,
1328,
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
] |
[
1898,
6029,
14260,
20376,
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,
7554,
199,
199,
504,
21785,
14,
2330,
492,
1919,
199,
504,
21785,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
1568,
63,
10718,
63,
1661,
8,
1310,
12,
1834,
63,
2024,
12,
1420,
63,
890,
12,
1834,
63,
1661,
12,
267,
30154,
304,
272,
1834,
63,
344,
275,
1834,
63,
2024,
459,
344,
418,
272,
2783,
63,
8938,
275,
378,
339,
347,
11705,
63,
1569,
63,
1150,
63,
3664,
8,
1813,
304,
267,
1834,
63,
2254,
63,
6761,
8,
2394,
63,
8938,
12,
1420,
63,
890,
12,
355,
1834,
63,
2024,
12,
1177,
14,
1069,
12,
30154,
9,
339,
327,
2654,
5759,
370,
2112,
2410,
1177,
365,
9999,
4847,
272,
340,
283,
1430,
2723,
14,
1932,
7922,
7,
315,
1177,
14,
1069,
14,
2314,
26,
267,
1177,
14,
1069,
14,
2314,
459,
1430,
2723,
14,
1932,
7922,
2278,
740,
8,
288,
334,
6814,
63,
1569,
63,
1150,
63,
3664,
12,
11969,
17003,
339,
862,
26,
267,
367,
3728,
315,
1834,
63,
1661,
26,
288,
1995,
3728,
288,
2783,
63,
8938,
847,
822,
8,
4604,
9,
272,
871,
2186,
12,
2329,
26,
267,
1499,
275,
3824,
2493,
1125,
8920,
7664,
687,
4865,
4887,
298,
355,
298,
509,
1834,
2818,
1569,
63,
344,
9,
83,
26,
2818,
1508,
9,
83,
531,
450,
9480,
342,
267,
5051,
14,
705,
8,
1328,
9,
267,
746,
339,
340,
1420,
63,
890,
1137,
2783,
63,
8938,
26,
267,
1499,
275,
3824,
8447,
4887,
367,
1834,
2818,
1569,
63,
344,
9,
83,
298,
355,
298,
27476,
2410,
3575,
1454,
2818,
2394,
63,
8938,
9,
68,
298,
355,
298,
2394,
531,
450,
9480,
342,
267,
5051,
14,
705,
8,
1328,
9,
267,
746,
1919,
14,
17541,
554,
1726,
6115,
8380,
6987,
1834,
5235,
367,
298,
5101,
298,
1569,
2818,
1569,
63,
344,
9,
83,
531,
450,
9480,
1012,
421,
199,
318,
1834,
63,
2254,
63,
6761,
8,
2394,
63,
8938,
12,
1420,
63,
890,
12,
1834,
63,
2024,
12,
1056,
12,
267,
30154,
304,
272,
408,
6795,
376,
1834,
14,
2254,
1245,
370,
314,
30154,
1041,
272,
862,
26,
267,
1067,
275,
1056,
14,
1100,
267,
4886,
275,
469,
288,
283,
2394,
63,
1150,
356,
2783,
63,
8938,
12,
288,
283,
1569,
63,
344,
356,
1834,
63,
2024,
459,
344,
995,
288,
283,
4597,
63,
344,
356,
1834,
63,
2024,
459,
4597,
995,
288,
283,
10244,
63,
4647,
63,
344,
356,
1067,
14,
4647,
12,
288,
283,
10244,
63,
751,
63,
344,
356,
1067,
14,
751,
12,
288,
283,
6881,
63,
711,
356,
1056,
14,
3846,
63,
2697,
12,
267,
789,
267,
340,
2783,
63,
8938,
1137,
1420,
63,
890,
26,
288,
11705,
275,
30154,
14,
705,
267,
587,
26,
288,
11705,
275,
30154,
14,
815,
398,
11705,
360,
1569,
14,
2254,
297,
4886,
9,
339,
871,
2186,
12,
2329,
26,
267,
1499,
275,
3824,
2493,
1125,
8920,
5309,
1834,
14,
2254,
2,
355,
298,
6955,
26,
2818,
1508,
9,
83,
531,
450,
9480,
342,
267,
5051,
14,
705,
8,
1328,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tkaitchuck/nupic
|
examples/opf/experiments/multistep/simple_3_sp/description.py
|
2
|
1715
|
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2013, Numenta, Inc. Unless you have purchased from
# Numenta, Inc. a separate commercial license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
## This file defines parameters for a prediction experiment.
import os
from nupic.frameworks.opf.expdescriptionhelpers import importBaseDescription
# the sub-experiment configuration
config = \
{
'dataSource': 'file://' + os.path.join(os.path.dirname(__file__),
'../datasets/simple_3.csv'),
'modelParams': { 'clParams': { 'clVerbosity': 0, 'steps': '1,3'},
'inferenceType': 'NontemporalMultiStep',
'sensorParams': { 'encoders': { }, 'verbosity': 0},
'spParams': { },
'tpParams': { }},
'predictionSteps': [1, 3]}
mod = importBaseDescription('../base/description.py', config)
locals().update(mod.__dict__)
|
gpl-3.0
|
[
3,
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
6171,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
15932,
68,
687,
199,
3,
22783,
12,
3277,
14,
282,
7396,
2414,
23012,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
309,
961,
570,
7890,
2633,
367,
282,
12044,
11805,
14,
199,
199,
646,
747,
199,
504,
26084,
14,
32037,
14,
16893,
14,
1474,
1802,
7546,
492,
492,
1563,
5831,
199,
199,
3,
314,
1007,
13,
10873,
2897,
199,
888,
275,
971,
199,
91,
16421,
283,
576,
2980,
356,
283,
493,
22399,
435,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
221,
1460,
20644,
12281,
15,
4129,
63,
19,
14,
4737,
659,
523,
283,
1238,
6007,
356,
469,
283,
429,
6007,
356,
469,
283,
429,
3673,
5947,
356,
378,
12,
283,
5895,
356,
283,
17,
12,
19,
2267,
673,
283,
20580,
804,
356,
283,
6932,
30574,
3947,
7801,
297,
673,
283,
8956,
6007,
356,
469,
283,
9347,
83,
356,
469,
1660,
283,
9833,
356,
378,
1386,
673,
283,
681,
6007,
356,
469,
1660,
673,
283,
683,
6007,
356,
469,
789,
1386,
523,
283,
14845,
20960,
356,
359,
17,
12,
650,
9420,
199,
199,
1494,
275,
492,
1563,
5831,
24592,
1095,
15,
1802,
14,
647,
297,
1101,
9,
199,
9350,
1252,
873,
8,
1494,
855,
807,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
6171,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
15932,
68,
687,
199,
3,
22783,
12,
3277,
14,
282,
7396,
2414,
23012,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
309,
961,
570,
7890,
2633,
367,
282,
12044,
11805,
14,
199,
199,
646,
747,
199,
504,
26084,
14,
32037,
14,
16893,
14,
1474,
1802,
7546,
492,
492,
1563,
5831,
199,
199,
3,
314,
1007,
13,
10873,
2897,
199,
888,
275,
971,
199,
91,
16421,
283,
576,
2980,
356,
283,
493,
22399,
435,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
221,
1460,
20644,
12281,
15,
4129,
63,
19,
14,
4737,
659,
523,
283,
1238,
6007,
356,
469,
283,
429,
6007,
356,
469,
283,
429,
3673,
5947,
356,
378,
12,
283,
5895,
356,
283,
17,
12,
19,
2267,
673,
283,
20580,
804,
356,
283,
6932,
30574,
3947,
7801,
297,
673,
283,
8956,
6007,
356,
469,
283,
9347,
83,
356,
469,
1660,
283,
9833,
356,
378,
1386,
673,
283,
681,
6007,
356,
469,
1660,
673,
283,
683,
6007,
356,
469,
789,
1386,
523,
283,
14845,
20960,
356,
359,
17,
12,
650,
9420,
199,
199,
1494,
275,
492,
1563,
5831,
24592,
1095,
15,
1802,
14,
647,
297,
1101,
9,
199,
9350,
1252,
873,
8,
1494,
855,
807,
3368,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
perzizzle/ansible-modules-extras
|
cloud/webfaction/webfaction_mailbox.py
|
51
|
4275
|
#!/usr/bin/python
#
# Create webfaction mailbox using Ansible and the Webfaction API
#
# ------------------------------------------
# (c) Quentin Stafford-Fraser and Andy Baker 2015
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
DOCUMENTATION = '''
---
module: webfaction_mailbox
short_description: Add or remove mailboxes on Webfaction
description:
- Add or remove mailboxes on a Webfaction account. Further documentation at http://github.com/quentinsf/ansible-webfaction.
author: Quentin Stafford-Fraser (@quentinsf)
version_added: "2.0"
notes:
- "You can run playbooks that use this on a local machine, or on a Webfaction host, or elsewhere, since the scripts use the remote webfaction API - the location is not important. However, running them on multiple hosts I(simultaneously) is best avoided. If you don't specify I(localhost) as your host, you may want to add C(serial: 1) to the plays."
- See `the webfaction API <http://docs.webfaction.com/xmlrpc-api/>`_ for more info.
options:
mailbox_name:
description:
- The name of the mailbox
required: true
mailbox_password:
description:
- The password for the mailbox
required: true
default: null
state:
description:
- Whether the mailbox should exist
required: false
choices: ['present', 'absent']
default: "present"
login_name:
description:
- The webfaction account to use
required: true
login_password:
description:
- The webfaction password to use
required: true
'''
EXAMPLES = '''
- name: Create a mailbox
webfaction_mailbox:
mailbox_name="mybox"
mailbox_password="myboxpw"
state=present
login_name={{webfaction_user}}
login_password={{webfaction_passwd}}
'''
import socket
import xmlrpclib
webfaction = xmlrpclib.ServerProxy('https://api.webfaction.com/')
def main():
module = AnsibleModule(
argument_spec=dict(
mailbox_name=dict(required=True),
mailbox_password=dict(required=True),
state=dict(required=False, choices=['present', 'absent'], default='present'),
login_name=dict(required=True),
login_password=dict(required=True),
),
supports_check_mode=True
)
mailbox_name = module.params['mailbox_name']
site_state = module.params['state']
session_id, account = webfaction.login(
module.params['login_name'],
module.params['login_password']
)
mailbox_list = webfaction.list_mailboxes(session_id)
existing_mailbox = mailbox_name in mailbox_list
result = {}
# Here's where the real stuff happens
if site_state == 'present':
# Does a mailbox with this name already exist?
if existing_mailbox:
module.exit_json(changed=False,)
positional_args = [session_id, mailbox_name]
if not module.check_mode:
# If this isn't a dry run, create the mailbox
result.update(webfaction.create_mailbox(*positional_args))
elif site_state == 'absent':
# If the mailbox is already not there, nothing changed.
if not existing_mailbox:
module.exit_json(changed=False)
if not module.check_mode:
# If this isn't a dry run, delete the mailbox
result.update(webfaction.delete_mailbox(session_id, mailbox_name))
else:
module.fail_json(msg="Unknown state specified: {}".format(site_state))
module.exit_json(changed=True, result=result)
from ansible.module_utils.basic import *
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
2790,
3330,
17287,
17470,
1808,
2622,
436,
314,
6001,
17287,
3261,
199,
3,
199,
3,
11016,
9460,
199,
3,
334,
67,
9,
5843,
484,
262,
7083,
70,
18090,
13,
38,
345,
332,
436,
6061,
89,
699,
12630,
6900,
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,
8948,
275,
1449,
199,
2595,
199,
578,
26,
3330,
17287,
63,
21869,
199,
3612,
63,
1802,
26,
2654,
503,
2813,
6016,
12922,
641,
6001,
17287,
199,
1802,
26,
272,
446,
2654,
503,
2813,
6016,
12922,
641,
282,
6001,
17287,
2933,
14,
28876,
3794,
737,
1455,
921,
5031,
14,
957,
15,
9333,
3617,
70,
15,
4853,
13,
2520,
17287,
14,
199,
2502,
26,
5843,
484,
262,
7083,
70,
18090,
13,
38,
345,
332,
8593,
9333,
3617,
70,
9,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
5983,
26,
272,
446,
298,
5556,
883,
1255,
5232,
8858,
626,
675,
642,
641,
282,
2257,
6844,
12,
503,
641,
282,
6001,
17287,
1591,
12,
503,
25320,
12,
3967,
314,
10554,
675,
314,
3982,
3330,
17287,
3261,
446,
314,
2909,
365,
440,
11012,
14,
9738,
12,
3879,
3062,
641,
3663,
7057,
473,
8,
5206,
24657,
590,
9,
365,
5526,
2289,
16142,
770,
14,
982,
1265,
2793,
1133,
4165,
473,
8,
5967,
9,
465,
2195,
1591,
12,
1265,
1443,
2934,
370,
1050,
445,
8,
2171,
26,
413,
9,
370,
314,
299,
9316,
2122,
272,
446,
1666,
658,
1589,
3330,
17287,
3261,
665,
1014,
921,
4757,
14,
2520,
17287,
14,
957,
15,
17596,
13,
1246,
3133,
18417,
367,
1655,
2256,
14,
199,
1419,
26,
339,
17470,
63,
354,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
17470,
267,
1415,
26,
2549,
339,
17470,
63,
2060,
26,
267,
1369,
26,
288,
446,
710,
2505,
367,
314,
17470,
267,
1415,
26,
2549,
267,
849,
26,
2973,
339,
1174,
26,
267,
1369,
26,
288,
446,
7480,
314,
17470,
1077,
2187,
267,
1415,
26,
3055,
267,
3415,
26,
788,
1881,
297,
283,
5575,
418,
267,
849,
26,
298,
1881,
2,
339,
4676,
63,
354,
26,
267,
1369,
26,
288,
446,
710,
3330,
17287,
2933,
370,
675,
267,
1415,
26,
2549,
339,
4676,
63,
2060,
26,
267,
1369,
26,
288,
446,
710,
3330,
17287,
2505,
370,
675,
267,
1415,
26,
2549,
199,
2344,
199,
199,
8918,
275,
1449,
523,
446,
536,
26,
2790,
282,
17470,
272,
3330,
17287,
63,
21869,
26,
489,
17470,
63,
354,
628,
1662,
1977,
2,
489,
17470,
63,
2060,
628,
1662,
1977,
8796,
2,
489,
1174,
29,
1881,
489,
4676,
63,
354,
3126,
91,
2520,
17287,
63,
751,
4863,
489,
4676,
63,
2060,
3126,
91,
2520,
17287,
63,
12671,
4863,
199,
2344,
199,
199,
646,
2838,
199,
646,
19122,
199,
199,
2520,
17287,
275,
19122,
14,
3120,
4936,
360,
2859,
921,
1246,
14,
2520,
17287,
14,
957,
6217,
199,
199,
318,
2446,
837,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
807,
8,
288,
17470,
63,
354,
29,
807,
8,
2427,
29,
549,
395,
288,
17470,
63,
2060,
29,
807,
8,
2427,
29,
549,
395,
288,
1174,
29,
807,
8,
2427,
29,
797,
12,
3415,
2968,
1881,
297,
283,
5575,
995,
849,
534,
1881,
659,
288,
4676,
63,
354,
29,
807,
8,
2427,
29,
549,
395,
288,
4676,
63,
2060,
29,
807,
8,
2427,
29,
549,
395,
267,
2318,
267,
5171,
63,
1074,
63,
632,
29,
549,
272,
776,
339,
17470,
63,
354,
275,
859,
14,
1162,
459,
21869,
63,
354,
418,
272,
4770,
63,
929,
275,
859,
14,
1162,
459,
929,
418,
339,
2351,
63,
344,
12,
2933,
275,
3330,
17287,
14,
2886,
8,
267,
859,
14,
1162,
459,
2886,
63,
354,
995,
267,
859,
14,
1162,
459,
2886,
63,
2060,
418,
272,
776,
339,
17470,
63,
513,
275,
3330,
17287,
14,
513,
63,
1198,
12922,
8,
1730,
63,
344,
9,
272,
3411,
63,
21869,
275,
17470,
63,
354,
315,
17470,
63,
513,
339,
754,
275,
1052,
2286,
327,
11842,
1159,
2382,
314,
3363,
8292,
10986,
339,
340,
4770,
63,
929,
508,
283,
1881,
356,
398,
327,
12078,
282,
17470,
543,
642,
536,
2575,
2187,
31,
267,
340,
3411,
63,
21869,
26,
288,
859,
14,
2224,
63,
1001,
8,
2489,
29,
797,
4258,
398,
11333,
63,
589,
275,
359,
1730,
63,
344,
12,
17470,
63,
354,
61,
398,
340,
440,
859,
14,
1074,
63,
632,
26,
288,
327,
982,
642,
5712,
1133,
282,
9951,
1255,
12,
1218,
314,
17470,
288,
754,
14,
873,
8,
2520,
17287,
14,
981,
63,
21869,
2031,
17867,
63,
589,
430,
339,
916,
4770,
63,
929,
508,
283,
5575,
356,
398,
327,
982,
314,
17470,
365,
2575,
440,
2337,
12,
6548,
2896,
14,
267,
340,
440,
3411,
63,
21869,
26,
288,
859,
14,
2224,
63,
1001,
8,
2489,
29,
797,
9,
398,
340,
440,
859,
14,
1074,
63,
632,
26,
288,
327,
982,
642,
5712,
1133,
282,
9951,
1255,
12,
3145,
314,
17470,
288,
754,
14,
873,
8,
2520,
17287,
14,
1807,
63,
21869,
8,
1730,
63,
344,
12,
17470,
63,
354,
430,
339,
587,
26,
267,
859,
14,
1633,
63,
1001,
8,
1328,
628,
5912,
1174,
2013,
26,
8352,
908,
8,
2124,
63,
929,
430,
339,
859,
14,
2224,
63,
1001,
8,
2489,
29,
549,
12,
754,
29,
1099
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
2790,
3330,
17287,
17470,
1808,
2622,
436,
314,
6001,
17287,
3261,
199,
3,
199,
3,
11016,
9460,
199,
3,
334,
67,
9,
5843,
484,
262,
7083,
70,
18090,
13,
38,
345,
332,
436,
6061,
89,
699,
12630,
6900,
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,
8948,
275,
1449,
199,
2595,
199,
578,
26,
3330,
17287,
63,
21869,
199,
3612,
63,
1802,
26,
2654,
503,
2813,
6016,
12922,
641,
6001,
17287,
199,
1802,
26,
272,
446,
2654,
503,
2813,
6016,
12922,
641,
282,
6001,
17287,
2933,
14,
28876,
3794,
737,
1455,
921,
5031,
14,
957,
15,
9333,
3617,
70,
15,
4853,
13,
2520,
17287,
14,
199,
2502,
26,
5843,
484,
262,
7083,
70,
18090,
13,
38,
345,
332,
8593,
9333,
3617,
70,
9,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
5983,
26,
272,
446,
298,
5556,
883,
1255,
5232,
8858,
626,
675,
642,
641,
282,
2257,
6844,
12,
503,
641,
282,
6001,
17287,
1591,
12,
503,
25320,
12,
3967,
314,
10554,
675,
314,
3982,
3330,
17287,
3261,
446,
314,
2909,
365,
440,
11012,
14,
9738,
12,
3879,
3062,
641,
3663,
7057,
473,
8,
5206,
24657,
590,
9,
365,
5526,
2289,
16142,
770,
14,
982,
1265,
2793,
1133,
4165,
473,
8,
5967,
9,
465,
2195,
1591,
12,
1265,
1443,
2934,
370,
1050,
445,
8,
2171,
26,
413,
9,
370,
314,
299,
9316,
2122,
272,
446,
1666,
658,
1589,
3330,
17287,
3261,
665,
1014,
921,
4757,
14,
2520,
17287,
14,
957,
15,
17596,
13,
1246,
3133,
18417,
367,
1655,
2256,
14,
199,
1419,
26,
339,
17470,
63,
354,
26,
267,
1369,
26,
288,
446,
710,
536,
402,
314,
17470,
267,
1415,
26,
2549,
339,
17470,
63,
2060,
26,
267,
1369,
26,
288,
446,
710,
2505,
367,
314,
17470,
267,
1415,
26,
2549,
267,
849,
26,
2973,
339,
1174,
26,
267,
1369,
26,
288,
446,
7480,
314,
17470,
1077,
2187,
267,
1415,
26,
3055,
267,
3415,
26,
788,
1881,
297,
283,
5575,
418,
267,
849,
26,
298,
1881,
2,
339,
4676,
63,
354,
26,
267,
1369,
26,
288,
446,
710,
3330,
17287,
2933,
370,
675,
267,
1415,
26,
2549,
339,
4676,
63,
2060,
26,
267,
1369,
26,
288,
446,
710,
3330,
17287,
2505,
370,
675,
267,
1415,
26,
2549,
199,
2344,
199,
199,
8918,
275,
1449,
523,
446,
536,
26,
2790,
282,
17470,
272,
3330,
17287,
63,
21869,
26,
489,
17470,
63,
354,
628,
1662,
1977,
2,
489,
17470,
63,
2060,
628,
1662,
1977,
8796,
2,
489,
1174,
29,
1881,
489,
4676,
63,
354,
3126,
91,
2520,
17287,
63,
751,
4863,
489,
4676,
63,
2060,
3126,
91,
2520,
17287,
63,
12671,
4863,
199,
2344,
199,
199,
646,
2838,
199,
646,
19122,
199,
199,
2520,
17287,
275,
19122,
14,
3120,
4936,
360,
2859,
921,
1246,
14,
2520,
17287,
14,
957,
6217,
199,
199,
318,
2446,
837,
339,
859,
275,
6953,
8,
267,
1423,
63,
1650,
29,
807,
8,
288,
17470,
63,
354,
29,
807,
8,
2427,
29,
549,
395,
288,
17470,
63,
2060,
29,
807,
8,
2427,
29,
549,
395,
288,
1174,
29,
807,
8,
2427,
29,
797,
12,
3415,
2968,
1881,
297,
283,
5575,
995,
849,
534,
1881,
659,
288,
4676,
63,
354,
29,
807,
8,
2427,
29,
549,
395,
288,
4676,
63,
2060,
29,
807,
8,
2427,
29,
549,
395,
267,
2318,
267,
5171,
63,
1074,
63,
632,
29,
549,
272,
776,
339,
17470,
63,
354,
275,
859,
14,
1162,
459,
21869,
63,
354,
418,
272,
4770,
63,
929,
275,
859,
14,
1162,
459,
929,
418,
339,
2351,
63,
344,
12,
2933,
275,
3330,
17287,
14,
2886,
8,
267,
859,
14,
1162,
459,
2886,
63,
354,
995,
267,
859,
14,
1162,
459,
2886,
63,
2060,
418,
272,
776,
339,
17470,
63,
513,
275,
3330,
17287,
14,
513,
63,
1198,
12922,
8,
1730,
63,
344,
9,
272,
3411,
63,
21869,
275,
17470,
63,
354,
315,
17470,
63,
513,
339,
754,
275,
1052,
2286,
327,
11842,
1159,
2382,
314,
3363,
8292,
10986,
339,
340,
4770,
63,
929,
508,
283,
1881,
356,
398,
327,
12078,
282,
17470,
543,
642,
536,
2575,
2187,
31,
267,
340,
3411,
63,
21869,
26,
288,
859,
14,
2224,
63,
1001,
8,
2489,
29,
797,
4258,
398,
11333,
63,
589,
275,
359,
1730,
63,
344,
12,
17470,
63,
354,
61,
398,
340,
440,
859,
14,
1074,
63,
632,
26,
288,
327,
982,
642,
5712,
1133,
282,
9951,
1255,
12,
1218,
314,
17470,
288,
754,
14,
873,
8,
2520,
17287,
14,
981,
63,
21869,
2031,
17867,
63,
589,
430,
339,
916,
4770,
63,
929,
508,
283,
5575,
356,
398,
327,
982,
314,
17470,
365,
2575,
440,
2337,
12,
6548,
2896,
14,
267,
340,
440,
3411,
63,
21869,
26,
288,
859,
14,
2224,
63,
1001,
8,
2489,
29,
797,
9,
398,
340,
440,
859,
14,
1074,
63,
632,
26,
288,
327,
982,
642,
5712,
1133,
282,
9951,
1255,
12,
3145,
314,
17470,
288,
754,
14,
873,
8,
2520,
17287,
14,
1807,
63,
21869,
8,
1730,
63,
344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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
] |
gdi2290/django
|
django/contrib/gis/tests/geoapp/test_sitemaps.py
|
28
|
3390
|
from __future__ import unicode_literals
from io import BytesIO
from xml.dom import minidom
import warnings
import zipfile
from django.conf import settings
from django.contrib.gis.geos import HAS_GEOS
from django.contrib.sites.models import Site
from django.test import (
TestCase, modify_settings, override_settings, skipUnlessDBFeature
)
from django.utils.deprecation import RemovedInDjango20Warning
if HAS_GEOS:
from .models import City, Country
@modify_settings(INSTALLED_APPS={'append': ['django.contrib.sites', 'django.contrib.sitemaps']})
@override_settings(ROOT_URLCONF='django.contrib.gis.tests.geoapp.urls')
@skipUnlessDBFeature("gis_enabled")
class GeoSitemapTest(TestCase):
def setUp(self):
super(GeoSitemapTest, self).setUp()
Site(id=settings.SITE_ID, domain="example.com", name="example.com").save()
def assertChildNodes(self, elem, expected):
"Taken from syndication/tests.py."
actual = set(n.nodeName for n in elem.childNodes)
expected = set(expected)
self.assertEqual(actual, expected)
def test_geositemap_kml(self):
"Tests KML/KMZ geographic sitemaps."
for kml_type in ('kml', 'kmz'):
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=RemovedInDjango20Warning)
# The URL for the sitemaps in urls.py have been updated
# with a name but since reversing by Python path is tried first
# before reversing by name and works since we're giving
# name='django.contrib.gis.sitemaps.views.(kml|kmz)', we need
# to silence the erroneous warning until reversing by dotted
# path is removed. The test will work without modification when
# it's removed.
doc = minidom.parseString(self.client.get('/sitemaps/%s.xml' % kml_type).content)
# Ensuring the right sitemaps namespace is present.
urlset = doc.firstChild
self.assertEqual(urlset.getAttribute('xmlns'), 'http://www.sitemaps.org/schemas/sitemap/0.9')
urls = urlset.getElementsByTagName('url')
self.assertEqual(2, len(urls)) # Should only be 2 sitemaps.
for url in urls:
self.assertChildNodes(url, ['loc'])
# Getting the relative URL since we don't have a real site.
kml_url = url.getElementsByTagName('loc')[0].childNodes[0].data.split('http://example.com')[1]
if kml_type == 'kml':
kml_doc = minidom.parseString(self.client.get(kml_url).content)
elif kml_type == 'kmz':
# Have to decompress KMZ before parsing.
buf = BytesIO(self.client.get(kml_url).content)
zf = zipfile.ZipFile(buf)
self.assertEqual(1, len(zf.filelist))
self.assertEqual('doc.kml', zf.filelist[0].filename)
kml_doc = minidom.parseString(zf.read('doc.kml'))
# Ensuring the correct number of placemarks are in the KML doc.
if 'city' in kml_url:
model = City
elif 'country' in kml_url:
model = Country
self.assertEqual(model.objects.count(), len(kml_doc.getElementsByTagName('Placemark')))
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
5890,
492,
11808,
199,
504,
2748,
14,
4556,
492,
19165,
199,
646,
3598,
199,
646,
10392,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
492,
7509,
63,
14151,
199,
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
199,
504,
1639,
14,
396,
492,
334,
272,
7640,
12,
2811,
63,
1751,
12,
4278,
63,
1751,
12,
3372,
5524,
18093,
199,
9,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1165,
3849,
199,
199,
692,
7509,
63,
14151,
26,
272,
687,
1275,
992,
492,
14753,
12,
19453,
421,
199,
32,
8951,
63,
1751,
8,
15942,
63,
14219,
3713,
740,
356,
788,
1176,
14,
2828,
14,
8619,
297,
283,
1176,
14,
2828,
14,
30515,
13678,
199,
32,
4415,
63,
1751,
8,
5441,
63,
18125,
534,
1176,
14,
2828,
14,
5668,
14,
2219,
14,
6721,
571,
14,
3603,
358,
199,
32,
22424,
480,
5668,
63,
3827,
531,
199,
533,
8875,
8972,
1130,
774,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
10748,
8972,
1130,
774,
12,
291,
680,
5996,
342,
267,
11666,
8,
344,
29,
1751,
14,
7917,
63,
998,
12,
2881,
628,
2694,
14,
957,
401,
536,
628,
2694,
14,
957,
3471,
2117,
342,
339,
347,
702,
3493,
6300,
8,
277,
12,
6193,
12,
1420,
304,
267,
298,
22620,
917,
687,
9560,
21171,
15,
2219,
14,
647,
2122,
267,
3503,
275,
663,
8,
78,
14,
13777,
367,
302,
315,
6193,
14,
10626,
9,
267,
1420,
275,
663,
8,
2062,
9,
267,
291,
14,
629,
8,
6514,
12,
1420,
9,
339,
347,
511,
63,
6721,
17205,
63,
21351,
8,
277,
304,
267,
298,
2925,
1804,
1698,
15,
43,
45,
58,
25637,
4770,
8919,
2122,
267,
367,
1022,
757,
63,
466,
315,
661,
21351,
297,
283,
14595,
90,
735,
288,
543,
3598,
14,
9341,
63,
5451,
837,
355,
3598,
14,
23945,
480,
4247,
401,
4637,
29,
497,
19797,
1165,
3849,
9,
355,
327,
710,
2851,
367,
314,
4770,
8919,
315,
8187,
14,
647,
1172,
2757,
4588,
355,
327,
543,
282,
536,
1325,
3967,
29465,
1044,
701,
2018,
931,
365,
16416,
1642,
355,
327,
2544,
29465,
1044,
701,
536,
436,
5419,
3967,
781,
3984,
15131,
355,
327,
536,
534,
1176,
14,
2828,
14,
5668,
14,
30515,
14,
4196,
14,
8,
21351,
92,
14595,
90,
3196,
781,
1929,
355,
327,
370,
9767,
21225,
314,
2329,
368,
1785,
5721,
5133,
29465,
1044,
701,
18947,
355,
327,
931,
365,
4829,
14,
710,
511,
911,
1736,
1928,
7100,
1380,
355,
327,
652,
1159,
4829,
14,
355,
1382,
275,
19165,
14,
14934,
8,
277,
14,
1258,
14,
362,
2336,
30515,
3149,
83,
14,
1652,
7,
450,
1022,
757,
63,
466,
680,
1317,
9,
953,
327,
23312,
4039,
314,
2451,
4770,
8919,
3231,
365,
3451,
14,
288,
1166,
409,
275,
1382,
14,
22262,
288,
291,
14,
629,
8,
633,
409,
14,
12956,
360,
13991,
659,
283,
1014,
921,
1544,
14,
30515,
14,
1308,
15,
9482,
15,
17205,
15,
16,
14,
25,
358,
953,
8187,
275,
1166,
409,
14,
15045,
360,
633,
358,
288,
291,
14,
629,
8,
18,
12,
822,
8,
3603,
430,
221,
327,
7719,
1454,
506,
499,
4770,
8919,
14,
288,
367,
1166,
315,
8187,
26,
355,
291,
14,
479,
3493,
6300,
8,
633,
12,
788,
2102,
1105,
2234,
327,
20703,
314,
3847,
2851,
3967,
781,
2793,
1133,
1172,
282,
3363,
4770,
14,
355,
1022,
757,
63,
633,
275,
1166,
14,
15045,
360,
2102,
5832,
16,
1055,
10626,
59,
16,
1055,
576,
14,
1294,
360,
1014,
921,
2694,
14,
957,
5832,
17,
61,
2234,
340,
1022,
757,
63,
466,
508,
283,
21351,
356,
490,
1022,
757,
63,
1301,
275,
19165,
14,
14934,
8,
277,
14,
1258,
14,
362,
8,
21351,
63,
633,
680,
1317,
9,
355,
916,
1022,
757,
63,
466,
508,
283,
14595,
90,
356,
490,
327,
26858,
370,
24733,
1804,
45,
58,
2544,
6057,
14,
490,
4123,
275,
11808,
8,
277,
14,
1258,
14,
362,
8,
21351,
63,
633,
680,
1317,
9,
490,
20194,
275,
10392,
14,
15016,
8,
1436,
9,
490,
291,
14,
629,
8,
17,
12,
822,
8,
20127,
14,
14964,
430,
490,
291,
14,
629,
360,
1301,
14,
21351,
297,
20194,
14,
14964,
59,
16,
1055,
1501,
9,
490,
1022,
757,
63,
1301,
275,
19165,
14,
14934,
8,
20127,
14,
739,
360,
1301,
14,
21351,
1333,
2234,
327,
23312,
4039,
314,
3211,
1329,
402,
4192,
10375,
787,
315,
314,
1804,
1698,
1382,
14,
355,
340,
283,
3690,
7,
315,
1022,
757,
63,
633,
26,
490,
1402,
275,
14753,
355,
916,
283,
6063,
7,
315,
1022,
757,
63,
633,
26,
490,
1402,
275,
19453,
355,
291,
14,
629,
8,
1238,
14,
1462,
14,
835,
1062,
822,
8,
21351,
63,
1301,
14,
15045,
360,
11613,
1657,
7058,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
5890,
492,
11808,
199,
504,
2748,
14,
4556,
492,
19165,
199,
646,
3598,
199,
646,
10392,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
492,
7509,
63,
14151,
199,
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
199,
504,
1639,
14,
396,
492,
334,
272,
7640,
12,
2811,
63,
1751,
12,
4278,
63,
1751,
12,
3372,
5524,
18093,
199,
9,
199,
504,
1639,
14,
1208,
14,
15383,
492,
23687,
1165,
3849,
199,
199,
692,
7509,
63,
14151,
26,
272,
687,
1275,
992,
492,
14753,
12,
19453,
421,
199,
32,
8951,
63,
1751,
8,
15942,
63,
14219,
3713,
740,
356,
788,
1176,
14,
2828,
14,
8619,
297,
283,
1176,
14,
2828,
14,
30515,
13678,
199,
32,
4415,
63,
1751,
8,
5441,
63,
18125,
534,
1176,
14,
2828,
14,
5668,
14,
2219,
14,
6721,
571,
14,
3603,
358,
199,
32,
22424,
480,
5668,
63,
3827,
531,
199,
533,
8875,
8972,
1130,
774,
8,
1746,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
10748,
8972,
1130,
774,
12,
291,
680,
5996,
342,
267,
11666,
8,
344,
29,
1751,
14,
7917,
63,
998,
12,
2881,
628,
2694,
14,
957,
401,
536,
628,
2694,
14,
957,
3471,
2117,
342,
339,
347,
702,
3493,
6300,
8,
277,
12,
6193,
12,
1420,
304,
267,
298,
22620,
917,
687,
9560,
21171,
15,
2219,
14,
647,
2122,
267,
3503,
275,
663,
8,
78,
14,
13777,
367,
302,
315,
6193,
14,
10626,
9,
267,
1420,
275,
663,
8,
2062,
9,
267,
291,
14,
629,
8,
6514,
12,
1420,
9,
339,
347,
511,
63,
6721,
17205,
63,
21351,
8,
277,
304,
267,
298,
2925,
1804,
1698,
15,
43,
45,
58,
25637,
4770,
8919,
2122,
267,
367,
1022,
757,
63,
466,
315,
661,
21351,
297,
283,
14595,
90,
735,
288,
543,
3598,
14,
9341,
63,
5451,
837,
355,
3598,
14,
23945,
480,
4247,
401,
4637,
29,
497,
19797,
1165,
3849,
9,
355,
327,
710,
2851,
367,
314,
4770,
8919,
315,
8187,
14,
647,
1172,
2757,
4588,
355,
327,
543,
282,
536,
1325,
3967,
29465,
1044,
701,
2018,
931,
365,
16416,
1642,
355,
327,
2544,
29465,
1044,
701,
536,
436,
5419,
3967,
781,
3984,
15131,
355,
327,
536,
534,
1176,
14,
2828,
14,
5668,
14,
30515,
14,
4196,
14,
8,
21351,
92,
14595,
90,
3196,
781,
1929,
355,
327,
370,
9767,
21225,
314,
2329,
368,
1785,
5721,
5133,
29465,
1044,
701,
18947,
355,
327,
931,
365,
4829,
14,
710,
511,
911,
1736,
1928,
7100,
1380,
355,
327,
652,
1159,
4829,
14,
355,
1382,
275,
19165,
14,
14934,
8,
277,
14,
1258,
14,
362,
2336,
30515,
3149,
83,
14,
1652,
7,
450,
1022,
757,
63,
466,
680,
1317,
9,
953,
327,
23312,
4039,
314,
2451,
4770,
8919,
3231,
365,
3451,
14,
288,
1166,
409,
275,
1382,
14,
22262,
288,
291,
14,
629,
8,
633,
409,
14,
12956,
360,
13991,
659,
283,
1014,
921,
1544,
14,
30515,
14,
1308,
15,
9482,
15,
17205,
15,
16,
14,
25,
358,
953,
8187,
275,
1166,
409,
14,
15045,
360,
633,
358,
288,
291,
14,
629,
8,
18,
12,
822,
8,
3603,
430,
221,
327,
7719,
1454,
506,
499,
4770,
8919,
14,
288,
367,
1166,
315,
8187,
26,
355,
291,
14,
479,
3493,
6300,
8,
633,
12,
788,
2102,
1105,
2234,
327,
20703,
314,
3847,
2851,
3967,
781,
2793,
1133,
1172,
282,
3363,
4770,
14,
355,
1022,
757,
63,
633,
275,
1166,
14,
15045,
360,
2102,
5832,
16,
1055,
10626,
59,
16,
1055,
576,
14,
1294,
360,
1014,
921,
2694,
14,
957,
5832,
17,
61,
2234,
340,
1022,
757,
63,
466,
508,
283,
21351,
356,
490,
1022,
757,
63,
1301,
275,
19165,
14,
14934,
8,
277,
14,
1258,
14,
362,
8,
21351,
63,
633,
680,
1317,
9,
355,
916,
1022,
757,
63,
466,
508,
283,
14595,
90,
356,
490,
327,
26858,
370,
24733,
1804,
45,
58,
2544,
6057,
14,
490,
4123,
275,
11808,
8,
277,
14,
1258,
14,
362,
8,
21351,
63,
633,
680,
1317,
9,
490,
20194,
275,
10392,
14,
15016,
8,
1436,
9,
490,
291,
14,
629,
8,
17,
12,
822,
8,
20127,
14,
14964,
430,
490,
291,
14,
629,
360,
1301,
14,
21351,
297,
20194,
14,
14964,
59,
16,
1055,
1501,
9,
490,
1022,
757,
63,
1301,
275,
19165,
14,
14934,
8,
20127,
14,
739,
360,
1301,
14,
21351,
1333,
2234,
327,
23312,
4039,
314,
3211,
1329,
402,
4192,
10375,
787,
315,
314,
1804,
1698,
1382,
14,
355,
340,
283,
3690,
7,
315,
1022,
757,
63,
633,
26,
490,
1402,
275,
14753,
355,
916,
283,
6063,
7,
315,
1022,
757,
63,
633,
26,
490,
1402,
275,
19453,
355,
291,
14,
629,
8,
1238,
14,
1462,
14,
835,
1062,
822,
8,
21351,
63,
1301,
14,
15045,
360,
11613,
1657,
7058,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
azaghal/ansible
|
test/lib/ansible_test/_internal/payload.py
|
21
|
5772
|
"""Payload management for sending Ansible files and test content to other systems (VMs, containers)."""
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import atexit
import os
import stat
import tarfile
import tempfile
import time
from . import types as t
from .config import (
IntegrationConfig,
ShellConfig,
)
from .util import (
display,
ANSIBLE_SOURCE_ROOT,
remove_tree,
is_subdir,
)
from .data import (
data_context,
)
from .util_common import (
CommonConfig,
)
# improve performance by disabling uid/gid lookups
tarfile.pwd = None
tarfile.grp = None
# this bin symlink map must exactly match the contents of the bin directory
# it is necessary for payload creation to reconstruct the bin directory when running ansible-test from an installed version of ansible
ANSIBLE_BIN_SYMLINK_MAP = {
'ansible': '../lib/ansible/cli/scripts/ansible_cli_stub.py',
'ansible-config': 'ansible',
'ansible-connection': '../lib/ansible/cli/scripts/ansible_connection_cli_stub.py',
'ansible-console': 'ansible',
'ansible-doc': 'ansible',
'ansible-galaxy': 'ansible',
'ansible-inventory': 'ansible',
'ansible-playbook': 'ansible',
'ansible-pull': 'ansible',
'ansible-test': '../test/lib/ansible_test/_data/cli/ansible_test_cli_stub.py',
'ansible-vault': 'ansible',
}
def create_payload(args, dst_path): # type: (CommonConfig, str) -> None
"""Create a payload for delegation."""
if args.explain:
return
files = list(data_context().ansible_source)
filters = {}
def make_executable(tar_info): # type: (tarfile.TarInfo) -> t.Optional[tarfile.TarInfo]
"""Make the given file executable."""
tar_info.mode |= stat.S_IXUSR | stat.S_IXOTH | stat.S_IXGRP
return tar_info
if not ANSIBLE_SOURCE_ROOT:
# reconstruct the bin directory which is not available when running from an ansible install
files.extend(create_temporary_bin_files(args))
filters.update(dict((os.path.join('ansible', path[3:]), make_executable) for path in ANSIBLE_BIN_SYMLINK_MAP.values() if path.startswith('../')))
if not data_context().content.is_ansible:
# exclude unnecessary files when not testing ansible itself
files = [f for f in files if
is_subdir(f[1], 'bin/') or
is_subdir(f[1], 'lib/ansible/') or
is_subdir(f[1], 'test/lib/ansible_test/')]
if not isinstance(args, (ShellConfig, IntegrationConfig)):
# exclude built-in ansible modules when they are not needed
files = [f for f in files if not is_subdir(f[1], 'lib/ansible/modules/') or f[1] == 'lib/ansible/modules/__init__.py']
collection_layouts = data_context().create_collection_layouts()
content_files = []
extra_files = []
for layout in collection_layouts:
if layout == data_context().content:
# include files from the current collection (layout.collection.directory will be added later)
content_files.extend((os.path.join(layout.root, path), path) for path in data_context().content.all_files())
else:
# include files from each collection in the same collection root as the content being tested
extra_files.extend((os.path.join(layout.root, path), os.path.join(layout.collection.directory, path)) for path in layout.all_files())
else:
# when testing ansible itself the ansible source is the content
content_files = files
# there are no extra files when testing ansible itself
extra_files = []
for callback in data_context().payload_callbacks:
# execute callbacks only on the content paths
# this is done before placing them in the appropriate subdirectory (see below)
callback(content_files)
# place ansible source files under the 'ansible' directory on the delegated host
files = [(src, os.path.join('ansible', dst)) for src, dst in files]
if data_context().content.collection:
# place collection files under the 'ansible_collections/{namespace}/{collection}' directory on the delegated host
files.extend((src, os.path.join(data_context().content.collection.directory, dst)) for src, dst in content_files)
# extra files already have the correct destination path
files.extend(extra_files)
# maintain predictable file order
files = sorted(set(files))
display.info('Creating a payload archive containing %d files...' % len(files), verbosity=1)
start = time.time()
with tarfile.TarFile.open(dst_path, mode='w:gz', compresslevel=4, format=tarfile.GNU_FORMAT) as tar:
for src, dst in files:
display.info('%s -> %s' % (src, dst), verbosity=4)
tar.add(src, dst, filter=filters.get(dst))
duration = time.time() - start
payload_size_bytes = os.path.getsize(dst_path)
display.info('Created a %d byte payload archive containing %d files in %d seconds.' % (payload_size_bytes, len(files), duration), verbosity=1)
def create_temporary_bin_files(args): # type: (CommonConfig) -> t.Tuple[t.Tuple[str, str], ...]
"""Create a temporary ansible bin directory populated using the symlink map."""
if args.explain:
temp_path = '/tmp/ansible-tmp-bin'
else:
temp_path = tempfile.mkdtemp(prefix='ansible', suffix='bin')
atexit.register(remove_tree, temp_path)
for name, dest in ANSIBLE_BIN_SYMLINK_MAP.items():
path = os.path.join(temp_path, name)
os.symlink(dest, path)
return tuple((os.path.join(temp_path, name), os.path.join('bin', name)) for name in sorted(ANSIBLE_BIN_SYMLINK_MAP))
|
gpl-3.0
|
[
624,
17215,
10041,
367,
10209,
2622,
1584,
436,
511,
1564,
370,
1163,
10460,
334,
6849,
83,
12,
15333,
10477,
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,
19840,
199,
646,
747,
199,
646,
5672,
199,
646,
13608,
199,
646,
5549,
199,
646,
900,
199,
199,
504,
1275,
492,
2943,
465,
307,
199,
199,
504,
1275,
888,
492,
334,
272,
27561,
2028,
12,
272,
24599,
2028,
12,
199,
9,
199,
199,
504,
1275,
1974,
492,
334,
272,
2929,
12,
272,
32271,
7187,
63,
10187,
63,
5441,
12,
272,
2813,
63,
2350,
12,
272,
365,
63,
10622,
12,
199,
9,
199,
199,
504,
1275,
576,
492,
334,
272,
666,
63,
1100,
12,
199,
9,
199,
199,
504,
1275,
1974,
63,
2330,
492,
334,
272,
13964,
2028,
12,
199,
9,
199,
199,
3,
19053,
10238,
701,
30723,
1747,
15,
8787,
16807,
199,
19862,
14,
14258,
275,
488,
199,
19862,
14,
12599,
275,
488,
199,
199,
3,
642,
2517,
15296,
2341,
1471,
8840,
1336,
314,
4072,
402,
314,
2517,
2082,
199,
3,
652,
365,
5784,
367,
4886,
7143,
370,
28462,
314,
2517,
2082,
1380,
3879,
3242,
13,
396,
687,
376,
4903,
1015,
402,
3242,
199,
8490,
63,
9431,
63,
4669,
1698,
12394,
63,
5443,
275,
469,
272,
283,
4853,
356,
20644,
773,
15,
4853,
15,
2764,
15,
6429,
15,
4853,
63,
2764,
63,
5811,
14,
647,
297,
272,
283,
4853,
13,
888,
356,
283,
4853,
297,
272,
283,
4853,
13,
2105,
356,
20644,
773,
15,
4853,
15,
2764,
15,
6429,
15,
4853,
63,
2105,
63,
2764,
63,
5811,
14,
647,
297,
272,
283,
4853,
13,
6614,
356,
283,
4853,
297,
272,
283,
4853,
13,
1301,
356,
283,
4853,
297,
272,
283,
4853,
13,
24806,
356,
283,
4853,
297,
272,
283,
4853,
13,
7212,
356,
283,
4853,
297,
272,
283,
4853,
13,
14205,
356,
283,
4853,
297,
272,
283,
4853,
13,
9302,
356,
283,
4853,
297,
272,
283,
4853,
13,
396,
356,
20644,
396,
15,
773,
15,
4853,
63,
396,
15607,
576,
15,
2764,
15,
4853,
63,
396,
63,
2764,
63,
5811,
14,
647,
297,
272,
283,
4853,
13,
10077,
356,
283,
4853,
297,
199,
93,
421,
199,
318,
1218,
63,
4749,
8,
589,
12,
5042,
63,
515,
304,
221,
327,
730,
26,
334,
7844,
2028,
12,
620,
9,
1035,
488,
272,
408,
2499,
282,
4886,
367,
18703,
425,
1041,
272,
340,
1249,
14,
32667,
26,
267,
372,
339,
1584,
275,
769,
8,
576,
63,
1100,
1252,
4853,
63,
1365,
9,
272,
4766,
275,
1052,
339,
347,
1852,
63,
5904,
8,
5369,
63,
815,
304,
221,
327,
730,
26,
334,
19862,
14,
24818,
2354,
9,
1035,
307,
14,
7012,
59,
19862,
14,
24818,
2354,
61,
267,
408,
5483,
314,
1627,
570,
7286,
1041,
267,
5330,
63,
815,
14,
632,
8901,
5672,
14,
51,
63,
3867,
22592,
1204,
5672,
14,
51,
63,
3867,
22949,
1204,
5672,
14,
51,
63,
3867,
3975,
48,
267,
372,
5330,
63,
815,
339,
340,
440,
32271,
7187,
63,
10187,
63,
5441,
26,
267,
327,
28462,
314,
2517,
2082,
1314,
365,
440,
2808,
1380,
3879,
687,
376,
3242,
3907,
267,
1584,
14,
2880,
8,
981,
63,
13555,
63,
1393,
63,
1725,
8,
589,
430,
267,
4766,
14,
873,
8,
807,
1332,
736,
14,
515,
14,
904,
360,
4853,
297,
931,
59,
19,
26,
2522,
1852,
63,
5904,
9,
367,
931,
315,
32271,
7187,
63,
9431,
63,
4669,
1698,
12394,
63,
5443,
14,
1459,
342,
340,
931,
14,
2460,
24592,
7058,
339,
340,
440,
666,
63,
1100,
1252,
1317,
14,
374,
63,
4853,
26,
267,
327,
5760,
23361,
1584,
1380,
440,
5343,
3242,
6337,
267,
1584,
275,
359,
70,
367,
289,
315,
1584,
340,
326,
365,
63,
10622,
8,
70,
59,
17,
467,
283,
1393,
6217,
503,
326,
365,
63,
10622,
8,
70,
59,
17,
467,
283,
773,
15,
4853,
6217,
503,
326,
365,
63,
10622,
8,
70,
59,
17,
467,
283,
396,
15,
773,
15,
4853,
63,
396,
15,
5440,
398,
340,
440,
1228,
8,
589,
12,
334,
8529,
2028,
12,
27561,
2028,
2298,
288,
327,
5760,
6137,
13,
262,
3242,
4621,
1380,
2985,
787,
440,
4346,
288,
1584,
275,
359,
70,
367,
289,
315,
1584,
340,
440,
365,
63,
10622,
8,
70,
59,
17,
467,
283,
773,
15,
4853,
15,
3112,
6217,
503,
289,
59,
17,
61,
508,
283,
773,
15,
4853,
15,
3112,
22128,
826,
4343,
647,
418,
398,
3245,
63,
4209,
83,
275,
666,
63,
1100,
1252,
981,
63,
3627,
63,
4209,
83,
342,
398,
1564,
63,
1725,
275,
942,
267,
2402,
63,
1725,
275,
942,
398,
367,
7054,
315,
3245,
63,
4209,
83,
26,
288,
340,
7054,
508,
666,
63,
1100,
1252,
1317,
26,
355,
327,
2387,
1584,
687,
314,
1453,
3245,
334,
4209,
14,
3627,
14,
3619,
911,
506,
3483,
2945,
9,
355,
1564,
63,
1725,
14,
2880,
1332,
736,
14,
515,
14,
904,
8,
4209,
14,
1231,
12,
931,
395,
931,
9,
367,
931,
315,
666,
63,
1100,
1252,
1317,
14,
452,
63,
1725,
1012,
288,
587,
26,
355,
327,
2387,
1584,
687,
1924,
3245,
315,
314,
2011,
3245,
1738,
465,
314,
1564,
3769,
12470,
355,
2402,
63,
1725,
14,
2880,
1332,
736,
14,
515,
14,
904,
8,
4209,
14,
1231,
12,
931,
395,
747,
14,
515,
14,
904,
8,
4209,
14,
3627,
14,
3619,
12,
931,
430,
367,
931,
315,
7054,
14,
452,
63,
1725,
1012,
272,
587,
26,
267,
327,
1380,
5343,
3242,
6337,
314,
3242,
1350,
365,
314,
1564,
267,
1564,
63,
1725,
275,
1584,
267,
327,
2337,
787,
949,
2402,
1584,
1380,
5343,
3242,
6337,
267,
2402,
63,
1725,
275,
942,
339,
367,
3233,
315,
666,
63,
1100,
1252,
4749,
63,
11948,
26,
267,
327,
5341,
13484,
1454,
641,
314,
1564,
3792,
267,
327,
642,
365,
4224,
2544,
299,
13121,
3062,
315,
314,
5827,
25094,
334,
3239,
5084,
9,
267,
3233,
8,
1317,
63,
1725,
9,
339,
327,
4192,
3242,
1350,
1584,
1334,
314,
283,
4853,
7,
2082,
641,
314,
29598,
1591,
272,
1584,
275,
3842,
2164,
12,
747,
14,
515,
14,
904,
360,
4853,
297,
5042,
430,
367,
2928,
12,
5042,
315,
1584,
61,
339,
340,
666
] |
[
17215,
10041,
367,
10209,
2622,
1584,
436,
511,
1564,
370,
1163,
10460,
334,
6849,
83,
12,
15333,
10477,
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,
19840,
199,
646,
747,
199,
646,
5672,
199,
646,
13608,
199,
646,
5549,
199,
646,
900,
199,
199,
504,
1275,
492,
2943,
465,
307,
199,
199,
504,
1275,
888,
492,
334,
272,
27561,
2028,
12,
272,
24599,
2028,
12,
199,
9,
199,
199,
504,
1275,
1974,
492,
334,
272,
2929,
12,
272,
32271,
7187,
63,
10187,
63,
5441,
12,
272,
2813,
63,
2350,
12,
272,
365,
63,
10622,
12,
199,
9,
199,
199,
504,
1275,
576,
492,
334,
272,
666,
63,
1100,
12,
199,
9,
199,
199,
504,
1275,
1974,
63,
2330,
492,
334,
272,
13964,
2028,
12,
199,
9,
199,
199,
3,
19053,
10238,
701,
30723,
1747,
15,
8787,
16807,
199,
19862,
14,
14258,
275,
488,
199,
19862,
14,
12599,
275,
488,
199,
199,
3,
642,
2517,
15296,
2341,
1471,
8840,
1336,
314,
4072,
402,
314,
2517,
2082,
199,
3,
652,
365,
5784,
367,
4886,
7143,
370,
28462,
314,
2517,
2082,
1380,
3879,
3242,
13,
396,
687,
376,
4903,
1015,
402,
3242,
199,
8490,
63,
9431,
63,
4669,
1698,
12394,
63,
5443,
275,
469,
272,
283,
4853,
356,
20644,
773,
15,
4853,
15,
2764,
15,
6429,
15,
4853,
63,
2764,
63,
5811,
14,
647,
297,
272,
283,
4853,
13,
888,
356,
283,
4853,
297,
272,
283,
4853,
13,
2105,
356,
20644,
773,
15,
4853,
15,
2764,
15,
6429,
15,
4853,
63,
2105,
63,
2764,
63,
5811,
14,
647,
297,
272,
283,
4853,
13,
6614,
356,
283,
4853,
297,
272,
283,
4853,
13,
1301,
356,
283,
4853,
297,
272,
283,
4853,
13,
24806,
356,
283,
4853,
297,
272,
283,
4853,
13,
7212,
356,
283,
4853,
297,
272,
283,
4853,
13,
14205,
356,
283,
4853,
297,
272,
283,
4853,
13,
9302,
356,
283,
4853,
297,
272,
283,
4853,
13,
396,
356,
20644,
396,
15,
773,
15,
4853,
63,
396,
15607,
576,
15,
2764,
15,
4853,
63,
396,
63,
2764,
63,
5811,
14,
647,
297,
272,
283,
4853,
13,
10077,
356,
283,
4853,
297,
199,
93,
421,
199,
318,
1218,
63,
4749,
8,
589,
12,
5042,
63,
515,
304,
221,
327,
730,
26,
334,
7844,
2028,
12,
620,
9,
1035,
488,
272,
408,
2499,
282,
4886,
367,
18703,
425,
1041,
272,
340,
1249,
14,
32667,
26,
267,
372,
339,
1584,
275,
769,
8,
576,
63,
1100,
1252,
4853,
63,
1365,
9,
272,
4766,
275,
1052,
339,
347,
1852,
63,
5904,
8,
5369,
63,
815,
304,
221,
327,
730,
26,
334,
19862,
14,
24818,
2354,
9,
1035,
307,
14,
7012,
59,
19862,
14,
24818,
2354,
61,
267,
408,
5483,
314,
1627,
570,
7286,
1041,
267,
5330,
63,
815,
14,
632,
8901,
5672,
14,
51,
63,
3867,
22592,
1204,
5672,
14,
51,
63,
3867,
22949,
1204,
5672,
14,
51,
63,
3867,
3975,
48,
267,
372,
5330,
63,
815,
339,
340,
440,
32271,
7187,
63,
10187,
63,
5441,
26,
267,
327,
28462,
314,
2517,
2082,
1314,
365,
440,
2808,
1380,
3879,
687,
376,
3242,
3907,
267,
1584,
14,
2880,
8,
981,
63,
13555,
63,
1393,
63,
1725,
8,
589,
430,
267,
4766,
14,
873,
8,
807,
1332,
736,
14,
515,
14,
904,
360,
4853,
297,
931,
59,
19,
26,
2522,
1852,
63,
5904,
9,
367,
931,
315,
32271,
7187,
63,
9431,
63,
4669,
1698,
12394,
63,
5443,
14,
1459,
342,
340,
931,
14,
2460,
24592,
7058,
339,
340,
440,
666,
63,
1100,
1252,
1317,
14,
374,
63,
4853,
26,
267,
327,
5760,
23361,
1584,
1380,
440,
5343,
3242,
6337,
267,
1584,
275,
359,
70,
367,
289,
315,
1584,
340,
326,
365,
63,
10622,
8,
70,
59,
17,
467,
283,
1393,
6217,
503,
326,
365,
63,
10622,
8,
70,
59,
17,
467,
283,
773,
15,
4853,
6217,
503,
326,
365,
63,
10622,
8,
70,
59,
17,
467,
283,
396,
15,
773,
15,
4853,
63,
396,
15,
5440,
398,
340,
440,
1228,
8,
589,
12,
334,
8529,
2028,
12,
27561,
2028,
2298,
288,
327,
5760,
6137,
13,
262,
3242,
4621,
1380,
2985,
787,
440,
4346,
288,
1584,
275,
359,
70,
367,
289,
315,
1584,
340,
440,
365,
63,
10622,
8,
70,
59,
17,
467,
283,
773,
15,
4853,
15,
3112,
6217,
503,
289,
59,
17,
61,
508,
283,
773,
15,
4853,
15,
3112,
22128,
826,
4343,
647,
418,
398,
3245,
63,
4209,
83,
275,
666,
63,
1100,
1252,
981,
63,
3627,
63,
4209,
83,
342,
398,
1564,
63,
1725,
275,
942,
267,
2402,
63,
1725,
275,
942,
398,
367,
7054,
315,
3245,
63,
4209,
83,
26,
288,
340,
7054,
508,
666,
63,
1100,
1252,
1317,
26,
355,
327,
2387,
1584,
687,
314,
1453,
3245,
334,
4209,
14,
3627,
14,
3619,
911,
506,
3483,
2945,
9,
355,
1564,
63,
1725,
14,
2880,
1332,
736,
14,
515,
14,
904,
8,
4209,
14,
1231,
12,
931,
395,
931,
9,
367,
931,
315,
666,
63,
1100,
1252,
1317,
14,
452,
63,
1725,
1012,
288,
587,
26,
355,
327,
2387,
1584,
687,
1924,
3245,
315,
314,
2011,
3245,
1738,
465,
314,
1564,
3769,
12470,
355,
2402,
63,
1725,
14,
2880,
1332,
736,
14,
515,
14,
904,
8,
4209,
14,
1231,
12,
931,
395,
747,
14,
515,
14,
904,
8,
4209,
14,
3627,
14,
3619,
12,
931,
430,
367,
931,
315,
7054,
14,
452,
63,
1725,
1012,
272,
587,
26,
267,
327,
1380,
5343,
3242,
6337,
314,
3242,
1350,
365,
314,
1564,
267,
1564,
63,
1725,
275,
1584,
267,
327,
2337,
787,
949,
2402,
1584,
1380,
5343,
3242,
6337,
267,
2402,
63,
1725,
275,
942,
339,
367,
3233,
315,
666,
63,
1100,
1252,
4749,
63,
11948,
26,
267,
327,
5341,
13484,
1454,
641,
314,
1564,
3792,
267,
327,
642,
365,
4224,
2544,
299,
13121,
3062,
315,
314,
5827,
25094,
334,
3239,
5084,
9,
267,
3233,
8,
1317,
63,
1725,
9,
339,
327,
4192,
3242,
1350,
1584,
1334,
314,
283,
4853,
7,
2082,
641,
314,
29598,
1591,
272,
1584,
275,
3842,
2164,
12,
747,
14,
515,
14,
904,
360,
4853,
297,
5042,
430,
367,
2928,
12,
5042,
315,
1584,
61,
339,
340,
666,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
apir8181/DLINE
|
Applications/GE/example/python_script/most_popular_flickr.py
|
1
|
1164
|
import sys
from collections import defaultdict
if __name__ == "__main__":
in_path = sys.argv[1]
out_path = sys.argv[2]
group_count = defaultdict(int)
with open(in_path) as in_file:
for line in in_file:
args = line.strip().split()
for arg in args[1:]:
group_count[int(arg)] += 1
sort_count = [(k, v) for k, v in group_count.iteritems()]
sort_count = sorted(sort_count, key=lambda x: -x[1])
popular_group = {x[0]: i for i, x in enumerate(sort_count[:5])}
with open(in_path) as in_file, \
open(out_path, 'w') as out_file:
for line in in_file:
args = line.strip().split()
node = int(args[0])
groups = [int(x) for x in args[1:]]
need_node = False
for group in groups:
if group in popular_group:
need_node = True
if need_node:
out_file.write('%d' % node)
for group in groups:
if group in popular_group:
out_file.write(' %d' % popular_group[group])
out_file.write('\n')
|
mit
|
[
199,
646,
984,
199,
504,
5055,
492,
10018,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
315,
63,
515,
275,
984,
14,
3020,
59,
17,
61,
272,
734,
63,
515,
275,
984,
14,
3020,
59,
18,
61,
339,
1572,
63,
835,
275,
10018,
8,
442,
9,
272,
543,
1551,
8,
262,
63,
515,
9,
465,
315,
63,
493,
26,
267,
367,
1004,
315,
315,
63,
493,
26,
288,
1249,
275,
1004,
14,
1913,
1252,
1294,
342,
288,
367,
1680,
315,
1249,
59,
17,
10688,
2049,
1572,
63,
835,
59,
442,
8,
1273,
1874,
847,
413,
339,
4069,
63,
835,
275,
3842,
75,
12,
373,
9,
367,
1022,
12,
373,
315,
1572,
63,
835,
14,
4611,
5106,
272,
4069,
63,
835,
275,
3355,
8,
3191,
63,
835,
12,
790,
29,
2734,
671,
26,
446,
88,
59,
17,
566,
272,
4560,
2238,
63,
923,
275,
469,
88,
59,
16,
2189,
284,
367,
284,
12,
671,
315,
3874,
8,
3191,
63,
835,
1491,
21,
566,
93,
339,
543,
1551,
8,
262,
63,
515,
9,
465,
315,
63,
493,
12,
971,
268,
1551,
8,
548,
63,
515,
12,
283,
87,
358,
465,
734,
63,
493,
26,
267,
367,
1004,
315,
315,
63,
493,
26,
288,
1249,
275,
1004,
14,
1913,
1252,
1294,
342,
288,
1031,
275,
1109,
8,
589,
59,
16,
566,
288,
4652,
275,
359,
442,
8,
88,
9,
367,
671,
315,
1249,
59,
17,
21316,
288,
1929,
63,
932,
275,
756,
288,
367,
1572,
315,
4652,
26,
355,
340,
1572,
315,
4560,
2238,
63,
923,
26,
490,
1929,
63,
932,
275,
715,
288,
340,
1929,
63,
932,
26,
355,
734,
63,
493,
14,
952,
3508,
68,
7,
450,
1031,
9,
355,
367,
1572,
315,
4652,
26,
490,
340,
1572,
315,
4560,
2238,
63,
923,
26,
717,
734,
63,
493,
14,
952,
360,
450,
68,
7,
450,
4560,
2238,
63,
923,
59,
923,
566,
355,
734,
63,
493,
14,
952,
2258,
78,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
646,
984,
199,
504,
5055,
492,
10018,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
315,
63,
515,
275,
984,
14,
3020,
59,
17,
61,
272,
734,
63,
515,
275,
984,
14,
3020,
59,
18,
61,
339,
1572,
63,
835,
275,
10018,
8,
442,
9,
272,
543,
1551,
8,
262,
63,
515,
9,
465,
315,
63,
493,
26,
267,
367,
1004,
315,
315,
63,
493,
26,
288,
1249,
275,
1004,
14,
1913,
1252,
1294,
342,
288,
367,
1680,
315,
1249,
59,
17,
10688,
2049,
1572,
63,
835,
59,
442,
8,
1273,
1874,
847,
413,
339,
4069,
63,
835,
275,
3842,
75,
12,
373,
9,
367,
1022,
12,
373,
315,
1572,
63,
835,
14,
4611,
5106,
272,
4069,
63,
835,
275,
3355,
8,
3191,
63,
835,
12,
790,
29,
2734,
671,
26,
446,
88,
59,
17,
566,
272,
4560,
2238,
63,
923,
275,
469,
88,
59,
16,
2189,
284,
367,
284,
12,
671,
315,
3874,
8,
3191,
63,
835,
1491,
21,
566,
93,
339,
543,
1551,
8,
262,
63,
515,
9,
465,
315,
63,
493,
12,
971,
268,
1551,
8,
548,
63,
515,
12,
283,
87,
358,
465,
734,
63,
493,
26,
267,
367,
1004,
315,
315,
63,
493,
26,
288,
1249,
275,
1004,
14,
1913,
1252,
1294,
342,
288,
1031,
275,
1109,
8,
589,
59,
16,
566,
288,
4652,
275,
359,
442,
8,
88,
9,
367,
671,
315,
1249,
59,
17,
21316,
288,
1929,
63,
932,
275,
756,
288,
367,
1572,
315,
4652,
26,
355,
340,
1572,
315,
4560,
2238,
63,
923,
26,
490,
1929,
63,
932,
275,
715,
288,
340,
1929,
63,
932,
26,
355,
734,
63,
493,
14,
952,
3508,
68,
7,
450,
1031,
9,
355,
367,
1572,
315,
4652,
26,
490,
340,
1572,
315,
4560,
2238,
63,
923,
26,
717,
734,
63,
493,
14,
952,
360,
450,
68,
7,
450,
4560,
2238,
63,
923,
59,
923,
566,
355,
734,
63,
493,
14,
952,
2258,
78,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
nju520/django
|
tests/template_tests/filter_tests/test_linebreaks.py
|
310
|
1920
|
from django.template.defaultfilters import linebreaks_filter
from django.test import SimpleTestCase
from django.utils.safestring import mark_safe
from ..utils import setup
class LinebreaksTests(SimpleTestCase):
"""
The contents in "linebreaks" are escaped according to the current
autoescape setting.
"""
@setup({'linebreaks01': '{{ a|linebreaks }} {{ b|linebreaks }}'})
def test_linebreaks01(self):
output = self.engine.render_to_string('linebreaks01', {"a": "x&\ny", "b": mark_safe("x&\ny")})
self.assertEqual(output, "<p>x&<br />y</p> <p>x&<br />y</p>")
@setup({'linebreaks02':
'{% autoescape off %}{{ a|linebreaks }} {{ b|linebreaks }}{% endautoescape %}'})
def test_linebreaks02(self):
output = self.engine.render_to_string('linebreaks02', {"a": "x&\ny", "b": mark_safe("x&\ny")})
self.assertEqual(output, "<p>x&<br />y</p> <p>x&<br />y</p>")
class FunctionTests(SimpleTestCase):
def test_line(self):
self.assertEqual(linebreaks_filter('line 1'), '<p>line 1</p>')
def test_newline(self):
self.assertEqual(linebreaks_filter('line 1\nline 2'), '<p>line 1<br />line 2</p>')
def test_carriage(self):
self.assertEqual(linebreaks_filter('line 1\rline 2'), '<p>line 1<br />line 2</p>')
def test_carriage_newline(self):
self.assertEqual(linebreaks_filter('line 1\r\nline 2'), '<p>line 1<br />line 2</p>')
def test_non_string_input(self):
self.assertEqual(linebreaks_filter(123), '<p>123</p>')
def test_autoescape(self):
self.assertEqual(
linebreaks_filter('foo\n<a>bar</a>\nbuz'),
'<p>foo<br /><a>bar</a><br />buz</p>',
)
def test_autoescape_off(self):
self.assertEqual(
linebreaks_filter('foo\n<a>bar</a>\nbuz', autoescape=False),
'<p>foo<br /><a>bar</a><br />buz</p>',
)
|
bsd-3-clause
|
[
504,
1639,
14,
1160,
14,
885,
4273,
492,
1004,
18566,
63,
1541,
199,
504,
1639,
14,
396,
492,
24424,
199,
504,
1639,
14,
1208,
14,
28389,
492,
2216,
63,
3489,
199,
199,
504,
2508,
1208,
492,
3272,
421,
199,
533,
7030,
18566,
2925,
8,
17968,
304,
272,
408,
272,
710,
4072,
315,
298,
604,
18566,
2,
787,
11077,
7182,
370,
314,
1453,
272,
19102,
4260,
14,
272,
408,
339,
768,
2758,
3252,
604,
18566,
614,
356,
11400,
282,
92,
604,
18566,
3586,
8448,
330,
92,
604,
18566,
29281,
272,
347,
511,
63,
604,
18566,
614,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
604,
18566,
614,
297,
2420,
65,
582,
298,
88,
28103,
9745,
401,
298,
66,
582,
2216,
63,
3489,
480,
88,
28103,
9745,
531,
1552,
267,
291,
14,
629,
8,
1199,
12,
3886,
80,
30,
88,
6,
5282,
22257,
3289,
7082,
89,
1108,
80,
30,
665,
80,
30,
88,
6,
28,
3289,
7082,
89,
1108,
80,
9579,
339,
768,
2758,
3252,
604,
18566,
996,
356,
267,
12100,
19102,
2331,
17337,
282,
92,
604,
18566,
3586,
8448,
330,
92,
604,
18566,
20104,
1284,
15818,
17776,
272,
347,
511,
63,
604,
18566,
996,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
604,
18566,
996,
297,
2420,
65,
582,
298,
88,
28103,
9745,
401,
298,
66,
582,
2216,
63,
3489,
480,
88,
28103,
9745,
531,
1552,
267,
291,
14,
629,
8,
1199,
12,
3886,
80,
30,
88,
6,
28,
3289,
7082,
89,
1108,
80,
30,
665,
80,
30,
88,
6,
28,
3289,
7082,
89,
1108,
80,
9579,
421,
199,
533,
6801,
2925,
8,
17968,
304,
339,
347,
511,
63,
604,
8,
277,
304,
267,
291,
14,
629,
8,
604,
18566,
63,
1541,
360,
604,
413,
659,
2650,
80,
30,
604,
413,
1108,
80,
5971,
339,
347,
511,
63,
12210,
8,
277,
304,
267,
291,
14,
629,
8,
604,
18566,
63,
1541,
360,
604,
413,
60,
78,
604,
499,
659,
2650,
80,
30,
604,
413,
28,
3289,
7082,
604,
499,
1108,
80,
5971,
339,
347,
511,
63,
7007,
25220,
8,
277,
304,
267,
291,
14,
629,
8,
604,
18566,
63,
1541,
360,
604,
413,
60,
82,
604,
499,
659,
2650,
80,
30,
604,
413,
28,
3289,
7082,
604,
499,
1108,
80,
5971,
339,
347,
511,
63,
7007,
25220,
63,
12210,
8,
277,
304,
267,
291,
14,
629,
8,
604,
18566,
63,
1541,
360,
604,
413,
60,
82,
60,
78,
604,
499,
659,
2650,
80,
30,
604,
413,
28,
3289,
7082,
604,
499,
1108,
80,
5971,
339,
347,
511,
63,
2865,
63,
875,
63,
1210,
8,
277,
304,
267,
291,
14,
629,
8,
604,
18566,
63,
1541,
8,
4288,
395,
2650,
80,
30,
4288,
1108,
80,
5971,
339,
347,
511,
63,
15818,
8,
277,
304,
267,
291,
14,
629,
8,
288,
1004,
18566,
63,
1541,
360,
1421,
60,
78,
28,
65,
30,
1700,
1108,
65,
3072,
78,
464,
90,
659,
288,
2650,
80,
30,
1421,
28,
3289,
7082,
6,
4116,
27,
65,
6,
3308,
27,
1700,
6,
4116,
22352,
65,
6,
3308,
22257,
3289,
7082,
464,
90,
1108,
80,
4206,
267,
776,
339,
347,
511,
63,
15818,
63,
1997,
8,
277,
304,
267,
291,
14,
629,
8,
288,
1004,
18566,
63,
1541,
360,
1421,
60,
78,
28,
65,
30,
1700,
1108,
65,
3072,
78,
464,
90,
297,
19102,
29,
797,
395,
288,
2650,
80,
30,
1421,
28,
3289,
21671,
65,
30,
1700,
1108,
65,
2535,
3289,
7082,
464,
90,
1108,
80,
4206,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
1160,
14,
885,
4273,
492,
1004,
18566,
63,
1541,
199,
504,
1639,
14,
396,
492,
24424,
199,
504,
1639,
14,
1208,
14,
28389,
492,
2216,
63,
3489,
199,
199,
504,
2508,
1208,
492,
3272,
421,
199,
533,
7030,
18566,
2925,
8,
17968,
304,
272,
408,
272,
710,
4072,
315,
298,
604,
18566,
2,
787,
11077,
7182,
370,
314,
1453,
272,
19102,
4260,
14,
272,
408,
339,
768,
2758,
3252,
604,
18566,
614,
356,
11400,
282,
92,
604,
18566,
3586,
8448,
330,
92,
604,
18566,
29281,
272,
347,
511,
63,
604,
18566,
614,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
604,
18566,
614,
297,
2420,
65,
582,
298,
88,
28103,
9745,
401,
298,
66,
582,
2216,
63,
3489,
480,
88,
28103,
9745,
531,
1552,
267,
291,
14,
629,
8,
1199,
12,
3886,
80,
30,
88,
6,
5282,
22257,
3289,
7082,
89,
1108,
80,
30,
665,
80,
30,
88,
6,
28,
3289,
7082,
89,
1108,
80,
9579,
339,
768,
2758,
3252,
604,
18566,
996,
356,
267,
12100,
19102,
2331,
17337,
282,
92,
604,
18566,
3586,
8448,
330,
92,
604,
18566,
20104,
1284,
15818,
17776,
272,
347,
511,
63,
604,
18566,
996,
8,
277,
304,
267,
1072,
275,
291,
14,
3908,
14,
3352,
63,
475,
63,
875,
360,
604,
18566,
996,
297,
2420,
65,
582,
298,
88,
28103,
9745,
401,
298,
66,
582,
2216,
63,
3489,
480,
88,
28103,
9745,
531,
1552,
267,
291,
14,
629,
8,
1199,
12,
3886,
80,
30,
88,
6,
28,
3289,
7082,
89,
1108,
80,
30,
665,
80,
30,
88,
6,
28,
3289,
7082,
89,
1108,
80,
9579,
421,
199,
533,
6801,
2925,
8,
17968,
304,
339,
347,
511,
63,
604,
8,
277,
304,
267,
291,
14,
629,
8,
604,
18566,
63,
1541,
360,
604,
413,
659,
2650,
80,
30,
604,
413,
1108,
80,
5971,
339,
347,
511,
63,
12210,
8,
277,
304,
267,
291,
14,
629,
8,
604,
18566,
63,
1541,
360,
604,
413,
60,
78,
604,
499,
659,
2650,
80,
30,
604,
413,
28,
3289,
7082,
604,
499,
1108,
80,
5971,
339,
347,
511,
63,
7007,
25220,
8,
277,
304,
267,
291,
14,
629,
8,
604,
18566,
63,
1541,
360,
604,
413,
60,
82,
604,
499,
659,
2650,
80,
30,
604,
413,
28,
3289,
7082,
604,
499,
1108,
80,
5971,
339,
347,
511,
63,
7007,
25220,
63,
12210,
8,
277,
304,
267,
291,
14,
629,
8,
604,
18566,
63,
1541,
360,
604,
413,
60,
82,
60,
78,
604,
499,
659,
2650,
80,
30,
604,
413,
28,
3289,
7082,
604,
499,
1108,
80,
5971,
339,
347,
511,
63,
2865,
63,
875,
63,
1210,
8,
277,
304,
267,
291,
14,
629,
8,
604,
18566,
63,
1541,
8,
4288,
395,
2650,
80,
30,
4288,
1108,
80,
5971,
339,
347,
511,
63,
15818,
8,
277,
304,
267,
291,
14,
629,
8,
288,
1004,
18566,
63,
1541,
360,
1421,
60,
78,
28,
65,
30,
1700,
1108,
65,
3072,
78,
464,
90,
659,
288,
2650,
80,
30,
1421,
28,
3289,
7082,
6,
4116,
27,
65,
6,
3308,
27,
1700,
6,
4116,
22352,
65,
6,
3308,
22257,
3289,
7082,
464,
90,
1108,
80,
4206,
267,
776,
339,
347,
511,
63,
15818,
63,
1997,
8,
277,
304,
267,
291,
14,
629,
8,
288,
1004,
18566,
63,
1541,
360,
1421,
60,
78,
28,
65,
30,
1700,
1108,
65,
3072,
78,
464,
90,
297,
19102,
29,
797,
395,
288,
2650,
80,
30,
1421,
28,
3289,
21671,
65,
30,
1700,
1108,
65,
2535,
3289,
7082,
464,
90,
1108,
80,
4206,
267,
776,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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