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
|
|---|---|---|---|---|---|---|---|---|
toshywoshy/ansible
|
lib/ansible/modules/network/onyx/onyx_snmp.py
|
9
|
19773
|
#!/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': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = """
---
module: onyx_snmp
version_added: "2.10"
author: "Sara-Touqan (@sarato)"
short_description: Manages SNMP general configurations on Mellanox ONYX network devices
description:
- This module provides declarative management of SNMP
on Mellanox ONYX network devices.
options:
state_enabled:
description:
- Enables/Disables the state of the SNMP configuration.
type: bool
contact_name:
description:
- Sets the SNMP contact name.
type: str
location:
description:
- Sets the SNMP location.
type: str
communities_enabled:
description:
- Enables/Disables community-based authentication on the system.
type: bool
multi_communities_enabled:
description:
- Enables/Disables multiple communities to be configured.
type: bool
snmp_communities:
type: list
description:
- List of snmp communities
suboptions:
community_name:
description:
- Configures snmp community name.
required: true
type: str
community_type:
description:
- Add this community as either a read-only or read-write community.
choices: ['read-only', 'read-write']
type: str
state:
description:
- Used to decide if you want to delete the given snmp community or not
choices: ['present', 'absent']
type: str
notify_enabled:
description:
- Enables/Disables sending of SNMP notifications (traps and informs) from thee system.
type: bool
notify_port:
description:
- Sets the default port to which notifications are sent.
type: str
notify_community:
description:
- Sets the default community for SNMP v1 and v2c notifications sent to hosts which do not have a community override set.
type: str
notify_send_test:
description:
- Sends a test notification.
type: str
choices: ['yes','no']
notify_event:
description:
- Specifys which events will be sent as SNMP notifications.
type: str
choices: ['asic-chip-down', 'dcbx-pfc-port-oper-state-trap', 'insufficient-power', 'mstp-new-bridge-root',
'ospf-lsdb-approaching-overflow', 'sm-stop', 'user-logout', 'cli-line-executed', 'dcbx-pfc-port-peer-state-trap',
'interface-down', 'mstp-new-root-port', 'ospf-lsdb-overflow', 'snmp-authtrap', 'xstp-new-root-bridge',
'cpu-util-high', 'disk-io-high', 'interface-up', 'mstp-topology-change', 'ospf-nbr-state-change',
'temperature-too-high', 'xstp-root-port-change', 'dcbx-ets-module-state-change', 'disk-space-low',
'internal-bus-error', 'netusage-high', 'paging-high', 'topology_change', 'xstp-topology-change',
'dcbx-ets-port-admin-state-trap', 'entity-state-change', 'internal-link-speed-mismatch', 'new_root',
'power-redundancy-mismatch', 'unexpected-cluster-join', 'dcbx-ets-port-oper-state-trap', 'expected-shutdown',
'liveness-failure', 'ospf-auth-fail', 'process-crash', 'unexpected-cluster-leave', 'dcbx-ets-port-peer-state-trap',
'health-module-status', 'low-power', 'ospf-config-error', 'process-exit', 'unexpected-cluster-size',
'dcbx-pfc-module-state-change', 'insufficient-fans', 'low-power-recover', 'ospf-if-rx-bad-packet',
'sm-restart', 'unexpected-shutdown', 'dcbx-pfc-port-admin-state-trap', 'insufficient-fans-recover', 'memusage-high',
'ospf-if-state-change', 'sm-start', 'user-login']
engine_id_reset:
description:
- Sets SNMPv3 engineID to node unique value.
type: bool
snmp_permissions:
type: list
description:
- Allow SNMPSET requests for items in a MIB.
suboptions:
state_enabled:
description:
- Enables/Disables the request.
required: true
type: bool
permission_type:
description:
- Configures the request type.
choices: ['MELLANOX-CONFIG-DB-MIB', 'MELLANOX-EFM-MIB','MELLANOX-POWER-CYCLE','MELLANOX-SW-UPDATE','RFC1213-MIB']
type: str
"""
EXAMPLES = """
- name: configure SNMP
onyx_snmp:
state_enabled: yes
contact_name: sara
location: Nablus
communities_enabled: no
multi_communities_enabled: no
notify_enabled: yes
notify_port: 1
notify_community: community_1
notify_send_test: yes
notify_event: temperature-too-high
snmp_communities:
- community_name: public
community_type: read-only
state: absent
snmp_permissions:
- state_enabled: yes
permission_type: MELLANOX-CONFIG-DB-MIB
"""
RETURN = """
commands:
description: The list of configuration mode commands to send to the device
returned: always.
type: list
sample:
- snmp-server enable
- no snmp-server enable
- snmp-server location <location_name>
- snmp-server contact <contact_name>
- snmp-server enable communities
- no snmp-server enable communities
- snmp-server enable mult-communities
- no snmp-server enable mult-communities
- snmp-server enable notify
- snmp-server notify port <port_number>
- snmp-server notify community <community_name>
- snmp-server notify send-test
- snmp-server notify event <event_name>
- snmp-server enable set-permission <permission_type>
- no snmp-server enable set-permission <permission_type>
- snmp-server community <community_name> <community_type>
- no snmp-server community <community_name>.
- snmp-server engineID reset.
"""
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.network.onyx.onyx import BaseOnyxModule
from ansible.module_utils.network.onyx.onyx import show_cmd
class OnyxSNMPModule(BaseOnyxModule):
def init_module(self):
""" module initialization
"""
community_spec = dict(community_name=dict(required=True),
community_type=dict(choices=['read-only', 'read-write']),
state=dict(choices=['present', 'absent']))
snmp_permission_spec = dict(state_enabled=dict(type='bool', required=True),
permission_type=dict(choices=['MELLANOX-CONFIG-DB-MIB', 'MELLANOX-EFM-MIB', 'MELLANOX-POWER-CYCLE',
'MELLANOX-SW-UPDATE', 'RFC1213-MIB']))
event_choices = ['asic-chip-down', 'dcbx-pfc-port-oper-state-trap', 'insufficient-power', 'mstp-new-bridge-root',
'ospf-lsdb-approaching-overflow', 'sm-stop', 'user-logout', 'cli-line-executed', 'dcbx-pfc-port-peer-state-trap',
'interface-down', 'mstp-new-root-port', 'ospf-lsdb-overflow', 'snmp-authtrap', 'xstp-new-root-bridge',
'cpu-util-high', 'disk-io-high', 'interface-up', 'mstp-topology-change', 'ospf-nbr-state-change',
'temperature-too-high', 'xstp-root-port-change', 'dcbx-ets-module-state-change', 'disk-space-low',
'internal-bus-error', 'netusage-high', 'paging-high', 'topology_change', 'xstp-topology-change',
'dcbx-ets-port-admin-state-trap', 'entity-state-change', 'internal-link-speed-mismatch', 'new_root',
'power-redundancy-mismatch', 'unexpected-cluster-join', 'dcbx-ets-port-oper-state-trap', 'expected-shutdown',
'liveness-failure', 'ospf-auth-fail', 'process-crash', 'unexpected-cluster-leave', 'dcbx-ets-port-peer-state-trap',
'health-module-status', 'low-power', 'ospf-config-error', 'process-exit', 'unexpected-cluster-size',
'dcbx-pfc-module-state-change', 'insufficient-fans', 'low-power-recover', 'ospf-if-rx-bad-packet',
'sm-restart', 'unexpected-shutdown', 'dcbx-pfc-port-admin-state-trap', 'insufficient-fans-recover', 'memusage-high',
'ospf-if-state-change', 'sm-start', 'user-login']
element_spec = dict(
state_enabled=dict(type='bool'),
contact_name=dict(type='str'),
location=dict(type='str'),
communities_enabled=dict(type='bool'),
multi_communities_enabled=dict(type='bool'),
snmp_communities=dict(type='list', elements='dict', options=community_spec),
notify_enabled=dict(type='bool'),
notify_port=dict(type='str'),
notify_community=dict(type='str'),
notify_send_test=dict(type='str', choices=['yes', 'no']),
notify_event=dict(type='str', choices=event_choices),
engine_id_reset=dict(type='bool'),
snmp_permissions=dict(type='list', elements='dict', options=snmp_permission_spec)
)
argument_spec = dict()
argument_spec.update(element_spec)
self._module = AnsibleModule(
argument_spec=argument_spec,
supports_check_mode=True)
def get_required_config(self):
module_params = self._module.params
self._required_config = dict(module_params)
self.validate_param_values(self._required_config)
def _show_snmp_config(self):
show_cmds = []
cmd = "show snmp"
show_cmds.append(show_cmd(self._module, cmd, json_fmt=True, fail_on_error=False))
cmd = "show running-config | include snmp"
show_cmds.append(show_cmd(self._module, cmd, json_fmt=True, fail_on_error=False))
return show_cmds
def _set_snmp_config(self, all_snmp_config):
ro_communities_list = []
rw_communities_list = []
snmp_config = all_snmp_config[0]
if not snmp_config:
return
if snmp_config.get("SNMP enabled") == 'yes':
self._current_config['state_enabled'] = True
else:
self._current_config['state_enabled'] = False
self._current_config['contact_name'] = snmp_config.get("System contact")
self._current_config['location'] = snmp_config.get("System location")
curr_ro_comm = snmp_config.get("Read-only community")
if curr_ro_comm:
ro_arr = curr_ro_comm.split(' ')
rw_arr = snmp_config.get("Read-write community").split(' ')
ro_communities_list = ro_arr[0]
rw_communities_list = rw_arr[0]
if (len(ro_arr) == 2):
self._current_config['communities_enabled'] = False
else:
self._current_config['communities_enabled'] = True
else:
read_only_communities = all_snmp_config[1]
read_write_communities = all_snmp_config[2]
if not read_only_communities:
return
read_only_comm = read_only_communities.get("Read-only communities")
if read_only_comm:
self._current_config['communities_enabled'] = True
ro_communities_list = read_only_comm[0].get("Lines")
else:
self._current_config['communities_enabled'] = False
ro_comm_disabled = read_only_communities.get("Read-only communities (DISABLED)")
if ro_comm_disabled:
ro_communities_list = ro_comm_disabled[0].get("Lines")
if not read_write_communities:
return
read_write_comm = read_write_communities.get("Read-write communities")
if read_write_comm:
self._current_config['communities_enabled'] = True
rw_communities_list = read_write_comm[0].get("Lines")
else:
self._current_config['communities_enabled'] = False
rw_comm_disabled = read_write_communities.get("Read-write communities (DISABLED)")
if rw_comm_disabled:
rw_communities_list = rw_comm_disabled[0].get("Lines")
self._current_config['ro_communities_list'] = ro_communities_list
self._current_config['rw_communities_list'] = rw_communities_list
def _set_snmp_running_config(self, snmp_running_config):
self._current_config['multi_comm_enabled'] = True
self._current_config['notify_enabled'] = True
curr_config_arr = []
snmp_lines = snmp_running_config.get('Lines')
for runn_config in snmp_lines:
curr_config_arr.append(runn_config.strip())
if 'no snmp-server enable mult-communities' in snmp_lines:
self._current_config['multi_comm_enabled'] = False
if 'no snmp-server enable notify' in snmp_lines:
self._current_config['notify_enabled'] = False
self._current_config['snmp_running_config'] = curr_config_arr
def load_current_config(self):
self._current_config = dict()
snmp_config = self._show_snmp_config()
if snmp_config[0]:
self._set_snmp_config(snmp_config[0])
if snmp_config[1]:
self._set_snmp_running_config(snmp_config[1])
def generate_commands(self):
current_state = self._current_config.get("state_enabled")
state = current_state
req_state = self._required_config.get("state_enabled")
if req_state is not None:
state = req_state
if state is not None:
if current_state != state:
if state is True:
self._commands.append('snmp-server enable')
else:
self._commands.append('no snmp-server enable')
contact_name = self._required_config.get("contact_name")
if contact_name:
current_contact_name = self._current_config.get("contact_name")
if contact_name is not None:
if current_contact_name != contact_name:
self._commands.append('snmp-server contact {0}' .format(contact_name))
location = self._required_config.get("location")
if location:
current_location = self._current_config.get("location")
if location is not None:
if current_location != location:
self._commands.append('snmp-server location {0}' .format(location))
communities_enabled = self._required_config.get("communities_enabled")
if communities_enabled is not None:
current_communities_enabled = self._current_config.get("communities_enabled")
if communities_enabled is not None:
if current_communities_enabled != communities_enabled:
if communities_enabled is True:
self._commands.append('snmp-server enable communities')
else:
self._commands.append('no snmp-server enable communities')
ro_communities = self._current_config.get("ro_communities_list")
rw_communities = self._current_config.get("rw_communities_list")
snmp_communities = self._required_config.get("snmp_communities")
if snmp_communities:
if snmp_communities is not None:
for community in snmp_communities:
community_name = community.get("community_name")
state = community.get("state")
if state:
if state == 'absent':
self._commands.append('no snmp-server community {0}' .format(community_name))
continue
community_type = community.get("community_type")
if community_type:
if community_type == 'read-only':
if community_name not in ro_communities:
self._commands.append('snmp-server community {0} ro' .format(community_name))
else:
if community_name not in rw_communities:
self._commands.append('snmp-server community {0} rw' .format(community_name))
else:
if community_name not in ro_communities:
self._commands.append('snmp-server community {0}' .format(community_name))
engine_id_reset = self._required_config.get("engine_id_reset")
if engine_id_reset is not None:
if engine_id_reset:
self._commands.append('snmp-server engineID reset')
current_multi_comm_state = self._current_config.get("multi_comm_enabled")
multi_communities_enabled = self._required_config.get("multi_communities_enabled")
if multi_communities_enabled is not None:
if current_multi_comm_state != multi_communities_enabled:
if multi_communities_enabled is True:
self._commands.append('snmp-server enable mult-communities')
else:
self._commands.append('no snmp-server enable mult-communities')
notify_enabled = self._required_config.get("notify_enabled")
if notify_enabled is not None:
current_notify_state = self._current_config.get("notify_enabled")
if current_notify_state != notify_enabled:
if notify_enabled is True:
self._commands.append('snmp-server enable notify')
else:
self._commands.append('no snmp-server enable notify')
snmp_permissions = self._required_config.get("snmp_permissions")
if snmp_permissions is not None:
for permission in snmp_permissions:
permission_type = permission.get('permission_type')
if permission.get('state_enabled') is True:
self._commands.append('snmp-server enable set-permission {0}' .format(permission_type))
else:
self._commands.append('no snmp-server enable set-permission {0}' .format(permission_type))
snmp_running_config = self._current_config.get("snmp_running_config")
notify_port = self._required_config.get("notify_port")
if notify_port is not None:
notified_cmd = 'snmp-server notify port {0}' .format(notify_port)
if notified_cmd not in snmp_running_config:
self._commands.append('snmp-server notify port {0}' .format(notify_port))
notify_community = self._required_config.get("notify_community")
if notify_community is not None:
notified_cmd = 'snmp-server notify community {0}' .format(notify_community)
if notified_cmd not in snmp_running_config:
self._commands.append('snmp-server notify community {0}' .format(notify_community))
notify_send_test = self._required_config.get("notify_send_test")
if notify_send_test is not None:
if notify_send_test == 'yes':
self._commands.append('snmp-server notify send-test')
notify_event = self._required_config.get("notify_event")
if notify_event is not None:
self._commands.append('snmp-server notify event {0}' .format(notify_event))
def main():
""" main entry point for module execution
"""
OnyxSNMPModule.main()
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
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,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
641,
20937,
63,
15523,
199,
1023,
63,
3270,
26,
298,
18,
14,
709,
2,
199,
2502,
26,
298,
51,
17956,
13,
52,
810,
81,
290,
8593,
29637,
11318,
2924,
199,
3612,
63,
1802,
26,
21612,
26549,
8605,
13422,
641,
603,
352,
1502,
19131,
5258,
16936,
2784,
7256,
199,
1802,
26,
523,
446,
961,
859,
6571,
30191,
10041,
402,
26549,
272,
641,
603,
352,
1502,
19131,
5258,
16936,
2784,
7256,
14,
199,
1419,
26,
523,
1174,
63,
3827,
26,
272,
1369,
26,
489,
446,
3447,
5921,
15,
2825,
5921,
314,
1174,
402,
314,
26549,
2897,
14,
272,
730,
26,
2155,
523,
8966,
63,
354,
26,
272,
1369,
26,
489,
446,
10729,
314,
26549,
8966,
536,
14,
272,
730,
26,
620,
523,
2909,
26,
272,
1369,
26,
489,
446,
10729,
314,
26549,
2909,
14,
272,
730,
26,
620,
523,
1923,
22047,
63,
3827,
26,
272,
1369,
26,
489,
446,
3447,
5921,
15,
2825,
5921,
23633,
13,
6788,
6299,
641,
314,
2656,
14,
272,
730,
26,
2155,
523,
3510,
63,
1404,
22047,
63,
3827,
26,
272,
1369,
26,
489,
446,
3447,
5921,
15,
2825,
5921,
3663,
1923,
22047,
370,
506,
7526,
14,
272,
730,
26,
2155,
523,
20143,
63,
1404,
22047,
26,
272,
730,
26,
769,
272,
1369,
26,
489,
446,
3820,
402,
20143,
1923,
22047,
272,
26265,
26,
489,
23633,
63,
354,
26,
267,
1369,
26,
881,
446,
4094,
1482,
20143,
23633,
536,
14,
267,
1415,
26,
2549,
267,
730,
26,
620,
489,
23633,
63,
466,
26,
267,
1369,
26,
881,
446,
2654,
642,
23633,
465,
1902,
282,
1586,
13,
2118,
503,
1586,
13,
952,
23633,
14,
267,
3415,
26,
788,
739,
13,
2118,
297,
283,
739,
13,
952,
418,
267,
730,
26,
620,
489,
1174,
26,
267,
1369,
26,
1467,
446,
8051,
370,
19822,
340,
1265,
2934,
370,
3145,
314,
1627,
20143,
23633,
503,
440,
267,
3415,
26,
788,
1881,
297,
283,
5575,
418,
267,
730,
26,
620,
523,
11705,
63,
3827,
26,
272,
1369,
26,
489,
446,
3447,
5921,
15,
2825,
5921,
10209,
402,
26549,
13116,
334,
1239,
1190,
436,
315,
3351,
9,
687,
314,
69,
2656,
14,
272,
730,
26,
2155,
523,
11705,
63,
719,
26,
272,
1369,
26,
489,
446,
10729,
314,
849,
1844,
370,
1314,
13116,
787,
4847,
14,
272,
730,
26,
620,
523,
11705,
63,
9387,
26,
272,
1369,
26,
489,
446,
10729,
314,
849,
23633,
367,
26549,
373,
17,
436,
373,
18,
67,
13116,
4847,
370,
7057,
1314,
886,
440,
1172,
282,
23633,
4278,
663,
14,
272,
730,
26,
620,
523,
11705,
63,
2254,
63,
396,
26,
272,
1369,
26,
489,
446,
221,
428,
3198,
282,
511,
6955,
14,
272,
730,
26,
620,
272,
3415,
26,
788,
5066,
1673,
889,
418,
523,
11705,
63,
1430,
26,
272,
1369,
26,
489,
446,
5367,
70,
588,
1314,
4474,
911,
506,
4847,
465,
26549,
13116,
14,
272,
730,
26,
620,
272,
3415,
26,
788,
2484,
13,
28329,
13,
2110,
297,
283,
68,
2894,
88,
13,
24419,
13,
719,
13,
2262,
13,
929,
13,
19510,
297,
283,
3617,
12983,
13,
5652,
297,
283,
77,
20643,
13,
1222,
13,
9528,
13,
1231,
297,
586,
283,
18303,
13,
9582,
13,
11227,
23302,
13,
14108,
297,
283,
3300,
13,
2379,
297,
283,
751,
13,
11646,
297,
283,
2764,
13,
604,
13,
22564,
297,
283,
68,
2894,
88,
13,
24419,
13,
719,
13,
7866,
13,
929,
13,
19510,
297,
586,
283,
3266,
13,
2110,
297,
283,
77,
20643,
13,
1222,
13,
1231,
13,
719,
297,
283,
18303,
13,
9582,
13,
14108,
297,
283,
15523,
13,
1178,
19510,
297,
283,
88,
20643,
13,
1222,
13,
1231,
13,
9528,
297,
586,
283,
3541,
13,
1974,
13,
6260,
297,
283,
4032,
13,
2308,
13,
6260,
297,
283,
3266,
13,
384,
297,
283,
77,
20643,
13,
10775,
13,
1461,
297,
283,
18303,
13,
23299,
13,
929,
13,
1461,
297,
586,
283,
12954,
13,
7354,
13,
6260,
297,
283,
88,
20643,
13,
1231,
13,
719,
13,
1461,
297,
283,
68,
2894,
88,
13,
8716,
13,
578,
13,
929,
13,
1461,
297,
283,
4032,
13,
2638,
13,
674,
297,
586,
283,
4672,
13,
5610,
13,
705,
297,
283,
846,
3807,
13,
6260,
297,
283,
31691,
13,
6260,
297,
283,
10775,
63,
1461,
297,
283,
88,
20643,
13,
10775,
13,
1461,
297,
586,
283,
68,
2894,
88,
13,
8716,
13,
719,
13,
2113,
13,
929,
13,
19510,
297,
283,
4502,
13,
929,
13,
1461,
297,
283,
4672,
13,
1073,
13,
7625,
13,
20759,
297,
283,
1222,
63,
1231,
297,
586,
283,
5652,
13,
581,
32270,
13,
20759,
297,
283,
8953,
13,
4201,
13,
904,
297,
283,
68,
2894,
88,
13,
8716,
13,
719,
13,
2262,
13,
929,
13,
19510,
297,
283,
2062,
13,
8831,
297,
586,
283,
317,
1856,
16709,
13,
5328,
297,
283,
18303,
13,
1178,
13,
1633,
297,
283,
1412,
13,
14807,
297,
283,
8953,
13,
4201,
13,
12422,
297,
283,
68,
2894,
88,
13,
8716,
13,
719,
13,
7866,
13,
929,
13,
19510,
297,
586,
283,
9665,
13,
578,
13,
1205,
297,
283,
674,
13,
5652,
297,
283,
18303,
13,
888,
13,
705,
297,
283,
1412,
13,
2224,
297,
283,
8953,
13,
4201,
13,
890,
297,
586,
283,
68,
2894,
88,
13,
24419,
13,
578,
13,
929,
13,
1461,
297,
283,
3617,
12983,
13,
70,
796,
297,
283,
674,
13,
5652,
13,
23131,
297,
283,
18303,
13,
692,
13,
6872,
13,
4087,
13,
6253,
297,
586,
283,
3300,
13,
10506,
297,
283,
8953,
13,
8831,
297,
283,
68,
2894,
88,
13,
24419,
13,
719,
13,
2113,
13,
929,
13,
19510
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
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,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
408,
199,
2595,
199,
578,
26,
641,
20937,
63,
15523,
199,
1023,
63,
3270,
26,
298,
18,
14,
709,
2,
199,
2502,
26,
298,
51,
17956,
13,
52,
810,
81,
290,
8593,
29637,
11318,
2924,
199,
3612,
63,
1802,
26,
21612,
26549,
8605,
13422,
641,
603,
352,
1502,
19131,
5258,
16936,
2784,
7256,
199,
1802,
26,
523,
446,
961,
859,
6571,
30191,
10041,
402,
26549,
272,
641,
603,
352,
1502,
19131,
5258,
16936,
2784,
7256,
14,
199,
1419,
26,
523,
1174,
63,
3827,
26,
272,
1369,
26,
489,
446,
3447,
5921,
15,
2825,
5921,
314,
1174,
402,
314,
26549,
2897,
14,
272,
730,
26,
2155,
523,
8966,
63,
354,
26,
272,
1369,
26,
489,
446,
10729,
314,
26549,
8966,
536,
14,
272,
730,
26,
620,
523,
2909,
26,
272,
1369,
26,
489,
446,
10729,
314,
26549,
2909,
14,
272,
730,
26,
620,
523,
1923,
22047,
63,
3827,
26,
272,
1369,
26,
489,
446,
3447,
5921,
15,
2825,
5921,
23633,
13,
6788,
6299,
641,
314,
2656,
14,
272,
730,
26,
2155,
523,
3510,
63,
1404,
22047,
63,
3827,
26,
272,
1369,
26,
489,
446,
3447,
5921,
15,
2825,
5921,
3663,
1923,
22047,
370,
506,
7526,
14,
272,
730,
26,
2155,
523,
20143,
63,
1404,
22047,
26,
272,
730,
26,
769,
272,
1369,
26,
489,
446,
3820,
402,
20143,
1923,
22047,
272,
26265,
26,
489,
23633,
63,
354,
26,
267,
1369,
26,
881,
446,
4094,
1482,
20143,
23633,
536,
14,
267,
1415,
26,
2549,
267,
730,
26,
620,
489,
23633,
63,
466,
26,
267,
1369,
26,
881,
446,
2654,
642,
23633,
465,
1902,
282,
1586,
13,
2118,
503,
1586,
13,
952,
23633,
14,
267,
3415,
26,
788,
739,
13,
2118,
297,
283,
739,
13,
952,
418,
267,
730,
26,
620,
489,
1174,
26,
267,
1369,
26,
1467,
446,
8051,
370,
19822,
340,
1265,
2934,
370,
3145,
314,
1627,
20143,
23633,
503,
440,
267,
3415,
26,
788,
1881,
297,
283,
5575,
418,
267,
730,
26,
620,
523,
11705,
63,
3827,
26,
272,
1369,
26,
489,
446,
3447,
5921,
15,
2825,
5921,
10209,
402,
26549,
13116,
334,
1239,
1190,
436,
315,
3351,
9,
687,
314,
69,
2656,
14,
272,
730,
26,
2155,
523,
11705,
63,
719,
26,
272,
1369,
26,
489,
446,
10729,
314,
849,
1844,
370,
1314,
13116,
787,
4847,
14,
272,
730,
26,
620,
523,
11705,
63,
9387,
26,
272,
1369,
26,
489,
446,
10729,
314,
849,
23633,
367,
26549,
373,
17,
436,
373,
18,
67,
13116,
4847,
370,
7057,
1314,
886,
440,
1172,
282,
23633,
4278,
663,
14,
272,
730,
26,
620,
523,
11705,
63,
2254,
63,
396,
26,
272,
1369,
26,
489,
446,
221,
428,
3198,
282,
511,
6955,
14,
272,
730,
26,
620,
272,
3415,
26,
788,
5066,
1673,
889,
418,
523,
11705,
63,
1430,
26,
272,
1369,
26,
489,
446,
5367,
70,
588,
1314,
4474,
911,
506,
4847,
465,
26549,
13116,
14,
272,
730,
26,
620,
272,
3415,
26,
788,
2484,
13,
28329,
13,
2110,
297,
283,
68,
2894,
88,
13,
24419,
13,
719,
13,
2262,
13,
929,
13,
19510,
297,
283,
3617,
12983,
13,
5652,
297,
283,
77,
20643,
13,
1222,
13,
9528,
13,
1231,
297,
586,
283,
18303,
13,
9582,
13,
11227,
23302,
13,
14108,
297,
283,
3300,
13,
2379,
297,
283,
751,
13,
11646,
297,
283,
2764,
13,
604,
13,
22564,
297,
283,
68,
2894,
88,
13,
24419,
13,
719,
13,
7866,
13,
929,
13,
19510,
297,
586,
283,
3266,
13,
2110,
297,
283,
77,
20643,
13,
1222,
13,
1231,
13,
719,
297,
283,
18303,
13,
9582,
13,
14108,
297,
283,
15523,
13,
1178,
19510,
297,
283,
88,
20643,
13,
1222,
13,
1231,
13,
9528,
297,
586,
283,
3541,
13,
1974,
13,
6260,
297,
283,
4032,
13,
2308,
13,
6260,
297,
283,
3266,
13,
384,
297,
283,
77,
20643,
13,
10775,
13,
1461,
297,
283,
18303,
13,
23299,
13,
929,
13,
1461,
297,
586,
283,
12954,
13,
7354,
13,
6260,
297,
283,
88,
20643,
13,
1231,
13,
719,
13,
1461,
297,
283,
68,
2894,
88,
13,
8716,
13,
578,
13,
929,
13,
1461,
297,
283,
4032,
13,
2638,
13,
674,
297,
586,
283,
4672,
13,
5610,
13,
705,
297,
283,
846,
3807,
13,
6260,
297,
283,
31691,
13,
6260,
297,
283,
10775,
63,
1461,
297,
283,
88,
20643,
13,
10775,
13,
1461,
297,
586,
283,
68,
2894,
88,
13,
8716,
13,
719,
13,
2113,
13,
929,
13,
19510,
297,
283,
4502,
13,
929,
13,
1461,
297,
283,
4672,
13,
1073,
13,
7625,
13,
20759,
297,
283,
1222,
63,
1231,
297,
586,
283,
5652,
13,
581,
32270,
13,
20759,
297,
283,
8953,
13,
4201,
13,
904,
297,
283,
68,
2894,
88,
13,
8716,
13,
719,
13,
2262,
13,
929,
13,
19510,
297,
283,
2062,
13,
8831,
297,
586,
283,
317,
1856,
16709,
13,
5328,
297,
283,
18303,
13,
1178,
13,
1633,
297,
283,
1412,
13,
14807,
297,
283,
8953,
13,
4201,
13,
12422,
297,
283,
68,
2894,
88,
13,
8716,
13,
719,
13,
7866,
13,
929,
13,
19510,
297,
586,
283,
9665,
13,
578,
13,
1205,
297,
283,
674,
13,
5652,
297,
283,
18303,
13,
888,
13,
705,
297,
283,
1412,
13,
2224,
297,
283,
8953,
13,
4201,
13,
890,
297,
586,
283,
68,
2894,
88,
13,
24419,
13,
578,
13,
929,
13,
1461,
297,
283,
3617,
12983,
13,
70,
796,
297,
283,
674,
13,
5652,
13,
23131,
297,
283,
18303,
13,
692,
13,
6872,
13,
4087,
13,
6253,
297,
586,
283,
3300,
13,
10506,
297,
283,
8953,
13,
8831,
297,
283,
68,
2894,
88,
13,
24419,
13,
719,
13,
2113,
13,
929,
13,
19510,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
alexryndin/ambari
|
ambari-agent/src/main/python/ambari_agent/ClusterConfiguration.py
|
3
|
5925
|
#!/usr/bin/env python
"""
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 logging
import ambari_simplejson as json
import os
import threading
logger = logging.getLogger(__name__)
class ClusterConfiguration():
"""
Maintains an in-memory cache and disk cache of the configurations for
every cluster. This is useful for having quick access to any of the
configuration properties.
"""
FILENAME = 'configurations.json'
# constants that define which commands hold configurations that can be
# used to populate this cache
EXECUTION_COMMANDS = 'executionCommands'
ALERT_DEFINITION_COMMANDS = 'alertDefinitionCommands'
COMMANDS_WITH_CONFIGURATIONS = [EXECUTION_COMMANDS, ALERT_DEFINITION_COMMANDS]
def __init__(self, cluster_config_cache_dir):
"""
Initializes the configuration cache.
:param cluster_config_cache_dir:
:return:
"""
self.cluster_config_cache_dir = cluster_config_cache_dir
# keys are cluster names, values are configurations
self.__configurations = {}
self.__file_lock = threading.RLock()
self.__cache_lock = threading.RLock()
self.__config_json_file = os.path.join(self.cluster_config_cache_dir, self.FILENAME)
# ensure that our cache directory exists
if not os.path.exists(cluster_config_cache_dir):
try:
os.makedirs(cluster_config_cache_dir)
except:
logger.critical("Could not create the cluster configuration cache directory {0}".format(cluster_config_cache_dir))
# if the file exists, then load it
try:
if os.path.isfile(self.__config_json_file):
with open(self.__config_json_file, 'r') as fp:
self.__configurations = json.load(fp)
except Exception, exception:
logger.warning("Unable to load configurations from {0}. This file will be regenerated on registration".format(self.__config_json_file))
def update_configurations_from_heartbeat(self, heartbeat):
"""
Updates the in-memory and disk-based cluster configurations based on
the heartbeat. This will only update configurations on the following
types of commands in the heartbeat: execution, and alert definition.
:param heartbeat: the heartbeat response
:return:
"""
heartbeat_keys = heartbeat.keys()
heartbeat_contains_configurations = False
for commandType in self.COMMANDS_WITH_CONFIGURATIONS:
if commandType in heartbeat_keys:
heartbeat_contains_configurations = True
# if this heartbeat doesn't contain a command with configurations, then
# don't process it
if heartbeat_contains_configurations is False:
return
if self.EXECUTION_COMMANDS in heartbeat_keys:
execution_commands = heartbeat[self.EXECUTION_COMMANDS]
for command in execution_commands:
if 'clusterName' in command and 'configurations' in command:
cluster_name = command['clusterName']
configurations = command['configurations']
self._update_configurations(cluster_name, configurations)
if self.ALERT_DEFINITION_COMMANDS in heartbeat_keys:
alert_definition_commands = heartbeat[self.ALERT_DEFINITION_COMMANDS]
for command in alert_definition_commands:
if 'clusterName' in command and 'configurations' in command:
cluster_name = command['clusterName']
configurations = command['configurations']
self._update_configurations(cluster_name, configurations)
def _update_configurations(self, cluster_name, configuration):
"""
Thread-safe method for writing out the specified cluster configuration
and updating the in-memory representation.
:param cluster_name:
:param configuration:
:return:
"""
logger.info("Updating cached configurations for cluster {0}".format(cluster_name))
self.__cache_lock.acquire()
try:
self.__configurations[cluster_name] = configuration
except Exception, exception :
logger.exception("Unable to update configurations for cluster {0}".format(cluster_name))
finally:
self.__cache_lock.release()
self.__file_lock.acquire()
try:
with os.fdopen(os.open(self.__config_json_file, os.O_WRONLY | os.O_CREAT, 0o600), "w") as f:
json.dump(self.__configurations, f, indent=2)
except Exception, exception :
logger.exception("Unable to update configurations for cluster {0}".format(cluster_name))
finally:
self.__file_lock.release()
def get_configuration_value(self, cluster_name, key):
"""
Gets a value from the cluster configuration map for the given cluster and
key. The key is expected to be of the form 'foo-bar/baz' or
'foo-bar/bar-baz/foobarbaz' where every / denotes a new mapping
:param key: a lookup key, like 'foo-bar/baz'
:return: the value, or None if not found
"""
self.__cache_lock.acquire()
try:
dictionary = self.__configurations[cluster_name]
for layer_key in key.split('/'):
dictionary = dictionary[layer_key]
return dictionary
except Exception:
logger.debug("Cache miss for configuration property {0} in cluster {1}".format(key, cluster_name))
return None
finally:
self.__cache_lock.release()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
2,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
624,
199,
199,
646,
2050,
199,
646,
16353,
759,
63,
4129,
1001,
465,
2022,
199,
646,
747,
199,
646,
5796,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
16454,
5688,
837,
523,
408,
523,
16593,
8368,
83,
376,
315,
13,
4844,
2581,
436,
4543,
2581,
402,
314,
13422,
367,
523,
4036,
4350,
14,
961,
365,
2997,
367,
9445,
12530,
2879,
370,
1263,
402,
314,
523,
2897,
4382,
14,
523,
408,
819,
16444,
11536,
275,
283,
10057,
14,
1001,
7,
819,
327,
5262,
626,
5627,
1314,
3718,
10266,
13422,
626,
883,
506,
523,
327,
1202,
370,
13904,
642,
2581,
523,
3651,
4220,
27129,
63,
28442,
275,
283,
9416,
14680,
7,
523,
12112,
5397,
63,
5638,
8727,
1075,
63,
28442,
275,
283,
9241,
10701,
14680,
7,
523,
11293,
20033,
63,
9139,
63,
5569,
1230,
12969,
275,
359,
18074,
1075,
63,
28442,
12,
12112,
5397,
63,
5638,
8727,
1075,
63,
28442,
61,
819,
347,
636,
826,
721,
277,
12,
4350,
63,
888,
63,
1637,
63,
694,
304,
272,
408,
272,
6026,
6491,
314,
2897,
2581,
14,
272,
520,
635,
4350,
63,
888,
63,
1637,
63,
694,
26,
272,
520,
1107,
26,
272,
408,
272,
291,
14,
4201,
63,
888,
63,
1637,
63,
694,
275,
4350,
63,
888,
63,
1637,
63,
694,
339,
327,
2883,
787,
4350,
1561,
12,
1338,
787,
13422,
272,
291,
855,
10057,
275,
1052,
339,
291,
855,
493,
63,
831,
275,
5796,
14,
30550,
342,
272,
291,
855,
1637,
63,
831,
275,
5796,
14,
30550,
342,
272,
291,
855,
888,
63,
1001,
63,
493,
275,
747,
14,
515,
14,
904,
8,
277,
14,
4201,
63,
888,
63,
1637,
63,
694,
12,
291,
14,
15440,
9,
339,
327,
4868,
626,
4154,
2581,
2082,
3495,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
4201,
63,
888,
63,
1637,
63,
694,
304,
489,
862,
26,
267,
747,
14,
8347,
8,
4201,
63,
888,
63,
1637,
63,
694,
9,
489,
871,
26,
267,
2512,
14,
13138,
480,
6531,
440,
1218,
314,
4350,
2897,
2581,
2082,
469,
16,
5469,
908,
8,
4201,
63,
888,
63,
1637,
63,
694,
430,
339,
327,
340,
314,
570,
3495,
12,
2066,
2248,
652,
272,
862,
26,
489,
340,
747,
14,
515,
14,
6292,
8,
277,
855,
888,
63,
1001,
63,
493,
304,
267,
543,
1551,
8,
277,
855,
888,
63,
1001,
63,
493,
12,
283,
82,
358,
465,
4090,
26,
881,
291,
855,
10057,
275,
2022,
14,
912,
8,
3997,
9,
272,
871,
2186,
12,
1919,
26,
489,
2512,
14,
3764,
480,
6005,
370,
2248,
13422,
687,
469,
16,
5565,
961,
570,
911,
506,
31904,
641,
10991,
1674,
908,
8,
277,
855,
888,
63,
1001,
63,
493,
430,
8330,
347,
1678,
63,
10057,
63,
504,
63,
22685,
8,
277,
12,
32015,
304,
272,
408,
272,
24663,
314,
315,
13,
4844,
436,
4543,
13,
6788,
4350,
13422,
4079,
641,
272,
314,
32015,
14,
961,
911,
1454,
1678,
13422,
641,
314,
2569,
272,
2943,
402,
3718,
315,
314,
32015,
26,
6451,
12,
436,
10459,
5492,
14,
272,
520,
635,
32015,
26,
314,
32015,
1177,
272,
520,
1107,
26,
272,
408,
272,
32015,
63,
1612,
275,
32015,
14,
1612,
342,
339,
32015,
63,
6134,
63,
10057,
275,
756,
272,
367,
1414,
804,
315,
291,
14,
28442,
63,
9139,
63,
5569,
1230,
12969,
26,
489,
340,
1414,
804,
315,
32015,
63,
1612,
26,
267,
32015,
63,
6134,
63,
10057,
275,
715,
339,
327,
340,
642,
32015,
3181,
1133,
1395,
282,
1414,
543,
13422,
12,
2066,
272,
327,
2793,
1133,
2112,
652,
272,
340,
32015,
63,
6134,
63,
10057,
365,
756,
26,
489,
372,
339,
340,
291,
14,
18074,
1075,
63,
28442,
315,
32015,
63,
1612,
26,
489,
6451,
63,
4405,
275,
32015,
59,
277,
14,
18074,
1075,
63,
28442,
61,
489,
367,
1414,
315,
6451,
63,
4405,
26,
267,
340,
283,
4201,
985,
7,
315,
1414,
436,
283,
10057,
7,
315,
1414,
26,
881,
4350,
63,
354,
275,
1414,
459,
4201,
985,
418,
881,
13422,
275,
1414,
459,
10057,
418,
881,
291,
423,
873,
63,
10057,
8,
4201,
63,
354,
12,
13422,
9,
339,
340,
291,
14,
748,
5397,
63,
5638,
8727,
1075,
63,
28442,
315,
32015,
63,
1612,
26,
489,
10459,
63,
7463,
63,
4405,
275,
32015,
59,
277,
14,
748,
5397,
63,
5638,
8727,
1075,
63,
28442,
61,
489,
367,
1414,
315,
10459,
63,
7463,
63,
4405,
26,
267,
340,
283,
4201,
985,
7,
315,
1414,
436,
283,
10057,
7,
315,
1414,
26,
881,
4350,
63,
354,
275,
1414,
459,
4201,
985,
418,
881,
13422,
275,
1414,
459,
10057,
418,
881,
291,
423,
873,
63,
10057,
8,
4201,
63,
354,
12,
13422,
9,
8330,
347,
485,
873,
63,
10057,
8,
277,
12,
4350,
63,
354,
12,
2897,
304,
272,
408,
272,
11086,
13,
3489,
1083,
367,
3575,
734,
314,
2013,
4350,
2897,
272,
436,
12928,
314,
315,
13,
4844,
6025,
14,
272,
520,
635,
4350,
63,
354,
26,
272,
520,
635,
2897,
26,
272,
520,
1107,
26,
272,
408,
272,
2512,
14,
815,
480,
24993,
6328,
13422,
367,
4350,
469,
16,
5469,
908,
8,
4201,
63,
354,
430,
339,
291,
855,
1637,
63,
831
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
624,
199,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
2,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
1045,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
339,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
624,
199,
199,
646,
2050,
199,
646,
16353,
759,
63,
4129,
1001,
465,
2022,
199,
646,
747,
199,
646,
5796,
199,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
533,
16454,
5688,
837,
523,
408,
523,
16593,
8368,
83,
376,
315,
13,
4844,
2581,
436,
4543,
2581,
402,
314,
13422,
367,
523,
4036,
4350,
14,
961,
365,
2997,
367,
9445,
12530,
2879,
370,
1263,
402,
314,
523,
2897,
4382,
14,
523,
408,
819,
16444,
11536,
275,
283,
10057,
14,
1001,
7,
819,
327,
5262,
626,
5627,
1314,
3718,
10266,
13422,
626,
883,
506,
523,
327,
1202,
370,
13904,
642,
2581,
523,
3651,
4220,
27129,
63,
28442,
275,
283,
9416,
14680,
7,
523,
12112,
5397,
63,
5638,
8727,
1075,
63,
28442,
275,
283,
9241,
10701,
14680,
7,
523,
11293,
20033,
63,
9139,
63,
5569,
1230,
12969,
275,
359,
18074,
1075,
63,
28442,
12,
12112,
5397,
63,
5638,
8727,
1075,
63,
28442,
61,
819,
347,
636,
826,
721,
277,
12,
4350,
63,
888,
63,
1637,
63,
694,
304,
272,
408,
272,
6026,
6491,
314,
2897,
2581,
14,
272,
520,
635,
4350,
63,
888,
63,
1637,
63,
694,
26,
272,
520,
1107,
26,
272,
408,
272,
291,
14,
4201,
63,
888,
63,
1637,
63,
694,
275,
4350,
63,
888,
63,
1637,
63,
694,
339,
327,
2883,
787,
4350,
1561,
12,
1338,
787,
13422,
272,
291,
855,
10057,
275,
1052,
339,
291,
855,
493,
63,
831,
275,
5796,
14,
30550,
342,
272,
291,
855,
1637,
63,
831,
275,
5796,
14,
30550,
342,
272,
291,
855,
888,
63,
1001,
63,
493,
275,
747,
14,
515,
14,
904,
8,
277,
14,
4201,
63,
888,
63,
1637,
63,
694,
12,
291,
14,
15440,
9,
339,
327,
4868,
626,
4154,
2581,
2082,
3495,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
4201,
63,
888,
63,
1637,
63,
694,
304,
489,
862,
26,
267,
747,
14,
8347,
8,
4201,
63,
888,
63,
1637,
63,
694,
9,
489,
871,
26,
267,
2512,
14,
13138,
480,
6531,
440,
1218,
314,
4350,
2897,
2581,
2082,
469,
16,
5469,
908,
8,
4201,
63,
888,
63,
1637,
63,
694,
430,
339,
327,
340,
314,
570,
3495,
12,
2066,
2248,
652,
272,
862,
26,
489,
340,
747,
14,
515,
14,
6292,
8,
277,
855,
888,
63,
1001,
63,
493,
304,
267,
543,
1551,
8,
277,
855,
888,
63,
1001,
63,
493,
12,
283,
82,
358,
465,
4090,
26,
881,
291,
855,
10057,
275,
2022,
14,
912,
8,
3997,
9,
272,
871,
2186,
12,
1919,
26,
489,
2512,
14,
3764,
480,
6005,
370,
2248,
13422,
687,
469,
16,
5565,
961,
570,
911,
506,
31904,
641,
10991,
1674,
908,
8,
277,
855,
888,
63,
1001,
63,
493,
430,
8330,
347,
1678,
63,
10057,
63,
504,
63,
22685,
8,
277,
12,
32015,
304,
272,
408,
272,
24663,
314,
315,
13,
4844,
436,
4543,
13,
6788,
4350,
13422,
4079,
641,
272,
314,
32015,
14,
961,
911,
1454,
1678,
13422,
641,
314,
2569,
272,
2943,
402,
3718,
315,
314,
32015,
26,
6451,
12,
436,
10459,
5492,
14,
272,
520,
635,
32015,
26,
314,
32015,
1177,
272,
520,
1107,
26,
272,
408,
272,
32015,
63,
1612,
275,
32015,
14,
1612,
342,
339,
32015,
63,
6134,
63,
10057,
275,
756,
272,
367,
1414,
804,
315,
291,
14,
28442,
63,
9139,
63,
5569,
1230,
12969,
26,
489,
340,
1414,
804,
315,
32015,
63,
1612,
26,
267,
32015,
63,
6134,
63,
10057,
275,
715,
339,
327,
340,
642,
32015,
3181,
1133,
1395,
282,
1414,
543,
13422,
12,
2066,
272,
327,
2793,
1133,
2112,
652,
272,
340,
32015,
63,
6134,
63,
10057,
365,
756,
26,
489,
372,
339,
340,
291,
14,
18074,
1075,
63,
28442,
315,
32015,
63,
1612,
26,
489,
6451,
63,
4405,
275,
32015,
59,
277,
14,
18074,
1075,
63,
28442,
61,
489,
367,
1414,
315,
6451,
63,
4405,
26,
267,
340,
283,
4201,
985,
7,
315,
1414,
436,
283,
10057,
7,
315,
1414,
26,
881,
4350,
63,
354,
275,
1414,
459,
4201,
985,
418,
881,
13422,
275,
1414,
459,
10057,
418,
881,
291,
423,
873,
63,
10057,
8,
4201,
63,
354,
12,
13422,
9,
339,
340,
291,
14,
748,
5397,
63,
5638,
8727,
1075,
63,
28442,
315,
32015,
63,
1612,
26,
489,
10459,
63,
7463,
63,
4405,
275,
32015,
59,
277,
14,
748,
5397,
63,
5638,
8727,
1075,
63,
28442,
61,
489,
367,
1414,
315,
10459,
63,
7463,
63,
4405,
26,
267,
340,
283,
4201,
985,
7,
315,
1414,
436,
283,
10057,
7,
315,
1414,
26,
881,
4350,
63,
354,
275,
1414,
459,
4201,
985,
418,
881,
13422,
275,
1414,
459,
10057,
418,
881,
291,
423,
873,
63,
10057,
8,
4201,
63,
354,
12,
13422,
9,
8330,
347,
485,
873,
63,
10057,
8,
277,
12,
4350,
63,
354,
12,
2897,
304,
272,
408,
272,
11086,
13,
3489,
1083,
367,
3575,
734,
314,
2013,
4350,
2897,
272,
436,
12928,
314,
315,
13,
4844,
6025,
14,
272,
520,
635,
4350,
63,
354,
26,
272,
520,
635,
2897,
26,
272,
520,
1107,
26,
272,
408,
272,
2512,
14,
815,
480,
24993,
6328,
13422,
367,
4350,
469,
16,
5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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
atopuzov/nitro-python
|
nssrc/com/citrix/netscaler/nitro/resource/config/network/vridparam.py
|
3
|
4003
|
#
# Copyright (c) 2008-2015 Citrix Systems, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License")
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from nssrc.com.citrix.netscaler.nitro.resource.base.base_resource import base_resource
from nssrc.com.citrix.netscaler.nitro.resource.base.base_resource import base_response
from nssrc.com.citrix.netscaler.nitro.service.options import options
from nssrc.com.citrix.netscaler.nitro.exception.nitro_exception import nitro_exception
from nssrc.com.citrix.netscaler.nitro.util.nitro_util import nitro_util
class vridparam(base_resource) :
""" Configuration for VR ID parameter resource. """
def __init__(self) :
self._sendtomaster = ""
@property
def sendtomaster(self) :
ur"""Forward packets to the master node, in an active-active mode configuration, if the virtual server is in the backup state and sharing is disabled.<br/>Default value: DISABLED<br/>Possible values = ENABLED, DISABLED.
"""
try :
return self._sendtomaster
except Exception as e:
raise e
@sendtomaster.setter
def sendtomaster(self, sendtomaster) :
ur"""Forward packets to the master node, in an active-active mode configuration, if the virtual server is in the backup state and sharing is disabled.<br/>Default value: DISABLED<br/>Possible values = ENABLED, DISABLED
"""
try :
self._sendtomaster = sendtomaster
except Exception as e:
raise e
def _get_nitro_response(self, service, response) :
ur""" converts nitro response into object and returns the object array in case of get request.
"""
try :
result = service.payload_formatter.string_to_resource(vridparam_response, response, self.__class__.__name__)
if(result.errorcode != 0) :
if (result.errorcode == 444) :
service.clear_session(self)
if result.severity :
if (result.severity == "ERROR") :
raise nitro_exception(result.errorcode, str(result.message), str(result.severity))
else :
raise nitro_exception(result.errorcode, str(result.message), str(result.severity))
return result.vridparam
except Exception as e :
raise e
def _get_object_name(self) :
ur""" Returns the value of object identifier argument
"""
try :
return 0
except Exception as e :
raise e
@classmethod
def update(cls, client, resource) :
ur""" Use this API to update vridparam.
"""
try :
if type(resource) is not list :
updateresource = vridparam()
updateresource.sendtomaster = resource.sendtomaster
return updateresource.update_resource(client)
except Exception as e :
raise e
@classmethod
def unset(cls, client, resource, args) :
ur""" Use this API to unset the properties of vridparam resource.
Properties that need to be unset are specified in args array.
"""
try :
if type(resource) is not list :
unsetresource = vridparam()
return unsetresource.unset_resource(client, args)
except Exception as e :
raise e
@classmethod
def get(cls, client, name="", option_="") :
ur""" Use this API to fetch all the vridparam resources that are configured on netscaler.
"""
try :
if not name :
obj = vridparam()
response = obj.get_resources(client, option_)
return response
except Exception as e :
raise e
class Sendtomaster:
ENABLED = "ENABLED"
DISABLED = "DISABLED"
class vridparam_response(base_response) :
def __init__(self, length=1) :
self.vridparam = []
self.errorcode = 0
self.message = ""
self.severity = ""
self.sessionid = ""
self.vridparam = [vridparam() for _ in range(length)]
|
apache-2.0
|
[
3,
199,
3,
1898,
334,
67,
9,
9079,
13,
7806,
445,
390,
1904,
15285,
12,
3277,
14,
199,
3,
199,
3,
257,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
531,
199,
3,
257,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
257,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
755,
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,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
257,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
504,
302,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1927,
14,
1095,
14,
1095,
63,
1927,
492,
1300,
63,
1927,
199,
504,
302,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1927,
14,
1095,
14,
1095,
63,
1927,
492,
1300,
63,
1310,
199,
504,
302,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1364,
14,
1419,
492,
1511,
199,
504,
302,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1971,
14,
18893,
63,
1971,
492,
20107,
63,
1971,
199,
199,
504,
302,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1974,
14,
18893,
63,
1974,
492,
20107,
63,
1974,
199,
199,
533,
373,
1677,
635,
8,
1095,
63,
1927,
9,
520,
199,
198,
624,
11595,
367,
812,
50,
2870,
2725,
2073,
14,
408,
199,
198,
318,
636,
826,
721,
277,
9,
520,
507,
198,
277,
423,
2254,
3151,
2311,
275,
3087,
421,
198,
32,
1829,
199,
198,
318,
3222,
3151,
2311,
8,
277,
9,
520,
507,
198,
300,
624,
12984,
14593,
370,
314,
5288,
1031,
12,
315,
376,
4702,
13,
2682,
818,
2897,
12,
340,
314,
5791,
1654,
365,
315,
314,
6902,
1174,
436,
26994,
365,
6980,
21455,
3289,
3133,
2698,
574,
26,
32147,
36,
28,
3289,
3133,
28096,
1338,
275,
27926,
36,
12,
32147,
36,
14,
507,
198,
624,
507,
198,
893,
520,
686,
198,
1107,
291,
423,
2254,
3151,
2311,
507,
198,
2590,
2186,
465,
325,
26,
686,
198,
3730,
325,
421,
198,
32,
2254,
3151,
2311,
14,
8345,
199,
198,
318,
3222,
3151,
2311,
8,
277,
12,
3222,
3151,
2311,
9,
520,
507,
198,
300,
624,
12984,
14593,
370,
314,
5288,
1031,
12,
315,
376,
4702,
13,
2682,
818,
2897,
12,
340,
314,
5791,
1654,
365,
315,
314,
6902,
1174,
436,
26994,
365,
6980,
21455,
3289,
3133,
2698,
574,
26,
32147,
36,
28,
3289,
3133,
28096,
1338,
275,
27926,
36,
12,
32147,
36,
507,
198,
624,
507,
198,
893,
520,
686,
198,
277,
423,
2254,
3151,
2311,
275,
3222,
3151,
2311,
507,
198,
2590,
2186,
465,
325,
26,
686,
198,
3730,
325,
421,
198,
318,
485,
362,
63,
18893,
63,
1310,
8,
277,
12,
2435,
12,
1177,
9,
520,
507,
198,
300,
624,
15373,
20107,
1177,
1901,
909,
436,
2529,
314,
909,
1625,
315,
1930,
402,
664,
1056,
14,
507,
198,
624,
507,
198,
893,
520,
686,
198,
1099,
275,
2435,
14,
4749,
63,
8911,
14,
875,
63,
475,
63,
1927,
8,
86,
1677,
635,
63,
1310,
12,
1177,
12,
291,
855,
533,
4914,
354,
3368,
686,
198,
692,
8,
1099,
14,
28857,
1137,
378,
9,
520,
1585,
198,
692,
334,
1099,
14,
28857,
508,
841,
1602,
9,
520,
1871,
198,
1364,
14,
3584,
63,
1730,
8,
277,
9,
1585,
198,
692,
754,
14,
20394,
520,
1871,
198,
692,
334,
1099,
14,
20394,
508,
298,
3170,
531,
520,
4671,
198,
3730,
20107,
63,
1971,
8,
1099,
14,
28857,
12,
620,
8,
1099,
14,
1188,
395,
620,
8,
1099,
14,
20394,
430,
1585,
198,
2836,
520,
1871,
198,
3730,
20107,
63,
1971,
8,
1099,
14,
28857,
12,
620,
8,
1099,
14,
1188,
395,
620,
8,
1099,
14,
20394,
430,
686,
198,
1107,
754,
14,
86,
1677,
635,
507,
198,
2590,
2186,
465,
325,
520,
686,
198,
3730,
325,
421,
198,
318,
485,
362,
63,
785,
63,
354,
8,
277,
9,
520,
507,
198,
300,
624,
1803,
314,
574,
402,
909,
5148,
1423,
507,
198,
624,
507,
198,
893,
520,
686,
198,
1107,
378,
507,
198,
2590,
2186,
465,
325,
520,
686,
198,
3730,
325,
6905,
198,
32,
3744,
199,
198,
318,
1678,
8,
1886,
12,
1890,
12,
2073,
9,
520,
507,
198,
300,
624,
3645,
642,
3261,
370,
1678,
373,
1677,
635,
14,
507,
198,
624,
507,
198,
893,
520,
686,
198,
692,
730,
8,
1927,
9,
365,
440,
769,
520,
1585,
198,
873,
1927,
275,
373,
1677,
635,
342,
1585,
198,
873,
1927,
14,
2254,
3151,
2311,
275,
2073,
14,
2254,
3151,
2311,
1585,
198,
1107,
1678,
1927,
14,
873,
63,
1927,
8,
1258,
9,
507,
198,
2590,
2186,
465,
325,
520,
686,
198,
3730,
325,
421,
198,
32,
3744,
199,
198,
318,
15376,
8,
1886,
12,
1890,
12,
2073,
12,
1249,
9,
520,
507,
198,
300,
624,
3645,
642,
3261,
370,
15376,
314,
4382,
402,
373,
1677,
635,
2073,
14,
507,
198,
8516,
626,
1929,
370,
506,
15376,
787,
2013,
315,
1249,
1625,
14,
507,
198,
624,
507,
198,
893,
520,
686,
198,
692,
730,
8,
1927,
9,
365,
440,
769,
520,
1585,
198,
16787,
1927,
275,
373,
1677,
635,
342,
1585,
198,
1107,
15376,
1927,
14,
16787,
63,
1927,
8,
1258,
12,
1249,
9,
507,
198,
2590,
2186,
465,
325,
520,
686,
198,
3730,
325,
421,
198,
32,
3744,
199,
198,
318,
664,
8,
1886,
12,
1890,
12,
536,
8772,
945,
10683,
7230,
520,
507,
198,
300,
624,
3645,
642,
3261,
370,
5267,
1006,
314,
373,
1677,
635,
5944,
626,
787,
7526,
641,
26067,
14,
507,
198,
624,
507,
198,
893,
520,
686,
198,
692,
440,
536,
520,
1585,
198,
1113,
275,
373,
1677,
635,
342,
1585,
198,
1310,
275,
1559,
14,
362,
63,
4435,
8,
1258,
12,
945,
4602,
686,
198,
1107
] |
[
199,
3,
1898,
334,
67,
9,
9079,
13,
7806,
445,
390,
1904,
15285,
12,
3277,
14,
199,
3,
199,
3,
257,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
531,
199,
3,
257,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
257,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
755,
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,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
257,
4204,
1334,
314,
844,
14,
199,
3,
199,
199,
504,
302,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1927,
14,
1095,
14,
1095,
63,
1927,
492,
1300,
63,
1927,
199,
504,
302,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1927,
14,
1095,
14,
1095,
63,
1927,
492,
1300,
63,
1310,
199,
504,
302,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1364,
14,
1419,
492,
1511,
199,
504,
302,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1971,
14,
18893,
63,
1971,
492,
20107,
63,
1971,
199,
199,
504,
302,
32231,
14,
957,
14,
14422,
1904,
14,
18860,
14,
18893,
14,
1974,
14,
18893,
63,
1974,
492,
20107,
63,
1974,
199,
199,
533,
373,
1677,
635,
8,
1095,
63,
1927,
9,
520,
199,
198,
624,
11595,
367,
812,
50,
2870,
2725,
2073,
14,
408,
199,
198,
318,
636,
826,
721,
277,
9,
520,
507,
198,
277,
423,
2254,
3151,
2311,
275,
3087,
421,
198,
32,
1829,
199,
198,
318,
3222,
3151,
2311,
8,
277,
9,
520,
507,
198,
300,
624,
12984,
14593,
370,
314,
5288,
1031,
12,
315,
376,
4702,
13,
2682,
818,
2897,
12,
340,
314,
5791,
1654,
365,
315,
314,
6902,
1174,
436,
26994,
365,
6980,
21455,
3289,
3133,
2698,
574,
26,
32147,
36,
28,
3289,
3133,
28096,
1338,
275,
27926,
36,
12,
32147,
36,
14,
507,
198,
624,
507,
198,
893,
520,
686,
198,
1107,
291,
423,
2254,
3151,
2311,
507,
198,
2590,
2186,
465,
325,
26,
686,
198,
3730,
325,
421,
198,
32,
2254,
3151,
2311,
14,
8345,
199,
198,
318,
3222,
3151,
2311,
8,
277,
12,
3222,
3151,
2311,
9,
520,
507,
198,
300,
624,
12984,
14593,
370,
314,
5288,
1031,
12,
315,
376,
4702,
13,
2682,
818,
2897,
12,
340,
314,
5791,
1654,
365,
315,
314,
6902,
1174,
436,
26994,
365,
6980,
21455,
3289,
3133,
2698,
574,
26,
32147,
36,
28,
3289,
3133,
28096,
1338,
275,
27926,
36,
12,
32147,
36,
507,
198,
624,
507,
198,
893,
520,
686,
198,
277,
423,
2254,
3151,
2311,
275,
3222,
3151,
2311,
507,
198,
2590,
2186,
465,
325,
26,
686,
198,
3730,
325,
421,
198,
318,
485,
362,
63,
18893,
63,
1310,
8,
277,
12,
2435,
12,
1177,
9,
520,
507,
198,
300,
624,
15373,
20107,
1177,
1901,
909,
436,
2529,
314,
909,
1625,
315,
1930,
402,
664,
1056,
14,
507,
198,
624,
507,
198,
893,
520,
686,
198,
1099,
275,
2435,
14,
4749,
63,
8911,
14,
875,
63,
475,
63,
1927,
8,
86,
1677,
635,
63,
1310,
12,
1177,
12,
291,
855,
533,
4914,
354,
3368,
686,
198,
692,
8,
1099,
14,
28857,
1137,
378,
9,
520,
1585,
198,
692,
334,
1099,
14,
28857,
508,
841,
1602,
9,
520,
1871,
198,
1364,
14,
3584,
63,
1730,
8,
277,
9,
1585,
198,
692,
754,
14,
20394,
520,
1871,
198,
692,
334,
1099,
14,
20394,
508,
298,
3170,
531,
520,
4671,
198,
3730,
20107,
63,
1971,
8,
1099,
14,
28857,
12,
620,
8,
1099,
14,
1188,
395,
620,
8,
1099,
14,
20394,
430,
1585,
198,
2836,
520,
1871,
198,
3730,
20107,
63,
1971,
8,
1099,
14,
28857,
12,
620,
8,
1099,
14,
1188,
395,
620,
8,
1099,
14,
20394,
430,
686,
198,
1107,
754,
14,
86,
1677,
635,
507,
198,
2590,
2186,
465,
325,
520,
686,
198,
3730,
325,
421,
198,
318,
485,
362,
63,
785,
63,
354,
8,
277,
9,
520,
507,
198,
300,
624,
1803,
314,
574,
402,
909,
5148,
1423,
507,
198,
624,
507,
198,
893,
520,
686,
198,
1107,
378,
507,
198,
2590,
2186,
465,
325,
520,
686,
198,
3730,
325,
6905,
198,
32,
3744,
199,
198,
318,
1678,
8,
1886,
12,
1890,
12,
2073,
9,
520,
507,
198,
300,
624,
3645,
642,
3261,
370,
1678,
373,
1677,
635,
14,
507,
198,
624,
507,
198,
893,
520,
686,
198,
692,
730,
8,
1927,
9,
365,
440,
769,
520,
1585,
198,
873,
1927,
275,
373,
1677,
635,
342,
1585,
198,
873,
1927,
14,
2254,
3151,
2311,
275,
2073,
14,
2254,
3151,
2311,
1585,
198,
1107,
1678,
1927,
14,
873,
63,
1927,
8,
1258,
9,
507,
198,
2590,
2186,
465,
325,
520,
686,
198,
3730,
325,
421,
198,
32,
3744,
199,
198,
318,
15376,
8,
1886,
12,
1890,
12,
2073,
12,
1249,
9,
520,
507,
198,
300,
624,
3645,
642,
3261,
370,
15376,
314,
4382,
402,
373,
1677,
635,
2073,
14,
507,
198,
8516,
626,
1929,
370,
506,
15376,
787,
2013,
315,
1249,
1625,
14,
507,
198,
624,
507,
198,
893,
520,
686,
198,
692,
730,
8,
1927,
9,
365,
440,
769,
520,
1585,
198,
16787,
1927,
275,
373,
1677,
635,
342,
1585,
198,
1107,
15376,
1927,
14,
16787,
63,
1927,
8,
1258,
12,
1249,
9,
507,
198,
2590,
2186,
465,
325,
520,
686,
198,
3730,
325,
421,
198,
32,
3744,
199,
198,
318,
664,
8,
1886,
12,
1890,
12,
536,
8772,
945,
10683,
7230,
520,
507,
198,
300,
624,
3645,
642,
3261,
370,
5267,
1006,
314,
373,
1677,
635,
5944,
626,
787,
7526,
641,
26067,
14,
507,
198,
624,
507,
198,
893,
520,
686,
198,
692,
440,
536,
520,
1585,
198,
1113,
275,
373,
1677,
635,
342,
1585,
198,
1310,
275,
1559,
14,
362,
63,
4435,
8,
1258,
12,
945,
4602,
686,
198,
1107,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
paolodedios/tensorflow
|
tensorflow/python/keras/tests/convert_to_constants_test.py
|
6
|
6291
|
# Copyright 2019 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for convert_to_constants.py."""
import os
import numpy as np
from tensorflow.python import keras
from tensorflow.python.eager import def_function
from tensorflow.python.framework import constant_op
from tensorflow.python.framework import convert_to_constants
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import tensor_spec
from tensorflow.python.keras import testing_utils
from tensorflow.python.module import module
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import init_ops
from tensorflow.python.platform import test
from tensorflow.python.saved_model.load import load
from tensorflow.python.saved_model.save import save
from tensorflow.python.util import nest
class VariablesToConstantsTest(test.TestCase):
def _freezeModel(self, model):
"""Freezes the model.
Args:
model: Function.
Returns:
root: AutoTrackable object with original ConcreteFunction.
output_func: frozen ConcreteFunction.
"""
root = module.Module()
root.f = model
input_func = root.f.get_concrete_function()
output_func = convert_to_constants.convert_variables_to_constants_v2(
input_func, lower_control_flow=False)
return root, output_func
def _hasStatefulPartitionedCallOp(self, graph_def):
"""Determines if a StatefulPartitionedCall op exists in the graph."""
for node in graph_def.node:
if node.op == "StatefulPartitionedCall":
return True
return False
def _getNumVariables(self, graph_def):
"""Returns the number of ReadVariableOp in the graph."""
return sum(node.op == "ReadVariableOp" for node in graph_def.node)
def _testConvertedFunction(self, obj, func, converted_concrete_func,
input_data):
# Ensure the converted graph has no variables and no function calls.
constant_graph_def = converted_concrete_func.graph.as_graph_def()
self.assertEqual(0, self._getNumVariables(constant_graph_def))
self.assertFalse(self._hasStatefulPartitionedCallOp(constant_graph_def))
# Check that the converted ConcreteFunction produces the same result as the
# original Function.
expected_value = nest.flatten(func(**input_data))
actual_value = nest.flatten(converted_concrete_func(**input_data))
for expected, actual in zip(expected_value, actual_value):
np.testing.assert_almost_equal(expected.numpy(), actual.numpy())
# Ensure the shape is retained.
for tensor in converted_concrete_func.inputs:
actual_shape = input_data[tensor.name.split(":")[0]].shape
self.assertEqual(tensor.shape, actual_shape)
# Save the converted ConcreteFunction as a signature.
save_dir = os.path.join(self.get_temp_dir(), "frozen_saved_model")
root = module.Module()
root.f = converted_concrete_func
save(root, save_dir, {"mykey": converted_concrete_func})
# Load it back and make sure it works.
loaded_obj = load(save_dir)
actual_value = nest.flatten(loaded_obj.signatures["mykey"](**input_data))
for expected, actual in zip(expected_value, actual_value):
np.testing.assert_almost_equal(expected.numpy(), actual.numpy())
@testing_utils.run_v2_only
def testKerasModel(self):
"""Test a basic Keras model with Variables."""
input_data = {"x": constant_op.constant(1., shape=[1, 1])}
# Create a simple Keras model.
x = [-1, 0, 1, 2, 3, 4]
y = [-3, -1, 1, 3, 5, 7]
model = keras.models.Sequential(
[keras.layers.Dense(units=1, input_shape=[1])])
model.compile(optimizer="sgd", loss="mean_squared_error")
model.fit(x, y, epochs=1)
@def_function.function(input_signature=[
tensor_spec.TensorSpec(shape=[1, 1], dtype=dtypes.float32)
])
def to_save(x):
return model(x)
root, output_func = self._freezeModel(to_save)
self._testConvertedFunction(root, root.f, output_func, input_data)
@testing_utils.run_v2_only
def testKerasLSTM(self):
"""Test a Keras LSTM containing dynamic_rnn ops."""
input_data = {
"x":
constant_op.constant(
np.array(
np.random.random_sample((10, 10, 10)), dtype=np.float32))
}
model = keras.models.Sequential(
[keras.layers.LSTM(units=10, input_shape=(10, 10))])
@def_function.function(input_signature=[
tensor_spec.TensorSpec(shape=[10, 10, 10], dtype=dtypes.float32)
])
def to_save(x):
return model(x)
root, output_func = self._freezeModel(to_save)
self._testConvertedFunction(root, root.f, output_func, input_data)
@testing_utils.run_v2_only
def testEmbeddings(self):
"""Test model with embeddings."""
input_data = {
"x":
constant_op.constant(
np.array(np.random.random_sample((20)), dtype=np.int32))
}
class EmbeddingModel(keras.Model):
def __init__(self):
super(EmbeddingModel, self).__init__()
self.shared_weights = self.add_weight(
"weights",
shape=(2000, 300),
dtype=dtypes.float32,
initializer=init_ops.random_normal_initializer(
mean=0.0, stddev=300**(-0.5)))
@def_function.function(input_signature=[
tensor_spec.TensorSpec(shape=(20), dtype=dtypes.int32)
])
def func(self, x):
return array_ops.gather(self.shared_weights, x)
model = EmbeddingModel()
root, output_func = self._freezeModel(model.func)
self._testConvertedFunction(root, root.f, output_func, input_data)
if __name__ == "__main__":
test.main()
|
apache-2.0
|
[
3,
1898,
20312,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
3957,
63,
475,
63,
5559,
14,
647,
1041,
199,
199,
646,
747,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
10283,
492,
347,
63,
1593,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
3957,
63,
475,
63,
5559,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1650,
199,
504,
3228,
14,
1548,
14,
8811,
492,
5343,
63,
1208,
199,
504,
3228,
14,
1548,
14,
578,
492,
859,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4205,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
14,
912,
492,
2248,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
14,
2117,
492,
3354,
199,
504,
3228,
14,
1548,
14,
1974,
492,
10715,
421,
199,
533,
17198,
1378,
22185,
774,
8,
396,
14,
1746,
304,
819,
347,
485,
18459,
1685,
8,
277,
12,
1402,
304,
272,
408,
10146,
90,
397,
314,
1402,
14,
339,
3033,
26,
489,
1402,
26,
6801,
14,
339,
1803,
26,
489,
1738,
26,
9195,
7927,
461,
909,
543,
3379,
1448,
7564,
3481,
14,
489,
1072,
63,
1532,
26,
8101,
1448,
7564,
3481,
14,
272,
408,
272,
1738,
275,
859,
14,
2377,
342,
272,
1738,
14,
70,
275,
1402,
272,
1324,
63,
1532,
275,
1738,
14,
70,
14,
362,
63,
13455,
63,
1593,
342,
339,
1072,
63,
1532,
275,
3957,
63,
475,
63,
5559,
14,
3916,
63,
3669,
63,
475,
63,
5559,
63,
86,
18,
8,
267,
1324,
63,
1532,
12,
5117,
63,
2785,
63,
1659,
29,
797,
9,
272,
372,
1738,
12,
1072,
63,
1532,
819,
347,
485,
1989,
2223,
1893,
13068,
379,
2176,
4619,
8,
277,
12,
3343,
63,
318,
304,
272,
408,
872,
18454,
340,
282,
8511,
1893,
13068,
379,
2176,
1687,
3495,
315,
314,
3343,
1041,
272,
367,
1031,
315,
3343,
63,
318,
14,
932,
26,
489,
340,
1031,
14,
411,
508,
298,
2223,
1893,
13068,
379,
2176,
582,
267,
372,
715,
272,
372,
756,
819,
347,
485,
362,
5667,
11458,
8,
277,
12,
3343,
63,
318,
304,
272,
408,
3407,
314,
1329,
402,
5574,
2773,
4619,
315,
314,
3343,
1041,
272,
372,
3089,
8,
932,
14,
411,
508,
298,
3284,
2773,
4619,
2,
367,
1031,
315,
3343,
63,
318,
14,
932,
9,
819,
347,
485,
396,
7619,
471,
3481,
8,
277,
12,
1559,
12,
2562,
12,
6702,
63,
13455,
63,
1532,
12,
2490,
1324,
63,
576,
304,
272,
327,
7523,
314,
6702,
3343,
965,
949,
2860,
436,
949,
805,
4882,
14,
272,
4413,
63,
2180,
63,
318,
275,
6702,
63,
13455,
63,
1532,
14,
2180,
14,
305,
63,
2180,
63,
318,
342,
272,
291,
14,
629,
8,
16,
12,
291,
423,
362,
5667,
11458,
8,
4083,
63,
2180,
63,
318,
430,
272,
291,
14,
3334,
8,
277,
423,
1989,
2223,
1893,
13068,
379,
2176,
4619,
8,
4083,
63,
2180,
63,
318,
430,
339,
327,
2670,
626,
314,
6702,
1448,
7564,
3481,
16904,
314,
2011,
754,
465,
314,
272,
327,
3379,
6801,
14,
272,
1420,
63,
585,
275,
10715,
14,
8487,
8,
1532,
3682,
1210,
63,
576,
430,
272,
3503,
63,
585,
275,
10715,
14,
8487,
8,
22818,
63,
13455,
63,
1532,
3682,
1210,
63,
576,
430,
339,
367,
1420,
12,
3503,
315,
3482,
8,
2062,
63,
585,
12,
3503,
63,
585,
304,
489,
980,
14,
4776,
14,
479,
63,
4398,
63,
1452,
8,
2062,
14,
4714,
1062,
3503,
14,
4714,
1012,
339,
327,
7523,
314,
2215,
365,
30403,
14,
272,
367,
2345,
315,
6702,
63,
13455,
63,
1532,
14,
3711,
26,
489,
3503,
63,
1392,
275,
1324,
63,
576,
59,
3128,
14,
354,
14,
1294,
20063,
59,
16,
20230,
1392,
489,
291,
14,
629,
8,
3128,
14,
1392,
12,
3503,
63,
1392,
9,
339,
327,
11063,
314,
6702,
1448,
7564,
3481,
465,
282,
4955,
14,
272,
3354,
63,
694,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
298,
11202,
63,
8420,
63,
1238,
531,
272,
1738,
275,
859,
14,
2377,
342,
272,
1738,
14,
70,
275,
6702,
63,
13455,
63,
1532,
272,
3354,
8,
1231,
12,
3354,
63,
694,
12,
2420,
1662,
498,
582,
6702,
63,
13455,
63,
1532,
1552,
339,
327,
7190,
652,
1771,
436,
1852,
3238,
652,
5419,
14,
272,
6511,
63,
1113,
275,
2248,
8,
2117,
63,
694,
9,
272,
3503,
63,
585,
275,
10715,
14,
8487,
8,
4591,
63,
1113,
14,
15132,
905,
1662,
498,
937,
3682,
1210,
63,
576,
430,
272,
367,
1420,
12,
3503,
315,
3482,
8,
2062,
63,
585,
12,
3503,
63,
585,
304,
489,
980,
14,
4776,
14,
479,
63,
4398,
63,
1452,
8,
2062,
14,
4714,
1062,
3503,
14,
4714,
1012,
819,
768,
4776,
63,
1208,
14,
1065,
63,
86,
18,
63,
2118,
523,
347,
511,
43,
30037,
1685,
8,
277,
304,
272,
408,
774,
282,
5678,
1804,
30037,
1402,
543,
17198,
1041,
272,
1324,
63,
576,
275,
2420,
88,
582,
4413,
63,
411,
14,
4083,
8,
17,
2020,
2215,
1524,
17,
12,
413,
566,
93,
339,
327,
2790,
282,
3486,
1804,
30037,
1402,
14,
272,
671
] |
[
1898,
20312,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
3957,
63,
475,
63,
5559,
14,
647,
1041,
199,
199,
646,
747,
199,
199,
646,
2680,
465,
980,
199,
199,
504,
3228,
14,
1548,
492,
11708,
199,
504,
3228,
14,
1548,
14,
10283,
492,
347,
63,
1593,
199,
504,
3228,
14,
1548,
14,
4857,
492,
4413,
63,
411,
199,
504,
3228,
14,
1548,
14,
4857,
492,
3957,
63,
475,
63,
5559,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1650,
199,
504,
3228,
14,
1548,
14,
8811,
492,
5343,
63,
1208,
199,
504,
3228,
14,
1548,
14,
578,
492,
859,
199,
504,
3228,
14,
1548,
14,
1483,
492,
1625,
63,
1483,
199,
504,
3228,
14,
1548,
14,
1483,
492,
4205,
63,
1483,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
14,
912,
492,
2248,
199,
504,
3228,
14,
1548,
14,
8420,
63,
1238,
14,
2117,
492,
3354,
199,
504,
3228,
14,
1548,
14,
1974,
492,
10715,
421,
199,
533,
17198,
1378,
22185,
774,
8,
396,
14,
1746,
304,
819,
347,
485,
18459,
1685,
8,
277,
12,
1402,
304,
272,
408,
10146,
90,
397,
314,
1402,
14,
339,
3033,
26,
489,
1402,
26,
6801,
14,
339,
1803,
26,
489,
1738,
26,
9195,
7927,
461,
909,
543,
3379,
1448,
7564,
3481,
14,
489,
1072,
63,
1532,
26,
8101,
1448,
7564,
3481,
14,
272,
408,
272,
1738,
275,
859,
14,
2377,
342,
272,
1738,
14,
70,
275,
1402,
272,
1324,
63,
1532,
275,
1738,
14,
70,
14,
362,
63,
13455,
63,
1593,
342,
339,
1072,
63,
1532,
275,
3957,
63,
475,
63,
5559,
14,
3916,
63,
3669,
63,
475,
63,
5559,
63,
86,
18,
8,
267,
1324,
63,
1532,
12,
5117,
63,
2785,
63,
1659,
29,
797,
9,
272,
372,
1738,
12,
1072,
63,
1532,
819,
347,
485,
1989,
2223,
1893,
13068,
379,
2176,
4619,
8,
277,
12,
3343,
63,
318,
304,
272,
408,
872,
18454,
340,
282,
8511,
1893,
13068,
379,
2176,
1687,
3495,
315,
314,
3343,
1041,
272,
367,
1031,
315,
3343,
63,
318,
14,
932,
26,
489,
340,
1031,
14,
411,
508,
298,
2223,
1893,
13068,
379,
2176,
582,
267,
372,
715,
272,
372,
756,
819,
347,
485,
362,
5667,
11458,
8,
277,
12,
3343,
63,
318,
304,
272,
408,
3407,
314,
1329,
402,
5574,
2773,
4619,
315,
314,
3343,
1041,
272,
372,
3089,
8,
932,
14,
411,
508,
298,
3284,
2773,
4619,
2,
367,
1031,
315,
3343,
63,
318,
14,
932,
9,
819,
347,
485,
396,
7619,
471,
3481,
8,
277,
12,
1559,
12,
2562,
12,
6702,
63,
13455,
63,
1532,
12,
2490,
1324,
63,
576,
304,
272,
327,
7523,
314,
6702,
3343,
965,
949,
2860,
436,
949,
805,
4882,
14,
272,
4413,
63,
2180,
63,
318,
275,
6702,
63,
13455,
63,
1532,
14,
2180,
14,
305,
63,
2180,
63,
318,
342,
272,
291,
14,
629,
8,
16,
12,
291,
423,
362,
5667,
11458,
8,
4083,
63,
2180,
63,
318,
430,
272,
291,
14,
3334,
8,
277,
423,
1989,
2223,
1893,
13068,
379,
2176,
4619,
8,
4083,
63,
2180,
63,
318,
430,
339,
327,
2670,
626,
314,
6702,
1448,
7564,
3481,
16904,
314,
2011,
754,
465,
314,
272,
327,
3379,
6801,
14,
272,
1420,
63,
585,
275,
10715,
14,
8487,
8,
1532,
3682,
1210,
63,
576,
430,
272,
3503,
63,
585,
275,
10715,
14,
8487,
8,
22818,
63,
13455,
63,
1532,
3682,
1210,
63,
576,
430,
339,
367,
1420,
12,
3503,
315,
3482,
8,
2062,
63,
585,
12,
3503,
63,
585,
304,
489,
980,
14,
4776,
14,
479,
63,
4398,
63,
1452,
8,
2062,
14,
4714,
1062,
3503,
14,
4714,
1012,
339,
327,
7523,
314,
2215,
365,
30403,
14,
272,
367,
2345,
315,
6702,
63,
13455,
63,
1532,
14,
3711,
26,
489,
3503,
63,
1392,
275,
1324,
63,
576,
59,
3128,
14,
354,
14,
1294,
20063,
59,
16,
20230,
1392,
489,
291,
14,
629,
8,
3128,
14,
1392,
12,
3503,
63,
1392,
9,
339,
327,
11063,
314,
6702,
1448,
7564,
3481,
465,
282,
4955,
14,
272,
3354,
63,
694,
275,
747,
14,
515,
14,
904,
8,
277,
14,
362,
63,
808,
63,
694,
1062,
298,
11202,
63,
8420,
63,
1238,
531,
272,
1738,
275,
859,
14,
2377,
342,
272,
1738,
14,
70,
275,
6702,
63,
13455,
63,
1532,
272,
3354,
8,
1231,
12,
3354,
63,
694,
12,
2420,
1662,
498,
582,
6702,
63,
13455,
63,
1532,
1552,
339,
327,
7190,
652,
1771,
436,
1852,
3238,
652,
5419,
14,
272,
6511,
63,
1113,
275,
2248,
8,
2117,
63,
694,
9,
272,
3503,
63,
585,
275,
10715,
14,
8487,
8,
4591,
63,
1113,
14,
15132,
905,
1662,
498,
937,
3682,
1210,
63,
576,
430,
272,
367,
1420,
12,
3503,
315,
3482,
8,
2062,
63,
585,
12,
3503,
63,
585,
304,
489,
980,
14,
4776,
14,
479,
63,
4398,
63,
1452,
8,
2062,
14,
4714,
1062,
3503,
14,
4714,
1012,
819,
768,
4776,
63,
1208,
14,
1065,
63,
86,
18,
63,
2118,
523,
347,
511,
43,
30037,
1685,
8,
277,
304,
272,
408,
774,
282,
5678,
1804,
30037,
1402,
543,
17198,
1041,
272,
1324,
63,
576,
275,
2420,
88,
582,
4413,
63,
411,
14,
4083,
8,
17,
2020,
2215,
1524,
17,
12,
413,
566,
93,
339,
327,
2790,
282,
3486,
1804,
30037,
1402,
14,
272,
671,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tiagoantao/tools-iuc
|
tools/cwpair2/cwpair2.py
|
6
|
3371
|
"""
cwpair2.py
Takes a list of called peaks on both strands and produces a list of matched pairs and a list
of unmatched orphans using a specified method for finding matched pairs. Methods for finding
matched pairs are mode, closest, largest or all, where the analysis is run for each method
Input: list of one or more gff format files
Output: files produced for each input/mode combination:
MP (matched_pair), D (details), O (orphans), P (frequency preview plot), F (frequency final plot),
C (statistics graph), statistics.tabular
"""
import argparse
import csv
import cwpair2_util
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--input', dest='inputs', action='append', nargs=2, help="Input datasets")
parser.add_argument('--method', dest='method', default='mode', help='Method of finding match.')
parser.add_argument('--up_distance', dest='up_distance', type=int, default=50, help='Distance upstream from a pair.')
parser.add_argument('--down_distance', dest='down_distance', type=int, default=100, help='Distance downstream of a pair.')
parser.add_argument('--binsize', dest='binsize', type=int, default=1, help='Width of bins for plots and mode.')
parser.add_argument('--threshold_format', dest='threshold_format', help='Percentage to filter the 95th percentile.')
parser.add_argument('--relative_threshold', dest='relative_threshold', type=float, default=0.0, help='Percentage to filter the 95th percentile.')
parser.add_argument('--absolute_threshold', dest='absolute_threshold', type=float, default=0.0, help='Absolute value to filter.')
parser.add_argument('--output_files', dest='output_files', default='matched_pair', help='Restrict output dataset collections.')
parser.add_argument('--statistics_output', dest='statistics_output', help='Statistics output file.')
args = parser.parse_args()
cwpair2_util.create_directories()
statistics = []
if args.absolute_threshold > 0:
threshold = args.absolute_threshold
elif args.relative_threshold > 0:
threshold = args.relative_threshold / 100.0
else:
threshold = 0
for (dataset_path, hid) in args.inputs:
stats = cwpair2_util.process_file(dataset_path,
hid,
args.method,
threshold,
args.up_distance,
args.down_distance,
args.binsize,
args.output_files)
statistics.extend(stats)
# Accumulate statistics.
by_file = {}
for stats in statistics:
# Skip "None" statistics from failed files
if not stats:
continue
path = stats['stats_path']
if path not in by_file:
by_file[path] = []
by_file[path].append(stats)
# Write tabular statistics file.
keys = ['fname', 'final_mode', 'preview_mode', 'perc95', 'paired', 'orphans']
statistics_out = csv.writer(open(args.statistics_output, 'wt'), delimiter='\t')
statistics_out.writerow(keys)
for file_path, statistics in by_file.items():
for stats in statistics:
statistics_out.writerow([stats[key] for key in keys])
|
mit
|
[
624,
199,
15346,
3852,
18,
14,
647,
199,
199,
32488,
282,
769,
402,
2797,
31803,
641,
3865,
620,
5915,
436,
16904,
282,
769,
402,
7838,
6342,
436,
282,
769,
199,
1618,
625,
10151,
503,
838,
796,
1808,
282,
2013,
1083,
367,
17196,
7838,
6342,
14,
221,
17653,
367,
17196,
199,
10151,
6342,
787,
818,
12,
18284,
12,
17451,
503,
1006,
12,
2382,
314,
11284,
365,
1255,
367,
1924,
1083,
199,
199,
3205,
26,
769,
402,
1373,
503,
1655,
486,
556,
1475,
1584,
199,
199,
2959,
26,
1584,
13584,
367,
1924,
1324,
15,
632,
14665,
26,
199,
1658,
334,
10151,
63,
3852,
395,
577,
334,
5087,
395,
593,
334,
6847,
796,
395,
510,
334,
11132,
19653,
5137,
395,
481,
334,
11132,
4242,
5137,
395,
199,
35,
334,
13724,
3343,
395,
11076,
14,
2902,
2238,
199,
624,
199,
199,
646,
7534,
199,
646,
7392,
199,
199,
646,
32422,
3852,
18,
63,
1974,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1798,
275,
7534,
14,
10730,
342,
272,
1798,
14,
525,
63,
2094,
4517,
1210,
297,
2053,
534,
3711,
297,
1595,
534,
740,
297,
9237,
29,
18,
12,
1720,
628,
3205,
13148,
531,
272,
1798,
14,
525,
63,
2094,
4517,
765,
297,
2053,
534,
765,
297,
849,
534,
632,
297,
1720,
534,
3767,
402,
17196,
1336,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
384,
63,
5590,
297,
2053,
534,
384,
63,
5590,
297,
730,
29,
442,
12,
849,
29,
1400,
12,
1720,
534,
10076,
18932,
687,
282,
4092,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
2110,
63,
5590,
297,
2053,
534,
2110,
63,
5590,
297,
730,
29,
442,
12,
849,
29,
1960,
12,
1720,
534,
10076,
3224,
1745,
402,
282,
4092,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
1393,
890,
297,
2053,
534,
1393,
890,
297,
730,
29,
442,
12,
849,
29,
17,
12,
1720,
534,
6216,
402,
13341,
367,
19695,
436,
818,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
7227,
63,
908,
297,
2053,
534,
7227,
63,
908,
297,
1720,
534,
17931,
474,
370,
2457,
314,
16102,
273,
31537,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
6188,
63,
7227,
297,
2053,
534,
6188,
63,
7227,
297,
730,
29,
1609,
12,
849,
29,
16,
14,
16,
12,
1720,
534,
17931,
474,
370,
2457,
314,
16102,
273,
31537,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
6116,
63,
7227,
297,
2053,
534,
6116,
63,
7227,
297,
730,
29,
1609,
12,
849,
29,
16,
14,
16,
12,
1720,
534,
24677,
574,
370,
2457,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
1199,
63,
1725,
297,
2053,
534,
1199,
63,
1725,
297,
849,
534,
10151,
63,
3852,
297,
1720,
534,
497,
4768,
1072,
4789,
5055,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
13724,
63,
1199,
297,
2053,
534,
13724,
63,
1199,
297,
1720,
534,
20750,
1072,
570,
2659,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
32422,
3852,
18,
63,
1974,
14,
981,
63,
12629,
342,
339,
11076,
275,
942,
272,
340,
1249,
14,
6116,
63,
7227,
690,
378,
26,
267,
8765,
275,
1249,
14,
6116,
63,
7227,
272,
916,
1249,
14,
6188,
63,
7227,
690,
378,
26,
267,
8765,
275,
1249,
14,
6188,
63,
7227,
1182,
2948,
14,
16,
272,
587,
26,
267,
8765,
275,
378,
272,
367,
334,
5214,
63,
515,
12,
27276,
9,
315,
1249,
14,
3711,
26,
267,
5020,
275,
32422,
3852,
18,
63,
1974,
14,
1412,
63,
493,
8,
5214,
63,
515,
12,
5101,
27276,
12,
5101,
1249,
14,
765,
12,
5101,
8765,
12,
5101,
1249,
14,
384,
63,
5590,
12,
5101,
1249,
14,
2110,
63,
5590,
12,
5101,
1249,
14,
1393,
890,
12,
5101,
1249,
14,
1199,
63,
1725,
9,
267,
11076,
14,
2880,
8,
3200,
9,
272,
327,
32254,
5434,
11076,
14,
272,
701,
63,
493,
275,
1052,
272,
367,
5020,
315,
11076,
26,
267,
327,
8232,
298,
403,
2,
11076,
687,
3405,
1584,
267,
340,
440,
5020,
26,
288,
1980,
267,
931,
275,
5020,
459,
3200,
63,
515,
418,
267,
340,
931,
440,
315,
701,
63,
493,
26,
288,
701,
63,
493,
59,
515,
61,
275,
942,
267,
701,
63,
493,
59,
515,
1055,
740,
8,
3200,
9,
272,
327,
6990,
5174,
2238,
11076,
570,
14,
272,
2883,
275,
788,
5252,
297,
283,
5094,
63,
632,
297,
283,
7780,
63,
632,
297,
283,
27293,
2720,
297,
283,
29796,
297,
283,
6847,
796,
418,
272,
11076,
63,
548,
275,
7392,
14,
5491,
8,
1490,
8,
589,
14,
13724,
63,
1199,
12,
283,
9115,
659,
11172,
17115,
84,
358,
272,
11076,
63,
548,
14,
22686,
8,
1612,
9,
272,
367,
570,
63,
515,
12,
11076,
315,
701,
63,
493,
14,
1744,
837,
267,
367,
5020,
315,
11076,
26,
288,
11076,
63,
548,
14,
22686,
779,
3200,
59,
498,
61,
367,
790,
315,
2883,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
15346,
3852,
18,
14,
647,
199,
199,
32488,
282,
769,
402,
2797,
31803,
641,
3865,
620,
5915,
436,
16904,
282,
769,
402,
7838,
6342,
436,
282,
769,
199,
1618,
625,
10151,
503,
838,
796,
1808,
282,
2013,
1083,
367,
17196,
7838,
6342,
14,
221,
17653,
367,
17196,
199,
10151,
6342,
787,
818,
12,
18284,
12,
17451,
503,
1006,
12,
2382,
314,
11284,
365,
1255,
367,
1924,
1083,
199,
199,
3205,
26,
769,
402,
1373,
503,
1655,
486,
556,
1475,
1584,
199,
199,
2959,
26,
1584,
13584,
367,
1924,
1324,
15,
632,
14665,
26,
199,
1658,
334,
10151,
63,
3852,
395,
577,
334,
5087,
395,
593,
334,
6847,
796,
395,
510,
334,
11132,
19653,
5137,
395,
481,
334,
11132,
4242,
5137,
395,
199,
35,
334,
13724,
3343,
395,
11076,
14,
2902,
2238,
199,
624,
199,
199,
646,
7534,
199,
646,
7392,
199,
199,
646,
32422,
3852,
18,
63,
1974,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1798,
275,
7534,
14,
10730,
342,
272,
1798,
14,
525,
63,
2094,
4517,
1210,
297,
2053,
534,
3711,
297,
1595,
534,
740,
297,
9237,
29,
18,
12,
1720,
628,
3205,
13148,
531,
272,
1798,
14,
525,
63,
2094,
4517,
765,
297,
2053,
534,
765,
297,
849,
534,
632,
297,
1720,
534,
3767,
402,
17196,
1336,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
384,
63,
5590,
297,
2053,
534,
384,
63,
5590,
297,
730,
29,
442,
12,
849,
29,
1400,
12,
1720,
534,
10076,
18932,
687,
282,
4092,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
2110,
63,
5590,
297,
2053,
534,
2110,
63,
5590,
297,
730,
29,
442,
12,
849,
29,
1960,
12,
1720,
534,
10076,
3224,
1745,
402,
282,
4092,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
1393,
890,
297,
2053,
534,
1393,
890,
297,
730,
29,
442,
12,
849,
29,
17,
12,
1720,
534,
6216,
402,
13341,
367,
19695,
436,
818,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
7227,
63,
908,
297,
2053,
534,
7227,
63,
908,
297,
1720,
534,
17931,
474,
370,
2457,
314,
16102,
273,
31537,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
6188,
63,
7227,
297,
2053,
534,
6188,
63,
7227,
297,
730,
29,
1609,
12,
849,
29,
16,
14,
16,
12,
1720,
534,
17931,
474,
370,
2457,
314,
16102,
273,
31537,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
6116,
63,
7227,
297,
2053,
534,
6116,
63,
7227,
297,
730,
29,
1609,
12,
849,
29,
16,
14,
16,
12,
1720,
534,
24677,
574,
370,
2457,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
1199,
63,
1725,
297,
2053,
534,
1199,
63,
1725,
297,
849,
534,
10151,
63,
3852,
297,
1720,
534,
497,
4768,
1072,
4789,
5055,
2659,
272,
1798,
14,
525,
63,
2094,
4517,
13724,
63,
1199,
297,
2053,
534,
13724,
63,
1199,
297,
1720,
534,
20750,
1072,
570,
2659,
272,
1249,
275,
1798,
14,
1122,
63,
589,
342,
339,
32422,
3852,
18,
63,
1974,
14,
981,
63,
12629,
342,
339,
11076,
275,
942,
272,
340,
1249,
14,
6116,
63,
7227,
690,
378,
26,
267,
8765,
275,
1249,
14,
6116,
63,
7227,
272,
916,
1249,
14,
6188,
63,
7227,
690,
378,
26,
267,
8765,
275,
1249,
14,
6188,
63,
7227,
1182,
2948,
14,
16,
272,
587,
26,
267,
8765,
275,
378,
272,
367,
334,
5214,
63,
515,
12,
27276,
9,
315,
1249,
14,
3711,
26,
267,
5020,
275,
32422,
3852,
18,
63,
1974,
14,
1412,
63,
493,
8,
5214,
63,
515,
12,
5101,
27276,
12,
5101,
1249,
14,
765,
12,
5101,
8765,
12,
5101,
1249,
14,
384,
63,
5590,
12,
5101,
1249,
14,
2110,
63,
5590,
12,
5101,
1249,
14,
1393,
890,
12,
5101,
1249,
14,
1199,
63,
1725,
9,
267,
11076,
14,
2880,
8,
3200,
9,
272,
327,
32254,
5434,
11076,
14,
272,
701,
63,
493,
275,
1052,
272,
367,
5020,
315,
11076,
26,
267,
327,
8232,
298,
403,
2,
11076,
687,
3405,
1584,
267,
340,
440,
5020,
26,
288,
1980,
267,
931,
275,
5020,
459,
3200,
63,
515,
418,
267,
340,
931,
440,
315,
701,
63,
493,
26,
288,
701,
63,
493,
59,
515,
61,
275,
942,
267,
701,
63,
493,
59,
515,
1055,
740,
8,
3200,
9,
272,
327,
6990,
5174,
2238,
11076,
570,
14,
272,
2883,
275,
788,
5252,
297,
283,
5094,
63,
632,
297,
283,
7780,
63,
632,
297,
283,
27293,
2720,
297,
283,
29796,
297,
283,
6847,
796,
418,
272,
11076,
63,
548,
275,
7392,
14,
5491,
8,
1490,
8,
589,
14,
13724,
63,
1199,
12,
283,
9115,
659,
11172,
17115,
84,
358,
272,
11076,
63,
548,
14,
22686,
8,
1612,
9,
272,
367,
570,
63,
515,
12,
11076,
315,
701,
63,
493,
14,
1744,
837,
267,
367,
5020,
315,
11076,
26,
288,
11076,
63,
548,
14,
22686,
779,
3200,
59,
498,
61,
367,
790,
315,
2883,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
CloudWareChile/OpenChile
|
openerp/addons/import_google/__init__.py
|
9
|
1074
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import partner
import wizard
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
5854,
199,
646,
12262,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
5854,
199,
646,
12262,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
percyfal/bokeh
|
bokeh/util/datatypes.py
|
13
|
1831
|
'''
'''
class MultiValuedDict(object):
''' Store a mapping from keys to multiple values with minimal overhead.
Avoids storing empty collecctions.
'''
def __init__(self):
'''
'''
self._dict = dict()
def add_value(self, key, value):
'''
'''
if key is None:
raise ValueError("Key is None")
if value is None:
raise ValueError("Can't put None in this dict")
if isinstance(value, set):
raise ValueError("Can't put sets in this dict")
existing = self._dict.get(key)
if existing is None:
self._dict[key] = value
elif isinstance(existing, set):
existing.add(value)
else:
self._dict[key] = set([existing, value])
def get_all(self, k):
'''
'''
existing = self._dict.get(k)
if existing is None:
return []
elif isinstance(existing, set):
return list(existing)
else:
return [existing]
def get_one(self, k, duplicate_error):
'''
'''
existing = self._dict.get(k)
if isinstance(existing, set):
if len(existing) == 1:
return next(iter(existing))
else:
raise ValueError(duplicate_error + (": %r" % (existing)))
else:
return existing
def remove_value(self, key, value):
'''
'''
if key is None:
raise ValueError("Key is None")
existing = self._dict.get(key)
if isinstance(existing, set):
existing.discard(value)
if len(existing) == 0:
del self._dict[key]
elif existing == value:
del self._dict[key]
else:
pass
|
bsd-3-clause
|
[
2344,
199,
199,
2344,
199,
199,
533,
6879,
1110,
68,
2141,
8,
785,
304,
272,
1449,
13874,
282,
4412,
687,
2883,
370,
3663,
1338,
543,
13460,
24075,
14,
339,
19503,
83,
16915,
2701,
1048,
10251,
2452,
14,
339,
1449,
339,
347,
636,
826,
721,
277,
304,
267,
1449,
398,
1449,
267,
291,
423,
807,
275,
1211,
342,
339,
347,
1050,
63,
585,
8,
277,
12,
790,
12,
574,
304,
267,
1449,
398,
1449,
267,
340,
790,
365,
488,
26,
288,
746,
1722,
480,
1197,
365,
488,
531,
398,
340,
574,
365,
488,
26,
288,
746,
1722,
480,
6049,
1133,
5324,
488,
315,
642,
1211,
531,
398,
340,
1228,
8,
585,
12,
663,
304,
288,
746,
1722,
480,
6049,
1133,
5324,
5951,
315,
642,
1211,
531,
398,
3411,
275,
291,
423,
807,
14,
362,
8,
498,
9,
267,
340,
3411,
365,
488,
26,
288,
291,
423,
807,
59,
498,
61,
275,
574,
267,
916,
1228,
8,
5952,
12,
663,
304,
288,
3411,
14,
525,
8,
585,
9,
267,
587,
26,
288,
291,
423,
807,
59,
498,
61,
275,
663,
779,
5952,
12,
574,
566,
339,
347,
664,
63,
452,
8,
277,
12,
1022,
304,
267,
1449,
398,
1449,
267,
3411,
275,
291,
423,
807,
14,
362,
8,
75,
9,
267,
340,
3411,
365,
488,
26,
288,
372,
942,
267,
916,
1228,
8,
5952,
12,
663,
304,
288,
372,
769,
8,
5952,
9,
267,
587,
26,
288,
372,
359,
5952,
61,
339,
347,
664,
63,
368,
8,
277,
12,
1022,
12,
9250,
63,
705,
304,
267,
1449,
398,
1449,
267,
3411,
275,
291,
423,
807,
14,
362,
8,
75,
9,
267,
340,
1228,
8,
5952,
12,
663,
304,
288,
340,
822,
8,
5952,
9,
508,
413,
26,
355,
372,
2163,
8,
1661,
8,
5952,
430,
288,
587,
26,
355,
746,
1722,
8,
11081,
63,
705,
435,
334,
582,
450,
82,
2,
450,
334,
5952,
1724,
267,
587,
26,
288,
372,
3411,
339,
347,
2813,
63,
585,
8,
277,
12,
790,
12,
574,
304,
267,
1449,
398,
1449,
267,
340,
790,
365,
488,
26,
288,
746,
1722,
480,
1197,
365,
488,
531,
398,
3411,
275,
291,
423,
807,
14,
362,
8,
498,
9,
267,
340,
1228,
8,
5952,
12,
663,
304,
288,
3411,
14,
14394,
8,
585,
9,
288,
340,
822,
8,
5952,
9,
508,
378,
26,
355,
2150,
291,
423,
807,
59,
498,
61,
267,
916,
3411,
508,
574,
26,
288,
2150,
291,
423,
807,
59,
498,
61,
267,
587,
26,
288,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
199,
2344,
199,
199,
533,
6879,
1110,
68,
2141,
8,
785,
304,
272,
1449,
13874,
282,
4412,
687,
2883,
370,
3663,
1338,
543,
13460,
24075,
14,
339,
19503,
83,
16915,
2701,
1048,
10251,
2452,
14,
339,
1449,
339,
347,
636,
826,
721,
277,
304,
267,
1449,
398,
1449,
267,
291,
423,
807,
275,
1211,
342,
339,
347,
1050,
63,
585,
8,
277,
12,
790,
12,
574,
304,
267,
1449,
398,
1449,
267,
340,
790,
365,
488,
26,
288,
746,
1722,
480,
1197,
365,
488,
531,
398,
340,
574,
365,
488,
26,
288,
746,
1722,
480,
6049,
1133,
5324,
488,
315,
642,
1211,
531,
398,
340,
1228,
8,
585,
12,
663,
304,
288,
746,
1722,
480,
6049,
1133,
5324,
5951,
315,
642,
1211,
531,
398,
3411,
275,
291,
423,
807,
14,
362,
8,
498,
9,
267,
340,
3411,
365,
488,
26,
288,
291,
423,
807,
59,
498,
61,
275,
574,
267,
916,
1228,
8,
5952,
12,
663,
304,
288,
3411,
14,
525,
8,
585,
9,
267,
587,
26,
288,
291,
423,
807,
59,
498,
61,
275,
663,
779,
5952,
12,
574,
566,
339,
347,
664,
63,
452,
8,
277,
12,
1022,
304,
267,
1449,
398,
1449,
267,
3411,
275,
291,
423,
807,
14,
362,
8,
75,
9,
267,
340,
3411,
365,
488,
26,
288,
372,
942,
267,
916,
1228,
8,
5952,
12,
663,
304,
288,
372,
769,
8,
5952,
9,
267,
587,
26,
288,
372,
359,
5952,
61,
339,
347,
664,
63,
368,
8,
277,
12,
1022,
12,
9250,
63,
705,
304,
267,
1449,
398,
1449,
267,
3411,
275,
291,
423,
807,
14,
362,
8,
75,
9,
267,
340,
1228,
8,
5952,
12,
663,
304,
288,
340,
822,
8,
5952,
9,
508,
413,
26,
355,
372,
2163,
8,
1661,
8,
5952,
430,
288,
587,
26,
355,
746,
1722,
8,
11081,
63,
705,
435,
334,
582,
450,
82,
2,
450,
334,
5952,
1724,
267,
587,
26,
288,
372,
3411,
339,
347,
2813,
63,
585,
8,
277,
12,
790,
12,
574,
304,
267,
1449,
398,
1449,
267,
340,
790,
365,
488,
26,
288,
746,
1722,
480,
1197,
365,
488,
531,
398,
3411,
275,
291,
423,
807,
14,
362,
8,
498,
9,
267,
340,
1228,
8,
5952,
12,
663,
304,
288,
3411,
14,
14394,
8,
585,
9,
288,
340,
822,
8,
5952,
9,
508,
378,
26,
355,
2150,
291,
423,
807,
59,
498,
61,
267,
916,
3411,
508,
574,
26,
288,
2150,
291,
423,
807,
59,
498,
61,
267,
587,
26,
288,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
demon-ru/iml-crm
|
addons/auth_openid/res_users.py
|
163
|
3778
|
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-2012 OpenERP s.a. (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.modules.registry import RegistryManager
from openerp.osv import osv, fields
import openerp.exceptions
from openerp import tools
import utils
class res_users(osv.osv):
_inherit = 'res.users'
# TODO create helper fields for autofill openid_url and openid_email -> http://pad.openerp.com/web-openid
_columns = {
'openid_url': fields.char('OpenID URL', size=1024, copy=False),
'openid_email': fields.char('OpenID Email', size=256, copy=False,
help="Used for disambiguation in case of a shared OpenID URL"),
'openid_key': fields.char('OpenID Key', size=utils.KEY_LENGTH,
readonly=True, copy=False),
}
def _check_openid_url_email(self, cr, uid, ids, context=None):
return all(self.search_count(cr, uid, [('active', '=', True), ('openid_url', '=', u.openid_url), ('openid_email', '=', u.openid_email)]) == 1 \
for u in self.browse(cr, uid, ids, context) if u.active and u.openid_url)
def _check_openid_url_email_msg(self, cr, uid, ids, context):
return "There is already an active user with this OpenID Email for this OpenID URL"
_constraints = [
(_check_openid_url_email, lambda self, *a, **kw: self._check_openid_url_email_msg(*a, **kw), ['active', 'openid_url', 'openid_email']),
]
def _login(self, db, login, password):
result = super(res_users, self)._login(db, login, password)
if result:
return result
else:
with RegistryManager.get(db).cursor() as cr:
cr.execute("""UPDATE res_users
SET login_date=now() AT TIME ZONE 'UTC'
WHERE login=%s AND openid_key=%s AND active=%s RETURNING id""",
(tools.ustr(login), tools.ustr(password), True))
# beware: record cache may be invalid
res = cr.fetchone()
cr.commit()
return res[0] if res else False
def check(self, db, uid, passwd):
try:
return super(res_users, self).check(db, uid, passwd)
except openerp.exceptions.AccessDenied:
if not passwd:
raise
with RegistryManager.get(db).cursor() as cr:
cr.execute('''SELECT COUNT(1)
FROM res_users
WHERE id=%s
AND openid_key=%s
AND active=%s''',
(int(uid), passwd, True))
if not cr.fetchone()[0]:
raise
self._uid_cache.setdefault(db, {})[uid] = passwd
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7129,
13,
7409,
7653,
308,
14,
65,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
504,
5166,
14,
3112,
14,
5189,
492,
20738,
2988,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
646,
5166,
14,
3924,
199,
504,
5166,
492,
7249,
199,
199,
646,
3778,
199,
199,
533,
522,
63,
3707,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
470,
14,
3707,
7,
339,
327,
3254,
1218,
5922,
1504,
367,
2599,
4498,
24494,
63,
633,
436,
24494,
63,
2123,
1035,
1455,
921,
6226,
14,
11267,
14,
957,
15,
2520,
13,
15403,
339,
485,
3406,
275,
469,
267,
283,
15403,
63,
633,
356,
1504,
14,
1560,
360,
30244,
2851,
297,
1568,
29,
7727,
12,
1331,
29,
797,
395,
267,
283,
15403,
63,
2123,
356,
1504,
14,
1560,
360,
30244,
11426,
297,
1568,
29,
3912,
12,
1331,
29,
797,
12,
2511,
1720,
628,
9167,
367,
2153,
16902,
4086,
315,
1930,
402,
282,
5709,
25463,
2851,
1288,
267,
283,
15403,
63,
498,
356,
1504,
14,
1560,
360,
30244,
2606,
297,
1568,
29,
1208,
14,
3078,
63,
9127,
12,
3303,
6863,
29,
549,
12,
1331,
29,
797,
395,
272,
789,
339,
347,
485,
1074,
63,
15403,
63,
633,
63,
2123,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
1006,
8,
277,
14,
1733,
63,
835,
8,
1556,
12,
1747,
12,
4274,
2682,
297,
6291,
715,
395,
661,
15403,
63,
633,
297,
6291,
399,
14,
15403,
63,
633,
395,
661,
15403,
63,
2123,
297,
6291,
399,
14,
15403,
63,
2123,
3948,
508,
413,
971,
673,
367,
399,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
9,
340,
399,
14,
2682,
436,
399,
14,
15403,
63,
633,
9,
339,
347,
485,
1074,
63,
15403,
63,
633,
63,
2123,
63,
1328,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
304,
267,
372,
298,
10924,
365,
2575,
376,
4702,
922,
543,
642,
25463,
11426,
367,
642,
25463,
2851,
2,
339,
485,
9882,
275,
359,
267,
6110,
1074,
63,
15403,
63,
633,
63,
2123,
12,
2400,
291,
12,
627,
65,
12,
1011,
829,
26,
291,
423,
1074,
63,
15403,
63,
633,
63,
2123,
63,
1328,
2031,
65,
12,
1011,
829,
395,
788,
2682,
297,
283,
15403,
63,
633,
297,
283,
15403,
63,
2123,
3815,
272,
1622,
339,
347,
485,
2886,
8,
277,
12,
1592,
12,
4676,
12,
2505,
304,
267,
754,
275,
1613,
8,
470,
63,
3707,
12,
291,
10445,
2886,
8,
697,
12,
4676,
12,
2505,
9,
267,
340,
754,
26,
288,
372,
754,
267,
587,
26,
288,
543,
20738,
2988,
14,
362,
8,
697,
680,
3937,
342,
465,
2467,
26,
355,
2467,
14,
2526,
4852,
10383,
522,
63,
3707,
1816,
11543,
4676,
63,
602,
29,
2131,
342,
15059,
17032,
3107,
4817,
283,
11288,
7,
1816,
6038,
4676,
2458,
83,
2401,
24494,
63,
498,
2458,
83,
2401,
4702,
2458,
83,
17409,
1230,
6024,
1305,
7208,
2574,
334,
2537,
14,
11409,
8,
2886,
395,
7249,
14,
11409,
8,
2060,
395,
715,
430,
355,
327,
506,
1068,
26,
2777,
2581,
1443,
506,
3866,
355,
522,
275,
2467,
14,
11591,
342,
355,
2467,
14,
3543,
342,
355,
372,
522,
59,
16,
61,
340,
522,
587,
756,
339,
347,
1104,
8,
277,
12,
1592,
12,
1747,
12,
15081,
304,
267,
862,
26,
288,
372,
1613,
8,
470,
63,
3707,
12,
291,
680,
1074,
8,
697,
12,
1747,
12,
15081,
9,
267,
871,
5166,
14,
3924,
14,
3946,
15729,
26,
288,
340,
440,
15081,
26,
355,
746,
288,
543,
20738,
2988,
14,
362,
8,
697,
680,
3937,
342,
465,
2467,
26,
355,
2467,
14,
2526,
10505,
4859,
24903,
8,
17,
9,
1816,
4442,
522,
63,
3707,
3044,
6038,
1305,
2458,
83,
639,
2401,
24494,
63,
498,
2458,
83,
639,
2401,
4702,
2458,
83,
18108,
1169,
334,
442,
8,
1535,
395,
15081,
12,
715,
430,
355,
340,
440,
2467,
14,
11591,
3430,
16,
2189,
490,
746,
355,
291,
423,
1535,
63,
1637,
14,
5486,
8,
697,
12,
1052,
2788,
1535,
61,
275,
15081,
6905,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
7129,
13,
7409,
7653,
308,
14,
65,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
504,
5166,
14,
3112,
14,
5189,
492,
20738,
2988,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
646,
5166,
14,
3924,
199,
504,
5166,
492,
7249,
199,
199,
646,
3778,
199,
199,
533,
522,
63,
3707,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
470,
14,
3707,
7,
339,
327,
3254,
1218,
5922,
1504,
367,
2599,
4498,
24494,
63,
633,
436,
24494,
63,
2123,
1035,
1455,
921,
6226,
14,
11267,
14,
957,
15,
2520,
13,
15403,
339,
485,
3406,
275,
469,
267,
283,
15403,
63,
633,
356,
1504,
14,
1560,
360,
30244,
2851,
297,
1568,
29,
7727,
12,
1331,
29,
797,
395,
267,
283,
15403,
63,
2123,
356,
1504,
14,
1560,
360,
30244,
11426,
297,
1568,
29,
3912,
12,
1331,
29,
797,
12,
2511,
1720,
628,
9167,
367,
2153,
16902,
4086,
315,
1930,
402,
282,
5709,
25463,
2851,
1288,
267,
283,
15403,
63,
498,
356,
1504,
14,
1560,
360,
30244,
2606,
297,
1568,
29,
1208,
14,
3078,
63,
9127,
12,
3303,
6863,
29,
549,
12,
1331,
29,
797,
395,
272,
789,
339,
347,
485,
1074,
63,
15403,
63,
633,
63,
2123,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
372,
1006,
8,
277,
14,
1733,
63,
835,
8,
1556,
12,
1747,
12,
4274,
2682,
297,
6291,
715,
395,
661,
15403,
63,
633,
297,
6291,
399,
14,
15403,
63,
633,
395,
661,
15403,
63,
2123,
297,
6291,
399,
14,
15403,
63,
2123,
3948,
508,
413,
971,
673,
367,
399,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
9,
340,
399,
14,
2682,
436,
399,
14,
15403,
63,
633,
9,
339,
347,
485,
1074,
63,
15403,
63,
633,
63,
2123,
63,
1328,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
304,
267,
372,
298,
10924,
365,
2575,
376,
4702,
922,
543,
642,
25463,
11426,
367,
642,
25463,
2851,
2,
339,
485,
9882,
275,
359,
267,
6110,
1074,
63,
15403,
63,
633,
63,
2123,
12,
2400,
291,
12,
627,
65,
12,
1011,
829,
26,
291,
423,
1074,
63,
15403,
63,
633,
63,
2123,
63,
1328,
2031,
65,
12,
1011,
829,
395,
788,
2682,
297,
283,
15403,
63,
633,
297,
283,
15403,
63,
2123,
3815,
272,
1622,
339,
347,
485,
2886,
8,
277,
12,
1592,
12,
4676,
12,
2505,
304,
267,
754,
275,
1613,
8,
470,
63,
3707,
12,
291,
10445,
2886,
8,
697,
12,
4676,
12,
2505,
9,
267,
340,
754,
26,
288,
372,
754,
267,
587,
26,
288,
543,
20738,
2988,
14,
362,
8,
697,
680,
3937,
342,
465,
2467,
26,
355,
2467,
14,
2526,
4852,
10383,
522,
63,
3707,
1816,
11543,
4676,
63,
602,
29,
2131,
342,
15059,
17032,
3107,
4817,
283,
11288,
7,
1816,
6038,
4676,
2458,
83,
2401,
24494,
63,
498,
2458,
83,
2401,
4702,
2458,
83,
17409,
1230,
6024,
1305,
7208,
2574,
334,
2537,
14,
11409,
8,
2886,
395,
7249,
14,
11409,
8,
2060,
395,
715,
430,
355,
327,
506,
1068,
26,
2777,
2581,
1443,
506,
3866,
355,
522,
275,
2467,
14,
11591,
342,
355,
2467,
14,
3543,
342,
355,
372,
522,
59,
16,
61,
340,
522,
587,
756,
339,
347,
1104,
8,
277,
12,
1592,
12,
1747,
12,
15081,
304,
267,
862,
26,
288,
372,
1613,
8,
470,
63,
3707,
12,
291,
680,
1074,
8,
697,
12,
1747,
12,
15081,
9,
267,
871,
5166,
14,
3924,
14,
3946,
15729,
26,
288,
340,
440,
15081,
26,
355,
746,
288,
543,
20738,
2988,
14,
362,
8,
697,
680,
3937,
342,
465,
2467,
26,
355,
2467,
14,
2526,
10505,
4859,
24903,
8,
17,
9,
1816,
4442,
522,
63,
3707,
3044,
6038,
1305,
2458,
83,
639,
2401,
24494,
63,
498,
2458,
83,
639,
2401,
4702,
2458,
83,
18108,
1169,
334,
442,
8,
1535,
395,
15081,
12,
715,
430,
355,
340,
440,
2467,
14,
11591,
3430,
16,
2189,
490,
746,
355,
291,
423,
1535,
63,
1637,
14,
5486,
8,
697,
12,
1052,
2788,
1535,
61,
275,
15081,
6905,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
borovsky/libqmi
|
utils/qmidb/qmidb.py
|
6
|
1448
|
#!/usr/bin/env python
# -*- Mode: python; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
#
# 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, version 2.
#
# 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.
#
# Copyright (C) 2011 - 2012 Red Hat, Inc.
#
import sys
import Entities
import Enums
import Fields
import Structs
if len(sys.argv) > 2:
print "Usage: qmidb.py <path to Entity.txt>"
sys.exit(1)
path = ""
if len(sys.argv) == 2:
path = sys.argv[1] + "/"
enums = Enums.Enums(path)
entities = Entities.Entities(path)
fields = Fields.Fields(path)
structs = Structs.Structs(path)
structs.validate(fields)
entities.validate(structs)
print '/* GENERATED CODE. DO NOT EDIT. */'
print '\ntypedef uint8 bool;\n'
enums.emit()
print '\n\n'
structs_used = entities.emit(fields, structs, enums)
# emit structs that weren't associated with an entity
structs.emit_unused(structs_used, fields, enums)
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
4900,
26,
2366,
27,
5174,
13,
2063,
26,
841,
27,
4363,
13,
8741,
13,
632,
26,
32644,
27,
286,
13,
4316,
13,
2743,
26,
841,
1882,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
12,
1015,
499,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
199,
3,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
446,
6029,
9572,
13002,
12,
3277,
14,
199,
3,
199,
199,
646,
984,
199,
646,
3447,
5080,
199,
646,
11305,
83,
199,
646,
16424,
199,
646,
13039,
83,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
272,
870,
298,
7692,
26,
1894,
8523,
66,
14,
647,
665,
515,
370,
17680,
14,
2424,
4335,
272,
984,
14,
2224,
8,
17,
9,
199,
515,
275,
3087,
199,
692,
822,
8,
1274,
14,
3020,
9,
508,
499,
26,
272,
931,
275,
984,
14,
3020,
59,
17,
61,
435,
10609,
199,
199,
19921,
275,
11305,
83,
14,
5081,
83,
8,
515,
9,
199,
8327,
275,
3447,
5080,
14,
24672,
8,
515,
9,
199,
955,
275,
16424,
14,
7304,
8,
515,
9,
199,
23253,
275,
13039,
83,
14,
4836,
83,
8,
515,
9,
199,
199,
23253,
14,
3502,
8,
955,
9,
199,
8327,
14,
3502,
8,
23253,
9,
199,
199,
1361,
1994,
10,
29087,
6989,
22547,
14,
3506,
2845,
24981,
14,
627,
4805,
199,
1361,
1557,
25116,
318,
3152,
24,
2155,
3779,
78,
7,
199,
19921,
14,
8159,
342,
199,
199,
1361,
1557,
78,
60,
78,
7,
199,
199,
23253,
63,
2972,
275,
9045,
14,
8159,
8,
955,
12,
2702,
83,
12,
28441,
9,
199,
199,
3,
8689,
2702,
83,
626,
781,
828,
1133,
4568,
543,
376,
4642,
199,
23253,
14,
8159,
63,
8618,
8,
23253,
63,
2972,
12,
1504,
12,
28441,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
4900,
26,
2366,
27,
5174,
13,
2063,
26,
841,
27,
4363,
13,
8741,
13,
632,
26,
32644,
27,
286,
13,
4316,
13,
2743,
26,
841,
1882,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
199,
3,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
314,
2868,
2290,
199,
3,
2752,
12,
1015,
499,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
199,
3,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
7760,
446,
6029,
9572,
13002,
12,
3277,
14,
199,
3,
199,
199,
646,
984,
199,
646,
3447,
5080,
199,
646,
11305,
83,
199,
646,
16424,
199,
646,
13039,
83,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
272,
870,
298,
7692,
26,
1894,
8523,
66,
14,
647,
665,
515,
370,
17680,
14,
2424,
4335,
272,
984,
14,
2224,
8,
17,
9,
199,
515,
275,
3087,
199,
692,
822,
8,
1274,
14,
3020,
9,
508,
499,
26,
272,
931,
275,
984,
14,
3020,
59,
17,
61,
435,
10609,
199,
199,
19921,
275,
11305,
83,
14,
5081,
83,
8,
515,
9,
199,
8327,
275,
3447,
5080,
14,
24672,
8,
515,
9,
199,
955,
275,
16424,
14,
7304,
8,
515,
9,
199,
23253,
275,
13039,
83,
14,
4836,
83,
8,
515,
9,
199,
199,
23253,
14,
3502,
8,
955,
9,
199,
8327,
14,
3502,
8,
23253,
9,
199,
199,
1361,
1994,
10,
29087,
6989,
22547,
14,
3506,
2845,
24981,
14,
627,
4805,
199,
1361,
1557,
25116,
318,
3152,
24,
2155,
3779,
78,
7,
199,
19921,
14,
8159,
342,
199,
199,
1361,
1557,
78,
60,
78,
7,
199,
199,
23253,
63,
2972,
275,
9045,
14,
8159,
8,
955,
12,
2702,
83,
12,
28441,
9,
199,
199,
3,
8689,
2702,
83,
626,
781,
828,
1133,
4568,
543,
376,
4642,
199,
23253,
14,
8159,
63,
8618,
8,
23253,
63,
2972,
12,
1504,
12,
28441,
9,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
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|
AkademieOlympia/sympy
|
sympy/strategies/tools.py
|
95
|
1313
|
from __future__ import print_function, division
from . import rl
from .core import do_one, exhaust, switch
from .traverse import top_down
def subs(d, **kwargs):
""" Full simultaneous exact substitution
Examples
========
>>> from sympy.strategies.tools import subs
>>> from sympy import Basic
>>> mapping = {1: 4, 4: 1, Basic(5): Basic(6, 7)}
>>> expr = Basic(1, Basic(2, 3), Basic(4, Basic(5)))
>>> subs(mapping)(expr)
Basic(4, Basic(2, 3), Basic(1, Basic(6, 7)))
"""
if d:
return top_down(do_one(*map(rl.subs, *zip(*d.items()))), **kwargs)
else:
return lambda x: x
def canon(*rules, **kwargs):
""" Strategy for canonicalization
Apply each rule in a bottom_up fashion through the tree.
Do each one in turn.
Keep doing this until there is no change.
"""
return exhaust(top_down(exhaust(do_one(*rules)), **kwargs))
def typed(ruletypes):
""" Apply rules based on the expression type
inputs:
ruletypes -- a dict mapping {Type: rule}
>>> from sympy.strategies import rm_id, typed
>>> from sympy import Add, Mul
>>> rm_zeros = rm_id(lambda x: x==0)
>>> rm_ones = rm_id(lambda x: x==1)
>>> remove_idents = typed({Add: rm_zeros, Mul: rm_ones})
"""
return switch(type, ruletypes)
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
199,
199,
504,
1275,
492,
25717,
199,
504,
1275,
1018,
492,
886,
63,
368,
12,
21354,
833,
12,
6258,
199,
504,
1275,
23650,
492,
2746,
63,
2110,
199,
199,
318,
13868,
8,
68,
12,
1011,
958,
304,
272,
408,
16579,
27008,
5835,
20584,
339,
6058,
272,
12655,
339,
1306,
687,
5840,
14,
20694,
1500,
14,
2537,
492,
13868,
272,
1306,
687,
5840,
492,
10082,
272,
1306,
4412,
275,
469,
17,
26,
841,
12,
841,
26,
413,
12,
10082,
8,
21,
304,
10082,
8,
22,
12,
1520,
6769,
272,
1306,
5348,
275,
10082,
8,
17,
12,
10082,
8,
18,
12,
650,
395,
10082,
8,
20,
12,
10082,
8,
21,
1724,
272,
1306,
13868,
8,
4745,
5130,
3684,
9,
272,
10082,
8,
20,
12,
10082,
8,
18,
12,
650,
395,
10082,
8,
17,
12,
10082,
8,
22,
12,
1520,
1724,
272,
408,
272,
340,
366,
26,
267,
372,
2746,
63,
2110,
8,
1117,
63,
368,
2031,
1130,
8,
4308,
14,
9841,
12,
627,
3065,
2031,
68,
14,
1744,
4059,
395,
1011,
958,
9,
272,
587,
26,
267,
372,
2400,
671,
26,
671,
199,
199,
318,
883,
265,
2031,
4423,
12,
1011,
958,
304,
272,
408,
8303,
5374,
367,
11358,
2072,
339,
14618,
1924,
2332,
315,
282,
9048,
63,
384,
32285,
4012,
314,
3123,
14,
272,
4226,
1924,
1373,
315,
7485,
14,
272,
14797,
9689,
642,
5133,
2337,
365,
949,
1570,
14,
272,
408,
272,
372,
21354,
833,
8,
2119,
63,
2110,
8,
476,
2411,
833,
8,
1117,
63,
368,
2031,
4423,
1826,
1011,
958,
430,
199,
199,
318,
20041,
8,
2200,
1313,
304,
272,
408,
14618,
4713,
4079,
641,
314,
3965,
730,
339,
4153,
26,
267,
2332,
1313,
1553,
282,
1211,
4412,
469,
804,
26,
2332,
93,
339,
1306,
687,
5840,
14,
20694,
1500,
492,
14267,
63,
344,
12,
20041,
272,
1306,
687,
5840,
492,
2654,
12,
22578,
272,
1306,
14267,
63,
4250,
275,
14267,
63,
344,
8,
2734,
671,
26,
671,
389,
16,
9,
272,
1306,
14267,
63,
4548,
221,
275,
14267,
63,
344,
8,
2734,
671,
26,
671,
389,
17,
9,
272,
1306,
2813,
63,
5425,
83,
275,
20041,
2561,
1123,
26,
14267,
63,
4250,
12,
22578,
26,
14267,
63,
4548,
1552,
272,
408,
272,
372,
6258,
8,
466,
12,
2332,
1313,
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
] |
[
636,
2443,
363,
492,
870,
63,
1593,
12,
4629,
199,
199,
504,
1275,
492,
25717,
199,
504,
1275,
1018,
492,
886,
63,
368,
12,
21354,
833,
12,
6258,
199,
504,
1275,
23650,
492,
2746,
63,
2110,
199,
199,
318,
13868,
8,
68,
12,
1011,
958,
304,
272,
408,
16579,
27008,
5835,
20584,
339,
6058,
272,
12655,
339,
1306,
687,
5840,
14,
20694,
1500,
14,
2537,
492,
13868,
272,
1306,
687,
5840,
492,
10082,
272,
1306,
4412,
275,
469,
17,
26,
841,
12,
841,
26,
413,
12,
10082,
8,
21,
304,
10082,
8,
22,
12,
1520,
6769,
272,
1306,
5348,
275,
10082,
8,
17,
12,
10082,
8,
18,
12,
650,
395,
10082,
8,
20,
12,
10082,
8,
21,
1724,
272,
1306,
13868,
8,
4745,
5130,
3684,
9,
272,
10082,
8,
20,
12,
10082,
8,
18,
12,
650,
395,
10082,
8,
17,
12,
10082,
8,
22,
12,
1520,
1724,
272,
408,
272,
340,
366,
26,
267,
372,
2746,
63,
2110,
8,
1117,
63,
368,
2031,
1130,
8,
4308,
14,
9841,
12,
627,
3065,
2031,
68,
14,
1744,
4059,
395,
1011,
958,
9,
272,
587,
26,
267,
372,
2400,
671,
26,
671,
199,
199,
318,
883,
265,
2031,
4423,
12,
1011,
958,
304,
272,
408,
8303,
5374,
367,
11358,
2072,
339,
14618,
1924,
2332,
315,
282,
9048,
63,
384,
32285,
4012,
314,
3123,
14,
272,
4226,
1924,
1373,
315,
7485,
14,
272,
14797,
9689,
642,
5133,
2337,
365,
949,
1570,
14,
272,
408,
272,
372,
21354,
833,
8,
2119,
63,
2110,
8,
476,
2411,
833,
8,
1117,
63,
368,
2031,
4423,
1826,
1011,
958,
430,
199,
199,
318,
20041,
8,
2200,
1313,
304,
272,
408,
14618,
4713,
4079,
641,
314,
3965,
730,
339,
4153,
26,
267,
2332,
1313,
1553,
282,
1211,
4412,
469,
804,
26,
2332,
93,
339,
1306,
687,
5840,
14,
20694,
1500,
492,
14267,
63,
344,
12,
20041,
272,
1306,
687,
5840,
492,
2654,
12,
22578,
272,
1306,
14267,
63,
4250,
275,
14267,
63,
344,
8,
2734,
671,
26,
671,
389,
16,
9,
272,
1306,
14267,
63,
4548,
221,
275,
14267,
63,
344,
8,
2734,
671,
26,
671,
389,
17,
9,
272,
1306,
2813,
63,
5425,
83,
275,
20041,
2561,
1123,
26,
14267,
63,
4250,
12,
22578,
26,
14267,
63,
4548,
1552,
272,
408,
272,
372,
6258,
8,
466,
12,
2332,
1313,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
SnappleCap/oh-mainline
|
vendor/packages/gdata/tests/gdata_tests/docs/service_test.py
|
39
|
17399
|
#!/usr/bin/python
#
# Copyright 2009 Google 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.
__author__ = ('api.jfisher (Jeff Fisher), '
'api.eric@google.com (Eric Bidelman)')
import getpass
import os
import re
import StringIO
import time
import unittest
import gdata.docs.service
import gdata.spreadsheet.service
username = ''
password = ''
client = gdata.docs.service.DocsService()
editClient = gdata.docs.service.DocsService()
spreadsheets = gdata.spreadsheet.service.SpreadsheetsService()
class DocumentsListServiceTest(unittest.TestCase):
def setUp(self):
self.client = client
self.editClient = editClient
self.editClient.SetClientLoginToken(client.GetClientLoginToken())
self.editClient.additional_headers = {'If-Match': '*'}
self.spreadsheets = spreadsheets
self.DOCUMENT_CATEGORY = client._MakeKindCategory(gdata.docs.service.DOCUMENT_LABEL)
self.SPREADSHEET_CATEGORY = client._MakeKindCategory(gdata.docs.service.SPREADSHEET_LABEL)
self.PRESENTATION_CATEGORY = client._MakeKindCategory(gdata.docs.service.PRESENTATION_LABEL)
class DocumentListQueryTest(DocumentsListServiceTest):
def setUp(self):
DocumentsListServiceTest.setUp(self)
self.feed = self.client.GetDocumentListFeed()
def testGetDocumentsListFeed(self):
self.assert_(isinstance(self.feed, gdata.docs.DocumentListFeed))
uri = 'http://docs.google.com/feeds/documents/private/full/?max-results=1'
# Query using GetDocumentListFeed()
feed = self.client.GetDocumentListFeed(uri)
self.assert_(isinstance(feed, gdata.docs.DocumentListFeed))
self.assertEqual(len(feed.entry), 1)
self.assertEqual(self.feed.entry[0].id.text, feed.entry[0].id.text)
self.assertEqual(self.feed.entry[0].title.text, feed.entry[0].title.text)
# Query using QueryDocumentListFeed()
feed2 = self.client.QueryDocumentListFeed(uri)
self.assertEqual(len(feed2.entry), 1)
self.assertEqual(self.feed.entry[0].id.text, feed2.entry[0].id.text)
self.assertEqual(self.feed.entry[0].title.text, feed2.entry[0].title.text)
def testGetDocumentsListEntry(self):
self_link = self.feed.entry[0].GetSelfLink().href
entry = self.client.GetDocumentListEntry(self_link)
self.assert_(isinstance(entry, gdata.docs.DocumentListEntry))
self.assertEqual(self.feed.entry[0].id.text, entry.id.text)
self.assertEqual(self.feed.entry[0].title.text, entry.title.text)
self.assert_(self.feed.entry[0].resourceId.text is not None)
self.assert_(self.feed.entry[0].lastModifiedBy is not None)
self.assert_(self.feed.entry[0].lastViewed is not None)
def testGetDocumentsListAclFeed(self):
uri = ('http://docs.google.com/feeds/documents/private/full/'
'-/mine?max-results=1')
feed = self.client.GetDocumentListFeed(uri)
feed_link = feed.entry[0].GetAclLink().href
acl_feed = self.client.GetDocumentListAclFeed(feed_link)
self.assert_(isinstance(acl_feed, gdata.docs.DocumentListAclFeed))
self.assert_(isinstance(acl_feed.entry[0], gdata.docs.DocumentListAclEntry))
self.assert_(acl_feed.entry[0].scope is not None)
self.assert_(acl_feed.entry[0].role is not None)
class DocumentListAclTest(DocumentsListServiceTest):
def setUp(self):
DocumentsListServiceTest.setUp(self)
uri = ('http://docs.google.com/feeds/documents/private/full'
'/-/mine?max-results=1')
self.feed = self.client.GetDocumentListFeed(uri)
self.EMAIL = 'x@example.com'
self.SCOPE_TYPE = 'user'
self.ROLE_VALUE = 'reader'
def testCreateAndUpdateAndDeleteAcl(self):
# Add new ACL
scope = gdata.docs.Scope(value=self.EMAIL, type=self.SCOPE_TYPE)
role = gdata.docs.Role(value=self.ROLE_VALUE)
acl_entry = self.client.Post(
gdata.docs.DocumentListAclEntry(scope=scope, role=role),
self.feed.entry[0].GetAclLink().href,
converter=gdata.docs.DocumentListAclEntryFromString)
self.assert_(isinstance(acl_entry, gdata.docs.DocumentListAclEntry))
self.assertEqual(acl_entry.scope.value, self.EMAIL)
self.assertEqual(acl_entry.scope.type, self.SCOPE_TYPE)
self.assertEqual(acl_entry.role.value, self.ROLE_VALUE)
# Update the user's role
ROLE_VALUE = 'writer'
acl_entry.role.value = ROLE_VALUE
updated_acl_entry = self.editClient.Put(
acl_entry, acl_entry.GetEditLink().href,
converter=gdata.docs.DocumentListAclEntryFromString)
self.assertEqual(updated_acl_entry.scope.value, self.EMAIL)
self.assertEqual(updated_acl_entry.scope.type, self.SCOPE_TYPE)
self.assertEqual(updated_acl_entry.role.value, ROLE_VALUE)
# Delete the ACL
self.editClient.Delete(updated_acl_entry.GetEditLink().href)
# Make sure entry was actually deleted
acl_feed = self.client.GetDocumentListAclFeed(
self.feed.entry[0].GetAclLink().href)
for acl_entry in acl_feed.entry:
self.assert_(acl_entry.scope.value != self.EMAIL)
class DocumentListCreateAndDeleteTest(DocumentsListServiceTest):
def setUp(self):
DocumentsListServiceTest.setUp(self)
self.BLANK_TITLE = "blank.txt"
self.TITLE = 'Test title'
self.new_entry = gdata.docs.DocumentListEntry()
self.new_entry.category.append(self.DOCUMENT_CATEGORY)
def testCreateAndDeleteEmptyDocumentSlugHeaderTitle(self):
created_entry = self.client.Post(self.new_entry,
'/feeds/documents/private/full',
extra_headers={'Slug': self.BLANK_TITLE})
self.editClient.Delete(created_entry.GetEditLink().href)
self.assertEqual(created_entry.title.text, self.BLANK_TITLE)
self.assertEqual(created_entry.category[0].label, 'document')
def testCreateAndDeleteEmptyDocumentAtomTitle(self):
self.new_entry.title = gdata.atom.Title(text=self.TITLE)
created_entry = self.client.Post(self.new_entry,
'/feeds/documents/private/full')
self.editClient.Delete(created_entry.GetEditLink().href)
self.assertEqual(created_entry.title.text, self.TITLE)
self.assertEqual(created_entry.category[0].label, 'document')
def testCreateAndDeleteEmptySpreadsheet(self):
self.new_entry.title = gdata.atom.Title(text=self.TITLE)
self.new_entry.category[0] = self.SPREADSHEET_CATEGORY
created_entry = self.client.Post(self.new_entry,
'/feeds/documents/private/full')
self.editClient.Delete(created_entry.GetEditLink().href)
self.assertEqual(created_entry.title.text, self.TITLE)
self.assertEqual(created_entry.category[0].label, 'viewed')
self.assertEqual(created_entry.category[1].label, 'spreadsheet')
def testCreateAndDeleteEmptyPresentation(self):
self.new_entry.title = gdata.atom.Title(text=self.TITLE)
self.new_entry.category[0] = self.PRESENTATION_CATEGORY
created_entry = self.client.Post(self.new_entry,
'/feeds/documents/private/full')
self.editClient.Delete(created_entry.GetEditLink().href)
self.assertEqual(created_entry.title.text, self.TITLE)
self.assertEqual(created_entry.category[0].label, 'viewed')
self.assertEqual(created_entry.category[1].label, 'presentation')
def testCreateAndDeleteFolder(self):
folder_name = 'TestFolder'
folder = self.client.CreateFolder(folder_name)
self.assertEqual(folder.title.text, folder_name)
self.editClient.Delete(folder.GetEditLink().href)
def testCreateAndDeleteFolderInFolder(self):
DEST_FOLDER_NAME = 'TestFolder'
dest_folder = self.client.CreateFolder(DEST_FOLDER_NAME)
CREATED_FOLDER_NAME = 'TestFolder2'
new_folder = self.client.CreateFolder(CREATED_FOLDER_NAME, dest_folder)
for category in new_folder.category:
if category.scheme.startswith(gdata.docs.service.FOLDERS_SCHEME_PREFIX):
self.assertEqual(new_folder.category[0].label, DEST_FOLDER_NAME)
break
# delete the folders we created, this will also delete the child folder
dest_folder = self.client.Get(dest_folder.GetSelfLink().href)
self.editClient.Delete(dest_folder.GetEditLink().href)
class DocumentListMoveInAndOutOfFolderTest(DocumentsListServiceTest):
def setUp(self):
DocumentsListServiceTest.setUp(self)
self.folder_name = 'TestFolder'
self.folder = self.client.CreateFolder(self.folder_name)
self.doc_title = 'TestDoc'
self.ms = gdata.MediaSource(file_path='test.doc',
content_type='application/msword')
def tearDown(self):
folder = self.client.Get(self.folder.GetSelfLink().href)
self.editClient.Delete(folder.GetEditLink().href)
def testUploadDocumentToFolder(self):
created_entry = self.client.Upload(self.ms, self.doc_title,
self.folder)
for category in created_entry.category:
if category.scheme.startswith(gdata.docs.service.FOLDERS_SCHEME_PREFIX):
self.assertEqual(category.label, self.folder_name)
break
# delete the doc we created
created_entry = self.client.Get(created_entry.GetSelfLink().href)
match = re.search('\/(document%3A[^\/]*)\/?.*?\/(.*)$',
created_entry.GetEditLink().href)
edit_uri = 'http://docs.google.com/feeds/documents/private/full/'
edit_uri += '%s/%s' % (match.group(1), match.group(2))
self.editClient.Delete(edit_uri)
def testMoveDocumentInAndOutOfFolder(self):
created_entry = self.client.Upload(self.ms, self.doc_title)
moved_entry = self.client.MoveIntoFolder(created_entry,
self.folder)
for category in moved_entry.category:
if category.scheme.startswith(gdata.docs.service.FOLDERS_SCHEME_PREFIX):
self.assertEqual(category.label, self.folder_name)
break
self.editClient.MoveOutOfFolder(moved_entry)
moved_entry = self.client.Get(moved_entry.GetSelfLink().href)
for category in moved_entry.category:
starts_with_folder__prefix = category.scheme.startswith(
gdata.docs.service.FOLDERS_SCHEME_PREFIX)
self.assert_(not starts_with_folder__prefix)
created_entry = self.client.Get(created_entry.GetSelfLink().href)
self.editClient.Delete(created_entry.GetEditLink().href)
def testMoveFolderIntoFolder(self):
dest_folder_name = 'DestFolderName'
dest_folder = self.client.CreateFolder(dest_folder_name)
self.client.MoveIntoFolder(self.folder, dest_folder)
self.folder = self.client.Get(self.folder.GetSelfLink().href)
folder_was_moved = False
for category in self.folder.category:
if category.term == dest_folder_name:
folder_was_moved = True
break
self.assert_(folder_was_moved)
#cleanup
dest_folder = self.client.Get(dest_folder.GetSelfLink().href)
self.editClient.Delete(dest_folder.GetEditLink().href)
class DocumentListUploadTest(DocumentsListServiceTest):
def testUploadAndDeleteDocument(self):
ms = gdata.MediaSource(file_path='test.doc',
content_type='application/msword')
entry = self.client.Upload(ms, 'test doc')
self.assertEqual(entry.title.text, 'test doc')
self.assertEqual(entry.category[0].label, 'document')
self.assert_(isinstance(entry, gdata.docs.DocumentListEntry))
self.editClient.Delete(entry.GetEditLink().href)
def testUploadAndDeletePresentation(self):
ms = gdata.MediaSource(file_path='test.ppt',
content_type='application/vnd.ms-powerpoint')
entry = self.client.Upload(ms, 'test preso')
self.assertEqual(entry.title.text, 'test preso')
self.assertEqual(entry.category[0].label, 'viewed')
self.assertEqual(entry.category[1].label, 'presentation')
self.assert_(isinstance(entry, gdata.docs.DocumentListEntry))
self.editClient.Delete(entry.GetEditLink().href)
def testUploadAndDeleteSpreadsheet(self):
ms = gdata.MediaSource(file_path='test.csv',
content_type='text/csv')
entry = self.client.Upload(ms, 'test spreadsheet')
self.assert_(entry.title.text == 'test spreadsheet')
self.assertEqual(entry.category[0].label, 'viewed')
self.assertEqual(entry.category[1].label, 'spreadsheet')
self.assert_(isinstance(entry, gdata.docs.DocumentListEntry))
self.editClient.Delete(entry.GetEditLink().href)
class DocumentListUpdateTest(DocumentsListServiceTest):
def setUp(self):
DocumentsListServiceTest.setUp(self)
self.TITLE = 'CreatedTestDoc'
new_entry = gdata.docs.DocumentListEntry()
new_entry.title = gdata.atom.Title(text=self.TITLE)
new_entry.category.append(self.DOCUMENT_CATEGORY)
self.created_entry = self.client.Post(new_entry,
'/feeds/documents/private/full')
def tearDown(self):
# Delete the test doc we created
self_link = self.created_entry.GetSelfLink().href
entry = self.client.GetDocumentListEntry(self_link)
self.editClient.Delete(entry.GetEditLink().href)
def testUpdateDocumentMetadataAndContent(self):
title = 'UpdatedTestDoc'
# Update metadata
self.created_entry.title.text = title
updated_entry = self.editClient.Put(self.created_entry,
self.created_entry.GetEditLink().href)
self.assertEqual(updated_entry.title.text, title)
# Update document's content
ms = gdata.MediaSource(file_path='test.doc',
content_type='application/msword')
uri = updated_entry.GetEditMediaLink().href
updated_entry = self.editClient.Put(ms, uri)
self.assertEqual(updated_entry.title.text, title)
# Append content to document
data = 'data to append'
ms = gdata.MediaSource(file_handle=StringIO.StringIO(data),
content_type='text/plain',
content_length=len(data))
uri = updated_entry.GetEditMediaLink().href + '?append=true'
updated_entry = self.editClient.Put(ms, uri)
class DocumentListExportTest(DocumentsListServiceTest):
def testExportDocument(self):
query = ('https://docs.google.com/feeds/documents/private/full'
'/-/document?max-results=1')
feed = self.client.QueryDocumentListFeed(query)
file_paths = ['./downloadedTest.doc', './downloadedTest.html',
'./downloadedTest.odt', './downloadedTest.pdf',
'./downloadedTest.png', './downloadedTest.rtf',
'./downloadedTest.txt', './downloadedTest.zip']
for path in file_paths:
self.client.Export(feed.entry[0], path)
self.assert_(os.path.exists(path))
self.assert_(os.path.getsize(path))
os.remove(path)
def testExportPresentation(self):
query = ('https://docs.google.com/feeds/documents/private/full'
'/-/presentation?max-results=1')
feed = self.client.QueryDocumentListFeed(query)
file_paths = ['./downloadedTest.pdf', './downloadedTest.ppt',
'./downloadedTest.swf', './downloadedTest.txt']
for path in file_paths:
self.client.Export(feed.entry[0].resourceId.text, path)
self.assert_(os.path.exists(path))
self.assert_(os.path.getsize(path))
os.remove(path)
def testExportSpreadsheet(self):
query = ('https://docs.google.com/feeds/documents/private/full'
'/-/spreadsheet?max-results=1')
feed = self.client.QueryDocumentListFeed(query)
file_paths = ['./downloadedTest.xls', './downloadedTest.csv',
'./downloadedTest.pdf', './downloadedTest.ods',
'./downloadedTest.tsv', './downloadedTest.html']
docs_token = self.client.GetClientLoginToken()
self.client.SetClientLoginToken(self.spreadsheets.GetClientLoginToken())
for path in file_paths:
self.client.Export(feed.entry[0], path)
self.assert_(os.path.exists(path))
self.assert_(os.path.getsize(path) > 0)
os.remove(path)
self.client.SetClientLoginToken(docs_token)
def testExportNonExistentDocument(self):
path = './ned.txt'
exception_raised = False
try:
self.client.Export('non_existent_doc', path)
except Exception, e: # expected
exception_raised = True
self.assert_(exception_raised)
self.assert_(not os.path.exists(path))
if __name__ == '__main__':
print ('DocList API Tests\nNOTE: Please run these tests only with a test '
'account. The tests may delete or update your data.')
username = raw_input('Please enter your username: ')
password = getpass.getpass()
if client.GetClientLoginToken() is None:
client.ClientLogin(username, password,
source='Document List Client Unit Tests')
if spreadsheets.GetClientLoginToken() is None:
spreadsheets.ClientLogin(username, password,
source='Document List Client Unit Tests')
unittest.main()
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
8937,
4475,
3277,
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,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
363,
2502,
363,
275,
661,
1246,
14,
74,
16056,
281,
334,
42,
3609,
481,
2453,
281,
395,
283,
1598,
283,
1246,
14,
281,
530,
32,
3098,
14,
957,
334,
37,
1567,
31012,
2264,
1237,
5942,
199,
199,
646,
18354,
199,
646,
747,
199,
646,
295,
199,
646,
5228,
199,
646,
900,
199,
646,
2882,
199,
199,
646,
11006,
14,
4757,
14,
1364,
199,
646,
11006,
14,
19930,
14,
1364,
421,
199,
2473,
275,
2125,
199,
2060,
275,
2125,
199,
199,
1258,
275,
11006,
14,
4757,
14,
1364,
14,
27858,
3167,
342,
199,
3773,
3041,
275,
11006,
14,
4757,
14,
1364,
14,
27858,
3167,
342,
199,
19930,
83,
275,
11006,
14,
19930,
14,
1364,
14,
30693,
83,
3167,
342,
421,
199,
533,
21361,
1296,
3167,
774,
8,
2796,
14,
1746,
304,
523,
347,
3613,
8,
277,
304,
272,
291,
14,
1258,
275,
1890,
272,
291,
14,
3773,
3041,
275,
5283,
3041,
272,
291,
14,
3773,
3041,
14,
1084,
3041,
8880,
3264,
8,
1258,
14,
1002,
3041,
8880,
3264,
1012,
272,
291,
14,
3773,
3041,
14,
8460,
63,
2139,
275,
791,
3917,
13,
4486,
356,
6438,
936,
272,
291,
14,
19930,
83,
275,
27076,
83,
272,
291,
14,
7884,
63,
22690,
275,
1890,
423,
5483,
13028,
7841,
8,
15275,
14,
4757,
14,
1364,
14,
7884,
63,
13837,
9,
272,
291,
14,
51,
4225,
1554,
20255,
775,
63,
22690,
275,
1890,
423,
5483,
13028,
7841,
8,
15275,
14,
4757,
14,
1364,
14,
51,
4225,
1554,
20255,
775,
63,
13837,
9,
272,
291,
14,
27160,
63,
22690,
275,
1890,
423,
5483,
13028,
7841,
8,
15275,
14,
4757,
14,
1364,
14,
27160,
63,
13837,
9,
421,
199,
533,
7543,
1296,
3227,
774,
8,
26872,
1296,
3167,
774,
304,
819,
347,
3613,
8,
277,
304,
272,
21361,
1296,
3167,
774,
14,
5996,
8,
277,
9,
272,
291,
14,
3871,
275,
291,
14,
1258,
14,
1002,
5564,
1296,
7658,
342,
819,
347,
19970,
26872,
1296,
7658,
8,
277,
304,
272,
291,
14,
479,
2531,
6074,
8,
277,
14,
3871,
12,
11006,
14,
4757,
14,
5564,
1296,
7658,
430,
272,
5108,
275,
283,
1014,
921,
4757,
14,
3098,
14,
957,
15,
11522,
15,
12233,
15,
4239,
15,
2861,
10197,
988,
13,
2604,
29,
17,
7,
339,
327,
8133,
1808,
2372,
5564,
1296,
7658,
342,
272,
4733,
275,
291,
14,
1258,
14,
1002,
5564,
1296,
7658,
8,
2302,
9,
272,
291,
14,
479,
2531,
6074,
8,
3871,
12,
11006,
14,
4757,
14,
5564,
1296,
7658,
430,
272,
291,
14,
629,
8,
552,
8,
3871,
14,
2373,
395,
413,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
344,
14,
505,
12,
4733,
14,
2373,
59,
16,
1055,
344,
14,
505,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1213,
14,
505,
12,
4733,
14,
2373,
59,
16,
1055,
1213,
14,
505,
9,
339,
327,
8133,
1808,
8133,
5564,
1296,
7658,
342,
272,
4733,
18,
275,
291,
14,
1258,
14,
3227,
5564,
1296,
7658,
8,
2302,
9,
272,
291,
14,
629,
8,
552,
8,
3871,
18,
14,
2373,
395,
413,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
344,
14,
505,
12,
4733,
18,
14,
2373,
59,
16,
1055,
344,
14,
505,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1213,
14,
505,
12,
4733,
18,
14,
2373,
59,
16,
1055,
1213,
14,
505,
9,
819,
347,
19970,
26872,
16934,
8,
277,
304,
272,
291,
63,
1073,
275,
291,
14,
3871,
14,
2373,
59,
16,
1055,
1002,
12887,
3834,
1252,
6399,
272,
2397,
275,
291,
14,
1258,
14,
1002,
5564,
16934,
8,
277,
63,
1073,
9,
272,
291,
14,
479,
2531,
6074,
8,
2373,
12,
11006,
14,
4757,
14,
5564,
16934,
430,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
344,
14,
505,
12,
2397,
14,
344,
14,
505,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1213,
14,
505,
12,
2397,
14,
1213,
14,
505,
9,
339,
291,
14,
479,
2531,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1927,
1304,
14,
505,
365,
440,
488,
9,
272,
291,
14,
479,
2531,
277,
14,
3871,
14,
2373,
59,
16,
1055,
2019,
11911,
2175,
365,
440,
488,
9,
272,
291,
14,
479,
2531,
277,
14,
3871,
14,
2373,
59,
16,
1055,
2019,
2768,
379,
365,
440,
488,
9,
819,
347,
19970,
26872,
1296,
23937,
7658,
8,
277,
304,
272,
5108,
275,
661,
1014,
921,
4757,
14,
3098,
14,
957,
15,
11522,
15,
12233,
15,
4239,
15,
2861,
4805,
1779,
2475,
15,
19153,
31,
988,
13,
2604,
29,
17,
358,
272,
4733,
275,
291,
14,
1258,
14,
1002,
5564,
1296,
7658,
8,
2302,
9,
272,
4733,
63,
1073,
275,
4733,
14,
2373,
59,
16,
1055,
1002,
23937,
3834,
1252,
6399,
272,
15316,
63,
3871,
275,
291,
14,
1258,
14,
1002,
5564,
1296,
23937,
7658,
8,
3871,
63,
1073,
9,
272,
291,
14,
479,
2531,
6074,
8,
5853,
63,
3871,
12,
11006,
14,
4757,
14,
5564,
1296,
23937,
7658,
430,
272,
291,
14,
479,
2531,
6074,
8,
5853,
63,
3871,
14,
2373,
59,
16,
467,
11006,
14,
4757,
14,
5564,
1296,
23937,
3900,
430,
272,
291,
14,
479,
2531,
5853
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
8937,
4475,
3277,
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,
420,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
363,
2502,
363,
275,
661,
1246,
14,
74,
16056,
281,
334,
42,
3609,
481,
2453,
281,
395,
283,
1598,
283,
1246,
14,
281,
530,
32,
3098,
14,
957,
334,
37,
1567,
31012,
2264,
1237,
5942,
199,
199,
646,
18354,
199,
646,
747,
199,
646,
295,
199,
646,
5228,
199,
646,
900,
199,
646,
2882,
199,
199,
646,
11006,
14,
4757,
14,
1364,
199,
646,
11006,
14,
19930,
14,
1364,
421,
199,
2473,
275,
2125,
199,
2060,
275,
2125,
199,
199,
1258,
275,
11006,
14,
4757,
14,
1364,
14,
27858,
3167,
342,
199,
3773,
3041,
275,
11006,
14,
4757,
14,
1364,
14,
27858,
3167,
342,
199,
19930,
83,
275,
11006,
14,
19930,
14,
1364,
14,
30693,
83,
3167,
342,
421,
199,
533,
21361,
1296,
3167,
774,
8,
2796,
14,
1746,
304,
523,
347,
3613,
8,
277,
304,
272,
291,
14,
1258,
275,
1890,
272,
291,
14,
3773,
3041,
275,
5283,
3041,
272,
291,
14,
3773,
3041,
14,
1084,
3041,
8880,
3264,
8,
1258,
14,
1002,
3041,
8880,
3264,
1012,
272,
291,
14,
3773,
3041,
14,
8460,
63,
2139,
275,
791,
3917,
13,
4486,
356,
6438,
936,
272,
291,
14,
19930,
83,
275,
27076,
83,
272,
291,
14,
7884,
63,
22690,
275,
1890,
423,
5483,
13028,
7841,
8,
15275,
14,
4757,
14,
1364,
14,
7884,
63,
13837,
9,
272,
291,
14,
51,
4225,
1554,
20255,
775,
63,
22690,
275,
1890,
423,
5483,
13028,
7841,
8,
15275,
14,
4757,
14,
1364,
14,
51,
4225,
1554,
20255,
775,
63,
13837,
9,
272,
291,
14,
27160,
63,
22690,
275,
1890,
423,
5483,
13028,
7841,
8,
15275,
14,
4757,
14,
1364,
14,
27160,
63,
13837,
9,
421,
199,
533,
7543,
1296,
3227,
774,
8,
26872,
1296,
3167,
774,
304,
819,
347,
3613,
8,
277,
304,
272,
21361,
1296,
3167,
774,
14,
5996,
8,
277,
9,
272,
291,
14,
3871,
275,
291,
14,
1258,
14,
1002,
5564,
1296,
7658,
342,
819,
347,
19970,
26872,
1296,
7658,
8,
277,
304,
272,
291,
14,
479,
2531,
6074,
8,
277,
14,
3871,
12,
11006,
14,
4757,
14,
5564,
1296,
7658,
430,
272,
5108,
275,
283,
1014,
921,
4757,
14,
3098,
14,
957,
15,
11522,
15,
12233,
15,
4239,
15,
2861,
10197,
988,
13,
2604,
29,
17,
7,
339,
327,
8133,
1808,
2372,
5564,
1296,
7658,
342,
272,
4733,
275,
291,
14,
1258,
14,
1002,
5564,
1296,
7658,
8,
2302,
9,
272,
291,
14,
479,
2531,
6074,
8,
3871,
12,
11006,
14,
4757,
14,
5564,
1296,
7658,
430,
272,
291,
14,
629,
8,
552,
8,
3871,
14,
2373,
395,
413,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
344,
14,
505,
12,
4733,
14,
2373,
59,
16,
1055,
344,
14,
505,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1213,
14,
505,
12,
4733,
14,
2373,
59,
16,
1055,
1213,
14,
505,
9,
339,
327,
8133,
1808,
8133,
5564,
1296,
7658,
342,
272,
4733,
18,
275,
291,
14,
1258,
14,
3227,
5564,
1296,
7658,
8,
2302,
9,
272,
291,
14,
629,
8,
552,
8,
3871,
18,
14,
2373,
395,
413,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
344,
14,
505,
12,
4733,
18,
14,
2373,
59,
16,
1055,
344,
14,
505,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1213,
14,
505,
12,
4733,
18,
14,
2373,
59,
16,
1055,
1213,
14,
505,
9,
819,
347,
19970,
26872,
16934,
8,
277,
304,
272,
291,
63,
1073,
275,
291,
14,
3871,
14,
2373,
59,
16,
1055,
1002,
12887,
3834,
1252,
6399,
272,
2397,
275,
291,
14,
1258,
14,
1002,
5564,
16934,
8,
277,
63,
1073,
9,
272,
291,
14,
479,
2531,
6074,
8,
2373,
12,
11006,
14,
4757,
14,
5564,
16934,
430,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
344,
14,
505,
12,
2397,
14,
344,
14,
505,
9,
272,
291,
14,
629,
8,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1213,
14,
505,
12,
2397,
14,
1213,
14,
505,
9,
339,
291,
14,
479,
2531,
277,
14,
3871,
14,
2373,
59,
16,
1055,
1927,
1304,
14,
505,
365,
440,
488,
9,
272,
291,
14,
479,
2531,
277,
14,
3871,
14,
2373,
59,
16,
1055,
2019,
11911,
2175,
365,
440,
488,
9,
272,
291,
14,
479,
2531,
277,
14,
3871,
14,
2373,
59,
16,
1055,
2019,
2768,
379,
365,
440,
488,
9,
819,
347,
19970,
26872,
1296,
23937,
7658,
8,
277,
304,
272,
5108,
275,
661,
1014,
921,
4757,
14,
3098,
14,
957,
15,
11522,
15,
12233,
15,
4239,
15,
2861,
4805,
1779,
2475,
15,
19153,
31,
988,
13,
2604,
29,
17,
358,
272,
4733,
275,
291,
14,
1258,
14,
1002,
5564,
1296,
7658,
8,
2302,
9,
272,
4733,
63,
1073,
275,
4733,
14,
2373,
59,
16,
1055,
1002,
23937,
3834,
1252,
6399,
272,
15316,
63,
3871,
275,
291,
14,
1258,
14,
1002,
5564,
1296,
23937,
7658,
8,
3871,
63,
1073,
9,
272,
291,
14,
479,
2531,
6074,
8,
5853,
63,
3871,
12,
11006,
14,
4757,
14,
5564,
1296,
23937,
7658,
430,
272,
291,
14,
479,
2531,
6074,
8,
5853,
63,
3871,
14,
2373,
59,
16,
467,
11006,
14,
4757,
14,
5564,
1296,
23937,
3900,
430,
272,
291,
14,
479,
2531,
5853,
0
] |
[
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|
ThePletch/ansible
|
lib/ansible/modules/windows/win_environment.py
|
23
|
3001
|
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2015, Jon Hawkesworth (@jhawkesworth) <figs@unity.demon.co.uk>
#
# 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/>.
# this is a windows documentation stub. actual code lives in the .ps1
# file of the same name
ANSIBLE_METADATA = {'status': ['preview'],
'supported_by': 'community',
'version': '1.0'}
DOCUMENTATION = '''
---
module: win_environment
version_added: "2.0"
short_description: Modifies environment variables on windows hosts.
description:
- Uses .net Environment to set or remove environment variables and can set at User, Machine or Process level.
- User level environment variables will be set, but not available until the user has logged off and on again.
options:
state:
description:
- present to ensure environment variable is set, or absent to ensure it is removed
required: false
default: present
choices:
- present
- absent
name:
description:
- The name of the environment variable
required: true
default: no default
value:
description:
- The value to store in the environment variable. Can be omitted for state=absent
required: false
default: no default
level:
description:
- The level at which to set the environment variable.
- Use 'machine' to set for all users.
- Use 'user' to set for the current user that ansible is connected as.
- Use 'process' to set for the current process. Probably not that useful.
required: true
default: no default
choices:
- machine
- process
- user
author: "Jon Hawkesworth (@jhawkesworth)"
notes:
- This module does not broadcast change events.
This means that the minority of windows applications which can have
their environment changed without restarting will not be notified and
therefore will need restarting to pick up new environment settings.
User level environment variables will require the user to log out
and in again before they become available.
'''
EXAMPLES = '''
# Set an environment variable for all users
win_environment:
state: present
name: TestVariable
value: "Test value"
level: machine
# Remove an environment variable for the current users
win_environment:
state: absent
name: TestVariable
level: user
'''
|
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,
265,
869,
10084,
9246,
584,
273,
8593,
74,
2411,
87,
9246,
584,
273,
9,
665,
5513,
32,
6639,
14,
271,
2106,
14,
331,
14,
3210,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
642,
365,
282,
10061,
3794,
10098,
14,
221,
3503,
1233,
27576,
315,
314,
1275,
1190,
17,
199,
3,
570,
402,
314,
2011,
536,
199,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
4747,
63,
5418,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
3612,
63,
1802,
26,
12972,
5604,
3734,
2860,
641,
10061,
7057,
14,
199,
1802,
26,
272,
446,
14911,
1275,
846,
9711,
370,
663,
503,
2813,
3734,
2860,
436,
883,
663,
737,
2876,
12,
18722,
503,
7132,
2166,
14,
23855,
446,
2876,
2166,
3734,
2860,
911,
506,
663,
12,
1325,
440,
2808,
5133,
314,
922,
965,
10367,
2331,
436,
641,
4020,
14,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
489,
446,
3451,
370,
4868,
3734,
1750,
365,
663,
12,
503,
9552,
370,
4868,
652,
365,
4829,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
489,
446,
3451,
489,
446,
9552,
523,
536,
26,
272,
1369,
26,
489,
446,
710,
536,
402,
314,
3734,
1750,
272,
1415,
26,
2549,
272,
849,
26,
949,
849,
523,
574,
26,
272,
1369,
26,
15166,
446,
710,
574,
370,
3877,
315,
314,
3734,
1750,
14,
6855,
506,
11684,
367,
1174,
29,
5575,
272,
1415,
26,
3055,
272,
849,
26,
949,
849,
523,
2166,
26,
272,
1369,
26,
15166,
446,
710,
2166,
737,
1314,
370,
663,
314,
3734,
1750,
14,
489,
446,
3645,
283,
6744,
7,
370,
663,
367,
1006,
4390,
14,
489,
446,
3645,
283,
751,
7,
370,
663,
367,
314,
1453,
922,
626,
3242,
365,
8539,
465,
14,
489,
446,
3645,
283,
1412,
7,
370,
663,
367,
314,
1453,
2112,
14,
221,
22770,
6665,
440,
626,
2997,
14,
272,
1415,
26,
2549,
272,
849,
26,
949,
849,
272,
3415,
26,
489,
446,
6844,
489,
446,
2112,
489,
446,
922,
199,
2502,
26,
298,
42,
265,
869,
10084,
9246,
584,
273,
8593,
74,
2411,
87,
9246,
584,
273,
2924,
199,
5983,
26,
221,
2043,
446,
961,
859,
1630,
440,
11180,
1570,
4474,
14,
257,
1362,
961,
4910,
626,
314,
1748,
3822,
402,
10061,
13103,
1314,
883,
1172,
221,
1362,
3932,
3734,
2896,
1928,
11004,
316,
911,
440,
506,
29535,
436,
221,
1362,
16119,
911,
1929,
11004,
316,
370,
3732,
1536,
892,
3734,
2202,
14,
257,
1362,
2876,
2166,
3734,
2860,
911,
4409,
314,
922,
370,
943,
734,
221,
1362,
436,
315,
4020,
2544,
2985,
8649,
2808,
14,
199,
2344,
199,
199,
8918,
275,
1449,
523,
327,
2494,
376,
3734,
1750,
367,
1006,
4390,
523,
4747,
63,
5418,
26,
272,
1174,
26,
3451,
272,
536,
26,
1379,
2773,
272,
574,
26,
298,
774,
574,
2,
272,
2166,
26,
6844,
523,
327,
5852,
376,
3734,
1750,
367,
314,
1453,
4390,
523,
4747,
63,
5418,
26,
272,
1174,
26,
9552,
272,
536,
26,
1379,
2773,
272,
2166,
26,
922,
199,
2344,
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
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
334,
67,
9,
6900,
12,
1603,
265,
869,
10084,
9246,
584,
273,
8593,
74,
2411,
87,
9246,
584,
273,
9,
665,
5513,
32,
6639,
14,
271,
2106,
14,
331,
14,
3210,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
642,
365,
282,
10061,
3794,
10098,
14,
221,
3503,
1233,
27576,
315,
314,
1275,
1190,
17,
199,
3,
570,
402,
314,
2011,
536,
199,
199,
8490,
63,
8314,
275,
791,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
297,
490,
283,
1023,
356,
283,
17,
14,
16,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
4747,
63,
5418,
199,
1023,
63,
3270,
26,
298,
18,
14,
16,
2,
199,
3612,
63,
1802,
26,
12972,
5604,
3734,
2860,
641,
10061,
7057,
14,
199,
1802,
26,
272,
446,
14911,
1275,
846,
9711,
370,
663,
503,
2813,
3734,
2860,
436,
883,
663,
737,
2876,
12,
18722,
503,
7132,
2166,
14,
23855,
446,
2876,
2166,
3734,
2860,
911,
506,
663,
12,
1325,
440,
2808,
5133,
314,
922,
965,
10367,
2331,
436,
641,
4020,
14,
199,
1419,
26,
523,
1174,
26,
272,
1369,
26,
489,
446,
3451,
370,
4868,
3734,
1750,
365,
663,
12,
503,
9552,
370,
4868,
652,
365,
4829,
272,
1415,
26,
3055,
272,
849,
26,
3451,
272,
3415,
26,
489,
446,
3451,
489,
446,
9552,
523,
536,
26,
272,
1369,
26,
489,
446,
710,
536,
402,
314,
3734,
1750,
272,
1415,
26,
2549,
272,
849,
26,
949,
849,
523,
574,
26,
272,
1369,
26,
15166,
446,
710,
574,
370,
3877,
315,
314,
3734,
1750,
14,
6855,
506,
11684,
367,
1174,
29,
5575,
272,
1415,
26,
3055,
272,
849,
26,
949,
849,
523,
2166,
26,
272,
1369,
26,
15166,
446,
710,
2166,
737,
1314,
370,
663,
314,
3734,
1750,
14,
489,
446,
3645,
283,
6744,
7,
370,
663,
367,
1006,
4390,
14,
489,
446,
3645,
283,
751,
7,
370,
663,
367,
314,
1453,
922,
626,
3242,
365,
8539,
465,
14,
489,
446,
3645,
283,
1412,
7,
370,
663,
367,
314,
1453,
2112,
14,
221,
22770,
6665,
440,
626,
2997,
14,
272,
1415,
26,
2549,
272,
849,
26,
949,
849,
272,
3415,
26,
489,
446,
6844,
489,
446,
2112,
489,
446,
922,
199,
2502,
26,
298,
42,
265,
869,
10084,
9246,
584,
273,
8593,
74,
2411,
87,
9246,
584,
273,
2924,
199,
5983,
26,
221,
2043,
446,
961,
859,
1630,
440,
11180,
1570,
4474,
14,
257,
1362,
961,
4910,
626,
314,
1748,
3822,
402,
10061,
13103,
1314,
883,
1172,
221,
1362,
3932,
3734,
2896,
1928,
11004,
316,
911,
440,
506,
29535,
436,
221,
1362,
16119,
911,
1929,
11004,
316,
370,
3732,
1536,
892,
3734,
2202,
14,
257,
1362,
2876,
2166,
3734,
2860,
911,
4409,
314,
922,
370,
943,
734,
221,
1362,
436,
315,
4020,
2544,
2985,
8649,
2808,
14,
199,
2344,
199,
199,
8918,
275,
1449,
523,
327,
2494,
376,
3734,
1750,
367,
1006,
4390,
523,
4747,
63,
5418,
26,
272,
1174,
26,
3451,
272,
536,
26,
1379,
2773,
272,
574,
26,
298,
774,
574,
2,
272,
2166,
26,
6844,
523,
327,
5852,
376,
3734,
1750,
367,
314,
1453,
4390,
523,
4747,
63,
5418,
26,
272,
1174,
26,
9552,
272,
536,
26,
1379,
2773,
272,
2166,
26,
922,
199,
2344,
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,
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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
] |
juanchopanza/pyhistuples
|
pyhistuples/tests/test_axis.py
|
1
|
1802
|
'''
Test suite for histogram.axis class.
'''
__author__ = "Juan PALACIOS juan.palacios@nikhef.nl"
from nose import tools as nt
from pyhistuples.pyhistogram.histogram import Axis
def test_instantiate_axis() :
ax = Axis(100, -50, 50, "My first axis")
nt.assert_true(ax is not None)
def test_axis_parameters() :
ax = Axis(100, -50, 50, "My first axis")
nt.assert_true(ax.nbins == 100)
nt.assert_true(ax.min == -50.)
nt.assert_true(ax.max == 50.)
nt.assert_true(ax.label == "My first axis")
nt.assert_true(ax.range == (-50,50))
def test_axis_bin_width() :
ax = Axis(100, -50, 50, "My first axis")
nt.assert_true(ax.binWidth() == 1.)
def test_axis_bin_centre() :
ax = Axis(20, -10, 10, "My first axis")
reference = [x+0.5 for x in xrange(-10,10)]
for i in xrange(10) :
nt.assert_true(ax.binCentre(i) == reference[i])
@nt.raises(IndexError)
def test_invalid_bin_center_raises_IndexError() :
ax = Axis(20, -10, 10, "My first axis")
ax.binCentre(max(ax.underflow_bin, ax.overflow_bin)+1)
def test_invalid_range_gets_special_bins() :
ax = Axis(20, -10, 10, "My first axis")
nt.assert_true(ax.binIndex(11) == ax.overflow_bin)
nt.assert_true(ax.binIndex(-11) == ax.underflow_bin)
def test_axis_equality() :
ax0 = Axis(20, -10, 10, "My first axis")
ax1 = Axis(20, -10, 10, "My first axis")
nt.assert_true(ax0==ax1)
def test_axis_inequality() :
ax0 = Axis(20, -10, 10, "My first axis")
ax1 = Axis(30, -10, 10, "My first axis")
nt.assert_true(ax0!=ax1)
def test_compare_to_Nonsense() :
ax0 = Axis(20, -10, 10, "My first axis")
nt.assert_true(ax0 is not None)
nt.assert_true(not ax0 is None)
nt.assert_true(ax0 != 1)
nt.assert_true(ax0 !=5.0)
nt.assert_true(ax0 != [])
|
gpl-3.0
|
[
2344,
199,
774,
5241,
367,
15379,
14,
3127,
1021,
14,
199,
2344,
199,
199,
363,
2502,
363,
275,
298,
42,
7856,
510,
748,
1348,
13532,
1335,
7856,
14,
80,
14774,
559,
736,
32,
22998,
426,
70,
14,
7530,
2,
199,
199,
504,
11354,
492,
7249,
465,
13377,
199,
504,
1134,
11141,
1363,
83,
14,
647,
14805,
14,
14805,
492,
23205,
421,
199,
318,
511,
63,
3615,
18973,
63,
3127,
342,
520,
272,
2185,
275,
23205,
8,
1960,
12,
446,
1400,
12,
5238,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
365,
440,
488,
9,
421,
199,
318,
511,
63,
3127,
63,
3214,
342,
520,
272,
2185,
275,
23205,
8,
1960,
12,
446,
1400,
12,
5238,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
78,
11329,
508,
2948,
9,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
827,
508,
446,
1400,
4959,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
988,
508,
5238,
4959,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
1302,
508,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
1842,
508,
5868,
1400,
12,
1400,
430,
421,
199,
318,
511,
63,
3127,
63,
1393,
63,
2063,
342,
520,
272,
2185,
275,
23205,
8,
1960,
12,
446,
1400,
12,
5238,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
1393,
6216,
342,
508,
413,
4959,
421,
199,
318,
511,
63,
3127,
63,
1393,
63,
31748,
342,
520,
272,
2185,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
3659,
275,
359,
88,
11,
16,
14,
21,
367,
671,
315,
4945,
2801,
709,
12,
709,
1874,
272,
367,
284,
315,
4945,
8,
709,
9,
520,
267,
13377,
14,
479,
63,
2052,
8,
1219,
14,
1393,
22744,
264,
8,
73,
9,
508,
3659,
59,
73,
566,
421,
199,
32,
343,
14,
3536,
8,
12129,
9,
199,
318,
511,
63,
3197,
63,
1393,
63,
4218,
63,
3536,
63,
12129,
342,
520,
272,
2185,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
2185,
14,
1393,
22744,
264,
8,
988,
8,
1219,
14,
7138,
1659,
63,
1393,
12,
2185,
14,
14108,
63,
1393,
6393,
17,
9,
421,
199,
318,
511,
63,
3197,
63,
1842,
63,
24894,
63,
6664,
63,
11329,
342,
520,
272,
2185,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
1393,
2681,
8,
845,
9,
508,
2185,
14,
14108,
63,
1393,
9,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
1393,
2681,
2801,
845,
9,
508,
2185,
14,
7138,
1659,
63,
1393,
9,
421,
199,
318,
511,
63,
3127,
63,
20982,
342,
520,
272,
2185,
16,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
2185,
17,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
16,
389,
1219,
17,
9,
421,
199,
318,
511,
63,
3127,
63,
1132,
9161,
342,
520,
272,
2185,
16,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
2185,
17,
275,
23205,
8,
1216,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
16,
1111,
1219,
17,
9,
421,
199,
318,
511,
63,
5785,
63,
475,
63,
6932,
16517,
342,
520,
272,
2185,
16,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
16,
365,
440,
488,
9,
272,
13377,
14,
479,
63,
2052,
8,
1397,
2185,
16,
365,
488,
9,
272,
13377,
14,
479,
63,
2052,
8,
1219,
16,
1137,
413,
9,
272,
13377,
14,
479,
63,
2052,
8,
1219,
16,
1137,
21,
14,
16,
9,
272,
13377,
14,
479,
63,
2052,
8,
1219,
16,
1137,
3073,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
774,
5241,
367,
15379,
14,
3127,
1021,
14,
199,
2344,
199,
199,
363,
2502,
363,
275,
298,
42,
7856,
510,
748,
1348,
13532,
1335,
7856,
14,
80,
14774,
559,
736,
32,
22998,
426,
70,
14,
7530,
2,
199,
199,
504,
11354,
492,
7249,
465,
13377,
199,
504,
1134,
11141,
1363,
83,
14,
647,
14805,
14,
14805,
492,
23205,
421,
199,
318,
511,
63,
3615,
18973,
63,
3127,
342,
520,
272,
2185,
275,
23205,
8,
1960,
12,
446,
1400,
12,
5238,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
365,
440,
488,
9,
421,
199,
318,
511,
63,
3127,
63,
3214,
342,
520,
272,
2185,
275,
23205,
8,
1960,
12,
446,
1400,
12,
5238,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
78,
11329,
508,
2948,
9,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
827,
508,
446,
1400,
4959,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
988,
508,
5238,
4959,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
1302,
508,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
1842,
508,
5868,
1400,
12,
1400,
430,
421,
199,
318,
511,
63,
3127,
63,
1393,
63,
2063,
342,
520,
272,
2185,
275,
23205,
8,
1960,
12,
446,
1400,
12,
5238,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
1393,
6216,
342,
508,
413,
4959,
421,
199,
318,
511,
63,
3127,
63,
1393,
63,
31748,
342,
520,
272,
2185,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
3659,
275,
359,
88,
11,
16,
14,
21,
367,
671,
315,
4945,
2801,
709,
12,
709,
1874,
272,
367,
284,
315,
4945,
8,
709,
9,
520,
267,
13377,
14,
479,
63,
2052,
8,
1219,
14,
1393,
22744,
264,
8,
73,
9,
508,
3659,
59,
73,
566,
421,
199,
32,
343,
14,
3536,
8,
12129,
9,
199,
318,
511,
63,
3197,
63,
1393,
63,
4218,
63,
3536,
63,
12129,
342,
520,
272,
2185,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
2185,
14,
1393,
22744,
264,
8,
988,
8,
1219,
14,
7138,
1659,
63,
1393,
12,
2185,
14,
14108,
63,
1393,
6393,
17,
9,
421,
199,
318,
511,
63,
3197,
63,
1842,
63,
24894,
63,
6664,
63,
11329,
342,
520,
272,
2185,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
1393,
2681,
8,
845,
9,
508,
2185,
14,
14108,
63,
1393,
9,
272,
13377,
14,
479,
63,
2052,
8,
1219,
14,
1393,
2681,
2801,
845,
9,
508,
2185,
14,
7138,
1659,
63,
1393,
9,
421,
199,
318,
511,
63,
3127,
63,
20982,
342,
520,
272,
2185,
16,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
2185,
17,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
16,
389,
1219,
17,
9,
421,
199,
318,
511,
63,
3127,
63,
1132,
9161,
342,
520,
272,
2185,
16,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
2185,
17,
275,
23205,
8,
1216,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
16,
1111,
1219,
17,
9,
421,
199,
318,
511,
63,
5785,
63,
475,
63,
6932,
16517,
342,
520,
272,
2185,
16,
275,
23205,
8,
1165,
12,
446,
709,
12,
1616,
12,
298,
5713,
1642,
3114,
531,
272,
13377,
14,
479,
63,
2052,
8,
1219,
16,
365,
440,
488,
9,
272,
13377,
14,
479,
63,
2052,
8,
1397,
2185,
16,
365,
488,
9,
272,
13377,
14,
479,
63,
2052,
8,
1219,
16,
1137,
413,
9,
272,
13377,
14,
479,
63,
2052,
8,
1219,
16,
1137,
21,
14,
16,
9,
272,
13377,
14,
479,
63,
2052,
8,
1219,
16,
1137,
3073,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
morrisonlevi/FrameworkBenchmarks
|
go/setup.py
|
1
|
1362
|
import subprocess
import sys
import os
import setup_util
def start(args, logfile, errfile):
setup_util.replace_text("go/src/hello/hello.go", "tcp\(.*:3306\)", "tcp(" + args.database_host + ":3306)")
if os.name == 'nt':
#subprocess.call("rmdir /s /q pkg\\windows_amd64", shell=True, cwd="go")
#subprocess.call("rmdir /s /q src\\github.com", shell=True, cwd="go")
#subprocess.call("del /s /q /f bin\\hello.exe", shell=True, cwd="go")
subprocess.call("set GOPATH=C:\\FrameworkBenchmarks\\go&& go get ./...", shell=True, cwd="go", stderr=errfile, stdout=logfile)
subprocess.Popen("setup.bat", shell=True, cwd="go", stderr=errfile, stdout=logfile)
return 0
subprocess.call("go get ./...", shell=True, cwd="go", stderr=errfile, stdout=logfile)
subprocess.Popen("go run src/hello/hello.go".rsplit(" "), cwd="go", stderr=errfile, stdout=logfile)
return 0
def stop(logfile, errfile):
if os.name == 'nt':
subprocess.call("taskkill /f /im go.exe > NUL", shell=True, stderr=errfile, stdout=logfile)
subprocess.call("taskkill /f /im hello.exe > NUL", shell=True, stderr=errfile, stdout=logfile)
return 0
p = subprocess.Popen(['ps', 'aux'], stdout=subprocess.PIPE)
out, err = p.communicate()
for line in out.splitlines():
if 'hello' in line:
pid = int(line.split(None, 2)[1])
os.kill(pid, 9)
return 0
|
bsd-3-clause
|
[
646,
3873,
199,
646,
984,
199,
646,
747,
199,
646,
3272,
63,
1974,
199,
199,
318,
1343,
8,
589,
12,
17251,
12,
2329,
493,
304,
523,
3272,
63,
1974,
14,
1814,
63,
505,
480,
1939,
15,
2164,
15,
5006,
15,
5006,
14,
1939,
401,
298,
8815,
60,
19276,
26,
1153,
1690,
60,
4186,
298,
8815,
480,
435,
1249,
14,
4659,
63,
1102,
435,
7244,
1153,
1690,
6320,
523,
340,
747,
14,
354,
508,
283,
343,
356,
272,
327,
5781,
14,
1250,
480,
19405,
1182,
83,
1182,
81,
5496,
1103,
8258,
63,
21778,
772,
401,
5218,
29,
549,
12,
8288,
628,
1939,
531,
272,
327,
5781,
14,
1250,
480,
19405,
1182,
83,
1182,
81,
2928,
1103,
5031,
14,
957,
401,
5218,
29,
549,
12,
8288,
628,
1939,
531,
272,
327,
5781,
14,
1250,
480,
2264,
1182,
83,
1182,
81,
1182,
70,
2517,
1103,
5006,
14,
5803,
401,
5218,
29,
549,
12,
8288,
628,
1939,
531,
272,
3873,
14,
1250,
480,
409,
598,
1938,
11695,
29,
35,
18589,
16442,
18644,
83,
1103,
1939,
12574,
2621,
664,
16605,
23966,
5218,
29,
549,
12,
8288,
628,
1939,
401,
4635,
29,
1508,
493,
12,
3839,
29,
12804,
9,
272,
3873,
14,
7942,
480,
2758,
14,
13475,
401,
5218,
29,
549,
12,
8288,
628,
1939,
401,
4635,
29,
1508,
493,
12,
3839,
29,
12804,
9,
5591,
372,
378,
523,
3873,
14,
1250,
480,
1939,
664,
16605,
23966,
5218,
29,
549,
12,
8288,
628,
1939,
401,
4635,
29,
1508,
493,
12,
3839,
29,
12804,
9,
16421,
3873,
14,
7942,
480,
1939,
1255,
2928,
15,
5006,
15,
5006,
14,
1939,
1674,
13490,
480,
26261,
8288,
628,
1939,
401,
4635,
29,
1508,
493,
12,
3839,
29,
12804,
9,
523,
372,
378,
199,
318,
3631,
8,
12804,
12,
2329,
493,
304,
523,
340,
747,
14,
354,
508,
283,
343,
356,
272,
3873,
14,
1250,
480,
1765,
8997,
1182,
70,
1182,
1017,
2621,
14,
5803,
690,
653,
1293,
401,
5218,
29,
549,
12,
4635,
29,
1508,
493,
12,
3839,
29,
12804,
9,
272,
3873,
14,
1250,
480,
1765,
8997,
1182,
70,
1182,
1017,
16509,
14,
5803,
690,
653,
1293,
401,
5218,
29,
549,
12,
4635,
29,
1508,
493,
12,
3839,
29,
12804,
9,
272,
372,
378,
523,
299,
275,
3873,
14,
7942,
2941,
1190,
297,
283,
10962,
995,
3839,
29,
5781,
14,
6089,
9,
523,
734,
12,
2329,
275,
299,
14,
10664,
342,
523,
367,
1004,
315,
734,
14,
7644,
837,
272,
340,
283,
5006,
7,
315,
1004,
26,
489,
4422,
275,
1109,
8,
604,
14,
1294,
8,
403,
12,
499,
2788,
17,
566,
489,
747,
14,
8997,
8,
3150,
12,
1749,
9,
523,
372,
378,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3873,
199,
646,
984,
199,
646,
747,
199,
646,
3272,
63,
1974,
199,
199,
318,
1343,
8,
589,
12,
17251,
12,
2329,
493,
304,
523,
3272,
63,
1974,
14,
1814,
63,
505,
480,
1939,
15,
2164,
15,
5006,
15,
5006,
14,
1939,
401,
298,
8815,
60,
19276,
26,
1153,
1690,
60,
4186,
298,
8815,
480,
435,
1249,
14,
4659,
63,
1102,
435,
7244,
1153,
1690,
6320,
523,
340,
747,
14,
354,
508,
283,
343,
356,
272,
327,
5781,
14,
1250,
480,
19405,
1182,
83,
1182,
81,
5496,
1103,
8258,
63,
21778,
772,
401,
5218,
29,
549,
12,
8288,
628,
1939,
531,
272,
327,
5781,
14,
1250,
480,
19405,
1182,
83,
1182,
81,
2928,
1103,
5031,
14,
957,
401,
5218,
29,
549,
12,
8288,
628,
1939,
531,
272,
327,
5781,
14,
1250,
480,
2264,
1182,
83,
1182,
81,
1182,
70,
2517,
1103,
5006,
14,
5803,
401,
5218,
29,
549,
12,
8288,
628,
1939,
531,
272,
3873,
14,
1250,
480,
409,
598,
1938,
11695,
29,
35,
18589,
16442,
18644,
83,
1103,
1939,
12574,
2621,
664,
16605,
23966,
5218,
29,
549,
12,
8288,
628,
1939,
401,
4635,
29,
1508,
493,
12,
3839,
29,
12804,
9,
272,
3873,
14,
7942,
480,
2758,
14,
13475,
401,
5218,
29,
549,
12,
8288,
628,
1939,
401,
4635,
29,
1508,
493,
12,
3839,
29,
12804,
9,
5591,
372,
378,
523,
3873,
14,
1250,
480,
1939,
664,
16605,
23966,
5218,
29,
549,
12,
8288,
628,
1939,
401,
4635,
29,
1508,
493,
12,
3839,
29,
12804,
9,
16421,
3873,
14,
7942,
480,
1939,
1255,
2928,
15,
5006,
15,
5006,
14,
1939,
1674,
13490,
480,
26261,
8288,
628,
1939,
401,
4635,
29,
1508,
493,
12,
3839,
29,
12804,
9,
523,
372,
378,
199,
318,
3631,
8,
12804,
12,
2329,
493,
304,
523,
340,
747,
14,
354,
508,
283,
343,
356,
272,
3873,
14,
1250,
480,
1765,
8997,
1182,
70,
1182,
1017,
2621,
14,
5803,
690,
653,
1293,
401,
5218,
29,
549,
12,
4635,
29,
1508,
493,
12,
3839,
29,
12804,
9,
272,
3873,
14,
1250,
480,
1765,
8997,
1182,
70,
1182,
1017,
16509,
14,
5803,
690,
653,
1293,
401,
5218,
29,
549,
12,
4635,
29,
1508,
493,
12,
3839,
29,
12804,
9,
272,
372,
378,
523,
299,
275,
3873,
14,
7942,
2941,
1190,
297,
283,
10962,
995,
3839,
29,
5781,
14,
6089,
9,
523,
734,
12,
2329,
275,
299,
14,
10664,
342,
523,
367,
1004,
315,
734,
14,
7644,
837,
272,
340,
283,
5006,
7,
315,
1004,
26,
489,
4422,
275,
1109,
8,
604,
14,
1294,
8,
403,
12,
499,
2788,
17,
566,
489,
747,
14,
8997,
8,
3150,
12,
1749,
9,
523,
372,
378,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
drewandersonnz/openshift-tools
|
openshift/installer/vendored/openshift-ansible-3.9.14-1/roles/openshift_health_checker/test/openshift_check_test.py
|
49
|
4070
|
import pytest
from openshift_checks import OpenShiftCheck, OpenShiftCheckException
from openshift_checks import load_checks
# Fixtures
@pytest.fixture()
def task_vars():
return dict(foo=42, bar=dict(baz="openshift"))
@pytest.fixture(params=[
("notfound",),
("multiple", "keys", "not", "in", "task_vars"),
])
def missing_keys(request):
return request.param
# Tests
def test_OpenShiftCheck_init():
class TestCheck(OpenShiftCheck):
name = "test_check"
run = NotImplemented
# execute_module required at init if it will be used
with pytest.raises(RuntimeError) as excinfo:
TestCheck().execute_module("foo")
assert 'execute_module' in str(excinfo.value)
execute_module = object()
# initialize with positional argument
check = TestCheck(execute_module)
assert check._execute_module == execute_module
# initialize with keyword argument
check = TestCheck(execute_module=execute_module)
assert check._execute_module == execute_module
assert check.task_vars == {}
assert check.tmp is None
def test_subclasses():
"""OpenShiftCheck.subclasses should find all subclasses recursively."""
class TestCheck1(OpenShiftCheck):
pass
class TestCheck2(OpenShiftCheck):
pass
class TestCheck1A(TestCheck1):
pass
local_subclasses = set([TestCheck1, TestCheck1A, TestCheck2])
known_subclasses = set(OpenShiftCheck.subclasses())
assert local_subclasses - known_subclasses == set(), "local_subclasses should be a subset of known_subclasses"
def test_load_checks():
"""Loading checks should load and return Python modules."""
modules = load_checks()
assert modules
def dummy_check(task_vars):
class TestCheck(OpenShiftCheck):
name = "dummy"
run = NotImplemented
return TestCheck(task_vars=task_vars)
@pytest.mark.parametrize("keys,expected", [
(("foo",), 42),
(("bar", "baz"), "openshift"),
(("bar.baz",), "openshift"),
])
def test_get_var_ok(task_vars, keys, expected):
assert dummy_check(task_vars).get_var(*keys) == expected
def test_get_var_error(task_vars, missing_keys):
with pytest.raises(OpenShiftCheckException):
dummy_check(task_vars).get_var(*missing_keys)
def test_get_var_default(task_vars, missing_keys):
default = object()
assert dummy_check(task_vars).get_var(*missing_keys, default=default) == default
@pytest.mark.parametrize("keys, convert, expected", [
(("foo",), str, "42"),
(("foo",), float, 42.0),
(("bar", "baz"), bool, False),
])
def test_get_var_convert(task_vars, keys, convert, expected):
assert dummy_check(task_vars).get_var(*keys, convert=convert) == expected
def convert_oscexc(_):
raise OpenShiftCheckException("known failure")
def convert_exc(_):
raise Exception("failure unknown")
@pytest.mark.parametrize("keys, convert, expect_text", [
(("bar", "baz"), int, "Cannot convert"),
(("bar.baz",), float, "Cannot convert"),
(("foo",), "bogus", "TypeError"),
(("foo",), lambda a, b: 1, "TypeError"),
(("foo",), lambda a: 1 / 0, "ZeroDivisionError"),
(("foo",), convert_oscexc, "known failure"),
(("foo",), convert_exc, "failure unknown"),
])
def test_get_var_convert_error(task_vars, keys, convert, expect_text):
with pytest.raises(OpenShiftCheckException) as excinfo:
dummy_check(task_vars).get_var(*keys, convert=convert)
assert expect_text in str(excinfo.value)
def test_register(task_vars):
check = dummy_check(task_vars)
check.register_failure(OpenShiftCheckException("spam"))
assert "spam" in str(check.failures[0])
with pytest.raises(OpenShiftCheckException) as excinfo:
check.register_file("spam") # no file contents specified
assert "not specified" in str(excinfo.value)
# normally execute_module registers the result file; test disabling that
check._execute_module = lambda *args, **_: dict()
check.execute_module("eggs", module_args={}, register=False)
assert not check.files_to_save
|
apache-2.0
|
[
646,
4613,
199,
199,
504,
1551,
4723,
63,
8625,
492,
3232,
14379,
1799,
12,
3232,
14379,
1799,
1726,
199,
504,
1551,
4723,
63,
8625,
492,
2248,
63,
8625,
421,
199,
3,
31574,
6969,
421,
199,
32,
4462,
14,
5997,
342,
199,
318,
2120,
63,
2936,
837,
272,
372,
1211,
8,
1421,
29,
2260,
12,
4681,
29,
807,
8,
6185,
628,
22858,
2237,
421,
199,
32,
4462,
14,
5997,
8,
1162,
1524,
272,
1689,
32353,
18529,
272,
1689,
6048,
401,
298,
1612,
401,
298,
1397,
401,
298,
262,
401,
298,
1765,
63,
2936,
1288,
199,
566,
199,
318,
4124,
63,
1612,
8,
1069,
304,
272,
372,
1056,
14,
635,
421,
199,
3,
6496,
421,
199,
318,
511,
63,
4299,
14379,
1799,
63,
826,
837,
272,
1021,
1379,
1799,
8,
4299,
14379,
1799,
304,
267,
536,
275,
298,
396,
63,
1074,
2,
267,
1255,
275,
3784,
339,
327,
5341,
63,
578,
1415,
737,
4205,
340,
652,
911,
506,
1202,
272,
543,
4613,
14,
3536,
8,
13281,
9,
465,
21596,
26,
267,
1379,
1799,
1252,
2526,
63,
578,
480,
1421,
531,
272,
702,
283,
2526,
63,
578,
7,
315,
620,
8,
27447,
14,
585,
9,
339,
5341,
63,
578,
275,
909,
342,
339,
327,
8265,
543,
11333,
1423,
272,
1104,
275,
1379,
1799,
8,
2526,
63,
578,
9,
272,
702,
1104,
423,
2526,
63,
578,
508,
5341,
63,
578,
339,
327,
8265,
543,
4252,
1423,
272,
1104,
275,
1379,
1799,
8,
2526,
63,
578,
29,
2526,
63,
578,
9,
272,
702,
1104,
423,
2526,
63,
578,
508,
5341,
63,
578,
339,
702,
1104,
14,
1765,
63,
2936,
508,
1052,
272,
702,
1104,
14,
2791,
365,
488,
421,
199,
318,
511,
63,
19094,
837,
272,
408,
4299,
14379,
1799,
14,
19094,
1077,
2342,
1006,
9180,
15035,
1041,
272,
1021,
1379,
1799,
17,
8,
4299,
14379,
1799,
304,
267,
986,
339,
1021,
1379,
1799,
18,
8,
4299,
14379,
1799,
304,
267,
986,
339,
1021,
1379,
1799,
17,
33,
8,
774,
1799,
17,
304,
267,
986,
339,
2257,
63,
19094,
275,
663,
779,
774,
1799,
17,
12,
1379,
1799,
17,
33,
12,
1379,
1799,
18,
566,
272,
6040,
63,
19094,
275,
663,
8,
4299,
14379,
1799,
14,
19094,
1012,
339,
702,
2257,
63,
19094,
446,
6040,
63,
19094,
508,
663,
1062,
298,
1832,
63,
19094,
1077,
506,
282,
10026,
402,
6040,
63,
19094,
2,
421,
199,
318,
511,
63,
912,
63,
8625,
837,
272,
408,
19236,
5920,
1077,
2248,
436,
372,
2018,
4621,
1041,
272,
4621,
275,
2248,
63,
8625,
342,
272,
702,
4621,
421,
199,
318,
7283,
63,
1074,
8,
1765,
63,
2936,
304,
272,
1021,
1379,
1799,
8,
4299,
14379,
1799,
304,
267,
536,
275,
298,
5869,
2,
267,
1255,
275,
3784,
339,
372,
1379,
1799,
8,
1765,
63,
2936,
29,
1765,
63,
2936,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1612,
12,
2062,
401,
359,
272,
19110,
1421,
18529,
5685,
395,
272,
19110,
1700,
401,
298,
6185,
1288,
298,
22858,
1288,
272,
19110,
1700,
14,
6185,
18529,
298,
22858,
1288,
199,
566,
199,
318,
511,
63,
362,
63,
1391,
63,
745,
8,
1765,
63,
2936,
12,
2883,
12,
1420,
304,
272,
702,
7283,
63,
1074,
8,
1765,
63,
2936,
680,
362,
63,
1391,
2031,
1612,
9,
508,
1420,
421,
199,
318,
511,
63,
362,
63,
1391,
63,
705,
8,
1765,
63,
2936,
12,
4124,
63,
1612,
304,
272,
543,
4613,
14,
3536,
8,
4299,
14379,
1799,
1726,
304,
267,
7283,
63,
1074,
8,
1765,
63,
2936,
680,
362,
63,
1391,
2031,
4752,
63,
1612,
9,
421,
199,
318,
511,
63,
362,
63,
1391,
63,
885,
8,
1765,
63,
2936,
12,
4124,
63,
1612,
304,
272,
849,
275,
909,
342,
272,
702,
7283,
63,
1074,
8,
1765,
63,
2936,
680,
362,
63,
1391,
2031,
4752,
63,
1612,
12,
849,
29,
885,
9,
508,
849,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1612,
12,
3957,
12,
1420,
401,
359,
272,
19110,
1421,
18529,
620,
12,
298,
2260,
1288,
272,
19110,
1421,
18529,
2069,
12,
5685,
14,
16,
395,
272,
19110,
1700,
401,
298,
6185,
1288,
2155,
12,
756,
395,
199,
566,
199,
318,
511,
63,
362,
63,
1391,
63,
3916,
8,
1765,
63,
2936,
12,
2883,
12,
3957,
12,
1420,
304,
272,
702,
7283,
63,
1074,
8,
1765,
63,
2936,
680,
362,
63,
1391,
2031,
1612,
12,
3957,
29,
3916,
9,
508,
1420,
421,
199,
318,
3957,
63,
736,
301,
1812,
1547,
304,
272,
746,
3232,
14379,
1799,
1726,
480,
3159,
5988,
531,
421,
199,
318,
3957,
63,
2804,
1547,
304,
272,
746,
2186,
480,
5328,
5809,
531,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1612,
12,
3957,
12,
4282,
63,
505,
401,
359,
272,
19110,
1700,
401,
298,
6185,
1288,
1109,
12,
298,
6612,
3957,
1288,
272,
19110,
1700,
14,
6185,
18529,
2069,
12,
298,
6612,
3957,
1288,
272,
19110,
1421,
18529,
298,
18665,
401,
298,
4333,
1288,
272,
19110,
1421,
18529,
2400,
282,
12,
330,
26,
413,
12,
298,
4333,
1288,
272,
19110,
1421,
18529,
2400,
282,
26,
413,
1182,
378,
12,
298,
31000,
1288,
272,
19110,
1421,
18529,
3957,
63,
736,
301,
1812,
12,
298,
3159,
5988,
1288,
272,
19110,
1421,
18529,
3957,
63,
2804,
12,
298,
5328,
5809,
1288,
199,
566,
199,
318,
511,
63,
362,
63,
1391,
63,
3916,
63,
705,
8,
1765,
63,
2936,
12,
2883,
12,
3957,
12,
4282,
63,
505,
304,
272,
543,
4613,
14,
3536,
8,
4299,
14379,
1799,
1726,
9,
465,
21596,
26,
267,
7283,
63,
1074,
8,
1765,
63,
2936,
680,
362,
63,
1391,
2031,
1612,
12,
3957,
29,
3916,
9,
272,
702,
4282,
63,
505,
315,
620,
8,
27447,
14,
585,
9,
421,
199,
318,
511,
63,
2683,
8,
1765,
63,
2936,
304,
272,
1104,
275,
7283,
63,
1074,
8,
1765,
63,
2936,
9,
339,
1104,
14,
2683,
63,
5328,
8,
4299,
14379,
1799,
1726,
480,
8283,
2237,
272,
702,
298,
8283,
2,
315,
620,
8,
1074,
14,
9968,
59,
16,
566,
339,
543,
4613,
14,
3536,
8,
4299,
14379,
1799,
1726,
9,
465,
21596,
26,
267,
1104,
14,
2683,
63,
493,
480,
8283,
531,
221,
327,
949,
570,
4072,
2013,
272,
702,
298,
1397,
2013,
2,
315,
620,
8
] |
[
4613,
199,
199,
504,
1551,
4723,
63,
8625,
492,
3232,
14379,
1799,
12,
3232,
14379,
1799,
1726,
199,
504,
1551,
4723,
63,
8625,
492,
2248,
63,
8625,
421,
199,
3,
31574,
6969,
421,
199,
32,
4462,
14,
5997,
342,
199,
318,
2120,
63,
2936,
837,
272,
372,
1211,
8,
1421,
29,
2260,
12,
4681,
29,
807,
8,
6185,
628,
22858,
2237,
421,
199,
32,
4462,
14,
5997,
8,
1162,
1524,
272,
1689,
32353,
18529,
272,
1689,
6048,
401,
298,
1612,
401,
298,
1397,
401,
298,
262,
401,
298,
1765,
63,
2936,
1288,
199,
566,
199,
318,
4124,
63,
1612,
8,
1069,
304,
272,
372,
1056,
14,
635,
421,
199,
3,
6496,
421,
199,
318,
511,
63,
4299,
14379,
1799,
63,
826,
837,
272,
1021,
1379,
1799,
8,
4299,
14379,
1799,
304,
267,
536,
275,
298,
396,
63,
1074,
2,
267,
1255,
275,
3784,
339,
327,
5341,
63,
578,
1415,
737,
4205,
340,
652,
911,
506,
1202,
272,
543,
4613,
14,
3536,
8,
13281,
9,
465,
21596,
26,
267,
1379,
1799,
1252,
2526,
63,
578,
480,
1421,
531,
272,
702,
283,
2526,
63,
578,
7,
315,
620,
8,
27447,
14,
585,
9,
339,
5341,
63,
578,
275,
909,
342,
339,
327,
8265,
543,
11333,
1423,
272,
1104,
275,
1379,
1799,
8,
2526,
63,
578,
9,
272,
702,
1104,
423,
2526,
63,
578,
508,
5341,
63,
578,
339,
327,
8265,
543,
4252,
1423,
272,
1104,
275,
1379,
1799,
8,
2526,
63,
578,
29,
2526,
63,
578,
9,
272,
702,
1104,
423,
2526,
63,
578,
508,
5341,
63,
578,
339,
702,
1104,
14,
1765,
63,
2936,
508,
1052,
272,
702,
1104,
14,
2791,
365,
488,
421,
199,
318,
511,
63,
19094,
837,
272,
408,
4299,
14379,
1799,
14,
19094,
1077,
2342,
1006,
9180,
15035,
1041,
272,
1021,
1379,
1799,
17,
8,
4299,
14379,
1799,
304,
267,
986,
339,
1021,
1379,
1799,
18,
8,
4299,
14379,
1799,
304,
267,
986,
339,
1021,
1379,
1799,
17,
33,
8,
774,
1799,
17,
304,
267,
986,
339,
2257,
63,
19094,
275,
663,
779,
774,
1799,
17,
12,
1379,
1799,
17,
33,
12,
1379,
1799,
18,
566,
272,
6040,
63,
19094,
275,
663,
8,
4299,
14379,
1799,
14,
19094,
1012,
339,
702,
2257,
63,
19094,
446,
6040,
63,
19094,
508,
663,
1062,
298,
1832,
63,
19094,
1077,
506,
282,
10026,
402,
6040,
63,
19094,
2,
421,
199,
318,
511,
63,
912,
63,
8625,
837,
272,
408,
19236,
5920,
1077,
2248,
436,
372,
2018,
4621,
1041,
272,
4621,
275,
2248,
63,
8625,
342,
272,
702,
4621,
421,
199,
318,
7283,
63,
1074,
8,
1765,
63,
2936,
304,
272,
1021,
1379,
1799,
8,
4299,
14379,
1799,
304,
267,
536,
275,
298,
5869,
2,
267,
1255,
275,
3784,
339,
372,
1379,
1799,
8,
1765,
63,
2936,
29,
1765,
63,
2936,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1612,
12,
2062,
401,
359,
272,
19110,
1421,
18529,
5685,
395,
272,
19110,
1700,
401,
298,
6185,
1288,
298,
22858,
1288,
272,
19110,
1700,
14,
6185,
18529,
298,
22858,
1288,
199,
566,
199,
318,
511,
63,
362,
63,
1391,
63,
745,
8,
1765,
63,
2936,
12,
2883,
12,
1420,
304,
272,
702,
7283,
63,
1074,
8,
1765,
63,
2936,
680,
362,
63,
1391,
2031,
1612,
9,
508,
1420,
421,
199,
318,
511,
63,
362,
63,
1391,
63,
705,
8,
1765,
63,
2936,
12,
4124,
63,
1612,
304,
272,
543,
4613,
14,
3536,
8,
4299,
14379,
1799,
1726,
304,
267,
7283,
63,
1074,
8,
1765,
63,
2936,
680,
362,
63,
1391,
2031,
4752,
63,
1612,
9,
421,
199,
318,
511,
63,
362,
63,
1391,
63,
885,
8,
1765,
63,
2936,
12,
4124,
63,
1612,
304,
272,
849,
275,
909,
342,
272,
702,
7283,
63,
1074,
8,
1765,
63,
2936,
680,
362,
63,
1391,
2031,
4752,
63,
1612,
12,
849,
29,
885,
9,
508,
849,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1612,
12,
3957,
12,
1420,
401,
359,
272,
19110,
1421,
18529,
620,
12,
298,
2260,
1288,
272,
19110,
1421,
18529,
2069,
12,
5685,
14,
16,
395,
272,
19110,
1700,
401,
298,
6185,
1288,
2155,
12,
756,
395,
199,
566,
199,
318,
511,
63,
362,
63,
1391,
63,
3916,
8,
1765,
63,
2936,
12,
2883,
12,
3957,
12,
1420,
304,
272,
702,
7283,
63,
1074,
8,
1765,
63,
2936,
680,
362,
63,
1391,
2031,
1612,
12,
3957,
29,
3916,
9,
508,
1420,
421,
199,
318,
3957,
63,
736,
301,
1812,
1547,
304,
272,
746,
3232,
14379,
1799,
1726,
480,
3159,
5988,
531,
421,
199,
318,
3957,
63,
2804,
1547,
304,
272,
746,
2186,
480,
5328,
5809,
531,
421,
199,
32,
4462,
14,
1657,
14,
10396,
480,
1612,
12,
3957,
12,
4282,
63,
505,
401,
359,
272,
19110,
1700,
401,
298,
6185,
1288,
1109,
12,
298,
6612,
3957,
1288,
272,
19110,
1700,
14,
6185,
18529,
2069,
12,
298,
6612,
3957,
1288,
272,
19110,
1421,
18529,
298,
18665,
401,
298,
4333,
1288,
272,
19110,
1421,
18529,
2400,
282,
12,
330,
26,
413,
12,
298,
4333,
1288,
272,
19110,
1421,
18529,
2400,
282,
26,
413,
1182,
378,
12,
298,
31000,
1288,
272,
19110,
1421,
18529,
3957,
63,
736,
301,
1812,
12,
298,
3159,
5988,
1288,
272,
19110,
1421,
18529,
3957,
63,
2804,
12,
298,
5328,
5809,
1288,
199,
566,
199,
318,
511,
63,
362,
63,
1391,
63,
3916,
63,
705,
8,
1765,
63,
2936,
12,
2883,
12,
3957,
12,
4282,
63,
505,
304,
272,
543,
4613,
14,
3536,
8,
4299,
14379,
1799,
1726,
9,
465,
21596,
26,
267,
7283,
63,
1074,
8,
1765,
63,
2936,
680,
362,
63,
1391,
2031,
1612,
12,
3957,
29,
3916,
9,
272,
702,
4282,
63,
505,
315,
620,
8,
27447,
14,
585,
9,
421,
199,
318,
511,
63,
2683,
8,
1765,
63,
2936,
304,
272,
1104,
275,
7283,
63,
1074,
8,
1765,
63,
2936,
9,
339,
1104,
14,
2683,
63,
5328,
8,
4299,
14379,
1799,
1726,
480,
8283,
2237,
272,
702,
298,
8283,
2,
315,
620,
8,
1074,
14,
9968,
59,
16,
566,
339,
543,
4613,
14,
3536,
8,
4299,
14379,
1799,
1726,
9,
465,
21596,
26,
267,
1104,
14,
2683,
63,
493,
480,
8283,
531,
221,
327,
949,
570,
4072,
2013,
272,
702,
298,
1397,
2013,
2,
315,
620,
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,
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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
] |
petemounce/ansible
|
lib/ansible/modules/network/nxos/nxos_vrf_interface.py
|
46
|
9455
|
#!/usr/bin/python
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
ANSIBLE_METADATA = {'metadata_version': '1.0',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: nxos_vrf_interface
extends_documentation_fragment: nxos
version_added: "2.1"
short_description: Manages interface specific VRF configuration.
description:
- Manages interface specific VRF configuration.
author:
- Jason Edelman (@jedelman8)
- Gabriele Gerbino (@GGabriele)
notes:
- VRF needs to be added globally with M(nxos_vrf) before
adding a VRF to an interface.
- Remove a VRF from an interface will still remove
all L3 attributes just as it does from CLI.
- VRF is not read from an interface until IP address is
configured on that interface.
options:
vrf:
description:
- Name of VRF to be managed.
required: true
interface:
description:
- Full name of interface to be managed, i.e. Ethernet1/1.
required: true
state:
description:
- Manages desired state of the resource.
required: false
default: present
choices: ['present','absent']
'''
EXAMPLES = '''
- name: Ensure vrf ntc exists on Eth1/1
nxos_vrf_interface:
vrf: ntc
interface: Ethernet1/1
host: 68.170.147.165
state: present
- name: Ensure ntc VRF does not exist on Eth1/1
nxos_vrf_interface:
vrf: ntc
interface: Ethernet1/1
host: 68.170.147.165
state: absent
'''
RETURN = '''
proposed:
description: k/v pairs of parameters passed into module
returned: always
type: dict
sample: {"interface": "loopback16", "vrf": "ntc"}
existing:
description: k/v pairs of existing vrf on the interface
returned: always
type: dict
sample: {"interface": "loopback16", "vrf": ""}
end_state:
description: k/v pairs of vrf after module execution
returned: always
type: dict
sample: {"interface": "loopback16", "vrf": "ntc"}
updates:
description: commands sent to the device
returned: always
type: list
sample: ["interface loopback16", "vrf member ntc"]
changed:
description: check to see if a change was made on the device
returned: always
type: boolean
sample: true
'''
import re
from ansible.module_utils.nxos import get_config, load_config, run_commands
from ansible.module_utils.nxos import nxos_argument_spec, check_args
from ansible.module_utils.basic import AnsibleModule
WARNINGS = []
def execute_show_command(command, module, command_type='cli_show'):
if module.params['transport'] == 'cli':
if 'show run' not in command:
command += ' | json'
cmds = [command]
body = run_commands(module, cmds)
elif module.params['transport'] == 'nxapi':
cmds = [command]
body = run_commands(module, cmds)
return body
def get_interface_type(interface):
if interface.upper().startswith('ET'):
return 'ethernet'
elif interface.upper().startswith('VL'):
return 'svi'
elif interface.upper().startswith('LO'):
return 'loopback'
elif interface.upper().startswith('MG'):
return 'management'
elif interface.upper().startswith('MA'):
return 'management'
elif interface.upper().startswith('PO'):
return 'portchannel'
else:
return 'unknown'
def get_interface_mode(interface, intf_type, module):
command = 'show interface {0}'.format(interface)
interface = {}
mode = 'unknown'
if intf_type in ['ethernet', 'portchannel']:
body = execute_show_command(command, module)[0]
interface_table = body['TABLE_interface']['ROW_interface']
mode = str(interface_table.get('eth_mode', 'layer3'))
if mode == 'access' or mode == 'trunk':
mode = 'layer2'
elif intf_type == 'loopback' or intf_type == 'svi':
mode = 'layer3'
return mode
def get_vrf_list(module):
command = 'show vrf all'
vrf_list = []
body = execute_show_command(command, module)[0]
try:
vrf_table = body['TABLE_vrf']['ROW_vrf']
except (KeyError, AttributeError):
return vrf_list
for each in vrf_table:
vrf_list.append(str(each['vrf_name']))
return vrf_list
def get_interface_info(interface, module):
if not interface.startswith('loopback'):
interface = interface.capitalize()
interface_type = get_interface_type(interface)
intf_module = re.split('\d+', interface)[0]
intf_name = interface_type + interface.split(intf_module)[1]
command = 'show run | section interface.{0}'.format(interface)
vrf_regex = ".*vrf\s+member\s+(?P<vrf>\S+).*"
try:
body = execute_show_command(command, module,
command_type='cli_show_ascii')[0]
match_vrf = re.match(vrf_regex, body, re.DOTALL)
group_vrf = match_vrf.groupdict()
vrf = group_vrf["vrf"]
except (AttributeError, TypeError):
return ""
return vrf
def is_default(interface, module):
command = 'show run interface {0}'.format(interface)
try:
body = execute_show_command(command, module,
command_type='cli_show_ascii')[0]
raw_list = body.split('\n')
if raw_list[-1].startswith('interface'):
return True
else:
return False
except (KeyError, IndexError):
return 'DNE'
def main():
argument_spec = dict(
vrf=dict(required=True),
interface=dict(type='str', required=True),
state=dict(default='present', choices=['present', 'absent'],
required=False),
include_defaults=dict(default=False),
config=dict(),
save=dict(type='bool', default=False)
)
argument_spec.update(nxos_argument_spec)
module = AnsibleModule(argument_spec=argument_spec,
supports_check_mode=True)
warnings = list()
check_args(module, warnings)
vrf = module.params['vrf']
interface = module.params['interface'].lower()
state = module.params['state']
current_vrfs = get_vrf_list(module)
if vrf not in current_vrfs:
WARNINGS.append("The VRF is not present/active on the device. "
"Use nxos_vrf to fix this.")
intf_type = get_interface_type(interface)
if (intf_type != 'ethernet' and module.params['transport'] == 'cli'):
if is_default(interface, module) == 'DNE':
module.fail_json(msg="interface does not exist on switch. Verify "
"switch platform or create it first with "
"nxos_interface if it's a logical interface")
mode = get_interface_mode(interface, intf_type, module)
if mode == 'layer2':
module.fail_json(msg='Ensure interface is a Layer 3 port before '
'configuring a VRF on an interface. You can '
'use nxos_interface')
proposed = dict(interface=interface, vrf=vrf)
current_vrf = get_interface_info(interface, module)
existing = dict(interface=interface, vrf=current_vrf)
changed = False
end_state = existing
if vrf != existing['vrf'] and state == 'absent':
module.fail_json(msg='The VRF you are trying to remove '
'from the interface does not exist '
'on that interface.',
interface=interface, proposed_vrf=vrf,
existing_vrf=existing['vrf'])
commands = []
if existing:
if state == 'absent':
if existing and vrf == existing['vrf']:
command = 'no vrf member {0}'.format(vrf)
commands.append(command)
elif state == 'present':
if existing['vrf'] != vrf:
command = 'vrf member {0}'.format(vrf)
commands.append(command)
if commands:
commands.insert(0, 'interface {0}'.format(interface))
if commands:
if module.check_mode:
module.exit_json(changed=True, commands=commands)
else:
load_config(module, commands)
changed = True
changed_vrf = get_interface_info(interface, module)
end_state = dict(interface=interface, vrf=changed_vrf)
if 'configure' in commands:
commands.pop(0)
results = {}
results['proposed'] = proposed
results['existing'] = existing
results['end_state'] = end_state
results['updates'] = commands
results['changed'] = changed
if WARNINGS:
results['warnings'] = WARNINGS
module.exit_json(**results)
if __name__ == '__main__':
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22072,
63,
11863,
63,
3266,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
3612,
63,
1802,
26,
21612,
3217,
2488,
812,
11778,
2897,
14,
199,
1802,
26,
272,
446,
21612,
3217,
2488,
812,
11778,
2897,
14,
199,
2502,
26,
272,
446,
1603,
2660,
662,
2264,
1237,
8593,
6532,
2264,
1237,
24,
9,
272,
446,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
5983,
26,
272,
446,
812,
11778,
4839,
370,
506,
3483,
26662,
543,
603,
8,
17982,
63,
11863,
9,
2544,
489,
7791,
282,
812,
11778,
370,
376,
3217,
14,
272,
446,
5852,
282,
812,
11778,
687,
376,
3217,
911,
5139,
2813,
489,
1006,
491,
19,
3004,
2951,
465,
652,
1630,
687,
14214,
14,
272,
446,
812,
11778,
365,
440,
1586,
687,
376,
3217,
5133,
3531,
2287,
365,
489,
7526,
641,
626,
3217,
14,
199,
1419,
26,
272,
15209,
26,
267,
1369,
26,
288,
446,
2812,
402,
812,
11778,
370,
506,
12883,
14,
267,
1415,
26,
2549,
272,
3217,
26,
267,
1369,
26,
288,
446,
16579,
536,
402,
3217,
370,
506,
12883,
12,
284,
14,
69,
14,
26125,
17,
15,
17,
14,
267,
1415,
26,
2549,
272,
1174,
26,
267,
1369,
26,
288,
446,
21612,
6387,
1174,
402,
314,
2073,
14,
267,
1415,
26,
3055,
267,
849,
26,
3451,
267,
3415,
26,
788,
1881,
1673,
5575,
418,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
7523,
15209,
302,
3641,
3495,
641,
662,
273,
17,
15,
17,
523,
22072,
63,
11863,
63,
3266,
26,
272,
15209,
26,
302,
3641,
272,
3217,
26,
26125,
17,
15,
17,
272,
1591,
26,
10851,
14,
11010,
14,
11160,
14,
10355,
272,
1174,
26,
3451,
199,
199,
13,
536,
26,
7523,
302,
3641,
812,
11778,
1630,
440,
2187,
641,
662,
273,
17,
15,
17,
523,
22072,
63,
11863,
63,
3266,
26,
272,
15209,
26,
302,
3641,
272,
3217,
26,
26125,
17,
15,
17,
272,
1591,
26,
10851,
14,
11010,
14,
11160,
14,
10355,
272,
1174,
26,
9552,
199,
2344,
199,
199,
9677,
275,
1449,
199,
15676,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
2633,
3032,
1901,
859,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
3266,
582,
298,
23983,
975,
401,
298,
11863,
582,
298,
343,
67,
3570,
199,
5952,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
3411,
15209,
641,
314,
3217,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
3266,
582,
298,
23983,
975,
401,
298,
11863,
582,
3087,
93,
199,
500,
63,
929,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
15209,
2410,
859,
6451,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
3266,
582,
298,
23983,
975,
401,
298,
11863,
582,
298,
343,
67,
3570,
199,
7618,
26,
272,
1369,
26,
3718,
4847,
370,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
2097,
3266,
4438,
894,
975,
401,
298,
11863,
3653,
302,
3641,
937,
199,
2489,
26,
272,
1369,
26,
1104,
370,
1937,
340,
282,
1570,
1990,
6326,
641,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
5046,
272,
2690,
26,
2549,
199,
2344,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
664,
63,
888,
12,
2248,
63,
888,
12,
1255,
63,
4405,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
22072,
63,
2094,
63,
1650,
12,
1104,
63,
589,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
421,
199,
17449,
3881,
275,
942,
199,
199,
318,
5341,
63,
2384,
63,
1531,
8,
1531,
12,
859,
12,
1414,
63,
466,
534,
2764,
63,
2384,
735,
272,
340,
859,
14,
1162,
459,
5545,
418,
508,
283,
2764,
356,
267,
340,
283,
2384,
1255,
7,
440,
315,
1414,
26,
288,
1414,
847,
283,
1204,
2022,
7,
267,
11465,
275,
359,
1531,
61,
267,
2396,
275,
1255,
63,
4405,
8,
578,
12,
11465,
9,
272,
916,
859,
14,
1162,
459,
5545,
418,
508,
283,
7343,
1246,
356,
267,
11465,
275,
359,
1531,
61,
267,
2396,
275,
1255,
63,
4405,
8,
578,
12,
11465,
9,
339,
372,
2396,
421,
199,
318,
664,
63,
3266,
63,
466,
8,
3266,
304,
272,
340,
3217,
14,
4142,
1252,
2460,
360,
775,
735,
267,
372,
283,
20354,
7,
272,
916,
3217,
14,
4142,
1252,
2460,
360,
32458,
735,
267,
372,
283,
83,
433,
7,
272,
916,
3217,
14,
4142,
1252,
2460,
360,
1484,
735,
267,
372,
283,
23983,
7,
272,
916,
3217,
14,
4142,
1252,
2460,
360,
26255,
735,
267,
372,
283,
8110,
7,
272,
916,
3217,
14,
4142,
1252,
2460,
360,
2054,
735,
267,
372,
283,
8110,
7,
272,
916,
3217,
14,
4142,
1252,
2460,
360,
1512,
735,
267,
372,
283,
719,
2775,
7,
272,
587,
26,
267,
372,
283,
5187,
7,
421,
199,
318,
664,
63,
3266,
63,
632,
8,
3266
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
16,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22072,
63,
11863,
63,
3266,
199,
11036,
63,
9970,
63,
7677,
26,
22072,
199,
1023,
63,
3270,
26,
298,
18,
14,
17,
2,
199,
3612,
63,
1802,
26,
21612,
3217,
2488,
812,
11778,
2897,
14,
199,
1802,
26,
272,
446,
21612,
3217,
2488,
812,
11778,
2897,
14,
199,
2502,
26,
272,
446,
1603,
2660,
662,
2264,
1237,
8593,
6532,
2264,
1237,
24,
9,
272,
446,
598,
371,
322,
8081,
22261,
1393,
79,
8593,
2916,
371,
322,
8081,
9,
199,
5983,
26,
272,
446,
812,
11778,
4839,
370,
506,
3483,
26662,
543,
603,
8,
17982,
63,
11863,
9,
2544,
489,
7791,
282,
812,
11778,
370,
376,
3217,
14,
272,
446,
5852,
282,
812,
11778,
687,
376,
3217,
911,
5139,
2813,
489,
1006,
491,
19,
3004,
2951,
465,
652,
1630,
687,
14214,
14,
272,
446,
812,
11778,
365,
440,
1586,
687,
376,
3217,
5133,
3531,
2287,
365,
489,
7526,
641,
626,
3217,
14,
199,
1419,
26,
272,
15209,
26,
267,
1369,
26,
288,
446,
2812,
402,
812,
11778,
370,
506,
12883,
14,
267,
1415,
26,
2549,
272,
3217,
26,
267,
1369,
26,
288,
446,
16579,
536,
402,
3217,
370,
506,
12883,
12,
284,
14,
69,
14,
26125,
17,
15,
17,
14,
267,
1415,
26,
2549,
272,
1174,
26,
267,
1369,
26,
288,
446,
21612,
6387,
1174,
402,
314,
2073,
14,
267,
1415,
26,
3055,
267,
849,
26,
3451,
267,
3415,
26,
788,
1881,
1673,
5575,
418,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
7523,
15209,
302,
3641,
3495,
641,
662,
273,
17,
15,
17,
523,
22072,
63,
11863,
63,
3266,
26,
272,
15209,
26,
302,
3641,
272,
3217,
26,
26125,
17,
15,
17,
272,
1591,
26,
10851,
14,
11010,
14,
11160,
14,
10355,
272,
1174,
26,
3451,
199,
199,
13,
536,
26,
7523,
302,
3641,
812,
11778,
1630,
440,
2187,
641,
662,
273,
17,
15,
17,
523,
22072,
63,
11863,
63,
3266,
26,
272,
15209,
26,
302,
3641,
272,
3217,
26,
26125,
17,
15,
17,
272,
1591,
26,
10851,
14,
11010,
14,
11160,
14,
10355,
272,
1174,
26,
9552,
199,
2344,
199,
199,
9677,
275,
1449,
199,
15676,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
2633,
3032,
1901,
859,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
3266,
582,
298,
23983,
975,
401,
298,
11863,
582,
298,
343,
67,
3570,
199,
5952,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
3411,
15209,
641,
314,
3217,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
3266,
582,
298,
23983,
975,
401,
298,
11863,
582,
3087,
93,
199,
500,
63,
929,
26,
272,
1369,
26,
1022,
15,
86,
6342,
402,
15209,
2410,
859,
6451,
272,
2138,
26,
3544,
272,
730,
26,
1211,
272,
2690,
26,
2420,
3266,
582,
298,
23983,
975,
401,
298,
11863,
582,
298,
343,
67,
3570,
199,
7618,
26,
272,
1369,
26,
3718,
4847,
370,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
769,
272,
2690,
26,
2097,
3266,
4438,
894,
975,
401,
298,
11863,
3653,
302,
3641,
937,
199,
2489,
26,
272,
1369,
26,
1104,
370,
1937,
340,
282,
1570,
1990,
6326,
641,
314,
2243,
272,
2138,
26,
3544,
272,
730,
26,
5046,
272,
2690,
26,
2549,
199,
2344,
199,
646,
295,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
664,
63,
888,
12,
2248,
63,
888,
12,
1255,
63,
4405,
199,
504,
3242,
14,
578,
63,
1208,
14,
17982,
492,
22072,
63,
2094,
63,
1650,
12,
1104,
63,
589,
199,
504,
3242,
14,
578,
63,
1208,
14,
4316,
492,
6953,
421,
199,
17449,
3881,
275,
942,
199,
199,
318,
5341,
63,
2384,
63,
1531,
8,
1531,
12,
859,
12,
1414,
63,
466,
534,
2764,
63,
2384,
735,
272,
340,
859,
14,
1162,
459,
5545,
418,
508,
283,
2764,
356,
267,
340,
283,
2384,
1255,
7,
440,
315,
1414,
26,
288,
1414,
847,
283,
1204,
2022,
7,
267,
11465,
275,
359,
1531,
61,
267,
2396,
275,
1255,
63,
4405,
8,
578,
12,
11465,
9,
272,
916,
859,
14,
1162,
459,
5545,
418,
508,
283,
7343,
1246,
356,
267,
11465,
275,
359,
1531,
61,
267,
2396,
275,
1255,
63,
4405,
8,
578,
12,
11465,
9,
339,
372,
2396,
421,
199,
318,
664,
63,
3266,
63,
466,
8,
3266,
304,
272,
340,
3217,
14,
4142,
1252,
2460,
360,
775,
735,
267,
372,
283,
20354,
7,
272,
916,
3217,
14,
4142,
1252,
2460,
360,
32458,
735,
267,
372,
283,
83,
433,
7,
272,
916,
3217,
14,
4142,
1252,
2460,
360,
1484,
735,
267,
372,
283,
23983,
7,
272,
916,
3217,
14,
4142,
1252,
2460,
360,
26255,
735,
267,
372,
283,
8110,
7,
272,
916,
3217,
14,
4142,
1252,
2460,
360,
2054,
735,
267,
372,
283,
8110,
7,
272,
916,
3217,
14,
4142,
1252,
2460,
360,
1512,
735,
267,
372,
283,
719,
2775,
7,
272,
587,
26,
267,
372,
283,
5187,
7,
421,
199,
318,
664,
63,
3266,
63,
632,
8,
3266,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
spanner888/madparts
|
export/detect.py
|
2
|
1146
|
# (c) 2013 Joost Yervante Damad <joost@damad.be>
# License: GPL
import eagle, kicad, madparts, kicad_old
MADPARTS = "madparts"
EAGLE = "eagle"
KICAD = "kicad"
KICAD_OLD = "kicad-old"
def detect(fn):
v = madparts.detect(fn)
if v is not None:
return (MADPARTS, v)
v = eagle.detect(fn)
if v is not None:
return (EAGLE, v)
v = kicad.detect(fn)
if v is not None:
return (KICAD, v)
v = kicad_old.detect(fn)
if v is not None:
return (KICAD_OLD, v)
raise Exception("Unknown file format")
def make_exporter_for(t, fn):
if t == EAGLE:
return eagle.Export(fn)
elif t == KICAD:
return kicad.Export(fn)
elif t == KICAD_OLD:
return kicad_old.Export(fn)
else:
raise Exception("Invalid export format")
def make_exporter(fn):
(t,_) = detect(fn)
return make_exporter_for(t, fn)
def make_importer(fn):
(t,_) = detect(fn)
if t == EAGLE:
return eagle.Import(fn)
elif t == KICAD:
return kicad.Import(fn)
elif t == KICAD_OLD:
return kicad_old.Import(fn)
elif t == MADPARTS:
return madparts.Import(fn) # for listing!
else:
raise Exception("Invalid export format")
|
gpl-3.0
|
[
3,
334,
67,
9,
6171,
7135,
941,
1488,
281,
86,
8949,
577,
455,
350,
665,
743,
941,
32,
68,
455,
350,
14,
1235,
30,
199,
3,
844,
26,
14629,
199,
199,
646,
325,
643,
274,
12,
1022,
530,
350,
12,
333,
350,
4181,
12,
1022,
530,
350,
63,
1753,
199,
199,
45,
1554,
14848,
51,
275,
298,
77,
350,
4181,
2,
199,
37,
1254,
906,
275,
298,
69,
643,
274,
2,
199,
43,
948,
1554,
275,
298,
75,
530,
350,
2,
199,
43,
948,
1554,
63,
5104,
275,
298,
75,
530,
350,
13,
1753,
2,
199,
199,
318,
9696,
8,
2324,
304,
523,
373,
275,
221,
333,
350,
4181,
14,
13552,
8,
2324,
9,
523,
340,
373,
365,
440,
488,
26,
272,
372,
334,
45,
1554,
14848,
51,
12,
373,
9,
523,
373,
275,
325,
643,
274,
14,
13552,
8,
2324,
9,
523,
340,
373,
365,
440,
488,
26,
272,
372,
334,
37,
1254,
906,
12,
373,
9,
523,
373,
275,
1022,
530,
350,
14,
13552,
8,
2324,
9,
523,
340,
373,
365,
440,
488,
26,
272,
372,
334,
43,
948,
1554,
12,
373,
9,
523,
373,
275,
1022,
530,
350,
63,
1753,
14,
13552,
8,
2324,
9,
523,
340,
373,
365,
440,
488,
26,
272,
372,
334,
43,
948,
1554,
63,
5104,
12,
373,
9,
523,
746,
2186,
480,
5912,
570,
1475,
531,
199,
199,
318,
1852,
63,
30305,
63,
509,
8,
84,
12,
4325,
304,
523,
340,
307,
508,
662,
1254,
906,
26,
272,
372,
325,
643,
274,
14,
11399,
8,
2324,
9,
523,
916,
307,
508,
1804,
948,
1554,
26,
272,
372,
1022,
530,
350,
14,
11399,
8,
2324,
9,
523,
916,
307,
508,
1804,
948,
1554,
63,
5104,
26,
272,
372,
1022,
530,
350,
63,
1753,
14,
11399,
8,
2324,
9,
523,
587,
26,
272,
746,
2186,
480,
3364,
4843,
1475,
531,
4388,
199,
318,
1852,
63,
30305,
8,
2324,
304,
523,
334,
84,
12,
4602,
275,
9696,
8,
2324,
9,
523,
372,
1852,
63,
30305,
63,
509,
8,
84,
12,
4325,
9,
421,
199,
318,
1852,
63,
12138,
8,
2324,
304,
257,
523,
334,
84,
12,
4602,
275,
9696,
8,
2324,
9,
523,
340,
307,
508,
662,
1254,
906,
26,
272,
372,
325,
643,
274,
14,
6295,
8,
2324,
9,
523,
916,
307,
508,
1804,
948,
1554,
26,
272,
372,
1022,
530,
350,
14,
6295,
8,
2324,
9,
523,
916,
307,
508,
1804,
948,
1554,
63,
5104,
26,
272,
372,
1022,
530,
350,
63,
1753,
14,
6295,
8,
2324,
9,
523,
916,
307,
508,
603,
1554,
14848,
51,
26,
272,
372,
333,
350,
4181,
14,
6295,
8,
2324,
9,
327,
367,
13778,
1,
523,
587,
26,
272,
746,
2186,
480,
3364,
4843,
1475,
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
] |
[
334,
67,
9,
6171,
7135,
941,
1488,
281,
86,
8949,
577,
455,
350,
665,
743,
941,
32,
68,
455,
350,
14,
1235,
30,
199,
3,
844,
26,
14629,
199,
199,
646,
325,
643,
274,
12,
1022,
530,
350,
12,
333,
350,
4181,
12,
1022,
530,
350,
63,
1753,
199,
199,
45,
1554,
14848,
51,
275,
298,
77,
350,
4181,
2,
199,
37,
1254,
906,
275,
298,
69,
643,
274,
2,
199,
43,
948,
1554,
275,
298,
75,
530,
350,
2,
199,
43,
948,
1554,
63,
5104,
275,
298,
75,
530,
350,
13,
1753,
2,
199,
199,
318,
9696,
8,
2324,
304,
523,
373,
275,
221,
333,
350,
4181,
14,
13552,
8,
2324,
9,
523,
340,
373,
365,
440,
488,
26,
272,
372,
334,
45,
1554,
14848,
51,
12,
373,
9,
523,
373,
275,
325,
643,
274,
14,
13552,
8,
2324,
9,
523,
340,
373,
365,
440,
488,
26,
272,
372,
334,
37,
1254,
906,
12,
373,
9,
523,
373,
275,
1022,
530,
350,
14,
13552,
8,
2324,
9,
523,
340,
373,
365,
440,
488,
26,
272,
372,
334,
43,
948,
1554,
12,
373,
9,
523,
373,
275,
1022,
530,
350,
63,
1753,
14,
13552,
8,
2324,
9,
523,
340,
373,
365,
440,
488,
26,
272,
372,
334,
43,
948,
1554,
63,
5104,
12,
373,
9,
523,
746,
2186,
480,
5912,
570,
1475,
531,
199,
199,
318,
1852,
63,
30305,
63,
509,
8,
84,
12,
4325,
304,
523,
340,
307,
508,
662,
1254,
906,
26,
272,
372,
325,
643,
274,
14,
11399,
8,
2324,
9,
523,
916,
307,
508,
1804,
948,
1554,
26,
272,
372,
1022,
530,
350,
14,
11399,
8,
2324,
9,
523,
916,
307,
508,
1804,
948,
1554,
63,
5104,
26,
272,
372,
1022,
530,
350,
63,
1753,
14,
11399,
8,
2324,
9,
523,
587,
26,
272,
746,
2186,
480,
3364,
4843,
1475,
531,
4388,
199,
318,
1852,
63,
30305,
8,
2324,
304,
523,
334,
84,
12,
4602,
275,
9696,
8,
2324,
9,
523,
372,
1852,
63,
30305,
63,
509,
8,
84,
12,
4325,
9,
421,
199,
318,
1852,
63,
12138,
8,
2324,
304,
257,
523,
334,
84,
12,
4602,
275,
9696,
8,
2324,
9,
523,
340,
307,
508,
662,
1254,
906,
26,
272,
372,
325,
643,
274,
14,
6295,
8,
2324,
9,
523,
916,
307,
508,
1804,
948,
1554,
26,
272,
372,
1022,
530,
350,
14,
6295,
8,
2324,
9,
523,
916,
307,
508,
1804,
948,
1554,
63,
5104,
26,
272,
372,
1022,
530,
350,
63,
1753,
14,
6295,
8,
2324,
9,
523,
916,
307,
508,
603,
1554,
14848,
51,
26,
272,
372,
333,
350,
4181,
14,
6295,
8,
2324,
9,
327,
367,
13778,
1,
523,
587,
26,
272,
746,
2186,
480,
3364,
4843,
1475,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
SUSE/azure-sdk-for-python
|
azure-mgmt-network/azure/mgmt/network/v2015_06_15/models/load_balancer.py
|
2
|
5896
|
# 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 .resource import Resource
class LoadBalancer(Resource):
"""LoadBalancer resource.
Variables are only populated by the server, and will be ignored when
sending a request.
:param id: Resource Identifier.
:type id: str
:ivar name: Resource name.
:vartype name: str
:ivar type: Resource type.
:vartype type: str
:param location: Resource location.
:type location: str
:param tags: Resource tags.
:type tags: dict
:param frontend_ip_configurations: Object representing the frontend IPs to
be used for the load balancer
:type frontend_ip_configurations: list of :class:`FrontendIPConfiguration
<azure.mgmt.network.v2015_06_15.models.FrontendIPConfiguration>`
:param backend_address_pools: Collection of backend address pools used by
a load balancer
:type backend_address_pools: list of :class:`BackendAddressPool
<azure.mgmt.network.v2015_06_15.models.BackendAddressPool>`
:param load_balancing_rules: Object collection representing the load
balancing rules Gets the provisioning
:type load_balancing_rules: list of :class:`LoadBalancingRule
<azure.mgmt.network.v2015_06_15.models.LoadBalancingRule>`
:param probes: Collection of probe objects used in the load balancer
:type probes: list of :class:`Probe
<azure.mgmt.network.v2015_06_15.models.Probe>`
:param inbound_nat_rules: Collection of inbound NAT Rules used by a load
balancer. Defining inbound NAT rules on your load balancer is mutually
exclusive with defining an inbound NAT pool. Inbound NAT pools are
referenced from virtual machine scale sets. NICs that are associated with
individual virtual machines cannot reference an Inbound NAT pool. They
have to reference individual inbound NAT rules.
:type inbound_nat_rules: list of :class:`InboundNatRule
<azure.mgmt.network.v2015_06_15.models.InboundNatRule>`
:param inbound_nat_pools: Defines an external port range for inbound NAT
to a single backend port on NICs associated with a load balancer. Inbound
NAT rules are created automatically for each NIC associated with the Load
Balancer using an external port from this range. Defining an Inbound NAT
pool on your Load Balancer is mutually exclusive with defining inbound Nat
rules. Inbound NAT pools are referenced from virtual machine scale sets.
NICs that are associated with individual virtual machines cannot reference
an inbound NAT pool. They have to reference individual inbound NAT rules.
:type inbound_nat_pools: list of :class:`InboundNatPool
<azure.mgmt.network.v2015_06_15.models.InboundNatPool>`
:param outbound_nat_rules: The outbound NAT rules.
:type outbound_nat_rules: list of :class:`OutboundNatRule
<azure.mgmt.network.v2015_06_15.models.OutboundNatRule>`
:param resource_guid: The resource GUID property of the load balancer
resource.
:type resource_guid: str
:param provisioning_state: Gets the provisioning state of the PublicIP
resource. Possible values are: 'Updating', 'Deleting', and 'Failed'.
:type provisioning_state: str
:param etag: A unique read-only string that changes whenever the resource
is updated.
:type etag: str
"""
_validation = {
'name': {'readonly': True},
'type': {'readonly': True},
}
_attribute_map = {
'id': {'key': 'id', 'type': 'str'},
'name': {'key': 'name', 'type': 'str'},
'type': {'key': 'type', 'type': 'str'},
'location': {'key': 'location', 'type': 'str'},
'tags': {'key': 'tags', 'type': '{str}'},
'frontend_ip_configurations': {'key': 'properties.frontendIPConfigurations', 'type': '[FrontendIPConfiguration]'},
'backend_address_pools': {'key': 'properties.backendAddressPools', 'type': '[BackendAddressPool]'},
'load_balancing_rules': {'key': 'properties.loadBalancingRules', 'type': '[LoadBalancingRule]'},
'probes': {'key': 'properties.probes', 'type': '[Probe]'},
'inbound_nat_rules': {'key': 'properties.inboundNatRules', 'type': '[InboundNatRule]'},
'inbound_nat_pools': {'key': 'properties.inboundNatPools', 'type': '[InboundNatPool]'},
'outbound_nat_rules': {'key': 'properties.outboundNatRules', 'type': '[OutboundNatRule]'},
'resource_guid': {'key': 'properties.resourceGuid', 'type': 'str'},
'provisioning_state': {'key': 'properties.provisioningState', 'type': 'str'},
'etag': {'key': 'etag', 'type': 'str'},
}
def __init__(self, id=None, location=None, tags=None, frontend_ip_configurations=None, backend_address_pools=None, load_balancing_rules=None, probes=None, inbound_nat_rules=None, inbound_nat_pools=None, outbound_nat_rules=None, resource_guid=None, provisioning_state=None, etag=None):
super(LoadBalancer, self).__init__(id=id, location=location, tags=tags)
self.frontend_ip_configurations = frontend_ip_configurations
self.backend_address_pools = backend_address_pools
self.load_balancing_rules = load_balancing_rules
self.probes = probes
self.inbound_nat_rules = inbound_nat_rules
self.inbound_nat_pools = inbound_nat_pools
self.outbound_nat_rules = outbound_nat_rules
self.resource_guid = resource_guid
self.provisioning_state = provisioning_state
self.etag = etag
|
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,
1275,
1927,
492,
7337,
421,
199,
533,
7190,
22249,
8,
4031,
304,
272,
408,
27560,
2073,
14,
339,
17198,
787,
1454,
16460,
701,
314,
1654,
12,
436,
911,
506,
5525,
1380,
272,
10209,
282,
1056,
14,
339,
520,
635,
1305,
26,
7337,
23285,
14,
272,
520,
466,
1305,
26,
620,
272,
520,
7725,
536,
26,
7337,
536,
14,
272,
520,
19729,
536,
26,
620,
272,
520,
7725,
730,
26,
7337,
730,
14,
272,
520,
19729,
730,
26,
620,
272,
520,
635,
2909,
26,
7337,
2909,
14,
272,
520,
466,
2909,
26,
620,
272,
520,
635,
3762,
26,
7337,
3762,
14,
272,
520,
466,
3762,
26,
1211,
272,
520,
635,
22523,
63,
711,
63,
10057,
26,
6935,
6144,
314,
22523,
30657,
370,
1362,
506,
1202,
367,
314,
2248,
17005,
272,
520,
466,
22523,
63,
711,
63,
10057,
26,
769,
402,
520,
533,
1705,
38,
11537,
1772,
5688,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
38,
11537,
1772,
5688,
8637,
272,
520,
635,
4865,
63,
1562,
63,
12406,
26,
18003,
402,
4865,
2287,
20092,
1202,
701,
1362,
282,
2248,
17005,
272,
520,
466,
4865,
63,
1562,
63,
12406,
26,
769,
402,
520,
533,
1705,
8447,
1476,
5453,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
8447,
1476,
5453,
8637,
272,
520,
635,
2248,
63,
30260,
63,
4423,
26,
6935,
3245,
6144,
314,
2248,
1362,
29300,
4713,
14509,
314,
20118,
272,
520,
466,
2248,
63,
30260,
63,
4423,
26,
769,
402,
520,
533,
1705,
6200,
13129,
15763,
5065,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
6200,
13129,
15763,
5065,
8637,
272,
520,
635,
5128,
397,
26,
18003,
402,
22362,
2251,
1202,
315,
314,
2248,
17005,
272,
520,
466,
5128,
397,
26,
769,
402,
520,
533,
1705,
16939,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
16939,
8637,
272,
520,
635,
30819,
63,
9468,
63,
4423,
26,
18003,
402,
30819,
31363,
24259,
1202,
701,
282,
2248,
1362,
17005,
14,
1487,
2408,
316,
30819,
31363,
4713,
641,
2195,
2248,
17005,
365,
16108,
1362,
13914,
543,
12669,
376,
30819,
31363,
4203,
14,
1010,
3556,
31363,
20092,
787,
1362,
11812,
687,
5791,
6844,
4666,
5951,
14,
31265,
83,
626,
787,
4568,
543,
1362,
8212,
5791,
20601,
3913,
3659,
376,
1010,
3556,
31363,
4203,
14,
9322,
1362,
1172,
370,
3659,
8212,
30819,
31363,
4713,
14,
272,
520,
466,
30819,
63,
9468,
63,
4423,
26,
769,
402,
520,
533,
1705,
607,
3556,
23604,
5065,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
607,
3556,
23604,
5065,
8637,
272,
520,
635,
30819,
63,
9468,
63,
12406,
26,
25022,
376,
5957,
1844,
1425,
367,
30819,
31363,
1362,
370,
282,
2849,
4865,
1844,
641,
31265,
83,
4568,
543,
282,
2248,
17005,
14,
1010,
3556,
1362,
31363,
4713,
787,
2737,
5847,
367,
1924,
31265,
4568,
543,
314,
7190,
1362,
23928,
7716,
1808,
376,
5957,
1844,
687,
642,
1425,
14,
1487,
2408,
316,
376,
1010,
3556,
31363,
1362,
4203,
641,
2195,
7190,
23928,
7716,
365,
16108,
13914,
543,
12669,
30819,
653,
292,
1362,
4713,
14,
1010,
3556,
31363,
20092,
787,
11812,
687,
5791,
6844,
4666,
5951,
14,
1362,
31265,
83,
626,
787,
4568,
543,
8212,
5791,
20601,
3913,
3659,
1362,
376,
30819,
31363,
4203,
14,
9322,
1172,
370,
3659,
8212,
30819,
31363,
4713,
14,
272,
520,
466,
30819,
63,
9468,
63,
12406,
26,
769,
402,
520,
533,
1705,
607,
3556,
23604,
5453,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
607,
3556,
23604,
5453,
8637,
272,
520,
635,
734,
3556,
63,
9468,
63,
4423,
26,
710,
734,
3556,
31363,
4713,
14,
272,
520,
466,
734,
3556,
63,
9468,
63,
4423,
26,
769,
402,
520,
533,
1705,
2204,
3556,
23604,
5065,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
2204,
3556,
23604,
5065,
8637,
272,
520,
635,
2073,
63,
9473,
26,
710,
2073,
21645,
3324,
402,
314,
2248,
17005,
1362,
2073,
14,
272,
520,
466,
2073,
63,
9473,
26,
620,
272,
520,
635,
20118,
63,
929,
26,
14509,
314,
20118,
1174,
402,
314,
1684,
1772,
1362,
2073,
14,
18558,
1338,
787,
26,
283,
24993,
297,
283,
22001,
297,
436,
283,
4276,
1370,
272,
520,
466,
20118,
63,
929,
26,
620,
272,
520,
635,
13677,
26,
437,
3747,
1586,
13,
2118,
1059,
626,
4493,
18119,
314,
2073,
1362,
365,
4588,
14,
272,
520,
466,
13677,
26,
620,
272,
408,
339,
485,
6136,
275,
469,
267,
283,
354,
356,
791,
6753,
356,
715,
1386,
267,
283,
466,
356,
791,
6753,
356,
715,
1386,
272,
789,
339,
485,
3215,
63,
1130,
275,
469,
267,
283,
344,
356,
791,
498,
356,
283,
344,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
354,
356,
791,
498,
356,
283,
354,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
466,
356,
791,
498,
356,
283,
466,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
1985,
356,
791,
498,
356,
283,
1985,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
2969,
356,
791,
498,
356,
283,
2969,
297,
283,
466,
356,
5041,
495,
93,
2267,
267,
283,
18062,
63,
711,
63,
10057,
356,
791,
498,
356,
283,
3282,
14,
18062,
1772,
25808,
297,
283,
466,
356,
6730,
38,
11537,
1772,
5688,
30375,
267,
283,
4620,
63,
1562,
63,
12406,
356,
791,
498,
356,
283,
3282,
14,
4620,
1476,
31633,
297,
283,
466,
356,
6730,
8447,
1476,
5453,
30375,
267,
283,
912,
63,
30260
] |
[
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,
1275,
1927,
492,
7337,
421,
199,
533,
7190,
22249,
8,
4031,
304,
272,
408,
27560,
2073,
14,
339,
17198,
787,
1454,
16460,
701,
314,
1654,
12,
436,
911,
506,
5525,
1380,
272,
10209,
282,
1056,
14,
339,
520,
635,
1305,
26,
7337,
23285,
14,
272,
520,
466,
1305,
26,
620,
272,
520,
7725,
536,
26,
7337,
536,
14,
272,
520,
19729,
536,
26,
620,
272,
520,
7725,
730,
26,
7337,
730,
14,
272,
520,
19729,
730,
26,
620,
272,
520,
635,
2909,
26,
7337,
2909,
14,
272,
520,
466,
2909,
26,
620,
272,
520,
635,
3762,
26,
7337,
3762,
14,
272,
520,
466,
3762,
26,
1211,
272,
520,
635,
22523,
63,
711,
63,
10057,
26,
6935,
6144,
314,
22523,
30657,
370,
1362,
506,
1202,
367,
314,
2248,
17005,
272,
520,
466,
22523,
63,
711,
63,
10057,
26,
769,
402,
520,
533,
1705,
38,
11537,
1772,
5688,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
38,
11537,
1772,
5688,
8637,
272,
520,
635,
4865,
63,
1562,
63,
12406,
26,
18003,
402,
4865,
2287,
20092,
1202,
701,
1362,
282,
2248,
17005,
272,
520,
466,
4865,
63,
1562,
63,
12406,
26,
769,
402,
520,
533,
1705,
8447,
1476,
5453,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
8447,
1476,
5453,
8637,
272,
520,
635,
2248,
63,
30260,
63,
4423,
26,
6935,
3245,
6144,
314,
2248,
1362,
29300,
4713,
14509,
314,
20118,
272,
520,
466,
2248,
63,
30260,
63,
4423,
26,
769,
402,
520,
533,
1705,
6200,
13129,
15763,
5065,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
6200,
13129,
15763,
5065,
8637,
272,
520,
635,
5128,
397,
26,
18003,
402,
22362,
2251,
1202,
315,
314,
2248,
17005,
272,
520,
466,
5128,
397,
26,
769,
402,
520,
533,
1705,
16939,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
16939,
8637,
272,
520,
635,
30819,
63,
9468,
63,
4423,
26,
18003,
402,
30819,
31363,
24259,
1202,
701,
282,
2248,
1362,
17005,
14,
1487,
2408,
316,
30819,
31363,
4713,
641,
2195,
2248,
17005,
365,
16108,
1362,
13914,
543,
12669,
376,
30819,
31363,
4203,
14,
1010,
3556,
31363,
20092,
787,
1362,
11812,
687,
5791,
6844,
4666,
5951,
14,
31265,
83,
626,
787,
4568,
543,
1362,
8212,
5791,
20601,
3913,
3659,
376,
1010,
3556,
31363,
4203,
14,
9322,
1362,
1172,
370,
3659,
8212,
30819,
31363,
4713,
14,
272,
520,
466,
30819,
63,
9468,
63,
4423,
26,
769,
402,
520,
533,
1705,
607,
3556,
23604,
5065,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
607,
3556,
23604,
5065,
8637,
272,
520,
635,
30819,
63,
9468,
63,
12406,
26,
25022,
376,
5957,
1844,
1425,
367,
30819,
31363,
1362,
370,
282,
2849,
4865,
1844,
641,
31265,
83,
4568,
543,
282,
2248,
17005,
14,
1010,
3556,
1362,
31363,
4713,
787,
2737,
5847,
367,
1924,
31265,
4568,
543,
314,
7190,
1362,
23928,
7716,
1808,
376,
5957,
1844,
687,
642,
1425,
14,
1487,
2408,
316,
376,
1010,
3556,
31363,
1362,
4203,
641,
2195,
7190,
23928,
7716,
365,
16108,
13914,
543,
12669,
30819,
653,
292,
1362,
4713,
14,
1010,
3556,
31363,
20092,
787,
11812,
687,
5791,
6844,
4666,
5951,
14,
1362,
31265,
83,
626,
787,
4568,
543,
8212,
5791,
20601,
3913,
3659,
1362,
376,
30819,
31363,
4203,
14,
9322,
1172,
370,
3659,
8212,
30819,
31363,
4713,
14,
272,
520,
466,
30819,
63,
9468,
63,
12406,
26,
769,
402,
520,
533,
1705,
607,
3556,
23604,
5453,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
607,
3556,
23604,
5453,
8637,
272,
520,
635,
734,
3556,
63,
9468,
63,
4423,
26,
710,
734,
3556,
31363,
4713,
14,
272,
520,
466,
734,
3556,
63,
9468,
63,
4423,
26,
769,
402,
520,
533,
1705,
2204,
3556,
23604,
5065,
1362,
665,
9078,
14,
9752,
14,
1200,
14,
86,
7806,
63,
1690,
63,
1046,
14,
992,
14,
2204,
3556,
23604,
5065,
8637,
272,
520,
635,
2073,
63,
9473,
26,
710,
2073,
21645,
3324,
402,
314,
2248,
17005,
1362,
2073,
14,
272,
520,
466,
2073,
63,
9473,
26,
620,
272,
520,
635,
20118,
63,
929,
26,
14509,
314,
20118,
1174,
402,
314,
1684,
1772,
1362,
2073,
14,
18558,
1338,
787,
26,
283,
24993,
297,
283,
22001,
297,
436,
283,
4276,
1370,
272,
520,
466,
20118,
63,
929,
26,
620,
272,
520,
635,
13677,
26,
437,
3747,
1586,
13,
2118,
1059,
626,
4493,
18119,
314,
2073,
1362,
365,
4588,
14,
272,
520,
466,
13677,
26,
620,
272,
408,
339,
485,
6136,
275,
469,
267,
283,
354,
356,
791,
6753,
356,
715,
1386,
267,
283,
466,
356,
791,
6753,
356,
715,
1386,
272,
789,
339,
485,
3215,
63,
1130,
275,
469,
267,
283,
344,
356,
791,
498,
356,
283,
344,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
354,
356,
791,
498,
356,
283,
354,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
466,
356,
791,
498,
356,
283,
466,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
1985,
356,
791,
498,
356,
283,
1985,
297,
283,
466,
356,
283,
495,
2267,
267,
283,
2969,
356,
791,
498,
356,
283,
2969,
297,
283,
466,
356,
5041,
495,
93,
2267,
267,
283,
18062,
63,
711,
63,
10057,
356,
791,
498,
356,
283,
3282,
14,
18062,
1772,
25808,
297,
283,
466,
356,
6730,
38,
11537,
1772,
5688,
30375,
267,
283,
4620,
63,
1562,
63,
12406,
356,
791,
498,
356,
283,
3282,
14,
4620,
1476,
31633,
297,
283,
466,
356,
6730,
8447,
1476,
5453,
30375,
267,
283,
912,
63,
30260,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
telwertowski/QGIS
|
python/plugins/processing/core/outputs.py
|
15
|
4537
|
# -*- coding: utf-8 -*-
"""
***************************************************************************
Output.py
---------------------
Date : August 2012
Copyright : (C) 2012 by Victor Olaya
Email : volayaf at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************
"""
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
__copyright__ = '(C) 2012, Victor Olaya'
import sys
from qgis.core import (QgsExpressionContext,
QgsExpressionContextUtils,
QgsExpression,
QgsExpressionContextScope,
QgsProject,
QgsSettings,
QgsVectorFileWriter,
QgsProcessingUtils,
QgsProcessingParameterDefinition,
QgsProcessingOutputRasterLayer,
QgsProcessingOutputVectorLayer,
QgsProcessingOutputMapLayer,
QgsProcessingOutputHtml,
QgsProcessingOutputNumber,
QgsProcessingOutputString,
QgsProcessingOutputBoolean,
QgsProcessingOutputFolder,
QgsProcessingOutputMultipleLayers)
def getOutputFromString(s):
try:
if "|" in s and s.startswith("Output"):
tokens = s.split("|")
params = [t if str(t) != "None" else None for t in tokens[1:]]
clazz = getattr(sys.modules[__name__], tokens[0])
return clazz(*params)
else:
tokens = s.split("=")
if not tokens[1].lower()[:len('output')] == 'output':
return None
name = tokens[0]
description = tokens[0]
token = tokens[1].strip()[len('output') + 1:]
out = None
if token.lower().strip().startswith('outputraster'):
out = QgsProcessingOutputRasterLayer(name, description)
elif token.lower().strip() == 'outputvector':
out = QgsProcessingOutputVectorLayer(name, description)
elif token.lower().strip() == 'outputlayer':
out = QgsProcessingOutputMapLayer(name, description)
elif token.lower().strip() == 'outputmultilayers':
out = QgsProcessingOutputMultipleLayers(name, description)
# elif token.lower().strip() == 'vector point':
# out = OutputVector(datatype=[dataobjects.TYPE_VECTOR_POINT])
# elif token.lower().strip() == 'vector line':
# out = OutputVector(datatype=[OutputVector.TYPE_VECTOR_LINE])
# elif token.lower().strip() == 'vector polygon':
# out = OutputVector(datatype=[OutputVector.TYPE_VECTOR_POLYGON])
# elif token.lower().strip().startswith('table'):
# out = OutputTable()
elif token.lower().strip().startswith('outputhtml'):
out = QgsProcessingOutputHtml(name, description)
# elif token.lower().strip().startswith('file'):
# out = OutputFile()
# ext = token.strip()[len('file') + 1:]
# if ext:
# out.ext = ext
elif token.lower().strip().startswith('outputfolder'):
out = QgsProcessingOutputFolder(name, description)
elif token.lower().strip().startswith('outputnumber'):
out = QgsProcessingOutputNumber(name, description)
elif token.lower().strip().startswith('outputstring'):
out = QgsProcessingOutputString(name, description)
elif token.lower().strip().startswith('outputboolean'):
out = QgsProcessingOutputBoolean(name, description)
# elif token.lower().strip().startswith('extent'):
# out = OutputExtent()
return out
except:
return None
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
7242,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
25298,
833,
6029,
272,
1898,
3322,
520,
334,
35,
9,
6029,
701,
6561,
630,
593,
817,
65,
272,
11426,
4483,
520,
5236,
1187,
2756,
737,
29712,
6308,
2414,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
2201,
630,
593,
817,
65,
7,
199,
363,
602,
363,
275,
283,
21640,
833,
6029,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6029,
12,
6561,
630,
593,
817,
65,
7,
199,
199,
646,
984,
199,
199,
504,
15640,
14,
1018,
492,
334,
7350,
9093,
2998,
12,
2432,
4888,
9093,
2998,
7535,
12,
2432,
4888,
9093,
12,
2432,
4888,
9093,
2998,
7812,
12,
2432,
4888,
4761,
12,
2432,
4888,
5268,
12,
2432,
4888,
3646,
28199,
12,
2432,
17214,
7535,
12,
2432,
23764,
10701,
12,
2432,
17214,
2959,
13284,
5003,
12,
2432,
17214,
2959,
18602,
12,
2432,
17214,
2959,
2956,
5003,
12,
2432,
17214,
2959,
12957,
12,
2432,
17214,
2959,
3259,
12,
2432,
17214,
2959,
1558,
12,
2432,
17214,
2959,
4082,
12,
2432,
17214,
2959,
7850,
12,
2432,
17214,
2959,
8433,
16862,
9,
421,
199,
318,
664,
2959,
7671,
8,
83,
304,
272,
862,
26,
267,
340,
15733,
2,
315,
308,
436,
308,
14,
2460,
480,
2959,
2349,
288,
4645,
275,
308,
14,
1294,
25795,
531,
288,
1862,
275,
359,
84,
340,
620,
8,
84,
9,
1137,
298,
403,
2,
587,
488,
367,
307,
315,
4645,
59,
17,
21316,
288,
6108,
4348,
275,
2519,
8,
1274,
14,
3112,
28894,
354,
363,
467,
4645,
59,
16,
566,
288,
372,
6108,
4348,
2031,
1162,
9,
267,
587,
26,
288,
4645,
275,
308,
14,
1294,
480,
23758,
288,
340,
440,
4645,
59,
17,
1055,
2325,
20523,
552,
360,
1199,
5440,
508,
283,
1199,
356,
355,
372,
488,
953,
536,
275,
4645,
59,
16,
61,
288,
1369,
275,
4645,
59,
16,
61,
953,
1526,
275,
4645,
59,
17,
1055,
1913,
3430,
552,
360,
1199,
358,
435,
413,
2938,
288,
734,
275,
488,
953,
340,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
1199,
20876,
735,
355,
734,
275,
17214,
2959,
13284,
5003,
8,
354,
12,
1369,
9,
288,
916,
1526,
14,
2325,
1252,
1913,
342,
508,
283,
1199,
4106,
356,
355,
734,
275,
17214,
2959,
18602,
8,
354,
12,
1369,
9,
288,
916,
1526,
14,
2325,
1252,
1913,
342,
508,
283,
1199,
1897,
356,
355,
734,
275,
17214,
2959,
2956,
5003,
8,
354,
12,
1369,
9,
288,
916,
1526,
14,
2325,
1252,
1913,
342,
508,
283,
1199,
3029,
4359,
356,
355,
734,
275,
17214,
2959,
8433,
16862,
8,
354,
12,
1369,
9,
199,
3,
3322,
916,
1526,
14,
2325,
1252,
1913,
342,
508,
283,
4106,
2376,
356,
199,
3,
4483,
734,
275,
7242,
3646,
8,
14184,
1524,
576,
1462,
14,
2711,
63,
2524,
1028,
726,
63,
7217,
566,
199,
3,
3322,
916,
1526,
14,
2325,
1252,
1913,
342,
508,
283,
4106,
1004,
356,
199,
3,
4483,
734,
275,
7242,
3646,
8,
14184,
1524,
2959,
3646,
14,
2711,
63,
2524,
1028,
726,
63,
6174,
566,
199,
3,
3322,
916,
1526,
14,
2325,
1252,
1913,
342,
508,
283,
4106,
17248,
356,
199,
3,
4483,
734,
275,
7242,
3646,
8,
14184,
1524,
2959,
3646,
14,
2711,
63,
2524,
1028,
726,
63,
23602,
566,
199,
3,
3322,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
1224,
735,
199,
3,
4483,
734,
275,
7242,
3186,
342,
288,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
548,
80,
762,
18866,
735,
355,
734,
275,
17214,
2959,
12957,
8,
354,
12,
1369,
9,
199,
3,
3322,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
493,
735,
199,
3,
4483,
734,
275,
7242,
1173,
342,
199,
3,
4483,
1599,
275,
1526,
14,
1913,
3430,
552,
360,
493,
358,
435,
413,
2938,
199,
3,
4483,
340,
1599,
26,
199,
3,
8540,
734,
14,
832,
275,
1599,
288,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
1199,
3741,
735,
355,
734,
275,
17214,
2959,
7850,
8,
354,
12,
1369,
9,
288,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
1199,
1955,
735,
355,
734,
275,
17214,
2959,
3259,
8,
354,
12,
1369,
9,
288,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
1199,
875,
735,
355,
734,
275,
17214,
2959,
1558,
8,
354,
12,
1369,
9,
288,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
1199,
4871,
735,
355,
734,
275,
17214,
2959,
4082,
8,
354,
12,
1369,
9,
199,
3,
3322,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
11599,
735,
199,
3,
4483,
734,
275,
7242,
19808,
342,
953,
372,
734,
272,
871,
26,
267,
372,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
17623,
272,
7242,
14,
647,
272,
10652,
9858,
272,
6148,
463,
520,
25298,
833,
6029,
272,
1898,
3322,
520,
334,
35,
9,
6029,
701,
6561,
630,
593,
817,
65,
272,
11426,
4483,
520,
5236,
1187,
2756,
737,
29712,
6308,
2414,
199,
17623,
199,
10,
17997,
627,
199,
10,
257,
961,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
221,
627,
199,
10,
257,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
221,
627,
199,
10,
257,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
258,
627,
199,
10,
257,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
15530,
627,
199,
10,
17997,
627,
199,
17623,
199,
624,
199,
199,
363,
2502,
363,
275,
283,
2201,
630,
593,
817,
65,
7,
199,
363,
602,
363,
275,
283,
21640,
833,
6029,
7,
199,
363,
7307,
363,
275,
8189,
35,
9,
6029,
12,
6561,
630,
593,
817,
65,
7,
199,
199,
646,
984,
199,
199,
504,
15640,
14,
1018,
492,
334,
7350,
9093,
2998,
12,
2432,
4888,
9093,
2998,
7535,
12,
2432,
4888,
9093,
12,
2432,
4888,
9093,
2998,
7812,
12,
2432,
4888,
4761,
12,
2432,
4888,
5268,
12,
2432,
4888,
3646,
28199,
12,
2432,
17214,
7535,
12,
2432,
23764,
10701,
12,
2432,
17214,
2959,
13284,
5003,
12,
2432,
17214,
2959,
18602,
12,
2432,
17214,
2959,
2956,
5003,
12,
2432,
17214,
2959,
12957,
12,
2432,
17214,
2959,
3259,
12,
2432,
17214,
2959,
1558,
12,
2432,
17214,
2959,
4082,
12,
2432,
17214,
2959,
7850,
12,
2432,
17214,
2959,
8433,
16862,
9,
421,
199,
318,
664,
2959,
7671,
8,
83,
304,
272,
862,
26,
267,
340,
15733,
2,
315,
308,
436,
308,
14,
2460,
480,
2959,
2349,
288,
4645,
275,
308,
14,
1294,
25795,
531,
288,
1862,
275,
359,
84,
340,
620,
8,
84,
9,
1137,
298,
403,
2,
587,
488,
367,
307,
315,
4645,
59,
17,
21316,
288,
6108,
4348,
275,
2519,
8,
1274,
14,
3112,
28894,
354,
363,
467,
4645,
59,
16,
566,
288,
372,
6108,
4348,
2031,
1162,
9,
267,
587,
26,
288,
4645,
275,
308,
14,
1294,
480,
23758,
288,
340,
440,
4645,
59,
17,
1055,
2325,
20523,
552,
360,
1199,
5440,
508,
283,
1199,
356,
355,
372,
488,
953,
536,
275,
4645,
59,
16,
61,
288,
1369,
275,
4645,
59,
16,
61,
953,
1526,
275,
4645,
59,
17,
1055,
1913,
3430,
552,
360,
1199,
358,
435,
413,
2938,
288,
734,
275,
488,
953,
340,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
1199,
20876,
735,
355,
734,
275,
17214,
2959,
13284,
5003,
8,
354,
12,
1369,
9,
288,
916,
1526,
14,
2325,
1252,
1913,
342,
508,
283,
1199,
4106,
356,
355,
734,
275,
17214,
2959,
18602,
8,
354,
12,
1369,
9,
288,
916,
1526,
14,
2325,
1252,
1913,
342,
508,
283,
1199,
1897,
356,
355,
734,
275,
17214,
2959,
2956,
5003,
8,
354,
12,
1369,
9,
288,
916,
1526,
14,
2325,
1252,
1913,
342,
508,
283,
1199,
3029,
4359,
356,
355,
734,
275,
17214,
2959,
8433,
16862,
8,
354,
12,
1369,
9,
199,
3,
3322,
916,
1526,
14,
2325,
1252,
1913,
342,
508,
283,
4106,
2376,
356,
199,
3,
4483,
734,
275,
7242,
3646,
8,
14184,
1524,
576,
1462,
14,
2711,
63,
2524,
1028,
726,
63,
7217,
566,
199,
3,
3322,
916,
1526,
14,
2325,
1252,
1913,
342,
508,
283,
4106,
1004,
356,
199,
3,
4483,
734,
275,
7242,
3646,
8,
14184,
1524,
2959,
3646,
14,
2711,
63,
2524,
1028,
726,
63,
6174,
566,
199,
3,
3322,
916,
1526,
14,
2325,
1252,
1913,
342,
508,
283,
4106,
17248,
356,
199,
3,
4483,
734,
275,
7242,
3646,
8,
14184,
1524,
2959,
3646,
14,
2711,
63,
2524,
1028,
726,
63,
23602,
566,
199,
3,
3322,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
1224,
735,
199,
3,
4483,
734,
275,
7242,
3186,
342,
288,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
548,
80,
762,
18866,
735,
355,
734,
275,
17214,
2959,
12957,
8,
354,
12,
1369,
9,
199,
3,
3322,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
493,
735,
199,
3,
4483,
734,
275,
7242,
1173,
342,
199,
3,
4483,
1599,
275,
1526,
14,
1913,
3430,
552,
360,
493,
358,
435,
413,
2938,
199,
3,
4483,
340,
1599,
26,
199,
3,
8540,
734,
14,
832,
275,
1599,
288,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
1199,
3741,
735,
355,
734,
275,
17214,
2959,
7850,
8,
354,
12,
1369,
9,
288,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
1199,
1955,
735,
355,
734,
275,
17214,
2959,
3259,
8,
354,
12,
1369,
9,
288,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
1199,
875,
735,
355,
734,
275,
17214,
2959,
1558,
8,
354,
12,
1369,
9,
288,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
1199,
4871,
735,
355,
734,
275,
17214,
2959,
4082,
8,
354,
12,
1369,
9,
199,
3,
3322,
916,
1526,
14,
2325,
1252,
1913,
1252,
2460,
360,
11599,
735,
199,
3,
4483,
734,
275,
7242,
19808,
342,
953,
372,
734,
272,
871,
26,
267,
372,
488,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jonathan-beard/edx-platform
|
cms/djangoapps/contentstore/migrations/0002_auto__del_field_videouploadconfig_status_whitelist.py
|
108
|
4442
|
# -*- coding: utf-8 -*-
import datetime
from south.db import db
from south.v2 import SchemaMigration
from django.db import models
class Migration(SchemaMigration):
def forwards(self, orm):
# Deleting field 'VideoUploadConfig.status_whitelist'
db.delete_column('contentstore_videouploadconfig', 'status_whitelist')
def backwards(self, orm):
# Adding field 'VideoUploadConfig.status_whitelist'
db.add_column('contentstore_videouploadconfig', 'status_whitelist',
self.gf('django.db.models.fields.TextField')(default='', blank=True),
keep_default=False)
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'contentstore.videouploadconfig': {
'Meta': {'object_name': 'VideoUploadConfig'},
'change_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'changed_by': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True', 'on_delete': 'models.PROTECT'}),
'enabled': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'profile_whitelist': ('django.db.models.fields.TextField', [], {'blank': 'True'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
}
}
complete_apps = ['contentstore']
|
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,
15920,
901,
283,
9166,
10301,
2028,
14,
1205,
63,
14189,
7,
267,
1592,
14,
1807,
63,
2301,
360,
28160,
63,
3722,
5064,
888,
297,
283,
1205,
63,
14189,
358,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
12934,
901,
283,
9166,
10301,
2028,
14,
1205,
63,
14189,
7,
267,
1592,
14,
525,
63,
2301,
360,
28160,
63,
3722,
5064,
888,
297,
283,
1205,
63,
14189,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
7533,
885,
4581,
4596,
29,
549,
395,
1993,
4215,
63,
885,
29,
797,
9,
2378,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1317,
63,
466,
363,
571,
63,
1302,
297,
283,
1317,
63,
466,
363,
1238,
297,
283,
11879,
18106,
283,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
283,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2473,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1216,
3071,
267,
1660,
267,
283,
28160,
14,
3722,
5064,
888,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
9166,
10301,
2028,
2267,
288,
283,
1461,
63,
602,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2495,
63,
2131,
63,
525,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2489,
63,
991,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6256,
283,
2307,
356,
283,
549,
297,
283,
265,
63,
1807,
356,
283,
992,
14,
29148,
1604,
288,
283,
3827,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
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,
2913,
63,
14189,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
297,
990,
791,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
10778,
14,
20735,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
354,
21099,
283,
3235,
63,
6314,
356,
9510
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2197,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
24765,
199,
504,
1639,
14,
697,
492,
1709,
421,
199,
533,
12090,
8,
24822,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
267,
327,
15920,
901,
283,
9166,
10301,
2028,
14,
1205,
63,
14189,
7,
267,
1592,
14,
1807,
63,
2301,
360,
28160,
63,
3722,
5064,
888,
297,
283,
1205,
63,
14189,
358,
2378,
347,
8552,
8,
277,
12,
9813,
304,
267,
327,
12934,
901,
283,
9166,
10301,
2028,
14,
1205,
63,
14189,
7,
267,
1592,
14,
525,
63,
2301,
360,
28160,
63,
3722,
5064,
888,
297,
283,
1205,
63,
14189,
297,
1993,
291,
14,
7102,
360,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
7533,
885,
4581,
4596,
29,
549,
395,
1993,
4215,
63,
885,
29,
797,
9,
2378,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1317,
63,
466,
363,
571,
63,
1302,
297,
283,
1317,
63,
466,
363,
1238,
297,
283,
11879,
18106,
283,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
283,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2473,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1216,
3071,
267,
1660,
267,
283,
28160,
14,
3722,
5064,
888,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
9166,
10301,
2028,
2267,
288,
283,
1461,
63,
602,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2495,
63,
2131,
63,
525,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2489,
63,
991,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
1899,
6256,
283,
2307,
356,
283,
549,
297,
283,
265,
63,
1807,
356,
283,
992,
14,
29148,
1604,
288,
283,
3827,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
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,
2913,
63,
14189,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
6254,
297,
990,
791,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
10778,
14,
20735,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
354,
21099,
283,
3235,
63,
6314,
356,
9510,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
weilu/Hadoop-Resource-Aware-Scheduler
|
common/contrib/hod/support/logcondense.py
|
8
|
8108
|
#!/bin/sh
#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.
""":"
work_dir=$(dirname $0)
base_name=$(basename $0)
cd $work_dir
if [ $HOD_PYTHON_HOME ]; then
exec $HOD_PYTHON_HOME -OO -u $base_name ${1+"$@"}
elif [ -e /usr/bin/python ]; then
exec /usr/bin/python -OO -u $base_name ${1+"$@"}
elif [ -e /usr/local/bin/python ]; then
exec /usr/local/bin/python -OO -u $base_name ${1+"$@"}
else
exec python -OO -u $base_name ${1+"$@"}
fi
":"""
from os import popen3
import os, sys
import re
import time
from datetime import datetime
from optparse import OptionParser
myName = os.path.basename(sys.argv[0])
myName = re.sub(".*/", "", myName)
reVersion = re.compile(".*(\d+_\d+).*")
VERSION = '$HeadURL: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-0.21/src/contrib/hod/support/logcondense.py $'
reMatch = reVersion.match(VERSION)
if reMatch:
VERSION = reMatch.group(1)
VERSION = re.sub("_", ".", VERSION)
else:
VERSION = 'DEV'
options = ( {'short' : "-p",
'long' : "--package",
'type' : "string",
'action' : "store",
'dest' : "package",
'metavar' : " ",
'default' : 'hadoop',
'help' : "Bin file for hadoop"},
{'short' : "-d",
'long' : "--days",
'type' : "int",
'action' : "store",
'dest' : "days",
'metavar' : " ",
'default' : 7,
'help' : "Number of days before logs are deleted"},
{'short' : "-c",
'long' : "--config",
'type' : "string",
'action' : "store",
'dest' : "config",
'metavar' : " ",
'default' : None,
'help' : "config directory for hadoop"},
{'short' : "-l",
'long' : "--logs",
'type' : "string",
'action' : "store",
'dest' : "log",
'metavar' : " ",
'default' : "/user",
'help' : "directory prefix under which logs are stored per user"},
{'short' : "-n",
'long' : "--dynamicdfs",
'type' : "string",
'action' : "store",
'dest' : "dynamicdfs",
'metavar' : " ",
'default' : "false",
'help' : "'true', if the cluster is used to bring up dynamic dfs clusters, 'false' otherwise"},
{'short' : "-r",
'long' : "--retain-master-logs",
'type' : "string",
'action' : "store",
'dest' : "retain_masters_logs",
'metavar' : " ",
'default' : "false",
'help' : "'true' if the logs of the masters(jobtracker and namenode if '--dynamicdfs' is set) have to be retained, 'false' if everything has to be removed"}
)
def getDfsCommand(options, args):
if (options.config == None):
cmd = options.package + " " + "dfs " + args
else:
cmd = options.package + " " + "--config " + options.config + " dfs " + args
return cmd
def runcondense():
import shutil
options = process_args()
# if the retain-master-logs option is true, we do not delete
# the jobtracker, and in case of dynamic dfs, namenode logs.
# else, we delete the entire job directory, as nothing other
# than master and slave log files should be under the hod-logs
# directory.
filteredNames = [] # logs to skip while deleting
deletedNamePrefixes = [] # logs prefixes to delete.
if options.retain_masters_logs == 'true':
filteredNames = ['jobtracker']
deletedNamePrefixes = ['*-tasktracker-*']
if options.dynamicdfs == 'true' and options.retain_masters_logs == 'true':
filteredNames.append('namenode')
deletedNamePrefixes.append('*-datanode-*')
filepath = '%s/\*/hod-logs/' % (options.log)
cmd = getDfsCommand(options, "-lsr " + filepath)
(stdin, stdout, stderr) = popen3(cmd)
lastjobid = 'none'
toPurge = { }
for line in stdout:
try:
m = re.match("^.*\s(.*)\n$", line)
filename = m.group(1)
# file name format: <prefix>/<user>/hod-logs/<jobid>/[0-9]*-[jobtracker|tasktracker|datanode|namenode|]-hostname-YYYYMMDDtime-random.tar.gz
# first strip prefix:
if filename.startswith(options.log):
filename = filename[len(options.log):]
if not filename.startswith('/'):
filename = '/' + filename
else:
continue
# Now get other details from filename.
k = re.match("/(.*)/hod-logs/(.*)/.*-.*-([0-9][0-9][0-9][0-9])([0-9][0-9])([0-9][0-9]).*$", filename)
if k:
username = k.group(1)
jobid = k.group(2)
datetimefile = datetime(int(k.group(3)), int(k.group(4)), int(k.group(5)))
datetimenow = datetime.utcnow()
diff = datetimenow - datetimefile
filedate = k.group(3) + k.group(4) + k.group(5)
newdate = datetimenow.strftime("%Y%m%d")
print "%s %s %s %d" % (filename, filedate, newdate, diff.days)
# if the cluster is used to bring up dynamic dfs, we must also leave NameNode logs.
foundFilteredName = False
for name in filteredNames:
if filename.find(name) >= 0:
foundFilteredName = True
break
if foundFilteredName:
continue
if (diff.days > options.days):
desttodel = filename
if not toPurge.has_key(jobid):
toPurge[jobid] = options.log.rstrip("/") + "/" + username + "/hod-logs/" + jobid
except Exception, e:
print >> sys.stderr, e
for job in toPurge.keys():
try:
if options.retain_masters_logs == 'false':
# delete entire job-id directory.
cmd = getDfsCommand(options, "-rmr " + toPurge[job])
print cmd
ret = os.system(cmd)
if (ret != 0):
print >> sys.stderr, "Command failed to delete job directory " + cmd
else:
# delete only the prefixes we're interested in.
for prefix in deletedNamePrefixes:
cmd = getDfsCommand(options, "-rm " + toPurge[job] + '/' + prefix)
print cmd
ret = os.system(cmd)
if (ret != 0):
print >> sys.stderr, "Command failed to delete file " + cmd
except Exception, e:
print >> sys.stderr, e
def process_args():
global options, myName, VERSION
usage = "usage: %s <ARGS>" % (myName)
version = "%s %s" % (myName, VERSION)
argParser = OptionParser(usage=usage, version=VERSION)
for option_element in options:
argParser.add_option(option_element['short'], option_element['long'],
type=option_element['type'], action=option_element['action'],
dest=option_element['dest'], default=option_element['default'],
metavar=option_element['metavar'], help=option_element['help'])
(parsedOptions, args) = argParser.parse_args()
if not os.path.exists(parsedOptions.package):
argParser.error("Could not find path to hadoop binary: %s" % parsedOptions.package)
if not os.path.exists(parsedOptions.config):
argParser.error("Could not find config: %s" % parsedOptions.config)
if parsedOptions.days <= 0:
argParser.error("Invalid number of days specified, must be > 0: %s" % parsedOptions.config)
if parsedOptions.dynamicdfs!='true' and parsedOptions.dynamicdfs!='false':
argParser.error("Invalid option for dynamicdfs, must be true or false: %s" % parsedOptions.dynamicdfs)
return parsedOptions
if __name__ == '__main__':
runcondense()
|
apache-2.0
|
[
3381,
1393,
15,
609,
199,
199,
3,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
3,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
23662,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
1045,
314,
844,
14,
221,
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,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
3097,
1298,
1334,
314,
844,
14,
199,
341,
5122,
199,
800,
63,
694,
29,
6629,
3475,
2672,
16,
9,
199,
1095,
63,
354,
29,
6629,
4846,
2672,
16,
9,
199,
2866,
2672,
800,
63,
694,
199,
199,
692,
359,
2672,
2979,
36,
63,
11720,
63,
9524,
1622,
27,
2066,
199,
1628,
2672,
2979,
36,
63,
11720,
63,
9524,
446,
5757,
446,
85,
2672,
1095,
63,
354,
10839,
17,
5207,
4,
32,
3570,
199,
4164,
359,
446,
69,
1182,
2647,
15,
1393,
15,
1548,
1622,
27,
2066,
199,
1628,
1182,
2647,
15,
1393,
15,
1548,
446,
5757,
446,
85,
2672,
1095,
63,
354,
10839,
17,
5207,
4,
32,
3570,
199,
4164,
359,
446,
69,
1182,
2647,
15,
1832,
15,
1393,
15,
1548,
1622,
27,
2066,
199,
1628,
1182,
2647,
15,
1832,
15,
1393,
15,
1548,
446,
5757,
446,
85,
2672,
1095,
63,
354,
10839,
17,
5207,
4,
32,
3570,
199,
2836,
199,
1628,
2366,
446,
5757,
446,
85,
2672,
1095,
63,
354,
10839,
17,
5207,
4,
32,
3570,
199,
329,
199,
582,
624,
4671,
755,
199,
504,
747,
492,
17758,
19,
199,
646,
747,
12,
984,
199,
646,
295,
199,
646,
900,
199,
504,
2197,
492,
2197,
199,
504,
8691,
492,
13491,
199,
199,
1662,
985,
3515,
275,
747,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
566,
199,
1662,
985,
3515,
275,
295,
14,
954,
480,
2795,
10665,
4873,
3002,
985,
9,
199,
199,
264,
3353,
275,
295,
14,
2014,
480,
2795,
2961,
68,
6416,
60,
68,
11,
680,
10,
531,
199,
199,
4612,
275,
4505,
11664,
2632,
26,
4178,
921,
6836,
14,
3796,
14,
1308,
15,
11857,
15,
29551,
15,
15449,
15,
2330,
15,
16896,
15,
4694,
13,
16,
14,
2025,
15,
2164,
15,
2828,
15,
72,
364,
15,
4058,
15,
793,
388,
7253,
14,
647,
2672,
7,
199,
199,
264,
4486,
275,
295,
3353,
14,
1431,
8,
4612,
9,
199,
692,
295,
4486,
26,
272,
15945,
275,
295,
4486,
14,
923,
8,
17,
9,
272,
15945,
275,
295,
14,
954,
11008,
401,
3680,
401,
15945,
9,
199,
2836,
26,
272,
15945,
275,
283,
13260,
7,
199,
199,
1419,
275,
334,
791,
3612,
7,
257,
520,
3905,
80,
401,
1467,
283,
2809,
7,
259,
520,
4320,
2491,
401,
1467,
283,
466,
7,
259,
520,
298,
875,
401,
1467,
283,
1287,
7,
221,
520,
298,
1617,
401,
1467,
283,
2614,
7,
259,
520,
298,
2491,
401,
1467,
283,
23303,
7,
520,
298,
3872,
1467,
283,
885,
7,
520,
283,
15449,
297,
1467,
283,
3437,
7,
259,
520,
298,
13394,
570,
367,
29252,
6018,
2742,
259,
791,
3612,
7,
257,
520,
3905,
68,
401,
507,
258,
283,
2809,
7,
259,
520,
4320,
4899,
401,
507,
258,
283,
466,
7,
259,
520,
298,
442,
401,
507,
258,
283,
1287,
7,
221,
520,
298,
1617,
401,
507,
258,
283,
2614,
7,
259,
520,
298,
4899,
401,
507,
258,
283,
23303,
7,
520,
298,
3872,
507,
258,
283,
885,
7,
520,
1520,
12,
507,
258,
283,
3437,
7,
259,
520,
298,
3259,
402,
7609,
2544,
9610,
787,
5463,
6018,
507,
258,
6722,
791,
3612,
7,
257,
520,
3905,
67,
401,
507,
258,
283,
2809,
7,
259,
520,
4320,
888,
401,
507,
258,
283,
466,
7,
259,
520,
298,
875,
401,
507,
258,
283,
1287,
7,
221,
520,
298,
1617,
401,
507,
258,
283,
2614,
7,
259,
520,
298,
888,
401,
507,
258,
283,
23303,
7,
520,
298,
3872,
507,
258,
283,
885,
7,
520,
488,
12,
507,
258,
283,
3437,
7,
259,
520,
298,
888,
2082,
367,
29252,
6018,
507,
258,
6722,
791,
3612,
7,
257,
520,
3905,
76,
401,
507,
258,
283,
2809,
7,
259,
520,
4320,
7270,
401,
507,
258,
283,
466,
7,
259,
520,
298,
875,
401,
507,
258,
283,
1287,
7,
221,
520,
298,
1617,
401,
507,
258,
283,
2614,
7,
259,
520,
298,
793,
401,
507,
258,
283,
23303,
7,
520,
298,
3872,
507,
258,
283,
885,
7,
520,
3286,
751,
401,
507,
258,
283,
3437,
7,
259,
520,
298,
3619,
2403,
1334,
1314,
9610,
787,
5489,
1126,
922,
6018,
2742,
259,
791,
3612,
7,
257,
520,
3905,
78,
401,
507,
258,
283,
2809,
7,
259,
520,
4320,
7764,
10434,
401,
507,
258,
283,
466,
7,
259,
520,
298,
875,
401,
507,
258,
283,
1287,
7,
221,
520,
298,
1617,
401,
507,
258,
283,
2614,
7,
259,
520,
298,
7764,
10434,
401,
507,
258,
283,
23303,
7,
520,
298,
3872,
507,
258,
283,
885,
7,
520,
298,
3910,
401,
507,
258,
283,
3437,
7,
259,
520,
3546,
2052,
297,
340,
314,
4350,
365,
1202,
370,
330,
5985,
1536,
8336,
366,
2319,
13865,
12,
283,
3910,
7,
4257,
6018,
2049,
6722,
791,
3612,
7,
257,
520,
3905,
82,
401,
507,
258,
283,
2809,
7,
259,
520,
4320,
264,
877,
13,
4133,
13,
7270,
401,
507,
258,
283,
466,
7,
259,
520,
298,
875,
401,
507,
258,
283,
1287,
7,
221,
520,
298,
1617,
401,
507,
258,
283,
2614,
7,
259,
520,
298,
264,
877,
63,
5892,
878,
63,
7270,
401,
507,
258,
283,
23303,
7,
520,
298,
3872,
507,
258,
283,
885,
7,
520,
298
] |
[
1393,
15,
609,
199,
199,
3,
31661,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
199,
3,
269,
1655,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
199,
3,
16832,
543,
642,
1736,
367,
4722,
2556,
199,
3,
1135,
1005,
316,
4248,
12715,
14,
221,
710,
14857,
12378,
642,
570,
199,
3,
475,
1265,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
199,
23662,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
199,
3,
1045,
314,
844,
14,
221,
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,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
3097,
1298,
1334,
314,
844,
14,
199,
341,
5122,
199,
800,
63,
694,
29,
6629,
3475,
2672,
16,
9,
199,
1095,
63,
354,
29,
6629,
4846,
2672,
16,
9,
199,
2866,
2672,
800,
63,
694,
199,
199,
692,
359,
2672,
2979,
36,
63,
11720,
63,
9524,
1622,
27,
2066,
199,
1628,
2672,
2979,
36,
63,
11720,
63,
9524,
446,
5757,
446,
85,
2672,
1095,
63,
354,
10839,
17,
5207,
4,
32,
3570,
199,
4164,
359,
446,
69,
1182,
2647,
15,
1393,
15,
1548,
1622,
27,
2066,
199,
1628,
1182,
2647,
15,
1393,
15,
1548,
446,
5757,
446,
85,
2672,
1095,
63,
354,
10839,
17,
5207,
4,
32,
3570,
199,
4164,
359,
446,
69,
1182,
2647,
15,
1832,
15,
1393,
15,
1548,
1622,
27,
2066,
199,
1628,
1182,
2647,
15,
1832,
15,
1393,
15,
1548,
446,
5757,
446,
85,
2672,
1095,
63,
354,
10839,
17,
5207,
4,
32,
3570,
199,
2836,
199,
1628,
2366,
446,
5757,
446,
85,
2672,
1095,
63,
354,
10839,
17,
5207,
4,
32,
3570,
199,
329,
199,
582,
624,
4671,
755,
199,
504,
747,
492,
17758,
19,
199,
646,
747,
12,
984,
199,
646,
295,
199,
646,
900,
199,
504,
2197,
492,
2197,
199,
504,
8691,
492,
13491,
199,
199,
1662,
985,
3515,
275,
747,
14,
515,
14,
4846,
8,
1274,
14,
3020,
59,
16,
566,
199,
1662,
985,
3515,
275,
295,
14,
954,
480,
2795,
10665,
4873,
3002,
985,
9,
199,
199,
264,
3353,
275,
295,
14,
2014,
480,
2795,
2961,
68,
6416,
60,
68,
11,
680,
10,
531,
199,
199,
4612,
275,
4505,
11664,
2632,
26,
4178,
921,
6836,
14,
3796,
14,
1308,
15,
11857,
15,
29551,
15,
15449,
15,
2330,
15,
16896,
15,
4694,
13,
16,
14,
2025,
15,
2164,
15,
2828,
15,
72,
364,
15,
4058,
15,
793,
388,
7253,
14,
647,
2672,
7,
199,
199,
264,
4486,
275,
295,
3353,
14,
1431,
8,
4612,
9,
199,
692,
295,
4486,
26,
272,
15945,
275,
295,
4486,
14,
923,
8,
17,
9,
272,
15945,
275,
295,
14,
954,
11008,
401,
3680,
401,
15945,
9,
199,
2836,
26,
272,
15945,
275,
283,
13260,
7,
199,
199,
1419,
275,
334,
791,
3612,
7,
257,
520,
3905,
80,
401,
1467,
283,
2809,
7,
259,
520,
4320,
2491,
401,
1467,
283,
466,
7,
259,
520,
298,
875,
401,
1467,
283,
1287,
7,
221,
520,
298,
1617,
401,
1467,
283,
2614,
7,
259,
520,
298,
2491,
401,
1467,
283,
23303,
7,
520,
298,
3872,
1467,
283,
885,
7,
520,
283,
15449,
297,
1467,
283,
3437,
7,
259,
520,
298,
13394,
570,
367,
29252,
6018,
2742,
259,
791,
3612,
7,
257,
520,
3905,
68,
401,
507,
258,
283,
2809,
7,
259,
520,
4320,
4899,
401,
507,
258,
283,
466,
7,
259,
520,
298,
442,
401,
507,
258,
283,
1287,
7,
221,
520,
298,
1617,
401,
507,
258,
283,
2614,
7,
259,
520,
298,
4899,
401,
507,
258,
283,
23303,
7,
520,
298,
3872,
507,
258,
283,
885,
7,
520,
1520,
12,
507,
258,
283,
3437,
7,
259,
520,
298,
3259,
402,
7609,
2544,
9610,
787,
5463,
6018,
507,
258,
6722,
791,
3612,
7,
257,
520,
3905,
67,
401,
507,
258,
283,
2809,
7,
259,
520,
4320,
888,
401,
507,
258,
283,
466,
7,
259,
520,
298,
875,
401,
507,
258,
283,
1287,
7,
221,
520,
298,
1617,
401,
507,
258,
283,
2614,
7,
259,
520,
298,
888,
401,
507,
258,
283,
23303,
7,
520,
298,
3872,
507,
258,
283,
885,
7,
520,
488,
12,
507,
258,
283,
3437,
7,
259,
520,
298,
888,
2082,
367,
29252,
6018,
507,
258,
6722,
791,
3612,
7,
257,
520,
3905,
76,
401,
507,
258,
283,
2809,
7,
259,
520,
4320,
7270,
401,
507,
258,
283,
466,
7,
259,
520,
298,
875,
401,
507,
258,
283,
1287,
7,
221,
520,
298,
1617,
401,
507,
258,
283,
2614,
7,
259,
520,
298,
793,
401,
507,
258,
283,
23303,
7,
520,
298,
3872,
507,
258,
283,
885,
7,
520,
3286,
751,
401,
507,
258,
283,
3437,
7,
259,
520,
298,
3619,
2403,
1334,
1314,
9610,
787,
5489,
1126,
922,
6018,
2742,
259,
791,
3612,
7,
257,
520,
3905,
78,
401,
507,
258,
283,
2809,
7,
259,
520,
4320,
7764,
10434,
401,
507,
258,
283,
466,
7,
259,
520,
298,
875,
401,
507,
258,
283,
1287,
7,
221,
520,
298,
1617,
401,
507,
258,
283,
2614,
7,
259,
520,
298,
7764,
10434,
401,
507,
258,
283,
23303,
7,
520,
298,
3872,
507,
258,
283,
885,
7,
520,
298,
3910,
401,
507,
258,
283,
3437,
7,
259,
520,
3546,
2052,
297,
340,
314,
4350,
365,
1202,
370,
330,
5985,
1536,
8336,
366,
2319,
13865,
12,
283,
3910,
7,
4257,
6018,
2049,
6722,
791,
3612,
7,
257,
520,
3905,
82,
401,
507,
258,
283,
2809,
7,
259,
520,
4320,
264,
877,
13,
4133,
13,
7270,
401,
507,
258,
283,
466,
7,
259,
520,
298,
875,
401,
507,
258,
283,
1287,
7,
221,
520,
298,
1617,
401,
507,
258,
283,
2614,
7,
259,
520,
298,
264,
877,
63,
5892,
878,
63,
7270,
401,
507,
258,
283,
23303,
7,
520,
298,
3872,
507,
258,
283,
885,
7,
520,
298,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
doomsterinc/odoo
|
addons/mrp/product.py
|
180
|
4590
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, osv
class product_template(osv.osv):
_inherit = "product.template"
def _bom_orders_count(self, cr, uid, ids, field_name, arg, context=None):
Bom = self.pool('mrp.bom')
res = {}
for product_tmpl_id in ids:
nb = Bom.search_count(cr, uid, [('product_tmpl_id', '=', product_tmpl_id)], context=context)
res[product_tmpl_id] = {
'bom_count': nb,
}
return res
def _bom_orders_count_mo(self, cr, uid, ids, name, arg, context=None):
res = {}
for product_tmpl_id in self.browse(cr, uid, ids):
res[product_tmpl_id.id] = sum([p.mo_count for p in product_tmpl_id.product_variant_ids])
return res
_columns = {
'bom_ids': fields.one2many('mrp.bom', 'product_tmpl_id','Bill of Materials'),
'bom_count': fields.function(_bom_orders_count, string='# Bill of Material', type='integer', multi="_bom_order_count"),
'mo_count': fields.function(_bom_orders_count_mo, string='# Manufacturing Orders', type='integer'),
'produce_delay': fields.float('Manufacturing Lead Time', help="Average delay in days to produce this product. In the case of multi-level BOM, the manufacturing lead times of the components will be added."),
'track_production': fields.boolean('Track Manufacturing Lots', help="Forces to specify a Serial Number for all moves containing this product and generated by a Manufacturing Order"),
}
_defaults = {
'produce_delay': 1,
}
def action_view_mos(self, cr, uid, ids, context=None):
products = self._get_products(cr, uid, ids, context=context)
result = self._get_act_window_dict(cr, uid, 'mrp.act_product_mrp_production', context=context)
if len(ids) == 1 and len(products) == 1:
result['context'] = "{'default_product_id': " + str(products[0]) + ", 'search_default_product_id': " + str(products[0]) + "}"
else:
result['domain'] = "[('product_id','in',[" + ','.join(map(str, products)) + "])]"
result['context'] = "{}"
return result
class product_product(osv.osv):
_inherit = "product.product"
def _bom_orders_count(self, cr, uid, ids, field_name, arg, context=None):
Production = self.pool('mrp.production')
res = {}
for product_id in ids:
res[product_id] = Production.search_count(cr,uid, [('product_id', '=', product_id)], context=context)
return res
_columns = {
'mo_count': fields.function(_bom_orders_count, string='# Manufacturing Orders', type='integer'),
}
def action_view_bom(self, cr, uid, ids, context=None):
tmpl_obj = self.pool.get("product.template")
products = set()
for product in self.browse(cr, uid, ids, context=context):
products.add(product.product_tmpl_id.id)
result = tmpl_obj._get_act_window_dict(cr, uid, 'mrp.product_open_bom', context=context)
# bom specific to this variant or global to template
domain = [
'|',
('product_id', 'in', ids),
'&',
('product_id', '=', False),
('product_tmpl_id', 'in', list(products)),
]
result['context'] = "{'default_product_id': active_id, 'search_default_product_id': active_id, 'default_product_tmpl_id': %s}" % (len(products) and products.pop() or 'False')
result['domain'] = str(domain)
return result
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
421,
199,
533,
3336,
63,
1160,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
298,
2558,
14,
1160,
2,
272,
347,
485,
16302,
63,
14387,
63,
835,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
12,
1067,
29,
403,
304,
267,
699,
676,
275,
291,
14,
2293,
360,
17058,
14,
16302,
358,
267,
522,
275,
1052,
267,
367,
3336,
63,
11510,
63,
344,
315,
2762,
26,
288,
8526,
275,
699,
676,
14,
1733,
63,
835,
8,
1556,
12,
1747,
12,
4274,
2558,
63,
11510,
63,
344,
297,
6291,
3336,
63,
11510,
63,
344,
4360,
1067,
29,
1100,
9,
288,
522,
59,
2558,
63,
11510,
63,
344,
61,
275,
469,
355,
283,
16302,
63,
835,
356,
8526,
12,
288,
789,
267,
372,
522,
339,
347,
485,
16302,
63,
14387,
63,
835,
63,
573,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1680,
12,
1067,
29,
403,
304,
267,
522,
275,
1052,
267,
367,
3336,
63,
11510,
63,
344,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
304,
288,
522,
59,
2558,
63,
11510,
63,
344,
14,
344,
61,
275,
3089,
779,
80,
14,
573,
63,
835,
367,
299,
315,
3336,
63,
11510,
63,
344,
14,
2558,
63,
8759,
63,
1580,
566,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
16302,
63,
1580,
356,
1504,
14,
368,
18,
3479,
360,
17058,
14,
16302,
297,
283,
2558,
63,
11510,
63,
344,
1673,
34,
778,
402,
26570,
83,
659,
267,
283,
16302,
63,
835,
356,
1504,
14,
1593,
1547,
16302,
63,
14387,
63,
835,
12,
1059,
26431,
699,
778,
402,
26570,
297,
730,
534,
4115,
297,
3510,
19667,
16302,
63,
1648,
63,
835,
1288,
267,
283,
573,
63,
835,
356,
1504,
14,
1593,
1547,
16302,
63,
14387,
63,
835,
63,
573,
12,
1059,
26431,
4688,
7415,
319,
4039,
4236,
7735,
297,
730,
534,
4115,
659,
267,
283,
7832,
63,
5814,
356,
1504,
14,
1609,
360,
2395,
7415,
319,
4039,
7005,
350,
4703,
297,
1720,
628,
17400,
7339,
315,
7609,
370,
7389,
642,
3336,
14,
1010,
314,
1930,
402,
3510,
13,
1896,
17720,
12,
314,
2169,
7415,
319,
4039,
12690,
5431,
402,
314,
7323,
911,
506,
3483,
7651,
267,
283,
3885,
63,
10777,
356,
1504,
14,
4871,
360,
7927,
4688,
7415,
319,
4039,
491,
16673,
297,
1720,
628,
1858,
823,
370,
4165,
282,
11973,
4860,
367,
1006,
14569,
3035,
642,
3336,
436,
4046,
701,
282,
4688,
7415,
319,
4039,
9240,
1288,
272,
789,
339,
485,
4322,
275,
469,
267,
283,
7832,
63,
5814,
356,
413,
12,
272,
789,
17635,
347,
1595,
63,
1345,
63,
16908,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
7585,
275,
291,
423,
362,
63,
13336,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
267,
754,
275,
291,
423,
362,
63,
2442,
63,
3806,
63,
807,
8,
1556,
12,
1747,
12,
283,
17058,
14,
2442,
63,
2558,
63,
17058,
63,
10777,
297,
1067,
29,
1100,
9,
267,
340,
822,
8,
1580,
9,
508,
413,
436,
822,
8,
13336,
9,
508,
413,
26,
288,
754,
459,
1100,
418,
275,
298,
1445,
885,
63,
2558,
63,
344,
356,
298,
435,
620,
8,
13336,
59,
16,
566,
435,
3872,
283,
1733,
63,
885,
63,
2558,
63,
344,
356,
298,
435,
620,
8,
13336,
59,
16,
566,
435,
298,
7063,
267,
587,
26,
288,
754,
459,
2261,
418,
275,
7369,
360,
2558,
63,
344,
1673,
262,
297,
905,
435,
12814,
904,
8,
1130,
8,
495,
12,
7585,
430,
435,
298,
566,
8480,
288,
754,
459,
1100,
418,
275,
28168,
267,
372,
754,
10813,
199,
199,
533,
3336,
63,
2558,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
298,
2558,
14,
2558,
2,
272,
347,
485,
16302,
63,
14387,
63,
835,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
12,
1067,
29,
403,
304,
267,
24114,
275,
291,
14,
2293,
360,
17058,
14,
10777,
358,
267,
522,
275,
1052,
267,
367,
3336,
63,
344,
315,
2762,
26,
288,
522,
59,
2558,
63,
344,
61,
275,
24114,
14,
1733,
63,
835,
8,
1556,
12,
1535,
12,
4274,
2558,
63,
344,
297,
6291,
3336,
63,
344,
4360,
1067,
29,
1100,
9,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
573,
63,
835,
356,
1504,
14,
1593,
1547,
16302,
63,
14387,
63,
835,
12,
1059,
26431,
4688,
7415,
319,
4039,
4236,
7735,
297,
730,
534,
4115,
659,
272,
789,
2286,
347,
1595,
63,
1345,
63,
16302,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
9675,
63,
1113,
275,
291,
14,
2293,
14,
362,
480,
2558,
14,
1160,
531,
267,
7585,
275,
663,
342,
267,
367,
3336,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
7585,
14,
525,
8,
2558
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
421,
199,
533,
3336,
63,
1160,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
298,
2558,
14,
1160,
2,
272,
347,
485,
16302,
63,
14387,
63,
835,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
12,
1067,
29,
403,
304,
267,
699,
676,
275,
291,
14,
2293,
360,
17058,
14,
16302,
358,
267,
522,
275,
1052,
267,
367,
3336,
63,
11510,
63,
344,
315,
2762,
26,
288,
8526,
275,
699,
676,
14,
1733,
63,
835,
8,
1556,
12,
1747,
12,
4274,
2558,
63,
11510,
63,
344,
297,
6291,
3336,
63,
11510,
63,
344,
4360,
1067,
29,
1100,
9,
288,
522,
59,
2558,
63,
11510,
63,
344,
61,
275,
469,
355,
283,
16302,
63,
835,
356,
8526,
12,
288,
789,
267,
372,
522,
339,
347,
485,
16302,
63,
14387,
63,
835,
63,
573,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1680,
12,
1067,
29,
403,
304,
267,
522,
275,
1052,
267,
367,
3336,
63,
11510,
63,
344,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
304,
288,
522,
59,
2558,
63,
11510,
63,
344,
14,
344,
61,
275,
3089,
779,
80,
14,
573,
63,
835,
367,
299,
315,
3336,
63,
11510,
63,
344,
14,
2558,
63,
8759,
63,
1580,
566,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
16302,
63,
1580,
356,
1504,
14,
368,
18,
3479,
360,
17058,
14,
16302,
297,
283,
2558,
63,
11510,
63,
344,
1673,
34,
778,
402,
26570,
83,
659,
267,
283,
16302,
63,
835,
356,
1504,
14,
1593,
1547,
16302,
63,
14387,
63,
835,
12,
1059,
26431,
699,
778,
402,
26570,
297,
730,
534,
4115,
297,
3510,
19667,
16302,
63,
1648,
63,
835,
1288,
267,
283,
573,
63,
835,
356,
1504,
14,
1593,
1547,
16302,
63,
14387,
63,
835,
63,
573,
12,
1059,
26431,
4688,
7415,
319,
4039,
4236,
7735,
297,
730,
534,
4115,
659,
267,
283,
7832,
63,
5814,
356,
1504,
14,
1609,
360,
2395,
7415,
319,
4039,
7005,
350,
4703,
297,
1720,
628,
17400,
7339,
315,
7609,
370,
7389,
642,
3336,
14,
1010,
314,
1930,
402,
3510,
13,
1896,
17720,
12,
314,
2169,
7415,
319,
4039,
12690,
5431,
402,
314,
7323,
911,
506,
3483,
7651,
267,
283,
3885,
63,
10777,
356,
1504,
14,
4871,
360,
7927,
4688,
7415,
319,
4039,
491,
16673,
297,
1720,
628,
1858,
823,
370,
4165,
282,
11973,
4860,
367,
1006,
14569,
3035,
642,
3336,
436,
4046,
701,
282,
4688,
7415,
319,
4039,
9240,
1288,
272,
789,
339,
485,
4322,
275,
469,
267,
283,
7832,
63,
5814,
356,
413,
12,
272,
789,
17635,
347,
1595,
63,
1345,
63,
16908,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
7585,
275,
291,
423,
362,
63,
13336,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
9,
267,
754,
275,
291,
423,
362,
63,
2442,
63,
3806,
63,
807,
8,
1556,
12,
1747,
12,
283,
17058,
14,
2442,
63,
2558,
63,
17058,
63,
10777,
297,
1067,
29,
1100,
9,
267,
340,
822,
8,
1580,
9,
508,
413,
436,
822,
8,
13336,
9,
508,
413,
26,
288,
754,
459,
1100,
418,
275,
298,
1445,
885,
63,
2558,
63,
344,
356,
298,
435,
620,
8,
13336,
59,
16,
566,
435,
3872,
283,
1733,
63,
885,
63,
2558,
63,
344,
356,
298,
435,
620,
8,
13336,
59,
16,
566,
435,
298,
7063,
267,
587,
26,
288,
754,
459,
2261,
418,
275,
7369,
360,
2558,
63,
344,
1673,
262,
297,
905,
435,
12814,
904,
8,
1130,
8,
495,
12,
7585,
430,
435,
298,
566,
8480,
288,
754,
459,
1100,
418,
275,
28168,
267,
372,
754,
10813,
199,
199,
533,
3336,
63,
2558,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
298,
2558,
14,
2558,
2,
272,
347,
485,
16302,
63,
14387,
63,
835,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
901,
63,
354,
12,
1680,
12,
1067,
29,
403,
304,
267,
24114,
275,
291,
14,
2293,
360,
17058,
14,
10777,
358,
267,
522,
275,
1052,
267,
367,
3336,
63,
344,
315,
2762,
26,
288,
522,
59,
2558,
63,
344,
61,
275,
24114,
14,
1733,
63,
835,
8,
1556,
12,
1535,
12,
4274,
2558,
63,
344,
297,
6291,
3336,
63,
344,
4360,
1067,
29,
1100,
9,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
573,
63,
835,
356,
1504,
14,
1593,
1547,
16302,
63,
14387,
63,
835,
12,
1059,
26431,
4688,
7415,
319,
4039,
4236,
7735,
297,
730,
534,
4115,
659,
272,
789,
2286,
347,
1595,
63,
1345,
63,
16302,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
9675,
63,
1113,
275,
291,
14,
2293,
14,
362,
480,
2558,
14,
1160,
531,
267,
7585,
275,
663,
342,
267,
367,
3336,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
7585,
14,
525,
8,
2558,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tamihiro/grpc
|
src/python/grpcio/tests/interop/server.py
|
7
|
2855
|
# Copyright 2015, Google Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""The Python implementation of the GRPC interoperability test server."""
import argparse
import logging
import time
from grpc.beta import implementations
from tests.interop import methods
from tests.interop import resources
from tests.interop import test_pb2
_ONE_DAY_IN_SECONDS = 60 * 60 * 24
def serve():
parser = argparse.ArgumentParser()
parser.add_argument(
'--port', help='the port on which to serve', type=int)
parser.add_argument(
'--use_tls', help='require a secure connection',
default=False, type=resources.parse_bool)
args = parser.parse_args()
server = test_pb2.beta_create_TestService_server(methods.TestService())
if args.use_tls:
private_key = resources.private_key()
certificate_chain = resources.certificate_chain()
credentials = implementations.ssl_server_credentials(
[(private_key, certificate_chain)])
server.add_secure_port('[::]:{}'.format(args.port), credentials)
else:
server.add_insecure_port('[::]:{}'.format(args.port))
server.start()
logging.info('Server serving.')
try:
while True:
time.sleep(_ONE_DAY_IN_SECONDS)
except BaseException as e:
logging.info('Caught exception "%s"; stopping server...', e)
server.stop(0)
logging.info('Server stopped; exiting.')
if __name__ == '__main__':
serve()
|
bsd-3-clause
|
[
3,
1898,
6900,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
1918,
2018,
4514,
402,
314,
598,
8171,
4661,
9198,
3616,
511,
1654,
1041,
199,
199,
646,
7534,
199,
646,
2050,
199,
646,
900,
199,
199,
504,
19753,
14,
5683,
492,
12591,
199,
199,
504,
2295,
14,
5707,
2675,
492,
3102,
199,
504,
2295,
14,
5707,
2675,
492,
5944,
199,
504,
2295,
14,
5707,
2675,
492,
511,
63,
3317,
18,
199,
199,
63,
4817,
63,
11655,
63,
568,
63,
23319,
275,
5212,
627,
5212,
627,
5504,
421,
199,
318,
14062,
837,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
719,
297,
1720,
534,
1589,
1844,
641,
1314,
370,
14062,
297,
730,
29,
442,
9,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
1180,
63,
9945,
297,
1720,
534,
4365,
282,
11153,
1950,
297,
489,
849,
29,
797,
12,
730,
29,
4435,
14,
1122,
63,
2245,
9,
523,
1249,
275,
1798,
14,
1122,
63,
589,
342,
819,
1654,
275,
511,
63,
3317,
18,
14,
5683,
63,
981,
63,
774,
3167,
63,
1000,
8,
2474,
14,
774,
3167,
1012,
523,
340,
1249,
14,
1180,
63,
9945,
26,
272,
5726,
63,
498,
275,
5944,
14,
4239,
63,
498,
342,
272,
5897,
63,
4429,
275,
5944,
14,
6999,
63,
4429,
342,
272,
6235,
275,
12591,
14,
4266,
63,
1000,
63,
6942,
8,
267,
3842,
4239,
63,
498,
12,
5897,
63,
4429,
3948,
272,
1654,
14,
525,
63,
7817,
63,
719,
360,
10345,
2189,
11123,
908,
8,
589,
14,
719,
395,
6235,
9,
523,
587,
26,
272,
1654,
14,
525,
63,
24824,
63,
719,
360,
10345,
2189,
11123,
908,
8,
589,
14,
719,
430,
819,
1654,
14,
928,
342,
523,
2050,
14,
815,
360,
3120,
22701,
2659,
523,
862,
26,
272,
1830,
715,
26,
489,
900,
14,
4532,
1547,
4817,
63,
11655,
63,
568,
63,
23319,
9,
523,
871,
25416,
465,
325,
26,
272,
2050,
14,
815,
360,
3630,
10846,
1919,
2071,
83,
11436,
23599,
1654,
20833,
325,
9,
272,
1654,
14,
2379,
8,
16,
9,
272,
2050,
14,
815,
360,
3120,
15248,
27,
24234,
2659,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
14062,
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
] |
[
1898,
6900,
12,
4475,
3277,
14,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
199,
3,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
199,
3,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
199,
3,
4084,
14,
199,
3,
258,
627,
11443,
314,
536,
402,
4475,
3277,
14,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
624,
1918,
2018,
4514,
402,
314,
598,
8171,
4661,
9198,
3616,
511,
1654,
1041,
199,
199,
646,
7534,
199,
646,
2050,
199,
646,
900,
199,
199,
504,
19753,
14,
5683,
492,
12591,
199,
199,
504,
2295,
14,
5707,
2675,
492,
3102,
199,
504,
2295,
14,
5707,
2675,
492,
5944,
199,
504,
2295,
14,
5707,
2675,
492,
511,
63,
3317,
18,
199,
199,
63,
4817,
63,
11655,
63,
568,
63,
23319,
275,
5212,
627,
5212,
627,
5504,
421,
199,
318,
14062,
837,
523,
1798,
275,
7534,
14,
10730,
342,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
719,
297,
1720,
534,
1589,
1844,
641,
1314,
370,
14062,
297,
730,
29,
442,
9,
523,
1798,
14,
525,
63,
2094,
8,
489,
2850,
1180,
63,
9945,
297,
1720,
534,
4365,
282,
11153,
1950,
297,
489,
849,
29,
797,
12,
730,
29,
4435,
14,
1122,
63,
2245,
9,
523,
1249,
275,
1798,
14,
1122,
63,
589,
342,
819,
1654,
275,
511,
63,
3317,
18,
14,
5683,
63,
981,
63,
774,
3167,
63,
1000,
8,
2474,
14,
774,
3167,
1012,
523,
340,
1249,
14,
1180,
63,
9945,
26,
272,
5726,
63,
498,
275,
5944,
14,
4239,
63,
498,
342,
272,
5897,
63,
4429,
275,
5944,
14,
6999,
63,
4429,
342,
272,
6235,
275,
12591,
14,
4266,
63,
1000,
63,
6942,
8,
267,
3842,
4239,
63,
498,
12,
5897,
63,
4429,
3948,
272,
1654,
14,
525,
63,
7817,
63,
719,
360,
10345,
2189,
11123,
908,
8,
589,
14,
719,
395,
6235,
9,
523,
587,
26,
272,
1654,
14,
525,
63,
24824,
63,
719,
360,
10345,
2189,
11123,
908,
8,
589,
14,
719,
430,
819,
1654,
14,
928,
342,
523,
2050,
14,
815,
360,
3120,
22701,
2659,
523,
862,
26,
272,
1830,
715,
26,
489,
900,
14,
4532,
1547,
4817,
63,
11655,
63,
568,
63,
23319,
9,
523,
871,
25416,
465,
325,
26,
272,
2050,
14,
815,
360,
3630,
10846,
1919,
2071,
83,
11436,
23599,
1654,
20833,
325,
9,
272,
1654,
14,
2379,
8,
16,
9,
272,
2050,
14,
815,
360,
3120,
15248,
27,
24234,
2659,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
14062,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
b1-systems/kiwi
|
kiwi/bootloader/config/grub2.py
|
1
|
32822
|
# Copyright (c) 2015 SUSE Linux GmbH. All rights reserved.
#
# This file is part of kiwi.
#
# kiwi 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.
#
# kiwi 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 kiwi. If not, see <http://www.gnu.org/licenses/>
#
import os
import platform
import glob
from collections import OrderedDict
# project
from kiwi.bootloader.config.base import BootLoaderConfigBase
from kiwi.bootloader.template.grub2 import BootLoaderTemplateGrub2
from kiwi.command import Command
from kiwi.defaults import Defaults
from kiwi.firmware import FirmWare
from kiwi.logger import log
from kiwi.path import Path
from kiwi.utils.sync import DataSync
from kiwi.utils.sysconfig import SysConfig
from kiwi.exceptions import (
KiwiTemplateError,
KiwiBootLoaderGrubPlatformError,
KiwiBootLoaderGrubModulesError,
KiwiBootLoaderGrubSecureBootError,
KiwiBootLoaderGrubFontError,
)
class BootLoaderConfigGrub2(BootLoaderConfigBase):
"""
**grub2 bootloader configuration.**
"""
def post_init(self, custom_args):
"""
grub2 post initialization method
:param dict custom_args:
Contains grub config arguments
.. code:: python
{'grub_directory_name': 'grub|grub2'}
"""
self.custom_args = custom_args
arch = platform.machine()
if arch == 'x86_64':
# grub2 support for bios and efi systems
self.arch = arch
elif arch.startswith('ppc64'):
# grub2 support for ofw and opal systems
self.arch = arch
elif arch == 'i686' or arch == 'i586':
# grub2 support for bios systems
self.arch = 'ix86'
elif arch == 'aarch64' or arch.startswith('arm'):
# grub2 support for efi systems
self.arch = arch
else:
raise KiwiBootLoaderGrubPlatformError(
'host architecture %s not supported for grub2 setup' % arch
)
if self.custom_args and 'grub_directory_name' in self.custom_args:
self.boot_directory_name = self.custom_args['grub_directory_name']
else:
self.boot_directory_name = 'grub'
self.terminal = self.xml_state.build_type.get_bootloader_console() \
or 'gfxterm'
self.gfxmode = self.get_gfxmode('grub2')
self.theme = self.get_boot_theme()
self.timeout = self.get_boot_timeout_seconds()
self.continue_on_timeout = self.get_continue_on_timeout()
self.failsafe_boot = self.failsafe_boot_entry_requested()
self.mediacheck_boot = self.xml_state.build_type.get_mediacheck()
self.xen_guest = self.xml_state.is_xen_guest()
self.firmware = FirmWare(
self.xml_state
)
self.live_type = self.xml_state.build_type.get_flags()
if not self.live_type:
self.live_type = Defaults.get_default_live_iso_type()
self.volume_id = self.xml_state.build_type.get_volid() or \
Defaults.get_volume_id()
self.install_volid = self.xml_state.build_type.get_volid() or \
Defaults.get_install_volume_id()
self.live_boot_options = [
'root=live:CDLABEL={0}'.format(self.volume_id),
'rd.live.image'
]
self.install_boot_options = [
'loglevel=0'
]
if self.xml_state.get_initrd_system() == 'dracut':
self.install_boot_options.append(
'root=install:CDLABEL={0}'.format(self.install_volid)
)
if self.xml_state.build_type.get_hybridpersistent():
self.live_boot_options += \
Defaults.get_live_iso_persistent_boot_options(
self.xml_state.build_type.get_hybridpersistent_filesystem()
)
if self.xml_state.is_xen_server():
self.hybrid_boot = False
self.multiboot = True
elif self.xen_guest:
self.hybrid_boot = False
self.multiboot = False
else:
self.hybrid_boot = True
self.multiboot = False
self.grub2 = BootLoaderTemplateGrub2()
self.config = None
self.efi_boot_path = None
self.cmdline_failsafe = None
self.cmdline = None
self.iso_boot = False
self.shim_fallback_setup = False
def write(self):
"""
Write grub.cfg and etc/default/grub file
"""
config_dir = self._get_grub2_boot_path()
config_file = config_dir + '/grub.cfg'
if self.config:
log.info('Writing grub.cfg file')
Path.create(config_dir)
with open(config_file, 'w') as config:
config.write(self.config)
if self.firmware.efi_mode():
if self.iso_boot or self.shim_fallback_setup:
efi_vendor_boot_path = Defaults.get_shim_vendor_directory(
self.root_dir
)
if efi_vendor_boot_path:
grub_config_file_for_efi_boot = os.sep.join(
[efi_vendor_boot_path, 'grub.cfg']
)
else:
grub_config_file_for_efi_boot = os.path.normpath(
os.sep.join([self.efi_boot_path, 'grub.cfg'])
)
log.info(
'Writing {0} file to be found by EFI firmware'.format(
grub_config_file_for_efi_boot
)
)
with open(grub_config_file_for_efi_boot, 'w') as config:
config.write(self.config)
if self.iso_boot:
self._create_embedded_fat_efi_image()
self._setup_default_grub()
self.setup_sysconfig_bootloader()
def setup_sysconfig_bootloader(self):
"""
Create or update etc/sysconfig/bootloader by the following
parameters required according to the grub2 bootloader setup
* LOADER_TYPE
* LOADER_LOCATION
* DEFAULT_APPEND
* FAILSAFE_APPEND
"""
sysconfig_bootloader_entries = {
'LOADER_TYPE':
'grub2-efi' if self.firmware.efi_mode() else 'grub2',
'LOADER_LOCATION':
'none' if self.firmware.efi_mode() else 'mbr'
}
if self.cmdline:
sysconfig_bootloader_entries['DEFAULT_APPEND'] = '"{0}"'.format(
self.cmdline
)
if self.cmdline_failsafe:
sysconfig_bootloader_entries['FAILSAFE_APPEND'] = '"{0}"'.format(
self.cmdline_failsafe
)
log.info('Writing sysconfig bootloader file')
sysconfig_bootloader_location = ''.join(
[self.root_dir, '/etc/sysconfig/']
)
if os.path.exists(sysconfig_bootloader_location):
sysconfig_bootloader_file = ''.join(
[sysconfig_bootloader_location, 'bootloader']
)
sysconfig_bootloader = SysConfig(
sysconfig_bootloader_file
)
sysconfig_bootloader_entries_sorted = OrderedDict(
sorted(sysconfig_bootloader_entries.items())
)
for key, value in list(sysconfig_bootloader_entries_sorted.items()):
log.info('--> {0}:{1}'.format(key, value))
sysconfig_bootloader[key] = value
sysconfig_bootloader.write()
def setup_disk_image_config(
self, boot_uuid, root_uuid, hypervisor='xen.gz', kernel='linux.vmx',
initrd='initrd.vmx', boot_options=''
):
"""
Create the grub.cfg in memory from a template suitable to boot
from a disk image
:param string boot_uuid: boot device UUID
:param string root_uuid: root device UUID
:param string hypervisor: hypervisor name
:param string kernel: kernel name
:param string initrd: initrd name
:param string boot_options: kernel options as string
"""
log.info('Creating grub2 config file from template')
self.cmdline = ' '.join(
[self.get_boot_cmdline(root_uuid), boot_options]
)
self.cmdline_failsafe = ' '.join(
[self.cmdline, Defaults.get_failsafe_kernel_options(), boot_options]
)
parameters = {
'search_params': ' '.join(['--fs-uuid', '--set=root', boot_uuid]),
'default_boot': '0',
'kernel_file': kernel,
'initrd_file': initrd,
'boot_options': self.cmdline,
'failsafe_boot_options': self.cmdline_failsafe,
'gfxmode': self.gfxmode,
'theme': self.theme,
'boot_timeout': self.timeout,
'title': self.get_menu_entry_title(),
'bootpath': self.get_boot_path('disk'),
'boot_directory_name': self.boot_directory_name
}
if self.multiboot:
log.info('--> Using multiboot disk template')
parameters['hypervisor'] = hypervisor
template = self.grub2.get_multiboot_disk_template(
self.failsafe_boot, self.terminal
)
else:
log.info('--> Using hybrid boot disk template')
template = self.grub2.get_disk_template(
self.failsafe_boot, self.hybrid_boot, self.terminal
)
try:
self.config = template.substitute(parameters)
except Exception as e:
raise KiwiTemplateError(
'%s: %s' % (type(e).__name__, format(e))
)
def setup_install_image_config(
self, mbrid, hypervisor='xen.gz', kernel='linux', initrd='initrd'
):
"""
Create grub2 config file to boot from an ISO install image
:param string mbrid: mbrid file name on boot device
:param string hypervisor: hypervisor name
:param string kernel: kernel name
:param string initrd: initrd name
"""
log.info('Creating grub2 install config file from template')
self.iso_boot = True
self.cmdline = self.get_boot_cmdline()
self.cmdline_failsafe = ' '.join(
[self.cmdline, Defaults.get_failsafe_kernel_options()]
)
parameters = {
'search_params': '--file --set=root /boot/' + mbrid.get_id(),
'default_boot': self.get_install_image_boot_default(),
'kernel_file': kernel,
'initrd_file': initrd,
'boot_options': ' '.join(
[self.cmdline] + self.install_boot_options
),
'failsafe_boot_options': ' '.join(
[self.cmdline_failsafe] + self.install_boot_options
),
'gfxmode': self.gfxmode,
'theme': self.theme,
'boot_timeout': self.timeout,
'title': self.get_menu_entry_install_title(),
'bootpath': self.get_boot_path('iso'),
'boot_directory_name': self.boot_directory_name
}
if self.multiboot:
log.info('--> Using multiboot install template')
parameters['hypervisor'] = hypervisor
template = self.grub2.get_multiboot_install_template(
self.failsafe_boot, self.terminal,
self.continue_on_timeout
)
else:
log.info('--> Using standard boot install template')
hybrid_boot = True
template = self.grub2.get_install_template(
self.failsafe_boot, hybrid_boot, self.terminal,
self.continue_on_timeout
)
try:
self.config = template.substitute(parameters)
except Exception as e:
raise KiwiTemplateError(
'%s: %s' % (type(e).__name__, format(e))
)
def setup_live_image_config(
self, mbrid, hypervisor='xen.gz', kernel='linux', initrd='initrd'
):
"""
Create grub2 config file to boot a live media ISO image
:param string mbrid: mbrid file name on boot device
:param string hypervisor: hypervisor name
:param string kernel: kernel name
:param string initrd: initrd name
"""
log.info('Creating grub2 live ISO config file from template')
self.iso_boot = True
self.cmdline = self.get_boot_cmdline()
self.cmdline_failsafe = ' '.join(
[self.cmdline, Defaults.get_failsafe_kernel_options()]
)
parameters = {
'search_params': '--file --set=root /boot/' + mbrid.get_id(),
'default_boot': '0',
'kernel_file': kernel,
'initrd_file': initrd,
'boot_options': ' '.join(
[self.cmdline] + self.live_boot_options
),
'failsafe_boot_options': ' '.join(
[self.cmdline_failsafe] + self.live_boot_options
),
'gfxmode': self.gfxmode,
'theme': self.theme,
'boot_timeout': self.timeout,
'title': self.get_menu_entry_title(plain=True),
'bootpath': self.get_boot_path('iso'),
'boot_directory_name': self.boot_directory_name
}
if self.multiboot:
log.info('--> Using multiboot template')
parameters['hypervisor'] = hypervisor
template = self.grub2.get_multiboot_iso_template(
self.failsafe_boot, self.terminal, self.mediacheck_boot
)
else:
log.info('--> Using standard boot template')
hybrid_boot = True
template = self.grub2.get_iso_template(
self.failsafe_boot, hybrid_boot,
self.terminal, self.mediacheck_boot
)
try:
self.config = template.substitute(parameters)
except Exception as e:
raise KiwiTemplateError(
'%s: %s' % (type(e).__name__, format(e))
)
def setup_install_boot_images(self, mbrid, lookup_path=None):
"""
Create/Provide grub2 boot images and metadata
In order to boot from the ISO grub2 modules, images and theme
data needs to be created and provided at the correct place on
the iso filesystem
:param string mbrid: mbrid file name on boot device
:param string lookup_path: custom module lookup path
"""
log.info('Creating grub2 bootloader images')
self.efi_boot_path = self.create_efi_path(in_sub_dir='')
log.info('--> Creating identifier file %s', mbrid.get_id())
Path.create(
self._get_grub2_boot_path()
)
mbrid.write(
self.root_dir + '/boot/' + mbrid.get_id()
)
mbrid.write(
self.root_dir + '/boot/mbrid'
)
self._copy_theme_data_to_boot_directory(lookup_path, 'iso')
if self._supports_bios_modules():
self._copy_bios_modules_to_boot_directory(lookup_path)
if self.firmware.efi_mode():
self._setup_EFI_path(lookup_path)
if self.firmware.efi_mode() == 'efi':
self._setup_efi_image(mbrid=mbrid, lookup_path=lookup_path)
self._copy_efi_modules_to_boot_directory(lookup_path)
elif self.firmware.efi_mode() == 'uefi':
self._copy_efi_modules_to_boot_directory(lookup_path)
self._setup_secure_boot_efi_image(lookup_path)
def setup_live_boot_images(self, mbrid, lookup_path=None):
"""
Create/Provide grub2 boot images and metadata
Calls setup_install_boot_images because no different action required
"""
self.setup_install_boot_images(mbrid, lookup_path)
def setup_disk_boot_images(self, boot_uuid, lookup_path=None):
"""
Create/Provide grub2 boot images and metadata
In order to boot from the disk grub2 modules, images and theme
data needs to be created and provided at the correct place in
the filesystem
:param string boot_uuid: boot device UUID
:param string lookup_path: custom module lookup path
"""
log.info('Creating grub2 bootloader images')
if self.firmware.efi_mode():
self.efi_boot_path = self.create_efi_path()
self._copy_theme_data_to_boot_directory(lookup_path, 'disk')
if not self.xen_guest and self._supports_bios_modules():
self._copy_bios_modules_to_boot_directory(lookup_path)
if self.firmware.efi_mode() == 'efi':
self._setup_efi_image(uuid=boot_uuid, lookup_path=lookup_path)
self._copy_efi_modules_to_boot_directory(lookup_path)
elif self.firmware.efi_mode() == 'uefi':
self._copy_efi_modules_to_boot_directory(lookup_path)
if not self._get_shim_install():
self.shim_fallback_setup = True
self._setup_secure_boot_efi_image(lookup_path)
if self.xen_guest:
self._copy_xen_modules_to_boot_directory(lookup_path)
def _supports_bios_modules(self):
if self.arch == 'ix86' or self.arch == 'x86_64':
return True
return False
def _setup_default_grub(self):
"""
Create or update etc/default/grub by parameters required
according to the root filesystem setup
* GRUB_TIMEOUT
* SUSE_BTRFS_SNAPSHOT_BOOTING
* GRUB_BACKGROUND
* GRUB_THEME
* GRUB_USE_LINUXEFI
* GRUB_USE_INITRDEFI
* GRUB_SERIAL_COMMAND
* GRUB_CMDLINE_LINUX_DEFAULT
"""
grub_default_entries = {
'GRUB_TIMEOUT': self.timeout
}
if self.cmdline:
grub_default_entries['GRUB_CMDLINE_LINUX_DEFAULT'] = '"{0}"'.format(
self.cmdline
)
if self.terminal and self.terminal == 'serial':
serial_format = '"serial {0} {1} {2} {3} {4}"'
grub_default_entries['GRUB_SERIAL_COMMAND'] = serial_format.format(
'--speed=38400',
'--unit=0',
'--word=8',
'--parity=no',
'--stop=1'
)
if self.theme:
theme_setup = '{0}/{1}/theme.txt'
grub_default_entries['GRUB_THEME'] = theme_setup.format(
''.join(['/boot/', self.boot_directory_name, '/themes']),
self.theme
)
theme_background = '{0}/{1}/background.png'.format(
''.join(['/boot/', self.boot_directory_name, '/themes']),
self.theme
)
if os.path.exists(os.sep.join([self.root_dir, theme_background])):
grub_default_entries['GRUB_BACKGROUND'] = theme_background
if self.firmware.efi_mode():
# linuxefi/initrdefi only exist on x86, others always use efi
if self.arch == 'ix86' or self.arch == 'x86_64':
grub_default_entries['GRUB_USE_LINUXEFI'] = 'true'
grub_default_entries['GRUB_USE_INITRDEFI'] = 'true'
if self.xml_state.build_type.get_btrfs_root_is_snapshot():
grub_default_entries['SUSE_BTRFS_SNAPSHOT_BOOTING'] = 'true'
if grub_default_entries:
log.info('Writing grub2 defaults file')
grub_default_location = ''.join([self.root_dir, '/etc/default/'])
if os.path.exists(grub_default_location):
grub_default_file = ''.join([grub_default_location, 'grub'])
grub_default = SysConfig(grub_default_file)
grub_default_entries_sorted = OrderedDict(
sorted(grub_default_entries.items())
)
for key, value in list(grub_default_entries_sorted.items()):
log.info('--> {0}:{1}'.format(key, value))
grub_default[key] = value
grub_default.write()
def _setup_secure_boot_efi_image(self, lookup_path):
"""
Provide the shim loader and the shim signed grub2 loader
in the required boot path. Normally this task is done by
the shim-install tool. However, shim-install does not exist
on all distributions and the script does not operate well
in e.g CD environments from which we generate live and/or
install media. Thus shim-install is used if possible at
install time of the bootloader because it requires access
to the target block device. In any other case this setup
code should act as the fallback solution
"""
log.warning(
'--> Running fallback setup for shim secure boot efi image'
)
if not lookup_path:
lookup_path = self.root_dir
shim_image = Defaults.get_shim_loader(lookup_path)
if not shim_image:
raise KiwiBootLoaderGrubSecureBootError(
'Microsoft signed shim loader not found'
)
grub_image = Defaults.get_signed_grub_loader(lookup_path)
if not grub_image:
raise KiwiBootLoaderGrubSecureBootError(
'Shim signed grub2 efi loader not found'
)
Command.run(
['cp', shim_image, self._get_efi_image_name()]
)
Command.run(
['cp', grub_image, self.efi_boot_path]
)
def _setup_efi_image(self, uuid=None, mbrid=None, lookup_path=None):
"""
Provide the unsigned grub2 efi image in the required boot path
If a prebuilt efi image as provided by the distribution could
be found, this image will be used. If no such image could be
found we create a custom image with a pre defined set of
grub modules
"""
if not lookup_path:
lookup_path = self.root_dir
grub_image = Defaults.get_unsigned_grub_loader(lookup_path)
if grub_image:
log.info('--> Using prebuilt unsigned efi image')
Command.run(
['cp', grub_image, self._get_efi_image_name()]
)
self._create_efi_config_search(uuid, mbrid)
else:
log.info('--> Creating unsigned efi image')
self._create_efi_image(
uuid, mbrid, lookup_path
)
def _create_embedded_fat_efi_image(self):
Path.create(self.root_dir + '/boot/' + self.arch)
efi_fat_image = ''.join(
[self.root_dir + '/boot/', self.arch, '/efi']
)
Command.run(
['qemu-img', 'create', efi_fat_image, '15M']
)
Command.run(
['mkdosfs', '-n', 'BOOT', efi_fat_image]
)
Command.run(
[
'mcopy', '-Do', '-s', '-i', efi_fat_image,
self.root_dir + '/EFI', '::'
]
)
def _create_efi_image(self, uuid=None, mbrid=None, lookup_path=None):
early_boot_script = self.efi_boot_path + '/earlyboot.cfg'
if uuid:
self._create_early_boot_script_for_uuid_search(
early_boot_script, uuid
)
else:
self._create_early_boot_script_for_mbrid_search(
early_boot_script, mbrid
)
Command.run(
[
self._get_grub2_mkimage_tool() or 'grub2-mkimage',
'-O', Defaults.get_efi_module_directory_name(self.arch),
'-o', self._get_efi_image_name(),
'-c', early_boot_script,
'-p', self.get_boot_path() + '/' + self.boot_directory_name,
'-d', self._get_efi_modules_path(lookup_path)
] + Defaults.get_grub_efi_modules(multiboot=self.xen_guest)
)
def _create_efi_config_search(self, uuid=None, mbrid=None):
efi_boot_config = self.efi_boot_path + '/grub.cfg'
if uuid:
self._create_early_boot_script_for_uuid_search(
efi_boot_config, uuid
)
else:
self._create_early_boot_script_for_mbrid_search(
efi_boot_config, mbrid
)
with open(efi_boot_config, 'a') as config:
config.write('normal{0}'.format(os.linesep))
def _create_early_boot_script_for_uuid_search(self, filename, uuid):
with open(filename, 'w') as early_boot:
early_boot.write(
'set btrfs_relative_path="yes"{0}'.format(os.linesep)
)
early_boot.write(
'search --fs-uuid --set=root {0}{1}'.format(uuid, os.linesep)
)
early_boot.write(
'set prefix=($root){0}/{1}{2}'.format(
self.get_boot_path(), self.boot_directory_name, os.linesep
)
)
def _create_early_boot_script_for_mbrid_search(self, filename, mbrid):
with open(filename, 'w') as early_boot:
early_boot.write(
'set btrfs_relative_path="yes"{0}'.format(os.linesep)
)
early_boot.write(
'search --file --set=root /boot/{0}{1}'.format(
mbrid.get_id(), os.linesep
)
)
early_boot.write(
'set prefix=($root)/boot/{0}{1}'.format(
self.boot_directory_name, os.linesep
)
)
def _get_grub2_mkimage_tool(self):
for grub_mkimage_tool in ['grub2-mkimage', 'grub-mkimage']:
if Path.which(grub_mkimage_tool):
return grub_mkimage_tool
def _get_grub2_boot_path(self):
return self.root_dir + '/boot/' + self.boot_directory_name
def _get_efi_image_name(self):
return self.efi_boot_path + '/' + Defaults.get_efi_image_name(self.arch)
def _get_efi_modules_path(self, lookup_path=None):
return self._get_module_path(
Defaults.get_efi_module_directory_name(self.arch),
lookup_path
)
def _get_bios_modules_path(self, lookup_path=None):
return self._get_module_path('i386-pc', lookup_path)
def _get_xen_modules_path(self, lookup_path=None):
return self._get_module_path(
Defaults.get_efi_module_directory_name('x86_64_xen'),
lookup_path
)
def _get_module_path(self, format_name, lookup_path=None):
if not lookup_path:
lookup_path = self.root_dir
return Defaults.get_grub_path(lookup_path, format_name)
def _find_theme_background_file(self, lookup_path):
background_pattern = os.sep.join(
[
lookup_path, 'boot', self.boot_directory_name, 'themes',
'*', 'background.png'
]
)
for background_file in glob.iglob(background_pattern):
return background_file
def _copy_theme_data_to_boot_directory(self, lookup_path, target):
if not lookup_path:
lookup_path = self.root_dir
boot_fonts_dir = os.path.normpath(
os.sep.join(
[
self.root_dir,
self.get_boot_path(target),
self.boot_directory_name,
'fonts'
]
)
)
Path.create(boot_fonts_dir)
boot_unicode_font = boot_fonts_dir + '/unicode.pf2'
if not os.path.exists(boot_unicode_font):
try:
unicode_font = Defaults.get_grub_path(
lookup_path, 'unicode.pf2'
)
Command.run(
['cp', unicode_font, boot_unicode_font]
)
except Exception as issue:
raise KiwiBootLoaderGrubFontError(
'Setting up unicode font failed with {0}'.format(issue)
)
boot_theme_dir = os.sep.join(
[self.root_dir, 'boot', self.boot_directory_name, 'themes']
)
Path.create(boot_theme_dir)
if self.theme:
theme_dir = Defaults.get_grub_path(
lookup_path, 'themes/' + self.theme, raise_on_error=False
)
boot_theme_background_file = self._find_theme_background_file(
lookup_path
)
if theme_dir and os.path.exists(theme_dir):
if boot_theme_background_file:
# A background file was found. Preserve a copy of the
# file which was created at install time of the theme
# package by the activate-theme script
boot_theme_background_backup_file = os.sep.join(
[self.root_dir, 'background.png']
)
Command.run(
[
'cp', boot_theme_background_file,
boot_theme_background_backup_file
]
)
# sync theme data from install path to boot path
data = DataSync(
theme_dir, boot_theme_dir
)
data.sync_data(
options=['-z', '-a']
)
if boot_theme_background_file:
# Install preserved background file to the theme
Command.run(
[
'mv', boot_theme_background_backup_file,
os.sep.join([boot_theme_dir, self.theme])
]
)
elif boot_theme_background_file:
# assume all theme data is in the directory of the
# background file and just sync that directory to the
# boot path
data = DataSync(
os.path.dirname(boot_theme_background_file), boot_theme_dir
)
data.sync_data(
options=['-z', '-a']
)
self._check_boot_theme_exists()
def _check_boot_theme_exists(self):
if self.theme:
theme_dir = os.sep.join(
[
self.root_dir, 'boot', self.boot_directory_name,
'themes', self.theme
]
)
if not os.path.exists(theme_dir):
log.warning('Theme %s not found', theme_dir)
log.warning('Set bootloader terminal to console mode')
self.terminal = 'console'
def _setup_EFI_path(self, lookup_path):
"""
Copy efi boot data from lookup_path to the root directory
"""
if not lookup_path:
lookup_path = self.root_dir
efi_path = lookup_path + '/boot/efi/'
if os.path.exists(efi_path):
efi_data = DataSync(efi_path, self.root_dir)
efi_data.sync_data(options=['-a'])
def _copy_efi_modules_to_boot_directory(self, lookup_path):
self._copy_modules_to_boot_directory_from(
self._get_efi_modules_path(lookup_path)
)
def _copy_bios_modules_to_boot_directory(self, lookup_path):
self._copy_modules_to_boot_directory_from(
self._get_bios_modules_path(lookup_path)
)
def _copy_xen_modules_to_boot_directory(self, lookup_path):
self._copy_modules_to_boot_directory_from(
self._get_xen_modules_path(lookup_path)
)
def _copy_modules_to_boot_directory_from(self, module_path):
boot_module_path = \
self._get_grub2_boot_path() + '/' + os.path.basename(module_path)
try:
data = DataSync(
module_path + '/', boot_module_path
)
data.sync_data(
options=['-z', '-a'], exclude=['*.module']
)
except Exception as e:
raise KiwiBootLoaderGrubModulesError(
'Module synchronisation failed with: %s' % format(e)
)
def _get_shim_install(self):
chroot_env = {
'PATH': os.sep.join([self.root_dir, 'usr', 'sbin'])
}
return Path.which(
filename='shim-install', custom_env=chroot_env
)
|
gpl-3.0
|
[
3,
1898,
334,
67,
9,
6900,
428,
4701,
10130,
23428,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1022,
73,
14249,
14,
199,
3,
199,
3,
1022,
73,
14249,
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,
1022,
73,
14249,
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,
1022,
73,
14249,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
3133,
199,
3,
199,
646,
747,
199,
646,
4298,
199,
646,
5739,
199,
504,
5055,
492,
8773,
199,
199,
3,
2199,
199,
504,
1022,
73,
14249,
14,
4930,
3422,
14,
888,
14,
1095,
492,
27324,
5455,
2028,
1563,
199,
504,
1022,
73,
14249,
14,
4930,
3422,
14,
1160,
14,
2587,
456,
18,
492,
27324,
5455,
4231,
23765,
456,
18,
199,
504,
1022,
73,
14249,
14,
1531,
492,
5817,
199,
504,
1022,
73,
14249,
14,
4322,
492,
7827,
199,
504,
1022,
73,
14249,
14,
26374,
492,
481,
18698,
55,
1530,
199,
504,
1022,
73,
14249,
14,
2921,
492,
943,
199,
504,
1022,
73,
14249,
14,
515,
492,
6912,
199,
504,
1022,
73,
14249,
14,
1208,
14,
5186,
492,
3918,
10878,
199,
504,
1022,
73,
14249,
14,
1208,
14,
24030,
492,
28766,
2028,
199,
199,
504,
1022,
73,
14249,
14,
3924,
492,
334,
272,
1804,
73,
14249,
4231,
547,
12,
272,
1804,
73,
14249,
17989,
5455,
23765,
456,
10397,
547,
12,
272,
1804,
73,
14249,
17989,
5455,
23765,
456,
17981,
547,
12,
272,
1804,
73,
14249,
17989,
5455,
23765,
456,
24117,
17989,
547,
12,
272,
1804,
73,
14249,
17989,
5455,
23765,
456,
6986,
547,
12,
199,
9,
421,
199,
533,
27324,
5455,
2028,
23765,
456,
18,
8,
17989,
5455,
2028,
1563,
304,
272,
408,
272,
1011,
2587,
456,
18,
8498,
3422,
2897,
14,
538,
272,
408,
272,
347,
2963,
63,
826,
8,
277,
12,
3537,
63,
589,
304,
267,
408,
267,
7192,
456,
18,
2963,
11097,
1083,
398,
520,
635,
1211,
3537,
63,
589,
26,
288,
22493,
7192,
456,
1101,
2368,
953,
2508,
1233,
447,
2366,
2234,
791,
2587,
456,
63,
3619,
63,
354,
356,
283,
2587,
456,
92,
2587,
456,
18,
936,
267,
408,
267,
291,
14,
4229,
63,
589,
275,
3537,
63,
589,
267,
3819,
275,
4298,
14,
6744,
342,
267,
340,
3819,
508,
283,
88,
1184,
63,
772,
356,
288,
327,
7192,
456,
18,
2291,
367,
330,
9207,
436,
325,
329,
10460,
288,
291,
14,
1047,
275,
3819,
267,
916,
3819,
14,
2460,
360,
20638,
772,
735,
288,
327,
7192,
456,
18,
2291,
367,
402,
87,
436,
1687,
279,
10460,
288,
291,
14,
1047,
275,
3819,
267,
916,
3819,
508,
283,
73,
10253,
7,
503,
3819,
508,
283,
73,
26888,
356,
288,
327,
7192,
456,
18,
2291,
367,
330,
9207,
10460,
288,
291,
14,
1047,
275,
283,
1148,
1184,
7,
267,
916,
3819,
508,
283,
65,
1047,
772,
7,
503,
3819,
14,
2460,
360,
5362,
735,
288,
327,
7192,
456,
18,
2291,
367,
325,
329,
10460,
288,
291,
14,
1047,
275,
3819,
267,
587,
26,
288,
746,
1804,
73,
14249,
17989,
5455,
23765,
456,
10397,
547,
8,
355,
283,
1102,
15931,
450,
83,
440,
3748,
367,
7192,
456,
18,
3272,
7,
450,
3819,
288,
776,
398,
340,
291,
14,
4229,
63,
589,
436,
283,
2587,
456,
63,
3619,
63,
354,
7,
315,
291,
14,
4229,
63,
589,
26,
288,
291,
14,
4930,
63,
3619,
63,
354,
275,
291,
14,
4229,
63,
589,
459,
2587,
456,
63,
3619,
63,
354,
418,
267,
587,
26,
288,
291,
14,
4930,
63,
3619,
63,
354,
275,
283,
2587,
456,
7,
398,
291,
14,
12010,
275,
291,
14,
1652,
63,
929,
14,
1506,
63,
466,
14,
362,
63,
4930,
3422,
63,
6614,
342,
971,
288,
503,
283,
7102,
31896,
7,
267,
291,
14,
7102,
88,
632,
275,
291,
14,
362,
63,
7102,
88,
632,
360,
2587,
456,
18,
358,
267,
291,
14,
7915,
275,
291,
14,
362,
63,
4930,
63,
7915,
342,
267,
291,
14,
2593,
275,
291,
14,
362,
63,
4930,
63,
2593,
63,
4515,
342,
267,
291,
14,
6958,
63,
265,
63,
2593,
275,
291,
14,
362,
63,
6958,
63,
265,
63,
2593,
342,
267,
291,
14,
1633,
3489,
63,
4930,
275,
291,
14,
1633,
3489,
63,
4930,
63,
2373,
63,
11151,
342,
267,
291,
14,
4603,
1074,
63,
4930,
275,
291,
14,
1652,
63,
929,
14,
1506,
63,
466,
14,
362,
63,
4603,
1074,
342,
267,
291,
14,
13615,
63,
10409,
275,
291,
14,
1652,
63,
929,
14,
374,
63,
13615,
63,
10409,
342,
267,
291,
14,
26374,
275,
481,
18698,
55,
1530,
8,
288,
291,
14,
1652,
63,
929,
267,
776,
398,
291,
14,
6442,
63,
466,
275,
291,
14,
1652,
63,
929,
14,
1506,
63,
466,
14,
362,
63,
2469,
342,
267,
340,
440,
291,
14,
6442,
63,
466,
26,
288,
291,
14,
6442,
63,
466,
275,
7827,
14,
362,
63,
885,
63,
6442,
63,
4595,
63,
466,
342,
398,
291,
14,
2405,
63,
344,
275,
291,
14,
1652,
63,
929,
14,
1506,
63,
466,
14,
362,
63,
2392,
7401,
342,
503,
971,
288,
7827,
14,
362,
63,
2405,
63,
344,
342,
267,
291,
14,
3174,
63,
2392,
7401,
275,
291,
14,
1652,
63,
929,
14,
1506,
63,
466,
14,
362,
63,
2392,
7401,
342,
503,
971,
288,
7827,
14,
362,
63,
3174,
63,
2405,
63,
344,
342,
398,
291,
14,
6442,
63,
4930,
63,
1419,
275,
359,
288,
283,
1231,
29,
6442,
26,
7695,
13837,
3126,
16,
5285,
908,
8,
277,
14,
2405,
63,
344,
395,
288,
283,
6883,
14
] |
[
1898,
334,
67,
9,
6900,
428,
4701,
10130,
23428,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
1022,
73,
14249,
14,
199,
3,
199,
3,
1022,
73,
14249,
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,
1022,
73,
14249,
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,
1022,
73,
14249,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
3133,
199,
3,
199,
646,
747,
199,
646,
4298,
199,
646,
5739,
199,
504,
5055,
492,
8773,
199,
199,
3,
2199,
199,
504,
1022,
73,
14249,
14,
4930,
3422,
14,
888,
14,
1095,
492,
27324,
5455,
2028,
1563,
199,
504,
1022,
73,
14249,
14,
4930,
3422,
14,
1160,
14,
2587,
456,
18,
492,
27324,
5455,
4231,
23765,
456,
18,
199,
504,
1022,
73,
14249,
14,
1531,
492,
5817,
199,
504,
1022,
73,
14249,
14,
4322,
492,
7827,
199,
504,
1022,
73,
14249,
14,
26374,
492,
481,
18698,
55,
1530,
199,
504,
1022,
73,
14249,
14,
2921,
492,
943,
199,
504,
1022,
73,
14249,
14,
515,
492,
6912,
199,
504,
1022,
73,
14249,
14,
1208,
14,
5186,
492,
3918,
10878,
199,
504,
1022,
73,
14249,
14,
1208,
14,
24030,
492,
28766,
2028,
199,
199,
504,
1022,
73,
14249,
14,
3924,
492,
334,
272,
1804,
73,
14249,
4231,
547,
12,
272,
1804,
73,
14249,
17989,
5455,
23765,
456,
10397,
547,
12,
272,
1804,
73,
14249,
17989,
5455,
23765,
456,
17981,
547,
12,
272,
1804,
73,
14249,
17989,
5455,
23765,
456,
24117,
17989,
547,
12,
272,
1804,
73,
14249,
17989,
5455,
23765,
456,
6986,
547,
12,
199,
9,
421,
199,
533,
27324,
5455,
2028,
23765,
456,
18,
8,
17989,
5455,
2028,
1563,
304,
272,
408,
272,
1011,
2587,
456,
18,
8498,
3422,
2897,
14,
538,
272,
408,
272,
347,
2963,
63,
826,
8,
277,
12,
3537,
63,
589,
304,
267,
408,
267,
7192,
456,
18,
2963,
11097,
1083,
398,
520,
635,
1211,
3537,
63,
589,
26,
288,
22493,
7192,
456,
1101,
2368,
953,
2508,
1233,
447,
2366,
2234,
791,
2587,
456,
63,
3619,
63,
354,
356,
283,
2587,
456,
92,
2587,
456,
18,
936,
267,
408,
267,
291,
14,
4229,
63,
589,
275,
3537,
63,
589,
267,
3819,
275,
4298,
14,
6744,
342,
267,
340,
3819,
508,
283,
88,
1184,
63,
772,
356,
288,
327,
7192,
456,
18,
2291,
367,
330,
9207,
436,
325,
329,
10460,
288,
291,
14,
1047,
275,
3819,
267,
916,
3819,
14,
2460,
360,
20638,
772,
735,
288,
327,
7192,
456,
18,
2291,
367,
402,
87,
436,
1687,
279,
10460,
288,
291,
14,
1047,
275,
3819,
267,
916,
3819,
508,
283,
73,
10253,
7,
503,
3819,
508,
283,
73,
26888,
356,
288,
327,
7192,
456,
18,
2291,
367,
330,
9207,
10460,
288,
291,
14,
1047,
275,
283,
1148,
1184,
7,
267,
916,
3819,
508,
283,
65,
1047,
772,
7,
503,
3819,
14,
2460,
360,
5362,
735,
288,
327,
7192,
456,
18,
2291,
367,
325,
329,
10460,
288,
291,
14,
1047,
275,
3819,
267,
587,
26,
288,
746,
1804,
73,
14249,
17989,
5455,
23765,
456,
10397,
547,
8,
355,
283,
1102,
15931,
450,
83,
440,
3748,
367,
7192,
456,
18,
3272,
7,
450,
3819,
288,
776,
398,
340,
291,
14,
4229,
63,
589,
436,
283,
2587,
456,
63,
3619,
63,
354,
7,
315,
291,
14,
4229,
63,
589,
26,
288,
291,
14,
4930,
63,
3619,
63,
354,
275,
291,
14,
4229,
63,
589,
459,
2587,
456,
63,
3619,
63,
354,
418,
267,
587,
26,
288,
291,
14,
4930,
63,
3619,
63,
354,
275,
283,
2587,
456,
7,
398,
291,
14,
12010,
275,
291,
14,
1652,
63,
929,
14,
1506,
63,
466,
14,
362,
63,
4930,
3422,
63,
6614,
342,
971,
288,
503,
283,
7102,
31896,
7,
267,
291,
14,
7102,
88,
632,
275,
291,
14,
362,
63,
7102,
88,
632,
360,
2587,
456,
18,
358,
267,
291,
14,
7915,
275,
291,
14,
362,
63,
4930,
63,
7915,
342,
267,
291,
14,
2593,
275,
291,
14,
362,
63,
4930,
63,
2593,
63,
4515,
342,
267,
291,
14,
6958,
63,
265,
63,
2593,
275,
291,
14,
362,
63,
6958,
63,
265,
63,
2593,
342,
267,
291,
14,
1633,
3489,
63,
4930,
275,
291,
14,
1633,
3489,
63,
4930,
63,
2373,
63,
11151,
342,
267,
291,
14,
4603,
1074,
63,
4930,
275,
291,
14,
1652,
63,
929,
14,
1506,
63,
466,
14,
362,
63,
4603,
1074,
342,
267,
291,
14,
13615,
63,
10409,
275,
291,
14,
1652,
63,
929,
14,
374,
63,
13615,
63,
10409,
342,
267,
291,
14,
26374,
275,
481,
18698,
55,
1530,
8,
288,
291,
14,
1652,
63,
929,
267,
776,
398,
291,
14,
6442,
63,
466,
275,
291,
14,
1652,
63,
929,
14,
1506,
63,
466,
14,
362,
63,
2469,
342,
267,
340,
440,
291,
14,
6442,
63,
466,
26,
288,
291,
14,
6442,
63,
466,
275,
7827,
14,
362,
63,
885,
63,
6442,
63,
4595,
63,
466,
342,
398,
291,
14,
2405,
63,
344,
275,
291,
14,
1652,
63,
929,
14,
1506,
63,
466,
14,
362,
63,
2392,
7401,
342,
503,
971,
288,
7827,
14,
362,
63,
2405,
63,
344,
342,
267,
291,
14,
3174,
63,
2392,
7401,
275,
291,
14,
1652,
63,
929,
14,
1506,
63,
466,
14,
362,
63,
2392,
7401,
342,
503,
971,
288,
7827,
14,
362,
63,
3174,
63,
2405,
63,
344,
342,
398,
291,
14,
6442,
63,
4930,
63,
1419,
275,
359,
288,
283,
1231,
29,
6442,
26,
7695,
13837,
3126,
16,
5285,
908,
8,
277,
14,
2405,
63,
344,
395,
288,
283,
6883,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
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ader.py
|
5
|
25507
|
py_object = object
import pixie.vm.object as object
from pixie.vm.object import affirm, runtime_error
import pixie.vm.code as code
from pixie.vm.code import as_var
from pixie.vm.primitives import nil, true, false
import pixie.vm.numbers as numbers
from pixie.vm.cons import cons
from pixie.vm.symbol import symbol, Symbol
from pixie.vm.keyword import keyword, Keyword
import pixie.vm.rt as rt
from pixie.vm.persistent_vector import EMPTY as EMPTY_VECTOR
from pixie.vm.libs.libedit import _readline
from pixie.vm.string import Character
from pixie.vm.code import wrap_fn
from pixie.vm.persistent_hash_map import EMPTY as EMPTY_MAP
from pixie.vm.persistent_hash_set import EMPTY as EMPTY_SET
from pixie.vm.persistent_list import EmptyList
import pixie.vm.compiler as compiler
from rpython.rlib.rbigint import rbigint
from rpython.rlib.rsre import rsre_re as re
READING_FORM_VAR = code.intern_var(u"pixie.stdlib", u"*reading-form*")
READING_FORM_VAR.set_dynamic()
READING_FORM_VAR.set_root(false)
LINE_NUMBER_KW = keyword(u"line-number")
COLUMN_NUMBER_KW = keyword(u"column-number")
LINE_KW = keyword(u"line")
FILE_KW = keyword(u"file")
GEN_SYM_ENV = code.intern_var(u"pixie.stdlib.reader", u"*gen-sym-env*")
GEN_SYM_ENV.set_dynamic()
GEN_SYM_ENV.set_root(EMPTY_MAP)
ARG_AMP = symbol(u"&")
ARG_MAX = keyword(u"max-arg")
ARG_ENV = code.intern_var(u"pixie.stdlib.reader", u"*arg-env*")
ARG_ENV.set_dynamic()
ARG_ENV.set_root(nil)
class PlatformReader(object.Object):
_type = object.Type(u"PlatformReader")
def type(self):
return PlatformReader._type
def read(self):
assert False
def unread(self):
pass
def reset_line(self):
return self
class StringReader(PlatformReader):
_type = object.Type(u"pixie.stdlib.StringReader")
def type(self):
return StringReader._type
def __init__(self, s):
affirm(isinstance(s, unicode), u"StringReader requires unicode")
self._str = s
self._idx = 0
def read(self):
if self._idx >= len(self._str):
raise EOFError()
ch = self._str[self._idx]
self._idx += 1
return ch
def unread(self):
self._idx -= 1
class UserSpaceReader(PlatformReader):
def __init__(self, reader_fn):
self._string_reader = None
self._reader_fn = reader_fn
def read(self):
if self._string_reader is None:
result = rt.name(self._reader_fn.invoke([]))
code._dynamic_vars.set_var_value(READING_FORM_VAR, rt.wrap(READING_FORM_VAR.deref().int_val() + 1))
if result == u"":
raise EOFError()
self._string_reader = StringReader(result)
try:
return self._string_reader.read()
except EOFError:
self._string_reader = None
return self.read()
def reset_line(self):
self._string_reader = None
def unread(self):
assert self._string_reader is not None
self._string_reader.unread()
@as_var(u"reader-fn")
def reader_fn(fn):
"""(reader-fn f)
Creates a new reader that can be passed to read, that will call the given f when a new string
of input is needed."""
return MetaDataReader(UserSpaceReader(fn))
class LinePromise(object.Object):
_type = object.Type(u"pixie.stdlib.LinePromise")
def type(self):
return LinePromise._type
def __init__(self):
self._chrs = []
self._str = None
def add_char(self, ch):
self._chrs.append(ch)
def finalize(self):
if self._chrs is not None:
self._str = u"".join(self._chrs)
self._chrs = None
def is_finalized(self):
return self._chrs is None
def __repr__(self):
if self.is_finalized():
return self._str
return u"".join(self._chrs)
class MetaDataReader(PlatformReader):
"""Creates metadata for use by the debug system"""
def __init__(self, parent_reader, filename=u"<unknown>"):
assert isinstance(parent_reader, PlatformReader)
self._parent_reader = parent_reader
self._line_number = 1
self._column_number = 0
self._line = LinePromise()
self._has_unread = False
self._prev_line_number = 1
self._prev_column_number = 0
self._prev_line = None
self._prev_chr = u"\0"
self._filename = filename
assert isinstance(self._prev_chr, unicode)
def read(self):
if self._has_unread:
self._has_unread = False
return self._prev_chr
else:
self._prev_column_number = self._column_number
self._prev_line_number = self._line_number
self._prev_line = self._line
ch = self._parent_reader.read()
if self._line.is_finalized():
self._line = LinePromise()
if ch == u'\n':
self._line.finalize()
self._line_number += 1
self._column_number = 0
else:
self._line.add_char(ch)
self._column_number += 1
self._cur_ch = ch
return ch
def reset_line(self):
self._line.finalize()
self._line_number += 1
self._column_number = 0
self._parent_reader.reset_line()
return self
def get_metadata(self):
return rt.hashmap(LINE_KW, rt.wrap(self._line),
LINE_NUMBER_KW, rt.wrap(self._line_number),
COLUMN_NUMBER_KW, rt.wrap(self._column_number),
FILE_KW, rt.wrap(self._filename))
def unread(self):
affirm(not self._has_unread, u"Can't unread twice")
self._has_unread = True
self._prev_chr = self._cur_ch
#
#
# def reader_str_state(self):
# spaces = []
# for x in range(self._column_number - 1):
# spaces.append(u" ")
#
# return u"in " + self._filename + \
# u" at " + unicode(str(self._line_number)) + u":" + unicode(str(self._column_number)) + u"\n" \
# + self._line.reader_string_state() + u"\n" + u"".join(spaces) + u"^"
def is_whitespace(ch):
return ch in u"\r\n\t ," or ch == u""
def is_digit(ch):
return ch in u"0123456789"
def is_terminating_macro(ch):
return ch != u"#" and ch != u"'" and ch != u"%" and ch in handlers
def eat_whitespace(rdr):
while True:
ch = rdr.read()
if is_whitespace(ch):
continue
rdr.unread()
return
class ReaderHandler(py_object):
def invoke(self, rdr, ch):
pass
class ListReader(ReaderHandler):
def invoke(self, rdr, ch):
lst = []
while True:
try:
eat_whitespace(rdr)
except EOFError:
throw_syntax_error_with_data(rdr, u"Unmatched list open '('")
ch = rdr.read()
if ch == u")":
if len(lst) == 0:
return EmptyList()
acc = nil
for x in range(len(lst) - 1, -1, -1):
acc = cons(lst[x], acc)
return acc
rdr.unread()
itm = read_inner(rdr, True, always_return_form=False)
if itm != rdr:
lst.append(itm)
class UnmatchedListReader(ReaderHandler):
def invoke(self, rdr, ch):
throw_syntax_error_with_data(rdr, u"Unmatched list close ')'")
class VectorReader(ReaderHandler):
def invoke(self, rdr, ch):
acc = EMPTY_VECTOR
while True:
try:
eat_whitespace(rdr)
except EOFError:
rdr
throw_syntax_error_with_data(rdr, u"Unmatched vector open '['")
ch = rdr.read()
if ch == u"]":
return acc
rdr.unread()
itm = read_inner(rdr, True, always_return_form=False)
if itm != rdr:
acc = rt.conj(acc, itm)
class UnmatchedVectorReader(ReaderHandler):
def invoke(self, rdr, ch):
throw_syntax_error_with_data(rdr, u"Unmatched vector close ']'")
class MapReader(ReaderHandler):
def invoke(self, rdr, ch):
acc = EMPTY_MAP
while True:
try:
eat_whitespace(rdr)
except EOFError:
throw_syntax_error_with_data(rdr, u"Unmatched map open '{'")
ch = rdr.read()
if ch == u"}":
return acc
rdr.unread()
itm = read_inner(rdr, True, always_return_form=False)
if itm != rdr:
k = itm
itm = rdr
while itm == rdr:
itm = read_inner(rdr, False, always_return_form=False)
v = itm
acc = rt._assoc(acc, k, v)
return acc
class UnmatchedMapReader(ReaderHandler):
def invoke(self, rdr, ch):
affirm(False, u"Unmatched Map brace '}'")
class QuoteReader(ReaderHandler):
def invoke(self, rdr, ch):
itm = read_inner(rdr, True)
return cons(symbol(u"quote"), cons(itm))
class KeywordReader(ReaderHandler):
def fqd(self, itm):
ns_alias = rt.namespace(itm)
current_nms = rt.ns.deref()
if ns_alias is None:
return keyword(rt.name(itm), rt.name(current_nms))
else:
ns_fqd = current_nms.resolve_ns(ns_alias)
return keyword(rt.name(itm), rt.name(ns_fqd))
def invoke(self, rdr, ch):
ch = rdr.read()
if ch == u":":
itm = read_inner(rdr, True)
return self.fqd(itm)
else:
rdr.unread()
itm = read_inner(rdr, True)
return keyword(rt.name(itm), rt.namespace(itm))
class LiteralStringReader(ReaderHandler):
def invoke(self, rdr, ch):
acc = []
# TODO: implement escape characters
while True:
try:
v = rdr.read()
except EOFError:
return throw_syntax_error_with_data(rdr, u"Unmatched string quote '\"'")
if v == "\"":
return rt.wrap(u"".join(acc))
elif v == "\\":
#inside escape... TODO handle everything.
try:
v = rdr.read()
if v == "\"":
acc.append("\"")
elif v == "\\":
acc.append("\\")
elif v == "n":
acc.append("\n")
elif v == "r":
acc.append("\r")
elif v == "t":
acc.append("\t")
else:
throw_syntax_error_with_data(rdr, u"unhandled escape character: " + v)
except EOFError:
throw_syntax_error_with_data(rdr, u"eof after escape character")
else:
acc.append(v)
def read_token(rdr):
acc = rdr.read()
while True:
ch = rdr.read()
if is_whitespace(ch) or is_terminating_macro(ch):
rdr.unread()
return acc
acc += ch
def read_unicode_char(rdr, token, offset, length, base):
if len(token) != offset + length:
throw_syntax_error_with_data(rdr, u"Invalid unicode character: \\" + token)
c = 0
for i in range(offset, offset + length):
d = int(str(token[i:i+1]), base)
c = c * base + d
return c
class LiteralCharacterReader(ReaderHandler):
def invoke(self, rdr, ch):
token = read_token(rdr)
if len(token) == 1:
return Character(ord(token[0]))
elif token == u"newline":
return Character(ord("\n"))
elif token == u"space":
return Character(ord(" "))
elif token == u"tab":
return Character(ord("\t"))
elif token == u"backspace":
return Character(ord("\b"))
elif token == u"formfeed":
return Character(ord("\f"))
elif token == u"return":
return Character(ord("\r"))
elif token.startswith("u"):
c = read_unicode_char(rdr, token, 1, 4, 16)
if c >= 0xd800 and c <= 0xdfff:
throw_syntax_error_with_data(rdr, u"Invalid character constant: \\" + token)
return Character(c)
elif token.startswith("o"):
l = len(token) - 1
if l > 3:
throw_syntax_error_with_data(rdr, u"Invalid octal escape sequence: \\" + token)
c = read_unicode_char(rdr, token, 1, l, 8)
if c > 0377:
throw_syntax_error_with_data(rdr, u"Octal escape sequences must be in range [0, 377]")
return Character(c)
else:
throw_syntax_error_with_data(rdr, u"Unsupported character: \\" + token)
class DerefReader(ReaderHandler):
def invoke(self, rdr, ch):
return rt.cons(symbol(u"-deref"), rt.cons(read_inner(rdr, True), nil))
QUOTE = symbol(u"quote")
UNQUOTE = symbol(u"unquote")
UNQUOTE_SPLICING = symbol(u"unquote-splicing")
APPLY = symbol(u"apply")
CONCAT = symbol(u"concat")
SEQ = symbol(u"seq")
LIST = symbol(u"list")
def is_unquote(form):
return True if rt._satisfies_QMARK_(rt.ISeq.deref(), form) \
and rt.eq(rt.first(form), UNQUOTE) \
else False
def is_unquote_splicing(form):
return True if rt._satisfies_QMARK_(rt.ISeq.deref(), form) \
and rt.eq(rt.first(form), UNQUOTE_SPLICING) \
else False
class SyntaxQuoteReader(ReaderHandler):
def invoke(self, rdr, ch):
form = read_inner(rdr, True)
with code.bindings(GEN_SYM_ENV, EMPTY_MAP):
result = self.syntax_quote(form)
return result
@staticmethod
def syntax_quote(form):
if isinstance(form, Symbol) and compiler.is_compiler_special(form):
ret = rt.list(QUOTE, form)
elif isinstance(form, Symbol):
if rt.namespace(form) is None and rt.name(form).endswith("#"):
gmap = rt.deref(GEN_SYM_ENV)
affirm(gmap is not nil, u"Gensym literal used outside a syntax quote")
gs = rt.get(gmap, form)
if gs is nil:
gs = rt.symbol(rt.str(form, rt.wrap(u"__"), rt.gensym()))
GEN_SYM_ENV.set_value(rt.assoc(gmap, form, gs))
form = gs
else:
var = rt.resolve_in(compiler.NS_VAR.deref(), form)
if var is nil:
form = rt.symbol(rt.str(rt.wrap(rt.name(rt.deref(compiler.NS_VAR))), rt.wrap(u"/"), form))
else:
form = rt.symbol(rt.str(rt.wrap(rt.namespace(var)), rt.wrap(u"/"), rt.str(rt.wrap(rt.name(var)))))
ret = rt.list(QUOTE, form)
elif is_unquote(form):
ret = rt.first(rt.next(form))
elif is_unquote_splicing(form):
return runtime_error(u"Unquote splicing not used inside list")
elif rt.vector_QMARK_(form) is true:
ret = rt.list(APPLY, CONCAT, SyntaxQuoteReader.expand_list(form))
elif form is not nil and rt.seq_QMARK_(form) is true:
ret = rt.list(APPLY, LIST, rt.cons(CONCAT, SyntaxQuoteReader.expand_list(rt.seq(form))))
else:
ret = rt.list(QUOTE, form)
return ret
@staticmethod
def expand_list(form):
return rt.reduce(expand_list_rfn, EMPTY_VECTOR, form)
@wrap_fn
def expand_list_rfn(ret, item):
if is_unquote(item):
ret = rt.conj(ret, rt.vector(rt.first(rt.next(item))))
elif is_unquote_splicing(item):
ret = rt.conj(ret, rt.first(rt.next(item)))
else:
ret = rt.conj(ret, rt.vector(SyntaxQuoteReader.syntax_quote(item)))
return ret
class UnquoteReader(ReaderHandler):
def invoke(self, rdr, ch):
ch = rdr.read()
sym = UNQUOTE
if ch == "@":
sym = UNQUOTE_SPLICING
else:
rdr.unread()
form = read_inner(rdr, True)
return rt.list(sym, form)
class MetaReader(ReaderHandler):
def invoke(self, rdr, ch):
meta = read_inner(rdr, True)
obj = read_inner(rdr, True)
if isinstance(meta, Keyword):
meta = rt.hashmap(meta, true)
if isinstance(meta, Symbol):
meta = rt.hashmap(keyword(u"tag"), meta)
if rt._satisfies_QMARK_(rt.IMeta.deref(), obj):
return rt.with_meta(obj, rt.merge(meta, rt.meta(obj)))
return obj
class ArgReader(ReaderHandler):
def invoke(self, rdr, ch):
if ARG_ENV.deref() is nil:
return read_symbol(rdr, ch)
ch = rdr.read()
rdr.unread()
if is_whitespace(ch) or is_terminating_macro(ch):
return ArgReader.register_next_arg(1)
n = read_inner(rdr, True)
if rt.eq(n, ARG_AMP):
return ArgReader.register_next_arg(-1)
if not isinstance(n, numbers.Integer):
throw_syntax_error_with_data(rdr, u"%-arg must be %, %<integer> or %&")
return ArgReader.register_next_arg(n.int_val())
@staticmethod
def register_next_arg(n):
arg_env = ARG_ENV.deref()
max_arg = rt.get(arg_env, ARG_MAX)
if n > max_arg.int_val():
arg_env = rt.assoc(arg_env, ARG_MAX, rt.wrap(n))
arg = rt.get(arg_env, rt.wrap(n), nil)
if arg is nil:
arg = ArgReader.gen_arg(n)
arg_env = rt.assoc(arg_env, rt.wrap(n), arg)
ARG_ENV.set_value(arg_env)
return arg
@staticmethod
def gen_arg(n):
s = unicode(str(n))
if n == -1:
s = u"_rest"
return rt.gensym(rt.wrap(u"arg" + s + u"__"))
class FnReader(ReaderHandler):
def invoke(self, rdr, ch):
if ARG_ENV.deref() is not nil:
throw_syntax_error_with_data(rdr, u"Nested #()s are not allowed")
try:
ARG_ENV.set_value(rt.assoc(EMPTY_MAP, ARG_MAX, rt.wrap(-1)))
rdr.unread()
form = read_inner(rdr, True)
args = EMPTY_VECTOR
percent_args = ARG_ENV.deref()
max_arg = rt.get(percent_args, ARG_MAX)
for i in range(1, max_arg.int_val() + 1):
arg = rt.get(percent_args, rt.wrap(i))
if arg is nil:
arg = ArgReader.gen_arg(i)
args = rt.conj(args, arg)
rest_arg = rt.get(percent_args, rt.wrap(-1))
if rest_arg is not nil:
args = rt.conj(args, ARG_AMP)
args = rt.conj(args, rest_arg)
return rt.cons(symbol(u"fn*"), rt.cons(args, rt.cons(form, nil)))
finally:
ARG_ENV.set_value(nil)
class SetReader(ReaderHandler):
def invoke(self, rdr, ch):
acc = EMPTY_SET
while True:
try:
eat_whitespace(rdr)
except EOFError:
throw_syntax_error_with_data(rdr, u"Unmatched set open '#{'")
ch = rdr.read()
if ch == u"}":
return acc
rdr.unread()
itm = read_inner(rdr, True, always_return_form=False)
if itm != rdr:
acc = acc.conj(itm)
class CommentReader(ReaderHandler):
def invoke(self, rdr, ch):
read_inner(rdr, True, always_return_form=True)
return rdr
dispatch_handlers = {
u"{": SetReader(),
u"(": FnReader(),
u"_": CommentReader()
}
class DispatchReader(ReaderHandler):
def invoke(self, rdr, ch):
ch = rdr.read()
handler = dispatch_handlers.get(ch, None)
if handler is None:
return throw_syntax_error_with_data(rdr, u"unknown dispatch #" + ch)
return handler.invoke(rdr, ch)
class LineCommentReader(ReaderHandler):
def invoke(self, rdr, ch):
self.skip_line(rdr)
return rdr
def skip_line(self, rdr):
while True:
ch = rdr.read()
if ch == u"\n":
return
handlers = {u"(": ListReader(),
u")": UnmatchedListReader(),
u"[": VectorReader(),
u"]": UnmatchedVectorReader(),
u"{": MapReader(),
u"}": UnmatchedMapReader(),
u"'": QuoteReader(),
u":": KeywordReader(),
u"\"": LiteralStringReader(),
u"\\": LiteralCharacterReader(),
u"@": DerefReader(),
u"`": SyntaxQuoteReader(),
u"~": UnquoteReader(),
u"^": MetaReader(),
u"#": DispatchReader(),
u";": LineCommentReader(),
u"%": ArgReader()
}
# inspired by https://github.com/clojure/tools.reader/blob/9ee11ed/src/main/clojure/clojure/tools/reader/impl/commons.clj#L45
# sign hex oct radix decimal biginteger
# 1 2 3 4 5 6 7 8
int_matcher = re.compile(u'^([-+]?)(?:(0[xX])([0-9a-fA-F]+)|0([0-7]+)|([1-9][0-9]?)[rR]([0-9a-zA-Z]+)|([0-9]*))(N)?$')
float_matcher = re.compile(u'^([-+]?[0-9]+(\.[0-9]*)?([eE][-+]?[0-9]+)?)$')
ratio_matcher = re.compile(u'^([-+]?[0-9]+)/([0-9]+)$')
def parse_int(m):
sign = 1
if m.group(1) == u'-':
sign = -1
radix = 10
if m.group(7):
num = m.group(7)
elif m.group(2):
radix = 16
num = m.group(3)
elif m.group(4):
radix = 8
num = m.group(4)
elif m.group(5):
radix = int(m.group(5))
num = m.group(6)
else:
return None
if m.group(8):
return rt.wrap(rbigint.fromstr(str(m.group(1) + num), radix))
else:
return rt.wrap(sign * int(str(num), radix))
def parse_float(m):
return rt.wrap(float(str(m.group(0))))
def parse_ratio(m):
n = rt.wrap(int(str(m.group(1))))
d = rt.wrap(int(str(m.group(2))))
return rt._div(n, d)
def parse_number(s):
m = int_matcher.match(s)
if m:
return parse_int(m)
else:
m = float_matcher.match(s)
if m:
return parse_float(m)
else:
m = ratio_matcher.match(s)
if m:
return parse_ratio(m)
else:
return None
def read_number(rdr, ch):
acc = [ch]
try:
while True:
ch = rdr.read()
if is_whitespace(ch) or ch in handlers:
rdr.unread()
break
acc.append(ch)
except EOFError:
pass
joined = u"".join(acc)
parsed = parse_number(joined)
if parsed is not None:
return parsed
return Symbol(joined)
def read_symbol(rdr, ch):
acc = [ch]
try:
while True:
ch = rdr.read()
if is_whitespace(ch) or is_terminating_macro(ch):
rdr.unread()
break
acc.append(ch)
except EOFError:
pass
sym_str = u"".join(acc)
if sym_str == u"true":
return true
if sym_str == u"false":
return false
if sym_str == u"nil":
return nil
return symbol(sym_str)
class EOF(object.Object):
_type = object.Type(u"EOF")
def type(self):
return EOF._type
eof = EOF()
code.intern_var(u"pixie.stdlib", u"eof").set_root(eof)
def throw_syntax_error_with_data(rdr, txt):
assert isinstance(txt, unicode)
if isinstance(rdr, MetaDataReader):
meta = rdr.get_metadata()
else:
meta = nil
data = rt.interpreter_code_info(meta)
err = object.runtime_error(txt)
err._trace.append(data)
raise object.WrappedException(err)
def read_inner(rdr, error_on_eof, always_return_form=True):
try:
eat_whitespace(rdr)
except EOFError as ex:
if error_on_eof:
runtime_error(u"Unexpected EOF while reading",
u"pixie.stdlib/EOFWhileReadingException")
return eof
ch = rdr.read()
if isinstance(rdr, MetaDataReader):
meta = rdr.get_metadata()
else:
meta = nil
macro = handlers.get(ch, None)
if macro is not None:
itm = macro.invoke(rdr, ch)
if always_return_form and itm == rdr:
return read_inner(rdr, error_on_eof, always_return_form=always_return_form)
elif is_digit(ch):
itm = read_number(rdr, ch)
elif ch == u"-":
ch2 = rdr.read()
if is_digit(ch2):
rdr.unread()
itm = read_number(rdr, ch)
else:
rdr.unread()
itm = read_symbol(rdr, ch)
else:
itm = read_symbol(rdr, ch)
if itm != rdr:
if rt.has_meta_QMARK_(itm):
itm = rt.with_meta(itm, rt.merge(meta, rt.meta(itm)))
return itm
def read(rdr, error_on_eof):
code._dynamic_vars.push_binding_frame()
code._dynamic_vars.set_var_value(READING_FORM_VAR, rt.wrap(0))
try:
form = read_inner(rdr, error_on_eof)
return form
finally:
code._dynamic_vars.pop_binding_frame()
@as_var("read")
def _read_(rdr, error_on_eof):
"""(read rdr error-on-eof)
Reads a single form from the input reader. If error-on-eof is true, an error will be thrown if eof is reached
and a valid form has not been parsed. Else will return eof"""
assert isinstance(rdr, PlatformReader)
return read(rdr, rt.is_true(error_on_eof))
|
lgpl-3.0
|
[
647,
63,
785,
275,
909,
199,
646,
25505,
1873,
14,
2611,
14,
785,
465,
909,
199,
504,
25505,
1873,
14,
2611,
14,
785,
492,
15871,
6022,
12,
8836,
63,
705,
199,
646,
25505,
1873,
14,
2611,
14,
600,
465,
1233,
199,
504,
25505,
1873,
14,
2611,
14,
600,
492,
465,
63,
1391,
199,
504,
25505,
1873,
14,
2611,
14,
1359,
22337,
492,
32644,
12,
2549,
12,
3055,
199,
646,
25505,
1873,
14,
2611,
14,
10548,
465,
5579,
199,
504,
25505,
1873,
14,
2611,
14,
8704,
492,
13447,
199,
504,
25505,
1873,
14,
2611,
14,
5155,
492,
5272,
12,
10080,
199,
504,
25505,
1873,
14,
2611,
14,
6691,
492,
4252,
12,
6431,
199,
646,
25505,
1873,
14,
2611,
14,
2591,
465,
14059,
199,
504,
25505,
1873,
14,
2611,
14,
18539,
63,
4106,
492,
16589,
465,
16589,
63,
2524,
1028,
726,
199,
504,
25505,
1873,
14,
2611,
14,
8450,
14,
773,
3773,
492,
485,
6407,
199,
504,
25505,
1873,
14,
2611,
14,
875,
492,
17660,
199,
504,
25505,
1873,
14,
2611,
14,
600,
492,
4816,
63,
2324,
199,
504,
25505,
1873,
14,
2611,
14,
18539,
63,
2227,
63,
1130,
492,
16589,
465,
16589,
63,
5443,
199,
504,
25505,
1873,
14,
2611,
14,
18539,
63,
2227,
63,
409,
492,
16589,
465,
16589,
63,
3597,
199,
504,
25505,
1873,
14,
2611,
14,
18539,
63,
513,
492,
9630,
1296,
199,
646,
25505,
1873,
14,
2611,
14,
5772,
465,
6365,
199,
199,
504,
519,
1548,
14,
82,
773,
14,
4848,
528,
442,
492,
519,
24884,
199,
504,
519,
1548,
14,
82,
773,
14,
2393,
264,
492,
10717,
264,
63,
264,
465,
295,
199,
199,
5670,
1206,
63,
3516,
63,
5568,
275,
1233,
14,
4404,
63,
1391,
8,
85,
2,
6644,
1873,
14,
28683,
401,
399,
31761,
19332,
13,
964,
10,
531,
199,
5670,
1206,
63,
3516,
63,
5568,
14,
409,
63,
7764,
342,
199,
5670,
1206,
63,
3516,
63,
5568,
14,
409,
63,
1231,
8,
3910,
9,
199,
199,
6174,
63,
9190,
63,
25114,
275,
4252,
8,
85,
2,
604,
13,
1955,
531,
199,
21436,
63,
9190,
63,
25114,
275,
4252,
8,
85,
2,
2301,
13,
1955,
531,
199,
6174,
63,
25114,
275,
4252,
8,
85,
2,
604,
531,
199,
3817,
63,
25114,
275,
4252,
8,
85,
2,
493,
531,
199,
199,
9289,
63,
30637,
63,
9984,
275,
1233,
14,
4404,
63,
1391,
8,
85,
2,
6644,
1873,
14,
28683,
14,
5503,
401,
399,
31761,
2268,
13,
3840,
13,
1813,
10,
531,
199,
9289,
63,
30637,
63,
9984,
14,
409,
63,
7764,
342,
199,
9289,
63,
30637,
63,
9984,
14,
409,
63,
1231,
8,
13993,
63,
5443,
9,
199,
199,
11611,
63,
7089,
275,
5272,
8,
85,
2,
6,
531,
199,
11611,
63,
4283,
275,
4252,
8,
85,
2,
988,
13,
1273,
531,
199,
11611,
63,
9984,
275,
1233,
14,
4404,
63,
1391,
8,
85,
2,
6644,
1873,
14,
28683,
14,
5503,
401,
399,
31761,
1273,
13,
1813,
10,
531,
199,
11611,
63,
9984,
14,
409,
63,
7764,
342,
199,
11611,
63,
9984,
14,
409,
63,
1231,
8,
20613,
9,
199,
199,
533,
16078,
5929,
8,
785,
14,
1692,
304,
272,
485,
466,
275,
909,
14,
804,
8,
85,
2,
10397,
5929,
531,
339,
347,
730,
8,
277,
304,
267,
372,
16078,
5929,
423,
466,
339,
347,
1586,
8,
277,
304,
267,
702,
756,
339,
347,
625,
739,
8,
277,
304,
267,
986,
339,
347,
5305,
63,
604,
8,
277,
304,
267,
372,
291,
199,
199,
533,
2624,
5929,
8,
10397,
5929,
304,
272,
485,
466,
275,
909,
14,
804,
8,
85,
2,
6644,
1873,
14,
28683,
14,
1558,
5929,
531,
272,
347,
730,
8,
277,
304,
267,
372,
2624,
5929,
423,
466,
339,
347,
636,
826,
721,
277,
12,
308,
304,
267,
15871,
6022,
8,
6074,
8,
83,
12,
2649,
395,
399,
2,
1558,
5929,
5074,
2649,
531,
267,
291,
423,
495,
275,
308,
267,
291,
423,
2996,
275,
378,
339,
347,
1586,
8,
277,
304,
267,
340,
291,
423,
2996,
2356,
822,
8,
277,
423,
495,
304,
288,
746,
21157,
342,
267,
682,
275,
291,
423,
495,
59,
277,
423,
2996,
61,
267,
291,
423,
2996,
847,
413,
267,
372,
682,
339,
347,
625,
739,
8,
277,
304,
267,
291,
423,
2996,
4862,
413,
199,
199,
533,
2876,
7643,
5929,
8,
10397,
5929,
304,
272,
347,
636,
826,
721,
277,
12,
7002,
63,
2324,
304,
267,
291,
423,
875,
63,
5503,
275,
488,
267,
291,
423,
5503,
63,
2324,
275,
7002,
63,
2324,
2378,
347,
1586,
8,
277,
304,
267,
340,
291,
423,
875,
63,
5503,
365,
488,
26,
288,
754,
275,
14059,
14,
354,
8,
277,
423,
5503,
63,
2324,
14,
15195,
26064,
288,
1233,
423,
7764,
63,
2936,
14,
409,
63,
1391,
63,
585,
8,
5670,
1206,
63,
3516,
63,
5568,
12,
14059,
14,
3823,
8,
5670,
1206,
63,
3516,
63,
5568,
14,
29176,
1252,
442,
63,
637,
342,
435,
413,
430,
288,
340,
754,
508,
399,
29679,
355,
746,
21157,
342,
288,
291,
423,
875,
63,
5503,
275,
2624,
5929,
8,
1099,
9,
398,
862,
26,
288,
372,
291,
423,
875,
63,
5503,
14,
739,
342,
267,
871,
21157,
26,
288,
291,
423,
875,
63,
5503,
275,
488,
288,
372,
291,
14,
739,
342,
339,
347,
5305,
63,
604,
8,
277,
304,
267,
291,
423,
875,
63,
5503,
275,
488,
339,
347,
625,
739,
8,
277,
304,
267,
702,
291,
423,
875,
63,
5503,
365,
440,
488,
267,
291,
423,
875,
63,
5503,
14,
28677,
342,
199,
199,
32,
305,
63,
1391,
8,
85,
2,
5503,
13,
2324,
531,
199,
318,
7002,
63,
2324,
8,
2324,
304,
272,
408,
8,
5503,
13,
2324,
289,
9,
272,
10560,
282,
892,
7002,
626,
883,
506,
3032,
370,
1586,
12,
626,
911,
1240,
314,
1627,
289,
1380,
282,
892,
1059,
272,
402,
1324,
365,
4346,
1041,
272,
372,
24905,
5929,
8,
1899,
7643,
5929,
8,
2324,
430,
199,
199,
533,
7030,
32303,
8,
785,
14,
1692,
304,
272,
485,
466,
275,
909,
14,
804,
8,
85,
2,
6644,
1873,
14,
28683,
14,
3049,
32303,
531,
272,
347,
730,
8,
277,
304,
267,
372,
7030,
32303,
423,
466,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
335
] |
[
63,
785,
275,
909,
199,
646,
25505,
1873,
14,
2611,
14,
785,
465,
909,
199,
504,
25505,
1873,
14,
2611,
14,
785,
492,
15871,
6022,
12,
8836,
63,
705,
199,
646,
25505,
1873,
14,
2611,
14,
600,
465,
1233,
199,
504,
25505,
1873,
14,
2611,
14,
600,
492,
465,
63,
1391,
199,
504,
25505,
1873,
14,
2611,
14,
1359,
22337,
492,
32644,
12,
2549,
12,
3055,
199,
646,
25505,
1873,
14,
2611,
14,
10548,
465,
5579,
199,
504,
25505,
1873,
14,
2611,
14,
8704,
492,
13447,
199,
504,
25505,
1873,
14,
2611,
14,
5155,
492,
5272,
12,
10080,
199,
504,
25505,
1873,
14,
2611,
14,
6691,
492,
4252,
12,
6431,
199,
646,
25505,
1873,
14,
2611,
14,
2591,
465,
14059,
199,
504,
25505,
1873,
14,
2611,
14,
18539,
63,
4106,
492,
16589,
465,
16589,
63,
2524,
1028,
726,
199,
504,
25505,
1873,
14,
2611,
14,
8450,
14,
773,
3773,
492,
485,
6407,
199,
504,
25505,
1873,
14,
2611,
14,
875,
492,
17660,
199,
504,
25505,
1873,
14,
2611,
14,
600,
492,
4816,
63,
2324,
199,
504,
25505,
1873,
14,
2611,
14,
18539,
63,
2227,
63,
1130,
492,
16589,
465,
16589,
63,
5443,
199,
504,
25505,
1873,
14,
2611,
14,
18539,
63,
2227,
63,
409,
492,
16589,
465,
16589,
63,
3597,
199,
504,
25505,
1873,
14,
2611,
14,
18539,
63,
513,
492,
9630,
1296,
199,
646,
25505,
1873,
14,
2611,
14,
5772,
465,
6365,
199,
199,
504,
519,
1548,
14,
82,
773,
14,
4848,
528,
442,
492,
519,
24884,
199,
504,
519,
1548,
14,
82,
773,
14,
2393,
264,
492,
10717,
264,
63,
264,
465,
295,
199,
199,
5670,
1206,
63,
3516,
63,
5568,
275,
1233,
14,
4404,
63,
1391,
8,
85,
2,
6644,
1873,
14,
28683,
401,
399,
31761,
19332,
13,
964,
10,
531,
199,
5670,
1206,
63,
3516,
63,
5568,
14,
409,
63,
7764,
342,
199,
5670,
1206,
63,
3516,
63,
5568,
14,
409,
63,
1231,
8,
3910,
9,
199,
199,
6174,
63,
9190,
63,
25114,
275,
4252,
8,
85,
2,
604,
13,
1955,
531,
199,
21436,
63,
9190,
63,
25114,
275,
4252,
8,
85,
2,
2301,
13,
1955,
531,
199,
6174,
63,
25114,
275,
4252,
8,
85,
2,
604,
531,
199,
3817,
63,
25114,
275,
4252,
8,
85,
2,
493,
531,
199,
199,
9289,
63,
30637,
63,
9984,
275,
1233,
14,
4404,
63,
1391,
8,
85,
2,
6644,
1873,
14,
28683,
14,
5503,
401,
399,
31761,
2268,
13,
3840,
13,
1813,
10,
531,
199,
9289,
63,
30637,
63,
9984,
14,
409,
63,
7764,
342,
199,
9289,
63,
30637,
63,
9984,
14,
409,
63,
1231,
8,
13993,
63,
5443,
9,
199,
199,
11611,
63,
7089,
275,
5272,
8,
85,
2,
6,
531,
199,
11611,
63,
4283,
275,
4252,
8,
85,
2,
988,
13,
1273,
531,
199,
11611,
63,
9984,
275,
1233,
14,
4404,
63,
1391,
8,
85,
2,
6644,
1873,
14,
28683,
14,
5503,
401,
399,
31761,
1273,
13,
1813,
10,
531,
199,
11611,
63,
9984,
14,
409,
63,
7764,
342,
199,
11611,
63,
9984,
14,
409,
63,
1231,
8,
20613,
9,
199,
199,
533,
16078,
5929,
8,
785,
14,
1692,
304,
272,
485,
466,
275,
909,
14,
804,
8,
85,
2,
10397,
5929,
531,
339,
347,
730,
8,
277,
304,
267,
372,
16078,
5929,
423,
466,
339,
347,
1586,
8,
277,
304,
267,
702,
756,
339,
347,
625,
739,
8,
277,
304,
267,
986,
339,
347,
5305,
63,
604,
8,
277,
304,
267,
372,
291,
199,
199,
533,
2624,
5929,
8,
10397,
5929,
304,
272,
485,
466,
275,
909,
14,
804,
8,
85,
2,
6644,
1873,
14,
28683,
14,
1558,
5929,
531,
272,
347,
730,
8,
277,
304,
267,
372,
2624,
5929,
423,
466,
339,
347,
636,
826,
721,
277,
12,
308,
304,
267,
15871,
6022,
8,
6074,
8,
83,
12,
2649,
395,
399,
2,
1558,
5929,
5074,
2649,
531,
267,
291,
423,
495,
275,
308,
267,
291,
423,
2996,
275,
378,
339,
347,
1586,
8,
277,
304,
267,
340,
291,
423,
2996,
2356,
822,
8,
277,
423,
495,
304,
288,
746,
21157,
342,
267,
682,
275,
291,
423,
495,
59,
277,
423,
2996,
61,
267,
291,
423,
2996,
847,
413,
267,
372,
682,
339,
347,
625,
739,
8,
277,
304,
267,
291,
423,
2996,
4862,
413,
199,
199,
533,
2876,
7643,
5929,
8,
10397,
5929,
304,
272,
347,
636,
826,
721,
277,
12,
7002,
63,
2324,
304,
267,
291,
423,
875,
63,
5503,
275,
488,
267,
291,
423,
5503,
63,
2324,
275,
7002,
63,
2324,
2378,
347,
1586,
8,
277,
304,
267,
340,
291,
423,
875,
63,
5503,
365,
488,
26,
288,
754,
275,
14059,
14,
354,
8,
277,
423,
5503,
63,
2324,
14,
15195,
26064,
288,
1233,
423,
7764,
63,
2936,
14,
409,
63,
1391,
63,
585,
8,
5670,
1206,
63,
3516,
63,
5568,
12,
14059,
14,
3823,
8,
5670,
1206,
63,
3516,
63,
5568,
14,
29176,
1252,
442,
63,
637,
342,
435,
413,
430,
288,
340,
754,
508,
399,
29679,
355,
746,
21157,
342,
288,
291,
423,
875,
63,
5503,
275,
2624,
5929,
8,
1099,
9,
398,
862,
26,
288,
372,
291,
423,
875,
63,
5503,
14,
739,
342,
267,
871,
21157,
26,
288,
291,
423,
875,
63,
5503,
275,
488,
288,
372,
291,
14,
739,
342,
339,
347,
5305,
63,
604,
8,
277,
304,
267,
291,
423,
875,
63,
5503,
275,
488,
339,
347,
625,
739,
8,
277,
304,
267,
702,
291,
423,
875,
63,
5503,
365,
440,
488,
267,
291,
423,
875,
63,
5503,
14,
28677,
342,
199,
199,
32,
305,
63,
1391,
8,
85,
2,
5503,
13,
2324,
531,
199,
318,
7002,
63,
2324,
8,
2324,
304,
272,
408,
8,
5503,
13,
2324,
289,
9,
272,
10560,
282,
892,
7002,
626,
883,
506,
3032,
370,
1586,
12,
626,
911,
1240,
314,
1627,
289,
1380,
282,
892,
1059,
272,
402,
1324,
365,
4346,
1041,
272,
372,
24905,
5929,
8,
1899,
7643,
5929,
8,
2324,
430,
199,
199,
533,
7030,
32303,
8,
785,
14,
1692,
304,
272,
485,
466,
275,
909,
14,
804,
8,
85,
2,
6644,
1873,
14,
28683,
14,
3049,
32303,
531,
272,
347,
730,
8,
277,
304,
267,
372,
7030,
32303,
423,
466,
339,
347,
636,
826,
721,
277,
304,
267,
291,
423,
335,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
takinbo/rapidsms-borno
|
apps/ajax/app.py
|
5
|
8308
|
#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4
import rapidsms
import cgi, urlparse, traceback
from threading import Thread
from SocketServer import ThreadingMixIn
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from django.utils.simplejson import JSONEncoder
from django.db.models.query import QuerySet
class App(rapidsms.app.App):
"""This App does nothing by itself. It exists only to serve other Apps, by
providing an easy (and standard) way for them to communicate between their
WebUI and RapidSMS App object.
When RapidSMS starts, this app starts an HTTPServer (port 8001 as default,
but configurable via rapidsms.ini) in a worker thread, and watches for any
incoming HTTP requests matching */app/method*. These requests, along with
their GET parameters and POST form, are passed on to the named app.
Examples:
method URL app method args
====== === === ====== ====
GET /breakfast/toast breakfast ajax_GET_toast { }
POST /breakfast/waffles breakfast ajax_POST_waffles { }, { }
POST /breakfast/eggs?x=1 breakfast ajax_POST_eggs { "x": 1 }, {}
Any data that is returned by the handler method is JSON encoded, and sent
back to the WebUI in response. Since the _webui_ app includes jQuery with
every view, this makes it very easy for the WebUIs of other apps to query
their running App object for state. See the _training_ app for an example.
But wait! AJAX can't cross domains, so a request to port 8001 from the WebUI
won't work! This is handled by the WebUI bundled with this app, that proxies
all requests to /ajax/(.+) to the right place, on the server side. I cannot
conceive of a situation where this would be a problem - but keep it in mind,
and don't forget to prepend "/ajax/" to your AJAX URLs."""
class Server(ThreadingMixIn, HTTPServer):
pass
class MyJsonEncoder(JSONEncoder):
def default(self, o):
# if this object has its own preference
# for JSON serialization, prioritize that
if hasattr(o, "__json__"):
return o.__json__()
elif type(o) == QuerySet:
return list(o)
# otherwise, revert to the usual behavior
return JSONEncoder.default(self, o)
class RequestHandler(BaseHTTPRequestHandler):
def __find_app(self, name):
# inspect the name of each active app,
# returning as soon as we find a match
for app in self.server.app.router.apps:
if app.slug == name:
return app
# no app by that
# name was found
return None
# handle both GET and POST with
# the same method
def do_GET(self): return self.process()
def do_POST(self): return self.process()
def process(self):
def response(code, output, json=True):
self.send_response(code)
mime_type = "application/json" if json else "text/plain"
self.send_header("content-type", mime_type)
self.end_headers()
if json:
json = App.MyJsonEncoder().encode(output)
self.wfile.write(json)
# otherwise, write the raw response.
# it doesn't make much sense to have
# error messages encoded as JSON...
else: self.wfile.write(output)
# HTTP2xx represents success
return (code>=200 and code <=299)
# should look something like:
# /alpha/bravo?charlie=delta
#
# this request will be parsed to the "bravo"
# method of the "alpha" app, with the params:
# { "charlie": ["delta"] }
#
# any other path format will return an http404
# error, for the time being. params are optional.
url = urlparse.urlparse(self.path)
path_parts = url.path.split("/")
# abort if the url didn't look right
# TODO: better error message here
if len(path_parts) != 3:
return response(404, "FAIL.")
# resolve the first part of the url into an app
# (via the router), and abort if it wasn't valid
app_name = path_parts[1]
app = self.__find_app(app_name)
if (app is None):
return response(404,
"Invalid app: %s" % app_name)
# same for the request name within the app
# (FYI, self.command returns GET, POST, etc)
meth_name = "ajax_%s_%s" % (self.command, path_parts[2])
if not hasattr(app, meth_name):
return response(404,
"Invalid method: %s" % meth_name)
# everything appears to be well, so call the
# target method, and return the response (as
# a string, for now)
try:
method = getattr(app, meth_name)
params = urlparse.urlparse(url.query)
args = [params]
# for post requests, we'll also need to parse
# the form data, and hand it to the method
if self.command == "POST":
form = {}
# parse the form data via the CGI lib. this is
# a horrible mess, but supports all kinds of
# encodings (multipart, in particular)
storage = cgi.FieldStorage(
fp = self.rfile,
headers = self.headers,
environ = {
"REQUEST_METHOD": "POST",
"CONTENT_TYPE": self.headers["content-type"] })
# convert the fieldstorage object into a dict,
# to keep it simple for the handler methods.
# TODO: maybe make this a util if it's useful
# elsewhere. it isn't, for the time being.
for key in storage.keys():
v = storage.getlist(key)
# where possible, just store the values as singular,
# to avoid CGIs usual post["id"][0] verbosity
if len(v) > 1: form[key] = v
else: form[key] = v[0]
args.append(form)
# call the method, and send back whatever data
# structure was returned, serialized with JSON
output = method(*args)
return response(200, output)
# something raised during the request, so
# return a useless http error to the requester
except Exception, err:
self.server.app.warning(traceback.format_exc())
return response(500, unicode(err), False)
# this does nothing, except prevent HTTP
# requests being echoed to the screen
def log_request(*args):
pass
def configure(self, host=None, port=None):
self.host = host
self.port = port
def start(self):
# create the webserver, through which the
# AJAX requests from the WebUI will arrive
self.server = self.Server((self.host, self.port), self.RequestHandler)
self.server.app = self
# start the server in a separate thread, and daemonize it
# to prevent it from hanging once the main thread terminates
self.thread = Thread(target=self.server.serve_forever)
self.thread.daemon = True
self.thread.start()
|
lgpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
6695,
26,
15933,
6714,
29,
20,
23014,
29,
20,
10844,
5584,
29,
20,
199,
199,
646,
660,
19331,
706,
199,
199,
646,
16004,
12,
7097,
12,
5190,
199,
504,
5796,
492,
11086,
199,
504,
17766,
3120,
492,
11086,
316,
26527,
199,
504,
3523,
14938,
492,
3523,
23518,
12,
3101,
3120,
199,
199,
504,
1639,
14,
1208,
14,
4129,
1001,
492,
4840,
6679,
199,
504,
1639,
14,
697,
14,
992,
14,
1131,
492,
18397,
421,
199,
533,
4693,
8,
1330,
1580,
706,
14,
571,
14,
2640,
304,
272,
408,
2765,
4693,
1630,
6548,
701,
6337,
14,
2779,
3495,
1454,
370,
14062,
1163,
4693,
83,
12,
701,
2126,
13070,
376,
8837,
334,
460,
4465,
9,
4340,
367,
3062,
370,
26808,
3382,
3932,
2126,
6001,
6379,
436,
820,
27703,
51,
3053,
4693,
909,
14,
267,
2126,
3979,
820,
27703,
51,
3053,
9174,
12,
642,
1145,
9174,
376,
3101,
3120,
334,
719,
1695,
4587,
465,
849,
12,
2126,
1325,
30241,
4799,
660,
19331,
706,
14,
2730,
9,
315,
282,
7239,
2462,
12,
436,
9626,
397,
367,
1263,
2126,
12467,
3101,
4145,
4877,
11589,
571,
15,
765,
4856,
5723,
4145,
12,
3180,
543,
2126,
3932,
9576,
2633,
436,
8761,
1824,
12,
787,
3032,
641,
370,
314,
4310,
1145,
14,
267,
2126,
6058,
26,
267,
2126,
1083,
221,
2851,
8295,
1145,
263,
1083,
3777,
1249,
2126,
9310,
29,
221,
24768,
8295,
24768,
263,
9310,
29,
3777,
275,
5918,
2126,
9576,
258,
1182,
4785,
7015,
15,
475,
1810,
258,
2059,
7015,
221,
25930,
63,
2970,
63,
475,
1810,
258,
469,
789,
2126,
8761,
259,
1182,
4785,
7015,
15,
758,
556,
2978,
257,
2059,
7015,
221,
25930,
63,
4030,
63,
758,
556,
2978,
221,
469,
1660,
469,
789,
2126,
8761,
259,
1182,
4785,
7015,
15,
14488,
31,
88,
29,
17,
221,
2059,
7015,
221,
25930,
63,
4030,
63,
14488,
258,
469,
298,
88,
582,
413,
1660,
1052,
267,
2126,
6184,
666,
626,
365,
2138,
701,
314,
3016,
1083,
365,
4840,
5737,
12,
436,
4847,
2126,
1771,
370,
314,
6001,
6379,
315,
1177,
14,
9336,
314,
485,
31991,
73,
63,
1145,
6952,
1335,
3227,
543,
2126,
4036,
2455,
12,
642,
7704,
652,
7437,
8837,
367,
314,
6001,
53,
1831,
402,
1163,
8686,
370,
1827,
2126,
3932,
3879,
4693,
909,
367,
1174,
14,
1666,
314,
485,
7588,
63,
1145,
367,
376,
2893,
14,
267,
2126,
11017,
3618,
1,
437,
42,
9839,
883,
1133,
8059,
14006,
12,
880,
282,
1056,
370,
1844,
1695,
4587,
687,
314,
6001,
6379,
2126,
7859,
1133,
1736,
1,
961,
365,
8860,
701,
314,
6001,
6379,
330,
725,
1146,
543,
642,
1145,
12,
626,
14942,
2126,
1006,
4145,
370,
1182,
12774,
7985,
6977,
9,
370,
314,
2451,
4192,
12,
641,
314,
1654,
5366,
14,
473,
3913,
2126,
406,
5251,
402,
282,
25781,
2382,
642,
3955,
506,
282,
5160,
446,
1325,
4215,
652,
315,
25169,
12,
2126,
436,
2793,
1133,
19459,
370,
18213,
3286,
12774,
6687,
370,
2195,
437,
42,
9839,
10867,
1041,
17635,
1021,
7146,
8,
4436,
316,
26527,
12,
3101,
3120,
304,
267,
986,
17635,
1021,
4932,
9653,
6679,
8,
23069,
304,
267,
347,
849,
8,
277,
12,
312,
304,
7846,
327,
340,
642,
909,
965,
2399,
5705,
16705,
288,
327,
367,
4840,
16953,
12,
6791,
5277,
806,
626,
288,
340,
2688,
8,
79,
12,
4396,
1001,
363,
2349,
355,
372,
312,
855,
1001,
4533,
7846,
916,
730,
8,
79,
9,
508,
18397,
26,
355,
372,
769,
8,
79,
9,
7846,
327,
4257,
12,
23347,
370,
314,
20195,
5953,
288,
372,
4840,
6679,
14,
885,
8,
277,
12,
312,
9,
25979,
1021,
4784,
2461,
8,
1563,
23518,
304,
267,
347,
636,
1623,
63,
571,
8,
277,
12,
536,
304,
7846,
327,
6485,
314,
536,
402,
1924,
4702,
1145,
12,
288,
327,
8152,
465,
18930,
465,
781,
2342,
282,
1336,
288,
367,
1145,
315,
291,
14,
1000,
14,
571,
14,
4995,
14,
5181,
26,
355,
340,
1145,
14,
5464,
508,
536,
26,
490,
372,
1145,
7846,
327,
949,
1145,
701,
626,
288,
327,
536,
1990,
1911,
288,
372,
488,
2728,
327,
2429,
3865,
9576,
436,
8761,
543,
267,
327,
314,
2011,
1083,
267,
347,
886,
63,
2970,
8,
277,
304,
221,
372,
291,
14,
1412,
342,
267,
347,
886,
63,
4030,
8,
277,
304,
372,
291,
14,
1412,
342,
2728,
347,
2112,
8,
277,
304,
288,
347,
1177,
8,
600,
12,
1072,
12,
2022,
29,
549,
304,
355,
291,
14,
2254,
63,
1310,
8,
600,
9,
355,
6660,
63,
466,
275,
298,
3578,
15,
1001,
2,
340,
2022,
587,
298,
505,
15,
6104,
2,
355,
291,
14,
2254,
63,
1291,
480,
1317,
13,
466,
401,
6660,
63,
466,
9,
355,
291,
14,
500,
63,
2139,
342,
14977,
340,
2022,
26,
490,
2022,
275,
4693,
14,
5713,
9653,
6679,
1252,
2143,
8,
1199,
9,
490,
291,
14,
18076,
14,
952,
8,
1001,
9,
14977,
327,
4257,
12,
2218,
314,
3066,
1177,
14,
355,
327,
652,
3181,
1133,
1852,
8298,
12249,
370,
1172,
355,
327,
1125,
3788,
5737,
465,
4840,
1396,
355,
587,
26,
291,
14,
18076,
14,
952,
8,
1199,
9,
14977,
327,
3101,
18,
2154,
8469,
3182,
355,
372,
334,
600,
8119,
1840,
436,
1233,
2695,
10488,
9,
7846,
327,
1077,
3648,
6020,
2839,
26,
288,
327,
257,
1182,
4468,
15,
7828,
2392,
31,
1560,
21530,
29,
3136,
288,
327,
7205,
327,
642,
1056,
911,
506,
4565,
370,
314,
298,
7828,
2392,
2,
288,
327,
1083,
402,
314,
298,
4468,
2,
1145,
12,
543,
314,
1862,
26,
288,
327,
257,
469,
298,
1560,
21530,
582,
2097,
3136,
937,
789,
288,
327,
288,
327,
1263,
1163,
931,
1475,
911,
372,
376,
1455,
5188,
288,
327,
1125,
12,
367,
314,
900,
3769,
14,
1862,
787,
2716,
14,
288,
1166,
275,
7097,
14,
10290,
8,
277,
14,
515,
9,
288,
931,
63,
4181,
275,
1166,
14,
515,
14,
1294,
19031,
7846,
327,
12004,
340,
314,
1166,
9980,
1133,
3648,
2451,
288,
327,
3254,
26,
8034,
1125,
1245,
2348,
288,
340,
822,
8,
515,
63,
4181,
9,
1137,
650,
26,
355,
372,
1177,
8,
5188,
12,
298,
8784,
2685,
7846,
327,
7512,
314,
1642,
1777,
402,
314,
1166,
1901,
376,
1145,
288,
327,
334,
12897,
314
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
6695,
26,
15933,
6714,
29,
20,
23014,
29,
20,
10844,
5584,
29,
20,
199,
199,
646,
660,
19331,
706,
199,
199,
646,
16004,
12,
7097,
12,
5190,
199,
504,
5796,
492,
11086,
199,
504,
17766,
3120,
492,
11086,
316,
26527,
199,
504,
3523,
14938,
492,
3523,
23518,
12,
3101,
3120,
199,
199,
504,
1639,
14,
1208,
14,
4129,
1001,
492,
4840,
6679,
199,
504,
1639,
14,
697,
14,
992,
14,
1131,
492,
18397,
421,
199,
533,
4693,
8,
1330,
1580,
706,
14,
571,
14,
2640,
304,
272,
408,
2765,
4693,
1630,
6548,
701,
6337,
14,
2779,
3495,
1454,
370,
14062,
1163,
4693,
83,
12,
701,
2126,
13070,
376,
8837,
334,
460,
4465,
9,
4340,
367,
3062,
370,
26808,
3382,
3932,
2126,
6001,
6379,
436,
820,
27703,
51,
3053,
4693,
909,
14,
267,
2126,
3979,
820,
27703,
51,
3053,
9174,
12,
642,
1145,
9174,
376,
3101,
3120,
334,
719,
1695,
4587,
465,
849,
12,
2126,
1325,
30241,
4799,
660,
19331,
706,
14,
2730,
9,
315,
282,
7239,
2462,
12,
436,
9626,
397,
367,
1263,
2126,
12467,
3101,
4145,
4877,
11589,
571,
15,
765,
4856,
5723,
4145,
12,
3180,
543,
2126,
3932,
9576,
2633,
436,
8761,
1824,
12,
787,
3032,
641,
370,
314,
4310,
1145,
14,
267,
2126,
6058,
26,
267,
2126,
1083,
221,
2851,
8295,
1145,
263,
1083,
3777,
1249,
2126,
9310,
29,
221,
24768,
8295,
24768,
263,
9310,
29,
3777,
275,
5918,
2126,
9576,
258,
1182,
4785,
7015,
15,
475,
1810,
258,
2059,
7015,
221,
25930,
63,
2970,
63,
475,
1810,
258,
469,
789,
2126,
8761,
259,
1182,
4785,
7015,
15,
758,
556,
2978,
257,
2059,
7015,
221,
25930,
63,
4030,
63,
758,
556,
2978,
221,
469,
1660,
469,
789,
2126,
8761,
259,
1182,
4785,
7015,
15,
14488,
31,
88,
29,
17,
221,
2059,
7015,
221,
25930,
63,
4030,
63,
14488,
258,
469,
298,
88,
582,
413,
1660,
1052,
267,
2126,
6184,
666,
626,
365,
2138,
701,
314,
3016,
1083,
365,
4840,
5737,
12,
436,
4847,
2126,
1771,
370,
314,
6001,
6379,
315,
1177,
14,
9336,
314,
485,
31991,
73,
63,
1145,
6952,
1335,
3227,
543,
2126,
4036,
2455,
12,
642,
7704,
652,
7437,
8837,
367,
314,
6001,
53,
1831,
402,
1163,
8686,
370,
1827,
2126,
3932,
3879,
4693,
909,
367,
1174,
14,
1666,
314,
485,
7588,
63,
1145,
367,
376,
2893,
14,
267,
2126,
11017,
3618,
1,
437,
42,
9839,
883,
1133,
8059,
14006,
12,
880,
282,
1056,
370,
1844,
1695,
4587,
687,
314,
6001,
6379,
2126,
7859,
1133,
1736,
1,
961,
365,
8860,
701,
314,
6001,
6379,
330,
725,
1146,
543,
642,
1145,
12,
626,
14942,
2126,
1006,
4145,
370,
1182,
12774,
7985,
6977,
9,
370,
314,
2451,
4192,
12,
641,
314,
1654,
5366,
14,
473,
3913,
2126,
406,
5251,
402,
282,
25781,
2382,
642,
3955,
506,
282,
5160,
446,
1325,
4215,
652,
315,
25169,
12,
2126,
436,
2793,
1133,
19459,
370,
18213,
3286,
12774,
6687,
370,
2195,
437,
42,
9839,
10867,
1041,
17635,
1021,
7146,
8,
4436,
316,
26527,
12,
3101,
3120,
304,
267,
986,
17635,
1021,
4932,
9653,
6679,
8,
23069,
304,
267,
347,
849,
8,
277,
12,
312,
304,
7846,
327,
340,
642,
909,
965,
2399,
5705,
16705,
288,
327,
367,
4840,
16953,
12,
6791,
5277,
806,
626,
288,
340,
2688,
8,
79,
12,
4396,
1001,
363,
2349,
355,
372,
312,
855,
1001,
4533,
7846,
916,
730,
8,
79,
9,
508,
18397,
26,
355,
372,
769,
8,
79,
9,
7846,
327,
4257,
12,
23347,
370,
314,
20195,
5953,
288,
372,
4840,
6679,
14,
885,
8,
277,
12,
312,
9,
25979,
1021,
4784,
2461,
8,
1563,
23518,
304,
267,
347,
636,
1623,
63,
571,
8,
277,
12,
536,
304,
7846,
327,
6485,
314,
536,
402,
1924,
4702,
1145,
12,
288,
327,
8152,
465,
18930,
465,
781,
2342,
282,
1336,
288,
367,
1145,
315,
291,
14,
1000,
14,
571,
14,
4995,
14,
5181,
26,
355,
340,
1145,
14,
5464,
508,
536,
26,
490,
372,
1145,
7846,
327,
949,
1145,
701,
626,
288,
327,
536,
1990,
1911,
288,
372,
488,
2728,
327,
2429,
3865,
9576,
436,
8761,
543,
267,
327,
314,
2011,
1083,
267,
347,
886,
63,
2970,
8,
277,
304,
221,
372,
291,
14,
1412,
342,
267,
347,
886,
63,
4030,
8,
277,
304,
372,
291,
14,
1412,
342,
2728,
347,
2112,
8,
277,
304,
288,
347,
1177,
8,
600,
12,
1072,
12,
2022,
29,
549,
304,
355,
291,
14,
2254,
63,
1310,
8,
600,
9,
355,
6660,
63,
466,
275,
298,
3578,
15,
1001,
2,
340,
2022,
587,
298,
505,
15,
6104,
2,
355,
291,
14,
2254,
63,
1291,
480,
1317,
13,
466,
401,
6660,
63,
466,
9,
355,
291,
14,
500,
63,
2139,
342,
14977,
340,
2022,
26,
490,
2022,
275,
4693,
14,
5713,
9653,
6679,
1252,
2143,
8,
1199,
9,
490,
291,
14,
18076,
14,
952,
8,
1001,
9,
14977,
327,
4257,
12,
2218,
314,
3066,
1177,
14,
355,
327,
652,
3181,
1133,
1852,
8298,
12249,
370,
1172,
355,
327,
1125,
3788,
5737,
465,
4840,
1396,
355,
587,
26,
291,
14,
18076,
14,
952,
8,
1199,
9,
14977,
327,
3101,
18,
2154,
8469,
3182,
355,
372,
334,
600,
8119,
1840,
436,
1233,
2695,
10488,
9,
7846,
327,
1077,
3648,
6020,
2839,
26,
288,
327,
257,
1182,
4468,
15,
7828,
2392,
31,
1560,
21530,
29,
3136,
288,
327,
7205,
327,
642,
1056,
911,
506,
4565,
370,
314,
298,
7828,
2392,
2,
288,
327,
1083,
402,
314,
298,
4468,
2,
1145,
12,
543,
314,
1862,
26,
288,
327,
257,
469,
298,
1560,
21530,
582,
2097,
3136,
937,
789,
288,
327,
288,
327,
1263,
1163,
931,
1475,
911,
372,
376,
1455,
5188,
288,
327,
1125,
12,
367,
314,
900,
3769,
14,
1862,
787,
2716,
14,
288,
1166,
275,
7097,
14,
10290,
8,
277,
14,
515,
9,
288,
931,
63,
4181,
275,
1166,
14,
515,
14,
1294,
19031,
7846,
327,
12004,
340,
314,
1166,
9980,
1133,
3648,
2451,
288,
327,
3254,
26,
8034,
1125,
1245,
2348,
288,
340,
822,
8,
515,
63,
4181,
9,
1137,
650,
26,
355,
372,
1177,
8,
5188,
12,
298,
8784,
2685,
7846,
327,
7512,
314,
1642,
1777,
402,
314,
1166,
1901,
376,
1145,
288,
327,
334,
12897,
314,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
clebergnu/avocado-vt
|
virttest/installer.py
|
7
|
6686
|
"""
Installer classes are responsible for building and installing virtualization
specific software components. This is the main entry point for tests that
wish to install virtualization software components.
The most common use case is to simply call make_installer() inside your tests.
"""
from avocado.core import exceptions
from . import base_installer
from . import qemu_installer
from . import libvirt_installer
__all__ = ['InstallerRegistry', 'INSTALLER_REGISTRY', 'make_installer',
'run_installers']
class InstallerRegistry(dict):
"""
Holds information on known installer classes
This class is used to create a single instance, named INSTALLER_REGISTRY,
that will hold all information on known installer types.
For registering a new installer class, use the register() method. If the
virt type is not set explicitly, it will be set to 'base'. Example:
>>> INSTALLER_REGISTRY.register('yum', base_installer.YumInstaller)
If you want to register a virt specific installer class, set the virt
(third) param:
>>> INSTALLER_REGISTRY.register('yum', qemu_installer.YumInstaller, 'qemu')
For getting a installer class, use the get_installer() method. This method
has a fallback option 'get_default_virt' that will return a generic virt
installer if set to true.
"""
DEFAULT_VIRT_NAME = 'base'
def __init__(self, **kwargs):
dict.__init__(self, **kwargs)
self[self.DEFAULT_VIRT_NAME] = {}
def register(self, mode, klass, virt=None):
"""
Register a class as responsible for installing virt software components
If virt is not set, it will assume a default of 'base'.
"""
if virt is None:
virt = self.DEFAULT_VIRT_NAME
elif virt not in self:
self[virt] = {}
self[virt][mode] = klass
def get_installer(self, mode, virt=None, get_default_virt=False):
"""
Gets a installer class that should be able to install the virt software
Always try to use classes that are specific to the virtualization
technology that is being tested. If you have confidence that the
installation is rather trivial and does not require custom steps, you
may be able to get away with a base class (by setting get_default_virt
to True).
"""
if virt is None:
virt = self.DEFAULT_VIRT_NAME
if virt not in self:
# return a base installer so the test could and give it a try?
if get_default_virt:
return self[self.DEFAULT_VIRT_NAME].get(mode)
else:
return self[virt].get(mode)
def get_modes(self, virt=None):
"""
Returns a list of all registered installer modes
"""
if virt is None:
virt = self.DEFAULT_VIRT_NAME
if virt not in self:
return []
return list(self[virt].keys())
#
# InstallerRegistry unique instance
#
INSTALLER_REGISTRY = InstallerRegistry()
#
# Register base installers
#
INSTALLER_REGISTRY.register('yum',
base_installer.YumInstaller)
INSTALLER_REGISTRY.register('koji',
base_installer.KojiInstaller)
INSTALLER_REGISTRY.register('git_repo',
base_installer.GitRepoInstaller)
INSTALLER_REGISTRY.register('local_src',
base_installer.LocalSourceDirInstaller)
INSTALLER_REGISTRY.register('local_tar',
base_installer.LocalSourceTarInstaller)
INSTALLER_REGISTRY.register('remote_tar',
base_installer.RemoteSourceTarInstaller)
#
# Register KVM specific installers
#
INSTALLER_REGISTRY.register('yum',
base_installer.YumInstaller,
'qemu')
INSTALLER_REGISTRY.register('koji',
base_installer.KojiInstaller,
'qemu')
INSTALLER_REGISTRY.register('git_repo',
qemu_installer.GitRepoInstaller,
'qemu')
INSTALLER_REGISTRY.register('local_src',
qemu_installer.LocalSourceDirInstaller,
'qemu')
INSTALLER_REGISTRY.register('local_tar',
qemu_installer.LocalSourceTarInstaller,
'qemu')
INSTALLER_REGISTRY.register('remote_tar',
qemu_installer.RemoteSourceTarInstaller,
'qemu')
INSTALLER_REGISTRY.register('git_repo',
libvirt_installer.GitRepoInstaller,
'libvirt')
def installer_name_split(fullname, virt=None):
"""
Split a full installer name into mode and short name
Examples:
git_repo_foo -> (git_repo, foo)
local_src_foo -> (local_src, foo)
"""
for mode in INSTALLER_REGISTRY.get_modes(virt):
if fullname.startswith('%s_' % mode):
_, _name = fullname.split(mode)
name = _name[1:]
return (mode, name)
return (None, None)
def make_installer(fullname, params, test=None):
"""
Installer factory: returns a new installer for the chosen mode and vm type
This is the main entry point for acquiring an installer. Tests, such as
the build test, should use this function.
Param priority evaluation order is 'install_mode', then 'mode'. For virt
type, 'vm_type' is consulted.
:param fullname: the full name of instance, eg: git_repo_foo
:param params: dictionary with parameters generated from cartersian config
:param test: the test instance
"""
virt = params.get("vm_type", None)
mode, name = installer_name_split(fullname, virt)
if mode is None or name is None:
error_msg = ('Invalid installer mode or name for "%s". Probably an '
'installer has not been registered' % fullname)
if virt is not None:
error_msg += ' specifically for virt type "%s"' % virt
raise exceptions.TestError(error_msg)
klass = INSTALLER_REGISTRY.get_installer(mode, virt)
if klass is None:
raise exceptions.TestError(
'Installer mode %s is not registered' % mode)
else:
return klass(mode, name, test, params)
def run_installers(params, test=None):
"""
Runs the installation routines for all installers, one at a time
This is usually the main entry point for tests
"""
for name in params.get("installers", "").split():
installer = make_installer(name, params, test)
installer.install()
|
gpl-2.0
|
[
624,
199,
27598,
3992,
787,
17845,
367,
10015,
436,
22200,
5791,
2072,
199,
6100,
2032,
7323,
14,
961,
365,
314,
2446,
2397,
2376,
367,
2295,
626,
199,
87,
2453,
370,
3907,
5791,
2072,
2032,
7323,
14,
199,
199,
1918,
4750,
2863,
675,
1930,
365,
370,
9329,
1240,
1852,
63,
17047,
342,
6272,
2195,
2295,
14,
199,
624,
199,
199,
504,
2289,
679,
5129,
14,
1018,
492,
4967,
199,
199,
504,
1275,
492,
1300,
63,
17047,
199,
504,
1275,
492,
1894,
14756,
63,
17047,
199,
504,
1275,
492,
13108,
63,
17047,
199,
199,
363,
452,
363,
275,
788,
27598,
10899,
297,
283,
16811,
540,
63,
25304,
57,
297,
283,
1875,
63,
17047,
297,
1779,
283,
1065,
63,
17047,
83,
418,
421,
199,
533,
14089,
9230,
10899,
8,
807,
304,
339,
408,
272,
869,
8250,
2556,
641,
6040,
18535,
3992,
339,
961,
1021,
365,
1202,
370,
1218,
282,
2849,
1256,
12,
4310,
20514,
1761,
540,
63,
25304,
57,
12,
272,
626,
911,
10266,
1006,
2556,
641,
6040,
18535,
2943,
14,
339,
2104,
2274,
316,
282,
892,
18535,
1021,
12,
675,
314,
2274,
342,
1083,
14,
982,
314,
272,
12043,
730,
365,
440,
663,
7662,
12,
652,
911,
506,
663,
370,
283,
1095,
1370,
5679,
26,
339,
1306,
20514,
1761,
540,
63,
25304,
57,
14,
2683,
360,
22108,
297,
1300,
63,
17047,
14,
57,
453,
27598,
9,
339,
982,
1265,
2934,
370,
2274,
282,
12043,
2488,
18535,
1021,
12,
663,
314,
12043,
272,
334,
11470,
9,
1215,
26,
339,
1306,
20514,
1761,
540,
63,
25304,
57,
14,
2683,
360,
22108,
297,
1894,
14756,
63,
17047,
14,
57,
453,
27598,
12,
283,
19839,
358,
339,
2104,
10232,
282,
18535,
1021,
12,
675,
314,
664,
63,
17047,
342,
1083,
14,
961,
1083,
272,
965,
282,
9567,
945,
283,
362,
63,
885,
63,
4549,
7,
626,
911,
372,
282,
7809,
12043,
272,
18535,
340,
663,
370,
2549,
14,
272,
408,
339,
6186,
63,
18228,
63,
2339,
275,
283,
1095,
7,
339,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
1211,
855,
826,
721,
277,
12,
1011,
958,
9,
267,
291,
59,
277,
14,
3472,
63,
18228,
63,
2339,
61,
275,
1052,
339,
347,
2274,
8,
277,
12,
818,
12,
8531,
12,
12043,
29,
403,
304,
267,
408,
267,
11828,
282,
1021,
465,
17845,
367,
22200,
12043,
2032,
7323,
398,
982,
12043,
365,
440,
663,
12,
652,
911,
5534,
282,
849,
402,
283,
1095,
1370,
267,
408,
267,
340,
12043,
365,
488,
26,
288,
12043,
275,
291,
14,
3472,
63,
18228,
63,
2339,
267,
916,
12043,
440,
315,
291,
26,
288,
291,
59,
4549,
61,
275,
1052,
398,
291,
59,
4549,
1527,
632,
61,
275,
8531,
339,
347,
664,
63,
17047,
8,
277,
12,
818,
12,
12043,
29,
403,
12,
664,
63,
885,
63,
4549,
29,
797,
304,
267,
408,
267,
14509,
282,
18535,
1021,
626,
1077,
506,
7688,
370,
3907,
314,
12043,
2032,
398,
16763,
862,
370,
675,
3992,
626,
787,
2488,
370,
314,
5791,
2072,
267,
1565,
24731,
626,
365,
3769,
12470,
14,
982,
1265,
1172,
15197,
626,
314,
267,
12096,
365,
7830,
28586,
436,
1630,
440,
4409,
3537,
7124,
12,
1265,
267,
1443,
506,
7688,
370,
664,
13437,
543,
282,
1300,
1021,
334,
991,
4260,
664,
63,
885,
63,
4549,
267,
370,
715,
680,
267,
408,
267,
340,
12043,
365,
488,
26,
288,
12043,
275,
291,
14,
3472,
63,
18228,
63,
2339,
267,
340,
12043,
440,
315,
291,
26,
288,
327,
372,
282,
1300,
18535,
880,
314,
511,
4293,
436,
8120,
652,
282,
862,
31,
288,
340,
664,
63,
885,
63,
4549,
26,
355,
372,
291,
59,
277,
14,
3472,
63,
18228,
63,
2339,
1055,
362,
8,
632,
9,
267,
587,
26,
288,
372,
291,
59,
4549,
1055,
362,
8,
632,
9,
339,
347,
664,
63,
10433,
8,
277,
12,
12043,
29,
403,
304,
267,
408,
267,
1803,
282,
769,
402,
1006,
7264,
18535,
12404,
267,
408,
267,
340,
12043,
365,
488,
26,
288,
12043,
275,
291,
14,
3472,
63,
18228,
63,
2339,
398,
340,
12043,
440,
315,
291,
26,
288,
372,
942,
398,
372,
769,
8,
277,
59,
4549,
1055,
1612,
1012,
421,
199,
3,
199,
3,
14089,
9230,
10899,
3747,
1256,
199,
3,
199,
16811,
540,
63,
25304,
57,
275,
14089,
9230,
10899,
342,
421,
199,
3,
199,
3,
11828,
1300,
18535,
83,
199,
3,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
22108,
297,
1169,
1300,
63,
17047,
14,
57,
453,
27598,
9,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
7697,
8047,
297,
1169,
1300,
63,
17047,
14,
31305,
8047,
27598,
9,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
3187,
63,
3417,
297,
1169,
1300,
63,
17047,
14,
14686,
11334,
27598,
9,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
1832,
63,
2164,
297,
1169,
1300,
63,
17047,
14,
5339,
2980,
3567,
27598,
9,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
1832,
63,
5369,
297,
1169,
1300,
63,
17047,
14,
5339,
2980,
24818,
27598,
9,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
3846,
63,
5369,
297,
1169,
1300,
63,
17047,
14,
6713,
2980,
24818,
27598,
9,
199,
199,
3,
199,
3,
11828,
1804,
6849,
2488,
18535,
83,
199,
3,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
22108,
297,
1169,
1300,
63,
17047,
14,
57,
453,
27598,
12,
1169,
283,
19839,
358,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
7697,
8047,
297,
1169,
1300,
63,
17047,
14,
31305,
8047,
27598,
12,
1169,
283,
19839,
358,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
3187,
63,
3417,
297,
1169,
1894,
14756,
63,
17047,
14,
14686,
11334,
27598,
12,
1169,
283,
19839,
358,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
1832,
63,
2164,
297,
1169,
1894,
14756,
63,
17047,
14,
5339,
2980,
3567,
27598,
12,
1169,
283,
19839,
358,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
1832,
63,
5369,
297,
1169,
1894,
14756,
63,
17047,
14,
5339,
2980,
24818,
27598,
12,
1169,
283,
19839,
358,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
3846,
63,
5369,
297,
1169,
1894,
14756,
63,
17047,
14,
6713,
2980,
24818,
27598,
12,
1169,
283,
19839,
358,
199,
199,
16811,
540
] |
[
199,
27598,
3992,
787,
17845,
367,
10015,
436,
22200,
5791,
2072,
199,
6100,
2032,
7323,
14,
961,
365,
314,
2446,
2397,
2376,
367,
2295,
626,
199,
87,
2453,
370,
3907,
5791,
2072,
2032,
7323,
14,
199,
199,
1918,
4750,
2863,
675,
1930,
365,
370,
9329,
1240,
1852,
63,
17047,
342,
6272,
2195,
2295,
14,
199,
624,
199,
199,
504,
2289,
679,
5129,
14,
1018,
492,
4967,
199,
199,
504,
1275,
492,
1300,
63,
17047,
199,
504,
1275,
492,
1894,
14756,
63,
17047,
199,
504,
1275,
492,
13108,
63,
17047,
199,
199,
363,
452,
363,
275,
788,
27598,
10899,
297,
283,
16811,
540,
63,
25304,
57,
297,
283,
1875,
63,
17047,
297,
1779,
283,
1065,
63,
17047,
83,
418,
421,
199,
533,
14089,
9230,
10899,
8,
807,
304,
339,
408,
272,
869,
8250,
2556,
641,
6040,
18535,
3992,
339,
961,
1021,
365,
1202,
370,
1218,
282,
2849,
1256,
12,
4310,
20514,
1761,
540,
63,
25304,
57,
12,
272,
626,
911,
10266,
1006,
2556,
641,
6040,
18535,
2943,
14,
339,
2104,
2274,
316,
282,
892,
18535,
1021,
12,
675,
314,
2274,
342,
1083,
14,
982,
314,
272,
12043,
730,
365,
440,
663,
7662,
12,
652,
911,
506,
663,
370,
283,
1095,
1370,
5679,
26,
339,
1306,
20514,
1761,
540,
63,
25304,
57,
14,
2683,
360,
22108,
297,
1300,
63,
17047,
14,
57,
453,
27598,
9,
339,
982,
1265,
2934,
370,
2274,
282,
12043,
2488,
18535,
1021,
12,
663,
314,
12043,
272,
334,
11470,
9,
1215,
26,
339,
1306,
20514,
1761,
540,
63,
25304,
57,
14,
2683,
360,
22108,
297,
1894,
14756,
63,
17047,
14,
57,
453,
27598,
12,
283,
19839,
358,
339,
2104,
10232,
282,
18535,
1021,
12,
675,
314,
664,
63,
17047,
342,
1083,
14,
961,
1083,
272,
965,
282,
9567,
945,
283,
362,
63,
885,
63,
4549,
7,
626,
911,
372,
282,
7809,
12043,
272,
18535,
340,
663,
370,
2549,
14,
272,
408,
339,
6186,
63,
18228,
63,
2339,
275,
283,
1095,
7,
339,
347,
636,
826,
721,
277,
12,
1011,
958,
304,
267,
1211,
855,
826,
721,
277,
12,
1011,
958,
9,
267,
291,
59,
277,
14,
3472,
63,
18228,
63,
2339,
61,
275,
1052,
339,
347,
2274,
8,
277,
12,
818,
12,
8531,
12,
12043,
29,
403,
304,
267,
408,
267,
11828,
282,
1021,
465,
17845,
367,
22200,
12043,
2032,
7323,
398,
982,
12043,
365,
440,
663,
12,
652,
911,
5534,
282,
849,
402,
283,
1095,
1370,
267,
408,
267,
340,
12043,
365,
488,
26,
288,
12043,
275,
291,
14,
3472,
63,
18228,
63,
2339,
267,
916,
12043,
440,
315,
291,
26,
288,
291,
59,
4549,
61,
275,
1052,
398,
291,
59,
4549,
1527,
632,
61,
275,
8531,
339,
347,
664,
63,
17047,
8,
277,
12,
818,
12,
12043,
29,
403,
12,
664,
63,
885,
63,
4549,
29,
797,
304,
267,
408,
267,
14509,
282,
18535,
1021,
626,
1077,
506,
7688,
370,
3907,
314,
12043,
2032,
398,
16763,
862,
370,
675,
3992,
626,
787,
2488,
370,
314,
5791,
2072,
267,
1565,
24731,
626,
365,
3769,
12470,
14,
982,
1265,
1172,
15197,
626,
314,
267,
12096,
365,
7830,
28586,
436,
1630,
440,
4409,
3537,
7124,
12,
1265,
267,
1443,
506,
7688,
370,
664,
13437,
543,
282,
1300,
1021,
334,
991,
4260,
664,
63,
885,
63,
4549,
267,
370,
715,
680,
267,
408,
267,
340,
12043,
365,
488,
26,
288,
12043,
275,
291,
14,
3472,
63,
18228,
63,
2339,
267,
340,
12043,
440,
315,
291,
26,
288,
327,
372,
282,
1300,
18535,
880,
314,
511,
4293,
436,
8120,
652,
282,
862,
31,
288,
340,
664,
63,
885,
63,
4549,
26,
355,
372,
291,
59,
277,
14,
3472,
63,
18228,
63,
2339,
1055,
362,
8,
632,
9,
267,
587,
26,
288,
372,
291,
59,
4549,
1055,
362,
8,
632,
9,
339,
347,
664,
63,
10433,
8,
277,
12,
12043,
29,
403,
304,
267,
408,
267,
1803,
282,
769,
402,
1006,
7264,
18535,
12404,
267,
408,
267,
340,
12043,
365,
488,
26,
288,
12043,
275,
291,
14,
3472,
63,
18228,
63,
2339,
398,
340,
12043,
440,
315,
291,
26,
288,
372,
942,
398,
372,
769,
8,
277,
59,
4549,
1055,
1612,
1012,
421,
199,
3,
199,
3,
14089,
9230,
10899,
3747,
1256,
199,
3,
199,
16811,
540,
63,
25304,
57,
275,
14089,
9230,
10899,
342,
421,
199,
3,
199,
3,
11828,
1300,
18535,
83,
199,
3,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
22108,
297,
1169,
1300,
63,
17047,
14,
57,
453,
27598,
9,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
7697,
8047,
297,
1169,
1300,
63,
17047,
14,
31305,
8047,
27598,
9,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
3187,
63,
3417,
297,
1169,
1300,
63,
17047,
14,
14686,
11334,
27598,
9,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
1832,
63,
2164,
297,
1169,
1300,
63,
17047,
14,
5339,
2980,
3567,
27598,
9,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
1832,
63,
5369,
297,
1169,
1300,
63,
17047,
14,
5339,
2980,
24818,
27598,
9,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
3846,
63,
5369,
297,
1169,
1300,
63,
17047,
14,
6713,
2980,
24818,
27598,
9,
199,
199,
3,
199,
3,
11828,
1804,
6849,
2488,
18535,
83,
199,
3,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
22108,
297,
1169,
1300,
63,
17047,
14,
57,
453,
27598,
12,
1169,
283,
19839,
358,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
7697,
8047,
297,
1169,
1300,
63,
17047,
14,
31305,
8047,
27598,
12,
1169,
283,
19839,
358,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
3187,
63,
3417,
297,
1169,
1894,
14756,
63,
17047,
14,
14686,
11334,
27598,
12,
1169,
283,
19839,
358,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
1832,
63,
2164,
297,
1169,
1894,
14756,
63,
17047,
14,
5339,
2980,
3567,
27598,
12,
1169,
283,
19839,
358,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
1832,
63,
5369,
297,
1169,
1894,
14756,
63,
17047,
14,
5339,
2980,
24818,
27598,
12,
1169,
283,
19839,
358,
199,
16811,
540,
63,
25304,
57,
14,
2683,
360,
3846,
63,
5369,
297,
1169,
1894,
14756,
63,
17047,
14,
6713,
2980,
24818,
27598,
12,
1169,
283,
19839,
358,
199,
199,
16811,
540,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sharmaeklavya2/zulip
|
zerver/migrations/0001_initial.py
|
13
|
23623
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
import bitfield.models
import django.db.models.deletion
import django.utils.timezone
from django.conf import settings
import zerver.models
class Migration(migrations.Migration):
dependencies = [
('auth', '0001_initial'),
]
if "postgres" not in settings.DATABASES["default"]["ENGINE"]:
zulip_postgres_migrations = [] # type: ignore # https://github.com/JukkaL/mypy/issues/1164
else:
zulip_postgres_migrations = [
# Full-text search
migrations.RunSQL("""
CREATE TEXT SEARCH DICTIONARY english_us_hunspell
(template = ispell, DictFile = en_us, AffFile = en_us, StopWords = zulip_english);
CREATE TEXT SEARCH CONFIGURATION zulip.english_us_search (COPY=pg_catalog.english);
ALTER TEXT SEARCH CONFIGURATION zulip.english_us_search
ALTER MAPPING FOR asciiword, asciihword, hword_asciipart, word, hword, hword_part
WITH english_us_hunspell, english_stem;
CREATE FUNCTION escape_html(text) RETURNS text IMMUTABLE LANGUAGE 'sql' AS $$
SELECT replace(replace(replace(replace(replace($1, '&', '&'), '<', '<'),
'>', '>'), '"', '"'), '''', ''');
$$ ;
ALTER TABLE zerver_message ADD COLUMN search_tsvector tsvector;
CREATE INDEX zerver_message_search_tsvector ON zerver_message USING gin(search_tsvector);
ALTER INDEX zerver_message_search_tsvector SET (fastupdate = OFF);
CREATE TABLE fts_update_log (id SERIAL PRIMARY KEY, message_id INTEGER NOT NULL);
CREATE FUNCTION do_notify_fts_update_log() RETURNS trigger LANGUAGE plpgsql AS
$$ BEGIN NOTIFY fts_update_log; RETURN NEW; END $$;
CREATE TRIGGER fts_update_log_notify AFTER INSERT ON fts_update_log
FOR EACH STATEMENT EXECUTE PROCEDURE do_notify_fts_update_log();
CREATE FUNCTION append_to_fts_update_log() RETURNS trigger LANGUAGE plpgsql AS
$$ BEGIN INSERT INTO fts_update_log (message_id) VALUES (NEW.id); RETURN NEW; END $$;
CREATE TRIGGER zerver_message_update_search_tsvector_async
BEFORE INSERT OR UPDATE OF subject, rendered_content ON zerver_message
FOR EACH ROW EXECUTE PROCEDURE append_to_fts_update_log();
"""),
]
operations = [
migrations.CreateModel(
name='UserProfile',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('password', models.CharField(max_length=128, verbose_name='password')),
('last_login', models.DateTimeField(default=django.utils.timezone.now, verbose_name='last login')),
('is_superuser', models.BooleanField(default=False, help_text='Designates that this user has all permissions without explicitly assigning them.', verbose_name='superuser status')),
('email', models.EmailField(unique=True, max_length=75, db_index=True)),
('is_staff', models.BooleanField(default=False)),
('is_active', models.BooleanField(default=True)),
('is_bot', models.BooleanField(default=False)),
('date_joined', models.DateTimeField(default=django.utils.timezone.now)),
('is_mirror_dummy', models.BooleanField(default=False)),
('full_name', models.CharField(max_length=100)),
('short_name', models.CharField(max_length=100)),
('pointer', models.IntegerField()),
('last_pointer_updater', models.CharField(max_length=64)),
('api_key', models.CharField(max_length=32)),
('enable_stream_desktop_notifications', models.BooleanField(default=True)),
('enable_stream_sounds', models.BooleanField(default=True)),
('enable_desktop_notifications', models.BooleanField(default=True)),
('enable_sounds', models.BooleanField(default=True)),
('enable_offline_email_notifications', models.BooleanField(default=True)),
('enable_offline_push_notifications', models.BooleanField(default=True)),
('enable_digest_emails', models.BooleanField(default=True)),
('default_desktop_notifications', models.BooleanField(default=True)),
('last_reminder', models.DateTimeField(default=django.utils.timezone.now, null=True)),
('rate_limits', models.CharField(default='', max_length=100)),
('default_all_public_streams', models.BooleanField(default=False)),
('enter_sends', models.NullBooleanField(default=True)),
('autoscroll_forever', models.BooleanField(default=False)),
('twenty_four_hour_time', models.BooleanField(default=False)),
('avatar_source', models.CharField(default='G', max_length=1, choices=[('G', 'Hosted by Gravatar'), ('U', 'Uploaded by user'), ('S', 'System generated')])),
('tutorial_status', models.CharField(default='W', max_length=1, choices=[('W', 'Waiting'), ('S', 'Started'), ('F', 'Finished')])),
('onboarding_steps', models.TextField(default='[]')),
('invites_granted', models.IntegerField(default=0)),
('invites_used', models.IntegerField(default=0)),
('alert_words', models.TextField(default='[]')),
('muted_topics', models.TextField(default='[]')),
('bot_owner', models.ForeignKey(on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL, null=True)),
],
options={
'abstract': False,
},
bases=(models.Model,),
),
migrations.CreateModel(
name='AppleDeviceToken',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('token', models.CharField(unique=True, max_length=255)),
('last_updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Client',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(unique=True, max_length=30, db_index=True)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='DefaultStream',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Huddle',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('huddle_hash', models.CharField(unique=True, max_length=40, db_index=True)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Message',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('subject', models.CharField(max_length=60, db_index=True)),
('content', models.TextField()),
('rendered_content', models.TextField(null=True)),
('rendered_content_version', models.IntegerField(null=True)),
('pub_date', models.DateTimeField(verbose_name='date published', db_index=True)),
('last_edit_time', models.DateTimeField(null=True)),
('edit_history', models.TextField(null=True)),
('has_attachment', models.BooleanField(default=False, db_index=True)),
('has_image', models.BooleanField(default=False, db_index=True)),
('has_link', models.BooleanField(default=False, db_index=True)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='MitUser',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('email', models.EmailField(unique=True, max_length=75)),
('status', models.IntegerField(default=0)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='PreregistrationUser',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('email', models.EmailField(max_length=75)),
('invited_at', models.DateTimeField(auto_now=True)),
('status', models.IntegerField(default=0)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='PushDeviceToken',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('kind', models.PositiveSmallIntegerField(choices=[(1, 'apns'), (2, 'gcm')])),
('token', models.CharField(unique=True, max_length=4096)),
('last_updated', models.DateTimeField(default=django.utils.timezone.now, auto_now=True)),
('ios_app_id', models.TextField(null=True)),
('user', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Realm',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('domain', models.CharField(unique=True, max_length=40, db_index=True)),
('name', models.CharField(max_length=40, null=True)),
('restricted_to_domain', models.BooleanField(default=True)),
('invite_required', models.BooleanField(default=False)),
('invite_by_admins_only', models.BooleanField(default=False)),
('mandatory_topics', models.BooleanField(default=False)),
('show_digest_email', models.BooleanField(default=True)),
('name_changes_disabled', models.BooleanField(default=False)),
('date_created', models.DateTimeField(default=django.utils.timezone.now)),
('deactivated', models.BooleanField(default=False)),
],
options={
'permissions': (('administer', 'Administer a realm'),),
},
bases=(models.Model,),
),
migrations.CreateModel(
name='RealmAlias',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('domain', models.CharField(unique=True, max_length=80, db_index=True)),
('realm', models.ForeignKey(to='zerver.Realm', null=True)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='RealmEmoji',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.TextField()),
('img_url', models.TextField()),
('realm', models.ForeignKey(to='zerver.Realm')),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='RealmFilter',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('pattern', models.TextField()),
('url_format_string', models.TextField()),
('realm', models.ForeignKey(to='zerver.Realm')),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Recipient',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('type_id', models.IntegerField(db_index=True)),
('type', models.PositiveSmallIntegerField(db_index=True)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Referral',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('email', models.EmailField(max_length=75)),
('timestamp', models.DateTimeField(auto_now_add=True)),
('user_profile', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='ScheduledJob',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('scheduled_timestamp', models.DateTimeField()),
('type', models.PositiveSmallIntegerField()),
('data', models.TextField()),
('filter_id', models.IntegerField(null=True)),
('filter_string', models.CharField(max_length=100)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Stream',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=60, db_index=True)),
('invite_only', models.NullBooleanField(default=False)),
('email_token', models.CharField(default=zerver.models.generate_email_token_for_stream, max_length=32)),
('description', models.CharField(default='', max_length=1024)),
('date_created', models.DateTimeField(default=django.utils.timezone.now)),
('deactivated', models.BooleanField(default=False)),
('realm', models.ForeignKey(to='zerver.Realm')),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='StreamColor',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('color', models.CharField(max_length=10)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='Subscription',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('active', models.BooleanField(default=True)),
('in_home_view', models.NullBooleanField(default=True)),
('color', models.CharField(default='#c2c2c2', max_length=10)),
('desktop_notifications', models.BooleanField(default=True)),
('audible_notifications', models.BooleanField(default=True)),
('notifications', models.BooleanField(default=False)),
('recipient', models.ForeignKey(to='zerver.Recipient')),
('user_profile', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='UserActivity',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('query', models.CharField(max_length=50, db_index=True)),
('count', models.IntegerField()),
('last_visit', models.DateTimeField(verbose_name='last visit')),
('client', models.ForeignKey(to='zerver.Client')),
('user_profile', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='UserActivityInterval',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('start', models.DateTimeField(verbose_name='start time', db_index=True)),
('end', models.DateTimeField(verbose_name='end time', db_index=True)),
('user_profile', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='UserMessage',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('flags', bitfield.models.BitField(['read', 'starred', 'collapsed', 'mentioned', 'wildcard_mentioned', 'summarize_in_home', 'summarize_in_stream', 'force_expand', 'force_collapse', 'has_alert_word', 'historical', 'is_me_message'], default=0)),
('message', models.ForeignKey(to='zerver.Message')),
('user_profile', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
options={
},
bases=(models.Model,),
),
migrations.CreateModel(
name='UserPresence',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('timestamp', models.DateTimeField(verbose_name='presence changed')),
('status', models.PositiveSmallIntegerField(default=1)),
('client', models.ForeignKey(to='zerver.Client')),
('user_profile', models.ForeignKey(to=settings.AUTH_USER_MODEL)),
],
options={
},
bases=(models.Model,),
),
migrations.AlterUniqueTogether(
name='userpresence',
unique_together=set([('user_profile', 'client')]),
),
migrations.AlterUniqueTogether(
name='usermessage',
unique_together=set([('user_profile', 'message')]),
),
migrations.AlterUniqueTogether(
name='useractivity',
unique_together=set([('user_profile', 'client', 'query')]),
),
migrations.AlterUniqueTogether(
name='subscription',
unique_together=set([('user_profile', 'recipient')]),
),
migrations.AddField(
model_name='streamcolor',
name='subscription',
field=models.ForeignKey(to='zerver.Subscription'),
preserve_default=True,
),
migrations.AlterUniqueTogether(
name='stream',
unique_together=set([('name', 'realm')]),
),
migrations.AlterUniqueTogether(
name='recipient',
unique_together=set([('type', 'type_id')]),
),
migrations.AlterUniqueTogether(
name='realmfilter',
unique_together=set([('realm', 'pattern')]),
),
migrations.AlterUniqueTogether(
name='realmemoji',
unique_together=set([('realm', 'name')]),
),
migrations.AddField(
model_name='realm',
name='notifications_stream',
field=models.ForeignKey(related_name='+', blank=True, to='zerver.Stream', null=True),
preserve_default=True,
),
migrations.AddField(
model_name='preregistrationuser',
name='realm',
field=models.ForeignKey(to='zerver.Realm', null=True),
preserve_default=True,
),
migrations.AddField(
model_name='preregistrationuser',
name='referred_by',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL, null=True),
preserve_default=True,
),
migrations.AddField(
model_name='preregistrationuser',
name='streams',
field=models.ManyToManyField(to='zerver.Stream', null=True),
preserve_default=True,
),
migrations.AddField(
model_name='message',
name='recipient',
field=models.ForeignKey(to='zerver.Recipient'),
preserve_default=True,
),
migrations.AddField(
model_name='message',
name='sender',
field=models.ForeignKey(to=settings.AUTH_USER_MODEL),
preserve_default=True,
),
migrations.AddField(
model_name='message',
name='sending_client',
field=models.ForeignKey(to='zerver.Client'),
preserve_default=True,
),
migrations.AddField(
model_name='defaultstream',
name='realm',
field=models.ForeignKey(to='zerver.Realm'),
preserve_default=True,
),
migrations.AddField(
model_name='defaultstream',
name='stream',
field=models.ForeignKey(to='zerver.Stream'),
preserve_default=True,
),
migrations.AlterUniqueTogether(
name='defaultstream',
unique_together=set([('realm', 'stream')]),
),
migrations.AddField(
model_name='userprofile',
name='default_events_register_stream',
field=models.ForeignKey(related_name='+', to='zerver.Stream', null=True),
preserve_default=True,
),
migrations.AddField(
model_name='userprofile',
name='default_sending_stream',
field=models.ForeignKey(related_name='+', to='zerver.Stream', null=True),
preserve_default=True,
),
migrations.AddField(
model_name='userprofile',
name='groups',
field=models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Group', blank=True, help_text='The groups this user belongs to. A user will get all permissions granted to each of their groups.', verbose_name='groups'),
preserve_default=True,
),
migrations.AddField(
model_name='userprofile',
name='realm',
field=models.ForeignKey(to='zerver.Realm'),
preserve_default=True,
),
migrations.AddField(
model_name='userprofile',
name='user_permissions',
field=models.ManyToManyField(related_query_name='user', related_name='user_set', to='auth.Permission', blank=True, help_text='Specific permissions for this user.', verbose_name='user permissions'),
preserve_default=True,
),
] + zulip_postgres_migrations
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
199,
646,
4546,
698,
14,
992,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
199,
646,
1639,
14,
1208,
14,
7145,
199,
504,
1639,
14,
2190,
492,
2202,
199,
646,
19959,
14,
992,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
1178,
297,
283,
4183,
63,
2747,
659,
272,
1622,
339,
340,
298,
10675,
2,
440,
315,
2202,
14,
27260,
905,
885,
6611,
15956,
6229,
267,
1315,
11294,
63,
10675,
63,
7685,
275,
942,
327,
730,
26,
3686,
327,
4178,
921,
5031,
14,
957,
15,
42,
3210,
7351,
44,
15,
1662,
647,
15,
10115,
15,
845,
772,
272,
587,
26,
267,
1315,
11294,
63,
10675,
63,
7685,
275,
359,
288,
327,
16579,
13,
505,
2754,
288,
6180,
14,
2540,
4657,
4852,
199,
8366,
11951,
5795,
7762,
577,
6196,
1075,
4392,
20171,
1891,
63,
527,
63,
72,
324,
32252,
523,
334,
1160,
275,
365,
321,
914,
12,
7448,
1173,
275,
655,
63,
527,
12,
31030,
1173,
275,
655,
63,
527,
12,
8015,
23759,
275,
1315,
11294,
63,
17872,
2736,
199,
8366,
11951,
5795,
7762,
15869,
15301,
1315,
11294,
14,
17872,
63,
527,
63,
1733,
334,
16188,
29,
4198,
63,
7959,
14,
17872,
2736,
199,
19350,
11951,
5795,
7762,
15869,
15301,
1315,
11294,
14,
17872,
63,
527,
63,
1733,
523,
12112,
1157,
603,
7121,
1206,
2381,
13294,
1027,
12,
13294,
72,
1027,
12,
394,
1027,
63,
4371,
2064,
12,
4349,
12,
394,
1027,
12,
394,
1027,
63,
2064,
523,
1663,
20171,
1891,
63,
527,
63,
72,
324,
32252,
12,
20171,
1891,
63,
18446,
27,
199,
199,
8366,
32744,
4772,
63,
1360,
8,
505,
9,
17409,
1230,
2709,
1318,
473,
3218,
934,
2617,
30508,
2962,
283,
3009,
7,
4319,
2672,
4,
523,
10468,
3350,
8,
1814,
8,
1814,
8,
1814,
8,
1814,
22187,
17,
12,
7673,
297,
7673,
5282,
27,
659,
30243,
7673,
4116,
27,
659,
639,
26120,
7673,
3308,
27,
659,
32089,
7673,
5184,
27,
659,
1449,
297,
7673,
3,
1355,
10784,
27,
199,
23174,
8700,
199,
199,
19350,
9934,
19959,
63,
1188,
21380,
29955,
2754,
63,
1086,
4106,
6714,
4106,
27,
199,
8366,
17055,
19959,
63,
1188,
63,
1733,
63,
1086,
4106,
5258,
19959,
63,
1188,
32210,
486,
262,
8,
1733,
63,
1086,
4106,
2736,
199,
19350,
17055,
19959,
63,
1188,
63,
1733,
63,
1086,
4106,
11543,
334,
7015,
873,
275,
32633,
2736,
199,
199,
8366,
9934,
289,
1086,
63,
873,
63,
793,
334,
344,
7017,
4938,
19770,
9301,
12,
1245,
63,
344,
17086,
2845,
5962,
2736,
199,
8366,
32744,
886,
63,
6814,
63,
856,
83,
63,
873,
63,
793,
342,
17409,
1230,
2709,
6804,
30508,
2962,
1620,
80,
458,
1710,
4319,
523,
2672,
4,
16427,
2845,
13367,
289,
1086,
63,
873,
63,
793,
27,
24646,
18689,
27,
7729,
2672,
4,
27,
199,
8366,
9074,
25703,
289,
1086,
63,
873,
63,
793,
63,
6814,
20089,
1157,
22542,
5258,
289,
1086,
63,
873,
63,
793,
523,
2381,
662,
33,
1244,
11377,
4479,
3651,
4220,
4586,
3611,
25927,
3942,
886,
63,
6814,
63,
856,
83,
63,
873,
63,
793,
7303,
199,
8366,
32744,
5666,
63,
475,
63,
856,
83,
63,
873,
63,
793,
342,
17409,
1230,
2709,
6804,
30508,
2962,
1620,
80,
458,
1710,
4319,
523,
2672,
4,
16427,
22542,
12872,
289,
1086,
63,
873,
63,
793,
334,
1188,
63,
344,
9,
13992,
334,
11365,
14,
344,
2736,
24646,
18689,
27,
7729,
2672,
4,
27,
199,
8366,
9074,
25703,
19959,
63,
1188,
63,
873,
63,
1733,
63,
1086,
4106,
63,
4146,
523,
6262,
18155,
22542,
1549,
17148,
1634,
5420,
12,
8018,
63,
1317,
5258,
19959,
63,
1188,
523,
2381,
662,
33,
1244,
9769,
55,
3651,
4220,
4586,
3611,
25927,
3942,
5666,
63,
475,
63,
856,
83,
63,
873,
63,
793,
7303,
199,
624,
395,
267,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
23544,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
2060,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3933,
12,
3376,
63,
354,
534,
2060,
3855,
355,
661,
2019,
63,
2886,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
12,
3376,
63,
354,
534,
2019,
4676,
3855,
355,
661,
374,
63,
11434,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
534,
20924,
2335,
626,
642,
922,
965,
1006,
3443,
1928,
7662,
26694,
3062,
3130,
3376,
63,
354,
534,
11434,
2004,
3855,
355,
661,
2123,
297,
1709,
14,
16577,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
2194,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
374,
63,
7018,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
374,
63,
2682,
297,
1709,
14,
5036,
8,
885,
29,
549,
1826,
355,
661,
374,
63,
3018,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
602,
63,
11806,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
1826,
355,
661,
374,
63,
12324,
63,
5869,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
2861,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
1826,
355,
661,
3612,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
1826,
355,
661,
3929,
297,
1709,
14,
3901,
4000,
355,
661,
2019,
63,
3929,
63,
29645,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
772,
1826,
355,
661,
1246,
63,
498,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
708,
1826,
355,
661,
4296,
63,
1745,
63,
14487,
63,
12782,
297,
1709,
14,
5036,
8,
885,
29,
549,
1826,
355,
661,
4296,
63,
1745,
63,
14990,
83,
297,
1709,
14,
5036,
8,
885,
29,
549,
1826,
355,
661,
4296,
63,
14487,
63,
12782,
297,
1709,
14,
5036,
8,
885,
29,
549,
1826,
355,
661,
4296,
63,
14990,
83,
297,
1709,
14,
5036,
8,
885,
29,
549,
1826,
355,
661
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
12,
6180,
199,
646,
4546,
698,
14,
992,
199,
646,
1639,
14,
697,
14,
992,
14,
14281,
199,
646,
1639,
14,
1208,
14,
7145,
199,
504,
1639,
14,
2190,
492,
2202,
199,
646,
19959,
14,
992,
421,
199,
533,
12090,
8,
7685,
14,
9816,
304,
339,
5124,
275,
359,
267,
661,
1178,
297,
283,
4183,
63,
2747,
659,
272,
1622,
339,
340,
298,
10675,
2,
440,
315,
2202,
14,
27260,
905,
885,
6611,
15956,
6229,
267,
1315,
11294,
63,
10675,
63,
7685,
275,
942,
327,
730,
26,
3686,
327,
4178,
921,
5031,
14,
957,
15,
42,
3210,
7351,
44,
15,
1662,
647,
15,
10115,
15,
845,
772,
272,
587,
26,
267,
1315,
11294,
63,
10675,
63,
7685,
275,
359,
288,
327,
16579,
13,
505,
2754,
288,
6180,
14,
2540,
4657,
4852,
199,
8366,
11951,
5795,
7762,
577,
6196,
1075,
4392,
20171,
1891,
63,
527,
63,
72,
324,
32252,
523,
334,
1160,
275,
365,
321,
914,
12,
7448,
1173,
275,
655,
63,
527,
12,
31030,
1173,
275,
655,
63,
527,
12,
8015,
23759,
275,
1315,
11294,
63,
17872,
2736,
199,
8366,
11951,
5795,
7762,
15869,
15301,
1315,
11294,
14,
17872,
63,
527,
63,
1733,
334,
16188,
29,
4198,
63,
7959,
14,
17872,
2736,
199,
19350,
11951,
5795,
7762,
15869,
15301,
1315,
11294,
14,
17872,
63,
527,
63,
1733,
523,
12112,
1157,
603,
7121,
1206,
2381,
13294,
1027,
12,
13294,
72,
1027,
12,
394,
1027,
63,
4371,
2064,
12,
4349,
12,
394,
1027,
12,
394,
1027,
63,
2064,
523,
1663,
20171,
1891,
63,
527,
63,
72,
324,
32252,
12,
20171,
1891,
63,
18446,
27,
199,
199,
8366,
32744,
4772,
63,
1360,
8,
505,
9,
17409,
1230,
2709,
1318,
473,
3218,
934,
2617,
30508,
2962,
283,
3009,
7,
4319,
2672,
4,
523,
10468,
3350,
8,
1814,
8,
1814,
8,
1814,
8,
1814,
22187,
17,
12,
7673,
297,
7673,
5282,
27,
659,
30243,
7673,
4116,
27,
659,
639,
26120,
7673,
3308,
27,
659,
32089,
7673,
5184,
27,
659,
1449,
297,
7673,
3,
1355,
10784,
27,
199,
23174,
8700,
199,
199,
19350,
9934,
19959,
63,
1188,
21380,
29955,
2754,
63,
1086,
4106,
6714,
4106,
27,
199,
8366,
17055,
19959,
63,
1188,
63,
1733,
63,
1086,
4106,
5258,
19959,
63,
1188,
32210,
486,
262,
8,
1733,
63,
1086,
4106,
2736,
199,
19350,
17055,
19959,
63,
1188,
63,
1733,
63,
1086,
4106,
11543,
334,
7015,
873,
275,
32633,
2736,
199,
199,
8366,
9934,
289,
1086,
63,
873,
63,
793,
334,
344,
7017,
4938,
19770,
9301,
12,
1245,
63,
344,
17086,
2845,
5962,
2736,
199,
8366,
32744,
886,
63,
6814,
63,
856,
83,
63,
873,
63,
793,
342,
17409,
1230,
2709,
6804,
30508,
2962,
1620,
80,
458,
1710,
4319,
523,
2672,
4,
16427,
2845,
13367,
289,
1086,
63,
873,
63,
793,
27,
24646,
18689,
27,
7729,
2672,
4,
27,
199,
8366,
9074,
25703,
289,
1086,
63,
873,
63,
793,
63,
6814,
20089,
1157,
22542,
5258,
289,
1086,
63,
873,
63,
793,
523,
2381,
662,
33,
1244,
11377,
4479,
3651,
4220,
4586,
3611,
25927,
3942,
886,
63,
6814,
63,
856,
83,
63,
873,
63,
793,
7303,
199,
8366,
32744,
5666,
63,
475,
63,
856,
83,
63,
873,
63,
793,
342,
17409,
1230,
2709,
6804,
30508,
2962,
1620,
80,
458,
1710,
4319,
523,
2672,
4,
16427,
22542,
12872,
289,
1086,
63,
873,
63,
793,
334,
1188,
63,
344,
9,
13992,
334,
11365,
14,
344,
2736,
24646,
18689,
27,
7729,
2672,
4,
27,
199,
8366,
9074,
25703,
19959,
63,
1188,
63,
873,
63,
1733,
63,
1086,
4106,
63,
4146,
523,
6262,
18155,
22542,
1549,
17148,
1634,
5420,
12,
8018,
63,
1317,
5258,
19959,
63,
1188,
523,
2381,
662,
33,
1244,
9769,
55,
3651,
4220,
4586,
3611,
25927,
3942,
5666,
63,
475,
63,
856,
83,
63,
873,
63,
793,
7303,
199,
624,
395,
267,
1622,
339,
5331,
275,
359,
267,
6180,
14,
14907,
8,
288,
536,
534,
23544,
297,
288,
1504,
1524,
355,
661,
344,
297,
1709,
14,
4378,
8,
3832,
63,
354,
534,
998,
297,
8437,
29,
797,
12,
2599,
63,
3966,
29,
549,
12,
5062,
63,
498,
29,
549,
1826,
355,
661,
2060,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3933,
12,
3376,
63,
354,
534,
2060,
3855,
355,
661,
2019,
63,
2886,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
12,
3376,
63,
354,
534,
2019,
4676,
3855,
355,
661,
374,
63,
11434,
297,
1709,
14,
5036,
8,
885,
29,
797,
12,
1720,
63,
505,
534,
20924,
2335,
626,
642,
922,
965,
1006,
3443,
1928,
7662,
26694,
3062,
3130,
3376,
63,
354,
534,
11434,
2004,
3855,
355,
661,
2123,
297,
1709,
14,
16577,
8,
3235,
29,
549,
12,
1390,
63,
1267,
29,
2194,
12,
1592,
63,
1080,
29,
549,
1826,
355,
661,
374,
63,
7018,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
374,
63,
2682,
297,
1709,
14,
5036,
8,
885,
29,
549,
1826,
355,
661,
374,
63,
3018,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
602,
63,
11806,
297,
1709,
14,
4626,
8,
885,
29,
1176,
14,
1208,
14,
7145,
14,
2131,
1826,
355,
661,
374,
63,
12324,
63,
5869,
297,
1709,
14,
5036,
8,
885,
29,
797,
1826,
355,
661,
2861,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
1826,
355,
661,
3612,
63,
354,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
1960,
1826,
355,
661,
3929,
297,
1709,
14,
3901,
4000,
355,
661,
2019,
63,
3929,
63,
29645,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
772,
1826,
355,
661,
1246,
63,
498,
297,
1709,
14,
2183,
8,
988,
63,
1267,
29,
708,
1826,
355,
661,
4296,
63,
1745,
63,
14487,
63,
12782,
297,
1709,
14,
5036,
8,
885,
29,
549,
1826,
355,
661,
4296,
63,
1745,
63,
14990,
83,
297,
1709,
14,
5036,
8,
885,
29,
549,
1826,
355,
661,
4296,
63,
14487,
63,
12782,
297,
1709,
14,
5036,
8,
885,
29,
549,
1826,
355,
661,
4296,
63,
14990,
83,
297,
1709,
14,
5036,
8,
885,
29,
549,
1826,
355,
661,
0
] |
[
1,
1,
1,
1,
1,
1,
1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emopwd/test/test_certificat/client.py
|
1
|
2847
|
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Copyright (c) 2015-2016, Thierry Lemeunier <thierry at lemeunier dot net>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import ssl
import socket
import pprint
import argparse
argparser = argparse.ArgumentParser(description='Client to test a X.509 certificat')
argparser.add_argument('-c', '--cert', metavar='certificat', type=str,
required=True, help="the PEM X509 certificat file")
argparser.add_argument('-p', '--port' , type=int, nargs='?', default=62230,
metavar='port', help='the server connexion port')
options = argparser.parse_args()
print("Using port number " + str(options.port))
print("Taking '" + options.cert + "' for certificat file")
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.verify_mode = ssl.CERT_OPTIONAL
context.check_hostname = False
context.options |= ssl.OP_NO_SSLv2 # SSL v2 not allowed
context.options |= ssl.OP_NO_SSLv3 # SSL v3 not allowed
context.load_verify_locations(cafile=options.cert)
conn = context.wrap_socket(socket.socket(socket.AF_INET))
try:
conn.connect(("localhost", options.port))
except ConnectionRefusedError as e:
print(e)
print("The server seems not running or verify the port number.")
exit(1)
except ssl.SSLError as e:
print(e)
print("There is a problem with this certificat.")
exit(1)
except Exception as e:
print(e)
exit(1)
print(conn.cipher())
cert = conn.getpeercert()
pprint.pprint(cert)
conn.send(b'Hello World!')
print("The certificat seems compatible.")
|
bsd-2-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
6900,
13,
9261,
12,
3868,
4446,
651,
7005,
278,
324,
4446,
665,
273,
4446,
651,
737,
1026,
278,
324,
4446,
6308,
1851,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
221,
199,
3,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
221,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
199,
3,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
199,
3,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
199,
3,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
199,
3,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
199,
3,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
199,
3,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
6149,
199,
646,
2838,
199,
646,
10933,
199,
646,
7534,
199,
199,
1273,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
3041,
370,
511,
282,
1323,
14,
6576,
3361,
1428,
3385,
358,
199,
199,
1273,
2087,
14,
525,
63,
2094,
3654,
67,
297,
2850,
4736,
297,
8214,
534,
2247,
1428,
3385,
297,
730,
29,
495,
12,
221,
2432,
1415,
29,
549,
12,
1720,
628,
1589,
25957,
1323,
6576,
3361,
1428,
3385,
570,
531,
717,
199,
1273,
2087,
14,
525,
63,
2094,
3654,
80,
297,
2850,
719,
7,
2360,
730,
29,
442,
12,
9237,
31468,
849,
29,
30603,
1216,
12,
2432,
8214,
534,
719,
297,
1720,
534,
1589,
1654,
2557,
476,
1636,
1844,
358,
199,
199,
1419,
275,
1680,
2087,
14,
1122,
63,
589,
342,
199,
199,
1361,
480,
10369,
1844,
1329,
298,
435,
620,
8,
1419,
14,
719,
430,
199,
1361,
480,
52,
11124,
5522,
435,
1511,
14,
4736,
435,
3546,
367,
3361,
1428,
3385,
570,
531,
199,
199,
1100,
275,
6149,
14,
5413,
2998,
8,
4266,
14,
9583,
63,
21082,
1789,
9,
199,
1100,
14,
4712,
63,
632,
275,
6149,
14,
11163,
63,
21008,
199,
1100,
14,
1074,
63,
4269,
275,
756,
199,
1100,
14,
1419,
8901,
6149,
14,
1938,
63,
2826,
63,
21082,
18,
327,
7799,
373,
18,
440,
4370,
199,
1100,
14,
1419,
8901,
6149,
14,
1938,
63,
2826,
63,
21082,
19,
327,
7799,
373,
19,
440,
4370,
199,
1100,
14,
912,
63,
4712,
63,
8022,
8,
696,
493,
29,
1419,
14,
4736,
9,
199,
199,
1631,
275,
1067,
14,
3823,
63,
3450,
8,
3450,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
430,
199,
199,
893,
26,
272,
2557,
14,
2242,
9313,
5967,
401,
1511,
14,
719,
430,
199,
2590,
8113,
2891,
2972,
547,
465,
325,
26,
272,
870,
8,
69,
9,
272,
870,
480,
1918,
1654,
12237,
440,
3879,
503,
4911,
314,
1844,
1329,
2685,
272,
4458,
8,
17,
9,
199,
2590,
6149,
14,
27102,
465,
325,
26,
272,
870,
8,
69,
9,
272,
870,
480,
10924,
365,
282,
5160,
543,
642,
3361,
1428,
3385,
2685,
272,
4458,
8,
17,
9,
199,
2590,
2186,
465,
325,
26,
272,
870,
8,
69,
9,
272,
4458,
8,
17,
9,
199,
199,
1361,
8,
1631,
14,
9231,
1012,
199,
199,
4736,
275,
2557,
14,
362,
7866,
4736,
342,
199,
15380,
14,
15380,
8,
4736,
9,
199,
199,
1631,
14,
2254,
8,
66,
7,
6257,
13064,
10916,
199,
199,
1361,
480,
1918,
3361,
1428,
3385,
12237,
9025,
2685,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
199,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
6900,
13,
9261,
12,
3868,
4446,
651,
7005,
278,
324,
4446,
665,
273,
4446,
651,
737,
1026,
278,
324,
4446,
6308,
1851,
30,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
199,
3,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
413,
14,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
221,
199,
3,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
499,
14,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
199,
3,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
199,
3,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
221,
199,
3,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
199,
3,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
1549,
199,
3,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
9206,
27,
199,
3,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
199,
3,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
199,
3,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
199,
3,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
6149,
199,
646,
2838,
199,
646,
10933,
199,
646,
7534,
199,
199,
1273,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
3041,
370,
511,
282,
1323,
14,
6576,
3361,
1428,
3385,
358,
199,
199,
1273,
2087,
14,
525,
63,
2094,
3654,
67,
297,
2850,
4736,
297,
8214,
534,
2247,
1428,
3385,
297,
730,
29,
495,
12,
221,
2432,
1415,
29,
549,
12,
1720,
628,
1589,
25957,
1323,
6576,
3361,
1428,
3385,
570,
531,
717,
199,
1273,
2087,
14,
525,
63,
2094,
3654,
80,
297,
2850,
719,
7,
2360,
730,
29,
442,
12,
9237,
31468,
849,
29,
30603,
1216,
12,
2432,
8214,
534,
719,
297,
1720,
534,
1589,
1654,
2557,
476,
1636,
1844,
358,
199,
199,
1419,
275,
1680,
2087,
14,
1122,
63,
589,
342,
199,
199,
1361,
480,
10369,
1844,
1329,
298,
435,
620,
8,
1419,
14,
719,
430,
199,
1361,
480,
52,
11124,
5522,
435,
1511,
14,
4736,
435,
3546,
367,
3361,
1428,
3385,
570,
531,
199,
199,
1100,
275,
6149,
14,
5413,
2998,
8,
4266,
14,
9583,
63,
21082,
1789,
9,
199,
1100,
14,
4712,
63,
632,
275,
6149,
14,
11163,
63,
21008,
199,
1100,
14,
1074,
63,
4269,
275,
756,
199,
1100,
14,
1419,
8901,
6149,
14,
1938,
63,
2826,
63,
21082,
18,
327,
7799,
373,
18,
440,
4370,
199,
1100,
14,
1419,
8901,
6149,
14,
1938,
63,
2826,
63,
21082,
19,
327,
7799,
373,
19,
440,
4370,
199,
1100,
14,
912,
63,
4712,
63,
8022,
8,
696,
493,
29,
1419,
14,
4736,
9,
199,
199,
1631,
275,
1067,
14,
3823,
63,
3450,
8,
3450,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
430,
199,
199,
893,
26,
272,
2557,
14,
2242,
9313,
5967,
401,
1511,
14,
719,
430,
199,
2590,
8113,
2891,
2972,
547,
465,
325,
26,
272,
870,
8,
69,
9,
272,
870,
480,
1918,
1654,
12237,
440,
3879,
503,
4911,
314,
1844,
1329,
2685,
272,
4458,
8,
17,
9,
199,
2590,
6149,
14,
27102,
465,
325,
26,
272,
870,
8,
69,
9,
272,
870,
480,
10924,
365,
282,
5160,
543,
642,
3361,
1428,
3385,
2685,
272,
4458,
8,
17,
9,
199,
2590,
2186,
465,
325,
26,
272,
870,
8,
69,
9,
272,
4458,
8,
17,
9,
199,
199,
1361,
8,
1631,
14,
9231,
1012,
199,
199,
4736,
275,
2557,
14,
362,
7866,
4736,
342,
199,
15380,
14,
15380,
8,
4736,
9,
199,
199,
1631,
14,
2254,
8,
66,
7,
6257,
13064,
10916,
199,
199,
1361,
480,
1918,
3361,
1428,
3385,
12237,
9025,
2685,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
buqing2009/MissionPlanner
|
Lib/encodings/utf_16_le.py
|
103
|
1079
|
""" Python 'utf-16-le' Codec
Written by Marc-Andre Lemburg (mal@lemburg.com).
(c) Copyright CNRI, All Rights Reserved. NO WARRANTY.
"""
import codecs
### Codec APIs
encode = codecs.utf_16_le_encode
def decode(input, errors='strict'):
return codecs.utf_16_le_decode(input, errors, True)
class IncrementalEncoder(codecs.IncrementalEncoder):
def encode(self, input, final=False):
return codecs.utf_16_le_encode(input, self.errors)[0]
class IncrementalDecoder(codecs.BufferedIncrementalDecoder):
_buffer_decode = codecs.utf_16_le_decode
class StreamWriter(codecs.StreamWriter):
encode = codecs.utf_16_le_encode
class StreamReader(codecs.StreamReader):
decode = codecs.utf_16_le_decode
### encodings module API
def getregentry():
return codecs.CodecInfo(
name='utf-16-le',
encode=encode,
decode=decode,
incrementalencoder=IncrementalEncoder,
incrementaldecoder=IncrementalDecoder,
streamreader=StreamReader,
streamwriter=StreamWriter,
)
|
gpl-3.0
|
[
624,
2018,
283,
1624,
13,
975,
13,
274,
7,
13732,
8065,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
2999,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
2999,
199,
624,
202,
199,
646,
6010,
2999,
199,
5680,
13732,
15913,
2999,
199,
2143,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2143,
2999,
199,
318,
4849,
8,
1210,
12,
2552,
534,
4768,
735,
1128,
372,
6010,
14,
1624,
63,
975,
63,
274,
63,
2708,
8,
1210,
12,
2552,
12,
715,
9,
2999,
199,
533,
24350,
8,
8933,
14,
17016,
304,
1128,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
1624,
63,
975,
63,
274,
63,
2143,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
2999,
199,
533,
24385,
8,
8933,
14,
23139,
16703,
304,
1128,
485,
2738,
63,
2708,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2708,
2999,
199,
533,
24163,
8,
8933,
14,
16551,
304,
1128,
3752,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2143,
2999,
199,
533,
22970,
8,
8933,
14,
16132,
304,
1128,
4849,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2708,
2999,
199,
5680,
14134,
859,
3261,
2999,
199,
318,
26116,
837,
1128,
372,
6010,
14,
26375,
8,
1039,
536,
534,
1624,
13,
975,
13,
274,
297,
1039,
3752,
29,
2143,
12,
1039,
4849,
29,
2708,
12,
1039,
26329,
29,
17016,
12,
1039,
26317,
29,
16703,
12,
1039,
26101,
29,
16132,
12,
1039,
26112,
29,
16551,
12,
1128,
776,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2018,
283,
1624,
13,
975,
13,
274,
7,
13732,
8065,
199,
32329,
701,
603,
9912,
13,
3325,
264,
7005,
32649,
334,
2174,
32,
274,
32649,
14,
957,
680,
2999,
199,
8,
67,
9,
1898,
445,
46,
6129,
12,
2900,
5924,
5702,
14,
4825,
3408,
14,
2999,
199,
624,
202,
199,
646,
6010,
2999,
199,
5680,
13732,
15913,
2999,
199,
2143,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2143,
2999,
199,
318,
4849,
8,
1210,
12,
2552,
534,
4768,
735,
1128,
372,
6010,
14,
1624,
63,
975,
63,
274,
63,
2708,
8,
1210,
12,
2552,
12,
715,
9,
2999,
199,
533,
24350,
8,
8933,
14,
17016,
304,
1128,
347,
3752,
8,
277,
12,
1324,
12,
4242,
29,
797,
304,
1039,
372,
6010,
14,
1624,
63,
975,
63,
274,
63,
2143,
8,
1210,
12,
291,
14,
2550,
2788,
16,
61,
2999,
199,
533,
24385,
8,
8933,
14,
23139,
16703,
304,
1128,
485,
2738,
63,
2708,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2708,
2999,
199,
533,
24163,
8,
8933,
14,
16551,
304,
1128,
3752,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2143,
2999,
199,
533,
22970,
8,
8933,
14,
16132,
304,
1128,
4849,
275,
6010,
14,
1624,
63,
975,
63,
274,
63,
2708,
2999,
199,
5680,
14134,
859,
3261,
2999,
199,
318,
26116,
837,
1128,
372,
6010,
14,
26375,
8,
1039,
536,
534,
1624,
13,
975,
13,
274,
297,
1039,
3752,
29,
2143,
12,
1039,
4849,
29,
2708,
12,
1039,
26329,
29,
17016,
12,
1039,
26317,
29,
16703,
12,
1039,
26101,
29,
16132,
12,
1039,
26112,
29,
16551,
12,
1128,
776,
1223,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
eamigo86/graphene-django-extras
|
tests/conftest.py
|
1
|
3393
|
import os
import sys
import django
from django.core import management
def pytest_addoption(parser):
parser.addoption(
"--no-pkgroot",
action="store_true",
default=False,
help="Remove package root directory from sys.path, ensuring that "
"graphene_django_extras is imported from the installed site-packages. "
"Used for testing the distribution.",
)
parser.addoption(
"--staticfiles",
action="store_true",
default=False,
help="Run tests with static files collection, using manifest "
"staticfiles storage. Used for testing the distribution.",
)
def pytest_configure(config):
from django.conf import settings
settings.configure(
ALLOWED_HOSTS=["*"],
DEBUG_PROPAGATE_EXCEPTIONS=True,
DATABASES={
"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": ":memory:"}
},
SITE_ID=1,
SECRET_KEY="not very secret in tests",
USE_I18N=True,
USE_L10N=True,
STATIC_URL="/static/",
ROOT_URLCONF="tests.urls",
TEMPLATES=[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"APP_DIRS": True,
"OPTIONS": {"debug": True}, # We want template errors to raise
}
],
MIDDLEWARE=(
"django.middleware.common.CommonMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
),
INSTALLED_APPS=(
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.sites",
"django.contrib.staticfiles",
"graphene_django",
"tests",
),
PASSWORD_HASHERS=("django.contrib.auth.hashers.MD5PasswordHasher",),
GRAPHENE={
"SCHEMA": "tests.schema.schema",
"MIDDLEWARE": ["graphene_django_extras.ExtraGraphQLDirectiveMiddleware"],
},
AUTHENTICATION_BACKENDS=(
"django.contrib.auth.backends.ModelBackend",
"guardian.backends.ObjectPermissionBackend",
),
)
# FIXME(eclar): necessary ?
if config.getoption("--no-pkgroot"):
sys.path.pop(0)
# import rest_framework before pytest re-adds the package root directory.
import graphene_django_extras
package_dir = os.path.join(os.getcwd(), "graphene_django_extras")
assert not graphene_django_extras.__file__.startswith(package_dir)
# Manifest storage will raise an exception if static files are not present (ie, a packaging failure).
if config.getoption("--staticfiles"):
import graphene_django_extras
settings.STATIC_ROOT = os.path.join(
os.path.dirname(graphene_django_extras.__file__), "static-root"
)
settings.STATICFILES_STORAGE = (
"django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
)
django.setup()
if config.getoption("--staticfiles"):
management.call_command("collectstatic", verbosity=0, interactive=False)
|
mit
|
[
646,
747,
199,
646,
984,
199,
199,
646,
1639,
199,
504,
1639,
14,
1018,
492,
10041,
421,
199,
318,
4613,
63,
525,
1422,
8,
2087,
304,
272,
1798,
14,
525,
1422,
8,
267,
4320,
889,
13,
4600,
1231,
401,
267,
1595,
628,
1617,
63,
2052,
401,
267,
849,
29,
797,
12,
267,
1720,
628,
5587,
2559,
1738,
2082,
687,
984,
14,
515,
12,
12889,
4039,
626,
298,
267,
298,
2180,
6349,
63,
1176,
63,
9975,
365,
8439,
687,
314,
4903,
4770,
13,
5154,
14,
298,
267,
298,
9167,
367,
5343,
314,
4084,
4765,
272,
776,
272,
1798,
14,
525,
1422,
8,
267,
4320,
18373,
401,
267,
1595,
628,
1617,
63,
2052,
401,
267,
849,
29,
797,
12,
267,
1720,
628,
2540,
2295,
543,
2955,
1584,
3245,
12,
1808,
7712,
298,
267,
298,
18373,
4887,
14,
8051,
367,
5343,
314,
4084,
4765,
272,
776,
421,
199,
318,
4613,
63,
6472,
8,
888,
304,
272,
687,
1639,
14,
2190,
492,
2202,
339,
2202,
14,
6472,
8,
267,
27805,
1149,
63,
23775,
6270,
10,
2255,
267,
10990,
63,
19926,
1254,
1951,
63,
25054,
29,
549,
12,
267,
26931,
21983,
3126,
288,
298,
885,
582,
2420,
15956,
582,
298,
1176,
14,
697,
14,
7765,
14,
10659,
19,
401,
298,
2339,
582,
7244,
4844,
26,
3570,
267,
1660,
267,
428,
4427,
63,
998,
29,
17,
12,
267,
5795,
11771,
63,
3078,
628,
1397,
7437,
7565,
315,
2295,
401,
267,
4815,
63,
41,
1085,
46,
29,
549,
12,
267,
4815,
63,
44,
709,
46,
29,
549,
12,
267,
27815,
63,
2632,
9555,
1986,
10665,
267,
16547,
63,
18125,
628,
2219,
14,
3603,
401,
267,
377,
9358,
16601,
1524,
288,
469,
355,
298,
18145,
582,
298,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
401,
355,
298,
7121,
63,
14455,
582,
715,
12,
355,
298,
8808,
582,
2420,
1757,
582,
715,
1386,
221,
327,
2136,
2934,
1978,
2552,
370,
746,
288,
789,
267,
2156,
267,
30718,
2687,
288,
298,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
401,
288,
298,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
401,
288,
298,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
401,
288,
298,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
401,
288,
298,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
401,
267,
2318,
267,
31061,
63,
14219,
2687,
288,
298,
1176,
14,
2828,
14,
2113,
401,
288,
298,
1176,
14,
2828,
14,
1178,
401,
288,
298,
1176,
14,
2828,
14,
10778,
401,
288,
298,
1176,
14,
2828,
14,
11676,
401,
288,
298,
1176,
14,
2828,
14,
8619,
401,
288,
298,
1176,
14,
2828,
14,
18373,
401,
288,
298,
2180,
6349,
63,
1176,
401,
288,
298,
2219,
401,
267,
2318,
267,
21705,
5172,
63,
13533,
31700,
15387,
1176,
14,
2828,
14,
1178,
14,
31342,
14,
5127,
21,
27596,
18529,
267,
21772,
21126,
742,
37,
3126,
288,
298,
10926,
582,
298,
2219,
14,
3629,
14,
3629,
401,
288,
298,
19987,
582,
2097,
2180,
6349,
63,
1176,
63,
9975,
14,
7426,
4578,
2940,
29489,
6608,
2255,
267,
1660,
267,
7560,
20987,
2594,
63,
28988,
2687,
288,
298,
1176,
14,
2828,
14,
1178,
14,
7765,
14,
1685,
8447,
401,
288,
298,
6051,
31186,
14,
7765,
14,
1692,
7980,
8447,
401,
267,
2318,
272,
776,
339,
327,
7600,
8,
69,
4925,
304,
5784,
5805,
272,
340,
1101,
14,
362,
1422,
6739,
889,
13,
4600,
1231,
2349,
267,
984,
14,
515,
14,
1935,
8,
16,
9,
398,
327,
492,
4618,
63,
4857,
2544,
4613,
295,
13,
525,
83,
314,
2559,
1738,
2082,
14,
267,
492,
3343,
6349,
63,
1176,
63,
9975,
398,
2559,
63,
694,
275,
747,
14,
515,
14,
904,
8,
736,
14,
9458,
1062,
298,
2180,
6349,
63,
1176,
63,
9975,
531,
267,
702,
440,
3343,
6349,
63,
1176,
63,
9975,
855,
493,
4343,
2460,
8,
2491,
63,
694,
9,
339,
327,
4688,
3944,
4887,
911,
746,
376,
1919,
340,
2955,
1584,
787,
440,
3451,
334,
1873,
12,
282,
27369,
5988,
680,
272,
340,
1101,
14,
362,
1422,
6739,
18373,
2349,
267,
492,
3343,
6349,
63,
1176,
63,
9975,
398,
2202,
14,
10449,
63,
5441,
275,
747,
14,
515,
14,
904,
8,
288,
747,
14,
515,
14,
3475,
8,
2180,
6349,
63,
1176,
63,
9975,
855,
493,
10139,
298,
1986,
13,
1231,
2,
267,
776,
267,
2202,
14,
10449,
9472,
63,
17467,
275,
334,
288,
298,
1176,
14,
2828,
14,
18373,
14,
3494,
14,
11038,
9278,
5535,
6408,
2,
267,
776,
339,
1639,
14,
2758,
342,
339,
340,
1101,
14,
362,
1422,
6739,
18373,
2349,
267,
10041,
14,
1250,
63,
1531,
480,
7112,
1986,
401,
8661,
29,
16,
12,
12777,
29,
797,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
646,
984,
199,
199,
646,
1639,
199,
504,
1639,
14,
1018,
492,
10041,
421,
199,
318,
4613,
63,
525,
1422,
8,
2087,
304,
272,
1798,
14,
525,
1422,
8,
267,
4320,
889,
13,
4600,
1231,
401,
267,
1595,
628,
1617,
63,
2052,
401,
267,
849,
29,
797,
12,
267,
1720,
628,
5587,
2559,
1738,
2082,
687,
984,
14,
515,
12,
12889,
4039,
626,
298,
267,
298,
2180,
6349,
63,
1176,
63,
9975,
365,
8439,
687,
314,
4903,
4770,
13,
5154,
14,
298,
267,
298,
9167,
367,
5343,
314,
4084,
4765,
272,
776,
272,
1798,
14,
525,
1422,
8,
267,
4320,
18373,
401,
267,
1595,
628,
1617,
63,
2052,
401,
267,
849,
29,
797,
12,
267,
1720,
628,
2540,
2295,
543,
2955,
1584,
3245,
12,
1808,
7712,
298,
267,
298,
18373,
4887,
14,
8051,
367,
5343,
314,
4084,
4765,
272,
776,
421,
199,
318,
4613,
63,
6472,
8,
888,
304,
272,
687,
1639,
14,
2190,
492,
2202,
339,
2202,
14,
6472,
8,
267,
27805,
1149,
63,
23775,
6270,
10,
2255,
267,
10990,
63,
19926,
1254,
1951,
63,
25054,
29,
549,
12,
267,
26931,
21983,
3126,
288,
298,
885,
582,
2420,
15956,
582,
298,
1176,
14,
697,
14,
7765,
14,
10659,
19,
401,
298,
2339,
582,
7244,
4844,
26,
3570,
267,
1660,
267,
428,
4427,
63,
998,
29,
17,
12,
267,
5795,
11771,
63,
3078,
628,
1397,
7437,
7565,
315,
2295,
401,
267,
4815,
63,
41,
1085,
46,
29,
549,
12,
267,
4815,
63,
44,
709,
46,
29,
549,
12,
267,
27815,
63,
2632,
9555,
1986,
10665,
267,
16547,
63,
18125,
628,
2219,
14,
3603,
401,
267,
377,
9358,
16601,
1524,
288,
469,
355,
298,
18145,
582,
298,
1176,
14,
1160,
14,
7765,
14,
1176,
14,
9323,
17969,
401,
355,
298,
7121,
63,
14455,
582,
715,
12,
355,
298,
8808,
582,
2420,
1757,
582,
715,
1386,
221,
327,
2136,
2934,
1978,
2552,
370,
746,
288,
789,
267,
2156,
267,
30718,
2687,
288,
298,
1176,
14,
5754,
14,
2330,
14,
7844,
6608,
401,
288,
298,
1176,
14,
2828,
14,
11676,
14,
5754,
14,
4434,
6608,
401,
288,
298,
1176,
14,
2828,
14,
1178,
14,
5754,
14,
10348,
6608,
401,
288,
298,
1176,
14,
2828,
14,
3431,
14,
5754,
14,
2209,
6608,
401,
288,
298,
1176,
14,
5754,
14,
10088,
14,
13912,
25322,
401,
267,
2318,
267,
31061,
63,
14219,
2687,
288,
298,
1176,
14,
2828,
14,
2113,
401,
288,
298,
1176,
14,
2828,
14,
1178,
401,
288,
298,
1176,
14,
2828,
14,
10778,
401,
288,
298,
1176,
14,
2828,
14,
11676,
401,
288,
298,
1176,
14,
2828,
14,
8619,
401,
288,
298,
1176,
14,
2828,
14,
18373,
401,
288,
298,
2180,
6349,
63,
1176,
401,
288,
298,
2219,
401,
267,
2318,
267,
21705,
5172,
63,
13533,
31700,
15387,
1176,
14,
2828,
14,
1178,
14,
31342,
14,
5127,
21,
27596,
18529,
267,
21772,
21126,
742,
37,
3126,
288,
298,
10926,
582,
298,
2219,
14,
3629,
14,
3629,
401,
288,
298,
19987,
582,
2097,
2180,
6349,
63,
1176,
63,
9975,
14,
7426,
4578,
2940,
29489,
6608,
2255,
267,
1660,
267,
7560,
20987,
2594,
63,
28988,
2687,
288,
298,
1176,
14,
2828,
14,
1178,
14,
7765,
14,
1685,
8447,
401,
288,
298,
6051,
31186,
14,
7765,
14,
1692,
7980,
8447,
401,
267,
2318,
272,
776,
339,
327,
7600,
8,
69,
4925,
304,
5784,
5805,
272,
340,
1101,
14,
362,
1422,
6739,
889,
13,
4600,
1231,
2349,
267,
984,
14,
515,
14,
1935,
8,
16,
9,
398,
327,
492,
4618,
63,
4857,
2544,
4613,
295,
13,
525,
83,
314,
2559,
1738,
2082,
14,
267,
492,
3343,
6349,
63,
1176,
63,
9975,
398,
2559,
63,
694,
275,
747,
14,
515,
14,
904,
8,
736,
14,
9458,
1062,
298,
2180,
6349,
63,
1176,
63,
9975,
531,
267,
702,
440,
3343,
6349,
63,
1176,
63,
9975,
855,
493,
4343,
2460,
8,
2491,
63,
694,
9,
339,
327,
4688,
3944,
4887,
911,
746,
376,
1919,
340,
2955,
1584,
787,
440,
3451,
334,
1873,
12,
282,
27369,
5988,
680,
272,
340,
1101,
14,
362,
1422,
6739,
18373,
2349,
267,
492,
3343,
6349,
63,
1176,
63,
9975,
398,
2202,
14,
10449,
63,
5441,
275,
747,
14,
515,
14,
904,
8,
288,
747,
14,
515,
14,
3475,
8,
2180,
6349,
63,
1176,
63,
9975,
855,
493,
10139,
298,
1986,
13,
1231,
2,
267,
776,
267,
2202,
14,
10449,
9472,
63,
17467,
275,
334,
288,
298,
1176,
14,
2828,
14,
18373,
14,
3494,
14,
11038,
9278,
5535,
6408,
2,
267,
776,
339,
1639,
14,
2758,
342,
339,
340,
1101,
14,
362,
1422,
6739,
18373,
2349,
267,
10041,
14,
1250,
63,
1531,
480,
7112,
1986,
401,
8661,
29,
16,
12,
12777,
29,
797,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
viaict/viaduct
|
app/views/contact.py
|
1
|
2562
|
from flask import Blueprint, flash, redirect, render_template, url_for
from flask_babel import lazy_gettext as _
from flask_login import current_user
from app import db
from app.decorators import require_role
from app.forms import init_form
from app.forms.contact import ContactForm
from app.models.contact import Contact
from app.models.location import Location
from app.roles import Roles
from app.service import role_service
blueprint = Blueprint('contact', __name__, url_prefix='/contacts')
@blueprint.route('/', methods=['GET', 'POST'])
@blueprint.route('/<int:page_nr>/', methods=['GET', 'POST'])
@require_role(Roles.VACANCY_READ)
def list(page_nr=1):
"""Show a paginated list of contacts."""
contacts = Contact.query.paginate(page_nr, 15, False)
can_write = role_service.user_has_role(current_user, Roles.VACANCY_WRITE)
return render_template('contact/list.htm', contacts=contacts,
can_write=can_write)
@blueprint.route('/create/', methods=['GET', 'POST'])
@blueprint.route('/edit/<int:contact_id>/', methods=['GET', 'POST'])
@require_role(Roles.VACANCY_WRITE)
def edit(contact_id=None):
"""Create or edit a contact, frontend."""
if contact_id:
contact = Contact.query.get(contact_id)
else:
contact = Contact()
form = init_form(ContactForm, obj=contact)
locations = Location.query.order_by(
Location.address).order_by(Location.city)
form.location_id.choices = \
[(l.id, '%s, %s' % (l.address, l.city)) for l in locations]
if form.validate_on_submit():
if not contact.id and Contact.query.filter(
Contact.email == form.email.data).count():
flash(_('Contact email "%s" is already in use.' %
form.email.data), 'danger')
return render_template('contact/edit.htm', contact=contact,
form=form)
form.populate_obj(contact)
db.session.add(contact)
db.session.commit()
flash(_('Contact person saved.'), 'success')
return redirect(url_for('contact.edit', contact_id=contact.id))
return render_template('contact/edit.htm', contact=contact, form=form)
@blueprint.route('/delete/<int:contact_id>/', methods=['POST'])
@require_role(Roles.VACANCY_WRITE)
def delete(contact_id):
"""Delete a contact."""
contact = Contact.query.get_or_404(contact_id)
db.session.delete(contact)
db.session.commit()
flash(_('Contact person deleted.'), 'success')
return redirect(url_for('contact.list'))
|
mit
|
[
504,
7209,
492,
22447,
1361,
12,
14775,
12,
4660,
12,
3795,
63,
1160,
12,
1166,
63,
509,
199,
504,
7209,
63,
66,
902,
492,
9617,
63,
5152,
465,
485,
199,
504,
7209,
63,
2886,
492,
1453,
63,
751,
199,
199,
504,
1145,
492,
1592,
199,
504,
1145,
14,
11582,
492,
4409,
63,
3756,
199,
504,
1145,
14,
3351,
492,
4205,
63,
964,
199,
504,
1145,
14,
3351,
14,
7811,
492,
18684,
2821,
199,
504,
1145,
14,
992,
14,
7811,
492,
18684,
199,
504,
1145,
14,
992,
14,
1985,
492,
12625,
199,
504,
1145,
14,
8050,
492,
6848,
2978,
199,
504,
1145,
14,
1364,
492,
4719,
63,
1364,
199,
199,
15918,
275,
22447,
1361,
360,
7811,
297,
636,
354,
3108,
1166,
63,
1861,
8805,
18147,
358,
421,
199,
32,
15918,
14,
4449,
10998,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
32,
15918,
14,
4449,
2336,
28,
442,
26,
1606,
63,
7865,
30,
3678,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
32,
4365,
63,
3756,
8,
3863,
2978,
14,
26780,
879,
15068,
63,
5670,
9,
199,
318,
769,
8,
1606,
63,
7865,
29,
17,
304,
272,
408,
6824,
282,
9881,
23831,
769,
402,
27989,
1041,
272,
27989,
275,
18684,
14,
1131,
14,
30979,
8,
1606,
63,
7865,
12,
4114,
12,
756,
9,
272,
883,
63,
952,
275,
4719,
63,
1364,
14,
751,
63,
1989,
63,
3756,
8,
1818,
63,
751,
12,
6848,
2978,
14,
26780,
879,
15068,
63,
10387,
9,
272,
372,
3795,
63,
1160,
360,
7811,
15,
513,
14,
15575,
297,
27989,
29,
18147,
12,
2574,
883,
63,
952,
29,
2425,
63,
952,
9,
421,
199,
32,
15918,
14,
4449,
2336,
981,
3678,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
32,
15918,
14,
4449,
2336,
3773,
8316,
442,
26,
7811,
63,
344,
30,
3678,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
32,
4365,
63,
3756,
8,
3863,
2978,
14,
26780,
879,
15068,
63,
10387,
9,
199,
318,
5283,
8,
7811,
63,
344,
29,
403,
304,
272,
408,
2499,
503,
5283,
282,
8966,
12,
22523,
1041,
272,
340,
8966,
63,
344,
26,
267,
8966,
275,
18684,
14,
1131,
14,
362,
8,
7811,
63,
344,
9,
272,
587,
26,
267,
8966,
275,
18684,
342,
339,
1824,
275,
4205,
63,
964,
8,
14499,
2821,
12,
1559,
29,
7811,
9,
339,
9918,
275,
12625,
14,
1131,
14,
1648,
63,
991,
8,
267,
12625,
14,
1562,
680,
1648,
63,
991,
8,
6592,
14,
3690,
9,
272,
1824,
14,
1985,
63,
344,
14,
4577,
275,
971,
267,
3842,
76,
14,
344,
12,
1543,
83,
12,
450,
83,
7,
450,
334,
76,
14,
1562,
12,
634,
14,
3690,
430,
367,
634,
315,
9918,
61,
339,
340,
1824,
14,
3502,
63,
265,
63,
7275,
837,
267,
340,
440,
8966,
14,
344,
436,
18684,
14,
1131,
14,
1541,
8,
355,
18684,
14,
2123,
508,
1824,
14,
2123,
14,
576,
680,
835,
837,
288,
14775,
6723,
14499,
3031,
2071,
83,
2,
365,
2575,
315,
675,
3530,
450,
490,
1824,
14,
2123,
14,
576,
395,
283,
68,
12974,
358,
288,
372,
3795,
63,
1160,
360,
7811,
15,
3773,
14,
15575,
297,
8966,
29,
7811,
12,
3521,
1824,
29,
964,
9,
267,
1824,
14,
13817,
63,
1113,
8,
7811,
9,
267,
1592,
14,
1730,
14,
525,
8,
7811,
9,
267,
1592,
14,
1730,
14,
3543,
342,
267,
14775,
6723,
14499,
4954,
6290,
8038,
283,
3742,
358,
267,
372,
4660,
8,
633,
63,
509,
360,
7811,
14,
3773,
297,
8966,
63,
344,
29,
7811,
14,
344,
430,
339,
372,
3795,
63,
1160,
360,
7811,
15,
3773,
14,
15575,
297,
8966,
29,
7811,
12,
1824,
29,
964,
9,
421,
199,
32,
15918,
14,
4449,
2336,
1807,
8316,
442,
26,
7811,
63,
344,
30,
3678,
3102,
2968,
4030,
1105,
199,
32,
4365,
63,
3756,
8,
3863,
2978,
14,
26780,
879,
15068,
63,
10387,
9,
199,
318,
3145,
8,
7811,
63,
344,
304,
272,
408,
5392,
282,
8966,
1041,
272,
8966,
275,
18684,
14,
1131,
14,
362,
63,
269,
63,
5188,
8,
7811,
63,
344,
9,
272,
1592,
14,
1730,
14,
1807,
8,
7811,
9,
272,
1592,
14,
1730,
14,
3543,
342,
272,
14775,
6723,
14499,
4954,
5463,
8038,
283,
3742,
358,
339,
372,
4660,
8,
633,
63,
509,
360,
7811,
14,
513,
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
] |
[
7209,
492,
22447,
1361,
12,
14775,
12,
4660,
12,
3795,
63,
1160,
12,
1166,
63,
509,
199,
504,
7209,
63,
66,
902,
492,
9617,
63,
5152,
465,
485,
199,
504,
7209,
63,
2886,
492,
1453,
63,
751,
199,
199,
504,
1145,
492,
1592,
199,
504,
1145,
14,
11582,
492,
4409,
63,
3756,
199,
504,
1145,
14,
3351,
492,
4205,
63,
964,
199,
504,
1145,
14,
3351,
14,
7811,
492,
18684,
2821,
199,
504,
1145,
14,
992,
14,
7811,
492,
18684,
199,
504,
1145,
14,
992,
14,
1985,
492,
12625,
199,
504,
1145,
14,
8050,
492,
6848,
2978,
199,
504,
1145,
14,
1364,
492,
4719,
63,
1364,
199,
199,
15918,
275,
22447,
1361,
360,
7811,
297,
636,
354,
3108,
1166,
63,
1861,
8805,
18147,
358,
421,
199,
32,
15918,
14,
4449,
10998,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
32,
15918,
14,
4449,
2336,
28,
442,
26,
1606,
63,
7865,
30,
3678,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
32,
4365,
63,
3756,
8,
3863,
2978,
14,
26780,
879,
15068,
63,
5670,
9,
199,
318,
769,
8,
1606,
63,
7865,
29,
17,
304,
272,
408,
6824,
282,
9881,
23831,
769,
402,
27989,
1041,
272,
27989,
275,
18684,
14,
1131,
14,
30979,
8,
1606,
63,
7865,
12,
4114,
12,
756,
9,
272,
883,
63,
952,
275,
4719,
63,
1364,
14,
751,
63,
1989,
63,
3756,
8,
1818,
63,
751,
12,
6848,
2978,
14,
26780,
879,
15068,
63,
10387,
9,
272,
372,
3795,
63,
1160,
360,
7811,
15,
513,
14,
15575,
297,
27989,
29,
18147,
12,
2574,
883,
63,
952,
29,
2425,
63,
952,
9,
421,
199,
32,
15918,
14,
4449,
2336,
981,
3678,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
32,
15918,
14,
4449,
2336,
3773,
8316,
442,
26,
7811,
63,
344,
30,
3678,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
32,
4365,
63,
3756,
8,
3863,
2978,
14,
26780,
879,
15068,
63,
10387,
9,
199,
318,
5283,
8,
7811,
63,
344,
29,
403,
304,
272,
408,
2499,
503,
5283,
282,
8966,
12,
22523,
1041,
272,
340,
8966,
63,
344,
26,
267,
8966,
275,
18684,
14,
1131,
14,
362,
8,
7811,
63,
344,
9,
272,
587,
26,
267,
8966,
275,
18684,
342,
339,
1824,
275,
4205,
63,
964,
8,
14499,
2821,
12,
1559,
29,
7811,
9,
339,
9918,
275,
12625,
14,
1131,
14,
1648,
63,
991,
8,
267,
12625,
14,
1562,
680,
1648,
63,
991,
8,
6592,
14,
3690,
9,
272,
1824,
14,
1985,
63,
344,
14,
4577,
275,
971,
267,
3842,
76,
14,
344,
12,
1543,
83,
12,
450,
83,
7,
450,
334,
76,
14,
1562,
12,
634,
14,
3690,
430,
367,
634,
315,
9918,
61,
339,
340,
1824,
14,
3502,
63,
265,
63,
7275,
837,
267,
340,
440,
8966,
14,
344,
436,
18684,
14,
1131,
14,
1541,
8,
355,
18684,
14,
2123,
508,
1824,
14,
2123,
14,
576,
680,
835,
837,
288,
14775,
6723,
14499,
3031,
2071,
83,
2,
365,
2575,
315,
675,
3530,
450,
490,
1824,
14,
2123,
14,
576,
395,
283,
68,
12974,
358,
288,
372,
3795,
63,
1160,
360,
7811,
15,
3773,
14,
15575,
297,
8966,
29,
7811,
12,
3521,
1824,
29,
964,
9,
267,
1824,
14,
13817,
63,
1113,
8,
7811,
9,
267,
1592,
14,
1730,
14,
525,
8,
7811,
9,
267,
1592,
14,
1730,
14,
3543,
342,
267,
14775,
6723,
14499,
4954,
6290,
8038,
283,
3742,
358,
267,
372,
4660,
8,
633,
63,
509,
360,
7811,
14,
3773,
297,
8966,
63,
344,
29,
7811,
14,
344,
430,
339,
372,
3795,
63,
1160,
360,
7811,
15,
3773,
14,
15575,
297,
8966,
29,
7811,
12,
1824,
29,
964,
9,
421,
199,
32,
15918,
14,
4449,
2336,
1807,
8316,
442,
26,
7811,
63,
344,
30,
3678,
3102,
2968,
4030,
1105,
199,
32,
4365,
63,
3756,
8,
3863,
2978,
14,
26780,
879,
15068,
63,
10387,
9,
199,
318,
3145,
8,
7811,
63,
344,
304,
272,
408,
5392,
282,
8966,
1041,
272,
8966,
275,
18684,
14,
1131,
14,
362,
63,
269,
63,
5188,
8,
7811,
63,
344,
9,
272,
1592,
14,
1730,
14,
1807,
8,
7811,
9,
272,
1592,
14,
1730,
14,
3543,
342,
272,
14775,
6723,
14499,
4954,
5463,
8038,
283,
3742,
358,
339,
372,
4660,
8,
633,
63,
509,
360,
7811,
14,
513,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
chengdh/openerp-ktv
|
openerp/addons/sale/company.py
|
10
|
1399
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from osv import osv, fields
class company(osv.osv):
_inherit = 'res.company'
_columns = {
'security_lead': fields.float('Security Days', required=True,
help="This is the days added to what you promise to customers "\
"for security purpose"),
}
_defaults = {
'security_lead': 0.0,
}
company()
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
9506,
492,
9506,
12,
1504,
199,
199,
533,
7233,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
470,
14,
4627,
7,
272,
485,
3406,
275,
469,
267,
283,
4416,
63,
13799,
356,
1504,
14,
1609,
360,
7676,
577,
5758,
297,
1415,
29,
549,
12,
288,
1720,
628,
2765,
365,
314,
7609,
3483,
370,
4052,
1265,
8023,
572,
370,
286,
28078,
1867,
288,
298,
509,
6391,
12016,
1288,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
4416,
63,
13799,
356,
378,
14,
16,
12,
272,
789,
199,
4627,
342,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
9506,
492,
9506,
12,
1504,
199,
199,
533,
7233,
8,
4795,
14,
4795,
304,
272,
485,
6486,
275,
283,
470,
14,
4627,
7,
272,
485,
3406,
275,
469,
267,
283,
4416,
63,
13799,
356,
1504,
14,
1609,
360,
7676,
577,
5758,
297,
1415,
29,
549,
12,
288,
1720,
628,
2765,
365,
314,
7609,
3483,
370,
4052,
1265,
8023,
572,
370,
286,
28078,
1867,
288,
298,
509,
6391,
12016,
1288,
272,
789,
272,
485,
4322,
275,
469,
267,
283,
4416,
63,
13799,
356,
378,
14,
16,
12,
272,
789,
199,
4627,
342,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nwalters512/the-blue-alliance
|
tests/test_event_team_status_helper.py
|
3
|
55040
|
import json
import unittest2
from appengine_fixture_loader.loader import load_fixture
from google.appengine.ext import testbed
from google.appengine.ext import ndb
from helpers.event_simulator import EventSimulator
from helpers.event_team_status_helper import EventTeamStatusHelper
from models.event import Event
from models.event_details import EventDetails
from models.match import Match
class TestSimulated2016nytrEventTeamStatusHelper(unittest2.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
self.testbed.init_taskqueue_stub(root_path=".")
ndb.get_context().clear_cache() # Prevent data from leaking between tests
def tearDown(self):
self.testbed.deactivate()
def testSimulatedEvent(self):
es = EventSimulator()
event = Event.get_by_id('2016nytr')
es.step()
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 is <b>Rank 15/36</b> with a record of <b>0-0-0</b> in quals.')
for _ in xrange(5):
es.step()
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 is <b>Rank 6/36</b> with a record of <b>1-0-0</b> in quals.')
for _ in xrange(67):
es.step()
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 was <b>Rank 1/36</b> with a record of <b>11-1-0</b> in quals.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 was <b>Rank 4/36</b> with a record of <b>9-3-0</b> in quals.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 was <b>Rank 16/36</b> with a record of <b>6-6-0</b> in quals.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 was <b>Rank 15/36</b> with a record of <b>6-6-0</b> in quals.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 was <b>Rank 21/36</b> with a record of <b>6-6-0</b> in quals.')
es.step() # Alliance selections added
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 was <b>Rank 1/36</b> with a record of <b>11-1-0</b> in quals and will be competing in the playoffs as the <b>Captain</b> of <b>Alliance 1</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 was <b>Rank 4/36</b> with a record of <b>9-3-0</b> in quals and will be competing in the playoffs as the <b>1st Pick</b> of <b>Alliance 4</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 was <b>Rank 16/36</b> with a record of <b>6-6-0</b> in quals and will be competing in the playoffs as the <b>2nd Pick</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 was <b>Rank 15/36</b> with a record of <b>6-6-0</b> in quals.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 was <b>Rank 21/36</b> with a record of <b>6-6-0</b> in quals.')
es.step() # QF schedule added
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 is <b>0-0-0</b> in the <b>Quarterfinals</b> as the <b>Captain</b> of <b>Alliance 1</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 is <b>0-0-0</b> in the <b>Quarterfinals</b> as the <b>1st Pick</b> of <b>Alliance 4</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 is <b>0-0-0</b> in the <b>Quarterfinals</b> as the <b>2nd Pick</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 was <b>Rank 15/36</b> with a record of <b>6-6-0</b> in quals.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 was <b>Rank 21/36</b> with a record of <b>6-6-0</b> in quals.')
es.step() # qf1m1
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 is <b>1-0-0</b> in the <b>Quarterfinals</b> as the <b>Captain</b> of <b>Alliance 1</b>.')
es.step() # qf2m1
es.step() # qf3m1
es.step() # qf4m1
es.step() # qf1m2
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 is <b>0-0-0</b> in the <b>Semifinals</b> as the <b>Captain</b> of <b>Alliance 1</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 is <b>0-1-0</b> in the <b>Quarterfinals</b> as the <b>1st Pick</b> of <b>Alliance 4</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 is <b>1-0-0</b> in the <b>Quarterfinals</b> as the <b>2nd Pick</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 was <b>Rank 15/36</b> with a record of <b>6-6-0</b> in quals.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 was <b>Rank 21/36</b> with a record of <b>6-6-0</b> in quals.')
es.step() # qf2m2
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 is <b>1-1-0</b> in the <b>Quarterfinals</b> as the <b>1st Pick</b> of <b>Alliance 4</b>.')
es.step() # qf3m2
es.step() # qf4m2
es.step() # qf2m3
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 is <b>0-0-0</b> in the <b>Semifinals</b> as the <b>1st Pick</b> of <b>Alliance 4</b>.')
es.step() # qf4m3
es.step() # sf1m1
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 is <b>1-0-0</b> in the <b>Semifinals</b> as the <b>Captain</b> of <b>Alliance 1</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 is <b>0-1-0</b> in the <b>Semifinals</b> as the <b>1st Pick</b> of <b>Alliance 4</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 is <b>0-0-0</b> in the <b>Semifinals</b> as the <b>2nd Pick</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 was <b>Rank 15/36</b> with a record of <b>6-6-0</b> in quals.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 was <b>Rank 21/36</b> with a record of <b>6-6-0</b> in quals.')
es.step() # sf2m1
es.step() # sf1m2
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 is <b>0-0-0</b> in the <b>Finals</b> as the <b>Captain</b> of <b>Alliance 1</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 was <b>Rank 4/36</b> with a record of <b>9-3-0</b> in quals, competed in the playoffs as the <b>1st Pick</b> of <b>Alliance 4</b>, and was <b>eliminated in the Semifinals</b> with a playoff record of <b>2-3-0</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 is <b>0-1-0</b> in the <b>Semifinals</b> as the <b>2nd Pick</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 was <b>Rank 15/36</b> with a record of <b>6-6-0</b> in quals.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 was <b>Rank 21/36</b> with a record of <b>6-6-0</b> in quals.')
es.step() # sf2m2
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 is <b>0-0-0</b> in the <b>Finals</b> as the <b>Captain</b> of <b>Alliance 1</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 was <b>Rank 4/36</b> with a record of <b>9-3-0</b> in quals, competed in the playoffs as the <b>1st Pick</b> of <b>Alliance 4</b>, and was <b>eliminated in the Semifinals</b> with a playoff record of <b>2-3-0</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 is <b>1-1-0</b> in the <b>Semifinals</b> as the <b>2nd Pick</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 is <b>1-1-0</b> in the <b>Semifinals</b> as the <b>Backup</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 was <b>Rank 21/36</b> with a record of <b>6-6-0</b> in quals.')
es.step() # sf2m3
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 is <b>0-0-0</b> in the <b>Finals</b> as the <b>Captain</b> of <b>Alliance 1</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 was <b>Rank 4/36</b> with a record of <b>9-3-0</b> in quals, competed in the playoffs as the <b>1st Pick</b> of <b>Alliance 4</b>, and was <b>eliminated in the Semifinals</b> with a playoff record of <b>2-3-0</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 is <b>0-0-0</b> in the <b>Finals</b> as the <b>2nd Pick</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 is <b>0-0-0</b> in the <b>Finals</b> as the <b>Backup</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 was <b>Rank 21/36</b> with a record of <b>6-6-0</b> in quals.')
es.step() # f1m1
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 is <b>1-0-0</b> in the <b>Finals</b> as the <b>Captain</b> of <b>Alliance 1</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 was <b>Rank 4/36</b> with a record of <b>9-3-0</b> in quals, competed in the playoffs as the <b>1st Pick</b> of <b>Alliance 4</b>, and was <b>eliminated in the Semifinals</b> with a playoff record of <b>2-3-0</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 is <b>0-1-0</b> in the <b>Finals</b> as the <b>2nd Pick</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 is <b>0-1-0</b> in the <b>Finals</b> as the <b>Backup</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 was <b>Rank 21/36</b> with a record of <b>6-6-0</b> in quals.')
es.step() # f1m2
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 is <b>1-1-0</b> in the <b>Finals</b> as the <b>Captain</b> of <b>Alliance 1</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 was <b>Rank 4/36</b> with a record of <b>9-3-0</b> in quals, competed in the playoffs as the <b>1st Pick</b> of <b>Alliance 4</b>, and was <b>eliminated in the Semifinals</b> with a playoff record of <b>2-3-0</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 is <b>1-1-0</b> in the <b>Finals</b> as the <b>2nd Pick</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 is <b>1-1-0</b> in the <b>Finals</b> as the <b>Backup</b> of <b>Alliance 2</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 was <b>Rank 21/36</b> with a record of <b>6-6-0</b> in quals.')
es.step() # f1m3
event = Event.get_by_id('2016nytr')
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 was <b>Rank 1/36</b> with a record of <b>11-1-0</b> in quals, competed in the playoffs as the <b>Captain</b> of <b>Alliance 1</b>, and <b>won the event</b> with a playoff record of <b>6-1-0</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 was <b>Rank 4/36</b> with a record of <b>9-3-0</b> in quals, competed in the playoffs as the <b>1st Pick</b> of <b>Alliance 4</b>, and was <b>eliminated in the Semifinals</b> with a playoff record of <b>2-3-0</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 was <b>Rank 16/36</b> with a record of <b>6-6-0</b> in quals, competed in the playoffs as the <b>2nd Pick</b> of <b>Alliance 2</b>, and was <b>eliminated in the Finals</b> with a playoff record of <b>5-3-0</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 was <b>Rank 15/36</b> with a record of <b>6-6-0</b> in quals, competed in the playoffs as the <b>Backup</b> of <b>Alliance 2</b>, and was <b>eliminated in the Finals</b> with a playoff record of <b>5-3-0</b>.')
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', event)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 was <b>Rank 21/36</b> with a record of <b>6-6-0</b> in quals.')
class Test2016nytrEventTeamStatusHelper(unittest2.TestCase):
status_359 = {
"alliance": {
"backup": None,
"name": "Alliance 1",
"number": 1,
"pick": 0
},
"playoff": {
"current_level_record": {
"losses": 1,
"ties": 0,
"wins": 2
},
"level": "f",
"playoff_average": None,
"record": {
"losses": 1,
"ties": 0,
"wins": 6
},
"status": "won"
},
"qual": {
"num_teams": 36,
"ranking": {
"dq": 0,
"matches_played": 12,
"qual_average": None,
"rank": 1,
"record": {
"losses": 1,
"ties": 0,
"wins": 11
},
"sort_orders": [
39.0,
310.0,
165.0,
448.0,
600.0
],
"team_key": "frc359"
},
"sort_order_info": [
{
"name": "Ranking Score",
"precision": 0
},
{
"name": "Auto",
"precision": 0
},
{
"name": "Scale/Challenge",
"precision": 0
},
{
"name": "Goals",
"precision": 0
},
{
"name": "Defense",
"precision": 0
}
],
"status": "completed"
}
}
status_5240 = {
"alliance": {
"backup": None,
"name": "Alliance 4",
"number": 4,
"pick": 1
},
"playoff": {
"current_level_record": {
"losses": 2,
"ties": 0,
"wins": 0
},
"level": "sf",
"playoff_average": None,
"record": {
"losses": 3,
"ties": 0,
"wins": 2
},
"status": "eliminated"
},
"qual": {
"num_teams": 36,
"ranking": {
"dq": 0,
"matches_played": 12,
"qual_average": None,
"rank": 6,
"record": {
"losses": 3,
"ties": 0,
"wins": 9
},
"sort_orders": [
28.0,
260.0,
150.0,
191.0,
575.0
],
"team_key": "frc5240"
},
"sort_order_info": [
{
"name": "Ranking Score",
"precision": 0
},
{
"name": "Auto",
"precision": 0
},
{
"name": "Scale/Challenge",
"precision": 0
},
{
"name": "Goals",
"precision": 0
},
{
"name": "Defense",
"precision": 0
}
],
"status": "completed"
}
}
status_229 = {
"alliance": {
"backup": {
"in": "frc1665",
"out": "frc229"
},
"name": "Alliance 2",
"number": 2,
"pick": 2
},
"playoff": {
"current_level_record": {
"losses": 2,
"ties": 0,
"wins": 1
},
"level": "f",
"playoff_average": None,
"record": {
"losses": 3,
"ties": 0,
"wins": 5
},
"status": "eliminated"
},
"qual": {
"num_teams": 36,
"ranking": {
"dq": 0,
"matches_played": 12,
"qual_average": None,
"rank": 20,
"record": {
"losses": 6,
"ties": 0,
"wins": 6
},
"sort_orders": [
20.0,
156.0,
130.0,
119.0,
525.0
],
"team_key": "frc229"
},
"sort_order_info": [
{
"name": "Ranking Score",
"precision": 0
},
{
"name": "Auto",
"precision": 0
},
{
"name": "Scale/Challenge",
"precision": 0
},
{
"name": "Goals",
"precision": 0
},
{
"name": "Defense",
"precision": 0
}
],
"status": "completed"
}
}
status_1665 = {
"alliance": {
"backup": {
"in": "frc1665",
"out": "frc229"
},
"name": "Alliance 2",
"number": 2,
"pick": -1
},
"playoff": {
"current_level_record": {
"losses": 2,
"ties": 0,
"wins": 1
},
"level": "f",
"playoff_average": None,
"record": {
"losses": 3,
"ties": 0,
"wins": 5
},
"status": "eliminated"
},
"qual": {
"num_teams": 36,
"ranking": {
"dq": 0,
"matches_played": 12,
"qual_average": None,
"rank": 18,
"record": {
"losses": 6,
"ties": 0,
"wins": 6
},
"sort_orders": [
20.0,
192.0,
105.0,
146.0,
525.0
],
"team_key": "frc1665"
},
"sort_order_info": [
{
"name": "Ranking Score",
"precision": 0
},
{
"name": "Auto",
"precision": 0
},
{
"name": "Scale/Challenge",
"precision": 0
},
{
"name": "Goals",
"precision": 0
},
{
"name": "Defense",
"precision": 0
}
],
"status": "completed"
}
}
status_5964 = {
"alliance": None,
"playoff": None,
"qual": {
"num_teams": 36,
"ranking": {
"dq": 0,
"matches_played": 12,
"qual_average": None,
"rank": 23,
"record": {
"losses": 6,
"ties": 0,
"wins": 6
},
"sort_orders": [
19.0,
218.0,
110.0,
159.0,
520.0
],
"team_key": "frc5964"
},
"sort_order_info": [
{
"name": "Ranking Score",
"precision": 0
},
{
"name": "Auto",
"precision": 0
},
{
"name": "Scale/Challenge",
"precision": 0
},
{
"name": "Goals",
"precision": 0
},
{
"name": "Defense",
"precision": 0
}
],
"status": "completed"
}
}
status_1124 = {
"qual": None,
"playoff": None,
"alliance": None
}
# Because I can't figure out how to get these to generate
def event_key_adder(self, obj):
obj.event = ndb.Key(Event, '2016nytr')
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
load_fixture('test_data/fixtures/2016nytr_event_team_status.json',
kind={'EventDetails': EventDetails, 'Event': Event, 'Match': Match},
post_processor=self.event_key_adder)
self.event = Event.get_by_id('2016nytr')
self.assertIsNotNone(self.event)
def tearDown(self):
self.testbed.deactivate()
def testEventWinner(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', self.event)
self.assertDictEqual(status, self.status_359)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 was <b>Rank 1/36</b> with a record of <b>11-1-0</b> in quals, competed in the playoffs as the <b>Captain</b> of <b>Alliance 1</b>, and <b>won the event</b> with a playoff record of <b>6-1-0</b>.')
def testElimSemisAndFirstPick(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', self.event)
self.assertDictEqual(status, self.status_5240)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 was <b>Rank 6/36</b> with a record of <b>9-3-0</b> in quals, competed in the playoffs as the <b>1st Pick</b> of <b>Alliance 4</b>, and was <b>eliminated in the Semifinals</b> with a playoff record of <b>2-3-0</b>.')
def testBackupOut(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', self.event)
self.assertDictEqual(status, self.status_229)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 was <b>Rank 20/36</b> with a record of <b>6-6-0</b> in quals, competed in the playoffs as the <b>2nd Pick</b> of <b>Alliance 2</b>, and was <b>eliminated in the Finals</b> with a playoff record of <b>5-3-0</b>.')
def testBackupIn(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', self.event)
self.assertDictEqual(status, self.status_1665)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 was <b>Rank 18/36</b> with a record of <b>6-6-0</b> in quals, competed in the playoffs as the <b>Backup</b> of <b>Alliance 2</b>, and was <b>eliminated in the Finals</b> with a playoff record of <b>5-3-0</b>.')
def testTeamNotPicked(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', self.event)
self.assertDictEqual(status, self.status_5964)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 was <b>Rank 23/36</b> with a record of <b>6-6-0</b> in quals.')
class Test2016nytrEventTeamStatusHelperNoEventDetails(unittest2.TestCase):
status_359 = {
"alliance": None,
"playoff": {
"current_level_record": {
"losses": 1,
"ties": 0,
"wins": 2
},
"level": "f",
"playoff_average": None,
"record": {
"losses": 1,
"ties": 0,
"wins": 6
},
"status": "won"
},
"qual": {
"num_teams": 36,
"ranking": {
"dq": None,
"matches_played": 12,
"qual_average": None,
"rank": None,
"record": {
"losses": 1,
"ties": 0,
"wins": 11
},
"sort_orders": None,
"team_key": "frc359",
},
"sort_order_info": None,
"status": "completed"
}
}
status_5240 = {
"alliance": None,
"playoff": {
"current_level_record": {
"losses": 2,
"ties": 0,
"wins": 0
},
"level": "sf",
"playoff_average": None,
"record": {
"losses": 3,
"ties": 0,
"wins": 2
},
"status": "eliminated"
},
"qual": {
"num_teams": 36,
"ranking": {
"dq": None,
"matches_played": 12,
"qual_average": None,
"rank": None,
"record": {
"losses": 3,
"ties": 0,
"wins": 9
},
"sort_orders": None,
"team_key": "frc5240",
},
"sort_order_info": None,
"status": "completed"
}
}
status_229 = {
"alliance": None,
"playoff": {
"current_level_record": {
"losses": 2,
"ties": 0,
"wins": 1
},
"level": "f",
"playoff_average": None,
"record": {
"losses": 3,
"ties": 0,
"wins": 5
},
"status": "eliminated"
},
"qual": {
"num_teams": 36,
"ranking": {
"dq": None,
"matches_played": 12,
"qual_average": None,
"rank": None,
"record": {
"losses": 6,
"ties": 0,
"wins": 6
},
"sort_orders": None,
"team_key": "frc229",
},
"sort_order_info": None,
"status": "completed"
}
}
status_1665 = {
"alliance": None,
"playoff": {
"current_level_record": {
"losses": 2,
"ties": 0,
"wins": 1
},
"level": "f",
"playoff_average": None,
"record": {
"losses": 3,
"ties": 0,
"wins": 5
},
"status": "eliminated"
},
"qual": {
"num_teams": 36,
"ranking": {
"dq": None,
"matches_played": 12,
"qual_average": None,
"rank": None,
"record": {
"losses": 6,
"ties": 0,
"wins": 6
},
"sort_orders": None,
"team_key": "frc1665",
},
"sort_order_info": None,
"status": "completed"
}
}
status_5964 = {
"alliance": None,
"playoff": None,
"qual": {
"num_teams": 36,
"ranking": {
"dq": None,
"matches_played": 12,
"qual_average": None,
"rank": None,
"record": {
"losses": 6,
"ties": 0,
"wins": 6
},
"sort_orders": None,
"team_key": "frc5964",
},
"sort_order_info": None,
"status": "completed"
}
}
status_1124 = {
"qual": None,
"playoff": None,
"alliance": None
}
# Because I can't figure out how to get these to generate
def event_key_adder(self, obj):
obj.event = ndb.Key(Event, '2016nytr')
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
load_fixture('test_data/fixtures/2016nytr_event_team_status.json',
kind={'EventDetails': EventDetails, 'Event': Event, 'Match': Match},
post_processor=self.event_key_adder)
self.event = Event.get_by_id('2016nytr')
EventDetails.get_by_id('2016nytr').key.delete() # Remove EventDetails
self.assertIsNotNone(self.event)
def tearDown(self):
self.testbed.deactivate()
def testEventWinner(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc359', self.event)
self.assertDictEqual(status, self.status_359)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc359', status),
'Team 359 had a record of <b>11-1-0</b> in quals and <b>won the event</b> with a playoff record of <b>6-1-0</b>.')
def testElimSemisAndFirstPick(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc5240', self.event)
self.assertDictEqual(status, self.status_5240)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5240', status),
'Team 5240 had a record of <b>9-3-0</b> in quals and was <b>eliminated in the Semifinals</b> with a playoff record of <b>2-3-0</b>.')
def testBackupOut(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc229', self.event)
self.assertDictEqual(status, self.status_229)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc229', status),
'Team 229 had a record of <b>6-6-0</b> in quals and was <b>eliminated in the Finals</b> with a playoff record of <b>5-3-0</b>.')
def testBackupIn(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc1665', self.event)
self.assertDictEqual(status, self.status_1665)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc1665', status),
'Team 1665 had a record of <b>6-6-0</b> in quals and was <b>eliminated in the Finals</b> with a playoff record of <b>5-3-0</b>.')
def testTeamNotPicked(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc5964', self.event)
self.assertDictEqual(status, self.status_5964)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc5964', status),
'Team 5964 had a record of <b>6-6-0</b> in quals.')
class Test2016casjEventTeamStatusHelperNoEventDetails(unittest2.TestCase):
status_254 = {
"alliance": None,
"playoff": {
"current_level_record": {
"losses": 0,
"ties": 0,
"wins": 2
},
"level": "f",
"playoff_average": None,
"record": {
"losses": 0,
"ties": 0,
"wins": 6
},
"status": "won"
},
"qual": {
"num_teams": 64,
"ranking": {
"dq": None,
"matches_played": 8,
"qual_average": None,
"rank": None,
"record": {
"losses": 0,
"ties": 0,
"wins": 8
},
"sort_orders": None,
"team_key": "frc254",
},
"sort_order_info": None,
"status": "completed"
}
}
# Because I can't figure out how to get these to generate
def event_key_adder(self, obj):
obj.event = ndb.Key(Event, '2016casj')
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
load_fixture('test_data/fixtures/2016casj.json',
kind={'EventDetails': EventDetails, 'Event': Event, 'Match': Match},
post_processor=self.event_key_adder)
self.event = Event.get_by_id('2016casj')
self.assertIsNotNone(self.event)
def tearDown(self):
self.testbed.deactivate()
def testEventSurrogate(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc254', self.event)
self.assertDictEqual(status, self.status_254)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc254', status),
'Team 254 had a record of <b>8-0-0</b> in quals and <b>won the event</b> with a playoff record of <b>6-0-0</b>.')
class Test2015casjEventTeamStatusHelper(unittest2.TestCase):
status_254 = {
"alliance": {
"backup": None,
"name": "Alliance 1",
"number": 1,
"pick": 0
},
"playoff": {
"current_level_record": {
"losses": 0,
"ties": 0,
"wins": 2
},
"level": "f",
"playoff_average": 224.14285714285714,
"record": None,
"status": "won"
},
"qual": {
"num_teams": 57,
"ranking": {
"dq": 0,
"matches_played": 10,
"qual_average": 200.4,
"rank": 1,
"record": None,
"sort_orders": [
200.4,
280.0,
200.0,
836.0,
522.0,
166.0
],
"team_key": "frc254"
},
"sort_order_info": [
{
"name": "Qual Avg.",
"precision": 1
},
{
"name": "Coopertition",
"precision": 0
},
{
"name": "Auto",
"precision": 0
},
{
"name": "Container",
"precision": 0
},
{
"name": "Tote",
"precision": 0
},
{
"name": "Litter",
"precision": 0
}
],
"status": "completed"
}
}
status_846 = {
"alliance": {
"backup": None,
"name": "Alliance 3",
"number": 3,
"pick": 1
},
"playoff": {
"current_level_record": None,
"level": "sf",
"playoff_average": 133.59999999999999,
"record": None,
"status": "eliminated"
},
"qual": {
"num_teams": 57,
"ranking": {
"dq": 0,
"matches_played": 10,
"qual_average": 97.0,
"rank": 8,
"record": None,
"sort_orders": [
97.0,
200.0,
20.0,
372.0,
294.0,
108.0
],
"team_key": "frc846"
},
"sort_order_info": [
{
"name": "Qual Avg.",
"precision": 1
},
{
"name": "Coopertition",
"precision": 0
},
{
"name": "Auto",
"precision": 0
},
{
"name": "Container",
"precision": 0
},
{
"name": "Tote",
"precision": 0
},
{
"name": "Litter",
"precision": 0
}
],
"status": "completed"
}
}
status_8 = {
"alliance": None,
"playoff": None,
"qual": {
"num_teams": 57,
"ranking": {
"dq": 0,
"matches_played": 10,
"qual_average": 42.6,
"rank": 53,
"record": None,
"sort_orders": [
42.6,
120.0,
0.0,
84.0,
150.0,
72.0
],
"team_key": "frc8"
},
"sort_order_info": [
{
"name": "Qual Avg.",
"precision": 1
},
{
"name": "Coopertition",
"precision": 0
},
{
"name": "Auto",
"precision": 0
},
{
"name": "Container",
"precision": 0
},
{
"name": "Tote",
"precision": 0
},
{
"name": "Litter",
"precision": 0
}
],
"status": "completed"
}
}
status_1124 = {
"qual": None,
"playoff": None,
"alliance": None
}
# Because I can't figure out how to get these to generate
def event_key_adder(self, obj):
obj.event = ndb.Key(Event, '2015casj')
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
load_fixture('test_data/fixtures/2015casj.json',
kind={'EventDetails': EventDetails, 'Event': Event, 'Match': Match},
post_processor=self.event_key_adder)
self.event = Event.get_by_id('2015casj')
self.assertIsNotNone(self.event)
def tearDown(self):
self.testbed.deactivate()
def testEventWinner(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc254', self.event)
self.assertDictEqual(status, self.status_254)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc254', status),
'Team 254 was <b>Rank 1/57</b> with an average score of <b>200.4</b> in quals, competed in the playoffs as the <b>Captain</b> of <b>Alliance 1</b>, and <b>won the event</b> with a playoff average of <b>224.1</b>.')
def testElimSemisAndFirstPick(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc846', self.event)
self.assertDictEqual(status, self.status_846)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc846', status),
'Team 846 was <b>Rank 8/57</b> with an average score of <b>97.0</b> in quals, competed in the playoffs as the <b>1st Pick</b> of <b>Alliance 3</b>, and was <b>eliminated in the Semifinals</b> with a playoff average of <b>133.6</b>.')
def testTeamNotPicked(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc8', self.event)
self.assertDictEqual(status, self.status_8)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc8', status),
'Team 8 was <b>Rank 53/57</b> with an average score of <b>42.6</b> in quals.')
class Test2015casjEventTeamStatusHelperNoEventDetails(unittest2.TestCase):
status_254 = {
"alliance": None,
"playoff": {
"current_level_record": {
"losses": 0,
"ties": 0,
"wins": 2
},
"level": "f",
"playoff_average": 224.14285714285714,
"record": None,
"status": "won"
},
"qual": {
"num_teams": 57,
"ranking": {
"dq": None,
"matches_played": 10,
"qual_average": 200.4,
"rank": None,
"record": None,
"sort_orders": None,
"team_key": "frc254",
},
"sort_order_info": None,
"status": "completed"
}
}
status_846 = {
"alliance": None,
"playoff": {
"current_level_record": None,
"level": "sf",
"playoff_average": 133.59999999999999,
"record": None,
"status": "eliminated"
},
"qual": {
"num_teams": 57,
"ranking": {
"dq": None,
"matches_played": 10,
"qual_average": 97.0,
"rank": None,
"record": None,
"sort_orders": None,
"team_key": "frc846",
},
"sort_order_info": None,
"status": "completed"
}
}
status_8 = {
"alliance": None,
"playoff": None,
"qual": {
"num_teams": 57,
"ranking": {
"dq": None,
"matches_played": 10,
"qual_average": 42.6,
"rank": None,
"record": None,
"sort_orders": None,
"team_key": "frc8",
},
"sort_order_info": None,
"status": "completed"
}
}
status_1124 = {
"qual": None,
"playoff": None,
"alliance": None
}
# Because I can't figure out how to get these to generate
def event_key_adder(self, obj):
obj.event = ndb.Key(Event, '2015casj')
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_memcache_stub()
ndb.get_context().clear_cache() # Prevent data from leaking between tests
load_fixture('test_data/fixtures/2015casj.json',
kind={'EventDetails': EventDetails, 'Event': Event, 'Match': Match},
post_processor=self.event_key_adder)
self.event = Event.get_by_id('2015casj')
EventDetails.get_by_id('2015casj').key.delete() # Remove EventDetails
self.assertIsNotNone(self.event)
def tearDown(self):
self.testbed.deactivate()
def testEventWinner(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc254', self.event)
self.assertDictEqual(status, self.status_254)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc254', status),
'Team 254 had an average score of <b>200.4</b> in quals and <b>won the event</b> with a playoff average of <b>224.1</b>.')
def testElimSemisAndFirstPick(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc846', self.event)
self.assertDictEqual(status, self.status_846)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc846', status),
'Team 846 had an average score of <b>97.0</b> in quals and was <b>eliminated in the Semifinals</b> with a playoff average of <b>133.6</b>.')
def testTeamNotPicked(self):
status = EventTeamStatusHelper.generate_team_at_event_status('frc8', self.event)
self.assertDictEqual(status, self.status_8)
self.assertEqual(
EventTeamStatusHelper.generate_team_at_event_status_string('frc8', status),
'Team 8 had an average score of <b>42.6</b> in quals.')
|
mit
|
[
646,
2022,
199,
199,
646,
2882,
18,
199,
504,
1145,
3908,
63,
5997,
63,
3422,
14,
3422,
492,
2248,
63,
5997,
199,
504,
6233,
14,
15358,
14,
832,
492,
511,
6123,
199,
504,
6233,
14,
15358,
14,
832,
492,
23788,
199,
199,
504,
10897,
14,
1430,
63,
20125,
492,
6763,
11397,
199,
504,
10897,
14,
1430,
63,
5969,
63,
1205,
63,
3676,
492,
6763,
13126,
3694,
4433,
199,
504,
1709,
14,
1430,
492,
6763,
199,
504,
1709,
14,
1430,
63,
5087,
492,
6763,
11347,
199,
504,
1709,
14,
1431,
492,
9814,
421,
199,
533,
1379,
7467,
8097,
9261,
9745,
454,
2390,
13126,
3694,
4433,
8,
2796,
18,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
396,
6123,
275,
511,
6123,
14,
774,
6123,
342,
267,
291,
14,
396,
6123,
14,
8222,
342,
267,
291,
14,
396,
6123,
14,
826,
63,
11450,
63,
86,
19,
63,
5811,
342,
267,
291,
14,
396,
6123,
14,
826,
63,
25835,
63,
5811,
342,
267,
291,
14,
396,
6123,
14,
826,
63,
1765,
1825,
63,
5811,
8,
1231,
63,
515,
628,
2685,
267,
23788,
14,
362,
63,
1100,
1252,
3584,
63,
1637,
342,
221,
327,
29861,
666,
687,
1026,
11124,
3382,
2295,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
396,
6123,
14,
24891,
342,
339,
347,
511,
7467,
8097,
2390,
8,
277,
304,
267,
9455,
275,
6763,
11397,
342,
267,
1566,
275,
6763,
14,
362,
63,
991,
63,
344,
360,
9261,
9745,
454,
358,
398,
9455,
14,
2926,
342,
267,
1566,
275,
6763,
14,
362,
63,
991,
63,
344,
360,
9261,
9745,
454,
358,
267,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
11444,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
11444,
297,
2004,
395,
288,
283,
13126,
650,
1427,
365,
665,
66,
30,
19486,
4114,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
16,
13,
16,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
367,
485,
315,
4945,
8,
21,
304,
288,
9455,
14,
2926,
342,
267,
1566,
275,
6763,
14,
362,
63,
991,
63,
344,
360,
9261,
9745,
454,
358,
267,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
11444,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
11444,
297,
2004,
395,
288,
283,
13126,
650,
1427,
365,
665,
66,
30,
19486,
1227,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
17,
13,
16,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
367,
485,
315,
4945,
8,
1822,
304,
288,
9455,
14,
2926,
342,
267,
1566,
275,
6763,
14,
362,
63,
991,
63,
344,
360,
9261,
9745,
454,
358,
267,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
11444,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
11444,
297,
2004,
395,
288,
283,
13126,
650,
1427,
1990,
665,
66,
30,
19486,
413,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
845,
13,
17,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
21,
9873,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
21,
9873,
297,
2004,
395,
288,
283,
13126,
959,
9873,
1990,
665,
66,
30,
19486,
841,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
25,
13,
19,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
11182,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
11182,
297,
2004,
395,
288,
283,
13126,
499,
1398,
1990,
665,
66,
30,
19486,
3193,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
22,
13,
22,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
975,
2182,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
975,
2182,
297,
2004,
395,
288,
283,
13126,
413,
16373,
1990,
665,
66,
30,
19486,
4114,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
22,
13,
22,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
1427,
772,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
1427,
772,
297,
2004,
395,
288,
283,
13126,
8155,
772,
1990,
665,
66,
30,
19486,
7829,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
22,
13,
22,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
9455,
14,
2926,
342,
221,
327,
4580,
3636,
7267,
83,
3483,
267,
1566,
275,
6763,
14,
362,
63,
991,
63,
344,
360,
9261,
9745,
454,
358,
267,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
11444,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
11444,
297,
2004,
395,
288,
283,
13126,
650,
1427,
1990,
665,
66,
30,
19486,
413,
15,
1344,
1108,
66,
30,
543
] |
[
2022,
199,
199,
646,
2882,
18,
199,
504,
1145,
3908,
63,
5997,
63,
3422,
14,
3422,
492,
2248,
63,
5997,
199,
504,
6233,
14,
15358,
14,
832,
492,
511,
6123,
199,
504,
6233,
14,
15358,
14,
832,
492,
23788,
199,
199,
504,
10897,
14,
1430,
63,
20125,
492,
6763,
11397,
199,
504,
10897,
14,
1430,
63,
5969,
63,
1205,
63,
3676,
492,
6763,
13126,
3694,
4433,
199,
504,
1709,
14,
1430,
492,
6763,
199,
504,
1709,
14,
1430,
63,
5087,
492,
6763,
11347,
199,
504,
1709,
14,
1431,
492,
9814,
421,
199,
533,
1379,
7467,
8097,
9261,
9745,
454,
2390,
13126,
3694,
4433,
8,
2796,
18,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
396,
6123,
275,
511,
6123,
14,
774,
6123,
342,
267,
291,
14,
396,
6123,
14,
8222,
342,
267,
291,
14,
396,
6123,
14,
826,
63,
11450,
63,
86,
19,
63,
5811,
342,
267,
291,
14,
396,
6123,
14,
826,
63,
25835,
63,
5811,
342,
267,
291,
14,
396,
6123,
14,
826,
63,
1765,
1825,
63,
5811,
8,
1231,
63,
515,
628,
2685,
267,
23788,
14,
362,
63,
1100,
1252,
3584,
63,
1637,
342,
221,
327,
29861,
666,
687,
1026,
11124,
3382,
2295,
339,
347,
6766,
8,
277,
304,
267,
291,
14,
396,
6123,
14,
24891,
342,
339,
347,
511,
7467,
8097,
2390,
8,
277,
304,
267,
9455,
275,
6763,
11397,
342,
267,
1566,
275,
6763,
14,
362,
63,
991,
63,
344,
360,
9261,
9745,
454,
358,
398,
9455,
14,
2926,
342,
267,
1566,
275,
6763,
14,
362,
63,
991,
63,
344,
360,
9261,
9745,
454,
358,
267,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
11444,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
11444,
297,
2004,
395,
288,
283,
13126,
650,
1427,
365,
665,
66,
30,
19486,
4114,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
16,
13,
16,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
367,
485,
315,
4945,
8,
21,
304,
288,
9455,
14,
2926,
342,
267,
1566,
275,
6763,
14,
362,
63,
991,
63,
344,
360,
9261,
9745,
454,
358,
267,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
11444,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
11444,
297,
2004,
395,
288,
283,
13126,
650,
1427,
365,
665,
66,
30,
19486,
1227,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
17,
13,
16,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
367,
485,
315,
4945,
8,
1822,
304,
288,
9455,
14,
2926,
342,
267,
1566,
275,
6763,
14,
362,
63,
991,
63,
344,
360,
9261,
9745,
454,
358,
267,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
11444,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
11444,
297,
2004,
395,
288,
283,
13126,
650,
1427,
1990,
665,
66,
30,
19486,
413,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
845,
13,
17,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
21,
9873,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
21,
9873,
297,
2004,
395,
288,
283,
13126,
959,
9873,
1990,
665,
66,
30,
19486,
841,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
25,
13,
19,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
11182,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
11182,
297,
2004,
395,
288,
283,
13126,
499,
1398,
1990,
665,
66,
30,
19486,
3193,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
22,
13,
22,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
975,
2182,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
975,
2182,
297,
2004,
395,
288,
283,
13126,
413,
16373,
1990,
665,
66,
30,
19486,
4114,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
22,
13,
22,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
1427,
772,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
1427,
772,
297,
2004,
395,
288,
283,
13126,
8155,
772,
1990,
665,
66,
30,
19486,
7829,
15,
1344,
1108,
66,
30,
543,
282,
2777,
402,
665,
66,
30,
22,
13,
22,
13,
16,
1108,
66,
30,
315,
6420,
83,
2659,
398,
9455,
14,
2926,
342,
221,
327,
4580,
3636,
7267,
83,
3483,
267,
1566,
275,
6763,
14,
362,
63,
991,
63,
344,
360,
9261,
9745,
454,
358,
267,
2004,
275,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
360,
32309,
11444,
297,
1566,
9,
267,
291,
14,
629,
8,
288,
6763,
13126,
3694,
4433,
14,
4208,
63,
5969,
63,
292,
63,
1430,
63,
1205,
63,
875,
360,
32309,
11444,
297,
2004,
395,
288,
283,
13126,
650,
1427,
1990,
665,
66,
30,
19486,
413,
15,
1344,
1108,
66,
30,
543,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
n37r06u3/webpymail
|
imaplib2/__init__.py
|
7
|
1490
|
# -*- coding: utf-8 -*-
# imaplib2 python module, meant to be a replacement to the python default
# imaplib module
# Copyright (C) 2008 Helder Guerreiro
## This file is part of imaplib2.
##
## imaplib2 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.
##
## imaplib2 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 hlimap. If not, see <http://www.gnu.org/licenses/>.
#
# Helder Guerreiro <helder@paxjulia.com>
#
# $Id$
#
'''Replacement for the standard python module imaplib.
However this is not a drop in replacement and there's no easy path to migrate
programs based on 'imaplib' to this library.
The package contents are:
* imapll - low level imap library, it makes no attempt to parse the server
responses;
* imapp - parsed imap library;
* parsefetch - parses the fetch command responses;
* parselist - parses the list and lsub commands responses;
* sexp - scans nested parentheses lists on a string and transforms it in python
lists;
* infolog - example infolog class;
* utils - severall utility functions and classes;
'''
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
23646,
773,
18,
2366,
859,
12,
18329,
370,
506,
282,
8343,
370,
314,
2366,
849,
199,
3,
23646,
773,
859,
199,
3,
1898,
334,
35,
9,
9079,
869,
352,
424,
12436,
281,
264,
14352,
199,
199,
309,
961,
570,
365,
1777,
402,
23646,
773,
18,
14,
199,
309,
199,
309,
23646,
773,
18,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
309,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
309,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
309,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
23646,
773,
18,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
309,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
394,
317,
1130,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
199,
3,
869,
352,
424,
12436,
281,
264,
14352,
665,
30586,
424,
32,
25355,
74,
13987,
65,
14,
957,
30,
199,
3,
199,
3,
2672,
1304,
4,
199,
3,
199,
199,
2344,
29475,
367,
314,
4465,
2366,
859,
23646,
773,
14,
199,
199,
18335,
5907,
642,
365,
440,
282,
5978,
315,
8343,
436,
2337,
1159,
949,
8837,
931,
370,
12810,
199,
28464,
4079,
641,
283,
15311,
773,
7,
370,
642,
3555,
14,
199,
199,
1918,
2559,
4072,
787,
26,
199,
199,
10,
23646,
914,
446,
6465,
2166,
23646,
3555,
12,
652,
7704,
949,
7427,
370,
2198,
314,
1654,
199,
10360,
27,
199,
10,
284,
14223,
446,
4565,
23646,
3555,
27,
199,
10,
2198,
3535,
446,
19953,
314,
5267,
1414,
9320,
27,
199,
10,
2198,
513,
446,
19953,
314,
769,
436,
9100,
456,
3718,
9320,
27,
199,
10,
542,
9290,
446,
4061,
796,
6032,
23592,
5548,
641,
282,
1059,
436,
18501,
652,
315,
2366,
199,
6717,
27,
199,
10,
2256,
793,
446,
2893,
2256,
793,
1021,
27,
199,
10,
3778,
446,
8828,
452,
11420,
3423,
436,
3992,
27,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
3,
23646,
773,
18,
2366,
859,
12,
18329,
370,
506,
282,
8343,
370,
314,
2366,
849,
199,
3,
23646,
773,
859,
199,
3,
1898,
334,
35,
9,
9079,
869,
352,
424,
12436,
281,
264,
14352,
199,
199,
309,
961,
570,
365,
1777,
402,
23646,
773,
18,
14,
199,
309,
199,
309,
23646,
773,
18,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
309,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
309,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
309,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
23646,
773,
18,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
309,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
394,
317,
1130,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
199,
3,
869,
352,
424,
12436,
281,
264,
14352,
665,
30586,
424,
32,
25355,
74,
13987,
65,
14,
957,
30,
199,
3,
199,
3,
2672,
1304,
4,
199,
3,
199,
199,
2344,
29475,
367,
314,
4465,
2366,
859,
23646,
773,
14,
199,
199,
18335,
5907,
642,
365,
440,
282,
5978,
315,
8343,
436,
2337,
1159,
949,
8837,
931,
370,
12810,
199,
28464,
4079,
641,
283,
15311,
773,
7,
370,
642,
3555,
14,
199,
199,
1918,
2559,
4072,
787,
26,
199,
199,
10,
23646,
914,
446,
6465,
2166,
23646,
3555,
12,
652,
7704,
949,
7427,
370,
2198,
314,
1654,
199,
10360,
27,
199,
10,
284,
14223,
446,
4565,
23646,
3555,
27,
199,
10,
2198,
3535,
446,
19953,
314,
5267,
1414,
9320,
27,
199,
10,
2198,
513,
446,
19953,
314,
769,
436,
9100,
456,
3718,
9320,
27,
199,
10,
542,
9290,
446,
4061,
796,
6032,
23592,
5548,
641,
282,
1059,
436,
18501,
652,
315,
2366,
199,
6717,
27,
199,
10,
2256,
793,
446,
2893,
2256,
793,
1021,
27,
199,
10,
3778,
446,
8828,
452,
11420,
3423,
436,
3992,
27,
199,
2344,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
GabrielCebrianM/hm-tools
|
bd.py
|
1
|
3191
|
#!/usr/bin/python
#
# Copyright 2017 Gabriel Cebrian
#
# 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 argparse
import hmtools.bd
import sys
def parse_arguments(argv):
"""Parses the command line arguments and checks that they meet the
requirements to perform the operations of the program. Returns two arrays of
points (tuples) in the form (bitrate, psnr), and a boolean stating whether
to use piecewiese or cubic interpolation.
Keyword arguments:
argv -- Command line arguments.
"""
argument_parser = argparse.ArgumentParser(description='Calculates the '
'BD-rate between two rate-distortion curves.')
argument_parser.add_argument('-o', '--old', action='store_true',
default=False, required=False, help='use the old cubic polynomial '
'interpolation function to calculate the BD-rate, instead of the '
'piecewise cubic interpolation function.', dest='use_old_bdrate')
argument_parser.add_argument('-b', '--base', nargs='+', type=float,
required=True, help='set of rate-distortion values of the baseline '
'encoder.', metavar='bitrate psnr', dest='base')
argument_parser.add_argument('-t', '--test', nargs='+', type=float,
required=True, help='set of rate-distortion values of the encoder '
'being tested.', metavar='bitrate psnr', dest='test')
arguments = argument_parser.parse_args(argv)
if (len(arguments.base) % 2) != 0:
argument_parser.error('incorrect baseline parameters. Please check you '
'have introduced the (bitrate psnr) tuples correctly.')
if (len(arguments.test) % 2) != 0:
argument_parser.error('incorrect test parameters. Please check you '
'have introduced the (bitrate psnr) tuples correctly.')
if len(arguments.base) < 8:
argument_parser.error('you must provide at least 4 points for the '
'baseline encoder.')
if len(arguments.test) < 8:
argument_parser.error('you must provide at least 4 points for the '
'encoder being tested.')
base = zip(arguments.base[0::2], arguments.base[1::2])
test = zip(arguments.test[0::2], arguments.test[1::2])
use_old_bdrate = arguments.use_old_bdrate
return base, test, use_old_bdrate
def main(argv):
base, test, use_old_bdrate = parse_arguments(argv[1:])
base = sorted(set(base))
test = sorted(set(test))
if use_old_bdrate:
bdrate = hmtools.bd.bdrate_old(base, test)
else:
bdrate = hmtools.bd.bdrate(base, test)
print('{:0.4f}'.format(bdrate))
if __name__ == "__main__":
main(sys.argv)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
257,
1898,
9708,
598,
371,
322,
352,
445,
2871,
18429,
199,
3,
199,
3,
257,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
257,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
257,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
755,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
257,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
257,
4204,
1334,
314,
844,
14,
199,
199,
646,
7534,
199,
646,
394,
77,
2537,
14,
3691,
199,
646,
984,
199,
199,
318,
2198,
63,
4958,
8,
3020,
304,
272,
408,
23400,
314,
1414,
1004,
2368,
436,
5920,
626,
2985,
26743,
314,
272,
9760,
370,
5147,
314,
5331,
402,
314,
2240,
14,
1803,
2877,
6572,
402,
272,
4501,
334,
11760,
9,
315,
314,
1824,
334,
24484,
12,
299,
5167,
82,
395,
436,
282,
5046,
410,
1958,
3775,
272,
370,
675,
14854,
87,
1873,
261,
503,
22217,
530,
14046,
14,
339,
6431,
2368,
26,
272,
9238,
1553,
5817,
1004,
2368,
14,
272,
408,
272,
1423,
63,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
13862,
2335,
314,
283,
288,
283,
11156,
13,
1866,
3382,
2877,
6634,
13,
2686,
15029,
1094,
2310,
2659,
339,
1423,
63,
2087,
14,
525,
63,
2094,
3654,
79,
297,
2850,
1753,
297,
1595,
534,
1617,
63,
2052,
297,
288,
849,
29,
797,
12,
1415,
29,
797,
12,
1720,
534,
1180,
314,
2269,
22217,
530,
11849,
283,
288,
283,
21080,
805,
370,
8671,
314,
699,
36,
13,
1866,
12,
3140,
402,
314,
283,
288,
283,
20082,
2605,
22217,
530,
14046,
805,
3130,
2053,
534,
1180,
63,
1753,
63,
3691,
1866,
358,
272,
1423,
63,
2087,
14,
525,
63,
2094,
3654,
66,
297,
2850,
1095,
297,
9237,
534,
7386,
730,
29,
1609,
12,
288,
1415,
29,
549,
12,
1720,
534,
409,
402,
6634,
13,
2686,
15029,
1338,
402,
314,
18828,
283,
288,
283,
9347,
3130,
8214,
534,
24484,
299,
5167,
82,
297,
2053,
534,
1095,
358,
272,
1423,
63,
2087,
14,
525,
63,
2094,
3654,
84,
297,
2850,
396,
297,
9237,
534,
7386,
730,
29,
1609,
12,
288,
1415,
29,
549,
12,
1720,
534,
409,
402,
6634,
13,
2686,
15029,
1338,
402,
314,
10295,
283,
288,
283,
1235,
316,
12470,
3130,
8214,
534,
24484,
299,
5167,
82,
297,
2053,
534,
396,
358,
339,
2368,
275,
1423,
63,
2087,
14,
1122,
63,
589,
8,
3020,
9,
339,
340,
334,
552,
8,
4958,
14,
1095,
9,
450,
499,
9,
1137,
378,
26,
267,
1423,
63,
2087,
14,
705,
360,
15448,
18828,
2633,
14,
7754,
1104,
1265,
283,
355,
283,
7804,
21399,
314,
334,
24484,
299,
5167,
82,
9,
6346,
6657,
2659,
272,
340,
334,
552,
8,
4958,
14,
396,
9,
450,
499,
9,
1137,
378,
26,
267,
1423,
63,
2087,
14,
705,
360,
15448,
511,
2633,
14,
7754,
1104,
1265,
283,
355,
283,
7804,
21399,
314,
334,
24484,
299,
5167,
82,
9,
6346,
6657,
2659,
272,
340,
822,
8,
4958,
14,
1095,
9,
665,
1695,
26,
267,
1423,
63,
2087,
14,
705,
360,
13297,
1471,
5647,
737,
5210,
841,
4501,
367,
314,
283,
355,
283,
14232,
10295,
2659,
272,
340,
822,
8,
4958,
14,
396,
9,
665,
1695,
26,
267,
1423,
63,
2087,
14,
705,
360,
13297,
1471,
5647,
737,
5210,
841,
4501,
367,
314,
283,
355,
283,
9347,
3769,
12470,
2659,
339,
1300,
275,
3482,
8,
4958,
14,
1095,
59,
16,
447,
18,
467,
2368,
14,
1095,
59,
17,
447,
18,
566,
272,
511,
275,
3482,
8,
4958,
14,
396,
59,
16,
447,
18,
467,
2368,
14,
396,
59,
17,
447,
18,
566,
272,
675,
63,
1753,
63,
3691,
1866,
275,
2368,
14,
1180,
63,
1753,
63,
3691,
1866,
339,
372,
1300,
12,
511,
12,
675,
63,
1753,
63,
3691,
1866,
199,
199,
318,
2446,
8,
3020,
304,
272,
1300,
12,
511,
12,
675,
63,
1753,
63,
3691,
1866,
275,
2198,
63,
4958,
8,
3020,
59,
17,
5728,
272,
1300,
275,
3355,
8,
409,
8,
1095,
430,
272,
511,
275,
3355,
8,
409,
8,
396,
430,
339,
340,
675,
63,
1753,
63,
3691,
1866,
26,
267,
21064,
1866,
275,
394,
77,
2537,
14,
3691,
14,
3691,
1866,
63,
1753,
8,
1095,
12,
511,
9,
272,
587,
26,
267,
21064,
1866,
275,
394,
77,
2537,
14,
3691,
14,
3691,
1866,
8,
1095,
12,
511,
9,
339,
870,
11117,
26,
16,
14,
20,
70,
5285,
908,
8,
3691,
1866,
430,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
8,
1274,
14,
3020,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
257,
1898,
9708,
598,
371,
322,
352,
445,
2871,
18429,
199,
3,
199,
3,
257,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
257,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
257,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
755,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
257,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
257,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
257,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
257,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
257,
4204,
1334,
314,
844,
14,
199,
199,
646,
7534,
199,
646,
394,
77,
2537,
14,
3691,
199,
646,
984,
199,
199,
318,
2198,
63,
4958,
8,
3020,
304,
272,
408,
23400,
314,
1414,
1004,
2368,
436,
5920,
626,
2985,
26743,
314,
272,
9760,
370,
5147,
314,
5331,
402,
314,
2240,
14,
1803,
2877,
6572,
402,
272,
4501,
334,
11760,
9,
315,
314,
1824,
334,
24484,
12,
299,
5167,
82,
395,
436,
282,
5046,
410,
1958,
3775,
272,
370,
675,
14854,
87,
1873,
261,
503,
22217,
530,
14046,
14,
339,
6431,
2368,
26,
272,
9238,
1553,
5817,
1004,
2368,
14,
272,
408,
272,
1423,
63,
2087,
275,
7534,
14,
10730,
8,
1802,
534,
13862,
2335,
314,
283,
288,
283,
11156,
13,
1866,
3382,
2877,
6634,
13,
2686,
15029,
1094,
2310,
2659,
339,
1423,
63,
2087,
14,
525,
63,
2094,
3654,
79,
297,
2850,
1753,
297,
1595,
534,
1617,
63,
2052,
297,
288,
849,
29,
797,
12,
1415,
29,
797,
12,
1720,
534,
1180,
314,
2269,
22217,
530,
11849,
283,
288,
283,
21080,
805,
370,
8671,
314,
699,
36,
13,
1866,
12,
3140,
402,
314,
283,
288,
283,
20082,
2605,
22217,
530,
14046,
805,
3130,
2053,
534,
1180,
63,
1753,
63,
3691,
1866,
358,
272,
1423,
63,
2087,
14,
525,
63,
2094,
3654,
66,
297,
2850,
1095,
297,
9237,
534,
7386,
730,
29,
1609,
12,
288,
1415,
29,
549,
12,
1720,
534,
409,
402,
6634,
13,
2686,
15029,
1338,
402,
314,
18828,
283,
288,
283,
9347,
3130,
8214,
534,
24484,
299,
5167,
82,
297,
2053,
534,
1095,
358,
272,
1423,
63,
2087,
14,
525,
63,
2094,
3654,
84,
297,
2850,
396,
297,
9237,
534,
7386,
730,
29,
1609,
12,
288,
1415,
29,
549,
12,
1720,
534,
409,
402,
6634,
13,
2686,
15029,
1338,
402,
314,
10295,
283,
288,
283,
1235,
316,
12470,
3130,
8214,
534,
24484,
299,
5167,
82,
297,
2053,
534,
396,
358,
339,
2368,
275,
1423,
63,
2087,
14,
1122,
63,
589,
8,
3020,
9,
339,
340,
334,
552,
8,
4958,
14,
1095,
9,
450,
499,
9,
1137,
378,
26,
267,
1423,
63,
2087,
14,
705,
360,
15448,
18828,
2633,
14,
7754,
1104,
1265,
283,
355,
283,
7804,
21399,
314,
334,
24484,
299,
5167,
82,
9,
6346,
6657,
2659,
272,
340,
334,
552,
8,
4958,
14,
396,
9,
450,
499,
9,
1137,
378,
26,
267,
1423,
63,
2087,
14,
705,
360,
15448,
511,
2633,
14,
7754,
1104,
1265,
283,
355,
283,
7804,
21399,
314,
334,
24484,
299,
5167,
82,
9,
6346,
6657,
2659,
272,
340,
822,
8,
4958,
14,
1095,
9,
665,
1695,
26,
267,
1423,
63,
2087,
14,
705,
360,
13297,
1471,
5647,
737,
5210,
841,
4501,
367,
314,
283,
355,
283,
14232,
10295,
2659,
272,
340,
822,
8,
4958,
14,
396,
9,
665,
1695,
26,
267,
1423,
63,
2087,
14,
705,
360,
13297,
1471,
5647,
737,
5210,
841,
4501,
367,
314,
283,
355,
283,
9347,
3769,
12470,
2659,
339,
1300,
275,
3482,
8,
4958,
14,
1095,
59,
16,
447,
18,
467,
2368,
14,
1095,
59,
17,
447,
18,
566,
272,
511,
275,
3482,
8,
4958,
14,
396,
59,
16,
447,
18,
467,
2368,
14,
396,
59,
17,
447,
18,
566,
272,
675,
63,
1753,
63,
3691,
1866,
275,
2368,
14,
1180,
63,
1753,
63,
3691,
1866,
339,
372,
1300,
12,
511,
12,
675,
63,
1753,
63,
3691,
1866,
199,
199,
318,
2446,
8,
3020,
304,
272,
1300,
12,
511,
12,
675,
63,
1753,
63,
3691,
1866,
275,
2198,
63,
4958,
8,
3020,
59,
17,
5728,
272,
1300,
275,
3355,
8,
409,
8,
1095,
430,
272,
511,
275,
3355,
8,
409,
8,
396,
430,
339,
340,
675,
63,
1753,
63,
3691,
1866,
26,
267,
21064,
1866,
275,
394,
77,
2537,
14,
3691,
14,
3691,
1866,
63,
1753,
8,
1095,
12,
511,
9,
272,
587,
26,
267,
21064,
1866,
275,
394,
77,
2537,
14,
3691,
14,
3691,
1866,
8,
1095,
12,
511,
9,
339,
870,
11117,
26,
16,
14,
20,
70,
5285,
908,
8,
3691,
1866,
430,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2446,
8,
1274,
14,
3020,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
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neutron-lib
|
neutron_lib/plugins/ml2/api.py
|
1
|
47478
|
# 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 abc
# The following keys are used in the segment dictionaries passed via
# the driver API.
ID = 'id'
NETWORK_TYPE = 'network_type'
PHYSICAL_NETWORK = 'physical_network'
SEGMENTATION_ID = 'segmentation_id'
MTU = 'mtu'
NETWORK_ID = 'network_id'
# The following keys are used in the binding level dictionaries
# available via the binding_levels and original_binding_levels
# PortContext properties.
BOUND_DRIVER = 'bound_driver'
BOUND_SEGMENT = 'bound_segment'
class MechanismDriver(object, metaclass=abc.ABCMeta):
"""Define stable abstract interface for ML2 mechanism drivers.
A mechanism driver is called on the creation, update, and deletion
of networks and ports. For every event, there are two methods that
get called - one within the database transaction (method suffix of
_precommit), one right afterwards (method suffix of _postcommit).
Exceptions raised by methods called inside the transaction can
rollback, but should not make any blocking calls (for example,
REST requests to an outside controller). Methods called after
transaction commits can make blocking external calls, though these
will block the entire process. Exceptions raised in calls after
the transaction commits may cause the associated resource to be
deleted.
Because rollback outside of the transaction is not done in the
update network/port case, all data validation must be done within
methods that are part of the database transaction.
"""
# Used in generating resource provider UUIDs for physical network
# interfaces. Each mechanism driver supporting Placement should have its
# own UUID v5 namespace (which is a UUID v1 in turn). When set to a
# concrete value use a uuid.UUID() object, not the string format.
# It will be used when hashing RP UUIDs from:
# (mech driver namespace, hostname, physical bridge/interface name)
# When needed generate new namespace UUIDs by:
# python -c 'import uuid ; print uuid.uuid1()'
# See also:
# https://tools.ietf.org/html/rfc4122
# https://stackoverflow.com/a/7816117
resource_provider_uuid5_namespace = None
@abc.abstractmethod
def initialize(self):
"""Perform driver initialization.
Called after all drivers have been loaded and the database has
been initialized. No abstract methods defined below will be
called prior to this method being called.
"""
def create_network_precommit(self, context):
"""Allocate resources for a new network.
:param context: NetworkContext instance describing the new
network.
Create a new network, allocating resources as necessary in the
database. Called inside transaction context on session. Call
cannot block. Raising an exception will result in a rollback
of the current transaction.
"""
pass
def create_network_postcommit(self, context):
"""Create a network.
:param context: NetworkContext instance describing the new
network.
Called after the transaction commits. Call can block, though
will block the entire process so care should be taken to not
drastically affect performance. Raising an exception will
cause the deletion of the resource.
"""
pass
def update_network_precommit(self, context):
"""Update resources of a network.
:param context: NetworkContext instance describing the new
state of the network, as well as the original state prior
to the update_network call.
Update values of a network, updating the associated resources
in the database. Called inside transaction context on session.
Raising an exception will result in rollback of the
transaction.
update_network_precommit is called for all changes to the
network state. It is up to the mechanism driver to ignore
state or state changes that it does not know or care about.
"""
pass
def update_network_postcommit(self, context):
"""Update a network.
:param context: NetworkContext instance describing the new
state of the network, as well as the original state prior
to the update_network call.
Called after the transaction commits. Call can block, though
will block the entire process so care should be taken to not
drastically affect performance. Raising an exception will
cause the deletion of the resource.
update_network_postcommit is called for all changes to the
network state. It is up to the mechanism driver to ignore
state or state changes that it does not know or care about.
"""
pass
def delete_network_precommit(self, context):
"""Delete resources for a network.
:param context: NetworkContext instance describing the current
state of the network, prior to the call to delete it.
Delete network resources previously allocated by this
mechanism driver for a network. Called inside transaction
context on session. Runtime errors are not expected, but
raising an exception will result in rollback of the
transaction.
"""
pass
def delete_network_postcommit(self, context):
"""Delete a network.
:param context: NetworkContext instance describing the current
state of the network, prior to the call to delete it.
Called after the transaction commits. Call can block, though
will block the entire process so care should be taken to not
drastically affect performance. Runtime errors are not
expected, and will not prevent the resource from being
deleted.
"""
pass
def create_subnet_precommit(self, context):
"""Allocate resources for a new subnet.
:param context: SubnetContext instance describing the new
subnet.
Create a new subnet, allocating resources as necessary in the
database. Called inside transaction context on session. Call
cannot block. Raising an exception will result in a rollback
of the current transaction.
"""
pass
def create_subnet_postcommit(self, context):
"""Create a subnet.
:param context: SubnetContext instance describing the new
subnet.
Called after the transaction commits. Call can block, though
will block the entire process so care should be taken to not
drastically affect performance. Raising an exception will
cause the deletion of the resource.
"""
pass
def update_subnet_precommit(self, context):
"""Update resources of a subnet.
:param context: SubnetContext instance describing the new
state of the subnet, as well as the original state prior
to the update_subnet call.
Update values of a subnet, updating the associated resources
in the database. Called inside transaction context on session.
Raising an exception will result in rollback of the
transaction.
update_subnet_precommit is called for all changes to the
subnet state. It is up to the mechanism driver to ignore
state or state changes that it does not know or care about.
"""
pass
def update_subnet_postcommit(self, context):
"""Update a subnet.
:param context: SubnetContext instance describing the new
state of the subnet, as well as the original state prior
to the update_subnet call.
Called after the transaction commits. Call can block, though
will block the entire process so care should be taken to not
drastically affect performance. Raising an exception will
cause the deletion of the resource.
update_subnet_postcommit is called for all changes to the
subnet state. It is up to the mechanism driver to ignore
state or state changes that it does not know or care about.
"""
pass
def delete_subnet_precommit(self, context):
"""Delete resources for a subnet.
:param context: SubnetContext instance describing the current
state of the subnet, prior to the call to delete it.
Delete subnet resources previously allocated by this
mechanism driver for a subnet. Called inside transaction
context on session. Runtime errors are not expected, but
raising an exception will result in rollback of the
transaction.
"""
pass
def delete_subnet_postcommit(self, context):
"""Delete a subnet.
:param context: SubnetContext instance describing the current
state of the subnet, prior to the call to delete it.
Called after the transaction commits. Call can block, though
will block the entire process so care should be taken to not
drastically affect performance. Runtime errors are not
expected, and will not prevent the resource from being
deleted.
"""
pass
def create_port_precommit(self, context):
"""Allocate resources for a new port.
:param context: PortContext instance describing the port.
Create a new port, allocating resources as necessary in the
database. Called inside transaction context on session. Call
cannot block. Raising an exception will result in a rollback
of the current transaction.
"""
pass
def create_port_postcommit(self, context):
"""Create a port.
:param context: PortContext instance describing the port.
Called after the transaction completes. Call can block, though
will block the entire process so care should be taken to not
drastically affect performance. Raising an exception will
result in the deletion of the resource.
"""
pass
def update_port_precommit(self, context):
"""Update resources of a port.
:param context: PortContext instance describing the new
state of the port, as well as the original state prior
to the update_port call.
Called inside transaction context on session to complete a
port update as defined by this mechanism driver. Raising an
exception will result in rollback of the transaction.
update_port_precommit is called for all changes to the port
state. It is up to the mechanism driver to ignore state or
state changes that it does not know or care about.
"""
pass
def update_port_postcommit(self, context):
"""Update a port.
:param context: PortContext instance describing the new
state of the port, as well as the original state prior
to the update_port call.
Called after the transaction completes. Call can block, though
will block the entire process so care should be taken to not
drastically affect performance. Raising an exception will
result in the deletion of the resource.
update_port_postcommit is called for all changes to the port
state. It is up to the mechanism driver to ignore state or
state changes that it does not know or care about.
"""
pass
def delete_port_precommit(self, context):
"""Delete resources of a port.
:param context: PortContext instance describing the current
state of the port, prior to the call to delete it.
Called inside transaction context on session. Runtime errors
are not expected, but raising an exception will result in
rollback of the transaction.
"""
pass
def delete_port_postcommit(self, context):
"""Delete a port.
:param context: PortContext instance describing the current
state of the port, prior to the call to delete it.
Called after the transaction completes. Call can block, though
will block the entire process so care should be taken to not
drastically affect performance. Runtime errors are not
expected, and will not prevent the resource from being
deleted.
"""
pass
def bind_port(self, context):
"""Attempt to bind a port.
:param context: PortContext instance describing the port
This method is called outside any transaction to attempt to
establish a port binding using this mechanism driver. Bindings
may be created at each of multiple levels of a hierarchical
network, and are established from the top level downward. At
each level, the mechanism driver determines whether it can
bind to any of the network segments in the
context.segments_to_bind property, based on the value of the
context.host property, any relevant port or network
attributes, and its own knowledge of the network topology. At
the top level, context.segments_to_bind contains the static
segments of the port's network. At each lower level of
binding, it contains static or dynamic segments supplied by
the driver that bound at the level above. If the driver is
able to complete the binding of the port to any segment in
context.segments_to_bind, it must call context.set_binding
with the binding details. If it can partially bind the port,
it must call context.continue_binding with the network
segments to be used to bind at the next lower level.
If the binding results are committed after bind_port returns,
they will be seen by all mechanism drivers as
update_port_precommit and update_port_postcommit calls. But if
some other thread or process concurrently binds or updates the
port, these binding results will not be committed, and
update_port_precommit and update_port_postcommit will not be
called on the mechanism drivers with these results. Because
binding results can be discarded rather than committed,
drivers should avoid making persistent state changes in
bind_port, or else must ensure that such state changes are
eventually cleaned up.
Implementing this method explicitly declares the mechanism
driver as having the intention to bind ports. This is inspected
by the QoS service to identify the available QoS rules you
can use with ports.
"""
pass
@property
def _supports_port_binding(self):
return self.__class__.bind_port != MechanismDriver.bind_port
def check_vlan_transparency(self, context):
"""Check if the network supports vlan transparency.
:param context: NetworkContext instance describing the network.
Check if the network supports vlan transparency or not.
"""
pass
def get_workers(self):
"""Get any NeutronWorker instances that should have their own process
Any driver that needs to run processes separate from the API or RPC
workers, can return a sequence of NeutronWorker instances.
"""
return ()
@classmethod
def is_host_filtering_supported(cls):
return (cls.filter_hosts_with_segment_access !=
MechanismDriver.filter_hosts_with_segment_access)
def filter_hosts_with_segment_access(
self, context, segments, candidate_hosts, agent_getter):
"""Filter hosts with access to at least one segment.
:returns: a set with a subset of candidate_hosts.
A driver can overload this method to return a subset of candidate_hosts
with the ones with access to at least one segment.
Default implementation returns all hosts to disable filtering
(backward compatibility).
"""
return candidate_hosts
def responsible_for_ports_allocation(self, context):
"""Is responsible for a port's resource provider?
:param context: PortContext instance describing the port
:returns: True for responsible, False for not responsible
For ports having an allocation in Placement (as expressed
in the port's binding:profile.allocation) decide while
binding if this mechanism driver is responsible for the
physical network interface represented by the resource
provider in Placement. Find the resource provider UUID in
context.current['binding:profile']['allocation'].
Drivers wanting to support resource allocations for ports in
Placement (eg. wanting to guarantee some minimum bandwidth)
must implement this method.
Default implementation returns False (backward compatibility).
"""
return False
@staticmethod
def provider_network_attribute_updates_supported():
"""Returns the provider network attributes that can be updated
Possible values: neutron_lib.api.definitions.provider_net.ATTRIBUTES
:returns: (list) provider network attributes that can be updated in a
live network using this driver.
"""
return []
def supported_extensions(self, extensions):
"""Return the mechanism driver supported extensions
By default this method will return the same provided set, without any
filtering. In case any particular mechanism driver needs to filter out
any specific extension or supports only a reduced set of extensions,
this method should be override.
:param extensions: set of extensions supported by the instance that
created this mechanism driver.
:returns: a set of the extensions currently supported by this
mechanism driver
"""
return extensions
class _TypeDriverBase(object, metaclass=abc.ABCMeta):
@abc.abstractmethod
def get_type(self):
"""Get driver's network type.
:returns: network_type value handled by this driver
"""
@abc.abstractmethod
def initialize(self):
"""Perform driver initialization.
Called after all drivers have been loaded and the database has
been initialized. No abstract methods defined below will be
called prior to this method being called.
"""
@abc.abstractmethod
def is_partial_segment(self, segment):
"""Return True if segment is a partially specified segment.
:param segment: segment dictionary
:returns: boolean
"""
@abc.abstractmethod
def validate_provider_segment(self, segment):
"""Validate attributes of a provider network segment.
:param segment: segment dictionary using keys defined above
:raises: neutron_lib.exceptions.InvalidInput if invalid
Called outside transaction context to validate the provider
attributes for a provider network segment. Raise InvalidInput
if:
- any required attribute is missing
- any prohibited or unrecognized attribute is present
- any attribute value is not valid
The network_type attribute is present in segment, but
need not be validated.
"""
@abc.abstractmethod
def get_mtu(self, physical):
"""Get driver's network MTU.
:returns: mtu maximum transmission unit
Returns the mtu for the network based on the config values and
the network type.
"""
class TypeDriver(_TypeDriverBase, metaclass=abc.ABCMeta):
"""Define abstract interface for ML2 type drivers.
ML2 type drivers each support a specific network_type for provider
and/or tenant network segments. Type drivers must implement this
abstract interface, which defines the API by which the plugin uses
the driver to manage the persistent type-specific resource
allocation state associated with network segments of that type.
Network segments are represented by segment dictionaries using the
NETWORK_TYPE, PHYSICAL_NETWORK, and SEGMENTATION_ID keys defined
above, corresponding to the provider attributes. Future revisions
of the TypeDriver API may add additional segment dictionary
keys. Attributes not applicable for a particular network_type may
either be excluded or stored as None.
TypeDriver passes session as argument for:
- reserve_provider_segment
- allocate_tenant_segment
- release_segment
- get_allocation
"""
@abc.abstractmethod
def reserve_provider_segment(self, session, segment, filters=None):
"""Reserve resource associated with a provider network segment.
:param session: database session
:param segment: segment dictionary
:param filters: a dictionary that is used as search criteria
:returns: segment dictionary
Called inside transaction context on session to reserve the
type-specific resource for a provider network segment. The
segment dictionary passed in was returned by a previous
validate_provider_segment() call.
"""
@abc.abstractmethod
def allocate_tenant_segment(self, session, filters=None):
"""Allocate resource for a new tenant network segment.
:param session: database session
:param filters: a dictionary that is used as search criteria
:returns: segment dictionary using keys defined above
Called inside transaction context on session to allocate a new
tenant network, typically from a type-specific resource
pool. If successful, return a segment dictionary describing
the segment. If tenant network segment cannot be allocated
(i.e. tenant networks not supported or resource pool is
exhausted), return None.
"""
@abc.abstractmethod
def release_segment(self, session, segment):
"""Release network segment.
:param session: database session
:param segment: segment dictionary using keys defined above
Called inside transaction context on session to release a
tenant or provider network's type-specific resource. Runtime
errors are not expected, but raising an exception will result
in rollback of the transaction.
"""
class ML2TypeDriver(_TypeDriverBase, metaclass=abc.ABCMeta):
"""Define abstract interface for ML2 type drivers.
ML2 type drivers each support a specific network_type for provider
and/or tenant network segments. Type drivers must implement this
abstract interface, which defines the API by which the plugin uses
the driver to manage the persistent type-specific resource
allocation state associated with network segments of that type.
Network segments are represented by segment dictionaries using the
NETWORK_TYPE, PHYSICAL_NETWORK, and SEGMENTATION_ID keys defined
above, corresponding to the provider attributes. Future revisions
of the TypeDriver API may add additional segment dictionary
keys. Attributes not applicable for a particular network_type may
either be excluded or stored as None.
ML2TypeDriver passes context as argument for:
- reserve_provider_segment
- allocate_tenant_segment
- release_segment
- get_allocation
"""
@abc.abstractmethod
def reserve_provider_segment(self, context, segment, filters=None):
"""Reserve resource associated with a provider network segment.
:param context: instance of neutron context with DB session
:param segment: segment dictionary
:param filters: a dictionary that is used as search criteria
:returns: segment dictionary
Called inside transaction context on session to reserve the
type-specific resource for a provider network segment. The
segment dictionary passed in was returned by a previous
validate_provider_segment() call.
"""
@abc.abstractmethod
def allocate_tenant_segment(self, context, filters=None):
"""Allocate resource for a new tenant network segment.
:param context: instance of neutron context with DB session
:param filters: a dictionary that is used as search criteria
:returns: segment dictionary using keys defined above
Called inside transaction context on session to allocate a new
tenant network, typically from a type-specific resource
pool. If successful, return a segment dictionary describing
the segment. If tenant network segment cannot be allocated
(i.e. tenant networks not supported or resource pool is
exhausted), return None.
"""
@abc.abstractmethod
def release_segment(self, context, segment):
"""Release network segment.
:param context: instance of neutron context with DB session
:param segment: segment dictionary using keys defined above
Called inside transaction context on session to release a
tenant or provider network's type-specific resource. Runtime
errors are not expected, but raising an exception will result
in rollback of the transaction.
"""
@abc.abstractmethod
def initialize_network_segment_range_support(self):
"""Perform driver network segment range initialization.
Called during the initialization of the ``network-segment-range``
service plugin if enabled, after all drivers have been loaded and the
database has been initialized. This reloads the `default`
network segment ranges when Neutron server starts/restarts.
"""
@abc.abstractmethod
def update_network_segment_range_allocations(self):
"""Update driver network segment range allocations.
This syncs the driver segment allocations when network segment ranges
have been created, updated or deleted.
"""
class NetworkContext(object, metaclass=abc.ABCMeta):
"""Context passed to MechanismDrivers for changes to network resources.
A NetworkContext instance wraps a network resource. It provides
helper methods for accessing other relevant information. Results
from expensive operations are cached so that other
MechanismDrivers can freely access the same information.
"""
@property
@abc.abstractmethod
def current(self):
"""Return the network in its current configuration.
Return the network, as defined by NeutronPluginBaseV2.
create_network and all extensions in the ml2 plugin, with
all its properties 'current' at the time the context was
established.
"""
@property
@abc.abstractmethod
def original(self):
"""Return the network in its original configuration.
Return the network, with all its properties set to their
original values prior to a call to update_network. Method is
only valid within calls to update_network_precommit and
update_network_postcommit.
"""
@property
@abc.abstractmethod
def network_segments(self):
"""Return the segments associated with this network resource."""
class SubnetContext(object, metaclass=abc.ABCMeta):
"""Context passed to MechanismDrivers for changes to subnet resources.
A SubnetContext instance wraps a subnet resource. It provides
helper methods for accessing other relevant information. Results
from expensive operations are cached so that other
MechanismDrivers can freely access the same information.
"""
@property
@abc.abstractmethod
def current(self):
"""Return the subnet in its current configuration.
Return the subnet, as defined by NeutronPluginBaseV2.
create_subnet and all extensions in the ml2 plugin, with
all its properties 'current' at the time the context was
established.
"""
@property
@abc.abstractmethod
def original(self):
"""Return the subnet in its original configuration.
Return the subnet, with all its properties set to their
original values prior to a call to update_subnet. Method is
only valid within calls to update_subnet_precommit and
update_subnet_postcommit.
"""
class PortContext(object, metaclass=abc.ABCMeta):
"""Context passed to MechanismDrivers for changes to port resources.
A PortContext instance wraps a port resource. It provides helper
methods for accessing other relevant information. Results from
expensive operations are cached so that other MechanismDrivers can
freely access the same information.
"""
@property
@abc.abstractmethod
def current(self):
"""Return the port in its current configuration.
Return the port, as defined by NeutronPluginBaseV2.
create_port and all extensions in the ml2 plugin, with
all its properties 'current' at the time the context was
established.
"""
@property
@abc.abstractmethod
def original(self):
"""Return the port in its original configuration.
Return the port, with all its properties set to their
original values prior to a call to update_port. Method is
only valid within calls to update_port_precommit and
update_port_postcommit.
"""
@property
@abc.abstractmethod
def status(self):
"""Return the status of the current port."""
@property
@abc.abstractmethod
def original_status(self):
"""Return the status of the original port.
The method is only valid within calls to update_port_precommit and
update_port_postcommit.
"""
@property
@abc.abstractmethod
def network(self):
"""Return the NetworkContext associated with this port."""
@property
@abc.abstractmethod
def binding_levels(self):
"""Return dictionaries describing the current binding levels.
This property returns a list of dictionaries describing each
binding level if the port is bound or partially bound, or None
if the port is unbound. Each returned dictionary contains the
name of the bound driver under the BOUND_DRIVER key, and the
bound segment dictionary under the BOUND_SEGMENT key.
The first entry (index 0) describes the top-level binding,
which always involves one of the port's network's static
segments. In the case of a hierarchical binding, subsequent
entries describe the lower-level bindings in descending order,
which may involve dynamic segments. Adjacent levels where
different drivers bind the same static or dynamic segment are
possible. The last entry (index -1) describes the bottom-level
binding that supplied the port's binding:vif_type and
binding:vif_details attribute values.
Within calls to MechanismDriver.bind_port, descriptions of the
levels above the level currently being bound are returned.
"""
@property
@abc.abstractmethod
def original_binding_levels(self):
"""Return dictionaries describing the original binding levels.
This property returns a list of dictionaries describing each
original binding level if the port was previously bound, or
None if the port was unbound. The content is as described for
the binding_levels property.
This property is only valid within calls to
update_port_precommit and update_port_postcommit. It returns
None otherwise.
"""
@property
@abc.abstractmethod
def top_bound_segment(self):
"""Return the current top-level bound segment dictionary.
This property returns the current top-level bound segment
dictionary, or None if the port is unbound. For a bound port,
top_bound_segment is equivalent to
binding_levels[0][BOUND_SEGMENT], and returns one of the
port's network's static segments.
"""
@property
@abc.abstractmethod
def original_top_bound_segment(self):
"""Return the original top-level bound segment dictionary.
This property returns the original top-level bound segment
dictionary, or None if the port was previously unbound. For a
previously bound port, original_top_bound_segment is
equivalent to original_binding_levels[0][BOUND_SEGMENT], and
returns one of the port's network's static segments.
This property is only valid within calls to
update_port_precommit and update_port_postcommit. It returns
None otherwise.
"""
@property
@abc.abstractmethod
def bottom_bound_segment(self):
"""Return the current bottom-level bound segment dictionary.
This property returns the current bottom-level bound segment
dictionary, or None if the port is unbound. For a bound port,
bottom_bound_segment is equivalent to
binding_levels[-1][BOUND_SEGMENT], and returns the segment
whose binding supplied the port's binding:vif_type and
binding:vif_details attribute values.
"""
@property
@abc.abstractmethod
def original_bottom_bound_segment(self):
"""Return the original bottom-level bound segment dictionary.
This property returns the original bottom-level bound segment
dictionary, or None if the port was previously unbound. For a
previously bound port, original_bottom_bound_segment is
equivalent to original_binding_levels[-1][BOUND_SEGMENT], and
returns the segment whose binding supplied the port's previous
binding:vif_type and binding:vif_details attribute values.
This property is only valid within calls to
update_port_precommit and update_port_postcommit. It returns
None otherwise.
"""
@property
@abc.abstractmethod
def host(self):
"""Return the host with which the port is associated.
In the context of a host-specific operation on a distributed
port, the host property indicates the host for which the port
operation is being performed. Otherwise, it is the same value
as current['binding:host_id'].
"""
@property
@abc.abstractmethod
def original_host(self):
"""Return the original host with which the port was associated.
In the context of a host-specific operation on a distributed
port, the original_host property indicates the host for which
the port operation is being performed. Otherwise, it is the
same value as original['binding:host_id'].
This property is only valid within calls to
update_port_precommit and update_port_postcommit. It returns
None otherwise.
"""
@property
@abc.abstractmethod
def vif_type(self):
"""Return the vif_type indicating the binding state of the port.
In the context of a host-specific operation on a distributed
port, the vif_type property indicates the binding state for
the host for which the port operation is being
performed. Otherwise, it is the same value as
current['binding:vif_type'].
"""
@property
@abc.abstractmethod
def original_vif_type(self):
"""Return the original vif_type of the port.
In the context of a host-specific operation on a distributed
port, the original_vif_type property indicates original
binding state for the host for which the port operation is
being performed. Otherwise, it is the same value as
original['binding:vif_type'].
This property is only valid within calls to
update_port_precommit and update_port_postcommit. It returns
None otherwise.
"""
@property
@abc.abstractmethod
def vif_details(self):
"""Return the vif_details describing the binding of the port.
In the context of a host-specific operation on a distributed
port, the vif_details property describes the binding for the
host for which the port operation is being
performed. Otherwise, it is the same value as
current['binding:vif_details'].
"""
@property
@abc.abstractmethod
def original_vif_details(self):
"""Return the original vif_details of the port.
In the context of a host-specific operation on a distributed
port, the original_vif_details property describes the original
binding for the host for which the port operation is being
performed. Otherwise, it is the same value as
original['binding:vif_details'].
This property is only valid within calls to
update_port_precommit and update_port_postcommit. It returns
None otherwise.
"""
@property
@abc.abstractmethod
def segments_to_bind(self):
"""Return the list of segments with which to bind the port.
This property returns the list of segment dictionaries with
which the mechanism driver may bind the port. When
establishing a top-level binding, these will be the port's
network's static segments. For each subsequent level, these
will be the segments passed to continue_binding by the
mechanism driver that bound the level above.
This property is only valid within calls to
MechanismDriver.bind_port. It returns None otherwise.
"""
@abc.abstractmethod
def host_agents(self, agent_type):
"""Get agents of the specified type on port's host.
:param agent_type: Agent type identifier
:returns: List of neutron.db.models.agent.Agent records
"""
@abc.abstractmethod
def set_binding(self, segment_id, vif_type, vif_details,
status=None):
"""Set the bottom-level binding for the port.
:param segment_id: Network segment bound for the port.
:param vif_type: The VIF type for the bound port.
:param vif_details: Dictionary with details for VIF driver.
:param status: Port status to set if not None.
This method is called by MechanismDriver.bind_port to indicate
success and specify binding details to use for port. The
segment_id must identify an item in the current value of the
segments_to_bind property.
"""
@abc.abstractmethod
def continue_binding(self, segment_id, next_segments_to_bind):
"""Continue binding the port with different segments.
:param segment_id: Network segment partially bound for the port.
:param next_segments_to_bind: Segments to continue binding with.
This method is called by MechanismDriver.bind_port to indicate
it was able to partially bind the port, but that one or more
additional mechanism drivers are required to complete the
binding. The segment_id must identify an item in the current
value of the segments_to_bind property. The list of segments
IDs passed as next_segments_to_bind identify dynamic (or
static) segments of the port's network that will be used to
populate segments_to_bind for the next lower level of a
hierarchical binding.
"""
@abc.abstractmethod
def allocate_dynamic_segment(self, segment):
"""Allocate a dynamic segment.
:param segment: A partially or fully specified segment dictionary
Called by the MechanismDriver.bind_port, create_port or update_port
to dynamically allocate a segment for the port using the partial
segment specified. The segment dictionary can be a fully or partially
specified segment. At a minimum it needs the network_type populated to
call on the appropriate type driver.
"""
@abc.abstractmethod
def release_dynamic_segment(self, segment_id):
"""Release an allocated dynamic segment.
:param segment_id: UUID of the dynamic network segment.
Called by the MechanismDriver.delete_port or update_port to release
the dynamic segment allocated for this port.
"""
class ExtensionDriver(object, metaclass=abc.ABCMeta):
"""Define stable abstract interface for ML2 extension drivers.
An extension driver extends the core resources implemented by the
ML2 plugin with additional attributes. Methods that process create
and update operations for these resources validate and persist
values for extended attributes supplied through the API. Other
methods extend the resource dictionaries returned from the API
operations with the values of the extended attributes.
"""
@abc.abstractmethod
def initialize(self):
"""Perform driver initialization.
Called after all drivers have been loaded and the database has
been initialized. No abstract methods defined below will be
called prior to this method being called.
"""
@property
def extension_alias(self):
"""Supported extension alias.
Return the alias identifying the core API extension supported
by this driver. Do not declare if API extension handling will
be left to a service plugin, and we just need to provide
core resource extension and updates.
"""
return
@property
def extension_aliases(self):
"""List of extension aliases supported by the driver.
Return a list of aliases identifying the core API extensions
supported by the driver. By default this just returns the
extension_alias property for backwards compatibility.
"""
return [self.extension_alias]
def process_create_network(self, plugin_context, data, result):
"""Process extended attributes for create network.
:param plugin_context: plugin request context
:param data: dictionary of incoming network data
:param result: network dictionary to extend
Called inside transaction context on plugin_context.session to
validate and persist any extended network attributes defined by this
driver. Extended attribute values must also be added to
result.
"""
pass
def process_create_subnet(self, plugin_context, data, result):
"""Process extended attributes for create subnet.
:param plugin_context: plugin request context
:param data: dictionary of incoming subnet data
:param result: subnet dictionary to extend
Called inside transaction context on plugin_context.session to
validate and persist any extended subnet attributes defined by this
driver. Extended attribute values must also be added to
result.
"""
pass
def process_create_port(self, plugin_context, data, result):
"""Process extended attributes for create port.
:param plugin_context: plugin request context
:param data: dictionary of incoming port data
:param result: port dictionary to extend
Called inside transaction context on plugin_context.session to
validate and persist any extended port attributes defined by this
driver. Extended attribute values must also be added to
result.
"""
pass
def process_update_network(self, plugin_context, data, result):
"""Process extended attributes for update network.
:param plugin_context: plugin request context
:param data: dictionary of incoming network data
:param result: network dictionary to extend
Called inside transaction context on plugin_context.session to
validate and update any extended network attributes defined by this
driver. Extended attribute values, whether updated or not,
must also be added to result.
"""
pass
def process_update_subnet(self, plugin_context, data, result):
"""Process extended attributes for update subnet.
:param plugin_context: plugin request context
:param data: dictionary of incoming subnet data
:param result: subnet dictionary to extend
Called inside transaction context on plugin_context.session to
validate and update any extended subnet attributes defined by this
driver. Extended attribute values, whether updated or not,
must also be added to result.
"""
pass
def process_update_port(self, plugin_context, data, result):
"""Process extended attributes for update port.
:param plugin_context: plugin request context
:param data: dictionary of incoming port data
:param result: port dictionary to extend
Called inside transaction context on plugin_context.session to
validate and update any extended port attributes defined by this
driver. Extended attribute values, whether updated or not,
must also be added to result.
"""
pass
def extend_network_dict(self, session, base_model, result):
"""Add extended attributes to network dictionary.
:param session: database session
:param base_model: network model data
:param result: network dictionary to extend
Called inside transaction context on session to add any
extended attributes defined by this driver to a network
dictionary to be used for mechanism driver calls and/or
returned as the result of a network operation.
"""
pass
def extend_subnet_dict(self, session, base_model, result):
"""Add extended attributes to subnet dictionary.
:param session: database session
:param base_model: subnet model data
:param result: subnet dictionary to extend
Called inside transaction context on session to add any
extended attributes defined by this driver to a subnet
dictionary to be used for mechanism driver calls and/or
returned as the result of a subnet operation.
"""
pass
def extend_port_dict(self, session, base_model, result):
"""Add extended attributes to port dictionary.
:param session: database session
:param base_model: port model data
:param result: port dictionary to extend
Called inside transaction context on session to add any
extended attributes defined by this driver to a port
dictionary to be used for mechanism driver calls
and/or returned as the result of a port operation.
"""
pass
|
apache-2.0
|
[
3,
2900,
4481,
4644,
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,
13022,
421,
199,
3,
710,
2569,
2883,
787,
1202,
315,
314,
8135,
11196,
3032,
4799,
199,
3,
314,
5253,
3261,
14,
199,
998,
275,
283,
344,
7,
199,
14560,
63,
2711,
275,
283,
1200,
63,
466,
7,
199,
9791,
20238,
5974,
63,
14560,
275,
283,
15020,
63,
1200,
7,
199,
27001,
2594,
63,
998,
275,
283,
26926,
63,
344,
7,
199,
5747,
53,
275,
283,
17696,
7,
199,
14560,
63,
998,
275,
283,
1200,
63,
344,
7,
199,
199,
3,
710,
2569,
2883,
787,
1202,
315,
314,
11696,
2166,
11196,
199,
3,
2808,
4799,
314,
11696,
63,
11402,
436,
3379,
63,
9140,
63,
11402,
199,
3,
10977,
2998,
4382,
14,
199,
17882,
63,
23401,
275,
283,
3556,
63,
3090,
7,
199,
17882,
63,
27001,
275,
283,
3556,
63,
9255,
7,
421,
199,
533,
3194,
11993,
6158,
8,
785,
12,
17074,
29,
3175,
14,
22254,
304,
272,
408,
16213,
17830,
9006,
3217,
367,
28007,
18,
14729,
19016,
14,
339,
437,
14729,
5253,
365,
2797,
641,
314,
7143,
12,
1678,
12,
436,
14068,
272,
402,
11759,
436,
8873,
14,
2104,
4036,
1566,
12,
2337,
787,
2877,
3102,
626,
272,
664,
2797,
446,
1373,
4453,
314,
3050,
6008,
334,
765,
4739,
402,
272,
485,
657,
3543,
395,
1373,
2451,
26982,
334,
765,
4739,
402,
485,
1932,
3543,
680,
339,
24873,
4915,
701,
3102,
2797,
6272,
314,
6008,
883,
272,
16475,
12,
1325,
1077,
440,
1852,
1263,
14592,
4882,
334,
509,
2893,
12,
272,
14880,
4145,
370,
376,
9682,
7614,
680,
17653,
2797,
2410,
272,
6008,
20835,
883,
1852,
14592,
5957,
4882,
12,
10617,
3520,
272,
911,
1853,
314,
8039,
2112,
14,
24873,
4915,
315,
4882,
2410,
272,
314,
6008,
20835,
1443,
7675,
314,
4568,
2073,
370,
506,
272,
5463,
14,
339,
13821,
16475,
9682,
402,
314,
6008,
365,
440,
4224,
315,
314,
272,
1678,
2784,
15,
719,
1930,
12,
1006,
666,
6411,
1471,
506,
4224,
4453,
272,
3102,
626,
787,
1777,
402,
314,
3050,
6008,
14,
272,
408,
339,
327,
8051,
315,
12999,
2073,
5022,
11134,
83,
367,
14095,
2784,
272,
327,
8386,
14,
7048,
14729,
5253,
21038,
10902,
434,
1077,
1172,
2399,
272,
327,
5705,
11134,
373,
21,
3231,
334,
6777,
365,
282,
11134,
373,
17,
315,
7485,
680,
3979,
663,
370,
282,
272,
327,
13801,
574,
675,
282,
5377,
14,
8757,
342,
909,
12,
440,
314,
1059,
1475,
14,
272,
327,
2779,
911,
506,
1202,
1380,
25223,
820,
48,
11134,
83,
687,
26,
272,
327,
258,
334,
278,
335,
5253,
3231,
12,
6246,
12,
14095,
13928,
15,
3266,
536,
9,
272,
327,
3979,
4346,
3550,
892,
3231,
11134,
83,
701,
26,
272,
327,
258,
2366,
446,
67,
283,
646,
5377,
8700,
870,
5377,
14,
2580,
17,
11716,
272,
327,
1666,
2597,
26,
272,
327,
258,
4178,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
8973,
20,
7507,
272,
327,
258,
4178,
921,
23153,
14,
957,
15,
65,
15,
2277,
975,
7362,
272,
2073,
63,
3780,
63,
2580,
21,
63,
3251,
275,
488,
339,
768,
3175,
14,
10315,
272,
347,
8265,
8,
277,
304,
267,
408,
20906,
5253,
11097,
14,
398,
12295,
2410,
1006,
19016,
1172,
2757,
6511,
436,
314,
3050,
965,
267,
2757,
10038,
14,
3091,
9006,
3102,
3247,
5084,
911,
506,
267,
2797,
6791,
370,
642,
1083,
3769,
2797,
14,
267,
408,
339,
347,
1218,
63,
1200,
63,
657,
3543,
8,
277,
12,
1067,
304,
267,
408,
22712,
5944,
367,
282,
892,
2784,
14,
398,
520,
635,
1067,
26,
7220,
2998,
1256,
13660,
314,
892,
288,
2784,
14,
398,
2790,
282,
892,
2784,
12,
29447,
1958,
5944,
465,
5784,
315,
314,
267,
3050,
14,
12295,
6272,
6008,
1067,
641,
2351,
14,
6523,
267,
3913,
1853,
14,
221,
3898,
11136,
376,
1919,
911,
754,
315,
282,
16475,
267,
402,
314,
1453,
6008,
14,
267,
408,
267,
986,
339,
347,
1218,
63,
1200,
63,
1932,
3543,
8,
277,
12,
1067,
304,
267,
408,
2499,
282,
2784,
14,
398,
520,
635,
1067,
26,
7220,
2998,
1256,
13660,
314,
892,
288,
2784,
14,
398,
12295,
2410,
314,
6008,
20835,
14,
6523,
883,
1853,
12,
10617,
267,
911,
1853,
314,
8039,
2112,
880,
10296,
1077,
506,
9394,
370,
440,
267,
366,
345,
270,
7288,
12787,
10238,
14,
3898,
11136,
376,
1919,
911,
267,
7675,
314,
14068,
402,
314,
2073,
14,
267,
408,
267,
986,
339,
347,
1678,
63,
1200,
63,
657,
3543,
8,
277,
12,
1067,
304,
267,
408,
4152,
5944,
402,
282,
2784,
14,
398,
520,
635,
1067,
26,
7220,
2998,
1256,
13660,
314,
892,
288,
1174,
402,
314,
2784,
12,
465,
5521,
465,
314,
3379,
1174,
6791,
288,
370,
314,
1678,
63,
1200,
1240,
14,
398,
6162,
1338,
402,
282,
2784,
12,
12928,
314,
4568,
5944,
267,
315,
314,
3050,
14,
12295,
6272,
6008,
1067,
641,
2351,
14,
267,
3898,
11136,
376,
1919,
911,
754,
315,
16475,
402,
314,
267,
6008,
14,
398,
1678,
63,
1200,
63,
657,
3543,
365,
2797,
367,
1006,
4493,
370,
314,
267,
2784,
1174,
14,
2779,
365,
1536,
370,
314,
14729,
5253,
370,
3686,
267,
1174,
503,
1174,
4493,
626,
652,
1630,
440,
5715,
503,
10296,
3595,
14,
267,
408,
267,
986,
339,
347,
1678,
63,
1200,
63,
1932,
3543,
8,
277,
12,
1067,
304,
267,
408,
4152,
282,
2784,
14,
398,
520,
635,
1067,
26,
7220,
2998,
1256,
13660,
314,
892,
288,
1174
] |
[
2900,
4481,
4644,
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,
13022,
421,
199,
3,
710,
2569,
2883,
787,
1202,
315,
314,
8135,
11196,
3032,
4799,
199,
3,
314,
5253,
3261,
14,
199,
998,
275,
283,
344,
7,
199,
14560,
63,
2711,
275,
283,
1200,
63,
466,
7,
199,
9791,
20238,
5974,
63,
14560,
275,
283,
15020,
63,
1200,
7,
199,
27001,
2594,
63,
998,
275,
283,
26926,
63,
344,
7,
199,
5747,
53,
275,
283,
17696,
7,
199,
14560,
63,
998,
275,
283,
1200,
63,
344,
7,
199,
199,
3,
710,
2569,
2883,
787,
1202,
315,
314,
11696,
2166,
11196,
199,
3,
2808,
4799,
314,
11696,
63,
11402,
436,
3379,
63,
9140,
63,
11402,
199,
3,
10977,
2998,
4382,
14,
199,
17882,
63,
23401,
275,
283,
3556,
63,
3090,
7,
199,
17882,
63,
27001,
275,
283,
3556,
63,
9255,
7,
421,
199,
533,
3194,
11993,
6158,
8,
785,
12,
17074,
29,
3175,
14,
22254,
304,
272,
408,
16213,
17830,
9006,
3217,
367,
28007,
18,
14729,
19016,
14,
339,
437,
14729,
5253,
365,
2797,
641,
314,
7143,
12,
1678,
12,
436,
14068,
272,
402,
11759,
436,
8873,
14,
2104,
4036,
1566,
12,
2337,
787,
2877,
3102,
626,
272,
664,
2797,
446,
1373,
4453,
314,
3050,
6008,
334,
765,
4739,
402,
272,
485,
657,
3543,
395,
1373,
2451,
26982,
334,
765,
4739,
402,
485,
1932,
3543,
680,
339,
24873,
4915,
701,
3102,
2797,
6272,
314,
6008,
883,
272,
16475,
12,
1325,
1077,
440,
1852,
1263,
14592,
4882,
334,
509,
2893,
12,
272,
14880,
4145,
370,
376,
9682,
7614,
680,
17653,
2797,
2410,
272,
6008,
20835,
883,
1852,
14592,
5957,
4882,
12,
10617,
3520,
272,
911,
1853,
314,
8039,
2112,
14,
24873,
4915,
315,
4882,
2410,
272,
314,
6008,
20835,
1443,
7675,
314,
4568,
2073,
370,
506,
272,
5463,
14,
339,
13821,
16475,
9682,
402,
314,
6008,
365,
440,
4224,
315,
314,
272,
1678,
2784,
15,
719,
1930,
12,
1006,
666,
6411,
1471,
506,
4224,
4453,
272,
3102,
626,
787,
1777,
402,
314,
3050,
6008,
14,
272,
408,
339,
327,
8051,
315,
12999,
2073,
5022,
11134,
83,
367,
14095,
2784,
272,
327,
8386,
14,
7048,
14729,
5253,
21038,
10902,
434,
1077,
1172,
2399,
272,
327,
5705,
11134,
373,
21,
3231,
334,
6777,
365,
282,
11134,
373,
17,
315,
7485,
680,
3979,
663,
370,
282,
272,
327,
13801,
574,
675,
282,
5377,
14,
8757,
342,
909,
12,
440,
314,
1059,
1475,
14,
272,
327,
2779,
911,
506,
1202,
1380,
25223,
820,
48,
11134,
83,
687,
26,
272,
327,
258,
334,
278,
335,
5253,
3231,
12,
6246,
12,
14095,
13928,
15,
3266,
536,
9,
272,
327,
3979,
4346,
3550,
892,
3231,
11134,
83,
701,
26,
272,
327,
258,
2366,
446,
67,
283,
646,
5377,
8700,
870,
5377,
14,
2580,
17,
11716,
272,
327,
1666,
2597,
26,
272,
327,
258,
4178,
921,
2537,
14,
15799,
14,
1308,
15,
1360,
15,
8973,
20,
7507,
272,
327,
258,
4178,
921,
23153,
14,
957,
15,
65,
15,
2277,
975,
7362,
272,
2073,
63,
3780,
63,
2580,
21,
63,
3251,
275,
488,
339,
768,
3175,
14,
10315,
272,
347,
8265,
8,
277,
304,
267,
408,
20906,
5253,
11097,
14,
398,
12295,
2410,
1006,
19016,
1172,
2757,
6511,
436,
314,
3050,
965,
267,
2757,
10038,
14,
3091,
9006,
3102,
3247,
5084,
911,
506,
267,
2797,
6791,
370,
642,
1083,
3769,
2797,
14,
267,
408,
339,
347,
1218,
63,
1200,
63,
657,
3543,
8,
277,
12,
1067,
304,
267,
408,
22712,
5944,
367,
282,
892,
2784,
14,
398,
520,
635,
1067,
26,
7220,
2998,
1256,
13660,
314,
892,
288,
2784,
14,
398,
2790,
282,
892,
2784,
12,
29447,
1958,
5944,
465,
5784,
315,
314,
267,
3050,
14,
12295,
6272,
6008,
1067,
641,
2351,
14,
6523,
267,
3913,
1853,
14,
221,
3898,
11136,
376,
1919,
911,
754,
315,
282,
16475,
267,
402,
314,
1453,
6008,
14,
267,
408,
267,
986,
339,
347,
1218,
63,
1200,
63,
1932,
3543,
8,
277,
12,
1067,
304,
267,
408,
2499,
282,
2784,
14,
398,
520,
635,
1067,
26,
7220,
2998,
1256,
13660,
314,
892,
288,
2784,
14,
398,
12295,
2410,
314,
6008,
20835,
14,
6523,
883,
1853,
12,
10617,
267,
911,
1853,
314,
8039,
2112,
880,
10296,
1077,
506,
9394,
370,
440,
267,
366,
345,
270,
7288,
12787,
10238,
14,
3898,
11136,
376,
1919,
911,
267,
7675,
314,
14068,
402,
314,
2073,
14,
267,
408,
267,
986,
339,
347,
1678,
63,
1200,
63,
657,
3543,
8,
277,
12,
1067,
304,
267,
408,
4152,
5944,
402,
282,
2784,
14,
398,
520,
635,
1067,
26,
7220,
2998,
1256,
13660,
314,
892,
288,
1174,
402,
314,
2784,
12,
465,
5521,
465,
314,
3379,
1174,
6791,
288,
370,
314,
1678,
63,
1200,
1240,
14,
398,
6162,
1338,
402,
282,
2784,
12,
12928,
314,
4568,
5944,
267,
315,
314,
3050,
14,
12295,
6272,
6008,
1067,
641,
2351,
14,
267,
3898,
11136,
376,
1919,
911,
754,
315,
16475,
402,
314,
267,
6008,
14,
398,
1678,
63,
1200,
63,
657,
3543,
365,
2797,
367,
1006,
4493,
370,
314,
267,
2784,
1174,
14,
2779,
365,
1536,
370,
314,
14729,
5253,
370,
3686,
267,
1174,
503,
1174,
4493,
626,
652,
1630,
440,
5715,
503,
10296,
3595,
14,
267,
408,
267,
986,
339,
347,
1678,
63,
1200,
63,
1932,
3543,
8,
277,
12,
1067,
304,
267,
408,
4152,
282,
2784,
14,
398,
520,
635,
1067,
26,
7220,
2998,
1256,
13660,
314,
892,
288,
1174,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
y12uc231/edx-platform
|
lms/djangoapps/bulk_email/migrations/0004_migrate_optout_user.py
|
182
|
6009
|
# -*- coding: utf-8 -*-
from south.db import db
from south.v2 import DataMigration
from django.core.exceptions import ObjectDoesNotExist
class Migration(DataMigration):
def forwards(self, orm):
# forwards data migration to copy over existing emails to associated ids
if not db.dry_run:
for optout in orm.Optout.objects.all():
try:
user = orm['auth.User'].objects.get(email=optout.email)
optout.user = user
optout.save()
except ObjectDoesNotExist:
# if user is not found (because they have already changed their email)
# then delete the optout, as it's no longer useful.
optout.delete()
def backwards(self, orm):
# backwards data migration to copy over emails of students to old email slot
if not db.dry_run:
for optout in orm.Optout.objects.all():
if optout.user is not None:
optout.email = optout.user.email
optout.save()
models = {
'auth.group': {
'Meta': {'object_name': 'Group'},
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}),
'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'})
},
'auth.permission': {
'Meta': {'ordering': "('content_type__app_label', 'content_type__model', 'codename')", 'unique_together': "(('content_type', 'codename'),)", 'object_name': 'Permission'},
'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '50'})
},
'auth.user': {
'Meta': {'object_name': 'User'},
'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}),
'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}),
'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}),
'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}),
'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}),
'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}),
'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}),
'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'})
},
'bulk_email.courseemail': {
'Meta': {'object_name': 'CourseEmail'},
'course_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}),
'html_message': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'modified': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}),
'sender': ('django.db.models.fields.related.ForeignKey', [], {'default': '1', 'to': "orm['auth.User']", 'null': 'True', 'blank': 'True'}),
'slug': ('django.db.models.fields.CharField', [], {'max_length': '128', 'db_index': 'True'}),
'subject': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}),
'text_message': ('django.db.models.fields.TextField', [], {'null': 'True', 'blank': 'True'}),
'to_option': ('django.db.models.fields.CharField', [], {'default': "'myself'", 'max_length': '64'})
},
'bulk_email.optout': {
'Meta': {'unique_together': "(('user', 'course_id'),)", 'object_name': 'Optout'},
'course_id': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'email': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'user': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['auth.User']", 'null': 'True'})
},
'contenttypes.contenttype': {
'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"},
'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),
'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}),
'name': ('django.db.models.fields.CharField', [], {'max_length': '100'})
}
}
complete_apps = ['bulk_email']
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
3918,
9816,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
421,
199,
533,
12090,
8,
1451,
9816,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
398,
327,
17465,
666,
8367,
370,
1331,
1806,
3411,
14931,
370,
4568,
2762,
267,
340,
440,
1592,
14,
10481,
63,
1065,
26,
288,
367,
1687,
475,
337,
315,
9813,
14,
4619,
475,
337,
14,
1462,
14,
452,
837,
355,
862,
26,
490,
922,
275,
9813,
459,
1178,
14,
1899,
2278,
1462,
14,
362,
8,
2123,
29,
411,
475,
337,
14,
2123,
9,
490,
1687,
475,
337,
14,
751,
275,
922,
490,
1687,
475,
337,
14,
2117,
342,
355,
871,
24803,
26,
490,
327,
340,
922,
365,
440,
1911,
334,
20684,
2985,
1172,
2575,
2896,
3932,
3031,
9,
490,
327,
2066,
3145,
314,
1687,
475,
337,
12,
465,
652,
1159,
949,
8088,
2997,
14,
490,
1687,
475,
337,
14,
1807,
342,
339,
347,
8552,
8,
277,
12,
9813,
304,
398,
327,
8552,
666,
8367,
370,
1331,
1806,
14931,
402,
18557,
370,
2269,
3031,
9348,
267,
340,
440,
1592,
14,
10481,
63,
1065,
26,
288,
367,
1687,
475,
337,
315,
9813,
14,
4619,
475,
337,
14,
1462,
14,
452,
837,
355,
340,
1687,
475,
337,
14,
751,
365,
440,
488,
26,
490,
1687,
475,
337,
14,
2123,
275,
1687,
475,
337,
14,
751,
14,
2123,
490,
1687,
475,
337,
14,
2117,
342,
339,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1317,
63,
466,
363,
571,
63,
1302,
297,
283,
1317,
63,
466,
363,
1238,
297,
283,
11879,
18106,
283,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
283,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2473,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1216,
3071,
267,
1660,
267,
283,
9377,
63,
2123,
14,
1972,
2123,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
6979,
7035,
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,
3966,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2495,
63,
2131,
63,
525,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
1360,
63,
1188,
356
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
12919,
14,
697,
492,
1592,
199,
504,
12919,
14,
86,
18,
492,
3918,
9816,
199,
504,
1639,
14,
1018,
14,
3924,
492,
24803,
421,
199,
533,
12090,
8,
1451,
9816,
304,
339,
347,
17465,
8,
277,
12,
9813,
304,
398,
327,
17465,
666,
8367,
370,
1331,
1806,
3411,
14931,
370,
4568,
2762,
267,
340,
440,
1592,
14,
10481,
63,
1065,
26,
288,
367,
1687,
475,
337,
315,
9813,
14,
4619,
475,
337,
14,
1462,
14,
452,
837,
355,
862,
26,
490,
922,
275,
9813,
459,
1178,
14,
1899,
2278,
1462,
14,
362,
8,
2123,
29,
411,
475,
337,
14,
2123,
9,
490,
1687,
475,
337,
14,
751,
275,
922,
490,
1687,
475,
337,
14,
2117,
342,
355,
871,
24803,
26,
490,
327,
340,
922,
365,
440,
1911,
334,
20684,
2985,
1172,
2575,
2896,
3932,
3031,
9,
490,
327,
2066,
3145,
314,
1687,
475,
337,
12,
465,
652,
1159,
949,
8088,
2997,
14,
490,
1687,
475,
337,
14,
1807,
342,
339,
347,
8552,
8,
277,
12,
9813,
304,
398,
327,
8552,
666,
8367,
370,
1331,
1806,
14931,
402,
18557,
370,
2269,
3031,
9348,
267,
340,
440,
1592,
14,
10481,
63,
1065,
26,
288,
367,
1687,
475,
337,
315,
9813,
14,
4619,
475,
337,
14,
1462,
14,
452,
837,
355,
340,
1687,
475,
337,
14,
751,
365,
440,
488,
26,
490,
1687,
475,
337,
14,
2123,
275,
1687,
475,
337,
14,
751,
14,
2123,
490,
1687,
475,
337,
14,
2117,
342,
339,
1709,
275,
469,
267,
283,
1178,
14,
923,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
2448,
2267,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1257,
1604,
288,
283,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
3071,
267,
1660,
267,
283,
1178,
14,
5693,
356,
469,
288,
283,
3396,
356,
791,
7128,
356,
16111,
1317,
63,
466,
363,
571,
63,
1302,
297,
283,
1317,
63,
466,
363,
1238,
297,
283,
11879,
18106,
283,
3235,
63,
6314,
356,
9510,
1317,
63,
466,
297,
283,
11879,
9878,
283,
785,
63,
354,
356,
283,
7980,
2267,
288,
283,
11879,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1960,
1604,
288,
283,
1317,
63,
466,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
3190,
297,
990,
791,
475,
356,
298,
1025,
459,
10778,
14,
11282,
6097,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1400,
3071,
267,
1660,
267,
283,
1178,
14,
751,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
1899,
2267,
288,
283,
602,
63,
11806,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2123,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
16577,
297,
990,
791,
988,
63,
1267,
356,
283,
2194,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2246,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2634,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
2448,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
344,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4378,
297,
990,
791,
3327,
63,
498,
356,
283,
549,
1604,
288,
283,
374,
63,
2682,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
549,
1604,
288,
283,
374,
63,
7018,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
374,
63,
11434,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
5036,
297,
990,
791,
885,
356,
283,
797,
1604,
288,
283,
2019,
63,
2886,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
885,
356,
283,
2083,
14,
2083,
14,
2131,
1604,
288,
283,
2019,
63,
354,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
1216,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
988,
63,
1267,
356,
283,
3933,
1604,
288,
283,
751,
63,
6060,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2407,
14,
7624,
297,
990,
791,
475,
356,
298,
1025,
459,
1178,
14,
7980,
6256,
283,
10247,
356,
283,
797,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
2473,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
2183,
297,
990,
791,
3235,
356,
283,
549,
297,
283,
988,
63,
1267,
356,
283,
1216,
3071,
267,
1660,
267,
283,
9377,
63,
2123,
14,
1972,
2123,
356,
469,
288,
283,
3396,
356,
791,
785,
63,
354,
356,
283,
6979,
7035,
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,
3966,
356,
661,
1176,
14,
697,
14,
992,
14,
955,
14,
4626,
297,
990,
791,
2495,
63,
2131,
63,
525,
356,
283,
549,
297,
283,
2500,
356,
283,
549,
1604,
288,
283,
1360,
63,
1188,
356,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
xingwu1/autorest
|
AutoRest/Generators/Python/Azure.Python.Tests/Expected/AcceptanceTests/StorageManagementClient/storagemanagementclient/storage_management_client.py
|
2
|
5986
|
# 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.service_client import ServiceClient
from msrest import Serializer, Deserializer
from msrestazure import AzureConfiguration
from .version import VERSION
from .operations.storage_accounts_operations import StorageAccountsOperations
from .operations.usage_operations import UsageOperations
from . import models
class StorageManagementClientConfiguration(AzureConfiguration):
"""Configuration for StorageManagementClient
Note that all parameters used to create this instance are saved as instance
attributes.
:param credentials: Gets Azure subscription credentials.
:type credentials: :mod:`A msrestazure Credentials
object<msrestazure.azure_active_directory>`
:param subscription_id: Gets subscription credentials which uniquely
identify Microsoft Azure subscription. The subscription ID forms part of
the URI for every service call.
:type subscription_id: str
:param api_version: Client Api Version.
:type api_version: str
:param accept_language: Gets or sets the preferred language for the
response.
:type accept_language: str
:param long_running_operation_retry_timeout: Gets or sets the retry
timeout in seconds for Long Running Operations. Default value is 30.
:type long_running_operation_retry_timeout: int
:param generate_client_request_id: When set to true a unique
x-ms-client-request-id value is generated and included in each request.
Default is true.
:type generate_client_request_id: bool
:param str base_url: Service URL
:param str filepath: Existing config
"""
def __init__(
self, credentials, subscription_id, api_version='2015-05-01-preview', accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
if credentials is None:
raise ValueError("Parameter 'credentials' must not be None.")
if subscription_id is None:
raise ValueError("Parameter 'subscription_id' must not be None.")
if not isinstance(subscription_id, str):
raise TypeError("Parameter 'subscription_id' must be str.")
if api_version is not None and not isinstance(api_version, str):
raise TypeError("Optional parameter 'api_version' must be str.")
if accept_language is not None and not isinstance(accept_language, str):
raise TypeError("Optional parameter 'accept_language' must be str.")
if not base_url:
base_url = 'https://management.azure.com'
super(StorageManagementClientConfiguration, self).__init__(base_url, filepath)
self.add_user_agent('storagemanagementclient/{}'.format(VERSION))
self.add_user_agent('Azure-SDK-For-Python')
self.credentials = credentials
self.subscription_id = subscription_id
self.api_version = api_version
self.accept_language = accept_language
self.long_running_operation_retry_timeout = long_running_operation_retry_timeout
self.generate_client_request_id = generate_client_request_id
class StorageManagementClient(object):
"""StorageManagementClient
:ivar config: Configuration for client.
:vartype config: StorageManagementClientConfiguration
:ivar storage_accounts: StorageAccounts operations
:vartype storage_accounts: .operations.StorageAccountsOperations
:ivar usage: Usage operations
:vartype usage: .operations.UsageOperations
:param credentials: Gets Azure subscription credentials.
:type credentials: :mod:`A msrestazure Credentials
object<msrestazure.azure_active_directory>`
:param subscription_id: Gets subscription credentials which uniquely
identify Microsoft Azure subscription. The subscription ID forms part of
the URI for every service call.
:type subscription_id: str
:param api_version: Client Api Version.
:type api_version: str
:param accept_language: Gets or sets the preferred language for the
response.
:type accept_language: str
:param long_running_operation_retry_timeout: Gets or sets the retry
timeout in seconds for Long Running Operations. Default value is 30.
:type long_running_operation_retry_timeout: int
:param generate_client_request_id: When set to true a unique
x-ms-client-request-id value is generated and included in each request.
Default is true.
:type generate_client_request_id: bool
:param str base_url: Service URL
:param str filepath: Existing config
"""
def __init__(
self, credentials, subscription_id, api_version='2015-05-01-preview', accept_language='en-US', long_running_operation_retry_timeout=30, generate_client_request_id=True, base_url=None, filepath=None):
self.config = StorageManagementClientConfiguration(credentials, subscription_id, api_version, accept_language, long_running_operation_retry_timeout, generate_client_request_id, base_url, filepath)
self._client = ServiceClient(self.config.credentials, self.config)
client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
self._serialize = Serializer(client_models)
self._deserialize = Deserializer(client_models)
self.storage_accounts = StorageAccountsOperations(
self._client, self.config, self._serialize, self._deserialize)
self.usage = UsageOperations(
self._client, self.config, self._serialize, self._deserialize)
|
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,
1364,
63,
1258,
492,
7591,
3041,
199,
504,
6605,
3911,
492,
25555,
12,
1487,
8349,
199,
504,
6605,
264,
1207,
7895,
492,
15474,
5688,
199,
504,
1275,
1023,
492,
15945,
199,
504,
1275,
8170,
14,
3494,
63,
8370,
63,
8170,
492,
10533,
30682,
12929,
199,
504,
1275,
8170,
14,
3807,
63,
8170,
492,
11028,
12929,
199,
504,
1275,
492,
1709,
421,
199,
533,
10533,
14552,
3041,
5688,
8,
22386,
5688,
304,
272,
408,
5688,
367,
10533,
14552,
3041,
272,
3390,
626,
1006,
2633,
1202,
370,
1218,
642,
1256,
787,
6290,
465,
1256,
272,
3004,
14,
339,
520,
635,
6235,
26,
14509,
15474,
9966,
6235,
14,
272,
520,
466,
6235,
26,
520,
1494,
1705,
33,
6605,
264,
1207,
7895,
23934,
1362,
909,
28,
706,
264,
1207,
7895,
14,
9078,
63,
2682,
63,
3619,
8637,
272,
520,
635,
9966,
63,
344,
26,
14509,
9966,
6235,
1314,
28727,
1362,
10405,
15332,
15474,
9966,
14,
710,
9966,
2870,
4513,
1777,
402,
1362,
314,
9022,
367,
4036,
2435,
1240,
14,
272,
520,
466,
9966,
63,
344,
26,
620,
272,
520,
635,
2986,
63,
1023,
26,
6810,
13986,
3394,
14,
272,
520,
466,
2986,
63,
1023,
26,
620,
272,
520,
635,
4729,
63,
3671,
26,
14509,
503,
5951,
314,
14388,
2637,
367,
314,
1362,
1177,
14,
272,
520,
466,
4729,
63,
3671,
26,
620,
272,
520,
635,
1846,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
26,
14509,
503,
5951,
314,
7269,
1362,
2653,
315,
4696,
367,
19944,
26848,
29474,
14,
3758,
574,
365,
4233,
14,
272,
520,
466,
1846,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
26,
1109,
272,
520,
635,
3550,
63,
1258,
63,
1069,
63,
344,
26,
3979,
663,
370,
2549,
282,
3747,
1362,
671,
13,
706,
13,
1258,
13,
1069,
13,
344,
574,
365,
4046,
436,
5120,
315,
1924,
1056,
14,
1362,
3758,
365,
2549,
14,
272,
520,
466,
3550,
63,
1258,
63,
1069,
63,
344,
26,
2155,
272,
520,
635,
620,
1300,
63,
633,
26,
7591,
2851,
272,
520,
635,
620,
9911,
26,
1316,
26958,
1101,
272,
408,
339,
347,
636,
826,
721,
288,
291,
12,
6235,
12,
9966,
63,
344,
12,
2986,
63,
1023,
534,
7806,
13,
1717,
13,
614,
13,
7780,
297,
4729,
63,
3671,
534,
287,
13,
1668,
297,
1846,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
29,
1216,
12,
3550,
63,
1258,
63,
1069,
63,
344,
29,
549,
12,
1300,
63,
633,
29,
403,
12,
9911,
29,
403,
304,
398,
340,
6235,
365,
488,
26,
288,
746,
1722,
480,
4720,
283,
6942,
7,
1471,
440,
506,
488,
2685,
267,
340,
9966,
63,
344,
365,
488,
26,
288,
746,
1722,
480,
4720,
283,
6645,
63,
344,
7,
1471,
440,
506,
488,
2685,
267,
340,
440,
1228,
8,
6645,
63,
344,
12,
620,
304,
288,
746,
3146,
480,
4720,
283,
6645,
63,
344,
7,
1471,
506,
620,
2685,
267,
340,
2986,
63,
1023,
365,
440,
488,
436,
440,
1228,
8,
1246,
63,
1023,
12,
620,
304,
288,
746,
3146,
480,
7012,
2725,
283,
1246,
63,
1023,
7,
1471,
506,
620,
2685,
267,
340,
4729,
63,
3671,
365,
440,
488,
436,
440,
1228,
8,
5694,
63,
3671,
12,
620,
304,
288,
746,
3146,
480,
7012,
2725,
283,
5694,
63,
3671,
7,
1471,
506,
620,
2685,
267,
340,
440,
1300,
63,
633,
26,
288,
1300,
63,
633,
275,
283,
2859,
921,
8110,
14,
9078,
14,
957,
7,
398,
1613,
8,
6408,
14552,
3041,
5688,
12,
291,
2843,
826,
721,
1095,
63,
633,
12,
9911,
9,
398,
291,
14,
525,
63,
751,
63,
4054,
360,
3494,
8110,
1258,
30837,
908,
8,
4612,
430,
267,
291,
14,
525,
63,
751,
63,
4054,
360,
22386,
13,
14939,
13,
1858,
13,
4718,
358,
398,
291,
14,
6942,
275,
6235,
267,
291,
14,
6645,
63,
344,
275,
9966,
63,
344,
267,
291,
14,
1246,
63,
1023,
275,
2986,
63,
1023,
267,
291,
14,
5694,
63,
3671,
275,
4729,
63,
3671,
267,
291,
14,
2809,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
275,
1846,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
267,
291,
14,
4208,
63,
1258,
63,
1069,
63,
344,
275,
3550,
63,
1258,
63,
1069,
63,
344,
421,
199,
533,
10533,
14552,
3041,
8,
785,
304,
272,
408,
6408,
14552,
3041,
339,
520,
7725,
1101,
26,
11595,
367,
1890,
14,
272,
520,
19729,
1101,
26,
10533,
14552,
3041,
5688,
339,
520,
7725,
4887,
63,
8370,
26,
10533,
30682,
5331,
272,
520,
19729,
4887,
63,
8370,
26,
1275,
8170,
14,
6408,
30682,
12929,
272,
520,
7725,
4503,
26,
11028,
5331,
272,
520,
19729,
4503,
26,
1275,
8170,
14,
7692,
12929,
339,
520,
635,
6235,
26,
14509,
15474,
9966,
6235,
14,
272,
520,
466,
6235,
26,
520,
1494,
1705,
33,
6605,
264,
1207,
7895,
23934,
1362,
909,
28,
706,
264,
1207,
7895,
14,
9078,
63,
2682,
63,
3619,
8637,
272,
520,
635,
9966,
63,
344,
26,
14509,
9966,
6235,
1314,
28727,
1362,
10405,
15332,
15474,
9966,
14,
710,
9966,
2870,
4513,
1777,
402,
1362,
314,
9022,
367,
4036,
2435,
1240,
14,
272,
520,
466,
9966,
63,
344,
26,
620,
272,
520,
635,
2986,
63,
1023,
26,
6810,
13986,
3394,
14,
272,
520,
466,
2986,
63,
1023,
26,
620,
272,
520,
635,
4729,
63,
3671,
26,
14509,
503,
5951,
314,
14388,
2637,
367,
314,
1362,
1177,
14,
272,
520,
466,
4729,
63,
3671,
26,
620,
272,
520,
635,
1846,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
26,
14509,
503,
5951,
314,
7269,
1362,
2653,
315,
4696,
367,
19944,
26848,
29474,
14,
3758,
574,
365,
4233,
14,
272,
520,
466,
1846,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
26,
1109,
272,
520,
635,
3550,
63,
1258,
63,
1069,
63
] |
[
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,
1364,
63,
1258,
492,
7591,
3041,
199,
504,
6605,
3911,
492,
25555,
12,
1487,
8349,
199,
504,
6605,
264,
1207,
7895,
492,
15474,
5688,
199,
504,
1275,
1023,
492,
15945,
199,
504,
1275,
8170,
14,
3494,
63,
8370,
63,
8170,
492,
10533,
30682,
12929,
199,
504,
1275,
8170,
14,
3807,
63,
8170,
492,
11028,
12929,
199,
504,
1275,
492,
1709,
421,
199,
533,
10533,
14552,
3041,
5688,
8,
22386,
5688,
304,
272,
408,
5688,
367,
10533,
14552,
3041,
272,
3390,
626,
1006,
2633,
1202,
370,
1218,
642,
1256,
787,
6290,
465,
1256,
272,
3004,
14,
339,
520,
635,
6235,
26,
14509,
15474,
9966,
6235,
14,
272,
520,
466,
6235,
26,
520,
1494,
1705,
33,
6605,
264,
1207,
7895,
23934,
1362,
909,
28,
706,
264,
1207,
7895,
14,
9078,
63,
2682,
63,
3619,
8637,
272,
520,
635,
9966,
63,
344,
26,
14509,
9966,
6235,
1314,
28727,
1362,
10405,
15332,
15474,
9966,
14,
710,
9966,
2870,
4513,
1777,
402,
1362,
314,
9022,
367,
4036,
2435,
1240,
14,
272,
520,
466,
9966,
63,
344,
26,
620,
272,
520,
635,
2986,
63,
1023,
26,
6810,
13986,
3394,
14,
272,
520,
466,
2986,
63,
1023,
26,
620,
272,
520,
635,
4729,
63,
3671,
26,
14509,
503,
5951,
314,
14388,
2637,
367,
314,
1362,
1177,
14,
272,
520,
466,
4729,
63,
3671,
26,
620,
272,
520,
635,
1846,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
26,
14509,
503,
5951,
314,
7269,
1362,
2653,
315,
4696,
367,
19944,
26848,
29474,
14,
3758,
574,
365,
4233,
14,
272,
520,
466,
1846,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
26,
1109,
272,
520,
635,
3550,
63,
1258,
63,
1069,
63,
344,
26,
3979,
663,
370,
2549,
282,
3747,
1362,
671,
13,
706,
13,
1258,
13,
1069,
13,
344,
574,
365,
4046,
436,
5120,
315,
1924,
1056,
14,
1362,
3758,
365,
2549,
14,
272,
520,
466,
3550,
63,
1258,
63,
1069,
63,
344,
26,
2155,
272,
520,
635,
620,
1300,
63,
633,
26,
7591,
2851,
272,
520,
635,
620,
9911,
26,
1316,
26958,
1101,
272,
408,
339,
347,
636,
826,
721,
288,
291,
12,
6235,
12,
9966,
63,
344,
12,
2986,
63,
1023,
534,
7806,
13,
1717,
13,
614,
13,
7780,
297,
4729,
63,
3671,
534,
287,
13,
1668,
297,
1846,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
29,
1216,
12,
3550,
63,
1258,
63,
1069,
63,
344,
29,
549,
12,
1300,
63,
633,
29,
403,
12,
9911,
29,
403,
304,
398,
340,
6235,
365,
488,
26,
288,
746,
1722,
480,
4720,
283,
6942,
7,
1471,
440,
506,
488,
2685,
267,
340,
9966,
63,
344,
365,
488,
26,
288,
746,
1722,
480,
4720,
283,
6645,
63,
344,
7,
1471,
440,
506,
488,
2685,
267,
340,
440,
1228,
8,
6645,
63,
344,
12,
620,
304,
288,
746,
3146,
480,
4720,
283,
6645,
63,
344,
7,
1471,
506,
620,
2685,
267,
340,
2986,
63,
1023,
365,
440,
488,
436,
440,
1228,
8,
1246,
63,
1023,
12,
620,
304,
288,
746,
3146,
480,
7012,
2725,
283,
1246,
63,
1023,
7,
1471,
506,
620,
2685,
267,
340,
4729,
63,
3671,
365,
440,
488,
436,
440,
1228,
8,
5694,
63,
3671,
12,
620,
304,
288,
746,
3146,
480,
7012,
2725,
283,
5694,
63,
3671,
7,
1471,
506,
620,
2685,
267,
340,
440,
1300,
63,
633,
26,
288,
1300,
63,
633,
275,
283,
2859,
921,
8110,
14,
9078,
14,
957,
7,
398,
1613,
8,
6408,
14552,
3041,
5688,
12,
291,
2843,
826,
721,
1095,
63,
633,
12,
9911,
9,
398,
291,
14,
525,
63,
751,
63,
4054,
360,
3494,
8110,
1258,
30837,
908,
8,
4612,
430,
267,
291,
14,
525,
63,
751,
63,
4054,
360,
22386,
13,
14939,
13,
1858,
13,
4718,
358,
398,
291,
14,
6942,
275,
6235,
267,
291,
14,
6645,
63,
344,
275,
9966,
63,
344,
267,
291,
14,
1246,
63,
1023,
275,
2986,
63,
1023,
267,
291,
14,
5694,
63,
3671,
275,
4729,
63,
3671,
267,
291,
14,
2809,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
275,
1846,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
267,
291,
14,
4208,
63,
1258,
63,
1069,
63,
344,
275,
3550,
63,
1258,
63,
1069,
63,
344,
421,
199,
533,
10533,
14552,
3041,
8,
785,
304,
272,
408,
6408,
14552,
3041,
339,
520,
7725,
1101,
26,
11595,
367,
1890,
14,
272,
520,
19729,
1101,
26,
10533,
14552,
3041,
5688,
339,
520,
7725,
4887,
63,
8370,
26,
10533,
30682,
5331,
272,
520,
19729,
4887,
63,
8370,
26,
1275,
8170,
14,
6408,
30682,
12929,
272,
520,
7725,
4503,
26,
11028,
5331,
272,
520,
19729,
4503,
26,
1275,
8170,
14,
7692,
12929,
339,
520,
635,
6235,
26,
14509,
15474,
9966,
6235,
14,
272,
520,
466,
6235,
26,
520,
1494,
1705,
33,
6605,
264,
1207,
7895,
23934,
1362,
909,
28,
706,
264,
1207,
7895,
14,
9078,
63,
2682,
63,
3619,
8637,
272,
520,
635,
9966,
63,
344,
26,
14509,
9966,
6235,
1314,
28727,
1362,
10405,
15332,
15474,
9966,
14,
710,
9966,
2870,
4513,
1777,
402,
1362,
314,
9022,
367,
4036,
2435,
1240,
14,
272,
520,
466,
9966,
63,
344,
26,
620,
272,
520,
635,
2986,
63,
1023,
26,
6810,
13986,
3394,
14,
272,
520,
466,
2986,
63,
1023,
26,
620,
272,
520,
635,
4729,
63,
3671,
26,
14509,
503,
5951,
314,
14388,
2637,
367,
314,
1362,
1177,
14,
272,
520,
466,
4729,
63,
3671,
26,
620,
272,
520,
635,
1846,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
26,
14509,
503,
5951,
314,
7269,
1362,
2653,
315,
4696,
367,
19944,
26848,
29474,
14,
3758,
574,
365,
4233,
14,
272,
520,
466,
1846,
63,
5720,
63,
5735,
63,
7154,
63,
2593,
26,
1109,
272,
520,
635,
3550,
63,
1258,
63,
1069,
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,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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
] |
lbjay/cds-invenio
|
modules/elmsubmit/lib/elmsubmit_field_validation.py
|
4
|
2925
|
# -*- coding: utf-8 -*-
##
## This file is part of CDS Invenio.
## Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008 CERN.
##
## CDS Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## CDS Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with CDS Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
__revision__ = "$Id$"
import re
def author(value):
"""
The author list must be in the following format:
Put one author per line, and a comma ',' (with no preceding
space) between the name and the firstname initial letters.
The name is going first, followed by the firstname initial
letters. Precede each initial by a single space. Place only a
single space between surnames.
Example: Put
Le Meur, J Y
Baron, T
for
Le Meur Jean-Yves & Baron Thomas.
"""
# Strip each line of leading/trainling whitespace and remove blank lines.
value = '\n'.join(filter(lambda line: line != '', map(lambda line: line.strip(), value.splitlines())))
# txt = txt.replace("\r\n", "\n") # Change to unix newline conventions.
# Allow names like:
# 'MacDonald Schlüter Wolsey-Smith, P J'
hyphenated_word = r'\w+(-\w+)*'
author_surname = r'%s( %s)*' % (hyphenated_word, hyphenated_word)
comma_space = r', '
initials = r'\w( \w)*'
author_re = author_surname + comma_space + initials
# Allow multiline list with no trailing spaces, and only single
# (optional) terminating newline:
author_list = r'(?u)^%s(\n%s)*?$' % (author_re, author_re)
if re.compile(author_list).search(value):
return (author.__doc__, value, True)
else:
return (author.__doc__, value, False)
def date(value):
"""
The date field must be in dd/mm/yyyy format.
eg. 01/03/2010
"""
value = value.strip()
day = '(3[01]|[12][0-9]|0[1-9])'
month = '(1[012]|0[1-9])'
year = '(\d\d\d\d)'
date_re = r'^%s/%s/%s(?!\n)$' % (day, month, year)
if re.compile(date_re).search(value):
return (date.__doc__, value, True)
else:
return (date.__doc__, value, False)
def files(value):
# Strip each line of leading/trainling whitespace and remove blank lines.
# Lowercase each filename.
value = '\n'.join(filter(lambda line: line != '', map(lambda line: line.strip().lower(), value.splitlines())))
return (files.__doc__, value, True)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
445,
3177,
12235,
14,
199,
309,
1898,
334,
35,
9,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
24354,
14,
199,
309,
199,
309,
445,
3177,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
445,
3177,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
445,
3177,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
295,
199,
199,
318,
4132,
8,
585,
304,
272,
408,
272,
710,
4132,
769,
1471,
506,
315,
314,
2569,
1475,
26,
272,
16280,
1373,
4132,
1126,
1004,
12,
436,
282,
10029,
13647,
334,
1045,
949,
22627,
272,
4601,
9,
3382,
314,
536,
436,
314,
1642,
354,
2536,
14435,
14,
339,
710,
536,
365,
9995,
1642,
12,
9437,
701,
314,
1642,
354,
2536,
272,
14435,
14,
221,
5543,
301,
271,
1924,
2536,
701,
282,
2849,
4601,
14,
221,
10902,
1454,
282,
272,
2849,
4601,
3382,
308,
349,
14015,
14,
339,
5679,
26,
16280,
339,
7005,
3194,
300,
12,
1603,
1488,
272,
12377,
265,
12,
377,
339,
367,
339,
7005,
3194,
300,
1603,
69,
290,
13,
57,
2310,
1253,
12377,
265,
27864,
14,
272,
408,
339,
327,
19828,
1924,
1004,
402,
9186,
15,
2834,
2983,
8139,
436,
2813,
4596,
2385,
14,
272,
574,
275,
1557,
78,
1370,
904,
8,
1541,
8,
2734,
1004,
26,
1004,
1137,
3260,
2341,
8,
2734,
1004,
26,
1004,
14,
1913,
1062,
574,
14,
7644,
16890,
339,
327,
9444,
275,
9444,
14,
1814,
4582,
82,
60,
78,
401,
1867,
78,
531,
327,
7743,
370,
16572,
8057,
8758,
852,
14,
339,
327,
9812,
1561,
2839,
26,
272,
327,
283,
3399,
36,
8125,
68,
22985,
76,
17709,
351,
644,
393,
261,
89,
13,
16782,
448,
12,
510,
1603,
7,
339,
7188,
17579,
972,
63,
1027,
275,
519,
1154,
87,
15622,
2696,
87,
11,
3342,
7,
272,
4132,
63,
30959,
275,
519,
5956,
83,
8,
450,
83,
3342,
7,
450,
334,
30215,
972,
63,
1027,
12,
7188,
17579,
972,
63,
1027,
9,
272,
10029,
63,
2638,
275,
519,
297,
283,
272,
2536,
83,
275,
519,
1154,
87,
8,
971,
87,
3342,
7,
272,
4132,
63,
264,
275,
4132,
63,
30959,
435,
10029,
63,
2638,
435,
2536,
83,
339,
327,
9812,
21838,
769,
543,
949,
8520,
7883,
12,
436,
1454,
2849,
272,
327,
334,
4144,
9,
5537,
1958,
8057,
26,
339,
4132,
63,
513,
275,
519,
10120,
85,
18979,
5,
83,
2961,
78,
5,
83,
3342,
31,
12913,
450,
334,
2502,
63,
264,
12,
4132,
63,
264,
9,
339,
340,
295,
14,
2014,
8,
2502,
63,
513,
680,
1733,
8,
585,
304,
267,
372,
334,
2502,
855,
1301,
3108,
574,
12,
715,
9,
272,
587,
26,
267,
372,
334,
2502,
855,
1301,
3108,
574,
12,
756,
9,
199,
199,
318,
1434,
8,
585,
304,
272,
408,
272,
710,
1434,
901,
1471,
506,
315,
13972,
15,
596,
15,
18322,
1475,
14,
272,
11837,
14,
17163,
15,
1644,
15,
6542,
272,
408,
339,
574,
275,
574,
14,
1913,
342,
339,
5382,
275,
8189,
19,
59,
614,
32673,
713,
1527,
16,
13,
25,
11752,
16,
59,
17,
13,
25,
566,
7,
272,
5794,
275,
8189,
17,
59,
11533,
11752,
16,
59,
17,
13,
25,
566,
7,
272,
5361,
275,
283,
2961,
68,
60,
68,
60,
68,
60,
68,
3171,
272,
1434,
63,
264,
275,
519,
4289,
5,
83,
3149,
83,
3149,
83,
2229,
12525,
78,
9,
12913,
450,
334,
2977,
12,
5794,
12,
5361,
9,
339,
340,
295,
14,
2014,
8,
602,
63,
264,
680,
1733,
8,
585,
304,
267,
372,
334,
602,
855,
1301,
3108,
574,
12,
715,
9,
272,
587,
26,
267,
372,
334,
602,
855,
1301,
3108,
574,
12,
756,
9,
199,
199,
318,
1584,
8,
585,
304,
339,
327,
19828,
1924,
1004,
402,
9186,
15,
2834,
2983,
8139,
436,
2813,
4596,
2385,
14,
272,
327,
29893,
2546,
1924,
1788,
14,
272,
574,
275,
1557,
78,
1370,
904,
8,
1541,
8,
2734,
1004,
26,
1004,
1137,
3260,
2341,
8,
2734,
1004,
26,
1004,
14,
1913,
1252,
2325,
1062,
574,
14,
7644,
16890,
339,
372,
334,
1725,
855,
1301,
3108,
574,
12,
715,
9,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
445,
3177,
12235,
14,
199,
309,
1898,
334,
35,
9,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
24354,
14,
199,
309,
199,
309,
445,
3177,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
445,
3177,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
445,
3177,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
295,
199,
199,
318,
4132,
8,
585,
304,
272,
408,
272,
710,
4132,
769,
1471,
506,
315,
314,
2569,
1475,
26,
272,
16280,
1373,
4132,
1126,
1004,
12,
436,
282,
10029,
13647,
334,
1045,
949,
22627,
272,
4601,
9,
3382,
314,
536,
436,
314,
1642,
354,
2536,
14435,
14,
339,
710,
536,
365,
9995,
1642,
12,
9437,
701,
314,
1642,
354,
2536,
272,
14435,
14,
221,
5543,
301,
271,
1924,
2536,
701,
282,
2849,
4601,
14,
221,
10902,
1454,
282,
272,
2849,
4601,
3382,
308,
349,
14015,
14,
339,
5679,
26,
16280,
339,
7005,
3194,
300,
12,
1603,
1488,
272,
12377,
265,
12,
377,
339,
367,
339,
7005,
3194,
300,
1603,
69,
290,
13,
57,
2310,
1253,
12377,
265,
27864,
14,
272,
408,
339,
327,
19828,
1924,
1004,
402,
9186,
15,
2834,
2983,
8139,
436,
2813,
4596,
2385,
14,
272,
574,
275,
1557,
78,
1370,
904,
8,
1541,
8,
2734,
1004,
26,
1004,
1137,
3260,
2341,
8,
2734,
1004,
26,
1004,
14,
1913,
1062,
574,
14,
7644,
16890,
339,
327,
9444,
275,
9444,
14,
1814,
4582,
82,
60,
78,
401,
1867,
78,
531,
327,
7743,
370,
16572,
8057,
8758,
852,
14,
339,
327,
9812,
1561,
2839,
26,
272,
327,
283,
3399,
36,
8125,
68,
22985,
76,
17709,
351,
644,
393,
261,
89,
13,
16782,
448,
12,
510,
1603,
7,
339,
7188,
17579,
972,
63,
1027,
275,
519,
1154,
87,
15622,
2696,
87,
11,
3342,
7,
272,
4132,
63,
30959,
275,
519,
5956,
83,
8,
450,
83,
3342,
7,
450,
334,
30215,
972,
63,
1027,
12,
7188,
17579,
972,
63,
1027,
9,
272,
10029,
63,
2638,
275,
519,
297,
283,
272,
2536,
83,
275,
519,
1154,
87,
8,
971,
87,
3342,
7,
272,
4132,
63,
264,
275,
4132,
63,
30959,
435,
10029,
63,
2638,
435,
2536,
83,
339,
327,
9812,
21838,
769,
543,
949,
8520,
7883,
12,
436,
1454,
2849,
272,
327,
334,
4144,
9,
5537,
1958,
8057,
26,
339,
4132,
63,
513,
275,
519,
10120,
85,
18979,
5,
83,
2961,
78,
5,
83,
3342,
31,
12913,
450,
334,
2502,
63,
264,
12,
4132,
63,
264,
9,
339,
340,
295,
14,
2014,
8,
2502,
63,
513,
680,
1733,
8,
585,
304,
267,
372,
334,
2502,
855,
1301,
3108,
574,
12,
715,
9,
272,
587,
26,
267,
372,
334,
2502,
855,
1301,
3108,
574,
12,
756,
9,
199,
199,
318,
1434,
8,
585,
304,
272,
408,
272,
710,
1434,
901,
1471,
506,
315,
13972,
15,
596,
15,
18322,
1475,
14,
272,
11837,
14,
17163,
15,
1644,
15,
6542,
272,
408,
339,
574,
275,
574,
14,
1913,
342,
339,
5382,
275,
8189,
19,
59,
614,
32673,
713,
1527,
16,
13,
25,
11752,
16,
59,
17,
13,
25,
566,
7,
272,
5794,
275,
8189,
17,
59,
11533,
11752,
16,
59,
17,
13,
25,
566,
7,
272,
5361,
275,
283,
2961,
68,
60,
68,
60,
68,
60,
68,
3171,
272,
1434,
63,
264,
275,
519,
4289,
5,
83,
3149,
83,
3149,
83,
2229,
12525,
78,
9,
12913,
450,
334,
2977,
12,
5794,
12,
5361,
9,
339,
340,
295,
14,
2014,
8,
602,
63,
264,
680,
1733,
8,
585,
304,
267,
372,
334,
602,
855,
1301,
3108,
574,
12,
715,
9,
272,
587,
26,
267,
372,
334,
602,
855,
1301,
3108,
574,
12,
756,
9,
199,
199,
318,
1584,
8,
585,
304,
339,
327,
19828,
1924,
1004,
402,
9186,
15,
2834,
2983,
8139,
436,
2813,
4596,
2385,
14,
272,
327,
29893,
2546,
1924,
1788,
14,
272,
574,
275,
1557,
78,
1370,
904,
8,
1541,
8,
2734,
1004,
26,
1004,
1137,
3260,
2341,
8,
2734,
1004,
26,
1004,
14,
1913,
1252,
2325,
1062,
574,
14,
7644,
16890,
339,
372,
334,
1725,
855,
1301,
3108,
574,
12,
715,
9,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
goblinhack/MundusMeus
|
python/things/snow_mound.py
|
1
|
1029
|
import tp
import mm
def thing_init(t):
return
total_snow_mound = 0
def snow_mound1_init(d1000_roll, tiles=[]):
global total_snow_mound
name = "snow_mound" + str(total_snow_mound + 1)
total_snow_mound = total_snow_mound + 1
x = tp.Tp(name=name,
is_snow_mound=True,
d1000_appearing_roll=d1000_roll)
x.set_short_name("Snow mound")
x.set_is_snow_mound(True)
x.set_is_world_item(True)
x.set_z_depth(mm.Z_DEPTH_FLOOR2)
x.set_blit_top_off(1)
x.set_blit_left_off(1)
x.set_blit_right_off(1)
for t in tiles:
x.set_tile(t, delay_ms=50)
x.thing_init = thing_init
return x
def init():
# high numbers means rare, low means common
snow_mound1_init(d1000_roll=1, tiles=["snow_mound1"])
snow_mound1_init(d1000_roll=1, tiles=["snow_mound2"])
snow_mound1_init(d1000_roll=1, tiles=["snow_mound3"])
snow_mound1_init(d1000_roll=1, tiles=["snow_mound4"])
snow_mound1_init(d1000_roll=1, tiles=["snow_mound5"])
init()
|
lgpl-3.0
|
[
646,
9253,
199,
646,
8562,
421,
199,
318,
8377,
63,
826,
8,
84,
304,
272,
372,
421,
199,
2923,
63,
27765,
63,
573,
725,
275,
378,
421,
199,
318,
308,
2131,
63,
573,
725,
17,
63,
826,
8,
68,
5279,
63,
2827,
12,
30419,
17894,
339,
2288,
3141,
63,
27765,
63,
573,
725,
339,
536,
275,
298,
27765,
63,
573,
725,
2,
435,
620,
8,
2923,
63,
27765,
63,
573,
725,
435,
413,
9,
272,
3141,
63,
27765,
63,
573,
725,
275,
3141,
63,
27765,
63,
573,
725,
435,
413,
339,
671,
275,
9253,
14,
52,
80,
8,
354,
29,
354,
12,
1598,
365,
63,
27765,
63,
573,
725,
29,
549,
12,
1598,
366,
5279,
63,
31711,
9332,
63,
2827,
29,
68,
5279,
63,
2827,
9,
339,
671,
14,
409,
63,
3612,
63,
354,
480,
51,
2131,
333,
1034,
531,
272,
671,
14,
409,
63,
374,
63,
27765,
63,
573,
725,
8,
549,
9,
272,
671,
14,
409,
63,
374,
63,
7617,
63,
1053,
8,
549,
9,
272,
671,
14,
409,
63,
90,
63,
4631,
8,
596,
14,
58,
63,
19715,
63,
38,
1484,
726,
18,
9,
272,
671,
14,
409,
63,
15574,
63,
2119,
63,
1997,
8,
17,
9,
272,
671,
14,
409,
63,
15574,
63,
3039,
63,
1997,
8,
17,
9,
272,
671,
14,
409,
63,
15574,
63,
1019,
63,
1997,
8,
17,
9,
339,
367,
307,
315,
30419,
26,
267,
671,
14,
409,
63,
7172,
8,
84,
12,
7339,
63,
706,
29,
1400,
9,
339,
671,
14,
2127,
63,
826,
275,
8377,
63,
826,
339,
372,
671,
421,
199,
318,
4205,
837,
272,
327,
4721,
5579,
4910,
24063,
12,
6465,
4910,
2863,
272,
308,
2131,
63,
573,
725,
17,
63,
826,
8,
68,
5279,
63,
2827,
29,
17,
12,
30419,
6270,
27765,
63,
573,
725,
17,
3135,
272,
308,
2131,
63,
573,
725,
17,
63,
826,
8,
68,
5279,
63,
2827,
29,
17,
12,
30419,
6270,
27765,
63,
573,
725,
18,
3135,
272,
308,
2131,
63,
573,
725,
17,
63,
826,
8,
68,
5279,
63,
2827,
29,
17,
12,
30419,
6270,
27765,
63,
573,
725,
19,
3135,
272,
308,
2131,
63,
573,
725,
17,
63,
826,
8,
68,
5279,
63,
2827,
29,
17,
12,
30419,
6270,
27765,
63,
573,
725,
20,
3135,
272,
308,
2131,
63,
573,
725,
17,
63,
826,
8,
68,
5279,
63,
2827,
29,
17,
12,
30419,
6270,
27765,
63,
573,
725,
21,
3135,
199,
199,
826,
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
] |
[
9253,
199,
646,
8562,
421,
199,
318,
8377,
63,
826,
8,
84,
304,
272,
372,
421,
199,
2923,
63,
27765,
63,
573,
725,
275,
378,
421,
199,
318,
308,
2131,
63,
573,
725,
17,
63,
826,
8,
68,
5279,
63,
2827,
12,
30419,
17894,
339,
2288,
3141,
63,
27765,
63,
573,
725,
339,
536,
275,
298,
27765,
63,
573,
725,
2,
435,
620,
8,
2923,
63,
27765,
63,
573,
725,
435,
413,
9,
272,
3141,
63,
27765,
63,
573,
725,
275,
3141,
63,
27765,
63,
573,
725,
435,
413,
339,
671,
275,
9253,
14,
52,
80,
8,
354,
29,
354,
12,
1598,
365,
63,
27765,
63,
573,
725,
29,
549,
12,
1598,
366,
5279,
63,
31711,
9332,
63,
2827,
29,
68,
5279,
63,
2827,
9,
339,
671,
14,
409,
63,
3612,
63,
354,
480,
51,
2131,
333,
1034,
531,
272,
671,
14,
409,
63,
374,
63,
27765,
63,
573,
725,
8,
549,
9,
272,
671,
14,
409,
63,
374,
63,
7617,
63,
1053,
8,
549,
9,
272,
671,
14,
409,
63,
90,
63,
4631,
8,
596,
14,
58,
63,
19715,
63,
38,
1484,
726,
18,
9,
272,
671,
14,
409,
63,
15574,
63,
2119,
63,
1997,
8,
17,
9,
272,
671,
14,
409,
63,
15574,
63,
3039,
63,
1997,
8,
17,
9,
272,
671,
14,
409,
63,
15574,
63,
1019,
63,
1997,
8,
17,
9,
339,
367,
307,
315,
30419,
26,
267,
671,
14,
409,
63,
7172,
8,
84,
12,
7339,
63,
706,
29,
1400,
9,
339,
671,
14,
2127,
63,
826,
275,
8377,
63,
826,
339,
372,
671,
421,
199,
318,
4205,
837,
272,
327,
4721,
5579,
4910,
24063,
12,
6465,
4910,
2863,
272,
308,
2131,
63,
573,
725,
17,
63,
826,
8,
68,
5279,
63,
2827,
29,
17,
12,
30419,
6270,
27765,
63,
573,
725,
17,
3135,
272,
308,
2131,
63,
573,
725,
17,
63,
826,
8,
68,
5279,
63,
2827,
29,
17,
12,
30419,
6270,
27765,
63,
573,
725,
18,
3135,
272,
308,
2131,
63,
573,
725,
17,
63,
826,
8,
68,
5279,
63,
2827,
29,
17,
12,
30419,
6270,
27765,
63,
573,
725,
19,
3135,
272,
308,
2131,
63,
573,
725,
17,
63,
826,
8,
68,
5279,
63,
2827,
29,
17,
12,
30419,
6270,
27765,
63,
573,
725,
20,
3135,
272,
308,
2131,
63,
573,
725,
17,
63,
826,
8,
68,
5279,
63,
2827,
29,
17,
12,
30419,
6270,
27765,
63,
573,
725,
21,
3135,
199,
199,
826,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tjsavage/full_nonrel_starter
|
django/core/management/commands/syncdb.py
|
161
|
8141
|
from optparse import make_option
import sys
from django.conf import settings
from django.core.management.base import NoArgsCommand
from django.core.management.color import no_style
from django.core.management.sql import custom_sql_for_model, emit_post_sync_signal
from django.db import connections, router, transaction, models, DEFAULT_DB_ALIAS
from django.utils.datastructures import SortedDict
from django.utils.importlib import import_module
class Command(NoArgsCommand):
option_list = NoArgsCommand.option_list + (
make_option('--noinput', action='store_false', dest='interactive', default=True,
help='Tells Django to NOT prompt the user for input of any kind.'),
make_option('--database', action='store', dest='database',
default=DEFAULT_DB_ALIAS, help='Nominates a database to synchronize. '
'Defaults to the "default" database.'),
)
help = "Create the database tables for all apps in INSTALLED_APPS whose tables haven't already been created."
def handle_noargs(self, **options):
verbosity = int(options.get('verbosity', 1))
interactive = options.get('interactive')
show_traceback = options.get('traceback', False)
# Stealth option -- 'load_initial_data' is used by the testing setup
# process to disable initial fixture loading.
load_initial_data = options.get('load_initial_data', True)
self.style = no_style()
# Import the 'management' module within each installed app, to register
# dispatcher events.
for app_name in settings.INSTALLED_APPS:
try:
import_module('.management', app_name)
except ImportError, exc:
# This is slightly hackish. We want to ignore ImportErrors
# if the "management" module itself is missing -- but we don't
# want to ignore the exception if the management module exists
# but raises an ImportError for some reason. The only way we
# can do this is to check the text of the exception. Note that
# we're a bit broad in how we check the text, because different
# Python implementations may not use the same text.
# CPython uses the text "No module named management"
# PyPy uses "No module named myproject.myapp.management"
msg = exc.args[0]
if not msg.startswith('No module named') or 'management' not in msg:
raise
db = options.get('database', DEFAULT_DB_ALIAS)
connection = connections[db]
cursor = connection.cursor()
# Get a list of already installed *models* so that references work right.
tables = connection.introspection.table_names()
seen_models = connection.introspection.installed_models(tables)
created_models = set()
pending_references = {}
# Build the manifest of apps and models that are to be synchronized
all_models = [
(app.__name__.split('.')[-2],
[m for m in models.get_models(app, include_auto_created=True)
if router.allow_syncdb(db, m)])
for app in models.get_apps()
]
def model_installed(model):
opts = model._meta
converter = connection.introspection.table_name_converter
return not ((converter(opts.db_table) in tables) or
(opts.auto_created and converter(opts.auto_created._meta.db_table) in tables))
manifest = SortedDict(
(app_name, filter(model_installed, model_list))
for app_name, model_list in all_models
)
# Create the tables for each model
if verbosity >= 1:
print "Creating tables ..."
for app_name, model_list in manifest.items():
for model in model_list:
# Create the model's database table, if it doesn't already exist.
if verbosity >= 3:
print "Processing %s.%s model" % (app_name, model._meta.object_name)
sql, references = connection.creation.sql_create_model(model, self.style, seen_models)
seen_models.add(model)
created_models.add(model)
for refto, refs in references.items():
pending_references.setdefault(refto, []).extend(refs)
if refto in seen_models:
sql.extend(connection.creation.sql_for_pending_references(refto, self.style, pending_references))
sql.extend(connection.creation.sql_for_pending_references(model, self.style, pending_references))
if verbosity >= 1 and sql:
print "Creating table %s" % model._meta.db_table
for statement in sql:
cursor.execute(statement)
tables.append(connection.introspection.table_name_converter(model._meta.db_table))
transaction.commit_unless_managed(using=db)
# Send the post_syncdb signal, so individual apps can do whatever they need
# to do at this point.
emit_post_sync_signal(created_models, verbosity, interactive, db)
# The connection may have been closed by a syncdb handler.
cursor = connection.cursor()
# Install custom SQL for the app (but only if this
# is a model we've just created)
if verbosity >= 1:
print "Installing custom SQL ..."
for app_name, model_list in manifest.items():
for model in model_list:
if model in created_models:
custom_sql = custom_sql_for_model(model, self.style, connection)
if custom_sql:
if verbosity >= 2:
print "Installing custom SQL for %s.%s model" % (app_name, model._meta.object_name)
try:
for sql in custom_sql:
cursor.execute(sql)
except Exception, e:
sys.stderr.write("Failed to install custom SQL for %s.%s model: %s\n" % \
(app_name, model._meta.object_name, e))
if show_traceback:
import traceback
traceback.print_exc()
transaction.rollback_unless_managed(using=db)
else:
transaction.commit_unless_managed(using=db)
else:
if verbosity >= 3:
print "No custom SQL for %s.%s model" % (app_name, model._meta.object_name)
if verbosity >= 1:
print "Installing indexes ..."
# Install SQL indicies for all newly created models
for app_name, model_list in manifest.items():
for model in model_list:
if model in created_models:
index_sql = connection.creation.sql_indexes_for_model(model, self.style)
if index_sql:
if verbosity >= 2:
print "Installing index for %s.%s model" % (app_name, model._meta.object_name)
try:
for sql in index_sql:
cursor.execute(sql)
except Exception, e:
sys.stderr.write("Failed to install index for %s.%s model: %s\n" % \
(app_name, model._meta.object_name, e))
transaction.rollback_unless_managed(using=db)
else:
transaction.commit_unless_managed(using=db)
# Load initial_data fixtures (unless that has been disabled)
if load_initial_data:
from django.core.management import call_command
call_command('loaddata', 'initial_data', verbosity=verbosity, database=db)
|
bsd-3-clause
|
[
504,
8691,
492,
1852,
63,
1422,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
3091,
6213,
3110,
199,
504,
1639,
14,
1018,
14,
8110,
14,
2326,
492,
949,
63,
2487,
199,
504,
1639,
14,
1018,
14,
8110,
14,
3009,
492,
3537,
63,
3009,
63,
509,
63,
1238,
12,
8689,
63,
1932,
63,
5186,
63,
4653,
199,
504,
1639,
14,
697,
492,
6947,
12,
6197,
12,
6008,
12,
1709,
12,
6186,
63,
2846,
63,
12644,
199,
504,
1639,
14,
1208,
14,
23004,
492,
27432,
2141,
199,
504,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
421,
199,
533,
5817,
8,
27099,
3110,
304,
272,
945,
63,
513,
275,
3091,
6213,
3110,
14,
1422,
63,
513,
435,
334,
267,
1852,
63,
1422,
4517,
889,
1210,
297,
1595,
534,
1617,
63,
3910,
297,
2053,
534,
13543,
297,
849,
29,
549,
12,
288,
1720,
534,
52,
6840,
5634,
370,
2845,
8457,
314,
922,
367,
1324,
402,
1263,
4928,
8038,
267,
1852,
63,
1422,
4517,
4659,
297,
1595,
534,
1617,
297,
2053,
534,
4659,
297,
288,
849,
29,
3472,
63,
2846,
63,
12644,
12,
1720,
534,
46,
676,
262,
2335,
282,
3050,
370,
31021,
14,
283,
355,
283,
16986,
370,
314,
298,
885,
2,
3050,
8038,
272,
776,
272,
1720,
275,
298,
2499,
314,
3050,
6716,
367,
1006,
8686,
315,
31061,
63,
14219,
7447,
6716,
19051,
1133,
2575,
2757,
2737,
2122,
339,
347,
2429,
63,
889,
589,
8,
277,
12,
1011,
1419,
304,
398,
8661,
275,
1109,
8,
1419,
14,
362,
360,
9833,
297,
413,
430,
267,
12777,
275,
1511,
14,
362,
360,
13543,
358,
267,
2498,
63,
6894,
275,
1511,
14,
362,
360,
6894,
297,
756,
9,
398,
327,
17854,
6130,
945,
1553,
283,
912,
63,
2747,
63,
576,
7,
365,
1202,
701,
314,
5343,
3272,
267,
327,
2112,
370,
3507,
2536,
10949,
8697,
14,
267,
2248,
63,
2747,
63,
576,
275,
1511,
14,
362,
360,
912,
63,
2747,
63,
576,
297,
715,
9,
398,
291,
14,
2487,
275,
949,
63,
2487,
342,
398,
327,
3161,
314,
283,
8110,
7,
859,
4453,
1924,
4903,
1145,
12,
370,
2274,
267,
327,
17475,
4474,
14,
267,
367,
1145,
63,
354,
315,
2202,
14,
15942,
63,
14219,
26,
288,
862,
26,
355,
492,
63,
578,
5175,
8110,
297,
1145,
63,
354,
9,
288,
871,
3545,
12,
3178,
26,
355,
327,
961,
365,
18023,
11176,
2453,
14,
2136,
2934,
370,
3686,
3545,
83,
355,
327,
340,
314,
298,
8110,
2,
859,
6337,
365,
4124,
1553,
1325,
781,
2793,
1133,
355,
327,
2934,
370,
3686,
314,
1919,
340,
314,
10041,
859,
3495,
355,
327,
1325,
6534,
376,
3545,
367,
2005,
4499,
14,
710,
1454,
4340,
781,
355,
327,
883,
886,
642,
365,
370,
1104,
314,
1318,
402,
314,
1919,
14,
3390,
626,
355,
327,
781,
3984,
282,
4546,
330,
5063,
315,
4212,
781,
1104,
314,
1318,
12,
2952,
3365,
355,
327,
2018,
12591,
1443,
440,
675,
314,
2011,
1318,
14,
355,
327,
25654,
4440,
314,
1318,
298,
1944,
859,
4310,
10041,
2,
355,
327,
1611,
2713,
4440,
298,
1944,
859,
4310,
3002,
1715,
14,
1662,
571,
14,
8110,
2,
355,
1499,
275,
3178,
14,
589,
59,
16,
61,
355,
340,
440,
1499,
14,
2460,
360,
1944,
859,
4310,
358,
503,
283,
8110,
7,
440,
315,
1499,
26,
490,
746,
398,
1592,
275,
1511,
14,
362,
360,
4659,
297,
6186,
63,
2846,
63,
12644,
9,
267,
1950,
275,
6947,
59,
697,
61,
267,
3920,
275,
1950,
14,
3937,
342,
398,
327,
2372,
282,
769,
402,
2575,
4903,
627,
992,
10,
880,
626,
6941,
1736,
2451,
14,
267,
6716,
275,
1950,
14,
21627,
14,
1224,
63,
1247,
342,
267,
6775,
63,
992,
275,
1950,
14,
21627,
14,
7657,
63,
992,
8,
5987,
9,
267,
2737,
63,
992,
275,
663,
342,
267,
9413,
63,
12635,
275,
1052,
398,
327,
6516,
314,
7712,
402,
8686,
436,
1709,
626,
787,
370,
506,
15354,
1759,
267,
1006,
63,
992,
275,
359,
288,
334,
571,
855,
354,
4343,
1294,
29084,
18,
467,
355,
359,
77,
367,
333,
315,
1709,
14,
362,
63,
992,
8,
571,
12,
2387,
63,
2495,
63,
3966,
29,
549,
9,
355,
340,
6197,
14,
3306,
63,
5186,
697,
8,
697,
12,
333,
3948,
288,
367,
1145,
315,
1709,
14,
362,
63,
5181,
342,
267,
1622,
267,
347,
1402,
63,
7657,
8,
1238,
304,
288,
3999,
275,
1402,
423,
2024,
288,
11109,
275,
1950,
14,
21627,
14,
1224,
63,
354,
63,
11256,
288,
372,
440,
3666,
11256,
8,
3291,
14,
697,
63,
1224,
9,
315,
6716,
9,
503,
355,
334,
3291,
14,
2495,
63,
3966,
436,
11109,
8,
3291,
14,
2495,
63,
3966,
423,
2024,
14,
697,
63,
1224,
9,
315,
6716,
430,
398,
7712,
275,
27432,
2141,
8,
288,
334,
571,
63,
354,
12,
2457,
8,
1238,
63,
7657,
12,
1402,
63,
513,
430,
288,
367,
1145,
63,
354,
12,
1402,
63,
513,
315,
1006,
63,
992,
267,
776,
398,
327,
2790,
314,
6716,
367,
1924,
1402,
267,
340,
8661,
2356,
413,
26,
288,
870,
298,
14380,
6716,
21742,
267,
367,
1145,
63,
354,
12,
1402,
63,
513,
315,
7712,
14,
1744,
837,
288,
367,
1402,
315,
1402,
63,
513,
26,
355,
327,
2790,
314,
1402,
1159,
3050,
1817,
12,
340,
652,
3181,
1133,
2575,
2187,
14,
355,
340,
8661,
2356,
650,
26,
490,
870,
298,
9589,
450,
83,
4111,
83,
1402,
2,
450,
334,
571,
63,
354,
12,
1402,
423,
2024,
14,
785,
63,
354,
9,
355,
3875,
12,
6941,
275,
1950,
14,
8782,
14,
3009,
63,
981,
63,
1238,
8,
1238,
12,
291,
14,
2487,
12,
6775,
63,
992,
9,
355,
6775,
63,
992,
14,
525,
8,
1238,
9,
355,
2737,
63,
992,
14,
525,
8,
1238,
9,
355,
367,
2984,
475,
12,
15749,
315,
6941,
14,
1744,
837,
490,
9413,
63,
12635,
14,
5486,
8,
1121,
475,
12,
15364,
2880,
8,
7655,
9,
490,
340,
2984,
475,
315,
6775,
63,
992,
26,
717,
3875,
14,
2880,
8,
2105,
14,
8782,
14,
3009,
63,
509,
63,
6455,
63,
12635,
8,
1121,
475,
12,
291,
14,
2487,
12,
9413,
63,
12635,
430,
355,
3875,
14,
2880,
8,
2105,
14,
8782,
14
] |
[
8691,
492,
1852,
63,
1422,
199,
646,
984,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
3091,
6213,
3110,
199,
504,
1639,
14,
1018,
14,
8110,
14,
2326,
492,
949,
63,
2487,
199,
504,
1639,
14,
1018,
14,
8110,
14,
3009,
492,
3537,
63,
3009,
63,
509,
63,
1238,
12,
8689,
63,
1932,
63,
5186,
63,
4653,
199,
504,
1639,
14,
697,
492,
6947,
12,
6197,
12,
6008,
12,
1709,
12,
6186,
63,
2846,
63,
12644,
199,
504,
1639,
14,
1208,
14,
23004,
492,
27432,
2141,
199,
504,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
421,
199,
533,
5817,
8,
27099,
3110,
304,
272,
945,
63,
513,
275,
3091,
6213,
3110,
14,
1422,
63,
513,
435,
334,
267,
1852,
63,
1422,
4517,
889,
1210,
297,
1595,
534,
1617,
63,
3910,
297,
2053,
534,
13543,
297,
849,
29,
549,
12,
288,
1720,
534,
52,
6840,
5634,
370,
2845,
8457,
314,
922,
367,
1324,
402,
1263,
4928,
8038,
267,
1852,
63,
1422,
4517,
4659,
297,
1595,
534,
1617,
297,
2053,
534,
4659,
297,
288,
849,
29,
3472,
63,
2846,
63,
12644,
12,
1720,
534,
46,
676,
262,
2335,
282,
3050,
370,
31021,
14,
283,
355,
283,
16986,
370,
314,
298,
885,
2,
3050,
8038,
272,
776,
272,
1720,
275,
298,
2499,
314,
3050,
6716,
367,
1006,
8686,
315,
31061,
63,
14219,
7447,
6716,
19051,
1133,
2575,
2757,
2737,
2122,
339,
347,
2429,
63,
889,
589,
8,
277,
12,
1011,
1419,
304,
398,
8661,
275,
1109,
8,
1419,
14,
362,
360,
9833,
297,
413,
430,
267,
12777,
275,
1511,
14,
362,
360,
13543,
358,
267,
2498,
63,
6894,
275,
1511,
14,
362,
360,
6894,
297,
756,
9,
398,
327,
17854,
6130,
945,
1553,
283,
912,
63,
2747,
63,
576,
7,
365,
1202,
701,
314,
5343,
3272,
267,
327,
2112,
370,
3507,
2536,
10949,
8697,
14,
267,
2248,
63,
2747,
63,
576,
275,
1511,
14,
362,
360,
912,
63,
2747,
63,
576,
297,
715,
9,
398,
291,
14,
2487,
275,
949,
63,
2487,
342,
398,
327,
3161,
314,
283,
8110,
7,
859,
4453,
1924,
4903,
1145,
12,
370,
2274,
267,
327,
17475,
4474,
14,
267,
367,
1145,
63,
354,
315,
2202,
14,
15942,
63,
14219,
26,
288,
862,
26,
355,
492,
63,
578,
5175,
8110,
297,
1145,
63,
354,
9,
288,
871,
3545,
12,
3178,
26,
355,
327,
961,
365,
18023,
11176,
2453,
14,
2136,
2934,
370,
3686,
3545,
83,
355,
327,
340,
314,
298,
8110,
2,
859,
6337,
365,
4124,
1553,
1325,
781,
2793,
1133,
355,
327,
2934,
370,
3686,
314,
1919,
340,
314,
10041,
859,
3495,
355,
327,
1325,
6534,
376,
3545,
367,
2005,
4499,
14,
710,
1454,
4340,
781,
355,
327,
883,
886,
642,
365,
370,
1104,
314,
1318,
402,
314,
1919,
14,
3390,
626,
355,
327,
781,
3984,
282,
4546,
330,
5063,
315,
4212,
781,
1104,
314,
1318,
12,
2952,
3365,
355,
327,
2018,
12591,
1443,
440,
675,
314,
2011,
1318,
14,
355,
327,
25654,
4440,
314,
1318,
298,
1944,
859,
4310,
10041,
2,
355,
327,
1611,
2713,
4440,
298,
1944,
859,
4310,
3002,
1715,
14,
1662,
571,
14,
8110,
2,
355,
1499,
275,
3178,
14,
589,
59,
16,
61,
355,
340,
440,
1499,
14,
2460,
360,
1944,
859,
4310,
358,
503,
283,
8110,
7,
440,
315,
1499,
26,
490,
746,
398,
1592,
275,
1511,
14,
362,
360,
4659,
297,
6186,
63,
2846,
63,
12644,
9,
267,
1950,
275,
6947,
59,
697,
61,
267,
3920,
275,
1950,
14,
3937,
342,
398,
327,
2372,
282,
769,
402,
2575,
4903,
627,
992,
10,
880,
626,
6941,
1736,
2451,
14,
267,
6716,
275,
1950,
14,
21627,
14,
1224,
63,
1247,
342,
267,
6775,
63,
992,
275,
1950,
14,
21627,
14,
7657,
63,
992,
8,
5987,
9,
267,
2737,
63,
992,
275,
663,
342,
267,
9413,
63,
12635,
275,
1052,
398,
327,
6516,
314,
7712,
402,
8686,
436,
1709,
626,
787,
370,
506,
15354,
1759,
267,
1006,
63,
992,
275,
359,
288,
334,
571,
855,
354,
4343,
1294,
29084,
18,
467,
355,
359,
77,
367,
333,
315,
1709,
14,
362,
63,
992,
8,
571,
12,
2387,
63,
2495,
63,
3966,
29,
549,
9,
355,
340,
6197,
14,
3306,
63,
5186,
697,
8,
697,
12,
333,
3948,
288,
367,
1145,
315,
1709,
14,
362,
63,
5181,
342,
267,
1622,
267,
347,
1402,
63,
7657,
8,
1238,
304,
288,
3999,
275,
1402,
423,
2024,
288,
11109,
275,
1950,
14,
21627,
14,
1224,
63,
354,
63,
11256,
288,
372,
440,
3666,
11256,
8,
3291,
14,
697,
63,
1224,
9,
315,
6716,
9,
503,
355,
334,
3291,
14,
2495,
63,
3966,
436,
11109,
8,
3291,
14,
2495,
63,
3966,
423,
2024,
14,
697,
63,
1224,
9,
315,
6716,
430,
398,
7712,
275,
27432,
2141,
8,
288,
334,
571,
63,
354,
12,
2457,
8,
1238,
63,
7657,
12,
1402,
63,
513,
430,
288,
367,
1145,
63,
354,
12,
1402,
63,
513,
315,
1006,
63,
992,
267,
776,
398,
327,
2790,
314,
6716,
367,
1924,
1402,
267,
340,
8661,
2356,
413,
26,
288,
870,
298,
14380,
6716,
21742,
267,
367,
1145,
63,
354,
12,
1402,
63,
513,
315,
7712,
14,
1744,
837,
288,
367,
1402,
315,
1402,
63,
513,
26,
355,
327,
2790,
314,
1402,
1159,
3050,
1817,
12,
340,
652,
3181,
1133,
2575,
2187,
14,
355,
340,
8661,
2356,
650,
26,
490,
870,
298,
9589,
450,
83,
4111,
83,
1402,
2,
450,
334,
571,
63,
354,
12,
1402,
423,
2024,
14,
785,
63,
354,
9,
355,
3875,
12,
6941,
275,
1950,
14,
8782,
14,
3009,
63,
981,
63,
1238,
8,
1238,
12,
291,
14,
2487,
12,
6775,
63,
992,
9,
355,
6775,
63,
992,
14,
525,
8,
1238,
9,
355,
2737,
63,
992,
14,
525,
8,
1238,
9,
355,
367,
2984,
475,
12,
15749,
315,
6941,
14,
1744,
837,
490,
9413,
63,
12635,
14,
5486,
8,
1121,
475,
12,
15364,
2880,
8,
7655,
9,
490,
340,
2984,
475,
315,
6775,
63,
992,
26,
717,
3875,
14,
2880,
8,
2105,
14,
8782,
14,
3009,
63,
509,
63,
6455,
63,
12635,
8,
1121,
475,
12,
291,
14,
2487,
12,
9413,
63,
12635,
430,
355,
3875,
14,
2880,
8,
2105,
14,
8782,
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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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
] |
fangxingli/hue
|
desktop/core/ext-py/Django-1.6.10/django/contrib/gis/db/backends/spatialite/operations.py
|
47
|
15372
|
import re
import sys
from decimal import Decimal
from django.contrib.gis.db.backends.base import BaseSpatialOperations
from django.contrib.gis.db.backends.util import SpatialOperation, SpatialFunction
from django.contrib.gis.db.backends.spatialite.adapter import SpatiaLiteAdapter
from django.contrib.gis.geometry.backend import Geometry
from django.contrib.gis.measure import Distance
from django.core.exceptions import ImproperlyConfigured
from django.db.backends.sqlite3.base import DatabaseOperations
from django.db.utils import DatabaseError
from django.utils import six
from django.utils.functional import cached_property
class SpatiaLiteOperator(SpatialOperation):
"For SpatiaLite operators (e.g. `&&`, `~`)."
def __init__(self, operator):
super(SpatiaLiteOperator, self).__init__(operator=operator)
class SpatiaLiteFunction(SpatialFunction):
"For SpatiaLite function calls."
def __init__(self, function, **kwargs):
super(SpatiaLiteFunction, self).__init__(function, **kwargs)
class SpatiaLiteFunctionParam(SpatiaLiteFunction):
"For SpatiaLite functions that take another parameter."
sql_template = '%(function)s(%(geo_col)s, %(geometry)s, %%s)'
class SpatiaLiteDistance(SpatiaLiteFunction):
"For SpatiaLite distance operations."
dist_func = 'Distance'
sql_template = '%(function)s(%(geo_col)s, %(geometry)s) %(operator)s %%s'
def __init__(self, operator):
super(SpatiaLiteDistance, self).__init__(self.dist_func,
operator=operator)
class SpatiaLiteRelate(SpatiaLiteFunctionParam):
"For SpatiaLite Relate(<geom>, <pattern>) calls."
pattern_regex = re.compile(r'^[012TF\*]{9}$')
def __init__(self, pattern):
if not self.pattern_regex.match(pattern):
raise ValueError('Invalid intersection matrix pattern "%s".' % pattern)
super(SpatiaLiteRelate, self).__init__('Relate')
# Valid distance types and substitutions
dtypes = (Decimal, Distance, float) + six.integer_types
def get_dist_ops(operator):
"Returns operations for regular distances; spherical distances are not currently supported."
return (SpatiaLiteDistance(operator),)
class SpatiaLiteOperations(DatabaseOperations, BaseSpatialOperations):
compiler_module = 'django.contrib.gis.db.models.sql.compiler'
name = 'spatialite'
spatialite = True
version_regex = re.compile(r'^(?P<major>\d)\.(?P<minor1>\d)\.(?P<minor2>\d+)')
valid_aggregates = dict([(k, None) for k in ('Extent', 'Union')])
Adapter = SpatiaLiteAdapter
Adaptor = Adapter # Backwards-compatibility alias.
area = 'Area'
centroid = 'Centroid'
contained = 'MbrWithin'
difference = 'Difference'
distance = 'Distance'
envelope = 'Envelope'
intersection = 'Intersection'
length = 'GLength' # OpenGis defines Length, but this conflicts with an SQLite reserved keyword
num_geom = 'NumGeometries'
num_points = 'NumPoints'
point_on_surface = 'PointOnSurface'
scale = 'ScaleCoords'
svg = 'AsSVG'
sym_difference = 'SymDifference'
transform = 'Transform'
translate = 'ShiftCoords'
union = 'GUnion' # OpenGis defines Union, but this conflicts with an SQLite reserved keyword
unionagg = 'GUnion'
from_text = 'GeomFromText'
from_wkb = 'GeomFromWKB'
select = 'AsText(%s)'
geometry_functions = {
'equals' : SpatiaLiteFunction('Equals'),
'disjoint' : SpatiaLiteFunction('Disjoint'),
'touches' : SpatiaLiteFunction('Touches'),
'crosses' : SpatiaLiteFunction('Crosses'),
'within' : SpatiaLiteFunction('Within'),
'overlaps' : SpatiaLiteFunction('Overlaps'),
'contains' : SpatiaLiteFunction('Contains'),
'intersects' : SpatiaLiteFunction('Intersects'),
'relate' : (SpatiaLiteRelate, six.string_types),
# Returns true if B's bounding box completely contains A's bounding box.
'contained' : SpatiaLiteFunction('MbrWithin'),
# Returns true if A's bounding box completely contains B's bounding box.
'bbcontains' : SpatiaLiteFunction('MbrContains'),
# Returns true if A's bounding box overlaps B's bounding box.
'bboverlaps' : SpatiaLiteFunction('MbrOverlaps'),
# These are implemented here as synonyms for Equals
'same_as' : SpatiaLiteFunction('Equals'),
'exact' : SpatiaLiteFunction('Equals'),
}
distance_functions = {
'distance_gt' : (get_dist_ops('>'), dtypes),
'distance_gte' : (get_dist_ops('>='), dtypes),
'distance_lt' : (get_dist_ops('<'), dtypes),
'distance_lte' : (get_dist_ops('<='), dtypes),
}
geometry_functions.update(distance_functions)
def __init__(self, connection):
super(DatabaseOperations, self).__init__(connection)
# Creating the GIS terms dictionary.
self.gis_terms = set(['isnull'])
self.gis_terms.update(self.geometry_functions)
@cached_property
def spatial_version(self):
"""Determine the version of the SpatiaLite library."""
try:
version = self.spatialite_version_tuple()[1:]
except Exception as msg:
new_msg = (
'Cannot determine the SpatiaLite version for the "%s" '
'database (error was "%s"). Was the SpatiaLite initialization '
'SQL loaded on this database?') % (self.connection.settings_dict['NAME'], msg)
six.reraise(ImproperlyConfigured, ImproperlyConfigured(new_msg), sys.exc_info()[2])
if version < (2, 3, 0):
raise ImproperlyConfigured('GeoDjango only supports SpatiaLite versions '
'2.3.0 and above')
return version
@property
def _version_greater_2_4_0_rc4(self):
if self.spatial_version >= (2, 4, 1):
return True
elif self.spatial_version < (2, 4, 0):
return False
else:
# Spatialite 2.4.0-RC4 added AsGML and AsKML, however both
# RC2 (shipped in popular Debian/Ubuntu packages) and RC4
# report version as '2.4.0', so we fall back to feature detection
try:
self._get_spatialite_func("AsGML(GeomFromText('POINT(1 1)'))")
except DatabaseError:
return False
return True
@cached_property
def gml(self):
return 'AsGML' if self._version_greater_2_4_0_rc4 else None
@cached_property
def kml(self):
return 'AsKML' if self._version_greater_2_4_0_rc4 else None
@cached_property
def geojson(self):
return 'AsGeoJSON' if self.spatial_version >= (3, 0, 0) else None
def check_aggregate_support(self, aggregate):
"""
Checks if the given aggregate name is supported (that is, if it's
in `self.valid_aggregates`).
"""
super(SpatiaLiteOperations, self).check_aggregate_support(aggregate)
agg_name = aggregate.__class__.__name__
return agg_name in self.valid_aggregates
def convert_geom(self, wkt, geo_field):
"""
Converts geometry WKT returned from a SpatiaLite aggregate.
"""
if wkt:
return Geometry(wkt, geo_field.srid)
else:
return None
def geo_db_type(self, f):
"""
Returns None because geometry columnas are added via the
`AddGeometryColumn` stored procedure on SpatiaLite.
"""
return None
def get_distance(self, f, value, lookup_type):
"""
Returns the distance parameters for the given geometry field,
lookup value, and lookup type. SpatiaLite only supports regular
cartesian-based queries (no spheroid/sphere calculations for point
geometries like PostGIS).
"""
if not value:
return []
value = value[0]
if isinstance(value, Distance):
if f.geodetic(self.connection):
raise ValueError('SpatiaLite does not support distance queries on '
'geometry fields with a geodetic coordinate system. '
'Distance objects; use a numeric value of your '
'distance in degrees instead.')
else:
dist_param = getattr(value, Distance.unit_attname(f.units_name(self.connection)))
else:
dist_param = value
return [dist_param]
def get_geom_placeholder(self, f, value):
"""
Provides a proper substitution value for Geometries that are not in the
SRID of the field. Specifically, this routine will substitute in the
Transform() and GeomFromText() function call(s).
"""
def transform_value(value, srid):
return not (value is None or value.srid == srid)
if hasattr(value, 'expression'):
if transform_value(value, f.srid):
placeholder = '%s(%%s, %s)' % (self.transform, f.srid)
else:
placeholder = '%s'
# No geometry value used for F expression, substitue in
# the column name instead.
return placeholder % self.get_expression_column(value)
else:
if transform_value(value, f.srid):
# Adding Transform() to the SQL placeholder.
return '%s(%s(%%s,%s), %s)' % (self.transform, self.from_text, value.srid, f.srid)
else:
return '%s(%%s,%s)' % (self.from_text, f.srid)
def _get_spatialite_func(self, func):
"""
Helper routine for calling SpatiaLite functions and returning
their result.
"""
cursor = self.connection._cursor()
try:
try:
cursor.execute('SELECT %s' % func)
row = cursor.fetchone()
except:
# Responsibility of caller to perform error handling.
raise
finally:
cursor.close()
return row[0]
def geos_version(self):
"Returns the version of GEOS used by SpatiaLite as a string."
return self._get_spatialite_func('geos_version()')
def proj4_version(self):
"Returns the version of the PROJ.4 library used by SpatiaLite."
return self._get_spatialite_func('proj4_version()')
def spatialite_version(self):
"Returns the SpatiaLite library version as a string."
return self._get_spatialite_func('spatialite_version()')
def spatialite_version_tuple(self):
"""
Returns the SpatiaLite version as a tuple (version string, major,
minor, subminor).
"""
# Getting the SpatiaLite version.
try:
version = self.spatialite_version()
except DatabaseError:
# The `spatialite_version` function first appeared in version 2.3.1
# of SpatiaLite, so doing a fallback test for 2.3.0 (which is
# used by popular Debian/Ubuntu packages).
version = None
try:
tmp = self._get_spatialite_func("X(GeomFromText('POINT(1 1)'))")
if tmp == 1.0: version = '2.3.0'
except DatabaseError:
pass
# If no version string defined, then just re-raise the original
# exception.
if version is None: raise
m = self.version_regex.match(version)
if m:
major = int(m.group('major'))
minor1 = int(m.group('minor1'))
minor2 = int(m.group('minor2'))
else:
raise Exception('Could not parse SpatiaLite version string: %s' % version)
return (version, major, minor1, minor2)
def spatial_aggregate_sql(self, agg):
"""
Returns the spatial aggregate SQL template and function for the
given Aggregate instance.
"""
agg_name = agg.__class__.__name__
if not self.check_aggregate_support(agg):
raise NotImplementedError('%s spatial aggregate is not implmented for this backend.' % agg_name)
agg_name = agg_name.lower()
if agg_name == 'union': agg_name += 'agg'
sql_template = self.select % '%(function)s(%(field)s)'
sql_function = getattr(self, agg_name)
return sql_template, sql_function
def spatial_lookup_sql(self, lvalue, lookup_type, value, field, qn):
"""
Returns the SpatiaLite-specific SQL for the given lookup value
[a tuple of (alias, column, db_type)], lookup type, lookup
value, the model field, and the quoting function.
"""
alias, col, db_type = lvalue
# Getting the quoted field as `geo_col`.
geo_col = '%s.%s' % (qn(alias), qn(col))
if lookup_type in self.geometry_functions:
# See if a SpatiaLite geometry function matches the lookup type.
tmp = self.geometry_functions[lookup_type]
# Lookup types that are tuples take tuple arguments, e.g., 'relate' and
# distance lookups.
if isinstance(tmp, tuple):
# First element of tuple is the SpatiaLiteOperation instance, and the
# second element is either the type or a tuple of acceptable types
# that may passed in as further parameters for the lookup type.
op, arg_type = tmp
# Ensuring that a tuple _value_ was passed in from the user
if not isinstance(value, (tuple, list)):
raise ValueError('Tuple required for `%s` lookup type.' % lookup_type)
# Geometry is first element of lookup tuple.
geom = value[0]
# Number of valid tuple parameters depends on the lookup type.
if len(value) != 2:
raise ValueError('Incorrect number of parameters given for `%s` lookup type.' % lookup_type)
# Ensuring the argument type matches what we expect.
if not isinstance(value[1], arg_type):
raise ValueError('Argument type should be %s, got %s instead.' % (arg_type, type(value[1])))
# For lookup type `relate`, the op instance is not yet created (has
# to be instantiated here to check the pattern parameter).
if lookup_type == 'relate':
op = op(value[1])
elif lookup_type in self.distance_functions:
op = op[0]
else:
op = tmp
geom = value
# Calling the `as_sql` function on the operation instance.
return op.as_sql(geo_col, self.get_geom_placeholder(field, geom))
elif lookup_type == 'isnull':
# Handling 'isnull' lookup type
return "%s IS %sNULL" % (geo_col, ('' if value else 'NOT ')), []
raise TypeError("Got invalid lookup_type: %s" % repr(lookup_type))
# Routines for getting the OGC-compliant models.
def geometry_columns(self):
from django.contrib.gis.db.backends.spatialite.models import GeometryColumns
return GeometryColumns
def spatial_ref_sys(self):
from django.contrib.gis.db.backends.spatialite.models import SpatialRefSys
return SpatialRefSys
|
apache-2.0
|
[
646,
295,
199,
646,
984,
199,
504,
6107,
492,
6345,
199,
199,
504,
1639,
14,
2828,
14,
5668,
14,
697,
14,
7765,
14,
1095,
492,
3523,
18075,
12929,
199,
504,
1639,
14,
2828,
14,
5668,
14,
697,
14,
7765,
14,
1974,
492,
13423,
6044,
12,
13423,
3481,
199,
504,
1639,
14,
2828,
14,
5668,
14,
697,
14,
7765,
14,
25873,
14,
10394,
492,
25177,
10200,
199,
504,
1639,
14,
2828,
14,
5668,
14,
7660,
14,
4620,
492,
10579,
199,
504,
1639,
14,
2828,
14,
5668,
14,
9580,
492,
21892,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
697,
14,
7765,
14,
10659,
19,
14,
1095,
492,
8692,
12929,
199,
504,
1639,
14,
697,
14,
1208,
492,
27728,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
421,
199,
533,
25177,
7961,
8,
18075,
6044,
304,
272,
298,
1858,
25177,
10211,
334,
69,
14,
71,
14,
658,
12574,
3559,
28157,
14963,
2,
272,
347,
636,
826,
721,
277,
12,
4182,
304,
267,
1613,
8,
12739,
23675,
7961,
12,
291,
2843,
826,
721,
3856,
29,
3856,
9,
199,
199,
533,
25177,
3481,
8,
18075,
3481,
304,
272,
298,
1858,
25177,
805,
4882,
2122,
272,
347,
636,
826,
721,
277,
12,
805,
12,
1011,
958,
304,
267,
1613,
8,
12739,
23675,
3481,
12,
291,
2843,
826,
721,
1593,
12,
1011,
958,
9,
199,
199,
533,
25177,
3481,
4098,
8,
12739,
23675,
3481,
304,
272,
298,
1858,
25177,
3423,
626,
5452,
4573,
2725,
2122,
272,
3875,
63,
1160,
275,
9487,
1593,
9,
83,
12473,
6721,
63,
761,
9,
83,
12,
2818,
7660,
9,
83,
12,
11539,
83,
3171,
199,
199,
533,
25177,
10076,
8,
12739,
23675,
3481,
304,
272,
298,
1858,
25177,
6033,
5331,
2122,
272,
2917,
63,
1532,
275,
283,
10076,
7,
272,
3875,
63,
1160,
275,
9487,
1593,
9,
83,
12473,
6721,
63,
761,
9,
83,
12,
2818,
7660,
9,
83,
9,
2818,
3856,
9,
83,
11539,
83,
7,
339,
347,
636,
826,
721,
277,
12,
4182,
304,
267,
1613,
8,
12739,
23675,
10076,
12,
291,
2843,
826,
721,
277,
14,
2686,
63,
1532,
12,
1740,
4182,
29,
3856,
9,
199,
199,
533,
25177,
5640,
323,
8,
12739,
23675,
3481,
4098,
304,
272,
298,
1858,
25177,
9781,
323,
27530,
6481,
6244,
665,
3401,
18956,
4882,
2122,
272,
3851,
63,
3821,
275,
295,
14,
2014,
8,
82,
23811,
11533,
6145,
60,
10,
8194,
25,
93,
9988,
272,
347,
636,
826,
721,
277,
12,
3851,
304,
267,
340,
440,
291,
14,
3401,
63,
3821,
14,
1431,
8,
3401,
304,
288,
746,
1722,
360,
3364,
16223,
3634,
3851,
2071,
83,
24217,
450,
3851,
9,
267,
1613,
8,
12739,
23675,
5640,
323,
12,
291,
2843,
826,
19734,
5640,
323,
358,
199,
199,
3,
4821,
6033,
2943,
436,
20873,
199,
5717,
275,
334,
6745,
12,
21892,
12,
2069,
9,
435,
3816,
14,
4115,
63,
1313,
199,
318,
664,
63,
2686,
63,
1483,
8,
3856,
304,
272,
298,
3407,
5331,
367,
5578,
15108,
27,
308,
27058,
15108,
787,
440,
5544,
3748,
2122,
272,
372,
334,
12739,
23675,
10076,
8,
3856,
16945,
199,
199,
533,
25177,
12929,
8,
7243,
12929,
12,
3523,
18075,
12929,
304,
272,
6365,
63,
578,
275,
283,
1176,
14,
2828,
14,
5668,
14,
697,
14,
992,
14,
3009,
14,
5772,
7,
272,
536,
275,
283,
25873,
7,
272,
11469,
1175,
275,
715,
272,
1015,
63,
3821,
275,
295,
14,
2014,
8,
82,
24550,
48,
28,
8452,
3072,
68,
31477,
2229,
48,
28,
11067,
17,
3072,
68,
31477,
2229,
48,
28,
11067,
18,
3072,
68,
11,
5942,
272,
1686,
63,
21622,
275,
1211,
7694,
75,
12,
488,
9,
367,
1022,
315,
661,
19808,
297,
283,
15540,
2023,
339,
4431,
4185,
275,
25177,
10200,
272,
4431,
6182,
269,
275,
4431,
4185,
327,
10257,
4751,
13,
15390,
5162,
14,
339,
9150,
275,
283,
11043,
7,
272,
27587,
275,
283,
22744,
3977,
7,
272,
10470,
275,
283,
45,
3289,
3007,
262,
7,
272,
8865,
275,
283,
32279,
7,
272,
6033,
275,
283,
10076,
7,
272,
24631,
275,
283,
28278,
7,
272,
16223,
275,
283,
29821,
7,
272,
2582,
275,
283,
2226,
287,
997,
7,
327,
3232,
39,
374,
7890,
19893,
12,
1325,
642,
18511,
543,
376,
19245,
4644,
4252,
272,
1967,
63,
6481,
275,
283,
5667,
4240,
14100,
7,
272,
1967,
63,
3438,
275,
283,
5667,
10225,
7,
272,
2376,
63,
265,
63,
10992,
275,
283,
3428,
3314,
16923,
7,
272,
4666,
275,
283,
9944,
29734,
7,
272,
21218,
275,
283,
2822,
19366,
7,
272,
4678,
63,
9196,
275,
283,
16594,
32279,
7,
272,
5793,
275,
283,
6939,
7,
272,
9028,
275,
283,
14379,
29734,
7,
272,
13629,
275,
283,
39,
15540,
7,
327,
3232,
39,
374,
7890,
15961,
12,
1325,
642,
18511,
543,
376,
19245,
4644,
4252,
272,
13629,
13452,
275,
283,
39,
15540,
7,
339,
687,
63,
505,
275,
283,
13427,
2532,
1872,
7,
272,
687,
63,
18914,
275,
283,
13427,
2532,
28328,
7,
272,
3504,
275,
283,
2822,
1872,
4042,
83,
3171,
339,
3400,
63,
5777,
275,
469,
267,
283,
11332,
7,
520,
25177,
3481,
360,
13317,
659,
267,
283,
31880,
7,
520,
25177,
3481,
360,
2825,
10153,
659,
267,
283,
12376,
397,
7,
520,
25177,
3481,
360,
52,
810,
12253,
659,
267,
283,
20363,
874,
7,
520,
25177,
3481,
360,
35,
4796,
874,
659,
267,
283,
12541,
7,
520,
25177,
3481,
360,
3007,
262,
659,
267,
283,
20798,
7,
520,
25177,
3481,
360,
5674,
13719,
659,
267,
283,
6134,
7,
520,
25177,
3481,
360,
6906,
659,
267,
283,
1058,
25353,
7,
520,
25177,
3481,
360,
2620,
25353,
659,
267,
283,
17322,
7,
520,
334,
12739,
23675,
5640,
323,
12,
3816,
14,
875,
63,
1313,
395,
267,
327,
1803,
2549,
340,
699,
1159,
16842,
5689,
14793,
3509,
437,
1159,
16842,
5689,
14,
267,
283,
30288,
7,
520,
25177,
3481,
360,
45,
3289,
3007,
262,
659,
267,
327,
1803,
2549,
340,
437,
1159,
16842,
5689,
14793,
3509,
699,
1159,
16842,
5689,
14,
267,
283,
2501,
6134,
7,
520,
25177,
3481,
360,
45,
3289,
6906,
659,
267,
327,
1803,
2549,
340,
437,
1159,
16842,
5689,
29755,
699,
1159,
16842,
5689,
14,
267,
283,
66,
656,
422,
13719,
7
] |
[
295,
199,
646,
984,
199,
504,
6107,
492,
6345,
199,
199,
504,
1639,
14,
2828,
14,
5668,
14,
697,
14,
7765,
14,
1095,
492,
3523,
18075,
12929,
199,
504,
1639,
14,
2828,
14,
5668,
14,
697,
14,
7765,
14,
1974,
492,
13423,
6044,
12,
13423,
3481,
199,
504,
1639,
14,
2828,
14,
5668,
14,
697,
14,
7765,
14,
25873,
14,
10394,
492,
25177,
10200,
199,
504,
1639,
14,
2828,
14,
5668,
14,
7660,
14,
4620,
492,
10579,
199,
504,
1639,
14,
2828,
14,
5668,
14,
9580,
492,
21892,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
697,
14,
7765,
14,
10659,
19,
14,
1095,
492,
8692,
12929,
199,
504,
1639,
14,
697,
14,
1208,
492,
27728,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
421,
199,
533,
25177,
7961,
8,
18075,
6044,
304,
272,
298,
1858,
25177,
10211,
334,
69,
14,
71,
14,
658,
12574,
3559,
28157,
14963,
2,
272,
347,
636,
826,
721,
277,
12,
4182,
304,
267,
1613,
8,
12739,
23675,
7961,
12,
291,
2843,
826,
721,
3856,
29,
3856,
9,
199,
199,
533,
25177,
3481,
8,
18075,
3481,
304,
272,
298,
1858,
25177,
805,
4882,
2122,
272,
347,
636,
826,
721,
277,
12,
805,
12,
1011,
958,
304,
267,
1613,
8,
12739,
23675,
3481,
12,
291,
2843,
826,
721,
1593,
12,
1011,
958,
9,
199,
199,
533,
25177,
3481,
4098,
8,
12739,
23675,
3481,
304,
272,
298,
1858,
25177,
3423,
626,
5452,
4573,
2725,
2122,
272,
3875,
63,
1160,
275,
9487,
1593,
9,
83,
12473,
6721,
63,
761,
9,
83,
12,
2818,
7660,
9,
83,
12,
11539,
83,
3171,
199,
199,
533,
25177,
10076,
8,
12739,
23675,
3481,
304,
272,
298,
1858,
25177,
6033,
5331,
2122,
272,
2917,
63,
1532,
275,
283,
10076,
7,
272,
3875,
63,
1160,
275,
9487,
1593,
9,
83,
12473,
6721,
63,
761,
9,
83,
12,
2818,
7660,
9,
83,
9,
2818,
3856,
9,
83,
11539,
83,
7,
339,
347,
636,
826,
721,
277,
12,
4182,
304,
267,
1613,
8,
12739,
23675,
10076,
12,
291,
2843,
826,
721,
277,
14,
2686,
63,
1532,
12,
1740,
4182,
29,
3856,
9,
199,
199,
533,
25177,
5640,
323,
8,
12739,
23675,
3481,
4098,
304,
272,
298,
1858,
25177,
9781,
323,
27530,
6481,
6244,
665,
3401,
18956,
4882,
2122,
272,
3851,
63,
3821,
275,
295,
14,
2014,
8,
82,
23811,
11533,
6145,
60,
10,
8194,
25,
93,
9988,
272,
347,
636,
826,
721,
277,
12,
3851,
304,
267,
340,
440,
291,
14,
3401,
63,
3821,
14,
1431,
8,
3401,
304,
288,
746,
1722,
360,
3364,
16223,
3634,
3851,
2071,
83,
24217,
450,
3851,
9,
267,
1613,
8,
12739,
23675,
5640,
323,
12,
291,
2843,
826,
19734,
5640,
323,
358,
199,
199,
3,
4821,
6033,
2943,
436,
20873,
199,
5717,
275,
334,
6745,
12,
21892,
12,
2069,
9,
435,
3816,
14,
4115,
63,
1313,
199,
318,
664,
63,
2686,
63,
1483,
8,
3856,
304,
272,
298,
3407,
5331,
367,
5578,
15108,
27,
308,
27058,
15108,
787,
440,
5544,
3748,
2122,
272,
372,
334,
12739,
23675,
10076,
8,
3856,
16945,
199,
199,
533,
25177,
12929,
8,
7243,
12929,
12,
3523,
18075,
12929,
304,
272,
6365,
63,
578,
275,
283,
1176,
14,
2828,
14,
5668,
14,
697,
14,
992,
14,
3009,
14,
5772,
7,
272,
536,
275,
283,
25873,
7,
272,
11469,
1175,
275,
715,
272,
1015,
63,
3821,
275,
295,
14,
2014,
8,
82,
24550,
48,
28,
8452,
3072,
68,
31477,
2229,
48,
28,
11067,
17,
3072,
68,
31477,
2229,
48,
28,
11067,
18,
3072,
68,
11,
5942,
272,
1686,
63,
21622,
275,
1211,
7694,
75,
12,
488,
9,
367,
1022,
315,
661,
19808,
297,
283,
15540,
2023,
339,
4431,
4185,
275,
25177,
10200,
272,
4431,
6182,
269,
275,
4431,
4185,
327,
10257,
4751,
13,
15390,
5162,
14,
339,
9150,
275,
283,
11043,
7,
272,
27587,
275,
283,
22744,
3977,
7,
272,
10470,
275,
283,
45,
3289,
3007,
262,
7,
272,
8865,
275,
283,
32279,
7,
272,
6033,
275,
283,
10076,
7,
272,
24631,
275,
283,
28278,
7,
272,
16223,
275,
283,
29821,
7,
272,
2582,
275,
283,
2226,
287,
997,
7,
327,
3232,
39,
374,
7890,
19893,
12,
1325,
642,
18511,
543,
376,
19245,
4644,
4252,
272,
1967,
63,
6481,
275,
283,
5667,
4240,
14100,
7,
272,
1967,
63,
3438,
275,
283,
5667,
10225,
7,
272,
2376,
63,
265,
63,
10992,
275,
283,
3428,
3314,
16923,
7,
272,
4666,
275,
283,
9944,
29734,
7,
272,
21218,
275,
283,
2822,
19366,
7,
272,
4678,
63,
9196,
275,
283,
16594,
32279,
7,
272,
5793,
275,
283,
6939,
7,
272,
9028,
275,
283,
14379,
29734,
7,
272,
13629,
275,
283,
39,
15540,
7,
327,
3232,
39,
374,
7890,
15961,
12,
1325,
642,
18511,
543,
376,
19245,
4644,
4252,
272,
13629,
13452,
275,
283,
39,
15540,
7,
339,
687,
63,
505,
275,
283,
13427,
2532,
1872,
7,
272,
687,
63,
18914,
275,
283,
13427,
2532,
28328,
7,
272,
3504,
275,
283,
2822,
1872,
4042,
83,
3171,
339,
3400,
63,
5777,
275,
469,
267,
283,
11332,
7,
520,
25177,
3481,
360,
13317,
659,
267,
283,
31880,
7,
520,
25177,
3481,
360,
2825,
10153,
659,
267,
283,
12376,
397,
7,
520,
25177,
3481,
360,
52,
810,
12253,
659,
267,
283,
20363,
874,
7,
520,
25177,
3481,
360,
35,
4796,
874,
659,
267,
283,
12541,
7,
520,
25177,
3481,
360,
3007,
262,
659,
267,
283,
20798,
7,
520,
25177,
3481,
360,
5674,
13719,
659,
267,
283,
6134,
7,
520,
25177,
3481,
360,
6906,
659,
267,
283,
1058,
25353,
7,
520,
25177,
3481,
360,
2620,
25353,
659,
267,
283,
17322,
7,
520,
334,
12739,
23675,
5640,
323,
12,
3816,
14,
875,
63,
1313,
395,
267,
327,
1803,
2549,
340,
699,
1159,
16842,
5689,
14793,
3509,
437,
1159,
16842,
5689,
14,
267,
283,
30288,
7,
520,
25177,
3481,
360,
45,
3289,
3007,
262,
659,
267,
327,
1803,
2549,
340,
437,
1159,
16842,
5689,
14793,
3509,
699,
1159,
16842,
5689,
14,
267,
283,
2501,
6134,
7,
520,
25177,
3481,
360,
45,
3289,
6906,
659,
267,
327,
1803,
2549,
340,
437,
1159,
16842,
5689,
29755,
699,
1159,
16842,
5689,
14,
267,
283,
66,
656,
422,
13719,
7,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
konrad/kufpybio
|
kufpybio/genelistmerger.py
|
1
|
5536
|
import os
import sys
import kufpybio.helpers as helpers
import sqlite3
from kufpybio.gene import Gene
class GeneListMerger(object):
def __init__(self, min_overlap_percentage=None, perform_gene_merging=True):
# This flag influeces the general behavior. It it is set to
# True gene will be merged i.e. the minimal star position
# value and maximum end position taken. If it is False new
# genes that are overlapping with old ones will be discarded.
self._perform_gene_merging = perform_gene_merging
self._min_overlap_percentage = min_overlap_percentage
self._tmp_db_file = 'tmp.db'
self._conn = sqlite3.connect(self._tmp_db_file)
self._cur = self._conn.cursor()
self._create_table()
def add_genes(self, genes_to_add):
for gene in genes_to_add:
self._test_and_add(gene)
def merged_genes(self):
return [self._sql_row_to_gene(row) for row
in self._cur.execute("SELECT * FROM genes")]
def cleanup(self):
self._conn.close()
os.remove(self._tmp_db_file)
def _create_table(self):
try:
self._cur.execute(
"create table genes (row_id integer primary key, name text, "
"chrom text, strand text, start int, end int)")
except sqlite3.OperationalError:
os.remove(self._tmp_db_file)
def _test_and_add(self, gene):
rows = list(self._cur.execute(
"SELECT * FROM genes WHERE chrom=? AND strand=? AND "
"start <= ? AND end >= ?",
(gene.seq_id, gene.strand, gene.end, gene.start)))
if len(rows) == 0:
self._store_gene_in_db(gene)
else:
# If the self._merge_genes is False the new gene is discarded
if self._perform_gene_merging is False:
return
elif len(rows) == 1:
self._try_gene_merge(gene, rows[0])
else:
self._try_multi_gene_merge(gene, rows)
def _try_multi_gene_merge(self, gene, rows):
overlapping_genes = [self._sql_row_to_gene(row) for row in rows]
genes_to_merge = []
rows_to_remove = []
for overlapping_gene, row in zip(overlapping_genes, rows):
if not self._have_sufficient_overlap(
gene, overlapping_gene) is True:
continue
genes_to_merge.append(overlapping_gene)
rows_to_remove.append(row)
for row in rows_to_remove:
self._remove_row(row)
start = min([gene.start] + [gene.start for gene in genes_to_merge])
end = max([gene.end] + [gene.end for gene in genes_to_merge])
gene_id = "_merged_with_".join(
[gene.gene_id for gene in genes_to_merge] + [gene.gene_id])
self._store_gene_in_db(
Gene(gene.seq_id, gene_id, gene_id, start, end, gene.strand))
def _try_gene_merge(self, gene, row):
overlapping_gene = self._sql_row_to_gene(row)
if not self._have_sufficient_overlap(
gene, overlapping_gene) is True:
return
if self._genes_are_identical(gene, overlapping_gene) is True:
return
start = min(gene.start, overlapping_gene.start)
end = max(gene.end, overlapping_gene.end)
gene_id = "%s_merged_with_%s" % (
overlapping_gene.gene_id, gene.gene_id)
self._remove_row(row)
self._store_gene_in_db(
Gene(gene.seq_id, gene_id, gene_id, start, end, gene.strand))
def _store_gene_in_db(self, gene):
self._cur.execute("INSERT INTO genes VALUES (NULL, ?, ?, ?, ?, ?)",
(gene.gene_id, gene.seq_id, gene.strand,
gene.start, gene.end))
self._conn.commit()
def _genes_are_identical(self, gene_1, gene_2):
if (gene_1.gene_id == gene_2.gene_id and
gene_1.start == gene_2.end and
gene_1.end == gene_2.end):
return True
return False
def _remove_row(self, row):
self._cur.execute("DELETE FROM genes WHERE row_id=%s" % (row[0]))
self._conn.commit()
def _sql_row_to_gene(self, row):
return Gene(row[2], row[1], row[1], row[4], row[5], row[3])
def _have_sufficient_overlap(self, gene_1, gene_2):
overlap = helpers.overlap(
gene_1.start, gene_1.end, gene_2.start, gene_2.end)
if overlap <= 0:
return False
if not self._min_overlap_percentage:
return True
else:
if ((self._overlap_percentage(gene_1, overlap)
>= self._min_overlap_percentage) and
(self._overlap_percentage(gene_2, overlap)
>= self._min_overlap_percentage)):
return True
return False
def _overlap_percentage(self, gene, overlap):
try:
return float(overlap) / float(gene.len()) * 100.0
except ZeroDivisionError:
sys.stderr.write("Zero length for gene '%s/%s (start and end: %s)'\n" % (
gene.gene_id, gene.name, gene.start))
def _merge_genes(self, gene_1, gene_2):
start = min([gene_1.start, gene_2.end])
end = max([gene_1.start, gene_2.end])
name = "_merged_with_".join([gene_1.name, gene_2.name])
gene_id = "_merged_with_".join([gene_1.gene_id, gene_2.gene_id])
return Gene(gene_1.seq_id, gene_id, name, start, end, gene_1.strand)
|
isc
|
[
646,
747,
199,
646,
984,
199,
646,
1022,
1286,
647,
17614,
14,
7546,
465,
10897,
199,
646,
11723,
19,
199,
504,
1022,
1286,
647,
17614,
14,
10654,
492,
598,
6349,
199,
199,
533,
598,
6349,
1296,
16797,
836,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1748,
63,
16736,
63,
14200,
29,
403,
12,
5147,
63,
10654,
63,
2626,
1540,
29,
549,
304,
267,
327,
961,
3305,
315,
2327,
310,
823,
314,
8605,
5953,
14,
2779,
652,
365,
663,
370,
267,
327,
715,
15599,
911,
506,
9545,
284,
14,
69,
14,
314,
13460,
14664,
3421,
267,
327,
574,
436,
5696,
1284,
3421,
9394,
14,
982,
652,
365,
756,
892,
267,
327,
3805,
397,
626,
787,
28281,
543,
2269,
7869,
911,
506,
22002,
14,
267,
291,
423,
15795,
63,
10654,
63,
2626,
1540,
275,
5147,
63,
10654,
63,
2626,
1540,
267,
291,
423,
827,
63,
16736,
63,
14200,
275,
1748,
63,
16736,
63,
14200,
267,
291,
423,
2791,
63,
697,
63,
493,
275,
283,
2791,
14,
697,
7,
267,
291,
423,
1631,
275,
11723,
19,
14,
2242,
8,
277,
423,
2791,
63,
697,
63,
493,
9,
267,
291,
423,
895,
275,
291,
423,
1631,
14,
3937,
342,
267,
291,
423,
981,
63,
1224,
342,
339,
347,
1050,
63,
26965,
8,
277,
12,
3805,
397,
63,
475,
63,
525,
304,
267,
367,
15599,
315,
3805,
397,
63,
475,
63,
525,
26,
288,
291,
423,
396,
63,
460,
63,
525,
8,
10654,
9,
339,
347,
9545,
63,
26965,
8,
277,
304,
267,
372,
359,
277,
423,
3009,
63,
1143,
63,
475,
63,
10654,
8,
1143,
9,
367,
1962,
8892,
315,
291,
423,
895,
14,
2526,
480,
4859,
627,
4442,
3805,
397,
11323,
339,
347,
9058,
8,
277,
304,
267,
291,
423,
1631,
14,
1600,
342,
267,
747,
14,
2168,
8,
277,
423,
2791,
63,
697,
63,
493,
9,
339,
347,
485,
981,
63,
1224,
8,
277,
304,
267,
862,
26,
288,
291,
423,
895,
14,
2526,
8,
355,
298,
981,
1817,
3805,
397,
334,
1143,
63,
344,
3000,
5062,
790,
12,
536,
1318,
12,
298,
355,
298,
23473,
1318,
12,
620,
460,
1318,
12,
1343,
1109,
12,
1284,
1109,
6320,
267,
871,
11723,
19,
14,
31998,
547,
26,
288,
747,
14,
2168,
8,
277,
423,
2791,
63,
697,
63,
493,
9,
339,
347,
485,
396,
63,
460,
63,
525,
8,
277,
12,
15599,
304,
267,
4730,
275,
769,
8,
277,
423,
895,
14,
2526,
8,
355,
298,
4859,
627,
4442,
3805,
397,
6038,
20074,
18048,
2401,
620,
460,
18048,
2401,
298,
355,
298,
928,
2695,
5805,
2401,
1284,
2356,
5805,
401,
355,
334,
10654,
14,
3610,
63,
344,
12,
15599,
14,
30964,
12,
15599,
14,
500,
12,
15599,
14,
928,
1724,
267,
340,
822,
8,
3838,
9,
508,
378,
26,
288,
291,
423,
1617,
63,
10654,
63,
262,
63,
697,
8,
10654,
9,
267,
587,
26,
288,
327,
982,
314,
291,
423,
5628,
63,
26965,
365,
756,
314,
892,
15599,
365,
22002,
288,
340,
291,
423,
15795,
63,
10654,
63,
2626,
1540,
365,
756,
26,
355,
372,
288,
916,
822,
8,
3838,
9,
508,
413,
26,
355,
291,
423,
893,
63,
10654,
63,
5628,
8,
10654,
12,
4730,
59,
16,
566,
288,
587,
26,
355,
291,
423,
893,
63,
3029,
63,
10654,
63,
5628,
8,
10654,
12,
4730,
9,
339,
347,
485,
893,
63,
3029,
63,
10654,
63,
5628,
8,
277,
12,
15599,
12,
4730,
304,
267,
28281,
63,
26965,
275,
359,
277,
423,
3009,
63,
1143,
63,
475,
63,
10654,
8,
1143,
9,
367,
1962,
315,
4730,
61,
267,
3805,
397,
63,
475,
63,
5628,
275,
942,
267,
4730,
63,
475,
63,
2168,
275,
942,
267,
367,
28281,
63,
10654,
12,
1962,
315,
3482,
8,
31034,
63,
26965,
12,
4730,
304,
288,
340,
440,
291,
423,
7804,
63,
83,
12983,
63,
16736,
8,
355,
15599,
12,
28281,
63,
10654,
9,
365,
715,
26,
355,
1980,
288,
3805,
397,
63,
475,
63,
5628,
14,
740,
8,
31034,
63,
10654,
9,
288,
4730,
63,
475,
63,
2168,
14,
740,
8,
1143,
9,
267,
367,
1962,
315,
4730,
63,
475,
63,
2168,
26,
288,
291,
423,
2168,
63,
1143,
8,
1143,
9,
267,
1343,
275,
1748,
779,
10654,
14,
928,
61,
435,
359,
10654,
14,
928,
367,
15599,
315,
3805,
397,
63,
475,
63,
5628,
566,
267,
1284,
275,
1390,
779,
10654,
14,
500,
61,
435,
359,
10654,
14,
500,
367,
15599,
315,
3805,
397,
63,
475,
63,
5628,
566,
267,
15599,
63,
344,
275,
2668,
15269,
63,
1045,
63,
1674,
904,
8,
288,
359,
10654,
14,
10654,
63,
344,
367,
15599,
315,
3805,
397,
63,
475,
63,
5628,
61,
435,
359,
10654,
14,
10654,
63,
344,
566,
267,
291,
423,
1617,
63,
10654,
63,
262,
63,
697,
8,
288,
598,
6349,
8,
10654,
14,
3610,
63,
344,
12,
15599,
63,
344,
12,
15599,
63,
344,
12,
1343,
12,
1284,
12,
15599,
14,
30964,
430,
339,
347,
485,
893,
63,
10654,
63,
5628,
8,
277,
12,
15599,
12,
1962,
304,
267,
28281,
63,
10654,
275,
291,
423,
3009,
63,
1143,
63,
475,
63,
10654,
8,
1143,
9,
267,
340,
440,
291,
423,
7804,
63,
83,
12983,
63,
16736,
8,
288,
15599,
12,
28281,
63,
10654,
9,
365,
715,
26,
288,
372,
267,
340,
291,
423,
26965,
63,
1530,
63,
14576,
8,
10654,
12,
28281,
63,
10654,
9,
365,
715,
26,
288,
372,
267,
1343,
275,
1748,
8,
10654,
14,
928,
12,
28281,
63,
10654,
14,
928,
9,
267,
1284,
275,
1390,
8,
10654,
14,
500,
12,
28281,
63,
10654,
14,
500,
9,
267,
15599,
63,
344,
275,
2071,
83,
63,
15269,
63,
1045,
4970,
83,
2,
450,
334,
288,
28281,
63,
10654,
14,
10654,
63,
344,
12,
15599,
14,
10654,
63,
344,
9,
267,
291,
423,
2168,
63,
1143,
8,
1143,
9,
267,
291,
423,
1617,
63,
10654,
63,
262,
63,
697,
8,
288,
598,
6349,
8,
10654,
14,
3610,
63,
344,
12,
15599,
63,
344,
12,
15599,
63,
344,
12,
1343,
12,
1284,
12,
15599,
14,
30964,
430,
339,
347,
485,
1617,
63,
10654,
63,
262,
63,
697,
8,
277,
12,
15599,
304,
267,
291,
423,
895,
14,
2526,
480,
10258,
12872,
3805,
397,
13992,
334
] |
[
747,
199,
646,
984,
199,
646,
1022,
1286,
647,
17614,
14,
7546,
465,
10897,
199,
646,
11723,
19,
199,
504,
1022,
1286,
647,
17614,
14,
10654,
492,
598,
6349,
199,
199,
533,
598,
6349,
1296,
16797,
836,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
1748,
63,
16736,
63,
14200,
29,
403,
12,
5147,
63,
10654,
63,
2626,
1540,
29,
549,
304,
267,
327,
961,
3305,
315,
2327,
310,
823,
314,
8605,
5953,
14,
2779,
652,
365,
663,
370,
267,
327,
715,
15599,
911,
506,
9545,
284,
14,
69,
14,
314,
13460,
14664,
3421,
267,
327,
574,
436,
5696,
1284,
3421,
9394,
14,
982,
652,
365,
756,
892,
267,
327,
3805,
397,
626,
787,
28281,
543,
2269,
7869,
911,
506,
22002,
14,
267,
291,
423,
15795,
63,
10654,
63,
2626,
1540,
275,
5147,
63,
10654,
63,
2626,
1540,
267,
291,
423,
827,
63,
16736,
63,
14200,
275,
1748,
63,
16736,
63,
14200,
267,
291,
423,
2791,
63,
697,
63,
493,
275,
283,
2791,
14,
697,
7,
267,
291,
423,
1631,
275,
11723,
19,
14,
2242,
8,
277,
423,
2791,
63,
697,
63,
493,
9,
267,
291,
423,
895,
275,
291,
423,
1631,
14,
3937,
342,
267,
291,
423,
981,
63,
1224,
342,
339,
347,
1050,
63,
26965,
8,
277,
12,
3805,
397,
63,
475,
63,
525,
304,
267,
367,
15599,
315,
3805,
397,
63,
475,
63,
525,
26,
288,
291,
423,
396,
63,
460,
63,
525,
8,
10654,
9,
339,
347,
9545,
63,
26965,
8,
277,
304,
267,
372,
359,
277,
423,
3009,
63,
1143,
63,
475,
63,
10654,
8,
1143,
9,
367,
1962,
8892,
315,
291,
423,
895,
14,
2526,
480,
4859,
627,
4442,
3805,
397,
11323,
339,
347,
9058,
8,
277,
304,
267,
291,
423,
1631,
14,
1600,
342,
267,
747,
14,
2168,
8,
277,
423,
2791,
63,
697,
63,
493,
9,
339,
347,
485,
981,
63,
1224,
8,
277,
304,
267,
862,
26,
288,
291,
423,
895,
14,
2526,
8,
355,
298,
981,
1817,
3805,
397,
334,
1143,
63,
344,
3000,
5062,
790,
12,
536,
1318,
12,
298,
355,
298,
23473,
1318,
12,
620,
460,
1318,
12,
1343,
1109,
12,
1284,
1109,
6320,
267,
871,
11723,
19,
14,
31998,
547,
26,
288,
747,
14,
2168,
8,
277,
423,
2791,
63,
697,
63,
493,
9,
339,
347,
485,
396,
63,
460,
63,
525,
8,
277,
12,
15599,
304,
267,
4730,
275,
769,
8,
277,
423,
895,
14,
2526,
8,
355,
298,
4859,
627,
4442,
3805,
397,
6038,
20074,
18048,
2401,
620,
460,
18048,
2401,
298,
355,
298,
928,
2695,
5805,
2401,
1284,
2356,
5805,
401,
355,
334,
10654,
14,
3610,
63,
344,
12,
15599,
14,
30964,
12,
15599,
14,
500,
12,
15599,
14,
928,
1724,
267,
340,
822,
8,
3838,
9,
508,
378,
26,
288,
291,
423,
1617,
63,
10654,
63,
262,
63,
697,
8,
10654,
9,
267,
587,
26,
288,
327,
982,
314,
291,
423,
5628,
63,
26965,
365,
756,
314,
892,
15599,
365,
22002,
288,
340,
291,
423,
15795,
63,
10654,
63,
2626,
1540,
365,
756,
26,
355,
372,
288,
916,
822,
8,
3838,
9,
508,
413,
26,
355,
291,
423,
893,
63,
10654,
63,
5628,
8,
10654,
12,
4730,
59,
16,
566,
288,
587,
26,
355,
291,
423,
893,
63,
3029,
63,
10654,
63,
5628,
8,
10654,
12,
4730,
9,
339,
347,
485,
893,
63,
3029,
63,
10654,
63,
5628,
8,
277,
12,
15599,
12,
4730,
304,
267,
28281,
63,
26965,
275,
359,
277,
423,
3009,
63,
1143,
63,
475,
63,
10654,
8,
1143,
9,
367,
1962,
315,
4730,
61,
267,
3805,
397,
63,
475,
63,
5628,
275,
942,
267,
4730,
63,
475,
63,
2168,
275,
942,
267,
367,
28281,
63,
10654,
12,
1962,
315,
3482,
8,
31034,
63,
26965,
12,
4730,
304,
288,
340,
440,
291,
423,
7804,
63,
83,
12983,
63,
16736,
8,
355,
15599,
12,
28281,
63,
10654,
9,
365,
715,
26,
355,
1980,
288,
3805,
397,
63,
475,
63,
5628,
14,
740,
8,
31034,
63,
10654,
9,
288,
4730,
63,
475,
63,
2168,
14,
740,
8,
1143,
9,
267,
367,
1962,
315,
4730,
63,
475,
63,
2168,
26,
288,
291,
423,
2168,
63,
1143,
8,
1143,
9,
267,
1343,
275,
1748,
779,
10654,
14,
928,
61,
435,
359,
10654,
14,
928,
367,
15599,
315,
3805,
397,
63,
475,
63,
5628,
566,
267,
1284,
275,
1390,
779,
10654,
14,
500,
61,
435,
359,
10654,
14,
500,
367,
15599,
315,
3805,
397,
63,
475,
63,
5628,
566,
267,
15599,
63,
344,
275,
2668,
15269,
63,
1045,
63,
1674,
904,
8,
288,
359,
10654,
14,
10654,
63,
344,
367,
15599,
315,
3805,
397,
63,
475,
63,
5628,
61,
435,
359,
10654,
14,
10654,
63,
344,
566,
267,
291,
423,
1617,
63,
10654,
63,
262,
63,
697,
8,
288,
598,
6349,
8,
10654,
14,
3610,
63,
344,
12,
15599,
63,
344,
12,
15599,
63,
344,
12,
1343,
12,
1284,
12,
15599,
14,
30964,
430,
339,
347,
485,
893,
63,
10654,
63,
5628,
8,
277,
12,
15599,
12,
1962,
304,
267,
28281,
63,
10654,
275,
291,
423,
3009,
63,
1143,
63,
475,
63,
10654,
8,
1143,
9,
267,
340,
440,
291,
423,
7804,
63,
83,
12983,
63,
16736,
8,
288,
15599,
12,
28281,
63,
10654,
9,
365,
715,
26,
288,
372,
267,
340,
291,
423,
26965,
63,
1530,
63,
14576,
8,
10654,
12,
28281,
63,
10654,
9,
365,
715,
26,
288,
372,
267,
1343,
275,
1748,
8,
10654,
14,
928,
12,
28281,
63,
10654,
14,
928,
9,
267,
1284,
275,
1390,
8,
10654,
14,
500,
12,
28281,
63,
10654,
14,
500,
9,
267,
15599,
63,
344,
275,
2071,
83,
63,
15269,
63,
1045,
4970,
83,
2,
450,
334,
288,
28281,
63,
10654,
14,
10654,
63,
344,
12,
15599,
14,
10654,
63,
344,
9,
267,
291,
423,
2168,
63,
1143,
8,
1143,
9,
267,
291,
423,
1617,
63,
10654,
63,
262,
63,
697,
8,
288,
598,
6349,
8,
10654,
14,
3610,
63,
344,
12,
15599,
63,
344,
12,
15599,
63,
344,
12,
1343,
12,
1284,
12,
15599,
14,
30964,
430,
339,
347,
485,
1617,
63,
10654,
63,
262,
63,
697,
8,
277,
12,
15599,
304,
267,
291,
423,
895,
14,
2526,
480,
10258,
12872,
3805,
397,
13992,
334,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Omegaphora/external_chromium_org
|
chrome/tools/history-viz.py
|
176
|
8039
|
#!/usr/bin/env python
# Copyright (c) 2011 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.
"""Process a History database and dump a .dot file suitable for GraphViz.
This is useful for debugging history redirect flows.
An example run of this program:
python /src/history-viz.py History > foo.dot
/c/Program\ Files/Graphviz2.18/bin/dot -Tpng foo.dot -o foo.png
"""
import struct
import subprocess
import sys
import urlparse
# Some transition types, copied from page_transition_types.h.
TRANS_TYPES = {
0: 'link',
1: 'typed',
2: 'most-visited',
3: 'auto subframe',
7: 'form',
}
class URL(object):
"""Represents a broken-down URL from our most visited database."""
def __init__(self, id, url):
"""Initialize a new URL object. |id| is the database id of the URL."""
self.id = id
self.url = url
scheme, loc, path, query, fragment = urlparse.urlsplit(url)
if scheme == 'http':
scheme = '' # Shorten for display purposes.
if len(scheme) > 0:
scheme += '://'
self.host = scheme + loc
self.path = path
extra = ''
if len(query) > 0:
extra += '?' + query
if len(fragment) > 0 or url.find('#') > 0:
extra += '#' + fragment
self.extra = extra
def PrettyPrint(self, include_host=True, include_path=True):
"""Pretty-print this URL in a form more suitable for the graph.
This will elide very long paths and potentially puts newlines between parts
of long components. include_host and include_path determine whether to
include the host and path in the output.
Returns: the pretty-printed string."""
MAX_LEN = 30 # Maximum length of a line in the output.
parts = []
if include_host:
parts.append(self.host)
if include_path:
parts.append(self.path)
parts.append(self.extra)
lines = []
line = ''
for part in parts:
if len(part) > MAX_LEN:
part = part[0:MAX_LEN-3] + '...'
if len(line)+len(part) > MAX_LEN:
lines.append(line)
line = ''
line += part
if len(line) > 0:
lines.append(line)
return '\n'.join(lines)
class Edge(object):
"""Represents an edge in the history graph, connecting two pages.
If a link is traversed twice, it is one Edge with two entries in
the .transitions array."""
def __init__(self, src, dst):
self.src = src
self.dst = dst
self.transitions = []
def Transitions(self):
"""Return a dictionary mapping transition type -> occurences."""
all = {}
for trans in self.transitions:
all[trans] = all.get(trans, 0) + 1
# We currently don't use the chain type.
# TODO(evanm): make this a command-line option.
# if trans & 0x30000000 != 0:
# chain = ''
# if trans & 0x10000000:
# chain = 'start'
# if trans & 0x20000000:
# if len(chain) == 0:
# chain = 'end'
# else:
# chain = ''
# if len(chain) > 0:
# edge['chain'] = chain
return all
def ClusterBy(objs, pred):
"""Group a list of objects by a predicate.
Given a list of objects and a predicate over the objects, return a
dictionary mapping pred(obj) -> all objs with the same pred(obj)."""
clusters = {}
for obj in objs:
cluster = pred(obj)
clusters[cluster] = clusters.get(cluster, [])
clusters[cluster].append(obj)
return clusters
def EscapeDot(string):
"""Escape a string suitable for embedding in a graphviz graph."""
# TODO(evanm): this is likely not sufficient.
return string.replace('\n', '\\n')
class SQLite(object):
"""Trivial interface to executing SQLite queries.
Spawns a new process with each call."""
def __init__(self, file=None):
self.file = file
def Run(self, sql):
"""Execute |sql|, yielding each row of results as an array."""
subproc = subprocess.Popen(['sqlite', self.file],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE)
subproc.stdin.write('.mode tabs\n')
subproc.stdin.write(sql + ';')
subproc.stdin.close()
for line in subproc.stdout:
row = line.strip().split('\t')
yield row
def LoadHistory(filename):
db = SQLite(filename)
urls = {} # Map of urlid => url.
urls['0'] = URL('0', 'start') # Node name '0' is our special 'start' node.
for id, url in db.Run('SELECT id, url FROM urls'):
urls[id] = URL(id, url)
visiturlids = {} # Map of visitid => urlid.
visiturlids['0'] = '0' # '0' is our special 'start' node.
edges = {} # Map of urlid->urlid->Edge.
for src, dst, url, trans in db.Run('SELECT from_visit, id, url, transition '
'FROM visits ORDER BY id'):
visiturlids[dst] = url
src = visiturlids[src]
dst = visiturlids[dst]
edges[src] = edges.get(src, {})
edge = edges[src][dst] = edges[src].get(dst, Edge(src, dst))
# SQLite outputs transition values as signed integers, but they're really
# a bitfield. Below does "unsigned trans = static_cast<unsigned>(trans)".
trans = struct.unpack('I', struct.pack('i', int(trans)))[0]
edge.transitions.append(trans)
return urls, edges
def main():
urls, edges = LoadHistory(sys.argv[1])
print 'digraph G {'
print ' graph [rankdir=LR]' # Display left to right.
print ' node [shape=box]' # Display nodes as boxes.
print ' subgraph { rank=source; 0 [label="start"] }'
# Output all the nodes within graph clusters.
hosts = ClusterBy(urls.values(), lambda url: url.host)
for i, (host, urls) in enumerate(hosts.items()):
# Cluster all URLs under this host if it has more than one entry.
host_clustered = len(urls) > 1
if host_clustered:
print 'subgraph clusterhost%d {' % i
print ' label="%s"' % host
paths = ClusterBy(urls, lambda url: url.path)
for j, (path, urls) in enumerate(paths.items()):
# Cluster all URLs under this host if it has more than one entry.
path_clustered = host_clustered and len(urls) > 1
if path_clustered:
print ' subgraph cluster%d%d {' % (i, j)
print ' label="%s"' % path
for url in urls:
if url.id == '0': continue # We already output the special start node.
pretty = url.PrettyPrint(include_host=not host_clustered,
include_path=not path_clustered)
print ' %s [label="%s"]' % (url.id, EscapeDot(pretty))
if path_clustered:
print ' }'
if host_clustered:
print '}'
# Output all the edges between nodes.
for src, dsts in edges.items():
for dst, edge in dsts.items():
# Gather up all the transitions into the label.
label = [] # Label for the edge.
transitions = edge.Transitions()
for trans, count in transitions.items():
text = ''
if count > 1:
text = '%dx ' % count
base_type = trans & 0xFF
redir = (trans & 0xC0000000) != 0
start = (trans & 0x10000000) != 0
end = (trans & 0x20000000) != 0
if start or end:
if start:
text += '<'
if end:
text += '>'
text += ' '
if redir:
text += 'R '
text += TRANS_TYPES.get(base_type, 'trans%d' % base_type)
label.append(text)
if len(label) == 0:
continue
edgeattrs = [] # Graphviz attributes for the edge.
# If the edge is from the start and the transitions are fishy, make it
# display as a dotted line.
if src == '0' and len(transitions.keys()) == 1 and transitions.has_key(0):
edgeattrs.append('style=dashed')
if len(label) > 0:
edgeattrs.append('label="%s"' % EscapeDot('\n'.join(label)))
out = '%s -> %s' % (src, dst)
if len(edgeattrs) > 0:
out += ' [%s]' % ','.join(edgeattrs)
print out
print '}'
return 0
if __name__ == '__main__':
sys.exit(main())
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
7760,
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,
3498,
282,
27829,
3050,
436,
5461,
282,
1275,
3287,
570,
11233,
367,
11513,
32068,
14,
199,
199,
2765,
365,
2997,
367,
10201,
7994,
4660,
30708,
14,
199,
199,
2493,
2893,
1255,
402,
642,
2240,
26,
523,
2366,
1182,
2164,
15,
5570,
13,
17249,
14,
647,
27829,
690,
3925,
14,
3287,
523,
1182,
67,
15,
9184,
60,
16920,
15,
4578,
17249,
18,
14,
1085,
15,
1393,
15,
3287,
446,
52,
4524,
3925,
14,
3287,
446,
79,
3925,
14,
4524,
199,
624,
199,
199,
646,
2702,
199,
646,
3873,
199,
646,
984,
199,
646,
7097,
421,
199,
3,
6601,
14116,
2943,
12,
8876,
687,
2034,
63,
14143,
63,
1313,
14,
72,
14,
199,
12191,
63,
7893,
275,
469,
523,
378,
26,
283,
1073,
297,
523,
413,
26,
283,
22033,
297,
523,
499,
26,
283,
2786,
13,
21736,
297,
523,
650,
26,
283,
2495,
1007,
1943,
297,
523,
1520,
26,
283,
964,
297,
199,
93,
421,
199,
533,
2851,
8,
785,
304,
523,
408,
18089,
282,
10529,
13,
2110,
2851,
687,
4154,
4750,
15867,
3050,
1041,
819,
347,
636,
826,
721,
277,
12,
1305,
12,
1166,
304,
272,
408,
9345,
282,
892,
2851,
909,
14,
221,
1204,
344,
92,
365,
314,
3050,
1305,
402,
314,
2851,
1041,
272,
291,
14,
344,
275,
1305,
272,
291,
14,
633,
275,
1166,
272,
5687,
12,
4355,
12,
931,
12,
1827,
12,
7956,
275,
7097,
14,
29491,
8,
633,
9,
272,
340,
5687,
508,
283,
1014,
356,
489,
5687,
275,
2125,
221,
327,
5244,
269,
724,
367,
2929,
12901,
14,
272,
340,
822,
8,
5512,
9,
690,
378,
26,
489,
5687,
847,
283,
22399,
272,
291,
14,
1102,
275,
5687,
435,
4355,
272,
291,
14,
515,
275,
931,
339,
2402,
275,
2125,
272,
340,
822,
8,
1131,
9,
690,
378,
26,
489,
2402,
847,
15539,
435,
1827,
272,
340,
822,
8,
7677,
9,
690,
378,
503,
1166,
14,
1623,
7863,
358,
690,
378,
26,
489,
2402,
847,
19619,
435,
7956,
272,
291,
14,
2911,
275,
2402,
819,
347,
31651,
5375,
8,
277,
12,
2387,
63,
1102,
29,
549,
12,
2387,
63,
515,
29,
549,
304,
272,
408,
27153,
13,
1361,
642,
2851,
315,
282,
1824,
1655,
11233,
367,
314,
3343,
14,
339,
961,
911,
325,
8409,
7437,
1846,
3792,
436,
18994,
27000,
14930,
3382,
4184,
272,
402,
1846,
7323,
14,
221,
2387,
63,
1102,
436,
2387,
63,
515,
6705,
3775,
370,
272,
2387,
314,
1591,
436,
931,
315,
314,
1072,
14,
339,
1803,
26,
314,
7268,
13,
27131,
1059,
1041,
272,
9141,
63,
5304,
275,
4233,
221,
327,
14212,
2582,
402,
282,
1004,
315,
314,
1072,
14,
272,
4184,
275,
942,
272,
340,
2387,
63,
1102,
26,
489,
4184,
14,
740,
8,
277,
14,
1102,
9,
272,
340,
2387,
63,
515,
26,
489,
4184,
14,
740,
8,
277,
14,
515,
9,
272,
4184,
14,
740,
8,
277,
14,
2911,
9,
272,
2385,
275,
942,
272,
1004,
275,
2125,
272,
367,
1777,
315,
4184,
26,
489,
340,
822,
8,
2064,
9,
690,
9141,
63,
5304,
26,
267,
1777,
275,
1777,
59,
16,
26,
4283,
63,
5304,
13,
19,
61,
435,
28044,
489,
340,
822,
8,
604,
6393,
552,
8,
2064,
9,
690,
9141,
63,
5304,
26,
267,
2385,
14,
740,
8,
604,
9,
267,
1004,
275,
2125,
489,
1004,
847,
1777,
272,
340,
822,
8,
604,
9,
690,
378,
26,
489,
2385,
14,
740,
8,
604,
9,
272,
372,
1557,
78,
1370,
904,
8,
1278,
9,
421,
199,
533,
25155,
8,
785,
304,
523,
408,
18089,
376,
6275,
315,
314,
7994,
3343,
12,
18170,
2877,
6497,
14,
819,
982,
282,
2142,
365,
1468,
7460,
13373,
12,
652,
365,
1373,
25155,
543,
2877,
4811,
315,
523,
314,
1275,
23062,
1625,
1041,
523,
347,
636,
826,
721,
277,
12,
2928,
12,
5042,
304,
272,
291,
14,
2164,
275,
2928,
272,
291,
14,
5119,
275,
5042,
272,
291,
14,
23062,
275,
942,
819,
347,
19894,
6150,
8,
277,
304,
272,
408,
1767,
282,
2600,
4412,
14116,
730,
1035,
14706,
608,
78,
823,
1041,
272,
1006,
275,
1052,
272,
367,
1752,
315,
291,
14,
23062,
26,
489,
1006,
59,
1515,
61,
275,
1006,
14,
362,
8,
1515,
12,
378,
9,
435,
413,
489,
327,
2136,
5544,
2793,
1133,
675,
314,
6036,
730,
14,
489,
327,
3254,
8,
6857,
290,
77,
304,
1852,
642,
282,
1414,
13,
604,
945,
14,
489,
327,
340,
1752,
1253,
378,
88,
19,
9084,
1137,
378,
26,
489,
327,
257,
6036,
275,
2125,
489,
327,
257,
340,
1752,
1253,
378,
88,
17,
9084,
26,
489,
327,
258,
6036,
275,
283,
928,
7,
489,
327,
257,
340,
1752,
1253,
378,
88,
18,
9084,
26,
489,
327,
258,
340,
822,
8,
4429,
9,
508,
378,
26,
489,
327,
755,
6036,
275,
283,
500,
7,
489,
327,
258,
587,
26,
489,
327,
755,
6036,
275,
2125,
489,
327,
257,
340,
822,
8,
4429,
9,
690,
378,
26,
489,
327,
258,
6275,
459,
4429,
418,
275,
6036,
272,
372,
1006,
421,
199,
318,
16454,
2175,
8,
8718,
12,
8869,
304,
523,
408,
2448,
282,
769,
402,
2251,
701,
282,
11944,
14,
819,
9138,
282,
769,
402,
2251,
436,
282,
11944,
1806,
314,
2251,
12,
372,
282,
523,
2600,
4412,
8869,
8,
1113,
9,
1035,
1006,
13474,
543,
314,
2011,
8869,
8,
1113,
10477,
523,
13865,
275,
1052,
523,
367,
1559,
315,
13474,
26,
272,
4350,
275,
8869,
8,
1113,
9,
272,
13865,
59,
4201,
61,
275,
13865,
14,
362,
8,
4201,
12,
3073,
272,
13865,
59,
4201,
1055,
740,
8,
1113,
9,
523,
372,
13865,
421,
199,
318,
21067,
14004,
8,
875,
304,
523,
408,
10260,
282,
1059,
11233,
367,
12452,
315,
282,
3343,
17249,
3343,
1041,
523,
327,
3254,
8,
6857,
290,
77,
304,
642,
365,
12060,
440,
19258,
14,
523,
372,
1059,
14,
1814,
2258,
78,
297,
6468,
78,
358,
421,
199,
533,
19245,
8,
785,
304,
523,
408,
6948,
15652,
3217,
370
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
7760,
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,
3498,
282,
27829,
3050,
436,
5461,
282,
1275,
3287,
570,
11233,
367,
11513,
32068,
14,
199,
199,
2765,
365,
2997,
367,
10201,
7994,
4660,
30708,
14,
199,
199,
2493,
2893,
1255,
402,
642,
2240,
26,
523,
2366,
1182,
2164,
15,
5570,
13,
17249,
14,
647,
27829,
690,
3925,
14,
3287,
523,
1182,
67,
15,
9184,
60,
16920,
15,
4578,
17249,
18,
14,
1085,
15,
1393,
15,
3287,
446,
52,
4524,
3925,
14,
3287,
446,
79,
3925,
14,
4524,
199,
624,
199,
199,
646,
2702,
199,
646,
3873,
199,
646,
984,
199,
646,
7097,
421,
199,
3,
6601,
14116,
2943,
12,
8876,
687,
2034,
63,
14143,
63,
1313,
14,
72,
14,
199,
12191,
63,
7893,
275,
469,
523,
378,
26,
283,
1073,
297,
523,
413,
26,
283,
22033,
297,
523,
499,
26,
283,
2786,
13,
21736,
297,
523,
650,
26,
283,
2495,
1007,
1943,
297,
523,
1520,
26,
283,
964,
297,
199,
93,
421,
199,
533,
2851,
8,
785,
304,
523,
408,
18089,
282,
10529,
13,
2110,
2851,
687,
4154,
4750,
15867,
3050,
1041,
819,
347,
636,
826,
721,
277,
12,
1305,
12,
1166,
304,
272,
408,
9345,
282,
892,
2851,
909,
14,
221,
1204,
344,
92,
365,
314,
3050,
1305,
402,
314,
2851,
1041,
272,
291,
14,
344,
275,
1305,
272,
291,
14,
633,
275,
1166,
272,
5687,
12,
4355,
12,
931,
12,
1827,
12,
7956,
275,
7097,
14,
29491,
8,
633,
9,
272,
340,
5687,
508,
283,
1014,
356,
489,
5687,
275,
2125,
221,
327,
5244,
269,
724,
367,
2929,
12901,
14,
272,
340,
822,
8,
5512,
9,
690,
378,
26,
489,
5687,
847,
283,
22399,
272,
291,
14,
1102,
275,
5687,
435,
4355,
272,
291,
14,
515,
275,
931,
339,
2402,
275,
2125,
272,
340,
822,
8,
1131,
9,
690,
378,
26,
489,
2402,
847,
15539,
435,
1827,
272,
340,
822,
8,
7677,
9,
690,
378,
503,
1166,
14,
1623,
7863,
358,
690,
378,
26,
489,
2402,
847,
19619,
435,
7956,
272,
291,
14,
2911,
275,
2402,
819,
347,
31651,
5375,
8,
277,
12,
2387,
63,
1102,
29,
549,
12,
2387,
63,
515,
29,
549,
304,
272,
408,
27153,
13,
1361,
642,
2851,
315,
282,
1824,
1655,
11233,
367,
314,
3343,
14,
339,
961,
911,
325,
8409,
7437,
1846,
3792,
436,
18994,
27000,
14930,
3382,
4184,
272,
402,
1846,
7323,
14,
221,
2387,
63,
1102,
436,
2387,
63,
515,
6705,
3775,
370,
272,
2387,
314,
1591,
436,
931,
315,
314,
1072,
14,
339,
1803,
26,
314,
7268,
13,
27131,
1059,
1041,
272,
9141,
63,
5304,
275,
4233,
221,
327,
14212,
2582,
402,
282,
1004,
315,
314,
1072,
14,
272,
4184,
275,
942,
272,
340,
2387,
63,
1102,
26,
489,
4184,
14,
740,
8,
277,
14,
1102,
9,
272,
340,
2387,
63,
515,
26,
489,
4184,
14,
740,
8,
277,
14,
515,
9,
272,
4184,
14,
740,
8,
277,
14,
2911,
9,
272,
2385,
275,
942,
272,
1004,
275,
2125,
272,
367,
1777,
315,
4184,
26,
489,
340,
822,
8,
2064,
9,
690,
9141,
63,
5304,
26,
267,
1777,
275,
1777,
59,
16,
26,
4283,
63,
5304,
13,
19,
61,
435,
28044,
489,
340,
822,
8,
604,
6393,
552,
8,
2064,
9,
690,
9141,
63,
5304,
26,
267,
2385,
14,
740,
8,
604,
9,
267,
1004,
275,
2125,
489,
1004,
847,
1777,
272,
340,
822,
8,
604,
9,
690,
378,
26,
489,
2385,
14,
740,
8,
604,
9,
272,
372,
1557,
78,
1370,
904,
8,
1278,
9,
421,
199,
533,
25155,
8,
785,
304,
523,
408,
18089,
376,
6275,
315,
314,
7994,
3343,
12,
18170,
2877,
6497,
14,
819,
982,
282,
2142,
365,
1468,
7460,
13373,
12,
652,
365,
1373,
25155,
543,
2877,
4811,
315,
523,
314,
1275,
23062,
1625,
1041,
523,
347,
636,
826,
721,
277,
12,
2928,
12,
5042,
304,
272,
291,
14,
2164,
275,
2928,
272,
291,
14,
5119,
275,
5042,
272,
291,
14,
23062,
275,
942,
819,
347,
19894,
6150,
8,
277,
304,
272,
408,
1767,
282,
2600,
4412,
14116,
730,
1035,
14706,
608,
78,
823,
1041,
272,
1006,
275,
1052,
272,
367,
1752,
315,
291,
14,
23062,
26,
489,
1006,
59,
1515,
61,
275,
1006,
14,
362,
8,
1515,
12,
378,
9,
435,
413,
489,
327,
2136,
5544,
2793,
1133,
675,
314,
6036,
730,
14,
489,
327,
3254,
8,
6857,
290,
77,
304,
1852,
642,
282,
1414,
13,
604,
945,
14,
489,
327,
340,
1752,
1253,
378,
88,
19,
9084,
1137,
378,
26,
489,
327,
257,
6036,
275,
2125,
489,
327,
257,
340,
1752,
1253,
378,
88,
17,
9084,
26,
489,
327,
258,
6036,
275,
283,
928,
7,
489,
327,
257,
340,
1752,
1253,
378,
88,
18,
9084,
26,
489,
327,
258,
340,
822,
8,
4429,
9,
508,
378,
26,
489,
327,
755,
6036,
275,
283,
500,
7,
489,
327,
258,
587,
26,
489,
327,
755,
6036,
275,
2125,
489,
327,
257,
340,
822,
8,
4429,
9,
690,
378,
26,
489,
327,
258,
6275,
459,
4429,
418,
275,
6036,
272,
372,
1006,
421,
199,
318,
16454,
2175,
8,
8718,
12,
8869,
304,
523,
408,
2448,
282,
769,
402,
2251,
701,
282,
11944,
14,
819,
9138,
282,
769,
402,
2251,
436,
282,
11944,
1806,
314,
2251,
12,
372,
282,
523,
2600,
4412,
8869,
8,
1113,
9,
1035,
1006,
13474,
543,
314,
2011,
8869,
8,
1113,
10477,
523,
13865,
275,
1052,
523,
367,
1559,
315,
13474,
26,
272,
4350,
275,
8869,
8,
1113,
9,
272,
13865,
59,
4201,
61,
275,
13865,
14,
362,
8,
4201,
12,
3073,
272,
13865,
59,
4201,
1055,
740,
8,
1113,
9,
523,
372,
13865,
421,
199,
318,
21067,
14004,
8,
875,
304,
523,
408,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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
] |
mozilla/django-session-csrf
|
setup.py
|
3
|
1072
|
import os
from setuptools import setup, find_packages
ROOT = os.path.abspath(os.path.dirname(__file__))
setup(
name='django-session-csrf',
version='0.7.1',
description='CSRF protection for Django without cookies.',
long_description=open(os.path.join(ROOT, 'README.rst')).read(),
author='Jeff Balogh',
author_email='jbalogh@mozilla.com',
url='http://github.com/mozilla/django-session-csrf',
license='BSD',
packages=find_packages(),
include_package_data=True,
zip_safe=False,
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
'Environment :: Web Environment :: Mozilla',
'Framework :: Django',
'Intended Audience :: Developers',
'License :: OSI Approved :: BSD License',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Operating System :: OS Independent',
'Programming Language :: Python',
'Topic :: Software Development :: Libraries :: Python Modules',
]
)
|
bsd-3-clause
|
[
646,
747,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
199,
5441,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
421,
199,
2758,
8,
272,
536,
534,
1176,
13,
1730,
13,
10088,
297,
272,
1015,
534,
16,
14,
23,
14,
17,
297,
272,
1369,
534,
26405,
23977,
367,
5634,
1928,
10049,
3130,
272,
1846,
63,
1802,
29,
1490,
8,
736,
14,
515,
14,
904,
8,
5441,
12,
283,
18195,
14,
8332,
11103,
739,
1062,
272,
4132,
534,
42,
3609,
699,
2548,
72,
297,
272,
4132,
63,
2123,
534,
26257,
2548,
72,
32,
12102,
14,
957,
297,
272,
1166,
534,
1014,
921,
5031,
14,
957,
15,
12102,
15,
1176,
13,
1730,
13,
10088,
297,
272,
4190,
534,
15400,
297,
272,
6117,
29,
1623,
63,
5154,
1062,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
3482,
63,
3489,
29,
797,
12,
272,
19137,
1524,
267,
283,
23753,
9795,
3800,
841,
446,
29521,
297,
267,
283,
8263,
3800,
6001,
9711,
297,
267,
283,
8263,
3800,
6001,
9711,
3800,
17728,
297,
267,
283,
16442,
3800,
5634,
297,
267,
283,
23910,
23975,
3800,
23493,
297,
267,
283,
3761,
3800,
25718,
26330,
3800,
6289,
844,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
18418,
283,
23699,
6187,
3800,
4403,
1010,
7106,
297,
267,
283,
11411,
8466,
3800,
2018,
297,
267,
283,
12157,
3800,
2290,
15290,
3800,
31454,
3800,
2018,
18167,
297,
272,
1622,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
747,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
199,
199,
5441,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
421,
199,
2758,
8,
272,
536,
534,
1176,
13,
1730,
13,
10088,
297,
272,
1015,
534,
16,
14,
23,
14,
17,
297,
272,
1369,
534,
26405,
23977,
367,
5634,
1928,
10049,
3130,
272,
1846,
63,
1802,
29,
1490,
8,
736,
14,
515,
14,
904,
8,
5441,
12,
283,
18195,
14,
8332,
11103,
739,
1062,
272,
4132,
534,
42,
3609,
699,
2548,
72,
297,
272,
4132,
63,
2123,
534,
26257,
2548,
72,
32,
12102,
14,
957,
297,
272,
1166,
534,
1014,
921,
5031,
14,
957,
15,
12102,
15,
1176,
13,
1730,
13,
10088,
297,
272,
4190,
534,
15400,
297,
272,
6117,
29,
1623,
63,
5154,
1062,
272,
2387,
63,
2491,
63,
576,
29,
549,
12,
272,
3482,
63,
3489,
29,
797,
12,
272,
19137,
1524,
267,
283,
23753,
9795,
3800,
841,
446,
29521,
297,
267,
283,
8263,
3800,
6001,
9711,
297,
267,
283,
8263,
3800,
6001,
9711,
3800,
17728,
297,
267,
283,
16442,
3800,
5634,
297,
267,
283,
23910,
23975,
3800,
23493,
297,
267,
283,
3761,
3800,
25718,
26330,
3800,
6289,
844,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
18418,
283,
23699,
6187,
3800,
4403,
1010,
7106,
297,
267,
283,
11411,
8466,
3800,
2018,
297,
267,
283,
12157,
3800,
2290,
15290,
3800,
31454,
3800,
2018,
18167,
297,
272,
1622,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
yohanko88/gem5-DC
|
configs/common/Options.py
|
1
|
20572
|
# Copyright (c) 2013 ARM Limited
# 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.
#
# Copyright (c) 2006-2008 The Regents of The University of Michigan
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met: redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer;
# redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution;
# neither the name of the copyright holders nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Authors: Lisa Hsu
import m5
from m5.defines import buildEnv
from m5.objects import *
from Benchmarks import *
import CpuConfig
import MemConfig
import PlatformConfig
from FSConfig import os_types
def _listCpuTypes(option, opt, value, parser):
CpuConfig.print_cpu_list()
sys.exit(0)
def _listMemTypes(option, opt, value, parser):
MemConfig.print_mem_list()
sys.exit(0)
def _listPlatformTypes(option, opt, value, parser):
PlatformConfig.print_platform_list()
sys.exit(0)
def addCommonOptions(parser):
# system options
parser.add_option("--list-cpu-types",
action="callback", callback=_listCpuTypes,
help="List available CPU types")
parser.add_option("--cpu-type", type="choice", default="atomic",
choices=CpuConfig.cpu_names(),
help = "type of cpu to run with")
parser.add_option("--checker", action="store_true");
parser.add_option("-n", "--num-cpus", type="int", default=1)
parser.add_option("--sys-voltage", action="store", type="string",
default='1.0V',
help = """Top-level voltage for blocks running at system
power supply""")
parser.add_option("--sys-clock", action="store", type="string",
default='1GHz',
help = """Top-level clock for blocks running at system
speed""")
parser.add_option("--cpu-clock", action="store", type="string",
default='2GHz',
help="Clock for blocks running at CPU speed")
parser.add_option("--smt", action="store_true", default=False,
help = """
Only used if multiple programs are specified. If true,
then the number of threads per cpu is same as the
number of programs.""")
parser.add_option("--elastic-trace-en", action="store_true",
help="""Enable capture of data dependency and instruction
fetch traces using elastic trace probe.""")
# Trace file paths input to trace probe in a capture simulation and input
# to Trace CPU in a replay simulation
parser.add_option("--inst-trace-file", action="store", type="string",
help="""Instruction fetch trace file input to
Elastic Trace probe in a capture simulation and
Trace CPU in a replay simulation""", default="")
parser.add_option("--data-trace-file", action="store", type="string",
help="""Data dependency trace file input to
Elastic Trace probe in a capture simulation and
Trace CPU in a replay simulation""", default="")
# Memory Options
parser.add_option("--list-mem-types",
action="callback", callback=_listMemTypes,
help="List available memory types")
parser.add_option("--mem-type", type="choice", default="DDR3_1600_x64",
choices=MemConfig.mem_names(),
help = "type of memory to use")
parser.add_option("--mem-channels", type="int", default=1,
help = "number of memory channels")
parser.add_option("--mem-ranks", type="int", default=None,
help = "number of memory ranks per channel")
parser.add_option("--mem-size", action="store", type="string",
default="512MB",
help="Specify the physical memory size (single memory)")
parser.add_option("-l", "--lpae", action="store_true")
parser.add_option("-V", "--virtualisation", action="store_true")
parser.add_option("--memchecker", action="store_true")
# Cache Options
parser.add_option("--external-memory-system", type="string",
help="use external ports of this port_type for caches")
parser.add_option("--tlm-memory", type="string",
help="use external port for SystemC TLM cosimulation")
parser.add_option("--caches", action="store_true")
parser.add_option("--l2cache", action="store_true")
parser.add_option("--fastmem", action="store_true")
parser.add_option("--num-dirs", type="int", default=1)
parser.add_option("--num-l2caches", type="int", default=1)
parser.add_option("--num-l3caches", type="int", default=1)
parser.add_option("--l1d_size", type="string", default="64kB")
parser.add_option("--l1i_size", type="string", default="32kB")
parser.add_option("--l2_size", type="string", default="2MB")
parser.add_option("--l3_size", type="string", default="16MB")
parser.add_option("--l1d_assoc", type="int", default=2)
parser.add_option("--l1i_assoc", type="int", default=2)
parser.add_option("--l2_assoc", type="int", default=8)
parser.add_option("--l3_assoc", type="int", default=16)
parser.add_option("--cacheline_size", type="int", default=64)
#HwiSoo: Fault injection options
parser.add_option("--injectTime", type="int", default="0",
help = "Time to inject fault")
parser.add_option("--injectLoc", type="int", default="0",
help = "Bit location to inject fault")
parser.add_option("--injectArch", type="choice", default="NO",
choices = ["Reg", "FU", "NO", "LSQ", "PipeReg"],
help = "Which architecture do you want to inject fautls? - Default: No injection")
parser.add_option("--checkArch", type="choice", default="NO",
choices = ["Reg", "FU", "NO", "LSQ"],
help = "Which architecture do you want to check fautls? - Default: No injection")
parser.add_option("--injectLSQQueue", type="choice", default="storeBuffer",
choices = ["requests", "storeBuffer", "transfers"],
help = "in LSQ, Which queue do you want to inject fautls? - Default: storeBuffer, other: requests, transfers")
parser.add_option("--pipeRegStage", type="choice", default="dToE",
choices = ["f1ToF2", "f2ToF1", "f2ToD", "dToE", "eToF1"],
help = "Inject a fault to the pipeline register on which stage")
# dist-gem5 options
parser.add_option("--dist", action="store_true",
help="Parallel distributed gem5 simulation.")
parser.add_option("--is-switch", action="store_true",
help="Select the network switch simulator process for a"\
"distributed gem5 run")
parser.add_option("--dist-rank", default=0, action="store", type="int",
help="Rank of this system within the dist gem5 run.")
parser.add_option("--dist-size", default=0, action="store", type="int",
help="Number of gem5 processes within the dist gem5 run.")
parser.add_option("--dist-server-name",
default="127.0.0.1",
action="store", type="string",
help="Name of the message server host\nDEFAULT: localhost")
parser.add_option("--dist-server-port",
default=2200,
action="store", type="int",
help="Message server listen port\nDEFAULT: 2200")
parser.add_option("--dist-sync-repeat",
default="0us",
action="store", type="string",
help="Repeat interval for synchronisation barriers among dist-gem5 processes\nDEFAULT: --ethernet-linkdelay")
parser.add_option("--dist-sync-start",
default="5200000000000t",
action="store", type="string",
help="Time to schedule the first dist synchronisation barrier\nDEFAULT:5200000000000t")
parser.add_option("--ethernet-linkspeed", default="10Gbps",
action="store", type="string",
help="Link speed in bps\nDEFAULT: 10Gbps")
parser.add_option("--ethernet-linkdelay", default="10us",
action="store", type="string",
help="Link delay in seconds\nDEFAULT: 10us")
# Enable Ruby
parser.add_option("--ruby", action="store_true")
# Run duration options
parser.add_option("-m", "--abs-max-tick", type="int", default=m5.MaxTick,
metavar="TICKS", help="Run to absolute simulated tick " \
"specified including ticks from a restored checkpoint")
parser.add_option("--rel-max-tick", type="int", default=None,
metavar="TICKS", help="Simulate for specified number of" \
" ticks relative to the simulation start tick (e.g. if " \
"restoring a checkpoint)")
parser.add_option("--maxtime", type="float", default=None,
help="Run to the specified absolute simulated time in " \
"seconds")
parser.add_option("-I", "--maxinsts", action="store", type="int",
default=None, help="""Total number of instructions to
simulate (default: run forever)""")
parser.add_option("--work-item-id", action="store", type="int",
help="the specific work id for exit & checkpointing")
parser.add_option("--num-work-ids", action="store", type="int",
help="Number of distinct work item types")
parser.add_option("--work-begin-cpu-id-exit", action="store", type="int",
help="exit when work starts on the specified cpu")
parser.add_option("--work-end-exit-count", action="store", type="int",
help="exit at specified work end count")
parser.add_option("--work-begin-exit-count", action="store", type="int",
help="exit at specified work begin count")
parser.add_option("--init-param", action="store", type="int", default=0,
help="""Parameter available in simulation with m5
initparam""")
parser.add_option("--initialize-only", action="store_true", default=False,
help="""Exit after initialization. Do not simulate time.
Useful when gem5 is run as a library.""")
# Simpoint options
parser.add_option("--simpoint-profile", action="store_true",
help="Enable basic block profiling for SimPoints")
parser.add_option("--simpoint-interval", type="int", default=10000000,
help="SimPoint interval in num of instructions")
parser.add_option("--take-simpoint-checkpoints", action="store", type="string",
help="<simpoint file,weight file,interval-length,warmup-length>")
parser.add_option("--restore-simpoint-checkpoint", action="store_true",
help="restore from a simpoint checkpoint taken with " +
"--take-simpoint-checkpoints")
# Checkpointing options
###Note that performing checkpointing via python script files will override
###checkpoint instructions built into binaries.
parser.add_option("--take-checkpoints", action="store", type="string",
help="<M,N> take checkpoints at tick M and every N ticks thereafter")
parser.add_option("--max-checkpoints", action="store", type="int",
help="the maximum number of checkpoints to drop", default=5)
parser.add_option("--checkpoint-dir", action="store", type="string",
help="Place all checkpoints in this absolute directory")
parser.add_option("-r", "--checkpoint-restore", action="store", type="int",
help="restore from checkpoint <N>")
parser.add_option("--checkpoint-at-end", action="store_true",
help="take a checkpoint at end of run")
parser.add_option("--work-begin-checkpoint-count", action="store", type="int",
help="checkpoint at specified work begin count")
parser.add_option("--work-end-checkpoint-count", action="store", type="int",
help="checkpoint at specified work end count")
parser.add_option("--work-cpus-checkpoint-count", action="store", type="int",
help="checkpoint and exit when active cpu count is reached")
parser.add_option("--restore-with-cpu", action="store", type="choice",
default="atomic", choices=CpuConfig.cpu_names(),
help = "cpu type for restoring from a checkpoint")
# CPU Switching - default switch model goes from a checkpoint
# to a timing simple CPU with caches to warm up, then to detailed CPU for
# data measurement
parser.add_option("--repeat-switch", action="store", type="int",
default=None,
help="switch back and forth between CPUs with period <N>")
parser.add_option("-s", "--standard-switch", action="store", type="int",
default=None,
help="switch from timing to Detailed CPU after warmup period of <N>")
parser.add_option("-p", "--prog-interval", type="str",
help="CPU Progress Interval")
# Fastforwarding and simpoint related materials
parser.add_option("-W", "--warmup-insts", action="store", type="int",
default=None,
help="Warmup period in total instructions (requires --standard-switch)")
parser.add_option("--bench", action="store", type="string", default=None,
help="base names for --take-checkpoint and --checkpoint-restore")
parser.add_option("-F", "--fast-forward", action="store", type="string",
default=None,
help="Number of instructions to fast forward before switching")
parser.add_option("-S", "--simpoint", action="store_true", default=False,
help="""Use workload simpoints as an instruction offset for
--checkpoint-restore or --take-checkpoint.""")
parser.add_option("--at-instruction", action="store_true", default=False,
help="""Treat value of --checkpoint-restore or --take-checkpoint as a
number of instructions.""")
parser.add_option("--spec-input", default="ref", type="choice",
choices=["ref", "test", "train", "smred", "mdred",
"lgred"],
help="Input set size for SPEC CPU2000 benchmarks.")
parser.add_option("--arm-iset", default="arm", type="choice",
choices=["arm", "thumb", "aarch64"],
help="ARM instruction set.")
def addSEOptions(parser):
# Benchmark options
parser.add_option("-c", "--cmd", default="",
help="The binary to run in syscall emulation mode.")
parser.add_option("-o", "--options", default="",
help="""The options to pass to the binary, use " "
around the entire string""")
parser.add_option("-e", "--env", default="",
help="Initialize workload environment from text file.")
parser.add_option("-i", "--input", default="",
help="Read stdin from a file.")
parser.add_option("--output", default="",
help="Redirect stdout to a file.")
parser.add_option("--errout", default="",
help="Redirect stderr to a file.")
def addFSOptions(parser):
# Simulation options
parser.add_option("--timesync", action="store_true",
help="Prevent simulated time from getting ahead of real time")
# System options
parser.add_option("--kernel", action="store", type="string")
parser.add_option("--os-type", action="store", type="choice",
choices=os_types[buildEnv['TARGET_ISA']], default="linux",
help="Specifies type of OS to boot")
parser.add_option("--script", action="store", type="string")
parser.add_option("--frame-capture", action="store_true",
help="Stores changed frame buffers from the VNC server to compressed "\
"files in the gem5 output directory")
if buildEnv['TARGET_ISA'] == "arm":
parser.add_option("--bare-metal", action="store_true",
help="Provide the raw system without the linux specific bits")
parser.add_option("--list-machine-types",
action="callback", callback=_listPlatformTypes,
help="List available platform types")
parser.add_option("--machine-type", action="store", type="choice",
choices=PlatformConfig.platform_names(),
default="VExpress_EMM")
parser.add_option("--dtb-filename", action="store", type="string",
help="Specifies device tree blob file to use with device-tree-"\
"enabled kernels")
parser.add_option("--enable-context-switch-stats-dump", \
action="store_true", help="Enable stats dump at context "\
"switches and dump tasks file (required for Streamline)")
# Benchmark options
parser.add_option("--dual", action="store_true",
help="Simulate two systems attached with an ethernet link")
parser.add_option("-b", "--benchmark", action="store", type="string",
dest="benchmark",
help="Specify the benchmark to run. Available benchmarks: %s"\
% DefinedBenchmarks)
# Metafile options
parser.add_option("--etherdump", action="store", type="string", dest="etherdump",
help="Specify the filename to dump a pcap capture of the" \
"ethernet traffic")
# Disk Image Options
parser.add_option("--disk-image", action="store", type="string", default=None,
help="Path to the disk image to use.")
parser.add_option("--root-device", action="store", type="string", default=None,
help="OS device name for root partition")
# Command line options
parser.add_option("--command-line", action="store", type="string",
default=None,
help="Template for the kernel command line.")
parser.add_option("--command-line-file", action="store",
default=None, type="string",
help="File with a template for the kernel command line")
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6171,
27155,
23954,
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,
1898,
334,
67,
9,
8315,
13,
9300,
710,
5044,
24871,
402,
710,
15904,
402,
603,
1158,
528,
290,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
491,
13655,
869,
9648,
199,
199,
646,
333,
21,
199,
504,
333,
21,
14,
14334,
492,
1900,
7744,
199,
504,
333,
21,
14,
1462,
492,
627,
199,
504,
27067,
83,
492,
627,
199,
199,
646,
445,
3165,
2028,
199,
646,
30465,
2028,
199,
646,
16078,
2028,
199,
199,
504,
27500,
2028,
492,
747,
63,
1313,
199,
199,
318,
485,
513,
23214,
4100,
8,
1422,
12,
2450,
12,
574,
12,
1798,
304,
272,
445,
3165,
2028,
14,
1361,
63,
3541,
63,
513,
342,
272,
984,
14,
2224,
8,
16,
9,
199,
199,
318,
485,
513,
14169,
4100,
8,
1422,
12,
2450,
12,
574,
12,
1798,
304,
272,
30465,
2028,
14,
1361,
63,
5286,
63,
513,
342,
272,
984,
14,
2224,
8,
16,
9,
199,
199,
318,
485,
513,
10397,
4100,
8,
1422,
12,
2450,
12,
574,
12,
1798,
304,
272,
16078,
2028,
14,
1361,
63,
3246,
63,
513,
342,
272,
984,
14,
2224,
8,
16,
9,
199,
199,
318,
1050,
7844,
4558,
8,
2087,
304,
272,
327,
2656,
1511,
272,
1798,
14,
525,
63,
1422,
6739,
513,
13,
3541,
13,
1313,
401,
1993,
1595,
628,
3058,
401,
3233,
3699,
513,
23214,
4100,
12,
1993,
1720,
628,
1296,
2808,
11952,
2943,
531,
272,
1798,
14,
525,
63,
1422,
6739,
3541,
13,
466,
401,
730,
628,
5095,
401,
849,
628,
10910,
401,
1993,
3415,
29,
23214,
2028,
14,
3541,
63,
1247,
1062,
1993,
1720,
275,
298,
466,
402,
5033,
370,
1255,
543,
531,
272,
1798,
14,
525,
63,
1422,
6739,
6743,
401,
1595,
628,
1617,
63,
2052,
3547,
272,
1798,
14,
525,
63,
1422,
6096,
78,
401,
4320,
1507,
13,
8896,
401,
730,
628,
442,
401,
849,
29,
17,
9,
272,
1798,
14,
525,
63,
1422,
6739,
1274,
13,
27543,
401,
1595,
628,
1617,
401,
730,
628,
875,
401,
1993,
849,
534,
17,
14,
16,
54,
297,
1993,
1720,
275,
408,
6105,
13,
1896,
29943,
367,
5664,
3879,
737,
2656,
1993,
7074,
17169,
6141,
272,
1798,
14,
525,
63,
1422,
6739,
1274,
13,
9597,
401,
1595,
628,
1617,
401,
730,
628,
875,
401,
1993,
849,
534,
17,
39,
13026,
297,
1993,
1720,
275,
408,
6105,
13,
1896,
12516,
367,
5664,
3879,
737,
2656,
1993,
8112,
6141,
272,
1798,
14,
525,
63,
1422,
6739,
3541,
13,
9597,
401,
1595,
628,
1617,
401,
730,
628,
875,
401,
1993,
849,
534,
18,
39,
13026,
297,
1993,
1720,
628,
17387,
367,
5664,
3879,
737,
11952,
8112,
531,
272,
1798,
14,
525,
63,
1422,
6739,
83,
2037,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
1993,
1720,
275,
408,
1993,
5972,
1202,
340,
3663,
18572,
787,
2013,
14,
982,
2549,
12,
1993,
2066,
314,
1329,
402,
7183,
1126,
5033,
365,
2011,
465,
314,
1993,
1329,
402,
18572,
24887,
272,
1798,
14,
525,
63,
1422,
6739,
15565,
13,
3446,
13,
287,
401,
1595,
628,
1617,
63,
2052,
401,
1993,
1720,
11916,
6476,
12296,
402,
666,
5936,
436,
16329,
1993,
5267,
26365,
1808,
24380,
3307,
22362,
24887,
272,
327,
11680,
570,
3792,
1324,
370,
3307,
22362,
315,
282,
12296,
17625,
436,
1324,
272,
327,
370,
11680,
11952,
315,
282,
24331,
17625,
272,
1798,
14,
525,
63,
1422,
6739,
3615,
13,
3446,
13,
493,
401,
1595,
628,
1617,
401,
730,
628,
875,
401,
1993,
1720,
11916,
17700,
5267,
3307,
570,
1324,
370,
1993,
19509,
11680,
22362,
315,
282,
12296,
17625,
436,
1993,
11680,
11952,
315,
282,
24331,
17625,
7208,
849,
18413
] |
[
1898,
334,
67,
9,
6171,
27155,
23954,
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,
1898,
334,
67,
9,
8315,
13,
9300,
710,
5044,
24871,
402,
710,
15904,
402,
603,
1158,
528,
290,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
7647,
26,
26771,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
27,
199,
3,
26771,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
27,
199,
3,
15564,
314,
536,
402,
314,
4248,
31976,
6590,
314,
1561,
402,
2399,
199,
3,
8417,
1443,
506,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
199,
3,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
3,
6642,
26,
491,
13655,
869,
9648,
199,
199,
646,
333,
21,
199,
504,
333,
21,
14,
14334,
492,
1900,
7744,
199,
504,
333,
21,
14,
1462,
492,
627,
199,
504,
27067,
83,
492,
627,
199,
199,
646,
445,
3165,
2028,
199,
646,
30465,
2028,
199,
646,
16078,
2028,
199,
199,
504,
27500,
2028,
492,
747,
63,
1313,
199,
199,
318,
485,
513,
23214,
4100,
8,
1422,
12,
2450,
12,
574,
12,
1798,
304,
272,
445,
3165,
2028,
14,
1361,
63,
3541,
63,
513,
342,
272,
984,
14,
2224,
8,
16,
9,
199,
199,
318,
485,
513,
14169,
4100,
8,
1422,
12,
2450,
12,
574,
12,
1798,
304,
272,
30465,
2028,
14,
1361,
63,
5286,
63,
513,
342,
272,
984,
14,
2224,
8,
16,
9,
199,
199,
318,
485,
513,
10397,
4100,
8,
1422,
12,
2450,
12,
574,
12,
1798,
304,
272,
16078,
2028,
14,
1361,
63,
3246,
63,
513,
342,
272,
984,
14,
2224,
8,
16,
9,
199,
199,
318,
1050,
7844,
4558,
8,
2087,
304,
272,
327,
2656,
1511,
272,
1798,
14,
525,
63,
1422,
6739,
513,
13,
3541,
13,
1313,
401,
1993,
1595,
628,
3058,
401,
3233,
3699,
513,
23214,
4100,
12,
1993,
1720,
628,
1296,
2808,
11952,
2943,
531,
272,
1798,
14,
525,
63,
1422,
6739,
3541,
13,
466,
401,
730,
628,
5095,
401,
849,
628,
10910,
401,
1993,
3415,
29,
23214,
2028,
14,
3541,
63,
1247,
1062,
1993,
1720,
275,
298,
466,
402,
5033,
370,
1255,
543,
531,
272,
1798,
14,
525,
63,
1422,
6739,
6743,
401,
1595,
628,
1617,
63,
2052,
3547,
272,
1798,
14,
525,
63,
1422,
6096,
78,
401,
4320,
1507,
13,
8896,
401,
730,
628,
442,
401,
849,
29,
17,
9,
272,
1798,
14,
525,
63,
1422,
6739,
1274,
13,
27543,
401,
1595,
628,
1617,
401,
730,
628,
875,
401,
1993,
849,
534,
17,
14,
16,
54,
297,
1993,
1720,
275,
408,
6105,
13,
1896,
29943,
367,
5664,
3879,
737,
2656,
1993,
7074,
17169,
6141,
272,
1798,
14,
525,
63,
1422,
6739,
1274,
13,
9597,
401,
1595,
628,
1617,
401,
730,
628,
875,
401,
1993,
849,
534,
17,
39,
13026,
297,
1993,
1720,
275,
408,
6105,
13,
1896,
12516,
367,
5664,
3879,
737,
2656,
1993,
8112,
6141,
272,
1798,
14,
525,
63,
1422,
6739,
3541,
13,
9597,
401,
1595,
628,
1617,
401,
730,
628,
875,
401,
1993,
849,
534,
18,
39,
13026,
297,
1993,
1720,
628,
17387,
367,
5664,
3879,
737,
11952,
8112,
531,
272,
1798,
14,
525,
63,
1422,
6739,
83,
2037,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
1993,
1720,
275,
408,
1993,
5972,
1202,
340,
3663,
18572,
787,
2013,
14,
982,
2549,
12,
1993,
2066,
314,
1329,
402,
7183,
1126,
5033,
365,
2011,
465,
314,
1993,
1329,
402,
18572,
24887,
272,
1798,
14,
525,
63,
1422,
6739,
15565,
13,
3446,
13,
287,
401,
1595,
628,
1617,
63,
2052,
401,
1993,
1720,
11916,
6476,
12296,
402,
666,
5936,
436,
16329,
1993,
5267,
26365,
1808,
24380,
3307,
22362,
24887,
272,
327,
11680,
570,
3792,
1324,
370,
3307,
22362,
315,
282,
12296,
17625,
436,
1324,
272,
327,
370,
11680,
11952,
315,
282,
24331,
17625,
272,
1798,
14,
525,
63,
1422,
6739,
3615,
13,
3446,
13,
493,
401,
1595,
628,
1617,
401,
730,
628,
875,
401,
1993,
1720,
11916,
17700,
5267,
3307,
570,
1324,
370,
1993,
19509,
11680,
22362,
315,
282,
12296,
17625,
436,
1993,
11680,
11952,
315,
282,
24331,
17625,
7208,
849,
18413,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nhomar/odoo
|
addons/hw_scale/controllers/main.py
|
106
|
6929
|
# -*- coding: utf-8 -*-
import logging
import os
import time
from os import listdir
from os.path import join
from threading import Thread, Lock
from select import select
from Queue import Queue, Empty
import openerp
import openerp.addons.hw_proxy.controllers.main as hw_proxy
from openerp import http
from openerp.http import request
from openerp.tools.translate import _
_logger = logging.getLogger(__name__)
try:
import serial
except ImportError:
_logger.error('Odoo module hw_scale depends on the pyserial python module')
serial = None
class Scale(Thread):
def __init__(self):
Thread.__init__(self)
self.lock = Lock()
self.scalelock = Lock()
self.status = {'status':'connecting', 'messages':[]}
self.input_dir = '/dev/serial/by-id/'
self.weight = 0
self.weight_info = 'ok'
self.device = None
def lockedstart(self):
with self.lock:
if not self.isAlive():
self.daemon = True
self.start()
def set_status(self, status, message = None):
if status == self.status['status']:
if message != None and message != self.status['messages'][-1]:
self.status['messages'].append(message)
else:
self.status['status'] = status
if message:
self.status['messages'] = [message]
else:
self.status['messages'] = []
if status == 'error' and message:
_logger.error('Scale Error: '+message)
elif status == 'disconnected' and message:
_logger.warning('Disconnected Scale: '+message)
def get_device(self):
try:
devices = [ device for device in listdir(self.input_dir)]
scales = [ device for device in devices if ('mettler' in device.lower()) or ('toledo' in device.lower()) ]
if len(scales) > 0:
print join(self.input_dir,scales[0])
self.set_status('connected','Connected to '+scales[0])
return serial.Serial(join(self.input_dir,scales[0]),
baudrate = 9600,
bytesize = serial.SEVENBITS,
stopbits = serial.STOPBITS_ONE,
parity = serial.PARITY_EVEN,
#xonxoff = serial.XON,
timeout = 0.01,
writeTimeout= 0.01)
else:
self.set_status('disconnected','Scale Not Found')
return None
except Exception as e:
self.set_status('error',str(e))
return None
def get_weight(self):
self.lockedstart()
return self.weight
def get_weight_info(self):
self.lockedstart()
return self.weight_info
def get_status(self):
self.lockedstart()
return self.status
def read_weight(self):
with self.scalelock:
if self.device:
try:
self.device.write('W')
time.sleep(0.1)
answer = []
while True:
char = self.device.read(1)
if not char:
break
else:
answer.append(char)
if '?' in answer:
stat = ord(answer[answer.index('?')+1])
if stat == 0:
self.weight_info = 'ok'
else:
self.weight_info = []
if stat & 1 :
self.weight_info.append('moving')
if stat & 1 << 1:
self.weight_info.append('over_capacity')
if stat & 1 << 2:
self.weight_info.append('negative')
self.weight = 0.0
if stat & 1 << 3:
self.weight_info.append('outside_zero_capture_range')
if stat & 1 << 4:
self.weight_info.append('center_of_zero')
if stat & 1 << 5:
self.weight_info.append('net_weight')
else:
answer = answer[1:-1]
if 'N' in answer:
answer = answer[0:-1]
try:
self.weight = float(''.join(answer))
except ValueError as v:
self.set_status('error','No data Received, please power-cycle the scale');
self.device = None
except Exception as e:
self.set_status('error',str(e))
self.device = None
def set_zero(self):
with self.scalelock:
if self.device:
try:
self.device.write('Z')
except Exception as e:
self.set_status('error',str(e))
self.device = None
def set_tare(self):
with self.scalelock:
if self.device:
try:
self.device.write('T')
except Exception as e:
self.set_status('error',str(e))
self.device = None
def clear_tare(self):
with self.scalelock:
if self.device:
try:
self.device.write('C')
except Exception as e:
self.set_status('error',str(e))
self.device = None
def run(self):
self.device = None
while True:
if self.device:
self.read_weight()
time.sleep(0.05)
else:
with self.scalelock:
self.device = self.get_device()
if not self.device:
time.sleep(5)
s = Scale()
hw_proxy.drivers['scale'] = s
class ScaleDriver(hw_proxy.Proxy):
@http.route('/hw_proxy/scale_read/', type='json', auth='none', cors='*')
def scale_read(self):
return {'weight':s.get_weight(), 'unit':'kg', 'info':s.get_weight_info()}
@http.route('/hw_proxy/scale_zero/', type='json', auth='none', cors='*')
def scale_zero(self):
s.set_zero()
return True
@http.route('/hw_proxy/scale_tare/', type='json', auth='none', cors='*')
def scale_tare(self):
s.set_tare()
return True
@http.route('/hw_proxy/scale_clear_tare/', type='json', auth='none', cors='*')
def scale_clear_tare(self):
s.clear_tare()
return True
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2050,
199,
646,
747,
199,
646,
900,
199,
504,
747,
492,
27483,
199,
504,
747,
14,
515,
492,
4263,
199,
504,
5796,
492,
11086,
12,
15536,
199,
504,
3504,
492,
3504,
199,
504,
10703,
492,
10703,
12,
9630,
199,
199,
646,
5166,
199,
646,
5166,
14,
10788,
14,
8090,
63,
3280,
14,
20531,
14,
973,
465,
12073,
63,
3280,
199,
504,
5166,
492,
1455,
199,
504,
5166,
14,
1014,
492,
1056,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
893,
26,
272,
492,
3012,
199,
2590,
3545,
26,
272,
485,
2921,
14,
705,
360,
47,
16766,
859,
12073,
63,
3467,
8350,
641,
314,
1134,
2171,
2366,
859,
358,
272,
3012,
275,
488,
421,
199,
533,
22869,
8,
4436,
304,
272,
347,
636,
826,
721,
277,
304,
267,
11086,
855,
826,
721,
277,
9,
267,
291,
14,
831,
275,
15536,
342,
267,
291,
14,
3467,
831,
275,
15536,
342,
267,
291,
14,
1205,
275,
791,
1205,
5242,
2242,
316,
297,
283,
3431,
356,
8607,
93,
267,
291,
14,
1210,
63,
694,
275,
1994,
2374,
15,
2171,
15,
991,
13,
344,
4805,
267,
291,
14,
3463,
275,
378,
267,
291,
14,
3463,
63,
815,
275,
283,
745,
7,
267,
291,
14,
1782,
275,
488,
339,
347,
14233,
928,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
340,
440,
291,
14,
374,
23692,
837,
355,
291,
14,
10824,
275,
715,
355,
291,
14,
928,
342,
339,
347,
663,
63,
1205,
8,
277,
12,
2004,
12,
1245,
275,
488,
304,
267,
340,
2004,
508,
291,
14,
1205,
459,
1205,
2565,
288,
340,
1245,
1137,
488,
436,
1245,
1137,
291,
14,
1205,
459,
3431,
31942,
17,
2189,
355,
291,
14,
1205,
459,
3431,
2278,
740,
8,
1188,
9,
267,
587,
26,
288,
291,
14,
1205,
459,
1205,
418,
275,
2004,
288,
340,
1245,
26,
355,
291,
14,
1205,
459,
3431,
418,
275,
359,
1188,
61,
288,
587,
26,
355,
291,
14,
1205,
459,
3431,
418,
275,
942,
398,
340,
2004,
508,
283,
705,
7,
436,
1245,
26,
288,
485,
2921,
14,
705,
360,
9944,
4520,
26,
6681,
1188,
9,
267,
916,
2004,
508,
283,
27476,
7,
436,
1245,
26,
288,
485,
2921,
14,
3764,
360,
2825,
7113,
22869,
26,
6681,
1188,
9,
339,
347,
664,
63,
1782,
8,
277,
304,
267,
862,
26,
288,
7256,
275,
359,
2243,
367,
2243,
315,
27483,
8,
277,
14,
1210,
63,
694,
1874,
288,
29823,
221,
275,
359,
2243,
367,
2243,
315,
7256,
340,
661,
10207,
1118,
82,
7,
315,
2243,
14,
2325,
1012,
503,
661,
475,
274,
1117,
7,
315,
2243,
14,
2325,
1012,
1622,
288,
340,
822,
8,
30832,
9,
690,
378,
26,
355,
870,
4263,
8,
277,
14,
1210,
63,
694,
12,
30832,
59,
16,
566,
355,
291,
14,
409,
63,
1205,
360,
7113,
1673,
16382,
370,
6681,
30832,
59,
16,
566,
355,
372,
3012,
14,
3571,
8,
904,
8,
277,
14,
1210,
63,
694,
12,
30832,
59,
16,
2522,
12723,
19325,
27112,
275,
1749,
6683,
12,
12723,
3696,
890,
275,
3012,
14,
899,
8253,
14662,
12,
12723,
3631,
5609,
275,
3012,
14,
11632,
14662,
63,
4817,
12,
12723,
623,
1209,
257,
275,
3012,
14,
4014,
1922,
63,
37,
8253,
12,
12723,
327,
88,
265,
88,
1997,
221,
275,
3012,
14,
56,
615,
12,
717,
2653,
221,
275,
378,
14,
614,
12,
12723,
2218,
6372,
29,
378,
14,
614,
9,
288,
587,
26,
355,
291,
14,
409,
63,
1205,
360,
27476,
1673,
9944,
2832,
2643,
358,
355,
372,
488,
267,
871,
2186,
465,
325,
26,
288,
291,
14,
409,
63,
1205,
360,
705,
297,
495,
8,
69,
430,
288,
372,
488,
339,
347,
664,
63,
3463,
8,
277,
304,
267,
291,
14,
9325,
928,
342,
267,
372,
291,
14,
3463,
339,
347,
664,
63,
3463,
63,
815,
8,
277,
304,
267,
291,
14,
9325,
928,
342,
267,
372,
291,
14,
3463,
63,
815,
2286,
347,
664,
63,
1205,
8,
277,
304,
267,
291,
14,
9325,
928,
342,
267,
372,
291,
14,
1205,
339,
347,
1586,
63,
3463,
8,
277,
304,
267,
543,
291,
14,
3467,
831,
26,
288,
340,
291,
14,
1782,
26,
355,
862,
26,
490,
291,
14,
1782,
14,
952,
360,
55,
358,
490,
900,
14,
4532,
8,
16,
14,
17,
9,
490,
6385,
275,
942,
4951,
1830,
715,
26,
717,
1495,
275,
291,
14,
1782,
14,
739,
8,
17,
9,
717,
340,
440,
1495,
26,
29157,
2059,
717,
587,
26,
1169,
6385,
14,
740,
8,
1560,
9,
4951,
340,
15539,
315,
6385,
26,
717,
5672,
275,
6206,
8,
5934,
59,
5934,
14,
1080,
360,
18478,
11,
17,
566,
717,
340,
5672,
508,
378,
26,
29157,
291,
14,
3463,
63,
815,
275,
283,
745,
7,
717,
587,
26,
1169,
291,
14,
3463,
63,
815,
275,
942,
1169,
340,
5672,
1253,
413,
520,
1816,
291,
14,
3463,
63,
815,
14,
740,
360,
7665,
358,
1169,
340,
5672,
1253,
413,
5213,
413,
26,
1816,
291,
14,
3463,
63,
815,
14,
740,
360,
1883,
63,
10457,
358,
1169,
340,
5672,
1253,
413,
5213,
499,
26,
1816,
291,
14,
3463,
63,
815,
14,
740,
360,
7371,
358,
1816,
291,
14,
3463,
275,
378,
14,
16,
1169,
340,
5672,
1253,
413,
5213,
650,
26,
1816,
291,
14,
3463,
63,
815,
14,
740,
360,
22431,
63,
4262,
63,
12685,
63,
1842,
358,
1169,
340,
5672,
1253,
413,
5213,
841,
26,
1816,
291,
14,
3463,
63,
815,
14,
740,
360,
4218,
63,
1618,
63,
4262,
358,
1169,
340,
5672,
1253,
413,
5213,
959,
26,
1816,
291,
14,
3463,
63,
815,
14,
740,
360,
846,
63,
3463,
358,
490,
587,
26,
717,
6385,
275,
6385,
59,
17,
6809,
17,
61,
717,
340,
283,
46,
7,
315,
6385,
26,
1169,
6385,
275,
6385,
59,
16,
6809,
17,
61,
717,
862,
26,
1169,
291,
14,
3463,
275,
2069,
17840,
904,
8,
5934,
430,
717,
871,
1722,
465,
373,
26,
1169,
291,
14,
409,
63,
1205,
360,
705,
1673,
1944,
666,
799,
2525,
12,
8749,
7074,
13,
7612,
314,
4666,
11339,
1169,
291,
14,
1782,
275,
488,
586,
355,
871,
2186,
465,
325
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
646,
2050,
199,
646,
747,
199,
646,
900,
199,
504,
747,
492,
27483,
199,
504,
747,
14,
515,
492,
4263,
199,
504,
5796,
492,
11086,
12,
15536,
199,
504,
3504,
492,
3504,
199,
504,
10703,
492,
10703,
12,
9630,
199,
199,
646,
5166,
199,
646,
5166,
14,
10788,
14,
8090,
63,
3280,
14,
20531,
14,
973,
465,
12073,
63,
3280,
199,
504,
5166,
492,
1455,
199,
504,
5166,
14,
1014,
492,
1056,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
63,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
199,
199,
893,
26,
272,
492,
3012,
199,
2590,
3545,
26,
272,
485,
2921,
14,
705,
360,
47,
16766,
859,
12073,
63,
3467,
8350,
641,
314,
1134,
2171,
2366,
859,
358,
272,
3012,
275,
488,
421,
199,
533,
22869,
8,
4436,
304,
272,
347,
636,
826,
721,
277,
304,
267,
11086,
855,
826,
721,
277,
9,
267,
291,
14,
831,
275,
15536,
342,
267,
291,
14,
3467,
831,
275,
15536,
342,
267,
291,
14,
1205,
275,
791,
1205,
5242,
2242,
316,
297,
283,
3431,
356,
8607,
93,
267,
291,
14,
1210,
63,
694,
275,
1994,
2374,
15,
2171,
15,
991,
13,
344,
4805,
267,
291,
14,
3463,
275,
378,
267,
291,
14,
3463,
63,
815,
275,
283,
745,
7,
267,
291,
14,
1782,
275,
488,
339,
347,
14233,
928,
8,
277,
304,
267,
543,
291,
14,
831,
26,
288,
340,
440,
291,
14,
374,
23692,
837,
355,
291,
14,
10824,
275,
715,
355,
291,
14,
928,
342,
339,
347,
663,
63,
1205,
8,
277,
12,
2004,
12,
1245,
275,
488,
304,
267,
340,
2004,
508,
291,
14,
1205,
459,
1205,
2565,
288,
340,
1245,
1137,
488,
436,
1245,
1137,
291,
14,
1205,
459,
3431,
31942,
17,
2189,
355,
291,
14,
1205,
459,
3431,
2278,
740,
8,
1188,
9,
267,
587,
26,
288,
291,
14,
1205,
459,
1205,
418,
275,
2004,
288,
340,
1245,
26,
355,
291,
14,
1205,
459,
3431,
418,
275,
359,
1188,
61,
288,
587,
26,
355,
291,
14,
1205,
459,
3431,
418,
275,
942,
398,
340,
2004,
508,
283,
705,
7,
436,
1245,
26,
288,
485,
2921,
14,
705,
360,
9944,
4520,
26,
6681,
1188,
9,
267,
916,
2004,
508,
283,
27476,
7,
436,
1245,
26,
288,
485,
2921,
14,
3764,
360,
2825,
7113,
22869,
26,
6681,
1188,
9,
339,
347,
664,
63,
1782,
8,
277,
304,
267,
862,
26,
288,
7256,
275,
359,
2243,
367,
2243,
315,
27483,
8,
277,
14,
1210,
63,
694,
1874,
288,
29823,
221,
275,
359,
2243,
367,
2243,
315,
7256,
340,
661,
10207,
1118,
82,
7,
315,
2243,
14,
2325,
1012,
503,
661,
475,
274,
1117,
7,
315,
2243,
14,
2325,
1012,
1622,
288,
340,
822,
8,
30832,
9,
690,
378,
26,
355,
870,
4263,
8,
277,
14,
1210,
63,
694,
12,
30832,
59,
16,
566,
355,
291,
14,
409,
63,
1205,
360,
7113,
1673,
16382,
370,
6681,
30832,
59,
16,
566,
355,
372,
3012,
14,
3571,
8,
904,
8,
277,
14,
1210,
63,
694,
12,
30832,
59,
16,
2522,
12723,
19325,
27112,
275,
1749,
6683,
12,
12723,
3696,
890,
275,
3012,
14,
899,
8253,
14662,
12,
12723,
3631,
5609,
275,
3012,
14,
11632,
14662,
63,
4817,
12,
12723,
623,
1209,
257,
275,
3012,
14,
4014,
1922,
63,
37,
8253,
12,
12723,
327,
88,
265,
88,
1997,
221,
275,
3012,
14,
56,
615,
12,
717,
2653,
221,
275,
378,
14,
614,
12,
12723,
2218,
6372,
29,
378,
14,
614,
9,
288,
587,
26,
355,
291,
14,
409,
63,
1205,
360,
27476,
1673,
9944,
2832,
2643,
358,
355,
372,
488,
267,
871,
2186,
465,
325,
26,
288,
291,
14,
409,
63,
1205,
360,
705,
297,
495,
8,
69,
430,
288,
372,
488,
339,
347,
664,
63,
3463,
8,
277,
304,
267,
291,
14,
9325,
928,
342,
267,
372,
291,
14,
3463,
339,
347,
664,
63,
3463,
63,
815,
8,
277,
304,
267,
291,
14,
9325,
928,
342,
267,
372,
291,
14,
3463,
63,
815,
2286,
347,
664,
63,
1205,
8,
277,
304,
267,
291,
14,
9325,
928,
342,
267,
372,
291,
14,
1205,
339,
347,
1586,
63,
3463,
8,
277,
304,
267,
543,
291,
14,
3467,
831,
26,
288,
340,
291,
14,
1782,
26,
355,
862,
26,
490,
291,
14,
1782,
14,
952,
360,
55,
358,
490,
900,
14,
4532,
8,
16,
14,
17,
9,
490,
6385,
275,
942,
4951,
1830,
715,
26,
717,
1495,
275,
291,
14,
1782,
14,
739,
8,
17,
9,
717,
340,
440,
1495,
26,
29157,
2059,
717,
587,
26,
1169,
6385,
14,
740,
8,
1560,
9,
4951,
340,
15539,
315,
6385,
26,
717,
5672,
275,
6206,
8,
5934,
59,
5934,
14,
1080,
360,
18478,
11,
17,
566,
717,
340,
5672,
508,
378,
26,
29157,
291,
14,
3463,
63,
815,
275,
283,
745,
7,
717,
587,
26,
1169,
291,
14,
3463,
63,
815,
275,
942,
1169,
340,
5672,
1253,
413,
520,
1816,
291,
14,
3463,
63,
815,
14,
740,
360,
7665,
358,
1169,
340,
5672,
1253,
413,
5213,
413,
26,
1816,
291,
14,
3463,
63,
815,
14,
740,
360,
1883,
63,
10457,
358,
1169,
340,
5672,
1253,
413,
5213,
499,
26,
1816,
291,
14,
3463,
63,
815,
14,
740,
360,
7371,
358,
1816,
291,
14,
3463,
275,
378,
14,
16,
1169,
340,
5672,
1253,
413,
5213,
650,
26,
1816,
291,
14,
3463,
63,
815,
14,
740,
360,
22431,
63,
4262,
63,
12685,
63,
1842,
358,
1169,
340,
5672,
1253,
413,
5213,
841,
26,
1816,
291,
14,
3463,
63,
815,
14,
740,
360,
4218,
63,
1618,
63,
4262,
358,
1169,
340,
5672,
1253,
413,
5213,
959,
26,
1816,
291,
14,
3463,
63,
815,
14,
740,
360,
846,
63,
3463,
358,
490,
587,
26,
717,
6385,
275,
6385,
59,
17,
6809,
17,
61,
717,
340,
283,
46,
7,
315,
6385,
26,
1169,
6385,
275,
6385,
59,
16,
6809,
17,
61,
717,
862,
26,
1169,
291,
14,
3463,
275,
2069,
17840,
904,
8,
5934,
430,
717,
871,
1722,
465,
373,
26,
1169,
291,
14,
409,
63,
1205,
360,
705,
1673,
1944,
666,
799,
2525,
12,
8749,
7074,
13,
7612,
314,
4666,
11339,
1169,
291,
14,
1782,
275,
488,
586,
355,
871,
2186,
465,
325,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
adblockplus/gyp
|
test/lib/TestMac.py
|
151
|
2472
|
# Copyright (c) 2014 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.
"""
TestMac.py: a collection of helper function shared between test on Mac OS X.
"""
import re
import subprocess
__all__ = ['Xcode', 'CheckFileType']
def CheckFileType(test, file, archs):
"""Check that |file| contains exactly |archs| or fails |test|."""
proc = subprocess.Popen(['lipo', '-info', file], stdout=subprocess.PIPE)
o = proc.communicate()[0].strip()
assert not proc.returncode
if len(archs) == 1:
pattern = re.compile('^Non-fat file: (.*) is architecture: (.*)$')
else:
pattern = re.compile('^Architectures in the fat file: (.*) are: (.*)$')
match = pattern.match(o)
if match is None:
print 'Ouput does not match expected pattern: %s' % (pattern.pattern)
test.fail_test()
else:
found_file, found_archs = match.groups()
if found_file != file or set(found_archs.split()) != set(archs):
print 'Expected file %s with arch %s, got %s with arch %s' % (
file, ' '.join(archs), found_file, found_archs)
test.fail_test()
class XcodeInfo(object):
"""Simplify access to Xcode informations."""
def __init__(self):
self._cache = {}
def _XcodeVersion(self):
lines = subprocess.check_output(['xcodebuild', '-version']).splitlines()
version = ''.join(lines[0].split()[-1].split('.'))
version = (version + '0' * (3 - len(version))).zfill(4)
return version, lines[-1].split()[-1]
def Version(self):
if 'Version' not in self._cache:
self._cache['Version'], self._cache['Build'] = self._XcodeVersion()
return self._cache['Version']
def Build(self):
if 'Build' not in self._cache:
self._cache['Version'], self._cache['Build'] = self._XcodeVersion()
return self._cache['Build']
def SDKBuild(self):
if 'SDKBuild' not in self._cache:
self._cache['SDKBuild'] = subprocess.check_output(
['xcodebuild', '-version', '-sdk', '', 'ProductBuildVersion'])
self._cache['SDKBuild'] = self._cache['SDKBuild'].rstrip('\n')
return self._cache['SDKBuild']
def SDKVersion(self):
if 'SDKVersion' not in self._cache:
self._cache['SDKVersion'] = subprocess.check_output(
['xcodebuild', '-version', '-sdk', '', 'SDKVersion'])
self._cache['SDKVersion'] = self._cache['SDKVersion'].rstrip('\n')
return self._cache['SDKVersion']
Xcode = XcodeInfo()
|
bsd-3-clause
|
[
3,
1898,
334,
67,
9,
6927,
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,
3399,
14,
647,
26,
221,
282,
3245,
402,
5922,
805,
5709,
3382,
511,
641,
10444,
4403,
1323,
14,
199,
624,
199,
199,
646,
295,
199,
646,
3873,
199,
199,
363,
452,
363,
275,
788,
18442,
297,
283,
1799,
20683,
418,
421,
199,
318,
2670,
20683,
8,
396,
12,
570,
12,
32244,
304,
523,
408,
1799,
626,
1204,
493,
92,
3509,
8840,
1204,
24239,
92,
503,
6918,
1204,
396,
92,
1041,
523,
6499,
275,
3873,
14,
7942,
2941,
317,
555,
297,
2475,
815,
297,
570,
467,
3839,
29,
5781,
14,
6089,
9,
523,
312,
275,
6499,
14,
10664,
3430,
16,
1055,
1913,
342,
523,
702,
440,
6499,
14,
9913,
523,
340,
822,
8,
24239,
9,
508,
413,
26,
272,
3851,
275,
295,
14,
2014,
9097,
6932,
13,
23156,
570,
26,
334,
12432,
365,
15931,
26,
334,
12432,
9988,
523,
587,
26,
272,
3851,
275,
295,
14,
2014,
9097,
8438,
1175,
22004,
315,
314,
289,
292,
570,
26,
334,
12432,
787,
26,
334,
12432,
9988,
523,
1336,
275,
3851,
14,
1431,
8,
79,
9,
523,
340,
1336,
365,
488,
26,
272,
870,
283,
47,
384,
337,
1630,
440,
1336,
1420,
3851,
26,
450,
83,
7,
450,
334,
3401,
14,
3401,
9,
272,
511,
14,
1633,
63,
396,
342,
523,
587,
26,
272,
1911,
63,
493,
12,
1911,
63,
24239,
275,
1336,
14,
2634,
342,
272,
340,
1911,
63,
493,
1137,
570,
503,
663,
8,
4214,
63,
24239,
14,
1294,
1012,
1137,
663,
8,
24239,
304,
489,
870,
283,
6964,
570,
450,
83,
543,
3819,
450,
83,
12,
4788,
450,
83,
543,
3819,
450,
83,
7,
450,
334,
881,
570,
12,
283,
1987,
904,
8,
24239,
395,
1911,
63,
493,
12,
1911,
63,
24239,
9,
489,
511,
14,
1633,
63,
396,
342,
421,
199,
533,
10602,
2354,
8,
785,
304,
523,
408,
51,
3236,
8209,
2879,
370,
10602,
315,
17308,
1041,
819,
347,
636,
826,
721,
277,
304,
272,
291,
423,
1637,
275,
1052,
819,
347,
485,
18442,
3353,
8,
277,
304,
272,
2385,
275,
3873,
14,
1074,
63,
1199,
2941,
8701,
1506,
297,
2475,
1023,
13227,
7644,
342,
272,
1015,
275,
6522,
904,
8,
1278,
59,
16,
1055,
1294,
19105,
17,
1055,
1294,
24535,
272,
1015,
275,
334,
1023,
435,
283,
16,
7,
627,
334,
19,
446,
822,
8,
1023,
23261,
26626,
8,
20,
9,
272,
372,
1015,
12,
2385,
1988,
17,
1055,
1294,
19105,
17,
61,
819,
347,
3394,
8,
277,
304,
272,
340,
283,
3353,
7,
440,
315,
291,
423,
1637,
26,
489,
291,
423,
1637,
459,
3353,
995,
291,
423,
1637,
459,
3425,
418,
275,
291,
423,
18442,
3353,
342,
272,
372,
291,
423,
1637,
459,
3353,
418,
819,
347,
6516,
8,
277,
304,
272,
340,
283,
3425,
7,
440,
315,
291,
423,
1637,
26,
489,
291,
423,
1637,
459,
3353,
995,
291,
423,
1637,
459,
3425,
418,
275,
291,
423,
18442,
3353,
342,
272,
372,
291,
423,
1637,
459,
3425,
418,
819,
347,
15610,
3425,
8,
277,
304,
272,
340,
283,
14939,
3425,
7,
440,
315,
291,
423,
1637,
26,
489,
291,
423,
1637,
459,
14939,
3425,
418,
275,
3873,
14,
1074,
63,
1199,
8,
881,
788,
8701,
1506,
297,
2475,
1023,
297,
2475,
9277,
297,
3260,
283,
5884,
3425,
3353,
1105,
489,
291,
423,
1637,
459,
14939,
3425,
418,
275,
291,
423,
1637,
459,
14939,
3425,
2278,
6735,
2258,
78,
358,
272,
372,
291,
423,
1637,
459,
14939,
3425,
418,
819,
347,
15610,
3353,
8,
277,
304,
272,
340,
283,
14939,
3353,
7,
440,
315,
291,
423,
1637,
26,
489,
291,
423,
1637,
459,
14939,
3353,
418,
275,
3873,
14,
1074,
63,
1199,
8,
881,
788,
8701,
1506,
297,
2475,
1023,
297,
2475,
9277,
297,
3260,
283,
14939,
3353,
1105,
489,
291,
423,
1637,
459,
14939,
3353,
418,
275,
291,
423,
1637,
459,
14939,
3353,
2278,
6735,
2258,
78,
358,
272,
372,
291,
423,
1637,
459,
14939,
3353,
418,
421,
199,
18442,
275,
10602,
2354,
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
] |
[
1898,
334,
67,
9,
6927,
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,
3399,
14,
647,
26,
221,
282,
3245,
402,
5922,
805,
5709,
3382,
511,
641,
10444,
4403,
1323,
14,
199,
624,
199,
199,
646,
295,
199,
646,
3873,
199,
199,
363,
452,
363,
275,
788,
18442,
297,
283,
1799,
20683,
418,
421,
199,
318,
2670,
20683,
8,
396,
12,
570,
12,
32244,
304,
523,
408,
1799,
626,
1204,
493,
92,
3509,
8840,
1204,
24239,
92,
503,
6918,
1204,
396,
92,
1041,
523,
6499,
275,
3873,
14,
7942,
2941,
317,
555,
297,
2475,
815,
297,
570,
467,
3839,
29,
5781,
14,
6089,
9,
523,
312,
275,
6499,
14,
10664,
3430,
16,
1055,
1913,
342,
523,
702,
440,
6499,
14,
9913,
523,
340,
822,
8,
24239,
9,
508,
413,
26,
272,
3851,
275,
295,
14,
2014,
9097,
6932,
13,
23156,
570,
26,
334,
12432,
365,
15931,
26,
334,
12432,
9988,
523,
587,
26,
272,
3851,
275,
295,
14,
2014,
9097,
8438,
1175,
22004,
315,
314,
289,
292,
570,
26,
334,
12432,
787,
26,
334,
12432,
9988,
523,
1336,
275,
3851,
14,
1431,
8,
79,
9,
523,
340,
1336,
365,
488,
26,
272,
870,
283,
47,
384,
337,
1630,
440,
1336,
1420,
3851,
26,
450,
83,
7,
450,
334,
3401,
14,
3401,
9,
272,
511,
14,
1633,
63,
396,
342,
523,
587,
26,
272,
1911,
63,
493,
12,
1911,
63,
24239,
275,
1336,
14,
2634,
342,
272,
340,
1911,
63,
493,
1137,
570,
503,
663,
8,
4214,
63,
24239,
14,
1294,
1012,
1137,
663,
8,
24239,
304,
489,
870,
283,
6964,
570,
450,
83,
543,
3819,
450,
83,
12,
4788,
450,
83,
543,
3819,
450,
83,
7,
450,
334,
881,
570,
12,
283,
1987,
904,
8,
24239,
395,
1911,
63,
493,
12,
1911,
63,
24239,
9,
489,
511,
14,
1633,
63,
396,
342,
421,
199,
533,
10602,
2354,
8,
785,
304,
523,
408,
51,
3236,
8209,
2879,
370,
10602,
315,
17308,
1041,
819,
347,
636,
826,
721,
277,
304,
272,
291,
423,
1637,
275,
1052,
819,
347,
485,
18442,
3353,
8,
277,
304,
272,
2385,
275,
3873,
14,
1074,
63,
1199,
2941,
8701,
1506,
297,
2475,
1023,
13227,
7644,
342,
272,
1015,
275,
6522,
904,
8,
1278,
59,
16,
1055,
1294,
19105,
17,
1055,
1294,
24535,
272,
1015,
275,
334,
1023,
435,
283,
16,
7,
627,
334,
19,
446,
822,
8,
1023,
23261,
26626,
8,
20,
9,
272,
372,
1015,
12,
2385,
1988,
17,
1055,
1294,
19105,
17,
61,
819,
347,
3394,
8,
277,
304,
272,
340,
283,
3353,
7,
440,
315,
291,
423,
1637,
26,
489,
291,
423,
1637,
459,
3353,
995,
291,
423,
1637,
459,
3425,
418,
275,
291,
423,
18442,
3353,
342,
272,
372,
291,
423,
1637,
459,
3353,
418,
819,
347,
6516,
8,
277,
304,
272,
340,
283,
3425,
7,
440,
315,
291,
423,
1637,
26,
489,
291,
423,
1637,
459,
3353,
995,
291,
423,
1637,
459,
3425,
418,
275,
291,
423,
18442,
3353,
342,
272,
372,
291,
423,
1637,
459,
3425,
418,
819,
347,
15610,
3425,
8,
277,
304,
272,
340,
283,
14939,
3425,
7,
440,
315,
291,
423,
1637,
26,
489,
291,
423,
1637,
459,
14939,
3425,
418,
275,
3873,
14,
1074,
63,
1199,
8,
881,
788,
8701,
1506,
297,
2475,
1023,
297,
2475,
9277,
297,
3260,
283,
5884,
3425,
3353,
1105,
489,
291,
423,
1637,
459,
14939,
3425,
418,
275,
291,
423,
1637,
459,
14939,
3425,
2278,
6735,
2258,
78,
358,
272,
372,
291,
423,
1637,
459,
14939,
3425,
418,
819,
347,
15610,
3353,
8,
277,
304,
272,
340,
283,
14939,
3353,
7,
440,
315,
291,
423,
1637,
26,
489,
291,
423,
1637,
459,
14939,
3353,
418,
275,
3873,
14,
1074,
63,
1199,
8,
881,
788,
8701,
1506,
297,
2475,
1023,
297,
2475,
9277,
297,
3260,
283,
14939,
3353,
1105,
489,
291,
423,
1637,
459,
14939,
3353,
418,
275,
291,
423,
1637,
459,
14939,
3353,
2278,
6735,
2258,
78,
358,
272,
372,
291,
423,
1637,
459,
14939,
3353,
418,
421,
199,
18442,
275,
10602,
2354,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
vigor/vigor_aosp_kernel
|
tools/perf/scripts/python/failed-syscalls-by-pid.py
|
11180
|
2058
|
# failed system call counts, by pid
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Displays system-wide failed system call totals, broken down by pid.
# 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 *
usage = "perf script -s syscall-counts-by-pid.py [comm|pid]\n";
for_comm = None
for_pid = None
if len(sys.argv) > 2:
sys.exit(usage)
if len(sys.argv) > 1:
try:
for_pid = int(sys.argv[1])
except:
for_comm = sys.argv[1]
syscalls = autodict()
def trace_begin():
print "Press control+C to stop and show the summary"
def trace_end():
print_error_totals()
def raw_syscalls__sys_exit(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, ret):
if (for_comm and common_comm != for_comm) or \
(for_pid and common_pid != for_pid ):
return
if ret < 0:
try:
syscalls[common_comm][common_pid][id][ret] += 1
except TypeError:
syscalls[common_comm][common_pid][id][ret] = 1
def print_error_totals():
if for_comm is not None:
print "\nsyscall errors for %s:\n\n" % (for_comm),
else:
print "\nsyscall errors:\n\n",
print "%-30s %10s\n" % ("comm [pid]", "count"),
print "%-30s %10s\n" % ("------------------------------", \
"----------"),
comm_keys = syscalls.keys()
for comm in comm_keys:
pid_keys = syscalls[comm].keys()
for pid in pid_keys:
print "\n%s [%d]\n" % (comm, pid),
id_keys = syscalls[comm][pid].keys()
for id in id_keys:
print " syscall: %-16s\n" % syscall_name(id),
ret_keys = syscalls[comm][pid][id].keys()
for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True):
print " err = %-20s %10d\n" % (strerror(ret), val),
|
gpl-2.0
|
[
3,
3405,
2656,
1240,
8242,
12,
701,
4422,
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,
3405,
2656,
1240,
23576,
12,
10529,
3224,
701,
4422,
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,
627,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
13,
991,
13,
3150,
14,
647,
359,
1404,
92,
3150,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
509,
63,
3150,
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,
893,
26,
507,
198,
509,
63,
3150,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
26,
507,
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,
705,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
2224,
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,
2203,
304,
199,
198,
692,
334,
509,
63,
1404,
436,
2863,
63,
1404,
1137,
367,
63,
1404,
9,
503,
971,
21979,
334,
509,
63,
3150,
221,
436,
2863,
63,
3150,
221,
1137,
367,
63,
3150,
3461,
507,
198,
1107,
421,
198,
692,
2203,
665,
378,
26,
507,
198,
893,
26,
686,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
1527,
3292,
61,
847,
413,
507,
198,
2590,
3146,
26,
686,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
1527,
3292,
61,
275,
413,
199,
199,
318,
870,
63,
705,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
2552,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
2552,
3427,
78,
60,
78,
401,
339,
870,
18301,
1216,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1404,
359,
3150,
11472,
298,
835,
1288,
272,
870,
18301,
1216,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
777,
10965,
401,
971,
639,
298,
9460,
1288,
339,
1923,
63,
1612,
275,
19473,
14,
1612,
342,
272,
367,
1923,
315,
1923,
63,
1612,
26,
6722,
4422,
63,
1612,
275,
19473,
59,
1404,
1055,
1612,
342,
6722,
367,
4422,
315,
4422,
63,
1612,
26,
15075,
870,
1867,
78,
5,
83,
8978,
68,
7272,
78,
2,
450,
334,
1404,
12,
4422,
395,
15075,
1305,
63,
1612,
275,
19473,
59,
1404,
1527,
3150,
1055,
1612,
342,
15075,
367,
1305,
315,
1305,
63,
1612,
26,
24449,
870,
298,
221,
18901,
26,
19752,
975,
83,
60,
78,
2,
450,
18901,
63,
354,
8,
344,
395,
24449,
2203,
63,
1612,
275,
19473,
59,
1404,
1527,
3150,
1527,
344,
1055,
1612,
342,
24449,
367,
2203,
12,
1139,
315,
3355,
8,
14507,
59,
1404,
1527,
3150,
1527,
344,
1055,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
221,
3837,
275,
715,
304,
1871,
259,
870,
298,
259,
2329,
275,
19752,
1165,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
20395,
8,
3292,
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
] |
[
3405,
2656,
1240,
8242,
12,
701,
4422,
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,
3405,
2656,
1240,
23576,
12,
10529,
3224,
701,
4422,
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,
627,
199,
199,
3807,
275,
298,
9452,
2884,
446,
83,
18901,
13,
6851,
13,
991,
13,
3150,
14,
647,
359,
1404,
92,
3150,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
509,
63,
3150,
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,
893,
26,
507,
198,
509,
63,
3150,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
26,
507,
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,
705,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
2224,
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,
2203,
304,
199,
198,
692,
334,
509,
63,
1404,
436,
2863,
63,
1404,
1137,
367,
63,
1404,
9,
503,
971,
21979,
334,
509,
63,
3150,
221,
436,
2863,
63,
3150,
221,
1137,
367,
63,
3150,
3461,
507,
198,
1107,
421,
198,
692,
2203,
665,
378,
26,
507,
198,
893,
26,
686,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
1527,
3292,
61,
847,
413,
507,
198,
2590,
3146,
26,
686,
198,
14507,
59,
2330,
63,
1404,
1527,
2330,
63,
3150,
1527,
344,
1527,
3292,
61,
275,
413,
199,
199,
318,
870,
63,
705,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
2552,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
2552,
3427,
78,
60,
78,
401,
339,
870,
18301,
1216,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1404,
359,
3150,
11472,
298,
835,
1288,
272,
870,
18301,
1216,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
777,
10965,
401,
971,
639,
298,
9460,
1288,
339,
1923,
63,
1612,
275,
19473,
14,
1612,
342,
272,
367,
1923,
315,
1923,
63,
1612,
26,
6722,
4422,
63,
1612,
275,
19473,
59,
1404,
1055,
1612,
342,
6722,
367,
4422,
315,
4422,
63,
1612,
26,
15075,
870,
1867,
78,
5,
83,
8978,
68,
7272,
78,
2,
450,
334,
1404,
12,
4422,
395,
15075,
1305,
63,
1612,
275,
19473,
59,
1404,
1527,
3150,
1055,
1612,
342,
15075,
367,
1305,
315,
1305,
63,
1612,
26,
24449,
870,
298,
221,
18901,
26,
19752,
975,
83,
60,
78,
2,
450,
18901,
63,
354,
8,
344,
395,
24449,
2203,
63,
1612,
275,
19473,
59,
1404,
1527,
3150,
1527,
344,
1055,
1612,
342,
24449,
367,
2203,
12,
1139,
315,
3355,
8,
14507,
59,
1404,
1527,
3150,
1527,
344,
1055,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
221,
3837,
275,
715,
304,
1871,
259,
870,
298,
259,
2329,
275,
19752,
1165,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
20395,
8,
3292,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
davidhax0r/Rocket
|
flask/lib/python2.7/site-packages/setuptools/site-patch.py
|
358
|
2418
|
def __boot():
import sys, os, os.path
PYTHONPATH = os.environ.get('PYTHONPATH')
if PYTHONPATH is None or (sys.platform=='win32' and not PYTHONPATH):
PYTHONPATH = []
else:
PYTHONPATH = PYTHONPATH.split(os.pathsep)
pic = getattr(sys,'path_importer_cache',{})
stdpath = sys.path[len(PYTHONPATH):]
mydir = os.path.dirname(__file__)
#print "searching",stdpath,sys.path
for item in stdpath:
if item==mydir or not item:
continue # skip if current dir. on Windows, or my own directory
importer = pic.get(item)
if importer is not None:
loader = importer.find_module('site')
if loader is not None:
# This should actually reload the current module
loader.load_module('site')
break
else:
try:
import imp # Avoid import loop in Python >= 3.3
stream, path, descr = imp.find_module('site',[item])
except ImportError:
continue
if stream is None:
continue
try:
# This should actually reload the current module
imp.load_module('site',stream,path,descr)
finally:
stream.close()
break
else:
raise ImportError("Couldn't find the real 'site' module")
#print "loaded", __file__
known_paths = dict([(makepath(item)[1],1) for item in sys.path]) # 2.2 comp
oldpos = getattr(sys,'__egginsert',0) # save old insertion position
sys.__egginsert = 0 # and reset the current one
for item in PYTHONPATH:
addsitedir(item)
sys.__egginsert += oldpos # restore effective old position
d,nd = makepath(stdpath[0])
insert_at = None
new_path = []
for item in sys.path:
p,np = makepath(item)
if np==nd and insert_at is None:
# We've hit the first 'system' path entry, so added entries go here
insert_at = len(new_path)
if np in known_paths or insert_at is None:
new_path.append(item)
else:
# new path after the insert point, back-insert it
new_path.insert(insert_at, item)
insert_at += 1
sys.path[:] = new_path
if __name__=='site':
__boot()
del __boot
|
mit
|
[
318,
636,
4930,
837,
272,
492,
984,
12,
747,
12,
747,
14,
515,
272,
31176,
275,
747,
14,
2314,
14,
362,
360,
29266,
358,
272,
340,
31176,
365,
488,
503,
334,
1274,
14,
3246,
6803,
2676,
708,
7,
436,
440,
31176,
304,
267,
31176,
275,
942,
272,
587,
26,
267,
31176,
275,
31176,
14,
1294,
8,
736,
14,
17843,
9,
339,
26559,
275,
2519,
8,
1274,
2584,
515,
63,
12138,
63,
1637,
297,
91,
1552,
272,
2418,
515,
275,
984,
14,
515,
59,
552,
8,
29266,
15405,
272,
3002,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
272,
327,
1361,
298,
1733,
316,
401,
1516,
515,
12,
1274,
14,
515,
339,
367,
1242,
315,
2418,
515,
26,
267,
340,
1242,
389,
1662,
694,
503,
440,
1242,
26,
288,
1980,
259,
327,
3372,
340,
1453,
2935,
14,
641,
5417,
12,
503,
3002,
5705,
2082,
267,
13479,
275,
26559,
14,
362,
8,
1053,
9,
267,
340,
13479,
365,
440,
488,
26,
288,
5077,
275,
13479,
14,
1623,
63,
578,
360,
2124,
358,
288,
340,
5077,
365,
440,
488,
26,
355,
327,
961,
1077,
5965,
13101,
314,
1453,
859,
355,
5077,
14,
912,
63,
578,
360,
2124,
358,
355,
2059,
267,
587,
26,
288,
862,
26,
355,
492,
1742,
327,
19503,
492,
4438,
315,
2018,
2356,
650,
14,
19,
355,
2547,
12,
931,
12,
16193,
275,
1742,
14,
1623,
63,
578,
360,
2124,
23993,
1053,
566,
288,
871,
3545,
26,
355,
1980,
288,
340,
2547,
365,
488,
26,
355,
1980,
288,
862,
26,
355,
327,
961,
1077,
5965,
13101,
314,
1453,
859,
355,
1742,
14,
912,
63,
578,
360,
2124,
297,
1745,
12,
515,
12,
12113,
9,
288,
3753,
26,
355,
2547,
14,
1600,
342,
288,
2059,
272,
587,
26,
267,
746,
3545,
480,
20485,
1133,
2342,
314,
3363,
283,
2124,
7,
859,
531,
339,
327,
1361,
298,
4591,
401,
636,
493,
363,
339,
6040,
63,
3771,
275,
1211,
7694,
1875,
515,
8,
1053,
2788,
17,
467,
17,
9,
367,
1242,
315,
984,
14,
515,
566,
327,
499,
14,
18,
1013,
339,
2269,
1712,
275,
2519,
8,
1274,
2584,
363,
5902,
903,
407,
297,
16,
9,
257,
327,
3354,
2269,
22470,
3421,
272,
984,
855,
5902,
903,
407,
275,
378,
9326,
327,
436,
5305,
314,
1453,
1373,
339,
367,
1242,
315,
31176,
26,
267,
1050,
2124,
694,
8,
1053,
9,
339,
984,
855,
5902,
903,
407,
847,
2269,
1712,
3698,
327,
9066,
15826,
2269,
3421,
2286,
366,
12,
977,
275,
1852,
515,
8,
1516,
515,
59,
16,
566,
272,
5518,
63,
292,
275,
488,
272,
892,
63,
515,
275,
942,
339,
367,
1242,
315,
984,
14,
515,
26,
267,
299,
12,
1590,
275,
1852,
515,
8,
1053,
9,
398,
340,
980,
389,
977,
436,
5518,
63,
292,
365,
488,
26,
288,
327,
2136,
9064,
9793,
314,
1642,
283,
2253,
7,
931,
2397,
12,
880,
3483,
4811,
2621,
2348,
288,
5518,
63,
292,
275,
822,
8,
1222,
63,
515,
9,
398,
340,
980,
315,
6040,
63,
3771,
503,
5518,
63,
292,
365,
488,
26,
288,
892,
63,
515,
14,
740,
8,
1053,
9,
267,
587,
26,
288,
327,
892,
931,
2410,
314,
5518,
2376,
12,
1771,
13,
3176,
652,
288,
892,
63,
515,
14,
3176,
8,
3176,
63,
292,
12,
1242,
9,
288,
5518,
63,
292,
847,
413,
15567,
984,
14,
515,
5873,
275,
892,
63,
515,
199,
199,
692,
636,
354,
363,
6803,
2124,
356,
14821,
636,
4930,
342,
272,
2150,
636,
4930,
1362,
17344,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
4930,
837,
272,
492,
984,
12,
747,
12,
747,
14,
515,
272,
31176,
275,
747,
14,
2314,
14,
362,
360,
29266,
358,
272,
340,
31176,
365,
488,
503,
334,
1274,
14,
3246,
6803,
2676,
708,
7,
436,
440,
31176,
304,
267,
31176,
275,
942,
272,
587,
26,
267,
31176,
275,
31176,
14,
1294,
8,
736,
14,
17843,
9,
339,
26559,
275,
2519,
8,
1274,
2584,
515,
63,
12138,
63,
1637,
297,
91,
1552,
272,
2418,
515,
275,
984,
14,
515,
59,
552,
8,
29266,
15405,
272,
3002,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
272,
327,
1361,
298,
1733,
316,
401,
1516,
515,
12,
1274,
14,
515,
339,
367,
1242,
315,
2418,
515,
26,
267,
340,
1242,
389,
1662,
694,
503,
440,
1242,
26,
288,
1980,
259,
327,
3372,
340,
1453,
2935,
14,
641,
5417,
12,
503,
3002,
5705,
2082,
267,
13479,
275,
26559,
14,
362,
8,
1053,
9,
267,
340,
13479,
365,
440,
488,
26,
288,
5077,
275,
13479,
14,
1623,
63,
578,
360,
2124,
358,
288,
340,
5077,
365,
440,
488,
26,
355,
327,
961,
1077,
5965,
13101,
314,
1453,
859,
355,
5077,
14,
912,
63,
578,
360,
2124,
358,
355,
2059,
267,
587,
26,
288,
862,
26,
355,
492,
1742,
327,
19503,
492,
4438,
315,
2018,
2356,
650,
14,
19,
355,
2547,
12,
931,
12,
16193,
275,
1742,
14,
1623,
63,
578,
360,
2124,
23993,
1053,
566,
288,
871,
3545,
26,
355,
1980,
288,
340,
2547,
365,
488,
26,
355,
1980,
288,
862,
26,
355,
327,
961,
1077,
5965,
13101,
314,
1453,
859,
355,
1742,
14,
912,
63,
578,
360,
2124,
297,
1745,
12,
515,
12,
12113,
9,
288,
3753,
26,
355,
2547,
14,
1600,
342,
288,
2059,
272,
587,
26,
267,
746,
3545,
480,
20485,
1133,
2342,
314,
3363,
283,
2124,
7,
859,
531,
339,
327,
1361,
298,
4591,
401,
636,
493,
363,
339,
6040,
63,
3771,
275,
1211,
7694,
1875,
515,
8,
1053,
2788,
17,
467,
17,
9,
367,
1242,
315,
984,
14,
515,
566,
327,
499,
14,
18,
1013,
339,
2269,
1712,
275,
2519,
8,
1274,
2584,
363,
5902,
903,
407,
297,
16,
9,
257,
327,
3354,
2269,
22470,
3421,
272,
984,
855,
5902,
903,
407,
275,
378,
9326,
327,
436,
5305,
314,
1453,
1373,
339,
367,
1242,
315,
31176,
26,
267,
1050,
2124,
694,
8,
1053,
9,
339,
984,
855,
5902,
903,
407,
847,
2269,
1712,
3698,
327,
9066,
15826,
2269,
3421,
2286,
366,
12,
977,
275,
1852,
515,
8,
1516,
515,
59,
16,
566,
272,
5518,
63,
292,
275,
488,
272,
892,
63,
515,
275,
942,
339,
367,
1242,
315,
984,
14,
515,
26,
267,
299,
12,
1590,
275,
1852,
515,
8,
1053,
9,
398,
340,
980,
389,
977,
436,
5518,
63,
292,
365,
488,
26,
288,
327,
2136,
9064,
9793,
314,
1642,
283,
2253,
7,
931,
2397,
12,
880,
3483,
4811,
2621,
2348,
288,
5518,
63,
292,
275,
822,
8,
1222,
63,
515,
9,
398,
340,
980,
315,
6040,
63,
3771,
503,
5518,
63,
292,
365,
488,
26,
288,
892,
63,
515,
14,
740,
8,
1053,
9,
267,
587,
26,
288,
327,
892,
931,
2410,
314,
5518,
2376,
12,
1771,
13,
3176,
652,
288,
892,
63,
515,
14,
3176,
8,
3176,
63,
292,
12,
1242,
9,
288,
5518,
63,
292,
847,
413,
15567,
984,
14,
515,
5873,
275,
892,
63,
515,
199,
199,
692,
636,
354,
363,
6803,
2124,
356,
14821,
636,
4930,
342,
272,
2150,
636,
4930,
1362,
17344,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
levkar/odoo
|
addons/sale_order_dates/models/sale_order.py
|
17
|
4154
|
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from datetime import timedelta
from odoo import api, fields, models, _
class SaleOrder(models.Model):
"""Add several date fields to Sale Orders, computed or user-entered"""
_inherit = 'sale.order'
commitment_date = fields.Datetime(compute='_compute_commitment_date', string='Commitment Date', store=True,
help="Date by which the products are sure to be delivered. This is "
"a date that you can promise to the customer, based on the "
"Product Lead Times.")
requested_date = fields.Datetime('Requested Date', readonly=True, states={'draft': [('readonly', False)],
'sent': [('readonly', False)]}, copy=False,
help="Date by which the customer has requested the items to be "
"delivered.\n"
"When this Order gets confirmed, the Delivery Order's "
"expected date will be computed based on this date and the "
"Company's Security Delay.\n"
"Leave this field empty if you want the Delivery Order to be "
"processed as soon as possible. In that case the expected "
"date will be computed using the default method: based on "
"the Product Lead Times and the Company's Security Delay.")
effective_date = fields.Date(compute='_compute_picking_ids', string='Effective Date', store=True,
help="Date on which the first Delivery Order was created.")
@api.depends('date_order', 'order_line.customer_lead')
def _compute_commitment_date(self):
"""Compute the commitment date"""
for order in self:
dates_list = []
order_datetime = fields.Datetime.from_string(order.date_order)
for line in order.order_line.filtered(lambda x: x.state != 'cancel'):
dt = order_datetime + timedelta(days=line.customer_lead or 0.0)
dates_list.append(dt)
if dates_list:
commit_date = min(dates_list) if order.picking_policy == 'direct' else max(dates_list)
order.commitment_date = fields.Datetime.to_string(commit_date)
def _compute_picking_ids(self):
super(SaleOrder, self)._compute_picking_ids()
for order in self:
dates_list = []
for pick in order.picking_ids:
dates_list.append(fields.Datetime.from_string(pick.date))
if dates_list:
order.effective_date = fields.Datetime.to_string(min(dates_list))
@api.onchange('requested_date')
def onchange_requested_date(self):
"""Warn if the requested dates is sooner than the commitment date"""
if (self.requested_date and self.commitment_date and self.requested_date < self.commitment_date):
return {'warning': {
'title': _('Requested date is too soon!'),
'message': _("The date requested by the customer is "
"sooner than the commitment date. You may be "
"unable to honor the customer's request.")
}
}
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
@api.multi
def _prepare_order_line_procurement(self, group_id):
vals = super(SaleOrderLine, self)._prepare_order_line_procurement(group_id=group_id)
for line in self.filtered("order_id.requested_date"):
date_planned = fields.Datetime.from_string(line.order_id.requested_date) - timedelta(days=line.order_id.company_id.security_lead)
vals.update({
'date_planned': fields.Datetime.to_string(date_planned),
})
return vals
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
199,
199,
504,
2197,
492,
6871,
199,
504,
28811,
492,
2986,
12,
1504,
12,
1709,
12,
485,
421,
199,
533,
428,
1895,
4738,
8,
992,
14,
1685,
304,
272,
408,
1123,
9978,
1434,
1504,
370,
428,
1895,
4236,
7735,
12,
9235,
503,
922,
13,
287,
3014,
624,
272,
485,
6486,
275,
283,
8515,
14,
1648,
7,
339,
5532,
434,
63,
602,
275,
1504,
14,
19636,
8,
3357,
17574,
3357,
63,
3543,
434,
63,
602,
297,
1059,
534,
11421,
434,
6148,
297,
3877,
29,
549,
12,
4228,
1720,
628,
2506,
701,
1314,
314,
7585,
787,
3238,
370,
506,
28218,
14,
961,
365,
298,
5644,
298,
65,
1434,
626,
1265,
883,
8023,
572,
370,
314,
15229,
12,
4079,
641,
314,
298,
5644,
298,
5884,
7005,
350,
4703,
83,
2685,
272,
5839,
63,
602,
275,
1504,
14,
19636,
360,
17935,
6148,
297,
6863,
29,
549,
12,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
4360,
3660,
283,
1150,
356,
4274,
6753,
297,
756,
26804,
1331,
29,
797,
12,
3660,
1720,
628,
2506,
701,
1314,
314,
15229,
965,
5839,
314,
2974,
370,
506,
298,
5101,
298,
30480,
3134,
78,
2,
5101,
298,
11423,
642,
9240,
7545,
22763,
12,
314,
1487,
317,
2588,
9240,
1159,
298,
5101,
298,
2062,
1434,
911,
506,
9235,
4079,
641,
642,
1434,
436,
314,
298,
5101,
298,
16063,
1159,
13863,
18464,
1187,
3134,
78,
2,
5101,
298,
23679,
642,
901,
2701,
340,
1265,
2934,
314,
1487,
317,
2588,
9240,
370,
506,
298,
5101,
298,
7292,
465,
18930,
465,
3962,
14,
1010,
626,
1930,
314,
1420,
298,
5101,
298,
602,
911,
506,
9235,
1808,
314,
849,
1083,
26,
4079,
641,
298,
5101,
298,
1589,
12705,
7005,
350,
4703,
83,
436,
314,
15878,
1159,
13863,
18464,
1187,
2685,
272,
15826,
63,
602,
275,
1504,
14,
2506,
8,
3357,
17574,
3357,
63,
11463,
63,
1580,
297,
1059,
534,
30754,
6148,
297,
3877,
29,
549,
12,
639,
1720,
628,
2506,
641,
1314,
314,
1642,
1487,
317,
2588,
9240,
1990,
2737,
2685,
339,
768,
1246,
14,
8912,
360,
602,
63,
1648,
297,
283,
1648,
63,
604,
14,
10178,
63,
13799,
358,
272,
347,
485,
3357,
63,
3543,
434,
63,
602,
8,
277,
304,
267,
408,
8564,
314,
5532,
434,
1434,
624,
267,
367,
1865,
315,
291,
26,
288,
10831,
63,
513,
275,
942,
288,
1865,
63,
2083,
275,
1504,
14,
19636,
14,
504,
63,
875,
8,
1648,
14,
602,
63,
1648,
9,
288,
367,
1004,
315,
1865,
14,
1648,
63,
604,
14,
11142,
8,
2734,
671,
26,
671,
14,
929,
1137,
283,
6406,
735,
355,
4487,
275,
1865,
63,
2083,
435,
6871,
8,
4899,
29,
604,
14,
10178,
63,
13799,
503,
378,
14,
16,
9,
355,
10831,
63,
513,
14,
740,
8,
3583,
9,
288,
340,
10831,
63,
513,
26,
355,
5532,
63,
602,
275,
1748,
8,
9356,
63,
513,
9,
340,
1865,
14,
11463,
63,
3185,
508,
283,
2275,
7,
587,
1390,
8,
9356,
63,
513,
9,
355,
1865,
14,
3543,
434,
63,
602,
275,
1504,
14,
19636,
14,
475,
63,
875,
8,
3543,
63,
602,
9,
339,
347,
485,
3357,
63,
11463,
63,
1580,
8,
277,
304,
267,
1613,
8,
30005,
4738,
12,
291,
10445,
3357,
63,
11463,
63,
1580,
342,
267,
367,
1865,
315,
291,
26,
288,
10831,
63,
513,
275,
942,
288,
367,
3732,
315,
1865,
14,
11463,
63,
1580,
26,
355,
10831,
63,
513,
14,
740,
8,
955,
14,
19636,
14,
504,
63,
875,
8,
4510,
14,
602,
430,
288,
340,
10831,
63,
513,
26,
355,
1865,
14,
20427,
63,
602,
275,
1504,
14,
19636,
14,
475,
63,
875,
8,
827,
8,
9356,
63,
513,
430,
339,
768,
1246,
14,
18128,
360,
11151,
63,
602,
358,
272,
347,
20258,
63,
11151,
63,
602,
8,
277,
304,
267,
408,
22673,
340,
314,
5839,
10831,
365,
18930,
281,
2419,
314,
5532,
434,
1434,
624,
267,
340,
334,
277,
14,
11151,
63,
602,
436,
291,
14,
3543,
434,
63,
602,
436,
291,
14,
11151,
63,
602,
665,
291,
14,
3543,
434,
63,
602,
304,
288,
372,
791,
3764,
356,
469,
355,
283,
1213,
356,
4018,
17935,
1434,
365,
4634,
18930,
15659,
355,
283,
1188,
356,
3824,
1918,
1434,
5839,
701,
314,
15229,
365,
298,
2490,
298,
1152,
265,
281,
2419,
314,
5532,
434,
1434,
14,
2047,
1443,
506,
298,
2490,
298,
17200,
370,
394,
15034,
314,
15229,
1159,
1056,
2685,
355,
789,
288,
789,
421,
199,
533,
428,
1895,
4738,
3049,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
8515,
14,
1648,
14,
604,
7,
339,
768,
1246,
14,
3029,
272,
347,
485,
6726,
63,
1648,
63,
604,
63,
18546,
8,
277,
12,
1572,
63,
344,
304,
267,
5322,
275,
1613,
8,
30005,
4738,
3049,
12,
291,
10445,
6726,
63,
1648,
63,
604,
63,
18546,
8,
923,
63,
344,
29,
923,
63,
344,
9,
267,
367,
1004,
315,
291,
14,
11142,
480,
1648,
63,
344,
14,
11151,
63,
602,
2349,
288,
1434,
63,
20235,
275,
1504,
14,
19636,
14,
504,
63,
875,
8,
604,
14,
1648,
63,
344,
14,
11151,
63,
602,
9,
446,
6871,
8,
4899,
29,
604,
14,
1648,
63,
344,
14,
4627,
63,
344,
14,
4416,
63,
13799,
9,
288,
5322,
14,
873,
2561,
355,
283,
602,
63,
20235,
356,
1504,
14,
19636,
14,
475,
63,
875,
8,
602,
63,
20235,
395,
288,
3828,
267,
372,
5322,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
14320,
402,
28935,
14,
1666,
5113,
570,
367,
2615,
4248,
436,
32572,
2436,
14,
199,
199,
504,
2197,
492,
6871,
199,
504,
28811,
492,
2986,
12,
1504,
12,
1709,
12,
485,
421,
199,
533,
428,
1895,
4738,
8,
992,
14,
1685,
304,
272,
408,
1123,
9978,
1434,
1504,
370,
428,
1895,
4236,
7735,
12,
9235,
503,
922,
13,
287,
3014,
624,
272,
485,
6486,
275,
283,
8515,
14,
1648,
7,
339,
5532,
434,
63,
602,
275,
1504,
14,
19636,
8,
3357,
17574,
3357,
63,
3543,
434,
63,
602,
297,
1059,
534,
11421,
434,
6148,
297,
3877,
29,
549,
12,
4228,
1720,
628,
2506,
701,
1314,
314,
7585,
787,
3238,
370,
506,
28218,
14,
961,
365,
298,
5644,
298,
65,
1434,
626,
1265,
883,
8023,
572,
370,
314,
15229,
12,
4079,
641,
314,
298,
5644,
298,
5884,
7005,
350,
4703,
83,
2685,
272,
5839,
63,
602,
275,
1504,
14,
19636,
360,
17935,
6148,
297,
6863,
29,
549,
12,
6363,
3713,
7185,
356,
4274,
6753,
297,
756,
4360,
3660,
283,
1150,
356,
4274,
6753,
297,
756,
26804,
1331,
29,
797,
12,
3660,
1720,
628,
2506,
701,
1314,
314,
15229,
965,
5839,
314,
2974,
370,
506,
298,
5101,
298,
30480,
3134,
78,
2,
5101,
298,
11423,
642,
9240,
7545,
22763,
12,
314,
1487,
317,
2588,
9240,
1159,
298,
5101,
298,
2062,
1434,
911,
506,
9235,
4079,
641,
642,
1434,
436,
314,
298,
5101,
298,
16063,
1159,
13863,
18464,
1187,
3134,
78,
2,
5101,
298,
23679,
642,
901,
2701,
340,
1265,
2934,
314,
1487,
317,
2588,
9240,
370,
506,
298,
5101,
298,
7292,
465,
18930,
465,
3962,
14,
1010,
626,
1930,
314,
1420,
298,
5101,
298,
602,
911,
506,
9235,
1808,
314,
849,
1083,
26,
4079,
641,
298,
5101,
298,
1589,
12705,
7005,
350,
4703,
83,
436,
314,
15878,
1159,
13863,
18464,
1187,
2685,
272,
15826,
63,
602,
275,
1504,
14,
2506,
8,
3357,
17574,
3357,
63,
11463,
63,
1580,
297,
1059,
534,
30754,
6148,
297,
3877,
29,
549,
12,
639,
1720,
628,
2506,
641,
1314,
314,
1642,
1487,
317,
2588,
9240,
1990,
2737,
2685,
339,
768,
1246,
14,
8912,
360,
602,
63,
1648,
297,
283,
1648,
63,
604,
14,
10178,
63,
13799,
358,
272,
347,
485,
3357,
63,
3543,
434,
63,
602,
8,
277,
304,
267,
408,
8564,
314,
5532,
434,
1434,
624,
267,
367,
1865,
315,
291,
26,
288,
10831,
63,
513,
275,
942,
288,
1865,
63,
2083,
275,
1504,
14,
19636,
14,
504,
63,
875,
8,
1648,
14,
602,
63,
1648,
9,
288,
367,
1004,
315,
1865,
14,
1648,
63,
604,
14,
11142,
8,
2734,
671,
26,
671,
14,
929,
1137,
283,
6406,
735,
355,
4487,
275,
1865,
63,
2083,
435,
6871,
8,
4899,
29,
604,
14,
10178,
63,
13799,
503,
378,
14,
16,
9,
355,
10831,
63,
513,
14,
740,
8,
3583,
9,
288,
340,
10831,
63,
513,
26,
355,
5532,
63,
602,
275,
1748,
8,
9356,
63,
513,
9,
340,
1865,
14,
11463,
63,
3185,
508,
283,
2275,
7,
587,
1390,
8,
9356,
63,
513,
9,
355,
1865,
14,
3543,
434,
63,
602,
275,
1504,
14,
19636,
14,
475,
63,
875,
8,
3543,
63,
602,
9,
339,
347,
485,
3357,
63,
11463,
63,
1580,
8,
277,
304,
267,
1613,
8,
30005,
4738,
12,
291,
10445,
3357,
63,
11463,
63,
1580,
342,
267,
367,
1865,
315,
291,
26,
288,
10831,
63,
513,
275,
942,
288,
367,
3732,
315,
1865,
14,
11463,
63,
1580,
26,
355,
10831,
63,
513,
14,
740,
8,
955,
14,
19636,
14,
504,
63,
875,
8,
4510,
14,
602,
430,
288,
340,
10831,
63,
513,
26,
355,
1865,
14,
20427,
63,
602,
275,
1504,
14,
19636,
14,
475,
63,
875,
8,
827,
8,
9356,
63,
513,
430,
339,
768,
1246,
14,
18128,
360,
11151,
63,
602,
358,
272,
347,
20258,
63,
11151,
63,
602,
8,
277,
304,
267,
408,
22673,
340,
314,
5839,
10831,
365,
18930,
281,
2419,
314,
5532,
434,
1434,
624,
267,
340,
334,
277,
14,
11151,
63,
602,
436,
291,
14,
3543,
434,
63,
602,
436,
291,
14,
11151,
63,
602,
665,
291,
14,
3543,
434,
63,
602,
304,
288,
372,
791,
3764,
356,
469,
355,
283,
1213,
356,
4018,
17935,
1434,
365,
4634,
18930,
15659,
355,
283,
1188,
356,
3824,
1918,
1434,
5839,
701,
314,
15229,
365,
298,
2490,
298,
1152,
265,
281,
2419,
314,
5532,
434,
1434,
14,
2047,
1443,
506,
298,
2490,
298,
17200,
370,
394,
15034,
314,
15229,
1159,
1056,
2685,
355,
789,
288,
789,
421,
199,
533,
428,
1895,
4738,
3049,
8,
992,
14,
1685,
304,
272,
485,
6486,
275,
283,
8515,
14,
1648,
14,
604,
7,
339,
768,
1246,
14,
3029,
272,
347,
485,
6726,
63,
1648,
63,
604,
63,
18546,
8,
277,
12,
1572,
63,
344,
304,
267,
5322,
275,
1613,
8,
30005,
4738,
3049,
12,
291,
10445,
6726,
63,
1648,
63,
604,
63,
18546,
8,
923,
63,
344,
29,
923,
63,
344,
9,
267,
367,
1004,
315,
291,
14,
11142,
480,
1648,
63,
344,
14,
11151,
63,
602,
2349,
288,
1434,
63,
20235,
275,
1504,
14,
19636,
14,
504,
63,
875,
8,
604,
14,
1648,
63,
344,
14,
11151,
63,
602,
9,
446,
6871,
8,
4899,
29,
604,
14,
1648,
63,
344,
14,
4627,
63,
344,
14,
4416,
63,
13799,
9,
288,
5322,
14,
873,
2561,
355,
283,
602,
63,
20235,
356,
1504,
14,
19636,
14,
475,
63,
875,
8,
602,
63,
20235,
395,
288,
3828,
267,
372,
5322,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pombredanne/Rusthon
|
regtests/bench/richards.py
|
2
|
8357
|
'''
Richards
'''
# based on a Java version:
# Based on original version written in BCPL by Dr Martin Richards
# in 1981 at Cambridge University Computer Laboratory, England
# and a C++ version derived from a Smalltalk version written by
# L Peter Deutsch.
# Java version: Copyright (C) 1995 Sun Microsystems, Inc.
# Translation from C++, Mario Wolczko
# Outer loop added by Alex Jacoby
from time import clock
from runtime import *
# Task IDs
I_IDLE = 1
I_WORK = 2
I_HANDLERA = 3
I_HANDLERB = 4
I_DEVA = 5
I_DEVB = 6
# Packet types
K_DEV = 1000
K_WORK = 1001
# Packet
BUFSIZE = 4
BUFSIZE_RANGE = range(BUFSIZE)
class Packet(object):
def __init__(self,l,i,k):
self.link = l
self.ident = i
self.kind = k
self.datum = 0
self.data = [0] * BUFSIZE
def append_to(self,lst):
self.link = None
if lst is None:
return self
else:
p = lst
next = p.link
while next is not None:
p = next
next = p.link
p.link = self
return lst
# Task Records
class TaskRec(object):
pass
class DeviceTaskRec(TaskRec):
def __init__(self):
self.pending = None
class IdleTaskRec(TaskRec):
def __init__(self):
self.control = 1
self.count = 10000
class HandlerTaskRec(TaskRec):
def __init__(self):
self.work_in = None
self.device_in = None
def workInAdd(self,p):
self.work_in = p.append_to(self.work_in)
return self.work_in
def deviceInAdd(self,p):
self.device_in = p.append_to(self.device_in)
return self.device_in
class WorkerTaskRec(TaskRec):
def __init__(self):
self.destination = I_HANDLERA
self.count = 0
# Task
class TaskState(object):
def __init__(self):
self.packet_pending = True
self.task_waiting = False
self.task_holding = False
def packetPending(self):
self.packet_pending = True
self.task_waiting = False
self.task_holding = False
return self
def waiting(self):
self.packet_pending = False
self.task_waiting = True
self.task_holding = False
return self
def running(self):
self.packet_pending = False
self.task_waiting = False
self.task_holding = False
return self
def waitingWithPacket(self):
self.packet_pending = True
self.task_waiting = True
self.task_holding = False
return self
def isPacketPending(self):
return self.packet_pending
def isTaskWaiting(self):
return self.task_waiting
def isTaskHolding(self):
return self.task_holding
def isTaskHoldingOrWaiting(self):
return self.task_holding or (not self.packet_pending and self.task_waiting)
def isWaitingWithPacket(self):
return self.packet_pending and self.task_waiting and not self.task_holding
tracing = False
layout = 0
def trace(a):
global layout
layout -= 1
if layout <= 0:
print()
layout = 50
print(a)
TASKTABSIZE = 10
class TaskWorkArea(object):
def __init__(self):
self.taskTab = [None] * TASKTABSIZE
self.taskList = None
self.holdCount = 0
self.qpktCount = 0
taskWorkArea = TaskWorkArea()
class Task(TaskState):
def __init__(self,i,p,w,initialState,r):
self.link = taskWorkArea.taskList
self.ident = i
self.priority = p
self.input = w
self.packet_pending = initialState.isPacketPending()
self.task_waiting = initialState.isTaskWaiting()
self.task_holding = initialState.isTaskHolding()
self.handle = r
taskWorkArea.taskList = self
taskWorkArea.taskTab[i] = self
def fn(self,pkt,r):
#raise NotImplementedError
print('NotImplementedError')
def addPacket(self,p,old):
if self.input is None:
self.input = p
self.packet_pending = True
if self.priority > old.priority:
return self
else:
p.append_to(self.input)
return old
#@v8
def runTask(self): ## most CPU load
if self.isWaitingWithPacket():
msg = self.input
self.input = msg.link
if self.input is None:
self.running()
else:
self.packetPending()
else:
msg = None
return self.fn(msg,self.handle)
def waitTask(self):
self.task_waiting = True
return self
def hold(self):
taskWorkArea.holdCount += 1
self.task_holding = True
return self.link
def release(self,i):
t = self.findtcb(i)
t.task_holding = False
if t.priority > self.priority:
return t
else:
return self
def qpkt(self,pkt):
t = self.findtcb(pkt.ident)
taskWorkArea.qpktCount += 1
pkt.link = None
pkt.ident = self.ident
return t.addPacket(pkt,self)
def findtcb(self,id):
t = taskWorkArea.taskTab[id]
if t is None:
print('Exception in findtcb')
return t
# DeviceTask
class DeviceTask(Task):
def __init__(self,i,p,w,s,r):
Task.__init__(self,i,p,w,s,r)
def fn(self,pkt,r):
d = r
#assert isinstance(d, DeviceTaskRec)
if pkt is None:
pkt = d.pending
if pkt is None:
return self.waitTask()
else:
d.pending = None
return self.qpkt(pkt)
else:
d.pending = pkt
if tracing: trace(pkt.datum)
return self.hold()
class HandlerTask(Task):
def __init__(self,i,p,w,s,r):
Task.__init__(self,i,p,w,s,r)
def fn(self,pkt,r):
h = r
#assert isinstance(h, HandlerTaskRec)
if pkt is not None:
if pkt.kind == K_WORK:
h.workInAdd(pkt)
else:
h.deviceInAdd(pkt)
work = h.work_in
if work is None:
return self.waitTask()
count = work.datum
if count >= BUFSIZE:
h.work_in = work.link
return self.qpkt(work)
dev = h.device_in
if dev is None:
return self.waitTask()
h.device_in = dev.link
dev.datum = work.data[count]
work.datum = count + 1
return self.qpkt(dev)
# IdleTask
class IdleTask(Task):
def __init__(self,i,p,w,s,r):
Task.__init__(self,i,0,None,s,r)
def fn(self,pkt,r):
i = r
#assert isinstance(i, IdleTaskRec)
i.count -= 1
if i.count == 0:
return self.hold()
elif i.control & 1 == 0:
i.control //= 2
return self.release(I_DEVA)
else:
i.control = i.control//2 ^ 0xd008
return self.release(I_DEVB)
# WorkTask
A = ord('A')
class WorkTask(Task):
def __init__(self,i,p,w,s,r):
Task.__init__(self,i,p,w,s,r)
def fn(self,pkt,r):
w = r
#assert isinstance(w, WorkerTaskRec)
if pkt is None:
return self.waitTask()
if w.destination == I_HANDLERA:
dest = I_HANDLERB
else:
dest = I_HANDLERA
w.destination = dest
pkt.ident = dest
pkt.datum = 0
for i in BUFSIZE_RANGE: # xrange(BUFSIZE)
w.count += 1
if w.count > 26:
w.count = 1
pkt.data[i] = A + w.count - 1
return self.qpkt(pkt)
def schedule():
t = taskWorkArea.taskList
while t is not None:
pkt = None
if tracing:
print("tcb =",t.ident)
if t.isTaskHoldingOrWaiting():
t = t.link
else:
if tracing: trace(chr(ord("0")+t.ident))
t = t.runTask()
class Richards(object):
def run(self, iterations):
for i in range(iterations):
taskWorkArea.holdCount = 0
taskWorkArea.qpktCount = 0
IdleTask(I_IDLE, 1, 10000, TaskState().running(), IdleTaskRec())
wkq = Packet(None, 0, K_WORK)
wkq = Packet(wkq , 0, K_WORK)
WorkTask(I_WORK, 1000, wkq, TaskState().waitingWithPacket(), WorkerTaskRec())
wkq = Packet(None, I_DEVA, K_DEV)
wkq = Packet(wkq , I_DEVA, K_DEV)
wkq = Packet(wkq , I_DEVA, K_DEV)
HandlerTask(I_HANDLERA, 2000, wkq, TaskState().waitingWithPacket(), HandlerTaskRec())
wkq = Packet(None, I_DEVB, K_DEV)
wkq = Packet(wkq , I_DEVB, K_DEV)
wkq = Packet(wkq , I_DEVB, K_DEV)
HandlerTask(I_HANDLERB, 3000, wkq, TaskState().waitingWithPacket(), HandlerTaskRec())
wkq = None;
DeviceTask(I_DEVA, 4000, wkq, TaskState().waiting(), DeviceTaskRec());
DeviceTask(I_DEVB, 5000, wkq, TaskState().waiting(), DeviceTaskRec());
schedule()
if taskWorkArea.holdCount == 9297 and taskWorkArea.qpktCount == 23246:
pass
else:
return False
return True
def entry_point(iterations):
r = Richards()
## before bench timer let v8 type infer the method
## types so it can be JIT on next call, set by `v8(func)`
#r.run(1)
#v8(r.run)
## above works, but it can also be done in a single line with `->` syntax
v8->( r.run(1) )
startTime = clock()
result = r.run(iterations)
if not result:
print('#ERROR incorrect results!')
return clock() - startTime
def main():
iterations=20
#print("#Richards benchmark (Python) starting. iterations="+str(iterations))
total_s = entry_point(iterations)
#print("#Total time for %s iterations: %s secs" %(iterations,total_s))
s = total_s / iterations
#print("#Average seconds per iteration:", s)
print(s)
main()
|
bsd-3-clause
|
[
2344,
199,
50,
1158,
5596,
199,
2344,
199,
199,
3,
4079,
641,
282,
9586,
1015,
26,
199,
3,
221,
21311,
641,
3379,
1015,
5313,
315,
32758,
2749,
701,
577,
82,
603,
26788,
30846,
5596,
199,
3,
221,
315,
5851,
2835,
737,
445,
455,
9528,
15904,
3599,
2699,
16871,
31671,
12,
18960,
9688,
199,
3,
221,
436,
282,
445,
4176,
1015,
7131,
687,
282,
23704,
21890,
1015,
5313,
701,
199,
3,
221,
491,
22912,
1487,
14608,
335,
14,
199,
3,
221,
9586,
1015,
26,
221,
1898,
334,
35,
9,
9013,
21,
25625,
27022,
19135,
12,
3277,
14,
199,
3,
221,
25224,
687,
445,
4176,
12,
603,
6936,
644,
393,
16823,
7697,
199,
3,
221,
593,
2699,
4438,
3483,
701,
22986,
1603,
13286,
991,
199,
199,
504,
900,
492,
12516,
199,
504,
8836,
492,
627,
199,
199,
3,
8495,
11449,
199,
41,
63,
23715,
275,
413,
199,
41,
63,
8406,
275,
499,
199,
41,
63,
30872,
33,
275,
650,
199,
41,
63,
30872,
34,
275,
841,
199,
41,
63,
13260,
33,
275,
959,
199,
41,
63,
13260,
34,
275,
1227,
199,
199,
3,
31782,
2943,
199,
43,
63,
13260,
275,
5198,
199,
43,
63,
8406,
275,
2948,
17,
199,
199,
3,
31782,
199,
199,
21323,
4305,
275,
841,
199,
199,
21323,
4305,
63,
15167,
275,
1425,
8,
21323,
4305,
9,
199,
199,
533,
31782,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
12,
76,
12,
73,
12,
75,
304,
507,
198,
277,
14,
1073,
275,
634,
507,
198,
277,
14,
5425,
275,
284,
507,
198,
277,
14,
5091,
275,
1022,
507,
198,
277,
14,
18945,
275,
378,
507,
198,
277,
14,
576,
275,
359,
16,
61,
627,
16331,
38,
4305,
421,
198,
318,
5666,
63,
475,
8,
277,
12,
6916,
304,
507,
198,
277,
14,
1073,
275,
488,
507,
198,
692,
9877,
365,
488,
26,
686,
198,
1107,
291,
507,
198,
2836,
26,
686,
198,
80,
275,
9877,
686,
198,
2184,
275,
299,
14,
1073,
686,
198,
6710,
2163,
365,
440,
488,
26,
1585,
198,
80,
275,
2163,
1585,
198,
2184,
275,
299,
14,
1073,
686,
198,
80,
14,
1073,
275,
291,
686,
198,
1107,
9877,
199,
199,
3,
8495,
799,
3692,
199,
199,
533,
8495,
21561,
8,
785,
304,
199,
198,
1529,
199,
199,
533,
12272,
4476,
21561,
8,
4476,
21561,
304,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
6455,
275,
488,
199,
199,
533,
473,
3011,
4476,
21561,
8,
4476,
21561,
304,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
2785,
275,
413,
507,
198,
277,
14,
835,
275,
11630,
199,
199,
533,
18599,
4476,
21561,
8,
4476,
21561,
304,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
800,
63,
262,
275,
488,
507,
198,
277,
14,
1782,
63,
262,
275,
488,
421,
198,
318,
1736,
607,
1123,
8,
277,
12,
80,
304,
507,
198,
277,
14,
800,
63,
262,
275,
299,
14,
740,
63,
475,
8,
277,
14,
800,
63,
262,
9,
507,
198,
1107,
291,
14,
800,
63,
262,
421,
198,
318,
2243,
607,
1123,
8,
277,
12,
80,
304,
507,
198,
277,
14,
1782,
63,
262,
275,
299,
14,
740,
63,
475,
8,
277,
14,
1782,
63,
262,
9,
507,
198,
1107,
291,
14,
1782,
63,
262,
199,
199,
533,
23886,
4476,
21561,
8,
4476,
21561,
304,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
6881,
275,
473,
63,
30872,
33,
507,
198,
277,
14,
835,
275,
378,
199,
3,
8495,
199,
199,
533,
8495,
2223,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
6253,
63,
6455,
275,
715,
507,
198,
277,
14,
1765,
63,
14093,
275,
756,
507,
198,
277,
14,
1765,
63,
72,
13122,
275,
756,
421,
198,
318,
3644,
15960,
8,
277,
304,
507,
198,
277,
14,
6253,
63,
6455,
275,
715,
507,
198,
277,
14,
1765,
63,
14093,
275,
756,
507,
198,
277,
14,
1765,
63,
72,
13122,
275,
756,
507,
198,
1107,
291,
421,
198,
318,
10923,
8,
277,
304,
507,
198,
277,
14,
6253,
63,
6455,
275,
756,
507,
198,
277,
14,
1765,
63,
14093,
275,
715,
507,
198,
277,
14,
1765,
63,
72,
13122,
275,
756,
507,
198,
1107,
291,
421,
198,
318,
3879,
8,
277,
304,
507,
198,
277,
14,
6253,
63,
6455,
275,
756,
507,
198,
277,
14,
1765,
63,
14093,
275,
756,
507,
198,
277,
14,
1765,
63,
72,
13122,
275,
756,
507,
198,
1107,
291,
18118,
198,
318,
10923,
3007,
2726,
8,
277,
304,
507,
198,
277,
14,
6253,
63,
6455,
275,
715,
507,
198,
277,
14,
1765,
63,
14093,
275,
715,
507,
198,
277,
14,
1765,
63,
72,
13122,
275,
756,
507,
198,
1107,
291,
18118,
198,
318,
365,
2726,
15960,
8,
277,
304,
507,
198,
1107,
291,
14,
6253,
63,
6455,
421,
198,
318,
365,
4476,
19189,
8,
277,
304,
507,
198,
1107,
291,
14,
1765,
63,
14093,
421,
198,
318,
365,
4476,
40,
13122,
8,
277,
304,
507,
198,
1107,
291,
14,
1765,
63,
72,
13122,
421,
198,
318,
365,
4476,
40,
13122,
2844,
19189,
8,
277,
304,
507,
198,
1107,
291,
14,
1765,
63,
72,
13122,
503,
334,
1397,
291,
14,
6253,
63,
6455,
436,
291,
14,
1765,
63,
14093,
9,
421,
198,
318,
365,
19189,
3007,
2726,
8,
277,
304,
507,
198,
1107,
291,
14,
6253,
63,
6455,
436,
291,
14,
1765,
63,
14093,
436,
440,
291,
14,
1765,
63,
72,
13122,
28154,
199,
21635,
275,
756,
199,
4209,
275,
378,
199,
199,
318,
3307,
8,
65,
304,
199,
198,
2966,
7054,
199,
198,
4209,
4862,
413,
199,
198,
692,
7054,
2695,
378,
26,
507,
198,
1361,
342,
507,
198,
4209,
275,
5238,
199,
198,
1361,
8,
65,
9,
421,
199,
17179,
10129,
4305,
275,
1616,
199,
199,
533,
8495,
6517,
11043,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
1765,
7690,
275,
359,
403,
61,
627,
377,
7946,
10129,
4305,
2742,
198,
277,
14,
1765,
1296,
275,
488,
2742,
198,
277,
14,
12239,
2353,
275,
378,
507,
198,
277,
14,
81,
20573,
2353,
275,
378,
199,
199,
1765,
6517,
11043,
275
] |
[
199,
50,
1158,
5596,
199,
2344,
199,
199,
3,
4079,
641,
282,
9586,
1015,
26,
199,
3,
221,
21311,
641,
3379,
1015,
5313,
315,
32758,
2749,
701,
577,
82,
603,
26788,
30846,
5596,
199,
3,
221,
315,
5851,
2835,
737,
445,
455,
9528,
15904,
3599,
2699,
16871,
31671,
12,
18960,
9688,
199,
3,
221,
436,
282,
445,
4176,
1015,
7131,
687,
282,
23704,
21890,
1015,
5313,
701,
199,
3,
221,
491,
22912,
1487,
14608,
335,
14,
199,
3,
221,
9586,
1015,
26,
221,
1898,
334,
35,
9,
9013,
21,
25625,
27022,
19135,
12,
3277,
14,
199,
3,
221,
25224,
687,
445,
4176,
12,
603,
6936,
644,
393,
16823,
7697,
199,
3,
221,
593,
2699,
4438,
3483,
701,
22986,
1603,
13286,
991,
199,
199,
504,
900,
492,
12516,
199,
504,
8836,
492,
627,
199,
199,
3,
8495,
11449,
199,
41,
63,
23715,
275,
413,
199,
41,
63,
8406,
275,
499,
199,
41,
63,
30872,
33,
275,
650,
199,
41,
63,
30872,
34,
275,
841,
199,
41,
63,
13260,
33,
275,
959,
199,
41,
63,
13260,
34,
275,
1227,
199,
199,
3,
31782,
2943,
199,
43,
63,
13260,
275,
5198,
199,
43,
63,
8406,
275,
2948,
17,
199,
199,
3,
31782,
199,
199,
21323,
4305,
275,
841,
199,
199,
21323,
4305,
63,
15167,
275,
1425,
8,
21323,
4305,
9,
199,
199,
533,
31782,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
12,
76,
12,
73,
12,
75,
304,
507,
198,
277,
14,
1073,
275,
634,
507,
198,
277,
14,
5425,
275,
284,
507,
198,
277,
14,
5091,
275,
1022,
507,
198,
277,
14,
18945,
275,
378,
507,
198,
277,
14,
576,
275,
359,
16,
61,
627,
16331,
38,
4305,
421,
198,
318,
5666,
63,
475,
8,
277,
12,
6916,
304,
507,
198,
277,
14,
1073,
275,
488,
507,
198,
692,
9877,
365,
488,
26,
686,
198,
1107,
291,
507,
198,
2836,
26,
686,
198,
80,
275,
9877,
686,
198,
2184,
275,
299,
14,
1073,
686,
198,
6710,
2163,
365,
440,
488,
26,
1585,
198,
80,
275,
2163,
1585,
198,
2184,
275,
299,
14,
1073,
686,
198,
80,
14,
1073,
275,
291,
686,
198,
1107,
9877,
199,
199,
3,
8495,
799,
3692,
199,
199,
533,
8495,
21561,
8,
785,
304,
199,
198,
1529,
199,
199,
533,
12272,
4476,
21561,
8,
4476,
21561,
304,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
6455,
275,
488,
199,
199,
533,
473,
3011,
4476,
21561,
8,
4476,
21561,
304,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
2785,
275,
413,
507,
198,
277,
14,
835,
275,
11630,
199,
199,
533,
18599,
4476,
21561,
8,
4476,
21561,
304,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
800,
63,
262,
275,
488,
507,
198,
277,
14,
1782,
63,
262,
275,
488,
421,
198,
318,
1736,
607,
1123,
8,
277,
12,
80,
304,
507,
198,
277,
14,
800,
63,
262,
275,
299,
14,
740,
63,
475,
8,
277,
14,
800,
63,
262,
9,
507,
198,
1107,
291,
14,
800,
63,
262,
421,
198,
318,
2243,
607,
1123,
8,
277,
12,
80,
304,
507,
198,
277,
14,
1782,
63,
262,
275,
299,
14,
740,
63,
475,
8,
277,
14,
1782,
63,
262,
9,
507,
198,
1107,
291,
14,
1782,
63,
262,
199,
199,
533,
23886,
4476,
21561,
8,
4476,
21561,
304,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
6881,
275,
473,
63,
30872,
33,
507,
198,
277,
14,
835,
275,
378,
199,
3,
8495,
199,
199,
533,
8495,
2223,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
6253,
63,
6455,
275,
715,
507,
198,
277,
14,
1765,
63,
14093,
275,
756,
507,
198,
277,
14,
1765,
63,
72,
13122,
275,
756,
421,
198,
318,
3644,
15960,
8,
277,
304,
507,
198,
277,
14,
6253,
63,
6455,
275,
715,
507,
198,
277,
14,
1765,
63,
14093,
275,
756,
507,
198,
277,
14,
1765,
63,
72,
13122,
275,
756,
507,
198,
1107,
291,
421,
198,
318,
10923,
8,
277,
304,
507,
198,
277,
14,
6253,
63,
6455,
275,
756,
507,
198,
277,
14,
1765,
63,
14093,
275,
715,
507,
198,
277,
14,
1765,
63,
72,
13122,
275,
756,
507,
198,
1107,
291,
421,
198,
318,
3879,
8,
277,
304,
507,
198,
277,
14,
6253,
63,
6455,
275,
756,
507,
198,
277,
14,
1765,
63,
14093,
275,
756,
507,
198,
277,
14,
1765,
63,
72,
13122,
275,
756,
507,
198,
1107,
291,
18118,
198,
318,
10923,
3007,
2726,
8,
277,
304,
507,
198,
277,
14,
6253,
63,
6455,
275,
715,
507,
198,
277,
14,
1765,
63,
14093,
275,
715,
507,
198,
277,
14,
1765,
63,
72,
13122,
275,
756,
507,
198,
1107,
291,
18118,
198,
318,
365,
2726,
15960,
8,
277,
304,
507,
198,
1107,
291,
14,
6253,
63,
6455,
421,
198,
318,
365,
4476,
19189,
8,
277,
304,
507,
198,
1107,
291,
14,
1765,
63,
14093,
421,
198,
318,
365,
4476,
40,
13122,
8,
277,
304,
507,
198,
1107,
291,
14,
1765,
63,
72,
13122,
421,
198,
318,
365,
4476,
40,
13122,
2844,
19189,
8,
277,
304,
507,
198,
1107,
291,
14,
1765,
63,
72,
13122,
503,
334,
1397,
291,
14,
6253,
63,
6455,
436,
291,
14,
1765,
63,
14093,
9,
421,
198,
318,
365,
19189,
3007,
2726,
8,
277,
304,
507,
198,
1107,
291,
14,
6253,
63,
6455,
436,
291,
14,
1765,
63,
14093,
436,
440,
291,
14,
1765,
63,
72,
13122,
28154,
199,
21635,
275,
756,
199,
4209,
275,
378,
199,
199,
318,
3307,
8,
65,
304,
199,
198,
2966,
7054,
199,
198,
4209,
4862,
413,
199,
198,
692,
7054,
2695,
378,
26,
507,
198,
1361,
342,
507,
198,
4209,
275,
5238,
199,
198,
1361,
8,
65,
9,
421,
199,
17179,
10129,
4305,
275,
1616,
199,
199,
533,
8495,
6517,
11043,
8,
785,
304,
199,
198,
318,
636,
826,
721,
277,
304,
507,
198,
277,
14,
1765,
7690,
275,
359,
403,
61,
627,
377,
7946,
10129,
4305,
2742,
198,
277,
14,
1765,
1296,
275,
488,
2742,
198,
277,
14,
12239,
2353,
275,
378,
507,
198,
277,
14,
81,
20573,
2353,
275,
378,
199,
199,
1765,
6517,
11043,
275,
0
] |
[
1,
1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angzhuo/kbengine
|
kbe/src/lib/python/Lib/test/test_keywordonlyarg.py
|
84
|
7311
|
"""Unit tests for the keyword only argument specified in PEP 3102."""
__author__ = "Jiwon Seo"
__email__ = "seojiwon at gmail dot com"
import unittest
from test.support import run_unittest
def posonly_sum(pos_arg1, *arg, **kwarg):
return pos_arg1 + sum(arg) + sum(kwarg.values())
def keywordonly_sum(*, k1=0, k2):
return k1 + k2
def keywordonly_nodefaults_sum(*, k1, k2):
return k1 + k2
def keywordonly_and_kwarg_sum(*, k1, k2, **kwarg):
return k1 + k2 + sum(kwarg.values())
def mixedargs_sum(a, b=0, *arg, k1, k2=0):
return a + b + k1 + k2 + sum(arg)
def mixedargs_sum2(a, b=0, *arg, k1, k2=0, **kwargs):
return a + b + k1 + k2 + sum(arg) + sum(kwargs.values())
def sortnum(*nums, reverse=False):
return sorted(list(nums), reverse=reverse)
def sortwords(*words, reverse=False, **kwargs):
return sorted(list(words), reverse=reverse)
class Foo:
def __init__(self, *, k1, k2=0):
self.k1 = k1
self.k2 = k2
def set(self, p1, *, k1, k2):
self.k1 = k1
self.k2 = k2
def sum(self):
return self.k1 + self.k2
class KeywordOnlyArgTestCase(unittest.TestCase):
def assertRaisesSyntaxError(self, codestr):
def shouldRaiseSyntaxError(s):
compile(s, "<test>", "single")
self.assertRaises(SyntaxError, shouldRaiseSyntaxError, codestr)
def testSyntaxErrorForFunctionDefinition(self):
self.assertRaisesSyntaxError("def f(p, *):\n pass\n")
self.assertRaisesSyntaxError("def f(p1, *, p1=100):\n pass\n")
self.assertRaisesSyntaxError("def f(p1, *k1, k1=100):\n pass\n")
self.assertRaisesSyntaxError("def f(p1, *, k1, k1=100):\n pass\n")
self.assertRaisesSyntaxError("def f(p1, *, **k1):\n pass\n")
self.assertRaisesSyntaxError("def f(p1, *, k1, **k1):\n pass\n")
self.assertRaisesSyntaxError("def f(p1, *, None, **k1):\n pass\n")
self.assertRaisesSyntaxError("def f(p, *, (k1, k2), **kw):\n pass\n")
def testSyntaxForManyArguments(self):
fundef = "def f("
for i in range(255):
fundef += "i%d, "%i
fundef += "*, key=100):\n pass\n"
self.assertRaisesSyntaxError(fundef)
fundef2 = "def foo(i,*,"
for i in range(255):
fundef2 += "i%d, "%i
fundef2 += "lastarg):\n pass\n"
self.assertRaisesSyntaxError(fundef2)
# exactly 255 arguments, should compile ok
fundef3 = "def f(i,*,"
for i in range(253):
fundef3 += "i%d, "%i
fundef3 += "lastarg):\n pass\n"
compile(fundef3, "<test>", "single")
def testTooManyPositionalErrorMessage(self):
def f(a, b=None, *, c=None):
pass
with self.assertRaises(TypeError) as exc:
f(1, 2, 3)
expected = "f() takes from 1 to 2 positional arguments but 3 were given"
self.assertEqual(str(exc.exception), expected)
def testSyntaxErrorForFunctionCall(self):
self.assertRaisesSyntaxError("f(p, k=1, p2)")
self.assertRaisesSyntaxError("f(p, k1=50, *(1,2), k1=100)")
def testRaiseErrorFuncallWithUnexpectedKeywordArgument(self):
self.assertRaises(TypeError, keywordonly_sum, ())
self.assertRaises(TypeError, keywordonly_nodefaults_sum, ())
self.assertRaises(TypeError, Foo, ())
try:
keywordonly_sum(k2=100, non_existing_arg=200)
self.fail("should raise TypeError")
except TypeError:
pass
try:
keywordonly_nodefaults_sum(k2=2)
self.fail("should raise TypeError")
except TypeError:
pass
def testFunctionCall(self):
self.assertEqual(1, posonly_sum(1))
self.assertEqual(1+2, posonly_sum(1,**{"2":2}))
self.assertEqual(1+2+3, posonly_sum(1,*(2,3)))
self.assertEqual(1+2+3+4, posonly_sum(1,*(2,3),**{"4":4}))
self.assertEqual(1, keywordonly_sum(k2=1))
self.assertEqual(1+2, keywordonly_sum(k1=1, k2=2))
self.assertEqual(1+2, keywordonly_and_kwarg_sum(k1=1, k2=2))
self.assertEqual(1+2+3, keywordonly_and_kwarg_sum(k1=1, k2=2, k3=3))
self.assertEqual(1+2+3+4,
keywordonly_and_kwarg_sum(k1=1, k2=2,
**{"a":3,"b":4}))
self.assertEqual(1+2, mixedargs_sum(1, k1=2))
self.assertEqual(1+2+3, mixedargs_sum(1, 2, k1=3))
self.assertEqual(1+2+3+4, mixedargs_sum(1, 2, k1=3, k2=4))
self.assertEqual(1+2+3+4+5, mixedargs_sum(1, 2, 3, k1=4, k2=5))
self.assertEqual(1+2, mixedargs_sum2(1, k1=2))
self.assertEqual(1+2+3, mixedargs_sum2(1, 2, k1=3))
self.assertEqual(1+2+3+4, mixedargs_sum2(1, 2, k1=3, k2=4))
self.assertEqual(1+2+3+4+5, mixedargs_sum2(1, 2, 3, k1=4, k2=5))
self.assertEqual(1+2+3+4+5+6,
mixedargs_sum2(1, 2, 3, k1=4, k2=5, k3=6))
self.assertEqual(1+2+3+4+5+6,
mixedargs_sum2(1, 2, 3, k1=4, **{'k2':5, 'k3':6}))
self.assertEqual(1, Foo(k1=1).sum())
self.assertEqual(1+2, Foo(k1=1,k2=2).sum())
self.assertEqual([1,2,3], sortnum(3,2,1))
self.assertEqual([3,2,1], sortnum(1,2,3, reverse=True))
self.assertEqual(['a','b','c'], sortwords('a','c','b'))
self.assertEqual(['c','b','a'], sortwords('a','c','b', reverse=True))
self.assertEqual(['c','b','a'],
sortwords('a','c','b', reverse=True, ignore='ignore'))
def testKwDefaults(self):
def foo(p1,p2=0, *, k1, k2=0):
return p1 + p2 + k1 + k2
self.assertEqual(2, foo.__code__.co_kwonlyargcount)
self.assertEqual({"k2":0}, foo.__kwdefaults__)
foo.__kwdefaults__ = {"k1":0}
try:
foo(1,k1=10)
self.fail("__kwdefaults__ is not properly changed")
except TypeError:
pass
def test_kwonly_methods(self):
class Example:
def f(self, *, k1=1, k2=2):
return k1, k2
self.assertEqual(Example().f(k1=1, k2=2), (1, 2))
self.assertEqual(Example.f(Example(), k1=1, k2=2), (1, 2))
self.assertRaises(TypeError, Example.f, k1=1, k2=2)
def test_issue13343(self):
# The Python compiler must scan all symbols of a function to
# determine their scope: global, local, cell...
# This was not done for the default values of keyword
# arguments in a lambda definition, and the following line
# used to fail with a SystemError.
lambda *, k1=unittest: None
def test_mangling(self):
class X:
def f(self, *, __a=42):
return __a
self.assertEqual(X().f(), 42)
def test_default_evaluation_order(self):
# See issue 16967
a = 42
with self.assertRaises(NameError) as err:
def f(v=a, x=b, *, y=c, z=d):
pass
self.assertEqual(str(err.exception), "name 'b' is not defined")
with self.assertRaises(NameError) as err:
f = lambda v=a, x=b, *, y=c, z=d: None
self.assertEqual(str(err.exception), "name 'b' is not defined")
def test_main():
run_unittest(KeywordOnlyArgTestCase)
if __name__ == "__main__":
test_main()
|
lgpl-3.0
|
[
624,
5072,
2295,
367,
314,
4252,
1454,
1423,
2013,
315,
13663,
650,
7759,
1041,
199,
199,
363,
2502,
363,
275,
298,
16911,
87,
265,
3240,
79,
2,
199,
363,
2123,
363,
275,
298,
261,
79,
8047,
87,
265,
737,
29712,
6308,
2414,
2,
199,
199,
646,
2882,
199,
504,
511,
14,
4058,
492,
1255,
63,
2796,
199,
199,
318,
2086,
2118,
63,
1838,
8,
1712,
63,
1273,
17,
12,
627,
1273,
12,
1011,
12745,
304,
272,
372,
2086,
63,
1273,
17,
435,
3089,
8,
1273,
9,
435,
3089,
8,
12745,
14,
1459,
1012,
199,
318,
4252,
2118,
63,
1838,
2031,
12,
1022,
17,
29,
16,
12,
1022,
18,
304,
272,
372,
1022,
17,
435,
1022,
18,
199,
318,
4252,
2118,
63,
889,
4322,
63,
1838,
2031,
12,
1022,
17,
12,
1022,
18,
304,
272,
372,
1022,
17,
435,
1022,
18,
199,
318,
4252,
2118,
63,
460,
63,
12745,
63,
1838,
2031,
12,
1022,
17,
12,
1022,
18,
12,
1011,
12745,
304,
272,
372,
1022,
17,
435,
1022,
18,
435,
3089,
8,
12745,
14,
1459,
1012,
199,
318,
13492,
589,
63,
1838,
8,
65,
12,
330,
29,
16,
12,
627,
1273,
12,
1022,
17,
12,
1022,
18,
29,
16,
304,
272,
372,
282,
435,
330,
435,
1022,
17,
435,
1022,
18,
435,
3089,
8,
1273,
9,
199,
318,
13492,
589,
63,
1838,
18,
8,
65,
12,
330,
29,
16,
12,
627,
1273,
12,
1022,
17,
12,
1022,
18,
29,
16,
12,
1011,
958,
304,
272,
372,
282,
435,
330,
435,
1022,
17,
435,
1022,
18,
435,
3089,
8,
1273,
9,
435,
3089,
8,
958,
14,
1459,
1012,
199,
199,
318,
4069,
1507,
2031,
16084,
12,
3837,
29,
797,
304,
272,
372,
3355,
8,
513,
8,
16084,
395,
3837,
29,
4471,
9,
199,
199,
318,
4069,
3148,
2031,
3148,
12,
3837,
29,
797,
12,
1011,
958,
304,
272,
372,
3355,
8,
513,
8,
3148,
395,
3837,
29,
4471,
9,
199,
199,
533,
8024,
26,
272,
347,
636,
826,
721,
277,
12,
9889,
1022,
17,
12,
1022,
18,
29,
16,
304,
267,
291,
14,
75,
17,
275,
1022,
17,
267,
291,
14,
75,
18,
275,
1022,
18,
272,
347,
663,
8,
277,
12,
299,
17,
12,
9889,
1022,
17,
12,
1022,
18,
304,
267,
291,
14,
75,
17,
275,
1022,
17,
267,
291,
14,
75,
18,
275,
1022,
18,
272,
347,
3089,
8,
277,
304,
267,
372,
291,
14,
75,
17,
435,
291,
14,
75,
18,
199,
199,
533,
6431,
5903,
6373,
1746,
8,
2796,
14,
1746,
304,
272,
347,
702,
1811,
9294,
8,
277,
12,
1233,
495,
304,
267,
347,
1077,
18111,
9294,
8,
83,
304,
288,
6555,
8,
83,
12,
3886,
396,
7166,
298,
4780,
531,
267,
291,
14,
1855,
8,
9294,
12,
1077,
18111,
9294,
12,
1233,
495,
9,
339,
347,
511,
9294,
1858,
3481,
10701,
8,
277,
304,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
12,
627,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
17,
12,
9889,
299,
17,
29,
1960,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
17,
12,
627,
75,
17,
12,
1022,
17,
29,
1960,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
17,
12,
9889,
1022,
17,
12,
1022,
17,
29,
1960,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
17,
12,
9889,
1011,
75,
17,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
17,
12,
9889,
1022,
17,
12,
1011,
75,
17,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
17,
12,
9889,
488,
12,
1011,
75,
17,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
12,
9889,
334,
75,
17,
12,
1022,
18,
395,
1011,
829,
17211,
78,
221,
986,
60,
78,
531,
339,
347,
511,
16626,
1858,
4089,
14517,
8,
277,
304,
267,
9627,
318,
275,
298,
318,
289,
480,
267,
367,
284,
315,
1425,
8,
2299,
304,
288,
9627,
318,
847,
298,
73,
5,
68,
12,
2071,
73,
267,
9627,
318,
847,
8969,
12,
790,
29,
1960,
17211,
78,
986,
60,
78,
2,
267,
291,
14,
1855,
9294,
8,
7036,
318,
9,
398,
9627,
318,
18,
275,
298,
318,
3925,
8,
73,
19166,
4589,
267,
367,
284,
315,
1425,
8,
2299,
304,
288,
9627,
318,
18,
847,
298,
73,
5,
68,
12,
2071,
73,
267,
9627,
318,
18,
847,
298,
2019,
1273,
17211,
78,
221,
986,
60,
78,
2,
267,
291,
14,
1855,
9294,
8,
7036,
318,
18,
9,
398,
327,
8840,
5450,
2368,
12,
1077,
6555,
4112,
267,
9627,
318,
19,
275,
298,
318,
289,
8,
73,
19166,
4589,
267,
367,
284,
315,
1425,
8,
3781,
304,
288,
9627,
318,
19,
847,
298,
73,
5,
68,
12,
2071,
73,
267,
9627,
318,
19,
847,
298,
2019,
1273,
17211,
78,
221,
986,
60,
78,
2,
267,
6555,
8,
7036,
318,
19,
12,
3886,
396,
7166,
298,
4780,
531,
339,
347,
511,
13749,
4089,
5625,
279,
547,
2209,
8,
277,
304,
267,
347,
289,
8,
65,
12,
330,
29,
403,
12,
9889,
286,
29,
403,
304,
288,
986,
267,
543,
291,
14,
1855,
8,
4333,
9,
465,
3178,
26,
288,
289,
8,
17,
12,
499,
12,
650,
9,
267,
1420,
275,
298,
70,
342,
6181,
687,
413,
370,
499,
11333,
2368,
1325,
650,
4898,
1627,
2,
267,
291,
14,
629,
8,
495,
8,
2804,
14,
1971,
395,
1420,
9,
339,
347,
511,
9294,
1858,
3481,
2176,
8,
277,
304,
267,
291,
14,
1855,
9294,
480,
70,
8,
80,
12,
1022,
29,
17,
12,
299,
18,
6320,
267,
291,
14,
1855,
9294,
480,
70,
8,
80,
12,
1022,
17,
29,
1400,
12,
26534,
17,
12,
18,
395,
1022,
17,
29,
1960,
6320,
339,
347,
511,
18111,
547,
7465,
452,
3007,
8708,
10650,
5201,
8,
277,
304,
267,
291,
14,
1855,
8,
4333,
12,
4252,
2118,
63,
1838,
12,
14515,
267,
291,
14,
1855,
8,
4333,
12,
4252,
2118,
63
] |
[
5072,
2295,
367,
314,
4252,
1454,
1423,
2013,
315,
13663,
650,
7759,
1041,
199,
199,
363,
2502,
363,
275,
298,
16911,
87,
265,
3240,
79,
2,
199,
363,
2123,
363,
275,
298,
261,
79,
8047,
87,
265,
737,
29712,
6308,
2414,
2,
199,
199,
646,
2882,
199,
504,
511,
14,
4058,
492,
1255,
63,
2796,
199,
199,
318,
2086,
2118,
63,
1838,
8,
1712,
63,
1273,
17,
12,
627,
1273,
12,
1011,
12745,
304,
272,
372,
2086,
63,
1273,
17,
435,
3089,
8,
1273,
9,
435,
3089,
8,
12745,
14,
1459,
1012,
199,
318,
4252,
2118,
63,
1838,
2031,
12,
1022,
17,
29,
16,
12,
1022,
18,
304,
272,
372,
1022,
17,
435,
1022,
18,
199,
318,
4252,
2118,
63,
889,
4322,
63,
1838,
2031,
12,
1022,
17,
12,
1022,
18,
304,
272,
372,
1022,
17,
435,
1022,
18,
199,
318,
4252,
2118,
63,
460,
63,
12745,
63,
1838,
2031,
12,
1022,
17,
12,
1022,
18,
12,
1011,
12745,
304,
272,
372,
1022,
17,
435,
1022,
18,
435,
3089,
8,
12745,
14,
1459,
1012,
199,
318,
13492,
589,
63,
1838,
8,
65,
12,
330,
29,
16,
12,
627,
1273,
12,
1022,
17,
12,
1022,
18,
29,
16,
304,
272,
372,
282,
435,
330,
435,
1022,
17,
435,
1022,
18,
435,
3089,
8,
1273,
9,
199,
318,
13492,
589,
63,
1838,
18,
8,
65,
12,
330,
29,
16,
12,
627,
1273,
12,
1022,
17,
12,
1022,
18,
29,
16,
12,
1011,
958,
304,
272,
372,
282,
435,
330,
435,
1022,
17,
435,
1022,
18,
435,
3089,
8,
1273,
9,
435,
3089,
8,
958,
14,
1459,
1012,
199,
199,
318,
4069,
1507,
2031,
16084,
12,
3837,
29,
797,
304,
272,
372,
3355,
8,
513,
8,
16084,
395,
3837,
29,
4471,
9,
199,
199,
318,
4069,
3148,
2031,
3148,
12,
3837,
29,
797,
12,
1011,
958,
304,
272,
372,
3355,
8,
513,
8,
3148,
395,
3837,
29,
4471,
9,
199,
199,
533,
8024,
26,
272,
347,
636,
826,
721,
277,
12,
9889,
1022,
17,
12,
1022,
18,
29,
16,
304,
267,
291,
14,
75,
17,
275,
1022,
17,
267,
291,
14,
75,
18,
275,
1022,
18,
272,
347,
663,
8,
277,
12,
299,
17,
12,
9889,
1022,
17,
12,
1022,
18,
304,
267,
291,
14,
75,
17,
275,
1022,
17,
267,
291,
14,
75,
18,
275,
1022,
18,
272,
347,
3089,
8,
277,
304,
267,
372,
291,
14,
75,
17,
435,
291,
14,
75,
18,
199,
199,
533,
6431,
5903,
6373,
1746,
8,
2796,
14,
1746,
304,
272,
347,
702,
1811,
9294,
8,
277,
12,
1233,
495,
304,
267,
347,
1077,
18111,
9294,
8,
83,
304,
288,
6555,
8,
83,
12,
3886,
396,
7166,
298,
4780,
531,
267,
291,
14,
1855,
8,
9294,
12,
1077,
18111,
9294,
12,
1233,
495,
9,
339,
347,
511,
9294,
1858,
3481,
10701,
8,
277,
304,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
12,
627,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
17,
12,
9889,
299,
17,
29,
1960,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
17,
12,
627,
75,
17,
12,
1022,
17,
29,
1960,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
17,
12,
9889,
1022,
17,
12,
1022,
17,
29,
1960,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
17,
12,
9889,
1011,
75,
17,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
17,
12,
9889,
1022,
17,
12,
1011,
75,
17,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
17,
12,
9889,
488,
12,
1011,
75,
17,
17211,
78,
221,
986,
60,
78,
531,
267,
291,
14,
1855,
9294,
480,
318,
289,
8,
80,
12,
9889,
334,
75,
17,
12,
1022,
18,
395,
1011,
829,
17211,
78,
221,
986,
60,
78,
531,
339,
347,
511,
16626,
1858,
4089,
14517,
8,
277,
304,
267,
9627,
318,
275,
298,
318,
289,
480,
267,
367,
284,
315,
1425,
8,
2299,
304,
288,
9627,
318,
847,
298,
73,
5,
68,
12,
2071,
73,
267,
9627,
318,
847,
8969,
12,
790,
29,
1960,
17211,
78,
986,
60,
78,
2,
267,
291,
14,
1855,
9294,
8,
7036,
318,
9,
398,
9627,
318,
18,
275,
298,
318,
3925,
8,
73,
19166,
4589,
267,
367,
284,
315,
1425,
8,
2299,
304,
288,
9627,
318,
18,
847,
298,
73,
5,
68,
12,
2071,
73,
267,
9627,
318,
18,
847,
298,
2019,
1273,
17211,
78,
221,
986,
60,
78,
2,
267,
291,
14,
1855,
9294,
8,
7036,
318,
18,
9,
398,
327,
8840,
5450,
2368,
12,
1077,
6555,
4112,
267,
9627,
318,
19,
275,
298,
318,
289,
8,
73,
19166,
4589,
267,
367,
284,
315,
1425,
8,
3781,
304,
288,
9627,
318,
19,
847,
298,
73,
5,
68,
12,
2071,
73,
267,
9627,
318,
19,
847,
298,
2019,
1273,
17211,
78,
221,
986,
60,
78,
2,
267,
6555,
8,
7036,
318,
19,
12,
3886,
396,
7166,
298,
4780,
531,
339,
347,
511,
13749,
4089,
5625,
279,
547,
2209,
8,
277,
304,
267,
347,
289,
8,
65,
12,
330,
29,
403,
12,
9889,
286,
29,
403,
304,
288,
986,
267,
543,
291,
14,
1855,
8,
4333,
9,
465,
3178,
26,
288,
289,
8,
17,
12,
499,
12,
650,
9,
267,
1420,
275,
298,
70,
342,
6181,
687,
413,
370,
499,
11333,
2368,
1325,
650,
4898,
1627,
2,
267,
291,
14,
629,
8,
495,
8,
2804,
14,
1971,
395,
1420,
9,
339,
347,
511,
9294,
1858,
3481,
2176,
8,
277,
304,
267,
291,
14,
1855,
9294,
480,
70,
8,
80,
12,
1022,
29,
17,
12,
299,
18,
6320,
267,
291,
14,
1855,
9294,
480,
70,
8,
80,
12,
1022,
17,
29,
1400,
12,
26534,
17,
12,
18,
395,
1022,
17,
29,
1960,
6320,
339,
347,
511,
18111,
547,
7465,
452,
3007,
8708,
10650,
5201,
8,
277,
304,
267,
291,
14,
1855,
8,
4333,
12,
4252,
2118,
63,
1838,
12,
14515,
267,
291,
14,
1855,
8,
4333,
12,
4252,
2118,
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,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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
] |
EricCline/CEM_inc
|
env/lib/python2.7/site-packages/django/core/management/commands/startproject.py
|
201
|
1323
|
from django.core.management.base import CommandError
from django.core.management.templates import TemplateCommand
from django.utils.crypto import get_random_string
from django.utils.importlib import import_module
class Command(TemplateCommand):
help = ("Creates a Django project directory structure for the given "
"project name in the current directory or optionally in the "
"given directory.")
def handle(self, project_name=None, target=None, *args, **options):
if project_name is None:
raise CommandError("you must provide a project name")
# Check that the project_name cannot be imported.
try:
import_module(project_name)
except ImportError:
pass
else:
raise CommandError("%r conflicts with the name of an existing "
"Python module and cannot be used as a "
"project name. Please try another name." %
project_name)
# Create a random SECRET_KEY hash to put it in the main settings.
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
options['secret_key'] = get_random_string(50, chars)
super(Command, self).handle('project', project_name, target, **options)
|
mit
|
[
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
14393,
199,
504,
1639,
14,
1018,
14,
8110,
14,
5876,
492,
5458,
3110,
199,
504,
1639,
14,
1208,
14,
10316,
492,
664,
63,
2355,
63,
875,
199,
504,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
421,
199,
533,
5817,
8,
4231,
3110,
304,
272,
1720,
275,
1689,
10607,
282,
5634,
2199,
2082,
5523,
367,
314,
1627,
298,
288,
298,
1715,
536,
315,
314,
1453,
2082,
503,
14190,
315,
314,
298,
288,
298,
11809,
2082,
2685,
339,
347,
2429,
8,
277,
12,
2199,
63,
354,
29,
403,
12,
1347,
29,
403,
12,
627,
589,
12,
1011,
1419,
304,
267,
340,
2199,
63,
354,
365,
488,
26,
288,
746,
14393,
480,
13297,
1471,
5647,
282,
2199,
536,
531,
398,
327,
2670,
626,
314,
2199,
63,
354,
3913,
506,
8439,
14,
267,
862,
26,
288,
492,
63,
578,
8,
1715,
63,
354,
9,
267,
871,
3545,
26,
288,
986,
267,
587,
26,
288,
746,
14393,
3647,
82,
18511,
543,
314,
536,
402,
376,
3411,
298,
3044,
298,
4718,
859,
436,
3913,
506,
1202,
465,
282,
298,
3044,
298,
1715,
536,
14,
7754,
862,
4573,
536,
2122,
450,
3044,
2199,
63,
354,
9,
398,
327,
2790,
282,
2196,
5795,
11771,
63,
3078,
2631,
370,
5324,
652,
315,
314,
2446,
2202,
14,
267,
8365,
275,
283,
23459,
11371,
1,
32,
3,
22074,
62,
6,
27436,
10683,
29600,
267,
1511,
459,
4731,
63,
498,
418,
275,
664,
63,
2355,
63,
875,
8,
1400,
12,
8365,
9,
398,
1613,
8,
3110,
12,
291,
680,
2479,
360,
1715,
297,
2199,
63,
354,
12,
1347,
12,
1011,
1419,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
1018,
14,
8110,
14,
1095,
492,
14393,
199,
504,
1639,
14,
1018,
14,
8110,
14,
5876,
492,
5458,
3110,
199,
504,
1639,
14,
1208,
14,
10316,
492,
664,
63,
2355,
63,
875,
199,
504,
1639,
14,
1208,
14,
25893,
492,
492,
63,
578,
421,
199,
533,
5817,
8,
4231,
3110,
304,
272,
1720,
275,
1689,
10607,
282,
5634,
2199,
2082,
5523,
367,
314,
1627,
298,
288,
298,
1715,
536,
315,
314,
1453,
2082,
503,
14190,
315,
314,
298,
288,
298,
11809,
2082,
2685,
339,
347,
2429,
8,
277,
12,
2199,
63,
354,
29,
403,
12,
1347,
29,
403,
12,
627,
589,
12,
1011,
1419,
304,
267,
340,
2199,
63,
354,
365,
488,
26,
288,
746,
14393,
480,
13297,
1471,
5647,
282,
2199,
536,
531,
398,
327,
2670,
626,
314,
2199,
63,
354,
3913,
506,
8439,
14,
267,
862,
26,
288,
492,
63,
578,
8,
1715,
63,
354,
9,
267,
871,
3545,
26,
288,
986,
267,
587,
26,
288,
746,
14393,
3647,
82,
18511,
543,
314,
536,
402,
376,
3411,
298,
3044,
298,
4718,
859,
436,
3913,
506,
1202,
465,
282,
298,
3044,
298,
1715,
536,
14,
7754,
862,
4573,
536,
2122,
450,
3044,
2199,
63,
354,
9,
398,
327,
2790,
282,
2196,
5795,
11771,
63,
3078,
2631,
370,
5324,
652,
315,
314,
2446,
2202,
14,
267,
8365,
275,
283,
23459,
11371,
1,
32,
3,
22074,
62,
6,
27436,
10683,
29600,
267,
1511,
459,
4731,
63,
498,
418,
275,
664,
63,
2355,
63,
875,
8,
1400,
12,
8365,
9,
398,
1613,
8,
3110,
12,
291,
680,
2479,
360,
1715,
297,
2199,
63,
354,
12,
1347,
12,
1011,
1419,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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right (c) Pymatgen Development Team.
# Distributed under the terms of the MIT License.
"""
Low-level objects providing an abstraction for the objects involved in the calculation.
"""
from __future__ import unicode_literals, division, print_function
import collections
import abc
import six
import numpy as np
import pymatgen.core.units as units
from pprint import pformat
from monty.design_patterns import singleton
from monty.collections import AttrDict
from enum import Enum
from monty.json import MSONable
from pymatgen.core.units import ArrayWithUnit
from pymatgen.core.lattice import Lattice
from pymatgen.core.structure import Structure
from pymatgen.util.serialization import pmg_serialize
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from monty.json import MontyEncoder, MontyDecoder
def lattice_from_abivars(cls=None, *args, **kwargs):
"""
Returns a `Lattice` object from a dictionary
with the Abinit variables `acell` and either `rprim` in Bohr or `angdeg`
If acell is not given, the Abinit default is used i.e. [1,1,1] Bohr
Args:
cls: Lattice class to be instantiated. pymatgen.core.lattice.Lattice if `cls` is None
Example:
lattice_from_abivars(acell=3*[10], rprim=np.eye(3))
"""
cls = Lattice if cls is None else cls
kwargs.update(dict(*args))
d = kwargs
rprim = d.get("rprim", None)
angdeg = d.get("angdeg", None)
acell = d["acell"]
if rprim is not None:
if angdeg is not None:
raise ValueError("angdeg and rprimd are mutually exclusive")
rprim = np.reshape(rprim, (3,3))
rprimd = [float(acell[i]) * rprim[i] for i in range(3)]
# Call pymatgen constructors (note that pymatgen uses Angstrom instead of Bohr).
return cls(ArrayWithUnit(rprimd, "bohr").to("ang"))
elif angdeg is not None:
angdeg = np.reshape(angdeg, 3)
if np.any(angdeg <= 0.):
raise ValueError("Angles must be > 0 but got %s" % str(angdeg))
if angdeg.sum() >= 360.:
raise ValueError("The sum of angdeg must be lower that 360, angdeg %s" % str(angdeg))
# This code follows the implementation in ingeo.F90
# See also http://www.abinit.org/doc/helpfiles/for-v7.8/input_variables/varbas.html#angdeg
tol12 = 1e-12
pi, sin, cos, sqrt = np.pi, np.sin, np.cos, np.sqrt
rprim = np.zeros((3,3))
if (abs(angdeg[0] -angdeg[1]) < tol12 and abs(angdeg[1] - angdeg[2]) < tol12 and
abs(angdeg[0]-90.) + abs(angdeg[1]-90.) + abs(angdeg[2] -90) > tol12):
# Treat the case of equal angles (except all right angles):
# generates trigonal symmetry wrt third axis
cosang = cos(pi * angdeg[0]/180.0)
a2 = 2.0/3.0*(1.0 - cosang)
aa = sqrt(a2)
cc = sqrt(1.0-a2)
rprim[0,0] = aa ; rprim[0,1] = 0.0 ; rprim[0,2] = cc
rprim[1,0] = -0.5*aa; rprim[1,1] = sqrt(3.0)*0.5*aa ; rprim[1,2] = cc
rprim[2,0] = -0.5*aa; rprim[2,1] = -sqrt(3.0)*0.5*aa; rprim[2,2] = cc
else:
# Treat all the other cases
rprim[0,0] = 1.0
rprim[1,0] = cos(pi*angdeg[2]/180.)
rprim[1,1] = sin(pi*angdeg[2]/180.)
rprim[2,0] = cos(pi*angdeg[1]/180.)
rprim[2,1] = (cos(pi*angdeg[0]/180.0)-rprim[1,0]*rprim[2,0])/rprim[1,1]
rprim[2,2] = sqrt(1.0-rprim[2,0]**2-rprim[2,1]**2)
# Call pymatgen constructors (note that pymatgen uses Angstrom instead of Bohr).
rprimd = [float(acell[i]) * rprim[i] for i in range(3)]
return cls(ArrayWithUnit(rprimd, "bohr").to("ang"))
raise ValueError("Don't know how to construct a Lattice from dict:\n%s" % pformat(d))
def structure_from_abivars(cls=None, *args, **kwargs):
"""
Build a :class:`Structure` object from a dictionary with ABINIT variables.
Args:
cls: Structure class to be instantiated. pymatgen.core.structure.Structure if cls is None
example:
al_structure = structure_from_abivars(
acell=3*[7.5],
rprim=[0.0, 0.5, 0.5,
0.5, 0.0, 0.5,
0.5, 0.5, 0.0],
typat=1,
xred=[0.0, 0.0, 0.0],
ntypat=1,
znucl=13,
)
`xred` can be replaced with `xcart` or `xangst`.
"""
kwargs.update(dict(*args))
d = kwargs
cls = Structure if cls is None else cls
#lattice = Lattice.from_dict(d, fmt="abivars")
lattice = lattice_from_abivars(**d)
coords, coords_are_cartesian = d.get("xred", None), False
if coords is None:
coords = d.get("xcart", None)
if coords is not None:
if "xangst" in d:
raise ValueError("xangst and xcart are mutually exclusive")
coords = ArrayWithUnit(coords, "bohr").to("ang")
else:
coords = d.get("xangst", None)
coords_are_cartesian = True
if coords is None:
raise ValueError("Cannot extract coordinates from:\n %s" % str(d))
coords = np.reshape(coords, (-1,3))
znucl_type, typat = d["znucl"], d["typat"]
if not isinstance(znucl_type, collections.Iterable):
znucl_type = [znucl_type]
if not isinstance(typat, collections.Iterable):
typat = [typat]
if len(typat) != len(coords):
raise ValueError("len(typat) != len(coords):\ntypat: %s\ncoords: %s" % (typat, coords))
# Note conversion to int and Fortran --> C indexing
typat = np.array(typat, dtype=np.int)
species = [znucl_type[typ-1] for typ in typat]
return cls(lattice, species, coords, validate_proximity=False,
to_unit_cell=False, coords_are_cartesian=coords_are_cartesian)
def structure_to_abivars(structure, **kwargs):
"""
Receives a structure and returns a dictionary with the ABINIT variables.
"""
if not structure.is_ordered:
raise ValueError("""\
Received disordered structure with partial occupancies that cannot be converted into an Abinit input
Please use OrderDisorderedStructureTransformation or EnumerateStructureTransformation
to build an appropriate supercell from partial occupancies or alternatively use the Virtual Crystal Approximation.""")
types_of_specie = structure.types_of_specie
natom = structure.num_sites
znucl_type = [specie.number for specie in types_of_specie]
znucl_atoms = structure.atomic_numbers
typat = np.zeros(natom, np.int)
for atm_idx, site in enumerate(structure):
typat[atm_idx] = types_of_specie.index(site.specie) + 1
rprim = ArrayWithUnit(structure.lattice.matrix, "ang").to("bohr")
xred = np.reshape([site.frac_coords for site in structure], (-1,3))
# Set small values to zero. This usually happens when the CIF file
# does not give structure parameters with enough digits.
rprim = np.where(np.abs(rprim) > 1e-8, rprim, 0.0)
xred = np.where(np.abs(xred) > 1e-8, xred, 0.0)
# Info on atoms.
d = dict(
natom=natom,
ntypat=len(types_of_specie),
typat=typat,
znucl=znucl_type,
xred=xred,
)
# Add info on the lattice.
# Should we use (rprim, acell) or (angdeg, acell) to specify the lattice?
geomode = kwargs.pop("geomode", "rprim")
#latt_dict = structure.lattice.to_abivars(geomode=geomode)
if geomode == "rprim":
d.update(dict(
acell=3 * [1.0],
rprim=rprim))
elif geomode == "angdeg":
d.update(dict(
acell=3 * [1.0],
angdeg=angdeg))
else:
raise ValueError("Wrong value for geomode: %s" % geomode)
return d
def contract(s):
"""
>>> assert contract("1 1 1 2 2 3") == "3*1 2*2 1*3"
>>> assert contract("1 1 3 2 3") == "2*1 1*3 1*2 1*3"
"""
if not s: return s
tokens = s.split()
old = tokens[0]
count = [[1, old]]
for t in tokens[1:]:
if t == old:
count[-1][0] += 1
else:
old = t
count.append([1, t])
return " ".join("%d*%s" % (c, t) for c, t in count)
class AbivarAble(six.with_metaclass(abc.ABCMeta, object)):
"""
An `AbivarAble` object provides a method `to_abivars`
that returns a dictionary with the abinit variables.
"""
@abc.abstractmethod
def to_abivars(self):
"""Returns a dictionary with the abinit variables."""
#@abc.abstractmethod
#def from_abivars(cls, vars):
# """Build the object from a dictionary with Abinit variables."""
def __str__(self):
return pformat(self.to_abivars(), indent=1, width=80, depth=None)
def __contains__(self, key):
return key in self.to_abivars()
@singleton
class MandatoryVariable(object):
"""
Singleton used to tag mandatory variables, just because I can use
the cool syntax: variable is MANDATORY!
"""
@singleton
class DefaultVariable(object):
"""Singleton used to tag variables that will have the default value"""
MANDATORY = MandatoryVariable()
DEFAULT = DefaultVariable()
class SpinMode(collections.namedtuple('SpinMode', "mode nsppol nspinor nspden"), AbivarAble, MSONable):
"""
Different configurations of the electron density as implemented in abinit:
One can use as_spinmode to construct the object via SpinMode.as_spinmode
(string) where string can assume the values:
- polarized
- unpolarized
- afm (anti-ferromagnetic)
- spinor (non-collinear magnetism)
- spinor_nomag (non-collinear, no magnetism)
"""
@classmethod
def as_spinmode(cls, obj):
"""Converts obj into a `SpinMode` instance"""
if isinstance(obj, cls):
return obj
else:
# Assume a string with mode
try:
return _mode2spinvars[obj]
except KeyError:
raise KeyError("Wrong value for spin_mode: %s" % str(obj))
def to_abivars(self):
return {
"nsppol": self.nsppol,
"nspinor": self.nspinor,
"nspden": self.nspden,
}
@pmg_serialize
def as_dict(self):
return {k: getattr(self, k) for k in self._fields}
@classmethod
def from_dict(cls, d):
return cls(**{k: d[k] for k in d if k in cls._fields})
# An handy Multiton
_mode2spinvars = {
"unpolarized": SpinMode("unpolarized", 1, 1, 1),
"polarized": SpinMode("polarized", 2, 1, 2),
"afm": SpinMode("afm", 1, 1, 2),
"spinor": SpinMode("spinor", 1, 2, 4),
"spinor_nomag": SpinMode("spinor_nomag", 1, 2, 1),
}
class Smearing(AbivarAble, MSONable):
"""
Variables defining the smearing technique. The preferred way to instanciate
a `Smearing` object is via the class method Smearing.as_smearing(string)
"""
#: Mapping string_mode --> occopt
_mode2occopt = {
'nosmearing': 1,
'fermi_dirac': 3,
'marzari4': 4,
'marzari5': 5,
'methfessel': 6,
'gaussian': 7}
def __init__(self, occopt, tsmear):
self.occopt = occopt
self.tsmear = tsmear
def __str__(self):
s = "occopt %d # %s Smearing\n" % (self.occopt, self.mode)
if self.tsmear:
s += 'tsmear %s' % self.tsmear
return s
def __eq__(self, other):
return (self.occopt == other.occopt and
np.allclose(self.tsmear, other.tsmear))
def __ne__(self, other):
return not self == other
def __bool__(self):
return self.mode != "nosmearing"
# py2 old version
__nonzero__ = __bool__
@classmethod
def as_smearing(cls, obj):
"""
Constructs an instance of `Smearing` from obj. Accepts obj in the form:
* Smearing instance
* "name:tsmear" e.g. "gaussian:0.004" (Hartree units)
* "name:tsmear units" e.g. "gaussian:0.1 eV"
* None --> no smearing
"""
if obj is None:
return Smearing.nosmearing()
if isinstance(obj, cls):
return obj
# obj is a string
if obj == "nosmearing":
return cls.nosmearing()
else:
obj, tsmear = obj.split(":")
obj.strip()
occopt = cls._mode2occopt[obj]
try:
tsmear = float(tsmear)
except ValueError:
tsmear, unit = tsmear.split()
tsmear = units.Energy(float(tsmear), unit).to("Ha")
return cls(occopt, tsmear)
@property
def mode(self):
for (mode_str, occopt) in self._mode2occopt.items():
if occopt == self.occopt:
return mode_str
raise AttributeError("Unknown occopt %s" % self.occopt)
@staticmethod
def nosmearing():
return Smearing(1, 0.0)
def to_abivars(self):
if self.mode == "nosmearing":
return {"occopt": 1, "tsmear": 0.0}
else:
return {"occopt": self.occopt, "tsmear": self.tsmear,}
@pmg_serialize
def as_dict(self):
"""json friendly dict representation of Smearing"""
return {"occopt": self.occopt, "tsmear": self.tsmear}
@staticmethod
def from_dict(d):
return Smearing(d["occopt"], d["tsmear"])
class ElectronsAlgorithm(dict, AbivarAble, MSONable):
"""Variables controlling the SCF/NSCF algorithm."""
# None indicates that we use abinit defaults.
_DEFAULT = dict(
iprcell=None, iscf=None, diemac=None, diemix=None, diemixmag=None,
dielam=None, diegap=None, dielng=None, diecut=None, nstep=50)
def __init__(self, *args, **kwargs):
super(ElectronsAlgorithm, self).__init__(*args, **kwargs)
for k in self:
if k not in self._DEFAULT:
raise ValueError("%s: No default value has been provided for "
"key %s" % (self.__class__.__name__, k))
def to_abivars(self):
return self.copy()
@pmg_serialize
def as_dict(self):
return self.copy()
@classmethod
def from_dict(cls, d):
d = d.copy()
d.pop("@module", None)
d.pop("@class", None)
return cls(**d)
class Electrons(AbivarAble, MSONable):
"""The electronic degrees of freedom"""
def __init__(self, spin_mode="polarized", smearing="fermi_dirac:0.1 eV",
algorithm=None, nband=None, fband=None, charge=0.0, comment=None): # occupancies=None,
"""
Constructor for Electrons object.
Args:
comment: String comment for Electrons
charge: Total charge of the system. Default is 0.
"""
super(Electrons, self).__init__()
self.comment = comment
self.smearing = Smearing.as_smearing(smearing)
self.spin_mode = SpinMode.as_spinmode(spin_mode)
self.nband = nband
self.fband = fband
self.charge = charge
self.algorithm = algorithm
@property
def nsppol(self):
return self.spin_mode.nsppol
@property
def nspinor(self):
return self.spin_mode.nspinor
@property
def nspden(self):
return self.spin_mode.nspden
def as_dict(self):
"json friendly dict representation"
d = {}
d["@module"] = self.__class__.__module__
d["@class"] = self.__class__.__name__
d["spin_mode"] = self.spin_mode.as_dict()
d["smearing"] = self.smearing.as_dict()
d["algorithm"] = self.algorithm.as_dict() if self.algorithm else None
d["nband"] = self.nband
d["fband"] = self.fband
d["charge"] = self.charge
d["comment"] = self.comment
return d
@classmethod
def from_dict(cls, d):
d = d.copy()
d.pop("@module", None)
d.pop("@class", None)
dec = MontyDecoder()
d["spin_mode"] = dec.process_decoded(d["spin_mode"])
d["smearing"] = dec.process_decoded(d["smearing"])
d["algorithm"] = dec.process_decoded(d["algorithm"]) if d["algorithm"] else None
return cls(**d)
def to_abivars(self):
abivars = self.spin_mode.to_abivars()
abivars.update({
"nband" : self.nband,
"fband" : self.fband,
"charge" : self.charge,
})
if self.smearing:
abivars.update(self.smearing.to_abivars())
if self.algorithm:
abivars.update(self.algorithm)
#abivars["#comment"] = self.comment
return abivars
class KSamplingModes(Enum):
monkhorst = 1
path = 2
automatic = 3
class KSampling(AbivarAble, MSONable):
"""
Input variables defining the K-point sampling.
"""
def __init__(self, mode=KSamplingModes.monkhorst, num_kpts= 0,
kpts=((1, 1, 1),),
kpt_shifts=(0.5, 0.5, 0.5),
kpts_weights=None, use_symmetries=True, use_time_reversal=True, chksymbreak=None,
comment=None):
"""
Highly flexible constructor for KSampling objects. The flexibility comes
at the cost of usability and in general, it is recommended that you use
the default constructor only if you know exactly what you are doing and
requires the flexibility. For most usage cases, the object be constructed
far more easily using the convenience static constructors:
#. gamma_only
#. gamma_centered
#. monkhorst
#. monkhorst_automatic
#. path
and it is recommended that you use those.
Args:
mode: Mode for generating k-poits. Use one of the KSamplingModes enum types.
num_kpts: Number of kpoints if mode is "automatic"
Number of division for the sampling of the smallest segment if mode is "path".
Not used for the other modes
kpts: Number of divisions. Even when only a single specification is
required, e.g. in the automatic scheme, the kpts should still
be specified as a 2D array. e.g., [[20]] or [[2,2,2]].
kpt_shifts: Shifts for Kpoints.
use_symmetries: False if spatial symmetries should not be used
to reduce the number of independent k-points.
use_time_reversal: False if time-reversal symmetry should not be used
to reduce the number of independent k-points.
kpts_weights: Optional weights for kpoints. For explicit kpoints.
chksymbreak: Abinit input variable: check whether the BZ sampling preserves the symmetry of the crystal.
comment: String comment for Kpoints
.. note::
The default behavior of the constructor is monkhorst.
"""
if isinstance(mode, six.string_types):
mode = KSamplingModes[mode]
super(KSampling, self).__init__()
self.mode = mode
self.comment = comment
self.num_kpts = num_kpts
self.kpts = kpts
self.kpt_shifts = kpt_shifts
self.kpts_weights = kpts_weights
self.use_symmetries = use_symmetries
self.use_time_reversal = use_time_reversal
self.chksymbreak = chksymbreak
abivars = {}
if mode == KSamplingModes.monkhorst:
assert num_kpts == 0
ngkpt = np.reshape(kpts, 3)
shiftk = np.reshape(kpt_shifts, (-1,3))
if use_symmetries and use_time_reversal: kptopt = 1
if not use_symmetries and use_time_reversal: kptopt = 2
if not use_symmetries and not use_time_reversal: kptopt = 3
if use_symmetries and not use_time_reversal: kptopt = 4
abivars.update({
"ngkpt" : ngkpt,
"shiftk" : shiftk,
"nshiftk" : len(shiftk),
"kptopt" : kptopt,
"chksymbreak": chksymbreak,
})
elif mode == KSamplingModes.path:
if num_kpts <= 0:
raise ValueError("For Path mode, num_kpts must be specified and >0")
kptbounds = np.reshape(kpts, (-1,3))
#print("in path with kptbound: %s " % kptbounds)
abivars.update({
"ndivsm" : num_kpts,
"kptbounds": kptbounds,
"kptopt" : -len(kptbounds)+1,
})
elif mode == KSamplingModes.automatic:
kpts = np.reshape(kpts, (-1,3))
if len(kpts) != num_kpts:
raise ValueError("For Automatic mode, num_kpts must be specified.")
abivars.update({
"kptopt" : 0,
"kpt" : kpts,
"nkpt" : num_kpts,
"kptnrm" : np.ones(num_kpts),
"wtk" : kpts_weights, # for iscf/=-2, wtk.
"chksymbreak": chksymbreak,
})
else:
raise ValueError("Unknown mode %s" % mode)
self.abivars = abivars
#self.abivars["#comment"] = comment
@property
def is_homogeneous(self):
return self.mode not in ["path"]
@classmethod
def gamma_only(cls):
"""Gamma-only sampling"""
return cls(kpt_shifts=(0.0,0.0,0.0), comment="Gamma-only sampling")
@classmethod
def gamma_centered(cls, kpts=(1, 1, 1), use_symmetries=True, use_time_reversal=True):
"""
Convenient static constructor for an automatic Gamma centered Kpoint grid.
Args:
kpts: Subdivisions N_1, N_2 and N_3 along reciprocal lattice vectors.
use_symmetries: False if spatial symmetries should not be used
to reduce the number of independent k-points.
use_time_reversal: False if time-reversal symmetry should not be used
to reduce the number of independent k-points.
Returns:
:class:`KSampling` object.
"""
return cls(kpts=[kpts], kpt_shifts=(0.0, 0.0, 0.0),
use_symmetries=use_symmetries, use_time_reversal=use_time_reversal,
comment="gamma-centered mode")
@classmethod
def monkhorst(cls, ngkpt, shiftk=(0.5, 0.5, 0.5), chksymbreak=None, use_symmetries=True,
use_time_reversal=True, comment=None):
"""
Convenient static constructor for a Monkhorst-Pack mesh.
Args:
ngkpt: Subdivisions N_1, N_2 and N_3 along reciprocal lattice vectors.
shiftk: Shift to be applied to the kpoints.
use_symmetries: Use spatial symmetries to reduce the number of k-points.
use_time_reversal: Use time-reversal symmetry to reduce the number of k-points.
Returns:
:class:`KSampling` object.
"""
return cls(
kpts=[ngkpt], kpt_shifts=shiftk,
use_symmetries=use_symmetries, use_time_reversal=use_time_reversal, chksymbreak=chksymbreak,
comment=comment if comment else "Monkhorst-Pack scheme with user-specified shiftk")
@classmethod
def monkhorst_automatic(cls, structure, ngkpt,
use_symmetries=True, use_time_reversal=True, chksymbreak=None, comment=None):
"""
Convenient static constructor for an automatic Monkhorst-Pack mesh.
Args:
structure: :class:`Structure` object.
ngkpt: Subdivisions N_1, N_2 and N_3 along reciprocal lattice vectors.
use_symmetries: Use spatial symmetries to reduce the number of k-points.
use_time_reversal: Use time-reversal symmetry to reduce the number of k-points.
Returns:
:class:`KSampling` object.
"""
sg = SpacegroupAnalyzer(structure)
#sg.get_crystal_system()
#sg.get_point_group_symbol()
# TODO
nshiftk = 1
#shiftk = 3*(0.5,) # this is the default
shiftk = 3*(0.5,)
#if lattice.ishexagonal:
#elif lattice.isbcc
#elif lattice.isfcc
return cls.monkhorst(
ngkpt, shiftk=shiftk, use_symmetries=use_symmetries, use_time_reversal=use_time_reversal,
chksymbreak=chksymbreak, comment=comment if comment else "Automatic Monkhorst-Pack scheme")
@classmethod
def _path(cls, ndivsm, structure=None, kpath_bounds=None, comment=None):
"""
Static constructor for path in k-space.
Args:
structure: :class:`Structure` object.
kpath_bounds: List with the reduced coordinates of the k-points defining the path.
ndivsm: Number of division for the smallest segment.
comment: Comment string.
Returns:
:class:`KSampling` object.
"""
if kpath_bounds is None:
# Compute the boundaries from the input structure.
from pymatgen.symmetry.bandstructure import HighSymmKpath
sp = HighSymmKpath(structure)
# Flat the array since "path" is a a list of lists!
kpath_labels = []
for labels in sp.kpath["path"]:
kpath_labels.extend(labels)
kpath_bounds = []
for label in kpath_labels:
red_coord = sp.kpath["kpoints"][label]
#print("label %s, red_coord %s" % (label, red_coord))
kpath_bounds.append(red_coord)
return cls(mode=KSamplingModes.path, num_kpts=ndivsm, kpts=kpath_bounds,
comment=comment if comment else "K-Path scheme")
@classmethod
def path_from_structure(cls, ndivsm, structure):
"""See _path for the meaning of the variables"""
return cls._path(ndivsm, structure=structure, comment="K-path generated automatically from structure")
@classmethod
def explicit_path(cls, ndivsm, kpath_bounds):
"""See _path for the meaning of the variables"""
return cls._path(ndivsm, kpath_bounds=kpath_bounds, comment="Explicit K-path")
@classmethod
def automatic_density(cls, structure, kppa, chksymbreak=None, use_symmetries=True, use_time_reversal=True,
shifts=(0.5, 0.5, 0.5)):
"""
Returns an automatic Kpoint object based on a structure and a kpoint
density. Uses Gamma centered meshes for hexagonal cells and Monkhorst-Pack grids otherwise.
Algorithm:
Uses a simple approach scaling the number of divisions along each
reciprocal lattice vector proportional to its length.
Args:
structure: Input structure
kppa: Grid density
"""
lattice = structure.lattice
lengths = lattice.abc
shifts = np.reshape(shifts, (-1, 3))
ngrid = kppa / structure.num_sites / len(shifts)
mult = (ngrid * lengths[0] * lengths[1] * lengths[2]) ** (1 / 3.)
num_div = [int(round(1.0 / lengths[i] * mult)) for i in range(3)]
# ensure that num_div[i] > 0
num_div = [i if i > 0 else 1 for i in num_div]
angles = lattice.angles
hex_angle_tol = 5 # in degrees
hex_length_tol = 0.01 # in angstroms
right_angles = [i for i in range(3) if abs(angles[i] - 90) < hex_angle_tol]
hex_angles = [i for i in range(3)
if abs(angles[i] - 60) < hex_angle_tol or
abs(angles[i] - 120) < hex_angle_tol]
is_hexagonal = (len(right_angles) == 2 and len(hex_angles) == 1
and abs(lengths[right_angles[0]] -
lengths[right_angles[1]]) < hex_length_tol)
#style = KSamplingModes.gamma
#if not is_hexagonal:
# num_div = [i + i % 2 for i in num_div]
# style = KSamplingModes.monkhorst
comment = "pymatge.io.abinit generated KPOINTS with grid density = " + "{} / atom".format(kppa)
return cls(
mode="monkhorst", num_kpts=0, kpts=[num_div], kpt_shifts=shifts,
use_symmetries=use_symmetries, use_time_reversal=use_time_reversal, chksymbreak=chksymbreak,
comment=comment)
def to_abivars(self):
return self.abivars
def as_dict(self):
enc = MontyEncoder()
return {'mode': self.mode.name, 'comment': self.comment,
'num_kpts': self.num_kpts,
'kpts': enc.default(np.array(self.kpts)), 'kpt_shifts': self.kpt_shifts,
'kpts_weights': self.kpts_weights, 'use_symmetries': self.use_symmetries,
'use_time_reversal': self.use_time_reversal, 'chksymbreak': self.chksymbreak,
'@module': self.__class__.__module__, '@class': self.__class__.__name__}
@classmethod
def from_dict(cls, d):
d = d.copy()
d.pop('@module', None)
d.pop('@class', None)
dec = MontyDecoder()
d['kpts'] = dec.process_decoded(d['kpts'])
return cls(**d)
class Constraints(AbivarAble):
"""This object defines the constraints for structural relaxation"""
def to_abivars(self):
raise NotImplementedError("")
class RelaxationMethod(AbivarAble, MSONable):
"""
This object stores the variables for the (constrained) structural optimization
ionmov and optcell specify the type of relaxation.
The other variables are optional and their use depend on ionmov and optcell.
A None value indicates that we use abinit default. Default values can
be modified by passing them to the constructor.
The set of variables are constructed in to_abivars depending on ionmov and optcell.
"""
_default_vars = {
"ionmov" : MANDATORY,
"optcell" : MANDATORY,
"ntime" : 80,
"dilatmx" : 1.05,
"ecutsm" : 0.5,
"strfact" : None,
"tolmxf" : None,
"strtarget" : None,
"atoms_constraints": {}, # Constraints are stored in a dictionary. {} means if no constraint is enforced.
}
IONMOV_DEFAULT = 3
OPTCELL_DEFAULT = 2
def __init__(self, *args, **kwargs):
# Initialize abivars with the default values.
self.abivars = self._default_vars
# Overwrite the keys with the args and kwargs passed to constructor.
self.abivars.update(*args, **kwargs)
self.abivars = AttrDict(self.abivars)
for k in self.abivars:
if k not in self._default_vars:
raise ValueError("%s: No default value has been provided for key %s" % (self.__class__.__name__, k))
for k in self.abivars:
if k is MANDATORY:
raise ValueError("%s: No default value has been provided for the mandatory key %s" %
(self.__class__.__name__, k))
@classmethod
def atoms_only(cls, atoms_constraints=None):
if atoms_constraints is None:
return cls(ionmov=cls.IONMOV_DEFAULT, optcell=0)
else:
return cls(ionmov=cls.IONMOV_DEFAULT, optcell=0, atoms_constraints=atoms_constraints)
@classmethod
def atoms_and_cell(cls, atoms_constraints=None):
if atoms_constraints is None:
return cls(ionmov=cls.IONMOV_DEFAULT, optcell=cls.OPTCELL_DEFAULT)
else:
return cls(ionmov=cls.IONMOV_DEFAULT, optcell=cls.OPTCELL_DEFAULT, atoms_constraints=atoms_constraints)
@property
def move_atoms(self):
"""True if atoms must be moved."""
return self.abivars.ionmov != 0
@property
def move_cell(self):
"""True if lattice parameters must be optimized."""
return self.abivars.optcell != 0
def to_abivars(self):
"""Returns a dictionary with the abinit variables"""
# These variables are always present.
out_vars = {
"ionmov" : self.abivars.ionmov,
"optcell": self.abivars.optcell,
"ntime" : self.abivars.ntime,
}
# Atom relaxation.
if self.move_atoms:
out_vars.update({
"tolmxf": self.abivars.tolmxf,
})
if self.abivars.atoms_constraints:
# Add input variables for constrained relaxation.
raise NotImplementedError("")
out_vars.update(self.abivars.atoms_constraints.to_abivars())
# Cell relaxation.
if self.move_cell:
out_vars.update({
"dilatmx" : self.abivars.dilatmx,
"ecutsm" : self.abivars.ecutsm,
"strfact" : self.abivars.strfact,
"strtarget": self.abivars.strtarget,
})
return out_vars
def as_dict(self):
d = dict(self._default_vars)
d['@module'] = self.__class__.__module__
d['@class'] = self.__class__.__name__
return d
@classmethod
def from_dict(cls, d):
d = d.copy()
d.pop('@module', None)
d.pop('@class', None)
return cls(**d)
class PPModelModes(Enum):
noppmodel = 0
godby = 1
hybersten = 2
linden = 3
farid = 4
class PPModel(AbivarAble, MSONable):
"""
Parameters defining the plasmon-pole technique.
The common way to instanciate a PPModel object is via the class method PPModel.as_ppmodel(string)
"""
@classmethod
def as_ppmodel(cls, obj):
"""
Constructs an instance of PPModel from obj.
Accepts obj in the form:
* PPmodel instance
* string. e.g "godby:12.3 eV", "linden".
"""
if isinstance(obj, cls):
return obj
# obj is a string
if ":" not in obj:
mode, plasmon_freq = obj, None
else:
# Extract mode and plasmon_freq
mode, plasmon_freq = obj.split(":")
try:
plasmon_freq = float(plasmon_freq)
except ValueError:
plasmon_freq, unit = plasmon_freq.split()
plasmon_freq = units.Energy(float(plasmon_freq), unit).to("Ha")
return cls(mode=mode, plasmon_freq=plasmon_freq)
def __init__(self, mode="godby", plasmon_freq=None):
if isinstance(mode, six.string_types):
mode = PPModelModes[mode]
self.mode = mode
self.plasmon_freq = plasmon_freq
def __eq__(self, other):
if other is None:
return False
else:
if self.mode != other.mode:
return False
if self.plasmon_freq is None:
return other.plasmon_freq is None
else:
return np.allclose(self.plasmon_freq, other.plasmon_freq)
def __ne__(self, other):
return not self == other
def __bool__(self):
return self.mode != PPModelModes.noppmodel
# py2 old version
__nonzero__ = __bool__
def __repr__(self):
return "<%s at %s, mode = %s>" % (self.__class__.__name__, id(self),
str(self.mode))
def to_abivars(self):
if self:
return {"ppmodel": self.mode.value,
"ppmfrq": self.plasmon_freq}
else:
return {}
@classmethod
def get_noppmodel(cls):
return cls(mode="noppmodel", plasmon_freq=None)
def as_dict(self):
return {"mode": self.mode.name, "plasmon_freq": self.plasmon_freq,
"@module": self.__class__.__module__,
"@class": self.__class__.__name__}
@staticmethod
def from_dict(d):
return PPModel(mode=d["mode"], plasmon_freq=d["plasmon_freq"])
class HilbertTransform(AbivarAble):
"""
Parameters for the Hilbert-transform method (Screening code)
i.e. the parameters defining the frequency mesh used for the spectral function
and the frequency mesh used for the polarizability
"""
def __init__(self, nomegasf, domegasf=None, spmeth=1, nfreqre=None, freqremax=None, nfreqim=None, freqremin=None):
"""
Args:
nomegasf: Number of points for sampling the spectral function along the real axis.
domegasf: Step in Ha for the linear mesh used for the spectral function.
spmeth: Algorith for the representation of the delta function.
nfreqre: Number of points along the real axis (linear mesh).
freqremax: Maximum frequency for W along the real axis (in hartree).
nfreqim: Number of point along the imaginary axis (Gauss-Legendre mesh).
freqremin: Minimum frequency for W along the real axis (in hartree).
"""
# Spectral function
self.nomegasf = nomegasf
self.domegasf = domegasf
self.spmeth = spmeth
# Mesh for the contour-deformation method used for the integration of the self-energy
self.nfreqre = nfreqre
self.freqremax = freqremax
self.freqremin = freqremin
self.nfreqim = nfreqim
def to_abivars(self):
"""Returns a dictionary with the abinit variables"""
return {
# Spectral function
"nomegasf": self.nomegasf,
"domegasf": self.domegasf,
"spmeth" : self.spmeth,
# Frequency mesh for the polarizability
"nfreqre" : self.nfreqre,
"freqremax": self.freqremax,
"nfreqim" : self.nfreqim,
"freqremin": self.freqremin,
}
class ModelDielectricFunction(AbivarAble):
"""Model dielectric function used for BSE calculation"""
def __init__(self, mdf_epsinf):
self.mdf_epsinf = mdf_epsinf
def to_abivars(self):
return {"mdf_epsinf": self.mdf_epsinf}
##########################################################################################
################################# WORK IN PROGRESS ######################################
##########################################################################################
class Screening(AbivarAble):
"""
This object defines the parameters used for the
computation of the screening function.
"""
# Approximations used for W
_WTYPES = {
"RPA": 0,
}
# Self-consistecy modes
_SC_MODES = {
"one_shot" : 0,
"energy_only" : 1,
"wavefunctions": 2,
}
def __init__(self, ecuteps, nband, w_type="RPA", sc_mode="one_shot",
hilbert=None, ecutwfn=None, inclvkb=2):
"""
Args:
ecuteps: Cutoff energy for the screening (Ha units).
nband Number of bands for the Green's function
w_type: Screening type
sc_mode: Self-consistency mode.
hilbert: Instance of :class:`HilbertTransform` defining the parameters for the Hilber transform method.
ecutwfn: Cutoff energy for the wavefunctions (Default: ecutwfn == ecut).
inclvkb: Option for the treatment of the dipole matrix elements (NC pseudos).
"""
if w_type not in self._WTYPES:
raise ValueError("W_TYPE: %s is not supported" % w_type)
if sc_mode not in self._SC_MODES:
raise ValueError("Self-consistecy mode %s is not supported" % sc_mode)
self.ecuteps = ecuteps
self.nband = nband
self.w_type = w_type
self.sc_mode = sc_mode
self.ecutwfn = ecutwfn
self.inclvkb = inclvkb
if hilbert is not None:
raise NotImplementedError("Hilber transform not coded yet")
self.hilbert = hilbert
# Default values (equivalent to those used in Abinit8)
self.gwpara=2
self.awtr =1
self.symchi=1
self.optdriver = 3
@property
def use_hilbert(self):
return hasattr(self, "hilbert")
#@property
#def gwcalctyp(self):
# "Return the value of the gwcalctyp input variable"
# dig0 = str(self._SIGMA_TYPES[self.type])
# dig1 = str(self._SC_MODES[self.sc_mode]
# return dig1.strip() + dig0.strip()
def to_abivars(self):
"""Returns a dictionary with the abinit variables"""
abivars = {
"ecuteps" : self.ecuteps,
"ecutwfn" : self.ecutwfn,
"inclvkb" : self.inclvkb,
"gwpara" : self.gwpara,
"awtr" : self.awtr,
"symchi" : self.symchi,
"nband" : self.nband,
#"gwcalctyp": self.gwcalctyp,
#"fftgw" : self.fftgw,
"optdriver" : self.optdriver,
}
# Variables for the Hilber transform.
if self.use_hilbert:
abivars.update(self.hilbert.to_abivars())
return abivars
class SelfEnergy(AbivarAble):
"""
This object defines the parameters used for the computation of the self-energy.
"""
_SIGMA_TYPES = {
"gw" : 0,
"hartree_fock": 5,
"sex" : 6,
"cohsex" : 7,
"model_gw_ppm": 8,
"model_gw_cd" : 9,
}
_SC_MODES = {
"one_shot" : 0,
"energy_only" : 1,
"wavefunctions": 2,
}
def __init__(self, se_type, sc_mode, nband, ecutsigx, screening,
gw_qprange=1, ppmodel=None, ecuteps=None, ecutwfn=None, gwpara=2):
"""
Args:
se_type: Type of self-energy (str)
sc_mode: Self-consistency mode.
nband: Number of bands for the Green's function
ecutsigx: Cutoff energy for the exchange part of the self-energy (Ha units).
screening: :class:`Screening` instance.
gw_qprange: Option for the automatic selection of k-points and bands for GW corrections.
See Abinit docs for more detail. The default value makes the code computie the
QP energies for all the point in the IBZ and one band above and one band below the Fermi level.
ppmodel: :class:`PPModel` instance with the parameters used for the plasmon-pole technique.
ecuteps: Cutoff energy for the screening (Ha units).
ecutwfn: Cutoff energy for the wavefunctions (Default: ecutwfn == ecut).
"""
if se_type not in self._SIGMA_TYPES:
raise ValueError("SIGMA_TYPE: %s is not supported" % se_type)
if sc_mode not in self._SC_MODES:
raise ValueError("Self-consistecy mode %s is not supported" % sc_mode)
self.type = se_type
self.sc_mode = sc_mode
self.nband = nband
self.ecutsigx = ecutsigx
self.screening = screening
self.gw_qprange = gw_qprange
self.gwpara = gwpara
if ppmodel is not None:
assert not screening.use_hilbert
self.ppmodel = PPModel.as_ppmodel(ppmodel)
self.ecuteps = ecuteps if ecuteps is not None else screening.ecuteps
self.ecutwfn = ecutwfn
self.optdriver = 4
#band_mode in ["gap", "full"]
#if isinstance(kptgw, str) and kptgw == "all":
# self.kptgw = None
# self.nkptgw = None
#else:
# self.kptgw = np.reshape(kptgw, (-1,3))
# self.nkptgw = len(self.kptgw)
#if bdgw is None:
# raise ValueError("bdgw must be specified")
#if isinstance(bdgw, str):
# # TODO add new variable in Abinit so that we can specify
# # an energy interval around the KS gap.
# homo = float(nele) / 2.0
# #self.bdgw =
#else:
# self.bdgw = np.reshape(bdgw, (-1,2))
#self.freq_int = freq_int
@property
def use_ppmodel(self):
"""True if we are using the plasmon-pole approximation."""
return hasattr(self, "ppmodel")
@property
def gwcalctyp(self):
"""Returns the value of the gwcalctyp input variable."""
dig0 = str(self._SIGMA_TYPES[self.type])
dig1 = str(self._SC_MODES[self.sc_mode])
return dig1.strip() + dig0.strip()
@property
def symsigma(self):
"""1 if symmetries can be used to reduce the number of q-points."""
return 1 if self.sc_mode == "one_shot" else 0
def to_abivars(self):
"""Returns a dictionary with the abinit variables."""
abivars = dict(
gwcalctyp=self.gwcalctyp,
ecuteps=self.ecuteps,
ecutsigx=self.ecutsigx,
symsigma=self.symsigma,
gw_qprange=self.gw_qprange,
gwpara=self.gwpara,
optdriver=self.optdriver,
nband=self.nband
#"ecutwfn" : self.ecutwfn,
#"kptgw" : self.kptgw,
#"nkptgw" : self.nkptgw,
#"bdgw" : self.bdgw,
)
# FIXME: problem with the spin
#assert len(self.bdgw) == self.nkptgw
# ppmodel variables
if self.use_ppmodel:
abivars.update(self.ppmodel.to_abivars())
return abivars
class ExcHamiltonian(AbivarAble):
"""This object contains the parameters for the solution of the Bethe-Salpeter equation."""
# Types of excitonic Hamiltonian.
_EXC_TYPES = {
"TDA": 0, # Tamm-Dancoff approximation.
"coupling": 1, # Calculation with coupling.
}
# Algorithms used to compute the macroscopic dielectric function
# and/or the exciton wavefunctions.
_ALGO2VAR = {
"direct_diago": 1,
"haydock" : 2,
"cg" : 3,
}
# Options specifying the treatment of the Coulomb term.
_COULOMB_MODES = [
"diago",
"full",
"model_df"
]
def __init__(self, bs_loband, nband, mbpt_sciss, coulomb_mode, ecuteps, spin_mode="polarized", mdf_epsinf=None,
exc_type="TDA", algo="haydock", with_lf=True, bs_freq_mesh=None, zcut=None, **kwargs):
"""
Args:
bs_loband: Lowest band index (Fortran convention) used in the e-h basis set.
Can be scalar or array of shape (nsppol,). Must be >= 1 and <= nband
nband: Max band index used in the e-h basis set.
mbpt_sciss: Scissors energy in Hartree.
coulomb_mode: Treatment of the Coulomb term.
ecuteps: Cutoff energy for W in Hartree.
mdf_epsinf: Macroscopic dielectric function :math:`\\epsilon_\\inf` used in
the model dielectric function.
exc_type: Approximation used for the BSE Hamiltonian
with_lf: True if local field effects are included <==> exchange term is included
bs_freq_mesh: Frequency mesh for the macroscopic dielectric function (start, stop, step) in Ha.
zcut: Broadening parameter in Ha.
**kwargs:
Extra keywords
"""
spin_mode = SpinMode.as_spinmode(spin_mode)
# We want an array bs_loband(nsppol).
try:
bs_loband = np.reshape(bs_loband, spin_mode.nsppol)
except ValueError:
bs_loband = np.array(spin_mode.nsppol * [int(bs_loband)])
self.bs_loband = bs_loband
self.nband = nband
self.mbpt_sciss = mbpt_sciss
self.coulomb_mode = coulomb_mode
assert coulomb_mode in self._COULOMB_MODES
self.ecuteps = ecuteps
self.mdf_epsinf = mdf_epsinf
self.exc_type = exc_type
assert exc_type in self._EXC_TYPES
self.algo = algo
assert algo in self._ALGO2VAR
self.with_lf = with_lf
# if bs_freq_mesh is not given, abinit will select its own mesh.
self.bs_freq_mesh = np.array(bs_freq_mesh) if bs_freq_mesh is not None else bs_freq_mesh
self.zcut = zcut
self.optdriver = 99
# Extra options.
self.kwargs = kwargs
#if "chksymbreak" not in self.kwargs:
# self.kwargs["chksymbreak"] = 0
# Consistency check
if any(bs_loband < 0):
raise ValueError("bs_loband <= 0 while it is %s" % bs_loband)
if any(bs_loband >= nband):
raise ValueError("bs_loband (%s) >= nband (%s)" % (bs_loband, nband))
@property
def inclvkb(self):
"""Treatment of the dipole matrix element (NC pseudos, default is 2)"""
return self.kwargs.get("inclvkb", 2)
@property
def use_haydock(self):
"""True if we are using the Haydock iterative technique."""
return self.algo == "haydock"
@property
def use_cg(self):
"""True if we are using the conjugate gradient method."""
return self.algo == "cg"
@property
def use_direct_diago(self):
"""True if we are performing the direct diagonalization of the BSE Hamiltonian."""
return self.algo == "direct_diago"
def to_abivars(self):
"""Returns a dictionary with the abinit variables."""
abivars = dict(
bs_calctype=1,
bs_loband=self.bs_loband,
#nband=self.nband,
mbpt_sciss=self.mbpt_sciss,
ecuteps=self.ecuteps,
bs_algorithm=self._ALGO2VAR[self.algo],
bs_coulomb_term=21,
mdf_epsinf=self.mdf_epsinf,
bs_exchange_term=1 if self.with_lf else 0,
inclvkb=self.inclvkb,
zcut=self.zcut,
bs_freq_mesh=self.bs_freq_mesh,
bs_coupling=self._EXC_TYPES[self.exc_type],
optdriver=self.optdriver,
)
if self.use_haydock:
# FIXME
abivars.update(
bs_haydock_niter=100, # No. of iterations for Haydock
bs_hayd_term=0, # No terminator
bs_haydock_tol=[0.05, 0], # Stopping criteria
)
elif self.use_direct_diago:
raise NotImplementedError("")
elif self.use_cg:
raise NotImplementedError("")
else:
raise ValueError("Unknown algorithm for EXC: %s" % self.algo)
# Add extra kwargs
abivars.update(self.kwargs)
return abivars
|
mit
|
[
3,
2803,
26,
2774,
13,
24,
199,
3,
1898,
334,
67,
9,
1611,
30649,
15290,
11682,
14,
199,
3,
17484,
1334,
314,
2895,
402,
314,
10697,
844,
14,
199,
624,
199,
10281,
13,
1896,
2251,
13070,
376,
2236,
29639,
367,
314,
2251,
28244,
315,
314,
15232,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
12,
4629,
12,
870,
63,
1593,
199,
199,
646,
5055,
199,
646,
13022,
199,
646,
3816,
199,
646,
2680,
465,
980,
199,
646,
1134,
30649,
14,
1018,
14,
5260,
465,
6204,
199,
199,
504,
10933,
492,
30843,
199,
504,
3485,
369,
14,
14748,
63,
7435,
492,
19768,
199,
504,
3485,
369,
14,
7882,
492,
20516,
2141,
199,
504,
4952,
492,
11305,
199,
504,
3485,
369,
14,
1001,
492,
603,
3377,
461,
199,
504,
1134,
30649,
14,
1018,
14,
5260,
492,
8725,
3007,
5072,
199,
504,
1134,
30649,
14,
1018,
14,
25553,
492,
491,
292,
3548,
199,
504,
1134,
30649,
14,
1018,
14,
6976,
492,
21730,
199,
504,
1134,
30649,
14,
1974,
14,
12161,
492,
299,
6649,
63,
3549,
199,
504,
1134,
30649,
14,
3840,
10987,
14,
17965,
492,
19326,
923,
17606,
199,
504,
3485,
369,
14,
1001,
492,
10953,
369,
6679,
12,
10953,
369,
8326,
421,
199,
318,
30952,
63,
504,
63,
371,
1003,
4291,
8,
1886,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
272,
1803,
282,
658,
22510,
3548,
64,
909,
687,
282,
2600,
272,
543,
314,
8351,
826,
2860,
658,
65,
3890,
64,
436,
1902,
658,
82,
31878,
64,
315,
5088,
6271,
503,
658,
621,
6458,
64,
272,
982,
282,
3890,
365,
440,
1627,
12,
314,
8351,
826,
849,
365,
1202,
284,
14,
69,
14,
359,
17,
12,
17,
12,
17,
61,
5088,
6271,
339,
3033,
26,
267,
843,
26,
491,
292,
3548,
1021,
370,
506,
17544,
14,
1134,
30649,
14,
1018,
14,
25553,
14,
22510,
3548,
340,
658,
1886,
64,
365,
488,
339,
5679,
26,
398,
30952,
63,
504,
63,
371,
1003,
4291,
8,
65,
3890,
29,
19,
23033,
709,
467,
519,
31878,
29,
1590,
14,
15240,
8,
19,
430,
272,
408,
272,
843,
275,
491,
292,
3548,
340,
843,
365,
488,
587,
843,
272,
2074,
14,
873,
8,
807,
2031,
589,
430,
272,
366,
275,
2074,
339,
519,
31878,
275,
366,
14,
362,
480,
82,
31878,
401,
488,
9,
272,
14550,
6458,
275,
366,
14,
362,
480,
621,
6458,
401,
488,
9,
272,
282,
3890,
275,
366,
905,
65,
3890,
937,
339,
340,
519,
31878,
365,
440,
488,
26,
267,
340,
14550,
6458,
365,
440,
488,
26,
288,
746,
1722,
480,
621,
6458,
436,
519,
1359,
1064,
787,
16108,
13914,
531,
267,
519,
31878,
275,
980,
14,
5217,
8,
82,
31878,
12,
334,
19,
12,
19,
430,
267,
519,
1359,
1064,
275,
359,
1609,
8,
65,
3890,
59,
73,
566,
627,
519,
31878,
59,
73,
61,
367,
284,
315,
1425,
8,
19,
1874,
267,
327,
6523,
1134,
30649,
31604,
334,
4610,
626,
1134,
30649,
4440,
1626,
23908,
417,
3140,
402,
5088,
6271,
680,
267,
372,
843,
8,
3836,
3007,
5072,
8,
82,
1359,
1064,
12,
298,
656,
6271,
3471,
475,
480,
621,
2237,
339,
916,
14550,
6458,
365,
440,
488,
26,
267,
14550,
6458,
275,
980,
14,
5217,
8,
621,
6458,
12,
650,
9,
398,
340,
980,
14,
1629,
8,
621,
6458,
2695,
378,
14,
304,
288,
746,
1722,
480,
2493,
27033,
1471,
506,
690,
378,
1325,
4788,
450,
83,
2,
450,
620,
8,
621,
6458,
430,
267,
340,
14550,
6458,
14,
1838,
342,
2356,
19434,
16781,
288,
746,
1722,
480,
1918,
3089,
402,
14550,
6458,
1471,
506,
5117,
626,
19434,
12,
14550,
6458,
450,
83,
2,
450,
620,
8,
621,
6458,
430,
398,
327,
961,
1233,
11924,
314,
4514,
315,
315,
6721,
14,
38,
2710,
267,
327,
1666,
2597,
1455,
921,
1544,
14,
371,
826,
14,
1308,
15,
1301,
15,
3437,
1725,
15,
509,
13,
86,
23,
14,
24,
15,
1210,
63,
3669,
15,
1391,
31917,
14,
1360,
3,
621,
6458,
267,
9561,
713,
275,
413,
69,
13,
713,
267,
6682,
12,
9829,
12,
9794,
12,
7452,
275,
980,
14,
1038,
12,
980,
14,
5911,
12,
980,
14,
5197,
12,
980,
14,
5079,
267,
519,
31878,
275,
980,
14,
4250,
1332,
19,
12,
19,
430,
267,
340,
334,
2101,
8,
621,
6458,
59,
16,
61,
446,
621,
6458,
59,
17,
566,
665,
9561,
713,
436,
2853,
8,
621,
6458,
59,
17,
61,
446,
14550,
6458,
59,
18,
566,
665,
9561,
713,
436,
288,
2853,
8,
621,
6458,
59,
16,
11285,
2710,
4959,
435,
2853,
8,
621,
6458,
59,
17,
11285,
2710,
4959,
435,
2853,
8,
621,
6458,
59,
18,
61,
446,
2710,
9,
690,
9561,
713,
304,
288,
327,
377,
8319,
314,
1930,
402,
4472,
22597,
334,
2590,
1006,
2451,
22597,
304,
288,
327,
12821,
3229,
71,
8125,
30246,
23105,
10919,
3114,
288,
9794,
621,
275,
9794,
8,
1038,
627,
14550,
6458,
59,
16,
12978,
7663,
14,
16,
9,
288,
282,
18,
275,
499,
14,
16,
15,
19,
14,
16,
5830,
17,
14,
16,
446,
9794,
621,
9,
288,
18319,
275,
7452,
8,
65,
18,
9,
288,
7429,
275,
7452,
8,
17,
14,
16,
13,
65,
18,
9,
288,
519,
31878,
59,
16,
12,
16,
61,
275,
18319,
258,
8700,
519,
31878,
59,
16,
12,
17,
61,
275,
378,
14,
16,
4519,
8700,
519,
31878,
59,
16,
12,
18,
61,
275,
7429,
288,
519,
31878,
59,
17,
12,
16,
61,
275,
446,
16,
14,
21,
10,
2158,
27,
519,
31878,
59,
17,
12,
17,
61,
275,
7452,
8,
19,
14,
16,
3342,
16,
14,
21,
10,
2158,
8700,
519,
31878,
59,
17,
12,
18,
61,
275,
7429,
288,
519,
31878,
59,
18,
12,
16,
61,
275,
446,
16,
14,
21,
10,
2158,
27,
519,
31878,
59,
18,
12,
17,
61,
275,
446,
5079,
8,
19,
14,
16,
3342,
16,
14,
21,
10,
2158,
27,
519,
31878,
59,
18,
12,
18,
61,
275,
7429,
267,
587,
26,
288,
327,
377,
8319,
1006,
314,
1163,
5560,
288,
519,
31878,
59,
16,
12,
16,
61,
275,
413,
14,
16,
288,
519,
31878,
59,
17,
12,
16,
61,
275,
9794,
8,
1038,
10,
621,
6458,
59,
18,
12978,
7663,
4959,
288
] |
[
2803,
26,
2774,
13,
24,
199,
3,
1898,
334,
67,
9,
1611,
30649,
15290,
11682,
14,
199,
3,
17484,
1334,
314,
2895,
402,
314,
10697,
844,
14,
199,
624,
199,
10281,
13,
1896,
2251,
13070,
376,
2236,
29639,
367,
314,
2251,
28244,
315,
314,
15232,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
12,
4629,
12,
870,
63,
1593,
199,
199,
646,
5055,
199,
646,
13022,
199,
646,
3816,
199,
646,
2680,
465,
980,
199,
646,
1134,
30649,
14,
1018,
14,
5260,
465,
6204,
199,
199,
504,
10933,
492,
30843,
199,
504,
3485,
369,
14,
14748,
63,
7435,
492,
19768,
199,
504,
3485,
369,
14,
7882,
492,
20516,
2141,
199,
504,
4952,
492,
11305,
199,
504,
3485,
369,
14,
1001,
492,
603,
3377,
461,
199,
504,
1134,
30649,
14,
1018,
14,
5260,
492,
8725,
3007,
5072,
199,
504,
1134,
30649,
14,
1018,
14,
25553,
492,
491,
292,
3548,
199,
504,
1134,
30649,
14,
1018,
14,
6976,
492,
21730,
199,
504,
1134,
30649,
14,
1974,
14,
12161,
492,
299,
6649,
63,
3549,
199,
504,
1134,
30649,
14,
3840,
10987,
14,
17965,
492,
19326,
923,
17606,
199,
504,
3485,
369,
14,
1001,
492,
10953,
369,
6679,
12,
10953,
369,
8326,
421,
199,
318,
30952,
63,
504,
63,
371,
1003,
4291,
8,
1886,
29,
403,
12,
627,
589,
12,
1011,
958,
304,
272,
408,
272,
1803,
282,
658,
22510,
3548,
64,
909,
687,
282,
2600,
272,
543,
314,
8351,
826,
2860,
658,
65,
3890,
64,
436,
1902,
658,
82,
31878,
64,
315,
5088,
6271,
503,
658,
621,
6458,
64,
272,
982,
282,
3890,
365,
440,
1627,
12,
314,
8351,
826,
849,
365,
1202,
284,
14,
69,
14,
359,
17,
12,
17,
12,
17,
61,
5088,
6271,
339,
3033,
26,
267,
843,
26,
491,
292,
3548,
1021,
370,
506,
17544,
14,
1134,
30649,
14,
1018,
14,
25553,
14,
22510,
3548,
340,
658,
1886,
64,
365,
488,
339,
5679,
26,
398,
30952,
63,
504,
63,
371,
1003,
4291,
8,
65,
3890,
29,
19,
23033,
709,
467,
519,
31878,
29,
1590,
14,
15240,
8,
19,
430,
272,
408,
272,
843,
275,
491,
292,
3548,
340,
843,
365,
488,
587,
843,
272,
2074,
14,
873,
8,
807,
2031,
589,
430,
272,
366,
275,
2074,
339,
519,
31878,
275,
366,
14,
362,
480,
82,
31878,
401,
488,
9,
272,
14550,
6458,
275,
366,
14,
362,
480,
621,
6458,
401,
488,
9,
272,
282,
3890,
275,
366,
905,
65,
3890,
937,
339,
340,
519,
31878,
365,
440,
488,
26,
267,
340,
14550,
6458,
365,
440,
488,
26,
288,
746,
1722,
480,
621,
6458,
436,
519,
1359,
1064,
787,
16108,
13914,
531,
267,
519,
31878,
275,
980,
14,
5217,
8,
82,
31878,
12,
334,
19,
12,
19,
430,
267,
519,
1359,
1064,
275,
359,
1609,
8,
65,
3890,
59,
73,
566,
627,
519,
31878,
59,
73,
61,
367,
284,
315,
1425,
8,
19,
1874,
267,
327,
6523,
1134,
30649,
31604,
334,
4610,
626,
1134,
30649,
4440,
1626,
23908,
417,
3140,
402,
5088,
6271,
680,
267,
372,
843,
8,
3836,
3007,
5072,
8,
82,
1359,
1064,
12,
298,
656,
6271,
3471,
475,
480,
621,
2237,
339,
916,
14550,
6458,
365,
440,
488,
26,
267,
14550,
6458,
275,
980,
14,
5217,
8,
621,
6458,
12,
650,
9,
398,
340,
980,
14,
1629,
8,
621,
6458,
2695,
378,
14,
304,
288,
746,
1722,
480,
2493,
27033,
1471,
506,
690,
378,
1325,
4788,
450,
83,
2,
450,
620,
8,
621,
6458,
430,
267,
340,
14550,
6458,
14,
1838,
342,
2356,
19434,
16781,
288,
746,
1722,
480,
1918,
3089,
402,
14550,
6458,
1471,
506,
5117,
626,
19434,
12,
14550,
6458,
450,
83,
2,
450,
620,
8,
621,
6458,
430,
398,
327,
961,
1233,
11924,
314,
4514,
315,
315,
6721,
14,
38,
2710,
267,
327,
1666,
2597,
1455,
921,
1544,
14,
371,
826,
14,
1308,
15,
1301,
15,
3437,
1725,
15,
509,
13,
86,
23,
14,
24,
15,
1210,
63,
3669,
15,
1391,
31917,
14,
1360,
3,
621,
6458,
267,
9561,
713,
275,
413,
69,
13,
713,
267,
6682,
12,
9829,
12,
9794,
12,
7452,
275,
980,
14,
1038,
12,
980,
14,
5911,
12,
980,
14,
5197,
12,
980,
14,
5079,
267,
519,
31878,
275,
980,
14,
4250,
1332,
19,
12,
19,
430,
267,
340,
334,
2101,
8,
621,
6458,
59,
16,
61,
446,
621,
6458,
59,
17,
566,
665,
9561,
713,
436,
2853,
8,
621,
6458,
59,
17,
61,
446,
14550,
6458,
59,
18,
566,
665,
9561,
713,
436,
288,
2853,
8,
621,
6458,
59,
16,
11285,
2710,
4959,
435,
2853,
8,
621,
6458,
59,
17,
11285,
2710,
4959,
435,
2853,
8,
621,
6458,
59,
18,
61,
446,
2710,
9,
690,
9561,
713,
304,
288,
327,
377,
8319,
314,
1930,
402,
4472,
22597,
334,
2590,
1006,
2451,
22597,
304,
288,
327,
12821,
3229,
71,
8125,
30246,
23105,
10919,
3114,
288,
9794,
621,
275,
9794,
8,
1038,
627,
14550,
6458,
59,
16,
12978,
7663,
14,
16,
9,
288,
282,
18,
275,
499,
14,
16,
15,
19,
14,
16,
5830,
17,
14,
16,
446,
9794,
621,
9,
288,
18319,
275,
7452,
8,
65,
18,
9,
288,
7429,
275,
7452,
8,
17,
14,
16,
13,
65,
18,
9,
288,
519,
31878,
59,
16,
12,
16,
61,
275,
18319,
258,
8700,
519,
31878,
59,
16,
12,
17,
61,
275,
378,
14,
16,
4519,
8700,
519,
31878,
59,
16,
12,
18,
61,
275,
7429,
288,
519,
31878,
59,
17,
12,
16,
61,
275,
446,
16,
14,
21,
10,
2158,
27,
519,
31878,
59,
17,
12,
17,
61,
275,
7452,
8,
19,
14,
16,
3342,
16,
14,
21,
10,
2158,
8700,
519,
31878,
59,
17,
12,
18,
61,
275,
7429,
288,
519,
31878,
59,
18,
12,
16,
61,
275,
446,
16,
14,
21,
10,
2158,
27,
519,
31878,
59,
18,
12,
17,
61,
275,
446,
5079,
8,
19,
14,
16,
3342,
16,
14,
21,
10,
2158,
27,
519,
31878,
59,
18,
12,
18,
61,
275,
7429,
267,
587,
26,
288,
327,
377,
8319,
1006,
314,
1163,
5560,
288,
519,
31878,
59,
16,
12,
16,
61,
275,
413,
14,
16,
288,
519,
31878,
59,
17,
12,
16,
61,
275,
9794,
8,
1038,
10,
621,
6458,
59,
18,
12978,
7663,
4959,
288,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
375
|
1493
|
# Symbolic constants for Tk
# Booleans
NO=FALSE=OFF=0
YES=TRUE=ON=1
# -anchor and -sticky
N='n'
S='s'
W='w'
E='e'
NW='nw'
SW='sw'
NE='ne'
SE='se'
NS='ns'
EW='ew'
NSEW='nsew'
CENTER='center'
# -fill
NONE='none'
X='x'
Y='y'
BOTH='both'
# -side
LEFT='left'
TOP='top'
RIGHT='right'
BOTTOM='bottom'
# -relief
RAISED='raised'
SUNKEN='sunken'
FLAT='flat'
RIDGE='ridge'
GROOVE='groove'
SOLID = 'solid'
# -orient
HORIZONTAL='horizontal'
VERTICAL='vertical'
# -tabs
NUMERIC='numeric'
# -wrap
CHAR='char'
WORD='word'
# -align
BASELINE='baseline'
# -bordermode
INSIDE='inside'
OUTSIDE='outside'
# Special tags, marks and insert positions
SEL='sel'
SEL_FIRST='sel.first'
SEL_LAST='sel.last'
END='end'
INSERT='insert'
CURRENT='current'
ANCHOR='anchor'
ALL='all' # e.g. Canvas.delete(ALL)
# Text widget and button states
NORMAL='normal'
DISABLED='disabled'
ACTIVE='active'
# Canvas state
HIDDEN='hidden'
# Menu item types
CASCADE='cascade'
CHECKBUTTON='checkbutton'
COMMAND='command'
RADIOBUTTON='radiobutton'
SEPARATOR='separator'
# Selection modes for list boxes
SINGLE='single'
BROWSE='browse'
MULTIPLE='multiple'
EXTENDED='extended'
# Activestyle for list boxes
# NONE='none' is also valid
DOTBOX='dotbox'
UNDERLINE='underline'
# Various canvas styles
PIESLICE='pieslice'
CHORD='chord'
ARC='arc'
FIRST='first'
LAST='last'
BUTT='butt'
PROJECTING='projecting'
ROUND='round'
BEVEL='bevel'
MITER='miter'
# Arguments to xview/yview
MOVETO='moveto'
SCROLL='scroll'
UNITS='units'
PAGES='pages'
|
gpl-2.0
|
[
3,
21478,
9670,
5262,
367,
12435,
199,
199,
3,
699,
1534,
274,
796,
199,
2826,
29,
19823,
29,
7517,
29,
16,
199,
15641,
29,
15064,
29,
615,
29,
17,
199,
199,
3,
446,
11498,
436,
446,
27364,
199,
46,
534,
78,
7,
199,
51,
534,
83,
7,
199,
55,
534,
87,
7,
199,
37,
534,
69,
7,
199,
23471,
534,
13100,
7,
199,
8745,
534,
3519,
7,
199,
6388,
534,
685,
7,
199,
899,
534,
261,
7,
199,
2709,
534,
561,
7,
199,
37,
55,
534,
546,
7,
199,
46,
899,
55,
534,
19315,
87,
7,
199,
17611,
534,
4218,
7,
199,
199,
3,
446,
4498,
199,
9185,
534,
3592,
7,
199,
56,
534,
88,
7,
199,
57,
534,
89,
7,
199,
28784,
534,
10727,
7,
199,
199,
3,
446,
2441,
199,
9894,
534,
3039,
7,
199,
11422,
534,
2119,
7,
199,
12811,
534,
1019,
7,
199,
27838,
534,
8305,
7,
199,
199,
3,
446,
26557,
2829,
199,
2847,
9359,
534,
21597,
7,
199,
23627,
6945,
534,
11846,
917,
7,
199,
3143,
619,
534,
7088,
7,
199,
50,
998,
4962,
534,
5562,
7,
199,
39,
1092,
47,
2524,
534,
23260,
79,
432,
7,
199,
15096,
998,
275,
283,
18533,
7,
199,
199,
3,
446,
19676,
199,
25968,
534,
11392,
7,
199,
22634,
534,
7870,
7,
199,
199,
3,
446,
8741,
199,
28425,
534,
6677,
7,
199,
199,
3,
446,
3823,
199,
5901,
534,
1560,
7,
199,
5172,
534,
1027,
7,
199,
199,
3,
446,
5743,
199,
5825,
6174,
534,
14232,
7,
199,
199,
3,
446,
8665,
632,
199,
10789,
11259,
534,
17183,
7,
199,
1877,
28035,
534,
22431,
7,
199,
199,
3,
12568,
3762,
12,
17370,
436,
5518,
12266,
199,
899,
44,
534,
5891,
7,
199,
899,
44,
63,
12903,
534,
5891,
14,
2246,
7,
199,
899,
44,
63,
16901,
534,
5891,
14,
2019,
7,
199,
3902,
534,
500,
7,
199,
10258,
534,
3176,
7,
199,
14211,
534,
1818,
7,
199,
20139,
726,
534,
11498,
7,
199,
1761,
534,
452,
7,
327,
325,
14,
71,
14,
29349,
14,
1807,
8,
1761,
9,
199,
199,
3,
4516,
3938,
436,
5528,
6363,
199,
10765,
534,
3302,
7,
199,
16205,
534,
7011,
7,
199,
10401,
534,
2682,
7,
199,
3,
29349,
1174,
199,
40,
22436,
534,
5642,
7,
199,
199,
3,
18281,
1242,
2943,
199,
10855,
534,
15377,
7,
199,
8936,
13272,
534,
1074,
3887,
7,
199,
10761,
534,
1531,
7,
199,
19662,
2090,
13272,
534,
12841,
2873,
2471,
7,
199,
15828,
534,
9896,
7,
199,
199,
3,
3240,
1486,
12404,
367,
769,
17193,
199,
16425,
534,
4780,
7,
199,
31956,
899,
534,
4570,
7,
199,
21894,
906,
534,
6048,
7,
199,
27059,
534,
10525,
7,
199,
199,
3,
23241,
2487,
367,
769,
17193,
199,
3,
653,
4817,
534,
3592,
7,
365,
2597,
1686,
199,
13203,
15694,
534,
3287,
1977,
7,
199,
6131,
540,
6174,
534,
24396,
7,
199,
199,
3,
21107,
1785,
10218,
15725,
199,
2252,
654,
2507,
37,
534,
1038,
397,
3037,
7,
199,
1244,
3731,
534,
335,
2181,
7,
199,
24028,
534,
9912,
7,
199,
12903,
534,
2246,
7,
199,
16901,
534,
2019,
7,
199,
12728,
52,
534,
7911,
84,
7,
199,
10797,
1206,
534,
1715,
316,
7,
199,
16848,
534,
2363,
7,
199,
6773,
10429,
534,
1235,
1090,
7,
199,
45,
11084,
534,
77,
1661,
7,
199,
199,
3,
7628,
370,
671,
1345,
15,
89,
1345,
199,
24321,
26614,
534,
14469,
16876,
7,
199,
26315,
534,
6755,
7,
199,
27522,
534,
5260,
7,
199,
48,
5383,
534,
5856,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
21478,
9670,
5262,
367,
12435,
199,
199,
3,
699,
1534,
274,
796,
199,
2826,
29,
19823,
29,
7517,
29,
16,
199,
15641,
29,
15064,
29,
615,
29,
17,
199,
199,
3,
446,
11498,
436,
446,
27364,
199,
46,
534,
78,
7,
199,
51,
534,
83,
7,
199,
55,
534,
87,
7,
199,
37,
534,
69,
7,
199,
23471,
534,
13100,
7,
199,
8745,
534,
3519,
7,
199,
6388,
534,
685,
7,
199,
899,
534,
261,
7,
199,
2709,
534,
561,
7,
199,
37,
55,
534,
546,
7,
199,
46,
899,
55,
534,
19315,
87,
7,
199,
17611,
534,
4218,
7,
199,
199,
3,
446,
4498,
199,
9185,
534,
3592,
7,
199,
56,
534,
88,
7,
199,
57,
534,
89,
7,
199,
28784,
534,
10727,
7,
199,
199,
3,
446,
2441,
199,
9894,
534,
3039,
7,
199,
11422,
534,
2119,
7,
199,
12811,
534,
1019,
7,
199,
27838,
534,
8305,
7,
199,
199,
3,
446,
26557,
2829,
199,
2847,
9359,
534,
21597,
7,
199,
23627,
6945,
534,
11846,
917,
7,
199,
3143,
619,
534,
7088,
7,
199,
50,
998,
4962,
534,
5562,
7,
199,
39,
1092,
47,
2524,
534,
23260,
79,
432,
7,
199,
15096,
998,
275,
283,
18533,
7,
199,
199,
3,
446,
19676,
199,
25968,
534,
11392,
7,
199,
22634,
534,
7870,
7,
199,
199,
3,
446,
8741,
199,
28425,
534,
6677,
7,
199,
199,
3,
446,
3823,
199,
5901,
534,
1560,
7,
199,
5172,
534,
1027,
7,
199,
199,
3,
446,
5743,
199,
5825,
6174,
534,
14232,
7,
199,
199,
3,
446,
8665,
632,
199,
10789,
11259,
534,
17183,
7,
199,
1877,
28035,
534,
22431,
7,
199,
199,
3,
12568,
3762,
12,
17370,
436,
5518,
12266,
199,
899,
44,
534,
5891,
7,
199,
899,
44,
63,
12903,
534,
5891,
14,
2246,
7,
199,
899,
44,
63,
16901,
534,
5891,
14,
2019,
7,
199,
3902,
534,
500,
7,
199,
10258,
534,
3176,
7,
199,
14211,
534,
1818,
7,
199,
20139,
726,
534,
11498,
7,
199,
1761,
534,
452,
7,
327,
325,
14,
71,
14,
29349,
14,
1807,
8,
1761,
9,
199,
199,
3,
4516,
3938,
436,
5528,
6363,
199,
10765,
534,
3302,
7,
199,
16205,
534,
7011,
7,
199,
10401,
534,
2682,
7,
199,
3,
29349,
1174,
199,
40,
22436,
534,
5642,
7,
199,
199,
3,
18281,
1242,
2943,
199,
10855,
534,
15377,
7,
199,
8936,
13272,
534,
1074,
3887,
7,
199,
10761,
534,
1531,
7,
199,
19662,
2090,
13272,
534,
12841,
2873,
2471,
7,
199,
15828,
534,
9896,
7,
199,
199,
3,
3240,
1486,
12404,
367,
769,
17193,
199,
16425,
534,
4780,
7,
199,
31956,
899,
534,
4570,
7,
199,
21894,
906,
534,
6048,
7,
199,
27059,
534,
10525,
7,
199,
199,
3,
23241,
2487,
367,
769,
17193,
199,
3,
653,
4817,
534,
3592,
7,
365,
2597,
1686,
199,
13203,
15694,
534,
3287,
1977,
7,
199,
6131,
540,
6174,
534,
24396,
7,
199,
199,
3,
21107,
1785,
10218,
15725,
199,
2252,
654,
2507,
37,
534,
1038,
397,
3037,
7,
199,
1244,
3731,
534,
335,
2181,
7,
199,
24028,
534,
9912,
7,
199,
12903,
534,
2246,
7,
199,
16901,
534,
2019,
7,
199,
12728,
52,
534,
7911,
84,
7,
199,
10797,
1206,
534,
1715,
316,
7,
199,
16848,
534,
2363,
7,
199,
6773,
10429,
534,
1235,
1090,
7,
199,
45,
11084,
534,
77,
1661,
7,
199,
199,
3,
7628,
370,
671,
1345,
15,
89,
1345,
199,
24321,
26614,
534,
14469,
16876,
7,
199,
26315,
534,
6755,
7,
199,
27522,
534,
5260,
7,
199,
48,
5383,
534,
5856,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
tyagiarpit/servo
|
tests/wpt/web-platform-tests/tools/html5lib/html5lib/tests/test_parser.py
|
451
|
3612
|
from __future__ import absolute_import, division, unicode_literals
import os
import sys
import traceback
import warnings
import re
warnings.simplefilter("error")
from .support import get_data_files
from .support import TestData, convert, convertExpected, treeTypes
from html5lib import html5parser, constants
# Run the parse error checks
checkParseErrors = False
# XXX - There should just be one function here but for some reason the testcase
# format differs from the treedump format by a single space character
def convertTreeDump(data):
return "\n".join(convert(3)(data).split("\n")[1:])
namespaceExpected = re.compile(r"^(\s*)<(\S+)>", re.M).sub
def runParserTest(innerHTML, input, expected, errors, treeClass,
namespaceHTMLElements):
with warnings.catch_warnings(record=True) as caughtWarnings:
warnings.simplefilter("always")
p = html5parser.HTMLParser(tree=treeClass,
namespaceHTMLElements=namespaceHTMLElements)
try:
if innerHTML:
document = p.parseFragment(input, innerHTML)
else:
document = p.parse(input)
except:
errorMsg = "\n".join(["\n\nInput:", input, "\nExpected:", expected,
"\nTraceback:", traceback.format_exc()])
assert False, errorMsg
otherWarnings = [x for x in caughtWarnings
if not issubclass(x.category, constants.DataLossWarning)]
assert len(otherWarnings) == 0, [(x.category, x.message) for x in otherWarnings]
if len(caughtWarnings):
return
output = convertTreeDump(p.tree.testSerializer(document))
expected = convertExpected(expected)
if namespaceHTMLElements:
expected = namespaceExpected(r"\1<html \2>", expected)
errorMsg = "\n".join(["\n\nInput:", input, "\nExpected:", expected,
"\nReceived:", output])
assert expected == output, errorMsg
errStr = []
for (line, col), errorcode, datavars in p.errors:
assert isinstance(datavars, dict), "%s, %s" % (errorcode, repr(datavars))
errStr.append("Line: %i Col: %i %s" % (line, col,
constants.E[errorcode] % datavars))
errorMsg2 = "\n".join(["\n\nInput:", input,
"\nExpected errors (" + str(len(errors)) + "):\n" + "\n".join(errors),
"\nActual errors (" + str(len(p.errors)) + "):\n" + "\n".join(errStr)])
if checkParseErrors:
assert len(p.errors) == len(errors), errorMsg2
def test_parser():
sys.stderr.write('Testing tree builders ' + " ".join(list(treeTypes.keys())) + "\n")
files = get_data_files('tree-construction')
for filename in files:
testName = os.path.basename(filename).replace(".dat", "")
if testName in ("template",):
continue
tests = TestData(filename, "data")
for index, test in enumerate(tests):
input, errors, innerHTML, expected = [test[key] for key in
('data', 'errors',
'document-fragment',
'document')]
if errors:
errors = errors.split("\n")
for treeName, treeCls in treeTypes.items():
for namespaceHTMLElements in (True, False):
yield (runParserTest, innerHTML, input, expected, errors, treeCls,
namespaceHTMLElements)
|
mpl-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
984,
199,
646,
5190,
199,
646,
3598,
199,
646,
295,
199,
199,
5451,
14,
18815,
480,
705,
531,
199,
199,
504,
1275,
4058,
492,
664,
63,
576,
63,
1725,
199,
504,
1275,
4058,
492,
1379,
1451,
12,
3957,
12,
3957,
6964,
12,
3123,
4100,
199,
504,
3517,
21,
773,
492,
3517,
21,
2087,
12,
5262,
199,
199,
3,
3378,
314,
2198,
1125,
5920,
199,
1074,
9123,
83,
275,
756,
199,
199,
3,
5787,
446,
6006,
1077,
2951,
506,
1373,
805,
2348,
1325,
367,
2005,
4499,
314,
16228,
199,
3,
1475,
22754,
687,
314,
307,
3798,
1220,
1475,
701,
282,
2849,
4601,
4528,
421,
199,
318,
3957,
3987,
11772,
8,
576,
304,
272,
372,
1867,
78,
1674,
904,
8,
3916,
8,
19,
5130,
576,
680,
1294,
4582,
78,
9981,
17,
5728,
199,
199,
3251,
6964,
275,
295,
14,
2014,
8,
82,
16136,
2961,
83,
13278,
28,
2961,
51,
8771,
7166,
295,
14,
45,
680,
954,
421,
199,
318,
1255,
2842,
774,
8,
26502,
12,
1324,
12,
1420,
12,
2552,
12,
3123,
2543,
12,
2116,
3231,
31428,
20446,
304,
272,
543,
3598,
14,
9341,
63,
5451,
8,
3059,
29,
549,
9,
465,
15604,
15921,
26,
267,
3598,
14,
18815,
480,
9223,
531,
267,
299,
275,
3517,
21,
2087,
14,
27375,
8,
2350,
29,
2350,
2543,
12,
3521,
3231,
31428,
20446,
29,
3251,
31428,
20446,
9,
398,
862,
26,
288,
340,
6506,
4943,
26,
355,
2213,
275,
299,
14,
1122,
11080,
8,
1210,
12,
6506,
4943,
9,
288,
587,
26,
355,
2213,
275,
299,
14,
1122,
8,
1210,
9,
267,
871,
26,
288,
1125,
6173,
275,
1867,
78,
1674,
904,
779,
3212,
78,
60,
78,
3205,
6783,
1324,
12,
1867,
78,
6964,
6783,
1420,
12,
3303,
1867,
78,
15905,
6783,
5190,
14,
908,
63,
2804,
9383,
288,
702,
756,
12,
1125,
6173,
339,
1163,
15921,
275,
359,
88,
367,
671,
315,
15604,
15921,
2151,
340,
440,
11602,
8,
88,
14,
3710,
12,
5262,
14,
1451,
8610,
3849,
1874,
272,
702,
822,
8,
1848,
15921,
9,
508,
378,
12,
3842,
88,
14,
3710,
12,
671,
14,
1188,
9,
367,
671,
315,
1163,
15921,
61,
272,
340,
822,
8,
24872,
15921,
304,
267,
372,
339,
1072,
275,
3957,
3987,
11772,
8,
80,
14,
2350,
14,
396,
7299,
8,
3554,
430,
339,
1420,
275,
3957,
6964,
8,
2062,
9,
272,
340,
3231,
31428,
20446,
26,
267,
1420,
275,
3231,
6964,
8,
82,
3212,
17,
28,
1360,
971,
18,
7166,
1420,
9,
339,
1125,
6173,
275,
1867,
78,
1674,
904,
779,
3212,
78,
60,
78,
3205,
6783,
1324,
12,
1867,
78,
6964,
6783,
1420,
12,
2079,
1867,
78,
9392,
6783,
1072,
566,
272,
702,
1420,
508,
1072,
12,
1125,
6173,
339,
2329,
2848,
275,
942,
272,
367,
334,
604,
12,
1048,
395,
1125,
600,
12,
666,
2936,
315,
299,
14,
2550,
26,
267,
702,
1228,
8,
576,
2936,
12,
1211,
395,
2071,
83,
12,
450,
83,
2,
450,
334,
28857,
12,
4700,
8,
576,
2936,
430,
267,
2329,
2848,
14,
740,
480,
3049,
26,
450,
73,
3626,
26,
450,
73,
450,
83,
2,
450,
334,
604,
12,
1048,
12,
6901,
5262,
14,
37,
59,
28857,
61,
450,
666,
2936,
430,
339,
1125,
6173,
18,
275,
1867,
78,
1674,
904,
779,
3212,
78,
60,
78,
3205,
6783,
1324,
12,
2574,
1867,
78,
6964,
2552,
1689,
435,
620,
8,
552,
8,
2550,
430,
435,
298,
17211,
78,
2,
435,
1867,
78,
1674,
904,
8,
2550,
395,
2574,
1867,
78,
30141,
2552,
1689,
435,
620,
8,
552,
8,
80,
14,
2550,
430,
435,
298,
17211,
78,
2,
435,
1867,
78,
1674,
904,
8,
1508,
2848,
3948,
272,
340,
1104,
9123,
83,
26,
288,
702,
822,
8,
80,
14,
2550,
9,
508,
822,
8,
2550,
395,
1125,
6173,
18,
421,
199,
318,
511,
63,
2087,
837,
272,
984,
14,
3083,
14,
952,
360,
9029,
3123,
27378,
283,
435,
298,
3680,
904,
8,
513,
8,
2350,
4100,
14,
1612,
4059,
435,
1867,
78,
531,
272,
1584,
275,
664,
63,
576,
63,
1725,
360,
2350,
13,
12708,
358,
339,
367,
1788,
315,
1584,
26,
267,
511,
985,
275,
747,
14,
515,
14,
4846,
8,
1501,
680,
1814,
9520,
4616,
401,
6899,
267,
340,
511,
985,
315,
1689,
1160,
401,
304,
288,
1980,
398,
2295,
275,
1379,
1451,
8,
1501,
12,
298,
576,
531,
398,
367,
1478,
12,
511,
315,
3874,
8,
2219,
304,
288,
1324,
12,
2552,
12,
6506,
4943,
12,
1420,
275,
359,
396,
59,
498,
61,
367,
790,
315,
8179,
661,
576,
297,
283,
2550,
297,
8962,
283,
3554,
13,
7677,
297,
8962,
283,
3554,
5440,
288,
340,
2552,
26,
355,
2552,
275,
2552,
14,
1294,
4582,
78,
531,
953,
367,
3123,
985,
12,
3123,
24342,
315,
3123,
4100,
14,
1744,
837,
355,
367,
3231,
31428,
20446,
315,
334,
549,
12,
756,
304,
490,
1995,
334,
1065,
2842,
774,
12,
6506,
4943,
12,
1324,
12,
1420,
12,
2552,
12,
3123,
24342,
12,
2574,
3231,
31428,
20446,
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
] |
[
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
2649,
63,
5955,
199,
199,
646,
747,
199,
646,
984,
199,
646,
5190,
199,
646,
3598,
199,
646,
295,
199,
199,
5451,
14,
18815,
480,
705,
531,
199,
199,
504,
1275,
4058,
492,
664,
63,
576,
63,
1725,
199,
504,
1275,
4058,
492,
1379,
1451,
12,
3957,
12,
3957,
6964,
12,
3123,
4100,
199,
504,
3517,
21,
773,
492,
3517,
21,
2087,
12,
5262,
199,
199,
3,
3378,
314,
2198,
1125,
5920,
199,
1074,
9123,
83,
275,
756,
199,
199,
3,
5787,
446,
6006,
1077,
2951,
506,
1373,
805,
2348,
1325,
367,
2005,
4499,
314,
16228,
199,
3,
1475,
22754,
687,
314,
307,
3798,
1220,
1475,
701,
282,
2849,
4601,
4528,
421,
199,
318,
3957,
3987,
11772,
8,
576,
304,
272,
372,
1867,
78,
1674,
904,
8,
3916,
8,
19,
5130,
576,
680,
1294,
4582,
78,
9981,
17,
5728,
199,
199,
3251,
6964,
275,
295,
14,
2014,
8,
82,
16136,
2961,
83,
13278,
28,
2961,
51,
8771,
7166,
295,
14,
45,
680,
954,
421,
199,
318,
1255,
2842,
774,
8,
26502,
12,
1324,
12,
1420,
12,
2552,
12,
3123,
2543,
12,
2116,
3231,
31428,
20446,
304,
272,
543,
3598,
14,
9341,
63,
5451,
8,
3059,
29,
549,
9,
465,
15604,
15921,
26,
267,
3598,
14,
18815,
480,
9223,
531,
267,
299,
275,
3517,
21,
2087,
14,
27375,
8,
2350,
29,
2350,
2543,
12,
3521,
3231,
31428,
20446,
29,
3251,
31428,
20446,
9,
398,
862,
26,
288,
340,
6506,
4943,
26,
355,
2213,
275,
299,
14,
1122,
11080,
8,
1210,
12,
6506,
4943,
9,
288,
587,
26,
355,
2213,
275,
299,
14,
1122,
8,
1210,
9,
267,
871,
26,
288,
1125,
6173,
275,
1867,
78,
1674,
904,
779,
3212,
78,
60,
78,
3205,
6783,
1324,
12,
1867,
78,
6964,
6783,
1420,
12,
3303,
1867,
78,
15905,
6783,
5190,
14,
908,
63,
2804,
9383,
288,
702,
756,
12,
1125,
6173,
339,
1163,
15921,
275,
359,
88,
367,
671,
315,
15604,
15921,
2151,
340,
440,
11602,
8,
88,
14,
3710,
12,
5262,
14,
1451,
8610,
3849,
1874,
272,
702,
822,
8,
1848,
15921,
9,
508,
378,
12,
3842,
88,
14,
3710,
12,
671,
14,
1188,
9,
367,
671,
315,
1163,
15921,
61,
272,
340,
822,
8,
24872,
15921,
304,
267,
372,
339,
1072,
275,
3957,
3987,
11772,
8,
80,
14,
2350,
14,
396,
7299,
8,
3554,
430,
339,
1420,
275,
3957,
6964,
8,
2062,
9,
272,
340,
3231,
31428,
20446,
26,
267,
1420,
275,
3231,
6964,
8,
82,
3212,
17,
28,
1360,
971,
18,
7166,
1420,
9,
339,
1125,
6173,
275,
1867,
78,
1674,
904,
779,
3212,
78,
60,
78,
3205,
6783,
1324,
12,
1867,
78,
6964,
6783,
1420,
12,
2079,
1867,
78,
9392,
6783,
1072,
566,
272,
702,
1420,
508,
1072,
12,
1125,
6173,
339,
2329,
2848,
275,
942,
272,
367,
334,
604,
12,
1048,
395,
1125,
600,
12,
666,
2936,
315,
299,
14,
2550,
26,
267,
702,
1228,
8,
576,
2936,
12,
1211,
395,
2071,
83,
12,
450,
83,
2,
450,
334,
28857,
12,
4700,
8,
576,
2936,
430,
267,
2329,
2848,
14,
740,
480,
3049,
26,
450,
73,
3626,
26,
450,
73,
450,
83,
2,
450,
334,
604,
12,
1048,
12,
6901,
5262,
14,
37,
59,
28857,
61,
450,
666,
2936,
430,
339,
1125,
6173,
18,
275,
1867,
78,
1674,
904,
779,
3212,
78,
60,
78,
3205,
6783,
1324,
12,
2574,
1867,
78,
6964,
2552,
1689,
435,
620,
8,
552,
8,
2550,
430,
435,
298,
17211,
78,
2,
435,
1867,
78,
1674,
904,
8,
2550,
395,
2574,
1867,
78,
30141,
2552,
1689,
435,
620,
8,
552,
8,
80,
14,
2550,
430,
435,
298,
17211,
78,
2,
435,
1867,
78,
1674,
904,
8,
1508,
2848,
3948,
272,
340,
1104,
9123,
83,
26,
288,
702,
822,
8,
80,
14,
2550,
9,
508,
822,
8,
2550,
395,
1125,
6173,
18,
421,
199,
318,
511,
63,
2087,
837,
272,
984,
14,
3083,
14,
952,
360,
9029,
3123,
27378,
283,
435,
298,
3680,
904,
8,
513,
8,
2350,
4100,
14,
1612,
4059,
435,
1867,
78,
531,
272,
1584,
275,
664,
63,
576,
63,
1725,
360,
2350,
13,
12708,
358,
339,
367,
1788,
315,
1584,
26,
267,
511,
985,
275,
747,
14,
515,
14,
4846,
8,
1501,
680,
1814,
9520,
4616,
401,
6899,
267,
340,
511,
985,
315,
1689,
1160,
401,
304,
288,
1980,
398,
2295,
275,
1379,
1451,
8,
1501,
12,
298,
576,
531,
398,
367,
1478,
12,
511,
315,
3874,
8,
2219,
304,
288,
1324,
12,
2552,
12,
6506,
4943,
12,
1420,
275,
359,
396,
59,
498,
61,
367,
790,
315,
8179,
661,
576,
297,
283,
2550,
297,
8962,
283,
3554,
13,
7677,
297,
8962,
283,
3554,
5440,
288,
340,
2552,
26,
355,
2552,
275,
2552,
14,
1294,
4582,
78,
531,
953,
367,
3123,
985,
12,
3123,
24342,
315,
3123,
4100,
14,
1744,
837,
355,
367,
3231,
31428,
20446,
315,
334,
549,
12,
756,
304,
490,
1995,
334,
1065,
2842,
774,
12,
6506,
4943,
12,
1324,
12,
1420,
12,
2552,
12,
3123,
24342,
12,
2574,
3231,
31428,
20446,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
walterst/qiime
|
scripts/multiple_rarefactions.py
|
15
|
5671
|
#!/usr/bin/env python
# File created on 09 Feb 2010
from __future__ import division
__author__ = "Justin Kuczynski"
__copyright__ = "Copyright 2011, The QIIME Project"
__credits__ = ["Justin Kuczynski", "Greg Caporaso", "Jai Ram Rideout"]
__license__ = "GPL"
__version__ = "1.9.1-dev"
__maintainer__ = "Justin Kuczynski"
__email__ = "justinak@gmail.com"
import os.path
from functools import partial
from skbio.stats import subsample
from qiime.util import parse_command_line_parameters, create_dir
from qiime.util import make_option
from qiime.rarefaction import RarefactionMaker
script_info = {}
script_info[
'brief_description'] = """Perform multiple subsamplings/rarefactions on an otu table"""
script_info[
'script_description'] = """To perform bootstrap, jackknife, and rarefaction analyses, the otu table must be subsampled (rarefied). This script rarefies, or subsamples, OTU tables. This does not provide curves of diversity by number of sequences in a sample. Rather it creates a series of subsampled OTU tables by random sampling (without replacement) of the input OTU table. Samples that have fewer sequences then the requested rarefaction depth for a given output otu table are omitted from those ouput otu tables. The pseudo-random number generator used for rarefaction by subsampling is NumPy's default - an implementation of the Mersenne twister PRNG."""
script_info['script_usage'] = []
script_info['script_usage'].append(
("""Generate rarefied OTU tables:""",
"""Generate rarefied OTU tables beginning with 10 (-m) sequences/sample through 140 (-x) sequences per sample in steps of of 10 (-s), performing 2 iterations at each sampling depth (-n). All resulting OTU tables will be written to 'rarefied_otu_tables' (-o). Any sample containing fewer sequences in the input file than the requested number of sequences per sample is removed from the output rarefied otu table.""",
"""%prog -i otu_table.biom -m 10 -x 140 -s 10 -n 2 -o rarefied_otu_tables/"""))
script_info[
'output_description'] = """The result of multiple_rarefactions.py consists of a number of biom files, which depend on the minimum/maximum number of sequences per samples, steps and iterations. The files have the same otu table format as the input otu_table.biom, and are named in the following way: rarefaction_100_0.biom, where "100" corresponds to the sequences per sample and "0" the iteration."""
script_info['required_options'] = [
make_option('-i', '--input_path',
help='Input OTU table filepath.',
type='existing_filepath'),
make_option('-o', '--output_path',
help="Output directory.",
type='new_dirpath'),
make_option('-m', '--min', type='int',
help='Minimum number of seqs/sample for rarefaction.'),
make_option('-x', '--max', type='int',
help='Maximum number of seqs/sample (inclusive) for rarefaction. '),
make_option('-s', '--step', type='int',
help='Size of each steps between the min/max of' +
' seqs/sample (e.g. min, min+step... for level <= max).')
]
script_info['optional_options'] = [
# This option is screwed up: dest should equal the long form parameter name,
# but I'm not sure if we can do anything about it since '-' is not allowed
# in variable names... Hmmm... Changing the long-form parameter name
# would cause older parameter files not to work.
make_option('-n', '--num_reps', dest='num_reps', default=10, type='int',
help='The number of iterations at each step. [default: %default]'),
make_option('--lineages_included', default=False,
action="store_true",
help='Retain taxonomic (lineage) information for each OTU. Note:' +
' this will only work if lineage information is in the input OTU' +
' table. [default: %default]'),
make_option('-k', '--keep_empty_otus', default=False, action='store_true',
help='Retain OTUs of all zeros, which are usually omitted from' +
' the output OTU tables. [default: %default]'),
make_option('--subsample_multinomial', default=False, action='store_true',
help='subsample using subsampling with replacement [default: %default]')
]
script_info['option_label'] = {'input_path': 'OTU table filepath',
'output_path': 'Output directory',
'min': 'Min # of seqs/sample',
'max': 'Max # of seqs/sample',
'step': 'Step size',
'num_reps': '# of iterations',
'lineages_included': 'Include lineages',
'keep_empty_otus': 'Retain empty OTUs'}
script_info['version'] = __version__
def main():
option_parser, opts, args = parse_command_line_parameters(**script_info)
if opts.step <= 0:
option_parser.error("step must be greater than 0")
create_dir(opts.output_path, fail_on_exist=False)
maker = RarefactionMaker(opts.input_path, opts.min, opts.max,
opts.step, opts.num_reps)
if opts.subsample_multinomial:
subsample_f = partial(subsample, replace=True)
else:
subsample_f = subsample
maker.rarefy_to_files(opts.output_path,
False,
include_lineages=opts.lineages_included,
empty_otus_removed=(not opts.keep_empty_otus),
subsample_f=subsample_f)
if __name__ == "__main__":
main()
|
gpl-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
3814,
2737,
641,
21798,
21141,
7129,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
363,
2502,
363,
275,
298,
22850,
262,
1804,
947,
3605,
561,
8810,
2,
199,
363,
7307,
363,
275,
298,
7384,
7760,
12,
710,
1413,
41,
3465,
7290,
2,
199,
363,
22461,
363,
275,
2097,
22850,
262,
1804,
947,
3605,
561,
8810,
401,
298,
39,
1135,
22516,
269,
305,
79,
401,
298,
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,
22850,
262,
1804,
947,
3605,
561,
8810,
2,
199,
363,
2123,
363,
275,
298,
4764,
262,
1151,
32,
6799,
14,
957,
2,
199,
199,
646,
747,
14,
515,
199,
504,
9143,
492,
7417,
199,
199,
504,
11448,
2308,
14,
3200,
492,
1007,
3271,
199,
199,
504,
31402,
1036,
14,
1974,
492,
2198,
63,
1531,
63,
604,
63,
3214,
12,
1218,
63,
694,
199,
504,
31402,
1036,
14,
1974,
492,
1852,
63,
1422,
199,
504,
31402,
1036,
14,
345,
264,
17287,
492,
820,
1530,
17287,
23560,
199,
199,
1579,
63,
815,
275,
1052,
199,
1579,
63,
815,
59,
272,
283,
19127,
63,
1802,
418,
275,
408,
20906,
3663,
1007,
2231,
2421,
780,
15,
345,
264,
667,
2452,
641,
376,
312,
10963,
1817,
624,
199,
1579,
63,
815,
59,
272,
283,
1579,
63,
1802,
418,
275,
408,
1378,
5147,
15865,
12,
1335,
564,
18974,
16839,
12,
436,
24063,
17287,
5909,
874,
12,
314,
312,
10963,
1817,
1471,
506,
1007,
25042,
334,
345,
264,
1290,
680,
221,
961,
2884,
24063,
5604,
12,
503,
1007,
3356,
12,
593,
21364,
6716,
14,
221,
961,
1630,
440,
5647,
1094,
2310,
402,
487,
422,
3677,
701,
1329,
402,
8013,
315,
282,
2690,
14,
221,
3898,
728,
652,
8491,
282,
6779,
402,
1007,
25042,
593,
21364,
6716,
701,
2196,
15877,
334,
7395,
8343,
9,
402,
314,
1324,
593,
21364,
1817,
14,
221,
428,
1889,
626,
1172,
27392,
8013,
2066,
314,
5839,
24063,
17287,
5818,
367,
282,
1627,
1072,
312,
10963,
1817,
787,
11684,
687,
5204,
312,
384,
337,
312,
10963,
6716,
14,
221,
710,
15984,
13,
2355,
1329,
4306,
1202,
367,
24063,
17287,
701,
1007,
17376,
365,
20602,
1159,
849,
446,
376,
4514,
402,
314,
18880,
2464,
685,
8900,
1429,
12218,
12259,
1041,
199,
1579,
63,
815,
459,
1579,
63,
3807,
418,
275,
942,
199,
199,
1579,
63,
815,
459,
1579,
63,
3807,
2278,
740,
8,
272,
334,
624,
6864,
24063,
1290,
593,
21364,
6716,
26,
7208,
1362,
408,
6864,
24063,
1290,
593,
21364,
6716,
9608,
543,
1616,
5868,
77,
9,
8013,
15,
3271,
4012,
22796,
5868,
88,
9,
8013,
1126,
2690,
315,
7124,
402,
402,
1616,
5868,
83,
395,
19203,
499,
10615,
737,
1924,
15877,
5818,
5868,
78,
680,
2900,
9183,
593,
21364,
6716,
911,
506,
5313,
370,
283,
345,
264,
1290,
63,
357,
85,
63,
5987,
7,
5868,
79,
680,
6184,
2690,
3035,
27392,
8013,
315,
314,
1324,
570,
2419,
314,
5839,
1329,
402,
8013,
1126,
2690,
365,
4829,
687,
314,
1072,
24063,
1290,
312,
10963,
1817,
17129,
1362,
408,
5,
6595,
446,
73,
312,
10963,
63,
1224,
14,
4492,
676,
446,
77,
1616,
446,
88,
22796,
446,
83,
1616,
446,
78,
499,
446,
79,
24063,
1290,
63,
357,
85,
63,
5987,
15,
624,
430,
199,
199,
1579,
63,
815,
59,
272,
283,
1199,
63,
1802,
418,
275,
408,
1918,
754,
402,
3663,
63,
345,
264,
667,
2452,
14,
647,
18581,
402,
282,
1329,
402,
12111,
676,
1584,
12,
1314,
11687,
641,
314,
7481,
15,
11555,
1329,
402,
8013,
1126,
5845,
12,
7124,
436,
10615,
14,
710,
1584,
1172,
314,
2011,
312,
10963,
1817,
1475,
465,
314,
1324,
312,
10963,
63,
1224,
14,
4492,
676,
12,
436,
787,
4310,
315,
314,
2569,
4340,
26,
24063,
17287,
63,
1960,
63,
16,
14,
4492,
676,
12,
2382,
298,
1960,
2,
13718,
370,
314,
8013,
1126,
2690,
436,
298,
16,
2,
314,
8494,
1041,
199,
199,
1579,
63,
815,
459,
2427,
63,
1419,
418,
275,
359,
272,
1852,
63,
1422,
3654,
73,
297,
2850,
1210,
63,
515,
297,
355,
1720,
534,
3205,
593,
21364,
1817,
9911,
3130,
355,
730,
534,
5952,
63,
7218,
659,
272,
1852,
63,
1422,
3654,
79,
297,
2850,
1199,
63,
515,
297,
355,
1720,
628,
2959,
2082,
4765,
355,
730,
534,
1222,
63,
17254,
659,
272,
1852,
63,
1422,
3654,
77,
297,
2850,
827,
297,
730,
534,
442,
297,
355,
1720,
534,
12092,
1329,
402,
5412,
83,
15,
3271,
367,
24063,
17287,
8038,
272,
1852,
63,
1422,
3654,
88,
297,
2850,
988,
297,
730,
534,
442,
297,
355,
1720,
534,
10915,
1329,
402,
5412,
83,
15,
3271,
334,
26062,
9,
367,
24063,
17287,
14,
17748,
272,
1852,
63,
1422,
3654,
83,
297,
2850,
2926,
297,
730,
534,
442,
297,
355,
1720,
534,
2320,
402,
1924,
7124,
3382,
314,
1748,
15,
988,
402,
7,
435,
355,
283,
5412,
83,
15,
3271,
334,
69,
14,
71,
14,
1748,
12,
1748,
11,
2926,
1396,
367,
2166,
2695,
1390,
28583,
199,
61,
199,
1579,
63,
815,
459,
4144,
63,
1419,
418,
275,
359,
272,
327,
961,
945,
365,
308,
1353,
24084,
1536,
26,
2053,
1077,
4472,
314,
1846,
1824,
2725,
536,
12,
272,
327,
1325,
473,
6704,
440,
3238,
340,
781,
883,
886,
7003,
3595,
652,
3967,
10791,
365,
440,
4370,
272,
327,
315,
1750,
1561,
1396,
869,
596,
77,
1396,
27854,
314,
1846,
13,
964,
2725,
536,
272,
327,
3955,
7675,
12731,
2725,
1584,
440,
370,
1736,
14,
272,
1852,
63,
1422,
3654,
78,
297,
2850,
1507,
63,
1155,
83,
297,
2053,
534,
1507,
63,
1155,
83,
297,
849,
29,
709,
12,
730,
534,
442,
297,
355,
1720,
534,
1918,
1329,
402,
10615,
737,
1924,
3650,
14,
359,
885,
26,
450,
885,
26987,
272,
1852,
63,
1422,
4517,
604,
7441,
63,
12409,
297,
849,
29,
797,
12,
355,
1595,
628,
1617,
63,
2052,
401,
355,
1720,
534,
6816,
1581,
9067,
15222,
530,
334,
604,
474,
9,
2556,
367,
1924,
593,
21364,
14,
3390,
4881,
435,
355,
283,
642,
911,
1454,
1736,
340,
1004,
474,
2556,
365,
315,
314,
1324,
593,
21364
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
3814,
2737,
641,
21798,
21141,
7129,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
363,
2502,
363,
275,
298,
22850,
262,
1804,
947,
3605,
561,
8810,
2,
199,
363,
7307,
363,
275,
298,
7384,
7760,
12,
710,
1413,
41,
3465,
7290,
2,
199,
363,
22461,
363,
275,
2097,
22850,
262,
1804,
947,
3605,
561,
8810,
401,
298,
39,
1135,
22516,
269,
305,
79,
401,
298,
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,
22850,
262,
1804,
947,
3605,
561,
8810,
2,
199,
363,
2123,
363,
275,
298,
4764,
262,
1151,
32,
6799,
14,
957,
2,
199,
199,
646,
747,
14,
515,
199,
504,
9143,
492,
7417,
199,
199,
504,
11448,
2308,
14,
3200,
492,
1007,
3271,
199,
199,
504,
31402,
1036,
14,
1974,
492,
2198,
63,
1531,
63,
604,
63,
3214,
12,
1218,
63,
694,
199,
504,
31402,
1036,
14,
1974,
492,
1852,
63,
1422,
199,
504,
31402,
1036,
14,
345,
264,
17287,
492,
820,
1530,
17287,
23560,
199,
199,
1579,
63,
815,
275,
1052,
199,
1579,
63,
815,
59,
272,
283,
19127,
63,
1802,
418,
275,
408,
20906,
3663,
1007,
2231,
2421,
780,
15,
345,
264,
667,
2452,
641,
376,
312,
10963,
1817,
624,
199,
1579,
63,
815,
59,
272,
283,
1579,
63,
1802,
418,
275,
408,
1378,
5147,
15865,
12,
1335,
564,
18974,
16839,
12,
436,
24063,
17287,
5909,
874,
12,
314,
312,
10963,
1817,
1471,
506,
1007,
25042,
334,
345,
264,
1290,
680,
221,
961,
2884,
24063,
5604,
12,
503,
1007,
3356,
12,
593,
21364,
6716,
14,
221,
961,
1630,
440,
5647,
1094,
2310,
402,
487,
422,
3677,
701,
1329,
402,
8013,
315,
282,
2690,
14,
221,
3898,
728,
652,
8491,
282,
6779,
402,
1007,
25042,
593,
21364,
6716,
701,
2196,
15877,
334,
7395,
8343,
9,
402,
314,
1324,
593,
21364,
1817,
14,
221,
428,
1889,
626,
1172,
27392,
8013,
2066,
314,
5839,
24063,
17287,
5818,
367,
282,
1627,
1072,
312,
10963,
1817,
787,
11684,
687,
5204,
312,
384,
337,
312,
10963,
6716,
14,
221,
710,
15984,
13,
2355,
1329,
4306,
1202,
367,
24063,
17287,
701,
1007,
17376,
365,
20602,
1159,
849,
446,
376,
4514,
402,
314,
18880,
2464,
685,
8900,
1429,
12218,
12259,
1041,
199,
1579,
63,
815,
459,
1579,
63,
3807,
418,
275,
942,
199,
199,
1579,
63,
815,
459,
1579,
63,
3807,
2278,
740,
8,
272,
334,
624,
6864,
24063,
1290,
593,
21364,
6716,
26,
7208,
1362,
408,
6864,
24063,
1290,
593,
21364,
6716,
9608,
543,
1616,
5868,
77,
9,
8013,
15,
3271,
4012,
22796,
5868,
88,
9,
8013,
1126,
2690,
315,
7124,
402,
402,
1616,
5868,
83,
395,
19203,
499,
10615,
737,
1924,
15877,
5818,
5868,
78,
680,
2900,
9183,
593,
21364,
6716,
911,
506,
5313,
370,
283,
345,
264,
1290,
63,
357,
85,
63,
5987,
7,
5868,
79,
680,
6184,
2690,
3035,
27392,
8013,
315,
314,
1324,
570,
2419,
314,
5839,
1329,
402,
8013,
1126,
2690,
365,
4829,
687,
314,
1072,
24063,
1290,
312,
10963,
1817,
17129,
1362,
408,
5,
6595,
446,
73,
312,
10963,
63,
1224,
14,
4492,
676,
446,
77,
1616,
446,
88,
22796,
446,
83,
1616,
446,
78,
499,
446,
79,
24063,
1290,
63,
357,
85,
63,
5987,
15,
624,
430,
199,
199,
1579,
63,
815,
59,
272,
283,
1199,
63,
1802,
418,
275,
408,
1918,
754,
402,
3663,
63,
345,
264,
667,
2452,
14,
647,
18581,
402,
282,
1329,
402,
12111,
676,
1584,
12,
1314,
11687,
641,
314,
7481,
15,
11555,
1329,
402,
8013,
1126,
5845,
12,
7124,
436,
10615,
14,
710,
1584,
1172,
314,
2011,
312,
10963,
1817,
1475,
465,
314,
1324,
312,
10963,
63,
1224,
14,
4492,
676,
12,
436,
787,
4310,
315,
314,
2569,
4340,
26,
24063,
17287,
63,
1960,
63,
16,
14,
4492,
676,
12,
2382,
298,
1960,
2,
13718,
370,
314,
8013,
1126,
2690,
436,
298,
16,
2,
314,
8494,
1041,
199,
199,
1579,
63,
815,
459,
2427,
63,
1419,
418,
275,
359,
272,
1852,
63,
1422,
3654,
73,
297,
2850,
1210,
63,
515,
297,
355,
1720,
534,
3205,
593,
21364,
1817,
9911,
3130,
355,
730,
534,
5952,
63,
7218,
659,
272,
1852,
63,
1422,
3654,
79,
297,
2850,
1199,
63,
515,
297,
355,
1720,
628,
2959,
2082,
4765,
355,
730,
534,
1222,
63,
17254,
659,
272,
1852,
63,
1422,
3654,
77,
297,
2850,
827,
297,
730,
534,
442,
297,
355,
1720,
534,
12092,
1329,
402,
5412,
83,
15,
3271,
367,
24063,
17287,
8038,
272,
1852,
63,
1422,
3654,
88,
297,
2850,
988,
297,
730,
534,
442,
297,
355,
1720,
534,
10915,
1329,
402,
5412,
83,
15,
3271,
334,
26062,
9,
367,
24063,
17287,
14,
17748,
272,
1852,
63,
1422,
3654,
83,
297,
2850,
2926,
297,
730,
534,
442,
297,
355,
1720,
534,
2320,
402,
1924,
7124,
3382,
314,
1748,
15,
988,
402,
7,
435,
355,
283,
5412,
83,
15,
3271,
334,
69,
14,
71,
14,
1748,
12,
1748,
11,
2926,
1396,
367,
2166,
2695,
1390,
28583,
199,
61,
199,
1579,
63,
815,
459,
4144,
63,
1419,
418,
275,
359,
272,
327,
961,
945,
365,
308,
1353,
24084,
1536,
26,
2053,
1077,
4472,
314,
1846,
1824,
2725,
536,
12,
272,
327,
1325,
473,
6704,
440,
3238,
340,
781,
883,
886,
7003,
3595,
652,
3967,
10791,
365,
440,
4370,
272,
327,
315,
1750,
1561,
1396,
869,
596,
77,
1396,
27854,
314,
1846,
13,
964,
2725,
536,
272,
327,
3955,
7675,
12731,
2725,
1584,
440,
370,
1736,
14,
272,
1852,
63,
1422,
3654,
78,
297,
2850,
1507,
63,
1155,
83,
297,
2053,
534,
1507,
63,
1155,
83,
297,
849,
29,
709,
12,
730,
534,
442,
297,
355,
1720,
534,
1918,
1329,
402,
10615,
737,
1924,
3650,
14,
359,
885,
26,
450,
885,
26987,
272,
1852,
63,
1422,
4517,
604,
7441,
63,
12409,
297,
849,
29,
797,
12,
355,
1595,
628,
1617,
63,
2052,
401,
355,
1720,
534,
6816,
1581,
9067,
15222,
530,
334,
604,
474,
9,
2556,
367,
1924,
593,
21364,
14,
3390,
4881,
435,
355,
283,
642,
911,
1454,
1736,
340,
1004,
474,
2556,
365,
315,
314,
1324,
593,
21364,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nchammas/asyncssh
|
examples/local_forwarding_server.py
|
2
|
1619
|
#!/usr/bin/env python3.4
#
# Copyright (c) 2013-2015 by Ron Frederick <ronf@timeheart.net>.
# All rights reserved.
#
# This program and the accompanying materials are made available under
# the terms of the Eclipse Public License v1.0 which accompanies this
# distribution and is available at:
#
# http://www.eclipse.org/legal/epl-v10.html
#
# Contributors:
# Ron Frederick - initial implementation, API, and documentation
# To run this program, the file ``ssh_host_key`` must exist with an SSH
# private key in it to use as a server host key. An SSH host certificate
# can optionally be provided in the file ``ssh_host_key-cert.pub``.
#
# The file ``ssh_user_ca`` must exist with a cert-authority entry of
# the certificate authority which can sign valid client certificates.
import asyncio, asyncssh, sys
class MySSHServer(asyncssh.SSHServer):
def connection_requested(self, dest_host, dest_port, orig_host, orig_port):
if dest_port == 80:
return True
else:
raise asyncssh.ChannelOpenError(
asyncssh.OPEN_ADMINISTRATIVELY_PROHIBITED,
'Only connections to port 80 are allowed')
@asyncio.coroutine
def start_server():
yield from asyncssh.create_server(MySSHServer, '', 8022,
server_host_keys=['ssh_host_key'],
authorized_client_keys='ssh_user_ca')
loop = asyncio.get_event_loop()
try:
loop.run_until_complete(start_server())
except (OSError, asyncssh.Error) as exc:
sys.exit('SSH server failed: ' + str(exc))
loop.run_forever()
|
epl-1.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
19,
14,
20,
199,
3,
199,
3,
1898,
334,
67,
9,
6171,
13,
7806,
701,
32472,
481,
264,
9910,
346,
665,
2641,
70,
32,
521,
426,
580,
14,
846,
10827,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2240,
436,
314,
23073,
8418,
787,
6326,
2808,
1334,
199,
3,
314,
2895,
402,
314,
662,
7548,
261,
1684,
844,
373,
17,
14,
16,
1314,
1066,
863,
23461,
642,
199,
3,
4084,
436,
365,
2808,
737,
26,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
825,
3587,
261,
14,
1308,
15,
9666,
15,
69,
1168,
13,
86,
709,
14,
1360,
199,
3,
199,
3,
23212,
26,
199,
3,
258,
32472,
481,
264,
9910,
346,
446,
2536,
4514,
12,
3261,
12,
436,
3794,
199,
199,
3,
4005,
1255,
642,
2240,
12,
314,
570,
1124,
5510,
63,
1102,
63,
498,
1040,
1471,
2187,
543,
376,
12027,
199,
3,
5726,
790,
315,
652,
370,
675,
465,
282,
1654,
1591,
790,
14,
1626,
12027,
1591,
5897,
199,
3,
883,
14190,
506,
2741,
315,
314,
570,
1124,
5510,
63,
1102,
63,
498,
13,
4736,
14,
5645,
4345,
199,
3,
199,
3,
710,
570,
1124,
5510,
63,
751,
63,
696,
1040,
1471,
2187,
543,
282,
6250,
13,
23635,
2397,
402,
199,
3,
314,
5897,
18330,
1314,
883,
2070,
1686,
1890,
14512,
14,
199,
199,
646,
16195,
12,
5316,
5510,
12,
984,
199,
199,
533,
4932,
13716,
3120,
8,
4146,
5510,
14,
13716,
3120,
304,
272,
347,
1950,
63,
11151,
8,
277,
12,
2053,
63,
1102,
12,
2053,
63,
719,
12,
2306,
63,
1102,
12,
2306,
63,
719,
304,
267,
340,
2053,
63,
719,
508,
5939,
26,
288,
372,
715,
267,
587,
26,
288,
746,
5316,
5510,
14,
5358,
4299,
547,
8,
1993,
5316,
5510,
14,
9935,
63,
14288,
21340,
14277,
6084,
63,
2514,
40,
2100,
649,
1149,
12,
1993,
283,
5903,
6947,
370,
1844,
5939,
787,
4370,
358,
199,
199,
32,
19343,
14,
16675,
199,
318,
1343,
63,
1000,
837,
272,
1995,
687,
5316,
5510,
14,
981,
63,
1000,
8,
5713,
13716,
3120,
12,
3260,
1695,
16348,
12,
4228,
1654,
63,
1102,
63,
1612,
2968,
5510,
63,
1102,
63,
498,
995,
4228,
18788,
63,
1258,
63,
1612,
534,
5510,
63,
751,
63,
696,
358,
199,
199,
3813,
275,
16195,
14,
362,
63,
1430,
63,
3813,
342,
199,
199,
893,
26,
272,
4438,
14,
1065,
63,
8111,
63,
4883,
8,
928,
63,
1000,
1012,
199,
2590,
334,
16719,
12,
5316,
5510,
14,
547,
9,
465,
3178,
26,
272,
984,
14,
2224,
360,
13716,
1654,
3405,
26,
283,
435,
620,
8,
2804,
430,
199,
199,
3813,
14,
1065,
63,
21327,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
19,
14,
20,
199,
3,
199,
3,
1898,
334,
67,
9,
6171,
13,
7806,
701,
32472,
481,
264,
9910,
346,
665,
2641,
70,
32,
521,
426,
580,
14,
846,
10827,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
961,
2240,
436,
314,
23073,
8418,
787,
6326,
2808,
1334,
199,
3,
314,
2895,
402,
314,
662,
7548,
261,
1684,
844,
373,
17,
14,
16,
1314,
1066,
863,
23461,
642,
199,
3,
4084,
436,
365,
2808,
737,
26,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
825,
3587,
261,
14,
1308,
15,
9666,
15,
69,
1168,
13,
86,
709,
14,
1360,
199,
3,
199,
3,
23212,
26,
199,
3,
258,
32472,
481,
264,
9910,
346,
446,
2536,
4514,
12,
3261,
12,
436,
3794,
199,
199,
3,
4005,
1255,
642,
2240,
12,
314,
570,
1124,
5510,
63,
1102,
63,
498,
1040,
1471,
2187,
543,
376,
12027,
199,
3,
5726,
790,
315,
652,
370,
675,
465,
282,
1654,
1591,
790,
14,
1626,
12027,
1591,
5897,
199,
3,
883,
14190,
506,
2741,
315,
314,
570,
1124,
5510,
63,
1102,
63,
498,
13,
4736,
14,
5645,
4345,
199,
3,
199,
3,
710,
570,
1124,
5510,
63,
751,
63,
696,
1040,
1471,
2187,
543,
282,
6250,
13,
23635,
2397,
402,
199,
3,
314,
5897,
18330,
1314,
883,
2070,
1686,
1890,
14512,
14,
199,
199,
646,
16195,
12,
5316,
5510,
12,
984,
199,
199,
533,
4932,
13716,
3120,
8,
4146,
5510,
14,
13716,
3120,
304,
272,
347,
1950,
63,
11151,
8,
277,
12,
2053,
63,
1102,
12,
2053,
63,
719,
12,
2306,
63,
1102,
12,
2306,
63,
719,
304,
267,
340,
2053,
63,
719,
508,
5939,
26,
288,
372,
715,
267,
587,
26,
288,
746,
5316,
5510,
14,
5358,
4299,
547,
8,
1993,
5316,
5510,
14,
9935,
63,
14288,
21340,
14277,
6084,
63,
2514,
40,
2100,
649,
1149,
12,
1993,
283,
5903,
6947,
370,
1844,
5939,
787,
4370,
358,
199,
199,
32,
19343,
14,
16675,
199,
318,
1343,
63,
1000,
837,
272,
1995,
687,
5316,
5510,
14,
981,
63,
1000,
8,
5713,
13716,
3120,
12,
3260,
1695,
16348,
12,
4228,
1654,
63,
1102,
63,
1612,
2968,
5510,
63,
1102,
63,
498,
995,
4228,
18788,
63,
1258,
63,
1612,
534,
5510,
63,
751,
63,
696,
358,
199,
199,
3813,
275,
16195,
14,
362,
63,
1430,
63,
3813,
342,
199,
199,
893,
26,
272,
4438,
14,
1065,
63,
8111,
63,
4883,
8,
928,
63,
1000,
1012,
199,
2590,
334,
16719,
12,
5316,
5510,
14,
547,
9,
465,
3178,
26,
272,
984,
14,
2224,
360,
13716,
1654,
3405,
26,
283,
435,
620,
8,
2804,
430,
199,
199,
3813,
14,
1065,
63,
21327,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
stevepeak/tornwrap
|
tornwrap/ratelimited.py
|
1
|
2242
|
import functools
def ratelimited(user=None, guest=None, redis_key_format="ratelimited.%s"):
"""Rate limit decorator
### Headers
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 567
X-RateLimit-Reset: 1242711173
### Status when rate limited
Status: 403 Forbidden
"""
if user:
assert type(user[0]) is int and user[0] > 0, "user[0] must be int and > 0"
assert type(user[1]) is int and user[1] > 0, "user[1] must be int and > 0"
else:
user = (None, None)
if guest:
assert type(guest[0]) is int and guest[0] > 0, "guest[0] must be int and > 0"
assert type(guest[1]) is int and guest[1] > 0, "guest[1] must be int and > 0"
else:
guest = (None, None)
def wrapper(method):
@functools.wraps(method)
def limit(self, *args, **kwargs):
tokens, refresh = user if self.current_user else guest
if tokens is None:
return method(self, *args, **kwargs)
# --------------
# Get IP Address
# --------------
# http://www.tornadoweb.org/en/stable/httputil.html?highlight=remote_ip#tornado.httputil.HTTPServerRequest.remote_ip
redis_key = redis_key_format % self.request.remote_ip
# ----------------
# Check Rate Limit
# ----------------
r = self.redis
current = r.get(redis_key)
if current is None:
r.setex(redis_key, tokens-1, refresh)
remaining, ttl = tokens-1, refresh
else:
remaining, ttl = int(r.decr(redis_key) or 0), int(r.ttl(redis_key) or 0)
# set headers
self.set_header("X-RateLimit-Limit", tokens)
self.set_header("X-RateLimit-Remaining", (0 if remaining < 0 else remaining))
self.set_header("X-RateLimit-Reset", ttl)
if remaining < 0:
do_continue = self.was_rate_limited(tokens, (0 if remaining < 0 else remaining), ttl)
if do_continue is not True:
return
# Continue with method
return method(self, *args, **kwargs)
return limit
return wrapper
|
apache-2.0
|
[
646,
9143,
421,
199,
318,
6634,
14136,
8,
751,
29,
403,
12,
13980,
29,
403,
12,
16967,
63,
498,
63,
908,
628,
1866,
14136,
4111,
83,
2349,
272,
408,
6621,
2304,
7531,
339,
6754,
21391,
272,
1323,
13,
6621,
8407,
13,
8407,
26,
5198,
272,
1323,
13,
6621,
8407,
13,
31109,
26,
959,
1822,
272,
1323,
13,
6621,
8407,
13,
9637,
26,
25442,
1465,
845,
12478,
339,
6754,
9795,
1380,
6634,
13988,
272,
9795,
26,
13269,
2104,
10912,
339,
408,
272,
340,
922,
26,
267,
702,
730,
8,
751,
59,
16,
566,
365,
1109,
436,
922,
59,
16,
61,
690,
378,
12,
298,
751,
59,
16,
61,
1471,
506,
1109,
436,
690,
378,
2,
267,
702,
730,
8,
751,
59,
17,
566,
365,
1109,
436,
922,
59,
17,
61,
690,
378,
12,
298,
751,
59,
17,
61,
1471,
506,
1109,
436,
690,
378,
2,
272,
587,
26,
267,
922,
275,
334,
403,
12,
488,
9,
339,
340,
13980,
26,
267,
702,
730,
8,
10409,
59,
16,
566,
365,
1109,
436,
13980,
59,
16,
61,
690,
378,
12,
298,
10409,
59,
16,
61,
1471,
506,
1109,
436,
690,
378,
2,
267,
702,
730,
8,
10409,
59,
17,
566,
365,
1109,
436,
13980,
59,
17,
61,
690,
378,
12,
298,
10409,
59,
17,
61,
1471,
506,
1109,
436,
690,
378,
2,
272,
587,
26,
267,
13980,
275,
334,
403,
12,
488,
9,
339,
347,
4975,
8,
765,
304,
267,
768,
17869,
14,
13582,
8,
765,
9,
267,
347,
2304,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
4645,
12,
9236,
275,
922,
340,
291,
14,
1818,
63,
751,
587,
13980,
288,
340,
4645,
365,
488,
26,
355,
372,
1083,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
953,
327,
3001,
8648,
288,
327,
2372,
3531,
9906,
288,
327,
3001,
8648,
288,
327,
1455,
921,
1544,
14,
84,
6161,
8369,
2871,
14,
1308,
15,
287,
15,
11989,
15,
1014,
1974,
14,
1360,
31,
14337,
29,
3846,
63,
711,
3,
18443,
14,
1014,
1974,
14,
14938,
2017,
14,
3846,
63,
711,
288,
16967,
63,
498,
275,
16967,
63,
498,
63,
908,
450,
291,
14,
1069,
14,
3846,
63,
711,
953,
327,
10652,
288,
327,
2670,
26311,
22672,
288,
327,
10652,
288,
519,
275,
291,
14,
15369,
288,
1453,
275,
519,
14,
362,
8,
15369,
63,
498,
9,
288,
340,
1453,
365,
488,
26,
355,
519,
14,
261,
3858,
8,
15369,
63,
498,
12,
4645,
13,
17,
12,
9236,
9,
355,
7971,
12,
14856,
275,
4645,
13,
17,
12,
9236,
288,
587,
26,
355,
7971,
12,
14856,
275,
1109,
8,
82,
14,
271,
1556,
8,
15369,
63,
498,
9,
503,
378,
395,
1109,
8,
82,
14,
12130,
8,
15369,
63,
498,
9,
503,
378,
9,
953,
327,
663,
2323,
288,
291,
14,
409,
63,
1291,
480,
56,
13,
6621,
8407,
13,
8407,
401,
4645,
9,
288,
291,
14,
409,
63,
1291,
480,
56,
13,
6621,
8407,
13,
31109,
401,
334,
16,
340,
7971,
665,
378,
587,
7971,
430,
288,
291,
14,
409,
63,
1291,
480,
56,
13,
6621,
8407,
13,
9637,
401,
14856,
9,
953,
340,
7971,
665,
378,
26,
355,
886,
63,
6958,
275,
291,
14,
10274,
63,
1866,
63,
14136,
8,
4504,
12,
334,
16,
340,
7971,
665,
378,
587,
7971,
395,
14856,
9,
355,
340,
886,
63,
6958,
365,
440,
715,
26,
490,
372,
953,
327,
1448,
1781,
543,
1083,
288,
372,
1083,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
398,
372,
2304,
339,
372,
4975,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
9143,
421,
199,
318,
6634,
14136,
8,
751,
29,
403,
12,
13980,
29,
403,
12,
16967,
63,
498,
63,
908,
628,
1866,
14136,
4111,
83,
2349,
272,
408,
6621,
2304,
7531,
339,
6754,
21391,
272,
1323,
13,
6621,
8407,
13,
8407,
26,
5198,
272,
1323,
13,
6621,
8407,
13,
31109,
26,
959,
1822,
272,
1323,
13,
6621,
8407,
13,
9637,
26,
25442,
1465,
845,
12478,
339,
6754,
9795,
1380,
6634,
13988,
272,
9795,
26,
13269,
2104,
10912,
339,
408,
272,
340,
922,
26,
267,
702,
730,
8,
751,
59,
16,
566,
365,
1109,
436,
922,
59,
16,
61,
690,
378,
12,
298,
751,
59,
16,
61,
1471,
506,
1109,
436,
690,
378,
2,
267,
702,
730,
8,
751,
59,
17,
566,
365,
1109,
436,
922,
59,
17,
61,
690,
378,
12,
298,
751,
59,
17,
61,
1471,
506,
1109,
436,
690,
378,
2,
272,
587,
26,
267,
922,
275,
334,
403,
12,
488,
9,
339,
340,
13980,
26,
267,
702,
730,
8,
10409,
59,
16,
566,
365,
1109,
436,
13980,
59,
16,
61,
690,
378,
12,
298,
10409,
59,
16,
61,
1471,
506,
1109,
436,
690,
378,
2,
267,
702,
730,
8,
10409,
59,
17,
566,
365,
1109,
436,
13980,
59,
17,
61,
690,
378,
12,
298,
10409,
59,
17,
61,
1471,
506,
1109,
436,
690,
378,
2,
272,
587,
26,
267,
13980,
275,
334,
403,
12,
488,
9,
339,
347,
4975,
8,
765,
304,
267,
768,
17869,
14,
13582,
8,
765,
9,
267,
347,
2304,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
288,
4645,
12,
9236,
275,
922,
340,
291,
14,
1818,
63,
751,
587,
13980,
288,
340,
4645,
365,
488,
26,
355,
372,
1083,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
953,
327,
3001,
8648,
288,
327,
2372,
3531,
9906,
288,
327,
3001,
8648,
288,
327,
1455,
921,
1544,
14,
84,
6161,
8369,
2871,
14,
1308,
15,
287,
15,
11989,
15,
1014,
1974,
14,
1360,
31,
14337,
29,
3846,
63,
711,
3,
18443,
14,
1014,
1974,
14,
14938,
2017,
14,
3846,
63,
711,
288,
16967,
63,
498,
275,
16967,
63,
498,
63,
908,
450,
291,
14,
1069,
14,
3846,
63,
711,
953,
327,
10652,
288,
327,
2670,
26311,
22672,
288,
327,
10652,
288,
519,
275,
291,
14,
15369,
288,
1453,
275,
519,
14,
362,
8,
15369,
63,
498,
9,
288,
340,
1453,
365,
488,
26,
355,
519,
14,
261,
3858,
8,
15369,
63,
498,
12,
4645,
13,
17,
12,
9236,
9,
355,
7971,
12,
14856,
275,
4645,
13,
17,
12,
9236,
288,
587,
26,
355,
7971,
12,
14856,
275,
1109,
8,
82,
14,
271,
1556,
8,
15369,
63,
498,
9,
503,
378,
395,
1109,
8,
82,
14,
12130,
8,
15369,
63,
498,
9,
503,
378,
9,
953,
327,
663,
2323,
288,
291,
14,
409,
63,
1291,
480,
56,
13,
6621,
8407,
13,
8407,
401,
4645,
9,
288,
291,
14,
409,
63,
1291,
480,
56,
13,
6621,
8407,
13,
31109,
401,
334,
16,
340,
7971,
665,
378,
587,
7971,
430,
288,
291,
14,
409,
63,
1291,
480,
56,
13,
6621,
8407,
13,
9637,
401,
14856,
9,
953,
340,
7971,
665,
378,
26,
355,
886,
63,
6958,
275,
291,
14,
10274,
63,
1866,
63,
14136,
8,
4504,
12,
334,
16,
340,
7971,
665,
378,
587,
7971,
395,
14856,
9,
355,
340,
886,
63,
6958,
365,
440,
715,
26,
490,
372,
953,
327,
1448,
1781,
543,
1083,
288,
372,
1083,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
398,
372,
2304,
339,
372,
4975,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
foligny/browsershots-psycopg2
|
shotserver/shotserver04/accounts/views.py
|
1
|
15999
|
# browsershots.org - Test your web design in different browsers
# Copyright (C) 2007 Johann C. Rocholl <johann@browsershots.org>
#
# Browsershots 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.
#
# Browsershots 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/>.
"""
Account views.
"""
__revision__ = "$Rev: 2971 $"
__date__ = "$Date: 2008-08-14 07:21:38 -0400 (Thu, 14 Aug 2008) $"
__author__ = "$Author: johann $"
import time
from datetime import datetime, timedelta
from psycopg2 import IntegrityError
import smtplib
from django.contrib import auth
from django.contrib.auth.decorators import login_required
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django import forms
from django.forms.util import ErrorList
from django.db import transaction, connection
from django.http import HttpResponseRedirect
from django.template import RequestContext
from django.shortcuts import render_to_response, get_object_or_404
from django.core.mail import send_mail
from django.utils.translation import ugettext_lazy as _
from django.utils.text import capfirst
from django.conf import settings
from shotserver04.factories.models import Factory
from shotserver04.messages.models import FactoryError
from shotserver04.common.object_cache import preload_foreign_keys
from shotserver04.common import error_page, success_page
from shotserver04.nonces import crypto
from shotserver04.nonces.models import Nonce
USERNAME_CHAR_FIRST = 'abcdefghijklmnopqrstuvwxyz'
USERNAME_CHAR = USERNAME_CHAR_FIRST + '0123456789_-'
PASSWORD_MIN_LENGTH = 6
def logout_required(func):
"""
The opposite of the login_required decorator.
"""
def wrapper(http_request, *args, **kwargs):
"""
Display an error page if the user is already signed in.
"""
if http_request.user.is_authenticated():
return error_page(http_request, _("You're already signed in"),
_("Please log out and then try again."))
return func(http_request, *args, **kwargs)
return wrapper
class LoginForm(forms.Form):
"""
Simple login form.
"""
username = forms.CharField(max_length=30, label=_("Username"))
password = forms.CharField(max_length=40, label=_("Password"),
widget=forms.PasswordInput(render_value=False))
@logout_required
def login(http_request):
"""
Show login form and then log in, if correct password was submitted.
"""
next = http_request.REQUEST.get('next', '')
if not next or '//' in next or ' ' in next:
next = settings.LOGIN_REDIRECT_URL
form = LoginForm(http_request.POST or None)
form_errors = []
user = None
if form.is_valid():
if not http_request.session.test_cookie_worked():
form_errors.append(_("Please enable cookies in your browser."))
else:
user = auth.authenticate(
username=form.cleaned_data['username'],
password=form.cleaned_data['password'])
if user is None:
form_errors.append(_("Incorrect username or password."))
elif not user.is_active:
form_errors.append(_("This account is inactive."))
if form_errors or not user:
form_title = _("Welcome to Browsershots!")
form_submit = _("let me in")
form_hidden = '<input type="hidden" name="next" value="%s" />' % next
form_extra = u"""
<ul>
<li><a href="../email/">%s</a></li>
<li><a href="../email/">%s</a></li>
</ul>
""".strip() % (_("Forgot your password?"),
_("Create a new account?"))
form_javascript = "document.getElementById('id_username').focus()"
http_request.session.set_test_cookie()
return render_to_response('form.html', locals(),
context_instance=RequestContext(http_request))
auth.login(http_request, user)
http_request.session.delete_test_cookie()
return HttpResponseRedirect(next)
def logout(http_request):
"""
De-authenticate the current user.
"""
auth.logout(http_request)
result_title = _("logged out")
result_class = 'success'
result_message = _("You have successfully logged out.")
return render_to_response('result.html', locals(),
context_instance=RequestContext(http_request))
def totals(where=None):
"""
Count monthly screenshots.
"""
sql = [
"SELECT",
"date_part('year', date) AS year,",
"date_part('month', date) AS month,",
"sum(screenshots)",
"FROM factories_screenshotcount",
]
if where:
sql.append(where)
sql.append("GROUP BY year, month")
cursor = connection.cursor()
cursor.execute('\n'.join(sql))
result = {}
for year, month, screenshots in cursor.fetchall():
result[(int(year), int(month))] = screenshots
return result
def user_month_totals(user):
"""
Get monthly statistics about uploaded screenshots and revenue.
"""
factories = user.factory_set.all()
if not factories.count():
return
all_factories = totals()
my_factories = totals("WHERE factory_id IN (%s)" % ','.join(
[str(factory.id) for factory in factories]))
keys = all_factories.keys()
keys.sort()
for year, month in keys:
all = all_factories.get((year, month), 0)
my = my_factories.get((year, month), 0)
revenue = 0
if 'shotserver04.revenue' in settings.INSTALLED_APPS:
from shotserver04.revenue import month_revenue
revenue = month_revenue(year, month)
yield ('%04d-%02d' % (year, month), all, my,
'%.3f%%' % (100.0 * my / all),
'%.2f' % (revenue * my / all))
@login_required
def profile(http_request):
"""
Show a user's private profile page.
"""
month_totals = list(user_month_totals(http_request.user))
factory_table_header = Factory.table_header()
factory_list = Factory.objects.select_related().filter(
admin=http_request.user)
if 'shotserver04.priority' in settings.INSTALLED_APPS:
priorities = http_request.user.userpriority_set.order_by('-expire')
if len(priorities):
user_has_priority_until = priorities[0].expire
if user_has_priority_until < datetime.now():
user_has_priority_until = False
return render_to_response('accounts/profile.html', locals(),
context_instance=RequestContext(http_request))
class EmailForm(forms.Form):
"""
Email input for address verification.
"""
email = forms.EmailField()
def email_message(domain, hashkey, user):
"""
Email template for verification message.
"""
if user:
salutation = unicode(_("Hi %(first_name)s!"))
salutation %= {'first_name': capfirst(user.first_name)}
what = "set a new password"
else:
salutation = unicode(_("Welcome to Browsershots!"))
what = "finish the registration process"
parts = [
salutation,
"""If you have not requested this verification email, you may ignore it.""",
"""Click the following link (or copy it into your browser's address bar)
to verify your email address and %s:""" % what,
"""http://%(domain)s/accounts/verify/%(hashkey)s/""" % locals(),
]
if user:
parts.append("Your username is %s." % user.username)
parts.append("Cheers,\nBrowsershots\n")
return u'\n\n'.join(parts)
@logout_required
def email(http_request):
"""
Ask user for email address, then send verification message.
"""
ip = http_request.META['REMOTE_ADDR']
nonces_per_day = Nonce.objects.filter(ip=ip, email__isnull=False,
created__gt=datetime.now() - timedelta(hours=24)).count()
if nonces_per_day >= 3:
return error_page(http_request, _("too many verification emails"),
_("There were too many email requests from your IP in the last 24 hours."),
_("Please try again later."))
form = EmailForm(http_request.POST or None)
if not form.is_valid():
form_title = _("email verification")
form_action = '/accounts/email/'
form_submit = _("send email")
form_javascript = "document.getElementById('id_email').focus()"
return render_to_response('form.html', locals(),
context_instance=RequestContext(http_request))
address = form.cleaned_data['email']
user = None
users = User.objects.filter(email=address)
if len(users):
user = users[0]
hashkey = crypto.random_md5()
Nonce.objects.create(email=address, hashkey=hashkey, ip=ip)
domain = Site.objects.get_current().domain
message = email_message(domain, hashkey, user)
try:
send_mail("Browsershots email verification", message,
settings.DEFAULT_FROM_EMAIL, [address],
fail_silently=False)
except smtplib.SMTPException, e:
return error_page(http_request, _("email error"),
_("Could not send email."), str(e))
hide_hashkey(hashkey)
return success_page(http_request, _("email sent"),
_("A verification email was sent to %(address)s.") % locals(),
_("Check your email inbox and follow the instructions in the message."),
_("If your email provider uses graylisting, it may take a few minutes."))
def hide_hashkey(hashkey):
"""
Remove hashkey from debug output.
"""
from django.db import connection
for index, query in enumerate(connection.queries):
if hashkey in query['sql']:
query['sql'] = query['sql'].replace(hashkey, '[hidden]')
class UserForm(forms.Form):
"""
Username and realname.
"""
username = forms.CharField(
max_length=User._meta.get_field('username').max_length,
label=capfirst(_("username")))
first_name = forms.CharField(
max_length=User._meta.get_field('first_name').max_length,
label=capfirst(_("first name")))
last_name = forms.CharField(
max_length=User._meta.get_field('last_name').max_length,
label=capfirst(_("last name")))
def clean_username(self):
"""
Check that the username is sensible.
"""
username = self.cleaned_data['username']
if username[0] not in USERNAME_CHAR_FIRST:
raise forms.ValidationError(unicode(
_("Username must start with a lowercase letter.")))
for index in range(len(username)):
if username[index] not in USERNAME_CHAR:
raise forms.ValidationError(unicode(
_("Username may contain only lowercase letters, digits, underscore, hyphen.")))
if username in 'admin administrator root webmaster'.split():
raise forms.ValidationError(unicode(
_("This username is reserved.")))
return username
class PasswordForm(forms.Form):
"""
Password and again.
"""
password = forms.CharField(max_length=40,
label=capfirst(_("password")),
widget=forms.PasswordInput(render_value=False))
again = forms.CharField(max_length=40,
label=capfirst(_("again")),
widget=forms.PasswordInput(render_value=False))
def clean_password(self):
"""
Check that the password is long enough and not too silly.
"""
password = self.cleaned_data['password']
if len(password) < PASSWORD_MIN_LENGTH:
raise forms.ValidationError(unicode(
_("The password must have %d or more characters.")) %
PASSWORD_MIN_LENGTH)
if password.isdigit():
raise forms.ValidationError(unicode(
_("The password must not be completely numeric.")))
return password
def clean_again(self):
"""
Check that the password and again is the same.
"""
if 'password' not in self.cleaned_data:
return
password = self.cleaned_data['password']
again = self.cleaned_data['again']
if again != password:
raise forms.ValidationError(unicode(
_("Repeat password is not the same.")))
return again
class RegistrationForm(UserForm, PasswordForm):
"""
User registration form, mixed from user and password form.
"""
def create_user(self, address):
"""
Try to create the user in the database.
Return None if the username is already taken.
"""
try:
return User.objects.create_user(self.cleaned_data['username'],
address, self.cleaned_data['password'])
except IntegrityError, e:
transaction.rollback()
if 'duplicate' in str(e).lower():
self.errors['username'] = ErrorList([
_("This username is already taken.")])
else:
self.errors[forms.NON_FIELD_ERRORS] = ErrorList([str(e)])
@logout_required
def verify(http_request, hashkey):
"""
Register a new user or set a new password,
after successful email verification.
"""
nonce = get_object_or_404(Nonce, hashkey=hashkey)
ip = http_request.META['REMOTE_ADDR']
if nonce.ip != ip:
return error_page(http_request, _("Wrong IP address"),
_("The verification email was requested from a different IP address."))
if not nonce.email:
return error_page(http_request, _("Bad verification code"),
_("The verification code has no email address."))
if nonce.created < datetime.now() - timedelta(hours=24):
return error_page(http_request, _("Verification code expired"),
_("The verification email was requested more than 24 hours ago."))
users = User.objects.filter(email=nonce.email)
if len(users):
return change_password(http_request, nonce, users[0])
else:
return register(http_request, nonce)
def change_password(http_request, nonce, user):
"""
Change password after email verification.
"""
form = PasswordForm(http_request.POST or None)
if not form.is_valid():
form_title = _("choose a new password")
form_action = '/accounts/verify/%s/' % nonce.hashkey
form_submit = _("change password")
form_javascript = "document.getElementById('id_password').focus()"
return render_to_response('form.html', locals(),
context_instance=RequestContext(http_request))
user.set_password(form.cleaned_data['password'])
user.save()
nonce.delete()
return success_page(http_request, _("Password changed"),
_("Your new password has been saved."),
_("Click the link in the top right corner to log in."))
def register(http_request, nonce):
"""
Register a new user after email verification.
"""
form = RegistrationForm(http_request.POST or None)
user = None
if form.is_valid():
user = form.create_user(nonce.email)
if user is None:
form_title = _("create a new account")
form_action = '/accounts/verify/%s/' % nonce.hashkey
form_submit = _("create account")
form_javascript = "document.getElementById('id_username').focus()"
return render_to_response('form.html', locals(),
context_instance=RequestContext(http_request))
user.first_name = form.cleaned_data['first_name']
user.last_name = form.cleaned_data['last_name']
user.save()
nonce.delete()
return success_page(http_request, _("Account created"),
_("A new user account was created."),
_("Click the link in the top right corner to log in."))
|
gpl-3.0
|
[
3,
7042,
2782,
83,
14,
1308,
446,
1379,
2195,
3330,
12899,
315,
3365,
23776,
199,
3,
1898,
334,
35,
9,
10219,
7135,
72,
1189,
445,
14,
6848,
335,
14385,
665,
31073,
1189,
32,
5750,
2782,
83,
14,
1308,
30,
199,
3,
199,
3,
27620,
2782,
83,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
27620,
2782,
83,
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,
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,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
6009,
6858,
14,
199,
624,
199,
199,
363,
5792,
363,
275,
7880,
26176,
26,
499,
27622,
2672,
2,
199,
363,
602,
363,
275,
7880,
2506,
26,
9079,
13,
2036,
13,
1079,
24937,
26,
2025,
26,
1703,
446,
27130,
334,
2719,
85,
12,
4329,
25298,
9079,
9,
2672,
2,
199,
363,
2502,
363,
275,
7880,
5949,
26,
5225,
72,
1189,
2672,
2,
199,
199,
646,
900,
199,
504,
2197,
492,
2197,
12,
6871,
199,
504,
15492,
18,
492,
26864,
199,
646,
30475,
199,
504,
1639,
14,
2828,
492,
1790,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
3351,
14,
1974,
492,
4520,
1296,
199,
504,
1639,
14,
697,
492,
6008,
12,
1950,
199,
504,
1639,
14,
1014,
492,
14935,
199,
504,
1639,
14,
1160,
492,
22538,
199,
504,
1639,
14,
17469,
492,
3795,
63,
475,
63,
1310,
12,
664,
63,
785,
63,
269,
63,
5188,
199,
504,
1639,
14,
1018,
14,
1198,
492,
3222,
63,
1198,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1208,
14,
505,
492,
4021,
2246,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1033,
357,
1000,
966,
14,
15406,
14,
992,
492,
23616,
199,
504,
1033,
357,
1000,
966,
14,
3431,
14,
992,
492,
23616,
547,
199,
504,
1033,
357,
1000,
966,
14,
2330,
14,
785,
63,
1637,
492,
32511,
63,
6846,
63,
1612,
199,
504,
1033,
357,
1000,
966,
14,
2330,
492,
1125,
63,
1606,
12,
3182,
63,
1606,
199,
504,
1033,
357,
1000,
966,
14,
2865,
823,
492,
13230,
199,
504,
1033,
357,
1000,
966,
14,
2865,
823,
14,
992,
492,
653,
5089,
421,
199,
11958,
63,
5901,
63,
12903,
275,
283,
23459,
7,
199,
11958,
63,
5901,
275,
13044,
2339,
63,
5901,
63,
12903,
435,
283,
11371,
63,
15668,
199,
9032,
63,
4896,
63,
9127,
275,
1227,
421,
199,
318,
22079,
63,
2427,
8,
1532,
304,
272,
408,
272,
710,
26912,
402,
314,
4676,
63,
2427,
7531,
14,
272,
408,
339,
347,
4975,
8,
1014,
63,
1069,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
12175,
376,
1125,
2034,
340,
314,
922,
365,
2575,
10514,
315,
14,
267,
408,
267,
340,
1455,
63,
1069,
14,
751,
14,
374,
63,
12177,
837,
288,
372,
1125,
63,
1606,
8,
1014,
63,
1069,
12,
3824,
5556,
3984,
2575,
10514,
315,
1288,
355,
3824,
8254,
943,
734,
436,
2066,
862,
4020,
13853,
267,
372,
2562,
8,
1014,
63,
1069,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
4975,
421,
199,
533,
16430,
2821,
8,
3351,
14,
2821,
304,
272,
408,
272,
5870,
4676,
1824,
14,
272,
408,
272,
3434,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
1216,
12,
1768,
9384,
13355,
2237,
272,
2505,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
2167,
12,
1768,
9384,
6139,
1288,
267,
3938,
29,
3351,
14,
31804,
8,
3352,
63,
585,
29,
797,
430,
421,
199,
32,
11646,
63,
2427,
199,
318,
4676,
8,
1014,
63,
1069,
304,
272,
408,
272,
12968,
4676,
1824,
436,
2066,
943,
315,
12,
340,
3211,
2505,
1990,
16930,
14,
272,
408,
272,
2163,
275,
1455,
63,
1069,
14,
6780,
14,
362,
360,
2184,
297,
4074,
272,
340,
440,
2163,
503,
18290,
7,
315,
2163,
503,
283,
283,
315,
2163,
26,
267,
2163,
275,
2202,
14,
17208,
63,
19747,
63,
2632,
272,
1824,
275,
16430,
2821,
8,
1014,
63,
1069,
14,
4030,
503,
488,
9,
272,
1824,
63,
2550,
275,
942,
272,
922,
275,
488,
272,
340,
1824,
14,
374,
63,
1078,
837,
267,
340,
440,
1455,
63,
1069,
14,
1730,
14,
396,
63,
5306,
63,
800,
379,
837,
288,
1824,
63,
2550,
14,
740,
6115,
8254,
4756,
10049,
315,
2195,
7042,
13853,
267,
587,
26,
288,
922,
275,
1790,
14,
13975,
8,
355,
3434,
29,
964,
14,
8275,
63,
576,
459,
2473,
995,
355,
2505,
29,
964,
14,
8275,
63,
576,
459,
2060,
1105,
288,
340,
922,
365,
488,
26,
355,
1824,
63,
2550,
14,
740,
6115,
18298,
3434,
503,
2505,
13853,
288,
916,
440,
922,
14,
374,
63,
2682,
26,
355,
1824,
63,
2550,
14,
740,
6115,
2765,
2933,
365,
21325,
13853,
272,
340,
1824,
63,
2550,
503,
440,
922,
26,
267,
1824,
63,
1213,
275,
3824,
24679,
370,
27620,
2782,
83,
9124,
267,
1824,
63,
7275,
275,
3824,
2723,
562,
315,
531,
267,
1824,
63,
5642,
275,
2650,
1210,
730,
628,
5642,
2,
536,
628,
2184,
2,
574,
5961,
83,
2,
22294,
450,
2163,
267,
1824,
63,
2911,
275,
399,
624,
199,
28,
348,
30,
199,
28,
317,
2535,
65,
4369,
628,
5093,
2123,
15,
14423,
83,
1108,
65,
2957,
317,
30,
199,
28,
317,
2535,
65,
4369,
628,
5093,
2123,
15,
14423,
83,
1108,
65,
2957,
317,
30,
199,
1108,
348,
30,
199,
23045,
1913,
342,
450,
26542,
38
] |
[
7042,
2782,
83,
14,
1308,
446,
1379,
2195,
3330,
12899,
315,
3365,
23776,
199,
3,
1898,
334,
35,
9,
10219,
7135,
72,
1189,
445,
14,
6848,
335,
14385,
665,
31073,
1189,
32,
5750,
2782,
83,
14,
1308,
30,
199,
3,
199,
3,
27620,
2782,
83,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
27620,
2782,
83,
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,
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,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
6009,
6858,
14,
199,
624,
199,
199,
363,
5792,
363,
275,
7880,
26176,
26,
499,
27622,
2672,
2,
199,
363,
602,
363,
275,
7880,
2506,
26,
9079,
13,
2036,
13,
1079,
24937,
26,
2025,
26,
1703,
446,
27130,
334,
2719,
85,
12,
4329,
25298,
9079,
9,
2672,
2,
199,
363,
2502,
363,
275,
7880,
5949,
26,
5225,
72,
1189,
2672,
2,
199,
199,
646,
900,
199,
504,
2197,
492,
2197,
12,
6871,
199,
504,
15492,
18,
492,
26864,
199,
646,
30475,
199,
504,
1639,
14,
2828,
492,
1790,
199,
504,
1639,
14,
2828,
14,
1178,
14,
11582,
492,
4676,
63,
2427,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
2828,
14,
8619,
14,
992,
492,
11666,
199,
504,
1639,
492,
4513,
199,
504,
1639,
14,
3351,
14,
1974,
492,
4520,
1296,
199,
504,
1639,
14,
697,
492,
6008,
12,
1950,
199,
504,
1639,
14,
1014,
492,
14935,
199,
504,
1639,
14,
1160,
492,
22538,
199,
504,
1639,
14,
17469,
492,
3795,
63,
475,
63,
1310,
12,
664,
63,
785,
63,
269,
63,
5188,
199,
504,
1639,
14,
1018,
14,
1198,
492,
3222,
63,
1198,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
504,
1639,
14,
1208,
14,
505,
492,
4021,
2246,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1033,
357,
1000,
966,
14,
15406,
14,
992,
492,
23616,
199,
504,
1033,
357,
1000,
966,
14,
3431,
14,
992,
492,
23616,
547,
199,
504,
1033,
357,
1000,
966,
14,
2330,
14,
785,
63,
1637,
492,
32511,
63,
6846,
63,
1612,
199,
504,
1033,
357,
1000,
966,
14,
2330,
492,
1125,
63,
1606,
12,
3182,
63,
1606,
199,
504,
1033,
357,
1000,
966,
14,
2865,
823,
492,
13230,
199,
504,
1033,
357,
1000,
966,
14,
2865,
823,
14,
992,
492,
653,
5089,
421,
199,
11958,
63,
5901,
63,
12903,
275,
283,
23459,
7,
199,
11958,
63,
5901,
275,
13044,
2339,
63,
5901,
63,
12903,
435,
283,
11371,
63,
15668,
199,
9032,
63,
4896,
63,
9127,
275,
1227,
421,
199,
318,
22079,
63,
2427,
8,
1532,
304,
272,
408,
272,
710,
26912,
402,
314,
4676,
63,
2427,
7531,
14,
272,
408,
339,
347,
4975,
8,
1014,
63,
1069,
12,
627,
589,
12,
1011,
958,
304,
267,
408,
267,
12175,
376,
1125,
2034,
340,
314,
922,
365,
2575,
10514,
315,
14,
267,
408,
267,
340,
1455,
63,
1069,
14,
751,
14,
374,
63,
12177,
837,
288,
372,
1125,
63,
1606,
8,
1014,
63,
1069,
12,
3824,
5556,
3984,
2575,
10514,
315,
1288,
355,
3824,
8254,
943,
734,
436,
2066,
862,
4020,
13853,
267,
372,
2562,
8,
1014,
63,
1069,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
4975,
421,
199,
533,
16430,
2821,
8,
3351,
14,
2821,
304,
272,
408,
272,
5870,
4676,
1824,
14,
272,
408,
272,
3434,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
1216,
12,
1768,
9384,
13355,
2237,
272,
2505,
275,
4513,
14,
2183,
8,
988,
63,
1267,
29,
2167,
12,
1768,
9384,
6139,
1288,
267,
3938,
29,
3351,
14,
31804,
8,
3352,
63,
585,
29,
797,
430,
421,
199,
32,
11646,
63,
2427,
199,
318,
4676,
8,
1014,
63,
1069,
304,
272,
408,
272,
12968,
4676,
1824,
436,
2066,
943,
315,
12,
340,
3211,
2505,
1990,
16930,
14,
272,
408,
272,
2163,
275,
1455,
63,
1069,
14,
6780,
14,
362,
360,
2184,
297,
4074,
272,
340,
440,
2163,
503,
18290,
7,
315,
2163,
503,
283,
283,
315,
2163,
26,
267,
2163,
275,
2202,
14,
17208,
63,
19747,
63,
2632,
272,
1824,
275,
16430,
2821,
8,
1014,
63,
1069,
14,
4030,
503,
488,
9,
272,
1824,
63,
2550,
275,
942,
272,
922,
275,
488,
272,
340,
1824,
14,
374,
63,
1078,
837,
267,
340,
440,
1455,
63,
1069,
14,
1730,
14,
396,
63,
5306,
63,
800,
379,
837,
288,
1824,
63,
2550,
14,
740,
6115,
8254,
4756,
10049,
315,
2195,
7042,
13853,
267,
587,
26,
288,
922,
275,
1790,
14,
13975,
8,
355,
3434,
29,
964,
14,
8275,
63,
576,
459,
2473,
995,
355,
2505,
29,
964,
14,
8275,
63,
576,
459,
2060,
1105,
288,
340,
922,
365,
488,
26,
355,
1824,
63,
2550,
14,
740,
6115,
18298,
3434,
503,
2505,
13853,
288,
916,
440,
922,
14,
374,
63,
2682,
26,
355,
1824,
63,
2550,
14,
740,
6115,
2765,
2933,
365,
21325,
13853,
272,
340,
1824,
63,
2550,
503,
440,
922,
26,
267,
1824,
63,
1213,
275,
3824,
24679,
370,
27620,
2782,
83,
9124,
267,
1824,
63,
7275,
275,
3824,
2723,
562,
315,
531,
267,
1824,
63,
5642,
275,
2650,
1210,
730,
628,
5642,
2,
536,
628,
2184,
2,
574,
5961,
83,
2,
22294,
450,
2163,
267,
1824,
63,
2911,
275,
399,
624,
199,
28,
348,
30,
199,
28,
317,
2535,
65,
4369,
628,
5093,
2123,
15,
14423,
83,
1108,
65,
2957,
317,
30,
199,
28,
317,
2535,
65,
4369,
628,
5093,
2123,
15,
14423,
83,
1108,
65,
2957,
317,
30,
199,
1108,
348,
30,
199,
23045,
1913,
342,
450,
26542,
38,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Teamxrtc/webrtc-streaming-node
|
third_party/webrtc/src/chromium/src/tools/grit/grit/format/resource_map.py
|
27
|
4029
|
#!/usr/bin/env python
# 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.
'''This file contains item formatters for resource_map_header and
resource_map_source files. A resource map is a mapping between resource names
(string) and the internal resource ID.'''
import os
from functools import partial
from grit import util
def GetFormatter(type):
if type == 'resource_map_header':
return _FormatHeader
elif type == 'resource_map_source':
return partial(_FormatSource, _GetItemName)
elif type == 'resource_file_map_source':
return partial(_FormatSource, _GetItemPath)
def GetMapName(root):
'''Get the name of the resource map based on the header file name. E.g.,
if our header filename is theme_resources.h, we name our resource map
kThemeResourcesMap.
|root| is the grd file root.'''
outputs = root.GetOutputFiles()
rc_header_file = None
for output in outputs:
if 'rc_header' == output.GetType():
rc_header_file = output.GetFilename()
if not rc_header_file:
raise Exception('unable to find resource header filename')
filename = os.path.splitext(os.path.split(rc_header_file)[1])[0]
filename = filename[0].upper() + filename[1:]
while filename.find('_') != -1:
pos = filename.find('_')
if pos >= len(filename):
break
filename = filename[:pos] + filename[pos + 1].upper() + filename[pos + 2:]
return 'k' + filename
def _FormatHeader(root, lang='en', output_dir='.'):
'''Create the header file for the resource mapping. This file just declares
an array of name/value pairs.'''
return '''\
// This file is automatically generated by GRIT. Do not edit.
#include <stddef.h>
#ifndef GRIT_RESOURCE_MAP_STRUCT_
#define GRIT_RESOURCE_MAP_STRUCT_
struct GritResourceMap {
const char* const name;
int value;
};
#endif // GRIT_RESOURCE_MAP_STRUCT_
extern const GritResourceMap %(map_name)s[];
extern const size_t %(map_name)sSize;
''' % { 'map_name': GetMapName(root) }
def _FormatSourceHeader(root):
'''Create the header of the C++ source file for the resource mapping.'''
rc_header_file = None
map_header_file = None
for output in root.GetOutputFiles():
if 'rc_header' == output.GetType():
rc_header_file = output.GetFilename()
elif 'resource_map_header' == output.GetType():
map_header_file = output.GetFilename()
if not rc_header_file or not map_header_file:
raise Exception('resource_map_source output type requires '
'resource_map_header and rc_header outputs')
return '''\
// This file is automatically generated by GRIT. Do not edit.
#include "%(map_header_file)s"
#include "base/basictypes.h"
#include "%(rc_header_file)s"
const GritResourceMap %(map_name)s[] = {
''' % { 'map_header_file': map_header_file,
'rc_header_file': rc_header_file,
'map_name': GetMapName(root),
}
def _FormatSourceFooter(root):
# Return the footer text.
return '''\
};
const size_t %(map_name)sSize = arraysize(%(map_name)s);
''' % { 'map_name': GetMapName(root) }
def _FormatSource(get_key, root, lang, output_dir):
from grit.format import rc_header
from grit.node import include, structure, message
yield _FormatSourceHeader(root)
tids = rc_header.GetIds(root)
seen = set()
active_descendants = [item for item in root.ActiveDescendants()]
output_all_resource_defines = root.ShouldOutputAllResourceDefines()
for item in root:
if not item.IsResourceMapSource():
continue
key = get_key(item)
tid = item.attrs['name']
if tid not in tids or key in seen:
continue
seen.add(key)
if item.GeneratesResourceMapEntry(output_all_resource_defines,
item in active_descendants):
yield ' {"%s", %s},\n' % (key, tid)
yield _FormatSourceFooter(root)
def _GetItemName(item):
return item.attrs['name']
def _GetItemPath(item):
return item.GetInputPath().replace("\\", "/")
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
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,
2344,
2765,
570,
3509,
1242,
30514,
367,
2073,
63,
1130,
63,
1291,
436,
199,
1927,
63,
1130,
63,
1365,
1584,
14,
221,
437,
2073,
2341,
365,
282,
4412,
3382,
2073,
1561,
199,
8,
875,
9,
436,
314,
5007,
2073,
2870,
10595,
199,
199,
646,
747,
199,
504,
9143,
492,
7417,
199,
199,
504,
486,
11133,
492,
4884,
421,
199,
318,
2372,
7772,
8,
466,
304,
523,
340,
730,
508,
283,
1927,
63,
1130,
63,
1291,
356,
272,
372,
485,
3484,
2567,
523,
916,
730,
508,
283,
1927,
63,
1130,
63,
1365,
356,
272,
372,
7417,
1547,
3484,
2980,
12,
485,
32474,
985,
9,
523,
916,
730,
508,
283,
1927,
63,
493,
63,
1130,
63,
1365,
356,
272,
372,
7417,
1547,
3484,
2980,
12,
485,
32474,
2042,
9,
421,
199,
318,
2372,
2956,
985,
8,
1231,
304,
523,
1449,
1002,
314,
536,
402,
314,
2073,
2341,
4079,
641,
314,
1406,
570,
536,
14,
221,
662,
14,
71,
2020,
523,
340,
4154,
1406,
1788,
365,
8879,
63,
4435,
14,
72,
12,
781,
536,
4154,
2073,
2341,
523,
1022,
16849,
13745,
2956,
14,
819,
1204,
1231,
92,
365,
314,
486,
6883,
570,
1738,
10595,
523,
4704,
275,
1738,
14,
18614,
5535,
342,
523,
4819,
63,
1291,
63,
493,
275,
488,
523,
367,
1072,
315,
4704,
26,
272,
340,
283,
1195,
63,
1291,
7,
508,
1072,
14,
24770,
837,
489,
4819,
63,
1291,
63,
493,
275,
1072,
14,
1002,
8117,
342,
523,
340,
440,
4819,
63,
1291,
63,
493,
26,
272,
746,
2186,
360,
17200,
370,
2342,
2073,
1406,
1788,
358,
523,
1788,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
1294,
8,
1195,
63,
1291,
63,
493,
2788,
17,
11057,
16,
61,
523,
1788,
275,
1788,
59,
16,
1055,
4142,
342,
435,
1788,
59,
17,
2938,
523,
1830,
1788,
14,
1623,
26341,
1137,
446,
17,
26,
272,
2086,
275,
1788,
14,
1623,
26341,
272,
340,
2086,
2356,
822,
8,
1501,
304,
489,
2059,
272,
1788,
275,
1788,
1491,
1712,
61,
435,
1788,
59,
1712,
435,
413,
1055,
4142,
342,
435,
1788,
59,
1712,
435,
499,
2938,
523,
372,
283,
75,
7,
435,
1788,
421,
199,
318,
485,
3484,
2567,
8,
1231,
12,
6339,
534,
287,
297,
1072,
63,
694,
15637,
735,
523,
1449,
2499,
314,
1406,
570,
367,
314,
2073,
4412,
14,
221,
961,
570,
2951,
477,
3995,
470,
523,
376,
1625,
402,
536,
15,
585,
6342,
10595,
523,
372,
18087,
199,
501,
961,
570,
365,
5847,
4046,
701,
21772,
649,
14,
221,
4226,
440,
5283,
14,
199,
199,
3,
2613,
665,
1516,
318,
14,
72,
30,
199,
199,
3,
27708,
21772,
649,
63,
14110,
63,
5443,
63,
8893,
63,
199,
3,
4640,
21772,
649,
63,
14110,
63,
5443,
63,
8893,
63,
199,
1820,
598,
11133,
4031,
2956,
469,
523,
950,
1495,
10,
950,
536,
27,
523,
1109,
574,
27,
199,
12084,
199,
3,
13739,
5001,
21772,
649,
63,
14110,
63,
5443,
63,
8893,
63,
199,
199,
18587,
950,
598,
11133,
4031,
2956,
2818,
1130,
63,
354,
9,
83,
8607,
27,
199,
18587,
950,
1568,
63,
84,
2818,
1130,
63,
354,
9,
83,
2320,
27,
199,
2344,
450,
469,
283,
1130,
63,
354,
356,
2372,
2956,
985,
8,
1231,
9,
789,
421,
199,
318,
485,
3484,
2980,
2567,
8,
1231,
304,
523,
1449,
2499,
314,
1406,
402,
314,
445,
4176,
1350,
570,
367,
314,
2073,
4412,
10595,
523,
4819,
63,
1291,
63,
493,
275,
488,
523,
2341,
63,
1291,
63,
493,
275,
488,
523,
367,
1072,
315,
1738,
14,
18614,
5535,
837,
272,
340,
283,
1195,
63,
1291,
7,
508,
1072,
14,
24770,
837,
489,
4819,
63,
1291,
63,
493,
275,
1072,
14,
1002,
8117,
342,
272,
916,
283,
1927,
63,
1130,
63,
1291,
7,
508,
1072,
14,
24770,
837,
489,
2341,
63,
1291,
63,
493,
275,
1072,
14,
1002,
8117,
342,
523,
340,
440,
4819,
63,
1291,
63,
493,
503,
440,
2341,
63,
1291,
63,
493,
26,
272,
746,
2186,
360,
1927,
63,
1130,
63,
1365,
1072,
730,
5074,
283,
267,
283,
1927,
63,
1130,
63,
1291,
436,
4819,
63,
1291,
4704,
358,
523,
372,
18087,
199,
501,
961,
570,
365,
5847,
4046,
701,
21772,
649,
14,
221,
4226,
440,
5283,
14,
199,
199,
3,
2613,
11792,
1130,
63,
1291,
63,
493,
9,
83,
2,
199,
199,
3,
2613,
298,
1095,
15,
66,
24950,
9798,
14,
72,
2,
199,
3,
2613,
11792,
1195,
63,
1291,
63,
493,
9,
83,
2,
199,
199,
1297,
598,
11133,
4031,
2956,
2818,
1130,
63,
354,
9,
83,
8607,
275,
469,
199,
2344,
450,
469,
283,
1130,
63,
1291,
63,
493,
356,
2341,
63,
1291,
63,
493,
12,
267,
283,
1195,
63,
1291,
63,
493,
356,
4819,
63,
1291,
63,
493,
12,
267,
283,
1130,
63,
354,
356,
2372,
2956,
985,
8,
1231,
395,
489,
789,
421,
199,
318,
485,
3484,
2980,
5686,
351,
8,
1231,
304,
523,
327,
1432,
314,
14178,
1318,
14,
523,
372,
18087,
199,
12084,
199,
199,
1297,
1568,
63,
84,
2818,
1130,
63,
354,
9,
83,
2320,
275,
1625,
890,
12473,
1130,
63,
354,
9,
83,
2736,
199,
2344,
450,
469,
283,
1130,
63,
354,
356,
2372,
2956,
985,
8,
1231,
9,
789,
421,
199,
318,
485,
3484,
2980,
8,
362,
63,
498,
12,
1738,
12,
6339,
12,
1072,
63,
694,
304,
523,
687,
486,
11133,
14,
908,
492,
4819,
63,
1291,
523,
687,
486,
11133,
14,
932,
492,
2387,
12,
5523,
12,
1245,
523,
1995,
485,
3484,
2980,
2567,
8,
1231,
9,
523,
3367,
795,
275,
4819,
63,
1291,
14,
1002,
11506,
8,
1231,
9,
523,
6775,
275,
663,
342,
523,
4702,
63,
29041,
275,
359,
1053,
367,
1242,
315,
1738,
14,
7472,
9921,
500,
2285,
5106,
523,
1072,
63,
452,
63,
1927,
63,
14334,
275,
1738,
14,
11408,
2959,
2422,
4031,
23891,
342,
523,
367,
1242,
315,
1738,
26,
272,
340,
440,
1242,
14,
1831,
4031,
2956,
2980,
837,
489,
1980
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
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,
2344,
2765,
570,
3509,
1242,
30514,
367,
2073,
63,
1130,
63,
1291,
436,
199,
1927,
63,
1130,
63,
1365,
1584,
14,
221,
437,
2073,
2341,
365,
282,
4412,
3382,
2073,
1561,
199,
8,
875,
9,
436,
314,
5007,
2073,
2870,
10595,
199,
199,
646,
747,
199,
504,
9143,
492,
7417,
199,
199,
504,
486,
11133,
492,
4884,
421,
199,
318,
2372,
7772,
8,
466,
304,
523,
340,
730,
508,
283,
1927,
63,
1130,
63,
1291,
356,
272,
372,
485,
3484,
2567,
523,
916,
730,
508,
283,
1927,
63,
1130,
63,
1365,
356,
272,
372,
7417,
1547,
3484,
2980,
12,
485,
32474,
985,
9,
523,
916,
730,
508,
283,
1927,
63,
493,
63,
1130,
63,
1365,
356,
272,
372,
7417,
1547,
3484,
2980,
12,
485,
32474,
2042,
9,
421,
199,
318,
2372,
2956,
985,
8,
1231,
304,
523,
1449,
1002,
314,
536,
402,
314,
2073,
2341,
4079,
641,
314,
1406,
570,
536,
14,
221,
662,
14,
71,
2020,
523,
340,
4154,
1406,
1788,
365,
8879,
63,
4435,
14,
72,
12,
781,
536,
4154,
2073,
2341,
523,
1022,
16849,
13745,
2956,
14,
819,
1204,
1231,
92,
365,
314,
486,
6883,
570,
1738,
10595,
523,
4704,
275,
1738,
14,
18614,
5535,
342,
523,
4819,
63,
1291,
63,
493,
275,
488,
523,
367,
1072,
315,
4704,
26,
272,
340,
283,
1195,
63,
1291,
7,
508,
1072,
14,
24770,
837,
489,
4819,
63,
1291,
63,
493,
275,
1072,
14,
1002,
8117,
342,
523,
340,
440,
4819,
63,
1291,
63,
493,
26,
272,
746,
2186,
360,
17200,
370,
2342,
2073,
1406,
1788,
358,
523,
1788,
275,
747,
14,
515,
14,
7973,
8,
736,
14,
515,
14,
1294,
8,
1195,
63,
1291,
63,
493,
2788,
17,
11057,
16,
61,
523,
1788,
275,
1788,
59,
16,
1055,
4142,
342,
435,
1788,
59,
17,
2938,
523,
1830,
1788,
14,
1623,
26341,
1137,
446,
17,
26,
272,
2086,
275,
1788,
14,
1623,
26341,
272,
340,
2086,
2356,
822,
8,
1501,
304,
489,
2059,
272,
1788,
275,
1788,
1491,
1712,
61,
435,
1788,
59,
1712,
435,
413,
1055,
4142,
342,
435,
1788,
59,
1712,
435,
499,
2938,
523,
372,
283,
75,
7,
435,
1788,
421,
199,
318,
485,
3484,
2567,
8,
1231,
12,
6339,
534,
287,
297,
1072,
63,
694,
15637,
735,
523,
1449,
2499,
314,
1406,
570,
367,
314,
2073,
4412,
14,
221,
961,
570,
2951,
477,
3995,
470,
523,
376,
1625,
402,
536,
15,
585,
6342,
10595,
523,
372,
18087,
199,
501,
961,
570,
365,
5847,
4046,
701,
21772,
649,
14,
221,
4226,
440,
5283,
14,
199,
199,
3,
2613,
665,
1516,
318,
14,
72,
30,
199,
199,
3,
27708,
21772,
649,
63,
14110,
63,
5443,
63,
8893,
63,
199,
3,
4640,
21772,
649,
63,
14110,
63,
5443,
63,
8893,
63,
199,
1820,
598,
11133,
4031,
2956,
469,
523,
950,
1495,
10,
950,
536,
27,
523,
1109,
574,
27,
199,
12084,
199,
3,
13739,
5001,
21772,
649,
63,
14110,
63,
5443,
63,
8893,
63,
199,
199,
18587,
950,
598,
11133,
4031,
2956,
2818,
1130,
63,
354,
9,
83,
8607,
27,
199,
18587,
950,
1568,
63,
84,
2818,
1130,
63,
354,
9,
83,
2320,
27,
199,
2344,
450,
469,
283,
1130,
63,
354,
356,
2372,
2956,
985,
8,
1231,
9,
789,
421,
199,
318,
485,
3484,
2980,
2567,
8,
1231,
304,
523,
1449,
2499,
314,
1406,
402,
314,
445,
4176,
1350,
570,
367,
314,
2073,
4412,
10595,
523,
4819,
63,
1291,
63,
493,
275,
488,
523,
2341,
63,
1291,
63,
493,
275,
488,
523,
367,
1072,
315,
1738,
14,
18614,
5535,
837,
272,
340,
283,
1195,
63,
1291,
7,
508,
1072,
14,
24770,
837,
489,
4819,
63,
1291,
63,
493,
275,
1072,
14,
1002,
8117,
342,
272,
916,
283,
1927,
63,
1130,
63,
1291,
7,
508,
1072,
14,
24770,
837,
489,
2341,
63,
1291,
63,
493,
275,
1072,
14,
1002,
8117,
342,
523,
340,
440,
4819,
63,
1291,
63,
493,
503,
440,
2341,
63,
1291,
63,
493,
26,
272,
746,
2186,
360,
1927,
63,
1130,
63,
1365,
1072,
730,
5074,
283,
267,
283,
1927,
63,
1130,
63,
1291,
436,
4819,
63,
1291,
4704,
358,
523,
372,
18087,
199,
501,
961,
570,
365,
5847,
4046,
701,
21772,
649,
14,
221,
4226,
440,
5283,
14,
199,
199,
3,
2613,
11792,
1130,
63,
1291,
63,
493,
9,
83,
2,
199,
199,
3,
2613,
298,
1095,
15,
66,
24950,
9798,
14,
72,
2,
199,
3,
2613,
11792,
1195,
63,
1291,
63,
493,
9,
83,
2,
199,
199,
1297,
598,
11133,
4031,
2956,
2818,
1130,
63,
354,
9,
83,
8607,
275,
469,
199,
2344,
450,
469,
283,
1130,
63,
1291,
63,
493,
356,
2341,
63,
1291,
63,
493,
12,
267,
283,
1195,
63,
1291,
63,
493,
356,
4819,
63,
1291,
63,
493,
12,
267,
283,
1130,
63,
354,
356,
2372,
2956,
985,
8,
1231,
395,
489,
789,
421,
199,
318,
485,
3484,
2980,
5686,
351,
8,
1231,
304,
523,
327,
1432,
314,
14178,
1318,
14,
523,
372,
18087,
199,
12084,
199,
199,
1297,
1568,
63,
84,
2818,
1130,
63,
354,
9,
83,
2320,
275,
1625,
890,
12473,
1130,
63,
354,
9,
83,
2736,
199,
2344,
450,
469,
283,
1130,
63,
354,
356,
2372,
2956,
985,
8,
1231,
9,
789,
421,
199,
318,
485,
3484,
2980,
8,
362,
63,
498,
12,
1738,
12,
6339,
12,
1072,
63,
694,
304,
523,
687,
486,
11133,
14,
908,
492,
4819,
63,
1291,
523,
687,
486,
11133,
14,
932,
492,
2387,
12,
5523,
12,
1245,
523,
1995,
485,
3484,
2980,
2567,
8,
1231,
9,
523,
3367,
795,
275,
4819,
63,
1291,
14,
1002,
11506,
8,
1231,
9,
523,
6775,
275,
663,
342,
523,
4702,
63,
29041,
275,
359,
1053,
367,
1242,
315,
1738,
14,
7472,
9921,
500,
2285,
5106,
523,
1072,
63,
452,
63,
1927,
63,
14334,
275,
1738,
14,
11408,
2959,
2422,
4031,
23891,
342,
523,
367,
1242,
315,
1738,
26,
272,
340,
440,
1242,
14,
1831,
4031,
2956,
2980,
837,
489,
1980,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Eyepea/fail2ban
|
fail2ban/server/filtersystemd.py
|
15
|
7968
|
# emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: t -*-
# vi: set ft=python sts=4 ts=4 sw=4 noet :
# This file is part of Fail2Ban.
#
# Fail2Ban 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.
#
# Fail2Ban 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 Fail2Ban; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
__author__ = "Steven Hiscocks"
__copyright__ = "Copyright (c) 2013 Steven Hiscocks"
__license__ = "GPL"
import datetime
import time
from distutils.version import LooseVersion
from systemd import journal
if LooseVersion(getattr(journal, '__version__', "0")) < '204':
raise ImportError("Fail2Ban requires systemd >= 204")
from .failmanager import FailManagerEmpty
from .filter import JournalFilter
from .mytime import MyTime
from ..helpers import getLogger
# Gets the instance of the logger.
logSys = getLogger(__name__)
##
# Journal reader class.
#
# This class reads from systemd journal and detects login failures or anything
# else that matches a given regular expression. This class is instantiated by
# a Jail object.
class FilterSystemd(JournalFilter): # pragma: systemd no cover
##
# Constructor.
#
# Initialize the filter object with default values.
# @param jail the jail object
def __init__(self, jail, **kwargs):
JournalFilter.__init__(self, jail, **kwargs)
self.__modified = False
# Initialise systemd-journal connection
self.__journal = journal.Reader(converters={'__CURSOR': lambda x: x})
self.__matches = []
self.setDatePattern(None)
logSys.debug("Created FilterSystemd")
##
# Add a journal match filters from list structure
#
# @param matches list structure with journal matches
def _addJournalMatches(self, matches):
if self.__matches:
self.__journal.add_disjunction() # Add OR
newMatches = []
for match in matches:
newMatches.append([])
for match_element in match:
self.__journal.add_match(match_element)
newMatches[-1].append(match_element)
self.__journal.add_disjunction()
self.__matches.extend(newMatches)
##
# Add a journal match filter
#
# @param match journalctl syntax matches in list structure
def addJournalMatch(self, match):
newMatches = [[]]
for match_element in match:
if match_element == "+":
newMatches.append([])
else:
newMatches[-1].append(match_element)
try:
self._addJournalMatches(newMatches)
except ValueError:
logSys.error(
"Error adding journal match for: %r", " ".join(match))
self.resetJournalMatches()
raise
else:
logSys.info("Added journal match for: %r", " ".join(match))
##
# Reset a journal match filter called on removal or failure
#
# @return None
def resetJournalMatches(self):
self.__journal.flush_matches()
logSys.debug("Flushed all journal matches")
match_copy = self.__matches[:]
self.__matches = []
try:
self._addJournalMatches(match_copy)
except ValueError:
logSys.error("Error restoring journal matches")
raise
else:
logSys.debug("Journal matches restored")
##
# Delete a journal match filter
#
# @param match journalctl syntax matches
def delJournalMatch(self, match):
if match in self.__matches:
del self.__matches[self.__matches.index(match)]
self.resetJournalMatches()
else:
raise ValueError("Match not found")
logSys.info("Removed journal match for: %r" % " ".join(match))
##
# Get current journal match filter
#
# @return journalctl syntax matches
def getJournalMatch(self):
return self.__matches
##
# Join group of log elements which may be a mix of bytes and strings
#
# @param elements list of strings and bytes
# @return elements joined as string
@staticmethod
def _joinStrAndBytes(elements):
strElements = []
for element in elements:
if isinstance(element, str):
strElements.append(element)
else:
strElements.append(str(element, errors='ignore'))
return " ".join(strElements)
##
# Format journal log entry into syslog style
#
# @param entry systemd journal entry dict
# @return format log line
@classmethod
def formatJournalEntry(cls, logentry):
logelements = [""]
if logentry.get('_HOSTNAME'):
logelements.append(logentry['_HOSTNAME'])
if logentry.get('SYSLOG_IDENTIFIER'):
logelements.append(logentry['SYSLOG_IDENTIFIER'])
if logentry.get('SYSLOG_PID'):
logelements[-1] += ("[%i]" % logentry['SYSLOG_PID'])
elif logentry.get('_PID'):
logelements[-1] += ("[%i]" % logentry['_PID'])
logelements[-1] += ":"
elif logentry.get('_COMM'):
logelements.append(logentry['_COMM'])
if logentry.get('_PID'):
logelements[-1] += ("[%i]" % logentry['_PID'])
logelements[-1] += ":"
if logelements[-1] == "kernel:":
if '_SOURCE_MONOTONIC_TIMESTAMP' in logentry:
monotonic = logentry.get('_SOURCE_MONOTONIC_TIMESTAMP')
else:
monotonic = logentry.get('__MONOTONIC_TIMESTAMP')[0]
logelements.append("[%12.6f]" % monotonic.total_seconds())
if isinstance(logentry.get('MESSAGE',''), list):
logelements.append(" ".join(logentry['MESSAGE']))
else:
logelements.append(logentry.get('MESSAGE', ''))
try:
logline = u" ".join(logelements)
except UnicodeDecodeError:
# Python 2, so treat as string
logline = " ".join([str(logline) for logline in logelements])
except TypeError:
# Python 3, one or more elements bytes
logSys.warning("Error decoding log elements from journal: %s" %
repr(logelements))
logline = cls._joinStrAndBytes(logelements)
date = logentry.get('_SOURCE_REALTIME_TIMESTAMP',
logentry.get('__REALTIME_TIMESTAMP'))
logSys.debug("Read systemd journal entry: %r" %
"".join([date.isoformat(), logline]))
return (('', date.isoformat(), logline),
time.mktime(date.timetuple()) + date.microsecond/1.0E6)
##
# Main loop.
#
# Peridocily check for new journal entries matching the filter and
# handover to FailManager
def run(self):
if not self.getJournalMatch():
logSys.notice(
"Jail started without 'journalmatch' set. "
"Jail regexs will be checked against all journal entries, "
"which is not advised for performance reasons.")
# Seek to now - findtime in journal
start_time = datetime.datetime.now() - \
datetime.timedelta(seconds=int(self.getFindTime()))
self.__journal.seek_realtime(start_time)
# Move back one entry to ensure do not end up in dead space
# if start time beyond end of journal
try:
self.__journal.get_previous()
except OSError:
pass # Reading failure, so safe to ignore
while self.active:
if not self.idle:
while self.active:
try:
logentry = self.__journal.get_next()
except OSError:
logSys.warning(
"Error reading line from systemd journal")
continue
if logentry:
self.processLineAndAdd(
*self.formatJournalEntry(logentry))
self.__modified = True
else:
break
if self.__modified:
try:
while True:
ticket = self.failManager.toBan()
self.jail.putFailTicket(ticket)
except FailManagerEmpty:
self.failManager.cleanup(MyTime.time())
self.__modified = False
self.__journal.wait(self.sleeptime)
logSys.debug((self.jail is not None and self.jail.name
or "jailless") +" filter terminated")
return True
def status(self, flavor="basic"):
ret = super(FilterSystemd, self).status(flavor=flavor)
ret.append(("Journal matches",
[" + ".join(" ".join(match) for match in self.__matches)]))
return ret
|
gpl-2.0
|
[
3,
325,
19309,
26,
1882,
818,
26,
2366,
27,
1134,
13,
3724,
13,
2743,
26,
841,
27,
4363,
13,
8741,
13,
632,
26,
307,
1882,
199,
3,
1321,
26,
663,
18133,
29,
1548,
23014,
29,
20,
6714,
29,
20,
5584,
29,
20,
949,
386,
520,
199,
199,
3,
961,
570,
365,
1777,
402,
12176,
18,
28018,
14,
199,
3,
199,
3,
12176,
18,
28018,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12176,
18,
28018,
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,
12176,
18,
28018,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
14,
421,
199,
363,
2502,
363,
275,
298,
26696,
1856,
869,
10081,
5618,
2,
199,
363,
7307,
363,
275,
298,
7384,
334,
67,
9,
6171,
17854,
1856,
869,
10081,
5618,
2,
199,
363,
1682,
363,
275,
298,
12006,
2,
199,
199,
646,
2197,
199,
646,
900,
199,
504,
7065,
14,
1023,
492,
18462,
199,
199,
504,
2656,
68,
492,
9605,
199,
692,
18462,
8,
5675,
8,
7067,
12,
2560,
1023,
7500,
298,
16,
2237,
665,
283,
6686,
356,
199,
198,
3730,
3545,
480,
4874,
18,
28018,
5074,
2656,
68,
2356,
14785,
531,
199,
199,
504,
1275,
1633,
2609,
492,
12176,
2988,
4699,
199,
504,
1275,
1541,
492,
22142,
4131,
199,
504,
1275,
1662,
521,
492,
4932,
1366,
199,
504,
2508,
7546,
492,
28138,
199,
199,
3,
14509,
314,
1256,
402,
314,
2512,
14,
199,
793,
11319,
275,
28138,
3460,
354,
3368,
421,
199,
309,
199,
3,
22142,
7002,
1021,
14,
199,
3,
199,
3,
961,
1021,
11597,
687,
2656,
68,
9605,
436,
477,
28853,
4676,
9081,
503,
7003,
199,
3,
587,
626,
4450,
282,
1627,
5578,
3965,
14,
961,
1021,
365,
17544,
701,
199,
3,
282,
1603,
1054,
909,
14,
199,
199,
533,
9388,
3989,
68,
8,
25909,
4131,
304,
327,
11942,
26,
2656,
68,
949,
8486,
199,
198,
309,
199,
198,
3,
20297,
14,
199,
198,
3,
199,
198,
3,
11578,
314,
2457,
909,
543,
849,
1338,
14,
199,
198,
3,
768,
635,
1335,
1054,
314,
1335,
1054,
909,
421,
198,
318,
636,
826,
721,
277,
12,
1335,
1054,
12,
1011,
958,
304,
507,
198,
25909,
4131,
855,
826,
721,
277,
12,
1335,
1054,
12,
1011,
958,
9,
507,
198,
277,
855,
5540,
275,
756,
507,
198,
3,
6026,
572,
2656,
68,
13,
7067,
1950,
507,
198,
277,
855,
7067,
275,
9605,
14,
5929,
8,
17911,
3713,
363,
31321,
356,
2400,
671,
26,
671,
1552,
507,
198,
277,
855,
6742,
275,
942,
507,
198,
277,
14,
409,
2506,
9959,
8,
403,
9,
507,
198,
793,
11319,
14,
1757,
480,
10502,
9388,
3989,
68,
531,
421,
198,
309,
199,
198,
3,
2654,
282,
9605,
1336,
4766,
687,
769,
5523,
199,
198,
3,
199,
198,
3,
768,
635,
4450,
769,
5523,
543,
9605,
4450,
421,
198,
318,
485,
525,
25909,
12962,
8,
277,
12,
4450,
304,
507,
198,
692,
291,
855,
6742,
26,
686,
198,
277,
855,
7067,
14,
525,
63,
2297,
32367,
342,
327,
2654,
1549,
507,
198,
1222,
12962,
275,
942,
507,
198,
509,
1336,
315,
4450,
26,
686,
198,
1222,
12962,
14,
740,
4157,
686,
198,
509,
1336,
63,
2108,
315,
1336,
26,
1585,
198,
277,
855,
7067,
14,
525,
63,
1431,
8,
1431,
63,
2108,
9,
1585,
198,
1222,
12962,
1988,
17,
1055,
740,
8,
1431,
63,
2108,
9,
686,
198,
277,
855,
7067,
14,
525,
63,
2297,
32367,
342,
507,
198,
277,
855,
6742,
14,
2880,
8,
1222,
12962,
9,
421,
198,
309,
199,
198,
3,
2654,
282,
9605,
1336,
2457,
199,
198,
3,
199,
198,
3,
768,
635,
1336,
9605,
8077,
6302,
4450,
315,
769,
5523,
421,
198,
318,
1050,
25909,
4486,
8,
277,
12,
1336,
304,
507,
198,
1222,
12962,
275,
3474,
2677,
507,
198,
509,
1336,
63,
2108,
315,
1336,
26,
686,
198,
692,
1336,
63,
2108,
508,
7210,
582,
1585,
198,
1222,
12962,
14,
740,
4157,
686,
198,
2836,
26,
1585,
198,
1222,
12962,
1988,
17,
1055,
740,
8,
1431,
63,
2108,
9,
507,
198,
893,
26,
686,
198,
277,
423,
525,
25909,
12962,
8,
1222,
12962,
9,
507,
198,
2590,
1722,
26,
686,
198,
793,
11319,
14,
705,
8,
1585,
198,
2,
547,
7791,
9605,
1336,
367,
26,
450,
82,
401,
298,
3680,
904,
8,
1431,
430,
686,
198,
277,
14,
3958,
25909,
12962,
342,
686,
198,
3730,
507,
198,
2836,
26,
686,
198,
793,
11319,
14,
815,
480,
20201,
9605,
1336,
367,
26,
450,
82,
401,
298,
3680,
904,
8,
1431,
430,
199,
198,
309,
199,
198,
3,
15510,
282,
9605,
1336,
2457,
2797,
641,
20055,
503,
5988,
199,
198,
3,
199,
198,
3,
768,
1107,
488,
221,
421,
198,
318,
5305,
25909,
12962,
8,
277,
304,
507,
198,
277,
855,
7067,
14,
4939,
63,
6742,
342,
507,
198,
793,
11319,
14,
1757,
480,
20053,
379,
1006,
9605,
4450,
531,
507,
198,
1431,
63,
1574,
275,
291,
855,
6742,
5873,
507,
198,
277,
855,
6742,
275,
942,
507,
198,
893,
26,
686,
198,
277,
423,
525,
25909,
12962,
8,
1431,
63,
1574,
9,
507,
198,
2590,
1722,
26,
686,
198,
793,
11319,
14,
705,
480,
547,
4618,
6854,
9605,
4450,
531,
686,
198,
3730,
507,
198,
2836,
26,
686,
198,
793,
11319,
14,
1757,
480,
25909,
4450,
14429,
531,
421,
198,
309,
199,
198,
3,
8496,
282,
9605,
1336,
2457,
199,
198,
3,
199,
198,
3,
768,
635,
1336,
9605,
8077,
6302,
4450,
421,
198,
318,
2150,
25909,
4486
] |
[
325,
19309,
26,
1882,
818,
26,
2366,
27,
1134,
13,
3724,
13,
2743,
26,
841,
27,
4363,
13,
8741,
13,
632,
26,
307,
1882,
199,
3,
1321,
26,
663,
18133,
29,
1548,
23014,
29,
20,
6714,
29,
20,
5584,
29,
20,
949,
386,
520,
199,
199,
3,
961,
570,
365,
1777,
402,
12176,
18,
28018,
14,
199,
3,
199,
3,
12176,
18,
28018,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
12176,
18,
28018,
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,
12176,
18,
28018,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
221,
11315,
13,
10067,
12,
8217,
14,
421,
199,
363,
2502,
363,
275,
298,
26696,
1856,
869,
10081,
5618,
2,
199,
363,
7307,
363,
275,
298,
7384,
334,
67,
9,
6171,
17854,
1856,
869,
10081,
5618,
2,
199,
363,
1682,
363,
275,
298,
12006,
2,
199,
199,
646,
2197,
199,
646,
900,
199,
504,
7065,
14,
1023,
492,
18462,
199,
199,
504,
2656,
68,
492,
9605,
199,
692,
18462,
8,
5675,
8,
7067,
12,
2560,
1023,
7500,
298,
16,
2237,
665,
283,
6686,
356,
199,
198,
3730,
3545,
480,
4874,
18,
28018,
5074,
2656,
68,
2356,
14785,
531,
199,
199,
504,
1275,
1633,
2609,
492,
12176,
2988,
4699,
199,
504,
1275,
1541,
492,
22142,
4131,
199,
504,
1275,
1662,
521,
492,
4932,
1366,
199,
504,
2508,
7546,
492,
28138,
199,
199,
3,
14509,
314,
1256,
402,
314,
2512,
14,
199,
793,
11319,
275,
28138,
3460,
354,
3368,
421,
199,
309,
199,
3,
22142,
7002,
1021,
14,
199,
3,
199,
3,
961,
1021,
11597,
687,
2656,
68,
9605,
436,
477,
28853,
4676,
9081,
503,
7003,
199,
3,
587,
626,
4450,
282,
1627,
5578,
3965,
14,
961,
1021,
365,
17544,
701,
199,
3,
282,
1603,
1054,
909,
14,
199,
199,
533,
9388,
3989,
68,
8,
25909,
4131,
304,
327,
11942,
26,
2656,
68,
949,
8486,
199,
198,
309,
199,
198,
3,
20297,
14,
199,
198,
3,
199,
198,
3,
11578,
314,
2457,
909,
543,
849,
1338,
14,
199,
198,
3,
768,
635,
1335,
1054,
314,
1335,
1054,
909,
421,
198,
318,
636,
826,
721,
277,
12,
1335,
1054,
12,
1011,
958,
304,
507,
198,
25909,
4131,
855,
826,
721,
277,
12,
1335,
1054,
12,
1011,
958,
9,
507,
198,
277,
855,
5540,
275,
756,
507,
198,
3,
6026,
572,
2656,
68,
13,
7067,
1950,
507,
198,
277,
855,
7067,
275,
9605,
14,
5929,
8,
17911,
3713,
363,
31321,
356,
2400,
671,
26,
671,
1552,
507,
198,
277,
855,
6742,
275,
942,
507,
198,
277,
14,
409,
2506,
9959,
8,
403,
9,
507,
198,
793,
11319,
14,
1757,
480,
10502,
9388,
3989,
68,
531,
421,
198,
309,
199,
198,
3,
2654,
282,
9605,
1336,
4766,
687,
769,
5523,
199,
198,
3,
199,
198,
3,
768,
635,
4450,
769,
5523,
543,
9605,
4450,
421,
198,
318,
485,
525,
25909,
12962,
8,
277,
12,
4450,
304,
507,
198,
692,
291,
855,
6742,
26,
686,
198,
277,
855,
7067,
14,
525,
63,
2297,
32367,
342,
327,
2654,
1549,
507,
198,
1222,
12962,
275,
942,
507,
198,
509,
1336,
315,
4450,
26,
686,
198,
1222,
12962,
14,
740,
4157,
686,
198,
509,
1336,
63,
2108,
315,
1336,
26,
1585,
198,
277,
855,
7067,
14,
525,
63,
1431,
8,
1431,
63,
2108,
9,
1585,
198,
1222,
12962,
1988,
17,
1055,
740,
8,
1431,
63,
2108,
9,
686,
198,
277,
855,
7067,
14,
525,
63,
2297,
32367,
342,
507,
198,
277,
855,
6742,
14,
2880,
8,
1222,
12962,
9,
421,
198,
309,
199,
198,
3,
2654,
282,
9605,
1336,
2457,
199,
198,
3,
199,
198,
3,
768,
635,
1336,
9605,
8077,
6302,
4450,
315,
769,
5523,
421,
198,
318,
1050,
25909,
4486,
8,
277,
12,
1336,
304,
507,
198,
1222,
12962,
275,
3474,
2677,
507,
198,
509,
1336,
63,
2108,
315,
1336,
26,
686,
198,
692,
1336,
63,
2108,
508,
7210,
582,
1585,
198,
1222,
12962,
14,
740,
4157,
686,
198,
2836,
26,
1585,
198,
1222,
12962,
1988,
17,
1055,
740,
8,
1431,
63,
2108,
9,
507,
198,
893,
26,
686,
198,
277,
423,
525,
25909,
12962,
8,
1222,
12962,
9,
507,
198,
2590,
1722,
26,
686,
198,
793,
11319,
14,
705,
8,
1585,
198,
2,
547,
7791,
9605,
1336,
367,
26,
450,
82,
401,
298,
3680,
904,
8,
1431,
430,
686,
198,
277,
14,
3958,
25909,
12962,
342,
686,
198,
3730,
507,
198,
2836,
26,
686,
198,
793,
11319,
14,
815,
480,
20201,
9605,
1336,
367,
26,
450,
82,
401,
298,
3680,
904,
8,
1431,
430,
199,
198,
309,
199,
198,
3,
15510,
282,
9605,
1336,
2457,
2797,
641,
20055,
503,
5988,
199,
198,
3,
199,
198,
3,
768,
1107,
488,
221,
421,
198,
318,
5305,
25909,
12962,
8,
277,
304,
507,
198,
277,
855,
7067,
14,
4939,
63,
6742,
342,
507,
198,
793,
11319,
14,
1757,
480,
20053,
379,
1006,
9605,
4450,
531,
507,
198,
1431,
63,
1574,
275,
291,
855,
6742,
5873,
507,
198,
277,
855,
6742,
275,
942,
507,
198,
893,
26,
686,
198,
277,
423,
525,
25909,
12962,
8,
1431,
63,
1574,
9,
507,
198,
2590,
1722,
26,
686,
198,
793,
11319,
14,
705,
480,
547,
4618,
6854,
9605,
4450,
531,
686,
198,
3730,
507,
198,
2836,
26,
686,
198,
793,
11319,
14,
1757,
480,
25909,
4450,
14429,
531,
421,
198,
309,
199,
198,
3,
8496,
282,
9605,
1336,
2457,
199,
198,
3,
199,
198,
3,
768,
635,
1336,
9605,
8077,
6302,
4450,
421,
198,
318,
2150,
25909,
4486,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jmartinm/invenio-master
|
modules/bibcheck/lib/plugins/texkey.py
|
15
|
1977
|
# -*- coding: utf-8 -*-
##
## This file is part of Invenio.
## Copyright (C) 2013 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
""" Bibcheck plugin to add tex keys """
from invenio.bibrecord import record_add_field
from invenio.sequtils_texkey import TexkeySeq, TexkeyNoAuthorError
def check_record(record, texkey_field="035__a", extra_subfields=()):
"""
Add a tex key to a record, checking that it doesn't have one already.
"""
tag = texkey_field[:3]
ind1, ind2, subfield = texkey_field[3:]
provenances = list(record.iterfield(texkey_field[:5] + "9"))
if len(provenances) and provenances[0][1] in ("SPIRESTeX", "INSPIRETeX"):
for _, val in record.iterfield(texkey_field[:5] + "z"):
if val:
return # Record already has a texkey
if len(list(record.iterfield(texkey_field))) == 0:
try:
texkey = TexkeySeq().next_value(bibrecord=record)
except TexkeyNoAuthorError:
record.warn("No first author or collaboration")
return
subfields_to_add = [(subfield, texkey)] + map(tuple, extra_subfields)
record_add_field(record, tag=tag, ind1=ind1, ind2=ind2,
subfields=subfields_to_add)
record.set_amended("Added Tex key '%s' to field %s" % (texkey, texkey_field))
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
309,
199,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
6171,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
21949,
1074,
3589,
370,
1050,
14709,
2883,
408,
199,
199,
504,
13640,
14,
8804,
3059,
492,
2777,
63,
525,
63,
698,
199,
504,
13640,
14,
261,
392,
3024,
63,
3858,
498,
492,
20566,
498,
11205,
12,
20566,
498,
1944,
5949,
547,
199,
199,
318,
1104,
63,
3059,
8,
3059,
12,
14709,
498,
63,
698,
628,
21088,
363,
65,
401,
2402,
63,
954,
955,
23603,
272,
408,
272,
2654,
282,
14709,
790,
370,
282,
2777,
12,
7907,
626,
652,
3181,
1133,
1172,
1373,
2575,
14,
272,
408,
272,
1947,
275,
14709,
498,
63,
698,
1491,
19,
61,
272,
7654,
17,
12,
7654,
18,
12,
31014,
275,
14709,
498,
63,
698,
59,
19,
2938,
339,
557,
1856,
13236,
275,
769,
8,
3059,
14,
1661,
698,
8,
3858,
498,
63,
698,
1491,
21,
61,
435,
298,
25,
2237,
272,
340,
822,
8,
496,
1856,
13236,
9,
436,
557,
1856,
13236,
59,
16,
1527,
17,
61,
315,
1689,
20495,
15740,
69,
56,
401,
298,
10789,
2252,
7341,
69,
56,
2349,
267,
367,
5501,
1139,
315,
2777,
14,
1661,
698,
8,
3858,
498,
63,
698,
1491,
21,
61,
435,
298,
90,
2349,
288,
340,
1139,
26,
355,
372,
327,
12651,
2575,
965,
282,
14709,
498,
339,
340,
822,
8,
513,
8,
3059,
14,
1661,
698,
8,
3858,
498,
63,
698,
1724,
508,
378,
26,
267,
862,
26,
288,
14709,
498,
275,
221,
20566,
498,
11205,
1252,
2184,
63,
585,
8,
8804,
3059,
29,
3059,
9,
267,
871,
20566,
498,
1944,
5949,
547,
26,
288,
2777,
14,
4050,
480,
1944,
1642,
4132,
503,
1048,
5561,
14496,
531,
288,
372,
267,
1007,
955,
63,
475,
63,
525,
275,
3842,
11852,
12,
14709,
498,
1874,
435,
2341,
8,
2960,
12,
2402,
63,
954,
955,
9,
267,
2777,
63,
525,
63,
698,
8,
3059,
12,
1947,
29,
1450,
12,
7654,
17,
29,
688,
17,
12,
7654,
18,
29,
688,
18,
12,
355,
1007,
955,
29,
954,
955,
63,
475,
63,
525,
9,
267,
2777,
14,
409,
63,
313,
78,
770,
480,
20201,
20566,
790,
1543,
83,
7,
370,
901,
450,
83,
2,
450,
334,
3858,
498,
12,
14709,
498,
63,
698,
430,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
309,
199,
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
6171,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
624,
21949,
1074,
3589,
370,
1050,
14709,
2883,
408,
199,
199,
504,
13640,
14,
8804,
3059,
492,
2777,
63,
525,
63,
698,
199,
504,
13640,
14,
261,
392,
3024,
63,
3858,
498,
492,
20566,
498,
11205,
12,
20566,
498,
1944,
5949,
547,
199,
199,
318,
1104,
63,
3059,
8,
3059,
12,
14709,
498,
63,
698,
628,
21088,
363,
65,
401,
2402,
63,
954,
955,
23603,
272,
408,
272,
2654,
282,
14709,
790,
370,
282,
2777,
12,
7907,
626,
652,
3181,
1133,
1172,
1373,
2575,
14,
272,
408,
272,
1947,
275,
14709,
498,
63,
698,
1491,
19,
61,
272,
7654,
17,
12,
7654,
18,
12,
31014,
275,
14709,
498,
63,
698,
59,
19,
2938,
339,
557,
1856,
13236,
275,
769,
8,
3059,
14,
1661,
698,
8,
3858,
498,
63,
698,
1491,
21,
61,
435,
298,
25,
2237,
272,
340,
822,
8,
496,
1856,
13236,
9,
436,
557,
1856,
13236,
59,
16,
1527,
17,
61,
315,
1689,
20495,
15740,
69,
56,
401,
298,
10789,
2252,
7341,
69,
56,
2349,
267,
367,
5501,
1139,
315,
2777,
14,
1661,
698,
8,
3858,
498,
63,
698,
1491,
21,
61,
435,
298,
90,
2349,
288,
340,
1139,
26,
355,
372,
327,
12651,
2575,
965,
282,
14709,
498,
339,
340,
822,
8,
513,
8,
3059,
14,
1661,
698,
8,
3858,
498,
63,
698,
1724,
508,
378,
26,
267,
862,
26,
288,
14709,
498,
275,
221,
20566,
498,
11205,
1252,
2184,
63,
585,
8,
8804,
3059,
29,
3059,
9,
267,
871,
20566,
498,
1944,
5949,
547,
26,
288,
2777,
14,
4050,
480,
1944,
1642,
4132,
503,
1048,
5561,
14496,
531,
288,
372,
267,
1007,
955,
63,
475,
63,
525,
275,
3842,
11852,
12,
14709,
498,
1874,
435,
2341,
8,
2960,
12,
2402,
63,
954,
955,
9,
267,
2777,
63,
525,
63,
698,
8,
3059,
12,
1947,
29,
1450,
12,
7654,
17,
29,
688,
17,
12,
7654,
18,
29,
688,
18,
12,
355,
1007,
955,
29,
954,
955,
63,
475,
63,
525,
9,
267,
2777,
14,
409,
63,
313,
78,
770,
480,
20201,
20566,
790,
1543,
83,
7,
370,
901,
450,
83,
2,
450,
334,
3858,
498,
12,
14709,
498,
63,
698,
430,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
AMOboxTV/AMOBox.LegoBuild
|
script.navi-x/init/skin.py
|
7
|
5396
|
#############################################################################
#
# Navi-X Playlist browser
#
#############################################################################
#############################################################################
#
# skin.py:
# This file loads the GUI elements on the main screen.
#############################################################################
from string import *
import sys, os.path
import urllib
import urllib2
import re, random, string
import xbmc, xbmcgui, xbmcaddon
import re, os, time, datetime, traceback
import Image, ImageFile
import shutil
import zipfile
import socket
from settings import *
try: Emulating = xbmcgui.Emulating
except: Emulating = False
addon = xbmcaddon.Addon(id='script.navi-x')
RootDir = addon.getAddonInfo('path')
if RootDir[-1]==';': RootDir=RootDir[0:-1]
if RootDir[-1]!='\\': RootDir=RootDir+'\\'
imageDir = RootDir + "\\images\\"
cacheDir = RootDir + "\\cache\\"
imageCacheDir = RootDir + "\\cache\\imageview\\"
scriptDir = "Q:\\scripts\\"
myDownloadsDir = RootDir + "My Downloads\\"
initDir = RootDir + "\\init\\"
######################################################################
# Description: Draws all widgets on the screen during start-up
# Parameters : window: handle to the main window
# Return : -
######################################################################
def load_skin(window):
#background image
window.bg = xbmcgui.ControlImage(0,0,720,576, imageDir + "background.png")
window.addControl(window.bg)
window.bg1 = xbmcgui.ControlImage(0,0,720,576, imageDir + "background.png")
window.addControl(window.bg1)
#Navi-X logo at top-right position
window.logo = xbmcgui.ControlImage(610,20,80,80, imageDir + "logo.png")
window.addControl(window.logo)
#user logo below the buttons
window.user_logo = xbmcgui.ControlImage(32,120,210,172, imageDir + "logo.png")
window.addControl(window.user_logo)
window.user_logo.setVisible(0)
#user thumb below the buttons (overlaps with the user logo)
window.user_thumb = xbmcgui.ControlImage(32,120,210,172, imageDir + "logo.png")
window.addControl(window.user_thumb)
window.user_thumb.setVisible(0)
#URL label at top-center position
window.urllbl = xbmcgui.ControlLabel(40,80,350,40, "", "font14")
window.addControl(window.urllbl)
#Navi-X Version label at top-left position
window.version = xbmcgui.ControlLabel(40,20,155,40, 'version: '+ Version+ '.' + SubVersion, "font14")
window.addControl(window.version)
#"Loading..." text at down-left side
window.infotekst = xbmcgui.ControlLabel(80,500,250,30, "Loading...")
window.addControl(window.infotekst)
window.infotekst.setVisible(0)
#"Please wait..." text displayed on top of the main list
window.loading = xbmcgui.ControlLabel(280, 130, 250, 30, "Please wait...")
window.addControl(window.loading)
window.loading.setVisible(0)
#main list displaying playlist entries
window.list = xbmcgui.ControlList(260,120,450,440,'font14','0xFFDDDDDD', buttonFocusTexture=RootDir+'images\\list-focus.png', imageWidth=32, imageHeight=32, itemHeight=38)
window.addControl(window.list)
window.list.setPageControlVisible(False)
#list cursor position label displayed at the bottom right of the screen
window.listpos = xbmcgui.ControlLabel(640,540,250,30, "")
window.addControl(window.listpos)
#buttons creation
x=50
y=303
window.button_home = xbmcgui.ControlButton(x,y,120,32,' Home', RootDir + "images\\button-focus1.png", RootDir + "images\\button-nofocus1.png")
window.addControl(window.button_home)
window.button_favorites = xbmcgui.ControlButton(x,y+32,120,32,' Favorites', RootDir + "images\\button-focus1.png", RootDir + "images\\button-nofocus1.png")
window.addControl(window.button_favorites)
window.button_downloads = xbmcgui.ControlButton(x,y+64,120,32,' Downloads', RootDir + "images\\button-focus1.png", RootDir + "images\\button-nofocus1.png")
window.addControl(window.button_downloads)
window.button_url = xbmcgui.ControlButton(x,y+96,120,32,' Browse', RootDir + "images\\button-focus1.png", RootDir + "images\\button-nofocus1.png")
window.addControl(window.button_url)
window.button_about = xbmcgui.ControlButton(x,y+128,120,32,' About', RootDir + "images\\button-focus1.png", RootDir + "images\\button-nofocus1.png")
window.addControl(window.button_about)
#button behaviour
window.button_home.controlDown(window.button_favorites)
window.button_favorites.controlDown(window.button_downloads)
window.button_downloads.controlDown(window.button_url)
window.button_url.controlDown(window.button_about)
window.button_about.controlUp(window.button_url)
window.button_url.controlUp(window.button_downloads)
window.button_downloads.controlUp(window.button_favorites)
window.button_favorites.controlUp(window.button_home)
window.button_home.controlRight(window.list)
window.button_favorites.controlRight(window.list)
window.button_downloads.controlRight(window.list)
window.button_url.controlRight(window.list)
window.button_about.controlRight(window.list)
window.list.controlLeft(window.button_home)
|
gpl-2.0
|
[
31635,
199,
3,
199,
3,
20721,
13,
56,
16527,
513,
7042,
199,
3,
199,
31635,
199,
199,
31635,
199,
3,
199,
3,
28337,
14,
647,
26,
199,
3,
961,
570,
14404,
314,
17160,
4008,
641,
314,
2446,
6426,
14,
199,
31635,
199,
199,
504,
1059,
492,
627,
199,
646,
984,
12,
747,
14,
515,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
295,
12,
2196,
12,
1059,
199,
646,
11709,
12,
26418,
12,
11709,
9291,
199,
646,
295,
12,
747,
12,
900,
12,
2197,
12,
5190,
199,
646,
6047,
12,
6047,
1173,
199,
646,
5145,
199,
646,
10392,
199,
646,
2838,
199,
504,
2202,
492,
627,
199,
199,
893,
26,
662,
3703,
1958,
275,
26418,
14,
37,
3703,
1958,
199,
2590,
26,
662,
3703,
1958,
275,
756,
199,
199,
9291,
275,
11709,
9291,
14,
19654,
8,
344,
534,
1579,
14,
15595,
13,
88,
358,
199,
6405,
3567,
275,
13553,
14,
362,
19654,
2354,
360,
515,
358,
199,
199,
692,
12826,
3567,
1988,
17,
22954,
6015,
12826,
3567,
29,
6405,
3567,
59,
16,
6809,
17,
61,
199,
692,
12826,
3567,
1988,
17,
61,
27909,
1103,
356,
12826,
3567,
29,
6405,
3567,
4786,
1103,
7,
199,
1569,
3567,
275,
12826,
3567,
435,
9926,
4782,
15022,
199,
1637,
3567,
275,
12826,
3567,
435,
9926,
1637,
15022,
199,
1569,
4437,
3567,
275,
12826,
3567,
435,
9926,
1637,
1103,
1569,
1345,
15022,
199,
1579,
3567,
275,
298,
49,
18589,
6429,
15022,
199,
1662,
3514,
3640,
3567,
275,
12826,
3567,
435,
298,
5713,
13392,
3640,
15022,
199,
826,
3567,
275,
12826,
3567,
435,
9926,
826,
15022,
199,
199,
18022,
199,
3,
11994,
26,
17813,
83,
1006,
11114,
641,
314,
6426,
5309,
1343,
13,
384,
199,
3,
3897,
520,
4353,
26,
2429,
370,
314,
2446,
4353,
199,
3,
1432,
258,
520,
446,
199,
18022,
199,
318,
2248,
63,
16409,
8,
3806,
304,
272,
327,
7451,
1834,
339,
4353,
14,
6856,
275,
26418,
14,
3717,
3491,
8,
16,
12,
16,
12,
18386,
12,
12255,
12,
1834,
3567,
435,
298,
7451,
14,
4524,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
6856,
9,
339,
4353,
14,
6856,
17,
275,
26418,
14,
3717,
3491,
8,
16,
12,
16,
12,
18386,
12,
12255,
12,
1834,
3567,
435,
298,
7451,
14,
4524,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
6856,
17,
9,
2286,
327,
19617,
13,
56,
23623,
737,
2746,
13,
1019,
3421,
272,
4353,
14,
9733,
275,
26418,
14,
3717,
3491,
8,
31504,
12,
1165,
12,
1257,
12,
1257,
12,
1834,
3567,
435,
298,
9733,
14,
4524,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
9733,
9,
339,
327,
751,
23623,
5084,
314,
15766,
272,
4353,
14,
751,
63,
9733,
275,
26418,
14,
3717,
3491,
8,
708,
12,
6708,
12,
12725,
12,
10419,
12,
1834,
3567,
435,
298,
9733,
14,
4524,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
751,
63,
9733,
9,
272,
4353,
14,
751,
63,
9733,
14,
32232,
8,
16,
9,
15567,
327,
751,
21541,
5084,
314,
15766,
334,
20798,
543,
314,
922,
23623,
9,
272,
4353,
14,
751,
63,
16534,
275,
26418,
14,
3717,
3491,
8,
708,
12,
6708,
12,
12725,
12,
10419,
12,
1834,
3567,
435,
298,
9733,
14,
4524,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
751,
63,
16534,
9,
272,
4353,
14,
751,
63,
16534,
14,
32232,
8,
16,
9,
2286,
327,
2632,
1768,
737,
2746,
13,
4218,
3421,
272,
4353,
14,
633,
18842,
275,
26418,
14,
3717,
4314,
8,
2167,
12,
1257,
12,
13595,
12,
2167,
12,
4873,
298,
4246,
1079,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
633,
18842,
9,
339,
327,
19617,
13,
56,
3394,
1768,
737,
2746,
13,
3039,
3421,
272,
4353,
14,
1023,
275,
26418,
14,
3717,
4314,
8,
2167,
12,
1165,
12,
11520,
12,
2167,
12,
283,
1023,
26,
6681,
3394,
11,
7815,
435,
4804,
3353,
12,
298,
4246,
1079,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
1023,
9,
755,
2286,
20383,
19236,
11500,
1318,
737,
3224,
13,
3039,
5366,
272,
4353,
14,
815,
266,
75,
270,
275,
26418,
14,
3717,
4314,
8,
1257,
12,
5783,
12,
7991,
12,
1216,
12,
298,
19236,
12594,
272,
4353,
14,
525,
3717,
8,
3806,
14,
815,
266,
75,
270,
9,
272,
4353,
14,
815,
266,
75,
270,
14,
32232,
8,
16,
9,
339,
20383,
8254,
3618,
11500,
1318,
9080,
641,
2746,
402,
314,
2446,
769,
272,
4353,
14,
8786,
275,
26418,
14,
3717,
4314,
8,
18520,
12,
21334,
12,
16074,
12,
4233,
12,
298,
8254,
3618,
12594,
272,
4353,
14,
525,
3717,
8,
3806,
14,
8786,
9,
272,
4353,
14,
8786,
14,
32232,
8,
16,
9,
2286,
327,
973,
769,
20589,
13210,
4811,
272,
4353,
14,
513,
275,
26418,
14,
3717,
1296,
8,
13085,
12,
6708,
12,
24223,
12,
14162,
2584,
4246,
1079,
1673,
16,
9039,
5745,
5745,
5745,
297,
5528,
17310,
17165,
29,
6405,
3567,
4786,
4782,
1103,
513,
13,
12283,
14,
4524,
297,
1834,
6216,
29,
708,
12,
1834,
8436,
29,
708,
12,
1242,
8436,
29,
1703,
9,
272,
4353,
14,
525,
3717,
8,
3806,
14,
513,
9,
272,
4353,
14,
513,
14,
409,
3276,
3717,
14917,
8,
797,
9,
339,
327,
513,
3920,
3421,
1768,
9080,
737,
314,
9048,
2451,
402,
314,
6426,
272,
4353,
14,
513,
1712,
275,
26418,
14,
3717,
4314,
8,
12021,
12,
17814,
12,
7991,
12,
1216,
12,
6899,
272,
4353,
14,
525,
3717,
8,
3806,
14,
513,
1712,
9,
2286,
327,
15687,
7143,
272,
671,
29,
1400,
272,
612,
29,
11810,
272,
4353,
14,
3887,
63,
4219,
275,
26418,
14,
3717,
4259,
8,
88,
12,
89,
12,
6708,
12,
708,
2584,
420,
14621,
297,
12826,
3567,
435,
298,
4782,
1103,
3887,
13,
12283,
17,
14,
4524,
401,
12826,
3567,
435,
298,
4782,
1103,
3887,
13,
889,
12283,
17,
14,
4524,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
3887,
63,
4219,
9,
272,
4353,
14,
3887,
63,
17520,
4033,
275,
26418,
14,
3717,
4259,
8,
88,
12,
89,
11,
708,
12,
6708,
12,
708,
2584,
420,
481,
12958,
4033,
297,
12826,
3567,
435,
298,
4782,
1103,
3887,
13,
12283,
17,
14,
4524,
401,
12826,
3567,
435,
298,
4782,
1103,
3887,
13,
889,
12283,
17
] |
[
199,
3,
199,
3,
20721,
13,
56,
16527,
513,
7042,
199,
3,
199,
31635,
199,
199,
31635,
199,
3,
199,
3,
28337,
14,
647,
26,
199,
3,
961,
570,
14404,
314,
17160,
4008,
641,
314,
2446,
6426,
14,
199,
31635,
199,
199,
504,
1059,
492,
627,
199,
646,
984,
12,
747,
14,
515,
199,
646,
4011,
199,
646,
4011,
18,
199,
646,
295,
12,
2196,
12,
1059,
199,
646,
11709,
12,
26418,
12,
11709,
9291,
199,
646,
295,
12,
747,
12,
900,
12,
2197,
12,
5190,
199,
646,
6047,
12,
6047,
1173,
199,
646,
5145,
199,
646,
10392,
199,
646,
2838,
199,
504,
2202,
492,
627,
199,
199,
893,
26,
662,
3703,
1958,
275,
26418,
14,
37,
3703,
1958,
199,
2590,
26,
662,
3703,
1958,
275,
756,
199,
199,
9291,
275,
11709,
9291,
14,
19654,
8,
344,
534,
1579,
14,
15595,
13,
88,
358,
199,
6405,
3567,
275,
13553,
14,
362,
19654,
2354,
360,
515,
358,
199,
199,
692,
12826,
3567,
1988,
17,
22954,
6015,
12826,
3567,
29,
6405,
3567,
59,
16,
6809,
17,
61,
199,
692,
12826,
3567,
1988,
17,
61,
27909,
1103,
356,
12826,
3567,
29,
6405,
3567,
4786,
1103,
7,
199,
1569,
3567,
275,
12826,
3567,
435,
9926,
4782,
15022,
199,
1637,
3567,
275,
12826,
3567,
435,
9926,
1637,
15022,
199,
1569,
4437,
3567,
275,
12826,
3567,
435,
9926,
1637,
1103,
1569,
1345,
15022,
199,
1579,
3567,
275,
298,
49,
18589,
6429,
15022,
199,
1662,
3514,
3640,
3567,
275,
12826,
3567,
435,
298,
5713,
13392,
3640,
15022,
199,
826,
3567,
275,
12826,
3567,
435,
9926,
826,
15022,
199,
199,
18022,
199,
3,
11994,
26,
17813,
83,
1006,
11114,
641,
314,
6426,
5309,
1343,
13,
384,
199,
3,
3897,
520,
4353,
26,
2429,
370,
314,
2446,
4353,
199,
3,
1432,
258,
520,
446,
199,
18022,
199,
318,
2248,
63,
16409,
8,
3806,
304,
272,
327,
7451,
1834,
339,
4353,
14,
6856,
275,
26418,
14,
3717,
3491,
8,
16,
12,
16,
12,
18386,
12,
12255,
12,
1834,
3567,
435,
298,
7451,
14,
4524,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
6856,
9,
339,
4353,
14,
6856,
17,
275,
26418,
14,
3717,
3491,
8,
16,
12,
16,
12,
18386,
12,
12255,
12,
1834,
3567,
435,
298,
7451,
14,
4524,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
6856,
17,
9,
2286,
327,
19617,
13,
56,
23623,
737,
2746,
13,
1019,
3421,
272,
4353,
14,
9733,
275,
26418,
14,
3717,
3491,
8,
31504,
12,
1165,
12,
1257,
12,
1257,
12,
1834,
3567,
435,
298,
9733,
14,
4524,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
9733,
9,
339,
327,
751,
23623,
5084,
314,
15766,
272,
4353,
14,
751,
63,
9733,
275,
26418,
14,
3717,
3491,
8,
708,
12,
6708,
12,
12725,
12,
10419,
12,
1834,
3567,
435,
298,
9733,
14,
4524,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
751,
63,
9733,
9,
272,
4353,
14,
751,
63,
9733,
14,
32232,
8,
16,
9,
15567,
327,
751,
21541,
5084,
314,
15766,
334,
20798,
543,
314,
922,
23623,
9,
272,
4353,
14,
751,
63,
16534,
275,
26418,
14,
3717,
3491,
8,
708,
12,
6708,
12,
12725,
12,
10419,
12,
1834,
3567,
435,
298,
9733,
14,
4524,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
751,
63,
16534,
9,
272,
4353,
14,
751,
63,
16534,
14,
32232,
8,
16,
9,
2286,
327,
2632,
1768,
737,
2746,
13,
4218,
3421,
272,
4353,
14,
633,
18842,
275,
26418,
14,
3717,
4314,
8,
2167,
12,
1257,
12,
13595,
12,
2167,
12,
4873,
298,
4246,
1079,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
633,
18842,
9,
339,
327,
19617,
13,
56,
3394,
1768,
737,
2746,
13,
3039,
3421,
272,
4353,
14,
1023,
275,
26418,
14,
3717,
4314,
8,
2167,
12,
1165,
12,
11520,
12,
2167,
12,
283,
1023,
26,
6681,
3394,
11,
7815,
435,
4804,
3353,
12,
298,
4246,
1079,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
1023,
9,
755,
2286,
20383,
19236,
11500,
1318,
737,
3224,
13,
3039,
5366,
272,
4353,
14,
815,
266,
75,
270,
275,
26418,
14,
3717,
4314,
8,
1257,
12,
5783,
12,
7991,
12,
1216,
12,
298,
19236,
12594,
272,
4353,
14,
525,
3717,
8,
3806,
14,
815,
266,
75,
270,
9,
272,
4353,
14,
815,
266,
75,
270,
14,
32232,
8,
16,
9,
339,
20383,
8254,
3618,
11500,
1318,
9080,
641,
2746,
402,
314,
2446,
769,
272,
4353,
14,
8786,
275,
26418,
14,
3717,
4314,
8,
18520,
12,
21334,
12,
16074,
12,
4233,
12,
298,
8254,
3618,
12594,
272,
4353,
14,
525,
3717,
8,
3806,
14,
8786,
9,
272,
4353,
14,
8786,
14,
32232,
8,
16,
9,
2286,
327,
973,
769,
20589,
13210,
4811,
272,
4353,
14,
513,
275,
26418,
14,
3717,
1296,
8,
13085,
12,
6708,
12,
24223,
12,
14162,
2584,
4246,
1079,
1673,
16,
9039,
5745,
5745,
5745,
297,
5528,
17310,
17165,
29,
6405,
3567,
4786,
4782,
1103,
513,
13,
12283,
14,
4524,
297,
1834,
6216,
29,
708,
12,
1834,
8436,
29,
708,
12,
1242,
8436,
29,
1703,
9,
272,
4353,
14,
525,
3717,
8,
3806,
14,
513,
9,
272,
4353,
14,
513,
14,
409,
3276,
3717,
14917,
8,
797,
9,
339,
327,
513,
3920,
3421,
1768,
9080,
737,
314,
9048,
2451,
402,
314,
6426,
272,
4353,
14,
513,
1712,
275,
26418,
14,
3717,
4314,
8,
12021,
12,
17814,
12,
7991,
12,
1216,
12,
6899,
272,
4353,
14,
525,
3717,
8,
3806,
14,
513,
1712,
9,
2286,
327,
15687,
7143,
272,
671,
29,
1400,
272,
612,
29,
11810,
272,
4353,
14,
3887,
63,
4219,
275,
26418,
14,
3717,
4259,
8,
88,
12,
89,
12,
6708,
12,
708,
2584,
420,
14621,
297,
12826,
3567,
435,
298,
4782,
1103,
3887,
13,
12283,
17,
14,
4524,
401,
12826,
3567,
435,
298,
4782,
1103,
3887,
13,
889,
12283,
17,
14,
4524,
531,
272,
4353,
14,
525,
3717,
8,
3806,
14,
3887,
63,
4219,
9,
272,
4353,
14,
3887,
63,
17520,
4033,
275,
26418,
14,
3717,
4259,
8,
88,
12,
89,
11,
708,
12,
6708,
12,
708,
2584,
420,
481,
12958,
4033,
297,
12826,
3567,
435,
298,
4782,
1103,
3887,
13,
12283,
17,
14,
4524,
401,
12826,
3567,
435,
298,
4782,
1103,
3887,
13,
889,
12283,
17,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
alxmrtnz/portfolio2015
|
.bundle/gems/pygments.rb-0.6.1/vendor/simplejson/setup.py
|
34
|
2959
|
#!/usr/bin/env python
import sys
from distutils.core import setup, Extension, Command
from distutils.command.build_ext import build_ext
from distutils.errors import CCompilerError, DistutilsExecError, \
DistutilsPlatformError
IS_PYPY = hasattr(sys, 'pypy_translation_info')
VERSION = '2.6.0'
DESCRIPTION = "Simple, fast, extensible JSON encoder/decoder for Python"
LONG_DESCRIPTION = open('README.rst', 'r').read()
CLASSIFIERS = filter(None, map(str.strip,
"""
Intended Audience :: Developers
License :: OSI Approved :: MIT License
Programming Language :: Python
Topic :: Software Development :: Libraries :: Python Modules
""".splitlines()))
if sys.platform == 'win32' and sys.version_info > (2, 6):
# 2.6's distutils.msvc9compiler can raise an IOError when failing to
# find the compiler
ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError,
IOError)
else:
ext_errors = (CCompilerError, DistutilsExecError, DistutilsPlatformError)
class BuildFailed(Exception):
pass
class ve_build_ext(build_ext):
# This class allows C extension building to fail.
def run(self):
try:
build_ext.run(self)
except DistutilsPlatformError, x:
raise BuildFailed()
def build_extension(self, ext):
try:
build_ext.build_extension(self, ext)
except ext_errors, x:
raise BuildFailed()
class TestCommand(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
import sys, subprocess
raise SystemExit(
subprocess.call([sys.executable, 'simplejson/tests/__init__.py']))
def run_setup(with_binary):
cmdclass = dict(test=TestCommand)
if with_binary:
kw = dict(
ext_modules = [
Extension("simplejson._speedups", ["simplejson/_speedups.c"]),
],
cmdclass=dict(cmdclass, build_ext=ve_build_ext),
)
else:
kw = dict(cmdclass=cmdclass)
setup(
name="simplejson",
version=VERSION,
description=DESCRIPTION,
long_description=LONG_DESCRIPTION,
classifiers=CLASSIFIERS,
author="Bob Ippolito",
author_email="bob@redivi.com",
url="http://github.com/simplejson/simplejson",
license="MIT License",
packages=['simplejson', 'simplejson.tests'],
platforms=['any'],
**kw)
try:
run_setup(not IS_PYPY)
except BuildFailed:
BUILD_EXT_WARNING = "WARNING: The C extension could not be compiled, speedups are not enabled."
print '*' * 75
print BUILD_EXT_WARNING
print "Failure information, if any, is above."
print "I'm retrying the build without the C extension now."
print '*' * 75
run_setup(False)
print '*' * 75
print BUILD_EXT_WARNING
print "Plain-Python installation succeeded."
print '*' * 75
|
mit
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
984,
199,
504,
7065,
14,
1018,
492,
3272,
12,
13282,
12,
5817,
199,
504,
7065,
14,
1531,
14,
1506,
63,
832,
492,
1900,
63,
832,
199,
504,
7065,
14,
2550,
492,
445,
9131,
547,
12,
12577,
4858,
547,
12,
971,
272,
12577,
10397,
547,
199,
199,
1311,
63,
4521,
4521,
275,
2688,
8,
1274,
12,
283,
20233,
63,
6893,
63,
815,
358,
199,
4612,
275,
283,
18,
14,
22,
14,
16,
7,
199,
17705,
275,
298,
3184,
12,
7377,
12,
2178,
1164,
4840,
10295,
15,
8813,
367,
2018,
2,
199,
12375,
63,
17705,
275,
1551,
360,
18195,
14,
8332,
297,
283,
82,
1959,
739,
342,
199,
199,
31163,
1976,
3960,
275,
2457,
8,
403,
12,
2341,
8,
495,
14,
1913,
12,
199,
624,
199,
23910,
23975,
3800,
23493,
199,
3761,
3800,
25718,
26330,
3800,
10697,
844,
199,
11411,
8466,
3800,
2018,
199,
12157,
3800,
2290,
15290,
3800,
31454,
3800,
2018,
18167,
199,
23045,
7644,
4059,
199,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
7,
436,
984,
14,
1023,
63,
815,
690,
334,
18,
12,
1227,
304,
2043,
327,
499,
14,
22,
1159,
7065,
14,
19875,
25,
5772,
883,
746,
376,
5925,
1380,
18648,
370,
2043,
327,
2342,
314,
6365,
2043,
1599,
63,
2550,
275,
334,
30926,
547,
12,
12577,
4858,
547,
12,
12577,
10397,
547,
12,
326,
5925,
9,
199,
2836,
26,
2043,
1599,
63,
2550,
275,
334,
30926,
547,
12,
12577,
4858,
547,
12,
12577,
10397,
547,
9,
199,
199,
533,
6516,
4276,
8,
1726,
304,
272,
986,
199,
199,
533,
11199,
63,
1506,
63,
832,
8,
1506,
63,
832,
304,
272,
327,
961,
1021,
6127,
445,
3329,
10015,
370,
2449,
14,
339,
347,
1255,
8,
277,
304,
267,
862,
26,
288,
1900,
63,
832,
14,
1065,
8,
277,
9,
267,
871,
12577,
10397,
547,
12,
671,
26,
288,
746,
6516,
4276,
342,
339,
347,
1900,
63,
3435,
8,
277,
12,
1599,
304,
267,
862,
26,
288,
1900,
63,
832,
14,
1506,
63,
3435,
8,
277,
12,
1599,
9,
267,
871,
1599,
63,
2550,
12,
671,
26,
288,
746,
6516,
4276,
342,
421,
199,
533,
1379,
3110,
8,
3110,
304,
272,
922,
63,
1419,
275,
942,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
986,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
986,
339,
347,
1255,
8,
277,
304,
267,
492,
984,
12,
3873,
267,
746,
14838,
8,
288,
3873,
14,
1250,
779,
1274,
14,
5904,
12,
283,
4129,
1001,
15,
2219,
22128,
826,
4343,
647,
5156,
199,
199,
318,
1255,
63,
2758,
8,
1045,
63,
3008,
304,
272,
2088,
533,
275,
1211,
8,
396,
29,
774,
3110,
9,
272,
340,
543,
63,
3008,
26,
267,
4775,
275,
1211,
8,
288,
1599,
63,
3112,
275,
359,
355,
13282,
480,
4129,
1001,
423,
7625,
15203,
401,
2097,
4129,
1001,
15607,
7625,
15203,
14,
67,
10252,
288,
2156,
288,
2088,
533,
29,
807,
8,
1760,
533,
12,
1900,
63,
832,
29,
432,
63,
1506,
63,
832,
395,
267,
776,
272,
587,
26,
267,
4775,
275,
1211,
8,
1760,
533,
29,
1760,
533,
9,
339,
3272,
8,
267,
536,
628,
4129,
1001,
401,
267,
1015,
29,
4612,
12,
267,
1369,
29,
17705,
12,
267,
1846,
63,
1802,
29,
12375,
63,
17705,
12,
267,
19137,
29,
31163,
1976,
3960,
12,
267,
4132,
628,
22593,
31045,
555,
317,
475,
401,
267,
4132,
63,
2123,
628,
7913,
32,
264,
328,
433,
14,
957,
401,
267,
1166,
628,
1014,
921,
5031,
14,
957,
15,
4129,
1001,
15,
4129,
1001,
401,
267,
4190,
628,
13965,
844,
401,
267,
6117,
2968,
4129,
1001,
297,
283,
4129,
1001,
14,
2219,
995,
267,
10677,
2968,
1629,
995,
267,
1011,
829,
9,
199,
199,
893,
26,
272,
1255,
63,
2758,
8,
1397,
2281,
63,
4521,
4521,
9,
199,
2590,
6516,
4276,
26,
272,
22974,
63,
2472,
63,
9171,
275,
298,
9171,
26,
710,
445,
3329,
4293,
440,
506,
10311,
12,
8112,
15203,
787,
440,
5223,
2122,
272,
870,
13626,
627,
13098,
272,
870,
22974,
63,
2472,
63,
9171,
272,
870,
298,
6782,
2556,
12,
340,
1263,
12,
365,
3432,
2122,
272,
870,
298,
41,
6704,
7269,
316,
314,
1900,
1928,
314,
445,
3329,
3063,
2122,
272,
870,
13626,
627,
13098,
339,
1255,
63,
2758,
8,
797,
9,
339,
870,
13626,
627,
13098,
272,
870,
22974,
63,
2472,
63,
9171,
272,
870,
298,
20711,
13,
4718,
12096,
19268,
2122,
272,
870,
13626,
627,
13098,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
646,
984,
199,
504,
7065,
14,
1018,
492,
3272,
12,
13282,
12,
5817,
199,
504,
7065,
14,
1531,
14,
1506,
63,
832,
492,
1900,
63,
832,
199,
504,
7065,
14,
2550,
492,
445,
9131,
547,
12,
12577,
4858,
547,
12,
971,
272,
12577,
10397,
547,
199,
199,
1311,
63,
4521,
4521,
275,
2688,
8,
1274,
12,
283,
20233,
63,
6893,
63,
815,
358,
199,
4612,
275,
283,
18,
14,
22,
14,
16,
7,
199,
17705,
275,
298,
3184,
12,
7377,
12,
2178,
1164,
4840,
10295,
15,
8813,
367,
2018,
2,
199,
12375,
63,
17705,
275,
1551,
360,
18195,
14,
8332,
297,
283,
82,
1959,
739,
342,
199,
199,
31163,
1976,
3960,
275,
2457,
8,
403,
12,
2341,
8,
495,
14,
1913,
12,
199,
624,
199,
23910,
23975,
3800,
23493,
199,
3761,
3800,
25718,
26330,
3800,
10697,
844,
199,
11411,
8466,
3800,
2018,
199,
12157,
3800,
2290,
15290,
3800,
31454,
3800,
2018,
18167,
199,
23045,
7644,
4059,
199,
199,
692,
984,
14,
3246,
508,
283,
2676,
708,
7,
436,
984,
14,
1023,
63,
815,
690,
334,
18,
12,
1227,
304,
2043,
327,
499,
14,
22,
1159,
7065,
14,
19875,
25,
5772,
883,
746,
376,
5925,
1380,
18648,
370,
2043,
327,
2342,
314,
6365,
2043,
1599,
63,
2550,
275,
334,
30926,
547,
12,
12577,
4858,
547,
12,
12577,
10397,
547,
12,
326,
5925,
9,
199,
2836,
26,
2043,
1599,
63,
2550,
275,
334,
30926,
547,
12,
12577,
4858,
547,
12,
12577,
10397,
547,
9,
199,
199,
533,
6516,
4276,
8,
1726,
304,
272,
986,
199,
199,
533,
11199,
63,
1506,
63,
832,
8,
1506,
63,
832,
304,
272,
327,
961,
1021,
6127,
445,
3329,
10015,
370,
2449,
14,
339,
347,
1255,
8,
277,
304,
267,
862,
26,
288,
1900,
63,
832,
14,
1065,
8,
277,
9,
267,
871,
12577,
10397,
547,
12,
671,
26,
288,
746,
6516,
4276,
342,
339,
347,
1900,
63,
3435,
8,
277,
12,
1599,
304,
267,
862,
26,
288,
1900,
63,
832,
14,
1506,
63,
3435,
8,
277,
12,
1599,
9,
267,
871,
1599,
63,
2550,
12,
671,
26,
288,
746,
6516,
4276,
342,
421,
199,
533,
1379,
3110,
8,
3110,
304,
272,
922,
63,
1419,
275,
942,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
986,
339,
347,
17284,
63,
1419,
8,
277,
304,
267,
986,
339,
347,
1255,
8,
277,
304,
267,
492,
984,
12,
3873,
267,
746,
14838,
8,
288,
3873,
14,
1250,
779,
1274,
14,
5904,
12,
283,
4129,
1001,
15,
2219,
22128,
826,
4343,
647,
5156,
199,
199,
318,
1255,
63,
2758,
8,
1045,
63,
3008,
304,
272,
2088,
533,
275,
1211,
8,
396,
29,
774,
3110,
9,
272,
340,
543,
63,
3008,
26,
267,
4775,
275,
1211,
8,
288,
1599,
63,
3112,
275,
359,
355,
13282,
480,
4129,
1001,
423,
7625,
15203,
401,
2097,
4129,
1001,
15607,
7625,
15203,
14,
67,
10252,
288,
2156,
288,
2088,
533,
29,
807,
8,
1760,
533,
12,
1900,
63,
832,
29,
432,
63,
1506,
63,
832,
395,
267,
776,
272,
587,
26,
267,
4775,
275,
1211,
8,
1760,
533,
29,
1760,
533,
9,
339,
3272,
8,
267,
536,
628,
4129,
1001,
401,
267,
1015,
29,
4612,
12,
267,
1369,
29,
17705,
12,
267,
1846,
63,
1802,
29,
12375,
63,
17705,
12,
267,
19137,
29,
31163,
1976,
3960,
12,
267,
4132,
628,
22593,
31045,
555,
317,
475,
401,
267,
4132,
63,
2123,
628,
7913,
32,
264,
328,
433,
14,
957,
401,
267,
1166,
628,
1014,
921,
5031,
14,
957,
15,
4129,
1001,
15,
4129,
1001,
401,
267,
4190,
628,
13965,
844,
401,
267,
6117,
2968,
4129,
1001,
297,
283,
4129,
1001,
14,
2219,
995,
267,
10677,
2968,
1629,
995,
267,
1011,
829,
9,
199,
199,
893,
26,
272,
1255,
63,
2758,
8,
1397,
2281,
63,
4521,
4521,
9,
199,
2590,
6516,
4276,
26,
272,
22974,
63,
2472,
63,
9171,
275,
298,
9171,
26,
710,
445,
3329,
4293,
440,
506,
10311,
12,
8112,
15203,
787,
440,
5223,
2122,
272,
870,
13626,
627,
13098,
272,
870,
22974,
63,
2472,
63,
9171,
272,
870,
298,
6782,
2556,
12,
340,
1263,
12,
365,
3432,
2122,
272,
870,
298,
41,
6704,
7269,
316,
314,
1900,
1928,
314,
445,
3329,
3063,
2122,
272,
870,
13626,
627,
13098,
339,
1255,
63,
2758,
8,
797,
9,
339,
870,
13626,
627,
13098,
272,
870,
22974,
63,
2472,
63,
9171,
272,
870,
298,
20711,
13,
4718,
12096,
19268,
2122,
272,
870,
13626,
627,
13098,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
Lujeni/ansible
|
lib/ansible/modules/monitoring/logicmonitor.py
|
21
|
73790
|
#!/usr/bin/python
# LogicMonitor Ansible module for managing Collectors, Hosts and Hostgroups
# Copyright (C) 2015 LogicMonitor
# 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
RETURN = '''
---
success:
description: flag indicating that execution was successful
returned: success
type: bool
sample: True
...
'''
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
---
module: logicmonitor
short_description: Manage your LogicMonitor account through Ansible Playbooks
description:
- LogicMonitor is a hosted, full-stack, infrastructure monitoring platform.
- This module manages hosts, host groups, and collectors within your LogicMonitor account.
version_added: "2.2"
author:
- Ethan Culler-Mayeno (@ethanculler)
- Jeff Wozniak (@woz5999)
notes:
- You must have an existing LogicMonitor account for this module to function.
requirements: ["An existing LogicMonitor account", "Linux"]
options:
target:
description:
- The type of LogicMonitor object you wish to manage.
- "Collector: Perform actions on a LogicMonitor collector."
- NOTE You should use Ansible service modules such as M(service) or M(supervisorctl) for managing the Collector 'logicmonitor-agent' and
'logicmonitor-watchdog' services. Specifically, you'll probably want to start these services after a Collector add and stop these services
before a Collector remove.
- "Host: Perform actions on a host device."
- "Hostgroup: Perform actions on a LogicMonitor host group."
- >
NOTE Host and Hostgroup tasks should always be performed via delegate_to: localhost. There are no benefits to running these tasks on the
remote host and doing so will typically cause problems.
required: true
choices: ['collector', 'host', 'datasource', 'hostgroup']
action:
description:
- The action you wish to perform on target.
- "Add: Add an object to your LogicMonitor account."
- "Remove: Remove an object from your LogicMonitor account."
- "Update: Update properties, description, or groups (target=host) for an object in your LogicMonitor account."
- "SDT: Schedule downtime for an object in your LogicMonitor account."
required: true
choices: ['add', 'remove', 'update', 'sdt']
company:
description:
- The LogicMonitor account company name. If you would log in to your account at "superheroes.logicmonitor.com" you would use "superheroes."
required: true
user:
description:
- A LogicMonitor user name. The module will authenticate and perform actions on behalf of this user.
required: true
password:
description:
- The password of the specified LogicMonitor user
required: true
collector:
description:
- The fully qualified domain name of a collector in your LogicMonitor account.
- This is required for the creation of a LogicMonitor host (target=host action=add).
- This is required for updating, removing or scheduling downtime for hosts if 'displayname' isn't
specified (target=host action=update action=remove action=sdt).
hostname:
description:
- The hostname of a host in your LogicMonitor account, or the desired hostname of a device to manage.
- Optional for managing hosts (target=host).
default: 'hostname -f'
displayname:
description:
- The display name of a host in your LogicMonitor account or the desired display name of a device to manage.
- Optional for managing hosts (target=host).
default: 'hostname -f'
description:
description:
- The long text description of the object in your LogicMonitor account.
- Optional for managing hosts and host groups (target=host or target=hostgroup; action=add or action=update).
default: ""
properties:
description:
- A dictionary of properties to set on the LogicMonitor host or host group.
- Optional for managing hosts and host groups (target=host or target=hostgroup; action=add or action=update).
- This parameter will add or update existing properties in your LogicMonitor account.
default: {}
groups:
description:
- A list of groups that the host should be a member of.
- Optional for managing hosts (target=host; action=add or action=update).
default: []
id:
description:
- ID of the datasource to target.
- Required for management of LogicMonitor datasources (target=datasource).
fullpath:
description:
- The fullpath of the host group object you would like to manage.
- Recommend running on a single Ansible host.
- Required for management of LogicMonitor host groups (target=hostgroup).
alertenable:
description:
- A boolean flag to turn alerting on or off for an object.
- Optional for managing all hosts (action=add or action=update).
type: bool
default: 'yes'
starttime:
description:
- The time that the Scheduled Down Time (SDT) should begin.
- Optional for managing SDT (action=sdt).
- Y-m-d H:M
default: Now
duration:
description:
- The duration (minutes) of the Scheduled Down Time (SDT).
- Optional for putting an object into SDT (action=sdt).
default: 30
...
'''
EXAMPLES = '''
# example of adding a new LogicMonitor collector to these devices
---
- hosts: collectors
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: Deploy/verify LogicMonitor collectors
become: yes
logicmonitor:
target: collector
action: add
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
#example of adding a list of hosts into monitoring
---
- hosts: hosts
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: Deploy LogicMonitor Host
# All tasks except for target=collector should use delegate_to: localhost
logicmonitor:
target: host
action: add
collector: mycompany-Collector
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
groups: /servers/production,/datacenter1
properties:
snmp.community: secret
dc: 1
type: prod
delegate_to: localhost
#example of putting a datasource in SDT
---
- hosts: localhost
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: SDT a datasource
# All tasks except for target=collector should use delegate_to: localhost
logicmonitor:
target: datasource
action: sdt
id: 123
duration: 3000
starttime: '2017-03-04 05:06'
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
#example of creating a hostgroup
---
- hosts: localhost
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: Create a host group
# All tasks except for target=collector should use delegate_to: localhost
logicmonitor:
target: hostgroup
action: add
fullpath: /servers/development
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
properties:
snmp.community: commstring
type: dev
#example of putting a list of hosts into SDT
---
- hosts: hosts
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: SDT hosts
# All tasks except for target=collector should use delegate_to: localhost
logicmonitor:
target: host
action: sdt
duration: 3000
starttime: '2016-11-10 09:08'
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
collector: mycompany-Collector
delegate_to: localhost
#example of putting a host group in SDT
---
- hosts: localhost
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: SDT a host group
# All tasks except for target=collector should use delegate_to: localhost
logicmonitor:
target: hostgroup
action: sdt
fullpath: /servers/development
duration: 3000
starttime: '2017-03-04 05:06'
company=: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
#example of updating a list of hosts
---
- hosts: hosts
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: Update a list of hosts
# All tasks except for target=collector should use delegate_to: localhost
logicmonitor:
target: host
action: update
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
collector: mycompany-Collector
groups: /servers/production,/datacenter5
properties:
snmp.community: commstring
dc: 5
delegate_to: localhost
#example of updating a hostgroup
---
- hosts: hosts
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: Update a host group
# All tasks except for target=collector should use delegate_to: localhost
logicmonitor:
target: hostgroup
action: update
fullpath: /servers/development
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
properties:
snmp.community: hg
type: dev
status: test
delegate_to: localhost
#example of removing a list of hosts from monitoring
---
- hosts: hosts
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: Remove LogicMonitor hosts
# All tasks except for target=collector should use delegate_to: localhost
logicmonitor:
target: host
action: remove
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
collector: mycompany-Collector
delegate_to: localhost
#example of removing a host group
---
- hosts: hosts
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: Remove LogicMonitor development servers hostgroup
# All tasks except for target=collector should use delegate_to: localhost
logicmonitor:
target: hostgroup
action: remove
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
fullpath: /servers/development
delegate_to: localhost
- name: Remove LogicMonitor servers hostgroup
# All tasks except for target=collector should use delegate_to: localhost
logicmonitor:
target: hostgroup
action: remove
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
fullpath: /servers
delegate_to: localhost
- name: Remove LogicMonitor datacenter1 hostgroup
# All tasks except for target=collector should use delegate_to: localhost
logicmonitor:
target: hostgroup
action: remove
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
fullpath: /datacenter1
delegate_to: localhost
- name: Remove LogicMonitor datacenter5 hostgroup
# All tasks except for target=collector should use delegate_to: localhost
logicmonitor:
target: hostgroup
action: remove
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
fullpath: /datacenter5
delegate_to: localhost
### example of removing a new LogicMonitor collector to these devices
---
- hosts: collectors
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: Remove LogicMonitor collectors
become: yes
logicmonitor:
target: collector
action: remove
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
#complete example
---
- hosts: localhost
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: Create a host group
logicmonitor:
target: hostgroup
action: add
fullpath: /servers/production/database
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
properties:
snmp.community: commstring
- name: SDT a host group
logicmonitor:
target: hostgroup
action: sdt
fullpath: /servers/production/web
duration: 3000
starttime: '2012-03-04 05:06'
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
- hosts: collectors
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: Deploy/verify LogicMonitor collectors
logicmonitor:
target: collector
action: add
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
- name: Place LogicMonitor collectors into 30 minute Scheduled downtime
logicmonitor:
target: collector
action: sdt
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
- name: Deploy LogicMonitor Host
logicmonitor:
target: host
action: add
collector: agent1.ethandev.com
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
properties:
snmp.community: commstring
dc: 1
groups: /servers/production/collectors, /datacenter1
delegate_to: localhost
- hosts: database-servers
remote_user: '{{ username }}'
vars:
company: mycompany
user: myusername
password: mypassword
tasks:
- name: deploy logicmonitor hosts
logicmonitor:
target: host
action: add
collector: monitoring.dev.com
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
properties:
snmp.community: commstring
type: db
dc: 1
groups: /servers/production/database, /datacenter1
delegate_to: localhost
- name: schedule 5 hour downtime for 2012-11-10 09:08
logicmonitor:
target: host
action: sdt
duration: 3000
starttime: '2012-11-10 09:08'
company: '{{ company }}'
user: '{{ user }}'
password: '{{ password }}'
delegate_to: localhost
'''
import datetime
import json
import os
import platform
import socket
import sys
import types
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.six.moves.urllib.parse import urlencode
from ansible.module_utils.urls import open_url
class LogicMonitor(object):
def __init__(self, module, **params):
self.__version__ = "1.0-python"
self.module = module
self.module.debug("Instantiating LogicMonitor object")
self.check_mode = False
self.company = params["company"]
self.user = params["user"]
self.password = params["password"]
self.fqdn = socket.getfqdn()
self.lm_url = "logicmonitor.com/santaba"
self.__version__ = self.__version__ + "-ansible-module"
def rpc(self, action, params):
"""Make a call to the LogicMonitor RPC library
and return the response"""
self.module.debug("Running LogicMonitor.rpc")
param_str = urlencode(params)
creds = urlencode(
{"c": self.company,
"u": self.user,
"p": self.password})
if param_str:
param_str = param_str + "&"
param_str = param_str + creds
try:
url = ("https://" + self.company + "." + self.lm_url +
"/rpc/" + action + "?" + param_str)
# Set custom LogicMonitor header with version
headers = {"X-LM-User-Agent": self.__version__}
# Set headers
f = open_url(url, headers=headers)
raw = f.read()
resp = json.loads(raw)
if resp["status"] == 403:
self.module.debug("Authentication failed.")
self.fail(msg="Error: " + resp["errmsg"])
else:
return raw
except IOError as ioe:
self.fail(msg="Error: Exception making RPC call to " +
"https://" + self.company + "." + self.lm_url +
"/rpc/" + action + "\nException" + str(ioe))
def do(self, action, params):
"""Make a call to the LogicMonitor
server \"do\" function"""
self.module.debug("Running LogicMonitor.do...")
param_str = urlencode(params)
creds = (urlencode(
{"c": self.company,
"u": self.user,
"p": self.password}))
if param_str:
param_str = param_str + "&"
param_str = param_str + creds
try:
self.module.debug("Attempting to open URL: " +
"https://" + self.company + "." + self.lm_url +
"/do/" + action + "?" + param_str)
f = open_url(
"https://" + self.company + "." + self.lm_url +
"/do/" + action + "?" + param_str)
return f.read()
except IOError as ioe:
self.fail(msg="Error: Exception making RPC call to " +
"https://" + self.company + "." + self.lm_url +
"/do/" + action + "\nException" + str(ioe))
def get_collectors(self):
"""Returns a JSON object containing a list of
LogicMonitor collectors"""
self.module.debug("Running LogicMonitor.get_collectors...")
self.module.debug("Making RPC call to 'getAgents'")
resp = self.rpc("getAgents", {})
resp_json = json.loads(resp)
if resp_json["status"] == 200:
self.module.debug("RPC call succeeded")
return resp_json["data"]
else:
self.fail(msg=resp)
def get_host_by_hostname(self, hostname, collector):
"""Returns a host object for the host matching the
specified hostname"""
self.module.debug("Running LogicMonitor.get_host_by_hostname...")
self.module.debug("Looking for hostname " + hostname)
self.module.debug("Making RPC call to 'getHosts'")
hostlist_json = json.loads(self.rpc("getHosts", {"hostGroupId": 1}))
if collector:
if hostlist_json["status"] == 200:
self.module.debug("RPC call succeeded")
hosts = hostlist_json["data"]["hosts"]
self.module.debug(
"Looking for host matching: hostname " + hostname +
" and collector " + str(collector["id"]))
for host in hosts:
if (host["hostName"] == hostname and
host["agentId"] == collector["id"]):
self.module.debug("Host match found")
return host
self.module.debug("No host match found")
return None
else:
self.module.debug("RPC call failed")
self.module.debug(hostlist_json)
else:
self.module.debug("No collector specified")
return None
def get_host_by_displayname(self, displayname):
"""Returns a host object for the host matching the
specified display name"""
self.module.debug("Running LogicMonitor.get_host_by_displayname...")
self.module.debug("Looking for displayname " + displayname)
self.module.debug("Making RPC call to 'getHost'")
host_json = (json.loads(self.rpc("getHost",
{"displayName": displayname})))
if host_json["status"] == 200:
self.module.debug("RPC call succeeded")
return host_json["data"]
else:
self.module.debug("RPC call failed")
self.module.debug(host_json)
return None
def get_collector_by_description(self, description):
"""Returns a JSON collector object for the collector
matching the specified FQDN (description)"""
self.module.debug(
"Running LogicMonitor.get_collector_by_description..."
)
collector_list = self.get_collectors()
if collector_list is not None:
self.module.debug("Looking for collector with description {0}" +
description)
for collector in collector_list:
if collector["description"] == description:
self.module.debug("Collector match found")
return collector
self.module.debug("No collector match found")
return None
def get_group(self, fullpath):
"""Returns a JSON group object for the group matching the
specified path"""
self.module.debug("Running LogicMonitor.get_group...")
self.module.debug("Making RPC call to getHostGroups")
resp = json.loads(self.rpc("getHostGroups", {}))
if resp["status"] == 200:
self.module.debug("RPC called succeeded")
groups = resp["data"]
self.module.debug("Looking for group matching " + fullpath)
for group in groups:
if group["fullPath"] == fullpath.lstrip('/'):
self.module.debug("Group match found")
return group
self.module.debug("No group match found")
return None
else:
self.module.debug("RPC call failed")
self.module.debug(resp)
return None
def create_group(self, fullpath):
"""Recursively create a path of host groups.
Returns the id of the newly created hostgroup"""
self.module.debug("Running LogicMonitor.create_group...")
res = self.get_group(fullpath)
if res:
self.module.debug("Group {0} exists." + fullpath)
return res["id"]
if fullpath == "/":
self.module.debug("Specified group is root. Doing nothing.")
return 1
else:
self.module.debug("Creating group named " + fullpath)
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
parentpath, name = fullpath.rsplit('/', 1)
parentgroup = self.get_group(parentpath)
parentid = 1
if parentpath == "":
parentid = 1
elif parentgroup:
parentid = parentgroup["id"]
else:
parentid = self.create_group(parentpath)
h = None
# Determine if we're creating a group from host or hostgroup class
if hasattr(self, '_build_host_group_hash'):
h = self._build_host_group_hash(
fullpath,
self.description,
self.properties,
self.alertenable)
h["name"] = name
h["parentId"] = parentid
else:
h = {"name": name,
"parentId": parentid,
"alertEnable": True,
"description": ""}
self.module.debug("Making RPC call to 'addHostGroup'")
resp = json.loads(
self.rpc("addHostGroup", h))
if resp["status"] == 200:
self.module.debug("RPC call succeeded")
return resp["data"]["id"]
elif resp["errmsg"] == "The record already exists":
self.module.debug("The hostgroup already exists")
group = self.get_group(fullpath)
return group["id"]
else:
self.module.debug("RPC call failed")
self.fail(
msg="Error: unable to create new hostgroup \"" +
name + "\".\n" + resp["errmsg"])
def fail(self, msg):
self.module.fail_json(msg=msg, changed=self.change, failed=True)
def exit(self, changed):
self.module.debug("Changed: " + changed)
self.module.exit_json(changed=changed, success=True)
def output_info(self, info):
self.module.debug("Registering properties as Ansible facts")
self.module.exit_json(changed=False, ansible_facts=info)
class Collector(LogicMonitor):
def __init__(self, params, module=None):
"""Initializor for the LogicMonitor Collector object"""
self.change = False
self.params = params
LogicMonitor.__init__(self, module, **params)
self.module.debug("Instantiating Collector object")
if self.params['description']:
self.description = self.params['description']
else:
self.description = self.fqdn
self.info = self._get()
self.installdir = "/usr/local/logicmonitor"
self.platform = platform.system()
self.is_64bits = sys.maxsize > 2**32
self.duration = self.params['duration']
self.starttime = self.params['starttime']
if self.info is None:
self.id = None
else:
self.id = self.info["id"]
def create(self):
"""Idempotent function to make sure that there is
a running collector installed and registered"""
self.module.debug("Running Collector.create...")
self._create()
self.get_installer_binary()
self.install()
def remove(self):
"""Idempotent function to make sure that there is
not a running collector installed and registered"""
self.module.debug("Running Collector.destroy...")
self._unreigster()
self.uninstall()
def get_installer_binary(self):
"""Download the LogicMonitor collector installer binary"""
self.module.debug("Running Collector.get_installer_binary...")
arch = 32
if self.is_64bits:
self.module.debug("64 bit system")
arch = 64
else:
self.module.debug("32 bit system")
if self.platform == "Linux" and self.id is not None:
self.module.debug("Platform is Linux")
self.module.debug("Agent ID is " + str(self.id))
installfilepath = (self.installdir +
"/logicmonitorsetup" +
str(self.id) + "_" + str(arch) +
".bin")
self.module.debug("Looking for existing installer at " +
installfilepath)
if not os.path.isfile(installfilepath):
self.module.debug("No previous installer found")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
self.module.debug("Downloading installer file")
# attempt to create the install dir before download
self.module.run_command("mkdir " + self.installdir)
try:
installer = (self.do("logicmonitorsetup",
{"id": self.id,
"arch": arch}))
with open(installfilepath, "w") as write_file:
write_file.write(installer)
except Exception:
self.fail(msg="Unable to open installer file for writing")
else:
self.module.debug("Collector installer already exists")
return installfilepath
elif self.id is None:
self.fail(
msg="Error: There is currently no collector " +
"associated with this device. To download " +
" the installer, first create a collector " +
"for this device.")
elif self.platform != "Linux":
self.fail(
msg="Error: LogicMonitor Collector must be " +
"installed on a Linux device.")
else:
self.fail(
msg="Error: Unable to retrieve the installer from the server")
def install(self):
"""Execute the LogicMonitor installer if not
already installed"""
self.module.debug("Running Collector.install...")
if self.platform == "Linux":
self.module.debug("Platform is Linux")
installer = self.get_installer_binary()
if self.info is None:
self.module.debug("Retrieving collector information")
self.info = self._get()
if not os.path.exists(self.installdir + "/agent"):
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
self.module.debug("Setting installer file permissions")
os.chmod(installer, 484) # decimal for 0o744
self.module.debug("Executing installer")
ret_code, out, err = self.module.run_command(installer + " -y")
if ret_code != 0:
self.fail(msg="Error: Unable to install collector: " + err)
else:
self.module.debug("Collector installed successfully")
else:
self.module.debug("Collector already installed")
else:
self.fail(
msg="Error: LogicMonitor Collector must be " +
"installed on a Linux device")
def uninstall(self):
"""Uninstall LogicMontitor collector from the system"""
self.module.debug("Running Collector.uninstall...")
uninstallfile = self.installdir + "/agent/bin/uninstall.pl"
if os.path.isfile(uninstallfile):
self.module.debug("Collector uninstall file exists")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
self.module.debug("Running collector uninstaller")
ret_code, out, err = self.module.run_command(uninstallfile)
if ret_code != 0:
self.fail(
msg="Error: Unable to uninstall collector: " + err)
else:
self.module.debug("Collector successfully uninstalled")
else:
if os.path.exists(self.installdir + "/agent"):
(self.fail(
msg="Unable to uninstall LogicMonitor " +
"Collector. Can not find LogicMonitor " +
"uninstaller."))
def sdt(self):
"""Create a scheduled down time
(maintenance window) for this host"""
self.module.debug("Running Collector.sdt...")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
duration = self.duration
starttime = self.starttime
offsetstart = starttime
if starttime:
self.module.debug("Start time specified")
start = datetime.datetime.strptime(starttime, '%Y-%m-%d %H:%M')
offsetstart = start
else:
self.module.debug("No start time specified. Using default.")
start = datetime.datetime.utcnow()
# Use user UTC offset
self.module.debug("Making RPC call to 'getTimeZoneSetting'")
accountresp = json.loads(self.rpc("getTimeZoneSetting", {}))
if accountresp["status"] == 200:
self.module.debug("RPC call succeeded")
offset = accountresp["data"]["offset"]
offsetstart = start + datetime.timedelta(0, offset)
else:
self.fail(msg="Error: Unable to retrieve timezone offset")
offsetend = offsetstart + datetime.timedelta(0, int(duration) * 60)
h = {"agentId": self.id,
"type": 1,
"notifyCC": True,
"year": offsetstart.year,
"month": offsetstart.month - 1,
"day": offsetstart.day,
"hour": offsetstart.hour,
"minute": offsetstart.minute,
"endYear": offsetend.year,
"endMonth": offsetend.month - 1,
"endDay": offsetend.day,
"endHour": offsetend.hour,
"endMinute": offsetend.minute}
self.module.debug("Making RPC call to 'setAgentSDT'")
resp = json.loads(self.rpc("setAgentSDT", h))
if resp["status"] == 200:
self.module.debug("RPC call succeeded")
return resp["data"]
else:
self.module.debug("RPC call failed")
self.fail(msg=resp["errmsg"])
def site_facts(self):
"""Output current properties information for the Collector"""
self.module.debug("Running Collector.site_facts...")
if self.info:
self.module.debug("Collector exists")
props = self.get_properties(True)
self.output_info(props)
else:
self.fail(msg="Error: Collector doesn't exit.")
def _get(self):
"""Returns a JSON object representing this collector"""
self.module.debug("Running Collector._get...")
collector_list = self.get_collectors()
if collector_list is not None:
self.module.debug("Collectors returned")
for collector in collector_list:
if collector["description"] == self.description:
return collector
else:
self.module.debug("No collectors returned")
return None
def _create(self):
"""Create a new collector in the associated
LogicMonitor account"""
self.module.debug("Running Collector._create...")
if self.platform == "Linux":
self.module.debug("Platform is Linux")
ret = self.info or self._get()
if ret is None:
self.change = True
self.module.debug("System changed")
if self.check_mode:
self.exit(changed=True)
h = {"autogen": True,
"description": self.description}
self.module.debug("Making RPC call to 'addAgent'")
create = (json.loads(self.rpc("addAgent", h)))
if create["status"] == 200:
self.module.debug("RPC call succeeded")
self.info = create["data"]
self.id = create["data"]["id"]
return create["data"]
else:
self.fail(msg=create["errmsg"])
else:
self.info = ret
self.id = ret["id"]
return ret
else:
self.fail(
msg="Error: LogicMonitor Collector must be " +
"installed on a Linux device.")
def _unreigster(self):
"""Delete this collector from the associated
LogicMonitor account"""
self.module.debug("Running Collector._unreigster...")
if self.info is None:
self.module.debug("Retrieving collector information")
self.info = self._get()
if self.info is not None:
self.module.debug("Collector found")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
self.module.debug("Making RPC call to 'deleteAgent'")
delete = json.loads(self.rpc("deleteAgent",
{"id": self.id}))
if delete["status"] == 200:
self.module.debug("RPC call succeeded")
return delete
else:
# The collector couldn't unregister. Start the service again
self.module.debug("Error unregistering collecting. " +
delete["errmsg"])
self.fail(msg=delete["errmsg"])
else:
self.module.debug("Collector not found")
return None
class Host(LogicMonitor):
def __init__(self, params, module=None):
"""Initializor for the LogicMonitor host object"""
self.change = False
self.params = params
self.collector = None
LogicMonitor.__init__(self, module, **self.params)
self.module.debug("Instantiating Host object")
if self.params["hostname"]:
self.module.debug("Hostname is " + self.params["hostname"])
self.hostname = self.params['hostname']
else:
self.module.debug("No hostname specified. Using " + self.fqdn)
self.hostname = self.fqdn
if self.params["displayname"]:
self.module.debug("Display name is " + self.params["displayname"])
self.displayname = self.params['displayname']
else:
self.module.debug("No display name specified. Using " + self.fqdn)
self.displayname = self.fqdn
# Attempt to host information via display name of host name
self.module.debug("Attempting to find host by displayname " +
self.displayname)
info = self.get_host_by_displayname(self.displayname)
if info is not None:
self.module.debug("Host found by displayname")
# Used the host information to grab the collector description
# if not provided
if (not hasattr(self.params, "collector") and
"agentDescription" in info):
self.module.debug("Setting collector from host response. " +
"Collector " + info["agentDescription"])
self.params["collector"] = info["agentDescription"]
else:
self.module.debug("Host not found by displayname")
# At this point, a valid collector description is required for success
# Check that the description exists or fail
if self.params["collector"]:
self.module.debug(
"Collector specified is " +
self.params["collector"]
)
self.collector = (self.get_collector_by_description(
self.params["collector"]))
else:
self.fail(msg="No collector specified.")
# If the host wasn't found via displayname, attempt by hostname
if info is None:
self.module.debug("Attempting to find host by hostname " +
self.hostname)
info = self.get_host_by_hostname(self.hostname, self.collector)
self.info = info
self.properties = self.params["properties"]
self.description = self.params["description"]
self.starttime = self.params["starttime"]
self.duration = self.params["duration"]
self.alertenable = self.params["alertenable"]
if self.params["groups"] is not None:
self.groups = self._strip_groups(self.params["groups"])
else:
self.groups = None
def create(self):
"""Idempotent function to create if missing,
update if changed, or skip"""
self.module.debug("Running Host.create...")
self.update()
def get_properties(self):
"""Returns a hash of the properties
associated with this LogicMonitor host"""
self.module.debug("Running Host.get_properties...")
if self.info:
self.module.debug("Making RPC call to 'getHostProperties'")
properties_json = (json.loads(self.rpc("getHostProperties",
{'hostId': self.info["id"],
"filterSystemProperties": True})))
if properties_json["status"] == 200:
self.module.debug("RPC call succeeded")
return properties_json["data"]
else:
self.module.debug("Error: there was an issue retrieving the " +
"host properties")
self.module.debug(properties_json["errmsg"])
self.fail(msg=properties_json["status"])
else:
self.module.debug(
"Unable to find LogicMonitor host which matches " +
self.displayname + " (" + self.hostname + ")"
)
return None
def set_properties(self, propertyhash):
"""update the host to have the properties
contained in the property hash"""
self.module.debug("Running Host.set_properties...")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
self.module.debug("Assigning property hash to host object")
self.properties = propertyhash
def add(self):
"""Add this device to monitoring
in your LogicMonitor account"""
self.module.debug("Running Host.add...")
if self.collector and not self.info:
self.module.debug("Host not registered. Registering.")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
h = self._build_host_hash(
self.hostname,
self.displayname,
self.collector,
self.description,
self.groups,
self.properties,
self.alertenable)
self.module.debug("Making RPC call to 'addHost'")
resp = json.loads(self.rpc("addHost", h))
if resp["status"] == 200:
self.module.debug("RPC call succeeded")
return resp["data"]
else:
self.module.debug("RPC call failed")
self.module.debug(resp)
return resp["errmsg"]
elif self.collector is None:
self.fail(msg="Specified collector doesn't exist")
else:
self.module.debug("Host already registered")
def update(self):
"""This method takes changes made to this host
and applies them to the corresponding host
in your LogicMonitor account."""
self.module.debug("Running Host.update...")
if self.info:
self.module.debug("Host already registered")
if self.is_changed():
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
h = (self._build_host_hash(
self.hostname,
self.displayname,
self.collector,
self.description,
self.groups,
self.properties,
self.alertenable))
h["id"] = self.info["id"]
h["opType"] = "replace"
self.module.debug("Making RPC call to 'updateHost'")
resp = json.loads(self.rpc("updateHost", h))
if resp["status"] == 200:
self.module.debug("RPC call succeeded")
else:
self.module.debug("RPC call failed")
self.fail(msg="Error: unable to update the host.")
else:
self.module.debug(
"Host properties match supplied properties. " +
"No changes to make."
)
return self.info
else:
self.module.debug("Host not registered. Registering")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
return self.add()
def remove(self):
"""Remove this host from your LogicMonitor account"""
self.module.debug("Running Host.remove...")
if self.info:
self.module.debug("Host registered")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
self.module.debug("Making RPC call to 'deleteHost'")
resp = json.loads(self.rpc("deleteHost",
{"hostId": self.info["id"],
"deleteFromSystem": True,
"hostGroupId": 1}))
if resp["status"] == 200:
self.module.debug(resp)
self.module.debug("RPC call succeeded")
return resp
else:
self.module.debug("RPC call failed")
self.module.debug(resp)
self.fail(msg=resp["errmsg"])
else:
self.module.debug("Host not registered")
def is_changed(self):
"""Return true if the host doesn't
match the LogicMonitor account"""
self.module.debug("Running Host.is_changed")
ignore = ['system.categories', 'snmp.version']
hostresp = self.get_host_by_displayname(self.displayname)
if hostresp is None:
hostresp = self.get_host_by_hostname(self.hostname, self.collector)
if hostresp:
self.module.debug("Comparing simple host properties")
if hostresp["alertEnable"] != self.alertenable:
return True
if hostresp["description"] != self.description:
return True
if hostresp["displayedAs"] != self.displayname:
return True
if (self.collector and
hasattr(self.collector, "id") and
hostresp["agentId"] != self.collector["id"]):
return True
self.module.debug("Comparing groups.")
if self._compare_groups(hostresp) is True:
return True
propresp = self.get_properties()
if propresp:
self.module.debug("Comparing properties.")
if self._compare_props(propresp, ignore) is True:
return True
else:
self.fail(
msg="Error: Unknown error retrieving host properties")
return False
else:
self.fail(msg="Error: Unknown error retrieving host information")
def sdt(self):
"""Create a scheduled down time
(maintenance window) for this host"""
self.module.debug("Running Host.sdt...")
if self.info:
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
duration = self.duration
starttime = self.starttime
offset = starttime
if starttime:
self.module.debug("Start time specified")
start = datetime.datetime.strptime(starttime, '%Y-%m-%d %H:%M')
offsetstart = start
else:
self.module.debug("No start time specified. Using default.")
start = datetime.datetime.utcnow()
# Use user UTC offset
self.module.debug("Making RPC call to 'getTimeZoneSetting'")
accountresp = (json.loads(self.rpc("getTimeZoneSetting", {})))
if accountresp["status"] == 200:
self.module.debug("RPC call succeeded")
offset = accountresp["data"]["offset"]
offsetstart = start + datetime.timedelta(0, offset)
else:
self.fail(
msg="Error: Unable to retrieve timezone offset")
offsetend = offsetstart + datetime.timedelta(0, int(duration) * 60)
h = {"hostId": self.info["id"],
"type": 1,
"year": offsetstart.year,
"month": offsetstart.month - 1,
"day": offsetstart.day,
"hour": offsetstart.hour,
"minute": offsetstart.minute,
"endYear": offsetend.year,
"endMonth": offsetend.month - 1,
"endDay": offsetend.day,
"endHour": offsetend.hour,
"endMinute": offsetend.minute}
self.module.debug("Making RPC call to 'setHostSDT'")
resp = (json.loads(self.rpc("setHostSDT", h)))
if resp["status"] == 200:
self.module.debug("RPC call succeeded")
return resp["data"]
else:
self.module.debug("RPC call failed")
self.fail(msg=resp["errmsg"])
else:
self.fail(msg="Error: Host doesn't exit.")
def site_facts(self):
"""Output current properties information for the Host"""
self.module.debug("Running Host.site_facts...")
if self.info:
self.module.debug("Host exists")
props = self.get_properties()
self.output_info(props)
else:
self.fail(msg="Error: Host doesn't exit.")
def _build_host_hash(self,
hostname,
displayname,
collector,
description,
groups,
properties,
alertenable):
"""Return a property formatted hash for the
creation of a host using the rpc function"""
self.module.debug("Running Host._build_host_hash...")
h = {}
h["hostName"] = hostname
h["displayedAs"] = displayname
h["alertEnable"] = alertenable
if collector:
self.module.debug("Collector property exists")
h["agentId"] = collector["id"]
else:
self.fail(
msg="Error: No collector found. Unable to build host hash.")
if description:
h["description"] = description
if groups is not None and groups is not []:
self.module.debug("Group property exists")
groupids = ""
for group in groups:
groupids = groupids + str(self.create_group(group)) + ","
h["hostGroupIds"] = groupids.rstrip(',')
if properties is not None and properties is not {}:
self.module.debug("Properties hash exists")
propnum = 0
for key, value in properties.items():
h["propName" + str(propnum)] = key
h["propValue" + str(propnum)] = value
propnum = propnum + 1
return h
def _verify_property(self, propname):
"""Check with LogicMonitor server to
verify property is unchanged"""
self.module.debug("Running Host._verify_property...")
if self.info:
self.module.debug("Host is registered")
if propname not in self.properties:
self.module.debug("Property " + propname + " does not exist")
return False
else:
self.module.debug("Property " + propname + " exists")
h = {"hostId": self.info["id"],
"propName0": propname,
"propValue0": self.properties[propname]}
self.module.debug("Making RCP call to 'verifyProperties'")
resp = json.loads(self.rpc('verifyProperties', h))
if resp["status"] == 200:
self.module.debug("RPC call succeeded")
return resp["data"]["match"]
else:
self.fail(
msg="Error: unable to get verification " +
"from server.\n%s" % resp["errmsg"])
else:
self.fail(
msg="Error: Host doesn't exist. Unable to verify properties")
def _compare_groups(self, hostresp):
"""Function to compare the host's current
groups against provided groups"""
self.module.debug("Running Host._compare_groups")
g = []
fullpathinids = hostresp["fullPathInIds"]
self.module.debug("Building list of groups")
for path in fullpathinids:
if path != []:
h = {'hostGroupId': path[-1]}
hgresp = json.loads(self.rpc("getHostGroup", h))
if (hgresp["status"] == 200 and
hgresp["data"]["appliesTo"] == ""):
g.append(path[-1])
if self.groups is not None:
self.module.debug("Comparing group lists")
for group in self.groups:
groupjson = self.get_group(group)
if groupjson is None:
self.module.debug("Group mismatch. No result.")
return True
elif groupjson['id'] not in g:
self.module.debug("Group mismatch. ID doesn't exist.")
return True
else:
g.remove(groupjson['id'])
if g != []:
self.module.debug("Group mismatch. New ID exists.")
return True
self.module.debug("Groups match")
def _compare_props(self, propresp, ignore):
"""Function to compare the host's current
properties against provided properties"""
self.module.debug("Running Host._compare_props...")
p = {}
self.module.debug("Creating list of properties")
for prop in propresp:
if prop["name"] not in ignore:
if ("*******" in prop["value"] and
self._verify_property(prop["name"])):
p[prop["name"]] = self.properties[prop["name"]]
else:
p[prop["name"]] = prop["value"]
self.module.debug("Comparing properties")
# Iterate provided properties and compare to received properties
for prop in self.properties:
if (prop not in p or
p[prop] != self.properties[prop]):
self.module.debug("Properties mismatch")
return True
self.module.debug("Properties match")
def _strip_groups(self, groups):
"""Function to strip whitespace from group list.
This function provides the user some flexibility when
formatting group arguments """
self.module.debug("Running Host._strip_groups...")
return map(lambda x: x.strip(), groups)
class Datasource(LogicMonitor):
def __init__(self, params, module=None):
"""Initializor for the LogicMonitor Datasource object"""
self.change = False
self.params = params
LogicMonitor.__init__(self, module, **params)
self.module.debug("Instantiating Datasource object")
self.id = self.params["id"]
self.starttime = self.params["starttime"]
self.duration = self.params["duration"]
def sdt(self):
"""Create a scheduled down time
(maintenance window) for this host"""
self.module.debug("Running Datasource.sdt...")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
duration = self.duration
starttime = self.starttime
offsetstart = starttime
if starttime:
self.module.debug("Start time specified")
start = datetime.datetime.strptime(starttime, '%Y-%m-%d %H:%M')
offsetstart = start
else:
self.module.debug("No start time specified. Using default.")
start = datetime.datetime.utcnow()
# Use user UTC offset
self.module.debug("Making RPC call to 'getTimeZoneSetting'")
accountresp = json.loads(self.rpc("getTimeZoneSetting", {}))
if accountresp["status"] == 200:
self.module.debug("RPC call succeeded")
offset = accountresp["data"]["offset"]
offsetstart = start + datetime.timedelta(0, offset)
else:
self.fail(msg="Error: Unable to retrieve timezone offset")
offsetend = offsetstart + datetime.timedelta(0, int(duration) * 60)
h = {"hostDataSourceId": self.id,
"type": 1,
"notifyCC": True,
"year": offsetstart.year,
"month": offsetstart.month - 1,
"day": offsetstart.day,
"hour": offsetstart.hour,
"minute": offsetstart.minute,
"endYear": offsetend.year,
"endMonth": offsetend.month - 1,
"endDay": offsetend.day,
"endHour": offsetend.hour,
"endMinute": offsetend.minute}
self.module.debug("Making RPC call to 'setHostDataSourceSDT'")
resp = json.loads(self.rpc("setHostDataSourceSDT", h))
if resp["status"] == 200:
self.module.debug("RPC call succeeded")
return resp["data"]
else:
self.module.debug("RPC call failed")
self.fail(msg=resp["errmsg"])
class Hostgroup(LogicMonitor):
def __init__(self, params, module=None):
"""Initializor for the LogicMonitor host object"""
self.change = False
self.params = params
LogicMonitor.__init__(self, module, **self.params)
self.module.debug("Instantiating Hostgroup object")
self.fullpath = self.params["fullpath"]
self.info = self.get_group(self.fullpath)
self.properties = self.params["properties"]
self.description = self.params["description"]
self.starttime = self.params["starttime"]
self.duration = self.params["duration"]
self.alertenable = self.params["alertenable"]
def create(self):
"""Wrapper for self.update()"""
self.module.debug("Running Hostgroup.create...")
self.update()
def get_properties(self, final=False):
"""Returns a hash of the properties
associated with this LogicMonitor host"""
self.module.debug("Running Hostgroup.get_properties...")
if self.info:
self.module.debug("Group found")
self.module.debug("Making RPC call to 'getHostGroupProperties'")
properties_json = json.loads(self.rpc(
"getHostGroupProperties",
{'hostGroupId': self.info["id"],
"finalResult": final}))
if properties_json["status"] == 200:
self.module.debug("RPC call succeeded")
return properties_json["data"]
else:
self.module.debug("RPC call failed")
self.fail(msg=properties_json["status"])
else:
self.module.debug("Group not found")
return None
def set_properties(self, propertyhash):
"""Update the host to have the properties
contained in the property hash"""
self.module.debug("Running Hostgroup.set_properties")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
self.module.debug("Assigning property has to host object")
self.properties = propertyhash
def add(self):
"""Idempotent function to ensure that the host
group exists in your LogicMonitor account"""
self.module.debug("Running Hostgroup.add")
if self.info is None:
self.module.debug("Group doesn't exist. Creating.")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
self.create_group(self.fullpath)
self.info = self.get_group(self.fullpath)
self.module.debug("Group created")
return self.info
else:
self.module.debug("Group already exists")
def update(self):
"""Idempotent function to ensure the host group settings
(alertenable, properties, etc) in the
LogicMonitor account match the current object."""
self.module.debug("Running Hostgroup.update")
if self.info:
if self.is_changed():
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
h = self._build_host_group_hash(
self.fullpath,
self.description,
self.properties,
self.alertenable)
h["opType"] = "replace"
if self.fullpath != "/":
h["id"] = self.info["id"]
self.module.debug("Making RPC call to 'updateHostGroup'")
resp = json.loads(self.rpc("updateHostGroup", h))
if resp["status"] == 200:
self.module.debug("RPC call succeeded")
return resp["data"]
else:
self.module.debug("RPC call failed")
self.fail(msg="Error: Unable to update the " +
"host.\n" + resp["errmsg"])
else:
self.module.debug(
"Group properties match supplied properties. " +
"No changes to make"
)
return self.info
else:
self.module.debug("Group doesn't exist. Creating.")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
return self.add()
def remove(self):
"""Idempotent function to ensure the host group
does not exist in your LogicMonitor account"""
self.module.debug("Running Hostgroup.remove...")
if self.info:
self.module.debug("Group exists")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
self.module.debug("Making RPC call to 'deleteHostGroup'")
resp = json.loads(self.rpc("deleteHostGroup",
{"hgId": self.info["id"]}))
if resp["status"] == 200:
self.module.debug(resp)
self.module.debug("RPC call succeeded")
return resp
elif resp["errmsg"] == "No such group":
self.module.debug("Group doesn't exist")
else:
self.module.debug("RPC call failed")
self.module.debug(resp)
self.fail(msg=resp["errmsg"])
else:
self.module.debug("Group doesn't exist")
def is_changed(self):
"""Return true if the host doesn't match
the LogicMonitor account"""
self.module.debug("Running Hostgroup.is_changed...")
ignore = []
group = self.get_group(self.fullpath)
properties = self.get_properties()
if properties is not None and group is not None:
self.module.debug("Comparing simple group properties")
if (group["alertEnable"] != self.alertenable or
group["description"] != self.description):
return True
p = {}
self.module.debug("Creating list of properties")
for prop in properties:
if prop["name"] not in ignore:
if ("*******" in prop["value"] and
self._verify_property(prop["name"])):
p[prop["name"]] = (
self.properties[prop["name"]])
else:
p[prop["name"]] = prop["value"]
self.module.debug("Comparing properties")
if set(p) != set(self.properties):
return True
else:
self.module.debug("No property information received")
return False
def sdt(self, duration=30, starttime=None):
"""Create a scheduled down time
(maintenance window) for this host"""
self.module.debug("Running Hostgroup.sdt")
self.module.debug("System changed")
self.change = True
if self.check_mode:
self.exit(changed=True)
duration = self.duration
starttime = self.starttime
offset = starttime
if starttime:
self.module.debug("Start time specified")
start = datetime.datetime.strptime(starttime, '%Y-%m-%d %H:%M')
offsetstart = start
else:
self.module.debug("No start time specified. Using default.")
start = datetime.datetime.utcnow()
# Use user UTC offset
self.module.debug("Making RPC call to 'getTimeZoneSetting'")
accountresp = json.loads(self.rpc("getTimeZoneSetting", {}))
if accountresp["status"] == 200:
self.module.debug("RPC call succeeded")
offset = accountresp["data"]["offset"]
offsetstart = start + datetime.timedelta(0, offset)
else:
self.fail(
msg="Error: Unable to retrieve timezone offset")
offsetend = offsetstart + datetime.timedelta(0, int(duration) * 60)
h = {"hostGroupId": self.info["id"],
"type": 1,
"year": offsetstart.year,
"month": offsetstart.month - 1,
"day": offsetstart.day,
"hour": offsetstart.hour,
"minute": offsetstart.minute,
"endYear": offsetend.year,
"endMonth": offsetend.month - 1,
"endDay": offsetend.day,
"endHour": offsetend.hour,
"endMinute": offsetend.minute}
self.module.debug("Making RPC call to setHostGroupSDT")
resp = json.loads(self.rpc("setHostGroupSDT", h))
if resp["status"] == 200:
self.module.debug("RPC call succeeded")
return resp["data"]
else:
self.module.debug("RPC call failed")
self.fail(msg=resp["errmsg"])
def site_facts(self):
"""Output current properties information for the Hostgroup"""
self.module.debug("Running Hostgroup.site_facts...")
if self.info:
self.module.debug("Group exists")
props = self.get_properties(True)
self.output_info(props)
else:
self.fail(msg="Error: Group doesn't exit.")
def _build_host_group_hash(self,
fullpath,
description,
properties,
alertenable):
"""Return a property formatted hash for the
creation of a hostgroup using the rpc function"""
self.module.debug("Running Hostgroup._build_host_hash")
h = {}
h["alertEnable"] = alertenable
if fullpath == "/":
self.module.debug("Group is root")
h["id"] = 1
else:
self.module.debug("Determining group path")
parentpath, name = fullpath.rsplit('/', 1)
parent = self.get_group(parentpath)
h["name"] = name
if parent:
self.module.debug("Parent group " +
str(parent["id"]) + " found.")
h["parentID"] = parent["id"]
else:
self.module.debug("No parent group found. Using root.")
h["parentID"] = 1
if description:
self.module.debug("Description property exists")
h["description"] = description
if properties != {}:
self.module.debug("Properties hash exists")
propnum = 0
for key, value in properties.items():
h["propName" + str(propnum)] = key
h["propValue" + str(propnum)] = value
propnum = propnum + 1
return h
def _verify_property(self, propname):
"""Check with LogicMonitor server
to verify property is unchanged"""
self.module.debug("Running Hostgroup._verify_property")
if self.info:
self.module.debug("Group exists")
if propname not in self.properties:
self.module.debug("Property " + propname + " does not exist")
return False
else:
self.module.debug("Property " + propname + " exists")
h = {"hostGroupId": self.info["id"],
"propName0": propname,
"propValue0": self.properties[propname]}
self.module.debug("Making RCP call to 'verifyProperties'")
resp = json.loads(self.rpc('verifyProperties', h))
if resp["status"] == 200:
self.module.debug("RPC call succeeded")
return resp["data"]["match"]
else:
self.fail(
msg="Error: unable to get verification " +
"from server.\n%s" % resp["errmsg"])
else:
self.fail(
msg="Error: Group doesn't exist. Unable to verify properties")
def selector(module):
"""Figure out which object and which actions
to take given the right parameters"""
if module.params["target"] == "collector":
target = Collector(module.params, module)
elif module.params["target"] == "host":
# Make sure required parameter collector is specified
if ((module.params["action"] == "add" or
module.params["displayname"] is None) and
module.params["collector"] is None):
module.fail_json(
msg="Parameter 'collector' required.")
target = Host(module.params, module)
elif module.params["target"] == "datasource":
# Validate target specific required parameters
if module.params["id"] is not None:
# make sure a supported action was specified
if module.params["action"] == "sdt":
target = Datasource(module.params, module)
else:
errmsg = ("Error: Unexpected action \"" +
module.params["action"] + "\" was specified.")
module.fail_json(msg=errmsg)
elif module.params["target"] == "hostgroup":
# Validate target specific required parameters
if module.params["fullpath"] is not None:
target = Hostgroup(module.params, module)
else:
module.fail_json(
msg="Parameter 'fullpath' required for target 'hostgroup'")
else:
module.fail_json(
msg="Error: Unexpected target \"" + module.params["target"] +
"\" was specified.")
if module.params["action"].lower() == "add":
action = target.create
elif module.params["action"].lower() == "remove":
action = target.remove
elif module.params["action"].lower() == "sdt":
action = target.sdt
elif module.params["action"].lower() == "update":
action = target.update
else:
errmsg = ("Error: Unexpected action \"" + module.params["action"] +
"\" was specified.")
module.fail_json(msg=errmsg)
action()
module.exit_json(changed=target.change)
def main():
TARGETS = [
"collector",
"host",
"datasource",
"hostgroup"]
ACTIONS = [
"add",
"remove",
"sdt",
"update"]
module = AnsibleModule(
argument_spec=dict(
target=dict(required=True, default=None, choices=TARGETS),
action=dict(required=True, default=None, choices=ACTIONS),
company=dict(required=True, default=None),
user=dict(required=True, default=None),
password=dict(required=True, default=None, no_log=True),
collector=dict(required=False, default=None),
hostname=dict(required=False, default=None),
displayname=dict(required=False, default=None),
id=dict(required=False, default=None),
description=dict(required=False, default=""),
fullpath=dict(required=False, default=None),
starttime=dict(required=False, default=None),
duration=dict(required=False, default=30, type='int'),
properties=dict(required=False, default={}, type="dict"),
groups=dict(required=False, default=[], type="list"),
alertenable=dict(required=False, default="true", type="bool")
),
supports_check_mode=True
)
selector(module)
if __name__ == "__main__":
main()
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
5297,
530,
13189,
2622,
859,
367,
28453,
3626,
3283,
83,
12,
10891,
83,
436,
10891,
2634,
199,
3,
1898,
334,
35,
9,
6900,
221,
5297,
530,
13189,
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,
9677,
275,
1449,
199,
2595,
199,
3742,
26,
272,
1369,
26,
3305,
9297,
626,
6451,
1990,
9512,
272,
2138,
26,
3182,
272,
730,
26,
2155,
272,
2690,
26,
715,
199,
1396,
199,
2344,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
9661,
7157,
199,
3612,
63,
1802,
26,
14944,
2195,
5297,
530,
13189,
2933,
4012,
2622,
16527,
8858,
199,
1802,
26,
523,
446,
5297,
530,
13189,
365,
282,
28311,
12,
2615,
13,
2340,
12,
28890,
6976,
20391,
4298,
14,
523,
446,
961,
859,
31965,
7057,
12,
1591,
4652,
12,
436,
14910,
83,
4453,
2195,
5297,
530,
13189,
2933,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
2502,
26,
199,
13,
662,
13797,
445,
348,
1435,
13,
15586,
287,
79,
8593,
12391,
290,
3119,
1435,
9,
199,
13,
1603,
3609,
644,
26051,
8445,
1151,
8593,
2027,
90,
21,
5637,
9,
199,
5983,
26,
523,
446,
2047,
1471,
1172,
376,
3411,
5297,
530,
13189,
2933,
367,
642,
859,
370,
805,
14,
199,
7538,
26,
2097,
2493,
3411,
5297,
530,
13189,
2933,
401,
298,
14091,
937,
199,
1419,
26,
523,
1347,
26,
272,
1369,
26,
489,
446,
710,
730,
402,
5297,
530,
13189,
909,
1265,
13809,
370,
9635,
14,
489,
446,
298,
12852,
26,
14795,
5445,
641,
282,
5297,
530,
13189,
14910,
2122,
489,
446,
6944,
2047,
1077,
675,
2622,
2435,
4621,
4066,
465,
603,
8,
1364,
9,
503,
603,
8,
4792,
8286,
8077,
9,
367,
28453,
314,
3626,
3283,
283,
15370,
7157,
13,
4054,
7,
436,
267,
283,
15370,
7157,
13,
6821,
13889,
7,
8500,
14,
30836,
12,
1265,
7171,
8646,
2934,
370,
1343,
3520,
8500,
2410,
282,
3626,
3283,
1050,
436,
3631,
3520,
8500,
267,
2544,
282,
3626,
3283,
2813,
14,
489,
446,
298,
4965,
26,
14795,
5445,
641,
282,
1591,
2243,
2122,
489,
446,
298,
4965,
923,
26,
14795,
5445,
641,
282,
5297,
530,
13189,
1591,
1572,
2122,
489,
446,
690,
267,
6944,
10891,
436,
10891,
923,
6527,
1077,
3544,
506,
10585,
4799,
13080,
63,
475,
26,
11667,
14,
6006,
787,
949,
22477,
14948,
370,
3879,
3520,
6527,
641,
314,
267,
3982,
1591,
436,
9689,
880,
911,
13609,
7675,
8826,
14,
272,
1415,
26,
2549,
272,
3415,
26,
788,
10946,
297,
283,
1102,
297,
283,
21208,
297,
283,
28221,
418,
523,
1595,
26,
272,
1369,
26,
489,
446,
710,
1595,
1265,
13809,
370,
5147,
641,
1347,
14,
489,
446,
298,
1123,
26,
2654,
376,
909,
370,
2195,
5297,
530,
13189,
2933,
2122,
489,
446,
298,
5587,
26,
5852,
376,
909,
687,
2195,
5297,
530,
13189,
2933,
2122,
489,
446,
298,
4152,
26,
6162,
4382,
12,
1369,
12,
503,
4652,
334,
1375,
29,
1102,
9,
367,
376,
909,
315,
2195,
5297,
530,
13189,
2933,
2122,
489,
446,
298,
3693,
52,
26,
24317,
3224,
521,
367,
376,
909,
315,
2195,
5297,
530,
13189,
2933,
2122,
272,
1415,
26,
2549,
272,
3415,
26,
788,
525,
297,
283,
2168,
297,
283,
873,
297,
283,
83,
3583,
418,
523,
7233,
26,
272,
1369,
26,
489,
446,
710,
5297,
530,
13189,
2933,
7233,
536,
14,
982,
1265,
3955,
943,
315,
370,
2195,
2933,
737,
298,
4792,
31863,
397,
14,
15370,
7157,
14,
957,
2,
1265,
3955,
675,
298,
4792,
31863,
397,
2122,
272,
1415,
26,
2549,
523,
922,
26,
272,
1369,
26,
489,
446,
437,
5297,
530,
13189,
922,
536,
14,
710,
859,
911,
12895,
436,
5147,
5445,
641,
506,
10220,
402,
642,
922,
14,
272,
1415,
26,
2549,
523,
2505,
26,
272,
1369,
26,
267,
446,
710,
2505,
402,
314,
2013,
5297,
530,
13189,
922,
272,
1415,
26,
2549,
523,
14910,
26,
272,
1369,
26,
489,
446,
710,
9999,
12313,
2881,
536,
402,
282,
14910,
315,
2195,
5297,
530,
13189,
2933,
14,
489,
446,
961,
365,
1415,
367,
314,
7143,
402,
282,
5297,
530,
13189,
1591,
334,
1375,
29,
1102,
1595,
29,
525,
680,
489,
446,
961,
365,
1415,
367,
12928,
12,
12881,
503,
23800,
3224,
521,
367,
7057,
340,
283,
2918,
354,
7,
5712,
1133,
267,
2013,
334,
1375,
29,
1102,
1595,
29,
873,
1595,
29,
2168,
1595,
29,
83,
3583,
680,
523,
6246,
26,
272,
1369,
26,
489,
446,
710,
6246,
402,
282,
1591,
315,
2195,
5297,
530,
13189,
2933,
12,
503,
314,
6387,
6246,
402,
282,
2243,
370,
9635,
14,
489,
446,
4879,
367,
28453,
7057,
334,
1375,
29,
1102,
680,
272,
849,
26,
283,
4269,
446,
70,
7,
523,
2929,
354,
26,
272,
1369,
26,
489,
446,
710,
2929,
536,
402,
282,
1591,
315,
2195,
5297,
530,
13189,
2933,
503,
314,
6387,
2929,
536,
402,
282,
2243,
370,
9635,
14,
489,
446,
4879,
367,
28453,
7057,
334,
1375,
29,
1102,
680,
272,
849,
26,
283,
4269,
446,
70,
7,
523,
1369,
26,
272,
1369,
26,
489,
446,
710,
1846,
1318,
1369,
402,
314,
909,
315,
2195,
5297,
530,
13189,
2933,
14,
489,
446,
4879,
367,
28453,
7057,
436,
1591,
4652,
334,
1375,
29,
1102,
503,
1347,
29,
28221,
27,
1595,
29,
525,
503,
1595,
29,
873,
680,
272,
849,
26,
3087,
523,
4382,
26,
272,
1369,
26,
489,
446,
437,
2600,
402,
4382,
370,
663,
641,
314,
5297,
530,
13189,
1591,
503,
1591,
1572,
14,
489,
446,
4879,
367,
28453,
7057,
436,
1591,
4652,
334,
1375,
29,
1102,
503,
1347,
29,
28221,
27,
1595,
29,
525,
503,
1595,
29,
873,
680,
489,
446,
961,
2725,
911,
1050,
503,
1678,
3411,
4382,
315,
2195,
5297,
530,
13189,
2933,
14,
272,
849,
26,
1052,
523,
4652
] |
[
2647,
15,
1393,
15,
1548,
199,
199,
3,
5297,
530,
13189,
2622,
859,
367,
28453,
3626,
3283,
83,
12,
10891,
83,
436,
10891,
2634,
199,
3,
1898,
334,
35,
9,
6900,
221,
5297,
530,
13189,
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,
9677,
275,
1449,
199,
2595,
199,
3742,
26,
272,
1369,
26,
3305,
9297,
626,
6451,
1990,
9512,
272,
2138,
26,
3182,
272,
730,
26,
2155,
272,
2690,
26,
715,
199,
1396,
199,
2344,
421,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
490,
283,
1205,
356,
788,
7780,
995,
490,
283,
4946,
63,
991,
356,
283,
9387,
936,
421,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
9661,
7157,
199,
3612,
63,
1802,
26,
14944,
2195,
5297,
530,
13189,
2933,
4012,
2622,
16527,
8858,
199,
1802,
26,
523,
446,
5297,
530,
13189,
365,
282,
28311,
12,
2615,
13,
2340,
12,
28890,
6976,
20391,
4298,
14,
523,
446,
961,
859,
31965,
7057,
12,
1591,
4652,
12,
436,
14910,
83,
4453,
2195,
5297,
530,
13189,
2933,
14,
199,
1023,
63,
3270,
26,
298,
18,
14,
18,
2,
199,
2502,
26,
199,
13,
662,
13797,
445,
348,
1435,
13,
15586,
287,
79,
8593,
12391,
290,
3119,
1435,
9,
199,
13,
1603,
3609,
644,
26051,
8445,
1151,
8593,
2027,
90,
21,
5637,
9,
199,
5983,
26,
523,
446,
2047,
1471,
1172,
376,
3411,
5297,
530,
13189,
2933,
367,
642,
859,
370,
805,
14,
199,
7538,
26,
2097,
2493,
3411,
5297,
530,
13189,
2933,
401,
298,
14091,
937,
199,
1419,
26,
523,
1347,
26,
272,
1369,
26,
489,
446,
710,
730,
402,
5297,
530,
13189,
909,
1265,
13809,
370,
9635,
14,
489,
446,
298,
12852,
26,
14795,
5445,
641,
282,
5297,
530,
13189,
14910,
2122,
489,
446,
6944,
2047,
1077,
675,
2622,
2435,
4621,
4066,
465,
603,
8,
1364,
9,
503,
603,
8,
4792,
8286,
8077,
9,
367,
28453,
314,
3626,
3283,
283,
15370,
7157,
13,
4054,
7,
436,
267,
283,
15370,
7157,
13,
6821,
13889,
7,
8500,
14,
30836,
12,
1265,
7171,
8646,
2934,
370,
1343,
3520,
8500,
2410,
282,
3626,
3283,
1050,
436,
3631,
3520,
8500,
267,
2544,
282,
3626,
3283,
2813,
14,
489,
446,
298,
4965,
26,
14795,
5445,
641,
282,
1591,
2243,
2122,
489,
446,
298,
4965,
923,
26,
14795,
5445,
641,
282,
5297,
530,
13189,
1591,
1572,
2122,
489,
446,
690,
267,
6944,
10891,
436,
10891,
923,
6527,
1077,
3544,
506,
10585,
4799,
13080,
63,
475,
26,
11667,
14,
6006,
787,
949,
22477,
14948,
370,
3879,
3520,
6527,
641,
314,
267,
3982,
1591,
436,
9689,
880,
911,
13609,
7675,
8826,
14,
272,
1415,
26,
2549,
272,
3415,
26,
788,
10946,
297,
283,
1102,
297,
283,
21208,
297,
283,
28221,
418,
523,
1595,
26,
272,
1369,
26,
489,
446,
710,
1595,
1265,
13809,
370,
5147,
641,
1347,
14,
489,
446,
298,
1123,
26,
2654,
376,
909,
370,
2195,
5297,
530,
13189,
2933,
2122,
489,
446,
298,
5587,
26,
5852,
376,
909,
687,
2195,
5297,
530,
13189,
2933,
2122,
489,
446,
298,
4152,
26,
6162,
4382,
12,
1369,
12,
503,
4652,
334,
1375,
29,
1102,
9,
367,
376,
909,
315,
2195,
5297,
530,
13189,
2933,
2122,
489,
446,
298,
3693,
52,
26,
24317,
3224,
521,
367,
376,
909,
315,
2195,
5297,
530,
13189,
2933,
2122,
272,
1415,
26,
2549,
272,
3415,
26,
788,
525,
297,
283,
2168,
297,
283,
873,
297,
283,
83,
3583,
418,
523,
7233,
26,
272,
1369,
26,
489,
446,
710,
5297,
530,
13189,
2933,
7233,
536,
14,
982,
1265,
3955,
943,
315,
370,
2195,
2933,
737,
298,
4792,
31863,
397,
14,
15370,
7157,
14,
957,
2,
1265,
3955,
675,
298,
4792,
31863,
397,
2122,
272,
1415,
26,
2549,
523,
922,
26,
272,
1369,
26,
489,
446,
437,
5297,
530,
13189,
922,
536,
14,
710,
859,
911,
12895,
436,
5147,
5445,
641,
506,
10220,
402,
642,
922,
14,
272,
1415,
26,
2549,
523,
2505,
26,
272,
1369,
26,
267,
446,
710,
2505,
402,
314,
2013,
5297,
530,
13189,
922,
272,
1415,
26,
2549,
523,
14910,
26,
272,
1369,
26,
489,
446,
710,
9999,
12313,
2881,
536,
402,
282,
14910,
315,
2195,
5297,
530,
13189,
2933,
14,
489,
446,
961,
365,
1415,
367,
314,
7143,
402,
282,
5297,
530,
13189,
1591,
334,
1375,
29,
1102,
1595,
29,
525,
680,
489,
446,
961,
365,
1415,
367,
12928,
12,
12881,
503,
23800,
3224,
521,
367,
7057,
340,
283,
2918,
354,
7,
5712,
1133,
267,
2013,
334,
1375,
29,
1102,
1595,
29,
873,
1595,
29,
2168,
1595,
29,
83,
3583,
680,
523,
6246,
26,
272,
1369,
26,
489,
446,
710,
6246,
402,
282,
1591,
315,
2195,
5297,
530,
13189,
2933,
12,
503,
314,
6387,
6246,
402,
282,
2243,
370,
9635,
14,
489,
446,
4879,
367,
28453,
7057,
334,
1375,
29,
1102,
680,
272,
849,
26,
283,
4269,
446,
70,
7,
523,
2929,
354,
26,
272,
1369,
26,
489,
446,
710,
2929,
536,
402,
282,
1591,
315,
2195,
5297,
530,
13189,
2933,
503,
314,
6387,
2929,
536,
402,
282,
2243,
370,
9635,
14,
489,
446,
4879,
367,
28453,
7057,
334,
1375,
29,
1102,
680,
272,
849,
26,
283,
4269,
446,
70,
7,
523,
1369,
26,
272,
1369,
26,
489,
446,
710,
1846,
1318,
1369,
402,
314,
909,
315,
2195,
5297,
530,
13189,
2933,
14,
489,
446,
4879,
367,
28453,
7057,
436,
1591,
4652,
334,
1375,
29,
1102,
503,
1347,
29,
28221,
27,
1595,
29,
525,
503,
1595,
29,
873,
680,
272,
849,
26,
3087,
523,
4382,
26,
272,
1369,
26,
489,
446,
437,
2600,
402,
4382,
370,
663,
641,
314,
5297,
530,
13189,
1591,
503,
1591,
1572,
14,
489,
446,
4879,
367,
28453,
7057,
436,
1591,
4652,
334,
1375,
29,
1102,
503,
1347,
29,
28221,
27,
1595,
29,
525,
503,
1595,
29,
873,
680,
489,
446,
961,
2725,
911,
1050,
503,
1678,
3411,
4382,
315,
2195,
5297,
530,
13189,
2933,
14,
272,
849,
26,
1052,
523,
4652,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
blueboxgroup/neutron
|
neutron/plugins/vmware/extensions/vnicindex.py
|
22
|
1594
|
# Copyright 2015 VMware, Inc. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from neutron.api.v2 import attributes
# Attribute Map
VNIC_INDEX = 'vnic_index'
EXTENDED_ATTRIBUTES_2_0 = {
'ports': {
VNIC_INDEX:
{'allow_post': True,
'allow_put': True,
'is_visible': True,
'default': None,
'convert_to': attributes.convert_to_int_if_not_none}}}
class Vnicindex(object):
@classmethod
def get_name(cls):
return "VNIC Index"
@classmethod
def get_alias(cls):
return "vnic-index"
@classmethod
def get_description(cls):
return ("Enable a port to be associated with a VNIC index")
@classmethod
def get_namespace(cls):
return "http://docs.openstack.org/ext/neutron/vnic_index/api/v1.0"
@classmethod
def get_updated(cls):
return "2014-09-15T12:00:00-00:00"
def get_extended_resources(self, version):
if version == "2.0":
return EXTENDED_ATTRIBUTES_2_0
else:
return {}
|
apache-2.0
|
[
3,
1898,
6900,
27391,
12,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
8224,
14,
1246,
14,
86,
18,
492,
3004,
199,
199,
3,
3882,
9672,
199,
54,
30374,
63,
10215,
275,
283,
29718,
63,
1080,
7,
421,
199,
27059,
63,
18166,
63,
18,
63,
16,
275,
469,
272,
283,
5203,
356,
469,
267,
812,
30374,
63,
10215,
26,
267,
791,
3306,
63,
1932,
356,
715,
12,
268,
283,
3306,
63,
524,
356,
715,
12,
268,
283,
374,
63,
6604,
356,
715,
12,
268,
283,
885,
356,
488,
12,
268,
283,
3916,
63,
475,
356,
3004,
14,
3916,
63,
475,
63,
442,
63,
692,
63,
1397,
63,
3592,
4863,
93,
421,
199,
533,
812,
12165,
1080,
8,
785,
304,
272,
768,
3744,
272,
347,
664,
63,
354,
8,
1886,
304,
267,
372,
298,
54,
30374,
5499,
2,
339,
768,
3744,
272,
347,
664,
63,
3620,
8,
1886,
304,
267,
372,
298,
29718,
13,
1080,
2,
339,
768,
3744,
272,
347,
664,
63,
1802,
8,
1886,
304,
267,
372,
1689,
6476,
282,
1844,
370,
506,
4568,
543,
282,
812,
30374,
1478,
531,
339,
768,
3744,
272,
347,
664,
63,
3251,
8,
1886,
304,
267,
372,
298,
1014,
921,
4757,
14,
8512,
14,
1308,
15,
832,
15,
10271,
15,
29718,
63,
1080,
15,
1246,
15,
86,
17,
14,
16,
2,
339,
768,
3744,
272,
347,
664,
63,
5334,
8,
1886,
304,
267,
372,
298,
7280,
13,
1643,
13,
1046,
52,
713,
26,
383,
26,
383,
13,
383,
26,
383,
2,
339,
347,
664,
63,
10525,
63,
4435,
8,
277,
12,
1015,
304,
267,
340,
1015,
508,
298,
18,
14,
16,
582,
288,
372,
20203,
25518,
63,
18166,
63,
18,
63,
16,
267,
587,
26,
288,
372,
1052,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
6900,
27391,
12,
3277,
14,
221,
2900,
4481,
4644,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
8224,
14,
1246,
14,
86,
18,
492,
3004,
199,
199,
3,
3882,
9672,
199,
54,
30374,
63,
10215,
275,
283,
29718,
63,
1080,
7,
421,
199,
27059,
63,
18166,
63,
18,
63,
16,
275,
469,
272,
283,
5203,
356,
469,
267,
812,
30374,
63,
10215,
26,
267,
791,
3306,
63,
1932,
356,
715,
12,
268,
283,
3306,
63,
524,
356,
715,
12,
268,
283,
374,
63,
6604,
356,
715,
12,
268,
283,
885,
356,
488,
12,
268,
283,
3916,
63,
475,
356,
3004,
14,
3916,
63,
475,
63,
442,
63,
692,
63,
1397,
63,
3592,
4863,
93,
421,
199,
533,
812,
12165,
1080,
8,
785,
304,
272,
768,
3744,
272,
347,
664,
63,
354,
8,
1886,
304,
267,
372,
298,
54,
30374,
5499,
2,
339,
768,
3744,
272,
347,
664,
63,
3620,
8,
1886,
304,
267,
372,
298,
29718,
13,
1080,
2,
339,
768,
3744,
272,
347,
664,
63,
1802,
8,
1886,
304,
267,
372,
1689,
6476,
282,
1844,
370,
506,
4568,
543,
282,
812,
30374,
1478,
531,
339,
768,
3744,
272,
347,
664,
63,
3251,
8,
1886,
304,
267,
372,
298,
1014,
921,
4757,
14,
8512,
14,
1308,
15,
832,
15,
10271,
15,
29718,
63,
1080,
15,
1246,
15,
86,
17,
14,
16,
2,
339,
768,
3744,
272,
347,
664,
63,
5334,
8,
1886,
304,
267,
372,
298,
7280,
13,
1643,
13,
1046,
52,
713,
26,
383,
26,
383,
13,
383,
26,
383,
2,
339,
347,
664,
63,
10525,
63,
4435,
8,
277,
12,
1015,
304,
267,
340,
1015,
508,
298,
18,
14,
16,
582,
288,
372,
20203,
25518,
63,
18166,
63,
18,
63,
16,
267,
587,
26,
288,
372,
1052,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
shangwuhencc/shogun
|
examples/undocumented/python_modular/features_sparse_modular.py
|
26
|
1227
|
#!/usr/bin/env python
import numpy
# create dense matrix A
A=numpy.array([[1,2,3],[4,0,0],[0,0,0],[0,5,0],[0,0,6],[9,9,9]], dtype=numpy.float64)
parameter_list=[[A]]
def features_sparse_modular (A):
from scipy.sparse import csc_matrix
from modshogun import SparseRealFeatures
from numpy import array, float64, all
# sparse representation X of dense matrix A
# note, will work with types other than float64 too,
# but requires recent scipy.sparse
X=csc_matrix(A)
#print(A)
# create sparse shogun features from dense matrix A
a=SparseRealFeatures(A)
a_out=a.get_full_feature_matrix()
#print(a_out)
assert(all(a_out==A))
#print(a_out)
# create sparse shogun features from sparse matrix X
a.set_sparse_feature_matrix(X)
a_out=a.get_full_feature_matrix()
#print(a_out)
assert(all(a_out==A))
# create sparse shogun features from sparse matrix X
a=SparseRealFeatures(X)
a_out=a.get_full_feature_matrix()
#print(a_out)
assert(all(a_out==A))
# obtain (data,row,indptr) csc arrays of sparse shogun features
z=csc_matrix(a.get_sparse_feature_matrix())
z_out=z.todense()
#print(z_out)
assert(all(z_out==A))
if __name__=='__main__':
print('Sparse Features')
features_sparse_modular(*parameter_list[0])
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
646,
2680,
199,
3,
1218,
9363,
3634,
437,
199,
33,
29,
4714,
14,
1144,
4038,
17,
12,
18,
12,
19,
6922,
20,
12,
16,
12,
16,
6922,
16,
12,
16,
12,
16,
6922,
16,
12,
21,
12,
16,
6922,
16,
12,
16,
12,
22,
6922,
25,
12,
25,
12,
25,
2365,
2152,
29,
4714,
14,
1609,
772,
9,
199,
199,
5329,
63,
513,
16025,
33,
2677,
199,
318,
4534,
63,
4421,
63,
1494,
2238,
334,
33,
304,
199,
198,
504,
7026,
14,
4421,
492,
28308,
63,
3642,
199,
198,
504,
3413,
13927,
17924,
492,
14531,
10099,
10807,
199,
198,
504,
2680,
492,
1625,
12,
2069,
772,
12,
1006,
421,
198,
3,
5178,
6025,
1323,
402,
9363,
3634,
437,
199,
198,
3,
5317,
12,
911,
1736,
543,
2943,
1163,
2419,
2069,
772,
4634,
12,
199,
198,
3,
1325,
5074,
8058,
7026,
14,
4421,
199,
198,
56,
29,
17000,
63,
3642,
8,
33,
9,
199,
198,
3,
1361,
8,
33,
9,
421,
198,
3,
1218,
5178,
930,
17924,
4534,
687,
9363,
3634,
437,
199,
198,
65,
29,
8629,
10099,
10807,
8,
33,
9,
199,
198,
65,
63,
548,
29,
65,
14,
362,
63,
2861,
63,
4445,
63,
3642,
342,
199,
198,
3,
1361,
8,
65,
63,
548,
9,
199,
198,
479,
8,
452,
8,
65,
63,
548,
389,
33,
430,
199,
198,
3,
1361,
8,
65,
63,
548,
9,
421,
198,
3,
1218,
5178,
930,
17924,
4534,
687,
5178,
3634,
1323,
199,
198,
65,
14,
409,
63,
4421,
63,
4445,
63,
3642,
8,
56,
9,
199,
198,
65,
63,
548,
29,
65,
14,
362,
63,
2861,
63,
4445,
63,
3642,
342,
199,
198,
3,
1361,
8,
65,
63,
548,
9,
199,
198,
479,
8,
452,
8,
65,
63,
548,
389,
33,
430,
421,
198,
3,
1218,
5178,
930,
17924,
4534,
687,
5178,
3634,
1323,
199,
198,
65,
29,
8629,
10099,
10807,
8,
56,
9,
199,
198,
65,
63,
548,
29,
65,
14,
362,
63,
2861,
63,
4445,
63,
3642,
342,
199,
198,
3,
1361,
8,
65,
63,
548,
9,
199,
198,
479,
8,
452,
8,
65,
63,
548,
389,
33,
430,
421,
198,
3,
3332,
334,
576,
12,
1143,
12,
25243,
9,
28308,
6572,
402,
5178,
930,
17924,
4534,
199,
198,
90,
29,
17000,
63,
3642,
8,
65,
14,
362,
63,
4421,
63,
4445,
63,
3642,
1012,
199,
198,
90,
63,
548,
29,
90,
14,
23526,
342,
199,
198,
3,
1361,
8,
90,
63,
548,
9,
199,
198,
479,
8,
452,
8,
90,
63,
548,
389,
33,
430,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
199,
198,
1361,
360,
8629,
7949,
2093,
358,
199,
198,
3179,
63,
4421,
63,
1494,
2238,
2031,
5329,
63,
513,
59,
16,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
646,
2680,
199,
3,
1218,
9363,
3634,
437,
199,
33,
29,
4714,
14,
1144,
4038,
17,
12,
18,
12,
19,
6922,
20,
12,
16,
12,
16,
6922,
16,
12,
16,
12,
16,
6922,
16,
12,
21,
12,
16,
6922,
16,
12,
16,
12,
22,
6922,
25,
12,
25,
12,
25,
2365,
2152,
29,
4714,
14,
1609,
772,
9,
199,
199,
5329,
63,
513,
16025,
33,
2677,
199,
318,
4534,
63,
4421,
63,
1494,
2238,
334,
33,
304,
199,
198,
504,
7026,
14,
4421,
492,
28308,
63,
3642,
199,
198,
504,
3413,
13927,
17924,
492,
14531,
10099,
10807,
199,
198,
504,
2680,
492,
1625,
12,
2069,
772,
12,
1006,
421,
198,
3,
5178,
6025,
1323,
402,
9363,
3634,
437,
199,
198,
3,
5317,
12,
911,
1736,
543,
2943,
1163,
2419,
2069,
772,
4634,
12,
199,
198,
3,
1325,
5074,
8058,
7026,
14,
4421,
199,
198,
56,
29,
17000,
63,
3642,
8,
33,
9,
199,
198,
3,
1361,
8,
33,
9,
421,
198,
3,
1218,
5178,
930,
17924,
4534,
687,
9363,
3634,
437,
199,
198,
65,
29,
8629,
10099,
10807,
8,
33,
9,
199,
198,
65,
63,
548,
29,
65,
14,
362,
63,
2861,
63,
4445,
63,
3642,
342,
199,
198,
3,
1361,
8,
65,
63,
548,
9,
199,
198,
479,
8,
452,
8,
65,
63,
548,
389,
33,
430,
199,
198,
3,
1361,
8,
65,
63,
548,
9,
421,
198,
3,
1218,
5178,
930,
17924,
4534,
687,
5178,
3634,
1323,
199,
198,
65,
14,
409,
63,
4421,
63,
4445,
63,
3642,
8,
56,
9,
199,
198,
65,
63,
548,
29,
65,
14,
362,
63,
2861,
63,
4445,
63,
3642,
342,
199,
198,
3,
1361,
8,
65,
63,
548,
9,
199,
198,
479,
8,
452,
8,
65,
63,
548,
389,
33,
430,
421,
198,
3,
1218,
5178,
930,
17924,
4534,
687,
5178,
3634,
1323,
199,
198,
65,
29,
8629,
10099,
10807,
8,
56,
9,
199,
198,
65,
63,
548,
29,
65,
14,
362,
63,
2861,
63,
4445,
63,
3642,
342,
199,
198,
3,
1361,
8,
65,
63,
548,
9,
199,
198,
479,
8,
452,
8,
65,
63,
548,
389,
33,
430,
421,
198,
3,
3332,
334,
576,
12,
1143,
12,
25243,
9,
28308,
6572,
402,
5178,
930,
17924,
4534,
199,
198,
90,
29,
17000,
63,
3642,
8,
65,
14,
362,
63,
4421,
63,
4445,
63,
3642,
1012,
199,
198,
90,
63,
548,
29,
90,
14,
23526,
342,
199,
198,
3,
1361,
8,
90,
63,
548,
9,
199,
198,
479,
8,
452,
8,
90,
63,
548,
389,
33,
430,
199,
199,
692,
636,
354,
363,
6803,
363,
973,
3706,
199,
198,
1361,
360,
8629,
7949,
2093,
358,
199,
198,
3179,
63,
4421,
63,
1494,
2238,
2031,
5329,
63,
513,
59,
16,
566,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
anjos/rrbob
|
bootstrap-buildout.py
|
172
|
6501
|
##############################################################################
#
# Copyright (c) 2006 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Bootstrap a buildout-based project
Simply run this script in a directory containing a buildout.cfg.
The script accepts buildout command-line options, so you can
use the -c option to specify an alternate configuration file.
"""
import os
import shutil
import sys
import tempfile
from optparse import OptionParser
tmpeggs = tempfile.mkdtemp()
usage = '''\
[DESIRED PYTHON FOR BUILDOUT] bootstrap.py [options]
Bootstraps a buildout-based project.
Simply run this script in a directory containing a buildout.cfg, using the
Python that you want bin/buildout to use.
Note that by using --find-links to point to local resources, you can keep
this script from going over the network.
'''
parser = OptionParser(usage=usage)
parser.add_option("-v", "--version", help="use a specific zc.buildout version")
parser.add_option("-t", "--accept-buildout-test-releases",
dest='accept_buildout_test_releases',
action="store_true", default=False,
help=("Normally, if you do not specify a --version, the "
"bootstrap script and buildout gets the newest "
"*final* versions of zc.buildout and its recipes and "
"extensions for you. If you use this flag, "
"bootstrap and buildout will get the newest releases "
"even if they are alphas or betas."))
parser.add_option("-c", "--config-file",
help=("Specify the path to the buildout configuration "
"file to be used."))
parser.add_option("-f", "--find-links",
help=("Specify a URL to search for buildout releases"))
parser.add_option("--allow-site-packages",
action="store_true", default=False,
help=("Let bootstrap.py use existing site packages"))
parser.add_option("--setuptools-version",
help="use a specific setuptools version")
options, args = parser.parse_args()
######################################################################
# load/install setuptools
try:
if options.allow_site_packages:
import setuptools
import pkg_resources
from urllib.request import urlopen
except ImportError:
from urllib2 import urlopen
ez = {}
exec(urlopen('https://bootstrap.pypa.io/ez_setup.py').read(), ez)
if not options.allow_site_packages:
# ez_setup imports site, which adds site packages
# this will remove them from the path to ensure that incompatible versions
# of setuptools are not in the path
import site
# inside a virtualenv, there is no 'getsitepackages'.
# We can't remove these reliably
if hasattr(site, 'getsitepackages'):
for sitepackage_path in site.getsitepackages():
sys.path[:] = [x for x in sys.path if sitepackage_path not in x]
setup_args = dict(to_dir=tmpeggs, download_delay=0)
if options.setuptools_version is not None:
setup_args['version'] = options.setuptools_version
ez['use_setuptools'](**setup_args)
import setuptools
import pkg_resources
# This does not (always?) update the default working set. We will
# do it.
for path in sys.path:
if path not in pkg_resources.working_set.entries:
pkg_resources.working_set.add_entry(path)
######################################################################
# Install buildout
ws = pkg_resources.working_set
cmd = [sys.executable, '-c',
'from setuptools.command.easy_install import main; main()',
'-mZqNxd', tmpeggs]
find_links = os.environ.get(
'bootstrap-testing-find-links',
options.find_links or
('http://downloads.buildout.org/'
if options.accept_buildout_test_releases else None)
)
if find_links:
cmd.extend(['-f', find_links])
setuptools_path = ws.find(
pkg_resources.Requirement.parse('setuptools')).location
requirement = 'zc.buildout'
version = options.version
if version is None and not options.accept_buildout_test_releases:
# Figure out the most recent final version of zc.buildout.
import setuptools.package_index
_final_parts = '*final-', '*final'
def _final_version(parsed_version):
try:
return not parsed_version.is_prerelease
except AttributeError:
# Older setuptools
for part in parsed_version:
if (part[:1] == '*') and (part not in _final_parts):
return False
return True
index = setuptools.package_index.PackageIndex(
search_path=[setuptools_path])
if find_links:
index.add_find_links((find_links,))
req = pkg_resources.Requirement.parse(requirement)
if index.obtain(req) is not None:
best = []
bestv = None
for dist in index[req.project_name]:
distv = dist.parsed_version
if _final_version(distv):
if bestv is None or distv > bestv:
best = [dist]
bestv = distv
elif distv == bestv:
best.append(dist)
if best:
best.sort()
version = best[-1].version
if version:
requirement = '=='.join((requirement, version))
cmd.append(requirement)
import subprocess
if subprocess.call(cmd, env=dict(os.environ, PYTHONPATH=setuptools_path)) != 0:
raise Exception(
"Failed to execute command:\n%s" % repr(cmd)[1:-1])
######################################################################
# Import and run buildout
ws.add_entry(tmpeggs)
ws.require(requirement)
import zc.buildout.buildout
if not [a for a in args if '=' not in a]:
args.append('bootstrap')
# if -c was provided, we push it back into args for buildout' main function
if options.config_file is not None:
args[0:0] = ['-c', options.config_file]
zc.buildout.buildout.main(args)
shutil.rmtree(tmpeggs)
|
bsd-3-clause
|
[
4605,
199,
3,
199,
3,
1898,
334,
67,
9,
8315,
3107,
13458,
2752,
436,
23212,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
961,
2032,
365,
5420,
370,
314,
1727,
1356,
402,
314,
3107,
13458,
1684,
844,
12,
199,
3,
3394,
499,
14,
17,
334,
58,
2749,
680,
221,
437,
1331,
402,
314,
3107,
2749,
1077,
21727,
642,
4084,
14,
199,
3,
5749,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
1821,
2401,
11727,
7168,
1549,
5292,
199,
3,
2990,
9315,
9706,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
377,
16507,
12,
3169,
12,
437,
9741,
7834,
1621,
12600,
12,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
199,
3,
199,
4605,
199,
624,
17989,
7868,
282,
1900,
548,
13,
6788,
2199,
199,
199,
51,
3236,
590,
1255,
642,
2884,
315,
282,
2082,
3035,
282,
1900,
548,
14,
4128,
14,
199,
1918,
2884,
11479,
1900,
548,
1414,
13,
604,
1511,
12,
880,
1265,
883,
199,
1180,
314,
446,
67,
945,
370,
4165,
376,
18034,
2897,
570,
14,
199,
624,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
199,
504,
8691,
492,
13491,
199,
199,
2791,
14488,
275,
5549,
14,
11983,
342,
199,
199,
3807,
275,
18087,
199,
59,
4448,
10322,
18280,
2381,
16331,
1193,
12619,
61,
15865,
14,
647,
359,
1419,
61,
199,
199,
17989,
270,
8146,
282,
1900,
548,
13,
6788,
2199,
14,
199,
199,
51,
3236,
590,
1255,
642,
2884,
315,
282,
2082,
3035,
282,
1900,
548,
14,
4128,
12,
1808,
314,
199,
4718,
626,
1265,
2934,
2517,
15,
1506,
548,
370,
675,
14,
199,
199,
7443,
626,
701,
1808,
1553,
1623,
13,
4614,
370,
2376,
370,
2257,
5944,
12,
1265,
883,
4215,
199,
3749,
2884,
687,
9995,
1806,
314,
2784,
14,
199,
2344,
199,
199,
2087,
275,
13491,
8,
3807,
29,
3807,
9,
199,
2087,
14,
525,
63,
1422,
6096,
86,
401,
4320,
1023,
401,
1720,
628,
1180,
282,
2488,
1315,
67,
14,
1506,
548,
1015,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
84,
401,
4320,
5694,
13,
1506,
548,
13,
396,
13,
11840,
401,
2116,
2053,
534,
5694,
63,
1506,
548,
63,
396,
63,
11840,
297,
2116,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
2116,
1720,
15387,
15548,
1183,
12,
340,
1265,
886,
440,
4165,
282,
1553,
1023,
12,
314,
298,
717,
298,
11146,
2884,
436,
1900,
548,
7545,
314,
29608,
298,
717,
8969,
5094,
10,
5459,
402,
1315,
67,
14,
1506,
548,
436,
2399,
17121,
83,
436,
298,
717,
298,
5359,
367,
1265,
14,
221,
982,
1265,
675,
642,
3305,
12,
298,
717,
298,
11146,
436,
1900,
548,
911,
664,
314,
29608,
19015,
298,
717,
298,
12056,
340,
2985,
787,
25363,
503,
2907,
305,
13853,
199,
2087,
14,
525,
63,
1422,
6096,
67,
401,
4320,
888,
13,
493,
401,
2116,
1720,
15387,
17768,
314,
931,
370,
314,
1900,
548,
2897,
298,
717,
298,
493,
370,
506,
1202,
13853,
199,
2087,
14,
525,
63,
1422,
6096,
70,
401,
4320,
1623,
13,
4614,
401,
2116,
1720,
15387,
17768,
282,
2851,
370,
2754,
367,
1900,
548,
19015,
2237,
199,
2087,
14,
525,
63,
1422,
6739,
3306,
13,
2124,
13,
5154,
401,
2116,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
2116,
1720,
15387,
15314,
15865,
14,
647,
675,
3411,
4770,
6117,
2237,
199,
2087,
14,
525,
63,
1422,
6739,
13623,
13,
1023,
401,
2116,
1720,
628,
1180,
282,
2488,
9116,
1015,
531,
421,
199,
1419,
12,
1249,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
18022,
199,
3,
2248,
15,
3174,
9116,
199,
199,
893,
26,
272,
340,
1511,
14,
3306,
63,
2124,
63,
5154,
26,
267,
492,
9116,
267,
492,
5496,
63,
4435,
272,
687,
4011,
14,
1069,
492,
18279,
199,
2590,
3545,
26,
272,
687,
4011,
18,
492,
18279,
199,
199,
27263,
275,
1052,
199,
1628,
8,
10890,
360,
2859,
921,
11146,
14,
647,
387,
14,
2308,
15,
27263,
63,
2758,
14,
647,
1959,
739,
1062,
325,
90,
9,
199,
199,
692,
440,
1511,
14,
3306,
63,
2124,
63,
5154,
26,
272,
327,
325,
90,
63,
2758,
8925,
4770,
12,
1314,
9584,
4770,
6117,
272,
327,
642,
911,
2813,
3062,
687,
314,
931,
370,
4868,
626,
18457,
5459,
272,
327,
402,
9116,
787,
440,
315,
314,
931,
272,
492,
4770,
272,
327,
6272,
282,
19128,
12,
2337,
365,
949,
283,
362,
2124,
5154,
1370,
272,
327,
2136,
883,
1133,
2813,
3520,
16492,
6665,
272,
340,
2688,
8,
2124,
12,
283,
362,
2124,
5154,
735,
267,
367,
4770,
2491,
63,
515,
315,
4770,
14,
362,
2124,
5154,
837,
288,
984,
14,
515,
5873,
275,
359,
88,
367,
671,
315,
984,
14,
515,
340,
4770,
2491,
63,
515,
440,
315,
671,
61,
199,
199,
2758,
63,
589,
275,
1211,
8,
475,
63,
694,
29,
2791,
14488,
12,
5235,
63,
5814,
29,
16,
9,
199,
199,
692,
1511,
14,
13623,
63,
1023,
365,
440,
488,
26,
272,
3272,
63,
589,
459,
1023,
418,
275,
1511,
14,
13623,
63,
1023,
199,
199,
27263,
459,
1180,
63,
13623,
418,
3682,
2758,
63,
589,
9,
199,
646,
9116,
199,
646,
5496,
63,
4435,
199,
199,
3,
961,
1630,
440,
334,
9223,
17076,
1678,
314,
849,
6449,
663,
14,
221,
2136,
911,
199,
3,
886,
652,
14,
199,
509,
931,
315,
984,
14,
515,
26,
272,
340,
931,
440,
315,
5496,
63,
4435,
14,
9818,
63,
409,
14,
3189,
26,
267,
5496,
63,
4435,
14,
9818,
63,
409,
14,
525,
63,
2373,
8,
515,
9,
199,
199,
18022,
199,
3,
13276,
1900,
548,
199,
199,
3569,
275,
5496,
63,
4435,
14,
9818,
63,
409,
199,
199,
1760,
275,
359,
1274,
14,
5904,
12,
2475,
67,
297,
2126,
283,
504,
9116,
14,
1531,
14,
13581,
63,
3174,
492,
2446,
27,
2446,
19633,
2126,
2475,
77,
58,
81,
46,
2207,
297,
3529,
14488,
61,
199,
199,
1623,
63,
4614,
275,
747,
14,
2314,
14,
362,
8,
272,
283,
11146,
13,
4776,
13,
1623,
13,
4614,
297,
272,
1511,
14,
1623,
63,
4614,
503,
272,
661,
1014,
921,
20373,
14,
1506,
548,
14,
1308,
4805,
1362,
340,
1511,
14,
5694,
63,
1506,
548,
63,
396
] |
[
199,
3,
199,
3,
1898,
334,
67,
9,
8315,
3107,
13458,
2752,
436,
23212,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
961,
2032,
365,
5420,
370,
314,
1727,
1356,
402,
314,
3107,
13458,
1684,
844,
12,
199,
3,
3394,
499,
14,
17,
334,
58,
2749,
680,
221,
437,
1331,
402,
314,
3107,
2749,
1077,
21727,
642,
4084,
14,
199,
3,
5749,
4141,
2281,
7049,
298,
1179,
2281,
2,
2401,
1821,
2401,
11727,
7168,
1549,
5292,
199,
3,
2990,
9315,
9706,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
199,
3,
2990,
1634,
377,
16507,
12,
3169,
12,
437,
9741,
7834,
1621,
12600,
12,
2401,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
199,
3,
199,
4605,
199,
624,
17989,
7868,
282,
1900,
548,
13,
6788,
2199,
199,
199,
51,
3236,
590,
1255,
642,
2884,
315,
282,
2082,
3035,
282,
1900,
548,
14,
4128,
14,
199,
1918,
2884,
11479,
1900,
548,
1414,
13,
604,
1511,
12,
880,
1265,
883,
199,
1180,
314,
446,
67,
945,
370,
4165,
376,
18034,
2897,
570,
14,
199,
624,
199,
199,
646,
747,
199,
646,
5145,
199,
646,
984,
199,
646,
5549,
199,
199,
504,
8691,
492,
13491,
199,
199,
2791,
14488,
275,
5549,
14,
11983,
342,
199,
199,
3807,
275,
18087,
199,
59,
4448,
10322,
18280,
2381,
16331,
1193,
12619,
61,
15865,
14,
647,
359,
1419,
61,
199,
199,
17989,
270,
8146,
282,
1900,
548,
13,
6788,
2199,
14,
199,
199,
51,
3236,
590,
1255,
642,
2884,
315,
282,
2082,
3035,
282,
1900,
548,
14,
4128,
12,
1808,
314,
199,
4718,
626,
1265,
2934,
2517,
15,
1506,
548,
370,
675,
14,
199,
199,
7443,
626,
701,
1808,
1553,
1623,
13,
4614,
370,
2376,
370,
2257,
5944,
12,
1265,
883,
4215,
199,
3749,
2884,
687,
9995,
1806,
314,
2784,
14,
199,
2344,
199,
199,
2087,
275,
13491,
8,
3807,
29,
3807,
9,
199,
2087,
14,
525,
63,
1422,
6096,
86,
401,
4320,
1023,
401,
1720,
628,
1180,
282,
2488,
1315,
67,
14,
1506,
548,
1015,
531,
199,
199,
2087,
14,
525,
63,
1422,
6096,
84,
401,
4320,
5694,
13,
1506,
548,
13,
396,
13,
11840,
401,
2116,
2053,
534,
5694,
63,
1506,
548,
63,
396,
63,
11840,
297,
2116,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
2116,
1720,
15387,
15548,
1183,
12,
340,
1265,
886,
440,
4165,
282,
1553,
1023,
12,
314,
298,
717,
298,
11146,
2884,
436,
1900,
548,
7545,
314,
29608,
298,
717,
8969,
5094,
10,
5459,
402,
1315,
67,
14,
1506,
548,
436,
2399,
17121,
83,
436,
298,
717,
298,
5359,
367,
1265,
14,
221,
982,
1265,
675,
642,
3305,
12,
298,
717,
298,
11146,
436,
1900,
548,
911,
664,
314,
29608,
19015,
298,
717,
298,
12056,
340,
2985,
787,
25363,
503,
2907,
305,
13853,
199,
2087,
14,
525,
63,
1422,
6096,
67,
401,
4320,
888,
13,
493,
401,
2116,
1720,
15387,
17768,
314,
931,
370,
314,
1900,
548,
2897,
298,
717,
298,
493,
370,
506,
1202,
13853,
199,
2087,
14,
525,
63,
1422,
6096,
70,
401,
4320,
1623,
13,
4614,
401,
2116,
1720,
15387,
17768,
282,
2851,
370,
2754,
367,
1900,
548,
19015,
2237,
199,
2087,
14,
525,
63,
1422,
6739,
3306,
13,
2124,
13,
5154,
401,
2116,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
2116,
1720,
15387,
15314,
15865,
14,
647,
675,
3411,
4770,
6117,
2237,
199,
2087,
14,
525,
63,
1422,
6739,
13623,
13,
1023,
401,
2116,
1720,
628,
1180,
282,
2488,
9116,
1015,
531,
421,
199,
1419,
12,
1249,
275,
1798,
14,
1122,
63,
589,
342,
199,
199,
18022,
199,
3,
2248,
15,
3174,
9116,
199,
199,
893,
26,
272,
340,
1511,
14,
3306,
63,
2124,
63,
5154,
26,
267,
492,
9116,
267,
492,
5496,
63,
4435,
272,
687,
4011,
14,
1069,
492,
18279,
199,
2590,
3545,
26,
272,
687,
4011,
18,
492,
18279,
199,
199,
27263,
275,
1052,
199,
1628,
8,
10890,
360,
2859,
921,
11146,
14,
647,
387,
14,
2308,
15,
27263,
63,
2758,
14,
647,
1959,
739,
1062,
325,
90,
9,
199,
199,
692,
440,
1511,
14,
3306,
63,
2124,
63,
5154,
26,
272,
327,
325,
90,
63,
2758,
8925,
4770,
12,
1314,
9584,
4770,
6117,
272,
327,
642,
911,
2813,
3062,
687,
314,
931,
370,
4868,
626,
18457,
5459,
272,
327,
402,
9116,
787,
440,
315,
314,
931,
272,
492,
4770,
272,
327,
6272,
282,
19128,
12,
2337,
365,
949,
283,
362,
2124,
5154,
1370,
272,
327,
2136,
883,
1133,
2813,
3520,
16492,
6665,
272,
340,
2688,
8,
2124,
12,
283,
362,
2124,
5154,
735,
267,
367,
4770,
2491,
63,
515,
315,
4770,
14,
362,
2124,
5154,
837,
288,
984,
14,
515,
5873,
275,
359,
88,
367,
671,
315,
984,
14,
515,
340,
4770,
2491,
63,
515,
440,
315,
671,
61,
199,
199,
2758,
63,
589,
275,
1211,
8,
475,
63,
694,
29,
2791,
14488,
12,
5235,
63,
5814,
29,
16,
9,
199,
199,
692,
1511,
14,
13623,
63,
1023,
365,
440,
488,
26,
272,
3272,
63,
589,
459,
1023,
418,
275,
1511,
14,
13623,
63,
1023,
199,
199,
27263,
459,
1180,
63,
13623,
418,
3682,
2758,
63,
589,
9,
199,
646,
9116,
199,
646,
5496,
63,
4435,
199,
199,
3,
961,
1630,
440,
334,
9223,
17076,
1678,
314,
849,
6449,
663,
14,
221,
2136,
911,
199,
3,
886,
652,
14,
199,
509,
931,
315,
984,
14,
515,
26,
272,
340,
931,
440,
315,
5496,
63,
4435,
14,
9818,
63,
409,
14,
3189,
26,
267,
5496,
63,
4435,
14,
9818,
63,
409,
14,
525,
63,
2373,
8,
515,
9,
199,
199,
18022,
199,
3,
13276,
1900,
548,
199,
199,
3569,
275,
5496,
63,
4435,
14,
9818,
63,
409,
199,
199,
1760,
275,
359,
1274,
14,
5904,
12,
2475,
67,
297,
2126,
283,
504,
9116,
14,
1531,
14,
13581,
63,
3174,
492,
2446,
27,
2446,
19633,
2126,
2475,
77,
58,
81,
46,
2207,
297,
3529,
14488,
61,
199,
199,
1623,
63,
4614,
275,
747,
14,
2314,
14,
362,
8,
272,
283,
11146,
13,
4776,
13,
1623,
13,
4614,
297,
272,
1511,
14,
1623,
63,
4614,
503,
272,
661,
1014,
921,
20373,
14,
1506,
548,
14,
1308,
4805,
1362,
340,
1511,
14,
5694,
63,
1506,
548,
63,
396,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
AkiraKito/fivalid
|
tests/validator_tests.py
|
1
|
11335
|
# -*- coding: utf-8 -*-
import sys, os
import unittest
sys.path.insert(0, os.path.join('..', 'fivalid'))
from validators import (
ValidationError, InvalidTypeError, InvalidValueError,
All, Any,
ValueAdapter,
Not,
Failure, Pass,
Number, FreeText, Equal, Regex,
AllowType, Prefix, Type, Length,
OnelinerText, String, Int,
SortOrder, Flag, Split
)
def err(validator, value, exc=None):
if exc is not None:
try:
validator(value)
except exc:
pass
else:
raise AssertionError('%s is not raised' % exc)
else:
try:
validator(value)
except ValidationError:
pass
else:
raise AssertionError
def suc(validator, value):
try:
validator(value)
except ValidationError, e:
raise AssertionError(e)
class ValidatorTraceBackInfoTest(unittest.TestCase):
def get_generator_test(self):
validator = String()
try:
validator(42)
except ValidationError, e:
gen = e.trace_info()
assert gen
assert hasattr(gen, '__iter__')
assert callable(gen.__iter__)
assert hasattr(gen, 'next')
assert callable(gen.next)
assert hasattr(gen, 'send')
assert callable(gen.send)
assert hasattr(gen, 'throw')
assert callable(gen.throw)
assert hasattr(gen, 'close')
assert callable(gen.close)
else:
raise AssertionError('ValidationError is not raised')
def check_info(self, generator, expected_info):
for index, info in enumerate(generator):
assert info['classname'] == expected_info[index]['classname'],\
'%s != %s' % (info['classname'], expected_info[index]['classname'])
assert info['value'] == expected_info[index]['value'],\
'%s != %s' % (info['value'], expected_info[index]['value'])
assert info['validator'] == expected_info[index]['validator'],\
'%s != %s' % (info['validator'], expected_info[index]['validator'])
def validator_info_from_exc_test(self):
validator = All(String(), Length(min=4))
validatee_value = 42
try:
validator(validatee_value)
except ValidationError, e:
expected_info = [
{'classname': 'All',
'value': validatee_value,
'validator': All(String(), Length(min=4))},
{'classname': 'String',
'value': validatee_value,
'validator': String()}
]
self.check_info(e.trace_info(), expected_info)
else:
raise AssertionError('ValidationError is not raised')
def validator_and_structure_info_from_exc_test(self):
from structures import (
StructuredFields, Dict,
ExtraDataRejection, PackAdapter)
rule = Dict(
foo=All(String(), Length(min=3))
)
validator = StructuredFields(rule)
validatee_value = 42
try:
validator(validatee_value)
except ValidationError, e:
expected_info = [
{'classname': 'Dict',
'value': validatee_value,
'validator': rule},
{'classname': 'All',
'value': validatee_value,
'validator': All(
Type(dict),
PackAdapter(['foo'], ExtraDataRejection()))},
{'classname': 'Type',
'value': validatee_value,
'validator': Type(dict)}
]
self.check_info(e.trace_info(), expected_info)
else:
raise AssertionError('ValidationError is not raised')
def no_nest_Any_test():
v = Any(Int(), String())
suc(v, '12345')
suc(v, 3345)
suc(v, 'aaa')
def no_nest_All_test():
v = All(AllowType(int), String())
suc(v, '2355')
err(v, 2355)
err(v, 'abcd')
def value_adapter_test():
class TestValueAdapter(ValueAdapter):
def on_adapt(self, value):
return str(value)
v = TestValueAdapter(Number())
if not isinstance(v.on_adapt(100), basestring):
raise AssertionError
suc(v, 100)
suc(v, '200')
err(v, 'a')
def not_test():
v = Not(Equal(2))
suc(v, '2000')
err(v, 2)
def failure_test():
v = Failure()
err(v, None)
err(v, 'none')
err(v, 200)
def pass_test():
v = Pass()
suc(v, None)
suc(v, 300)
def number_test():
v = Number()
suc(v, 1)
suc(v, 442300)
suc(v, '3445')
suc(v, 1.33)
suc(v, '3.1415')
err(v, 'ab', InvalidValueError)
err(v, dict(), InvalidTypeError)
vmin = Number(min=0)
suc(vmin, 0)
suc(vmin, 1)
err(vmin, -1, InvalidValueError)
err(vmin, -0.01, InvalidValueError)
suc(vmin, '0')
suc(vmin, 65536)
err(vmin, 'hogepiyo', InvalidValueError)
vmax = Number(max=10)
suc(vmax, 10)
suc(vmax, 9)
err(vmax, 11, InvalidValueError)
err(vmax, 10.01, InvalidValueError)
suc(vmax, '10')
suc(vmax, -2000)
err(vmax, 'x23456', InvalidValueError)
vmm = Number(min=0, max=100)
suc(vmm, 0)
suc(vmm, 100)
err(vmm, -1, InvalidValueError)
err(vmm, 101, InvalidValueError)
suc(vmm, 30)
def freetext_test():
v = FreeText()
suc(v, 'hoge')
suc(v, '232122')
suc(v, 'a33453')
suc(v, '寿限無寿限無五劫の擦り切れ')
suc(v, u'寿限無寿限無五劫の擦り切れ')
suc(v, '寿限無寿限無五劫の擦り切れ\n海砂利水魚の')
suc(v, u'寿限無寿限無五劫の擦り切れ\n海砂利水魚の')
err(v, frozenset([1,2,3]), InvalidTypeError)
vban = FreeText(ban_phrases=['ho', u'五劫'])
suc(vban, 'moge')
suc(vban, '寿限無')
suc(vban, u'の擦り切れ')
err(vban, 'hoge', InvalidValueError)
suc(vban, '寿限無寿限無五劫の擦り切れ')
err(vban, u'寿限無寿限無五劫の擦り切れ', InvalidValueError)
err(vban, '五劫のho', InvalidValueError)
err(vban, u'五劫のho', InvalidValueError)
vig = FreeText(ignore_chars=['oge', '擦り切れ'])
suc(vig, 'moge')
suc(vig, '寿限無寿限無五劫の擦り切れ')
suc(vig, u'寿限無寿限無五劫の擦り切れ')
vbi = FreeText(ban_phrases=['oge', '擦り切'], ignore_chars=['hoge', '五劫の擦り切れ'])
suc(vbi, 'hogetaxi')
err(vbi, 'xoge', InvalidValueError)
suc(vbi, '寿限無寿限無五劫の擦り切れ')
suc(vbi, u'寿限無寿限無五劫の擦り切れ')
err(vbi, 'の擦り切れ', InvalidValueError)
err(vbi, '五●の擦り切れ', InvalidValueError)
def equal_test():
v = Equal('1')
suc(v, '1')
suc(v, u'1')
err(v, 1, InvalidValueError)
err(v, '2', InvalidValueError)
err(v, 2, InvalidValueError)
v2 = Equal(u'寿限無')
suc(v2, u'寿限無')
suc(v2, u'寿限無'.encode('utf-8'))
err(v2, u'寿限無'.encode('euc-jp'), InvalidValueError)
def regex_test():
err(Regex, 1, TypeError)
vterr = Regex('hoge')
err(vterr, 100, InvalidTypeError)
vm = Regex('^hoge')
suc(vm, 'hoge')
err(vm, 'xhoge', InvalidValueError)
suc(vm, 'hogep')
vs = Regex('ho.+ge', is_match=False)
suc(vs, 'hoxge')
suc(vs, 'hoxgep')
suc(vs, 'dhoahfoejaiohoxgep')
err(vs, 'hoge', InvalidValueError)
vmf = Regex('ho.ge', flags='imlsux')
err(vmf, 'hoge', InvalidValueError)
suc(vmf, 'HooGe')
vsf = Regex('hopi', flags=set('lmsuix'))
suc(vsf, 'hopi')
assert Regex('foo') == Regex('foo')
assert Regex('foo') != Regex('bar')
assert Regex('foo') == Regex('foo', is_match=True)
assert Regex('foo') != Regex('foo', is_match=False)
assert Regex('foo', flags='i') == Regex('foo', flags='i')
assert Regex('foo', flags='iu') != Regex('foo', flags='i')
def allowtype_test():
err(AllowType, [], ValueError)
v = AllowType(int)
suc(v, 1)
suc(v, '4423')
err(v, 'jugem', InvalidValueError)
err(v, {}, InvalidTypeError)
def func(exc):
try:
raise exc
except ValueError:
pass
else:
raise AssertionError('ValueError is not raised')
vex = AllowType(float, on_exception=func)
suc(vex, 'aaa')
suc(vex, 1.23)
def prefix_test():
v_ab = Prefix('abc')
suc(v_ab, 'abcdef')
suc(v_ab, 'abc221')
err(v_ab, 'axc000', InvalidValueError)
v_num = Prefix(23)
suc(v_num, 2344)
suc(v_num, '2345')
err(v_num, 2244, InvalidValueError)
def type_test():
vint = Type(int)
suc(vint, 100)
err(vint, '100', InvalidTypeError)
vbs = Type(basestring)
suc(vbs, 'aaa')
suc(vbs, u'君は誰とホトトギス')
err(vbs, 1, InvalidTypeError)
def length_test():
v = Length()
suc(v, '1234567890')
suc(v, 'X' * 1000)
vmin = Length(min=5)
suc(vmin, '12345')
err(vmin, '1234', InvalidValueError)
err(vmin, '', InvalidValueError)
vmax = Length(max=10)
suc(vmax, '1234567890')
suc(vmax, '')
err(vmax, '1234567890a', InvalidValueError)
def onelinertext_test():
v = OnelinerText()
suc(v, 'abcdefg')
suc(v, 'abcdefg' * 100)
err(v, 'abcdef\nGHIJ', InvalidValueError)
err(v, '寿限無\n寿限無', InvalidValueError)
err(v, u'寿限無\n寿限無\n', InvalidValueError)
err(v, '''寿限無
寿限無''', InvalidValueError)
err(v, u'''寿限無
寿限無''', InvalidValueError)
def string_test():
v = String()
suc(v, 'abcdef')
suc(v, '12345')
err(v, 1, InvalidTypeError)
def int_test():
v = Int()
suc(v, 111)
err(v, '1234', InvalidTypeError)
err(v, 'abcdef', InvalidTypeError)
def sortorder_test():
v = SortOrder()
suc(v, 'asc')
suc(v, 'desc')
err(v, 'ascd', InvalidValueError)
err(v, 'description', InvalidValueError)
def flag_test():
v = Flag()
suc(v, 'true')
suc(v, 't')
suc(v, '1')
suc(v, 'false')
suc(v, 'f')
suc(v, '0')
suc(v, 'TRUE')
suc(v, 'F')
def split_test():
v = Split(Equal('HMX'), Number(max=16), sep='-')
suc(v, 'HMX-1')
suc(v, 'HMX-13')
suc(v, 'HMX-16')
err(v, 'HMX-16a', InvalidValueError)
err(v, 'MMX-1', InvalidValueError)
err(v, 'HMX@16', InvalidValueError)
err(v, 'HMX-00-1', InvalidValueError)
v = Split(
Equal('HMX'),
Any(Equal('16a'), Equal('16b'), Equal('16c')),
sep='-')
suc(v, 'HMX-16a')
suc(v, 'HMX-16b')
suc(v, 'HMX-16c')
err(v, 'HMX-16', InvalidValueError)
# left match
v = Split(Pass(), Number(), sep='-')
suc(v, 'xxxxxxx-1024')
suc(v, '-4423')
err(v, '---3', InvalidValueError)
# right match
v = Split(Pass(), Number(), Number(), sep='-', rmatch=True)
suc(v, 'xxxxx200-300-400')
suc(v, '-300-400')
# can not decode to unicode
class Moge(object):
def __repr__(self):
return u'もげ-200'.encode('euc-jp')
v = Split(Pass(), Number(), sep='-')
err(v, Moge(), InvalidValueError)
if __name__ == '__main__':
import nose
nose.main()
|
bsd-2-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
984,
12,
747,
199,
646,
2882,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
904,
24893,
297,
283,
329,
1078,
1333,
199,
504,
14370,
492,
334,
272,
8505,
12,
6378,
4333,
12,
6378,
3393,
12,
272,
2900,
12,
6184,
12,
272,
1594,
10200,
12,
272,
2832,
12,
272,
20367,
12,
8325,
12,
272,
4860,
12,
2868,
1872,
12,
221,
591,
12,
12939,
12,
272,
9812,
804,
12,
25110,
12,
2434,
12,
19893,
12,
272,
593,
2715,
16187,
1872,
12,
2624,
12,
9805,
12,
272,
16722,
4738,
12,
18241,
12,
11740,
199,
9,
421,
199,
318,
2329,
8,
11034,
12,
574,
12,
3178,
29,
403,
304,
272,
340,
3178,
365,
440,
488,
26,
267,
862,
26,
288,
11822,
8,
585,
9,
267,
871,
3178,
26,
288,
986,
267,
587,
26,
288,
746,
9070,
3508,
83,
365,
440,
4915,
7,
450,
3178,
9,
272,
587,
26,
267,
862,
26,
288,
11822,
8,
585,
9,
267,
871,
8505,
26,
288,
986,
267,
587,
26,
288,
746,
9070,
421,
199,
318,
16176,
8,
11034,
12,
574,
304,
272,
862,
26,
267,
11822,
8,
585,
9,
272,
871,
8505,
12,
325,
26,
267,
746,
9070,
8,
69,
9,
421,
199,
533,
4821,
707,
3921,
4540,
2354,
774,
8,
2796,
14,
1746,
304,
339,
347,
664,
63,
4679,
63,
396,
8,
277,
304,
267,
11822,
275,
2624,
342,
267,
862,
26,
288,
11822,
8,
2260,
9,
267,
871,
8505,
12,
325,
26,
288,
3805,
275,
325,
14,
3446,
63,
815,
342,
288,
702,
3805,
288,
702,
2688,
8,
2268,
12,
2560,
1661,
13766,
288,
702,
4550,
8,
2268,
855,
1661,
3368,
288,
702,
2688,
8,
2268,
12,
283,
2184,
358,
288,
702,
4550,
8,
2268,
14,
2184,
9,
288,
702,
2688,
8,
2268,
12,
283,
2254,
358,
288,
702,
4550,
8,
2268,
14,
2254,
9,
288,
702,
2688,
8,
2268,
12,
283,
11964,
358,
288,
702,
4550,
8,
2268,
14,
11964,
9,
288,
702,
2688,
8,
2268,
12,
283,
1600,
358,
288,
702,
4550,
8,
2268,
14,
1600,
9,
267,
587,
26,
288,
746,
9070,
360,
8172,
365,
440,
4915,
358,
339,
347,
1104,
63,
815,
8,
277,
12,
4306,
12,
1420,
63,
815,
304,
267,
367,
1478,
12,
2256,
315,
3874,
8,
4679,
304,
288,
702,
2256,
459,
19851,
418,
508,
1420,
63,
815,
59,
1080,
2733,
19851,
995,
60,
490,
1543,
83,
1137,
450,
83,
7,
450,
334,
815,
459,
19851,
995,
1420,
63,
815,
59,
1080,
2733,
19851,
1105,
288,
702,
2256,
459,
585,
418,
508,
1420,
63,
815,
59,
1080,
2733,
585,
995,
60,
490,
1543,
83,
1137,
450,
83,
7,
450,
334,
815,
459,
585,
995,
1420,
63,
815,
59,
1080,
2733,
585,
1105,
288,
702,
2256,
459,
11034,
418,
508,
1420,
63,
815,
59,
1080,
2733,
11034,
995,
60,
490,
1543,
83,
1137,
450,
83,
7,
450,
334,
815,
459,
11034,
995,
1420,
63,
815,
59,
1080,
2733,
11034,
1105,
2286,
347,
11822,
63,
815,
63,
504,
63,
2804,
63,
396,
8,
277,
304,
267,
11822,
275,
2900,
8,
1558,
1062,
19893,
8,
827,
29,
20,
430,
267,
4107,
69,
63,
585,
275,
5685,
267,
862,
26,
288,
11822,
8,
3502,
69,
63,
585,
9,
267,
871,
8505,
12,
325,
26,
288,
1420,
63,
815,
275,
359,
355,
791,
19851,
356,
283,
2422,
297,
326,
283,
585,
356,
4107,
69,
63,
585,
12,
326,
283,
11034,
356,
2900,
8,
1558,
1062,
19893,
8,
827,
29,
20,
430,
1386,
355,
791,
19851,
356,
283,
1558,
297,
326,
283,
585,
356,
4107,
69,
63,
585,
12,
326,
283,
11034,
356,
2624,
12737,
288,
1622,
288,
291,
14,
1074,
63,
815,
8,
69,
14,
3446,
63,
815,
1062,
1420,
63,
815,
9,
267,
587,
26,
288,
746,
9070,
360,
8172,
365,
440,
4915,
358,
339,
347,
11822,
63,
460,
63,
6976,
63,
815,
63,
504,
63,
2804,
63,
396,
8,
277,
304,
267,
687,
13955,
492,
334,
288,
13039,
3297,
7304,
12,
7448,
12,
288,
11177,
1451,
497,
8923,
12,
9954,
10200,
9,
267,
2332,
275,
7448,
8,
288,
3925,
29,
2422,
8,
1558,
1062,
19893,
8,
827,
29,
19,
430,
267,
776,
267,
11822,
275,
13039,
3297,
7304,
8,
2200,
9,
267,
4107,
69,
63,
585,
275,
5685,
267,
862,
26,
288,
11822,
8,
3502,
69,
63,
585,
9,
267,
871,
8505,
12,
325,
26,
288,
1420,
63,
815,
275,
359,
355,
791,
19851,
356,
283,
2141,
297,
326,
283,
585,
356,
4107,
69,
63,
585,
12,
326,
283,
11034,
356,
2332,
1386,
355,
791,
19851,
356,
283,
2422,
297,
326,
283,
585,
356,
4107,
69,
63,
585,
12,
326,
283,
11034,
356,
2900,
8,
2151,
2434,
8,
807,
395,
2151,
9954,
10200,
2941,
1421,
995,
11177,
1451,
497,
8923,
4059,
1386,
355,
791,
19851,
356,
283,
804,
297,
326,
283,
585,
356,
4107,
69,
63,
585,
12,
326,
283,
11034,
356,
2434,
8,
807,
6769,
288,
1622,
288,
291,
14,
1074,
63,
815,
8,
69,
14,
3446,
63,
815,
1062,
1420,
63,
815,
9,
267,
587,
26,
288,
746,
9070,
360,
8172,
365,
440,
4915,
358,
421,
199,
318,
949,
63,
15272,
63,
9874,
63,
396,
837,
272,
373,
275,
6184,
8,
3241,
1062,
2624,
1012,
272,
16176,
8,
86,
12,
283,
13261,
358,
272,
16176,
8,
86,
12,
650,
9908,
9,
272,
16176,
8,
86,
12,
283,
11629,
358,
421,
199,
318,
949,
63,
15272,
63,
2422,
63,
396,
837,
272,
373,
275,
2900,
8,
7852,
804,
8,
442,
395,
2624,
1012,
272,
16176,
8,
86,
12,
283,
1789,
1229,
358,
272,
2329,
8,
86,
12,
6546,
1229,
9,
272,
2329,
8,
86,
12,
283,
13591,
358,
421,
199,
318,
574,
63,
10394,
63,
396,
837,
272,
1021,
1379,
1110,
10200,
8,
1110,
10200,
304,
267,
347,
641,
63,
19609,
8,
277,
12,
574,
304,
288,
372,
620,
8,
585,
9,
272,
373,
275,
1379,
1110,
10200,
8,
3259,
1012,
272,
340,
440,
1228,
8,
86,
14,
265,
63,
19609,
8,
1960,
395,
7116,
304,
267,
746,
9070,
272,
16176,
8,
86,
12,
2948,
9,
272,
16176,
8,
86,
12,
283,
1840,
358,
272,
2329,
8,
86,
12
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
984,
12,
747,
199,
646,
2882,
199,
1274,
14,
515,
14,
3176,
8,
16,
12,
747,
14,
515,
14,
904,
24893,
297,
283,
329,
1078,
1333,
199,
504,
14370,
492,
334,
272,
8505,
12,
6378,
4333,
12,
6378,
3393,
12,
272,
2900,
12,
6184,
12,
272,
1594,
10200,
12,
272,
2832,
12,
272,
20367,
12,
8325,
12,
272,
4860,
12,
2868,
1872,
12,
221,
591,
12,
12939,
12,
272,
9812,
804,
12,
25110,
12,
2434,
12,
19893,
12,
272,
593,
2715,
16187,
1872,
12,
2624,
12,
9805,
12,
272,
16722,
4738,
12,
18241,
12,
11740,
199,
9,
421,
199,
318,
2329,
8,
11034,
12,
574,
12,
3178,
29,
403,
304,
272,
340,
3178,
365,
440,
488,
26,
267,
862,
26,
288,
11822,
8,
585,
9,
267,
871,
3178,
26,
288,
986,
267,
587,
26,
288,
746,
9070,
3508,
83,
365,
440,
4915,
7,
450,
3178,
9,
272,
587,
26,
267,
862,
26,
288,
11822,
8,
585,
9,
267,
871,
8505,
26,
288,
986,
267,
587,
26,
288,
746,
9070,
421,
199,
318,
16176,
8,
11034,
12,
574,
304,
272,
862,
26,
267,
11822,
8,
585,
9,
272,
871,
8505,
12,
325,
26,
267,
746,
9070,
8,
69,
9,
421,
199,
533,
4821,
707,
3921,
4540,
2354,
774,
8,
2796,
14,
1746,
304,
339,
347,
664,
63,
4679,
63,
396,
8,
277,
304,
267,
11822,
275,
2624,
342,
267,
862,
26,
288,
11822,
8,
2260,
9,
267,
871,
8505,
12,
325,
26,
288,
3805,
275,
325,
14,
3446,
63,
815,
342,
288,
702,
3805,
288,
702,
2688,
8,
2268,
12,
2560,
1661,
13766,
288,
702,
4550,
8,
2268,
855,
1661,
3368,
288,
702,
2688,
8,
2268,
12,
283,
2184,
358,
288,
702,
4550,
8,
2268,
14,
2184,
9,
288,
702,
2688,
8,
2268,
12,
283,
2254,
358,
288,
702,
4550,
8,
2268,
14,
2254,
9,
288,
702,
2688,
8,
2268,
12,
283,
11964,
358,
288,
702,
4550,
8,
2268,
14,
11964,
9,
288,
702,
2688,
8,
2268,
12,
283,
1600,
358,
288,
702,
4550,
8,
2268,
14,
1600,
9,
267,
587,
26,
288,
746,
9070,
360,
8172,
365,
440,
4915,
358,
339,
347,
1104,
63,
815,
8,
277,
12,
4306,
12,
1420,
63,
815,
304,
267,
367,
1478,
12,
2256,
315,
3874,
8,
4679,
304,
288,
702,
2256,
459,
19851,
418,
508,
1420,
63,
815,
59,
1080,
2733,
19851,
995,
60,
490,
1543,
83,
1137,
450,
83,
7,
450,
334,
815,
459,
19851,
995,
1420,
63,
815,
59,
1080,
2733,
19851,
1105,
288,
702,
2256,
459,
585,
418,
508,
1420,
63,
815,
59,
1080,
2733,
585,
995,
60,
490,
1543,
83,
1137,
450,
83,
7,
450,
334,
815,
459,
585,
995,
1420,
63,
815,
59,
1080,
2733,
585,
1105,
288,
702,
2256,
459,
11034,
418,
508,
1420,
63,
815,
59,
1080,
2733,
11034,
995,
60,
490,
1543,
83,
1137,
450,
83,
7,
450,
334,
815,
459,
11034,
995,
1420,
63,
815,
59,
1080,
2733,
11034,
1105,
2286,
347,
11822,
63,
815,
63,
504,
63,
2804,
63,
396,
8,
277,
304,
267,
11822,
275,
2900,
8,
1558,
1062,
19893,
8,
827,
29,
20,
430,
267,
4107,
69,
63,
585,
275,
5685,
267,
862,
26,
288,
11822,
8,
3502,
69,
63,
585,
9,
267,
871,
8505,
12,
325,
26,
288,
1420,
63,
815,
275,
359,
355,
791,
19851,
356,
283,
2422,
297,
326,
283,
585,
356,
4107,
69,
63,
585,
12,
326,
283,
11034,
356,
2900,
8,
1558,
1062,
19893,
8,
827,
29,
20,
430,
1386,
355,
791,
19851,
356,
283,
1558,
297,
326,
283,
585,
356,
4107,
69,
63,
585,
12,
326,
283,
11034,
356,
2624,
12737,
288,
1622,
288,
291,
14,
1074,
63,
815,
8,
69,
14,
3446,
63,
815,
1062,
1420,
63,
815,
9,
267,
587,
26,
288,
746,
9070,
360,
8172,
365,
440,
4915,
358,
339,
347,
11822,
63,
460,
63,
6976,
63,
815,
63,
504,
63,
2804,
63,
396,
8,
277,
304,
267,
687,
13955,
492,
334,
288,
13039,
3297,
7304,
12,
7448,
12,
288,
11177,
1451,
497,
8923,
12,
9954,
10200,
9,
267,
2332,
275,
7448,
8,
288,
3925,
29,
2422,
8,
1558,
1062,
19893,
8,
827,
29,
19,
430,
267,
776,
267,
11822,
275,
13039,
3297,
7304,
8,
2200,
9,
267,
4107,
69,
63,
585,
275,
5685,
267,
862,
26,
288,
11822,
8,
3502,
69,
63,
585,
9,
267,
871,
8505,
12,
325,
26,
288,
1420,
63,
815,
275,
359,
355,
791,
19851,
356,
283,
2141,
297,
326,
283,
585,
356,
4107,
69,
63,
585,
12,
326,
283,
11034,
356,
2332,
1386,
355,
791,
19851,
356,
283,
2422,
297,
326,
283,
585,
356,
4107,
69,
63,
585,
12,
326,
283,
11034,
356,
2900,
8,
2151,
2434,
8,
807,
395,
2151,
9954,
10200,
2941,
1421,
995,
11177,
1451,
497,
8923,
4059,
1386,
355,
791,
19851,
356,
283,
804,
297,
326,
283,
585,
356,
4107,
69,
63,
585,
12,
326,
283,
11034,
356,
2434,
8,
807,
6769,
288,
1622,
288,
291,
14,
1074,
63,
815,
8,
69,
14,
3446,
63,
815,
1062,
1420,
63,
815,
9,
267,
587,
26,
288,
746,
9070,
360,
8172,
365,
440,
4915,
358,
421,
199,
318,
949,
63,
15272,
63,
9874,
63,
396,
837,
272,
373,
275,
6184,
8,
3241,
1062,
2624,
1012,
272,
16176,
8,
86,
12,
283,
13261,
358,
272,
16176,
8,
86,
12,
650,
9908,
9,
272,
16176,
8,
86,
12,
283,
11629,
358,
421,
199,
318,
949,
63,
15272,
63,
2422,
63,
396,
837,
272,
373,
275,
2900,
8,
7852,
804,
8,
442,
395,
2624,
1012,
272,
16176,
8,
86,
12,
283,
1789,
1229,
358,
272,
2329,
8,
86,
12,
6546,
1229,
9,
272,
2329,
8,
86,
12,
283,
13591,
358,
421,
199,
318,
574,
63,
10394,
63,
396,
837,
272,
1021,
1379,
1110,
10200,
8,
1110,
10200,
304,
267,
347,
641,
63,
19609,
8,
277,
12,
574,
304,
288,
372,
620,
8,
585,
9,
272,
373,
275,
1379,
1110,
10200,
8,
3259,
1012,
272,
340,
440,
1228,
8,
86,
14,
265,
63,
19609,
8,
1960,
395,
7116,
304,
267,
746,
9070,
272,
16176,
8,
86,
12,
2948,
9,
272,
16176,
8,
86,
12,
283,
1840,
358,
272,
2329,
8,
86,
12,
0
] |
[
1,
1,
1,
1,
1,
1,
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ib/pyminer/pyminer.py
|
1257
|
6438
|
#!/usr/bin/python
#
# Copyright (c) 2011 The Bitcoin developers
# Distributed under the MIT/X11 software license, see the accompanying
# file license.txt or http://www.opensource.org/licenses/mit-license.php.
#
import time
import json
import pprint
import hashlib
import struct
import re
import base64
import httplib
import sys
from multiprocessing import Process
ERR_SLEEP = 15
MAX_NONCE = 1000000L
settings = {}
pp = pprint.PrettyPrinter(indent=4)
class BitcoinRPC:
OBJID = 1
def __init__(self, host, port, username, password):
authpair = "%s:%s" % (username, password)
self.authhdr = "Basic %s" % (base64.b64encode(authpair))
self.conn = httplib.HTTPConnection(host, port, False, 30)
def rpc(self, method, params=None):
self.OBJID += 1
obj = { 'version' : '1.1',
'method' : method,
'id' : self.OBJID }
if params is None:
obj['params'] = []
else:
obj['params'] = params
self.conn.request('POST', '/', json.dumps(obj),
{ 'Authorization' : self.authhdr,
'Content-type' : 'application/json' })
resp = self.conn.getresponse()
if resp is None:
print "JSON-RPC: no response"
return None
body = resp.read()
resp_obj = json.loads(body)
if resp_obj is None:
print "JSON-RPC: cannot JSON-decode body"
return None
if 'error' in resp_obj and resp_obj['error'] != None:
return resp_obj['error']
if 'result' not in resp_obj:
print "JSON-RPC: no result in object"
return None
return resp_obj['result']
def getblockcount(self):
return self.rpc('getblockcount')
def getwork(self, data=None):
return self.rpc('getwork', data)
def uint32(x):
return x & 0xffffffffL
def bytereverse(x):
return uint32(( ((x) << 24) | (((x) << 8) & 0x00ff0000) |
(((x) >> 8) & 0x0000ff00) | ((x) >> 24) ))
def bufreverse(in_buf):
out_words = []
for i in range(0, len(in_buf), 4):
word = struct.unpack('@I', in_buf[i:i+4])[0]
out_words.append(struct.pack('@I', bytereverse(word)))
return ''.join(out_words)
def wordreverse(in_buf):
out_words = []
for i in range(0, len(in_buf), 4):
out_words.append(in_buf[i:i+4])
out_words.reverse()
return ''.join(out_words)
class Miner:
def __init__(self, id):
self.id = id
self.max_nonce = MAX_NONCE
def work(self, datastr, targetstr):
# decode work data hex string to binary
static_data = datastr.decode('hex')
static_data = bufreverse(static_data)
# the first 76b of 80b do not change
blk_hdr = static_data[:76]
# decode 256-bit target value
targetbin = targetstr.decode('hex')
targetbin = targetbin[::-1] # byte-swap and dword-swap
targetbin_str = targetbin.encode('hex')
target = long(targetbin_str, 16)
# pre-hash first 76b of block header
static_hash = hashlib.sha256()
static_hash.update(blk_hdr)
for nonce in xrange(self.max_nonce):
# encode 32-bit nonce value
nonce_bin = struct.pack("<I", nonce)
# hash final 4b, the nonce value
hash1_o = static_hash.copy()
hash1_o.update(nonce_bin)
hash1 = hash1_o.digest()
# sha256 hash of sha256 hash
hash_o = hashlib.sha256()
hash_o.update(hash1)
hash = hash_o.digest()
# quick test for winning solution: high 32 bits zero?
if hash[-4:] != '\0\0\0\0':
continue
# convert binary hash to 256-bit Python long
hash = bufreverse(hash)
hash = wordreverse(hash)
hash_str = hash.encode('hex')
l = long(hash_str, 16)
# proof-of-work test: hash < target
if l < target:
print time.asctime(), "PROOF-OF-WORK found: %064x" % (l,)
return (nonce + 1, nonce_bin)
else:
print time.asctime(), "PROOF-OF-WORK false positive %064x" % (l,)
# return (nonce + 1, nonce_bin)
return (nonce + 1, None)
def submit_work(self, rpc, original_data, nonce_bin):
nonce_bin = bufreverse(nonce_bin)
nonce = nonce_bin.encode('hex')
solution = original_data[:152] + nonce + original_data[160:256]
param_arr = [ solution ]
result = rpc.getwork(param_arr)
print time.asctime(), "--> Upstream RPC result:", result
def iterate(self, rpc):
work = rpc.getwork()
if work is None:
time.sleep(ERR_SLEEP)
return
if 'data' not in work or 'target' not in work:
time.sleep(ERR_SLEEP)
return
time_start = time.time()
(hashes_done, nonce_bin) = self.work(work['data'],
work['target'])
time_end = time.time()
time_diff = time_end - time_start
self.max_nonce = long(
(hashes_done * settings['scantime']) / time_diff)
if self.max_nonce > 0xfffffffaL:
self.max_nonce = 0xfffffffaL
if settings['hashmeter']:
print "HashMeter(%d): %d hashes, %.2f Khash/sec" % (
self.id, hashes_done,
(hashes_done / 1000.0) / time_diff)
if nonce_bin is not None:
self.submit_work(rpc, work['data'], nonce_bin)
def loop(self):
rpc = BitcoinRPC(settings['host'], settings['port'],
settings['rpcuser'], settings['rpcpass'])
if rpc is None:
return
while True:
self.iterate(rpc)
def miner_thread(id):
miner = Miner(id)
miner.loop()
if __name__ == '__main__':
if len(sys.argv) != 2:
print "Usage: pyminer.py CONFIG-FILE"
sys.exit(1)
f = open(sys.argv[1])
for line in f:
# skip comment lines
m = re.search('^\s*#', line)
if m:
continue
# parse key=value lines
m = re.search('^(\w+)\s*=\s*(\S.*)$', line)
if m is None:
continue
settings[m.group(1)] = m.group(2)
f.close()
if 'host' not in settings:
settings['host'] = '127.0.0.1'
if 'port' not in settings:
settings['port'] = 8332
if 'threads' not in settings:
settings['threads'] = 1
if 'hashmeter' not in settings:
settings['hashmeter'] = 0
if 'scantime' not in settings:
settings['scantime'] = 30L
if 'rpcuser' not in settings or 'rpcpass' not in settings:
print "Missing username and/or password in cfg file"
sys.exit(1)
settings['port'] = int(settings['port'])
settings['threads'] = int(settings['threads'])
settings['hashmeter'] = int(settings['hashmeter'])
settings['scantime'] = long(settings['scantime'])
thr_list = []
for thr_id in range(settings['threads']):
p = Process(target=miner_thread, args=(thr_id,))
p.start()
thr_list.append(p)
time.sleep(1) # stagger threads
print settings['threads'], "mining threads started"
print time.asctime(), "Miner Starts - %s:%s" % (settings['host'], settings['port'])
try:
for thr_proc in thr_list:
thr_proc.join()
except KeyboardInterrupt:
pass
print time.asctime(), "Miner Stops - %s:%s" % (settings['host'], settings['port'])
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
67,
9,
7760,
710,
21158,
19782,
199,
3,
17484,
1334,
314,
10697,
15,
56,
845,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
4190,
14,
2424,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
3,
199,
199,
646,
900,
199,
646,
2022,
199,
646,
10933,
199,
646,
8337,
199,
646,
2702,
199,
646,
295,
199,
646,
1300,
772,
199,
646,
8809,
199,
646,
984,
199,
504,
12866,
492,
7132,
199,
199,
2666,
63,
51,
906,
6102,
275,
4114,
199,
4283,
63,
13887,
2089,
275,
19492,
44,
199,
199,
1751,
275,
1052,
199,
802,
275,
10933,
14,
27153,
14131,
8,
3724,
29,
20,
9,
199,
199,
533,
21158,
8171,
26,
199,
198,
15862,
998,
275,
413,
421,
198,
318,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
3434,
12,
2505,
304,
507,
198,
1178,
3852,
275,
2071,
83,
2689,
83,
2,
450,
334,
2473,
12,
2505,
9,
507,
198,
277,
14,
1178,
11244,
275,
298,
6845,
450,
83,
2,
450,
334,
1095,
772,
14,
66,
772,
2143,
8,
1178,
3852,
430,
507,
198,
277,
14,
1631,
275,
8809,
14,
19114,
8,
1102,
12,
1844,
12,
756,
12,
4233,
9,
199,
198,
318,
8985,
8,
277,
12,
1083,
12,
1862,
29,
403,
304,
507,
198,
277,
14,
15862,
998,
847,
413,
507,
198,
1113,
275,
469,
283,
1023,
7,
520,
283,
17,
14,
17,
297,
686,
198,
6704,
69,
594,
7,
520,
1083,
12,
686,
198,
7,
344,
7,
520,
291,
14,
15862,
998,
789,
507,
198,
692,
1862,
365,
488,
26,
686,
198,
1113,
459,
1162,
418,
275,
942,
507,
198,
2836,
26,
686,
198,
1113,
459,
1162,
418,
275,
1862,
507,
198,
277,
14,
1631,
14,
1069,
360,
4030,
297,
17220,
2022,
14,
4180,
8,
1113,
395,
686,
198,
91,
283,
11626,
7,
520,
291,
14,
1178,
11244,
12,
1585,
221,
283,
2714,
13,
466,
7,
520,
283,
3578,
15,
1001,
7,
3828,
2742,
198,
4518,
275,
291,
14,
1631,
14,
25006,
342,
507,
198,
692,
3085,
365,
488,
26,
686,
198,
1361,
298,
6243,
13,
8171,
26,
949,
1177,
2,
686,
198,
1107,
488,
2742,
198,
2030,
275,
3085,
14,
739,
342,
507,
198,
4518,
63,
1113,
275,
2022,
14,
3640,
8,
2030,
9,
507,
198,
692,
3085,
63,
1113,
365,
488,
26,
686,
198,
1361,
298,
6243,
13,
8171,
26,
3913,
4840,
13,
2708,
2396,
2,
686,
198,
1107,
488,
507,
198,
692,
283,
705,
7,
315,
3085,
63,
1113,
436,
3085,
63,
1113,
459,
705,
418,
1137,
488,
26,
686,
198,
1107,
3085,
63,
1113,
459,
705,
418,
507,
198,
692,
283,
1099,
7,
440,
315,
3085,
63,
1113,
26,
686,
198,
1361,
298,
6243,
13,
8171,
26,
949,
754,
315,
909,
2,
686,
198,
1107,
488,
2742,
198,
1107,
3085,
63,
1113,
459,
1099,
418,
199,
198,
318,
664,
1457,
835,
8,
277,
304,
507,
198,
1107,
291,
14,
4354,
360,
30710,
358,
199,
198,
318,
664,
800,
8,
277,
12,
666,
29,
403,
304,
507,
198,
1107,
291,
14,
4354,
360,
362,
800,
297,
666,
9,
199,
199,
318,
3152,
708,
8,
88,
304,
199,
198,
1107,
671,
1253,
378,
21870,
44,
199,
199,
318,
3696,
4471,
8,
88,
304,
199,
198,
1107,
3152,
708,
1332,
3666,
88,
9,
5213,
5504,
9,
1204,
20337,
88,
9,
5213,
1695,
9,
1253,
378,
88,
383,
556,
993,
9,
1204,
686,
198,
12925,
88,
9,
4331,
1695,
9,
1253,
378,
88,
993,
556,
383,
9,
1204,
3666,
88,
9,
4331,
5504,
9,
5082,
199,
199,
318,
4123,
4471,
8,
262,
63,
1436,
304,
199,
198,
548,
63,
3148,
275,
942,
199,
198,
509,
284,
315,
1425,
8,
16,
12,
822,
8,
262,
63,
1436,
395,
841,
304,
507,
198,
1027,
275,
2702,
14,
5301,
16591,
41,
297,
315,
63,
1436,
59,
73,
26,
73,
11,
20,
11057,
16,
61,
507,
198,
548,
63,
3148,
14,
740,
8,
1820,
14,
1389,
16591,
41,
297,
3696,
4471,
8,
1027,
1724,
199,
198,
1107,
6522,
904,
8,
548,
63,
3148,
9,
199,
199,
318,
4349,
4471,
8,
262,
63,
1436,
304,
199,
198,
548,
63,
3148,
275,
942,
199,
198,
509,
284,
315,
1425,
8,
16,
12,
822,
8,
262,
63,
1436,
395,
841,
304,
507,
198,
548,
63,
3148,
14,
740,
8,
262,
63,
1436,
59,
73,
26,
73,
11,
20,
566,
199,
198,
548,
63,
3148,
14,
4471,
342,
199,
198,
1107,
6522,
904,
8,
548,
63,
3148,
9,
199,
199,
533,
10195,
281,
26,
199,
198,
318,
636,
826,
721,
277,
12,
1305,
304,
507,
198,
277,
14,
344,
275,
1305,
507,
198,
277,
14,
988,
63,
10667,
275,
9141,
63,
13887,
2089,
421,
198,
318,
1736,
8,
277,
12,
666,
495,
12,
1347,
495,
304,
507,
198,
3,
4849,
1736,
666,
6318,
1059,
370,
3366,
507,
198,
1986,
63,
576,
275,
666,
495,
14,
2708,
360,
4097,
358,
507,
198,
1986,
63,
576,
275,
4123,
4471,
8,
1986,
63,
576,
9,
2742,
198,
3,
314,
1642,
14646,
66,
402,
5939,
66,
886,
440,
1570,
507,
198,
14023,
63,
11244,
275,
2955,
63,
576,
1491,
2114,
61,
2742,
198,
3,
4849,
7633,
13,
2075,
1347,
574,
507,
198,
1375,
1393,
275,
1347,
495,
14,
2708,
360,
4097,
358,
507,
198,
1375,
1393,
275,
1347,
1393,
14172,
17,
61,
198,
3,
3696,
13,
9286,
436,
366,
1027,
13,
9286,
507,
198,
1375,
1393,
63,
495,
275,
1347,
1393,
14,
2143,
360,
4097,
358,
507,
198,
1375,
275,
1846,
8,
1375,
1393,
63,
495,
12,
3193,
9,
2742,
198,
3,
876,
13,
2227,
1642,
14646,
66,
402,
1853,
1406,
507,
198,
1986,
63,
2227,
275,
8337,
14,
4835,
3912,
342,
507,
198,
1986,
63,
2227,
14,
873,
8,
14023,
63,
11244,
9,
2742,
198,
509,
13711,
315,
4945,
8,
277,
14,
988,
63,
10667,
304,
6319,
198,
3,
3752,
4337,
13,
2075,
13711,
574,
686,
198,
10667,
63,
1393,
275,
2702,
14,
1389,
6757,
41,
401,
13711,
9,
6319,
198,
3,
2631,
4242,
841,
66,
12,
314,
13711,
574,
686,
198,
2227,
17,
63,
79,
275,
2955,
63,
2227,
14
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
67,
9,
7760,
710,
21158,
19782,
199,
3,
17484,
1334,
314,
10697,
15,
56,
845,
2032,
4190,
12,
1937,
314,
23073,
199,
3,
570,
4190,
14,
2424,
503,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
14,
199,
3,
199,
199,
646,
900,
199,
646,
2022,
199,
646,
10933,
199,
646,
8337,
199,
646,
2702,
199,
646,
295,
199,
646,
1300,
772,
199,
646,
8809,
199,
646,
984,
199,
504,
12866,
492,
7132,
199,
199,
2666,
63,
51,
906,
6102,
275,
4114,
199,
4283,
63,
13887,
2089,
275,
19492,
44,
199,
199,
1751,
275,
1052,
199,
802,
275,
10933,
14,
27153,
14131,
8,
3724,
29,
20,
9,
199,
199,
533,
21158,
8171,
26,
199,
198,
15862,
998,
275,
413,
421,
198,
318,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
3434,
12,
2505,
304,
507,
198,
1178,
3852,
275,
2071,
83,
2689,
83,
2,
450,
334,
2473,
12,
2505,
9,
507,
198,
277,
14,
1178,
11244,
275,
298,
6845,
450,
83,
2,
450,
334,
1095,
772,
14,
66,
772,
2143,
8,
1178,
3852,
430,
507,
198,
277,
14,
1631,
275,
8809,
14,
19114,
8,
1102,
12,
1844,
12,
756,
12,
4233,
9,
199,
198,
318,
8985,
8,
277,
12,
1083,
12,
1862,
29,
403,
304,
507,
198,
277,
14,
15862,
998,
847,
413,
507,
198,
1113,
275,
469,
283,
1023,
7,
520,
283,
17,
14,
17,
297,
686,
198,
6704,
69,
594,
7,
520,
1083,
12,
686,
198,
7,
344,
7,
520,
291,
14,
15862,
998,
789,
507,
198,
692,
1862,
365,
488,
26,
686,
198,
1113,
459,
1162,
418,
275,
942,
507,
198,
2836,
26,
686,
198,
1113,
459,
1162,
418,
275,
1862,
507,
198,
277,
14,
1631,
14,
1069,
360,
4030,
297,
17220,
2022,
14,
4180,
8,
1113,
395,
686,
198,
91,
283,
11626,
7,
520,
291,
14,
1178,
11244,
12,
1585,
221,
283,
2714,
13,
466,
7,
520,
283,
3578,
15,
1001,
7,
3828,
2742,
198,
4518,
275,
291,
14,
1631,
14,
25006,
342,
507,
198,
692,
3085,
365,
488,
26,
686,
198,
1361,
298,
6243,
13,
8171,
26,
949,
1177,
2,
686,
198,
1107,
488,
2742,
198,
2030,
275,
3085,
14,
739,
342,
507,
198,
4518,
63,
1113,
275,
2022,
14,
3640,
8,
2030,
9,
507,
198,
692,
3085,
63,
1113,
365,
488,
26,
686,
198,
1361,
298,
6243,
13,
8171,
26,
3913,
4840,
13,
2708,
2396,
2,
686,
198,
1107,
488,
507,
198,
692,
283,
705,
7,
315,
3085,
63,
1113,
436,
3085,
63,
1113,
459,
705,
418,
1137,
488,
26,
686,
198,
1107,
3085,
63,
1113,
459,
705,
418,
507,
198,
692,
283,
1099,
7,
440,
315,
3085,
63,
1113,
26,
686,
198,
1361,
298,
6243,
13,
8171,
26,
949,
754,
315,
909,
2,
686,
198,
1107,
488,
2742,
198,
1107,
3085,
63,
1113,
459,
1099,
418,
199,
198,
318,
664,
1457,
835,
8,
277,
304,
507,
198,
1107,
291,
14,
4354,
360,
30710,
358,
199,
198,
318,
664,
800,
8,
277,
12,
666,
29,
403,
304,
507,
198,
1107,
291,
14,
4354,
360,
362,
800,
297,
666,
9,
199,
199,
318,
3152,
708,
8,
88,
304,
199,
198,
1107,
671,
1253,
378,
21870,
44,
199,
199,
318,
3696,
4471,
8,
88,
304,
199,
198,
1107,
3152,
708,
1332,
3666,
88,
9,
5213,
5504,
9,
1204,
20337,
88,
9,
5213,
1695,
9,
1253,
378,
88,
383,
556,
993,
9,
1204,
686,
198,
12925,
88,
9,
4331,
1695,
9,
1253,
378,
88,
993,
556,
383,
9,
1204,
3666,
88,
9,
4331,
5504,
9,
5082,
199,
199,
318,
4123,
4471,
8,
262,
63,
1436,
304,
199,
198,
548,
63,
3148,
275,
942,
199,
198,
509,
284,
315,
1425,
8,
16,
12,
822,
8,
262,
63,
1436,
395,
841,
304,
507,
198,
1027,
275,
2702,
14,
5301,
16591,
41,
297,
315,
63,
1436,
59,
73,
26,
73,
11,
20,
11057,
16,
61,
507,
198,
548,
63,
3148,
14,
740,
8,
1820,
14,
1389,
16591,
41,
297,
3696,
4471,
8,
1027,
1724,
199,
198,
1107,
6522,
904,
8,
548,
63,
3148,
9,
199,
199,
318,
4349,
4471,
8,
262,
63,
1436,
304,
199,
198,
548,
63,
3148,
275,
942,
199,
198,
509,
284,
315,
1425,
8,
16,
12,
822,
8,
262,
63,
1436,
395,
841,
304,
507,
198,
548,
63,
3148,
14,
740,
8,
262,
63,
1436,
59,
73,
26,
73,
11,
20,
566,
199,
198,
548,
63,
3148,
14,
4471,
342,
199,
198,
1107,
6522,
904,
8,
548,
63,
3148,
9,
199,
199,
533,
10195,
281,
26,
199,
198,
318,
636,
826,
721,
277,
12,
1305,
304,
507,
198,
277,
14,
344,
275,
1305,
507,
198,
277,
14,
988,
63,
10667,
275,
9141,
63,
13887,
2089,
421,
198,
318,
1736,
8,
277,
12,
666,
495,
12,
1347,
495,
304,
507,
198,
3,
4849,
1736,
666,
6318,
1059,
370,
3366,
507,
198,
1986,
63,
576,
275,
666,
495,
14,
2708,
360,
4097,
358,
507,
198,
1986,
63,
576,
275,
4123,
4471,
8,
1986,
63,
576,
9,
2742,
198,
3,
314,
1642,
14646,
66,
402,
5939,
66,
886,
440,
1570,
507,
198,
14023,
63,
11244,
275,
2955,
63,
576,
1491,
2114,
61,
2742,
198,
3,
4849,
7633,
13,
2075,
1347,
574,
507,
198,
1375,
1393,
275,
1347,
495,
14,
2708,
360,
4097,
358,
507,
198,
1375,
1393,
275,
1347,
1393,
14172,
17,
61,
198,
3,
3696,
13,
9286,
436,
366,
1027,
13,
9286,
507,
198,
1375,
1393,
63,
495,
275,
1347,
1393,
14,
2143,
360,
4097,
358,
507,
198,
1375,
275,
1846,
8,
1375,
1393,
63,
495,
12,
3193,
9,
2742,
198,
3,
876,
13,
2227,
1642,
14646,
66,
402,
1853,
1406,
507,
198,
1986,
63,
2227,
275,
8337,
14,
4835,
3912,
342,
507,
198,
1986,
63,
2227,
14,
873,
8,
14023,
63,
11244,
9,
2742,
198,
509,
13711,
315,
4945,
8,
277,
14,
988,
63,
10667,
304,
6319,
198,
3,
3752,
4337,
13,
2075,
13711,
574,
686,
198,
10667,
63,
1393,
275,
2702,
14,
1389,
6757,
41,
401,
13711,
9,
6319,
198,
3,
2631,
4242,
841,
66,
12,
314,
13711,
574,
686,
198,
2227,
17,
63,
79,
275,
2955,
63,
2227,
14,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
40223231/Final-Exam-with-classmate
|
static/Brython3.1.1-20150328-091302/Lib/site-packages/pygame/__init__.py
|
603
|
6082
|
## pygame - Python Game Library
## Copyright (C) 2000-2001 Pete Shinners
##
## This library is free software; you can redistribute it and/or
## modify it under the terms of the GNU Library General Public
## License as published by the Free Software Foundation; either
## version 2 of the License, or (at your option) any later version.
##
## This library is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## Library General Public License for more details.
##
## You should have received a copy of the GNU Library General Public
## License along with this library; if not, write to the Free
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
## Pete Shinners
## pete@shinners.org
'''Top-level Pygame module.
Pygame is a set of Python modules designed for writing games.
It is written on top of the excellent SDL library. This allows you
to create fully featured games and multimedia programs in the Python
language. The package is highly portable, with games running on
Windows, MacOS, OS X, BeOS, FreeBSD, IRIX, and Linux.
'''
__docformat__ = 'restructuredtext'
__version__ = '$Id$'
import os
import sys
class MissingModule:
def __init__(self, name, info='', urgent=0):
self.name = name
self.info = str(info)
self.urgent = urgent
if urgent:
self.warn()
def __getattr__(self, var):
if not self.urgent:
self.warn()
self.urgent = 1
MissingPygameModule = "%s module not available" % self.name
raise NotImplementedError(MissingPygameModule)
def __nonzero__(self):
return 0
def warn(self):
if self.urgent: type = 'import'
else: type = 'use'
message = '%s %s: %s' % (type, self.name, self.info)
try:
import warnings
if self.urgent: level = 4
else: level = 3
warnings.warn(message, RuntimeWarning, level)
except ImportError:
print(message)
#we need to import like this, each at a time. the cleanest way to import
#our modules is with the import command (not the __import__ function)
#first, the "required" modules
#from pygame.array import * #brython fix me
from pygame.base import *
from pygame.constants import *
from pygame.version import *
from pygame.rect import Rect
import pygame.color
Color = pygame.color.Color
__version__ = ver
#added by earney
from . import time
from . import display
from . import constants
from . import event
from . import font
from . import mixer
from . import sprite
from .surface import Surface
from . import image
from . import mouse
from . import transform
#next, the "standard" modules
#we still allow them to be missing for stripped down pygame distributions
'''
try: import pygame.cdrom
except (ImportError,IOError), msg:cdrom=MissingModule("cdrom", msg, 1)
try: import pygame.cursors
except (ImportError,IOError), msg:cursors=MissingModule("cursors", msg, 1)
try: import pygame.display
except (ImportError,IOError), msg:display=MissingModule("display", msg, 1)
try: import pygame.draw
except (ImportError,IOError), msg:draw=MissingModule("draw", msg, 1)
try: import pygame.event
except (ImportError,IOError), msg:event=MissingModule("event", msg, 1)
try: import pygame.image
except (ImportError,IOError), msg:image=MissingModule("image", msg, 1)
try: import pygame.joystick
except (ImportError,IOError), msg:joystick=MissingModule("joystick", msg, 1)
try: import pygame.key
except (ImportError,IOError), msg:key=MissingModule("key", msg, 1)
try: import pygame.mouse
except (ImportError,IOError), msg:mouse=MissingModule("mouse", msg, 1)
try: import pygame.sprite
except (ImportError,IOError), msg:sprite=MissingModule("sprite", msg, 1)
try: from pygame.surface import Surface
except (ImportError,IOError):Surface = lambda:Missing_Function
try: from pygame.overlay import Overlay
except (ImportError,IOError):Overlay = lambda:Missing_Function
try: import pygame.time
except (ImportError,IOError), msg:time=MissingModule("time", msg, 1)
try: import pygame.transform
except (ImportError,IOError), msg:transform=MissingModule("transform", msg, 1)
#lastly, the "optional" pygame modules
try:
import pygame.font
import pygame.sysfont
pygame.font.SysFont = pygame.sysfont.SysFont
pygame.font.get_fonts = pygame.sysfont.get_fonts
pygame.font.match_font = pygame.sysfont.match_font
except (ImportError,IOError), msg:font=MissingModule("font", msg, 0)
try: import pygame.mixer
except (ImportError,IOError), msg:mixer=MissingModule("mixer", msg, 0)
#try: import pygame.movie
#except (ImportError,IOError), msg:movie=MissingModule("movie", msg, 0)
#try: import pygame.movieext
#except (ImportError,IOError), msg:movieext=MissingModule("movieext", msg, 0)
try: import pygame.surfarray
except (ImportError,IOError), msg:surfarray=MissingModule("surfarray", msg, 0)
try: import pygame.sndarray
except (ImportError,IOError), msg:sndarray=MissingModule("sndarray", msg, 0)
#try: import pygame.fastevent
#except (ImportError,IOError), msg:fastevent=MissingModule("fastevent", msg, 0)
#there's also a couple "internal" modules not needed
#by users, but putting them here helps "dependency finder"
#programs get everything they need (like py2exe)
try: import pygame.imageext; del pygame.imageext
except (ImportError,IOError):pass
try: import pygame.mixer_music; del pygame.mixer_music
except (ImportError,IOError):pass
def packager_imports():
"""
Some additional things that py2app/py2exe will want to see
"""
import OpenGL.GL
'''
#make Rects pickleable
import copyreg
def __rect_constructor(x,y,w,h):
return Rect(x,y,w,h)
def __rect_reduce(r):
assert type(r) == Rect
return __rect_constructor, (r.x, r.y, r.w, r.h)
copyreg.pickle(Rect, __rect_reduce, __rect_constructor)
#cleanup namespace
del pygame, os, sys, #TODO rwobject, surflock, MissingModule, copy_reg
|
gpl-3.0
|
[
309,
259,
9193,
446,
2018,
25132,
11243,
199,
309,
259,
1898,
334,
35,
9,
12293,
13,
8339,
221,
11379,
266,
5244,
262,
8715,
199,
309,
199,
309,
259,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
259,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
11243,
1696,
1684,
199,
309,
259,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
309,
259,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
259,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
259,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
199,
309,
259,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
199,
309,
259,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
309,
199,
309,
259,
11379,
266,
5244,
262,
8715,
199,
309,
259,
4837,
266,
32,
609,
262,
8715,
14,
1308,
199,
199,
2344,
6105,
13,
1896,
1611,
5097,
859,
14,
199,
199,
2713,
5097,
365,
282,
663,
402,
2018,
4621,
19829,
367,
3575,
9219,
83,
14,
199,
7940,
365,
5313,
641,
2746,
402,
314,
444,
6067,
12518,
14314,
3555,
14,
961,
6127,
1265,
199,
475,
1218,
9999,
13953,
3297,
9219,
83,
436,
19207,
521,
2391,
18572,
315,
314,
2018,
199,
3671,
14,
710,
2559,
365,
4721,
590,
1844,
461,
12,
543,
9219,
83,
3879,
641,
199,
8647,
12,
10444,
3100,
12,
4403,
1323,
12,
6423,
3100,
12,
2868,
15400,
12,
473,
20264,
12,
436,
10130,
14,
199,
2344,
199,
199,
363,
21841,
363,
275,
283,
26854,
7,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
199,
199,
646,
747,
199,
646,
984,
199,
199,
533,
15626,
2377,
26,
272,
347,
636,
826,
721,
277,
12,
536,
12,
2256,
4581,
7629,
12069,
29,
16,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
815,
275,
620,
8,
815,
9,
267,
291,
14,
300,
12069,
275,
7629,
12069,
267,
340,
7629,
12069,
26,
288,
291,
14,
4050,
342,
339,
347,
636,
5675,
721,
277,
12,
2729,
304,
267,
340,
440,
291,
14,
300,
12069,
26,
288,
291,
14,
4050,
342,
288,
291,
14,
300,
12069,
275,
413,
267,
15626,
2713,
5097,
2377,
275,
2071,
83,
859,
440,
2808,
2,
450,
291,
14,
354,
267,
746,
4279,
8,
7718,
2713,
5097,
2377,
9,
339,
347,
636,
10262,
721,
277,
304,
267,
372,
378,
339,
347,
7987,
8,
277,
304,
267,
340,
291,
14,
300,
12069,
26,
730,
275,
283,
646,
7,
267,
587,
26,
730,
275,
283,
1180,
7,
267,
1245,
275,
1543,
83,
450,
83,
26,
450,
83,
7,
450,
334,
466,
12,
291,
14,
354,
12,
291,
14,
815,
9,
267,
862,
26,
288,
492,
3598,
288,
340,
291,
14,
300,
12069,
26,
2166,
275,
841,
288,
587,
26,
2166,
275,
650,
288,
3598,
14,
4050,
8,
1188,
12,
25178,
12,
2166,
9,
267,
871,
3545,
26,
288,
870,
8,
1188,
9,
4388,
199,
3,
1129,
1929,
370,
492,
2839,
642,
12,
1924,
737,
282,
900,
14,
314,
3633,
597,
4340,
370,
492,
199,
3,
567,
4621,
365,
543,
314,
492,
1414,
334,
1397,
314,
636,
646,
363,
805,
9,
199,
199,
3,
2246,
12,
314,
298,
2427,
2,
4621,
199,
3,
504,
9193,
14,
1144,
492,
627,
221,
327,
66,
23196,
5325,
562,
199,
199,
504,
9193,
14,
1095,
492,
627,
199,
504,
9193,
14,
5559,
492,
627,
199,
504,
9193,
14,
1023,
492,
627,
199,
504,
9193,
14,
1201,
492,
21536,
199,
646,
9193,
14,
2326,
199,
4117,
275,
9193,
14,
2326,
14,
4117,
199,
363,
1023,
363,
275,
809,
199,
199,
3,
3270,
701,
8413,
23263,
199,
504,
1275,
492,
900,
199,
504,
1275,
492,
2929,
199,
504,
1275,
492,
5262,
199,
504,
1275,
492,
1566,
199,
504,
1275,
492,
5023,
199,
504,
1275,
492,
13667,
281,
199,
504,
1275,
492,
17325,
199,
504,
1275,
10992,
492,
29564,
199,
504,
1275,
492,
1834,
199,
504,
1275,
492,
12817,
199,
504,
1275,
492,
5793,
199,
199,
3,
2184,
12,
314,
298,
6807,
2,
4621,
199,
3,
1129,
5139,
2040,
3062,
370,
506,
4124,
367,
14489,
3224,
9193,
10208,
199,
2344,
199,
893,
26,
492,
9193,
14,
2866,
417,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
2866,
417,
29,
7718,
2377,
480,
2866,
417,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
17255,
1384,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
17255,
1384,
29,
7718,
2377,
480,
17255,
1384,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
2918,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
2918,
29,
7718,
2377,
480,
2918,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
5485,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
5485,
29,
7718,
2377,
480,
5485,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
1430,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
1430,
29,
7718,
2377,
480,
1430,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
1569,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
1569,
29,
7718,
2377,
480,
1569,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
26729,
18043,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
26729,
18043,
29,
7718,
2377,
480,
26729,
18043,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
498,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
498,
29,
7718,
2377,
480,
498,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
10544,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
10544,
29,
7718,
2377,
480,
10544,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
15972,
199,
2590
] |
[
259,
9193,
446,
2018,
25132,
11243,
199,
309,
259,
1898,
334,
35,
9,
12293,
13,
8339,
221,
11379,
266,
5244,
262,
8715,
199,
309,
199,
309,
259,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
259,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
11243,
1696,
1684,
199,
309,
259,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
309,
259,
1015,
499,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
259,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
309,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
259,
11243,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
11243,
1696,
1684,
199,
309,
259,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
199,
309,
259,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
309,
199,
309,
259,
11379,
266,
5244,
262,
8715,
199,
309,
259,
4837,
266,
32,
609,
262,
8715,
14,
1308,
199,
199,
2344,
6105,
13,
1896,
1611,
5097,
859,
14,
199,
199,
2713,
5097,
365,
282,
663,
402,
2018,
4621,
19829,
367,
3575,
9219,
83,
14,
199,
7940,
365,
5313,
641,
2746,
402,
314,
444,
6067,
12518,
14314,
3555,
14,
961,
6127,
1265,
199,
475,
1218,
9999,
13953,
3297,
9219,
83,
436,
19207,
521,
2391,
18572,
315,
314,
2018,
199,
3671,
14,
710,
2559,
365,
4721,
590,
1844,
461,
12,
543,
9219,
83,
3879,
641,
199,
8647,
12,
10444,
3100,
12,
4403,
1323,
12,
6423,
3100,
12,
2868,
15400,
12,
473,
20264,
12,
436,
10130,
14,
199,
2344,
199,
199,
363,
21841,
363,
275,
283,
26854,
7,
199,
363,
1023,
363,
275,
4505,
1304,
12913,
199,
199,
646,
747,
199,
646,
984,
199,
199,
533,
15626,
2377,
26,
272,
347,
636,
826,
721,
277,
12,
536,
12,
2256,
4581,
7629,
12069,
29,
16,
304,
267,
291,
14,
354,
275,
536,
267,
291,
14,
815,
275,
620,
8,
815,
9,
267,
291,
14,
300,
12069,
275,
7629,
12069,
267,
340,
7629,
12069,
26,
288,
291,
14,
4050,
342,
339,
347,
636,
5675,
721,
277,
12,
2729,
304,
267,
340,
440,
291,
14,
300,
12069,
26,
288,
291,
14,
4050,
342,
288,
291,
14,
300,
12069,
275,
413,
267,
15626,
2713,
5097,
2377,
275,
2071,
83,
859,
440,
2808,
2,
450,
291,
14,
354,
267,
746,
4279,
8,
7718,
2713,
5097,
2377,
9,
339,
347,
636,
10262,
721,
277,
304,
267,
372,
378,
339,
347,
7987,
8,
277,
304,
267,
340,
291,
14,
300,
12069,
26,
730,
275,
283,
646,
7,
267,
587,
26,
730,
275,
283,
1180,
7,
267,
1245,
275,
1543,
83,
450,
83,
26,
450,
83,
7,
450,
334,
466,
12,
291,
14,
354,
12,
291,
14,
815,
9,
267,
862,
26,
288,
492,
3598,
288,
340,
291,
14,
300,
12069,
26,
2166,
275,
841,
288,
587,
26,
2166,
275,
650,
288,
3598,
14,
4050,
8,
1188,
12,
25178,
12,
2166,
9,
267,
871,
3545,
26,
288,
870,
8,
1188,
9,
4388,
199,
3,
1129,
1929,
370,
492,
2839,
642,
12,
1924,
737,
282,
900,
14,
314,
3633,
597,
4340,
370,
492,
199,
3,
567,
4621,
365,
543,
314,
492,
1414,
334,
1397,
314,
636,
646,
363,
805,
9,
199,
199,
3,
2246,
12,
314,
298,
2427,
2,
4621,
199,
3,
504,
9193,
14,
1144,
492,
627,
221,
327,
66,
23196,
5325,
562,
199,
199,
504,
9193,
14,
1095,
492,
627,
199,
504,
9193,
14,
5559,
492,
627,
199,
504,
9193,
14,
1023,
492,
627,
199,
504,
9193,
14,
1201,
492,
21536,
199,
646,
9193,
14,
2326,
199,
4117,
275,
9193,
14,
2326,
14,
4117,
199,
363,
1023,
363,
275,
809,
199,
199,
3,
3270,
701,
8413,
23263,
199,
504,
1275,
492,
900,
199,
504,
1275,
492,
2929,
199,
504,
1275,
492,
5262,
199,
504,
1275,
492,
1566,
199,
504,
1275,
492,
5023,
199,
504,
1275,
492,
13667,
281,
199,
504,
1275,
492,
17325,
199,
504,
1275,
10992,
492,
29564,
199,
504,
1275,
492,
1834,
199,
504,
1275,
492,
12817,
199,
504,
1275,
492,
5793,
199,
199,
3,
2184,
12,
314,
298,
6807,
2,
4621,
199,
3,
1129,
5139,
2040,
3062,
370,
506,
4124,
367,
14489,
3224,
9193,
10208,
199,
2344,
199,
893,
26,
492,
9193,
14,
2866,
417,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
2866,
417,
29,
7718,
2377,
480,
2866,
417,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
17255,
1384,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
17255,
1384,
29,
7718,
2377,
480,
17255,
1384,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
2918,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
2918,
29,
7718,
2377,
480,
2918,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
5485,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
5485,
29,
7718,
2377,
480,
5485,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
1430,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
1430,
29,
7718,
2377,
480,
1430,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
1569,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
1569,
29,
7718,
2377,
480,
1569,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
26729,
18043,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
26729,
18043,
29,
7718,
2377,
480,
26729,
18043,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
498,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
498,
29,
7718,
2377,
480,
498,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
10544,
199,
2590,
334,
17825,
12,
13760,
395,
1499,
26,
10544,
29,
7718,
2377,
480,
10544,
401,
1499,
12,
413,
9,
199,
199,
893,
26,
492,
9193,
14,
15972,
199,
2590,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
BaconPancakes/valor
|
lib/youtube_dl/extractor/tonline.py
|
71
|
2093
|
# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
from ..utils import int_or_none
class TOnlineIE(InfoExtractor):
IE_NAME = 't-online.de'
_VALID_URL = r'https?://(?:www\.)?t-online\.de/tv/(?:[^/]+/)*id_(?P<id>\d+)'
_TEST = {
'url': 'http://www.t-online.de/tv/sport/fussball/id_79166266/drittes-remis-zidane-es-muss-etwas-passieren-.html',
'md5': '7d94dbdde5f9d77c5accc73c39632c29',
'info_dict': {
'id': '79166266',
'ext': 'mp4',
'title': 'Drittes Remis! Zidane: "Es muss etwas passieren"',
'description': 'Es läuft nicht rund bei Real Madrid. Das 1:1 gegen den SD Eibar war das dritte Unentschieden in Folge in der Liga.',
}
}
def _real_extract(self, url):
video_id = self._match_id(url)
video_data = self._download_json(
'http://www.t-online.de/tv/id_%s/tid_json_video' % video_id, video_id)
title = video_data['subtitle']
formats = []
for asset in video_data.get('assets', []):
asset_source = asset.get('source') or asset.get('source2')
if not asset_source:
continue
formats_id = []
for field_key in ('type', 'profile'):
field_value = asset.get(field_key)
if field_value:
formats_id.append(field_value)
formats.append({
'format_id': '-'.join(formats_id),
'url': asset_source,
})
thumbnails = []
for image in video_data.get('images', []):
image_source = image.get('source')
if not image_source:
continue
thumbnails.append({
'url': image_source,
})
return {
'id': video_id,
'title': title,
'description': video_data.get('description'),
'duration': int_or_none(video_data.get('duration')),
'thumbnails': thumbnails,
'formats': formats,
}
|
gpl-3.0
|
[
3,
2803,
26,
2774,
13,
24,
199,
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,
2296,
78,
604,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
283,
84,
13,
15178,
14,
271,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
84,
13,
15178,
4537,
271,
15,
6993,
32576,
26285,
15,
3342,
344,
63,
2229,
48,
28,
344,
3072,
68,
29600,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
84,
13,
15178,
14,
271,
15,
6993,
15,
3275,
15,
13499,
385,
8571,
15,
344,
63,
1965,
975,
2789,
1272,
15,
68,
11133,
744,
13,
264,
1292,
13,
90,
344,
5865,
13,
397,
13,
6553,
385,
13,
386,
10274,
13,
80,
2608,
69,
828,
30858,
1360,
297,
267,
283,
1064,
21,
356,
283,
23,
68,
2635,
697,
10282,
21,
70,
25,
68,
1138,
67,
21,
645,
2055,
2898,
67,
13443,
708,
67,
1398,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1965,
975,
2789,
1272,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
36,
11133,
744,
799,
1292,
1,
3107,
344,
5865,
26,
298,
21658,
8504,
385,
325,
8122,
305,
299,
2608,
69,
828,
6949,
288,
283,
1802,
356,
283,
21658,
634,
13733,
85,
856,
302,
1158,
84,
519,
725,
32731,
14849,
603,
350,
1677,
14,
577,
305,
413,
26,
17,
2312,
2268,
5376,
428,
36,
662,
73,
1700,
3429,
366,
305,
366,
11133,
266,
1910,
24871,
14025,
848,
315,
481,
393,
303,
315,
16921,
491,
29055,
3130,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
3991,
63,
576,
275,
291,
423,
4249,
63,
1001,
8,
288,
283,
1014,
921,
1544,
14,
84,
13,
15178,
14,
271,
15,
6993,
15,
344,
4970,
83,
15,
5700,
63,
1001,
63,
3722,
7,
450,
3991,
63,
344,
12,
3991,
63,
344,
9,
267,
2538,
275,
3991,
63,
576,
459,
14348,
418,
398,
6752,
275,
942,
267,
367,
8977,
315,
3991,
63,
576,
14,
362,
360,
12186,
297,
12319,
288,
8977,
63,
1365,
275,
8977,
14,
362,
360,
1365,
358,
503,
8977,
14,
362,
360,
1365,
18,
358,
288,
340,
440,
8977,
63,
1365,
26,
355,
1980,
288,
6752,
63,
344,
275,
942,
288,
367,
901,
63,
498,
315,
661,
466,
297,
283,
2913,
735,
355,
901,
63,
585,
275,
8977,
14,
362,
8,
698,
63,
498,
9,
355,
340,
901,
63,
585,
26,
490,
6752,
63,
344,
14,
740,
8,
698,
63,
585,
9,
288,
6752,
14,
740,
2561,
355,
283,
908,
63,
344,
356,
2475,
1370,
904,
8,
6321,
63,
344,
395,
355,
283,
633,
356,
8977,
63,
1365,
12,
288,
3828,
398,
10062,
83,
275,
942,
267,
367,
1834,
315,
3991,
63,
576,
14,
362,
360,
4782,
297,
12319,
288,
1834,
63,
1365,
275,
1834,
14,
362,
360,
1365,
358,
288,
340,
440,
1834,
63,
1365,
26,
355,
1980,
288,
10062,
83,
14,
740,
2561,
355,
283,
633,
356,
1834,
63,
1365,
12,
288,
3828,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
3991,
63,
576,
14,
362,
360,
1802,
659,
288,
283,
5553,
356,
1109,
63,
269,
63,
3592,
8,
3722,
63,
576,
14,
362,
360,
5553,
3855,
288,
283,
8311,
83,
356,
10062,
83,
12,
288,
283,
6321,
356,
6752,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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,
2296,
78,
604,
4332,
8,
18283,
304,
272,
15292,
63,
2339,
275,
283,
84,
13,
15178,
14,
271,
7,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
84,
13,
15178,
4537,
271,
15,
6993,
32576,
26285,
15,
3342,
344,
63,
2229,
48,
28,
344,
3072,
68,
29600,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
84,
13,
15178,
14,
271,
15,
6993,
15,
3275,
15,
13499,
385,
8571,
15,
344,
63,
1965,
975,
2789,
1272,
15,
68,
11133,
744,
13,
264,
1292,
13,
90,
344,
5865,
13,
397,
13,
6553,
385,
13,
386,
10274,
13,
80,
2608,
69,
828,
30858,
1360,
297,
267,
283,
1064,
21,
356,
283,
23,
68,
2635,
697,
10282,
21,
70,
25,
68,
1138,
67,
21,
645,
2055,
2898,
67,
13443,
708,
67,
1398,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
1965,
975,
2789,
1272,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
36,
11133,
744,
799,
1292,
1,
3107,
344,
5865,
26,
298,
21658,
8504,
385,
325,
8122,
305,
299,
2608,
69,
828,
6949,
288,
283,
1802,
356,
283,
21658,
634,
13733,
85,
856,
302,
1158,
84,
519,
725,
32731,
14849,
603,
350,
1677,
14,
577,
305,
413,
26,
17,
2312,
2268,
5376,
428,
36,
662,
73,
1700,
3429,
366,
305,
366,
11133,
266,
1910,
24871,
14025,
848,
315,
481,
393,
303,
315,
16921,
491,
29055,
3130,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
3991,
63,
576,
275,
291,
423,
4249,
63,
1001,
8,
288,
283,
1014,
921,
1544,
14,
84,
13,
15178,
14,
271,
15,
6993,
15,
344,
4970,
83,
15,
5700,
63,
1001,
63,
3722,
7,
450,
3991,
63,
344,
12,
3991,
63,
344,
9,
267,
2538,
275,
3991,
63,
576,
459,
14348,
418,
398,
6752,
275,
942,
267,
367,
8977,
315,
3991,
63,
576,
14,
362,
360,
12186,
297,
12319,
288,
8977,
63,
1365,
275,
8977,
14,
362,
360,
1365,
358,
503,
8977,
14,
362,
360,
1365,
18,
358,
288,
340,
440,
8977,
63,
1365,
26,
355,
1980,
288,
6752,
63,
344,
275,
942,
288,
367,
901,
63,
498,
315,
661,
466,
297,
283,
2913,
735,
355,
901,
63,
585,
275,
8977,
14,
362,
8,
698,
63,
498,
9,
355,
340,
901,
63,
585,
26,
490,
6752,
63,
344,
14,
740,
8,
698,
63,
585,
9,
288,
6752,
14,
740,
2561,
355,
283,
908,
63,
344,
356,
2475,
1370,
904,
8,
6321,
63,
344,
395,
355,
283,
633,
356,
8977,
63,
1365,
12,
288,
3828,
398,
10062,
83,
275,
942,
267,
367,
1834,
315,
3991,
63,
576,
14,
362,
360,
4782,
297,
12319,
288,
1834,
63,
1365,
275,
1834,
14,
362,
360,
1365,
358,
288,
340,
440,
1834,
63,
1365,
26,
355,
1980,
288,
10062,
83,
14,
740,
2561,
355,
283,
633,
356,
1834,
63,
1365,
12,
288,
3828,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
3991,
63,
576,
14,
362,
360,
1802,
659,
288,
283,
5553,
356,
1109,
63,
269,
63,
3592,
8,
3722,
63,
576,
14,
362,
360,
5553,
3855,
288,
283,
8311,
83,
356,
10062,
83,
12,
288,
283,
6321,
356,
6752,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
marklescroart/bvp
|
bvp/Classes/background.py
|
1
|
11453
|
# Imports
import os
import six
from bvp.utils.blender import add_group, grab_only, apply_material
from .constraint import ObConstraint, CamConstraint
from .mapped_class import MappedClass
from .object import Object
# Should be moved, along with test below
#from .Camera import Camera
#from .Scene import Scene
#from .Sky import Sky
try:
import bpy
import mathutils as bmu
is_blender = True
except ImportError:
is_blender = False
class Background(MappedClass):
"""Backgrounds for scenes"""
def __init__(self, name='DummyBackground', fname=None, n_vertices=None, n_faces=None,
type='Background', wordnet_label=None, real_world_size=None, lens=50., is_cycles=None,
semantic_category=None, object_semantic_category='all', sky_semantic_category='all',
camera_constraints=None, object_constraints=None, obstacles=None, materials=None,
_id=None, _rev=None, dbi=None):
"""Class to store Backgrounds (floor, walls, maybe lights, + constraints on objects)
A Background consists of a floor, background objects (walls, maybe trees, etc), maybe
lights, and constraints that partly determine the locations of objects, actions*,
and cameras in a scene. Each Background is stored as a group in a .blend file.
All elements of the background (floor, walls, buildings, emtpy objects defining
bounds of space, what have you) should be in this group.
Parameters
---------
name: string
a unique identifier for the BG in question. Either a string
(interpreted to be the name of the BG group) or a lambda function
(See bvpLibrary "getSceneComponent" function)
"""
# Quick setting of attributes
inpt = locals()
self.type = 'Background'
for k, v in inpt.items():
if not k in ('self', 'type'):
if v == 'None':
setattr(self, k, None)
else:
setattr(self, k, v)
if isinstance(self.real_world_size, (list, tuple)):
self.real_world_size = self.real_world_size[0]
self._db_fields = []
self._data_fields = ['materials']
self._temp_fields = ['CamConstraint', 'ObConstraint']
#mappedclass translation is not recursive, so we must set these manually.
#TODO Utkarsh: find better solution to this
if self.camera_constraints is not None:
self.CamConstraint = CamConstraint(**camera_constraints)
if self.object_constraints is not None:
self.ObConstraint = ObConstraint(**object_constraints)
#if camera_constraints:
# for k in camera_constraints.keys():
# setattr(self.CamConstraint,k,camera_constraints[k])
# self.obConstraints = ObConstraint()
# if object_constraints:
# print(object_constraints)
# for k in object_constraints.keys():
# setattr(self.obConstraints,k,object_constraints[k])
if obstacles is not None: # and obstacles.lower() != 'none'
if isinstance(obstacles, list):
#TODO: SemanticCat =/= semantic_category. Fix this at some point.
self.obstacles = [Object(pos3D=obst['pos3D'],size3D=obst['size3D']) for obst in obstacles]
else:
if isinstance(obstacles, six.string_types):
if obstacles.lower() != 'none':
raise Exception('String variable for `obstacles` in background not understood')
else:
# Fine.
pass
else:
print(obstacles)
def place(self, scn=None, proxy=False):
"""
Adds background to Blender scene
"""
# Make file local, if it isn't already
if self.path is not None:
#
self.cloud_download()
if not scn:
scn = bpy.context.scene # Get current scene if input not supplied
if self.name is not 'DummyBackground':
# Add group of mesh object(s)
#print('{}, {}'.format(self.path, self.name))
bg_ob = add_group(self.name, self.fname, self.path, proxy=proxy)
# Next clause is a HACK because some background groups are not
# stored with a parent. Remove me when library is fixed.
if isinstance(bg_ob, (list, tuple)):
bg_ob = bg_ob[0]
if not proxy:
if bpy.app.version < (2, 80, 0):
bg_grp = bg_ob.users_group[0]
else:
bg_grp = bg_ob.users_collection[0]
for o in bg_grp.objects:
o.name = 'BG_' + o.name
else:
# Potentially add default background (with ground plane, other render settings...)
print("BG is empty!")
if self.materials is not None:
if proxy:
raise ValueError("Can't change materials of proxy objects. Use proxy=False.")
if bpy.app.version < (2, 80, 0):
self.apply_materials(bg_ob.users_group[0], self.materials)
else:
self.apply_materials(bg_ob.users_collection[0], self.materials)
def apply_materials(self, bpy_grp, materials):
"""Apply materials to already-placed background.
Parameters
----------
objects : list
list of all blender objects in this group
materials : list
list of bvp materials to apply. ** CURRENTLY ONLY WORKS FOR ONE MATERIAL **
Notes
-----
TODO: Deal with uv in more sensible fashion
"""
if len(materials) > 1:
raise NotImplementedError('Multiple material assignment not working yet.')
for i, material in enumerate(materials):
mat = material.link()
for o in bpy_grp.objects:
if o.type in ('MESH', 'CURVE'): # More?
apply_material(o, mat, uv=False)
@classmethod
def from_blender(cls, context, dbi):
"""Create an Action from a selected object in Blender.
This function only works within an active Blender session. The selected object must be an armature with
an action linked to it.
Parameters
----------
context : bpy context
context for determining selected object, etc
"""
# Idiot-proofing
assert is_blender, "from_blender() only works within an active blender session."
# Get relevant blender objects
wm = context.window_manager
scn = context.scene
ob = context.object
grab_only(ob)
# Compute parameters
## GET GROUP, USE WORDNET LABELS FOR GROUP
if bpy.app.version < (2, 80, 0):
grp = ob.users_group[0]
else:
grp = ob.users_collection[0]
## WordNet labels
wordnet_label = [s.name for s in grp.Background.wordnet_label] # or whatever
semantic_category = [s.name for s in grp.Background.semantic_category] # OR whatever
# TODO: n_vertices, n_faces, lens (interactive manual input?), constraints.
## Parent file
#pfile = act.Action.parent_file
# The above value (pfile) is ignored for now. Need to eventually implement some way to take the contents
# of the current file (group/action/whatever) and save them (append them) to another specfied file
# in the database. Currently NOT IMPLEMENTED.
thisfile = os.path.dirname(bpy.data.filepath) #if len(bpy.data.filepath)>0 else pfile
if thisfile=="":
# Require saving in db-appropriate location
raise NotImplementedError("Please save this file into %s before trying to save to database."%(os.path.join(dbpath, 'Background/')))
# Construct bvp Action
bg = cls.__new__(cls)
bg.__init__(name=grp.name,
fname=thisfile,
n_vertices=n_vertices,
n_faces=n_faces,
lens=lens,
semantic_category=grp.Background.semantic_category,
object_semantic_category=grp.Background.object_semantic_category,
sky_semantic_category=grp.Background.sky_semantic_category,
camera_constraint=None, # Save these? Unclear...
object_constraints=None, # same
obstacles=None, # same
dbi=dbi
)
return bg
# def test_background(self, frames=(1, 1), object_list=(), n_objects=0, edge_dist=0., object_overlap=0.50):
# """
# Tests object / camera constraints to see if they are working
# ** And shadows??
# Should be grouped with other testing functions, not here. Move.
# """
# Cam = Camera(frames=frames)
# Sky = Sky('*'+self.sky_semantic_category[0], Lib) # Choose a sky according to semantic category of BG ## RELIES ON ONLY ONE ENTRY FOR SKY SEMANTIC CAT! Should be most specific specifier...
# scn = Scene(0, BG=self, Cam=Cam, Sky=Sky, FrameRange=frames)
# if not object_list and not n_objects:
# object_list = [Object('*animal', Lib, size3D=None), Object('*vehicle', Lib, size3D=None), Object('*appliance', Lib, size3D=None)]
# n_objects = 0
# elif not object_list and n_objects:
# object_list = [Object(None, None, size3D=None) for x in range(n_objects)]
# scn.populate_scene(object_listist=object_list, ResetCam=True, RaiseError=True, nIter=100, edge_dist=edge_dist, object_overlap=object_overlap)
# if is_blender:
# RO = RenderOptions()
# scn.Create(RO)
# # Add spheres if there are blank objects:
# uv = bpy.ops.mesh.primitive_uv_sphere_add
# for o in range(n_objects):
# print('Sz of obj %d = %.2f'%(o, scn.Obj[o].size3D))
# ObSz = scn.Obj[o].size3D/2.
# pos = bmu.Vector(scn.Obj[o].pos3D) + bmu.Vector([0, 0, ObSz])
# uv(location=pos, size=ObSz)
def __repr__(self):
rstr = ('\nbvp Background {name}\n'
' File: {fname}\n'
' [{sem_cat}]\n'
' [{wn_lab}]\n'
' Size: {sz}, Lens: {lens}\n'
' Vertices: {verts}, Faces: {face}\n'
' Skies allowed: {skies}\n'
' Objects allowed: {obj}\n'
)
sem_cat = [] if self.semantic_category is None else self.semantic_category
wn_lab = [] if self.wordnet_label is None else self.wordnet_label
skies = [] if self.sky_semantic_category is None else self.sky_semantic_category
obj = [] if self.object_semantic_category is None else self.object_semantic_category
out = rstr.format(name=self.name, fname=self.fname,
sem_cat=', '.join(sem_cat),
wn_lab =', '.join(wn_lab),
sz=self.real_world_size, lens=self.lens,
verts=self.n_vertices, face=self.n_faces,
skies=', '.join(skies), obj=', '.join(obj))
return(out)
|
bsd-2-clause
|
[
3,
24339,
199,
646,
747,
199,
646,
3816,
199,
504,
330,
11702,
14,
1208,
14,
66,
24912,
492,
1050,
63,
923,
12,
18200,
63,
2118,
12,
4838,
63,
9820,
199,
504,
1275,
5631,
492,
17985,
8463,
12,
445,
455,
8463,
199,
504,
1275,
11663,
63,
533,
492,
9672,
1915,
2543,
199,
504,
1275,
785,
492,
6935,
199,
199,
3,
7719,
506,
12155,
12,
3180,
543,
511,
5084,
199,
3,
504,
1275,
18425,
492,
445,
7122,
199,
3,
504,
1275,
14216,
492,
18055,
69,
199,
3,
504,
1275,
51,
10562,
492,
428,
10562,
199,
199,
893,
26,
272,
492,
20575,
272,
492,
3473,
1208,
465,
330,
6553,
272,
365,
63,
66,
24912,
275,
715,
199,
2590,
3545,
26,
272,
365,
63,
66,
24912,
275,
756,
199,
199,
533,
10257,
3928,
8,
20698,
2543,
304,
272,
408,
14148,
83,
367,
8482,
397,
624,
272,
347,
636,
826,
721,
277,
12,
536,
534,
11324,
14148,
297,
6748,
29,
403,
12,
302,
63,
12637,
29,
403,
12,
302,
63,
4309,
29,
403,
12,
4960,
730,
534,
14148,
297,
4349,
846,
63,
1302,
29,
403,
12,
3363,
63,
7617,
63,
890,
29,
403,
12,
822,
83,
29,
1400,
2020,
365,
63,
23356,
29,
403,
12,
267,
32451,
63,
3710,
29,
403,
12,
909,
63,
261,
23127,
63,
3710,
534,
452,
297,
2386,
89,
63,
261,
23127,
63,
3710,
534,
452,
297,
267,
15177,
63,
9882,
29,
403,
12,
909,
63,
9882,
29,
403,
12,
2607,
270,
645,
2978,
29,
403,
12,
8418,
29,
403,
12,
267,
485,
344,
29,
403,
12,
485,
4964,
29,
403,
12,
1592,
73,
29,
403,
304,
4960,
408,
2543,
370,
3877,
10257,
3928,
83,
334,
11289,
12,
19882,
83,
12,
11703,
10540,
83,
12,
435,
9565,
641,
2251,
9,
24807,
437,
10257,
3928,
18581,
402,
282,
19841,
12,
8020,
2251,
334,
7567,
83,
12,
11703,
14416,
12,
5423,
395,
11703,
4960,
10540,
83,
12,
436,
9565,
626,
1777,
590,
6705,
314,
9918,
402,
2251,
12,
5445,
10381,
4960,
436,
20382,
6360,
315,
282,
13856,
14,
7048,
10257,
3928,
365,
5489,
465,
282,
1572,
315,
282,
1275,
27163,
570,
14,
4960,
2900,
4008,
402,
314,
8020,
334,
11289,
12,
19882,
83,
12,
1900,
780,
12,
325,
2037,
647,
2251,
12669,
4960,
10461,
402,
4601,
12,
4052,
1172,
1265,
9,
1077,
506,
315,
642,
1572,
14,
221,
2728,
3897,
267,
3001,
13,
267,
536,
26,
1059,
7205,
282,
3747,
5148,
367,
314,
699,
39,
315,
7894,
14,
13083,
282,
1059,
8892,
334,
12108,
471,
370,
506,
314,
536,
402,
314,
699,
39,
1572,
9,
503,
282,
2400,
805,
355,
334,
9295,
330,
11702,
7424,
298,
362,
14216,
7004,
2,
805,
9,
398,
408,
267,
327,
27534,
4260,
402,
3004,
267,
315,
541,
275,
9480,
342,
267,
291,
14,
466,
275,
283,
14148,
7,
267,
367,
1022,
12,
373,
315,
315,
541,
14,
1744,
837,
7205,
340,
440,
1022,
315,
661,
277,
297,
283,
466,
735,
355,
340,
373,
508,
283,
403,
356,
490,
5371,
8,
277,
12,
1022,
12,
488,
9,
355,
587,
26,
490,
5371,
8,
277,
12,
1022,
12,
373,
9,
267,
340,
1228,
8,
277,
14,
3093,
63,
7617,
63,
890,
12,
334,
513,
12,
2008,
2298,
288,
291,
14,
3093,
63,
7617,
63,
890,
275,
291,
14,
3093,
63,
7617,
63,
890,
59,
16,
61,
267,
291,
423,
697,
63,
955,
275,
942,
267,
291,
423,
576,
63,
955,
275,
788,
23231,
418,
267,
291,
423,
808,
63,
955,
275,
788,
30524,
8463,
297,
283,
11394,
8463,
418,
2728,
327,
11663,
533,
7761,
365,
440,
9133,
12,
880,
781,
1471,
663,
3520,
10250,
14,
4960,
327,
11768,
738,
2663,
285,
609,
26,
2342,
8034,
8744,
370,
642,
267,
340,
291,
14,
11928,
63,
9882,
365,
440,
488,
26,
288,
291,
14,
30524,
8463,
275,
445,
455,
8463,
3682,
11928,
63,
9882,
9,
267,
340,
291,
14,
785,
63,
9882,
365,
440,
488,
26,
288,
291,
14,
11394,
8463,
275,
17985,
8463,
3682,
785,
63,
9882,
9,
267,
327,
692,
15177,
63,
9882,
26,
267,
327,
259,
367,
1022,
315,
15177,
63,
9882,
14,
1612,
837,
267,
327,
263,
5371,
8,
277,
14,
30524,
8463,
12,
75,
12,
11928,
63,
9882,
59,
75,
566,
2728,
327,
291,
14,
2873,
21007,
275,
17985,
8463,
342,
267,
327,
340,
909,
63,
9882,
26,
267,
327,
258,
870,
8,
785,
63,
9882,
9,
267,
327,
258,
367,
1022,
315,
909,
63,
9882,
14,
1612,
837,
267,
327,
260,
5371,
8,
277,
14,
2873,
21007,
12,
75,
12,
785,
63,
9882,
59,
75,
566,
398,
340,
2607,
270,
645,
2978,
365,
440,
488,
26,
327,
436,
2607,
270,
645,
2978,
14,
2325,
342,
1137,
283,
3592,
7,
288,
340,
1228,
8,
2873,
270,
645,
2978,
12,
769,
304,
355,
327,
11768,
26,
3240,
23127,
21548,
275,
15,
29,
32451,
63,
3710,
14,
14811,
642,
737,
2005,
2376,
14,
355,
291,
14,
2873,
270,
645,
2978,
275,
359,
1692,
8,
1712,
19,
36,
29,
2873,
270,
459,
1712,
19,
36,
995,
890,
19,
36,
29,
2873,
270,
459,
890,
19,
36,
1105,
367,
2607,
270,
315,
2607,
270,
645,
2978,
61,
7205,
587,
26,
355,
340,
1228,
8,
2873,
270,
645,
2978,
12,
3816,
14,
875,
63,
1313,
304,
490,
340,
2607,
270,
645,
2978,
14,
2325,
342,
1137,
283,
3592,
356,
717,
746,
2186,
360,
1558,
1750,
367,
658,
2873,
270,
645,
2978,
64,
315,
8020,
440,
1334,
14308,
364,
358,
490,
587,
26,
717,
327,
481,
1132,
14,
717,
986,
8892,
587,
26,
490,
870,
8,
2873,
270,
645,
2978,
9,
272,
347,
4192,
8,
277,
12,
4061,
78,
29,
403,
12,
4566,
29,
797,
304,
267,
408,
267,
15747,
8020,
370,
699,
24912,
13856,
267,
408,
267,
327,
4155,
570,
2257,
12,
340,
652,
5712,
1133,
2575,
267,
340,
291,
14,
515,
365,
440,
488,
26,
288,
327,
288,
291,
14,
4091,
63,
4249,
342,
267,
340,
440,
4061,
78,
26,
288,
4061,
78,
275,
20575,
14,
1100,
14,
10436,
327,
2372,
1453,
13856,
340,
1324,
440,
6841,
267,
340,
291,
14,
354,
365,
440,
283,
11324,
14148,
356,
288,
327,
2654,
1572,
402,
9364,
909,
8,
83,
9,
288,
327,
1361,
11117,
1386,
9499
] |
[
24339,
199,
646,
747,
199,
646,
3816,
199,
504,
330,
11702,
14,
1208,
14,
66,
24912,
492,
1050,
63,
923,
12,
18200,
63,
2118,
12,
4838,
63,
9820,
199,
504,
1275,
5631,
492,
17985,
8463,
12,
445,
455,
8463,
199,
504,
1275,
11663,
63,
533,
492,
9672,
1915,
2543,
199,
504,
1275,
785,
492,
6935,
199,
199,
3,
7719,
506,
12155,
12,
3180,
543,
511,
5084,
199,
3,
504,
1275,
18425,
492,
445,
7122,
199,
3,
504,
1275,
14216,
492,
18055,
69,
199,
3,
504,
1275,
51,
10562,
492,
428,
10562,
199,
199,
893,
26,
272,
492,
20575,
272,
492,
3473,
1208,
465,
330,
6553,
272,
365,
63,
66,
24912,
275,
715,
199,
2590,
3545,
26,
272,
365,
63,
66,
24912,
275,
756,
199,
199,
533,
10257,
3928,
8,
20698,
2543,
304,
272,
408,
14148,
83,
367,
8482,
397,
624,
272,
347,
636,
826,
721,
277,
12,
536,
534,
11324,
14148,
297,
6748,
29,
403,
12,
302,
63,
12637,
29,
403,
12,
302,
63,
4309,
29,
403,
12,
4960,
730,
534,
14148,
297,
4349,
846,
63,
1302,
29,
403,
12,
3363,
63,
7617,
63,
890,
29,
403,
12,
822,
83,
29,
1400,
2020,
365,
63,
23356,
29,
403,
12,
267,
32451,
63,
3710,
29,
403,
12,
909,
63,
261,
23127,
63,
3710,
534,
452,
297,
2386,
89,
63,
261,
23127,
63,
3710,
534,
452,
297,
267,
15177,
63,
9882,
29,
403,
12,
909,
63,
9882,
29,
403,
12,
2607,
270,
645,
2978,
29,
403,
12,
8418,
29,
403,
12,
267,
485,
344,
29,
403,
12,
485,
4964,
29,
403,
12,
1592,
73,
29,
403,
304,
4960,
408,
2543,
370,
3877,
10257,
3928,
83,
334,
11289,
12,
19882,
83,
12,
11703,
10540,
83,
12,
435,
9565,
641,
2251,
9,
24807,
437,
10257,
3928,
18581,
402,
282,
19841,
12,
8020,
2251,
334,
7567,
83,
12,
11703,
14416,
12,
5423,
395,
11703,
4960,
10540,
83,
12,
436,
9565,
626,
1777,
590,
6705,
314,
9918,
402,
2251,
12,
5445,
10381,
4960,
436,
20382,
6360,
315,
282,
13856,
14,
7048,
10257,
3928,
365,
5489,
465,
282,
1572,
315,
282,
1275,
27163,
570,
14,
4960,
2900,
4008,
402,
314,
8020,
334,
11289,
12,
19882,
83,
12,
1900,
780,
12,
325,
2037,
647,
2251,
12669,
4960,
10461,
402,
4601,
12,
4052,
1172,
1265,
9,
1077,
506,
315,
642,
1572,
14,
221,
2728,
3897,
267,
3001,
13,
267,
536,
26,
1059,
7205,
282,
3747,
5148,
367,
314,
699,
39,
315,
7894,
14,
13083,
282,
1059,
8892,
334,
12108,
471,
370,
506,
314,
536,
402,
314,
699,
39,
1572,
9,
503,
282,
2400,
805,
355,
334,
9295,
330,
11702,
7424,
298,
362,
14216,
7004,
2,
805,
9,
398,
408,
267,
327,
27534,
4260,
402,
3004,
267,
315,
541,
275,
9480,
342,
267,
291,
14,
466,
275,
283,
14148,
7,
267,
367,
1022,
12,
373,
315,
315,
541,
14,
1744,
837,
7205,
340,
440,
1022,
315,
661,
277,
297,
283,
466,
735,
355,
340,
373,
508,
283,
403,
356,
490,
5371,
8,
277,
12,
1022,
12,
488,
9,
355,
587,
26,
490,
5371,
8,
277,
12,
1022,
12,
373,
9,
267,
340,
1228,
8,
277,
14,
3093,
63,
7617,
63,
890,
12,
334,
513,
12,
2008,
2298,
288,
291,
14,
3093,
63,
7617,
63,
890,
275,
291,
14,
3093,
63,
7617,
63,
890,
59,
16,
61,
267,
291,
423,
697,
63,
955,
275,
942,
267,
291,
423,
576,
63,
955,
275,
788,
23231,
418,
267,
291,
423,
808,
63,
955,
275,
788,
30524,
8463,
297,
283,
11394,
8463,
418,
2728,
327,
11663,
533,
7761,
365,
440,
9133,
12,
880,
781,
1471,
663,
3520,
10250,
14,
4960,
327,
11768,
738,
2663,
285,
609,
26,
2342,
8034,
8744,
370,
642,
267,
340,
291,
14,
11928,
63,
9882,
365,
440,
488,
26,
288,
291,
14,
30524,
8463,
275,
445,
455,
8463,
3682,
11928,
63,
9882,
9,
267,
340,
291,
14,
785,
63,
9882,
365,
440,
488,
26,
288,
291,
14,
11394,
8463,
275,
17985,
8463,
3682,
785,
63,
9882,
9,
267,
327,
692,
15177,
63,
9882,
26,
267,
327,
259,
367,
1022,
315,
15177,
63,
9882,
14,
1612,
837,
267,
327,
263,
5371,
8,
277,
14,
30524,
8463,
12,
75,
12,
11928,
63,
9882,
59,
75,
566,
2728,
327,
291,
14,
2873,
21007,
275,
17985,
8463,
342,
267,
327,
340,
909,
63,
9882,
26,
267,
327,
258,
870,
8,
785,
63,
9882,
9,
267,
327,
258,
367,
1022,
315,
909,
63,
9882,
14,
1612,
837,
267,
327,
260,
5371,
8,
277,
14,
2873,
21007,
12,
75,
12,
785,
63,
9882,
59,
75,
566,
398,
340,
2607,
270,
645,
2978,
365,
440,
488,
26,
327,
436,
2607,
270,
645,
2978,
14,
2325,
342,
1137,
283,
3592,
7,
288,
340,
1228,
8,
2873,
270,
645,
2978,
12,
769,
304,
355,
327,
11768,
26,
3240,
23127,
21548,
275,
15,
29,
32451,
63,
3710,
14,
14811,
642,
737,
2005,
2376,
14,
355,
291,
14,
2873,
270,
645,
2978,
275,
359,
1692,
8,
1712,
19,
36,
29,
2873,
270,
459,
1712,
19,
36,
995,
890,
19,
36,
29,
2873,
270,
459,
890,
19,
36,
1105,
367,
2607,
270,
315,
2607,
270,
645,
2978,
61,
7205,
587,
26,
355,
340,
1228,
8,
2873,
270,
645,
2978,
12,
3816,
14,
875,
63,
1313,
304,
490,
340,
2607,
270,
645,
2978,
14,
2325,
342,
1137,
283,
3592,
356,
717,
746,
2186,
360,
1558,
1750,
367,
658,
2873,
270,
645,
2978,
64,
315,
8020,
440,
1334,
14308,
364,
358,
490,
587,
26,
717,
327,
481,
1132,
14,
717,
986,
8892,
587,
26,
490,
870,
8,
2873,
270,
645,
2978,
9,
272,
347,
4192,
8,
277,
12,
4061,
78,
29,
403,
12,
4566,
29,
797,
304,
267,
408,
267,
15747,
8020,
370,
699,
24912,
13856,
267,
408,
267,
327,
4155,
570,
2257,
12,
340,
652,
5712,
1133,
2575,
267,
340,
291,
14,
515,
365,
440,
488,
26,
288,
327,
288,
291,
14,
4091,
63,
4249,
342,
267,
340,
440,
4061,
78,
26,
288,
4061,
78,
275,
20575,
14,
1100,
14,
10436,
327,
2372,
1453,
13856,
340,
1324,
440,
6841,
267,
340,
291,
14,
354,
365,
440,
283,
11324,
14148,
356,
288,
327,
2654,
1572,
402,
9364,
909,
8,
83,
9,
288,
327,
1361,
11117,
1386,
9499,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zzzombat/lucid-python-django
|
django/contrib/gis/geos/tests/test_io.py
|
321
|
4159
|
import binascii, ctypes, unittest
from django.contrib.gis.geos import GEOSGeometry, WKTReader, WKTWriter, WKBReader, WKBWriter, geos_version_info
class GEOSIOTest(unittest.TestCase):
def test01_wktreader(self):
# Creating a WKTReader instance
wkt_r = WKTReader()
wkt = 'POINT (5 23)'
# read() should return a GEOSGeometry
ref = GEOSGeometry(wkt)
g1 = wkt_r.read(wkt)
g2 = wkt_r.read(unicode(wkt))
for geom in (g1, g2):
self.assertEqual(ref, geom)
# Should only accept basestring objects.
self.assertRaises(TypeError, wkt_r.read, 1)
self.assertRaises(TypeError, wkt_r.read, buffer('foo'))
def test02_wktwriter(self):
# Creating a WKTWriter instance, testing its ptr property.
wkt_w = WKTWriter()
self.assertRaises(TypeError, wkt_w._set_ptr, WKTReader.ptr_type())
ref = GEOSGeometry('POINT (5 23)')
ref_wkt = 'POINT (5.0000000000000000 23.0000000000000000)'
self.assertEqual(ref_wkt, wkt_w.write(ref))
def test03_wkbreader(self):
# Creating a WKBReader instance
wkb_r = WKBReader()
hex = '000000000140140000000000004037000000000000'
wkb = buffer(binascii.a2b_hex(hex))
ref = GEOSGeometry(hex)
# read() should return a GEOSGeometry on either a hex string or
# a WKB buffer.
g1 = wkb_r.read(wkb)
g2 = wkb_r.read(hex)
for geom in (g1, g2):
self.assertEqual(ref, geom)
bad_input = (1, 5.23, None, False)
for bad_wkb in bad_input:
self.assertRaises(TypeError, wkb_r.read, bad_wkb)
def test04_wkbwriter(self):
wkb_w = WKBWriter()
# Representations of 'POINT (5 23)' in hex -- one normal and
# the other with the byte order changed.
g = GEOSGeometry('POINT (5 23)')
hex1 = '010100000000000000000014400000000000003740'
wkb1 = buffer(binascii.a2b_hex(hex1))
hex2 = '000000000140140000000000004037000000000000'
wkb2 = buffer(binascii.a2b_hex(hex2))
self.assertEqual(hex1, wkb_w.write_hex(g))
self.assertEqual(wkb1, wkb_w.write(g))
# Ensuring bad byteorders are not accepted.
for bad_byteorder in (-1, 2, 523, 'foo', None):
# Equivalent of `wkb_w.byteorder = bad_byteorder`
self.assertRaises(ValueError, wkb_w._set_byteorder, bad_byteorder)
# Setting the byteorder to 0 (for Big Endian)
wkb_w.byteorder = 0
self.assertEqual(hex2, wkb_w.write_hex(g))
self.assertEqual(wkb2, wkb_w.write(g))
# Back to Little Endian
wkb_w.byteorder = 1
# Now, trying out the 3D and SRID flags.
g = GEOSGeometry('POINT (5 23 17)')
g.srid = 4326
hex3d = '0101000080000000000000144000000000000037400000000000003140'
wkb3d = buffer(binascii.a2b_hex(hex3d))
hex3d_srid = '01010000A0E6100000000000000000144000000000000037400000000000003140'
wkb3d_srid = buffer(binascii.a2b_hex(hex3d_srid))
# Ensuring bad output dimensions are not accepted
for bad_outdim in (-1, 0, 1, 4, 423, 'foo', None):
# Equivalent of `wkb_w.outdim = bad_outdim`
self.assertRaises(ValueError, wkb_w._set_outdim, bad_outdim)
# These tests will fail on 3.0.0 because of a bug that was fixed in 3.1:
# http://trac.osgeo.org/geos/ticket/216
if not geos_version_info()['version'].startswith('3.0.'):
# Now setting the output dimensions to be 3
wkb_w.outdim = 3
self.assertEqual(hex3d, wkb_w.write_hex(g))
self.assertEqual(wkb3d, wkb_w.write(g))
# Telling the WKBWriter to inlcude the srid in the representation.
wkb_w.srid = True
self.assertEqual(hex3d_srid, wkb_w.write_hex(g))
self.assertEqual(wkb3d_srid, wkb_w.write(g))
def suite():
s = unittest.TestSuite()
s.addTest(unittest.makeSuite(GEOSIOTest))
return s
def run(verbosity=2):
unittest.TextTestRunner(verbosity=verbosity).run(suite())
|
bsd-3-clause
|
[
646,
14755,
12,
5577,
12,
2882,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
492,
21479,
12,
22561,
5929,
12,
22561,
6261,
12,
644,
12780,
5929,
12,
644,
12780,
6261,
12,
30259,
63,
1023,
63,
815,
199,
199,
533,
11920,
2090,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
614,
63,
11412,
5503,
8,
277,
304,
267,
327,
20507,
282,
22561,
5929,
1256,
267,
21992,
63,
82,
275,
22561,
5929,
342,
267,
21992,
275,
283,
7217,
334,
21,
6546,
3171,
398,
327,
1586,
342,
1077,
372,
282,
21479,
267,
2984,
275,
21479,
8,
11412,
9,
267,
486,
17,
275,
21992,
63,
82,
14,
739,
8,
11412,
9,
267,
486,
18,
275,
21992,
63,
82,
14,
739,
8,
2975,
8,
11412,
430,
398,
367,
9671,
315,
334,
71,
17,
12,
486,
18,
304,
288,
291,
14,
629,
8,
1121,
12,
9671,
9,
398,
327,
7719,
1454,
4729,
7116,
2251,
14,
267,
291,
14,
1855,
8,
4333,
12,
21992,
63,
82,
14,
739,
12,
413,
9,
267,
291,
14,
1855,
8,
4333,
12,
21992,
63,
82,
14,
739,
12,
3335,
360,
1421,
1333,
339,
347,
511,
996,
63,
11412,
5491,
8,
277,
304,
267,
327,
20507,
282,
22561,
6261,
1256,
12,
5343,
2399,
12448,
3324,
14,
267,
21992,
63,
87,
275,
22561,
6261,
342,
267,
291,
14,
1855,
8,
4333,
12,
21992,
63,
87,
423,
409,
63,
4695,
12,
22561,
5929,
14,
4695,
63,
466,
1012,
398,
2984,
275,
21479,
360,
7217,
334,
21,
6546,
5942,
267,
2984,
63,
11412,
275,
283,
7217,
334,
21,
14,
9409,
6546,
14,
9409,
3171,
267,
291,
14,
629,
8,
1121,
63,
11412,
12,
21992,
63,
87,
14,
952,
8,
1121,
430,
339,
347,
511,
1644,
63,
18914,
5503,
8,
277,
304,
267,
327,
20507,
282,
644,
12780,
5929,
1256,
267,
24249,
63,
82,
275,
644,
12780,
5929,
342,
398,
6318,
275,
283,
3607,
614,
8854,
20,
15672,
2167,
1401,
15672,
7,
267,
24249,
275,
3335,
8,
27460,
14,
65,
18,
66,
63,
4097,
8,
4097,
430,
267,
2984,
275,
21479,
8,
4097,
9,
398,
327,
1586,
342,
1077,
372,
282,
21479,
641,
1902,
282,
6318,
1059,
503,
267,
327,
282,
644,
12780,
3335,
14,
267,
486,
17,
275,
24249,
63,
82,
14,
739,
8,
18914,
9,
267,
486,
18,
275,
24249,
63,
82,
14,
739,
8,
4097,
9,
267,
367,
9671,
315,
334,
71,
17,
12,
486,
18,
304,
288,
291,
14,
629,
8,
1121,
12,
9671,
9,
398,
4875,
63,
1210,
275,
334,
17,
12,
959,
14,
1789,
12,
488,
12,
756,
9,
267,
367,
4875,
63,
18914,
315,
4875,
63,
1210,
26,
288,
291,
14,
1855,
8,
4333,
12,
24249,
63,
82,
14,
739,
12,
4875,
63,
18914,
9,
5493,
347,
511,
966,
63,
18914,
5491,
8,
277,
304,
267,
24249,
63,
87,
275,
644,
12780,
6261,
342,
398,
327,
17634,
1298,
402,
283,
7217,
334,
21,
6546,
3171,
315,
6318,
1553,
1373,
3293,
436,
267,
327,
314,
1163,
543,
314,
3696,
1865,
2896,
14,
267,
486,
275,
21479,
360,
7217,
334,
21,
6546,
5942,
267,
6318,
17,
275,
283,
11502,
15672,
3273,
9862,
15672,
1644,
17702,
7,
267,
24249,
17,
275,
3335,
8,
27460,
14,
65,
18,
66,
63,
4097,
8,
4097,
17,
430,
267,
6318,
18,
275,
283,
3607,
614,
8854,
20,
15672,
2167,
1401,
15672,
7,
267,
24249,
18,
275,
3335,
8,
27460,
14,
65,
18,
66,
63,
4097,
8,
4097,
18,
430,
398,
291,
14,
629,
8,
4097,
17,
12,
24249,
63,
87,
14,
952,
63,
4097,
8,
71,
430,
267,
291,
14,
629,
8,
18914,
17,
12,
24249,
63,
87,
14,
952,
8,
71,
430,
398,
327,
23312,
4039,
4875,
3696,
14387,
787,
440,
10226,
14,
267,
367,
4875,
63,
19415,
315,
5868,
17,
12,
499,
12,
959,
1789,
12,
283,
1421,
297,
488,
304,
288,
327,
24228,
402,
658,
18914,
63,
87,
14,
19415,
275,
4875,
63,
19415,
64,
288,
291,
14,
1855,
8,
3393,
12,
24249,
63,
87,
423,
409,
63,
19415,
12,
4875,
63,
19415,
9,
10631,
327,
13510,
314,
30310,
370,
378,
334,
509,
13123,
3447,
6268,
9,
267,
24249,
63,
87,
14,
19415,
275,
378,
267,
291,
14,
629,
8,
4097,
18,
12,
24249,
63,
87,
14,
952,
63,
4097,
8,
71,
430,
267,
291,
14,
629,
8,
18914,
18,
12,
24249,
63,
87,
14,
952,
8,
71,
430,
398,
327,
10257,
370,
491,
390,
1118,
3447,
6268,
267,
24249,
63,
87,
14,
19415,
275,
413,
398,
327,
7356,
12,
9936,
734,
314,
650,
36,
436,
22425,
3285,
14,
267,
486,
275,
21479,
360,
7217,
334,
21,
6546,
5557,
5942,
267,
486,
14,
10498,
275,
26719,
2728,
6318,
19,
68,
275,
283,
11502,
993,
24,
15672,
30826,
15672,
1644,
1342,
15672,
1644,
10037,
7,
267,
24249,
19,
68,
275,
3335,
8,
27460,
14,
65,
18,
66,
63,
4097,
8,
4097,
19,
68,
430,
267,
6318,
19,
68,
63,
10498,
275,
283,
11502,
993,
33,
16,
37,
2976,
9409,
30826,
15672,
1644,
1342,
15672,
1644,
10037,
7,
267,
24249,
19,
68,
63,
10498,
275,
3335,
8,
27460,
14,
65,
18,
66,
63,
4097,
8,
4097,
19,
68,
63,
10498,
430,
398,
327,
23312,
4039,
4875,
1072,
7365,
787,
440,
10226,
267,
367,
4875,
63,
548,
3572,
315,
5868,
17,
12,
378,
12,
413,
12,
841,
12,
841,
1789,
12,
283,
1421,
297,
488,
304,
288,
327,
24228,
402,
658,
18914,
63,
87,
14,
548,
3572,
275,
4875,
63,
548,
3572,
64,
288,
291,
14,
1855,
8,
3393,
12,
24249,
63,
87,
423,
409,
63,
548,
3572,
12,
4875,
63,
548,
3572,
9,
398,
327,
5723,
2295,
911,
2449,
641,
650,
14,
16,
14,
16,
2952,
402,
282,
6519,
626,
1990,
6317,
315,
650,
14,
17,
26,
267,
327,
1455,
921,
23047,
14,
736,
6721,
14,
1308,
15,
12151,
15,
9201,
15,
9669,
267,
340,
440,
30259,
63,
1023,
63,
815,
12047,
1023,
2278,
2460,
360,
19,
14,
16,
30194,
288,
327,
7356,
4260,
314,
1072,
7365,
370,
506,
650,
288,
24249,
63,
87,
14,
548,
3572,
275,
650,
953,
291,
14,
629,
8,
4097,
19,
68,
12,
24249,
63,
87,
14,
952,
63,
4097,
8,
71,
430,
288,
291,
14,
629,
8,
18914,
19,
68,
12
] |
[
14755,
12,
5577,
12,
2882,
199,
504,
1639,
14,
2828,
14,
5668,
14,
12151,
492,
21479,
12,
22561,
5929,
12,
22561,
6261,
12,
644,
12780,
5929,
12,
644,
12780,
6261,
12,
30259,
63,
1023,
63,
815,
199,
199,
533,
11920,
2090,
774,
8,
2796,
14,
1746,
304,
339,
347,
511,
614,
63,
11412,
5503,
8,
277,
304,
267,
327,
20507,
282,
22561,
5929,
1256,
267,
21992,
63,
82,
275,
22561,
5929,
342,
267,
21992,
275,
283,
7217,
334,
21,
6546,
3171,
398,
327,
1586,
342,
1077,
372,
282,
21479,
267,
2984,
275,
21479,
8,
11412,
9,
267,
486,
17,
275,
21992,
63,
82,
14,
739,
8,
11412,
9,
267,
486,
18,
275,
21992,
63,
82,
14,
739,
8,
2975,
8,
11412,
430,
398,
367,
9671,
315,
334,
71,
17,
12,
486,
18,
304,
288,
291,
14,
629,
8,
1121,
12,
9671,
9,
398,
327,
7719,
1454,
4729,
7116,
2251,
14,
267,
291,
14,
1855,
8,
4333,
12,
21992,
63,
82,
14,
739,
12,
413,
9,
267,
291,
14,
1855,
8,
4333,
12,
21992,
63,
82,
14,
739,
12,
3335,
360,
1421,
1333,
339,
347,
511,
996,
63,
11412,
5491,
8,
277,
304,
267,
327,
20507,
282,
22561,
6261,
1256,
12,
5343,
2399,
12448,
3324,
14,
267,
21992,
63,
87,
275,
22561,
6261,
342,
267,
291,
14,
1855,
8,
4333,
12,
21992,
63,
87,
423,
409,
63,
4695,
12,
22561,
5929,
14,
4695,
63,
466,
1012,
398,
2984,
275,
21479,
360,
7217,
334,
21,
6546,
5942,
267,
2984,
63,
11412,
275,
283,
7217,
334,
21,
14,
9409,
6546,
14,
9409,
3171,
267,
291,
14,
629,
8,
1121,
63,
11412,
12,
21992,
63,
87,
14,
952,
8,
1121,
430,
339,
347,
511,
1644,
63,
18914,
5503,
8,
277,
304,
267,
327,
20507,
282,
644,
12780,
5929,
1256,
267,
24249,
63,
82,
275,
644,
12780,
5929,
342,
398,
6318,
275,
283,
3607,
614,
8854,
20,
15672,
2167,
1401,
15672,
7,
267,
24249,
275,
3335,
8,
27460,
14,
65,
18,
66,
63,
4097,
8,
4097,
430,
267,
2984,
275,
21479,
8,
4097,
9,
398,
327,
1586,
342,
1077,
372,
282,
21479,
641,
1902,
282,
6318,
1059,
503,
267,
327,
282,
644,
12780,
3335,
14,
267,
486,
17,
275,
24249,
63,
82,
14,
739,
8,
18914,
9,
267,
486,
18,
275,
24249,
63,
82,
14,
739,
8,
4097,
9,
267,
367,
9671,
315,
334,
71,
17,
12,
486,
18,
304,
288,
291,
14,
629,
8,
1121,
12,
9671,
9,
398,
4875,
63,
1210,
275,
334,
17,
12,
959,
14,
1789,
12,
488,
12,
756,
9,
267,
367,
4875,
63,
18914,
315,
4875,
63,
1210,
26,
288,
291,
14,
1855,
8,
4333,
12,
24249,
63,
82,
14,
739,
12,
4875,
63,
18914,
9,
5493,
347,
511,
966,
63,
18914,
5491,
8,
277,
304,
267,
24249,
63,
87,
275,
644,
12780,
6261,
342,
398,
327,
17634,
1298,
402,
283,
7217,
334,
21,
6546,
3171,
315,
6318,
1553,
1373,
3293,
436,
267,
327,
314,
1163,
543,
314,
3696,
1865,
2896,
14,
267,
486,
275,
21479,
360,
7217,
334,
21,
6546,
5942,
267,
6318,
17,
275,
283,
11502,
15672,
3273,
9862,
15672,
1644,
17702,
7,
267,
24249,
17,
275,
3335,
8,
27460,
14,
65,
18,
66,
63,
4097,
8,
4097,
17,
430,
267,
6318,
18,
275,
283,
3607,
614,
8854,
20,
15672,
2167,
1401,
15672,
7,
267,
24249,
18,
275,
3335,
8,
27460,
14,
65,
18,
66,
63,
4097,
8,
4097,
18,
430,
398,
291,
14,
629,
8,
4097,
17,
12,
24249,
63,
87,
14,
952,
63,
4097,
8,
71,
430,
267,
291,
14,
629,
8,
18914,
17,
12,
24249,
63,
87,
14,
952,
8,
71,
430,
398,
327,
23312,
4039,
4875,
3696,
14387,
787,
440,
10226,
14,
267,
367,
4875,
63,
19415,
315,
5868,
17,
12,
499,
12,
959,
1789,
12,
283,
1421,
297,
488,
304,
288,
327,
24228,
402,
658,
18914,
63,
87,
14,
19415,
275,
4875,
63,
19415,
64,
288,
291,
14,
1855,
8,
3393,
12,
24249,
63,
87,
423,
409,
63,
19415,
12,
4875,
63,
19415,
9,
10631,
327,
13510,
314,
30310,
370,
378,
334,
509,
13123,
3447,
6268,
9,
267,
24249,
63,
87,
14,
19415,
275,
378,
267,
291,
14,
629,
8,
4097,
18,
12,
24249,
63,
87,
14,
952,
63,
4097,
8,
71,
430,
267,
291,
14,
629,
8,
18914,
18,
12,
24249,
63,
87,
14,
952,
8,
71,
430,
398,
327,
10257,
370,
491,
390,
1118,
3447,
6268,
267,
24249,
63,
87,
14,
19415,
275,
413,
398,
327,
7356,
12,
9936,
734,
314,
650,
36,
436,
22425,
3285,
14,
267,
486,
275,
21479,
360,
7217,
334,
21,
6546,
5557,
5942,
267,
486,
14,
10498,
275,
26719,
2728,
6318,
19,
68,
275,
283,
11502,
993,
24,
15672,
30826,
15672,
1644,
1342,
15672,
1644,
10037,
7,
267,
24249,
19,
68,
275,
3335,
8,
27460,
14,
65,
18,
66,
63,
4097,
8,
4097,
19,
68,
430,
267,
6318,
19,
68,
63,
10498,
275,
283,
11502,
993,
33,
16,
37,
2976,
9409,
30826,
15672,
1644,
1342,
15672,
1644,
10037,
7,
267,
24249,
19,
68,
63,
10498,
275,
3335,
8,
27460,
14,
65,
18,
66,
63,
4097,
8,
4097,
19,
68,
63,
10498,
430,
398,
327,
23312,
4039,
4875,
1072,
7365,
787,
440,
10226,
267,
367,
4875,
63,
548,
3572,
315,
5868,
17,
12,
378,
12,
413,
12,
841,
12,
841,
1789,
12,
283,
1421,
297,
488,
304,
288,
327,
24228,
402,
658,
18914,
63,
87,
14,
548,
3572,
275,
4875,
63,
548,
3572,
64,
288,
291,
14,
1855,
8,
3393,
12,
24249,
63,
87,
423,
409,
63,
548,
3572,
12,
4875,
63,
548,
3572,
9,
398,
327,
5723,
2295,
911,
2449,
641,
650,
14,
16,
14,
16,
2952,
402,
282,
6519,
626,
1990,
6317,
315,
650,
14,
17,
26,
267,
327,
1455,
921,
23047,
14,
736,
6721,
14,
1308,
15,
12151,
15,
9201,
15,
9669,
267,
340,
440,
30259,
63,
1023,
63,
815,
12047,
1023,
2278,
2460,
360,
19,
14,
16,
30194,
288,
327,
7356,
4260,
314,
1072,
7365,
370,
506,
650,
288,
24249,
63,
87,
14,
548,
3572,
275,
650,
953,
291,
14,
629,
8,
4097,
19,
68,
12,
24249,
63,
87,
14,
952,
63,
4097,
8,
71,
430,
288,
291,
14,
629,
8,
18914,
19,
68,
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,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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
] |
gitlabhq/pygments.rb
|
vendor/pygments-main/pygments/styles/default.py
|
364
|
2532
|
# -*- coding: utf-8 -*-
"""
pygments.styles.default
~~~~~~~~~~~~~~~~~~~~~~~
The default highlighting style.
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
Number, Operator, Generic, Whitespace
class DefaultStyle(Style):
"""
The default style (inspired by Emacs 22).
"""
background_color = "#f8f8f8"
default_style = ""
styles = {
Whitespace: "#bbbbbb",
Comment: "italic #408080",
Comment.Preproc: "noitalic #BC7A00",
#Keyword: "bold #AA22FF",
Keyword: "bold #008000",
Keyword.Pseudo: "nobold",
Keyword.Type: "nobold #B00040",
Operator: "#666666",
Operator.Word: "bold #AA22FF",
Name.Builtin: "#008000",
Name.Function: "#0000FF",
Name.Class: "bold #0000FF",
Name.Namespace: "bold #0000FF",
Name.Exception: "bold #D2413A",
Name.Variable: "#19177C",
Name.Constant: "#880000",
Name.Label: "#A0A000",
Name.Entity: "bold #999999",
Name.Attribute: "#7D9029",
Name.Tag: "bold #008000",
Name.Decorator: "#AA22FF",
String: "#BA2121",
String.Doc: "italic",
String.Interpol: "bold #BB6688",
String.Escape: "bold #BB6622",
String.Regex: "#BB6688",
#String.Symbol: "#B8860B",
String.Symbol: "#19177C",
String.Other: "#008000",
Number: "#666666",
Generic.Heading: "bold #000080",
Generic.Subheading: "bold #800080",
Generic.Deleted: "#A00000",
Generic.Inserted: "#00A000",
Generic.Error: "#FF0000",
Generic.Emph: "italic",
Generic.Strong: "bold",
Generic.Prompt: "bold #000080",
Generic.Output: "#888",
Generic.Traceback: "#04D",
Error: "border:#FF0000"
}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12955,
14,
885,
272,
18294,
2878,
23597,
339,
710,
849,
22437,
3449,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
504,
13277,
14,
2487,
492,
19442,
199,
504,
13277,
14,
1418,
492,
6431,
12,
2812,
12,
6819,
12,
2624,
12,
4520,
12,
971,
1362,
4860,
12,
11013,
12,
8307,
12,
24403,
421,
199,
533,
3758,
6609,
8,
6609,
304,
272,
408,
272,
710,
849,
3449,
334,
262,
8721,
581,
701,
662,
19309,
6928,
680,
272,
408,
339,
8020,
63,
2326,
275,
5426,
70,
24,
70,
24,
70,
24,
2,
272,
849,
63,
2487,
275,
3087,
339,
15725,
275,
469,
267,
24403,
26,
4483,
5426,
14923,
2501,
401,
267,
6819,
26,
7861,
298,
21843,
327,
2167,
15844,
401,
267,
6819,
14,
19285,
26,
3698,
298,
889,
21843,
327,
6265,
23,
33,
383,
401,
398,
327,
10650,
26,
7861,
298,
9771,
327,
2276,
1081,
1665,
401,
267,
6431,
26,
7861,
298,
9771,
327,
8662,
1493,
401,
267,
6431,
14,
23414,
26,
3322,
298,
889,
9771,
401,
267,
6431,
14,
804,
26,
4519,
298,
889,
9771,
327,
34,
383,
11189,
401,
398,
11013,
26,
8295,
5426,
6997,
1272,
401,
267,
11013,
14,
10155,
26,
3777,
298,
9771,
327,
2276,
1081,
1665,
401,
398,
2812,
14,
12306,
26,
4519,
5426,
8662,
1493,
401,
267,
2812,
14,
3481,
26,
3777,
5426,
993,
1665,
401,
267,
2812,
14,
2543,
26,
4483,
298,
9771,
327,
993,
1665,
401,
267,
2812,
14,
8814,
26,
3322,
298,
9771,
327,
993,
1665,
401,
267,
2812,
14,
1726,
26,
3322,
298,
9771,
327,
36,
1194,
969,
33,
401,
267,
2812,
14,
2773,
26,
3777,
5426,
1167,
8881,
35,
401,
267,
2812,
14,
9737,
26,
3777,
5426,
1299,
993,
401,
267,
2812,
14,
4314,
26,
4483,
5426,
33,
16,
33,
1493,
401,
267,
2812,
14,
7302,
26,
5185,
298,
9771,
327,
20036,
401,
267,
2812,
14,
1646,
26,
3322,
5426,
23,
36,
25,
13996,
401,
267,
2812,
14,
1931,
26,
8295,
298,
9771,
327,
8662,
1493,
401,
267,
2812,
14,
14946,
26,
3322,
5426,
2276,
1081,
1665,
401,
398,
2624,
26,
8540,
5426,
4134,
18,
10753,
401,
267,
2624,
14,
3768,
26,
4483,
298,
21843,
401,
267,
2624,
14,
22713,
26,
3698,
298,
9771,
327,
5342,
1272,
1299,
401,
267,
2624,
14,
10260,
26,
3777,
298,
9771,
327,
5342,
1272,
1081,
401,
267,
2624,
14,
5103,
26,
4519,
5426,
5342,
1272,
1299,
401,
267,
327,
1558,
14,
8169,
26,
3777,
5426,
34,
24,
14832,
34,
401,
267,
2624,
14,
8169,
26,
3777,
5426,
1167,
8881,
35,
401,
267,
2624,
14,
8632,
26,
4519,
5426,
8662,
1493,
401,
267,
4860,
26,
8540,
5426,
6997,
1272,
401,
398,
8307,
14,
23818,
26,
3698,
298,
9771,
327,
993,
1257,
401,
267,
8307,
14,
2610,
13983,
26,
263,
298,
9771,
327,
15214,
1257,
401,
267,
8307,
14,
17735,
26,
3698,
5426,
33,
5345,
401,
267,
8307,
14,
607,
9449,
26,
3515,
5426,
383,
33,
1493,
401,
267,
8307,
14,
547,
26,
3777,
5426,
1665,
993,
401,
267,
8307,
14,
37,
311,
72,
26,
4519,
298,
21843,
401,
267,
8307,
14,
2848,
951,
26,
3322,
298,
9771,
401,
267,
8307,
14,
20430,
26,
3322,
298,
9771,
327,
993,
1257,
401,
267,
8307,
14,
2959,
26,
3322,
5426,
13997,
401,
267,
8307,
14,
15905,
26,
260,
5426,
966,
36,
401,
398,
4520,
26,
9326,
298,
8665,
15596,
1665,
993,
2,
272,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12955,
14,
885,
272,
18294,
2878,
23597,
339,
710,
849,
22437,
3449,
14,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
504,
13277,
14,
2487,
492,
19442,
199,
504,
13277,
14,
1418,
492,
6431,
12,
2812,
12,
6819,
12,
2624,
12,
4520,
12,
971,
1362,
4860,
12,
11013,
12,
8307,
12,
24403,
421,
199,
533,
3758,
6609,
8,
6609,
304,
272,
408,
272,
710,
849,
3449,
334,
262,
8721,
581,
701,
662,
19309,
6928,
680,
272,
408,
339,
8020,
63,
2326,
275,
5426,
70,
24,
70,
24,
70,
24,
2,
272,
849,
63,
2487,
275,
3087,
339,
15725,
275,
469,
267,
24403,
26,
4483,
5426,
14923,
2501,
401,
267,
6819,
26,
7861,
298,
21843,
327,
2167,
15844,
401,
267,
6819,
14,
19285,
26,
3698,
298,
889,
21843,
327,
6265,
23,
33,
383,
401,
398,
327,
10650,
26,
7861,
298,
9771,
327,
2276,
1081,
1665,
401,
267,
6431,
26,
7861,
298,
9771,
327,
8662,
1493,
401,
267,
6431,
14,
23414,
26,
3322,
298,
889,
9771,
401,
267,
6431,
14,
804,
26,
4519,
298,
889,
9771,
327,
34,
383,
11189,
401,
398,
11013,
26,
8295,
5426,
6997,
1272,
401,
267,
11013,
14,
10155,
26,
3777,
298,
9771,
327,
2276,
1081,
1665,
401,
398,
2812,
14,
12306,
26,
4519,
5426,
8662,
1493,
401,
267,
2812,
14,
3481,
26,
3777,
5426,
993,
1665,
401,
267,
2812,
14,
2543,
26,
4483,
298,
9771,
327,
993,
1665,
401,
267,
2812,
14,
8814,
26,
3322,
298,
9771,
327,
993,
1665,
401,
267,
2812,
14,
1726,
26,
3322,
298,
9771,
327,
36,
1194,
969,
33,
401,
267,
2812,
14,
2773,
26,
3777,
5426,
1167,
8881,
35,
401,
267,
2812,
14,
9737,
26,
3777,
5426,
1299,
993,
401,
267,
2812,
14,
4314,
26,
4483,
5426,
33,
16,
33,
1493,
401,
267,
2812,
14,
7302,
26,
5185,
298,
9771,
327,
20036,
401,
267,
2812,
14,
1646,
26,
3322,
5426,
23,
36,
25,
13996,
401,
267,
2812,
14,
1931,
26,
8295,
298,
9771,
327,
8662,
1493,
401,
267,
2812,
14,
14946,
26,
3322,
5426,
2276,
1081,
1665,
401,
398,
2624,
26,
8540,
5426,
4134,
18,
10753,
401,
267,
2624,
14,
3768,
26,
4483,
298,
21843,
401,
267,
2624,
14,
22713,
26,
3698,
298,
9771,
327,
5342,
1272,
1299,
401,
267,
2624,
14,
10260,
26,
3777,
298,
9771,
327,
5342,
1272,
1081,
401,
267,
2624,
14,
5103,
26,
4519,
5426,
5342,
1272,
1299,
401,
267,
327,
1558,
14,
8169,
26,
3777,
5426,
34,
24,
14832,
34,
401,
267,
2624,
14,
8169,
26,
3777,
5426,
1167,
8881,
35,
401,
267,
2624,
14,
8632,
26,
4519,
5426,
8662,
1493,
401,
267,
4860,
26,
8540,
5426,
6997,
1272,
401,
398,
8307,
14,
23818,
26,
3698,
298,
9771,
327,
993,
1257,
401,
267,
8307,
14,
2610,
13983,
26,
263,
298,
9771,
327,
15214,
1257,
401,
267,
8307,
14,
17735,
26,
3698,
5426,
33,
5345,
401,
267,
8307,
14,
607,
9449,
26,
3515,
5426,
383,
33,
1493,
401,
267,
8307,
14,
547,
26,
3777,
5426,
1665,
993,
401,
267,
8307,
14,
37,
311,
72,
26,
4519,
298,
21843,
401,
267,
8307,
14,
2848,
951,
26,
3322,
298,
9771,
401,
267,
8307,
14,
20430,
26,
3322,
298,
9771,
327,
993,
1257,
401,
267,
8307,
14,
2959,
26,
3322,
5426,
13997,
401,
267,
8307,
14,
15905,
26,
260,
5426,
966,
36,
401,
398,
4520,
26,
9326,
298,
8665,
15596,
1665,
993,
2,
272,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
racker/python-raxcli
|
raxcli/apps/registry/commands/configuration/get.py
|
1
|
1315
|
# Copyright 2013 Rackspace
#
# 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 logging
from raxcli.apps.registry.utils import BaseRegistryShowCommand
from raxcli.apps.registry.utils import get_client
class GetCommand(BaseRegistryShowCommand):
"""
Return a single configuration value.
"""
log = logging.getLogger(__name__)
def take_action(self, parsed_args):
client = get_client(parsed_args)
value = client.configuration.get(parsed_args.object_id)
result = (value['id'], value['value'])
return (('ID', 'Value'), result)
|
apache-2.0
|
[
3,
1898,
6171,
32679,
199,
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
2050,
421,
199,
504,
660,
1812,
317,
14,
5181,
14,
5189,
14,
1208,
492,
3523,
10899,
6824,
3110,
199,
504,
660,
1812,
317,
14,
5181,
14,
5189,
14,
1208,
492,
664,
63,
1258,
421,
199,
533,
2372,
3110,
8,
1563,
10899,
6824,
3110,
304,
272,
408,
272,
1432,
282,
2849,
2897,
574,
14,
272,
408,
272,
943,
275,
2050,
14,
5572,
3460,
354,
3368,
339,
347,
5452,
63,
1287,
8,
277,
12,
4565,
63,
589,
304,
267,
1890,
275,
664,
63,
1258,
8,
6751,
63,
589,
9,
267,
574,
275,
1890,
14,
4758,
14,
362,
8,
6751,
63,
589,
14,
785,
63,
344,
9,
267,
754,
275,
334,
585,
459,
344,
995,
574,
459,
585,
1105,
267,
372,
13636,
998,
297,
283,
1110,
659,
754,
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
] |
[
1898,
6171,
32679,
199,
3,
199,
3,
3909,
370,
314,
3668,
2290,
2752,
334,
14950,
9,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
2050,
421,
199,
504,
660,
1812,
317,
14,
5181,
14,
5189,
14,
1208,
492,
3523,
10899,
6824,
3110,
199,
504,
660,
1812,
317,
14,
5181,
14,
5189,
14,
1208,
492,
664,
63,
1258,
421,
199,
533,
2372,
3110,
8,
1563,
10899,
6824,
3110,
304,
272,
408,
272,
1432,
282,
2849,
2897,
574,
14,
272,
408,
272,
943,
275,
2050,
14,
5572,
3460,
354,
3368,
339,
347,
5452,
63,
1287,
8,
277,
12,
4565,
63,
589,
304,
267,
1890,
275,
664,
63,
1258,
8,
6751,
63,
589,
9,
267,
574,
275,
1890,
14,
4758,
14,
362,
8,
6751,
63,
589,
14,
785,
63,
344,
9,
267,
754,
275,
334,
585,
459,
344,
995,
574,
459,
585,
1105,
267,
372,
13636,
998,
297,
283,
1110,
659,
754,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
MosheBerman/brisket-mashup
|
source/libraries/simplejson-3.3.1/simplejson/tests/test_decimal.py
|
147
|
2544
|
import decimal
from decimal import Decimal
from unittest import TestCase
from simplejson.compat import StringIO, reload_module
import simplejson as json
class TestDecimal(TestCase):
NUMS = "1.0", "10.00", "1.1", "1234567890.1234567890", "500"
def dumps(self, obj, **kw):
sio = StringIO()
json.dump(obj, sio, **kw)
res = json.dumps(obj, **kw)
self.assertEqual(res, sio.getvalue())
return res
def loads(self, s, **kw):
sio = StringIO(s)
res = json.loads(s, **kw)
self.assertEqual(res, json.load(sio, **kw))
return res
def test_decimal_encode(self):
for d in map(Decimal, self.NUMS):
self.assertEqual(self.dumps(d, use_decimal=True), str(d))
def test_decimal_decode(self):
for s in self.NUMS:
self.assertEqual(self.loads(s, parse_float=Decimal), Decimal(s))
def test_stringify_key(self):
for d in map(Decimal, self.NUMS):
v = {d: d}
self.assertEqual(
self.loads(
self.dumps(v, use_decimal=True), parse_float=Decimal),
{str(d): d})
def test_decimal_roundtrip(self):
for d in map(Decimal, self.NUMS):
# The type might not be the same (int and Decimal) but they
# should still compare equal.
for v in [d, [d], {'': d}]:
self.assertEqual(
self.loads(
self.dumps(v, use_decimal=True), parse_float=Decimal),
v)
def test_decimal_defaults(self):
d = Decimal('1.1')
# use_decimal=True is the default
self.assertRaises(TypeError, json.dumps, d, use_decimal=False)
self.assertEqual('1.1', json.dumps(d))
self.assertEqual('1.1', json.dumps(d, use_decimal=True))
self.assertRaises(TypeError, json.dump, d, StringIO(),
use_decimal=False)
sio = StringIO()
json.dump(d, sio)
self.assertEqual('1.1', sio.getvalue())
sio = StringIO()
json.dump(d, sio, use_decimal=True)
self.assertEqual('1.1', sio.getvalue())
def test_decimal_reload(self):
# Simulate a subinterpreter that reloads the Python modules but not
# the C code https://github.com/simplejson/simplejson/issues/34
global Decimal
Decimal = reload_module(decimal).Decimal
import simplejson.encoder
simplejson.encoder.Decimal = Decimal
self.test_decimal_roundtrip()
|
mit
|
[
646,
6107,
199,
504,
6107,
492,
6345,
199,
504,
2882,
492,
7640,
199,
504,
13804,
14,
5819,
492,
5228,
12,
13101,
63,
578,
199,
199,
646,
13804,
465,
2022,
199,
199,
533,
1379,
6745,
8,
1746,
304,
272,
11576,
51,
275,
298,
17,
14,
16,
401,
298,
709,
14,
383,
401,
298,
17,
14,
17,
401,
298,
21515,
14,
21515,
401,
298,
5783,
2,
272,
347,
16864,
8,
277,
12,
1559,
12,
1011,
829,
304,
267,
29129,
275,
5228,
342,
267,
2022,
14,
2724,
8,
1113,
12,
29129,
12,
1011,
829,
9,
267,
522,
275,
2022,
14,
4180,
8,
1113,
12,
1011,
829,
9,
267,
291,
14,
629,
8,
470,
12,
29129,
14,
7150,
1012,
267,
372,
522,
339,
347,
14404,
8,
277,
12,
308,
12,
1011,
829,
304,
267,
29129,
275,
5228,
8,
83,
9,
267,
522,
275,
2022,
14,
3640,
8,
83,
12,
1011,
829,
9,
267,
291,
14,
629,
8,
470,
12,
2022,
14,
912,
8,
22961,
12,
1011,
829,
430,
267,
372,
522,
339,
347,
511,
63,
6355,
63,
2143,
8,
277,
304,
267,
367,
366,
315,
2341,
8,
6745,
12,
291,
14,
1440,
3053,
304,
288,
291,
14,
629,
8,
277,
14,
4180,
8,
68,
12,
675,
63,
6355,
29,
549,
395,
620,
8,
68,
430,
339,
347,
511,
63,
6355,
63,
2708,
8,
277,
304,
267,
367,
308,
315,
291,
14,
1440,
3053,
26,
288,
291,
14,
629,
8,
277,
14,
3640,
8,
83,
12,
2198,
63,
1609,
29,
6745,
395,
6345,
8,
83,
430,
339,
347,
511,
63,
875,
2021,
63,
498,
8,
277,
304,
267,
367,
366,
315,
2341,
8,
6745,
12,
291,
14,
1440,
3053,
304,
288,
373,
275,
469,
68,
26,
366,
93,
288,
291,
14,
629,
8,
355,
291,
14,
3640,
8,
490,
291,
14,
4180,
8,
86,
12,
675,
63,
6355,
29,
549,
395,
2198,
63,
1609,
29,
6745,
395,
355,
469,
495,
8,
68,
304,
366,
1552,
339,
347,
511,
63,
6355,
63,
25920,
8,
277,
304,
267,
367,
366,
315,
2341,
8,
6745,
12,
291,
14,
1440,
3053,
304,
288,
327,
710,
730,
5594,
440,
506,
314,
2011,
334,
442,
436,
6345,
9,
1325,
2985,
288,
327,
1077,
5139,
6540,
4472,
14,
288,
367,
373,
315,
359,
68,
12,
359,
68,
467,
791,
356,
366,
93,
2189,
355,
291,
14,
629,
8,
490,
291,
14,
3640,
8,
717,
291,
14,
4180,
8,
86,
12,
675,
63,
6355,
29,
549,
395,
2198,
63,
1609,
29,
6745,
395,
490,
373,
9,
339,
347,
511,
63,
6355,
63,
4322,
8,
277,
304,
267,
366,
275,
6345,
360,
17,
14,
17,
358,
267,
327,
675,
63,
6355,
29,
549,
365,
314,
849,
267,
291,
14,
1855,
8,
4333,
12,
2022,
14,
4180,
12,
366,
12,
675,
63,
6355,
29,
797,
9,
267,
291,
14,
629,
360,
17,
14,
17,
297,
2022,
14,
4180,
8,
68,
430,
267,
291,
14,
629,
360,
17,
14,
17,
297,
2022,
14,
4180,
8,
68,
12,
675,
63,
6355,
29,
549,
430,
267,
291,
14,
1855,
8,
4333,
12,
2022,
14,
2724,
12,
366,
12,
5228,
1062,
2079,
675,
63,
6355,
29,
797,
9,
267,
29129,
275,
5228,
342,
267,
2022,
14,
2724,
8,
68,
12,
29129,
9,
267,
291,
14,
629,
360,
17,
14,
17,
297,
29129,
14,
7150,
1012,
267,
29129,
275,
5228,
342,
267,
2022,
14,
2724,
8,
68,
12,
29129,
12,
675,
63,
6355,
29,
549,
9,
267,
291,
14,
629,
360,
17,
14,
17,
297,
29129,
14,
7150,
1012,
339,
347,
511,
63,
6355,
63,
9233,
8,
277,
304,
267,
327,
10751,
5434,
282,
1007,
20244,
626,
295,
3640,
314,
2018,
4621,
1325,
440,
267,
327,
314,
445,
1233,
4178,
921,
5031,
14,
957,
15,
4129,
1001,
15,
4129,
1001,
15,
10115,
15,
1082,
267,
2288,
6345,
267,
6345,
275,
13101,
63,
578,
8,
6355,
680,
6745,
267,
492,
13804,
14,
9347,
267,
13804,
14,
9347,
14,
6745,
275,
6345,
267,
291,
14,
396,
63,
6355,
63,
25920,
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
] |
[
6107,
199,
504,
6107,
492,
6345,
199,
504,
2882,
492,
7640,
199,
504,
13804,
14,
5819,
492,
5228,
12,
13101,
63,
578,
199,
199,
646,
13804,
465,
2022,
199,
199,
533,
1379,
6745,
8,
1746,
304,
272,
11576,
51,
275,
298,
17,
14,
16,
401,
298,
709,
14,
383,
401,
298,
17,
14,
17,
401,
298,
21515,
14,
21515,
401,
298,
5783,
2,
272,
347,
16864,
8,
277,
12,
1559,
12,
1011,
829,
304,
267,
29129,
275,
5228,
342,
267,
2022,
14,
2724,
8,
1113,
12,
29129,
12,
1011,
829,
9,
267,
522,
275,
2022,
14,
4180,
8,
1113,
12,
1011,
829,
9,
267,
291,
14,
629,
8,
470,
12,
29129,
14,
7150,
1012,
267,
372,
522,
339,
347,
14404,
8,
277,
12,
308,
12,
1011,
829,
304,
267,
29129,
275,
5228,
8,
83,
9,
267,
522,
275,
2022,
14,
3640,
8,
83,
12,
1011,
829,
9,
267,
291,
14,
629,
8,
470,
12,
2022,
14,
912,
8,
22961,
12,
1011,
829,
430,
267,
372,
522,
339,
347,
511,
63,
6355,
63,
2143,
8,
277,
304,
267,
367,
366,
315,
2341,
8,
6745,
12,
291,
14,
1440,
3053,
304,
288,
291,
14,
629,
8,
277,
14,
4180,
8,
68,
12,
675,
63,
6355,
29,
549,
395,
620,
8,
68,
430,
339,
347,
511,
63,
6355,
63,
2708,
8,
277,
304,
267,
367,
308,
315,
291,
14,
1440,
3053,
26,
288,
291,
14,
629,
8,
277,
14,
3640,
8,
83,
12,
2198,
63,
1609,
29,
6745,
395,
6345,
8,
83,
430,
339,
347,
511,
63,
875,
2021,
63,
498,
8,
277,
304,
267,
367,
366,
315,
2341,
8,
6745,
12,
291,
14,
1440,
3053,
304,
288,
373,
275,
469,
68,
26,
366,
93,
288,
291,
14,
629,
8,
355,
291,
14,
3640,
8,
490,
291,
14,
4180,
8,
86,
12,
675,
63,
6355,
29,
549,
395,
2198,
63,
1609,
29,
6745,
395,
355,
469,
495,
8,
68,
304,
366,
1552,
339,
347,
511,
63,
6355,
63,
25920,
8,
277,
304,
267,
367,
366,
315,
2341,
8,
6745,
12,
291,
14,
1440,
3053,
304,
288,
327,
710,
730,
5594,
440,
506,
314,
2011,
334,
442,
436,
6345,
9,
1325,
2985,
288,
327,
1077,
5139,
6540,
4472,
14,
288,
367,
373,
315,
359,
68,
12,
359,
68,
467,
791,
356,
366,
93,
2189,
355,
291,
14,
629,
8,
490,
291,
14,
3640,
8,
717,
291,
14,
4180,
8,
86,
12,
675,
63,
6355,
29,
549,
395,
2198,
63,
1609,
29,
6745,
395,
490,
373,
9,
339,
347,
511,
63,
6355,
63,
4322,
8,
277,
304,
267,
366,
275,
6345,
360,
17,
14,
17,
358,
267,
327,
675,
63,
6355,
29,
549,
365,
314,
849,
267,
291,
14,
1855,
8,
4333,
12,
2022,
14,
4180,
12,
366,
12,
675,
63,
6355,
29,
797,
9,
267,
291,
14,
629,
360,
17,
14,
17,
297,
2022,
14,
4180,
8,
68,
430,
267,
291,
14,
629,
360,
17,
14,
17,
297,
2022,
14,
4180,
8,
68,
12,
675,
63,
6355,
29,
549,
430,
267,
291,
14,
1855,
8,
4333,
12,
2022,
14,
2724,
12,
366,
12,
5228,
1062,
2079,
675,
63,
6355,
29,
797,
9,
267,
29129,
275,
5228,
342,
267,
2022,
14,
2724,
8,
68,
12,
29129,
9,
267,
291,
14,
629,
360,
17,
14,
17,
297,
29129,
14,
7150,
1012,
267,
29129,
275,
5228,
342,
267,
2022,
14,
2724,
8,
68,
12,
29129,
12,
675,
63,
6355,
29,
549,
9,
267,
291,
14,
629,
360,
17,
14,
17,
297,
29129,
14,
7150,
1012,
339,
347,
511,
63,
6355,
63,
9233,
8,
277,
304,
267,
327,
10751,
5434,
282,
1007,
20244,
626,
295,
3640,
314,
2018,
4621,
1325,
440,
267,
327,
314,
445,
1233,
4178,
921,
5031,
14,
957,
15,
4129,
1001,
15,
4129,
1001,
15,
10115,
15,
1082,
267,
2288,
6345,
267,
6345,
275,
13101,
63,
578,
8,
6355,
680,
6745,
267,
492,
13804,
14,
9347,
267,
13804,
14,
9347,
14,
6745,
275,
6345,
267,
291,
14,
396,
63,
6355,
63,
25920,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
crmccreary/openerp_server
|
openerp/addons/import_base/__init__.py
|
9
|
1089
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Openerp sa (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import import_framework
import mapper
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
9319,
4457,
2937,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
492,
63,
4857,
199,
646,
7796,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
9319,
4457,
2937,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
492,
63,
4857,
199,
646,
7796,
199,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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autifier.org>
#
# written by Stefano Sanfilippo <a.little.coder@gmail.com>
#
# usage:
#
# if detect(some_string):
# unpacked = unpack(some_string)
#
# CAVEAT by Einar Lielmanis
#
# You really don't want to obfuscate your scripts there: they're tracking
# your unpackings, your script gets turned into something like this,
# as of 2011-08-26:
#
# var _escape = 'your_script_escaped';
# var _111 = document.createElement('script');
# _111.src = 'http://api.www.myobfuscate.com/?getsrc=ok' +
# '&ref=' + encodeURIComponent(document.referrer) +
# '&url=' + encodeURIComponent(document.URL);
# var 000 = document.getElementsByTagName('head')[0];
# 000.appendChild(_111);
# document.write(unescape(_escape));
#
"""Deobfuscator for scripts messed up with MyObfuscate.com"""
import re
import base64
# Python 2 retrocompatibility
# pylint: disable=F0401
# pylint: disable=E0611
try:
from urllib import unquote
except ImportError:
from urllib.parse import unquote
from . import UnpackingError
PRIORITY = 1
CAVEAT = """//
// Unpacker warning: be careful when using myobfuscate.com for your projects:
// scripts obfuscated by the free online version call back home.
//
"""
SIGNATURE = (r'["\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F'
r'\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x61\x62\x63\x64\x65'
r'\x66\x67\x68\x69\x6A\x6B\x6C\x6D\x6E\x6F\x70\x71\x72\x73\x74\x75'
r'\x76\x77\x78\x79\x7A\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x2B'
r'\x2F\x3D","","\x63\x68\x61\x72\x41\x74","\x69\x6E\x64\x65\x78'
r'\x4F\x66","\x66\x72\x6F\x6D\x43\x68\x61\x72\x43\x6F\x64\x65","'
r'\x6C\x65\x6E\x67\x74\x68"]')
def detect(source):
"""Detects MyObfuscate.com packer."""
return SIGNATURE in source
def unpack(source):
"""Unpacks js code packed with MyObfuscate.com"""
if not detect(source):
return source
payload = unquote(_filter(source))
match = re.search(r"^var _escape\='<script>(.*)<\/script>'",
payload, re.DOTALL)
polished = match.group(1) if match else source
return CAVEAT + polished
def _filter(source):
"""Extracts and decode payload (original file) from `source`"""
try:
varname = re.search(r'eval\(\w+\(\w+\((\w+)\)\)\);', source).group(1)
reverse = re.search(r"var +%s *\= *'(.*)';" % varname, source).group(1)
except AttributeError:
raise UnpackingError('Malformed MyObfuscate data.')
try:
return base64.b64decode(reverse[::-1].encode('utf8')).decode('utf8')
except TypeError:
raise UnpackingError('MyObfuscate payload is not base64-encoded.')
|
mit
|
[
3,
199,
3,
477,
2873,
31958,
67,
707,
367,
10554,
26560,
939,
1536,
543,
3002,
2873,
31958,
1411,
14,
957,
199,
3,
701,
662,
262,
285,
491,
14769,
1237,
374,
665,
69,
262,
285,
32,
3596,
30745,
935,
3895,
14,
1308,
30,
199,
3,
199,
3,
258,
5313,
701,
17854,
70,
8143,
29359,
329,
3587,
555,
665,
65,
14,
10182,
14,
2693,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
4503,
26,
199,
3,
199,
3,
340,
9696,
8,
3972,
63,
875,
304,
199,
3,
258,
23389,
275,
7787,
8,
3972,
63,
875,
9,
199,
3,
199,
199,
3,
7240,
2524,
619,
701,
662,
262,
285,
491,
14769,
1237,
374,
199,
199,
3,
199,
3,
2047,
7710,
2793,
1133,
2934,
370,
2607,
31958,
1411,
2195,
10554,
2337,
26,
2985,
3984,
15161,
199,
3,
2195,
7787,
780,
12,
2195,
2884,
7545,
19136,
1901,
6020,
2839,
642,
12,
199,
3,
465,
402,
7760,
13,
2036,
13,
1479,
26,
199,
3,
199,
3,
257,
2729,
485,
3765,
275,
283,
12695,
63,
1579,
63,
13572,
13619,
199,
3,
257,
2729,
485,
6673,
275,
2213,
14,
20296,
360,
1579,
11339,
199,
3,
257,
485,
6673,
14,
2164,
275,
283,
1014,
921,
1246,
14,
1544,
14,
1662,
2873,
31958,
1411,
14,
957,
10197,
362,
2164,
29,
745,
7,
435,
199,
3,
4519,
7673,
1121,
534,
435,
3752,
1230,
948,
22527,
1946,
8,
3554,
14,
21928,
3859,
9,
435,
199,
3,
4519,
7673,
633,
534,
435,
3752,
1230,
948,
22527,
1946,
8,
3554,
14,
2632,
2736,
199,
3,
257,
2729,
21551,
275,
2213,
14,
15045,
360,
2993,
5832,
16,
11566,
199,
3,
257,
21551,
14,
14988,
1547,
6673,
2736,
199,
3,
257,
2213,
14,
952,
8,
22726,
1547,
3765,
16674,
199,
3,
199,
199,
624,
872,
2873,
31958,
67,
707,
367,
10554,
26560,
939,
1536,
543,
4932,
47,
4361,
527,
1411,
14,
957,
624,
199,
199,
646,
295,
199,
646,
1300,
772,
199,
199,
3,
2018,
499,
295,
1374,
15390,
199,
3,
4287,
26,
3507,
29,
38,
28025,
199,
3,
4287,
26,
3507,
29,
37,
1690,
845,
199,
893,
26,
272,
687,
4011,
492,
14342,
199,
2590,
3545,
26,
272,
687,
4011,
14,
1122,
492,
14342,
199,
199,
504,
1275,
492,
31017,
316,
547,
199,
199,
25144,
275,
413,
199,
199,
3263,
2524,
619,
275,
408,
501,
199,
501,
31017,
281,
5721,
26,
506,
25082,
1380,
1808,
3002,
2873,
31958,
1411,
14,
957,
367,
2195,
11336,
26,
199,
501,
10554,
2607,
31958,
3153,
701,
314,
2867,
18470,
1015,
1240,
1771,
5629,
14,
199,
501,
199,
199,
624,
199,
199,
26588,
275,
334,
82,
7,
905,
60,
88,
2953,
60,
88,
2260,
60,
88,
2824,
60,
88,
1602,
60,
88,
2322,
60,
88,
2466,
60,
88,
2417,
60,
88,
2006,
60,
88,
1887,
60,
88,
20,
33,
60,
88,
20,
34,
60,
88,
20,
35,
60,
88,
20,
36,
60,
88,
20,
37,
60,
88,
20,
38,
7,
1467,
519,
1154,
88,
1400,
60,
88,
2869,
60,
88,
2528,
60,
88,
2481,
60,
88,
1477,
60,
88,
1229,
60,
88,
1367,
60,
88,
1641,
60,
88,
2010,
60,
88,
1427,
60,
88,
21,
33,
60,
88,
2976,
60,
88,
2789,
60,
88,
2766,
60,
88,
772,
60,
88,
2182,
7,
1467,
519,
1154,
88,
1272,
60,
88,
1822,
60,
88,
2333,
60,
88,
1876,
60,
88,
22,
33,
60,
88,
22,
34,
60,
88,
22,
35,
60,
88,
22,
36,
60,
88,
22,
37,
60,
88,
22,
38,
60,
88,
2760,
60,
88,
3172,
60,
88,
2819,
60,
88,
2898,
60,
88,
1342,
60,
88,
2194,
7,
1467,
519,
1154,
88,
2114,
60,
88,
1138,
60,
88,
2277,
60,
88,
1965,
60,
88,
23,
33,
60,
88,
1216,
60,
88,
2192,
60,
88,
708,
60,
88,
1153,
60,
88,
1082,
60,
88,
1276,
60,
88,
1344,
60,
88,
1401,
60,
88,
1703,
60,
88,
1355,
60,
88,
18,
34,
7,
1467,
519,
1154,
88,
18,
38,
60,
88,
19,
36,
401,
5151,
3212,
88,
2766,
60,
88,
2333,
60,
88,
2976,
60,
88,
2819,
60,
88,
2953,
60,
88,
1342,
2266,
60,
88,
1876,
60,
88,
22,
37,
60,
88,
772,
60,
88,
2182,
60,
88,
2277,
7,
1467,
519,
1154,
88,
20,
38,
60,
88,
1272,
2266,
60,
88,
1272,
60,
88,
2819,
60,
88,
22,
38,
60,
88,
22,
36,
60,
88,
2824,
60,
88,
2333,
60,
88,
2976,
60,
88,
2819,
60,
88,
2824,
60,
88,
22,
38,
60,
88,
772,
60,
88,
2182,
2266,
7,
1467,
519,
1154,
88,
22,
35,
60,
88,
2182,
60,
88,
22,
37,
60,
88,
1822,
60,
88,
1342,
60,
88,
2333,
937,
358,
199,
199,
318,
9696,
8,
1365,
304,
272,
408,
872,
28853,
4932,
47,
4361,
527,
1411,
14,
957,
1706,
281,
1041,
272,
372,
5056,
13214,
315,
1350,
199,
199,
318,
7787,
8,
1365,
304,
272,
408,
26472,
83,
8586,
1233,
13170,
543,
4932,
47,
4361,
527,
1411,
14,
957,
624,
272,
340,
440,
9696,
8,
1365,
304,
267,
372,
1350,
272,
4886,
275,
14342,
1547,
1541,
8,
1365,
430,
272,
1336,
275,
295,
14,
1733,
8,
82,
16136,
1391,
485,
3765,
60,
15829,
1579,
13661,
12432,
28,
19814,
1579,
3524,
401,
1993,
4886,
12,
295,
14,
16504,
9,
272,
1115,
1891,
379,
275,
1336,
14,
923,
8,
17,
9,
340,
1336,
587,
1350,
272,
372,
7240,
2524,
619,
435,
1115,
1891,
379,
199,
199,
318,
485,
1541,
8,
1365,
304,
272,
408,
12147,
83,
436,
4849,
4886,
334,
5043,
570,
9,
687,
658,
1365,
64,
624,
272,
862,
26,
267,
22071,
275,
295,
14,
1733,
8,
82,
7,
2579,
29323,
87,
7896,
2961,
87,
7896,
1332,
60,
87,
13439,
2862,
2862,
27853,
1350,
680,
923,
8,
17,
9,
267,
3837,
275,
295,
14,
1733,
8,
82,
2,
1391,
435,
5,
83,
30940,
29,
627,
6774,
2795,
3171,
9426,
450,
22071,
12,
1350,
680,
923,
8,
17,
9,
272,
871,
4281,
26,
267,
746,
31017,
316,
547,
360,
29513,
4932,
47,
4361,
527,
1411,
666,
2659,
272,
862,
26,
267,
372,
1300,
772,
14,
66,
772,
2708,
8,
4471,
14172,
17,
1055,
2143,
360,
1624,
24,
11103,
2708,
360,
1624,
24,
358,
272,
871,
3146,
26,
267,
746,
31017
] |
[
199,
3,
477,
2873,
31958,
67,
707,
367,
10554,
26560,
939,
1536,
543,
3002,
2873,
31958,
1411,
14,
957,
199,
3,
701,
662,
262,
285,
491,
14769,
1237,
374,
665,
69,
262,
285,
32,
3596,
30745,
935,
3895,
14,
1308,
30,
199,
3,
199,
3,
258,
5313,
701,
17854,
70,
8143,
29359,
329,
3587,
555,
665,
65,
14,
10182,
14,
2693,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
4503,
26,
199,
3,
199,
3,
340,
9696,
8,
3972,
63,
875,
304,
199,
3,
258,
23389,
275,
7787,
8,
3972,
63,
875,
9,
199,
3,
199,
199,
3,
7240,
2524,
619,
701,
662,
262,
285,
491,
14769,
1237,
374,
199,
199,
3,
199,
3,
2047,
7710,
2793,
1133,
2934,
370,
2607,
31958,
1411,
2195,
10554,
2337,
26,
2985,
3984,
15161,
199,
3,
2195,
7787,
780,
12,
2195,
2884,
7545,
19136,
1901,
6020,
2839,
642,
12,
199,
3,
465,
402,
7760,
13,
2036,
13,
1479,
26,
199,
3,
199,
3,
257,
2729,
485,
3765,
275,
283,
12695,
63,
1579,
63,
13572,
13619,
199,
3,
257,
2729,
485,
6673,
275,
2213,
14,
20296,
360,
1579,
11339,
199,
3,
257,
485,
6673,
14,
2164,
275,
283,
1014,
921,
1246,
14,
1544,
14,
1662,
2873,
31958,
1411,
14,
957,
10197,
362,
2164,
29,
745,
7,
435,
199,
3,
4519,
7673,
1121,
534,
435,
3752,
1230,
948,
22527,
1946,
8,
3554,
14,
21928,
3859,
9,
435,
199,
3,
4519,
7673,
633,
534,
435,
3752,
1230,
948,
22527,
1946,
8,
3554,
14,
2632,
2736,
199,
3,
257,
2729,
21551,
275,
2213,
14,
15045,
360,
2993,
5832,
16,
11566,
199,
3,
257,
21551,
14,
14988,
1547,
6673,
2736,
199,
3,
257,
2213,
14,
952,
8,
22726,
1547,
3765,
16674,
199,
3,
199,
199,
624,
872,
2873,
31958,
67,
707,
367,
10554,
26560,
939,
1536,
543,
4932,
47,
4361,
527,
1411,
14,
957,
624,
199,
199,
646,
295,
199,
646,
1300,
772,
199,
199,
3,
2018,
499,
295,
1374,
15390,
199,
3,
4287,
26,
3507,
29,
38,
28025,
199,
3,
4287,
26,
3507,
29,
37,
1690,
845,
199,
893,
26,
272,
687,
4011,
492,
14342,
199,
2590,
3545,
26,
272,
687,
4011,
14,
1122,
492,
14342,
199,
199,
504,
1275,
492,
31017,
316,
547,
199,
199,
25144,
275,
413,
199,
199,
3263,
2524,
619,
275,
408,
501,
199,
501,
31017,
281,
5721,
26,
506,
25082,
1380,
1808,
3002,
2873,
31958,
1411,
14,
957,
367,
2195,
11336,
26,
199,
501,
10554,
2607,
31958,
3153,
701,
314,
2867,
18470,
1015,
1240,
1771,
5629,
14,
199,
501,
199,
199,
624,
199,
199,
26588,
275,
334,
82,
7,
905,
60,
88,
2953,
60,
88,
2260,
60,
88,
2824,
60,
88,
1602,
60,
88,
2322,
60,
88,
2466,
60,
88,
2417,
60,
88,
2006,
60,
88,
1887,
60,
88,
20,
33,
60,
88,
20,
34,
60,
88,
20,
35,
60,
88,
20,
36,
60,
88,
20,
37,
60,
88,
20,
38,
7,
1467,
519,
1154,
88,
1400,
60,
88,
2869,
60,
88,
2528,
60,
88,
2481,
60,
88,
1477,
60,
88,
1229,
60,
88,
1367,
60,
88,
1641,
60,
88,
2010,
60,
88,
1427,
60,
88,
21,
33,
60,
88,
2976,
60,
88,
2789,
60,
88,
2766,
60,
88,
772,
60,
88,
2182,
7,
1467,
519,
1154,
88,
1272,
60,
88,
1822,
60,
88,
2333,
60,
88,
1876,
60,
88,
22,
33,
60,
88,
22,
34,
60,
88,
22,
35,
60,
88,
22,
36,
60,
88,
22,
37,
60,
88,
22,
38,
60,
88,
2760,
60,
88,
3172,
60,
88,
2819,
60,
88,
2898,
60,
88,
1342,
60,
88,
2194,
7,
1467,
519,
1154,
88,
2114,
60,
88,
1138,
60,
88,
2277,
60,
88,
1965,
60,
88,
23,
33,
60,
88,
1216,
60,
88,
2192,
60,
88,
708,
60,
88,
1153,
60,
88,
1082,
60,
88,
1276,
60,
88,
1344,
60,
88,
1401,
60,
88,
1703,
60,
88,
1355,
60,
88,
18,
34,
7,
1467,
519,
1154,
88,
18,
38,
60,
88,
19,
36,
401,
5151,
3212,
88,
2766,
60,
88,
2333,
60,
88,
2976,
60,
88,
2819,
60,
88,
2953,
60,
88,
1342,
2266,
60,
88,
1876,
60,
88,
22,
37,
60,
88,
772,
60,
88,
2182,
60,
88,
2277,
7,
1467,
519,
1154,
88,
20,
38,
60,
88,
1272,
2266,
60,
88,
1272,
60,
88,
2819,
60,
88,
22,
38,
60,
88,
22,
36,
60,
88,
2824,
60,
88,
2333,
60,
88,
2976,
60,
88,
2819,
60,
88,
2824,
60,
88,
22,
38,
60,
88,
772,
60,
88,
2182,
2266,
7,
1467,
519,
1154,
88,
22,
35,
60,
88,
2182,
60,
88,
22,
37,
60,
88,
1822,
60,
88,
1342,
60,
88,
2333,
937,
358,
199,
199,
318,
9696,
8,
1365,
304,
272,
408,
872,
28853,
4932,
47,
4361,
527,
1411,
14,
957,
1706,
281,
1041,
272,
372,
5056,
13214,
315,
1350,
199,
199,
318,
7787,
8,
1365,
304,
272,
408,
26472,
83,
8586,
1233,
13170,
543,
4932,
47,
4361,
527,
1411,
14,
957,
624,
272,
340,
440,
9696,
8,
1365,
304,
267,
372,
1350,
272,
4886,
275,
14342,
1547,
1541,
8,
1365,
430,
272,
1336,
275,
295,
14,
1733,
8,
82,
16136,
1391,
485,
3765,
60,
15829,
1579,
13661,
12432,
28,
19814,
1579,
3524,
401,
1993,
4886,
12,
295,
14,
16504,
9,
272,
1115,
1891,
379,
275,
1336,
14,
923,
8,
17,
9,
340,
1336,
587,
1350,
272,
372,
7240,
2524,
619,
435,
1115,
1891,
379,
199,
199,
318,
485,
1541,
8,
1365,
304,
272,
408,
12147,
83,
436,
4849,
4886,
334,
5043,
570,
9,
687,
658,
1365,
64,
624,
272,
862,
26,
267,
22071,
275,
295,
14,
1733,
8,
82,
7,
2579,
29323,
87,
7896,
2961,
87,
7896,
1332,
60,
87,
13439,
2862,
2862,
27853,
1350,
680,
923,
8,
17,
9,
267,
3837,
275,
295,
14,
1733,
8,
82,
2,
1391,
435,
5,
83,
30940,
29,
627,
6774,
2795,
3171,
9426,
450,
22071,
12,
1350,
680,
923,
8,
17,
9,
272,
871,
4281,
26,
267,
746,
31017,
316,
547,
360,
29513,
4932,
47,
4361,
527,
1411,
666,
2659,
272,
862,
26,
267,
372,
1300,
772,
14,
66,
772,
2708,
8,
4471,
14172,
17,
1055,
2143,
360,
1624,
24,
11103,
2708,
360,
1624,
24,
358,
272,
871,
3146,
26,
267,
746,
31017,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
lobiCode/VoterChat
|
models.py
|
1
|
5261
|
"""
Copyright 2014 VoterChat
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 datetime import datetime
from functools import wraps
from main import r
def flushdb():
"""
Prepare the database to store users.
"""
r.set("message_last_id", 0)
def exists(f):
"""
Raises an exception if the user does not exist.
"""
@wraps(f)
def wrapper(self, *args, **kwargs):
if not r.exists(self.key):
raise ValueError(
"Object %s does not exist in the database." % self.key
)
return f(self, *args, **kwargs)
return wrapper
def not_exists(f):
"""
Raises an exception if the user exists.
"""
@wraps(f)
def wrapper(self, *args, **kwargs):
if r.exists(self.key):
raise ValueError(
"Object %s already exists in the database." % self.key
)
return f(self, *args, **kwargs)
return wrapper
def new_id(obj_type):
return r.incr("%s_last_id" % obj_type)
class DBModel(object):
"""
Representation of a database object.
"""
def __init__(self, obj_type, obj_id):
"""
Creates a new object with the following data:
* obj_type - Object type
* obj_id - Object ID
The object will be located at "obj_type:obj_id"
after it is created. The key of the object can
be accessed using `obj.key`.
"""
self.type = obj_type
self.id = obj_id
self.key = "%s:%s" % (self.type, self.id)
self.created_at = None
@not_exists
def new(self):
"""
Creates a new object in the database.
"""
self.created_at = datetime.now()
for k, v in self.__dict__.iteritems():
self.set(k, v)
@exists
def delete(self):
"""
Delete the object in the database.
"""
r.delete(self.key)
@exists
def get(self):
"""
Returns user information.
"""
return r.hgetall(self.key)
def set(self, field, value):
"""
Sets object information given a field
and value.
"""
setattr(self, field, value)
r.hset(self.key, field, value)
@exists
def load(self):
"""
Load object information from the database.
"""
for k, v in self.get().iteritems():
setattr(self, k, v)
class Message(DBModel):
"""
Class representing a message.
"""
def __init__(self, msg_id, sender="", content="", stamp=datetime.now()):
"""
Creates a message given the following parameters:
* msg_id - ID of the message.
Parameters:
* sender - Username of the sender.
* content - Content of the message.
* stamp - Timestamp of the message.
Default is the current time.
"""
DBModel.__init__(self, "message", msg_id)
self.sender = sender
self.content = content
self.stamp = stamp
@exists
def delete(self):
DBModel.delete(self)
r.delete("%s:count" % self.key)
@exists
def send_users(self, users):
"""
Send a list of users the message.
"""
r.set("%s:count" % self.key, len(users))
for username in users:
user = User(username)
user.load()
user.send(self.id)
@exists
def recieved(self):
"""
Mark the message to be recieved by a user.
"""
val = r.decr("%s:count" % self.key)
if val == 0:
self.delete()
class User(DBModel):
"""
Class representing User object.
"""
def __init__(self, username, email="", phone_no=""):
"""
Creates a user given the following parameters:
* username - Username of the user.
Parameters:
* email - Email address of the user.
* phone_no - Phone number of the user.
"""
DBModel.__init__(self, "user", username)
self.email = email
self.phone_no = phone_no
@exists
def delete(self):
DBModel.delete(self)
r.delete("%s:queue" % self.key)
@exists
def poll(self):
"""
Pops messages from the user's queue.
"""
msg_lst = []
while True:
msg_id = r.lpop("%s:queue" % self.key)
if not msg_id:
break
msg = Message(msg_id)
msg.load()
msg_lst.append(msg.get())
msg.recieved()
return msg_lst
@exists
def send(self, msg_id):
"""
Add a message into the user's queue
given the ID of the message.
"""
r.rpush("%s:queue" % self.key, msg_id)
|
apache-2.0
|
[
624,
199,
7384,
6927,
32665,
351,
21954,
199,
199,
31661,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
13297,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
5556,
1443,
3332,
282,
1331,
402,
314,
844,
737,
8410,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
624,
199,
199,
504,
2197,
492,
2197,
199,
504,
9143,
492,
14018,
199,
199,
504,
2446,
492,
519,
199,
199,
318,
8976,
697,
837,
272,
408,
272,
17008,
314,
3050,
370,
3877,
4390,
14,
272,
408,
272,
519,
14,
409,
480,
1188,
63,
2019,
63,
344,
401,
378,
9,
258,
199,
199,
318,
3495,
8,
70,
304,
272,
408,
272,
6218,
376,
1919,
340,
314,
922,
1630,
440,
2187,
14,
272,
408,
272,
768,
13582,
8,
70,
9,
272,
347,
4975,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
519,
14,
2444,
8,
277,
14,
498,
304,
288,
746,
1722,
8,
355,
298,
1692,
450,
83,
1630,
440,
2187,
315,
314,
3050,
2122,
450,
291,
14,
498,
288,
776,
267,
372,
289,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
4975,
199,
199,
318,
440,
63,
2444,
8,
70,
304,
272,
408,
272,
6218,
376,
1919,
340,
314,
922,
3495,
14,
272,
408,
272,
768,
13582,
8,
70,
9,
272,
347,
4975,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
519,
14,
2444,
8,
277,
14,
498,
304,
288,
746,
1722,
8,
355,
298,
1692,
450,
83,
2575,
3495,
315,
314,
3050,
2122,
450,
291,
14,
498,
288,
776,
267,
372,
289,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
4975,
199,
199,
318,
892,
63,
344,
8,
1113,
63,
466,
304,
272,
372,
519,
14,
19362,
3647,
83,
63,
2019,
63,
344,
2,
450,
1559,
63,
466,
9,
421,
199,
533,
6249,
1685,
8,
785,
304,
272,
408,
272,
17634,
425,
402,
282,
3050,
909,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1559,
63,
466,
12,
1559,
63,
344,
304,
267,
408,
267,
10560,
282,
892,
909,
543,
314,
2569,
666,
26,
267,
627,
1559,
63,
466,
446,
6935,
730,
267,
627,
1559,
63,
344,
446,
6935,
2870,
398,
710,
909,
911,
506,
16180,
737,
298,
1113,
63,
466,
26,
1113,
63,
344,
2,
267,
2410,
652,
365,
2737,
14,
710,
790,
402,
314,
909,
883,
267,
506,
13810,
1808,
658,
1113,
14,
498,
2313,
267,
408,
267,
291,
14,
466,
275,
1559,
63,
466,
267,
291,
14,
344,
275,
1559,
63,
344,
267,
291,
14,
498,
275,
2071,
83,
2689,
83,
2,
450,
334,
277,
14,
466,
12,
291,
14,
344,
9,
398,
291,
14,
3966,
63,
292,
275,
488,
339,
768,
1397,
63,
2444,
272,
347,
892,
8,
277,
304,
267,
408,
267,
10560,
282,
892,
909,
315,
314,
3050,
14,
267,
408,
267,
291,
14,
3966,
63,
292,
275,
2197,
14,
2131,
342,
267,
367,
1022,
12,
373,
315,
291,
855,
807,
4343,
4611,
837,
288,
291,
14,
409,
8,
75,
12,
373,
9,
339,
768,
2444,
272,
347,
3145,
8,
277,
304,
267,
408,
267,
8496,
314,
909,
315,
314,
3050,
14,
267,
408,
267,
519,
14,
1807,
8,
277,
14,
498,
9,
339,
768,
2444,
272,
347,
664,
8,
277,
304,
267,
408,
267,
1803,
922,
2556,
14,
267,
408,
267,
372,
519,
14,
72,
362,
452,
8,
277,
14,
498,
9,
339,
347,
663,
8,
277,
12,
901,
12,
574,
304,
267,
408,
267,
10729,
909,
2556,
1627,
282,
901,
267,
436,
574,
14,
267,
408,
267,
5371,
8,
277,
12,
901,
12,
574,
9,
267,
519,
14,
72,
409,
8,
277,
14,
498,
12,
901,
12,
574,
9,
339,
768,
2444,
272,
347,
2248,
8,
277,
304,
267,
408,
267,
7190,
909,
2556,
687,
314,
3050,
14,
267,
408,
267,
367,
1022,
12,
373,
315,
291,
14,
362,
1252,
4611,
837,
288,
5371,
8,
277,
12,
1022,
12,
373,
9,
199,
199,
533,
6430,
8,
2846,
1685,
304,
272,
408,
272,
8089,
6144,
282,
1245,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1499,
63,
344,
12,
8904,
8772,
1564,
8772,
16206,
29,
2083,
14,
2131,
5109,
267,
408,
267,
10560,
282,
1245,
1627,
314,
2569,
2633,
26,
267,
627,
1499,
63,
344,
446,
2870,
402,
314,
1245,
14,
398,
3897,
26,
267,
627,
8904,
446,
29739,
402,
314,
8904,
14,
267,
627,
1564,
446,
6646,
402,
314,
1245,
14,
267,
627,
16206,
446,
18267,
402,
314,
1245,
14,
2116,
3758,
365,
314,
1453,
900,
14,
267,
408,
267,
6249,
1685,
855,
826,
721,
277,
12,
298,
1188,
401,
1499,
63,
344,
9,
267,
291,
14,
8114,
275,
8904,
267,
291,
14,
1317,
275,
1564,
267,
291,
14,
2359,
275,
16206,
339,
768,
2444,
272,
347,
3145,
8,
277,
304,
267,
6249,
1685,
14,
1807,
8,
277,
9,
267,
519,
14,
1807,
3647,
83,
26,
835,
2,
450,
291,
14,
498,
9,
339,
768,
2444,
272,
347,
3222,
63,
3707,
8,
277,
12,
4390,
304,
267,
408,
267,
10217,
282,
769,
402,
4390,
314,
1245,
14,
267,
408,
267,
519,
14,
409,
3647,
83,
26,
835,
2,
450,
291,
14,
498,
12,
822,
8,
3707,
430,
267,
367,
3434,
315,
4390,
26,
288,
922,
275,
2876,
8,
2473,
9,
288,
922,
14,
912,
342,
288,
922,
14,
2254,
8,
277,
14,
344,
9,
339,
768,
2444,
272,
347,
295,
559,
27986,
8,
277,
304,
267,
408,
267,
7173,
314,
1245,
370,
506,
295,
559,
27986,
701,
282,
922,
14,
267,
408,
267,
1139,
275,
519,
14,
271,
1556,
3647,
83,
26,
835,
2,
450,
291,
14,
498,
9,
267,
340,
1139,
508,
378,
26,
288,
291,
14,
1807,
342,
199,
199,
533
] |
[
199,
7384,
6927,
32665,
351,
21954,
199,
199,
31661,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
13297,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
5556,
1443,
3332,
282,
1331,
402,
314,
844,
737,
8410,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
199,
5524,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
16832,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
29946,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
9295,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3097,
1298,
1334,
314,
844,
14,
199,
624,
199,
199,
504,
2197,
492,
2197,
199,
504,
9143,
492,
14018,
199,
199,
504,
2446,
492,
519,
199,
199,
318,
8976,
697,
837,
272,
408,
272,
17008,
314,
3050,
370,
3877,
4390,
14,
272,
408,
272,
519,
14,
409,
480,
1188,
63,
2019,
63,
344,
401,
378,
9,
258,
199,
199,
318,
3495,
8,
70,
304,
272,
408,
272,
6218,
376,
1919,
340,
314,
922,
1630,
440,
2187,
14,
272,
408,
272,
768,
13582,
8,
70,
9,
272,
347,
4975,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
440,
519,
14,
2444,
8,
277,
14,
498,
304,
288,
746,
1722,
8,
355,
298,
1692,
450,
83,
1630,
440,
2187,
315,
314,
3050,
2122,
450,
291,
14,
498,
288,
776,
267,
372,
289,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
4975,
199,
199,
318,
440,
63,
2444,
8,
70,
304,
272,
408,
272,
6218,
376,
1919,
340,
314,
922,
3495,
14,
272,
408,
272,
768,
13582,
8,
70,
9,
272,
347,
4975,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
519,
14,
2444,
8,
277,
14,
498,
304,
288,
746,
1722,
8,
355,
298,
1692,
450,
83,
2575,
3495,
315,
314,
3050,
2122,
450,
291,
14,
498,
288,
776,
267,
372,
289,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
272,
372,
4975,
199,
199,
318,
892,
63,
344,
8,
1113,
63,
466,
304,
272,
372,
519,
14,
19362,
3647,
83,
63,
2019,
63,
344,
2,
450,
1559,
63,
466,
9,
421,
199,
533,
6249,
1685,
8,
785,
304,
272,
408,
272,
17634,
425,
402,
282,
3050,
909,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1559,
63,
466,
12,
1559,
63,
344,
304,
267,
408,
267,
10560,
282,
892,
909,
543,
314,
2569,
666,
26,
267,
627,
1559,
63,
466,
446,
6935,
730,
267,
627,
1559,
63,
344,
446,
6935,
2870,
398,
710,
909,
911,
506,
16180,
737,
298,
1113,
63,
466,
26,
1113,
63,
344,
2,
267,
2410,
652,
365,
2737,
14,
710,
790,
402,
314,
909,
883,
267,
506,
13810,
1808,
658,
1113,
14,
498,
2313,
267,
408,
267,
291,
14,
466,
275,
1559,
63,
466,
267,
291,
14,
344,
275,
1559,
63,
344,
267,
291,
14,
498,
275,
2071,
83,
2689,
83,
2,
450,
334,
277,
14,
466,
12,
291,
14,
344,
9,
398,
291,
14,
3966,
63,
292,
275,
488,
339,
768,
1397,
63,
2444,
272,
347,
892,
8,
277,
304,
267,
408,
267,
10560,
282,
892,
909,
315,
314,
3050,
14,
267,
408,
267,
291,
14,
3966,
63,
292,
275,
2197,
14,
2131,
342,
267,
367,
1022,
12,
373,
315,
291,
855,
807,
4343,
4611,
837,
288,
291,
14,
409,
8,
75,
12,
373,
9,
339,
768,
2444,
272,
347,
3145,
8,
277,
304,
267,
408,
267,
8496,
314,
909,
315,
314,
3050,
14,
267,
408,
267,
519,
14,
1807,
8,
277,
14,
498,
9,
339,
768,
2444,
272,
347,
664,
8,
277,
304,
267,
408,
267,
1803,
922,
2556,
14,
267,
408,
267,
372,
519,
14,
72,
362,
452,
8,
277,
14,
498,
9,
339,
347,
663,
8,
277,
12,
901,
12,
574,
304,
267,
408,
267,
10729,
909,
2556,
1627,
282,
901,
267,
436,
574,
14,
267,
408,
267,
5371,
8,
277,
12,
901,
12,
574,
9,
267,
519,
14,
72,
409,
8,
277,
14,
498,
12,
901,
12,
574,
9,
339,
768,
2444,
272,
347,
2248,
8,
277,
304,
267,
408,
267,
7190,
909,
2556,
687,
314,
3050,
14,
267,
408,
267,
367,
1022,
12,
373,
315,
291,
14,
362,
1252,
4611,
837,
288,
5371,
8,
277,
12,
1022,
12,
373,
9,
199,
199,
533,
6430,
8,
2846,
1685,
304,
272,
408,
272,
8089,
6144,
282,
1245,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
1499,
63,
344,
12,
8904,
8772,
1564,
8772,
16206,
29,
2083,
14,
2131,
5109,
267,
408,
267,
10560,
282,
1245,
1627,
314,
2569,
2633,
26,
267,
627,
1499,
63,
344,
446,
2870,
402,
314,
1245,
14,
398,
3897,
26,
267,
627,
8904,
446,
29739,
402,
314,
8904,
14,
267,
627,
1564,
446,
6646,
402,
314,
1245,
14,
267,
627,
16206,
446,
18267,
402,
314,
1245,
14,
2116,
3758,
365,
314,
1453,
900,
14,
267,
408,
267,
6249,
1685,
855,
826,
721,
277,
12,
298,
1188,
401,
1499,
63,
344,
9,
267,
291,
14,
8114,
275,
8904,
267,
291,
14,
1317,
275,
1564,
267,
291,
14,
2359,
275,
16206,
339,
768,
2444,
272,
347,
3145,
8,
277,
304,
267,
6249,
1685,
14,
1807,
8,
277,
9,
267,
519,
14,
1807,
3647,
83,
26,
835,
2,
450,
291,
14,
498,
9,
339,
768,
2444,
272,
347,
3222,
63,
3707,
8,
277,
12,
4390,
304,
267,
408,
267,
10217,
282,
769,
402,
4390,
314,
1245,
14,
267,
408,
267,
519,
14,
409,
3647,
83,
26,
835,
2,
450,
291,
14,
498,
12,
822,
8,
3707,
430,
267,
367,
3434,
315,
4390,
26,
288,
922,
275,
2876,
8,
2473,
9,
288,
922,
14,
912,
342,
288,
922,
14,
2254,
8,
277,
14,
344,
9,
339,
768,
2444,
272,
347,
295,
559,
27986,
8,
277,
304,
267,
408,
267,
7173,
314,
1245,
370,
506,
295,
559,
27986,
701,
282,
922,
14,
267,
408,
267,
1139,
275,
519,
14,
271,
1556,
3647,
83,
26,
835,
2,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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
] |
stormpath/stormpath-django
|
testproject/testproject/wsgi.py
|
3
|
1444
|
"""
WSGI config for django_stormpath project.
This module contains the WSGI application used by Django's development server
and any production WSGI deployments. It should expose a module-level variable
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
this application via the ``WSGI_APPLICATION`` setting.
Usually you will have the standard Django WSGI application here, but it also
might make sense to replace the whole Django WSGI application with a custom one
that later delegates to the Django one. For example, you could introduce WSGI
middleware here, or combine a Django application with an application of another
framework.
"""
import os
# We defer to a DJANGO_SETTINGS_MODULE already in the environment. This breaks
# if running multiple sites in the same mod_wsgi process. To fix this, use
# mod_wsgi daemon mode with each site in its own daemon process, or use
# os.environ["DJANGO_SETTINGS_MODULE"] = "django_stormpath.settings"
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
# This application object is used by any WSGI server configured to use this
# file. This includes Django's development server, if the WSGI_APPLICATION
# setting points here.
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
# Apply WSGI middleware here.
# from helloworld.wsgi import HelloWorldApplication
# application = HelloWorldApplication(application)
|
apache-2.0
|
[
624,
199,
16828,
1101,
367,
1639,
63,
8041,
8075,
2199,
14,
199,
199,
2765,
859,
3509,
314,
9279,
4223,
1202,
701,
5634,
1159,
16367,
1654,
199,
460,
1263,
9920,
9279,
12287,
1470,
14,
2779,
1077,
23705,
282,
859,
13,
1896,
1750,
199,
4579,
1124,
3578,
4345,
5634,
1159,
1124,
1065,
1000,
1040,
436,
1124,
1065,
30076,
1040,
3718,
20131,
199,
3749,
4223,
4799,
314,
1124,
16828,
63,
24051,
1040,
4260,
14,
199,
199,
23642,
3163,
1265,
911,
1172,
314,
4465,
5634,
9279,
4223,
2348,
12,
1325,
652,
2597,
199,
77,
1070,
1852,
12249,
370,
3350,
314,
8852,
5634,
9279,
4223,
543,
282,
3537,
1373,
199,
9099,
2945,
18703,
2335,
370,
314,
5634,
1373,
14,
2104,
2893,
12,
1265,
4293,
13318,
3402,
9279,
199,
5754,
2348,
12,
503,
13323,
282,
5634,
4223,
543,
376,
4223,
402,
4573,
199,
4857,
14,
199,
199,
624,
199,
646,
747,
199,
199,
3,
2136,
10133,
370,
282,
577,
42,
18822,
63,
13931,
63,
10001,
2575,
315,
314,
3734,
14,
961,
18277,
199,
3,
340,
3879,
3663,
15424,
315,
314,
2011,
3413,
63,
6508,
2112,
14,
4005,
5325,
642,
12,
675,
199,
3,
3413,
63,
6508,
11128,
818,
543,
1924,
4770,
315,
2399,
5705,
11128,
2112,
12,
503,
675,
199,
3,
747,
14,
2314,
905,
22848,
63,
13931,
63,
10001,
937,
275,
298,
1176,
63,
8041,
8075,
14,
1751,
2,
199,
736,
14,
2314,
14,
5486,
480,
22848,
63,
13931,
63,
10001,
401,
298,
396,
1715,
14,
1751,
531,
199,
199,
3,
961,
4223,
909,
365,
1202,
701,
1263,
9279,
1654,
7526,
370,
675,
642,
199,
3,
570,
14,
961,
6952,
5634,
1159,
16367,
1654,
12,
340,
314,
9279,
63,
24051,
199,
3,
4260,
4501,
2348,
14,
199,
504,
1639,
14,
1018,
14,
6508,
492,
664,
63,
6508,
63,
3578,
199,
3578,
275,
664,
63,
6508,
63,
3578,
342,
199,
199,
3,
14618,
9279,
10816,
2348,
14,
199,
3,
687,
16509,
7617,
14,
6508,
492,
23833,
15943,
5039,
199,
3,
4223,
275,
23833,
15943,
5039,
8,
3578,
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
] |
[
199,
16828,
1101,
367,
1639,
63,
8041,
8075,
2199,
14,
199,
199,
2765,
859,
3509,
314,
9279,
4223,
1202,
701,
5634,
1159,
16367,
1654,
199,
460,
1263,
9920,
9279,
12287,
1470,
14,
2779,
1077,
23705,
282,
859,
13,
1896,
1750,
199,
4579,
1124,
3578,
4345,
5634,
1159,
1124,
1065,
1000,
1040,
436,
1124,
1065,
30076,
1040,
3718,
20131,
199,
3749,
4223,
4799,
314,
1124,
16828,
63,
24051,
1040,
4260,
14,
199,
199,
23642,
3163,
1265,
911,
1172,
314,
4465,
5634,
9279,
4223,
2348,
12,
1325,
652,
2597,
199,
77,
1070,
1852,
12249,
370,
3350,
314,
8852,
5634,
9279,
4223,
543,
282,
3537,
1373,
199,
9099,
2945,
18703,
2335,
370,
314,
5634,
1373,
14,
2104,
2893,
12,
1265,
4293,
13318,
3402,
9279,
199,
5754,
2348,
12,
503,
13323,
282,
5634,
4223,
543,
376,
4223,
402,
4573,
199,
4857,
14,
199,
199,
624,
199,
646,
747,
199,
199,
3,
2136,
10133,
370,
282,
577,
42,
18822,
63,
13931,
63,
10001,
2575,
315,
314,
3734,
14,
961,
18277,
199,
3,
340,
3879,
3663,
15424,
315,
314,
2011,
3413,
63,
6508,
2112,
14,
4005,
5325,
642,
12,
675,
199,
3,
3413,
63,
6508,
11128,
818,
543,
1924,
4770,
315,
2399,
5705,
11128,
2112,
12,
503,
675,
199,
3,
747,
14,
2314,
905,
22848,
63,
13931,
63,
10001,
937,
275,
298,
1176,
63,
8041,
8075,
14,
1751,
2,
199,
736,
14,
2314,
14,
5486,
480,
22848,
63,
13931,
63,
10001,
401,
298,
396,
1715,
14,
1751,
531,
199,
199,
3,
961,
4223,
909,
365,
1202,
701,
1263,
9279,
1654,
7526,
370,
675,
642,
199,
3,
570,
14,
961,
6952,
5634,
1159,
16367,
1654,
12,
340,
314,
9279,
63,
24051,
199,
3,
4260,
4501,
2348,
14,
199,
504,
1639,
14,
1018,
14,
6508,
492,
664,
63,
6508,
63,
3578,
199,
3578,
275,
664,
63,
6508,
63,
3578,
342,
199,
199,
3,
14618,
9279,
10816,
2348,
14,
199,
3,
687,
16509,
7617,
14,
6508,
492,
23833,
15943,
5039,
199,
3,
4223,
275,
23833,
15943,
5039,
8,
3578,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
scalingdata/Impala
|
tests/query_test/test_insert.py
|
1
|
7872
|
#!/usr/bin/env python
# Copyright (c) 2012 Cloudera, Inc. All rights reserved.
# Targeted Impala insert tests
#
import logging
import os
import pytest
from testdata.common import widetable
from tests.beeswax.impala_beeswax import ImpalaBeeswaxException
from tests.common.test_vector import *
from tests.common.impala_test_suite import *
from tests.common.test_dimensions import create_exec_option_dimension
from tests.common.skip import SkipIfS3
# TODO: Add Gzip back. IMPALA-424
PARQUET_CODECS = ['none', 'snappy']
@SkipIfS3.insert
class TestInsertQueries(ImpalaTestSuite):
@classmethod
def get_workload(self):
return 'functional-query'
@classmethod
def add_test_dimensions(cls):
super(TestInsertQueries, cls).add_test_dimensions()
# Fix the exec_option vector to have a single value. This is needed should we decide
# to run the insert tests in parallel (otherwise there will be two tests inserting
# into the same table at the same time for the same file format).
# TODO: When we do decide to run these tests in parallel we could create unique temp
# tables for each test case to resolve the concurrency problems.
if cls.exploration_strategy() == 'core':
cls.TestMatrix.add_dimension(create_exec_option_dimension(
cluster_sizes=[0], disable_codegen_options=[False], batch_sizes=[0],
sync_ddl=[0]))
cls.TestMatrix.add_dimension(create_uncompressed_text_dimension(cls.get_workload()))
else:
cls.TestMatrix.add_dimension(create_exec_option_dimension(
cluster_sizes=[0], disable_codegen_options=[False], batch_sizes=[0],
sync_ddl=[0, 1]))
cls.TestMatrix.add_dimension(TestDimension("compression_codec", *PARQUET_CODECS));
# Insert is currently only supported for text and parquet
# For parquet, we want to iterate through all the compression codecs
# TODO: each column in parquet can have a different codec. We could
# test all the codecs in one table/file with some additional flags.
cls.TestMatrix.add_constraint(lambda v:\
v.get_value('table_format').file_format == 'parquet' or \
(v.get_value('table_format').file_format == 'text' and \
v.get_value('compression_codec') == 'none'))
cls.TestMatrix.add_constraint(lambda v:\
v.get_value('table_format').compression_codec == 'none')
@classmethod
def setup_class(cls):
super(TestInsertQueries, cls).setup_class()
@pytest.mark.execute_serially
def test_insert(self, vector):
if (vector.get_value('table_format').file_format == 'parquet'):
vector.get_value('exec_option')['COMPRESSION_CODEC'] = \
vector.get_value('compression_codec')
self.run_test_case('QueryTest/insert', vector,
multiple_impalad=vector.get_value('exec_option')['sync_ddl'] == 1)
@pytest.mark.execute_serially
def test_insert_overwrite(self, vector):
self.run_test_case('QueryTest/insert_overwrite', vector,
multiple_impalad=vector.get_value('exec_option')['sync_ddl'] == 1)
class TestInsertWideTable(ImpalaTestSuite):
@classmethod
def get_workload(self):
return 'functional-query'
@classmethod
def add_test_dimensions(cls):
super(TestInsertWideTable, cls).add_test_dimensions()
# Only vary codegen
cls.TestMatrix.add_dimension(create_exec_option_dimension(
cluster_sizes=[0], disable_codegen_options=[True, False], batch_sizes=[0]))
# Inserts only supported on text and parquet
# TODO: Enable 'text'/codec once the compressed text writers are in.
cls.TestMatrix.add_constraint(lambda v:\
v.get_value('table_format').file_format == 'parquet' or \
v.get_value('table_format').file_format == 'text')
cls.TestMatrix.add_constraint(lambda v:\
v.get_value('table_format').compression_codec == 'none')
# Don't run on core. This test is very slow (IMPALA-864) and we are unlikely to
# regress here.
if cls.exploration_strategy() == 'core':
cls.TestMatrix.add_constraint(lambda v: False);
def test_insert_wide_table(self, vector):
table_format = vector.get_value('table_format')
# Text can't handle as many columns as Parquet (codegen takes forever)
num_cols = 1000 if table_format.file_format == 'text' else 2000
db_name = QueryTestSectionReader.get_db_name(vector.get_value('table_format'))
table_name = db_name + ".insert_widetable"
if vector.get_value('exec_option')['disable_codegen']:
table_name += "_codegen_disabled"
self.client.execute("drop table if exists " + table_name)
col_descs = widetable.get_columns(num_cols)
create_stmt = "CREATE TABLE " + table_name + "(" + ','.join(col_descs) + ")"
if vector.get_value('table_format').file_format == 'parquet':
create_stmt += " stored as parquet"
self.client.execute(create_stmt)
# Get a single row of data
col_vals = widetable.get_data(num_cols, 1, quote_strings=True)[0]
insert_stmt = "INSERT INTO " + table_name + " VALUES(" + col_vals + ")"
self.client.execute(insert_stmt)
result = self.client.execute("select count(*) from " + table_name)
assert result.data == ["1"]
result = self.client.execute("select * from " + table_name)
types = parse_column_types(result.schema)
labels = parse_column_labels(result.schema)
expected = QueryTestResult([col_vals], types, labels, order_matters=False)
actual = QueryTestResult(parse_result_rows(result), types, labels, order_matters=False)
assert expected == actual
@SkipIfS3.insert
class TestInsertPartKey(ImpalaTestSuite):
"""Regression test for IMPALA-875"""
@classmethod
def get_workload(self):
return 'functional-query'
@classmethod
def add_test_dimensions(cls):
super(TestInsertPartKey, cls).add_test_dimensions()
# Only run for a single table type
cls.TestMatrix.add_dimension(create_exec_option_dimension(
cluster_sizes=[0], disable_codegen_options=[False], batch_sizes=[0],
sync_ddl=[1]))
cls.TestMatrix.add_constraint(lambda v:
(v.get_value('table_format').file_format == 'text'))
cls.TestMatrix.add_constraint(lambda v:\
v.get_value('table_format').compression_codec == 'none')
@pytest.mark.execute_serially
def test_insert_part_key(self, vector):
"""Test that partition column exprs are cast to the correct type. See IMPALA-875."""
self.run_test_case('QueryTest/insert_part_key', vector,
multiple_impalad=vector.get_value('exec_option')['sync_ddl'] == 1)
@SkipIfS3.insert
class TestInsertNullQueries(ImpalaTestSuite):
@classmethod
def get_workload(self):
return 'functional-query'
@classmethod
def add_test_dimensions(cls):
super(TestInsertNullQueries, cls).add_test_dimensions()
# Fix the exec_option vector to have a single value. This is needed should we decide
# to run the insert tests in parallel (otherwise there will be two tests inserting
# into the same table at the same time for the same file format).
# TODO: When we do decide to run these tests in parallel we could create unique temp
# tables for each test case to resolve the concurrency problems.
cls.TestMatrix.add_dimension(create_exec_option_dimension(
cluster_sizes=[0], disable_codegen_options=[False], batch_sizes=[0]))
# These tests only make sense for inserting into a text table with special
# logic to handle all the possible ways NULL needs to be written as ascii
cls.TestMatrix.add_constraint(lambda v:\
(v.get_value('table_format').file_format == 'text' and \
v.get_value('table_format').compression_codec == 'none'))
@classmethod
def setup_class(cls):
super(TestInsertNullQueries, cls).setup_class()
@pytest.mark.execute_serially
def test_insert_null(self, vector):
self.run_test_case('QueryTest/insert_null', vector)
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
5980,
3786,
345,
12,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
377,
20174,
8362,
14774,
5518,
2295,
199,
3,
199,
646,
2050,
199,
646,
747,
199,
646,
4613,
199,
504,
511,
576,
14,
2330,
492,
20239,
1224,
199,
504,
2295,
14,
1235,
397,
758,
88,
14,
3236,
14774,
63,
1235,
397,
758,
88,
492,
8362,
14774,
3655,
397,
758,
88,
1726,
199,
504,
2295,
14,
2330,
14,
396,
63,
4106,
492,
627,
199,
504,
2295,
14,
2330,
14,
3236,
14774,
63,
396,
63,
5768,
492,
627,
199,
504,
2295,
14,
2330,
14,
396,
63,
13320,
492,
1218,
63,
1628,
63,
1422,
63,
7430,
199,
504,
2295,
14,
2330,
14,
2759,
492,
8232,
3917,
51,
19,
199,
199,
3,
3254,
26,
2654,
598,
3065,
1771,
14,
221,
5025,
26674,
13,
21089,
199,
4014,
2328,
775,
63,
6012,
3298,
275,
788,
3592,
297,
283,
5167,
18869,
418,
199,
199,
32,
7738,
3917,
51,
19,
14,
3176,
199,
533,
1379,
9971,
13611,
8,
8499,
14774,
10591,
304,
523,
768,
3744,
523,
347,
664,
63,
800,
912,
8,
277,
304,
272,
372,
283,
15481,
13,
1131,
7,
819,
768,
3744,
523,
347,
1050,
63,
396,
63,
13320,
8,
1886,
304,
272,
1613,
8,
774,
9971,
13611,
12,
843,
680,
525,
63,
396,
63,
13320,
342,
272,
327,
14811,
314,
2146,
63,
1422,
5477,
370,
1172,
282,
2849,
574,
14,
961,
365,
4346,
1077,
781,
19822,
272,
327,
370,
1255,
314,
5518,
2295,
315,
9861,
334,
26617,
2337,
911,
506,
2877,
2295,
28498,
272,
327,
1901,
314,
2011,
1817,
737,
314,
2011,
900,
367,
314,
2011,
570,
1475,
680,
272,
327,
3254,
26,
3979,
781,
886,
19822,
370,
1255,
3520,
2295,
315,
9861,
781,
4293,
1218,
3747,
2388,
272,
327,
6716,
367,
1924,
511,
1930,
370,
7512,
314,
406,
4968,
8826,
14,
272,
340,
843,
14,
29028,
63,
8590,
342,
508,
283,
1018,
356,
489,
843,
14,
774,
6443,
14,
525,
63,
7430,
8,
981,
63,
1628,
63,
1422,
63,
7430,
8,
881,
4350,
63,
7723,
1524,
16,
467,
3507,
63,
600,
2268,
63,
1419,
1524,
797,
467,
3522,
63,
7723,
1524,
16,
467,
881,
7604,
63,
17102,
1524,
16,
2459,
489,
843,
14,
774,
6443,
14,
525,
63,
7430,
8,
981,
63,
324,
10895,
63,
505,
63,
7430,
8,
1886,
14,
362,
63,
800,
912,
4059,
272,
587,
26,
489,
843,
14,
774,
6443,
14,
525,
63,
7430,
8,
981,
63,
1628,
63,
1422,
63,
7430,
8,
881,
4350,
63,
7723,
1524,
16,
467,
3507,
63,
600,
2268,
63,
1419,
1524,
797,
467,
3522,
63,
7723,
1524,
16,
467,
881,
7604,
63,
17102,
1524,
16,
12,
413,
2459,
489,
843,
14,
774,
6443,
14,
525,
63,
7430,
8,
774,
17905,
480,
12849,
63,
9276,
401,
627,
4014,
2328,
775,
63,
6012,
3298,
16674,
489,
327,
15496,
365,
5544,
1454,
3748,
367,
1318,
436,
623,
17917,
489,
327,
2104,
623,
17917,
12,
781,
2934,
370,
13974,
4012,
1006,
314,
10291,
6010,
489,
327,
3254,
26,
1924,
2763,
315,
623,
17917,
883,
1172,
282,
3365,
9076,
14,
221,
2136,
4293,
489,
327,
511,
1006,
314,
6010,
315,
1373,
1817,
15,
493,
543,
2005,
4722,
3285,
14,
489,
843,
14,
774,
6443,
14,
525,
63,
5631,
8,
2734,
373,
3427,
881,
373,
14,
362,
63,
585,
360,
1224,
63,
908,
1959,
493,
63,
908,
508,
283,
462,
17917,
7,
503,
971,
288,
334,
86,
14,
362,
63,
585,
360,
1224,
63,
908,
1959,
493,
63,
908,
508,
283,
505,
7,
436,
971,
288,
373,
14,
362,
63,
585,
360,
12849,
63,
9276,
358,
508,
283,
3592,
1333,
489,
843,
14,
774,
6443,
14,
525,
63,
5631,
8,
2734,
373,
3427,
881,
373,
14,
362,
63,
585,
360,
1224,
63,
908,
1959,
12849,
63,
9276,
508,
283,
3592,
358,
819,
768,
3744,
523,
347,
3272,
63,
533,
8,
1886,
304,
272,
1613,
8,
774,
9971,
13611,
12,
843,
680,
2758,
63,
533,
342,
819,
768,
4462,
14,
1657,
14,
2526,
63,
261,
322,
1183,
523,
347,
511,
63,
3176,
8,
277,
12,
5477,
304,
272,
340,
334,
4106,
14,
362,
63,
585,
360,
1224,
63,
908,
1959,
493,
63,
908,
508,
283,
462,
17917,
735,
489,
5477,
14,
362,
63,
585,
360,
1628,
63,
1422,
24211,
30193,
63,
6012,
35,
418,
275,
971,
881,
5477,
14,
362,
63,
585,
360,
12849,
63,
9276,
358,
272,
291,
14,
1065,
63,
396,
63,
2546,
360,
3227,
774,
15,
3176,
297,
5477,
12,
267,
3663,
63,
3236,
279,
350,
29,
4106,
14,
362,
63,
585,
360,
1628,
63,
1422,
24211,
5186,
63,
17102,
418,
508,
413,
9,
819,
768,
4462,
14,
1657,
14,
2526,
63,
261,
322,
1183,
523,
347,
511,
63,
3176,
63,
14658,
8,
277,
12,
5477,
304,
272,
291,
14,
1065,
63,
396,
63,
2546,
360,
3227,
774,
15,
3176,
63,
14658,
297,
5477,
12,
267,
3663,
63,
3236,
279,
350,
29,
4106,
14,
362,
63,
585,
360,
1628,
63,
1422,
24211,
5186,
63,
17102,
418,
508,
413,
9,
199,
199,
533,
1379,
9971,
55,
2655,
3186,
8,
8499,
14774,
10591,
304,
523,
768,
3744,
523,
347,
664,
63,
800,
912,
8,
277,
304,
272,
372,
283,
15481,
13,
1131,
7,
819,
768,
3744,
523,
347,
1050,
63,
396,
63,
13320,
8,
1886,
304,
272,
1613,
8,
774,
9971,
55,
2655,
3186,
12,
843,
680,
525,
63,
396,
63,
13320,
342,
339,
327,
5972,
17083,
1233,
2268,
272,
843,
14,
774,
6443,
14,
525,
63,
7430,
8,
981,
63,
1628,
63,
1422,
63,
7430,
8,
267,
4350,
63,
7723,
1524,
16,
467,
3507,
63,
600,
2268,
63,
1419,
1524,
549,
12,
756,
467,
3522,
63,
7723,
1524,
16,
2459,
339,
327,
15496,
83,
1454,
3748,
641,
1318,
436,
623,
17917,
272,
327,
3254,
26,
12030,
283,
505,
9807,
9276,
5403,
314,
12335,
1318,
2211,
878,
787,
315,
14,
272,
843,
14,
774,
6443,
14,
525,
63,
5631,
8,
2734,
373,
3427,
267,
373,
14,
362,
63,
585,
360,
1224,
63,
908,
1959,
493,
63,
908,
508,
283,
462,
17917,
7,
503,
971,
267,
373,
14,
362,
63,
585,
360,
1224,
63,
908,
1959,
493,
63,
908,
508
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6029,
5980,
3786,
345,
12,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
377,
20174,
8362,
14774,
5518,
2295,
199,
3,
199,
646,
2050,
199,
646,
747,
199,
646,
4613,
199,
504,
511,
576,
14,
2330,
492,
20239,
1224,
199,
504,
2295,
14,
1235,
397,
758,
88,
14,
3236,
14774,
63,
1235,
397,
758,
88,
492,
8362,
14774,
3655,
397,
758,
88,
1726,
199,
504,
2295,
14,
2330,
14,
396,
63,
4106,
492,
627,
199,
504,
2295,
14,
2330,
14,
3236,
14774,
63,
396,
63,
5768,
492,
627,
199,
504,
2295,
14,
2330,
14,
396,
63,
13320,
492,
1218,
63,
1628,
63,
1422,
63,
7430,
199,
504,
2295,
14,
2330,
14,
2759,
492,
8232,
3917,
51,
19,
199,
199,
3,
3254,
26,
2654,
598,
3065,
1771,
14,
221,
5025,
26674,
13,
21089,
199,
4014,
2328,
775,
63,
6012,
3298,
275,
788,
3592,
297,
283,
5167,
18869,
418,
199,
199,
32,
7738,
3917,
51,
19,
14,
3176,
199,
533,
1379,
9971,
13611,
8,
8499,
14774,
10591,
304,
523,
768,
3744,
523,
347,
664,
63,
800,
912,
8,
277,
304,
272,
372,
283,
15481,
13,
1131,
7,
819,
768,
3744,
523,
347,
1050,
63,
396,
63,
13320,
8,
1886,
304,
272,
1613,
8,
774,
9971,
13611,
12,
843,
680,
525,
63,
396,
63,
13320,
342,
272,
327,
14811,
314,
2146,
63,
1422,
5477,
370,
1172,
282,
2849,
574,
14,
961,
365,
4346,
1077,
781,
19822,
272,
327,
370,
1255,
314,
5518,
2295,
315,
9861,
334,
26617,
2337,
911,
506,
2877,
2295,
28498,
272,
327,
1901,
314,
2011,
1817,
737,
314,
2011,
900,
367,
314,
2011,
570,
1475,
680,
272,
327,
3254,
26,
3979,
781,
886,
19822,
370,
1255,
3520,
2295,
315,
9861,
781,
4293,
1218,
3747,
2388,
272,
327,
6716,
367,
1924,
511,
1930,
370,
7512,
314,
406,
4968,
8826,
14,
272,
340,
843,
14,
29028,
63,
8590,
342,
508,
283,
1018,
356,
489,
843,
14,
774,
6443,
14,
525,
63,
7430,
8,
981,
63,
1628,
63,
1422,
63,
7430,
8,
881,
4350,
63,
7723,
1524,
16,
467,
3507,
63,
600,
2268,
63,
1419,
1524,
797,
467,
3522,
63,
7723,
1524,
16,
467,
881,
7604,
63,
17102,
1524,
16,
2459,
489,
843,
14,
774,
6443,
14,
525,
63,
7430,
8,
981,
63,
324,
10895,
63,
505,
63,
7430,
8,
1886,
14,
362,
63,
800,
912,
4059,
272,
587,
26,
489,
843,
14,
774,
6443,
14,
525,
63,
7430,
8,
981,
63,
1628,
63,
1422,
63,
7430,
8,
881,
4350,
63,
7723,
1524,
16,
467,
3507,
63,
600,
2268,
63,
1419,
1524,
797,
467,
3522,
63,
7723,
1524,
16,
467,
881,
7604,
63,
17102,
1524,
16,
12,
413,
2459,
489,
843,
14,
774,
6443,
14,
525,
63,
7430,
8,
774,
17905,
480,
12849,
63,
9276,
401,
627,
4014,
2328,
775,
63,
6012,
3298,
16674,
489,
327,
15496,
365,
5544,
1454,
3748,
367,
1318,
436,
623,
17917,
489,
327,
2104,
623,
17917,
12,
781,
2934,
370,
13974,
4012,
1006,
314,
10291,
6010,
489,
327,
3254,
26,
1924,
2763,
315,
623,
17917,
883,
1172,
282,
3365,
9076,
14,
221,
2136,
4293,
489,
327,
511,
1006,
314,
6010,
315,
1373,
1817,
15,
493,
543,
2005,
4722,
3285,
14,
489,
843,
14,
774,
6443,
14,
525,
63,
5631,
8,
2734,
373,
3427,
881,
373,
14,
362,
63,
585,
360,
1224,
63,
908,
1959,
493,
63,
908,
508,
283,
462,
17917,
7,
503,
971,
288,
334,
86,
14,
362,
63,
585,
360,
1224,
63,
908,
1959,
493,
63,
908,
508,
283,
505,
7,
436,
971,
288,
373,
14,
362,
63,
585,
360,
12849,
63,
9276,
358,
508,
283,
3592,
1333,
489,
843,
14,
774,
6443,
14,
525,
63,
5631,
8,
2734,
373,
3427,
881,
373,
14,
362,
63,
585,
360,
1224,
63,
908,
1959,
12849,
63,
9276,
508,
283,
3592,
358,
819,
768,
3744,
523,
347,
3272,
63,
533,
8,
1886,
304,
272,
1613,
8,
774,
9971,
13611,
12,
843,
680,
2758,
63,
533,
342,
819,
768,
4462,
14,
1657,
14,
2526,
63,
261,
322,
1183,
523,
347,
511,
63,
3176,
8,
277,
12,
5477,
304,
272,
340,
334,
4106,
14,
362,
63,
585,
360,
1224,
63,
908,
1959,
493,
63,
908,
508,
283,
462,
17917,
735,
489,
5477,
14,
362,
63,
585,
360,
1628,
63,
1422,
24211,
30193,
63,
6012,
35,
418,
275,
971,
881,
5477,
14,
362,
63,
585,
360,
12849,
63,
9276,
358,
272,
291,
14,
1065,
63,
396,
63,
2546,
360,
3227,
774,
15,
3176,
297,
5477,
12,
267,
3663,
63,
3236,
279,
350,
29,
4106,
14,
362,
63,
585,
360,
1628,
63,
1422,
24211,
5186,
63,
17102,
418,
508,
413,
9,
819,
768,
4462,
14,
1657,
14,
2526,
63,
261,
322,
1183,
523,
347,
511,
63,
3176,
63,
14658,
8,
277,
12,
5477,
304,
272,
291,
14,
1065,
63,
396,
63,
2546,
360,
3227,
774,
15,
3176,
63,
14658,
297,
5477,
12,
267,
3663,
63,
3236,
279,
350,
29,
4106,
14,
362,
63,
585,
360,
1628,
63,
1422,
24211,
5186,
63,
17102,
418,
508,
413,
9,
199,
199,
533,
1379,
9971,
55,
2655,
3186,
8,
8499,
14774,
10591,
304,
523,
768,
3744,
523,
347,
664,
63,
800,
912,
8,
277,
304,
272,
372,
283,
15481,
13,
1131,
7,
819,
768,
3744,
523,
347,
1050,
63,
396,
63,
13320,
8,
1886,
304,
272,
1613,
8,
774,
9971,
55,
2655,
3186,
12,
843,
680,
525,
63,
396,
63,
13320,
342,
339,
327,
5972,
17083,
1233,
2268,
272,
843,
14,
774,
6443,
14,
525,
63,
7430,
8,
981,
63,
1628,
63,
1422,
63,
7430,
8,
267,
4350,
63,
7723,
1524,
16,
467,
3507,
63,
600,
2268,
63,
1419,
1524,
549,
12,
756,
467,
3522,
63,
7723,
1524,
16,
2459,
339,
327,
15496,
83,
1454,
3748,
641,
1318,
436,
623,
17917,
272,
327,
3254,
26,
12030,
283,
505,
9807,
9276,
5403,
314,
12335,
1318,
2211,
878,
787,
315,
14,
272,
843,
14,
774,
6443,
14,
525,
63,
5631,
8,
2734,
373,
3427,
267,
373,
14,
362,
63,
585,
360,
1224,
63,
908,
1959,
493,
63,
908,
508,
283,
462,
17917,
7,
503,
971,
267,
373,
14,
362,
63,
585,
360,
1224,
63,
908,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1,
1,
1,
1,
1,
1,
1,
1
] |
unindented/streamcode
|
client/static/jsrepl/extern/python/closured/lib/python2.7/lib2to3/pgen2/conv.py
|
325
|
9627
|
# Copyright 2004-2005 Elemental Security, Inc. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Convert graminit.[ch] spit out by pgen to Python code.
Pgen is the Python parser generator. It is useful to quickly create a
parser from a grammar file in Python's grammar notation. But I don't
want my parsers to be written in C (yet), so I'm translating the
parsing tables to Python data structures and writing a Python parse
engine.
Note that the token numbers are constants determined by the standard
Python tokenizer. The standard token module defines these numbers and
their names (the names are not used much). The token numbers are
hardcoded into the Python tokenizer and into pgen. A Python
implementation of the Python tokenizer is also available, in the
standard tokenize module.
On the other hand, symbol numbers (representing the grammar's
non-terminals) are assigned by pgen based on the actual grammar
input.
Note: this module is pretty much obsolete; the pgen module generates
equivalent grammar tables directly from the Grammar.txt input file
without having to invoke the Python pgen C program.
"""
# Python imports
import re
# Local imports
from pgen2 import grammar, token
class Converter(grammar.Grammar):
"""Grammar subclass that reads classic pgen output files.
The run() method reads the tables as produced by the pgen parser
generator, typically contained in two C files, graminit.h and
graminit.c. The other methods are for internal use only.
See the base class for more documentation.
"""
def run(self, graminit_h, graminit_c):
"""Load the grammar tables from the text files written by pgen."""
self.parse_graminit_h(graminit_h)
self.parse_graminit_c(graminit_c)
self.finish_off()
def parse_graminit_h(self, filename):
"""Parse the .h file written by pgen. (Internal)
This file is a sequence of #define statements defining the
nonterminals of the grammar as numbers. We build two tables
mapping the numbers to names and back.
"""
try:
f = open(filename)
except IOError, err:
print "Can't open %s: %s" % (filename, err)
return False
self.symbol2number = {}
self.number2symbol = {}
lineno = 0
for line in f:
lineno += 1
mo = re.match(r"^#define\s+(\w+)\s+(\d+)$", line)
if not mo and line.strip():
print "%s(%s): can't parse %s" % (filename, lineno,
line.strip())
else:
symbol, number = mo.groups()
number = int(number)
assert symbol not in self.symbol2number
assert number not in self.number2symbol
self.symbol2number[symbol] = number
self.number2symbol[number] = symbol
return True
def parse_graminit_c(self, filename):
"""Parse the .c file written by pgen. (Internal)
The file looks as follows. The first two lines are always this:
#include "pgenheaders.h"
#include "grammar.h"
After that come four blocks:
1) one or more state definitions
2) a table defining dfas
3) a table defining labels
4) a struct defining the grammar
A state definition has the following form:
- one or more arc arrays, each of the form:
static arc arcs_<n>_<m>[<k>] = {
{<i>, <j>},
...
};
- followed by a state array, of the form:
static state states_<s>[<t>] = {
{<k>, arcs_<n>_<m>},
...
};
"""
try:
f = open(filename)
except IOError, err:
print "Can't open %s: %s" % (filename, err)
return False
# The code below essentially uses f's iterator-ness!
lineno = 0
# Expect the two #include lines
lineno, line = lineno+1, f.next()
assert line == '#include "pgenheaders.h"\n', (lineno, line)
lineno, line = lineno+1, f.next()
assert line == '#include "grammar.h"\n', (lineno, line)
# Parse the state definitions
lineno, line = lineno+1, f.next()
allarcs = {}
states = []
while line.startswith("static arc "):
while line.startswith("static arc "):
mo = re.match(r"static arc arcs_(\d+)_(\d+)\[(\d+)\] = {$",
line)
assert mo, (lineno, line)
n, m, k = map(int, mo.groups())
arcs = []
for _ in range(k):
lineno, line = lineno+1, f.next()
mo = re.match(r"\s+{(\d+), (\d+)},$", line)
assert mo, (lineno, line)
i, j = map(int, mo.groups())
arcs.append((i, j))
lineno, line = lineno+1, f.next()
assert line == "};\n", (lineno, line)
allarcs[(n, m)] = arcs
lineno, line = lineno+1, f.next()
mo = re.match(r"static state states_(\d+)\[(\d+)\] = {$", line)
assert mo, (lineno, line)
s, t = map(int, mo.groups())
assert s == len(states), (lineno, line)
state = []
for _ in range(t):
lineno, line = lineno+1, f.next()
mo = re.match(r"\s+{(\d+), arcs_(\d+)_(\d+)},$", line)
assert mo, (lineno, line)
k, n, m = map(int, mo.groups())
arcs = allarcs[n, m]
assert k == len(arcs), (lineno, line)
state.append(arcs)
states.append(state)
lineno, line = lineno+1, f.next()
assert line == "};\n", (lineno, line)
lineno, line = lineno+1, f.next()
self.states = states
# Parse the dfas
dfas = {}
mo = re.match(r"static dfa dfas\[(\d+)\] = {$", line)
assert mo, (lineno, line)
ndfas = int(mo.group(1))
for i in range(ndfas):
lineno, line = lineno+1, f.next()
mo = re.match(r'\s+{(\d+), "(\w+)", (\d+), (\d+), states_(\d+),$',
line)
assert mo, (lineno, line)
symbol = mo.group(2)
number, x, y, z = map(int, mo.group(1, 3, 4, 5))
assert self.symbol2number[symbol] == number, (lineno, line)
assert self.number2symbol[number] == symbol, (lineno, line)
assert x == 0, (lineno, line)
state = states[z]
assert y == len(state), (lineno, line)
lineno, line = lineno+1, f.next()
mo = re.match(r'\s+("(?:\\\d\d\d)*")},$', line)
assert mo, (lineno, line)
first = {}
rawbitset = eval(mo.group(1))
for i, c in enumerate(rawbitset):
byte = ord(c)
for j in range(8):
if byte & (1<<j):
first[i*8 + j] = 1
dfas[number] = (state, first)
lineno, line = lineno+1, f.next()
assert line == "};\n", (lineno, line)
self.dfas = dfas
# Parse the labels
labels = []
lineno, line = lineno+1, f.next()
mo = re.match(r"static label labels\[(\d+)\] = {$", line)
assert mo, (lineno, line)
nlabels = int(mo.group(1))
for i in range(nlabels):
lineno, line = lineno+1, f.next()
mo = re.match(r'\s+{(\d+), (0|"\w+")},$', line)
assert mo, (lineno, line)
x, y = mo.groups()
x = int(x)
if y == "0":
y = None
else:
y = eval(y)
labels.append((x, y))
lineno, line = lineno+1, f.next()
assert line == "};\n", (lineno, line)
self.labels = labels
# Parse the grammar struct
lineno, line = lineno+1, f.next()
assert line == "grammar _PyParser_Grammar = {\n", (lineno, line)
lineno, line = lineno+1, f.next()
mo = re.match(r"\s+(\d+),$", line)
assert mo, (lineno, line)
ndfas = int(mo.group(1))
assert ndfas == len(self.dfas)
lineno, line = lineno+1, f.next()
assert line == "\tdfas,\n", (lineno, line)
lineno, line = lineno+1, f.next()
mo = re.match(r"\s+{(\d+), labels},$", line)
assert mo, (lineno, line)
nlabels = int(mo.group(1))
assert nlabels == len(self.labels), (lineno, line)
lineno, line = lineno+1, f.next()
mo = re.match(r"\s+(\d+)$", line)
assert mo, (lineno, line)
start = int(mo.group(1))
assert start in self.number2symbol, (lineno, line)
self.start = start
lineno, line = lineno+1, f.next()
assert line == "};\n", (lineno, line)
try:
lineno, line = lineno+1, f.next()
except StopIteration:
pass
else:
assert 0, (lineno, line)
def finish_off(self):
"""Create additional useful structures. (Internal)."""
self.keywords = {} # map from keyword strings to arc labels
self.tokens = {} # map from numeric token values to arc labels
for ilabel, (type, value) in enumerate(self.labels):
if type == token.NAME and value is not None:
self.keywords[value] = ilabel
elif value is None:
self.tokens[type] = ilabel
|
mit
|
[
3,
1898,
8353,
13,
9397,
6566,
279,
13863,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
7306,
1999,
77,
826,
24097,
335,
61,
2249,
390,
734,
701,
299,
2268,
370,
2018,
1233,
14,
199,
199,
48,
2268,
365,
314,
2018,
1798,
4306,
14,
221,
2779,
365,
2997,
370,
23661,
1218,
282,
199,
2087,
687,
282,
12528,
570,
315,
2018,
1159,
12528,
15843,
14,
221,
11017,
473,
2793,
1133,
199,
7051,
3002,
21295,
370,
506,
5313,
315,
445,
334,
28064,
395,
880,
473,
6704,
1752,
24615,
314,
199,
11059,
6716,
370,
2018,
666,
13955,
436,
3575,
282,
2018,
2198,
199,
3908,
14,
199,
199,
7443,
626,
314,
1526,
5579,
787,
5262,
12037,
701,
314,
4465,
199,
4718,
14803,
14,
221,
710,
4465,
1526,
859,
7890,
3520,
5579,
436,
199,
1589,
723,
1561,
334,
1589,
1561,
787,
440,
1202,
8298,
680,
221,
710,
1526,
5579,
787,
199,
8726,
15282,
1901,
314,
2018,
14803,
436,
1901,
299,
2268,
14,
221,
437,
2018,
199,
12236,
402,
314,
2018,
14803,
365,
2597,
2808,
12,
315,
314,
199,
6807,
13343,
859,
14,
199,
199,
3314,
314,
1163,
4926,
12,
5272,
5579,
334,
13063,
316,
314,
12528,
1159,
199,
2865,
13,
24322,
9,
787,
7943,
701,
299,
2268,
4079,
641,
314,
3503,
12528,
199,
1210,
14,
199,
199,
7443,
26,
642,
859,
365,
7268,
8298,
24985,
27,
314,
299,
2268,
859,
12821,
199,
24179,
12528,
6716,
5370,
687,
314,
10268,
9992,
14,
2424,
1324,
570,
199,
7395,
9445,
370,
12677,
314,
2018,
299,
2268,
445,
2240,
14,
199,
199,
624,
199,
199,
3,
2018,
8925,
199,
646,
295,
199,
199,
3,
10111,
8925,
199,
504,
299,
2268,
18,
492,
12528,
12,
1526,
421,
199,
533,
11801,
351,
8,
15239,
14,
27119,
304,
272,
408,
27119,
5516,
626,
11597,
31205,
299,
2268,
1072,
1584,
14,
339,
710,
1255,
342,
1083,
11597,
314,
6716,
465,
13584,
701,
314,
299,
2268,
1798,
272,
4306,
12,
13609,
10470,
315,
2877,
445,
1584,
12,
1999,
77,
826,
14,
72,
436,
272,
1999,
77,
826,
14,
67,
14,
221,
710,
1163,
3102,
787,
367,
5007,
675,
1454,
14,
339,
1666,
314,
1300,
1021,
367,
1655,
3794,
14,
339,
408,
339,
347,
1255,
8,
277,
12,
1999,
77,
826,
63,
72,
12,
1999,
77,
826,
63,
67,
304,
267,
408,
6200,
314,
12528,
6716,
687,
314,
1318,
1584,
5313,
701,
299,
2268,
1041,
267,
291,
14,
1122,
63,
1679,
826,
63,
72,
8,
1679,
826,
63,
72,
9,
267,
291,
14,
1122,
63,
1679,
826,
63,
67,
8,
1679,
826,
63,
67,
9,
267,
291,
14,
8192,
63,
1997,
342,
339,
347,
2198,
63,
1679,
826,
63,
72,
8,
277,
12,
1788,
304,
267,
408,
4003,
314,
1275,
72,
570,
5313,
701,
299,
2268,
14,
221,
334,
8405,
9,
398,
961,
570,
365,
282,
3414,
402,
327,
4640,
9834,
12669,
314,
267,
2222,
24322,
402,
314,
12528,
465,
5579,
14,
221,
2136,
1900,
2877,
6716,
267,
4412,
314,
5579,
370,
1561,
436,
1771,
14,
398,
408,
267,
862,
26,
288,
289,
275,
1551,
8,
1501,
9,
267,
871,
5925,
12,
2329,
26,
288,
870,
298,
6049,
1133,
1551,
450,
83,
26,
450,
83,
2,
450,
334,
1501,
12,
2329,
9,
288,
372,
756,
267,
291,
14,
5155,
18,
1955,
275,
1052,
267,
291,
14,
1955,
18,
5155,
275,
1052,
267,
5874,
275,
378,
267,
367,
1004,
315,
289,
26,
288,
5874,
847,
413,
288,
1303,
275,
295,
14,
1431,
8,
82,
16136,
3,
4640,
60,
83,
20900,
87,
13439,
83,
20900,
68,
8771,
11918,
1004,
9,
288,
340,
440,
1303,
436,
1004,
14,
1913,
837,
355,
870,
2071,
83,
4042,
83,
304,
883,
1133,
2198,
450,
83,
2,
450,
334,
1501,
12,
5874,
12,
8179,
1004,
14,
1913,
1012,
288,
587,
26,
355,
5272,
12,
1329,
275,
1303,
14,
2634,
342,
355,
1329,
275,
1109,
8,
1955,
9,
355,
702,
5272,
440,
315,
291,
14,
5155,
18,
1955,
355,
702,
1329,
440,
315,
291,
14,
1955,
18,
5155,
355,
291,
14,
5155,
18,
1955,
59,
5155,
61,
275,
1329,
355,
291,
14,
1955,
18,
5155,
59,
1955,
61,
275,
5272,
267,
372,
715,
339,
347,
2198,
63,
1679,
826,
63,
67,
8,
277,
12,
1788,
304,
267,
408,
4003,
314,
1275,
67,
570,
5313,
701,
299,
2268,
14,
221,
334,
8405,
9,
398,
710,
570,
10734,
465,
11924,
14,
221,
710,
1642,
2877,
2385,
787,
3544,
642,
26,
398,
327,
2613,
298,
80,
2268,
2139,
14,
72,
2,
267,
327,
2613,
298,
15239,
14,
72,
2,
398,
12836,
626,
11492,
11648,
5664,
26,
398,
413,
9,
1373,
503,
1655,
1174,
10269,
267,
499,
9,
282,
1817,
12669,
4051,
305,
267,
650,
9,
282,
1817,
12669,
3628,
267,
841,
9,
282,
2702,
12669,
314,
12528,
398,
437,
1174,
5492,
965,
314,
2569,
1824,
26,
267,
446,
1373,
503,
1655,
14972,
6572,
12,
1924,
402,
314,
1824,
26,
881,
2955,
14972,
601,
1259,
27718,
78,
30,
27718,
77,
9514,
28,
75,
19109,
275,
469,
2116,
469,
28,
73,
6244,
665,
74,
30,
1386,
2116,
2263,
881,
16735,
267,
446,
9437,
701,
282,
1174,
1625,
12,
402,
314,
1824,
26,
881,
2955,
1174,
6363,
27718,
83,
9514,
28,
84,
19109,
275,
469,
2116,
469,
28,
75,
6244,
601,
1259,
27718,
78,
30,
27718,
77,
30,
1386,
2116,
2263,
881,
16735,
398,
408,
267,
862,
26,
288,
289,
275,
1551,
8,
1501,
9,
267,
871,
5925,
12,
2329,
26,
288,
870,
298,
6049,
1133,
1551,
450,
83,
26,
450,
83,
2,
450,
334,
1501,
12,
2329,
9,
288,
372,
756,
267,
327,
710,
1233,
5084,
28891,
4440,
289,
1159,
6122,
13,
4171,
1,
267,
5874,
275,
378,
398,
327,
15100,
314,
2877,
327,
2613,
2385,
267,
5874,
12,
1004,
275,
5874,
11,
17,
12,
289,
14,
2184,
342,
267,
702,
1004,
508,
3943,
2613,
298,
80,
2268,
2139,
14,
72,
3212,
78,
297,
334,
3469,
12,
1004,
9,
267,
5874,
12,
1004,
275,
5874,
11,
17,
12,
289,
14,
2184,
342,
267,
702,
1004,
508,
3943,
2613,
298,
15239,
14,
72,
3212,
78,
297,
334,
3469,
12,
1004,
9,
398,
327,
6077,
314,
1174,
10269,
267,
5874,
12,
1004,
275
] |
[
1898,
8353,
13,
9397,
6566,
279,
13863,
12,
3277,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
7306,
1999,
77,
826,
24097,
335,
61,
2249,
390,
734,
701,
299,
2268,
370,
2018,
1233,
14,
199,
199,
48,
2268,
365,
314,
2018,
1798,
4306,
14,
221,
2779,
365,
2997,
370,
23661,
1218,
282,
199,
2087,
687,
282,
12528,
570,
315,
2018,
1159,
12528,
15843,
14,
221,
11017,
473,
2793,
1133,
199,
7051,
3002,
21295,
370,
506,
5313,
315,
445,
334,
28064,
395,
880,
473,
6704,
1752,
24615,
314,
199,
11059,
6716,
370,
2018,
666,
13955,
436,
3575,
282,
2018,
2198,
199,
3908,
14,
199,
199,
7443,
626,
314,
1526,
5579,
787,
5262,
12037,
701,
314,
4465,
199,
4718,
14803,
14,
221,
710,
4465,
1526,
859,
7890,
3520,
5579,
436,
199,
1589,
723,
1561,
334,
1589,
1561,
787,
440,
1202,
8298,
680,
221,
710,
1526,
5579,
787,
199,
8726,
15282,
1901,
314,
2018,
14803,
436,
1901,
299,
2268,
14,
221,
437,
2018,
199,
12236,
402,
314,
2018,
14803,
365,
2597,
2808,
12,
315,
314,
199,
6807,
13343,
859,
14,
199,
199,
3314,
314,
1163,
4926,
12,
5272,
5579,
334,
13063,
316,
314,
12528,
1159,
199,
2865,
13,
24322,
9,
787,
7943,
701,
299,
2268,
4079,
641,
314,
3503,
12528,
199,
1210,
14,
199,
199,
7443,
26,
642,
859,
365,
7268,
8298,
24985,
27,
314,
299,
2268,
859,
12821,
199,
24179,
12528,
6716,
5370,
687,
314,
10268,
9992,
14,
2424,
1324,
570,
199,
7395,
9445,
370,
12677,
314,
2018,
299,
2268,
445,
2240,
14,
199,
199,
624,
199,
199,
3,
2018,
8925,
199,
646,
295,
199,
199,
3,
10111,
8925,
199,
504,
299,
2268,
18,
492,
12528,
12,
1526,
421,
199,
533,
11801,
351,
8,
15239,
14,
27119,
304,
272,
408,
27119,
5516,
626,
11597,
31205,
299,
2268,
1072,
1584,
14,
339,
710,
1255,
342,
1083,
11597,
314,
6716,
465,
13584,
701,
314,
299,
2268,
1798,
272,
4306,
12,
13609,
10470,
315,
2877,
445,
1584,
12,
1999,
77,
826,
14,
72,
436,
272,
1999,
77,
826,
14,
67,
14,
221,
710,
1163,
3102,
787,
367,
5007,
675,
1454,
14,
339,
1666,
314,
1300,
1021,
367,
1655,
3794,
14,
339,
408,
339,
347,
1255,
8,
277,
12,
1999,
77,
826,
63,
72,
12,
1999,
77,
826,
63,
67,
304,
267,
408,
6200,
314,
12528,
6716,
687,
314,
1318,
1584,
5313,
701,
299,
2268,
1041,
267,
291,
14,
1122,
63,
1679,
826,
63,
72,
8,
1679,
826,
63,
72,
9,
267,
291,
14,
1122,
63,
1679,
826,
63,
67,
8,
1679,
826,
63,
67,
9,
267,
291,
14,
8192,
63,
1997,
342,
339,
347,
2198,
63,
1679,
826,
63,
72,
8,
277,
12,
1788,
304,
267,
408,
4003,
314,
1275,
72,
570,
5313,
701,
299,
2268,
14,
221,
334,
8405,
9,
398,
961,
570,
365,
282,
3414,
402,
327,
4640,
9834,
12669,
314,
267,
2222,
24322,
402,
314,
12528,
465,
5579,
14,
221,
2136,
1900,
2877,
6716,
267,
4412,
314,
5579,
370,
1561,
436,
1771,
14,
398,
408,
267,
862,
26,
288,
289,
275,
1551,
8,
1501,
9,
267,
871,
5925,
12,
2329,
26,
288,
870,
298,
6049,
1133,
1551,
450,
83,
26,
450,
83,
2,
450,
334,
1501,
12,
2329,
9,
288,
372,
756,
267,
291,
14,
5155,
18,
1955,
275,
1052,
267,
291,
14,
1955,
18,
5155,
275,
1052,
267,
5874,
275,
378,
267,
367,
1004,
315,
289,
26,
288,
5874,
847,
413,
288,
1303,
275,
295,
14,
1431,
8,
82,
16136,
3,
4640,
60,
83,
20900,
87,
13439,
83,
20900,
68,
8771,
11918,
1004,
9,
288,
340,
440,
1303,
436,
1004,
14,
1913,
837,
355,
870,
2071,
83,
4042,
83,
304,
883,
1133,
2198,
450,
83,
2,
450,
334,
1501,
12,
5874,
12,
8179,
1004,
14,
1913,
1012,
288,
587,
26,
355,
5272,
12,
1329,
275,
1303,
14,
2634,
342,
355,
1329,
275,
1109,
8,
1955,
9,
355,
702,
5272,
440,
315,
291,
14,
5155,
18,
1955,
355,
702,
1329,
440,
315,
291,
14,
1955,
18,
5155,
355,
291,
14,
5155,
18,
1955,
59,
5155,
61,
275,
1329,
355,
291,
14,
1955,
18,
5155,
59,
1955,
61,
275,
5272,
267,
372,
715,
339,
347,
2198,
63,
1679,
826,
63,
67,
8,
277,
12,
1788,
304,
267,
408,
4003,
314,
1275,
67,
570,
5313,
701,
299,
2268,
14,
221,
334,
8405,
9,
398,
710,
570,
10734,
465,
11924,
14,
221,
710,
1642,
2877,
2385,
787,
3544,
642,
26,
398,
327,
2613,
298,
80,
2268,
2139,
14,
72,
2,
267,
327,
2613,
298,
15239,
14,
72,
2,
398,
12836,
626,
11492,
11648,
5664,
26,
398,
413,
9,
1373,
503,
1655,
1174,
10269,
267,
499,
9,
282,
1817,
12669,
4051,
305,
267,
650,
9,
282,
1817,
12669,
3628,
267,
841,
9,
282,
2702,
12669,
314,
12528,
398,
437,
1174,
5492,
965,
314,
2569,
1824,
26,
267,
446,
1373,
503,
1655,
14972,
6572,
12,
1924,
402,
314,
1824,
26,
881,
2955,
14972,
601,
1259,
27718,
78,
30,
27718,
77,
9514,
28,
75,
19109,
275,
469,
2116,
469,
28,
73,
6244,
665,
74,
30,
1386,
2116,
2263,
881,
16735,
267,
446,
9437,
701,
282,
1174,
1625,
12,
402,
314,
1824,
26,
881,
2955,
1174,
6363,
27718,
83,
9514,
28,
84,
19109,
275,
469,
2116,
469,
28,
75,
6244,
601,
1259,
27718,
78,
30,
27718,
77,
30,
1386,
2116,
2263,
881,
16735,
398,
408,
267,
862,
26,
288,
289,
275,
1551,
8,
1501,
9,
267,
871,
5925,
12,
2329,
26,
288,
870,
298,
6049,
1133,
1551,
450,
83,
26,
450,
83,
2,
450,
334,
1501,
12,
2329,
9,
288,
372,
756,
267,
327,
710,
1233,
5084,
28891,
4440,
289,
1159,
6122,
13,
4171,
1,
267,
5874,
275,
378,
398,
327,
15100,
314,
2877,
327,
2613,
2385,
267,
5874,
12,
1004,
275,
5874,
11,
17,
12,
289,
14,
2184,
342,
267,
702,
1004,
508,
3943,
2613,
298,
80,
2268,
2139,
14,
72,
3212,
78,
297,
334,
3469,
12,
1004,
9,
267,
5874,
12,
1004,
275,
5874,
11,
17,
12,
289,
14,
2184,
342,
267,
702,
1004,
508,
3943,
2613,
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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
] |
cortedeltimo/SickRage
|
lib/concurrent/futures/thread.py
|
14
|
5643
|
# Copyright 2009 Brian Quinlan. All Rights Reserved.
# Licensed to PSF under a Contributor Agreement.
"""Implements ThreadPoolExecutor."""
import atexit
from concurrent.futures import _base
import itertools
import Queue as queue
import threading
import weakref
import sys
try:
from multiprocessing import cpu_count
except ImportError:
# some platforms don't have multiprocessing
def cpu_count():
return None
__author__ = 'Brian Quinlan (brian@sweetapp.com)'
# Workers are created as daemon threads. This is done to allow the interpreter
# to exit when there are still idle threads in a ThreadPoolExecutor's thread
# pool (i.e. shutdown() was not called). However, allowing workers to die with
# the interpreter has two undesirable properties:
# - The workers would still be running during interpretor shutdown,
# meaning that they would fail in unpredictable ways.
# - The workers could be killed while evaluating a work item, which could
# be bad if the callable being evaluated has external side-effects e.g.
# writing to a file.
#
# To work around this problem, an exit handler is installed which tells the
# workers to exit when their work queues are empty and then waits until the
# threads finish.
_threads_queues = weakref.WeakKeyDictionary()
_shutdown = False
def _python_exit():
global _shutdown
_shutdown = True
items = list(_threads_queues.items()) if _threads_queues else ()
for t, q in items:
q.put(None)
for t, q in items:
t.join(sys.maxint)
atexit.register(_python_exit)
class _WorkItem(object):
def __init__(self, future, fn, args, kwargs):
self.future = future
self.fn = fn
self.args = args
self.kwargs = kwargs
def run(self):
if not self.future.set_running_or_notify_cancel():
return
try:
result = self.fn(*self.args, **self.kwargs)
except:
e, tb = sys.exc_info()[1:]
self.future.set_exception_info(e, tb)
else:
self.future.set_result(result)
def _worker(executor_reference, work_queue):
try:
while True:
work_item = work_queue.get(block=True)
if work_item is not None:
work_item.run()
# Delete references to object. See issue16284
del work_item
continue
executor = executor_reference()
# Exit if:
# - The interpreter is shutting down OR
# - The executor that owns the worker has been collected OR
# - The executor that owns the worker has been shutdown.
if _shutdown or executor is None or executor._shutdown:
# Notice other workers
work_queue.put(None)
return
del executor
except:
_base.LOGGER.critical('Exception in worker', exc_info=True)
class ThreadPoolExecutor(_base.Executor):
# Used to assign unique thread names when thread_name_prefix is not supplied.
_counter = itertools.count().next
def __init__(self, max_workers=None, thread_name_prefix=''):
"""Initializes a new ThreadPoolExecutor instance.
Args:
max_workers: The maximum number of threads that can be used to
execute the given calls.
thread_name_prefix: An optional name prefix to give our threads.
"""
if max_workers is None:
# Use this number because ThreadPoolExecutor is often
# used to overlap I/O instead of CPU work.
max_workers = (cpu_count() or 1) * 5
if max_workers <= 0:
raise ValueError("max_workers must be greater than 0")
self._max_workers = max_workers
self._work_queue = queue.Queue()
self._threads = set()
self._shutdown = False
self._shutdown_lock = threading.Lock()
self._thread_name_prefix = (thread_name_prefix or
("ThreadPoolExecutor-%d" % self._counter()))
def submit(self, fn, *args, **kwargs):
with self._shutdown_lock:
if self._shutdown:
raise RuntimeError('cannot schedule new futures after shutdown')
f = _base.Future()
w = _WorkItem(f, fn, args, kwargs)
self._work_queue.put(w)
self._adjust_thread_count()
return f
submit.__doc__ = _base.Executor.submit.__doc__
def _adjust_thread_count(self):
# When the executor gets lost, the weakref callback will wake up
# the worker threads.
def weakref_cb(_, q=self._work_queue):
q.put(None)
# TODO(bquinlan): Should avoid creating new threads if there are more
# idle threads than items in the work queue.
num_threads = len(self._threads)
if num_threads < self._max_workers:
thread_name = '%s_%d' % (self._thread_name_prefix or self,
num_threads)
t = threading.Thread(name=thread_name, target=_worker,
args=(weakref.ref(self, weakref_cb),
self._work_queue))
t.daemon = True
t.start()
self._threads.add(t)
_threads_queues[t] = self._work_queue
def shutdown(self, wait=True):
with self._shutdown_lock:
self._shutdown = True
self._work_queue.put(None)
if wait:
for t in self._threads:
t.join(sys.maxint)
shutdown.__doc__ = _base.Executor.shutdown.__doc__
|
gpl-3.0
|
[
3,
1898,
8937,
699,
18429,
5843,
262,
1502,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
29452,
11086,
5453,
16752,
1041,
199,
199,
646,
19840,
199,
504,
23002,
14,
25513,
492,
485,
1095,
199,
646,
7975,
199,
646,
10703,
465,
4126,
199,
646,
5796,
199,
646,
13852,
199,
646,
984,
199,
199,
893,
26,
272,
687,
12866,
492,
5033,
63,
835,
199,
2590,
3545,
26,
272,
327,
2005,
10677,
2793,
1133,
1172,
12866,
272,
347,
5033,
63,
835,
837,
267,
372,
488,
199,
199,
363,
2502,
363,
275,
283,
34,
18429,
5843,
262,
1502,
334,
9660,
290,
32,
83,
11554,
571,
14,
957,
3171,
199,
199,
3,
9361,
1192,
787,
2737,
465,
11128,
7183,
14,
961,
365,
4224,
370,
2040,
314,
12693,
199,
3,
370,
4458,
1380,
2337,
787,
5139,
15072,
7183,
315,
282,
11086,
5453,
16752,
1159,
2462,
199,
3,
4203,
334,
73,
14,
69,
14,
12842,
342,
1990,
440,
2797,
680,
9738,
12,
17266,
14123,
370,
18833,
543,
199,
3,
314,
12693,
965,
2877,
625,
271,
338,
6842,
4382,
26,
199,
3,
257,
446,
710,
14123,
3955,
5139,
506,
3879,
5309,
6421,
8270,
12842,
12,
199,
3,
258,
11150,
626,
2985,
3955,
2449,
315,
625,
6892,
461,
15217,
14,
199,
3,
257,
446,
710,
14123,
4293,
506,
26659,
1830,
27083,
282,
1736,
1242,
12,
1314,
4293,
199,
3,
258,
506,
4875,
340,
314,
4550,
3769,
13006,
965,
5957,
5366,
13,
27626,
325,
14,
71,
14,
199,
3,
258,
3575,
370,
282,
570,
14,
199,
3,
199,
3,
4005,
1736,
6818,
642,
5160,
12,
376,
4458,
3016,
365,
4903,
1314,
26544,
314,
199,
3,
14123,
370,
4458,
1380,
3932,
1736,
21366,
787,
2701,
436,
2066,
14442,
1405,
5133,
314,
199,
3,
7183,
9578,
14,
199,
199,
63,
6962,
63,
18849,
275,
13852,
14,
18889,
1197,
11728,
342,
199,
63,
8831,
275,
756,
199,
199,
318,
485,
1548,
63,
2224,
837,
272,
2288,
485,
8831,
272,
485,
8831,
275,
715,
272,
2974,
275,
769,
1547,
6962,
63,
18849,
14,
1744,
1012,
340,
485,
6962,
63,
18849,
587,
6248,
272,
367,
307,
12,
1894,
315,
2974,
26,
267,
1894,
14,
524,
8,
403,
9,
272,
367,
307,
12,
1894,
315,
2974,
26,
267,
307,
14,
904,
8,
1274,
14,
21411,
9,
199,
199,
24026,
390,
14,
2683,
1547,
1548,
63,
2224,
9,
199,
199,
533,
485,
6517,
2081,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
6466,
12,
4325,
12,
1249,
12,
2074,
304,
267,
291,
14,
2443,
275,
6466,
267,
291,
14,
2324,
275,
4325,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
958,
275,
2074,
339,
347,
1255,
8,
277,
304,
267,
340,
440,
291,
14,
2443,
14,
409,
63,
5720,
63,
269,
63,
6814,
63,
6406,
837,
288,
372,
398,
862,
26,
288,
754,
275,
291,
14,
2324,
2031,
277,
14,
589,
12,
1011,
277,
14,
958,
9,
267,
871,
26,
288,
325,
12,
7070,
275,
984,
14,
2804,
63,
815,
3430,
17,
2938,
288,
291,
14,
2443,
14,
409,
63,
1971,
63,
815,
8,
69,
12,
7070,
9,
267,
587,
26,
288,
291,
14,
2443,
14,
409,
63,
1099,
8,
1099,
9,
199,
199,
318,
485,
6599,
8,
13471,
63,
4443,
12,
1736,
63,
1825,
304,
272,
862,
26,
267,
1830,
715,
26,
288,
1736,
63,
1053,
275,
1736,
63,
1825,
14,
362,
8,
1457,
29,
549,
9,
288,
340,
1736,
63,
1053,
365,
440,
488,
26,
355,
1736,
63,
1053,
14,
1065,
342,
355,
327,
8496,
6941,
370,
909,
14,
1666,
4976,
975,
10681,
355,
2150,
1736,
63,
1053,
355,
1980,
288,
13270,
275,
13270,
63,
4443,
342,
288,
327,
18704,
340,
26,
288,
327,
257,
446,
710,
12693,
365,
24761,
1337,
3224,
1549,
288,
327,
257,
446,
710,
13270,
626,
22182,
561,
314,
7239,
965,
2757,
13736,
1549,
288,
327,
257,
446,
710,
13270,
626,
22182,
561,
314,
7239,
965,
2757,
12842,
14,
288,
340,
485,
8831,
503,
13270,
365,
488,
503,
13270,
423,
8831,
26,
355,
327,
3091,
3548,
1163,
14123,
355,
1736,
63,
1825,
14,
524,
8,
403,
9,
355,
372,
288,
2150,
13270,
272,
871,
26,
267,
485,
1095,
14,
10186,
14,
13138,
360,
1726,
315,
7239,
297,
3178,
63,
815,
29,
549,
9,
421,
199,
533,
11086,
5453,
16752,
1547,
1095,
14,
16752,
304,
339,
327,
8051,
370,
5090,
3747,
2462,
1561,
1380,
2462,
63,
354,
63,
1861,
365,
440,
6841,
14,
272,
485,
5337,
275,
7975,
14,
835,
1252,
2184,
339,
347,
636,
826,
721,
277,
12,
1390,
63,
11009,
29,
403,
12,
2462,
63,
354,
63,
1861,
9280,
267,
408,
23489,
282,
892,
11086,
5453,
16752,
1256,
14,
398,
3033,
26,
288,
1390,
63,
11009,
26,
710,
5696,
1329,
402,
7183,
626,
883,
506,
1202,
370,
355,
5341,
314,
1627,
4882,
14,
288,
2462,
63,
354,
63,
1861,
26,
1626,
2716,
536,
2403,
370,
8120,
4154,
7183,
14,
267,
408,
267,
340,
1390,
63,
11009,
365,
488,
26,
288,
327,
3645,
642,
1329,
2952,
11086,
5453,
16752,
365,
14115,
288,
327,
1202,
370,
15145,
473,
15,
47,
3140,
402,
11952,
1736,
14,
288,
1390,
63,
11009,
275,
334,
3541,
63,
835,
342,
503,
413,
9,
627,
959,
267,
340,
1390,
63,
11009,
2695,
378,
26,
288,
746,
1722,
480,
988,
63,
11009,
1471,
506,
8932,
2419,
378,
531,
398,
291,
423,
988,
63,
11009,
275,
1390,
63,
11009,
267,
291,
423,
800,
63,
1825,
275,
4126,
14,
3737,
342,
267,
291,
423,
6962,
275,
663,
342,
267,
291,
423,
8831,
275,
756,
267,
291,
423,
8831,
63,
831,
275,
5796,
14,
6432,
342,
267,
291,
423,
2671,
63,
354,
63,
1861,
275,
334,
2671,
63,
354,
63,
1861,
503,
2511,
1689,
4436,
5453,
16752,
3295,
68,
2,
450,
291,
423,
5337,
4059,
339,
347,
11482,
8,
277,
12,
4325,
12,
627,
589,
12,
1011,
958,
304,
267,
543,
291,
423,
8831,
63,
831,
26,
288,
340,
291,
423,
8831,
26,
355,
746,
6064,
360,
11250,
8732,
892,
27471,
2410,
12842,
358,
953,
289,
275,
485,
1095,
14,
14224,
342,
288,
336,
275,
485,
6517,
2081,
8,
70,
12,
4325,
12,
1249,
12,
2074,
9,
953,
291,
423,
800,
63,
1825
] |
[
1898,
8937,
699,
18429,
5843,
262,
1502,
14,
2900,
5924,
5702,
14,
199,
3,
3909,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
199,
624,
29452,
11086,
5453,
16752,
1041,
199,
199,
646,
19840,
199,
504,
23002,
14,
25513,
492,
485,
1095,
199,
646,
7975,
199,
646,
10703,
465,
4126,
199,
646,
5796,
199,
646,
13852,
199,
646,
984,
199,
199,
893,
26,
272,
687,
12866,
492,
5033,
63,
835,
199,
2590,
3545,
26,
272,
327,
2005,
10677,
2793,
1133,
1172,
12866,
272,
347,
5033,
63,
835,
837,
267,
372,
488,
199,
199,
363,
2502,
363,
275,
283,
34,
18429,
5843,
262,
1502,
334,
9660,
290,
32,
83,
11554,
571,
14,
957,
3171,
199,
199,
3,
9361,
1192,
787,
2737,
465,
11128,
7183,
14,
961,
365,
4224,
370,
2040,
314,
12693,
199,
3,
370,
4458,
1380,
2337,
787,
5139,
15072,
7183,
315,
282,
11086,
5453,
16752,
1159,
2462,
199,
3,
4203,
334,
73,
14,
69,
14,
12842,
342,
1990,
440,
2797,
680,
9738,
12,
17266,
14123,
370,
18833,
543,
199,
3,
314,
12693,
965,
2877,
625,
271,
338,
6842,
4382,
26,
199,
3,
257,
446,
710,
14123,
3955,
5139,
506,
3879,
5309,
6421,
8270,
12842,
12,
199,
3,
258,
11150,
626,
2985,
3955,
2449,
315,
625,
6892,
461,
15217,
14,
199,
3,
257,
446,
710,
14123,
4293,
506,
26659,
1830,
27083,
282,
1736,
1242,
12,
1314,
4293,
199,
3,
258,
506,
4875,
340,
314,
4550,
3769,
13006,
965,
5957,
5366,
13,
27626,
325,
14,
71,
14,
199,
3,
258,
3575,
370,
282,
570,
14,
199,
3,
199,
3,
4005,
1736,
6818,
642,
5160,
12,
376,
4458,
3016,
365,
4903,
1314,
26544,
314,
199,
3,
14123,
370,
4458,
1380,
3932,
1736,
21366,
787,
2701,
436,
2066,
14442,
1405,
5133,
314,
199,
3,
7183,
9578,
14,
199,
199,
63,
6962,
63,
18849,
275,
13852,
14,
18889,
1197,
11728,
342,
199,
63,
8831,
275,
756,
199,
199,
318,
485,
1548,
63,
2224,
837,
272,
2288,
485,
8831,
272,
485,
8831,
275,
715,
272,
2974,
275,
769,
1547,
6962,
63,
18849,
14,
1744,
1012,
340,
485,
6962,
63,
18849,
587,
6248,
272,
367,
307,
12,
1894,
315,
2974,
26,
267,
1894,
14,
524,
8,
403,
9,
272,
367,
307,
12,
1894,
315,
2974,
26,
267,
307,
14,
904,
8,
1274,
14,
21411,
9,
199,
199,
24026,
390,
14,
2683,
1547,
1548,
63,
2224,
9,
199,
199,
533,
485,
6517,
2081,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
6466,
12,
4325,
12,
1249,
12,
2074,
304,
267,
291,
14,
2443,
275,
6466,
267,
291,
14,
2324,
275,
4325,
267,
291,
14,
589,
275,
1249,
267,
291,
14,
958,
275,
2074,
339,
347,
1255,
8,
277,
304,
267,
340,
440,
291,
14,
2443,
14,
409,
63,
5720,
63,
269,
63,
6814,
63,
6406,
837,
288,
372,
398,
862,
26,
288,
754,
275,
291,
14,
2324,
2031,
277,
14,
589,
12,
1011,
277,
14,
958,
9,
267,
871,
26,
288,
325,
12,
7070,
275,
984,
14,
2804,
63,
815,
3430,
17,
2938,
288,
291,
14,
2443,
14,
409,
63,
1971,
63,
815,
8,
69,
12,
7070,
9,
267,
587,
26,
288,
291,
14,
2443,
14,
409,
63,
1099,
8,
1099,
9,
199,
199,
318,
485,
6599,
8,
13471,
63,
4443,
12,
1736,
63,
1825,
304,
272,
862,
26,
267,
1830,
715,
26,
288,
1736,
63,
1053,
275,
1736,
63,
1825,
14,
362,
8,
1457,
29,
549,
9,
288,
340,
1736,
63,
1053,
365,
440,
488,
26,
355,
1736,
63,
1053,
14,
1065,
342,
355,
327,
8496,
6941,
370,
909,
14,
1666,
4976,
975,
10681,
355,
2150,
1736,
63,
1053,
355,
1980,
288,
13270,
275,
13270,
63,
4443,
342,
288,
327,
18704,
340,
26,
288,
327,
257,
446,
710,
12693,
365,
24761,
1337,
3224,
1549,
288,
327,
257,
446,
710,
13270,
626,
22182,
561,
314,
7239,
965,
2757,
13736,
1549,
288,
327,
257,
446,
710,
13270,
626,
22182,
561,
314,
7239,
965,
2757,
12842,
14,
288,
340,
485,
8831,
503,
13270,
365,
488,
503,
13270,
423,
8831,
26,
355,
327,
3091,
3548,
1163,
14123,
355,
1736,
63,
1825,
14,
524,
8,
403,
9,
355,
372,
288,
2150,
13270,
272,
871,
26,
267,
485,
1095,
14,
10186,
14,
13138,
360,
1726,
315,
7239,
297,
3178,
63,
815,
29,
549,
9,
421,
199,
533,
11086,
5453,
16752,
1547,
1095,
14,
16752,
304,
339,
327,
8051,
370,
5090,
3747,
2462,
1561,
1380,
2462,
63,
354,
63,
1861,
365,
440,
6841,
14,
272,
485,
5337,
275,
7975,
14,
835,
1252,
2184,
339,
347,
636,
826,
721,
277,
12,
1390,
63,
11009,
29,
403,
12,
2462,
63,
354,
63,
1861,
9280,
267,
408,
23489,
282,
892,
11086,
5453,
16752,
1256,
14,
398,
3033,
26,
288,
1390,
63,
11009,
26,
710,
5696,
1329,
402,
7183,
626,
883,
506,
1202,
370,
355,
5341,
314,
1627,
4882,
14,
288,
2462,
63,
354,
63,
1861,
26,
1626,
2716,
536,
2403,
370,
8120,
4154,
7183,
14,
267,
408,
267,
340,
1390,
63,
11009,
365,
488,
26,
288,
327,
3645,
642,
1329,
2952,
11086,
5453,
16752,
365,
14115,
288,
327,
1202,
370,
15145,
473,
15,
47,
3140,
402,
11952,
1736,
14,
288,
1390,
63,
11009,
275,
334,
3541,
63,
835,
342,
503,
413,
9,
627,
959,
267,
340,
1390,
63,
11009,
2695,
378,
26,
288,
746,
1722,
480,
988,
63,
11009,
1471,
506,
8932,
2419,
378,
531,
398,
291,
423,
988,
63,
11009,
275,
1390,
63,
11009,
267,
291,
423,
800,
63,
1825,
275,
4126,
14,
3737,
342,
267,
291,
423,
6962,
275,
663,
342,
267,
291,
423,
8831,
275,
756,
267,
291,
423,
8831,
63,
831,
275,
5796,
14,
6432,
342,
267,
291,
423,
2671,
63,
354,
63,
1861,
275,
334,
2671,
63,
354,
63,
1861,
503,
2511,
1689,
4436,
5453,
16752,
3295,
68,
2,
450,
291,
423,
5337,
4059,
339,
347,
11482,
8,
277,
12,
4325,
12,
627,
589,
12,
1011,
958,
304,
267,
543,
291,
423,
8831,
63,
831,
26,
288,
340,
291,
423,
8831,
26,
355,
746,
6064,
360,
11250,
8732,
892,
27471,
2410,
12842,
358,
953,
289,
275,
485,
1095,
14,
14224,
342,
288,
336,
275,
485,
6517,
2081,
8,
70,
12,
4325,
12,
1249,
12,
2074,
9,
953,
291,
423,
800,
63,
1825,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
PredictiveScienceLab/py-mcmc
|
demos/demo4.py
|
2
|
4183
|
"""
This demo demonstrates how to use a mean function in a GP and allow the model
to discover the most important basis functions.
This model is equivalent to a Relevance Vector Machine.
Author:
Ilias Bilionis
Date:
3/20/2014
"""
import numpy as np
import GPy
import pymcmc as pm
import matplotlib.pyplot as plt
# Write a class that represents the mean you wish to use:
class PolynomialBasis(object):
"""
A simple set of polynomials.
:param degree: The degree of the polynomials.
:type degree: int
"""
def __init__(self, degree):
"""
The constructor can do anything you want. The object should be
constructed before doing anything with pymcmc in any case.
Just make sure that inside the constructor you define the ``num_output``
attribute whose value should be equal to the number of basis functions.
"""
self.degree = degree
self.num_output = degree + 1 # YOU HAVE TO DEFINE THIS ATTRIBUTE!
def __call__(self, X):
"""
Evaluate the basis functions at ``X``.
Now, you should assume that ``X`` is a 2D numpy array of size
``num_points x input_dim``. If ``input_dim`` is 1, then you still need
to consider it as a 2D array because this is the kind of data that GPy
requires. If you want to make the function work also with 1D arrays if
``input_dim`` is one the use the trick below.
The output of this function should be the design matrix. That is,
it should be the matrix ``phi`` of dimensions
``num_points x num_output``. In otherwors, ``phi[i, j]`` should be
the value of basis function ``phi_j`` at ``X[i, :]``.
"""
if X.ndim == 1:
X = X[:, None] # Trick for 1D arrays
return np.hstack([X ** i for i in range(self.degree + 1)])
# Pick your degree
degree = 5
# Construct your basis
poly_basis = PolynomialBasis(degree)
# Let us generate some random data to play with
# The number of input dimensions
input_dim = 1
# The number of observations
num_points = 50
# The noise level we are going to add to the observations
noise = 0.1
# Observed inputs
X = 20. * np.random.rand(num_points, 1) - 10.
# The observations we make
Y = np.sin(X) / X + noise * np.random.randn(num_points, 1) - 0.1 * X + 0.1 * X ** 3
# Let's construct a GP model with just a mean and a diagonal covariance
# This is the mean (and at the same time the kernel)
mean = pm.MeanFunction(input_dim, poly_basis, ARD=True)
# Add an RBF kernel
kernel = GPy.kern.RBF(input_dim)
# Now, let's construct the model
model = GPy.models.GPRegression(X, Y, kernel=mean + kernel)
print 'Model before training:'
print str(model)
# You may just train the model by maximizing the likelihood:
model.optimize_restarts(messages=True)
print 'Trained model:'
print str(model)
print model.add.mean.variance
# And just plot the predictions
model.plot(plot_limits=(-10, 15))
# Let us also plot the full function
x = np.linspace(-10, 15, 100)[:, None]
y = np.sin(x) / x - 0.1 * x + 0.1 * x ** 3
plt.plot(x, y, 'r', linewidth=2)
plt.legend(['Mean of GP', '5% percentile of GP', '95% percentile of GP',
'Observations', 'Real Underlying Function'], loc='best')
plt.title('Model trained by maximizing the likelihood')
plt.show()
a = raw_input('press enter to continue...')
# Or you might want to do it using MCMC:
new_mean = pm.MeanFunction(input_dim, poly_basis, ARD=True)
new_kernel = GPy.kern.RBF(input_dim)
new_model = GPy.models.GPRegression(X, Y, kernel=mean + new_kernel)
proposal = pm.MALAProposal(dt=0.1)
mcmc = pm.MetropolisHastings(new_model, proposal=proposal)
mcmc.sample(50000, num_thin=100, num_burn=1000, verbose=True)
print 'Model trained with MCMC:'
print str(new_model)
print new_model.add.mean.variance
# Plot everything for this too:
new_model.plot(plot_limits=(-10., 15.))
# Let us also plot the full function
plt.plot(x, y, 'r', linewidth=2)
plt.legend(['Mean of GP', '5% percentile of GP', '95% percentile of GP',
'Observations', 'Real Underlying Function'], loc='best')
plt.title('Model trained by MCMC')
plt.show()
a = raw_input('press enter to continue...')
|
lgpl-3.0
|
[
624,
199,
2765,
14779,
23789,
31216,
4212,
370,
675,
282,
4615,
805,
315,
282,
17346,
436,
2040,
314,
1402,
199,
475,
20131,
314,
4750,
11012,
5597,
3423,
14,
199,
2765,
1402,
365,
7353,
370,
282,
799,
28791,
11388,
18722,
14,
199,
199,
5949,
26,
272,
473,
317,
305,
699,
1638,
265,
374,
199,
199,
2506,
26,
272,
650,
15,
1165,
15,
7280,
199,
199,
624,
421,
199,
646,
2680,
465,
980,
199,
646,
598,
2713,
199,
646,
1134,
77,
4400,
67,
465,
14207,
199,
646,
8027,
14,
13563,
465,
4488,
421,
199,
3,
6990,
282,
1021,
626,
8469,
314,
4615,
1265,
13809,
370,
675,
26,
199,
533,
8467,
8887,
34,
4864,
8,
785,
304,
272,
408,
272,
437,
3486,
663,
402,
27599,
14,
339,
520,
635,
13666,
26,
221,
710,
13666,
402,
314,
27599,
14,
272,
520,
466,
13666,
26,
257,
1109,
272,
408,
339,
347,
636,
826,
721,
277,
12,
13666,
304,
267,
408,
267,
710,
3787,
883,
886,
7003,
1265,
2934,
14,
710,
909,
1077,
506,
267,
14701,
2544,
9689,
7003,
543,
1134,
77,
4400,
67,
315,
1263,
1930,
14,
267,
13870,
1852,
3238,
626,
6272,
314,
3787,
1265,
5627,
314,
1124,
1507,
63,
1199,
1040,
267,
2225,
7447,
574,
1077,
506,
4472,
370,
314,
1329,
402,
5597,
3423,
14,
267,
408,
267,
291,
14,
10956,
275,
13666,
267,
291,
14,
1507,
63,
1199,
275,
13666,
435,
413,
327,
1488,
22050,
25227,
2296,
23566,
3565,
5749,
10762,
2100,
4586,
1,
339,
347,
636,
1250,
721,
277,
12,
1323,
304,
267,
408,
267,
27450,
314,
5597,
3423,
737,
1124,
56,
4345,
398,
7356,
12,
1265,
1077,
5534,
626,
1124,
56,
1040,
365,
282,
499,
36,
2680,
1625,
402,
1568,
267,
1124,
1507,
63,
3438,
671,
1324,
63,
3572,
4345,
982,
1124,
1210,
63,
3572,
1040,
365,
413,
12,
2066,
1265,
5139,
1929,
267,
370,
11201,
652,
465,
282,
499,
36,
1625,
2952,
642,
365,
314,
4928,
402,
666,
626,
598,
2713,
267,
5074,
14,
982,
1265,
2934,
370,
1852,
314,
805,
1736,
2597,
543,
413,
36,
6572,
340,
267,
1124,
1210,
63,
3572,
1040,
365,
1373,
314,
675,
314,
20907,
5084,
14,
398,
710,
1072,
402,
642,
805,
1077,
506,
314,
12899,
3634,
14,
10314,
365,
12,
267,
652,
1077,
506,
314,
3634,
1124,
10909,
1040,
402,
7365,
267,
1124,
1507,
63,
3438,
671,
1967,
63,
1199,
4345,
1010,
1163,
584,
83,
12,
1124,
10909,
59,
73,
12,
1335,
21133,
1077,
506,
267,
314,
574,
402,
5597,
805,
1124,
10909,
63,
74,
1040,
737,
1124,
56,
59,
73,
12,
12228,
4345,
267,
408,
267,
340,
1323,
14,
8322,
508,
413,
26,
288,
1323,
275,
1323,
3981,
488,
61,
327,
12480,
346,
367,
413,
36,
6572,
267,
372,
980,
14,
20949,
779,
56,
1011,
284,
367,
284,
315,
1425,
8,
277,
14,
10956,
435,
413,
3948,
421,
199,
3,
16568,
2195,
13666,
199,
10956,
275,
959,
199,
3,
9215,
2195,
5597,
199,
6023,
63,
19220,
275,
8467,
8887,
34,
4864,
8,
10956,
9,
199,
3,
12230,
2739,
3550,
2005,
2196,
666,
370,
5232,
543,
199,
3,
710,
1329,
402,
1324,
7365,
199,
1210,
63,
3572,
275,
413,
199,
3,
710,
1329,
402,
19739,
199,
1507,
63,
3438,
275,
5238,
199,
3,
710,
11145,
2166,
781,
787,
9995,
370,
1050,
370,
314,
19739,
199,
11838,
275,
378,
14,
17,
199,
3,
17985,
2485,
4153,
199,
56,
275,
3388,
14,
627,
980,
14,
2355,
14,
3759,
8,
1507,
63,
3438,
12,
413,
9,
446,
1616,
14,
199,
3,
710,
19739,
781,
1852,
199,
57,
275,
980,
14,
5911,
8,
56,
9,
1182,
1323,
435,
11145,
627,
980,
14,
2355,
14,
10843,
8,
1507,
63,
3438,
12,
413,
9,
446,
378,
14,
17,
627,
1323,
435,
378,
14,
17,
627,
1323,
1011,
650,
199,
3,
12230,
1159,
6982,
282,
17346,
1402,
543,
2951,
282,
4615,
436,
282,
16788,
13263,
199,
3,
961,
365,
314,
4615,
334,
460,
737,
314,
2011,
900,
314,
5114,
9,
199,
3670,
275,
14207,
14,
14825,
3481,
8,
1210,
63,
3572,
12,
8446,
63,
19220,
12,
4160,
36,
29,
549,
9,
199,
3,
2654,
376,
820,
12659,
5114,
199,
4989,
275,
598,
2713,
14,
30136,
14,
50,
12659,
8,
1210,
63,
3572,
9,
199,
3,
7356,
12,
4691,
1159,
6982,
314,
1402,
199,
1238,
275,
598,
2713,
14,
992,
14,
8225,
13013,
8,
56,
12,
1488,
12,
5114,
29,
3670,
435,
5114,
9,
199,
1361,
283,
1685,
2544,
6093,
4881,
199,
1361,
620,
8,
1238,
9,
199,
3,
2047,
1443,
2951,
3560,
314,
1402,
701,
1390,
1017,
9147,
314,
22046,
26,
199,
1238,
14,
13416,
63,
10506,
83,
8,
3431,
29,
549,
9,
199,
1361,
283,
2437,
1942,
1402,
4881,
199,
1361,
620,
8,
1238,
9,
199,
1361,
1402,
14,
525,
14,
3670,
14,
6221,
199,
3,
6061,
2951,
5137,
314,
7914,
199,
1238,
14,
2798,
8,
2798,
63,
9368,
26154,
709,
12,
4114,
430,
199,
3,
12230,
2739,
2597,
5137,
314,
2615,
805,
199,
88,
275,
980,
14,
11649,
2801,
709,
12,
4114,
12,
2948,
24517,
488,
61,
199,
89,
275,
980,
14,
5911,
8,
88,
9,
1182,
671,
446,
378,
14,
17,
627,
671,
435,
378,
14,
17,
627,
671,
1011,
650,
199,
6003,
14,
2798,
8,
88,
12,
612,
12,
283,
82,
297,
21213,
29,
18,
9,
199,
6003,
14,
10231,
2941,
14825,
402,
17346,
297,
283,
21,
5,
31537,
402,
17346,
297,
283,
2720,
5,
31537,
402,
17346,
297,
288,
283,
11394,
12225,
297,
283,
10099,
25010,
6670,
6801,
995,
4355,
534,
7010,
358,
199,
6003,
14,
1213,
360,
1685,
28161,
701,
1390,
1017,
9147,
314,
22046,
358,
199,
6003,
14,
2384,
342,
199,
65,
275,
3066,
63,
1210,
360,
2915,
9509,
370,
1980,
15103,
199,
3,
4236,
1265,
5594,
2934,
370,
886,
652,
1808,
32685,
7608,
26,
199,
1222,
63,
3670,
275,
14207,
14,
14825,
3481,
8,
1210,
63,
3572,
12,
8446,
63,
19220,
12,
4160,
36,
29,
549,
9,
199,
1222,
63,
4989,
275,
598,
2713,
14,
30136,
14,
50,
12659,
8,
1210,
63,
3572,
9,
199,
1222,
63,
1238,
275,
598,
2713,
14,
992,
14,
8225,
13013,
8,
56,
12,
1488,
12,
5114,
29,
3670,
435,
892,
63,
4989,
9,
199,
25700,
275,
14207,
14,
45
] |
[
199,
2765,
14779,
23789,
31216,
4212,
370,
675,
282,
4615,
805,
315,
282,
17346,
436,
2040,
314,
1402,
199,
475,
20131,
314,
4750,
11012,
5597,
3423,
14,
199,
2765,
1402,
365,
7353,
370,
282,
799,
28791,
11388,
18722,
14,
199,
199,
5949,
26,
272,
473,
317,
305,
699,
1638,
265,
374,
199,
199,
2506,
26,
272,
650,
15,
1165,
15,
7280,
199,
199,
624,
421,
199,
646,
2680,
465,
980,
199,
646,
598,
2713,
199,
646,
1134,
77,
4400,
67,
465,
14207,
199,
646,
8027,
14,
13563,
465,
4488,
421,
199,
3,
6990,
282,
1021,
626,
8469,
314,
4615,
1265,
13809,
370,
675,
26,
199,
533,
8467,
8887,
34,
4864,
8,
785,
304,
272,
408,
272,
437,
3486,
663,
402,
27599,
14,
339,
520,
635,
13666,
26,
221,
710,
13666,
402,
314,
27599,
14,
272,
520,
466,
13666,
26,
257,
1109,
272,
408,
339,
347,
636,
826,
721,
277,
12,
13666,
304,
267,
408,
267,
710,
3787,
883,
886,
7003,
1265,
2934,
14,
710,
909,
1077,
506,
267,
14701,
2544,
9689,
7003,
543,
1134,
77,
4400,
67,
315,
1263,
1930,
14,
267,
13870,
1852,
3238,
626,
6272,
314,
3787,
1265,
5627,
314,
1124,
1507,
63,
1199,
1040,
267,
2225,
7447,
574,
1077,
506,
4472,
370,
314,
1329,
402,
5597,
3423,
14,
267,
408,
267,
291,
14,
10956,
275,
13666,
267,
291,
14,
1507,
63,
1199,
275,
13666,
435,
413,
327,
1488,
22050,
25227,
2296,
23566,
3565,
5749,
10762,
2100,
4586,
1,
339,
347,
636,
1250,
721,
277,
12,
1323,
304,
267,
408,
267,
27450,
314,
5597,
3423,
737,
1124,
56,
4345,
398,
7356,
12,
1265,
1077,
5534,
626,
1124,
56,
1040,
365,
282,
499,
36,
2680,
1625,
402,
1568,
267,
1124,
1507,
63,
3438,
671,
1324,
63,
3572,
4345,
982,
1124,
1210,
63,
3572,
1040,
365,
413,
12,
2066,
1265,
5139,
1929,
267,
370,
11201,
652,
465,
282,
499,
36,
1625,
2952,
642,
365,
314,
4928,
402,
666,
626,
598,
2713,
267,
5074,
14,
982,
1265,
2934,
370,
1852,
314,
805,
1736,
2597,
543,
413,
36,
6572,
340,
267,
1124,
1210,
63,
3572,
1040,
365,
1373,
314,
675,
314,
20907,
5084,
14,
398,
710,
1072,
402,
642,
805,
1077,
506,
314,
12899,
3634,
14,
10314,
365,
12,
267,
652,
1077,
506,
314,
3634,
1124,
10909,
1040,
402,
7365,
267,
1124,
1507,
63,
3438,
671,
1967,
63,
1199,
4345,
1010,
1163,
584,
83,
12,
1124,
10909,
59,
73,
12,
1335,
21133,
1077,
506,
267,
314,
574,
402,
5597,
805,
1124,
10909,
63,
74,
1040,
737,
1124,
56,
59,
73,
12,
12228,
4345,
267,
408,
267,
340,
1323,
14,
8322,
508,
413,
26,
288,
1323,
275,
1323,
3981,
488,
61,
327,
12480,
346,
367,
413,
36,
6572,
267,
372,
980,
14,
20949,
779,
56,
1011,
284,
367,
284,
315,
1425,
8,
277,
14,
10956,
435,
413,
3948,
421,
199,
3,
16568,
2195,
13666,
199,
10956,
275,
959,
199,
3,
9215,
2195,
5597,
199,
6023,
63,
19220,
275,
8467,
8887,
34,
4864,
8,
10956,
9,
199,
3,
12230,
2739,
3550,
2005,
2196,
666,
370,
5232,
543,
199,
3,
710,
1329,
402,
1324,
7365,
199,
1210,
63,
3572,
275,
413,
199,
3,
710,
1329,
402,
19739,
199,
1507,
63,
3438,
275,
5238,
199,
3,
710,
11145,
2166,
781,
787,
9995,
370,
1050,
370,
314,
19739,
199,
11838,
275,
378,
14,
17,
199,
3,
17985,
2485,
4153,
199,
56,
275,
3388,
14,
627,
980,
14,
2355,
14,
3759,
8,
1507,
63,
3438,
12,
413,
9,
446,
1616,
14,
199,
3,
710,
19739,
781,
1852,
199,
57,
275,
980,
14,
5911,
8,
56,
9,
1182,
1323,
435,
11145,
627,
980,
14,
2355,
14,
10843,
8,
1507,
63,
3438,
12,
413,
9,
446,
378,
14,
17,
627,
1323,
435,
378,
14,
17,
627,
1323,
1011,
650,
199,
3,
12230,
1159,
6982,
282,
17346,
1402,
543,
2951,
282,
4615,
436,
282,
16788,
13263,
199,
3,
961,
365,
314,
4615,
334,
460,
737,
314,
2011,
900,
314,
5114,
9,
199,
3670,
275,
14207,
14,
14825,
3481,
8,
1210,
63,
3572,
12,
8446,
63,
19220,
12,
4160,
36,
29,
549,
9,
199,
3,
2654,
376,
820,
12659,
5114,
199,
4989,
275,
598,
2713,
14,
30136,
14,
50,
12659,
8,
1210,
63,
3572,
9,
199,
3,
7356,
12,
4691,
1159,
6982,
314,
1402,
199,
1238,
275,
598,
2713,
14,
992,
14,
8225,
13013,
8,
56,
12,
1488,
12,
5114,
29,
3670,
435,
5114,
9,
199,
1361,
283,
1685,
2544,
6093,
4881,
199,
1361,
620,
8,
1238,
9,
199,
3,
2047,
1443,
2951,
3560,
314,
1402,
701,
1390,
1017,
9147,
314,
22046,
26,
199,
1238,
14,
13416,
63,
10506,
83,
8,
3431,
29,
549,
9,
199,
1361,
283,
2437,
1942,
1402,
4881,
199,
1361,
620,
8,
1238,
9,
199,
1361,
1402,
14,
525,
14,
3670,
14,
6221,
199,
3,
6061,
2951,
5137,
314,
7914,
199,
1238,
14,
2798,
8,
2798,
63,
9368,
26154,
709,
12,
4114,
430,
199,
3,
12230,
2739,
2597,
5137,
314,
2615,
805,
199,
88,
275,
980,
14,
11649,
2801,
709,
12,
4114,
12,
2948,
24517,
488,
61,
199,
89,
275,
980,
14,
5911,
8,
88,
9,
1182,
671,
446,
378,
14,
17,
627,
671,
435,
378,
14,
17,
627,
671,
1011,
650,
199,
6003,
14,
2798,
8,
88,
12,
612,
12,
283,
82,
297,
21213,
29,
18,
9,
199,
6003,
14,
10231,
2941,
14825,
402,
17346,
297,
283,
21,
5,
31537,
402,
17346,
297,
283,
2720,
5,
31537,
402,
17346,
297,
288,
283,
11394,
12225,
297,
283,
10099,
25010,
6670,
6801,
995,
4355,
534,
7010,
358,
199,
6003,
14,
1213,
360,
1685,
28161,
701,
1390,
1017,
9147,
314,
22046,
358,
199,
6003,
14,
2384,
342,
199,
65,
275,
3066,
63,
1210,
360,
2915,
9509,
370,
1980,
15103,
199,
3,
4236,
1265,
5594,
2934,
370,
886,
652,
1808,
32685,
7608,
26,
199,
1222,
63,
3670,
275,
14207,
14,
14825,
3481,
8,
1210,
63,
3572,
12,
8446,
63,
19220,
12,
4160,
36,
29,
549,
9,
199,
1222,
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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
] |
transientlunatic/otter
|
otter/_version.py
|
1
|
18447
|
# This file helps to compute a version number in source trees obtained from
# git-archive tarball (such as those provided by githubs download-from-tag
# feature). Distribution tarballs (built by setup.py sdist) and build
# directories (produced by setup.py build) will contain a much shorter file
# that just contains the computed version number.
# This file is released into the public domain. Generated by
# versioneer-0.18 (https://github.com/warner/python-versioneer)
"""Git implementation of _version.py."""
import errno
import os
import re
import subprocess
import sys
def get_keywords():
"""Get the keywords needed to look up the version information."""
# these strings will be replaced by git during git-archive.
# setup.py/versioneer.py will grep for the variable names, so they must
# each be defined on a line of their own. _version.py will just call
# get_keywords().
git_refnames = "$Format:%d$"
git_full = "$Format:%H$"
git_date = "$Format:%ci$"
keywords = {"refnames": git_refnames, "full": git_full, "date": git_date}
return keywords
class VersioneerConfig:
"""Container for Versioneer configuration parameters."""
def get_config():
"""Create, populate and return the VersioneerConfig() object."""
# these strings are filled in when 'setup.py versioneer' creates
# _version.py
cfg = VersioneerConfig()
cfg.VCS = "git"
cfg.style = "pep440"
cfg.tag_prefix = "v"
cfg.parentdir_prefix = "None"
cfg.versionfile_source = "otter/_version.py"
cfg.verbose = False
return cfg
class NotThisMethod(Exception):
"""Exception raised if a method is not valid for the current scenario."""
LONG_VERSION_PY = {}
HANDLERS = {}
def register_vcs_handler(vcs, method): # decorator
"""Decorator to mark a method as the handler for a particular VCS."""
def decorate(f):
"""Store f in HANDLERS[vcs][method]."""
if vcs not in HANDLERS:
HANDLERS[vcs] = {}
HANDLERS[vcs][method] = f
return f
return decorate
def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False,
env=None):
"""Call the given command(s)."""
assert isinstance(commands, list)
p = None
for c in commands:
try:
dispcmd = str([c] + args)
# remember shell=False, so use git.cmd on windows, not just git
p = subprocess.Popen([c] + args, cwd=cwd, env=env,
stdout=subprocess.PIPE,
stderr=(subprocess.PIPE if hide_stderr
else None))
break
except EnvironmentError:
e = sys.exc_info()[1]
if e.errno == errno.ENOENT:
continue
if verbose:
print("unable to run %s" % dispcmd)
print(e)
return None, None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
return None, None
stdout = p.communicate()[0].strip()
if sys.version_info[0] >= 3:
stdout = stdout.decode()
if p.returncode != 0:
if verbose:
print("unable to run %s (error)" % dispcmd)
print("stdout was %s" % stdout)
return None, p.returncode
return stdout, p.returncode
def versions_from_parentdir(parentdir_prefix, root, verbose):
"""Try to determine the version from the parent directory name.
Source tarballs conventionally unpack into a directory that includes both
the project name and a version string. We will also support searching up
two directory levels for an appropriately named parent directory
"""
rootdirs = []
for i in range(3):
dirname = os.path.basename(root)
if dirname.startswith(parentdir_prefix):
return {"version": dirname[len(parentdir_prefix):],
"full-revisionid": None,
"dirty": False, "error": None, "date": None}
else:
rootdirs.append(root)
root = os.path.dirname(root) # up a level
if verbose:
print("Tried directories %s but none started with prefix %s" %
(str(rootdirs), parentdir_prefix))
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
@register_vcs_handler("git", "get_keywords")
def git_get_keywords(versionfile_abs):
"""Extract version information from the given file."""
# the code embedded in _version.py can just fetch the value of these
# keywords. When used from setup.py, we don't want to import _version.py,
# so we do it with a regexp instead. This function is not used from
# _version.py.
keywords = {}
try:
f = open(versionfile_abs, "r")
for line in f.readlines():
if line.strip().startswith("git_refnames ="):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
keywords["refnames"] = mo.group(1)
if line.strip().startswith("git_full ="):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
keywords["full"] = mo.group(1)
if line.strip().startswith("git_date ="):
mo = re.search(r'=\s*"(.*)"', line)
if mo:
keywords["date"] = mo.group(1)
f.close()
except EnvironmentError:
pass
return keywords
@register_vcs_handler("git", "keywords")
def git_versions_from_keywords(keywords, tag_prefix, verbose):
"""Get version information from git keywords."""
if not keywords:
raise NotThisMethod("no keywords at all, weird")
date = keywords.get("date")
if date is not None:
# git-2.2.0 added "%cI", which expands to an ISO-8601 -compliant
# datestamp. However we prefer "%ci" (which expands to an "ISO-8601
# -like" string, which we must then edit to make compliant), because
# it's been around since git-1.5.3, and it's too difficult to
# discover which version we're using, or to work around using an
# older one.
date = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
refnames = keywords["refnames"].strip()
if refnames.startswith("$Format"):
if verbose:
print("keywords are unexpanded, not using")
raise NotThisMethod("unexpanded keywords, not a git-archive tarball")
refs = set([r.strip() for r in refnames.strip("()").split(",")])
# starting in git-1.8.3, tags are listed as "tag: foo-1.0" instead of
# just "foo-1.0". If we see a "tag: " prefix, prefer those.
TAG = "tag: "
tags = set([r[len(TAG):] for r in refs if r.startswith(TAG)])
if not tags:
# Either we're using git < 1.8.3, or there really are no tags. We use
# a heuristic: assume all version tags have a digit. The old git %d
# expansion behaves like git log --decorate=short and strips out the
# refs/heads/ and refs/tags/ prefixes that would let us distinguish
# between branches and tags. By ignoring refnames without digits, we
# filter out many common branch names like "release" and
# "stabilization", as well as "HEAD" and "master".
tags = set([r for r in refs if re.search(r'\d', r)])
if verbose:
print("discarding '%s', no digits" % ",".join(refs - tags))
if verbose:
print("likely tags: %s" % ",".join(sorted(tags)))
for ref in sorted(tags):
# sorting will prefer e.g. "2.0" over "2.0rc1"
if ref.startswith(tag_prefix):
r = ref[len(tag_prefix):]
if verbose:
print("picking %s" % r)
return {"version": r,
"full-revisionid": keywords["full"].strip(),
"dirty": False, "error": None,
"date": date}
# no suitable tags, so version is "0+unknown", but full hex is still there
if verbose:
print("no suitable tags, using unknown + full revision id")
return {"version": "0+unknown",
"full-revisionid": keywords["full"].strip(),
"dirty": False, "error": "no suitable tags", "date": None}
@register_vcs_handler("git", "pieces_from_vcs")
def git_pieces_from_vcs(tag_prefix, root, verbose, run_command=run_command):
"""Get version from 'git describe' in the root of the source tree.
This only gets called if the git-archive 'subst' keywords were *not*
expanded, and _version.py hasn't already been rewritten with a short
version string, meaning we're inside a checked out source tree.
"""
GITS = ["git"]
if sys.platform == "win32":
GITS = ["git.cmd", "git.exe"]
out, rc = run_command(GITS, ["rev-parse", "--git-dir"], cwd=root,
hide_stderr=True)
if rc != 0:
if verbose:
print("Directory %s not under git control" % root)
raise NotThisMethod("'git rev-parse --git-dir' returned error")
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
# if there isn't one, this yields HEX[-dirty] (no NUM)
describe_out, rc = run_command(GITS, ["describe", "--tags", "--dirty",
"--always", "--long",
"--match", "%s*" % tag_prefix],
cwd=root)
# --long was added in git-1.5.5
if describe_out is None:
raise NotThisMethod("'git describe' failed")
describe_out = describe_out.strip()
full_out, rc = run_command(GITS, ["rev-parse", "HEAD"], cwd=root)
if full_out is None:
raise NotThisMethod("'git rev-parse' failed")
full_out = full_out.strip()
pieces = {}
pieces["long"] = full_out
pieces["short"] = full_out[:7] # maybe improved later
pieces["error"] = None
# parse describe_out. It will be like TAG-NUM-gHEX[-dirty] or HEX[-dirty]
# TAG might have hyphens.
git_describe = describe_out
# look for -dirty suffix
dirty = git_describe.endswith("-dirty")
pieces["dirty"] = dirty
if dirty:
git_describe = git_describe[:git_describe.rindex("-dirty")]
# now we have TAG-NUM-gHEX or HEX
if "-" in git_describe:
# TAG-NUM-gHEX
mo = re.search(r'^(.+)-(\d+)-g([0-9a-f]+)$', git_describe)
if not mo:
# unparseable. Maybe git-describe is misbehaving?
pieces["error"] = ("unable to parse git-describe output: '%s'"
% describe_out)
return pieces
# tag
full_tag = mo.group(1)
if not full_tag.startswith(tag_prefix):
if verbose:
fmt = "tag '%s' doesn't start with prefix '%s'"
print(fmt % (full_tag, tag_prefix))
pieces["error"] = ("tag '%s' doesn't start with prefix '%s'"
% (full_tag, tag_prefix))
return pieces
pieces["closest-tag"] = full_tag[len(tag_prefix):]
# distance: number of commits since tag
pieces["distance"] = int(mo.group(2))
# commit: short hex revision ID
pieces["short"] = mo.group(3)
else:
# HEX: no tags
pieces["closest-tag"] = None
count_out, rc = run_command(GITS, ["rev-list", "HEAD", "--count"],
cwd=root)
pieces["distance"] = int(count_out) # total number of commits
# commit date: see ISO-8601 comment in git_versions_from_keywords()
date = run_command(GITS, ["show", "-s", "--format=%ci", "HEAD"],
cwd=root)[0].strip()
pieces["date"] = date.strip().replace(" ", "T", 1).replace(" ", "", 1)
return pieces
def plus_or_dot(pieces):
"""Return a + if we don't already have one, else return a ."""
if "+" in pieces.get("closest-tag", ""):
return "."
return "+"
def render_pep440(pieces):
"""Build up version string, with post-release "local version identifier".
Our goal: TAG[+DISTANCE.gHEX[.dirty]] . Note that if you
get a tagged build and then dirty it, you'll get TAG+0.gHEX.dirty
Exceptions:
1: no tags. git_describe was just HEX. 0+untagged.DISTANCE.gHEX[.dirty]
"""
if pieces["closest-tag"]:
rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]:
rendered += plus_or_dot(pieces)
rendered += "%d.g%s" % (pieces["distance"], pieces["short"])
if pieces["dirty"]:
rendered += ".dirty"
else:
# exception #1
rendered = "0+untagged.%d.g%s" % (pieces["distance"],
pieces["short"])
if pieces["dirty"]:
rendered += ".dirty"
return rendered
def render_pep440_pre(pieces):
"""TAG[.post.devDISTANCE] -- No -dirty.
Exceptions:
1: no tags. 0.post.devDISTANCE
"""
if pieces["closest-tag"]:
rendered = pieces["closest-tag"]
if pieces["distance"]:
rendered += ".post.dev%d" % pieces["distance"]
else:
# exception #1
rendered = "0.post.dev%d" % pieces["distance"]
return rendered
def render_pep440_post(pieces):
"""TAG[.postDISTANCE[.dev0]+gHEX] .
The ".dev0" means dirty. Note that .dev0 sorts backwards
(a dirty tree will appear "older" than the corresponding clean one),
but you shouldn't be releasing software with -dirty anyways.
Exceptions:
1: no tags. 0.postDISTANCE[.dev0]
"""
if pieces["closest-tag"]:
rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]:
rendered += ".post%d" % pieces["distance"]
if pieces["dirty"]:
rendered += ".dev0"
rendered += plus_or_dot(pieces)
rendered += "g%s" % pieces["short"]
else:
# exception #1
rendered = "0.post%d" % pieces["distance"]
if pieces["dirty"]:
rendered += ".dev0"
rendered += "+g%s" % pieces["short"]
return rendered
def render_pep440_old(pieces):
"""TAG[.postDISTANCE[.dev0]] .
The ".dev0" means dirty.
Eexceptions:
1: no tags. 0.postDISTANCE[.dev0]
"""
if pieces["closest-tag"]:
rendered = pieces["closest-tag"]
if pieces["distance"] or pieces["dirty"]:
rendered += ".post%d" % pieces["distance"]
if pieces["dirty"]:
rendered += ".dev0"
else:
# exception #1
rendered = "0.post%d" % pieces["distance"]
if pieces["dirty"]:
rendered += ".dev0"
return rendered
def render_git_describe(pieces):
"""TAG[-DISTANCE-gHEX][-dirty].
Like 'git describe --tags --dirty --always'.
Exceptions:
1: no tags. HEX[-dirty] (note: no 'g' prefix)
"""
if pieces["closest-tag"]:
rendered = pieces["closest-tag"]
if pieces["distance"]:
rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
else:
# exception #1
rendered = pieces["short"]
if pieces["dirty"]:
rendered += "-dirty"
return rendered
def render_git_describe_long(pieces):
"""TAG-DISTANCE-gHEX[-dirty].
Like 'git describe --tags --dirty --always -long'.
The distance/hash is unconditional.
Exceptions:
1: no tags. HEX[-dirty] (note: no 'g' prefix)
"""
if pieces["closest-tag"]:
rendered = pieces["closest-tag"]
rendered += "-%d-g%s" % (pieces["distance"], pieces["short"])
else:
# exception #1
rendered = pieces["short"]
if pieces["dirty"]:
rendered += "-dirty"
return rendered
def render(pieces, style):
"""Render the given version pieces into the requested style."""
if pieces["error"]:
return {"version": "unknown",
"full-revisionid": pieces.get("long"),
"dirty": None,
"error": pieces["error"],
"date": None}
if not style or style == "default":
style = "pep440" # the default
if style == "pep440":
rendered = render_pep440(pieces)
elif style == "pep440-pre":
rendered = render_pep440_pre(pieces)
elif style == "pep440-post":
rendered = render_pep440_post(pieces)
elif style == "pep440-old":
rendered = render_pep440_old(pieces)
elif style == "git-describe":
rendered = render_git_describe(pieces)
elif style == "git-describe-long":
rendered = render_git_describe_long(pieces)
else:
raise ValueError("unknown style '%s'" % style)
return {"version": rendered, "full-revisionid": pieces["long"],
"dirty": pieces["dirty"], "error": None,
"date": pieces.get("date")}
def get_versions():
"""Get version information or return default if unable to do so."""
# I am in _version.py, which lives at ROOT/VERSIONFILE_SOURCE. If we have
# __file__, we can work backwards from there to the root. Some
# py2exe/bbfreeze/non-CPython implementations don't do __file__, in which
# case we can only use expanded keywords.
cfg = get_config()
verbose = cfg.verbose
try:
return git_versions_from_keywords(get_keywords(), cfg.tag_prefix,
verbose)
except NotThisMethod:
pass
try:
root = os.path.realpath(__file__)
# versionfile_source is the relative path from the top of the source
# tree (where the .git directory might live) to this file. Invert
# this to find the root from __file__.
for i in cfg.versionfile_source.split('/'):
root = os.path.dirname(root)
except NameError:
return {"version": "0+unknown", "full-revisionid": None,
"dirty": None,
"error": "unable to find root of source tree",
"date": None}
try:
pieces = git_pieces_from_vcs(cfg.tag_prefix, root, verbose)
return render(pieces, cfg.style)
except NotThisMethod:
pass
try:
if cfg.parentdir_prefix:
return versions_from_parentdir(cfg.parentdir_prefix, root, verbose)
except NotThisMethod:
pass
return {"version": "0+unknown", "full-revisionid": None,
"dirty": None,
"error": "unable to compute version", "date": None}
|
isc
|
[
199,
3,
961,
570,
22577,
370,
4526,
282,
1015,
1329,
315,
1350,
14416,
15884,
687,
199,
3,
6135,
13,
6404,
17641,
334,
10180,
465,
5204,
2741,
701,
12869,
83,
5235,
13,
504,
13,
1450,
199,
3,
3878,
680,
11839,
17641,
83,
334,
11730,
701,
3272,
14,
647,
26644,
9,
436,
1900,
199,
3,
6602,
334,
7832,
68,
701,
3272,
14,
647,
1900,
9,
911,
1395,
282,
8298,
18299,
570,
199,
3,
626,
2951,
3509,
314,
9235,
1015,
1329,
14,
199,
199,
3,
961,
570,
365,
14286,
1901,
314,
4575,
2881,
14,
17065,
701,
199,
3,
809,
19106,
13,
16,
14,
1085,
334,
2859,
921,
5031,
14,
957,
15,
4050,
281,
15,
1548,
13,
27550,
9,
199,
199,
624,
14686,
4514,
402,
485,
1023,
14,
647,
1041,
199,
199,
646,
7554,
199,
646,
747,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
421,
199,
318,
664,
63,
7511,
837,
272,
408,
1002,
314,
7681,
4346,
370,
3648,
1536,
314,
1015,
2556,
1041,
272,
327,
3520,
3326,
911,
506,
8717,
701,
6135,
5309,
6135,
13,
6404,
14,
272,
327,
3272,
14,
647,
15,
27550,
14,
647,
911,
20595,
367,
314,
1750,
1561,
12,
880,
2985,
1471,
272,
327,
1924,
506,
3247,
641,
282,
1004,
402,
3932,
5705,
14,
485,
1023,
14,
647,
911,
2951,
1240,
272,
327,
664,
63,
7511,
1252,
272,
6135,
63,
1121,
1247,
275,
7880,
3484,
2689,
68,
17351,
272,
6135,
63,
2861,
275,
7880,
3484,
2689,
40,
17351,
272,
6135,
63,
602,
275,
7880,
3484,
2689,
559,
17351,
272,
7681,
275,
2420,
1121,
1247,
582,
6135,
63,
1121,
1247,
12,
298,
2861,
582,
6135,
63,
2861,
12,
298,
602,
582,
6135,
63,
602,
93,
272,
372,
7681,
421,
199,
533,
5444,
19106,
2028,
26,
272,
408,
4076,
367,
5444,
19106,
2897,
2633,
1041,
421,
199,
318,
664,
63,
888,
837,
272,
408,
2499,
12,
13904,
436,
372,
314,
5444,
19106,
2028,
342,
909,
1041,
272,
327,
3520,
3326,
787,
13457,
315,
1380,
283,
2758,
14,
647,
809,
19106,
7,
8491,
272,
327,
485,
1023,
14,
647,
272,
4810,
275,
5444,
19106,
2028,
342,
272,
4810,
14,
24379,
275,
298,
3187,
2,
272,
4810,
14,
2487,
275,
298,
12636,
14162,
2,
272,
4810,
14,
1450,
63,
1861,
275,
298,
86,
2,
272,
4810,
14,
1708,
694,
63,
1861,
275,
298,
403,
2,
272,
4810,
14,
30134,
63,
1365,
275,
298,
357,
351,
15607,
1023,
14,
647,
2,
272,
4810,
14,
3832,
275,
756,
272,
372,
4810,
421,
199,
533,
2832,
2765,
3767,
8,
1726,
304,
272,
408,
1726,
4915,
340,
282,
1083,
365,
440,
1686,
367,
314,
1453,
15728,
1041,
421,
199,
12375,
63,
4612,
63,
4521,
275,
1052,
199,
10854,
28778,
275,
1052,
421,
199,
318,
2274,
63,
15525,
63,
2232,
8,
15525,
12,
1083,
304,
221,
327,
7531,
272,
408,
14946,
370,
2216,
282,
1083,
465,
314,
3016,
367,
282,
6770,
23563,
1041,
272,
347,
24774,
8,
70,
304,
267,
408,
5502,
289,
315,
23276,
28778,
59,
15525,
1527,
765,
61,
1041,
267,
340,
19827,
440,
315,
23276,
28778,
26,
288,
23276,
28778,
59,
15525,
61,
275,
1052,
267,
23276,
28778,
59,
15525,
1527,
765,
61,
275,
289,
267,
372,
289,
272,
372,
24774,
421,
199,
318,
1255,
63,
1531,
8,
4405,
12,
1249,
12,
8288,
29,
403,
12,
3376,
29,
797,
12,
13714,
63,
3083,
29,
797,
12,
355,
2589,
29,
403,
304,
272,
408,
2176,
314,
1627,
1414,
8,
83,
10477,
272,
702,
1228,
8,
4405,
12,
769,
9,
272,
299,
275,
488,
272,
367,
286,
315,
3718,
26,
267,
862,
26,
288,
9628,
1760,
275,
620,
779,
67,
61,
435,
1249,
9,
288,
327,
21027,
5218,
29,
797,
12,
880,
675,
6135,
14,
1760,
641,
10061,
12,
440,
2951,
6135,
288,
299,
275,
3873,
14,
7942,
779,
67,
61,
435,
1249,
12,
8288,
29,
6525,
12,
2589,
29,
1813,
12,
639,
3839,
29,
5781,
14,
6089,
12,
639,
4635,
2687,
5781,
14,
6089,
340,
13714,
63,
3083,
1460,
587,
488,
430,
288,
2059,
267,
871,
25139,
26,
288,
325,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
340,
325,
14,
7931,
508,
7554,
14,
20465,
26,
355,
1980,
288,
340,
3376,
26,
355,
870,
480,
17200,
370,
1255,
450,
83,
2,
450,
9628,
1760,
9,
355,
870,
8,
69,
9,
288,
372,
488,
12,
488,
272,
587,
26,
267,
340,
3376,
26,
288,
870,
480,
17200,
370,
2342,
1414,
12,
16416,
450,
83,
2,
450,
334,
4405,
4641,
267,
372,
488,
12,
488,
272,
3839,
275,
299,
14,
10664,
3430,
16,
1055,
1913,
342,
272,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
26,
267,
3839,
275,
3839,
14,
2708,
342,
272,
340,
299,
14,
9913,
1137,
378,
26,
267,
340,
3376,
26,
288,
870,
480,
17200,
370,
1255,
450,
83,
334,
705,
2924,
450,
9628,
1760,
9,
288,
870,
480,
2703,
1990,
450,
83,
2,
450,
3839,
9,
267,
372,
488,
12,
299,
14,
9913,
272,
372,
3839,
12,
299,
14,
9913,
421,
199,
318,
5459,
63,
504,
63,
1708,
694,
8,
1708,
694,
63,
1861,
12,
1738,
12,
3376,
304,
272,
408,
12357,
370,
6705,
314,
1015,
687,
314,
1676,
2082,
536,
14,
339,
5800,
17641,
83,
16129,
1183,
7787,
1901,
282,
2082,
626,
6952,
3865,
272,
314,
2199,
536,
436,
282,
1015,
1059,
14,
2136,
911,
2597,
2291,
18112,
1536,
272,
2877,
2082,
11106,
367,
376,
22497,
4310,
1676,
2082,
272,
408,
272,
1738,
3220,
275,
942,
339,
367,
284,
315,
1425,
8,
19,
304,
267,
9017,
275,
747,
14,
515,
14,
4846,
8,
1231,
9,
267,
340,
9017,
14,
2460,
8,
1708,
694,
63,
1861,
304,
288,
372,
2420,
1023,
582,
9017,
59,
552,
8,
1708,
694,
63,
1861,
304,
467,
490,
298,
2861,
13,
5792,
344,
582,
488,
12,
490,
298,
8799,
582,
756,
12,
298,
705,
582,
488,
12,
298,
602,
582,
488,
93,
267,
587,
26,
288,
1738,
3220,
14,
740,
8,
1231,
9,
288,
1738,
275,
747,
14,
515,
14,
3475,
8,
1231,
9,
221,
327,
1536,
282,
2166,
339,
340,
3376,
26,
267,
870,
480,
6948,
379,
6602,
450,
83,
1325,
7179,
8239,
543,
2403,
450,
83,
2,
450,
1598,
334,
495,
8
] |
[
3,
961,
570,
22577,
370,
4526,
282,
1015,
1329,
315,
1350,
14416,
15884,
687,
199,
3,
6135,
13,
6404,
17641,
334,
10180,
465,
5204,
2741,
701,
12869,
83,
5235,
13,
504,
13,
1450,
199,
3,
3878,
680,
11839,
17641,
83,
334,
11730,
701,
3272,
14,
647,
26644,
9,
436,
1900,
199,
3,
6602,
334,
7832,
68,
701,
3272,
14,
647,
1900,
9,
911,
1395,
282,
8298,
18299,
570,
199,
3,
626,
2951,
3509,
314,
9235,
1015,
1329,
14,
199,
199,
3,
961,
570,
365,
14286,
1901,
314,
4575,
2881,
14,
17065,
701,
199,
3,
809,
19106,
13,
16,
14,
1085,
334,
2859,
921,
5031,
14,
957,
15,
4050,
281,
15,
1548,
13,
27550,
9,
199,
199,
624,
14686,
4514,
402,
485,
1023,
14,
647,
1041,
199,
199,
646,
7554,
199,
646,
747,
199,
646,
295,
199,
646,
3873,
199,
646,
984,
421,
199,
318,
664,
63,
7511,
837,
272,
408,
1002,
314,
7681,
4346,
370,
3648,
1536,
314,
1015,
2556,
1041,
272,
327,
3520,
3326,
911,
506,
8717,
701,
6135,
5309,
6135,
13,
6404,
14,
272,
327,
3272,
14,
647,
15,
27550,
14,
647,
911,
20595,
367,
314,
1750,
1561,
12,
880,
2985,
1471,
272,
327,
1924,
506,
3247,
641,
282,
1004,
402,
3932,
5705,
14,
485,
1023,
14,
647,
911,
2951,
1240,
272,
327,
664,
63,
7511,
1252,
272,
6135,
63,
1121,
1247,
275,
7880,
3484,
2689,
68,
17351,
272,
6135,
63,
2861,
275,
7880,
3484,
2689,
40,
17351,
272,
6135,
63,
602,
275,
7880,
3484,
2689,
559,
17351,
272,
7681,
275,
2420,
1121,
1247,
582,
6135,
63,
1121,
1247,
12,
298,
2861,
582,
6135,
63,
2861,
12,
298,
602,
582,
6135,
63,
602,
93,
272,
372,
7681,
421,
199,
533,
5444,
19106,
2028,
26,
272,
408,
4076,
367,
5444,
19106,
2897,
2633,
1041,
421,
199,
318,
664,
63,
888,
837,
272,
408,
2499,
12,
13904,
436,
372,
314,
5444,
19106,
2028,
342,
909,
1041,
272,
327,
3520,
3326,
787,
13457,
315,
1380,
283,
2758,
14,
647,
809,
19106,
7,
8491,
272,
327,
485,
1023,
14,
647,
272,
4810,
275,
5444,
19106,
2028,
342,
272,
4810,
14,
24379,
275,
298,
3187,
2,
272,
4810,
14,
2487,
275,
298,
12636,
14162,
2,
272,
4810,
14,
1450,
63,
1861,
275,
298,
86,
2,
272,
4810,
14,
1708,
694,
63,
1861,
275,
298,
403,
2,
272,
4810,
14,
30134,
63,
1365,
275,
298,
357,
351,
15607,
1023,
14,
647,
2,
272,
4810,
14,
3832,
275,
756,
272,
372,
4810,
421,
199,
533,
2832,
2765,
3767,
8,
1726,
304,
272,
408,
1726,
4915,
340,
282,
1083,
365,
440,
1686,
367,
314,
1453,
15728,
1041,
421,
199,
12375,
63,
4612,
63,
4521,
275,
1052,
199,
10854,
28778,
275,
1052,
421,
199,
318,
2274,
63,
15525,
63,
2232,
8,
15525,
12,
1083,
304,
221,
327,
7531,
272,
408,
14946,
370,
2216,
282,
1083,
465,
314,
3016,
367,
282,
6770,
23563,
1041,
272,
347,
24774,
8,
70,
304,
267,
408,
5502,
289,
315,
23276,
28778,
59,
15525,
1527,
765,
61,
1041,
267,
340,
19827,
440,
315,
23276,
28778,
26,
288,
23276,
28778,
59,
15525,
61,
275,
1052,
267,
23276,
28778,
59,
15525,
1527,
765,
61,
275,
289,
267,
372,
289,
272,
372,
24774,
421,
199,
318,
1255,
63,
1531,
8,
4405,
12,
1249,
12,
8288,
29,
403,
12,
3376,
29,
797,
12,
13714,
63,
3083,
29,
797,
12,
355,
2589,
29,
403,
304,
272,
408,
2176,
314,
1627,
1414,
8,
83,
10477,
272,
702,
1228,
8,
4405,
12,
769,
9,
272,
299,
275,
488,
272,
367,
286,
315,
3718,
26,
267,
862,
26,
288,
9628,
1760,
275,
620,
779,
67,
61,
435,
1249,
9,
288,
327,
21027,
5218,
29,
797,
12,
880,
675,
6135,
14,
1760,
641,
10061,
12,
440,
2951,
6135,
288,
299,
275,
3873,
14,
7942,
779,
67,
61,
435,
1249,
12,
8288,
29,
6525,
12,
2589,
29,
1813,
12,
639,
3839,
29,
5781,
14,
6089,
12,
639,
4635,
2687,
5781,
14,
6089,
340,
13714,
63,
3083,
1460,
587,
488,
430,
288,
2059,
267,
871,
25139,
26,
288,
325,
275,
984,
14,
2804,
63,
815,
3430,
17,
61,
288,
340,
325,
14,
7931,
508,
7554,
14,
20465,
26,
355,
1980,
288,
340,
3376,
26,
355,
870,
480,
17200,
370,
1255,
450,
83,
2,
450,
9628,
1760,
9,
355,
870,
8,
69,
9,
288,
372,
488,
12,
488,
272,
587,
26,
267,
340,
3376,
26,
288,
870,
480,
17200,
370,
2342,
1414,
12,
16416,
450,
83,
2,
450,
334,
4405,
4641,
267,
372,
488,
12,
488,
272,
3839,
275,
299,
14,
10664,
3430,
16,
1055,
1913,
342,
272,
340,
984,
14,
1023,
63,
815,
59,
16,
61,
2356,
650,
26,
267,
3839,
275,
3839,
14,
2708,
342,
272,
340,
299,
14,
9913,
1137,
378,
26,
267,
340,
3376,
26,
288,
870,
480,
17200,
370,
1255,
450,
83,
334,
705,
2924,
450,
9628,
1760,
9,
288,
870,
480,
2703,
1990,
450,
83,
2,
450,
3839,
9,
267,
372,
488,
12,
299,
14,
9913,
272,
372,
3839,
12,
299,
14,
9913,
421,
199,
318,
5459,
63,
504,
63,
1708,
694,
8,
1708,
694,
63,
1861,
12,
1738,
12,
3376,
304,
272,
408,
12357,
370,
6705,
314,
1015,
687,
314,
1676,
2082,
536,
14,
339,
5800,
17641,
83,
16129,
1183,
7787,
1901,
282,
2082,
626,
6952,
3865,
272,
314,
2199,
536,
436,
282,
1015,
1059,
14,
2136,
911,
2597,
2291,
18112,
1536,
272,
2877,
2082,
11106,
367,
376,
22497,
4310,
1676,
2082,
272,
408,
272,
1738,
3220,
275,
942,
339,
367,
284,
315,
1425,
8,
19,
304,
267,
9017,
275,
747,
14,
515,
14,
4846,
8,
1231,
9,
267,
340,
9017,
14,
2460,
8,
1708,
694,
63,
1861,
304,
288,
372,
2420,
1023,
582,
9017,
59,
552,
8,
1708,
694,
63,
1861,
304,
467,
490,
298,
2861,
13,
5792,
344,
582,
488,
12,
490,
298,
8799,
582,
756,
12,
298,
705,
582,
488,
12,
298,
602,
582,
488,
93,
267,
587,
26,
288,
1738,
3220,
14,
740,
8,
1231,
9,
288,
1738,
275,
747,
14,
515,
14,
3475,
8,
1231,
9,
221,
327,
1536,
282,
2166,
339,
340,
3376,
26,
267,
870,
480,
6948,
379,
6602,
450,
83,
1325,
7179,
8239,
543,
2403,
450,
83,
2,
450,
1598,
334,
495,
8,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
varunagrawal/azure-services
|
varunagrawal/VarunWeb/env/Lib/site-packages/setuptools/command/test.py
|
285
|
5932
|
from setuptools import Command
from distutils.errors import DistutilsOptionError
import sys
from pkg_resources import *
from pkg_resources import _namespace_packages
from unittest import TestLoader, main
class ScanningLoader(TestLoader):
def loadTestsFromModule(self, module):
"""Return a suite of all tests cases contained in the given module
If the module is a package, load tests from all the modules in it.
If the module has an ``additional_tests`` function, call it and add
the return value to the tests.
"""
tests = []
if module.__name__!='setuptools.tests.doctest': # ugh
tests.append(TestLoader.loadTestsFromModule(self,module))
if hasattr(module, "additional_tests"):
tests.append(module.additional_tests())
if hasattr(module, '__path__'):
for file in resource_listdir(module.__name__, ''):
if file.endswith('.py') and file!='__init__.py':
submodule = module.__name__+'.'+file[:-3]
else:
if resource_exists(
module.__name__, file+'/__init__.py'
):
submodule = module.__name__+'.'+file
else:
continue
tests.append(self.loadTestsFromName(submodule))
if len(tests)!=1:
return self.suiteClass(tests)
else:
return tests[0] # don't create a nested suite for only one return
class test(Command):
"""Command to run unit tests after in-place build"""
description = "run unit tests after in-place build"
user_options = [
('test-module=','m', "Run 'test_suite' in specified module"),
('test-suite=','s',
"Test suite to run (e.g. 'some_module.test_suite')"),
]
def initialize_options(self):
self.test_suite = None
self.test_module = None
self.test_loader = None
def finalize_options(self):
if self.test_suite is None:
if self.test_module is None:
self.test_suite = self.distribution.test_suite
else:
self.test_suite = self.test_module+".test_suite"
elif self.test_module:
raise DistutilsOptionError(
"You may specify a module or a suite, but not both"
)
self.test_args = [self.test_suite]
if self.verbose:
self.test_args.insert(0,'--verbose')
if self.test_loader is None:
self.test_loader = getattr(self.distribution,'test_loader',None)
if self.test_loader is None:
self.test_loader = "setuptools.command.test:ScanningLoader"
def with_project_on_sys_path(self, func):
if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False):
# If we run 2to3 we can not do this inplace:
# Ensure metadata is up-to-date
self.reinitialize_command('build_py', inplace=0)
self.run_command('build_py')
bpy_cmd = self.get_finalized_command("build_py")
build_path = normalize_path(bpy_cmd.build_lib)
# Build extensions
self.reinitialize_command('egg_info', egg_base=build_path)
self.run_command('egg_info')
self.reinitialize_command('build_ext', inplace=0)
self.run_command('build_ext')
else:
# Without 2to3 inplace works fine:
self.run_command('egg_info')
# Build extensions in-place
self.reinitialize_command('build_ext', inplace=1)
self.run_command('build_ext')
ei_cmd = self.get_finalized_command("egg_info")
old_path = sys.path[:]
old_modules = sys.modules.copy()
try:
sys.path.insert(0, normalize_path(ei_cmd.egg_base))
working_set.__init__()
add_activation_listener(lambda dist: dist.activate())
require('%s==%s' % (ei_cmd.egg_name, ei_cmd.egg_version))
func()
finally:
sys.path[:] = old_path
sys.modules.clear()
sys.modules.update(old_modules)
working_set.__init__()
def run(self):
if self.distribution.install_requires:
self.distribution.fetch_build_eggs(self.distribution.install_requires)
if self.distribution.tests_require:
self.distribution.fetch_build_eggs(self.distribution.tests_require)
if self.test_suite:
cmd = ' '.join(self.test_args)
if self.dry_run:
self.announce('skipping "unittest %s" (dry run)' % cmd)
else:
self.announce('running "unittest %s"' % cmd)
self.with_project_on_sys_path(self.run_tests)
def run_tests(self):
import unittest
# Purge modules under test from sys.modules. The test loader will
# re-import them from the build location. Required when 2to3 is used
# with namespace packages.
if sys.version_info >= (3,) and getattr(self.distribution, 'use_2to3', False):
module = self.test_args[-1].split('.')[0]
if module in _namespace_packages:
del_modules = []
if module in sys.modules:
del_modules.append(module)
module += '.'
for name in sys.modules:
if name.startswith(module):
del_modules.append(name)
list(map(sys.modules.__delitem__, del_modules))
loader_ep = EntryPoint.parse("x="+self.test_loader)
loader_class = loader_ep.load(require=False)
cks = loader_class()
unittest.main(
None, None, [unittest.__file__]+self.test_args,
testLoader = cks
)
|
gpl-2.0
|
[
504,
9116,
492,
5817,
199,
504,
7065,
14,
2550,
492,
31484,
199,
646,
984,
199,
504,
5496,
63,
4435,
492,
627,
199,
504,
5496,
63,
4435,
492,
485,
3251,
63,
5154,
199,
504,
2882,
492,
1379,
5455,
12,
2446,
199,
199,
533,
13916,
11495,
5455,
8,
15824,
304,
339,
347,
2248,
11519,
2377,
8,
277,
12,
859,
304,
267,
408,
1767,
282,
5241,
402,
1006,
2295,
5560,
10470,
315,
314,
1627,
859,
398,
982,
314,
859,
365,
282,
2559,
12,
2248,
2295,
687,
1006,
314,
4621,
315,
652,
14,
267,
982,
314,
859,
965,
376,
1124,
8460,
63,
2219,
1040,
805,
12,
1240,
652,
436,
1050,
267,
314,
372,
574,
370,
314,
2295,
14,
267,
408,
267,
2295,
275,
942,
267,
340,
859,
855,
354,
363,
27909,
13623,
14,
2219,
14,
11390,
356,
221,
327,
399,
3561,
288,
2295,
14,
740,
8,
15824,
14,
12861,
2377,
8,
277,
12,
578,
430,
398,
340,
2688,
8,
578,
12,
298,
8460,
63,
2219,
2349,
288,
2295,
14,
740,
8,
578,
14,
8460,
63,
2219,
1012,
398,
340,
2688,
8,
578,
12,
2560,
515,
12168,
288,
367,
570,
315,
2073,
63,
7374,
8,
578,
855,
354,
3108,
21019,
355,
340,
570,
14,
4130,
5175,
647,
358,
436,
570,
27909,
363,
826,
4343,
647,
356,
490,
22988,
275,
859,
855,
354,
363,
18098,
6828,
493,
4439,
19,
61,
355,
587,
26,
490,
340,
2073,
63,
2444,
8,
717,
859,
855,
354,
3108,
570,
4786,
22128,
826,
4343,
647,
7,
490,
3461,
717,
22988,
275,
859,
855,
354,
363,
18098,
6828,
493,
490,
587,
26,
717,
1980,
355,
2295,
14,
740,
8,
277,
14,
25998,
8,
16229,
430,
398,
340,
822,
8,
2219,
9,
1111,
17,
26,
288,
372,
291,
14,
27216,
8,
2219,
9,
267,
587,
26,
288,
372,
2295,
59,
16,
61,
327,
2793,
1133,
1218,
282,
6032,
5241,
367,
1454,
1373,
372,
421,
199,
533,
511,
8,
3110,
304,
339,
408,
3110,
370,
1255,
4137,
2295,
2410,
315,
13,
2778,
1900,
624,
339,
1369,
275,
298,
1065,
4137,
2295,
2410,
315,
13,
2778,
1900,
2,
339,
922,
63,
1419,
275,
359,
267,
661,
396,
13,
578,
29511,
77,
297,
298,
2540,
283,
396,
63,
5768,
7,
315,
2013,
859,
1288,
267,
661,
396,
13,
5768,
29511,
83,
297,
288,
298,
774,
5241,
370,
1255,
334,
69,
14,
71,
14,
283,
3972,
63,
578,
14,
396,
63,
5768,
358,
1288,
272,
1622,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
291,
14,
396,
63,
5768,
275,
488,
267,
291,
14,
396,
63,
578,
275,
488,
267,
291,
14,
396,
63,
3422,
275,
488,
2378,
347,
17284,
63,
1419,
8,
277,
304,
398,
340,
291,
14,
396,
63,
5768,
365,
488,
26,
288,
340,
291,
14,
396,
63,
578,
365,
488,
26,
355,
291,
14,
396,
63,
5768,
275,
291,
14,
4972,
14,
396,
63,
5768,
288,
587,
26,
355,
291,
14,
396,
63,
5768,
275,
291,
14,
396,
63,
578,
24878,
396,
63,
5768,
2,
267,
916,
291,
14,
396,
63,
578,
26,
288,
746,
31484,
8,
355,
298,
5556,
1443,
4165,
282,
859,
503,
282,
5241,
12,
1325,
440,
3865,
2,
288,
776,
398,
291,
14,
396,
63,
589,
275,
359,
277,
14,
396,
63,
5768,
61,
398,
340,
291,
14,
3832,
26,
288,
291,
14,
396,
63,
589,
14,
3176,
8,
16,
2584,
306,
3832,
358,
267,
340,
291,
14,
396,
63,
3422,
365,
488,
26,
288,
291,
14,
396,
63,
3422,
275,
2519,
8,
277,
14,
4972,
2584,
396,
63,
3422,
297,
403,
9,
267,
340,
291,
14,
396,
63,
3422,
365,
488,
26,
288,
291,
14,
396,
63,
3422,
275,
298,
13623,
14,
1531,
14,
396,
26,
7181,
11495,
5455,
2,
16478,
347,
543,
63,
1715,
63,
265,
63,
1274,
63,
515,
8,
277,
12,
2562,
304,
267,
340,
984,
14,
1023,
63,
815,
2356,
334,
19,
4258,
436,
2519,
8,
277,
14,
4972,
12,
283,
1180,
63,
18,
475,
19,
297,
756,
304,
288,
327,
982,
781,
1255,
499,
475,
19,
781,
883,
440,
886,
642,
16304,
26,
953,
327,
7523,
3341,
365,
1536,
13,
475,
13,
602,
288,
291,
14,
264,
8489,
63,
1531,
360,
1506,
63,
647,
297,
16304,
29,
16,
9,
288,
291,
14,
1065,
63,
1531,
360,
1506,
63,
647,
358,
288,
20575,
63,
1760,
275,
291,
14,
362,
63,
19231,
63,
1531,
480,
1506,
63,
647,
531,
288,
1900,
63,
515,
275,
7666,
63,
515,
8,
66,
647,
63,
1760,
14,
1506,
63,
773,
9,
953,
327,
6516,
5478,
288,
291,
14,
264,
8489,
63,
1531,
360,
5799,
63,
815,
297,
11393,
63,
1095,
29,
1506,
63,
515,
9,
288,
291,
14,
1065,
63,
1531,
360,
5799,
63,
815,
358,
953,
291,
14,
264,
8489,
63,
1531,
360,
1506,
63,
832,
297,
16304,
29,
16,
9,
288,
291,
14,
1065,
63,
1531,
360,
1506,
63,
832,
358,
267,
587,
26,
288,
327,
23952,
499,
475,
19,
16304,
5419,
15701,
26,
288,
291,
14,
1065,
63,
1531,
360,
5799,
63,
815,
358,
953,
327,
6516,
5478,
315,
13,
2778,
288,
291,
14,
264,
8489,
63,
1531,
360,
1506,
63,
832,
297,
16304,
29,
17,
9,
288,
291,
14,
1065,
63,
1531,
360,
1506,
63,
832,
358,
398,
20654,
63,
1760,
275,
291,
14,
362,
63,
19231,
63,
1531,
480,
5799,
63,
815,
531,
398,
2269,
63,
515,
275,
984,
14,
515,
5873,
267,
2269,
63,
3112,
275,
984,
14,
3112,
14,
1574,
342,
398,
862,
26,
288,
984,
14,
515,
14,
3176,
8,
16,
12,
7666,
63,
515,
8,
24708,
63,
1760,
14,
5799,
63,
1095,
430,
288,
6449,
63,
409,
855,
826,
4533,
288,
1050,
63,
12312,
63,
9799,
8,
2734,
2917,
26,
2917,
14,
8222,
1012,
288,
4409,
3508,
83,
389,
5,
83,
7,
450,
334,
24708,
63,
1760,
14,
5799,
63,
354,
12,
20654,
63,
1760,
14,
5799,
63,
1023,
430,
288,
2562,
342,
267,
3753,
26,
288,
984,
14,
515,
5873,
275,
2269,
63,
515,
288,
984,
14,
3112,
14,
3584,
342,
288,
984,
14,
3112,
14,
873,
8,
1753,
63,
3112,
9,
288,
6449,
63,
409,
855,
826,
4533,
2378,
347,
1255,
8,
277,
304,
267,
340,
291,
14,
4972,
14,
3174
] |
[
9116,
492,
5817,
199,
504,
7065,
14,
2550,
492,
31484,
199,
646,
984,
199,
504,
5496,
63,
4435,
492,
627,
199,
504,
5496,
63,
4435,
492,
485,
3251,
63,
5154,
199,
504,
2882,
492,
1379,
5455,
12,
2446,
199,
199,
533,
13916,
11495,
5455,
8,
15824,
304,
339,
347,
2248,
11519,
2377,
8,
277,
12,
859,
304,
267,
408,
1767,
282,
5241,
402,
1006,
2295,
5560,
10470,
315,
314,
1627,
859,
398,
982,
314,
859,
365,
282,
2559,
12,
2248,
2295,
687,
1006,
314,
4621,
315,
652,
14,
267,
982,
314,
859,
965,
376,
1124,
8460,
63,
2219,
1040,
805,
12,
1240,
652,
436,
1050,
267,
314,
372,
574,
370,
314,
2295,
14,
267,
408,
267,
2295,
275,
942,
267,
340,
859,
855,
354,
363,
27909,
13623,
14,
2219,
14,
11390,
356,
221,
327,
399,
3561,
288,
2295,
14,
740,
8,
15824,
14,
12861,
2377,
8,
277,
12,
578,
430,
398,
340,
2688,
8,
578,
12,
298,
8460,
63,
2219,
2349,
288,
2295,
14,
740,
8,
578,
14,
8460,
63,
2219,
1012,
398,
340,
2688,
8,
578,
12,
2560,
515,
12168,
288,
367,
570,
315,
2073,
63,
7374,
8,
578,
855,
354,
3108,
21019,
355,
340,
570,
14,
4130,
5175,
647,
358,
436,
570,
27909,
363,
826,
4343,
647,
356,
490,
22988,
275,
859,
855,
354,
363,
18098,
6828,
493,
4439,
19,
61,
355,
587,
26,
490,
340,
2073,
63,
2444,
8,
717,
859,
855,
354,
3108,
570,
4786,
22128,
826,
4343,
647,
7,
490,
3461,
717,
22988,
275,
859,
855,
354,
363,
18098,
6828,
493,
490,
587,
26,
717,
1980,
355,
2295,
14,
740,
8,
277,
14,
25998,
8,
16229,
430,
398,
340,
822,
8,
2219,
9,
1111,
17,
26,
288,
372,
291,
14,
27216,
8,
2219,
9,
267,
587,
26,
288,
372,
2295,
59,
16,
61,
327,
2793,
1133,
1218,
282,
6032,
5241,
367,
1454,
1373,
372,
421,
199,
533,
511,
8,
3110,
304,
339,
408,
3110,
370,
1255,
4137,
2295,
2410,
315,
13,
2778,
1900,
624,
339,
1369,
275,
298,
1065,
4137,
2295,
2410,
315,
13,
2778,
1900,
2,
339,
922,
63,
1419,
275,
359,
267,
661,
396,
13,
578,
29511,
77,
297,
298,
2540,
283,
396,
63,
5768,
7,
315,
2013,
859,
1288,
267,
661,
396,
13,
5768,
29511,
83,
297,
288,
298,
774,
5241,
370,
1255,
334,
69,
14,
71,
14,
283,
3972,
63,
578,
14,
396,
63,
5768,
358,
1288,
272,
1622,
339,
347,
8265,
63,
1419,
8,
277,
304,
267,
291,
14,
396,
63,
5768,
275,
488,
267,
291,
14,
396,
63,
578,
275,
488,
267,
291,
14,
396,
63,
3422,
275,
488,
2378,
347,
17284,
63,
1419,
8,
277,
304,
398,
340,
291,
14,
396,
63,
5768,
365,
488,
26,
288,
340,
291,
14,
396,
63,
578,
365,
488,
26,
355,
291,
14,
396,
63,
5768,
275,
291,
14,
4972,
14,
396,
63,
5768,
288,
587,
26,
355,
291,
14,
396,
63,
5768,
275,
291,
14,
396,
63,
578,
24878,
396,
63,
5768,
2,
267,
916,
291,
14,
396,
63,
578,
26,
288,
746,
31484,
8,
355,
298,
5556,
1443,
4165,
282,
859,
503,
282,
5241,
12,
1325,
440,
3865,
2,
288,
776,
398,
291,
14,
396,
63,
589,
275,
359,
277,
14,
396,
63,
5768,
61,
398,
340,
291,
14,
3832,
26,
288,
291,
14,
396,
63,
589,
14,
3176,
8,
16,
2584,
306,
3832,
358,
267,
340,
291,
14,
396,
63,
3422,
365,
488,
26,
288,
291,
14,
396,
63,
3422,
275,
2519,
8,
277,
14,
4972,
2584,
396,
63,
3422,
297,
403,
9,
267,
340,
291,
14,
396,
63,
3422,
365,
488,
26,
288,
291,
14,
396,
63,
3422,
275,
298,
13623,
14,
1531,
14,
396,
26,
7181,
11495,
5455,
2,
16478,
347,
543,
63,
1715,
63,
265,
63,
1274,
63,
515,
8,
277,
12,
2562,
304,
267,
340,
984,
14,
1023,
63,
815,
2356,
334,
19,
4258,
436,
2519,
8,
277,
14,
4972,
12,
283,
1180,
63,
18,
475,
19,
297,
756,
304,
288,
327,
982,
781,
1255,
499,
475,
19,
781,
883,
440,
886,
642,
16304,
26,
953,
327,
7523,
3341,
365,
1536,
13,
475,
13,
602,
288,
291,
14,
264,
8489,
63,
1531,
360,
1506,
63,
647,
297,
16304,
29,
16,
9,
288,
291,
14,
1065,
63,
1531,
360,
1506,
63,
647,
358,
288,
20575,
63,
1760,
275,
291,
14,
362,
63,
19231,
63,
1531,
480,
1506,
63,
647,
531,
288,
1900,
63,
515,
275,
7666,
63,
515,
8,
66,
647,
63,
1760,
14,
1506,
63,
773,
9,
953,
327,
6516,
5478,
288,
291,
14,
264,
8489,
63,
1531,
360,
5799,
63,
815,
297,
11393,
63,
1095,
29,
1506,
63,
515,
9,
288,
291,
14,
1065,
63,
1531,
360,
5799,
63,
815,
358,
953,
291,
14,
264,
8489,
63,
1531,
360,
1506,
63,
832,
297,
16304,
29,
16,
9,
288,
291,
14,
1065,
63,
1531,
360,
1506,
63,
832,
358,
267,
587,
26,
288,
327,
23952,
499,
475,
19,
16304,
5419,
15701,
26,
288,
291,
14,
1065,
63,
1531,
360,
5799,
63,
815,
358,
953,
327,
6516,
5478,
315,
13,
2778,
288,
291,
14,
264,
8489,
63,
1531,
360,
1506,
63,
832,
297,
16304,
29,
17,
9,
288,
291,
14,
1065,
63,
1531,
360,
1506,
63,
832,
358,
398,
20654,
63,
1760,
275,
291,
14,
362,
63,
19231,
63,
1531,
480,
5799,
63,
815,
531,
398,
2269,
63,
515,
275,
984,
14,
515,
5873,
267,
2269,
63,
3112,
275,
984,
14,
3112,
14,
1574,
342,
398,
862,
26,
288,
984,
14,
515,
14,
3176,
8,
16,
12,
7666,
63,
515,
8,
24708,
63,
1760,
14,
5799,
63,
1095,
430,
288,
6449,
63,
409,
855,
826,
4533,
288,
1050,
63,
12312,
63,
9799,
8,
2734,
2917,
26,
2917,
14,
8222,
1012,
288,
4409,
3508,
83,
389,
5,
83,
7,
450,
334,
24708,
63,
1760,
14,
5799,
63,
354,
12,
20654,
63,
1760,
14,
5799,
63,
1023,
430,
288,
2562,
342,
267,
3753,
26,
288,
984,
14,
515,
5873,
275,
2269,
63,
515,
288,
984,
14,
3112,
14,
3584,
342,
288,
984,
14,
3112,
14,
873,
8,
1753,
63,
3112,
9,
288,
6449,
63,
409,
855,
826,
4533,
2378,
347,
1255,
8,
277,
304,
267,
340,
291,
14,
4972,
14,
3174,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sallaire/Sick-Beard
|
sickbeard/notifiers/nma.py
|
45
|
2072
|
import sickbeard
from sickbeard import logger, common
from lib.pynma import pynma
class NMA_Notifier:
def test_notify(self, nma_api, nma_priority):
return self._sendNMA(nma_api, nma_priority, event="Test", message="Testing NMA settings from Sick Beard", force=True)
def notify_snatch(self, ep_name):
if sickbeard.NMA_NOTIFY_ONSNATCH:
self._sendNMA(nma_api=None, nma_priority=None, event=common.notifyStrings[common.NOTIFY_SNATCH], message=ep_name)
def notify_download(self, ep_name):
if sickbeard.NMA_NOTIFY_ONDOWNLOAD:
self._sendNMA(nma_api=None, nma_priority=None, event=common.notifyStrings[common.NOTIFY_DOWNLOAD], message=ep_name)
def notify_subtitle_download(self, ep_name, lang):
if sickbeard.NMA_NOTIFY_ONSUBTITLEDOWNLOAD:
self._sendNMA(nma_api=None, nma_priority=None, event=common.notifyStrings[common.NOTIFY_SUBTITLE_DOWNLOAD], message=ep_name + ": " + lang)
def _sendNMA(self, nma_api=None, nma_priority=None, event=None, message=None, force=False):
title = 'Sick-Beard'
if not sickbeard.USE_NMA and not force:
return False
if nma_api == None:
nma_api = sickbeard.NMA_API
if nma_priority == None:
nma_priority = sickbeard.NMA_PRIORITY
logger.log(u"NMA title: " + title, logger.DEBUG)
logger.log(u"NMA event: " + event, logger.DEBUG)
logger.log(u"NMA message: " + message, logger.DEBUG)
batch = False
p = pynma.PyNMA()
keys = nma_api.split(',')
p.addkey(keys)
if len(keys) > 1: batch = True
response = p.push(title, event, message, priority=nma_priority, batch_mode=batch)
if not response[nma_api][u'code'] == u'200':
logger.log(u'Could not send notification to NotifyMyAndroid', logger.ERROR)
return False
else:
return True
notifier = NMA_Notifier
|
gpl-3.0
|
[
646,
17898,
199,
199,
504,
17898,
492,
2512,
12,
2863,
199,
504,
1973,
14,
647,
78,
391,
492,
1134,
78,
391,
199,
199,
533,
653,
2054,
63,
26884,
26,
2286,
347,
511,
63,
6814,
8,
277,
12,
302,
391,
63,
1246,
12,
302,
391,
63,
6693,
304,
267,
372,
291,
423,
2254,
46,
2054,
8,
78,
391,
63,
1246,
12,
302,
391,
63,
6693,
12,
1566,
628,
774,
401,
1245,
628,
9029,
653,
2054,
2202,
687,
28964,
6423,
1005,
401,
3542,
29,
549,
9,
339,
347,
11705,
63,
5167,
693,
8,
277,
12,
5442,
63,
354,
304,
267,
340,
17898,
14,
46,
2054,
63,
24972,
63,
615,
8199,
8078,
26,
288,
291,
423,
2254,
46,
2054,
8,
78,
391,
63,
1246,
29,
403,
12,
302,
391,
63,
6693,
29,
403,
12,
1566,
29,
2330,
14,
6814,
12672,
59,
2330,
14,
24972,
63,
8199,
8078,
467,
1245,
29,
1545,
63,
354,
9,
339,
347,
11705,
63,
4249,
8,
277,
12,
5442,
63,
354,
304,
267,
340,
17898,
14,
46,
2054,
63,
24972,
63,
615,
24930,
26,
288,
291,
423,
2254,
46,
2054,
8,
78,
391,
63,
1246,
29,
403,
12,
302,
391,
63,
6693,
29,
403,
12,
1566,
29,
2330,
14,
6814,
12672,
59,
2330,
14,
24972,
63,
24930,
467,
1245,
29,
1545,
63,
354,
9,
339,
347,
11705,
63,
14348,
63,
4249,
8,
277,
12,
5442,
63,
354,
12,
6339,
304,
267,
340,
17898,
14,
46,
2054,
63,
24972,
63,
615,
6348,
19091,
24930,
26,
288,
291,
423,
2254,
46,
2054,
8,
78,
391,
63,
1246,
29,
403,
12,
302,
391,
63,
6693,
29,
403,
12,
1566,
29,
2330,
14,
6814,
12672,
59,
2330,
14,
24972,
63,
6348,
19091,
63,
24930,
467,
1245,
29,
1545,
63,
354,
435,
7244,
298,
435,
6339,
9,
5493,
347,
485,
2254,
46,
2054,
8,
277,
12,
302,
391,
63,
1246,
29,
403,
12,
302,
391,
63,
6693,
29,
403,
12,
1566,
29,
403,
12,
1245,
29,
403,
12,
3542,
29,
797,
304,
13857,
2538,
275,
283,
51,
2000,
13,
3655,
1005,
7,
13857,
340,
440,
17898,
14,
4701,
63,
46,
2054,
436,
440,
3542,
26,
288,
372,
756,
2728,
340,
302,
391,
63,
1246,
508,
488,
26,
288,
302,
391,
63,
1246,
275,
17898,
14,
46,
2054,
63,
3735,
10631,
340,
302,
391,
63,
6693,
508,
488,
26,
288,
302,
391,
63,
6693,
275,
17898,
14,
46,
2054,
63,
25144,
13857,
2512,
14,
793,
8,
85,
2,
46,
2054,
2538,
26,
298,
435,
2538,
12,
2512,
14,
5287,
9,
267,
2512,
14,
793,
8,
85,
2,
46,
2054,
1566,
26,
298,
435,
1566,
12,
2512,
14,
5287,
9,
267,
2512,
14,
793,
8,
85,
2,
46,
2054,
1245,
26,
298,
435,
1245,
12,
2512,
14,
5287,
9,
2728,
3522,
275,
756,
2728,
299,
275,
1134,
78,
391,
14,
2713,
46,
2054,
342,
267,
2883,
275,
302,
391,
63,
1246,
14,
1294,
11917,
267,
299,
14,
525,
498,
8,
1612,
9,
2728,
340,
822,
8,
1612,
9,
690,
413,
26,
3522,
275,
715,
2728,
1177,
275,
299,
14,
5335,
8,
1213,
12,
1566,
12,
1245,
12,
7464,
29,
78,
391,
63,
6693,
12,
3522,
63,
632,
29,
2912,
9,
355,
267,
340,
440,
1177,
59,
78,
391,
63,
1246,
1527,
85,
7,
600,
418,
508,
399,
7,
1840,
356,
288,
2512,
14,
793,
8,
85,
7,
6531,
440,
3222,
6955,
370,
31949,
5713,
20762,
297,
2512,
14,
3170,
9,
288,
372,
756,
267,
587,
26,
288,
372,
715,
586,
199,
18031,
275,
653,
2054,
63,
26884,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
17898,
199,
199,
504,
17898,
492,
2512,
12,
2863,
199,
504,
1973,
14,
647,
78,
391,
492,
1134,
78,
391,
199,
199,
533,
653,
2054,
63,
26884,
26,
2286,
347,
511,
63,
6814,
8,
277,
12,
302,
391,
63,
1246,
12,
302,
391,
63,
6693,
304,
267,
372,
291,
423,
2254,
46,
2054,
8,
78,
391,
63,
1246,
12,
302,
391,
63,
6693,
12,
1566,
628,
774,
401,
1245,
628,
9029,
653,
2054,
2202,
687,
28964,
6423,
1005,
401,
3542,
29,
549,
9,
339,
347,
11705,
63,
5167,
693,
8,
277,
12,
5442,
63,
354,
304,
267,
340,
17898,
14,
46,
2054,
63,
24972,
63,
615,
8199,
8078,
26,
288,
291,
423,
2254,
46,
2054,
8,
78,
391,
63,
1246,
29,
403,
12,
302,
391,
63,
6693,
29,
403,
12,
1566,
29,
2330,
14,
6814,
12672,
59,
2330,
14,
24972,
63,
8199,
8078,
467,
1245,
29,
1545,
63,
354,
9,
339,
347,
11705,
63,
4249,
8,
277,
12,
5442,
63,
354,
304,
267,
340,
17898,
14,
46,
2054,
63,
24972,
63,
615,
24930,
26,
288,
291,
423,
2254,
46,
2054,
8,
78,
391,
63,
1246,
29,
403,
12,
302,
391,
63,
6693,
29,
403,
12,
1566,
29,
2330,
14,
6814,
12672,
59,
2330,
14,
24972,
63,
24930,
467,
1245,
29,
1545,
63,
354,
9,
339,
347,
11705,
63,
14348,
63,
4249,
8,
277,
12,
5442,
63,
354,
12,
6339,
304,
267,
340,
17898,
14,
46,
2054,
63,
24972,
63,
615,
6348,
19091,
24930,
26,
288,
291,
423,
2254,
46,
2054,
8,
78,
391,
63,
1246,
29,
403,
12,
302,
391,
63,
6693,
29,
403,
12,
1566,
29,
2330,
14,
6814,
12672,
59,
2330,
14,
24972,
63,
6348,
19091,
63,
24930,
467,
1245,
29,
1545,
63,
354,
435,
7244,
298,
435,
6339,
9,
5493,
347,
485,
2254,
46,
2054,
8,
277,
12,
302,
391,
63,
1246,
29,
403,
12,
302,
391,
63,
6693,
29,
403,
12,
1566,
29,
403,
12,
1245,
29,
403,
12,
3542,
29,
797,
304,
13857,
2538,
275,
283,
51,
2000,
13,
3655,
1005,
7,
13857,
340,
440,
17898,
14,
4701,
63,
46,
2054,
436,
440,
3542,
26,
288,
372,
756,
2728,
340,
302,
391,
63,
1246,
508,
488,
26,
288,
302,
391,
63,
1246,
275,
17898,
14,
46,
2054,
63,
3735,
10631,
340,
302,
391,
63,
6693,
508,
488,
26,
288,
302,
391,
63,
6693,
275,
17898,
14,
46,
2054,
63,
25144,
13857,
2512,
14,
793,
8,
85,
2,
46,
2054,
2538,
26,
298,
435,
2538,
12,
2512,
14,
5287,
9,
267,
2512,
14,
793,
8,
85,
2,
46,
2054,
1566,
26,
298,
435,
1566,
12,
2512,
14,
5287,
9,
267,
2512,
14,
793,
8,
85,
2,
46,
2054,
1245,
26,
298,
435,
1245,
12,
2512,
14,
5287,
9,
2728,
3522,
275,
756,
2728,
299,
275,
1134,
78,
391,
14,
2713,
46,
2054,
342,
267,
2883,
275,
302,
391,
63,
1246,
14,
1294,
11917,
267,
299,
14,
525,
498,
8,
1612,
9,
2728,
340,
822,
8,
1612,
9,
690,
413,
26,
3522,
275,
715,
2728,
1177,
275,
299,
14,
5335,
8,
1213,
12,
1566,
12,
1245,
12,
7464,
29,
78,
391,
63,
6693,
12,
3522,
63,
632,
29,
2912,
9,
355,
267,
340,
440,
1177,
59,
78,
391,
63,
1246,
1527,
85,
7,
600,
418,
508,
399,
7,
1840,
356,
288,
2512,
14,
793,
8,
85,
7,
6531,
440,
3222,
6955,
370,
31949,
5713,
20762,
297,
2512,
14,
3170,
9,
288,
372,
756,
267,
587,
26,
288,
372,
715,
586,
199,
18031,
275,
653,
2054,
63,
26884,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1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idsms/tests/test_i18n.py
|
3
|
1697
|
#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4 encoding=utf-8
import unittest, threading, time, datetime
#from django.test.client import Client
from rapidsms.i18n import ugettext_from_locale as _t
from rapidsms.i18n import ugettext_noop as _
from rapidsms.i18n import init
class TestI18n(unittest.TestCase):
def setUp(self):
#self.client = Client()
pass
def test_sms(self):
# this gets cleaned up once rapidsms unit tests are fixed
init()
self.assertEquals( _t("You said: %(message)s"), "You said: %(message)s" )
# this gets cleaned up once rapidsms unit tests are fixed
init('fr', [ ['en','English'],['fr','Francais'],['de','Deutsche'] ])
self.assertEquals( _t("You said: %(message)s", 'en'), "You said: %(message)s" )
self.assertEquals( _t("You said: %(message)s", 'fr'), "Vous avez dit: %(message)s" )
self.assertEquals( _t("You said: %(message)s", 'de'), "Ni Dichte: %(message)s" )
# for unknown language codes, revert to default translator
self.assertEquals( _t("You said: %(message)s", 'ru' ), "Vous avez dit: %(message)s" )
"""
Not sure where to put django-dependent unit tests...
def test_web(self):
response = self.client.get('')
self.assertContains(assertContains, "Log in")
response = self.client.post('i18n/', {'language':'fr'})
response = self.client.get('')
self.assertContains(assertContains, "Log in")
def test_web_and_sms(self):
# Test together in case of weird initialization dependencies
self.test_sms()
self.test_web()
"""
if __name__ == "__main__":
unittest.main()
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
6695,
26,
15933,
6714,
29,
20,
23014,
29,
20,
10844,
5584,
29,
20,
2644,
29,
1624,
13,
24,
199,
199,
646,
2882,
12,
5796,
12,
900,
12,
2197,
199,
3,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
199,
504,
660,
19331,
706,
14,
73,
1085,
78,
492,
10366,
63,
504,
63,
5508,
465,
485,
84,
199,
504,
660,
19331,
706,
14,
73,
1085,
78,
492,
10366,
63,
12921,
465,
485,
199,
504,
660,
19331,
706,
14,
73,
1085,
78,
492,
4205,
199,
199,
533,
1379,
41,
1085,
78,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
327,
277,
14,
1258,
275,
6810,
342,
267,
986,
339,
347,
511,
63,
18751,
8,
277,
304,
267,
327,
642,
7545,
12364,
1536,
5403,
660,
19331,
706,
4137,
2295,
787,
6317,
267,
4205,
342,
267,
291,
14,
2947,
8,
485,
84,
480,
5556,
25097,
26,
2818,
1188,
9,
83,
1288,
298,
5556,
25097,
26,
2818,
1188,
9,
83,
2,
776,
398,
327,
642,
7545,
12364,
1536,
5403,
660,
19331,
706,
4137,
2295,
787,
6317,
267,
4205,
360,
4391,
297,
359,
788,
287,
1673,
19410,
995,
459,
4391,
1673,
38,
1312,
696,
374,
995,
459,
271,
1673,
872,
14608,
595,
418,
4794,
267,
291,
14,
2947,
8,
485,
84,
480,
5556,
25097,
26,
2818,
1188,
9,
83,
401,
283,
287,
659,
298,
5556,
25097,
26,
2818,
1188,
9,
83,
2,
776,
267,
291,
14,
2947,
8,
485,
84,
480,
5556,
25097,
26,
2818,
1188,
9,
83,
401,
283,
4391,
659,
298,
54,
1785,
282,
432,
90,
487,
84,
26,
2818,
1188,
9,
83,
2,
776,
267,
291,
14,
2947,
8,
485,
84,
480,
5556,
25097,
26,
2818,
1188,
9,
83,
401,
283,
271,
659,
298,
20959,
577,
1158,
266,
26,
2818,
1188,
9,
83,
2,
776,
267,
327,
367,
5809,
2637,
9479,
12,
23347,
370,
849,
32034,
267,
291,
14,
2947,
8,
485,
84,
480,
5556,
25097,
26,
2818,
1188,
9,
83,
401,
283,
6558,
7,
2318,
298,
54,
1785,
282,
432,
90,
487,
84,
26,
2818,
1188,
9,
83,
2,
776,
339,
408,
5591,
2832,
3238,
2382,
370,
5324,
1639,
13,
7106,
4137,
2295,
1396,
2286,
347,
511,
63,
2520,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8355,
267,
291,
14,
9535,
8,
9535,
12,
298,
2445,
315,
531,
267,
1177,
275,
291,
14,
1258,
14,
1932,
360,
73,
1085,
78,
3678,
791,
3671,
5242,
4391,
3071,
267,
1177,
275,
291,
14,
1258,
14,
362,
8355,
267,
291,
14,
9535,
8,
9535,
12,
298,
2445,
315,
531,
339,
347,
511,
63,
2520,
63,
460,
63,
18751,
8,
277,
304,
267,
327,
1379,
10451,
315,
1930,
402,
22965,
11097,
5124,
4960,
291,
14,
396,
63,
18751,
342,
267,
291,
14,
396,
63,
2520,
342,
272,
408,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6695,
26,
15933,
6714,
29,
20,
23014,
29,
20,
10844,
5584,
29,
20,
2644,
29,
1624,
13,
24,
199,
199,
646,
2882,
12,
5796,
12,
900,
12,
2197,
199,
3,
504,
1639,
14,
396,
14,
1258,
492,
6810,
199,
199,
504,
660,
19331,
706,
14,
73,
1085,
78,
492,
10366,
63,
504,
63,
5508,
465,
485,
84,
199,
504,
660,
19331,
706,
14,
73,
1085,
78,
492,
10366,
63,
12921,
465,
485,
199,
504,
660,
19331,
706,
14,
73,
1085,
78,
492,
4205,
199,
199,
533,
1379,
41,
1085,
78,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
327,
277,
14,
1258,
275,
6810,
342,
267,
986,
339,
347,
511,
63,
18751,
8,
277,
304,
267,
327,
642,
7545,
12364,
1536,
5403,
660,
19331,
706,
4137,
2295,
787,
6317,
267,
4205,
342,
267,
291,
14,
2947,
8,
485,
84,
480,
5556,
25097,
26,
2818,
1188,
9,
83,
1288,
298,
5556,
25097,
26,
2818,
1188,
9,
83,
2,
776,
398,
327,
642,
7545,
12364,
1536,
5403,
660,
19331,
706,
4137,
2295,
787,
6317,
267,
4205,
360,
4391,
297,
359,
788,
287,
1673,
19410,
995,
459,
4391,
1673,
38,
1312,
696,
374,
995,
459,
271,
1673,
872,
14608,
595,
418,
4794,
267,
291,
14,
2947,
8,
485,
84,
480,
5556,
25097,
26,
2818,
1188,
9,
83,
401,
283,
287,
659,
298,
5556,
25097,
26,
2818,
1188,
9,
83,
2,
776,
267,
291,
14,
2947,
8,
485,
84,
480,
5556,
25097,
26,
2818,
1188,
9,
83,
401,
283,
4391,
659,
298,
54,
1785,
282,
432,
90,
487,
84,
26,
2818,
1188,
9,
83,
2,
776,
267,
291,
14,
2947,
8,
485,
84,
480,
5556,
25097,
26,
2818,
1188,
9,
83,
401,
283,
271,
659,
298,
20959,
577,
1158,
266,
26,
2818,
1188,
9,
83,
2,
776,
267,
327,
367,
5809,
2637,
9479,
12,
23347,
370,
849,
32034,
267,
291,
14,
2947,
8,
485,
84,
480,
5556,
25097,
26,
2818,
1188,
9,
83,
401,
283,
6558,
7,
2318,
298,
54,
1785,
282,
432,
90,
487,
84,
26,
2818,
1188,
9,
83,
2,
776,
339,
408,
5591,
2832,
3238,
2382,
370,
5324,
1639,
13,
7106,
4137,
2295,
1396,
2286,
347,
511,
63,
2520,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8355,
267,
291,
14,
9535,
8,
9535,
12,
298,
2445,
315,
531,
267,
1177,
275,
291,
14,
1258,
14,
1932,
360,
73,
1085,
78,
3678,
791,
3671,
5242,
4391,
3071,
267,
1177,
275,
291,
14,
1258,
14,
362,
8355,
267,
291,
14,
9535,
8,
9535,
12,
298,
2445,
315,
531,
339,
347,
511,
63,
2520,
63,
460,
63,
18751,
8,
277,
304,
267,
327,
1379,
10451,
315,
1930,
402,
22965,
11097,
5124,
4960,
291,
14,
396,
63,
18751,
342,
267,
291,
14,
396,
63,
2520,
342,
272,
408,
199,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
valkyriesavage/invenio
|
modules/websubmit/lib/functions/Move_to_Pending.py
|
35
|
1983
|
## This file is part of Invenio.
## Copyright (C) 2004, 2005, 2006, 2007, 2008, 2010, 2011 CERN.
##
## Invenio is free software; you can redistribute it and/or
## modify it under the terms of the GNU General Public License as
## published by the Free Software Foundation; either version 2 of the
## License, or (at your option) any later version.
##
## Invenio is distributed in the hope that it will be useful, but
## WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
## General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with Invenio; if not, write to the Free Software Foundation, Inc.,
## 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
__revision__ = "$Id$"
## Description: function Move_to_Pending
## This function moves the current working directory to
## /pending (usually the document is then waiting for
## approval)
## Author: T.Baron
## PARAMETERS: -
import os
from invenio.config import CFG_WEBSUBMIT_STORAGEDIR
from invenio.websubmit_config import InvenioWebSubmitFunctionError
def Move_to_Pending(parameters, curdir, form, user_info=None):
"""
This function moves the existing submission directory to the
/opt/invenio/var/data/submit/storage/pending directory. It is
used to store temporarily this data until it is approved or...
"""
global rn
doctype = form['doctype']
PENDIR = "%s/pending/%s" % (CFG_WEBSUBMIT_STORAGEDIR,doctype)
if not os.path.exists(PENDIR):
try:
os.makedirs(PENDIR)
except:
raise InvenioWebSubmitFunctionError("Cannot create pending directory %s" % PENDIR)
# Moves the files to the pending directory
rn = rn.replace("/","-")
namedir = rn
FINALDIR = "%s/%s" % (PENDIR,namedir)
os.rename(curdir,FINALDIR)
return ""
|
gpl-2.0
|
[
309,
961,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
7129,
12,
7760,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
8410,
925,
11994,
26,
257,
805,
14171,
63,
475,
63,
15960,
2043,
925,
4483,
961,
805,
14569,
314,
1453,
6449,
2082,
370,
2043,
925,
3777,
1182,
6455,
334,
25118,
314,
2213,
365,
2066,
10923,
367,
2043,
925,
4519,
4286,
637,
9,
2043,
925,
6529,
26,
260,
377,
14,
5281,
265,
2043,
925,
23710,
26,
259,
446,
199,
199,
646,
747,
199,
199,
504,
13640,
14,
888,
492,
10974,
63,
13166,
6348,
13965,
63,
13774,
1254,
1149,
3927,
199,
504,
13640,
14,
2520,
7275,
63,
888,
492,
12235,
5926,
17187,
3481,
547,
199,
199,
318,
14171,
63,
475,
63,
15960,
8,
3214,
12,
1094,
694,
12,
1824,
12,
922,
63,
815,
29,
403,
304,
272,
408,
272,
961,
805,
14569,
314,
3411,
13071,
2082,
370,
314,
272,
1182,
2992,
15,
30628,
15,
1391,
15,
576,
15,
7275,
15,
3494,
15,
6455,
2082,
14,
2779,
365,
272,
1202,
370,
3877,
22256,
642,
666,
5133,
652,
365,
30055,
503,
1396,
272,
408,
272,
2288,
519,
78,
272,
13265,
275,
1824,
459,
6356,
418,
272,
510,
742,
3022,
275,
2071,
83,
15,
6455,
3149,
83,
2,
450,
334,
10118,
63,
13166,
6348,
13965,
63,
13774,
1254,
1149,
3927,
12,
6356,
9,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
48,
742,
3022,
304,
267,
862,
26,
288,
747,
14,
8347,
8,
48,
742,
3022,
9,
267,
871,
26,
288,
746,
12235,
5926,
17187,
3481,
547,
480,
6612,
1218,
9413,
2082,
450,
83,
2,
450,
510,
742,
3022,
9,
272,
327,
3930,
2310,
314,
1584,
370,
314,
9413,
2082,
272,
519,
78,
275,
519,
78,
14,
1814,
4769,
2266,
13,
531,
272,
536,
694,
275,
519,
78,
272,
24745,
3022,
275,
2071,
83,
3149,
83,
2,
450,
334,
48,
742,
3022,
12,
354,
694,
9,
272,
747,
14,
8165,
8,
15594,
12,
29270,
3022,
9,
272,
372,
3087,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
570,
365,
1777,
402,
12235,
14,
199,
309,
1898,
334,
35,
9,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
7129,
12,
7760,
24354,
14,
199,
309,
199,
309,
12235,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
309,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
199,
309,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
12235,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
199,
309,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
309,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
309,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
309,
199,
309,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
309,
3180,
543,
12235,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
199,
309,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
8410,
925,
11994,
26,
257,
805,
14171,
63,
475,
63,
15960,
2043,
925,
4483,
961,
805,
14569,
314,
1453,
6449,
2082,
370,
2043,
925,
3777,
1182,
6455,
334,
25118,
314,
2213,
365,
2066,
10923,
367,
2043,
925,
4519,
4286,
637,
9,
2043,
925,
6529,
26,
260,
377,
14,
5281,
265,
2043,
925,
23710,
26,
259,
446,
199,
199,
646,
747,
199,
199,
504,
13640,
14,
888,
492,
10974,
63,
13166,
6348,
13965,
63,
13774,
1254,
1149,
3927,
199,
504,
13640,
14,
2520,
7275,
63,
888,
492,
12235,
5926,
17187,
3481,
547,
199,
199,
318,
14171,
63,
475,
63,
15960,
8,
3214,
12,
1094,
694,
12,
1824,
12,
922,
63,
815,
29,
403,
304,
272,
408,
272,
961,
805,
14569,
314,
3411,
13071,
2082,
370,
314,
272,
1182,
2992,
15,
30628,
15,
1391,
15,
576,
15,
7275,
15,
3494,
15,
6455,
2082,
14,
2779,
365,
272,
1202,
370,
3877,
22256,
642,
666,
5133,
652,
365,
30055,
503,
1396,
272,
408,
272,
2288,
519,
78,
272,
13265,
275,
1824,
459,
6356,
418,
272,
510,
742,
3022,
275,
2071,
83,
15,
6455,
3149,
83,
2,
450,
334,
10118,
63,
13166,
6348,
13965,
63,
13774,
1254,
1149,
3927,
12,
6356,
9,
272,
340,
440,
747,
14,
515,
14,
2444,
8,
48,
742,
3022,
304,
267,
862,
26,
288,
747,
14,
8347,
8,
48,
742,
3022,
9,
267,
871,
26,
288,
746,
12235,
5926,
17187,
3481,
547,
480,
6612,
1218,
9413,
2082,
450,
83,
2,
450,
510,
742,
3022,
9,
272,
327,
3930,
2310,
314,
1584,
370,
314,
9413,
2082,
272,
519,
78,
275,
519,
78,
14,
1814,
4769,
2266,
13,
531,
272,
536,
694,
275,
519,
78,
272,
24745,
3022,
275,
2071,
83,
3149,
83,
2,
450,
334,
48,
742,
3022,
12,
354,
694,
9,
272,
747,
14,
8165,
8,
15594,
12,
29270,
3022,
9,
272,
372,
3087,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
jswope00/griffinx
|
common/djangoapps/terrain/stubs/lti.py
|
13
|
12432
|
"""
Stub implementation of LTI Provider.
What is supported:
------------------
1.) This LTI Provider can service only one Tool Consumer at the same time. It is
not possible to have this LTI multiple times on a single page in LMS.
"""
from uuid import uuid4
import textwrap
import urllib
import re
from oauthlib.oauth1.rfc5849 import signature, parameters
import oauthlib.oauth1
import hashlib
import base64
import mock
import requests
from http import StubHttpRequestHandler, StubHttpService
class StubLtiHandler(StubHttpRequestHandler):
"""
A handler for LTI POST and GET requests.
"""
DEFAULT_CLIENT_KEY = 'test_client_key'
DEFAULT_CLIENT_SECRET = 'test_client_secret'
DEFAULT_LTI_ENDPOINT = 'correct_lti_endpoint'
DEFAULT_LTI_ADDRESS = 'http://127.0.0.1:{port}/'
def do_GET(self):
"""
Handle a GET request from the client and sends response back.
Used for checking LTI Provider started correctly.
"""
self.send_response(200, 'This is LTI Provider.', {'Content-type': 'text/plain'})
def do_POST(self):
"""
Handle a POST request from the client and sends response back.
"""
if 'grade' in self.path and self._send_graded_result().status_code == 200:
status_message = 'LTI consumer (edX) responded with XML content:<br>' + self.server.grade_data['TC answer']
content = self._create_content(status_message)
self.send_response(200, content)
elif 'lti2_outcome' in self.path and self._send_lti2_outcome().status_code == 200:
status_message = 'LTI consumer (edX) responded with HTTP {}<br>'.format(
self.server.grade_data['status_code'])
content = self._create_content(status_message)
self.send_response(200, content)
elif 'lti2_delete' in self.path and self._send_lti2_delete().status_code == 200:
status_message = 'LTI consumer (edX) responded with HTTP {}<br>'.format(
self.server.grade_data['status_code'])
content = self._create_content(status_message)
self.send_response(200, content)
# Respond to request with correct lti endpoint
elif self._is_correct_lti_request():
params = {k: v for k, v in self.post_dict.items() if k != 'oauth_signature'}
if self._check_oauth_signature(params, self.post_dict.get('oauth_signature', "")):
status_message = "This is LTI tool. Success."
# Set data for grades what need to be stored as server data
if 'lis_outcome_service_url' in self.post_dict:
self.server.grade_data = {
'callback_url': self.post_dict.get('lis_outcome_service_url').replace('https', 'http'),
'sourcedId': self.post_dict.get('lis_result_sourcedid')
}
submit_url = '//{}:{}'.format(*self.server.server_address)
content = self._create_content(status_message, submit_url)
self.send_response(200, content)
else:
content = self._create_content("Wrong LTI signature")
self.send_response(200, content)
else:
content = self._create_content("Invalid request URL")
self.send_response(500, content)
def _send_graded_result(self):
"""
Send grade request.
"""
values = {
'textString': 0.5,
'sourcedId': self.server.grade_data['sourcedId'],
'imsx_messageIdentifier': uuid4().hex,
}
payload = textwrap.dedent("""
<?xml version = "1.0" encoding = "UTF-8"?>
<imsx_POXEnvelopeRequest xmlns="http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0">
<imsx_POXHeader>
<imsx_POXRequestHeaderInfo>
<imsx_version>V1.0</imsx_version>
<imsx_messageIdentifier>{imsx_messageIdentifier}</imsx_messageIdentifier> /
</imsx_POXRequestHeaderInfo>
</imsx_POXHeader>
<imsx_POXBody>
<replaceResultRequest>
<resultRecord>
<sourcedGUID>
<sourcedId>{sourcedId}</sourcedId>
</sourcedGUID>
<result>
<resultScore>
<language>en-us</language>
<textString>{textString}</textString>
</resultScore>
</result>
</resultRecord>
</replaceResultRequest>
</imsx_POXBody>
</imsx_POXEnvelopeRequest>
""")
data = payload.format(**values)
url = self.server.grade_data['callback_url']
headers = {
'Content-Type': 'application/xml',
'X-Requested-With': 'XMLHttpRequest',
'Authorization': self._oauth_sign(url, data)
}
# Send request ignoring verifirecation of SSL certificate
response = requests.post(url, data=data, headers=headers, verify=False)
self.server.grade_data['TC answer'] = response.content
return response
def _send_lti2_outcome(self):
"""
Send a grade back to consumer
"""
payload = textwrap.dedent("""
{{
"@context" : "http://purl.imsglobal.org/ctx/lis/v2/Result",
"@type" : "Result",
"resultScore" : {score},
"comment" : "This is awesome."
}}
""")
data = payload.format(score=0.8)
return self._send_lti2(data)
def _send_lti2_delete(self):
"""
Send a delete back to consumer
"""
payload = textwrap.dedent("""
{
"@context" : "http://purl.imsglobal.org/ctx/lis/v2/Result",
"@type" : "Result"
}
""")
return self._send_lti2(payload)
def _send_lti2(self, payload):
"""
Send lti2 json result service request.
"""
### We compute the LTI V2.0 service endpoint from the callback_url (which is set by the launch call)
url = self.server.grade_data['callback_url']
url_parts = url.split('/')
url_parts[-1] = "lti_2_0_result_rest_handler"
anon_id = self.server.grade_data['sourcedId'].split(":")[-1]
url_parts.extend(["user", anon_id])
new_url = '/'.join(url_parts)
content_type = 'application/vnd.ims.lis.v2.result+json'
headers = {
'Content-Type': content_type,
'Authorization': self._oauth_sign(new_url, payload,
method='PUT',
content_type=content_type)
}
# Send request ignoring verifirecation of SSL certificate
response = requests.put(new_url, data=payload, headers=headers, verify=False)
self.server.grade_data['status_code'] = response.status_code
self.server.grade_data['TC answer'] = response.content
return response
def _create_content(self, response_text, submit_url=None):
"""
Return content (str) either for launch, send grade or get result from TC.
"""
if submit_url:
submit_form = textwrap.dedent("""
<form action="{submit_url}/grade" method="post">
<input type="submit" name="submit-button" value="Submit">
</form>
<form action="{submit_url}/lti2_outcome" method="post">
<input type="submit" name="submit-lti2-button" value="Submit">
</form>
<form action="{submit_url}/lti2_delete" method="post">
<input type="submit" name="submit-lti2-delete-button" value="Submit">
</form>
""").format(submit_url=submit_url)
else:
submit_form = ''
# Show roles only for LTI launch.
if self.post_dict.get('roles'):
role = '<h5>Role: {}</h5>'.format(self.post_dict['roles'])
else:
role = ''
response_str = textwrap.dedent("""
<html>
<head>
<title>TEST TITLE</title>
</head>
<body>
<div>
<h2>IFrame loaded</h2>
<h3>Server response is:</h3>
<h3 class="result">{response}</h3>
{role}
</div>
{submit_form}
</body>
</html>
""").format(response=response_text, role=role, submit_form=submit_form)
# Currently LTI module doublequotes the lis_result_sourcedid parameter.
# Unquote response two times.
return urllib.unquote(urllib.unquote(response_str))
def _is_correct_lti_request(self):
"""
Return a boolean indicating whether the URL path is a valid LTI end-point.
"""
lti_endpoint = self.server.config.get('lti_endpoint', self.DEFAULT_LTI_ENDPOINT)
return lti_endpoint in self.path
def _oauth_sign(self, url, body, content_type=u'application/x-www-form-urlencoded', method=u'POST'):
"""
Signs request and returns signed Authorization header.
"""
client_key = self.server.config.get('client_key', self.DEFAULT_CLIENT_KEY)
client_secret = self.server.config.get('client_secret', self.DEFAULT_CLIENT_SECRET)
client = oauthlib.oauth1.Client(
client_key=unicode(client_key),
client_secret=unicode(client_secret)
)
headers = {
# This is needed for body encoding:
'Content-Type': content_type,
}
# Calculate and encode body hash. See http://oauth.googlecode.com/svn/spec/ext/body_hash/1.0/oauth-bodyhash.html
sha1 = hashlib.sha1()
sha1.update(body)
oauth_body_hash = unicode(base64.b64encode(sha1.digest())) # pylint: disable=too-many-function-args
params = client.get_oauth_params(None)
params.append((u'oauth_body_hash', oauth_body_hash))
mock_request = mock.Mock(
uri=unicode(urllib.unquote(url)),
headers=headers,
body=u"",
decoded_body=u"",
oauth_params=params,
http_method=unicode(method),
)
sig = client.get_oauth_signature(mock_request)
mock_request.oauth_params.append((u'oauth_signature', sig))
new_headers = parameters.prepare_headers(mock_request.oauth_params, headers, realm=None)
return new_headers['Authorization']
def _check_oauth_signature(self, params, client_signature):
"""
Checks oauth signature from client.
`params` are params from post request except signature,
`client_signature` is signature from request.
Builds mocked request and verifies hmac-sha1 signing::
1. builds string to sign from `params`, `url` and `http_method`.
2. signs it with `client_secret` which comes from server settings.
3. obtains signature after sign and then compares it with request.signature
(request signature comes form client in request)
Returns `True` if signatures are correct, otherwise `False`.
"""
client_secret = unicode(self.server.config.get('client_secret', self.DEFAULT_CLIENT_SECRET))
port = self.server.server_address[1]
lti_base = self.DEFAULT_LTI_ADDRESS.format(port=port)
lti_endpoint = self.server.config.get('lti_endpoint', self.DEFAULT_LTI_ENDPOINT)
url = lti_base + lti_endpoint
request = mock.Mock()
request.params = [(unicode(k), unicode(v)) for k, v in params.items()]
request.uri = unicode(url)
request.http_method = u'POST'
request.signature = unicode(client_signature)
return signature.verify_hmac_sha1(request, client_secret)
class StubLtiService(StubHttpService):
"""
A stub LTI provider server that responds
to POST and GET requests to localhost.
"""
HANDLER_CLASS = StubLtiHandler
|
agpl-3.0
|
[
624,
199,
8067,
4514,
402,
491,
13247,
18489,
14,
199,
199,
21015,
365,
3748,
26,
199,
777,
306,
199,
199,
17,
4959,
961,
491,
13247,
18489,
883,
2435,
1454,
1373,
15650,
1448,
5391,
737,
314,
2011,
900,
14,
2779,
365,
199,
1397,
3962,
370,
1172,
642,
491,
13247,
3663,
5431,
641,
282,
2849,
2034,
315,
27540,
14,
199,
199,
624,
199,
199,
504,
5377,
492,
5377,
20,
199,
646,
13390,
199,
646,
4011,
199,
646,
295,
199,
504,
9725,
773,
14,
6126,
17,
14,
8973,
12248,
25,
492,
4955,
12,
2633,
199,
646,
9725,
773,
14,
6126,
17,
199,
646,
8337,
199,
646,
1300,
772,
199,
646,
1683,
199,
646,
4145,
199,
504,
1455,
492,
23429,
10441,
2461,
12,
23429,
5779,
3167,
421,
199,
533,
23429,
44,
280,
2461,
8,
8067,
10441,
2461,
304,
272,
408,
272,
437,
3016,
367,
491,
13247,
8761,
436,
9576,
4145,
14,
272,
408,
272,
6186,
63,
9901,
63,
3078,
275,
283,
396,
63,
1258,
63,
498,
7,
272,
6186,
63,
9901,
63,
12961,
275,
283,
396,
63,
1258,
63,
4731,
7,
272,
6186,
63,
44,
13247,
63,
21054,
275,
283,
4525,
63,
21934,
63,
6520,
7,
272,
6186,
63,
44,
13247,
63,
12368,
275,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
719,
93,
4805,
339,
347,
886,
63,
2970,
8,
277,
304,
267,
408,
267,
8690,
282,
9576,
1056,
687,
314,
1890,
436,
16178,
1177,
1771,
14,
398,
8051,
367,
7907,
491,
13247,
18489,
8239,
6657,
14,
267,
408,
267,
291,
14,
2254,
63,
1310,
8,
1840,
12,
283,
2765,
365,
491,
13247,
18489,
3130,
791,
2714,
13,
466,
356,
283,
505,
15,
6104,
3071,
339,
347,
886,
63,
4030,
8,
277,
304,
267,
408,
267,
8690,
282,
8761,
1056,
687,
314,
1890,
436,
16178,
1177,
1771,
14,
267,
408,
267,
340,
283,
4523,
7,
315,
291,
14,
515,
436,
291,
423,
2254,
63,
13688,
63,
1099,
1252,
1205,
63,
600,
508,
1926,
26,
288,
2004,
63,
1188,
275,
283,
44,
13247,
9790,
334,
24852,
9,
9163,
770,
543,
4692,
1564,
16875,
3289,
3524,
435,
291,
14,
1000,
14,
4523,
63,
576,
459,
5708,
6385,
418,
288,
1564,
275,
291,
423,
981,
63,
1317,
8,
1205,
63,
1188,
9,
288,
291,
14,
2254,
63,
1310,
8,
1840,
12,
1564,
9,
267,
916,
283,
21934,
18,
63,
17502,
7,
315,
291,
14,
515,
436,
291,
423,
2254,
63,
21934,
18,
63,
17502,
1252,
1205,
63,
600,
508,
1926,
26,
288,
2004,
63,
1188,
275,
283,
44,
13247,
9790,
334,
24852,
9,
9163,
770,
543,
3101,
1052,
28,
3289,
22936,
908,
8,
355,
291,
14,
1000,
14,
4523,
63,
576,
459,
1205,
63,
600,
1105,
288,
1564,
275,
291,
423,
981,
63,
1317,
8,
1205,
63,
1188,
9,
288,
291,
14,
2254,
63,
1310,
8,
1840,
12,
1564,
9,
267,
916,
283,
21934,
18,
63,
1807,
7,
315,
291,
14,
515,
436,
291,
423,
2254,
63,
21934,
18,
63,
1807,
1252,
1205,
63,
600,
508,
1926,
26,
288,
2004,
63,
1188,
275,
283,
44,
13247,
9790,
334,
24852,
9,
9163,
770,
543,
3101,
1052,
28,
3289,
22936,
908,
8,
355,
291,
14,
1000,
14,
4523,
63,
576,
459,
1205,
63,
600,
1105,
288,
1564,
275,
291,
423,
981,
63,
1317,
8,
1205,
63,
1188,
9,
288,
291,
14,
2254,
63,
1310,
8,
1840,
12,
1564,
9,
267,
327,
3591,
31717,
370,
1056,
543,
3211,
634,
280,
6037,
267,
916,
291,
423,
374,
63,
4525,
63,
21934,
63,
1069,
837,
288,
1862,
275,
469,
75,
26,
373,
367,
1022,
12,
373,
315,
291,
14,
1932,
63,
807,
14,
1744,
342,
340,
1022,
1137,
283,
6126,
63,
5233,
936,
953,
340,
291,
423,
1074,
63,
6126,
63,
5233,
8,
1162,
12,
291,
14,
1932,
63,
807,
14,
362,
360,
6126,
63,
5233,
297,
6899,
304,
355,
2004,
63,
1188,
275,
298,
2765,
365,
491,
13247,
4744,
14,
22318,
2122,
2234,
327,
2494,
666,
367,
1999,
3424,
4052,
1929,
370,
506,
5489,
465,
1654,
666,
355,
340,
283,
14392,
63,
17502,
63,
1364,
63,
633,
7,
315,
291,
14,
1932,
63,
807,
26,
490,
291,
14,
1000,
14,
4523,
63,
576,
275,
469,
717,
283,
3058,
63,
633,
356,
291,
14,
1932,
63,
807,
14,
362,
360,
14392,
63,
17502,
63,
1364,
63,
633,
1959,
1814,
360,
2859,
297,
283,
1014,
659,
717,
283,
1365,
68,
1304,
356,
291,
14,
1932,
63,
807,
14,
362,
360,
14392,
63,
1099,
63,
1365,
14887,
358,
490,
789,
2234,
11482,
63,
633,
275,
18290,
2440,
26,
11123,
908,
2031,
277,
14,
1000,
14,
1000,
63,
1562,
9,
355,
1564,
275,
291,
423,
981,
63,
1317,
8,
1205,
63,
1188,
12,
11482,
63,
633,
9,
355,
291,
14,
2254,
63,
1310,
8,
1840,
12,
1564,
9,
953,
587,
26,
355,
1564,
275,
291,
423,
981,
63,
1317,
480,
14858,
491,
13247,
4955,
531,
355,
291,
14,
2254,
63,
1310,
8,
1840,
12,
1564,
9,
267,
587,
26,
288,
1564,
275,
291,
423,
981,
63,
1317,
480,
3364,
1056,
2851,
531,
288,
291,
14,
2254,
63,
1310,
8,
5783,
12,
1564,
9,
339,
347,
485,
2254,
63,
13688,
63,
1099,
8,
277,
304,
267,
408,
267,
10217,
16183,
1056,
14,
267,
408,
267,
1338,
275,
469,
288,
283,
505,
1558,
356,
378,
14,
21,
12,
288,
283,
1365,
68,
1304,
356,
291,
14,
1000,
14,
4523,
63,
576,
459,
1365,
68,
1304,
995,
288,
283,
11171,
88,
63,
1188,
7544,
356,
5377,
20,
1252,
4097,
12,
267,
789,
267,
4886,
275,
13390,
14,
14674,
4852,
288,
665,
31,
1652,
1015,
275,
298,
17,
14,
16,
2,
2644,
275,
298,
6610,
13,
24,
24327,
355,
665,
11171,
88,
63,
1512,
56,
28278,
2017,
221,
9604,
628,
1014,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
5950,
15,
21934,
86,
17,
80,
17,
15,
10515,
15,
11171,
22491,
63,
86,
17,
80,
16,
1743,
2116,
665,
11171,
88,
63,
1512,
56,
2567,
30,
490,
665,
11171,
88,
63,
1512,
56,
20165,
2354,
30,
1993,
665,
11171,
88,
63,
1023,
30,
54,
17,
14,
16,
1108,
11171,
88,
63,
1023,
30,
1993,
665,
11171,
88,
63,
1188,
7544,
22266,
11171,
88,
63,
1188,
7544,
17890,
11171
] |
[
199,
8067,
4514,
402,
491,
13247,
18489,
14,
199,
199,
21015,
365,
3748,
26,
199,
777,
306,
199,
199,
17,
4959,
961,
491,
13247,
18489,
883,
2435,
1454,
1373,
15650,
1448,
5391,
737,
314,
2011,
900,
14,
2779,
365,
199,
1397,
3962,
370,
1172,
642,
491,
13247,
3663,
5431,
641,
282,
2849,
2034,
315,
27540,
14,
199,
199,
624,
199,
199,
504,
5377,
492,
5377,
20,
199,
646,
13390,
199,
646,
4011,
199,
646,
295,
199,
504,
9725,
773,
14,
6126,
17,
14,
8973,
12248,
25,
492,
4955,
12,
2633,
199,
646,
9725,
773,
14,
6126,
17,
199,
646,
8337,
199,
646,
1300,
772,
199,
646,
1683,
199,
646,
4145,
199,
504,
1455,
492,
23429,
10441,
2461,
12,
23429,
5779,
3167,
421,
199,
533,
23429,
44,
280,
2461,
8,
8067,
10441,
2461,
304,
272,
408,
272,
437,
3016,
367,
491,
13247,
8761,
436,
9576,
4145,
14,
272,
408,
272,
6186,
63,
9901,
63,
3078,
275,
283,
396,
63,
1258,
63,
498,
7,
272,
6186,
63,
9901,
63,
12961,
275,
283,
396,
63,
1258,
63,
4731,
7,
272,
6186,
63,
44,
13247,
63,
21054,
275,
283,
4525,
63,
21934,
63,
6520,
7,
272,
6186,
63,
44,
13247,
63,
12368,
275,
283,
1014,
921,
4195,
14,
16,
14,
16,
14,
17,
14534,
719,
93,
4805,
339,
347,
886,
63,
2970,
8,
277,
304,
267,
408,
267,
8690,
282,
9576,
1056,
687,
314,
1890,
436,
16178,
1177,
1771,
14,
398,
8051,
367,
7907,
491,
13247,
18489,
8239,
6657,
14,
267,
408,
267,
291,
14,
2254,
63,
1310,
8,
1840,
12,
283,
2765,
365,
491,
13247,
18489,
3130,
791,
2714,
13,
466,
356,
283,
505,
15,
6104,
3071,
339,
347,
886,
63,
4030,
8,
277,
304,
267,
408,
267,
8690,
282,
8761,
1056,
687,
314,
1890,
436,
16178,
1177,
1771,
14,
267,
408,
267,
340,
283,
4523,
7,
315,
291,
14,
515,
436,
291,
423,
2254,
63,
13688,
63,
1099,
1252,
1205,
63,
600,
508,
1926,
26,
288,
2004,
63,
1188,
275,
283,
44,
13247,
9790,
334,
24852,
9,
9163,
770,
543,
4692,
1564,
16875,
3289,
3524,
435,
291,
14,
1000,
14,
4523,
63,
576,
459,
5708,
6385,
418,
288,
1564,
275,
291,
423,
981,
63,
1317,
8,
1205,
63,
1188,
9,
288,
291,
14,
2254,
63,
1310,
8,
1840,
12,
1564,
9,
267,
916,
283,
21934,
18,
63,
17502,
7,
315,
291,
14,
515,
436,
291,
423,
2254,
63,
21934,
18,
63,
17502,
1252,
1205,
63,
600,
508,
1926,
26,
288,
2004,
63,
1188,
275,
283,
44,
13247,
9790,
334,
24852,
9,
9163,
770,
543,
3101,
1052,
28,
3289,
22936,
908,
8,
355,
291,
14,
1000,
14,
4523,
63,
576,
459,
1205,
63,
600,
1105,
288,
1564,
275,
291,
423,
981,
63,
1317,
8,
1205,
63,
1188,
9,
288,
291,
14,
2254,
63,
1310,
8,
1840,
12,
1564,
9,
267,
916,
283,
21934,
18,
63,
1807,
7,
315,
291,
14,
515,
436,
291,
423,
2254,
63,
21934,
18,
63,
1807,
1252,
1205,
63,
600,
508,
1926,
26,
288,
2004,
63,
1188,
275,
283,
44,
13247,
9790,
334,
24852,
9,
9163,
770,
543,
3101,
1052,
28,
3289,
22936,
908,
8,
355,
291,
14,
1000,
14,
4523,
63,
576,
459,
1205,
63,
600,
1105,
288,
1564,
275,
291,
423,
981,
63,
1317,
8,
1205,
63,
1188,
9,
288,
291,
14,
2254,
63,
1310,
8,
1840,
12,
1564,
9,
267,
327,
3591,
31717,
370,
1056,
543,
3211,
634,
280,
6037,
267,
916,
291,
423,
374,
63,
4525,
63,
21934,
63,
1069,
837,
288,
1862,
275,
469,
75,
26,
373,
367,
1022,
12,
373,
315,
291,
14,
1932,
63,
807,
14,
1744,
342,
340,
1022,
1137,
283,
6126,
63,
5233,
936,
953,
340,
291,
423,
1074,
63,
6126,
63,
5233,
8,
1162,
12,
291,
14,
1932,
63,
807,
14,
362,
360,
6126,
63,
5233,
297,
6899,
304,
355,
2004,
63,
1188,
275,
298,
2765,
365,
491,
13247,
4744,
14,
22318,
2122,
2234,
327,
2494,
666,
367,
1999,
3424,
4052,
1929,
370,
506,
5489,
465,
1654,
666,
355,
340,
283,
14392,
63,
17502,
63,
1364,
63,
633,
7,
315,
291,
14,
1932,
63,
807,
26,
490,
291,
14,
1000,
14,
4523,
63,
576,
275,
469,
717,
283,
3058,
63,
633,
356,
291,
14,
1932,
63,
807,
14,
362,
360,
14392,
63,
17502,
63,
1364,
63,
633,
1959,
1814,
360,
2859,
297,
283,
1014,
659,
717,
283,
1365,
68,
1304,
356,
291,
14,
1932,
63,
807,
14,
362,
360,
14392,
63,
1099,
63,
1365,
14887,
358,
490,
789,
2234,
11482,
63,
633,
275,
18290,
2440,
26,
11123,
908,
2031,
277,
14,
1000,
14,
1000,
63,
1562,
9,
355,
1564,
275,
291,
423,
981,
63,
1317,
8,
1205,
63,
1188,
12,
11482,
63,
633,
9,
355,
291,
14,
2254,
63,
1310,
8,
1840,
12,
1564,
9,
953,
587,
26,
355,
1564,
275,
291,
423,
981,
63,
1317,
480,
14858,
491,
13247,
4955,
531,
355,
291,
14,
2254,
63,
1310,
8,
1840,
12,
1564,
9,
267,
587,
26,
288,
1564,
275,
291,
423,
981,
63,
1317,
480,
3364,
1056,
2851,
531,
288,
291,
14,
2254,
63,
1310,
8,
5783,
12,
1564,
9,
339,
347,
485,
2254,
63,
13688,
63,
1099,
8,
277,
304,
267,
408,
267,
10217,
16183,
1056,
14,
267,
408,
267,
1338,
275,
469,
288,
283,
505,
1558,
356,
378,
14,
21,
12,
288,
283,
1365,
68,
1304,
356,
291,
14,
1000,
14,
4523,
63,
576,
459,
1365,
68,
1304,
995,
288,
283,
11171,
88,
63,
1188,
7544,
356,
5377,
20,
1252,
4097,
12,
267,
789,
267,
4886,
275,
13390,
14,
14674,
4852,
288,
665,
31,
1652,
1015,
275,
298,
17,
14,
16,
2,
2644,
275,
298,
6610,
13,
24,
24327,
355,
665,
11171,
88,
63,
1512,
56,
28278,
2017,
221,
9604,
628,
1014,
921,
1544,
14,
73,
1328,
1498,
14,
1308,
15,
5950,
15,
21934,
86,
17,
80,
17,
15,
10515,
15,
11171,
22491,
63,
86,
17,
80,
16,
1743,
2116,
665,
11171,
88,
63,
1512,
56,
2567,
30,
490,
665,
11171,
88,
63,
1512,
56,
20165,
2354,
30,
1993,
665,
11171,
88,
63,
1023,
30,
54,
17,
14,
16,
1108,
11171,
88,
63,
1023,
30,
1993,
665,
11171,
88,
63,
1188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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
huahbo/src
|
book/Recipes/rweutil.py
|
5
|
3249
|
from rsf.proj import *
# ------------------------------------------------------------
def C2Rdat(mapRC, mapCC,cos,par):
Flow( mapRC,[mapCC,cos],
'''
window |
spray axis=2 n=1 o=%(oz)g d=%(dz)g |
pad beg2=10 n2out=20 |
c2r adj=n linear=n nsz=3 nsx=3
rays=${SOURCES[1]} |
put label1=g label2=t
''' % par)
def R2Cdat(mapCC, mapRC,cos,par):
par['nzcut']=20
par['ozcut']=-10*par['dz']
Flow( mapCC,[mapRC,cos],
'''
c2r adj=y linear=n nsz=3 nsx=3
rays=${SOURCES[1]}
a1n=%(nx)d a1o=%(ox)g a1d=%(dx)g
a2n=%(nzcut)d a2o=%(ozcut)g a2d=%(dz)g |
window n2=1 min2=%(oz)g
''' % par)
# ------------------------------------------------------------
def C2Rimg(mapRC, mapCC,cos,par):
Flow( mapRC,[mapCC,cos],
'''
window |
c2r adj=n linear=y
rays=${SOURCES[1]} |
put label1=g label2=t
''' % par)
def R2Cimg(mapCC, mapRC,cos,par):
Flow( mapCC,[mapRC,cos],
'''
window |
c2r adj=y linear=n nsz=3 nsx=3
rays=${SOURCES[1]}
a1n=%(nx)d a1o=%(ox)g a1d=%(dx)g
a2n=%(nz)d a2o=%(oz)g a2d=%(dz)g |
put label1=z label2=x
''' % par)
# ------------------------------------------------------------
def SPmod(datRC, wavRC,imgRC,abmRC,abrRC,par):
Flow( datRC,[wavRC,imgRC,abmRC,abrRC],
'''
rwesrmig ntap=25 adj=y verb=y method=1
nw=%(nw)d ow=%(ow)g dw=%(dw)g
img=${SOURCES[1]}
abm=${SOURCES[2]}
abr=${SOURCES[3]} |
put label1=g label2=t label3=w
''' % par)
def SPmig(imgRC, wavRC,datRC,abmRC,abrRC,par):
Flow( imgRC,[wavRC,datRC,abmRC,abrRC],
'''
rwesrmig ntap=25 adj=n verb=y method=1
rwf=${SOURCES[1]}
abm=${SOURCES[2]}
abr=${SOURCES[3]} |
put label1=g label2=t
''')
# ------------------------------------------------------------
def ZOmod(datRC, imgRC,abmRC,abrRC,par):
Flow( datRC,[imgRC,abmRC,abrRC],
'''
rwezomig ntap=25 adj=y verb=y method=1
nw=%(nw)d ow=%(ow)g dw=%(dw)g
abm=${SOURCES[1]}
abr=${SOURCES[2]} |
put label1=g label2=t label3=w
''' % par)
def ZOmig(migRC, datRC,abmRC,abrRC,par):
Flow( migRC,[datRC,abmRC,abrRC],
'''
rwezomig ntap=25 adj=n verb=y method=1
abm=${SOURCES[1]}
abr=${SOURCES[2]} |
put label1=g label2=t
''')
# ------------------------------------------------------------
def t2w (wdat,tdat,par):
Flow(wdat,tdat,
'''
fft1 opt=n |
window squeeze=n n1=%(nw)d min1=%(ow)g |
put label1=w label2=x label3=y |
transp plane=12 |
transp plane=23
''' % par)
def w2t (tdat,wdat,par):
Flow(tdat,wdat,
'''
transp |
pad beg1=%d n1out=%d |
fft1 opt=n inv=y |
window f1=%d |
pad n1out=%d |
put label1=t label2=x o1=0
''' % (int(par['ow']/par['dw']),
par['nT']/2+1,
par['kT'],
par['nT']))
|
gpl-2.0
|
[
504,
519,
7646,
14,
5468,
492,
627,
199,
199,
3,
9527,
4559,
199,
199,
318,
445,
18,
50,
4616,
8,
1130,
8205,
12,
2341,
2571,
12,
5197,
12,
462,
304,
272,
20823,
8,
221,
2341,
8205,
14343,
1130,
2571,
12,
5197,
467,
268,
1449,
268,
4353,
1204,
268,
2249,
803,
3114,
29,
18,
302,
29,
17,
312,
15438,
26051,
9,
71,
366,
15438,
17019,
9,
71,
1204,
268,
6567,
31191,
18,
29,
709,
302,
18,
548,
29,
1165,
1204,
268,
286,
18,
82,
14510,
29,
78,
7798,
29,
78,
700,
90,
29,
19,
700,
88,
29,
19,
268,
660,
588,
29,
10545,
25744,
59,
17,
9420,
1204,
268,
5324,
1768,
17,
29,
71,
1768,
18,
29,
84,
268,
1449,
450,
623,
9,
199,
199,
318,
820,
18,
35,
4616,
8,
1130,
2571,
12,
2341,
8205,
12,
5197,
12,
462,
304,
14821,
623,
459,
15291,
5919,
13784,
1165,
272,
623,
459,
26051,
5919,
418,
4022,
709,
10,
462,
459,
17019,
418,
272,
20823,
8,
221,
2341,
2571,
14343,
1130,
8205,
12,
5197,
467,
268,
1449,
268,
286,
18,
82,
14510,
29,
89,
7798,
29,
78,
700,
90,
29,
19,
700,
88,
29,
19,
268,
660,
588,
29,
10545,
25744,
59,
17,
9420,
268,
282,
17,
78,
15438,
7343,
9,
68,
259,
282,
17,
79,
15438,
19131,
9,
71,
259,
282,
17,
68,
15438,
8373,
9,
71,
268,
282,
18,
78,
15438,
15291,
5919,
9,
68,
282,
18,
79,
15438,
26051,
5919,
9,
71,
282,
18,
68,
15438,
17019,
9,
71,
1204,
268,
4353,
302,
18,
29,
17,
1748,
18,
15438,
26051,
9,
71,
268,
1449,
450,
623,
9,
199,
199,
3,
9527,
4559,
199,
199,
318,
445,
18,
50,
4060,
8,
1130,
8205,
12,
2341,
2571,
12,
5197,
12,
462,
304,
272,
20823,
8,
221,
2341,
8205,
14343,
1130,
2571,
12,
5197,
467,
268,
1449,
268,
4353,
1204,
268,
286,
18,
82,
14510,
29,
78,
7798,
29,
89,
268,
660,
588,
29,
10545,
25744,
59,
17,
9420,
1204,
268,
5324,
1768,
17,
29,
71,
1768,
18,
29,
84,
268,
1449,
450,
623,
9,
199,
199,
318,
820,
18,
35,
4060,
8,
1130,
2571,
12,
2341,
8205,
12,
5197,
12,
462,
304,
272,
20823,
8,
221,
2341,
2571,
14343,
1130,
8205,
12,
5197,
467,
268,
1449,
268,
4353,
1204,
268,
286,
18,
82,
14510,
29,
89,
7798,
29,
78,
700,
90,
29,
19,
700,
88,
29,
19,
268,
660,
588,
29,
10545,
25744,
59,
17,
9420,
268,
282,
17,
78,
15438,
7343,
9,
68,
282,
17,
79,
15438,
19131,
9,
71,
282,
17,
68,
15438,
8373,
9,
71,
268,
282,
18,
78,
15438,
15291,
9,
68,
282,
18,
79,
15438,
26051,
9,
71,
282,
18,
68,
15438,
17019,
9,
71,
1204,
268,
5324,
1768,
17,
29,
90,
1768,
18,
29,
88,
268,
1449,
450,
623,
9,
199,
199,
3,
9527,
4559,
199,
199,
318,
6988,
1494,
8,
4616,
8205,
12,
336,
1214,
8205,
12,
4060,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
12,
462,
304,
272,
20823,
8,
6394,
8205,
14343,
19118,
8205,
12,
4060,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
467,
268,
1449,
268,
29329,
397,
82,
4071,
13377,
439,
29,
821,
14510,
29,
89,
16041,
29,
89,
1083,
29,
17,
268,
22823,
15438,
13100,
9,
68,
22182,
15438,
583,
9,
71,
17594,
15438,
10772,
9,
71,
221,
268,
6050,
29,
10545,
25744,
59,
17,
9420,
268,
2236,
77,
29,
10545,
25744,
59,
18,
9420,
268,
2236,
82,
29,
10545,
25744,
59,
19,
9420,
1204,
268,
5324,
1768,
17,
29,
71,
1768,
18,
29,
84,
1768,
19,
29,
87,
268,
1449,
450,
623,
9,
199,
199,
318,
6988,
4071,
8,
4060,
8205,
12,
336,
1214,
8205,
12,
4616,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
12,
462,
304,
272,
20823,
8,
6050,
8205,
14343,
19118,
8205,
12,
4616,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
467,
268,
1449,
268,
29329,
397,
82,
4071,
13377,
439,
29,
821,
14510,
29,
78,
16041,
29,
89,
1083,
29,
17,
268,
519,
14114,
29,
10545,
25744,
59,
17,
9420,
268,
2236,
77,
29,
10545,
25744,
59,
18,
9420,
268,
2236,
82,
29,
10545,
25744,
59,
19,
9420,
1204,
268,
5324,
1768,
17,
29,
71,
1768,
18,
29,
84,
268,
21464,
199,
199,
3,
9527,
4559,
199,
199,
318,
3107,
47,
1494,
8,
4616,
8205,
12,
6050,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
12,
462,
304,
272,
20823,
8,
6394,
8205,
14343,
4060,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
467,
268,
1449,
268,
519,
1129,
90,
676,
528,
13377,
439,
29,
821,
14510,
29,
89,
16041,
29,
89,
1083,
29,
17,
268,
22823,
15438,
13100,
9,
68,
22182,
15438,
583,
9,
71,
17594,
15438,
10772,
9,
71,
221,
268,
2236,
77,
29,
10545,
25744,
59,
17,
9420,
268,
2236,
82,
29,
10545,
25744,
59,
18,
9420,
1204,
268,
5324,
1768,
17,
29,
71,
1768,
18,
29,
84,
1768,
19,
29,
87,
268,
1449,
450,
623,
9,
199,
199,
318,
3107,
47,
4071,
8,
4071,
8205,
12,
6394,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
12,
462,
304,
272,
20823,
8,
3952,
8205,
14343,
4616,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
467,
268,
1449,
268,
519,
1129,
90,
676,
528,
13377,
439,
29,
821,
14510,
29,
78,
16041,
29,
89,
1083,
29,
17,
268,
2236,
77,
29,
10545,
25744,
59,
17,
9420,
268,
2236,
82,
29,
10545,
25744,
59,
18,
9420,
1204,
268,
5324,
1768,
17,
29,
71,
1768,
18,
29,
84,
268,
21464,
199,
199,
3,
9527,
4559,
199,
199,
318,
307,
18,
87,
334,
2989,
292,
12,
2076,
292,
12,
462,
304,
272,
20823,
8,
2989,
292,
12,
2076,
292,
12,
268,
1449,
268,
18160,
17,
2450,
29,
78,
1204,
268,
4353,
308,
14167,
29,
78,
302,
17,
15438,
13100,
9,
68,
1748,
17,
15438,
583,
9,
71,
1204,
268,
5324,
1768,
17,
29,
87,
1768,
18,
29,
88,
1768,
19,
29,
89,
1204,
268,
7115,
681,
16388,
29,
713,
1204,
268,
7115,
681,
16388,
29,
1789,
221,
268,
1449,
450,
623,
9,
421,
199,
318,
336,
18,
84,
334,
2076,
292,
12,
2989,
292,
12,
462,
304,
272
] |
[
519,
7646,
14,
5468,
492,
627,
199,
199,
3,
9527,
4559,
199,
199,
318,
445,
18,
50,
4616,
8,
1130,
8205,
12,
2341,
2571,
12,
5197,
12,
462,
304,
272,
20823,
8,
221,
2341,
8205,
14343,
1130,
2571,
12,
5197,
467,
268,
1449,
268,
4353,
1204,
268,
2249,
803,
3114,
29,
18,
302,
29,
17,
312,
15438,
26051,
9,
71,
366,
15438,
17019,
9,
71,
1204,
268,
6567,
31191,
18,
29,
709,
302,
18,
548,
29,
1165,
1204,
268,
286,
18,
82,
14510,
29,
78,
7798,
29,
78,
700,
90,
29,
19,
700,
88,
29,
19,
268,
660,
588,
29,
10545,
25744,
59,
17,
9420,
1204,
268,
5324,
1768,
17,
29,
71,
1768,
18,
29,
84,
268,
1449,
450,
623,
9,
199,
199,
318,
820,
18,
35,
4616,
8,
1130,
2571,
12,
2341,
8205,
12,
5197,
12,
462,
304,
14821,
623,
459,
15291,
5919,
13784,
1165,
272,
623,
459,
26051,
5919,
418,
4022,
709,
10,
462,
459,
17019,
418,
272,
20823,
8,
221,
2341,
2571,
14343,
1130,
8205,
12,
5197,
467,
268,
1449,
268,
286,
18,
82,
14510,
29,
89,
7798,
29,
78,
700,
90,
29,
19,
700,
88,
29,
19,
268,
660,
588,
29,
10545,
25744,
59,
17,
9420,
268,
282,
17,
78,
15438,
7343,
9,
68,
259,
282,
17,
79,
15438,
19131,
9,
71,
259,
282,
17,
68,
15438,
8373,
9,
71,
268,
282,
18,
78,
15438,
15291,
5919,
9,
68,
282,
18,
79,
15438,
26051,
5919,
9,
71,
282,
18,
68,
15438,
17019,
9,
71,
1204,
268,
4353,
302,
18,
29,
17,
1748,
18,
15438,
26051,
9,
71,
268,
1449,
450,
623,
9,
199,
199,
3,
9527,
4559,
199,
199,
318,
445,
18,
50,
4060,
8,
1130,
8205,
12,
2341,
2571,
12,
5197,
12,
462,
304,
272,
20823,
8,
221,
2341,
8205,
14343,
1130,
2571,
12,
5197,
467,
268,
1449,
268,
4353,
1204,
268,
286,
18,
82,
14510,
29,
78,
7798,
29,
89,
268,
660,
588,
29,
10545,
25744,
59,
17,
9420,
1204,
268,
5324,
1768,
17,
29,
71,
1768,
18,
29,
84,
268,
1449,
450,
623,
9,
199,
199,
318,
820,
18,
35,
4060,
8,
1130,
2571,
12,
2341,
8205,
12,
5197,
12,
462,
304,
272,
20823,
8,
221,
2341,
2571,
14343,
1130,
8205,
12,
5197,
467,
268,
1449,
268,
4353,
1204,
268,
286,
18,
82,
14510,
29,
89,
7798,
29,
78,
700,
90,
29,
19,
700,
88,
29,
19,
268,
660,
588,
29,
10545,
25744,
59,
17,
9420,
268,
282,
17,
78,
15438,
7343,
9,
68,
282,
17,
79,
15438,
19131,
9,
71,
282,
17,
68,
15438,
8373,
9,
71,
268,
282,
18,
78,
15438,
15291,
9,
68,
282,
18,
79,
15438,
26051,
9,
71,
282,
18,
68,
15438,
17019,
9,
71,
1204,
268,
5324,
1768,
17,
29,
90,
1768,
18,
29,
88,
268,
1449,
450,
623,
9,
199,
199,
3,
9527,
4559,
199,
199,
318,
6988,
1494,
8,
4616,
8205,
12,
336,
1214,
8205,
12,
4060,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
12,
462,
304,
272,
20823,
8,
6394,
8205,
14343,
19118,
8205,
12,
4060,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
467,
268,
1449,
268,
29329,
397,
82,
4071,
13377,
439,
29,
821,
14510,
29,
89,
16041,
29,
89,
1083,
29,
17,
268,
22823,
15438,
13100,
9,
68,
22182,
15438,
583,
9,
71,
17594,
15438,
10772,
9,
71,
221,
268,
6050,
29,
10545,
25744,
59,
17,
9420,
268,
2236,
77,
29,
10545,
25744,
59,
18,
9420,
268,
2236,
82,
29,
10545,
25744,
59,
19,
9420,
1204,
268,
5324,
1768,
17,
29,
71,
1768,
18,
29,
84,
1768,
19,
29,
87,
268,
1449,
450,
623,
9,
199,
199,
318,
6988,
4071,
8,
4060,
8205,
12,
336,
1214,
8205,
12,
4616,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
12,
462,
304,
272,
20823,
8,
6050,
8205,
14343,
19118,
8205,
12,
4616,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
467,
268,
1449,
268,
29329,
397,
82,
4071,
13377,
439,
29,
821,
14510,
29,
78,
16041,
29,
89,
1083,
29,
17,
268,
519,
14114,
29,
10545,
25744,
59,
17,
9420,
268,
2236,
77,
29,
10545,
25744,
59,
18,
9420,
268,
2236,
82,
29,
10545,
25744,
59,
19,
9420,
1204,
268,
5324,
1768,
17,
29,
71,
1768,
18,
29,
84,
268,
21464,
199,
199,
3,
9527,
4559,
199,
199,
318,
3107,
47,
1494,
8,
4616,
8205,
12,
6050,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
12,
462,
304,
272,
20823,
8,
6394,
8205,
14343,
4060,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
467,
268,
1449,
268,
519,
1129,
90,
676,
528,
13377,
439,
29,
821,
14510,
29,
89,
16041,
29,
89,
1083,
29,
17,
268,
22823,
15438,
13100,
9,
68,
22182,
15438,
583,
9,
71,
17594,
15438,
10772,
9,
71,
221,
268,
2236,
77,
29,
10545,
25744,
59,
17,
9420,
268,
2236,
82,
29,
10545,
25744,
59,
18,
9420,
1204,
268,
5324,
1768,
17,
29,
71,
1768,
18,
29,
84,
1768,
19,
29,
87,
268,
1449,
450,
623,
9,
199,
199,
318,
3107,
47,
4071,
8,
4071,
8205,
12,
6394,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
12,
462,
304,
272,
20823,
8,
3952,
8205,
14343,
4616,
8205,
12,
371,
77,
8205,
12,
371,
82,
8205,
467,
268,
1449,
268,
519,
1129,
90,
676,
528,
13377,
439,
29,
821,
14510,
29,
78,
16041,
29,
89,
1083,
29,
17,
268,
2236,
77,
29,
10545,
25744,
59,
17,
9420,
268,
2236,
82,
29,
10545,
25744,
59,
18,
9420,
1204,
268,
5324,
1768,
17,
29,
71,
1768,
18,
29,
84,
268,
21464,
199,
199,
3,
9527,
4559,
199,
199,
318,
307,
18,
87,
334,
2989,
292,
12,
2076,
292,
12,
462,
304,
272,
20823,
8,
2989,
292,
12,
2076,
292,
12,
268,
1449,
268,
18160,
17,
2450,
29,
78,
1204,
268,
4353,
308,
14167,
29,
78,
302,
17,
15438,
13100,
9,
68,
1748,
17,
15438,
583,
9,
71,
1204,
268,
5324,
1768,
17,
29,
87,
1768,
18,
29,
88,
1768,
19,
29,
89,
1204,
268,
7115,
681,
16388,
29,
713,
1204,
268,
7115,
681,
16388,
29,
1789,
221,
268,
1449,
450,
623,
9,
421,
199,
318,
336,
18,
84,
334,
2076,
292,
12,
2989,
292,
12,
462,
304,
272,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
snopt/snopt-python
|
examples/snmainb.py
|
1
|
7041
|
"""
An example SNOPTB problem.
"""
import numpy as np
from snopt import snoptb, SNOPT_options
def hexCon(mode,x,fCon,gCon,nState):
two = 2.0
fCon[ 0] = x[0]**2 + x[5]**2
fCon[ 1] = (x[1] - x[0])**2 + (x[6] - x[5])**2
fCon[ 2] = (x[2] - x[0])**2 + x[5]**2
fCon[ 3] = (x[0] - x[3])**2 + (x[5] - x[7])**2
fCon[ 4] = (x[0] - x[4])**2 + (x[5] - x[8])**2
fCon[ 5] = x[1]**2 + x[6]**2
fCon[ 6] = (x[2] - x[1])**2 + x[6]**2
fCon[ 7] = (x[3] - x[1])**2 + (x[7] - x[6])**2
fCon[ 8] = (x[1] - x[4])**2 + (x[6] - x[8])**2
fCon[ 9] = (x[3] - x[2])**2 + x[7]**2
fCon[10] = (x[4] - x[2])**2 + x[8]**2
fCon[11] = x[3]**2 + x[7]**2
fCon[12] = (x[3] - x[4])**2 + (x[8] - x[7])**2
fCon[13] = x[4]**2 + x[8]**2
# Nonlinear Jacobian elements for column 1.
# rows = [1,2,3,4,5].
gCon[ 0] = two*x[0]
gCon[ 1] = - two*(x[1] - x[0])
gCon[ 2] = - two*(x[2] - x[0])
gCon[ 3] = two*(x[0] - x[3])
gCon[ 4] = two*(x[0] - x[4])
# Nonlinear Jacobian elements for column 2.
# Rows = [2,6,7,8,9].
gCon[ 5] = two*(x[1] - x[0])
gCon[ 6] = two*x[1]
gCon[ 7] = - two*(x[2] - x[1])
gCon[ 8] = - two*(x[3] - x[1])
gCon[ 9] = two*(x[1] - x[4])
# Nonlinear Jacobian elements for column 3.
# Rows = [3,7,10,11].
gCon[10] = two*(x[2] - x[0])
gCon[11] = two*(x[2] - x[1])
gCon[12] = - two*(x[3] - x[2])
gCon[13] = - two*(x[4] - x[2])
# Nonlinear Jacobian elements for column 4.
# Rows = [4,8,10,12,13].
gCon[14] = - two*(x[0] - x[3])
gCon[15] = two*(x[3] - x[1])
gCon[16] = two*(x[3] - x[2])
gCon[17] = two*x[3]
gCon[18] = two*(x[3] - x[4])
# Nonlinear Jacobian elements for column 5.
# Rows = [5,9,11,13,14].
gCon[19] = - two*(x[0] - x[4])
gCon[20] = - two*(x[1] - x[4])
gCon[21] = two*(x[4] - x[2])
gCon[22] = - two*(x[3] - x[4])
gCon[23] = two*x[4]
# Nonlinear Jacobian elements for column 6.
# Rows = [1,2,3,4,5].
gCon[24] = two*x[5]
gCon[25] = - two*(x[6] - x[5])
gCon[26] = two*x[5]
gCon[27] = two*(x[5] - x[7])
gCon[28] = two*(x[5] - x[8])
# Nonlinear Jacobian elements for column 7.
# Rows = [2,6,7,8,9].
gCon[29] = two*(x[6] - x[5])
gCon[30] = two*x[6]
gCon[31] = two*x[6]
gCon[32] = - two*(x[7] - x[6])
gCon[33] = two*(x[6] - x[8])
# Nonlinear Jacobian elements for column 8.
# Rows = [4,8,10,12,13].
gCon[34] = - two*(x[5] - x[7])
gCon[35] = two*(x[7] - x[6])
gCon[36] = two*x[7]
gCon[37] = two*x[7]
gCon[38] = - two*(x[8] - x[7])
# Nonlinear Jacobian elements for column 9.
# Rows = [5,9,11,13,14].
gCon[39] = - two*(x[5] - x[8])
gCon[40] = - two*(x[6] - x[8])
gCon[41] = two*x[8]
gCon[42] = two*(x[8] - x[7])
gCon[43] = two*x[8]
return mode, fCon, gCon
def hexObj(mode,x,fObj,gObj,nState):
fObj = - x[1]*x[5] + x[0]*x[6] - x[2]*x[6] - x[4]*x[7] + x[3]*x[8] + x[2]*x[7]
gObj[0] = x[6]
gObj[1] = - x[5]
gObj[2] = - x[6] + x[7]
gObj[3] = x[8]
gObj[4] = - x[7]
gObj[5] = - x[1]
gObj[6] = - x[2] + x[0]
gObj[7] = - x[4] + x[2]
gObj[8] = x[3]
return mode, fObj, gObj
inf = 1.0e+20
options = SNOPT_options()
options.setOption('Infinite bound',inf)
options.setOption('Specs filename','snmainb.spc')
options.setOption('Print filename','snmainb.out')
m = 18
n = 9
nnCon = 14
ne = 52
nnJac = n
nnObj = n
bl = -inf*np.ones(n+m)
bu = inf*np.ones(n+m)
# Nonlinear constraints
bu[1+n:nnCon+n] = 1.0
# Linear constraints
bl[1+n+nnCon:m+n] = 0.0
# Variables
bl[0] = 0.0
bl[2] = -1.0
bl[4] = 0.0
bl[5] = 0.0
bl[6] = 0.0
bu[2] = 1.0
bu[7] = 0.0
bu[8] = 0.0
# Initial x
x = np.zeros(n+m)
x[0] = .1e+0
x[1] = .125e+0
x[2] = .666666e+0
x[3] = .142857e+0
x[4] = .111111e+0
x[5] = .2e+0
x[6] = .25e+0
x[7] = -.2e+0
x[8] = -.25e+0
# Jacobian
locJ = np.zeros(n+1,'i')
indJ = np.zeros(ne,'i')
valJ = np.zeros(ne,float)
locJ[0] = 0
indJ[ 0] = 0
indJ[ 1] = 1
indJ[ 2] = 2
indJ[ 3] = 3
indJ[ 4] = 4
valJ[ 0] = 0.0
valJ[ 1] = 0.0
valJ[ 2] = 0.0
valJ[ 3] = 0.0
valJ[ 4] = 0.0
# Column 1.
# Linear element in row 6 next.
indJ[ 5] = 14
valJ[ 5] = -1.0
# Column 2.
# Nonlinear elements in rows [2, 6, 7, 8, 9].
locJ[ 1] = 6
indJ[ 6] = 1
indJ[ 7] = 5
indJ[ 8] = 6
indJ[ 9] = 7
indJ[10] = 8
valJ[ 6] = 0.0
valJ[ 7] = 0.0
valJ[ 8] = 0.0
valJ[ 9] = 0.0
valJ[10] = 0.0
# Column 2.
# Linear elements in rows [15,16].
indJ[11] = 14
indJ[12] = 15
valJ[11] = 1.0
valJ[12] = -1.0
# Column 3.
# Nonlinear elements in rows [3, 7, 10, 11].
locJ[ 2] = 13
indJ[13] = 2
indJ[14] = 6
indJ[15] = 9
indJ[16] = 10
valJ[13] = 0.0
valJ[14] = 0.0
valJ[15] = 0.0
valJ[16] = 0.0
# Column 3.
# Linear elements in rows [16, 17].
indJ[17] = 15
indJ[18] = 16
valJ[17] = 1.0
valJ[18] = 1.0
# Column 4.
# Nonlinear elements in rows [20, 21, 22, 23, 24].
locJ[ 3] = 19
indJ[19] = 3
indJ[20] = 7
indJ[21] = 9
indJ[22] = 11
indJ[23] = 12
valJ[19] = 0.0
valJ[20] = 0.0
valJ[21] = 0.0
valJ[22] = 0.0
valJ[23] = 0.0
# Column 4.
# Linear elements in rows [17, 18].
indJ[24] = 16
indJ[25] = 17
valJ[24] = -1.0
valJ[25] = 1.0
# Column 5.
# Nonlinear elements in rows [5, 9, 11, 13, 14].
locJ[ 4] = 26
indJ[26] = 4
indJ[27] = 8
indJ[28] = 10
indJ[29] = 12
indJ[30] = 13
valJ[26] = 0.0
valJ[27] = 0.0
valJ[28] = 0.0
valJ[29] = 0.0
valJ[30] = 0.0
# Column 5.
# Linear element in row 18.
indJ[31] = 17
valJ[31] = -1.0
# Column 6.
# Nonlinear elements in rows [1, 2, 3, 4, 5, 6].
locJ[5] = 32
indJ[32] = 0
indJ[33] = 1
indJ[34] = 2
indJ[35] = 3
indJ[36] = 4
valJ[32] = 0.0
valJ[33] = 0.0
valJ[34] = 0.0
valJ[35] = 0.0
valJ[36] = 0.0
# Column 7.
# Nonlinear elements in rows [2, 6, 7, 8, 9].
locJ[6] = 37
indJ[37] = 1
indJ[38] = 5
indJ[39] = 6
indJ[40] = 7
indJ[41] = 8
valJ[37] = 0.0
valJ[38] = 0.0
valJ[39] = 0.0
valJ[40] = 0.0
valJ[41] = 0.0
# Column 8.
# Nonlinear elements in rows [4, 8, 10, 12, 13].
locJ[7] = 42
indJ[42] = 3
indJ[43] = 7
indJ[44] = 9
indJ[45] = 11
indJ[46] = 12
valJ[42] = 0.0
valJ[43] = 0.0
valJ[44] = 0.0
valJ[45] = 0.0
valJ[46] = 0.0
# Column 9.
# Nonlinear elements in rows [5, 9, 11, 13, 14].
locJ[8] = 47
indJ[47] = 4
indJ[48] = 8
indJ[49] = 10
indJ[50] = 12
indJ[51] = 13
valJ[47] = 0.0
valJ[48] = 0.0
valJ[49] = 0.0
valJ[50] = 0.0
valJ[51] = 0.0
# Don't forget to finish off locJ.
# This is crucial.
locJ[ 9] = 51 + 1
# Put components of J into a tuple
J = (valJ,indJ,locJ)
options.setOption('Verbose',True)
result = snoptb(hexObj,hexCon,nnObj=nnObj,nnCon=nnCon,nnJac=nnJac,
name=' snmainb',x0=x,bl=bl,bu=bu,J=J,m=m,n=n,options=options)
|
mit
|
[
624,
199,
2493,
2893,
428,
46,
5123,
34,
5160,
14,
199,
624,
199,
199,
646,
2680,
465,
980,
199,
504,
6895,
2992,
492,
6895,
2992,
66,
12,
428,
46,
5123,
63,
1419,
421,
199,
318,
6318,
714,
8,
632,
12,
88,
12,
70,
714,
12,
71,
714,
12,
78,
2223,
304,
272,
2877,
275,
499,
14,
16,
339,
289,
714,
59,
378,
61,
275,
259,
671,
59,
16,
24186,
18,
3515,
435,
257,
671,
59,
21,
24186,
18,
272,
289,
714,
59,
413,
61,
275,
257,
334,
88,
59,
17,
61,
446,
671,
59,
16,
566,
538,
18,
221,
435,
221,
334,
88,
59,
22,
61,
446,
671,
59,
21,
566,
538,
18,
272,
289,
714,
59,
499,
61,
275,
257,
334,
88,
59,
18,
61,
446,
671,
59,
16,
566,
538,
18,
221,
435,
257,
671,
59,
21,
24186,
18,
272,
289,
714,
59,
650,
61,
275,
257,
334,
88,
59,
16,
61,
446,
671,
59,
19,
566,
538,
18,
221,
435,
221,
334,
88,
59,
21,
61,
446,
671,
59,
23,
566,
538,
18,
272,
289,
714,
59,
841,
61,
275,
257,
334,
88,
59,
16,
61,
446,
671,
59,
20,
566,
538,
18,
221,
435,
221,
334,
88,
59,
21,
61,
446,
671,
59,
24,
566,
538,
18,
272,
289,
714,
59,
959,
61,
275,
259,
671,
59,
17,
24186,
18,
3515,
435,
257,
671,
59,
22,
24186,
18,
272,
289,
714,
59,
1227,
61,
275,
257,
334,
88,
59,
18,
61,
446,
671,
59,
17,
566,
538,
18,
221,
435,
257,
671,
59,
22,
24186,
18,
272,
289,
714,
59,
1520,
61,
275,
257,
334,
88,
59,
19,
61,
446,
671,
59,
17,
566,
538,
18,
221,
435,
221,
334,
88,
59,
23,
61,
446,
671,
59,
22,
566,
538,
18,
272,
289,
714,
59,
1695,
61,
275,
257,
334,
88,
59,
17,
61,
446,
671,
59,
20,
566,
538,
18,
221,
435,
221,
334,
88,
59,
22,
61,
446,
671,
59,
24,
566,
538,
18,
272,
289,
714,
59,
1749,
61,
275,
257,
334,
88,
59,
19,
61,
446,
671,
59,
18,
566,
538,
18,
221,
435,
257,
671,
59,
23,
24186,
18,
272,
289,
714,
59,
709,
61,
275,
257,
334,
88,
59,
20,
61,
446,
671,
59,
18,
566,
538,
18,
221,
435,
257,
671,
59,
24,
24186,
18,
272,
289,
714,
59,
845,
61,
275,
259,
671,
59,
19,
24186,
18,
3515,
435,
257,
671,
59,
23,
24186,
18,
272,
289,
714,
59,
713,
61,
275,
257,
334,
88,
59,
19,
61,
446,
671,
59,
20,
566,
538,
18,
221,
435,
221,
334,
88,
59,
24,
61,
446,
671,
59,
23,
566,
538,
18,
272,
289,
714,
59,
969,
61,
275,
259,
671,
59,
20,
24186,
18,
3515,
435,
257,
671,
59,
24,
24186,
18,
339,
327,
10172,
6676,
30633,
4008,
367,
2763,
413,
14,
272,
327,
4730,
275,
359,
17,
12,
18,
12,
19,
12,
20,
12,
21,
1055,
272,
486,
714,
59,
378,
61,
275,
257,
2877,
10,
88,
59,
16,
61,
272,
486,
714,
59,
413,
61,
275,
446,
2877,
5830,
88,
59,
17,
61,
446,
671,
59,
16,
566,
272,
486,
714,
59,
499,
61,
275,
446,
2877,
5830,
88,
59,
18,
61,
446,
671,
59,
16,
566,
272,
486,
714,
59,
650,
61,
275,
257,
2877,
5830,
88,
59,
16,
61,
446,
671,
59,
19,
566,
272,
486,
714,
59,
841,
61,
275,
257,
2877,
5830,
88,
59,
16,
61,
446,
671,
59,
20,
566,
339,
327,
10172,
6676,
30633,
4008,
367,
2763,
499,
14,
272,
327,
15231,
83,
275,
359,
18,
12,
22,
12,
23,
12,
24,
12,
25,
1055,
339,
486,
714,
59,
959,
61,
275,
257,
2877,
5830,
88,
59,
17,
61,
446,
671,
59,
16,
566,
272,
486,
714,
59,
1227,
61,
275,
257,
2877,
10,
88,
59,
17,
61,
272,
486,
714,
59,
1520,
61,
275,
446,
2877,
5830,
88,
59,
18,
61,
446,
671,
59,
17,
566,
272,
486,
714,
59,
1695,
61,
275,
446,
2877,
5830,
88,
59,
19,
61,
446,
671,
59,
17,
566,
272,
486,
714,
59,
1749,
61,
275,
257,
2877,
5830,
88,
59,
17,
61,
446,
671,
59,
20,
566,
339,
327,
10172,
6676,
30633,
4008,
367,
2763,
650,
14,
272,
327,
15231,
83,
275,
359,
19,
12,
23,
12,
709,
12,
845,
1055,
339,
486,
714,
59,
709,
61,
275,
257,
2877,
5830,
88,
59,
18,
61,
446,
671,
59,
16,
566,
272,
486,
714,
59,
845,
61,
275,
257,
2877,
5830,
88,
59,
18,
61,
446,
671,
59,
17,
566,
272,
486,
714,
59,
713,
61,
275,
446,
2877,
5830,
88,
59,
19,
61,
446,
671,
59,
18,
566,
272,
486,
714,
59,
969,
61,
275,
446,
2877,
5830,
88,
59,
20,
61,
446,
671,
59,
18,
566,
339,
327,
10172,
6676,
30633,
4008,
367,
2763,
841,
14,
272,
327,
15231,
83,
275,
359,
20,
12,
24,
12,
709,
12,
713,
12,
969,
1055,
339,
486,
714,
59,
1079,
61,
275,
446,
2877,
5830,
88,
59,
16,
61,
446,
671,
59,
19,
566,
272,
486,
714,
59,
1046,
61,
275,
257,
2877,
5830,
88,
59,
19,
61,
446,
671,
59,
17,
566,
272,
486,
714,
59,
975,
61,
275,
257,
2877,
5830,
88,
59,
19,
61,
446,
671,
59,
18,
566,
272,
486,
714,
59,
1196,
61,
275,
257,
2877,
10,
88,
59,
19,
61,
272,
486,
714,
59,
1085,
61,
275,
257,
2877,
5830,
88,
59,
19,
61,
446,
671,
59,
20,
566,
339,
327,
10172,
6676,
30633,
4008,
367,
2763,
959,
14,
272,
327,
15231,
83,
275,
359,
21,
12,
25,
12,
845,
12,
969,
12,
1079,
1055,
339,
486,
714,
59,
1167,
61,
275,
446,
2877,
5830,
88,
59,
16,
61,
446,
671,
59,
20,
566,
272,
486,
714,
59,
1165,
61,
275,
446,
2877,
5830,
88,
59,
17,
61,
446,
671,
59,
20,
566,
272,
486,
714,
59,
2025,
61,
275,
257,
2877,
5830,
88,
59,
20,
61,
446,
671,
59,
18,
566,
272,
486,
714,
59,
1081,
61,
275,
446,
2877,
5830,
88,
59,
19,
61,
446,
671,
59,
20,
566,
272,
486,
714,
59,
1789,
61,
275,
257,
2877,
10,
88,
59
] |
[
199,
2493,
2893,
428,
46,
5123,
34,
5160,
14,
199,
624,
199,
199,
646,
2680,
465,
980,
199,
504,
6895,
2992,
492,
6895,
2992,
66,
12,
428,
46,
5123,
63,
1419,
421,
199,
318,
6318,
714,
8,
632,
12,
88,
12,
70,
714,
12,
71,
714,
12,
78,
2223,
304,
272,
2877,
275,
499,
14,
16,
339,
289,
714,
59,
378,
61,
275,
259,
671,
59,
16,
24186,
18,
3515,
435,
257,
671,
59,
21,
24186,
18,
272,
289,
714,
59,
413,
61,
275,
257,
334,
88,
59,
17,
61,
446,
671,
59,
16,
566,
538,
18,
221,
435,
221,
334,
88,
59,
22,
61,
446,
671,
59,
21,
566,
538,
18,
272,
289,
714,
59,
499,
61,
275,
257,
334,
88,
59,
18,
61,
446,
671,
59,
16,
566,
538,
18,
221,
435,
257,
671,
59,
21,
24186,
18,
272,
289,
714,
59,
650,
61,
275,
257,
334,
88,
59,
16,
61,
446,
671,
59,
19,
566,
538,
18,
221,
435,
221,
334,
88,
59,
21,
61,
446,
671,
59,
23,
566,
538,
18,
272,
289,
714,
59,
841,
61,
275,
257,
334,
88,
59,
16,
61,
446,
671,
59,
20,
566,
538,
18,
221,
435,
221,
334,
88,
59,
21,
61,
446,
671,
59,
24,
566,
538,
18,
272,
289,
714,
59,
959,
61,
275,
259,
671,
59,
17,
24186,
18,
3515,
435,
257,
671,
59,
22,
24186,
18,
272,
289,
714,
59,
1227,
61,
275,
257,
334,
88,
59,
18,
61,
446,
671,
59,
17,
566,
538,
18,
221,
435,
257,
671,
59,
22,
24186,
18,
272,
289,
714,
59,
1520,
61,
275,
257,
334,
88,
59,
19,
61,
446,
671,
59,
17,
566,
538,
18,
221,
435,
221,
334,
88,
59,
23,
61,
446,
671,
59,
22,
566,
538,
18,
272,
289,
714,
59,
1695,
61,
275,
257,
334,
88,
59,
17,
61,
446,
671,
59,
20,
566,
538,
18,
221,
435,
221,
334,
88,
59,
22,
61,
446,
671,
59,
24,
566,
538,
18,
272,
289,
714,
59,
1749,
61,
275,
257,
334,
88,
59,
19,
61,
446,
671,
59,
18,
566,
538,
18,
221,
435,
257,
671,
59,
23,
24186,
18,
272,
289,
714,
59,
709,
61,
275,
257,
334,
88,
59,
20,
61,
446,
671,
59,
18,
566,
538,
18,
221,
435,
257,
671,
59,
24,
24186,
18,
272,
289,
714,
59,
845,
61,
275,
259,
671,
59,
19,
24186,
18,
3515,
435,
257,
671,
59,
23,
24186,
18,
272,
289,
714,
59,
713,
61,
275,
257,
334,
88,
59,
19,
61,
446,
671,
59,
20,
566,
538,
18,
221,
435,
221,
334,
88,
59,
24,
61,
446,
671,
59,
23,
566,
538,
18,
272,
289,
714,
59,
969,
61,
275,
259,
671,
59,
20,
24186,
18,
3515,
435,
257,
671,
59,
24,
24186,
18,
339,
327,
10172,
6676,
30633,
4008,
367,
2763,
413,
14,
272,
327,
4730,
275,
359,
17,
12,
18,
12,
19,
12,
20,
12,
21,
1055,
272,
486,
714,
59,
378,
61,
275,
257,
2877,
10,
88,
59,
16,
61,
272,
486,
714,
59,
413,
61,
275,
446,
2877,
5830,
88,
59,
17,
61,
446,
671,
59,
16,
566,
272,
486,
714,
59,
499,
61,
275,
446,
2877,
5830,
88,
59,
18,
61,
446,
671,
59,
16,
566,
272,
486,
714,
59,
650,
61,
275,
257,
2877,
5830,
88,
59,
16,
61,
446,
671,
59,
19,
566,
272,
486,
714,
59,
841,
61,
275,
257,
2877,
5830,
88,
59,
16,
61,
446,
671,
59,
20,
566,
339,
327,
10172,
6676,
30633,
4008,
367,
2763,
499,
14,
272,
327,
15231,
83,
275,
359,
18,
12,
22,
12,
23,
12,
24,
12,
25,
1055,
339,
486,
714,
59,
959,
61,
275,
257,
2877,
5830,
88,
59,
17,
61,
446,
671,
59,
16,
566,
272,
486,
714,
59,
1227,
61,
275,
257,
2877,
10,
88,
59,
17,
61,
272,
486,
714,
59,
1520,
61,
275,
446,
2877,
5830,
88,
59,
18,
61,
446,
671,
59,
17,
566,
272,
486,
714,
59,
1695,
61,
275,
446,
2877,
5830,
88,
59,
19,
61,
446,
671,
59,
17,
566,
272,
486,
714,
59,
1749,
61,
275,
257,
2877,
5830,
88,
59,
17,
61,
446,
671,
59,
20,
566,
339,
327,
10172,
6676,
30633,
4008,
367,
2763,
650,
14,
272,
327,
15231,
83,
275,
359,
19,
12,
23,
12,
709,
12,
845,
1055,
339,
486,
714,
59,
709,
61,
275,
257,
2877,
5830,
88,
59,
18,
61,
446,
671,
59,
16,
566,
272,
486,
714,
59,
845,
61,
275,
257,
2877,
5830,
88,
59,
18,
61,
446,
671,
59,
17,
566,
272,
486,
714,
59,
713,
61,
275,
446,
2877,
5830,
88,
59,
19,
61,
446,
671,
59,
18,
566,
272,
486,
714,
59,
969,
61,
275,
446,
2877,
5830,
88,
59,
20,
61,
446,
671,
59,
18,
566,
339,
327,
10172,
6676,
30633,
4008,
367,
2763,
841,
14,
272,
327,
15231,
83,
275,
359,
20,
12,
24,
12,
709,
12,
713,
12,
969,
1055,
339,
486,
714,
59,
1079,
61,
275,
446,
2877,
5830,
88,
59,
16,
61,
446,
671,
59,
19,
566,
272,
486,
714,
59,
1046,
61,
275,
257,
2877,
5830,
88,
59,
19,
61,
446,
671,
59,
17,
566,
272,
486,
714,
59,
975,
61,
275,
257,
2877,
5830,
88,
59,
19,
61,
446,
671,
59,
18,
566,
272,
486,
714,
59,
1196,
61,
275,
257,
2877,
10,
88,
59,
19,
61,
272,
486,
714,
59,
1085,
61,
275,
257,
2877,
5830,
88,
59,
19,
61,
446,
671,
59,
20,
566,
339,
327,
10172,
6676,
30633,
4008,
367,
2763,
959,
14,
272,
327,
15231,
83,
275,
359,
21,
12,
25,
12,
845,
12,
969,
12,
1079,
1055,
339,
486,
714,
59,
1167,
61,
275,
446,
2877,
5830,
88,
59,
16,
61,
446,
671,
59,
20,
566,
272,
486,
714,
59,
1165,
61,
275,
446,
2877,
5830,
88,
59,
17,
61,
446,
671,
59,
20,
566,
272,
486,
714,
59,
2025,
61,
275,
257,
2877,
5830,
88,
59,
20,
61,
446,
671,
59,
18,
566,
272,
486,
714,
59,
1081,
61,
275,
446,
2877,
5830,
88,
59,
19,
61,
446,
671,
59,
20,
566,
272,
486,
714,
59,
1789,
61,
275,
257,
2877,
10,
88,
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,
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
] |
haum/pelican-flickrtag
|
pelican_flickrtag/flickr.py
|
1
|
51012
|
"""
flickr.py
Copyright 2004-2006 James Clarke <james@jamesclarke.info>
Portions Copyright 2007-2008 Joshua Henderson <joshhendo@gmail.com>
THIS SOFTWARE IS SUPPLIED WITHOUT WARRANTY OF ANY KIND, AND MAY BE
COPIED, MODIFIED OR DISTRIBUTED IN ANY WAY, AS LONG AS THIS NOTICE
AND ACKNOWLEDGEMENT OF AUTHORSHIP REMAIN.
2013-01-12
Removed dependency on the token.txt token file.
2007-12-17
For an upto date TODO list, please see:
http://code.google.com/p/flickrpy/wiki/TodoList
For information on how to use the Authentication
module, plese see:
http://code.google.com/p/flickrpy/wiki/UserAuthentication
2006-12-19
Applied patches from Berco Beute and Wolfram Kriesing.
"""
__author__ = "James Clarke <james@jamesclarke.info>"
__version__ = "$Rev$"
__date__ = "$Date$"
__copyright__ = "Copyright: 2004-2010 James Clarke; Portions: 2007-2008 Joshua Henderson; Portions: 2011 Andrei Vlad Vacariu"
from urllib import urlencode, urlopen
from xml.dom import minidom
import hashlib
import os
HOST = 'https://flickr.com'
API = '/services/rest'
# set these here or using flickr.API_KEY in your application
API_TOKEN = None
API_KEY = ''
API_SECRET = ''
email = None
password = None
AUTH = False
debug = False
# The next 2 variables are only important if authentication is used
# this can be set here or using flickr.tokenPath in your application
# this is the path to the folder containing tokenFile (default: token.txt)
tokenPath = ''
# this can be set here or using flickr.tokenFile in your application
# this is the name of the file containing the stored token.
tokenFile = 'token.txt'
class FlickrError(Exception): pass
class Photo(object):
"""Represents a Flickr Photo."""
__readonly = ['id', 'secret', 'server', 'farm', 'isfavorite', 'license', 'rotation',
'owner', 'dateposted', 'datetaken', 'takengranularity',
'title', 'description', 'ispublic', 'isfriend', 'isfamily',
'cancomment', 'canaddmeta', 'comments', 'tags', 'permcomment',
'permaddmeta', 'url']
#XXX: Hopefully None won't cause problems
def __init__(self, id, owner=None, dateuploaded=None, \
title=None, description=None, ispublic=None, \
isfriend=None, isfamily=None, cancomment=None, \
canaddmeta=None, comments=None, tags=None, secret=None, \
isfavorite=None, server=None, farm=None, license=None, \
rotation=None, url=None):
"""Must specify id, rest is optional."""
self.__loaded = False
self.__cancomment = cancomment
self.__canaddmeta = canaddmeta
self.__comments = comments
self.__dateuploaded = dateuploaded
self.__description = description
self.__id = id
self.__license = license
self.__isfamily = isfamily
self.__isfavorite = isfavorite
self.__isfriend = isfriend
self.__ispublic = ispublic
self.__owner = owner
self.__rotation = rotation
self.__secret = secret
self.__server = server
self.__farm = farm
self.__tags = tags
self.__title = title
self.__dateposted = None
self.__datetaken = None
self.__takengranularity = None
self.__permcomment = None
self.__permaddmeta = None
self.__url = None
def __setattr__(self, key, value):
if key in self.__class__.__readonly:
raise AttributeError("The attribute %s is read-only." % key)
else:
super(Photo, self).__setattr__(key, value)
def __getattr__(self, key):
if not self.__loaded:
self._load_properties()
if key in self.__class__.__readonly:
return super(Photo, self).__getattribute__("_%s__%s" % (self.__class__.__name__, key))
else:
return super(Photo, self).__getattribute__(key)
def _load_properties(self):
"""Loads the properties from Flickr."""
self.__loaded = True
method = 'flickr.photos.getInfo'
data = _doget(method, photo_id=self.id)
photo = data.rsp.photo
self.__secret = photo.secret
self.__server = photo.server
self.__farm = photo.farm
self.__isfavorite = photo.isfavorite
self.__license = photo.license
self.__rotation = photo.rotation
owner = photo.owner
self.__owner = User(owner.nsid, username=owner.username,\
realname=owner.realname,\
location=owner.location)
self.__title = photo.title.text
self.__description = photo.description.text
self.__ispublic = photo.visibility.ispublic
self.__isfriend = photo.visibility.isfriend
self.__isfamily = photo.visibility.isfamily
self.__dateposted = photo.dates.posted
self.__datetaken = photo.dates.taken
self.__takengranularity = photo.dates.takengranularity
self.__cancomment = photo.editability.cancomment
self.__canaddmeta = photo.editability.canaddmeta
self.__comments = photo.comments.text
self.__url = photo.urls.url.text
try:
self.__permcomment = photo.permissions.permcomment
self.__permaddmeta = photo.permissions.permaddmeta
except AttributeError:
self.__permcomment = None
self.__permaddmeta = None
#TODO: Implement Notes?
if hasattr(photo.tags, "tag"):
if isinstance(photo.tags.tag, list):
self.__tags = [Tag(tag.id, User(tag.author), tag.raw, tag.text) \
for tag in photo.tags.tag]
else:
tag = photo.tags.tag
self.__tags = [Tag(tag.id, User(tag.author), tag.raw, tag.text)]
def __str__(self):
return '<Flickr Photo %s>' % self.id
def setTags(self, tags):
"""Set the tags for current photo to list tags.
(flickr.photos.settags)
"""
method = 'flickr.photos.setTags'
tags = uniq(tags)
_dopost(method, auth=True, photo_id=self.id, tags=tags)
self._load_properties()
def addTags(self, tags):
"""Adds the list of tags to current tags. (flickr.photos.addtags)
"""
method = 'flickr.photos.addTags'
if isinstance(tags, list):
tags = uniq(tags)
_dopost(method, auth=True, photo_id=self.id, tags=tags)
#load properties again
self._load_properties()
def removeTag(self, tag):
"""Remove the tag from the photo must be a Tag object.
(flickr.photos.removeTag)
"""
method = 'flickr.photos.removeTag'
tag_id = ''
try:
tag_id = tag.id
except AttributeError:
raise FlickrError, "Tag object expected"
_dopost(method, auth=True, photo_id=self.id, tag_id=tag_id)
self._load_properties()
def setMeta(self, title=None, description=None):
"""Set metadata for photo. (flickr.photos.setMeta)"""
method = 'flickr.photos.setMeta'
if title is None:
title = self.title
if description is None:
description = self.description
_dopost(method, auth=True, title=title, \
description=description, photo_id=self.id)
self.__title = title
self.__description = description
def getAllContexts(self):
"""Retrieves lists of the pools/sets the photo is in"""
method = 'flickr.photos.getAllContexts'
data = _doget(method, photo_id=self.id)
d = {'pools': [], 'sets': []}
if hasattr(data.rsp, "pool"):
if isinstance(data.rsp.pool, list):
for pool in data.rsp.pool:
d["pools"].append({"id": pool.id, "title": pool.title})
else:
d["pools"].append({"id": data.rsp.pool.id, "title": data.rsp.pool.title})
if hasattr(data.rsp, "set"):
if isinstance(data.rsp.set, list):
for theset in data.rsp.set:
d["sets"].append({"id": theset.id, "title": theset.title})
else:
d["sets"].append({"id": data.rsp.set.id, "title": data.rsp.set.title})
return d
def getPoolCount(self):
"""Retrieves a count of the pools the photo is in"""
d = self.getAllContexts()
return len( d["pools"] )
def getSetCount(self):
"""Retrieves a count of the pools the photo is in"""
d = self.getAllContexts()
return len( d["sets"] )
def getURL(self, size='Medium', urlType='url'):
"""Retrieves a url for the photo. (flickr.photos.getSizes)
urlType - 'url' or 'source'
'url' - flickr page of photo
'source' - image file
"""
method = 'flickr.photos.getSizes'
data = _doget(method, photo_id=self.id)
for psize in data.rsp.sizes.size:
if psize.label == size:
return getattr(psize, urlType)
raise FlickrError, "No URL found"
def getSizes(self):
"""
Get all the available sizes of the current image, and all available
data about them.
Returns: A list of dicts with the size data.
"""
method = 'flickr.photos.getSizes'
data = _doget(method, photo_id=self.id)
ret = []
# The given props are those that we return and the according types, since
# return width and height as string would make "75">"100" be True, which
# is just error prone.
props = {'url':str,'width':int,'height':int,'label':str,'source':str,'text':str}
for psize in data.rsp.sizes.size:
d = {}
for prop,convert_to_type in props.items():
d[prop] = convert_to_type(getattr(psize, prop))
ret.append(d)
return ret
#def getExif(self):
#method = 'flickr.photos.getExif'
#data = _doget(method, photo_id=self.id)
#ret = []
#for exif in data.rsp.photo.exif:
#print exif.label, dir(exif)
##ret.append({exif.label:exif.})
#return ret
##raise FlickrError, "No URL found"
def getLocation(self):
"""
Return the latitude+longitutde of the picture.
Returns None if no location given for this pic.
"""
method = 'flickr.photos.geo.getLocation'
try:
data = _doget(method, photo_id=self.id)
except FlickrError: # Some other error might have occured too!?
return None
loc = data.rsp.photo.location
return [loc.latitude, loc.longitude]
def getComments(self):
""""
get list of comments for photo
returns a list of comment objects
comment text is in return [item].text
"""
method = "flickr.photos.comments.getList"
try:
data = _doget(method, photo_id=self.id)
except FlickrError: # ???? what errors might there be????
return None
return data.rsp.comments
def _getDirectURL(self, size=None):
size = "_%s" % size if size else ""
return "http://farm%s.static.flickr.com/%s/%s_%s%s.jpg" % \
(self.farm, self.server, self.id, self.secret, size)
def getThumbnail(self):
"""
Return a string representation of the URL to the thumbnail
image (not the thumbnail image page).
"""
return self._getDirectURL('t')
def getSmallSquare(self):
"""
Return a string representation of the URL to the small square
image (not the small square image page).
"""
return self._getDirectURL('s')
def getSmall(self):
"""
Return a string representation of the URL to the small
image (not the small image page).
"""
return self._getDirectURL('m')
def getMedium(self):
"""
Return a string representation of the URL to the medium
image (not the medium image page).
"""
return self._getDirectURL()
def getMedium640(self):
"""
Return a string representation of the URL to the medium
image (not the medium image page).
"""
return self._getDirectURL('z')
def getLarge(self):
"""
Return a string representation of the URL to the large
image (not the large image page).
"""
return self._getDirectURL('b')
def getGalleryList(self, per_page='', page=''):
"""
get list of galleries which
contain the photo.
Galleries are returned sorted by
date which the photo was added
to the gallery
"""
if per_page > 500: # Max is 500
per_page = 500
method = "flickr.galleries.getListForPhoto"
try:
data = _doget(method, photo_id=self.id, per_page=per_page, \
page=page)
except FlickrError:
return None
return data.rsp.galleries.gallery
class Photoset(object):
"""A Flickr photoset."""
def __init__(self, id, title, primary, photos=0, description='', \
secret='', server=''):
self.__id = id
self.__title = title
self.__primary = primary
self.__description = description
self.__count = photos
self.__secret = secret
self.__server = server
id = property(lambda self: self.__id)
title = property(lambda self: self.__title)
description = property(lambda self: self.__description)
primary = property(lambda self: self.__primary)
def __len__(self):
return self.__count
def __str__(self):
return '<Flickr Photoset %s>' % self.id
def getPhotos(self):
"""Returns list of Photos."""
method = 'flickr.photosets.getPhotos'
data = _doget(method, photoset_id=self.id)
photos = data.rsp.photoset.photo
p = []
for photo in photos:
p.append(Photo(photo.id, title=photo.title, secret=photo.secret, \
server=photo.server))
return p
def editPhotos(self, photos, primary=None):
"""Edit the photos in this set.
photos - photos for set
primary - primary photo (if None will used current)
"""
method = 'flickr.photosets.editPhotos'
if primary is None:
primary = self.primary
ids = [photo.id for photo in photos]
if primary.id not in ids:
ids.append(primary.id)
_dopost(method, auth=True, photoset_id=self.id,\
primary_photo_id=primary.id,
photo_ids=ids)
self.__count = len(ids)
return True
def addPhoto(self, photo):
"""Add a photo to this set.
photo - the photo
"""
method = 'flickr.photosets.addPhoto'
_dopost(method, auth=True, photoset_id=self.id, photo_id=photo.id)
self.__count += 1
return True
def removePhoto(self, photo):
"""Remove the photo from this set.
photo - the photo
"""
method = 'flickr.photosets.removePhoto'
_dopost(method, auth=True, photoset_id=self.id, photo_id=photo.id)
self.__count = self.__count - 1
return True
def editMeta(self, title=None, description=None):
"""Set metadata for photo. (flickr.photos.setMeta)"""
method = 'flickr.photosets.editMeta'
if title is None:
title = self.title
if description is None:
description = self.description
_dopost(method, auth=True, title=title, \
description=description, photoset_id=self.id)
self.__title = title
self.__description = description
return True
#XXX: Delete isn't handled well as the python object will still exist
def delete(self):
"""Deletes the photoset.
"""
method = 'flickr.photosets.delete'
_dopost(method, auth=True, photoset_id=self.id)
return True
def create(cls, photo, title, description=''):
"""Create a new photoset.
photo - primary photo
"""
if not isinstance(photo, Photo):
raise TypeError, "Photo expected"
method = 'flickr.photosets.create'
data = _dopost(method, auth=True, title=title,\
description=description,\
primary_photo_id=photo.id)
set = Photoset(data.rsp.photoset.id, title, Photo(photo.id),
photos=1, description=description)
return set
create = classmethod(create)
class User(object):
"""A Flickr user."""
def __init__(self, id, username=None, isadmin=None, ispro=None, \
realname=None, location=None, firstdate=None, count=None):
"""id required, rest optional."""
self.__loaded = False #so we don't keep loading data
self.__id = id
self.__username = username
self.__isadmin = isadmin
self.__ispro = ispro
self.__realname = realname
self.__location = location
self.__photos_firstdate = firstdate
self.__photos_count = count
#property fu
id = property(lambda self: self._general_getattr('id'))
username = property(lambda self: self._general_getattr('username'))
isadmin = property(lambda self: self._general_getattr('isadmin'))
ispro = property(lambda self: self._general_getattr('ispro'))
realname = property(lambda self: self._general_getattr('realname'))
location = property(lambda self: self._general_getattr('location'))
photos_firstdate = property(lambda self: \
self._general_getattr('photos_firstdate'))
photos_firstdatetaken = property(lambda self: \
self._general_getattr\
('photos_firstdatetaken'))
photos_count = property(lambda self: \
self._general_getattr('photos_count'))
icon_server= property(lambda self: self._general_getattr('icon_server'))
icon_url= property(lambda self: self._general_getattr('icon_url'))
def _general_getattr(self, var):
"""Generic get attribute function."""
if getattr(self, "_%s__%s" % (self.__class__.__name__, var)) is None \
and not self.__loaded:
self._load_properties()
return getattr(self, "_%s__%s" % (self.__class__.__name__, var))
def _load_properties(self):
"""Load User properties from Flickr."""
method = 'flickr.people.getInfo'
data = _doget(method, user_id=self.__id)
self.__loaded = True
person = data.rsp.person
self.__isadmin = person.isadmin
self.__ispro = person.ispro
self.__icon_server = person.iconserver
if int(person.iconserver) > 0:
self.__icon_url = 'http://photos%s.flickr.com/buddyicons/%s.jpg' \
% (person.iconserver, self.__id)
else:
self.__icon_url = 'http://www.flickr.com/images/buddyicon.jpg'
self.__username = person.username.text
self.__realname = getattr((getattr(person, 'realname', u'')), 'text', u'')
self.__location = getattr((getattr(person, 'location', u'')), 'text', u'')
self.__photos_count = getattr((getattr(getattr(person, 'photos', None), 'count', u'')), 'text', u'')
if self.__photos_count:
self.__photos_firstdate = person.photos.firstdate.text
self.__photos_firstdatetaken = person.photos.firstdatetaken.text
else:
self.__photos_firstdate = None
self.__photos_firstdatetaken = None
def __str__(self):
return '<Flickr User %s>' % self.id
def getPhotosets(self):
"""Returns a list of Photosets."""
method = 'flickr.photosets.getList'
data = _doget(method, user_id=self.id)
sets = []
if not getattr(data.rsp.photosets, 'photoset',None):
return sets #N.B. returns an empty set
if isinstance(data.rsp.photosets.photoset, list):
for photoset in data.rsp.photosets.photoset:
sets.append(Photoset(photoset.id, photoset.title.text,\
Photo(photoset.primary),\
secret=photoset.secret, \
server=photoset.server, \
description=photoset.description.text,
photos=photoset.photos))
else:
photoset = data.rsp.photosets.photoset
sets.append(Photoset(photoset.id, photoset.title.text,\
Photo(photoset.primary),\
secret=photoset.secret, \
server=photoset.server, \
description=photoset.description.text,
photos=photoset.photos))
return sets
def getPublicFavorites(self, per_page='', page=''):
return favorites_getPublicList(user_id=self.id, per_page=per_page, \
page=page)
def getFavorites(self, per_page='', page=''):
return favorites_getList(user_id=self.id, per_page=per_page, \
page=page)
def getGalleries(self, per_page='', page=''):
return galleries_getList(user_id=self.id, per_page=per_page, \
page=page)
class Group(object):
"""Flickr Group Pool"""
def __init__(self, id, name=None, members=None, online=None,\
privacy=None, chatid=None, chatcount=None):
self.__loaded = False
self.__id = id
self.__name = name
self.__members = members
self.__online = online
self.__privacy = privacy
self.__chatid = chatid
self.__chatcount = chatcount
self.__url = None
id = property(lambda self: self._general_getattr('id'))
name = property(lambda self: self._general_getattr('name'))
members = property(lambda self: self._general_getattr('members'))
online = property(lambda self: self._general_getattr('online'))
privacy = property(lambda self: self._general_getattr('privacy'))
chatid = property(lambda self: self._general_getattr('chatid'))
chatcount = property(lambda self: self._general_getattr('chatcount'))
def _general_getattr(self, var):
"""Generic get attribute function."""
if getattr(self, "_%s__%s" % (self.__class__.__name__, var)) is None \
and not self.__loaded:
self._load_properties()
return getattr(self, "_%s__%s" % (self.__class__.__name__, var))
def _load_properties(self):
"""Loads the properties from Flickr."""
method = 'flickr.groups.getInfo'
data = _doget(method, group_id=self.id)
self.__loaded = True
group = data.rsp.group
self.__name = group.name.text
self.__description = group.description.text
self.__members = group.members.text
self.__privacy = group.privacy.text
def __str__(self):
return '<Flickr Group %s>' % self.id
def getPhotos(self, tags='', per_page='', page=''):
"""Get a list of photo objects for this group"""
method = 'flickr.groups.pools.getPhotos'
data = _doget(method, group_id=self.id, tags=tags,\
per_page=per_page, page=page)
photos = []
for photo in data.rsp.photos.photo:
photos.append(_parse_photo(photo))
return photos
def add(self, photo):
"""Adds a Photo to the group"""
method = 'flickr.groups.pools.add'
_dopost(method, auth=True, photo_id=photo.id, group_id=self.id)
return True
def remove(self, photo):
"""Remove a Photo from the group"""
method = 'flickr.groups.pools.remove'
_dopost(method, auth=True, photo_id=photo.id, group_id=self.id)
return True
class Tag(object):
def __init__(self, id, author, raw, text):
self.id = id
self.author = author
self.raw = raw
self.text = text
def __str__(self):
return '<Flickr Tag %s (%s)>' % (self.id, self.text)
class Gallery(object):
"""Represents a Flickr Gallery.
Takes gallery_id as argument.
"""
# There are other attributes a Gallery could have,
# but defining them here might create errors.
# Might be useful to define them here, though,
# if the user wants to change them when creating
# an instance.
def __init__(self, id, owner=None, title=None, description=None, \
date_create=None, date_update=None, count_photos=None, \
count_videos=None, primary_photo_id=None, \
primary_photo_server=None, primary_photo_farm=None, \
primary_photo_secret=None):
self.__loaded = False
self.__url = None
self.__id = id
self.__owner = owner
self.__title = title
self.__description = description
self.__date_create = date_create
self.__date_update = date_update
self.__count_photos = count_photos
self.__count_videos = count_videos
self.__primary_photo_id = primary_photo_id
self.__primary_photo_server = primary_photo_server
self.__primary_photo_farm = primary_photo_farm
self.__primary_photo_secret = primary_photo_secret
id = property(lambda self: self._general_getattr('id'))
url = property(lambda self: self._general_getattr('url'))
owner = property(lambda self: self._general_getattr('owner'))
title = property(lambda self: self._general_getattr('title'))
description = property(lambda self: self._general_getattr('description'))
date_create = property(lambda self: self._general_getattr('date_create'))
date_update = property(lambda self: self._general_getattr('date_update'))
count_photos = property(lambda self: self._general_getattr('count_photos'))
count_videos = property(lambda self: self._general_getattr('count_videos'))
primary_photo_id = property(lambda self: self._general_getattr('primary_photo_id'))
primary_photo_server = property(lambda self: self._general_getattr('primary_photo_server'))
primary_photo_farm = property(lambda self: self._general_getattr('primary_photo_farm'))
primary_photo_secret = property(lambda self: self._general_getattr('primary_photo_secret'))
def _general_getattr(self, var):
"""Generic get attribute function."""
if getattr(self, "_%s__%s" % (self.__class__.__name__, var)) is None \
and not self.__loaded:
self._load_properties()
return getattr(self, "_%s__%s" % (self.__class__.__name__, var))
def _load_properties(self):
"""Loads the properties from Flickr."""
method = 'flickr.galleries.getInfo'
data = _doget(method, gallery_id=self.id)
self.__loaded = True
gallery = data.rsp.gallery
self.__url = gallery.url
self.__owner = gallery.owner
self.__title = gallery.title.text
self.__description = gallery.description.text
self.__date_create = gallery.date_create
self.__date_update = gallery.date_update
self.__count_photos = gallery.count_photos
self.__count_videos = gallery.count_videos
self.__primary_photo_id = gallery.primary_photo_id
self.__primary_photo_server = gallery.primary_photo_server
self.__primary_photo_farm = gallery.primary_photo_farm
self.__primary_photo_secret = gallery.primary_photo_secret
def __str__(self):
return '<Flickr Gallery %s>' % self.id
def addPhoto(self, photo, comment=''):
"""Add a new Photo to the Gallery."""
method = 'flickr.galleries.addPhoto'
_dopost(method, auth=True, photo_id=photo.id, gallery_id=self.id, \
comment=comment)
return True
def editMeta(self, title='', description=''):
"""Modify the meta-data for a gallery.
In original API, title is required, but here, if not
specified, it will use the current title. (So it's optional)
Calling this function without any parameters will blank out the description.
"""
method = 'flickr.galleries.editMeta'
if title == '':
title = self.title
_dopost(method, auth=True, gallery_id=self.id, title=title, \
description=description)
return True
def editPhoto(self, photo, comment):
"""Change the comment for the given Photo."""
method = 'flickr.galleries.editPhoto'
_dopost(method, auth=True, gallery_id=self.id, photo_id=photo.id, \
comment=comment)
return True
def editPhotos(self, primary_photo, *photos):
"""Modify the photos in a gallery. Use this method to add,
remove and re-order photos."""
method = 'flickr.galleries.editPhotos'
photo_ids = ','.join([photo.id for photo in photos])
_dopost(method, auth=True, gallery_id=self.id, \
primary_photo_id=primary_photo.id, photo_ids=photo_ids)
return True
def getPhotos(self, per_page='', page='', **extras):
"""Return the list of photos for a gallery.
*extras (optional): A comma-delimited list of extra information
to fetch for each returned record. Currently supported fields are:
description, license, date_upload, date_taken, owner_name,
icon_server, original_format, last_update, geo, tags, machine_tags,
o_dims, views, media, path_alias, url_sq, url_t, url_s, url_m, url_o
"""
method = 'flickr.galleries.getPhotos'
extras = ','.join('%s=%s' % (i, v) for i, v in dict(extras).items())
data = _doget(method, gallery_id=self.id, per_page=per_page, \
page=page, extras=extras)
photos = {} # dict with photo instance as key and comment as value.
# if there's no comment, '' will be assigned.
for photo in data.rsp.photos.photo:
if photo.has_comment == '1':
photos[_parse_photo(photo)] = photo.comment.text
elif photo.has_comment == '0':
photos[_parse_photo(photo)] = ''
else: # Shouldn't EVER get here
raise FlickrError
return photos
#Flickr API methods
#see api docs http://www.flickr.com/services/api/
#for details of each param
#XXX: Could be Photo.search(cls)
def photos_search(user_id='', auth=False, tags='', tag_mode='', text='',\
min_upload_date='', max_upload_date='',\
min_taken_date='', max_taken_date='', \
license='', per_page='', page='', sort='',\
safe_search='', content_type='' ):
"""Returns a list of Photo objects.
If auth=True then will auth the user. Can see private etc
"""
method = 'flickr.photos.search'
data = _doget(method, auth=auth, user_id=user_id, tags=tags, text=text,\
min_upload_date=min_upload_date,\
max_upload_date=max_upload_date, \
min_taken_date=min_taken_date, \
max_taken_date=max_taken_date, \
license=license, per_page=per_page,\
page=page, sort=sort, safe_search=safe_search, \
content_type=content_type, \
tag_mode=tag_mode)
photos = []
if data.rsp.photos.__dict__.has_key('photo'):
if isinstance(data.rsp.photos.photo, list):
for photo in data.rsp.photos.photo:
photos.append(_parse_photo(photo))
else:
photos = [_parse_photo(data.rsp.photos.photo)]
return photos
def photos_search_pages(user_id='', auth=False, tags='', tag_mode='', text='',\
min_upload_date='', max_upload_date='',\
min_taken_date='', max_taken_date='', \
license='', per_page='', page='', sort=''):
"""Returns the number of pages for the previous function (photos_search())
"""
method = 'flickr.photos.search'
data = _doget(method, auth=auth, user_id=user_id, tags=tags, text=text,\
min_upload_date=min_upload_date,\
max_upload_date=max_upload_date, \
min_taken_date=min_taken_date, \
max_taken_date=max_taken_date, \
license=license, per_page=per_page,\
page=page, sort=sort)
return data.rsp.photos.pages
def photos_get_recent(extras='', per_page='', page=''):
"""http://www.flickr.com/services/api/flickr.photos.getRecent.html
"""
method = 'flickr.photos.getRecent'
data = _doget(method, extras=extras, per_page=per_page, page=page)
photos = []
if data.rsp.photos.__dict__.has_key('photo'):
if isinstance(data.rsp.photos.photo, list):
for photo in data.rsp.photos.photo:
photos.append(_parse_photo(photo))
else:
photos = [_parse_photo(data.rsp.photos.photo)]
return photos
#XXX: Could be class method in User
def people_findByEmail(email):
"""Returns User object."""
method = 'flickr.people.findByEmail'
data = _doget(method, find_email=email)
user = User(data.rsp.user.id, username=data.rsp.user.username.text)
return user
def people_findByUsername(username):
"""Returns User object."""
method = 'flickr.people.findByUsername'
data = _doget(method, username=username)
user = User(data.rsp.user.id, username=data.rsp.user.username.text)
return user
#XXX: Should probably be in User as a list User.public
def people_getPublicPhotos(user_id, per_page='', page=''):
"""Returns list of Photo objects."""
method = 'flickr.people.getPublicPhotos'
data = _doget(method, user_id=user_id, per_page=per_page, page=page)
photos = []
if hasattr(data.rsp.photos, "photo"): # Check if there are photos at all (may be been paging too far).
if isinstance(data.rsp.photos.photo, list):
for photo in data.rsp.photos.photo:
photos.append(_parse_photo(photo))
else:
photos = [_parse_photo(data.rsp.photos.photo)]
return photos
#XXX: These are also called from User
def favorites_getList(user_id='', per_page='', page=''):
"""Returns list of Photo objects."""
method = 'flickr.favorites.getList'
data = _doget(method, auth=True, user_id=user_id, per_page=per_page,\
page=page)
photos = []
if isinstance(data.rsp.photos.photo, list):
for photo in data.rsp.photos.photo:
photos.append(_parse_photo(photo))
else:
photos = [_parse_photo(data.rsp.photos.photo)]
return photos
def favorites_getPublicList(user_id, per_page='', page=''):
"""Returns list of Photo objects."""
method = 'flickr.favorites.getPublicList'
data = _doget(method, auth=False, user_id=user_id, per_page=per_page,\
page=page)
photos = []
if isinstance(data.rsp.photos.photo, list):
for photo in data.rsp.photos.photo:
photos.append(_parse_photo(photo))
else:
photos = [_parse_photo(data.rsp.photos.photo)]
return photos
def favorites_add(photo_id):
"""Add a photo to the user's favorites."""
method = 'flickr.favorites.add'
_dopost(method, auth=True, photo_id=photo_id)
return True
def favorites_remove(photo_id):
"""Remove a photo from the user's favorites."""
method = 'flickr.favorites.remove'
_dopost(method, auth=True, photo_id=photo_id)
return True
def groups_getPublicGroups():
"""Get a list of groups the auth'd user is a member of."""
method = 'flickr.groups.getPublicGroups'
data = _doget(method, auth=True)
groups = []
if isinstance(data.rsp.groups.group, list):
for group in data.rsp.groups.group:
groups.append(Group(group.id, name=group.name))
else:
group = data.rsp.groups.group
groups = [Group(group.id, name=group.name)]
return groups
def groups_pools_getGroups():
"""Get a list of groups the auth'd user can post photos to."""
method = 'flickr.groups.pools.getGroups'
data = _doget(method, auth=True)
groups = []
if isinstance(data.rsp.groups.group, list):
for group in data.rsp.groups.group:
groups.append(Group(group.id, name=group.name, \
privacy=group.privacy))
else:
group = data.rsp.groups.group
groups = [Group(group.id, name=group.name, privacy=group.privacy)]
return groups
def tags_getListUser(user_id=''):
"""Returns a list of tags for the given user (in string format)"""
method = 'flickr.tags.getListUser'
auth = user_id == ''
data = _doget(method, auth=auth, user_id=user_id)
if isinstance(data.rsp.tags.tag, list):
return [tag.text for tag in data.rsp.tags.tag]
else:
return [data.rsp.tags.tag.text]
def tags_getListUserPopular(user_id='', count=''):
"""Gets the popular tags for a user in dictionary form tag=>count"""
method = 'flickr.tags.getListUserPopular'
auth = user_id == ''
data = _doget(method, auth=auth, user_id=user_id)
result = {}
if isinstance(data.rsp.tags.tag, list):
for tag in data.rsp.tags.tag:
result[tag.text] = tag.count
else:
result[data.rsp.tags.tag.text] = data.rsp.tags.tag.count
return result
def tags_getrelated(tag):
"""Gets the related tags for given tag."""
method = 'flickr.tags.getRelated'
data = _doget(method, auth=False, tag=tag)
if isinstance(data.rsp.tags.tag, list):
return [tag.text for tag in data.rsp.tags.tag]
else:
return [data.rsp.tags.tag.text]
def contacts_getPublicList(user_id):
"""Gets the contacts (Users) for the user_id"""
method = 'flickr.contacts.getPublicList'
data = _doget(method, auth=False, user_id=user_id)
try:
if isinstance(data.rsp.contacts.contact, list):
return [User(user.nsid, username=user.username) \
for user in data.rsp.contacts.contact]
except AttributeError:
return "No users in the list"
except:
return "Unknown error"
# else:
# user = data.rsp.contacts.contact
# return [User(user.nsid, username=user.username)]
def interestingness():
method = 'flickr.interestingness.getList'
data = _doget(method)
photos = []
if isinstance(data.rsp.photos.photo , list):
for photo in data.rsp.photos.photo:
photos.append(_parse_photo(photo))
else:
photos = [_parse_photo(data.rsp.photos.photo)]
return photos
def galleries_create(title, description, primary_photo_id=None):
"""Create a new gallery."""
method = 'flickr.galleries.create'
if primary_photo_id is None:
_dopost(method, auth=True, title=title, description=description,
primary_photo_id=primary_photo_id)
elif primary_photo_id is not None:
_dopost(method, auth=True, title=title, description=description)
def galleries_getList(user_id='', per_page='', page=''):
"""Returns list of Gallery objects."""
method = 'flickr.galleries.getList'
data = _doget(method, auth=False, user_id=user_id, per_page=per_page, \
page=page)
galleries = []
if isinstance(data.rsp.galleries.gallery, list):
for gallery in data.rsp.galleries.gallery:
galleries.append(_parse_gallery(gallery))
else:
galleries = [_parse_gallery(data.rsp.galleries.gallery)]
return galleries
def test_login():
method = 'flickr.test.login'
data = _doget(method, auth=True)
user = User(data.rsp.user.id, username=data.rsp.user.username.text)
return user
def test_echo():
method = 'flickr.test.echo'
data = _doget(method)
return data.rsp.stat
#useful methods
def _doget(method, auth=False, **params):
#uncomment to check you aren't killing the flickr server
#print "***** do get %s" % method
params = _prepare_params(params)
url = '%s%s/?api_key=%s&method=%s&%s%s'% \
(HOST, API, API_KEY, method, urlencode(params),
_get_auth_url_suffix(method, auth, params))
#another useful debug print statement
if debug:
print "_doget", url
return _get_data(minidom.parse(urlopen(url)))
def _dopost(method, auth=False, **params):
#uncomment to check you aren't killing the flickr server
#print "***** do post %s" % method
params = _prepare_params(params)
url = '%s%s/?api_key=%s%s'% \
(HOST, API, API_KEY, _get_auth_url_suffix(method, auth, params))
# There's no reason this can't be str(urlencode(params)). I just wanted to
# have it the same as the rest.
payload = '%s' % (urlencode(params))
#another useful debug print statement
if debug:
print "_dopost url", url
print "_dopost payload", payload
return _get_data(minidom.parse(urlopen(url, payload)))
def _prepare_params(params):
"""Convert lists to strings with ',' between items."""
for (key, value) in params.items():
if isinstance(value, list):
params[key] = ','.join([item for item in value])
return params
def _get_data(xml):
"""Given a bunch of XML back from Flickr, we turn it into a data structure
we can deal with (after checking for errors)."""
data = unmarshal(xml)
if not data.rsp.stat == 'ok':
msg = "ERROR [%s]: %s" % (data.rsp.err.code, data.rsp.err.msg)
raise FlickrError, msg
return data
def _get_api_sig(params):
"""Generate API signature."""
token = userToken()
parameters = ['api_key', 'auth_token']
for item in params.items():
parameters.append(item[0])
parameters.sort()
api_string = [API_SECRET]
for item in parameters:
for chocolate in params.items():
if item == chocolate[0]:
api_string.append(item)
api_string.append(str(chocolate[1]))
if item == 'api_key':
api_string.append('api_key')
api_string.append(API_KEY)
if item == 'auth_token':
api_string.append('auth_token')
api_string.append(token)
api_signature = hashlib.md5(''.join(api_string)).hexdigest()
return api_signature
def _get_auth_url_suffix(method, auth, params):
"""Figure out whether we want to authorize, and if so, construct a suitable
URL suffix to pass to the Flickr API."""
authentication = False
# auth may be passed in via the API, AUTH may be set globally (in the same
# manner as API_KEY, etc). We do a few more checks than may seem necessary
# because we allow the 'auth' parameter to actually contain the
# authentication token, not just True/False.
if auth or AUTH:
token = userToken()
authentication = True
elif auth != False:
token = auth
authentication = True
elif AUTH != False:
token = AUTH
authentication = True
# If we're not authenticating, no suffix is required.
if not authentication:
return ''
full_params = params
full_params['method'] = method
return '&auth_token=%s&api_sig=%s' % (token, _get_api_sig(full_params))
def _parse_photo(photo):
"""Create a Photo object from photo data."""
owner = User(photo.owner)
title = photo.title
ispublic = photo.ispublic
isfriend = photo.isfriend
isfamily = photo.isfamily
secret = photo.secret
server = photo.server
p = Photo(photo.id, owner=owner, title=title, ispublic=ispublic,\
isfriend=isfriend, isfamily=isfamily, secret=secret, \
server=server)
return p
def _parse_gallery(gallery):
"""Create a Gallery object from gallery data."""
# This might not work!! NEEDS TESTING
url = gallery.url
owner = User(gallery.owner)
title = gallery.title.text
description = gallery.description.text
date_create = gallery.date_create
date_update = gallery.date_update
count_photos = gallery.count_photos
count_videos = gallery.count_videos
primary_photo_id = gallery.primary_photo_id
primary_photo_server = gallery.primary_photo_server
primary_photo_farm = gallery.primary_photo_farm
primary_photo_secret = gallery.primary_photo_secret
g = Gallery(gallery.id, owner=owner, title=title, description=description, \
date_create=date_create, date_update=date_update, \
count_photos=count_photos, count_videos=count_videos, \
primary_photo_id=primary_photo_id, \
primary_photo_server=primary_photo_server, \
primary_photo_farm=primary_photo_farm, \
primary_photo_secret=primary_photo_secret)
return g
#stolen methods
class Bag: pass
#unmarshal taken and modified from pyamazon.py
#makes the xml easy to work with
def unmarshal(element):
rc = Bag()
if isinstance(element, minidom.Element):
for key in element.attributes.keys():
setattr(rc, key, element.attributes[key].value)
childElements = [e for e in element.childNodes \
if isinstance(e, minidom.Element)]
if childElements:
for child in childElements:
key = child.tagName
if hasattr(rc, key):
if type(getattr(rc, key)) <> type([]):
setattr(rc, key, [getattr(rc, key)])
setattr(rc, key, getattr(rc, key) + [unmarshal(child)])
elif isinstance(child, minidom.Element) and \
(child.tagName == 'Details'):
# make the first Details element a key
setattr(rc,key,[unmarshal(child)])
#dbg: because otherwise 'hasattr' only tests
#dbg: on the second occurence: if there's a
#dbg: single return to a query, it's not a
#dbg: list. This module should always
#dbg: return a list of Details objects.
else:
setattr(rc, key, unmarshal(child))
else:
#jec: we'll have the main part of the element stored in .text
#jec: will break if tag <text> is also present
text = "".join([e.data for e in element.childNodes \
if isinstance(e, minidom.Text)])
setattr(rc, 'text', text)
return rc
#unique items from a list from the cookbook
def uniq(alist): # Fastest without order preserving
set = {}
map(set.__setitem__, alist, [])
return set.keys()
## Only the "getList" module is complete.
## Work in Progress; Nearly Finished
class Blogs():
def getList(self,auth=True):
"""blogs.getList requires READ authentication"""
# please read documentation on how to use this
method = 'flickr.blogs.getList'
if auth==True : data = _doget(method, auth=True)
if not auth==True : data = _doget(method, auth=False)
bID = []
bName = []
bNeedsPword = []
bURL = []
try:
for plog in data.rsp.blogs.blog:
bID.append(plog.id)
bName.append(plog.name)
bNeedsPword.append(plog.needspassword)
bURL.append(plog.url)
except TypeError:
try:
bID.append(data.rsp.blogs.blog.id)
bName.append(data.rsp.blogs.blog.name)
bNeedsPword.append(data.rsp.blogs.blog.needspassword)
bURL.append(data.rsp.blogs.blog.url)
except AttributeError:
return "AttributeError, unexplained!"
except:
return "Unknown error!"
except AttributeError:
return "There are no blogs!"
myReturn = [bID,bName,bNeedsPword,bURL]
return myReturn
def postPhoto(self, blogID, photoID, title, description, bpassword):
"""blogs.postPhoto requires WRITE authentication"""
method = 'flickr.blogs.postPhoto'
return None
class Urls():
def getUserPhotosURL(userid):
"""Returns user URL in an array (to access, use array[1])"""
method = 'flickr.urls.getUserPhotos'
data = _doget(method, user_id=userid)
return [data.rsp.user.nsid,data.rsp.user.url]
class Auth():
def getFrob(self):
"""Returns a frob that is used in authentication"""
method = 'flickr.auth.getFrob'
sig_str = API_SECRET + 'api_key' + API_KEY + 'method' + method
signature_hash = hashlib.md5(sig_str).hexdigest()
data = _doget(method, auth=False, api_sig=signature_hash)
return data.rsp.frob.text
def loginLink(self, permission, frob):
"""Generates a link that the user should be sent to"""
myAuth = Auth()
sig_str = API_SECRET + 'api_key' + API_KEY + 'frob' + frob + 'perms' + permission
signature_hash = hashlib.md5(sig_str).hexdigest()
perms = permission
link = "http://flickr.com/services/auth/?api_key=%s&perms=%s&frob=%s&api_sig=%s" % (API_KEY, perms, frob, signature_hash)
return link
def getToken(self, frob):
"""This token is what needs to be used in future API calls"""
method = 'flickr.auth.getToken'
sig_str = API_SECRET + 'api_key' + API_KEY + 'frob' + frob + 'method' + method
signature_hash = hashlib.md5(sig_str).hexdigest()
data = _doget(method, auth=False, api_sig=signature_hash,
api_key=API_KEY, frob=frob)
return data.rsp.auth.token.text
def userToken():
global API_TOKEN
# This method allows you flickr.py to retrive the saved token
# as once the token for a program has been got from flickr,
# it cannot be got again, so flickr.py saves it in a file
# called token.txt (default) somewhere.
if API_TOKEN is not None:
return API_TOKEN
if not tokenPath == '':
f = file(os.path.join(tokenPath, tokenFile), 'r')
else:
f = file(tokenFile, 'r')
API_TOKEN = f.read()
f.close()
return API_TOKEN
def getUserPhotosURL(userid):
"""Returns user URL in an array (to access, use array[1])"""
# This addition has been added upon request of
# nsteinmetz. It will be "cleaned up" at another
# time.
method = 'flickr.urls.getUserPhotos'
data = _doget(method, user_id=userid)
userurl = [data.rsp.user.nsid,data.rsp.user.url]
return userurl
if __name__ == '__main__':
print test_echo()
|
mit
|
[
624,
272,
289,
8442,
82,
14,
647,
272,
1898,
8353,
13,
7968,
1603,
14015,
8465,
285,
415,
665,
74,
14015,
32,
74,
14015,
4925,
415,
14,
815,
30,
272,
20825,
1898,
10219,
13,
9300,
7135,
609,
1458,
869,
13747,
834,
665,
743,
609,
72,
500,
79,
32,
6799,
14,
957,
30,
199,
199,
24571,
4141,
2281,
7402,
48,
5177,
2428,
3408,
1634,
1821,
3826,
12,
2401,
603,
3448,
6262,
199,
1439,
2252,
1149,
12,
10362,
1914,
19679,
1549,
5266,
3027,
5406,
1149,
1621,
1821,
9683,
12,
4319,
26594,
4319,
5749,
12840,
199,
3649,
20709,
21786,
39,
9591,
1634,
17632,
3234,
1772,
5363,
5848,
14,
199,
199,
6965,
13,
614,
13,
713,
523,
799,
3539,
5936,
641,
314,
1526,
14,
2424,
1526,
570,
14,
199,
199,
9488,
13,
713,
13,
1196,
523,
2104,
376,
1536,
475,
1434,
3254,
769,
12,
8749,
1937,
26,
523,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
70,
8442,
82,
647,
15,
6797,
15,
52,
19657,
1296,
819,
2104,
2556,
641,
4212,
370,
675,
314,
15995,
523,
859,
12,
299,
274,
261,
1937,
26,
523,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
70,
8442,
82,
647,
15,
6797,
15,
1899,
10348,
199,
199,
7968,
13,
713,
13,
1167,
523,
4693,
1857,
12385,
687,
23207,
331,
6423,
938,
436,
644,
79,
276,
5975,
1804,
1996,
316,
14,
199,
199,
624,
199,
199,
363,
2502,
363,
275,
298,
42,
14015,
8465,
285,
415,
665,
74,
14015,
32,
74,
14015,
4925,
415,
14,
815,
4335,
199,
363,
1023,
363,
275,
7880,
26176,
17351,
199,
363,
602,
363,
275,
7880,
2506,
17351,
199,
363,
7307,
363,
275,
298,
7384,
26,
8353,
13,
6542,
1603,
14015,
8465,
285,
415,
27,
20825,
26,
10219,
13,
9300,
7135,
609,
1458,
869,
13747,
834,
27,
20825,
26,
7760,
6061,
264,
73,
812,
76,
350,
812,
645,
759,
85,
2,
199,
199,
504,
4011,
492,
16511,
12,
18279,
199,
504,
2748,
14,
4556,
492,
19165,
199,
646,
8337,
199,
646,
747,
199,
199,
5449,
275,
283,
2859,
921,
70,
8442,
82,
14,
957,
7,
199,
3735,
275,
1994,
5950,
15,
3911,
7,
199,
199,
3,
663,
3520,
2348,
503,
1808,
289,
8442,
82,
14,
3735,
63,
3078,
315,
2195,
4223,
199,
3735,
63,
8803,
275,
488,
199,
3735,
63,
3078,
275,
2125,
199,
3735,
63,
12961,
275,
2125,
199,
2123,
275,
488,
199,
2060,
275,
488,
199,
5580,
275,
756,
199,
1757,
275,
756,
199,
199,
3,
710,
2163,
499,
2860,
787,
1454,
11012,
340,
6299,
365,
1202,
199,
199,
3,
642,
883,
506,
663,
2348,
503,
1808,
289,
8442,
82,
14,
1418,
2042,
315,
2195,
4223,
199,
3,
642,
365,
314,
931,
370,
314,
4922,
3035,
1526,
1173,
334,
885,
26,
1526,
14,
2424,
9,
199,
1418,
2042,
275,
2125,
199,
199,
3,
642,
883,
506,
663,
2348,
503,
1808,
289,
8442,
82,
14,
1418,
1173,
315,
2195,
4223,
199,
3,
642,
365,
314,
536,
402,
314,
570,
3035,
314,
5489,
1526,
14,
199,
1418,
1173,
275,
283,
1418,
14,
2424,
7,
421,
199,
533,
481,
8442,
82,
547,
8,
1726,
304,
986,
199,
199,
533,
30808,
8,
785,
304,
272,
408,
18089,
282,
481,
8442,
82,
30808,
1041,
339,
636,
6753,
275,
788,
344,
297,
283,
4731,
297,
283,
1000,
297,
283,
70,
5362,
297,
283,
374,
23874,
297,
283,
1682,
297,
283,
15362,
297,
2116,
283,
4597,
297,
283,
602,
21760,
297,
283,
602,
28549,
297,
283,
28549,
26655,
22504,
297,
2116,
283,
1213,
297,
283,
1802,
297,
283,
374,
3455,
297,
283,
374,
23472,
297,
283,
374,
6606,
297,
2116,
283,
2425,
3349,
297,
283,
2425,
525,
2024,
297,
283,
6223,
297,
283,
2969,
297,
283,
8220,
3349,
297,
2116,
283,
8220,
525,
2024,
297,
283,
633,
418,
339,
327,
13933,
26,
869,
13458,
5836,
488,
7859,
1133,
7675,
8826,
272,
347,
636,
826,
721,
277,
12,
1305,
12,
5771,
29,
403,
12,
1434,
19044,
29,
403,
12,
971,
326,
2538,
29,
403,
12,
1369,
29,
403,
12,
365,
3455,
29,
403,
12,
971,
326,
365,
23472,
29,
403,
12,
365,
6606,
29,
403,
12,
883,
3349,
29,
403,
12,
971,
326,
883,
525,
2024,
29,
403,
12,
6786,
29,
403,
12,
3762,
29,
403,
12,
7565,
29,
403,
12,
971,
326,
365,
23874,
29,
403,
12,
1654,
29,
403,
12,
289,
5362,
29,
403,
12,
4190,
29,
403,
12,
971,
326,
13038,
29,
403,
12,
1166,
29,
403,
304,
267,
408,
13757,
4165,
1305,
12,
4618,
365,
2716,
1041,
267,
291,
855,
4591,
275,
756,
267,
291,
855,
2425,
3349,
275,
883,
3349,
267,
291,
855,
2425,
525,
2024,
275,
883,
525,
2024,
267,
291,
855,
6223,
275,
6786,
267,
291,
855,
602,
19044,
275,
1434,
19044,
267,
291,
855,
1802,
275,
1369,
267,
291,
855,
344,
275,
1305,
267,
291,
855,
1682,
275,
4190,
267,
291,
855,
374,
6606,
275,
365,
6606,
267,
291,
855,
374,
23874,
275,
365,
23874,
267,
291,
855,
374,
23472,
275,
365,
23472,
267,
291,
855,
374,
3455,
275,
365,
3455,
267,
291,
855,
4597,
275,
5771,
267,
291,
855,
15362,
275,
13038,
267,
291,
855,
4731,
275,
7565,
267,
291,
855,
1000,
275,
1654,
267,
291,
855,
70,
5362,
275,
289,
5362,
267,
291,
855,
2969,
275,
3762,
267,
291,
855,
1213,
275,
2538,
398,
291,
855,
602,
21760,
275,
488,
267,
291,
855,
602,
28549,
275,
488,
267,
291,
855,
28549,
26655,
22504,
275,
488,
267,
291,
855,
8220,
3349,
275,
488,
267,
291,
855,
8220,
525,
2024,
275,
488,
267,
291,
855,
633,
275,
488,
339,
347,
636,
10202,
721,
277,
12,
790,
12,
574,
304,
267,
340,
790,
315,
291,
855,
533,
4914,
6753,
26,
288,
746,
4281,
480,
1918,
2225,
450,
83,
365,
1586,
13,
2118,
2122,
450,
790,
9,
267,
587,
26,
288,
1613,
8,
21258,
12,
291,
2843,
10202,
721,
498,
12,
574,
9,
339,
347,
636,
5675,
721,
277,
12,
790,
304,
267,
340,
440,
291,
855,
4591,
26,
288,
291,
423,
912,
63,
3282,
342,
267,
340,
790,
315,
291,
855,
533,
4914,
6753,
26,
288,
372,
1613,
8,
21258,
12,
291,
2843,
18480,
29093,
4970,
83,
363,
5,
83,
2,
450,
334,
277
] |
[
272,
289,
8442,
82,
14,
647,
272,
1898,
8353,
13,
7968,
1603,
14015,
8465,
285,
415,
665,
74,
14015,
32,
74,
14015,
4925,
415,
14,
815,
30,
272,
20825,
1898,
10219,
13,
9300,
7135,
609,
1458,
869,
13747,
834,
665,
743,
609,
72,
500,
79,
32,
6799,
14,
957,
30,
199,
199,
24571,
4141,
2281,
7402,
48,
5177,
2428,
3408,
1634,
1821,
3826,
12,
2401,
603,
3448,
6262,
199,
1439,
2252,
1149,
12,
10362,
1914,
19679,
1549,
5266,
3027,
5406,
1149,
1621,
1821,
9683,
12,
4319,
26594,
4319,
5749,
12840,
199,
3649,
20709,
21786,
39,
9591,
1634,
17632,
3234,
1772,
5363,
5848,
14,
199,
199,
6965,
13,
614,
13,
713,
523,
799,
3539,
5936,
641,
314,
1526,
14,
2424,
1526,
570,
14,
199,
199,
9488,
13,
713,
13,
1196,
523,
2104,
376,
1536,
475,
1434,
3254,
769,
12,
8749,
1937,
26,
523,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
70,
8442,
82,
647,
15,
6797,
15,
52,
19657,
1296,
819,
2104,
2556,
641,
4212,
370,
675,
314,
15995,
523,
859,
12,
299,
274,
261,
1937,
26,
523,
1455,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
70,
8442,
82,
647,
15,
6797,
15,
1899,
10348,
199,
199,
7968,
13,
713,
13,
1167,
523,
4693,
1857,
12385,
687,
23207,
331,
6423,
938,
436,
644,
79,
276,
5975,
1804,
1996,
316,
14,
199,
199,
624,
199,
199,
363,
2502,
363,
275,
298,
42,
14015,
8465,
285,
415,
665,
74,
14015,
32,
74,
14015,
4925,
415,
14,
815,
4335,
199,
363,
1023,
363,
275,
7880,
26176,
17351,
199,
363,
602,
363,
275,
7880,
2506,
17351,
199,
363,
7307,
363,
275,
298,
7384,
26,
8353,
13,
6542,
1603,
14015,
8465,
285,
415,
27,
20825,
26,
10219,
13,
9300,
7135,
609,
1458,
869,
13747,
834,
27,
20825,
26,
7760,
6061,
264,
73,
812,
76,
350,
812,
645,
759,
85,
2,
199,
199,
504,
4011,
492,
16511,
12,
18279,
199,
504,
2748,
14,
4556,
492,
19165,
199,
646,
8337,
199,
646,
747,
199,
199,
5449,
275,
283,
2859,
921,
70,
8442,
82,
14,
957,
7,
199,
3735,
275,
1994,
5950,
15,
3911,
7,
199,
199,
3,
663,
3520,
2348,
503,
1808,
289,
8442,
82,
14,
3735,
63,
3078,
315,
2195,
4223,
199,
3735,
63,
8803,
275,
488,
199,
3735,
63,
3078,
275,
2125,
199,
3735,
63,
12961,
275,
2125,
199,
2123,
275,
488,
199,
2060,
275,
488,
199,
5580,
275,
756,
199,
1757,
275,
756,
199,
199,
3,
710,
2163,
499,
2860,
787,
1454,
11012,
340,
6299,
365,
1202,
199,
199,
3,
642,
883,
506,
663,
2348,
503,
1808,
289,
8442,
82,
14,
1418,
2042,
315,
2195,
4223,
199,
3,
642,
365,
314,
931,
370,
314,
4922,
3035,
1526,
1173,
334,
885,
26,
1526,
14,
2424,
9,
199,
1418,
2042,
275,
2125,
199,
199,
3,
642,
883,
506,
663,
2348,
503,
1808,
289,
8442,
82,
14,
1418,
1173,
315,
2195,
4223,
199,
3,
642,
365,
314,
536,
402,
314,
570,
3035,
314,
5489,
1526,
14,
199,
1418,
1173,
275,
283,
1418,
14,
2424,
7,
421,
199,
533,
481,
8442,
82,
547,
8,
1726,
304,
986,
199,
199,
533,
30808,
8,
785,
304,
272,
408,
18089,
282,
481,
8442,
82,
30808,
1041,
339,
636,
6753,
275,
788,
344,
297,
283,
4731,
297,
283,
1000,
297,
283,
70,
5362,
297,
283,
374,
23874,
297,
283,
1682,
297,
283,
15362,
297,
2116,
283,
4597,
297,
283,
602,
21760,
297,
283,
602,
28549,
297,
283,
28549,
26655,
22504,
297,
2116,
283,
1213,
297,
283,
1802,
297,
283,
374,
3455,
297,
283,
374,
23472,
297,
283,
374,
6606,
297,
2116,
283,
2425,
3349,
297,
283,
2425,
525,
2024,
297,
283,
6223,
297,
283,
2969,
297,
283,
8220,
3349,
297,
2116,
283,
8220,
525,
2024,
297,
283,
633,
418,
339,
327,
13933,
26,
869,
13458,
5836,
488,
7859,
1133,
7675,
8826,
272,
347,
636,
826,
721,
277,
12,
1305,
12,
5771,
29,
403,
12,
1434,
19044,
29,
403,
12,
971,
326,
2538,
29,
403,
12,
1369,
29,
403,
12,
365,
3455,
29,
403,
12,
971,
326,
365,
23472,
29,
403,
12,
365,
6606,
29,
403,
12,
883,
3349,
29,
403,
12,
971,
326,
883,
525,
2024,
29,
403,
12,
6786,
29,
403,
12,
3762,
29,
403,
12,
7565,
29,
403,
12,
971,
326,
365,
23874,
29,
403,
12,
1654,
29,
403,
12,
289,
5362,
29,
403,
12,
4190,
29,
403,
12,
971,
326,
13038,
29,
403,
12,
1166,
29,
403,
304,
267,
408,
13757,
4165,
1305,
12,
4618,
365,
2716,
1041,
267,
291,
855,
4591,
275,
756,
267,
291,
855,
2425,
3349,
275,
883,
3349,
267,
291,
855,
2425,
525,
2024,
275,
883,
525,
2024,
267,
291,
855,
6223,
275,
6786,
267,
291,
855,
602,
19044,
275,
1434,
19044,
267,
291,
855,
1802,
275,
1369,
267,
291,
855,
344,
275,
1305,
267,
291,
855,
1682,
275,
4190,
267,
291,
855,
374,
6606,
275,
365,
6606,
267,
291,
855,
374,
23874,
275,
365,
23874,
267,
291,
855,
374,
23472,
275,
365,
23472,
267,
291,
855,
374,
3455,
275,
365,
3455,
267,
291,
855,
4597,
275,
5771,
267,
291,
855,
15362,
275,
13038,
267,
291,
855,
4731,
275,
7565,
267,
291,
855,
1000,
275,
1654,
267,
291,
855,
70,
5362,
275,
289,
5362,
267,
291,
855,
2969,
275,
3762,
267,
291,
855,
1213,
275,
2538,
398,
291,
855,
602,
21760,
275,
488,
267,
291,
855,
602,
28549,
275,
488,
267,
291,
855,
28549,
26655,
22504,
275,
488,
267,
291,
855,
8220,
3349,
275,
488,
267,
291,
855,
8220,
525,
2024,
275,
488,
267,
291,
855,
633,
275,
488,
339,
347,
636,
10202,
721,
277,
12,
790,
12,
574,
304,
267,
340,
790,
315,
291,
855,
533,
4914,
6753,
26,
288,
746,
4281,
480,
1918,
2225,
450,
83,
365,
1586,
13,
2118,
2122,
450,
790,
9,
267,
587,
26,
288,
1613,
8,
21258,
12,
291,
2843,
10202,
721,
498,
12,
574,
9,
339,
347,
636,
5675,
721,
277,
12,
790,
304,
267,
340,
440,
291,
855,
4591,
26,
288,
291,
423,
912,
63,
3282,
342,
267,
340,
790,
315,
291,
855,
533,
4914,
6753,
26,
288,
372,
1613,
8,
21258,
12,
291,
2843,
18480,
29093,
4970,
83,
363,
5,
83,
2,
450,
334,
277,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fintech-circle/edx-platform
|
openedx/core/djangoapps/cors_csrf/views.py
|
24
|
2497
|
"""Views for enabling cross-domain requests. """
import json
import logging
from django.conf import settings
from django.http import HttpResponseNotFound
from django.views.decorators.cache import cache_page
from edxmako.shortcuts import render_to_response
from .models import XDomainProxyConfiguration
log = logging.getLogger(__name__)
XDOMAIN_PROXY_CACHE_TIMEOUT = getattr(settings, 'XDOMAIN_PROXY_CACHE_TIMEOUT', 60 * 15)
@cache_page(XDOMAIN_PROXY_CACHE_TIMEOUT)
def xdomain_proxy(request): # pylint: disable=unused-argument
"""Serve the xdomain proxy page.
Internet Explorer 9 does not send cookie information with CORS,
which means we can't make cross-domain POST requests that
require authentication (for example, from the course details
page on the marketing site to the enrollment API
to auto-enroll a user in an "honor" track).
The XDomain library [https://github.com/jpillora/xdomain]
provides an alternative to using CORS.
The library works as follows:
1) A static HTML file ("xdomain_proxy.html") is served from courses.edx.org.
The file includes JavaScript and a domain whitelist.
2) The course details page (on edx.org) creates an invisible iframe
that loads the proxy HTML file.
3) A JS shim library on the course details page intercepts
AJAX requests and communicates with JavaScript on the iframed page.
The iframed page then proxies the request to the LMS.
Since the iframed page is served from courses.edx.org,
this is a same-domain request, so all cookies for the domain
are sent along with the request.
You can enable this feature and configure the domain whitelist
using Django admin.
"""
config = XDomainProxyConfiguration.current()
if not config.enabled:
return HttpResponseNotFound()
allowed_domains = []
for domain in config.whitelist.split("\n"):
if domain.strip():
allowed_domains.append(domain.strip())
if not allowed_domains:
log.warning(
u"No whitelist configured for cross-domain proxy. "
u"You can configure the whitelist in Django Admin "
u"using the XDomainProxyConfiguration model."
)
return HttpResponseNotFound()
context = {
'xdomain_masters': json.dumps({
domain: '*'
for domain in allowed_domains
})
}
return render_to_response('cors_csrf/xdomain_proxy.html', context)
|
agpl-3.0
|
[
624,
21180,
367,
29310,
8059,
13,
2261,
4145,
14,
408,
199,
646,
2022,
199,
646,
2050,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1014,
492,
6183,
4667,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1637,
492,
2581,
63,
1606,
199,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
199,
504,
1275,
992,
492,
1323,
7705,
4936,
5688,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
56,
7378,
63,
20026,
63,
8677,
63,
8899,
275,
2519,
8,
1751,
12,
283,
56,
7378,
63,
20026,
63,
8677,
63,
8899,
297,
5212,
627,
4114,
9,
421,
199,
32,
1637,
63,
1606,
8,
56,
7378,
63,
20026,
63,
8677,
63,
8899,
9,
199,
318,
671,
2261,
63,
3280,
8,
1069,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
408,
1505,
432,
314,
671,
2261,
4566,
2034,
14,
339,
22026,
7910,
22732,
1749,
1630,
440,
3222,
5494,
2556,
543,
445,
4149,
12,
272,
1314,
4910,
781,
883,
1133,
1852,
8059,
13,
2261,
8761,
4145,
626,
272,
4409,
6299,
334,
509,
2893,
12,
687,
314,
2518,
2436,
272,
2034,
641,
314,
2216,
13800,
4770,
370,
314,
14869,
3261,
272,
370,
2599,
13,
14695,
282,
922,
315,
376,
298,
19923,
2,
4426,
680,
339,
710,
1323,
7705,
3555,
359,
2859,
921,
5031,
14,
957,
15,
11538,
778,
11131,
15,
88,
2261,
61,
272,
6571,
376,
13943,
370,
1808,
445,
4149,
14,
339,
710,
3555,
5419,
465,
11924,
26,
339,
413,
9,
437,
2955,
4163,
570,
1689,
88,
2261,
63,
3280,
14,
1360,
531,
365,
19733,
687,
13588,
14,
8268,
14,
1308,
14,
2126,
710,
570,
6952,
15250,
436,
282,
2881,
22671,
14,
339,
499,
9,
710,
2518,
2436,
2034,
334,
265,
22435,
14,
1308,
9,
8491,
376,
315,
6604,
340,
1186,
2126,
626,
14404,
314,
4566,
4163,
570,
14,
339,
650,
9,
437,
18001,
25905,
3555,
641,
314,
2518,
2436,
2034,
13926,
83,
2126,
437,
42,
9839,
4145,
436,
13882,
2335,
543,
15250,
641,
314,
340,
1186,
68,
2034,
14,
2126,
710,
340,
1186,
68,
2034,
2066,
14942,
314,
1056,
370,
314,
27540,
14,
2126,
9336,
314,
340,
1186,
68,
2034,
365,
19733,
687,
13588,
14,
8268,
14,
1308,
12,
2126,
642,
365,
282,
2011,
13,
2261,
1056,
12,
880,
1006,
10049,
367,
314,
2881,
2126,
787,
4847,
3180,
543,
314,
1056,
14,
339,
2047,
883,
4756,
642,
3878,
436,
7908,
314,
2881,
22671,
272,
1808,
5634,
4628,
14,
339,
408,
272,
1101,
275,
1323,
7705,
4936,
5688,
14,
1818,
342,
272,
340,
440,
1101,
14,
3827,
26,
267,
372,
6183,
4667,
342,
339,
4370,
63,
9756,
275,
942,
272,
367,
2881,
315,
1101,
14,
14189,
14,
1294,
4582,
78,
2349,
267,
340,
2881,
14,
1913,
837,
288,
4370,
63,
9756,
14,
740,
8,
2261,
14,
1913,
1012,
339,
340,
440,
4370,
63,
9756,
26,
267,
943,
14,
3764,
8,
288,
399,
2,
1944,
22671,
7526,
367,
8059,
13,
2261,
4566,
14,
298,
288,
399,
2,
5556,
883,
7908,
314,
22671,
315,
5634,
9516,
298,
288,
399,
2,
4941,
314,
1323,
7705,
4936,
5688,
1402,
2122,
267,
776,
267,
372,
6183,
4667,
342,
339,
1067,
275,
469,
267,
283,
88,
2261,
63,
5892,
878,
356,
2022,
14,
4180,
2561,
288,
2881,
26,
13626,
288,
367,
2881,
315,
4370,
63,
9756,
267,
3828,
272,
789,
272,
372,
3795,
63,
475,
63,
1310,
360,
30967,
63,
10088,
15,
88,
2261,
63,
3280,
14,
1360,
297,
1067,
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
] |
[
21180,
367,
29310,
8059,
13,
2261,
4145,
14,
408,
199,
646,
2022,
199,
646,
2050,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1014,
492,
6183,
4667,
199,
504,
1639,
14,
4196,
14,
11582,
14,
1637,
492,
2581,
63,
1606,
199,
199,
504,
22435,
19491,
14,
17469,
492,
3795,
63,
475,
63,
1310,
199,
199,
504,
1275,
992,
492,
1323,
7705,
4936,
5688,
199,
199,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
56,
7378,
63,
20026,
63,
8677,
63,
8899,
275,
2519,
8,
1751,
12,
283,
56,
7378,
63,
20026,
63,
8677,
63,
8899,
297,
5212,
627,
4114,
9,
421,
199,
32,
1637,
63,
1606,
8,
56,
7378,
63,
20026,
63,
8677,
63,
8899,
9,
199,
318,
671,
2261,
63,
3280,
8,
1069,
304,
221,
327,
4287,
26,
3507,
29,
8618,
13,
2094,
272,
408,
1505,
432,
314,
671,
2261,
4566,
2034,
14,
339,
22026,
7910,
22732,
1749,
1630,
440,
3222,
5494,
2556,
543,
445,
4149,
12,
272,
1314,
4910,
781,
883,
1133,
1852,
8059,
13,
2261,
8761,
4145,
626,
272,
4409,
6299,
334,
509,
2893,
12,
687,
314,
2518,
2436,
272,
2034,
641,
314,
2216,
13800,
4770,
370,
314,
14869,
3261,
272,
370,
2599,
13,
14695,
282,
922,
315,
376,
298,
19923,
2,
4426,
680,
339,
710,
1323,
7705,
3555,
359,
2859,
921,
5031,
14,
957,
15,
11538,
778,
11131,
15,
88,
2261,
61,
272,
6571,
376,
13943,
370,
1808,
445,
4149,
14,
339,
710,
3555,
5419,
465,
11924,
26,
339,
413,
9,
437,
2955,
4163,
570,
1689,
88,
2261,
63,
3280,
14,
1360,
531,
365,
19733,
687,
13588,
14,
8268,
14,
1308,
14,
2126,
710,
570,
6952,
15250,
436,
282,
2881,
22671,
14,
339,
499,
9,
710,
2518,
2436,
2034,
334,
265,
22435,
14,
1308,
9,
8491,
376,
315,
6604,
340,
1186,
2126,
626,
14404,
314,
4566,
4163,
570,
14,
339,
650,
9,
437,
18001,
25905,
3555,
641,
314,
2518,
2436,
2034,
13926,
83,
2126,
437,
42,
9839,
4145,
436,
13882,
2335,
543,
15250,
641,
314,
340,
1186,
68,
2034,
14,
2126,
710,
340,
1186,
68,
2034,
2066,
14942,
314,
1056,
370,
314,
27540,
14,
2126,
9336,
314,
340,
1186,
68,
2034,
365,
19733,
687,
13588,
14,
8268,
14,
1308,
12,
2126,
642,
365,
282,
2011,
13,
2261,
1056,
12,
880,
1006,
10049,
367,
314,
2881,
2126,
787,
4847,
3180,
543,
314,
1056,
14,
339,
2047,
883,
4756,
642,
3878,
436,
7908,
314,
2881,
22671,
272,
1808,
5634,
4628,
14,
339,
408,
272,
1101,
275,
1323,
7705,
4936,
5688,
14,
1818,
342,
272,
340,
440,
1101,
14,
3827,
26,
267,
372,
6183,
4667,
342,
339,
4370,
63,
9756,
275,
942,
272,
367,
2881,
315,
1101,
14,
14189,
14,
1294,
4582,
78,
2349,
267,
340,
2881,
14,
1913,
837,
288,
4370,
63,
9756,
14,
740,
8,
2261,
14,
1913,
1012,
339,
340,
440,
4370,
63,
9756,
26,
267,
943,
14,
3764,
8,
288,
399,
2,
1944,
22671,
7526,
367,
8059,
13,
2261,
4566,
14,
298,
288,
399,
2,
5556,
883,
7908,
314,
22671,
315,
5634,
9516,
298,
288,
399,
2,
4941,
314,
1323,
7705,
4936,
5688,
1402,
2122,
267,
776,
267,
372,
6183,
4667,
342,
339,
1067,
275,
469,
267,
283,
88,
2261,
63,
5892,
878,
356,
2022,
14,
4180,
2561,
288,
2881,
26,
13626,
288,
367,
2881,
315,
4370,
63,
9756,
267,
3828,
272,
789,
272,
372,
3795,
63,
475,
63,
1310,
360,
30967,
63,
10088,
15,
88,
2261,
63,
3280,
14,
1360,
297,
1067,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Wikia/sparrow
|
apps/tasks/models.py
|
1
|
2950
|
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models
import django.dispatch
from django.utils.translation import ugettext as _
from django.core.urlresolvers import reverse
from django_enumfield import enum
import celery.states
from common.utils import build_absolute_uri
from testrunner.test_suites.simple import SimpleTestSuite
from .signals import task_status_changed
class TaskStatus(enum.Enum):
PENDING = 0
IN_PROGRESS = 1
DONE = 2
ERROR = -1
labels = {
PENDING: _('Pending'),
IN_PROGRESS: _('In progress'),
DONE: _('Done'),
ERROR: _('Error'),
}
@classmethod
def from_celery_status(cls, celery_status):
if celery_status == celery.states.PENDING:
return cls.PENDING
if celery_status in (celery.states.RECEIVED, celery.states.STARTED):
return cls.IN_PROGRESS
if celery_status in celery.states.EXCEPTION_STATES:
return cls.ERROR
if celery_status == celery.states.SUCCESS:
return cls.DONE
raise ValueError('Unknown status: {0}'.format(celery_status))
class Task(models.Model):
id = models.AutoField(primary_key=True)
test_run = models.ForeignKey('test_runs.TestRun', related_name='tasks')
created = models.DateTimeField(auto_now_add=True)
status = enum.EnumField(TaskStatus, default=TaskStatus.PENDING)
job_id = models.UUIDField(blank=True, null=True)
__original_status = None
def __init__(self, *args, **kwargs):
super(Task, self).__init__(*args, **kwargs)
self.__original_status = self.status
def save(self, *args, **kwargs):
super(Task, self).save(*args, **kwargs)
if self.__original_status != self.status:
task_status_changed.send(self.__class__, instance=self)
self.__original_status = self.status
def run(self):
results_uri=build_absolute_uri(reverse('testresult-list'))
raw_result_uri=build_absolute_uri(reverse('testrawresult-list'))
task_uri=build_absolute_uri(reverse('task-detail', args=[self.id, ]))
test_run_uri=build_absolute_uri(reverse('testrun-detail', args=[self.test_run_id, ]))
test_run = self.test_run
suite = SimpleTestSuite()
result = suite.run(
task_id=self.id,
retries=test_run.retries,
url=test_run.test_run_uri,
app_commit=test_run.app_commit,
config_commit=test_run.config_commit,
results_uri=results_uri,
raw_result_uri=raw_result_uri,
task_uri=task_uri,
test_run_uri=test_run_uri
)
self.job_id = result.id
self.status = TaskStatus.from_celery_status(result.status)
self.save()
def __repr__(self):
return "{0} #{1}".format(self.__class__.__name__, self.id)
__unicode__ = __repr__
__str__ = __repr__
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
646,
1639,
14,
6052,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
63,
4869,
698,
492,
4952,
199,
646,
22748,
14,
4981,
199,
504,
2863,
14,
1208,
492,
1900,
63,
6116,
63,
2302,
199,
199,
504,
511,
5933,
14,
396,
63,
27034,
14,
4129,
492,
5870,
10591,
199,
199,
504,
1275,
10458,
492,
2120,
63,
1205,
63,
2489,
4388,
199,
533,
8495,
3694,
8,
4869,
14,
5081,
304,
272,
510,
15219,
275,
378,
272,
1621,
63,
24547,
275,
413,
272,
577,
4817,
275,
499,
272,
12539,
275,
446,
17,
339,
3628,
275,
469,
267,
510,
15219,
26,
4018,
15960,
659,
267,
1621,
63,
24547,
26,
4018,
607,
6696,
659,
267,
577,
4817,
26,
4018,
10759,
659,
267,
12539,
26,
4018,
547,
659,
272,
789,
339,
768,
3744,
272,
347,
687,
63,
23593,
63,
1205,
8,
1886,
12,
22748,
63,
1205,
304,
267,
340,
22748,
63,
1205,
508,
22748,
14,
4981,
14,
21243,
26,
288,
372,
843,
14,
21243,
267,
340,
22748,
63,
1205,
315,
334,
23593,
14,
4981,
14,
28467,
30487,
12,
22748,
14,
4981,
14,
32385,
304,
288,
372,
843,
14,
568,
63,
24547,
267,
340,
22748,
63,
1205,
315,
22748,
14,
4981,
14,
15375,
63,
23162,
26,
288,
372,
843,
14,
3170,
267,
340,
22748,
63,
1205,
508,
22748,
14,
4981,
14,
12779,
26,
288,
372,
843,
14,
22162,
398,
746,
1722,
360,
5912,
2004,
26,
469,
16,
5285,
908,
8,
23593,
63,
1205,
430,
421,
199,
533,
8495,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
511,
63,
1065,
275,
1709,
14,
3190,
360,
396,
63,
10802,
14,
21228,
297,
4048,
63,
354,
534,
5054,
358,
272,
2737,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
2004,
275,
4952,
14,
5081,
792,
8,
4476,
3694,
12,
849,
29,
4476,
3694,
14,
21243,
9,
272,
3906,
63,
344,
275,
1709,
14,
8757,
792,
8,
2500,
29,
549,
12,
2973,
29,
549,
9,
339,
636,
5043,
63,
1205,
275,
488,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
4476,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
398,
291,
855,
5043,
63,
1205,
275,
291,
14,
1205,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
398,
1613,
8,
4476,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
398,
340,
291,
855,
5043,
63,
1205,
1137,
291,
14,
1205,
26,
288,
2120,
63,
1205,
63,
2489,
14,
2254,
8,
277,
855,
533,
3108,
1256,
29,
277,
9,
288,
291,
855,
5043,
63,
1205,
275,
291,
14,
1205,
339,
347,
1255,
8,
277,
304,
267,
2058,
63,
2302,
29,
1506,
63,
6116,
63,
2302,
8,
4471,
360,
396,
1099,
13,
513,
1333,
267,
3066,
63,
1099,
63,
2302,
29,
1506,
63,
6116,
63,
2302,
8,
4471,
360,
396,
1773,
1099,
13,
513,
1333,
267,
2120,
63,
2302,
29,
1506,
63,
6116,
63,
2302,
8,
4471,
360,
1765,
13,
5506,
297,
1249,
1524,
277,
14,
344,
12,
22979,
267,
511,
63,
1065,
63,
2302,
29,
1506,
63,
6116,
63,
2302,
8,
4471,
360,
396,
1065,
13,
5506,
297,
1249,
1524,
277,
14,
396,
63,
1065,
63,
344,
12,
22979,
398,
511,
63,
1065,
275,
291,
14,
396,
63,
1065,
267,
5241,
275,
5870,
10591,
342,
267,
754,
275,
5241,
14,
1065,
8,
288,
2120,
63,
344,
29,
277,
14,
344,
12,
288,
10086,
29,
396,
63,
1065,
14,
10937,
12,
288,
1166,
29,
396,
63,
1065,
14,
396,
63,
1065,
63,
2302,
12,
288,
1145,
63,
3543,
29,
396,
63,
1065,
14,
571,
63,
3543,
12,
288,
1101,
63,
3543,
29,
396,
63,
1065,
14,
888,
63,
3543,
12,
288,
2058,
63,
2302,
29,
2604,
63,
2302,
12,
288,
3066,
63,
1099,
63,
2302,
29,
1773,
63,
1099,
63,
2302,
12,
288,
2120,
63,
2302,
29,
1765,
63,
2302,
12,
288,
511,
63,
1065,
63,
2302,
29,
396,
63,
1065,
63,
2302,
267,
776,
267,
291,
14,
2423,
63,
344,
275,
754,
14,
344,
267,
291,
14,
1205,
275,
8495,
3694,
14,
504,
63,
23593,
63,
1205,
8,
1099,
14,
1205,
9,
267,
291,
14,
2117,
342,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
5310,
16,
93,
327,
91,
17,
5469,
908,
8,
277,
855,
533,
4914,
354,
3108,
291,
14,
344,
9,
339,
636,
2975,
363,
275,
636,
2722,
363,
339,
636,
495,
363,
275,
636,
2722,
363,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
1639,
14,
697,
492,
1709,
199,
646,
1639,
14,
6052,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
465,
485,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
63,
4869,
698,
492,
4952,
199,
646,
22748,
14,
4981,
199,
504,
2863,
14,
1208,
492,
1900,
63,
6116,
63,
2302,
199,
199,
504,
511,
5933,
14,
396,
63,
27034,
14,
4129,
492,
5870,
10591,
199,
199,
504,
1275,
10458,
492,
2120,
63,
1205,
63,
2489,
4388,
199,
533,
8495,
3694,
8,
4869,
14,
5081,
304,
272,
510,
15219,
275,
378,
272,
1621,
63,
24547,
275,
413,
272,
577,
4817,
275,
499,
272,
12539,
275,
446,
17,
339,
3628,
275,
469,
267,
510,
15219,
26,
4018,
15960,
659,
267,
1621,
63,
24547,
26,
4018,
607,
6696,
659,
267,
577,
4817,
26,
4018,
10759,
659,
267,
12539,
26,
4018,
547,
659,
272,
789,
339,
768,
3744,
272,
347,
687,
63,
23593,
63,
1205,
8,
1886,
12,
22748,
63,
1205,
304,
267,
340,
22748,
63,
1205,
508,
22748,
14,
4981,
14,
21243,
26,
288,
372,
843,
14,
21243,
267,
340,
22748,
63,
1205,
315,
334,
23593,
14,
4981,
14,
28467,
30487,
12,
22748,
14,
4981,
14,
32385,
304,
288,
372,
843,
14,
568,
63,
24547,
267,
340,
22748,
63,
1205,
315,
22748,
14,
4981,
14,
15375,
63,
23162,
26,
288,
372,
843,
14,
3170,
267,
340,
22748,
63,
1205,
508,
22748,
14,
4981,
14,
12779,
26,
288,
372,
843,
14,
22162,
398,
746,
1722,
360,
5912,
2004,
26,
469,
16,
5285,
908,
8,
23593,
63,
1205,
430,
421,
199,
533,
8495,
8,
992,
14,
1685,
304,
272,
1305,
275,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
511,
63,
1065,
275,
1709,
14,
3190,
360,
396,
63,
10802,
14,
21228,
297,
4048,
63,
354,
534,
5054,
358,
272,
2737,
275,
1709,
14,
4626,
8,
2495,
63,
2131,
63,
525,
29,
549,
9,
272,
2004,
275,
4952,
14,
5081,
792,
8,
4476,
3694,
12,
849,
29,
4476,
3694,
14,
21243,
9,
272,
3906,
63,
344,
275,
1709,
14,
8757,
792,
8,
2500,
29,
549,
12,
2973,
29,
549,
9,
339,
636,
5043,
63,
1205,
275,
488,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
4476,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
398,
291,
855,
5043,
63,
1205,
275,
291,
14,
1205,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
398,
1613,
8,
4476,
12,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
398,
340,
291,
855,
5043,
63,
1205,
1137,
291,
14,
1205,
26,
288,
2120,
63,
1205,
63,
2489,
14,
2254,
8,
277,
855,
533,
3108,
1256,
29,
277,
9,
288,
291,
855,
5043,
63,
1205,
275,
291,
14,
1205,
339,
347,
1255,
8,
277,
304,
267,
2058,
63,
2302,
29,
1506,
63,
6116,
63,
2302,
8,
4471,
360,
396,
1099,
13,
513,
1333,
267,
3066,
63,
1099,
63,
2302,
29,
1506,
63,
6116,
63,
2302,
8,
4471,
360,
396,
1773,
1099,
13,
513,
1333,
267,
2120,
63,
2302,
29,
1506,
63,
6116,
63,
2302,
8,
4471,
360,
1765,
13,
5506,
297,
1249,
1524,
277,
14,
344,
12,
22979,
267,
511,
63,
1065,
63,
2302,
29,
1506,
63,
6116,
63,
2302,
8,
4471,
360,
396,
1065,
13,
5506,
297,
1249,
1524,
277,
14,
396,
63,
1065,
63,
344,
12,
22979,
398,
511,
63,
1065,
275,
291,
14,
396,
63,
1065,
267,
5241,
275,
5870,
10591,
342,
267,
754,
275,
5241,
14,
1065,
8,
288,
2120,
63,
344,
29,
277,
14,
344,
12,
288,
10086,
29,
396,
63,
1065,
14,
10937,
12,
288,
1166,
29,
396,
63,
1065,
14,
396,
63,
1065,
63,
2302,
12,
288,
1145,
63,
3543,
29,
396,
63,
1065,
14,
571,
63,
3543,
12,
288,
1101,
63,
3543,
29,
396,
63,
1065,
14,
888,
63,
3543,
12,
288,
2058,
63,
2302,
29,
2604,
63,
2302,
12,
288,
3066,
63,
1099,
63,
2302,
29,
1773,
63,
1099,
63,
2302,
12,
288,
2120,
63,
2302,
29,
1765,
63,
2302,
12,
288,
511,
63,
1065,
63,
2302,
29,
396,
63,
1065,
63,
2302,
267,
776,
267,
291,
14,
2423,
63,
344,
275,
754,
14,
344,
267,
291,
14,
1205,
275,
8495,
3694,
14,
504,
63,
23593,
63,
1205,
8,
1099,
14,
1205,
9,
267,
291,
14,
2117,
342,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
5310,
16,
93,
327,
91,
17,
5469,
908,
8,
277,
855,
533,
4914,
354,
3108,
291,
14,
344,
9,
339,
636,
2975,
363,
275,
636,
2722,
363,
339,
636,
495,
363,
275,
636,
2722,
363,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
CforED/Machine-Learning
|
sklearn/externals/joblib/pool.py
|
237
|
23894
|
"""Custom implementation of multiprocessing.Pool with custom pickler
This module provides efficient ways of working with data stored in
shared memory with numpy.memmap arrays without inducing any memory
copy between the parent and child processes.
This module should not be imported if multiprocessing is not
available as it implements subclasses of multiprocessing Pool
that uses a custom alternative to SimpleQueue.
"""
# Author: Olivier Grisel <olivier.grisel@ensta.org>
# Copyright: 2012, Olivier Grisel
# License: BSD 3 clause
from mmap import mmap
import errno
import os
import stat
import sys
import threading
import atexit
import tempfile
import shutil
try:
# Python 2 compat
from cPickle import loads
from cPickle import dumps
except ImportError:
from pickle import loads
from pickle import dumps
import copyreg
# Customizable pure Python pickler in Python 2
# customizable C-optimized pickler under Python 3.3+
from pickle import Pickler
from pickle import HIGHEST_PROTOCOL
from io import BytesIO
from ._multiprocessing_helpers import mp, assert_spawning
# We need the class definition to derive from it not the multiprocessing.Pool
# factory function
from multiprocessing.pool import Pool
try:
import numpy as np
from numpy.lib.stride_tricks import as_strided
except ImportError:
np = None
from .numpy_pickle import load
from .numpy_pickle import dump
from .hashing import hash
# Some system have a ramdisk mounted by default, we can use it instead of /tmp
# as the default folder to dump big arrays to share with subprocesses
SYSTEM_SHARED_MEM_FS = '/dev/shm'
# Folder and file permissions to chmod temporary files generated by the
# memmaping pool. Only the owner of the Python process can access the
# temporary files and folder.
FOLDER_PERMISSIONS = stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR
FILE_PERMISSIONS = stat.S_IRUSR | stat.S_IWUSR
###############################################################################
# Support for efficient transient pickling of numpy data structures
def _get_backing_memmap(a):
"""Recursively look up the original np.memmap instance base if any"""
b = getattr(a, 'base', None)
if b is None:
# TODO: check scipy sparse datastructure if scipy is installed
# a nor its descendants do not have a memmap base
return None
elif isinstance(b, mmap):
# a is already a real memmap instance.
return a
else:
# Recursive exploration of the base ancestry
return _get_backing_memmap(b)
def has_shareable_memory(a):
"""Return True if a is backed by some mmap buffer directly or not"""
return _get_backing_memmap(a) is not None
def _strided_from_memmap(filename, dtype, mode, offset, order, shape, strides,
total_buffer_len):
"""Reconstruct an array view on a memmory mapped file"""
if mode == 'w+':
# Do not zero the original data when unpickling
mode = 'r+'
if strides is None:
# Simple, contiguous memmap
return np.memmap(filename, dtype=dtype, shape=shape, mode=mode,
offset=offset, order=order)
else:
# For non-contiguous data, memmap the total enclosing buffer and then
# extract the non-contiguous view with the stride-tricks API
base = np.memmap(filename, dtype=dtype, shape=total_buffer_len,
mode=mode, offset=offset, order=order)
return as_strided(base, shape=shape, strides=strides)
def _reduce_memmap_backed(a, m):
"""Pickling reduction for memmap backed arrays
a is expected to be an instance of np.ndarray (or np.memmap)
m is expected to be an instance of np.memmap on the top of the ``base``
attribute ancestry of a. ``m.base`` should be the real python mmap object.
"""
# offset that comes from the striding differences between a and m
a_start, a_end = np.byte_bounds(a)
m_start = np.byte_bounds(m)[0]
offset = a_start - m_start
# offset from the backing memmap
offset += m.offset
if m.flags['F_CONTIGUOUS']:
order = 'F'
else:
# The backing memmap buffer is necessarily contiguous hence C if not
# Fortran
order = 'C'
if a.flags['F_CONTIGUOUS'] or a.flags['C_CONTIGUOUS']:
# If the array is a contiguous view, no need to pass the strides
strides = None
total_buffer_len = None
else:
# Compute the total number of items to map from which the strided
# view will be extracted.
strides = a.strides
total_buffer_len = (a_end - a_start) // a.itemsize
return (_strided_from_memmap,
(m.filename, a.dtype, m.mode, offset, order, a.shape, strides,
total_buffer_len))
def reduce_memmap(a):
"""Pickle the descriptors of a memmap instance to reopen on same file"""
m = _get_backing_memmap(a)
if m is not None:
# m is a real mmap backed memmap instance, reduce a preserving striding
# information
return _reduce_memmap_backed(a, m)
else:
# This memmap instance is actually backed by a regular in-memory
# buffer: this can happen when using binary operators on numpy.memmap
# instances
return (loads, (dumps(np.asarray(a), protocol=HIGHEST_PROTOCOL),))
class ArrayMemmapReducer(object):
"""Reducer callable to dump large arrays to memmap files.
Parameters
----------
max_nbytes: int
Threshold to trigger memmaping of large arrays to files created
a folder.
temp_folder: str
Path of a folder where files for backing memmaped arrays are created.
mmap_mode: 'r', 'r+' or 'c'
Mode for the created memmap datastructure. See the documentation of
numpy.memmap for more details. Note: 'w+' is coerced to 'r+'
automatically to avoid zeroing the data on unpickling.
verbose: int, optional, 0 by default
If verbose > 0, memmap creations are logged.
If verbose > 1, both memmap creations, reuse and array pickling are
logged.
context_id: int, optional, None by default
Set to a value identifying a call context to spare costly hashing of
the content of the input arrays when it is safe to assume that each
array will not be mutated by the parent process for the duration of the
dispatch process. This is the case when using the high level Parallel
API. It might not be the case when using the MemmapingPool API
directly.
prewarm: bool, optional, False by default.
Force a read on newly memmaped array to make sure that OS pre-cache it
memory. This can be useful to avoid concurrent disk access when the
same data array is passed to different worker processes.
"""
def __init__(self, max_nbytes, temp_folder, mmap_mode, verbose=0,
context_id=None, prewarm=True):
self._max_nbytes = max_nbytes
self._temp_folder = temp_folder
self._mmap_mode = mmap_mode
self.verbose = int(verbose)
self._context_id = context_id
self._prewarm = prewarm
def __call__(self, a):
m = _get_backing_memmap(a)
if m is not None:
# a is already backed by a memmap file, let's reuse it directly
return _reduce_memmap_backed(a, m)
if (not a.dtype.hasobject
and self._max_nbytes is not None
and a.nbytes > self._max_nbytes):
# check that the folder exists (lazily create the pool temp folder
# if required)
try:
os.makedirs(self._temp_folder)
os.chmod(self._temp_folder, FOLDER_PERMISSIONS)
except OSError as e:
if e.errno != errno.EEXIST:
raise e
# Find a unique, concurrent safe filename for writing the
# content of this array only once.
if self._context_id is not None:
marker = self._context_id
else:
marker = hash(a)
basename = "%d-%d-%d-%s.pkl" % (
os.getpid(), id(threading.current_thread()), id(a), marker)
filename = os.path.join(self._temp_folder, basename)
# In case the same array with the same content is passed several
# times to the pool subprocess children, serialize it only once
# XXX: implement an explicit reference counting scheme to make it
# possible to delete temporary files as soon as the workers are
# done processing this data.
if not os.path.exists(filename):
if self.verbose > 0:
print("Memmaping (shape=%r, dtype=%s) to new file %s" % (
a.shape, a.dtype, filename))
for dumped_filename in dump(a, filename):
os.chmod(dumped_filename, FILE_PERMISSIONS)
if self._prewarm:
# Warm up the data to avoid concurrent disk access in
# multiple children processes
load(filename, mmap_mode=self._mmap_mode).max()
elif self.verbose > 1:
print("Memmaping (shape=%s, dtype=%s) to old file %s" % (
a.shape, a.dtype, filename))
# Let's use the memmap reducer
return reduce_memmap(load(filename, mmap_mode=self._mmap_mode))
else:
# do not convert a into memmap, let pickler do its usual copy with
# the default system pickler
if self.verbose > 1:
print("Pickling array (shape=%r, dtype=%s)." % (
a.shape, a.dtype))
return (loads, (dumps(a, protocol=HIGHEST_PROTOCOL),))
###############################################################################
# Enable custom pickling in Pool queues
class CustomizablePickler(Pickler):
"""Pickler that accepts custom reducers.
HIGHEST_PROTOCOL is selected by default as this pickler is used
to pickle ephemeral datastructures for interprocess communication
hence no backward compatibility is required.
`reducers` is expected expected to be a dictionary with key/values
being `(type, callable)` pairs where `callable` is a function that
give an instance of `type` will return a tuple `(constructor,
tuple_of_objects)` to rebuild an instance out of the pickled
`tuple_of_objects` as would return a `__reduce__` method. See the
standard library documentation on pickling for more details.
"""
# We override the pure Python pickler as its the only way to be able to
# customize the dispatch table without side effects in Python 2.6
# to 3.2. For Python 3.3+ leverage the new dispatch_table
# feature from http://bugs.python.org/issue14166 that makes it possible
# to use the C implementation of the Pickler which is faster.
def __init__(self, writer, reducers=None, protocol=HIGHEST_PROTOCOL):
Pickler.__init__(self, writer, protocol=protocol)
if reducers is None:
reducers = {}
if hasattr(Pickler, 'dispatch'):
# Make the dispatch registry an instance level attribute instead of
# a reference to the class dictionary under Python 2
self.dispatch = Pickler.dispatch.copy()
else:
# Under Python 3 initialize the dispatch table with a copy of the
# default registry
self.dispatch_table = copyreg.dispatch_table.copy()
for type, reduce_func in reducers.items():
self.register(type, reduce_func)
def register(self, type, reduce_func):
if hasattr(Pickler, 'dispatch'):
# Python 2 pickler dispatching is not explicitly customizable.
# Let us use a closure to workaround this limitation.
def dispatcher(self, obj):
reduced = reduce_func(obj)
self.save_reduce(obj=obj, *reduced)
self.dispatch[type] = dispatcher
else:
self.dispatch_table[type] = reduce_func
class CustomizablePicklingQueue(object):
"""Locked Pipe implementation that uses a customizable pickler.
This class is an alternative to the multiprocessing implementation
of SimpleQueue in order to make it possible to pass custom
pickling reducers, for instance to avoid memory copy when passing
memmory mapped datastructures.
`reducers` is expected expected to be a dictionary with key/values
being `(type, callable)` pairs where `callable` is a function that
give an instance of `type` will return a tuple `(constructor,
tuple_of_objects)` to rebuild an instance out of the pickled
`tuple_of_objects` as would return a `__reduce__` method. See the
standard library documentation on pickling for more details.
"""
def __init__(self, context, reducers=None):
self._reducers = reducers
self._reader, self._writer = context.Pipe(duplex=False)
self._rlock = context.Lock()
if sys.platform == 'win32':
self._wlock = None
else:
self._wlock = context.Lock()
self._make_methods()
def __getstate__(self):
assert_spawning(self)
return (self._reader, self._writer, self._rlock, self._wlock,
self._reducers)
def __setstate__(self, state):
(self._reader, self._writer, self._rlock, self._wlock,
self._reducers) = state
self._make_methods()
def empty(self):
return not self._reader.poll()
def _make_methods(self):
self._recv = recv = self._reader.recv
racquire, rrelease = self._rlock.acquire, self._rlock.release
def get():
racquire()
try:
return recv()
finally:
rrelease()
self.get = get
if self._reducers:
def send(obj):
buffer = BytesIO()
CustomizablePickler(buffer, self._reducers).dump(obj)
self._writer.send_bytes(buffer.getvalue())
self._send = send
else:
self._send = send = self._writer.send
if self._wlock is None:
# writes to a message oriented win32 pipe are atomic
self.put = send
else:
wlock_acquire, wlock_release = (
self._wlock.acquire, self._wlock.release)
def put(obj):
wlock_acquire()
try:
return send(obj)
finally:
wlock_release()
self.put = put
class PicklingPool(Pool):
"""Pool implementation with customizable pickling reducers.
This is useful to control how data is shipped between processes
and makes it possible to use shared memory without useless
copies induces by the default pickling methods of the original
objects passed as arguments to dispatch.
`forward_reducers` and `backward_reducers` are expected to be
dictionaries with key/values being `(type, callable)` pairs where
`callable` is a function that give an instance of `type` will return
a tuple `(constructor, tuple_of_objects)` to rebuild an instance out
of the pickled `tuple_of_objects` as would return a `__reduce__`
method. See the standard library documentation on pickling for more
details.
"""
def __init__(self, processes=None, forward_reducers=None,
backward_reducers=None, **kwargs):
if forward_reducers is None:
forward_reducers = dict()
if backward_reducers is None:
backward_reducers = dict()
self._forward_reducers = forward_reducers
self._backward_reducers = backward_reducers
poolargs = dict(processes=processes)
poolargs.update(kwargs)
super(PicklingPool, self).__init__(**poolargs)
def _setup_queues(self):
context = getattr(self, '_ctx', mp)
self._inqueue = CustomizablePicklingQueue(context,
self._forward_reducers)
self._outqueue = CustomizablePicklingQueue(context,
self._backward_reducers)
self._quick_put = self._inqueue._send
self._quick_get = self._outqueue._recv
def delete_folder(folder_path):
"""Utility function to cleanup a temporary folder if still existing"""
if os.path.exists(folder_path):
shutil.rmtree(folder_path)
class MemmapingPool(PicklingPool):
"""Process pool that shares large arrays to avoid memory copy.
This drop-in replacement for `multiprocessing.pool.Pool` makes
it possible to work efficiently with shared memory in a numpy
context.
Existing instances of numpy.memmap are preserved: the child
suprocesses will have access to the same shared memory in the
original mode except for the 'w+' mode that is automatically
transformed as 'r+' to avoid zeroing the original data upon
instantiation.
Furthermore large arrays from the parent process are automatically
dumped to a temporary folder on the filesystem such as child
processes to access their content via memmaping (file system
backed shared memory).
Note: it is important to call the terminate method to collect
the temporary folder used by the pool.
Parameters
----------
processes: int, optional
Number of worker processes running concurrently in the pool.
initializer: callable, optional
Callable executed on worker process creation.
initargs: tuple, optional
Arguments passed to the initializer callable.
temp_folder: str, optional
Folder to be used by the pool for memmaping large arrays
for sharing memory with worker processes. If None, this will try in
order:
- a folder pointed by the JOBLIB_TEMP_FOLDER environment variable,
- /dev/shm if the folder exists and is writable: this is a RAMdisk
filesystem available by default on modern Linux distributions,
- the default system temporary folder that can be overridden
with TMP, TMPDIR or TEMP environment variables, typically /tmp
under Unix operating systems.
max_nbytes int or None, optional, 1e6 by default
Threshold on the size of arrays passed to the workers that
triggers automated memmory mapping in temp_folder.
Use None to disable memmaping of large arrays.
forward_reducers: dictionary, optional
Reducers used to pickle objects passed from master to worker
processes: see below.
backward_reducers: dictionary, optional
Reducers used to pickle return values from workers back to the
master process.
verbose: int, optional
Make it possible to monitor how the communication of numpy arrays
with the subprocess is handled (pickling or memmaping)
context_id: int, optional, None by default
Set to a value identifying a call context to spare costly hashing of
the content of the input arrays when it is safe to assume that each
array will not be mutated by the parent process for the duration of the
dispatch process. This is the case when using the high level Parallel
API.
prewarm: bool or str, optional, "auto" by default.
If True, force a read on newly memmaped array to make sure that OS pre-
cache it in memory. This can be useful to avoid concurrent disk access
when the same data array is passed to different worker processes.
If "auto" (by default), prewarm is set to True, unless the Linux shared
memory partition /dev/shm is available and used as temp_folder.
`forward_reducers` and `backward_reducers` are expected to be
dictionaries with key/values being `(type, callable)` pairs where
`callable` is a function that give an instance of `type` will return
a tuple `(constructor, tuple_of_objects)` to rebuild an instance out
of the pickled `tuple_of_objects` as would return a `__reduce__`
method. See the standard library documentation on pickling for more
details.
"""
def __init__(self, processes=None, temp_folder=None, max_nbytes=1e6,
mmap_mode='r', forward_reducers=None, backward_reducers=None,
verbose=0, context_id=None, prewarm=False, **kwargs):
if forward_reducers is None:
forward_reducers = dict()
if backward_reducers is None:
backward_reducers = dict()
# Prepare a sub-folder name for the serialization of this particular
# pool instance (do not create in advance to spare FS write access if
# no array is to be dumped):
use_shared_mem = False
pool_folder_name = "joblib_memmaping_pool_%d_%d" % (
os.getpid(), id(self))
if temp_folder is None:
temp_folder = os.environ.get('JOBLIB_TEMP_FOLDER', None)
if temp_folder is None:
if os.path.exists(SYSTEM_SHARED_MEM_FS):
try:
temp_folder = SYSTEM_SHARED_MEM_FS
pool_folder = os.path.join(temp_folder, pool_folder_name)
if not os.path.exists(pool_folder):
os.makedirs(pool_folder)
use_shared_mem = True
except IOError:
# Missing rights in the the /dev/shm partition,
# fallback to regular temp folder.
temp_folder = None
if temp_folder is None:
# Fallback to the default tmp folder, typically /tmp
temp_folder = tempfile.gettempdir()
temp_folder = os.path.abspath(os.path.expanduser(temp_folder))
pool_folder = os.path.join(temp_folder, pool_folder_name)
self._temp_folder = pool_folder
# Register the garbage collector at program exit in case caller forgets
# to call terminate explicitly: note we do not pass any reference to
# self to ensure that this callback won't prevent garbage collection of
# the pool instance and related file handler resources such as POSIX
# semaphores and pipes
atexit.register(lambda: delete_folder(pool_folder))
if np is not None:
# Register smart numpy.ndarray reducers that detects memmap backed
# arrays and that is alse able to dump to memmap large in-memory
# arrays over the max_nbytes threshold
if prewarm == "auto":
prewarm = not use_shared_mem
forward_reduce_ndarray = ArrayMemmapReducer(
max_nbytes, pool_folder, mmap_mode, verbose,
context_id=context_id, prewarm=prewarm)
forward_reducers[np.ndarray] = forward_reduce_ndarray
forward_reducers[np.memmap] = reduce_memmap
# Communication from child process to the parent process always
# pickles in-memory numpy.ndarray without dumping them as memmap
# to avoid confusing the caller and make it tricky to collect the
# temporary folder
backward_reduce_ndarray = ArrayMemmapReducer(
None, pool_folder, mmap_mode, verbose)
backward_reducers[np.ndarray] = backward_reduce_ndarray
backward_reducers[np.memmap] = reduce_memmap
poolargs = dict(
processes=processes,
forward_reducers=forward_reducers,
backward_reducers=backward_reducers)
poolargs.update(kwargs)
super(MemmapingPool, self).__init__(**poolargs)
def terminate(self):
super(MemmapingPool, self).terminate()
delete_folder(self._temp_folder)
|
bsd-3-clause
|
[
624,
7223,
4514,
402,
12866,
14,
5453,
543,
3537,
3732,
1435,
199,
199,
2765,
859,
6571,
13402,
15217,
402,
6449,
543,
666,
5489,
315,
199,
5555,
4402,
543,
2680,
14,
5286,
1130,
6572,
1928,
315,
14713,
1263,
4402,
199,
1574,
3382,
314,
1676,
436,
1982,
10358,
14,
199,
199,
2765,
859,
1077,
440,
506,
8439,
340,
12866,
365,
440,
199,
4561,
465,
652,
9031,
9180,
402,
12866,
15553,
199,
9099,
4440,
282,
3537,
13943,
370,
5870,
3737,
14,
199,
199,
624,
199,
3,
6529,
26,
593,
317,
26645,
598,
322,
5891,
665,
23711,
26645,
14,
7928,
5891,
32,
287,
1207,
14,
1308,
30,
199,
3,
1898,
26,
6029,
12,
593,
317,
26645,
598,
322,
5891,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
504,
21991,
492,
21991,
199,
646,
7554,
199,
646,
747,
199,
646,
5672,
199,
646,
984,
199,
646,
5796,
199,
646,
19840,
199,
646,
5549,
199,
646,
5145,
199,
199,
893,
26,
272,
327,
2018,
499,
8434,
272,
687,
17572,
492,
14404,
272,
687,
17572,
492,
16864,
199,
2590,
3545,
26,
272,
687,
5927,
492,
14404,
272,
687,
5927,
492,
16864,
272,
492,
1331,
1135,
199,
199,
3,
8388,
14065,
15111,
2018,
3732,
1435,
315,
2018,
499,
199,
3,
3537,
14065,
445,
13,
25499,
3732,
1435,
1334,
2018,
650,
14,
19,
11,
199,
504,
5927,
492,
16568,
1435,
199,
199,
504,
5927,
492,
869,
13454,
1719,
63,
9583,
199,
504,
5890,
492,
11808,
199,
199,
504,
13653,
25725,
63,
7546,
492,
6118,
12,
702,
63,
3770,
87,
1835,
199,
3,
2136,
1929,
314,
1021,
5492,
370,
23519,
687,
652,
440,
314,
12866,
14,
5453,
199,
3,
6434,
805,
199,
504,
12866,
14,
2293,
492,
15553,
199,
199,
893,
26,
272,
492,
2680,
465,
980,
272,
687,
2680,
14,
773,
14,
12318,
63,
599,
5618,
492,
465,
63,
816,
770,
199,
2590,
3545,
26,
272,
980,
275,
488,
199,
199,
504,
1275,
4714,
63,
8092,
492,
2248,
199,
504,
1275,
4714,
63,
8092,
492,
5461,
199,
504,
1275,
2227,
316,
492,
2631,
199,
199,
3,
6601,
2656,
1172,
282,
21394,
4032,
27979,
701,
849,
12,
781,
883,
675,
652,
3140,
402,
1182,
2791,
199,
3,
465,
314,
849,
4922,
370,
5461,
7282,
6572,
370,
8663,
543,
1007,
11816,
199,
12711,
63,
13772,
63,
10293,
63,
7079,
275,
1994,
2374,
15,
609,
77,
7,
199,
199,
3,
29121,
436,
570,
3443,
370,
30106,
7937,
1584,
4046,
701,
314,
199,
3,
7573,
1130,
316,
4203,
14,
5972,
314,
5771,
402,
314,
2018,
2112,
883,
2879,
314,
199,
3,
7937,
1584,
436,
4922,
14,
199,
19041,
63,
4227,
31978,
275,
5672,
14,
51,
63,
3927,
22592,
1204,
5672,
14,
51,
63,
22275,
22592,
1204,
5672,
14,
51,
63,
3867,
22592,
199,
3817,
63,
4227,
31978,
275,
5672,
14,
51,
63,
3927,
22592,
1204,
5672,
14,
51,
63,
22275,
22592,
199,
199,
11490,
199,
3,
12502,
367,
13402,
7115,
14928,
24394,
402,
2680,
666,
13955,
421,
199,
318,
485,
362,
63,
18222,
63,
5286,
1130,
8,
65,
304,
272,
408,
14244,
9840,
3648,
1536,
314,
3379,
980,
14,
5286,
1130,
1256,
1300,
340,
1263,
624,
272,
330,
275,
2519,
8,
65,
12,
283,
1095,
297,
488,
9,
272,
340,
330,
365,
488,
26,
267,
327,
3254,
26,
1104,
7026,
5178,
666,
6976,
340,
7026,
365,
4903,
267,
327,
282,
6590,
2399,
26061,
886,
440,
1172,
282,
7573,
1130,
1300,
267,
372,
488,
339,
916,
1228,
8,
66,
12,
21991,
304,
267,
327,
282,
365,
2575,
282,
3363,
7573,
1130,
1256,
14,
267,
372,
282,
339,
587,
26,
267,
327,
18306,
3398,
31337,
402,
314,
1300,
12294,
27723,
267,
372,
485,
362,
63,
18222,
63,
5286,
1130,
8,
66,
9,
421,
199,
318,
965,
63,
6251,
461,
63,
4844,
8,
65,
304,
272,
408,
1767,
715,
340,
282,
365,
1771,
379,
701,
2005,
21991,
3335,
5370,
503,
440,
624,
272,
372,
485,
362,
63,
18222,
63,
5286,
1130,
8,
65,
9,
365,
440,
488,
421,
199,
318,
485,
816,
770,
63,
504,
63,
5286,
1130,
8,
1501,
12,
2152,
12,
818,
12,
3268,
12,
1865,
12,
2215,
12,
11883,
12,
586,
3141,
63,
2738,
63,
552,
304,
272,
408,
497,
8514,
376,
1625,
2455,
641,
282,
562,
596,
1089,
9994,
570,
624,
272,
340,
818,
508,
283,
87,
11,
356,
267,
327,
4226,
440,
4697,
314,
3379,
666,
1380,
625,
24773,
267,
818,
275,
283,
82,
4786,
339,
340,
11883,
365,
488,
26,
267,
327,
5870,
12,
26611,
7573,
1130,
267,
372,
980,
14,
5286,
1130,
8,
1501,
12,
2152,
29,
2271,
12,
2215,
29,
1392,
12,
818,
29,
632,
12,
586,
3268,
29,
2743,
12,
1865,
29,
1648,
9,
272,
587,
26,
267,
327,
2104,
2222,
13,
16583,
666,
12,
7573,
1130,
314,
3141,
25188,
3335,
436,
2066,
267,
327,
5536,
314,
2222,
13,
16583,
2455,
543,
314,
7345,
13,
599,
5618,
3261,
267,
1300,
275,
980,
14,
5286,
1130,
8,
1501,
12,
2152,
29,
2271,
12,
2215,
29,
2923,
63,
2738,
63,
552,
12,
586,
818,
29,
632,
12,
3268,
29,
2743,
12,
1865,
29,
1648,
9,
267,
372,
465,
63,
816,
770,
8,
1095,
12,
2215,
29,
1392,
12,
11883,
29,
16759,
9,
421,
199,
318,
485,
5270,
63,
5286,
1130,
63,
894,
379,
8,
65,
12,
333,
304,
272,
408,
8587,
2983,
16773,
367,
7573,
1130,
1771,
379,
6572,
339,
282,
365,
1420,
370,
506,
376,
1256,
402,
980,
14,
8237,
334,
269,
980,
14,
5286,
1130,
9,
272,
333,
365,
1420,
370,
506,
376,
1256,
402,
980,
14,
5286,
1130,
641,
314,
2746,
402,
314,
1124,
1095,
1040,
272,
2225,
12294,
27723,
402,
282,
14,
1124,
77,
14,
1095,
1040,
1077,
506,
314,
3363,
2366,
21991,
909,
14,
272,
408,
272,
327,
3268,
626,
12477,
687,
314,
4024,
1098,
15109,
3382,
282,
436,
333,
272,
282,
63,
928,
12,
282,
63,
500,
275,
980,
14,
4414,
63,
9632,
8,
65,
9,
272,
333,
63,
928,
275,
980,
14,
4414,
63,
9632,
8,
77,
2788,
16,
61,
272,
3268,
275,
282,
63,
928,
446,
333,
63,
928,
339,
327,
3268,
687,
314,
21094,
7573,
1130,
272,
3268,
847,
333,
14,
2743,
339,
340,
333,
14,
2469,
459,
38,
63,
5801,
1277,
32504
] |
[
7223,
4514,
402,
12866,
14,
5453,
543,
3537,
3732,
1435,
199,
199,
2765,
859,
6571,
13402,
15217,
402,
6449,
543,
666,
5489,
315,
199,
5555,
4402,
543,
2680,
14,
5286,
1130,
6572,
1928,
315,
14713,
1263,
4402,
199,
1574,
3382,
314,
1676,
436,
1982,
10358,
14,
199,
199,
2765,
859,
1077,
440,
506,
8439,
340,
12866,
365,
440,
199,
4561,
465,
652,
9031,
9180,
402,
12866,
15553,
199,
9099,
4440,
282,
3537,
13943,
370,
5870,
3737,
14,
199,
199,
624,
199,
3,
6529,
26,
593,
317,
26645,
598,
322,
5891,
665,
23711,
26645,
14,
7928,
5891,
32,
287,
1207,
14,
1308,
30,
199,
3,
1898,
26,
6029,
12,
593,
317,
26645,
598,
322,
5891,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
504,
21991,
492,
21991,
199,
646,
7554,
199,
646,
747,
199,
646,
5672,
199,
646,
984,
199,
646,
5796,
199,
646,
19840,
199,
646,
5549,
199,
646,
5145,
199,
199,
893,
26,
272,
327,
2018,
499,
8434,
272,
687,
17572,
492,
14404,
272,
687,
17572,
492,
16864,
199,
2590,
3545,
26,
272,
687,
5927,
492,
14404,
272,
687,
5927,
492,
16864,
272,
492,
1331,
1135,
199,
199,
3,
8388,
14065,
15111,
2018,
3732,
1435,
315,
2018,
499,
199,
3,
3537,
14065,
445,
13,
25499,
3732,
1435,
1334,
2018,
650,
14,
19,
11,
199,
504,
5927,
492,
16568,
1435,
199,
199,
504,
5927,
492,
869,
13454,
1719,
63,
9583,
199,
504,
5890,
492,
11808,
199,
199,
504,
13653,
25725,
63,
7546,
492,
6118,
12,
702,
63,
3770,
87,
1835,
199,
3,
2136,
1929,
314,
1021,
5492,
370,
23519,
687,
652,
440,
314,
12866,
14,
5453,
199,
3,
6434,
805,
199,
504,
12866,
14,
2293,
492,
15553,
199,
199,
893,
26,
272,
492,
2680,
465,
980,
272,
687,
2680,
14,
773,
14,
12318,
63,
599,
5618,
492,
465,
63,
816,
770,
199,
2590,
3545,
26,
272,
980,
275,
488,
199,
199,
504,
1275,
4714,
63,
8092,
492,
2248,
199,
504,
1275,
4714,
63,
8092,
492,
5461,
199,
504,
1275,
2227,
316,
492,
2631,
199,
199,
3,
6601,
2656,
1172,
282,
21394,
4032,
27979,
701,
849,
12,
781,
883,
675,
652,
3140,
402,
1182,
2791,
199,
3,
465,
314,
849,
4922,
370,
5461,
7282,
6572,
370,
8663,
543,
1007,
11816,
199,
12711,
63,
13772,
63,
10293,
63,
7079,
275,
1994,
2374,
15,
609,
77,
7,
199,
199,
3,
29121,
436,
570,
3443,
370,
30106,
7937,
1584,
4046,
701,
314,
199,
3,
7573,
1130,
316,
4203,
14,
5972,
314,
5771,
402,
314,
2018,
2112,
883,
2879,
314,
199,
3,
7937,
1584,
436,
4922,
14,
199,
19041,
63,
4227,
31978,
275,
5672,
14,
51,
63,
3927,
22592,
1204,
5672,
14,
51,
63,
22275,
22592,
1204,
5672,
14,
51,
63,
3867,
22592,
199,
3817,
63,
4227,
31978,
275,
5672,
14,
51,
63,
3927,
22592,
1204,
5672,
14,
51,
63,
22275,
22592,
199,
199,
11490,
199,
3,
12502,
367,
13402,
7115,
14928,
24394,
402,
2680,
666,
13955,
421,
199,
318,
485,
362,
63,
18222,
63,
5286,
1130,
8,
65,
304,
272,
408,
14244,
9840,
3648,
1536,
314,
3379,
980,
14,
5286,
1130,
1256,
1300,
340,
1263,
624,
272,
330,
275,
2519,
8,
65,
12,
283,
1095,
297,
488,
9,
272,
340,
330,
365,
488,
26,
267,
327,
3254,
26,
1104,
7026,
5178,
666,
6976,
340,
7026,
365,
4903,
267,
327,
282,
6590,
2399,
26061,
886,
440,
1172,
282,
7573,
1130,
1300,
267,
372,
488,
339,
916,
1228,
8,
66,
12,
21991,
304,
267,
327,
282,
365,
2575,
282,
3363,
7573,
1130,
1256,
14,
267,
372,
282,
339,
587,
26,
267,
327,
18306,
3398,
31337,
402,
314,
1300,
12294,
27723,
267,
372,
485,
362,
63,
18222,
63,
5286,
1130,
8,
66,
9,
421,
199,
318,
965,
63,
6251,
461,
63,
4844,
8,
65,
304,
272,
408,
1767,
715,
340,
282,
365,
1771,
379,
701,
2005,
21991,
3335,
5370,
503,
440,
624,
272,
372,
485,
362,
63,
18222,
63,
5286,
1130,
8,
65,
9,
365,
440,
488,
421,
199,
318,
485,
816,
770,
63,
504,
63,
5286,
1130,
8,
1501,
12,
2152,
12,
818,
12,
3268,
12,
1865,
12,
2215,
12,
11883,
12,
586,
3141,
63,
2738,
63,
552,
304,
272,
408,
497,
8514,
376,
1625,
2455,
641,
282,
562,
596,
1089,
9994,
570,
624,
272,
340,
818,
508,
283,
87,
11,
356,
267,
327,
4226,
440,
4697,
314,
3379,
666,
1380,
625,
24773,
267,
818,
275,
283,
82,
4786,
339,
340,
11883,
365,
488,
26,
267,
327,
5870,
12,
26611,
7573,
1130,
267,
372,
980,
14,
5286,
1130,
8,
1501,
12,
2152,
29,
2271,
12,
2215,
29,
1392,
12,
818,
29,
632,
12,
586,
3268,
29,
2743,
12,
1865,
29,
1648,
9,
272,
587,
26,
267,
327,
2104,
2222,
13,
16583,
666,
12,
7573,
1130,
314,
3141,
25188,
3335,
436,
2066,
267,
327,
5536,
314,
2222,
13,
16583,
2455,
543,
314,
7345,
13,
599,
5618,
3261,
267,
1300,
275,
980,
14,
5286,
1130,
8,
1501,
12,
2152,
29,
2271,
12,
2215,
29,
2923,
63,
2738,
63,
552,
12,
586,
818,
29,
632,
12,
3268,
29,
2743,
12,
1865,
29,
1648,
9,
267,
372,
465,
63,
816,
770,
8,
1095,
12,
2215,
29,
1392,
12,
11883,
29,
16759,
9,
421,
199,
318,
485,
5270,
63,
5286,
1130,
63,
894,
379,
8,
65,
12,
333,
304,
272,
408,
8587,
2983,
16773,
367,
7573,
1130,
1771,
379,
6572,
339,
282,
365,
1420,
370,
506,
376,
1256,
402,
980,
14,
8237,
334,
269,
980,
14,
5286,
1130,
9,
272,
333,
365,
1420,
370,
506,
376,
1256,
402,
980,
14,
5286,
1130,
641,
314,
2746,
402,
314,
1124,
1095,
1040,
272,
2225,
12294,
27723,
402,
282,
14,
1124,
77,
14,
1095,
1040,
1077,
506,
314,
3363,
2366,
21991,
909,
14,
272,
408,
272,
327,
3268,
626,
12477,
687,
314,
4024,
1098,
15109,
3382,
282,
436,
333,
272,
282,
63,
928,
12,
282,
63,
500,
275,
980,
14,
4414,
63,
9632,
8,
65,
9,
272,
333,
63,
928,
275,
980,
14,
4414,
63,
9632,
8,
77,
2788,
16,
61,
272,
3268,
275,
282,
63,
928,
446,
333,
63,
928,
339,
327,
3268,
687,
314,
21094,
7573,
1130,
272,
3268,
847,
333,
14,
2743,
339,
340,
333,
14,
2469,
459,
38,
63,
5801,
1277,
32504,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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