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
sequencelengths 1.02k
1.02k
| labels
sequencelengths 1.02k
1.02k
| attention_mask
sequencelengths 1.02k
1.02k
|
---|---|---|---|---|---|---|---|---|
drawks/ansible | lib/ansible/modules/cloud/google/gcp_redis_instance_facts.py | 12 | 7557 | #!/usr/bin/python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2017 Google
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
# ----------------------------------------------------------------------------
#
# *** AUTO GENERATED CODE *** AUTO GENERATED CODE ***
#
# ----------------------------------------------------------------------------
#
# This file is automatically generated by Magic Modules and manual
# changes will be clobbered when the file is regenerated.
#
# Please read more about how to change this file at
# https://www.github.com/GoogleCloudPlatform/magic-modules
#
# ----------------------------------------------------------------------------
from __future__ import absolute_import, division, print_function
__metaclass__ = type
################################################################################
# Documentation
################################################################################
ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ["preview"], 'supported_by': 'community'}
DOCUMENTATION = '''
---
module: gcp_redis_instance_facts
description:
- Gather facts for GCP Instance
short_description: Gather facts for GCP Instance
version_added: 2.8
author: Google Inc. (@googlecloudplatform)
requirements:
- python >= 2.6
- requests >= 2.18.4
- google-auth >= 1.3.0
options:
region:
description:
- The name of the Redis region of the instance.
required: true
extends_documentation_fragment: gcp
'''
EXAMPLES = '''
- name: " a instance facts"
gcp_redis_instance_facts:
region: us-central1
project: test_project
auth_kind: serviceaccount
service_account_file: "/tmp/auth.pem"
state: facts
'''
RETURN = '''
items:
description: List of items
returned: always
type: complex
contains:
alternativeLocationId:
description:
- Only applicable to STANDARD_HA tier which protects the instance against zonal
failures by provisioning it across two zones.
- If provided, it must be a different zone from the one provided in [locationId].
returned: success
type: str
authorizedNetwork:
description:
- The full name of the Google Compute Engine network to which the instance is
connected. If left unspecified, the default network will be used.
returned: success
type: str
createTime:
description:
- The time the instance was created in RFC3339 UTC "Zulu" format, accurate to
nanoseconds.
returned: success
type: str
currentLocationId:
description:
- The current zone where the Redis endpoint is placed.
- For Basic Tier instances, this will always be the same as the [locationId]
provided by the user at creation time. For Standard Tier instances, this can
be either [locationId] or [alternativeLocationId] and can change after a failover
event.
returned: success
type: str
displayName:
description:
- An arbitrary and optional user-provided name for the instance.
returned: success
type: str
host:
description:
- Hostname or IP address of the exposed Redis endpoint used by clients to connect
to the service.
returned: success
type: str
labels:
description:
- Resource labels to represent user provided metadata.
returned: success
type: dict
redisConfigs:
description:
- Redis configuration parameters, according to U(http://redis.io/topics/config.)
- 'Please check Memorystore documentation for the list of supported parameters:
U(https://cloud.google.com/memorystore/docs/redis/reference/rest/v1/projects.locations.instances#Instance.FIELDS.redis_configs)
.'
returned: success
type: dict
locationId:
description:
- The zone where the instance will be provisioned. If not provided, the service
will choose a zone for the instance. For STANDARD_HA tier, instances will
be created across two zones for protection against zonal failures. If [alternativeLocationId]
is also provided, it must be different from [locationId].
returned: success
type: str
name:
description:
- The ID of the instance or a fully qualified identifier for the instance. .
returned: success
type: str
memorySizeGb:
description:
- Redis memory size in GiB.
returned: success
type: int
port:
description:
- The port number of the exposed Redis endpoint.
returned: success
type: int
redisVersion:
description:
- The version of Redis software. If not provided, latest supported version will
be used. Updating the version will perform an upgrade/downgrade to the new
version. Currently, the supported values are REDIS_3_2 for Redis 3.2.
returned: success
type: str
reservedIpRange:
description:
- The CIDR range of internal addresses that are reserved for this instance.
If not provided, the service will choose an unused /29 block, for example,
10.0.0.0/29 or 192.168.0.0/29. Ranges must be unique and non-overlapping with
existing subnets in an authorized network.
returned: success
type: str
tier:
description:
- 'The service tier of the instance. Must be one of these values: - BASIC: standalone
instance - STANDARD_HA: highly available primary/replica instances .'
returned: success
type: str
region:
description:
- The name of the Redis region of the instance.
returned: success
type: str
'''
################################################################################
# Imports
################################################################################
from ansible.module_utils.gcp_utils import navigate_hash, GcpSession, GcpModule, GcpRequest
import json
################################################################################
# Main
################################################################################
def main():
module = GcpModule(argument_spec=dict(region=dict(required=True, type='str')))
if not module.params['scopes']:
module.params['scopes'] = ['https://www.googleapis.com/auth/cloud-platform']
items = fetch_list(module, collection(module))
if items.get('instances'):
items = items.get('instances')
else:
items = []
return_value = {'items': items}
module.exit_json(**return_value)
def collection(module):
return "https://redis.googleapis.com/v1/projects/{project}/locations/{region}/instances".format(**module.params)
def fetch_list(module, link):
auth = GcpSession(module, 'redis')
response = auth.get(link)
return return_if_object(module, response)
def return_if_object(module, response):
# If not found, return nothing.
if response.status_code == 404:
return None
# If no content, return nothing.
if response.status_code == 204:
return None
try:
module.raise_for_status(response)
result = response.json()
except getattr(json.decoder, 'JSONDecodeError', ValueError) as inst:
module.fail_json(msg="Invalid JSON response with error: %s" % inst)
if navigate_hash(result, ['error', 'errors']):
module.fail_json(msg=navigate_hash(result, ['error', 'errors']))
return result
if __name__ == "__main__":
main()
| gpl-3.0 | [
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
9708,
4475,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
3,
27103,
199,
3,
199,
3,
258,
19688,
258,
25420,
29087,
6989,
22547,
259,
19688,
259,
25420,
29087,
6989,
22547,
258,
19688,
199,
3,
199,
3,
27103,
199,
3,
199,
3,
258,
961,
570,
365,
5847,
4046,
701,
603,
6573,
18167,
436,
8722,
199,
3,
258,
4493,
911,
506,
286,
1191,
18897,
1380,
314,
570,
365,
31904,
14,
199,
3,
199,
3,
258,
7754,
1586,
1655,
3595,
4212,
370,
1570,
642,
570,
737,
199,
3,
258,
4178,
921,
1544,
14,
5031,
14,
957,
15,
13266,
9089,
10397,
15,
11523,
13,
3112,
199,
3,
199,
3,
27103,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
363,
6577,
363,
275,
730,
199,
199,
13289,
199,
3,
15249,
199,
13289,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
283,
1205,
356,
2097,
7780,
2255,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22088,
63,
15369,
63,
842,
63,
5047,
199,
1802,
26,
199,
13,
19634,
9036,
367,
30902,
10066,
199,
3612,
63,
1802,
26,
19634,
9036,
367,
30902,
10066,
199,
1023,
63,
3270,
26,
499,
14,
24,
199,
2502,
26,
4475,
3277,
14,
8593,
3098,
4091,
3246,
9,
199,
7538,
26,
199,
13,
2366,
2356,
499,
14,
22,
199,
13,
4145,
2356,
499,
14,
1085,
14,
20,
199,
13,
6233,
13,
1178,
2356,
413,
14,
19,
14,
16,
199,
1419,
26,
523,
4897,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
25496,
4897,
402,
314,
1256,
14,
272,
1415,
26,
2549,
199,
11036,
63,
9970,
63,
7677,
26,
22088,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
298,
282,
1256,
9036,
2,
523,
22088,
63,
15369,
63,
842,
63,
5047,
26,
272,
4897,
26,
2739,
13,
16067,
17,
272,
2199,
26,
511,
63,
1715,
272,
1790,
63,
5091,
26,
2435,
2048,
272,
2435,
63,
2048,
63,
493,
26,
3286,
2791,
15,
1178,
14,
13102,
2,
272,
1174,
26,
9036,
199,
2344,
199,
199,
9677,
275,
1449,
199,
1744,
26,
523,
1369,
26,
3820,
402,
2974,
523,
2138,
26,
3544,
523,
730,
26,
6114,
523,
3509,
26,
272,
13943,
6592,
1304,
26,
489,
1369,
26,
489,
446,
5972,
3964,
370,
4384,
16938,
63,
6294,
31800,
1314,
557,
28853,
314,
1256,
6169,
1315,
8125,
267,
9081,
701,
20118,
652,
9371,
2877,
18666,
14,
489,
446,
982,
2741,
12,
652,
1471,
506,
282,
3365,
5718,
687,
314,
1373,
2741,
315,
359,
1985,
1304,
1055,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
18788,
4491,
26,
489,
1369,
26,
489,
446,
710,
2615,
536,
402,
314,
4475,
8354,
12580,
2784,
370,
1314,
314,
1256,
365,
267,
8539,
14,
982,
3602,
21994,
12,
314,
849,
2784,
911,
506,
1202,
14,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
1218,
1366,
26,
489,
1369,
26,
489,
446,
710,
900,
314,
1256,
1990,
2737,
315,
7329,
29536,
12174,
298,
58,
348,
85,
2,
1475,
12,
23189,
370,
267,
12055,
3362,
2776,
14,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
1453,
6592,
1304,
26,
489,
1369,
26,
489,
446,
710,
1453,
5718,
2382,
314,
25496,
6037,
365,
15090,
14,
489,
446,
2104,
10082,
377,
4446,
4454,
12,
642,
911,
3544,
506,
314,
2011,
465,
314,
359,
1985,
1304,
61,
267,
2741,
701,
314,
922,
737,
7143,
900,
14,
2104,
9739,
377,
4446,
4454,
12,
642,
883,
267,
506,
1902,
359,
1985,
1304,
61,
503,
359,
19389,
6592,
1304,
61,
436,
883,
1570,
2410,
282,
1433,
23165,
267,
1566,
14,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
2929,
985,
26,
489,
1369,
26,
489,
446,
1626,
9697,
436,
2716,
922,
13,
16929,
536,
367,
314,
1256,
14,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
1591,
26,
489,
1369,
26,
489,
446,
10891,
354,
503,
3531,
2287,
402,
314,
19282,
25496,
6037,
1202,
701,
13431,
370,
4907,
267,
370,
314,
2435,
14,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
3628,
26,
489,
1369,
26,
489,
446,
7337,
3628,
370,
2954,
922,
2741,
3341,
14,
489,
2138,
26,
3182,
489,
730,
26,
1211,
272,
16967,
29123,
26,
489,
1369,
26,
489,
446,
25496,
2897,
2633,
12,
7182,
370,
738,
8,
1014,
921,
15369,
14,
2308,
15,
11299,
15,
888,
4959,
489,
446,
283,
8254,
1104,
15825,
1617,
3794,
367,
314,
769,
402,
3748,
2633,
26,
267,
738,
8,
2859,
921,
4091,
14,
3098,
14,
957,
15,
4844,
1617,
15,
4757,
15,
15369,
15,
4443,
15,
3911,
15,
86,
17,
15,
6776,
14,
8022,
14,
5990,
3,
3244,
14,
12767,
14,
15369,
63,
7532,
9,
267,
1275,
7,
489,
2138,
26,
3182,
489,
730,
26,
1211,
272,
2909,
1304,
26,
489,
1369,
26,
489,
446,
710,
5718,
2382,
314,
1256,
911,
506,
1727,
12308,
14,
982,
440,
2741,
12,
314,
2435,
267,
911,
11496,
282,
5718,
367,
314,
1256,
14,
2104,
4384,
16938,
63,
6294,
31800,
12,
4454,
911,
267,
506,
2737,
9371,
2877,
18666,
367,
23977,
6169,
1315,
8125,
9081,
14,
982,
359,
19389,
6592,
1304,
61,
267,
365,
2597,
2741,
12,
652,
1471,
506,
3365,
687,
359,
1985,
1304,
1055,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
536,
26,
489,
1369,
26,
489,
446,
710,
2870,
402,
314,
1256,
503,
282,
9999,
12313,
5148,
367,
314,
1256,
14,
1275,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
4402,
2320,
30271,
26,
489,
1369,
26,
489,
446,
25496,
4402,
1568,
315,
598,
17587,
14,
489,
2138,
26,
3182,
489,
730,
26,
1109,
272,
1844,
26,
489,
1369,
26,
489,
446,
710,
1844,
1329,
402,
314,
19282,
25496,
6037,
14,
489,
2138,
26,
3182,
489,
730,
26,
1109,
272,
16967,
3353,
26,
489,
1369,
26,
489,
446,
710,
1015,
402,
25496,
2032,
14,
982
] | [
2647,
15,
1393,
15,
1548,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
1898,
334,
35,
9,
9708,
4475,
199,
3,
1664,
1696,
1684,
844,
373,
19,
14,
16,
11,
334,
3239,
9685,
503,
4178,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
15,
11692,
13,
19,
14,
16,
14,
2424,
9,
199,
3,
27103,
199,
3,
199,
3,
258,
19688,
258,
25420,
29087,
6989,
22547,
259,
19688,
259,
25420,
29087,
6989,
22547,
258,
19688,
199,
3,
199,
3,
27103,
199,
3,
199,
3,
258,
961,
570,
365,
5847,
4046,
701,
603,
6573,
18167,
436,
8722,
199,
3,
258,
4493,
911,
506,
286,
1191,
18897,
1380,
314,
570,
365,
31904,
14,
199,
3,
199,
3,
258,
7754,
1586,
1655,
3595,
4212,
370,
1570,
642,
570,
737,
199,
3,
258,
4178,
921,
1544,
14,
5031,
14,
957,
15,
13266,
9089,
10397,
15,
11523,
13,
3112,
199,
3,
199,
3,
27103,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
363,
6577,
363,
275,
730,
199,
199,
13289,
199,
3,
15249,
199,
13289,
199,
199,
8490,
63,
8314,
275,
791,
2343,
63,
1023,
356,
283,
17,
14,
17,
297,
283,
1205,
356,
2097,
7780,
2255,
283,
4946,
63,
991,
356,
283,
9387,
936,
199,
199,
8948,
275,
1449,
199,
2595,
199,
578,
26,
22088,
63,
15369,
63,
842,
63,
5047,
199,
1802,
26,
199,
13,
19634,
9036,
367,
30902,
10066,
199,
3612,
63,
1802,
26,
19634,
9036,
367,
30902,
10066,
199,
1023,
63,
3270,
26,
499,
14,
24,
199,
2502,
26,
4475,
3277,
14,
8593,
3098,
4091,
3246,
9,
199,
7538,
26,
199,
13,
2366,
2356,
499,
14,
22,
199,
13,
4145,
2356,
499,
14,
1085,
14,
20,
199,
13,
6233,
13,
1178,
2356,
413,
14,
19,
14,
16,
199,
1419,
26,
523,
4897,
26,
272,
1369,
26,
272,
446,
710,
536,
402,
314,
25496,
4897,
402,
314,
1256,
14,
272,
1415,
26,
2549,
199,
11036,
63,
9970,
63,
7677,
26,
22088,
199,
2344,
199,
199,
8918,
275,
1449,
199,
13,
536,
26,
298,
282,
1256,
9036,
2,
523,
22088,
63,
15369,
63,
842,
63,
5047,
26,
272,
4897,
26,
2739,
13,
16067,
17,
272,
2199,
26,
511,
63,
1715,
272,
1790,
63,
5091,
26,
2435,
2048,
272,
2435,
63,
2048,
63,
493,
26,
3286,
2791,
15,
1178,
14,
13102,
2,
272,
1174,
26,
9036,
199,
2344,
199,
199,
9677,
275,
1449,
199,
1744,
26,
523,
1369,
26,
3820,
402,
2974,
523,
2138,
26,
3544,
523,
730,
26,
6114,
523,
3509,
26,
272,
13943,
6592,
1304,
26,
489,
1369,
26,
489,
446,
5972,
3964,
370,
4384,
16938,
63,
6294,
31800,
1314,
557,
28853,
314,
1256,
6169,
1315,
8125,
267,
9081,
701,
20118,
652,
9371,
2877,
18666,
14,
489,
446,
982,
2741,
12,
652,
1471,
506,
282,
3365,
5718,
687,
314,
1373,
2741,
315,
359,
1985,
1304,
1055,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
18788,
4491,
26,
489,
1369,
26,
489,
446,
710,
2615,
536,
402,
314,
4475,
8354,
12580,
2784,
370,
1314,
314,
1256,
365,
267,
8539,
14,
982,
3602,
21994,
12,
314,
849,
2784,
911,
506,
1202,
14,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
1218,
1366,
26,
489,
1369,
26,
489,
446,
710,
900,
314,
1256,
1990,
2737,
315,
7329,
29536,
12174,
298,
58,
348,
85,
2,
1475,
12,
23189,
370,
267,
12055,
3362,
2776,
14,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
1453,
6592,
1304,
26,
489,
1369,
26,
489,
446,
710,
1453,
5718,
2382,
314,
25496,
6037,
365,
15090,
14,
489,
446,
2104,
10082,
377,
4446,
4454,
12,
642,
911,
3544,
506,
314,
2011,
465,
314,
359,
1985,
1304,
61,
267,
2741,
701,
314,
922,
737,
7143,
900,
14,
2104,
9739,
377,
4446,
4454,
12,
642,
883,
267,
506,
1902,
359,
1985,
1304,
61,
503,
359,
19389,
6592,
1304,
61,
436,
883,
1570,
2410,
282,
1433,
23165,
267,
1566,
14,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
2929,
985,
26,
489,
1369,
26,
489,
446,
1626,
9697,
436,
2716,
922,
13,
16929,
536,
367,
314,
1256,
14,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
1591,
26,
489,
1369,
26,
489,
446,
10891,
354,
503,
3531,
2287,
402,
314,
19282,
25496,
6037,
1202,
701,
13431,
370,
4907,
267,
370,
314,
2435,
14,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
3628,
26,
489,
1369,
26,
489,
446,
7337,
3628,
370,
2954,
922,
2741,
3341,
14,
489,
2138,
26,
3182,
489,
730,
26,
1211,
272,
16967,
29123,
26,
489,
1369,
26,
489,
446,
25496,
2897,
2633,
12,
7182,
370,
738,
8,
1014,
921,
15369,
14,
2308,
15,
11299,
15,
888,
4959,
489,
446,
283,
8254,
1104,
15825,
1617,
3794,
367,
314,
769,
402,
3748,
2633,
26,
267,
738,
8,
2859,
921,
4091,
14,
3098,
14,
957,
15,
4844,
1617,
15,
4757,
15,
15369,
15,
4443,
15,
3911,
15,
86,
17,
15,
6776,
14,
8022,
14,
5990,
3,
3244,
14,
12767,
14,
15369,
63,
7532,
9,
267,
1275,
7,
489,
2138,
26,
3182,
489,
730,
26,
1211,
272,
2909,
1304,
26,
489,
1369,
26,
489,
446,
710,
5718,
2382,
314,
1256,
911,
506,
1727,
12308,
14,
982,
440,
2741,
12,
314,
2435,
267,
911,
11496,
282,
5718,
367,
314,
1256,
14,
2104,
4384,
16938,
63,
6294,
31800,
12,
4454,
911,
267,
506,
2737,
9371,
2877,
18666,
367,
23977,
6169,
1315,
8125,
9081,
14,
982,
359,
19389,
6592,
1304,
61,
267,
365,
2597,
2741,
12,
652,
1471,
506,
3365,
687,
359,
1985,
1304,
1055,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
536,
26,
489,
1369,
26,
489,
446,
710,
2870,
402,
314,
1256,
503,
282,
9999,
12313,
5148,
367,
314,
1256,
14,
1275,
489,
2138,
26,
3182,
489,
730,
26,
620,
272,
4402,
2320,
30271,
26,
489,
1369,
26,
489,
446,
25496,
4402,
1568,
315,
598,
17587,
14,
489,
2138,
26,
3182,
489,
730,
26,
1109,
272,
1844,
26,
489,
1369,
26,
489,
446,
710,
1844,
1329,
402,
314,
19282,
25496,
6037,
14,
489,
2138,
26,
3182,
489,
730,
26,
1109,
272,
16967,
3353,
26,
489,
1369,
26,
489,
446,
710,
1015,
402,
25496,
2032,
14,
982,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
TangXT/edx-platform | common/djangoapps/user_api/models.py | 24 | 1900 | from django.contrib.auth.models import User
from django.core.validators import RegexValidator
from django.db import models
from xmodule_django.models import CourseKeyField
class UserPreference(models.Model):
"""A user's preference, stored as generic text to be processed by client"""
KEY_REGEX = r"[-_a-zA-Z0-9]+"
user = models.ForeignKey(User, db_index=True, related_name="preferences")
key = models.CharField(max_length=255, db_index=True, validators=[RegexValidator(KEY_REGEX)])
value = models.TextField()
class Meta: # pylint: disable=missing-docstring
unique_together = ("user", "key")
@classmethod
def set_preference(cls, user, preference_key, preference_value):
"""
Sets the user preference for a given key
"""
user_pref, _ = cls.objects.get_or_create(user=user, key=preference_key)
user_pref.value = preference_value
user_pref.save()
@classmethod
def get_preference(cls, user, preference_key, default=None):
"""
Gets the user preference value for a given key
Returns the given default if there isn't a preference for the given key
"""
try:
user_pref = cls.objects.get(user=user, key=preference_key)
return user_pref.value
except cls.DoesNotExist:
return default
class UserCourseTag(models.Model):
"""
Per-course user tags, to be used by various things that want to store tags about
the user. Added initially to store assignment to experimental groups.
"""
user = models.ForeignKey(User, db_index=True, related_name="+")
key = models.CharField(max_length=255, db_index=True)
course_id = CourseKeyField(max_length=255, db_index=True)
value = models.TextField()
class Meta: # pylint: disable=missing-docstring
unique_together = ("user", "course_id", "key")
| agpl-3.0 | [
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
1018,
14,
11346,
492,
12939,
8640,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
504,
9872,
63,
1176,
14,
992,
492,
22574,
792,
421,
199,
533,
2876,
25258,
8,
992,
14,
1685,
304,
272,
408,
33,
922,
1159,
16705,
12,
5489,
465,
7809,
1318,
370,
506,
7686,
701,
1890,
624,
272,
9301,
63,
10710,
275,
519,
2,
1988,
63,
65,
13,
6353,
13,
58,
16,
13,
25,
2807,
2,
272,
922,
275,
1709,
14,
3190,
8,
1899,
12,
1592,
63,
1080,
29,
549,
12,
4048,
63,
354,
628,
18063,
531,
272,
790,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
1592,
63,
1080,
29,
549,
12,
14370,
1524,
5103,
8640,
8,
3078,
63,
10710,
3948,
272,
574,
275,
1709,
14,
6254,
342,
339,
1021,
6288,
26,
221,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
267,
3747,
63,
6314,
275,
1689,
751,
401,
298,
498,
531,
339,
768,
3744,
272,
347,
663,
63,
14994,
8,
1886,
12,
922,
12,
16705,
63,
498,
12,
16705,
63,
585,
304,
267,
408,
267,
10729,
314,
922,
16705,
367,
282,
1627,
790,
267,
408,
267,
922,
63,
13829,
12,
485,
275,
843,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
751,
29,
751,
12,
790,
29,
14994,
63,
498,
9,
267,
922,
63,
13829,
14,
585,
275,
16705,
63,
585,
267,
922,
63,
13829,
14,
2117,
342,
339,
768,
3744,
272,
347,
664,
63,
14994,
8,
1886,
12,
922,
12,
16705,
63,
498,
12,
849,
29,
403,
304,
267,
408,
267,
14509,
314,
922,
16705,
574,
367,
282,
1627,
790,
398,
1803,
314,
1627,
849,
340,
2337,
5712,
1133,
282,
16705,
367,
314,
1627,
790,
267,
408,
398,
862,
26,
288,
922,
63,
13829,
275,
843,
14,
1462,
14,
362,
8,
751,
29,
751,
12,
790,
29,
14994,
63,
498,
9,
288,
372,
922,
63,
13829,
14,
585,
267,
871,
843,
14,
7400,
26,
288,
372,
849,
421,
199,
533,
2876,
6979,
1931,
8,
992,
14,
1685,
304,
272,
408,
272,
3492,
13,
1972,
922,
3762,
12,
370,
506,
1202,
701,
7750,
7645,
626,
2934,
370,
3877,
3762,
3595,
272,
314,
922,
14,
221,
16230,
22801,
370,
3877,
9801,
370,
22820,
4652,
14,
272,
408,
272,
922,
275,
1709,
14,
3190,
8,
1899,
12,
1592,
63,
1080,
29,
549,
12,
4048,
63,
354,
16368,
531,
272,
790,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
1592,
63,
1080,
29,
549,
9,
272,
2518,
63,
344,
275,
22574,
792,
8,
988,
63,
1267,
29,
2299,
12,
1592,
63,
1080,
29,
549,
9,
272,
574,
275,
1709,
14,
6254,
342,
339,
1021,
6288,
26,
221,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
267,
3747,
63,
6314,
275,
1689,
751,
401,
298,
1972,
63,
344,
401,
298,
498,
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
] | [
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
1018,
14,
11346,
492,
12939,
8640,
199,
504,
1639,
14,
697,
492,
1709,
199,
199,
504,
9872,
63,
1176,
14,
992,
492,
22574,
792,
421,
199,
533,
2876,
25258,
8,
992,
14,
1685,
304,
272,
408,
33,
922,
1159,
16705,
12,
5489,
465,
7809,
1318,
370,
506,
7686,
701,
1890,
624,
272,
9301,
63,
10710,
275,
519,
2,
1988,
63,
65,
13,
6353,
13,
58,
16,
13,
25,
2807,
2,
272,
922,
275,
1709,
14,
3190,
8,
1899,
12,
1592,
63,
1080,
29,
549,
12,
4048,
63,
354,
628,
18063,
531,
272,
790,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
1592,
63,
1080,
29,
549,
12,
14370,
1524,
5103,
8640,
8,
3078,
63,
10710,
3948,
272,
574,
275,
1709,
14,
6254,
342,
339,
1021,
6288,
26,
221,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
267,
3747,
63,
6314,
275,
1689,
751,
401,
298,
498,
531,
339,
768,
3744,
272,
347,
663,
63,
14994,
8,
1886,
12,
922,
12,
16705,
63,
498,
12,
16705,
63,
585,
304,
267,
408,
267,
10729,
314,
922,
16705,
367,
282,
1627,
790,
267,
408,
267,
922,
63,
13829,
12,
485,
275,
843,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
751,
29,
751,
12,
790,
29,
14994,
63,
498,
9,
267,
922,
63,
13829,
14,
585,
275,
16705,
63,
585,
267,
922,
63,
13829,
14,
2117,
342,
339,
768,
3744,
272,
347,
664,
63,
14994,
8,
1886,
12,
922,
12,
16705,
63,
498,
12,
849,
29,
403,
304,
267,
408,
267,
14509,
314,
922,
16705,
574,
367,
282,
1627,
790,
398,
1803,
314,
1627,
849,
340,
2337,
5712,
1133,
282,
16705,
367,
314,
1627,
790,
267,
408,
398,
862,
26,
288,
922,
63,
13829,
275,
843,
14,
1462,
14,
362,
8,
751,
29,
751,
12,
790,
29,
14994,
63,
498,
9,
288,
372,
922,
63,
13829,
14,
585,
267,
871,
843,
14,
7400,
26,
288,
372,
849,
421,
199,
533,
2876,
6979,
1931,
8,
992,
14,
1685,
304,
272,
408,
272,
3492,
13,
1972,
922,
3762,
12,
370,
506,
1202,
701,
7750,
7645,
626,
2934,
370,
3877,
3762,
3595,
272,
314,
922,
14,
221,
16230,
22801,
370,
3877,
9801,
370,
22820,
4652,
14,
272,
408,
272,
922,
275,
1709,
14,
3190,
8,
1899,
12,
1592,
63,
1080,
29,
549,
12,
4048,
63,
354,
16368,
531,
272,
790,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
2299,
12,
1592,
63,
1080,
29,
549,
9,
272,
2518,
63,
344,
275,
22574,
792,
8,
988,
63,
1267,
29,
2299,
12,
1592,
63,
1080,
29,
549,
9,
272,
574,
275,
1709,
14,
6254,
342,
339,
1021,
6288,
26,
221,
327,
4287,
26,
3507,
29,
4752,
13,
12485,
267,
3747,
63,
6314,
275,
1689,
751,
401,
298,
1972,
63,
344,
401,
298,
498,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tastynoodle/django | tests/i18n/contenttypes/tests.py | 9 | 1181 | # coding: utf-8
from __future__ import unicode_literals
import os
from django.contrib.contenttypes.models import ContentType
from django.test import TestCase
from django.test.utils import override_settings
from django.utils._os import upath
from django.utils import six
from django.utils import translation
from i18n import TransRealMixin
@override_settings(
USE_I18N=True,
LOCALE_PATHS=(
os.path.join(os.path.dirname(upath(__file__)), 'locale'),
),
LANGUAGE_CODE='en',
LANGUAGES=(
('en', 'English'),
('fr', 'French'),
),
)
class ContentTypeTests(TransRealMixin, TestCase):
def test_verbose_name(self):
company_type = ContentType.objects.get(app_label='i18n', model='company')
with translation.override('en'):
self.assertEqual(six.text_type(company_type), 'Company')
with translation.override('fr'):
self.assertEqual(six.text_type(company_type), 'Société')
def test_field_override(self):
company_type = ContentType.objects.get(app_label='i18n', model='company')
company_type.name = 'Other'
self.assertEqual(six.text_type(company_type), 'Other')
| bsd-3-clause | [
3,
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
423,
736,
492,
1536,
1619,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
492,
7761,
199,
199,
504,
284,
1085,
78,
492,
6266,
10099,
4256,
421,
199,
32,
4415,
63,
1751,
8,
272,
4815,
63,
41,
1085,
46,
29,
549,
12,
272,
20639,
37,
63,
20202,
2687,
267,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
384,
1619,
3460,
493,
22159,
283,
5508,
659,
272,
2318,
272,
30508,
2962,
63,
6012,
534,
287,
297,
272,
30508,
5383,
2687,
267,
661,
287,
297,
283,
19410,
659,
267,
661,
4391,
297,
283,
38,
15148,
659,
272,
2318,
199,
9,
199,
533,
14501,
2925,
8,
3188,
10099,
4256,
12,
7640,
304,
272,
347,
511,
63,
3832,
63,
354,
8,
277,
304,
267,
7233,
63,
466,
275,
14501,
14,
1462,
14,
362,
8,
571,
63,
1302,
534,
73,
1085,
78,
297,
1402,
534,
4627,
358,
267,
543,
7761,
14,
4415,
360,
287,
735,
288,
291,
14,
629,
8,
4174,
14,
505,
63,
466,
8,
4627,
63,
466,
395,
283,
16063,
358,
267,
543,
7761,
14,
4415,
360,
4391,
735,
288,
291,
14,
629,
8,
4174,
14,
505,
63,
466,
8,
4627,
63,
466,
395,
283,
51,
3095,
5741,
84,
5741,
358,
339,
347,
511,
63,
698,
63,
4415,
8,
277,
304,
267,
7233,
63,
466,
275,
14501,
14,
1462,
14,
362,
8,
571,
63,
1302,
534,
73,
1085,
78,
297,
1402,
534,
4627,
358,
267,
7233,
63,
466,
14,
354,
275,
283,
8632,
7,
267,
291,
14,
629,
8,
4174,
14,
505,
63,
466,
8,
4627,
63,
466,
395,
283,
8632,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
2803,
26,
2774,
13,
24,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
1208,
492,
4278,
63,
1751,
199,
504,
1639,
14,
1208,
423,
736,
492,
1536,
1619,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
492,
7761,
199,
199,
504,
284,
1085,
78,
492,
6266,
10099,
4256,
421,
199,
32,
4415,
63,
1751,
8,
272,
4815,
63,
41,
1085,
46,
29,
549,
12,
272,
20639,
37,
63,
20202,
2687,
267,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
384,
1619,
3460,
493,
22159,
283,
5508,
659,
272,
2318,
272,
30508,
2962,
63,
6012,
534,
287,
297,
272,
30508,
5383,
2687,
267,
661,
287,
297,
283,
19410,
659,
267,
661,
4391,
297,
283,
38,
15148,
659,
272,
2318,
199,
9,
199,
533,
14501,
2925,
8,
3188,
10099,
4256,
12,
7640,
304,
272,
347,
511,
63,
3832,
63,
354,
8,
277,
304,
267,
7233,
63,
466,
275,
14501,
14,
1462,
14,
362,
8,
571,
63,
1302,
534,
73,
1085,
78,
297,
1402,
534,
4627,
358,
267,
543,
7761,
14,
4415,
360,
287,
735,
288,
291,
14,
629,
8,
4174,
14,
505,
63,
466,
8,
4627,
63,
466,
395,
283,
16063,
358,
267,
543,
7761,
14,
4415,
360,
4391,
735,
288,
291,
14,
629,
8,
4174,
14,
505,
63,
466,
8,
4627,
63,
466,
395,
283,
51,
3095,
5741,
84,
5741,
358,
339,
347,
511,
63,
698,
63,
4415,
8,
277,
304,
267,
7233,
63,
466,
275,
14501,
14,
1462,
14,
362,
8,
571,
63,
1302,
534,
73,
1085,
78,
297,
1402,
534,
4627,
358,
267,
7233,
63,
466,
14,
354,
275,
283,
8632,
7,
267,
291,
14,
629,
8,
4174,
14,
505,
63,
466,
8,
4627,
63,
466,
395,
283,
8632,
358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
snowflakedb/snowflake-connector-python | src/snowflake/connector/vendored/urllib3/util/__init__.py | 27 | 1155 | from __future__ import absolute_import
# For backwards compatibility, provide imports that used to be here.
from .connection import is_connection_dropped
from .request import SKIP_HEADER, SKIPPABLE_HEADERS, make_headers
from .response import is_fp_closed
from .retry import Retry
from .ssl_ import (
ALPN_PROTOCOLS,
HAS_SNI,
IS_PYOPENSSL,
IS_SECURETRANSPORT,
PROTOCOL_TLS,
SSLContext,
assert_fingerprint,
resolve_cert_reqs,
resolve_ssl_version,
ssl_wrap_socket,
)
from .timeout import Timeout, current_time
from .url import Url, get_host, parse_url, split_first
from .wait import wait_for_read, wait_for_write
__all__ = (
"HAS_SNI",
"IS_PYOPENSSL",
"IS_SECURETRANSPORT",
"SSLContext",
"PROTOCOL_TLS",
"ALPN_PROTOCOLS",
"Retry",
"Timeout",
"Url",
"assert_fingerprint",
"current_time",
"is_connection_dropped",
"is_fp_closed",
"get_host",
"parse_url",
"make_headers",
"resolve_cert_reqs",
"resolve_ssl_version",
"split_first",
"ssl_wrap_socket",
"wait_for_read",
"wait_for_write",
"SKIP_HEADER",
"SKIPPABLE_HEADERS",
)
| apache-2.0 | [
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
3,
2104,
8552,
7163,
12,
5647,
8925,
626,
1202,
370,
506,
2348,
14,
199,
504,
1275,
2105,
492,
365,
63,
2105,
63,
27557,
199,
504,
1275,
1069,
492,
27885,
63,
7311,
12,
27885,
48,
2617,
63,
21178,
12,
1852,
63,
2139,
199,
504,
1275,
1310,
492,
365,
63,
3997,
63,
5938,
199,
504,
1275,
7154,
492,
20506,
199,
504,
1275,
4266,
63,
492,
334,
272,
12112,
9060,
63,
9583,
51,
12,
272,
7509,
63,
8199,
41,
12,
272,
2281,
63,
4521,
9935,
5413,
12,
272,
2281,
63,
13478,
775,
50,
5622,
3657,
12,
272,
3611,
2566,
3978,
63,
10224,
12,
272,
7799,
2998,
12,
272,
702,
63,
15077,
12,
272,
7512,
63,
4736,
63,
12720,
12,
272,
7512,
63,
4266,
63,
1023,
12,
272,
6149,
63,
3823,
63,
3450,
12,
199,
9,
199,
504,
1275,
2593,
492,
12878,
12,
1453,
63,
521,
199,
504,
1275,
633,
492,
20503,
12,
664,
63,
1102,
12,
2198,
63,
633,
12,
3715,
63,
2246,
199,
504,
1275,
2573,
492,
3618,
63,
509,
63,
739,
12,
3618,
63,
509,
63,
952,
199,
199,
363,
452,
363,
275,
334,
272,
298,
13533,
63,
8199,
41,
401,
272,
298,
1311,
63,
4521,
9935,
5413,
401,
272,
298,
1311,
63,
13478,
775,
50,
5622,
3657,
401,
272,
298,
5413,
2998,
401,
272,
298,
9583,
63,
10224,
401,
272,
298,
748,
9060,
63,
9583,
51,
401,
272,
298,
12989,
401,
272,
298,
6372,
401,
272,
298,
6417,
401,
272,
298,
479,
63,
15077,
401,
272,
298,
1818,
63,
521,
401,
272,
298,
374,
63,
2105,
63,
27557,
401,
272,
298,
374,
63,
3997,
63,
5938,
401,
272,
298,
362,
63,
1102,
401,
272,
298,
1122,
63,
633,
401,
272,
298,
1875,
63,
2139,
401,
272,
298,
6983,
63,
4736,
63,
12720,
401,
272,
298,
6983,
63,
4266,
63,
1023,
401,
272,
298,
1294,
63,
2246,
401,
272,
298,
4266,
63,
3823,
63,
3450,
401,
272,
298,
2573,
63,
509,
63,
739,
401,
272,
298,
2573,
63,
509,
63,
952,
401,
272,
298,
13525,
63,
7311,
401,
272,
298,
13525,
48,
2617,
63,
21178,
401,
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
] | [
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
3,
2104,
8552,
7163,
12,
5647,
8925,
626,
1202,
370,
506,
2348,
14,
199,
504,
1275,
2105,
492,
365,
63,
2105,
63,
27557,
199,
504,
1275,
1069,
492,
27885,
63,
7311,
12,
27885,
48,
2617,
63,
21178,
12,
1852,
63,
2139,
199,
504,
1275,
1310,
492,
365,
63,
3997,
63,
5938,
199,
504,
1275,
7154,
492,
20506,
199,
504,
1275,
4266,
63,
492,
334,
272,
12112,
9060,
63,
9583,
51,
12,
272,
7509,
63,
8199,
41,
12,
272,
2281,
63,
4521,
9935,
5413,
12,
272,
2281,
63,
13478,
775,
50,
5622,
3657,
12,
272,
3611,
2566,
3978,
63,
10224,
12,
272,
7799,
2998,
12,
272,
702,
63,
15077,
12,
272,
7512,
63,
4736,
63,
12720,
12,
272,
7512,
63,
4266,
63,
1023,
12,
272,
6149,
63,
3823,
63,
3450,
12,
199,
9,
199,
504,
1275,
2593,
492,
12878,
12,
1453,
63,
521,
199,
504,
1275,
633,
492,
20503,
12,
664,
63,
1102,
12,
2198,
63,
633,
12,
3715,
63,
2246,
199,
504,
1275,
2573,
492,
3618,
63,
509,
63,
739,
12,
3618,
63,
509,
63,
952,
199,
199,
363,
452,
363,
275,
334,
272,
298,
13533,
63,
8199,
41,
401,
272,
298,
1311,
63,
4521,
9935,
5413,
401,
272,
298,
1311,
63,
13478,
775,
50,
5622,
3657,
401,
272,
298,
5413,
2998,
401,
272,
298,
9583,
63,
10224,
401,
272,
298,
748,
9060,
63,
9583,
51,
401,
272,
298,
12989,
401,
272,
298,
6372,
401,
272,
298,
6417,
401,
272,
298,
479,
63,
15077,
401,
272,
298,
1818,
63,
521,
401,
272,
298,
374,
63,
2105,
63,
27557,
401,
272,
298,
374,
63,
3997,
63,
5938,
401,
272,
298,
362,
63,
1102,
401,
272,
298,
1122,
63,
633,
401,
272,
298,
1875,
63,
2139,
401,
272,
298,
6983,
63,
4736,
63,
12720,
401,
272,
298,
6983,
63,
4266,
63,
1023,
401,
272,
298,
1294,
63,
2246,
401,
272,
298,
4266,
63,
3823,
63,
3450,
401,
272,
298,
2573,
63,
509,
63,
739,
401,
272,
298,
2573,
63,
509,
63,
952,
401,
272,
298,
13525,
63,
7311,
401,
272,
298,
13525,
48,
2617,
63,
21178,
401,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
stevegt/UltimakerUtils | leveling-rings-UM1.py | 1 | 2681 | #!/usr/bin/python
# Derived from the UM2 version by an anonymous contributor...
#
# http://umforum.ultimaker.com/index.php?/topic/5951-um2-calibration-utility-leveling-ringsgcode/?p=54694
#
# ...who wisely says: "I accept NO liability for any damage done by
# using either version or any derivatives. USE AT YOUR OWN RISK."
filament_diameter = 2.89
build_area_width = 205.0
build_area_depth = 205.0
rings = 10
wide = 0.4
thick = 0.2925 / 2
temperature = 230
bed_temperature = 60
base_dia = 180
pi=3.1415927
center_x = build_area_width/2.0
center_y = build_area_depth/2.0
filament_area = (filament_diameter / 2) ** 2 * pi
head = '''
M107 ;start with the fan off
G21 ;metric values
G90 ;absolute positioning
M82 ;set extruder to absolute mode
M107 ;start with the fan off
G28 X0 Y0 ;move X/Y to min endstops
G28 Z0 ;move Z to min endstops
G1 Z15.0 F9000 ;move the platform down 15mm
M140 S{bed_temperature:.2f} ;set bed temp (no wait)
M109 T0 S{temperature:.2f} ;set extruder temp (wait)
M190 S{bed_temperature:.2f} ;set bed temp (wait)
G92 E0 ;zero the extruded length
G1 F200 E3 ;extrude 3mm of feed stock
G92 E0 ;zero the extruded length again
G1 F9000 ;set speed to 9000
;Put printing message on LCD screen
M117 Printing...
;Layer count: 1
;LAYER:0
'''
loop = '''
G0 F9000 X{x:.2f} Y{y:.2f} Z{z:.2f}
G2 F1000 X{x:.2f} Y{y:.2f} I{r:.2f} E{total_mm3:.2f}'''
tail = '''
;End GCode
M104 S0 ;extruder heater off
M140 S0 ;heated bed heater off (if you have it)
G91 ;relative positioning
G1 E-1 F300 ;retract the filament a bit before lifting the nozzle, to release some of the pressure
G1 Z+0.5 E-5 X-20 Y-20 F9000 ;move Z up a bit and retract filament even more
G28 X0 Y0 ;move X/Y to min endstops, so the head is out of the way
M84 ;steppers off
G90 ;absolute positioning'''
total_mm3 = 0
body = ''
cross_section = thick * wide
z = thick
for i in range(rings):
dia = base_dia - ((wide * 2) * i)
circumference = pi * dia
r = dia/2.0;
x = center_x - r
y = center_y
mm3 = (circumference * cross_section) / filament_area
total_mm3 += mm3
body += loop.format(**vars())
print head.format(**vars())
print body
print tail.format(**vars())
| gpl-2.0 | [
3381,
2647,
15,
1393,
15,
1548,
199,
199,
3,
27731,
687,
314,
738,
45,
18,
1015,
701,
376,
16535,
11615,
1396,
199,
3,
199,
3,
1455,
921,
453,
10044,
14,
1141,
14367,
14,
957,
15,
1080,
14,
8624,
31,
15,
5746,
15,
1427,
2869,
13,
453,
18,
13,
25851,
13,
16877,
13,
1896,
316,
13,
25182,
71,
600,
10197,
80,
29,
1477,
19421,
199,
3,
199,
3,
2263,
11345,
336,
572,
590,
20065,
26,
221,
298,
41,
4729,
4825,
1212,
3616,
367,
1263,
12927,
960,
4224,
701,
199,
3,
1808,
1902,
1015,
503,
1263,
28059,
14,
257,
4815,
15059,
1488,
11237,
593,
3705,
820,
22481,
2122,
257,
199,
199,
1289,
14040,
63,
328,
1787,
275,
499,
14,
1407,
199,
1506,
63,
6789,
63,
2063,
275,
24005,
14,
16,
199,
1506,
63,
6789,
63,
4631,
275,
24005,
14,
16,
199,
25182,
275,
1616,
199,
13062,
275,
378,
14,
20,
199,
273,
2000,
275,
378,
14,
1398,
821,
1182,
499,
199,
199,
12954,
275,
28700,
199,
6123,
63,
12954,
275,
5212,
199,
199,
1095,
63,
2391,
275,
13576,
199,
199,
1038,
29,
19,
14,
1079,
9327,
1465,
199,
199,
4218,
63,
88,
275,
1900,
63,
6789,
63,
2063,
15,
18,
14,
16,
199,
4218,
63,
89,
275,
1900,
63,
6789,
63,
4631,
15,
18,
14,
16,
199,
199,
1289,
14040,
63,
6789,
275,
334,
1289,
14040,
63,
328,
1787,
1182,
499,
9,
1011,
499,
627,
6682,
199,
199,
2993,
275,
1449,
199,
45,
7555,
14960,
8700,
928,
543,
314,
13758,
2331,
199,
39,
2025,
17907,
8700,
5165,
1338,
199,
39,
2710,
17907,
8700,
6116,
3421,
316,
199,
45,
2564,
17907,
8700,
409,
1599,
6558,
424,
370,
3679,
818,
199,
45,
7555,
14960,
8700,
928,
543,
314,
13758,
2331,
199,
39,
1651,
1323,
16,
1488,
16,
9668,
8700,
1185,
1323,
15,
57,
370,
1748,
1284,
270,
1483,
199,
39,
1651,
3107,
16,
14516,
8700,
1185,
3107,
370,
1748,
1284,
270,
1483,
199,
39,
17,
3107,
1046,
14,
16,
481,
25,
1493,
8295,
8700,
1185,
314,
4298,
3224,
4114,
596,
199,
45,
10037,
428,
91,
6123,
63,
12954,
14010,
18,
70,
93,
7861,
8700,
409,
30739,
2388,
334,
889,
3618,
9,
199,
45,
6996,
377,
16,
428,
91,
12954,
14010,
18,
70,
93,
3777,
8700,
409,
1599,
6558,
424,
2388,
334,
2573,
9,
199,
45,
12205,
428,
91,
6123,
63,
12954,
14010,
18,
70,
93,
4483,
8700,
409,
30739,
2388,
334,
2573,
9,
199,
39,
2942,
662,
16,
14516,
8700,
4262,
314,
1599,
6558,
770,
2582,
199,
39,
17,
481,
1840,
662,
19,
10473,
8700,
832,
82,
3786,
650,
596,
402,
4733,
10952,
199,
39,
2942,
662,
16,
14516,
8700,
4262,
314,
1599,
6558,
770,
2582,
4020,
199,
39,
17,
481,
25,
1493,
12788,
8700,
409,
8112,
370,
1749,
1493,
199,
27,
18989,
16116,
1245,
641,
491,
7695,
6426,
199,
45,
7362,
9101,
316,
1396,
199,
199,
27,
5003,
2338,
26,
413,
199,
27,
24167,
26,
16,
199,
2344,
199,
199,
3813,
275,
1449,
199,
39,
16,
481,
25,
1493,
1323,
91,
88,
14010,
18,
70,
93,
221,
1488,
91,
89,
14010,
18,
70,
93,
3107,
91,
90,
14010,
18,
70,
93,
199,
39,
18,
481,
5279,
221,
1323,
91,
88,
14010,
18,
70,
93,
221,
1488,
91,
89,
14010,
18,
70,
93,
473,
91,
82,
14010,
18,
70,
93,
662,
91,
2923,
63,
596,
19,
14010,
18,
70,
93,
2344,
199,
199,
1521,
275,
1449,
199,
27,
3005,
598,
3034,
199,
45,
6785,
428,
16,
12793,
8700,
832,
6558,
424,
946,
6618,
2331,
199,
45,
10037,
428,
16,
12793,
8700,
426,
972,
30739,
946,
6618,
2331,
334,
692,
1265,
1172,
652,
9,
199,
39,
3328,
17907,
8700,
6188,
3421,
316,
199,
39,
17,
662,
13,
17,
481,
5863,
9326,
8700,
264,
6908,
314,
1794,
14040,
282,
4546,
2544,
221,
853,
1337,
314,
949,
17622,
12,
370,
4683,
2005,
402,
314,
25471,
199,
39,
17,
3107,
11,
16,
14,
21,
662,
13,
21,
1323,
13,
1165,
1488,
13,
1165,
481,
25,
1493,
259,
8700,
1185,
3107,
1536,
282,
4546,
436,
295,
6908,
1794,
14040,
2755,
1655,
199,
39,
1651,
1323,
16,
1488,
16,
9668,
8700,
1185,
1323,
15,
57,
370,
1748,
1284,
270,
1483,
12,
880,
314,
4854,
365,
734,
402,
314,
4340,
199,
45,
1349,
17907,
8700,
2926,
32206,
2331,
199,
39,
2710,
17907,
8700,
6116,
3421,
316,
2344,
199,
199,
2923,
63,
596,
19,
275,
378,
199,
199,
2030,
275,
2125,
199,
199,
7925,
63,
2792,
275,
294,
2000,
627,
20239,
199,
90,
275,
294,
2000,
199,
199,
509,
284,
315,
1425,
8,
25182,
304,
199,
198,
2391,
275,
1300,
63,
2391,
446,
3666,
13062,
627,
499,
9,
627,
284,
9,
199,
198,
6092,
453,
1769,
275,
6682,
627,
487,
65,
9948,
198,
82,
275,
487,
65,
15,
18,
14,
16,
27,
199,
198,
88,
275,
8126,
63,
88,
446,
519,
199,
198,
89,
275,
8126,
63,
89,
9948,
198,
596,
19,
275,
334,
6092,
453,
1769,
627,
8059,
63,
2792,
9,
1182,
1794,
14040,
63,
6789,
199,
198,
2923,
63,
596,
19,
847,
8562,
19,
199,
198,
2030,
847,
4438,
14,
908,
3682,
2936,
1012,
199,
199,
1361,
4854,
14,
908,
3682,
2936,
1012,
199,
1361,
2396,
199,
1361,
9483,
14,
908,
3682,
2936,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
2647,
15,
1393,
15,
1548,
199,
199,
3,
27731,
687,
314,
738,
45,
18,
1015,
701,
376,
16535,
11615,
1396,
199,
3,
199,
3,
1455,
921,
453,
10044,
14,
1141,
14367,
14,
957,
15,
1080,
14,
8624,
31,
15,
5746,
15,
1427,
2869,
13,
453,
18,
13,
25851,
13,
16877,
13,
1896,
316,
13,
25182,
71,
600,
10197,
80,
29,
1477,
19421,
199,
3,
199,
3,
2263,
11345,
336,
572,
590,
20065,
26,
221,
298,
41,
4729,
4825,
1212,
3616,
367,
1263,
12927,
960,
4224,
701,
199,
3,
1808,
1902,
1015,
503,
1263,
28059,
14,
257,
4815,
15059,
1488,
11237,
593,
3705,
820,
22481,
2122,
257,
199,
199,
1289,
14040,
63,
328,
1787,
275,
499,
14,
1407,
199,
1506,
63,
6789,
63,
2063,
275,
24005,
14,
16,
199,
1506,
63,
6789,
63,
4631,
275,
24005,
14,
16,
199,
25182,
275,
1616,
199,
13062,
275,
378,
14,
20,
199,
273,
2000,
275,
378,
14,
1398,
821,
1182,
499,
199,
199,
12954,
275,
28700,
199,
6123,
63,
12954,
275,
5212,
199,
199,
1095,
63,
2391,
275,
13576,
199,
199,
1038,
29,
19,
14,
1079,
9327,
1465,
199,
199,
4218,
63,
88,
275,
1900,
63,
6789,
63,
2063,
15,
18,
14,
16,
199,
4218,
63,
89,
275,
1900,
63,
6789,
63,
4631,
15,
18,
14,
16,
199,
199,
1289,
14040,
63,
6789,
275,
334,
1289,
14040,
63,
328,
1787,
1182,
499,
9,
1011,
499,
627,
6682,
199,
199,
2993,
275,
1449,
199,
45,
7555,
14960,
8700,
928,
543,
314,
13758,
2331,
199,
39,
2025,
17907,
8700,
5165,
1338,
199,
39,
2710,
17907,
8700,
6116,
3421,
316,
199,
45,
2564,
17907,
8700,
409,
1599,
6558,
424,
370,
3679,
818,
199,
45,
7555,
14960,
8700,
928,
543,
314,
13758,
2331,
199,
39,
1651,
1323,
16,
1488,
16,
9668,
8700,
1185,
1323,
15,
57,
370,
1748,
1284,
270,
1483,
199,
39,
1651,
3107,
16,
14516,
8700,
1185,
3107,
370,
1748,
1284,
270,
1483,
199,
39,
17,
3107,
1046,
14,
16,
481,
25,
1493,
8295,
8700,
1185,
314,
4298,
3224,
4114,
596,
199,
45,
10037,
428,
91,
6123,
63,
12954,
14010,
18,
70,
93,
7861,
8700,
409,
30739,
2388,
334,
889,
3618,
9,
199,
45,
6996,
377,
16,
428,
91,
12954,
14010,
18,
70,
93,
3777,
8700,
409,
1599,
6558,
424,
2388,
334,
2573,
9,
199,
45,
12205,
428,
91,
6123,
63,
12954,
14010,
18,
70,
93,
4483,
8700,
409,
30739,
2388,
334,
2573,
9,
199,
39,
2942,
662,
16,
14516,
8700,
4262,
314,
1599,
6558,
770,
2582,
199,
39,
17,
481,
1840,
662,
19,
10473,
8700,
832,
82,
3786,
650,
596,
402,
4733,
10952,
199,
39,
2942,
662,
16,
14516,
8700,
4262,
314,
1599,
6558,
770,
2582,
4020,
199,
39,
17,
481,
25,
1493,
12788,
8700,
409,
8112,
370,
1749,
1493,
199,
27,
18989,
16116,
1245,
641,
491,
7695,
6426,
199,
45,
7362,
9101,
316,
1396,
199,
199,
27,
5003,
2338,
26,
413,
199,
27,
24167,
26,
16,
199,
2344,
199,
199,
3813,
275,
1449,
199,
39,
16,
481,
25,
1493,
1323,
91,
88,
14010,
18,
70,
93,
221,
1488,
91,
89,
14010,
18,
70,
93,
3107,
91,
90,
14010,
18,
70,
93,
199,
39,
18,
481,
5279,
221,
1323,
91,
88,
14010,
18,
70,
93,
221,
1488,
91,
89,
14010,
18,
70,
93,
473,
91,
82,
14010,
18,
70,
93,
662,
91,
2923,
63,
596,
19,
14010,
18,
70,
93,
2344,
199,
199,
1521,
275,
1449,
199,
27,
3005,
598,
3034,
199,
45,
6785,
428,
16,
12793,
8700,
832,
6558,
424,
946,
6618,
2331,
199,
45,
10037,
428,
16,
12793,
8700,
426,
972,
30739,
946,
6618,
2331,
334,
692,
1265,
1172,
652,
9,
199,
39,
3328,
17907,
8700,
6188,
3421,
316,
199,
39,
17,
662,
13,
17,
481,
5863,
9326,
8700,
264,
6908,
314,
1794,
14040,
282,
4546,
2544,
221,
853,
1337,
314,
949,
17622,
12,
370,
4683,
2005,
402,
314,
25471,
199,
39,
17,
3107,
11,
16,
14,
21,
662,
13,
21,
1323,
13,
1165,
1488,
13,
1165,
481,
25,
1493,
259,
8700,
1185,
3107,
1536,
282,
4546,
436,
295,
6908,
1794,
14040,
2755,
1655,
199,
39,
1651,
1323,
16,
1488,
16,
9668,
8700,
1185,
1323,
15,
57,
370,
1748,
1284,
270,
1483,
12,
880,
314,
4854,
365,
734,
402,
314,
4340,
199,
45,
1349,
17907,
8700,
2926,
32206,
2331,
199,
39,
2710,
17907,
8700,
6116,
3421,
316,
2344,
199,
199,
2923,
63,
596,
19,
275,
378,
199,
199,
2030,
275,
2125,
199,
199,
7925,
63,
2792,
275,
294,
2000,
627,
20239,
199,
90,
275,
294,
2000,
199,
199,
509,
284,
315,
1425,
8,
25182,
304,
199,
198,
2391,
275,
1300,
63,
2391,
446,
3666,
13062,
627,
499,
9,
627,
284,
9,
199,
198,
6092,
453,
1769,
275,
6682,
627,
487,
65,
9948,
198,
82,
275,
487,
65,
15,
18,
14,
16,
27,
199,
198,
88,
275,
8126,
63,
88,
446,
519,
199,
198,
89,
275,
8126,
63,
89,
9948,
198,
596,
19,
275,
334,
6092,
453,
1769,
627,
8059,
63,
2792,
9,
1182,
1794,
14040,
63,
6789,
199,
198,
2923,
63,
596,
19,
847,
8562,
19,
199,
198,
2030,
847,
4438,
14,
908,
3682,
2936,
1012,
199,
199,
1361,
4854,
14,
908,
3682,
2936,
1012,
199,
1361,
2396,
199,
1361,
9483,
14,
908,
3682,
2936,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
biswajitsahu/kuma | vendor/packages/git/diff.py | 32 | 2669 | # diff.py
# Copyright (C) 2008-2010 Michael Trier ([email protected]) and contributors
#
# This module is part of GitPython and is released under
# the BSD License: http://www.opensource.org/licenses/bsd-license.php
import re
import commit
class Diff(object):
"""
A Diff contains diff information between two commits.
"""
def __init__(self, repo, a_path, b_path, a_commit, b_commit, a_mode,
b_mode, new_file, deleted_file, rename_from,
rename_to, diff):
self.repo = repo
self.a_path = a_path
self.b_path = b_path
if not a_commit or re.search(r'^0{40}$', a_commit):
self.a_commit = None
else:
self.a_commit = commit.Commit(repo, id=a_commit)
if not b_commit or re.search(r'^0{40}$', b_commit):
self.b_commit = None
else:
self.b_commit = commit.Commit(repo, id=b_commit)
self.a_mode = a_mode
self.b_mode = b_mode
self.new_file = new_file
self.deleted_file = deleted_file
self.rename_from = rename_from
self.rename_to = rename_to
self.renamed = rename_from != rename_to
self.diff = diff
@classmethod
def list_from_string(cls, repo, text):
diffs = []
diff_header = re.compile(r"""
#^diff[ ]--git
[ ]a/(?P<a_path>\S+)[ ]b/(?P<b_path>\S+)\n
(?:^similarity[ ]index[ ](?P<similarity_index>\d+)%\n
^rename[ ]from[ ](?P<rename_from>\S+)\n
^rename[ ]to[ ](?P<rename_to>\S+)(?:\n|$))?
(?:^old[ ]mode[ ](?P<old_mode>\d+)\n
^new[ ]mode[ ](?P<new_mode>\d+)(?:\n|$))?
(?:^new[ ]file[ ]mode[ ](?P<new_file_mode>.+)(?:\n|$))?
(?:^deleted[ ]file[ ]mode[ ](?P<deleted_file_mode>.+)(?:\n|$))?
(?:^index[ ](?P<a_commit>[0-9A-Fa-f]+)
\.\.(?P<b_commit>[0-9A-Fa-f]+)[ ]?(?P<b_mode>.+)?(?:\n|$))?
""", re.VERBOSE | re.MULTILINE).match
for diff in ('\n' + text).split('\ndiff --git')[1:]:
header = diff_header(diff)
a_path, b_path, similarity_index, rename_from, rename_to, \
old_mode, new_mode, new_file_mode, deleted_file_mode, \
a_commit, b_commit, b_mode = header.groups()
new_file, deleted_file = bool(new_file_mode), bool(deleted_file_mode)
diffs.append(Diff(repo, a_path, b_path, a_commit, b_commit,
old_mode or deleted_file_mode, new_mode or new_file_mode or b_mode,
new_file, deleted_file, rename_from, rename_to, diff[header.end():]))
return diffs
| mpl-2.0 | [
3,
3915,
14,
647,
199,
3,
1898,
334,
35,
9,
9079,
13,
6542,
16922,
377,
10742,
334,
77,
599,
281,
32,
6799,
14,
957,
9,
436,
8417,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
12579,
4718,
436,
365,
14286,
1334,
199,
3,
314,
6289,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
15746,
13,
1682,
14,
8624,
199,
199,
646,
295,
199,
646,
5532,
199,
199,
533,
27134,
8,
785,
304,
272,
408,
272,
437,
27134,
3509,
3915,
2556,
3382,
2877,
20835,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3831,
12,
282,
63,
515,
12,
330,
63,
515,
12,
282,
63,
3543,
12,
330,
63,
3543,
12,
282,
63,
632,
12,
326,
330,
63,
632,
12,
892,
63,
493,
12,
5463,
63,
493,
12,
11441,
63,
504,
12,
326,
11441,
63,
475,
12,
3915,
304,
267,
291,
14,
3417,
275,
3831,
267,
291,
14,
65,
63,
515,
275,
282,
63,
515,
267,
291,
14,
66,
63,
515,
275,
330,
63,
515,
398,
340,
440,
282,
63,
3543,
503,
295,
14,
1733,
8,
82,
4289,
16,
91,
2167,
19204,
282,
63,
3543,
304,
288,
291,
14,
65,
63,
3543,
275,
488,
267,
587,
26,
288,
291,
14,
65,
63,
3543,
275,
5532,
14,
11421,
8,
3417,
12,
1305,
29,
65,
63,
3543,
9,
267,
340,
440,
330,
63,
3543,
503,
295,
14,
1733,
8,
82,
4289,
16,
91,
2167,
19204,
330,
63,
3543,
304,
288,
291,
14,
66,
63,
3543,
275,
488,
267,
587,
26,
288,
291,
14,
66,
63,
3543,
275,
5532,
14,
11421,
8,
3417,
12,
1305,
29,
66,
63,
3543,
9,
398,
291,
14,
65,
63,
632,
275,
282,
63,
632,
267,
291,
14,
66,
63,
632,
275,
330,
63,
632,
267,
291,
14,
1222,
63,
493,
275,
892,
63,
493,
267,
291,
14,
6062,
63,
493,
275,
5463,
63,
493,
267,
291,
14,
8165,
63,
504,
275,
11441,
63,
504,
267,
291,
14,
8165,
63,
475,
275,
11441,
63,
475,
267,
291,
14,
29401,
275,
11441,
63,
504,
1137,
11441,
63,
475,
267,
291,
14,
3028,
275,
3915,
339,
768,
3744,
272,
347,
769,
63,
504,
63,
875,
8,
1886,
12,
3831,
12,
1318,
304,
267,
14981,
275,
942,
398,
3915,
63,
1291,
275,
295,
14,
2014,
8,
82,
624,
288,
327,
62,
3028,
59,
1622,
306,
3187,
355,
359,
1622,
65,
9448,
48,
28,
65,
63,
515,
3072,
51,
11,
2788,
1622,
66,
9448,
48,
28,
66,
63,
515,
3072,
51,
13439,
78,
288,
16697,
62,
21965,
59,
1622,
1080,
59,
1622,
2229,
48,
28,
21965,
63,
1080,
3072,
68,
8771,
27744,
78,
2049,
7167,
8165,
59,
1622,
504,
59,
1622,
2229,
48,
28,
8165,
63,
504,
3072,
51,
13439,
78,
2049,
7167,
8165,
59,
1622,
475,
59,
1622,
2229,
48,
28,
8165,
63,
475,
3072,
51,
8771,
15840,
78,
92,
4,
22119,
288,
16697,
62,
1753,
59,
1622,
632,
59,
1622,
2229,
48,
28,
1753,
63,
632,
3072,
68,
13439,
78,
2049,
7167,
1222,
59,
1622,
632,
59,
1622,
2229,
48,
28,
1222,
63,
632,
3072,
68,
8771,
15840,
78,
92,
4,
22119,
288,
16697,
62,
1222,
59,
1622,
493,
59,
1622,
632,
59,
1622,
2229,
48,
28,
1222,
63,
493,
63,
632,
31411,
9,
15840,
78,
92,
4,
22119,
288,
16697,
62,
6062,
59,
1622,
493,
59,
1622,
632,
59,
1622,
2229,
48,
28,
6062,
63,
493,
63,
632,
31411,
9,
15840,
78,
92,
4,
22119,
288,
16697,
62,
1080,
59,
1622,
2229,
48,
28,
65,
63,
3543,
9514,
16,
13,
25,
33,
13,
1906,
13,
70,
11896,
355,
971,
3134,
14,
2229,
48,
28,
66,
63,
3543,
9514,
16,
13,
25,
33,
13,
1906,
13,
70,
2807,
2788,
1622,
31,
2229,
48,
28,
66,
63,
632,
31411,
5547,
15840,
78,
92,
4,
22119,
267,
10327,
295,
14,
16075,
1204,
295,
14,
16661,
680,
1431,
398,
367,
3915,
315,
17485,
78,
7,
435,
1318,
680,
1294,
2258,
28632,
1553,
3187,
5832,
17,
10688,
288,
1406,
275,
3915,
63,
1291,
8,
3028,
9,
953,
282,
63,
515,
12,
330,
63,
515,
12,
22838,
63,
1080,
12,
11441,
63,
504,
12,
11441,
63,
475,
12,
971,
355,
2269,
63,
632,
12,
892,
63,
632,
12,
892,
63,
493,
63,
632,
12,
5463,
63,
493,
63,
632,
12,
971,
355,
282,
63,
3543,
12,
330,
63,
3543,
12,
330,
63,
632,
275,
1406,
14,
2634,
342,
288,
892,
63,
493,
12,
5463,
63,
493,
275,
2155,
8,
1222,
63,
493,
63,
632,
395,
2155,
8,
6062,
63,
493,
63,
632,
9,
953,
14981,
14,
740,
8,
10746,
8,
3417,
12,
282,
63,
515,
12,
330,
63,
515,
12,
282,
63,
3543,
12,
330,
63,
3543,
12,
355,
2269,
63,
632,
503,
5463,
63,
493,
63,
632,
12,
892,
63,
632,
503,
892,
63,
493,
63,
632,
503,
330,
63,
632,
12,
355,
892,
63,
493,
12,
5463,
63,
493,
12,
11441,
63,
504,
12,
11441,
63,
475,
12,
3915,
59,
1291,
14,
500,
837,
2459,
398,
372,
14981,
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
] | [
3915,
14,
647,
199,
3,
1898,
334,
35,
9,
9079,
13,
6542,
16922,
377,
10742,
334,
77,
599,
281,
32,
6799,
14,
957,
9,
436,
8417,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
12579,
4718,
436,
365,
14286,
1334,
199,
3,
314,
6289,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
15746,
13,
1682,
14,
8624,
199,
199,
646,
295,
199,
646,
5532,
199,
199,
533,
27134,
8,
785,
304,
272,
408,
272,
437,
27134,
3509,
3915,
2556,
3382,
2877,
20835,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3831,
12,
282,
63,
515,
12,
330,
63,
515,
12,
282,
63,
3543,
12,
330,
63,
3543,
12,
282,
63,
632,
12,
326,
330,
63,
632,
12,
892,
63,
493,
12,
5463,
63,
493,
12,
11441,
63,
504,
12,
326,
11441,
63,
475,
12,
3915,
304,
267,
291,
14,
3417,
275,
3831,
267,
291,
14,
65,
63,
515,
275,
282,
63,
515,
267,
291,
14,
66,
63,
515,
275,
330,
63,
515,
398,
340,
440,
282,
63,
3543,
503,
295,
14,
1733,
8,
82,
4289,
16,
91,
2167,
19204,
282,
63,
3543,
304,
288,
291,
14,
65,
63,
3543,
275,
488,
267,
587,
26,
288,
291,
14,
65,
63,
3543,
275,
5532,
14,
11421,
8,
3417,
12,
1305,
29,
65,
63,
3543,
9,
267,
340,
440,
330,
63,
3543,
503,
295,
14,
1733,
8,
82,
4289,
16,
91,
2167,
19204,
330,
63,
3543,
304,
288,
291,
14,
66,
63,
3543,
275,
488,
267,
587,
26,
288,
291,
14,
66,
63,
3543,
275,
5532,
14,
11421,
8,
3417,
12,
1305,
29,
66,
63,
3543,
9,
398,
291,
14,
65,
63,
632,
275,
282,
63,
632,
267,
291,
14,
66,
63,
632,
275,
330,
63,
632,
267,
291,
14,
1222,
63,
493,
275,
892,
63,
493,
267,
291,
14,
6062,
63,
493,
275,
5463,
63,
493,
267,
291,
14,
8165,
63,
504,
275,
11441,
63,
504,
267,
291,
14,
8165,
63,
475,
275,
11441,
63,
475,
267,
291,
14,
29401,
275,
11441,
63,
504,
1137,
11441,
63,
475,
267,
291,
14,
3028,
275,
3915,
339,
768,
3744,
272,
347,
769,
63,
504,
63,
875,
8,
1886,
12,
3831,
12,
1318,
304,
267,
14981,
275,
942,
398,
3915,
63,
1291,
275,
295,
14,
2014,
8,
82,
624,
288,
327,
62,
3028,
59,
1622,
306,
3187,
355,
359,
1622,
65,
9448,
48,
28,
65,
63,
515,
3072,
51,
11,
2788,
1622,
66,
9448,
48,
28,
66,
63,
515,
3072,
51,
13439,
78,
288,
16697,
62,
21965,
59,
1622,
1080,
59,
1622,
2229,
48,
28,
21965,
63,
1080,
3072,
68,
8771,
27744,
78,
2049,
7167,
8165,
59,
1622,
504,
59,
1622,
2229,
48,
28,
8165,
63,
504,
3072,
51,
13439,
78,
2049,
7167,
8165,
59,
1622,
475,
59,
1622,
2229,
48,
28,
8165,
63,
475,
3072,
51,
8771,
15840,
78,
92,
4,
22119,
288,
16697,
62,
1753,
59,
1622,
632,
59,
1622,
2229,
48,
28,
1753,
63,
632,
3072,
68,
13439,
78,
2049,
7167,
1222,
59,
1622,
632,
59,
1622,
2229,
48,
28,
1222,
63,
632,
3072,
68,
8771,
15840,
78,
92,
4,
22119,
288,
16697,
62,
1222,
59,
1622,
493,
59,
1622,
632,
59,
1622,
2229,
48,
28,
1222,
63,
493,
63,
632,
31411,
9,
15840,
78,
92,
4,
22119,
288,
16697,
62,
6062,
59,
1622,
493,
59,
1622,
632,
59,
1622,
2229,
48,
28,
6062,
63,
493,
63,
632,
31411,
9,
15840,
78,
92,
4,
22119,
288,
16697,
62,
1080,
59,
1622,
2229,
48,
28,
65,
63,
3543,
9514,
16,
13,
25,
33,
13,
1906,
13,
70,
11896,
355,
971,
3134,
14,
2229,
48,
28,
66,
63,
3543,
9514,
16,
13,
25,
33,
13,
1906,
13,
70,
2807,
2788,
1622,
31,
2229,
48,
28,
66,
63,
632,
31411,
5547,
15840,
78,
92,
4,
22119,
267,
10327,
295,
14,
16075,
1204,
295,
14,
16661,
680,
1431,
398,
367,
3915,
315,
17485,
78,
7,
435,
1318,
680,
1294,
2258,
28632,
1553,
3187,
5832,
17,
10688,
288,
1406,
275,
3915,
63,
1291,
8,
3028,
9,
953,
282,
63,
515,
12,
330,
63,
515,
12,
22838,
63,
1080,
12,
11441,
63,
504,
12,
11441,
63,
475,
12,
971,
355,
2269,
63,
632,
12,
892,
63,
632,
12,
892,
63,
493,
63,
632,
12,
5463,
63,
493,
63,
632,
12,
971,
355,
282,
63,
3543,
12,
330,
63,
3543,
12,
330,
63,
632,
275,
1406,
14,
2634,
342,
288,
892,
63,
493,
12,
5463,
63,
493,
275,
2155,
8,
1222,
63,
493,
63,
632,
395,
2155,
8,
6062,
63,
493,
63,
632,
9,
953,
14981,
14,
740,
8,
10746,
8,
3417,
12,
282,
63,
515,
12,
330,
63,
515,
12,
282,
63,
3543,
12,
330,
63,
3543,
12,
355,
2269,
63,
632,
503,
5463,
63,
493,
63,
632,
12,
892,
63,
632,
503,
892,
63,
493,
63,
632,
503,
330,
63,
632,
12,
355,
892,
63,
493,
12,
5463,
63,
493,
12,
11441,
63,
504,
12,
11441,
63,
475,
12,
3915,
59,
1291,
14,
500,
837,
2459,
398,
372,
14981,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
galtys/odoo | setup.py | 37 | 5624 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import re
from glob import glob
from setuptools import find_packages, setup
from os.path import join, dirname
execfile(join(dirname(__file__), 'openerp', 'release.py')) # Load release variables
lib_name = 'openerp'
def py2exe_datafiles():
data_files = {}
data_files['Microsoft.VC90.CRT'] = glob('C:\Microsoft.VC90.CRT\*.*')
for root, dirnames, filenames in os.walk('openerp'):
for filename in filenames:
if not re.match(r'.*(\.pyc|\.pyo|\~)$', filename):
data_files.setdefault(root, []).append(join(root, filename))
import babel
data_files['babel/localedata'] = glob(join(dirname(babel.__file__), 'localedata', '*'))
others = ['global.dat', 'numbers.py', 'support.py', 'plural.py']
data_files['babel'] = map(lambda f: join(dirname(babel.__file__), f), others)
others = ['frontend.py', 'mofile.py']
data_files['babel/messages'] = map(lambda f: join(dirname(babel.__file__), 'messages', f), others)
import pytz
tzdir = dirname(pytz.__file__)
for root, _, filenames in os.walk(join(tzdir, 'zoneinfo')):
base = join('pytz', root[len(tzdir) + 1:])
data_files[base] = [join(root, f) for f in filenames]
import docutils
dudir = dirname(docutils.__file__)
for root, _, filenames in os.walk(dudir):
base = join('docutils', root[len(dudir) + 1:])
data_files[base] = [join(root, f) for f in filenames if not f.endswith(('.py', '.pyc', '.pyo'))]
import passlib
pl = dirname(passlib.__file__)
for root, _, filenames in os.walk(pl):
base = join('passlib', root[len(pl) + 1:])
data_files[base] = [join(root, f) for f in filenames if not f.endswith(('.py', '.pyc', '.pyo'))]
return data_files.items()
def py2exe_options():
if os.name == 'nt':
import py2exe
return {
'console': [
{'script': 'odoo.py'},
{'script': 'openerp-gevent'},
{'script': 'openerp-server', 'icon_resources': [
(1, join('setup', 'win32', 'static', 'pixmaps', 'openerp-icon.ico'))
]},
],
'options': {
'py2exe': {
'skip_archive': 1,
'optimize': 0, # Keep the assert running as the integrated tests rely on them.
'dist_dir': 'dist',
'packages': [
'asynchat', 'asyncore',
'commands',
'dateutil',
'decimal',
'decorator',
'docutils',
'email',
'encodings',
'HTMLParser',
'imaplib',
'jinja2',
'lxml', 'lxml._elementpath', 'lxml.builder', 'lxml.etree', 'lxml.objectify',
'mako',
'markupsafe',
'mock',
'openerp',
'openid',
'passlib',
'PIL',
'poplib',
'psutil',
'pychart',
'pydot',
'pyparsing',
'pyPdf',
'pytz',
'reportlab',
'requests',
'select',
'simplejson',
'smtplib',
'uuid',
'vatnumber',
'vobject',
'win32service', 'win32serviceutil',
'xlwt',
'xml', 'xml.dom',
'yaml',
],
'excludes': ['Tkconstants', 'Tkinter', 'tcl'],
}
},
'data_files': py2exe_datafiles()
}
else:
return {}
setup(
name='odoo',
version=version,
description=description,
long_description=long_desc,
url=url,
author=author,
author_email=author_email,
classifiers=filter(None, classifiers.split('\n')),
license=license,
scripts=['openerp-server', 'openerp-gevent', 'odoo.py'],
packages=find_packages(),
package_dir={'%s' % lib_name: 'openerp'},
include_package_data=True,
install_requires=[
'babel >= 1.0',
'decorator',
'docutils',
'feedparser',
'gevent',
'Jinja2',
'lxml', # windows binary http://www.lfd.uci.edu/~gohlke/pythonlibs/
'mako',
'mock',
'passlib',
'pillow', # windows binary http://www.lfd.uci.edu/~gohlke/pythonlibs/
'psutil', # windows binary code.google.com/p/psutil/downloads/list
'psycogreen',
'psycopg2 >= 2.2',
'python-chart',
'pydot',
'pyparsing',
'pypdf',
'pyserial',
'python-dateutil',
'python-ldap', # optional
'python-openid',
'pytz',
'pyusb >= 1.0.0b1',
'pyyaml',
'qrcode',
'reportlab', # windows binary pypi.python.org/pypi/reportlab
'requests',
'simplejson',
'unittest2',
'vatnumber',
'vobject',
'werkzeug',
'xlwt',
],
extras_require={
'SSL': ['pyopenssl'],
},
tests_require=[
'unittest2',
'mock',
],
**py2exe_options()
)
| agpl-3.0 | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
747,
199,
646,
295,
199,
504,
5739,
492,
5739,
199,
504,
9116,
492,
2342,
63,
5154,
12,
3272,
199,
504,
747,
14,
515,
492,
4263,
12,
9017,
421,
199,
1628,
493,
8,
904,
8,
3475,
3460,
493,
10139,
283,
11267,
297,
283,
3221,
14,
647,
1333,
221,
327,
7190,
4683,
2860,
199,
773,
63,
354,
275,
283,
11267,
7,
421,
199,
318,
1134,
18,
5803,
63,
576,
1725,
837,
272,
666,
63,
1725,
275,
1052,
272,
666,
63,
1725,
459,
12940,
14,
9454,
2710,
14,
2944,
52,
418,
275,
5739,
360,
35,
3427,
12940,
14,
9454,
2710,
14,
2944,
52,
60,
10,
24915,
339,
367,
1738,
12,
22310,
12,
6203,
315,
747,
14,
7757,
360,
11267,
735,
267,
367,
1788,
315,
6203,
26,
288,
340,
440,
295,
14,
1431,
8,
82,
1370,
22588,
14,
11357,
92,
4537,
22345,
6113,
94,
29150,
1788,
304,
355,
666,
63,
1725,
14,
5486,
8,
1231,
12,
15364,
740,
8,
904,
8,
1231,
12,
1788,
430,
339,
492,
29178,
272,
666,
63,
1725,
459,
66,
902,
15,
5508,
576,
418,
275,
5739,
8,
904,
8,
3475,
8,
66,
902,
855,
493,
10139,
283,
5508,
576,
297,
6438,
1333,
272,
11789,
275,
788,
2966,
14,
4616,
297,
283,
10548,
14,
647,
297,
283,
4058,
14,
647,
297,
283,
10019,
14,
647,
418,
272,
666,
63,
1725,
459,
66,
902,
418,
275,
2341,
8,
2734,
289,
26,
4263,
8,
3475,
8,
66,
902,
855,
493,
10139,
289,
395,
11789,
9,
272,
11789,
275,
788,
18062,
14,
647,
297,
283,
573,
493,
14,
647,
418,
272,
666,
63,
1725,
459,
66,
902,
15,
3431,
418,
275,
2341,
8,
2734,
289,
26,
4263,
8,
3475,
8,
66,
902,
855,
493,
10139,
283,
3431,
297,
289,
395,
11789,
9,
339,
492,
15444,
272,
5823,
694,
275,
9017,
8,
21948,
855,
493,
3368,
272,
367,
1738,
12,
5501,
6203,
315,
747,
14,
7757,
8,
904,
8,
3903,
694,
12,
283,
2619,
815,
8109,
267,
1300,
275,
4263,
360,
21948,
297,
1738,
59,
552,
8,
3903,
694,
9,
435,
413,
5728,
267,
666,
63,
1725,
59,
1095,
61,
275,
359,
904,
8,
1231,
12,
289,
9,
367,
289,
315,
6203,
61,
339,
492,
18382,
272,
15776,
694,
275,
9017,
8,
27114,
855,
493,
3368,
272,
367,
1738,
12,
5501,
6203,
315,
747,
14,
7757,
8,
2033,
694,
304,
267,
1300,
275,
4263,
360,
27114,
297,
1738,
59,
552,
8,
2033,
694,
9,
435,
413,
5728,
267,
666,
63,
1725,
59,
1095,
61,
275,
359,
904,
8,
1231,
12,
289,
9,
367,
289,
315,
6203,
340,
440,
289,
14,
4130,
4725,
14,
647,
297,
1987,
11357,
297,
1987,
22345,
27738,
339,
492,
986,
773,
272,
1620,
275,
9017,
8,
1529,
773,
855,
493,
3368,
272,
367,
1738,
12,
5501,
6203,
315,
747,
14,
7757,
8,
1168,
304,
267,
1300,
275,
4263,
360,
1529,
773,
297,
1738,
59,
552,
8,
1168,
9,
435,
413,
5728,
267,
666,
63,
1725,
59,
1095,
61,
275,
359,
904,
8,
1231,
12,
289,
9,
367,
289,
315,
6203,
340,
440,
289,
14,
4130,
4725,
14,
647,
297,
1987,
11357,
297,
1987,
22345,
27738,
339,
372,
666,
63,
1725,
14,
1744,
342,
421,
199,
318,
1134,
18,
5803,
63,
1419,
837,
272,
340,
747,
14,
354,
508,
283,
343,
356,
267,
492,
1134,
18,
5803,
267,
372,
469,
288,
283,
6614,
356,
359,
355,
791,
1579,
356,
283,
22058,
14,
647,
2267,
355,
791,
1579,
356,
283,
11267,
13,
303,
782,
2267,
355,
791,
1579,
356,
283,
11267,
13,
1000,
297,
283,
4677,
63,
4435,
356,
359,
490,
334,
17,
12,
4263,
360,
2758,
297,
283,
2676,
708,
297,
283,
1986,
297,
283,
6644,
8919,
297,
283,
11267,
13,
4677,
14,
12802,
1333,
355,
1622,
1386,
288,
2156,
288,
283,
1419,
356,
469,
355,
283,
647,
18,
5803,
356,
469,
490,
283,
2759,
63,
6404,
356,
413,
12,
490,
283,
13416,
356,
378,
12,
221,
327,
14797,
314,
702,
3879,
465,
314,
17806,
972,
2295,
19687,
641,
3062,
14,
490,
283,
2686,
63,
694,
356,
283,
2686,
297,
490,
283,
5154,
356,
359,
717,
283,
305,
5654,
292,
297,
283,
305,
25400,
297,
717,
283,
4405,
297,
717,
283,
602,
1974,
297,
717,
283,
6355,
297,
717,
283,
11547,
297,
717,
283,
27114,
297,
717,
283,
2123,
297,
717,
283,
21138,
297,
717,
283,
27375,
297,
717,
283,
15311,
773,
297,
717,
283,
12264,
18,
297,
717,
283,
22899,
297,
283,
22899,
423,
2108,
515,
297,
283,
22899,
14,
5649,
297,
283,
22899,
14,
9464,
297,
283,
22899,
14,
1113,
825,
3338,
297,
717,
283,
19491,
297,
717,
283,
10131,
3489,
297,
717,
283,
1805,
297,
717,
283,
11267,
297,
717,
283,
15403,
297,
717,
283,
1529,
773,
297,
717,
283,
48,
1193,
297,
717,
283,
1935,
773,
297,
717,
283,
31903,
297,
717,
283,
647,
9019,
297,
717,
283,
647,
3287,
297,
717,
283,
647,
11059,
297,
717,
283,
647,
48,
1587,
297,
717,
283,
21948,
297,
717,
283,
3070,
5561,
297,
717,
283,
6615,
297,
717,
283,
2416,
297,
717,
283,
4129,
1001,
297,
717,
283,
15592,
773,
297,
717,
283,
2580,
297,
717,
283,
16305,
1955,
297,
717,
283,
86,
785,
297,
717,
283,
2676,
708,
1364,
297,
283,
2676,
708,
1364,
1974,
297,
717,
283,
15455,
9115,
297,
717,
283,
1652,
297,
283,
1652,
14,
4556,
297,
717,
283,
5963,
297,
490,
2156,
490,
283,
26984,
356,
788,
15189,
5559,
297,
283,
15189,
1058,
297,
283,
23644,
995,
355,
789,
288,
1660,
288,
283,
576,
63,
1725,
356,
1134,
18,
5803,
63,
576,
1725,
342,
267,
789,
272,
587,
26,
267,
372,
1052,
421,
199,
2758,
8,
272,
536,
534,
22058,
297,
272,
1015,
29,
1023,
12,
272,
1369,
29,
1802,
12,
272,
1846,
63,
1802,
29,
2809,
63,
3257,
12,
272,
1166,
29,
633,
12,
272,
4132,
29,
2502,
12,
272,
4132,
63,
2123,
29,
2502,
63,
2123,
12,
272,
19137,
29,
1541,
8,
403,
12,
19137,
14,
1294,
2258,
78,
3855,
272,
4190,
29,
1682,
12,
272,
10554,
2968,
11267,
13,
1000,
297,
283,
11267,
13,
303,
782
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
747,
199,
646,
295,
199,
504,
5739,
492,
5739,
199,
504,
9116,
492,
2342,
63,
5154,
12,
3272,
199,
504,
747,
14,
515,
492,
4263,
12,
9017,
421,
199,
1628,
493,
8,
904,
8,
3475,
3460,
493,
10139,
283,
11267,
297,
283,
3221,
14,
647,
1333,
221,
327,
7190,
4683,
2860,
199,
773,
63,
354,
275,
283,
11267,
7,
421,
199,
318,
1134,
18,
5803,
63,
576,
1725,
837,
272,
666,
63,
1725,
275,
1052,
272,
666,
63,
1725,
459,
12940,
14,
9454,
2710,
14,
2944,
52,
418,
275,
5739,
360,
35,
3427,
12940,
14,
9454,
2710,
14,
2944,
52,
60,
10,
24915,
339,
367,
1738,
12,
22310,
12,
6203,
315,
747,
14,
7757,
360,
11267,
735,
267,
367,
1788,
315,
6203,
26,
288,
340,
440,
295,
14,
1431,
8,
82,
1370,
22588,
14,
11357,
92,
4537,
22345,
6113,
94,
29150,
1788,
304,
355,
666,
63,
1725,
14,
5486,
8,
1231,
12,
15364,
740,
8,
904,
8,
1231,
12,
1788,
430,
339,
492,
29178,
272,
666,
63,
1725,
459,
66,
902,
15,
5508,
576,
418,
275,
5739,
8,
904,
8,
3475,
8,
66,
902,
855,
493,
10139,
283,
5508,
576,
297,
6438,
1333,
272,
11789,
275,
788,
2966,
14,
4616,
297,
283,
10548,
14,
647,
297,
283,
4058,
14,
647,
297,
283,
10019,
14,
647,
418,
272,
666,
63,
1725,
459,
66,
902,
418,
275,
2341,
8,
2734,
289,
26,
4263,
8,
3475,
8,
66,
902,
855,
493,
10139,
289,
395,
11789,
9,
272,
11789,
275,
788,
18062,
14,
647,
297,
283,
573,
493,
14,
647,
418,
272,
666,
63,
1725,
459,
66,
902,
15,
3431,
418,
275,
2341,
8,
2734,
289,
26,
4263,
8,
3475,
8,
66,
902,
855,
493,
10139,
283,
3431,
297,
289,
395,
11789,
9,
339,
492,
15444,
272,
5823,
694,
275,
9017,
8,
21948,
855,
493,
3368,
272,
367,
1738,
12,
5501,
6203,
315,
747,
14,
7757,
8,
904,
8,
3903,
694,
12,
283,
2619,
815,
8109,
267,
1300,
275,
4263,
360,
21948,
297,
1738,
59,
552,
8,
3903,
694,
9,
435,
413,
5728,
267,
666,
63,
1725,
59,
1095,
61,
275,
359,
904,
8,
1231,
12,
289,
9,
367,
289,
315,
6203,
61,
339,
492,
18382,
272,
15776,
694,
275,
9017,
8,
27114,
855,
493,
3368,
272,
367,
1738,
12,
5501,
6203,
315,
747,
14,
7757,
8,
2033,
694,
304,
267,
1300,
275,
4263,
360,
27114,
297,
1738,
59,
552,
8,
2033,
694,
9,
435,
413,
5728,
267,
666,
63,
1725,
59,
1095,
61,
275,
359,
904,
8,
1231,
12,
289,
9,
367,
289,
315,
6203,
340,
440,
289,
14,
4130,
4725,
14,
647,
297,
1987,
11357,
297,
1987,
22345,
27738,
339,
492,
986,
773,
272,
1620,
275,
9017,
8,
1529,
773,
855,
493,
3368,
272,
367,
1738,
12,
5501,
6203,
315,
747,
14,
7757,
8,
1168,
304,
267,
1300,
275,
4263,
360,
1529,
773,
297,
1738,
59,
552,
8,
1168,
9,
435,
413,
5728,
267,
666,
63,
1725,
59,
1095,
61,
275,
359,
904,
8,
1231,
12,
289,
9,
367,
289,
315,
6203,
340,
440,
289,
14,
4130,
4725,
14,
647,
297,
1987,
11357,
297,
1987,
22345,
27738,
339,
372,
666,
63,
1725,
14,
1744,
342,
421,
199,
318,
1134,
18,
5803,
63,
1419,
837,
272,
340,
747,
14,
354,
508,
283,
343,
356,
267,
492,
1134,
18,
5803,
267,
372,
469,
288,
283,
6614,
356,
359,
355,
791,
1579,
356,
283,
22058,
14,
647,
2267,
355,
791,
1579,
356,
283,
11267,
13,
303,
782,
2267,
355,
791,
1579,
356,
283,
11267,
13,
1000,
297,
283,
4677,
63,
4435,
356,
359,
490,
334,
17,
12,
4263,
360,
2758,
297,
283,
2676,
708,
297,
283,
1986,
297,
283,
6644,
8919,
297,
283,
11267,
13,
4677,
14,
12802,
1333,
355,
1622,
1386,
288,
2156,
288,
283,
1419,
356,
469,
355,
283,
647,
18,
5803,
356,
469,
490,
283,
2759,
63,
6404,
356,
413,
12,
490,
283,
13416,
356,
378,
12,
221,
327,
14797,
314,
702,
3879,
465,
314,
17806,
972,
2295,
19687,
641,
3062,
14,
490,
283,
2686,
63,
694,
356,
283,
2686,
297,
490,
283,
5154,
356,
359,
717,
283,
305,
5654,
292,
297,
283,
305,
25400,
297,
717,
283,
4405,
297,
717,
283,
602,
1974,
297,
717,
283,
6355,
297,
717,
283,
11547,
297,
717,
283,
27114,
297,
717,
283,
2123,
297,
717,
283,
21138,
297,
717,
283,
27375,
297,
717,
283,
15311,
773,
297,
717,
283,
12264,
18,
297,
717,
283,
22899,
297,
283,
22899,
423,
2108,
515,
297,
283,
22899,
14,
5649,
297,
283,
22899,
14,
9464,
297,
283,
22899,
14,
1113,
825,
3338,
297,
717,
283,
19491,
297,
717,
283,
10131,
3489,
297,
717,
283,
1805,
297,
717,
283,
11267,
297,
717,
283,
15403,
297,
717,
283,
1529,
773,
297,
717,
283,
48,
1193,
297,
717,
283,
1935,
773,
297,
717,
283,
31903,
297,
717,
283,
647,
9019,
297,
717,
283,
647,
3287,
297,
717,
283,
647,
11059,
297,
717,
283,
647,
48,
1587,
297,
717,
283,
21948,
297,
717,
283,
3070,
5561,
297,
717,
283,
6615,
297,
717,
283,
2416,
297,
717,
283,
4129,
1001,
297,
717,
283,
15592,
773,
297,
717,
283,
2580,
297,
717,
283,
16305,
1955,
297,
717,
283,
86,
785,
297,
717,
283,
2676,
708,
1364,
297,
283,
2676,
708,
1364,
1974,
297,
717,
283,
15455,
9115,
297,
717,
283,
1652,
297,
283,
1652,
14,
4556,
297,
717,
283,
5963,
297,
490,
2156,
490,
283,
26984,
356,
788,
15189,
5559,
297,
283,
15189,
1058,
297,
283,
23644,
995,
355,
789,
288,
1660,
288,
283,
576,
63,
1725,
356,
1134,
18,
5803,
63,
576,
1725,
342,
267,
789,
272,
587,
26,
267,
372,
1052,
421,
199,
2758,
8,
272,
536,
534,
22058,
297,
272,
1015,
29,
1023,
12,
272,
1369,
29,
1802,
12,
272,
1846,
63,
1802,
29,
2809,
63,
3257,
12,
272,
1166,
29,
633,
12,
272,
4132,
29,
2502,
12,
272,
4132,
63,
2123,
29,
2502,
63,
2123,
12,
272,
19137,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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
] |
leviroth/praw | praw/models/base.py | 6 | 1256 | """Provide the PRAWBase superclass."""
from copy import deepcopy
class PRAWBase(object):
"""Superclass for all models in PRAW."""
@staticmethod
def _safely_add_arguments(argument_dict, key, **new_arguments):
"""Replace argument_dict[key] with a deepcopy and update.
This method is often called when new parameters need to be added to a
request. By calling this method and adding the new or updated
parameters we can insure we don't modify the dictionary passed in by
the caller.
"""
value = deepcopy(argument_dict[key]) if key in argument_dict else {}
value.update(new_arguments)
argument_dict[key] = value
@classmethod
def parse(cls, data, reddit):
"""Return an instance of ``cls`` from ``data``.
:param data: The structured data.
:param reddit: An instance of :class:`.Reddit`.
"""
return cls(reddit, _data=data)
def __init__(self, reddit, _data):
"""Initialize a PRAWModel instance.
:param reddit: An instance of :class:`.Reddit`.
"""
self._reddit = reddit
if _data:
for attribute, value in _data.items():
setattr(self, attribute, value)
| bsd-2-clause | [
624,
25107,
314,
510,
4307,
1563,
17035,
1041,
199,
504,
1331,
492,
14800,
421,
199,
533,
510,
4307,
1563,
8,
785,
304,
272,
408,
11823,
533,
367,
1006,
1709,
315,
510,
4307,
1041,
339,
768,
4639,
272,
347,
485,
2231,
70,
7742,
63,
525,
63,
4958,
8,
2094,
63,
807,
12,
790,
12,
1011,
1222,
63,
4958,
304,
267,
408,
11328,
1423,
63,
807,
59,
498,
61,
543,
282,
14800,
436,
1678,
14,
398,
961,
1083,
365,
14115,
2797,
1380,
892,
2633,
1929,
370,
506,
3483,
370,
282,
267,
1056,
14,
4885,
6358,
642,
1083,
436,
7791,
314,
892,
503,
4588,
267,
2633,
781,
883,
315,
3253,
781,
2793,
1133,
2811,
314,
2600,
3032,
315,
701,
267,
314,
8025,
14,
398,
408,
267,
574,
275,
14800,
8,
2094,
63,
807,
59,
498,
566,
340,
790,
315,
1423,
63,
807,
587,
1052,
267,
574,
14,
873,
8,
1222,
63,
4958,
9,
267,
1423,
63,
807,
59,
498,
61,
275,
574,
339,
768,
3744,
272,
347,
2198,
8,
1886,
12,
666,
12,
8992,
1741,
304,
267,
408,
1767,
376,
1256,
402,
1124,
1886,
1040,
687,
1124,
576,
4345,
398,
520,
635,
666,
26,
710,
21781,
666,
14,
267,
520,
635,
8992,
1741,
26,
1626,
1256,
402,
520,
533,
5026,
10858,
1741,
2313,
398,
408,
267,
372,
843,
8,
18374,
12,
485,
576,
29,
576,
9,
339,
347,
636,
826,
721,
277,
12,
8992,
1741,
12,
485,
576,
304,
267,
408,
9345,
282,
510,
4307,
1685,
1256,
14,
398,
520,
635,
8992,
1741,
26,
1626,
1256,
402,
520,
533,
5026,
10858,
1741,
2313,
398,
408,
267,
291,
423,
18374,
275,
8992,
1741,
267,
340,
485,
576,
26,
288,
367,
2225,
12,
574,
315,
485,
576,
14,
1744,
837,
355,
5371,
8,
277,
12,
2225,
12,
574,
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
] | [
25107,
314,
510,
4307,
1563,
17035,
1041,
199,
504,
1331,
492,
14800,
421,
199,
533,
510,
4307,
1563,
8,
785,
304,
272,
408,
11823,
533,
367,
1006,
1709,
315,
510,
4307,
1041,
339,
768,
4639,
272,
347,
485,
2231,
70,
7742,
63,
525,
63,
4958,
8,
2094,
63,
807,
12,
790,
12,
1011,
1222,
63,
4958,
304,
267,
408,
11328,
1423,
63,
807,
59,
498,
61,
543,
282,
14800,
436,
1678,
14,
398,
961,
1083,
365,
14115,
2797,
1380,
892,
2633,
1929,
370,
506,
3483,
370,
282,
267,
1056,
14,
4885,
6358,
642,
1083,
436,
7791,
314,
892,
503,
4588,
267,
2633,
781,
883,
315,
3253,
781,
2793,
1133,
2811,
314,
2600,
3032,
315,
701,
267,
314,
8025,
14,
398,
408,
267,
574,
275,
14800,
8,
2094,
63,
807,
59,
498,
566,
340,
790,
315,
1423,
63,
807,
587,
1052,
267,
574,
14,
873,
8,
1222,
63,
4958,
9,
267,
1423,
63,
807,
59,
498,
61,
275,
574,
339,
768,
3744,
272,
347,
2198,
8,
1886,
12,
666,
12,
8992,
1741,
304,
267,
408,
1767,
376,
1256,
402,
1124,
1886,
1040,
687,
1124,
576,
4345,
398,
520,
635,
666,
26,
710,
21781,
666,
14,
267,
520,
635,
8992,
1741,
26,
1626,
1256,
402,
520,
533,
5026,
10858,
1741,
2313,
398,
408,
267,
372,
843,
8,
18374,
12,
485,
576,
29,
576,
9,
339,
347,
636,
826,
721,
277,
12,
8992,
1741,
12,
485,
576,
304,
267,
408,
9345,
282,
510,
4307,
1685,
1256,
14,
398,
520,
635,
8992,
1741,
26,
1626,
1256,
402,
520,
533,
5026,
10858,
1741,
2313,
398,
408,
267,
291,
423,
18374,
275,
8992,
1741,
267,
340,
485,
576,
26,
288,
367,
2225,
12,
574,
315,
485,
576,
14,
1744,
837,
355,
5371,
8,
277,
12,
2225,
12,
574,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
KosiehBarter/anaconda | pyanaconda/pwpolicy.py | 10 | 4777 | #
# Brian C. Lane <[email protected]>
#
# Copyright 2015 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use, modify,
# copy, or redistribute it subject to the terms and conditions of the GNU
# General Public License v.2. This program is distributed in the hope that it
# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
# implied warranties 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. Any Red Hat
# trademarks that are incorporated in the source code or documentation are not
# subject to the GNU General Public License and may only be used or replicated
# with the express permission of Red Hat, Inc.
#
from pykickstart.base import BaseData, KickstartCommand
from pykickstart.errors import KickstartValueError, formatErrorMsg
from pykickstart.options import KSOptionParser
import warnings
from pyanaconda.i18n import _
class F22_PwPolicyData(BaseData):
""" Kickstart Data object to hold information about pwpolicy. """
removedKeywords = BaseData.removedKeywords
removedAttrs = BaseData.removedAttrs
def __init__(self, *args, **kwargs):
BaseData.__init__(self, *args, **kwargs)
self.name = kwargs.get("name", "")
self.minlen = kwargs.get("minlen", 8)
self.minquality = kwargs.get("minquality", 50)
self.strict = kwargs.get("strict", True)
self.changesok = kwargs.get("changesok", False)
self.emptyok = kwargs.get("emptyok", True)
def __eq__(self, y):
if not y:
return False
return self.name == y.name
def __ne__(self, y):
return not self == y
def __str__(self):
retval = BaseData.__str__(self)
if self.name != "":
retval += "pwpolicy"
retval += self._getArgsAsStr() + "\n"
return retval
def _getArgsAsStr(self):
retval = ""
retval += " %s" % self.name
retval += " --minlen=%d" % self.minlen
retval += " --minquality=%d" % self.minquality
if self.strict:
retval += " --strict"
else:
retval += " --notstrict"
if self.changesok:
retval += " --changesok"
else:
retval += " --nochanges"
if self.emptyok:
retval += " --emptyok"
else:
retval += " --notempty"
return retval
class F22_PwPolicy(KickstartCommand):
""" Kickstart command implementing password policy. """
removedKeywords = KickstartCommand.removedKeywords
removedAttrs = KickstartCommand.removedAttrs
def __init__(self, writePriority=0, *args, **kwargs):
KickstartCommand.__init__(self, writePriority, *args, **kwargs)
self.op = self._getParser()
self.policyList = kwargs.get("policyList", [])
def __str__(self):
retval = ""
for policy in self.policyList:
retval += policy.__str__()
return retval
def _getParser(self):
op = KSOptionParser()
op.add_option("--minlen", type="int")
op.add_option("--minquality", type="int")
op.add_option("--strict", action="store_true")
op.add_option("--notstrict", dest="strict", action="store_false")
op.add_option("--changesok", action="store_true")
op.add_option("--nochanges", dest="changesok", action="store_false")
op.add_option("--emptyok", action="store_true")
op.add_option("--notempty", dest="emptyok", action="store_false")
return op
def parse(self, args):
(opts, extra) = self.op.parse_args(args=args, lineno=self.lineno)
if len(extra) != 1:
raise KickstartValueError(formatErrorMsg(self.lineno, msg=_("policy name required for %s") % "pwpolicy"))
pd = self.handler.PwPolicyData()
self._setToObj(self.op, opts, pd)
pd.lineno = self.lineno
pd.name = extra[0]
# Check for duplicates in the data list.
if pd in self.dataList():
warnings.warn(_("A %(command)s with the name %(policyName)s has already been defined.") % {"command": "pwpolicy", "policyName": pd.name})
return pd
def dataList(self):
return self.policyList
def get_policy(self, name):
""" Get the policy by name
:param str name: Name of the policy to return.
"""
policy = [p for p in self.policyList if p.name == name]
if policy:
return policy[0]
else:
return None
| gpl-2.0 | [
3,
199,
3,
699,
18429,
445,
14,
491,
5865,
665,
66,
429,
32,
17164,
14,
957,
30,
199,
3,
199,
3,
1898,
6900,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
1331,
31816,
471,
6285,
365,
6326,
2808,
370,
29165,
13809,
316,
370,
675,
12,
2811,
12,
199,
3,
1331,
12,
503,
3604,
652,
5420,
370,
314,
2895,
436,
3704,
402,
314,
1664,
199,
3,
1696,
1684,
844,
373,
14,
18,
14,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
199,
3,
911,
506,
2997,
12,
1325,
2428,
1821,
3408,
19147,
503,
2478,
12,
5893,
314,
199,
3,
2478,
3712,
1417,
402,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
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,
12,
8217,
14,
221,
6184,
9572,
13002,
199,
3,
21032,
10375,
626,
787,
30147,
972,
315,
314,
1350,
1233,
503,
3794,
787,
440,
199,
3,
5420,
370,
314,
1664,
1696,
1684,
844,
436,
1443,
1454,
506,
1202,
503,
32436,
199,
3,
543,
314,
4056,
4983,
402,
9572,
13002,
12,
3277,
14,
199,
3,
199,
504,
1134,
30784,
14,
1095,
492,
3523,
1451,
12,
1804,
18938,
3110,
199,
504,
1134,
30784,
14,
2550,
492,
1804,
18938,
3393,
12,
1475,
547,
6173,
199,
504,
1134,
30784,
14,
1419,
492,
1804,
51,
14553,
199,
199,
646,
3598,
199,
504,
1134,
28299,
14,
73,
1085,
78,
492,
485,
199,
199,
533,
481,
1081,
63,
48,
87,
4845,
1451,
8,
1563,
1451,
304,
272,
408,
1804,
18938,
3918,
909,
370,
10266,
2556,
3595,
19206,
3185,
14,
408,
272,
4829,
23611,
275,
3523,
1451,
14,
10649,
23611,
272,
4829,
21368,
275,
3523,
1451,
14,
10649,
21368,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
3523,
1451,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
354,
275,
2074,
14,
362,
480,
354,
401,
6899,
267,
291,
14,
827,
552,
275,
2074,
14,
362,
480,
827,
552,
401,
1695,
9,
267,
291,
14,
827,
9161,
275,
2074,
14,
362,
480,
827,
9161,
401,
5238,
9,
267,
291,
14,
4768,
275,
2074,
14,
362,
480,
4768,
401,
715,
9,
267,
291,
14,
6627,
745,
275,
2074,
14,
362,
480,
6627,
745,
401,
756,
9,
267,
291,
14,
1667,
745,
275,
2074,
14,
362,
480,
1667,
745,
401,
715,
9,
339,
347,
636,
4077,
721,
277,
12,
612,
304,
267,
340,
440,
612,
26,
288,
372,
756,
398,
372,
291,
14,
354,
508,
612,
14,
354,
339,
347,
636,
685,
721,
277,
12,
612,
304,
267,
372,
440,
291,
508,
612,
339,
347,
636,
495,
721,
277,
304,
267,
9151,
275,
3523,
1451,
855,
495,
721,
277,
9,
398,
340,
291,
14,
354,
1137,
10812,
288,
9151,
847,
298,
8796,
3185,
2,
288,
9151,
847,
291,
423,
362,
6213,
2822,
2848,
342,
435,
1867,
78,
2,
398,
372,
9151,
339,
347,
485,
362,
6213,
2822,
2848,
8,
277,
304,
267,
9151,
275,
3087,
398,
9151,
847,
298,
450,
83,
2,
450,
291,
14,
354,
267,
9151,
847,
298,
1553,
827,
552,
2458,
68,
2,
450,
291,
14,
827,
552,
267,
9151,
847,
298,
1553,
827,
9161,
2458,
68,
2,
450,
291,
14,
827,
9161,
398,
340,
291,
14,
4768,
26,
288,
9151,
847,
298,
1553,
4768,
2,
267,
587,
26,
288,
9151,
847,
298,
1553,
1397,
4768,
2,
267,
340,
291,
14,
6627,
745,
26,
288,
9151,
847,
298,
1553,
6627,
745,
2,
267,
587,
26,
288,
9151,
847,
298,
1553,
889,
6627,
2,
267,
340,
291,
14,
1667,
745,
26,
288,
9151,
847,
298,
1553,
1667,
745,
2,
267,
587,
26,
288,
9151,
847,
298,
1553,
889,
808,
369,
2,
398,
372,
9151,
199,
199,
533,
481,
1081,
63,
48,
87,
4845,
8,
43,
18938,
3110,
304,
272,
408,
1804,
18938,
1414,
18234,
2505,
4592,
14,
408,
272,
4829,
23611,
275,
1804,
18938,
3110,
14,
10649,
23611,
272,
4829,
21368,
275,
1804,
18938,
3110,
14,
10649,
21368,
339,
347,
636,
826,
721,
277,
12,
2218,
14354,
29,
16,
12,
627,
589,
12,
1011,
958,
304,
267,
1804,
18938,
3110,
855,
826,
721,
277,
12,
2218,
14354,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
411,
275,
291,
423,
362,
2842,
342,
398,
291,
14,
3185,
1296,
275,
2074,
14,
362,
480,
3185,
1296,
401,
3073,
339,
347,
636,
495,
721,
277,
304,
267,
9151,
275,
3087,
267,
367,
4592,
315,
291,
14,
3185,
1296,
26,
288,
9151,
847,
4592,
855,
495,
4533,
398,
372,
9151,
339,
347,
485,
362,
2842,
8,
277,
304,
267,
1687,
275,
1804,
51,
14553,
342,
267,
1687,
14,
525,
63,
1422,
6739,
827,
552,
401,
730,
628,
442,
531,
267,
1687,
14,
525,
63,
1422,
6739,
827,
9161,
401,
730,
628,
442,
531,
267,
1687,
14,
525,
63,
1422,
6739,
4768,
401,
1595,
628,
1617,
63,
2052,
531,
267,
1687,
14,
525,
63,
1422,
6739,
1397,
4768,
401,
2053,
628,
4768,
401,
1595,
628,
1617,
63,
3910,
531,
267,
1687,
14,
525,
63,
1422,
6739,
6627,
745,
401,
1595,
628,
1617,
63,
2052,
531,
267,
1687,
14,
525,
63,
1422,
6739,
889,
6627,
401,
2053,
628,
6627,
745,
401,
1595,
628,
1617,
63,
3910,
531,
267,
1687,
14,
525,
63,
1422,
6739,
1667,
745,
401,
1595,
628,
1617,
63,
2052,
531,
267,
1687,
14,
525,
63,
1422,
6739,
889,
808,
369,
401,
2053,
628,
1667,
745,
401,
1595,
628,
1617,
63,
3910,
531,
267,
372,
1687,
339,
347,
2198,
8,
277,
12,
1249,
304,
267,
334,
3291,
12,
2402,
9,
275,
291,
14,
411,
14,
1122,
63,
589,
8,
589,
29,
589,
12,
5874,
29,
277,
14,
3469,
9,
267,
340,
822,
8,
2911,
9,
1137,
413,
26,
288,
746,
1804,
18938,
3393,
8,
908,
547,
6173,
8,
277,
14,
3469,
12,
1499,
9384,
3185,
536,
1415,
367,
450,
83,
531,
450,
298,
8796,
3185,
2237,
398,
6454
] | [
199,
3,
699,
18429,
445,
14,
491,
5865,
665,
66,
429,
32,
17164,
14,
957,
30,
199,
3,
199,
3,
1898,
6900,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
1331,
31816,
471,
6285,
365,
6326,
2808,
370,
29165,
13809,
316,
370,
675,
12,
2811,
12,
199,
3,
1331,
12,
503,
3604,
652,
5420,
370,
314,
2895,
436,
3704,
402,
314,
1664,
199,
3,
1696,
1684,
844,
373,
14,
18,
14,
221,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
199,
3,
911,
506,
2997,
12,
1325,
2428,
1821,
3408,
19147,
503,
2478,
12,
5893,
314,
199,
3,
2478,
3712,
1417,
402,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
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,
12,
8217,
14,
221,
6184,
9572,
13002,
199,
3,
21032,
10375,
626,
787,
30147,
972,
315,
314,
1350,
1233,
503,
3794,
787,
440,
199,
3,
5420,
370,
314,
1664,
1696,
1684,
844,
436,
1443,
1454,
506,
1202,
503,
32436,
199,
3,
543,
314,
4056,
4983,
402,
9572,
13002,
12,
3277,
14,
199,
3,
199,
504,
1134,
30784,
14,
1095,
492,
3523,
1451,
12,
1804,
18938,
3110,
199,
504,
1134,
30784,
14,
2550,
492,
1804,
18938,
3393,
12,
1475,
547,
6173,
199,
504,
1134,
30784,
14,
1419,
492,
1804,
51,
14553,
199,
199,
646,
3598,
199,
504,
1134,
28299,
14,
73,
1085,
78,
492,
485,
199,
199,
533,
481,
1081,
63,
48,
87,
4845,
1451,
8,
1563,
1451,
304,
272,
408,
1804,
18938,
3918,
909,
370,
10266,
2556,
3595,
19206,
3185,
14,
408,
272,
4829,
23611,
275,
3523,
1451,
14,
10649,
23611,
272,
4829,
21368,
275,
3523,
1451,
14,
10649,
21368,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
3523,
1451,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
354,
275,
2074,
14,
362,
480,
354,
401,
6899,
267,
291,
14,
827,
552,
275,
2074,
14,
362,
480,
827,
552,
401,
1695,
9,
267,
291,
14,
827,
9161,
275,
2074,
14,
362,
480,
827,
9161,
401,
5238,
9,
267,
291,
14,
4768,
275,
2074,
14,
362,
480,
4768,
401,
715,
9,
267,
291,
14,
6627,
745,
275,
2074,
14,
362,
480,
6627,
745,
401,
756,
9,
267,
291,
14,
1667,
745,
275,
2074,
14,
362,
480,
1667,
745,
401,
715,
9,
339,
347,
636,
4077,
721,
277,
12,
612,
304,
267,
340,
440,
612,
26,
288,
372,
756,
398,
372,
291,
14,
354,
508,
612,
14,
354,
339,
347,
636,
685,
721,
277,
12,
612,
304,
267,
372,
440,
291,
508,
612,
339,
347,
636,
495,
721,
277,
304,
267,
9151,
275,
3523,
1451,
855,
495,
721,
277,
9,
398,
340,
291,
14,
354,
1137,
10812,
288,
9151,
847,
298,
8796,
3185,
2,
288,
9151,
847,
291,
423,
362,
6213,
2822,
2848,
342,
435,
1867,
78,
2,
398,
372,
9151,
339,
347,
485,
362,
6213,
2822,
2848,
8,
277,
304,
267,
9151,
275,
3087,
398,
9151,
847,
298,
450,
83,
2,
450,
291,
14,
354,
267,
9151,
847,
298,
1553,
827,
552,
2458,
68,
2,
450,
291,
14,
827,
552,
267,
9151,
847,
298,
1553,
827,
9161,
2458,
68,
2,
450,
291,
14,
827,
9161,
398,
340,
291,
14,
4768,
26,
288,
9151,
847,
298,
1553,
4768,
2,
267,
587,
26,
288,
9151,
847,
298,
1553,
1397,
4768,
2,
267,
340,
291,
14,
6627,
745,
26,
288,
9151,
847,
298,
1553,
6627,
745,
2,
267,
587,
26,
288,
9151,
847,
298,
1553,
889,
6627,
2,
267,
340,
291,
14,
1667,
745,
26,
288,
9151,
847,
298,
1553,
1667,
745,
2,
267,
587,
26,
288,
9151,
847,
298,
1553,
889,
808,
369,
2,
398,
372,
9151,
199,
199,
533,
481,
1081,
63,
48,
87,
4845,
8,
43,
18938,
3110,
304,
272,
408,
1804,
18938,
1414,
18234,
2505,
4592,
14,
408,
272,
4829,
23611,
275,
1804,
18938,
3110,
14,
10649,
23611,
272,
4829,
21368,
275,
1804,
18938,
3110,
14,
10649,
21368,
339,
347,
636,
826,
721,
277,
12,
2218,
14354,
29,
16,
12,
627,
589,
12,
1011,
958,
304,
267,
1804,
18938,
3110,
855,
826,
721,
277,
12,
2218,
14354,
12,
627,
589,
12,
1011,
958,
9,
267,
291,
14,
411,
275,
291,
423,
362,
2842,
342,
398,
291,
14,
3185,
1296,
275,
2074,
14,
362,
480,
3185,
1296,
401,
3073,
339,
347,
636,
495,
721,
277,
304,
267,
9151,
275,
3087,
267,
367,
4592,
315,
291,
14,
3185,
1296,
26,
288,
9151,
847,
4592,
855,
495,
4533,
398,
372,
9151,
339,
347,
485,
362,
2842,
8,
277,
304,
267,
1687,
275,
1804,
51,
14553,
342,
267,
1687,
14,
525,
63,
1422,
6739,
827,
552,
401,
730,
628,
442,
531,
267,
1687,
14,
525,
63,
1422,
6739,
827,
9161,
401,
730,
628,
442,
531,
267,
1687,
14,
525,
63,
1422,
6739,
4768,
401,
1595,
628,
1617,
63,
2052,
531,
267,
1687,
14,
525,
63,
1422,
6739,
1397,
4768,
401,
2053,
628,
4768,
401,
1595,
628,
1617,
63,
3910,
531,
267,
1687,
14,
525,
63,
1422,
6739,
6627,
745,
401,
1595,
628,
1617,
63,
2052,
531,
267,
1687,
14,
525,
63,
1422,
6739,
889,
6627,
401,
2053,
628,
6627,
745,
401,
1595,
628,
1617,
63,
3910,
531,
267,
1687,
14,
525,
63,
1422,
6739,
1667,
745,
401,
1595,
628,
1617,
63,
2052,
531,
267,
1687,
14,
525,
63,
1422,
6739,
889,
808,
369,
401,
2053,
628,
1667,
745,
401,
1595,
628,
1617,
63,
3910,
531,
267,
372,
1687,
339,
347,
2198,
8,
277,
12,
1249,
304,
267,
334,
3291,
12,
2402,
9,
275,
291,
14,
411,
14,
1122,
63,
589,
8,
589,
29,
589,
12,
5874,
29,
277,
14,
3469,
9,
267,
340,
822,
8,
2911,
9,
1137,
413,
26,
288,
746,
1804,
18938,
3393,
8,
908,
547,
6173,
8,
277,
14,
3469,
12,
1499,
9384,
3185,
536,
1415,
367,
450,
83,
531,
450,
298,
8796,
3185,
2237,
398,
6454,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
udapi/udapi-python | udapi/block/ud/complywithtext.py | 1 | 11648 | r"""Block ComplyWithText for adapting the nodes to comply with the text.
Implementation design details:
Usually, most of the inconsistencies between tree tokens and the raw text are simple to solve.
However, there may be also rare cases when it is not clear how to align the tokens
(nodes in the tree) with the raw text (stored in ``root.text``).
This block tries to solve the general case using several heuristics.
It starts with running a LCS-like algorithm (LCS = longest common subsequence)
``difflib.SequenceMatcher`` on the raw text and concatenation of tokens' forms,
i.e. on sequences of characters (as opposed to running LCS on sequences of tokens).
To prevent mis-alignment problems, we keep the spaces present in the raw text
and we insert spaces into the concatenated forms (``tree_chars``) according to ``SpaceAfter=No``.
An example of a mis-alignment problem:
text "énfase na necesidade" with 4 nodes "énfase en a necesidade"
should be solved by adding multiword token "na" over the nodes "en" and "a".
However, running LCS (or difflib) over the character sequences
"énfaseenanecesidade"
"énfasenanecesidade"
may result in énfase -> énfas.
Author: Martin Popel
"""
import difflib
import logging
import re
from udapi.core.block import Block
from udapi.core.mwt import MWT
class ComplyWithText(Block):
"""Adapt the nodes to comply with the text."""
def __init__(self, fix_text=True, prefer_mwt=True, allow_goeswith=True, max_mwt_length=4,
**kwargs):
"""Args:
fix_text: After all heuristics are applied, the token forms may still not match the text.
Should we edit the text to match the token forms (as a last resort)? Default=True.
prefer_mwt - What to do if multiple subsequent nodes correspond to a text written
without spaces and non-word characters (punctuation)?
E.g. if "3pm doesn't" is annotated with four nodes "3 pm does n't".
We can use either SpaceAfter=No, or create a multi-word token (MWT).
Note that if there is space or punctuation, SpaceAfter=No will be used always
(e.g. "3 p.m." annotated with three nodes "3 p. m.").
If the character sequence does not match exactly, MWT will be used always
(e.g. "3pm doesn't" annotated with four nodes "3 p.m. does not").
Thus this parameter influences only the "unclear" cases.
Default=True (i.e. prefer multi-word tokens over SpaceAfter=No).
allow_goeswith - If a node corresponds to multiple space-separated strings in text,
which are not allowed as tokens with space, we can either leave this diff
unresolved or create new nodes and join them with the `goeswith` deprel.
Default=True (i.e. add the goeswith nodes if applicable).
max_mwt_length - Maximum length of newly created multi-word tokens (in syntactic words).
Default=4.
"""
super().__init__(**kwargs)
self.fix_text = fix_text
self.prefer_mwt = prefer_mwt
self.allow_goeswith = allow_goeswith
self.max_mwt_length = max_mwt_length
@staticmethod
def allow_space(form):
"""Is space allowed within this token form?"""
return re.fullmatch('[0-9 ]+([,.][0-9]+)?', form)
@staticmethod
def store_orig_form(node, new_form):
"""Store the original form of this node into MISC, unless the change is common&expected."""
_ = new_form
if node.form not in ("''", "``"):
node.misc['OrigForm'] = node.form
def process_tree(self, root):
text = root.text
if text is None:
raise ValueError('Tree %s has no text, cannot use ud.ComplyWithText' % root)
# Normalize the stored text (double space -> single space)
# and skip sentences which are already ok.
text = ' '.join(text.split())
if text == root.compute_text():
return
tree_chars, char_nodes = _nodes_to_chars(root.token_descendants)
# Align. difflib may not give LCS, but usually it is good enough.
matcher = difflib.SequenceMatcher(None, tree_chars, text, autojunk=False)
diffs = list(matcher.get_opcodes())
_log_diffs(diffs, tree_chars, text, 'matcher')
diffs = self.unspace_diffs(diffs, tree_chars, text)
_log_diffs(diffs, tree_chars, text, 'unspace')
diffs = self.merge_diffs(diffs, char_nodes)
_log_diffs(diffs, tree_chars, text, 'merge')
# Solve diffs.
self.solve_diffs(diffs, tree_chars, char_nodes, text)
# Fill SpaceAfter=No.
tmp_text = text
for node in root.token_descendants:
if tmp_text.startswith(node.form):
tmp_text = tmp_text[len(node.form):]
if not tmp_text or tmp_text[0].isspace():
del node.misc['SpaceAfter']
tmp_text = tmp_text.lstrip()
else:
node.misc['SpaceAfter'] = 'No'
else:
logging.warning('Node %s does not match text "%s"', node, tmp_text[:20])
return
# Edit root.text if needed.
if self.fix_text:
computed_text = root.compute_text()
if text != computed_text:
root.add_comment('ToDoOrigText = ' + root.text)
root.text = computed_text
def unspace_diffs(self, orig_diffs, tree_chars, text):
diffs = []
for diff in orig_diffs:
edit, tree_lo, tree_hi, text_lo, text_hi = diff
if edit != 'insert':
if tree_chars[tree_lo] == ' ':
tree_lo += 1
if tree_chars[tree_hi - 1] == ' ':
tree_hi -= 1
old = tree_chars[tree_lo:tree_hi]
new = text[text_lo:text_hi]
if old == '' and new == '':
continue
elif old == new:
edit = 'equal'
elif old == '':
edit = 'insert'
diffs.append((edit, tree_lo, tree_hi, text_lo, text_hi))
return diffs
def merge_diffs(self, orig_diffs, char_nodes):
"""Make sure each diff starts on original token boundary.
If not, merge the diff with the previous diff.
E.g. (equal, "5", "5"), (replace, "-6", "–7")
is changed into (replace, "5-6", "5–7")
"""
diffs = []
for diff in orig_diffs:
edit, tree_lo, tree_hi, text_lo, text_hi = diff
if edit != 'insert' and char_nodes[tree_lo] is not None:
diffs.append(diff)
elif edit == 'equal':
while tree_lo < tree_hi and char_nodes[tree_lo] is None:
tree_lo += 1
text_lo += 1
diffs[-1] = ('replace', diffs[-1][1], tree_lo, diffs[-1][3], text_lo)
if tree_lo < tree_hi:
diffs.append(('equal', tree_lo, tree_hi, text_lo, text_hi))
else:
if not diffs:
diffs = [diff]
elif diffs[-1][0] != 'equal':
diffs[-1] = ('replace', diffs[-1][1], tree_hi, diffs[-1][3], text_hi)
else:
p_tree_hi = diffs[-1][2] - 1
p_text_hi = diffs[-1][4] - 1
while char_nodes[p_tree_hi] is None:
p_tree_hi -= 1
p_text_hi -= 1
assert p_tree_hi >= diffs[-1][1]
assert p_text_hi >= diffs[-1][3]
diffs[-1] = ('equal', diffs[-1][1], p_tree_hi, diffs[-1][3], p_text_hi)
diffs.append(('replace', p_tree_hi, tree_hi, p_text_hi, text_hi))
return diffs
def solve_diffs(self, diffs, tree_chars, char_nodes, text):
for diff in diffs:
edit, tree_lo, tree_hi, text_lo, text_hi = diff
# Focus only on edits of type 'replace', log insertions and deletions as failures.
if edit == 'equal':
continue
if edit in ('insert', 'delete'):
logging.warning('Unable to solve token-vs-text mismatch\n%s',
_diff2str(diff, tree_chars, text))
continue
# Revert the splittng and solve the diff.
nodes = [n for n in char_nodes[tree_lo:tree_hi] if n is not None]
form = text[text_lo:text_hi]
self.solve_diff(nodes, form.strip())
def solve_diff(self, nodes, form):
"""Fix a given (minimal) tokens-vs-text inconsistency."""
nodes_str = ' '.join([n.form for n in nodes]) # just for debugging
node = nodes[0]
# First, solve the cases when the text contains a space.
if ' ' in form:
if len(nodes) == 1 and node.form == form.replace(' ', ''):
if self.allow_space(form):
self.store_orig_form(node, form)
node.form = form
elif self.allow_goeswith:
forms = form.split()
node.form = forms[0]
for split_form in reversed(forms[1:]):
new = node.create_child(form=split_form, deprel='goeswith', upos=node.upos)
new.shift_after_node(node)
else:
logging.warning('Unable to solve 1:m diff:\n%s -> %s', nodes_str, form)
else:
logging.warning('Unable to solve n:m diff:\n%s -> %s', nodes_str, form)
# Second, solve the cases when multiple nodes match one form (without any spaces).
elif len(nodes) > 1:
# If the match is exact, we can choose between MWT ans SpaceAfter solutions.
if not self.prefer_mwt and ''.join([n.form for n in nodes]) == form:
pass # SpaceAfter=No will be added later on.
# If one of the nodes is already a MWT, we cannot have nested MWTs.
# TODO: enlarge the MWT instead of failing.
elif any(isinstance(n, MWT) for n in nodes):
logging.warning('Unable to solve partial-MWT diff:\n%s -> %s', nodes_str, form)
# MWT with too many words are suspicious.
elif len(nodes) > self.max_mwt_length:
logging.warning('Not creating too long (%d>%d) MWT:\n%s -> %s',
len(nodes), self.max_mwt_length, nodes_str, form)
# Otherwise, create a new MWT.
else:
node.root.create_multiword_token(nodes, form)
# Third, solve the 1-1 cases.
else:
self.store_orig_form(node, form)
node.form = form
def _nodes_to_chars(nodes):
chars, char_nodes = [], []
for node in nodes:
form = node.form
if node.misc['SpaceAfter'] != 'No' and node != nodes[-1]:
form += ' '
chars.extend(form)
char_nodes.append(node)
char_nodes.extend([None] * (len(form) - 1))
return ''.join(chars), char_nodes
def _log_diffs(diffs, tree_chars, text, msg):
if logging.getLogger().isEnabledFor(logging.DEBUG):
logging.warning('=== After %s:', msg)
for diff in diffs:
logging.warning(_diff2str(diff, tree_chars, text))
def _diff2str(diff, tree, text):
old = '|' + ''.join(tree[diff[1]:diff[2]]) + '|'
new = '|' + ''.join(text[diff[3]:diff[4]]) + '|'
if diff[0] == 'equal':
return '{:7} {!s:>50}'.format(diff[0], old)
return '{:7} {!s:>50} --> {!s}'.format(diff[0], old, new)
| gpl-3.0 | [
82,
624,
3142,
3599,
590,
3007,
1872,
367,
1503,
439,
1337,
314,
3380,
370,
1013,
590,
543,
314,
1318,
14,
199,
199,
7921,
12899,
2436,
26,
199,
23642,
3163,
12,
4750,
402,
314,
315,
388,
2316,
724,
2578,
3382,
3123,
4645,
436,
314,
3066,
1318,
787,
3486,
370,
14241,
14,
199,
18335,
5907,
12,
2337,
1443,
506,
2597,
24063,
5560,
1380,
652,
365,
440,
5436,
4212,
370,
6998,
314,
4645,
199,
8,
2415,
315,
314,
3123,
9,
543,
314,
3066,
1318,
334,
16431,
315,
1124,
1231,
14,
505,
20008,
199,
2765,
1853,
11275,
370,
14241,
314,
8605,
1930,
1808,
9978,
946,
300,
631,
2932,
14,
199,
199,
7940,
9174,
543,
3879,
282,
491,
3298,
13,
2930,
5563,
334,
44,
3298,
275,
21303,
2863,
1007,
4041,
9,
199,
1040,
3028,
773,
14,
5826,
16073,
1040,
641,
314,
3066,
1318,
436,
28207,
402,
4645,
7,
4513,
12,
199,
73,
14,
69,
14,
641,
8013,
402,
4110,
334,
305,
25068,
370,
3879,
491,
3298,
641,
8013,
402,
4645,
680,
199,
199,
1378,
7981,
3201,
13,
13699,
8826,
12,
781,
4215,
314,
7883,
3451,
315,
314,
3066,
1318,
199,
460,
781,
5518,
7883,
1901,
314,
26271,
4513,
15693,
2350,
63,
6574,
16580,
7182,
370,
1124,
7643,
10881,
29,
1944,
4345,
199,
2493,
2893,
402,
282,
3201,
13,
13699,
5160,
26,
199,
505,
298,
5741,
9914,
482,
11802,
1279,
301,
338,
983,
271,
2,
543,
841,
3380,
298,
5741,
9914,
482,
655,
282,
1279,
301,
338,
983,
271,
2,
199,
5626,
506,
308,
7064,
701,
7791,
3510,
1027,
1526,
298,
3540,
2,
1806,
314,
3380,
298,
287,
2,
436,
298,
65,
1674,
199,
18335,
5907,
12,
3879,
491,
3298,
334,
269,
27070,
9,
1806,
314,
4528,
8013,
199,
2,
5741,
9914,
482,
287,
5865,
301,
338,
983,
271,
2,
199,
2,
5741,
9914,
482,
4304,
69,
301,
338,
983,
271,
2,
199,
7551,
754,
315,
26785,
9914,
482,
1035,
26785,
9914,
305,
14,
199,
199,
5949,
26,
603,
26788,
4376,
28478,
199,
624,
199,
646,
27070,
199,
646,
2050,
199,
646,
295,
199,
199,
504,
26759,
1246,
14,
1018,
14,
1457,
492,
8651,
199,
504,
26759,
1246,
14,
1018,
14,
77,
9115,
492,
603,
21283,
421,
199,
533,
3599,
590,
3007,
1872,
8,
3142,
304,
272,
408,
2767,
6182,
314,
3380,
370,
1013,
590,
543,
314,
1318,
1041,
339,
347,
636,
826,
721,
277,
12,
5325,
63,
505,
29,
549,
12,
16602,
63,
77,
9115,
29,
549,
12,
2040,
63,
1939,
397,
1045,
29,
549,
12,
1390,
63,
77,
9115,
63,
1267,
29,
20,
12,
326,
1011,
958,
304,
267,
408,
6213,
26,
267,
5325,
63,
505,
26,
12836,
1006,
946,
300,
631,
2932,
787,
6781,
12,
314,
1526,
4513,
1443,
5139,
440,
1336,
314,
1318,
14,
288,
7719,
781,
5283,
314,
1318,
370,
1336,
314,
1526,
4513,
334,
305,
282,
2061,
522,
361,
5547,
3758,
29,
549,
14,
267,
16602,
63,
77,
9115,
446,
14791,
370,
886,
340,
3663,
13372,
3380,
17118,
370,
282,
1318,
5313,
288,
1928,
7883,
436,
2222,
13,
1027,
4110,
334,
25181,
5547,
288,
662,
14,
71,
14,
340,
298,
19,
7073,
3181,
1133,
2,
365,
27526,
543,
11648,
3380,
298,
19,
14207,
1630,
302,
1133,
1674,
288,
2136,
883,
675,
1902,
19326,
10881,
29,
1944,
12,
503,
1218,
282,
3510,
13,
1027,
1526,
334,
45,
21283,
680,
288,
3390,
626,
340,
2337,
365,
4601,
503,
22929,
12,
19326,
10881,
29,
1944,
911,
506,
1202,
3544,
288,
334,
69,
14,
71,
14,
298,
19,
299,
14,
77,
2122,
27526,
543,
7795,
3380,
298,
19,
299,
14,
333,
2685,
14,
288,
982,
314,
4528,
3414,
1630,
440,
1336,
8840,
12,
603,
21283,
911,
506,
1202,
3544,
288,
334,
69,
14,
71,
14,
298,
19,
7073,
3181,
1133,
2,
27526,
543,
11648,
3380,
298,
19,
299,
14,
77,
14,
1630,
440,
3471,
288,
20227,
642,
2725,
315,
17761,
25231,
1454,
314,
298,
1097,
4025,
2,
5560,
14,
288,
3758,
29,
549,
334,
73,
14,
69,
14,
16602,
3510,
13,
1027,
4645,
1806,
19326,
10881,
29,
1944,
680,
267,
2040,
63,
1939,
397,
1045,
446,
982,
282,
1031,
13718,
370,
3663,
4601,
13,
12794,
3326,
315,
1318,
12,
288,
1314,
787,
440,
4370,
465,
4645,
543,
4601,
12,
781,
883,
1902,
10137,
642,
3915,
288,
625,
13697,
503,
1218,
892,
3380,
436,
4263,
3062,
543,
314,
658,
1939,
397,
1045,
64,
477,
30788,
14,
288,
3758,
29,
549,
334,
73,
14,
69,
14,
1050,
314,
13538,
1045,
3380,
340,
3964,
680,
267,
1390,
63,
77,
9115,
63,
1267,
446,
14212,
2582,
402,
13903,
2737,
3510,
13,
1027,
4645,
334,
262,
1847,
343,
27296,
5932,
680,
288,
3758,
29,
20,
14,
267,
408,
267,
1613,
11027,
826,
14155,
958,
9,
267,
291,
14,
970,
63,
505,
275,
5325,
63,
505,
267,
291,
14,
24283,
63,
77,
9115,
275,
16602,
63,
77,
9115,
267,
291,
14,
3306,
63,
1939,
397,
1045,
275,
2040,
63,
1939,
397,
1045,
267,
291,
14,
988,
63,
77,
9115,
63,
1267,
275,
1390,
63,
77,
9115,
63,
1267,
339,
768,
4639,
272,
347,
2040,
63,
2638,
8,
964,
304,
267,
408,
1831,
4601,
4370,
4453,
642,
1526,
1824,
30196,
267,
372,
295,
14,
2861,
1431,
11894,
16,
13,
25,
1622,
11,
779,
18485,
1527,
16,
13,
25,
23763,
297,
1824,
9,
339,
768,
4639,
272,
347,
3877,
63,
2981,
63,
964,
8,
932,
12,
892,
63,
964,
304,
267,
408,
5502,
314,
3379,
1824,
402,
642,
1031,
1901,
603,
25806,
12,
7444,
314,
1570,
365,
2863,
6,
2062,
1041,
267,
485,
275,
892,
63,
964,
267,
340,
1031,
14,
964,
440,
315,
1689,
891,
401,
298,
1040,
2349,
288,
1031,
14,
9923,
459,
29698,
2821,
418,
275,
1031,
14,
964,
339,
347,
2112,
63,
2350,
8,
277,
12,
1738,
304,
267,
1318,
275,
1738,
14,
505,
267,
340,
1318,
365,
488,
26,
288,
746,
1722,
360,
3987,
450,
83,
965,
949,
1318,
12,
3913,
675,
26759,
14,
2404,
590,
3007,
1872,
7,
450,
1738,
9,
398,
327,
21017,
314,
5489,
1318,
334,
3157,
4601,
1035,
2849,
4601,
9,
267,
327,
436,
3372,
24256,
1314,
787,
2575,
4112,
14,
267,
1318,
275,
283,
1987,
904,
8,
505,
14,
1294,
1012,
267,
340,
1318,
508,
1738
] | [
624,
3142,
3599,
590,
3007,
1872,
367,
1503,
439,
1337,
314,
3380,
370,
1013,
590,
543,
314,
1318,
14,
199,
199,
7921,
12899,
2436,
26,
199,
23642,
3163,
12,
4750,
402,
314,
315,
388,
2316,
724,
2578,
3382,
3123,
4645,
436,
314,
3066,
1318,
787,
3486,
370,
14241,
14,
199,
18335,
5907,
12,
2337,
1443,
506,
2597,
24063,
5560,
1380,
652,
365,
440,
5436,
4212,
370,
6998,
314,
4645,
199,
8,
2415,
315,
314,
3123,
9,
543,
314,
3066,
1318,
334,
16431,
315,
1124,
1231,
14,
505,
20008,
199,
2765,
1853,
11275,
370,
14241,
314,
8605,
1930,
1808,
9978,
946,
300,
631,
2932,
14,
199,
199,
7940,
9174,
543,
3879,
282,
491,
3298,
13,
2930,
5563,
334,
44,
3298,
275,
21303,
2863,
1007,
4041,
9,
199,
1040,
3028,
773,
14,
5826,
16073,
1040,
641,
314,
3066,
1318,
436,
28207,
402,
4645,
7,
4513,
12,
199,
73,
14,
69,
14,
641,
8013,
402,
4110,
334,
305,
25068,
370,
3879,
491,
3298,
641,
8013,
402,
4645,
680,
199,
199,
1378,
7981,
3201,
13,
13699,
8826,
12,
781,
4215,
314,
7883,
3451,
315,
314,
3066,
1318,
199,
460,
781,
5518,
7883,
1901,
314,
26271,
4513,
15693,
2350,
63,
6574,
16580,
7182,
370,
1124,
7643,
10881,
29,
1944,
4345,
199,
2493,
2893,
402,
282,
3201,
13,
13699,
5160,
26,
199,
505,
298,
5741,
9914,
482,
11802,
1279,
301,
338,
983,
271,
2,
543,
841,
3380,
298,
5741,
9914,
482,
655,
282,
1279,
301,
338,
983,
271,
2,
199,
5626,
506,
308,
7064,
701,
7791,
3510,
1027,
1526,
298,
3540,
2,
1806,
314,
3380,
298,
287,
2,
436,
298,
65,
1674,
199,
18335,
5907,
12,
3879,
491,
3298,
334,
269,
27070,
9,
1806,
314,
4528,
8013,
199,
2,
5741,
9914,
482,
287,
5865,
301,
338,
983,
271,
2,
199,
2,
5741,
9914,
482,
4304,
69,
301,
338,
983,
271,
2,
199,
7551,
754,
315,
26785,
9914,
482,
1035,
26785,
9914,
305,
14,
199,
199,
5949,
26,
603,
26788,
4376,
28478,
199,
624,
199,
646,
27070,
199,
646,
2050,
199,
646,
295,
199,
199,
504,
26759,
1246,
14,
1018,
14,
1457,
492,
8651,
199,
504,
26759,
1246,
14,
1018,
14,
77,
9115,
492,
603,
21283,
421,
199,
533,
3599,
590,
3007,
1872,
8,
3142,
304,
272,
408,
2767,
6182,
314,
3380,
370,
1013,
590,
543,
314,
1318,
1041,
339,
347,
636,
826,
721,
277,
12,
5325,
63,
505,
29,
549,
12,
16602,
63,
77,
9115,
29,
549,
12,
2040,
63,
1939,
397,
1045,
29,
549,
12,
1390,
63,
77,
9115,
63,
1267,
29,
20,
12,
326,
1011,
958,
304,
267,
408,
6213,
26,
267,
5325,
63,
505,
26,
12836,
1006,
946,
300,
631,
2932,
787,
6781,
12,
314,
1526,
4513,
1443,
5139,
440,
1336,
314,
1318,
14,
288,
7719,
781,
5283,
314,
1318,
370,
1336,
314,
1526,
4513,
334,
305,
282,
2061,
522,
361,
5547,
3758,
29,
549,
14,
267,
16602,
63,
77,
9115,
446,
14791,
370,
886,
340,
3663,
13372,
3380,
17118,
370,
282,
1318,
5313,
288,
1928,
7883,
436,
2222,
13,
1027,
4110,
334,
25181,
5547,
288,
662,
14,
71,
14,
340,
298,
19,
7073,
3181,
1133,
2,
365,
27526,
543,
11648,
3380,
298,
19,
14207,
1630,
302,
1133,
1674,
288,
2136,
883,
675,
1902,
19326,
10881,
29,
1944,
12,
503,
1218,
282,
3510,
13,
1027,
1526,
334,
45,
21283,
680,
288,
3390,
626,
340,
2337,
365,
4601,
503,
22929,
12,
19326,
10881,
29,
1944,
911,
506,
1202,
3544,
288,
334,
69,
14,
71,
14,
298,
19,
299,
14,
77,
2122,
27526,
543,
7795,
3380,
298,
19,
299,
14,
333,
2685,
14,
288,
982,
314,
4528,
3414,
1630,
440,
1336,
8840,
12,
603,
21283,
911,
506,
1202,
3544,
288,
334,
69,
14,
71,
14,
298,
19,
7073,
3181,
1133,
2,
27526,
543,
11648,
3380,
298,
19,
299,
14,
77,
14,
1630,
440,
3471,
288,
20227,
642,
2725,
315,
17761,
25231,
1454,
314,
298,
1097,
4025,
2,
5560,
14,
288,
3758,
29,
549,
334,
73,
14,
69,
14,
16602,
3510,
13,
1027,
4645,
1806,
19326,
10881,
29,
1944,
680,
267,
2040,
63,
1939,
397,
1045,
446,
982,
282,
1031,
13718,
370,
3663,
4601,
13,
12794,
3326,
315,
1318,
12,
288,
1314,
787,
440,
4370,
465,
4645,
543,
4601,
12,
781,
883,
1902,
10137,
642,
3915,
288,
625,
13697,
503,
1218,
892,
3380,
436,
4263,
3062,
543,
314,
658,
1939,
397,
1045,
64,
477,
30788,
14,
288,
3758,
29,
549,
334,
73,
14,
69,
14,
1050,
314,
13538,
1045,
3380,
340,
3964,
680,
267,
1390,
63,
77,
9115,
63,
1267,
446,
14212,
2582,
402,
13903,
2737,
3510,
13,
1027,
4645,
334,
262,
1847,
343,
27296,
5932,
680,
288,
3758,
29,
20,
14,
267,
408,
267,
1613,
11027,
826,
14155,
958,
9,
267,
291,
14,
970,
63,
505,
275,
5325,
63,
505,
267,
291,
14,
24283,
63,
77,
9115,
275,
16602,
63,
77,
9115,
267,
291,
14,
3306,
63,
1939,
397,
1045,
275,
2040,
63,
1939,
397,
1045,
267,
291,
14,
988,
63,
77,
9115,
63,
1267,
275,
1390,
63,
77,
9115,
63,
1267,
339,
768,
4639,
272,
347,
2040,
63,
2638,
8,
964,
304,
267,
408,
1831,
4601,
4370,
4453,
642,
1526,
1824,
30196,
267,
372,
295,
14,
2861,
1431,
11894,
16,
13,
25,
1622,
11,
779,
18485,
1527,
16,
13,
25,
23763,
297,
1824,
9,
339,
768,
4639,
272,
347,
3877,
63,
2981,
63,
964,
8,
932,
12,
892,
63,
964,
304,
267,
408,
5502,
314,
3379,
1824,
402,
642,
1031,
1901,
603,
25806,
12,
7444,
314,
1570,
365,
2863,
6,
2062,
1041,
267,
485,
275,
892,
63,
964,
267,
340,
1031,
14,
964,
440,
315,
1689,
891,
401,
298,
1040,
2349,
288,
1031,
14,
9923,
459,
29698,
2821,
418,
275,
1031,
14,
964,
339,
347,
2112,
63,
2350,
8,
277,
12,
1738,
304,
267,
1318,
275,
1738,
14,
505,
267,
340,
1318,
365,
488,
26,
288,
746,
1722,
360,
3987,
450,
83,
965,
949,
1318,
12,
3913,
675,
26759,
14,
2404,
590,
3007,
1872,
7,
450,
1738,
9,
398,
327,
21017,
314,
5489,
1318,
334,
3157,
4601,
1035,
2849,
4601,
9,
267,
327,
436,
3372,
24256,
1314,
787,
2575,
4112,
14,
267,
1318,
275,
283,
1987,
904,
8,
505,
14,
1294,
1012,
267,
340,
1318,
508,
1738,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tragiclifestories/django | django/contrib/admin/templatetags/admin_modify.py | 342 | 2505 | from django import template
register = template.Library()
@register.inclusion_tag('admin/prepopulated_fields_js.html', takes_context=True)
def prepopulated_fields_js(context):
"""
Creates a list of prepopulated_fields that should render Javascript for
the prepopulated fields for both the admin form and inlines.
"""
prepopulated_fields = []
if 'adminform' in context:
prepopulated_fields.extend(context['adminform'].prepopulated_fields)
if 'inline_admin_formsets' in context:
for inline_admin_formset in context['inline_admin_formsets']:
for inline_admin_form in inline_admin_formset:
if inline_admin_form.original is None:
prepopulated_fields.extend(inline_admin_form.prepopulated_fields)
context.update({'prepopulated_fields': prepopulated_fields})
return context
@register.inclusion_tag('admin/submit_line.html', takes_context=True)
def submit_row(context):
"""
Displays the row of buttons for delete and save.
"""
opts = context['opts']
change = context['change']
is_popup = context['is_popup']
save_as = context['save_as']
show_save = context.get('show_save', True)
show_save_and_continue = context.get('show_save_and_continue', True)
ctx = {
'opts': opts,
'show_delete_link': (
not is_popup and context['has_delete_permission'] and
change and context.get('show_delete', True)
),
'show_save_as_new': not is_popup and change and save_as,
'show_save_and_add_another': (
context['has_add_permission'] and not is_popup and
(not save_as or context['add'])
),
'show_save_and_continue': not is_popup and context['has_change_permission'] and show_save_and_continue,
'is_popup': is_popup,
'show_save': show_save,
'preserved_filters': context.get('preserved_filters'),
}
if context.get('original') is not None:
ctx['original'] = context['original']
return ctx
@register.filter
def cell_count(inline_admin_form):
"""Returns the number of cells used in a tabular inline"""
count = 1 # Hidden cell with hidden 'id' field
for fieldset in inline_admin_form:
# Loop through all the fields (one per cell)
for line in fieldset:
for field in line:
count += 1
if inline_admin_form.formset.can_delete:
# Delete checkbox
count += 1
return count
| bsd-3-clause | [
504,
1639,
492,
1978,
199,
199,
2683,
275,
1978,
14,
7424,
342,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
2113,
15,
657,
21440,
63,
955,
63,
3596,
14,
1360,
297,
6181,
63,
1100,
29,
549,
9,
199,
318,
876,
21440,
63,
955,
63,
3596,
8,
1100,
304,
272,
408,
272,
10560,
282,
769,
402,
876,
21440,
63,
955,
626,
1077,
3795,
31861,
367,
272,
314,
876,
21440,
1504,
367,
3865,
314,
4628,
1824,
436,
29177,
14,
272,
408,
272,
876,
21440,
63,
955,
275,
942,
272,
340,
283,
2113,
964,
7,
315,
1067,
26,
267,
876,
21440,
63,
955,
14,
2880,
8,
1100,
459,
2113,
964,
2278,
657,
21440,
63,
955,
9,
272,
340,
283,
6460,
63,
2113,
63,
31033,
7,
315,
1067,
26,
267,
367,
8308,
63,
2113,
63,
10724,
315,
1067,
459,
6460,
63,
2113,
63,
31033,
2565,
288,
367,
8308,
63,
2113,
63,
964,
315,
8308,
63,
2113,
63,
10724,
26,
355,
340,
8308,
63,
2113,
63,
964,
14,
5043,
365,
488,
26,
490,
876,
21440,
63,
955,
14,
2880,
8,
6460,
63,
2113,
63,
964,
14,
657,
21440,
63,
955,
9,
272,
1067,
14,
873,
3252,
657,
21440,
63,
955,
356,
876,
21440,
63,
955,
1552,
272,
372,
1067,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
2113,
15,
7275,
63,
604,
14,
1360,
297,
6181,
63,
1100,
29,
549,
9,
199,
318,
11482,
63,
1143,
8,
1100,
304,
272,
408,
272,
28750,
314,
1962,
402,
15766,
367,
3145,
436,
3354,
14,
272,
408,
272,
3999,
275,
1067,
459,
3291,
418,
272,
1570,
275,
1067,
459,
1461,
418,
272,
365,
63,
16020,
275,
1067,
459,
374,
63,
16020,
418,
272,
3354,
63,
305,
275,
1067,
459,
2117,
63,
305,
418,
272,
2498,
63,
2117,
275,
1067,
14,
362,
360,
2384,
63,
2117,
297,
715,
9,
272,
2498,
63,
2117,
63,
460,
63,
6958,
275,
1067,
14,
362,
360,
2384,
63,
2117,
63,
460,
63,
6958,
297,
715,
9,
272,
4027,
275,
469,
267,
283,
3291,
356,
3999,
12,
267,
283,
2384,
63,
1807,
63,
1073,
356,
334,
288,
440,
365,
63,
16020,
436,
1067,
459,
1989,
63,
1807,
63,
5693,
418,
436,
288,
1570,
436,
1067,
14,
362,
360,
2384,
63,
1807,
297,
715,
9,
267,
2318,
267,
283,
2384,
63,
2117,
63,
305,
63,
1222,
356,
440,
365,
63,
16020,
436,
1570,
436,
3354,
63,
305,
12,
267,
283,
2384,
63,
2117,
63,
460,
63,
525,
63,
13565,
356,
334,
288,
1067,
459,
1989,
63,
525,
63,
5693,
418,
436,
440,
365,
63,
16020,
436,
288,
334,
1397,
3354,
63,
305,
503,
1067,
459,
525,
1105,
267,
2318,
267,
283,
2384,
63,
2117,
63,
460,
63,
6958,
356,
440,
365,
63,
16020,
436,
1067,
459,
1989,
63,
1461,
63,
5693,
418,
436,
2498,
63,
2117,
63,
460,
63,
6958,
12,
267,
283,
374,
63,
16020,
356,
365,
63,
16020,
12,
267,
283,
2384,
63,
2117,
356,
2498,
63,
2117,
12,
267,
283,
32104,
63,
4273,
356,
1067,
14,
362,
360,
32104,
63,
4273,
659,
272,
789,
272,
340,
1067,
14,
362,
360,
5043,
358,
365,
440,
488,
26,
267,
4027,
459,
5043,
418,
275,
1067,
459,
5043,
418,
272,
372,
4027,
421,
199,
32,
2683,
14,
1541,
199,
318,
4917,
63,
835,
8,
6460,
63,
2113,
63,
964,
304,
272,
408,
3407,
314,
1329,
402,
10106,
1202,
315,
282,
5174,
2238,
8308,
624,
272,
2338,
275,
413,
221,
327,
26401,
4917,
543,
8752,
283,
344,
7,
901,
272,
367,
901,
409,
315,
8308,
63,
2113,
63,
964,
26,
267,
327,
18175,
4012,
1006,
314,
1504,
334,
368,
1126,
4917,
9,
267,
367,
1004,
315,
901,
409,
26,
288,
367,
901,
315,
1004,
26,
355,
2338,
847,
413,
272,
340,
8308,
63,
2113,
63,
964,
14,
10724,
14,
2425,
63,
1807,
26,
267,
327,
8496,
24190,
267,
2338,
847,
413,
272,
372,
2338,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
492,
1978,
199,
199,
2683,
275,
1978,
14,
7424,
342,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
2113,
15,
657,
21440,
63,
955,
63,
3596,
14,
1360,
297,
6181,
63,
1100,
29,
549,
9,
199,
318,
876,
21440,
63,
955,
63,
3596,
8,
1100,
304,
272,
408,
272,
10560,
282,
769,
402,
876,
21440,
63,
955,
626,
1077,
3795,
31861,
367,
272,
314,
876,
21440,
1504,
367,
3865,
314,
4628,
1824,
436,
29177,
14,
272,
408,
272,
876,
21440,
63,
955,
275,
942,
272,
340,
283,
2113,
964,
7,
315,
1067,
26,
267,
876,
21440,
63,
955,
14,
2880,
8,
1100,
459,
2113,
964,
2278,
657,
21440,
63,
955,
9,
272,
340,
283,
6460,
63,
2113,
63,
31033,
7,
315,
1067,
26,
267,
367,
8308,
63,
2113,
63,
10724,
315,
1067,
459,
6460,
63,
2113,
63,
31033,
2565,
288,
367,
8308,
63,
2113,
63,
964,
315,
8308,
63,
2113,
63,
10724,
26,
355,
340,
8308,
63,
2113,
63,
964,
14,
5043,
365,
488,
26,
490,
876,
21440,
63,
955,
14,
2880,
8,
6460,
63,
2113,
63,
964,
14,
657,
21440,
63,
955,
9,
272,
1067,
14,
873,
3252,
657,
21440,
63,
955,
356,
876,
21440,
63,
955,
1552,
272,
372,
1067,
421,
199,
32,
2683,
14,
24265,
63,
1450,
360,
2113,
15,
7275,
63,
604,
14,
1360,
297,
6181,
63,
1100,
29,
549,
9,
199,
318,
11482,
63,
1143,
8,
1100,
304,
272,
408,
272,
28750,
314,
1962,
402,
15766,
367,
3145,
436,
3354,
14,
272,
408,
272,
3999,
275,
1067,
459,
3291,
418,
272,
1570,
275,
1067,
459,
1461,
418,
272,
365,
63,
16020,
275,
1067,
459,
374,
63,
16020,
418,
272,
3354,
63,
305,
275,
1067,
459,
2117,
63,
305,
418,
272,
2498,
63,
2117,
275,
1067,
14,
362,
360,
2384,
63,
2117,
297,
715,
9,
272,
2498,
63,
2117,
63,
460,
63,
6958,
275,
1067,
14,
362,
360,
2384,
63,
2117,
63,
460,
63,
6958,
297,
715,
9,
272,
4027,
275,
469,
267,
283,
3291,
356,
3999,
12,
267,
283,
2384,
63,
1807,
63,
1073,
356,
334,
288,
440,
365,
63,
16020,
436,
1067,
459,
1989,
63,
1807,
63,
5693,
418,
436,
288,
1570,
436,
1067,
14,
362,
360,
2384,
63,
1807,
297,
715,
9,
267,
2318,
267,
283,
2384,
63,
2117,
63,
305,
63,
1222,
356,
440,
365,
63,
16020,
436,
1570,
436,
3354,
63,
305,
12,
267,
283,
2384,
63,
2117,
63,
460,
63,
525,
63,
13565,
356,
334,
288,
1067,
459,
1989,
63,
525,
63,
5693,
418,
436,
440,
365,
63,
16020,
436,
288,
334,
1397,
3354,
63,
305,
503,
1067,
459,
525,
1105,
267,
2318,
267,
283,
2384,
63,
2117,
63,
460,
63,
6958,
356,
440,
365,
63,
16020,
436,
1067,
459,
1989,
63,
1461,
63,
5693,
418,
436,
2498,
63,
2117,
63,
460,
63,
6958,
12,
267,
283,
374,
63,
16020,
356,
365,
63,
16020,
12,
267,
283,
2384,
63,
2117,
356,
2498,
63,
2117,
12,
267,
283,
32104,
63,
4273,
356,
1067,
14,
362,
360,
32104,
63,
4273,
659,
272,
789,
272,
340,
1067,
14,
362,
360,
5043,
358,
365,
440,
488,
26,
267,
4027,
459,
5043,
418,
275,
1067,
459,
5043,
418,
272,
372,
4027,
421,
199,
32,
2683,
14,
1541,
199,
318,
4917,
63,
835,
8,
6460,
63,
2113,
63,
964,
304,
272,
408,
3407,
314,
1329,
402,
10106,
1202,
315,
282,
5174,
2238,
8308,
624,
272,
2338,
275,
413,
221,
327,
26401,
4917,
543,
8752,
283,
344,
7,
901,
272,
367,
901,
409,
315,
8308,
63,
2113,
63,
964,
26,
267,
327,
18175,
4012,
1006,
314,
1504,
334,
368,
1126,
4917,
9,
267,
367,
1004,
315,
901,
409,
26,
288,
367,
901,
315,
1004,
26,
355,
2338,
847,
413,
272,
340,
8308,
63,
2113,
63,
964,
14,
10724,
14,
2425,
63,
1807,
26,
267,
327,
8496,
24190,
267,
2338,
847,
413,
272,
372,
2338,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
wkpark/zinnia | python/test.py | 12 | 1187 | #!/usr/bin/python
import zinnia
input = "(character (width 1000)(height 1000)(strokes ((243 273)(393 450))((700 253)(343 486)(280 716)(393 866)(710 880))))";
try:
s = zinnia.Character()
r = zinnia.Recognizer()
r.open("/usr/local/lib/zinnia/model/tomoe/handwriting-ja.model")
if (not s.parse(input)):
print s.what()
result = r.classify(s, 10)
size = result.size()
for i in range(0, (size - 1)):
print "%s\t%f" % (result.value(i), result.score(i))
s.clear();
s.set_width(300)
s.set_height(300)
s.add(0, 51, 29)
s.add(0, 117, 41)
s.add(1, 99, 65)
s.add(1, 219, 77)
s.add(2, 27, 131)
s.add(2, 261, 131)
s.add(3, 129, 17)
s.add(3, 57, 203)
s.add(4, 111, 71)
s.add(4, 219, 173)
s.add(5, 81, 161)
s.add(5, 93, 281)
s.add(6, 99, 167)
s.add(6, 207, 167)
s.add(6, 189, 245)
s.add(7, 99, 227)
s.add(7, 189, 227)
s.add(8, 111, 257)
s.add(8, 189, 245)
result = r.classify(s, 10)
size = result.size()
for i in range(0, (size - 1)):
print "%s\t%f" % (result.value(i), result.score(i))
except RuntimeError, e:
print "RuntimeError: ", e,
| bsd-3-clause | [
3381,
2647,
15,
1393,
15,
1548,
199,
199,
646,
1315,
262,
22042,
199,
199,
1210,
275,
7340,
10856,
334,
2063,
5198,
5130,
3333,
5198,
5130,
24627,
9246,
3666,
13440,
499,
2898,
5130,
15490,
841,
1400,
430,
1332,
15946,
26727,
5130,
14761,
841,
1184,
5130,
18520,
1520,
975,
5130,
15490,
10300,
22,
5130,
26072,
1695,
1257,
7845,
11436,
1362,
199,
893,
26,
272,
308,
275,
1315,
262,
22042,
14,
14852,
342,
272,
519,
275,
1315,
262,
22042,
14,
497,
6862,
1793,
342,
272,
519,
14,
1490,
4769,
2647,
15,
1832,
15,
773,
15,
90,
262,
22042,
15,
1238,
15,
475,
573,
69,
15,
6868,
14827,
13,
3387,
14,
1238,
531,
339,
340,
334,
1397,
308,
14,
1122,
8,
1210,
2298,
267,
870,
308,
14,
10058,
342,
272,
754,
275,
519,
14,
12334,
1399,
8,
83,
12,
1616,
9,
272,
1568,
275,
754,
14,
890,
342,
272,
367,
284,
315,
1425,
8,
16,
12,
334,
890,
446,
413,
2298,
267,
870,
2071,
83,
60,
84,
5,
70,
2,
450,
334,
1099,
14,
585,
8,
73,
395,
754,
14,
3397,
8,
73,
430,
339,
308,
14,
3584,
7303,
272,
308,
14,
409,
63,
2063,
8,
5863,
9,
272,
308,
14,
409,
63,
3333,
8,
5863,
9,
272,
308,
14,
525,
8,
16,
12,
8026,
12,
7349,
9,
272,
308,
14,
525,
8,
16,
12,
26189,
12,
13385,
9,
272,
308,
14,
525,
8,
17,
12,
8806,
12,
11738,
9,
272,
308,
14,
525,
8,
17,
12,
499,
1167,
12,
8375,
9,
272,
308,
14,
525,
8,
18,
12,
8087,
12,
30542,
9,
272,
308,
14,
525,
8,
18,
12,
499,
2976,
12,
30542,
9,
272,
308,
14,
525,
8,
19,
12,
25454,
12,
5557,
9,
272,
308,
14,
525,
8,
19,
12,
12699,
12,
29202,
9,
272,
308,
14,
525,
8,
20,
12,
20128,
12,
17245,
9,
272,
308,
14,
525,
8,
20,
12,
499,
1167,
12,
413,
2898,
9,
272,
308,
14,
525,
8,
21,
12,
19071,
12,
32372,
9,
272,
308,
14,
525,
8,
21,
12,
18969,
12,
499,
2835,
9,
272,
308,
14,
525,
8,
22,
12,
8806,
12,
31650,
9,
272,
308,
14,
525,
8,
22,
12,
31533,
12,
31650,
9,
272,
308,
14,
525,
8,
22,
12,
31446,
12,
32102,
9,
272,
308,
14,
525,
8,
23,
12,
8806,
12,
499,
1465,
9,
272,
308,
14,
525,
8,
23,
12,
31446,
12,
499,
1465,
9,
272,
308,
14,
525,
8,
24,
12,
20128,
12,
499,
1641,
9,
272,
308,
14,
525,
8,
24,
12,
31446,
12,
32102,
9,
272,
754,
275,
519,
14,
12334,
1399,
8,
83,
12,
1616,
9,
272,
1568,
275,
754,
14,
890,
342,
272,
367,
284,
315,
1425,
8,
16,
12,
334,
890,
446,
413,
2298,
267,
870,
2071,
83,
60,
84,
5,
70,
2,
450,
334,
1099,
14,
585,
8,
73,
395,
754,
14,
3397,
8,
73,
430,
199,
199,
2590,
6064,
12,
325,
26,
272,
870,
298,
13281,
26,
3872,
325,
12,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
2647,
15,
1393,
15,
1548,
199,
199,
646,
1315,
262,
22042,
199,
199,
1210,
275,
7340,
10856,
334,
2063,
5198,
5130,
3333,
5198,
5130,
24627,
9246,
3666,
13440,
499,
2898,
5130,
15490,
841,
1400,
430,
1332,
15946,
26727,
5130,
14761,
841,
1184,
5130,
18520,
1520,
975,
5130,
15490,
10300,
22,
5130,
26072,
1695,
1257,
7845,
11436,
1362,
199,
893,
26,
272,
308,
275,
1315,
262,
22042,
14,
14852,
342,
272,
519,
275,
1315,
262,
22042,
14,
497,
6862,
1793,
342,
272,
519,
14,
1490,
4769,
2647,
15,
1832,
15,
773,
15,
90,
262,
22042,
15,
1238,
15,
475,
573,
69,
15,
6868,
14827,
13,
3387,
14,
1238,
531,
339,
340,
334,
1397,
308,
14,
1122,
8,
1210,
2298,
267,
870,
308,
14,
10058,
342,
272,
754,
275,
519,
14,
12334,
1399,
8,
83,
12,
1616,
9,
272,
1568,
275,
754,
14,
890,
342,
272,
367,
284,
315,
1425,
8,
16,
12,
334,
890,
446,
413,
2298,
267,
870,
2071,
83,
60,
84,
5,
70,
2,
450,
334,
1099,
14,
585,
8,
73,
395,
754,
14,
3397,
8,
73,
430,
339,
308,
14,
3584,
7303,
272,
308,
14,
409,
63,
2063,
8,
5863,
9,
272,
308,
14,
409,
63,
3333,
8,
5863,
9,
272,
308,
14,
525,
8,
16,
12,
8026,
12,
7349,
9,
272,
308,
14,
525,
8,
16,
12,
26189,
12,
13385,
9,
272,
308,
14,
525,
8,
17,
12,
8806,
12,
11738,
9,
272,
308,
14,
525,
8,
17,
12,
499,
1167,
12,
8375,
9,
272,
308,
14,
525,
8,
18,
12,
8087,
12,
30542,
9,
272,
308,
14,
525,
8,
18,
12,
499,
2976,
12,
30542,
9,
272,
308,
14,
525,
8,
19,
12,
25454,
12,
5557,
9,
272,
308,
14,
525,
8,
19,
12,
12699,
12,
29202,
9,
272,
308,
14,
525,
8,
20,
12,
20128,
12,
17245,
9,
272,
308,
14,
525,
8,
20,
12,
499,
1167,
12,
413,
2898,
9,
272,
308,
14,
525,
8,
21,
12,
19071,
12,
32372,
9,
272,
308,
14,
525,
8,
21,
12,
18969,
12,
499,
2835,
9,
272,
308,
14,
525,
8,
22,
12,
8806,
12,
31650,
9,
272,
308,
14,
525,
8,
22,
12,
31533,
12,
31650,
9,
272,
308,
14,
525,
8,
22,
12,
31446,
12,
32102,
9,
272,
308,
14,
525,
8,
23,
12,
8806,
12,
499,
1465,
9,
272,
308,
14,
525,
8,
23,
12,
31446,
12,
499,
1465,
9,
272,
308,
14,
525,
8,
24,
12,
20128,
12,
499,
1641,
9,
272,
308,
14,
525,
8,
24,
12,
31446,
12,
32102,
9,
272,
754,
275,
519,
14,
12334,
1399,
8,
83,
12,
1616,
9,
272,
1568,
275,
754,
14,
890,
342,
272,
367,
284,
315,
1425,
8,
16,
12,
334,
890,
446,
413,
2298,
267,
870,
2071,
83,
60,
84,
5,
70,
2,
450,
334,
1099,
14,
585,
8,
73,
395,
754,
14,
3397,
8,
73,
430,
199,
199,
2590,
6064,
12,
325,
26,
272,
870,
298,
13281,
26,
3872,
325,
12,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
storiesofsolidarity/story-database | stories/admin.py | 1 | 1393 | from django.contrib import admin
from models import Location, Story
from people.models import Author
class LocationAdmin(admin.ModelAdmin):
list_display = ('zipcode', 'city_fmt', 'county_fmt', 'state_fmt', 'story_count')
list_filter = ('state',)
search_fields = ('zipcode', 'city', 'county')
admin.site.register(Location, LocationAdmin)
class EmployerFilter(admin.SimpleListFilter):
title = 'author employer'
parameter_name = 'employer'
def lookups(self, request, model_admin):
employer_set = set()
for a in Author.objects.all():
if a.employer:
employer_set.add(a.employer.split(' ', 1)[0])
return [(str(c), str(c)) for c in employer_set if c]
def queryset(self, request, queryset):
if self.value() or self.value() == 'None':
return queryset.filter(author__employer__startswith=self.value())
else:
return queryset
class StoryAdmin(admin.ModelAdmin):
list_display = ('excerpt', 'author_display', 'employer', 'anonymous', 'created_at')
list_filter = (EmployerFilter, 'location__state', 'truncated')
date_hierarchy = 'created_at'
readonly_fields = ('truncated',)
raw_id_fields = ('author', 'location')
search_fields = ('location__city', 'author__user__first_name', 'author__user__last_name', 'content')
admin.site.register(Story, StoryAdmin)
| agpl-3.0 | [
504,
1639,
14,
2828,
492,
4628,
199,
504,
1709,
492,
12625,
12,
1933,
1089,
199,
504,
13135,
14,
992,
492,
6529,
421,
199,
533,
12625,
4880,
8,
2113,
14,
12976,
304,
272,
769,
63,
2918,
275,
661,
3065,
600,
297,
283,
3690,
63,
5045,
297,
283,
3094,
369,
63,
5045,
297,
283,
929,
63,
5045,
297,
283,
17372,
63,
835,
358,
272,
769,
63,
1541,
275,
661,
929,
9538,
272,
2754,
63,
955,
275,
661,
3065,
600,
297,
283,
3690,
297,
283,
3094,
369,
358,
199,
199,
2113,
14,
2124,
14,
2683,
8,
6592,
12,
12625,
4880,
9,
421,
199,
533,
662,
311,
3374,
281,
4131,
8,
2113,
14,
3184,
24703,
304,
272,
2538,
275,
283,
2502,
9052,
3374,
281,
7,
272,
2725,
63,
354,
275,
283,
2109,
3374,
281,
7,
339,
347,
16807,
8,
277,
12,
1056,
12,
1402,
63,
2113,
304,
267,
9052,
3374,
281,
63,
409,
275,
663,
342,
267,
367,
282,
315,
6529,
14,
1462,
14,
452,
837,
288,
340,
282,
14,
2109,
3374,
281,
26,
355,
9052,
3374,
281,
63,
409,
14,
525,
8,
65,
14,
2109,
3374,
281,
14,
1294,
360,
1656,
413,
2788,
16,
566,
267,
372,
3842,
495,
8,
67,
395,
620,
8,
67,
430,
367,
286,
315,
9052,
3374,
281,
63,
409,
340,
286,
61,
339,
347,
7594,
8,
277,
12,
1056,
12,
7594,
304,
267,
340,
291,
14,
585,
342,
503,
291,
14,
585,
342,
508,
283,
403,
356,
288,
372,
7594,
14,
1541,
8,
2502,
363,
2109,
3374,
281,
363,
2460,
29,
277,
14,
585,
1012,
267,
587,
26,
288,
372,
7594,
421,
199,
533,
1933,
1089,
4880,
8,
2113,
14,
12976,
304,
272,
769,
63,
2918,
275,
661,
476,
2247,
541,
297,
283,
2502,
63,
2918,
297,
283,
2109,
3374,
281,
297,
283,
12628,
297,
283,
3966,
63,
292,
358,
272,
769,
63,
1541,
275,
334,
37,
311,
3374,
281,
4131,
12,
283,
1985,
363,
929,
297,
283,
19347,
358,
272,
1434,
63,
14861,
275,
283,
3966,
63,
292,
7,
272,
6863,
63,
955,
275,
661,
19347,
9538,
272,
3066,
63,
344,
63,
955,
275,
661,
2502,
297,
283,
1985,
358,
272,
2754,
63,
955,
275,
661,
1985,
363,
3690,
297,
283,
2502,
363,
751,
363,
2246,
63,
354,
297,
283,
2502,
363,
751,
363,
2019,
63,
354,
297,
283,
1317,
358,
199,
199,
2113,
14,
2124,
14,
2683,
8,
25120,
12,
1933,
1089,
4880,
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
] | [
1639,
14,
2828,
492,
4628,
199,
504,
1709,
492,
12625,
12,
1933,
1089,
199,
504,
13135,
14,
992,
492,
6529,
421,
199,
533,
12625,
4880,
8,
2113,
14,
12976,
304,
272,
769,
63,
2918,
275,
661,
3065,
600,
297,
283,
3690,
63,
5045,
297,
283,
3094,
369,
63,
5045,
297,
283,
929,
63,
5045,
297,
283,
17372,
63,
835,
358,
272,
769,
63,
1541,
275,
661,
929,
9538,
272,
2754,
63,
955,
275,
661,
3065,
600,
297,
283,
3690,
297,
283,
3094,
369,
358,
199,
199,
2113,
14,
2124,
14,
2683,
8,
6592,
12,
12625,
4880,
9,
421,
199,
533,
662,
311,
3374,
281,
4131,
8,
2113,
14,
3184,
24703,
304,
272,
2538,
275,
283,
2502,
9052,
3374,
281,
7,
272,
2725,
63,
354,
275,
283,
2109,
3374,
281,
7,
339,
347,
16807,
8,
277,
12,
1056,
12,
1402,
63,
2113,
304,
267,
9052,
3374,
281,
63,
409,
275,
663,
342,
267,
367,
282,
315,
6529,
14,
1462,
14,
452,
837,
288,
340,
282,
14,
2109,
3374,
281,
26,
355,
9052,
3374,
281,
63,
409,
14,
525,
8,
65,
14,
2109,
3374,
281,
14,
1294,
360,
1656,
413,
2788,
16,
566,
267,
372,
3842,
495,
8,
67,
395,
620,
8,
67,
430,
367,
286,
315,
9052,
3374,
281,
63,
409,
340,
286,
61,
339,
347,
7594,
8,
277,
12,
1056,
12,
7594,
304,
267,
340,
291,
14,
585,
342,
503,
291,
14,
585,
342,
508,
283,
403,
356,
288,
372,
7594,
14,
1541,
8,
2502,
363,
2109,
3374,
281,
363,
2460,
29,
277,
14,
585,
1012,
267,
587,
26,
288,
372,
7594,
421,
199,
533,
1933,
1089,
4880,
8,
2113,
14,
12976,
304,
272,
769,
63,
2918,
275,
661,
476,
2247,
541,
297,
283,
2502,
63,
2918,
297,
283,
2109,
3374,
281,
297,
283,
12628,
297,
283,
3966,
63,
292,
358,
272,
769,
63,
1541,
275,
334,
37,
311,
3374,
281,
4131,
12,
283,
1985,
363,
929,
297,
283,
19347,
358,
272,
1434,
63,
14861,
275,
283,
3966,
63,
292,
7,
272,
6863,
63,
955,
275,
661,
19347,
9538,
272,
3066,
63,
344,
63,
955,
275,
661,
2502,
297,
283,
1985,
358,
272,
2754,
63,
955,
275,
661,
1985,
363,
3690,
297,
283,
2502,
363,
751,
363,
2246,
63,
354,
297,
283,
2502,
363,
751,
363,
2019,
63,
354,
297,
283,
1317,
358,
199,
199,
2113,
14,
2124,
14,
2683,
8,
25120,
12,
1933,
1089,
4880,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Racing1/android_kernel_htc_ruby_aosp | tools/perf/scripts/python/syscall-counts.py | 944 | 1429 | # system call counts
# (c) 2010, Tom Zanussi <[email protected]>
# Licensed under the terms of the GNU GPL License version 2
#
# Displays system-wide system call totals, broken down by syscall.
# If a [comm] arg is specified, only syscalls called by [comm] are displayed.
import os
import sys
sys.path.append(os.environ['PERF_EXEC_PATH'] + \
'/scripts/python/Perf-Trace-Util/lib/Perf/Trace')
from perf_trace_context import *
from Core import *
usage = "perf trace -s syscall-counts.py [comm]\n";
for_comm = None
if len(sys.argv) > 2:
sys.exit(usage)
if len(sys.argv) > 1:
for_comm = sys.argv[1]
syscalls = autodict()
def trace_begin():
pass
def trace_end():
print_syscall_totals()
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, args):
if for_comm is not None:
if common_comm != for_comm:
return
try:
syscalls[id] += 1
except TypeError:
syscalls[id] = 1
def print_syscall_totals():
if for_comm is not None:
print "\nsyscall events for %s:\n\n" % (for_comm),
else:
print "\nsyscall events:\n\n",
print "%-40s %10s\n" % ("event", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"-----------"),
for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
reverse = True):
print "%-40d %10d\n" % (id, val),
| gpl-2.0 | [
3,
2656,
1240,
8242,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
199,
3807,
275,
298,
9452,
3307,
446,
83,
18901,
13,
6851,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1529,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
1871,
221,
3837,
275,
715,
304,
6722,
870,
18301,
2167,
68,
221,
450,
709,
68,
60,
78,
2,
450,
334,
344,
12,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
2656,
1240,
8242,
199,
3,
334,
67,
9,
7129,
12,
21644,
29385,
665,
29453,
32,
6799,
14,
957,
30,
199,
3,
3909,
1334,
314,
2895,
402,
314,
1664,
14629,
844,
1015,
499,
199,
3,
199,
3,
28750,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
18901,
14,
199,
3,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
359,
1404,
61,
787,
9080,
14,
199,
199,
646,
747,
199,
646,
984,
199,
199,
1274,
14,
515,
14,
740,
8,
736,
14,
2314,
459,
17038,
63,
10276,
63,
3243,
418,
435,
971,
199,
198,
9807,
6429,
15,
1548,
15,
12387,
13,
3921,
13,
9562,
15,
773,
15,
12387,
15,
3921,
358,
199,
199,
504,
8582,
63,
3446,
63,
1100,
492,
627,
199,
504,
11672,
492,
627,
199,
199,
3807,
275,
298,
9452,
3307,
446,
83,
18901,
13,
6851,
14,
647,
359,
1404,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
1529,
199,
199,
318,
3307,
63,
500,
837,
199,
198,
1361,
63,
19444,
63,
17552,
342,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
870,
63,
19444,
63,
17552,
837,
272,
340,
367,
63,
1404,
365,
440,
488,
26,
6722,
870,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
272,
587,
26,
6722,
870,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
339,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
272,
870,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
639,
298,
13715,
1288,
339,
367,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
1871,
221,
3837,
275,
715,
304,
6722,
870,
18301,
2167,
68,
221,
450,
709,
68,
60,
78,
2,
450,
334,
344,
12,
1139,
395,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
peppelinux/inventario_verdebinario | museo/models.py | 1 | 4183 | from django.db import models
from photologue.models import ImageModel
from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _
class Produttore(ImageModel):
id_tabella = models.AutoField(primary_key=True)
nome = models.CharField(max_length=135, blank=True)
nome_abbreviato = models.CharField(max_length=135, blank=True)
#slug = models.SlugField(unique=True, help_text=('"slug": un identificatore automatico e univoco'))
descrizione = models.TextField(max_length=1024, blank=True)
data_nascita = models.DateField(null=True, blank=True)
data_chiusura = models.DateField(null=True, blank=True)
#immagine_logo = models.ImageField(upload_to="LoghiProduttori", blank=True)
url = models.CharField(max_length=256, blank=True)
def save(self, *args, **kwargs):
if self.nome_abbreviato == None or self.nome_abbreviato.split() == []:
self.nome_abbreviato = self.nome.upper()
super(self.__class__, self).save(*args, **kwargs) # Call the "real" save() method.
class Meta:
ordering = ['nome']
db_table = 'produttore'
verbose_name_plural = "Produttore"
# def get_absolute_url(self):
# return '%s' % (self.url)
def __str__(self):
return '%s' % (self.nome_abbreviato)
class SchedaTecnica(models.Model):
id_tabella = models.AutoField(primary_key=True)
modello = models.CharField(max_length=135, blank=True)
produttore = models.ForeignKey(Produttore, null=True, blank=True, on_delete=models.SET_NULL)
paese_di_origine = models.CharField(max_length=135, blank=True)
anno = models.CharField(max_length=135, blank=True)
tastiera = models.CharField(max_length=135, blank=True)
cpu = models.CharField(max_length=135, blank=True)
velocita = models.CharField(max_length=135, blank=True)
memoria_volatile = models.CharField(max_length=135, blank=True)
memoria_di_massa = models.CharField(max_length=135, blank=True)
modalita_grafica = models.CharField(max_length=135, blank=True)
audio = models.CharField(max_length=135, blank=True)
dispositivi_media = models.CharField(max_length=135, blank=True)
alimentazione = models.CharField(max_length=135, blank=True)
prezzo = models.CharField(max_length=135, blank=True)
descrizione = models.TextField(max_length=1024, blank=True)
data_inserimento = models.DateField(null=True, blank=False, auto_now_add=True)
class Meta:
db_table = 'scheda_tecnica'
verbose_name_plural = "Scheda Tecnica"
class FotoHardwareMuseo(ImageModel):
id_tabella = models.AutoField(primary_key=True)
#immagine = models.ImageField(upload_to="FotoHardwareMuseo/%d.%m.%Y", blank=True)
etichetta_verde = models.CharField(max_length=135, blank=True)
data_inserimento = models.DateField(null=True, blank=False, auto_now_add=True)
seriale = models.CharField(max_length=384, blank=True)
didascalia = models.TextField(max_length=328, blank=True)
scheda_tecnica = models.ForeignKey(SchedaTecnica, null=True, blank=True, on_delete=models.SET_NULL)
class Meta:
db_table = 'foto_hardware_museo'
verbose_name_plural = "Foto Hardware Museo"
def __str__(self):
return '%s %s' % (self.seriale, self.scheda_tecnica)
def get_absolute_url(self):
#return '/media/foto/FotoHardwareMuseo/' + self.data_inserimento.strftime('%d.%m.%Y') + '/' + self.image.name
return '/media/%s' % self.image.name
def admin_thumbnail(self):
func = getattr(self, 'get_admin_thumbnail_url', None)
if func is None:
return _('An "admin_thumbnail" photo size has not been defined.')
else:
if hasattr(self, 'get_absolute_url'):
return '<a class="foto_admin_thumbs" target="_blank" href="%s"><img src="%s"></a>' % \
(self.get_absolute_url(), func())
else:
return '<a class="foto_admin_thumbs" target="_blank" href="%s"><img src="%s"></a>' % \
(self.image.url, func())
admin_thumbnail.short_description = _('Thumbnail')
admin_thumbnail.allow_tags = True
| gpl-3.0 | [
504,
1639,
14,
697,
492,
1709,
199,
504,
19397,
793,
310,
14,
992,
492,
6047,
1685,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
421,
199,
533,
2165,
32343,
475,
264,
8,
3491,
1685,
304,
272,
1305,
63,
84,
902,
416,
275,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
949,
278,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
949,
278,
63,
371,
23988,
11318,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
327,
5464,
275,
1709,
14,
17315,
8,
3235,
29,
549,
12,
1720,
63,
505,
7782,
2,
5464,
582,
625,
16346,
3385,
720,
2599,
391,
280,
331,
325,
17225,
79,
331,
1333,
272,
7039,
16079,
368,
275,
1709,
14,
6254,
8,
988,
63,
1267,
29,
7727,
12,
4596,
29,
549,
9,
272,
666,
63,
78,
10125,
21492,
275,
1709,
14,
14071,
8,
2307,
29,
549,
12,
4596,
29,
549,
9,
272,
666,
63,
13175,
527,
12417,
275,
1709,
14,
14071,
8,
2307,
29,
549,
12,
4596,
29,
549,
9,
272,
327,
1017,
391,
2598,
63,
9733,
275,
1709,
14,
21910,
8,
5064,
63,
475,
628,
2445,
5812,
30966,
337,
8270,
73,
401,
4596,
29,
549,
9,
272,
1166,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3912,
12,
4596,
29,
549,
9,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
291,
14,
29897,
63,
371,
23988,
11318,
508,
488,
503,
291,
14,
29897,
63,
371,
23988,
11318,
14,
1294,
342,
508,
18410,
288,
291,
14,
29897,
63,
371,
23988,
11318,
275,
291,
14,
29897,
14,
4142,
342,
267,
1613,
8,
277,
855,
533,
3108,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
327,
6523,
314,
298,
3093,
2,
3354,
342,
1083,
14,
339,
1021,
6288,
26,
267,
7794,
275,
788,
29897,
418,
267,
1592,
63,
1224,
275,
283,
8788,
337,
475,
264,
7,
267,
3376,
63,
354,
63,
10019,
275,
298,
30966,
337,
475,
264,
2,
199,
199,
3,
259,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
199,
3,
263,
372,
1543,
83,
7,
450,
334,
277,
14,
633,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
7,
450,
334,
277,
14,
29897,
63,
371,
23988,
11318,
9,
421,
199,
533,
428,
1809,
65,
52,
825,
12165,
65,
8,
992,
14,
1685,
304,
272,
1305,
63,
84,
902,
416,
275,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
1402,
320,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
12441,
337,
475,
264,
275,
1709,
14,
3190,
8,
30966,
337,
475,
264,
12,
2973,
29,
549,
12,
4596,
29,
549,
12,
641,
63,
1807,
29,
992,
14,
3597,
63,
8084,
9,
272,
691,
31209,
63,
328,
63,
2981,
1132,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
22984,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
307,
1810,
4446,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
5033,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
11199,
2102,
21492,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
7573,
269,
4674,
63,
32059,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
7573,
269,
4674,
63,
328,
63,
11535,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
21698,
21492,
63,
926,
329,
696,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
10491,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
2153,
555,
338,
3804,
63,
4603,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
21165,
434,
30834,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
876,
4348,
79,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
7039,
16079,
368,
275,
1709,
14,
6254,
8,
988,
63,
1267,
29,
7727,
12,
4596,
29,
549,
9,
272,
666,
63,
262,
261,
322,
434,
79,
275,
1709,
14,
14071,
8,
2307,
29,
549,
12,
4596,
29,
797,
12,
2599,
63,
2131,
63,
525,
29,
549,
9,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
10487,
65,
63,
266,
6413,
24027,
7,
267,
3376,
63,
354,
63,
10019,
275,
298,
29806,
65,
377,
825,
12165,
65,
2,
421,
199,
533,
481,
3459,
23219,
45,
1180,
79,
8,
3491,
1685,
304,
272,
1305,
63,
84,
902,
416,
275,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
327,
1017,
391,
2598,
275,
1709,
14,
21910,
8,
5064,
63,
475,
628,
38,
3459,
23219,
45,
1180,
79,
3149,
68,
4111,
77,
4111,
57,
401,
4596,
29,
549,
9,
272,
325,
280,
335,
386,
502,
63,
422,
271,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
666,
63,
262,
261,
322,
434,
79,
275,
1709,
14,
14071,
8,
2307,
29,
549,
12,
4596,
29,
797,
12,
2599,
63,
2131,
63,
525,
29,
549,
9,
272,
542,
322,
1895,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8188,
12,
4596,
29,
549,
9,
272,
8103,
305,
915,
4674,
275,
1709,
14,
6254,
8,
988,
63,
1267,
29,
12870,
12,
4596,
29,
549,
9,
272,
10286,
65,
63,
266,
6413,
24027,
275,
1709,
14,
3190,
8,
29806,
65,
52,
825,
12165,
65,
12,
2973,
29,
549,
12,
4596,
29,
549,
12,
641,
63,
1807,
29,
992,
14,
3597,
63,
8084,
9,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
70,
3459,
63,
16529,
63,
77,
1180,
79,
7,
267,
3376,
63,
354,
63,
10019,
275,
298,
38,
3459,
22825,
1068,
603,
1180
] | [
1639,
14,
697,
492,
1709,
199,
504,
19397,
793,
310,
14,
992,
492,
6047,
1685,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
421,
199,
533,
2165,
32343,
475,
264,
8,
3491,
1685,
304,
272,
1305,
63,
84,
902,
416,
275,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
949,
278,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
949,
278,
63,
371,
23988,
11318,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
327,
5464,
275,
1709,
14,
17315,
8,
3235,
29,
549,
12,
1720,
63,
505,
7782,
2,
5464,
582,
625,
16346,
3385,
720,
2599,
391,
280,
331,
325,
17225,
79,
331,
1333,
272,
7039,
16079,
368,
275,
1709,
14,
6254,
8,
988,
63,
1267,
29,
7727,
12,
4596,
29,
549,
9,
272,
666,
63,
78,
10125,
21492,
275,
1709,
14,
14071,
8,
2307,
29,
549,
12,
4596,
29,
549,
9,
272,
666,
63,
13175,
527,
12417,
275,
1709,
14,
14071,
8,
2307,
29,
549,
12,
4596,
29,
549,
9,
272,
327,
1017,
391,
2598,
63,
9733,
275,
1709,
14,
21910,
8,
5064,
63,
475,
628,
2445,
5812,
30966,
337,
8270,
73,
401,
4596,
29,
549,
9,
272,
1166,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
3912,
12,
4596,
29,
549,
9,
339,
347,
3354,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
340,
291,
14,
29897,
63,
371,
23988,
11318,
508,
488,
503,
291,
14,
29897,
63,
371,
23988,
11318,
14,
1294,
342,
508,
18410,
288,
291,
14,
29897,
63,
371,
23988,
11318,
275,
291,
14,
29897,
14,
4142,
342,
267,
1613,
8,
277,
855,
533,
3108,
291,
680,
2117,
2031,
589,
12,
1011,
958,
9,
327,
6523,
314,
298,
3093,
2,
3354,
342,
1083,
14,
339,
1021,
6288,
26,
267,
7794,
275,
788,
29897,
418,
267,
1592,
63,
1224,
275,
283,
8788,
337,
475,
264,
7,
267,
3376,
63,
354,
63,
10019,
275,
298,
30966,
337,
475,
264,
2,
199,
199,
3,
259,
347,
664,
63,
6116,
63,
633,
8,
277,
304,
199,
3,
263,
372,
1543,
83,
7,
450,
334,
277,
14,
633,
9,
339,
347,
636,
495,
721,
277,
304,
267,
372,
1543,
83,
7,
450,
334,
277,
14,
29897,
63,
371,
23988,
11318,
9,
421,
199,
533,
428,
1809,
65,
52,
825,
12165,
65,
8,
992,
14,
1685,
304,
272,
1305,
63,
84,
902,
416,
275,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
1402,
320,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
12441,
337,
475,
264,
275,
1709,
14,
3190,
8,
30966,
337,
475,
264,
12,
2973,
29,
549,
12,
4596,
29,
549,
12,
641,
63,
1807,
29,
992,
14,
3597,
63,
8084,
9,
272,
691,
31209,
63,
328,
63,
2981,
1132,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
22984,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
307,
1810,
4446,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
5033,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
11199,
2102,
21492,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
7573,
269,
4674,
63,
32059,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
7573,
269,
4674,
63,
328,
63,
11535,
65,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
21698,
21492,
63,
926,
329,
696,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
10491,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
2153,
555,
338,
3804,
63,
4603,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
21165,
434,
30834,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
876,
4348,
79,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
7039,
16079,
368,
275,
1709,
14,
6254,
8,
988,
63,
1267,
29,
7727,
12,
4596,
29,
549,
9,
272,
666,
63,
262,
261,
322,
434,
79,
275,
1709,
14,
14071,
8,
2307,
29,
549,
12,
4596,
29,
797,
12,
2599,
63,
2131,
63,
525,
29,
549,
9,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
10487,
65,
63,
266,
6413,
24027,
7,
267,
3376,
63,
354,
63,
10019,
275,
298,
29806,
65,
377,
825,
12165,
65,
2,
421,
199,
533,
481,
3459,
23219,
45,
1180,
79,
8,
3491,
1685,
304,
272,
1305,
63,
84,
902,
416,
275,
1709,
14,
4378,
8,
3327,
63,
498,
29,
549,
9,
272,
327,
1017,
391,
2598,
275,
1709,
14,
21910,
8,
5064,
63,
475,
628,
38,
3459,
23219,
45,
1180,
79,
3149,
68,
4111,
77,
4111,
57,
401,
4596,
29,
549,
9,
272,
325,
280,
335,
386,
502,
63,
422,
271,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8312,
12,
4596,
29,
549,
9,
272,
666,
63,
262,
261,
322,
434,
79,
275,
1709,
14,
14071,
8,
2307,
29,
549,
12,
4596,
29,
797,
12,
2599,
63,
2131,
63,
525,
29,
549,
9,
272,
542,
322,
1895,
275,
1709,
14,
2183,
8,
988,
63,
1267,
29,
8188,
12,
4596,
29,
549,
9,
272,
8103,
305,
915,
4674,
275,
1709,
14,
6254,
8,
988,
63,
1267,
29,
12870,
12,
4596,
29,
549,
9,
272,
10286,
65,
63,
266,
6413,
24027,
275,
1709,
14,
3190,
8,
29806,
65,
52,
825,
12165,
65,
12,
2973,
29,
549,
12,
4596,
29,
549,
12,
641,
63,
1807,
29,
992,
14,
3597,
63,
8084,
9,
339,
1021,
6288,
26,
267,
1592,
63,
1224,
275,
283,
70,
3459,
63,
16529,
63,
77,
1180,
79,
7,
267,
3376,
63,
354,
63,
10019,
275,
298,
38,
3459,
22825,
1068,
603,
1180,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
scholarly/pynacl | tests/test_encoding.py | 7 | 2670 | # Copyright 2013 Donald Stufft and individual contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import absolute_import, division, print_function
import pytest
import nacl.encoding
import nacl.secret
KEY = b"1" * nacl.secret.SecretBox.KEY_SIZE
NONCE = b"1" * nacl.secret.SecretBox.NONCE_SIZE
TEXT = b"The quick brown fox jumps over the lazy dog"
VECTORS = [
# Encoder, Ciphertext
(
nacl.encoding.RawEncoder,
(b"111111111111111111111111\xfcU\xe2\x9f\xe6E\x92\xd7\x0eFM=x\x83\x8fj"
b"} v\xd4\xf0\x1a1\xc0\x88Uk\x12\x02\x1cd\xfaOH\x13\xdc\x0e\x0e\xd7A"
b"\x07\x0b.\x9f\x01\xbf\xe4\xd0s\xf1P\xd3\x0e\xaa\x9d\xb3\xf7\\\x0f"),
),
(
nacl.encoding.HexEncoder,
(b"313131313131313131313131313131313131313131313131fc55e29fe64592d70e4"
b"64d3d78838f6a7d2076d4f01a31c088556b12021c64fa4f4813dc0e0ed741070b2e"
b"9f01bfe4d073f150d30eaa9db3f75c0f"),
),
(
nacl.encoding.Base16Encoder,
(b"313131313131313131313131313131313131313131313131FC55E29FE64592D70E4"
b"64D3D78838F6A7D2076D4F01A31C088556B12021C64FA4F4813DC0E0ED741070B2E"
b"9F01BFE4D073F150D30EAA9DB3F75C0F"),
),
(
nacl.encoding.Base32Encoder,
(b"GEYTCMJRGEYTCMJRGEYTCMJRGEYTCMJRGEYTCMP4KXRJ7ZSFSLLQ4RSNHV4IHD3KPUQ"
b"HNVHQDIY4BCCVNMJAEHDE7JHUQE64BYHNOQIHBMXJ6AN74TIHH4KQ2MHKVHNT65OA6"
b"==="),
),
(
nacl.encoding.Base64Encoder,
(b"MTExMTExMTExMTExMTExMTExMTExMTEx/FXin+ZFktcORk09eIOPan0gdtTwGjHAiFV"
b"rEgIcZPpPSBPcDg7XQQcLLp8Bv+TQc/FQ0w6qnbP3XA8="),
),
(
nacl.encoding.URLSafeBase64Encoder,
(b"MTExMTExMTExMTExMTExMTExMTExMTEx_FXin-ZFktcORk09eIOPan0gdtTwGjHAiFV"
b"rEgIcZPpPSBPcDg7XQQcLLp8Bv-TQc_FQ0w6qnbP3XA8="),
),
]
@pytest.mark.parametrize(("encoder", "ciphertext"), VECTORS)
def test_encoders(encoder, ciphertext):
box = nacl.secret.SecretBox(KEY)
test_ciphertext = box.encrypt(TEXT, NONCE, encoder=encoder)
assert test_ciphertext == ciphertext
test_plaintext = box.decrypt(test_ciphertext, encoder=encoder)
assert test_plaintext == TEXT
| apache-2.0 | [
3,
1898,
6171,
7529,
27075,
1933,
3043,
84,
436,
8212,
8417,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
646,
4613,
199,
199,
646,
302,
5853,
14,
2991,
199,
646,
302,
5853,
14,
4731,
421,
199,
3078,
275,
330,
2,
17,
2,
627,
302,
5853,
14,
4731,
14,
13790,
3532,
14,
3078,
63,
4305,
199,
13887,
2089,
275,
330,
2,
17,
2,
627,
302,
5853,
14,
4731,
14,
13790,
3532,
14,
13887,
2089,
63,
4305,
199,
3876,
275,
330,
2,
1918,
12530,
330,
18406,
7090,
88,
14882,
83,
1806,
314,
9617,
23454,
2,
199,
2524,
1028,
4149,
275,
359,
272,
327,
3447,
2693,
12,
29683,
505,
272,
334,
267,
302,
5853,
14,
2991,
14,
7963,
6679,
12,
267,
334,
66,
2,
28031,
14757,
60,
10347,
53,
60,
1845,
18,
60,
88,
25,
70,
60,
1845,
22,
37,
60,
88,
2942,
60,
2207,
23,
60,
88,
16,
69,
22367,
29,
88,
60,
88,
2658,
60,
88,
24,
70,
74,
2,
268,
330,
3570,
373,
60,
2207,
20,
60,
1949,
16,
60,
88,
17,
65,
17,
60,
1812,
16,
60,
88,
1299,
53,
75,
60,
88,
713,
60,
88,
996,
60,
88,
17,
2866,
60,
10500,
30454,
60,
88,
969,
60,
10550,
60,
88,
16,
69,
60,
88,
16,
69,
60,
2207,
23,
33,
2,
268,
330,
3212,
88,
1780,
60,
88,
16,
66,
3134,
88,
25,
70,
60,
88,
614,
60,
9566,
60,
1845,
20,
60,
2207,
16,
83,
60,
1949,
17,
48,
60,
2207,
19,
60,
88,
16,
69,
60,
10117,
60,
88,
25,
68,
60,
1774,
19,
60,
1949,
23,
9780,
88,
16,
70,
1288,
272,
2318,
272,
334,
267,
302,
5853,
14,
2991,
14,
10373,
6679,
12,
267,
334,
66,
2,
19455,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
11780,
3003,
1229,
69,
1398,
771,
772,
14098,
68,
2760,
69,
20,
2,
268,
330,
2,
772,
68,
19,
68,
29831,
1703,
70,
22,
65,
23,
68,
1165,
2114,
68,
20,
70,
614,
65,
2192,
67,
27930,
18683,
66,
713,
15385,
67,
772,
667,
20,
70,
2006,
969,
3833,
16,
69,
16,
379,
1342,
709,
2760,
66,
18,
69,
2,
268,
330,
2,
25,
70,
614,
66,
771,
20,
68,
26010,
70,
8251,
68,
1216,
69,
2158,
25,
697,
19,
70,
2194,
67,
16,
70,
1288,
272,
2318,
272,
334,
267,
302,
5853,
14,
2991,
14,
1563,
975,
6679,
12,
267,
334,
66,
2,
19455,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
11780,
4161,
1229,
37,
1398,
5100,
772,
14098,
36,
2760,
37,
20,
2,
268,
330,
2,
772,
36,
19,
36,
29831,
1703,
38,
22,
33,
23,
36,
1165,
2114,
36,
20,
38,
614,
33,
2192,
35,
27930,
18683,
34,
713,
15385,
35,
772,
2078,
20,
38,
2006,
969,
5196,
16,
37,
16,
1149,
1342,
709,
2760,
34,
18,
37,
2,
268,
330,
2,
25,
38,
614,
34,
5100,
20,
36,
26010,
38,
8251,
36,
1216,
37,
2276,
25,
2846,
19,
38,
2194,
35,
16,
38,
1288,
272,
2318,
272,
334,
267,
302,
5853,
14,
2991,
14,
1563,
708,
6679,
12,
267,
334,
66,
2,
4962,
57,
5708,
30495,
50,
4962,
57,
5708,
30495,
50,
4962,
57,
5708,
30495,
50,
4962,
57,
5708,
30495,
50,
4962,
57,
5708,
1658,
20,
43,
12297,
42,
23,
26697,
7079,
4464,
49,
20,
50,
8199,
16566,
20,
41,
14903,
19,
43,
6903,
49,
2,
268,
330,
2,
40,
7312,
27497,
1914,
57,
20,
34,
2571,
54,
21942,
42,
12500,
40,
1093,
23,
42,
28327,
31668,
772,
8285,
40,
2826,
49,
19824,
15225,
56,
42,
22,
879,
1342,
13247,
10213,
20,
24817,
18,
30668,
43,
54,
40,
12460,
2182,
47,
33,
22,
2,
268,
330,
2,
389,
628,
395,
272,
2318,
272,
334,
267,
302,
5853,
14,
2991,
14,
1563,
772,
6679,
12,
267,
334,
66,
2,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
15,
22322,
262,
11,
23643,
75,
3641,
726,
75,
1643,
69,
41,
1938,
290,
16,
71,
3583,
22879,
39,
74,
6294,
73,
24600,
2,
268,
330,
2,
82,
29496,
41,
67,
58,
48,
80,
5067,
24408,
67,
36,
71,
23,
56,
12917,
67,
4464,
80,
24,
34,
86,
11,
52,
49,
67,
15,
27629,
16,
87,
22,
81,
4994,
48,
19,
56,
33,
24,
628,
395,
272,
2318,
272,
334,
267,
302,
5853,
14,
2991,
14,
2632,
11090,
1563,
772,
6679,
12,
267,
334,
66,
2,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
63,
22322,
262,
13,
23643,
75,
3641,
726,
75,
1643,
69,
41,
1938,
290,
16,
71,
3583,
22879,
39,
74,
6294,
73,
24600,
2,
268,
330,
2,
82,
29496,
41,
67,
58,
48,
80,
5067,
24408,
67,
36,
71,
23,
56,
12917,
67,
4464,
80,
24,
34,
86,
13,
52,
49,
67,
63,
27629,
16,
87,
22,
81,
4994,
48,
19,
56,
33,
24,
628,
395,
272,
2318,
199,
61,
421,
199,
32,
4462,
14,
1657,
14,
10396,
9313,
9347,
401,
298,
27661,
1288,
812,
3582,
4149,
9,
199,
318,
511,
63,
9347,
83,
8,
9347,
12,
29147,
304,
272,
5689,
275,
302,
5853,
14,
4731,
14,
13790,
3532,
8,
3078,
9,
339,
511
] | [
1898,
6171,
7529,
27075,
1933,
3043,
84,
436,
8212,
8417,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
199,
646,
4613,
199,
199,
646,
302,
5853,
14,
2991,
199,
646,
302,
5853,
14,
4731,
421,
199,
3078,
275,
330,
2,
17,
2,
627,
302,
5853,
14,
4731,
14,
13790,
3532,
14,
3078,
63,
4305,
199,
13887,
2089,
275,
330,
2,
17,
2,
627,
302,
5853,
14,
4731,
14,
13790,
3532,
14,
13887,
2089,
63,
4305,
199,
3876,
275,
330,
2,
1918,
12530,
330,
18406,
7090,
88,
14882,
83,
1806,
314,
9617,
23454,
2,
199,
2524,
1028,
4149,
275,
359,
272,
327,
3447,
2693,
12,
29683,
505,
272,
334,
267,
302,
5853,
14,
2991,
14,
7963,
6679,
12,
267,
334,
66,
2,
28031,
14757,
60,
10347,
53,
60,
1845,
18,
60,
88,
25,
70,
60,
1845,
22,
37,
60,
88,
2942,
60,
2207,
23,
60,
88,
16,
69,
22367,
29,
88,
60,
88,
2658,
60,
88,
24,
70,
74,
2,
268,
330,
3570,
373,
60,
2207,
20,
60,
1949,
16,
60,
88,
17,
65,
17,
60,
1812,
16,
60,
88,
1299,
53,
75,
60,
88,
713,
60,
88,
996,
60,
88,
17,
2866,
60,
10500,
30454,
60,
88,
969,
60,
10550,
60,
88,
16,
69,
60,
88,
16,
69,
60,
2207,
23,
33,
2,
268,
330,
3212,
88,
1780,
60,
88,
16,
66,
3134,
88,
25,
70,
60,
88,
614,
60,
9566,
60,
1845,
20,
60,
2207,
16,
83,
60,
1949,
17,
48,
60,
2207,
19,
60,
88,
16,
69,
60,
10117,
60,
88,
25,
68,
60,
1774,
19,
60,
1949,
23,
9780,
88,
16,
70,
1288,
272,
2318,
272,
334,
267,
302,
5853,
14,
2991,
14,
10373,
6679,
12,
267,
334,
66,
2,
19455,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
11780,
3003,
1229,
69,
1398,
771,
772,
14098,
68,
2760,
69,
20,
2,
268,
330,
2,
772,
68,
19,
68,
29831,
1703,
70,
22,
65,
23,
68,
1165,
2114,
68,
20,
70,
614,
65,
2192,
67,
27930,
18683,
66,
713,
15385,
67,
772,
667,
20,
70,
2006,
969,
3833,
16,
69,
16,
379,
1342,
709,
2760,
66,
18,
69,
2,
268,
330,
2,
25,
70,
614,
66,
771,
20,
68,
26010,
70,
8251,
68,
1216,
69,
2158,
25,
697,
19,
70,
2194,
67,
16,
70,
1288,
272,
2318,
272,
334,
267,
302,
5853,
14,
2991,
14,
1563,
975,
6679,
12,
267,
334,
66,
2,
19455,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
969,
11780,
4161,
1229,
37,
1398,
5100,
772,
14098,
36,
2760,
37,
20,
2,
268,
330,
2,
772,
36,
19,
36,
29831,
1703,
38,
22,
33,
23,
36,
1165,
2114,
36,
20,
38,
614,
33,
2192,
35,
27930,
18683,
34,
713,
15385,
35,
772,
2078,
20,
38,
2006,
969,
5196,
16,
37,
16,
1149,
1342,
709,
2760,
34,
18,
37,
2,
268,
330,
2,
25,
38,
614,
34,
5100,
20,
36,
26010,
38,
8251,
36,
1216,
37,
2276,
25,
2846,
19,
38,
2194,
35,
16,
38,
1288,
272,
2318,
272,
334,
267,
302,
5853,
14,
2991,
14,
1563,
708,
6679,
12,
267,
334,
66,
2,
4962,
57,
5708,
30495,
50,
4962,
57,
5708,
30495,
50,
4962,
57,
5708,
30495,
50,
4962,
57,
5708,
30495,
50,
4962,
57,
5708,
1658,
20,
43,
12297,
42,
23,
26697,
7079,
4464,
49,
20,
50,
8199,
16566,
20,
41,
14903,
19,
43,
6903,
49,
2,
268,
330,
2,
40,
7312,
27497,
1914,
57,
20,
34,
2571,
54,
21942,
42,
12500,
40,
1093,
23,
42,
28327,
31668,
772,
8285,
40,
2826,
49,
19824,
15225,
56,
42,
22,
879,
1342,
13247,
10213,
20,
24817,
18,
30668,
43,
54,
40,
12460,
2182,
47,
33,
22,
2,
268,
330,
2,
389,
628,
395,
272,
2318,
272,
334,
267,
302,
5853,
14,
2991,
14,
1563,
772,
6679,
12,
267,
334,
66,
2,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
15,
22322,
262,
11,
23643,
75,
3641,
726,
75,
1643,
69,
41,
1938,
290,
16,
71,
3583,
22879,
39,
74,
6294,
73,
24600,
2,
268,
330,
2,
82,
29496,
41,
67,
58,
48,
80,
5067,
24408,
67,
36,
71,
23,
56,
12917,
67,
4464,
80,
24,
34,
86,
11,
52,
49,
67,
15,
27629,
16,
87,
22,
81,
4994,
48,
19,
56,
33,
24,
628,
395,
272,
2318,
272,
334,
267,
302,
5853,
14,
2991,
14,
2632,
11090,
1563,
772,
6679,
12,
267,
334,
66,
2,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
5747,
920,
63,
22322,
262,
13,
23643,
75,
3641,
726,
75,
1643,
69,
41,
1938,
290,
16,
71,
3583,
22879,
39,
74,
6294,
73,
24600,
2,
268,
330,
2,
82,
29496,
41,
67,
58,
48,
80,
5067,
24408,
67,
36,
71,
23,
56,
12917,
67,
4464,
80,
24,
34,
86,
13,
52,
49,
67,
63,
27629,
16,
87,
22,
81,
4994,
48,
19,
56,
33,
24,
628,
395,
272,
2318,
199,
61,
421,
199,
32,
4462,
14,
1657,
14,
10396,
9313,
9347,
401,
298,
27661,
1288,
812,
3582,
4149,
9,
199,
318,
511,
63,
9347,
83,
8,
9347,
12,
29147,
304,
272,
5689,
275,
302,
5853,
14,
4731,
14,
13790,
3532,
8,
3078,
9,
339,
511,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
hsum/sqlalchemy | examples/vertical/__init__.py | 30 | 1043 | """
Illustrates "vertical table" mappings.
A "vertical table" refers to a technique where individual attributes
of an object are stored as distinct rows in a table. The "vertical
table" technique is used to persist objects which can have a varied
set of attributes, at the expense of simple query control and brevity.
It is commonly found in content/document management systems in order
to represent user-created structures flexibly.
Two variants on the approach are given. In the second, each row
references a "datatype" which contains information about the type of
information stored in the attribute, such as integer, string, or date.
Example::
shrew = Animal(u'shrew')
shrew[u'cuteness'] = 5
shrew[u'weasel-like'] = False
shrew[u'poisonous'] = True
session.add(shrew)
session.flush()
q = (session.query(Animal).
filter(Animal.facts.any(
and_(AnimalFact.key == u'weasel-like',
AnimalFact.value == True))))
print 'weasel-like animals', q.all()
.. autosource::
""" | mit | [
624,
199,
41,
914,
11409,
2335,
298,
7870,
1817,
2,
13546,
14,
199,
199,
33,
298,
7870,
1817,
2,
15724,
370,
282,
32414,
2382,
8212,
3004,
199,
1618,
376,
909,
787,
5489,
465,
15392,
4730,
315,
282,
1817,
14,
710,
298,
7870,
199,
1224,
2,
32414,
365,
1202,
370,
22400,
2251,
1314,
883,
1172,
282,
4172,
379,
199,
409,
402,
3004,
12,
737,
314,
26963,
402,
3486,
1827,
3304,
436,
330,
264,
18936,
14,
199,
7940,
365,
28829,
1911,
315,
1564,
15,
3554,
10041,
10460,
315,
1865,
199,
475,
2954,
922,
13,
3966,
13955,
20758,
1892,
590,
14,
199,
199,
11467,
21169,
641,
314,
18140,
787,
1627,
14,
221,
1010,
314,
3499,
12,
1924,
1962,
199,
12635,
282,
298,
14184,
2,
1314,
3509,
2556,
3595,
314,
730,
402,
199,
11697,
5489,
315,
314,
2225,
12,
4066,
465,
3000,
12,
1059,
12,
503,
1434,
14,
421,
199,
9846,
447,
339,
1033,
5257,
275,
1626,
7265,
8,
85,
1159,
72,
5257,
358,
272,
1033,
5257,
59,
85,
7,
67,
938,
4171,
418,
275,
959,
272,
1033,
5257,
59,
85,
7,
1129,
482,
76,
13,
2930,
418,
275,
756,
272,
1033,
5257,
59,
85,
7,
555,
28287,
1785,
418,
275,
715,
339,
2351,
14,
525,
8,
609,
5257,
9,
272,
2351,
14,
4939,
342,
339,
1894,
275,
334,
1730,
14,
1131,
8,
2493,
7265,
680,
268,
2457,
8,
2493,
7265,
14,
5047,
14,
1629,
8,
1779,
436,
2531,
2493,
7265,
24704,
14,
498,
508,
399,
7,
1129,
482,
76,
13,
2930,
297,
355,
1626,
7265,
24704,
14,
585,
508,
715,
7845,
272,
870,
283,
1129,
482,
76,
13,
2930,
27183,
2551,
297,
1894,
14,
452,
342,
199,
199,
703,
26651,
616,
447,
199,
199,
624,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
41,
914,
11409,
2335,
298,
7870,
1817,
2,
13546,
14,
199,
199,
33,
298,
7870,
1817,
2,
15724,
370,
282,
32414,
2382,
8212,
3004,
199,
1618,
376,
909,
787,
5489,
465,
15392,
4730,
315,
282,
1817,
14,
710,
298,
7870,
199,
1224,
2,
32414,
365,
1202,
370,
22400,
2251,
1314,
883,
1172,
282,
4172,
379,
199,
409,
402,
3004,
12,
737,
314,
26963,
402,
3486,
1827,
3304,
436,
330,
264,
18936,
14,
199,
7940,
365,
28829,
1911,
315,
1564,
15,
3554,
10041,
10460,
315,
1865,
199,
475,
2954,
922,
13,
3966,
13955,
20758,
1892,
590,
14,
199,
199,
11467,
21169,
641,
314,
18140,
787,
1627,
14,
221,
1010,
314,
3499,
12,
1924,
1962,
199,
12635,
282,
298,
14184,
2,
1314,
3509,
2556,
3595,
314,
730,
402,
199,
11697,
5489,
315,
314,
2225,
12,
4066,
465,
3000,
12,
1059,
12,
503,
1434,
14,
421,
199,
9846,
447,
339,
1033,
5257,
275,
1626,
7265,
8,
85,
1159,
72,
5257,
358,
272,
1033,
5257,
59,
85,
7,
67,
938,
4171,
418,
275,
959,
272,
1033,
5257,
59,
85,
7,
1129,
482,
76,
13,
2930,
418,
275,
756,
272,
1033,
5257,
59,
85,
7,
555,
28287,
1785,
418,
275,
715,
339,
2351,
14,
525,
8,
609,
5257,
9,
272,
2351,
14,
4939,
342,
339,
1894,
275,
334,
1730,
14,
1131,
8,
2493,
7265,
680,
268,
2457,
8,
2493,
7265,
14,
5047,
14,
1629,
8,
1779,
436,
2531,
2493,
7265,
24704,
14,
498,
508,
399,
7,
1129,
482,
76,
13,
2930,
297,
355,
1626,
7265,
24704,
14,
585,
508,
715,
7845,
272,
870,
283,
1129,
482,
76,
13,
2930,
27183,
2551,
297,
1894,
14,
452,
342,
199,
199,
703,
26651,
616,
447,
199,
199,
624,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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in/env python
# Test whether a clean session client has a QoS 1 message queued for it.
import subprocess
import socket
import time
import inspect, os, sys
# From http://stackoverflow.com/questions/279237/python-import-a-module-from-a-folder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"..")))
if cmd_subfolder not in sys.path:
sys.path.insert(0, cmd_subfolder)
import mosq_test
rc = 1
mid = 109
keepalive = 60
connect_packet = mosq_test.gen_connect("clean-qos2-test", keepalive=keepalive, clean_session=False)
connack_packet = mosq_test.gen_connack(rc=0)
disconnect_packet = mosq_test.gen_disconnect()
subscribe_packet = mosq_test.gen_subscribe(mid, "qos1/clean_session/test", 1)
suback_packet = mosq_test.gen_suback(mid, 1)
mid = 1
publish_packet = mosq_test.gen_publish("qos1/clean_session/test", qos=1, mid=mid, payload="clean-session-message")
puback_packet = mosq_test.gen_puback(mid)
broker = subprocess.Popen(['../../src/mosquitto', '-p', '1888'], stderr=subprocess.PIPE)
try:
time.sleep(0.5)
sock = mosq_test.do_client_connect(connect_packet, connack_packet)
sock.send(subscribe_packet)
if mosq_test.expect_packet(sock, "suback", suback_packet):
sock.send(disconnect_packet)
sock.close()
pub = subprocess.Popen(['./05-clean-session-qos1-helper.py'])
pub.wait()
# Now reconnect and expect a publish message.
sock = mosq_test.do_client_connect(connect_packet, connack_packet, timeout=30)
if mosq_test.expect_packet(sock, "publish", publish_packet):
sock.send(puback_packet)
rc = 0
sock.close()
finally:
broker.terminate()
broker.wait()
if rc:
(stdo, stde) = broker.communicate()
print(stde)
exit(rc)
| gpl-3.0 | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1379,
3775,
282,
3633,
2351,
1890,
965,
282,
1413,
79,
51,
413,
1245,
26102,
367,
652,
14,
199,
199,
646,
3873,
199,
646,
2838,
199,
646,
900,
199,
199,
646,
6485,
12,
747,
12,
984,
199,
3,
11606,
1455,
921,
23153,
14,
957,
15,
16069,
15,
1465,
2942,
1401,
15,
1548,
13,
646,
13,
65,
13,
578,
13,
504,
13,
65,
13,
3741,
199,
1760,
63,
954,
3741,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
1294,
8,
10955,
14,
23462,
8,
6485,
14,
1818,
1943,
342,
5082,
59,
16,
20007,
703,
13324,
199,
692,
2088,
63,
954,
3741,
440,
315,
984,
14,
515,
26,
272,
984,
14,
515,
14,
3176,
8,
16,
12,
2088,
63,
954,
3741,
9,
199,
199,
646,
333,
736,
81,
63,
396,
199,
199,
1195,
275,
413,
199,
8523,
275,
24058,
199,
28227,
275,
5212,
199,
2242,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
2242,
480,
3118,
13,
12282,
18,
13,
396,
401,
4215,
9631,
29,
28227,
12,
3633,
63,
1730,
29,
797,
9,
199,
1631,
564,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
1631,
564,
8,
1195,
29,
16,
9,
199,
199,
10673,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
10673,
342,
199,
199,
10108,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
10108,
8,
8523,
12,
298,
12282,
17,
15,
3118,
63,
1730,
15,
396,
401,
413,
9,
199,
954,
564,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
954,
564,
8,
8523,
12,
413,
9,
199,
199,
8523,
275,
413,
199,
4763,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
4763,
480,
12282,
17,
15,
3118,
63,
1730,
15,
396,
401,
19384,
29,
17,
12,
10887,
29,
8523,
12,
4886,
628,
3118,
13,
1730,
13,
1188,
531,
199,
5645,
564,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
5645,
564,
8,
8523,
9,
199,
199,
16620,
275,
3873,
14,
7942,
2941,
9707,
2164,
15,
573,
8471,
390,
475,
297,
2475,
80,
297,
283,
1085,
1299,
995,
4635,
29,
5781,
14,
6089,
9,
199,
199,
893,
26,
272,
900,
14,
4532,
8,
16,
14,
21,
9,
339,
6771,
275,
333,
736,
81,
63,
396,
14,
1117,
63,
1258,
63,
2242,
8,
2242,
63,
6253,
12,
2557,
564,
63,
6253,
9,
272,
6771,
14,
2254,
8,
10108,
63,
6253,
9,
339,
340,
333,
736,
81,
63,
396,
14,
4921,
63,
6253,
8,
5096,
12,
298,
954,
564,
401,
1007,
564,
63,
6253,
304,
267,
6771,
14,
2254,
8,
10673,
63,
6253,
9,
267,
6771,
14,
1600,
342,
398,
7974,
275,
3873,
14,
7942,
2941,
13186,
1717,
13,
3118,
13,
1730,
13,
12282,
17,
13,
3676,
14,
647,
1105,
267,
7974,
14,
2573,
342,
398,
327,
7356,
30882,
436,
4282,
282,
2780,
1245,
14,
267,
6771,
275,
333,
736,
81,
63,
396,
14,
1117,
63,
1258,
63,
2242,
8,
2242,
63,
6253,
12,
2557,
564,
63,
6253,
12,
2653,
29,
1216,
9,
267,
340,
333,
736,
81,
63,
396,
14,
4921,
63,
6253,
8,
5096,
12,
298,
4763,
401,
2780,
63,
6253,
304,
288,
6771,
14,
2254,
8,
5645,
564,
63,
6253,
9,
288,
4819,
275,
378,
398,
6771,
14,
1600,
342,
199,
15172,
26,
272,
15416,
14,
14478,
342,
272,
15416,
14,
2573,
342,
272,
340,
4819,
26,
267,
334,
270,
1117,
12,
410,
271,
9,
275,
15416,
14,
10664,
342,
267,
870,
8,
270,
271,
9,
199,
199,
2224,
8,
1195,
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
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
1379,
3775,
282,
3633,
2351,
1890,
965,
282,
1413,
79,
51,
413,
1245,
26102,
367,
652,
14,
199,
199,
646,
3873,
199,
646,
2838,
199,
646,
900,
199,
199,
646,
6485,
12,
747,
12,
984,
199,
3,
11606,
1455,
921,
23153,
14,
957,
15,
16069,
15,
1465,
2942,
1401,
15,
1548,
13,
646,
13,
65,
13,
578,
13,
504,
13,
65,
13,
3741,
199,
1760,
63,
954,
3741,
275,
747,
14,
515,
14,
11091,
8,
736,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
1294,
8,
10955,
14,
23462,
8,
6485,
14,
1818,
1943,
342,
5082,
59,
16,
20007,
703,
13324,
199,
692,
2088,
63,
954,
3741,
440,
315,
984,
14,
515,
26,
272,
984,
14,
515,
14,
3176,
8,
16,
12,
2088,
63,
954,
3741,
9,
199,
199,
646,
333,
736,
81,
63,
396,
199,
199,
1195,
275,
413,
199,
8523,
275,
24058,
199,
28227,
275,
5212,
199,
2242,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
2242,
480,
3118,
13,
12282,
18,
13,
396,
401,
4215,
9631,
29,
28227,
12,
3633,
63,
1730,
29,
797,
9,
199,
1631,
564,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
1631,
564,
8,
1195,
29,
16,
9,
199,
199,
10673,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
10673,
342,
199,
199,
10108,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
10108,
8,
8523,
12,
298,
12282,
17,
15,
3118,
63,
1730,
15,
396,
401,
413,
9,
199,
954,
564,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
954,
564,
8,
8523,
12,
413,
9,
199,
199,
8523,
275,
413,
199,
4763,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
4763,
480,
12282,
17,
15,
3118,
63,
1730,
15,
396,
401,
19384,
29,
17,
12,
10887,
29,
8523,
12,
4886,
628,
3118,
13,
1730,
13,
1188,
531,
199,
5645,
564,
63,
6253,
275,
333,
736,
81,
63,
396,
14,
2268,
63,
5645,
564,
8,
8523,
9,
199,
199,
16620,
275,
3873,
14,
7942,
2941,
9707,
2164,
15,
573,
8471,
390,
475,
297,
2475,
80,
297,
283,
1085,
1299,
995,
4635,
29,
5781,
14,
6089,
9,
199,
199,
893,
26,
272,
900,
14,
4532,
8,
16,
14,
21,
9,
339,
6771,
275,
333,
736,
81,
63,
396,
14,
1117,
63,
1258,
63,
2242,
8,
2242,
63,
6253,
12,
2557,
564,
63,
6253,
9,
272,
6771,
14,
2254,
8,
10108,
63,
6253,
9,
339,
340,
333,
736,
81,
63,
396,
14,
4921,
63,
6253,
8,
5096,
12,
298,
954,
564,
401,
1007,
564,
63,
6253,
304,
267,
6771,
14,
2254,
8,
10673,
63,
6253,
9,
267,
6771,
14,
1600,
342,
398,
7974,
275,
3873,
14,
7942,
2941,
13186,
1717,
13,
3118,
13,
1730,
13,
12282,
17,
13,
3676,
14,
647,
1105,
267,
7974,
14,
2573,
342,
398,
327,
7356,
30882,
436,
4282,
282,
2780,
1245,
14,
267,
6771,
275,
333,
736,
81,
63,
396,
14,
1117,
63,
1258,
63,
2242,
8,
2242,
63,
6253,
12,
2557,
564,
63,
6253,
12,
2653,
29,
1216,
9,
267,
340,
333,
736,
81,
63,
396,
14,
4921,
63,
6253,
8,
5096,
12,
298,
4763,
401,
2780,
63,
6253,
304,
288,
6771,
14,
2254,
8,
5645,
564,
63,
6253,
9,
288,
4819,
275,
378,
398,
6771,
14,
1600,
342,
199,
15172,
26,
272,
15416,
14,
14478,
342,
272,
15416,
14,
2573,
342,
272,
340,
4819,
26,
267,
334,
270,
1117,
12,
410,
271,
9,
275,
15416,
14,
10664,
342,
267,
870,
8,
270,
271,
9,
199,
199,
2224,
8,
1195,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
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/bdb.py | 144 | 21714 | """Debugger basics"""
import fnmatch
import sys
import os
import types
__all__ = ["BdbQuit","Bdb","Breakpoint"]
class BdbQuit(Exception):
"""Exception to give up completely"""
class Bdb:
"""Generic Python debugger base class.
This class takes care of details of the trace facility;
a derived class should implement user interaction.
The standard debugger class (pdb.Pdb) is an example.
"""
def __init__(self, skip=None):
self.skip = set(skip) if skip else None
self.breaks = {}
self.fncache = {}
self.frame_returning = None
def canonic(self, filename):
if filename == "<" + filename[1:-1] + ">":
return filename
canonic = self.fncache.get(filename)
if not canonic:
canonic = os.path.abspath(filename)
canonic = os.path.normcase(canonic)
self.fncache[filename] = canonic
return canonic
def reset(self):
import linecache
linecache.checkcache()
self.botframe = None
self._set_stopinfo(None, None)
def trace_dispatch(self, frame, event, arg):
if self.quitting:
return # None
if event == 'line':
return self.dispatch_line(frame)
if event == 'call':
return self.dispatch_call(frame, arg)
if event == 'return':
return self.dispatch_return(frame, arg)
if event == 'exception':
return self.dispatch_exception(frame, arg)
if event == 'c_call':
return self.trace_dispatch
if event == 'c_exception':
return self.trace_dispatch
if event == 'c_return':
return self.trace_dispatch
print 'bdb.Bdb.dispatch: unknown debugging event:', repr(event)
return self.trace_dispatch
def dispatch_line(self, frame):
if self.stop_here(frame) or self.break_here(frame):
self.user_line(frame)
if self.quitting: raise BdbQuit
return self.trace_dispatch
def dispatch_call(self, frame, arg):
# XXX 'arg' is no longer used
if self.botframe is None:
# First call of dispatch since reset()
self.botframe = frame.f_back # (CT) Note that this may also be None!
return self.trace_dispatch
if not (self.stop_here(frame) or self.break_anywhere(frame)):
# No need to trace this function
return # None
self.user_call(frame, arg)
if self.quitting: raise BdbQuit
return self.trace_dispatch
def dispatch_return(self, frame, arg):
if self.stop_here(frame) or frame == self.returnframe:
try:
self.frame_returning = frame
self.user_return(frame, arg)
finally:
self.frame_returning = None
if self.quitting: raise BdbQuit
return self.trace_dispatch
def dispatch_exception(self, frame, arg):
if self.stop_here(frame):
self.user_exception(frame, arg)
if self.quitting: raise BdbQuit
return self.trace_dispatch
# Normally derived classes don't override the following
# methods, but they may if they want to redefine the
# definition of stopping and breakpoints.
def is_skipped_module(self, module_name):
for pattern in self.skip:
if fnmatch.fnmatch(module_name, pattern):
return True
return False
def stop_here(self, frame):
# (CT) stopframe may now also be None, see dispatch_call.
# (CT) the former test for None is therefore removed from here.
if self.skip and \
self.is_skipped_module(frame.f_globals.get('__name__')):
return False
if frame is self.stopframe:
if self.stoplineno == -1:
return False
return frame.f_lineno >= self.stoplineno
while frame is not None and frame is not self.stopframe:
if frame is self.botframe:
return True
frame = frame.f_back
return False
def break_here(self, frame):
filename = self.canonic(frame.f_code.co_filename)
if not filename in self.breaks:
return False
lineno = frame.f_lineno
if not lineno in self.breaks[filename]:
# The line itself has no breakpoint, but maybe the line is the
# first line of a function with breakpoint set by function name.
lineno = frame.f_code.co_firstlineno
if not lineno in self.breaks[filename]:
return False
# flag says ok to delete temp. bp
(bp, flag) = effective(filename, lineno, frame)
if bp:
self.currentbp = bp.number
if (flag and bp.temporary):
self.do_clear(str(bp.number))
return True
else:
return False
def do_clear(self, arg):
raise NotImplementedError, "subclass of bdb must implement do_clear()"
def break_anywhere(self, frame):
return self.canonic(frame.f_code.co_filename) in self.breaks
# Derived classes should override the user_* methods
# to gain control.
def user_call(self, frame, argument_list):
"""This method is called when there is the remote possibility
that we ever need to stop in this function."""
pass
def user_line(self, frame):
"""This method is called when we stop or break at this line."""
pass
def user_return(self, frame, return_value):
"""This method is called when a return trap is set here."""
pass
def user_exception(self, frame, exc_info):
exc_type, exc_value, exc_traceback = exc_info
"""This method is called if an exception occurs,
but only if we are to stop at or just below this level."""
pass
def _set_stopinfo(self, stopframe, returnframe, stoplineno=0):
self.stopframe = stopframe
self.returnframe = returnframe
self.quitting = 0
# stoplineno >= 0 means: stop at line >= the stoplineno
# stoplineno -1 means: don't stop at all
self.stoplineno = stoplineno
# Derived classes and clients can call the following methods
# to affect the stepping state.
def set_until(self, frame): #the name "until" is borrowed from gdb
"""Stop when the line with the line no greater than the current one is
reached or when returning from current frame"""
self._set_stopinfo(frame, frame, frame.f_lineno+1)
def set_step(self):
"""Stop after one line of code."""
# Issue #13183: pdb skips frames after hitting a breakpoint and running
# step commands.
# Restore the trace function in the caller (that may not have been set
# for performance reasons) when returning from the current frame.
if self.frame_returning:
caller_frame = self.frame_returning.f_back
if caller_frame and not caller_frame.f_trace:
caller_frame.f_trace = self.trace_dispatch
self._set_stopinfo(None, None)
def set_next(self, frame):
"""Stop on the next line in or below the given frame."""
self._set_stopinfo(frame, None)
def set_return(self, frame):
"""Stop when returning from the given frame."""
self._set_stopinfo(frame.f_back, frame)
def set_trace(self, frame=None):
"""Start debugging from `frame`.
If frame is not specified, debugging starts from caller's frame.
"""
if frame is None:
frame = sys._getframe().f_back
self.reset()
while frame:
frame.f_trace = self.trace_dispatch
self.botframe = frame
frame = frame.f_back
self.set_step()
sys.settrace(self.trace_dispatch)
def set_continue(self):
# Don't stop except at breakpoints or when finished
self._set_stopinfo(self.botframe, None, -1)
if not self.breaks:
# no breakpoints; run without debugger overhead
sys.settrace(None)
frame = sys._getframe().f_back
while frame and frame is not self.botframe:
del frame.f_trace
frame = frame.f_back
def set_quit(self):
self.stopframe = self.botframe
self.returnframe = None
self.quitting = 1
sys.settrace(None)
# Derived classes and clients can call the following methods
# to manipulate breakpoints. These methods return an
# error message is something went wrong, None if all is well.
# Set_break prints out the breakpoint line and file:lineno.
# Call self.get_*break*() to see the breakpoints or better
# for bp in Breakpoint.bpbynumber: if bp: bp.bpprint().
def set_break(self, filename, lineno, temporary=0, cond = None,
funcname=None):
filename = self.canonic(filename)
import linecache # Import as late as possible
line = linecache.getline(filename, lineno)
if not line:
return 'Line %s:%d does not exist' % (filename,
lineno)
if not filename in self.breaks:
self.breaks[filename] = []
list = self.breaks[filename]
if not lineno in list:
list.append(lineno)
bp = Breakpoint(filename, lineno, temporary, cond, funcname)
def _prune_breaks(self, filename, lineno):
if (filename, lineno) not in Breakpoint.bplist:
self.breaks[filename].remove(lineno)
if not self.breaks[filename]:
del self.breaks[filename]
def clear_break(self, filename, lineno):
filename = self.canonic(filename)
if not filename in self.breaks:
return 'There are no breakpoints in %s' % filename
if lineno not in self.breaks[filename]:
return 'There is no breakpoint at %s:%d' % (filename,
lineno)
# If there's only one bp in the list for that file,line
# pair, then remove the breaks entry
for bp in Breakpoint.bplist[filename, lineno][:]:
bp.deleteMe()
self._prune_breaks(filename, lineno)
def clear_bpbynumber(self, arg):
try:
number = int(arg)
except:
return 'Non-numeric breakpoint number (%s)' % arg
try:
bp = Breakpoint.bpbynumber[number]
except IndexError:
return 'Breakpoint number (%d) out of range' % number
if not bp:
return 'Breakpoint (%d) already deleted' % number
bp.deleteMe()
self._prune_breaks(bp.file, bp.line)
def clear_all_file_breaks(self, filename):
filename = self.canonic(filename)
if not filename in self.breaks:
return 'There are no breakpoints in %s' % filename
for line in self.breaks[filename]:
blist = Breakpoint.bplist[filename, line]
for bp in blist:
bp.deleteMe()
del self.breaks[filename]
def clear_all_breaks(self):
if not self.breaks:
return 'There are no breakpoints'
for bp in Breakpoint.bpbynumber:
if bp:
bp.deleteMe()
self.breaks = {}
def get_break(self, filename, lineno):
filename = self.canonic(filename)
return filename in self.breaks and \
lineno in self.breaks[filename]
def get_breaks(self, filename, lineno):
filename = self.canonic(filename)
return filename in self.breaks and \
lineno in self.breaks[filename] and \
Breakpoint.bplist[filename, lineno] or []
def get_file_breaks(self, filename):
filename = self.canonic(filename)
if filename in self.breaks:
return self.breaks[filename]
else:
return []
def get_all_breaks(self):
return self.breaks
# Derived classes and clients can call the following method
# to get a data structure representing a stack trace.
def get_stack(self, f, t):
stack = []
if t and t.tb_frame is f:
t = t.tb_next
while f is not None:
stack.append((f, f.f_lineno))
if f is self.botframe:
break
f = f.f_back
stack.reverse()
i = max(0, len(stack) - 1)
while t is not None:
stack.append((t.tb_frame, t.tb_lineno))
t = t.tb_next
if f is None:
i = max(0, len(stack) - 1)
return stack, i
#
def format_stack_entry(self, frame_lineno, lprefix=': '):
import linecache, repr
frame, lineno = frame_lineno
filename = self.canonic(frame.f_code.co_filename)
s = '%s(%r)' % (filename, lineno)
if frame.f_code.co_name:
s = s + frame.f_code.co_name
else:
s = s + "<lambda>"
if '__args__' in frame.f_locals:
args = frame.f_locals['__args__']
else:
args = None
if args:
s = s + repr.repr(args)
else:
s = s + '()'
if '__return__' in frame.f_locals:
rv = frame.f_locals['__return__']
s = s + '->'
s = s + repr.repr(rv)
line = linecache.getline(filename, lineno, frame.f_globals)
if line: s = s + lprefix + line.strip()
return s
# The following two methods can be called by clients to use
# a debugger to debug a statement, given as a string.
def run(self, cmd, globals=None, locals=None):
if globals is None:
import __main__
globals = __main__.__dict__
if locals is None:
locals = globals
self.reset()
sys.settrace(self.trace_dispatch)
if not isinstance(cmd, types.CodeType):
cmd = cmd+'\n'
try:
exec cmd in globals, locals
except BdbQuit:
pass
finally:
self.quitting = 1
sys.settrace(None)
def runeval(self, expr, globals=None, locals=None):
if globals is None:
import __main__
globals = __main__.__dict__
if locals is None:
locals = globals
self.reset()
sys.settrace(self.trace_dispatch)
if not isinstance(expr, types.CodeType):
expr = expr+'\n'
try:
return eval(expr, globals, locals)
except BdbQuit:
pass
finally:
self.quitting = 1
sys.settrace(None)
def runctx(self, cmd, globals, locals):
# B/W compatibility
self.run(cmd, globals, locals)
# This method is more useful to debug a single function call.
def runcall(self, func, *args, **kwds):
self.reset()
sys.settrace(self.trace_dispatch)
res = None
try:
res = func(*args, **kwds)
except BdbQuit:
pass
finally:
self.quitting = 1
sys.settrace(None)
return res
def set_trace():
Bdb().set_trace()
class Breakpoint:
"""Breakpoint class
Implements temporary breakpoints, ignore counts, disabling and
(re)-enabling, and conditionals.
Breakpoints are indexed by number through bpbynumber and by
the file,line tuple using bplist. The former points to a
single instance of class Breakpoint. The latter points to a
list of such instances since there may be more than one
breakpoint per line.
"""
# XXX Keeping state in the class is a mistake -- this means
# you cannot have more than one active Bdb instance.
next = 1 # Next bp to be assigned
bplist = {} # indexed by (file, lineno) tuple
bpbynumber = [None] # Each entry is None or an instance of Bpt
# index 0 is unused, except for marking an
# effective break .... see effective()
def __init__(self, file, line, temporary=0, cond=None, funcname=None):
self.funcname = funcname
# Needed if funcname is not None.
self.func_first_executable_line = None
self.file = file # This better be in canonical form!
self.line = line
self.temporary = temporary
self.cond = cond
self.enabled = 1
self.ignore = 0
self.hits = 0
self.number = Breakpoint.next
Breakpoint.next = Breakpoint.next + 1
# Build the two lists
self.bpbynumber.append(self)
if (file, line) in self.bplist:
self.bplist[file, line].append(self)
else:
self.bplist[file, line] = [self]
def deleteMe(self):
index = (self.file, self.line)
self.bpbynumber[self.number] = None # No longer in list
self.bplist[index].remove(self)
if not self.bplist[index]:
# No more bp for this f:l combo
del self.bplist[index]
def enable(self):
self.enabled = 1
def disable(self):
self.enabled = 0
def bpprint(self, out=None):
if out is None:
out = sys.stdout
if self.temporary:
disp = 'del '
else:
disp = 'keep '
if self.enabled:
disp = disp + 'yes '
else:
disp = disp + 'no '
print >>out, '%-4dbreakpoint %s at %s:%d' % (self.number, disp,
self.file, self.line)
if self.cond:
print >>out, '\tstop only if %s' % (self.cond,)
if self.ignore:
print >>out, '\tignore next %d hits' % (self.ignore)
if (self.hits):
if (self.hits > 1): ss = 's'
else: ss = ''
print >>out, ('\tbreakpoint already hit %d time%s' %
(self.hits, ss))
# -----------end of Breakpoint class----------
def checkfuncname(b, frame):
"""Check whether we should break here because of `b.funcname`."""
if not b.funcname:
# Breakpoint was set via line number.
if b.line != frame.f_lineno:
# Breakpoint was set at a line with a def statement and the function
# defined is called: don't break.
return False
return True
# Breakpoint set via function name.
if frame.f_code.co_name != b.funcname:
# It's not a function call, but rather execution of def statement.
return False
# We are in the right frame.
if not b.func_first_executable_line:
# The function is entered for the 1st time.
b.func_first_executable_line = frame.f_lineno
if b.func_first_executable_line != frame.f_lineno:
# But we are not at the first line number: don't break.
return False
return True
# Determines if there is an effective (active) breakpoint at this
# line of code. Returns breakpoint number or 0 if none
def effective(file, line, frame):
"""Determine which breakpoint for this file:line is to be acted upon.
Called only if we know there is a bpt at this
location. Returns breakpoint that was triggered and a flag
that indicates if it is ok to delete a temporary bp.
"""
possibles = Breakpoint.bplist[file,line]
for i in range(0, len(possibles)):
b = possibles[i]
if b.enabled == 0:
continue
if not checkfuncname(b, frame):
continue
# Count every hit when bp is enabled
b.hits = b.hits + 1
if not b.cond:
# If unconditional, and ignoring,
# go on to next, else break
if b.ignore > 0:
b.ignore = b.ignore -1
continue
else:
# breakpoint and marker that's ok
# to delete if temporary
return (b,1)
else:
# Conditional bp.
# Ignore count applies only to those bpt hits where the
# condition evaluates to true.
try:
val = eval(b.cond, frame.f_globals,
frame.f_locals)
if val:
if b.ignore > 0:
b.ignore = b.ignore -1
# continue
else:
return (b,1)
# else:
# continue
except:
# if eval fails, most conservative
# thing is to stop on breakpoint
# regardless of ignore count.
# Don't delete temporary,
# as another hint to user.
return (b,0)
return (None, None)
# -------------------- testing --------------------
class Tdb(Bdb):
def user_call(self, frame, args):
name = frame.f_code.co_name
if not name: name = '???'
print '+++ call', name, args
def user_line(self, frame):
import linecache
name = frame.f_code.co_name
if not name: name = '???'
fn = self.canonic(frame.f_code.co_filename)
line = linecache.getline(fn, frame.f_lineno, frame.f_globals)
print '+++', fn, frame.f_lineno, name, ':', line.strip()
def user_return(self, frame, retval):
print '+++ return', retval
def user_exception(self, frame, exc_stuff):
print '+++ exception', exc_stuff
self.set_continue()
def foo(n):
print 'foo(', n, ')'
x = bar(n*10)
print 'bar returned', x
def bar(a):
print 'bar(', a, ')'
return a/2
def test():
t = Tdb()
t.run('import bdb; bdb.foo(10)')
# end
| apache-2.0 | [
624,
31521,
5678,
83,
624,
199,
199,
646,
15951,
199,
646,
984,
199,
646,
747,
199,
646,
2943,
199,
199,
363,
452,
363,
275,
2097,
34,
697,
24145,
2266,
34,
697,
2266,
28944,
937,
199,
199,
533,
699,
697,
24145,
8,
1726,
304,
272,
408,
1726,
370,
8120,
1536,
14793,
624,
421,
199,
533,
699,
697,
26,
339,
408,
9417,
2018,
14958,
1300,
1021,
14,
339,
961,
1021,
6181,
10296,
402,
2436,
402,
314,
3307,
21395,
27,
272,
282,
7131,
1021,
1077,
5669,
922,
18752,
14,
272,
710,
4465,
14958,
1021,
334,
10511,
14,
21427,
9,
365,
376,
2893,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3372,
29,
403,
304,
267,
291,
14,
2759,
275,
663,
8,
2759,
9,
340,
3372,
587,
488,
267,
291,
14,
18566,
275,
1052,
267,
291,
14,
2324,
1637,
275,
1052,
267,
291,
14,
1943,
63,
24112,
275,
488,
339,
347,
883,
12732,
8,
277,
12,
1788,
304,
267,
340,
1788,
508,
3886,
2,
435,
1788,
59,
17,
6809,
17,
61,
435,
25366,
288,
372,
1788,
267,
883,
12732,
275,
291,
14,
2324,
1637,
14,
362,
8,
1501,
9,
267,
340,
440,
883,
12732,
26,
288,
883,
12732,
275,
747,
14,
515,
14,
4832,
8,
1501,
9,
288,
883,
12732,
275,
747,
14,
515,
14,
21288,
8,
2425,
12732,
9,
288,
291,
14,
2324,
1637,
59,
1501,
61,
275,
883,
12732,
267,
372,
883,
12732,
339,
347,
5305,
8,
277,
304,
267,
492,
26026,
267,
26026,
14,
1074,
1637,
342,
267,
291,
14,
3018,
1943,
275,
488,
267,
291,
423,
409,
63,
2379,
815,
8,
403,
12,
488,
9,
339,
347,
3307,
63,
6052,
8,
277,
12,
2787,
12,
1566,
12,
1680,
304,
267,
340,
291,
14,
10589,
1337,
26,
288,
372,
327,
488,
267,
340,
1566,
508,
283,
604,
356,
288,
372,
291,
14,
6052,
63,
604,
8,
1943,
9,
267,
340,
1566,
508,
283,
1250,
356,
288,
372,
291,
14,
6052,
63,
1250,
8,
1943,
12,
1680,
9,
267,
340,
1566,
508,
283,
1107,
356,
288,
372,
291,
14,
6052,
63,
1107,
8,
1943,
12,
1680,
9,
267,
340,
1566,
508,
283,
1971,
356,
288,
372,
291,
14,
6052,
63,
1971,
8,
1943,
12,
1680,
9,
267,
340,
1566,
508,
283,
67,
63,
1250,
356,
288,
372,
291,
14,
3446,
63,
6052,
267,
340,
1566,
508,
283,
67,
63,
1971,
356,
288,
372,
291,
14,
3446,
63,
6052,
267,
340,
1566,
508,
283,
67,
63,
1107,
356,
288,
372,
291,
14,
3446,
63,
6052,
267,
870,
283,
27178,
14,
34,
697,
14,
6052,
26,
5809,
10201,
1566,
6536,
4700,
8,
1430,
9,
267,
372,
291,
14,
3446,
63,
6052,
339,
347,
7634,
63,
604,
8,
277,
12,
2787,
304,
267,
340,
291,
14,
2379,
63,
1681,
8,
1943,
9,
503,
291,
14,
4785,
63,
1681,
8,
1943,
304,
288,
291,
14,
751,
63,
604,
8,
1943,
9,
288,
340,
291,
14,
10589,
1337,
26,
746,
699,
697,
24145,
267,
372,
291,
14,
3446,
63,
6052,
339,
347,
7634,
63,
1250,
8,
277,
12,
2787,
12,
1680,
304,
267,
327,
5787,
283,
1273,
7,
365,
949,
8088,
1202,
267,
340,
291,
14,
3018,
1943,
365,
488,
26,
288,
327,
7758,
1240,
402,
7634,
3967,
5305,
342,
288,
291,
14,
3018,
1943,
275,
2787,
14,
70,
63,
894,
327,
334,
1028,
9,
3390,
626,
642,
1443,
2597,
506,
488,
1,
288,
372,
291,
14,
3446,
63,
6052,
267,
340,
440,
334,
277,
14,
2379,
63,
1681,
8,
1943,
9,
503,
291,
14,
4785,
63,
1629,
4509,
8,
1943,
2298,
288,
327,
3091,
1929,
370,
3307,
642,
805,
288,
372,
327,
488,
267,
291,
14,
751,
63,
1250,
8,
1943,
12,
1680,
9,
267,
340,
291,
14,
10589,
1337,
26,
746,
699,
697,
24145,
267,
372,
291,
14,
3446,
63,
6052,
339,
347,
7634,
63,
1107,
8,
277,
12,
2787,
12,
1680,
304,
267,
340,
291,
14,
2379,
63,
1681,
8,
1943,
9,
503,
2787,
508,
291,
14,
1107,
1943,
26,
288,
862,
26,
355,
291,
14,
1943,
63,
24112,
275,
2787,
355,
291,
14,
751,
63,
1107,
8,
1943,
12,
1680,
9,
288,
3753,
26,
355,
291,
14,
1943,
63,
24112,
275,
488,
288,
340,
291,
14,
10589,
1337,
26,
746,
699,
697,
24145,
267,
372,
291,
14,
3446,
63,
6052,
339,
347,
7634,
63,
1971,
8,
277,
12,
2787,
12,
1680,
304,
267,
340,
291,
14,
2379,
63,
1681,
8,
1943,
304,
288,
291,
14,
751,
63,
1971,
8,
1943,
12,
1680,
9,
288,
340,
291,
14,
10589,
1337,
26,
746,
699,
697,
24145,
267,
372,
291,
14,
3446,
63,
6052,
339,
327,
24573,
7131,
3992,
2793,
1133,
4278,
314,
2569,
272,
327,
3102,
12,
1325,
2985,
1443,
340,
2985,
2934,
370,
295,
4640,
314,
272,
327,
5492,
402,
23599,
436,
28906,
14,
339,
347,
365,
63,
11962,
63,
578,
8,
277,
12,
859,
63,
354,
304,
267,
367,
3851,
315,
291,
14,
2759,
26,
288,
340,
15951,
14,
15359,
8,
578,
63,
354,
12,
3851,
304,
355,
372,
715,
267,
372,
756,
339,
347,
3631,
63,
1681,
8,
277,
12,
2787,
304,
267,
327,
334,
1028,
9,
3631,
1943,
1443,
3063,
2597,
506,
488,
12,
1937,
7634,
63,
1250,
14,
267,
327,
334,
1028,
9,
314,
26610,
511,
367,
488,
365,
16119,
4829,
687,
2348,
14,
267,
340,
291,
14,
2759,
436,
971,
2049,
291,
14,
374,
63,
11962,
63,
578,
8,
1943,
14,
70,
63,
8473,
14,
362,
10714,
354,
363,
8109,
288,
372,
756,
267,
340,
2787,
365,
291,
14,
2379,
1943,
26,
288,
340,
291,
14,
2379,
3469,
508,
446,
17,
26,
355,
372,
756,
288,
372,
2787,
14,
70,
63,
3469,
2356,
291,
14,
2379,
3469,
267,
1830,
2787,
365,
440,
488,
436,
2787,
365,
440,
291,
14,
2379,
1943,
26,
288,
340,
2787,
365,
291,
14,
3018,
1943,
26,
355,
372,
715,
288,
2787,
275,
2787,
14,
70,
63,
894,
267,
372,
756,
339,
347,
2059,
63,
1681,
8,
277,
12,
2787,
304,
267,
1788,
275,
291,
14,
2425,
12732,
8,
1943,
14,
70,
63,
600,
14,
331,
63,
1501,
9,
267,
340,
440,
1788,
315,
291,
14,
18566,
26,
288,
372,
756,
267,
5874,
275,
2787,
14,
70
] | [
31521,
5678,
83,
624,
199,
199,
646,
15951,
199,
646,
984,
199,
646,
747,
199,
646,
2943,
199,
199,
363,
452,
363,
275,
2097,
34,
697,
24145,
2266,
34,
697,
2266,
28944,
937,
199,
199,
533,
699,
697,
24145,
8,
1726,
304,
272,
408,
1726,
370,
8120,
1536,
14793,
624,
421,
199,
533,
699,
697,
26,
339,
408,
9417,
2018,
14958,
1300,
1021,
14,
339,
961,
1021,
6181,
10296,
402,
2436,
402,
314,
3307,
21395,
27,
272,
282,
7131,
1021,
1077,
5669,
922,
18752,
14,
272,
710,
4465,
14958,
1021,
334,
10511,
14,
21427,
9,
365,
376,
2893,
14,
272,
408,
339,
347,
636,
826,
721,
277,
12,
3372,
29,
403,
304,
267,
291,
14,
2759,
275,
663,
8,
2759,
9,
340,
3372,
587,
488,
267,
291,
14,
18566,
275,
1052,
267,
291,
14,
2324,
1637,
275,
1052,
267,
291,
14,
1943,
63,
24112,
275,
488,
339,
347,
883,
12732,
8,
277,
12,
1788,
304,
267,
340,
1788,
508,
3886,
2,
435,
1788,
59,
17,
6809,
17,
61,
435,
25366,
288,
372,
1788,
267,
883,
12732,
275,
291,
14,
2324,
1637,
14,
362,
8,
1501,
9,
267,
340,
440,
883,
12732,
26,
288,
883,
12732,
275,
747,
14,
515,
14,
4832,
8,
1501,
9,
288,
883,
12732,
275,
747,
14,
515,
14,
21288,
8,
2425,
12732,
9,
288,
291,
14,
2324,
1637,
59,
1501,
61,
275,
883,
12732,
267,
372,
883,
12732,
339,
347,
5305,
8,
277,
304,
267,
492,
26026,
267,
26026,
14,
1074,
1637,
342,
267,
291,
14,
3018,
1943,
275,
488,
267,
291,
423,
409,
63,
2379,
815,
8,
403,
12,
488,
9,
339,
347,
3307,
63,
6052,
8,
277,
12,
2787,
12,
1566,
12,
1680,
304,
267,
340,
291,
14,
10589,
1337,
26,
288,
372,
327,
488,
267,
340,
1566,
508,
283,
604,
356,
288,
372,
291,
14,
6052,
63,
604,
8,
1943,
9,
267,
340,
1566,
508,
283,
1250,
356,
288,
372,
291,
14,
6052,
63,
1250,
8,
1943,
12,
1680,
9,
267,
340,
1566,
508,
283,
1107,
356,
288,
372,
291,
14,
6052,
63,
1107,
8,
1943,
12,
1680,
9,
267,
340,
1566,
508,
283,
1971,
356,
288,
372,
291,
14,
6052,
63,
1971,
8,
1943,
12,
1680,
9,
267,
340,
1566,
508,
283,
67,
63,
1250,
356,
288,
372,
291,
14,
3446,
63,
6052,
267,
340,
1566,
508,
283,
67,
63,
1971,
356,
288,
372,
291,
14,
3446,
63,
6052,
267,
340,
1566,
508,
283,
67,
63,
1107,
356,
288,
372,
291,
14,
3446,
63,
6052,
267,
870,
283,
27178,
14,
34,
697,
14,
6052,
26,
5809,
10201,
1566,
6536,
4700,
8,
1430,
9,
267,
372,
291,
14,
3446,
63,
6052,
339,
347,
7634,
63,
604,
8,
277,
12,
2787,
304,
267,
340,
291,
14,
2379,
63,
1681,
8,
1943,
9,
503,
291,
14,
4785,
63,
1681,
8,
1943,
304,
288,
291,
14,
751,
63,
604,
8,
1943,
9,
288,
340,
291,
14,
10589,
1337,
26,
746,
699,
697,
24145,
267,
372,
291,
14,
3446,
63,
6052,
339,
347,
7634,
63,
1250,
8,
277,
12,
2787,
12,
1680,
304,
267,
327,
5787,
283,
1273,
7,
365,
949,
8088,
1202,
267,
340,
291,
14,
3018,
1943,
365,
488,
26,
288,
327,
7758,
1240,
402,
7634,
3967,
5305,
342,
288,
291,
14,
3018,
1943,
275,
2787,
14,
70,
63,
894,
327,
334,
1028,
9,
3390,
626,
642,
1443,
2597,
506,
488,
1,
288,
372,
291,
14,
3446,
63,
6052,
267,
340,
440,
334,
277,
14,
2379,
63,
1681,
8,
1943,
9,
503,
291,
14,
4785,
63,
1629,
4509,
8,
1943,
2298,
288,
327,
3091,
1929,
370,
3307,
642,
805,
288,
372,
327,
488,
267,
291,
14,
751,
63,
1250,
8,
1943,
12,
1680,
9,
267,
340,
291,
14,
10589,
1337,
26,
746,
699,
697,
24145,
267,
372,
291,
14,
3446,
63,
6052,
339,
347,
7634,
63,
1107,
8,
277,
12,
2787,
12,
1680,
304,
267,
340,
291,
14,
2379,
63,
1681,
8,
1943,
9,
503,
2787,
508,
291,
14,
1107,
1943,
26,
288,
862,
26,
355,
291,
14,
1943,
63,
24112,
275,
2787,
355,
291,
14,
751,
63,
1107,
8,
1943,
12,
1680,
9,
288,
3753,
26,
355,
291,
14,
1943,
63,
24112,
275,
488,
288,
340,
291,
14,
10589,
1337,
26,
746,
699,
697,
24145,
267,
372,
291,
14,
3446,
63,
6052,
339,
347,
7634,
63,
1971,
8,
277,
12,
2787,
12,
1680,
304,
267,
340,
291,
14,
2379,
63,
1681,
8,
1943,
304,
288,
291,
14,
751,
63,
1971,
8,
1943,
12,
1680,
9,
288,
340,
291,
14,
10589,
1337,
26,
746,
699,
697,
24145,
267,
372,
291,
14,
3446,
63,
6052,
339,
327,
24573,
7131,
3992,
2793,
1133,
4278,
314,
2569,
272,
327,
3102,
12,
1325,
2985,
1443,
340,
2985,
2934,
370,
295,
4640,
314,
272,
327,
5492,
402,
23599,
436,
28906,
14,
339,
347,
365,
63,
11962,
63,
578,
8,
277,
12,
859,
63,
354,
304,
267,
367,
3851,
315,
291,
14,
2759,
26,
288,
340,
15951,
14,
15359,
8,
578,
63,
354,
12,
3851,
304,
355,
372,
715,
267,
372,
756,
339,
347,
3631,
63,
1681,
8,
277,
12,
2787,
304,
267,
327,
334,
1028,
9,
3631,
1943,
1443,
3063,
2597,
506,
488,
12,
1937,
7634,
63,
1250,
14,
267,
327,
334,
1028,
9,
314,
26610,
511,
367,
488,
365,
16119,
4829,
687,
2348,
14,
267,
340,
291,
14,
2759,
436,
971,
2049,
291,
14,
374,
63,
11962,
63,
578,
8,
1943,
14,
70,
63,
8473,
14,
362,
10714,
354,
363,
8109,
288,
372,
756,
267,
340,
2787,
365,
291,
14,
2379,
1943,
26,
288,
340,
291,
14,
2379,
3469,
508,
446,
17,
26,
355,
372,
756,
288,
372,
2787,
14,
70,
63,
3469,
2356,
291,
14,
2379,
3469,
267,
1830,
2787,
365,
440,
488,
436,
2787,
365,
440,
291,
14,
2379,
1943,
26,
288,
340,
2787,
365,
291,
14,
3018,
1943,
26,
355,
372,
715,
288,
2787,
275,
2787,
14,
70,
63,
894,
267,
372,
756,
339,
347,
2059,
63,
1681,
8,
277,
12,
2787,
304,
267,
1788,
275,
291,
14,
2425,
12732,
8,
1943,
14,
70,
63,
600,
14,
331,
63,
1501,
9,
267,
340,
440,
1788,
315,
291,
14,
18566,
26,
288,
372,
756,
267,
5874,
275,
2787,
14,
70,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
XtheOne/Inverter-Data-Logger | InverterLib.py | 1 | 3301 | import socket
import struct
import os
import binascii
import sys
if sys.version[0] == '2':
reload(sys)
sys.setdefaultencoding('cp437')
def getNetworkIp():
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
s.connect(('<broadcast>', 0))
return s.getsockname()[0]
def createV4RequestFrame(logger_sn):
"""Create request frame for inverter logger.
The request string is build from several parts. The first part is a
fixed 4 char string; the second part is the reversed hex notation of
the s/n twice; then again a fixed string of two chars; a checksum of
the double s/n with an offset; and finally a fixed ending char.
Args:
logger_sn (int): Serial number of the inverter
Returns:
str: Information request string for inverter
"""
#frame = (headCode) + (dataFieldLength) + (contrlCode) + (sn) + (sn) + (command) + (checksum) + (endCode)
frame_hdr = binascii.unhexlify('680241b1') #from SolarMan / new Omnik app
command = binascii.unhexlify('0100')
defchk = binascii.unhexlify('87')
endCode = binascii.unhexlify('16')
tar = bytearray.fromhex(hex(logger_sn)[8:10] + hex(logger_sn)[6:8] + hex(logger_sn)[4:6] + hex(logger_sn)[2:4])
frame = bytearray(frame_hdr + tar + tar + command + defchk + endCode)
checksum = 0
frame_bytes = bytearray(frame)
for i in range(1, len(frame_bytes) - 2, 1):
checksum += frame_bytes[i] & 255
frame_bytes[len(frame_bytes) - 2] = int((checksum & 255))
return bytearray(frame_bytes)
def expand_path(path):
"""
Expand relative path to absolute path.
Args:
path: file path
Returns: absolute path to file
"""
if os.path.isabs(path):
return path
else:
return os.path.dirname(os.path.abspath(__file__)) + "/" + path
def getLoggers():
# Create the datagram socket
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.bind((getNetworkIp(), 48899))
# Set a timeout so the socket does not block indefinitely when trying to receive data.
sock.settimeout(3)
# Set the time-to-live for messages to 1 so they do not go past the local network segment.
ttl = struct.pack('b', 1)
sock.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, ttl)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
SendData = "WIFIKIT-214028-READ" # Lotto/TM = "AT+YZAPP=214028,READ"
gateways = ''
try:
# Send data to the broadcast address
sent = sock.sendto(SendData, ('<broadcast>', 48899))
# Look for responses from all recipients
while True:
try:
data, server = sock.recvfrom(1024)
except socket.timeout:
break
else:
if (data == SendData): continue #skip sent data
a = data.split(',')
wifi_ip, wifi_mac, wifi_sn = a[0],a[1],a[2]
if (len(gateways)>1):
gateways = gateways+','
gateways = gateways+wifi_ip+','+wifi_sn
finally:
sock.close()
return gateways
| gpl-3.0 | [
646,
2838,
199,
646,
2702,
199,
646,
747,
199,
646,
14755,
199,
646,
984,
199,
199,
692,
984,
14,
1023,
59,
16,
61,
508,
283,
18,
356,
272,
13101,
8,
1274,
9,
272,
984,
14,
409,
27205,
28139,
360,
1850,
21717,
358,
199,
199,
318,
664,
4491,
6583,
837,
272,
308,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
9,
272,
308,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
907,
4701,
7803,
12,
413,
9,
272,
308,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
21111,
32215,
12,
413,
9,
272,
308,
14,
2242,
4725,
28,
10786,
4206,
378,
430,
272,
372,
308,
14,
27886,
3430,
16,
61,
199,
199,
318,
1218,
54,
20,
2017,
3160,
8,
2921,
63,
5167,
304,
272,
408,
2499,
1056,
2787,
367,
315,
422,
351,
2512,
14,
339,
710,
1056,
1059,
365,
1900,
687,
9978,
4184,
14,
710,
1642,
1777,
365,
282,
272,
6317,
841,
1495,
1059,
27,
314,
3499,
1777,
365,
314,
10822,
6318,
15843,
402,
272,
314,
308,
15,
78,
13373,
27,
2066,
4020,
282,
6317,
1059,
402,
2877,
8365,
27,
282,
9040,
402,
272,
314,
4270,
308,
15,
78,
543,
376,
3268,
27,
436,
3753,
282,
6317,
13401,
1495,
14,
339,
3033,
26,
267,
2512,
63,
5167,
334,
442,
304,
11973,
1329,
402,
314,
315,
422,
351,
339,
1803,
26,
267,
620,
26,
17064,
1056,
1059,
367,
315,
422,
351,
272,
408,
272,
327,
1943,
275,
334,
2993,
3034,
9,
435,
334,
576,
792,
4625,
9,
435,
334,
388,
7245,
3034,
9,
435,
334,
5167,
9,
435,
334,
5167,
9,
435,
334,
1531,
9,
435,
334,
8928,
9,
435,
334,
500,
3034,
9,
272,
2787,
63,
11244,
275,
14755,
14,
324,
20677,
360,
2333,
996,
2953,
66,
17,
358,
327,
504,
17991,
285,
2395,
1182,
892,
593,
10344,
3258,
1145,
272,
1414,
275,
14755,
14,
324,
20677,
360,
16569,
358,
272,
347,
14823,
275,
14755,
14,
324,
20677,
360,
1555,
358,
272,
1284,
3034,
275,
14755,
14,
324,
20677,
360,
975,
358,
339,
5330,
275,
11640,
14,
504,
4097,
8,
4097,
8,
2921,
63,
5167,
2788,
24,
26,
709,
61,
435,
6318,
8,
2921,
63,
5167,
2788,
22,
26,
24,
61,
435,
6318,
8,
2921,
63,
5167,
2788,
20,
26,
22,
61,
435,
6318,
8,
2921,
63,
5167,
2788,
18,
26,
20,
566,
272,
2787,
275,
11640,
8,
1943,
63,
11244,
435,
5330,
435,
5330,
435,
1414,
435,
347,
14823,
435,
1284,
3034,
9,
339,
9040,
275,
378,
272,
2787,
63,
2394,
275,
11640,
8,
1943,
9,
272,
367,
284,
315,
1425,
8,
17,
12,
822,
8,
1943,
63,
2394,
9,
446,
499,
12,
413,
304,
267,
9040,
847,
2787,
63,
2394,
59,
73,
61,
1253,
5450,
272,
2787,
63,
2394,
59,
552,
8,
1943,
63,
2394,
9,
446,
499,
61,
275,
1109,
1332,
8928,
1253,
5450,
430,
272,
372,
11640,
8,
1943,
63,
2394,
9,
199,
199,
318,
6544,
63,
515,
8,
515,
304,
272,
408,
272,
18890,
3847,
931,
370,
3679,
931,
14,
339,
3033,
26,
267,
931,
26,
570,
931,
339,
1803,
26,
3679,
931,
370,
570,
339,
408,
272,
340,
747,
14,
515,
14,
17896,
8,
515,
304,
267,
372,
931,
272,
587,
26,
267,
372,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
435,
10609,
435,
931,
199,
199,
318,
28138,
83,
837,
272,
327,
2790,
314,
666,
1679,
2838,
272,
6771,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
9,
272,
6771,
14,
3409,
1332,
362,
4491,
6583,
1062,
841,
1299,
1020,
430,
272,
327,
2494,
282,
2653,
880,
314,
2838,
1630,
440,
1853,
315,
23442,
590,
1380,
9936,
370,
9128,
666,
14,
272,
6771,
14,
24630,
8,
19,
9,
272,
327,
2494,
314,
900,
13,
475,
13,
6442,
367,
3788,
370,
413,
880,
2985,
886,
440,
2621,
13541,
314,
2257,
2784,
8135,
14,
272,
14856,
275,
2702,
14,
1389,
360,
66,
297,
413,
9,
272,
6771,
14,
27689,
8,
3450,
14,
20130,
63,
1772,
12,
2838,
14,
1772,
63,
8203,
948,
11307,
63,
25567,
12,
14856,
9,
272,
6771,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
907,
4701,
7803,
12,
413,
9,
272,
6771,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
21111,
32215,
12,
413,
9,
272,
10217,
1451,
275,
298,
24696,
43,
649,
13,
6886,
15501,
13,
5670,
2,
327,
491,
357,
475,
15,
20690,
275,
298,
619,
11,
26184,
7121,
29,
6886,
15501,
12,
5670,
2,
339,
17036,
2885,
275,
2125,
272,
862,
26,
267,
327,
10217,
666,
370,
314,
11180,
2287,
267,
4847,
275,
6771,
14,
23267,
8,
6795,
1451,
12,
19990,
10786,
4206,
841,
1299,
1020,
430,
267,
327,
12077,
367,
9320,
687,
1006,
19255,
267,
1830,
715,
26,
288,
862,
26,
355,
666,
12,
1654,
275,
6771,
14,
7637,
504,
8,
7727,
9,
288,
871,
2838,
14,
2593,
26,
355,
2059,
288,
587,
26,
355,
340,
334,
576,
508,
10217,
1451,
304,
1980,
327,
2759,
4847,
666,
355,
282,
275,
666,
14,
1294,
11917,
355,
7912,
63,
711,
12,
7912,
63,
3088,
12,
7912,
63,
5167,
275,
282,
59,
16,
467,
65,
59,
17,
467,
65,
59,
18,
61,
355,
340,
334,
552,
8,
3237,
2885,
13032,
17,
304,
490,
17036,
2885,
275,
17036,
2885,
11,
1673,
355,
17036,
2885,
275,
17036,
2885,
11,
4326,
63,
711,
11,
1673,
11,
4326,
63,
5167,
339,
3753,
26,
267,
6771,
14,
1600,
342,
267,
372,
17036,
2885,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
2838,
199,
646,
2702,
199,
646,
747,
199,
646,
14755,
199,
646,
984,
199,
199,
692,
984,
14,
1023,
59,
16,
61,
508,
283,
18,
356,
272,
13101,
8,
1274,
9,
272,
984,
14,
409,
27205,
28139,
360,
1850,
21717,
358,
199,
199,
318,
664,
4491,
6583,
837,
272,
308,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
9,
272,
308,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
907,
4701,
7803,
12,
413,
9,
272,
308,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
21111,
32215,
12,
413,
9,
272,
308,
14,
2242,
4725,
28,
10786,
4206,
378,
430,
272,
372,
308,
14,
27886,
3430,
16,
61,
199,
199,
318,
1218,
54,
20,
2017,
3160,
8,
2921,
63,
5167,
304,
272,
408,
2499,
1056,
2787,
367,
315,
422,
351,
2512,
14,
339,
710,
1056,
1059,
365,
1900,
687,
9978,
4184,
14,
710,
1642,
1777,
365,
282,
272,
6317,
841,
1495,
1059,
27,
314,
3499,
1777,
365,
314,
10822,
6318,
15843,
402,
272,
314,
308,
15,
78,
13373,
27,
2066,
4020,
282,
6317,
1059,
402,
2877,
8365,
27,
282,
9040,
402,
272,
314,
4270,
308,
15,
78,
543,
376,
3268,
27,
436,
3753,
282,
6317,
13401,
1495,
14,
339,
3033,
26,
267,
2512,
63,
5167,
334,
442,
304,
11973,
1329,
402,
314,
315,
422,
351,
339,
1803,
26,
267,
620,
26,
17064,
1056,
1059,
367,
315,
422,
351,
272,
408,
272,
327,
1943,
275,
334,
2993,
3034,
9,
435,
334,
576,
792,
4625,
9,
435,
334,
388,
7245,
3034,
9,
435,
334,
5167,
9,
435,
334,
5167,
9,
435,
334,
1531,
9,
435,
334,
8928,
9,
435,
334,
500,
3034,
9,
272,
2787,
63,
11244,
275,
14755,
14,
324,
20677,
360,
2333,
996,
2953,
66,
17,
358,
327,
504,
17991,
285,
2395,
1182,
892,
593,
10344,
3258,
1145,
272,
1414,
275,
14755,
14,
324,
20677,
360,
16569,
358,
272,
347,
14823,
275,
14755,
14,
324,
20677,
360,
1555,
358,
272,
1284,
3034,
275,
14755,
14,
324,
20677,
360,
975,
358,
339,
5330,
275,
11640,
14,
504,
4097,
8,
4097,
8,
2921,
63,
5167,
2788,
24,
26,
709,
61,
435,
6318,
8,
2921,
63,
5167,
2788,
22,
26,
24,
61,
435,
6318,
8,
2921,
63,
5167,
2788,
20,
26,
22,
61,
435,
6318,
8,
2921,
63,
5167,
2788,
18,
26,
20,
566,
272,
2787,
275,
11640,
8,
1943,
63,
11244,
435,
5330,
435,
5330,
435,
1414,
435,
347,
14823,
435,
1284,
3034,
9,
339,
9040,
275,
378,
272,
2787,
63,
2394,
275,
11640,
8,
1943,
9,
272,
367,
284,
315,
1425,
8,
17,
12,
822,
8,
1943,
63,
2394,
9,
446,
499,
12,
413,
304,
267,
9040,
847,
2787,
63,
2394,
59,
73,
61,
1253,
5450,
272,
2787,
63,
2394,
59,
552,
8,
1943,
63,
2394,
9,
446,
499,
61,
275,
1109,
1332,
8928,
1253,
5450,
430,
272,
372,
11640,
8,
1943,
63,
2394,
9,
199,
199,
318,
6544,
63,
515,
8,
515,
304,
272,
408,
272,
18890,
3847,
931,
370,
3679,
931,
14,
339,
3033,
26,
267,
931,
26,
570,
931,
339,
1803,
26,
3679,
931,
370,
570,
339,
408,
272,
340,
747,
14,
515,
14,
17896,
8,
515,
304,
267,
372,
931,
272,
587,
26,
267,
372,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
435,
10609,
435,
931,
199,
199,
318,
28138,
83,
837,
272,
327,
2790,
314,
666,
1679,
2838,
272,
6771,
275,
2838,
14,
3450,
8,
3450,
14,
5699,
63,
11367,
12,
2838,
14,
9469,
63,
25351,
9,
272,
6771,
14,
3409,
1332,
362,
4491,
6583,
1062,
841,
1299,
1020,
430,
272,
327,
2494,
282,
2653,
880,
314,
2838,
1630,
440,
1853,
315,
23442,
590,
1380,
9936,
370,
9128,
666,
14,
272,
6771,
14,
24630,
8,
19,
9,
272,
327,
2494,
314,
900,
13,
475,
13,
6442,
367,
3788,
370,
413,
880,
2985,
886,
440,
2621,
13541,
314,
2257,
2784,
8135,
14,
272,
14856,
275,
2702,
14,
1389,
360,
66,
297,
413,
9,
272,
6771,
14,
27689,
8,
3450,
14,
20130,
63,
1772,
12,
2838,
14,
1772,
63,
8203,
948,
11307,
63,
25567,
12,
14856,
9,
272,
6771,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
907,
4701,
7803,
12,
413,
9,
272,
6771,
14,
27689,
8,
3450,
14,
15096,
63,
17462,
12,
2838,
14,
4118,
63,
21111,
32215,
12,
413,
9,
272,
10217,
1451,
275,
298,
24696,
43,
649,
13,
6886,
15501,
13,
5670,
2,
327,
491,
357,
475,
15,
20690,
275,
298,
619,
11,
26184,
7121,
29,
6886,
15501,
12,
5670,
2,
339,
17036,
2885,
275,
2125,
272,
862,
26,
267,
327,
10217,
666,
370,
314,
11180,
2287,
267,
4847,
275,
6771,
14,
23267,
8,
6795,
1451,
12,
19990,
10786,
4206,
841,
1299,
1020,
430,
267,
327,
12077,
367,
9320,
687,
1006,
19255,
267,
1830,
715,
26,
288,
862,
26,
355,
666,
12,
1654,
275,
6771,
14,
7637,
504,
8,
7727,
9,
288,
871,
2838,
14,
2593,
26,
355,
2059,
288,
587,
26,
355,
340,
334,
576,
508,
10217,
1451,
304,
1980,
327,
2759,
4847,
666,
355,
282,
275,
666,
14,
1294,
11917,
355,
7912,
63,
711,
12,
7912,
63,
3088,
12,
7912,
63,
5167,
275,
282,
59,
16,
467,
65,
59,
17,
467,
65,
59,
18,
61,
355,
340,
334,
552,
8,
3237,
2885,
13032,
17,
304,
490,
17036,
2885,
275,
17036,
2885,
11,
1673,
355,
17036,
2885,
275,
17036,
2885,
11,
4326,
63,
711,
11,
1673,
11,
4326,
63,
5167,
339,
3753,
26,
267,
6771,
14,
1600,
342,
267,
372,
17036,
2885,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
sigrokproject/libsigrokdecode | decoders/swd/__init__.py | 6 | 1212 | ##
## This file is part of the libsigrokdecode project.
##
## Copyright (C) 2014 Angus Gratton <[email protected]>
##
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, see <http://www.gnu.org/licenses/>.
##
'''
This PD decodes the ARM SWD (version 1) protocol, as described in the
"ARM Debug Interface v5.2" Architecture Specification.
Not supported:
* Turnaround periods other than the default 1, as set in DLCR.TURNROUND
(should be trivial to add)
* SWD protocol version 2 (multi-drop support, etc.)
Details:
http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ihi0031c/index.html
(Registration required)
'''
from .pd import Decoder
| gpl-3.0 | [
309,
199,
309,
961,
570,
365,
1777,
402,
314,
1973,
4093,
29275,
2708,
2199,
14,
199,
309,
199,
309,
1898,
334,
35,
9,
6927,
1626,
17360,
598,
17565,
1860,
665,
17360,
32,
1715,
17360,
14,
957,
30,
199,
309,
199,
309,
961,
2240,
365,
2867,
2032,
27,
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,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
309,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
961,
2240,
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,
642,
2240,
27,
340,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
309,
199,
199,
2344,
199,
2765,
510,
36,
4849,
83,
314,
27155,
428,
16698,
334,
1023,
413,
9,
4113,
12,
465,
11736,
315,
314,
199,
2,
12482,
14245,
14816,
373,
21,
14,
18,
2,
19521,
10497,
5367,
3477,
14,
199,
199,
1763,
3748,
26,
199,
627,
16147,
11659,
17382,
1163,
2419,
314,
849,
413,
12,
465,
663,
315,
577,
44,
2944,
14,
52,
7648,
16848,
2043,
334,
5626,
506,
28586,
370,
1050,
9,
199,
627,
428,
16698,
4113,
1015,
499,
334,
3029,
13,
4824,
2291,
12,
5423,
4959,
199,
199,
11347,
26,
199,
1014,
921,
815,
4218,
14,
5362,
14,
957,
15,
3437,
15,
1080,
14,
74,
681,
31,
5746,
13043,
957,
14,
5362,
14,
1301,
14,
73,
5812,
383,
2192,
67,
15,
1080,
14,
1360,
199,
8,
11757,
1415,
9,
199,
2344,
199,
199,
504,
1275,
8961,
492,
1487,
2693,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
309,
961,
570,
365,
1777,
402,
314,
1973,
4093,
29275,
2708,
2199,
14,
199,
309,
199,
309,
1898,
334,
35,
9,
6927,
1626,
17360,
598,
17565,
1860,
665,
17360,
32,
1715,
17360,
14,
957,
30,
199,
309,
199,
309,
961,
2240,
365,
2867,
2032,
27,
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,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
309,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
309,
199,
309,
961,
2240,
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,
642,
2240,
27,
340,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
309,
199,
199,
2344,
199,
2765,
510,
36,
4849,
83,
314,
27155,
428,
16698,
334,
1023,
413,
9,
4113,
12,
465,
11736,
315,
314,
199,
2,
12482,
14245,
14816,
373,
21,
14,
18,
2,
19521,
10497,
5367,
3477,
14,
199,
199,
1763,
3748,
26,
199,
627,
16147,
11659,
17382,
1163,
2419,
314,
849,
413,
12,
465,
663,
315,
577,
44,
2944,
14,
52,
7648,
16848,
2043,
334,
5626,
506,
28586,
370,
1050,
9,
199,
627,
428,
16698,
4113,
1015,
499,
334,
3029,
13,
4824,
2291,
12,
5423,
4959,
199,
199,
11347,
26,
199,
1014,
921,
815,
4218,
14,
5362,
14,
957,
15,
3437,
15,
1080,
14,
74,
681,
31,
5746,
13043,
957,
14,
5362,
14,
1301,
14,
73,
5812,
383,
2192,
67,
15,
1080,
14,
1360,
199,
8,
11757,
1415,
9,
199,
2344,
199,
199,
504,
1275,
8961,
492,
1487,
2693,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dstanek/keystone | keystone/common/dependency.py | 10 | 7661 | # Copyright 2012 OpenStack Foundation
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
"""This module provides support for dependency injection.
Providers are registered via the ``@provider()`` decorator, and dependencies on
them are registered with ``@requires()``. Providers are available to their
consumers via an attribute. See the documentation for the individual functions
for more detail.
See also:
https://en.wikipedia.org/wiki/Dependency_injection
"""
import traceback
from keystone.i18n import _
_REGISTRY = {}
_future_dependencies = {}
_factories = {}
def _set_provider(name, provider):
_original_provider, where_registered = _REGISTRY.get(name, (None, None))
if where_registered:
raise Exception('%s already has a registered provider, at\n%s' %
(name, ''.join(where_registered)))
_REGISTRY[name] = (provider, traceback.format_stack())
GET_REQUIRED = object()
GET_OPTIONAL = object()
def get_provider(name, optional=GET_REQUIRED):
if optional is GET_REQUIRED:
return _REGISTRY[name][0]
return _REGISTRY.get(name, (None, None))[0]
class UnresolvableDependencyException(Exception):
"""Raised when a required dependency is not resolvable.
See ``resolve_future_dependencies()`` for more details.
"""
def __init__(self, name, targets):
msg = _('Unregistered dependency: %(name)s for %(targets)s') % {
'name': name, 'targets': targets}
super(UnresolvableDependencyException, self).__init__(msg)
def provider(name):
"""A class decorator used to register providers.
When ``@provider()`` is used to decorate a class, members of that class
will register themselves as providers for the named dependency. As an
example, In the code fragment::
@dependency.provider('foo_api')
class Foo:
def __init__(self):
...
...
foo = Foo()
The object ``foo`` will be registered as a provider for ``foo_api``. No
more than one such instance should be created; additional instances will
replace the previous ones, possibly resulting in different instances being
used by different consumers.
"""
def wrapper(cls):
def wrapped(init):
def __wrapped_init__(self, *args, **kwargs):
"""Initialize the wrapped object and add it to the registry."""
init(self, *args, **kwargs)
_set_provider(name, self)
resolve_future_dependencies(__provider_name=name)
return __wrapped_init__
cls.__init__ = wrapped(cls.__init__)
_factories[name] = cls
return cls
return wrapper
def _process_dependencies(obj):
# Any dependencies that can be resolved immediately are resolved.
# Dependencies that cannot be resolved immediately are stored for
# resolution in resolve_future_dependencies.
def process(obj, attr_name, unresolved_in_out):
for dependency in getattr(obj, attr_name, []):
if dependency not in _REGISTRY:
# We don't know about this dependency, so save it for later.
unresolved_in_out.setdefault(dependency, []).append(obj)
continue
setattr(obj, dependency, get_provider(dependency))
process(obj, '_dependencies', _future_dependencies)
def requires(*dependencies):
"""A class decorator used to inject providers into consumers.
The required providers will be made available to instances of the decorated
class via an attribute with the same name as the provider. For example, in
the code fragment::
@dependency.requires('foo_api', 'bar_api')
class FooBarClient:
def __init__(self):
...
...
client = FooBarClient()
The object ``client`` will have attributes named ``foo_api`` and
``bar_api``, which are instances of the named providers.
Objects must not rely on the existence of these attributes until after
``resolve_future_dependencies()`` has been called; they may not exist
beforehand.
Dependencies registered via ``@required()`` must have providers; if not,
an ``UnresolvableDependencyException`` will be raised when
``resolve_future_dependencies()`` is called.
"""
def wrapper(self, *args, **kwargs):
"""Inject each dependency from the registry."""
self.__wrapped_init__(*args, **kwargs)
_process_dependencies(self)
def wrapped(cls):
"""Note the required dependencies on the object for later injection.
The dependencies of the parent class are combined with that of the
child class to create a new set of dependencies.
"""
existing_dependencies = getattr(cls, '_dependencies', set())
cls._dependencies = existing_dependencies.union(dependencies)
if not hasattr(cls, '__wrapped_init__'):
cls.__wrapped_init__ = cls.__init__
cls.__init__ = wrapper
return cls
return wrapped
def resolve_future_dependencies(__provider_name=None):
"""Forces injection of all dependencies.
Before this function is called, circular dependencies may not have been
injected. This function should be called only once, after all global
providers are registered. If an object needs to be created after this
call, it must not have circular dependencies.
If any required dependencies are unresolvable, this function will raise an
``UnresolvableDependencyException``.
Outside of this module, this function should be called with no arguments;
the optional argument, ``__provider_name`` is used internally, and should
be treated as an implementation detail.
"""
new_providers = dict()
if __provider_name:
# A provider was registered, so take care of any objects depending on
# it.
targets = _future_dependencies.pop(__provider_name, [])
for target in targets:
setattr(target, __provider_name, get_provider(__provider_name))
return
# Resolve future dependencies, raises UnresolvableDependencyException if
# there's no provider registered.
try:
for dependency, targets in _future_dependencies.copy().items():
if dependency not in _REGISTRY:
# a Class was registered that could fulfill the dependency, but
# it has not yet been initialized.
factory = _factories.get(dependency)
if factory:
provider = factory()
new_providers[dependency] = provider
else:
raise UnresolvableDependencyException(dependency, targets)
for target in targets:
setattr(target, dependency, get_provider(dependency))
finally:
_future_dependencies.clear()
return new_providers
def reset():
"""Reset the registry of providers.
This is useful for unit testing to ensure that tests don't use providers
from previous tests.
"""
_REGISTRY.clear()
_future_dependencies.clear()
| apache-2.0 | [
3,
1898,
6029,
14260,
2752,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
624,
2765,
859,
6571,
2291,
367,
5936,
315,
8923,
14,
199,
199,
6663,
83,
787,
7264,
4799,
314,
1124,
32,
3780,
8497,
7531,
12,
436,
5124,
641,
199,
1589,
77,
787,
7264,
543,
1124,
32,
6537,
28566,
18489,
83,
787,
2808,
370,
3932,
199,
10235,
2393,
4799,
376,
2225,
14,
1666,
314,
3794,
367,
314,
8212,
3423,
199,
509,
1655,
10093,
14,
199,
199,
9295,
2597,
26,
339,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
14403,
63,
262,
8923,
199,
199,
624,
199,
199,
646,
5190,
199,
199,
504,
19395,
14,
73,
1085,
78,
492,
485,
421,
199,
63,
25304,
57,
275,
1052,
199,
199,
63,
2443,
63,
5714,
275,
1052,
199,
63,
15406,
275,
1052,
421,
199,
318,
485,
409,
63,
3780,
8,
354,
12,
5022,
304,
272,
485,
5043,
63,
3780,
12,
2382,
63,
11616,
275,
485,
25304,
57,
14,
362,
8,
354,
12,
334,
403,
12,
488,
430,
272,
340,
2382,
63,
11616,
26,
267,
746,
2186,
3508,
83,
2575,
965,
282,
7264,
5022,
12,
737,
60,
78,
5,
83,
7,
450,
717,
334,
354,
12,
6522,
904,
8,
4509,
63,
11616,
1724,
272,
485,
25304,
57,
59,
354,
61,
275,
334,
3780,
12,
5190,
14,
908,
63,
2340,
1012,
421,
199,
2970,
63,
12496,
275,
909,
342,
199,
2970,
63,
21008,
275,
909,
342,
421,
199,
318,
664,
63,
3780,
8,
354,
12,
2716,
29,
2970,
63,
12496,
304,
272,
340,
2716,
365,
9576,
63,
12496,
26,
267,
372,
485,
25304,
57,
59,
354,
1527,
16,
61,
272,
372,
485,
25304,
57,
14,
362,
8,
354,
12,
334,
403,
12,
488,
11515,
16,
61,
421,
199,
533,
1910,
26702,
30456,
14403,
1726,
8,
1726,
304,
272,
408,
16894,
1380,
282,
1415,
5936,
365,
440,
17416,
30456,
14,
339,
1666,
1124,
6983,
63,
2443,
63,
5714,
8497,
367,
1655,
2436,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
536,
12,
4545,
304,
267,
1499,
275,
4018,
1358,
11616,
5936,
26,
2818,
354,
9,
83,
367,
2818,
4684,
9,
83,
358,
450,
469,
288,
283,
354,
356,
536,
12,
283,
4684,
356,
4545,
93,
267,
1613,
8,
1358,
26702,
30456,
14403,
1726,
12,
291,
2843,
826,
721,
1328,
9,
421,
199,
318,
5022,
8,
354,
304,
272,
408,
33,
1021,
7531,
1202,
370,
2274,
18032,
14,
339,
3979,
1124,
32,
3780,
8497,
365,
1202,
370,
24774,
282,
1021,
12,
7556,
402,
626,
1021,
272,
911,
2274,
17279,
465,
18032,
367,
314,
4310,
5936,
14,
3709,
376,
272,
2893,
12,
1010,
314,
1233,
7956,
447,
398,
768,
8575,
14,
3780,
360,
1421,
63,
1246,
358,
267,
1021,
8024,
26,
288,
347,
636,
826,
721,
277,
304,
355,
2263,
953,
2263,
398,
3925,
275,
8024,
342,
339,
710,
909,
1124,
1421,
1040,
911,
506,
7264,
465,
282,
5022,
367,
1124,
1421,
63,
1246,
4345,
3091,
272,
1655,
2419,
1373,
4066,
1256,
1077,
506,
2737,
27,
4722,
4454,
911,
272,
3350,
314,
4136,
7869,
12,
12570,
9183,
315,
3365,
4454,
3769,
272,
1202,
701,
3365,
9451,
2393,
14,
339,
408,
272,
347,
4975,
8,
1886,
304,
267,
347,
8072,
8,
826,
304,
288,
347,
636,
9130,
63,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
355,
408,
9345,
314,
8072,
909,
436,
1050,
652,
370,
314,
7086,
1041,
355,
4205,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
355,
485,
409,
63,
3780,
8,
354,
12,
291,
9,
355,
7512,
63,
2443,
63,
5714,
3460,
3780,
63,
354,
29,
354,
9,
953,
372,
636,
9130,
63,
826,
363,
398,
843,
855,
826,
363,
275,
8072,
8,
1886,
855,
826,
3368,
267,
485,
15406,
59,
354,
61,
275,
843,
267,
372,
843,
272,
372,
4975,
421,
199,
318,
485,
1412,
63,
5714,
8,
1113,
304,
272,
327,
6184,
5124,
626,
883,
506,
12152,
9939,
787,
12152,
14,
272,
327,
1487,
3209,
626,
3913,
506,
12152,
9939,
787,
5489,
367,
272,
327,
12401,
315,
7512,
63,
2443,
63,
5714,
14,
339,
347,
2112,
8,
1113,
12,
1921,
63,
354,
12,
625,
13697,
63,
262,
63,
548,
304,
267,
367,
5936,
315,
2519,
8,
1113,
12,
1921,
63,
354,
12,
12319,
288,
340,
5936,
440,
315,
485,
25304,
57,
26,
355,
327,
2136,
2793,
1133,
5715,
3595,
642,
5936,
12,
880,
3354,
652,
367,
2945,
14,
355,
625,
13697,
63,
262,
63,
548,
14,
5486,
8,
8575,
12,
15364,
740,
8,
1113,
9,
355,
1980,
953,
5371,
8,
1113,
12,
5936,
12,
664,
63,
3780,
8,
8575,
430,
339,
2112,
8,
1113,
12,
2513,
5714,
297,
485,
2443,
63,
5714,
9,
421,
199,
318,
5074,
2031,
5714,
304,
272,
408,
33,
1021,
7531,
1202,
370,
16182,
18032,
1901,
9451,
2393,
14,
339,
710,
1415,
18032,
911,
506,
6326,
2808,
370,
4454,
402,
314,
16225,
272,
1021,
4799,
376,
2225,
543,
314,
2011,
536,
465,
314,
5022,
14,
2104,
2893,
12,
315,
272,
314,
1233,
7956,
447,
398,
768,
8575,
14,
6537,
360,
1421,
63,
1246,
297,
283,
1700,
63,
1246,
358,
267,
1021,
8024,
5281,
3041,
26,
288,
347,
636,
826,
721,
277,
304,
355,
2263,
953,
2263,
398,
1890,
275,
8024,
5281,
3041,
342,
339,
710,
909,
1124,
1258,
1040,
911,
1172,
3004,
4310,
1124,
1421,
63,
1246,
1040,
436,
272,
1124,
1700,
63,
1246,
4542,
1314,
787,
4454,
402,
314,
4310,
18032,
14,
339,
26794,
1471,
440,
19687,
641,
314
] | [
1898,
6029,
14260,
2752,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
2428,
199,
3,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
1334,
314,
844,
14,
199,
199,
624,
2765,
859,
6571,
2291,
367,
5936,
315,
8923,
14,
199,
199,
6663,
83,
787,
7264,
4799,
314,
1124,
32,
3780,
8497,
7531,
12,
436,
5124,
641,
199,
1589,
77,
787,
7264,
543,
1124,
32,
6537,
28566,
18489,
83,
787,
2808,
370,
3932,
199,
10235,
2393,
4799,
376,
2225,
14,
1666,
314,
3794,
367,
314,
8212,
3423,
199,
509,
1655,
10093,
14,
199,
199,
9295,
2597,
26,
339,
4178,
921,
287,
14,
13961,
14,
1308,
15,
6797,
15,
14403,
63,
262,
8923,
199,
199,
624,
199,
199,
646,
5190,
199,
199,
504,
19395,
14,
73,
1085,
78,
492,
485,
421,
199,
63,
25304,
57,
275,
1052,
199,
199,
63,
2443,
63,
5714,
275,
1052,
199,
63,
15406,
275,
1052,
421,
199,
318,
485,
409,
63,
3780,
8,
354,
12,
5022,
304,
272,
485,
5043,
63,
3780,
12,
2382,
63,
11616,
275,
485,
25304,
57,
14,
362,
8,
354,
12,
334,
403,
12,
488,
430,
272,
340,
2382,
63,
11616,
26,
267,
746,
2186,
3508,
83,
2575,
965,
282,
7264,
5022,
12,
737,
60,
78,
5,
83,
7,
450,
717,
334,
354,
12,
6522,
904,
8,
4509,
63,
11616,
1724,
272,
485,
25304,
57,
59,
354,
61,
275,
334,
3780,
12,
5190,
14,
908,
63,
2340,
1012,
421,
199,
2970,
63,
12496,
275,
909,
342,
199,
2970,
63,
21008,
275,
909,
342,
421,
199,
318,
664,
63,
3780,
8,
354,
12,
2716,
29,
2970,
63,
12496,
304,
272,
340,
2716,
365,
9576,
63,
12496,
26,
267,
372,
485,
25304,
57,
59,
354,
1527,
16,
61,
272,
372,
485,
25304,
57,
14,
362,
8,
354,
12,
334,
403,
12,
488,
11515,
16,
61,
421,
199,
533,
1910,
26702,
30456,
14403,
1726,
8,
1726,
304,
272,
408,
16894,
1380,
282,
1415,
5936,
365,
440,
17416,
30456,
14,
339,
1666,
1124,
6983,
63,
2443,
63,
5714,
8497,
367,
1655,
2436,
14,
339,
408,
272,
347,
636,
826,
721,
277,
12,
536,
12,
4545,
304,
267,
1499,
275,
4018,
1358,
11616,
5936,
26,
2818,
354,
9,
83,
367,
2818,
4684,
9,
83,
358,
450,
469,
288,
283,
354,
356,
536,
12,
283,
4684,
356,
4545,
93,
267,
1613,
8,
1358,
26702,
30456,
14403,
1726,
12,
291,
2843,
826,
721,
1328,
9,
421,
199,
318,
5022,
8,
354,
304,
272,
408,
33,
1021,
7531,
1202,
370,
2274,
18032,
14,
339,
3979,
1124,
32,
3780,
8497,
365,
1202,
370,
24774,
282,
1021,
12,
7556,
402,
626,
1021,
272,
911,
2274,
17279,
465,
18032,
367,
314,
4310,
5936,
14,
3709,
376,
272,
2893,
12,
1010,
314,
1233,
7956,
447,
398,
768,
8575,
14,
3780,
360,
1421,
63,
1246,
358,
267,
1021,
8024,
26,
288,
347,
636,
826,
721,
277,
304,
355,
2263,
953,
2263,
398,
3925,
275,
8024,
342,
339,
710,
909,
1124,
1421,
1040,
911,
506,
7264,
465,
282,
5022,
367,
1124,
1421,
63,
1246,
4345,
3091,
272,
1655,
2419,
1373,
4066,
1256,
1077,
506,
2737,
27,
4722,
4454,
911,
272,
3350,
314,
4136,
7869,
12,
12570,
9183,
315,
3365,
4454,
3769,
272,
1202,
701,
3365,
9451,
2393,
14,
339,
408,
272,
347,
4975,
8,
1886,
304,
267,
347,
8072,
8,
826,
304,
288,
347,
636,
9130,
63,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
355,
408,
9345,
314,
8072,
909,
436,
1050,
652,
370,
314,
7086,
1041,
355,
4205,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
355,
485,
409,
63,
3780,
8,
354,
12,
291,
9,
355,
7512,
63,
2443,
63,
5714,
3460,
3780,
63,
354,
29,
354,
9,
953,
372,
636,
9130,
63,
826,
363,
398,
843,
855,
826,
363,
275,
8072,
8,
1886,
855,
826,
3368,
267,
485,
15406,
59,
354,
61,
275,
843,
267,
372,
843,
272,
372,
4975,
421,
199,
318,
485,
1412,
63,
5714,
8,
1113,
304,
272,
327,
6184,
5124,
626,
883,
506,
12152,
9939,
787,
12152,
14,
272,
327,
1487,
3209,
626,
3913,
506,
12152,
9939,
787,
5489,
367,
272,
327,
12401,
315,
7512,
63,
2443,
63,
5714,
14,
339,
347,
2112,
8,
1113,
12,
1921,
63,
354,
12,
625,
13697,
63,
262,
63,
548,
304,
267,
367,
5936,
315,
2519,
8,
1113,
12,
1921,
63,
354,
12,
12319,
288,
340,
5936,
440,
315,
485,
25304,
57,
26,
355,
327,
2136,
2793,
1133,
5715,
3595,
642,
5936,
12,
880,
3354,
652,
367,
2945,
14,
355,
625,
13697,
63,
262,
63,
548,
14,
5486,
8,
8575,
12,
15364,
740,
8,
1113,
9,
355,
1980,
953,
5371,
8,
1113,
12,
5936,
12,
664,
63,
3780,
8,
8575,
430,
339,
2112,
8,
1113,
12,
2513,
5714,
297,
485,
2443,
63,
5714,
9,
421,
199,
318,
5074,
2031,
5714,
304,
272,
408,
33,
1021,
7531,
1202,
370,
16182,
18032,
1901,
9451,
2393,
14,
339,
710,
1415,
18032,
911,
506,
6326,
2808,
370,
4454,
402,
314,
16225,
272,
1021,
4799,
376,
2225,
543,
314,
2011,
536,
465,
314,
5022,
14,
2104,
2893,
12,
315,
272,
314,
1233,
7956,
447,
398,
768,
8575,
14,
6537,
360,
1421,
63,
1246,
297,
283,
1700,
63,
1246,
358,
267,
1021,
8024,
5281,
3041,
26,
288,
347,
636,
826,
721,
277,
304,
355,
2263,
953,
2263,
398,
1890,
275,
8024,
5281,
3041,
342,
339,
710,
909,
1124,
1258,
1040,
911,
1172,
3004,
4310,
1124,
1421,
63,
1246,
1040,
436,
272,
1124,
1700,
63,
1246,
4542,
1314,
787,
4454,
402,
314,
4310,
18032,
14,
339,
26794,
1471,
440,
19687,
641,
314,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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utf-8 -*-
from __future__ import unicode_literals
import datetime
import os
from pelican.readers import Readers
from pelican.tests.support import unittest, get_settings
from .asciidoc_reader import asciidoc_enabled
CUR_DIR = os.path.dirname(__file__)
CONTENT_PATH = os.path.join(CUR_DIR, 'test_data')
@unittest.skipUnless(asciidoc_enabled, "asciidoc isn't installed")
class AsciiDocReaderTest(unittest.TestCase):
def read_file(self, path, **kwargs):
# Isolate from future API changes to readers.read_file
r = Readers(settings=get_settings(**kwargs))
return r.read_file(base_path=CONTENT_PATH, path=path)
def test_article_with_asc_extension(self):
# Ensure the asc extension is being processed by the correct reader
page = self.read_file(
path='article_with_asc_extension.asc')
expected = ('<div class="sect1">\n'
'<h2 id="_used_for_pelican_test">'
'Used for pelican test</h2>\n'
'<div class="sectionbody">\n'
'<div class="paragraph">'
'<p>The quick brown fox jumped over '
'the lazy dog’s back.</p>'
'</div>\n</div>\n</div>\n')
self.assertEqual(page.content, expected)
expected = {
'category': 'Blog',
'author': 'Author O. Article',
'title': 'Test AsciiDoc File Header',
'date': datetime.datetime(2011, 9, 15, 9, 5),
'tags': ['Linux', 'Python', 'Pelican'],
}
for key, value in expected.items():
self.assertEqual(value, page.metadata[key], key)
def test_article_with_asc_options(self):
# test to ensure the ASCIIDOC_OPTIONS is being used
page = self.read_file(path='article_with_asc_options.asc',
ASCIIDOC_OPTIONS=["-a revision=1.0.42"])
expected = ('<div class="sect1">\n'
'<h2 id="_used_for_pelican_test">'
'Used for pelican test</h2>\n'
'<div class="sectionbody">\n'
'<div class="paragraph">'
'<p>version 1.0.42</p></div>\n'
'<div class="paragraph">'
'<p>The quick brown fox jumped over '
'the lazy dog’s back.</p>'
'</div>\n</div>\n</div>\n')
self.assertEqual(page.content, expected) | unlicense | [
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
646,
747,
199,
199,
504,
4837,
28091,
14,
27056,
492,
23099,
83,
199,
504,
4837,
28091,
14,
2219,
14,
4058,
492,
2882,
12,
664,
63,
1751,
199,
199,
504,
1275,
305,
559,
344,
679,
63,
5503,
492,
465,
559,
344,
679,
63,
3827,
199,
199,
7013,
63,
3022,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
9663,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
7013,
63,
3022,
12,
283,
396,
63,
576,
358,
199,
199,
32,
2796,
14,
11278,
8,
305,
559,
344,
679,
63,
3827,
12,
298,
305,
559,
344,
679,
5712,
1133,
4903,
531,
199,
533,
437,
551,
5908,
3768,
5929,
774,
8,
2796,
14,
1746,
304,
272,
347,
1586,
63,
493,
8,
277,
12,
931,
12,
1011,
958,
304,
267,
327,
6596,
16288,
687,
6466,
3261,
4493,
370,
7002,
83,
14,
739,
63,
493,
267,
519,
275,
23099,
83,
8,
1751,
29,
362,
63,
1751,
3682,
958,
430,
267,
372,
519,
14,
739,
63,
493,
8,
1095,
63,
515,
29,
9663,
63,
3243,
12,
931,
29,
515,
9,
339,
347,
511,
63,
6934,
63,
1045,
63,
10125,
63,
3435,
8,
277,
304,
267,
327,
7523,
314,
16635,
3329,
365,
3769,
7686,
701,
314,
3211,
7002,
267,
2034,
275,
291,
14,
739,
63,
493,
8,
288,
931,
534,
6934,
63,
1045,
63,
10125,
63,
3435,
14,
10125,
358,
267,
1420,
275,
19990,
3015,
1021,
628,
8519,
17,
14559,
78,
7,
490,
2650,
72,
18,
1305,
19667,
2972,
63,
509,
63,
321,
28091,
63,
396,
15603,
490,
283,
9167,
367,
4837,
28091,
511,
1108,
72,
18,
3072,
78,
7,
490,
2650,
3015,
1021,
628,
2792,
2030,
14559,
78,
7,
490,
2650,
3015,
1021,
628,
12400,
15603,
490,
2650,
80,
30,
1918,
12530,
330,
18406,
7090,
88,
14882,
379,
1806,
283,
490,
283,
1589,
9617,
23454,
7997,
2564,
1196,
27,
83,
1771,
9758,
80,
3524,
490,
11936,
3015,
3072,
78,
1108,
3015,
3072,
78,
1108,
3015,
3072,
78,
358,
267,
291,
14,
629,
8,
1606,
14,
1317,
12,
1420,
9,
267,
1420,
275,
469,
288,
283,
3710,
356,
283,
26081,
297,
288,
283,
2502,
356,
283,
5949,
593,
14,
8281,
297,
288,
283,
1213,
356,
283,
774,
437,
551,
5908,
3768,
3814,
10240,
297,
288,
283,
602,
356,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
4114,
12,
1749,
12,
959,
395,
288,
283,
2969,
356,
788,
14091,
297,
283,
4718,
297,
283,
8070,
28091,
995,
267,
789,
398,
367,
790,
12,
574,
315,
1420,
14,
1744,
837,
288,
291,
14,
629,
8,
585,
12,
2034,
14,
2343,
59,
498,
467,
790,
9,
339,
347,
511,
63,
6934,
63,
1045,
63,
10125,
63,
1419,
8,
277,
304,
267,
327,
511,
370,
4868,
314,
4319,
3553,
998,
21137,
63,
8808,
365,
3769,
1202,
267,
2034,
275,
291,
14,
739,
63,
493,
8,
515,
534,
6934,
63,
1045,
63,
10125,
63,
1419,
14,
10125,
297,
288,
4319,
3553,
998,
21137,
63,
8808,
6270,
13,
65,
6974,
29,
17,
14,
16,
14,
2260,
3135,
267,
1420,
275,
19990,
3015,
1021,
628,
8519,
17,
14559,
78,
7,
490,
2650,
72,
18,
1305,
19667,
2972,
63,
509,
63,
321,
28091,
63,
396,
15603,
490,
283,
9167,
367,
4837,
28091,
511,
1108,
72,
18,
3072,
78,
7,
490,
2650,
3015,
1021,
628,
2792,
2030,
14559,
78,
7,
490,
2650,
3015,
1021,
628,
12400,
15603,
490,
2650,
80,
30,
1023,
413,
14,
16,
14,
2260,
1108,
80,
2957,
3015,
3072,
78,
7,
490,
2650,
3015,
1021,
628,
12400,
15603,
490,
2650,
80,
30,
1918,
12530,
330,
18406,
7090,
88,
14882,
379,
1806,
283,
490,
283,
1589,
9617,
23454,
7997,
2564,
1196,
27,
83,
1771,
9758,
80,
3524,
490,
11936,
3015,
3072,
78,
1108,
3015,
3072,
78,
1108,
3015,
3072,
78,
358,
267,
291,
14,
629,
8,
1606,
14,
1317,
12,
1420,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
646,
2197,
199,
646,
747,
199,
199,
504,
4837,
28091,
14,
27056,
492,
23099,
83,
199,
504,
4837,
28091,
14,
2219,
14,
4058,
492,
2882,
12,
664,
63,
1751,
199,
199,
504,
1275,
305,
559,
344,
679,
63,
5503,
492,
465,
559,
344,
679,
63,
3827,
199,
199,
7013,
63,
3022,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
9663,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
7013,
63,
3022,
12,
283,
396,
63,
576,
358,
199,
199,
32,
2796,
14,
11278,
8,
305,
559,
344,
679,
63,
3827,
12,
298,
305,
559,
344,
679,
5712,
1133,
4903,
531,
199,
533,
437,
551,
5908,
3768,
5929,
774,
8,
2796,
14,
1746,
304,
272,
347,
1586,
63,
493,
8,
277,
12,
931,
12,
1011,
958,
304,
267,
327,
6596,
16288,
687,
6466,
3261,
4493,
370,
7002,
83,
14,
739,
63,
493,
267,
519,
275,
23099,
83,
8,
1751,
29,
362,
63,
1751,
3682,
958,
430,
267,
372,
519,
14,
739,
63,
493,
8,
1095,
63,
515,
29,
9663,
63,
3243,
12,
931,
29,
515,
9,
339,
347,
511,
63,
6934,
63,
1045,
63,
10125,
63,
3435,
8,
277,
304,
267,
327,
7523,
314,
16635,
3329,
365,
3769,
7686,
701,
314,
3211,
7002,
267,
2034,
275,
291,
14,
739,
63,
493,
8,
288,
931,
534,
6934,
63,
1045,
63,
10125,
63,
3435,
14,
10125,
358,
267,
1420,
275,
19990,
3015,
1021,
628,
8519,
17,
14559,
78,
7,
490,
2650,
72,
18,
1305,
19667,
2972,
63,
509,
63,
321,
28091,
63,
396,
15603,
490,
283,
9167,
367,
4837,
28091,
511,
1108,
72,
18,
3072,
78,
7,
490,
2650,
3015,
1021,
628,
2792,
2030,
14559,
78,
7,
490,
2650,
3015,
1021,
628,
12400,
15603,
490,
2650,
80,
30,
1918,
12530,
330,
18406,
7090,
88,
14882,
379,
1806,
283,
490,
283,
1589,
9617,
23454,
7997,
2564,
1196,
27,
83,
1771,
9758,
80,
3524,
490,
11936,
3015,
3072,
78,
1108,
3015,
3072,
78,
1108,
3015,
3072,
78,
358,
267,
291,
14,
629,
8,
1606,
14,
1317,
12,
1420,
9,
267,
1420,
275,
469,
288,
283,
3710,
356,
283,
26081,
297,
288,
283,
2502,
356,
283,
5949,
593,
14,
8281,
297,
288,
283,
1213,
356,
283,
774,
437,
551,
5908,
3768,
3814,
10240,
297,
288,
283,
602,
356,
2197,
14,
2083,
8,
8128,
12,
1749,
12,
4114,
12,
1749,
12,
959,
395,
288,
283,
2969,
356,
788,
14091,
297,
283,
4718,
297,
283,
8070,
28091,
995,
267,
789,
398,
367,
790,
12,
574,
315,
1420,
14,
1744,
837,
288,
291,
14,
629,
8,
585,
12,
2034,
14,
2343,
59,
498,
467,
790,
9,
339,
347,
511,
63,
6934,
63,
1045,
63,
10125,
63,
1419,
8,
277,
304,
267,
327,
511,
370,
4868,
314,
4319,
3553,
998,
21137,
63,
8808,
365,
3769,
1202,
267,
2034,
275,
291,
14,
739,
63,
493,
8,
515,
534,
6934,
63,
1045,
63,
10125,
63,
1419,
14,
10125,
297,
288,
4319,
3553,
998,
21137,
63,
8808,
6270,
13,
65,
6974,
29,
17,
14,
16,
14,
2260,
3135,
267,
1420,
275,
19990,
3015,
1021,
628,
8519,
17,
14559,
78,
7,
490,
2650,
72,
18,
1305,
19667,
2972,
63,
509,
63,
321,
28091,
63,
396,
15603,
490,
283,
9167,
367,
4837,
28091,
511,
1108,
72,
18,
3072,
78,
7,
490,
2650,
3015,
1021,
628,
2792,
2030,
14559,
78,
7,
490,
2650,
3015,
1021,
628,
12400,
15603,
490,
2650,
80,
30,
1023,
413,
14,
16,
14,
2260,
1108,
80,
2957,
3015,
3072,
78,
7,
490,
2650,
3015,
1021,
628,
12400,
15603,
490,
2650,
80,
30,
1918,
12530,
330,
18406,
7090,
88,
14882,
379,
1806,
283,
490,
283,
1589,
9617,
23454,
7997,
2564,
1196,
27,
83,
1771,
9758,
80,
3524,
490,
11936,
3015,
3072,
78,
1108,
3015,
3072,
78,
1108,
3015,
3072,
78,
358,
267,
291,
14,
629,
8,
1606,
14,
1317,
12,
1420,
9,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
mvaled/sentry | tests/sentry/deletions/test_tagkey.py | 1 | 3690 | from __future__ import absolute_import
from sentry import tagstore
from sentry.tagstore.models import EventTag
from sentry.models import ScheduledDeletion
from sentry.tasks.deletion import run_deletion
from sentry.testutils import TestCase
class DeleteTagKeyTest(TestCase):
def test_simple(self):
team = self.create_team(name="test", slug="test")
project = self.create_project(teams=[team], name="test1", slug="test1")
group = self.create_group(project=project)
key = "foo"
value = "bar"
tk = tagstore.create_tag_key(
key=key, project_id=project.id, environment_id=self.environment.id
)
tv = tagstore.create_tag_value(
key=key, value=value, project_id=project.id, environment_id=self.environment.id
)
tagstore.create_group_tag_key(
key=key, group_id=group.id, project_id=project.id, environment_id=self.environment.id
)
tagstore.create_group_tag_value(
key=key,
value=value,
group_id=group.id,
project_id=project.id,
environment_id=self.environment.id,
)
tagstore.create_event_tags(
group_id=group.id,
project_id=project.id,
event_id=1,
environment_id=self.environment.id,
tags=[(tk.key, tv.value)],
)
project2 = self.create_project(teams=[team], name="test2")
env2 = self.create_environment(project=project2)
group2 = self.create_group(project=project2)
tk2 = tagstore.create_tag_key(project2.id, env2.id, key)
tv2 = tagstore.create_tag_value(
key=key, value=value, project_id=project2.id, environment_id=env2.id
)
tagstore.create_group_tag_key(
key=key, group_id=group2.id, project_id=project2.id, environment_id=env2.id
)
tagstore.create_group_tag_value(
key=key, value=value, group_id=group2.id, project_id=project2.id, environment_id=env2.id
)
tagstore.create_event_tags(
group_id=group2.id,
project_id=project2.id,
environment_id=env2.id,
event_id=1,
tags=[(tk2.key, tv2.value)],
)
deletion = ScheduledDeletion.schedule(tk, days=0)
deletion.update(in_progress=True)
with self.tasks():
run_deletion(deletion.id)
try:
tagstore.get_group_tag_value(
group.project_id, group.id, self.environment.id, key, value
)
assert False # verify exception thrown
except tagstore.GroupTagValueNotFound:
pass
try:
tagstore.get_group_tag_key(group.project_id, group.id, self.environment.id, key)
assert False # verify exception thrown
except tagstore.GroupTagKeyNotFound:
pass
try:
tagstore.get_tag_value(project.id, self.environment.id, key, value)
assert False # verify exception thrown
except tagstore.TagValueNotFound:
pass
try:
tagstore.get_tag_key(project.id, self.environment.id, key)
assert False # verify exception thrown
except tagstore.TagKeyNotFound:
pass
assert tagstore.get_tag_key(project2.id, env2.id, key) is not None
assert tagstore.get_group_tag_key(group2.project_id, group2.id, env2.id, key) is not None
assert (
tagstore.get_group_tag_value(group2.project_id, group2.id, env2.id, key, value)
is not None
)
assert EventTag.objects.filter(key_id=tk2.id).exists()
| bsd-3-clause | [
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
26230,
492,
1947,
1617,
199,
504,
26230,
14,
1450,
1617,
14,
992,
492,
6763,
1931,
199,
504,
26230,
14,
992,
492,
24317,
68,
3896,
296,
199,
504,
26230,
14,
5054,
14,
14281,
492,
1255,
63,
14281,
199,
504,
26230,
14,
396,
1208,
492,
7640,
421,
199,
533,
8496,
1931,
1197,
774,
8,
1746,
304,
272,
347,
511,
63,
4129,
8,
277,
304,
267,
8099,
275,
291,
14,
981,
63,
5969,
8,
354,
628,
396,
401,
8889,
628,
396,
531,
267,
2199,
275,
291,
14,
981,
63,
1715,
8,
19048,
1524,
5969,
467,
536,
628,
396,
17,
401,
8889,
628,
396,
17,
531,
267,
1572,
275,
291,
14,
981,
63,
923,
8,
1715,
29,
1715,
9,
267,
790,
275,
298,
1421,
2,
267,
574,
275,
298,
1700,
2,
267,
10157,
275,
1947,
1617,
14,
981,
63,
1450,
63,
498,
8,
288,
790,
29,
498,
12,
2199,
63,
344,
29,
1715,
14,
344,
12,
3734,
63,
344,
29,
277,
14,
5418,
14,
344,
267,
776,
267,
13466,
275,
1947,
1617,
14,
981,
63,
1450,
63,
585,
8,
288,
790,
29,
498,
12,
574,
29,
585,
12,
2199,
63,
344,
29,
1715,
14,
344,
12,
3734,
63,
344,
29,
277,
14,
5418,
14,
344,
267,
776,
267,
1947,
1617,
14,
981,
63,
923,
63,
1450,
63,
498,
8,
288,
790,
29,
498,
12,
1572,
63,
344,
29,
923,
14,
344,
12,
2199,
63,
344,
29,
1715,
14,
344,
12,
3734,
63,
344,
29,
277,
14,
5418,
14,
344,
267,
776,
267,
1947,
1617,
14,
981,
63,
923,
63,
1450,
63,
585,
8,
288,
790,
29,
498,
12,
288,
574,
29,
585,
12,
288,
1572,
63,
344,
29,
923,
14,
344,
12,
288,
2199,
63,
344,
29,
1715,
14,
344,
12,
288,
3734,
63,
344,
29,
277,
14,
5418,
14,
344,
12,
267,
776,
267,
1947,
1617,
14,
981,
63,
1430,
63,
2969,
8,
288,
1572,
63,
344,
29,
923,
14,
344,
12,
288,
2199,
63,
344,
29,
1715,
14,
344,
12,
288,
1566,
63,
344,
29,
17,
12,
288,
3734,
63,
344,
29,
277,
14,
5418,
14,
344,
12,
288,
3762,
17497,
2663,
14,
498,
12,
13466,
14,
585,
4360,
267,
776,
398,
2199,
18,
275,
291,
14,
981,
63,
1715,
8,
19048,
1524,
5969,
467,
536,
628,
396,
18,
531,
267,
2589,
18,
275,
291,
14,
981,
63,
5418,
8,
1715,
29,
1715,
18,
9,
267,
1572,
18,
275,
291,
14,
981,
63,
923,
8,
1715,
29,
1715,
18,
9,
267,
10157,
18,
275,
1947,
1617,
14,
981,
63,
1450,
63,
498,
8,
1715,
18,
14,
344,
12,
2589,
18,
14,
344,
12,
790,
9,
267,
13466,
18,
275,
1947,
1617,
14,
981,
63,
1450,
63,
585,
8,
288,
790,
29,
498,
12,
574,
29,
585,
12,
2199,
63,
344,
29,
1715,
18,
14,
344,
12,
3734,
63,
344,
29,
1813,
18,
14,
344,
267,
776,
267,
1947,
1617,
14,
981,
63,
923,
63,
1450,
63,
498,
8,
288,
790,
29,
498,
12,
1572,
63,
344,
29,
923,
18,
14,
344,
12,
2199,
63,
344,
29,
1715,
18,
14,
344,
12,
3734,
63,
344,
29,
1813,
18,
14,
344,
267,
776,
267,
1947,
1617,
14,
981,
63,
923,
63,
1450,
63,
585,
8,
288,
790,
29,
498,
12,
574,
29,
585,
12,
1572,
63,
344,
29,
923,
18,
14,
344,
12,
2199,
63,
344,
29,
1715,
18,
14,
344,
12,
3734,
63,
344,
29,
1813,
18,
14,
344,
267,
776,
267,
1947,
1617,
14,
981,
63,
1430,
63,
2969,
8,
288,
1572,
63,
344,
29,
923,
18,
14,
344,
12,
288,
2199,
63,
344,
29,
1715,
18,
14,
344,
12,
288,
3734,
63,
344,
29,
1813,
18,
14,
344,
12,
288,
1566,
63,
344,
29,
17,
12,
288,
3762,
17497,
2663,
18,
14,
498,
12,
13466,
18,
14,
585,
4360,
267,
776,
398,
14068,
275,
24317,
68,
3896,
296,
14,
7211,
8,
2663,
12,
7609,
29,
16,
9,
267,
14068,
14,
873,
8,
262,
63,
5734,
29,
549,
9,
398,
543,
291,
14,
5054,
837,
288,
1255,
63,
14281,
8,
14281,
14,
344,
9,
398,
862,
26,
288,
1947,
1617,
14,
362,
63,
923,
63,
1450,
63,
585,
8,
355,
1572,
14,
1715,
63,
344,
12,
1572,
14,
344,
12,
291,
14,
5418,
14,
344,
12,
790,
12,
574,
288,
776,
288,
702,
756,
221,
327,
4911,
1919,
14031,
267,
871,
1947,
1617,
14,
2448,
1931,
1110,
4667,
26,
288,
986,
267,
862,
26,
288,
1947,
1617,
14,
362,
63,
923,
63,
1450,
63,
498,
8,
923,
14,
1715,
63,
344,
12,
1572,
14,
344,
12,
291,
14,
5418,
14,
344,
12,
790,
9,
288,
702,
756,
221,
327,
4911,
1919,
14031,
267,
871,
1947,
1617,
14,
2448,
1931,
1197,
4667,
26,
288,
986,
267,
862,
26,
288,
1947,
1617,
14,
362,
63,
1450,
63,
585,
8,
1715,
14,
344,
12,
291,
14,
5418,
14,
344,
12,
790,
12,
574,
9,
288,
702,
756,
221,
327,
4911,
1919,
14031,
267,
871,
1947,
1617,
14,
1931,
1110,
4667,
26,
288,
986,
267,
862,
26,
288,
1947,
1617,
14,
362,
63,
1450,
63,
498,
8,
1715,
14,
344,
12,
291,
14,
5418,
14,
344,
12,
790,
9,
288,
702,
756,
221,
327,
4911,
1919,
14031,
267,
871,
1947,
1617,
14,
1931,
1197,
4667,
26,
288,
986,
398,
702,
1947,
1617,
14,
362,
63,
1450,
63,
498,
8,
1715,
18,
14,
344,
12,
2589,
18,
14,
344,
12,
790,
9,
365,
440,
488,
267,
702,
1947,
1617,
14,
362,
63,
923,
63,
1450,
63,
498,
8,
923,
18,
14,
1715,
63,
344,
12,
1572,
18,
14,
344,
12,
2589,
18,
14,
344,
12,
790,
9,
365,
440,
488,
267,
702,
334,
288,
1947,
1617,
14,
362,
63,
923,
63,
1450,
63,
585,
8,
923,
18,
14,
1715,
63,
344,
12,
1572,
18,
14,
344,
12,
2589,
18,
14,
344,
12,
790,
12,
574,
9,
288,
365,
440,
488,
267,
776,
267,
702,
6763,
1931,
14,
1462,
14,
1541,
8,
498,
63,
344,
29,
2663,
18,
14,
344,
680,
2444,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
26230,
492,
1947,
1617,
199,
504,
26230,
14,
1450,
1617,
14,
992,
492,
6763,
1931,
199,
504,
26230,
14,
992,
492,
24317,
68,
3896,
296,
199,
504,
26230,
14,
5054,
14,
14281,
492,
1255,
63,
14281,
199,
504,
26230,
14,
396,
1208,
492,
7640,
421,
199,
533,
8496,
1931,
1197,
774,
8,
1746,
304,
272,
347,
511,
63,
4129,
8,
277,
304,
267,
8099,
275,
291,
14,
981,
63,
5969,
8,
354,
628,
396,
401,
8889,
628,
396,
531,
267,
2199,
275,
291,
14,
981,
63,
1715,
8,
19048,
1524,
5969,
467,
536,
628,
396,
17,
401,
8889,
628,
396,
17,
531,
267,
1572,
275,
291,
14,
981,
63,
923,
8,
1715,
29,
1715,
9,
267,
790,
275,
298,
1421,
2,
267,
574,
275,
298,
1700,
2,
267,
10157,
275,
1947,
1617,
14,
981,
63,
1450,
63,
498,
8,
288,
790,
29,
498,
12,
2199,
63,
344,
29,
1715,
14,
344,
12,
3734,
63,
344,
29,
277,
14,
5418,
14,
344,
267,
776,
267,
13466,
275,
1947,
1617,
14,
981,
63,
1450,
63,
585,
8,
288,
790,
29,
498,
12,
574,
29,
585,
12,
2199,
63,
344,
29,
1715,
14,
344,
12,
3734,
63,
344,
29,
277,
14,
5418,
14,
344,
267,
776,
267,
1947,
1617,
14,
981,
63,
923,
63,
1450,
63,
498,
8,
288,
790,
29,
498,
12,
1572,
63,
344,
29,
923,
14,
344,
12,
2199,
63,
344,
29,
1715,
14,
344,
12,
3734,
63,
344,
29,
277,
14,
5418,
14,
344,
267,
776,
267,
1947,
1617,
14,
981,
63,
923,
63,
1450,
63,
585,
8,
288,
790,
29,
498,
12,
288,
574,
29,
585,
12,
288,
1572,
63,
344,
29,
923,
14,
344,
12,
288,
2199,
63,
344,
29,
1715,
14,
344,
12,
288,
3734,
63,
344,
29,
277,
14,
5418,
14,
344,
12,
267,
776,
267,
1947,
1617,
14,
981,
63,
1430,
63,
2969,
8,
288,
1572,
63,
344,
29,
923,
14,
344,
12,
288,
2199,
63,
344,
29,
1715,
14,
344,
12,
288,
1566,
63,
344,
29,
17,
12,
288,
3734,
63,
344,
29,
277,
14,
5418,
14,
344,
12,
288,
3762,
17497,
2663,
14,
498,
12,
13466,
14,
585,
4360,
267,
776,
398,
2199,
18,
275,
291,
14,
981,
63,
1715,
8,
19048,
1524,
5969,
467,
536,
628,
396,
18,
531,
267,
2589,
18,
275,
291,
14,
981,
63,
5418,
8,
1715,
29,
1715,
18,
9,
267,
1572,
18,
275,
291,
14,
981,
63,
923,
8,
1715,
29,
1715,
18,
9,
267,
10157,
18,
275,
1947,
1617,
14,
981,
63,
1450,
63,
498,
8,
1715,
18,
14,
344,
12,
2589,
18,
14,
344,
12,
790,
9,
267,
13466,
18,
275,
1947,
1617,
14,
981,
63,
1450,
63,
585,
8,
288,
790,
29,
498,
12,
574,
29,
585,
12,
2199,
63,
344,
29,
1715,
18,
14,
344,
12,
3734,
63,
344,
29,
1813,
18,
14,
344,
267,
776,
267,
1947,
1617,
14,
981,
63,
923,
63,
1450,
63,
498,
8,
288,
790,
29,
498,
12,
1572,
63,
344,
29,
923,
18,
14,
344,
12,
2199,
63,
344,
29,
1715,
18,
14,
344,
12,
3734,
63,
344,
29,
1813,
18,
14,
344,
267,
776,
267,
1947,
1617,
14,
981,
63,
923,
63,
1450,
63,
585,
8,
288,
790,
29,
498,
12,
574,
29,
585,
12,
1572,
63,
344,
29,
923,
18,
14,
344,
12,
2199,
63,
344,
29,
1715,
18,
14,
344,
12,
3734,
63,
344,
29,
1813,
18,
14,
344,
267,
776,
267,
1947,
1617,
14,
981,
63,
1430,
63,
2969,
8,
288,
1572,
63,
344,
29,
923,
18,
14,
344,
12,
288,
2199,
63,
344,
29,
1715,
18,
14,
344,
12,
288,
3734,
63,
344,
29,
1813,
18,
14,
344,
12,
288,
1566,
63,
344,
29,
17,
12,
288,
3762,
17497,
2663,
18,
14,
498,
12,
13466,
18,
14,
585,
4360,
267,
776,
398,
14068,
275,
24317,
68,
3896,
296,
14,
7211,
8,
2663,
12,
7609,
29,
16,
9,
267,
14068,
14,
873,
8,
262,
63,
5734,
29,
549,
9,
398,
543,
291,
14,
5054,
837,
288,
1255,
63,
14281,
8,
14281,
14,
344,
9,
398,
862,
26,
288,
1947,
1617,
14,
362,
63,
923,
63,
1450,
63,
585,
8,
355,
1572,
14,
1715,
63,
344,
12,
1572,
14,
344,
12,
291,
14,
5418,
14,
344,
12,
790,
12,
574,
288,
776,
288,
702,
756,
221,
327,
4911,
1919,
14031,
267,
871,
1947,
1617,
14,
2448,
1931,
1110,
4667,
26,
288,
986,
267,
862,
26,
288,
1947,
1617,
14,
362,
63,
923,
63,
1450,
63,
498,
8,
923,
14,
1715,
63,
344,
12,
1572,
14,
344,
12,
291,
14,
5418,
14,
344,
12,
790,
9,
288,
702,
756,
221,
327,
4911,
1919,
14031,
267,
871,
1947,
1617,
14,
2448,
1931,
1197,
4667,
26,
288,
986,
267,
862,
26,
288,
1947,
1617,
14,
362,
63,
1450,
63,
585,
8,
1715,
14,
344,
12,
291,
14,
5418,
14,
344,
12,
790,
12,
574,
9,
288,
702,
756,
221,
327,
4911,
1919,
14031,
267,
871,
1947,
1617,
14,
1931,
1110,
4667,
26,
288,
986,
267,
862,
26,
288,
1947,
1617,
14,
362,
63,
1450,
63,
498,
8,
1715,
14,
344,
12,
291,
14,
5418,
14,
344,
12,
790,
9,
288,
702,
756,
221,
327,
4911,
1919,
14031,
267,
871,
1947,
1617,
14,
1931,
1197,
4667,
26,
288,
986,
398,
702,
1947,
1617,
14,
362,
63,
1450,
63,
498,
8,
1715,
18,
14,
344,
12,
2589,
18,
14,
344,
12,
790,
9,
365,
440,
488,
267,
702,
1947,
1617,
14,
362,
63,
923,
63,
1450,
63,
498,
8,
923,
18,
14,
1715,
63,
344,
12,
1572,
18,
14,
344,
12,
2589,
18,
14,
344,
12,
790,
9,
365,
440,
488,
267,
702,
334,
288,
1947,
1617,
14,
362,
63,
923,
63,
1450,
63,
585,
8,
923,
18,
14,
1715,
63,
344,
12,
1572,
18,
14,
344,
12,
2589,
18,
14,
344,
12,
790,
12,
574,
9,
288,
365,
440,
488,
267,
776,
267,
702,
6763,
1931,
14,
1462,
14,
1541,
8,
498,
63,
344,
29,
2663,
18,
14,
344,
680,
2444,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
RedhawkSDR/integration-gnuhawk | gnuradio/docs/doxygen/doxyxml/doxyindex.py | 16 | 8404 | #
# Copyright 2010 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio 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, or (at your option)
# any later version.
#
# GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
"""
Classes providing more user-friendly interfaces to the doxygen xml
docs than the generated classes provide.
"""
import os
from generated import index
from base import Base
from text import description
class DoxyIndex(Base):
"""
Parses a doxygen xml directory.
"""
__module__ = "gnuradio.utils.doxyxml"
def _parse(self):
if self._parsed:
return
super(DoxyIndex, self)._parse()
self._root = index.parse(os.path.join(self._xml_path, 'index.xml'))
for mem in self._root.compound:
converted = self.convert_mem(mem)
# For files we want the contents to be accessible directly
# from the parent rather than having to go through the file
# object.
if self.get_cls(mem) == DoxyFile:
if mem.name.endswith('.h'):
self._members += converted.members()
self._members.append(converted)
else:
self._members.append(converted)
def generate_swig_doc_i(self):
"""
%feature("docstring") gr_make_align_on_samplenumbers_ss::align_state "
Wraps the C++: gr_align_on_samplenumbers_ss::align_state";
"""
pass
class DoxyCompMem(Base):
kind = None
def __init__(self, *args, **kwargs):
super(DoxyCompMem, self).__init__(*args, **kwargs)
@classmethod
def can_parse(cls, obj):
return obj.kind == cls.kind
def set_descriptions(self, parse_data):
bd = description(getattr(parse_data, 'briefdescription', None))
dd = description(getattr(parse_data, 'detaileddescription', None))
self._data['brief_description'] = bd
self._data['detailed_description'] = dd
def set_parameters(self, data):
vs = [ddc.value for ddc in data.detaileddescription.content_]
pls = []
for v in vs:
if hasattr(v, 'parameterlist'):
pls += v.parameterlist
pis = []
for pl in pls:
pis += pl.parameteritem
dpis = []
for pi in pis:
dpi = DoxyParameterItem(pi)
dpi._parse()
dpis.append(dpi)
self._data['params'] = dpis
class DoxyCompound(DoxyCompMem):
pass
class DoxyMember(DoxyCompMem):
pass
class DoxyFunction(DoxyMember):
__module__ = "gnuradio.utils.doxyxml"
kind = 'function'
def _parse(self):
if self._parsed:
return
super(DoxyFunction, self)._parse()
self.set_descriptions(self._parse_data)
self.set_parameters(self._parse_data)
if not self._data['params']:
# If the params weren't set by a comment then just grab the names.
self._data['params'] = []
prms = self._parse_data.param
for prm in prms:
self._data['params'].append(DoxyParam(prm))
brief_description = property(lambda self: self.data()['brief_description'])
detailed_description = property(lambda self: self.data()['detailed_description'])
params = property(lambda self: self.data()['params'])
Base.mem_classes.append(DoxyFunction)
class DoxyParam(DoxyMember):
__module__ = "gnuradio.utils.doxyxml"
def _parse(self):
if self._parsed:
return
super(DoxyParam, self)._parse()
self.set_descriptions(self._parse_data)
self._data['declname'] = self._parse_data.declname
@property
def description(self):
descriptions = []
if self.brief_description:
descriptions.append(self.brief_description)
if self.detailed_description:
descriptions.append(self.detailed_description)
return '\n\n'.join(descriptions)
brief_description = property(lambda self: self.data()['brief_description'])
detailed_description = property(lambda self: self.data()['detailed_description'])
name = property(lambda self: self.data()['declname'])
class DoxyParameterItem(DoxyMember):
"""A different representation of a parameter in Doxygen."""
def _parse(self):
if self._parsed:
return
super(DoxyParameterItem, self)._parse()
names = []
for nl in self._parse_data.parameternamelist:
for pn in nl.parametername:
names.append(description(pn))
# Just take first name
self._data['name'] = names[0]
# Get description
pd = description(self._parse_data.get_parameterdescription())
self._data['description'] = pd
description = property(lambda self: self.data()['description'])
name = property(lambda self: self.data()['name'])
class DoxyClass(DoxyCompound):
__module__ = "gnuradio.utils.doxyxml"
kind = 'class'
def _parse(self):
if self._parsed:
return
super(DoxyClass, self)._parse()
self.retrieve_data()
if self._error:
return
self.set_descriptions(self._retrieved_data.compounddef)
self.set_parameters(self._retrieved_data.compounddef)
# Sectiondef.kind tells about whether private or public.
# We just ignore this for now.
self.process_memberdefs()
brief_description = property(lambda self: self.data()['brief_description'])
detailed_description = property(lambda self: self.data()['detailed_description'])
params = property(lambda self: self.data()['params'])
Base.mem_classes.append(DoxyClass)
class DoxyFile(DoxyCompound):
__module__ = "gnuradio.utils.doxyxml"
kind = 'file'
def _parse(self):
if self._parsed:
return
super(DoxyFile, self)._parse()
self.retrieve_data()
self.set_descriptions(self._retrieved_data.compounddef)
if self._error:
return
self.process_memberdefs()
brief_description = property(lambda self: self.data()['brief_description'])
detailed_description = property(lambda self: self.data()['detailed_description'])
Base.mem_classes.append(DoxyFile)
class DoxyNamespace(DoxyCompound):
__module__ = "gnuradio.utils.doxyxml"
kind = 'namespace'
Base.mem_classes.append(DoxyNamespace)
class DoxyGroup(DoxyCompound):
__module__ = "gnuradio.utils.doxyxml"
kind = 'group'
def _parse(self):
if self._parsed:
return
super(DoxyGroup, self)._parse()
self.retrieve_data()
if self._error:
return
cdef = self._retrieved_data.compounddef
self._data['title'] = description(cdef.title)
# Process inner groups
grps = cdef.innergroup
for grp in grps:
converted = DoxyGroup.from_refid(grp.refid, top=self.top)
self._members.append(converted)
# Process inner classes
klasses = cdef.innerclass
for kls in klasses:
converted = DoxyClass.from_refid(kls.refid, top=self.top)
self._members.append(converted)
# Process normal members
self.process_memberdefs()
title = property(lambda self: self.data()['title'])
Base.mem_classes.append(DoxyGroup)
class DoxyFriend(DoxyMember):
__module__ = "gnuradio.utils.doxyxml"
kind = 'friend'
Base.mem_classes.append(DoxyFriend)
class DoxyOther(Base):
__module__ = "gnuradio.utils.doxyxml"
kinds = set(['variable', 'struct', 'union', 'define', 'typedef', 'enum', 'dir', 'page'])
@classmethod
def can_parse(cls, obj):
return obj.kind in cls.kinds
Base.mem_classes.append(DoxyOther)
| gpl-3.0 | [
3,
199,
3,
1898,
7129,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
221,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
221,
199,
3,
1664,
13514,
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,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
1664,
13514,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
221,
199,
624,
199,
15711,
13070,
1655,
922,
13,
17317,
8386,
370,
314,
886,
20515,
2748,
199,
4757,
2419,
314,
4046,
3992,
5647,
14,
199,
624,
199,
199,
646,
747,
199,
199,
504,
4046,
492,
1478,
199,
504,
1300,
492,
3523,
199,
504,
1318,
492,
1369,
199,
199,
533,
4226,
1702,
2681,
8,
1563,
304,
272,
408,
272,
29968,
282,
886,
20515,
2748,
2082,
14,
272,
408,
339,
636,
578,
363,
275,
298,
784,
23289,
14,
1208,
14,
1117,
1702,
1652,
2,
339,
347,
485,
1122,
8,
277,
304,
267,
340,
291,
423,
6751,
26,
288,
372,
267,
1613,
8,
2585,
1702,
2681,
12,
291,
10445,
1122,
342,
267,
291,
423,
1231,
275,
1478,
14,
1122,
8,
736,
14,
515,
14,
904,
8,
277,
423,
1652,
63,
515,
12,
283,
1080,
14,
1652,
1333,
755,
267,
367,
7573,
315,
291,
423,
1231,
14,
15278,
26,
288,
6702,
275,
291,
14,
3916,
63,
5286,
8,
5286,
9,
288,
327,
2104,
1584,
781,
2934,
314,
4072,
370,
506,
17909,
5370,
288,
327,
687,
314,
1676,
7830,
2419,
9445,
370,
2621,
4012,
314,
570,
288,
327,
909,
14,
288,
340,
291,
14,
362,
63,
1886,
8,
5286,
9,
508,
4226,
1702,
1173,
26,
355,
340,
7573,
14,
354,
14,
4130,
5175,
72,
735,
490,
291,
423,
6334,
847,
6702,
14,
6334,
342,
490,
291,
423,
6334,
14,
740,
8,
22818,
9,
288,
587,
26,
355,
291,
423,
6334,
14,
740,
8,
22818,
9,
421,
199,
318,
3550,
63,
9676,
63,
1301,
63,
73,
8,
277,
304,
272,
408,
272,
450,
4445,
480,
12485,
531,
7192,
63,
1875,
63,
5743,
63,
265,
63,
16557,
552,
29330,
63,
385,
447,
5743,
63,
929,
298,
272,
644,
8146,
314,
445,
4176,
26,
7192,
63,
5743,
63,
265,
63,
16557,
552,
29330,
63,
385,
447,
5743,
63,
929,
11436,
272,
408,
272,
986,
421,
199,
533,
4226,
1702,
2404,
14169,
8,
1563,
304,
2378,
4928,
275,
488,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
2585,
1702,
2404,
14169,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
768,
3744,
272,
347,
883,
63,
1122,
8,
1886,
12,
1559,
304,
267,
372,
1559,
14,
5091,
508,
843,
14,
5091,
339,
347,
663,
63,
21713,
8,
277,
12,
2198,
63,
576,
304,
267,
21064,
275,
1369,
8,
5675,
8,
1122,
63,
576,
12,
283,
19127,
1802,
297,
488,
430,
267,
13972,
275,
1369,
8,
5675,
8,
1122,
63,
576,
12,
283,
19170,
1802,
297,
488,
430,
267,
291,
423,
576,
459,
19127,
63,
1802,
418,
275,
21064,
267,
291,
423,
576,
459,
19170,
63,
1802,
418,
275,
13972,
260,
339,
347,
663,
63,
3214,
8,
277,
12,
666,
304,
267,
8118,
275,
359,
617,
67,
14,
585,
367,
366,
3833,
315,
666,
14,
19170,
1802,
14,
1317,
24601,
267,
299,
478,
275,
942,
267,
367,
373,
315,
8118,
26,
288,
340,
2688,
8,
86,
12,
283,
5329,
513,
735,
355,
299,
478,
847,
373,
14,
5329,
513,
267,
299,
374,
275,
942,
267,
367,
1620,
315,
299,
478,
26,
288,
299,
374,
847,
1620,
14,
8121,
6236,
563,
267,
12392,
374,
275,
942,
267,
367,
6682,
315,
299,
374,
26,
288,
26910,
275,
4226,
1702,
4720,
2081,
8,
1038,
9,
288,
26910,
423,
1122,
342,
288,
12392,
374,
14,
740,
8,
23595,
9,
267,
291,
423,
576,
459,
1162,
418,
275,
12392,
374,
421,
199,
533,
4226,
1702,
26552,
8,
2585,
1702,
2404,
14169,
304,
272,
986,
199,
199,
533,
4226,
1702,
7021,
8,
2585,
1702,
2404,
14169,
304,
272,
986,
199,
199,
533,
4226,
1702,
3481,
8,
2585,
1702,
7021,
304,
339,
636,
578,
363,
275,
298,
784,
23289,
14,
1208,
14,
1117,
1702,
1652,
2,
339,
4928,
275,
283,
1593,
7,
339,
347,
485,
1122,
8,
277,
304,
267,
340,
291,
423,
6751,
26,
288,
372,
267,
1613,
8,
2585,
1702,
3481,
12,
291,
10445,
1122,
342,
267,
291,
14,
409,
63,
21713,
8,
277,
423,
1122,
63,
576,
9,
267,
291,
14,
409,
63,
3214,
8,
277,
423,
1122,
63,
576,
9,
267,
340,
440,
291,
423,
576,
459,
1162,
2565,
288,
327,
982,
314,
1862,
781,
828,
1133,
663,
701,
282,
3721,
2066,
2951,
18200,
314,
1561,
14,
288,
291,
423,
576,
459,
1162,
418,
275,
942,
288,
5448,
706,
275,
291,
423,
1122,
63,
576,
14,
635,
288,
367,
5448,
77,
315,
5448,
706,
26,
355,
291,
423,
576,
459,
1162,
2278,
740,
8,
2585,
1702,
4098,
8,
2700,
77,
430,
339,
29226,
63,
1802,
275,
3324,
8,
2734,
291,
26,
291,
14,
576,
12047,
19127,
63,
1802,
1105,
272,
16212,
63,
1802,
275,
3324,
8,
2734,
291,
26,
291,
14,
576,
12047,
19170,
63,
1802,
1105,
272,
1862,
275,
3324,
8,
2734,
291,
26,
291,
14,
576,
12047,
1162,
1105,
199,
199,
1563,
14,
5286,
63,
2888,
14,
740,
8,
2585,
1702,
3481,
9,
421,
199,
533,
4226,
1702,
4098,
8,
2585,
1702,
7021,
304,
2286,
636,
578,
363,
275,
298
] | [
199,
3,
1898,
7129,
2868,
2290,
2752,
12,
3277,
14,
199,
3,
221,
199,
3,
961,
570,
365,
1777,
402,
1664,
13514,
199,
3,
221,
199,
3,
1664,
13514,
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,
12,
503,
334,
292,
2195,
945,
9,
199,
3,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
1664,
13514,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
1664,
13514,
27,
1937,
314,
570,
9685,
14,
221,
982,
440,
12,
2218,
370,
199,
3,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
14259,
12,
199,
3,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
199,
3,
221,
199,
624,
199,
15711,
13070,
1655,
922,
13,
17317,
8386,
370,
314,
886,
20515,
2748,
199,
4757,
2419,
314,
4046,
3992,
5647,
14,
199,
624,
199,
199,
646,
747,
199,
199,
504,
4046,
492,
1478,
199,
504,
1300,
492,
3523,
199,
504,
1318,
492,
1369,
199,
199,
533,
4226,
1702,
2681,
8,
1563,
304,
272,
408,
272,
29968,
282,
886,
20515,
2748,
2082,
14,
272,
408,
339,
636,
578,
363,
275,
298,
784,
23289,
14,
1208,
14,
1117,
1702,
1652,
2,
339,
347,
485,
1122,
8,
277,
304,
267,
340,
291,
423,
6751,
26,
288,
372,
267,
1613,
8,
2585,
1702,
2681,
12,
291,
10445,
1122,
342,
267,
291,
423,
1231,
275,
1478,
14,
1122,
8,
736,
14,
515,
14,
904,
8,
277,
423,
1652,
63,
515,
12,
283,
1080,
14,
1652,
1333,
755,
267,
367,
7573,
315,
291,
423,
1231,
14,
15278,
26,
288,
6702,
275,
291,
14,
3916,
63,
5286,
8,
5286,
9,
288,
327,
2104,
1584,
781,
2934,
314,
4072,
370,
506,
17909,
5370,
288,
327,
687,
314,
1676,
7830,
2419,
9445,
370,
2621,
4012,
314,
570,
288,
327,
909,
14,
288,
340,
291,
14,
362,
63,
1886,
8,
5286,
9,
508,
4226,
1702,
1173,
26,
355,
340,
7573,
14,
354,
14,
4130,
5175,
72,
735,
490,
291,
423,
6334,
847,
6702,
14,
6334,
342,
490,
291,
423,
6334,
14,
740,
8,
22818,
9,
288,
587,
26,
355,
291,
423,
6334,
14,
740,
8,
22818,
9,
421,
199,
318,
3550,
63,
9676,
63,
1301,
63,
73,
8,
277,
304,
272,
408,
272,
450,
4445,
480,
12485,
531,
7192,
63,
1875,
63,
5743,
63,
265,
63,
16557,
552,
29330,
63,
385,
447,
5743,
63,
929,
298,
272,
644,
8146,
314,
445,
4176,
26,
7192,
63,
5743,
63,
265,
63,
16557,
552,
29330,
63,
385,
447,
5743,
63,
929,
11436,
272,
408,
272,
986,
421,
199,
533,
4226,
1702,
2404,
14169,
8,
1563,
304,
2378,
4928,
275,
488,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
2585,
1702,
2404,
14169,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
339,
768,
3744,
272,
347,
883,
63,
1122,
8,
1886,
12,
1559,
304,
267,
372,
1559,
14,
5091,
508,
843,
14,
5091,
339,
347,
663,
63,
21713,
8,
277,
12,
2198,
63,
576,
304,
267,
21064,
275,
1369,
8,
5675,
8,
1122,
63,
576,
12,
283,
19127,
1802,
297,
488,
430,
267,
13972,
275,
1369,
8,
5675,
8,
1122,
63,
576,
12,
283,
19170,
1802,
297,
488,
430,
267,
291,
423,
576,
459,
19127,
63,
1802,
418,
275,
21064,
267,
291,
423,
576,
459,
19170,
63,
1802,
418,
275,
13972,
260,
339,
347,
663,
63,
3214,
8,
277,
12,
666,
304,
267,
8118,
275,
359,
617,
67,
14,
585,
367,
366,
3833,
315,
666,
14,
19170,
1802,
14,
1317,
24601,
267,
299,
478,
275,
942,
267,
367,
373,
315,
8118,
26,
288,
340,
2688,
8,
86,
12,
283,
5329,
513,
735,
355,
299,
478,
847,
373,
14,
5329,
513,
267,
299,
374,
275,
942,
267,
367,
1620,
315,
299,
478,
26,
288,
299,
374,
847,
1620,
14,
8121,
6236,
563,
267,
12392,
374,
275,
942,
267,
367,
6682,
315,
299,
374,
26,
288,
26910,
275,
4226,
1702,
4720,
2081,
8,
1038,
9,
288,
26910,
423,
1122,
342,
288,
12392,
374,
14,
740,
8,
23595,
9,
267,
291,
423,
576,
459,
1162,
418,
275,
12392,
374,
421,
199,
533,
4226,
1702,
26552,
8,
2585,
1702,
2404,
14169,
304,
272,
986,
199,
199,
533,
4226,
1702,
7021,
8,
2585,
1702,
2404,
14169,
304,
272,
986,
199,
199,
533,
4226,
1702,
3481,
8,
2585,
1702,
7021,
304,
339,
636,
578,
363,
275,
298,
784,
23289,
14,
1208,
14,
1117,
1702,
1652,
2,
339,
4928,
275,
283,
1593,
7,
339,
347,
485,
1122,
8,
277,
304,
267,
340,
291,
423,
6751,
26,
288,
372,
267,
1613,
8,
2585,
1702,
3481,
12,
291,
10445,
1122,
342,
267,
291,
14,
409,
63,
21713,
8,
277,
423,
1122,
63,
576,
9,
267,
291,
14,
409,
63,
3214,
8,
277,
423,
1122,
63,
576,
9,
267,
340,
440,
291,
423,
576,
459,
1162,
2565,
288,
327,
982,
314,
1862,
781,
828,
1133,
663,
701,
282,
3721,
2066,
2951,
18200,
314,
1561,
14,
288,
291,
423,
576,
459,
1162,
418,
275,
942,
288,
5448,
706,
275,
291,
423,
1122,
63,
576,
14,
635,
288,
367,
5448,
77,
315,
5448,
706,
26,
355,
291,
423,
576,
459,
1162,
2278,
740,
8,
2585,
1702,
4098,
8,
2700,
77,
430,
339,
29226,
63,
1802,
275,
3324,
8,
2734,
291,
26,
291,
14,
576,
12047,
19127,
63,
1802,
1105,
272,
16212,
63,
1802,
275,
3324,
8,
2734,
291,
26,
291,
14,
576,
12047,
19170,
63,
1802,
1105,
272,
1862,
275,
3324,
8,
2734,
291,
26,
291,
14,
576,
12047,
1162,
1105,
199,
199,
1563,
14,
5286,
63,
2888,
14,
740,
8,
2585,
1702,
3481,
9,
421,
199,
533,
4226,
1702,
4098,
8,
2585,
1702,
7021,
304,
2286,
636,
578,
363,
275,
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,
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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
] |
alexandrucoman/vbox-nova-driver | nova/tests/unit/api/openstack/compute/contrib/test_server_groups.py | 33 | 15330 | # Copyright (c) 2014 Cisco Systems, 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 oslo_utils import uuidutils
import webob
from nova.api.openstack.compute.contrib import server_groups
from nova.api.openstack.compute.plugins.v3 import server_groups as sg_v21
from nova.api.openstack import extensions
from nova import context
import nova.db
from nova import exception
from nova import objects
from nova import test
from nova.tests.unit.api.openstack import fakes
FAKE_UUID1 = 'a47ae74e-ab08-447f-8eee-ffd43fc46c16'
FAKE_UUID2 = 'c6e6430a-6563-4efa-9542-5e93c9e97d18'
FAKE_UUID3 = 'b8713410-9ba3-e913-901b-13410ca90121'
class AttrDict(dict):
def __getattr__(self, k):
return self[k]
def server_group_template(**kwargs):
sgroup = kwargs.copy()
sgroup.setdefault('name', 'test')
return sgroup
def server_group_resp_template(**kwargs):
sgroup = kwargs.copy()
sgroup.setdefault('name', 'test')
sgroup.setdefault('policies', [])
sgroup.setdefault('members', [])
return sgroup
def server_group_db(sg):
attrs = sg.copy()
if 'id' in attrs:
attrs['uuid'] = attrs.pop('id')
if 'policies' in attrs:
policies = attrs.pop('policies')
attrs['policies'] = policies
else:
attrs['policies'] = []
if 'members' in attrs:
members = attrs.pop('members')
attrs['members'] = members
else:
attrs['members'] = []
attrs['deleted'] = 0
attrs['deleted_at'] = None
attrs['created_at'] = None
attrs['updated_at'] = None
if 'user_id' not in attrs:
attrs['user_id'] = 'user_id'
if 'project_id' not in attrs:
attrs['project_id'] = 'project_id'
attrs['id'] = 7
return AttrDict(attrs)
class ServerGroupTestV21(test.TestCase):
validation_error = exception.ValidationError
def setUp(self):
super(ServerGroupTestV21, self).setUp()
self._setup_controller()
self.req = fakes.HTTPRequest.blank('')
def _setup_controller(self):
self.controller = sg_v21.ServerGroupController()
def test_create_server_group_with_no_policies(self):
sgroup = server_group_template()
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
def _create_server_group_normal(self, policies):
sgroup = server_group_template()
sgroup['policies'] = policies
res_dict = self.controller.create(self.req,
body={'server_group': sgroup})
self.assertEqual(res_dict['server_group']['name'], 'test')
self.assertTrue(uuidutils.is_uuid_like(res_dict['server_group']['id']))
self.assertEqual(res_dict['server_group']['policies'], policies)
def test_create_server_group(self):
policies = ['affinity', 'anti-affinity']
for policy in policies:
self._create_server_group_normal([policy])
def _create_instance(self, context):
instance = objects.Instance(context=context, image_ref=1, node='node1',
reservation_id='a', host='host1', project_id='fake',
vm_state='fake', system_metadata={'key': 'value'})
instance.create()
return instance
def _create_instance_group(self, context, members):
ig = objects.InstanceGroup(context=context, name='fake_name',
user_id='fake_user', project_id='fake',
members=members)
ig.create()
return ig.uuid
def _create_groups_and_instances(self, ctx):
instances = [self._create_instance(ctx), self._create_instance(ctx)]
members = [instance.uuid for instance in instances]
ig_uuid = self._create_instance_group(ctx, members)
return (ig_uuid, instances, members)
def test_display_members(self):
ctx = context.RequestContext('fake_user', 'fake')
(ig_uuid, instances, members) = self._create_groups_and_instances(ctx)
res_dict = self.controller.show(self.req, ig_uuid)
result_members = res_dict['server_group']['members']
self.assertEqual(2, len(result_members))
for member in members:
self.assertIn(member, result_members)
def test_display_active_members_only(self):
ctx = context.RequestContext('fake_user', 'fake')
(ig_uuid, instances, members) = self._create_groups_and_instances(ctx)
# delete an instance
instances[1].destroy()
# check that the instance does not exist
self.assertRaises(exception.InstanceNotFound,
objects.Instance.get_by_uuid,
ctx, instances[1].uuid)
res_dict = self.controller.show(self.req, ig_uuid)
result_members = res_dict['server_group']['members']
# check that only the active instance is displayed
self.assertEqual(1, len(result_members))
self.assertIn(instances[0].uuid, result_members)
def test_create_server_group_with_non_alphanumeric_in_name(self):
# The fix for bug #1434335 expanded the allowable character set
# for server group names to include non-alphanumeric characters
# if they are printable.
sgroup = server_group_template(name='good* $%name',
policies=['affinity'])
res_dict = self.controller.create(self.req,
body={'server_group': sgroup})
self.assertEqual(res_dict['server_group']['name'], 'good* $%name')
def test_create_server_group_with_illegal_name(self):
# blank name
sgroup = server_group_template(name='', policies=['test_policy'])
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
# name with length 256
sgroup = server_group_template(name='1234567890' * 26,
policies=['test_policy'])
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
# non-string name
sgroup = server_group_template(name=12, policies=['test_policy'])
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
# name with leading spaces
sgroup = server_group_template(name=' leading spaces',
policies=['test_policy'])
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
# name with trailing spaces
sgroup = server_group_template(name='trailing space ',
policies=['test_policy'])
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
# name with all spaces
sgroup = server_group_template(name=' ',
policies=['test_policy'])
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
# name with unprintable character
sgroup = server_group_template(name='bad\x00name',
policies=['test_policy'])
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
# name with out of range char U0001F4A9
sgroup = server_group_template(name=u"\U0001F4A9",
policies=['affinity'])
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
def test_create_server_group_with_illegal_policies(self):
# blank policy
sgroup = server_group_template(name='fake-name', policies='')
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
# policy as integer
sgroup = server_group_template(name='fake-name', policies=7)
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
# policy as string
sgroup = server_group_template(name='fake-name', policies='invalid')
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
# policy as None
sgroup = server_group_template(name='fake-name', policies=None)
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
def test_create_server_group_conflicting_policies(self):
sgroup = server_group_template()
policies = ['anti-affinity', 'affinity']
sgroup['policies'] = policies
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
def test_create_server_group_with_duplicate_policies(self):
sgroup = server_group_template()
policies = ['affinity', 'affinity']
sgroup['policies'] = policies
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
def test_create_server_group_not_supported(self):
sgroup = server_group_template()
policies = ['storage-affinity', 'anti-affinity', 'rack-affinity']
sgroup['policies'] = policies
self.assertRaises(self.validation_error, self.controller.create,
self.req, body={'server_group': sgroup})
def test_create_server_group_with_no_body(self):
self.assertRaises(self.validation_error,
self.controller.create, self.req, body=None)
def test_create_server_group_with_no_server_group(self):
body = {'no-instanceGroup': None}
self.assertRaises(self.validation_error,
self.controller.create, self.req, body=body)
def test_list_server_group_by_tenant(self):
groups = []
policies = ['anti-affinity']
members = []
metadata = {} # always empty
names = ['default-x', 'test']
sg1 = server_group_resp_template(id=str(1345),
name=names[0],
policies=policies,
members=members,
metadata=metadata)
sg2 = server_group_resp_template(id=str(891),
name=names[1],
policies=policies,
members=members,
metadata=metadata)
groups = [sg1, sg2]
expected = {'server_groups': groups}
def return_server_groups(context, project_id):
return [server_group_db(sg) for sg in groups]
self.stubs.Set(nova.db, 'instance_group_get_all_by_project_id',
return_server_groups)
res_dict = self.controller.index(self.req)
self.assertEqual(res_dict, expected)
def test_list_server_group_all(self):
all_groups = []
tenant_groups = []
policies = ['anti-affinity']
members = []
metadata = {} # always empty
names = ['default-x', 'test']
sg1 = server_group_resp_template(id=str(1345),
name=names[0],
policies=[],
members=members,
metadata=metadata)
sg2 = server_group_resp_template(id=str(891),
name=names[1],
policies=policies,
members=members,
metadata={})
tenant_groups = [sg2]
all_groups = [sg1, sg2]
all = {'server_groups': all_groups}
tenant_specific = {'server_groups': tenant_groups}
def return_all_server_groups(context):
return [server_group_db(sg) for sg in all_groups]
self.stubs.Set(nova.db, 'instance_group_get_all',
return_all_server_groups)
def return_tenant_server_groups(context, project_id):
return [server_group_db(sg) for sg in tenant_groups]
self.stubs.Set(nova.db, 'instance_group_get_all_by_project_id',
return_tenant_server_groups)
path = '/os-server-groups?all_projects=True'
req = fakes.HTTPRequest.blank(path, use_admin_context=True)
res_dict = self.controller.index(req)
self.assertEqual(res_dict, all)
req = fakes.HTTPRequest.blank(path)
res_dict = self.controller.index(req)
self.assertEqual(res_dict, tenant_specific)
def test_delete_server_group_by_id(self):
sg = server_group_template(id='123')
self.called = False
def server_group_delete(context, id):
self.called = True
def return_server_group(context, group_id):
self.assertEqual(sg['id'], group_id)
return server_group_db(sg)
self.stubs.Set(nova.db, 'instance_group_delete',
server_group_delete)
self.stubs.Set(nova.db, 'instance_group_get',
return_server_group)
resp = self.controller.delete(self.req, '123')
self.assertTrue(self.called)
# NOTE: on v2.1, http status code is set as wsgi_code of API
# method instead of status_int in a response object.
if isinstance(self.controller, sg_v21.ServerGroupController):
status_int = self.controller.delete.wsgi_code
else:
status_int = resp.status_int
self.assertEqual(204, status_int)
def test_delete_non_existing_server_group(self):
self.assertRaises(webob.exc.HTTPNotFound, self.controller.delete,
self.req, 'invalid')
class ServerGroupTestV2(ServerGroupTestV21):
validation_error = webob.exc.HTTPBadRequest
def _setup_controller(self):
ext_mgr = extensions.ExtensionManager()
ext_mgr.extensions = {}
self.controller = server_groups.ServerGroupController(ext_mgr)
| apache-2.0 | [
3,
1898,
334,
67,
9,
6927,
28356,
15285,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
11258,
63,
1208,
492,
5377,
1208,
199,
646,
14568,
199,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
2828,
492,
1654,
63,
2634,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
5265,
14,
86,
19,
492,
1654,
63,
2634,
465,
12578,
63,
86,
2025,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
492,
1067,
199,
646,
5913,
14,
697,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
2251,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
14,
3248,
14,
1246,
14,
8512,
492,
14063,
199,
199,
14623,
63,
8757,
17,
275,
283,
65,
2417,
3624,
1342,
69,
13,
371,
2036,
13,
20773,
70,
13,
24,
18777,
13,
30329,
2824,
3003,
2466,
67,
975,
7,
199,
14623,
63,
8757,
18,
275,
283,
67,
22,
69,
772,
1216,
65,
13,
22,
18199,
13,
20,
25015,
13,
25,
19861,
13,
21,
69,
3129,
67,
25,
69,
2576,
68,
1085,
7,
199,
14623,
63,
8757,
19,
275,
283,
66,
1555,
7582,
709,
13,
25,
2470,
19,
13,
69,
25,
969,
13,
23166,
66,
13,
7582,
709,
696,
23166,
2025,
7,
421,
199,
533,
20516,
2141,
8,
807,
304,
272,
347,
636,
5675,
721,
277,
12,
1022,
304,
267,
372,
291,
59,
75,
61,
421,
199,
318,
1654,
63,
923,
63,
1160,
3682,
958,
304,
272,
308,
923,
275,
2074,
14,
1574,
342,
272,
308,
923,
14,
5486,
360,
354,
297,
283,
396,
358,
272,
372,
308,
923,
421,
199,
318,
1654,
63,
923,
63,
4518,
63,
1160,
3682,
958,
304,
272,
308,
923,
275,
2074,
14,
1574,
342,
272,
308,
923,
14,
5486,
360,
354,
297,
283,
396,
358,
272,
308,
923,
14,
5486,
360,
11767,
297,
3073,
272,
308,
923,
14,
5486,
360,
6334,
297,
3073,
272,
372,
308,
923,
421,
199,
318,
1654,
63,
923,
63,
697,
8,
1226,
304,
272,
3290,
275,
12578,
14,
1574,
342,
272,
340,
283,
344,
7,
315,
3290,
26,
267,
3290,
459,
2580,
418,
275,
3290,
14,
1935,
360,
344,
358,
272,
340,
283,
11767,
7,
315,
3290,
26,
267,
14118,
275,
3290,
14,
1935,
360,
11767,
358,
267,
3290,
459,
11767,
418,
275,
14118,
272,
587,
26,
267,
3290,
459,
11767,
418,
275,
942,
272,
340,
283,
6334,
7,
315,
3290,
26,
267,
7556,
275,
3290,
14,
1935,
360,
6334,
358,
267,
3290,
459,
6334,
418,
275,
7556,
272,
587,
26,
267,
3290,
459,
6334,
418,
275,
942,
272,
3290,
459,
6062,
418,
275,
378,
272,
3290,
459,
6062,
63,
292,
418,
275,
488,
272,
3290,
459,
3966,
63,
292,
418,
275,
488,
272,
3290,
459,
5334,
63,
292,
418,
275,
488,
272,
340,
283,
751,
63,
344,
7,
440,
315,
3290,
26,
267,
3290,
459,
751,
63,
344,
418,
275,
283,
751,
63,
344,
7,
272,
340,
283,
1715,
63,
344,
7,
440,
315,
3290,
26,
267,
3290,
459,
1715,
63,
344,
418,
275,
283,
1715,
63,
344,
7,
272,
3290,
459,
344,
418,
275,
1520,
339,
372,
20516,
2141,
8,
3288,
9,
421,
199,
533,
7146,
2448,
774,
54,
2025,
8,
396,
14,
1746,
304,
272,
6411,
63,
705,
275,
1919,
14,
8172,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
3120,
2448,
774,
54,
2025,
12,
291,
680,
5996,
342,
267,
291,
423,
2758,
63,
5538,
342,
267,
291,
14,
2103,
275,
14063,
14,
21053,
14,
2500,
8355,
339,
347,
485,
2758,
63,
5538,
8,
277,
304,
267,
291,
14,
5538,
275,
12578,
63,
86,
2025,
14,
3120,
2448,
7506,
342,
339,
347,
511,
63,
981,
63,
1000,
63,
923,
63,
1045,
63,
889,
63,
11767,
8,
277,
304,
267,
308,
923,
275,
1654,
63,
923,
63,
1160,
342,
267,
291,
14,
1855,
8,
277,
14,
6136,
63,
705,
12,
291,
14,
5538,
14,
981,
12,
2079,
291,
14,
2103,
12,
2396,
3713,
1000,
63,
923,
356,
308,
923,
1552,
339,
347,
485,
981,
63,
1000,
63,
923,
63,
3302,
8,
277,
12,
14118,
304,
267,
308,
923,
275,
1654,
63,
923,
63,
1160,
342,
267,
308,
923,
459,
11767,
418,
275,
14118,
267,
522,
63,
807,
275,
291,
14,
5538,
14,
981,
8,
277,
14,
2103,
12,
5101,
2396,
3713,
1000,
63,
923,
356,
308,
923,
1552,
267,
291,
14,
629,
8,
470,
63,
807,
459,
1000,
63,
923,
2545,
354,
995,
283,
396,
358,
267,
291,
14,
1815,
8,
2580,
1208,
14,
374,
63,
2580,
63,
2930,
8,
470,
63,
807,
459,
1000,
63,
923,
2545,
344,
5156,
267,
291,
14,
629,
8,
470,
63,
807,
459,
1000,
63,
923,
2545,
11767,
995,
14118,
9,
339,
347,
511,
63,
981,
63,
1000,
63,
923,
8,
277,
304,
267,
14118,
275,
788,
15964,
297,
283,
4466,
13,
15964,
418,
267,
367,
4592,
315,
14118,
26,
288,
291,
423,
981,
63,
1000,
63,
923,
63,
3302,
779,
3185,
566,
339,
347,
485,
981,
63,
842,
8,
277,
12,
1067,
304,
267,
1256,
275,
2251,
14,
3244,
8,
1100,
29,
1100,
12,
1834,
63,
1121,
29,
17,
12,
1031,
534,
932,
17,
297,
355,
25476,
63,
344,
534,
65,
297,
1591,
534,
1102,
17,
297,
2199,
63,
344,
534,
3183,
297,
355,
4169,
63,
929,
534,
3183,
297,
2656,
63,
2343,
3713,
498,
356,
283,
585
] | [
1898,
334,
67,
9,
6927,
28356,
15285,
12,
3277,
14,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
11258,
63,
1208,
492,
5377,
1208,
199,
646,
14568,
199,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
2828,
492,
1654,
63,
2634,
199,
504,
5913,
14,
1246,
14,
8512,
14,
3357,
14,
5265,
14,
86,
19,
492,
1654,
63,
2634,
465,
12578,
63,
86,
2025,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
492,
1067,
199,
646,
5913,
14,
697,
199,
504,
5913,
492,
1919,
199,
504,
5913,
492,
2251,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
14,
3248,
14,
1246,
14,
8512,
492,
14063,
199,
199,
14623,
63,
8757,
17,
275,
283,
65,
2417,
3624,
1342,
69,
13,
371,
2036,
13,
20773,
70,
13,
24,
18777,
13,
30329,
2824,
3003,
2466,
67,
975,
7,
199,
14623,
63,
8757,
18,
275,
283,
67,
22,
69,
772,
1216,
65,
13,
22,
18199,
13,
20,
25015,
13,
25,
19861,
13,
21,
69,
3129,
67,
25,
69,
2576,
68,
1085,
7,
199,
14623,
63,
8757,
19,
275,
283,
66,
1555,
7582,
709,
13,
25,
2470,
19,
13,
69,
25,
969,
13,
23166,
66,
13,
7582,
709,
696,
23166,
2025,
7,
421,
199,
533,
20516,
2141,
8,
807,
304,
272,
347,
636,
5675,
721,
277,
12,
1022,
304,
267,
372,
291,
59,
75,
61,
421,
199,
318,
1654,
63,
923,
63,
1160,
3682,
958,
304,
272,
308,
923,
275,
2074,
14,
1574,
342,
272,
308,
923,
14,
5486,
360,
354,
297,
283,
396,
358,
272,
372,
308,
923,
421,
199,
318,
1654,
63,
923,
63,
4518,
63,
1160,
3682,
958,
304,
272,
308,
923,
275,
2074,
14,
1574,
342,
272,
308,
923,
14,
5486,
360,
354,
297,
283,
396,
358,
272,
308,
923,
14,
5486,
360,
11767,
297,
3073,
272,
308,
923,
14,
5486,
360,
6334,
297,
3073,
272,
372,
308,
923,
421,
199,
318,
1654,
63,
923,
63,
697,
8,
1226,
304,
272,
3290,
275,
12578,
14,
1574,
342,
272,
340,
283,
344,
7,
315,
3290,
26,
267,
3290,
459,
2580,
418,
275,
3290,
14,
1935,
360,
344,
358,
272,
340,
283,
11767,
7,
315,
3290,
26,
267,
14118,
275,
3290,
14,
1935,
360,
11767,
358,
267,
3290,
459,
11767,
418,
275,
14118,
272,
587,
26,
267,
3290,
459,
11767,
418,
275,
942,
272,
340,
283,
6334,
7,
315,
3290,
26,
267,
7556,
275,
3290,
14,
1935,
360,
6334,
358,
267,
3290,
459,
6334,
418,
275,
7556,
272,
587,
26,
267,
3290,
459,
6334,
418,
275,
942,
272,
3290,
459,
6062,
418,
275,
378,
272,
3290,
459,
6062,
63,
292,
418,
275,
488,
272,
3290,
459,
3966,
63,
292,
418,
275,
488,
272,
3290,
459,
5334,
63,
292,
418,
275,
488,
272,
340,
283,
751,
63,
344,
7,
440,
315,
3290,
26,
267,
3290,
459,
751,
63,
344,
418,
275,
283,
751,
63,
344,
7,
272,
340,
283,
1715,
63,
344,
7,
440,
315,
3290,
26,
267,
3290,
459,
1715,
63,
344,
418,
275,
283,
1715,
63,
344,
7,
272,
3290,
459,
344,
418,
275,
1520,
339,
372,
20516,
2141,
8,
3288,
9,
421,
199,
533,
7146,
2448,
774,
54,
2025,
8,
396,
14,
1746,
304,
272,
6411,
63,
705,
275,
1919,
14,
8172,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
3120,
2448,
774,
54,
2025,
12,
291,
680,
5996,
342,
267,
291,
423,
2758,
63,
5538,
342,
267,
291,
14,
2103,
275,
14063,
14,
21053,
14,
2500,
8355,
339,
347,
485,
2758,
63,
5538,
8,
277,
304,
267,
291,
14,
5538,
275,
12578,
63,
86,
2025,
14,
3120,
2448,
7506,
342,
339,
347,
511,
63,
981,
63,
1000,
63,
923,
63,
1045,
63,
889,
63,
11767,
8,
277,
304,
267,
308,
923,
275,
1654,
63,
923,
63,
1160,
342,
267,
291,
14,
1855,
8,
277,
14,
6136,
63,
705,
12,
291,
14,
5538,
14,
981,
12,
2079,
291,
14,
2103,
12,
2396,
3713,
1000,
63,
923,
356,
308,
923,
1552,
339,
347,
485,
981,
63,
1000,
63,
923,
63,
3302,
8,
277,
12,
14118,
304,
267,
308,
923,
275,
1654,
63,
923,
63,
1160,
342,
267,
308,
923,
459,
11767,
418,
275,
14118,
267,
522,
63,
807,
275,
291,
14,
5538,
14,
981,
8,
277,
14,
2103,
12,
5101,
2396,
3713,
1000,
63,
923,
356,
308,
923,
1552,
267,
291,
14,
629,
8,
470,
63,
807,
459,
1000,
63,
923,
2545,
354,
995,
283,
396,
358,
267,
291,
14,
1815,
8,
2580,
1208,
14,
374,
63,
2580,
63,
2930,
8,
470,
63,
807,
459,
1000,
63,
923,
2545,
344,
5156,
267,
291,
14,
629,
8,
470,
63,
807,
459,
1000,
63,
923,
2545,
11767,
995,
14118,
9,
339,
347,
511,
63,
981,
63,
1000,
63,
923,
8,
277,
304,
267,
14118,
275,
788,
15964,
297,
283,
4466,
13,
15964,
418,
267,
367,
4592,
315,
14118,
26,
288,
291,
423,
981,
63,
1000,
63,
923,
63,
3302,
779,
3185,
566,
339,
347,
485,
981,
63,
842,
8,
277,
12,
1067,
304,
267,
1256,
275,
2251,
14,
3244,
8,
1100,
29,
1100,
12,
1834,
63,
1121,
29,
17,
12,
1031,
534,
932,
17,
297,
355,
25476,
63,
344,
534,
65,
297,
1591,
534,
1102,
17,
297,
2199,
63,
344,
534,
3183,
297,
355,
4169,
63,
929,
534,
3183,
297,
2656,
63,
2343,
3713,
498,
356,
283,
585,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
cpcloud/PyTables | contrib/make_hdf.py | 14 | 10754 | #!/usr/bin/env python
from __future__ import generators
import tables, cPickle, time
#################################################################################
def is_scalar(item):
try:
iter(item)
#could be a string
try:
item[:0]+'' #check for string
return 'str'
except:
return 0
except:
return 'notstr'
def is_dict(item):
try:
item.iteritems()
return 1
except:
return 0
def make_col(row_type, row_name, row_item, str_len):
'''for strings it will always make at least 80 char or twice mac char size'''
set_len=80
if str_len:
if 2*str_len>set_len:
set_len=2*str_len
row_type[row_name]=tables.Col("CharType", set_len)
else:
type_matrix={
int: tables.Col("Int32", 1),
float: tables.Col("Float32", 4), #Col("Int16", 1)
}
row_type[row_name]=type_matrix[type(row_item)]
def make_row(data):
row_type={}
scalar_type=is_scalar(data)
if scalar_type:
if scalar_type=='str':
make_col(row_type, 'scalar', data, len(data))
else:
make_col(row_type, 'scalar', data, 0)
else: #it is a list-like
the_type=is_scalar(data[0])
if the_type=='str':
#get max length
the_max=0
for i in data:
if len(i)>the_max:
the_max=len(i)
make_col(row_type, 'col', data[0], the_max)
elif the_type:
make_col(row_type, 'col', data[0], 0)
else: #list within the list, make many columns
make_col(row_type, 'col_depth', 0, 0)
count=0
for col in data:
the_type=is_scalar(col[0])
if the_type=='str':
#get max length
the_max=0
for i in data:
if len(i)>the_max:
the_max=len(i)
make_col(row_type, 'col_'+str(count), col[0], the_max)
elif the_type:
make_col(row_type, 'col_'+str(count), col[0], 0)
else:
raise ValueError('too many nested levels of lists')
count+=1
return row_type
def add_table(fileh, group_obj, data, table_name):
#figure out if it is a list of lists or a single list
#get types of columns
row_type=make_row(data)
table1=fileh.createTable(group_obj, table_name, row_type, 'H', compress=1)
row=table1.row
if is_scalar(data):
row['scalar']=data
row.append()
else:
if is_scalar(data[0]):
for i in data:
row['col']=i
row.append()
else:
count=0
for col in data:
row['col_depth']=len(col)
for the_row in col:
if is_scalar(the_row):
row['col_'+str(count)]=the_row
row.append()
else:
raise ValueError('too many levels of lists')
count+=1
table1.flush()
def add_cache(fileh, cache):
group_name='pytables_cache_v0';table_name='cache0'
root=fileh.root
group_obj=fileh.createGroup(root, group_name)
cache_str=cPickle.dumps(cache, 0)
cache_str=cache_str.replace('\n', chr(1))
cache_pieces=[]
while cache_str:
cache_part=cache_str[:8000];cache_str=cache_str[8000:]
if cache_part:
cache_pieces.append(cache_part)
row_type={}
row_type['col_0']=tables.Col("CharType", 8000)
#
table_cache=fileh.createTable(group_obj, table_name, row_type, 'H', compress =1)
for piece in cache_pieces:
print len(piece)
table_cache.row['col_0']=piece
table_cache.row.append()
table_cache.flush()
def save2(hdf_file, data):
fileh=tables.openFile(hdf_file, mode='w', title='logon history')
root=fileh.root;cache_root=cache={}
root_path=root._v_pathname;root=0
stack = [ (root_path, data, cache) ]
table_num=0
count=0
while stack:
(group_obj_path, data, cache)=stack.pop()
#data='wilma':{'mother':[22,23,24]}}
#grp_name wilma
for grp_name in data:
#print 'fileh=',fileh
count+=1
cache[grp_name]={}
new_group_obj=fileh.createGroup(group_obj_path, grp_name)
#print 'path=',new_group_obj._v_pathname
new_path=new_group_obj._v_pathname
#if dict, you have a bunch of groups
if is_dict(data[grp_name]):#{'mother':[22,23,24]}
stack.append((new_path, data[grp_name], cache[grp_name]))
#you have a table
else:
#data[grp_name]=[110,130,140],[1,2,3]
add_table(fileh, new_path, data[grp_name], 'tbl_'+str(table_num))
table_num+=1
#fileh=tables.openFile(hdf_file,mode='a',title='logon history')
add_cache(fileh, cache_root)
fileh.close()
########################
class Hdf_dict(dict):
def __init__(self,hdf_file,hdf_dict={},stack=[]):
self.hdf_file=hdf_file
self.stack=stack
if stack:
self.hdf_dict=hdf_dict
else:
self.hdf_dict=self.get_cache()
self.cur_dict=self.hdf_dict
def get_cache(self):
fileh=tables.openFile(self.hdf_file, rootUEP='pytables_cache_v0')
table=fileh.root.cache0
total=[]
print 'reading'
begin=time.time()
for i in table.iterrows():
total.append(i['col_0'])
total=''.join(total)
total=total.replace(chr(1), '\n')
print 'loaded cache len=', len(total), time.time()-begin
begin=time.time()
a=cPickle.loads(total)
print 'cache', time.time()-begin
return a
def has_key(self, k):
return k in self.cur_dict
def keys(self):
return self.cur_dict.keys()
def get(self,key,default=None):
try:
return self.__getitem__(key)
except:
return default
def items(self):
return list(self.iteritems())
def values(self):
return list(self.itervalues())
###########################################
def __len__(self):
return len(self.cur_dict)
def __getitem__(self, k):
if k in self.cur_dict:
#now check if k has any data
if self.cur_dict[k]:
new_stack=self.stack[:]
new_stack.append(k)
return Hdf_dict(self.hdf_file, hdf_dict=self.cur_dict[k], stack=new_stack)
else:
new_stack=self.stack[:]
new_stack.append(k)
fileh=tables.openFile(self.hdf_file, rootUEP='/'.join(new_stack))
#cur_data=getattr(self.cur_group,k) #/wilma (Group) '' =getattr(/ (Group) 'logon history',wilma)
for table in fileh.root:
#return [ i['col_1'] for i in table.iterrows() ] #[9110,91]
#perhaps they stored a single item
try:
for item in table['scalar']:
return item
except:
#otherwise they stored a list of data
try:
return [ item for item in table['col']]
except:
cur_column=[]
total_columns=[]
col_num=0
cur_row=0
num_rows=0
for row in table:
if not num_rows:
num_rows=row['col_depth']
if cur_row==num_rows:
cur_row=num_rows=0
col_num+=1
total_columns.append(cur_column)
cur_column=[]
cur_column.append( row['col_'+str(col_num)])
cur_row+=1
total_columns.append(cur_column)
return total_columns
else:
raise KeyError(k)
def iterkeys(self):
for key in self.iterkeys():
yield key
def __iter__(self):
return self.iterkeys()
def itervalues(self):
for k in self.iterkeys():
v=self.__getitem__(k)
yield v
def iteritems(self):
# yield children
for k in self.iterkeys():
v=self.__getitem__(k)
yield (k, v)
def __repr__(self):
return '{Hdf dict}'
def __str__(self):
return self.__repr__()
#####
def setdefault(self,key,default=None):
try:
return self.__getitem__(key)
except:
self.__setitem__(key)
return default
def update(self, d):
for k, v in d.iteritems():
self.__setitem__(k, v)
def popitem(self):
try:
k, v = self.iteritems().next()
del self[k]
return k, v
except StopIteration:
raise KeyError("Hdf Dict is empty")
def __setitem__(self, key, value):
raise NotImplementedError
def __delitem__(self, key):
raise NotImplementedError
def __hash__(self):
raise TypeError("Hdf dict bjects are unhashable")
if __name__=='__main__':
def write_small(file=''):
data1={
'fred':['a', 'b', 'c'],
'barney':[[9110, 9130, 9140], [91, 92, 93]],
'wilma':{'mother':{'pebbles':[22, 23, 24],'bambam':[67, 68, 69]}}
}
print 'saving'
save2(file, data1)
print 'saved'
def read_small(file=''):
#a=make_hdf.Hdf_dict(file)
a=Hdf_dict(file)
print a['wilma']
b=a['wilma']
for i in b:
print i
print a.keys()
print 'has fred', bool('fred' in a)
print 'length a', len(a)
print 'get', a.get('fred'), a.get('not here')
print 'wilma keys', a['wilma'].keys()
print 'barney', a['barney']
print 'get items'
print a.items()
for i in a.iteritems():
print 'item', i
for i in a.itervalues():
print i
a=raw_input('enter y to write out test file to test.hdf')
if a.strip()=='y':
print 'writing'
write_small('test.hdf')
print 'reading'
read_small('test.hdf')
| bsd-3-clause | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
636,
2443,
363,
492,
16952,
199,
199,
646,
6716,
12,
17572,
12,
900,
199,
13289,
3,
421,
199,
318,
365,
63,
7033,
8,
1053,
304,
272,
862,
26,
267,
2740,
8,
1053,
9,
267,
327,
15153,
506,
282,
1059,
267,
862,
26,
288,
1242,
1491,
16,
2807,
891,
327,
1074,
367,
1059,
288,
372,
283,
495,
7,
267,
871,
26,
288,
372,
378,
272,
871,
26,
267,
372,
283,
1397,
495,
7,
421,
199,
318,
365,
63,
807,
8,
1053,
304,
272,
862,
26,
267,
1242,
14,
4611,
342,
267,
372,
413,
272,
871,
26,
267,
372,
378,
421,
199,
318,
1852,
63,
761,
8,
1143,
63,
466,
12,
1962,
63,
354,
12,
1962,
63,
1053,
12,
620,
63,
552,
304,
272,
1449,
509,
3326,
652,
911,
3544,
1852,
737,
5210,
5939,
1495,
503,
13373,
4497,
1495,
1568,
2344,
272,
663,
63,
552,
29,
1257,
272,
340,
620,
63,
552,
26,
267,
340,
499,
10,
495,
63,
552,
30,
409,
63,
552,
26,
288,
663,
63,
552,
29,
18,
10,
495,
63,
552,
267,
1962,
63,
466,
59,
1143,
63,
354,
10404,
5987,
14,
2001,
480,
1610,
804,
401,
663,
63,
552,
9,
272,
587,
26,
267,
730,
63,
3642,
3126,
288,
1109,
26,
6716,
14,
2001,
480,
3241,
708,
401,
413,
395,
288,
2069,
26,
6716,
14,
2001,
480,
5136,
708,
401,
841,
395,
327,
2001,
480,
3241,
975,
401,
413,
9,
288,
789,
267,
1962,
63,
466,
59,
1143,
63,
354,
10404,
466,
63,
3642,
59,
466,
8,
1143,
63,
1053,
1874,
421,
199,
318,
1852,
63,
1143,
8,
576,
304,
272,
1962,
63,
466,
7622,
272,
6917,
63,
466,
29,
374,
63,
7033,
8,
576,
9,
272,
340,
6917,
63,
466,
26,
267,
340,
6917,
63,
466,
6803,
495,
356,
288,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
7033,
297,
666,
12,
822,
8,
576,
430,
267,
587,
26,
288,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
7033,
297,
666,
12,
378,
9,
272,
587,
26,
327,
390,
365,
282,
769,
13,
2930,
267,
314,
63,
466,
29,
374,
63,
7033,
8,
576,
59,
16,
566,
267,
340,
314,
63,
466,
6803,
495,
356,
288,
327,
362,
1390,
2582,
288,
314,
63,
988,
29,
16,
288,
367,
284,
315,
666,
26,
1598,
340,
822,
8,
73,
13032,
1589,
63,
988,
26,
326,
314,
63,
988,
29,
552,
8,
73,
9,
288,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
761,
297,
666,
59,
16,
467,
314,
63,
988,
9,
267,
916,
314,
63,
466,
26,
288,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
761,
297,
666,
59,
16,
467,
378,
9,
267,
587,
26,
327,
513,
4453,
314,
769,
12,
1852,
5002,
4362,
288,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
761,
63,
4631,
297,
378,
12,
378,
9,
288,
2338,
29,
16,
288,
367,
1048,
315,
666,
26,
355,
314,
63,
466,
29,
374,
63,
7033,
8,
761,
59,
16,
566,
355,
340,
314,
63,
466,
6803,
495,
356,
490,
327,
362,
1390,
2582,
490,
314,
63,
988,
29,
16,
490,
367,
284,
315,
666,
26,
1993,
340,
822,
8,
73,
13032,
1589,
63,
988,
26,
586,
314,
63,
988,
29,
552,
8,
73,
9,
490,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
761,
20013,
495,
8,
835,
395,
1048,
59,
16,
467,
314,
63,
988,
9,
355,
916,
314,
63,
466,
26,
490,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
761,
20013,
495,
8,
835,
395,
1048,
59,
16,
467,
378,
9,
355,
587,
26,
490,
746,
1722,
360,
7354,
5002,
6032,
11106,
402,
5548,
358,
355,
2338,
10365,
17,
272,
372,
1962,
63,
466,
421,
199,
318,
1050,
63,
1224,
8,
493,
72,
12,
1572,
63,
1113,
12,
666,
12,
1817,
63,
354,
304,
272,
327,
8941,
734,
340,
652,
365,
282,
769,
402,
5548,
503,
282,
2849,
769,
272,
327,
362,
2943,
402,
4362,
272,
1962,
63,
466,
29,
1875,
63,
1143,
8,
576,
9,
272,
1817,
17,
29,
493,
72,
14,
981,
3186,
8,
923,
63,
1113,
12,
1817,
63,
354,
12,
1962,
63,
466,
12,
283,
40,
297,
11029,
29,
17,
9,
272,
1962,
29,
1224,
17,
14,
1143,
339,
340,
365,
63,
7033,
8,
576,
304,
267,
1962,
459,
7033,
13784,
576,
267,
1962,
14,
740,
342,
272,
587,
26,
267,
340,
365,
63,
7033,
8,
576,
59,
16,
4682,
288,
367,
284,
315,
666,
26,
355,
1962,
459,
761,
13784,
73,
355,
1962,
14,
740,
342,
267,
587,
26,
288,
2338,
29,
16,
288,
367,
1048,
315,
666,
26,
355,
1962,
459,
761,
63,
4631,
13784,
552,
8,
761,
9,
355,
367,
314,
63,
1143,
315,
1048,
26,
490,
340,
365,
63,
7033,
8,
1589,
63,
1143,
304,
717,
1962,
459,
761,
20013,
495,
8,
835,
1874,
29,
1589,
63,
1143,
717,
1962,
14,
740,
342,
490,
587,
26,
717,
746,
1722,
360,
7354,
5002,
11106,
402,
5548,
358,
355,
2338,
10365,
17,
272,
1817,
17,
14,
4939,
342,
421,
199,
318,
1050,
63,
1637,
8,
493,
72,
12,
2581,
304,
272,
1572,
63,
354,
534,
647,
5987,
63,
1637,
63,
86,
16,
13619,
1224,
63,
354,
534,
1637,
16,
7,
272,
1738,
29,
493,
72,
14,
1231,
272,
1572,
63,
1113,
29,
493,
72,
14,
981,
2448,
8,
1231,
12,
1572,
63,
354,
9,
272,
2581,
63,
495,
29,
67,
12755,
14,
4180,
8,
1637,
12,
378,
9,
272,
2581,
63,
495,
29,
1637,
63,
495,
14,
1814,
2258,
78,
297,
8678,
8,
17,
430,
272,
2581,
63,
15655,
9811,
272,
1830,
2581,
63,
495,
26,
267,
2581,
63,
2064,
29,
1637,
63,
495,
1491,
15214,
11566,
1637,
63,
495,
29,
1637,
63,
495,
59,
15214,
2938,
267,
340,
2581,
63,
2064,
26,
288,
2581,
63,
15655,
14,
740,
8,
1637,
63,
2064,
9,
272,
1962,
63,
466,
7622,
272,
1962,
63,
466,
459,
761,
63,
16,
13784,
5987,
14,
2001,
480,
1610,
804,
401,
29855,
9,
272,
327,
272,
1817,
63,
1637,
29,
493,
72,
14,
981,
3186,
8,
923,
63,
1113,
12,
1817,
63,
354,
12,
1962
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
199,
504,
636,
2443,
363,
492,
16952,
199,
199,
646,
6716,
12,
17572,
12,
900,
199,
13289,
3,
421,
199,
318,
365,
63,
7033,
8,
1053,
304,
272,
862,
26,
267,
2740,
8,
1053,
9,
267,
327,
15153,
506,
282,
1059,
267,
862,
26,
288,
1242,
1491,
16,
2807,
891,
327,
1074,
367,
1059,
288,
372,
283,
495,
7,
267,
871,
26,
288,
372,
378,
272,
871,
26,
267,
372,
283,
1397,
495,
7,
421,
199,
318,
365,
63,
807,
8,
1053,
304,
272,
862,
26,
267,
1242,
14,
4611,
342,
267,
372,
413,
272,
871,
26,
267,
372,
378,
421,
199,
318,
1852,
63,
761,
8,
1143,
63,
466,
12,
1962,
63,
354,
12,
1962,
63,
1053,
12,
620,
63,
552,
304,
272,
1449,
509,
3326,
652,
911,
3544,
1852,
737,
5210,
5939,
1495,
503,
13373,
4497,
1495,
1568,
2344,
272,
663,
63,
552,
29,
1257,
272,
340,
620,
63,
552,
26,
267,
340,
499,
10,
495,
63,
552,
30,
409,
63,
552,
26,
288,
663,
63,
552,
29,
18,
10,
495,
63,
552,
267,
1962,
63,
466,
59,
1143,
63,
354,
10404,
5987,
14,
2001,
480,
1610,
804,
401,
663,
63,
552,
9,
272,
587,
26,
267,
730,
63,
3642,
3126,
288,
1109,
26,
6716,
14,
2001,
480,
3241,
708,
401,
413,
395,
288,
2069,
26,
6716,
14,
2001,
480,
5136,
708,
401,
841,
395,
327,
2001,
480,
3241,
975,
401,
413,
9,
288,
789,
267,
1962,
63,
466,
59,
1143,
63,
354,
10404,
466,
63,
3642,
59,
466,
8,
1143,
63,
1053,
1874,
421,
199,
318,
1852,
63,
1143,
8,
576,
304,
272,
1962,
63,
466,
7622,
272,
6917,
63,
466,
29,
374,
63,
7033,
8,
576,
9,
272,
340,
6917,
63,
466,
26,
267,
340,
6917,
63,
466,
6803,
495,
356,
288,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
7033,
297,
666,
12,
822,
8,
576,
430,
267,
587,
26,
288,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
7033,
297,
666,
12,
378,
9,
272,
587,
26,
327,
390,
365,
282,
769,
13,
2930,
267,
314,
63,
466,
29,
374,
63,
7033,
8,
576,
59,
16,
566,
267,
340,
314,
63,
466,
6803,
495,
356,
288,
327,
362,
1390,
2582,
288,
314,
63,
988,
29,
16,
288,
367,
284,
315,
666,
26,
1598,
340,
822,
8,
73,
13032,
1589,
63,
988,
26,
326,
314,
63,
988,
29,
552,
8,
73,
9,
288,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
761,
297,
666,
59,
16,
467,
314,
63,
988,
9,
267,
916,
314,
63,
466,
26,
288,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
761,
297,
666,
59,
16,
467,
378,
9,
267,
587,
26,
327,
513,
4453,
314,
769,
12,
1852,
5002,
4362,
288,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
761,
63,
4631,
297,
378,
12,
378,
9,
288,
2338,
29,
16,
288,
367,
1048,
315,
666,
26,
355,
314,
63,
466,
29,
374,
63,
7033,
8,
761,
59,
16,
566,
355,
340,
314,
63,
466,
6803,
495,
356,
490,
327,
362,
1390,
2582,
490,
314,
63,
988,
29,
16,
490,
367,
284,
315,
666,
26,
1993,
340,
822,
8,
73,
13032,
1589,
63,
988,
26,
586,
314,
63,
988,
29,
552,
8,
73,
9,
490,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
761,
20013,
495,
8,
835,
395,
1048,
59,
16,
467,
314,
63,
988,
9,
355,
916,
314,
63,
466,
26,
490,
1852,
63,
761,
8,
1143,
63,
466,
12,
283,
761,
20013,
495,
8,
835,
395,
1048,
59,
16,
467,
378,
9,
355,
587,
26,
490,
746,
1722,
360,
7354,
5002,
6032,
11106,
402,
5548,
358,
355,
2338,
10365,
17,
272,
372,
1962,
63,
466,
421,
199,
318,
1050,
63,
1224,
8,
493,
72,
12,
1572,
63,
1113,
12,
666,
12,
1817,
63,
354,
304,
272,
327,
8941,
734,
340,
652,
365,
282,
769,
402,
5548,
503,
282,
2849,
769,
272,
327,
362,
2943,
402,
4362,
272,
1962,
63,
466,
29,
1875,
63,
1143,
8,
576,
9,
272,
1817,
17,
29,
493,
72,
14,
981,
3186,
8,
923,
63,
1113,
12,
1817,
63,
354,
12,
1962,
63,
466,
12,
283,
40,
297,
11029,
29,
17,
9,
272,
1962,
29,
1224,
17,
14,
1143,
339,
340,
365,
63,
7033,
8,
576,
304,
267,
1962,
459,
7033,
13784,
576,
267,
1962,
14,
740,
342,
272,
587,
26,
267,
340,
365,
63,
7033,
8,
576,
59,
16,
4682,
288,
367,
284,
315,
666,
26,
355,
1962,
459,
761,
13784,
73,
355,
1962,
14,
740,
342,
267,
587,
26,
288,
2338,
29,
16,
288,
367,
1048,
315,
666,
26,
355,
1962,
459,
761,
63,
4631,
13784,
552,
8,
761,
9,
355,
367,
314,
63,
1143,
315,
1048,
26,
490,
340,
365,
63,
7033,
8,
1589,
63,
1143,
304,
717,
1962,
459,
761,
20013,
495,
8,
835,
1874,
29,
1589,
63,
1143,
717,
1962,
14,
740,
342,
490,
587,
26,
717,
746,
1722,
360,
7354,
5002,
11106,
402,
5548,
358,
355,
2338,
10365,
17,
272,
1817,
17,
14,
4939,
342,
421,
199,
318,
1050,
63,
1637,
8,
493,
72,
12,
2581,
304,
272,
1572,
63,
354,
534,
647,
5987,
63,
1637,
63,
86,
16,
13619,
1224,
63,
354,
534,
1637,
16,
7,
272,
1738,
29,
493,
72,
14,
1231,
272,
1572,
63,
1113,
29,
493,
72,
14,
981,
2448,
8,
1231,
12,
1572,
63,
354,
9,
272,
2581,
63,
495,
29,
67,
12755,
14,
4180,
8,
1637,
12,
378,
9,
272,
2581,
63,
495,
29,
1637,
63,
495,
14,
1814,
2258,
78,
297,
8678,
8,
17,
430,
272,
2581,
63,
15655,
9811,
272,
1830,
2581,
63,
495,
26,
267,
2581,
63,
2064,
29,
1637,
63,
495,
1491,
15214,
11566,
1637,
63,
495,
29,
1637,
63,
495,
59,
15214,
2938,
267,
340,
2581,
63,
2064,
26,
288,
2581,
63,
15655,
14,
740,
8,
1637,
63,
2064,
9,
272,
1962,
63,
466,
7622,
272,
1962,
63,
466,
459,
761,
63,
16,
13784,
5987,
14,
2001,
480,
1610,
804,
401,
29855,
9,
272,
327,
272,
1817,
63,
1637,
29,
493,
72,
14,
981,
3186,
8,
923,
63,
1113,
12,
1817,
63,
354,
12,
1962,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kanagasabapathi/python-for-android | python3-alpha/python3-src/Tools/scripts/win_add2path.py | 49 | 1618 | """Add Python to the search path on Windows
This is a simple script to add Python to the Windows search path. It
modifies the current user (HKCU) tree of the registry.
Copyright (c) 2008 by Christian Heimes <[email protected]>
Licensed to PSF under a Contributor Agreement.
"""
import sys
import site
import os
import winreg
HKCU = winreg.HKEY_CURRENT_USER
ENV = "Environment"
PATH = "PATH"
DEFAULT = "%PATH%"
def modify():
pythonpath = os.path.dirname(os.path.normpath(sys.executable))
scripts = os.path.join(pythonpath, "Scripts")
appdata = os.environ["APPDATA"]
if hasattr(site, "USER_SITE"):
userpath = site.USER_SITE.replace(appdata, "%APPDATA%")
userscripts = os.path.join(userpath, "Scripts")
else:
userscripts = None
with winreg.CreateKey(HKCU, ENV) as key:
try:
envpath = winreg.QueryValueEx(key, PATH)[0]
except WindowsError:
envpath = DEFAULT
paths = [envpath]
for path in (pythonpath, scripts, userscripts):
if path and path not in envpath and os.path.isdir(path):
paths.append(path)
envpath = os.pathsep.join(paths)
winreg.SetValueEx(key, PATH, 0, winreg.REG_EXPAND_SZ, envpath)
return paths, envpath
def main():
paths, envpath = modify()
if len(paths) > 1:
print("Path(s) added:")
print('\n'.join(paths[1:]))
else:
print("No path was added")
print("\nPATH is now:\n%s\n" % envpath)
print("Expanded:")
print(winreg.ExpandEnvironmentStrings(envpath))
if __name__ == '__main__':
main()
| apache-2.0 | [
624,
1123,
2018,
370,
314,
2754,
931,
641,
5417,
199,
199,
2765,
365,
282,
3486,
2884,
370,
1050,
2018,
370,
314,
5417,
2754,
931,
14,
2779,
199,
3729,
5604,
314,
1453,
922,
334,
40,
18504,
53,
9,
3123,
402,
314,
7086,
14,
199,
199,
7384,
334,
67,
9,
9079,
701,
2799,
18824,
5653,
5311,
29778,
665,
335,
18824,
5653,
32,
595,
29778,
14,
271,
30,
199,
31661,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
624,
199,
199,
646,
984,
199,
646,
4770,
199,
646,
747,
199,
646,
30748,
199,
199,
40,
18504,
53,
275,
30748,
14,
23802,
63,
14211,
63,
3791,
199,
9984,
275,
298,
8263,
2,
199,
3243,
275,
298,
3243,
2,
199,
3472,
275,
2071,
3243,
5,
2,
199,
199,
318,
2811,
837,
272,
2366,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
9267,
8,
1274,
14,
5904,
430,
272,
10554,
275,
747,
14,
515,
14,
904,
8,
1548,
515,
12,
298,
25681,
531,
272,
1145,
576,
275,
747,
14,
2314,
905,
28057,
937,
272,
340,
2688,
8,
2124,
12,
298,
3791,
63,
7917,
2349,
267,
922,
515,
275,
4770,
14,
3791,
63,
7917,
14,
1814,
8,
571,
576,
12,
2071,
28057,
5,
531,
267,
922,
6429,
275,
747,
14,
515,
14,
904,
8,
751,
515,
12,
298,
25681,
531,
272,
587,
26,
267,
922,
6429,
275,
488,
339,
543,
30748,
14,
2499,
1197,
8,
40,
18504,
53,
12,
5070,
54,
9,
465,
790,
26,
267,
862,
26,
288,
2589,
515,
275,
30748,
14,
3227,
1110,
920,
8,
498,
12,
15097,
2788,
16,
61,
267,
871,
23950,
26,
288,
2589,
515,
275,
6186,
398,
3792,
275,
359,
1813,
515,
61,
267,
367,
931,
315,
334,
1548,
515,
12,
10554,
12,
922,
6429,
304,
288,
340,
931,
436,
931,
440,
315,
2589,
515,
436,
747,
14,
515,
14,
6027,
8,
515,
304,
355,
3792,
14,
740,
8,
515,
9,
398,
2589,
515,
275,
747,
14,
17843,
14,
904,
8,
3771,
9,
267,
30748,
14,
21322,
920,
8,
498,
12,
15097,
12,
378,
12,
30748,
14,
5616,
63,
20612,
63,
18101,
12,
2589,
515,
9,
267,
372,
3792,
12,
2589,
515,
199,
199,
318,
2446,
837,
272,
3792,
12,
2589,
515,
275,
2811,
342,
272,
340,
822,
8,
3771,
9,
690,
413,
26,
267,
870,
480,
2042,
8,
83,
9,
3483,
9107,
267,
870,
2258,
78,
1370,
904,
8,
3771,
59,
17,
16720,
272,
587,
26,
267,
870,
480,
1944,
931,
1990,
3483,
531,
272,
870,
4582,
78,
3243,
365,
3063,
3427,
78,
5,
83,
60,
78,
2,
450,
2589,
515,
9,
272,
870,
480,
27136,
9107,
272,
870,
8,
15658,
14,
12839,
8263,
12672,
8,
1813,
515,
430,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
1123,
2018,
370,
314,
2754,
931,
641,
5417,
199,
199,
2765,
365,
282,
3486,
2884,
370,
1050,
2018,
370,
314,
5417,
2754,
931,
14,
2779,
199,
3729,
5604,
314,
1453,
922,
334,
40,
18504,
53,
9,
3123,
402,
314,
7086,
14,
199,
199,
7384,
334,
67,
9,
9079,
701,
2799,
18824,
5653,
5311,
29778,
665,
335,
18824,
5653,
32,
595,
29778,
14,
271,
30,
199,
31661,
370,
29770,
1334,
282,
17636,
28629,
14,
199,
624,
199,
199,
646,
984,
199,
646,
4770,
199,
646,
747,
199,
646,
30748,
199,
199,
40,
18504,
53,
275,
30748,
14,
23802,
63,
14211,
63,
3791,
199,
9984,
275,
298,
8263,
2,
199,
3243,
275,
298,
3243,
2,
199,
3472,
275,
2071,
3243,
5,
2,
199,
199,
318,
2811,
837,
272,
2366,
515,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
9267,
8,
1274,
14,
5904,
430,
272,
10554,
275,
747,
14,
515,
14,
904,
8,
1548,
515,
12,
298,
25681,
531,
272,
1145,
576,
275,
747,
14,
2314,
905,
28057,
937,
272,
340,
2688,
8,
2124,
12,
298,
3791,
63,
7917,
2349,
267,
922,
515,
275,
4770,
14,
3791,
63,
7917,
14,
1814,
8,
571,
576,
12,
2071,
28057,
5,
531,
267,
922,
6429,
275,
747,
14,
515,
14,
904,
8,
751,
515,
12,
298,
25681,
531,
272,
587,
26,
267,
922,
6429,
275,
488,
339,
543,
30748,
14,
2499,
1197,
8,
40,
18504,
53,
12,
5070,
54,
9,
465,
790,
26,
267,
862,
26,
288,
2589,
515,
275,
30748,
14,
3227,
1110,
920,
8,
498,
12,
15097,
2788,
16,
61,
267,
871,
23950,
26,
288,
2589,
515,
275,
6186,
398,
3792,
275,
359,
1813,
515,
61,
267,
367,
931,
315,
334,
1548,
515,
12,
10554,
12,
922,
6429,
304,
288,
340,
931,
436,
931,
440,
315,
2589,
515,
436,
747,
14,
515,
14,
6027,
8,
515,
304,
355,
3792,
14,
740,
8,
515,
9,
398,
2589,
515,
275,
747,
14,
17843,
14,
904,
8,
3771,
9,
267,
30748,
14,
21322,
920,
8,
498,
12,
15097,
12,
378,
12,
30748,
14,
5616,
63,
20612,
63,
18101,
12,
2589,
515,
9,
267,
372,
3792,
12,
2589,
515,
199,
199,
318,
2446,
837,
272,
3792,
12,
2589,
515,
275,
2811,
342,
272,
340,
822,
8,
3771,
9,
690,
413,
26,
267,
870,
480,
2042,
8,
83,
9,
3483,
9107,
267,
870,
2258,
78,
1370,
904,
8,
3771,
59,
17,
16720,
272,
587,
26,
267,
870,
480,
1944,
931,
1990,
3483,
531,
272,
870,
4582,
78,
3243,
365,
3063,
3427,
78,
5,
83,
60,
78,
2,
450,
2589,
515,
9,
272,
870,
480,
27136,
9107,
272,
870,
8,
15658,
14,
12839,
8263,
12672,
8,
1813,
515,
430,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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import sys
import termios
from tools.utils.basic_printer import print_with_style, ConsoleColor
HOME = os.environ['HOME']
def get_input():
fd = sys.stdin.fileno()
old_tty_info = termios.tcgetattr(fd)
new_tty_info = old_tty_info[:]
new_tty_info[3] &= ~termios.ICANON
new_tty_info[3] &= ~termios.ECHO
termios.tcsetattr(fd, termios.TCSANOW, new_tty_info)
answer = os.read(fd, 1)
termios.tcsetattr(fd, termios.TCSANOW, old_tty_info)
return answer
def add_alias():
if sys.platform == 'darwin':
bash_profile_name = '.bash_profile'
else:
bash_profile_name = '.bashrc'
linux_bash_profile_path = os.path.join(HOME, bash_profile_name)
exec_file_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'main.py')
alias = 'alias updateall="python %s"' % exec_file_path
if os.path.exists(linux_bash_profile_path):
with open(linux_bash_profile_path, 'rw') as bashrc_file:
bash_profile = bashrc_file.read()
if bash_profile.find(alias) >= 0:
return
answer = ''
while not answer or answer not in {'y', 'n'}:
print_with_style('Add \'%s\' to your %s?(y/n)' % (alias, bash_profile_name), color=ConsoleColor.YELLOW)
answer = get_input()
if answer == 'n':
return
elif answer == 'y':
break
bash_profile = bash_profile + '\n' + alias
with open(linux_bash_profile_path, 'w') as bashrc_file:
bashrc_file.write(bash_profile)
print_with_style('Alias added.', color=ConsoleColor.YELLOW)
| gpl-3.0 | [
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
10502,
701,
1335,
18939,
74,
5653,
737,
14894,
15,
22,
15,
1398,
3193,
26,
1216,
199,
624,
199,
646,
747,
199,
646,
984,
199,
646,
28725,
199,
504,
7249,
14,
1208,
14,
4316,
63,
11835,
492,
870,
63,
1045,
63,
2487,
12,
19809,
4117,
199,
9524,
275,
747,
14,
2314,
459,
9524,
418,
421,
199,
318,
664,
63,
1210,
837,
272,
6111,
275,
984,
14,
6626,
14,
9843,
342,
272,
2269,
63,
4707,
63,
815,
275,
28725,
14,
3641,
5675,
8,
2592,
9,
272,
892,
63,
4707,
63,
815,
275,
2269,
63,
4707,
63,
815,
5873,
272,
892,
63,
4707,
63,
815,
59,
19,
61,
18415,
6146,
351,
24597,
14,
948,
879,
615,
272,
892,
63,
4707,
63,
815,
59,
19,
61,
18415,
6146,
351,
24597,
14,
37,
10465,
272,
28725,
14,
3641,
10202,
8,
2592,
12,
28725,
14,
52,
3298,
879,
19716,
12,
892,
63,
4707,
63,
815,
9,
272,
6385,
275,
747,
14,
739,
8,
2592,
12,
413,
9,
272,
28725,
14,
3641,
10202,
8,
2592,
12,
28725,
14,
52,
3298,
879,
19716,
12,
2269,
63,
4707,
63,
815,
9,
272,
372,
6385,
421,
199,
318,
1050,
63,
3620,
837,
272,
340,
984,
14,
3246,
508,
283,
13245,
356,
267,
20387,
63,
2913,
63,
354,
275,
1987,
16408,
63,
2913,
7,
272,
587,
26,
267,
20387,
63,
2913,
63,
354,
275,
1987,
16408,
1195,
7,
272,
18369,
63,
16408,
63,
2913,
63,
515,
275,
747,
14,
515,
14,
904,
8,
9524,
12,
20387,
63,
2913,
63,
354,
9,
272,
2146,
63,
493,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
22159,
283,
973,
14,
647,
358,
272,
5162,
275,
283,
3620,
1678,
452,
628,
1548,
450,
83,
4507,
450,
2146,
63,
493,
63,
515,
272,
340,
747,
14,
515,
14,
2444,
8,
5135,
63,
16408,
63,
2913,
63,
515,
304,
267,
543,
1551,
8,
5135,
63,
16408,
63,
2913,
63,
515,
12,
283,
13057,
358,
465,
20387,
1195,
63,
493,
26,
288,
20387,
63,
2913,
275,
20387,
1195,
63,
493,
14,
739,
342,
288,
340,
20387,
63,
2913,
14,
1623,
8,
3620,
9,
2356,
378,
26,
355,
372,
288,
6385,
275,
2125,
288,
1830,
440,
6385,
503,
6385,
440,
315,
791,
89,
297,
283,
78,
936,
26,
355,
870,
63,
1045,
63,
2487,
360,
1123,
19095,
83,
3985,
370,
2195,
450,
83,
31,
8,
89,
15,
78,
3171,
450,
334,
3620,
12,
20387,
63,
2913,
63,
354,
395,
3164,
29,
9270,
4117,
14,
57,
23575,
9,
355,
6385,
275,
664,
63,
1210,
342,
355,
340,
6385,
508,
283,
78,
356,
490,
372,
355,
916,
6385,
508,
283,
89,
356,
490,
2059,
288,
20387,
63,
2913,
275,
20387,
63,
2913,
435,
1557,
78,
7,
435,
5162,
267,
543,
1551,
8,
5135,
63,
16408,
63,
2913,
63,
515,
12,
283,
87,
358,
465,
20387,
1195,
63,
493,
26,
288,
20387,
1195,
63,
493,
14,
952,
8,
16408,
63,
2913,
9,
288,
870,
63,
1045,
63,
2487,
360,
14149,
3483,
3130,
3164,
29,
9270,
4117,
14,
57,
23575,
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
] | [
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
10502,
701,
1335,
18939,
74,
5653,
737,
14894,
15,
22,
15,
1398,
3193,
26,
1216,
199,
624,
199,
646,
747,
199,
646,
984,
199,
646,
28725,
199,
504,
7249,
14,
1208,
14,
4316,
63,
11835,
492,
870,
63,
1045,
63,
2487,
12,
19809,
4117,
199,
9524,
275,
747,
14,
2314,
459,
9524,
418,
421,
199,
318,
664,
63,
1210,
837,
272,
6111,
275,
984,
14,
6626,
14,
9843,
342,
272,
2269,
63,
4707,
63,
815,
275,
28725,
14,
3641,
5675,
8,
2592,
9,
272,
892,
63,
4707,
63,
815,
275,
2269,
63,
4707,
63,
815,
5873,
272,
892,
63,
4707,
63,
815,
59,
19,
61,
18415,
6146,
351,
24597,
14,
948,
879,
615,
272,
892,
63,
4707,
63,
815,
59,
19,
61,
18415,
6146,
351,
24597,
14,
37,
10465,
272,
28725,
14,
3641,
10202,
8,
2592,
12,
28725,
14,
52,
3298,
879,
19716,
12,
892,
63,
4707,
63,
815,
9,
272,
6385,
275,
747,
14,
739,
8,
2592,
12,
413,
9,
272,
28725,
14,
3641,
10202,
8,
2592,
12,
28725,
14,
52,
3298,
879,
19716,
12,
2269,
63,
4707,
63,
815,
9,
272,
372,
6385,
421,
199,
318,
1050,
63,
3620,
837,
272,
340,
984,
14,
3246,
508,
283,
13245,
356,
267,
20387,
63,
2913,
63,
354,
275,
1987,
16408,
63,
2913,
7,
272,
587,
26,
267,
20387,
63,
2913,
63,
354,
275,
1987,
16408,
1195,
7,
272,
18369,
63,
16408,
63,
2913,
63,
515,
275,
747,
14,
515,
14,
904,
8,
9524,
12,
20387,
63,
2913,
63,
354,
9,
272,
2146,
63,
493,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
22159,
283,
973,
14,
647,
358,
272,
5162,
275,
283,
3620,
1678,
452,
628,
1548,
450,
83,
4507,
450,
2146,
63,
493,
63,
515,
272,
340,
747,
14,
515,
14,
2444,
8,
5135,
63,
16408,
63,
2913,
63,
515,
304,
267,
543,
1551,
8,
5135,
63,
16408,
63,
2913,
63,
515,
12,
283,
13057,
358,
465,
20387,
1195,
63,
493,
26,
288,
20387,
63,
2913,
275,
20387,
1195,
63,
493,
14,
739,
342,
288,
340,
20387,
63,
2913,
14,
1623,
8,
3620,
9,
2356,
378,
26,
355,
372,
288,
6385,
275,
2125,
288,
1830,
440,
6385,
503,
6385,
440,
315,
791,
89,
297,
283,
78,
936,
26,
355,
870,
63,
1045,
63,
2487,
360,
1123,
19095,
83,
3985,
370,
2195,
450,
83,
31,
8,
89,
15,
78,
3171,
450,
334,
3620,
12,
20387,
63,
2913,
63,
354,
395,
3164,
29,
9270,
4117,
14,
57,
23575,
9,
355,
6385,
275,
664,
63,
1210,
342,
355,
340,
6385,
508,
283,
78,
356,
490,
372,
355,
916,
6385,
508,
283,
89,
356,
490,
2059,
288,
20387,
63,
2913,
275,
20387,
63,
2913,
435,
1557,
78,
7,
435,
5162,
267,
543,
1551,
8,
5135,
63,
16408,
63,
2913,
63,
515,
12,
283,
87,
358,
465,
20387,
1195,
63,
493,
26,
288,
20387,
1195,
63,
493,
14,
952,
8,
16408,
63,
2913,
9,
288,
870,
63,
1045,
63,
2487,
360,
14149,
3483,
3130,
3164,
29,
9270,
4117,
14,
57,
23575,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,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Lib/test/test_json/test_indent.py | 103 | 1824 | import textwrap
from io import StringIO
from test.test_json import PyTest, CTest
class TestIndent:
def test_indent(self):
h = [['blorpie'], ['whoops'], [], 'd-shtaeou', 'd-nthiouh', 'i-vhbjkhnth',
{'nifty': 87}, {'field': 'yes', 'morefield': False} ]
expect = textwrap.dedent("""\
[
\t[
\t\t"blorpie"
\t],
\t[
\t\t"whoops"
\t],
\t[],
\t"d-shtaeou",
\t"d-nthiouh",
\t"i-vhbjkhnth",
\t{
\t\t"nifty": 87
\t},
\t{
\t\t"field": "yes",
\t\t"morefield": false
\t}
]""")
d1 = self.dumps(h)
d2 = self.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))
d3 = self.dumps(h, indent='\t', sort_keys=True, separators=(',', ': '))
d4 = self.dumps(h, indent=2, sort_keys=True)
d5 = self.dumps(h, indent='\t', sort_keys=True)
h1 = self.loads(d1)
h2 = self.loads(d2)
h3 = self.loads(d3)
self.assertEqual(h1, h)
self.assertEqual(h2, h)
self.assertEqual(h3, h)
self.assertEqual(d2, expect.expandtabs(2))
self.assertEqual(d3, expect)
self.assertEqual(d4, d2)
self.assertEqual(d5, d3)
def test_indent0(self):
h = {3: 1}
def check(indent, expected):
d1 = self.dumps(h, indent=indent)
self.assertEqual(d1, expected)
sio = StringIO()
self.json.dump(h, sio, indent=indent)
self.assertEqual(sio.getvalue(), expected)
# indent=0 should emit newlines
check(0, '{\n"3": 1\n}')
# indent=None is more compact
check(None, '{"3": 1}')
class TestPyIndent(TestIndent, PyTest): pass
class TestCIndent(TestIndent, CTest): pass
| lgpl-3.0 | [
646,
13390,
199,
504,
5890,
492,
5228,
199,
504,
511,
14,
396,
63,
1001,
492,
1611,
774,
12,
445,
774,
421,
199,
533,
1379,
7583,
26,
272,
347,
511,
63,
3724,
8,
277,
304,
267,
394,
275,
11194,
3345,
269,
9890,
995,
788,
11345,
1483,
995,
990,
283,
68,
13,
609,
502,
69,
810,
297,
283,
68,
13,
16621,
73,
810,
72,
297,
283,
73,
13,
20369,
468,
75,
6164,
273,
297,
1467,
791,
78,
692,
369,
356,
10513,
1386,
791,
698,
356,
283,
5066,
297,
283,
6878,
698,
356,
756,
93,
1622,
398,
4282,
275,
13390,
14,
14674,
21723,
267,
359,
267,
971,
84,
59,
267,
971,
84,
60,
84,
2,
3345,
269,
9890,
2,
267,
971,
84,
467,
267,
971,
84,
59,
267,
971,
84,
60,
84,
2,
11345,
1483,
2,
267,
971,
84,
467,
267,
971,
84,
59,
467,
267,
971,
84,
2,
68,
13,
609,
502,
69,
810,
401,
267,
971,
84,
2,
68,
13,
16621,
73,
810,
72,
401,
267,
971,
84,
2,
73,
13,
20369,
468,
75,
6164,
273,
401,
267,
971,
84,
91,
267,
971,
84,
60,
84,
2,
78,
692,
369,
582,
10513,
267,
971,
84,
1386,
267,
971,
84,
91,
267,
971,
84,
60,
84,
2,
698,
582,
298,
5066,
401,
267,
971,
84,
60,
84,
2,
6878,
698,
582,
3055,
267,
971,
84,
93,
267,
1622,
6141,
398,
366,
17,
275,
291,
14,
4180,
8,
72,
9,
267,
366,
18,
275,
291,
14,
4180,
8,
72,
12,
4363,
29,
18,
12,
4069,
63,
1612,
29,
549,
12,
17658,
2687,
23324,
7596,
20005,
267,
366,
19,
275,
291,
14,
4180,
8,
72,
12,
4363,
17115,
84,
297,
4069,
63,
1612,
29,
549,
12,
17658,
2687,
23324,
7596,
20005,
267,
366,
20,
275,
291,
14,
4180,
8,
72,
12,
4363,
29,
18,
12,
4069,
63,
1612,
29,
549,
9,
267,
366,
21,
275,
291,
14,
4180,
8,
72,
12,
4363,
17115,
84,
297,
4069,
63,
1612,
29,
549,
9,
398,
394,
17,
275,
291,
14,
3640,
8,
68,
17,
9,
267,
394,
18,
275,
291,
14,
3640,
8,
68,
18,
9,
267,
394,
19,
275,
291,
14,
3640,
8,
68,
19,
9,
398,
291,
14,
629,
8,
72,
17,
12,
394,
9,
267,
291,
14,
629,
8,
72,
18,
12,
394,
9,
267,
291,
14,
629,
8,
72,
19,
12,
394,
9,
267,
291,
14,
629,
8,
68,
18,
12,
4282,
14,
30386,
8,
18,
430,
267,
291,
14,
629,
8,
68,
19,
12,
4282,
9,
267,
291,
14,
629,
8,
68,
20,
12,
366,
18,
9,
267,
291,
14,
629,
8,
68,
21,
12,
366,
19,
9,
339,
347,
511,
63,
3724,
16,
8,
277,
304,
267,
394,
275,
469,
19,
26,
413,
93,
267,
347,
1104,
8,
3724,
12,
1420,
304,
288,
366,
17,
275,
291,
14,
4180,
8,
72,
12,
4363,
29,
3724,
9,
288,
291,
14,
629,
8,
68,
17,
12,
1420,
9,
953,
29129,
275,
5228,
342,
288,
291,
14,
1001,
14,
2724,
8,
72,
12,
29129,
12,
4363,
29,
3724,
9,
288,
291,
14,
629,
8,
22961,
14,
7150,
1062,
1420,
9,
398,
327,
4363,
29,
16,
1077,
8689,
14930,
267,
1104,
8,
16,
12,
5041,
60,
78,
2,
19,
582,
413,
60,
78,
12216,
267,
327,
4363,
29,
403,
365,
1655,
23314,
267,
1104,
8,
403,
12,
17137,
19,
582,
413,
12216,
421,
199,
533,
1379,
2713,
7583,
8,
774,
7583,
12,
1611,
774,
304,
986,
199,
533,
1379,
35,
7583,
8,
774,
7583,
12,
445,
774,
304,
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
] | [
13390,
199,
504,
5890,
492,
5228,
199,
504,
511,
14,
396,
63,
1001,
492,
1611,
774,
12,
445,
774,
421,
199,
533,
1379,
7583,
26,
272,
347,
511,
63,
3724,
8,
277,
304,
267,
394,
275,
11194,
3345,
269,
9890,
995,
788,
11345,
1483,
995,
990,
283,
68,
13,
609,
502,
69,
810,
297,
283,
68,
13,
16621,
73,
810,
72,
297,
283,
73,
13,
20369,
468,
75,
6164,
273,
297,
1467,
791,
78,
692,
369,
356,
10513,
1386,
791,
698,
356,
283,
5066,
297,
283,
6878,
698,
356,
756,
93,
1622,
398,
4282,
275,
13390,
14,
14674,
21723,
267,
359,
267,
971,
84,
59,
267,
971,
84,
60,
84,
2,
3345,
269,
9890,
2,
267,
971,
84,
467,
267,
971,
84,
59,
267,
971,
84,
60,
84,
2,
11345,
1483,
2,
267,
971,
84,
467,
267,
971,
84,
59,
467,
267,
971,
84,
2,
68,
13,
609,
502,
69,
810,
401,
267,
971,
84,
2,
68,
13,
16621,
73,
810,
72,
401,
267,
971,
84,
2,
73,
13,
20369,
468,
75,
6164,
273,
401,
267,
971,
84,
91,
267,
971,
84,
60,
84,
2,
78,
692,
369,
582,
10513,
267,
971,
84,
1386,
267,
971,
84,
91,
267,
971,
84,
60,
84,
2,
698,
582,
298,
5066,
401,
267,
971,
84,
60,
84,
2,
6878,
698,
582,
3055,
267,
971,
84,
93,
267,
1622,
6141,
398,
366,
17,
275,
291,
14,
4180,
8,
72,
9,
267,
366,
18,
275,
291,
14,
4180,
8,
72,
12,
4363,
29,
18,
12,
4069,
63,
1612,
29,
549,
12,
17658,
2687,
23324,
7596,
20005,
267,
366,
19,
275,
291,
14,
4180,
8,
72,
12,
4363,
17115,
84,
297,
4069,
63,
1612,
29,
549,
12,
17658,
2687,
23324,
7596,
20005,
267,
366,
20,
275,
291,
14,
4180,
8,
72,
12,
4363,
29,
18,
12,
4069,
63,
1612,
29,
549,
9,
267,
366,
21,
275,
291,
14,
4180,
8,
72,
12,
4363,
17115,
84,
297,
4069,
63,
1612,
29,
549,
9,
398,
394,
17,
275,
291,
14,
3640,
8,
68,
17,
9,
267,
394,
18,
275,
291,
14,
3640,
8,
68,
18,
9,
267,
394,
19,
275,
291,
14,
3640,
8,
68,
19,
9,
398,
291,
14,
629,
8,
72,
17,
12,
394,
9,
267,
291,
14,
629,
8,
72,
18,
12,
394,
9,
267,
291,
14,
629,
8,
72,
19,
12,
394,
9,
267,
291,
14,
629,
8,
68,
18,
12,
4282,
14,
30386,
8,
18,
430,
267,
291,
14,
629,
8,
68,
19,
12,
4282,
9,
267,
291,
14,
629,
8,
68,
20,
12,
366,
18,
9,
267,
291,
14,
629,
8,
68,
21,
12,
366,
19,
9,
339,
347,
511,
63,
3724,
16,
8,
277,
304,
267,
394,
275,
469,
19,
26,
413,
93,
267,
347,
1104,
8,
3724,
12,
1420,
304,
288,
366,
17,
275,
291,
14,
4180,
8,
72,
12,
4363,
29,
3724,
9,
288,
291,
14,
629,
8,
68,
17,
12,
1420,
9,
953,
29129,
275,
5228,
342,
288,
291,
14,
1001,
14,
2724,
8,
72,
12,
29129,
12,
4363,
29,
3724,
9,
288,
291,
14,
629,
8,
22961,
14,
7150,
1062,
1420,
9,
398,
327,
4363,
29,
16,
1077,
8689,
14930,
267,
1104,
8,
16,
12,
5041,
60,
78,
2,
19,
582,
413,
60,
78,
12216,
267,
327,
4363,
29,
403,
365,
1655,
23314,
267,
1104,
8,
403,
12,
17137,
19,
582,
413,
12216,
421,
199,
533,
1379,
2713,
7583,
8,
774,
7583,
12,
1611,
774,
304,
986,
199,
533,
1379,
35,
7583,
8,
774,
7583,
12,
445,
774,
304,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
gs0510/coala-bears | bears/python/PyFlakesBear.py | 13 | 1050 | from coalib.bearlib.abstractions.Linter import linter
from dependency_management.requirements.PipRequirement import PipRequirement
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
@linter(executable='pyflakes',
use_stderr=True,
output_format='regex',
output_regex=r'.*:(?P<line>\d+):'
r'[(?P<column>\d+):|?]*(?P<severity>)\s(?P<message>.*)\n',
severity_map={
'': RESULT_SEVERITY.INFO
})
class PyFlakesBear:
"""
Checks Python files for errors using ``pyflakes``.
See https://github.com/PyCQA/pyflakes for more info.
"""
LANGUAGES = {'Python', 'Python 3'}
REQUIREMENTS = {PipRequirement('pyflakes', '1.4.0')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'[email protected]'}
LICENSE = 'AGPL-3.0'
ASCIINEMA_URL = 'https://asciinema.org/a/92503'
CAN_DETECT = {'Syntax', 'Unused Code', 'Undefined Element'}
@staticmethod
def create_arguments(filename, file, config_file):
return filename,
| agpl-3.0 | [
504,
512,
25530,
14,
31796,
773,
14,
371,
14183,
2452,
14,
44,
1058,
492,
7403,
351,
199,
504,
5936,
63,
8110,
14,
7538,
14,
32457,
17947,
492,
510,
711,
17947,
199,
504,
512,
25530,
14,
2604,
14,
9517,
63,
899,
2111,
1922,
492,
20668,
63,
899,
2111,
1922,
421,
199,
32,
25240,
8,
5904,
534,
647,
29677,
297,
267,
675,
63,
3083,
29,
549,
12,
267,
1072,
63,
908,
534,
3821,
297,
267,
1072,
63,
3821,
29,
82,
1370,
19429,
2229,
48,
28,
604,
3072,
68,
11,
304,
7,
2151,
519,
3894,
2229,
48,
28,
2301,
3072,
68,
11,
304,
92,
31,
3672,
2229,
48,
28,
20394,
30,
2862,
83,
2229,
48,
28,
1188,
23742,
2862,
78,
297,
267,
25574,
63,
1130,
3126,
288,
8061,
20668,
63,
899,
2111,
1922,
14,
4531,
267,
3828,
199,
533,
1611,
38,
416,
9246,
30860,
26,
272,
408,
272,
13813,
2018,
1584,
367,
2552,
1808,
1124,
647,
29677,
4345,
339,
1666,
4178,
921,
5031,
14,
957,
15,
2713,
35,
14323,
15,
647,
29677,
367,
1655,
2256,
14,
272,
408,
272,
30508,
5383,
275,
791,
4718,
297,
283,
4718,
650,
936,
272,
17023,
21201,
20967,
275,
469,
32457,
17947,
360,
647,
29677,
297,
283,
17,
14,
20,
14,
16,
21004,
272,
10610,
275,
791,
1918,
512,
14774,
19782,
936,
272,
10610,
63,
10089,
51,
275,
791,
331,
14774,
13,
27870,
32,
3098,
2634,
14,
957,
936,
272,
5113,
275,
283,
1254,
2749,
13,
19,
14,
16,
7,
272,
4319,
3553,
3565,
2054,
63,
2632,
275,
283,
2859,
921,
305,
559,
1132,
391,
14,
1308,
15,
65,
15,
32503,
1644,
7,
272,
29661,
63,
17442,
3582,
275,
791,
16626,
297,
283,
20782,
5495,
297,
283,
16283,
6566,
936,
339,
768,
4639,
272,
347,
1218,
63,
4958,
8,
1501,
12,
570,
12,
1101,
63,
493,
304,
267,
372,
1788,
12,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
512,
25530,
14,
31796,
773,
14,
371,
14183,
2452,
14,
44,
1058,
492,
7403,
351,
199,
504,
5936,
63,
8110,
14,
7538,
14,
32457,
17947,
492,
510,
711,
17947,
199,
504,
512,
25530,
14,
2604,
14,
9517,
63,
899,
2111,
1922,
492,
20668,
63,
899,
2111,
1922,
421,
199,
32,
25240,
8,
5904,
534,
647,
29677,
297,
267,
675,
63,
3083,
29,
549,
12,
267,
1072,
63,
908,
534,
3821,
297,
267,
1072,
63,
3821,
29,
82,
1370,
19429,
2229,
48,
28,
604,
3072,
68,
11,
304,
7,
2151,
519,
3894,
2229,
48,
28,
2301,
3072,
68,
11,
304,
92,
31,
3672,
2229,
48,
28,
20394,
30,
2862,
83,
2229,
48,
28,
1188,
23742,
2862,
78,
297,
267,
25574,
63,
1130,
3126,
288,
8061,
20668,
63,
899,
2111,
1922,
14,
4531,
267,
3828,
199,
533,
1611,
38,
416,
9246,
30860,
26,
272,
408,
272,
13813,
2018,
1584,
367,
2552,
1808,
1124,
647,
29677,
4345,
339,
1666,
4178,
921,
5031,
14,
957,
15,
2713,
35,
14323,
15,
647,
29677,
367,
1655,
2256,
14,
272,
408,
272,
30508,
5383,
275,
791,
4718,
297,
283,
4718,
650,
936,
272,
17023,
21201,
20967,
275,
469,
32457,
17947,
360,
647,
29677,
297,
283,
17,
14,
20,
14,
16,
21004,
272,
10610,
275,
791,
1918,
512,
14774,
19782,
936,
272,
10610,
63,
10089,
51,
275,
791,
331,
14774,
13,
27870,
32,
3098,
2634,
14,
957,
936,
272,
5113,
275,
283,
1254,
2749,
13,
19,
14,
16,
7,
272,
4319,
3553,
3565,
2054,
63,
2632,
275,
283,
2859,
921,
305,
559,
1132,
391,
14,
1308,
15,
65,
15,
32503,
1644,
7,
272,
29661,
63,
17442,
3582,
275,
791,
16626,
297,
283,
20782,
5495,
297,
283,
16283,
6566,
936,
339,
768,
4639,
272,
347,
1218,
63,
4958,
8,
1501,
12,
570,
12,
1101,
63,
493,
304,
267,
372,
1788,
12,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
amw2104/fireplace | setup.py | 1 | 1046 | #!/usr/bin/env python
import os.path
import fireplace
from setuptools import setup, find_packages
README = open(os.path.join(os.path.dirname(__file__), "README.md")).read()
CLASSIFIERS = [
"Development Status :: 2 - Pre-Alpha",
"Intended Audience :: Developers",
"License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)"
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.4",
"Topic :: Games/Entertainment :: Simulation",
]
setup(
name="fireplace",
version=fireplace.__version__,
packages=find_packages(exclude="tests"),
package_data={"": ["CardDefs.xml"]},
include_package_data=True,
tests_require=["pytest"],
author=fireplace.__author__,
author_email=fireplace.__email__,
description="Pure-python Hearthstone re-implementation and simulator",
classifiers=CLASSIFIERS,
download_url="https://github.com/jleclanche/python-bna/tarball/master",
long_description=README,
license="AGPLv3",
url="https://github.com/jleclanche/fireplace",
)
| agpl-3.0 | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
747,
14,
515,
199,
646,
5883,
1814,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
421,
199,
18195,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
298,
18195,
14,
1064,
21688,
739,
342,
199,
199,
31163,
1976,
3960,
275,
359,
199,
198,
2,
23753,
9795,
3800,
499,
446,
5543,
13,
16192,
401,
199,
198,
2,
23910,
23975,
3800,
23493,
401,
199,
198,
2,
3761,
3800,
25718,
26330,
3800,
1664,
4265,
1696,
1684,
844,
373,
19,
503,
2945,
334,
1254,
2749,
86,
19,
20415,
199,
198,
2,
11411,
8466,
3800,
2018,
401,
199,
198,
2,
11411,
8466,
3800,
2018,
3800,
650,
401,
199,
198,
2,
11411,
8466,
3800,
2018,
3800,
650,
14,
20,
401,
199,
198,
2,
12157,
3800,
598,
14015,
15,
8468,
877,
434,
3800,
10751,
5332,
401,
199,
61,
199,
199,
2758,
8,
199,
198,
354,
628,
329,
1814,
401,
199,
198,
1023,
29,
329,
1814,
855,
1023,
3108,
199,
198,
5154,
29,
1623,
63,
5154,
8,
5473,
628,
2219,
1288,
199,
198,
2491,
63,
576,
3126,
29679,
2097,
13832,
872,
2319,
14,
1652,
19057,
199,
198,
2613,
63,
2491,
63,
576,
29,
549,
12,
199,
198,
2219,
63,
4365,
6270,
4462,
2255,
199,
198,
2502,
29,
329,
1814,
855,
2502,
3108,
199,
198,
2502,
63,
2123,
29,
329,
1814,
855,
2123,
3108,
199,
198,
1802,
628,
28928,
13,
1548,
869,
2210,
273,
8361,
295,
13,
12236,
436,
15797,
401,
199,
198,
27628,
29,
31163,
1976,
3960,
12,
199,
198,
4249,
63,
633,
628,
2859,
921,
5031,
14,
957,
15,
74,
274,
429,
290,
595,
15,
1548,
13,
66,
3540,
15,
18829,
15,
4133,
401,
199,
198,
2809,
63,
1802,
29,
18195,
12,
199,
198,
1682,
628,
1254,
2749,
86,
19,
401,
199,
198,
633,
628,
2859,
921,
5031,
14,
957,
15,
74,
274,
429,
290,
595,
15,
329,
1814,
401,
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
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
747,
14,
515,
199,
646,
5883,
1814,
199,
504,
9116,
492,
3272,
12,
2342,
63,
5154,
421,
199,
18195,
275,
1551,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
298,
18195,
14,
1064,
21688,
739,
342,
199,
199,
31163,
1976,
3960,
275,
359,
199,
198,
2,
23753,
9795,
3800,
499,
446,
5543,
13,
16192,
401,
199,
198,
2,
23910,
23975,
3800,
23493,
401,
199,
198,
2,
3761,
3800,
25718,
26330,
3800,
1664,
4265,
1696,
1684,
844,
373,
19,
503,
2945,
334,
1254,
2749,
86,
19,
20415,
199,
198,
2,
11411,
8466,
3800,
2018,
401,
199,
198,
2,
11411,
8466,
3800,
2018,
3800,
650,
401,
199,
198,
2,
11411,
8466,
3800,
2018,
3800,
650,
14,
20,
401,
199,
198,
2,
12157,
3800,
598,
14015,
15,
8468,
877,
434,
3800,
10751,
5332,
401,
199,
61,
199,
199,
2758,
8,
199,
198,
354,
628,
329,
1814,
401,
199,
198,
1023,
29,
329,
1814,
855,
1023,
3108,
199,
198,
5154,
29,
1623,
63,
5154,
8,
5473,
628,
2219,
1288,
199,
198,
2491,
63,
576,
3126,
29679,
2097,
13832,
872,
2319,
14,
1652,
19057,
199,
198,
2613,
63,
2491,
63,
576,
29,
549,
12,
199,
198,
2219,
63,
4365,
6270,
4462,
2255,
199,
198,
2502,
29,
329,
1814,
855,
2502,
3108,
199,
198,
2502,
63,
2123,
29,
329,
1814,
855,
2123,
3108,
199,
198,
1802,
628,
28928,
13,
1548,
869,
2210,
273,
8361,
295,
13,
12236,
436,
15797,
401,
199,
198,
27628,
29,
31163,
1976,
3960,
12,
199,
198,
4249,
63,
633,
628,
2859,
921,
5031,
14,
957,
15,
74,
274,
429,
290,
595,
15,
1548,
13,
66,
3540,
15,
18829,
15,
4133,
401,
199,
198,
2809,
63,
1802,
29,
18195,
12,
199,
198,
1682,
628,
1254,
2749,
86,
19,
401,
199,
198,
633,
628,
2859,
921,
5031,
14,
957,
15,
74,
274,
429,
290,
595,
15,
329,
1814,
401,
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,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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
] |
sjperkins/tensorflow | tensorflow/contrib/keras/python/keras/metrics.py | 8 | 3418 | # Copyright 2015 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Built-in Keras metrics functions.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import six
from tensorflow.contrib.keras.python.keras import backend as K
# pylint: disable=unused-import
from tensorflow.contrib.keras.python.keras.losses import binary_crossentropy
from tensorflow.contrib.keras.python.keras.losses import categorical_crossentropy
from tensorflow.contrib.keras.python.keras.losses import cosine_proximity
from tensorflow.contrib.keras.python.keras.losses import hinge
from tensorflow.contrib.keras.python.keras.losses import kullback_leibler_divergence
from tensorflow.contrib.keras.python.keras.losses import logcosh
from tensorflow.contrib.keras.python.keras.losses import mean_absolute_error
from tensorflow.contrib.keras.python.keras.losses import mean_absolute_percentage_error
from tensorflow.contrib.keras.python.keras.losses import mean_squared_error
from tensorflow.contrib.keras.python.keras.losses import mean_squared_logarithmic_error
from tensorflow.contrib.keras.python.keras.losses import poisson
from tensorflow.contrib.keras.python.keras.losses import sparse_categorical_crossentropy
from tensorflow.contrib.keras.python.keras.losses import squared_hinge
# pylint: disable=unused-import
from tensorflow.contrib.keras.python.keras.utils.generic_utils import deserialize_keras_object
def binary_accuracy(y_true, y_pred):
return K.mean(K.equal(y_true, K.round(y_pred)), axis=-1)
def categorical_accuracy(y_true, y_pred):
return K.cast(
K.equal(K.argmax(y_true, axis=-1), K.argmax(y_pred, axis=-1)), K.floatx())
def sparse_categorical_accuracy(y_true, y_pred):
return K.cast(
K.equal(
K.max(y_true, axis=-1), K.cast(K.argmax(y_pred, axis=-1),
K.floatx())), K.floatx())
def top_k_categorical_accuracy(y_true, y_pred, k=5):
return K.mean(K.in_top_k(y_pred, K.argmax(y_true, axis=-1), k), axis=-1)
# Aliases
mse = MSE = mean_squared_error
mae = MAE = mean_absolute_error
mape = MAPE = mean_absolute_percentage_error
msle = MSLE = mean_squared_logarithmic_error
cosine = cosine_proximity
def serialize(metric):
return metric.__name__
def deserialize(name, custom_objects=None):
return deserialize_keras_object(
name,
module_objects=globals(),
custom_objects=custom_objects,
printable_module_name='metric function')
def get(identifier):
if isinstance(identifier, six.string_types):
identifier = str(identifier)
return deserialize(identifier)
elif callable(identifier):
return identifier
else:
raise ValueError('Could not interpret '
'metric function identifier:', identifier)
| apache-2.0 | [
3,
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
32406,
13,
262,
1804,
30037,
7186,
3423,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
3816,
199,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
492,
4865,
465,
1804,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
3366,
63,
20363,
1150,
7537,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
22138,
63,
20363,
1150,
7537,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
28188,
63,
8221,
1017,
1209,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
394,
17081,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
1022,
979,
894,
63,
274,
7247,
82,
63,
32049,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
943,
15106,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
4615,
63,
6116,
63,
705,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
4615,
63,
6116,
63,
14200,
63,
705,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
4615,
63,
12973,
63,
705,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
4615,
63,
12973,
63,
793,
18327,
15003,
63,
705,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
1115,
18571,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
5178,
63,
16810,
63,
20363,
1150,
7537,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
20478,
63,
27809,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
1208,
14,
6767,
63,
1208,
492,
22920,
63,
8811,
63,
785,
421,
199,
318,
3366,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
304,
523,
372,
1804,
14,
3670,
8,
43,
14,
1452,
8,
89,
63,
2052,
12,
1804,
14,
2363,
8,
89,
63,
5991,
1826,
3114,
4022,
17,
9,
421,
199,
318,
22138,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
304,
523,
372,
1804,
14,
2931,
8,
489,
1804,
14,
1452,
8,
43,
14,
16383,
8,
89,
63,
2052,
12,
3114,
4022,
17,
395,
1804,
14,
16383,
8,
89,
63,
5991,
12,
3114,
4022,
17,
1826,
1804,
14,
1609,
88,
1012,
421,
199,
318,
5178,
63,
16810,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
304,
523,
372,
1804,
14,
2931,
8,
489,
1804,
14,
1452,
8,
881,
1804,
14,
988,
8,
89,
63,
2052,
12,
3114,
4022,
17,
395,
1804,
14,
2931,
8,
43,
14,
16383,
8,
89,
63,
5991,
12,
3114,
4022,
17,
395,
1460,
1804,
14,
1609,
88,
22606,
1804,
14,
1609,
88,
1012,
421,
199,
318,
2746,
63,
75,
63,
16810,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
12,
1022,
29,
21,
304,
523,
372,
1804,
14,
3670,
8,
43,
14,
262,
63,
2119,
63,
75,
8,
89,
63,
5991,
12,
1804,
14,
16383,
8,
89,
63,
2052,
12,
3114,
4022,
17,
395,
1022,
395,
3114,
4022,
17,
9,
421,
199,
3,
15170,
3274,
199,
199,
23927,
275,
603,
899,
275,
4615,
63,
12973,
63,
705,
199,
391,
69,
275,
4828,
37,
275,
4615,
63,
6116,
63,
705,
199,
391,
321,
275,
603,
25380,
275,
4615,
63,
6116,
63,
14200,
63,
705,
199,
706,
274,
275,
14282,
906,
275,
4615,
63,
12973,
63,
793,
18327,
15003,
63,
705,
199,
28485,
275,
28188,
63,
8221,
1017,
1209,
421,
199,
318,
8437,
8,
5165,
304,
523,
372,
6370,
855,
354,
363,
421,
199,
318,
22920,
8,
354,
12,
3537,
63,
1462,
29,
403,
304,
523,
372,
22920,
63,
8811,
63,
785,
8,
489,
536,
12,
489,
859,
63,
1462,
29,
8473,
1062,
489,
3537,
63,
1462,
29,
4229,
63,
1462,
12,
489,
21834,
63,
578,
63,
354,
534,
5165,
805,
358,
421,
199,
318,
664,
8,
5364,
304,
523,
340,
1228,
8,
5364,
12,
3816,
14,
875,
63,
1313,
304,
272,
5148,
275,
620,
8,
5364,
9,
272,
372,
22920,
8,
5364,
9,
523,
916,
4550,
8,
5364,
304,
272,
372,
5148,
523,
587,
26,
272,
746,
1722,
360,
6531,
440,
15579,
283,
2151,
283,
5165,
805,
5148,
6536,
5148,
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
] | [
1898,
6900,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
32406,
13,
262,
1804,
30037,
7186,
3423,
14,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
646,
3816,
199,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
492,
4865,
465,
1804,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
3366,
63,
20363,
1150,
7537,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
22138,
63,
20363,
1150,
7537,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
28188,
63,
8221,
1017,
1209,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
394,
17081,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
1022,
979,
894,
63,
274,
7247,
82,
63,
32049,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
943,
15106,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
4615,
63,
6116,
63,
705,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
4615,
63,
6116,
63,
14200,
63,
705,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
4615,
63,
12973,
63,
705,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
4615,
63,
12973,
63,
793,
18327,
15003,
63,
705,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
1115,
18571,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
5178,
63,
16810,
63,
20363,
1150,
7537,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
17865,
492,
20478,
63,
27809,
199,
3,
4287,
26,
3507,
29,
8618,
13,
646,
199,
504,
3228,
14,
2828,
14,
8811,
14,
1548,
14,
8811,
14,
1208,
14,
6767,
63,
1208,
492,
22920,
63,
8811,
63,
785,
421,
199,
318,
3366,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
304,
523,
372,
1804,
14,
3670,
8,
43,
14,
1452,
8,
89,
63,
2052,
12,
1804,
14,
2363,
8,
89,
63,
5991,
1826,
3114,
4022,
17,
9,
421,
199,
318,
22138,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
304,
523,
372,
1804,
14,
2931,
8,
489,
1804,
14,
1452,
8,
43,
14,
16383,
8,
89,
63,
2052,
12,
3114,
4022,
17,
395,
1804,
14,
16383,
8,
89,
63,
5991,
12,
3114,
4022,
17,
1826,
1804,
14,
1609,
88,
1012,
421,
199,
318,
5178,
63,
16810,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
304,
523,
372,
1804,
14,
2931,
8,
489,
1804,
14,
1452,
8,
881,
1804,
14,
988,
8,
89,
63,
2052,
12,
3114,
4022,
17,
395,
1804,
14,
2931,
8,
43,
14,
16383,
8,
89,
63,
5991,
12,
3114,
4022,
17,
395,
1460,
1804,
14,
1609,
88,
22606,
1804,
14,
1609,
88,
1012,
421,
199,
318,
2746,
63,
75,
63,
16810,
63,
13374,
8,
89,
63,
2052,
12,
612,
63,
5991,
12,
1022,
29,
21,
304,
523,
372,
1804,
14,
3670,
8,
43,
14,
262,
63,
2119,
63,
75,
8,
89,
63,
5991,
12,
1804,
14,
16383,
8,
89,
63,
2052,
12,
3114,
4022,
17,
395,
1022,
395,
3114,
4022,
17,
9,
421,
199,
3,
15170,
3274,
199,
199,
23927,
275,
603,
899,
275,
4615,
63,
12973,
63,
705,
199,
391,
69,
275,
4828,
37,
275,
4615,
63,
6116,
63,
705,
199,
391,
321,
275,
603,
25380,
275,
4615,
63,
6116,
63,
14200,
63,
705,
199,
706,
274,
275,
14282,
906,
275,
4615,
63,
12973,
63,
793,
18327,
15003,
63,
705,
199,
28485,
275,
28188,
63,
8221,
1017,
1209,
421,
199,
318,
8437,
8,
5165,
304,
523,
372,
6370,
855,
354,
363,
421,
199,
318,
22920,
8,
354,
12,
3537,
63,
1462,
29,
403,
304,
523,
372,
22920,
63,
8811,
63,
785,
8,
489,
536,
12,
489,
859,
63,
1462,
29,
8473,
1062,
489,
3537,
63,
1462,
29,
4229,
63,
1462,
12,
489,
21834,
63,
578,
63,
354,
534,
5165,
805,
358,
421,
199,
318,
664,
8,
5364,
304,
523,
340,
1228,
8,
5364,
12,
3816,
14,
875,
63,
1313,
304,
272,
5148,
275,
620,
8,
5364,
9,
272,
372,
22920,
8,
5364,
9,
523,
916,
4550,
8,
5364,
304,
272,
372,
5148,
523,
587,
26,
272,
746,
1722,
360,
6531,
440,
15579,
283,
2151,
283,
5165,
805,
5148,
6536,
5148,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dapengchen123/code_v1 | reid/datasets/market1501.py | 1 | 3563 | from __future__ import print_function, absolute_import
import os.path as osp
from ..utils.data import Dataset
from ..utils.osutils import mkdir_if_missing
from ..utils.serialization import write_json
class Market1501(Dataset):
url = 'https://drive.google.com/file/d/0B8-rUzbwVRk0c054eEozWG9COHM/view'
md5 = '65005ab7d12ec1c44de4eeafe813e68a'
def __init__(self, root, split_id=0, num_val=0.3, download=False):
super(Market1501, self).__init__(root, split_id=split_id)
if download:
self.download()
if not self._check_integrity():
raise RuntimeError("Dataset not found or corrupted. " +
"You can use download=True to download it.")
self.load(num_val)
def download(self):
if self._check_integrity():
print("Files already downloaded and verified")
return
import re
import hashlib
import shutil
from glob import glob
from zipfile import ZipFile
raw_dir = osp.join(self.root, 'raw')
mkdir_if_missing(raw_dir)
# Download the raw zip file
fpath = osp.join(raw_dir, 'Market-1501-v15.09.15.zip')
if osp.isfile(fpath) and \
hashlib.md5(open(fpath, 'rb').read()).hexdigest() == self.md5:
print("Using downloaded file: " + fpath)
else:
raise RuntimeError("Please download the dataset manually from {} "
"to {}".format(self.url, fpath))
# Extract the file
exdir = osp.join(raw_dir, 'Market-1501-v15.09.15')
if not osp.isdir(exdir):
print("Extracting zip file")
with ZipFile(fpath) as z:
z.extractall(path=raw_dir)
# Format
images_dir = osp.join(self.root, 'images')
mkdir_if_missing(images_dir)
# 1501 identities (+1 for background) with 6 camera views each
identities = [[[] for _ in range(6)] for _ in range(1502)]
def register(subdir, pattern=re.compile(r'([-\d]+)_c(\d)')):
fpaths = sorted(glob(osp.join(exdir, subdir, '*.jpg')))
pids = set()
for fpath in fpaths:
fname = osp.basename(fpath)
pid, cam = map(int, pattern.search(fname).groups())
if pid == -1: continue # junk images are just ignored
assert 0 <= pid <= 1501 # pid == 0 means background
assert 1 <= cam <= 6
cam -= 1
pids.add(pid)
fname = ('{:08d}_{:02d}_{:04d}.jpg'
.format(pid, cam, len(identities[pid][cam])))
identities[pid][cam].append(fname)
shutil.copy(fpath, osp.join(images_dir, fname))
return pids
trainval_pids = register('bounding_box_train')
gallery_pids = register('bounding_box_test')
query_pids = register('query')
assert query_pids <= gallery_pids
assert trainval_pids.isdisjoint(gallery_pids)
# Save meta information into a json file
meta = {'name': 'Market1501', 'shot': 'multiple', 'num_cameras': 6,
'identities': identities}
write_json(meta, osp.join(self.root, 'meta.json'))
# Save the only training / test split
splits = [{
'trainval': sorted(list(trainval_pids)),
'query': sorted(list(query_pids)),
'gallery': sorted(list(gallery_pids))}]
write_json(splits, osp.join(self.root, 'splits.json'))
| mit | [
504,
636,
2443,
363,
492,
870,
63,
1593,
12,
3679,
63,
646,
199,
646,
747,
14,
515,
465,
312,
681,
199,
199,
504,
2508,
1208,
14,
576,
492,
20284,
199,
504,
2508,
1208,
14,
736,
1208,
492,
20366,
63,
692,
63,
4752,
199,
504,
2508,
1208,
14,
12161,
492,
2218,
63,
1001,
421,
199,
533,
7173,
386,
1046,
614,
8,
9271,
304,
272,
1166,
275,
283,
2859,
921,
9541,
14,
3098,
14,
957,
15,
493,
15,
68,
15,
16,
34,
24,
13,
28978,
90,
12415,
20271,
75,
16,
67,
22663,
20565,
26051,
55,
39,
25,
1439,
27699,
15,
1345,
7,
272,
6128,
21,
275,
283,
2182,
7972,
371,
23,
68,
713,
825,
17,
67,
1602,
271,
20,
1024,
6504,
24,
969,
69,
2333,
65,
7,
339,
347,
636,
826,
721,
277,
12,
1738,
12,
3715,
63,
344,
29,
16,
12,
1967,
63,
637,
29,
16,
14,
19,
12,
5235,
29,
797,
304,
267,
1613,
8,
21667,
1046,
614,
12,
291,
2843,
826,
721,
1231,
12,
3715,
63,
344,
29,
1294,
63,
344,
9,
398,
340,
5235,
26,
288,
291,
14,
4249,
342,
398,
340,
440,
291,
423,
1074,
63,
5707,
12997,
837,
288,
746,
6064,
480,
9271,
440,
1911,
503,
1970,
15692,
14,
298,
435,
3044,
298,
5556,
883,
675,
5235,
29,
549,
370,
5235,
652,
2685,
398,
291,
14,
912,
8,
1507,
63,
637,
9,
339,
347,
5235,
8,
277,
304,
267,
340,
291,
423,
1074,
63,
5707,
12997,
837,
288,
870,
480,
5535,
2575,
13557,
436,
16317,
531,
288,
372,
398,
492,
295,
267,
492,
8337,
267,
492,
5145,
267,
687,
5739,
492,
5739,
267,
687,
10392,
492,
26755,
398,
3066,
63,
694,
275,
312,
681,
14,
904,
8,
277,
14,
1231,
12,
283,
1773,
358,
267,
20366,
63,
692,
63,
4752,
8,
1773,
63,
694,
9,
398,
327,
17955,
314,
3066,
3482,
570,
267,
30540,
275,
312,
681,
14,
904,
8,
1773,
63,
694,
12,
283,
21667,
13,
1046,
614,
13,
86,
1046,
14,
1643,
14,
1046,
14,
3065,
358,
267,
340,
312,
681,
14,
6292,
8,
23248,
9,
436,
971,
881,
8337,
14,
1064,
21,
8,
1490,
8,
23248,
12,
283,
4848,
1959,
739,
8801,
11453,
342,
508,
291,
14,
1064,
21,
26,
288,
870,
480,
10369,
13557,
570,
26,
298,
435,
30540,
9,
267,
587,
26,
288,
746,
6064,
480,
8254,
5235,
314,
4789,
10250,
687,
1052,
298,
3044,
298,
475,
8352,
908,
8,
277,
14,
633,
12,
30540,
430,
398,
327,
12892,
314,
570,
267,
444,
694,
275,
312,
681,
14,
904,
8,
1773,
63,
694,
12,
283,
21667,
13,
1046,
614,
13,
86,
1046,
14,
1643,
14,
1046,
358,
267,
340,
440,
312,
681,
14,
6027,
8,
476,
694,
304,
288,
870,
480,
12147,
316,
3482,
570,
531,
288,
543,
26755,
8,
23248,
9,
465,
1315,
26,
355,
1315,
14,
5005,
452,
8,
515,
29,
1773,
63,
694,
9,
398,
327,
9701,
267,
5935,
63,
694,
275,
312,
681,
14,
904,
8,
277,
14,
1231,
12,
283,
4782,
358,
267,
20366,
63,
692,
63,
4752,
8,
4782,
63,
694,
9,
398,
327,
4114,
614,
6120,
5080,
334,
11,
17,
367,
8020,
9,
543,
1227,
15177,
6858,
1924,
267,
6120,
5080,
275,
3474,
8607,
367,
485,
315,
1425,
8,
22,
1874,
367,
485,
315,
1425,
8,
1046,
996,
1874,
398,
347,
2274,
8,
10622,
12,
3851,
29,
264,
14,
2014,
8,
82,
21731,
2696,
68,
11896,
63,
67,
2961,
68,
5942,
304,
288,
289,
3771,
275,
3355,
8,
6463,
8,
79,
681,
14,
904,
8,
476,
694,
12,
15488,
12,
11937,
8476,
7058,
288,
25902,
275,
663,
342,
288,
367,
30540,
315,
289,
3771,
26,
355,
6748,
275,
312,
681,
14,
4846,
8,
23248,
9,
355,
4422,
12,
27570,
275,
2341,
8,
442,
12,
3851,
14,
1733,
8,
5252,
680,
2634,
1012,
355,
340,
4422,
508,
446,
17,
26,
1980,
221,
327,
24605,
5935,
787,
2951,
5525,
355,
702,
378,
2695,
4422,
2695,
4114,
614,
221,
327,
4422,
508,
378,
4910,
8020,
355,
702,
413,
2695,
27570,
2695,
1227,
355,
27570,
4862,
413,
355,
25902,
14,
525,
8,
3150,
9,
355,
6748,
275,
661,
28476,
2036,
68,
26738,
26,
996,
68,
26738,
26,
966,
68,
5565,
8476,
7,
586,
1275,
908,
8,
3150,
12,
27570,
12,
822,
8,
9281,
5080,
59,
3150,
1527,
15176,
11845,
355,
6120,
5080,
59,
3150,
1527,
15176,
1055,
740,
8,
5252,
9,
355,
5145,
14,
1574,
8,
23248,
12,
312,
681,
14,
904,
8,
4782,
63,
694,
12,
6748,
430,
288,
372,
25902,
398,
3560,
637,
63,
19331,
275,
2274,
360,
24511,
63,
1977,
63,
2834,
358,
267,
486,
17787,
63,
19331,
275,
2274,
360,
24511,
63,
1977,
63,
396,
358,
267,
1827,
63,
19331,
275,
2274,
360,
1131,
358,
267,
702,
1827,
63,
19331,
2695,
486,
17787,
63,
19331,
267,
702,
3560,
637,
63,
19331,
14,
374,
31880,
8,
25372,
63,
19331,
9,
398,
327,
11063,
3404,
2556,
1901,
282,
2022,
570,
267,
3404,
275,
791,
354,
356,
283,
21667,
1046,
614,
297,
283,
2782,
356,
283,
6048,
297,
283,
1507,
63,
27467,
6360,
356,
1227,
12,
355,
283,
9281,
5080,
356,
6120,
5080,
93,
267,
2218,
63,
1001,
8,
2024,
12,
312,
681,
14,
904,
8,
277,
14,
1231,
12,
283,
2024,
14,
1001,
1333,
398,
327,
11063,
314,
1454,
6093,
1182,
511,
3715,
267,
19115,
275,
8910,
288,
283,
2834,
637,
356,
3355,
8,
513,
8,
2834,
637,
63,
19331,
1826,
288,
283,
1131,
356,
3355,
8,
513,
8,
1131,
63,
19331,
1826,
288,
283,
25372,
356,
3355,
8,
513,
8,
25372,
63,
19331,
430,
11049,
267,
2218,
63,
1001,
8,
16508,
12,
312,
681,
14,
904,
8,
277,
14,
1231,
12,
283,
16508,
14,
1001,
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
] | [
636,
2443,
363,
492,
870,
63,
1593,
12,
3679,
63,
646,
199,
646,
747,
14,
515,
465,
312,
681,
199,
199,
504,
2508,
1208,
14,
576,
492,
20284,
199,
504,
2508,
1208,
14,
736,
1208,
492,
20366,
63,
692,
63,
4752,
199,
504,
2508,
1208,
14,
12161,
492,
2218,
63,
1001,
421,
199,
533,
7173,
386,
1046,
614,
8,
9271,
304,
272,
1166,
275,
283,
2859,
921,
9541,
14,
3098,
14,
957,
15,
493,
15,
68,
15,
16,
34,
24,
13,
28978,
90,
12415,
20271,
75,
16,
67,
22663,
20565,
26051,
55,
39,
25,
1439,
27699,
15,
1345,
7,
272,
6128,
21,
275,
283,
2182,
7972,
371,
23,
68,
713,
825,
17,
67,
1602,
271,
20,
1024,
6504,
24,
969,
69,
2333,
65,
7,
339,
347,
636,
826,
721,
277,
12,
1738,
12,
3715,
63,
344,
29,
16,
12,
1967,
63,
637,
29,
16,
14,
19,
12,
5235,
29,
797,
304,
267,
1613,
8,
21667,
1046,
614,
12,
291,
2843,
826,
721,
1231,
12,
3715,
63,
344,
29,
1294,
63,
344,
9,
398,
340,
5235,
26,
288,
291,
14,
4249,
342,
398,
340,
440,
291,
423,
1074,
63,
5707,
12997,
837,
288,
746,
6064,
480,
9271,
440,
1911,
503,
1970,
15692,
14,
298,
435,
3044,
298,
5556,
883,
675,
5235,
29,
549,
370,
5235,
652,
2685,
398,
291,
14,
912,
8,
1507,
63,
637,
9,
339,
347,
5235,
8,
277,
304,
267,
340,
291,
423,
1074,
63,
5707,
12997,
837,
288,
870,
480,
5535,
2575,
13557,
436,
16317,
531,
288,
372,
398,
492,
295,
267,
492,
8337,
267,
492,
5145,
267,
687,
5739,
492,
5739,
267,
687,
10392,
492,
26755,
398,
3066,
63,
694,
275,
312,
681,
14,
904,
8,
277,
14,
1231,
12,
283,
1773,
358,
267,
20366,
63,
692,
63,
4752,
8,
1773,
63,
694,
9,
398,
327,
17955,
314,
3066,
3482,
570,
267,
30540,
275,
312,
681,
14,
904,
8,
1773,
63,
694,
12,
283,
21667,
13,
1046,
614,
13,
86,
1046,
14,
1643,
14,
1046,
14,
3065,
358,
267,
340,
312,
681,
14,
6292,
8,
23248,
9,
436,
971,
881,
8337,
14,
1064,
21,
8,
1490,
8,
23248,
12,
283,
4848,
1959,
739,
8801,
11453,
342,
508,
291,
14,
1064,
21,
26,
288,
870,
480,
10369,
13557,
570,
26,
298,
435,
30540,
9,
267,
587,
26,
288,
746,
6064,
480,
8254,
5235,
314,
4789,
10250,
687,
1052,
298,
3044,
298,
475,
8352,
908,
8,
277,
14,
633,
12,
30540,
430,
398,
327,
12892,
314,
570,
267,
444,
694,
275,
312,
681,
14,
904,
8,
1773,
63,
694,
12,
283,
21667,
13,
1046,
614,
13,
86,
1046,
14,
1643,
14,
1046,
358,
267,
340,
440,
312,
681,
14,
6027,
8,
476,
694,
304,
288,
870,
480,
12147,
316,
3482,
570,
531,
288,
543,
26755,
8,
23248,
9,
465,
1315,
26,
355,
1315,
14,
5005,
452,
8,
515,
29,
1773,
63,
694,
9,
398,
327,
9701,
267,
5935,
63,
694,
275,
312,
681,
14,
904,
8,
277,
14,
1231,
12,
283,
4782,
358,
267,
20366,
63,
692,
63,
4752,
8,
4782,
63,
694,
9,
398,
327,
4114,
614,
6120,
5080,
334,
11,
17,
367,
8020,
9,
543,
1227,
15177,
6858,
1924,
267,
6120,
5080,
275,
3474,
8607,
367,
485,
315,
1425,
8,
22,
1874,
367,
485,
315,
1425,
8,
1046,
996,
1874,
398,
347,
2274,
8,
10622,
12,
3851,
29,
264,
14,
2014,
8,
82,
21731,
2696,
68,
11896,
63,
67,
2961,
68,
5942,
304,
288,
289,
3771,
275,
3355,
8,
6463,
8,
79,
681,
14,
904,
8,
476,
694,
12,
15488,
12,
11937,
8476,
7058,
288,
25902,
275,
663,
342,
288,
367,
30540,
315,
289,
3771,
26,
355,
6748,
275,
312,
681,
14,
4846,
8,
23248,
9,
355,
4422,
12,
27570,
275,
2341,
8,
442,
12,
3851,
14,
1733,
8,
5252,
680,
2634,
1012,
355,
340,
4422,
508,
446,
17,
26,
1980,
221,
327,
24605,
5935,
787,
2951,
5525,
355,
702,
378,
2695,
4422,
2695,
4114,
614,
221,
327,
4422,
508,
378,
4910,
8020,
355,
702,
413,
2695,
27570,
2695,
1227,
355,
27570,
4862,
413,
355,
25902,
14,
525,
8,
3150,
9,
355,
6748,
275,
661,
28476,
2036,
68,
26738,
26,
996,
68,
26738,
26,
966,
68,
5565,
8476,
7,
586,
1275,
908,
8,
3150,
12,
27570,
12,
822,
8,
9281,
5080,
59,
3150,
1527,
15176,
11845,
355,
6120,
5080,
59,
3150,
1527,
15176,
1055,
740,
8,
5252,
9,
355,
5145,
14,
1574,
8,
23248,
12,
312,
681,
14,
904,
8,
4782,
63,
694,
12,
6748,
430,
288,
372,
25902,
398,
3560,
637,
63,
19331,
275,
2274,
360,
24511,
63,
1977,
63,
2834,
358,
267,
486,
17787,
63,
19331,
275,
2274,
360,
24511,
63,
1977,
63,
396,
358,
267,
1827,
63,
19331,
275,
2274,
360,
1131,
358,
267,
702,
1827,
63,
19331,
2695,
486,
17787,
63,
19331,
267,
702,
3560,
637,
63,
19331,
14,
374,
31880,
8,
25372,
63,
19331,
9,
398,
327,
11063,
3404,
2556,
1901,
282,
2022,
570,
267,
3404,
275,
791,
354,
356,
283,
21667,
1046,
614,
297,
283,
2782,
356,
283,
6048,
297,
283,
1507,
63,
27467,
6360,
356,
1227,
12,
355,
283,
9281,
5080,
356,
6120,
5080,
93,
267,
2218,
63,
1001,
8,
2024,
12,
312,
681,
14,
904,
8,
277,
14,
1231,
12,
283,
2024,
14,
1001,
1333,
398,
327,
11063,
314,
1454,
6093,
1182,
511,
3715,
267,
19115,
275,
8910,
288,
283,
2834,
637,
356,
3355,
8,
513,
8,
2834,
637,
63,
19331,
1826,
288,
283,
1131,
356,
3355,
8,
513,
8,
1131,
63,
19331,
1826,
288,
283,
25372,
356,
3355,
8,
513,
8,
25372,
63,
19331,
430,
11049,
267,
2218,
63,
1001,
8,
16508,
12,
312,
681,
14,
904,
8,
277,
14,
1231,
12,
283,
16508,
14,
1001,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
larsmans/scipy | benchmarks/benchmarks/linalg_solve_toeplitz.py | 106 | 1170 | """Benchmark the solve_toeplitz solver (Levinson recursion)
"""
from __future__ import division, absolute_import, print_function
import numpy as np
try:
import scipy.linalg
except ImportError:
pass
from .common import Benchmark
class SolveToeplitz(Benchmark):
params = (
('float64', 'complex128'),
(100, 300, 1000),
('toeplitz', 'generic')
)
param_names = ('dtype', 'n', 'solver')
def setup(self, dtype, n, soltype):
random = np.random.RandomState(1234)
dtype = np.dtype(dtype)
# Sample a random Toeplitz matrix representation and rhs.
c = random.randn(n)
r = random.randn(n)
y = random.randn(n)
if dtype == np.complex128:
c = c + 1j*random.rand(n)
r = r + 1j*random.rand(n)
y = y + 1j*random.rand(n)
self.c = c
self.r = r
self.y = y
self.T = scipy.linalg.toeplitz(c, r=r)
def time_solve_toeplitz(self, dtype, n, soltype):
if soltype == 'toeplitz':
scipy.linalg.solve_toeplitz((self.c, self.r), self.y)
else:
scipy.linalg.solve(self.T, self.y)
| bsd-3-clause | [
624,
18644,
314,
14241,
63,
475,
1545,
29382,
10196,
334,
2553,
11908,
834,
16189,
9,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
893,
26,
272,
492,
7026,
14,
10096,
199,
2590,
3545,
26,
272,
986,
199,
199,
504,
1275,
2330,
492,
27067,
421,
199,
533,
428,
3344,
1378,
1545,
29382,
8,
18644,
304,
272,
1862,
275,
334,
267,
661,
1609,
772,
297,
283,
5254,
3933,
659,
267,
334,
1960,
12,
9601,
12,
5198,
395,
267,
661,
475,
1545,
29382,
297,
283,
6767,
358,
272,
776,
272,
1215,
63,
1247,
275,
661,
2271,
297,
283,
78,
297,
283,
11263,
358,
339,
347,
3272,
8,
277,
12,
2152,
12,
302,
12,
8597,
466,
304,
267,
2196,
275,
980,
14,
2355,
14,
15726,
8,
4321,
9,
398,
2152,
275,
980,
14,
2271,
8,
2271,
9,
398,
327,
15227,
282,
2196,
4005,
1545,
29382,
3634,
6025,
436,
9085,
14,
267,
286,
275,
2196,
14,
10843,
8,
78,
9,
267,
519,
275,
2196,
14,
10843,
8,
78,
9,
267,
612,
275,
2196,
14,
10843,
8,
78,
9,
267,
340,
2152,
508,
980,
14,
5254,
3933,
26,
288,
286,
275,
286,
435,
413,
74,
10,
2355,
14,
3759,
8,
78,
9,
288,
519,
275,
519,
435,
413,
74,
10,
2355,
14,
3759,
8,
78,
9,
288,
612,
275,
612,
435,
413,
74,
10,
2355,
14,
3759,
8,
78,
9,
398,
291,
14,
67,
275,
286,
267,
291,
14,
82,
275,
519,
267,
291,
14,
89,
275,
612,
267,
291,
14,
52,
275,
7026,
14,
10096,
14,
475,
1545,
29382,
8,
67,
12,
519,
29,
82,
9,
339,
347,
900,
63,
11356,
63,
475,
1545,
29382,
8,
277,
12,
2152,
12,
302,
12,
8597,
466,
304,
267,
340,
8597,
466,
508,
283,
475,
1545,
29382,
356,
288,
7026,
14,
10096,
14,
11356,
63,
475,
1545,
29382,
1332,
277,
14,
67,
12,
291,
14,
82,
395,
291,
14,
89,
9,
267,
587,
26,
288,
7026,
14,
10096,
14,
11356,
8,
277,
14,
52,
12,
291,
14,
89,
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
] | [
18644,
314,
14241,
63,
475,
1545,
29382,
10196,
334,
2553,
11908,
834,
16189,
9,
199,
624,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
12,
870,
63,
1593,
199,
199,
646,
2680,
465,
980,
199,
199,
893,
26,
272,
492,
7026,
14,
10096,
199,
2590,
3545,
26,
272,
986,
199,
199,
504,
1275,
2330,
492,
27067,
421,
199,
533,
428,
3344,
1378,
1545,
29382,
8,
18644,
304,
272,
1862,
275,
334,
267,
661,
1609,
772,
297,
283,
5254,
3933,
659,
267,
334,
1960,
12,
9601,
12,
5198,
395,
267,
661,
475,
1545,
29382,
297,
283,
6767,
358,
272,
776,
272,
1215,
63,
1247,
275,
661,
2271,
297,
283,
78,
297,
283,
11263,
358,
339,
347,
3272,
8,
277,
12,
2152,
12,
302,
12,
8597,
466,
304,
267,
2196,
275,
980,
14,
2355,
14,
15726,
8,
4321,
9,
398,
2152,
275,
980,
14,
2271,
8,
2271,
9,
398,
327,
15227,
282,
2196,
4005,
1545,
29382,
3634,
6025,
436,
9085,
14,
267,
286,
275,
2196,
14,
10843,
8,
78,
9,
267,
519,
275,
2196,
14,
10843,
8,
78,
9,
267,
612,
275,
2196,
14,
10843,
8,
78,
9,
267,
340,
2152,
508,
980,
14,
5254,
3933,
26,
288,
286,
275,
286,
435,
413,
74,
10,
2355,
14,
3759,
8,
78,
9,
288,
519,
275,
519,
435,
413,
74,
10,
2355,
14,
3759,
8,
78,
9,
288,
612,
275,
612,
435,
413,
74,
10,
2355,
14,
3759,
8,
78,
9,
398,
291,
14,
67,
275,
286,
267,
291,
14,
82,
275,
519,
267,
291,
14,
89,
275,
612,
267,
291,
14,
52,
275,
7026,
14,
10096,
14,
475,
1545,
29382,
8,
67,
12,
519,
29,
82,
9,
339,
347,
900,
63,
11356,
63,
475,
1545,
29382,
8,
277,
12,
2152,
12,
302,
12,
8597,
466,
304,
267,
340,
8597,
466,
508,
283,
475,
1545,
29382,
356,
288,
7026,
14,
10096,
14,
11356,
63,
475,
1545,
29382,
1332,
277,
14,
67,
12,
291,
14,
82,
395,
291,
14,
89,
9,
267,
587,
26,
288,
7026,
14,
10096,
14,
11356,
8,
277,
14,
52,
12,
291,
14,
89,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
glenflet/ZtoRGBpy | ZtoRGBpy/_info.py | 1 | 2082 | # -*- coding: utf-8 -*-
# =================================================================================
# Copyright 2019 Glen Fletcher <[email protected]>
#
# 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.
#
# All documentation this file as docstrings or comments are licensed under the
# Creative Commons Attribution-ShareAlike 4.0 International License; you may
# not use this documentation except in compliance with this License.
# You may obtain a copy of this License at
#
# https://creativecommons.org/licenses/by-sa/4.0
#
# =================================================================================
"""
ZtoRGB information definition module
Special private module used for automatic processing, and inclusion
.. moduleauthor:: Glen Fletcher <[email protected]>
"""
__authors__ = [
("Glen Fletcher", "[email protected]")]
__copyright__ = "2019 Glen Fletcher"
__license__ = """\
The source code for this package is licensed under the [Apache 2.0 License](http://www.apache.org/licenses/LICENSE-2.0),
while the documentation including docstrings and comments embedded in the source code are licensed under the
[Creative Commons Attribution-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-sa/4.0)
"""
__contact__ = "Glen Fletcher <[email protected]>"
__version__ = "2.0"
__title__ = "ZtoRGBpy"
__desc__ = """\
Complex number to perceptually uniform RGB subset mapping library"""
__all__ = [
'__authors__', '__copyright__', '__license__',
'__contact__', '__version__', '__title__',
'__desc__']
| mit | [
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
7819,
1280,
199,
3,
221,
1898,
20312,
598,
552,
481,
2723,
7641,
665,
1198,
32,
71,
552,
70,
2723,
7641,
14,
957,
30,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
3,
199,
3,
221,
2900,
3794,
642,
570,
465,
20964,
503,
6786,
787,
18233,
1334,
314,
199,
3,
221,
9750,
1905,
7046,
4654,
2854,
15980,
13,
18713,
33,
2930,
841,
14,
16,
28220,
844,
27,
1265,
1443,
199,
3,
221,
440,
675,
642,
3794,
871,
315,
4151,
543,
642,
844,
14,
199,
3,
221,
2047,
1443,
3332,
282,
1331,
402,
642,
844,
737,
199,
3,
199,
3,
259,
4178,
921,
1353,
1905,
2330,
83,
14,
1308,
15,
2383,
15,
991,
13,
2231,
15,
20,
14,
16,
199,
3,
199,
3,
7819,
1280,
199,
624,
199,
58,
475,
12067,
2556,
5492,
859,
199,
199,
12246,
5726,
859,
1202,
367,
4834,
6661,
12,
436,
20396,
199,
199,
703,
28966,
447,
598,
552,
481,
2723,
7641,
665,
1198,
32,
71,
552,
70,
2723,
7641,
14,
957,
30,
199,
624,
199,
199,
363,
8149,
363,
275,
359,
272,
1689,
39,
552,
481,
2723,
7641,
401,
298,
1198,
32,
71,
552,
70,
2723,
7641,
14,
957,
11323,
199,
363,
7307,
363,
275,
298,
14982,
598,
552,
481,
2723,
7641,
2,
199,
363,
1682,
363,
275,
9638,
199,
1918,
1350,
1233,
367,
642,
2559,
365,
18233,
1334,
314,
359,
28993,
499,
14,
16,
844,
8738,
1014,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
395,
199,
6710,
314,
3794,
5893,
20964,
436,
6786,
12169,
315,
314,
1350,
1233,
787,
18233,
1334,
314,
199,
59,
5482,
1905,
7046,
4654,
2854,
15980,
13,
18713,
33,
2930,
841,
14,
16,
28220,
844,
8738,
2859,
921,
1353,
1905,
2330,
83,
14,
1308,
15,
2383,
15,
991,
13,
2231,
15,
20,
14,
16,
9,
199,
624,
199,
363,
7811,
363,
275,
298,
39,
552,
481,
2723,
7641,
665,
1198,
32,
71,
552,
70,
2723,
7641,
14,
957,
4335,
199,
363,
1023,
363,
275,
298,
18,
14,
16,
2,
199,
363,
1213,
363,
275,
298,
58,
475,
12067,
647,
2,
199,
363,
3257,
363,
275,
9638,
199,
14500,
1329,
370,
1126,
716,
3163,
14818,
19013,
10026,
4412,
3555,
624,
199,
199,
363,
452,
363,
275,
359,
272,
2560,
8149,
7500,
2560,
7307,
7500,
2560,
1682,
7500,
272,
2560,
7811,
7500,
2560,
1023,
7500,
2560,
1213,
7500,
272,
2560,
3257,
17501,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
7819,
1280,
199,
3,
221,
1898,
20312,
598,
552,
481,
2723,
7641,
665,
1198,
32,
71,
552,
70,
2723,
7641,
14,
957,
30,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
3,
199,
3,
221,
2900,
3794,
642,
570,
465,
20964,
503,
6786,
787,
18233,
1334,
314,
199,
3,
221,
9750,
1905,
7046,
4654,
2854,
15980,
13,
18713,
33,
2930,
841,
14,
16,
28220,
844,
27,
1265,
1443,
199,
3,
221,
440,
675,
642,
3794,
871,
315,
4151,
543,
642,
844,
14,
199,
3,
221,
2047,
1443,
3332,
282,
1331,
402,
642,
844,
737,
199,
3,
199,
3,
259,
4178,
921,
1353,
1905,
2330,
83,
14,
1308,
15,
2383,
15,
991,
13,
2231,
15,
20,
14,
16,
199,
3,
199,
3,
7819,
1280,
199,
624,
199,
58,
475,
12067,
2556,
5492,
859,
199,
199,
12246,
5726,
859,
1202,
367,
4834,
6661,
12,
436,
20396,
199,
199,
703,
28966,
447,
598,
552,
481,
2723,
7641,
665,
1198,
32,
71,
552,
70,
2723,
7641,
14,
957,
30,
199,
624,
199,
199,
363,
8149,
363,
275,
359,
272,
1689,
39,
552,
481,
2723,
7641,
401,
298,
1198,
32,
71,
552,
70,
2723,
7641,
14,
957,
11323,
199,
363,
7307,
363,
275,
298,
14982,
598,
552,
481,
2723,
7641,
2,
199,
363,
1682,
363,
275,
9638,
199,
1918,
1350,
1233,
367,
642,
2559,
365,
18233,
1334,
314,
359,
28993,
499,
14,
16,
844,
8738,
1014,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
395,
199,
6710,
314,
3794,
5893,
20964,
436,
6786,
12169,
315,
314,
1350,
1233,
787,
18233,
1334,
314,
199,
59,
5482,
1905,
7046,
4654,
2854,
15980,
13,
18713,
33,
2930,
841,
14,
16,
28220,
844,
8738,
2859,
921,
1353,
1905,
2330,
83,
14,
1308,
15,
2383,
15,
991,
13,
2231,
15,
20,
14,
16,
9,
199,
624,
199,
363,
7811,
363,
275,
298,
39,
552,
481,
2723,
7641,
665,
1198,
32,
71,
552,
70,
2723,
7641,
14,
957,
4335,
199,
363,
1023,
363,
275,
298,
18,
14,
16,
2,
199,
363,
1213,
363,
275,
298,
58,
475,
12067,
647,
2,
199,
363,
3257,
363,
275,
9638,
199,
14500,
1329,
370,
1126,
716,
3163,
14818,
19013,
10026,
4412,
3555,
624,
199,
199,
363,
452,
363,
275,
359,
272,
2560,
8149,
7500,
2560,
7307,
7500,
2560,
1682,
7500,
272,
2560,
7811,
7500,
2560,
1023,
7500,
2560,
1213,
7500,
272,
2560,
3257,
17501,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
ElecProg/decmath | decmath/trig.py | 1 | 4598 | from decimal import getcontext, Decimal
from decmath import _pi, _to_Decimal, sign
# Trigonometric functions
def acos(x):
"""Return the arc cosine (measured in radians) of x."""
x = _to_Decimal(x)
if x.is_nan():
return Decimal("NaN")
elif abs(x) > 1:
raise ValueError("Domain error: acos accepts -1 <= x <= 1.")
elif x == -1:
return _pi()
elif x == 0:
return _pi() / 2
elif x == 1:
return Decimal(0)
getcontext().prec += 2
one_half = Decimal('0.5')
i, lasts, s, gamma, fact, num = Decimal(0), 0, _pi() / 2 - x, 1, 1, x
while s != lasts:
lasts = s
i += 1
fact *= i
num *= x * x
gamma *= i - one_half
coeff = gamma / ((2 * i + 1) * fact)
s -= coeff * num
getcontext().prec -= 2
return +s
def asin(x):
"""Return the arc sine (measured in radians) of x."""
x = _to_Decimal(x)
if x.is_nan():
return Decimal("NaN")
elif abs(x) > 1:
raise ValueError("Domain error: asin accepts -1 <= x <= 1.")
elif x == -1:
return -_pi() / 2
elif x == 0:
return Decimal(0)
elif x == 1:
return _pi() / 2
getcontext().prec += 2
one_half = Decimal('0.5')
i, lasts, s, gamma, fact, num = Decimal(0), 0, x, 1, 1, x
while s != lasts:
lasts = s
i += 1
fact *= i
num *= x * x
gamma *= i - one_half
coeff = gamma / ((2 * i + 1) * fact)
s += coeff * num
getcontext().prec -= 2
return +s
def atan(x):
"""Return the arc tangent (measured in radians) of x."""
x = _to_Decimal(x)
if x.is_nan():
return Decimal("NaN")
elif x == Decimal('-Inf'):
return -_pi() / 2
elif x == 0:
return Decimal(0)
elif x == Decimal('Inf'):
return _pi() / 2
if x < -1:
c = _pi() / -2
x = 1 / x
elif x > 1:
c = _pi() / 2
x = 1 / x
else:
c = 0
getcontext().prec += 2
x_squared = x**2
y = x_squared / (1 + x_squared)
y_over_x = y / x
i, lasts, s, coeff, num = Decimal(0), 0, y_over_x, 1, y_over_x
while s != lasts:
lasts = s
i += 2
coeff *= i / (i + 1)
num *= y
s += coeff * num
if c:
s = c - s
getcontext().prec -= 2
return +s
def atan2(y, x):
"""Return the arc tangent (measured in radians) of y/x.
Unlike atan(y/x), the signs of both x and y are considered."""
y = _to_Decimal(y)
x = _to_Decimal(x)
abs_y = abs(y)
abs_x = abs(x)
y_is_real = abs_y != Decimal('Inf')
if y.is_nan() or x.is_nan():
return Decimal("NaN")
if x:
if y_is_real:
a = y and atan(y / x) or Decimal(0)
if x < 0:
a += sign(y) * _pi()
return a
elif abs_y == abs_x:
x = sign(x)
y = sign(y)
return _pi() * (Decimal(2) * abs(x) - x) / (Decimal(4) * y)
if y:
return atan(sign(y) * Decimal('Inf'))
elif sign(x) < 0:
return sign(y) * _pi()
else:
return sign(y) * Decimal(0)
def cos(x):
"""Return the cosine of x as measured in radians."""
x = _to_Decimal(x) % (2 * _pi())
if x.is_nan():
return Decimal('NaN')
elif x == _pi() / 2 or x == 3 * _pi() / 2:
return Decimal(0)
getcontext().prec += 2
i, lasts, s, fact, num, sign = 0, 0, 1, 1, 1, 1
while s != lasts:
lasts = s
i += 2
fact *= i * (i - 1)
num *= x * x
sign *= -1
s += num / fact * sign
getcontext().prec -= 2
return +s
def hypot(x, y):
"""Return the Euclidean distance, sqrt(x*x + y*y)."""
return (_to_Decimal(x).__pow__(2) + _to_Decimal(y).__pow__(2)).sqrt()
def sin(x):
"""Return the sine of x as measured in radians."""
x = _to_Decimal(x) % (2 * _pi())
if x.is_nan():
return Decimal('NaN')
elif x == 0 or x == _pi():
return Decimal(0)
getcontext().prec += 2
i, lasts, s, fact, num, sign = 1, 0, x, 1, x, 1
while s != lasts:
lasts = s
i += 2
fact *= i * (i - 1)
num *= x * x
sign *= -1
s += num / fact * sign
getcontext().prec -= 2
return +s
def tan(x):
"""Return the tangent of x (measured in radians)."""
x = _to_Decimal(x)
if x.is_nan():
return Decimal('NaN')
elif x == _pi() / 2:
return Decimal('Inf')
elif x == 3 * _pi() / 2:
return Decimal('-Inf')
return sin(x) / cos(x)
| mit | [
504,
6107,
492,
664,
1100,
12,
6345,
199,
504,
9700,
3442,
492,
485,
1038,
12,
485,
475,
63,
6745,
12,
2070,
199,
199,
3,
12480,
27719,
15890,
3423,
421,
199,
318,
282,
5197,
8,
88,
304,
272,
408,
1767,
314,
14972,
28188,
334,
19116,
3297,
315,
26874,
9,
402,
671,
1041,
272,
671,
275,
485,
475,
63,
6745,
8,
88,
9,
339,
340,
671,
14,
374,
63,
4304,
837,
267,
372,
6345,
480,
14300,
531,
272,
916,
2853,
8,
88,
9,
690,
413,
26,
267,
746,
1722,
480,
7705,
1125,
26,
282,
5197,
11479,
446,
17,
2695,
671,
2695,
413,
2685,
272,
916,
671,
508,
446,
17,
26,
267,
372,
485,
1038,
342,
272,
916,
671,
508,
378,
26,
267,
372,
485,
1038,
342,
1182,
499,
272,
916,
671,
508,
413,
26,
267,
372,
6345,
8,
16,
9,
339,
664,
1100,
1252,
9218,
847,
499,
272,
1373,
63,
10220,
275,
6345,
360,
16,
14,
21,
358,
272,
284,
12,
2061,
83,
12,
308,
12,
10169,
12,
10572,
12,
1967,
275,
6345,
8,
16,
395,
378,
12,
485,
1038,
342,
1182,
499,
446,
671,
12,
413,
12,
413,
12,
671,
272,
1830,
308,
1137,
2061,
83,
26,
267,
2061,
83,
275,
308,
267,
284,
847,
413,
267,
10572,
9000,
284,
267,
1967,
9000,
671,
627,
671,
267,
10169,
9000,
284,
446,
1373,
63,
10220,
267,
14678,
275,
10169,
1182,
3666,
18,
627,
284,
435,
413,
9,
627,
10572,
9,
267,
308,
4862,
14678,
627,
1967,
272,
664,
1100,
1252,
9218,
4862,
499,
272,
372,
435,
83,
421,
199,
318,
465,
262,
8,
88,
304,
272,
408,
1767,
314,
14972,
308,
1132,
334,
19116,
3297,
315,
26874,
9,
402,
671,
1041,
272,
671,
275,
485,
475,
63,
6745,
8,
88,
9,
339,
340,
671,
14,
374,
63,
4304,
837,
267,
372,
6345,
480,
14300,
531,
272,
916,
2853,
8,
88,
9,
690,
413,
26,
267,
746,
1722,
480,
7705,
1125,
26,
465,
262,
11479,
446,
17,
2695,
671,
2695,
413,
2685,
272,
916,
671,
508,
446,
17,
26,
267,
372,
446,
63,
1038,
342,
1182,
499,
272,
916,
671,
508,
378,
26,
267,
372,
6345,
8,
16,
9,
272,
916,
671,
508,
413,
26,
267,
372,
485,
1038,
342,
1182,
499,
339,
664,
1100,
1252,
9218,
847,
499,
272,
1373,
63,
10220,
275,
6345,
360,
16,
14,
21,
358,
272,
284,
12,
2061,
83,
12,
308,
12,
10169,
12,
10572,
12,
1967,
275,
6345,
8,
16,
395,
378,
12,
671,
12,
413,
12,
413,
12,
671,
272,
1830,
308,
1137,
2061,
83,
26,
267,
2061,
83,
275,
308,
267,
284,
847,
413,
267,
10572,
9000,
284,
267,
1967,
9000,
671,
627,
671,
267,
10169,
9000,
284,
446,
1373,
63,
10220,
267,
14678,
275,
10169,
1182,
3666,
18,
627,
284,
435,
413,
9,
627,
10572,
9,
267,
308,
847,
14678,
627,
1967,
272,
664,
1100,
1252,
9218,
4862,
499,
272,
372,
435,
83,
421,
199,
318,
31393,
8,
88,
304,
272,
408,
1767,
314,
14972,
307,
29360,
334,
19116,
3297,
315,
26874,
9,
402,
671,
1041,
272,
671,
275,
485,
475,
63,
6745,
8,
88,
9,
339,
340,
671,
14,
374,
63,
4304,
837,
267,
372,
6345,
480,
14300,
531,
272,
916,
671,
508,
6345,
3654,
17354,
735,
267,
372,
446,
63,
1038,
342,
1182,
499,
272,
916,
671,
508,
378,
26,
267,
372,
6345,
8,
16,
9,
272,
916,
671,
508,
6345,
360,
17354,
735,
267,
372,
485,
1038,
342,
1182,
499,
339,
340,
671,
665,
446,
17,
26,
267,
286,
275,
485,
1038,
342,
1182,
446,
18,
267,
671,
275,
413,
1182,
671,
272,
916,
671,
690,
413,
26,
267,
286,
275,
485,
1038,
342,
1182,
499,
267,
671,
275,
413,
1182,
671,
272,
587,
26,
267,
286,
275,
378,
339,
664,
1100,
1252,
9218,
847,
499,
272,
671,
63,
12973,
275,
671,
538,
18,
272,
612,
275,
671,
63,
12973,
1182,
334,
17,
435,
671,
63,
12973,
9,
272,
612,
63,
1883,
63,
88,
275,
612,
1182,
671,
272,
284,
12,
2061,
83,
12,
308,
12,
14678,
12,
1967,
275,
6345,
8,
16,
395,
378,
12,
612,
63,
1883,
63,
88,
12,
413,
12,
612,
63,
1883,
63,
88,
272,
1830,
308,
1137,
2061,
83,
26,
267,
2061,
83,
275,
308,
267,
284,
847,
499,
267,
14678,
9000,
284,
1182,
334,
73,
435,
413,
9,
267,
1967,
9000,
612,
267,
308,
847,
14678,
627,
1967,
272,
340,
286,
26,
267,
308,
275,
286,
446,
308,
272,
664,
1100,
1252,
9218,
4862,
499,
272,
372,
435,
83,
421,
199,
318,
31393,
18,
8,
89,
12,
671,
304,
272,
408,
1767,
314,
14972,
307,
29360,
334,
19116,
3297,
315,
26874,
9,
402,
612,
15,
88,
14,
272,
25059,
31393,
8,
89,
15,
88,
395,
314,
27624,
402,
3865,
671,
436,
612,
787,
8652,
1041,
272,
612,
275,
485,
475,
63,
6745,
8,
89,
9,
272,
671,
275,
485,
475,
63,
6745,
8,
88,
9,
272,
2853,
63,
89,
275,
2853,
8,
89,
9,
272,
2853,
63,
88,
275,
2853,
8,
88,
9,
272,
612,
63,
374,
63,
3093,
275,
2853,
63,
89,
1137,
6345,
360,
17354,
358,
339,
340,
612,
14,
374,
63,
4304,
342,
503,
671,
14,
374,
63,
4304,
837,
267,
372,
6345,
480,
14300,
531,
339,
340,
671,
26,
267,
340,
612,
63,
374,
63,
3093,
26,
288,
282,
275,
612,
436,
31393,
8,
89,
1182,
671,
9,
503,
6345,
8,
16,
9,
288,
340,
671,
665,
378,
26,
355,
282,
847,
2070,
8,
89,
9,
627,
485,
1038,
342,
288,
372,
282,
267,
916,
2853,
63,
89,
508,
2853,
63,
88,
26,
288,
671,
275,
2070,
8,
88,
9,
288,
612,
275,
2070,
8,
89,
9,
288,
372,
485,
1038,
342,
627,
334,
6745,
8,
18,
9,
627,
2853,
8,
88,
9,
446,
671,
9,
1182,
334,
6745,
8,
20,
9,
627,
612,
9,
272,
340,
612,
26,
267,
372,
31393,
8,
1037,
8,
89,
9,
627,
6345,
360,
17354,
1333,
272,
916,
2070,
8,
88,
9,
665,
378,
26,
267,
372,
2070,
8,
89,
9,
627,
485,
1038,
342,
272,
587,
26,
267,
372,
2070,
8,
89,
9,
627,
6345,
8,
16,
9,
421,
199,
318,
9794,
8,
88,
304,
272
] | [
6107,
492,
664,
1100,
12,
6345,
199,
504,
9700,
3442,
492,
485,
1038,
12,
485,
475,
63,
6745,
12,
2070,
199,
199,
3,
12480,
27719,
15890,
3423,
421,
199,
318,
282,
5197,
8,
88,
304,
272,
408,
1767,
314,
14972,
28188,
334,
19116,
3297,
315,
26874,
9,
402,
671,
1041,
272,
671,
275,
485,
475,
63,
6745,
8,
88,
9,
339,
340,
671,
14,
374,
63,
4304,
837,
267,
372,
6345,
480,
14300,
531,
272,
916,
2853,
8,
88,
9,
690,
413,
26,
267,
746,
1722,
480,
7705,
1125,
26,
282,
5197,
11479,
446,
17,
2695,
671,
2695,
413,
2685,
272,
916,
671,
508,
446,
17,
26,
267,
372,
485,
1038,
342,
272,
916,
671,
508,
378,
26,
267,
372,
485,
1038,
342,
1182,
499,
272,
916,
671,
508,
413,
26,
267,
372,
6345,
8,
16,
9,
339,
664,
1100,
1252,
9218,
847,
499,
272,
1373,
63,
10220,
275,
6345,
360,
16,
14,
21,
358,
272,
284,
12,
2061,
83,
12,
308,
12,
10169,
12,
10572,
12,
1967,
275,
6345,
8,
16,
395,
378,
12,
485,
1038,
342,
1182,
499,
446,
671,
12,
413,
12,
413,
12,
671,
272,
1830,
308,
1137,
2061,
83,
26,
267,
2061,
83,
275,
308,
267,
284,
847,
413,
267,
10572,
9000,
284,
267,
1967,
9000,
671,
627,
671,
267,
10169,
9000,
284,
446,
1373,
63,
10220,
267,
14678,
275,
10169,
1182,
3666,
18,
627,
284,
435,
413,
9,
627,
10572,
9,
267,
308,
4862,
14678,
627,
1967,
272,
664,
1100,
1252,
9218,
4862,
499,
272,
372,
435,
83,
421,
199,
318,
465,
262,
8,
88,
304,
272,
408,
1767,
314,
14972,
308,
1132,
334,
19116,
3297,
315,
26874,
9,
402,
671,
1041,
272,
671,
275,
485,
475,
63,
6745,
8,
88,
9,
339,
340,
671,
14,
374,
63,
4304,
837,
267,
372,
6345,
480,
14300,
531,
272,
916,
2853,
8,
88,
9,
690,
413,
26,
267,
746,
1722,
480,
7705,
1125,
26,
465,
262,
11479,
446,
17,
2695,
671,
2695,
413,
2685,
272,
916,
671,
508,
446,
17,
26,
267,
372,
446,
63,
1038,
342,
1182,
499,
272,
916,
671,
508,
378,
26,
267,
372,
6345,
8,
16,
9,
272,
916,
671,
508,
413,
26,
267,
372,
485,
1038,
342,
1182,
499,
339,
664,
1100,
1252,
9218,
847,
499,
272,
1373,
63,
10220,
275,
6345,
360,
16,
14,
21,
358,
272,
284,
12,
2061,
83,
12,
308,
12,
10169,
12,
10572,
12,
1967,
275,
6345,
8,
16,
395,
378,
12,
671,
12,
413,
12,
413,
12,
671,
272,
1830,
308,
1137,
2061,
83,
26,
267,
2061,
83,
275,
308,
267,
284,
847,
413,
267,
10572,
9000,
284,
267,
1967,
9000,
671,
627,
671,
267,
10169,
9000,
284,
446,
1373,
63,
10220,
267,
14678,
275,
10169,
1182,
3666,
18,
627,
284,
435,
413,
9,
627,
10572,
9,
267,
308,
847,
14678,
627,
1967,
272,
664,
1100,
1252,
9218,
4862,
499,
272,
372,
435,
83,
421,
199,
318,
31393,
8,
88,
304,
272,
408,
1767,
314,
14972,
307,
29360,
334,
19116,
3297,
315,
26874,
9,
402,
671,
1041,
272,
671,
275,
485,
475,
63,
6745,
8,
88,
9,
339,
340,
671,
14,
374,
63,
4304,
837,
267,
372,
6345,
480,
14300,
531,
272,
916,
671,
508,
6345,
3654,
17354,
735,
267,
372,
446,
63,
1038,
342,
1182,
499,
272,
916,
671,
508,
378,
26,
267,
372,
6345,
8,
16,
9,
272,
916,
671,
508,
6345,
360,
17354,
735,
267,
372,
485,
1038,
342,
1182,
499,
339,
340,
671,
665,
446,
17,
26,
267,
286,
275,
485,
1038,
342,
1182,
446,
18,
267,
671,
275,
413,
1182,
671,
272,
916,
671,
690,
413,
26,
267,
286,
275,
485,
1038,
342,
1182,
499,
267,
671,
275,
413,
1182,
671,
272,
587,
26,
267,
286,
275,
378,
339,
664,
1100,
1252,
9218,
847,
499,
272,
671,
63,
12973,
275,
671,
538,
18,
272,
612,
275,
671,
63,
12973,
1182,
334,
17,
435,
671,
63,
12973,
9,
272,
612,
63,
1883,
63,
88,
275,
612,
1182,
671,
272,
284,
12,
2061,
83,
12,
308,
12,
14678,
12,
1967,
275,
6345,
8,
16,
395,
378,
12,
612,
63,
1883,
63,
88,
12,
413,
12,
612,
63,
1883,
63,
88,
272,
1830,
308,
1137,
2061,
83,
26,
267,
2061,
83,
275,
308,
267,
284,
847,
499,
267,
14678,
9000,
284,
1182,
334,
73,
435,
413,
9,
267,
1967,
9000,
612,
267,
308,
847,
14678,
627,
1967,
272,
340,
286,
26,
267,
308,
275,
286,
446,
308,
272,
664,
1100,
1252,
9218,
4862,
499,
272,
372,
435,
83,
421,
199,
318,
31393,
18,
8,
89,
12,
671,
304,
272,
408,
1767,
314,
14972,
307,
29360,
334,
19116,
3297,
315,
26874,
9,
402,
612,
15,
88,
14,
272,
25059,
31393,
8,
89,
15,
88,
395,
314,
27624,
402,
3865,
671,
436,
612,
787,
8652,
1041,
272,
612,
275,
485,
475,
63,
6745,
8,
89,
9,
272,
671,
275,
485,
475,
63,
6745,
8,
88,
9,
272,
2853,
63,
89,
275,
2853,
8,
89,
9,
272,
2853,
63,
88,
275,
2853,
8,
88,
9,
272,
612,
63,
374,
63,
3093,
275,
2853,
63,
89,
1137,
6345,
360,
17354,
358,
339,
340,
612,
14,
374,
63,
4304,
342,
503,
671,
14,
374,
63,
4304,
837,
267,
372,
6345,
480,
14300,
531,
339,
340,
671,
26,
267,
340,
612,
63,
374,
63,
3093,
26,
288,
282,
275,
612,
436,
31393,
8,
89,
1182,
671,
9,
503,
6345,
8,
16,
9,
288,
340,
671,
665,
378,
26,
355,
282,
847,
2070,
8,
89,
9,
627,
485,
1038,
342,
288,
372,
282,
267,
916,
2853,
63,
89,
508,
2853,
63,
88,
26,
288,
671,
275,
2070,
8,
88,
9,
288,
612,
275,
2070,
8,
89,
9,
288,
372,
485,
1038,
342,
627,
334,
6745,
8,
18,
9,
627,
2853,
8,
88,
9,
446,
671,
9,
1182,
334,
6745,
8,
20,
9,
627,
612,
9,
272,
340,
612,
26,
267,
372,
31393,
8,
1037,
8,
89,
9,
627,
6345,
360,
17354,
1333,
272,
916,
2070,
8,
88,
9,
665,
378,
26,
267,
372,
2070,
8,
89,
9,
627,
485,
1038,
342,
272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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
] |
jasonwee/asus-rt-n14uhp-mrtg | tmp/ve_asus-rt-n14uhp-mrtg/lib/python3.4/site-packages/django/db/backends/postgresql/operations.py | 149 | 10182 | from __future__ import unicode_literals
from psycopg2.extras import Inet
from django.conf import settings
from django.db.backends.base.operations import BaseDatabaseOperations
class DatabaseOperations(BaseDatabaseOperations):
def unification_cast_sql(self, output_field):
internal_type = output_field.get_internal_type()
if internal_type in ("GenericIPAddressField", "IPAddressField", "TimeField", "UUIDField"):
# PostgreSQL will resolve a union as type 'text' if input types are
# 'unknown'.
# http://www.postgresql.org/docs/9.4/static/typeconv-union-case.html
# These fields cannot be implicitly cast back in the default
# PostgreSQL configuration so we need to explicitly cast them.
# We must also remove components of the type within brackets:
# varchar(255) -> varchar.
return 'CAST(%%s AS %s)' % output_field.db_type(self.connection).split('(')[0]
return '%s'
def date_extract_sql(self, lookup_type, field_name):
# http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
if lookup_type == 'week_day':
# For consistency across backends, we return Sunday=1, Saturday=7.
return "EXTRACT('dow' FROM %s) + 1" % field_name
else:
return "EXTRACT('%s' FROM %s)" % (lookup_type, field_name)
def date_trunc_sql(self, lookup_type, field_name):
# http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
return "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
def _convert_field_to_tz(self, field_name, tzname):
if settings.USE_TZ:
field_name = "%s AT TIME ZONE %%s" % field_name
params = [tzname]
else:
params = []
return field_name, params
def datetime_cast_date_sql(self, field_name, tzname):
field_name, params = self._convert_field_to_tz(field_name, tzname)
sql = '(%s)::date' % field_name
return sql, params
def datetime_extract_sql(self, lookup_type, field_name, tzname):
field_name, params = self._convert_field_to_tz(field_name, tzname)
sql = self.date_extract_sql(lookup_type, field_name)
return sql, params
def datetime_trunc_sql(self, lookup_type, field_name, tzname):
field_name, params = self._convert_field_to_tz(field_name, tzname)
# http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
sql = "DATE_TRUNC('%s', %s)" % (lookup_type, field_name)
return sql, params
def deferrable_sql(self):
return " DEFERRABLE INITIALLY DEFERRED"
def lookup_cast(self, lookup_type, internal_type=None):
lookup = '%s'
# Cast text lookups to text to allow things like filter(x__contains=4)
if lookup_type in ('iexact', 'contains', 'icontains', 'startswith',
'istartswith', 'endswith', 'iendswith', 'regex', 'iregex'):
if internal_type in ('IPAddressField', 'GenericIPAddressField'):
lookup = "HOST(%s)"
else:
lookup = "%s::text"
# Use UPPER(x) for case-insensitive lookups; it's faster.
if lookup_type in ('iexact', 'icontains', 'istartswith', 'iendswith'):
lookup = 'UPPER(%s)' % lookup
return lookup
def last_insert_id(self, cursor, table_name, pk_name):
# Use pg_get_serial_sequence to get the underlying sequence name
# from the table name and column name (available since PostgreSQL 8)
cursor.execute("SELECT CURRVAL(pg_get_serial_sequence('%s','%s'))" % (
self.quote_name(table_name), pk_name))
return cursor.fetchone()[0]
def no_limit_value(self):
return None
def prepare_sql_script(self, sql):
return [sql]
def quote_name(self, name):
if name.startswith('"') and name.endswith('"'):
return name # Quoting once is enough.
return '"%s"' % name
def set_time_zone_sql(self):
return "SET TIME ZONE %s"
def sql_flush(self, style, tables, sequences, allow_cascade=False):
if tables:
# Perform a single SQL 'TRUNCATE x, y, z...;' statement. It allows
# us to truncate tables referenced by a foreign key in any other
# table.
tables_sql = ', '.join(
style.SQL_FIELD(self.quote_name(table)) for table in tables)
if allow_cascade:
sql = ['%s %s %s;' % (
style.SQL_KEYWORD('TRUNCATE'),
tables_sql,
style.SQL_KEYWORD('CASCADE'),
)]
else:
sql = ['%s %s;' % (
style.SQL_KEYWORD('TRUNCATE'),
tables_sql,
)]
sql.extend(self.sequence_reset_by_name_sql(style, sequences))
return sql
else:
return []
def sequence_reset_by_name_sql(self, style, sequences):
# 'ALTER SEQUENCE sequence_name RESTART WITH 1;'... style SQL statements
# to reset sequence indices
sql = []
for sequence_info in sequences:
table_name = sequence_info['table']
column_name = sequence_info['column']
if not (column_name and len(column_name) > 0):
# This will be the case if it's an m2m using an autogenerated
# intermediate table (see BaseDatabaseIntrospection.sequence_list)
column_name = 'id'
sql.append("%s setval(pg_get_serial_sequence('%s','%s'), 1, false);" %
(style.SQL_KEYWORD('SELECT'),
style.SQL_TABLE(self.quote_name(table_name)),
style.SQL_FIELD(column_name))
)
return sql
def tablespace_sql(self, tablespace, inline=False):
if inline:
return "USING INDEX TABLESPACE %s" % self.quote_name(tablespace)
else:
return "TABLESPACE %s" % self.quote_name(tablespace)
def sequence_reset_sql(self, style, model_list):
from django.db import models
output = []
qn = self.quote_name
for model in model_list:
# Use `coalesce` to set the sequence for each model to the max pk value if there are records,
# or 1 if there are none. Set the `is_called` property (the third argument to `setval`) to true
# if there are records (as the max pk value is already in use), otherwise set it to false.
# Use pg_get_serial_sequence to get the underlying sequence name from the table name
# and column name (available since PostgreSQL 8)
for f in model._meta.local_fields:
if isinstance(f, models.AutoField):
output.append(
"%s setval(pg_get_serial_sequence('%s','%s'), "
"coalesce(max(%s), 1), max(%s) %s null) %s %s;" % (
style.SQL_KEYWORD('SELECT'),
style.SQL_TABLE(qn(model._meta.db_table)),
style.SQL_FIELD(f.column),
style.SQL_FIELD(qn(f.column)),
style.SQL_FIELD(qn(f.column)),
style.SQL_KEYWORD('IS NOT'),
style.SQL_KEYWORD('FROM'),
style.SQL_TABLE(qn(model._meta.db_table)),
)
)
break # Only one AutoField is allowed per model, so don't bother continuing.
for f in model._meta.many_to_many:
if not f.remote_field.through:
output.append(
"%s setval(pg_get_serial_sequence('%s','%s'), "
"coalesce(max(%s), 1), max(%s) %s null) %s %s;" % (
style.SQL_KEYWORD('SELECT'),
style.SQL_TABLE(qn(f.m2m_db_table())),
style.SQL_FIELD('id'),
style.SQL_FIELD(qn('id')),
style.SQL_FIELD(qn('id')),
style.SQL_KEYWORD('IS NOT'),
style.SQL_KEYWORD('FROM'),
style.SQL_TABLE(qn(f.m2m_db_table()))
)
)
return output
def prep_for_iexact_query(self, x):
return x
def max_name_length(self):
"""
Returns the maximum length of an identifier.
Note that the maximum length of an identifier is 63 by default, but can
be changed by recompiling PostgreSQL after editing the NAMEDATALEN
macro in src/include/pg_config_manual.h .
This implementation simply returns 63, but can easily be overridden by a
custom database backend that inherits most of its behavior from this one.
"""
return 63
def distinct_sql(self, fields):
if fields:
return 'DISTINCT ON (%s)' % ', '.join(fields)
else:
return 'DISTINCT'
def last_executed_query(self, cursor, sql, params):
# http://initd.org/psycopg/docs/cursor.html#cursor.query
# The query attribute is a Psycopg extension to the DB API 2.0.
if cursor.query is not None:
return cursor.query.decode('utf-8')
return None
def return_insert_id(self):
return "RETURNING %s", ()
def bulk_insert_sql(self, fields, placeholder_rows):
placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
values_sql = ", ".join("(%s)" % sql for sql in placeholder_rows_sql)
return "VALUES " + values_sql
def adapt_datefield_value(self, value):
return value
def adapt_datetimefield_value(self, value):
return value
def adapt_timefield_value(self, value):
return value
def adapt_ipaddressfield_value(self, value):
if value:
return Inet(value)
return None
| apache-2.0 | [
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
15492,
18,
14,
9975,
492,
473,
846,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
8170,
492,
29103,
12929,
421,
199,
533,
8692,
12929,
8,
1563,
7243,
12929,
304,
272,
347,
625,
7313,
63,
2931,
63,
3009,
8,
277,
12,
1072,
63,
698,
304,
267,
5007,
63,
466,
275,
1072,
63,
698,
14,
362,
63,
4672,
63,
466,
342,
267,
340,
5007,
63,
466,
315,
1689,
9417,
26969,
401,
298,
26969,
401,
298,
27115,
401,
298,
8757,
792,
2349,
288,
327,
20175,
911,
7512,
282,
13629,
465,
730,
283,
505,
7,
340,
1324,
2943,
787,
288,
327,
283,
5187,
1370,
288,
327,
1455,
921,
1544,
14,
15437,
14,
1308,
15,
4757,
15,
25,
14,
20,
15,
1986,
15,
466,
5598,
13,
8888,
13,
2546,
14,
1360,
288,
327,
5723,
1504,
3913,
506,
19796,
9106,
1771,
315,
314,
849,
288,
327,
20175,
2897,
880,
781,
1929,
370,
7662,
9106,
3062,
14,
288,
327,
2136,
1471,
2597,
2813,
7323,
402,
314,
730,
4453,
21873,
26,
288,
327,
31044,
8,
2299,
9,
1035,
31044,
14,
288,
372,
283,
18898,
4042,
5,
83,
4319,
450,
83,
3171,
450,
1072,
63,
698,
14,
697,
63,
466,
8,
277,
14,
2105,
680,
1294,
14097,
5832,
16,
61,
267,
372,
1543,
83,
7,
339,
347,
1434,
63,
5005,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
304,
267,
327,
1455,
921,
1544,
14,
15437,
14,
1308,
15,
4757,
15,
1818,
15,
1986,
15,
5777,
13,
2083,
14,
1360,
3,
29865,
13,
12488,
13,
30335,
267,
340,
4237,
63,
466,
508,
283,
6419,
63,
2977,
356,
288,
327,
2104,
17754,
9371,
14745,
12,
781,
372,
428,
24759,
29,
17,
12,
428,
292,
300,
2977,
29,
23,
14,
288,
372,
298,
30335,
360,
68,
583,
7,
4442,
450,
83,
9,
435,
413,
2,
450,
901,
63,
354,
267,
587,
26,
288,
372,
298,
30335,
3508,
83,
7,
4442,
450,
83,
2924,
450,
334,
3892,
63,
466,
12,
901,
63,
354,
9,
339,
347,
1434,
63,
8208,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
304,
267,
327,
1455,
921,
1544,
14,
15437,
14,
1308,
15,
4757,
15,
1818,
15,
1986,
15,
5777,
13,
2083,
14,
1360,
3,
29865,
13,
12488,
13,
22346,
267,
372,
298,
5390,
63,
22346,
3508,
83,
297,
450,
83,
2924,
450,
334,
3892,
63,
466,
12,
901,
63,
354,
9,
339,
347,
485,
3916,
63,
698,
63,
475,
63,
3903,
8,
277,
12,
901,
63,
354,
12,
28054,
304,
267,
340,
2202,
14,
4701,
63,
14226,
26,
288,
901,
63,
354,
275,
2071,
83,
15059,
17032,
3107,
4817,
11539,
83,
2,
450,
901,
63,
354,
288,
1862,
275,
359,
20027,
61,
267,
587,
26,
288,
1862,
275,
942,
267,
372,
901,
63,
354,
12,
1862,
339,
347,
2197,
63,
2931,
63,
602,
63,
3009,
8,
277,
12,
901,
63,
354,
12,
28054,
304,
267,
901,
63,
354,
12,
1862,
275,
291,
423,
3916,
63,
698,
63,
475,
63,
3903,
8,
698,
63,
354,
12,
28054,
9,
267,
3875,
275,
25676,
83,
304,
26,
602,
7,
450,
901,
63,
354,
267,
372,
3875,
12,
1862,
339,
347,
2197,
63,
5005,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
12,
28054,
304,
267,
901,
63,
354,
12,
1862,
275,
291,
423,
3916,
63,
698,
63,
475,
63,
3903,
8,
698,
63,
354,
12,
28054,
9,
267,
3875,
275,
291,
14,
602,
63,
5005,
63,
3009,
8,
3892,
63,
466,
12,
901,
63,
354,
9,
267,
372,
3875,
12,
1862,
339,
347,
2197,
63,
8208,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
12,
28054,
304,
267,
901,
63,
354,
12,
1862,
275,
291,
423,
3916,
63,
698,
63,
475,
63,
3903,
8,
698,
63,
354,
12,
28054,
9,
267,
327,
1455,
921,
1544,
14,
15437,
14,
1308,
15,
4757,
15,
1818,
15,
1986,
15,
5777,
13,
2083,
14,
1360,
3,
29865,
13,
12488,
13,
22346,
267,
3875,
275,
298,
5390,
63,
22346,
3508,
83,
297,
450,
83,
2924,
450,
334,
3892,
63,
466,
12,
901,
63,
354,
9,
267,
372,
3875,
12,
1862,
339,
347,
10133,
6842,
63,
3009,
8,
277,
304,
267,
372,
298,
23566,
2666,
2617,
20199,
41,
28292,
3265,
15849,
7387,
2,
339,
347,
4237,
63,
2931,
8,
277,
12,
4237,
63,
466,
12,
5007,
63,
466,
29,
403,
304,
267,
4237,
275,
1543,
83,
7,
398,
327,
445,
1810,
1318,
16807,
370,
1318,
370,
2040,
7645,
2839,
2457,
8,
88,
363,
6134,
29,
20,
9,
267,
340,
4237,
63,
466,
315,
661,
32344,
297,
283,
6134,
297,
283,
30314,
297,
283,
2460,
297,
2574,
283,
631,
580,
1908,
297,
283,
4130,
297,
283,
73,
4130,
297,
283,
3821,
297,
283,
3621,
2145,
735,
288,
340,
5007,
63,
466,
315,
661,
26969,
297,
283,
9417,
26969,
735,
355,
4237,
275,
298,
5449,
4042,
83,
2924,
288,
587,
26,
355,
4237,
275,
2071,
83,
447,
505,
2,
398,
327,
3645,
27300,
8,
88,
9,
367,
1930,
13,
15851,
16807,
27,
652,
1159,
12930,
14,
267,
340,
4237,
63,
466,
315,
661,
32344,
297,
283,
30314,
297,
283,
631,
580,
1908,
297,
283,
73,
4130,
735,
288,
4237,
275,
283,
2160,
4227,
4042,
83,
3171,
450,
4237,
398,
372,
4237,
339,
347,
2061,
63,
3176,
63,
344,
8,
277,
12,
3920,
12,
1817,
63,
354,
12,
3803,
63,
354,
304,
267,
327,
3645,
10275,
63,
362,
63,
2171,
63,
4041,
370,
664,
314,
8793,
3414,
536,
267,
327,
687,
314,
1817,
536,
436,
2763,
536,
334,
4561,
3967,
20175,
1695,
9,
267,
3920,
14,
2526,
480,
4859,
18715,
50,
3204,
8,
4198,
63,
362,
63,
2171,
63,
4041,
3508,
83,
1673,
5,
83,
1333,
2,
450,
334,
288,
291,
14,
3513,
63,
354,
8,
1224,
63,
354,
395,
3803,
63,
354,
430,
267,
372,
3920,
14,
11591,
3430,
16,
61,
339,
347,
949,
63,
3097,
63,
585,
8,
277,
304,
267,
372,
488,
339,
347,
9275,
63,
3009,
63,
1579,
8,
277,
12,
3875,
304,
267,
372,
359,
3009,
61,
339,
347,
6313
] | [
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
15492,
18,
14,
9975,
492,
473,
846,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
697,
14,
7765,
14,
1095,
14,
8170,
492,
29103,
12929,
421,
199,
533,
8692,
12929,
8,
1563,
7243,
12929,
304,
272,
347,
625,
7313,
63,
2931,
63,
3009,
8,
277,
12,
1072,
63,
698,
304,
267,
5007,
63,
466,
275,
1072,
63,
698,
14,
362,
63,
4672,
63,
466,
342,
267,
340,
5007,
63,
466,
315,
1689,
9417,
26969,
401,
298,
26969,
401,
298,
27115,
401,
298,
8757,
792,
2349,
288,
327,
20175,
911,
7512,
282,
13629,
465,
730,
283,
505,
7,
340,
1324,
2943,
787,
288,
327,
283,
5187,
1370,
288,
327,
1455,
921,
1544,
14,
15437,
14,
1308,
15,
4757,
15,
25,
14,
20,
15,
1986,
15,
466,
5598,
13,
8888,
13,
2546,
14,
1360,
288,
327,
5723,
1504,
3913,
506,
19796,
9106,
1771,
315,
314,
849,
288,
327,
20175,
2897,
880,
781,
1929,
370,
7662,
9106,
3062,
14,
288,
327,
2136,
1471,
2597,
2813,
7323,
402,
314,
730,
4453,
21873,
26,
288,
327,
31044,
8,
2299,
9,
1035,
31044,
14,
288,
372,
283,
18898,
4042,
5,
83,
4319,
450,
83,
3171,
450,
1072,
63,
698,
14,
697,
63,
466,
8,
277,
14,
2105,
680,
1294,
14097,
5832,
16,
61,
267,
372,
1543,
83,
7,
339,
347,
1434,
63,
5005,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
304,
267,
327,
1455,
921,
1544,
14,
15437,
14,
1308,
15,
4757,
15,
1818,
15,
1986,
15,
5777,
13,
2083,
14,
1360,
3,
29865,
13,
12488,
13,
30335,
267,
340,
4237,
63,
466,
508,
283,
6419,
63,
2977,
356,
288,
327,
2104,
17754,
9371,
14745,
12,
781,
372,
428,
24759,
29,
17,
12,
428,
292,
300,
2977,
29,
23,
14,
288,
372,
298,
30335,
360,
68,
583,
7,
4442,
450,
83,
9,
435,
413,
2,
450,
901,
63,
354,
267,
587,
26,
288,
372,
298,
30335,
3508,
83,
7,
4442,
450,
83,
2924,
450,
334,
3892,
63,
466,
12,
901,
63,
354,
9,
339,
347,
1434,
63,
8208,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
304,
267,
327,
1455,
921,
1544,
14,
15437,
14,
1308,
15,
4757,
15,
1818,
15,
1986,
15,
5777,
13,
2083,
14,
1360,
3,
29865,
13,
12488,
13,
22346,
267,
372,
298,
5390,
63,
22346,
3508,
83,
297,
450,
83,
2924,
450,
334,
3892,
63,
466,
12,
901,
63,
354,
9,
339,
347,
485,
3916,
63,
698,
63,
475,
63,
3903,
8,
277,
12,
901,
63,
354,
12,
28054,
304,
267,
340,
2202,
14,
4701,
63,
14226,
26,
288,
901,
63,
354,
275,
2071,
83,
15059,
17032,
3107,
4817,
11539,
83,
2,
450,
901,
63,
354,
288,
1862,
275,
359,
20027,
61,
267,
587,
26,
288,
1862,
275,
942,
267,
372,
901,
63,
354,
12,
1862,
339,
347,
2197,
63,
2931,
63,
602,
63,
3009,
8,
277,
12,
901,
63,
354,
12,
28054,
304,
267,
901,
63,
354,
12,
1862,
275,
291,
423,
3916,
63,
698,
63,
475,
63,
3903,
8,
698,
63,
354,
12,
28054,
9,
267,
3875,
275,
25676,
83,
304,
26,
602,
7,
450,
901,
63,
354,
267,
372,
3875,
12,
1862,
339,
347,
2197,
63,
5005,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
12,
28054,
304,
267,
901,
63,
354,
12,
1862,
275,
291,
423,
3916,
63,
698,
63,
475,
63,
3903,
8,
698,
63,
354,
12,
28054,
9,
267,
3875,
275,
291,
14,
602,
63,
5005,
63,
3009,
8,
3892,
63,
466,
12,
901,
63,
354,
9,
267,
372,
3875,
12,
1862,
339,
347,
2197,
63,
8208,
63,
3009,
8,
277,
12,
4237,
63,
466,
12,
901,
63,
354,
12,
28054,
304,
267,
901,
63,
354,
12,
1862,
275,
291,
423,
3916,
63,
698,
63,
475,
63,
3903,
8,
698,
63,
354,
12,
28054,
9,
267,
327,
1455,
921,
1544,
14,
15437,
14,
1308,
15,
4757,
15,
1818,
15,
1986,
15,
5777,
13,
2083,
14,
1360,
3,
29865,
13,
12488,
13,
22346,
267,
3875,
275,
298,
5390,
63,
22346,
3508,
83,
297,
450,
83,
2924,
450,
334,
3892,
63,
466,
12,
901,
63,
354,
9,
267,
372,
3875,
12,
1862,
339,
347,
10133,
6842,
63,
3009,
8,
277,
304,
267,
372,
298,
23566,
2666,
2617,
20199,
41,
28292,
3265,
15849,
7387,
2,
339,
347,
4237,
63,
2931,
8,
277,
12,
4237,
63,
466,
12,
5007,
63,
466,
29,
403,
304,
267,
4237,
275,
1543,
83,
7,
398,
327,
445,
1810,
1318,
16807,
370,
1318,
370,
2040,
7645,
2839,
2457,
8,
88,
363,
6134,
29,
20,
9,
267,
340,
4237,
63,
466,
315,
661,
32344,
297,
283,
6134,
297,
283,
30314,
297,
283,
2460,
297,
2574,
283,
631,
580,
1908,
297,
283,
4130,
297,
283,
73,
4130,
297,
283,
3821,
297,
283,
3621,
2145,
735,
288,
340,
5007,
63,
466,
315,
661,
26969,
297,
283,
9417,
26969,
735,
355,
4237,
275,
298,
5449,
4042,
83,
2924,
288,
587,
26,
355,
4237,
275,
2071,
83,
447,
505,
2,
398,
327,
3645,
27300,
8,
88,
9,
367,
1930,
13,
15851,
16807,
27,
652,
1159,
12930,
14,
267,
340,
4237,
63,
466,
315,
661,
32344,
297,
283,
30314,
297,
283,
631,
580,
1908,
297,
283,
73,
4130,
735,
288,
4237,
275,
283,
2160,
4227,
4042,
83,
3171,
450,
4237,
398,
372,
4237,
339,
347,
2061,
63,
3176,
63,
344,
8,
277,
12,
3920,
12,
1817,
63,
354,
12,
3803,
63,
354,
304,
267,
327,
3645,
10275,
63,
362,
63,
2171,
63,
4041,
370,
664,
314,
8793,
3414,
536,
267,
327,
687,
314,
1817,
536,
436,
2763,
536,
334,
4561,
3967,
20175,
1695,
9,
267,
3920,
14,
2526,
480,
4859,
18715,
50,
3204,
8,
4198,
63,
362,
63,
2171,
63,
4041,
3508,
83,
1673,
5,
83,
1333,
2,
450,
334,
288,
291,
14,
3513,
63,
354,
8,
1224,
63,
354,
395,
3803,
63,
354,
430,
267,
372,
3920,
14,
11591,
3430,
16,
61,
339,
347,
949,
63,
3097,
63,
585,
8,
277,
304,
267,
372,
488,
339,
347,
9275,
63,
3009,
63,
1579,
8,
277,
12,
3875,
304,
267,
372,
359,
3009,
61,
339,
347,
6313,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
martindurant/astrobits | time_series.py | 1 | 12543 | """Take a list of files and known star coordinates, and
perform photometry on them all, either with apertures (phot)
or by PSF fitting (daophot, which required additional
parameters and is apropriate to poor S/N or crowded fields).
Makes extensive use of iraf tasks; set all photometry parameters
before running:
datapars - for data characteristics
centerpars - finding the reference star on each image.
centerpars, photpars, fitskypars - for controling aperture photometry
daopars - for controling daophot
filelist: set of image files, in IRAF syntax (image.fits[1][*,*,2] etc);
can be more than one per cube.
coords: name a file containing all star coords for photometry, based on
an image unshifted relative to (0,0) in the shifts list. Be pure numbers
for phot method, .mag or .als for daophot method.
shifts: name a file containing shifts, a tuple of shifts arrays, image
header keywords (tuple of two= or None for no shifts
refstar: coords of star for deriving (x,y) offset, as in coords
timestamp: source of the timing information: a header keyword, delta-t
for uniform sampling or a file with times (in whatever formate you'll be
using later.
psf: whether to use daophot or aperture phot for analysis. If this is a
filename, that is the PSF profile to use for every image; if it is "True",
make a new PSF for every image. Pars below only for full PSF fitting
pststars: a .pst file from daophot, listing the IDs of stars for making
the PSF for each image. NB: DAOphot refuses to measure any star with SNR<2.
ids: which stars are interesting, by ID (in input coord list order)
coords: starting well-measured coords (pdump-ed from a .als, perhaps).
"""
import os
import numpy
from glob import glob
import pyfits
from pylab import find
from numpy import load,vstack,save,median
thisdir = os.getcwd()
os.chdir("/home/durant")
from pyraf import iraf
iraf.cd(thisdir)
iraf.digiphot()
iraf.daophot()
import pyraf
import pyfits
import numpy as n
def shift_file_coords(filename,xshift,yshift,output,sort=None):
"""Understands filetypes: 2-column ascii numbers, .mag, .als, .pst.
NB: shift means where each image is, relative to the original (not where
it should be moved to).
"""
if not(sort):
sort = 'num'
if filename.find('.mag')>0: sort = 'mag'
if filename.find('.als')>0: sort = 'als'
if filename.find('.pst')>0: sort = 'pst'
if not(sort=='num' or sort=='mag' or sort=='als' or sort=='pst'):
raise ValueError('Unknown input filetype: %s'%filename)
if sort=='num': # shift 2-column numeric ASCII table
x,y = load(filename,usecols=[0,1],unpack=True)
x += xshift
y += yshift
X = vstack((x,y))
save(output,X.transpose())
return
if sort=='mag': #shift a .mag photometry file
fred = open(filename)
freda= open(output,'w')
for line in fred:
if line.split()[-1]=='\\' and len(line.split())==9 and line[0]!='#':
x = float(line.split()[0]) + xshift
y = float(line.split()[1]) + yshift
line = "%-14.3f %-11.3f"%(x,y)+line[21:]
freda.write(line)
if sort=='als': #shift a .als DAOphot photometry file
fred = open(filename)
freda= open(output,'w')
for line in fred:
if line.split()[-1]=='\\' and len(line.split())==8 and line[0]!='#':
x = float(line.split()[1]) + xshift
y = float(line.split()[2]) + yshift
line = line[:9] + "%-10.3f %-10.3f"%(x,y) + line[29:]
freda.write(line)
if sort=='pst': #shift a PSF star list for DAOphot
fred = open(filename)
freda= open(output,'w')
for line in fred:
if line[0]!="#":
x = float(line.split()[1]) + xshift
y = float(line.split()[2]) + yshift
line = line[:9] + "%-10.3f %-10.3f"%(x,y) + line[29:]
freda.write(line)
fred.close()
freda.close()
def recentre(image,refcoordfile):
"""Returns improved shift by centroiding
on the reference star using phot. This can be VERY
sensitive to the parameters in centerpars."""
xin,yin = load(refcoordfile,unpack=True)
try:
iraf.phot(image,refcoordfile,'temp.mag',inter="no",calgorithm='centroid',
mode='h',verify='no',update='no',verbose='no')
xout,yout=iraf.pdump('temp.mag','xcen,ycen','yes',Stdout=1)[0].split()
except:
print "Recentring failed on", image
return 0.,0.
xout,yout = float(xout),float(yout)
return xout-xin,yout-yin
vary_par = 1.
vary_max = 10
vary_min = 6
vary_fwhm= 0
def setaperture(image,refstar):
"""Measure the FWHM of the reference star unsing simple DAOphot editor
and then set the photometry aperture to this number"""
x,y = load(refstar,unpack=True)
fred = open('tempaperfile','w')
fred.write("%f %f 100 a\nq"%(x,y))
fred.close()
try:
output=iraf.daoedit(image,icomm='tempaperfile',Stdout=1,Stderr=1)
except:
print "Aperture setting failed on",image
return
FWHM = float(output[3].split()[4])
iraf.photpars.apertures = min(max(FWHM*vary_par,vary_min),vary_max)
iraf.daopars.fitrad = min(max(FWHM*vary_par,vary_min),vary_max)
global vary_fwhm
vary_fwhm = FWHM
print "FWHM: ", FWHM, " aperture: ",iraf.photpars.apertures
def apphot(image,coords,refstar=None,centre=False,vary=False):
"""Apperture photometry with centering based on a reference star.
NB: centre refers to shifting the coordinates by centroiding on the
reference star; recentering on the final phot depends on
centerpars.calgorithm ."""
iraf.dele('temp.mag*')
if centre:
xsh,ysh = recentre(image,refstar)
print "Fine centring: ", xsh,ysh
else: #no recentreing by reference star (but could still have calgorithm!=none)
xsh,ysh = 0,0
if vary:
setaperture(image,refstar)
shift_file_coords(coords,xsh,ysh,'tempcoords')
iraf.phot(image,'tempcoords','temp.mag2',inter="no",
mode='h',verify='no',update='no',verbose='no')
out = iraf.pdump('temp.mag2','id,flux,msky,stdev','yes',Stdout=1)
return out
def psfphot(image,coords,pststars,refstar,centre=True,vary=False):
"""PSF photometry. Centering is through phot on refstar.
Assume coords is a .als file for now. Recentering is always done
for the reference star, never for the targets."""
iraf.dele('temp.mag*')
iraf.dele('temp.psf.fits')
iraf.dele('temp.als')
if centre:
xsh,ysh = recentre(image,refstar)
print "Fine Centring: ", xsh,ysh
else: xsh,ysh = 0,0
if vary:
setaperture(image,refstar)
shift_file_coords(coords,xsh,ysh,'tempcoords2',sort='als')
shift_file_coords(pststars,xsh,ysh,'temppst2',sort='pst')
iraf.phot(image,'tempcoords2','temp.mag2',inter="no",calgorithm='none',
mode='h',verify='no',update='no',verbose='no')
iraf.psf(image,'temp.mag2','temppst2','temp.psf','temp.mag.pst','temp.mag.psg',
inter='no',mode='h',verify='no',update='no',verbose='no')
iraf.allstar(image,'temp.mag2','temp.psf','temp.als','temp.mag.arj',"default",
mode='h',verify='no',update='no',verbose='no')
out = iraf.pdump('temp.als','id,mag,merr,msky','yes',Stdout=1)
return out
def simplepsfphot(image,coords,psf,refstar,centre=True,vary=False):
"""PSF photometry, with a given PSF file in psf used for every image"""
iraf.dele('temp.mag*')
iraf.dele('temp.als')
iraf.dele('temp.sub.fits')
if centre:
xsh,ysh = recentre(image,refstar)
print "Fine Centring: ", xsh,ysh
else: xsh,ysh = 0,0
if vary:
setaperture(image,refstar)
shift_file_coords(coords,xsh,ysh,'tempcoords2',sort='als')
iraf.phot(image,'tempcoords2','temp.mag2',inter="no",calgorithm='none',
mode='h',verify='no',update='no',verbose='no')
iraf.allstar(image,'temp.mag2',psf,'temp.als','temp.mag.arj','temp.sub.fits',
mode='h',verify='no',update='no',verbose='no')
out = iraf.pdump('temp.als','id,mag,merr,msky','yes',Stdout=1)
return out
def custom1(filename): # for NACO timing mode cubes - removes horizontal banding
#iraf.imarith(filename,'-','dark','temp')
iraf.imarith(filename,'/','flatK','temp')
im = pyfits.getdata('temp.fits')
med = median(im.transpose())
out = ((im).transpose()-med).transpose()
(pyfits.ImageHDU(out)).writeto("temp2.fits",clobber=True)
iraf.imdel('temp')
iraf.imcopy('temp2[1]','temp')
def get_id(starid,output='output'):
"""from the output of the photometry, grab the magnitudes and magerrs of starid"""
mag = load(output,usecols=[4+starid*4])
merr= load(output,usecols=[5+starid*4])
return mag,merr
def run(filelist,coords,refstar,shifts=None,centre=False,psf=False,pststars=None,
ids=None,dark=0,flat=1,timestamp="TIME",output='output',custom_process=None,
vary=False):
"""If psf==True, must include all extra par files.
If PSF is a filename (.psf.fits), this profileis used to fit every image.
Timestamp can be either a file of times (same length as filelist), a header
keyword, or an array of times.
The input list can include [] notation for multiple extensions or sections
of each file (incompatible with header-based time-stamps).
custom_process(file) is a function taking a filename (possible including [x]
syntax) and places a processed image in temp.fits."""
output = open(output,'w')
x = load(coords,usecols=[1])
numstars = len(x)
myfiles = open(filelist).readlines()
myfiles = [myfiles[i][:-1] for i in range(len(myfiles))]
if timestamp.__class__ == numpy.ndarray: #--sort out times--
times = 1 #times=1 means we know the times beforehand
elif len(glob(timestamp))>0:
timestamp = load(timestamp,usecols=[0])
times=1
else:
times=0 #times=0 mean find the time from each image
if type(shifts)==type(" "): #--sort out shifts--
xshifts,yshifts = load(shifts,unpack=True)#filename give, assuming 2 columns
xshifts,yshifts = -xshifts,-yshifts #these are in the opposite sense to coords from stack
elif n.iterable(shifts):
xshifts=n.array(shifts[0]) #for shifts given as arrays/lists
yshifts=n.array(shifts[1])
else:
print "No shifts" #assume all shifts are zero
xshifts = n.zeros(len(myfiles))
yshifts = n.zeros(len(myfiles))
for i,thisfile in enumerate(myfiles): #run!
print i,thisfile
if times:
time = timestamp[i] #known time
else:
time = pyfits.getval(thisfile,timestamp) #FITS keyword
try:
iraf.dele('temp.fits')
if custom_process: #arbitrary subroutine to process a file -> temp.fits
custom_process(thisfile)
else: #typical dark/bias subtract and flatfield
iraf.imarith(thisfile,'-',dark,'temp')
iraf.imarith('temp','/',flat,'temp')
shift_file_coords(coords,xshifts[i],yshifts[i],'tempcoords') #apply coarse shifts
shift_file_coords(refstar,xshifts[i],yshifts[i],'tempref',sort='num')
if psf:
if psf is True: #full PSF fit
shift_file_coords(pststars,xshifts[i],yshifts[i],'temppst')
out=psfphot('temp.fits','tempcoords','temppst','tempref',centre,vary)
else: #DAOphot with known PSF
out=simplepsfphot('temp.fits','tempcoords',psf,'tempref',centre,vary)
else: #aperture photometry
out=apphot('temp.fits','tempcoords','tempref',centre,vary=vary)
output.write("%s %s %s "%(thisfile,time,vary_fwhm))
myids = n.array([int(out[i].split()[0]) for i in range(len(out))])
for i in ids or range(numstars):
try: #search for each requested ID
foundid = find(myids==i)[0]
output.write(out[foundid]+" ")
except: #ID not found
output.write(" 0 0 0 0 ")
output.write("\n")
except KeyboardInterrupt: #exit on Ctrl-C
break
except pyraf.irafglobals.IrafError, err:
print "IRAF error ",err,thisfile
break
except ValueError, err:
print "Value error ",err,thisfile
raise
output.close()
#iraf.dele('temp*')
| mit | [
624,
27200,
282,
769,
402,
1584,
436,
6040,
14664,
8983,
12,
436,
199,
15795,
3945,
357,
2358,
641,
3062,
1006,
12,
1902,
543,
282,
28621,
1482,
334,
838,
357,
9,
199,
269,
701,
29770,
21774,
334,
983,
411,
8885,
12,
1314,
1415,
4722,
199,
3214,
436,
365,
282,
496,
5655,
370,
1115,
269,
428,
15,
46,
503,
286,
1143,
770,
1504,
680,
199,
27142,
2178,
3398,
675,
402,
284,
345,
70,
6527,
27,
663,
1006,
3945,
357,
2358,
2633,
199,
5182,
3879,
26,
199,
576,
21152,
446,
367,
666,
2735,
6236,
8323,
199,
4218,
21152,
446,
17196,
314,
3659,
14664,
641,
1924,
1834,
14,
199,
4218,
21152,
12,
3945,
357,
21152,
12,
5542,
12267,
21152,
446,
367,
3304,
316,
282,
529,
7603,
3945,
357,
2358,
199,
983,
411,
4291,
446,
367,
3304,
316,
12927,
411,
8885,
199,
199,
14964,
26,
663,
402,
1834,
1584,
12,
315,
473,
2847,
38,
6302,
334,
1569,
14,
14948,
59,
17,
1527,
10381,
10381,
18,
61,
5423,
2736,
199,
2425,
506,
1655,
2419,
1373,
1126,
15681,
14,
199,
8032,
26,
536,
282,
570,
3035,
1006,
14664,
13259,
367,
3945,
357,
2358,
12,
4079,
641,
199,
290,
1834,
625,
26063,
471,
3847,
370,
334,
16,
12,
16,
9,
315,
314,
20863,
1086,
769,
14,
6423,
15111,
5579,
199,
509,
3945,
357,
1083,
12,
1275,
5615,
503,
1275,
2551,
367,
12927,
411,
8885,
1083,
14,
199,
26063,
1086,
26,
536,
282,
570,
3035,
20863,
1086,
12,
282,
2008,
402,
20863,
1086,
6572,
12,
1834,
199,
1291,
7681,
334,
2960,
402,
2877,
29,
503,
488,
367,
949,
20863,
1086,
199,
1121,
7848,
26,
13259,
402,
14664,
367,
5405,
4007,
334,
88,
12,
89,
9,
3268,
12,
465,
315,
13259,
199,
3954,
26,
1350,
402,
314,
20542,
2556,
26,
282,
1406,
4252,
12,
5762,
13,
84,
199,
509,
14818,
15877,
503,
282,
570,
543,
5431,
334,
262,
15685,
1824,
323,
1265,
7171,
506,
199,
4941,
2945,
14,
199,
199,
1190,
70,
26,
3775,
370,
675,
12927,
411,
8885,
503,
282,
529,
7603,
3945,
357,
367,
11284,
14,
982,
642,
365,
282,
199,
1501,
12,
626,
365,
314,
29770,
4690,
370,
675,
367,
4036,
1834,
27,
340,
652,
365,
298,
549,
401,
199,
1875,
282,
892,
29770,
367,
4036,
1834,
14,
2235,
83,
5084,
1454,
367,
2615,
29770,
21774,
199,
80,
270,
270,
4291,
26,
282,
1275,
80,
270,
570,
687,
12927,
411,
8885,
12,
13778,
314,
11449,
402,
410,
4291,
367,
10663,
199,
1589,
29770,
367,
1924,
1834,
14,
25377,
26,
577,
23320,
838,
357,
2984,
5589,
370,
9775,
1263,
14664,
543,
428,
17774,
28,
18,
14,
199,
199,
1580,
26,
1314,
410,
4291,
787,
19604,
12,
701,
2870,
334,
262,
1324,
11021,
769,
1865,
9,
199,
8032,
26,
6617,
5521,
13,
19116,
3297,
13259,
334,
80,
2724,
13,
379,
687,
282,
1275,
2551,
12,
25358,
680,
199,
624,
199,
646,
747,
199,
646,
2680,
199,
504,
5739,
492,
5739,
199,
646,
1134,
14948,
199,
504,
19199,
492,
2342,
199,
504,
2680,
492,
2248,
12,
20221,
12,
2117,
12,
13106,
199,
199,
3749,
694,
275,
747,
14,
9458,
342,
199,
736,
14,
8563,
4769,
4219,
15,
30695,
867,
531,
199,
504,
1134,
345,
70,
492,
284,
345,
70,
199,
20936,
70,
14,
2866,
8,
3749,
694,
9,
199,
20936,
70,
14,
18367,
711,
8885,
342,
199,
20936,
70,
14,
983,
411,
8885,
342,
199,
646,
1134,
345,
70,
199,
646,
1134,
14948,
199,
646,
2680,
465,
302,
199,
199,
318,
7706,
63,
493,
63,
8032,
8,
1501,
12,
88,
4723,
12,
588,
72,
2949,
12,
1199,
12,
3191,
29,
403,
304,
272,
408,
16001,
26580,
570,
1313,
26,
499,
13,
2301,
13294,
5579,
12,
1275,
5615,
12,
1275,
2551,
12,
1275,
80,
270,
14,
199,
16170,
26,
7706,
4910,
2382,
1924,
1834,
365,
12,
3847,
370,
314,
3379,
334,
1397,
2382,
199,
390,
1077,
506,
12155,
370,
680,
199,
624,
272,
340,
440,
8,
3191,
304,
267,
4069,
275,
283,
1507,
7,
267,
340,
1788,
14,
1623,
5175,
5615,
358,
30,
16,
26,
4069,
275,
283,
5615,
7,
267,
340,
1788,
14,
1623,
5175,
2551,
358,
30,
16,
26,
4069,
275,
283,
2551,
7,
267,
340,
1788,
14,
1623,
5175,
80,
270,
358,
30,
16,
26,
4069,
275,
283,
80,
270,
7,
272,
340,
440,
8,
3191,
6803,
1507,
7,
503,
4069,
6803,
5615,
7,
503,
4069,
6803,
2551,
7,
503,
4069,
6803,
80,
270,
735,
267,
746,
1722,
360,
5912,
1324,
26245,
26,
450,
83,
5956,
1501,
9,
272,
340,
4069,
6803,
1507,
356,
327,
7706,
499,
13,
2301,
8950,
10485,
1817,
267,
671,
12,
89,
275,
2248,
8,
1501,
12,
1180,
4574,
1524,
16,
12,
17,
467,
5301,
29,
549,
9,
267,
671,
847,
671,
4723,
267,
612,
847,
19205,
72,
2949,
267,
1323,
275,
373,
2340,
1332,
88,
12,
89,
430,
267,
3354,
8,
1199,
12,
56,
14,
10483,
1012,
267,
372,
272,
340,
4069,
6803,
5615,
356,
327,
4723,
282,
1275,
5615,
3945,
357,
2358,
570,
267,
289,
581,
275,
1551,
8,
1501,
9,
267,
289,
581,
65,
29,
1551,
8,
1199,
2584,
87,
358,
267,
367,
1004,
315,
289,
581,
26,
288,
340,
1004,
14,
1294,
19105,
17,
22954,
1103,
7,
436,
822,
8,
604,
14,
1294,
1012,
389,
25,
436,
1004,
59,
16,
61,
27909,
24397,
355,
671,
275,
2069,
8,
604,
14,
1294,
3430,
16,
566,
435,
671,
4723,
355,
612,
275,
2069,
8,
604,
14,
1294,
3430,
17,
566,
435,
19205,
72,
2949,
355,
1004,
275,
18301,
1079,
14,
19,
70,
19752,
845,
14,
19,
70,
14007,
88,
12,
89,
6393,
604,
59,
2025,
2938,
288,
289,
581,
65,
14,
952,
8,
604,
9,
463,
272,
340,
4069,
6803,
2551,
356,
327,
4723,
282,
1275,
2551,
577,
23320,
838,
357,
3945,
357,
2358,
570,
267,
289,
581,
275,
1551,
8,
1501,
9,
267,
289,
581,
65,
29,
1551,
8,
1199,
2584,
87,
358,
267,
367,
1004,
315,
289,
581,
26,
288,
340,
1004,
14,
1294,
19105,
17,
22954,
1103,
7,
436,
822,
8,
604,
14,
1294,
1012,
389,
24,
436,
1004,
59,
16,
61,
27909,
24397,
355,
671,
275,
2069,
8,
604,
14,
1294,
3430,
17,
566,
435,
671,
4723,
355,
612,
275,
2069,
8
] | [
27200,
282,
769,
402,
1584,
436,
6040,
14664,
8983,
12,
436,
199,
15795,
3945,
357,
2358,
641,
3062,
1006,
12,
1902,
543,
282,
28621,
1482,
334,
838,
357,
9,
199,
269,
701,
29770,
21774,
334,
983,
411,
8885,
12,
1314,
1415,
4722,
199,
3214,
436,
365,
282,
496,
5655,
370,
1115,
269,
428,
15,
46,
503,
286,
1143,
770,
1504,
680,
199,
27142,
2178,
3398,
675,
402,
284,
345,
70,
6527,
27,
663,
1006,
3945,
357,
2358,
2633,
199,
5182,
3879,
26,
199,
576,
21152,
446,
367,
666,
2735,
6236,
8323,
199,
4218,
21152,
446,
17196,
314,
3659,
14664,
641,
1924,
1834,
14,
199,
4218,
21152,
12,
3945,
357,
21152,
12,
5542,
12267,
21152,
446,
367,
3304,
316,
282,
529,
7603,
3945,
357,
2358,
199,
983,
411,
4291,
446,
367,
3304,
316,
12927,
411,
8885,
199,
199,
14964,
26,
663,
402,
1834,
1584,
12,
315,
473,
2847,
38,
6302,
334,
1569,
14,
14948,
59,
17,
1527,
10381,
10381,
18,
61,
5423,
2736,
199,
2425,
506,
1655,
2419,
1373,
1126,
15681,
14,
199,
8032,
26,
536,
282,
570,
3035,
1006,
14664,
13259,
367,
3945,
357,
2358,
12,
4079,
641,
199,
290,
1834,
625,
26063,
471,
3847,
370,
334,
16,
12,
16,
9,
315,
314,
20863,
1086,
769,
14,
6423,
15111,
5579,
199,
509,
3945,
357,
1083,
12,
1275,
5615,
503,
1275,
2551,
367,
12927,
411,
8885,
1083,
14,
199,
26063,
1086,
26,
536,
282,
570,
3035,
20863,
1086,
12,
282,
2008,
402,
20863,
1086,
6572,
12,
1834,
199,
1291,
7681,
334,
2960,
402,
2877,
29,
503,
488,
367,
949,
20863,
1086,
199,
1121,
7848,
26,
13259,
402,
14664,
367,
5405,
4007,
334,
88,
12,
89,
9,
3268,
12,
465,
315,
13259,
199,
3954,
26,
1350,
402,
314,
20542,
2556,
26,
282,
1406,
4252,
12,
5762,
13,
84,
199,
509,
14818,
15877,
503,
282,
570,
543,
5431,
334,
262,
15685,
1824,
323,
1265,
7171,
506,
199,
4941,
2945,
14,
199,
199,
1190,
70,
26,
3775,
370,
675,
12927,
411,
8885,
503,
282,
529,
7603,
3945,
357,
367,
11284,
14,
982,
642,
365,
282,
199,
1501,
12,
626,
365,
314,
29770,
4690,
370,
675,
367,
4036,
1834,
27,
340,
652,
365,
298,
549,
401,
199,
1875,
282,
892,
29770,
367,
4036,
1834,
14,
2235,
83,
5084,
1454,
367,
2615,
29770,
21774,
199,
80,
270,
270,
4291,
26,
282,
1275,
80,
270,
570,
687,
12927,
411,
8885,
12,
13778,
314,
11449,
402,
410,
4291,
367,
10663,
199,
1589,
29770,
367,
1924,
1834,
14,
25377,
26,
577,
23320,
838,
357,
2984,
5589,
370,
9775,
1263,
14664,
543,
428,
17774,
28,
18,
14,
199,
199,
1580,
26,
1314,
410,
4291,
787,
19604,
12,
701,
2870,
334,
262,
1324,
11021,
769,
1865,
9,
199,
8032,
26,
6617,
5521,
13,
19116,
3297,
13259,
334,
80,
2724,
13,
379,
687,
282,
1275,
2551,
12,
25358,
680,
199,
624,
199,
646,
747,
199,
646,
2680,
199,
504,
5739,
492,
5739,
199,
646,
1134,
14948,
199,
504,
19199,
492,
2342,
199,
504,
2680,
492,
2248,
12,
20221,
12,
2117,
12,
13106,
199,
199,
3749,
694,
275,
747,
14,
9458,
342,
199,
736,
14,
8563,
4769,
4219,
15,
30695,
867,
531,
199,
504,
1134,
345,
70,
492,
284,
345,
70,
199,
20936,
70,
14,
2866,
8,
3749,
694,
9,
199,
20936,
70,
14,
18367,
711,
8885,
342,
199,
20936,
70,
14,
983,
411,
8885,
342,
199,
646,
1134,
345,
70,
199,
646,
1134,
14948,
199,
646,
2680,
465,
302,
199,
199,
318,
7706,
63,
493,
63,
8032,
8,
1501,
12,
88,
4723,
12,
588,
72,
2949,
12,
1199,
12,
3191,
29,
403,
304,
272,
408,
16001,
26580,
570,
1313,
26,
499,
13,
2301,
13294,
5579,
12,
1275,
5615,
12,
1275,
2551,
12,
1275,
80,
270,
14,
199,
16170,
26,
7706,
4910,
2382,
1924,
1834,
365,
12,
3847,
370,
314,
3379,
334,
1397,
2382,
199,
390,
1077,
506,
12155,
370,
680,
199,
624,
272,
340,
440,
8,
3191,
304,
267,
4069,
275,
283,
1507,
7,
267,
340,
1788,
14,
1623,
5175,
5615,
358,
30,
16,
26,
4069,
275,
283,
5615,
7,
267,
340,
1788,
14,
1623,
5175,
2551,
358,
30,
16,
26,
4069,
275,
283,
2551,
7,
267,
340,
1788,
14,
1623,
5175,
80,
270,
358,
30,
16,
26,
4069,
275,
283,
80,
270,
7,
272,
340,
440,
8,
3191,
6803,
1507,
7,
503,
4069,
6803,
5615,
7,
503,
4069,
6803,
2551,
7,
503,
4069,
6803,
80,
270,
735,
267,
746,
1722,
360,
5912,
1324,
26245,
26,
450,
83,
5956,
1501,
9,
272,
340,
4069,
6803,
1507,
356,
327,
7706,
499,
13,
2301,
8950,
10485,
1817,
267,
671,
12,
89,
275,
2248,
8,
1501,
12,
1180,
4574,
1524,
16,
12,
17,
467,
5301,
29,
549,
9,
267,
671,
847,
671,
4723,
267,
612,
847,
19205,
72,
2949,
267,
1323,
275,
373,
2340,
1332,
88,
12,
89,
430,
267,
3354,
8,
1199,
12,
56,
14,
10483,
1012,
267,
372,
272,
340,
4069,
6803,
5615,
356,
327,
4723,
282,
1275,
5615,
3945,
357,
2358,
570,
267,
289,
581,
275,
1551,
8,
1501,
9,
267,
289,
581,
65,
29,
1551,
8,
1199,
2584,
87,
358,
267,
367,
1004,
315,
289,
581,
26,
288,
340,
1004,
14,
1294,
19105,
17,
22954,
1103,
7,
436,
822,
8,
604,
14,
1294,
1012,
389,
25,
436,
1004,
59,
16,
61,
27909,
24397,
355,
671,
275,
2069,
8,
604,
14,
1294,
3430,
16,
566,
435,
671,
4723,
355,
612,
275,
2069,
8,
604,
14,
1294,
3430,
17,
566,
435,
19205,
72,
2949,
355,
1004,
275,
18301,
1079,
14,
19,
70,
19752,
845,
14,
19,
70,
14007,
88,
12,
89,
6393,
604,
59,
2025,
2938,
288,
289,
581,
65,
14,
952,
8,
604,
9,
463,
272,
340,
4069,
6803,
2551,
356,
327,
4723,
282,
1275,
2551,
577,
23320,
838,
357,
3945,
357,
2358,
570,
267,
289,
581,
275,
1551,
8,
1501,
9,
267,
289,
581,
65,
29,
1551,
8,
1199,
2584,
87,
358,
267,
367,
1004,
315,
289,
581,
26,
288,
340,
1004,
14,
1294,
19105,
17,
22954,
1103,
7,
436,
822,
8,
604,
14,
1294,
1012,
389,
24,
436,
1004,
59,
16,
61,
27909,
24397,
355,
671,
275,
2069,
8,
604,
14,
1294,
3430,
17,
566,
435,
671,
4723,
355,
612,
275,
2069,
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,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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
] |
dunkhong/grr | grr/server/grr_response_server/databases/db_yara_test_lib.py | 1 | 1573 | #!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""A module with test cases for the YARA database method."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
import os
from grr_response_server.databases import db
from grr_response_server.rdfvalues import objects as rdf_objects
class DatabaseTestYaraMixin(object):
"""A mixin class for testing YARA methods of database implementations."""
def testWriteYaraSignatureReferenceIncorrectUsername(self):
blob_id = rdf_objects.BlobID(os.urandom(32))
with self.assertRaises(db.UnknownGRRUserError) as context:
self.db.WriteYaraSignatureReference(blob_id=blob_id, username="quux")
self.assertEqual(context.exception.username, "quux")
def testWriteYaraSignatureReferenceDuplicated(self):
self.db.WriteGRRUser("foo")
blob_id = rdf_objects.BlobID(os.urandom(32))
# Writing duplicated signatures is possible, it should not raise.
self.db.WriteYaraSignatureReference(blob_id=blob_id, username="foo")
self.db.WriteYaraSignatureReference(blob_id=blob_id, username="foo")
def testVerifyYaraSignatureReferenceSimple(self):
self.db.WriteGRRUser("foo")
blob_id = rdf_objects.BlobID(os.urandom(32))
self.db.WriteYaraSignatureReference(blob_id=blob_id, username="foo")
self.assertTrue(self.db.VerifyYaraSignatureReference(blob_id))
def testVerifyYaraSignatureReferenceIncorrect(self):
blob_id = rdf_objects.BlobID(os.urandom(32))
self.assertFalse(self.db.VerifyYaraSignatureReference(blob_id))
| apache-2.0 | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2644,
26,
2774,
13,
24,
1882,
199,
624,
33,
859,
543,
511,
5560,
367,
314,
1488,
689,
33,
3050,
1083,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
199,
504,
31118,
63,
1310,
63,
1000,
14,
17439,
492,
1592,
199,
504,
31118,
63,
1310,
63,
1000,
14,
17120,
1459,
492,
2251,
465,
18148,
63,
1462,
421,
199,
533,
8692,
774,
57,
17956,
4256,
8,
785,
304,
523,
408,
33,
20048,
1021,
367,
5343,
1488,
689,
33,
3102,
402,
3050,
12591,
1041,
819,
347,
511,
3534,
57,
17956,
10014,
5083,
18298,
13355,
8,
277,
304,
272,
9182,
63,
344,
275,
18148,
63,
1462,
14,
16799,
998,
8,
736,
14,
22776,
8,
708,
430,
339,
543,
291,
14,
1855,
8,
697,
14,
5912,
3975,
50,
1899,
547,
9,
465,
1067,
26,
489,
291,
14,
697,
14,
3534,
57,
17956,
10014,
5083,
8,
6582,
63,
344,
29,
6582,
63,
344,
12,
3434,
628,
32050,
531,
339,
291,
14,
629,
8,
1100,
14,
1971,
14,
2473,
12,
298,
32050,
531,
819,
347,
511,
3534,
57,
17956,
10014,
5083,
36,
16724,
8,
277,
304,
272,
291,
14,
697,
14,
3534,
3975,
50,
1899,
480,
1421,
531,
339,
9182,
63,
344,
275,
18148,
63,
1462,
14,
16799,
998,
8,
736,
14,
22776,
8,
708,
430,
339,
327,
12859,
1337,
21747,
17597,
365,
3962,
12,
652,
1077,
440,
746,
14,
272,
291,
14,
697,
14,
3534,
57,
17956,
10014,
5083,
8,
6582,
63,
344,
29,
6582,
63,
344,
12,
3434,
628,
1421,
531,
272,
291,
14,
697,
14,
3534,
57,
17956,
10014,
5083,
8,
6582,
63,
344,
29,
6582,
63,
344,
12,
3434,
628,
1421,
531,
819,
347,
511,
7496,
57,
17956,
10014,
5083,
3184,
8,
277,
304,
272,
291,
14,
697,
14,
3534,
3975,
50,
1899,
480,
1421,
531,
339,
9182,
63,
344,
275,
18148,
63,
1462,
14,
16799,
998,
8,
736,
14,
22776,
8,
708,
430,
272,
291,
14,
697,
14,
3534,
57,
17956,
10014,
5083,
8,
6582,
63,
344,
29,
6582,
63,
344,
12,
3434,
628,
1421,
531,
339,
291,
14,
1815,
8,
277,
14,
697,
14,
7496,
57,
17956,
10014,
5083,
8,
6582,
63,
344,
430,
819,
347,
511,
7496,
57,
17956,
10014,
5083,
18298,
8,
277,
304,
272,
9182,
63,
344,
275,
18148,
63,
1462,
14,
16799,
998,
8,
736,
14,
22776,
8,
708,
430,
339,
291,
14,
3334,
8,
277,
14,
697,
14,
7496,
57,
17956,
10014,
5083,
8,
6582,
63,
344,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
2644,
26,
2774,
13,
24,
1882,
199,
624,
33,
859,
543,
511,
5560,
367,
314,
1488,
689,
33,
3050,
1083,
1041,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
747,
199,
199,
504,
31118,
63,
1310,
63,
1000,
14,
17439,
492,
1592,
199,
504,
31118,
63,
1310,
63,
1000,
14,
17120,
1459,
492,
2251,
465,
18148,
63,
1462,
421,
199,
533,
8692,
774,
57,
17956,
4256,
8,
785,
304,
523,
408,
33,
20048,
1021,
367,
5343,
1488,
689,
33,
3102,
402,
3050,
12591,
1041,
819,
347,
511,
3534,
57,
17956,
10014,
5083,
18298,
13355,
8,
277,
304,
272,
9182,
63,
344,
275,
18148,
63,
1462,
14,
16799,
998,
8,
736,
14,
22776,
8,
708,
430,
339,
543,
291,
14,
1855,
8,
697,
14,
5912,
3975,
50,
1899,
547,
9,
465,
1067,
26,
489,
291,
14,
697,
14,
3534,
57,
17956,
10014,
5083,
8,
6582,
63,
344,
29,
6582,
63,
344,
12,
3434,
628,
32050,
531,
339,
291,
14,
629,
8,
1100,
14,
1971,
14,
2473,
12,
298,
32050,
531,
819,
347,
511,
3534,
57,
17956,
10014,
5083,
36,
16724,
8,
277,
304,
272,
291,
14,
697,
14,
3534,
3975,
50,
1899,
480,
1421,
531,
339,
9182,
63,
344,
275,
18148,
63,
1462,
14,
16799,
998,
8,
736,
14,
22776,
8,
708,
430,
339,
327,
12859,
1337,
21747,
17597,
365,
3962,
12,
652,
1077,
440,
746,
14,
272,
291,
14,
697,
14,
3534,
57,
17956,
10014,
5083,
8,
6582,
63,
344,
29,
6582,
63,
344,
12,
3434,
628,
1421,
531,
272,
291,
14,
697,
14,
3534,
57,
17956,
10014,
5083,
8,
6582,
63,
344,
29,
6582,
63,
344,
12,
3434,
628,
1421,
531,
819,
347,
511,
7496,
57,
17956,
10014,
5083,
3184,
8,
277,
304,
272,
291,
14,
697,
14,
3534,
3975,
50,
1899,
480,
1421,
531,
339,
9182,
63,
344,
275,
18148,
63,
1462,
14,
16799,
998,
8,
736,
14,
22776,
8,
708,
430,
272,
291,
14,
697,
14,
3534,
57,
17956,
10014,
5083,
8,
6582,
63,
344,
29,
6582,
63,
344,
12,
3434,
628,
1421,
531,
339,
291,
14,
1815,
8,
277,
14,
697,
14,
7496,
57,
17956,
10014,
5083,
8,
6582,
63,
344,
430,
819,
347,
511,
7496,
57,
17956,
10014,
5083,
18298,
8,
277,
304,
272,
9182,
63,
344,
275,
18148,
63,
1462,
14,
16799,
998,
8,
736,
14,
22776,
8,
708,
430,
339,
291,
14,
3334,
8,
277,
14,
697,
14,
7496,
57,
17956,
10014,
5083,
8,
6582,
63,
344,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
baslr/ArangoDB | 3rdParty/V8/V8-5.0.71.39/tools/clang/scripts/run_tool.py | 10 | 11655 | #!/usr/bin/env python
# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Wrapper script to help run clang tools across Chromium code.
How to use this tool:
If you want to run the tool across all Chromium code:
run_tool.py <tool> <path/to/compiledb>
If you want to include all files mentioned in the compilation database:
run_tool.py <tool> <path/to/compiledb> --all
If you only want to run the tool across just chrome/browser and content/browser:
run_tool.py <tool> <path/to/compiledb> chrome/browser content/browser
Please see https://code.google.com/p/chromium/wiki/ClangToolRefactoring for more
information, which documents the entire automated refactoring flow in Chromium.
Why use this tool:
The clang tool implementation doesn't take advantage of multiple cores, and if
it fails mysteriously in the middle, all the generated replacements will be
lost.
Unfortunately, if the work is simply sharded across multiple cores by running
multiple RefactoringTools, problems arise when they attempt to rewrite a file at
the same time. To work around that, clang tools that are run using this tool
should output edits to stdout in the following format:
==== BEGIN EDITS ====
r:<file path>:<offset>:<length>:<replacement text>
r:<file path>:<offset>:<length>:<replacement text>
...etc...
==== END EDITS ====
Any generated edits are applied once the clang tool has finished running
across Chromium, regardless of whether some instances failed or not.
"""
import argparse
import collections
import functools
import json
import multiprocessing
import os.path
import subprocess
import sys
Edit = collections.namedtuple('Edit',
('edit_type', 'offset', 'length', 'replacement'))
def _GenerateCompileDatabase(path):
"""Generates a compile database.
Note: requires ninja.
Args:
path: The build directory to generate a compile database for.
"""
# TODO(dcheng): Incorporate Windows-specific compile DB munging from
# https://codereview.chromium.org/718873004
print 'Generating compile database in %s...' % path
args = ['ninja', '-C', path, '-t', 'compdb', 'cc', 'cxx', 'objc', 'objcxx']
output = subprocess.check_output(args)
with file(os.path.join(path, 'compile_commands.json'), 'w') as f:
f.write(output)
def _GetFilesFromGit(paths=None):
"""Gets the list of files in the git repository.
Args:
paths: Prefix filter for the returned paths. May contain multiple entries.
"""
args = []
if sys.platform == 'win32':
args.append('git.bat')
else:
args.append('git')
args.append('ls-files')
if paths:
args.extend(paths)
command = subprocess.Popen(args, stdout=subprocess.PIPE)
output, _ = command.communicate()
return [os.path.realpath(p) for p in output.splitlines()]
def _GetFilesFromCompileDB(build_directory):
""" Gets the list of files mentioned in the compilation database.
Args:
build_directory: Directory that contains the compile database.
"""
compiledb_path = os.path.join(build_directory, 'compile_commands.json')
with open(compiledb_path, 'rb') as compiledb_file:
json_commands = json.load(compiledb_file)
return [os.path.join(entry['directory'], entry['file'])
for entry in json_commands]
def _ExtractEditsFromStdout(build_directory, stdout):
"""Extracts generated list of edits from the tool's stdout.
The expected format is documented at the top of this file.
Args:
build_directory: Directory that contains the compile database. Used to
normalize the filenames.
stdout: The stdout from running the clang tool.
Returns:
A dictionary mapping filenames to the associated edits.
"""
lines = stdout.splitlines()
start_index = lines.index('==== BEGIN EDITS ====')
end_index = lines.index('==== END EDITS ====')
edits = collections.defaultdict(list)
for line in lines[start_index + 1:end_index]:
try:
edit_type, path, offset, length, replacement = line.split(':::', 4)
replacement = replacement.replace('\0', '\n')
# Normalize the file path emitted by the clang tool.
path = os.path.realpath(os.path.join(build_directory, path))
edits[path].append(Edit(edit_type, int(offset), int(length), replacement))
except ValueError:
print 'Unable to parse edit: %s' % line
return edits
def _ExecuteTool(toolname, build_directory, filename):
"""Executes the tool.
This is defined outside the class so it can be pickled for the multiprocessing
module.
Args:
toolname: Path to the tool to execute.
build_directory: Directory that contains the compile database.
filename: The file to run the tool over.
Returns:
A dictionary that must contain the key "status" and a boolean value
associated with it.
If status is True, then the generated edits are stored with the key "edits"
in the dictionary.
Otherwise, the filename and the output from stderr are associated with the
keys "filename" and "stderr" respectively.
"""
command = subprocess.Popen(
(toolname, '-p', build_directory, filename),
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
stdout, stderr = command.communicate()
if command.returncode != 0:
return {'status': False, 'filename': filename, 'stderr': stderr}
else:
return {'status': True,
'edits': _ExtractEditsFromStdout(build_directory, stdout)}
class _CompilerDispatcher(object):
"""Multiprocessing controller for running clang tools in parallel."""
def __init__(self, toolname, build_directory, filenames):
"""Initializer method.
Args:
toolname: Path to the tool to execute.
build_directory: Directory that contains the compile database.
filenames: The files to run the tool over.
"""
self.__toolname = toolname
self.__build_directory = build_directory
self.__filenames = filenames
self.__success_count = 0
self.__failed_count = 0
self.__edit_count = 0
self.__edits = collections.defaultdict(list)
@property
def edits(self):
return self.__edits
@property
def failed_count(self):
return self.__failed_count
def Run(self):
"""Does the grunt work."""
pool = multiprocessing.Pool()
result_iterator = pool.imap_unordered(
functools.partial(_ExecuteTool, self.__toolname,
self.__build_directory), self.__filenames)
for result in result_iterator:
self.__ProcessResult(result)
sys.stdout.write('\n')
sys.stdout.flush()
def __ProcessResult(self, result):
"""Handles result processing.
Args:
result: The result dictionary returned by _ExecuteTool.
"""
if result['status']:
self.__success_count += 1
for k, v in result['edits'].iteritems():
self.__edits[k].extend(v)
self.__edit_count += len(v)
else:
self.__failed_count += 1
sys.stdout.write('\nFailed to process %s\n' % result['filename'])
sys.stdout.write(result['stderr'])
sys.stdout.write('\n')
percentage = (float(self.__success_count + self.__failed_count) /
len(self.__filenames)) * 100
sys.stdout.write('Succeeded: %d, Failed: %d, Edits: %d [%.2f%%]\r' %
(self.__success_count, self.__failed_count,
self.__edit_count, percentage))
sys.stdout.flush()
def _ApplyEdits(edits):
"""Apply the generated edits.
Args:
edits: A dict mapping filenames to Edit instances that apply to that file.
"""
edit_count = 0
for k, v in edits.iteritems():
# Sort the edits and iterate through them in reverse order. Sorting allows
# duplicate edits to be quickly skipped, while reversing means that
# subsequent edits don't need to have their offsets updated with each edit
# applied.
v.sort()
last_edit = None
with open(k, 'rb+') as f:
contents = bytearray(f.read())
for edit in reversed(v):
if edit == last_edit:
continue
last_edit = edit
contents[edit.offset:edit.offset + edit.length] = edit.replacement
if not edit.replacement:
_ExtendDeletionIfElementIsInList(contents, edit.offset)
edit_count += 1
f.seek(0)
f.truncate()
f.write(contents)
print 'Applied %d edits to %d files' % (edit_count, len(edits))
_WHITESPACE_BYTES = frozenset((ord('\t'), ord('\n'), ord('\r'), ord(' ')))
def _ExtendDeletionIfElementIsInList(contents, offset):
"""Extends the range of a deletion if the deleted element was part of a list.
This rewriter helper makes it easy for refactoring tools to remove elements
from a list. Even if a matcher callback knows that it is removing an element
from a list, it may not have enough information to accurately remove the list
element; for example, another matcher callback may end up removing an adjacent
list element, or all the list elements may end up being removed.
With this helper, refactoring tools can simply remove the list element and not
worry about having to include the comma in the replacement.
Args:
contents: A bytearray with the deletion already applied.
offset: The offset in the bytearray where the deleted range used to be.
"""
char_before = char_after = None
left_trim_count = 0
for byte in reversed(contents[:offset]):
left_trim_count += 1
if byte in _WHITESPACE_BYTES:
continue
if byte in (ord(','), ord(':'), ord('('), ord('{')):
char_before = chr(byte)
break
right_trim_count = 0
for byte in contents[offset:]:
right_trim_count += 1
if byte in _WHITESPACE_BYTES:
continue
if byte == ord(','):
char_after = chr(byte)
break
if char_before:
if char_after:
del contents[offset:offset + right_trim_count]
elif char_before in (',', ':'):
del contents[offset - left_trim_count:offset]
def main():
parser = argparse.ArgumentParser()
parser.add_argument('tool', help='clang tool to run')
parser.add_argument('--all', action='store_true')
parser.add_argument(
'--generate-compdb',
action='store_true',
help='regenerate the compile database before running the tool')
parser.add_argument(
'compile_database',
help='path to the directory that contains the compile database')
parser.add_argument(
'path_filter',
nargs='*',
help='optional paths to filter what files the tool is run on')
args = parser.parse_args()
if args.generate_compdb:
_GenerateCompileDatabase(args.compile_database)
if args.all:
filenames = set(_GetFilesFromCompileDB(args.compile_database))
source_filenames = filenames
else:
filenames = set(_GetFilesFromGit(args.path_filter))
# Filter out files that aren't C/C++/Obj-C/Obj-C++.
extensions = frozenset(('.c', '.cc', '.cpp', '.m', '.mm'))
source_filenames = [f
for f in filenames
if os.path.splitext(f)[1] in extensions]
dispatcher = _CompilerDispatcher(args.tool, args.compile_database,
source_filenames)
dispatcher.Run()
# Filter out edits to files that aren't in the git repository, since it's not
# useful to modify files that aren't under source control--typically, these
# are generated files or files in a git submodule that's not part of Chromium.
_ApplyEdits({k: v
for k, v in dispatcher.edits.iteritems()
if os.path.realpath(k) in filenames})
return -dispatcher.failed_count
if __name__ == '__main__':
sys.exit(main())
| apache-2.0 | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
624,
4590,
2884,
370,
1720,
1255,
25444,
7249,
9371,
12051,
1233,
14,
199,
199,
18335,
370,
675,
642,
4744,
26,
199,
3917,
1265,
2934,
370,
1255,
314,
4744,
9371,
1006,
12051,
1233,
26,
199,
1065,
63,
3557,
14,
647,
665,
3557,
30,
665,
515,
15,
475,
15,
2014,
697,
30,
199,
199,
3917,
1265,
2934,
370,
2387,
1006,
1584,
26239,
315,
314,
18653,
3050,
26,
199,
1065,
63,
3557,
14,
647,
665,
3557,
30,
665,
515,
15,
475,
15,
2014,
697,
30,
1553,
452,
199,
199,
3917,
1265,
1454,
2934,
370,
1255,
314,
4744,
9371,
2951,
18221,
15,
5750,
436,
1564,
15,
5750,
26,
199,
1065,
63,
3557,
14,
647,
665,
3557,
30,
665,
515,
15,
475,
15,
2014,
697,
30,
18221,
15,
5750,
1564,
15,
5750,
199,
199,
8254,
1937,
4178,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
13211,
15,
6797,
15,
1968,
621,
5157,
497,
4778,
316,
367,
1655,
199,
11697,
12,
1314,
8247,
314,
8039,
6384,
23513,
24200,
316,
6369,
315,
12051,
14,
199,
199,
55,
3577,
675,
642,
4744,
26,
199,
1918,
25444,
4744,
4514,
3181,
1133,
5452,
30268,
402,
3663,
23857,
12,
436,
340,
199,
390,
6918,
333,
588,
6236,
1785,
590,
315,
314,
12180,
12,
1006,
314,
4046,
22372,
911,
506,
199,
22031,
14,
199,
199,
1358,
21839,
12,
340,
314,
1736,
365,
9329,
1033,
12910,
9371,
3663,
23857,
701,
3879,
199,
6048,
799,
4778,
316,
11654,
12,
8826,
14554,
261,
1380,
2985,
7427,
370,
19913,
282,
570,
737,
199,
1589,
2011,
900,
14,
4005,
1736,
6818,
626,
12,
25444,
7249,
626,
787,
1255,
1808,
642,
4744,
199,
5626,
1072,
7860,
1086,
370,
3839,
315,
314,
2569,
1475,
26,
199,
199,
532,
16427,
24981,
51,
275,
5918,
199,
82,
16875,
493,
931,
30,
16875,
2743,
30,
16875,
1267,
30,
16875,
15895,
1318,
30,
199,
82,
16875,
493,
931,
30,
16875,
2743,
30,
16875,
1267,
30,
16875,
15895,
1318,
30,
199,
1396,
6839,
1396,
199,
532,
7729,
24981,
51,
275,
5918,
199,
199,
9874,
4046,
7860,
1086,
787,
6781,
5403,
314,
25444,
4744,
965,
9158,
3879,
199,
32293,
12051,
12,
15270,
402,
3775,
2005,
4454,
3405,
503,
440,
14,
199,
624,
199,
199,
646,
7534,
199,
646,
5055,
199,
646,
9143,
199,
646,
2022,
199,
646,
12866,
199,
646,
747,
14,
515,
199,
646,
3873,
199,
646,
984,
199,
199,
4685,
275,
5055,
14,
18921,
360,
4685,
297,
2892,
661,
3773,
63,
466,
297,
283,
2743,
297,
283,
1267,
297,
283,
15895,
1333,
421,
199,
318,
485,
6864,
12626,
7243,
8,
515,
304,
523,
408,
20551,
282,
6555,
3050,
14,
819,
3390,
26,
5074,
14822,
14,
819,
3033,
26,
272,
931,
26,
710,
1900,
2082,
370,
3550,
282,
6555,
3050,
367,
14,
523,
408,
523,
327,
3254,
8,
68,
335,
7420,
304,
1010,
20504,
323,
5417,
13,
6100,
6555,
6249,
333,
324,
1540,
687,
523,
327,
4178,
921,
600,
8578,
14,
13211,
14,
1308,
15,
26948,
1555,
5863,
20,
523,
870,
283,
29244,
6555,
3050,
315,
450,
83,
13698,
450,
931,
523,
1249,
275,
788,
8675,
297,
2475,
35,
297,
931,
12,
2475,
84,
297,
283,
863,
697,
297,
283,
2055,
297,
283,
9634,
297,
283,
27148,
297,
283,
1113,
9634,
418,
523,
1072,
275,
3873,
14,
1074,
63,
1199,
8,
589,
9,
523,
543,
570,
8,
736,
14,
515,
14,
904,
8,
515,
12,
283,
2014,
63,
4405,
14,
1001,
659,
283,
87,
358,
465,
289,
26,
272,
289,
14,
952,
8,
1199,
9,
421,
199,
318,
485,
1002,
5535,
2532,
14686,
8,
3771,
29,
403,
304,
523,
408,
14426,
314,
769,
402,
1584,
315,
314,
6135,
7611,
14,
819,
3033,
26,
272,
3792,
26,
25110,
2457,
367,
314,
2138,
3792,
14,
10162,
1395,
3663,
4811,
14,
523,
408,
523,
1249,
275,
942,
523,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
272,
1249,
14,
740,
360,
3187,
14,
13475,
358,
523,
587,
26,
272,
1249,
14,
740,
360,
3187,
358,
523,
1249,
14,
740,
360,
478,
13,
1725,
358,
523,
340,
3792,
26,
272,
1249,
14,
2880,
8,
3771,
9,
523,
1414,
275,
3873,
14,
7942,
8,
589,
12,
3839,
29,
5781,
14,
6089,
9,
523,
1072,
12,
485,
275,
1414,
14,
10664,
342,
523,
372,
359,
736,
14,
515,
14,
11091,
8,
80,
9,
367,
299,
315,
1072,
14,
7644,
5106,
421,
199,
318,
485,
1002,
5535,
2532,
12626,
2846,
8,
1506,
63,
3619,
304,
523,
408,
14509,
314,
769,
402,
1584,
26239,
315,
314,
18653,
3050,
14,
819,
3033,
26,
272,
1900,
63,
3619,
26,
15191,
626,
3509,
314,
6555,
3050,
14,
523,
408,
523,
6555,
697,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1506,
63,
3619,
12,
283,
2014,
63,
4405,
14,
1001,
358,
523,
543,
1551,
8,
2014,
697,
63,
515,
12,
283,
4848,
358,
465,
6555,
697,
63,
493,
26,
272,
2022,
63,
4405,
275,
2022,
14,
912,
8,
2014,
697,
63,
493,
9,
819,
372,
359,
736,
14,
515,
14,
904,
8,
2373,
459,
3619,
995,
2397,
459,
493,
1105,
881,
367,
2397,
315,
2022,
63,
4405,
61,
421,
199,
318,
485,
12147,
37,
15256,
2532,
26080,
8,
1506,
63,
3619,
12,
3839,
304,
523,
408,
12147,
83,
4046,
769,
402,
7860,
1086,
687,
314,
4744,
1159,
3839,
14,
819,
710,
1420,
1475,
365,
22751,
737,
314,
2746,
402,
642,
570,
14,
819,
3033,
26,
272,
1900,
63,
3619,
26,
15191,
626,
3509,
314,
6555,
3050,
14,
8051,
370,
489,
7666,
314,
6203,
14,
272,
3839,
26,
710,
3839,
687,
3879,
314,
25444,
4744,
14,
819,
1803,
26,
272,
437,
2600,
4412,
6203,
370,
314,
4568,
7860,
1086,
14,
523,
408,
523,
2385,
275,
3839,
14,
7644,
342,
523,
1343,
63,
1080,
275,
2385,
14,
1080,
360,
532,
16427,
24981,
51,
275,
5918,
358,
523,
1284,
63,
1080,
275,
2385,
14,
1080,
360,
532,
7729,
24981,
51,
275,
5918,
358,
523,
7860,
1086,
275,
5055,
14,
21501
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
334,
67,
9,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
624,
4590,
2884,
370,
1720,
1255,
25444,
7249,
9371,
12051,
1233,
14,
199,
199,
18335,
370,
675,
642,
4744,
26,
199,
3917,
1265,
2934,
370,
1255,
314,
4744,
9371,
1006,
12051,
1233,
26,
199,
1065,
63,
3557,
14,
647,
665,
3557,
30,
665,
515,
15,
475,
15,
2014,
697,
30,
199,
199,
3917,
1265,
2934,
370,
2387,
1006,
1584,
26239,
315,
314,
18653,
3050,
26,
199,
1065,
63,
3557,
14,
647,
665,
3557,
30,
665,
515,
15,
475,
15,
2014,
697,
30,
1553,
452,
199,
199,
3917,
1265,
1454,
2934,
370,
1255,
314,
4744,
9371,
2951,
18221,
15,
5750,
436,
1564,
15,
5750,
26,
199,
1065,
63,
3557,
14,
647,
665,
3557,
30,
665,
515,
15,
475,
15,
2014,
697,
30,
18221,
15,
5750,
1564,
15,
5750,
199,
199,
8254,
1937,
4178,
921,
600,
14,
3098,
14,
957,
15,
80,
15,
13211,
15,
6797,
15,
1968,
621,
5157,
497,
4778,
316,
367,
1655,
199,
11697,
12,
1314,
8247,
314,
8039,
6384,
23513,
24200,
316,
6369,
315,
12051,
14,
199,
199,
55,
3577,
675,
642,
4744,
26,
199,
1918,
25444,
4744,
4514,
3181,
1133,
5452,
30268,
402,
3663,
23857,
12,
436,
340,
199,
390,
6918,
333,
588,
6236,
1785,
590,
315,
314,
12180,
12,
1006,
314,
4046,
22372,
911,
506,
199,
22031,
14,
199,
199,
1358,
21839,
12,
340,
314,
1736,
365,
9329,
1033,
12910,
9371,
3663,
23857,
701,
3879,
199,
6048,
799,
4778,
316,
11654,
12,
8826,
14554,
261,
1380,
2985,
7427,
370,
19913,
282,
570,
737,
199,
1589,
2011,
900,
14,
4005,
1736,
6818,
626,
12,
25444,
7249,
626,
787,
1255,
1808,
642,
4744,
199,
5626,
1072,
7860,
1086,
370,
3839,
315,
314,
2569,
1475,
26,
199,
199,
532,
16427,
24981,
51,
275,
5918,
199,
82,
16875,
493,
931,
30,
16875,
2743,
30,
16875,
1267,
30,
16875,
15895,
1318,
30,
199,
82,
16875,
493,
931,
30,
16875,
2743,
30,
16875,
1267,
30,
16875,
15895,
1318,
30,
199,
1396,
6839,
1396,
199,
532,
7729,
24981,
51,
275,
5918,
199,
199,
9874,
4046,
7860,
1086,
787,
6781,
5403,
314,
25444,
4744,
965,
9158,
3879,
199,
32293,
12051,
12,
15270,
402,
3775,
2005,
4454,
3405,
503,
440,
14,
199,
624,
199,
199,
646,
7534,
199,
646,
5055,
199,
646,
9143,
199,
646,
2022,
199,
646,
12866,
199,
646,
747,
14,
515,
199,
646,
3873,
199,
646,
984,
199,
199,
4685,
275,
5055,
14,
18921,
360,
4685,
297,
2892,
661,
3773,
63,
466,
297,
283,
2743,
297,
283,
1267,
297,
283,
15895,
1333,
421,
199,
318,
485,
6864,
12626,
7243,
8,
515,
304,
523,
408,
20551,
282,
6555,
3050,
14,
819,
3390,
26,
5074,
14822,
14,
819,
3033,
26,
272,
931,
26,
710,
1900,
2082,
370,
3550,
282,
6555,
3050,
367,
14,
523,
408,
523,
327,
3254,
8,
68,
335,
7420,
304,
1010,
20504,
323,
5417,
13,
6100,
6555,
6249,
333,
324,
1540,
687,
523,
327,
4178,
921,
600,
8578,
14,
13211,
14,
1308,
15,
26948,
1555,
5863,
20,
523,
870,
283,
29244,
6555,
3050,
315,
450,
83,
13698,
450,
931,
523,
1249,
275,
788,
8675,
297,
2475,
35,
297,
931,
12,
2475,
84,
297,
283,
863,
697,
297,
283,
2055,
297,
283,
9634,
297,
283,
27148,
297,
283,
1113,
9634,
418,
523,
1072,
275,
3873,
14,
1074,
63,
1199,
8,
589,
9,
523,
543,
570,
8,
736,
14,
515,
14,
904,
8,
515,
12,
283,
2014,
63,
4405,
14,
1001,
659,
283,
87,
358,
465,
289,
26,
272,
289,
14,
952,
8,
1199,
9,
421,
199,
318,
485,
1002,
5535,
2532,
14686,
8,
3771,
29,
403,
304,
523,
408,
14426,
314,
769,
402,
1584,
315,
314,
6135,
7611,
14,
819,
3033,
26,
272,
3792,
26,
25110,
2457,
367,
314,
2138,
3792,
14,
10162,
1395,
3663,
4811,
14,
523,
408,
523,
1249,
275,
942,
523,
340,
984,
14,
3246,
508,
283,
2676,
708,
356,
272,
1249,
14,
740,
360,
3187,
14,
13475,
358,
523,
587,
26,
272,
1249,
14,
740,
360,
3187,
358,
523,
1249,
14,
740,
360,
478,
13,
1725,
358,
523,
340,
3792,
26,
272,
1249,
14,
2880,
8,
3771,
9,
523,
1414,
275,
3873,
14,
7942,
8,
589,
12,
3839,
29,
5781,
14,
6089,
9,
523,
1072,
12,
485,
275,
1414,
14,
10664,
342,
523,
372,
359,
736,
14,
515,
14,
11091,
8,
80,
9,
367,
299,
315,
1072,
14,
7644,
5106,
421,
199,
318,
485,
1002,
5535,
2532,
12626,
2846,
8,
1506,
63,
3619,
304,
523,
408,
14509,
314,
769,
402,
1584,
26239,
315,
314,
18653,
3050,
14,
819,
3033,
26,
272,
1900,
63,
3619,
26,
15191,
626,
3509,
314,
6555,
3050,
14,
523,
408,
523,
6555,
697,
63,
515,
275,
747,
14,
515,
14,
904,
8,
1506,
63,
3619,
12,
283,
2014,
63,
4405,
14,
1001,
358,
523,
543,
1551,
8,
2014,
697,
63,
515,
12,
283,
4848,
358,
465,
6555,
697,
63,
493,
26,
272,
2022,
63,
4405,
275,
2022,
14,
912,
8,
2014,
697,
63,
493,
9,
819,
372,
359,
736,
14,
515,
14,
904,
8,
2373,
459,
3619,
995,
2397,
459,
493,
1105,
881,
367,
2397,
315,
2022,
63,
4405,
61,
421,
199,
318,
485,
12147,
37,
15256,
2532,
26080,
8,
1506,
63,
3619,
12,
3839,
304,
523,
408,
12147,
83,
4046,
769,
402,
7860,
1086,
687,
314,
4744,
1159,
3839,
14,
819,
710,
1420,
1475,
365,
22751,
737,
314,
2746,
402,
642,
570,
14,
819,
3033,
26,
272,
1900,
63,
3619,
26,
15191,
626,
3509,
314,
6555,
3050,
14,
8051,
370,
489,
7666,
314,
6203,
14,
272,
3839,
26,
710,
3839,
687,
3879,
314,
25444,
4744,
14,
819,
1803,
26,
272,
437,
2600,
4412,
6203,
370,
314,
4568,
7860,
1086,
14,
523,
408,
523,
2385,
275,
3839,
14,
7644,
342,
523,
1343,
63,
1080,
275,
2385,
14,
1080,
360,
532,
16427,
24981,
51,
275,
5918,
358,
523,
1284,
63,
1080,
275,
2385,
14,
1080,
360,
532,
7729,
24981,
51,
275,
5918,
358,
523,
7860,
1086,
275,
5055,
14,
21501,
0
] | [
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|
baslr/ArangoDB | 3rdParty/V8/V8-5.0.71.39/tools/find-commit-for-patch.py | 53 | 3327 | #!/usr/bin/env python
# Copyright 2014 the V8 project authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import argparse
import subprocess
import sys
def GetArgs():
parser = argparse.ArgumentParser(
description="Finds a commit that a given patch can be applied to. "
"Does not actually apply the patch or modify your checkout "
"in any way.")
parser.add_argument("patch_file", help="Patch file to match")
parser.add_argument(
"--branch", "-b", default="origin/master", type=str,
help="Git tree-ish where to start searching for commits, "
"default: %(default)s")
parser.add_argument(
"--limit", "-l", default=500, type=int,
help="Maximum number of commits to search, default: %(default)s")
parser.add_argument(
"--verbose", "-v", default=False, action="store_true",
help="Print verbose output for your entertainment")
return parser.parse_args()
def FindFilesInPatch(patch_file):
files = {}
next_file = ""
with open(patch_file) as patch:
for line in patch:
if line.startswith("diff --git "):
# diff --git a/src/objects.cc b/src/objects.cc
words = line.split()
assert words[2].startswith("a/") and len(words[2]) > 2
next_file = words[2][2:]
elif line.startswith("index "):
# index add3e61..d1bbf6a 100644
hashes = line.split()[1]
old_hash = hashes.split("..")[0]
if old_hash.startswith("0000000"): continue # Ignore new files.
files[next_file] = old_hash
return files
def GetGitCommitHash(treeish):
cmd = ["git", "log", "-1", "--format=%H", treeish]
return subprocess.check_output(cmd).strip()
def CountMatchingFiles(commit, files):
matched_files = 0
# Calling out to git once and parsing the result Python-side is faster
# than calling 'git ls-tree' for every file.
cmd = ["git", "ls-tree", "-r", commit] + [f for f in files]
output = subprocess.check_output(cmd)
for line in output.splitlines():
# 100644 blob c6d5daaa7d42e49a653f9861224aad0a0244b944 src/objects.cc
_, _, actual_hash, filename = line.split()
expected_hash = files[filename]
if actual_hash.startswith(expected_hash): matched_files += 1
return matched_files
def FindFirstMatchingCommit(start, files, limit, verbose):
commit = GetGitCommitHash(start)
num_files = len(files)
if verbose: print(">>> Found %d files modified by patch." % num_files)
for _ in range(limit):
matched_files = CountMatchingFiles(commit, files)
if verbose: print("Commit %s matched %d files" % (commit, matched_files))
if matched_files == num_files:
return commit
commit = GetGitCommitHash("%s^" % commit)
print("Sorry, no matching commit found. "
"Try running 'git fetch', specifying the correct --branch, "
"and/or setting a higher --limit.")
sys.exit(1)
if __name__ == "__main__":
args = GetArgs()
files = FindFilesInPatch(args.patch_file)
commit = FindFirstMatchingCommit(args.branch, files, args.limit, args.verbose)
if args.verbose:
print(">>> Matching commit: %s" % commit)
print(subprocess.check_output(["git", "log", "-1", commit]))
print(">>> Kthxbai.")
else:
print(commit)
| apache-2.0 | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6927,
314,
812,
24,
2199,
11462,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
7534,
199,
646,
3873,
199,
646,
984,
421,
199,
318,
2372,
6213,
837,
523,
1798,
275,
7534,
14,
10730,
8,
489,
1369,
628,
30344,
282,
5532,
626,
282,
1627,
3371,
883,
506,
6781,
370,
14,
298,
2116,
298,
6586,
440,
5965,
4838,
314,
3371,
503,
2811,
2195,
15243,
298,
2116,
298,
262,
1263,
4340,
2685,
523,
1798,
14,
525,
63,
2094,
480,
2068,
63,
493,
401,
1720,
628,
11173,
570,
370,
1336,
531,
523,
1798,
14,
525,
63,
2094,
8,
489,
4320,
4694,
401,
3905,
66,
401,
849,
628,
6493,
15,
4133,
401,
730,
29,
495,
12,
489,
1720,
628,
14686,
3123,
13,
2453,
2382,
370,
1343,
18112,
367,
20835,
12,
298,
1779,
298,
885,
26,
2818,
885,
9,
83,
531,
523,
1798,
14,
525,
63,
2094,
8,
489,
4320,
3097,
401,
3905,
76,
401,
849,
29,
5783,
12,
730,
29,
442,
12,
489,
1720,
628,
10915,
1329,
402,
20835,
370,
2754,
12,
849,
26,
2818,
885,
9,
83,
531,
523,
1798,
14,
525,
63,
2094,
8,
489,
4320,
3832,
401,
3905,
86,
401,
849,
29,
797,
12,
1595,
628,
1617,
63,
2052,
401,
489,
1720,
628,
5375,
3376,
1072,
367,
2195,
9509,
877,
434,
531,
523,
372,
1798,
14,
1122,
63,
589,
342,
421,
199,
318,
6668,
5535,
607,
11173,
8,
2068,
63,
493,
304,
523,
1584,
275,
1052,
523,
2163,
63,
493,
275,
3087,
523,
543,
1551,
8,
2068,
63,
493,
9,
465,
3371,
26,
272,
367,
1004,
315,
3371,
26,
489,
340,
1004,
14,
2460,
480,
3028,
1553,
3187,
26699,
267,
327,
3915,
1553,
3187,
282,
15,
2164,
15,
1462,
14,
2055,
330,
15,
2164,
15,
1462,
14,
2055,
267,
5932,
275,
1004,
14,
1294,
342,
267,
702,
5932,
59,
18,
1055,
2460,
480,
65,
13589,
436,
822,
8,
3148,
59,
18,
566,
690,
499,
267,
2163,
63,
493,
275,
5932,
59,
18,
1527,
18,
2938,
489,
916,
1004,
14,
2460,
480,
1080,
26699,
267,
327,
1478,
1050,
19,
69,
2976,
703,
68,
17,
31319,
22,
65,
2948,
10893,
267,
14647,
275,
1004,
14,
1294,
3430,
17,
61,
267,
2269,
63,
2227,
275,
14647,
14,
1294,
480,
703,
9981,
16,
61,
267,
340,
2269,
63,
2227,
14,
2460,
480,
9084,
2349,
1980,
221,
327,
14092,
892,
1584,
14,
267,
1584,
59,
2184,
63,
493,
61,
275,
2269,
63,
2227,
523,
372,
1584,
421,
199,
318,
2372,
14686,
11421,
3476,
8,
2350,
2453,
304,
523,
2088,
275,
2097,
3187,
401,
298,
793,
401,
3905,
17,
401,
4320,
908,
2458,
40,
401,
3123,
2453,
61,
523,
372,
3873,
14,
1074,
63,
1199,
8,
1760,
680,
1913,
342,
421,
199,
318,
14826,
14215,
5535,
8,
3543,
12,
1584,
304,
523,
7838,
63,
1725,
275,
378,
523,
327,
23892,
734,
370,
6135,
5403,
436,
6057,
314,
754,
2018,
13,
2441,
365,
12930,
523,
327,
2419,
6358,
283,
3187,
9100,
13,
2350,
7,
367,
4036,
570,
14,
523,
2088,
275,
2097,
3187,
401,
298,
478,
13,
2350,
401,
3905,
82,
401,
5532,
61,
435,
359,
70,
367,
289,
315,
1584,
61,
523,
1072,
275,
3873,
14,
1074,
63,
1199,
8,
1760,
9,
523,
367,
1004,
315,
1072,
14,
7644,
837,
272,
327,
2948,
10893,
9182,
286,
22,
68,
21,
983,
2158,
23,
68,
2260,
69,
1887,
65,
25401,
70,
30292,
713,
1194,
65,
350,
16,
65,
996,
1602,
66,
32393,
420,
2928,
15,
1462,
14,
2055,
272,
5501,
5501,
3503,
63,
2227,
12,
1788,
275,
1004,
14,
1294,
342,
272,
1420,
63,
2227,
275,
1584,
59,
1501,
61,
272,
340,
3503,
63,
2227,
14,
2460,
8,
2062,
63,
2227,
304,
7838,
63,
1725,
847,
413,
523,
372,
7838,
63,
1725,
421,
199,
318,
6668,
7147,
14215,
11421,
8,
928,
12,
1584,
12,
2304,
12,
3376,
304,
523,
5532,
275,
2372,
14686,
11421,
3476,
8,
928,
9,
523,
1967,
63,
1725,
275,
822,
8,
1725,
9,
523,
340,
3376,
26,
870,
480,
6071,
2643,
450,
68,
1584,
6042,
701,
3371,
2122,
450,
1967,
63,
1725,
9,
523,
367,
485,
315,
1425,
8,
3097,
304,
272,
7838,
63,
1725,
275,
14826,
14215,
5535,
8,
3543,
12,
1584,
9,
272,
340,
3376,
26,
870,
480,
11421,
450,
83,
7838,
450,
68,
1584,
2,
450,
334,
3543,
12,
7838,
63,
1725,
430,
272,
340,
7838,
63,
1725,
508,
1967,
63,
1725,
26,
489,
372,
5532,
272,
5532,
275,
2372,
14686,
11421,
3476,
3647,
83,
62,
2,
450,
5532,
9,
523,
870,
480,
27143,
12,
949,
4877,
5532,
1911,
14,
298,
267,
298,
12357,
3879,
283,
3187,
5267,
297,
9176,
314,
3211,
1553,
4694,
12,
298,
267,
298,
460,
15,
269,
4260,
282,
10948,
1553,
3097,
2685,
523,
984,
14,
2224,
8,
17,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
1249,
275,
2372,
6213,
342,
523,
1584,
275,
6668,
5535,
607,
11173,
8,
589,
14,
2068,
63,
493,
9,
523,
5532,
275,
6668,
7147,
14215,
11421,
8,
589,
14,
4694,
12,
1584,
12,
1249,
14,
3097,
12,
1249,
14,
3832,
9,
523,
340,
1249,
14,
3832,
26,
272,
870,
480,
6071,
9814,
316,
5532,
26,
450,
83,
2,
450,
5532,
9,
272,
870,
8,
5781,
14,
1074,
63,
1199,
5234,
3187,
401,
298,
793,
401,
3905,
17,
401,
5532,
2459,
272,
870,
480,
6071,
1804,
273,
1774,
5789,
2685,
523,
587,
26,
272,
870,
8,
3543,
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
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6927,
314,
812,
24,
2199,
11462,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
646,
7534,
199,
646,
3873,
199,
646,
984,
421,
199,
318,
2372,
6213,
837,
523,
1798,
275,
7534,
14,
10730,
8,
489,
1369,
628,
30344,
282,
5532,
626,
282,
1627,
3371,
883,
506,
6781,
370,
14,
298,
2116,
298,
6586,
440,
5965,
4838,
314,
3371,
503,
2811,
2195,
15243,
298,
2116,
298,
262,
1263,
4340,
2685,
523,
1798,
14,
525,
63,
2094,
480,
2068,
63,
493,
401,
1720,
628,
11173,
570,
370,
1336,
531,
523,
1798,
14,
525,
63,
2094,
8,
489,
4320,
4694,
401,
3905,
66,
401,
849,
628,
6493,
15,
4133,
401,
730,
29,
495,
12,
489,
1720,
628,
14686,
3123,
13,
2453,
2382,
370,
1343,
18112,
367,
20835,
12,
298,
1779,
298,
885,
26,
2818,
885,
9,
83,
531,
523,
1798,
14,
525,
63,
2094,
8,
489,
4320,
3097,
401,
3905,
76,
401,
849,
29,
5783,
12,
730,
29,
442,
12,
489,
1720,
628,
10915,
1329,
402,
20835,
370,
2754,
12,
849,
26,
2818,
885,
9,
83,
531,
523,
1798,
14,
525,
63,
2094,
8,
489,
4320,
3832,
401,
3905,
86,
401,
849,
29,
797,
12,
1595,
628,
1617,
63,
2052,
401,
489,
1720,
628,
5375,
3376,
1072,
367,
2195,
9509,
877,
434,
531,
523,
372,
1798,
14,
1122,
63,
589,
342,
421,
199,
318,
6668,
5535,
607,
11173,
8,
2068,
63,
493,
304,
523,
1584,
275,
1052,
523,
2163,
63,
493,
275,
3087,
523,
543,
1551,
8,
2068,
63,
493,
9,
465,
3371,
26,
272,
367,
1004,
315,
3371,
26,
489,
340,
1004,
14,
2460,
480,
3028,
1553,
3187,
26699,
267,
327,
3915,
1553,
3187,
282,
15,
2164,
15,
1462,
14,
2055,
330,
15,
2164,
15,
1462,
14,
2055,
267,
5932,
275,
1004,
14,
1294,
342,
267,
702,
5932,
59,
18,
1055,
2460,
480,
65,
13589,
436,
822,
8,
3148,
59,
18,
566,
690,
499,
267,
2163,
63,
493,
275,
5932,
59,
18,
1527,
18,
2938,
489,
916,
1004,
14,
2460,
480,
1080,
26699,
267,
327,
1478,
1050,
19,
69,
2976,
703,
68,
17,
31319,
22,
65,
2948,
10893,
267,
14647,
275,
1004,
14,
1294,
3430,
17,
61,
267,
2269,
63,
2227,
275,
14647,
14,
1294,
480,
703,
9981,
16,
61,
267,
340,
2269,
63,
2227,
14,
2460,
480,
9084,
2349,
1980,
221,
327,
14092,
892,
1584,
14,
267,
1584,
59,
2184,
63,
493,
61,
275,
2269,
63,
2227,
523,
372,
1584,
421,
199,
318,
2372,
14686,
11421,
3476,
8,
2350,
2453,
304,
523,
2088,
275,
2097,
3187,
401,
298,
793,
401,
3905,
17,
401,
4320,
908,
2458,
40,
401,
3123,
2453,
61,
523,
372,
3873,
14,
1074,
63,
1199,
8,
1760,
680,
1913,
342,
421,
199,
318,
14826,
14215,
5535,
8,
3543,
12,
1584,
304,
523,
7838,
63,
1725,
275,
378,
523,
327,
23892,
734,
370,
6135,
5403,
436,
6057,
314,
754,
2018,
13,
2441,
365,
12930,
523,
327,
2419,
6358,
283,
3187,
9100,
13,
2350,
7,
367,
4036,
570,
14,
523,
2088,
275,
2097,
3187,
401,
298,
478,
13,
2350,
401,
3905,
82,
401,
5532,
61,
435,
359,
70,
367,
289,
315,
1584,
61,
523,
1072,
275,
3873,
14,
1074,
63,
1199,
8,
1760,
9,
523,
367,
1004,
315,
1072,
14,
7644,
837,
272,
327,
2948,
10893,
9182,
286,
22,
68,
21,
983,
2158,
23,
68,
2260,
69,
1887,
65,
25401,
70,
30292,
713,
1194,
65,
350,
16,
65,
996,
1602,
66,
32393,
420,
2928,
15,
1462,
14,
2055,
272,
5501,
5501,
3503,
63,
2227,
12,
1788,
275,
1004,
14,
1294,
342,
272,
1420,
63,
2227,
275,
1584,
59,
1501,
61,
272,
340,
3503,
63,
2227,
14,
2460,
8,
2062,
63,
2227,
304,
7838,
63,
1725,
847,
413,
523,
372,
7838,
63,
1725,
421,
199,
318,
6668,
7147,
14215,
11421,
8,
928,
12,
1584,
12,
2304,
12,
3376,
304,
523,
5532,
275,
2372,
14686,
11421,
3476,
8,
928,
9,
523,
1967,
63,
1725,
275,
822,
8,
1725,
9,
523,
340,
3376,
26,
870,
480,
6071,
2643,
450,
68,
1584,
6042,
701,
3371,
2122,
450,
1967,
63,
1725,
9,
523,
367,
485,
315,
1425,
8,
3097,
304,
272,
7838,
63,
1725,
275,
14826,
14215,
5535,
8,
3543,
12,
1584,
9,
272,
340,
3376,
26,
870,
480,
11421,
450,
83,
7838,
450,
68,
1584,
2,
450,
334,
3543,
12,
7838,
63,
1725,
430,
272,
340,
7838,
63,
1725,
508,
1967,
63,
1725,
26,
489,
372,
5532,
272,
5532,
275,
2372,
14686,
11421,
3476,
3647,
83,
62,
2,
450,
5532,
9,
523,
870,
480,
27143,
12,
949,
4877,
5532,
1911,
14,
298,
267,
298,
12357,
3879,
283,
3187,
5267,
297,
9176,
314,
3211,
1553,
4694,
12,
298,
267,
298,
460,
15,
269,
4260,
282,
10948,
1553,
3097,
2685,
523,
984,
14,
2224,
8,
17,
9,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
1249,
275,
2372,
6213,
342,
523,
1584,
275,
6668,
5535,
607,
11173,
8,
589,
14,
2068,
63,
493,
9,
523,
5532,
275,
6668,
7147,
14215,
11421,
8,
589,
14,
4694,
12,
1584,
12,
1249,
14,
3097,
12,
1249,
14,
3832,
9,
523,
340,
1249,
14,
3832,
26,
272,
870,
480,
6071,
9814,
316,
5532,
26,
450,
83,
2,
450,
5532,
9,
272,
870,
8,
5781,
14,
1074,
63,
1199,
5234,
3187,
401,
298,
793,
401,
3905,
17,
401,
5532,
2459,
272,
870,
480,
6071,
1804,
273,
1774,
5789,
2685,
523,
587,
26,
272,
870,
8,
3543,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
nzavagli/UnrealPy | UnrealPyEmbed/Development/Python/2015.08.07-Python2710-x64-Source-vs2015/Python27/Source/Twisted-15.2.1/twisted/internet/test/test_threads.py | 39 | 7983 | # Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Tests for implementations of L{IReactorThreads}.
"""
from __future__ import division, absolute_import
__metaclass__ = type
from weakref import ref
import gc, threading
from twisted.python.threadable import isInIOThread
from twisted.internet.test.reactormixins import ReactorBuilder
from twisted.python.threadpool import ThreadPool
from twisted.internet.interfaces import IReactorThreads
class ThreadTestsBuilder(ReactorBuilder):
"""
Builder for defining tests relating to L{IReactorThreads}.
"""
requiredInterfaces = (IReactorThreads,)
def test_getThreadPool(self):
"""
C{reactor.getThreadPool()} returns an instance of L{ThreadPool} which
starts when C{reactor.run()} is called and stops before it returns.
"""
state = []
reactor = self.buildReactor()
pool = reactor.getThreadPool()
self.assertIsInstance(pool, ThreadPool)
self.assertFalse(
pool.started, "Pool should not start before reactor.run")
def f():
# Record the state for later assertions
state.append(pool.started)
state.append(pool.joined)
reactor.stop()
reactor.callWhenRunning(f)
self.runReactor(reactor, 2)
self.assertTrue(
state[0], "Pool should start after reactor.run")
self.assertFalse(
state[1], "Pool should not be joined before reactor.stop")
self.assertTrue(
pool.joined,
"Pool should be stopped after reactor.run returns")
def test_suggestThreadPoolSize(self):
"""
C{reactor.suggestThreadPoolSize()} sets the maximum size of the reactor
threadpool.
"""
reactor = self.buildReactor()
reactor.suggestThreadPoolSize(17)
pool = reactor.getThreadPool()
self.assertEqual(pool.max, 17)
def test_delayedCallFromThread(self):
"""
A function scheduled with L{IReactorThreads.callFromThread} invoked
from a delayed call is run immediately in the next reactor iteration.
When invoked from the reactor thread, previous implementations of
L{IReactorThreads.callFromThread} would skip the pipe/socket based wake
up step, assuming the reactor would wake up on its own. However, this
resulted in the reactor not noticing a insert into the thread queue at
the right time (in this case, after the thread queue has been processed
for that reactor iteration).
"""
reactor = self.buildReactor()
def threadCall():
reactor.stop()
# Set up the use of callFromThread being tested.
reactor.callLater(0, reactor.callFromThread, threadCall)
before = reactor.seconds()
self.runReactor(reactor, 60)
after = reactor.seconds()
# We specified a timeout of 60 seconds. The timeout code in runReactor
# probably won't actually work, though. If the reactor comes out of
# the event notification API just a little bit early, say after 59.9999
# seconds instead of after 60 seconds, then the queued thread call will
# get processed but the timeout delayed call runReactor sets up won't!
# Then the reactor will stop and runReactor will return without the
# timeout firing. As it turns out, select() and poll() are quite
# likely to return *slightly* earlier than we ask them to, so the
# timeout will rarely happen, even if callFromThread is broken. So,
# instead we'll measure the elapsed time and make sure it's something
# less than about half of the timeout we specified. This is heuristic.
# It assumes that select() won't ever return after 30 seconds when we
# asked it to timeout after 60 seconds. And of course like all
# time-based tests, it's slightly non-deterministic. If the OS doesn't
# schedule this process for 30 seconds, then the test might fail even
# if callFromThread is working.
self.assertTrue(after - before < 30)
def test_callFromThread(self):
"""
A function scheduled with L{IReactorThreads.callFromThread} invoked
from another thread is run in the reactor thread.
"""
reactor = self.buildReactor()
result = []
def threadCall():
result.append(threading.currentThread())
reactor.stop()
reactor.callLater(0, reactor.callInThread,
reactor.callFromThread, threadCall)
self.runReactor(reactor, 5)
self.assertEqual(result, [threading.currentThread()])
def test_stopThreadPool(self):
"""
When the reactor stops, L{ReactorBase._stopThreadPool} drops the
reactor's direct reference to its internal threadpool and removes
the associated startup and shutdown triggers.
This is the case of the thread pool being created before the reactor
is run.
"""
reactor = self.buildReactor()
threadpool = ref(reactor.getThreadPool())
reactor.callWhenRunning(reactor.stop)
self.runReactor(reactor)
gc.collect()
self.assertIs(threadpool(), None)
def test_stopThreadPoolWhenStartedAfterReactorRan(self):
"""
We must handle the case of shutting down the thread pool when it was
started after the reactor was run in a special way.
Some implementation background: The thread pool is started with
callWhenRunning, which only returns a system trigger ID when it is
invoked before the reactor is started.
This is the case of the thread pool being created after the reactor
is started.
"""
reactor = self.buildReactor()
threadPoolRefs = []
def acquireThreadPool():
threadPoolRefs.append(ref(reactor.getThreadPool()))
reactor.stop()
reactor.callWhenRunning(acquireThreadPool)
self.runReactor(reactor)
gc.collect()
self.assertIs(threadPoolRefs[0](), None)
def test_cleanUpThreadPoolEvenBeforeReactorIsRun(self):
"""
When the reactor has its shutdown event fired before it is run, the
thread pool is completely destroyed.
For what it's worth, the reason we support this behavior at all is
because Trial does this.
This is the case of the thread pool being created without the reactor
being started at al.
"""
reactor = self.buildReactor()
threadPoolRef = ref(reactor.getThreadPool())
reactor.fireSystemEvent("shutdown")
gc.collect()
self.assertIs(threadPoolRef(), None)
def test_isInIOThread(self):
"""
The reactor registers itself as the I/O thread when it runs so that
L{twisted.python.threadable.isInIOThread} returns C{True} if it is
called in the thread the reactor is running in.
"""
results = []
reactor = self.buildReactor()
def check():
results.append(isInIOThread())
reactor.stop()
reactor.callWhenRunning(check)
self.runReactor(reactor)
self.assertEqual([True], results)
def test_isNotInIOThread(self):
"""
The reactor registers itself as the I/O thread when it runs so that
L{twisted.python.threadable.isInIOThread} returns C{False} if it is
called in a different thread than the reactor is running in.
"""
results = []
reactor = self.buildReactor()
def check():
results.append(isInIOThread())
reactor.callFromThread(reactor.stop)
reactor.callInThread(check)
self.runReactor(reactor)
self.assertEqual([False], results)
globals().update(ThreadTestsBuilder.makeTestCaseClasses())
| mit | [
3,
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
12591,
402,
491,
91,
30861,
22785,
5565,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
199,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
13852,
492,
2984,
199,
646,
9486,
12,
5796,
199,
199,
504,
7390,
14,
1548,
14,
2671,
461,
492,
365,
607,
41,
1387,
72,
739,
199,
504,
7390,
14,
4901,
14,
396,
14,
13544,
30192,
492,
799,
5021,
6437,
199,
504,
7390,
14,
1548,
14,
2671,
2293,
492,
11086,
5453,
199,
504,
7390,
14,
4901,
14,
7436,
492,
473,
15860,
22785,
421,
199,
533,
11086,
2925,
6437,
8,
15860,
6437,
304,
272,
408,
272,
19286,
367,
12669,
2295,
4668,
1958,
370,
491,
91,
30861,
22785,
5565,
272,
408,
272,
1415,
18680,
275,
334,
30861,
22785,
4258,
339,
347,
511,
63,
362,
4436,
5453,
8,
277,
304,
267,
408,
267,
445,
91,
13544,
14,
362,
4436,
5453,
12737,
2529,
376,
1256,
402,
491,
91,
4436,
5453,
93,
1314,
267,
9174,
1380,
445,
91,
13544,
14,
1065,
12737,
365,
2797,
436,
20922,
2544,
652,
2529,
14,
267,
408,
267,
1174,
275,
942,
267,
9655,
275,
291,
14,
1506,
15860,
342,
398,
4203,
275,
9655,
14,
362,
4436,
5453,
342,
267,
291,
14,
6926,
8,
2293,
12,
11086,
5453,
9,
267,
291,
14,
3334,
8,
288,
4203,
14,
8924,
12,
298,
5453,
1077,
440,
1343,
2544,
9655,
14,
1065,
531,
398,
347,
289,
837,
288,
327,
12651,
314,
1174,
367,
2945,
22835,
288,
1174,
14,
740,
8,
2293,
14,
8924,
9,
288,
1174,
14,
740,
8,
2293,
14,
11806,
9,
288,
9655,
14,
2379,
342,
398,
9655,
14,
1250,
11423,
9602,
8,
70,
9,
267,
291,
14,
1065,
15860,
8,
13544,
12,
499,
9,
398,
291,
14,
1815,
8,
288,
1174,
59,
16,
467,
298,
5453,
1077,
1343,
2410,
9655,
14,
1065,
531,
267,
291,
14,
3334,
8,
288,
1174,
59,
17,
467,
298,
5453,
1077,
440,
506,
16538,
2544,
9655,
14,
2379,
531,
267,
291,
14,
1815,
8,
288,
4203,
14,
11806,
12,
288,
298,
5453,
1077,
506,
15248,
2410,
9655,
14,
1065,
2529,
531,
2378,
347,
511,
63,
19957,
4436,
5453,
2320,
8,
277,
304,
267,
408,
267,
445,
91,
13544,
14,
19957,
4436,
5453,
2320,
12737,
5951,
314,
5696,
1568,
402,
314,
9655,
267,
2462,
2293,
14,
267,
408,
267,
9655,
275,
291,
14,
1506,
15860,
342,
267,
9655,
14,
19957,
4436,
5453,
2320,
8,
1196,
9,
267,
4203,
275,
9655,
14,
362,
4436,
5453,
342,
267,
291,
14,
629,
8,
2293,
14,
988,
12,
5557,
9,
2378,
347,
511,
63,
21830,
2176,
2532,
4436,
8,
277,
304,
267,
408,
267,
437,
805,
18416,
543,
491,
91,
30861,
22785,
14,
1250,
2532,
4436,
93,
10302,
267,
687,
282,
24725,
1240,
365,
1255,
9939,
315,
314,
2163,
9655,
8494,
14,
398,
3979,
10302,
687,
314,
9655,
2462,
12,
4136,
12591,
402,
267,
491,
91,
30861,
22785,
14,
1250,
2532,
4436,
93,
3955,
3372,
314,
5200,
15,
3450,
4079,
21560,
267,
1536,
3650,
12,
18002,
314,
9655,
3955,
21560,
1536,
641,
2399,
5705,
14,
221,
9738,
12,
642,
267,
522,
30355,
315,
314,
9655,
440,
949,
764,
316,
282,
5518,
1901,
314,
2462,
4126,
737,
267,
314,
2451,
900,
334,
262,
642,
1930,
12,
2410,
314,
2462,
4126,
965,
2757,
7686,
267,
367,
626,
9655,
8494,
680,
267,
408,
267,
9655,
275,
291,
14,
1506,
15860,
342,
398,
347,
2462,
2176,
837,
288,
9655,
14,
2379,
342,
398,
327,
2494,
1536,
314,
675,
402,
1240,
2532,
4436,
3769,
12470,
14,
267,
9655,
14,
1250,
22028,
8,
16,
12,
9655,
14,
1250,
2532,
4436,
12,
2462,
2176,
9,
398,
2544,
275,
9655,
14,
4515,
342,
267,
291,
14,
1065,
15860,
8,
13544,
12,
5212,
9,
267,
2410,
275,
9655,
14,
4515,
342,
398,
327,
2136,
2013,
282,
2653,
402,
5212,
4696,
14,
221,
710,
2653,
1233,
315,
1255,
15860,
267,
327,
8646,
7859,
1133,
5965,
1736,
12,
10617,
14,
221,
982,
314,
9655,
12477,
734,
402,
267,
327,
314,
1566,
6955,
3261,
2951,
282,
12050,
4546,
14670,
12,
14722,
2410,
8155,
14,
5008,
267,
327,
4696,
3140,
402,
2410,
5212,
4696,
12,
2066,
314,
26102,
2462,
1240,
911,
267,
327,
664,
7686,
1325,
314,
2653,
24725,
1240,
1255,
15860,
5951,
1536,
7859,
1133,
1,
267,
327,
9442,
314,
9655,
911,
3631,
436,
1255,
15860,
911,
372,
1928,
314,
267,
327,
2653,
289,
16648,
14,
221,
3709,
652,
25449,
734,
12,
3504,
342,
436,
11271,
342,
787,
18794,
267,
327,
12060,
370,
372,
627,
83,
4040,
590,
10,
14119,
2419,
781,
7198,
3062,
370,
12,
880,
314,
267,
327,
2653,
911,
24063,
590,
5992,
12,
2755,
340,
1240,
2532,
4436,
365,
10529,
14,
221,
2002,
12,
267,
327,
3140,
781,
7171,
9775,
314,
14439,
900,
436,
1852,
3238,
652,
1159,
6020,
267,
327,
6656,
2419,
3595,
12995,
402,
314,
2653,
781,
2013,
14,
221,
961,
365,
25332,
14,
267,
327,
2779,
15194,
626,
3504,
342,
7859,
1133,
14433,
372,
2410,
4233,
4696,
1380,
781,
267,
327,
20864,
652,
370,
2653,
2410,
5212,
4696,
14,
221,
6061,
402,
2518,
2839,
1006,
267,
327,
900,
13,
6788,
2295,
12,
652,
1159,
18023,
2222,
13,
30709,
14,
221,
982,
314,
4403,
3181,
1133,
267,
327,
8732,
642,
2112,
367,
4233,
4696,
12,
2066,
314,
511,
5594,
2449,
2755,
267,
327,
340,
1240,
2532,
4436,
365,
6449,
14,
267,
291,
14,
1815,
8,
4399,
446,
2544,
665,
4233,
9,
2378,
347,
511,
63,
1250,
2532,
4436,
8,
277,
304,
267,
408,
267,
437,
805,
18416,
543,
491,
91,
30861,
22785,
14,
1250,
2532,
4436,
93,
10302,
267,
687,
4573,
2462,
365,
1255,
315,
314,
9655,
2462,
14,
267,
408,
267,
9655,
275,
291,
14,
1506,
15860,
342,
267,
754,
275,
942,
398,
347,
2462,
2176,
837,
288,
754,
14,
740,
8,
12562,
14,
1818,
4436,
1012,
288,
9655,
14,
2379,
342,
267,
9655,
14,
1250,
22028,
8,
16,
12,
9655,
14,
1250,
607,
4436,
12,
2079,
9655,
14,
1250,
2532,
4436,
12,
2462,
2176,
9,
267,
291,
14,
1065,
15860,
8,
13544,
12,
959,
9,
398,
291,
14,
629,
8
] | [
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
12591,
402,
491,
91,
30861,
22785,
5565,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
4629,
12,
3679,
63,
646,
199,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
13852,
492,
2984,
199,
646,
9486,
12,
5796,
199,
199,
504,
7390,
14,
1548,
14,
2671,
461,
492,
365,
607,
41,
1387,
72,
739,
199,
504,
7390,
14,
4901,
14,
396,
14,
13544,
30192,
492,
799,
5021,
6437,
199,
504,
7390,
14,
1548,
14,
2671,
2293,
492,
11086,
5453,
199,
504,
7390,
14,
4901,
14,
7436,
492,
473,
15860,
22785,
421,
199,
533,
11086,
2925,
6437,
8,
15860,
6437,
304,
272,
408,
272,
19286,
367,
12669,
2295,
4668,
1958,
370,
491,
91,
30861,
22785,
5565,
272,
408,
272,
1415,
18680,
275,
334,
30861,
22785,
4258,
339,
347,
511,
63,
362,
4436,
5453,
8,
277,
304,
267,
408,
267,
445,
91,
13544,
14,
362,
4436,
5453,
12737,
2529,
376,
1256,
402,
491,
91,
4436,
5453,
93,
1314,
267,
9174,
1380,
445,
91,
13544,
14,
1065,
12737,
365,
2797,
436,
20922,
2544,
652,
2529,
14,
267,
408,
267,
1174,
275,
942,
267,
9655,
275,
291,
14,
1506,
15860,
342,
398,
4203,
275,
9655,
14,
362,
4436,
5453,
342,
267,
291,
14,
6926,
8,
2293,
12,
11086,
5453,
9,
267,
291,
14,
3334,
8,
288,
4203,
14,
8924,
12,
298,
5453,
1077,
440,
1343,
2544,
9655,
14,
1065,
531,
398,
347,
289,
837,
288,
327,
12651,
314,
1174,
367,
2945,
22835,
288,
1174,
14,
740,
8,
2293,
14,
8924,
9,
288,
1174,
14,
740,
8,
2293,
14,
11806,
9,
288,
9655,
14,
2379,
342,
398,
9655,
14,
1250,
11423,
9602,
8,
70,
9,
267,
291,
14,
1065,
15860,
8,
13544,
12,
499,
9,
398,
291,
14,
1815,
8,
288,
1174,
59,
16,
467,
298,
5453,
1077,
1343,
2410,
9655,
14,
1065,
531,
267,
291,
14,
3334,
8,
288,
1174,
59,
17,
467,
298,
5453,
1077,
440,
506,
16538,
2544,
9655,
14,
2379,
531,
267,
291,
14,
1815,
8,
288,
4203,
14,
11806,
12,
288,
298,
5453,
1077,
506,
15248,
2410,
9655,
14,
1065,
2529,
531,
2378,
347,
511,
63,
19957,
4436,
5453,
2320,
8,
277,
304,
267,
408,
267,
445,
91,
13544,
14,
19957,
4436,
5453,
2320,
12737,
5951,
314,
5696,
1568,
402,
314,
9655,
267,
2462,
2293,
14,
267,
408,
267,
9655,
275,
291,
14,
1506,
15860,
342,
267,
9655,
14,
19957,
4436,
5453,
2320,
8,
1196,
9,
267,
4203,
275,
9655,
14,
362,
4436,
5453,
342,
267,
291,
14,
629,
8,
2293,
14,
988,
12,
5557,
9,
2378,
347,
511,
63,
21830,
2176,
2532,
4436,
8,
277,
304,
267,
408,
267,
437,
805,
18416,
543,
491,
91,
30861,
22785,
14,
1250,
2532,
4436,
93,
10302,
267,
687,
282,
24725,
1240,
365,
1255,
9939,
315,
314,
2163,
9655,
8494,
14,
398,
3979,
10302,
687,
314,
9655,
2462,
12,
4136,
12591,
402,
267,
491,
91,
30861,
22785,
14,
1250,
2532,
4436,
93,
3955,
3372,
314,
5200,
15,
3450,
4079,
21560,
267,
1536,
3650,
12,
18002,
314,
9655,
3955,
21560,
1536,
641,
2399,
5705,
14,
221,
9738,
12,
642,
267,
522,
30355,
315,
314,
9655,
440,
949,
764,
316,
282,
5518,
1901,
314,
2462,
4126,
737,
267,
314,
2451,
900,
334,
262,
642,
1930,
12,
2410,
314,
2462,
4126,
965,
2757,
7686,
267,
367,
626,
9655,
8494,
680,
267,
408,
267,
9655,
275,
291,
14,
1506,
15860,
342,
398,
347,
2462,
2176,
837,
288,
9655,
14,
2379,
342,
398,
327,
2494,
1536,
314,
675,
402,
1240,
2532,
4436,
3769,
12470,
14,
267,
9655,
14,
1250,
22028,
8,
16,
12,
9655,
14,
1250,
2532,
4436,
12,
2462,
2176,
9,
398,
2544,
275,
9655,
14,
4515,
342,
267,
291,
14,
1065,
15860,
8,
13544,
12,
5212,
9,
267,
2410,
275,
9655,
14,
4515,
342,
398,
327,
2136,
2013,
282,
2653,
402,
5212,
4696,
14,
221,
710,
2653,
1233,
315,
1255,
15860,
267,
327,
8646,
7859,
1133,
5965,
1736,
12,
10617,
14,
221,
982,
314,
9655,
12477,
734,
402,
267,
327,
314,
1566,
6955,
3261,
2951,
282,
12050,
4546,
14670,
12,
14722,
2410,
8155,
14,
5008,
267,
327,
4696,
3140,
402,
2410,
5212,
4696,
12,
2066,
314,
26102,
2462,
1240,
911,
267,
327,
664,
7686,
1325,
314,
2653,
24725,
1240,
1255,
15860,
5951,
1536,
7859,
1133,
1,
267,
327,
9442,
314,
9655,
911,
3631,
436,
1255,
15860,
911,
372,
1928,
314,
267,
327,
2653,
289,
16648,
14,
221,
3709,
652,
25449,
734,
12,
3504,
342,
436,
11271,
342,
787,
18794,
267,
327,
12060,
370,
372,
627,
83,
4040,
590,
10,
14119,
2419,
781,
7198,
3062,
370,
12,
880,
314,
267,
327,
2653,
911,
24063,
590,
5992,
12,
2755,
340,
1240,
2532,
4436,
365,
10529,
14,
221,
2002,
12,
267,
327,
3140,
781,
7171,
9775,
314,
14439,
900,
436,
1852,
3238,
652,
1159,
6020,
267,
327,
6656,
2419,
3595,
12995,
402,
314,
2653,
781,
2013,
14,
221,
961,
365,
25332,
14,
267,
327,
2779,
15194,
626,
3504,
342,
7859,
1133,
14433,
372,
2410,
4233,
4696,
1380,
781,
267,
327,
20864,
652,
370,
2653,
2410,
5212,
4696,
14,
221,
6061,
402,
2518,
2839,
1006,
267,
327,
900,
13,
6788,
2295,
12,
652,
1159,
18023,
2222,
13,
30709,
14,
221,
982,
314,
4403,
3181,
1133,
267,
327,
8732,
642,
2112,
367,
4233,
4696,
12,
2066,
314,
511,
5594,
2449,
2755,
267,
327,
340,
1240,
2532,
4436,
365,
6449,
14,
267,
291,
14,
1815,
8,
4399,
446,
2544,
665,
4233,
9,
2378,
347,
511,
63,
1250,
2532,
4436,
8,
277,
304,
267,
408,
267,
437,
805,
18416,
543,
491,
91,
30861,
22785,
14,
1250,
2532,
4436,
93,
10302,
267,
687,
4573,
2462,
365,
1255,
315,
314,
9655,
2462,
14,
267,
408,
267,
9655,
275,
291,
14,
1506,
15860,
342,
267,
754,
275,
942,
398,
347,
2462,
2176,
837,
288,
754,
14,
740,
8,
12562,
14,
1818,
4436,
1012,
288,
9655,
14,
2379,
342,
267,
9655,
14,
1250,
22028,
8,
16,
12,
9655,
14,
1250,
607,
4436,
12,
2079,
9655,
14,
1250,
2532,
4436,
12,
2462,
2176,
9,
267,
291,
14,
1065,
15860,
8,
13544,
12,
959,
9,
398,
291,
14,
629,
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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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
] |
CuonDeveloper/cuon | cuon_client/Client/CUON/cuon/Web2/SingleWeb2.py | 3 | 1723 | # -*- coding: utf-8 -*-
##Copyright (C) [2005] [Jürgen Hamel, D-32584 Löhne]
##This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as
##published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
##This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
##warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
##for more details.
##You should have received a copy of the GNU General Public License along with this program; if not, write to the
##Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
from cuon.Databases.SingleData import SingleData
import logging
import pygtk
pygtk.require('2.0')
import gtk
#import gtk.glade
import gobject
class SingleWeb2(SingleData):
def __init__(self, allTables):
SingleData.__init__(self)
# tables.dbd and address
self.sNameOfTable = "web2"
self.xmlTableDef = 0
# self.loadTable()
# self.saveTable()
self.loadTable(allTables)
self.setStore( gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_UINT) )
self.listHeader['names'] = ['title', 'designation', 'ID']
self.listHeader['size'] = [25,10,25,25,10]
print "number of Columns "
print len(self.table.Columns)
#
self.cType = 'html'
def readNonWidgetEntries(self, dicValues):
print 'readNonWidgetEntries(self) by SingleWeb2'
dicValues['ctype'] = [self.cType, 'string']
return dicValues | gpl-3.0 | [
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
309,
7384,
334,
35,
9,
359,
9397,
61,
221,
359,
42,
17709,
82,
2268,
869,
14868,
12,
577,
13,
708,
12248,
491,
14614,
72,
685,
61,
199,
199,
309,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
8987,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
309,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
199,
309,
3281,
1312,
369,
402,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
199,
309,
509,
1655,
2436,
14,
199,
199,
309,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
199,
309,
10146,
2290,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
9948,
199,
504,
286,
21615,
14,
7243,
83,
14,
7200,
1451,
492,
13050,
1451,
199,
646,
2050,
199,
646,
1134,
12275,
199,
647,
12275,
14,
4365,
360,
18,
14,
16,
358,
199,
646,
8116,
199,
3,
646,
8116,
14,
31589,
199,
646,
25595,
4388,
199,
533,
13050,
5926,
18,
8,
7200,
1451,
304,
25979,
347,
636,
826,
721,
277,
12,
1006,
18845,
304,
398,
13050,
1451,
855,
826,
721,
277,
9,
267,
327,
6716,
14,
697,
68,
436,
2287,
267,
291,
14,
83,
985,
3466,
3186,
275,
221,
298,
2520,
18,
2,
267,
291,
14,
1652,
3186,
6172,
275,
378,
267,
327,
291,
14,
912,
3186,
342,
267,
327,
291,
14,
2117,
3186,
342,
398,
291,
14,
912,
3186,
8,
452,
18845,
9,
267,
291,
14,
409,
5502,
8,
8116,
14,
1296,
5502,
8,
71,
785,
14,
2711,
63,
5353,
12,
25595,
14,
2711,
63,
5353,
12,
221,
25595,
14,
2711,
63,
17459,
9,
776,
267,
291,
14,
513,
2567,
459,
1247,
418,
275,
788,
1213,
297,
283,
14748,
425,
297,
283,
998,
418,
267,
291,
14,
513,
2567,
459,
890,
418,
275,
359,
821,
12,
709,
12,
821,
12,
821,
12,
709,
61,
267,
870,
298,
1955,
402,
3626,
2346,
298,
267,
870,
822,
8,
277,
14,
1224,
14,
15086,
9,
267,
327,
267,
291,
14,
67,
804,
275,
283,
1360,
7,
18407,
347,
1586,
6932,
3339,
17816,
8,
277,
12,
12219,
6550,
304,
267,
870,
283,
739,
6932,
3339,
17816,
8,
277,
9,
701,
13050,
5926,
18,
7,
267,
12219,
6550,
459,
3667,
418,
275,
359,
277,
14,
67,
804,
12,
283,
875,
418,
267,
372,
12219,
6550,
257,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
7384,
334,
35,
9,
359,
9397,
61,
221,
359,
42,
17709,
82,
2268,
869,
14868,
12,
577,
13,
708,
12248,
491,
14614,
72,
685,
61,
199,
199,
309,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
199,
309,
8987,
701,
314,
2868,
2290,
2752,
27,
1902,
1015,
650,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
309,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
199,
309,
3281,
1312,
369,
402,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
1666,
314,
1664,
1696,
1684,
844,
199,
309,
509,
1655,
2436,
14,
199,
199,
309,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
199,
309,
10146,
2290,
2752,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
15673,
13,
13421,
12,
8217,
14,
9948,
199,
504,
286,
21615,
14,
7243,
83,
14,
7200,
1451,
492,
13050,
1451,
199,
646,
2050,
199,
646,
1134,
12275,
199,
647,
12275,
14,
4365,
360,
18,
14,
16,
358,
199,
646,
8116,
199,
3,
646,
8116,
14,
31589,
199,
646,
25595,
4388,
199,
533,
13050,
5926,
18,
8,
7200,
1451,
304,
25979,
347,
636,
826,
721,
277,
12,
1006,
18845,
304,
398,
13050,
1451,
855,
826,
721,
277,
9,
267,
327,
6716,
14,
697,
68,
436,
2287,
267,
291,
14,
83,
985,
3466,
3186,
275,
221,
298,
2520,
18,
2,
267,
291,
14,
1652,
3186,
6172,
275,
378,
267,
327,
291,
14,
912,
3186,
342,
267,
327,
291,
14,
2117,
3186,
342,
398,
291,
14,
912,
3186,
8,
452,
18845,
9,
267,
291,
14,
409,
5502,
8,
8116,
14,
1296,
5502,
8,
71,
785,
14,
2711,
63,
5353,
12,
25595,
14,
2711,
63,
5353,
12,
221,
25595,
14,
2711,
63,
17459,
9,
776,
267,
291,
14,
513,
2567,
459,
1247,
418,
275,
788,
1213,
297,
283,
14748,
425,
297,
283,
998,
418,
267,
291,
14,
513,
2567,
459,
890,
418,
275,
359,
821,
12,
709,
12,
821,
12,
821,
12,
709,
61,
267,
870,
298,
1955,
402,
3626,
2346,
298,
267,
870,
822,
8,
277,
14,
1224,
14,
15086,
9,
267,
327,
267,
291,
14,
67,
804,
275,
283,
1360,
7,
18407,
347,
1586,
6932,
3339,
17816,
8,
277,
12,
12219,
6550,
304,
267,
870,
283,
739,
6932,
3339,
17816,
8,
277,
9,
701,
13050,
5926,
18,
7,
267,
12219,
6550,
459,
3667,
418,
275,
359,
277,
14,
67,
804,
12,
283,
875,
418,
267,
372,
12219,
6550,
257,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
daxxi13/CouchPotatoServer | libs/pyutil/benchmarks/bench_xor.py | 106 | 1658 | #!/usr/bin/env python
# Copyright (c) 2002-2010 Zooko Wilcox-O'Hearn
# This file is part of pyutil; see README.rst for licensing terms.
import hmac, sys, random
from pyutil.assertutil import _assert
from pyutil.xor import xor
from pyutil import benchfunc
from pyutil import randutil
SFUNCS = [hmac._strxor, xor.py_xor,]
SFNAMES = ["hmac", "pyutil py",]
inputs = {}
def _help_init_string(N):
global inputs
if not inputs.has_key(N):
inputs[N] = [randutil.insecurerandstr(N), randutil.insecurerandstr(N),]
def _help_make_bench_xor(f):
def g(n):
assert inputs.has_key(n)
_assert(isinstance(inputs[n][0], str), "Required to be a string.", inputs[n][0])
assert len(inputs[n][0]) == n
_assert(isinstance(inputs[n][1], str), "Required to be a string.", inputs[n][1])
assert len(inputs[n][1]) == n
for SF in SFUNCS:
assert f(inputs[n][0], inputs[n][1]) == SF(inputs[n][0], inputs[n][1])
return f(inputs[n][0], inputs[n][1])
return g
def bench(SETSIZES=[2**x for x in range(0, 22, 3)]):
random.seed(0)
if len(SFUNCS) <= 1: print ""
maxnamel = max(map(len, SFNAMES))
for SETSIZE in SETSIZES:
seed = random.random()
# print "seed: ", seed
random.seed(seed)
i = 0
if len(SFUNCS) > 1: print ""
for FUNC in SFUNCS:
funcname = SFNAMES[i] + " " * (maxnamel - len(SFNAMES[i]))
print "%s" % funcname,
sys.stdout.flush()
benchfunc.rep_bench(_help_make_bench_xor(FUNC), SETSIZE, initfunc=_help_init_string, MAXREPS=2**9, MAXTIME=30)
i = i + 1
bench()
| gpl-3.0 | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
221,
1898,
334,
67,
9,
14790,
13,
6542,
3107,
6992,
79,
644,
382,
331,
88,
13,
47,
7,
1966,
1060,
199,
3,
221,
961,
570,
365,
1777,
402,
1134,
1974,
27,
1937,
27781,
14,
8332,
367,
32572,
2895,
14,
199,
199,
646,
20330,
12,
984,
12,
2196,
199,
199,
504,
1134,
1974,
14,
479,
1974,
492,
485,
479,
199,
504,
1134,
1974,
14,
15721,
492,
31770,
199,
504,
1134,
1974,
492,
26456,
1532,
199,
504,
1134,
1974,
492,
10261,
1974,
199,
199,
51,
9309,
3298,
275,
359,
18537,
423,
495,
15721,
12,
31770,
14,
647,
63,
15721,
12,
61,
199,
199,
51,
4963,
31819,
275,
2097,
18537,
401,
298,
647,
1974,
1134,
401,
61,
199,
3711,
275,
1052,
199,
199,
318,
485,
3437,
63,
826,
63,
875,
8,
46,
304,
272,
2288,
4153,
272,
340,
440,
4153,
14,
1989,
63,
498,
8,
46,
304,
267,
4153,
59,
46,
61,
275,
359,
3759,
1974,
14,
24824,
3759,
495,
8,
46,
395,
10261,
1974,
14,
24824,
3759,
495,
8,
46,
395,
61,
199,
199,
318,
485,
3437,
63,
1875,
63,
16571,
63,
15721,
8,
70,
304,
272,
347,
486,
8,
78,
304,
267,
702,
4153,
14,
1989,
63,
498,
8,
78,
9,
267,
485,
479,
8,
6074,
8,
3711,
59,
78,
1527,
16,
467,
620,
395,
298,
8030,
370,
506,
282,
1059,
4765,
4153,
59,
78,
1527,
16,
566,
267,
702,
822,
8,
3711,
59,
78,
1527,
16,
566,
508,
302,
267,
485,
479,
8,
6074,
8,
3711,
59,
78,
1527,
17,
467,
620,
395,
298,
8030,
370,
506,
282,
1059,
4765,
4153,
59,
78,
1527,
17,
566,
267,
702,
822,
8,
3711,
59,
78,
1527,
17,
566,
508,
302,
267,
367,
29531,
315,
428,
9309,
3298,
26,
288,
702,
289,
8,
3711,
59,
78,
1527,
16,
467,
4153,
59,
78,
1527,
17,
566,
508,
29531,
8,
3711,
59,
78,
1527,
16,
467,
4153,
59,
78,
1527,
17,
566,
398,
372,
289,
8,
3711,
59,
78,
1527,
16,
467,
4153,
59,
78,
1527,
17,
566,
272,
372,
486,
199,
199,
318,
26456,
8,
3597,
2684,
58,
654,
1524,
18,
538,
88,
367,
671,
315,
1425,
8,
16,
12,
6928,
12,
650,
31540,
272,
2196,
14,
5176,
8,
16,
9,
272,
340,
822,
8,
51,
9309,
3298,
9,
2695,
413,
26,
870,
3087,
272,
1390,
354,
76,
275,
1390,
8,
1130,
8,
552,
12,
428,
4963,
31819,
430,
272,
367,
11543,
4305,
315,
11543,
2684,
58,
654,
26,
267,
6347,
275,
2196,
14,
2355,
342,
267,
327,
870,
298,
5176,
26,
3872,
6347,
267,
2196,
14,
5176,
8,
5176,
9,
267,
284,
275,
378,
267,
340,
822,
8,
51,
9309,
3298,
9,
690,
413,
26,
870,
3087,
267,
367,
481,
17192,
315,
428,
9309,
3298,
26,
288,
24092,
275,
428,
4963,
31819,
59,
73,
61,
435,
298,
298,
627,
334,
988,
354,
76,
446,
822,
8,
51,
4963,
31819,
59,
73,
2459,
288,
870,
2071,
83,
2,
450,
24092,
12,
288,
984,
14,
2703,
14,
4939,
342,
288,
26456,
1532,
14,
1155,
63,
16571,
1547,
3437,
63,
1875,
63,
16571,
63,
15721,
8,
19587,
395,
11543,
4305,
12,
4205,
1532,
3699,
3437,
63,
826,
63,
875,
12,
9141,
907,
5067,
29,
18,
538,
25,
12,
9141,
4961,
29,
1216,
9,
288,
284,
275,
284,
435,
413,
199,
199,
16571,
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
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
221,
1898,
334,
67,
9,
14790,
13,
6542,
3107,
6992,
79,
644,
382,
331,
88,
13,
47,
7,
1966,
1060,
199,
3,
221,
961,
570,
365,
1777,
402,
1134,
1974,
27,
1937,
27781,
14,
8332,
367,
32572,
2895,
14,
199,
199,
646,
20330,
12,
984,
12,
2196,
199,
199,
504,
1134,
1974,
14,
479,
1974,
492,
485,
479,
199,
504,
1134,
1974,
14,
15721,
492,
31770,
199,
504,
1134,
1974,
492,
26456,
1532,
199,
504,
1134,
1974,
492,
10261,
1974,
199,
199,
51,
9309,
3298,
275,
359,
18537,
423,
495,
15721,
12,
31770,
14,
647,
63,
15721,
12,
61,
199,
199,
51,
4963,
31819,
275,
2097,
18537,
401,
298,
647,
1974,
1134,
401,
61,
199,
3711,
275,
1052,
199,
199,
318,
485,
3437,
63,
826,
63,
875,
8,
46,
304,
272,
2288,
4153,
272,
340,
440,
4153,
14,
1989,
63,
498,
8,
46,
304,
267,
4153,
59,
46,
61,
275,
359,
3759,
1974,
14,
24824,
3759,
495,
8,
46,
395,
10261,
1974,
14,
24824,
3759,
495,
8,
46,
395,
61,
199,
199,
318,
485,
3437,
63,
1875,
63,
16571,
63,
15721,
8,
70,
304,
272,
347,
486,
8,
78,
304,
267,
702,
4153,
14,
1989,
63,
498,
8,
78,
9,
267,
485,
479,
8,
6074,
8,
3711,
59,
78,
1527,
16,
467,
620,
395,
298,
8030,
370,
506,
282,
1059,
4765,
4153,
59,
78,
1527,
16,
566,
267,
702,
822,
8,
3711,
59,
78,
1527,
16,
566,
508,
302,
267,
485,
479,
8,
6074,
8,
3711,
59,
78,
1527,
17,
467,
620,
395,
298,
8030,
370,
506,
282,
1059,
4765,
4153,
59,
78,
1527,
17,
566,
267,
702,
822,
8,
3711,
59,
78,
1527,
17,
566,
508,
302,
267,
367,
29531,
315,
428,
9309,
3298,
26,
288,
702,
289,
8,
3711,
59,
78,
1527,
16,
467,
4153,
59,
78,
1527,
17,
566,
508,
29531,
8,
3711,
59,
78,
1527,
16,
467,
4153,
59,
78,
1527,
17,
566,
398,
372,
289,
8,
3711,
59,
78,
1527,
16,
467,
4153,
59,
78,
1527,
17,
566,
272,
372,
486,
199,
199,
318,
26456,
8,
3597,
2684,
58,
654,
1524,
18,
538,
88,
367,
671,
315,
1425,
8,
16,
12,
6928,
12,
650,
31540,
272,
2196,
14,
5176,
8,
16,
9,
272,
340,
822,
8,
51,
9309,
3298,
9,
2695,
413,
26,
870,
3087,
272,
1390,
354,
76,
275,
1390,
8,
1130,
8,
552,
12,
428,
4963,
31819,
430,
272,
367,
11543,
4305,
315,
11543,
2684,
58,
654,
26,
267,
6347,
275,
2196,
14,
2355,
342,
267,
327,
870,
298,
5176,
26,
3872,
6347,
267,
2196,
14,
5176,
8,
5176,
9,
267,
284,
275,
378,
267,
340,
822,
8,
51,
9309,
3298,
9,
690,
413,
26,
870,
3087,
267,
367,
481,
17192,
315,
428,
9309,
3298,
26,
288,
24092,
275,
428,
4963,
31819,
59,
73,
61,
435,
298,
298,
627,
334,
988,
354,
76,
446,
822,
8,
51,
4963,
31819,
59,
73,
2459,
288,
870,
2071,
83,
2,
450,
24092,
12,
288,
984,
14,
2703,
14,
4939,
342,
288,
26456,
1532,
14,
1155,
63,
16571,
1547,
3437,
63,
1875,
63,
16571,
63,
15721,
8,
19587,
395,
11543,
4305,
12,
4205,
1532,
3699,
3437,
63,
826,
63,
875,
12,
9141,
907,
5067,
29,
18,
538,
25,
12,
9141,
4961,
29,
1216,
9,
288,
284,
275,
284,
435,
413,
199,
199,
16571,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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ific helpers for populating a DeviceTree.
#
# Copyright (C) 2009-2015 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU Lesser General Public License v.2, or (at your option) any later
# version. This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY expressed or implied, including the implied
# warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
# the GNU Lesser General Public License for more details. You should have
# received a copy of the GNU Lesser General Public License along with this
# program; if not, write to the Free Software Foundation, Inc., 51 Franklin
# Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat trademarks
# that are incorporated in the source code or documentation are not subject
# to the GNU Lesser General Public License and may only be used or
# replicated with the express permission of Red Hat, Inc.
#
# Red Hat Author(s): David Lehman <[email protected]>
#
from .populatorhelper import PopulatorHelper
from ... import udev
# pylint: disable=abstract-method
class DevicePopulator(PopulatorHelper):
""" Populator helper base class for devices.
Subclasses must define a match method and, if they want to instantiate
a device, a run method.
"""
@classmethod
def match(cls, data):
return False
def _handle_rename(self):
name = udev.device_get_name(self.data)
if self.device.name != name:
self.device.name = name
# TODO: update name registry -- better yet, generate the name list on demand
def _handle_resize(self):
old_size = self.device.current_size
self.device.update_size()
if old_size != self.device.current_size:
self._devicetree.cancel_disk_actions(self.device.disks)
def update(self):
self._handle_rename()
self._handle_resize()
| lgpl-2.1 | [
3,
4560,
6109,
15,
7546,
15,
1782,
1935,
6109,
14,
647,
199,
3,
3523,
1021,
367,
2243,
13,
466,
13,
6100,
10897,
367,
4560,
20529,
282,
12272,
3987,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
8937,
13,
7806,
221,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
1331,
31816,
471,
6285,
365,
6326,
2808,
370,
29165,
13809,
316,
370,
675,
12,
199,
3,
2811,
12,
1331,
12,
503,
3604,
652,
5420,
370,
314,
2895,
436,
3704,
402,
199,
3,
314,
1664,
6401,
1696,
1684,
844,
373,
14,
18,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
199,
3,
1015,
14,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
19147,
503,
2478,
12,
5893,
314,
2478,
199,
3,
3712,
1417,
402,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
199,
3,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
221,
2047,
1077,
1172,
199,
3,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
3180,
543,
642,
199,
3,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
199,
3,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
221,
6184,
9572,
13002,
21032,
10375,
199,
3,
626,
787,
30147,
972,
315,
314,
1350,
1233,
503,
3794,
787,
440,
5420,
199,
3,
370,
314,
1664,
6401,
1696,
1684,
844,
436,
1443,
1454,
506,
1202,
503,
199,
3,
32436,
543,
314,
4056,
4983,
402,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
9572,
13002,
6529,
8,
83,
304,
20232,
7005,
72,
1237,
665,
3011,
72,
1237,
32,
17164,
14,
957,
30,
199,
3,
199,
199,
504,
1275,
1935,
6109,
3676,
492,
13244,
6109,
4433,
199,
504,
2263,
492,
399,
2374,
421,
199,
3,
4287,
26,
3507,
29,
6198,
13,
765,
199,
533,
12272,
9606,
6109,
8,
9606,
6109,
4433,
304,
272,
408,
13244,
6109,
5922,
1300,
1021,
367,
7256,
14,
398,
20196,
1471,
5627,
282,
1336,
1083,
436,
12,
340,
2985,
2934,
370,
17321,
267,
282,
2243,
12,
282,
1255,
1083,
14,
272,
408,
272,
768,
3744,
272,
347,
1336,
8,
1886,
12,
666,
304,
267,
372,
756,
339,
347,
485,
2479,
63,
8165,
8,
277,
304,
267,
536,
275,
399,
2374,
14,
1782,
63,
362,
63,
354,
8,
277,
14,
576,
9,
267,
340,
291,
14,
1782,
14,
354,
1137,
536,
26,
288,
291,
14,
1782,
14,
354,
275,
536,
267,
327,
3254,
26,
1678,
536,
7086,
1553,
8034,
5966,
12,
3550,
314,
536,
769,
641,
29237,
339,
347,
485,
2479,
63,
8709,
8,
277,
304,
267,
2269,
63,
890,
275,
291,
14,
1782,
14,
1818,
63,
890,
267,
291,
14,
1782,
14,
873,
63,
890,
342,
267,
340,
2269,
63,
890,
1137,
291,
14,
1782,
14,
1818,
63,
890,
26,
288,
291,
423,
1782,
2350,
14,
6406,
63,
4032,
63,
3723,
8,
277,
14,
1782,
14,
16203,
9,
339,
347,
1678,
8,
277,
304,
267,
291,
423,
2479,
63,
8165,
342,
267,
291,
423,
2479,
63,
8709,
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
] | [
4560,
6109,
15,
7546,
15,
1782,
1935,
6109,
14,
647,
199,
3,
3523,
1021,
367,
2243,
13,
466,
13,
6100,
10897,
367,
4560,
20529,
282,
12272,
3987,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
8937,
13,
7806,
221,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
961,
1331,
31816,
471,
6285,
365,
6326,
2808,
370,
29165,
13809,
316,
370,
675,
12,
199,
3,
2811,
12,
1331,
12,
503,
3604,
652,
5420,
370,
314,
2895,
436,
3704,
402,
199,
3,
314,
1664,
6401,
1696,
1684,
844,
373,
14,
18,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
199,
3,
1015,
14,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
19147,
503,
2478,
12,
5893,
314,
2478,
199,
3,
3712,
1417,
402,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
199,
3,
314,
1664,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
221,
2047,
1077,
1172,
199,
3,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
844,
3180,
543,
642,
199,
3,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
11236,
199,
3,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
12,
8217,
14,
221,
6184,
9572,
13002,
21032,
10375,
199,
3,
626,
787,
30147,
972,
315,
314,
1350,
1233,
503,
3794,
787,
440,
5420,
199,
3,
370,
314,
1664,
6401,
1696,
1684,
844,
436,
1443,
1454,
506,
1202,
503,
199,
3,
32436,
543,
314,
4056,
4983,
402,
9572,
13002,
12,
3277,
14,
199,
3,
199,
3,
9572,
13002,
6529,
8,
83,
304,
20232,
7005,
72,
1237,
665,
3011,
72,
1237,
32,
17164,
14,
957,
30,
199,
3,
199,
199,
504,
1275,
1935,
6109,
3676,
492,
13244,
6109,
4433,
199,
504,
2263,
492,
399,
2374,
421,
199,
3,
4287,
26,
3507,
29,
6198,
13,
765,
199,
533,
12272,
9606,
6109,
8,
9606,
6109,
4433,
304,
272,
408,
13244,
6109,
5922,
1300,
1021,
367,
7256,
14,
398,
20196,
1471,
5627,
282,
1336,
1083,
436,
12,
340,
2985,
2934,
370,
17321,
267,
282,
2243,
12,
282,
1255,
1083,
14,
272,
408,
272,
768,
3744,
272,
347,
1336,
8,
1886,
12,
666,
304,
267,
372,
756,
339,
347,
485,
2479,
63,
8165,
8,
277,
304,
267,
536,
275,
399,
2374,
14,
1782,
63,
362,
63,
354,
8,
277,
14,
576,
9,
267,
340,
291,
14,
1782,
14,
354,
1137,
536,
26,
288,
291,
14,
1782,
14,
354,
275,
536,
267,
327,
3254,
26,
1678,
536,
7086,
1553,
8034,
5966,
12,
3550,
314,
536,
769,
641,
29237,
339,
347,
485,
2479,
63,
8709,
8,
277,
304,
267,
2269,
63,
890,
275,
291,
14,
1782,
14,
1818,
63,
890,
267,
291,
14,
1782,
14,
873,
63,
890,
342,
267,
340,
2269,
63,
890,
1137,
291,
14,
1782,
14,
1818,
63,
890,
26,
288,
291,
423,
1782,
2350,
14,
6406,
63,
4032,
63,
3723,
8,
277,
14,
1782,
14,
16203,
9,
339,
347,
1678,
8,
277,
304,
267,
291,
423,
2479,
63,
8165,
342,
267,
291,
423,
2479,
63,
8709,
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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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
] |
nzavagli/UnrealPy | UnrealPyEmbed/Development/Python/2015.08.07-Python2710-x64-Source-vs2015/Python27/Source/CherryPy-3.8.0/cherrypy/tutorial/tut03_get_and_post.py | 22 | 1719 | """
Tutorial - Passing variables
This tutorial shows you how to pass GET/POST variables to methods.
"""
import cherrypy
class WelcomePage:
def index(self):
# Ask for the user's name.
return '''
<form action="greetUser" method="GET">
What is your name?
<input type="text" name="name" />
<input type="submit" />
</form>'''
index.exposed = True
def greetUser(self, name=None):
# CherryPy passes all GET and POST variables as method parameters.
# It doesn't make a difference where the variables come from, how
# large their contents are, and so on.
#
# You can define default parameter values as usual. In this
# example, the "name" parameter defaults to None so we can check
# if a name was actually specified.
if name:
# Greet the user!
return "Hey %s, what's up?" % name
else:
if name is None:
# No name was specified
return 'Please enter your name <a href="./">here</a>.'
else:
return 'No, really, enter your name <a href="./">here</a>.'
greetUser.exposed = True
import os.path
tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')
if __name__ == '__main__':
# CherryPy always starts with app.root when trying to map request URIs
# to objects, so we need to mount a request handler root. A request
# to '/' will be mapped to HelloWorld().index().
cherrypy.quickstart(WelcomePage(), config=tutconf)
else:
# This branch is for the test suite; you can ignore it.
cherrypy.tree.mount(WelcomePage(), config=tutconf)
| mit | [
624,
199,
52,
15888,
446,
31755,
2860,
199,
199,
2765,
307,
15888,
13703,
1265,
4212,
370,
986,
9576,
15,
4030,
2860,
370,
3102,
14,
199,
624,
199,
199,
646,
13397,
421,
199,
533,
644,
14628,
3276,
26,
339,
347,
1478,
8,
277,
304,
267,
327,
30481,
367,
314,
922,
1159,
536,
14,
267,
372,
1449,
288,
665,
964,
1595,
628,
71,
7936,
1899,
2,
1083,
628,
2970,
1743,
288,
14791,
365,
2195,
536,
31,
288,
665,
1210,
730,
628,
505,
2,
536,
628,
354,
2,
7082,
288,
665,
1210,
730,
628,
7275,
2,
7082,
288,
3068,
964,
26934,
272,
1478,
14,
26717,
275,
715,
339,
347,
486,
7936,
1899,
8,
277,
12,
536,
29,
403,
304,
267,
327,
30992,
27794,
14933,
1006,
9576,
436,
8761,
2860,
465,
1083,
2633,
14,
267,
327,
2779,
3181,
1133,
1852,
282,
8865,
2382,
314,
2860,
11492,
687,
12,
4212,
267,
327,
7031,
3932,
4072,
787,
12,
436,
880,
641,
14,
267,
327,
267,
327,
2047,
883,
5627,
849,
2725,
1338,
465,
20195,
14,
1010,
642,
267,
327,
2893,
12,
314,
298,
354,
2,
2725,
4243,
370,
488,
880,
781,
883,
1104,
267,
327,
340,
282,
536,
1990,
5965,
2013,
14,
398,
340,
536,
26,
288,
327,
598,
7936,
314,
922,
1,
288,
372,
298,
1966,
89,
450,
83,
12,
4052,
1159,
1536,
13472,
450,
536,
267,
587,
26,
288,
340,
536,
365,
488,
26,
355,
327,
3091,
536,
1990,
2013,
355,
372,
283,
8254,
9509,
2195,
536,
665,
65,
4369,
628,
13186,
1743,
1681,
1108,
65,
30,
3530,
288,
587,
26,
355,
372,
283,
1944,
12,
7710,
12,
9509,
2195,
536,
665,
65,
4369,
628,
13186,
1743,
1681,
1108,
65,
30,
3530,
272,
486,
7936,
1899,
14,
26717,
275,
715,
421,
199,
646,
747,
14,
515,
199,
84,
337,
2190,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
23561,
14,
2190,
358,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
327,
30992,
27794,
3544,
9174,
543,
1145,
14,
1231,
1380,
9936,
370,
2341,
1056,
30143,
272,
327,
370,
2251,
12,
880,
781,
1929,
370,
10760,
282,
1056,
3016,
1738,
14,
437,
1056,
272,
327,
370,
7324,
911,
506,
9994,
370,
23833,
15943,
1252,
1080,
1252,
272,
13397,
14,
28957,
8,
24679,
3276,
1062,
1101,
29,
84,
337,
2190,
9,
199,
2836,
26,
272,
327,
961,
5246,
365,
367,
314,
511,
5241,
27,
1265,
883,
3686,
652,
14,
272,
13397,
14,
2350,
14,
3956,
8,
24679,
3276,
1062,
1101,
29,
84,
337,
2190,
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
] | [
199,
52,
15888,
446,
31755,
2860,
199,
199,
2765,
307,
15888,
13703,
1265,
4212,
370,
986,
9576,
15,
4030,
2860,
370,
3102,
14,
199,
624,
199,
199,
646,
13397,
421,
199,
533,
644,
14628,
3276,
26,
339,
347,
1478,
8,
277,
304,
267,
327,
30481,
367,
314,
922,
1159,
536,
14,
267,
372,
1449,
288,
665,
964,
1595,
628,
71,
7936,
1899,
2,
1083,
628,
2970,
1743,
288,
14791,
365,
2195,
536,
31,
288,
665,
1210,
730,
628,
505,
2,
536,
628,
354,
2,
7082,
288,
665,
1210,
730,
628,
7275,
2,
7082,
288,
3068,
964,
26934,
272,
1478,
14,
26717,
275,
715,
339,
347,
486,
7936,
1899,
8,
277,
12,
536,
29,
403,
304,
267,
327,
30992,
27794,
14933,
1006,
9576,
436,
8761,
2860,
465,
1083,
2633,
14,
267,
327,
2779,
3181,
1133,
1852,
282,
8865,
2382,
314,
2860,
11492,
687,
12,
4212,
267,
327,
7031,
3932,
4072,
787,
12,
436,
880,
641,
14,
267,
327,
267,
327,
2047,
883,
5627,
849,
2725,
1338,
465,
20195,
14,
1010,
642,
267,
327,
2893,
12,
314,
298,
354,
2,
2725,
4243,
370,
488,
880,
781,
883,
1104,
267,
327,
340,
282,
536,
1990,
5965,
2013,
14,
398,
340,
536,
26,
288,
327,
598,
7936,
314,
922,
1,
288,
372,
298,
1966,
89,
450,
83,
12,
4052,
1159,
1536,
13472,
450,
536,
267,
587,
26,
288,
340,
536,
365,
488,
26,
355,
327,
3091,
536,
1990,
2013,
355,
372,
283,
8254,
9509,
2195,
536,
665,
65,
4369,
628,
13186,
1743,
1681,
1108,
65,
30,
3530,
288,
587,
26,
355,
372,
283,
1944,
12,
7710,
12,
9509,
2195,
536,
665,
65,
4369,
628,
13186,
1743,
1681,
1108,
65,
30,
3530,
272,
486,
7936,
1899,
14,
26717,
275,
715,
421,
199,
646,
747,
14,
515,
199,
84,
337,
2190,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
23561,
14,
2190,
358,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
327,
30992,
27794,
3544,
9174,
543,
1145,
14,
1231,
1380,
9936,
370,
2341,
1056,
30143,
272,
327,
370,
2251,
12,
880,
781,
1929,
370,
10760,
282,
1056,
3016,
1738,
14,
437,
1056,
272,
327,
370,
7324,
911,
506,
9994,
370,
23833,
15943,
1252,
1080,
1252,
272,
13397,
14,
28957,
8,
24679,
3276,
1062,
1101,
29,
84,
337,
2190,
9,
199,
2836,
26,
272,
327,
961,
5246,
365,
367,
314,
511,
5241,
27,
1265,
883,
3686,
652,
14,
272,
13397,
14,
2350,
14,
3956,
8,
24679,
3276,
1062,
1101,
29,
84,
337,
2190,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pearsonlab/nipype | nipype/interfaces/fsl/tests/test_auto_SpatialFilter.py | 10 | 1610 | # AUTO-GENERATED by tools/checkspecs.py - DO NOT EDIT
from ....testing import assert_equal
from ..maths import SpatialFilter
def test_SpatialFilter_inputs():
input_map = dict(args=dict(argstr='%s',
),
environ=dict(nohash=True,
usedefault=True,
),
ignore_exception=dict(nohash=True,
usedefault=True,
),
in_file=dict(argstr='%s',
mandatory=True,
position=2,
),
internal_datatype=dict(argstr='-dt %s',
position=1,
),
kernel_file=dict(argstr='%s',
position=5,
xor=['kernel_size'],
),
kernel_shape=dict(argstr='-kernel %s',
position=4,
),
kernel_size=dict(argstr='%.4f',
position=5,
xor=['kernel_file'],
),
nan2zeros=dict(argstr='-nan',
position=3,
),
operation=dict(argstr='-f%s',
mandatory=True,
position=6,
),
out_file=dict(argstr='%s',
genfile=True,
hash_files=False,
position=-2,
),
output_datatype=dict(argstr='-odt %s',
position=-1,
),
output_type=dict(),
terminal_output=dict(nohash=True,
),
)
inputs = SpatialFilter.input_spec()
for key, metadata in list(input_map.items()):
for metakey, value in list(metadata.items()):
yield assert_equal, getattr(inputs.traits()[key], metakey), value
def test_SpatialFilter_outputs():
output_map = dict(out_file=dict(),
)
outputs = SpatialFilter.output_spec()
for key, metadata in list(output_map.items()):
for metakey, value in list(metadata.items()):
yield assert_equal, getattr(outputs.traits()[key], metakey), value
| bsd-3-clause | [
3,
25420,
13,
12795,
6989,
701,
7249,
15,
1074,
7273,
14,
647,
446,
3506,
2845,
24981,
199,
504,
29222,
4776,
492,
702,
63,
1452,
199,
504,
2508,
3442,
83,
492,
13423,
4131,
421,
199,
318,
511,
63,
18075,
4131,
63,
3711,
837,
272,
1324,
63,
1130,
275,
1211,
8,
589,
29,
807,
8,
21371,
9569,
83,
297,
272,
2318,
272,
6160,
29,
807,
8,
889,
2227,
29,
549,
12,
272,
675,
885,
29,
549,
12,
272,
2318,
272,
3686,
63,
1971,
29,
807,
8,
889,
2227,
29,
549,
12,
272,
675,
885,
29,
549,
12,
272,
2318,
272,
315,
63,
493,
29,
807,
8,
21371,
9569,
83,
297,
272,
15230,
29,
549,
12,
272,
3421,
29,
18,
12,
272,
2318,
272,
5007,
63,
14184,
29,
807,
8,
21371,
18274,
3583,
450,
83,
297,
272,
3421,
29,
17,
12,
272,
2318,
272,
5114,
63,
493,
29,
807,
8,
21371,
9569,
83,
297,
272,
3421,
29,
21,
12,
272,
31770,
2968,
4989,
63,
890,
995,
272,
2318,
272,
5114,
63,
1392,
29,
807,
8,
21371,
18274,
4989,
450,
83,
297,
272,
3421,
29,
20,
12,
272,
2318,
272,
5114,
63,
890,
29,
807,
8,
21371,
9569,
14,
20,
70,
297,
272,
3421,
29,
21,
12,
272,
31770,
2968,
4989,
63,
493,
995,
272,
2318,
272,
12055,
18,
4250,
29,
807,
8,
21371,
18274,
4304,
297,
272,
3421,
29,
19,
12,
272,
2318,
272,
3439,
29,
807,
8,
21371,
18274,
70,
5,
83,
297,
272,
15230,
29,
549,
12,
272,
3421,
29,
22,
12,
272,
2318,
272,
734,
63,
493,
29,
807,
8,
21371,
9569,
83,
297,
272,
3805,
493,
29,
549,
12,
272,
2631,
63,
1725,
29,
797,
12,
272,
3421,
4022,
18,
12,
272,
2318,
272,
1072,
63,
14184,
29,
807,
8,
21371,
18274,
364,
84,
450,
83,
297,
272,
3421,
4022,
17,
12,
272,
2318,
272,
1072,
63,
466,
29,
807,
1062,
272,
11167,
63,
1199,
29,
807,
8,
889,
2227,
29,
549,
12,
272,
2318,
272,
776,
272,
4153,
275,
13423,
4131,
14,
1210,
63,
1650,
342,
339,
367,
790,
12,
3341,
315,
769,
8,
1210,
63,
1130,
14,
1744,
5109,
267,
367,
3404,
498,
12,
574,
315,
769,
8,
2343,
14,
1744,
5109,
288,
1995,
702,
63,
1452,
12,
2519,
8,
3711,
14,
17668,
3430,
498,
467,
3404,
498,
395,
574,
421,
199,
318,
511,
63,
18075,
4131,
63,
4467,
837,
272,
1072,
63,
1130,
275,
1211,
8,
548,
63,
493,
29,
807,
1062,
272,
776,
272,
4704,
275,
13423,
4131,
14,
1199,
63,
1650,
342,
339,
367,
790,
12,
3341,
315,
769,
8,
1199,
63,
1130,
14,
1744,
5109,
267,
367,
3404,
498,
12,
574,
315,
769,
8,
2343,
14,
1744,
5109,
288,
1995,
702,
63,
1452,
12,
2519,
8,
4467,
14,
17668,
3430,
498,
467,
3404,
498,
395,
574,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
25420,
13,
12795,
6989,
701,
7249,
15,
1074,
7273,
14,
647,
446,
3506,
2845,
24981,
199,
504,
29222,
4776,
492,
702,
63,
1452,
199,
504,
2508,
3442,
83,
492,
13423,
4131,
421,
199,
318,
511,
63,
18075,
4131,
63,
3711,
837,
272,
1324,
63,
1130,
275,
1211,
8,
589,
29,
807,
8,
21371,
9569,
83,
297,
272,
2318,
272,
6160,
29,
807,
8,
889,
2227,
29,
549,
12,
272,
675,
885,
29,
549,
12,
272,
2318,
272,
3686,
63,
1971,
29,
807,
8,
889,
2227,
29,
549,
12,
272,
675,
885,
29,
549,
12,
272,
2318,
272,
315,
63,
493,
29,
807,
8,
21371,
9569,
83,
297,
272,
15230,
29,
549,
12,
272,
3421,
29,
18,
12,
272,
2318,
272,
5007,
63,
14184,
29,
807,
8,
21371,
18274,
3583,
450,
83,
297,
272,
3421,
29,
17,
12,
272,
2318,
272,
5114,
63,
493,
29,
807,
8,
21371,
9569,
83,
297,
272,
3421,
29,
21,
12,
272,
31770,
2968,
4989,
63,
890,
995,
272,
2318,
272,
5114,
63,
1392,
29,
807,
8,
21371,
18274,
4989,
450,
83,
297,
272,
3421,
29,
20,
12,
272,
2318,
272,
5114,
63,
890,
29,
807,
8,
21371,
9569,
14,
20,
70,
297,
272,
3421,
29,
21,
12,
272,
31770,
2968,
4989,
63,
493,
995,
272,
2318,
272,
12055,
18,
4250,
29,
807,
8,
21371,
18274,
4304,
297,
272,
3421,
29,
19,
12,
272,
2318,
272,
3439,
29,
807,
8,
21371,
18274,
70,
5,
83,
297,
272,
15230,
29,
549,
12,
272,
3421,
29,
22,
12,
272,
2318,
272,
734,
63,
493,
29,
807,
8,
21371,
9569,
83,
297,
272,
3805,
493,
29,
549,
12,
272,
2631,
63,
1725,
29,
797,
12,
272,
3421,
4022,
18,
12,
272,
2318,
272,
1072,
63,
14184,
29,
807,
8,
21371,
18274,
364,
84,
450,
83,
297,
272,
3421,
4022,
17,
12,
272,
2318,
272,
1072,
63,
466,
29,
807,
1062,
272,
11167,
63,
1199,
29,
807,
8,
889,
2227,
29,
549,
12,
272,
2318,
272,
776,
272,
4153,
275,
13423,
4131,
14,
1210,
63,
1650,
342,
339,
367,
790,
12,
3341,
315,
769,
8,
1210,
63,
1130,
14,
1744,
5109,
267,
367,
3404,
498,
12,
574,
315,
769,
8,
2343,
14,
1744,
5109,
288,
1995,
702,
63,
1452,
12,
2519,
8,
3711,
14,
17668,
3430,
498,
467,
3404,
498,
395,
574,
421,
199,
318,
511,
63,
18075,
4131,
63,
4467,
837,
272,
1072,
63,
1130,
275,
1211,
8,
548,
63,
493,
29,
807,
1062,
272,
776,
272,
4704,
275,
13423,
4131,
14,
1199,
63,
1650,
342,
339,
367,
790,
12,
3341,
315,
769,
8,
1199,
63,
1130,
14,
1744,
5109,
267,
367,
3404,
498,
12,
574,
315,
769,
8,
2343,
14,
1744,
5109,
288,
1995,
702,
63,
1452,
12,
2519,
8,
4467,
14,
17668,
3430,
498,
467,
3404,
498,
395,
574,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
oscaro/django | django/utils/feedgenerator.py | 78 | 16377 | """
Syndication feed generation library -- used for generating RSS, etc.
Sample usage:
>>> from django.utils import feedgenerator
>>> feed = feedgenerator.Rss201rev2Feed(
... title="Poynter E-Media Tidbits",
... link="http://www.poynter.org/column.asp?id=31",
... description="A group Weblog by the sharpest minds in online media/journalism/publishing.",
... language="en",
... )
>>> feed.add_item(
... title="Hello",
... link="http://www.holovaty.com/test/",
... description="Testing."
... )
>>> with open('test.rss', 'w') as fp:
... feed.write(fp, 'utf-8')
For definitions of the different versions of RSS, see:
http://web.archive.org/web/20110718035220/http://diveintomark.org/archives/2004/02/04/incompatible-rss
"""
from __future__ import unicode_literals
import datetime
from django.utils.xmlutils import SimplerXMLGenerator
from django.utils.encoding import force_text, iri_to_uri
from django.utils import datetime_safe
from django.utils import six
from django.utils.six import StringIO
from django.utils.six.moves.urllib.parse import urlparse
from django.utils.timezone import is_aware
def rfc2822_date(date):
# We can't use strftime() because it produces locale-dependent results, so
# we have to map english month and day names manually
months = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec',)
days = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
# Support datetime objects older than 1900
date = datetime_safe.new_datetime(date)
# We do this ourselves to be timezone aware, email.Utils is not tz aware.
dow = days[date.weekday()]
month = months[date.month - 1]
time_str = date.strftime('%s, %%d %s %%Y %%H:%%M:%%S ' % (dow, month))
if six.PY2: # strftime returns a byte string in Python 2
time_str = time_str.decode('utf-8')
if is_aware(date):
offset = date.tzinfo.utcoffset(date)
timezone = (offset.days * 24 * 60) + (offset.seconds // 60)
hour, minute = divmod(timezone, 60)
return time_str + '%+03d%02d' % (hour, minute)
else:
return time_str + '-0000'
def rfc3339_date(date):
# Support datetime objects older than 1900
date = datetime_safe.new_datetime(date)
time_str = date.strftime('%Y-%m-%dT%H:%M:%S')
if six.PY2: # strftime returns a byte string in Python 2
time_str = time_str.decode('utf-8')
if is_aware(date):
offset = date.tzinfo.utcoffset(date)
timezone = (offset.days * 24 * 60) + (offset.seconds // 60)
hour, minute = divmod(timezone, 60)
return time_str + '%+03d:%02d' % (hour, minute)
else:
return time_str + 'Z'
def get_tag_uri(url, date):
"""
Creates a TagURI.
See http://web.archive.org/web/20110514113830/http://diveintomark.org/archives/2004/05/28/howto-atom-id
"""
bits = urlparse(url)
d = ''
if date is not None:
d = ',%s' % datetime_safe.new_datetime(date).strftime('%Y-%m-%d')
return 'tag:%s%s:%s/%s' % (bits.hostname, d, bits.path, bits.fragment)
class SyndicationFeed(object):
"Base class for all syndication feeds. Subclasses should provide write()"
def __init__(self, title, link, description, language=None, author_email=None,
author_name=None, author_link=None, subtitle=None, categories=None,
feed_url=None, feed_copyright=None, feed_guid=None, ttl=None, **kwargs):
to_unicode = lambda s: force_text(s, strings_only=True)
if categories:
categories = [force_text(c) for c in categories]
if ttl is not None:
# Force ints to unicode
ttl = force_text(ttl)
self.feed = {
'title': to_unicode(title),
'link': iri_to_uri(link),
'description': to_unicode(description),
'language': to_unicode(language),
'author_email': to_unicode(author_email),
'author_name': to_unicode(author_name),
'author_link': iri_to_uri(author_link),
'subtitle': to_unicode(subtitle),
'categories': categories or (),
'feed_url': iri_to_uri(feed_url),
'feed_copyright': to_unicode(feed_copyright),
'id': feed_guid or link,
'ttl': ttl,
}
self.feed.update(kwargs)
self.items = []
def add_item(self, title, link, description, author_email=None,
author_name=None, author_link=None, pubdate=None, comments=None,
unique_id=None, unique_id_is_permalink=None, enclosure=None,
categories=(), item_copyright=None, ttl=None, updateddate=None, **kwargs):
"""
Adds an item to the feed. All args are expected to be Python Unicode
objects except pubdate and updateddate, which are datetime.datetime
objects, and enclosure, which is an instance of the Enclosure class.
"""
to_unicode = lambda s: force_text(s, strings_only=True)
if categories:
categories = [to_unicode(c) for c in categories]
if ttl is not None:
# Force ints to unicode
ttl = force_text(ttl)
item = {
'title': to_unicode(title),
'link': iri_to_uri(link),
'description': to_unicode(description),
'author_email': to_unicode(author_email),
'author_name': to_unicode(author_name),
'author_link': iri_to_uri(author_link),
'pubdate': pubdate,
'updateddate': updateddate,
'comments': to_unicode(comments),
'unique_id': to_unicode(unique_id),
'unique_id_is_permalink': unique_id_is_permalink,
'enclosure': enclosure,
'categories': categories or (),
'item_copyright': to_unicode(item_copyright),
'ttl': ttl,
}
item.update(kwargs)
self.items.append(item)
def num_items(self):
return len(self.items)
def root_attributes(self):
"""
Return extra attributes to place on the root (i.e. feed/channel) element.
Called from write().
"""
return {}
def add_root_elements(self, handler):
"""
Add elements in the root (i.e. feed/channel) element. Called
from write().
"""
pass
def item_attributes(self, item):
"""
Return extra attributes to place on each item (i.e. item/entry) element.
"""
return {}
def add_item_elements(self, handler, item):
"""
Add elements on each item (i.e. item/entry) element.
"""
pass
def write(self, outfile, encoding):
"""
Outputs the feed in the given encoding to outfile, which is a file-like
object. Subclasses should override this.
"""
raise NotImplementedError('subclasses of SyndicationFeed must provide a write() method')
def writeString(self, encoding):
"""
Returns the feed in the given encoding as a string.
"""
s = StringIO()
self.write(s, encoding)
return s.getvalue()
def latest_post_date(self):
"""
Returns the latest item's pubdate or updateddate. If no items
have either of these attributes this returns the current date/time.
"""
latest_date = None
date_keys = ('updateddate', 'pubdate')
for item in self.items:
for date_key in date_keys:
item_date = item.get(date_key)
if item_date:
if latest_date is None or item_date > latest_date:
latest_date = item_date
return latest_date or datetime.datetime.now()
class Enclosure(object):
"Represents an RSS enclosure"
def __init__(self, url, length, mime_type):
"All args are expected to be Python Unicode objects"
self.length, self.mime_type = length, mime_type
self.url = iri_to_uri(url)
class RssFeed(SyndicationFeed):
mime_type = 'application/rss+xml; charset=utf-8'
def write(self, outfile, encoding):
handler = SimplerXMLGenerator(outfile, encoding)
handler.startDocument()
handler.startElement("rss", self.rss_attributes())
handler.startElement("channel", self.root_attributes())
self.add_root_elements(handler)
self.write_items(handler)
self.endChannelElement(handler)
handler.endElement("rss")
def rss_attributes(self):
return {"version": self._version,
"xmlns:atom": "http://www.w3.org/2005/Atom"}
def write_items(self, handler):
for item in self.items:
handler.startElement('item', self.item_attributes(item))
self.add_item_elements(handler, item)
handler.endElement("item")
def add_root_elements(self, handler):
handler.addQuickElement("title", self.feed['title'])
handler.addQuickElement("link", self.feed['link'])
handler.addQuickElement("description", self.feed['description'])
if self.feed['feed_url'] is not None:
handler.addQuickElement("atom:link", None,
{"rel": "self", "href": self.feed['feed_url']})
if self.feed['language'] is not None:
handler.addQuickElement("language", self.feed['language'])
for cat in self.feed['categories']:
handler.addQuickElement("category", cat)
if self.feed['feed_copyright'] is not None:
handler.addQuickElement("copyright", self.feed['feed_copyright'])
handler.addQuickElement("lastBuildDate", rfc2822_date(self.latest_post_date()))
if self.feed['ttl'] is not None:
handler.addQuickElement("ttl", self.feed['ttl'])
def endChannelElement(self, handler):
handler.endElement("channel")
class RssUserland091Feed(RssFeed):
_version = "0.91"
def add_item_elements(self, handler, item):
handler.addQuickElement("title", item['title'])
handler.addQuickElement("link", item['link'])
if item['description'] is not None:
handler.addQuickElement("description", item['description'])
class Rss201rev2Feed(RssFeed):
# Spec: http://blogs.law.harvard.edu/tech/rss
_version = "2.0"
def add_item_elements(self, handler, item):
handler.addQuickElement("title", item['title'])
handler.addQuickElement("link", item['link'])
if item['description'] is not None:
handler.addQuickElement("description", item['description'])
# Author information.
if item["author_name"] and item["author_email"]:
handler.addQuickElement("author", "%s (%s)" %
(item['author_email'], item['author_name']))
elif item["author_email"]:
handler.addQuickElement("author", item["author_email"])
elif item["author_name"]:
handler.addQuickElement("dc:creator", item["author_name"], {"xmlns:dc": "http://purl.org/dc/elements/1.1/"})
if item['pubdate'] is not None:
handler.addQuickElement("pubDate", rfc2822_date(item['pubdate']))
if item['comments'] is not None:
handler.addQuickElement("comments", item['comments'])
if item['unique_id'] is not None:
guid_attrs = {}
if isinstance(item.get('unique_id_is_permalink'), bool):
guid_attrs['isPermaLink'] = str(
item['unique_id_is_permalink']).lower()
handler.addQuickElement("guid", item['unique_id'], guid_attrs)
if item['ttl'] is not None:
handler.addQuickElement("ttl", item['ttl'])
# Enclosure.
if item['enclosure'] is not None:
handler.addQuickElement("enclosure", '',
{"url": item['enclosure'].url, "length": item['enclosure'].length,
"type": item['enclosure'].mime_type})
# Categories.
for cat in item['categories']:
handler.addQuickElement("category", cat)
class Atom1Feed(SyndicationFeed):
# Spec: http://atompub.org/2005/07/11/draft-ietf-atompub-format-10.html
mime_type = 'application/atom+xml; charset=utf-8'
ns = "http://www.w3.org/2005/Atom"
def write(self, outfile, encoding):
handler = SimplerXMLGenerator(outfile, encoding)
handler.startDocument()
handler.startElement('feed', self.root_attributes())
self.add_root_elements(handler)
self.write_items(handler)
handler.endElement("feed")
def root_attributes(self):
if self.feed['language'] is not None:
return {"xmlns": self.ns, "xml:lang": self.feed['language']}
else:
return {"xmlns": self.ns}
def add_root_elements(self, handler):
handler.addQuickElement("title", self.feed['title'])
handler.addQuickElement("link", "", {"rel": "alternate", "href": self.feed['link']})
if self.feed['feed_url'] is not None:
handler.addQuickElement("link", "", {"rel": "self", "href": self.feed['feed_url']})
handler.addQuickElement("id", self.feed['id'])
handler.addQuickElement("updated", rfc3339_date(self.latest_post_date()))
if self.feed['author_name'] is not None:
handler.startElement("author", {})
handler.addQuickElement("name", self.feed['author_name'])
if self.feed['author_email'] is not None:
handler.addQuickElement("email", self.feed['author_email'])
if self.feed['author_link'] is not None:
handler.addQuickElement("uri", self.feed['author_link'])
handler.endElement("author")
if self.feed['subtitle'] is not None:
handler.addQuickElement("subtitle", self.feed['subtitle'])
for cat in self.feed['categories']:
handler.addQuickElement("category", "", {"term": cat})
if self.feed['feed_copyright'] is not None:
handler.addQuickElement("rights", self.feed['feed_copyright'])
def write_items(self, handler):
for item in self.items:
handler.startElement("entry", self.item_attributes(item))
self.add_item_elements(handler, item)
handler.endElement("entry")
def add_item_elements(self, handler, item):
handler.addQuickElement("title", item['title'])
handler.addQuickElement("link", "", {"href": item['link'], "rel": "alternate"})
if item['pubdate'] is not None:
handler.addQuickElement('published', rfc3339_date(item['pubdate']))
if item['updateddate'] is not None:
handler.addQuickElement('updated', rfc3339_date(item['updateddate']))
# Author information.
if item['author_name'] is not None:
handler.startElement("author", {})
handler.addQuickElement("name", item['author_name'])
if item['author_email'] is not None:
handler.addQuickElement("email", item['author_email'])
if item['author_link'] is not None:
handler.addQuickElement("uri", item['author_link'])
handler.endElement("author")
# Unique ID.
if item['unique_id'] is not None:
unique_id = item['unique_id']
else:
unique_id = get_tag_uri(item['link'], item['pubdate'])
handler.addQuickElement("id", unique_id)
# Summary.
if item['description'] is not None:
handler.addQuickElement("summary", item['description'], {"type": "html"})
# Enclosure.
if item['enclosure'] is not None:
handler.addQuickElement("link", '',
{"rel": "enclosure",
"href": item['enclosure'].url,
"length": item['enclosure'].length,
"type": item['enclosure'].mime_type})
# Categories.
for cat in item['categories']:
handler.addQuickElement("category", "", {"term": cat})
# Rights.
if item['item_copyright'] is not None:
handler.addQuickElement("rights", item['item_copyright'])
# This isolates the decision of what the system default is, so calling code can
# do "feedgenerator.DefaultFeed" instead of "feedgenerator.Rss201rev2Feed".
DefaultFeed = Rss201rev2Feed
| bsd-3-clause | [
624,
199,
17746,
21171,
4733,
10152,
3555,
1553,
1202,
367,
12999,
30331,
12,
5423,
14,
199,
199,
8176,
4503,
26,
199,
199,
6071,
687,
1639,
14,
1208,
492,
4733,
4679,
199,
6071,
4733,
275,
4733,
4679,
14,
50,
385,
1797,
4964,
18,
7658,
8,
199,
1396,
258,
2538,
628,
1575,
1236,
351,
662,
13,
11398,
377,
344,
5609,
401,
199,
1396,
258,
2142,
628,
1014,
921,
1544,
14,
555,
1236,
351,
14,
1308,
15,
2301,
14,
20222,
31,
344,
29,
2192,
401,
199,
1396,
258,
1369,
628,
33,
1572,
6001,
793,
701,
314,
1033,
285,
321,
270,
333,
18212,
315,
18470,
5898,
15,
7067,
19185,
15,
4763,
316,
4765,
199,
1396,
258,
2637,
628,
287,
401,
199,
1396,
776,
199,
6071,
4733,
14,
525,
63,
1053,
8,
199,
1396,
258,
2538,
628,
6257,
401,
199,
1396,
258,
2142,
628,
1014,
921,
1544,
14,
526,
320,
16305,
89,
14,
957,
15,
396,
10665,
199,
1396,
258,
1369,
628,
9029,
2122,
199,
1396,
776,
199,
6071,
543,
1551,
360,
396,
14,
13614,
297,
283,
87,
358,
465,
4090,
26,
199,
1396,
258,
4733,
14,
952,
8,
3997,
12,
283,
1624,
13,
24,
358,
199,
199,
1858,
10269,
402,
314,
3365,
5459,
402,
30331,
12,
1937,
26,
199,
1014,
921,
2520,
14,
6404,
14,
1308,
15,
2520,
15,
1797,
7555,
7663,
1276,
11174,
15,
1014,
921,
28021,
442,
676,
1096,
14,
1308,
15,
28067,
15,
15431,
15,
996,
15,
966,
15,
31787,
13,
13614,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
504,
1639,
14,
1208,
14,
1652,
1208,
492,
5870,
82,
4317,
7599,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
12,
24086,
63,
475,
63,
2302,
199,
504,
1639,
14,
1208,
492,
2197,
63,
3489,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
4174,
492,
5228,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
7097,
199,
504,
1639,
14,
1208,
14,
7145,
492,
365,
63,
14600,
421,
199,
318,
18158,
29736,
63,
602,
8,
602,
304,
272,
327,
2136,
883,
1133,
675,
14053,
342,
2952,
652,
16904,
5867,
13,
7106,
2058,
12,
880,
272,
327,
781,
1172,
370,
2341,
20171,
1891,
5794,
436,
5382,
1561,
10250,
272,
20096,
275,
661,
19825,
297,
283,
27717,
297,
283,
10570,
297,
283,
33,
2700,
297,
283,
15586,
297,
283,
42,
324,
297,
283,
42,
348,
297,
283,
21640,
297,
283,
23337,
297,
283,
17584,
297,
283,
1944,
86,
297,
283,
8584,
9538,
272,
7609,
275,
661,
6671,
297,
283,
52,
310,
297,
283,
55,
379,
297,
283,
2719,
85,
297,
283,
22533,
297,
283,
22332,
297,
283,
22546,
358,
272,
327,
12502,
2197,
2251,
12731,
2419,
5851,
383,
272,
1434,
275,
2197,
63,
3489,
14,
1222,
63,
2083,
8,
602,
9,
272,
327,
2136,
886,
642,
26495,
370,
506,
7137,
20381,
12,
3031,
14,
7535,
365,
440,
5823,
20381,
14,
272,
366,
583,
275,
7609,
59,
602,
14,
12451,
5106,
272,
5794,
275,
20096,
59,
602,
14,
4482,
446,
413,
61,
272,
900,
63,
495,
275,
1434,
14,
6205,
3508,
83,
12,
11539,
68,
450,
83,
11539,
57,
11539,
40,
2689,
5,
45,
2689,
5,
51,
283,
450,
334,
68,
583,
12,
5794,
430,
272,
340,
3816,
14,
4521,
18,
26,
3777,
327,
14053,
2529,
282,
3696,
1059,
315,
2018,
499,
267,
900,
63,
495,
275,
900,
63,
495,
14,
2708,
360,
1624,
13,
24,
358,
272,
340,
365,
63,
14600,
8,
602,
304,
267,
3268,
275,
1434,
14,
9374,
14,
24036,
8,
602,
9,
267,
7137,
275,
334,
2743,
14,
4899,
627,
5504,
627,
5212,
9,
435,
334,
2743,
14,
4515,
5001,
5212,
9,
267,
6925,
12,
12709,
275,
16438,
8,
7145,
12,
5212,
9,
267,
372,
900,
63,
495,
435,
1543,
11,
1644,
68,
5,
996,
68,
7,
450,
334,
5180,
12,
12709,
9,
272,
587,
26,
267,
372,
900,
63,
495,
435,
2475,
993,
7,
421,
199,
318,
18158,
29536,
63,
602,
8,
602,
304,
272,
327,
12502,
2197,
2251,
12731,
2419,
5851,
383,
272,
1434,
275,
2197,
63,
3489,
14,
1222,
63,
2083,
8,
602,
9,
272,
900,
63,
495,
275,
1434,
14,
6205,
3508,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
358,
272,
340,
3816,
14,
4521,
18,
26,
3777,
327,
14053,
2529,
282,
3696,
1059,
315,
2018,
499,
267,
900,
63,
495,
275,
900,
63,
495,
14,
2708,
360,
1624,
13,
24,
358,
272,
340,
365,
63,
14600,
8,
602,
304,
267,
3268,
275,
1434,
14,
9374,
14,
24036,
8,
602,
9,
267,
7137,
275,
334,
2743,
14,
4899,
627,
5504,
627,
5212,
9,
435,
334,
2743,
14,
4515,
5001,
5212,
9,
267,
6925,
12,
12709,
275,
16438,
8,
7145,
12,
5212,
9,
267,
372,
900,
63,
495,
435,
1543,
11,
1644,
68,
2689,
996,
68,
7,
450,
334,
5180,
12,
12709,
9,
272,
587,
26,
267,
372,
900,
63,
495,
435,
283,
58,
7,
421,
199,
318,
664,
63,
1450,
63,
2302,
8,
633,
12,
1434,
304,
272,
408,
272,
10560,
282,
8053,
7639,
14,
339,
1666,
1455,
921,
2520,
14,
6404,
14,
1308,
15,
2520,
15,
1797,
7320,
1079,
845,
1703,
1216,
15,
1014,
921,
28021,
442,
676,
1096,
14,
1308,
15,
28067,
15,
15431,
15,
1717,
15,
1651,
15,
21232,
13,
4188,
13,
344,
272,
408,
272,
5821,
275,
7097,
8,
633,
9,
272,
366,
275,
2125,
272,
340,
1434,
365,
440,
488,
26,
267,
366,
275,
1656,
5,
83,
7,
450,
2197,
63,
3489,
14,
1222,
63,
2083,
8,
602,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
358,
272,
372,
283,
1450,
2689,
83,
5,
83,
2689,
83,
3149,
83,
7,
450,
334,
5609,
14,
4269,
12,
366,
12,
5821,
14,
515,
12,
5821,
14,
7677,
9,
421,
199,
533,
29988,
21171,
7658,
8,
785,
304,
272,
298,
1563,
1021,
367,
1006,
9560,
21171,
22295,
14,
20196,
1077,
5647,
2218,
16493,
272,
347,
636,
826,
721,
277,
12,
2538,
12,
2142,
12,
1369,
12,
2637,
29,
403,
12,
4132,
63,
2123,
29,
403,
12,
288,
4132,
63,
354,
29,
403,
12,
4132,
63,
1073,
29,
403,
12,
18197,
29,
403,
12
] | [
199,
17746,
21171,
4733,
10152,
3555,
1553,
1202,
367,
12999,
30331,
12,
5423,
14,
199,
199,
8176,
4503,
26,
199,
199,
6071,
687,
1639,
14,
1208,
492,
4733,
4679,
199,
6071,
4733,
275,
4733,
4679,
14,
50,
385,
1797,
4964,
18,
7658,
8,
199,
1396,
258,
2538,
628,
1575,
1236,
351,
662,
13,
11398,
377,
344,
5609,
401,
199,
1396,
258,
2142,
628,
1014,
921,
1544,
14,
555,
1236,
351,
14,
1308,
15,
2301,
14,
20222,
31,
344,
29,
2192,
401,
199,
1396,
258,
1369,
628,
33,
1572,
6001,
793,
701,
314,
1033,
285,
321,
270,
333,
18212,
315,
18470,
5898,
15,
7067,
19185,
15,
4763,
316,
4765,
199,
1396,
258,
2637,
628,
287,
401,
199,
1396,
776,
199,
6071,
4733,
14,
525,
63,
1053,
8,
199,
1396,
258,
2538,
628,
6257,
401,
199,
1396,
258,
2142,
628,
1014,
921,
1544,
14,
526,
320,
16305,
89,
14,
957,
15,
396,
10665,
199,
1396,
258,
1369,
628,
9029,
2122,
199,
1396,
776,
199,
6071,
543,
1551,
360,
396,
14,
13614,
297,
283,
87,
358,
465,
4090,
26,
199,
1396,
258,
4733,
14,
952,
8,
3997,
12,
283,
1624,
13,
24,
358,
199,
199,
1858,
10269,
402,
314,
3365,
5459,
402,
30331,
12,
1937,
26,
199,
1014,
921,
2520,
14,
6404,
14,
1308,
15,
2520,
15,
1797,
7555,
7663,
1276,
11174,
15,
1014,
921,
28021,
442,
676,
1096,
14,
1308,
15,
28067,
15,
15431,
15,
996,
15,
966,
15,
31787,
13,
13614,
199,
624,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
2197,
199,
504,
1639,
14,
1208,
14,
1652,
1208,
492,
5870,
82,
4317,
7599,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
505,
12,
24086,
63,
475,
63,
2302,
199,
504,
1639,
14,
1208,
492,
2197,
63,
3489,
199,
504,
1639,
14,
1208,
492,
3816,
199,
504,
1639,
14,
1208,
14,
4174,
492,
5228,
199,
504,
1639,
14,
1208,
14,
4174,
14,
4912,
14,
4078,
14,
1122,
492,
7097,
199,
504,
1639,
14,
1208,
14,
7145,
492,
365,
63,
14600,
421,
199,
318,
18158,
29736,
63,
602,
8,
602,
304,
272,
327,
2136,
883,
1133,
675,
14053,
342,
2952,
652,
16904,
5867,
13,
7106,
2058,
12,
880,
272,
327,
781,
1172,
370,
2341,
20171,
1891,
5794,
436,
5382,
1561,
10250,
272,
20096,
275,
661,
19825,
297,
283,
27717,
297,
283,
10570,
297,
283,
33,
2700,
297,
283,
15586,
297,
283,
42,
324,
297,
283,
42,
348,
297,
283,
21640,
297,
283,
23337,
297,
283,
17584,
297,
283,
1944,
86,
297,
283,
8584,
9538,
272,
7609,
275,
661,
6671,
297,
283,
52,
310,
297,
283,
55,
379,
297,
283,
2719,
85,
297,
283,
22533,
297,
283,
22332,
297,
283,
22546,
358,
272,
327,
12502,
2197,
2251,
12731,
2419,
5851,
383,
272,
1434,
275,
2197,
63,
3489,
14,
1222,
63,
2083,
8,
602,
9,
272,
327,
2136,
886,
642,
26495,
370,
506,
7137,
20381,
12,
3031,
14,
7535,
365,
440,
5823,
20381,
14,
272,
366,
583,
275,
7609,
59,
602,
14,
12451,
5106,
272,
5794,
275,
20096,
59,
602,
14,
4482,
446,
413,
61,
272,
900,
63,
495,
275,
1434,
14,
6205,
3508,
83,
12,
11539,
68,
450,
83,
11539,
57,
11539,
40,
2689,
5,
45,
2689,
5,
51,
283,
450,
334,
68,
583,
12,
5794,
430,
272,
340,
3816,
14,
4521,
18,
26,
3777,
327,
14053,
2529,
282,
3696,
1059,
315,
2018,
499,
267,
900,
63,
495,
275,
900,
63,
495,
14,
2708,
360,
1624,
13,
24,
358,
272,
340,
365,
63,
14600,
8,
602,
304,
267,
3268,
275,
1434,
14,
9374,
14,
24036,
8,
602,
9,
267,
7137,
275,
334,
2743,
14,
4899,
627,
5504,
627,
5212,
9,
435,
334,
2743,
14,
4515,
5001,
5212,
9,
267,
6925,
12,
12709,
275,
16438,
8,
7145,
12,
5212,
9,
267,
372,
900,
63,
495,
435,
1543,
11,
1644,
68,
5,
996,
68,
7,
450,
334,
5180,
12,
12709,
9,
272,
587,
26,
267,
372,
900,
63,
495,
435,
2475,
993,
7,
421,
199,
318,
18158,
29536,
63,
602,
8,
602,
304,
272,
327,
12502,
2197,
2251,
12731,
2419,
5851,
383,
272,
1434,
275,
2197,
63,
3489,
14,
1222,
63,
2083,
8,
602,
9,
272,
900,
63,
495,
275,
1434,
14,
6205,
3508,
57,
3295,
77,
3295,
19772,
5,
40,
2689,
45,
2689,
51,
358,
272,
340,
3816,
14,
4521,
18,
26,
3777,
327,
14053,
2529,
282,
3696,
1059,
315,
2018,
499,
267,
900,
63,
495,
275,
900,
63,
495,
14,
2708,
360,
1624,
13,
24,
358,
272,
340,
365,
63,
14600,
8,
602,
304,
267,
3268,
275,
1434,
14,
9374,
14,
24036,
8,
602,
9,
267,
7137,
275,
334,
2743,
14,
4899,
627,
5504,
627,
5212,
9,
435,
334,
2743,
14,
4515,
5001,
5212,
9,
267,
6925,
12,
12709,
275,
16438,
8,
7145,
12,
5212,
9,
267,
372,
900,
63,
495,
435,
1543,
11,
1644,
68,
2689,
996,
68,
7,
450,
334,
5180,
12,
12709,
9,
272,
587,
26,
267,
372,
900,
63,
495,
435,
283,
58,
7,
421,
199,
318,
664,
63,
1450,
63,
2302,
8,
633,
12,
1434,
304,
272,
408,
272,
10560,
282,
8053,
7639,
14,
339,
1666,
1455,
921,
2520,
14,
6404,
14,
1308,
15,
2520,
15,
1797,
7320,
1079,
845,
1703,
1216,
15,
1014,
921,
28021,
442,
676,
1096,
14,
1308,
15,
28067,
15,
15431,
15,
1717,
15,
1651,
15,
21232,
13,
4188,
13,
344,
272,
408,
272,
5821,
275,
7097,
8,
633,
9,
272,
366,
275,
2125,
272,
340,
1434,
365,
440,
488,
26,
267,
366,
275,
1656,
5,
83,
7,
450,
2197,
63,
3489,
14,
1222,
63,
2083,
8,
602,
680,
6205,
3508,
57,
3295,
77,
3295,
68,
358,
272,
372,
283,
1450,
2689,
83,
5,
83,
2689,
83,
3149,
83,
7,
450,
334,
5609,
14,
4269,
12,
366,
12,
5821,
14,
515,
12,
5821,
14,
7677,
9,
421,
199,
533,
29988,
21171,
7658,
8,
785,
304,
272,
298,
1563,
1021,
367,
1006,
9560,
21171,
22295,
14,
20196,
1077,
5647,
2218,
16493,
272,
347,
636,
826,
721,
277,
12,
2538,
12,
2142,
12,
1369,
12,
2637,
29,
403,
12,
4132,
63,
2123,
29,
403,
12,
288,
4132,
63,
354,
29,
403,
12,
4132,
63,
1073,
29,
403,
12,
18197,
29,
403,
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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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
] |
Crypt0s/Ramen | fs_libs/ftputil/build/lib/ftputil/path.py | 2 | 7681 | # Copyright (C) 2003-2013, Stefan Schwarzer <[email protected]>
# See the file LICENSE for licensing terms.
"""
ftputil.path - simulate `os.path` for FTP servers
"""
from __future__ import absolute_import
from __future__ import unicode_literals
import posixpath
import stat
import ftputil.compat
import ftputil.error
import ftputil.tool
# The `_Path` class shouldn't be used directly by clients of the
# ftputil library.
__all__ = []
class _Path(object):
"""
Support class resembling `os.path`, accessible from the `FTPHost`
object, e. g. as `FTPHost().path.abspath(path)`.
Hint: substitute `os` with the `FTPHost` object.
"""
# `_Path` needs to provide all methods of `os.path`.
# pylint: disable=too-many-instance-attributes
def __init__(self, host):
self._host = host
# Delegate these to the `posixpath` module.
# pylint: disable=invalid-name
pp = posixpath
self.dirname = pp.dirname
self.basename = pp.basename
self.isabs = pp.isabs
self.commonprefix = pp.commonprefix
self.split = pp.split
self.splitdrive = pp.splitdrive
self.splitext = pp.splitext
self.normcase = pp.normcase
self.normpath = pp.normpath
def abspath(self, path):
"""Return an absolute path."""
original_path = path
path = ftputil.tool.as_unicode(path)
if not self.isabs(path):
path = self.join(self._host.getcwd(), path)
return ftputil.tool.same_string_type_as(original_path,
self.normpath(path))
def exists(self, path):
"""Return true if the path exists."""
try:
lstat_result = self._host.lstat(
path, _exception_for_missing_path=False)
return lstat_result is not None
except ftputil.error.RootDirError:
return True
def getmtime(self, path):
"""
Return the timestamp for the last modification for `path`
as a float.
This will raise `PermanentError` if the path doesn't exist,
but maybe other exceptions depending on the state of the
server (e. g. timeout).
"""
return self._host.stat(path).st_mtime
def getsize(self, path):
"""
Return the size of the `path` item as an integer.
This will raise `PermanentError` if the path doesn't exist,
but maybe raise other exceptions depending on the state of the
server (e. g. timeout).
"""
return self._host.stat(path).st_size
@staticmethod
def join(*paths):
"""
Join the path component from `paths` and return the joined
path.
All of these paths must be either unicode strings or byte
strings. If not, `join` raises a `TypeError`.
"""
# These checks are implicitly done by Python 3, but not by
# Python 2.
all_paths_are_unicode = all(
(isinstance(path, ftputil.compat.unicode_type)
for path in paths))
all_paths_are_bytes = all(
(isinstance(path, ftputil.compat.bytes_type)
for path in paths))
if all_paths_are_unicode or all_paths_are_bytes:
return posixpath.join(*paths)
else:
# Python 3 raises this exception for mixed strings
# in `os.path.join`, so also use this exception.
raise TypeError(
"can't mix unicode strings and bytes in path components")
# Check whether a path is a regular file/dir/link. For the first
# two cases follow links (like in `os.path`).
#
# Implementation note: The previous implementations simply called
# `stat` or `lstat` and returned `False` if they ended with
# raising a `PermanentError`. That exception usually used to
# signal a missing path. This approach has the problem, however,
# that exceptions caused by code earlier in `lstat` are obscured
# by the exception handling in `isfile`, `isdir` and `islink`.
def isfile(self, path):
"""
Return true if the `path` exists and corresponds to a regular
file (no link).
A non-existing path does _not_ cause a `PermanentError`.
"""
path = ftputil.tool.as_unicode(path)
# Workaround if we can't go up from the current directory
if path == self._host.getcwd():
return False
try:
stat_result = self._host.stat(
path, _exception_for_missing_path=False)
if stat_result is None:
return False
else:
return stat.S_ISREG(stat_result.st_mode)
except ftputil.error.RootDirError:
return False
def isdir(self, path):
"""
Return true if the `path` exists and corresponds to a
directory (no link).
A non-existing path does _not_ cause a `PermanentError`.
"""
path = ftputil.tool.as_unicode(path)
# Workaround if we can't go up from the current directory
if path == self._host.getcwd():
return True
try:
stat_result = self._host.stat(
path, _exception_for_missing_path=False)
if stat_result is None:
return False
else:
return stat.S_ISDIR(stat_result.st_mode)
except ftputil.error.RootDirError:
return True
def islink(self, path):
"""
Return true if the `path` exists and is a link.
A non-existing path does _not_ cause a `PermanentError`.
"""
path = ftputil.tool.as_unicode(path)
try:
lstat_result = self._host.lstat(
path, _exception_for_missing_path=False)
if lstat_result is None:
return False
else:
return stat.S_ISLNK(lstat_result.st_mode)
except ftputil.error.RootDirError:
return False
def walk(self, top, func, arg):
"""
Directory tree walk with callback function.
For each directory in the directory tree rooted at top
(including top itself, but excluding "." and ".."), call
func(arg, dirname, fnames). dirname is the name of the
directory, and fnames a list of the names of the files and
subdirectories in dirname (excluding "." and ".."). func may
modify the fnames list in-place (e.g. via del or slice
assignment), and walk will only recurse into the
subdirectories whose names remain in fnames; this can be used
to implement a filter, or to impose a specific order of
visiting. No semantics are defined for, or required of, arg,
beyond that arg is always passed to func. It can be used,
e.g., to pass a filename pattern, or a mutable object designed
to accumulate statistics. Passing None for arg is common.
"""
top = ftputil.tool.as_unicode(top)
# This code (and the above documentation) is taken from
# `posixpath.py`, with slight modifications.
try:
names = self._host.listdir(top)
except OSError:
return
func(arg, top, names)
for name in names:
name = self.join(top, name)
try:
stat_result = self._host.lstat(name)
except OSError:
continue
if stat.S_ISDIR(stat_result[stat.ST_MODE]):
self.walk(name, func, arg)
| gpl-3.0 | [
3,
1898,
334,
35,
9,
13004,
13,
6965,
12,
17854,
12269,
22985,
3281,
2282,
665,
385,
335,
3281,
2282,
32,
385,
335,
3281,
2282,
14,
846,
30,
199,
3,
1666,
314,
570,
5113,
367,
32572,
2895,
14,
199,
199,
624,
199,
8915,
1974,
14,
515,
446,
20577,
658,
736,
14,
515,
64,
367,
23125,
8037,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
15454,
199,
646,
5672,
199,
199,
646,
14904,
1974,
14,
5819,
199,
646,
14904,
1974,
14,
705,
199,
646,
14904,
1974,
14,
3557,
421,
199,
3,
710,
18494,
2042,
64,
1021,
9296,
1133,
506,
1202,
5370,
701,
13431,
402,
314,
199,
3,
14904,
1974,
3555,
14,
199,
363,
452,
363,
275,
942,
421,
199,
533,
485,
2042,
8,
785,
304,
272,
408,
272,
12502,
1021,
295,
8946,
2983,
658,
736,
14,
515,
3559,
17909,
687,
314,
658,
15123,
4965,
64,
272,
909,
12,
325,
14,
486,
14,
465,
658,
15123,
4965,
1252,
515,
14,
4832,
8,
515,
20414,
339,
869,
442,
26,
23080,
658,
736,
64,
543,
314,
658,
15123,
4965,
64,
909,
14,
272,
408,
339,
327,
18494,
2042,
64,
4839,
370,
5647,
1006,
3102,
402,
658,
736,
14,
515,
2313,
272,
327,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
842,
13,
2987,
339,
347,
636,
826,
721,
277,
12,
1591,
304,
267,
291,
423,
1102,
275,
1591,
267,
327,
12035,
3237,
3520,
370,
314,
658,
23342,
64,
859,
14,
267,
327,
4287,
26,
3507,
29,
3197,
13,
354,
267,
11618,
275,
15454,
267,
291,
14,
3475,
420,
275,
11618,
14,
3475,
267,
291,
14,
4846,
258,
275,
11618,
14,
4846,
267,
291,
14,
17896,
263,
275,
11618,
14,
17896,
267,
291,
14,
2330,
1861,
275,
11618,
14,
2330,
1861,
267,
291,
14,
1294,
263,
275,
11618,
14,
1294,
267,
291,
14,
1294,
9541,
257,
275,
11618,
14,
1294,
9541,
267,
291,
14,
7973,
258,
275,
11618,
14,
7973,
267,
291,
14,
21288,
258,
275,
11618,
14,
21288,
267,
291,
14,
9267,
258,
275,
11618,
14,
9267,
339,
347,
19529,
8,
277,
12,
931,
304,
267,
408,
1767,
376,
3679,
931,
1041,
267,
3379,
63,
515,
275,
931,
267,
931,
275,
14904,
1974,
14,
3557,
14,
305,
63,
2975,
8,
515,
9,
267,
340,
440,
291,
14,
17896,
8,
515,
304,
288,
931,
275,
291,
14,
904,
8,
277,
423,
1102,
14,
9458,
1062,
931,
9,
267,
372,
14904,
1974,
14,
3557,
14,
7191,
63,
875,
63,
466,
63,
305,
8,
5043,
63,
515,
12,
6059,
291,
14,
9267,
8,
515,
430,
339,
347,
3495,
8,
277,
12,
931,
304,
267,
408,
1767,
2549,
340,
314,
931,
3495,
1041,
267,
862,
26,
288,
634,
3736,
63,
1099,
275,
291,
423,
1102,
14,
26956,
8,
2490,
931,
12,
485,
1971,
63,
509,
63,
4752,
63,
515,
29,
797,
9,
288,
372,
634,
3736,
63,
1099,
365,
440,
488,
267,
871,
14904,
1974,
14,
705,
14,
6405,
3567,
547,
26,
288,
372,
715,
339,
347,
664,
8180,
8,
277,
12,
931,
304,
267,
408,
267,
1432,
314,
4913,
367,
314,
2061,
7100,
367,
658,
515,
64,
267,
465,
282,
2069,
14,
398,
961,
911,
746,
658,
31776,
547,
64,
340,
314,
931,
3181,
1133,
2187,
12,
267,
1325,
11703,
1163,
4967,
10298,
641,
314,
1174,
402,
314,
267,
1654,
334,
69,
14,
486,
14,
2653,
680,
267,
408,
267,
372,
291,
423,
1102,
14,
3736,
8,
515,
680,
270,
63,
8180,
339,
347,
664,
890,
8,
277,
12,
931,
304,
267,
408,
267,
1432,
314,
1568,
402,
314,
658,
515,
64,
1242,
465,
376,
3000,
14,
398,
961,
911,
746,
658,
31776,
547,
64,
340,
314,
931,
3181,
1133,
2187,
12,
267,
1325,
11703,
746,
1163,
4967,
10298,
641,
314,
1174,
402,
314,
267,
1654,
334,
69,
14,
486,
14,
2653,
680,
267,
408,
267,
372,
291,
423,
1102,
14,
3736,
8,
515,
680,
270,
63,
890,
339,
768,
4639,
272,
347,
4263,
2031,
3771,
304,
267,
408,
267,
25733,
314,
931,
3931,
687,
658,
3771,
64,
436,
372,
314,
16538,
267,
931,
14,
398,
2900,
402,
3520,
3792,
1471,
506,
1902,
2649,
3326,
503,
3696,
267,
3326,
14,
982,
440,
12,
658,
904,
64,
6534,
282,
658,
4333,
2313,
267,
408,
267,
327,
5723,
5920,
787,
19796,
4224,
701,
2018,
650,
12,
1325,
440,
701,
267,
327,
2018,
499,
14,
267,
1006,
63,
3771,
63,
1530,
63,
2975,
275,
1006,
8,
881,
334,
6074,
8,
515,
12,
14904,
1974,
14,
5819,
14,
2975,
63,
466,
9,
881,
367,
931,
315,
3792,
430,
267,
1006,
63,
3771,
63,
1530,
63,
2394,
275,
1006,
8,
881,
334,
6074,
8,
515,
12,
14904,
1974,
14,
5819,
14,
2394,
63,
466,
9,
881,
367,
931,
315,
3792,
430,
267,
340,
1006,
63,
3771,
63,
1530,
63,
2975,
503,
1006,
63,
3771,
63,
1530,
63,
2394,
26,
288,
372,
15454,
14,
904,
2031,
3771,
9,
267,
587,
26,
288,
327,
2018,
650,
6534,
642,
1919,
367,
13492,
3326,
288,
327,
315,
658,
736,
14,
515,
14,
904,
3559,
880,
2597,
675,
642,
1919,
14,
288,
746,
3146,
8,
490,
298,
2425,
1133,
13667,
2649,
3326,
436,
2783,
315,
931,
7323,
531,
339,
327,
2670,
3775,
282,
931,
365,
282,
5578,
570,
15,
694,
15,
1073,
14,
2104,
314,
1642,
272,
327,
2877,
5560,
2035,
6220,
334,
2930,
315,
658,
736,
14,
515,
14963,
272,
327,
272,
327,
24425,
5317,
26,
710,
4136,
12591,
9329,
2797,
272,
327,
658,
3736,
64,
503,
658,
26956,
64,
436,
2138,
658,
797,
64,
340,
2985,
22480,
543,
272,
327,
17026,
282,
658,
31776,
547,
2313,
10314,
1919,
9987,
1202,
370,
272,
327,
4673,
282,
4124,
931,
14,
961,
18140,
965,
314,
5160,
12,
13432,
12,
272,
327,
626,
4967,
18104,
701,
1233,
14119,
315,
658,
26956,
64,
787,
2607,
551,
3297,
272,
327,
701,
314,
1919,
7252,
315,
658,
6292,
3559,
658,
6027,
64,
436,
658,
20719,
2313,
339,
347,
29214,
8,
277,
12,
931,
304,
267,
408,
267,
1432,
2549,
340,
314,
658,
515,
64,
3495,
436,
13718,
370,
282,
5578,
267,
570,
334,
889,
2142,
680,
398,
437,
2222,
13,
5952
] | [
1898,
334,
35,
9,
13004,
13,
6965,
12,
17854,
12269,
22985,
3281,
2282,
665,
385,
335,
3281,
2282,
32,
385,
335,
3281,
2282,
14,
846,
30,
199,
3,
1666,
314,
570,
5113,
367,
32572,
2895,
14,
199,
199,
624,
199,
8915,
1974,
14,
515,
446,
20577,
658,
736,
14,
515,
64,
367,
23125,
8037,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
15454,
199,
646,
5672,
199,
199,
646,
14904,
1974,
14,
5819,
199,
646,
14904,
1974,
14,
705,
199,
646,
14904,
1974,
14,
3557,
421,
199,
3,
710,
18494,
2042,
64,
1021,
9296,
1133,
506,
1202,
5370,
701,
13431,
402,
314,
199,
3,
14904,
1974,
3555,
14,
199,
363,
452,
363,
275,
942,
421,
199,
533,
485,
2042,
8,
785,
304,
272,
408,
272,
12502,
1021,
295,
8946,
2983,
658,
736,
14,
515,
3559,
17909,
687,
314,
658,
15123,
4965,
64,
272,
909,
12,
325,
14,
486,
14,
465,
658,
15123,
4965,
1252,
515,
14,
4832,
8,
515,
20414,
339,
869,
442,
26,
23080,
658,
736,
64,
543,
314,
658,
15123,
4965,
64,
909,
14,
272,
408,
339,
327,
18494,
2042,
64,
4839,
370,
5647,
1006,
3102,
402,
658,
736,
14,
515,
2313,
272,
327,
4287,
26,
3507,
29,
7354,
13,
3479,
13,
842,
13,
2987,
339,
347,
636,
826,
721,
277,
12,
1591,
304,
267,
291,
423,
1102,
275,
1591,
267,
327,
12035,
3237,
3520,
370,
314,
658,
23342,
64,
859,
14,
267,
327,
4287,
26,
3507,
29,
3197,
13,
354,
267,
11618,
275,
15454,
267,
291,
14,
3475,
420,
275,
11618,
14,
3475,
267,
291,
14,
4846,
258,
275,
11618,
14,
4846,
267,
291,
14,
17896,
263,
275,
11618,
14,
17896,
267,
291,
14,
2330,
1861,
275,
11618,
14,
2330,
1861,
267,
291,
14,
1294,
263,
275,
11618,
14,
1294,
267,
291,
14,
1294,
9541,
257,
275,
11618,
14,
1294,
9541,
267,
291,
14,
7973,
258,
275,
11618,
14,
7973,
267,
291,
14,
21288,
258,
275,
11618,
14,
21288,
267,
291,
14,
9267,
258,
275,
11618,
14,
9267,
339,
347,
19529,
8,
277,
12,
931,
304,
267,
408,
1767,
376,
3679,
931,
1041,
267,
3379,
63,
515,
275,
931,
267,
931,
275,
14904,
1974,
14,
3557,
14,
305,
63,
2975,
8,
515,
9,
267,
340,
440,
291,
14,
17896,
8,
515,
304,
288,
931,
275,
291,
14,
904,
8,
277,
423,
1102,
14,
9458,
1062,
931,
9,
267,
372,
14904,
1974,
14,
3557,
14,
7191,
63,
875,
63,
466,
63,
305,
8,
5043,
63,
515,
12,
6059,
291,
14,
9267,
8,
515,
430,
339,
347,
3495,
8,
277,
12,
931,
304,
267,
408,
1767,
2549,
340,
314,
931,
3495,
1041,
267,
862,
26,
288,
634,
3736,
63,
1099,
275,
291,
423,
1102,
14,
26956,
8,
2490,
931,
12,
485,
1971,
63,
509,
63,
4752,
63,
515,
29,
797,
9,
288,
372,
634,
3736,
63,
1099,
365,
440,
488,
267,
871,
14904,
1974,
14,
705,
14,
6405,
3567,
547,
26,
288,
372,
715,
339,
347,
664,
8180,
8,
277,
12,
931,
304,
267,
408,
267,
1432,
314,
4913,
367,
314,
2061,
7100,
367,
658,
515,
64,
267,
465,
282,
2069,
14,
398,
961,
911,
746,
658,
31776,
547,
64,
340,
314,
931,
3181,
1133,
2187,
12,
267,
1325,
11703,
1163,
4967,
10298,
641,
314,
1174,
402,
314,
267,
1654,
334,
69,
14,
486,
14,
2653,
680,
267,
408,
267,
372,
291,
423,
1102,
14,
3736,
8,
515,
680,
270,
63,
8180,
339,
347,
664,
890,
8,
277,
12,
931,
304,
267,
408,
267,
1432,
314,
1568,
402,
314,
658,
515,
64,
1242,
465,
376,
3000,
14,
398,
961,
911,
746,
658,
31776,
547,
64,
340,
314,
931,
3181,
1133,
2187,
12,
267,
1325,
11703,
746,
1163,
4967,
10298,
641,
314,
1174,
402,
314,
267,
1654,
334,
69,
14,
486,
14,
2653,
680,
267,
408,
267,
372,
291,
423,
1102,
14,
3736,
8,
515,
680,
270,
63,
890,
339,
768,
4639,
272,
347,
4263,
2031,
3771,
304,
267,
408,
267,
25733,
314,
931,
3931,
687,
658,
3771,
64,
436,
372,
314,
16538,
267,
931,
14,
398,
2900,
402,
3520,
3792,
1471,
506,
1902,
2649,
3326,
503,
3696,
267,
3326,
14,
982,
440,
12,
658,
904,
64,
6534,
282,
658,
4333,
2313,
267,
408,
267,
327,
5723,
5920,
787,
19796,
4224,
701,
2018,
650,
12,
1325,
440,
701,
267,
327,
2018,
499,
14,
267,
1006,
63,
3771,
63,
1530,
63,
2975,
275,
1006,
8,
881,
334,
6074,
8,
515,
12,
14904,
1974,
14,
5819,
14,
2975,
63,
466,
9,
881,
367,
931,
315,
3792,
430,
267,
1006,
63,
3771,
63,
1530,
63,
2394,
275,
1006,
8,
881,
334,
6074,
8,
515,
12,
14904,
1974,
14,
5819,
14,
2394,
63,
466,
9,
881,
367,
931,
315,
3792,
430,
267,
340,
1006,
63,
3771,
63,
1530,
63,
2975,
503,
1006,
63,
3771,
63,
1530,
63,
2394,
26,
288,
372,
15454,
14,
904,
2031,
3771,
9,
267,
587,
26,
288,
327,
2018,
650,
6534,
642,
1919,
367,
13492,
3326,
288,
327,
315,
658,
736,
14,
515,
14,
904,
3559,
880,
2597,
675,
642,
1919,
14,
288,
746,
3146,
8,
490,
298,
2425,
1133,
13667,
2649,
3326,
436,
2783,
315,
931,
7323,
531,
339,
327,
2670,
3775,
282,
931,
365,
282,
5578,
570,
15,
694,
15,
1073,
14,
2104,
314,
1642,
272,
327,
2877,
5560,
2035,
6220,
334,
2930,
315,
658,
736,
14,
515,
14963,
272,
327,
272,
327,
24425,
5317,
26,
710,
4136,
12591,
9329,
2797,
272,
327,
658,
3736,
64,
503,
658,
26956,
64,
436,
2138,
658,
797,
64,
340,
2985,
22480,
543,
272,
327,
17026,
282,
658,
31776,
547,
2313,
10314,
1919,
9987,
1202,
370,
272,
327,
4673,
282,
4124,
931,
14,
961,
18140,
965,
314,
5160,
12,
13432,
12,
272,
327,
626,
4967,
18104,
701,
1233,
14119,
315,
658,
26956,
64,
787,
2607,
551,
3297,
272,
327,
701,
314,
1919,
7252,
315,
658,
6292,
3559,
658,
6027,
64,
436,
658,
20719,
2313,
339,
347,
29214,
8,
277,
12,
931,
304,
267,
408,
267,
1432,
2549,
340,
314,
658,
515,
64,
3495,
436,
13718,
370,
282,
5578,
267,
570,
334,
889,
2142,
680,
398,
437,
2222,
13,
5952,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
netscaler/neutron | neutron/tests/unit/linuxbridge/test_defaults.py | 2 | 1671 | # Copyright (c) 2012 OpenStack Foundation.
#
# 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 oslo.config import cfg
from neutron.plugins.linuxbridge.common import config # noqa
from neutron.tests import base
class ConfigurationTest(base.BaseTestCase):
def test_defaults(self):
self.assertEqual(2,
cfg.CONF.AGENT.polling_interval)
self.assertEqual(True,
cfg.CONF.AGENT.rpc_support_old_agents)
self.assertEqual('sudo',
cfg.CONF.AGENT.root_helper)
self.assertEqual('local',
cfg.CONF.VLANS.tenant_network_type)
self.assertEqual(0,
len(cfg.CONF.VLANS.network_vlan_ranges))
self.assertEqual(0,
len(cfg.CONF.LINUX_BRIDGE.
physical_interface_mappings))
self.assertEqual(False, cfg.CONF.VXLAN.enable_vxlan)
self.assertEqual(config.DEFAULT_VXLAN_GROUP,
cfg.CONF.VXLAN.vxlan_group)
self.assertEqual(0, len(cfg.CONF.VXLAN.local_ip))
self.assertEqual(False, cfg.CONF.VXLAN.l2_population)
| apache-2.0 | [
3,
1898,
334,
67,
9,
6029,
14260,
2752,
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,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
199,
504,
8224,
14,
5265,
14,
472,
85,
1774,
5562,
14,
2330,
492,
1101,
221,
327,
8151,
199,
504,
8224,
14,
2219,
492,
1300,
421,
199,
533,
11595,
774,
8,
1095,
14,
20760,
304,
339,
347,
511,
63,
4322,
8,
277,
304,
267,
291,
14,
629,
8,
18,
12,
586,
4810,
14,
3103,
14,
14565,
14,
17154,
63,
4284,
9,
267,
291,
14,
629,
8,
549,
12,
586,
4810,
14,
3103,
14,
14565,
14,
4354,
63,
4058,
63,
1753,
63,
14250,
9,
267,
291,
14,
629,
360,
12095,
297,
586,
4810,
14,
3103,
14,
14565,
14,
1231,
63,
3676,
9,
267,
291,
14,
629,
360,
1832,
297,
586,
4810,
14,
3103,
14,
32458,
5622,
14,
4647,
63,
1200,
63,
466,
9,
267,
291,
14,
629,
8,
16,
12,
586,
822,
8,
4128,
14,
3103,
14,
32458,
5622,
14,
1200,
63,
7175,
63,
8404,
430,
267,
291,
14,
629,
8,
16,
12,
586,
822,
8,
4128,
14,
3103,
14,
26030,
63,
7184,
998,
4962,
14,
2490,
14095,
63,
3266,
63,
14632,
430,
267,
291,
14,
629,
8,
797,
12,
4810,
14,
3103,
14,
28493,
10825,
14,
4296,
63,
18843,
1502,
9,
267,
291,
14,
629,
8,
888,
14,
3472,
63,
28493,
10825,
63,
7823,
12,
586,
4810,
14,
3103,
14,
28493,
10825,
14,
18843,
1502,
63,
923,
9,
267,
291,
14,
629,
8,
16,
12,
822,
8,
4128,
14,
3103,
14,
28493,
10825,
14,
1832,
63,
711,
430,
267,
291,
14,
629,
8,
797,
12,
4810,
14,
3103,
14,
28493,
10825,
14,
76,
18,
63,
16003,
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
] | [
1898,
334,
67,
9,
6029,
14260,
2752,
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,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
11258,
14,
888,
492,
4810,
199,
199,
504,
8224,
14,
5265,
14,
472,
85,
1774,
5562,
14,
2330,
492,
1101,
221,
327,
8151,
199,
504,
8224,
14,
2219,
492,
1300,
421,
199,
533,
11595,
774,
8,
1095,
14,
20760,
304,
339,
347,
511,
63,
4322,
8,
277,
304,
267,
291,
14,
629,
8,
18,
12,
586,
4810,
14,
3103,
14,
14565,
14,
17154,
63,
4284,
9,
267,
291,
14,
629,
8,
549,
12,
586,
4810,
14,
3103,
14,
14565,
14,
4354,
63,
4058,
63,
1753,
63,
14250,
9,
267,
291,
14,
629,
360,
12095,
297,
586,
4810,
14,
3103,
14,
14565,
14,
1231,
63,
3676,
9,
267,
291,
14,
629,
360,
1832,
297,
586,
4810,
14,
3103,
14,
32458,
5622,
14,
4647,
63,
1200,
63,
466,
9,
267,
291,
14,
629,
8,
16,
12,
586,
822,
8,
4128,
14,
3103,
14,
32458,
5622,
14,
1200,
63,
7175,
63,
8404,
430,
267,
291,
14,
629,
8,
16,
12,
586,
822,
8,
4128,
14,
3103,
14,
26030,
63,
7184,
998,
4962,
14,
2490,
14095,
63,
3266,
63,
14632,
430,
267,
291,
14,
629,
8,
797,
12,
4810,
14,
3103,
14,
28493,
10825,
14,
4296,
63,
18843,
1502,
9,
267,
291,
14,
629,
8,
888,
14,
3472,
63,
28493,
10825,
63,
7823,
12,
586,
4810,
14,
3103,
14,
28493,
10825,
14,
18843,
1502,
63,
923,
9,
267,
291,
14,
629,
8,
16,
12,
822,
8,
4128,
14,
3103,
14,
28493,
10825,
14,
1832,
63,
711,
430,
267,
291,
14,
629,
8,
797,
12,
4810,
14,
3103,
14,
28493,
10825,
14,
76,
18,
63,
16003,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
weidnerm/pi-ws2812 | version.py | 10 | 2918 | #
# SConstruct
#
# Copyright (c) 2016 Jeremy Garff <jer @ jers.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.
# 3. Neither the name of the owner nor the names of its contributors may be used to endorse
# or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 SCons, os
def version_flags(env):
if not env['V']:
env['VERSIONCOMSTR'] = 'Version ${TARGET}'
def version_builders(env):
def generate_version_header(target, source, env):
headername = os.path.basename(target[0].abspath)
headerdef = headername.replace('.', '_').replace('-', '_').upper()
try:
version = open(source[0].abspath, 'r').readline().strip().split('.')
except:
version = [ '0', '0', '0' ]
f = open(headername, 'w')
f.write('/* Auto Generated Header built by version.py - DO NOT MODIFY */\n')
f.write('\n')
f.write('#ifndef __%s__\n' % (headerdef))
f.write('#define __%s__\n' % (headerdef))
f.write('\n')
f.write('#define VERSION_MAJOR %s\n' % version[0])
f.write('#define VERSION_MINOR %s\n' % version[1])
f.write('#define VERSION_MICRO %s\n' % version[2])
f.write('\n')
f.write('#endif /* __%s__ */\n' % (headerdef))
f.close()
env.Append(BUILDERS = {
'Version' : SCons.Builder.Builder(
action = SCons.Action.Action(generate_version_header, '${VERSIONCOMSTR}'),
suffix = '.h',
),
})
def exists(env):
return 1
def generate(env, **kwargs):
[f(env) for f in (version_flags, version_builders)]
| bsd-2-clause | [
3,
199,
3,
428,
11493,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
1603,
69,
264,
1662,
598,
285,
556,
665,
74,
281,
768,
1335,
1192,
14,
846,
30,
199,
3,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
787,
8211,
199,
3,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
258,
413,
14,
221,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
769,
402,
199,
3,
260,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
499,
14,
221,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
642,
769,
199,
3,
260,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
199,
3,
260,
2741,
543,
314,
4084,
14,
199,
3,
258,
650,
14,
221,
11443,
314,
536,
402,
314,
5771,
6590,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
199,
3,
260,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
199,
3,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
199,
3,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
6262,
199,
3,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
199,
3,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
199,
3,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
199,
3,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
199,
3,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
646,
8218,
12,
747,
199,
199,
318,
1015,
63,
2469,
8,
1813,
304,
272,
340,
440,
2589,
459,
54,
2565,
267,
2589,
459,
4612,
11265,
3027,
418,
275,
283,
3353,
10839,
9268,
6834,
199,
199,
318,
1015,
63,
20968,
8,
1813,
304,
272,
347,
3550,
63,
1023,
63,
1291,
8,
1375,
12,
1350,
12,
2589,
304,
267,
1406,
354,
275,
747,
14,
515,
14,
4846,
8,
1375,
59,
16,
1055,
4832,
9,
267,
1406,
318,
275,
1406,
354,
14,
1814,
14078,
2513,
1959,
1814,
13858,
2513,
1959,
4142,
342,
398,
862,
26,
288,
1015,
275,
1551,
8,
1365,
59,
16,
1055,
4832,
12,
283,
82,
1959,
6407,
1252,
1913,
1252,
1294,
7563,
267,
871,
26,
288,
1015,
275,
359,
283,
16,
297,
283,
16,
297,
283,
16,
7,
1622,
398,
289,
275,
1551,
8,
1291,
354,
12,
283,
87,
358,
267,
289,
14,
952,
2336,
10,
9195,
17065,
10240,
6137,
701,
1015,
14,
647,
446,
3506,
2845,
10362,
1914,
18114,
9399,
78,
358,
267,
289,
14,
952,
2258,
78,
358,
267,
289,
14,
952,
7863,
27708,
636,
5,
83,
363,
60,
78,
7,
450,
334,
1291,
318,
430,
267,
289,
14,
952,
7863,
4640,
636,
5,
83,
363,
60,
78,
7,
450,
334,
1291,
318,
430,
267,
289,
14,
952,
2258,
78,
358,
267,
289,
14,
952,
7863,
4640,
15945,
63,
29241,
450,
83,
60,
78,
7,
450,
1015,
59,
16,
566,
267,
289,
14,
952,
7863,
4640,
15945,
63,
4896,
726,
450,
83,
60,
78,
7,
450,
1015,
59,
17,
566,
267,
289,
14,
952,
7863,
4640,
15945,
63,
29112,
450,
83,
60,
78,
7,
450,
1015,
59,
18,
566,
267,
289,
14,
952,
2258,
78,
358,
267,
289,
14,
952,
7863,
13739,
13505,
636,
5,
83,
363,
9399,
78,
7,
450,
334,
1291,
318,
430,
267,
289,
14,
1600,
342,
339,
2589,
14,
8310,
8,
8248,
3960,
275,
469,
267,
283,
3353,
7,
520,
8218,
14,
6437,
14,
6437,
8,
288,
1595,
275,
8218,
14,
3310,
14,
3310,
8,
4208,
63,
1023,
63,
1291,
12,
20044,
4612,
11265,
3027,
93,
659,
288,
4739,
275,
1987,
72,
297,
267,
2318,
272,
3828,
199,
199,
318,
3495,
8,
1813,
304,
272,
372,
413,
199,
199,
318,
3550,
8,
1813,
12,
1011,
958,
304,
272,
359,
70,
8,
1813,
9,
367,
289,
315,
334,
1023,
63,
2469,
12,
1015,
63,
20968,
1874,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
199,
3,
428,
11493,
199,
3,
199,
3,
1898,
334,
67,
9,
7800,
1603,
69,
264,
1662,
598,
285,
556,
665,
74,
281,
768,
1335,
1192,
14,
846,
30,
199,
3,
199,
3,
2900,
4481,
4644,
14,
199,
3,
199,
3,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
7100,
12,
787,
8211,
199,
3,
2741,
626,
314,
2569,
3704,
787,
7647,
26,
199,
3,
199,
3,
258,
413,
14,
221,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
4245,
12,
642,
769,
402,
199,
3,
260,
3704,
436,
314,
2569,
6450,
14,
199,
3,
258,
499,
14,
221,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
4245,
12,
642,
769,
199,
3,
260,
402,
3704,
436,
314,
2569,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
199,
3,
260,
2741,
543,
314,
4084,
14,
199,
3,
258,
650,
14,
221,
11443,
314,
536,
402,
314,
5771,
6590,
314,
1561,
402,
2399,
8417,
1443,
506,
1202,
370,
10692,
199,
3,
260,
503,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
5313,
4983,
14,
199,
3,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
199,
3,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
199,
3,
3092,
2381,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
29785,
6262,
199,
3,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
9836,
12,
1549,
9110,
6736,
199,
3,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
199,
3,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
5603,
12,
7061,
1621,
199,
3,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
199,
3,
1634,
2334,
4815,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
199,
646,
8218,
12,
747,
199,
199,
318,
1015,
63,
2469,
8,
1813,
304,
272,
340,
440,
2589,
459,
54,
2565,
267,
2589,
459,
4612,
11265,
3027,
418,
275,
283,
3353,
10839,
9268,
6834,
199,
199,
318,
1015,
63,
20968,
8,
1813,
304,
272,
347,
3550,
63,
1023,
63,
1291,
8,
1375,
12,
1350,
12,
2589,
304,
267,
1406,
354,
275,
747,
14,
515,
14,
4846,
8,
1375,
59,
16,
1055,
4832,
9,
267,
1406,
318,
275,
1406,
354,
14,
1814,
14078,
2513,
1959,
1814,
13858,
2513,
1959,
4142,
342,
398,
862,
26,
288,
1015,
275,
1551,
8,
1365,
59,
16,
1055,
4832,
12,
283,
82,
1959,
6407,
1252,
1913,
1252,
1294,
7563,
267,
871,
26,
288,
1015,
275,
359,
283,
16,
297,
283,
16,
297,
283,
16,
7,
1622,
398,
289,
275,
1551,
8,
1291,
354,
12,
283,
87,
358,
267,
289,
14,
952,
2336,
10,
9195,
17065,
10240,
6137,
701,
1015,
14,
647,
446,
3506,
2845,
10362,
1914,
18114,
9399,
78,
358,
267,
289,
14,
952,
2258,
78,
358,
267,
289,
14,
952,
7863,
27708,
636,
5,
83,
363,
60,
78,
7,
450,
334,
1291,
318,
430,
267,
289,
14,
952,
7863,
4640,
636,
5,
83,
363,
60,
78,
7,
450,
334,
1291,
318,
430,
267,
289,
14,
952,
2258,
78,
358,
267,
289,
14,
952,
7863,
4640,
15945,
63,
29241,
450,
83,
60,
78,
7,
450,
1015,
59,
16,
566,
267,
289,
14,
952,
7863,
4640,
15945,
63,
4896,
726,
450,
83,
60,
78,
7,
450,
1015,
59,
17,
566,
267,
289,
14,
952,
7863,
4640,
15945,
63,
29112,
450,
83,
60,
78,
7,
450,
1015,
59,
18,
566,
267,
289,
14,
952,
2258,
78,
358,
267,
289,
14,
952,
7863,
13739,
13505,
636,
5,
83,
363,
9399,
78,
7,
450,
334,
1291,
318,
430,
267,
289,
14,
1600,
342,
339,
2589,
14,
8310,
8,
8248,
3960,
275,
469,
267,
283,
3353,
7,
520,
8218,
14,
6437,
14,
6437,
8,
288,
1595,
275,
8218,
14,
3310,
14,
3310,
8,
4208,
63,
1023,
63,
1291,
12,
20044,
4612,
11265,
3027,
93,
659,
288,
4739,
275,
1987,
72,
297,
267,
2318,
272,
3828,
199,
199,
318,
3495,
8,
1813,
304,
272,
372,
413,
199,
199,
318,
3550,
8,
1813,
12,
1011,
958,
304,
272,
359,
70,
8,
1813,
9,
367,
289,
315,
334,
1023,
63,
2469,
12,
1015,
63,
20968,
1874,
4388,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
xupit3r/askpgh | askbot/middleware/locale.py | 13 | 1027 | "Taken from django.middleware.locale: this is the locale selecting middleware that will look at accept headers"
from django.utils.cache import patch_vary_headers
from django.utils import translation
from askbot.conf import settings
class LocaleMiddleware(object):
"""
This is a very simple middleware that parses a request
and decides what translation object to install in the current
thread context. This allows pages to be dynamically
translated to the language the user desires (if the language
is available, of course).
"""
def process_request(self, request):
language = settings.ASKBOT_LANGUAGE
translation.activate(language)
request.LANGUAGE_CODE = translation.get_language()
def process_response(self, request, response):
patch_vary_headers(response, ('Accept-Language',))
if 'Content-Language' not in response:
response['Content-Language'] = translation.get_language()
#translation.deactivate()
return response
| gpl-3.0 | [
2,
22620,
917,
687,
1639,
14,
5754,
14,
5508,
26,
642,
365,
314,
5867,
30090,
10816,
626,
911,
3648,
737,
4729,
2323,
2,
199,
199,
504,
1639,
14,
1208,
14,
1637,
492,
3371,
63,
21989,
63,
2139,
199,
504,
1639,
14,
1208,
492,
7761,
199,
504,
7198,
3018,
14,
2190,
492,
2202,
199,
199,
533,
28298,
6608,
8,
785,
304,
272,
408,
272,
961,
365,
282,
7437,
3486,
10816,
626,
19953,
282,
1056,
272,
436,
12985,
3424,
4052,
7761,
909,
370,
3907,
315,
314,
1453,
272,
2462,
1067,
14,
961,
6127,
6497,
370,
506,
18774,
272,
14598,
370,
314,
2637,
314,
922,
477,
338,
470,
334,
692,
314,
2637,
272,
365,
2808,
12,
402,
2518,
680,
272,
408,
339,
347,
2112,
63,
1069,
8,
277,
12,
1056,
304,
267,
2637,
275,
2202,
14,
7946,
11372,
63,
13947,
267,
7761,
14,
8222,
8,
3671,
9,
267,
1056,
14,
13947,
63,
6012,
275,
7761,
14,
362,
63,
3671,
342,
339,
347,
2112,
63,
1310,
8,
277,
12,
1056,
12,
1177,
304,
267,
3371,
63,
21989,
63,
2139,
8,
1310,
12,
661,
8422,
13,
8493,
16829,
267,
340,
283,
2714,
13,
8493,
7,
440,
315,
1177,
26,
288,
1177,
459,
2714,
13,
8493,
418,
275,
7761,
14,
362,
63,
3671,
342,
267,
327,
6893,
14,
24891,
342,
267,
372,
1177,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
22620,
917,
687,
1639,
14,
5754,
14,
5508,
26,
642,
365,
314,
5867,
30090,
10816,
626,
911,
3648,
737,
4729,
2323,
2,
199,
199,
504,
1639,
14,
1208,
14,
1637,
492,
3371,
63,
21989,
63,
2139,
199,
504,
1639,
14,
1208,
492,
7761,
199,
504,
7198,
3018,
14,
2190,
492,
2202,
199,
199,
533,
28298,
6608,
8,
785,
304,
272,
408,
272,
961,
365,
282,
7437,
3486,
10816,
626,
19953,
282,
1056,
272,
436,
12985,
3424,
4052,
7761,
909,
370,
3907,
315,
314,
1453,
272,
2462,
1067,
14,
961,
6127,
6497,
370,
506,
18774,
272,
14598,
370,
314,
2637,
314,
922,
477,
338,
470,
334,
692,
314,
2637,
272,
365,
2808,
12,
402,
2518,
680,
272,
408,
339,
347,
2112,
63,
1069,
8,
277,
12,
1056,
304,
267,
2637,
275,
2202,
14,
7946,
11372,
63,
13947,
267,
7761,
14,
8222,
8,
3671,
9,
267,
1056,
14,
13947,
63,
6012,
275,
7761,
14,
362,
63,
3671,
342,
339,
347,
2112,
63,
1310,
8,
277,
12,
1056,
12,
1177,
304,
267,
3371,
63,
21989,
63,
2139,
8,
1310,
12,
661,
8422,
13,
8493,
16829,
267,
340,
283,
2714,
13,
8493,
7,
440,
315,
1177,
26,
288,
1177,
459,
2714,
13,
8493,
418,
275,
7761,
14,
362,
63,
3671,
342,
267,
327,
6893,
14,
24891,
342,
267,
372,
1177,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
LockScreen/Backend | venv/lib/python2.7/site-packages/rsa/pem.py | 216 | 3372 | # -*- coding: utf-8 -*-
#
# Copyright 2011 Sybren A. Stüvel <[email protected]>
#
# 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.
'''Functions that load and write PEM-encoded files.'''
import base64
from rsa._compat import b, is_bytes
def _markers(pem_marker):
'''
Returns the start and end PEM markers
'''
if is_bytes(pem_marker):
pem_marker = pem_marker.decode('utf-8')
return (b('-----BEGIN %s-----' % pem_marker),
b('-----END %s-----' % pem_marker))
def load_pem(contents, pem_marker):
'''Loads a PEM file.
@param contents: the contents of the file to interpret
@param pem_marker: the marker of the PEM content, such as 'RSA PRIVATE KEY'
when your file has '-----BEGIN RSA PRIVATE KEY-----' and
'-----END RSA PRIVATE KEY-----' markers.
@return the base64-decoded content between the start and end markers.
@raise ValueError: when the content is invalid, for example when the start
marker cannot be found.
'''
(pem_start, pem_end) = _markers(pem_marker)
pem_lines = []
in_pem_part = False
for line in contents.splitlines():
line = line.strip()
# Skip empty lines
if not line:
continue
# Handle start marker
if line == pem_start:
if in_pem_part:
raise ValueError('Seen start marker "%s" twice' % pem_start)
in_pem_part = True
continue
# Skip stuff before first marker
if not in_pem_part:
continue
# Handle end marker
if in_pem_part and line == pem_end:
in_pem_part = False
break
# Load fields
if b(':') in line:
continue
pem_lines.append(line)
# Do some sanity checks
if not pem_lines:
raise ValueError('No PEM start marker "%s" found' % pem_start)
if in_pem_part:
raise ValueError('No PEM end marker "%s" found' % pem_end)
# Base64-decode the contents
pem = b('').join(pem_lines)
return base64.decodestring(pem)
def save_pem(contents, pem_marker):
'''Saves a PEM file.
@param contents: the contents to encode in PEM format
@param pem_marker: the marker of the PEM content, such as 'RSA PRIVATE KEY'
when your file has '-----BEGIN RSA PRIVATE KEY-----' and
'-----END RSA PRIVATE KEY-----' markers.
@return the base64-encoded content between the start and end markers.
'''
(pem_start, pem_end) = _markers(pem_marker)
b64 = base64.encodestring(contents).replace(b('\n'), b(''))
pem_lines = [pem_start]
for block_start in range(0, len(b64), 64):
block = b64[block_start:block_start + 64]
pem_lines.append(block)
pem_lines.append(pem_end)
pem_lines.append(b(''))
return b('\n').join(pem_lines)
| mit | [
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
221,
1898,
7760,
5515,
66,
828,
437,
14,
1933,
17709,
1090,
665,
1786,
66,
828,
32,
270,
85,
1090,
14,
16913,
30,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
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,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
199,
2344,
13967,
626,
2248,
436,
2218,
25957,
13,
8167,
1584,
10595,
199,
199,
646,
1300,
772,
199,
504,
23609,
423,
5819,
492,
330,
12,
365,
63,
2394,
199,
199,
318,
485,
16835,
8,
13102,
63,
4211,
304,
272,
1449,
272,
1803,
314,
1343,
436,
1284,
25957,
14327,
272,
1449,
339,
340,
365,
63,
2394,
8,
13102,
63,
4211,
304,
267,
4837,
77,
63,
4211,
275,
4837,
77,
63,
4211,
14,
2708,
360,
1624,
13,
24,
358,
339,
372,
334,
66,
360,
9858,
15947,
450,
83,
9858,
7,
450,
4837,
77,
63,
4211,
395,
288,
330,
360,
9858,
3902,
450,
83,
9858,
7,
450,
4837,
77,
63,
4211,
430,
199,
199,
318,
2248,
63,
13102,
8,
4407,
12,
4837,
77,
63,
4211,
304,
272,
1449,
30777,
282,
25957,
570,
14,
339,
768,
635,
4072,
26,
314,
4072,
402,
314,
570,
370,
15579,
272,
768,
635,
4837,
77,
63,
4211,
26,
314,
3608,
402,
314,
25957,
1564,
12,
4066,
465,
283,
12115,
28644,
1951,
9301,
7,
267,
1380,
2195,
570,
965,
283,
9858,
15947,
18471,
28644,
1951,
9301,
9858,
7,
436,
267,
283,
9858,
3902,
18471,
28644,
1951,
9301,
9858,
7,
14327,
14,
339,
768,
1107,
314,
1300,
772,
13,
16167,
1564,
3382,
314,
1343,
436,
1284,
14327,
14,
339,
768,
3730,
1722,
26,
1380,
314,
1564,
365,
3866,
12,
367,
2893,
1380,
314,
1343,
267,
3608,
3913,
506,
1911,
14,
339,
1449,
339,
334,
13102,
63,
928,
12,
4837,
77,
63,
500,
9,
275,
485,
16835,
8,
13102,
63,
4211,
9,
339,
4837,
77,
63,
1278,
275,
942,
272,
315,
63,
13102,
63,
2064,
275,
756,
339,
367,
1004,
315,
4072,
14,
7644,
837,
267,
1004,
275,
1004,
14,
1913,
342,
398,
327,
8232,
2701,
2385,
267,
340,
440,
1004,
26,
288,
1980,
398,
327,
8690,
1343,
3608,
267,
340,
1004,
508,
4837,
77,
63,
928,
26,
288,
340,
315,
63,
13102,
63,
2064,
26,
355,
746,
1722,
360,
1513,
287,
1343,
3608,
2071,
83,
2,
13373,
7,
450,
4837,
77,
63,
928,
9,
953,
315,
63,
13102,
63,
2064,
275,
715,
288,
1980,
398,
327,
8232,
8292,
2544,
1642,
3608,
267,
340,
440,
315,
63,
13102,
63,
2064,
26,
288,
1980,
398,
327,
8690,
1284,
3608,
267,
340,
315,
63,
13102,
63,
2064,
436,
1004,
508,
4837,
77,
63,
500,
26,
288,
315,
63,
13102,
63,
2064,
275,
756,
288,
2059,
398,
327,
7190,
1504,
267,
340,
330,
11633,
315,
1004,
26,
288,
1980,
398,
4837,
77,
63,
1278,
14,
740,
8,
604,
9,
339,
327,
4226,
2005,
16740,
5920,
272,
340,
440,
4837,
77,
63,
1278,
26,
267,
746,
1722,
360,
1944,
25957,
1343,
3608,
2071,
83,
2,
1911,
7,
450,
4837,
77,
63,
928,
9,
339,
340,
315,
63,
13102,
63,
2064,
26,
267,
746,
1722,
360,
1944,
25957,
1284,
3608,
2071,
83,
2,
1911,
7,
450,
4837,
77,
63,
500,
9,
339,
327,
3523,
772,
13,
2708,
314,
4072,
272,
4837,
77,
275,
330,
360,
1959,
904,
8,
13102,
63,
1278,
9,
272,
372,
1300,
772,
14,
2708,
875,
8,
13102,
9,
421,
199,
318,
3354,
63,
13102,
8,
4407,
12,
4837,
77,
63,
4211,
304,
272,
1449,
51,
7047,
282,
25957,
570,
14,
339,
768,
635,
4072,
26,
314,
4072,
370,
3752,
315,
25957,
1475,
272,
768,
635,
4837,
77,
63,
4211,
26,
314,
3608,
402,
314,
25957,
1564,
12,
4066,
465,
283,
12115,
28644,
1951,
9301,
7,
267,
1380,
2195,
570,
965,
283,
9858,
15947,
18471,
28644,
1951,
9301,
9858,
7,
436,
267,
283,
9858,
3902,
18471,
28644,
1951,
9301,
9858,
7,
14327,
14,
339,
768,
1107,
314,
1300,
772,
13,
8167,
1564,
3382,
314,
1343,
436,
1284,
14327,
14,
339,
1449,
339,
334,
13102,
63,
928,
12,
4837,
77,
63,
500,
9,
275,
485,
16835,
8,
13102,
63,
4211,
9,
339,
330,
772,
275,
1300,
772,
14,
2143,
875,
8,
4407,
680,
1814,
8,
66,
2258,
78,
659,
330,
30991,
272,
4837,
77,
63,
1278,
275,
359,
13102,
63,
928,
61,
2286,
367,
1853,
63,
928,
315,
1425,
8,
16,
12,
822,
8,
66,
772,
395,
5049,
304,
267,
1853,
275,
330,
772,
59,
1457,
63,
928,
26,
1457,
63,
928,
435,
5049,
61,
267,
4837,
77,
63,
1278,
14,
740,
8,
1457,
9,
339,
4837,
77,
63,
1278,
14,
740,
8,
13102,
63,
500,
9,
272,
4837,
77,
63,
1278,
14,
740,
8,
66,
30991,
339,
372,
330,
2258,
78,
1959,
904,
8,
13102,
63,
1278,
9,
16872,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
221,
1898,
7760,
5515,
66,
828,
437,
14,
1933,
17709,
1090,
665,
1786,
66,
828,
32,
270,
85,
1090,
14,
16913,
30,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
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,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
199,
2344,
13967,
626,
2248,
436,
2218,
25957,
13,
8167,
1584,
10595,
199,
199,
646,
1300,
772,
199,
504,
23609,
423,
5819,
492,
330,
12,
365,
63,
2394,
199,
199,
318,
485,
16835,
8,
13102,
63,
4211,
304,
272,
1449,
272,
1803,
314,
1343,
436,
1284,
25957,
14327,
272,
1449,
339,
340,
365,
63,
2394,
8,
13102,
63,
4211,
304,
267,
4837,
77,
63,
4211,
275,
4837,
77,
63,
4211,
14,
2708,
360,
1624,
13,
24,
358,
339,
372,
334,
66,
360,
9858,
15947,
450,
83,
9858,
7,
450,
4837,
77,
63,
4211,
395,
288,
330,
360,
9858,
3902,
450,
83,
9858,
7,
450,
4837,
77,
63,
4211,
430,
199,
199,
318,
2248,
63,
13102,
8,
4407,
12,
4837,
77,
63,
4211,
304,
272,
1449,
30777,
282,
25957,
570,
14,
339,
768,
635,
4072,
26,
314,
4072,
402,
314,
570,
370,
15579,
272,
768,
635,
4837,
77,
63,
4211,
26,
314,
3608,
402,
314,
25957,
1564,
12,
4066,
465,
283,
12115,
28644,
1951,
9301,
7,
267,
1380,
2195,
570,
965,
283,
9858,
15947,
18471,
28644,
1951,
9301,
9858,
7,
436,
267,
283,
9858,
3902,
18471,
28644,
1951,
9301,
9858,
7,
14327,
14,
339,
768,
1107,
314,
1300,
772,
13,
16167,
1564,
3382,
314,
1343,
436,
1284,
14327,
14,
339,
768,
3730,
1722,
26,
1380,
314,
1564,
365,
3866,
12,
367,
2893,
1380,
314,
1343,
267,
3608,
3913,
506,
1911,
14,
339,
1449,
339,
334,
13102,
63,
928,
12,
4837,
77,
63,
500,
9,
275,
485,
16835,
8,
13102,
63,
4211,
9,
339,
4837,
77,
63,
1278,
275,
942,
272,
315,
63,
13102,
63,
2064,
275,
756,
339,
367,
1004,
315,
4072,
14,
7644,
837,
267,
1004,
275,
1004,
14,
1913,
342,
398,
327,
8232,
2701,
2385,
267,
340,
440,
1004,
26,
288,
1980,
398,
327,
8690,
1343,
3608,
267,
340,
1004,
508,
4837,
77,
63,
928,
26,
288,
340,
315,
63,
13102,
63,
2064,
26,
355,
746,
1722,
360,
1513,
287,
1343,
3608,
2071,
83,
2,
13373,
7,
450,
4837,
77,
63,
928,
9,
953,
315,
63,
13102,
63,
2064,
275,
715,
288,
1980,
398,
327,
8232,
8292,
2544,
1642,
3608,
267,
340,
440,
315,
63,
13102,
63,
2064,
26,
288,
1980,
398,
327,
8690,
1284,
3608,
267,
340,
315,
63,
13102,
63,
2064,
436,
1004,
508,
4837,
77,
63,
500,
26,
288,
315,
63,
13102,
63,
2064,
275,
756,
288,
2059,
398,
327,
7190,
1504,
267,
340,
330,
11633,
315,
1004,
26,
288,
1980,
398,
4837,
77,
63,
1278,
14,
740,
8,
604,
9,
339,
327,
4226,
2005,
16740,
5920,
272,
340,
440,
4837,
77,
63,
1278,
26,
267,
746,
1722,
360,
1944,
25957,
1343,
3608,
2071,
83,
2,
1911,
7,
450,
4837,
77,
63,
928,
9,
339,
340,
315,
63,
13102,
63,
2064,
26,
267,
746,
1722,
360,
1944,
25957,
1284,
3608,
2071,
83,
2,
1911,
7,
450,
4837,
77,
63,
500,
9,
339,
327,
3523,
772,
13,
2708,
314,
4072,
272,
4837,
77,
275,
330,
360,
1959,
904,
8,
13102,
63,
1278,
9,
272,
372,
1300,
772,
14,
2708,
875,
8,
13102,
9,
421,
199,
318,
3354,
63,
13102,
8,
4407,
12,
4837,
77,
63,
4211,
304,
272,
1449,
51,
7047,
282,
25957,
570,
14,
339,
768,
635,
4072,
26,
314,
4072,
370,
3752,
315,
25957,
1475,
272,
768,
635,
4837,
77,
63,
4211,
26,
314,
3608,
402,
314,
25957,
1564,
12,
4066,
465,
283,
12115,
28644,
1951,
9301,
7,
267,
1380,
2195,
570,
965,
283,
9858,
15947,
18471,
28644,
1951,
9301,
9858,
7,
436,
267,
283,
9858,
3902,
18471,
28644,
1951,
9301,
9858,
7,
14327,
14,
339,
768,
1107,
314,
1300,
772,
13,
8167,
1564,
3382,
314,
1343,
436,
1284,
14327,
14,
339,
1449,
339,
334,
13102,
63,
928,
12,
4837,
77,
63,
500,
9,
275,
485,
16835,
8,
13102,
63,
4211,
9,
339,
330,
772,
275,
1300,
772,
14,
2143,
875,
8,
4407,
680,
1814,
8,
66,
2258,
78,
659,
330,
30991,
272,
4837,
77,
63,
1278,
275,
359,
13102,
63,
928,
61,
2286,
367,
1853,
63,
928,
315,
1425,
8,
16,
12,
822,
8,
66,
772,
395,
5049,
304,
267,
1853,
275,
330,
772,
59,
1457,
63,
928,
26,
1457,
63,
928,
435,
5049,
61,
267,
4837,
77,
63,
1278,
14,
740,
8,
1457,
9,
339,
4837,
77,
63,
1278,
14,
740,
8,
13102,
63,
500,
9,
272,
4837,
77,
63,
1278,
14,
740,
8,
66,
30991,
339,
372,
330,
2258,
78,
1959,
904,
8,
13102,
63,
1278,
9,
16872,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
beomyeol/models | street/python/errorcounter_test.py | 22 | 4913 | # Copyright 2016 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for errorcounter."""
import tensorflow as tf
import errorcounter as ec
class ErrorcounterTest(tf.test.TestCase):
def testComputeErrorRate(self):
"""Tests that the percent calculation works as expected.
"""
rate = ec.ComputeErrorRate(error_count=0, truth_count=0)
self.assertEqual(rate, 100.0)
rate = ec.ComputeErrorRate(error_count=1, truth_count=0)
self.assertEqual(rate, 100.0)
rate = ec.ComputeErrorRate(error_count=10, truth_count=1)
self.assertEqual(rate, 100.0)
rate = ec.ComputeErrorRate(error_count=0, truth_count=1)
self.assertEqual(rate, 0.0)
rate = ec.ComputeErrorRate(error_count=3, truth_count=12)
self.assertEqual(rate, 25.0)
def testCountErrors(self):
"""Tests that the error counter works as expected.
"""
truth_str = 'farm barn'
counts = ec.CountErrors(ocr_text=truth_str, truth_text=truth_str)
self.assertEqual(
counts, ec.ErrorCounts(
fn=0, fp=0, truth_count=9, test_count=9))
# With a period on the end, we get a char error.
dot_str = 'farm barn.'
counts = ec.CountErrors(ocr_text=dot_str, truth_text=truth_str)
self.assertEqual(
counts, ec.ErrorCounts(
fn=0, fp=1, truth_count=9, test_count=10))
counts = ec.CountErrors(ocr_text=truth_str, truth_text=dot_str)
self.assertEqual(
counts, ec.ErrorCounts(
fn=1, fp=0, truth_count=10, test_count=9))
# Space is just another char.
no_space = 'farmbarn'
counts = ec.CountErrors(ocr_text=no_space, truth_text=truth_str)
self.assertEqual(
counts, ec.ErrorCounts(
fn=1, fp=0, truth_count=9, test_count=8))
counts = ec.CountErrors(ocr_text=truth_str, truth_text=no_space)
self.assertEqual(
counts, ec.ErrorCounts(
fn=0, fp=1, truth_count=8, test_count=9))
# Lose them all.
counts = ec.CountErrors(ocr_text='', truth_text=truth_str)
self.assertEqual(
counts, ec.ErrorCounts(
fn=9, fp=0, truth_count=9, test_count=0))
counts = ec.CountErrors(ocr_text=truth_str, truth_text='')
self.assertEqual(
counts, ec.ErrorCounts(
fn=0, fp=9, truth_count=0, test_count=9))
def testCountWordErrors(self):
"""Tests that the error counter works as expected.
"""
truth_str = 'farm barn'
counts = ec.CountWordErrors(ocr_text=truth_str, truth_text=truth_str)
self.assertEqual(
counts, ec.ErrorCounts(
fn=0, fp=0, truth_count=2, test_count=2))
# With a period on the end, we get a word error.
dot_str = 'farm barn.'
counts = ec.CountWordErrors(ocr_text=dot_str, truth_text=truth_str)
self.assertEqual(
counts, ec.ErrorCounts(
fn=1, fp=1, truth_count=2, test_count=2))
counts = ec.CountWordErrors(ocr_text=truth_str, truth_text=dot_str)
self.assertEqual(
counts, ec.ErrorCounts(
fn=1, fp=1, truth_count=2, test_count=2))
# Space is special.
no_space = 'farmbarn'
counts = ec.CountWordErrors(ocr_text=no_space, truth_text=truth_str)
self.assertEqual(
counts, ec.ErrorCounts(
fn=2, fp=1, truth_count=2, test_count=1))
counts = ec.CountWordErrors(ocr_text=truth_str, truth_text=no_space)
self.assertEqual(
counts, ec.ErrorCounts(
fn=1, fp=2, truth_count=1, test_count=2))
# Lose them all.
counts = ec.CountWordErrors(ocr_text='', truth_text=truth_str)
self.assertEqual(
counts, ec.ErrorCounts(
fn=2, fp=0, truth_count=2, test_count=0))
counts = ec.CountWordErrors(ocr_text=truth_str, truth_text='')
self.assertEqual(
counts, ec.ErrorCounts(
fn=0, fp=2, truth_count=0, test_count=2))
# With a space in ba rn, there is an extra add.
sp_str = 'farm ba rn'
counts = ec.CountWordErrors(ocr_text=sp_str, truth_text=truth_str)
self.assertEqual(
counts, ec.ErrorCounts(
fn=1, fp=2, truth_count=2, test_count=3))
counts = ec.CountWordErrors(ocr_text=truth_str, truth_text=sp_str)
self.assertEqual(
counts, ec.ErrorCounts(
fn=2, fp=1, truth_count=3, test_count=2))
if __name__ == '__main__':
tf.test.main()
| apache-2.0 | [
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
1125,
5337,
1041,
199,
646,
3228,
465,
2833,
199,
646,
1125,
5337,
465,
7062,
421,
199,
533,
4520,
5337,
774,
8,
3249,
14,
396,
14,
1746,
304,
819,
347,
511,
8564,
30676,
8,
277,
304,
272,
408,
2925,
626,
314,
8878,
15232,
5419,
465,
1420,
14,
272,
408,
272,
6634,
275,
7062,
14,
8564,
30676,
8,
705,
63,
835,
29,
16,
12,
16865,
63,
835,
29,
16,
9,
272,
291,
14,
629,
8,
1866,
12,
2948,
14,
16,
9,
272,
6634,
275,
7062,
14,
8564,
30676,
8,
705,
63,
835,
29,
17,
12,
16865,
63,
835,
29,
16,
9,
272,
291,
14,
629,
8,
1866,
12,
2948,
14,
16,
9,
272,
6634,
275,
7062,
14,
8564,
30676,
8,
705,
63,
835,
29,
709,
12,
16865,
63,
835,
29,
17,
9,
272,
291,
14,
629,
8,
1866,
12,
2948,
14,
16,
9,
272,
6634,
275,
7062,
14,
8564,
30676,
8,
705,
63,
835,
29,
16,
12,
16865,
63,
835,
29,
17,
9,
272,
291,
14,
629,
8,
1866,
12,
378,
14,
16,
9,
272,
6634,
275,
7062,
14,
8564,
30676,
8,
705,
63,
835,
29,
19,
12,
16865,
63,
835,
29,
713,
9,
272,
291,
14,
629,
8,
1866,
12,
5661,
14,
16,
9,
819,
347,
511,
2353,
9298,
8,
277,
304,
272,
408,
2925,
626,
314,
1125,
7055,
5419,
465,
1420,
14,
272,
408,
272,
16865,
63,
495,
275,
283,
70,
5362,
330,
1060,
7,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
29,
17167,
63,
495,
12,
16865,
63,
505,
29,
17167,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
16,
12,
4090,
29,
16,
12,
16865,
63,
835,
29,
25,
12,
511,
63,
835,
29,
25,
430,
272,
327,
8777,
282,
6247,
641,
314,
1284,
12,
781,
664,
282,
1495,
1125,
14,
272,
6308,
63,
495,
275,
283,
70,
5362,
330,
1060,
3530,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
29,
3287,
63,
495,
12,
16865,
63,
505,
29,
17167,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
16,
12,
4090,
29,
17,
12,
16865,
63,
835,
29,
25,
12,
511,
63,
835,
29,
709,
430,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
29,
17167,
63,
495,
12,
16865,
63,
505,
29,
3287,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
17,
12,
4090,
29,
16,
12,
16865,
63,
835,
29,
709,
12,
511,
63,
835,
29,
25,
430,
272,
327,
19326,
365,
2951,
4573,
1495,
14,
272,
949,
63,
2638,
275,
283,
15315,
887,
1060,
7,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
29,
889,
63,
2638,
12,
16865,
63,
505,
29,
17167,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
17,
12,
4090,
29,
16,
12,
16865,
63,
835,
29,
25,
12,
511,
63,
835,
29,
24,
430,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
29,
17167,
63,
495,
12,
16865,
63,
505,
29,
889,
63,
2638,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
16,
12,
4090,
29,
17,
12,
16865,
63,
835,
29,
24,
12,
511,
63,
835,
29,
25,
430,
272,
327,
491,
3362,
3062,
1006,
14,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
4581,
16865,
63,
505,
29,
17167,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
25,
12,
4090,
29,
16,
12,
16865,
63,
835,
29,
25,
12,
511,
63,
835,
29,
16,
430,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
29,
17167,
63,
495,
12,
16865,
63,
505,
13275,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
16,
12,
4090,
29,
25,
12,
16865,
63,
835,
29,
16,
12,
511,
63,
835,
29,
25,
430,
819,
347,
511,
2353,
10155,
9298,
8,
277,
304,
272,
408,
2925,
626,
314,
1125,
7055,
5419,
465,
1420,
14,
272,
408,
272,
16865,
63,
495,
275,
283,
70,
5362,
330,
1060,
7,
272,
8242,
275,
7062,
14,
2353,
10155,
9298,
8,
679,
82,
63,
505,
29,
17167,
63,
495,
12,
16865,
63,
505,
29,
17167,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
16,
12,
4090,
29,
16,
12,
16865,
63,
835,
29,
18,
12,
511,
63,
835,
29,
18,
430,
272,
327,
8777,
282,
6247,
641,
314,
1284,
12,
781,
664,
282,
4349,
1125,
14,
272,
6308,
63,
495,
275,
283,
70,
5362,
330,
1060,
3530,
272,
8242,
275,
7062,
14,
2353,
10155,
9298,
8,
679,
82,
63,
505,
29,
3287,
63,
495,
12,
16865,
63,
505,
29,
17167,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
17,
12,
4090,
29,
17,
12,
16865,
63,
835,
29,
18,
12,
511,
63,
835,
29,
18,
430,
272,
8242,
275,
7062,
14
] | [
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
3,
11148,
199,
624,
2925,
367,
1125,
5337,
1041,
199,
646,
3228,
465,
2833,
199,
646,
1125,
5337,
465,
7062,
421,
199,
533,
4520,
5337,
774,
8,
3249,
14,
396,
14,
1746,
304,
819,
347,
511,
8564,
30676,
8,
277,
304,
272,
408,
2925,
626,
314,
8878,
15232,
5419,
465,
1420,
14,
272,
408,
272,
6634,
275,
7062,
14,
8564,
30676,
8,
705,
63,
835,
29,
16,
12,
16865,
63,
835,
29,
16,
9,
272,
291,
14,
629,
8,
1866,
12,
2948,
14,
16,
9,
272,
6634,
275,
7062,
14,
8564,
30676,
8,
705,
63,
835,
29,
17,
12,
16865,
63,
835,
29,
16,
9,
272,
291,
14,
629,
8,
1866,
12,
2948,
14,
16,
9,
272,
6634,
275,
7062,
14,
8564,
30676,
8,
705,
63,
835,
29,
709,
12,
16865,
63,
835,
29,
17,
9,
272,
291,
14,
629,
8,
1866,
12,
2948,
14,
16,
9,
272,
6634,
275,
7062,
14,
8564,
30676,
8,
705,
63,
835,
29,
16,
12,
16865,
63,
835,
29,
17,
9,
272,
291,
14,
629,
8,
1866,
12,
378,
14,
16,
9,
272,
6634,
275,
7062,
14,
8564,
30676,
8,
705,
63,
835,
29,
19,
12,
16865,
63,
835,
29,
713,
9,
272,
291,
14,
629,
8,
1866,
12,
5661,
14,
16,
9,
819,
347,
511,
2353,
9298,
8,
277,
304,
272,
408,
2925,
626,
314,
1125,
7055,
5419,
465,
1420,
14,
272,
408,
272,
16865,
63,
495,
275,
283,
70,
5362,
330,
1060,
7,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
29,
17167,
63,
495,
12,
16865,
63,
505,
29,
17167,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
16,
12,
4090,
29,
16,
12,
16865,
63,
835,
29,
25,
12,
511,
63,
835,
29,
25,
430,
272,
327,
8777,
282,
6247,
641,
314,
1284,
12,
781,
664,
282,
1495,
1125,
14,
272,
6308,
63,
495,
275,
283,
70,
5362,
330,
1060,
3530,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
29,
3287,
63,
495,
12,
16865,
63,
505,
29,
17167,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
16,
12,
4090,
29,
17,
12,
16865,
63,
835,
29,
25,
12,
511,
63,
835,
29,
709,
430,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
29,
17167,
63,
495,
12,
16865,
63,
505,
29,
3287,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
17,
12,
4090,
29,
16,
12,
16865,
63,
835,
29,
709,
12,
511,
63,
835,
29,
25,
430,
272,
327,
19326,
365,
2951,
4573,
1495,
14,
272,
949,
63,
2638,
275,
283,
15315,
887,
1060,
7,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
29,
889,
63,
2638,
12,
16865,
63,
505,
29,
17167,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
17,
12,
4090,
29,
16,
12,
16865,
63,
835,
29,
25,
12,
511,
63,
835,
29,
24,
430,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
29,
17167,
63,
495,
12,
16865,
63,
505,
29,
889,
63,
2638,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
16,
12,
4090,
29,
17,
12,
16865,
63,
835,
29,
24,
12,
511,
63,
835,
29,
25,
430,
272,
327,
491,
3362,
3062,
1006,
14,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
4581,
16865,
63,
505,
29,
17167,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
25,
12,
4090,
29,
16,
12,
16865,
63,
835,
29,
25,
12,
511,
63,
835,
29,
16,
430,
272,
8242,
275,
7062,
14,
2353,
9298,
8,
679,
82,
63,
505,
29,
17167,
63,
495,
12,
16865,
63,
505,
13275,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
16,
12,
4090,
29,
25,
12,
16865,
63,
835,
29,
16,
12,
511,
63,
835,
29,
25,
430,
819,
347,
511,
2353,
10155,
9298,
8,
277,
304,
272,
408,
2925,
626,
314,
1125,
7055,
5419,
465,
1420,
14,
272,
408,
272,
16865,
63,
495,
275,
283,
70,
5362,
330,
1060,
7,
272,
8242,
275,
7062,
14,
2353,
10155,
9298,
8,
679,
82,
63,
505,
29,
17167,
63,
495,
12,
16865,
63,
505,
29,
17167,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
16,
12,
4090,
29,
16,
12,
16865,
63,
835,
29,
18,
12,
511,
63,
835,
29,
18,
430,
272,
327,
8777,
282,
6247,
641,
314,
1284,
12,
781,
664,
282,
4349,
1125,
14,
272,
6308,
63,
495,
275,
283,
70,
5362,
330,
1060,
3530,
272,
8242,
275,
7062,
14,
2353,
10155,
9298,
8,
679,
82,
63,
505,
29,
3287,
63,
495,
12,
16865,
63,
505,
29,
17167,
63,
495,
9,
272,
291,
14,
629,
8,
267,
8242,
12,
7062,
14,
547,
23209,
8,
288,
4325,
29,
17,
12,
4090,
29,
17,
12,
16865,
63,
835,
29,
18,
12,
511,
63,
835,
29,
18,
430,
272,
8242,
275,
7062,
14,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
tensorflow/datasets | tensorflow_datasets/text/tiny_shakespeare_test.py | 1 | 1291 | # coding=utf-8
# Copyright 2021 The TensorFlow Datasets Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Tests for tiny Shakespeare dataset."""
from tensorflow_datasets import testing
from tensorflow_datasets.text import tiny_shakespeare
class TinyShakespeareTest(testing.DatasetBuilderTestCase):
DATASET_CLASS = tiny_shakespeare.TinyShakespeare
SPLITS = {
"train": 1,
"validation": 1,
"test": 1,
}
# If you are calling `download/download_and_extract` with a dict, like:
# dl_manager.download({'some_key': 'http://a.org/out.txt', ...})
# then the tests needs to provide the fake output paths relative to the
# fake data directory
# DL_EXTRACT_RESULT = {'some_key': 'output_file1.txt', ...}
if __name__ == "__main__":
testing.test_main()
| apache-2.0 | [
3,
2803,
29,
1624,
13,
24,
199,
3,
1898,
499,
15385,
710,
9134,
3918,
2193,
6642,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
2925,
367,
29128,
5244,
4364,
321,
1530,
4789,
1041,
199,
199,
504,
3228,
63,
12281,
492,
5343,
199,
504,
3228,
63,
12281,
14,
505,
492,
29128,
63,
609,
4364,
321,
1530,
421,
199,
533,
11947,
2662,
4364,
321,
1530,
774,
8,
4776,
14,
9271,
6437,
1746,
304,
523,
17971,
1179,
775,
63,
6885,
275,
29128,
63,
609,
4364,
321,
1530,
14,
52,
8952,
2662,
4364,
321,
1530,
523,
428,
2749,
5930,
275,
469,
489,
298,
2834,
582,
413,
12,
489,
298,
6136,
582,
413,
12,
489,
298,
396,
582,
413,
12,
523,
789,
819,
327,
982,
1265,
787,
6358,
658,
4249,
15,
4249,
63,
460,
63,
5005,
64,
543,
282,
1211,
12,
2839,
26,
523,
327,
257,
15396,
63,
2609,
14,
4249,
3252,
3972,
63,
498,
356,
283,
1014,
921,
65,
14,
1308,
15,
548,
14,
2424,
297,
2263,
1552,
523,
327,
2066,
314,
2295,
4839,
370,
5647,
314,
4026,
1072,
3792,
3847,
370,
314,
523,
327,
4026,
666,
2082,
523,
327,
577,
44,
63,
30335,
63,
9517,
275,
791,
3972,
63,
498,
356,
283,
1199,
63,
493,
17,
14,
2424,
297,
2263,
93,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
5343,
14,
396,
63,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
2803,
29,
1624,
13,
24,
199,
3,
1898,
499,
15385,
710,
9134,
3918,
2193,
6642,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
2925,
367,
29128,
5244,
4364,
321,
1530,
4789,
1041,
199,
199,
504,
3228,
63,
12281,
492,
5343,
199,
504,
3228,
63,
12281,
14,
505,
492,
29128,
63,
609,
4364,
321,
1530,
421,
199,
533,
11947,
2662,
4364,
321,
1530,
774,
8,
4776,
14,
9271,
6437,
1746,
304,
523,
17971,
1179,
775,
63,
6885,
275,
29128,
63,
609,
4364,
321,
1530,
14,
52,
8952,
2662,
4364,
321,
1530,
523,
428,
2749,
5930,
275,
469,
489,
298,
2834,
582,
413,
12,
489,
298,
6136,
582,
413,
12,
489,
298,
396,
582,
413,
12,
523,
789,
819,
327,
982,
1265,
787,
6358,
658,
4249,
15,
4249,
63,
460,
63,
5005,
64,
543,
282,
1211,
12,
2839,
26,
523,
327,
257,
15396,
63,
2609,
14,
4249,
3252,
3972,
63,
498,
356,
283,
1014,
921,
65,
14,
1308,
15,
548,
14,
2424,
297,
2263,
1552,
523,
327,
2066,
314,
2295,
4839,
370,
5647,
314,
4026,
1072,
3792,
3847,
370,
314,
523,
327,
4026,
666,
2082,
523,
327,
577,
44,
63,
30335,
63,
9517,
275,
791,
3972,
63,
498,
356,
283,
1199,
63,
493,
17,
14,
2424,
297,
2263,
93,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
5343,
14,
396,
63,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
aboyett/blockdiag | src/blockdiag/plugins/autoclass.py | 1 | 1130 | # -*- coding: utf-8 -*-
# Copyright 2011 Takeshi KOMIYA
#
# 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 re
from blockdiag import plugins
class AutoClass(plugins.NodeHandler):
def on_created(self, node):
if node.id is None:
return
for name, klass in self.diagram.classes.items():
pattern = "_%s$" % re.escape(name)
if re.search(pattern, node.id):
node.label = re.sub(pattern, '', node.id)
node.set_attributes(klass.attrs)
def setup(self, diagram, **kwargs):
plugins.install_node_handler(AutoClass(diagram, **kwargs))
| apache-2.0 | [
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
221,
1898,
7760,
17415,
5812,
1804,
7474,
41,
57,
33,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
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,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
199,
646,
295,
199,
504,
1853,
6706,
492,
8963,
421,
199,
533,
9195,
2543,
8,
5265,
14,
1716,
2461,
304,
272,
347,
641,
63,
3966,
8,
277,
12,
1031,
304,
267,
340,
1031,
14,
344,
365,
488,
26,
288,
372,
398,
367,
536,
12,
8531,
315,
291,
14,
32189,
14,
2888,
14,
1744,
837,
288,
3851,
275,
2668,
5,
83,
17351,
450,
295,
14,
3765,
8,
354,
9,
953,
340,
295,
14,
1733,
8,
3401,
12,
1031,
14,
344,
304,
355,
1031,
14,
1302,
275,
295,
14,
954,
8,
3401,
12,
3260,
1031,
14,
344,
9,
355,
1031,
14,
409,
63,
2987,
8,
11645,
14,
3288,
9,
421,
199,
318,
3272,
8,
277,
12,
8348,
5975,
12,
1011,
958,
304,
272,
8963,
14,
3174,
63,
932,
63,
2232,
8,
3358,
2543,
8,
32189,
12,
1011,
958,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
221,
1898,
7760,
17415,
5812,
1804,
7474,
41,
57,
33,
199,
3,
199,
3,
221,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
221,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
221,
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,
221,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
221,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
221,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
221,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
221,
4204,
1334,
314,
844,
14,
199,
199,
646,
295,
199,
504,
1853,
6706,
492,
8963,
421,
199,
533,
9195,
2543,
8,
5265,
14,
1716,
2461,
304,
272,
347,
641,
63,
3966,
8,
277,
12,
1031,
304,
267,
340,
1031,
14,
344,
365,
488,
26,
288,
372,
398,
367,
536,
12,
8531,
315,
291,
14,
32189,
14,
2888,
14,
1744,
837,
288,
3851,
275,
2668,
5,
83,
17351,
450,
295,
14,
3765,
8,
354,
9,
953,
340,
295,
14,
1733,
8,
3401,
12,
1031,
14,
344,
304,
355,
1031,
14,
1302,
275,
295,
14,
954,
8,
3401,
12,
3260,
1031,
14,
344,
9,
355,
1031,
14,
409,
63,
2987,
8,
11645,
14,
3288,
9,
421,
199,
318,
3272,
8,
277,
12,
8348,
5975,
12,
1011,
958,
304,
272,
8963,
14,
3174,
63,
932,
63,
2232,
8,
3358,
2543,
8,
32189,
12,
1011,
958,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
thelac/crazyflie | win32install/generate_nsis.py | 18 | 1224 | import jinja2
import os
from subprocess import Popen, PIPE
DIST_PATH = "..\dist"
# Get list of files and directory to install/uninstall
INSTALL_FILES = []
INSTALL_DIRS = []
os.chdir(os.path.join(os.path.dirname(__file__), DIST_PATH))
for root, dirs, files in os.walk("."):
for f in files:
INSTALL_FILES += [os.path.join(root[2:], f)]
INSTALL_DIRS += [root[2:]]
print "Found {} files in {} folders to install.".format(len(INSTALL_FILES),
len(INSTALL_DIRS))
# Get git tag or VERSION
try:
process = Popen(["git", "describe", "--tags"], stdout=PIPE)
(output, err) = process.communicate()
exit_code = process.wait()
except OSError:
raise Exception("Cannot run git: Git is required to generate installer!")
VERSION = output.strip()
print "Cfclient version {}".format(VERSION)
os.chdir(os.path.dirname(__file__))
with open("cfclient.nsi.tmpl", "r") as template_file:
TEMPLATE = template_file.read()
TMPL = jinja2.Template(TEMPLATE)
with open("cfclient.nsi", "w") as out_file:
out_file.write(TMPL.render(files=INSTALL_FILES,
dirs=INSTALL_DIRS,
version=VERSION))
| gpl-2.0 | [
646,
10321,
18,
199,
646,
747,
199,
504,
3873,
492,
13995,
12,
22773,
199,
199,
13783,
63,
3243,
275,
21777,
60,
2686,
2,
199,
199,
3,
2372,
769,
402,
1584,
436,
2082,
370,
3907,
15,
19502,
199,
16811,
63,
9472,
275,
942,
199,
16811,
63,
14455,
275,
942,
199,
199,
736,
14,
8563,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
28424,
63,
3243,
430,
199,
509,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
480,
30946,
272,
367,
289,
315,
1584,
26,
267,
20514,
1761,
63,
9472,
847,
359,
736,
14,
515,
14,
904,
8,
1231,
59,
18,
8429,
289,
1874,
272,
20514,
1761,
63,
14455,
847,
359,
1231,
59,
18,
21316,
199,
199,
1361,
298,
3601,
1052,
1584,
315,
1052,
16533,
370,
3907,
15848,
908,
8,
552,
8,
16811,
63,
9472,
395,
9144,
822,
8,
16811,
63,
14455,
430,
421,
199,
3,
2372,
6135,
1947,
503,
15945,
199,
893,
26,
272,
2112,
275,
13995,
5234,
3187,
401,
298,
11935,
401,
4320,
2969,
2255,
3839,
29,
6089,
9,
272,
334,
1199,
12,
2329,
9,
275,
2112,
14,
10664,
342,
272,
4458,
63,
600,
275,
2112,
14,
2573,
342,
199,
2590,
6440,
26,
272,
746,
2186,
480,
6612,
1255,
6135,
26,
12579,
365,
1415,
370,
3550,
18535,
9124,
199,
199,
4612,
275,
1072,
14,
1913,
342,
199,
199,
1361,
298,
24304,
1258,
1015,
8352,
908,
8,
4612,
9,
199,
199,
736,
14,
8563,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
199,
1045,
1551,
480,
2177,
1258,
14,
78,
338,
14,
11510,
401,
298,
82,
531,
465,
1978,
63,
493,
26,
272,
24877,
275,
1978,
63,
493,
14,
739,
342,
199,
199,
23719,
275,
10321,
18,
14,
4231,
8,
7433,
9,
199,
199,
1045,
1551,
480,
2177,
1258,
14,
78,
338,
401,
298,
87,
531,
465,
734,
63,
493,
26,
272,
734,
63,
493,
14,
952,
8,
23719,
14,
3352,
8,
1725,
29,
16811,
63,
9472,
12,
3044,
7606,
29,
16811,
63,
14455,
12,
3044,
1015,
29,
4612,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
10321,
18,
199,
646,
747,
199,
504,
3873,
492,
13995,
12,
22773,
199,
199,
13783,
63,
3243,
275,
21777,
60,
2686,
2,
199,
199,
3,
2372,
769,
402,
1584,
436,
2082,
370,
3907,
15,
19502,
199,
16811,
63,
9472,
275,
942,
199,
16811,
63,
14455,
275,
942,
199,
199,
736,
14,
8563,
8,
736,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
28424,
63,
3243,
430,
199,
509,
1738,
12,
7606,
12,
1584,
315,
747,
14,
7757,
480,
30946,
272,
367,
289,
315,
1584,
26,
267,
20514,
1761,
63,
9472,
847,
359,
736,
14,
515,
14,
904,
8,
1231,
59,
18,
8429,
289,
1874,
272,
20514,
1761,
63,
14455,
847,
359,
1231,
59,
18,
21316,
199,
199,
1361,
298,
3601,
1052,
1584,
315,
1052,
16533,
370,
3907,
15848,
908,
8,
552,
8,
16811,
63,
9472,
395,
9144,
822,
8,
16811,
63,
14455,
430,
421,
199,
3,
2372,
6135,
1947,
503,
15945,
199,
893,
26,
272,
2112,
275,
13995,
5234,
3187,
401,
298,
11935,
401,
4320,
2969,
2255,
3839,
29,
6089,
9,
272,
334,
1199,
12,
2329,
9,
275,
2112,
14,
10664,
342,
272,
4458,
63,
600,
275,
2112,
14,
2573,
342,
199,
2590,
6440,
26,
272,
746,
2186,
480,
6612,
1255,
6135,
26,
12579,
365,
1415,
370,
3550,
18535,
9124,
199,
199,
4612,
275,
1072,
14,
1913,
342,
199,
199,
1361,
298,
24304,
1258,
1015,
8352,
908,
8,
4612,
9,
199,
199,
736,
14,
8563,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
199,
199,
1045,
1551,
480,
2177,
1258,
14,
78,
338,
14,
11510,
401,
298,
82,
531,
465,
1978,
63,
493,
26,
272,
24877,
275,
1978,
63,
493,
14,
739,
342,
199,
199,
23719,
275,
10321,
18,
14,
4231,
8,
7433,
9,
199,
199,
1045,
1551,
480,
2177,
1258,
14,
78,
338,
401,
298,
87,
531,
465,
734,
63,
493,
26,
272,
734,
63,
493,
14,
952,
8,
23719,
14,
3352,
8,
1725,
29,
16811,
63,
9472,
12,
3044,
7606,
29,
16811,
63,
14455,
12,
3044,
1015,
29,
4612,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0
] |
waynenilsen/statsmodels | statsmodels/examples/ex_kde_confint.py | 34 | 1973 | # -*- coding: utf-8 -*-
"""
Created on Mon Dec 16 11:02:59 2013
Author: Josef Perktold
"""
from __future__ import print_function
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
import statsmodels.nonparametric.api as npar
from statsmodels.sandbox.nonparametric import kernels
from statsmodels.distributions.mixture_rvs import mixture_rvs
# example from test_kde.py mixture of two normal distributions
np.random.seed(12345)
x = mixture_rvs([.25,.75], size=200, dist=[stats.norm, stats.norm],
kwargs = (dict(loc=-1, scale=.5),dict(loc=1, scale=.5)))
x.sort() # not needed
kde = npar.KDEUnivariate(x)
kde.fit('gau')
ci = kde.kernel.density_confint(kde.density, len(x))
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.hist(x, bins=15, normed=True, alpha=0.25)
ax.plot(kde.support, kde.density, lw=2, color='red')
ax.fill_between(kde.support, ci[:,0], ci[:,1],
color='grey', alpha='0.7')
ax.set_title('Kernel Density Gaussian (bw = %4.2f)' % kde.bw)
# use all kernels directly
x_grid = np.linspace(np.min(x), np.max(x), 51)
x_grid = np.linspace(-3, 3, 51)
kernel_names = ['Biweight', 'Cosine', 'Epanechnikov', 'Gaussian',
'Triangular', 'Triweight', #'Uniform',
]
fig = plt.figure()
for ii, kn in enumerate(kernel_names):
ax = fig.add_subplot(2, 3, ii+1) # without uniform
ax.hist(x, bins=10, normed=True, alpha=0.25)
#reduce bandwidth for Gaussian and Uniform which are to large in example
if kn in ['Gaussian', 'Uniform']:
args = (0.5,)
else:
args = ()
kernel = getattr(kernels, kn)(*args)
kde_grid = [kernel.density(x, xi) for xi in x_grid]
confint_grid = kernel.density_confint(kde_grid, len(x))
ax.plot(x_grid, kde_grid, lw=2, color='red', label=kn)
ax.fill_between(x_grid, confint_grid[:,0], confint_grid[:,1],
color='grey', alpha='0.7')
ax.legend(loc='upper left')
plt.show()
| bsd-3-clause | [
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
199,
10502,
641,
10953,
13966,
3193,
4119,
26,
996,
26,
1427,
6171,
199,
199,
5949,
26,
1603,
3362,
70,
3492,
5973,
1753,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
2680,
465,
980,
199,
504,
7026,
492,
5020,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
5020,
992,
14,
2865,
9727,
67,
14,
1246,
465,
302,
462,
199,
504,
5020,
992,
14,
16647,
14,
2865,
9727,
67,
492,
26091,
199,
504,
5020,
992,
14,
5613,
14,
2664,
4167,
63,
23322,
492,
31885,
63,
23322,
199,
199,
3,
2893,
687,
511,
63,
29461,
14,
647,
31885,
402,
2877,
3293,
10208,
199,
1590,
14,
2355,
14,
5176,
8,
13261,
9,
199,
88,
275,
31885,
63,
23322,
779,
14,
821,
18485,
2194,
467,
1568,
29,
1840,
12,
2917,
1524,
3200,
14,
4791,
12,
5020,
14,
4791,
467,
355,
2074,
275,
334,
807,
8,
2102,
4022,
17,
12,
4666,
15856,
21,
395,
807,
8,
2102,
29,
17,
12,
4666,
15856,
21,
1724,
199,
199,
88,
14,
3191,
342,
327,
440,
4346,
199,
199,
29461,
275,
302,
462,
14,
43,
1093,
1358,
23225,
8,
88,
9,
199,
29461,
14,
3269,
360,
16750,
358,
199,
559,
275,
1022,
271,
14,
4989,
14,
15669,
63,
2190,
442,
8,
29461,
14,
15669,
12,
822,
8,
88,
430,
199,
199,
592,
275,
4488,
14,
8941,
342,
199,
1219,
275,
6085,
14,
525,
63,
13334,
8,
17,
12,
413,
12,
413,
9,
199,
1219,
14,
11141,
8,
88,
12,
13341,
29,
1046,
12,
6590,
3594,
29,
549,
12,
5131,
29,
16,
14,
821,
9,
199,
1219,
14,
2798,
8,
29461,
14,
4058,
12,
1022,
271,
14,
15669,
12,
20482,
29,
18,
12,
3164,
534,
581,
358,
199,
1219,
14,
4498,
63,
13007,
8,
29461,
14,
4058,
12,
16279,
3981,
16,
467,
16279,
3981,
17,
467,
490,
3164,
534,
16708,
297,
5131,
534,
16,
14,
23,
358,
199,
1219,
14,
409,
63,
1213,
360,
14127,
25187,
3677,
17131,
334,
12415,
275,
450,
20,
14,
18,
70,
3171,
450,
1022,
271,
14,
12415,
9,
421,
199,
3,
675,
1006,
26091,
5370,
199,
199,
88,
63,
3825,
275,
980,
14,
11649,
8,
1590,
14,
827,
8,
88,
395,
980,
14,
988,
8,
88,
395,
8026,
9,
199,
88,
63,
3825,
275,
980,
14,
11649,
2801,
19,
12,
650,
12,
8026,
9,
199,
199,
4989,
63,
1247,
275,
788,
17975,
3463,
297,
283,
26253,
1132,
297,
283,
14057,
5865,
11019,
3258,
8822,
297,
283,
26756,
297,
355,
283,
23341,
297,
283,
6948,
3463,
297,
17384,
12421,
297,
355,
1622,
199,
199,
592,
275,
4488,
14,
8941,
342,
199,
509,
15393,
12,
1022,
78,
315,
3874,
8,
4989,
63,
1247,
304,
272,
2185,
275,
6085,
14,
525,
63,
13334,
8,
18,
12,
650,
12,
15393,
11,
17,
9,
257,
327,
1928,
14818,
272,
2185,
14,
11141,
8,
88,
12,
13341,
29,
709,
12,
6590,
3594,
29,
549,
12,
5131,
29,
16,
14,
821,
9,
272,
327,
5270,
20434,
367,
17131,
436,
1910,
8241,
1314,
787,
370,
7031,
315,
2893,
272,
340,
1022,
78,
315,
788,
26756,
297,
283,
12421,
2565,
267,
1249,
275,
334,
16,
14,
21,
4258,
272,
587,
26,
267,
1249,
275,
6248,
272,
5114,
275,
2519,
8,
29824,
12,
1022,
78,
25967,
589,
9,
339,
1022,
271,
63,
3825,
275,
359,
4989,
14,
15669,
8,
88,
12,
19905,
9,
367,
19905,
315,
671,
63,
3825,
61,
272,
3743,
442,
63,
3825,
275,
5114,
14,
15669,
63,
2190,
442,
8,
29461,
63,
3825,
12,
822,
8,
88,
430,
339,
2185,
14,
2798,
8,
88,
63,
3825,
12,
1022,
271,
63,
3825,
12,
20482,
29,
18,
12,
3164,
534,
581,
297,
1768,
29,
18974,
9,
272,
2185,
14,
4498,
63,
13007,
8,
88,
63,
3825,
12,
3743,
442,
63,
3825,
3981,
16,
467,
3743,
442,
63,
3825,
3981,
17,
467,
490,
3164,
534,
16708,
297,
5131,
534,
16,
14,
23,
358,
272,
2185,
14,
10231,
8,
2102,
534,
4142,
3602,
358,
199,
199,
6003,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
199,
10502,
641,
10953,
13966,
3193,
4119,
26,
996,
26,
1427,
6171,
199,
199,
5949,
26,
1603,
3362,
70,
3492,
5973,
1753,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
646,
2680,
465,
980,
199,
504,
7026,
492,
5020,
199,
646,
8027,
14,
13563,
465,
4488,
199,
646,
5020,
992,
14,
2865,
9727,
67,
14,
1246,
465,
302,
462,
199,
504,
5020,
992,
14,
16647,
14,
2865,
9727,
67,
492,
26091,
199,
504,
5020,
992,
14,
5613,
14,
2664,
4167,
63,
23322,
492,
31885,
63,
23322,
199,
199,
3,
2893,
687,
511,
63,
29461,
14,
647,
31885,
402,
2877,
3293,
10208,
199,
1590,
14,
2355,
14,
5176,
8,
13261,
9,
199,
88,
275,
31885,
63,
23322,
779,
14,
821,
18485,
2194,
467,
1568,
29,
1840,
12,
2917,
1524,
3200,
14,
4791,
12,
5020,
14,
4791,
467,
355,
2074,
275,
334,
807,
8,
2102,
4022,
17,
12,
4666,
15856,
21,
395,
807,
8,
2102,
29,
17,
12,
4666,
15856,
21,
1724,
199,
199,
88,
14,
3191,
342,
327,
440,
4346,
199,
199,
29461,
275,
302,
462,
14,
43,
1093,
1358,
23225,
8,
88,
9,
199,
29461,
14,
3269,
360,
16750,
358,
199,
559,
275,
1022,
271,
14,
4989,
14,
15669,
63,
2190,
442,
8,
29461,
14,
15669,
12,
822,
8,
88,
430,
199,
199,
592,
275,
4488,
14,
8941,
342,
199,
1219,
275,
6085,
14,
525,
63,
13334,
8,
17,
12,
413,
12,
413,
9,
199,
1219,
14,
11141,
8,
88,
12,
13341,
29,
1046,
12,
6590,
3594,
29,
549,
12,
5131,
29,
16,
14,
821,
9,
199,
1219,
14,
2798,
8,
29461,
14,
4058,
12,
1022,
271,
14,
15669,
12,
20482,
29,
18,
12,
3164,
534,
581,
358,
199,
1219,
14,
4498,
63,
13007,
8,
29461,
14,
4058,
12,
16279,
3981,
16,
467,
16279,
3981,
17,
467,
490,
3164,
534,
16708,
297,
5131,
534,
16,
14,
23,
358,
199,
1219,
14,
409,
63,
1213,
360,
14127,
25187,
3677,
17131,
334,
12415,
275,
450,
20,
14,
18,
70,
3171,
450,
1022,
271,
14,
12415,
9,
421,
199,
3,
675,
1006,
26091,
5370,
199,
199,
88,
63,
3825,
275,
980,
14,
11649,
8,
1590,
14,
827,
8,
88,
395,
980,
14,
988,
8,
88,
395,
8026,
9,
199,
88,
63,
3825,
275,
980,
14,
11649,
2801,
19,
12,
650,
12,
8026,
9,
199,
199,
4989,
63,
1247,
275,
788,
17975,
3463,
297,
283,
26253,
1132,
297,
283,
14057,
5865,
11019,
3258,
8822,
297,
283,
26756,
297,
355,
283,
23341,
297,
283,
6948,
3463,
297,
17384,
12421,
297,
355,
1622,
199,
199,
592,
275,
4488,
14,
8941,
342,
199,
509,
15393,
12,
1022,
78,
315,
3874,
8,
4989,
63,
1247,
304,
272,
2185,
275,
6085,
14,
525,
63,
13334,
8,
18,
12,
650,
12,
15393,
11,
17,
9,
257,
327,
1928,
14818,
272,
2185,
14,
11141,
8,
88,
12,
13341,
29,
709,
12,
6590,
3594,
29,
549,
12,
5131,
29,
16,
14,
821,
9,
272,
327,
5270,
20434,
367,
17131,
436,
1910,
8241,
1314,
787,
370,
7031,
315,
2893,
272,
340,
1022,
78,
315,
788,
26756,
297,
283,
12421,
2565,
267,
1249,
275,
334,
16,
14,
21,
4258,
272,
587,
26,
267,
1249,
275,
6248,
272,
5114,
275,
2519,
8,
29824,
12,
1022,
78,
25967,
589,
9,
339,
1022,
271,
63,
3825,
275,
359,
4989,
14,
15669,
8,
88,
12,
19905,
9,
367,
19905,
315,
671,
63,
3825,
61,
272,
3743,
442,
63,
3825,
275,
5114,
14,
15669,
63,
2190,
442,
8,
29461,
63,
3825,
12,
822,
8,
88,
430,
339,
2185,
14,
2798,
8,
88,
63,
3825,
12,
1022,
271,
63,
3825,
12,
20482,
29,
18,
12,
3164,
534,
581,
297,
1768,
29,
18974,
9,
272,
2185,
14,
4498,
63,
13007,
8,
88,
63,
3825,
12,
3743,
442,
63,
3825,
3981,
16,
467,
3743,
442,
63,
3825,
3981,
17,
467,
490,
3164,
534,
16708,
297,
5131,
534,
16,
14,
23,
358,
272,
2185,
14,
10231,
8,
2102,
534,
4142,
3602,
358,
199,
199,
6003,
14,
2384,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
uni2u/neutron | neutron/tests/unit/test_db_migration.py | 14 | 8272 | # Copyright 2012 New Dream Network, LLC (DreamHost)
# 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 sys
import mock
from neutron.db import migration
from neutron.db.migration import cli
from neutron.tests import base
class TestDbMigration(base.BaseTestCase):
def setUp(self):
super(TestDbMigration, self).setUp()
mock.patch('alembic.op.get_bind').start()
self.mock_alembic_is_offline = mock.patch(
'alembic.context.is_offline_mode', return_value=False).start()
self.mock_alembic_is_offline.return_value = False
self.mock_sa_inspector = mock.patch(
'sqlalchemy.engine.reflection.Inspector').start()
def _prepare_mocked_sqlalchemy_inspector(self):
mock_inspector = mock.MagicMock()
mock_inspector.get_table_names.return_value = ['foo', 'bar']
mock_inspector.get_columns.return_value = [{'name': 'foo_column'},
{'name': 'bar_column'}]
self.mock_sa_inspector.from_engine.return_value = mock_inspector
def test_schema_has_table(self):
self._prepare_mocked_sqlalchemy_inspector()
self.assertTrue(migration.schema_has_table('foo'))
def test_schema_has_table_raises_if_offline(self):
self.mock_alembic_is_offline.return_value = True
self.assertRaises(RuntimeError, migration.schema_has_table, 'foo')
def test_schema_has_column_missing_table(self):
self._prepare_mocked_sqlalchemy_inspector()
self.assertFalse(migration.schema_has_column('meh', 'meh'))
def test_schema_has_column(self):
self._prepare_mocked_sqlalchemy_inspector()
self.assertTrue(migration.schema_has_column('foo', 'foo_column'))
def test_schema_has_column_raises_if_offline(self):
self.mock_alembic_is_offline.return_value = True
self.assertRaises(RuntimeError, migration.schema_has_column,
'foo', 'foo_col')
def test_schema_has_column_missing_column(self):
self._prepare_mocked_sqlalchemy_inspector()
self.assertFalse(migration.schema_has_column(
'foo', column_name='meh'))
class TestCli(base.BaseTestCase):
def setUp(self):
super(TestCli, self).setUp()
self.do_alembic_cmd_p = mock.patch.object(cli, 'do_alembic_command')
self.do_alembic_cmd = self.do_alembic_cmd_p.start()
self.mock_alembic_err = mock.patch('alembic.util.err').start()
self.mock_alembic_err.side_effect = SystemExit
def _main_test_helper(self, argv, func_name, exp_args=(), exp_kwargs={}):
with mock.patch.object(sys, 'argv', argv):
cli.main()
self.do_alembic_cmd.assert_has_calls(
[mock.call(mock.ANY, func_name, *exp_args, **exp_kwargs)]
)
def test_stamp(self):
self._main_test_helper(
['prog', 'stamp', 'foo'],
'stamp',
('foo',),
{'sql': False}
)
self._main_test_helper(
['prog', 'stamp', 'foo', '--sql'],
'stamp',
('foo',),
{'sql': True}
)
def test_current(self):
self._main_test_helper(['prog', 'current'], 'current')
def test_history(self):
self._main_test_helper(['prog', 'history'], 'history')
def test_check_migration(self):
with mock.patch.object(cli, 'validate_head_file') as validate:
self._main_test_helper(['prog', 'check_migration'], 'branches')
validate.assert_called_once_with(mock.ANY)
def test_database_sync_revision(self):
with mock.patch.object(cli, 'update_head_file') as update:
self._main_test_helper(
['prog', 'revision', '--autogenerate', '-m', 'message'],
'revision',
(),
{'message': 'message', 'sql': False, 'autogenerate': True}
)
update.assert_called_once_with(mock.ANY)
update.reset_mock()
self._main_test_helper(
['prog', 'revision', '--sql', '-m', 'message'],
'revision',
(),
{'message': 'message', 'sql': True, 'autogenerate': False}
)
update.assert_called_once_with(mock.ANY)
def test_upgrade(self):
self._main_test_helper(
['prog', 'upgrade', '--sql', 'head'],
'upgrade',
('head',),
{'sql': True}
)
self._main_test_helper(
['prog', 'upgrade', '--delta', '3'],
'upgrade',
('+3',),
{'sql': False}
)
def test_downgrade(self):
self._main_test_helper(
['prog', 'downgrade', '--sql', 'folsom'],
'downgrade',
('folsom',),
{'sql': True}
)
self._main_test_helper(
['prog', 'downgrade', '--delta', '2'],
'downgrade',
('-2',),
{'sql': False}
)
def _test_validate_head_file_helper(self, heads, file_content=None):
with mock.patch('alembic.script.ScriptDirectory.from_config') as fc:
fc.return_value.get_heads.return_value = heads
fc.return_value.get_current_head.return_value = heads[0]
with mock.patch('__builtin__.open') as mock_open:
mock_open.return_value.__enter__ = lambda s: s
mock_open.return_value.__exit__ = mock.Mock()
mock_open.return_value.read.return_value = file_content
with mock.patch('os.path.isfile') as is_file:
is_file.return_value = file_content is not None
if file_content in heads:
cli.validate_head_file(mock.sentinel.config)
else:
self.assertRaises(
SystemExit,
cli.validate_head_file,
mock.sentinel.config
)
self.mock_alembic_err.assert_called_once_with(mock.ANY)
fc.assert_called_once_with(mock.sentinel.config)
def test_validate_head_file_multiple_heads(self):
self._test_validate_head_file_helper(['a', 'b'])
def test_validate_head_file_missing_file(self):
self._test_validate_head_file_helper(['a'])
def test_validate_head_file_wrong_contents(self):
self._test_validate_head_file_helper(['a'], 'b')
def test_validate_head_success(self):
self._test_validate_head_file_helper(['a'], 'a')
def test_update_head_file_multiple_heads(self):
with mock.patch('alembic.script.ScriptDirectory.from_config') as fc:
fc.return_value.get_heads.return_value = ['a', 'b']
self.assertRaises(
SystemExit,
cli.update_head_file,
mock.sentinel.config
)
self.mock_alembic_err.assert_called_once_with(mock.ANY)
fc.assert_called_once_with(mock.sentinel.config)
def test_update_head_file_success(self):
with mock.patch('alembic.script.ScriptDirectory.from_config') as fc:
fc.return_value.get_heads.return_value = ['a']
fc.return_value.get_current_head.return_value = 'a'
with mock.patch('__builtin__.open') as mock_open:
mock_open.return_value.__enter__ = lambda s: s
mock_open.return_value.__exit__ = mock.Mock()
cli.update_head_file(mock.sentinel.config)
mock_open.return_value.write.assert_called_once_with('a')
fc.assert_called_once_with(mock.sentinel.config)
| apache-2.0 | [
3,
1898,
6029,
7053,
577,
1091,
7220,
12,
20376,
334,
36,
1091,
4965,
9,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
984,
199,
199,
646,
1683,
199,
199,
504,
8224,
14,
697,
492,
8367,
199,
504,
8224,
14,
697,
14,
8998,
492,
5053,
199,
504,
8224,
14,
2219,
492,
1300,
421,
199,
533,
1379,
8882,
9816,
8,
1095,
14,
20760,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
8882,
9816,
12,
291,
680,
5996,
342,
267,
1683,
14,
2068,
360,
1895,
20596,
14,
411,
14,
362,
63,
3409,
1959,
928,
342,
267,
291,
14,
1805,
63,
1895,
20596,
63,
374,
63,
18430,
275,
1683,
14,
2068,
8,
288,
283,
1895,
20596,
14,
1100,
14,
374,
63,
18430,
63,
632,
297,
372,
63,
585,
29,
797,
680,
928,
342,
267,
291,
14,
1805,
63,
1895,
20596,
63,
374,
63,
18430,
14,
1107,
63,
585,
275,
756,
267,
291,
14,
1805,
63,
2231,
63,
26047,
275,
1683,
14,
2068,
8,
288,
283,
14536,
14,
3908,
14,
14906,
14,
13962,
15152,
1959,
928,
342,
339,
347,
485,
6726,
63,
27740,
63,
14536,
63,
26047,
8,
277,
304,
267,
1683,
63,
26047,
275,
1683,
14,
11988,
342,
267,
1683,
63,
26047,
14,
362,
63,
1224,
63,
1247,
14,
1107,
63,
585,
275,
788,
1421,
297,
283,
1700,
418,
267,
1683,
63,
26047,
14,
362,
63,
3406,
14,
1107,
63,
585,
275,
9016,
354,
356,
283,
1421,
63,
2301,
2267,
8962,
791,
354,
356,
283,
1700,
63,
2301,
20623,
267,
291,
14,
1805,
63,
2231,
63,
26047,
14,
504,
63,
3908,
14,
1107,
63,
585,
275,
1683,
63,
26047,
339,
347,
511,
63,
3629,
63,
1989,
63,
1224,
8,
277,
304,
267,
291,
423,
6726,
63,
27740,
63,
14536,
63,
26047,
342,
267,
291,
14,
1815,
8,
8998,
14,
3629,
63,
1989,
63,
1224,
360,
1421,
1333,
339,
347,
511,
63,
3629,
63,
1989,
63,
1224,
63,
3536,
63,
692,
63,
18430,
8,
277,
304,
267,
291,
14,
1805,
63,
1895,
20596,
63,
374,
63,
18430,
14,
1107,
63,
585,
275,
715,
267,
291,
14,
1855,
8,
13281,
12,
8367,
14,
3629,
63,
1989,
63,
1224,
12,
283,
1421,
358,
339,
347,
511,
63,
3629,
63,
1989,
63,
2301,
63,
4752,
63,
1224,
8,
277,
304,
267,
291,
423,
6726,
63,
27740,
63,
14536,
63,
26047,
342,
267,
291,
14,
3334,
8,
8998,
14,
3629,
63,
1989,
63,
2301,
360,
278,
72,
297,
283,
278,
72,
1333,
339,
347,
511,
63,
3629,
63,
1989,
63,
2301,
8,
277,
304,
267,
291,
423,
6726,
63,
27740,
63,
14536,
63,
26047,
342,
267,
291,
14,
1815,
8,
8998,
14,
3629,
63,
1989,
63,
2301,
360,
1421,
297,
283,
1421,
63,
2301,
1333,
339,
347,
511,
63,
3629,
63,
1989,
63,
2301,
63,
3536,
63,
692,
63,
18430,
8,
277,
304,
267,
291,
14,
1805,
63,
1895,
20596,
63,
374,
63,
18430,
14,
1107,
63,
585,
275,
715,
267,
291,
14,
1855,
8,
13281,
12,
8367,
14,
3629,
63,
1989,
63,
2301,
12,
2079,
283,
1421,
297,
283,
1421,
63,
761,
358,
339,
347,
511,
63,
3629,
63,
1989,
63,
2301,
63,
4752,
63,
2301,
8,
277,
304,
267,
291,
423,
6726,
63,
27740,
63,
14536,
63,
26047,
342,
267,
291,
14,
3334,
8,
8998,
14,
3629,
63,
1989,
63,
2301,
8,
288,
283,
1421,
297,
2763,
63,
354,
534,
278,
72,
1333,
421,
199,
533,
1379,
20653,
8,
1095,
14,
20760,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
20653,
12,
291,
680,
5996,
342,
267,
291,
14,
1117,
63,
1895,
20596,
63,
1760,
63,
80,
275,
1683,
14,
2068,
14,
785,
8,
2764,
12,
283,
1117,
63,
1895,
20596,
63,
1531,
358,
267,
291,
14,
1117,
63,
1895,
20596,
63,
1760,
275,
291,
14,
1117,
63,
1895,
20596,
63,
1760,
63,
80,
14,
928,
342,
267,
291,
14,
1805,
63,
1895,
20596,
63,
1508,
275,
1683,
14,
2068,
360,
1895,
20596,
14,
1974,
14,
1508,
1959,
928,
342,
267,
291,
14,
1805,
63,
1895,
20596,
63,
1508,
14,
2441,
63,
5881,
275,
14838,
339,
347,
485,
973,
63,
396,
63,
3676,
8,
277,
12,
9238,
12,
2562,
63,
354,
12,
1437,
63,
589,
16729,
1437,
63,
958,
16420,
267,
543,
1683,
14,
2068,
14,
785,
8,
1274,
12,
283,
3020,
297,
9238,
304,
288,
5053,
14,
973,
342,
288,
291,
14,
1117,
63,
1895,
20596,
63,
1760,
14,
479,
63,
1989,
63,
5352,
8,
355,
359,
1805,
14,
1250,
8,
1805,
14,
8974,
12,
2562,
63,
354,
12,
627,
1474,
63,
589,
12,
1011,
1474,
63,
958,
1874,
288,
776,
339,
347,
511,
63,
2359,
8,
277,
304,
267,
291,
423,
973,
63,
396,
63,
3676,
8,
288,
788,
6595,
297,
283,
2359,
297,
283,
1421,
995,
288,
283,
2359,
297,
288,
661,
1421,
5529,
288,
791,
3009,
356,
756,
93,
267,
776,
398,
291,
423,
973,
63,
396,
63,
3676,
8,
288,
788,
6595,
297,
283,
2359,
297,
283,
1421,
297,
2850,
3009,
995,
288,
283,
2359,
297,
288,
661,
1421,
5529,
288,
791,
3009,
356,
715,
93,
267,
776,
339,
347,
511,
63,
1818,
8,
277,
304,
267,
291,
423,
973,
63,
396,
63,
3676,
2941,
6595,
297,
283,
1818,
995,
283,
1818,
358,
339,
347,
511,
63,
5570,
8,
277,
304,
267,
291,
423,
973,
63,
396,
63,
3676,
2941
] | [
1898,
6029,
7053,
577,
1091,
7220,
12,
20376,
334,
36,
1091,
4965,
9,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
984,
199,
199,
646,
1683,
199,
199,
504,
8224,
14,
697,
492,
8367,
199,
504,
8224,
14,
697,
14,
8998,
492,
5053,
199,
504,
8224,
14,
2219,
492,
1300,
421,
199,
533,
1379,
8882,
9816,
8,
1095,
14,
20760,
304,
339,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
8882,
9816,
12,
291,
680,
5996,
342,
267,
1683,
14,
2068,
360,
1895,
20596,
14,
411,
14,
362,
63,
3409,
1959,
928,
342,
267,
291,
14,
1805,
63,
1895,
20596,
63,
374,
63,
18430,
275,
1683,
14,
2068,
8,
288,
283,
1895,
20596,
14,
1100,
14,
374,
63,
18430,
63,
632,
297,
372,
63,
585,
29,
797,
680,
928,
342,
267,
291,
14,
1805,
63,
1895,
20596,
63,
374,
63,
18430,
14,
1107,
63,
585,
275,
756,
267,
291,
14,
1805,
63,
2231,
63,
26047,
275,
1683,
14,
2068,
8,
288,
283,
14536,
14,
3908,
14,
14906,
14,
13962,
15152,
1959,
928,
342,
339,
347,
485,
6726,
63,
27740,
63,
14536,
63,
26047,
8,
277,
304,
267,
1683,
63,
26047,
275,
1683,
14,
11988,
342,
267,
1683,
63,
26047,
14,
362,
63,
1224,
63,
1247,
14,
1107,
63,
585,
275,
788,
1421,
297,
283,
1700,
418,
267,
1683,
63,
26047,
14,
362,
63,
3406,
14,
1107,
63,
585,
275,
9016,
354,
356,
283,
1421,
63,
2301,
2267,
8962,
791,
354,
356,
283,
1700,
63,
2301,
20623,
267,
291,
14,
1805,
63,
2231,
63,
26047,
14,
504,
63,
3908,
14,
1107,
63,
585,
275,
1683,
63,
26047,
339,
347,
511,
63,
3629,
63,
1989,
63,
1224,
8,
277,
304,
267,
291,
423,
6726,
63,
27740,
63,
14536,
63,
26047,
342,
267,
291,
14,
1815,
8,
8998,
14,
3629,
63,
1989,
63,
1224,
360,
1421,
1333,
339,
347,
511,
63,
3629,
63,
1989,
63,
1224,
63,
3536,
63,
692,
63,
18430,
8,
277,
304,
267,
291,
14,
1805,
63,
1895,
20596,
63,
374,
63,
18430,
14,
1107,
63,
585,
275,
715,
267,
291,
14,
1855,
8,
13281,
12,
8367,
14,
3629,
63,
1989,
63,
1224,
12,
283,
1421,
358,
339,
347,
511,
63,
3629,
63,
1989,
63,
2301,
63,
4752,
63,
1224,
8,
277,
304,
267,
291,
423,
6726,
63,
27740,
63,
14536,
63,
26047,
342,
267,
291,
14,
3334,
8,
8998,
14,
3629,
63,
1989,
63,
2301,
360,
278,
72,
297,
283,
278,
72,
1333,
339,
347,
511,
63,
3629,
63,
1989,
63,
2301,
8,
277,
304,
267,
291,
423,
6726,
63,
27740,
63,
14536,
63,
26047,
342,
267,
291,
14,
1815,
8,
8998,
14,
3629,
63,
1989,
63,
2301,
360,
1421,
297,
283,
1421,
63,
2301,
1333,
339,
347,
511,
63,
3629,
63,
1989,
63,
2301,
63,
3536,
63,
692,
63,
18430,
8,
277,
304,
267,
291,
14,
1805,
63,
1895,
20596,
63,
374,
63,
18430,
14,
1107,
63,
585,
275,
715,
267,
291,
14,
1855,
8,
13281,
12,
8367,
14,
3629,
63,
1989,
63,
2301,
12,
2079,
283,
1421,
297,
283,
1421,
63,
761,
358,
339,
347,
511,
63,
3629,
63,
1989,
63,
2301,
63,
4752,
63,
2301,
8,
277,
304,
267,
291,
423,
6726,
63,
27740,
63,
14536,
63,
26047,
342,
267,
291,
14,
3334,
8,
8998,
14,
3629,
63,
1989,
63,
2301,
8,
288,
283,
1421,
297,
2763,
63,
354,
534,
278,
72,
1333,
421,
199,
533,
1379,
20653,
8,
1095,
14,
20760,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
20653,
12,
291,
680,
5996,
342,
267,
291,
14,
1117,
63,
1895,
20596,
63,
1760,
63,
80,
275,
1683,
14,
2068,
14,
785,
8,
2764,
12,
283,
1117,
63,
1895,
20596,
63,
1531,
358,
267,
291,
14,
1117,
63,
1895,
20596,
63,
1760,
275,
291,
14,
1117,
63,
1895,
20596,
63,
1760,
63,
80,
14,
928,
342,
267,
291,
14,
1805,
63,
1895,
20596,
63,
1508,
275,
1683,
14,
2068,
360,
1895,
20596,
14,
1974,
14,
1508,
1959,
928,
342,
267,
291,
14,
1805,
63,
1895,
20596,
63,
1508,
14,
2441,
63,
5881,
275,
14838,
339,
347,
485,
973,
63,
396,
63,
3676,
8,
277,
12,
9238,
12,
2562,
63,
354,
12,
1437,
63,
589,
16729,
1437,
63,
958,
16420,
267,
543,
1683,
14,
2068,
14,
785,
8,
1274,
12,
283,
3020,
297,
9238,
304,
288,
5053,
14,
973,
342,
288,
291,
14,
1117,
63,
1895,
20596,
63,
1760,
14,
479,
63,
1989,
63,
5352,
8,
355,
359,
1805,
14,
1250,
8,
1805,
14,
8974,
12,
2562,
63,
354,
12,
627,
1474,
63,
589,
12,
1011,
1474,
63,
958,
1874,
288,
776,
339,
347,
511,
63,
2359,
8,
277,
304,
267,
291,
423,
973,
63,
396,
63,
3676,
8,
288,
788,
6595,
297,
283,
2359,
297,
283,
1421,
995,
288,
283,
2359,
297,
288,
661,
1421,
5529,
288,
791,
3009,
356,
756,
93,
267,
776,
398,
291,
423,
973,
63,
396,
63,
3676,
8,
288,
788,
6595,
297,
283,
2359,
297,
283,
1421,
297,
2850,
3009,
995,
288,
283,
2359,
297,
288,
661,
1421,
5529,
288,
791,
3009,
356,
715,
93,
267,
776,
339,
347,
511,
63,
1818,
8,
277,
304,
267,
291,
423,
973,
63,
396,
63,
3676,
2941,
6595,
297,
283,
1818,
995,
283,
1818,
358,
339,
347,
511,
63,
5570,
8,
277,
304,
267,
291,
423,
973,
63,
396,
63,
3676,
2941,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
da-anda/xbmc | lib/libUPnP/Platinum/Build/Tools/SCons/gcc-generic.py | 283 | 1317 | import os
def generate(env, gcc_cross_prefix=None, gcc_strict=True, gcc_stop_on_warning=None, gcc_extra_options=''):
if gcc_stop_on_warning == None: gcc_stop_on_warning = env['stop_on_warning']
### compiler flags
if gcc_strict:
env.AppendUnique(CCFLAGS = ['-pedantic', '-Wall', '-W', '-Wundef', '-Wno-long-long'])
env.AppendUnique(CFLAGS = ['-Wmissing-prototypes', '-Wmissing-declarations'])
else:
env.AppendUnique(CCFLAGS = ['-Wall'])
compiler_defines = ['-D_REENTRANT']
env.AppendUnique(CCFLAGS = compiler_defines)
env.AppendUnique(CPPFLAGS = compiler_defines)
if env['build_config'] == 'Debug':
env.AppendUnique(CCFLAGS = '-g')
else:
env.AppendUnique(CCFLAGS = '-O3')
if gcc_stop_on_warning:
env.AppendUnique(CCFLAGS = ['-Werror'])
env['STRIP'] = 'strip'
if gcc_cross_prefix:
env['ENV']['PATH'] += os.environ['PATH']
env['AR'] = gcc_cross_prefix+'-ar'
env['RANLIB'] = gcc_cross_prefix+'-ranlib'
env['CC'] = gcc_cross_prefix+'-gcc ' + gcc_extra_options
env['CXX'] = gcc_cross_prefix+'-g++ ' + gcc_extra_options
env['LINK'] = gcc_cross_prefix+'-g++ ' + gcc_extra_options
env['STRIP'] = gcc_cross_prefix+'-strip'
| gpl-2.0 | [
646,
747,
199,
199,
318,
3550,
8,
1813,
12,
19443,
63,
7925,
63,
1861,
29,
403,
12,
19443,
63,
4768,
29,
549,
12,
19443,
63,
2379,
63,
265,
63,
3764,
29,
403,
12,
19443,
63,
2911,
63,
1419,
9280,
272,
340,
19443,
63,
2379,
63,
265,
63,
3764,
508,
488,
26,
19443,
63,
2379,
63,
265,
63,
3764,
275,
2589,
459,
2379,
63,
265,
63,
3764,
418,
20950,
6754,
6365,
3285,
272,
340,
19443,
63,
4768,
26,
267,
2589,
14,
8310,
11427,
8,
2571,
4831,
275,
11573,
1915,
290,
764,
297,
2475,
18018,
297,
221,
2475,
55,
297,
221,
2475,
55,
25878,
297,
2475,
55,
889,
13,
2809,
13,
2809,
1105,
267,
2589,
14,
8310,
11427,
8,
14804,
221,
275,
11573,
55,
4752,
13,
16141,
83,
297,
2475,
55,
4752,
13,
21200,
1105,
272,
587,
26,
267,
2589,
14,
8310,
11427,
8,
2571,
4831,
275,
11573,
18018,
1105,
2286,
6365,
63,
14334,
275,
11573,
36,
63,
907,
1309,
50,
1441,
418,
272,
2589,
14,
8310,
11427,
8,
2571,
4831,
221,
275,
6365,
63,
14334,
9,
272,
2589,
14,
8310,
11427,
8,
14533,
4831,
275,
6365,
63,
14334,
9,
2286,
340,
2589,
459,
1506,
63,
888,
418,
508,
283,
7084,
356,
267,
2589,
14,
8310,
11427,
8,
2571,
4831,
275,
2475,
71,
358,
272,
587,
26,
267,
2589,
14,
8310,
11427,
8,
2571,
4831,
275,
2475,
47,
19,
358,
2286,
340,
19443,
63,
2379,
63,
265,
63,
3764,
26,
267,
2589,
14,
8310,
11427,
8,
2571,
4831,
275,
11573,
55,
705,
1105,
5493,
2589,
459,
31296,
418,
221,
275,
283,
1913,
7,
339,
340,
19443,
63,
7925,
63,
1861,
26,
267,
2589,
459,
9984,
2545,
3243,
418,
847,
747,
14,
2314,
459,
3243,
418,
267,
2589,
459,
689,
418,
258,
275,
19443,
63,
7925,
63,
1861,
4786,
13,
285,
7,
267,
2589,
459,
27644,
5617,
418,
275,
19443,
63,
7925,
63,
1861,
4786,
13,
1312,
773,
7,
267,
2589,
459,
2571,
418,
258,
275,
19443,
63,
7925,
63,
1861,
4786,
13,
13112,
283,
435,
19443,
63,
2911,
63,
1419,
267,
2589,
459,
12206,
418,
259,
275,
19443,
63,
7925,
63,
1861,
4786,
13,
71,
4176,
283,
435,
19443,
63,
2911,
63,
1419,
267,
2589,
459,
7916,
418,
257,
275,
19443,
63,
7925,
63,
1861,
4786,
13,
71,
4176,
283,
435,
19443,
63,
2911,
63,
1419,
267,
2589,
459,
31296,
418,
221,
275,
19443,
63,
7925,
63,
1861,
4786,
13,
1913,
7,
10813,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
747,
199,
199,
318,
3550,
8,
1813,
12,
19443,
63,
7925,
63,
1861,
29,
403,
12,
19443,
63,
4768,
29,
549,
12,
19443,
63,
2379,
63,
265,
63,
3764,
29,
403,
12,
19443,
63,
2911,
63,
1419,
9280,
272,
340,
19443,
63,
2379,
63,
265,
63,
3764,
508,
488,
26,
19443,
63,
2379,
63,
265,
63,
3764,
275,
2589,
459,
2379,
63,
265,
63,
3764,
418,
20950,
6754,
6365,
3285,
272,
340,
19443,
63,
4768,
26,
267,
2589,
14,
8310,
11427,
8,
2571,
4831,
275,
11573,
1915,
290,
764,
297,
2475,
18018,
297,
221,
2475,
55,
297,
221,
2475,
55,
25878,
297,
2475,
55,
889,
13,
2809,
13,
2809,
1105,
267,
2589,
14,
8310,
11427,
8,
14804,
221,
275,
11573,
55,
4752,
13,
16141,
83,
297,
2475,
55,
4752,
13,
21200,
1105,
272,
587,
26,
267,
2589,
14,
8310,
11427,
8,
2571,
4831,
275,
11573,
18018,
1105,
2286,
6365,
63,
14334,
275,
11573,
36,
63,
907,
1309,
50,
1441,
418,
272,
2589,
14,
8310,
11427,
8,
2571,
4831,
221,
275,
6365,
63,
14334,
9,
272,
2589,
14,
8310,
11427,
8,
14533,
4831,
275,
6365,
63,
14334,
9,
2286,
340,
2589,
459,
1506,
63,
888,
418,
508,
283,
7084,
356,
267,
2589,
14,
8310,
11427,
8,
2571,
4831,
275,
2475,
71,
358,
272,
587,
26,
267,
2589,
14,
8310,
11427,
8,
2571,
4831,
275,
2475,
47,
19,
358,
2286,
340,
19443,
63,
2379,
63,
265,
63,
3764,
26,
267,
2589,
14,
8310,
11427,
8,
2571,
4831,
275,
11573,
55,
705,
1105,
5493,
2589,
459,
31296,
418,
221,
275,
283,
1913,
7,
339,
340,
19443,
63,
7925,
63,
1861,
26,
267,
2589,
459,
9984,
2545,
3243,
418,
847,
747,
14,
2314,
459,
3243,
418,
267,
2589,
459,
689,
418,
258,
275,
19443,
63,
7925,
63,
1861,
4786,
13,
285,
7,
267,
2589,
459,
27644,
5617,
418,
275,
19443,
63,
7925,
63,
1861,
4786,
13,
1312,
773,
7,
267,
2589,
459,
2571,
418,
258,
275,
19443,
63,
7925,
63,
1861,
4786,
13,
13112,
283,
435,
19443,
63,
2911,
63,
1419,
267,
2589,
459,
12206,
418,
259,
275,
19443,
63,
7925,
63,
1861,
4786,
13,
71,
4176,
283,
435,
19443,
63,
2911,
63,
1419,
267,
2589,
459,
7916,
418,
257,
275,
19443,
63,
7925,
63,
1861,
4786,
13,
71,
4176,
283,
435,
19443,
63,
2911,
63,
1419,
267,
2589,
459,
31296,
418,
221,
275,
19443,
63,
7925,
63,
1861,
4786,
13,
1913,
7,
10813,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
Pistachitos/Sick-Beard | lib/imdb/utils.py | 50 | 60601 | """
utils module (imdb package).
This module provides basic utilities for the imdb package.
Copyright 2004-2012 Davide Alberani <[email protected]>
2009 H. Turgut Uyar <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
"""
from __future__ import generators
import re
import string
import logging
from copy import copy, deepcopy
from time import strptime, strftime
from imdb import VERSION
from imdb import linguistics
from imdb._exceptions import IMDbParserError
# Logger for imdb.utils module.
_utils_logger = logging.getLogger('imdbpy.utils')
# The regular expression for the "long" year format of IMDb, like
# "(1998)" and "(1986/II)", where the optional roman number (that I call
# "imdbIndex" after the slash is used for movies with the same title
# and year of release.
# XXX: probably L, C, D and M are far too much! ;-)
re_year_index = re.compile(r'\(([0-9\?]{4}(/[IVXLCDM]+)?)\)')
re_extended_year_index = re.compile(r'\((TV episode|TV Series|TV mini-series|TV|Video|Video Game)? ?((?:[0-9\?]{4})(?:-[0-9\?]{4})?)(?:/([IVXLCDM]+)?)?\)')
re_remove_kind = re.compile(r'\((TV episode|TV Series|TV mini-series|TV|Video|Video Game)? ?')
# Match only the imdbIndex (for name strings).
re_index = re.compile(r'^\(([IVXLCDM]+)\)$')
# Match things inside parentheses.
re_parentheses = re.compile(r'(\(.*\))')
# Match the number of episodes.
re_episodes = re.compile('\s?\((\d+) episodes\)', re.I)
re_episode_info = re.compile(r'{\s*(.+?)?\s?(\([0-9\?]{4}-[0-9\?]{1,2}-[0-9\?]{1,2}\))?\s?(\(#[0-9]+\.[0-9]+\))?}')
# Common suffixes in surnames.
_sname_suffixes = ('de', 'la', 'der', 'den', 'del', 'y', 'da', 'van',
'e', 'von', 'the', 'di', 'du', 'el', 'al')
def canonicalName(name):
"""Return the given name in canonical "Surname, Name" format.
It assumes that name is in the 'Name Surname' format."""
# XXX: some statistics (as of 17 Apr 2008, over 2288622 names):
# - just a surname: 69476
# - single surname, single name: 2209656
# - composed surname, composed name: 9490
# - composed surname, single name: 67606
# (2: 59764, 3: 6862, 4: 728)
# - single surname, composed name: 242310
# (2: 229467, 3: 9901, 4: 2041, 5: 630)
# - Jr.: 8025
# Don't convert names already in the canonical format.
if name.find(', ') != -1: return name
if isinstance(name, unicode):
joiner = u'%s, %s'
sur_joiner = u'%s %s'
sur_space = u' %s'
space = u' '
else:
joiner = '%s, %s'
sur_joiner = '%s %s'
sur_space = ' %s'
space = ' '
sname = name.split(' ')
snl = len(sname)
if snl == 2:
# Just a name and a surname: how boring...
name = joiner % (sname[1], sname[0])
elif snl > 2:
lsname = [x.lower() for x in sname]
if snl == 3: _indexes = (0, snl-2)
else: _indexes = (0, snl-2, snl-3)
# Check for common surname prefixes at the beginning and near the end.
for index in _indexes:
if lsname[index] not in _sname_suffixes: continue
try:
# Build the surname.
surn = sur_joiner % (sname[index], sname[index+1])
del sname[index]
del sname[index]
try:
# Handle the "Jr." after the name.
if lsname[index+2].startswith('jr'):
surn += sur_space % sname[index]
del sname[index]
except (IndexError, ValueError):
pass
name = joiner % (surn, space.join(sname))
break
except ValueError:
continue
else:
name = joiner % (sname[-1], space.join(sname[:-1]))
return name
def normalizeName(name):
"""Return a name in the normal "Name Surname" format."""
if isinstance(name, unicode):
joiner = u'%s %s'
else:
joiner = '%s %s'
sname = name.split(', ')
if len(sname) == 2:
name = joiner % (sname[1], sname[0])
return name
def analyze_name(name, canonical=None):
"""Return a dictionary with the name and the optional imdbIndex
keys, from the given string.
If canonical is None (default), the name is stored in its own style.
If canonical is True, the name is converted to canonical style.
If canonical is False, the name is converted to normal format.
raise an IMDbParserError exception if the name is not valid.
"""
original_n = name
name = name.strip()
res = {}
imdbIndex = ''
opi = name.rfind('(')
cpi = name.rfind(')')
# Strip notes (but not if the name starts with a parenthesis).
if opi not in (-1, 0) and cpi > opi:
if re_index.match(name[opi:cpi+1]):
imdbIndex = name[opi+1:cpi]
name = name[:opi].rstrip()
else:
# XXX: for the birth and death dates case like " (1926-2004)"
name = re_parentheses.sub('', name).strip()
if not name:
raise IMDbParserError('invalid name: "%s"' % original_n)
if canonical is not None:
if canonical:
name = canonicalName(name)
else:
name = normalizeName(name)
res['name'] = name
if imdbIndex:
res['imdbIndex'] = imdbIndex
return res
def build_name(name_dict, canonical=None):
"""Given a dictionary that represents a "long" IMDb name,
return a string.
If canonical is None (default), the name is returned in the stored style.
If canonical is True, the name is converted to canonical style.
If canonical is False, the name is converted to normal format.
"""
name = name_dict.get('canonical name') or name_dict.get('name', '')
if not name: return ''
if canonical is not None:
if canonical:
name = canonicalName(name)
else:
name = normalizeName(name)
imdbIndex = name_dict.get('imdbIndex')
if imdbIndex:
name += ' (%s)' % imdbIndex
return name
# XXX: here only for backward compatibility. Find and remove any dependency.
_articles = linguistics.GENERIC_ARTICLES
_unicodeArticles = linguistics.toUnicode(_articles)
articlesDicts = linguistics.articlesDictsForLang(None)
spArticles = linguistics.spArticlesForLang(None)
def canonicalTitle(title, lang=None):
"""Return the title in the canonic format 'Movie Title, The';
beware that it doesn't handle long imdb titles, but only the
title portion, without year[/imdbIndex] or special markup.
The 'lang' argument can be used to specify the language of the title.
"""
isUnicode = isinstance(title, unicode)
articlesDicts = linguistics.articlesDictsForLang(lang)
try:
if title.split(', ')[-1].lower() in articlesDicts[isUnicode]:
return title
except IndexError:
pass
if isUnicode:
_format = u'%s, %s'
else:
_format = '%s, %s'
ltitle = title.lower()
spArticles = linguistics.spArticlesForLang(lang)
for article in spArticles[isUnicode]:
if ltitle.startswith(article):
lart = len(article)
title = _format % (title[lart:], title[:lart])
if article[-1] == ' ':
title = title[:-1]
break
## XXX: an attempt using a dictionary lookup.
##for artSeparator in (' ', "'", '-'):
## article = _articlesDict.get(ltitle.split(artSeparator)[0])
## if article is not None:
## lart = len(article)
## # check titles like "una", "I'm Mad" and "L'abbacchio".
## if title[lart:] == '' or (artSeparator != ' ' and
## title[lart:][1] != artSeparator): continue
## title = '%s, %s' % (title[lart:], title[:lart])
## if artSeparator == ' ': title = title[1:]
## break
return title
def normalizeTitle(title, lang=None):
"""Return the title in the normal "The Title" format;
beware that it doesn't handle long imdb titles, but only the
title portion, without year[/imdbIndex] or special markup.
The 'lang' argument can be used to specify the language of the title.
"""
isUnicode = isinstance(title, unicode)
stitle = title.split(', ')
articlesDicts = linguistics.articlesDictsForLang(lang)
if len(stitle) > 1 and stitle[-1].lower() in articlesDicts[isUnicode]:
sep = ' '
if stitle[-1][-1] in ("'", '-'):
sep = ''
if isUnicode:
_format = u'%s%s%s'
_joiner = u', '
else:
_format = '%s%s%s'
_joiner = ', '
title = _format % (stitle[-1], sep, _joiner.join(stitle[:-1]))
return title
def _split_series_episode(title):
"""Return the series and the episode titles; if this is not a
series' episode, the returned series title is empty.
This function recognize two different styles:
"The Series" An Episode (2005)
"The Series" (2004) {An Episode (2005) (#season.episode)}"""
series_title = ''
episode_or_year = ''
if title[-1:] == '}':
# Title of the episode, as in the plain text data files.
begin_eps = title.rfind('{')
if begin_eps == -1: return '', ''
series_title = title[:begin_eps].rstrip()
# episode_or_year is returned with the {...}
episode_or_year = title[begin_eps:].strip()
if episode_or_year[:12] == '{SUSPENDED}}': return '', ''
# XXX: works only with tv series; it's still unclear whether
# IMDb will support episodes for tv mini series and tv movies...
elif title[0:1] == '"':
second_quot = title[1:].find('"') + 2
if second_quot != 1: # a second " was found.
episode_or_year = title[second_quot:].lstrip()
first_char = episode_or_year[0:1]
if not first_char: return '', ''
if first_char != '(':
# There is not a (year) but the title of the episode;
# that means this is an episode title, as returned by
# the web server.
series_title = title[:second_quot]
##elif episode_or_year[-1:] == '}':
## # Title of the episode, as in the plain text data files.
## begin_eps = episode_or_year.find('{')
## if begin_eps == -1: return series_title, episode_or_year
## series_title = title[:second_quot+begin_eps].rstrip()
## # episode_or_year is returned with the {...}
## episode_or_year = episode_or_year[begin_eps:]
return series_title, episode_or_year
def is_series_episode(title):
"""Return True if 'title' is an series episode."""
title = title.strip()
if _split_series_episode(title)[0]: return 1
return 0
def analyze_title(title, canonical=None, canonicalSeries=None,
canonicalEpisode=None, _emptyString=u''):
"""Analyze the given title and return a dictionary with the
"stripped" title, the kind of the show ("movie", "tv series", etc.),
the year of production and the optional imdbIndex (a roman number
used to distinguish between movies with the same title and year).
If canonical is None (default), the title is stored in its own style.
If canonical is True, the title is converted to canonical style.
If canonical is False, the title is converted to normal format.
raise an IMDbParserError exception if the title is not valid.
"""
# XXX: introduce the 'lang' argument?
if canonical is not None:
canonicalSeries = canonicalEpisode = canonical
original_t = title
result = {}
title = title.strip()
year = _emptyString
kind = _emptyString
imdbIndex = _emptyString
series_title, episode_or_year = _split_series_episode(title)
if series_title:
# It's an episode of a series.
series_d = analyze_title(series_title, canonical=canonicalSeries)
oad = sen = ep_year = _emptyString
# Plain text data files format.
if episode_or_year[0:1] == '{' and episode_or_year[-1:] == '}':
match = re_episode_info.findall(episode_or_year)
if match:
# Episode title, original air date and #season.episode
episode_or_year, oad, sen = match[0]
episode_or_year = episode_or_year.strip()
if not oad:
# No year, but the title is something like (2005-04-12)
if episode_or_year and episode_or_year[0] == '(' and \
episode_or_year[-1:] == ')' and \
episode_or_year[1:2] != '#':
oad = episode_or_year
if oad[1:5] and oad[5:6] == '-':
try:
ep_year = int(oad[1:5])
except (TypeError, ValueError):
pass
if not oad and not sen and episode_or_year.startswith('(#'):
sen = episode_or_year
elif episode_or_year.startswith('Episode dated'):
oad = episode_or_year[14:]
if oad[-4:].isdigit():
try:
ep_year = int(oad[-4:])
except (TypeError, ValueError):
pass
episode_d = analyze_title(episode_or_year, canonical=canonicalEpisode)
episode_d['kind'] = u'episode'
episode_d['episode of'] = series_d
if oad:
episode_d['original air date'] = oad[1:-1]
if ep_year and episode_d.get('year') is None:
episode_d['year'] = ep_year
if sen and sen[2:-1].find('.') != -1:
seas, epn = sen[2:-1].split('.')
if seas:
# Set season and episode.
try: seas = int(seas)
except: pass
try: epn = int(epn)
except: pass
episode_d['season'] = seas
if epn:
episode_d['episode'] = epn
return episode_d
# First of all, search for the kind of show.
# XXX: Number of entries at 17 Apr 2008:
# movie: 379,871
# episode: 483,832
# tv movie: 61,119
# tv series: 44,795
# video movie: 57,915
# tv mini series: 5,497
# video game: 5,490
# More up-to-date statistics: http://us.imdb.com/database_statistics
if title.endswith('(TV)'):
kind = u'tv movie'
title = title[:-4].rstrip()
elif title.endswith('(V)'):
kind = u'video movie'
title = title[:-3].rstrip()
elif title.endswith('(video)'):
kind = u'video movie'
title = title[:-7].rstrip()
elif title.endswith('(mini)'):
kind = u'tv mini series'
title = title[:-6].rstrip()
elif title.endswith('(VG)'):
kind = u'video game'
title = title[:-4].rstrip()
# Search for the year and the optional imdbIndex (a roman number).
yi = re_year_index.findall(title)
if not yi:
yi = re_extended_year_index.findall(title)
if yi:
yk, yiy, yii = yi[-1]
yi = [(yiy, yii)]
if yk == 'TV episode':
kind = u'episode'
elif yk == 'TV':
kind = u'tv movie'
elif yk == 'TV Series':
kind = u'tv series'
elif yk == 'Video':
kind = u'video movie'
elif yk == 'TV mini-series':
kind = u'tv mini series'
elif yk == 'Video Game':
kind = u'video game'
title = re_remove_kind.sub('(', title)
if yi:
last_yi = yi[-1]
year = last_yi[0]
if last_yi[1]:
imdbIndex = last_yi[1][1:]
year = year[:-len(imdbIndex)-1]
i = title.rfind('(%s)' % last_yi[0])
if i != -1:
title = title[:i-1].rstrip()
# This is a tv (mini) series: strip the '"' at the begin and at the end.
# XXX: strip('"') is not used for compatibility with Python 2.0.
if title and title[0] == title[-1] == '"':
if not kind:
kind = u'tv series'
title = title[1:-1].strip()
elif title.endswith('(TV series)'):
kind = u'tv series'
title = title[:-11].rstrip()
if not title:
raise IMDbParserError('invalid title: "%s"' % original_t)
if canonical is not None:
if canonical:
title = canonicalTitle(title)
else:
title = normalizeTitle(title)
# 'kind' is one in ('movie', 'episode', 'tv series', 'tv mini series',
# 'tv movie', 'video movie', 'video game')
result['title'] = title
result['kind'] = kind or u'movie'
if year and year != '????':
if '-' in year:
result['series years'] = year
year = year[:4]
try:
result['year'] = int(year)
except (TypeError, ValueError):
pass
if imdbIndex:
result['imdbIndex'] = imdbIndex
if isinstance(_emptyString, str):
result['kind'] = str(kind or 'movie')
return result
_web_format = '%d %B %Y'
_ptdf_format = '(%Y-%m-%d)'
def _convertTime(title, fromPTDFtoWEB=1, _emptyString=u''):
"""Convert a time expressed in the pain text data files, to
the 'Episode dated ...' format used on the web site; if
fromPTDFtoWEB is false, the inverted conversion is applied."""
try:
if fromPTDFtoWEB:
from_format = _ptdf_format
to_format = _web_format
else:
from_format = u'Episode dated %s' % _web_format
to_format = _ptdf_format
t = strptime(title, from_format)
title = strftime(to_format, t)
if fromPTDFtoWEB:
if title[0] == '0': title = title[1:]
title = u'Episode dated %s' % title
except ValueError:
pass
if isinstance(_emptyString, str):
try:
title = str(title)
except UnicodeDecodeError:
pass
return title
def build_title(title_dict, canonical=None, canonicalSeries=None,
canonicalEpisode=None, ptdf=0, lang=None, _doYear=1,
_emptyString=u''):
"""Given a dictionary that represents a "long" IMDb title,
return a string.
If canonical is None (default), the title is returned in the stored style.
If canonical is True, the title is converted to canonical style.
If canonical is False, the title is converted to normal format.
lang can be used to specify the language of the title.
If ptdf is true, the plain text data files format is used.
"""
if canonical is not None:
canonicalSeries = canonical
pre_title = _emptyString
kind = title_dict.get('kind')
episode_of = title_dict.get('episode of')
if kind == 'episode' and episode_of is not None:
# Works with both Movie instances and plain dictionaries.
doYear = 0
if ptdf:
doYear = 1
pre_title = build_title(episode_of, canonical=canonicalSeries,
ptdf=0, _doYear=doYear,
_emptyString=_emptyString)
ep_dict = {'title': title_dict.get('title', ''),
'imdbIndex': title_dict.get('imdbIndex')}
ep_title = ep_dict['title']
if not ptdf:
doYear = 1
ep_dict['year'] = title_dict.get('year', '????')
if ep_title[0:1] == '(' and ep_title[-1:] == ')' and \
ep_title[1:5].isdigit():
ep_dict['title'] = _convertTime(ep_title, fromPTDFtoWEB=1,
_emptyString=_emptyString)
else:
doYear = 0
if ep_title.startswith('Episode dated'):
ep_dict['title'] = _convertTime(ep_title, fromPTDFtoWEB=0,
_emptyString=_emptyString)
episode_title = build_title(ep_dict,
canonical=canonicalEpisode, ptdf=ptdf,
_doYear=doYear, _emptyString=_emptyString)
if ptdf:
oad = title_dict.get('original air date', _emptyString)
if len(oad) == 10 and oad[4] == '-' and oad[7] == '-' and \
episode_title.find(oad) == -1:
episode_title += ' (%s)' % oad
seas = title_dict.get('season')
if seas is not None:
episode_title += ' (#%s' % seas
episode = title_dict.get('episode')
if episode is not None:
episode_title += '.%s' % episode
episode_title += ')'
episode_title = '{%s}' % episode_title
return '%s %s' % (pre_title, episode_title)
title = title_dict.get('title', '')
if not title: return _emptyString
if canonical is not None:
if canonical:
title = canonicalTitle(title, lang=lang)
else:
title = normalizeTitle(title, lang=lang)
if pre_title:
title = '%s %s' % (pre_title, title)
if kind in (u'tv series', u'tv mini series'):
title = '"%s"' % title
if _doYear:
imdbIndex = title_dict.get('imdbIndex')
year = title_dict.get('year') or u'????'
if isinstance(_emptyString, str):
year = str(year)
title += ' (%s' % year
if imdbIndex:
title += '/%s' % imdbIndex
title += ')'
if kind:
if kind == 'tv movie':
title += ' (TV)'
elif kind == 'video movie':
title += ' (V)'
elif kind == 'tv mini series':
title += ' (mini)'
elif kind == 'video game':
title += ' (VG)'
return title
def split_company_name_notes(name):
"""Return two strings, the first representing the company name,
and the other representing the (optional) notes."""
name = name.strip()
notes = u''
if name.endswith(')'):
fpidx = name.find('(')
if fpidx != -1:
notes = name[fpidx:]
name = name[:fpidx].rstrip()
return name, notes
def analyze_company_name(name, stripNotes=False):
"""Return a dictionary with the name and the optional 'country'
keys, from the given string.
If stripNotes is true, tries to not consider optional notes.
raise an IMDbParserError exception if the name is not valid.
"""
if stripNotes:
name = split_company_name_notes(name)[0]
o_name = name
name = name.strip()
country = None
if name.endswith(']'):
idx = name.rfind('[')
if idx != -1:
country = name[idx:]
name = name[:idx].rstrip()
if not name:
raise IMDbParserError('invalid name: "%s"' % o_name)
result = {'name': name}
if country:
result['country'] = country
return result
def build_company_name(name_dict, _emptyString=u''):
"""Given a dictionary that represents a "long" IMDb company name,
return a string.
"""
name = name_dict.get('name')
if not name:
return _emptyString
country = name_dict.get('country')
if country is not None:
name += ' %s' % country
return name
class _LastC:
"""Size matters."""
def __cmp__(self, other):
if isinstance(other, self.__class__): return 0
return 1
_last = _LastC()
def cmpMovies(m1, m2):
"""Compare two movies by year, in reverse order; the imdbIndex is checked
for movies with the same year of production and title."""
# Sort tv series' episodes.
m1e = m1.get('episode of')
m2e = m2.get('episode of')
if m1e is not None and m2e is not None:
cmp_series = cmpMovies(m1e, m2e)
if cmp_series != 0:
return cmp_series
m1s = m1.get('season')
m2s = m2.get('season')
if m1s is not None and m2s is not None:
if m1s < m2s:
return 1
elif m1s > m2s:
return -1
m1p = m1.get('episode')
m2p = m2.get('episode')
if m1p < m2p:
return 1
elif m1p > m2p:
return -1
try:
if m1e is None: m1y = int(m1.get('year', 0))
else: m1y = int(m1e.get('year', 0))
except ValueError:
m1y = 0
try:
if m2e is None: m2y = int(m2.get('year', 0))
else: m2y = int(m2e.get('year', 0))
except ValueError:
m2y = 0
if m1y > m2y: return -1
if m1y < m2y: return 1
# Ok, these movies have the same production year...
#m1t = m1.get('canonical title', _last)
#m2t = m2.get('canonical title', _last)
# It should works also with normal dictionaries (returned from searches).
#if m1t is _last and m2t is _last:
m1t = m1.get('title', _last)
m2t = m2.get('title', _last)
if m1t < m2t: return -1
if m1t > m2t: return 1
# Ok, these movies have the same title...
m1i = m1.get('imdbIndex', _last)
m2i = m2.get('imdbIndex', _last)
if m1i > m2i: return -1
if m1i < m2i: return 1
m1id = getattr(m1, 'movieID', None)
# Introduce this check even for other comparisons functions?
# XXX: is it safe to check without knowning the data access system?
# probably not a great idea. Check for 'kind', instead?
if m1id is not None:
m2id = getattr(m2, 'movieID', None)
if m1id > m2id: return -1
elif m1id < m2id: return 1
return 0
def cmpPeople(p1, p2):
"""Compare two people by billingPos, name and imdbIndex."""
p1b = getattr(p1, 'billingPos', None) or _last
p2b = getattr(p2, 'billingPos', None) or _last
if p1b > p2b: return 1
if p1b < p2b: return -1
p1n = p1.get('canonical name', _last)
p2n = p2.get('canonical name', _last)
if p1n is _last and p2n is _last:
p1n = p1.get('name', _last)
p2n = p2.get('name', _last)
if p1n > p2n: return 1
if p1n < p2n: return -1
p1i = p1.get('imdbIndex', _last)
p2i = p2.get('imdbIndex', _last)
if p1i > p2i: return 1
if p1i < p2i: return -1
return 0
def cmpCompanies(p1, p2):
"""Compare two companies."""
p1n = p1.get('long imdb name', _last)
p2n = p2.get('long imdb name', _last)
if p1n is _last and p2n is _last:
p1n = p1.get('name', _last)
p2n = p2.get('name', _last)
if p1n > p2n: return 1
if p1n < p2n: return -1
p1i = p1.get('country', _last)
p2i = p2.get('country', _last)
if p1i > p2i: return 1
if p1i < p2i: return -1
return 0
# References to titles, names and characters.
# XXX: find better regexp!
re_titleRef = re.compile(r'_(.+?(?: \([0-9\?]{4}(?:/[IVXLCDM]+)?\))?(?: \(mini\)| \(TV\)| \(V\)| \(VG\))?)_ \(qv\)')
# FIXME: doesn't match persons with ' in the name.
re_nameRef = re.compile(r"'([^']+?)' \(qv\)")
# XXX: good choice? Are there characters with # in the name?
re_characterRef = re.compile(r"#([^']+?)# \(qv\)")
# Functions used to filter the text strings.
def modNull(s, titlesRefs, namesRefs, charactersRefs):
"""Do nothing."""
return s
def modClearTitleRefs(s, titlesRefs, namesRefs, charactersRefs):
"""Remove titles references."""
return re_titleRef.sub(r'\1', s)
def modClearNameRefs(s, titlesRefs, namesRefs, charactersRefs):
"""Remove names references."""
return re_nameRef.sub(r'\1', s)
def modClearCharacterRefs(s, titlesRefs, namesRefs, charactersRefs):
"""Remove characters references"""
return re_characterRef.sub(r'\1', s)
def modClearRefs(s, titlesRefs, namesRefs, charactersRefs):
"""Remove titles, names and characters references."""
s = modClearTitleRefs(s, {}, {}, {})
s = modClearCharacterRefs(s, {}, {}, {})
return modClearNameRefs(s, {}, {}, {})
def modifyStrings(o, modFunct, titlesRefs, namesRefs, charactersRefs):
"""Modify a string (or string values in a dictionary or strings
in a list), using the provided modFunct function and titlesRefs
namesRefs and charactersRefs references dictionaries."""
# Notice that it doesn't go any deeper than the first two levels in a list.
if isinstance(o, (unicode, str)):
return modFunct(o, titlesRefs, namesRefs, charactersRefs)
elif isinstance(o, (list, tuple, dict)):
_stillorig = 1
if isinstance(o, (list, tuple)): keys = xrange(len(o))
else: keys = o.keys()
for i in keys:
v = o[i]
if isinstance(v, (unicode, str)):
if _stillorig:
o = copy(o)
_stillorig = 0
o[i] = modFunct(v, titlesRefs, namesRefs, charactersRefs)
elif isinstance(v, (list, tuple)):
modifyStrings(o[i], modFunct, titlesRefs, namesRefs,
charactersRefs)
return o
def date_and_notes(s):
"""Parse (birth|death) date and notes; returns a tuple in the
form (date, notes)."""
s = s.strip()
if not s: return (u'', u'')
notes = u''
if s[0].isdigit() or s.split()[0].lower() in ('c.', 'january', 'february',
'march', 'april', 'may', 'june',
'july', 'august', 'september',
'october', 'november',
'december', 'ca.', 'circa',
'????,'):
i = s.find(',')
if i != -1:
notes = s[i+1:].strip()
s = s[:i]
else:
notes = s
s = u''
if s == '????': s = u''
return s, notes
class RolesList(list):
"""A list of Person or Character instances, used for the currentRole
property."""
def __unicode__(self):
return u' / '.join([unicode(x) for x in self])
def __str__(self):
# FIXME: does it make sense at all? Return a unicode doesn't
# seem right, in __str__.
return u' / '.join([unicode(x).encode('utf8') for x in self])
# Replace & with &, but only if it's not already part of a charref.
#_re_amp = re.compile(r'(&)(?!\w+;)', re.I)
#_re_amp = re.compile(r'(?<=\W)&(?=[^a-zA-Z0-9_#])')
_re_amp = re.compile(r'&(?![^a-zA-Z0-9_#]{1,5};)')
def escape4xml(value):
"""Escape some chars that can't be present in a XML value."""
if isinstance(value, int):
value = str(value)
value = _re_amp.sub('&', value)
value = value.replace('"', '"').replace("'", ''')
value = value.replace('<', '<').replace('>', '>')
if isinstance(value, unicode):
value = value.encode('ascii', 'xmlcharrefreplace')
return value
def _refsToReplace(value, modFunct, titlesRefs, namesRefs, charactersRefs):
"""Return three lists - for movie titles, persons and characters names -
with two items tuples: the first item is the reference once escaped
by the user-provided modFunct function, the second is the same
reference un-escaped."""
mRefs = []
for refRe, refTemplate in [(re_titleRef, u'_%s_ (qv)'),
(re_nameRef, u"'%s' (qv)"),
(re_characterRef, u'#%s# (qv)')]:
theseRefs = []
for theRef in refRe.findall(value):
# refTemplate % theRef values don't change for a single
# _Container instance, so this is a good candidate for a
# cache or something - even if it's so rarely used that...
# Moreover, it can grow - ia.update(...) - and change if
# modFunct is modified.
goodValue = modFunct(refTemplate % theRef, titlesRefs, namesRefs,
charactersRefs)
# Prevents problems with crap in plain text data files.
# We should probably exclude invalid chars and string that
# are too long in the re_*Ref expressions.
if '_' in goodValue or len(goodValue) > 128:
continue
toReplace = escape4xml(goodValue)
# Only the 'value' portion is replaced.
replaceWith = goodValue.replace(theRef, escape4xml(theRef))
theseRefs.append((toReplace, replaceWith))
mRefs.append(theseRefs)
return mRefs
def _handleTextNotes(s):
"""Split text::notes strings."""
ssplit = s.split('::', 1)
if len(ssplit) == 1:
return s
return u'%s<notes>%s</notes>' % (ssplit[0], ssplit[1])
def _normalizeValue(value, withRefs=False, modFunct=None, titlesRefs=None,
namesRefs=None, charactersRefs=None):
"""Replace some chars that can't be present in a XML text."""
# XXX: use s.encode(encoding, 'xmlcharrefreplace') ? Probably not
# a great idea: after all, returning a unicode is safe.
if isinstance(value, (unicode, str)):
if not withRefs:
value = _handleTextNotes(escape4xml(value))
else:
# Replace references that were accidentally escaped.
replaceLists = _refsToReplace(value, modFunct, titlesRefs,
namesRefs, charactersRefs)
value = modFunct(value, titlesRefs or {}, namesRefs or {},
charactersRefs or {})
value = _handleTextNotes(escape4xml(value))
for replaceList in replaceLists:
for toReplace, replaceWith in replaceList:
value = value.replace(toReplace, replaceWith)
else:
value = unicode(value)
return value
def _tag4TON(ton, addAccessSystem=False, _containerOnly=False):
"""Build a tag for the given _Container instance;
both open and close tags are returned."""
tag = ton.__class__.__name__.lower()
what = 'name'
if tag == 'movie':
value = ton.get('long imdb title') or ton.get('title', '')
what = 'title'
else:
value = ton.get('long imdb name') or ton.get('name', '')
value = _normalizeValue(value)
extras = u''
crl = ton.currentRole
if crl:
if not isinstance(crl, list):
crl = [crl]
for cr in crl:
crTag = cr.__class__.__name__.lower()
crValue = cr['long imdb name']
crValue = _normalizeValue(crValue)
crID = cr.getID()
if crID is not None:
extras += u'<current-role><%s id="%s">' \
u'<name>%s</name></%s>' % (crTag, crID,
crValue, crTag)
else:
extras += u'<current-role><%s><name>%s</name></%s>' % \
(crTag, crValue, crTag)
if cr.notes:
extras += u'<notes>%s</notes>' % _normalizeValue(cr.notes)
extras += u'</current-role>'
theID = ton.getID()
if theID is not None:
beginTag = u'<%s id="%s"' % (tag, theID)
if addAccessSystem and ton.accessSystem:
beginTag += ' access-system="%s"' % ton.accessSystem
if not _containerOnly:
beginTag += u'><%s>%s</%s>' % (what, value, what)
else:
beginTag += u'>'
else:
if not _containerOnly:
beginTag = u'<%s><%s>%s</%s>' % (tag, what, value, what)
else:
beginTag = u'<%s>' % tag
beginTag += extras
if ton.notes:
beginTag += u'<notes>%s</notes>' % _normalizeValue(ton.notes)
return (beginTag, u'</%s>' % tag)
TAGS_TO_MODIFY = {
'movie.parents-guide': ('item', True),
'movie.number-of-votes': ('item', True),
'movie.soundtrack.item': ('item', True),
'movie.quotes': ('quote', False),
'movie.quotes.quote': ('line', False),
'movie.demographic': ('item', True),
'movie.episodes': ('season', True),
'movie.episodes.season': ('episode', True),
'person.merchandising-links': ('item', True),
'person.genres': ('item', True),
'person.quotes': ('quote', False),
'person.keywords': ('item', True),
'character.quotes': ('item', True),
'character.quotes.item': ('quote', False),
'character.quotes.item.quote': ('line', False)
}
_allchars = string.maketrans('', '')
_keepchars = _allchars.translate(_allchars, string.ascii_lowercase + '-' +
string.digits)
def _tagAttr(key, fullpath):
"""Return a tuple with a tag name and a (possibly empty) attribute,
applying the conversions specified in TAGS_TO_MODIFY and checking
that the tag is safe for a XML document."""
attrs = {}
_escapedKey = escape4xml(key)
if fullpath in TAGS_TO_MODIFY:
tagName, useTitle = TAGS_TO_MODIFY[fullpath]
if useTitle:
attrs['key'] = _escapedKey
elif not isinstance(key, unicode):
if isinstance(key, str):
tagName = unicode(key, 'ascii', 'ignore')
else:
strType = str(type(key)).replace("<type '", "").replace("'>", "")
attrs['keytype'] = strType
tagName = unicode(key)
else:
tagName = key
if isinstance(key, int):
attrs['keytype'] = 'int'
origTagName = tagName
tagName = tagName.lower().replace(' ', '-')
tagName = str(tagName).translate(_allchars, _keepchars)
if origTagName != tagName:
if 'key' not in attrs:
attrs['key'] = _escapedKey
if (not tagName) or tagName[0].isdigit() or tagName[0] == '-':
# This is a fail-safe: we should never be here, since unpredictable
# keys must be listed in TAGS_TO_MODIFY.
# This will proably break the DTD/schema, but at least it will
# produce a valid XML.
tagName = 'item'
_utils_logger.error('invalid tag: %s [%s]' % (_escapedKey, fullpath))
attrs['key'] = _escapedKey
return tagName, u' '.join([u'%s="%s"' % i for i in attrs.items()])
def _seq2xml(seq, _l=None, withRefs=False, modFunct=None,
titlesRefs=None, namesRefs=None, charactersRefs=None,
_topLevel=True, key2infoset=None, fullpath=''):
"""Convert a sequence or a dictionary to a list of XML
unicode strings."""
if _l is None:
_l = []
if isinstance(seq, dict):
for key in seq:
value = seq[key]
if isinstance(key, _Container):
# Here we're assuming that a _Container is never a top-level
# key (otherwise we should handle key2infoset).
openTag, closeTag = _tag4TON(key)
# So that fullpath will contains something meaningful.
tagName = key.__class__.__name__.lower()
else:
tagName, attrs = _tagAttr(key, fullpath)
openTag = u'<%s' % tagName
if attrs:
openTag += ' %s' % attrs
if _topLevel and key2infoset and key in key2infoset:
openTag += u' infoset="%s"' % key2infoset[key]
if isinstance(value, int):
openTag += ' type="int"'
elif isinstance(value, float):
openTag += ' type="float"'
openTag += u'>'
closeTag = u'</%s>' % tagName
_l.append(openTag)
_seq2xml(value, _l, withRefs, modFunct, titlesRefs,
namesRefs, charactersRefs, _topLevel=False,
fullpath='%s.%s' % (fullpath, tagName))
_l.append(closeTag)
elif isinstance(seq, (list, tuple)):
tagName, attrs = _tagAttr('item', fullpath)
beginTag = u'<%s' % tagName
if attrs:
beginTag += u' %s' % attrs
#beginTag += u'>'
closeTag = u'</%s>' % tagName
for item in seq:
if isinstance(item, _Container):
_seq2xml(item, _l, withRefs, modFunct, titlesRefs,
namesRefs, charactersRefs, _topLevel=False,
fullpath='%s.%s' % (fullpath,
item.__class__.__name__.lower()))
else:
openTag = beginTag
if isinstance(item, int):
openTag += ' type="int"'
elif isinstance(item, float):
openTag += ' type="float"'
openTag += u'>'
_l.append(openTag)
_seq2xml(item, _l, withRefs, modFunct, titlesRefs,
namesRefs, charactersRefs, _topLevel=False,
fullpath='%s.%s' % (fullpath, tagName))
_l.append(closeTag)
else:
if isinstance(seq, _Container):
_l.extend(_tag4TON(seq))
else:
# Text, ints, floats and the like.
_l.append(_normalizeValue(seq, withRefs=withRefs,
modFunct=modFunct,
titlesRefs=titlesRefs,
namesRefs=namesRefs,
charactersRefs=charactersRefs))
return _l
_xmlHead = u"""<?xml version="1.0"?>
<!DOCTYPE %s SYSTEM "http://imdbpy.sf.net/dtd/imdbpy{VERSION}.dtd">
"""
_xmlHead = _xmlHead.replace('{VERSION}',
VERSION.replace('.', '').split('dev')[0][:2])
class _Container(object):
"""Base class for Movie, Person, Character and Company classes."""
# The default sets of information retrieved.
default_info = ()
# Aliases for some not-so-intuitive keys.
keys_alias = {}
# List of keys to modify.
keys_tomodify_list = ()
# Function used to compare two instances of this class.
cmpFunct = None
# Regular expression used to build the 'full-size (headshot|cover url)'.
_re_fullsizeURL = re.compile(r'\._V1\._SX(\d+)_SY(\d+)_')
def __init__(self, myID=None, data=None, notes=u'',
currentRole=u'', roleID=None, roleIsPerson=False,
accessSystem=None, titlesRefs=None, namesRefs=None,
charactersRefs=None, modFunct=None, *args, **kwds):
"""Initialize a Movie, Person, Character or Company object.
*myID* -- your personal identifier for this object.
*data* -- a dictionary used to initialize the object.
*notes* -- notes for the person referred in the currentRole
attribute; e.g.: '(voice)' or the alias used in the
movie credits.
*accessSystem* -- a string representing the data access system used.
*currentRole* -- a Character instance representing the current role
or duty of a person in this movie, or a Person
object representing the actor/actress who played
a given character in a Movie. If a string is
passed, an object is automatically build.
*roleID* -- if available, the characterID/personID of the currentRole
object.
*roleIsPerson* -- when False (default) the currentRole is assumed
to be a Character object, otherwise a Person.
*titlesRefs* -- a dictionary with references to movies.
*namesRefs* -- a dictionary with references to persons.
*charactersRefs* -- a dictionary with references to characters.
*modFunct* -- function called returning text fields.
"""
self.reset()
self.accessSystem = accessSystem
self.myID = myID
if data is None: data = {}
self.set_data(data, override=1)
self.notes = notes
if titlesRefs is None: titlesRefs = {}
self.update_titlesRefs(titlesRefs)
if namesRefs is None: namesRefs = {}
self.update_namesRefs(namesRefs)
if charactersRefs is None: charactersRefs = {}
self.update_charactersRefs(charactersRefs)
self.set_mod_funct(modFunct)
self.keys_tomodify = {}
for item in self.keys_tomodify_list:
self.keys_tomodify[item] = None
self._roleIsPerson = roleIsPerson
if not roleIsPerson:
from imdb.Character import Character
self._roleClass = Character
else:
from imdb.Person import Person
self._roleClass = Person
self.currentRole = currentRole
if roleID:
self.roleID = roleID
self._init(*args, **kwds)
def _get_roleID(self):
"""Return the characterID or personID of the currentRole object."""
if not self.__role:
return None
if isinstance(self.__role, list):
return [x.getID() for x in self.__role]
return self.currentRole.getID()
def _set_roleID(self, roleID):
"""Set the characterID or personID of the currentRole object."""
if not self.__role:
# XXX: needed? Just ignore it? It's probably safer to
# ignore it, to prevent some bugs in the parsers.
#raise IMDbError,"Can't set ID of an empty Character/Person object."
pass
if not self._roleIsPerson:
if not isinstance(roleID, (list, tuple)):
self.currentRole.characterID = roleID
else:
for index, item in enumerate(roleID):
self.__role[index].characterID = item
else:
if not isinstance(roleID, (list, tuple)):
self.currentRole.personID = roleID
else:
for index, item in enumerate(roleID):
self.__role[index].personID = item
roleID = property(_get_roleID, _set_roleID,
doc="the characterID or personID of the currentRole object.")
def _get_currentRole(self):
"""Return a Character or Person instance."""
if self.__role:
return self.__role
return self._roleClass(name=u'', accessSystem=self.accessSystem,
modFunct=self.modFunct)
def _set_currentRole(self, role):
"""Set self.currentRole to a Character or Person instance."""
if isinstance(role, (unicode, str)):
if not role:
self.__role = None
else:
self.__role = self._roleClass(name=role, modFunct=self.modFunct,
accessSystem=self.accessSystem)
elif isinstance(role, (list, tuple)):
self.__role = RolesList()
for item in role:
if isinstance(item, (unicode, str)):
self.__role.append(self._roleClass(name=item,
accessSystem=self.accessSystem,
modFunct=self.modFunct))
else:
self.__role.append(item)
if not self.__role:
self.__role = None
else:
self.__role = role
currentRole = property(_get_currentRole, _set_currentRole,
doc="The role of a Person in a Movie" + \
" or the interpreter of a Character in a Movie.")
def _init(self, **kwds): pass
def reset(self):
"""Reset the object."""
self.data = {}
self.myID = None
self.notes = u''
self.titlesRefs = {}
self.namesRefs = {}
self.charactersRefs = {}
self.modFunct = modClearRefs
self.current_info = []
self.infoset2keys = {}
self.key2infoset = {}
self.__role = None
self._reset()
def _reset(self): pass
def clear(self):
"""Reset the dictionary."""
self.data.clear()
self.notes = u''
self.titlesRefs = {}
self.namesRefs = {}
self.charactersRefs = {}
self.current_info = []
self.infoset2keys = {}
self.key2infoset = {}
self.__role = None
self._clear()
def _clear(self): pass
def get_current_info(self):
"""Return the current set of information retrieved."""
return self.current_info
def update_infoset_map(self, infoset, keys, mainInfoset):
"""Update the mappings between infoset and keys."""
if keys is None:
keys = []
if mainInfoset is not None:
theIS = mainInfoset
else:
theIS = infoset
self.infoset2keys[theIS] = keys
for key in keys:
self.key2infoset[key] = theIS
def set_current_info(self, ci):
"""Set the current set of information retrieved."""
# XXX:Remove? It's never used and there's no way to update infoset2keys.
self.current_info = ci
def add_to_current_info(self, val, keys=None, mainInfoset=None):
"""Add a set of information to the current list."""
if val not in self.current_info:
self.current_info.append(val)
self.update_infoset_map(val, keys, mainInfoset)
def has_current_info(self, val):
"""Return true if the given set of information is in the list."""
return val in self.current_info
def set_mod_funct(self, modFunct):
"""Set the fuction used to modify the strings."""
if modFunct is None: modFunct = modClearRefs
self.modFunct = modFunct
def update_titlesRefs(self, titlesRefs):
"""Update the dictionary with the references to movies."""
self.titlesRefs.update(titlesRefs)
def get_titlesRefs(self):
"""Return the dictionary with the references to movies."""
return self.titlesRefs
def update_namesRefs(self, namesRefs):
"""Update the dictionary with the references to names."""
self.namesRefs.update(namesRefs)
def get_namesRefs(self):
"""Return the dictionary with the references to names."""
return self.namesRefs
def update_charactersRefs(self, charactersRefs):
"""Update the dictionary with the references to characters."""
self.charactersRefs.update(charactersRefs)
def get_charactersRefs(self):
"""Return the dictionary with the references to characters."""
return self.charactersRefs
def set_data(self, data, override=0):
"""Set the movie data to the given dictionary; if 'override' is
set, the previous data is removed, otherwise the two dictionary
are merged.
"""
if not override:
self.data.update(data)
else:
self.data = data
def getID(self):
"""Return movieID, personID, characterID or companyID."""
raise NotImplementedError('override this method')
def __cmp__(self, other):
"""Compare two Movie, Person, Character or Company objects."""
# XXX: raise an exception?
if self.cmpFunct is None: return -1
if not isinstance(other, self.__class__): return -1
return self.cmpFunct(other)
def __hash__(self):
"""Hash for this object."""
# XXX: does it always work correctly?
theID = self.getID()
if theID is not None and self.accessSystem not in ('UNKNOWN', None):
# Handle 'http' and 'mobile' as they are the same access system.
acs = self.accessSystem
if acs in ('mobile', 'httpThin'):
acs = 'http'
# There must be some indication of the kind of the object, too.
s4h = '%s:%s[%s]' % (self.__class__.__name__, theID, acs)
else:
s4h = repr(self)
return hash(s4h)
def isSame(self, other):
"""Return True if the two represent the same object."""
if not isinstance(other, self.__class__): return 0
if hash(self) == hash(other): return 1
return 0
def __len__(self):
"""Number of items in the data dictionary."""
return len(self.data)
def getAsXML(self, key, _with_add_keys=True):
"""Return a XML representation of the specified key, or None
if empty. If _with_add_keys is False, dinamically generated
keys are excluded."""
# Prevent modifyStrings in __getitem__ to be called; if needed,
# it will be called by the _normalizeValue function.
origModFunct = self.modFunct
self.modFunct = modNull
# XXX: not totally sure it's a good idea, but could prevent
# problems (i.e.: the returned string always contains
# a DTD valid tag, and not something that can be only in
# the keys_alias map).
key = self.keys_alias.get(key, key)
if (not _with_add_keys) and (key in self._additional_keys()):
self.modFunct = origModFunct
return None
try:
withRefs = False
if key in self.keys_tomodify and \
origModFunct not in (None, modNull):
withRefs = True
value = self.get(key)
if value is None:
return None
tag = self.__class__.__name__.lower()
return u''.join(_seq2xml({key: value}, withRefs=withRefs,
modFunct=origModFunct,
titlesRefs=self.titlesRefs,
namesRefs=self.namesRefs,
charactersRefs=self.charactersRefs,
key2infoset=self.key2infoset,
fullpath=tag))
finally:
self.modFunct = origModFunct
def asXML(self, _with_add_keys=True):
"""Return a XML representation of the whole object.
If _with_add_keys is False, dinamically generated keys are excluded."""
beginTag, endTag = _tag4TON(self, addAccessSystem=True,
_containerOnly=True)
resList = [beginTag]
for key in self.keys():
value = self.getAsXML(key, _with_add_keys=_with_add_keys)
if not value:
continue
resList.append(value)
resList.append(endTag)
head = _xmlHead % self.__class__.__name__.lower()
return head + u''.join(resList)
def _getitem(self, key):
"""Handle special keys."""
return None
def __getitem__(self, key):
"""Return the value for a given key, checking key aliases;
a KeyError exception is raised if the key is not found.
"""
value = self._getitem(key)
if value is not None: return value
# Handle key aliases.
key = self.keys_alias.get(key, key)
rawData = self.data[key]
if key in self.keys_tomodify and \
self.modFunct not in (None, modNull):
try:
return modifyStrings(rawData, self.modFunct, self.titlesRefs,
self.namesRefs, self.charactersRefs)
except RuntimeError, e:
# Symbian/python 2.2 has a poor regexp implementation.
import warnings
warnings.warn('RuntimeError in '
"imdb.utils._Container.__getitem__; if it's not "
"a recursion limit exceeded and we're not running "
"in a Symbian environment, it's a bug:\n%s" % e)
return rawData
def __setitem__(self, key, item):
"""Directly store the item with the given key."""
self.data[key] = item
def __delitem__(self, key):
"""Remove the given section or key."""
# XXX: how to remove an item of a section?
del self.data[key]
def _additional_keys(self):
"""Valid keys to append to the data.keys() list."""
return []
def keys(self):
"""Return a list of valid keys."""
return self.data.keys() + self._additional_keys()
def items(self):
"""Return the items in the dictionary."""
return [(k, self.get(k)) for k in self.keys()]
# XXX: is this enough?
def iteritems(self): return self.data.iteritems()
def iterkeys(self): return self.data.iterkeys()
def itervalues(self): return self.data.itervalues()
def values(self):
"""Return the values in the dictionary."""
return [self.get(k) for k in self.keys()]
def has_key(self, key):
"""Return true if a given section is defined."""
try:
self.__getitem__(key)
except KeyError:
return 0
return 1
# XXX: really useful???
# consider also that this will confuse people who meant to
# call ia.update(movieObject, 'data set') instead.
def update(self, dict):
self.data.update(dict)
def get(self, key, failobj=None):
"""Return the given section, or default if it's not found."""
try:
return self.__getitem__(key)
except KeyError:
return failobj
def setdefault(self, key, failobj=None):
if not self.has_key(key):
self[key] = failobj
return self[key]
def pop(self, key, *args):
return self.data.pop(key, *args)
def popitem(self):
return self.data.popitem()
def __repr__(self):
"""String representation of an object."""
raise NotImplementedError('override this method')
def __str__(self):
"""Movie title or person name."""
raise NotImplementedError('override this method')
def __contains__(self, key):
raise NotImplementedError('override this method')
def append_item(self, key, item):
"""The item is appended to the list identified by the given key."""
self.data.setdefault(key, []).append(item)
def set_item(self, key, item):
"""Directly store the item with the given key."""
self.data[key] = item
def __nonzero__(self):
"""Return true if self.data contains something."""
if self.data: return 1
return 0
def __deepcopy__(self, memo):
raise NotImplementedError('override this method')
def copy(self):
"""Return a deep copy of the object itself."""
return deepcopy(self)
def flatten(seq, toDescend=(list, dict, tuple), yieldDictKeys=0,
onlyKeysType=(_Container,), scalar=None):
"""Iterate over nested lists and dictionaries; toDescend is a list
or a tuple of types to be considered non-scalar; if yieldDictKeys is
true, also dictionaries' keys are yielded; if scalar is not None, only
items of the given type(s) are yielded."""
if scalar is None or isinstance(seq, scalar):
yield seq
if isinstance(seq, toDescend):
if isinstance(seq, (dict, _Container)):
if yieldDictKeys:
# Yield also the keys of the dictionary.
for key in seq.iterkeys():
for k in flatten(key, toDescend=toDescend,
yieldDictKeys=yieldDictKeys,
onlyKeysType=onlyKeysType, scalar=scalar):
if onlyKeysType and isinstance(k, onlyKeysType):
yield k
for value in seq.itervalues():
for v in flatten(value, toDescend=toDescend,
yieldDictKeys=yieldDictKeys,
onlyKeysType=onlyKeysType, scalar=scalar):
yield v
elif not isinstance(seq, (str, unicode, int, float)):
for item in seq:
for i in flatten(item, toDescend=toDescend,
yieldDictKeys=yieldDictKeys,
onlyKeysType=onlyKeysType, scalar=scalar):
yield i
| gpl-3.0 | [
624,
199,
1208,
859,
334,
17117,
2559,
680,
199,
199,
2765,
859,
6571,
5678,
15841,
367,
314,
18232,
2559,
14,
199,
199,
7384,
8353,
13,
7409,
577,
65,
5624,
4580,
605,
26455,
665,
983,
32,
281,
32047,
14,
5135,
14,
390,
30,
2049,
8937,
869,
14,
377,
17629,
337,
738,
89,
285,
665,
29514,
285,
32,
266,
75,
723,
14,
1308,
30,
199,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
16952,
199,
646,
295,
199,
646,
1059,
199,
646,
2050,
199,
504,
1331,
492,
1331,
12,
14800,
199,
504,
900,
492,
620,
9367,
12,
14053,
199,
199,
504,
18232,
492,
15945,
199,
504,
18232,
492,
634,
14659,
631,
2932,
199,
504,
18232,
423,
3924,
492,
473,
5127,
66,
21811,
421,
199,
3,
15996,
367,
18232,
14,
1208,
859,
14,
199,
63,
1208,
63,
2921,
275,
2050,
14,
5572,
360,
17117,
647,
14,
1208,
358,
199,
199,
3,
710,
5578,
3965,
367,
314,
298,
2809,
2,
5361,
1475,
402,
473,
5127,
66,
12,
2839,
199,
3,
7340,
23756,
2924,
436,
7340,
1167,
1184,
15,
8921,
4186,
2382,
314,
2716,
221,
20971,
1329,
334,
9099,
473,
1240,
199,
3,
298,
17117,
2681,
2,
2410,
314,
14457,
365,
1202,
367,
1303,
14484,
543,
314,
2011,
2538,
199,
3,
436,
5361,
402,
4683,
14,
199,
3,
5787,
26,
8646,
491,
12,
445,
12,
577,
436,
603,
787,
12474,
4634,
8298,
1,
8700,
13,
9,
199,
264,
63,
3403,
63,
1080,
275,
295,
14,
2014,
8,
82,
1154,
27123,
16,
13,
25,
29635,
8194,
20,
22999,
32418,
6882,
56,
7027,
17751,
23763,
2862,
5942,
199,
264,
63,
10525,
63,
3403,
63,
1080,
275,
295,
14,
2014,
8,
82,
1154,
1332,
12764,
11052,
92,
12764,
12403,
92,
12764,
20536,
13,
5602,
92,
12764,
92,
9166,
92,
9166,
25132,
5547,
5805,
17304,
7766,
16,
13,
25,
29635,
8194,
20,
1552,
5169,
13,
59,
16,
13,
25,
29635,
8194,
20,
1552,
17076,
5169,
15,
779,
6882,
56,
7027,
17751,
23763,
5547,
60,
5942,
199,
264,
63,
2168,
63,
5091,
275,
295,
14,
2014,
8,
82,
1154,
1332,
12764,
11052,
92,
12764,
12403,
92,
12764,
20536,
13,
5602,
92,
12764,
92,
9166,
92,
9166,
25132,
5547,
5805,
358,
199,
199,
3,
9814,
1454,
314,
18232,
2681,
334,
509,
536,
3326,
680,
199,
264,
63,
1080,
275,
295,
14,
2014,
8,
82,
15542,
27123,
6882,
56,
7027,
17751,
18096,
9,
9988,
199,
199,
3,
9814,
7645,
6272,
23592,
14,
199,
264,
63,
25510,
275,
295,
14,
2014,
8,
82,
13445,
8,
17910,
28435,
199,
199,
3,
9814,
314,
1329,
402,
30060,
14,
199,
264,
63,
22027,
275,
295,
14,
2014,
2258,
83,
8995,
1332,
60,
68,
8771,
30060,
60,
3196,
295,
14,
41,
9,
199,
264,
63,
9544,
63,
815,
275,
295,
14,
2014,
8,
82,
7,
12911,
83,
5830,
11198,
5547,
60,
83,
31,
2961,
779,
16,
13,
25,
29635,
8194,
20,
17063,
59,
16,
13,
25,
29635,
8194,
17,
12,
18,
17063,
59,
16,
13,
25,
29635,
8194,
17,
12,
18,
4988,
430,
8995,
83,
31,
2961,
27496,
59,
16,
13,
25,
2807,
27658,
16,
13,
25,
24621,
22119,
12216,
199,
199,
3,
13964,
19475,
315,
308,
349,
14015,
14,
199,
63,
27469,
63,
16097,
275,
661,
271,
297,
283,
416,
297,
283,
424,
297,
283,
848,
297,
283,
2264,
297,
283,
89,
297,
283,
983,
297,
283,
20662,
297,
490,
283,
69,
297,
283,
86,
265,
297,
283,
1589,
297,
283,
328,
297,
283,
2033,
297,
283,
352,
297,
283,
279,
358,
199,
199,
318,
11358,
985,
8,
354,
304,
272,
408,
1767,
314,
1627,
536,
315,
11358,
298,
51,
21121,
12,
2812,
2,
1475,
14,
272,
2779,
15194,
626,
536,
365,
315,
314,
283,
985,
428,
21121,
7,
1475,
1041,
272,
327,
5787,
26,
2005,
11076,
334,
305,
402,
5557,
437,
2700,
9079,
12,
1806,
499,
1651,
1184,
1081,
1561,
304,
272,
327,
420,
446,
2951,
282,
308,
21121,
26,
463,
1227,
2635,
2114,
272,
327,
420,
446,
2849,
308,
21121,
12,
2849,
536,
26,
221,
25647,
2534,
1367,
272,
327,
420,
446,
26356,
308,
21121,
12,
26356,
536,
26,
1749,
26410,
272,
327,
420,
446,
26356,
308,
21121,
12,
2849,
536,
26,
221,
1227,
2114,
1690,
272,
327,
263,
334,
18,
26,
959,
2576,
772,
12,
650,
26,
1227,
16414,
12,
841,
26,
1520,
1651,
9,
272,
327,
420,
446,
2849,
308,
21121,
12,
26356,
536,
26,
5504,
1789,
709,
272,
327,
263,
334,
18,
26,
499,
10693,
1822,
12,
650,
26,
8806,
614,
12,
841,
26,
499,
10531,
12,
959,
26,
1227,
1216,
9,
272,
327,
420,
446,
1603,
82,
16781,
5939,
821,
272,
327,
7529,
1133,
3957,
1561,
2575,
315,
314,
11358,
1475,
14,
272,
340,
536,
14,
1623,
5102,
5320,
1137,
446,
17,
26,
372,
536,
272,
340,
1228,
8,
354,
12,
2649,
304,
267,
4263,
281,
275,
399,
5956,
83,
12,
450,
83,
7,
267,
6296,
63,
904,
281,
275,
399,
5956,
83,
450,
83,
7,
267,
6296,
63,
2638,
275,
399,
7,
450,
83,
7,
267,
4601,
275,
399,
7,
283,
272,
587,
26,
267,
4263,
281,
275,
1543,
83,
12,
450,
83,
7,
267,
6296,
63,
904,
281,
275,
1543,
83,
450,
83,
7,
267,
6296,
63,
2638,
275,
283,
450,
83,
7,
267,
4601,
275,
283,
283,
272,
308,
354
] | [
199,
1208,
859,
334,
17117,
2559,
680,
199,
199,
2765,
859,
6571,
5678,
15841,
367,
314,
18232,
2559,
14,
199,
199,
7384,
8353,
13,
7409,
577,
65,
5624,
4580,
605,
26455,
665,
983,
32,
281,
32047,
14,
5135,
14,
390,
30,
2049,
8937,
869,
14,
377,
17629,
337,
738,
89,
285,
665,
29514,
285,
32,
266,
75,
723,
14,
1308,
30,
199,
199,
2765,
2240,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
27,
1902,
1015,
499,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2765,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
7911,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
31461,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
17732,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
199,
5556,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
21632,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
30216,
12,
3277,
2020,
8155,
15630,
10902,
12,
14453,
13540,
12,
8226,
12,
4828,
221,
15673,
13,
13421,
221,
8217,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
16952,
199,
646,
295,
199,
646,
1059,
199,
646,
2050,
199,
504,
1331,
492,
1331,
12,
14800,
199,
504,
900,
492,
620,
9367,
12,
14053,
199,
199,
504,
18232,
492,
15945,
199,
504,
18232,
492,
634,
14659,
631,
2932,
199,
504,
18232,
423,
3924,
492,
473,
5127,
66,
21811,
421,
199,
3,
15996,
367,
18232,
14,
1208,
859,
14,
199,
63,
1208,
63,
2921,
275,
2050,
14,
5572,
360,
17117,
647,
14,
1208,
358,
199,
199,
3,
710,
5578,
3965,
367,
314,
298,
2809,
2,
5361,
1475,
402,
473,
5127,
66,
12,
2839,
199,
3,
7340,
23756,
2924,
436,
7340,
1167,
1184,
15,
8921,
4186,
2382,
314,
2716,
221,
20971,
1329,
334,
9099,
473,
1240,
199,
3,
298,
17117,
2681,
2,
2410,
314,
14457,
365,
1202,
367,
1303,
14484,
543,
314,
2011,
2538,
199,
3,
436,
5361,
402,
4683,
14,
199,
3,
5787,
26,
8646,
491,
12,
445,
12,
577,
436,
603,
787,
12474,
4634,
8298,
1,
8700,
13,
9,
199,
264,
63,
3403,
63,
1080,
275,
295,
14,
2014,
8,
82,
1154,
27123,
16,
13,
25,
29635,
8194,
20,
22999,
32418,
6882,
56,
7027,
17751,
23763,
2862,
5942,
199,
264,
63,
10525,
63,
3403,
63,
1080,
275,
295,
14,
2014,
8,
82,
1154,
1332,
12764,
11052,
92,
12764,
12403,
92,
12764,
20536,
13,
5602,
92,
12764,
92,
9166,
92,
9166,
25132,
5547,
5805,
17304,
7766,
16,
13,
25,
29635,
8194,
20,
1552,
5169,
13,
59,
16,
13,
25,
29635,
8194,
20,
1552,
17076,
5169,
15,
779,
6882,
56,
7027,
17751,
23763,
5547,
60,
5942,
199,
264,
63,
2168,
63,
5091,
275,
295,
14,
2014,
8,
82,
1154,
1332,
12764,
11052,
92,
12764,
12403,
92,
12764,
20536,
13,
5602,
92,
12764,
92,
9166,
92,
9166,
25132,
5547,
5805,
358,
199,
199,
3,
9814,
1454,
314,
18232,
2681,
334,
509,
536,
3326,
680,
199,
264,
63,
1080,
275,
295,
14,
2014,
8,
82,
15542,
27123,
6882,
56,
7027,
17751,
18096,
9,
9988,
199,
199,
3,
9814,
7645,
6272,
23592,
14,
199,
264,
63,
25510,
275,
295,
14,
2014,
8,
82,
13445,
8,
17910,
28435,
199,
199,
3,
9814,
314,
1329,
402,
30060,
14,
199,
264,
63,
22027,
275,
295,
14,
2014,
2258,
83,
8995,
1332,
60,
68,
8771,
30060,
60,
3196,
295,
14,
41,
9,
199,
264,
63,
9544,
63,
815,
275,
295,
14,
2014,
8,
82,
7,
12911,
83,
5830,
11198,
5547,
60,
83,
31,
2961,
779,
16,
13,
25,
29635,
8194,
20,
17063,
59,
16,
13,
25,
29635,
8194,
17,
12,
18,
17063,
59,
16,
13,
25,
29635,
8194,
17,
12,
18,
4988,
430,
8995,
83,
31,
2961,
27496,
59,
16,
13,
25,
2807,
27658,
16,
13,
25,
24621,
22119,
12216,
199,
199,
3,
13964,
19475,
315,
308,
349,
14015,
14,
199,
63,
27469,
63,
16097,
275,
661,
271,
297,
283,
416,
297,
283,
424,
297,
283,
848,
297,
283,
2264,
297,
283,
89,
297,
283,
983,
297,
283,
20662,
297,
490,
283,
69,
297,
283,
86,
265,
297,
283,
1589,
297,
283,
328,
297,
283,
2033,
297,
283,
352,
297,
283,
279,
358,
199,
199,
318,
11358,
985,
8,
354,
304,
272,
408,
1767,
314,
1627,
536,
315,
11358,
298,
51,
21121,
12,
2812,
2,
1475,
14,
272,
2779,
15194,
626,
536,
365,
315,
314,
283,
985,
428,
21121,
7,
1475,
1041,
272,
327,
5787,
26,
2005,
11076,
334,
305,
402,
5557,
437,
2700,
9079,
12,
1806,
499,
1651,
1184,
1081,
1561,
304,
272,
327,
420,
446,
2951,
282,
308,
21121,
26,
463,
1227,
2635,
2114,
272,
327,
420,
446,
2849,
308,
21121,
12,
2849,
536,
26,
221,
25647,
2534,
1367,
272,
327,
420,
446,
26356,
308,
21121,
12,
26356,
536,
26,
1749,
26410,
272,
327,
420,
446,
26356,
308,
21121,
12,
2849,
536,
26,
221,
1227,
2114,
1690,
272,
327,
263,
334,
18,
26,
959,
2576,
772,
12,
650,
26,
1227,
16414,
12,
841,
26,
1520,
1651,
9,
272,
327,
420,
446,
2849,
308,
21121,
12,
26356,
536,
26,
5504,
1789,
709,
272,
327,
263,
334,
18,
26,
499,
10693,
1822,
12,
650,
26,
8806,
614,
12,
841,
26,
499,
10531,
12,
959,
26,
1227,
1216,
9,
272,
327,
420,
446,
1603,
82,
16781,
5939,
821,
272,
327,
7529,
1133,
3957,
1561,
2575,
315,
314,
11358,
1475,
14,
272,
340,
536,
14,
1623,
5102,
5320,
1137,
446,
17,
26,
372,
536,
272,
340,
1228,
8,
354,
12,
2649,
304,
267,
4263,
281,
275,
399,
5956,
83,
12,
450,
83,
7,
267,
6296,
63,
904,
281,
275,
399,
5956,
83,
450,
83,
7,
267,
6296,
63,
2638,
275,
399,
7,
450,
83,
7,
267,
4601,
275,
399,
7,
283,
272,
587,
26,
267,
4263,
281,
275,
1543,
83,
12,
450,
83,
7,
267,
6296,
63,
904,
281,
275,
1543,
83,
450,
83,
7,
267,
6296,
63,
2638,
275,
283,
450,
83,
7,
267,
4601,
275,
283,
283,
272,
308,
354,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
Hellowlol/PyTunes | modules/newznab.py | 1 | 9273 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
import cherrypy
import pytunes
import math
from pytunes.proxy import get_image
from urllib2 import urlopen, quote
from json import loads
import logging
class Newznab:
def __init__(self):
self.logger = logging.getLogger('modules.newznab')
pytunes.MODULES.append({
'name': 'Newznab Search',
'id': 'newznab',
'fields': [
{'type':'bool', 'label':'Enable', 'name':'newznab_enable'},
{'type':'text', 'label':'Menu name', 'name':'newznab_name', 'placeholder':''},
#{'type':'select',
# 'label':'Default NZB Client',
# 'name':'default_nzb_id',
# 'options':[],
# 'desc':'Only Enabled Clients Will Show'
#},
{'type':'text', 'label':'Console Category', 'name':'newznab_console', 'desc':'From Sabnzbd Configuration'},
{'type':'text', 'label':'Movies Category', 'name':'newznab_movies', 'desc':'From Sabnzbd Configuration'},
{'type':'text', 'label':'Audio Category', 'name':'newznab_audio', 'desc':'From Sabnzbd Configuration'},
{'type':'text', 'label':'PC Category', 'name':'newznab_pc', 'desc':'From Sabnzbd Configuration'},
{'type':'text', 'label':'TV Category', 'name':'newznab_tv', 'desc':'From Sabnzbd Configuration'},
{'type':'text', 'label':'XXX Category', 'name':'newznab_xxx', 'desc':'From Sabnzbd Configuration'},
{'type':'text', 'label':'Books Category', 'name':'newznab_books', 'desc':'From Sabnzbd Configuration'},
{'type':'text', 'label':'Other Category', 'name':'newznab_other', 'desc':'From Sabnzbd Configuration'}
]})
pytunes.MODULES.append({
'name': 'Newznab Servers',
'id': 'newznab_update_server',
'action': '%ssettings/setnewzserver' % pytunes.WEBDIR,
#'test': pytunes.WEBDIR + 'newznab/ping',
'fields': [
{'type':'select',
'label':'Newznab Servers',
'name':'newznab_server_id',
'options':[
{'name':'New', 'value':0}
]},
{'type':'text',
'label':'Name',
'name':'newznab_server_name'},
{'type':'text', 'label':'Host', 'name':'newznab_server_host'},
{'type':'text', 'label':'Apikey', 'name':'newznab_server_apikey'},
{'type':'bool', 'label':'Use SSL', 'name':'newznab_server_ssl'}
]})
@cherrypy.expose()
def index(self, query='', **kwargs):
return pytunes.LOOKUP.get_template('newznab.html').render(query=query, scriptname='newznab')
"""
NOT IMPLEMENTET
@cherrypy.expose()
@cherrypy.tools.json_out()
def ping(self, newznab_host, newznab_apikey, **kwargs):
self.logger.debug("Pinging newznab-host")
return 1
"""
@cherrypy.expose()
def thumb(self, url, h=None, w=None, o=100):
if url.startswith('rageid'):
settings = pytunes.settings
host = settings.get('newznab_host', '').replace('http://', '').replace('https://', '')
ssl = 's' if settings.get('newznab_ssl', 0) else ''
url = 'http%s://%s/covers/tv/%s.jpg' % (ssl, host, url[6:])
return get_image(url, h, w, o)
@cherrypy.expose()
def getcategories(self, **kwargs):
self.logger.debug("Fetching available categories")
ret = ''
try:
settings = pytunes.settings
self.current = settings.get_current_newznab_host()
host = self.current.host.replace('http://', '').replace('https://', '')
ssl = '' if self.current.ssl == '0' else 's'
apikey = self.current.apikey
url = 'http%s://%s/api?t=caps&o=xml' % (ssl, host)
self.logger.debug("Fetching Cat information from: %s" % url)
caps = urlopen(url, timeout=10).read()
lines = caps.split('\n')
opt_line = '<option value="%s">%s</option>'
for line in lines:
if 'category' in line and 'genre' not in line and not '/cat' in line:
junk,id,name = line.strip().split(' ')
id = id.split('"')[1]
main_name = name.split('"')[1]
ret += opt_line % (id, main_name)
if 'subcat' in line:
subcat = line.strip().split(' name')
id = subcat[0].split('"')[1]
name = '%s > %s' % (main_name, subcat[1].split('"')[1])
ret += opt_line % (id, name)
except:
self.logger.error('Unable to fetch categories from: %s' % url)
return ret
@cherrypy.expose()
def search(self, q='', cat='', **kwargs):
ret = ''
row = '<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>'
settings = pytunes.settings
sab_cat = {
'1000':settings.get('newznab_console', ''),
'2000':settings.get('newznab_movies', ''),
'3000':settings.get('newznab_audio', ''),
'4000':settings.get('newznab_pc', ''),
'5000':settings.get('newznab_tv', ''),
'6000':settings.get('newznab_xxx', ''),
'7000':settings.get('newznab_books', ''),
'8000':settings.get('newznab_other', '')
}
if cat:
cat = '&cat=%s' % cat
res = self.fetch('search&q=%s%s&extended=1' % (quote(q), cat))
#put in staticvars
link = "<a href='/newznab/AddNzbFromUrl?nzb_url=%s&nzb_category=%s' class='ajax-link' title='Download' cat='%s'><i class='icon-download-alt'></i></a>"
try:
results = res['channel']['item']
except:
results = res
grabs = '0'
for each in results:
files = str(each['attr'][4]['@attributes']['value'])
grabs = str(each['attr'][6]['@attributes']['value'])
category = each['category']
title = each['title']
cat = sab_cat[str(each['attr'][0]['@attributes']['value'])]
num = int(each['enclosure']['@attributes']['length'])
for x in [' bytes',' KB',' MB',' GB']:
if num < 1024.0:
size = "%3.2f%s" % (num, x)
break
num /= 1024.0
dl = link % (quote(each['link']), cat, cat)
ret += row % (title, category, size, files, grabs, dl)
return ret
@cherrypy.expose()
@cherrypy.tools.json_out()
def AddNzbFromUrl(self, nzb_url, nzb_category=''):
self.logger.debug("Adding nzb from url")
if nzb_category:
nzb_category = '&cat=%s' % nzb_category
return self.send('&mode=addurl&name=%s%s' % (quote(nzb_url), nzb_category))
def fetch(self, cmd):
try:
settings = pytunes.settings
self.current = settings.get_current_newznab_host()
host = self.current.host.replace('http://', '').replace('https://', '')
ssl = 's' if settings.get('newznab_ssl') == 'on' else ''
apikey = self.current.apikey
url = 'http%s://%s/api?o=json&apikey=%s&t=%s' ( ssl, host, apikey, cmd)
self.logger.debug("Fetching information from: %s" % url)
return loads(urlopen(url, timeout=30).read())
except Exception, e:
self.logger.debug("Exception%s: " % str(e))
self.logger.error("Unable to fetch information from: newznab %s" % str(e))
def send(self, link):
try:
host = pytunes.settings.get('sabnzbd_host', '')
port = str(pytunes.settings.get('sabnzbd_port', ''))
apikey = pytunes.settings.get('sabnzbd_apikey', '')
sabnzbd_basepath = pytunes.settings.get('sabnzbd_basepath', '/sabnzbd/')
ssl = 's' if pytunes.settings.get('sabnzbd_ssl', 0) else ''
if(sabnzbd_basepath == ""):
sabnzbd_basepath = "/sabnzbd/"
if not(sabnzbd_basepath.endswith('/')):
sabnzbd_basepath += "/"
url = 'http%s://%s:%s%sapi?output=json&apikey=%s%s' % (ssl, host, port, sabnzbd_basepath, apikey, link)
self.logger.debug("Sending NZB to: %s: " % url)
return loads(urlopen(url, timeout=10).read())
except:
self.logger.error("Cannot contact sabnzbd")
return
#Future use...use staticvars
@cherrypy.expose()
def GetClients(self):
nzbclients = ''
if pytunes.settings.get('nzbget_enable', ''):
nzbclients += '<option id="nzbget">NZBget</option>'
if pytunes.settings.get('sabnzbd_enable', ''):
nzbclients += '<option id="sabnzbd">Sabnzbd+</option>'
if not nzbclients:
nzbclients = '<option>No Clients Enabled</option>'
return nzbclients
| gpl-3.0 | [
3381,
2647,
15,
1393,
15,
1813,
2366,
202,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
2999,
199,
646,
13397,
202,
199,
646,
1134,
10032,
397,
202,
199,
646,
3473,
202,
199,
504,
1134,
10032,
397,
14,
3280,
492,
664,
63,
1569,
202,
199,
504,
4011,
18,
492,
18279,
12,
6313,
202,
199,
504,
2022,
492,
14404,
202,
199,
646,
2050,
2999,
199,
533,
7053,
31591,
371,
26,
1128,
347,
636,
826,
721,
277,
304,
1039,
291,
14,
2921,
275,
2050,
14,
5572,
360,
3112,
14,
1222,
31591,
371,
358,
1039,
1134,
10032,
397,
14,
21194,
14,
740,
2561,
1675,
283,
354,
356,
283,
4665,
31591,
371,
8730,
297,
1675,
283,
344,
356,
283,
1222,
31591,
371,
297,
1675,
283,
955,
356,
359,
2628,
791,
466,
5242,
2245,
297,
283,
1302,
5242,
6476,
297,
283,
354,
5242,
1222,
31591,
371,
63,
4296,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
5977,
536,
297,
283,
354,
5242,
1222,
31591,
371,
63,
354,
297,
283,
6199,
356,
891,
1386,
2628,
327,
1445,
466,
5242,
2416,
297,
2628,
327,
283,
1302,
5242,
2698,
653,
58,
34,
6810,
297,
2628,
327,
283,
354,
5242,
885,
63,
15291,
66,
63,
344,
297,
2628,
327,
283,
1419,
15211,
467,
2628,
327,
283,
3257,
5242,
5903,
3447,
1909,
6810,
83,
12823,
12968,
7,
221,
2628,
327,
1386,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
9270,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
6614,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
3716,
14484,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
20888,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
15484,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
8130,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
4222,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
2352,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
12764,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
6993,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
13933,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
10013,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
8696,
83,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
8858,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
8632,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
1848,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
936,
1039,
1622,
1552,
4341,
1134,
10032,
397,
14,
21194,
14,
740,
2561,
1675,
283,
354,
356,
283,
4665,
31591,
371,
7146,
83,
297,
1675,
283,
344,
356,
283,
1222,
31591,
371,
63,
873,
63,
1000,
297,
1675,
283,
1287,
356,
1543,
83,
1751,
15,
409,
1222,
90,
1000,
7,
450,
1134,
10032,
397,
14,
13166,
3022,
12,
1675,
17384,
396,
356,
1134,
10032,
397,
14,
13166,
3022,
435,
283,
1222,
31591,
371,
15,
4073,
297,
1675,
283,
955,
356,
359,
2628,
791,
466,
5242,
2416,
297,
20085,
283,
1302,
5242,
4665,
31591,
371,
7146,
83,
297,
20085,
283,
354,
5242,
1222,
31591,
371,
63,
1000,
63,
344,
297,
20085,
283,
1419,
15211,
4906,
791,
354,
5242,
4665,
297,
283,
585,
356,
16,
93,
2628,
1622,
1386,
2628,
791,
466,
5242,
505,
297,
20085,
283,
1302,
5242,
985,
297,
20085,
283,
354,
5242,
1222,
31591,
371,
63,
1000,
63,
354,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
4965,
297,
283,
354,
5242,
1222,
31591,
371,
63,
1000,
63,
1102,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
7394,
498,
297,
283,
354,
5242,
1222,
31591,
371,
63,
1000,
63,
28181,
2267,
2628,
791,
466,
5242,
2245,
297,
283,
1302,
5242,
6119,
7799,
297,
283,
354,
5242,
1222,
31591,
371,
63,
1000,
63,
4266,
936,
1039,
1622,
1552,
2958,
768,
23438,
14,
20586,
342,
1128,
347,
1478,
8,
277,
12,
1827,
4581,
1011,
958,
304,
1039,
372,
1134,
10032,
397,
14,
29149,
14,
362,
63,
1160,
360,
1222,
31591,
371,
14,
1360,
1959,
3352,
8,
1131,
29,
1131,
12,
2884,
354,
534,
1222,
31591,
371,
358,
2958,
408,
1128,
2845,
5025,
10320,
775,
1128,
768,
23438,
14,
20586,
342,
1128,
768,
23438,
14,
2537,
14,
1001,
63,
548,
342,
1128,
347,
18249,
8,
277,
12,
892,
31591,
371,
63,
1102,
12,
892,
31591,
371,
63,
28181,
12,
1011,
958,
304,
1039,
291,
14,
2921,
14,
1757,
480,
22638,
316,
892,
31591,
371,
13,
1102,
531,
1039,
372,
413,
1128,
408,
2958,
768,
23438,
14,
20586,
342,
1128,
347,
21541,
8,
277,
12,
1166,
12,
394,
29,
403,
12,
336,
29,
403,
12,
312,
29,
1960,
304,
1039,
340,
1166,
14,
2460,
360,
28812,
344,
735,
1675,
2202,
275,
1134,
10032,
397,
14,
1751,
1675,
1591,
275,
2202,
14,
362,
360,
1222,
31591,
371,
63,
1102,
297,
12548,
1814,
360,
1014,
921,
297,
12548,
1814,
360,
2859,
921,
297,
4074,
1675,
6149,
275,
283,
83,
7,
340,
2202,
14,
362,
360,
1222,
31591,
371,
63,
4266,
297,
378,
9,
587,
2125,
11556,
1166,
275,
283,
1014,
5,
83,
13827,
83,
15,
5899,
83,
15,
6993,
3149,
83,
14,
8476,
7,
450,
334,
4266,
12,
1591,
12,
1166,
59,
22,
5728,
4341,
372,
664,
63,
1569,
8,
633,
12,
394,
12,
336,
12,
312,
9,
2958,
768,
23438,
14,
20586,
342,
1128,
347,
664,
8906,
8,
277,
12,
1011,
958,
304,
1039,
291,
14,
2921,
14,
1757,
480,
11135,
316,
2808,
9695,
531,
1039,
2203,
275,
2125,
1039,
862,
26,
1675,
2202,
275,
1134,
10032,
397,
14,
1751,
1675,
291,
14,
1818,
275,
2202,
14,
362,
63,
1818,
63,
1222,
31591,
371,
63,
1102,
342,
1675,
1591,
275,
291,
14,
1818,
14,
1102,
14,
1814,
360,
1014,
921,
297,
12548,
1814,
360,
2859,
921,
297,
4074,
1675,
6149,
275,
2125
] | [
2647,
15,
1393,
15,
1813,
2366,
202,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
2999,
199,
646,
13397,
202,
199,
646,
1134,
10032,
397,
202,
199,
646,
3473,
202,
199,
504,
1134,
10032,
397,
14,
3280,
492,
664,
63,
1569,
202,
199,
504,
4011,
18,
492,
18279,
12,
6313,
202,
199,
504,
2022,
492,
14404,
202,
199,
646,
2050,
2999,
199,
533,
7053,
31591,
371,
26,
1128,
347,
636,
826,
721,
277,
304,
1039,
291,
14,
2921,
275,
2050,
14,
5572,
360,
3112,
14,
1222,
31591,
371,
358,
1039,
1134,
10032,
397,
14,
21194,
14,
740,
2561,
1675,
283,
354,
356,
283,
4665,
31591,
371,
8730,
297,
1675,
283,
344,
356,
283,
1222,
31591,
371,
297,
1675,
283,
955,
356,
359,
2628,
791,
466,
5242,
2245,
297,
283,
1302,
5242,
6476,
297,
283,
354,
5242,
1222,
31591,
371,
63,
4296,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
5977,
536,
297,
283,
354,
5242,
1222,
31591,
371,
63,
354,
297,
283,
6199,
356,
891,
1386,
2628,
327,
1445,
466,
5242,
2416,
297,
2628,
327,
283,
1302,
5242,
2698,
653,
58,
34,
6810,
297,
2628,
327,
283,
354,
5242,
885,
63,
15291,
66,
63,
344,
297,
2628,
327,
283,
1419,
15211,
467,
2628,
327,
283,
3257,
5242,
5903,
3447,
1909,
6810,
83,
12823,
12968,
7,
221,
2628,
327,
1386,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
9270,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
6614,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
3716,
14484,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
20888,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
15484,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
8130,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
4222,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
2352,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
12764,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
6993,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
13933,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
10013,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
8696,
83,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
8858,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
8632,
13573,
297,
283,
354,
5242,
1222,
31591,
371,
63,
1848,
297,
283,
3257,
5242,
2532,
428,
371,
15291,
3691,
11595,
936,
1039,
1622,
1552,
4341,
1134,
10032,
397,
14,
21194,
14,
740,
2561,
1675,
283,
354,
356,
283,
4665,
31591,
371,
7146,
83,
297,
1675,
283,
344,
356,
283,
1222,
31591,
371,
63,
873,
63,
1000,
297,
1675,
283,
1287,
356,
1543,
83,
1751,
15,
409,
1222,
90,
1000,
7,
450,
1134,
10032,
397,
14,
13166,
3022,
12,
1675,
17384,
396,
356,
1134,
10032,
397,
14,
13166,
3022,
435,
283,
1222,
31591,
371,
15,
4073,
297,
1675,
283,
955,
356,
359,
2628,
791,
466,
5242,
2416,
297,
20085,
283,
1302,
5242,
4665,
31591,
371,
7146,
83,
297,
20085,
283,
354,
5242,
1222,
31591,
371,
63,
1000,
63,
344,
297,
20085,
283,
1419,
15211,
4906,
791,
354,
5242,
4665,
297,
283,
585,
356,
16,
93,
2628,
1622,
1386,
2628,
791,
466,
5242,
505,
297,
20085,
283,
1302,
5242,
985,
297,
20085,
283,
354,
5242,
1222,
31591,
371,
63,
1000,
63,
354,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
4965,
297,
283,
354,
5242,
1222,
31591,
371,
63,
1000,
63,
1102,
2267,
2628,
791,
466,
5242,
505,
297,
283,
1302,
5242,
7394,
498,
297,
283,
354,
5242,
1222,
31591,
371,
63,
1000,
63,
28181,
2267,
2628,
791,
466,
5242,
2245,
297,
283,
1302,
5242,
6119,
7799,
297,
283,
354,
5242,
1222,
31591,
371,
63,
1000,
63,
4266,
936,
1039,
1622,
1552,
2958,
768,
23438,
14,
20586,
342,
1128,
347,
1478,
8,
277,
12,
1827,
4581,
1011,
958,
304,
1039,
372,
1134,
10032,
397,
14,
29149,
14,
362,
63,
1160,
360,
1222,
31591,
371,
14,
1360,
1959,
3352,
8,
1131,
29,
1131,
12,
2884,
354,
534,
1222,
31591,
371,
358,
2958,
408,
1128,
2845,
5025,
10320,
775,
1128,
768,
23438,
14,
20586,
342,
1128,
768,
23438,
14,
2537,
14,
1001,
63,
548,
342,
1128,
347,
18249,
8,
277,
12,
892,
31591,
371,
63,
1102,
12,
892,
31591,
371,
63,
28181,
12,
1011,
958,
304,
1039,
291,
14,
2921,
14,
1757,
480,
22638,
316,
892,
31591,
371,
13,
1102,
531,
1039,
372,
413,
1128,
408,
2958,
768,
23438,
14,
20586,
342,
1128,
347,
21541,
8,
277,
12,
1166,
12,
394,
29,
403,
12,
336,
29,
403,
12,
312,
29,
1960,
304,
1039,
340,
1166,
14,
2460,
360,
28812,
344,
735,
1675,
2202,
275,
1134,
10032,
397,
14,
1751,
1675,
1591,
275,
2202,
14,
362,
360,
1222,
31591,
371,
63,
1102,
297,
12548,
1814,
360,
1014,
921,
297,
12548,
1814,
360,
2859,
921,
297,
4074,
1675,
6149,
275,
283,
83,
7,
340,
2202,
14,
362,
360,
1222,
31591,
371,
63,
4266,
297,
378,
9,
587,
2125,
11556,
1166,
275,
283,
1014,
5,
83,
13827,
83,
15,
5899,
83,
15,
6993,
3149,
83,
14,
8476,
7,
450,
334,
4266,
12,
1591,
12,
1166,
59,
22,
5728,
4341,
372,
664,
63,
1569,
8,
633,
12,
394,
12,
336,
12,
312,
9,
2958,
768,
23438,
14,
20586,
342,
1128,
347,
664,
8906,
8,
277,
12,
1011,
958,
304,
1039,
291,
14,
2921,
14,
1757,
480,
11135,
316,
2808,
9695,
531,
1039,
2203,
275,
2125,
1039,
862,
26,
1675,
2202,
275,
1134,
10032,
397,
14,
1751,
1675,
291,
14,
1818,
275,
2202,
14,
362,
63,
1818,
63,
1222,
31591,
371,
63,
1102,
342,
1675,
1591,
275,
291,
14,
1818,
14,
1102,
14,
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
] |
3dfxmadscientist/cbss-server | addons/base_vat/__openerp__.py | 125 | 2928 | # -*- 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/>.
#
##############################################################################
{
'name': 'VAT Number Validation',
'version': '1.0',
'category': 'Hidden/Dependency',
'description': """
VAT validation for Partner's VAT numbers.
=========================================
After installing this module, values entered in the VAT field of Partners will
be validated for all supported countries. The country is inferred from the
2-letter country code that prefixes the VAT number, e.g. ``BE0477472701``
will be validated using the Belgian rules.
There are two different levels of VAT number validation:
--------------------------------------------------------
* By default, a simple off-line check is performed using the known validation
rules for the country, usually a simple check digit. This is quick and
always available, but allows numbers that are perhaps not truly allocated,
or not valid anymore.
* When the "VAT VIES Check" option is enabled (in the configuration of the user's
Company), VAT numbers will be instead submitted to the online EU VIES
database, which will truly verify that the number is valid and currently
allocated to a EU company. This is a little bit slower than the simple
off-line check, requires an Internet connection, and may not be available
all the time. If the service is not available or does not support the
requested country (e.g. for non-EU countries), a simple check will be performed
instead.
Supported countries currently include EU countries, and a few non-EU countries
such as Chile, Colombia, Mexico, Norway or Russia. For unsupported countries,
only the country code will be validated.
""",
'author': 'OpenERP SA',
'depends': ['account'],
'website': 'http://www.openerp.com',
'data': ['base_vat_view.xml'],
'installable': True,
'auto_install': False,
'images': ['images/1_partner_vat.jpeg'],
}
# 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,
91,
272,
283,
354,
356,
283,
54,
619,
4860,
19381,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
14983,
15,
14403,
297,
272,
283,
1802,
356,
408,
199,
54,
619,
6411,
367,
31351,
1159,
812,
619,
5579,
14,
199,
2486,
15495,
199,
199,
10881,
22200,
642,
859,
12,
1338,
19138,
315,
314,
812,
619,
901,
402,
14320,
8715,
911,
199,
1235,
16468,
367,
1006,
3748,
26013,
14,
710,
9023,
365,
22515,
687,
314,
199,
18,
13,
9269,
9023,
1233,
626,
13158,
314,
812,
619,
1329,
12,
325,
14,
71,
14,
1124,
6773,
966,
1138,
2417,
1465,
614,
1040,
199,
14117,
506,
16468,
1808,
314,
699,
352,
71,
5653,
4713,
14,
199,
199,
10924,
787,
2877,
3365,
11106,
402,
812,
619,
1329,
6411,
26,
199,
6489,
518,
272,
627,
4885,
849,
12,
282,
3486,
2331,
13,
604,
1104,
365,
10585,
1808,
314,
6040,
6411,
489,
4713,
367,
314,
9023,
12,
9987,
282,
3486,
1104,
10964,
14,
961,
365,
12530,
436,
15166,
3544,
2808,
12,
1325,
6127,
5579,
626,
787,
25358,
440,
5651,
21797,
17659,
12,
489,
503,
440,
1686,
20827,
14,
2126,
272,
627,
3979,
314,
298,
54,
619,
812,
2563,
2670,
2,
945,
365,
5223,
334,
262,
314,
2897,
402,
314,
922,
1159,
489,
15878,
395,
812,
619,
5579,
911,
506,
3140,
16930,
370,
314,
18470,
26007,
812,
2563,
489,
3050,
12,
1314,
911,
5651,
21797,
4911,
626,
314,
1329,
365,
1686,
436,
5544,
489,
17659,
370,
282,
26007,
7233,
14,
961,
365,
282,
12050,
4546,
26200,
2419,
314,
3486,
489,
2331,
13,
604,
1104,
12,
5074,
376,
22026,
1950,
12,
436,
1443,
440,
506,
2808,
489,
1006,
314,
900,
14,
982,
314,
2435,
365,
440,
2808,
503,
1630,
440,
2291,
314,
489,
5839,
9023,
334,
69,
14,
71,
14,
367,
2222,
13,
23539,
26013,
395,
282,
3486,
1104,
911,
506,
10585,
489,
3140,
14,
199,
199,
10682,
26013,
5544,
2387,
26007,
26013,
12,
436,
282,
9284,
2222,
13,
23539,
26013,
199,
10180,
465,
2799,
441,
12,
1849,
320,
887,
4674,
12,
603,
476,
12802,
12,
653,
269,
3316,
503,
820,
527,
10971,
14,
2104,
16313,
26013,
12,
199,
2118,
314,
9023,
1233,
911,
506,
16468,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
8912,
356,
788,
2048,
995,
272,
283,
7360,
356,
283,
1014,
921,
1544,
14,
11267,
14,
957,
297,
272,
283,
576,
356,
788,
1095,
63,
16305,
63,
1345,
14,
1652,
995,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
4782,
356,
788,
4782,
15,
17,
63,
3899,
63,
16305,
14,
14230,
995,
199,
93,
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
] | [
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,
91,
272,
283,
354,
356,
283,
54,
619,
4860,
19381,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
14983,
15,
14403,
297,
272,
283,
1802,
356,
408,
199,
54,
619,
6411,
367,
31351,
1159,
812,
619,
5579,
14,
199,
2486,
15495,
199,
199,
10881,
22200,
642,
859,
12,
1338,
19138,
315,
314,
812,
619,
901,
402,
14320,
8715,
911,
199,
1235,
16468,
367,
1006,
3748,
26013,
14,
710,
9023,
365,
22515,
687,
314,
199,
18,
13,
9269,
9023,
1233,
626,
13158,
314,
812,
619,
1329,
12,
325,
14,
71,
14,
1124,
6773,
966,
1138,
2417,
1465,
614,
1040,
199,
14117,
506,
16468,
1808,
314,
699,
352,
71,
5653,
4713,
14,
199,
199,
10924,
787,
2877,
3365,
11106,
402,
812,
619,
1329,
6411,
26,
199,
6489,
518,
272,
627,
4885,
849,
12,
282,
3486,
2331,
13,
604,
1104,
365,
10585,
1808,
314,
6040,
6411,
489,
4713,
367,
314,
9023,
12,
9987,
282,
3486,
1104,
10964,
14,
961,
365,
12530,
436,
15166,
3544,
2808,
12,
1325,
6127,
5579,
626,
787,
25358,
440,
5651,
21797,
17659,
12,
489,
503,
440,
1686,
20827,
14,
2126,
272,
627,
3979,
314,
298,
54,
619,
812,
2563,
2670,
2,
945,
365,
5223,
334,
262,
314,
2897,
402,
314,
922,
1159,
489,
15878,
395,
812,
619,
5579,
911,
506,
3140,
16930,
370,
314,
18470,
26007,
812,
2563,
489,
3050,
12,
1314,
911,
5651,
21797,
4911,
626,
314,
1329,
365,
1686,
436,
5544,
489,
17659,
370,
282,
26007,
7233,
14,
961,
365,
282,
12050,
4546,
26200,
2419,
314,
3486,
489,
2331,
13,
604,
1104,
12,
5074,
376,
22026,
1950,
12,
436,
1443,
440,
506,
2808,
489,
1006,
314,
900,
14,
982,
314,
2435,
365,
440,
2808,
503,
1630,
440,
2291,
314,
489,
5839,
9023,
334,
69,
14,
71,
14,
367,
2222,
13,
23539,
26013,
395,
282,
3486,
1104,
911,
506,
10585,
489,
3140,
14,
199,
199,
10682,
26013,
5544,
2387,
26007,
26013,
12,
436,
282,
9284,
2222,
13,
23539,
26013,
199,
10180,
465,
2799,
441,
12,
1849,
320,
887,
4674,
12,
603,
476,
12802,
12,
653,
269,
3316,
503,
820,
527,
10971,
14,
2104,
16313,
26013,
12,
199,
2118,
314,
9023,
1233,
911,
506,
16468,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
8912,
356,
788,
2048,
995,
272,
283,
7360,
356,
283,
1014,
921,
1544,
14,
11267,
14,
957,
297,
272,
283,
576,
356,
788,
1095,
63,
16305,
63,
1345,
14,
1652,
995,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
272,
283,
4782,
356,
788,
4782,
15,
17,
63,
3899,
63,
16305,
14,
14230,
995,
199,
93,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
freelawproject/recap-server | settings.py | 1 | 1377 | """Settings are derived by compiling any files ending in .py in the settings
directory, in alphabetical order.
This results in the following concept:
- default settings are in 10-public.py (this should contain most settings)
- custom settings are in 05-private.py (an example of this file is here for
you)
- any overrides to public settings can go in 20-private.py (you'll need to
create this)
"""
from __future__ import with_statement
import os
import glob
import sys
def _generate_secret_key(file_path):
import random
chars = 'abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)'
def random_char():
return chars[int(len(chars)*random.random())]
rand_str = ''.join(random_char() for i in range(64))
with open(file_path, 'w') as f:
f.write('SECRET_KEY=%s\n' % repr(rand_str))
ROOT_PATH = os.path.dirname(__file__)
# Try importing the SECRET_KEY from the file secret_key.py. If it doesn't exist,
# there is an import error, and the key is generated and written to the file.
try:
from secret_key import SECRET_KEY
except ImportError:
_generate_secret_key(os.path.join(ROOT_PATH, 'secret_key.py'))
from secret_key import SECRET_KEY
# Load the conf files.
conf_files = glob.glob(os.path.join(
os.path.dirname(__file__), 'settings', '*.py'))
conf_files.sort()
for f in conf_files:
execfile(os.path.abspath(f))
| gpl-3.0 | [
624,
5268,
787,
7131,
701,
1013,
5662,
1263,
1584,
13401,
315,
1275,
647,
315,
314,
2202,
199,
3619,
12,
315,
23331,
3294,
1865,
14,
199,
199,
2765,
2058,
315,
314,
2569,
19834,
26,
199,
446,
849,
2202,
787,
315,
1616,
13,
3455,
14,
647,
334,
3749,
1077,
1395,
4750,
2202,
9,
199,
446,
3537,
2202,
787,
315,
22528,
13,
4239,
14,
647,
334,
290,
2893,
402,
642,
570,
365,
2348,
367,
2043,
1265,
9,
199,
446,
1263,
10580,
370,
4575,
2202,
883,
2621,
315,
3388,
13,
4239,
14,
647,
334,
13297,
7171,
1929,
370,
2043,
1218,
642,
9,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
646,
747,
199,
646,
5739,
199,
646,
984,
421,
199,
318,
485,
4208,
63,
4731,
63,
498,
8,
493,
63,
515,
304,
272,
492,
2196,
272,
8365,
275,
283,
23459,
11371,
1,
32,
3,
22074,
62,
6,
27436,
10683,
29600,
339,
347,
2196,
63,
1560,
837,
267,
372,
8365,
59,
442,
8,
552,
8,
6574,
3342,
2355,
14,
2355,
24821,
272,
10261,
63,
495,
275,
6522,
904,
8,
2355,
63,
1560,
342,
367,
284,
315,
1425,
8,
772,
430,
272,
543,
1551,
8,
493,
63,
515,
12,
283,
87,
358,
465,
289,
26,
267,
289,
14,
952,
360,
12961,
63,
3078,
2458,
83,
60,
78,
7,
450,
4700,
8,
3759,
63,
495,
430,
199,
199,
5441,
63,
3243,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
199,
3,
7649,
16306,
314,
5795,
11771,
63,
3078,
687,
314,
570,
7565,
63,
498,
14,
647,
14,
982,
652,
3181,
1133,
2187,
12,
199,
3,
2337,
365,
376,
492,
1125,
12,
436,
314,
790,
365,
4046,
436,
5313,
370,
314,
570,
14,
199,
893,
26,
272,
687,
7565,
63,
498,
492,
5795,
11771,
63,
3078,
199,
2590,
3545,
26,
272,
485,
4208,
63,
4731,
63,
498,
8,
736,
14,
515,
14,
904,
8,
5441,
63,
3243,
12,
283,
4731,
63,
498,
14,
647,
1333,
272,
687,
7565,
63,
498,
492,
5795,
11771,
63,
3078,
199,
199,
3,
7190,
314,
3743,
1584,
14,
199,
2190,
63,
1725,
275,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
272,
747,
14,
515,
14,
3475,
3460,
493,
10139,
283,
1751,
297,
11937,
647,
1333,
199,
2190,
63,
1725,
14,
3191,
342,
199,
509,
289,
315,
3743,
63,
1725,
26,
272,
22711,
8,
736,
14,
515,
14,
4832,
8,
70,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
5268,
787,
7131,
701,
1013,
5662,
1263,
1584,
13401,
315,
1275,
647,
315,
314,
2202,
199,
3619,
12,
315,
23331,
3294,
1865,
14,
199,
199,
2765,
2058,
315,
314,
2569,
19834,
26,
199,
446,
849,
2202,
787,
315,
1616,
13,
3455,
14,
647,
334,
3749,
1077,
1395,
4750,
2202,
9,
199,
446,
3537,
2202,
787,
315,
22528,
13,
4239,
14,
647,
334,
290,
2893,
402,
642,
570,
365,
2348,
367,
2043,
1265,
9,
199,
446,
1263,
10580,
370,
4575,
2202,
883,
2621,
315,
3388,
13,
4239,
14,
647,
334,
13297,
7171,
1929,
370,
2043,
1218,
642,
9,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
646,
747,
199,
646,
5739,
199,
646,
984,
421,
199,
318,
485,
4208,
63,
4731,
63,
498,
8,
493,
63,
515,
304,
272,
492,
2196,
272,
8365,
275,
283,
23459,
11371,
1,
32,
3,
22074,
62,
6,
27436,
10683,
29600,
339,
347,
2196,
63,
1560,
837,
267,
372,
8365,
59,
442,
8,
552,
8,
6574,
3342,
2355,
14,
2355,
24821,
272,
10261,
63,
495,
275,
6522,
904,
8,
2355,
63,
1560,
342,
367,
284,
315,
1425,
8,
772,
430,
272,
543,
1551,
8,
493,
63,
515,
12,
283,
87,
358,
465,
289,
26,
267,
289,
14,
952,
360,
12961,
63,
3078,
2458,
83,
60,
78,
7,
450,
4700,
8,
3759,
63,
495,
430,
199,
199,
5441,
63,
3243,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
199,
199,
3,
7649,
16306,
314,
5795,
11771,
63,
3078,
687,
314,
570,
7565,
63,
498,
14,
647,
14,
982,
652,
3181,
1133,
2187,
12,
199,
3,
2337,
365,
376,
492,
1125,
12,
436,
314,
790,
365,
4046,
436,
5313,
370,
314,
570,
14,
199,
893,
26,
272,
687,
7565,
63,
498,
492,
5795,
11771,
63,
3078,
199,
2590,
3545,
26,
272,
485,
4208,
63,
4731,
63,
498,
8,
736,
14,
515,
14,
904,
8,
5441,
63,
3243,
12,
283,
4731,
63,
498,
14,
647,
1333,
272,
687,
7565,
63,
498,
492,
5795,
11771,
63,
3078,
199,
199,
3,
7190,
314,
3743,
1584,
14,
199,
2190,
63,
1725,
275,
5739,
14,
6463,
8,
736,
14,
515,
14,
904,
8,
272,
747,
14,
515,
14,
3475,
3460,
493,
10139,
283,
1751,
297,
11937,
647,
1333,
199,
2190,
63,
1725,
14,
3191,
342,
199,
509,
289,
315,
3743,
63,
1725,
26,
272,
22711,
8,
736,
14,
515,
14,
4832,
8,
70,
430,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
laiqiqi886/kbengine | kbe/res/scripts/common/Lib/ast.py | 91 | 12034 | """
ast
~~~
The `ast` module helps Python applications to process trees of the Python
abstract syntax grammar. The abstract syntax itself might change with
each Python release; this module helps to find out programmatically what
the current grammar looks like and allows modifications of it.
An abstract syntax tree can be generated by passing `ast.PyCF_ONLY_AST` as
a flag to the `compile()` builtin function or by using the `parse()`
function from this module. The result will be a tree of objects whose
classes all inherit from `ast.AST`.
A modified abstract syntax tree can be compiled into a Python code object
using the built-in `compile()` function.
Additionally various helper functions are provided that make working with
the trees simpler. The main intention of the helper functions and this
module in general is to provide an easy to use interface for libraries
that work tightly with the python syntax (template engines for example).
:copyright: Copyright 2008 by Armin Ronacher.
:license: Python License.
"""
from _ast import *
def parse(source, filename='<unknown>', mode='exec'):
"""
Parse the source into an AST node.
Equivalent to compile(source, filename, mode, PyCF_ONLY_AST).
"""
return compile(source, filename, mode, PyCF_ONLY_AST)
def literal_eval(node_or_string):
"""
Safely evaluate an expression node or a string containing a Python
expression. The string or node provided may only consist of the following
Python literal structures: strings, bytes, numbers, tuples, lists, dicts,
sets, booleans, and None.
"""
if isinstance(node_or_string, str):
node_or_string = parse(node_or_string, mode='eval')
if isinstance(node_or_string, Expression):
node_or_string = node_or_string.body
def _convert(node):
if isinstance(node, (Str, Bytes)):
return node.s
elif isinstance(node, Num):
return node.n
elif isinstance(node, Tuple):
return tuple(map(_convert, node.elts))
elif isinstance(node, List):
return list(map(_convert, node.elts))
elif isinstance(node, Set):
return set(map(_convert, node.elts))
elif isinstance(node, Dict):
return dict((_convert(k), _convert(v)) for k, v
in zip(node.keys, node.values))
elif isinstance(node, NameConstant):
return node.value
elif isinstance(node, UnaryOp) and \
isinstance(node.op, (UAdd, USub)) and \
isinstance(node.operand, (Num, UnaryOp, BinOp)):
operand = _convert(node.operand)
if isinstance(node.op, UAdd):
return + operand
else:
return - operand
elif isinstance(node, BinOp) and \
isinstance(node.op, (Add, Sub)) and \
isinstance(node.right, (Num, UnaryOp, BinOp)) and \
isinstance(node.left, (Num, UnaryOp, BinOp)):
left = _convert(node.left)
right = _convert(node.right)
if isinstance(node.op, Add):
return left + right
else:
return left - right
raise ValueError('malformed node or string: ' + repr(node))
return _convert(node_or_string)
def dump(node, annotate_fields=True, include_attributes=False):
"""
Return a formatted dump of the tree in *node*. This is mainly useful for
debugging purposes. The returned string will show the names and the values
for fields. This makes the code impossible to evaluate, so if evaluation is
wanted *annotate_fields* must be set to False. Attributes such as line
numbers and column offsets are not dumped by default. If this is wanted,
*include_attributes* can be set to True.
"""
def _format(node):
if isinstance(node, AST):
fields = [(a, _format(b)) for a, b in iter_fields(node)]
rv = '%s(%s' % (node.__class__.__name__, ', '.join(
('%s=%s' % field for field in fields)
if annotate_fields else
(b for a, b in fields)
))
if include_attributes and node._attributes:
rv += fields and ', ' or ' '
rv += ', '.join('%s=%s' % (a, _format(getattr(node, a)))
for a in node._attributes)
return rv + ')'
elif isinstance(node, list):
return '[%s]' % ', '.join(_format(x) for x in node)
return repr(node)
if not isinstance(node, AST):
raise TypeError('expected AST, got %r' % node.__class__.__name__)
return _format(node)
def copy_location(new_node, old_node):
"""
Copy source location (`lineno` and `col_offset` attributes) from
*old_node* to *new_node* if possible, and return *new_node*.
"""
for attr in 'lineno', 'col_offset':
if attr in old_node._attributes and attr in new_node._attributes \
and hasattr(old_node, attr):
setattr(new_node, attr, getattr(old_node, attr))
return new_node
def fix_missing_locations(node):
"""
When you compile a node tree with compile(), the compiler expects lineno and
col_offset attributes for every node that supports them. This is rather
tedious to fill in for generated nodes, so this helper adds these attributes
recursively where not already set, by setting them to the values of the
parent node. It works recursively starting at *node*.
"""
def _fix(node, lineno, col_offset):
if 'lineno' in node._attributes:
if not hasattr(node, 'lineno'):
node.lineno = lineno
else:
lineno = node.lineno
if 'col_offset' in node._attributes:
if not hasattr(node, 'col_offset'):
node.col_offset = col_offset
else:
col_offset = node.col_offset
for child in iter_child_nodes(node):
_fix(child, lineno, col_offset)
_fix(node, 1, 0)
return node
def increment_lineno(node, n=1):
"""
Increment the line number of each node in the tree starting at *node* by *n*.
This is useful to "move code" to a different location in a file.
"""
for child in walk(node):
if 'lineno' in child._attributes:
child.lineno = getattr(child, 'lineno', 0) + n
return node
def iter_fields(node):
"""
Yield a tuple of ``(fieldname, value)`` for each field in ``node._fields``
that is present on *node*.
"""
for field in node._fields:
try:
yield field, getattr(node, field)
except AttributeError:
pass
def iter_child_nodes(node):
"""
Yield all direct child nodes of *node*, that is, all fields that are nodes
and all items of fields that are lists of nodes.
"""
for name, field in iter_fields(node):
if isinstance(field, AST):
yield field
elif isinstance(field, list):
for item in field:
if isinstance(item, AST):
yield item
def get_docstring(node, clean=True):
"""
Return the docstring for the given node or None if no docstring can
be found. If the node provided does not have docstrings a TypeError
will be raised.
"""
if not isinstance(node, (FunctionDef, ClassDef, Module)):
raise TypeError("%r can't have docstrings" % node.__class__.__name__)
if node.body and isinstance(node.body[0], Expr) and \
isinstance(node.body[0].value, Str):
if clean:
import inspect
return inspect.cleandoc(node.body[0].value.s)
return node.body[0].value.s
def walk(node):
"""
Recursively yield all descendant nodes in the tree starting at *node*
(including *node* itself), in no specified order. This is useful if you
only want to modify nodes in place and don't care about the context.
"""
from collections import deque
todo = deque([node])
while todo:
node = todo.popleft()
todo.extend(iter_child_nodes(node))
yield node
class NodeVisitor(object):
"""
A node visitor base class that walks the abstract syntax tree and calls a
visitor function for every node found. This function may return a value
which is forwarded by the `visit` method.
This class is meant to be subclassed, with the subclass adding visitor
methods.
Per default the visitor functions for the nodes are ``'visit_'`` +
class name of the node. So a `TryFinally` node visit function would
be `visit_TryFinally`. This behavior can be changed by overriding
the `visit` method. If no visitor function exists for a node
(return value `None`) the `generic_visit` visitor is used instead.
Don't use the `NodeVisitor` if you want to apply changes to nodes during
traversing. For this a special visitor exists (`NodeTransformer`) that
allows modifications.
"""
def visit(self, node):
"""Visit a node."""
method = 'visit_' + node.__class__.__name__
visitor = getattr(self, method, self.generic_visit)
return visitor(node)
def generic_visit(self, node):
"""Called if no explicit visitor function exists for a node."""
for field, value in iter_fields(node):
if isinstance(value, list):
for item in value:
if isinstance(item, AST):
self.visit(item)
elif isinstance(value, AST):
self.visit(value)
class NodeTransformer(NodeVisitor):
"""
A :class:`NodeVisitor` subclass that walks the abstract syntax tree and
allows modification of nodes.
The `NodeTransformer` will walk the AST and use the return value of the
visitor methods to replace or remove the old node. If the return value of
the visitor method is ``None``, the node will be removed from its location,
otherwise it is replaced with the return value. The return value may be the
original node in which case no replacement takes place.
Here is an example transformer that rewrites all occurrences of name lookups
(``foo``) to ``data['foo']``::
class RewriteName(NodeTransformer):
def visit_Name(self, node):
return copy_location(Subscript(
value=Name(id='data', ctx=Load()),
slice=Index(value=Str(s=node.id)),
ctx=node.ctx
), node)
Keep in mind that if the node you're operating on has child nodes you must
either transform the child nodes yourself or call the :meth:`generic_visit`
method for the node first.
For nodes that were part of a collection of statements (that applies to all
statement nodes), the visitor may also return a list of nodes rather than
just a single node.
Usually you use the transformer like this::
node = YourTransformer().visit(node)
"""
def generic_visit(self, node):
for field, old_value in iter_fields(node):
old_value = getattr(node, field, None)
if isinstance(old_value, list):
new_values = []
for value in old_value:
if isinstance(value, AST):
value = self.visit(value)
if value is None:
continue
elif not isinstance(value, AST):
new_values.extend(value)
continue
new_values.append(value)
old_value[:] = new_values
elif isinstance(old_value, AST):
new_node = self.visit(old_value)
if new_node is None:
delattr(node, field)
else:
setattr(node, field, new_node)
return node
| lgpl-3.0 | [
624,
272,
6073,
272,
221,
23597,
339,
710,
658,
1810,
64,
859,
22577,
2018,
13103,
370,
2112,
14416,
402,
314,
2018,
272,
9006,
6302,
12528,
14,
221,
710,
9006,
6302,
6337,
5594,
1570,
543,
272,
1924,
2018,
4683,
27,
642,
859,
22577,
370,
2342,
734,
2240,
17174,
4052,
272,
314,
1453,
12528,
10734,
2839,
436,
6127,
23070,
402,
652,
14,
339,
1626,
9006,
6302,
3123,
883,
506,
4046,
701,
9476,
658,
1810,
14,
2713,
5487,
63,
10452,
63,
11307,
64,
465,
272,
282,
3305,
370,
314,
658,
2014,
11995,
6762,
805,
503,
701,
1808,
314,
658,
1122,
11995,
272,
805,
687,
642,
859,
14,
221,
710,
754,
911,
506,
282,
3123,
402,
2251,
7447,
272,
3992,
1006,
8287,
687,
658,
1810,
14,
11307,
2313,
339,
437,
6042,
9006,
6302,
3123,
883,
506,
10311,
1901,
282,
2018,
1233,
909,
272,
1808,
314,
6137,
13,
262,
658,
2014,
11995,
805,
14,
339,
25448,
7750,
5922,
3423,
787,
2741,
626,
1852,
6449,
543,
272,
314,
14416,
28293,
14,
221,
710,
2446,
25343,
402,
314,
5922,
3423,
436,
642,
272,
859,
315,
8605,
365,
370,
5647,
376,
8837,
370,
675,
3217,
367,
8363,
272,
626,
1736,
3367,
913,
590,
543,
314,
2366,
6302,
334,
1160,
28156,
367,
2893,
680,
2378,
520,
7307,
26,
1898,
9079,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
2018,
844,
14,
199,
624,
199,
504,
485,
1810,
492,
627,
421,
199,
318,
2198,
8,
1365,
12,
1788,
15829,
5187,
4206,
818,
534,
1628,
735,
272,
408,
272,
6077,
314,
1350,
1901,
376,
20788,
1031,
14,
272,
24228,
370,
6555,
8,
1365,
12,
1788,
12,
818,
12,
1611,
5487,
63,
10452,
63,
11307,
680,
272,
408,
272,
372,
6555,
8,
1365,
12,
1788,
12,
818,
12,
1611,
5487,
63,
10452,
63,
11307,
9,
421,
199,
318,
8785,
63,
2579,
8,
932,
63,
269,
63,
875,
304,
272,
408,
272,
428,
2756,
7742,
9352,
376,
3965,
1031,
503,
282,
1059,
3035,
282,
2018,
272,
3965,
14,
221,
710,
1059,
503,
1031,
2741,
1443,
1454,
17568,
402,
314,
2569,
272,
2018,
8785,
13955,
26,
3326,
12,
2783,
12,
5579,
12,
6346,
12,
5548,
12,
10809,
12,
272,
5951,
12,
1234,
16721,
796,
12,
436,
488,
14,
272,
408,
272,
340,
1228,
8,
932,
63,
269,
63,
875,
12,
620,
304,
267,
1031,
63,
269,
63,
875,
275,
2198,
8,
932,
63,
269,
63,
875,
12,
818,
534,
2579,
358,
272,
340,
1228,
8,
932,
63,
269,
63,
875,
12,
22013,
304,
267,
1031,
63,
269,
63,
875,
275,
1031,
63,
269,
63,
875,
14,
2030,
272,
347,
485,
3916,
8,
932,
304,
267,
340,
1228,
8,
932,
12,
334,
2848,
12,
9879,
2298,
288,
372,
1031,
14,
83,
267,
916,
1228,
8,
932,
12,
16817,
304,
288,
372,
1031,
14,
78,
267,
916,
1228,
8,
932,
12,
11634,
304,
288,
372,
2008,
8,
1130,
1547,
3916,
12,
1031,
14,
352,
1086,
430,
267,
916,
1228,
8,
932,
12,
3820,
304,
288,
372,
769,
8,
1130,
1547,
3916,
12,
1031,
14,
352,
1086,
430,
267,
916,
1228,
8,
932,
12,
2494,
304,
288,
372,
663,
8,
1130,
1547,
3916,
12,
1031,
14,
352,
1086,
430,
267,
916,
1228,
8,
932,
12,
7448,
304,
288,
372,
1211,
1332,
63,
3916,
8,
75,
395,
485,
3916,
8,
86,
430,
367,
1022,
12,
373,
717,
315,
3482,
8,
932,
14,
1612,
12,
1031,
14,
1459,
430,
267,
916,
1228,
8,
932,
12,
2812,
9737,
304,
288,
372,
1031,
14,
585,
267,
916,
1228,
8,
932,
12,
1910,
695,
4619,
9,
436,
971,
1467,
1228,
8,
932,
14,
411,
12,
334,
53,
1123,
12,
738,
2610,
430,
436,
971,
1467,
1228,
8,
932,
14,
20315,
12,
334,
5667,
12,
1910,
695,
4619,
12,
32613,
4619,
2298,
288,
14888,
275,
485,
3916,
8,
932,
14,
20315,
9,
288,
340,
1228,
8,
932,
14,
411,
12,
738,
1123,
304,
355,
372,
435,
14888,
288,
587,
26,
355,
372,
446,
14888,
267,
916,
1228,
8,
932,
12,
32613,
4619,
9,
436,
971,
1467,
1228,
8,
932,
14,
411,
12,
334,
1123,
12,
4804,
430,
436,
971,
1467,
1228,
8,
932,
14,
1019,
12,
334,
5667,
12,
1910,
695,
4619,
12,
32613,
4619,
430,
436,
971,
1467,
1228,
8,
932,
14,
3039,
12,
334,
5667,
12,
1910,
695,
4619,
12,
32613,
4619,
2298,
288,
3602,
275,
485,
3916,
8,
932,
14,
3039,
9,
288,
2451,
275,
485,
3916,
8,
932,
14,
1019,
9,
288,
340,
1228,
8,
932,
14,
411,
12,
2654,
304,
355,
372,
3602,
435,
2451,
288,
587,
26,
355,
372,
3602,
446,
2451,
267,
746,
1722,
360,
31029,
1031,
503,
1059,
26,
283,
435,
4700,
8,
932,
430,
272,
372,
485,
3916,
8,
932,
63,
269,
63,
875,
9,
421,
199,
318,
5461,
8,
932,
12,
28987,
63,
955,
29,
549,
12,
2387,
63,
2987,
29,
797,
304,
272,
408,
272,
1432,
282,
7871,
5461,
402,
314,
3123,
315,
627,
932,
4856,
221,
961,
365,
27580,
2997,
367,
272,
10201,
12901,
14,
221,
710,
2138,
1059,
911,
2498,
314,
1561,
436,
314,
1338,
272,
367,
1504,
14,
221,
961,
7704,
314,
1233,
26847,
370,
9352,
12,
880,
340,
11735,
365,
272,
13632,
627,
10898,
63,
955,
10,
1471,
506,
663,
370,
756,
14,
221,
9382,
4066,
465,
1004,
272,
5579,
436,
2763,
15340,
787,
440,
31374,
701,
849,
14,
221,
982,
642,
365,
13632,
12,
272,
627,
2613,
63,
2987,
10,
883,
506,
663,
370,
715,
14,
272,
408,
272,
347,
485,
908,
8,
932,
304,
267,
340,
1228,
8,
932,
12,
20788,
304,
288,
1504,
275,
3842,
65,
12,
485,
908,
8,
66,
430,
367,
282,
12,
330,
315,
2740,
63,
955,
8,
932,
1874,
288,
4336,
275,
1543,
83,
4042,
83,
7,
450,
334,
932,
855,
533,
4914,
354,
3108,
1656,
1987,
904,
8,
355,
16651,
83,
2458,
83,
7,
450,
901,
367,
901,
315,
1504,
9,
355,
340,
28987,
63,
955,
587,
355,
334,
66,
367,
282,
12,
330,
315,
1504,
9,
288,
5082,
288,
340,
2387,
63,
2987,
436,
1031,
423,
2987,
26,
355,
4336,
847,
1504,
436,
1656,
283,
503,
283,
283,
355,
4336,
847,
1656,
1987,
904,
3508,
83,
2458,
83,
7,
450,
334
] | [
272,
6073,
272,
221,
23597,
339,
710,
658,
1810,
64,
859,
22577,
2018,
13103,
370,
2112,
14416,
402,
314,
2018,
272,
9006,
6302,
12528,
14,
221,
710,
9006,
6302,
6337,
5594,
1570,
543,
272,
1924,
2018,
4683,
27,
642,
859,
22577,
370,
2342,
734,
2240,
17174,
4052,
272,
314,
1453,
12528,
10734,
2839,
436,
6127,
23070,
402,
652,
14,
339,
1626,
9006,
6302,
3123,
883,
506,
4046,
701,
9476,
658,
1810,
14,
2713,
5487,
63,
10452,
63,
11307,
64,
465,
272,
282,
3305,
370,
314,
658,
2014,
11995,
6762,
805,
503,
701,
1808,
314,
658,
1122,
11995,
272,
805,
687,
642,
859,
14,
221,
710,
754,
911,
506,
282,
3123,
402,
2251,
7447,
272,
3992,
1006,
8287,
687,
658,
1810,
14,
11307,
2313,
339,
437,
6042,
9006,
6302,
3123,
883,
506,
10311,
1901,
282,
2018,
1233,
909,
272,
1808,
314,
6137,
13,
262,
658,
2014,
11995,
805,
14,
339,
25448,
7750,
5922,
3423,
787,
2741,
626,
1852,
6449,
543,
272,
314,
14416,
28293,
14,
221,
710,
2446,
25343,
402,
314,
5922,
3423,
436,
642,
272,
859,
315,
8605,
365,
370,
5647,
376,
8837,
370,
675,
3217,
367,
8363,
272,
626,
1736,
3367,
913,
590,
543,
314,
2366,
6302,
334,
1160,
28156,
367,
2893,
680,
2378,
520,
7307,
26,
1898,
9079,
701,
1952,
827,
32472,
19728,
14,
272,
520,
1682,
26,
2018,
844,
14,
199,
624,
199,
504,
485,
1810,
492,
627,
421,
199,
318,
2198,
8,
1365,
12,
1788,
15829,
5187,
4206,
818,
534,
1628,
735,
272,
408,
272,
6077,
314,
1350,
1901,
376,
20788,
1031,
14,
272,
24228,
370,
6555,
8,
1365,
12,
1788,
12,
818,
12,
1611,
5487,
63,
10452,
63,
11307,
680,
272,
408,
272,
372,
6555,
8,
1365,
12,
1788,
12,
818,
12,
1611,
5487,
63,
10452,
63,
11307,
9,
421,
199,
318,
8785,
63,
2579,
8,
932,
63,
269,
63,
875,
304,
272,
408,
272,
428,
2756,
7742,
9352,
376,
3965,
1031,
503,
282,
1059,
3035,
282,
2018,
272,
3965,
14,
221,
710,
1059,
503,
1031,
2741,
1443,
1454,
17568,
402,
314,
2569,
272,
2018,
8785,
13955,
26,
3326,
12,
2783,
12,
5579,
12,
6346,
12,
5548,
12,
10809,
12,
272,
5951,
12,
1234,
16721,
796,
12,
436,
488,
14,
272,
408,
272,
340,
1228,
8,
932,
63,
269,
63,
875,
12,
620,
304,
267,
1031,
63,
269,
63,
875,
275,
2198,
8,
932,
63,
269,
63,
875,
12,
818,
534,
2579,
358,
272,
340,
1228,
8,
932,
63,
269,
63,
875,
12,
22013,
304,
267,
1031,
63,
269,
63,
875,
275,
1031,
63,
269,
63,
875,
14,
2030,
272,
347,
485,
3916,
8,
932,
304,
267,
340,
1228,
8,
932,
12,
334,
2848,
12,
9879,
2298,
288,
372,
1031,
14,
83,
267,
916,
1228,
8,
932,
12,
16817,
304,
288,
372,
1031,
14,
78,
267,
916,
1228,
8,
932,
12,
11634,
304,
288,
372,
2008,
8,
1130,
1547,
3916,
12,
1031,
14,
352,
1086,
430,
267,
916,
1228,
8,
932,
12,
3820,
304,
288,
372,
769,
8,
1130,
1547,
3916,
12,
1031,
14,
352,
1086,
430,
267,
916,
1228,
8,
932,
12,
2494,
304,
288,
372,
663,
8,
1130,
1547,
3916,
12,
1031,
14,
352,
1086,
430,
267,
916,
1228,
8,
932,
12,
7448,
304,
288,
372,
1211,
1332,
63,
3916,
8,
75,
395,
485,
3916,
8,
86,
430,
367,
1022,
12,
373,
717,
315,
3482,
8,
932,
14,
1612,
12,
1031,
14,
1459,
430,
267,
916,
1228,
8,
932,
12,
2812,
9737,
304,
288,
372,
1031,
14,
585,
267,
916,
1228,
8,
932,
12,
1910,
695,
4619,
9,
436,
971,
1467,
1228,
8,
932,
14,
411,
12,
334,
53,
1123,
12,
738,
2610,
430,
436,
971,
1467,
1228,
8,
932,
14,
20315,
12,
334,
5667,
12,
1910,
695,
4619,
12,
32613,
4619,
2298,
288,
14888,
275,
485,
3916,
8,
932,
14,
20315,
9,
288,
340,
1228,
8,
932,
14,
411,
12,
738,
1123,
304,
355,
372,
435,
14888,
288,
587,
26,
355,
372,
446,
14888,
267,
916,
1228,
8,
932,
12,
32613,
4619,
9,
436,
971,
1467,
1228,
8,
932,
14,
411,
12,
334,
1123,
12,
4804,
430,
436,
971,
1467,
1228,
8,
932,
14,
1019,
12,
334,
5667,
12,
1910,
695,
4619,
12,
32613,
4619,
430,
436,
971,
1467,
1228,
8,
932,
14,
3039,
12,
334,
5667,
12,
1910,
695,
4619,
12,
32613,
4619,
2298,
288,
3602,
275,
485,
3916,
8,
932,
14,
3039,
9,
288,
2451,
275,
485,
3916,
8,
932,
14,
1019,
9,
288,
340,
1228,
8,
932,
14,
411,
12,
2654,
304,
355,
372,
3602,
435,
2451,
288,
587,
26,
355,
372,
3602,
446,
2451,
267,
746,
1722,
360,
31029,
1031,
503,
1059,
26,
283,
435,
4700,
8,
932,
430,
272,
372,
485,
3916,
8,
932,
63,
269,
63,
875,
9,
421,
199,
318,
5461,
8,
932,
12,
28987,
63,
955,
29,
549,
12,
2387,
63,
2987,
29,
797,
304,
272,
408,
272,
1432,
282,
7871,
5461,
402,
314,
3123,
315,
627,
932,
4856,
221,
961,
365,
27580,
2997,
367,
272,
10201,
12901,
14,
221,
710,
2138,
1059,
911,
2498,
314,
1561,
436,
314,
1338,
272,
367,
1504,
14,
221,
961,
7704,
314,
1233,
26847,
370,
9352,
12,
880,
340,
11735,
365,
272,
13632,
627,
10898,
63,
955,
10,
1471,
506,
663,
370,
756,
14,
221,
9382,
4066,
465,
1004,
272,
5579,
436,
2763,
15340,
787,
440,
31374,
701,
849,
14,
221,
982,
642,
365,
13632,
12,
272,
627,
2613,
63,
2987,
10,
883,
506,
663,
370,
715,
14,
272,
408,
272,
347,
485,
908,
8,
932,
304,
267,
340,
1228,
8,
932,
12,
20788,
304,
288,
1504,
275,
3842,
65,
12,
485,
908,
8,
66,
430,
367,
282,
12,
330,
315,
2740,
63,
955,
8,
932,
1874,
288,
4336,
275,
1543,
83,
4042,
83,
7,
450,
334,
932,
855,
533,
4914,
354,
3108,
1656,
1987,
904,
8,
355,
16651,
83,
2458,
83,
7,
450,
901,
367,
901,
315,
1504,
9,
355,
340,
28987,
63,
955,
587,
355,
334,
66,
367,
282,
12,
330,
315,
1504,
9,
288,
5082,
288,
340,
2387,
63,
2987,
436,
1031,
423,
2987,
26,
355,
4336,
847,
1504,
436,
1656,
283,
503,
283,
283,
355,
4336,
847,
1656,
1987,
904,
3508,
83,
2458,
83,
7,
450,
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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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
] |
ramitalat/odoo | addons/hr_contract/__openerp__.py | 260 | 1834 | # -*- 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/>.
#
##############################################################################
{
'name': 'Employee Contracts',
'version': '1.0',
'category': 'Human Resources',
'description': """
Add all information on the employee form to manage contracts.
=============================================================
* Contract
* Place of Birth,
* Medical Examination Date
* Company Vehicle
You can assign several contracts per employee.
""",
'author': 'OpenERP SA',
'website': 'https://www.odoo.com/page/employees',
'depends': ['base_action_rule', 'hr'],
'data': [
'security/ir.model.access.csv',
'hr_contract_view.xml',
'hr_contract_data.xml',
'base_action_rule_view.xml',
],
'demo': [],
'test': ['test/test_hr_contract.yml'],
'installable': True,
'auto_install': False,
}
# 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,
421,
199,
91,
272,
283,
354,
356,
283,
22635,
1448,
1239,
3021,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
31355,
26250,
297,
272,
283,
1802,
356,
408,
199,
1123,
1006,
2556,
641,
314,
15778,
1824,
370,
9635,
18782,
3021,
14,
199,
12813,
9152,
339,
627,
1448,
6908,
272,
627,
10902,
402,
699,
8244,
12,
272,
627,
3194,
328,
915,
1316,
455,
3155,
6148,
272,
627,
15878,
25777,
13438,
199,
199,
5556,
883,
5090,
9978,
18782,
3021,
1126,
15778,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
24561,
297,
272,
283,
8912,
356,
788,
1095,
63,
1287,
63,
2200,
297,
283,
6271,
995,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
6271,
63,
14624,
63,
1345,
14,
1652,
297,
267,
283,
6271,
63,
14624,
63,
576,
14,
1652,
297,
267,
283,
1095,
63,
1287,
63,
2200,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
396,
356,
788,
396,
15,
396,
63,
6271,
63,
14624,
14,
11714,
995,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
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
] | [
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,
421,
199,
91,
272,
283,
354,
356,
283,
22635,
1448,
1239,
3021,
297,
272,
283,
1023,
356,
283,
17,
14,
16,
297,
272,
283,
3710,
356,
283,
31355,
26250,
297,
272,
283,
1802,
356,
408,
199,
1123,
1006,
2556,
641,
314,
15778,
1824,
370,
9635,
18782,
3021,
14,
199,
12813,
9152,
339,
627,
1448,
6908,
272,
627,
10902,
402,
699,
8244,
12,
272,
627,
3194,
328,
915,
1316,
455,
3155,
6148,
272,
627,
15878,
25777,
13438,
199,
199,
5556,
883,
5090,
9978,
18782,
3021,
1126,
15778,
14,
272,
10327,
272,
283,
2502,
356,
283,
25347,
13950,
297,
272,
283,
7360,
356,
283,
2859,
921,
1544,
14,
22058,
14,
957,
15,
1606,
15,
24561,
297,
272,
283,
8912,
356,
788,
1095,
63,
1287,
63,
2200,
297,
283,
6271,
995,
272,
283,
576,
356,
359,
267,
283,
4416,
15,
723,
14,
1238,
14,
2732,
14,
4737,
297,
267,
283,
6271,
63,
14624,
63,
1345,
14,
1652,
297,
267,
283,
6271,
63,
14624,
63,
576,
14,
1652,
297,
267,
283,
1095,
63,
1287,
63,
2200,
63,
1345,
14,
1652,
297,
272,
2156,
272,
283,
8768,
356,
990,
272,
283,
396,
356,
788,
396,
15,
396,
63,
6271,
63,
14624,
14,
11714,
995,
272,
283,
21762,
356,
715,
12,
272,
283,
2495,
63,
3174,
356,
756,
12,
199,
93,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
gfreed/android_external_chromium-org | tools/metrics/histograms/pretty_print.py | 53 | 12009 | #!/usr/bin/env python
# Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Pretty-prints the histograms.xml file, alphabetizing tags, wrapping text
at 80 chars, enforcing standard attribute ordering, and standardizing
indentation.
This is quite a bit more complicated than just calling tree.toprettyxml();
we need additional customization, like special attribute ordering in tags
and wrapping text nodes, so we implement our own full custom XML pretty-printer.
"""
from __future__ import with_statement
import diffutil
import json
import logging
import shutil
import sys
import textwrap
import xml.dom.minidom
WRAP_COLUMN = 80
# Desired order for tag attributes; attributes listed here will appear first,
# and in the same order as in these lists.
# { tag_name: [attribute_name, ...] }
ATTRIBUTE_ORDER = {
'enum': ['name', 'type'],
'histogram': ['name', 'enum', 'units'],
'int': ['value', 'label'],
'fieldtrial': ['name', 'separator', 'ordering'],
'group': ['name', 'label'],
'affected-histogram': ['name'],
'with-group': ['name'],
}
# Tag names for top-level nodes whose children we don't want to indent.
TAGS_THAT_DONT_INDENT = [
'histogram-configuration',
'histograms',
'fieldtrials',
'enums'
]
# Extra vertical spacing rules for special tag names.
# {tag_name: (newlines_after_open, newlines_before_close, newlines_after_close)}
TAGS_THAT_HAVE_EXTRA_NEWLINE = {
'histogram-configuration': (2, 1, 1),
'histograms': (2, 1, 1),
'fieldtrials': (2, 1, 1),
'enums': (2, 1, 1),
'histogram': (1, 1, 1),
'enum': (1, 1, 1),
'fieldtrial': (1, 1, 1),
}
# Tags that we allow to be squished into a single line for brevity.
TAGS_THAT_ALLOW_SINGLE_LINE = [
'summary',
'int',
]
# Tags whose children we want to alphabetize. The key is the parent tag name,
# and the value is a pair of the tag name of the children we want to sort,
# and a key function that maps each child node to the desired sort key.
ALPHABETIZATION_RULES = {
'histograms': ('histogram', lambda n: n.attributes['name'].value.lower()),
'enums': ('enum', lambda n: n.attributes['name'].value.lower()),
'enum': ('int', lambda n: int(n.attributes['value'].value)),
'fieldtrials': ('fieldtrial', lambda n: n.attributes['name'].value.lower()),
'fieldtrial': ('affected-histogram',
lambda n: n.attributes['name'].value.lower()),
}
class Error(Exception):
pass
def LastLineLength(s):
"""Returns the length of the last line in s.
Args:
s: A multi-line string, including newlines.
Returns:
The length of the last line in s, in characters.
"""
if s.rfind('\n') == -1: return len(s)
return len(s) - s.rfind('\n') - len('\n')
def XmlEscape(s):
"""XML-escapes the given string, replacing magic characters (&<>") with their
escaped equivalents."""
s = s.replace("&", "&").replace("<", "<")
s = s.replace("\"", """).replace(">", ">")
return s
def PrettyPrintNode(node, indent=0):
"""Pretty-prints the given XML node at the given indent level.
Args:
node: The minidom node to pretty-print.
indent: The current indent level.
Returns:
The pretty-printed string (including embedded newlines).
Raises:
Error if the XML has unknown tags or attributes.
"""
# Handle the top-level document node.
if node.nodeType == xml.dom.minidom.Node.DOCUMENT_NODE:
return '\n'.join([PrettyPrintNode(n) for n in node.childNodes])
# Handle text nodes.
if node.nodeType == xml.dom.minidom.Node.TEXT_NODE:
# Wrap each paragraph in the text to fit in the 80 column limit.
wrapper = textwrap.TextWrapper()
wrapper.initial_indent = ' ' * indent
wrapper.subsequent_indent = ' ' * indent
wrapper.break_on_hyphens = False
wrapper.break_long_words = False
wrapper.width = WRAP_COLUMN
text = XmlEscape(node.data)
# Remove any common indent.
text = textwrap.dedent(text.strip('\n'))
lines = text.split('\n')
# Split the text into paragraphs at blank line boundaries.
paragraphs = [[]]
for l in lines:
if len(l.strip()) == 0 and len(paragraphs[-1]) > 0:
paragraphs.append([])
else:
paragraphs[-1].append(l)
# Remove trailing empty paragraph if present.
if len(paragraphs) > 0 and len(paragraphs[-1]) == 0:
paragraphs = paragraphs[:-1]
# Wrap each paragraph and separate with two newlines.
return '\n\n'.join([wrapper.fill('\n'.join(p)) for p in paragraphs])
# Handle element nodes.
if node.nodeType == xml.dom.minidom.Node.ELEMENT_NODE:
newlines_after_open, newlines_before_close, newlines_after_close = (
TAGS_THAT_HAVE_EXTRA_NEWLINE.get(node.tagName, (1, 1, 0)))
# Open the tag.
s = ' ' * indent + '<' + node.tagName
# Calculate how much space to allow for the '>' or '/>'.
closing_chars = 1
if not node.childNodes:
closing_chars = 2
# Pretty-print the attributes.
attributes = node.attributes.keys()
if attributes:
# Reorder the attributes.
if not node.tagName in ATTRIBUTE_ORDER:
unrecognized_attributes = attributes;
else:
unrecognized_attributes = (
[a for a in attributes if not a in ATTRIBUTE_ORDER[node.tagName]])
attributes = (
[a for a in ATTRIBUTE_ORDER[node.tagName] if a in attributes])
for a in unrecognized_attributes:
logging.error(
'Unrecognized attribute "%s" in tag "%s"' % (a, node.tagName))
if unrecognized_attributes:
raise Error()
for a in attributes:
value = XmlEscape(node.attributes[a].value)
# Replace sequences of whitespace with single spaces.
words = value.split()
a_str = ' %s="%s"' % (a, ' '.join(words))
# Start a new line if the attribute will make this line too long.
if LastLineLength(s) + len(a_str) + closing_chars > WRAP_COLUMN:
s += '\n' + ' ' * (indent + 3)
# Output everything up to the first quote.
s += ' %s="' % (a)
value_indent_level = LastLineLength(s)
# Output one word at a time, splitting to the next line where necessary.
column = value_indent_level
for i, word in enumerate(words):
# This is slightly too conservative since not every word will be
# followed by the closing characters...
if i > 0 and (column + len(word) + 1 + closing_chars > WRAP_COLUMN):
s = s.rstrip() # remove any trailing whitespace
s += '\n' + ' ' * value_indent_level
column = value_indent_level
s += word + ' '
column += len(word) + 1
s = s.rstrip() # remove any trailing whitespace
s += '"'
s = s.rstrip() # remove any trailing whitespace
# Pretty-print the child nodes.
if node.childNodes:
s += '>'
# Calculate the new indent level for child nodes.
new_indent = indent
if node.tagName not in TAGS_THAT_DONT_INDENT:
new_indent += 2
child_nodes = node.childNodes
# Recursively pretty-print the child nodes.
child_nodes = [PrettyPrintNode(n, indent=new_indent) for n in child_nodes]
child_nodes = [c for c in child_nodes if len(c.strip()) > 0]
# Determine whether we can fit the entire node on a single line.
close_tag = '</%s>' % node.tagName
space_left = WRAP_COLUMN - LastLineLength(s) - len(close_tag)
if (node.tagName in TAGS_THAT_ALLOW_SINGLE_LINE and
len(child_nodes) == 1 and len(child_nodes[0].strip()) <= space_left):
s += child_nodes[0].strip()
else:
s += '\n' * newlines_after_open + '\n'.join(child_nodes)
s += '\n' * newlines_before_close + ' ' * indent
s += close_tag
else:
s += '/>'
s += '\n' * newlines_after_close
return s
# Handle comment nodes.
if node.nodeType == xml.dom.minidom.Node.COMMENT_NODE:
return '<!--%s-->\n' % node.data
# Ignore other node types. This could be a processing instruction (<? ... ?>)
# or cdata section (<![CDATA[...]]!>), neither of which are legal in the
# histograms XML at present.
logging.error('Ignoring unrecognized node data: %s' % node.toxml())
raise Error()
def unsafeAppendChild(parent, child):
"""Append child to parent's list of children, ignoring the possibility that it
is already in another node's childNodes list. Requires that the previous
parent of child is discarded (to avoid non-tree DOM graphs).
This can provide a significant speedup as O(n^2) operations are removed (in
particular, each child insertion avoids the need to traverse the old parent's
entire list of children)."""
child.parentNode = None
parent.appendChild(child)
child.parentNode = parent
def TransformByAlphabetizing(node):
"""Transform the given XML by alphabetizing specific node types according to
the rules in ALPHABETIZATION_RULES.
Args:
node: The minidom node to transform.
Returns:
The minidom node, with children appropriately alphabetized. Note that the
transformation is done in-place, i.e. the original minidom tree is modified
directly.
"""
if node.nodeType != xml.dom.minidom.Node.ELEMENT_NODE:
for c in node.childNodes: TransformByAlphabetizing(c)
return node
# Element node with a tag name that we alphabetize the children of?
if node.tagName in ALPHABETIZATION_RULES:
# Put subnodes in a list of node,key pairs to allow for custom sorting.
subtag, key_function = ALPHABETIZATION_RULES[node.tagName]
subnodes = []
last_key = -1
for c in node.childNodes:
if (c.nodeType == xml.dom.minidom.Node.ELEMENT_NODE and
c.tagName == subtag):
last_key = key_function(c)
# Subnodes that we don't want to rearrange use the last node's key,
# so they stay in the same relative position.
subnodes.append( (c, last_key) )
# Sort the subnode list.
subnodes.sort(key=lambda pair: pair[1])
# Re-add the subnodes, transforming each recursively.
while node.firstChild:
node.removeChild(node.firstChild)
for (c, _) in subnodes:
unsafeAppendChild(node, TransformByAlphabetizing(c))
return node
# Recursively handle other element nodes and other node types.
for c in node.childNodes: TransformByAlphabetizing(c)
return node
def PrettyPrint(raw_xml):
"""Pretty-print the given XML.
Args:
xml: The contents of the histograms XML file, as a string.
Returns:
The pretty-printed version.
"""
tree = xml.dom.minidom.parseString(raw_xml)
tree = TransformByAlphabetizing(tree)
return PrettyPrintNode(tree)
def main():
logging.basicConfig(level=logging.INFO)
presubmit = ('--presubmit' in sys.argv)
logging.info('Loading histograms.xml...')
with open('histograms.xml', 'rb') as f:
xml = f.read()
# Check there are no CR ('\r') characters in the file.
if '\r' in xml:
logging.info('DOS-style line endings (CR characters) detected - these are '
'not allowed. Please run dos2unix histograms.xml')
sys.exit(1)
logging.info('Pretty-printing...')
try:
pretty = PrettyPrint(xml)
except Error:
logging.error('Aborting parsing due to fatal errors.')
sys.exit(1)
if xml == pretty:
logging.info('histograms.xml is correctly pretty-printed.')
sys.exit(0)
if presubmit:
logging.info('histograms.xml is not formatted correctly; run '
'pretty_print.py to fix.')
sys.exit(1)
if not diffutil.PromptUserToAcceptDiff(
xml, pretty,
'Is the prettified version acceptable?'):
logging.error('Aborting')
return
logging.info('Creating backup file histograms.before.pretty-print.xml')
shutil.move('histograms.xml', 'histograms.before.pretty-print.xml')
logging.info('Writing new histograms.xml file')
with open('histograms.xml', 'wb') as f:
f.write(pretty)
if __name__ == '__main__':
main()
| bsd-3-clause | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
27153,
13,
29593,
314,
394,
22137,
14,
1652,
570,
12,
23331,
280,
20135,
3762,
12,
19696,
1318,
199,
292,
5939,
8365,
12,
655,
509,
4477,
4465,
2225,
7794,
12,
436,
28974,
20135,
199,
25152,
14,
199,
199,
2765,
365,
18794,
282,
4546,
1655,
23515,
2419,
2951,
6358,
3123,
14,
2119,
21958,
1652,
7303,
199,
1129,
1929,
4722,
32715,
12,
2839,
4539,
2225,
7794,
315,
3762,
199,
460,
19696,
1318,
3380,
12,
880,
781,
5669,
4154,
5705,
2615,
3537,
4692,
7268,
13,
11835,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
3915,
1974,
199,
646,
2022,
199,
646,
2050,
199,
646,
5145,
199,
646,
984,
199,
646,
13390,
199,
646,
2748,
14,
4556,
14,
21827,
421,
199,
23824,
63,
21436,
275,
5939,
199,
199,
3,
1487,
5381,
1865,
367,
1947,
3004,
27,
3004,
10532,
2348,
911,
7468,
1642,
12,
199,
3,
436,
315,
314,
2011,
1865,
465,
315,
3520,
5548,
14,
199,
3,
469,
1947,
63,
354,
26,
359,
3215,
63,
354,
12,
21214,
789,
199,
17075,
63,
12125,
275,
469,
523,
283,
4869,
356,
788,
354,
297,
283,
466,
995,
523,
283,
14805,
356,
788,
354,
297,
283,
4869,
297,
283,
5260,
995,
523,
283,
442,
356,
788,
585,
297,
283,
1302,
995,
523,
283,
698,
14443,
356,
788,
354,
297,
283,
9896,
297,
283,
7128,
995,
523,
283,
923,
356,
788,
354,
297,
283,
1302,
995,
523,
283,
26653,
13,
14805,
356,
788,
354,
995,
523,
283,
1045,
13,
923,
356,
788,
354,
995,
199,
93,
199,
199,
3,
8053,
1561,
367,
2746,
13,
1896,
3380,
7447,
4978,
781,
2793,
1133,
2934,
370,
4363,
14,
199,
17626,
63,
2080,
619,
63,
31874,
63,
29080,
275,
359,
523,
283,
14805,
13,
4758,
297,
523,
283,
72,
22137,
297,
523,
283,
698,
24684,
297,
523,
283,
19921,
7,
199,
61,
199,
199,
3,
11177,
13763,
19621,
4713,
367,
4539,
1947,
1561,
14,
199,
3,
469,
1450,
63,
354,
26,
334,
13839,
63,
4399,
63,
1490,
12,
14930,
63,
5182,
63,
1600,
12,
14930,
63,
4399,
63,
1600,
6769,
199,
17626,
63,
2080,
619,
63,
10767,
63,
18555,
63,
28758,
275,
469,
523,
283,
14805,
13,
4758,
356,
334,
18,
12,
413,
12,
413,
395,
523,
283,
72,
22137,
356,
334,
18,
12,
413,
12,
413,
395,
523,
283,
698,
24684,
356,
334,
18,
12,
413,
12,
413,
395,
523,
283,
19921,
356,
334,
18,
12,
413,
12,
413,
395,
523,
283,
14805,
356,
334,
17,
12,
413,
12,
413,
395,
523,
283,
4869,
356,
334,
17,
12,
413,
12,
413,
395,
523,
283,
698,
14443,
356,
334,
17,
12,
413,
12,
413,
395,
199,
93,
199,
199,
3,
25204,
626,
781,
2040,
370,
506,
12345,
4387,
1901,
282,
2849,
1004,
367,
330,
264,
18936,
14,
199,
17626,
63,
2080,
619,
63,
12231,
63,
16425,
63,
6174,
275,
359,
523,
283,
4705,
297,
523,
283,
442,
297,
199,
61,
199,
199,
3,
25204,
7447,
4978,
781,
2934,
370,
23331,
30510,
14,
710,
790,
365,
314,
1676,
1947,
536,
12,
199,
3,
436,
314,
574,
365,
282,
4092,
402,
314,
1947,
536,
402,
314,
4978,
781,
2934,
370,
4069,
12,
199,
3,
436,
282,
790,
805,
626,
9033,
1924,
1982,
1031,
370,
314,
6387,
4069,
790,
14,
199,
748,
9791,
1217,
775,
22800,
63,
31490,
275,
469,
523,
283,
72,
22137,
356,
661,
14805,
297,
2400,
302,
26,
302,
14,
2987,
459,
354,
2278,
585,
14,
2325,
4000,
523,
283,
19921,
356,
661,
4869,
297,
2400,
302,
26,
302,
14,
2987,
459,
354,
2278,
585,
14,
2325,
4000,
523,
283,
4869,
356,
661,
442,
297,
2400,
302,
26,
1109,
8,
78,
14,
2987,
459,
585,
2278,
585,
1826,
523,
283,
698,
24684,
356,
661,
698,
14443,
297,
2400,
302,
26,
302,
14,
2987,
459,
354,
2278,
585,
14,
2325,
4000,
523,
283,
698,
14443,
356,
661,
26653,
13,
14805,
297,
326,
2400,
302,
26,
302,
14,
2987,
459,
354,
2278,
585,
14,
2325,
4000,
199,
93,
421,
199,
533,
4520,
8,
1726,
304,
523,
986,
421,
199,
318,
15237,
3049,
4625,
8,
83,
304,
523,
408,
3407,
314,
2582,
402,
314,
2061,
1004,
315,
308,
14,
819,
3033,
26,
272,
308,
26,
437,
3510,
13,
604,
1059,
12,
5893,
14930,
14,
819,
1803,
26,
272,
710,
2582,
402,
314,
2061,
1004,
315,
308,
12,
315,
4110,
14,
523,
408,
523,
340,
308,
14,
14542,
2258,
78,
358,
508,
446,
17,
26,
372,
822,
8,
83,
9,
523,
372,
822,
8,
83,
9,
446,
308,
14,
14542,
2258,
78,
358,
446,
822,
2258,
78,
358,
421,
199,
318,
24881,
10260,
8,
83,
304,
523,
408,
4317,
13,
3765,
83,
314,
1627,
1059,
12,
15810,
10628,
4110,
334,
6,
28,
9579,
543,
3932,
523,
11077,
7353,
83,
1041,
523,
308,
275,
308,
14,
1814,
22077,
401,
11746,
5282,
27,
3471,
1814,
6757,
401,
11746,
4116,
15027,
523,
308,
275,
308,
14,
1814,
4582,
5151,
11746,
5184,
27,
3471,
1814,
480,
7166,
11746,
3308,
15027,
523,
372,
308,
421,
199,
318,
31651,
5375,
1716,
8,
932,
12,
4363,
29,
16,
304,
523,
408,
27153,
13,
29593,
314,
1627,
4692,
1031,
737,
314,
1627,
4363,
2166,
14,
819,
3033,
26,
272,
1031,
26,
710,
19165,
1031,
370,
7268,
13,
1361,
14,
272,
4363,
26,
710,
1453,
4363,
2166,
14,
819,
1803,
26,
272,
710,
7268,
13,
27131,
1059,
334,
15768,
12169,
14930,
680,
819,
6218,
26,
272,
4520,
340,
314,
4692,
965,
5809,
3762,
503,
3004,
14,
523,
408,
523,
327,
8690,
314,
2746,
13,
1896,
2213,
1031,
14,
523,
340,
1031,
14,
12412,
508,
2748,
14,
4556,
14,
21827,
14,
1716,
14,
7884,
63,
8063,
26,
272,
372,
1557,
78,
1370,
904,
779,
27153,
5375,
1716,
8,
78,
9,
367,
302,
315,
1031,
14,
10626,
566,
819,
327,
8690,
1318,
3380,
14,
523,
340,
1031,
14,
12412,
508,
2748,
14,
4556,
14,
21827,
14
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1898,
6171,
710,
12051,
6642,
14,
2900,
4481,
4644,
14,
199,
3,
3645,
402,
642,
1350,
1233,
365,
10413,
701,
282,
6289,
13,
2487,
4190,
626,
883,
506,
199,
3,
1911,
315,
314,
5113,
570,
14,
199,
199,
624,
27153,
13,
29593,
314,
394,
22137,
14,
1652,
570,
12,
23331,
280,
20135,
3762,
12,
19696,
1318,
199,
292,
5939,
8365,
12,
655,
509,
4477,
4465,
2225,
7794,
12,
436,
28974,
20135,
199,
25152,
14,
199,
199,
2765,
365,
18794,
282,
4546,
1655,
23515,
2419,
2951,
6358,
3123,
14,
2119,
21958,
1652,
7303,
199,
1129,
1929,
4722,
32715,
12,
2839,
4539,
2225,
7794,
315,
3762,
199,
460,
19696,
1318,
3380,
12,
880,
781,
5669,
4154,
5705,
2615,
3537,
4692,
7268,
13,
11835,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
543,
63,
6242,
199,
199,
646,
3915,
1974,
199,
646,
2022,
199,
646,
2050,
199,
646,
5145,
199,
646,
984,
199,
646,
13390,
199,
646,
2748,
14,
4556,
14,
21827,
421,
199,
23824,
63,
21436,
275,
5939,
199,
199,
3,
1487,
5381,
1865,
367,
1947,
3004,
27,
3004,
10532,
2348,
911,
7468,
1642,
12,
199,
3,
436,
315,
314,
2011,
1865,
465,
315,
3520,
5548,
14,
199,
3,
469,
1947,
63,
354,
26,
359,
3215,
63,
354,
12,
21214,
789,
199,
17075,
63,
12125,
275,
469,
523,
283,
4869,
356,
788,
354,
297,
283,
466,
995,
523,
283,
14805,
356,
788,
354,
297,
283,
4869,
297,
283,
5260,
995,
523,
283,
442,
356,
788,
585,
297,
283,
1302,
995,
523,
283,
698,
14443,
356,
788,
354,
297,
283,
9896,
297,
283,
7128,
995,
523,
283,
923,
356,
788,
354,
297,
283,
1302,
995,
523,
283,
26653,
13,
14805,
356,
788,
354,
995,
523,
283,
1045,
13,
923,
356,
788,
354,
995,
199,
93,
199,
199,
3,
8053,
1561,
367,
2746,
13,
1896,
3380,
7447,
4978,
781,
2793,
1133,
2934,
370,
4363,
14,
199,
17626,
63,
2080,
619,
63,
31874,
63,
29080,
275,
359,
523,
283,
14805,
13,
4758,
297,
523,
283,
72,
22137,
297,
523,
283,
698,
24684,
297,
523,
283,
19921,
7,
199,
61,
199,
199,
3,
11177,
13763,
19621,
4713,
367,
4539,
1947,
1561,
14,
199,
3,
469,
1450,
63,
354,
26,
334,
13839,
63,
4399,
63,
1490,
12,
14930,
63,
5182,
63,
1600,
12,
14930,
63,
4399,
63,
1600,
6769,
199,
17626,
63,
2080,
619,
63,
10767,
63,
18555,
63,
28758,
275,
469,
523,
283,
14805,
13,
4758,
356,
334,
18,
12,
413,
12,
413,
395,
523,
283,
72,
22137,
356,
334,
18,
12,
413,
12,
413,
395,
523,
283,
698,
24684,
356,
334,
18,
12,
413,
12,
413,
395,
523,
283,
19921,
356,
334,
18,
12,
413,
12,
413,
395,
523,
283,
14805,
356,
334,
17,
12,
413,
12,
413,
395,
523,
283,
4869,
356,
334,
17,
12,
413,
12,
413,
395,
523,
283,
698,
14443,
356,
334,
17,
12,
413,
12,
413,
395,
199,
93,
199,
199,
3,
25204,
626,
781,
2040,
370,
506,
12345,
4387,
1901,
282,
2849,
1004,
367,
330,
264,
18936,
14,
199,
17626,
63,
2080,
619,
63,
12231,
63,
16425,
63,
6174,
275,
359,
523,
283,
4705,
297,
523,
283,
442,
297,
199,
61,
199,
199,
3,
25204,
7447,
4978,
781,
2934,
370,
23331,
30510,
14,
710,
790,
365,
314,
1676,
1947,
536,
12,
199,
3,
436,
314,
574,
365,
282,
4092,
402,
314,
1947,
536,
402,
314,
4978,
781,
2934,
370,
4069,
12,
199,
3,
436,
282,
790,
805,
626,
9033,
1924,
1982,
1031,
370,
314,
6387,
4069,
790,
14,
199,
748,
9791,
1217,
775,
22800,
63,
31490,
275,
469,
523,
283,
72,
22137,
356,
661,
14805,
297,
2400,
302,
26,
302,
14,
2987,
459,
354,
2278,
585,
14,
2325,
4000,
523,
283,
19921,
356,
661,
4869,
297,
2400,
302,
26,
302,
14,
2987,
459,
354,
2278,
585,
14,
2325,
4000,
523,
283,
4869,
356,
661,
442,
297,
2400,
302,
26,
1109,
8,
78,
14,
2987,
459,
585,
2278,
585,
1826,
523,
283,
698,
24684,
356,
661,
698,
14443,
297,
2400,
302,
26,
302,
14,
2987,
459,
354,
2278,
585,
14,
2325,
4000,
523,
283,
698,
14443,
356,
661,
26653,
13,
14805,
297,
326,
2400,
302,
26,
302,
14,
2987,
459,
354,
2278,
585,
14,
2325,
4000,
199,
93,
421,
199,
533,
4520,
8,
1726,
304,
523,
986,
421,
199,
318,
15237,
3049,
4625,
8,
83,
304,
523,
408,
3407,
314,
2582,
402,
314,
2061,
1004,
315,
308,
14,
819,
3033,
26,
272,
308,
26,
437,
3510,
13,
604,
1059,
12,
5893,
14930,
14,
819,
1803,
26,
272,
710,
2582,
402,
314,
2061,
1004,
315,
308,
12,
315,
4110,
14,
523,
408,
523,
340,
308,
14,
14542,
2258,
78,
358,
508,
446,
17,
26,
372,
822,
8,
83,
9,
523,
372,
822,
8,
83,
9,
446,
308,
14,
14542,
2258,
78,
358,
446,
822,
2258,
78,
358,
421,
199,
318,
24881,
10260,
8,
83,
304,
523,
408,
4317,
13,
3765,
83,
314,
1627,
1059,
12,
15810,
10628,
4110,
334,
6,
28,
9579,
543,
3932,
523,
11077,
7353,
83,
1041,
523,
308,
275,
308,
14,
1814,
22077,
401,
11746,
5282,
27,
3471,
1814,
6757,
401,
11746,
4116,
15027,
523,
308,
275,
308,
14,
1814,
4582,
5151,
11746,
5184,
27,
3471,
1814,
480,
7166,
11746,
3308,
15027,
523,
372,
308,
421,
199,
318,
31651,
5375,
1716,
8,
932,
12,
4363,
29,
16,
304,
523,
408,
27153,
13,
29593,
314,
1627,
4692,
1031,
737,
314,
1627,
4363,
2166,
14,
819,
3033,
26,
272,
1031,
26,
710,
19165,
1031,
370,
7268,
13,
1361,
14,
272,
4363,
26,
710,
1453,
4363,
2166,
14,
819,
1803,
26,
272,
710,
7268,
13,
27131,
1059,
334,
15768,
12169,
14930,
680,
819,
6218,
26,
272,
4520,
340,
314,
4692,
965,
5809,
3762,
503,
3004,
14,
523,
408,
523,
327,
8690,
314,
2746,
13,
1896,
2213,
1031,
14,
523,
340,
1031,
14,
12412,
508,
2748,
14,
4556,
14,
21827,
14,
1716,
14,
7884,
63,
8063,
26,
272,
372,
1557,
78,
1370,
904,
779,
27153,
5375,
1716,
8,
78,
9,
367,
302,
315,
1031,
14,
10626,
566,
819,
327,
8690,
1318,
3380,
14,
523,
340,
1031,
14,
12412,
508,
2748,
14,
4556,
14,
21827,
14,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
chrismeyersfsu/ansible | lib/ansible/plugins/filter/ipaddr.py | 19 | 19242 | # (c) 2014, Maciej Delmanowski <[email protected]>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
from functools import partial
import types
try:
import netaddr
except ImportError:
# in this case, we'll make the filters return error messages (see bottom)
netaddr = None
else:
class mac_linux(netaddr.mac_unix):
pass
mac_linux.word_fmt = '%.2x'
from ansible import errors
# ---- IP address and network query helpers ----
def _empty_ipaddr_query(v, vtype):
# We don't have any query to process, so just check what type the user
# expects, and return the IP address in a correct format
if v:
if vtype == 'address':
return str(v.ip)
elif vtype == 'network':
return str(v)
def _6to4_query(v, vtype, value):
if v.version == 4:
if v.size == 1:
ipconv = str(v.ip)
elif v.size > 1:
if v.ip != v.network:
ipconv = str(v.ip)
else:
ipconv = False
if ipaddr(ipconv, 'public'):
numbers = list(map(int, ipconv.split('.')))
try:
return '2002:{:02x}{:02x}:{:02x}{:02x}::1/48'.format(*numbers)
except:
return False
elif v.version == 6:
if vtype == 'address':
if ipaddr(str(v), '2002::/16'):
return value
elif vtype == 'network':
if v.ip != v.network:
if ipaddr(str(v.ip), '2002::/16'):
return value
else:
return False
def _ip_query(v):
if v.size == 1:
return str(v.ip)
if v.size > 1:
# /31 networks in netaddr have no broadcast address
if v.ip != v.network or not v.broadcast:
return str(v.ip)
def _gateway_query(v):
if v.size > 1:
if v.ip != v.network:
return str(v.ip) + '/' + str(v.prefixlen)
def _bool_ipaddr_query(v):
if v:
return True
def _broadcast_query(v):
if v.size > 1:
return str(v.broadcast)
def _cidr_query(v):
return str(v)
def _cidr_lookup_query(v, iplist, value):
try:
if v in iplist:
return value
except:
return False
def _host_query(v):
if v.size == 1:
return str(v)
elif v.size > 1:
if v.ip != v.network:
return str(v.ip) + '/' + str(v.prefixlen)
def _hostmask_query(v):
return str(v.hostmask)
def _int_query(v, vtype):
if vtype == 'address':
return int(v.ip)
elif vtype == 'network':
return str(int(v.ip)) + '/' + str(int(v.prefixlen))
def _ipv4_query(v, value):
if v.version == 6:
try:
return str(v.ipv4())
except:
return False
else:
return value
def _ipv6_query(v, value):
if v.version == 4:
return str(v.ipv6())
else:
return value
def _link_local_query(v, value):
v_ip = netaddr.IPAddress(str(v.ip))
if v.version == 4:
if ipaddr(str(v_ip), '169.254.0.0/24'):
return value
elif v.version == 6:
if ipaddr(str(v_ip), 'fe80::/10'):
return value
def _loopback_query(v, value):
v_ip = netaddr.IPAddress(str(v.ip))
if v_ip.is_loopback():
return value
def _multicast_query(v, value):
if v.is_multicast():
return value
def _net_query(v):
if v.size > 1:
if v.ip == v.network:
return str(v.network) + '/' + str(v.prefixlen)
def _netmask_query(v):
return str(v.netmask)
def _network_query(v):
if v.size > 1:
return str(v.network)
def _prefix_query(v):
return int(v.prefixlen)
def _private_query(v, value):
if v.is_private():
return value
def _public_query(v, value):
v_ip = netaddr.IPAddress(str(v.ip))
if v_ip.is_unicast() and not v_ip.is_private() and \
not v_ip.is_loopback() and not v_ip.is_netmask() and \
not v_ip.is_hostmask():
return value
def _revdns_query(v):
v_ip = netaddr.IPAddress(str(v.ip))
return v_ip.reverse_dns
def _size_query(v):
return v.size
def _subnet_query(v):
return str(v.cidr)
def _type_query(v):
if v.size == 1:
return 'address'
if v.size > 1:
if v.ip != v.network:
return 'address'
else:
return 'network'
def _unicast_query(v, value):
if v.is_unicast():
return value
def _version_query(v):
return v.version
def _wrap_query(v, vtype, value):
if v.version == 6:
if vtype == 'address':
return '[' + str(v.ip) + ']'
elif vtype == 'network':
return '[' + str(v.ip) + ']/' + str(v.prefixlen)
else:
return value
# ---- HWaddr query helpers ----
def _bare_query(v):
v.dialect = netaddr.mac_bare
return str(v)
def _bool_hwaddr_query(v):
if v:
return True
def _int_hwaddr_query(v):
return int(v)
def _cisco_query(v):
v.dialect = netaddr.mac_cisco
return str(v)
def _empty_hwaddr_query(v, value):
if v:
return value
def _linux_query(v):
v.dialect = mac_linux
return str(v)
def _postgresql_query(v):
v.dialect = netaddr.mac_pgsql
return str(v)
def _unix_query(v):
v.dialect = netaddr.mac_unix
return str(v)
def _win_query(v):
v.dialect = netaddr.mac_eui48
return str(v)
# ---- IP address and network filters ----
def ipaddr(value, query = '', version = False, alias = 'ipaddr'):
''' Check if string is an IP address or network and filter it '''
query_func_extra_args = {
'': ('vtype',),
'6to4': ('vtype', 'value'),
'cidr_lookup': ('iplist', 'value'),
'int': ('vtype',),
'ipv4': ('value',),
'ipv6': ('value',),
'link-local': ('value',),
'loopback': ('value',),
'lo': ('value',),
'multicast': ('value',),
'private': ('value',),
'public': ('value',),
'unicast': ('value',),
'wrap': ('vtype', 'value'),
}
query_func_map = {
'': _empty_ipaddr_query,
'6to4': _6to4_query,
'address': _ip_query,
'address/prefix': _gateway_query,
'bool': _bool_ipaddr_query,
'broadcast': _broadcast_query,
'cidr': _cidr_query,
'cidr_lookup': _cidr_lookup_query,
'gateway': _gateway_query,
'gw': _gateway_query,
'host': _host_query,
'host/prefix': _gateway_query,
'hostmask': _hostmask_query,
'hostnet': _gateway_query,
'int': _int_query,
'ip': _ip_query,
'ipv4': _ipv4_query,
'ipv6': _ipv6_query,
'link-local': _link_local_query,
'lo': _loopback_query,
'loopback': _loopback_query,
'multicast': _multicast_query,
'net': _net_query,
'netmask': _netmask_query,
'network': _network_query,
'prefix': _prefix_query,
'private': _private_query,
'public': _public_query,
'revdns': _revdns_query,
'router': _gateway_query,
'size': _size_query,
'subnet': _subnet_query,
'type': _type_query,
'unicast': _unicast_query,
'v4': _ipv4_query,
'v6': _ipv6_query,
'version': _version_query,
'wrap': _wrap_query,
}
vtype = None
if not value:
return False
elif value == True:
return False
# Check if value is a list and parse each element
elif isinstance(value, (list, tuple, types.GeneratorType)):
_ret = []
for element in value:
if ipaddr(element, str(query), version):
_ret.append(ipaddr(element, str(query), version))
if _ret:
return _ret
else:
return list()
# Check if value is a number and convert it to an IP address
elif str(value).isdigit():
# We don't know what IP version to assume, so let's check IPv4 first,
# then IPv6
try:
if ((not version) or (version and version == 4)):
v = netaddr.IPNetwork('0.0.0.0/0')
v.value = int(value)
v.prefixlen = 32
elif version and version == 6:
v = netaddr.IPNetwork('::/0')
v.value = int(value)
v.prefixlen = 128
# IPv4 didn't work the first time, so it definitely has to be IPv6
except:
try:
v = netaddr.IPNetwork('::/0')
v.value = int(value)
v.prefixlen = 128
# The value is too big for IPv6. Are you a nanobot?
except:
return False
# We got an IP address, let's mark it as such
value = str(v)
vtype = 'address'
# value has not been recognized, check if it's a valid IP string
else:
try:
v = netaddr.IPNetwork(value)
# value is a valid IP string, check if user specified
# CIDR prefix or just an IP address, this will indicate default
# output format
try:
address, prefix = value.split('/')
vtype = 'network'
except:
vtype = 'address'
# value hasn't been recognized, maybe it's a numerical CIDR?
except:
try:
address, prefix = value.split('/')
address.isdigit()
address = int(address)
prefix.isdigit()
prefix = int(prefix)
# It's not numerical CIDR, give up
except:
return False
# It is something, so let's try and build a CIDR from the parts
try:
v = netaddr.IPNetwork('0.0.0.0/0')
v.value = address
v.prefixlen = prefix
# It's not a valid IPv4 CIDR
except:
try:
v = netaddr.IPNetwork('::/0')
v.value = address
v.prefixlen = prefix
# It's not a valid IPv6 CIDR. Give up.
except:
return False
# We have a valid CIDR, so let's write it in correct format
value = str(v)
vtype = 'network'
# We have a query string but it's not in the known query types. Check if
# that string is a valid subnet, if so, we can check later if given IP
# address/network is inside that specific subnet
try:
### ?? 6to4 and link-local were True here before. Should they still?
if query and (query not in query_func_map or query == 'cidr_lookup') and ipaddr(query, 'network'):
iplist = netaddr.IPSet([netaddr.IPNetwork(query)])
query = 'cidr_lookup'
except:
pass
# This code checks if value maches the IP version the user wants, ie. if
# it's any version ("ipaddr()"), IPv4 ("ipv4()") or IPv6 ("ipv6()")
# If version does not match, return False
if version and v.version != version:
return False
extras = []
for arg in query_func_extra_args.get(query, tuple()):
extras.append(locals()[arg])
try:
return query_func_map[query](v, *extras)
except KeyError:
try:
float(query)
if v.size == 1:
if vtype == 'address':
return str(v.ip)
elif vtype == 'network':
return str(v)
elif v.size > 1:
try:
return str(v[query]) + '/' + str(v.prefixlen)
except:
return False
else:
return value
except:
raise errors.AnsibleFilterError(alias + ': unknown filter type: %s' % query)
return False
def ipwrap(value, query = ''):
try:
if isinstance(value, (list, tuple, types.GeneratorType)):
_ret = []
for element in value:
if ipaddr(element, query, version = False, alias = 'ipwrap'):
_ret.append(ipaddr(element, 'wrap'))
else:
_ret.append(element)
return _ret
else:
_ret = ipaddr(value, query, version = False, alias = 'ipwrap')
if _ret:
return ipaddr(_ret, 'wrap')
else:
return value
except:
return value
def ipv4(value, query = ''):
return ipaddr(value, query, version = 4, alias = 'ipv4')
def ipv6(value, query = ''):
return ipaddr(value, query, version = 6, alias = 'ipv6')
# Split given subnet into smaller subnets or find out the biggest subnet of
# a given IP address with given CIDR prefix
# Usage:
#
# - address or address/prefix | ipsubnet
# returns CIDR subnet of a given input
#
# - address/prefix | ipsubnet(cidr)
# returns number of possible subnets for given CIDR prefix
#
# - address/prefix | ipsubnet(cidr, index)
# returns new subnet with given CIDR prefix
#
# - address | ipsubnet(cidr)
# returns biggest subnet with given CIDR prefix that address belongs to
#
# - address | ipsubnet(cidr, index)
# returns next indexed subnet which contains given address
def ipsubnet(value, query = '', index = 'x'):
''' Manipulate IPv4/IPv6 subnets '''
try:
vtype = ipaddr(value, 'type')
if vtype == 'address':
v = ipaddr(value, 'cidr')
elif vtype == 'network':
v = ipaddr(value, 'subnet')
value = netaddr.IPNetwork(v)
except:
return False
if not query:
return str(value)
elif str(query).isdigit():
vsize = ipaddr(v, 'size')
query = int(query)
try:
float(index)
index = int(index)
if vsize > 1:
try:
return str(list(value.subnet(query))[index])
except:
return False
elif vsize == 1:
try:
return str(value.supernet(query)[index])
except:
return False
except:
if vsize > 1:
try:
return str(len(list(value.subnet(query))))
except:
return False
elif vsize == 1:
try:
return str(value.supernet(query)[0])
except:
return False
return False
# Returns the nth host within a network described by value.
# Usage:
#
# - address or address/prefix | nthhost(nth)
# returns the nth host within the given network
def nthhost(value, query=''):
''' Get the nth host within a given network '''
try:
vtype = ipaddr(value, 'type')
if vtype == 'address':
v = ipaddr(value, 'cidr')
elif vtype == 'network':
v = ipaddr(value, 'subnet')
value = netaddr.IPNetwork(v)
except:
return False
if not query:
return False
try:
nth = int(query)
if value.size > nth:
return value[nth]
except ValueError:
return False
return False
# Returns the SLAAC address within a network for a given HW/MAC address.
# Usage:
#
# - prefix | slaac(mac)
def slaac(value, query = ''):
''' Get the SLAAC address within given network '''
try:
vtype = ipaddr(value, 'type')
if vtype == 'address':
v = ipaddr(value, 'cidr')
elif vtype == 'network':
v = ipaddr(value, 'subnet')
if ipaddr(value, 'version') != 6:
return False
value = netaddr.IPNetwork(v)
except:
return False
if not query:
return False
try:
mac = hwaddr(query, alias = 'slaac')
eui = netaddr.EUI(mac)
except:
return False
return eui.ipv6(value.network)
# ---- HWaddr / MAC address filters ----
def hwaddr(value, query = '', alias = 'hwaddr'):
''' Check if string is a HW/MAC address and filter it '''
query_func_extra_args = {
'': ('value',),
}
query_func_map = {
'': _empty_hwaddr_query,
'bare': _bare_query,
'bool': _bool_hwaddr_query,
'int': _int_hwaddr_query,
'cisco': _cisco_query,
'eui48': _win_query,
'linux': _linux_query,
'pgsql': _postgresql_query,
'postgresql': _postgresql_query,
'psql': _postgresql_query,
'unix': _unix_query,
'win': _win_query,
}
try:
v = netaddr.EUI(value)
except:
if query and query != 'bool':
raise errors.AnsibleFilterError(alias + ': not a hardware address: %s' % value)
extras = []
for arg in query_func_extra_args.get(query, tuple()):
extras.append(locals()[arg])
try:
return query_func_map[query](v, *extras)
except KeyError:
raise errors.AnsibleFilterError(alias + ': unknown filter type: %s' % query)
return False
def macaddr(value, query = ''):
return hwaddr(value, query, alias = 'macaddr')
def _need_netaddr(f_name, *args, **kwargs):
raise errors.AnsibleFilterError('The {0} filter requires python-netaddr be'
' installed on the ansible controller'.format(f_name))
def ip4_hex(arg):
''' Convert an IPv4 address to Hexadecimal notation '''
numbers = list(map(int, arg.split('.')))
return '{:02x}{:02x}{:02x}{:02x}'.format(*numbers)
# ---- Ansible filters ----
class FilterModule(object):
''' IP address and network manipulation filters '''
filter_map = {
# IP addresses and networks
'ipaddr': ipaddr,
'ipwrap': ipwrap,
'ipv4': ipv4,
'ipv6': ipv6,
'ipsubnet': ipsubnet,
'nthhost': nthhost,
'slaac': slaac,
'ip4_hex': ip4_hex,
# MAC / HW addresses
'hwaddr': hwaddr,
'macaddr': macaddr
}
def filters(self):
if netaddr:
return self.filter_map
else:
# Need to install python-netaddr for these filters to work
return dict((f, partial(_need_netaddr, f)) for f in self.filter_map)
| gpl-3.0 | [
3,
334,
67,
9,
6927,
12,
16593,
559,
69,
74,
18464,
1237,
19844,
665,
10481,
468,
379,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
9143,
492,
7417,
199,
646,
2943,
199,
199,
893,
26,
272,
492,
25798,
199,
2590,
3545,
26,
272,
327,
315,
642,
1930,
12,
781,
7171,
1852,
314,
4766,
372,
1125,
3788,
334,
3239,
9048,
9,
272,
25798,
275,
488,
199,
2836,
26,
272,
1021,
4497,
63,
5135,
8,
846,
2697,
14,
3088,
63,
11864,
304,
267,
986,
272,
4497,
63,
5135,
14,
1027,
63,
5045,
275,
22769,
18,
88,
7,
199,
199,
504,
3242,
492,
2552,
421,
199,
3,
4099,
3531,
2287,
436,
2784,
1827,
10897,
4099,
199,
199,
318,
485,
1667,
63,
22623,
63,
1131,
8,
86,
12,
29878,
304,
272,
327,
2136,
2793,
1133,
1172,
1263,
1827,
370,
2112,
12,
880,
2951,
1104,
4052,
730,
314,
922,
272,
327,
14292,
12,
436,
372,
314,
3531,
2287,
315,
282,
3211,
1475,
272,
340,
373,
26,
267,
340,
29878,
508,
283,
1562,
356,
288,
372,
620,
8,
86,
14,
711,
9,
267,
916,
29878,
508,
283,
1200,
356,
288,
372,
620,
8,
86,
9,
199,
199,
318,
485,
22,
475,
20,
63,
1131,
8,
86,
12,
29878,
12,
574,
304,
272,
340,
373,
14,
1023,
508,
841,
26,
398,
340,
373,
14,
890,
508,
413,
26,
288,
3384,
5598,
275,
620,
8,
86,
14,
711,
9,
267,
916,
373,
14,
890,
690,
413,
26,
288,
340,
373,
14,
711,
1137,
373,
14,
1200,
26,
355,
3384,
5598,
275,
620,
8,
86,
14,
711,
9,
288,
587,
26,
355,
3384,
5598,
275,
756,
398,
340,
21249,
8,
711,
5598,
12,
283,
3455,
735,
288,
5579,
275,
769,
8,
1130,
8,
442,
12,
3384,
5598,
14,
1294,
7563,
430,
398,
862,
26,
288,
372,
283,
15135,
14534,
26,
996,
88,
8847,
26,
996,
88,
16495,
26,
996,
88,
8847,
26,
996,
88,
93,
447,
17,
15,
2006,
1370,
908,
2031,
10548,
9,
267,
871,
26,
288,
372,
756,
339,
916,
373,
14,
1023,
508,
1227,
26,
267,
340,
29878,
508,
283,
1562,
356,
288,
340,
21249,
8,
495,
8,
86,
395,
283,
15135,
26346,
975,
735,
355,
372,
574,
267,
916,
29878,
508,
283,
1200,
356,
288,
340,
373,
14,
711,
1137,
373,
14,
1200,
26,
355,
340,
21249,
8,
495,
8,
86,
14,
711,
395,
283,
15135,
26346,
975,
735,
490,
372,
574,
288,
587,
26,
355,
372,
756,
199,
199,
318,
485,
711,
63,
1131,
8,
86,
304,
272,
340,
373,
14,
890,
508,
413,
26,
267,
372,
620,
8,
86,
14,
711,
9,
272,
340,
373,
14,
890,
690,
413,
26,
267,
327,
1182,
2192,
11759,
315,
25798,
1172,
949,
11180,
2287,
267,
340,
373,
14,
711,
1137,
373,
14,
1200,
503,
440,
373,
14,
10786,
26,
288,
372,
620,
8,
86,
14,
711,
9,
199,
199,
318,
485,
7019,
63,
1131,
8,
86,
304,
272,
340,
373,
14,
890,
690,
413,
26,
267,
340,
373,
14,
711,
1137,
373,
14,
1200,
26,
288,
372,
620,
8,
86,
14,
711,
9,
435,
7324,
435,
620,
8,
86,
14,
16089,
9,
199,
199,
318,
485,
2245,
63,
22623,
63,
1131,
8,
86,
304,
272,
340,
373,
26,
267,
372,
715,
199,
199,
318,
485,
10786,
63,
1131,
8,
86,
304,
272,
340,
373,
14,
890,
690,
413,
26,
267,
372,
620,
8,
86,
14,
10786,
9,
199,
199,
318,
485,
10509,
63,
1131,
8,
86,
304,
272,
372,
620,
8,
86,
9,
199,
199,
318,
485,
10509,
63,
3892,
63,
1131,
8,
86,
12,
3384,
513,
12,
574,
304,
272,
862,
26,
267,
340,
373,
315,
3384,
513,
26,
288,
372,
574,
272,
871,
26,
267,
372,
756,
199,
199,
318,
485,
1102,
63,
1131,
8,
86,
304,
272,
340,
373,
14,
890,
508,
413,
26,
267,
372,
620,
8,
86,
9,
272,
916,
373,
14,
890,
690,
413,
26,
267,
340,
373,
14,
711,
1137,
373,
14,
1200,
26,
288,
372,
620,
8,
86,
14,
711,
9,
435,
7324,
435,
620,
8,
86,
14,
16089,
9,
199,
199,
318,
485,
1102,
2629,
63,
1131,
8,
86,
304,
272,
372,
620,
8,
86,
14,
1102,
2629,
9,
199,
199,
318,
485,
442,
63,
1131,
8,
86,
12,
29878,
304,
272,
340,
29878,
508,
283,
1562,
356,
267,
372,
1109,
8,
86,
14,
711,
9,
272,
916,
29878,
508,
283,
1200,
356,
267,
372,
620,
8,
442,
8,
86,
14,
711,
430,
435,
7324,
435,
620,
8,
442,
8,
86,
14,
16089,
430,
199,
199,
318,
485,
4774,
20,
63,
1131,
8,
86,
12,
574,
304,
272,
340,
373,
14,
1023,
508,
1227,
26,
267,
862,
26,
288,
372,
620,
8,
86,
14,
4774,
20,
1012,
267,
871,
26,
288,
372,
756,
272,
587,
26,
267,
372,
574,
199,
199,
318,
485,
4774,
22,
63,
1131,
8,
86,
12,
574,
304,
272,
340,
373,
14,
1023,
508,
841,
26,
267,
372,
620,
8,
86,
14,
4774,
22,
1012,
272,
587,
26,
267,
372,
574,
199,
199,
318,
485,
1073
] | [
334,
67,
9,
6927,
12,
16593,
559,
69,
74,
18464,
1237,
19844,
665,
10481,
468,
379,
32,
6799,
14,
957,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
504,
9143,
492,
7417,
199,
646,
2943,
199,
199,
893,
26,
272,
492,
25798,
199,
2590,
3545,
26,
272,
327,
315,
642,
1930,
12,
781,
7171,
1852,
314,
4766,
372,
1125,
3788,
334,
3239,
9048,
9,
272,
25798,
275,
488,
199,
2836,
26,
272,
1021,
4497,
63,
5135,
8,
846,
2697,
14,
3088,
63,
11864,
304,
267,
986,
272,
4497,
63,
5135,
14,
1027,
63,
5045,
275,
22769,
18,
88,
7,
199,
199,
504,
3242,
492,
2552,
421,
199,
3,
4099,
3531,
2287,
436,
2784,
1827,
10897,
4099,
199,
199,
318,
485,
1667,
63,
22623,
63,
1131,
8,
86,
12,
29878,
304,
272,
327,
2136,
2793,
1133,
1172,
1263,
1827,
370,
2112,
12,
880,
2951,
1104,
4052,
730,
314,
922,
272,
327,
14292,
12,
436,
372,
314,
3531,
2287,
315,
282,
3211,
1475,
272,
340,
373,
26,
267,
340,
29878,
508,
283,
1562,
356,
288,
372,
620,
8,
86,
14,
711,
9,
267,
916,
29878,
508,
283,
1200,
356,
288,
372,
620,
8,
86,
9,
199,
199,
318,
485,
22,
475,
20,
63,
1131,
8,
86,
12,
29878,
12,
574,
304,
272,
340,
373,
14,
1023,
508,
841,
26,
398,
340,
373,
14,
890,
508,
413,
26,
288,
3384,
5598,
275,
620,
8,
86,
14,
711,
9,
267,
916,
373,
14,
890,
690,
413,
26,
288,
340,
373,
14,
711,
1137,
373,
14,
1200,
26,
355,
3384,
5598,
275,
620,
8,
86,
14,
711,
9,
288,
587,
26,
355,
3384,
5598,
275,
756,
398,
340,
21249,
8,
711,
5598,
12,
283,
3455,
735,
288,
5579,
275,
769,
8,
1130,
8,
442,
12,
3384,
5598,
14,
1294,
7563,
430,
398,
862,
26,
288,
372,
283,
15135,
14534,
26,
996,
88,
8847,
26,
996,
88,
16495,
26,
996,
88,
8847,
26,
996,
88,
93,
447,
17,
15,
2006,
1370,
908,
2031,
10548,
9,
267,
871,
26,
288,
372,
756,
339,
916,
373,
14,
1023,
508,
1227,
26,
267,
340,
29878,
508,
283,
1562,
356,
288,
340,
21249,
8,
495,
8,
86,
395,
283,
15135,
26346,
975,
735,
355,
372,
574,
267,
916,
29878,
508,
283,
1200,
356,
288,
340,
373,
14,
711,
1137,
373,
14,
1200,
26,
355,
340,
21249,
8,
495,
8,
86,
14,
711,
395,
283,
15135,
26346,
975,
735,
490,
372,
574,
288,
587,
26,
355,
372,
756,
199,
199,
318,
485,
711,
63,
1131,
8,
86,
304,
272,
340,
373,
14,
890,
508,
413,
26,
267,
372,
620,
8,
86,
14,
711,
9,
272,
340,
373,
14,
890,
690,
413,
26,
267,
327,
1182,
2192,
11759,
315,
25798,
1172,
949,
11180,
2287,
267,
340,
373,
14,
711,
1137,
373,
14,
1200,
503,
440,
373,
14,
10786,
26,
288,
372,
620,
8,
86,
14,
711,
9,
199,
199,
318,
485,
7019,
63,
1131,
8,
86,
304,
272,
340,
373,
14,
890,
690,
413,
26,
267,
340,
373,
14,
711,
1137,
373,
14,
1200,
26,
288,
372,
620,
8,
86,
14,
711,
9,
435,
7324,
435,
620,
8,
86,
14,
16089,
9,
199,
199,
318,
485,
2245,
63,
22623,
63,
1131,
8,
86,
304,
272,
340,
373,
26,
267,
372,
715,
199,
199,
318,
485,
10786,
63,
1131,
8,
86,
304,
272,
340,
373,
14,
890,
690,
413,
26,
267,
372,
620,
8,
86,
14,
10786,
9,
199,
199,
318,
485,
10509,
63,
1131,
8,
86,
304,
272,
372,
620,
8,
86,
9,
199,
199,
318,
485,
10509,
63,
3892,
63,
1131,
8,
86,
12,
3384,
513,
12,
574,
304,
272,
862,
26,
267,
340,
373,
315,
3384,
513,
26,
288,
372,
574,
272,
871,
26,
267,
372,
756,
199,
199,
318,
485,
1102,
63,
1131,
8,
86,
304,
272,
340,
373,
14,
890,
508,
413,
26,
267,
372,
620,
8,
86,
9,
272,
916,
373,
14,
890,
690,
413,
26,
267,
340,
373,
14,
711,
1137,
373,
14,
1200,
26,
288,
372,
620,
8,
86,
14,
711,
9,
435,
7324,
435,
620,
8,
86,
14,
16089,
9,
199,
199,
318,
485,
1102,
2629,
63,
1131,
8,
86,
304,
272,
372,
620,
8,
86,
14,
1102,
2629,
9,
199,
199,
318,
485,
442,
63,
1131,
8,
86,
12,
29878,
304,
272,
340,
29878,
508,
283,
1562,
356,
267,
372,
1109,
8,
86,
14,
711,
9,
272,
916,
29878,
508,
283,
1200,
356,
267,
372,
620,
8,
442,
8,
86,
14,
711,
430,
435,
7324,
435,
620,
8,
442,
8,
86,
14,
16089,
430,
199,
199,
318,
485,
4774,
20,
63,
1131,
8,
86,
12,
574,
304,
272,
340,
373,
14,
1023,
508,
1227,
26,
267,
862,
26,
288,
372,
620,
8,
86,
14,
4774,
20,
1012,
267,
871,
26,
288,
372,
756,
272,
587,
26,
267,
372,
574,
199,
199,
318,
485,
4774,
22,
63,
1131,
8,
86,
12,
574,
304,
272,
340,
373,
14,
1023,
508,
841,
26,
267,
372,
620,
8,
86,
14,
4774,
22,
1012,
272,
587,
26,
267,
372,
574,
199,
199,
318,
485,
1073,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mxamin/youtube-dl | youtube_dl/extractor/criterion.py | 1 | 1284 | # -*- coding: utf-8 -*-
from __future__ import unicode_literals
import re
from .common import InfoExtractor
class CriterionIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?criterion\.com/films/(?P<id>[0-9]+)-.+'
_TEST = {
'url': 'http://www.criterion.com/films/184-le-samourai',
'md5': 'bc51beba55685509883a9a7830919ec3',
'info_dict': {
'id': '184',
'ext': 'mp4',
'title': 'Le Samouraï',
'description': 'md5:a2b4b116326558149bef81f76dcbb93f',
}
}
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
webpage = self._download_webpage(url, video_id)
final_url = self._search_regex(
r'so.addVariable\("videoURL", "(.+?)"\)\;', webpage, 'video url')
title = self._og_search_title(webpage)
description = self._html_search_meta('description', webpage)
thumbnail = self._search_regex(
r'so.addVariable\("thumbnailURL", "(.+?)"\)\;',
webpage, 'thumbnail url')
return {
'id': video_id,
'url': final_url,
'title': title,
'description': description,
'thumbnail': thumbnail,
}
| unlicense | [
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
445,
7527,
265,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
21418,
4537,
957,
15,
1289,
706,
9448,
48,
28,
344,
9514,
16,
13,
25,
2807,
7216,
14,
4786,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
21418,
14,
957,
15,
1289,
706,
15,
10078,
13,
274,
13,
21660,
567,
5789,
297,
267,
283,
1064,
21,
356,
283,
3776,
2869,
1235,
2470,
1229,
2333,
1229,
1643,
16456,
65,
25,
65,
2277,
10556,
1167,
825,
19,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
10078,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
2553,
428,
455,
567,
65,
128,
108,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
65,
18,
66,
20,
66,
7524,
8342,
17686,
10721,
31945,
2835,
70,
2114,
3833,
2501,
3129,
70,
297,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
398,
4242,
63,
633,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
1159,
79,
14,
525,
2773,
60,
480,
3722,
2632,
401,
7340,
11198,
2924,
13670,
10805,
9248,
12,
283,
3722,
1166,
358,
267,
2538,
275,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
9,
267,
1369,
275,
291,
423,
1360,
63,
1733,
63,
2024,
360,
1802,
297,
9248,
9,
267,
10062,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
1159,
79,
14,
525,
2773,
60,
480,
8311,
2632,
401,
7340,
11198,
2924,
13670,
10805,
288,
9248,
12,
283,
8311,
1166,
358,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
633,
356,
4242,
63,
633,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
1369,
12,
288,
283,
8311,
356,
10062,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
445,
7527,
265,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
21418,
4537,
957,
15,
1289,
706,
9448,
48,
28,
344,
9514,
16,
13,
25,
2807,
7216,
14,
4786,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
21418,
14,
957,
15,
1289,
706,
15,
10078,
13,
274,
13,
21660,
567,
5789,
297,
267,
283,
1064,
21,
356,
283,
3776,
2869,
1235,
2470,
1229,
2333,
1229,
1643,
16456,
65,
25,
65,
2277,
10556,
1167,
825,
19,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
10078,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
2553,
428,
455,
567,
65,
128,
108,
297,
288,
283,
1802,
356,
283,
1064,
21,
26,
65,
18,
66,
20,
66,
7524,
8342,
17686,
10721,
31945,
2835,
70,
2114,
3833,
2501,
3129,
70,
297,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
3991,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
3991,
63,
344,
9,
398,
4242,
63,
633,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
1159,
79,
14,
525,
2773,
60,
480,
3722,
2632,
401,
7340,
11198,
2924,
13670,
10805,
9248,
12,
283,
3722,
1166,
358,
267,
2538,
275,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
9,
267,
1369,
275,
291,
423,
1360,
63,
1733,
63,
2024,
360,
1802,
297,
9248,
9,
267,
10062,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
1159,
79,
14,
525,
2773,
60,
480,
8311,
2632,
401,
7340,
11198,
2924,
13670,
10805,
288,
9248,
12,
283,
8311,
1166,
358,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
633,
356,
4242,
63,
633,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
1802,
356,
1369,
12,
288,
283,
8311,
356,
10062,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0
] |
kernel-sanders/arsenic-mobile | Dependencies/Twisted-13.0.0/twisted/python/test/test_inotify.py | 50 | 3584 | # Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.
"""
Tests for L{twisted.python._inotify}.
"""
from twisted.trial.unittest import TestCase
from twisted.python.runtime import platform
if platform.supportsINotify():
from ctypes import c_int, c_uint32, c_char_p
from twisted.python import _inotify
from twisted.python._inotify import (
INotifyError, initializeModule, init, add)
else:
_inotify = None
class INotifyTests(TestCase):
"""
Tests for L{twisted.python._inotify}.
"""
if _inotify is None:
skip = "This platform doesn't support INotify."
def test_missingInit(self):
"""
If the I{libc} object passed to L{initializeModule} has no
C{inotify_init} attribute, L{ImportError} is raised.
"""
class libc:
def inotify_add_watch(self):
pass
def inotify_rm_watch(self):
pass
self.assertRaises(ImportError, initializeModule, libc())
def test_missingAdd(self):
"""
If the I{libc} object passed to L{initializeModule} has no
C{inotify_add_watch} attribute, L{ImportError} is raised.
"""
class libc:
def inotify_init(self):
pass
def inotify_rm_watch(self):
pass
self.assertRaises(ImportError, initializeModule, libc())
def test_missingRemove(self):
"""
If the I{libc} object passed to L{initializeModule} has no
C{inotify_rm_watch} attribute, L{ImportError} is raised.
"""
class libc:
def inotify_init(self):
pass
def inotify_add_watch(self):
pass
self.assertRaises(ImportError, initializeModule, libc())
def test_setTypes(self):
"""
If the I{libc} object passed to L{initializeModule} has all of the
necessary attributes, it sets the C{argtypes} and C{restype} attributes
of the three ctypes methods used from libc.
"""
class libc:
def inotify_init(self):
pass
inotify_init = staticmethod(inotify_init)
def inotify_rm_watch(self):
pass
inotify_rm_watch = staticmethod(inotify_rm_watch)
def inotify_add_watch(self):
pass
inotify_add_watch = staticmethod(inotify_add_watch)
c = libc()
initializeModule(c)
self.assertEqual(c.inotify_init.argtypes, [])
self.assertEqual(c.inotify_init.restype, c_int)
self.assertEqual(c.inotify_rm_watch.argtypes, [c_int, c_int])
self.assertEqual(c.inotify_rm_watch.restype, c_int)
self.assertEqual(
c.inotify_add_watch.argtypes, [c_int, c_char_p, c_uint32])
self.assertEqual(c.inotify_add_watch.restype, c_int)
def test_failedInit(self):
"""
If C{inotify_init} returns a negative number, L{init} raises
L{INotifyError}.
"""
class libc:
def inotify_init(self):
return -1
self.patch(_inotify, 'libc', libc())
self.assertRaises(INotifyError, init)
def test_failedAddWatch(self):
"""
If C{inotify_add_watch} returns a negative number, L{add}
raises L{INotifyError}.
"""
class libc:
def inotify_add_watch(self, fd, path, mask):
return -1
self.patch(_inotify, 'libc', libc())
self.assertRaises(INotifyError, add, 3, '/foo', 0)
| gpl-3.0 | [
3,
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
491,
91,
12145,
14,
1548,
423,
10175,
3338,
5565,
199,
624,
199,
199,
504,
7390,
14,
14443,
14,
2796,
492,
7640,
199,
504,
7390,
14,
1548,
14,
7726,
492,
4298,
199,
199,
692,
4298,
14,
9823,
568,
79,
3338,
837,
272,
687,
5577,
492,
286,
63,
442,
12,
286,
63,
1635,
708,
12,
286,
63,
1560,
63,
80,
272,
687,
7390,
14,
1548,
492,
485,
10175,
3338,
272,
687,
7390,
14,
1548,
423,
10175,
3338,
492,
334,
267,
1621,
79,
3338,
547,
12,
8265,
2377,
12,
4205,
12,
1050,
9,
199,
2836,
26,
272,
485,
10175,
3338,
275,
488,
4388,
199,
533,
1621,
79,
3338,
2925,
8,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
12145,
14,
1548,
423,
10175,
3338,
5565,
272,
408,
272,
340,
485,
10175,
3338,
365,
488,
26,
267,
3372,
275,
298,
2765,
4298,
3181,
1133,
2291,
1621,
79,
3338,
2122,
339,
347,
511,
63,
4752,
9346,
8,
277,
304,
267,
408,
267,
982,
314,
473,
91,
20217,
93,
909,
3032,
370,
491,
91,
8489,
2377,
93,
965,
949,
267,
445,
91,
10175,
3338,
63,
826,
93,
2225,
12,
491,
91,
17825,
93,
365,
4915,
14,
267,
408,
267,
1021,
1973,
67,
26,
288,
347,
315,
79,
3338,
63,
525,
63,
6821,
8,
277,
304,
355,
986,
288,
347,
315,
79,
3338,
63,
5682,
63,
6821,
8,
277,
304,
355,
986,
267,
291,
14,
1855,
8,
17825,
12,
8265,
2377,
12,
1973,
67,
1012,
2378,
347,
511,
63,
4752,
1123,
8,
277,
304,
267,
408,
267,
982,
314,
473,
91,
20217,
93,
909,
3032,
370,
491,
91,
8489,
2377,
93,
965,
949,
267,
445,
91,
10175,
3338,
63,
525,
63,
6821,
93,
2225,
12,
491,
91,
17825,
93,
365,
4915,
14,
267,
408,
267,
1021,
1973,
67,
26,
288,
347,
315,
79,
3338,
63,
826,
8,
277,
304,
355,
986,
288,
347,
315,
79,
3338,
63,
5682,
63,
6821,
8,
277,
304,
355,
986,
267,
291,
14,
1855,
8,
17825,
12,
8265,
2377,
12,
1973,
67,
1012,
2378,
347,
511,
63,
4752,
5587,
8,
277,
304,
267,
408,
267,
982,
314,
473,
91,
20217,
93,
909,
3032,
370,
491,
91,
8489,
2377,
93,
965,
949,
267,
445,
91,
10175,
3338,
63,
5682,
63,
6821,
93,
2225,
12,
491,
91,
17825,
93,
365,
4915,
14,
267,
408,
267,
1021,
1973,
67,
26,
288,
347,
315,
79,
3338,
63,
826,
8,
277,
304,
355,
986,
288,
347,
315,
79,
3338,
63,
525,
63,
6821,
8,
277,
304,
355,
986,
267,
291,
14,
1855,
8,
17825,
12,
8265,
2377,
12,
1973,
67,
1012,
2378,
347,
511,
63,
409,
4100,
8,
277,
304,
267,
408,
267,
982,
314,
473,
91,
20217,
93,
909,
3032,
370,
491,
91,
8489,
2377,
93,
965,
1006,
402,
314,
267,
5784,
3004,
12,
652,
5951,
314,
445,
91,
10025,
93,
436,
445,
91,
9990,
93,
3004,
267,
402,
314,
7795,
5577,
3102,
1202,
687,
1973,
67,
14,
267,
408,
267,
1021,
1973,
67,
26,
288,
347,
315,
79,
3338,
63,
826,
8,
277,
304,
355,
986,
288,
315,
79,
3338,
63,
826,
275,
12822,
8,
10175,
3338,
63,
826,
9,
953,
347,
315,
79,
3338,
63,
5682,
63,
6821,
8,
277,
304,
355,
986,
288,
315,
79,
3338,
63,
5682,
63,
6821,
275,
12822,
8,
10175,
3338,
63,
5682,
63,
6821,
9,
953,
347,
315,
79,
3338,
63,
525,
63,
6821,
8,
277,
304,
355,
986,
288,
315,
79,
3338,
63,
525,
63,
6821,
275,
12822,
8,
10175,
3338,
63,
525,
63,
6821,
9,
398,
286,
275,
1973,
67,
342,
267,
8265,
2377,
8,
67,
9,
267,
291,
14,
629,
8,
67,
14,
10175,
3338,
63,
826,
14,
10025,
12,
3073,
267,
291,
14,
629,
8,
67,
14,
10175,
3338,
63,
826,
14,
9990,
12,
286,
63,
442,
9,
398,
291,
14,
629,
8,
67,
14,
10175,
3338,
63,
5682,
63,
6821,
14,
10025,
12,
359,
67,
63,
442,
12,
286,
63,
442,
566,
267,
291,
14,
629,
8,
67,
14,
10175,
3338,
63,
5682,
63,
6821,
14,
9990,
12,
286,
63,
442,
9,
398,
291,
14,
629,
8,
288,
286,
14,
10175,
3338,
63,
525,
63,
6821,
14,
10025,
12,
359,
67,
63,
442,
12,
286,
63,
1560,
63,
80,
12,
286,
63,
1635,
708,
566,
267,
291,
14,
629,
8,
67,
14,
10175,
3338,
63,
525,
63,
6821,
14,
9990,
12,
286,
63,
442,
9,
2378,
347,
511,
63,
4892,
9346,
8,
277,
304,
267,
408,
267,
982,
445,
91,
10175,
3338,
63,
826,
93,
2529,
282,
6946,
1329,
12,
491,
91,
826,
93,
6534,
267,
491,
91,
568,
79,
3338,
547,
5565,
267,
408,
267,
1021,
1973,
67,
26,
288,
347,
315,
79,
3338,
63,
826,
8,
277,
304,
355,
372,
446,
17,
267,
291,
14,
2068,
1547,
10175,
3338,
12,
283,
20217,
297,
1973,
67,
1012,
267,
291,
14,
1855,
8,
568,
79,
3338,
547,
12,
4205,
9,
2378,
347,
511,
63,
4892,
1123,
13978,
8,
277,
304,
267,
408,
267,
982,
445,
91,
10175,
3338,
63,
525,
63,
6821,
93,
2529,
282,
6946,
1329,
12,
491,
91,
525,
93,
267,
6534,
491,
91,
568,
79,
3338,
547,
5565,
267,
408,
267,
1021,
1973,
67,
26,
288,
347,
315,
79,
3338,
63,
525,
63,
6821,
8,
277,
12,
6111,
12,
931,
12,
3656,
304,
355,
372,
446,
17,
267,
291,
14,
2068,
1547,
10175,
3338,
12,
283,
20217,
297,
1973,
67,
1012,
267,
291,
14,
1855,
8,
568,
79,
3338,
547,
12,
1050,
12,
650,
12,
1994,
1421,
297,
378,
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
] | [
1898,
334,
67,
9,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
2925,
367,
491,
91,
12145,
14,
1548,
423,
10175,
3338,
5565,
199,
624,
199,
199,
504,
7390,
14,
14443,
14,
2796,
492,
7640,
199,
504,
7390,
14,
1548,
14,
7726,
492,
4298,
199,
199,
692,
4298,
14,
9823,
568,
79,
3338,
837,
272,
687,
5577,
492,
286,
63,
442,
12,
286,
63,
1635,
708,
12,
286,
63,
1560,
63,
80,
272,
687,
7390,
14,
1548,
492,
485,
10175,
3338,
272,
687,
7390,
14,
1548,
423,
10175,
3338,
492,
334,
267,
1621,
79,
3338,
547,
12,
8265,
2377,
12,
4205,
12,
1050,
9,
199,
2836,
26,
272,
485,
10175,
3338,
275,
488,
4388,
199,
533,
1621,
79,
3338,
2925,
8,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
12145,
14,
1548,
423,
10175,
3338,
5565,
272,
408,
272,
340,
485,
10175,
3338,
365,
488,
26,
267,
3372,
275,
298,
2765,
4298,
3181,
1133,
2291,
1621,
79,
3338,
2122,
339,
347,
511,
63,
4752,
9346,
8,
277,
304,
267,
408,
267,
982,
314,
473,
91,
20217,
93,
909,
3032,
370,
491,
91,
8489,
2377,
93,
965,
949,
267,
445,
91,
10175,
3338,
63,
826,
93,
2225,
12,
491,
91,
17825,
93,
365,
4915,
14,
267,
408,
267,
1021,
1973,
67,
26,
288,
347,
315,
79,
3338,
63,
525,
63,
6821,
8,
277,
304,
355,
986,
288,
347,
315,
79,
3338,
63,
5682,
63,
6821,
8,
277,
304,
355,
986,
267,
291,
14,
1855,
8,
17825,
12,
8265,
2377,
12,
1973,
67,
1012,
2378,
347,
511,
63,
4752,
1123,
8,
277,
304,
267,
408,
267,
982,
314,
473,
91,
20217,
93,
909,
3032,
370,
491,
91,
8489,
2377,
93,
965,
949,
267,
445,
91,
10175,
3338,
63,
525,
63,
6821,
93,
2225,
12,
491,
91,
17825,
93,
365,
4915,
14,
267,
408,
267,
1021,
1973,
67,
26,
288,
347,
315,
79,
3338,
63,
826,
8,
277,
304,
355,
986,
288,
347,
315,
79,
3338,
63,
5682,
63,
6821,
8,
277,
304,
355,
986,
267,
291,
14,
1855,
8,
17825,
12,
8265,
2377,
12,
1973,
67,
1012,
2378,
347,
511,
63,
4752,
5587,
8,
277,
304,
267,
408,
267,
982,
314,
473,
91,
20217,
93,
909,
3032,
370,
491,
91,
8489,
2377,
93,
965,
949,
267,
445,
91,
10175,
3338,
63,
5682,
63,
6821,
93,
2225,
12,
491,
91,
17825,
93,
365,
4915,
14,
267,
408,
267,
1021,
1973,
67,
26,
288,
347,
315,
79,
3338,
63,
826,
8,
277,
304,
355,
986,
288,
347,
315,
79,
3338,
63,
525,
63,
6821,
8,
277,
304,
355,
986,
267,
291,
14,
1855,
8,
17825,
12,
8265,
2377,
12,
1973,
67,
1012,
2378,
347,
511,
63,
409,
4100,
8,
277,
304,
267,
408,
267,
982,
314,
473,
91,
20217,
93,
909,
3032,
370,
491,
91,
8489,
2377,
93,
965,
1006,
402,
314,
267,
5784,
3004,
12,
652,
5951,
314,
445,
91,
10025,
93,
436,
445,
91,
9990,
93,
3004,
267,
402,
314,
7795,
5577,
3102,
1202,
687,
1973,
67,
14,
267,
408,
267,
1021,
1973,
67,
26,
288,
347,
315,
79,
3338,
63,
826,
8,
277,
304,
355,
986,
288,
315,
79,
3338,
63,
826,
275,
12822,
8,
10175,
3338,
63,
826,
9,
953,
347,
315,
79,
3338,
63,
5682,
63,
6821,
8,
277,
304,
355,
986,
288,
315,
79,
3338,
63,
5682,
63,
6821,
275,
12822,
8,
10175,
3338,
63,
5682,
63,
6821,
9,
953,
347,
315,
79,
3338,
63,
525,
63,
6821,
8,
277,
304,
355,
986,
288,
315,
79,
3338,
63,
525,
63,
6821,
275,
12822,
8,
10175,
3338,
63,
525,
63,
6821,
9,
398,
286,
275,
1973,
67,
342,
267,
8265,
2377,
8,
67,
9,
267,
291,
14,
629,
8,
67,
14,
10175,
3338,
63,
826,
14,
10025,
12,
3073,
267,
291,
14,
629,
8,
67,
14,
10175,
3338,
63,
826,
14,
9990,
12,
286,
63,
442,
9,
398,
291,
14,
629,
8,
67,
14,
10175,
3338,
63,
5682,
63,
6821,
14,
10025,
12,
359,
67,
63,
442,
12,
286,
63,
442,
566,
267,
291,
14,
629,
8,
67,
14,
10175,
3338,
63,
5682,
63,
6821,
14,
9990,
12,
286,
63,
442,
9,
398,
291,
14,
629,
8,
288,
286,
14,
10175,
3338,
63,
525,
63,
6821,
14,
10025,
12,
359,
67,
63,
442,
12,
286,
63,
1560,
63,
80,
12,
286,
63,
1635,
708,
566,
267,
291,
14,
629,
8,
67,
14,
10175,
3338,
63,
525,
63,
6821,
14,
9990,
12,
286,
63,
442,
9,
2378,
347,
511,
63,
4892,
9346,
8,
277,
304,
267,
408,
267,
982,
445,
91,
10175,
3338,
63,
826,
93,
2529,
282,
6946,
1329,
12,
491,
91,
826,
93,
6534,
267,
491,
91,
568,
79,
3338,
547,
5565,
267,
408,
267,
1021,
1973,
67,
26,
288,
347,
315,
79,
3338,
63,
826,
8,
277,
304,
355,
372,
446,
17,
267,
291,
14,
2068,
1547,
10175,
3338,
12,
283,
20217,
297,
1973,
67,
1012,
267,
291,
14,
1855,
8,
568,
79,
3338,
547,
12,
4205,
9,
2378,
347,
511,
63,
4892,
1123,
13978,
8,
277,
304,
267,
408,
267,
982,
445,
91,
10175,
3338,
63,
525,
63,
6821,
93,
2529,
282,
6946,
1329,
12,
491,
91,
525,
93,
267,
6534,
491,
91,
568,
79,
3338,
547,
5565,
267,
408,
267,
1021,
1973,
67,
26,
288,
347,
315,
79,
3338,
63,
525,
63,
6821,
8,
277,
12,
6111,
12,
931,
12,
3656,
304,
355,
372,
446,
17,
267,
291,
14,
2068,
1547,
10175,
3338,
12,
283,
20217,
297,
1973,
67,
1012,
267,
291,
14,
1855,
8,
568,
79,
3338,
547,
12,
1050,
12,
650,
12,
1994,
1421,
297,
378,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
qedsoftware/commcare-hq | custom/opm/constants.py | 1 | 1732 | from corehq.apps.fixtures.models import FixtureDataItem
from corehq.util.quickcache import quickcache
DOMAIN = 'opm'
PREG_REG_XMLNS = "http://openrosa.org/formdesigner/D127C457-3E15-4F5E-88C3-98CD1722C625"
VHND_XMLNS = "http://openrosa.org/formdesigner/ff5de10d75afda15cddb3b00a0b1e21d33a50d59"
BIRTH_PREP_XMLNS = "http://openrosa.org/formdesigner/50378991-FEC3-408D-B4A5-A264F3B52184"
DELIVERY_XMLNS = "http://openrosa.org/formdesigner/492F8F0E-EE7D-4B28-B890-7CDA5F137194"
CHILD_FOLLOWUP_XMLNS = "http://openrosa.org/formdesigner/C90C2C1F-3B34-47F3-B3A3-061EAAC1A601"
CFU1_XMLNS = "http://openrosa.org/formdesigner/d642dd328514f2af92c093d414d63e5b2670b9c"
CFU2_XMLNS = "http://openrosa.org/formdesigner/9ef423bba8595a99976f0bc9532617841253a7fa"
CFU3_XMLNS = "http://openrosa.org/formdesigner/f15b9f8fb92e2552b1885897ece257609ed16649"
GROWTH_MONITORING_XMLNS= "http://openrosa.org/formdesigner/F1356F3F-C695-491F-9277-7F9B5522200C"
CLOSE_FORM = "http://openrosa.org/formdesigner/41A1B3E0-C1A4-41EA-AE90-71A328F0D8FD"
CHILDREN_FORMS = [CFU1_XMLNS, CFU2_XMLNS, CFU3_XMLNS, CHILD_FOLLOWUP_XMLNS]
OPM_XMLNSs = [PREG_REG_XMLNS, VHND_XMLNS, BIRTH_PREP_XMLNS, DELIVERY_XMLNS,
CHILD_FOLLOWUP_XMLNS, CFU1_XMLNS, CFU2_XMLNS, CFU3_XMLNS,
GROWTH_MONITORING_XMLNS, CLOSE_FORM]
# TODO Move these to a cached fixtures lookup
MONTH_AMT = 250
TWO_YEAR_AMT = 2000
THREE_YEAR_AMT = 3000
@quickcache([], timeout=30 * 60)
def get_fixture_data():
fixtures = FixtureDataItem.get_indexed_items(DOMAIN, 'condition_amounts', 'condition')
return dict((k, int(fixture['rs_amount'])) for k, fixture in fixtures.items())
class InvalidRow(Exception):
"""
Raise this in the row constructor to skip row
"""
| bsd-3-clause | [
504,
6170,
21550,
14,
5181,
14,
8769,
14,
992,
492,
31574,
4167,
1451,
2081,
199,
504,
6170,
21550,
14,
1974,
14,
13239,
1637,
492,
12530,
1637,
199,
199,
7378,
275,
283,
31961,
7,
199,
199,
4225,
39,
63,
5616,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
36,
4195,
35,
27603,
13,
19,
37,
1046,
13,
20,
38,
21,
37,
13,
1299,
35,
19,
13,
2905,
7695,
1196,
1081,
35,
22475,
2,
199,
54,
40,
8711,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
556,
21,
271,
709,
68,
2194,
2756,
983,
1046,
67,
23217,
19,
66,
383,
65,
16,
66,
17,
69,
2025,
68,
1153,
65,
1400,
68,
1427,
2,
199,
34,
3927,
2080,
63,
4225,
48,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
1400,
12046,
18411,
13,
38,
4220,
19,
13,
26132,
36,
13,
34,
20,
33,
21,
13,
33,
9408,
38,
19,
34,
2528,
10078,
2,
199,
1093,
2673,
2111,
57,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
25722,
38,
24,
38,
16,
37,
13,
8699,
23,
36,
13,
20,
34,
1651,
13,
34,
13173,
13,
23,
7695,
33,
21,
38,
7498,
10860,
2,
199,
30460,
63,
38,
29905,
2160,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
35,
2710,
35,
18,
35,
17,
38,
13,
19,
34,
1082,
13,
2417,
38,
19,
13,
34,
19,
33,
19,
13,
22531,
11765,
1348,
17,
33,
24539,
2,
199,
5487,
53,
17,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
68,
15463,
617,
708,
2426,
1079,
70,
18,
2756,
2942,
67,
19035,
68,
25250,
68,
2766,
69,
21,
66,
1479,
2760,
66,
25,
67,
2,
199,
5487,
53,
18,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
25,
2829,
30813,
32703,
24,
16447,
65,
5637,
2114,
70,
16,
3776,
2720,
8342,
1196,
1349,
28452,
65,
23,
667,
2,
199,
5487,
53,
19,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
70,
1046,
66,
25,
70,
24,
4675,
2942,
69,
2299,
18,
66,
1085,
2426,
8483,
69,
301,
821,
2114,
1643,
379,
975,
11228,
2,
199,
39,
11415,
2080,
63,
32387,
726,
1206,
63,
4317,
2709,
29,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
38,
969,
1367,
38,
19,
38,
13,
35,
20017,
13,
27712,
38,
13,
2942,
1138,
13,
23,
38,
25,
34,
1229,
1081,
1840,
35,
2,
199,
199,
18219,
63,
3516,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
2953,
33,
17,
34,
19,
37,
16,
13,
35,
17,
33,
20,
13,
2953,
11765,
13,
12500,
2710,
13,
3172,
33,
12870,
38,
16,
36,
24,
7902,
2,
199,
1244,
1193,
4564,
742,
63,
11518,
275,
359,
5487,
53,
17,
63,
4317,
2709,
12,
6035,
53,
18,
63,
4317,
2709,
12,
6035,
53,
19,
63,
4317,
2709,
12,
6624,
6853,
63,
38,
29905,
2160,
63,
4317,
2709,
61,
199,
199,
1938,
45,
63,
4317,
2709,
83,
275,
359,
4225,
39,
63,
5616,
63,
4317,
2709,
12,
812,
40,
8711,
63,
4317,
2709,
12,
699,
3927,
2080,
63,
4225,
48,
63,
4317,
2709,
12,
3265,
2673,
2111,
57,
63,
4317,
2709,
12,
1598,
6624,
6853,
63,
38,
29905,
2160,
63,
4317,
2709,
12,
6035,
53,
17,
63,
4317,
2709,
12,
6035,
53,
18,
63,
4317,
2709,
12,
6035,
53,
19,
63,
4317,
2709,
12,
1598,
598,
11415,
2080,
63,
32387,
726,
1206,
63,
4317,
2709,
12,
445,
1484,
899,
63,
3516,
61,
199,
199,
3,
3254,
14171,
3520,
370,
282,
6328,
15188,
4237,
199,
16413,
63,
1156,
52,
275,
16074,
199,
52,
11325,
63,
19216,
63,
1156,
52,
275,
12293,
199,
2080,
5271,
63,
19216,
63,
1156,
52,
275,
29664,
421,
199,
32,
13239,
1637,
8798,
2653,
29,
1216,
627,
5212,
9,
199,
318,
664,
63,
5997,
63,
576,
837,
272,
15188,
275,
31574,
4167,
1451,
2081,
14,
362,
63,
16821,
63,
1744,
8,
7378,
12,
283,
5394,
63,
4606,
83,
297,
283,
5394,
358,
272,
372,
1211,
1332,
75,
12,
1109,
8,
5997,
459,
2393,
63,
4606,
5156,
367,
1022,
12,
10949,
315,
15188,
14,
1744,
1012,
421,
199,
533,
6378,
5810,
8,
1726,
304,
272,
408,
272,
14771,
642,
315,
314,
1962,
3787,
370,
3372,
1962,
272,
408,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
6170,
21550,
14,
5181,
14,
8769,
14,
992,
492,
31574,
4167,
1451,
2081,
199,
504,
6170,
21550,
14,
1974,
14,
13239,
1637,
492,
12530,
1637,
199,
199,
7378,
275,
283,
31961,
7,
199,
199,
4225,
39,
63,
5616,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
36,
4195,
35,
27603,
13,
19,
37,
1046,
13,
20,
38,
21,
37,
13,
1299,
35,
19,
13,
2905,
7695,
1196,
1081,
35,
22475,
2,
199,
54,
40,
8711,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
556,
21,
271,
709,
68,
2194,
2756,
983,
1046,
67,
23217,
19,
66,
383,
65,
16,
66,
17,
69,
2025,
68,
1153,
65,
1400,
68,
1427,
2,
199,
34,
3927,
2080,
63,
4225,
48,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
1400,
12046,
18411,
13,
38,
4220,
19,
13,
26132,
36,
13,
34,
20,
33,
21,
13,
33,
9408,
38,
19,
34,
2528,
10078,
2,
199,
1093,
2673,
2111,
57,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
25722,
38,
24,
38,
16,
37,
13,
8699,
23,
36,
13,
20,
34,
1651,
13,
34,
13173,
13,
23,
7695,
33,
21,
38,
7498,
10860,
2,
199,
30460,
63,
38,
29905,
2160,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
35,
2710,
35,
18,
35,
17,
38,
13,
19,
34,
1082,
13,
2417,
38,
19,
13,
34,
19,
33,
19,
13,
22531,
11765,
1348,
17,
33,
24539,
2,
199,
5487,
53,
17,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
68,
15463,
617,
708,
2426,
1079,
70,
18,
2756,
2942,
67,
19035,
68,
25250,
68,
2766,
69,
21,
66,
1479,
2760,
66,
25,
67,
2,
199,
5487,
53,
18,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
25,
2829,
30813,
32703,
24,
16447,
65,
5637,
2114,
70,
16,
3776,
2720,
8342,
1196,
1349,
28452,
65,
23,
667,
2,
199,
5487,
53,
19,
63,
4317,
2709,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
70,
1046,
66,
25,
70,
24,
4675,
2942,
69,
2299,
18,
66,
1085,
2426,
8483,
69,
301,
821,
2114,
1643,
379,
975,
11228,
2,
199,
39,
11415,
2080,
63,
32387,
726,
1206,
63,
4317,
2709,
29,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
38,
969,
1367,
38,
19,
38,
13,
35,
20017,
13,
27712,
38,
13,
2942,
1138,
13,
23,
38,
25,
34,
1229,
1081,
1840,
35,
2,
199,
199,
18219,
63,
3516,
275,
298,
1014,
921,
1490,
293,
2231,
14,
1308,
15,
964,
14748,
281,
15,
2953,
33,
17,
34,
19,
37,
16,
13,
35,
17,
33,
20,
13,
2953,
11765,
13,
12500,
2710,
13,
3172,
33,
12870,
38,
16,
36,
24,
7902,
2,
199,
1244,
1193,
4564,
742,
63,
11518,
275,
359,
5487,
53,
17,
63,
4317,
2709,
12,
6035,
53,
18,
63,
4317,
2709,
12,
6035,
53,
19,
63,
4317,
2709,
12,
6624,
6853,
63,
38,
29905,
2160,
63,
4317,
2709,
61,
199,
199,
1938,
45,
63,
4317,
2709,
83,
275,
359,
4225,
39,
63,
5616,
63,
4317,
2709,
12,
812,
40,
8711,
63,
4317,
2709,
12,
699,
3927,
2080,
63,
4225,
48,
63,
4317,
2709,
12,
3265,
2673,
2111,
57,
63,
4317,
2709,
12,
1598,
6624,
6853,
63,
38,
29905,
2160,
63,
4317,
2709,
12,
6035,
53,
17,
63,
4317,
2709,
12,
6035,
53,
18,
63,
4317,
2709,
12,
6035,
53,
19,
63,
4317,
2709,
12,
1598,
598,
11415,
2080,
63,
32387,
726,
1206,
63,
4317,
2709,
12,
445,
1484,
899,
63,
3516,
61,
199,
199,
3,
3254,
14171,
3520,
370,
282,
6328,
15188,
4237,
199,
16413,
63,
1156,
52,
275,
16074,
199,
52,
11325,
63,
19216,
63,
1156,
52,
275,
12293,
199,
2080,
5271,
63,
19216,
63,
1156,
52,
275,
29664,
421,
199,
32,
13239,
1637,
8798,
2653,
29,
1216,
627,
5212,
9,
199,
318,
664,
63,
5997,
63,
576,
837,
272,
15188,
275,
31574,
4167,
1451,
2081,
14,
362,
63,
16821,
63,
1744,
8,
7378,
12,
283,
5394,
63,
4606,
83,
297,
283,
5394,
358,
272,
372,
1211,
1332,
75,
12,
1109,
8,
5997,
459,
2393,
63,
4606,
5156,
367,
1022,
12,
10949,
315,
15188,
14,
1744,
1012,
421,
199,
533,
6378,
5810,
8,
1726,
304,
272,
408,
272,
14771,
642,
315,
314,
1962,
3787,
370,
3372,
1962,
272,
408,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
roadmapper/ansible | test/units/modules/network/opx/opx_module.py | 52 | 2604 | # (c) 2018 Red Hat Inc.
#
# (c) 2018 Dell Inc. or its subsidiaries. All Rights Reserved.
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Make coding more python3-ish
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import os
import json
from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures')
fixture_data = {}
def load_fixture(name):
path = os.path.join(fixture_path, name)
if path in fixture_data:
return fixture_data[path]
with open(path) as f:
data = f.read()
try:
data = json.loads(data)
except Exception:
pass
fixture_data[path] = data
return data
class TestOpxModule(ModuleTestCase):
def execute_module(self, failed=False, changed=False,
response=None, msg=None, db=None,
commit_event=None):
self.load_fixtures(response)
if failed:
result = self.failed(msg)
self.assertTrue(result['failed'], result)
else:
result = self.changed(changed, db)
self.assertEqual(result['changed'], changed, result)
return result
def failed(self, msg):
with self.assertRaises(AnsibleFailJson) as exc:
self.module.main()
result = exc.exception.args[0]
self.assertTrue(result['failed'], result)
self.assertEqual(result['msg'], msg, result)
return result
def changed(self, changed=False, db=None):
with self.assertRaises(AnsibleExitJson) as exc:
self.module.main()
result = exc.exception.args[0]
print("res" + str(result) + "dv=" + str(db) + "ch=" + str(changed))
self.assertEqual(result['changed'], changed, result)
if db:
self.assertEqual(result['db'], db, result)
return result
def load_fixtures(self, response=None):
pass
| gpl-3.0 | [
3,
334,
67,
9,
14894,
9572,
13002,
3277,
14,
199,
3,
199,
3,
334,
67,
9,
14894,
577,
1697,
3277,
14,
503,
2399,
1007,
338,
328,
3433,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
646,
2022,
199,
199,
504,
6204,
14,
3112,
14,
1208,
492,
2622,
6699,
9653,
12,
2622,
4874,
9653,
12,
5673,
1746,
421,
199,
5997,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
8769,
358,
199,
5997,
63,
576,
275,
1052,
421,
199,
318,
2248,
63,
5997,
8,
354,
304,
272,
931,
275,
747,
14,
515,
14,
904,
8,
5997,
63,
515,
12,
536,
9,
339,
340,
931,
315,
10949,
63,
576,
26,
267,
372,
10949,
63,
576,
59,
515,
61,
339,
543,
1551,
8,
515,
9,
465,
289,
26,
267,
666,
275,
289,
14,
739,
342,
339,
862,
26,
267,
666,
275,
2022,
14,
3640,
8,
576,
9,
272,
871,
2186,
26,
267,
986,
339,
10949,
63,
576,
59,
515,
61,
275,
666,
272,
372,
666,
421,
199,
533,
1379,
4619,
88,
2377,
8,
2377,
1746,
304,
339,
347,
5341,
63,
578,
8,
277,
12,
3405,
29,
797,
12,
2896,
29,
797,
12,
2432,
1177,
29,
403,
12,
1499,
29,
403,
12,
1592,
29,
403,
12,
2432,
5532,
63,
1430,
29,
403,
304,
398,
291,
14,
912,
63,
8769,
8,
1310,
9,
398,
340,
3405,
26,
288,
754,
275,
291,
14,
4892,
8,
1328,
9,
288,
291,
14,
1815,
8,
1099,
459,
4892,
995,
754,
9,
267,
587,
26,
288,
754,
275,
291,
14,
2489,
8,
2489,
12,
1592,
9,
288,
291,
14,
629,
8,
1099,
459,
2489,
995,
2896,
12,
754,
9,
398,
372,
754,
339,
347,
3405,
8,
277,
12,
1499,
304,
267,
543,
291,
14,
1855,
8,
10047,
4874,
9653,
9,
465,
3178,
26,
288,
291,
14,
578,
14,
973,
342,
398,
754,
275,
3178,
14,
1971,
14,
589,
59,
16,
61,
267,
291,
14,
1815,
8,
1099,
459,
4892,
995,
754,
9,
267,
291,
14,
629,
8,
1099,
459,
1328,
995,
1499,
12,
754,
9,
267,
372,
754,
339,
347,
2896,
8,
277,
12,
2896,
29,
797,
12,
1592,
29,
403,
304,
267,
543,
291,
14,
1855,
8,
10047,
6699,
9653,
9,
465,
3178,
26,
288,
291,
14,
578,
14,
973,
342,
398,
754,
275,
3178,
14,
1971,
14,
589,
59,
16,
61,
267,
870,
480,
470,
2,
435,
620,
8,
1099,
9,
435,
298,
8398,
628,
435,
620,
8,
697,
9,
435,
298,
335,
628,
435,
620,
8,
2489,
430,
267,
291,
14,
629,
8,
1099,
459,
2489,
995,
2896,
12,
754,
9,
267,
340,
1592,
26,
288,
291,
14,
629,
8,
1099,
459,
697,
995,
1592,
12,
754,
9,
398,
372,
754,
339,
347,
2248,
63,
8769,
8,
277,
12,
1177,
29,
403,
304,
267,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
14894,
9572,
13002,
3277,
14,
199,
3,
199,
3,
334,
67,
9,
14894,
577,
1697,
3277,
14,
503,
2399,
1007,
338,
328,
3433,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
3,
4155,
2803,
1655,
2366,
19,
13,
2453,
199,
504,
636,
2443,
363,
492,
334,
6116,
63,
646,
12,
4629,
12,
870,
63,
1593,
9,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
747,
199,
646,
2022,
199,
199,
504,
6204,
14,
3112,
14,
1208,
492,
2622,
6699,
9653,
12,
2622,
4874,
9653,
12,
5673,
1746,
421,
199,
5997,
63,
515,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
3475,
3460,
493,
10139,
283,
8769,
358,
199,
5997,
63,
576,
275,
1052,
421,
199,
318,
2248,
63,
5997,
8,
354,
304,
272,
931,
275,
747,
14,
515,
14,
904,
8,
5997,
63,
515,
12,
536,
9,
339,
340,
931,
315,
10949,
63,
576,
26,
267,
372,
10949,
63,
576,
59,
515,
61,
339,
543,
1551,
8,
515,
9,
465,
289,
26,
267,
666,
275,
289,
14,
739,
342,
339,
862,
26,
267,
666,
275,
2022,
14,
3640,
8,
576,
9,
272,
871,
2186,
26,
267,
986,
339,
10949,
63,
576,
59,
515,
61,
275,
666,
272,
372,
666,
421,
199,
533,
1379,
4619,
88,
2377,
8,
2377,
1746,
304,
339,
347,
5341,
63,
578,
8,
277,
12,
3405,
29,
797,
12,
2896,
29,
797,
12,
2432,
1177,
29,
403,
12,
1499,
29,
403,
12,
1592,
29,
403,
12,
2432,
5532,
63,
1430,
29,
403,
304,
398,
291,
14,
912,
63,
8769,
8,
1310,
9,
398,
340,
3405,
26,
288,
754,
275,
291,
14,
4892,
8,
1328,
9,
288,
291,
14,
1815,
8,
1099,
459,
4892,
995,
754,
9,
267,
587,
26,
288,
754,
275,
291,
14,
2489,
8,
2489,
12,
1592,
9,
288,
291,
14,
629,
8,
1099,
459,
2489,
995,
2896,
12,
754,
9,
398,
372,
754,
339,
347,
3405,
8,
277,
12,
1499,
304,
267,
543,
291,
14,
1855,
8,
10047,
4874,
9653,
9,
465,
3178,
26,
288,
291,
14,
578,
14,
973,
342,
398,
754,
275,
3178,
14,
1971,
14,
589,
59,
16,
61,
267,
291,
14,
1815,
8,
1099,
459,
4892,
995,
754,
9,
267,
291,
14,
629,
8,
1099,
459,
1328,
995,
1499,
12,
754,
9,
267,
372,
754,
339,
347,
2896,
8,
277,
12,
2896,
29,
797,
12,
1592,
29,
403,
304,
267,
543,
291,
14,
1855,
8,
10047,
6699,
9653,
9,
465,
3178,
26,
288,
291,
14,
578,
14,
973,
342,
398,
754,
275,
3178,
14,
1971,
14,
589,
59,
16,
61,
267,
870,
480,
470,
2,
435,
620,
8,
1099,
9,
435,
298,
8398,
628,
435,
620,
8,
697,
9,
435,
298,
335,
628,
435,
620,
8,
2489,
430,
267,
291,
14,
629,
8,
1099,
459,
2489,
995,
2896,
12,
754,
9,
267,
340,
1592,
26,
288,
291,
14,
629,
8,
1099,
459,
697,
995,
1592,
12,
754,
9,
398,
372,
754,
339,
347,
2248,
63,
8769,
8,
277,
12,
1177,
29,
403,
304,
267,
986,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
brijeshkesariya/odoo | addons/account_payment/wizard/account_payment_order.py | 338 | 5906 | # -*- 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 time
from lxml import etree
from openerp.osv import fields, osv
from openerp.tools.translate import _
class payment_order_create(osv.osv_memory):
"""
Create a payment object with lines corresponding to the account move line
to pay according to the date and the mode provided by the user.
Hypothesis:
- Small number of non-reconciled move line, payment mode and bank account type,
- Big number of partner and bank account.
If a type is given, unsuitable account Entry lines are ignored.
"""
_name = 'payment.order.create'
_description = 'payment.order.create'
_columns = {
'duedate': fields.date('Due Date', required=True),
'entries': fields.many2many('account.move.line', 'line_pay_rel', 'pay_id', 'line_id', 'Entries')
}
_defaults = {
'duedate': lambda *a: time.strftime('%Y-%m-%d'),
}
def fields_view_get(self, cr, uid, view_id=None, view_type='form', context=None, toolbar=False, submenu=False):
if not context: context = {}
res = super(payment_order_create, self).fields_view_get(cr, uid, view_id=view_id, view_type=view_type, context=context, toolbar=toolbar, submenu=False)
if context and 'line_ids' in context:
doc = etree.XML(res['arch'])
nodes = doc.xpath("//field[@name='entries']")
for node in nodes:
node.set('domain', '[("id", "in", '+ str(context['line_ids'])+')]')
res['arch'] = etree.tostring(doc)
return res
def create_payment(self, cr, uid, ids, context=None):
order_obj = self.pool.get('payment.order')
line_obj = self.pool.get('account.move.line')
payment_obj = self.pool.get('payment.line')
if context is None:
context = {}
data = self.browse(cr, uid, ids, context=context)[0]
line_ids = [entry.id for entry in data.entries]
if not line_ids:
return {'type': 'ir.actions.act_window_close'}
payment = order_obj.browse(cr, uid, context['active_id'], context=context)
t = None
line2bank = line_obj.line2bank(cr, uid, line_ids, t, context)
## Finally populate the current payment with new lines:
for line in line_obj.browse(cr, uid, line_ids, context=context):
if payment.date_prefered == "now":
#no payment date => immediate payment
date_to_pay = False
elif payment.date_prefered == 'due':
date_to_pay = line.date_maturity
elif payment.date_prefered == 'fixed':
date_to_pay = payment.date_scheduled
payment_obj.create(cr, uid,{
'move_line_id': line.id,
'amount_currency': line.amount_residual_currency,
'bank_id': line2bank.get(line.id),
'order_id': payment.id,
'partner_id': line.partner_id and line.partner_id.id or False,
'communication': line.ref or '/',
'state': line.invoice and line.invoice.reference_type != 'none' and 'structured' or 'normal',
'date': date_to_pay,
'currency': (line.invoice and line.invoice.currency_id.id) or line.journal_id.currency.id or line.journal_id.company_id.currency_id.id,
}, context=context)
return {'type': 'ir.actions.act_window_close'}
def search_entries(self, cr, uid, ids, context=None):
line_obj = self.pool.get('account.move.line')
mod_obj = self.pool.get('ir.model.data')
if context is None:
context = {}
data = self.browse(cr, uid, ids, context=context)[0]
search_due_date = data.duedate
# payment = self.pool.get('payment.order').browse(cr, uid, context['active_id'], context=context)
# Search for move line to pay:
domain = [('reconcile_id', '=', False), ('account_id.type', '=', 'payable'), ('credit', '>', 0), ('account_id.reconcile', '=', True)]
domain = domain + ['|', ('date_maturity', '<=', search_due_date), ('date_maturity', '=', False)]
line_ids = line_obj.search(cr, uid, domain, context=context)
context = dict(context, line_ids=line_ids)
model_data_ids = mod_obj.search(cr, uid,[('model', '=', 'ir.ui.view'), ('name', '=', 'view_create_payment_order_lines')], context=context)
resource_id = mod_obj.read(cr, uid, model_data_ids, fields=['res_id'], context=context)[0]['res_id']
return {'name': _('Entry Lines'),
'context': context,
'view_type': 'form',
'view_mode': 'form',
'res_model': 'payment.order.create',
'views': [(resource_id,'form')],
'type': 'ir.actions.act_window',
'target': 'new',
}
# 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,
900,
199,
504,
14490,
492,
7559,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
533,
11628,
63,
1648,
63,
981,
8,
4795,
14,
4795,
63,
4844,
304,
272,
408,
272,
2790,
282,
11628,
909,
543,
2385,
5226,
370,
314,
2933,
4057,
1004,
272,
370,
8633,
7182,
370,
314,
1434,
436,
314,
818,
2741,
701,
314,
922,
14,
272,
29591,
555,
14925,
26,
272,
446,
23704,
1329,
402,
2222,
13,
14808,
1672,
4057,
1004,
12,
11628,
818,
436,
16297,
2933,
730,
12,
272,
446,
13123,
1329,
402,
5854,
436,
16297,
2933,
14,
339,
982,
282,
730,
365,
1627,
12,
625,
83,
10020,
2933,
11855,
2385,
787,
5525,
14,
272,
408,
339,
485,
354,
275,
283,
7948,
14,
1648,
14,
981,
7,
272,
485,
1802,
275,
283,
7948,
14,
1648,
14,
981,
7,
272,
485,
3406,
275,
469,
267,
283,
11933,
602,
356,
1504,
14,
602,
360,
36,
310,
6148,
297,
1415,
29,
549,
395,
267,
283,
3189,
356,
1504,
14,
3479,
18,
3479,
360,
2048,
14,
1185,
14,
604,
297,
283,
604,
63,
5989,
63,
3369,
297,
283,
5989,
63,
344,
297,
283,
604,
63,
344,
297,
283,
17816,
358,
272,
789,
272,
485,
4322,
275,
469,
268,
283,
11933,
602,
356,
2400,
627,
65,
26,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
659,
272,
789,
339,
347,
1504,
63,
1345,
63,
362,
8,
277,
12,
2467,
12,
1747,
12,
2455,
63,
344,
29,
403,
12,
2455,
63,
466,
534,
964,
297,
1067,
29,
403,
12,
22483,
29,
797,
12,
1007,
4470,
29,
797,
304,
267,
340,
440,
1067,
26,
1067,
275,
1052,
267,
522,
275,
1613,
8,
7948,
63,
1648,
63,
981,
12,
291,
680,
955,
63,
1345,
63,
362,
8,
1556,
12,
1747,
12,
2455,
63,
344,
29,
1345,
63,
344,
12,
2455,
63,
466,
29,
1345,
63,
466,
12,
1067,
29,
1100,
12,
22483,
29,
13951,
12,
1007,
4470,
29,
797,
9,
267,
340,
1067,
436,
283,
604,
63,
1580,
7,
315,
1067,
26,
288,
1382,
275,
7559,
14,
4317,
8,
470,
459,
1047,
1105,
288,
3380,
275,
1382,
14,
8006,
21816,
698,
14251,
354,
534,
3189,
32266,
288,
367,
1031,
315,
3380,
26,
355,
1031,
14,
409,
360,
2261,
297,
6730,
480,
344,
401,
298,
262,
401,
6681,
620,
8,
1100,
459,
604,
63,
1580,
1105,
11,
5440,
358,
288,
522,
459,
1047,
418,
275,
7559,
14,
14028,
8,
1301,
9,
267,
372,
522,
339,
347,
1218,
63,
7948,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
1865,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
7948,
14,
1648,
358,
267,
1004,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
1185,
14,
604,
358,
267,
11628,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
7948,
14,
604,
358,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
666,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
2788,
16,
61,
267,
1004,
63,
1580,
275,
359,
2373,
14,
344,
367,
2397,
315,
666,
14,
3189,
61,
267,
340,
440,
1004,
63,
1580,
26,
288,
372,
791,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
63,
1600,
936,
398,
11628,
275,
1865,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
1067,
459,
2682,
63,
344,
995,
1067,
29,
1100,
9,
267,
307,
275,
488,
267,
1004,
18,
9860,
275,
1004,
63,
1113,
14,
604,
18,
9860,
8,
1556,
12,
1747,
12,
1004,
63,
1580,
12,
307,
12,
1067,
9,
398,
925,
19177,
13904,
314,
1453,
11628,
543,
892,
2385,
26,
267,
367,
1004,
315,
1004,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
1004,
63,
1580,
12,
1067,
29,
1100,
304,
288,
340,
11628,
14,
602,
63,
657,
22941,
508,
298,
2131,
582,
355,
327,
889,
11628,
1434,
9265,
8569,
11628,
355,
1434,
63,
475,
63,
5989,
275,
756,
288,
916,
11628,
14,
602,
63,
657,
22941,
508,
283,
11933,
356,
355,
1434,
63,
475,
63,
5989,
275,
1004,
14,
602,
63,
569,
5581,
288,
916,
11628,
14,
602,
63,
657,
22941,
508,
283,
5964,
356,
355,
1434,
63,
475,
63,
5989,
275,
11628,
14,
602,
63,
19274,
288,
11628,
63,
1113,
14,
981,
8,
1556,
12,
1747,
12,
91,
490,
283,
1185,
63,
604,
63,
344,
356,
1004,
14,
344,
12,
490,
283,
4606,
63,
4968,
356,
1004,
14,
4606,
63,
20161,
63,
4968,
12,
490,
283,
9860,
63,
344,
356,
1004,
18,
9860,
14,
362,
8,
604,
14,
344,
395,
490,
283,
1648,
63,
344,
356,
11628,
14,
344,
12,
490,
283,
3899,
63,
344,
356,
1004,
14,
3899,
63,
344,
436,
1004,
14,
3899,
63,
344,
14,
344,
503,
756,
12,
490,
283,
29351,
356,
1004,
14,
1121,
503,
17220,
490,
283,
929,
356,
1004,
14,
5404,
436,
1004,
14,
5404
] | [
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,
900,
199,
504,
14490,
492,
7559,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
504,
5166,
14,
2537,
14,
5275,
492,
485,
199,
199,
533,
11628,
63,
1648,
63,
981,
8,
4795,
14,
4795,
63,
4844,
304,
272,
408,
272,
2790,
282,
11628,
909,
543,
2385,
5226,
370,
314,
2933,
4057,
1004,
272,
370,
8633,
7182,
370,
314,
1434,
436,
314,
818,
2741,
701,
314,
922,
14,
272,
29591,
555,
14925,
26,
272,
446,
23704,
1329,
402,
2222,
13,
14808,
1672,
4057,
1004,
12,
11628,
818,
436,
16297,
2933,
730,
12,
272,
446,
13123,
1329,
402,
5854,
436,
16297,
2933,
14,
339,
982,
282,
730,
365,
1627,
12,
625,
83,
10020,
2933,
11855,
2385,
787,
5525,
14,
272,
408,
339,
485,
354,
275,
283,
7948,
14,
1648,
14,
981,
7,
272,
485,
1802,
275,
283,
7948,
14,
1648,
14,
981,
7,
272,
485,
3406,
275,
469,
267,
283,
11933,
602,
356,
1504,
14,
602,
360,
36,
310,
6148,
297,
1415,
29,
549,
395,
267,
283,
3189,
356,
1504,
14,
3479,
18,
3479,
360,
2048,
14,
1185,
14,
604,
297,
283,
604,
63,
5989,
63,
3369,
297,
283,
5989,
63,
344,
297,
283,
604,
63,
344,
297,
283,
17816,
358,
272,
789,
272,
485,
4322,
275,
469,
268,
283,
11933,
602,
356,
2400,
627,
65,
26,
900,
14,
6205,
3508,
57,
3295,
77,
3295,
68,
659,
272,
789,
339,
347,
1504,
63,
1345,
63,
362,
8,
277,
12,
2467,
12,
1747,
12,
2455,
63,
344,
29,
403,
12,
2455,
63,
466,
534,
964,
297,
1067,
29,
403,
12,
22483,
29,
797,
12,
1007,
4470,
29,
797,
304,
267,
340,
440,
1067,
26,
1067,
275,
1052,
267,
522,
275,
1613,
8,
7948,
63,
1648,
63,
981,
12,
291,
680,
955,
63,
1345,
63,
362,
8,
1556,
12,
1747,
12,
2455,
63,
344,
29,
1345,
63,
344,
12,
2455,
63,
466,
29,
1345,
63,
466,
12,
1067,
29,
1100,
12,
22483,
29,
13951,
12,
1007,
4470,
29,
797,
9,
267,
340,
1067,
436,
283,
604,
63,
1580,
7,
315,
1067,
26,
288,
1382,
275,
7559,
14,
4317,
8,
470,
459,
1047,
1105,
288,
3380,
275,
1382,
14,
8006,
21816,
698,
14251,
354,
534,
3189,
32266,
288,
367,
1031,
315,
3380,
26,
355,
1031,
14,
409,
360,
2261,
297,
6730,
480,
344,
401,
298,
262,
401,
6681,
620,
8,
1100,
459,
604,
63,
1580,
1105,
11,
5440,
358,
288,
522,
459,
1047,
418,
275,
7559,
14,
14028,
8,
1301,
9,
267,
372,
522,
339,
347,
1218,
63,
7948,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
1067,
29,
403,
304,
267,
1865,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
7948,
14,
1648,
358,
267,
1004,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
2048,
14,
1185,
14,
604,
358,
267,
11628,
63,
1113,
275,
291,
14,
2293,
14,
362,
360,
7948,
14,
604,
358,
267,
340,
1067,
365,
488,
26,
288,
1067,
275,
1052,
267,
666,
275,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
2788,
16,
61,
267,
1004,
63,
1580,
275,
359,
2373,
14,
344,
367,
2397,
315,
666,
14,
3189,
61,
267,
340,
440,
1004,
63,
1580,
26,
288,
372,
791,
466,
356,
283,
723,
14,
3723,
14,
2442,
63,
3806,
63,
1600,
936,
398,
11628,
275,
1865,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
1067,
459,
2682,
63,
344,
995,
1067,
29,
1100,
9,
267,
307,
275,
488,
267,
1004,
18,
9860,
275,
1004,
63,
1113,
14,
604,
18,
9860,
8,
1556,
12,
1747,
12,
1004,
63,
1580,
12,
307,
12,
1067,
9,
398,
925,
19177,
13904,
314,
1453,
11628,
543,
892,
2385,
26,
267,
367,
1004,
315,
1004,
63,
1113,
14,
4570,
8,
1556,
12,
1747,
12,
1004,
63,
1580,
12,
1067,
29,
1100,
304,
288,
340,
11628,
14,
602,
63,
657,
22941,
508,
298,
2131,
582,
355,
327,
889,
11628,
1434,
9265,
8569,
11628,
355,
1434,
63,
475,
63,
5989,
275,
756,
288,
916,
11628,
14,
602,
63,
657,
22941,
508,
283,
11933,
356,
355,
1434,
63,
475,
63,
5989,
275,
1004,
14,
602,
63,
569,
5581,
288,
916,
11628,
14,
602,
63,
657,
22941,
508,
283,
5964,
356,
355,
1434,
63,
475,
63,
5989,
275,
11628,
14,
602,
63,
19274,
288,
11628,
63,
1113,
14,
981,
8,
1556,
12,
1747,
12,
91,
490,
283,
1185,
63,
604,
63,
344,
356,
1004,
14,
344,
12,
490,
283,
4606,
63,
4968,
356,
1004,
14,
4606,
63,
20161,
63,
4968,
12,
490,
283,
9860,
63,
344,
356,
1004,
18,
9860,
14,
362,
8,
604,
14,
344,
395,
490,
283,
1648,
63,
344,
356,
11628,
14,
344,
12,
490,
283,
3899,
63,
344,
356,
1004,
14,
3899,
63,
344,
436,
1004,
14,
3899,
63,
344,
14,
344,
503,
756,
12,
490,
283,
29351,
356,
1004,
14,
1121,
503,
17220,
490,
283,
929,
356,
1004,
14,
5404,
436,
1004,
14,
5404,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
SANBI-SA/tools-iuc | data_managers/data_manager_humann2_database_downloader/data_manager/data_manager_humann2_download.py | 9 | 5204 | #!/usr/bin/env python
#
# Data manager for reference data for the 'humann2' Galaxy tools
import datetime
import json
import optparse
import os
import shutil
import subprocess
import sys
HUMANN2_REFERENCE_DATA = {
"full": "Full",
"DEMO": "Demo",
"uniref50_diamond": "Full UniRef50",
"uniref50_ec_filtered_diamond": "EC-filtered UniRef50",
"uniref50_GO_filtered_rapsearch2": "GO filtered UniRef50 for rapsearch2",
"uniref90_diamond": "Full UniRef90",
"uniref90_ec_filtered_diamond": "EC-filtered UniRef90",
"DEMO_diamond": "Demo"
}
# Utility functions for interacting with Galaxy JSON
def read_input_json(jsonfile):
"""Read the JSON supplied from the data manager tool
Returns a tuple (param_dict,extra_files_path)
'param_dict' is an arbitrary dictionary of parameters
input into the tool; 'extra_files_path' is the path
to a directory where output files must be put for the
receiving data manager to pick them up.
NB the directory pointed to by 'extra_files_path'
doesn't exist initially, it is the job of the script
to create it if necessary.
"""
params = json.loads(open(jsonfile).read())
return (params['param_dict'],
params['output_data'][0]['extra_files_path'])
# Utility functions for creating data table dictionaries
#
# Example usage:
# >>> d = create_data_tables_dict()
# >>> add_data_table(d,'my_data')
# >>> add_data_table_entry(dict(dbkey='hg19',value='human'))
# >>> add_data_table_entry(dict(dbkey='mm9',value='mouse'))
# >>> print str(json.dumps(d))
def create_data_tables_dict():
"""Return a dictionary for storing data table information
Returns a dictionary that can be used with 'add_data_table'
and 'add_data_table_entry' to store information about a
data table. It can be converted to JSON to be sent back to
the data manager.
"""
d = {}
d['data_tables'] = {}
return d
def add_data_table(d, table):
"""Add a data table to the data tables dictionary
Creates a placeholder for a data table called 'table'.
"""
d['data_tables'][table] = []
def add_data_table_entry(d, table, entry):
"""Add an entry to a data table
Appends an entry to the data table 'table'. 'entry'
should be a dictionary where the keys are the names of
columns in the data table.
Raises an exception if the named data table doesn't
exist.
"""
try:
d['data_tables'][table].append(entry)
except KeyError:
raise Exception("add_data_table_entry: no table '%s'" % table)
def download_humann2_db(data_tables, table_name, database, build, target_dir):
"""Download HUMAnN2 database
Creates references to the specified file(s) on the Galaxy
server in the appropriate data table (determined from the
file extension).
The 'data_tables' dictionary should have been created using
the 'create_data_tables_dict' and 'add_data_table' functions.
Arguments:
data_tables: a dictionary containing the data table info
table_name: name of the table
database: database to download (chocophlan or uniref)
build: build of the database to download
target_dir: directory to put copy or link to the data file
"""
value = "%s-%s-%s" % (database, build, datetime.date.today().isoformat())
db_target_dir = os.path.join(target_dir, database)
build_target_dir = os.path.join(db_target_dir, build)
cmd = "humann2_databases --download %s %s %s --update-config no" % (
database,
build,
db_target_dir)
subprocess.check_call(cmd, shell=True)
shutil.move(os.path.join(db_target_dir, database), build_target_dir)
add_data_table_entry(
data_tables,
table_name,
dict(
dbkey=build,
value=value,
name=HUMANN2_REFERENCE_DATA[build],
path=build_target_dir))
if __name__ == "__main__":
print("Starting...")
# Read command line
parser = optparse.OptionParser(description='Download HUMAnN2 database')
parser.add_option('--database', help="Database name")
parser.add_option('--build', help="Build of the database")
options, args = parser.parse_args()
print("args : %s" % args)
# Check for JSON file
if len(args) != 1:
sys.stderr.write("Need to supply JSON file name")
sys.exit(1)
jsonfile = args[0]
# Read the input JSON
params, target_dir = read_input_json(jsonfile)
# Make the target directory
print("Making %s" % target_dir)
os.mkdir(target_dir)
# Set up data tables dictionary
data_tables = create_data_tables_dict()
if options.database == "chocophlan":
table_name = 'humann2_nucleotide_database'
else:
table_name = 'humann2_protein_database'
add_data_table(data_tables, table_name)
# Fetch data from specified data sources
download_humann2_db(
data_tables,
table_name,
options.database,
options.build,
target_dir)
# Write output JSON
print("Outputting JSON")
print(str(json.dumps(data_tables)))
open(jsonfile, 'wb').write(json.dumps(data_tables))
print("Done.")
| mit | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
3918,
5256,
367,
3659,
666,
367,
314,
283,
72,
453,
1189,
18,
7,
598,
15914,
7249,
199,
646,
2197,
199,
646,
2022,
199,
646,
8691,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
421,
199,
40,
2639,
879,
46,
18,
63,
31177,
63,
3998,
275,
469,
272,
298,
2861,
582,
298,
9042,
401,
272,
298,
1093,
2679,
582,
298,
21493,
401,
272,
298,
5411,
1121,
1400,
63,
328,
24940,
582,
298,
9042,
1910,
73,
2891,
1400,
401,
272,
298,
5411,
1121,
1400,
63,
825,
63,
11142,
63,
328,
24940,
582,
298,
4220,
13,
11142,
1910,
73,
2891,
1400,
401,
272,
298,
5411,
1121,
1400,
63,
13160,
63,
11142,
63,
1330,
1733,
18,
582,
298,
13160,
9806,
1910,
73,
2891,
1400,
367,
660,
80,
1733,
18,
401,
272,
298,
5411,
1121,
2710,
63,
328,
24940,
582,
298,
9042,
1910,
73,
2891,
2710,
401,
272,
298,
5411,
1121,
2710,
63,
825,
63,
11142,
63,
328,
24940,
582,
298,
4220,
13,
11142,
1910,
73,
2891,
2710,
401,
272,
298,
1093,
2679,
63,
328,
24940,
582,
298,
21493,
2,
199,
93,
421,
199,
3,
20511,
3423,
367,
17232,
316,
543,
598,
15914,
4840,
199,
318,
1586,
63,
1210,
63,
1001,
8,
1001,
493,
304,
272,
408,
3284,
314,
4840,
6841,
687,
314,
666,
5256,
4744,
339,
1803,
282,
2008,
334,
635,
63,
807,
12,
2911,
63,
1725,
63,
515,
9,
339,
283,
635,
63,
807,
7,
365,
376,
9697,
2600,
402,
2633,
272,
1324,
1901,
314,
4744,
27,
283,
2911,
63,
1725,
63,
515,
7,
365,
314,
931,
272,
370,
282,
2082,
2382,
1072,
1584,
1471,
506,
5324,
367,
314,
272,
18390,
666,
5256,
370,
3732,
3062,
1536,
14,
339,
25377,
314,
2082,
32031,
370,
701,
283,
2911,
63,
1725,
63,
515,
7,
272,
3181,
1133,
2187,
22801,
12,
652,
365,
314,
3906,
402,
314,
2884,
272,
370,
1218,
652,
340,
5784,
14,
339,
408,
272,
1862,
275,
2022,
14,
3640,
8,
1490,
8,
1001,
493,
680,
739,
1012,
272,
372,
334,
1162,
459,
635,
63,
807,
995,
288,
1862,
459,
1199,
63,
576,
3488,
16,
2733,
2911,
63,
1725,
63,
515,
1105,
421,
199,
3,
20511,
3423,
367,
6425,
666,
1817,
11196,
199,
3,
199,
3,
5679,
4503,
26,
199,
3,
1306,
366,
275,
1218,
63,
576,
63,
5987,
63,
807,
342,
199,
3,
1306,
1050,
63,
576,
63,
1224,
8,
68,
2584,
1662,
63,
576,
358,
199,
3,
1306,
1050,
63,
576,
63,
1224,
63,
2373,
8,
807,
8,
697,
498,
534,
9208,
1167,
297,
585,
534,
14864,
1333,
199,
3,
1306,
1050,
63,
576,
63,
1224,
63,
2373,
8,
807,
8,
697,
498,
534,
596,
25,
297,
585,
534,
10544,
1333,
199,
3,
1306,
870,
620,
8,
1001,
14,
4180,
8,
68,
430,
199,
318,
1218,
63,
576,
63,
5987,
63,
807,
837,
272,
408,
1767,
282,
2600,
367,
16915,
666,
1817,
2556,
339,
1803,
282,
2600,
626,
883,
506,
1202,
543,
283,
525,
63,
576,
63,
1224,
7,
272,
436,
283,
525,
63,
576,
63,
1224,
63,
2373,
7,
370,
3877,
2556,
3595,
282,
272,
666,
1817,
14,
2779,
883,
506,
6702,
370,
4840,
370,
506,
4847,
1771,
370,
272,
314,
666,
5256,
14,
339,
408,
272,
366,
275,
1052,
272,
366,
459,
576,
63,
5987,
418,
275,
1052,
272,
372,
366,
421,
199,
318,
1050,
63,
576,
63,
1224,
8,
68,
12,
1817,
304,
272,
408,
1123,
282,
666,
1817,
370,
314,
666,
6716,
2600,
339,
10560,
282,
10069,
367,
282,
666,
1817,
2797,
283,
1224,
1370,
339,
408,
272,
366,
459,
576,
63,
5987,
3488,
1224,
61,
275,
942,
421,
199,
318,
1050,
63,
576,
63,
1224,
63,
2373,
8,
68,
12,
1817,
12,
2397,
304,
272,
408,
1123,
376,
2397,
370,
282,
666,
1817,
339,
4693,
3198,
376,
2397,
370,
314,
666,
1817,
283,
1224,
1370,
283,
2373,
7,
272,
1077,
506,
282,
2600,
2382,
314,
2883,
787,
314,
1561,
402,
272,
4362,
315,
314,
666,
1817,
14,
339,
6218,
376,
1919,
340,
314,
4310,
666,
1817,
3181,
1133,
272,
2187,
14,
339,
408,
272,
862,
26,
267,
366,
459,
576,
63,
5987,
3488,
1224,
1055,
740,
8,
2373,
9,
272,
871,
4067,
26,
267,
746,
2186,
480,
525,
63,
576,
63,
1224,
63,
2373,
26,
949,
1817,
1543,
83,
4065,
450,
1817,
9,
421,
199,
318,
5235,
63,
72,
453,
1189,
18,
63,
697,
8,
576,
63,
5987,
12,
1817,
63,
354,
12,
3050,
12,
1900,
12,
1347,
63,
694,
304,
272,
408,
11950,
869,
53,
2054,
78,
46,
18,
3050,
339,
10560,
6941,
370,
314,
2013,
570,
8,
83,
9,
641,
314,
598,
15914,
272,
1654,
315,
314,
5827,
666,
1817,
334,
27248,
687,
314,
272,
570,
3329,
680,
339,
710,
283,
576,
63,
5987,
7,
2600,
1077,
1172,
2757,
2737,
1808,
272,
314,
283,
981,
63,
576,
63,
5987,
63,
807,
7,
436,
283,
525,
63,
576,
63,
1224,
7,
3423,
14,
339,
7628,
26,
489,
666,
63,
5987,
26,
282,
2600,
3035,
314,
666,
1817,
2256,
489,
1817,
63,
354,
26,
536,
402,
314,
1817,
489,
3050,
26,
3050,
370,
5235,
334,
2239,
331,
838,
1502,
503,
15439,
1121,
9,
489,
1900,
26,
1900,
402,
314,
3050,
370,
5235,
489,
1347,
63,
694,
26,
2082,
370,
5324,
1331,
503,
2142,
370,
314,
666,
570,
339,
408,
272,
574,
275,
2071,
83,
3295,
83,
3295,
83,
2,
450,
334,
4659,
12,
1900,
12,
2197,
14,
602,
14,
8136,
1252,
17070,
1012,
272,
1592,
63,
1375,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1375,
63,
694,
12,
3050,
9,
272,
1900,
63,
1375,
63,
694,
275,
747,
14,
515,
14,
904,
8,
697,
63,
1375,
63,
694,
12,
1900,
9,
272,
2088,
275,
298,
72,
453,
1189,
18,
63,
17439,
1553,
4249,
450,
83,
450,
83,
450,
83,
1553,
873,
13,
888,
949,
2,
450,
334,
267,
3050,
12,
267,
1900,
12,
267,
1592,
63,
1375,
63,
694,
9,
272,
3873,
14,
1074,
63,
1250,
8,
1760,
12,
5218,
29,
549,
9,
272,
5145,
14,
1185,
8,
736,
14,
515,
14,
904,
8,
697,
63,
1375,
63,
694,
12,
3050,
395,
1900
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
3918,
5256,
367,
3659,
666,
367,
314,
283,
72,
453,
1189,
18,
7,
598,
15914,
7249,
199,
646,
2197,
199,
646,
2022,
199,
646,
8691,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
421,
199,
40,
2639,
879,
46,
18,
63,
31177,
63,
3998,
275,
469,
272,
298,
2861,
582,
298,
9042,
401,
272,
298,
1093,
2679,
582,
298,
21493,
401,
272,
298,
5411,
1121,
1400,
63,
328,
24940,
582,
298,
9042,
1910,
73,
2891,
1400,
401,
272,
298,
5411,
1121,
1400,
63,
825,
63,
11142,
63,
328,
24940,
582,
298,
4220,
13,
11142,
1910,
73,
2891,
1400,
401,
272,
298,
5411,
1121,
1400,
63,
13160,
63,
11142,
63,
1330,
1733,
18,
582,
298,
13160,
9806,
1910,
73,
2891,
1400,
367,
660,
80,
1733,
18,
401,
272,
298,
5411,
1121,
2710,
63,
328,
24940,
582,
298,
9042,
1910,
73,
2891,
2710,
401,
272,
298,
5411,
1121,
2710,
63,
825,
63,
11142,
63,
328,
24940,
582,
298,
4220,
13,
11142,
1910,
73,
2891,
2710,
401,
272,
298,
1093,
2679,
63,
328,
24940,
582,
298,
21493,
2,
199,
93,
421,
199,
3,
20511,
3423,
367,
17232,
316,
543,
598,
15914,
4840,
199,
318,
1586,
63,
1210,
63,
1001,
8,
1001,
493,
304,
272,
408,
3284,
314,
4840,
6841,
687,
314,
666,
5256,
4744,
339,
1803,
282,
2008,
334,
635,
63,
807,
12,
2911,
63,
1725,
63,
515,
9,
339,
283,
635,
63,
807,
7,
365,
376,
9697,
2600,
402,
2633,
272,
1324,
1901,
314,
4744,
27,
283,
2911,
63,
1725,
63,
515,
7,
365,
314,
931,
272,
370,
282,
2082,
2382,
1072,
1584,
1471,
506,
5324,
367,
314,
272,
18390,
666,
5256,
370,
3732,
3062,
1536,
14,
339,
25377,
314,
2082,
32031,
370,
701,
283,
2911,
63,
1725,
63,
515,
7,
272,
3181,
1133,
2187,
22801,
12,
652,
365,
314,
3906,
402,
314,
2884,
272,
370,
1218,
652,
340,
5784,
14,
339,
408,
272,
1862,
275,
2022,
14,
3640,
8,
1490,
8,
1001,
493,
680,
739,
1012,
272,
372,
334,
1162,
459,
635,
63,
807,
995,
288,
1862,
459,
1199,
63,
576,
3488,
16,
2733,
2911,
63,
1725,
63,
515,
1105,
421,
199,
3,
20511,
3423,
367,
6425,
666,
1817,
11196,
199,
3,
199,
3,
5679,
4503,
26,
199,
3,
1306,
366,
275,
1218,
63,
576,
63,
5987,
63,
807,
342,
199,
3,
1306,
1050,
63,
576,
63,
1224,
8,
68,
2584,
1662,
63,
576,
358,
199,
3,
1306,
1050,
63,
576,
63,
1224,
63,
2373,
8,
807,
8,
697,
498,
534,
9208,
1167,
297,
585,
534,
14864,
1333,
199,
3,
1306,
1050,
63,
576,
63,
1224,
63,
2373,
8,
807,
8,
697,
498,
534,
596,
25,
297,
585,
534,
10544,
1333,
199,
3,
1306,
870,
620,
8,
1001,
14,
4180,
8,
68,
430,
199,
318,
1218,
63,
576,
63,
5987,
63,
807,
837,
272,
408,
1767,
282,
2600,
367,
16915,
666,
1817,
2556,
339,
1803,
282,
2600,
626,
883,
506,
1202,
543,
283,
525,
63,
576,
63,
1224,
7,
272,
436,
283,
525,
63,
576,
63,
1224,
63,
2373,
7,
370,
3877,
2556,
3595,
282,
272,
666,
1817,
14,
2779,
883,
506,
6702,
370,
4840,
370,
506,
4847,
1771,
370,
272,
314,
666,
5256,
14,
339,
408,
272,
366,
275,
1052,
272,
366,
459,
576,
63,
5987,
418,
275,
1052,
272,
372,
366,
421,
199,
318,
1050,
63,
576,
63,
1224,
8,
68,
12,
1817,
304,
272,
408,
1123,
282,
666,
1817,
370,
314,
666,
6716,
2600,
339,
10560,
282,
10069,
367,
282,
666,
1817,
2797,
283,
1224,
1370,
339,
408,
272,
366,
459,
576,
63,
5987,
3488,
1224,
61,
275,
942,
421,
199,
318,
1050,
63,
576,
63,
1224,
63,
2373,
8,
68,
12,
1817,
12,
2397,
304,
272,
408,
1123,
376,
2397,
370,
282,
666,
1817,
339,
4693,
3198,
376,
2397,
370,
314,
666,
1817,
283,
1224,
1370,
283,
2373,
7,
272,
1077,
506,
282,
2600,
2382,
314,
2883,
787,
314,
1561,
402,
272,
4362,
315,
314,
666,
1817,
14,
339,
6218,
376,
1919,
340,
314,
4310,
666,
1817,
3181,
1133,
272,
2187,
14,
339,
408,
272,
862,
26,
267,
366,
459,
576,
63,
5987,
3488,
1224,
1055,
740,
8,
2373,
9,
272,
871,
4067,
26,
267,
746,
2186,
480,
525,
63,
576,
63,
1224,
63,
2373,
26,
949,
1817,
1543,
83,
4065,
450,
1817,
9,
421,
199,
318,
5235,
63,
72,
453,
1189,
18,
63,
697,
8,
576,
63,
5987,
12,
1817,
63,
354,
12,
3050,
12,
1900,
12,
1347,
63,
694,
304,
272,
408,
11950,
869,
53,
2054,
78,
46,
18,
3050,
339,
10560,
6941,
370,
314,
2013,
570,
8,
83,
9,
641,
314,
598,
15914,
272,
1654,
315,
314,
5827,
666,
1817,
334,
27248,
687,
314,
272,
570,
3329,
680,
339,
710,
283,
576,
63,
5987,
7,
2600,
1077,
1172,
2757,
2737,
1808,
272,
314,
283,
981,
63,
576,
63,
5987,
63,
807,
7,
436,
283,
525,
63,
576,
63,
1224,
7,
3423,
14,
339,
7628,
26,
489,
666,
63,
5987,
26,
282,
2600,
3035,
314,
666,
1817,
2256,
489,
1817,
63,
354,
26,
536,
402,
314,
1817,
489,
3050,
26,
3050,
370,
5235,
334,
2239,
331,
838,
1502,
503,
15439,
1121,
9,
489,
1900,
26,
1900,
402,
314,
3050,
370,
5235,
489,
1347,
63,
694,
26,
2082,
370,
5324,
1331,
503,
2142,
370,
314,
666,
570,
339,
408,
272,
574,
275,
2071,
83,
3295,
83,
3295,
83,
2,
450,
334,
4659,
12,
1900,
12,
2197,
14,
602,
14,
8136,
1252,
17070,
1012,
272,
1592,
63,
1375,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1375,
63,
694,
12,
3050,
9,
272,
1900,
63,
1375,
63,
694,
275,
747,
14,
515,
14,
904,
8,
697,
63,
1375,
63,
694,
12,
1900,
9,
272,
2088,
275,
298,
72,
453,
1189,
18,
63,
17439,
1553,
4249,
450,
83,
450,
83,
450,
83,
1553,
873,
13,
888,
949,
2,
450,
334,
267,
3050,
12,
267,
1900,
12,
267,
1592,
63,
1375,
63,
694,
9,
272,
3873,
14,
1074,
63,
1250,
8,
1760,
12,
5218,
29,
549,
9,
272,
5145,
14,
1185,
8,
736,
14,
515,
14,
904,
8,
697,
63,
1375,
63,
694,
12,
3050,
395,
1900,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tonioo/modoboa | modoboa/lib/u2u_decode.py | 1 | 2282 | # -*- coding: utf-8 -*-
"""
Unstructured rfc2047 header to unicode.
A stupid (and not accurate) answer to https://bugs.python.org/issue1079.
"""
from __future__ import unicode_literals
import re
from email.header import decode_header, make_header
from email.utils import parseaddr
from django.utils.encoding import smart_text
# check spaces between encoded_words (and strip them)
sre = re.compile(r"\?=[ \t]+=\?")
# re pat for MIME encoded_word (without trailing spaces)
mre = re.compile(r"=\?[^?]*?\?[bq]\?[^?\t]*?\?=", re.I)
# re do detect encoded ASCII characters
ascii_re = re.compile(r"=[\dA-F]{2,3}", re.I)
def clean_spaces(m):
"""Replace unencoded spaces in string.
:param str m: a match object
:return: the cleaned string
"""
return m.group(0).replace(" ", "=20")
def clean_non_printable_char(m):
"""Strip non printable characters."""
code = int(m.group(0)[1:], 16)
if code < 20:
return ""
return m.group(0)
def decode_mime(m):
"""Substitute matching encoded_word with unicode equiv."""
h = decode_header(clean_spaces(m))
try:
u = smart_text(make_header(h))
except (LookupError, UnicodeDecodeError):
return m.group(0)
return u
def clean_header(header):
"""Clean header function."""
header = "".join(header.splitlines())
header = sre.sub("?==?", header)
return ascii_re.sub(clean_non_printable_char, header)
def u2u_decode(s):
"""utility function for (final) decoding of mime header
note: resulting string is in one line (no \n within)
note2: spaces between enc_words are stripped (see RFC2047)
"""
return mre.sub(decode_mime, clean_header(s)).strip(" \r\t\n")
def decode_address(value):
"""Special function for address decoding.
We need a dedicated processing because RFC1342 explicitely says
address MUST NOT contain encoded-word:
These are the ONLY locations where an encoded-word may appear. In
particular, an encoded-word MUST NOT appear in any portion of an
"address". In addition, an encoded-word MUST NOT be used in a
Received header field.
"""
phrase, address = parseaddr(clean_header(value))
if phrase:
phrase = mre.sub(decode_mime, phrase)
return phrase, address
| isc | [
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
1358,
15774,
18158,
6686,
23,
1406,
370,
2649,
14,
199,
199,
33,
410,
31596,
334,
460,
440,
23189,
9,
6385,
370,
4178,
921,
13017,
14,
1548,
14,
1308,
15,
5237,
709,
1965,
14,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
504,
3031,
14,
1291,
492,
4849,
63,
1291,
12,
1852,
63,
1291,
199,
504,
3031,
14,
1208,
492,
2198,
2697,
199,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
505,
199,
199,
3,
1104,
7883,
3382,
5737,
63,
3148,
334,
460,
6202,
3062,
9,
199,
31026,
275,
295,
14,
2014,
8,
82,
3212,
31,
1524,
971,
84,
2807,
9529,
18582,
199,
3,
295,
12713,
367,
14735,
5737,
63,
1027,
334,
7395,
8520,
7883,
9,
199,
77,
264,
275,
295,
14,
2014,
8,
82,
2,
9529,
31,
4735,
31,
3672,
8995,
26736,
23907,
7272,
31,
4735,
8995,
84,
3672,
8995,
31,
11107,
295,
14,
41,
9,
199,
3,
295,
886,
9696,
5737,
10485,
4110,
199,
4371,
63,
264,
275,
295,
14,
2014,
8,
82,
2,
32296,
68,
33,
13,
38,
8194,
18,
12,
19,
10750,
295,
14,
41,
9,
421,
199,
318,
3633,
63,
10749,
8,
77,
304,
272,
408,
11328,
625,
8167,
7883,
315,
1059,
14,
339,
520,
635,
620,
333,
26,
282,
1336,
909,
272,
520,
1107,
26,
314,
12364,
1059,
272,
408,
272,
372,
333,
14,
923,
8,
16,
680,
1814,
480,
3872,
298,
29,
1165,
531,
421,
199,
318,
3633,
63,
2865,
63,
20557,
63,
1560,
8,
77,
304,
272,
408,
21332,
2222,
21834,
4110,
1041,
272,
1233,
275,
1109,
8,
77,
14,
923,
8,
16,
2788,
17,
8429,
3193,
9,
272,
340,
1233,
665,
3388,
26,
267,
372,
3087,
272,
372,
333,
14,
923,
8,
16,
9,
421,
199,
318,
4849,
63,
7626,
8,
77,
304,
272,
408,
2610,
25585,
4877,
5737,
63,
1027,
543,
2649,
325,
5608,
1041,
272,
394,
275,
4849,
63,
1291,
8,
3118,
63,
10749,
8,
77,
430,
272,
862,
26,
267,
399,
275,
11179,
63,
505,
8,
1875,
63,
1291,
8,
72,
430,
272,
871,
334,
32060,
12,
18965,
304,
267,
372,
333,
14,
923,
8,
16,
9,
272,
372,
399,
421,
199,
318,
3633,
63,
1291,
8,
1291,
304,
272,
408,
6580,
1406,
805,
1041,
272,
1406,
275,
10587,
904,
8,
1291,
14,
7644,
1012,
272,
1406,
275,
25877,
14,
954,
480,
31,
389,
15583,
1406,
9,
272,
372,
13294,
63,
264,
14,
954,
8,
3118,
63,
2865,
63,
20557,
63,
1560,
12,
1406,
9,
421,
199,
318,
399,
18,
85,
63,
2708,
8,
83,
304,
272,
408,
16877,
805,
367,
334,
5094,
9,
15952,
402,
6660,
1406,
339,
5317,
26,
9183,
1059,
365,
315,
1373,
1004,
334,
889,
971,
78,
4453,
9,
272,
5317,
18,
26,
7883,
3382,
12011,
63,
3148,
787,
14489,
334,
3239,
7329,
6686,
23,
9,
272,
408,
272,
372,
333,
264,
14,
954,
8,
2708,
63,
7626,
12,
3633,
63,
1291,
8,
83,
4992,
1913,
480,
971,
82,
60,
84,
60,
78,
531,
421,
199,
318,
4849,
63,
1562,
8,
585,
304,
272,
408,
12246,
805,
367,
2287,
15952,
14,
339,
2136,
1929,
282,
29711,
6661,
2952,
7329,
969,
2260,
1437,
317,
25171,
590,
20065,
272,
2287,
18095,
2845,
1395,
5737,
13,
1027,
26,
2541,
5723,
787,
314,
5258,
6084,
9918,
2382,
376,
5737,
13,
1027,
1443,
7468,
14,
221,
1010,
489,
6770,
12,
376,
5737,
13,
1027,
18095,
2845,
7468,
315,
1263,
18046,
402,
376,
489,
298,
1562,
1674,
221,
1010,
10234,
12,
376,
5737,
13,
1027,
18095,
2845,
506,
1202,
315,
282,
489,
799,
2525,
1406,
901,
14,
272,
408,
272,
21621,
12,
2287,
275,
2198,
2697,
8,
3118,
63,
1291,
8,
585,
430,
272,
340,
21621,
26,
267,
21621,
275,
333,
264,
14,
954,
8,
2708,
63,
7626,
12,
21621,
9,
272,
372,
21621,
12,
2287,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1358,
15774,
18158,
6686,
23,
1406,
370,
2649,
14,
199,
199,
33,
410,
31596,
334,
460,
440,
23189,
9,
6385,
370,
4178,
921,
13017,
14,
1548,
14,
1308,
15,
5237,
709,
1965,
14,
199,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
504,
3031,
14,
1291,
492,
4849,
63,
1291,
12,
1852,
63,
1291,
199,
504,
3031,
14,
1208,
492,
2198,
2697,
199,
199,
504,
1639,
14,
1208,
14,
2991,
492,
11179,
63,
505,
199,
199,
3,
1104,
7883,
3382,
5737,
63,
3148,
334,
460,
6202,
3062,
9,
199,
31026,
275,
295,
14,
2014,
8,
82,
3212,
31,
1524,
971,
84,
2807,
9529,
18582,
199,
3,
295,
12713,
367,
14735,
5737,
63,
1027,
334,
7395,
8520,
7883,
9,
199,
77,
264,
275,
295,
14,
2014,
8,
82,
2,
9529,
31,
4735,
31,
3672,
8995,
26736,
23907,
7272,
31,
4735,
8995,
84,
3672,
8995,
31,
11107,
295,
14,
41,
9,
199,
3,
295,
886,
9696,
5737,
10485,
4110,
199,
4371,
63,
264,
275,
295,
14,
2014,
8,
82,
2,
32296,
68,
33,
13,
38,
8194,
18,
12,
19,
10750,
295,
14,
41,
9,
421,
199,
318,
3633,
63,
10749,
8,
77,
304,
272,
408,
11328,
625,
8167,
7883,
315,
1059,
14,
339,
520,
635,
620,
333,
26,
282,
1336,
909,
272,
520,
1107,
26,
314,
12364,
1059,
272,
408,
272,
372,
333,
14,
923,
8,
16,
680,
1814,
480,
3872,
298,
29,
1165,
531,
421,
199,
318,
3633,
63,
2865,
63,
20557,
63,
1560,
8,
77,
304,
272,
408,
21332,
2222,
21834,
4110,
1041,
272,
1233,
275,
1109,
8,
77,
14,
923,
8,
16,
2788,
17,
8429,
3193,
9,
272,
340,
1233,
665,
3388,
26,
267,
372,
3087,
272,
372,
333,
14,
923,
8,
16,
9,
421,
199,
318,
4849,
63,
7626,
8,
77,
304,
272,
408,
2610,
25585,
4877,
5737,
63,
1027,
543,
2649,
325,
5608,
1041,
272,
394,
275,
4849,
63,
1291,
8,
3118,
63,
10749,
8,
77,
430,
272,
862,
26,
267,
399,
275,
11179,
63,
505,
8,
1875,
63,
1291,
8,
72,
430,
272,
871,
334,
32060,
12,
18965,
304,
267,
372,
333,
14,
923,
8,
16,
9,
272,
372,
399,
421,
199,
318,
3633,
63,
1291,
8,
1291,
304,
272,
408,
6580,
1406,
805,
1041,
272,
1406,
275,
10587,
904,
8,
1291,
14,
7644,
1012,
272,
1406,
275,
25877,
14,
954,
480,
31,
389,
15583,
1406,
9,
272,
372,
13294,
63,
264,
14,
954,
8,
3118,
63,
2865,
63,
20557,
63,
1560,
12,
1406,
9,
421,
199,
318,
399,
18,
85,
63,
2708,
8,
83,
304,
272,
408,
16877,
805,
367,
334,
5094,
9,
15952,
402,
6660,
1406,
339,
5317,
26,
9183,
1059,
365,
315,
1373,
1004,
334,
889,
971,
78,
4453,
9,
272,
5317,
18,
26,
7883,
3382,
12011,
63,
3148,
787,
14489,
334,
3239,
7329,
6686,
23,
9,
272,
408,
272,
372,
333,
264,
14,
954,
8,
2708,
63,
7626,
12,
3633,
63,
1291,
8,
83,
4992,
1913,
480,
971,
82,
60,
84,
60,
78,
531,
421,
199,
318,
4849,
63,
1562,
8,
585,
304,
272,
408,
12246,
805,
367,
2287,
15952,
14,
339,
2136,
1929,
282,
29711,
6661,
2952,
7329,
969,
2260,
1437,
317,
25171,
590,
20065,
272,
2287,
18095,
2845,
1395,
5737,
13,
1027,
26,
2541,
5723,
787,
314,
5258,
6084,
9918,
2382,
376,
5737,
13,
1027,
1443,
7468,
14,
221,
1010,
489,
6770,
12,
376,
5737,
13,
1027,
18095,
2845,
7468,
315,
1263,
18046,
402,
376,
489,
298,
1562,
1674,
221,
1010,
10234,
12,
376,
5737,
13,
1027,
18095,
2845,
506,
1202,
315,
282,
489,
799,
2525,
1406,
901,
14,
272,
408,
272,
21621,
12,
2287,
275,
2198,
2697,
8,
3118,
63,
1291,
8,
585,
430,
272,
340,
21621,
26,
267,
21621,
275,
333,
264,
14,
954,
8,
2708,
63,
7626,
12,
21621,
9,
272,
372,
21621,
12,
2287,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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per', 'SafeDumper', 'Dumper']
from emitter import *
from serializer import *
from representer import *
from resolver import *
class BaseDumper(Emitter, Serializer, BaseRepresenter, BaseResolver):
def __init__(self, stream,
default_style=None, default_flow_style=None,
canonical=None, indent=None, width=None,
allow_unicode=None, line_break=None,
encoding=None, explicit_start=None, explicit_end=None,
version=None, tags=None):
Emitter.__init__(self, stream, canonical=canonical,
indent=indent, width=width,
allow_unicode=allow_unicode, line_break=line_break)
Serializer.__init__(self, encoding=encoding,
explicit_start=explicit_start, explicit_end=explicit_end,
version=version, tags=tags)
Representer.__init__(self, default_style=default_style,
default_flow_style=default_flow_style)
Resolver.__init__(self)
class SafeDumper(Emitter, Serializer, SafeRepresenter, Resolver):
def __init__(self, stream,
default_style=None, default_flow_style=None,
canonical=None, indent=None, width=None,
allow_unicode=None, line_break=None,
encoding=None, explicit_start=None, explicit_end=None,
version=None, tags=None):
Emitter.__init__(self, stream, canonical=canonical,
indent=indent, width=width,
allow_unicode=allow_unicode, line_break=line_break)
Serializer.__init__(self, encoding=encoding,
explicit_start=explicit_start, explicit_end=explicit_end,
version=version, tags=tags)
SafeRepresenter.__init__(self, default_style=default_style,
default_flow_style=default_flow_style)
Resolver.__init__(self)
class Dumper(Emitter, Serializer, Representer, Resolver):
def __init__(self, stream,
default_style=None, default_flow_style=None,
canonical=None, indent=None, width=None,
allow_unicode=None, line_break=None,
encoding=None, explicit_start=None, explicit_end=None,
version=None, tags=None):
Emitter.__init__(self, stream, canonical=canonical,
indent=indent, width=width,
allow_unicode=allow_unicode, line_break=line_break)
Serializer.__init__(self, encoding=encoding,
explicit_start=explicit_start, explicit_end=explicit_end,
version=version, tags=tags)
Representer.__init__(self, default_style=default_style,
default_flow_style=default_flow_style)
Resolver.__init__(self)
| mit | [
199,
363,
452,
363,
275,
788,
1563,
28593,
297,
283,
11090,
28593,
297,
283,
28593,
418,
199,
199,
504,
8689,
351,
492,
627,
199,
504,
9146,
492,
627,
199,
504,
295,
22682,
492,
627,
199,
504,
15611,
492,
627,
199,
199,
533,
3523,
28593,
8,
37,
22541,
12,
25555,
12,
3523,
497,
22682,
12,
3523,
12407,
304,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
288,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
288,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
288,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
288,
2644,
29,
403,
12,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
288,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
662,
22541,
855,
826,
721,
277,
12,
2547,
12,
11358,
29,
13109,
12,
355,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
355,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
267,
25555,
855,
826,
721,
277,
12,
2644,
29,
2991,
12,
355,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
12,
355,
1015,
29,
1023,
12,
3762,
29,
2969,
9,
267,
799,
22682,
855,
826,
721,
277,
12,
849,
63,
2487,
29,
885,
63,
2487,
12,
355,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
9,
267,
26046,
855,
826,
721,
277,
9,
199,
199,
533,
14969,
28593,
8,
37,
22541,
12,
25555,
12,
14969,
497,
22682,
12,
26046,
304,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
288,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
288,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
288,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
288,
2644,
29,
403,
12,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
288,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
662,
22541,
855,
826,
721,
277,
12,
2547,
12,
11358,
29,
13109,
12,
355,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
355,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
267,
25555,
855,
826,
721,
277,
12,
2644,
29,
2991,
12,
355,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
12,
355,
1015,
29,
1023,
12,
3762,
29,
2969,
9,
267,
14969,
497,
22682,
855,
826,
721,
277,
12,
849,
63,
2487,
29,
885,
63,
2487,
12,
355,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
9,
267,
26046,
855,
826,
721,
277,
9,
199,
199,
533,
19460,
281,
8,
37,
22541,
12,
25555,
12,
799,
22682,
12,
26046,
304,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
288,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
288,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
288,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
288,
2644,
29,
403,
12,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
288,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
662,
22541,
855,
826,
721,
277,
12,
2547,
12,
11358,
29,
13109,
12,
355,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
355,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
267,
25555,
855,
826,
721,
277,
12,
2644,
29,
2991,
12,
355,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
12,
355,
1015,
29,
1023,
12,
3762,
29,
2969,
9,
267,
799,
22682,
855,
826,
721,
277,
12,
849,
63,
2487,
29,
885,
63,
2487,
12,
355,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
9,
267,
26046,
855,
826,
721,
277,
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
] | [
363,
452,
363,
275,
788,
1563,
28593,
297,
283,
11090,
28593,
297,
283,
28593,
418,
199,
199,
504,
8689,
351,
492,
627,
199,
504,
9146,
492,
627,
199,
504,
295,
22682,
492,
627,
199,
504,
15611,
492,
627,
199,
199,
533,
3523,
28593,
8,
37,
22541,
12,
25555,
12,
3523,
497,
22682,
12,
3523,
12407,
304,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
288,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
288,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
288,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
288,
2644,
29,
403,
12,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
288,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
662,
22541,
855,
826,
721,
277,
12,
2547,
12,
11358,
29,
13109,
12,
355,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
355,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
267,
25555,
855,
826,
721,
277,
12,
2644,
29,
2991,
12,
355,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
12,
355,
1015,
29,
1023,
12,
3762,
29,
2969,
9,
267,
799,
22682,
855,
826,
721,
277,
12,
849,
63,
2487,
29,
885,
63,
2487,
12,
355,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
9,
267,
26046,
855,
826,
721,
277,
9,
199,
199,
533,
14969,
28593,
8,
37,
22541,
12,
25555,
12,
14969,
497,
22682,
12,
26046,
304,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
288,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
288,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
288,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
288,
2644,
29,
403,
12,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
288,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
662,
22541,
855,
826,
721,
277,
12,
2547,
12,
11358,
29,
13109,
12,
355,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
355,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
267,
25555,
855,
826,
721,
277,
12,
2644,
29,
2991,
12,
355,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
12,
355,
1015,
29,
1023,
12,
3762,
29,
2969,
9,
267,
14969,
497,
22682,
855,
826,
721,
277,
12,
849,
63,
2487,
29,
885,
63,
2487,
12,
355,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
9,
267,
26046,
855,
826,
721,
277,
9,
199,
199,
533,
19460,
281,
8,
37,
22541,
12,
25555,
12,
799,
22682,
12,
26046,
304,
339,
347,
636,
826,
721,
277,
12,
2547,
12,
288,
849,
63,
2487,
29,
403,
12,
849,
63,
1659,
63,
2487,
29,
403,
12,
288,
11358,
29,
403,
12,
4363,
29,
403,
12,
3462,
29,
403,
12,
288,
2040,
63,
2975,
29,
403,
12,
1004,
63,
4785,
29,
403,
12,
288,
2644,
29,
403,
12,
5027,
63,
928,
29,
403,
12,
5027,
63,
500,
29,
403,
12,
288,
1015,
29,
403,
12,
3762,
29,
403,
304,
267,
662,
22541,
855,
826,
721,
277,
12,
2547,
12,
11358,
29,
13109,
12,
355,
4363,
29,
3724,
12,
3462,
29,
2063,
12,
355,
2040,
63,
2975,
29,
3306,
63,
2975,
12,
1004,
63,
4785,
29,
604,
63,
4785,
9,
267,
25555,
855,
826,
721,
277,
12,
2644,
29,
2991,
12,
355,
5027,
63,
928,
29,
10306,
63,
928,
12,
5027,
63,
500,
29,
10306,
63,
500,
12,
355,
1015,
29,
1023,
12,
3762,
29,
2969,
9,
267,
799,
22682,
855,
826,
721,
277,
12,
849,
63,
2487,
29,
885,
63,
2487,
12,
355,
849,
63,
1659,
63,
2487,
29,
885,
63,
1659,
63,
2487,
9,
267,
26046,
855,
826,
721,
277,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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ripts.
"""
import errno
import logging
import logging.config
import logging.handlers
import optparse
import os
import select
import signal
import sys
import time
import skytools
import skytools.skylog
try:
import skytools.installer_config
default_skylog = skytools.installer_config.skylog
except ImportError:
default_skylog = 0
__pychecker__ = 'no-badexcept'
__all__ = ['BaseScript', 'UsageError', 'daemonize', 'DBScript']
class UsageError(Exception):
"""User induced error."""
#
# daemon mode
#
def daemonize():
"""Turn the process into daemon.
Goes background and disables all i/o.
"""
# launch new process, kill parent
pid = os.fork()
if pid != 0:
os._exit(0)
# start new session
os.setsid()
# stop i/o
fd = os.open("/dev/null", os.O_RDWR)
os.dup2(fd, 0)
os.dup2(fd, 1)
os.dup2(fd, 2)
if fd > 2:
os.close(fd)
#
# Pidfile locking+cleanup & daemonization combined
#
def run_single_process(runnable, daemon, pidfile):
"""Run runnable class, possibly daemonized, locked on pidfile."""
# check if another process is running
if pidfile and os.path.isfile(pidfile):
if skytools.signal_pidfile(pidfile, 0):
print("Pidfile exists, another process running?")
sys.exit(1)
else:
print("Ignoring stale pidfile")
# daemonize if needed
if daemon:
daemonize()
# clean only own pidfile
own_pidfile = False
try:
if pidfile:
data = str(os.getpid())
skytools.write_atomic(pidfile, data)
own_pidfile = True
runnable.run()
finally:
if own_pidfile:
try:
os.remove(pidfile)
except: pass
#
# logging setup
#
_log_config_done = 0
_log_init_done = {}
def _load_log_config(fn, defs):
"""Fixed fileConfig."""
# Work around fileConfig default behaviour to disable
# not only old handlers on load (which slightly makes sense)
# but also old logger objects (which does not make sense).
if sys.hexversion >= 0x2060000:
logging.config.fileConfig(fn, defs, False)
else:
logging.config.fileConfig(fn, defs)
root = logging.getLogger()
for lg in root.manager.loggerDict.values():
lg.disabled = 0
def _init_log(job_name, service_name, cf, log_level, is_daemon):
"""Logging setup happens here."""
global _log_init_done, _log_config_done
got_skylog = 0
use_skylog = cf.getint("use_skylog", default_skylog)
# if non-daemon, avoid skylog if script is running on console.
# set use_skylog=2 to disable.
if not is_daemon and use_skylog == 1:
if os.isatty(sys.stdout.fileno()):
use_skylog = 0
# load logging config if needed
if use_skylog and not _log_config_done:
# python logging.config braindamage:
# cannot specify external classess without such hack
logging.skylog = skytools.skylog
skytools.skylog.set_service_name(service_name, job_name)
# load general config
flist = cf.getlist('skylog_locations',
['skylog.ini', '~/.skylog.ini', '/etc/skylog.ini'])
for fn in flist:
fn = os.path.expanduser(fn)
if os.path.isfile(fn):
defs = {'job_name': job_name, 'service_name': service_name}
_load_log_config(fn, defs)
got_skylog = 1
break
_log_config_done = 1
if not got_skylog:
sys.stderr.write("skylog.ini not found!\n")
sys.exit(1)
# avoid duplicate logging init for job_name
log = logging.getLogger(job_name)
if job_name in _log_init_done:
return log
_log_init_done[job_name] = 1
# tune level on root logger
root = logging.getLogger()
root.setLevel(log_level)
# compatibility: specify ini file in script config
def_fmt = '%(asctime)s %(process)s %(levelname)s %(message)s'
def_datefmt = '' # None
logfile = cf.getfile("logfile", "")
if logfile:
fstr = cf.get('logfmt_file', def_fmt)
fstr_date = cf.get('logdatefmt_file', def_datefmt)
if log_level < logging.INFO:
fstr = cf.get('logfmt_file_verbose', fstr)
fstr_date = cf.get('logdatefmt_file_verbose', fstr_date)
fmt = logging.Formatter(fstr, fstr_date)
size = cf.getint('log_size', 10*1024*1024)
num = cf.getint('log_count', 3)
hdlr = logging.handlers.RotatingFileHandler(
logfile, 'a', size, num)
hdlr.setFormatter(fmt)
root.addHandler(hdlr)
# if skylog.ini is disabled or not available, log at least to stderr
if not got_skylog:
fstr = cf.get('logfmt_console', def_fmt)
fstr_date = cf.get('logdatefmt_console', def_datefmt)
if log_level < logging.INFO:
fstr = cf.get('logfmt_console_verbose', fstr)
fstr_date = cf.get('logdatefmt_console_verbose', fstr_date)
hdlr = logging.StreamHandler()
fmt = logging.Formatter(fstr, fstr_date)
hdlr.setFormatter(fmt)
root.addHandler(hdlr)
return log
class BaseScript(object):
"""Base class for service scripts.
Handles logging, daemonizing, config, errors.
Config template::
## Parameters for skytools.BaseScript ##
# how many seconds to sleep between work loops
# if missing or 0, then instead sleeping, the script will exit
loop_delay = 1.0
# where to log
logfile = ~/log/%(job_name)s.log
# where to write pidfile
pidfile = ~/pid/%(job_name)s.pid
# per-process name to use in logging
#job_name = %(config_name)s
# whether centralized logging should be used
# search-path [ ./skylog.ini, ~/.skylog.ini, /etc/skylog.ini ]
# 0 - disabled
# 1 - enabled, unless non-daemon on console (os.isatty())
# 2 - always enabled
#use_skylog = 0
# where to find skylog.ini
#skylog_locations = skylog.ini, ~/.skylog.ini, /etc/skylog.ini
# how many seconds to sleep after catching a exception
#exception_sleep = 20
"""
service_name = None
job_name = None
cf = None
cf_defaults = {}
pidfile = None
# >0 - sleep time if work() requests sleep
# 0 - exit if work requests sleep
# <0 - run work() once [same as looping=0]
loop_delay = 1.0
# 0 - run work() once
# 1 - run work() repeatedly
looping = 1
# result from last work() call:
# 1 - there is probably more work, don't sleep
# 0 - no work, sleep before calling again
# -1 - exception was thrown
work_state = 1
# setup logger here, this allows override by subclass
log = logging.getLogger('skytools.BaseScript')
def __init__(self, service_name, args):
"""Script setup.
User class should override work() and optionally __init__(), startup(),
reload(), reset(), shutdown() and init_optparse().
NB: In case of daemon, __init__() and startup()/work()/shutdown() will be
run in different processes. So nothing fancy should be done in __init__().
@param service_name: unique name for script.
It will be also default job_name, if not specified in config.
@param args: cmdline args (sys.argv[1:]), but can be overridden
"""
self.service_name = service_name
self.go_daemon = 0
self.need_reload = 0
self.exception_count = 0
self.stat_dict = {}
self.log_level = logging.INFO
# parse command line
parser = self.init_optparse()
self.options, self.args = parser.parse_args(args)
# check args
if self.options.version:
self.print_version()
sys.exit(0)
if self.options.daemon:
self.go_daemon = 1
if self.options.quiet:
self.log_level = logging.WARNING
if self.options.verbose > 1:
self.log_level = skytools.skylog.TRACE
elif self.options.verbose:
self.log_level = logging.DEBUG
self.cf_override = {}
if self.options.set:
for a in self.options.set:
k, v = a.split('=', 1)
self.cf_override[k.strip()] = v.strip()
if self.options.ini:
self.print_ini()
sys.exit(0)
# read config file
self.reload()
# init logging
_init_log(self.job_name, self.service_name, self.cf, self.log_level, self.go_daemon)
# send signal, if needed
if self.options.cmd == "kill":
self.send_signal(signal.SIGTERM)
elif self.options.cmd == "stop":
self.send_signal(signal.SIGINT)
elif self.options.cmd == "reload":
self.send_signal(signal.SIGHUP)
def print_version(self):
service = self.service_name
if getattr(self, '__version__', None):
service += ' version %s' % self.__version__
print '%s, Skytools version %s' % (service, skytools.__version__)
def print_ini(self):
"""Prints out ini file from doc string of the script of default for dbscript
Used by --ini option on command line.
"""
# current service name
print("[%s]\n" % self.service_name)
# walk class hierarchy
bases = [self.__class__]
while len(bases) > 0:
parents = []
for c in bases:
for p in c.__bases__:
if p not in parents:
parents.append(p)
doc = c.__doc__
if doc:
self._print_ini_frag(doc)
bases = parents
def _print_ini_frag(self, doc):
# use last '::' block as config template
pos = doc and doc.rfind('::\n') or -1
if pos < 0:
return
doc = doc[pos+2 : ].rstrip()
doc = skytools.dedent(doc)
# merge overrided options into output
for ln in doc.splitlines():
vals = ln.split('=', 1)
if len(vals) != 2:
print(ln)
continue
k = vals[0].strip()
v = vals[1].strip()
if k and k[0] == '#':
print(ln)
k = k[1:]
if k in self.cf_override:
print('%s = %s' % (k, self.cf_override[k]))
elif k in self.cf_override:
if v:
print('#' + ln)
print('%s = %s' % (k, self.cf_override[k]))
else:
print(ln)
print('')
def load_config(self):
"""Loads and returns skytools.Config instance.
By default it uses first command-line argument as config
file name. Can be overridden.
"""
if len(self.args) < 1:
print("need config file, use --help for help.")
sys.exit(1)
conf_file = self.args[0]
return skytools.Config(self.service_name, conf_file,
user_defs = self.cf_defaults,
override = self.cf_override)
def init_optparse(self, parser = None):
"""Initialize a OptionParser() instance that will be used to
parse command line arguments.
Note that it can be overridden both directions - either DBScript
will initialize an instance and pass it to user code or user can
initialize and then pass to DBScript.init_optparse().
@param parser: optional OptionParser() instance,
where DBScript should attach its own arguments.
@return: initialized OptionParser() instance.
"""
if parser:
p = parser
else:
p = optparse.OptionParser()
p.set_usage("%prog [options] INI")
# generic options
p.add_option("-q", "--quiet", action="store_true",
help = "log only errors and warnings")
p.add_option("-v", "--verbose", action="count",
help = "log verbosely")
p.add_option("-d", "--daemon", action="store_true",
help = "go background")
p.add_option("-V", "--version", action="store_true",
help = "print version info and exit")
p.add_option("", "--ini", action="store_true",
help = "display sample ini file")
p.add_option("", "--set", action="append",
help = "override config setting (--set 'PARAM=VAL')")
# control options
g = optparse.OptionGroup(p, 'control running process')
g.add_option("-r", "--reload",
action="store_const", const="reload", dest="cmd",
help = "reload config (send SIGHUP)")
g.add_option("-s", "--stop",
action="store_const", const="stop", dest="cmd",
help = "stop program safely (send SIGINT)")
g.add_option("-k", "--kill",
action="store_const", const="kill", dest="cmd",
help = "kill program immediately (send SIGTERM)")
p.add_option_group(g)
return p
def send_signal(self, sig):
if not self.pidfile:
self.log.warning("No pidfile in config, nothing to do")
elif os.path.isfile(self.pidfile):
alive = skytools.signal_pidfile(self.pidfile, sig)
if not alive:
self.log.warning("pidfile exists, but process not running")
else:
self.log.warning("No pidfile, process not running")
sys.exit(0)
def set_single_loop(self, do_single_loop):
"""Changes whether the script will loop or not."""
if do_single_loop:
self.looping = 0
else:
self.looping = 1
def _boot_daemon(self):
run_single_process(self, self.go_daemon, self.pidfile)
def start(self):
"""This will launch main processing thread."""
if self.go_daemon:
if not self.pidfile:
self.log.error("Daemon needs pidfile")
sys.exit(1)
self.run_func_safely(self._boot_daemon)
def stop(self):
"""Safely stops processing loop."""
self.looping = 0
def reload(self):
"Reload config."
# avoid double loading on startup
if not self.cf:
self.cf = self.load_config()
else:
self.cf.reload()
self.log.info ("Config reloaded")
self.job_name = self.cf.get("job_name")
self.pidfile = self.cf.getfile("pidfile", '')
self.loop_delay = self.cf.getfloat("loop_delay", self.loop_delay)
self.exception_sleep = self.cf.getfloat("exception_sleep", 20)
self.exception_quiet = self.cf.getlist("exception_quiet", [])
self.exception_grace = self.cf.getfloat("exception_grace", 5*60)
self.exception_reset = self.cf.getfloat("exception_reset", 15*60)
def hook_sighup(self, sig, frame):
"Internal SIGHUP handler. Minimal code here."
self.need_reload = 1
last_sigint = 0
def hook_sigint(self, sig, frame):
"Internal SIGINT handler. Minimal code here."
self.stop()
t = time.time()
if t - self.last_sigint < 1:
self.log.warning("Double ^C, fast exit")
sys.exit(1)
self.last_sigint = t
def stat_get(self, key):
"""Reads a stat value."""
try:
value = self.stat_dict[key]
except KeyError:
value = None
return value
def stat_put(self, key, value):
"""Sets a stat value."""
self.stat_dict[key] = value
def stat_increase(self, key, increase = 1):
"""Increases a stat value."""
try:
self.stat_dict[key] += increase
except KeyError:
self.stat_dict[key] = increase
def send_stats(self):
"Send statistics to log."
res = []
for k, v in self.stat_dict.items():
res.append("%s: %s" % (k, v))
if len(res) == 0:
return
logmsg = "{%s}" % ", ".join(res)
self.log.info(logmsg)
self.stat_dict = {}
def reset(self):
"Something bad happened, reset all state."
pass
def run(self):
"Thread main loop."
# run startup, safely
self.run_func_safely(self.startup)
while 1:
# reload config, if needed
if self.need_reload:
self.reload()
self.need_reload = 0
# do some work
work = self.run_once()
if not self.looping or self.loop_delay < 0:
break
# remember work state
self.work_state = work
# should sleep?
if not work:
if self.loop_delay > 0:
self.sleep(self.loop_delay)
if not self.looping:
break
else:
break
# run shutdown, safely?
self.shutdown()
def run_once(self):
state = self.run_func_safely(self.work, True)
# send stats that was added
self.send_stats()
return state
last_func_fail = None
def run_func_safely(self, func, prefer_looping = False):
"Run users work function, safely."
try:
r = func()
if self.last_func_fail and time.time() > self.last_func_fail + self.exception_reset:
self.last_func_fail = None
# set exception count to 0 after success
self.exception_count = 0
return r
except UsageError, d:
self.log.error(str(d))
sys.exit(1)
except MemoryError, d:
try: # complex logging may not succeed
self.log.exception("Job %s out of memory, exiting" % self.job_name)
except MemoryError:
self.log.fatal("Out of memory")
sys.exit(1)
except SystemExit, d:
self.send_stats()
if prefer_looping and self.looping and self.loop_delay > 0:
self.log.info("got SystemExit(%s), exiting" % str(d))
self.reset()
raise d
except KeyboardInterrupt, d:
self.send_stats()
if prefer_looping and self.looping and self.loop_delay > 0:
self.log.info("got KeyboardInterrupt, exiting")
self.reset()
sys.exit(1)
except Exception, d:
try: # this may fail too
self.send_stats()
except:
pass
if self.last_func_fail is None:
self.last_func_fail = time.time()
emsg = str(d).rstrip()
self.reset()
self.exception_hook(d, emsg)
# reset and sleep
self.reset()
if prefer_looping and self.looping and self.loop_delay > 0:
# increase exception count & sleep
self.exception_count += 1
self.sleep_on_exception()
return -1
sys.exit(1)
def sleep(self, secs):
"""Make script sleep for some amount of time."""
try:
time.sleep(secs)
except IOError, ex:
if ex.errno != errno.EINTR:
raise
def sleep_on_exception(self):
"""Make script sleep for some amount of time when an exception occurs.
To implement more advance exception sleeping like exponential backoff you
can override this method. Also note that you can use self.exception_count
to track the number of consecutive exceptions.
"""
self.sleep(self.exception_sleep)
def _is_quiet_exception(self, ex):
return ((self.exception_quiet == ["ALL"] or ex.__class__.__name__ in self.exception_quiet)
and self.last_func_fail and time.time() < self.last_func_fail + self.exception_grace)
def exception_hook(self, det, emsg):
"""Called on after exception processing.
Can do additional logging.
@param det: exception details
@param emsg: exception msg
"""
lm = "Job %s crashed: %s" % (self.job_name, emsg)
if self._is_quiet_exception(det):
self.log.warning(lm)
else:
self.log.exception(lm)
def work(self):
"""Here should user's processing happen.
Return value is taken as boolean - if true, the next loop
starts immediately. If false, DBScript sleeps for a loop_delay.
"""
raise Exception("Nothing implemented?")
def startup(self):
"""Will be called just before entering main loop.
In case of daemon, if will be called in same process as work(),
unlike __init__().
"""
self.started = time.time()
# set signals
if hasattr(signal, 'SIGHUP'):
signal.signal(signal.SIGHUP, self.hook_sighup)
if hasattr(signal, 'SIGINT'):
signal.signal(signal.SIGINT, self.hook_sigint)
def shutdown(self):
"""Will be called just after exiting main loop.
In case of daemon, if will be called in same process as work(),
unlike __init__().
"""
pass
# define some aliases (short-cuts / backward compatibility cruft)
stat_add = stat_put # Old, deprecated function.
stat_inc = stat_increase
##
## DBScript
##
#: how old connections need to be closed
DEF_CONN_AGE = 20*60 # 20 min
class DBScript(BaseScript):
"""Base class for database scripts.
Handles database connection state.
Config template::
## Parameters for skytools.DBScript ##
# default lifetime for database connections (in seconds)
#connection_lifetime = 1200
"""
def __init__(self, service_name, args):
"""Script setup.
User class should override work() and optionally __init__(), startup(),
reload(), reset() and init_optparse().
NB: in case of daemon, the __init__() and startup()/work() will be
run in different processes. So nothing fancy should be done in __init__().
@param service_name: unique name for script.
It will be also default job_name, if not specified in config.
@param args: cmdline args (sys.argv[1:]), but can be overridden
"""
self.db_cache = {}
self._db_defaults = {}
self._listen_map = {} # dbname: channel_list
BaseScript.__init__(self, service_name, args)
def connection_hook(self, dbname, conn):
pass
def set_database_defaults(self, dbname, **kwargs):
self._db_defaults[dbname] = kwargs
def add_connect_string_profile(self, connstr, profile):
"""Add extra profile info to connect string.
"""
if profile:
extra = self.cf.get("%s_extra_connstr" % profile, '')
if extra:
connstr += ' ' + extra
return connstr
def get_database(self, dbname, autocommit = 0, isolation_level = -1,
cache = None, connstr = None, profile = None):
"""Load cached database connection.
User must not store it permanently somewhere,
as all connections will be invalidated on reset.
"""
max_age = self.cf.getint('connection_lifetime', DEF_CONN_AGE)
if not cache:
cache = dbname
params = {}
defs = self._db_defaults.get(cache, {})
params.update(defs)
if isolation_level >= 0:
params['isolation_level'] = isolation_level
elif autocommit:
params['isolation_level'] = 0
elif params.get('autocommit', 0):
params['isolation_level'] = 0
elif not 'isolation_level' in params:
params['isolation_level'] = skytools.I_READ_COMMITTED
if not 'max_age' in params:
params['max_age'] = max_age
if cache in self.db_cache:
dbc = self.db_cache[cache]
if connstr is None:
connstr = self.cf.get(dbname, '')
if connstr:
connstr = self.add_connect_string_profile(connstr, profile)
dbc.check_connstr(connstr)
else:
if not connstr:
connstr = self.cf.get(dbname)
connstr = self.add_connect_string_profile(connstr, profile)
# connstr might contain password, it is not a good idea to log it
filtered_connstr = connstr
pos = connstr.lower().find('password')
if pos >= 0:
filtered_connstr = connstr[:pos] + ' [...]'
self.log.debug("Connect '%s' to '%s'" % (cache, filtered_connstr))
dbc = DBCachedConn(cache, connstr, params['max_age'], setup_func = self.connection_hook)
self.db_cache[cache] = dbc
clist = []
if cache in self._listen_map:
clist = self._listen_map[cache]
return dbc.get_connection(params['isolation_level'], clist)
def close_database(self, dbname):
"""Explicitly close a cached connection.
Next call to get_database() will reconnect.
"""
if dbname in self.db_cache:
dbc = self.db_cache[dbname]
dbc.reset()
del self.db_cache[dbname]
def reset(self):
"Something bad happened, reset all connections."
for dbc in self.db_cache.values():
dbc.reset()
self.db_cache = {}
BaseScript.reset(self)
def run_once(self):
state = BaseScript.run_once(self)
# reconnect if needed
for dbc in self.db_cache.values():
dbc.refresh()
return state
def exception_hook(self, d, emsg):
"""Log database and query details from exception."""
curs = getattr(d, 'cursor', None)
conn = getattr(curs, 'connection', None)
cname = getattr(conn, 'my_name', None)
if cname:
# Properly named connection
cname = d.cursor.connection.my_name
sql = getattr(curs, 'query', None) or '?'
if len(sql) > 200: # avoid logging londiste huge batched queries
sql = sql[:60] + " ..."
lm = "Job %s got error on connection '%s': %s. Query: %s" % (
self.job_name, cname, emsg, sql)
if self._is_quiet_exception(d):
self.log.warning(lm)
else:
self.log.exception(lm)
else:
BaseScript.exception_hook(self, d, emsg)
def sleep(self, secs):
"""Make script sleep for some amount of time."""
fdlist = []
for dbname in self._listen_map.keys():
if dbname not in self.db_cache:
continue
fd = self.db_cache[dbname].fileno()
if fd is None:
continue
fdlist.append(fd)
if not fdlist:
return BaseScript.sleep(self, secs)
try:
if hasattr(select, 'poll'):
p = select.poll()
for fd in fdlist:
p.register(fd, select.POLLIN)
p.poll(int(secs * 1000))
else:
select.select(fdlist, [], [], secs)
except select.error, d:
self.log.info('wait canceled')
def _exec_cmd(self, curs, sql, args, quiet = False, prefix = None):
"""Internal tool: Run SQL on cursor."""
if self.options.verbose:
self.log.debug("exec_cmd: %s" % skytools.quote_statement(sql, args))
_pfx = ""
if prefix:
_pfx = "[%s] " % prefix
curs.execute(sql, args)
ok = True
rows = curs.fetchall()
for row in rows:
try:
code = row['ret_code']
msg = row['ret_note']
except KeyError:
self.log.error("Query does not conform to exec_cmd API:")
self.log.error("SQL: %s" % skytools.quote_statement(sql, args))
self.log.error("Row: %s" % repr(row.copy()))
sys.exit(1)
level = code / 100
if level == 1:
self.log.debug("%s%d %s" % (_pfx, code, msg))
elif level == 2:
if quiet:
self.log.debug("%s%d %s" % (_pfx, code, msg))
else:
self.log.info("%s%s" % (_pfx, msg,))
elif level == 3:
self.log.warning("%s%s" % (_pfx, msg,))
else:
self.log.error("%s%s" % (_pfx, msg,))
self.log.debug("Query was: %s" % skytools.quote_statement(sql, args))
ok = False
return (ok, rows)
def _exec_cmd_many(self, curs, sql, baseargs, extra_list, quiet = False, prefix=None):
"""Internal tool: Run SQL on cursor multiple times."""
ok = True
rows = []
for a in extra_list:
(tmp_ok, tmp_rows) = self._exec_cmd(curs, sql, baseargs + [a], quiet, prefix)
if not tmp_ok:
ok = False
rows += tmp_rows
return (ok, rows)
def exec_cmd(self, db_or_curs, q, args, commit = True, quiet = False, prefix = None):
"""Run SQL on db with code/value error handling."""
if hasattr(db_or_curs, 'cursor'):
db = db_or_curs
curs = db.cursor()
else:
db = None
curs = db_or_curs
(ok, rows) = self._exec_cmd(curs, q, args, quiet, prefix)
if ok:
if commit and db:
db.commit()
return rows
else:
if db:
db.rollback()
if self.options.verbose:
raise Exception("db error")
# error is already logged
sys.exit(1)
def exec_cmd_many(self, db_or_curs, sql, baseargs, extra_list,
commit = True, quiet = False, prefix = None):
"""Run SQL on db multiple times."""
if hasattr(db_or_curs, 'cursor'):
db = db_or_curs
curs = db.cursor()
else:
db = None
curs = db_or_curs
(ok, rows) = self._exec_cmd_many(curs, sql, baseargs, extra_list, quiet, prefix)
if ok:
if commit and db:
db.commit()
return rows
else:
if db:
db.rollback()
if self.options.verbose:
raise Exception("db error")
# error is already logged
sys.exit(1)
def execute_with_retry (self, dbname, stmt, args, exceptions = None):
""" Execute SQL and retry if it fails.
Return number of retries and current valid cursor, or raise an exception.
"""
sql_retry = self.cf.getbool("sql_retry", False)
sql_retry_max_count = self.cf.getint("sql_retry_max_count", 10)
sql_retry_max_time = self.cf.getint("sql_retry_max_time", 300)
sql_retry_formula_a = self.cf.getint("sql_retry_formula_a", 1)
sql_retry_formula_b = self.cf.getint("sql_retry_formula_b", 5)
sql_retry_formula_cap = self.cf.getint("sql_retry_formula_cap", 60)
elist = exceptions or tuple()
stime = time.time()
tried = 0
dbc = None
while True:
try:
if dbc is None:
if dbname not in self.db_cache:
self.get_database(dbname, autocommit=1)
dbc = self.db_cache[dbname]
if dbc.isolation_level != skytools.I_AUTOCOMMIT:
raise skytools.UsageError ("execute_with_retry: autocommit required")
else:
dbc.reset()
curs = dbc.get_connection(dbc.isolation_level).cursor()
curs.execute (stmt, args)
break
except elist, e:
if not sql_retry or tried >= sql_retry_max_count or time.time() - stime >= sql_retry_max_time:
raise
self.log.info("Job %s got error on connection %s: %s" % (self.job_name, dbname, e))
except:
raise
# y = a + bx , apply cap
y = sql_retry_formula_a + sql_retry_formula_b * tried
if sql_retry_formula_cap is not None and y > sql_retry_formula_cap:
y = sql_retry_formula_cap
tried += 1
self.log.info("Retry #%i in %i seconds ...", tried, y)
self.sleep(y)
return tried, curs
def listen(self, dbname, channel):
"""Make connection listen for specific event channel.
Listening will be activated on next .get_database() call.
Basically this means that DBScript.sleep() will poll for events
on that db connection, so when event appears, script will be
woken up.
"""
if dbname not in self._listen_map:
self._listen_map[dbname] = []
clist = self._listen_map[dbname]
if channel not in clist:
clist.append(channel)
def unlisten(self, dbname, channel='*'):
"""Stop connection for listening on specific event channel.
Listening will stop on next .get_database() call.
"""
if dbname not in self._listen_map:
return
if channel == '*':
del self._listen_map[dbname]
return
clist = self._listen_map[dbname]
try:
clist.remove(channel)
except ValueError:
pass
class DBCachedConn(object):
"""Cache a db connection."""
def __init__(self, name, loc, max_age = DEF_CONN_AGE, verbose = False, setup_func=None, channels=[]):
self.name = name
self.loc = loc
self.conn = None
self.conn_time = 0
self.max_age = max_age
self.isolation_level = -1
self.verbose = verbose
self.setup_func = setup_func
self.listen_channel_list = []
def fileno(self):
if not self.conn:
return None
return self.conn.cursor().fileno()
def get_connection(self, isolation_level = -1, listen_channel_list = []):
# default isolation_level is READ COMMITTED
if isolation_level < 0:
isolation_level = skytools.I_READ_COMMITTED
# new conn?
if not self.conn:
self.isolation_level = isolation_level
self.conn = skytools.connect_database(self.loc)
self.conn.my_name = self.name
self.conn.set_isolation_level(isolation_level)
self.conn_time = time.time()
if self.setup_func:
self.setup_func(self.name, self.conn)
else:
if self.isolation_level != isolation_level:
raise Exception("Conflict in isolation_level")
self._sync_listen(listen_channel_list)
# done
return self.conn
def _sync_listen(self, new_clist):
if not new_clist and not self.listen_channel_list:
return
curs = self.conn.cursor()
for ch in self.listen_channel_list:
if ch not in new_clist:
curs.execute("UNLISTEN %s" % skytools.quote_ident(ch))
for ch in new_clist:
if ch not in self.listen_channel_list:
curs.execute("LISTEN %s" % skytools.quote_ident(ch))
if self.isolation_level != skytools.I_AUTOCOMMIT:
self.conn.commit()
self.listen_channel_list = new_clist[:]
def refresh(self):
if not self.conn:
return
#for row in self.conn.notifies():
# if row[0].lower() == "reload":
# self.reset()
# return
if not self.max_age:
return
if time.time() - self.conn_time >= self.max_age:
self.reset()
def reset(self):
if not self.conn:
return
# drop reference
conn = self.conn
self.conn = None
self.listen_channel_list = []
# close
try:
conn.close()
except: pass
def check_connstr(self, connstr):
"""Drop connection if connect string has changed.
"""
if self.loc != connstr:
self.reset()
| isc | [
199,
624,
6119,
1893,
3423,
436,
3992,
367,
3050,
10554,
14,
199,
199,
624,
199,
199,
646,
7554,
199,
646,
2050,
199,
646,
2050,
14,
888,
199,
646,
2050,
14,
5586,
199,
646,
8691,
199,
646,
747,
199,
646,
3504,
199,
646,
4673,
199,
646,
984,
199,
646,
900,
199,
199,
646,
2386,
89,
2537,
199,
646,
2386,
89,
2537,
14,
12267,
793,
199,
199,
893,
26,
272,
492,
2386,
89,
2537,
14,
17047,
63,
888,
272,
849,
63,
12267,
793,
275,
2386,
89,
2537,
14,
17047,
63,
888,
14,
12267,
793,
199,
2590,
3545,
26,
272,
849,
63,
12267,
793,
275,
378,
199,
199,
363,
647,
6743,
363,
275,
283,
889,
13,
2470,
731,
716,
7,
199,
199,
363,
452,
363,
275,
788,
1563,
5229,
297,
283,
7692,
547,
297,
283,
10824,
794,
297,
283,
2846,
5229,
418,
199,
199,
533,
11028,
547,
8,
1726,
304,
272,
408,
1899,
315,
16584,
1125,
1041,
199,
199,
3,
199,
3,
11128,
818,
199,
3,
199,
199,
318,
11128,
794,
837,
272,
408,
16838,
314,
2112,
1901,
11128,
14,
339,
3971,
397,
8020,
436,
28421,
1006,
284,
15,
79,
14,
272,
408,
339,
327,
10623,
892,
2112,
12,
14561,
1676,
272,
4422,
275,
747,
14,
11796,
342,
272,
340,
4422,
1137,
378,
26,
267,
747,
423,
2224,
8,
16,
9,
339,
327,
1343,
892,
2351,
272,
747,
14,
409,
4148,
342,
339,
327,
3631,
284,
15,
79,
272,
6111,
275,
747,
14,
1490,
4769,
2374,
15,
2307,
401,
747,
14,
47,
63,
15543,
6524,
9,
272,
747,
14,
11048,
18,
8,
2592,
12,
378,
9,
272,
747,
14,
11048,
18,
8,
2592,
12,
413,
9,
272,
747,
14,
11048,
18,
8,
2592,
12,
499,
9,
272,
340,
6111,
690,
499,
26,
267,
747,
14,
1600,
8,
2592,
9,
199,
199,
3,
199,
3,
510,
344,
493,
27267,
11,
7661,
1253,
11128,
2072,
12149,
199,
3,
199,
199,
318,
1255,
63,
4780,
63,
1412,
8,
1065,
25757,
12,
11128,
12,
32739,
304,
272,
408,
2540,
1255,
25757,
1021,
12,
12570,
11128,
1759,
12,
14233,
641,
32739,
1041,
339,
327,
1104,
340,
4573,
2112,
365,
3879,
272,
340,
32739,
436,
747,
14,
515,
14,
6292,
8,
21957,
304,
267,
340,
2386,
89,
2537,
14,
4653,
63,
21957,
8,
21957,
12,
378,
304,
288,
870,
480,
29620,
493,
3495,
12,
4573,
2112,
3879,
18582,
288,
984,
14,
2224,
8,
17,
9,
267,
587,
26,
288,
870,
480,
32390,
20149,
32739,
531,
339,
327,
11128,
794,
340,
4346,
272,
340,
11128,
26,
267,
11128,
794,
342,
339,
327,
3633,
1454,
5705,
32739,
272,
5705,
63,
21957,
275,
756,
339,
862,
26,
267,
340,
32739,
26,
288,
666,
275,
620,
8,
736,
14,
17829,
1012,
288,
2386,
89,
2537,
14,
952,
63,
10910,
8,
21957,
12,
666,
9,
288,
5705,
63,
21957,
275,
715,
398,
1255,
25757,
14,
1065,
342,
272,
3753,
26,
267,
340,
5705,
63,
21957,
26,
288,
862,
26,
355,
747,
14,
2168,
8,
21957,
9,
288,
871,
26,
986,
199,
199,
3,
199,
3,
2050,
3272,
199,
3,
199,
199,
63,
793,
63,
888,
63,
4456,
275,
378,
199,
63,
793,
63,
826,
63,
4456,
275,
1052,
199,
199,
318,
485,
912,
63,
793,
63,
888,
8,
2324,
12,
22603,
304,
272,
408,
9515,
570,
2028,
1041,
339,
327,
9361,
6818,
570,
2028,
849,
13942,
370,
3507,
272,
327,
440,
1454,
2269,
8297,
641,
2248,
334,
6777,
18023,
7704,
12249,
9,
272,
327,
1325,
2597,
2269,
2512,
2251,
334,
6777,
1630,
440,
1852,
12249,
680,
339,
340,
984,
14,
4097,
1023,
2356,
378,
88,
11089,
993,
26,
267,
2050,
14,
888,
14,
493,
2028,
8,
2324,
12,
22603,
12,
756,
9,
272,
587,
26,
267,
2050,
14,
888,
14,
493,
2028,
8,
2324,
12,
22603,
9,
267,
1738,
275,
2050,
14,
5572,
342,
267,
367,
634,
71,
315,
1738,
14,
2609,
14,
2921,
2141,
14,
1459,
837,
288,
634,
71,
14,
7011,
275,
378,
199,
199,
318,
485,
826,
63,
793,
8,
2423,
63,
354,
12,
2435,
63,
354,
12,
3980,
12,
943,
63,
1896,
12,
365,
63,
10824,
304,
272,
408,
14054,
3272,
10986,
2348,
1041,
272,
2288,
485,
793,
63,
826,
63,
4456,
12,
485,
793,
63,
888,
63,
4456,
339,
4788,
63,
12267,
793,
275,
378,
272,
675,
63,
12267,
793,
275,
3980,
14,
26627,
480,
1180,
63,
12267,
793,
401,
849,
63,
12267,
793,
9,
339,
327,
340,
2222,
13,
10824,
12,
5126,
2386,
89,
793,
340,
2884,
365,
3879,
641,
8559,
14,
272,
327,
663,
675,
63,
12267,
793,
29,
18,
370,
3507,
14,
272,
340,
440,
365,
63,
10824,
436,
675,
63,
12267,
793,
508,
413,
26,
267,
340,
747,
14,
21122,
8,
1274,
14,
2703,
14,
9843,
5109,
288,
675,
63,
12267,
793,
275,
378,
339,
327,
2248,
2050,
1101,
340,
4346,
272,
340,
675,
63,
12267,
793,
436,
440,
485,
793,
63,
888,
63,
4456,
26,
267,
327,
2366,
2050,
14,
888,
11137,
688,
65,
960,
26,
267,
327,
3913,
4165,
5957,
824,
305,
5480,
1928,
4066,
11176,
267,
2050,
14,
12267,
793,
275,
2386,
89,
2537,
14,
12267,
793,
267,
2386,
89,
2537,
14,
12267,
793,
14,
409,
63,
1364,
63,
354,
8,
1364,
63,
354,
12,
3906,
63,
354,
9,
398,
327,
2248,
8605,
1101,
267,
28579,
275,
3980,
14,
21343,
360,
12267,
793,
63,
8022,
297,
2574,
788,
12267,
793,
14,
2730,
297,
17352,
8083,
12267,
793,
14,
2730,
297,
1994,
6839,
15,
12267,
793,
14,
2730,
1105,
267,
367,
4325,
315,
28579,
26,
288,
4325,
275,
747,
14,
515,
14,
12131,
8,
2324,
9,
288,
340,
747,
14,
515,
14,
6292,
8,
2324,
304,
355,
22603,
275,
791,
2423,
63,
354,
356,
3906,
63,
354,
12,
283,
1364,
63,
354,
356,
2435,
63,
354,
93,
355,
485,
912,
63,
793,
63,
888,
8,
2324,
12,
22603,
9,
355,
4788,
63,
12267,
793,
275,
413,
355,
2059,
267,
485,
793,
63,
888,
63,
4456,
275,
413,
267,
340,
440,
4788,
63,
12267,
793,
26,
288,
984,
14,
3083,
14,
952,
480,
12267,
793,
14,
2730,
440,
1911,
12525,
78,
531,
288,
984,
14,
2224,
8,
17,
9,
339,
327,
5126,
9250,
2050,
4205,
367,
3906,
63
] | [
624,
6119,
1893,
3423,
436,
3992,
367,
3050,
10554,
14,
199,
199,
624,
199,
199,
646,
7554,
199,
646,
2050,
199,
646,
2050,
14,
888,
199,
646,
2050,
14,
5586,
199,
646,
8691,
199,
646,
747,
199,
646,
3504,
199,
646,
4673,
199,
646,
984,
199,
646,
900,
199,
199,
646,
2386,
89,
2537,
199,
646,
2386,
89,
2537,
14,
12267,
793,
199,
199,
893,
26,
272,
492,
2386,
89,
2537,
14,
17047,
63,
888,
272,
849,
63,
12267,
793,
275,
2386,
89,
2537,
14,
17047,
63,
888,
14,
12267,
793,
199,
2590,
3545,
26,
272,
849,
63,
12267,
793,
275,
378,
199,
199,
363,
647,
6743,
363,
275,
283,
889,
13,
2470,
731,
716,
7,
199,
199,
363,
452,
363,
275,
788,
1563,
5229,
297,
283,
7692,
547,
297,
283,
10824,
794,
297,
283,
2846,
5229,
418,
199,
199,
533,
11028,
547,
8,
1726,
304,
272,
408,
1899,
315,
16584,
1125,
1041,
199,
199,
3,
199,
3,
11128,
818,
199,
3,
199,
199,
318,
11128,
794,
837,
272,
408,
16838,
314,
2112,
1901,
11128,
14,
339,
3971,
397,
8020,
436,
28421,
1006,
284,
15,
79,
14,
272,
408,
339,
327,
10623,
892,
2112,
12,
14561,
1676,
272,
4422,
275,
747,
14,
11796,
342,
272,
340,
4422,
1137,
378,
26,
267,
747,
423,
2224,
8,
16,
9,
339,
327,
1343,
892,
2351,
272,
747,
14,
409,
4148,
342,
339,
327,
3631,
284,
15,
79,
272,
6111,
275,
747,
14,
1490,
4769,
2374,
15,
2307,
401,
747,
14,
47,
63,
15543,
6524,
9,
272,
747,
14,
11048,
18,
8,
2592,
12,
378,
9,
272,
747,
14,
11048,
18,
8,
2592,
12,
413,
9,
272,
747,
14,
11048,
18,
8,
2592,
12,
499,
9,
272,
340,
6111,
690,
499,
26,
267,
747,
14,
1600,
8,
2592,
9,
199,
199,
3,
199,
3,
510,
344,
493,
27267,
11,
7661,
1253,
11128,
2072,
12149,
199,
3,
199,
199,
318,
1255,
63,
4780,
63,
1412,
8,
1065,
25757,
12,
11128,
12,
32739,
304,
272,
408,
2540,
1255,
25757,
1021,
12,
12570,
11128,
1759,
12,
14233,
641,
32739,
1041,
339,
327,
1104,
340,
4573,
2112,
365,
3879,
272,
340,
32739,
436,
747,
14,
515,
14,
6292,
8,
21957,
304,
267,
340,
2386,
89,
2537,
14,
4653,
63,
21957,
8,
21957,
12,
378,
304,
288,
870,
480,
29620,
493,
3495,
12,
4573,
2112,
3879,
18582,
288,
984,
14,
2224,
8,
17,
9,
267,
587,
26,
288,
870,
480,
32390,
20149,
32739,
531,
339,
327,
11128,
794,
340,
4346,
272,
340,
11128,
26,
267,
11128,
794,
342,
339,
327,
3633,
1454,
5705,
32739,
272,
5705,
63,
21957,
275,
756,
339,
862,
26,
267,
340,
32739,
26,
288,
666,
275,
620,
8,
736,
14,
17829,
1012,
288,
2386,
89,
2537,
14,
952,
63,
10910,
8,
21957,
12,
666,
9,
288,
5705,
63,
21957,
275,
715,
398,
1255,
25757,
14,
1065,
342,
272,
3753,
26,
267,
340,
5705,
63,
21957,
26,
288,
862,
26,
355,
747,
14,
2168,
8,
21957,
9,
288,
871,
26,
986,
199,
199,
3,
199,
3,
2050,
3272,
199,
3,
199,
199,
63,
793,
63,
888,
63,
4456,
275,
378,
199,
63,
793,
63,
826,
63,
4456,
275,
1052,
199,
199,
318,
485,
912,
63,
793,
63,
888,
8,
2324,
12,
22603,
304,
272,
408,
9515,
570,
2028,
1041,
339,
327,
9361,
6818,
570,
2028,
849,
13942,
370,
3507,
272,
327,
440,
1454,
2269,
8297,
641,
2248,
334,
6777,
18023,
7704,
12249,
9,
272,
327,
1325,
2597,
2269,
2512,
2251,
334,
6777,
1630,
440,
1852,
12249,
680,
339,
340,
984,
14,
4097,
1023,
2356,
378,
88,
11089,
993,
26,
267,
2050,
14,
888,
14,
493,
2028,
8,
2324,
12,
22603,
12,
756,
9,
272,
587,
26,
267,
2050,
14,
888,
14,
493,
2028,
8,
2324,
12,
22603,
9,
267,
1738,
275,
2050,
14,
5572,
342,
267,
367,
634,
71,
315,
1738,
14,
2609,
14,
2921,
2141,
14,
1459,
837,
288,
634,
71,
14,
7011,
275,
378,
199,
199,
318,
485,
826,
63,
793,
8,
2423,
63,
354,
12,
2435,
63,
354,
12,
3980,
12,
943,
63,
1896,
12,
365,
63,
10824,
304,
272,
408,
14054,
3272,
10986,
2348,
1041,
272,
2288,
485,
793,
63,
826,
63,
4456,
12,
485,
793,
63,
888,
63,
4456,
339,
4788,
63,
12267,
793,
275,
378,
272,
675,
63,
12267,
793,
275,
3980,
14,
26627,
480,
1180,
63,
12267,
793,
401,
849,
63,
12267,
793,
9,
339,
327,
340,
2222,
13,
10824,
12,
5126,
2386,
89,
793,
340,
2884,
365,
3879,
641,
8559,
14,
272,
327,
663,
675,
63,
12267,
793,
29,
18,
370,
3507,
14,
272,
340,
440,
365,
63,
10824,
436,
675,
63,
12267,
793,
508,
413,
26,
267,
340,
747,
14,
21122,
8,
1274,
14,
2703,
14,
9843,
5109,
288,
675,
63,
12267,
793,
275,
378,
339,
327,
2248,
2050,
1101,
340,
4346,
272,
340,
675,
63,
12267,
793,
436,
440,
485,
793,
63,
888,
63,
4456,
26,
267,
327,
2366,
2050,
14,
888,
11137,
688,
65,
960,
26,
267,
327,
3913,
4165,
5957,
824,
305,
5480,
1928,
4066,
11176,
267,
2050,
14,
12267,
793,
275,
2386,
89,
2537,
14,
12267,
793,
267,
2386,
89,
2537,
14,
12267,
793,
14,
409,
63,
1364,
63,
354,
8,
1364,
63,
354,
12,
3906,
63,
354,
9,
398,
327,
2248,
8605,
1101,
267,
28579,
275,
3980,
14,
21343,
360,
12267,
793,
63,
8022,
297,
2574,
788,
12267,
793,
14,
2730,
297,
17352,
8083,
12267,
793,
14,
2730,
297,
1994,
6839,
15,
12267,
793,
14,
2730,
1105,
267,
367,
4325,
315,
28579,
26,
288,
4325,
275,
747,
14,
515,
14,
12131,
8,
2324,
9,
288,
340,
747,
14,
515,
14,
6292,
8,
2324,
304,
355,
22603,
275,
791,
2423,
63,
354,
356,
3906,
63,
354,
12,
283,
1364,
63,
354,
356,
2435,
63,
354,
93,
355,
485,
912,
63,
793,
63,
888,
8,
2324,
12,
22603,
9,
355,
4788,
63,
12267,
793,
275,
413,
355,
2059,
267,
485,
793,
63,
888,
63,
4456,
275,
413,
267,
340,
440,
4788,
63,
12267,
793,
26,
288,
984,
14,
3083,
14,
952,
480,
12267,
793,
14,
2730,
440,
1911,
12525,
78,
531,
288,
984,
14,
2224,
8,
17,
9,
339,
327,
5126,
9250,
2050,
4205,
367,
3906,
63,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
ProfessionalIT/professionalit-webiste | sdk/google_appengine/lib/django-1.5/django/contrib/localflavor/it/it_province.py | 110 | 2779 | # -*- coding: utf-8 -*
from __future__ import unicode_literals
PROVINCE_CHOICES = (
('AG', 'Agrigento'),
('AL', 'Alessandria'),
('AN', 'Ancona'),
('AO', 'Aosta'),
('AR', 'Arezzo'),
('AP', 'Ascoli Piceno'),
('AT', 'Asti'),
('AV', 'Avellino'),
('BA', 'Bari'),
('BT', 'Barletta-Andria-Trani'), # active starting from 2009
('BL', 'Belluno'),
('BN', 'Benevento'),
('BG', 'Bergamo'),
('BI', 'Biella'),
('BO', 'Bologna'),
('BZ', 'Bolzano/Bozen'),
('BS', 'Brescia'),
('BR', 'Brindisi'),
('CA', 'Cagliari'),
('CL', 'Caltanissetta'),
('CB', 'Campobasso'),
('CI', 'Carbonia-Iglesias'),
('CE', 'Caserta'),
('CT', 'Catania'),
('CZ', 'Catanzaro'),
('CH', 'Chieti'),
('CO', 'Como'),
('CS', 'Cosenza'),
('CR', 'Cremona'),
('KR', 'Crotone'),
('CN', 'Cuneo'),
('EN', 'Enna'),
('FM', 'Fermo'), # active starting from 2009
('FE', 'Ferrara'),
('FI', 'Firenze'),
('FG', 'Foggia'),
('FC', 'Forlì-Cesena'),
('FR', 'Frosinone'),
('GE', 'Genova'),
('GO', 'Gorizia'),
('GR', 'Grosseto'),
('IM', 'Imperia'),
('IS', 'Isernia'),
('SP', 'La Spezia'),
('AQ', 'L’Aquila'),
('LT', 'Latina'),
('LE', 'Lecce'),
('LC', 'Lecco'),
('LI', 'Livorno'),
('LO', 'Lodi'),
('LU', 'Lucca'),
('MC', 'Macerata'),
('MN', 'Mantova'),
('MS', 'Massa-Carrara'),
('MT', 'Matera'),
('VS', 'Medio Campidano'),
('ME', 'Messina'),
('MI', 'Milano'),
('MO', 'Modena'),
('MB', 'Monza e Brianza'), # active starting from 2009
('NA', 'Napoli'),
('NO', 'Novara'),
('NU', 'Nuoro'),
('OG', 'Ogliastra'),
('OT', 'Olbia-Tempio'),
('OR', 'Oristano'),
('PD', 'Padova'),
('PA', 'Palermo'),
('PR', 'Parma'),
('PV', 'Pavia'),
('PG', 'Perugia'),
('PU', 'Pesaro e Urbino'),
('PE', 'Pescara'),
('PC', 'Piacenza'),
('PI', 'Pisa'),
('PT', 'Pistoia'),
('PN', 'Pordenone'),
('PZ', 'Potenza'),
('PO', 'Prato'),
('RG', 'Ragusa'),
('RA', 'Ravenna'),
('RC', 'Reggio Calabria'),
('RE', 'Reggio Emilia'),
('RI', 'Rieti'),
('RN', 'Rimini'),
('RM', 'Roma'),
('RO', 'Rovigo'),
('SA', 'Salerno'),
('SS', 'Sassari'),
('SV', 'Savona'),
('SI', 'Siena'),
('SR', 'Siracusa'),
('SO', 'Sondrio'),
('TA', 'Taranto'),
('TE', 'Teramo'),
('TR', 'Terni'),
('TO', 'Torino'),
('TP', 'Trapani'),
('TN', 'Trento'),
('TV', 'Treviso'),
('TS', 'Trieste'),
('UD', 'Udine'),
('VA', 'Varese'),
('VE', 'Venezia'),
('VB', 'Verbano Cusio Ossola'),
('VC', 'Vercelli'),
('VR', 'Verona'),
('VV', 'Vibo Valentia'),
('VI', 'Vicenza'),
('VT', 'Viterbo'),
)
| lgpl-3.0 | [
3,
1882,
2803,
26,
2774,
13,
24,
446,
10,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
2514,
54,
568,
2089,
63,
16236,
275,
334,
272,
661,
1254,
297,
283,
5676,
322,
2268,
475,
659,
272,
661,
748,
297,
283,
33,
2003,
460,
23714,
659,
272,
661,
879,
297,
283,
2493,
388,
65,
659,
272,
661,
23320,
297,
283,
33,
941,
65,
659,
272,
661,
689,
297,
283,
17683,
4348,
79,
659,
272,
661,
1282,
297,
283,
2822,
331,
317,
510,
530,
287,
79,
659,
272,
661,
619,
297,
283,
33,
270,
73,
659,
272,
661,
6087,
297,
283,
33,
1090,
472,
79,
659,
272,
661,
4134,
297,
283,
34,
759,
659,
272,
661,
19162,
297,
283,
5281,
2723,
502,
13,
3325,
23714,
13,
14612,
73,
659,
327,
4702,
6617,
687,
8937,
272,
661,
7847,
297,
283,
34,
1697,
324,
79,
659,
272,
661,
18273,
297,
283,
34,
6349,
1856,
475,
659,
272,
661,
18998,
297,
283,
34,
19719,
4393,
659,
272,
661,
19419,
297,
283,
34,
14769,
416,
659,
272,
661,
3973,
297,
283,
2208,
320,
784,
65,
659,
272,
661,
21338,
297,
283,
34,
393,
90,
8143,
15,
2208,
5193,
659,
272,
661,
11087,
297,
283,
34,
470,
16521,
659,
272,
661,
7184,
297,
283,
12771,
3558,
338,
659,
272,
661,
3263,
297,
283,
35,
643,
317,
759,
659,
272,
661,
1981,
297,
283,
35,
4478,
7199,
409,
502,
659,
272,
661,
9956,
297,
283,
3630,
311,
2873,
15923,
659,
272,
661,
3553,
297,
283,
35,
31585,
4674,
13,
41,
3845,
338,
305,
659,
272,
661,
2089,
297,
283,
3630,
407,
65,
659,
272,
661,
1028,
297,
283,
35,
16080,
4674,
659,
272,
661,
27808,
297,
283,
35,
16080,
90,
285,
79,
659,
272,
661,
1244,
297,
283,
1049,
1873,
280,
659,
272,
661,
1439,
297,
283,
967,
573,
659,
272,
661,
3298,
297,
283,
967,
2464,
8076,
659,
272,
661,
2944,
297,
283,
5482,
2106,
65,
659,
272,
661,
23063,
297,
283,
35,
4571,
368,
659,
272,
661,
12874,
297,
283,
35,
11474,
79,
659,
272,
661,
742,
297,
283,
1327,
3540,
659,
272,
661,
22367,
297,
283,
38,
281,
573,
659,
327,
4702,
6617,
687,
8937,
272,
661,
5100,
297,
283,
38,
1508,
17956,
659,
272,
661,
1976,
297,
283,
9047,
828,
806,
659,
272,
661,
27453,
297,
283,
38,
24798,
4674,
659,
272,
661,
4161,
297,
283,
1858,
76,
128,
106,
13,
24417,
2464,
65,
659,
272,
661,
5372,
297,
283,
38,
4796,
262,
368,
659,
272,
661,
4962,
297,
283,
8168,
79,
3042,
659,
272,
661,
13160,
297,
283,
39,
5546,
4674,
659,
272,
661,
3975,
297,
283,
39,
4796,
409,
79,
659,
272,
661,
1469,
297,
283,
8499,
281,
4674,
659,
272,
661,
1311,
297,
283,
41,
332,
22042,
659,
272,
661,
5763,
297,
283,
7833,
428,
321,
90,
4674,
659,
272,
661,
20152,
297,
283,
44,
21045,
33,
392,
25330,
659,
272,
661,
17090,
297,
283,
22510,
13765,
659,
272,
661,
906,
297,
283,
44,
825,
301,
659,
272,
661,
7027,
297,
283,
44,
825,
331,
659,
272,
661,
2673,
297,
283,
44,
1003,
269,
889,
659,
272,
661,
1484,
297,
283,
2041,
328,
659,
272,
661,
20237,
297,
283,
44,
947,
696,
659,
272,
661,
7608,
297,
283,
3399,
281,
419,
659,
272,
661,
16237,
297,
283,
2395,
475,
3042,
659,
272,
661,
3053,
297,
283,
27218,
65,
13,
35,
5250,
17956,
659,
272,
661,
5747,
297,
283,
45,
323,
345,
659,
272,
661,
7428,
297,
283,
1352,
3006,
24569,
344,
8143,
659,
272,
661,
3635,
297,
283,
1352,
385,
13765,
659,
272,
661,
10709,
297,
283,
45,
382,
8143,
659,
272,
661,
2679,
297,
283,
1385,
3540,
659,
272,
661,
4567,
297,
283,
6671,
8076,
325,
699,
18429,
8076,
659,
327,
4702,
6617,
687,
8937,
272,
661,
7170,
297,
283,
46,
439,
23711,
659,
272,
661,
2826,
297,
283,
1944,
1391,
65,
659,
272,
661,
1440,
297,
283,
21988,
269,
79,
659,
272,
661,
14008,
297,
283,
47,
71,
317,
1810,
345,
659,
272,
661,
1387,
297,
283,
47,
76,
4492,
65,
13,
6530,
2308,
659,
272,
661,
726,
297,
283,
15736,
270,
8143,
659,
272,
661,
11435,
297,
283,
48,
5129,
3042,
659,
272,
661,
8470,
297,
283,
4232,
1435,
573,
659,
272,
661,
3311,
297,
283,
1262,
391,
659,
272,
661,
24553,
297,
283,
4232,
12897,
659,
272,
661,
11115,
297,
283,
2623,
1518,
4674,
659,
272,
661,
6903,
297,
283,
48,
397,
285,
79,
325,
738,
82,
1393,
79,
659,
272,
661,
1510,
297,
283,
48,
397,
7007,
65,
659,
272,
661,
4222,
297,
283,
10542,
645,
287,
8076,
659,
272,
661,
2252,
297,
283,
48,
13655,
659,
272,
661,
4189,
297,
283,
48,
7133,
4674,
659,
272,
661,
9060,
297,
283,
48,
269,
848,
368,
659,
272,
661,
48,
58,
297,
283,
1575,
724,
8076,
659,
272,
661,
1512,
297,
283,
9779,
11318,
659,
272,
661,
14058,
297,
283,
50,
643,
527,
65,
659,
272,
661,
2847,
297,
283,
50,
15556,
3540,
659,
272,
661,
8205,
297,
283,
497,
2721,
2308,
8256,
371,
23714,
659,
272,
661,
907,
297,
283,
497,
2721,
2308,
662,
77,
1638,
65,
659,
272,
661,
6129,
297,
283,
50,
1873,
280,
659,
272,
661,
15303,
297,
283,
28522,
18000,
659,
272,
661,
11026,
297,
283,
3863,
391,
659,
272,
661,
1092,
297,
283,
3863,
433,
1939,
659,
272,
661,
4251,
297,
283,
12226,
1435,
889,
659,
272,
661,
2300,
297,
283,
51,
405,
759,
659,
272,
661,
4985,
297,
283,
51,
1214,
265,
65,
659,
272,
661,
2684,
297,
283,
18934,
287,
65,
659,
272,
661,
5943,
297,
283,
18934,
6457,
527,
65,
659,
272,
661,
4118,
297,
283,
51,
7835,
322,
79,
659,
272,
661,
6166,
297,
283,
24818,
290,
475,
659,
272,
661,
3727,
297,
283,
8600,
4393,
659,
272,
661,
1766,
297,
283,
8600,
8445,
659,
272,
661,
2566,
297,
283,
20994,
10175,
659,
272,
661,
6495,
297,
283,
52,
1330,
26455,
659,
272,
661,
52,
46,
297,
283,
52,
640,
79,
659,
272,
661,
12764,
297,
283,
52,
4964,
4595,
659,
272,
661,
9730,
297,
283,
52,
1996,
266,
659,
272,
661,
3383,
297,
283,
53,
68,
1132
] | [
1882,
2803,
26,
2774,
13,
24,
446,
10,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
2514,
54,
568,
2089,
63,
16236,
275,
334,
272,
661,
1254,
297,
283,
5676,
322,
2268,
475,
659,
272,
661,
748,
297,
283,
33,
2003,
460,
23714,
659,
272,
661,
879,
297,
283,
2493,
388,
65,
659,
272,
661,
23320,
297,
283,
33,
941,
65,
659,
272,
661,
689,
297,
283,
17683,
4348,
79,
659,
272,
661,
1282,
297,
283,
2822,
331,
317,
510,
530,
287,
79,
659,
272,
661,
619,
297,
283,
33,
270,
73,
659,
272,
661,
6087,
297,
283,
33,
1090,
472,
79,
659,
272,
661,
4134,
297,
283,
34,
759,
659,
272,
661,
19162,
297,
283,
5281,
2723,
502,
13,
3325,
23714,
13,
14612,
73,
659,
327,
4702,
6617,
687,
8937,
272,
661,
7847,
297,
283,
34,
1697,
324,
79,
659,
272,
661,
18273,
297,
283,
34,
6349,
1856,
475,
659,
272,
661,
18998,
297,
283,
34,
19719,
4393,
659,
272,
661,
19419,
297,
283,
34,
14769,
416,
659,
272,
661,
3973,
297,
283,
2208,
320,
784,
65,
659,
272,
661,
21338,
297,
283,
34,
393,
90,
8143,
15,
2208,
5193,
659,
272,
661,
11087,
297,
283,
34,
470,
16521,
659,
272,
661,
7184,
297,
283,
12771,
3558,
338,
659,
272,
661,
3263,
297,
283,
35,
643,
317,
759,
659,
272,
661,
1981,
297,
283,
35,
4478,
7199,
409,
502,
659,
272,
661,
9956,
297,
283,
3630,
311,
2873,
15923,
659,
272,
661,
3553,
297,
283,
35,
31585,
4674,
13,
41,
3845,
338,
305,
659,
272,
661,
2089,
297,
283,
3630,
407,
65,
659,
272,
661,
1028,
297,
283,
35,
16080,
4674,
659,
272,
661,
27808,
297,
283,
35,
16080,
90,
285,
79,
659,
272,
661,
1244,
297,
283,
1049,
1873,
280,
659,
272,
661,
1439,
297,
283,
967,
573,
659,
272,
661,
3298,
297,
283,
967,
2464,
8076,
659,
272,
661,
2944,
297,
283,
5482,
2106,
65,
659,
272,
661,
23063,
297,
283,
35,
4571,
368,
659,
272,
661,
12874,
297,
283,
35,
11474,
79,
659,
272,
661,
742,
297,
283,
1327,
3540,
659,
272,
661,
22367,
297,
283,
38,
281,
573,
659,
327,
4702,
6617,
687,
8937,
272,
661,
5100,
297,
283,
38,
1508,
17956,
659,
272,
661,
1976,
297,
283,
9047,
828,
806,
659,
272,
661,
27453,
297,
283,
38,
24798,
4674,
659,
272,
661,
4161,
297,
283,
1858,
76,
128,
106,
13,
24417,
2464,
65,
659,
272,
661,
5372,
297,
283,
38,
4796,
262,
368,
659,
272,
661,
4962,
297,
283,
8168,
79,
3042,
659,
272,
661,
13160,
297,
283,
39,
5546,
4674,
659,
272,
661,
3975,
297,
283,
39,
4796,
409,
79,
659,
272,
661,
1469,
297,
283,
8499,
281,
4674,
659,
272,
661,
1311,
297,
283,
41,
332,
22042,
659,
272,
661,
5763,
297,
283,
7833,
428,
321,
90,
4674,
659,
272,
661,
20152,
297,
283,
44,
21045,
33,
392,
25330,
659,
272,
661,
17090,
297,
283,
22510,
13765,
659,
272,
661,
906,
297,
283,
44,
825,
301,
659,
272,
661,
7027,
297,
283,
44,
825,
331,
659,
272,
661,
2673,
297,
283,
44,
1003,
269,
889,
659,
272,
661,
1484,
297,
283,
2041,
328,
659,
272,
661,
20237,
297,
283,
44,
947,
696,
659,
272,
661,
7608,
297,
283,
3399,
281,
419,
659,
272,
661,
16237,
297,
283,
2395,
475,
3042,
659,
272,
661,
3053,
297,
283,
27218,
65,
13,
35,
5250,
17956,
659,
272,
661,
5747,
297,
283,
45,
323,
345,
659,
272,
661,
7428,
297,
283,
1352,
3006,
24569,
344,
8143,
659,
272,
661,
3635,
297,
283,
1352,
385,
13765,
659,
272,
661,
10709,
297,
283,
45,
382,
8143,
659,
272,
661,
2679,
297,
283,
1385,
3540,
659,
272,
661,
4567,
297,
283,
6671,
8076,
325,
699,
18429,
8076,
659,
327,
4702,
6617,
687,
8937,
272,
661,
7170,
297,
283,
46,
439,
23711,
659,
272,
661,
2826,
297,
283,
1944,
1391,
65,
659,
272,
661,
1440,
297,
283,
21988,
269,
79,
659,
272,
661,
14008,
297,
283,
47,
71,
317,
1810,
345,
659,
272,
661,
1387,
297,
283,
47,
76,
4492,
65,
13,
6530,
2308,
659,
272,
661,
726,
297,
283,
15736,
270,
8143,
659,
272,
661,
11435,
297,
283,
48,
5129,
3042,
659,
272,
661,
8470,
297,
283,
4232,
1435,
573,
659,
272,
661,
3311,
297,
283,
1262,
391,
659,
272,
661,
24553,
297,
283,
4232,
12897,
659,
272,
661,
11115,
297,
283,
2623,
1518,
4674,
659,
272,
661,
6903,
297,
283,
48,
397,
285,
79,
325,
738,
82,
1393,
79,
659,
272,
661,
1510,
297,
283,
48,
397,
7007,
65,
659,
272,
661,
4222,
297,
283,
10542,
645,
287,
8076,
659,
272,
661,
2252,
297,
283,
48,
13655,
659,
272,
661,
4189,
297,
283,
48,
7133,
4674,
659,
272,
661,
9060,
297,
283,
48,
269,
848,
368,
659,
272,
661,
48,
58,
297,
283,
1575,
724,
8076,
659,
272,
661,
1512,
297,
283,
9779,
11318,
659,
272,
661,
14058,
297,
283,
50,
643,
527,
65,
659,
272,
661,
2847,
297,
283,
50,
15556,
3540,
659,
272,
661,
8205,
297,
283,
497,
2721,
2308,
8256,
371,
23714,
659,
272,
661,
907,
297,
283,
497,
2721,
2308,
662,
77,
1638,
65,
659,
272,
661,
6129,
297,
283,
50,
1873,
280,
659,
272,
661,
15303,
297,
283,
28522,
18000,
659,
272,
661,
11026,
297,
283,
3863,
391,
659,
272,
661,
1092,
297,
283,
3863,
433,
1939,
659,
272,
661,
4251,
297,
283,
12226,
1435,
889,
659,
272,
661,
2300,
297,
283,
51,
405,
759,
659,
272,
661,
4985,
297,
283,
51,
1214,
265,
65,
659,
272,
661,
2684,
297,
283,
18934,
287,
65,
659,
272,
661,
5943,
297,
283,
18934,
6457,
527,
65,
659,
272,
661,
4118,
297,
283,
51,
7835,
322,
79,
659,
272,
661,
6166,
297,
283,
24818,
290,
475,
659,
272,
661,
3727,
297,
283,
8600,
4393,
659,
272,
661,
1766,
297,
283,
8600,
8445,
659,
272,
661,
2566,
297,
283,
20994,
10175,
659,
272,
661,
6495,
297,
283,
52,
1330,
26455,
659,
272,
661,
52,
46,
297,
283,
52,
640,
79,
659,
272,
661,
12764,
297,
283,
52,
4964,
4595,
659,
272,
661,
9730,
297,
283,
52,
1996,
266,
659,
272,
661,
3383,
297,
283,
53,
68,
1132,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
AnhellO/DAS_Sistemas | Ago-Dic-2017/Enrique Castillo/Ordinario/test/Lib/site-packages/django/contrib/gis/management/commands/ogrinspect.py | 20 | 5848 | import argparse
from django.contrib.gis import gdal
from django.core.management.base import BaseCommand, CommandError
from django.utils.inspect import get_func_args
class LayerOptionAction(argparse.Action):
"""
Custom argparse action for the `ogrinspect` `layer_key` keyword option
which may be an integer or a string.
"""
def __call__(self, parser, namespace, value, option_string=None):
try:
setattr(namespace, self.dest, int(value))
except ValueError:
setattr(namespace, self.dest, value)
class ListOptionAction(argparse.Action):
"""
Custom argparse action for `ogrinspect` keywords that require
a string list. If the string is 'True'/'true' then the option
value will be a boolean instead.
"""
def __call__(self, parser, namespace, value, option_string=None):
if value.lower() == 'true':
setattr(namespace, self.dest, True)
else:
setattr(namespace, self.dest, value.split(','))
class Command(BaseCommand):
help = (
'Inspects the given OGR-compatible data source (e.g., a shapefile) and outputs\n'
'a GeoDjango model with the given model name. For example:\n'
' ./manage.py ogrinspect zipcode.shp Zipcode'
)
requires_system_checks = False
def add_arguments(self, parser):
parser.add_argument('data_source', help='Path to the data source.')
parser.add_argument('model_name', help='Name of the model to create.')
parser.add_argument(
'--blank', dest='blank',
action=ListOptionAction, default=False,
help='Use a comma separated list of OGR field names to add '
'the `blank=True` option to the field definition. Set to `true` '
'to apply to all applicable fields.',
)
parser.add_argument(
'--decimal', dest='decimal',
action=ListOptionAction, default=False,
help='Use a comma separated list of OGR float fields to '
'generate `DecimalField` instead of the default '
'`FloatField`. Set to `true` to apply to all OGR float fields.',
)
parser.add_argument(
'--geom-name', dest='geom_name', default='geom',
help='Specifies the model name for the Geometry Field (defaults to `geom`)'
)
parser.add_argument(
'--layer', dest='layer_key',
action=LayerOptionAction, default=0,
help='The key for specifying which layer in the OGR data '
'source to use. Defaults to 0 (the first layer). May be '
'an integer or a string identifier for the layer.',
)
parser.add_argument(
'--multi-geom', action='store_true', dest='multi_geom',
help='Treat the geometry in the data source as a geometry collection.',
)
parser.add_argument(
'--name-field', dest='name_field',
help='Specifies a field name to return for the __str__() method.',
)
parser.add_argument(
'--no-imports', action='store_false', dest='imports',
help='Do not include `from django.contrib.gis.db import models` statement.',
)
parser.add_argument(
'--null', dest='null', action=ListOptionAction, default=False,
help='Use a comma separated list of OGR field names to add '
'the `null=True` option to the field definition. Set to `true` '
'to apply to all applicable fields.',
)
parser.add_argument(
'--srid', dest='srid',
help='The SRID to use for the Geometry Field. If it can be '
'determined, the SRID of the data source is used.',
)
parser.add_argument(
'--mapping', action='store_true', dest='mapping',
help='Generate mapping dictionary for use with `LayerMapping`.',
)
def handle(self, *args, **options):
data_source, model_name = options.pop('data_source'), options.pop('model_name')
# Getting the OGR DataSource from the string parameter.
try:
ds = gdal.DataSource(data_source)
except gdal.GDALException as msg:
raise CommandError(msg)
# Returning the output of ogrinspect with the given arguments
# and options.
from django.contrib.gis.utils.ogrinspect import _ogrinspect, mapping
# Filter options to params accepted by `_ogrinspect`
ogr_options = {k: v for k, v in options.items()
if k in get_func_args(_ogrinspect) and v is not None}
output = [s for s in _ogrinspect(ds, model_name, **ogr_options)]
if options['mapping']:
# Constructing the keyword arguments for `mapping`, and
# calling it on the data source.
kwargs = {
'geom_name': options['geom_name'],
'layer_key': options['layer_key'],
'multi_geom': options['multi_geom'],
}
mapping_dict = mapping(ds, **kwargs)
# This extra legwork is so that the dictionary definition comes
# out in the same order as the fields in the model definition.
rev_mapping = {v: k for k, v in mapping_dict.items()}
output.extend(['', '', '# Auto-generated `LayerMapping` dictionary for %s model' % model_name,
'%s_mapping = {' % model_name.lower()])
output.extend(" '%s': '%s'," % (
rev_mapping[ogr_fld], ogr_fld) for ogr_fld in ds[options['layer_key']].fields
)
output.extend([" '%s': '%s'," % (options['geom_name'], mapping_dict[options['geom_name']]), '}'])
return '\n'.join(output) + '\n'
| mit | [
646,
7534,
199,
199,
504,
1639,
14,
2828,
14,
5668,
492,
15834,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
504,
1639,
14,
1208,
14,
10955,
492,
664,
63,
1532,
63,
589,
421,
199,
533,
11915,
2602,
3310,
8,
18978,
14,
3310,
304,
272,
408,
272,
8388,
7534,
1595,
367,
314,
658,
14945,
10955,
64,
658,
1897,
63,
498,
64,
4252,
945,
272,
1314,
1443,
506,
376,
3000,
503,
282,
1059,
14,
272,
408,
272,
347,
636,
1250,
721,
277,
12,
1798,
12,
3231,
12,
574,
12,
945,
63,
875,
29,
403,
304,
267,
862,
26,
288,
5371,
8,
3251,
12,
291,
14,
2614,
12,
1109,
8,
585,
430,
267,
871,
1722,
26,
288,
5371,
8,
3251,
12,
291,
14,
2614,
12,
574,
9,
421,
199,
533,
3820,
2602,
3310,
8,
18978,
14,
3310,
304,
272,
408,
272,
8388,
7534,
1595,
367,
658,
14945,
10955,
64,
7681,
626,
4409,
272,
282,
1059,
769,
14,
982,
314,
1059,
365,
283,
549,
29957,
2052,
7,
2066,
314,
945,
272,
574,
911,
506,
282,
5046,
3140,
14,
272,
408,
272,
347,
636,
1250,
721,
277,
12,
1798,
12,
3231,
12,
574,
12,
945,
63,
875,
29,
403,
304,
267,
340,
574,
14,
2325,
342,
508,
283,
2052,
356,
288,
5371,
8,
3251,
12,
291,
14,
2614,
12,
715,
9,
267,
587,
26,
288,
5371,
8,
3251,
12,
291,
14,
2614,
12,
574,
14,
1294,
5102,
1333,
421,
199,
533,
5817,
8,
25150,
304,
272,
1720,
275,
334,
267,
283,
13962,
1764,
83,
314,
1627,
10904,
13,
6490,
666,
1350,
334,
69,
14,
71,
2020,
282,
2215,
493,
9,
436,
4704,
60,
78,
7,
267,
283,
65,
8875,
9323,
1402,
543,
314,
1627,
1402,
536,
14,
2104,
2893,
3427,
78,
7,
267,
283,
16605,
9053,
14,
647,
20713,
10955,
3482,
600,
14,
17299,
16688,
600,
7,
272,
776,
339,
5074,
63,
2253,
63,
8625,
275,
756,
339,
347,
1050,
63,
4958,
8,
277,
12,
1798,
304,
267,
1798,
14,
525,
63,
2094,
360,
576,
63,
1365,
297,
1720,
534,
2042,
370,
314,
666,
1350,
2659,
267,
1798,
14,
525,
63,
2094,
360,
1238,
63,
354,
297,
1720,
534,
985,
402,
314,
1402,
370,
1218,
2659,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
2500,
297,
2053,
534,
2500,
297,
288,
1595,
29,
1296,
2602,
3310,
12,
849,
29,
797,
12,
288,
1720,
534,
6119,
282,
10029,
11673,
769,
402,
10904,
901,
1561,
370,
1050,
283,
326,
283,
1589,
658,
2500,
29,
549,
64,
945,
370,
314,
901,
5492,
14,
2494,
370,
658,
2052,
64,
283,
326,
283,
475,
4838,
370,
1006,
3964,
1504,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
6355,
297,
2053,
534,
6355,
297,
288,
1595,
29,
1296,
2602,
3310,
12,
849,
29,
797,
12,
288,
1720,
534,
6119,
282,
10029,
11673,
769,
402,
10904,
2069,
1504,
370,
283,
326,
283,
4208,
658,
15975,
64,
3140,
402,
314,
849,
283,
326,
26144,
13019,
2313,
2494,
370,
658,
2052,
64,
370,
4838,
370,
1006,
10904,
2069,
1504,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
6481,
13,
354,
297,
2053,
534,
6481,
63,
354,
297,
849,
534,
6481,
297,
288,
1720,
534,
6154,
5604,
314,
1402,
536,
367,
314,
10579,
5024,
334,
4322,
370,
658,
6481,
64,
3171,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
1897,
297,
2053,
534,
1897,
63,
498,
297,
288,
1595,
29,
5003,
2602,
3310,
12,
849,
29,
16,
12,
288,
1720,
534,
1918,
790,
367,
9176,
1314,
4045,
315,
314,
10904,
666,
283,
326,
283,
1365,
370,
675,
14,
7827,
370,
378,
334,
1589,
1642,
4045,
680,
10162,
506,
283,
326,
283,
290,
3000,
503,
282,
1059,
5148,
367,
314,
4045,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
3029,
13,
6481,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
3029,
63,
6481,
297,
288,
1720,
534,
29442,
314,
3400,
315,
314,
666,
1350,
465,
282,
3400,
3245,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
354,
13,
698,
297,
2053,
534,
354,
63,
698,
297,
288,
1720,
534,
6154,
5604,
282,
901,
536,
370,
372,
367,
314,
636,
495,
4533,
1083,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
889,
13,
12775,
297,
1595,
534,
1617,
63,
3910,
297,
2053,
534,
12775,
297,
288,
1720,
534,
2585,
440,
2387,
658,
504,
1639,
14,
2828,
14,
5668,
14,
697,
492,
1709,
64,
5164,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
2307,
297,
2053,
534,
2307,
297,
1595,
29,
1296,
2602,
3310,
12,
849,
29,
797,
12,
288,
1720,
534,
6119,
282,
10029,
11673,
769,
402,
10904,
901,
1561,
370,
1050,
283,
326,
283,
1589,
658,
2307,
29,
549,
64,
945,
370,
314,
901,
5492,
14,
2494,
370,
658,
2052,
64,
283,
326,
283,
475,
4838,
370,
1006,
3964,
1504,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
10498,
297,
2053,
534,
10498,
297,
288,
1720,
534,
1918,
22425,
370,
675,
367,
314,
10579,
5024,
14,
982,
652,
883,
506,
283,
326,
283,
27248,
12,
314,
22425,
402,
314,
666,
1350,
365,
1202,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
4745,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
4745,
297,
288,
1720,
534,
6864,
4412,
2600,
367,
675,
543,
658,
5003,
7674,
2313,
297,
267,
776,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
666,
63,
1365,
12,
1402,
63,
354,
275,
1511,
14,
1935,
360,
576,
63,
1365,
659,
1511,
14,
1935,
360,
1238,
63,
354,
358,
398,
327,
20703,
314,
10904,
24300,
687,
314,
1059,
2725,
14,
267,
862,
26,
288,
6364,
275,
15834,
14,
16693,
8,
576,
63,
1365,
9,
267,
871,
15834,
14,
17835,
1726,
465,
1499,
26,
288,
746,
14393,
8,
1328,
9,
398,
327,
1432,
316,
314,
1072,
402,
20713,
10955,
543,
314,
1627,
2368,
267,
327,
436,
1511,
14,
267,
687,
1639,
14,
2828,
14,
5668,
14,
1208,
14,
14945,
10955,
492,
485,
14945,
10955,
12,
4412,
267,
327,
9388,
1511,
370
] | [
7534,
199,
199,
504,
1639,
14,
2828,
14,
5668,
492,
15834,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
504,
1639,
14,
1208,
14,
10955,
492,
664,
63,
1532,
63,
589,
421,
199,
533,
11915,
2602,
3310,
8,
18978,
14,
3310,
304,
272,
408,
272,
8388,
7534,
1595,
367,
314,
658,
14945,
10955,
64,
658,
1897,
63,
498,
64,
4252,
945,
272,
1314,
1443,
506,
376,
3000,
503,
282,
1059,
14,
272,
408,
272,
347,
636,
1250,
721,
277,
12,
1798,
12,
3231,
12,
574,
12,
945,
63,
875,
29,
403,
304,
267,
862,
26,
288,
5371,
8,
3251,
12,
291,
14,
2614,
12,
1109,
8,
585,
430,
267,
871,
1722,
26,
288,
5371,
8,
3251,
12,
291,
14,
2614,
12,
574,
9,
421,
199,
533,
3820,
2602,
3310,
8,
18978,
14,
3310,
304,
272,
408,
272,
8388,
7534,
1595,
367,
658,
14945,
10955,
64,
7681,
626,
4409,
272,
282,
1059,
769,
14,
982,
314,
1059,
365,
283,
549,
29957,
2052,
7,
2066,
314,
945,
272,
574,
911,
506,
282,
5046,
3140,
14,
272,
408,
272,
347,
636,
1250,
721,
277,
12,
1798,
12,
3231,
12,
574,
12,
945,
63,
875,
29,
403,
304,
267,
340,
574,
14,
2325,
342,
508,
283,
2052,
356,
288,
5371,
8,
3251,
12,
291,
14,
2614,
12,
715,
9,
267,
587,
26,
288,
5371,
8,
3251,
12,
291,
14,
2614,
12,
574,
14,
1294,
5102,
1333,
421,
199,
533,
5817,
8,
25150,
304,
272,
1720,
275,
334,
267,
283,
13962,
1764,
83,
314,
1627,
10904,
13,
6490,
666,
1350,
334,
69,
14,
71,
2020,
282,
2215,
493,
9,
436,
4704,
60,
78,
7,
267,
283,
65,
8875,
9323,
1402,
543,
314,
1627,
1402,
536,
14,
2104,
2893,
3427,
78,
7,
267,
283,
16605,
9053,
14,
647,
20713,
10955,
3482,
600,
14,
17299,
16688,
600,
7,
272,
776,
339,
5074,
63,
2253,
63,
8625,
275,
756,
339,
347,
1050,
63,
4958,
8,
277,
12,
1798,
304,
267,
1798,
14,
525,
63,
2094,
360,
576,
63,
1365,
297,
1720,
534,
2042,
370,
314,
666,
1350,
2659,
267,
1798,
14,
525,
63,
2094,
360,
1238,
63,
354,
297,
1720,
534,
985,
402,
314,
1402,
370,
1218,
2659,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
2500,
297,
2053,
534,
2500,
297,
288,
1595,
29,
1296,
2602,
3310,
12,
849,
29,
797,
12,
288,
1720,
534,
6119,
282,
10029,
11673,
769,
402,
10904,
901,
1561,
370,
1050,
283,
326,
283,
1589,
658,
2500,
29,
549,
64,
945,
370,
314,
901,
5492,
14,
2494,
370,
658,
2052,
64,
283,
326,
283,
475,
4838,
370,
1006,
3964,
1504,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
6355,
297,
2053,
534,
6355,
297,
288,
1595,
29,
1296,
2602,
3310,
12,
849,
29,
797,
12,
288,
1720,
534,
6119,
282,
10029,
11673,
769,
402,
10904,
2069,
1504,
370,
283,
326,
283,
4208,
658,
15975,
64,
3140,
402,
314,
849,
283,
326,
26144,
13019,
2313,
2494,
370,
658,
2052,
64,
370,
4838,
370,
1006,
10904,
2069,
1504,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
6481,
13,
354,
297,
2053,
534,
6481,
63,
354,
297,
849,
534,
6481,
297,
288,
1720,
534,
6154,
5604,
314,
1402,
536,
367,
314,
10579,
5024,
334,
4322,
370,
658,
6481,
64,
3171,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
1897,
297,
2053,
534,
1897,
63,
498,
297,
288,
1595,
29,
5003,
2602,
3310,
12,
849,
29,
16,
12,
288,
1720,
534,
1918,
790,
367,
9176,
1314,
4045,
315,
314,
10904,
666,
283,
326,
283,
1365,
370,
675,
14,
7827,
370,
378,
334,
1589,
1642,
4045,
680,
10162,
506,
283,
326,
283,
290,
3000,
503,
282,
1059,
5148,
367,
314,
4045,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
3029,
13,
6481,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
3029,
63,
6481,
297,
288,
1720,
534,
29442,
314,
3400,
315,
314,
666,
1350,
465,
282,
3400,
3245,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
354,
13,
698,
297,
2053,
534,
354,
63,
698,
297,
288,
1720,
534,
6154,
5604,
282,
901,
536,
370,
372,
367,
314,
636,
495,
4533,
1083,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
889,
13,
12775,
297,
1595,
534,
1617,
63,
3910,
297,
2053,
534,
12775,
297,
288,
1720,
534,
2585,
440,
2387,
658,
504,
1639,
14,
2828,
14,
5668,
14,
697,
492,
1709,
64,
5164,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
2307,
297,
2053,
534,
2307,
297,
1595,
29,
1296,
2602,
3310,
12,
849,
29,
797,
12,
288,
1720,
534,
6119,
282,
10029,
11673,
769,
402,
10904,
901,
1561,
370,
1050,
283,
326,
283,
1589,
658,
2307,
29,
549,
64,
945,
370,
314,
901,
5492,
14,
2494,
370,
658,
2052,
64,
283,
326,
283,
475,
4838,
370,
1006,
3964,
1504,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
10498,
297,
2053,
534,
10498,
297,
288,
1720,
534,
1918,
22425,
370,
675,
367,
314,
10579,
5024,
14,
982,
652,
883,
506,
283,
326,
283,
27248,
12,
314,
22425,
402,
314,
666,
1350,
365,
1202,
3130,
267,
776,
267,
1798,
14,
525,
63,
2094,
8,
288,
2850,
4745,
297,
1595,
534,
1617,
63,
2052,
297,
2053,
534,
4745,
297,
288,
1720,
534,
6864,
4412,
2600,
367,
675,
543,
658,
5003,
7674,
2313,
297,
267,
776,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
267,
666,
63,
1365,
12,
1402,
63,
354,
275,
1511,
14,
1935,
360,
576,
63,
1365,
659,
1511,
14,
1935,
360,
1238,
63,
354,
358,
398,
327,
20703,
314,
10904,
24300,
687,
314,
1059,
2725,
14,
267,
862,
26,
288,
6364,
275,
15834,
14,
16693,
8,
576,
63,
1365,
9,
267,
871,
15834,
14,
17835,
1726,
465,
1499,
26,
288,
746,
14393,
8,
1328,
9,
398,
327,
1432,
316,
314,
1072,
402,
20713,
10955,
543,
314,
1627,
2368,
267,
327,
436,
1511,
14,
267,
687,
1639,
14,
2828,
14,
5668,
14,
1208,
14,
14945,
10955,
492,
485,
14945,
10955,
12,
4412,
267,
327,
9388,
1511,
370,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
almeidapaulopt/erpnext | erpnext/accounts/report/share_balance/share_balance.py | 19 | 1475 | # Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
# For license information, please see license.txt
from __future__ import unicode_literals
import frappe
from frappe import msgprint, _
def execute(filters=None):
if not filters: filters = {}
if not filters.get("date"):
frappe.throw(_("Please select date"))
columns = get_columns(filters)
date = filters.get("date")
data = []
if not filters.get("shareholder"):
pass
else:
share_type, no_of_shares, rate, amount = 1, 2, 3, 4
all_shares = get_all_shares(filters.get("shareholder"))
for share_entry in all_shares:
row = False
for datum in data:
if datum[share_type] == share_entry.share_type:
datum[no_of_shares] += share_entry.no_of_shares
datum[amount] += share_entry.amount
if datum[no_of_shares] == 0:
datum[rate] = 0
else:
datum[rate] = datum[amount] / datum[no_of_shares]
row = True
break
# new entry
if not row:
row = [filters.get("shareholder"),
share_entry.share_type, share_entry.no_of_shares, share_entry.rate, share_entry.amount]
data.append(row)
return columns, data
def get_columns(filters):
columns = [
_("Shareholder") + ":Link/Shareholder:150",
_("Share Type") + "::90",
_("No of Shares") + "::90",
_("Average Rate") + ":Currency:90",
_("Amount") + ":Currency:90"
]
return columns
def get_all_shares(shareholder):
return frappe.get_doc('Shareholder', shareholder).share_balance
| gpl-3.0 | [
3,
1898,
334,
67,
9,
6171,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
8417,
199,
3,
2104,
4190,
2556,
12,
8749,
1937,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
492,
1499,
1361,
12,
485,
199,
199,
318,
5341,
8,
4273,
29,
403,
304,
199,
198,
692,
440,
4766,
26,
4766,
275,
1052,
421,
198,
692,
440,
4766,
14,
362,
480,
602,
2349,
507,
198,
9098,
14,
11964,
6115,
8254,
3504,
1434,
2237,
421,
198,
3406,
275,
664,
63,
3406,
8,
4273,
9,
421,
198,
602,
275,
4766,
14,
362,
480,
602,
531,
421,
198,
576,
275,
942,
421,
198,
692,
440,
4766,
14,
362,
480,
6251,
4302,
2349,
507,
198,
1529,
199,
198,
2836,
26,
507,
198,
6251,
63,
466,
12,
949,
63,
1618,
63,
18318,
12,
6634,
12,
5982,
275,
413,
12,
499,
12,
650,
12,
841,
2742,
198,
452,
63,
18318,
275,
664,
63,
452,
63,
18318,
8,
4273,
14,
362,
480,
6251,
4302,
2237,
507,
198,
509,
8663,
63,
2373,
315,
1006,
63,
18318,
26,
686,
198,
1143,
275,
756,
686,
198,
509,
18908,
315,
666,
26,
1585,
198,
692,
18908,
59,
6251,
63,
466,
61,
508,
8663,
63,
2373,
14,
6251,
63,
466,
26,
1871,
198,
18945,
59,
889,
63,
1618,
63,
18318,
61,
847,
8663,
63,
2373,
14,
889,
63,
1618,
63,
18318,
1871,
198,
18945,
59,
4606,
61,
847,
8663,
63,
2373,
14,
4606,
1871,
198,
692,
18908,
59,
889,
63,
1618,
63,
18318,
61,
508,
378,
26,
4671,
198,
18945,
59,
1866,
61,
275,
378,
1871,
198,
2836,
26,
4671,
198,
18945,
59,
1866,
61,
275,
18908,
59,
4606,
61,
1182,
18908,
59,
889,
63,
1618,
63,
18318,
61,
1871,
198,
1143,
275,
715,
1871,
198,
4785,
686,
198,
3,
892,
2397,
686,
198,
692,
440,
1962,
26,
1585,
198,
1143,
275,
359,
4273,
14,
362,
480,
6251,
4302,
1288,
1871,
198,
6251,
63,
2373,
14,
6251,
63,
466,
12,
8663,
63,
2373,
14,
889,
63,
1618,
63,
18318,
12,
8663,
63,
2373,
14,
1866,
12,
8663,
63,
2373,
14,
4606,
61,
16737,
198,
576,
14,
740,
8,
1143,
9,
421,
198,
1107,
4362,
12,
666,
199,
199,
318,
664,
63,
3406,
8,
4273,
304,
199,
198,
3406,
275,
359,
507,
198,
14332,
18713,
4302,
531,
435,
7244,
3834,
15,
18713,
4302,
26,
8251,
401,
507,
198,
14332,
18713,
2434,
531,
435,
27472,
2710,
401,
507,
198,
14332,
1944,
402,
428,
2411,
470,
531,
435,
27472,
2710,
401,
507,
198,
14332,
17400,
26311,
531,
435,
7244,
19567,
26,
2710,
401,
507,
198,
14332,
18785,
531,
435,
7244,
19567,
26,
2710,
2,
199,
198,
61,
199,
198,
1107,
4362,
199,
199,
318,
664,
63,
452,
63,
18318,
8,
6251,
4302,
304,
199,
198,
1107,
6950,
14,
362,
63,
1301,
360,
18713,
4302,
297,
8663,
4302,
680,
6251,
63,
7358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6171,
12,
481,
5034,
19215,
29053,
14,
12126,
14,
436,
8417,
199,
3,
2104,
4190,
2556,
12,
8749,
1937,
4190,
14,
2424,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
492,
1499,
1361,
12,
485,
199,
199,
318,
5341,
8,
4273,
29,
403,
304,
199,
198,
692,
440,
4766,
26,
4766,
275,
1052,
421,
198,
692,
440,
4766,
14,
362,
480,
602,
2349,
507,
198,
9098,
14,
11964,
6115,
8254,
3504,
1434,
2237,
421,
198,
3406,
275,
664,
63,
3406,
8,
4273,
9,
421,
198,
602,
275,
4766,
14,
362,
480,
602,
531,
421,
198,
576,
275,
942,
421,
198,
692,
440,
4766,
14,
362,
480,
6251,
4302,
2349,
507,
198,
1529,
199,
198,
2836,
26,
507,
198,
6251,
63,
466,
12,
949,
63,
1618,
63,
18318,
12,
6634,
12,
5982,
275,
413,
12,
499,
12,
650,
12,
841,
2742,
198,
452,
63,
18318,
275,
664,
63,
452,
63,
18318,
8,
4273,
14,
362,
480,
6251,
4302,
2237,
507,
198,
509,
8663,
63,
2373,
315,
1006,
63,
18318,
26,
686,
198,
1143,
275,
756,
686,
198,
509,
18908,
315,
666,
26,
1585,
198,
692,
18908,
59,
6251,
63,
466,
61,
508,
8663,
63,
2373,
14,
6251,
63,
466,
26,
1871,
198,
18945,
59,
889,
63,
1618,
63,
18318,
61,
847,
8663,
63,
2373,
14,
889,
63,
1618,
63,
18318,
1871,
198,
18945,
59,
4606,
61,
847,
8663,
63,
2373,
14,
4606,
1871,
198,
692,
18908,
59,
889,
63,
1618,
63,
18318,
61,
508,
378,
26,
4671,
198,
18945,
59,
1866,
61,
275,
378,
1871,
198,
2836,
26,
4671,
198,
18945,
59,
1866,
61,
275,
18908,
59,
4606,
61,
1182,
18908,
59,
889,
63,
1618,
63,
18318,
61,
1871,
198,
1143,
275,
715,
1871,
198,
4785,
686,
198,
3,
892,
2397,
686,
198,
692,
440,
1962,
26,
1585,
198,
1143,
275,
359,
4273,
14,
362,
480,
6251,
4302,
1288,
1871,
198,
6251,
63,
2373,
14,
6251,
63,
466,
12,
8663,
63,
2373,
14,
889,
63,
1618,
63,
18318,
12,
8663,
63,
2373,
14,
1866,
12,
8663,
63,
2373,
14,
4606,
61,
16737,
198,
576,
14,
740,
8,
1143,
9,
421,
198,
1107,
4362,
12,
666,
199,
199,
318,
664,
63,
3406,
8,
4273,
304,
199,
198,
3406,
275,
359,
507,
198,
14332,
18713,
4302,
531,
435,
7244,
3834,
15,
18713,
4302,
26,
8251,
401,
507,
198,
14332,
18713,
2434,
531,
435,
27472,
2710,
401,
507,
198,
14332,
1944,
402,
428,
2411,
470,
531,
435,
27472,
2710,
401,
507,
198,
14332,
17400,
26311,
531,
435,
7244,
19567,
26,
2710,
401,
507,
198,
14332,
18785,
531,
435,
7244,
19567,
26,
2710,
2,
199,
198,
61,
199,
198,
1107,
4362,
199,
199,
318,
664,
63,
452,
63,
18318,
8,
6251,
4302,
304,
199,
198,
1107,
6950,
14,
362,
63,
1301,
360,
18713,
4302,
297,
8663,
4302,
680,
6251,
63,
7358,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
zhuwenping/python-for-android | python-modules/twisted/twisted/internet/test/test_qtreactor.py | 59 | 1108 | # Copyright (c) 2009 Twisted Matrix Laboratories.
# See LICENSE for details.
import sys
from twisted.trial import unittest
from twisted.python.runtime import platform
from twisted.python.util import sibpath
from twisted.internet.utils import getProcessOutputAndValue
skipWindowsNopywin32 = None
if platform.isWindows():
try:
import win32process
except ImportError:
skipWindowsNopywin32 = ("On windows, spawnProcess is not available "
"in the absence of win32process.")
class QtreactorTestCase(unittest.TestCase):
"""
Tests for L{twisted.internet.qtreactor}.
"""
def test_importQtreactor(self):
"""
Attempting to import L{twisted.internet.qtreactor} should raise an
C{ImportError} indicating that C{qtreactor} is no longer a part of
Twisted.
"""
sys.modules["qtreactor"] = None
from twisted.plugins.twisted_qtstub import errorMessage
try:
import twisted.internet.qtreactor
except ImportError, e:
self.assertEquals(str(e), errorMessage)
| apache-2.0 | [
3,
1898,
334,
67,
9,
8937,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
646,
984,
199,
199,
504,
7390,
14,
14443,
492,
2882,
199,
504,
7390,
14,
1548,
14,
7726,
492,
4298,
199,
504,
7390,
14,
1548,
14,
1974,
492,
20417,
515,
199,
504,
7390,
14,
4901,
14,
1208,
492,
664,
3498,
2959,
3325,
1110,
421,
199,
2759,
8647,
46,
927,
2676,
708,
275,
488,
199,
692,
4298,
14,
374,
8647,
837,
272,
862,
26,
267,
492,
4747,
708,
1412,
272,
871,
3545,
26,
267,
3372,
8647,
46,
927,
2676,
708,
275,
1689,
3314,
10061,
12,
15187,
3498,
365,
440,
2808,
298,
1816,
298,
262,
314,
2236,
14073,
402,
4747,
708,
1412,
2685,
199,
199,
533,
3959,
13544,
1746,
8,
2796,
14,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
12145,
14,
4901,
14,
8440,
13544,
5565,
272,
408,
272,
347,
511,
63,
646,
4238,
13544,
8,
277,
304,
267,
408,
267,
17413,
1337,
370,
492,
491,
91,
12145,
14,
4901,
14,
8440,
13544,
93,
1077,
746,
376,
267,
445,
91,
17825,
93,
9297,
626,
445,
91,
8440,
13544,
93,
365,
949,
8088,
282,
1777,
402,
267,
17078,
14,
267,
408,
267,
984,
14,
3112,
905,
8440,
13544,
937,
275,
488,
267,
687,
7390,
14,
5265,
14,
12145,
63,
8440,
5811,
492,
1125,
2209,
267,
862,
26,
288,
492,
7390,
14,
4901,
14,
8440,
13544,
267,
871,
3545,
12,
325,
26,
288,
291,
14,
2947,
8,
495,
8,
69,
395,
1125,
2209,
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,
32768,
32768,
32768
] | [
1898,
334,
67,
9,
8937,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
646,
984,
199,
199,
504,
7390,
14,
14443,
492,
2882,
199,
504,
7390,
14,
1548,
14,
7726,
492,
4298,
199,
504,
7390,
14,
1548,
14,
1974,
492,
20417,
515,
199,
504,
7390,
14,
4901,
14,
1208,
492,
664,
3498,
2959,
3325,
1110,
421,
199,
2759,
8647,
46,
927,
2676,
708,
275,
488,
199,
692,
4298,
14,
374,
8647,
837,
272,
862,
26,
267,
492,
4747,
708,
1412,
272,
871,
3545,
26,
267,
3372,
8647,
46,
927,
2676,
708,
275,
1689,
3314,
10061,
12,
15187,
3498,
365,
440,
2808,
298,
1816,
298,
262,
314,
2236,
14073,
402,
4747,
708,
1412,
2685,
199,
199,
533,
3959,
13544,
1746,
8,
2796,
14,
1746,
304,
272,
408,
272,
6496,
367,
491,
91,
12145,
14,
4901,
14,
8440,
13544,
5565,
272,
408,
272,
347,
511,
63,
646,
4238,
13544,
8,
277,
304,
267,
408,
267,
17413,
1337,
370,
492,
491,
91,
12145,
14,
4901,
14,
8440,
13544,
93,
1077,
746,
376,
267,
445,
91,
17825,
93,
9297,
626,
445,
91,
8440,
13544,
93,
365,
949,
8088,
282,
1777,
402,
267,
17078,
14,
267,
408,
267,
984,
14,
3112,
905,
8440,
13544,
937,
275,
488,
267,
687,
7390,
14,
5265,
14,
12145,
63,
8440,
5811,
492,
1125,
2209,
267,
862,
26,
288,
492,
7390,
14,
4901,
14,
8440,
13544,
267,
871,
3545,
12,
325,
26,
288,
291,
14,
2947,
8,
495,
8,
69,
395,
1125,
2209,
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,
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
] |
justinpotts/mozillians | vendor-local/lib/python/kombu/transport/SQS.py | 10 | 11233 | """
kombu.transport.SQS
===================
Amazon SQS transport.
:copyright: (c) 2010 - 2012 by Ask Solem
:license: BSD, see LICENSE for more details.
"""
from __future__ import absolute_import
import socket
import string
from Queue import Empty
from anyjson import loads, dumps
from boto import exception
from boto import sdb as _sdb
from boto import sqs as _sqs
from boto.sdb.domain import Domain
from boto.sdb.connection import SDBConnection
from boto.sqs.connection import SQSConnection
from boto.sqs.message import Message
from kombu.exceptions import StdChannelError
from kombu.utils import cached_property, uuid
from kombu.utils.encoding import safe_str
from . import virtual
# dots are replaced by dash, all other punctuation
# replaced by underscore.
CHARS_REPLACE_TABLE = dict((ord(c), 0x5f)
for c in string.punctuation if c not in '-_.')
CHARS_REPLACE_TABLE[0x2e] = 0x2d # '.' -> '-'
class Table(Domain):
"""Amazon SimpleDB domain describing the message routing table."""
# caches queues already bound, so we don't have to declare them again.
_already_bound = set()
def routes_for(self, exchange):
"""Iterator giving all routes for an exchange."""
return self.select("""WHERE exchange = '%s'""" % exchange)
def get_queue(self, queue):
"""Get binding for queue."""
qid = self._get_queue_id(queue)
if qid:
return self.get_item(qid)
def create_binding(self, queue):
"""Get binding item for queue.
Creates the item if it doesn't exist.
"""
item = self.get_queue(queue)
if item:
return item, item["id"]
id = uuid()
return self.new_item(id), id
def queue_bind(self, exchange, routing_key, pattern, queue):
if queue not in self._already_bound:
binding, id = self.create_binding(queue)
binding.update(exchange=exchange,
routing_key=routing_key or "",
pattern=pattern or "",
queue=queue or "",
id=id)
binding.save()
self._already_bound.add(queue)
def queue_delete(self, queue):
"""delete queue by name."""
self._already_bound.discard(queue)
item = self._get_queue_item(queue)
if item:
self.delete_item(item)
def exchange_delete(self, exchange):
"""Delete all routes for `exchange`."""
for item in self.routes_for(exchange):
self.delete_item(item["id"])
def get_item(self, item_name):
"""Uses `consistent_read` by default."""
# Domain is an old-style class, can't use super().
for consistent_read in (False, True):
item = Domain.get_item(self, item_name, consistent_read)
if item:
return item
def select(self, query='', next_token=None, consistent_read=True,
max_items=None):
"""Uses `consistent_read` by default."""
query = """SELECT * FROM `%s` %s""" % (self.name, query)
return Domain.select(self, query, next_token,
consistent_read, max_items)
def _try_first(self, query='', **kwargs):
for c in (False, True):
for item in self.select(query, consistent_read=c, **kwargs):
return item
def get_exchanges(self):
return list(set(i["exchange"] for i in self.select()))
def _get_queue_item(self, queue):
return self._try_first("""WHERE queue = '%s' limit 1""" % queue)
def _get_queue_id(self, queue):
item = self._get_queue_item(queue)
if item:
return item["id"]
class Channel(virtual.Channel):
Table = Table
default_region = "us-east-1"
domain_format = "kombu%(vhost)s"
_sdb = None
_sqs = None
_queue_cache = {}
_noack_queues = set()
def __init__(self, *args, **kwargs):
super(Channel, self).__init__(*args, **kwargs)
# SQS blows up when you try to create a new queue if one already
# exists with a different visibility_timeout, so this prepopulates
# the queue_cache to protect us from recreating
# queues that are known to already exist.
queues = self.sqs.get_all_queues()
for queue in queues:
self._queue_cache[queue.name] = queue
def basic_consume(self, queue, no_ack, *args, **kwargs):
if no_ack:
self._noack_queues.add(queue)
return super(Channel, self).basic_consume(queue, no_ack,
*args, **kwargs)
def basic_cancel(self, consumer_tag):
if consumer_tag in self._consumers:
queue = self._tag_to_queue[consumer_tag]
self._noack_queues.discard(queue)
return super(Channel, self).basic_cancel(consumer_tag)
def entity_name(self, name, table=CHARS_REPLACE_TABLE):
"""Format AMQP queue name into a legal SQS queue name."""
return unicode(safe_str(name)).translate(table)
def _new_queue(self, queue, **kwargs):
"""Ensures a queue exists in SQS."""
queue = self.queue_name_prefix + queue
try:
return self._queue_cache[queue]
except KeyError:
q = self._queue_cache[queue] = self.sqs.create_queue(
self.entity_name(queue),
self.visibility_timeout)
return q
def _queue_bind(self, *args):
"""Bind ``queue`` to ``exchange`` with routing key.
Route will be stored in SDB if so enabled.
"""
if self.supports_fanout:
self.table.queue_bind(*args)
def get_table(self, exchange):
"""Get routing table.
Retrieved from SDB if :attr:`supports_fanout`.
"""
if self.supports_fanout:
return [(r["routing_key"], r["pattern"], r["queue"])
for r in self.table.routes_for(exchange)]
return super(Channel, self).get_table(exchange)
def get_exchanges(self):
if self.supports_fanout:
return self.table.get_exchanges()
return super(Channel, self).get_exchanges()
def _delete(self, queue, *args):
"""delete queue by name."""
self._queue_cache.pop(queue, None)
if self.supports_fanout:
self.table.queue_delete(queue)
super(Channel, self)._delete(queue)
def exchange_delete(self, exchange, **kwargs):
"""Delete exchange by name."""
if self.supports_fanout:
self.table.exchange_delete(exchange)
super(Channel, self).exchange_delete(exchange, **kwargs)
def _has_queue(self, queue, **kwargs):
"""Returns True if ``queue`` has been previously declared."""
if self.supports_fanout:
return bool(self.table.get_queue(queue))
return super(Channel, self)._has_queue(queue)
def _put(self, queue, message, **kwargs):
"""Put message onto queue."""
q = self._new_queue(queue)
m = Message()
m.set_body(dumps(message))
q.write(m)
def _put_fanout(self, exchange, message, **kwargs):
"""Deliver fanout message to all queues in ``exchange``."""
for route in self.table.routes_for(exchange):
self._put(route["queue"], message, **kwargs)
def _get(self, queue):
"""Try to retrieve a single message off ``queue``."""
q = self._new_queue(queue)
rs = q.get_messages(1)
if rs:
m = rs[0]
payload = loads(rs[0].get_body())
if queue in self._noack_queues:
q.delete_message(m)
else:
payload["properties"]["delivery_info"].update({
"sqs_message": m, "sqs_queue": q, })
return payload
raise Empty()
def basic_ack(self, delivery_tag):
delivery_info = self.qos.get(delivery_tag).delivery_info
try:
queue = delivery_info["sqs_queue"]
except KeyError:
pass
else:
queue.delete_message(delivery_info["sqs_message"])
super(Channel, self).basic_ack(delivery_tag)
def _size(self, queue):
"""Returns the number of messages in a queue."""
return self._new_queue(queue).count()
def _purge(self, queue):
"""Deletes all current messages in a queue."""
q = self._new_queue(queue)
# SQS is slow at registering messages, so run for a few
# iterations to ensure messages are deleted.
size = 0
for i in xrange(10):
size += q.count()
if not size:
break
q.clear()
return size
def close(self):
super(Channel, self).close()
for conn in (self._sqs, self._sdb):
if conn:
try:
conn.close()
except AttributeError, exc: # FIXME ???
if "can't set attribute" not in str(exc):
raise
def _get_regioninfo(self, regions):
if self.region:
for _r in regions:
if _r.name == self.region:
return _r
def _aws_connect_to(self, fun, regions):
conninfo = self.conninfo
region = self._get_regioninfo(regions)
return fun(region=region,
aws_access_key_id=conninfo.userid,
aws_secret_access_key=conninfo.password,
port=conninfo.port)
def _next_delivery_tag(self):
return uuid() # See #73
@property
def sqs(self):
if self._sqs is None:
self._sqs = self._aws_connect_to(SQSConnection, _sqs.regions())
return self._sqs
@property
def sdb(self):
if self._sdb is None:
self._sdb = self._aws_connect_to(SDBConnection, _sdb.regions())
return self._sdb
@property
def table(self):
name = self.entity_name(self.domain_format % {
"vhost": self.conninfo.virtual_host})
d = self.sdb.get_object("CreateDomain", {"DomainName": name},
self.Table)
d.name = name
return d
@property
def conninfo(self):
return self.connection.client
@property
def transport_options(self):
return self.connection.client.transport_options
@cached_property
def visibility_timeout(self):
return self.transport_options.get("visibility_timeout")
@cached_property
def queue_name_prefix(self):
return self.transport_options.get("queue_name_prefix", '')
@cached_property
def supports_fanout(self):
return self.transport_options.get("sdb_persistence", False)
@cached_property
def region(self):
return self.transport_options.get("region") or self.default_region
class Transport(virtual.Transport):
Channel = Channel
polling_interval = 1
default_port = None
connection_errors = (exception.SQSError, socket.error)
channel_errors = (exception.SQSDecodeError, StdChannelError)
| bsd-3-clause | [
624,
199,
75,
676,
464,
14,
5545,
14,
18445,
51,
199,
1280,
5918,
199,
199,
33,
8872,
428,
23298,
7773,
14,
199,
199,
26,
7307,
26,
334,
67,
9,
7129,
446,
6029,
701,
30481,
2002,
3701,
199,
26,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2838,
199,
646,
1059,
199,
199,
504,
10703,
492,
9630,
199,
199,
504,
1263,
1001,
492,
14404,
12,
16864,
199,
199,
504,
6055,
492,
1919,
199,
504,
6055,
492,
308,
697,
465,
485,
21624,
199,
504,
6055,
492,
5295,
83,
465,
485,
31603,
199,
504,
6055,
14,
21624,
14,
2261,
492,
14061,
199,
504,
6055,
14,
21624,
14,
2105,
492,
428,
2846,
3225,
199,
504,
6055,
14,
31603,
14,
2105,
492,
428,
23298,
3225,
199,
504,
6055,
14,
31603,
14,
1188,
492,
6430,
199,
199,
504,
1022,
676,
464,
14,
3924,
492,
20992,
5358,
547,
199,
504,
1022,
676,
464,
14,
1208,
492,
6328,
63,
1829,
12,
5377,
199,
504,
1022,
676,
464,
14,
1208,
14,
2991,
492,
5048,
63,
495,
199,
199,
504,
1275,
492,
5791,
199,
199,
3,
21185,
787,
8717,
701,
11847,
12,
1006,
1163,
22929,
199,
3,
8717,
701,
18888,
14,
199,
16326,
63,
27010,
63,
8723,
275,
1211,
1332,
2181,
8,
67,
395,
378,
88,
21,
70,
9,
2574,
367,
286,
315,
1059,
14,
25181,
340,
286,
440,
315,
2475,
63,
2659,
199,
16326,
63,
27010,
63,
8723,
59,
16,
88,
18,
69,
61,
275,
378,
88,
18,
68,
221,
327,
7815,
1035,
10791,
421,
199,
533,
6957,
8,
7705,
304,
272,
408,
33,
8872,
5870,
2846,
2881,
13660,
314,
1245,
14870,
1817,
1041,
272,
327,
18014,
21366,
2575,
3914,
12,
880,
781,
2793,
1133,
1172,
370,
20771,
3062,
4020,
14,
272,
485,
14039,
63,
3556,
275,
663,
342,
339,
347,
15777,
63,
509,
8,
277,
12,
15343,
304,
267,
408,
3585,
15131,
1006,
15777,
367,
376,
15343,
1041,
267,
372,
291,
14,
2416,
4852,
17688,
15343,
275,
1543,
83,
26555,
450,
15343,
9,
339,
347,
664,
63,
1825,
8,
277,
12,
4126,
304,
267,
408,
1002,
11696,
367,
4126,
1041,
267,
1894,
344,
275,
291,
423,
362,
63,
1825,
63,
344,
8,
1825,
9,
267,
340,
1894,
344,
26,
288,
372,
291,
14,
362,
63,
1053,
8,
81,
344,
9,
339,
347,
1218,
63,
9140,
8,
277,
12,
4126,
304,
267,
408,
1002,
11696,
1242,
367,
4126,
14,
398,
10560,
314,
1242,
340,
652,
3181,
1133,
2187,
14,
398,
408,
267,
1242,
275,
291,
14,
362,
63,
1825,
8,
1825,
9,
267,
340,
1242,
26,
288,
372,
1242,
12,
1242,
905,
344,
937,
267,
1305,
275,
5377,
342,
267,
372,
291,
14,
1222,
63,
1053,
8,
344,
395,
1305,
339,
347,
4126,
63,
3409,
8,
277,
12,
15343,
12,
14870,
63,
498,
12,
3851,
12,
4126,
304,
267,
340,
4126,
440,
315,
291,
423,
14039,
63,
3556,
26,
288,
11696,
12,
1305,
275,
291,
14,
981,
63,
9140,
8,
1825,
9,
288,
11696,
14,
873,
8,
14197,
29,
14197,
12,
2574,
14870,
63,
498,
29,
9492,
63,
498,
503,
4873,
2574,
3851,
29,
3401,
503,
4873,
2574,
4126,
29,
1825,
503,
4873,
2574,
1305,
29,
344,
9,
288,
11696,
14,
2117,
342,
288,
291,
423,
14039,
63,
3556,
14,
525,
8,
1825,
9,
339,
347,
4126,
63,
1807,
8,
277,
12,
4126,
304,
267,
408,
1807,
4126,
701,
536,
1041,
267,
291,
423,
14039,
63,
3556,
14,
14394,
8,
1825,
9,
267,
1242,
275,
291,
423,
362,
63,
1825,
63,
1053,
8,
1825,
9,
267,
340,
1242,
26,
288,
291,
14,
1807,
63,
1053,
8,
1053,
9,
339,
347,
15343,
63,
1807,
8,
277,
12,
15343,
304,
267,
408,
5392,
1006,
15777,
367,
658,
14197,
17105,
267,
367,
1242,
315,
291,
14,
13243,
63,
509,
8,
14197,
304,
288,
291,
14,
1807,
63,
1053,
8,
1053,
905,
344,
3135,
339,
347,
664,
63,
1053,
8,
277,
12,
1242,
63,
354,
304,
267,
408,
21896,
658,
15478,
63,
739,
64,
701,
849,
1041,
267,
327,
14061,
365,
376,
2269,
13,
2487,
1021,
12,
883,
1133,
675,
1613,
1252,
267,
367,
12137,
63,
739,
315,
334,
797,
12,
715,
304,
288,
1242,
275,
14061,
14,
362,
63,
1053,
8,
277,
12,
1242,
63,
354,
12,
12137,
63,
739,
9,
288,
340,
1242,
26,
355,
372,
1242,
339,
347,
3504,
8,
277,
12,
1827,
4581,
2163,
63,
1418,
29,
403,
12,
12137,
63,
739,
29,
549,
12,
288,
1390,
63,
1744,
29,
403,
304,
267,
408,
21896,
658,
15478,
63,
739,
64,
701,
849,
1041,
267,
1827,
275,
408,
4859,
627,
4442,
18633,
83,
64,
450,
83,
624,
450,
334,
277,
14,
354,
12,
1827,
9,
267,
372,
14061,
14,
2416,
8,
277,
12,
1827,
12,
2163,
63,
1418,
12,
3521,
12137,
63,
739,
12,
1390,
63,
1744,
9,
339,
347,
485,
893,
63,
2246,
8,
277,
12,
1827,
4581,
1011,
958,
304,
267,
367,
286,
315,
334,
797,
12,
715,
304,
288,
367,
1242,
315,
291,
14,
2416,
8,
1131,
12,
12137,
63,
739,
29,
67,
12,
1011,
958,
304,
355,
372,
1242,
339,
347,
664,
63,
476,
6627,
8,
277,
304,
267,
372,
769,
8,
409,
8,
73,
905,
14197,
937,
367,
284,
315,
291,
14,
2416,
4059,
339,
347,
485,
362,
63,
1825,
63,
1053,
8,
277,
12,
4126,
304,
267,
372,
291,
423,
893,
63,
2246,
4852,
17688,
4126,
275,
1543,
83,
7,
2304,
413,
624,
450,
4126,
9,
339,
347,
485,
362,
63,
1825,
63,
344,
8,
277,
12,
4126,
304,
267,
1242,
275,
291,
423,
362,
63,
1825,
63,
1053,
8,
1825,
9,
267,
340,
1242,
26,
288,
372,
1242,
905,
344,
937,
421,
199,
533,
17270,
8,
2065,
14,
5358,
304,
272,
6957,
275,
6957,
339,
849,
63,
4551,
275,
298,
527,
13,
14346,
13,
17,
2,
272,
2881,
63,
908,
275,
298,
75,
676,
464,
2840,
32071,
9,
83,
2,
272,
485,
21624,
275,
488,
272,
485,
31603,
275,
488,
272,
485,
1825,
63,
1637,
275,
1052,
272,
485,
889,
564,
63,
18849,
275,
663,
342,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267
] | [
199,
75,
676,
464,
14,
5545,
14,
18445,
51,
199,
1280,
5918,
199,
199,
33,
8872,
428,
23298,
7773,
14,
199,
199,
26,
7307,
26,
334,
67,
9,
7129,
446,
6029,
701,
30481,
2002,
3701,
199,
26,
1682,
26,
6289,
12,
1937,
5113,
367,
1655,
2436,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
646,
2838,
199,
646,
1059,
199,
199,
504,
10703,
492,
9630,
199,
199,
504,
1263,
1001,
492,
14404,
12,
16864,
199,
199,
504,
6055,
492,
1919,
199,
504,
6055,
492,
308,
697,
465,
485,
21624,
199,
504,
6055,
492,
5295,
83,
465,
485,
31603,
199,
504,
6055,
14,
21624,
14,
2261,
492,
14061,
199,
504,
6055,
14,
21624,
14,
2105,
492,
428,
2846,
3225,
199,
504,
6055,
14,
31603,
14,
2105,
492,
428,
23298,
3225,
199,
504,
6055,
14,
31603,
14,
1188,
492,
6430,
199,
199,
504,
1022,
676,
464,
14,
3924,
492,
20992,
5358,
547,
199,
504,
1022,
676,
464,
14,
1208,
492,
6328,
63,
1829,
12,
5377,
199,
504,
1022,
676,
464,
14,
1208,
14,
2991,
492,
5048,
63,
495,
199,
199,
504,
1275,
492,
5791,
199,
199,
3,
21185,
787,
8717,
701,
11847,
12,
1006,
1163,
22929,
199,
3,
8717,
701,
18888,
14,
199,
16326,
63,
27010,
63,
8723,
275,
1211,
1332,
2181,
8,
67,
395,
378,
88,
21,
70,
9,
2574,
367,
286,
315,
1059,
14,
25181,
340,
286,
440,
315,
2475,
63,
2659,
199,
16326,
63,
27010,
63,
8723,
59,
16,
88,
18,
69,
61,
275,
378,
88,
18,
68,
221,
327,
7815,
1035,
10791,
421,
199,
533,
6957,
8,
7705,
304,
272,
408,
33,
8872,
5870,
2846,
2881,
13660,
314,
1245,
14870,
1817,
1041,
272,
327,
18014,
21366,
2575,
3914,
12,
880,
781,
2793,
1133,
1172,
370,
20771,
3062,
4020,
14,
272,
485,
14039,
63,
3556,
275,
663,
342,
339,
347,
15777,
63,
509,
8,
277,
12,
15343,
304,
267,
408,
3585,
15131,
1006,
15777,
367,
376,
15343,
1041,
267,
372,
291,
14,
2416,
4852,
17688,
15343,
275,
1543,
83,
26555,
450,
15343,
9,
339,
347,
664,
63,
1825,
8,
277,
12,
4126,
304,
267,
408,
1002,
11696,
367,
4126,
1041,
267,
1894,
344,
275,
291,
423,
362,
63,
1825,
63,
344,
8,
1825,
9,
267,
340,
1894,
344,
26,
288,
372,
291,
14,
362,
63,
1053,
8,
81,
344,
9,
339,
347,
1218,
63,
9140,
8,
277,
12,
4126,
304,
267,
408,
1002,
11696,
1242,
367,
4126,
14,
398,
10560,
314,
1242,
340,
652,
3181,
1133,
2187,
14,
398,
408,
267,
1242,
275,
291,
14,
362,
63,
1825,
8,
1825,
9,
267,
340,
1242,
26,
288,
372,
1242,
12,
1242,
905,
344,
937,
267,
1305,
275,
5377,
342,
267,
372,
291,
14,
1222,
63,
1053,
8,
344,
395,
1305,
339,
347,
4126,
63,
3409,
8,
277,
12,
15343,
12,
14870,
63,
498,
12,
3851,
12,
4126,
304,
267,
340,
4126,
440,
315,
291,
423,
14039,
63,
3556,
26,
288,
11696,
12,
1305,
275,
291,
14,
981,
63,
9140,
8,
1825,
9,
288,
11696,
14,
873,
8,
14197,
29,
14197,
12,
2574,
14870,
63,
498,
29,
9492,
63,
498,
503,
4873,
2574,
3851,
29,
3401,
503,
4873,
2574,
4126,
29,
1825,
503,
4873,
2574,
1305,
29,
344,
9,
288,
11696,
14,
2117,
342,
288,
291,
423,
14039,
63,
3556,
14,
525,
8,
1825,
9,
339,
347,
4126,
63,
1807,
8,
277,
12,
4126,
304,
267,
408,
1807,
4126,
701,
536,
1041,
267,
291,
423,
14039,
63,
3556,
14,
14394,
8,
1825,
9,
267,
1242,
275,
291,
423,
362,
63,
1825,
63,
1053,
8,
1825,
9,
267,
340,
1242,
26,
288,
291,
14,
1807,
63,
1053,
8,
1053,
9,
339,
347,
15343,
63,
1807,
8,
277,
12,
15343,
304,
267,
408,
5392,
1006,
15777,
367,
658,
14197,
17105,
267,
367,
1242,
315,
291,
14,
13243,
63,
509,
8,
14197,
304,
288,
291,
14,
1807,
63,
1053,
8,
1053,
905,
344,
3135,
339,
347,
664,
63,
1053,
8,
277,
12,
1242,
63,
354,
304,
267,
408,
21896,
658,
15478,
63,
739,
64,
701,
849,
1041,
267,
327,
14061,
365,
376,
2269,
13,
2487,
1021,
12,
883,
1133,
675,
1613,
1252,
267,
367,
12137,
63,
739,
315,
334,
797,
12,
715,
304,
288,
1242,
275,
14061,
14,
362,
63,
1053,
8,
277,
12,
1242,
63,
354,
12,
12137,
63,
739,
9,
288,
340,
1242,
26,
355,
372,
1242,
339,
347,
3504,
8,
277,
12,
1827,
4581,
2163,
63,
1418,
29,
403,
12,
12137,
63,
739,
29,
549,
12,
288,
1390,
63,
1744,
29,
403,
304,
267,
408,
21896,
658,
15478,
63,
739,
64,
701,
849,
1041,
267,
1827,
275,
408,
4859,
627,
4442,
18633,
83,
64,
450,
83,
624,
450,
334,
277,
14,
354,
12,
1827,
9,
267,
372,
14061,
14,
2416,
8,
277,
12,
1827,
12,
2163,
63,
1418,
12,
3521,
12137,
63,
739,
12,
1390,
63,
1744,
9,
339,
347,
485,
893,
63,
2246,
8,
277,
12,
1827,
4581,
1011,
958,
304,
267,
367,
286,
315,
334,
797,
12,
715,
304,
288,
367,
1242,
315,
291,
14,
2416,
8,
1131,
12,
12137,
63,
739,
29,
67,
12,
1011,
958,
304,
355,
372,
1242,
339,
347,
664,
63,
476,
6627,
8,
277,
304,
267,
372,
769,
8,
409,
8,
73,
905,
14197,
937,
367,
284,
315,
291,
14,
2416,
4059,
339,
347,
485,
362,
63,
1825,
63,
1053,
8,
277,
12,
4126,
304,
267,
372,
291,
423,
893,
63,
2246,
4852,
17688,
4126,
275,
1543,
83,
7,
2304,
413,
624,
450,
4126,
9,
339,
347,
485,
362,
63,
1825,
63,
344,
8,
277,
12,
4126,
304,
267,
1242,
275,
291,
423,
362,
63,
1825,
63,
1053,
8,
1825,
9,
267,
340,
1242,
26,
288,
372,
1242,
905,
344,
937,
421,
199,
533,
17270,
8,
2065,
14,
5358,
304,
272,
6957,
275,
6957,
339,
849,
63,
4551,
275,
298,
527,
13,
14346,
13,
17,
2,
272,
2881,
63,
908,
275,
298,
75,
676,
464,
2840,
32071,
9,
83,
2,
272,
485,
21624,
275,
488,
272,
485,
31603,
275,
488,
272,
485,
1825,
63,
1637,
275,
1052,
272,
485,
889,
564,
63,
18849,
275,
663,
342,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
huangkuan/hack | lib/gcloud/monitoring/test_query.py | 7 | 23503 | # Copyright 2016 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.
import unittest2
PROJECT = 'my-project'
METRIC_TYPE = 'compute.googleapis.com/instance/uptime'
METRIC_LABELS = {'instance_name': 'instance-1'}
METRIC_LABELS2 = {'instance_name': 'instance-2'}
RESOURCE_TYPE = 'gce_instance'
RESOURCE_LABELS = {
'project_id': 'my-project',
'zone': 'us-east1-a',
'instance_id': '1234567890123456789',
}
RESOURCE_LABELS2 = {
'project_id': 'my-project',
'zone': 'us-east1-b',
'instance_id': '9876543210987654321',
}
METRIC_KIND = 'DELTA'
VALUE_TYPE = 'DOUBLE'
TS0 = '2016-04-06T22:05:00.042Z'
TS1 = '2016-04-06T22:05:01.042Z'
TS2 = '2016-04-06T22:05:02.042Z'
class TestAligner(unittest2.TestCase):
def _getTargetClass(self):
from gcloud.monitoring.query import Aligner
return Aligner
def test_one(self):
self.assertTrue(hasattr(self._getTargetClass(), 'ALIGN_RATE'))
def test_names(self):
for name in self._getTargetClass().__dict__:
if not name.startswith('_'):
self.assertEqual(getattr(self._getTargetClass(), name), name)
class TestReducer(unittest2.TestCase):
def _getTargetClass(self):
from gcloud.monitoring.query import Reducer
return Reducer
def test_one(self):
self.assertTrue(hasattr(self._getTargetClass(),
'REDUCE_PERCENTILE_99'))
def test_names(self):
for name in self._getTargetClass().__dict__:
if not name.startswith('_'):
self.assertEqual(getattr(self._getTargetClass(), name), name)
class TestQuery(unittest2.TestCase):
def _getTargetClass(self):
from gcloud.monitoring.query import Query
return Query
def _makeOne(self, *args, **kwargs):
return self._getTargetClass()(*args, **kwargs)
def test_constructor_minimal(self):
client = _Client(project=PROJECT, connection=_Connection())
query = self._makeOne(client)
self.assertEqual(query._client, client)
self.assertEqual(query._filter.metric_type,
self._getTargetClass().DEFAULT_METRIC_TYPE)
self.assertIsNone(query._start_time)
self.assertIsNone(query._end_time)
self.assertIsNone(query._per_series_aligner)
self.assertIsNone(query._alignment_period_seconds)
self.assertIsNone(query._cross_series_reducer)
self.assertEqual(query._group_by_fields, ())
def test_constructor_maximal(self):
import datetime
T1 = datetime.datetime(2016, 4, 7, 2, 30, 30)
DAYS, HOURS, MINUTES = 1, 2, 3
T0 = T1 - datetime.timedelta(days=DAYS, hours=HOURS, minutes=MINUTES)
client = _Client(project=PROJECT, connection=_Connection())
query = self._makeOne(client, METRIC_TYPE,
end_time=T1,
days=DAYS, hours=HOURS, minutes=MINUTES)
self.assertEqual(query._client, client)
self.assertEqual(query._filter.metric_type, METRIC_TYPE)
self.assertEqual(query._start_time, T0)
self.assertEqual(query._end_time, T1)
self.assertIsNone(query._per_series_aligner)
self.assertIsNone(query._alignment_period_seconds)
self.assertIsNone(query._cross_series_reducer)
self.assertEqual(query._group_by_fields, ())
def test_constructor_default_end_time(self):
import datetime
from gcloud._testing import _Monkey
from gcloud.monitoring import query as MUT
MINUTES = 5
NOW, T0, T1 = [
datetime.datetime(2016, 4, 7, 2, 30, 30),
datetime.datetime(2016, 4, 7, 2, 25, 0),
datetime.datetime(2016, 4, 7, 2, 30, 0),
]
client = _Client(project=PROJECT, connection=_Connection())
with _Monkey(MUT, _UTCNOW=lambda: NOW):
query = self._makeOne(client, METRIC_TYPE, minutes=MINUTES)
self.assertEqual(query._start_time, T0)
self.assertEqual(query._end_time, T1)
def test_constructor_nonzero_duration_illegal(self):
import datetime
T1 = datetime.datetime(2016, 4, 7, 2, 30, 30)
client = _Client(project=PROJECT, connection=_Connection())
with self.assertRaises(ValueError):
self._makeOne(client, METRIC_TYPE, end_time=T1)
def test_execution_without_interval_illegal(self):
client = _Client(project=PROJECT, connection=_Connection())
query = self._makeOne(client, METRIC_TYPE)
with self.assertRaises(ValueError):
list(query)
def test_metric_type(self):
client = _Client(project=PROJECT, connection=_Connection())
query = self._makeOne(client, METRIC_TYPE)
self.assertEqual(query.metric_type, METRIC_TYPE)
def test_filter(self):
client = _Client(project=PROJECT, connection=_Connection())
query = self._makeOne(client, METRIC_TYPE)
expected = 'metric.type = "{type}"'.format(type=METRIC_TYPE)
self.assertEqual(query.filter, expected)
def test_filter_by_group(self):
GROUP = '1234567'
client = _Client(project=PROJECT, connection=_Connection())
query = self._makeOne(client, METRIC_TYPE)
query = query.select_group(GROUP)
expected = (
'metric.type = "{type}"'
' AND group.id = "{group}"'
).format(type=METRIC_TYPE, group=GROUP)
self.assertEqual(query.filter, expected)
def test_filter_by_projects(self):
PROJECT1, PROJECT2 = 'project-1', 'project-2'
client = _Client(project=PROJECT, connection=_Connection())
query = self._makeOne(client, METRIC_TYPE)
query = query.select_projects(PROJECT1, PROJECT2)
expected = (
'metric.type = "{type}"'
' AND project = "{project1}" OR project = "{project2}"'
).format(type=METRIC_TYPE, project1=PROJECT1, project2=PROJECT2)
self.assertEqual(query.filter, expected)
def test_filter_by_resources(self):
ZONE_PREFIX = 'europe-'
client = _Client(project=PROJECT, connection=_Connection())
query = self._makeOne(client, METRIC_TYPE)
query = query.select_resources(zone_prefix=ZONE_PREFIX)
expected = (
'metric.type = "{type}"'
' AND resource.label.zone = starts_with("{prefix}")'
).format(type=METRIC_TYPE, prefix=ZONE_PREFIX)
self.assertEqual(query.filter, expected)
def test_filter_by_metrics(self):
INSTANCE = 'my-instance'
client = _Client(project=PROJECT, connection=_Connection())
query = self._makeOne(client, METRIC_TYPE)
query = query.select_metrics(instance_name=INSTANCE)
expected = (
'metric.type = "{type}"'
' AND metric.label.instance_name = "{instance}"'
).format(type=METRIC_TYPE, instance=INSTANCE)
self.assertEqual(query.filter, expected)
def test_request_parameters_minimal(self):
import datetime
T1 = datetime.datetime(2016, 4, 7, 2, 30, 0)
client = _Client(project=PROJECT, connection=_Connection())
query = self._makeOne(client, METRIC_TYPE)
query = query.select_interval(end_time=T1)
actual = list(query._build_query_params())
expected = [
('filter', 'metric.type = "{type}"'.format(type=METRIC_TYPE)),
('interval.endTime', T1.isoformat() + 'Z'),
]
self.assertEqual(actual, expected)
def test_request_parameters_maximal(self):
import datetime
T0 = datetime.datetime(2016, 4, 7, 2, 0, 0)
T1 = datetime.datetime(2016, 4, 7, 2, 30, 0)
ALIGNER = 'ALIGN_DELTA'
MINUTES, SECONDS, PERIOD = 1, 30, '90s'
REDUCER = 'REDUCE_MEAN'
FIELD1, FIELD2 = 'resource.zone', 'metric.instance_name'
PAGE_SIZE = 100
PAGE_TOKEN = 'second-page-please'
client = _Client(project=PROJECT, connection=_Connection())
query = self._makeOne(client, METRIC_TYPE)
query = query.select_interval(start_time=T0, end_time=T1)
query = query.align(ALIGNER, minutes=MINUTES, seconds=SECONDS)
query = query.reduce(REDUCER, FIELD1, FIELD2)
actual = list(query._build_query_params(headers_only=True,
page_size=PAGE_SIZE,
page_token=PAGE_TOKEN))
expected = [
('filter', 'metric.type = "{type}"'.format(type=METRIC_TYPE)),
('interval.endTime', T1.isoformat() + 'Z'),
('interval.startTime', T0.isoformat() + 'Z'),
('aggregation.perSeriesAligner', ALIGNER),
('aggregation.alignmentPeriod', PERIOD),
('aggregation.crossSeriesReducer', REDUCER),
('aggregation.groupByFields', FIELD1),
('aggregation.groupByFields', FIELD2),
('view', 'HEADERS'),
('pageSize', PAGE_SIZE),
('pageToken', PAGE_TOKEN),
]
self.assertEqual(actual, expected)
def test_iteration(self):
import datetime
T0 = datetime.datetime(2016, 4, 6, 22, 5, 0)
T1 = datetime.datetime(2016, 4, 6, 22, 10, 0)
INTERVAL1 = {'startTime': TS0, 'endTime': TS1}
INTERVAL2 = {'startTime': TS1, 'endTime': TS2}
VALUE1 = 60 # seconds
VALUE2 = 60.001 # seconds
SERIES1 = {
'metric': {'type': METRIC_TYPE, 'labels': METRIC_LABELS},
'resource': {'type': RESOURCE_TYPE, 'labels': RESOURCE_LABELS},
'metricKind': METRIC_KIND,
'valueType': VALUE_TYPE,
'points': [
{'interval': INTERVAL2, 'value': {'doubleValue': VALUE1}},
{'interval': INTERVAL1, 'value': {'doubleValue': VALUE1}},
],
}
SERIES2 = {
'metric': {'type': METRIC_TYPE, 'labels': METRIC_LABELS2},
'resource': {'type': RESOURCE_TYPE, 'labels': RESOURCE_LABELS2},
'metricKind': METRIC_KIND,
'valueType': VALUE_TYPE,
'points': [
{'interval': INTERVAL2, 'value': {'doubleValue': VALUE2}},
{'interval': INTERVAL1, 'value': {'doubleValue': VALUE2}},
],
}
RESPONSE = {'timeSeries': [SERIES1, SERIES2]}
connection = _Connection(RESPONSE)
client = _Client(project=PROJECT, connection=connection)
query = self._makeOne(client, METRIC_TYPE)
query = query.select_interval(start_time=T0, end_time=T1)
response = list(query)
self.assertEqual(len(response), 2)
series1, series2 = response
self.assertEqual(series1.metric.labels, METRIC_LABELS)
self.assertEqual(series2.metric.labels, METRIC_LABELS2)
self.assertEqual(series1.resource.labels, RESOURCE_LABELS)
self.assertEqual(series2.resource.labels, RESOURCE_LABELS2)
self.assertEqual([p.value for p in series1.points], [VALUE1, VALUE1])
self.assertEqual([p.value for p in series2.points], [VALUE2, VALUE2])
self.assertEqual([p.end_time for p in series1.points], [TS1, TS2])
self.assertEqual([p.end_time for p in series2.points], [TS1, TS2])
expected_request = {
'method': 'GET',
'path': '/projects/{project}/timeSeries/'.format(project=PROJECT),
'query_params': [
('filter', 'metric.type = "{type}"'.format(type=METRIC_TYPE)),
('interval.endTime', T1.isoformat() + 'Z'),
('interval.startTime', T0.isoformat() + 'Z'),
],
}
request, = connection._requested
self.assertEqual(request, expected_request)
def test_iteration_paged(self):
import copy
import datetime
from gcloud.exceptions import NotFound
T0 = datetime.datetime(2016, 4, 6, 22, 5, 0)
T1 = datetime.datetime(2016, 4, 6, 22, 10, 0)
INTERVAL1 = {'startTime': TS0, 'endTime': TS1}
INTERVAL2 = {'startTime': TS1, 'endTime': TS2}
VALUE1 = 60 # seconds
VALUE2 = 60.001 # seconds
SERIES1 = {
'metric': {'type': METRIC_TYPE, 'labels': METRIC_LABELS},
'resource': {'type': RESOURCE_TYPE, 'labels': RESOURCE_LABELS},
'metricKind': METRIC_KIND,
'valueType': VALUE_TYPE,
'points': [
{'interval': INTERVAL2, 'value': {'doubleValue': VALUE1}},
{'interval': INTERVAL1, 'value': {'doubleValue': VALUE1}},
],
}
SERIES2_PART1 = {
'metric': {'type': METRIC_TYPE, 'labels': METRIC_LABELS2},
'resource': {'type': RESOURCE_TYPE, 'labels': RESOURCE_LABELS2},
'metricKind': METRIC_KIND,
'valueType': VALUE_TYPE,
'points': [
{'interval': INTERVAL2, 'value': {'doubleValue': VALUE2}},
],
}
SERIES2_PART2 = {
'metric': {'type': METRIC_TYPE, 'labels': METRIC_LABELS2},
'resource': {'type': RESOURCE_TYPE, 'labels': RESOURCE_LABELS2},
'metricKind': METRIC_KIND,
'valueType': VALUE_TYPE,
'points': [
{'interval': INTERVAL1, 'value': {'doubleValue': VALUE2}},
],
}
TOKEN = 'second-page-please'
RESPONSE1 = {'timeSeries': [SERIES1, SERIES2_PART1],
'nextPageToken': TOKEN}
RESPONSE2 = {'timeSeries': [SERIES2_PART2]}
connection = _Connection(RESPONSE1, RESPONSE2)
client = _Client(project=PROJECT, connection=connection)
query = self._makeOne(client, METRIC_TYPE)
query = query.select_interval(start_time=T0, end_time=T1)
response = list(query)
self.assertEqual(len(response), 2)
series1, series2 = response
self.assertEqual(series1.metric.labels, METRIC_LABELS)
self.assertEqual(series2.metric.labels, METRIC_LABELS2)
self.assertEqual(series1.resource.labels, RESOURCE_LABELS)
self.assertEqual(series2.resource.labels, RESOURCE_LABELS2)
self.assertEqual([p.value for p in series1.points], [VALUE1, VALUE1])
self.assertEqual([p.value for p in series2.points], [VALUE2, VALUE2])
self.assertEqual([p.end_time for p in series1.points], [TS1, TS2])
self.assertEqual([p.end_time for p in series2.points], [TS1, TS2])
expected_request1 = {
'method': 'GET',
'path': '/projects/{project}/timeSeries/'.format(project=PROJECT),
'query_params': [
('filter', 'metric.type = "{type}"'.format(type=METRIC_TYPE)),
('interval.endTime', T1.isoformat() + 'Z'),
('interval.startTime', T0.isoformat() + 'Z'),
],
}
expected_request2 = copy.deepcopy(expected_request1)
expected_request2['query_params'].append(('pageToken', TOKEN))
request1, request2 = connection._requested
self.assertEqual(request1, expected_request1)
self.assertEqual(request2, expected_request2)
with self.assertRaises(NotFound):
list(query)
def test_iteration_empty(self):
import datetime
T0 = datetime.datetime(2016, 4, 6, 22, 5, 0)
T1 = datetime.datetime(2016, 4, 6, 22, 10, 0)
connection = _Connection({})
client = _Client(project=PROJECT, connection=connection)
query = self._makeOne(client, METRIC_TYPE)
query = query.select_interval(start_time=T0, end_time=T1)
response = list(query)
self.assertEqual(len(response), 0)
expected_request = {
'method': 'GET',
'path': '/projects/{project}/timeSeries/'.format(project=PROJECT),
'query_params': [
('filter', 'metric.type = "{type}"'.format(type=METRIC_TYPE)),
('interval.endTime', T1.isoformat() + 'Z'),
('interval.startTime', T0.isoformat() + 'Z'),
],
}
request, = connection._requested
self.assertEqual(request, expected_request)
def test_iteration_headers_only(self):
import datetime
T0 = datetime.datetime(2016, 4, 6, 22, 5, 0)
T1 = datetime.datetime(2016, 4, 6, 22, 10, 0)
SERIES1 = {
'metric': {'type': METRIC_TYPE, 'labels': METRIC_LABELS},
'resource': {'type': RESOURCE_TYPE, 'labels': RESOURCE_LABELS},
'metricKind': METRIC_KIND,
'valueType': VALUE_TYPE,
}
SERIES2 = {
'metric': {'type': METRIC_TYPE, 'labels': METRIC_LABELS2},
'resource': {'type': RESOURCE_TYPE, 'labels': RESOURCE_LABELS2},
'metricKind': METRIC_KIND,
'valueType': VALUE_TYPE,
}
RESPONSE = {'timeSeries': [SERIES1, SERIES2]}
connection = _Connection(RESPONSE)
client = _Client(project=PROJECT, connection=connection)
query = self._makeOne(client, METRIC_TYPE)
query = query.select_interval(start_time=T0, end_time=T1)
response = list(query.iter(headers_only=True))
self.assertEqual(len(response), 2)
series1, series2 = response
self.assertEqual(series1.metric.labels, METRIC_LABELS)
self.assertEqual(series2.metric.labels, METRIC_LABELS2)
self.assertEqual(series1.resource.labels, RESOURCE_LABELS)
self.assertEqual(series2.resource.labels, RESOURCE_LABELS2)
self.assertEqual(series1.points, [])
self.assertEqual(series2.points, [])
expected_request = {
'method': 'GET',
'path': '/projects/{project}/timeSeries/'.format(project=PROJECT),
'query_params': [
('filter', 'metric.type = "{type}"'.format(type=METRIC_TYPE)),
('interval.endTime', T1.isoformat() + 'Z'),
('interval.startTime', T0.isoformat() + 'Z'),
('view', 'HEADERS'),
],
}
request, = connection._requested
self.assertEqual(request, expected_request)
class Test_Filter(unittest2.TestCase):
def _getTargetClass(self):
from gcloud.monitoring.query import _Filter
return _Filter
def _makeOne(self, metric_type):
return self._getTargetClass()(metric_type)
def test_minimal(self):
obj = self._makeOne(METRIC_TYPE)
expected = 'metric.type = "{type}"'.format(type=METRIC_TYPE)
self.assertEqual(str(obj), expected)
def test_maximal(self):
obj = self._makeOne(METRIC_TYPE)
obj.group_id = '1234567'
obj.projects = 'project-1', 'project-2'
obj.select_resources(resource_type='some-resource',
resource_label='foo')
obj.select_metrics(metric_label_prefix='bar-')
expected = (
'metric.type = "{type}"'
' AND group.id = "1234567"'
' AND project = "project-1" OR project = "project-2"'
' AND resource.label.resource_label = "foo"'
' AND resource.type = "some-resource"'
' AND metric.label.metric_label = starts_with("bar-")'
).format(type=METRIC_TYPE)
self.assertEqual(str(obj), expected)
class Test__build_label_filter(unittest2.TestCase):
def _callFUT(self, *args, **kwargs):
from gcloud.monitoring.query import _build_label_filter
return _build_label_filter(*args, **kwargs)
def test_no_labels(self):
self.assertEqual(self._callFUT('resource'), '')
def test_label_is_none(self):
self.assertEqual(self._callFUT('resource', foo=None), '')
def test_metric_labels(self):
actual = self._callFUT(
'metric',
alpha_prefix='a-',
beta_gamma_suffix='-b',
delta_epsilon='xyz',
)
expected = (
'metric.label.alpha = starts_with("a-")'
' AND metric.label.beta_gamma = ends_with("-b")'
' AND metric.label.delta_epsilon = "xyz"'
)
self.assertEqual(actual, expected)
def test_resource_labels(self):
actual = self._callFUT(
'resource',
alpha_prefix='a-',
beta_gamma_suffix='-b',
delta_epsilon='xyz',
)
expected = (
'resource.label.alpha = starts_with("a-")'
' AND resource.label.beta_gamma = ends_with("-b")'
' AND resource.label.delta_epsilon = "xyz"'
)
self.assertEqual(actual, expected)
def test_raw_label_filters(self):
actual = self._callFUT(
'resource',
'resource.label.alpha = starts_with("a-")',
'resource.label.beta_gamma = ends_with("-b")',
'resource.label.delta_epsilon = "xyz"',
)
expected = (
'resource.label.alpha = starts_with("a-")'
' AND resource.label.beta_gamma = ends_with("-b")'
' AND resource.label.delta_epsilon = "xyz"'
)
self.assertEqual(actual, expected)
def test_resource_type(self):
actual = self._callFUT('resource', resource_type='foo')
expected = 'resource.type = "foo"'
self.assertEqual(actual, expected)
def test_resource_type_prefix(self):
actual = self._callFUT('resource', resource_type_prefix='foo-')
expected = 'resource.type = starts_with("foo-")'
self.assertEqual(actual, expected)
def test_resource_type_suffix(self):
actual = self._callFUT('resource', resource_type_suffix='-foo')
expected = 'resource.type = ends_with("-foo")'
self.assertEqual(actual, expected)
class Test__format_timestamp(unittest2.TestCase):
def _callFUT(self, timestamp):
from gcloud.monitoring.query import _format_timestamp
return _format_timestamp(timestamp)
def test_naive(self):
from datetime import datetime
TIMESTAMP = datetime(2016, 4, 5, 13, 30, 0)
timestamp = self._callFUT(TIMESTAMP)
self.assertEqual(timestamp, '2016-04-05T13:30:00Z')
def test_with_timezone(self):
from datetime import datetime
from gcloud._helpers import UTC
TIMESTAMP = datetime(2016, 4, 5, 13, 30, 0, tzinfo=UTC)
timestamp = self._callFUT(TIMESTAMP)
self.assertEqual(timestamp, '2016-04-05T13:30:00Z')
class _Connection(object):
def __init__(self, *responses):
self._responses = list(responses)
self._requested = []
def api_request(self, **kwargs):
from gcloud.exceptions import NotFound
self._requested.append(kwargs)
try:
return self._responses.pop(0)
except IndexError:
raise NotFound('miss')
class _Client(object):
def __init__(self, project, connection):
self.project = project
self.connection = connection
| apache-2.0 | [
3,
1898,
7800,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
2882,
18,
199,
199,
10797,
275,
283,
1662,
13,
1715,
7,
199,
199,
20141,
63,
2711,
275,
283,
3357,
14,
17533,
14,
957,
15,
842,
15,
24853,
7,
199,
20141,
63,
13837,
51,
275,
791,
842,
63,
354,
356,
283,
842,
13,
17,
936,
199,
20141,
63,
13837,
51,
18,
275,
791,
842,
63,
354,
356,
283,
842,
13,
18,
936,
199,
199,
14110,
63,
2711,
275,
283,
22833,
63,
842,
7,
199,
14110,
63,
13837,
51,
275,
469,
272,
283,
1715,
63,
344,
356,
283,
1662,
13,
1715,
297,
272,
283,
2619,
356,
283,
527,
13,
14346,
17,
13,
65,
297,
272,
283,
842,
63,
344,
356,
283,
11272,
11371,
297,
199,
93,
199,
14110,
63,
13837,
51,
18,
275,
469,
272,
283,
1715,
63,
344,
356,
283,
1662,
13,
1715,
297,
272,
283,
2619,
356,
283,
527,
13,
14346,
17,
13,
66,
297,
272,
283,
842,
63,
344,
356,
283,
23358,
11157,
708,
6996,
1555,
11157,
12638,
297,
199,
93,
199,
199,
20141,
63,
43,
3192,
275,
283,
4424,
6166,
7,
199,
7041,
63,
2711,
275,
283,
14989,
7,
199,
199,
9730,
16,
275,
283,
9261,
13,
966,
13,
1690,
52,
1081,
26,
1717,
26,
383,
14,
13011,
58,
7,
199,
9730,
17,
275,
283,
9261,
13,
966,
13,
1690,
52,
1081,
26,
1717,
26,
614,
14,
13011,
58,
7,
199,
9730,
18,
275,
283,
9261,
13,
966,
13,
1690,
52,
1081,
26,
1717,
26,
996,
14,
13011,
58,
7,
421,
199,
533,
1379,
9497,
281,
8,
2796,
18,
14,
1746,
304,
339,
347,
485,
362,
4277,
2543,
8,
277,
304,
267,
687,
486,
4091,
14,
20554,
14,
1131,
492,
15170,
784,
281,
267,
372,
15170,
784,
281,
339,
347,
511,
63,
368,
8,
277,
304,
267,
291,
14,
1815,
8,
11161,
8,
277,
423,
362,
4277,
2543,
1062,
283,
15255,
63,
16553,
1333,
339,
347,
511,
63,
1247,
8,
277,
304,
267,
367,
536,
315,
291,
423,
362,
4277,
2543,
11027,
807,
10651,
288,
340,
440,
536,
14,
2460,
30018,
355,
291,
14,
629,
8,
5675,
8,
277,
423,
362,
4277,
2543,
1062,
536,
395,
536,
9,
421,
199,
533,
1379,
10858,
947,
281,
8,
2796,
18,
14,
1746,
304,
339,
347,
485,
362,
4277,
2543,
8,
277,
304,
267,
687,
486,
4091,
14,
20554,
14,
1131,
492,
9572,
947,
281,
267,
372,
9572,
947,
281,
339,
347,
511,
63,
368,
8,
277,
304,
267,
291,
14,
1815,
8,
11161,
8,
277,
423,
362,
4277,
2543,
1062,
1816,
283,
907,
4980,
2089,
63,
4227,
17349,
8453,
63,
1020,
1333,
339,
347,
511,
63,
1247,
8,
277,
304,
267,
367,
536,
315,
291,
423,
362,
4277,
2543,
11027,
807,
10651,
288,
340,
440,
536,
14,
2460,
30018,
355,
291,
14,
629,
8,
5675,
8,
277,
423,
362,
4277,
2543,
1062,
536,
395,
536,
9,
421,
199,
533,
1379,
3227,
8,
2796,
18,
14,
1746,
304,
339,
347,
485,
362,
4277,
2543,
8,
277,
304,
267,
687,
486,
4091,
14,
20554,
14,
1131,
492,
8133,
267,
372,
8133,
339,
347,
485,
32273,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
291,
423,
362,
4277,
2543,
342,
2031,
589,
12,
1011,
958,
9,
339,
347,
511,
63,
1880,
63,
21508,
8,
277,
304,
267,
1890,
275,
485,
3041,
8,
1715,
29,
10797,
12,
1950,
3699,
3225,
1012,
267,
1827,
275,
291,
423,
32273,
8,
1258,
9,
398,
291,
14,
629,
8,
1131,
423,
1258,
12,
1890,
9,
267,
291,
14,
629,
8,
1131,
423,
1541,
14,
5165,
63,
466,
12,
586,
291,
423,
362,
4277,
2543,
1252,
3472,
63,
20141,
63,
2711,
9,
398,
291,
14,
7702,
8,
1131,
423,
928,
63,
521,
9,
267,
291,
14,
7702,
8,
1131,
423,
500,
63,
521,
9,
398,
291,
14,
7702,
8,
1131,
423,
529,
63,
5602,
63,
5743,
281,
9,
267,
291,
14,
7702,
8,
1131,
423,
13699,
63,
5191,
63,
4515,
9,
267,
291,
14,
7702,
8,
1131,
423,
7925,
63,
5602,
63,
581,
947,
281,
9,
267,
291,
14,
629,
8,
1131,
423,
923,
63,
991,
63,
955,
12,
14515,
339,
347,
511,
63,
1880,
63,
988,
7265,
8,
277,
304,
267,
492,
2197,
398,
377,
17,
275,
2197,
14,
2083,
8,
9261,
12,
841,
12,
1520,
12,
499,
12,
4233,
12,
4233,
9,
267,
577,
3448,
51,
12,
7781,
28746,
12,
15861,
934,
654,
275,
413,
12,
499,
12,
650,
267,
377,
16,
275,
377,
17,
446,
2197,
14,
7473,
8,
4899,
29,
25683,
12,
10857,
29,
2979,
28746,
12,
9395,
29,
4896,
934,
654,
9,
398,
1890,
275,
485,
3041,
8,
1715,
29,
10797,
12,
1950,
3699,
3225,
1012,
267,
1827,
275,
291,
423,
32273,
8,
1258,
12,
19357,
14673,
63,
2711,
12,
2892,
1284,
63,
521,
29,
52,
17,
12,
2892,
7609,
29,
25683,
12,
10857,
29,
2979,
28746,
12,
9395,
29,
4896,
934,
654,
9,
398,
291,
14,
629,
8,
1131,
423,
1258,
12,
1890,
9,
267,
291,
14,
629,
8,
1131,
423,
1541,
14,
5165,
63,
466,
12,
19357,
14673,
63,
2711,
9,
398,
291,
14,
629,
8,
1131,
423,
928,
63,
521,
12,
377,
16,
9,
267,
291,
14,
629,
8,
1131,
423,
500,
63,
521,
12,
377,
17,
9,
398,
291,
14,
7702,
8,
1131,
423,
529,
63,
5602,
63,
5743,
281,
9,
267,
291,
14,
7702,
8,
1131,
423
] | [
1898,
7800,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
2882,
18,
199,
199,
10797,
275,
283,
1662,
13,
1715,
7,
199,
199,
20141,
63,
2711,
275,
283,
3357,
14,
17533,
14,
957,
15,
842,
15,
24853,
7,
199,
20141,
63,
13837,
51,
275,
791,
842,
63,
354,
356,
283,
842,
13,
17,
936,
199,
20141,
63,
13837,
51,
18,
275,
791,
842,
63,
354,
356,
283,
842,
13,
18,
936,
199,
199,
14110,
63,
2711,
275,
283,
22833,
63,
842,
7,
199,
14110,
63,
13837,
51,
275,
469,
272,
283,
1715,
63,
344,
356,
283,
1662,
13,
1715,
297,
272,
283,
2619,
356,
283,
527,
13,
14346,
17,
13,
65,
297,
272,
283,
842,
63,
344,
356,
283,
11272,
11371,
297,
199,
93,
199,
14110,
63,
13837,
51,
18,
275,
469,
272,
283,
1715,
63,
344,
356,
283,
1662,
13,
1715,
297,
272,
283,
2619,
356,
283,
527,
13,
14346,
17,
13,
66,
297,
272,
283,
842,
63,
344,
356,
283,
23358,
11157,
708,
6996,
1555,
11157,
12638,
297,
199,
93,
199,
199,
20141,
63,
43,
3192,
275,
283,
4424,
6166,
7,
199,
7041,
63,
2711,
275,
283,
14989,
7,
199,
199,
9730,
16,
275,
283,
9261,
13,
966,
13,
1690,
52,
1081,
26,
1717,
26,
383,
14,
13011,
58,
7,
199,
9730,
17,
275,
283,
9261,
13,
966,
13,
1690,
52,
1081,
26,
1717,
26,
614,
14,
13011,
58,
7,
199,
9730,
18,
275,
283,
9261,
13,
966,
13,
1690,
52,
1081,
26,
1717,
26,
996,
14,
13011,
58,
7,
421,
199,
533,
1379,
9497,
281,
8,
2796,
18,
14,
1746,
304,
339,
347,
485,
362,
4277,
2543,
8,
277,
304,
267,
687,
486,
4091,
14,
20554,
14,
1131,
492,
15170,
784,
281,
267,
372,
15170,
784,
281,
339,
347,
511,
63,
368,
8,
277,
304,
267,
291,
14,
1815,
8,
11161,
8,
277,
423,
362,
4277,
2543,
1062,
283,
15255,
63,
16553,
1333,
339,
347,
511,
63,
1247,
8,
277,
304,
267,
367,
536,
315,
291,
423,
362,
4277,
2543,
11027,
807,
10651,
288,
340,
440,
536,
14,
2460,
30018,
355,
291,
14,
629,
8,
5675,
8,
277,
423,
362,
4277,
2543,
1062,
536,
395,
536,
9,
421,
199,
533,
1379,
10858,
947,
281,
8,
2796,
18,
14,
1746,
304,
339,
347,
485,
362,
4277,
2543,
8,
277,
304,
267,
687,
486,
4091,
14,
20554,
14,
1131,
492,
9572,
947,
281,
267,
372,
9572,
947,
281,
339,
347,
511,
63,
368,
8,
277,
304,
267,
291,
14,
1815,
8,
11161,
8,
277,
423,
362,
4277,
2543,
1062,
1816,
283,
907,
4980,
2089,
63,
4227,
17349,
8453,
63,
1020,
1333,
339,
347,
511,
63,
1247,
8,
277,
304,
267,
367,
536,
315,
291,
423,
362,
4277,
2543,
11027,
807,
10651,
288,
340,
440,
536,
14,
2460,
30018,
355,
291,
14,
629,
8,
5675,
8,
277,
423,
362,
4277,
2543,
1062,
536,
395,
536,
9,
421,
199,
533,
1379,
3227,
8,
2796,
18,
14,
1746,
304,
339,
347,
485,
362,
4277,
2543,
8,
277,
304,
267,
687,
486,
4091,
14,
20554,
14,
1131,
492,
8133,
267,
372,
8133,
339,
347,
485,
32273,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
372,
291,
423,
362,
4277,
2543,
342,
2031,
589,
12,
1011,
958,
9,
339,
347,
511,
63,
1880,
63,
21508,
8,
277,
304,
267,
1890,
275,
485,
3041,
8,
1715,
29,
10797,
12,
1950,
3699,
3225,
1012,
267,
1827,
275,
291,
423,
32273,
8,
1258,
9,
398,
291,
14,
629,
8,
1131,
423,
1258,
12,
1890,
9,
267,
291,
14,
629,
8,
1131,
423,
1541,
14,
5165,
63,
466,
12,
586,
291,
423,
362,
4277,
2543,
1252,
3472,
63,
20141,
63,
2711,
9,
398,
291,
14,
7702,
8,
1131,
423,
928,
63,
521,
9,
267,
291,
14,
7702,
8,
1131,
423,
500,
63,
521,
9,
398,
291,
14,
7702,
8,
1131,
423,
529,
63,
5602,
63,
5743,
281,
9,
267,
291,
14,
7702,
8,
1131,
423,
13699,
63,
5191,
63,
4515,
9,
267,
291,
14,
7702,
8,
1131,
423,
7925,
63,
5602,
63,
581,
947,
281,
9,
267,
291,
14,
629,
8,
1131,
423,
923,
63,
991,
63,
955,
12,
14515,
339,
347,
511,
63,
1880,
63,
988,
7265,
8,
277,
304,
267,
492,
2197,
398,
377,
17,
275,
2197,
14,
2083,
8,
9261,
12,
841,
12,
1520,
12,
499,
12,
4233,
12,
4233,
9,
267,
577,
3448,
51,
12,
7781,
28746,
12,
15861,
934,
654,
275,
413,
12,
499,
12,
650,
267,
377,
16,
275,
377,
17,
446,
2197,
14,
7473,
8,
4899,
29,
25683,
12,
10857,
29,
2979,
28746,
12,
9395,
29,
4896,
934,
654,
9,
398,
1890,
275,
485,
3041,
8,
1715,
29,
10797,
12,
1950,
3699,
3225,
1012,
267,
1827,
275,
291,
423,
32273,
8,
1258,
12,
19357,
14673,
63,
2711,
12,
2892,
1284,
63,
521,
29,
52,
17,
12,
2892,
7609,
29,
25683,
12,
10857,
29,
2979,
28746,
12,
9395,
29,
4896,
934,
654,
9,
398,
291,
14,
629,
8,
1131,
423,
1258,
12,
1890,
9,
267,
291,
14,
629,
8,
1131,
423,
1541,
14,
5165,
63,
466,
12,
19357,
14673,
63,
2711,
9,
398,
291,
14,
629,
8,
1131,
423,
928,
63,
521,
12,
377,
16,
9,
267,
291,
14,
629,
8,
1131,
423,
500,
63,
521,
12,
377,
17,
9,
398,
291,
14,
7702,
8,
1131,
423,
529,
63,
5602,
63,
5743,
281,
9,
267,
291,
14,
7702,
8,
1131,
423,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bitsauce/Sauce-Engine | 3rdparty/SDL/src/joystick/sort_controllers.py | 84 | 1974 | #!/usr/bin/env python
#
# Script to sort the game controller database entries in SDL_gamecontroller.c
import re
filename = "SDL_gamecontrollerdb.h"
input = open(filename)
output = open(filename + ".new", "w")
parsing_controllers = False
controllers = []
controller_guids = {}
split_pattern = re.compile(r'([^"]*")([^,]*,)([^,]*,)([^"]*)(".*)')
def save_controller(line):
global controllers
match = split_pattern.match(line)
entry = [ match.group(1), match.group(2), match.group(3) ]
bindings = sorted(match.group(4).split(","))
if (bindings[0] == ""):
bindings.pop(0)
entry.extend(",".join(bindings) + ",")
entry.append(match.group(5))
controllers.append(entry)
def write_controllers():
global controllers
global controller_guids
for entry in sorted(controllers, key=lambda entry: entry[2]):
line = "".join(entry) + "\n"
if not line.endswith(",\n") and not line.endswith("*/\n"):
print "Warning: '%s' is missing a comma at the end of the line" % (line)
if (entry[1] in controller_guids):
print "Warning: entry '%s' is duplicate of entry '%s'" % (entry[2], controller_guids[entry[1]][2])
controller_guids[entry[1]] = entry
output.write(line)
controllers = []
controller_guids = {}
for line in input:
if ( parsing_controllers ):
if (line.startswith("{")):
output.write(line)
elif (line.startswith("#endif")):
parsing_controllers = False
write_controllers()
output.write(line)
elif (line.startswith("#")):
print "Parsing " + line.strip()
write_controllers()
output.write(line)
else:
save_controller(line)
else:
if (line.startswith("static const char *s_ControllerMappings")):
parsing_controllers = True
output.write(line)
output.close()
print "Finished writing %s.new" % filename
| lgpl-2.1 | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
14914,
370,
4069,
314,
9219,
7614,
3050,
4811,
315,
14314,
63,
5097,
5538,
14,
67,
199,
199,
646,
295,
421,
199,
1501,
275,
298,
14029,
63,
5097,
5538,
697,
14,
72,
2,
199,
1210,
275,
1551,
8,
1501,
9,
199,
1199,
275,
1551,
8,
1501,
435,
3680,
1222,
401,
298,
87,
531,
199,
11059,
63,
20531,
275,
756,
199,
20531,
275,
942,
199,
5538,
63,
9473,
83,
275,
1052,
199,
1294,
63,
3401,
275,
295,
14,
2014,
8,
82,
7,
15710,
10,
531,
7059,
12,
3672,
4258,
7059,
12,
3672,
4258,
15710,
13278,
480,
2795,
5942,
199,
199,
318,
3354,
63,
5538,
8,
604,
304,
272,
2288,
27325,
272,
1336,
275,
3715,
63,
3401,
14,
1431,
8,
604,
9,
272,
2397,
275,
359,
1336,
14,
923,
8,
17,
395,
1336,
14,
923,
8,
18,
395,
1336,
14,
923,
8,
19,
9,
1622,
272,
17792,
275,
3355,
8,
1431,
14,
923,
8,
20,
680,
1294,
11854,
2237,
272,
340,
334,
10880,
59,
16,
61,
508,
26430,
267,
17792,
14,
1935,
8,
16,
9,
272,
2397,
14,
2880,
11854,
1674,
904,
8,
10880,
9,
435,
3872,
531,
272,
2397,
14,
740,
8,
1431,
14,
923,
8,
21,
430,
272,
27325,
14,
740,
8,
2373,
9,
199,
199,
318,
2218,
63,
20531,
837,
272,
2288,
27325,
272,
2288,
7614,
63,
9473,
83,
272,
367,
2397,
315,
3355,
8,
20531,
12,
790,
29,
2734,
2397,
26,
2397,
59,
18,
4682,
267,
1004,
275,
10587,
904,
8,
2373,
9,
435,
1867,
78,
2,
267,
340,
440,
1004,
14,
4130,
11854,
60,
78,
531,
436,
440,
1004,
14,
4130,
23124,
6307,
78,
2349,
288,
870,
298,
3849,
26,
1543,
83,
7,
365,
4124,
282,
10029,
737,
314,
1284,
402,
314,
1004,
2,
450,
334,
604,
9,
267,
340,
334,
2373,
59,
17,
61,
315,
7614,
63,
9473,
83,
304,
288,
870,
298,
3849,
26,
2397,
1543,
83,
7,
365,
9250,
402,
2397,
1543,
83,
4065,
450,
334,
2373,
59,
18,
467,
7614,
63,
9473,
83,
59,
2373,
59,
17,
22235,
18,
566,
267,
7614,
63,
9473,
83,
59,
2373,
59,
17,
2677,
275,
2397,
398,
1072,
14,
952,
8,
604,
9,
272,
27325,
275,
942,
272,
7614,
63,
9473,
83,
275,
1052,
199,
199,
509,
1004,
315,
1324,
26,
272,
340,
334,
6057,
63,
20531,
3461,
267,
340,
334,
604,
14,
2460,
13076,
14150,
288,
1072,
14,
952,
8,
604,
9,
267,
916,
334,
604,
14,
2460,
10064,
13739,
14150,
288,
6057,
63,
20531,
275,
756,
288,
2218,
63,
20531,
342,
288,
1072,
14,
952,
8,
604,
9,
267,
916,
334,
604,
14,
2460,
10064,
14150,
288,
870,
298,
17412,
298,
435,
1004,
14,
1913,
342,
288,
2218,
63,
20531,
342,
288,
1072,
14,
952,
8,
604,
9,
267,
587,
26,
288,
3354,
63,
5538,
8,
604,
9,
272,
587,
26,
267,
340,
334,
604,
14,
2460,
480,
1986,
950,
1495,
627,
83,
63,
7506,
45,
12020,
14150,
288,
6057,
63,
20531,
275,
715,
398,
1072,
14,
952,
8,
604,
9,
199,
199,
1199,
14,
1600,
342,
199,
1361,
298,
13430,
3575,
450,
83,
14,
1222,
2,
450,
1788,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
14914,
370,
4069,
314,
9219,
7614,
3050,
4811,
315,
14314,
63,
5097,
5538,
14,
67,
199,
199,
646,
295,
421,
199,
1501,
275,
298,
14029,
63,
5097,
5538,
697,
14,
72,
2,
199,
1210,
275,
1551,
8,
1501,
9,
199,
1199,
275,
1551,
8,
1501,
435,
3680,
1222,
401,
298,
87,
531,
199,
11059,
63,
20531,
275,
756,
199,
20531,
275,
942,
199,
5538,
63,
9473,
83,
275,
1052,
199,
1294,
63,
3401,
275,
295,
14,
2014,
8,
82,
7,
15710,
10,
531,
7059,
12,
3672,
4258,
7059,
12,
3672,
4258,
15710,
13278,
480,
2795,
5942,
199,
199,
318,
3354,
63,
5538,
8,
604,
304,
272,
2288,
27325,
272,
1336,
275,
3715,
63,
3401,
14,
1431,
8,
604,
9,
272,
2397,
275,
359,
1336,
14,
923,
8,
17,
395,
1336,
14,
923,
8,
18,
395,
1336,
14,
923,
8,
19,
9,
1622,
272,
17792,
275,
3355,
8,
1431,
14,
923,
8,
20,
680,
1294,
11854,
2237,
272,
340,
334,
10880,
59,
16,
61,
508,
26430,
267,
17792,
14,
1935,
8,
16,
9,
272,
2397,
14,
2880,
11854,
1674,
904,
8,
10880,
9,
435,
3872,
531,
272,
2397,
14,
740,
8,
1431,
14,
923,
8,
21,
430,
272,
27325,
14,
740,
8,
2373,
9,
199,
199,
318,
2218,
63,
20531,
837,
272,
2288,
27325,
272,
2288,
7614,
63,
9473,
83,
272,
367,
2397,
315,
3355,
8,
20531,
12,
790,
29,
2734,
2397,
26,
2397,
59,
18,
4682,
267,
1004,
275,
10587,
904,
8,
2373,
9,
435,
1867,
78,
2,
267,
340,
440,
1004,
14,
4130,
11854,
60,
78,
531,
436,
440,
1004,
14,
4130,
23124,
6307,
78,
2349,
288,
870,
298,
3849,
26,
1543,
83,
7,
365,
4124,
282,
10029,
737,
314,
1284,
402,
314,
1004,
2,
450,
334,
604,
9,
267,
340,
334,
2373,
59,
17,
61,
315,
7614,
63,
9473,
83,
304,
288,
870,
298,
3849,
26,
2397,
1543,
83,
7,
365,
9250,
402,
2397,
1543,
83,
4065,
450,
334,
2373,
59,
18,
467,
7614,
63,
9473,
83,
59,
2373,
59,
17,
22235,
18,
566,
267,
7614,
63,
9473,
83,
59,
2373,
59,
17,
2677,
275,
2397,
398,
1072,
14,
952,
8,
604,
9,
272,
27325,
275,
942,
272,
7614,
63,
9473,
83,
275,
1052,
199,
199,
509,
1004,
315,
1324,
26,
272,
340,
334,
6057,
63,
20531,
3461,
267,
340,
334,
604,
14,
2460,
13076,
14150,
288,
1072,
14,
952,
8,
604,
9,
267,
916,
334,
604,
14,
2460,
10064,
13739,
14150,
288,
6057,
63,
20531,
275,
756,
288,
2218,
63,
20531,
342,
288,
1072,
14,
952,
8,
604,
9,
267,
916,
334,
604,
14,
2460,
10064,
14150,
288,
870,
298,
17412,
298,
435,
1004,
14,
1913,
342,
288,
2218,
63,
20531,
342,
288,
1072,
14,
952,
8,
604,
9,
267,
587,
26,
288,
3354,
63,
5538,
8,
604,
9,
272,
587,
26,
267,
340,
334,
604,
14,
2460,
480,
1986,
950,
1495,
627,
83,
63,
7506,
45,
12020,
14150,
288,
6057,
63,
20531,
275,
715,
398,
1072,
14,
952,
8,
604,
9,
199,
199,
1199,
14,
1600,
342,
199,
1361,
298,
13430,
3575,
450,
83,
14,
1222,
2,
450,
1788,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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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
] |
drax68/graphite-web | webapp/graphite/metrics/urls.py | 5 | 1063 | """Copyright 2009 Chris Davis
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License."""
from django.conf.urls import url
from . import views
urlpatterns = [
url('^index\.json$', views.index_json, name='metrics_index'),
url('^find/?$', views.find_view, name='metrics_find'),
url('^expand/?$', views.expand_view, name='metrics_expand'),
url('^get-metadata/?$', views.get_metadata_view,
name='metrics_get_metadata'),
url('^set-metadata/?$', views.set_metadata_view,
name='metrics_set_metadata'),
url('', views.find_view, name='metrics'),
]
| apache-2.0 | [
624,
7384,
8937,
2799,
5719,
577,
1214,
374,
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,
8410,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
2043,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2043,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
2043,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
2043,
4204,
1334,
314,
844,
1041,
199,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1275,
492,
6858,
199,
199,
20050,
275,
359,
272,
1166,
9097,
1080,
4537,
1001,
4268,
6858,
14,
1080,
63,
1001,
12,
536,
534,
6759,
63,
1080,
659,
272,
1166,
9097,
1623,
10197,
4268,
6858,
14,
1623,
63,
1345,
12,
536,
534,
6759,
63,
1623,
659,
272,
1166,
9097,
4441,
10197,
4268,
6858,
14,
4441,
63,
1345,
12,
536,
534,
6759,
63,
4441,
659,
272,
1166,
9097,
362,
13,
2343,
10197,
4268,
6858,
14,
362,
63,
2343,
63,
1345,
12,
267,
536,
534,
6759,
63,
362,
63,
2343,
659,
272,
1166,
9097,
409,
13,
2343,
10197,
4268,
6858,
14,
409,
63,
2343,
63,
1345,
12,
267,
536,
534,
6759,
63,
409,
63,
2343,
659,
272,
1166,
8594,
6858,
14,
1623,
63,
1345,
12,
536,
534,
6759,
659,
199,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
7384,
8937,
2799,
5719,
577,
1214,
374,
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,
8410,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
2043,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2043,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
2043,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
2043,
4204,
1334,
314,
844,
1041,
199,
199,
504,
1639,
14,
2190,
14,
3603,
492,
1166,
199,
504,
1275,
492,
6858,
199,
199,
20050,
275,
359,
272,
1166,
9097,
1080,
4537,
1001,
4268,
6858,
14,
1080,
63,
1001,
12,
536,
534,
6759,
63,
1080,
659,
272,
1166,
9097,
1623,
10197,
4268,
6858,
14,
1623,
63,
1345,
12,
536,
534,
6759,
63,
1623,
659,
272,
1166,
9097,
4441,
10197,
4268,
6858,
14,
4441,
63,
1345,
12,
536,
534,
6759,
63,
4441,
659,
272,
1166,
9097,
362,
13,
2343,
10197,
4268,
6858,
14,
362,
63,
2343,
63,
1345,
12,
267,
536,
534,
6759,
63,
362,
63,
2343,
659,
272,
1166,
9097,
409,
13,
2343,
10197,
4268,
6858,
14,
409,
63,
2343,
63,
1345,
12,
267,
536,
534,
6759,
63,
409,
63,
2343,
659,
272,
1166,
8594,
6858,
14,
1623,
63,
1345,
12,
536,
534,
6759,
659,
199,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
pku9104038/edx-platform | cms/envs/dev.py | 2 | 6563 | """
This config file runs the simplest dev environment"""
# We intentionally define lots of variables that aren't used, and
# want to import all variables from base settings files
# pylint: disable=W0401, W0614
from .common import *
from logsettings import get_logger_config
DEBUG = True
TEMPLATE_DEBUG = DEBUG
LOGGING = get_logger_config(ENV_ROOT / "log",
logging_env="dev",
tracking_filename="tracking.log",
dev_env=True,
debug=True)
modulestore_options = {
'default_class': 'xmodule.raw_module.RawDescriptor',
'fs_root': GITHUB_REPO_ROOT,
'render_template': 'edxmako.shortcuts.render_to_string',
}
MODULESTORE = {
'default': {
'ENGINE': 'xmodule.modulestore.draft.DraftModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options
},
'direct': {
'ENGINE': 'xmodule.modulestore.mongo.MongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options
},
'split': {
'ENGINE': 'xmodule.modulestore.split_mongo.SplitMongoModuleStore',
'DOC_STORE_CONFIG': DOC_STORE_CONFIG,
'OPTIONS': modulestore_options
}
}
# cdodge: This is the specifier for the MongoDB (using GridFS) backed static content store
# This is for static content for courseware, not system static content (e.g. javascript, css, edX branding, etc)
CONTENTSTORE = {
'ENGINE': 'xmodule.contentstore.mongo.MongoContentStore',
'DOC_STORE_CONFIG': {
'host': 'localhost',
'db': 'xcontent',
},
# allow for additional options that can be keyed on a name, e.g. 'trashcan'
'ADDITIONAL_OPTIONS': {
'trashcan': {
'bucket': 'trash_fs'
}
}
}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ENV_ROOT / "db" / "edx.db",
}
}
LMS_BASE = "localhost:8000"
FEATURES['PREVIEW_LMS_BASE'] = "localhost:8000"
REPOS = {
'edx4edx': {
'branch': 'master',
'origin': '[email protected]:MITx/edx4edx.git',
},
'content-mit-6002x': {
'branch': 'master',
# 'origin': '[email protected]:MITx/6002x-fall-2012.git',
'origin': '[email protected]:MITx/content-mit-6002x.git',
},
'6.00x': {
'branch': 'master',
'origin': '[email protected]:MITx/6.00x.git',
},
'7.00x': {
'branch': 'master',
'origin': '[email protected]:MITx/7.00x.git',
},
'3.091x': {
'branch': 'master',
'origin': '[email protected]:MITx/3.091x.git',
},
}
CACHES = {
# This is the cache used for most things. Askbot will not work without a
# functioning cache -- it relies on caching to load its settings in places.
# In staging/prod envs, the sessions also live here.
'default': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'edx_loc_mem_cache',
'KEY_FUNCTION': 'util.memcache.safe_key',
},
# The general cache is what you get if you use our util.cache. It's used for
# things like caching the course.xml file for different A/B test groups.
# We set it to be a DummyCache to force reloading of course.xml in dev.
# In staging environments, we would grab VERSION from data uploaded by the
# push process.
'general': {
'BACKEND': 'django.core.cache.backends.dummy.DummyCache',
'KEY_PREFIX': 'general',
'VERSION': 4,
'KEY_FUNCTION': 'util.memcache.safe_key',
},
'mongo_metadata_inheritance': {
'BACKEND': 'django.core.cache.backends.filebased.FileBasedCache',
'LOCATION': '/var/tmp/mongo_metadata_inheritance',
'TIMEOUT': 300,
'KEY_FUNCTION': 'util.memcache.safe_key',
},
'loc_cache': {
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
'LOCATION': 'edx_location_mem_cache',
},
}
# Make the keyedcache startup warnings go away
CACHE_TIMEOUT = 0
# Dummy secret key for dev
SECRET_KEY = '85920908f28904ed733fe576320db18cabd7b6cd'
################################ PIPELINE #################################
PIPELINE_SASS_ARGUMENTS = '--debug-info --require {proj_dir}/static/sass/bourbon/lib/bourbon.rb'.format(proj_dir=PROJECT_ROOT)
################################# CELERY ######################################
# By default don't use a worker, execute tasks as if they were local functions
CELERY_ALWAYS_EAGER = True
################################ DEBUG TOOLBAR #################################
INSTALLED_APPS += ('debug_toolbar', 'debug_toolbar_mongo')
MIDDLEWARE_CLASSES += ('debug_toolbar.middleware.DebugToolbarMiddleware',)
INTERNAL_IPS = ('127.0.0.1',)
DEBUG_TOOLBAR_PANELS = (
'debug_toolbar.panels.version.VersionDebugPanel',
'debug_toolbar.panels.timer.TimerDebugPanel',
'debug_toolbar.panels.settings_vars.SettingsVarsDebugPanel',
'debug_toolbar.panels.headers.HeaderDebugPanel',
'debug_toolbar.panels.request_vars.RequestVarsDebugPanel',
'debug_toolbar.panels.sql.SQLDebugPanel',
'debug_toolbar.panels.signals.SignalDebugPanel',
'debug_toolbar.panels.logger.LoggingPanel',
# Enabling the profiler has a weird bug as of django-debug-toolbar==0.9.4 and
# Django=1.3.1/1.4 where requests to views get duplicated (your method gets
# hit twice). So you can uncomment when you need to diagnose performance
# problems, but you shouldn't leave it on.
# 'debug_toolbar.panels.profiling.ProfilingDebugPanel',
)
DEBUG_TOOLBAR_CONFIG = {
'INTERCEPT_REDIRECTS': False
}
# To see stacktraces for MongoDB queries, set this to True.
# Stacktraces slow down page loads drastically (for pages with lots of queries).
DEBUG_TOOLBAR_MONGO_STACKTRACES = False
# disable NPS survey in dev mode
FEATURES['STUDIO_NPS_SURVEY'] = False
# Enable URL that shows information about the status of variuous services
FEATURES['ENABLE_SERVICE_STATUS'] = True
############################# SEGMENT-IO ##################################
# If there's an environment variable set, grab it and turn on Segment.io
# Note that this is the Studio key. There is a separate key for the LMS.
import os
SEGMENT_IO_KEY = os.environ.get('SEGMENT_IO_KEY')
if SEGMENT_IO_KEY:
FEATURES['SEGMENT_IO'] = True
#####################################################################
# Lastly, see if the developer has any local overrides.
try:
from .private import * # pylint: disable=F0401
except ImportError:
pass
| agpl-3.0 | [
624,
199,
2765,
1101,
570,
7858,
314,
3486,
270,
4866,
3734,
624,
199,
199,
3,
2136,
32005,
5627,
24213,
402,
2860,
626,
10621,
1133,
1202,
12,
436,
199,
3,
2934,
370,
492,
1006,
2860,
687,
1300,
2202,
1584,
199,
3,
4287,
26,
3507,
29,
55,
28025,
12,
644,
1690,
1079,
199,
199,
504,
1275,
2330,
492,
627,
199,
504,
943,
1751,
492,
664,
63,
2921,
63,
888,
199,
199,
5287,
275,
715,
199,
7433,
63,
5287,
275,
10990,
199,
27896,
275,
664,
63,
2921,
63,
888,
8,
9984,
63,
5441,
1182,
298,
793,
401,
1169,
2050,
63,
1813,
628,
2374,
401,
1169,
15161,
63,
1501,
628,
14428,
14,
793,
401,
1169,
4866,
63,
1813,
29,
549,
12,
1169,
3105,
29,
549,
9,
199,
199,
10012,
63,
1419,
275,
469,
272,
283,
885,
63,
533,
356,
283,
14293,
14,
1773,
63,
578,
14,
7963,
4311,
297,
272,
283,
2319,
63,
1231,
356,
598,
30087,
63,
20424,
63,
5441,
12,
272,
283,
3352,
63,
1160,
356,
283,
8268,
19491,
14,
17469,
14,
3352,
63,
475,
63,
875,
297,
199,
93,
199,
199,
27011,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
14293,
14,
10012,
14,
7185,
14,
18332,
14389,
297,
267,
283,
16618,
63,
16169,
63,
5569,
356,
3506,
35,
63,
16169,
63,
5569,
12,
267,
283,
8808,
356,
10996,
63,
1419,
272,
1660,
272,
283,
2275,
356,
469,
267,
283,
15956,
356,
283,
14293,
14,
10012,
14,
9217,
14,
20393,
14389,
297,
267,
283,
16618,
63,
16169,
63,
5569,
356,
3506,
35,
63,
16169,
63,
5569,
12,
267,
283,
8808,
356,
10996,
63,
1419,
272,
1660,
272,
283,
1294,
356,
469,
267,
283,
15956,
356,
283,
14293,
14,
10012,
14,
1294,
63,
9217,
14,
8862,
20393,
14389,
297,
267,
283,
16618,
63,
16169,
63,
5569,
356,
3506,
35,
63,
16169,
63,
5569,
12,
267,
283,
8808,
356,
10996,
63,
1419,
272,
789,
199,
93,
421,
199,
3,
12829,
364,
303,
26,
961,
365,
314,
16628,
367,
314,
28458,
334,
4941,
16386,
7079,
9,
1771,
379,
2955,
1564,
3877,
199,
3,
961,
365,
367,
2955,
1564,
367,
20736,
12,
440,
2656,
2955,
1564,
334,
69,
14,
71,
14,
18910,
12,
11431,
12,
3988,
56,
32159,
316,
12,
5423,
9,
199,
9663,
16169,
275,
469,
272,
283,
15956,
356,
283,
14293,
14,
28160,
14,
9217,
14,
20393,
2714,
5502,
297,
272,
283,
16618,
63,
16169,
63,
5569,
356,
469,
267,
283,
1102,
356,
283,
5967,
297,
267,
283,
697,
356,
283,
88,
1317,
297,
272,
1660,
272,
327,
2040,
367,
4722,
1511,
626,
883,
506,
19272,
641,
282,
536,
12,
325,
14,
71,
14,
283,
28272,
2425,
7,
272,
283,
1554,
3841,
21518,
63,
8808,
356,
469,
267,
283,
28272,
2425,
356,
469,
288,
283,
4623,
356,
283,
28272,
63,
2319,
7,
267,
789,
272,
789,
199,
93,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
267,
283,
2339,
356,
5070,
54,
63,
5441,
1182,
298,
697,
2,
1182,
298,
8268,
14,
697,
401,
272,
789,
199,
93,
199,
199,
44,
3053,
63,
5825,
275,
298,
5967,
26,
15214,
2,
199,
13313,
459,
4225,
12058,
63,
44,
3053,
63,
5825,
418,
275,
298,
5967,
26,
15214,
2,
199,
199,
907,
9263,
275,
469,
272,
283,
8268,
20,
8268,
356,
469,
267,
283,
4694,
356,
283,
4133,
297,
267,
283,
6493,
356,
283,
3187,
32,
5031,
14,
957,
26,
13965,
88,
15,
8268,
20,
8268,
14,
3187,
297,
272,
1660,
272,
283,
1317,
13,
1147,
13,
6683,
18,
88,
356,
469,
267,
283,
4694,
356,
283,
4133,
297,
267,
327,
283,
6493,
356,
283,
3187,
32,
5031,
14,
957,
26,
13965,
88,
15,
6683,
18,
88,
13,
70,
452,
13,
7409,
14,
3187,
297,
267,
283,
6493,
356,
283,
3187,
32,
5031,
14,
957,
26,
13965,
88,
15,
1317,
13,
1147,
13,
6683,
18,
88,
14,
3187,
297,
272,
1660,
272,
283,
22,
14,
383,
88,
356,
469,
267,
283,
4694,
356,
283,
4133,
297,
267,
283,
6493,
356,
283,
3187,
32,
5031,
14,
957,
26,
13965,
88,
15,
22,
14,
383,
88,
14,
3187,
297,
272,
1660,
272,
283,
23,
14,
383,
88,
356,
469,
267,
283,
4694,
356,
283,
4133,
297,
267,
283,
6493,
356,
283,
3187,
32,
5031,
14,
957,
26,
13965,
88,
15,
23,
14,
383,
88,
14,
3187,
297,
272,
1660,
272,
283,
19,
14,
21013,
88,
356,
469,
267,
283,
4694,
356,
283,
4133,
297,
267,
283,
6493,
356,
283,
3187,
32,
5031,
14,
957,
26,
13965,
88,
15,
19,
14,
21013,
88,
14,
3187,
297,
272,
1660,
199,
93,
199,
199,
3263,
1244,
654,
275,
469,
272,
327,
961,
365,
314,
2581,
1202,
367,
4750,
7645,
14,
30481,
3018,
911,
440,
1736,
1928,
282,
272,
327,
805,
316,
2581,
1553,
652,
25749,
641,
13627,
370,
2248,
2399,
2202,
315,
9825,
14,
272,
327,
1010,
28512,
15,
8788,
2589,
83,
12,
314,
12184,
2597,
12166,
2348,
14,
272,
283,
885,
356,
469,
267,
283,
18145,
356,
283,
1176,
14,
1018,
14,
1637,
14,
7765,
14,
2102,
5286,
14,
3040,
14169,
4437,
297,
267,
283,
16575,
356,
283,
8268,
63,
2102,
63,
5286,
63,
1637,
297,
267,
283,
3078,
63,
15476,
356,
283,
1974,
14,
25835,
14,
3489,
63,
498,
297,
272,
1660,
339,
327,
710,
8605,
2581,
365,
4052,
1265,
664,
340,
1265,
675,
4154,
4884,
14,
1637,
14,
2779,
1159,
1202,
367,
272,
327,
7645,
2839,
13627,
314,
2518,
14,
1652,
570,
367,
3365,
437,
15,
34,
511,
4652,
14,
272,
327,
2136,
663,
652,
370,
506,
282,
9762,
4437,
370,
3542,
295,
8786,
402,
2518,
14,
1652,
315,
4866,
14,
272,
327,
1010,
28512,
22196,
12,
781,
3955,
18200,
15945,
687,
666,
14238,
701,
314,
272,
327,
6675,
2112,
14,
272,
283,
10706,
356,
469,
267,
283,
18145,
356,
283,
1176,
14,
1018,
14,
1637,
14,
7765,
14,
5869,
14,
11324,
4437,
297,
267,
283,
3078,
63,
6351,
356,
283,
10706,
297,
267,
283,
4612,
356,
841,
12,
267,
283,
3078,
63,
15476,
356,
283,
1974,
14,
25835,
14,
3489,
63,
498,
297,
272,
1660,
339,
283,
9217,
63,
2343
] | [
199,
2765,
1101,
570,
7858,
314,
3486,
270,
4866,
3734,
624,
199,
199,
3,
2136,
32005,
5627,
24213,
402,
2860,
626,
10621,
1133,
1202,
12,
436,
199,
3,
2934,
370,
492,
1006,
2860,
687,
1300,
2202,
1584,
199,
3,
4287,
26,
3507,
29,
55,
28025,
12,
644,
1690,
1079,
199,
199,
504,
1275,
2330,
492,
627,
199,
504,
943,
1751,
492,
664,
63,
2921,
63,
888,
199,
199,
5287,
275,
715,
199,
7433,
63,
5287,
275,
10990,
199,
27896,
275,
664,
63,
2921,
63,
888,
8,
9984,
63,
5441,
1182,
298,
793,
401,
1169,
2050,
63,
1813,
628,
2374,
401,
1169,
15161,
63,
1501,
628,
14428,
14,
793,
401,
1169,
4866,
63,
1813,
29,
549,
12,
1169,
3105,
29,
549,
9,
199,
199,
10012,
63,
1419,
275,
469,
272,
283,
885,
63,
533,
356,
283,
14293,
14,
1773,
63,
578,
14,
7963,
4311,
297,
272,
283,
2319,
63,
1231,
356,
598,
30087,
63,
20424,
63,
5441,
12,
272,
283,
3352,
63,
1160,
356,
283,
8268,
19491,
14,
17469,
14,
3352,
63,
475,
63,
875,
297,
199,
93,
199,
199,
27011,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
14293,
14,
10012,
14,
7185,
14,
18332,
14389,
297,
267,
283,
16618,
63,
16169,
63,
5569,
356,
3506,
35,
63,
16169,
63,
5569,
12,
267,
283,
8808,
356,
10996,
63,
1419,
272,
1660,
272,
283,
2275,
356,
469,
267,
283,
15956,
356,
283,
14293,
14,
10012,
14,
9217,
14,
20393,
14389,
297,
267,
283,
16618,
63,
16169,
63,
5569,
356,
3506,
35,
63,
16169,
63,
5569,
12,
267,
283,
8808,
356,
10996,
63,
1419,
272,
1660,
272,
283,
1294,
356,
469,
267,
283,
15956,
356,
283,
14293,
14,
10012,
14,
1294,
63,
9217,
14,
8862,
20393,
14389,
297,
267,
283,
16618,
63,
16169,
63,
5569,
356,
3506,
35,
63,
16169,
63,
5569,
12,
267,
283,
8808,
356,
10996,
63,
1419,
272,
789,
199,
93,
421,
199,
3,
12829,
364,
303,
26,
961,
365,
314,
16628,
367,
314,
28458,
334,
4941,
16386,
7079,
9,
1771,
379,
2955,
1564,
3877,
199,
3,
961,
365,
367,
2955,
1564,
367,
20736,
12,
440,
2656,
2955,
1564,
334,
69,
14,
71,
14,
18910,
12,
11431,
12,
3988,
56,
32159,
316,
12,
5423,
9,
199,
9663,
16169,
275,
469,
272,
283,
15956,
356,
283,
14293,
14,
28160,
14,
9217,
14,
20393,
2714,
5502,
297,
272,
283,
16618,
63,
16169,
63,
5569,
356,
469,
267,
283,
1102,
356,
283,
5967,
297,
267,
283,
697,
356,
283,
88,
1317,
297,
272,
1660,
272,
327,
2040,
367,
4722,
1511,
626,
883,
506,
19272,
641,
282,
536,
12,
325,
14,
71,
14,
283,
28272,
2425,
7,
272,
283,
1554,
3841,
21518,
63,
8808,
356,
469,
267,
283,
28272,
2425,
356,
469,
288,
283,
4623,
356,
283,
28272,
63,
2319,
7,
267,
789,
272,
789,
199,
93,
199,
199,
27260,
275,
469,
272,
283,
885,
356,
469,
267,
283,
15956,
356,
283,
1176,
14,
697,
14,
7765,
14,
10659,
19,
297,
267,
283,
2339,
356,
5070,
54,
63,
5441,
1182,
298,
697,
2,
1182,
298,
8268,
14,
697,
401,
272,
789,
199,
93,
199,
199,
44,
3053,
63,
5825,
275,
298,
5967,
26,
15214,
2,
199,
13313,
459,
4225,
12058,
63,
44,
3053,
63,
5825,
418,
275,
298,
5967,
26,
15214,
2,
199,
199,
907,
9263,
275,
469,
272,
283,
8268,
20,
8268,
356,
469,
267,
283,
4694,
356,
283,
4133,
297,
267,
283,
6493,
356,
283,
3187,
32,
5031,
14,
957,
26,
13965,
88,
15,
8268,
20,
8268,
14,
3187,
297,
272,
1660,
272,
283,
1317,
13,
1147,
13,
6683,
18,
88,
356,
469,
267,
283,
4694,
356,
283,
4133,
297,
267,
327,
283,
6493,
356,
283,
3187,
32,
5031,
14,
957,
26,
13965,
88,
15,
6683,
18,
88,
13,
70,
452,
13,
7409,
14,
3187,
297,
267,
283,
6493,
356,
283,
3187,
32,
5031,
14,
957,
26,
13965,
88,
15,
1317,
13,
1147,
13,
6683,
18,
88,
14,
3187,
297,
272,
1660,
272,
283,
22,
14,
383,
88,
356,
469,
267,
283,
4694,
356,
283,
4133,
297,
267,
283,
6493,
356,
283,
3187,
32,
5031,
14,
957,
26,
13965,
88,
15,
22,
14,
383,
88,
14,
3187,
297,
272,
1660,
272,
283,
23,
14,
383,
88,
356,
469,
267,
283,
4694,
356,
283,
4133,
297,
267,
283,
6493,
356,
283,
3187,
32,
5031,
14,
957,
26,
13965,
88,
15,
23,
14,
383,
88,
14,
3187,
297,
272,
1660,
272,
283,
19,
14,
21013,
88,
356,
469,
267,
283,
4694,
356,
283,
4133,
297,
267,
283,
6493,
356,
283,
3187,
32,
5031,
14,
957,
26,
13965,
88,
15,
19,
14,
21013,
88,
14,
3187,
297,
272,
1660,
199,
93,
199,
199,
3263,
1244,
654,
275,
469,
272,
327,
961,
365,
314,
2581,
1202,
367,
4750,
7645,
14,
30481,
3018,
911,
440,
1736,
1928,
282,
272,
327,
805,
316,
2581,
1553,
652,
25749,
641,
13627,
370,
2248,
2399,
2202,
315,
9825,
14,
272,
327,
1010,
28512,
15,
8788,
2589,
83,
12,
314,
12184,
2597,
12166,
2348,
14,
272,
283,
885,
356,
469,
267,
283,
18145,
356,
283,
1176,
14,
1018,
14,
1637,
14,
7765,
14,
2102,
5286,
14,
3040,
14169,
4437,
297,
267,
283,
16575,
356,
283,
8268,
63,
2102,
63,
5286,
63,
1637,
297,
267,
283,
3078,
63,
15476,
356,
283,
1974,
14,
25835,
14,
3489,
63,
498,
297,
272,
1660,
339,
327,
710,
8605,
2581,
365,
4052,
1265,
664,
340,
1265,
675,
4154,
4884,
14,
1637,
14,
2779,
1159,
1202,
367,
272,
327,
7645,
2839,
13627,
314,
2518,
14,
1652,
570,
367,
3365,
437,
15,
34,
511,
4652,
14,
272,
327,
2136,
663,
652,
370,
506,
282,
9762,
4437,
370,
3542,
295,
8786,
402,
2518,
14,
1652,
315,
4866,
14,
272,
327,
1010,
28512,
22196,
12,
781,
3955,
18200,
15945,
687,
666,
14238,
701,
314,
272,
327,
6675,
2112,
14,
272,
283,
10706,
356,
469,
267,
283,
18145,
356,
283,
1176,
14,
1018,
14,
1637,
14,
7765,
14,
5869,
14,
11324,
4437,
297,
267,
283,
3078,
63,
6351,
356,
283,
10706,
297,
267,
283,
4612,
356,
841,
12,
267,
283,
3078,
63,
15476,
356,
283,
1974,
14,
25835,
14,
3489,
63,
498,
297,
272,
1660,
339,
283,
9217,
63,
2343,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
imsplitbit/nova | nova/tests/virt/test_block_device.py | 2 | 18934 | # vim: tabstop=4 shiftwidth=4 softtabstop=4
# 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 nova import block_device
from nova.conductor import api as conductor_api
from nova import context
from nova.openstack.common import jsonutils
from nova import test
from nova.tests import matchers
from nova.virt import block_device as driver_block_device
from nova.virt import driver
from nova.volume import cinder
class TestDriverBlockDevice(test.NoDBTestCase):
driver_classes = {
'swap': driver_block_device.DriverSwapBlockDevice,
'ephemeral': driver_block_device.DriverEphemeralBlockDevice,
'volume': driver_block_device.DriverVolumeBlockDevice,
'snapshot': driver_block_device.DriverSnapshotBlockDevice,
'image': driver_block_device.DriverImageBlockDevice
}
swap_bdm = block_device.BlockDeviceDict(
{'id': 1, 'instance_uuid': 'fake-instance',
'device_name': '/dev/sdb1',
'source_type': 'blank',
'destination_type': 'local',
'delete_on_termination': True,
'guest_format': 'swap',
'disk_bus': 'scsi',
'volume_size': 2,
'boot_index': -1})
swap_driver_bdm = {
'device_name': '/dev/sdb1',
'swap_size': 2,
'disk_bus': 'scsi'}
swap_legacy_driver_bdm = {
'device_name': '/dev/sdb1',
'swap_size': 2}
ephemeral_bdm = block_device.BlockDeviceDict(
{'id': 2, 'instance_uuid': 'fake-instance',
'device_name': '/dev/sdc1',
'source_type': 'blank',
'destination_type': 'local',
'disk_bus': 'scsi',
'device_type': 'disk',
'volume_size': 4,
'guest_format': 'ext4',
'delete_on_termination': True,
'boot_index': -1})
ephemeral_driver_bdm = {
'device_name': '/dev/sdc1',
'size': 4,
'device_type': 'disk',
'guest_format': 'ext4',
'disk_bus': 'scsi'}
ephemeral_legacy_driver_bdm = {
'device_name': '/dev/sdc1',
'size': 4,
'virtual_name': 'ephemeral0',
'num': 0}
volume_bdm = block_device.BlockDeviceDict(
{'id': 3, 'instance_uuid': 'fake-instance',
'device_name': '/dev/sda1',
'source_type': 'volume',
'disk_bus': 'scsi',
'device_type': 'disk',
'volume_size': 8,
'destination_type': 'volume',
'volume_id': 'fake-volume-id-1',
'guest_format': 'ext4',
'connection_info': '{"fake": "connection_info"}',
'delete_on_termination': False,
'boot_index': 0})
volume_driver_bdm = {
'mount_device': '/dev/sda1',
'connection_info': {"fake": "connection_info"},
'delete_on_termination': False,
'disk_bus': 'scsi',
'device_type': 'disk',
'guest_format': 'ext4',
'boot_index': 0}
volume_legacy_driver_bdm = {
'mount_device': '/dev/sda1',
'connection_info': {"fake": "connection_info"},
'delete_on_termination': False}
snapshot_bdm = block_device.BlockDeviceDict(
{'id': 4, 'instance_uuid': 'fake-instance',
'device_name': '/dev/sda2',
'delete_on_termination': True,
'volume_size': 3,
'disk_bus': 'scsi',
'device_type': 'disk',
'source_type': 'snapshot',
'destination_type': 'volume',
'connection_info': '{"fake": "connection_info"}',
'snapshot_id': 'fake-snapshot-id-1',
'volume_id': 'fake-volume-id-2',
'boot_index': -1})
snapshot_driver_bdm = {
'mount_device': '/dev/sda2',
'connection_info': {"fake": "connection_info"},
'delete_on_termination': True,
'disk_bus': 'scsi',
'device_type': 'disk',
'guest_format': None,
'boot_index': -1}
snapshot_legacy_driver_bdm = {
'mount_device': '/dev/sda2',
'connection_info': {"fake": "connection_info"},
'delete_on_termination': True}
image_bdm = block_device.BlockDeviceDict(
{'id': 5, 'instance_uuid': 'fake-instance',
'device_name': '/dev/sda2',
'delete_on_termination': True,
'volume_size': 1,
'disk_bus': 'scsi',
'device_type': 'disk',
'source_type': 'image',
'destination_type': 'volume',
'connection_info': '{"fake": "connection_info"}',
'image_id': 'fake-image-id-1',
'volume_id': 'fake-volume-id-2',
'boot_index': -1})
image_driver_bdm = {
'mount_device': '/dev/sda2',
'connection_info': {"fake": "connection_info"},
'delete_on_termination': True,
'disk_bus': 'scsi',
'device_type': 'disk',
'guest_format': None,
'boot_index': -1}
image_legacy_driver_bdm = {
'mount_device': '/dev/sda2',
'connection_info': {"fake": "connection_info"},
'delete_on_termination': True}
def setUp(self):
super(TestDriverBlockDevice, self).setUp()
self.volume_api = self.mox.CreateMock(cinder.API)
self.virt_driver = self.mox.CreateMock(driver.ComputeDriver)
self.db_api = self.mox.CreateMock(conductor_api.API)
self.context = context.RequestContext('fake_user',
'fake_project')
def test_driver_block_device_base_class(self):
self.base_class_transform_called = False
class DummyBlockDevice(driver_block_device.DriverBlockDevice):
_fields = set(['foo', 'bar'])
_legacy_fields = set(['foo', 'baz'])
def _transform(inst, bdm):
self.base_class_transform_called = True
dummy_device = DummyBlockDevice({'foo': 'foo_val', 'id': 42})
self.assertTrue(self.base_class_transform_called)
self.assertThat(dummy_device, matchers.DictMatches(
{'foo': None, 'bar': None}))
self.assertEqual(dummy_device.id, 42)
self.assertThat(dummy_device.legacy(), matchers.DictMatches(
{'foo': None, 'baz': None}))
self.assertRaises(driver_block_device._NotTransformable,
DummyBlockDevice, {'no_device': True})
def _test_driver_device(self, name):
test_bdm = self.driver_classes[name](
getattr(self, "%s_bdm" % name))
self.assertThat(test_bdm, matchers.DictMatches(
getattr(self, "%s_driver_bdm" % name)))
self.assertThat(test_bdm.legacy(),
matchers.DictMatches(
getattr(self, "%s_legacy_driver_bdm" % name)))
# Make sure that all others raise _invalidType
for other_name, cls in self.driver_classes.iteritems():
if other_name == name:
continue
self.assertRaises(driver_block_device._InvalidType,
cls,
getattr(self, '%s_bdm' % name))
def _test_driver_default_size(self, name):
size = 'swap_size' if name == 'swap' else 'size'
no_size_bdm = getattr(self, "%s_bdm" % name).copy()
no_size_bdm['volume_size'] = None
driver_bdm = self.driver_classes[name](no_size_bdm)
self.assertEqual(driver_bdm[size], 0)
del no_size_bdm['volume_size']
driver_bdm = self.driver_classes[name](no_size_bdm)
self.assertEqual(driver_bdm[size], 0)
def test_driver_swap_block_device(self):
self._test_driver_device("swap")
def test_driver_swap_default_size(self):
self._test_driver_default_size('swap')
def test_driver_ephemeral_block_device(self):
self._test_driver_device("ephemeral")
def test_driver_ephemeral_default_size(self):
self._test_driver_default_size('ephemeral')
def test_driver_volume_block_device(self):
self._test_driver_device("volume")
test_bdm = self.driver_classes['volume'](
self.volume_bdm)
self.assertEqual(test_bdm.id, 3)
self.assertEqual(test_bdm.volume_id, 'fake-volume-id-1')
self.assertEqual(test_bdm.volume_size, 8)
def test_driver_snapshot_block_device(self):
self._test_driver_device("snapshot")
test_bdm = self.driver_classes['snapshot'](
self.snapshot_bdm)
self.assertEqual(test_bdm.id, 4)
self.assertEqual(test_bdm.snapshot_id, 'fake-snapshot-id-1')
self.assertEqual(test_bdm.volume_id, 'fake-volume-id-2')
self.assertEqual(test_bdm.volume_size, 3)
def test_driver_image_block_device(self):
self._test_driver_device('image')
test_bdm = self.driver_classes['image'](
self.image_bdm)
self.assertEqual(test_bdm.id, 5)
self.assertEqual(test_bdm.image_id, 'fake-image-id-1')
self.assertEqual(test_bdm.volume_size, 1)
def test_driver_image_block_device_destination_local(self):
self._test_driver_device('image')
bdm = self.image_bdm.copy()
bdm['destination_type'] = 'local'
self.assertRaises(driver_block_device._InvalidType,
self.driver_classes['image'], bdm)
def test_volume_attach(self):
test_bdm = self.driver_classes['volume'](
self.volume_bdm)
elevated_context = self.context.elevated()
self.stubs.Set(self.context, 'elevated',
lambda: elevated_context)
instance = {'id': 'fake_id', 'uuid': 'fake_uuid'}
volume = {'id': 'fake-volume-id-1'}
connector = {'ip': 'fake_ip', 'host': 'fake_host'}
connection_info = {'data': {}}
expected_conn_info = {'data': {},
'serial': 'fake-volume-id-1'}
self.volume_api.get(self.context,
'fake-volume-id-1').AndReturn(volume)
self.volume_api.check_attach(self.context, volume,
instance=instance).AndReturn(None)
self.virt_driver.get_volume_connector(instance).AndReturn(connector)
self.volume_api.initialize_connection(
elevated_context, volume['id'],
connector).AndReturn(connection_info)
self.volume_api.attach(elevated_context, 'fake-volume-id-1',
'fake_uuid', '/dev/sda1').AndReturn(None)
self.db_api.block_device_mapping_update(elevated_context, 3,
{'connection_info': jsonutils.dumps(expected_conn_info)})
self.mox.ReplayAll()
test_bdm.attach(self.context, instance,
self.volume_api, self.virt_driver, self.db_api)
self.assertThat(test_bdm['connection_info'],
matchers.DictMatches(expected_conn_info))
def test_refresh_connection(self):
test_bdm = self.driver_classes['snapshot'](
self.snapshot_bdm)
instance = {'id': 'fake_id', 'uuid': 'fake_uuid'}
connector = {'ip': 'fake_ip', 'host': 'fake_host'}
connection_info = {'data': {}}
expected_conn_info = {'data': {},
'serial': 'fake-volume-id-2'}
self.virt_driver.get_volume_connector(instance).AndReturn(connector)
self.volume_api.initialize_connection(
self.context, test_bdm.volume_id,
connector).AndReturn(connection_info)
self.db_api.block_device_mapping_update(self.context, 4,
{'connection_info': jsonutils.dumps(expected_conn_info)})
self.mox.ReplayAll()
test_bdm.refresh_connection_info(self.context, instance,
self.volume_api, self.virt_driver,
self.db_api)
self.assertThat(test_bdm['connection_info'],
matchers.DictMatches(expected_conn_info))
def test_snapshot_attach_no_volume(self):
no_volume_snapshot = self.snapshot_bdm.copy()
no_volume_snapshot['volume_id'] = None
test_bdm = self.driver_classes['snapshot'](no_volume_snapshot)
instance = {'id': 'fake_id', 'uuid': 'fake_uuid'}
snapshot = {'id': 'fake-snapshot-id-1'}
volume = {'id': 'fake-volume-id-2'}
wait_func = self.mox.CreateMockAnything()
volume_class = self.driver_classes['volume']
self.mox.StubOutWithMock(volume_class, 'attach')
self.volume_api.get_snapshot(self.context,
'fake-snapshot-id-1').AndReturn(snapshot)
self.volume_api.create(self.context, 3,
'', '', snapshot).AndReturn(volume)
wait_func(self.context, 'fake-volume-id-2').AndReturn(None)
self.db_api.block_device_mapping_update(
self.context, 4, {'volume_id': 'fake-volume-id-2'}).AndReturn(None)
volume_class.attach(self.context, instance, self.volume_api,
self.virt_driver, self.db_api).AndReturn(None)
self.mox.ReplayAll()
test_bdm.attach(self.context, instance, self.volume_api,
self.virt_driver, self.db_api, wait_func)
self.assertEqual(test_bdm.volume_id, 'fake-volume-id-2')
def test_snapshot_attach_volume(self):
test_bdm = self.driver_classes['snapshot'](
self.snapshot_bdm)
instance = {'id': 'fake_id', 'uuid': 'fake_uuid'}
volume_class = self.driver_classes['volume']
self.mox.StubOutWithMock(volume_class, 'attach')
# Make sure theses are not called
self.mox.StubOutWithMock(self.volume_api, 'get_snapshot')
self.mox.StubOutWithMock(self.volume_api, 'create')
self.mox.StubOutWithMock(self.db_api,
'block_device_mapping_update')
volume_class.attach(self.context, instance, self.volume_api,
self.virt_driver, self.db_api).AndReturn(None)
self.mox.ReplayAll()
test_bdm.attach(self.context, instance, self.volume_api,
self.virt_driver, self.db_api)
self.assertEqual(test_bdm.volume_id, 'fake-volume-id-2')
def test_image_attach_no_volume(self):
no_volume_image = self.image_bdm.copy()
no_volume_image['volume_id'] = None
test_bdm = self.driver_classes['image'](no_volume_image)
instance = {'id': 'fake_id', 'uuid': 'fake_uuid'}
image = {'id': 'fake-image-id-1'}
volume = {'id': 'fake-volume-id-2'}
wait_func = self.mox.CreateMockAnything()
volume_class = self.driver_classes['volume']
self.mox.StubOutWithMock(volume_class, 'attach')
self.volume_api.create(self.context, 1,
'', '', image_id=image['id']).AndReturn(volume)
wait_func(self.context, 'fake-volume-id-2').AndReturn(None)
self.db_api.block_device_mapping_update(
self.context, 5, {'volume_id': 'fake-volume-id-2'}).AndReturn(None)
volume_class.attach(self.context, instance, self.volume_api,
self.virt_driver, self.db_api).AndReturn(None)
self.mox.ReplayAll()
test_bdm.attach(self.context, instance, self.volume_api,
self.virt_driver, self.db_api, wait_func)
self.assertEqual(test_bdm.volume_id, 'fake-volume-id-2')
def test_image_attach_volume(self):
test_bdm = self.driver_classes['image'](
self.image_bdm)
instance = {'id': 'fake_id', 'uuid': 'fake_uuid'}
volume_class = self.driver_classes['volume']
self.mox.StubOutWithMock(volume_class, 'attach')
# Make sure theses are not called
self.mox.StubOutWithMock(self.volume_api, 'get_snapshot')
self.mox.StubOutWithMock(self.volume_api, 'create')
self.mox.StubOutWithMock(self.db_api,
'block_device_mapping_update')
volume_class.attach(self.context, instance, self.volume_api,
self.virt_driver, self.db_api).AndReturn(None)
self.mox.ReplayAll()
test_bdm.attach(self.context, instance, self.volume_api,
self.virt_driver, self.db_api)
self.assertEqual(test_bdm.volume_id, 'fake-volume-id-2')
def test_convert_block_devices(self):
converted = driver_block_device._convert_block_devices(
self.driver_classes['volume'],
[self.volume_bdm, self.ephemeral_bdm])
self.assertEqual(converted, [self.volume_driver_bdm])
def test_legacy_block_devices(self):
test_snapshot = self.driver_classes['snapshot'](
self.snapshot_bdm)
block_device_mapping = [test_snapshot, test_snapshot]
legacy_bdm = driver_block_device.legacy_block_devices(
block_device_mapping)
self.assertEqual(legacy_bdm, [self.snapshot_legacy_driver_bdm,
self.snapshot_legacy_driver_bdm])
# Test that the ephemerals work as expected
test_ephemerals = [self.driver_classes['ephemeral'](
self.ephemeral_bdm) for _ in xrange(2)]
expected = [self.ephemeral_legacy_driver_bdm.copy()
for _ in xrange(2)]
expected[0]['virtual_name'] = 'ephemeral0'
expected[0]['num'] = 0
expected[1]['virtual_name'] = 'ephemeral1'
expected[1]['num'] = 1
legacy_ephemerals = driver_block_device.legacy_block_devices(
test_ephemerals)
self.assertEqual(expected, legacy_ephemerals)
def test_get_swap(self):
swap = [self.swap_driver_bdm]
legacy_swap = [self.swap_legacy_driver_bdm]
no_swap = [self.volume_driver_bdm]
self.assertEqual(swap[0], driver_block_device.get_swap(swap))
self.assertEqual(legacy_swap[0],
driver_block_device.get_swap(legacy_swap))
self.assertEqual(no_swap, driver_block_device.get_swap(no_swap))
self.assertIsNone(driver_block_device.get_swap([]))
def test_is_implemented(self):
for bdm in (self.image_bdm, self.volume_bdm, self.swap_bdm,
self.ephemeral_bdm, self.snapshot_bdm):
self.assertTrue(driver_block_device.is_implemented(bdm))
local_image = self.image_bdm.copy()
local_image['destination_type'] = 'local'
self.assertFalse(driver_block_device.is_implemented(local_image))
| apache-2.0 | [
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
5913,
492,
1853,
63,
1782,
199,
504,
5913,
14,
28678,
492,
2986,
465,
406,
19966,
63,
1246,
199,
504,
5913,
492,
1067,
199,
504,
5913,
14,
8512,
14,
2330,
492,
18705,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
492,
31679,
199,
504,
5913,
14,
4549,
492,
1853,
63,
1782,
465,
5253,
63,
1457,
63,
1782,
199,
504,
5913,
14,
4549,
492,
5253,
199,
504,
5913,
14,
2405,
492,
13069,
421,
199,
533,
1379,
6158,
32442,
8,
396,
14,
32437,
304,
272,
5253,
63,
2888,
275,
469,
267,
283,
9286,
356,
5253,
63,
1457,
63,
1782,
14,
6158,
18385,
32442,
12,
267,
283,
19562,
356,
5253,
63,
1457,
63,
1782,
14,
6158,
14057,
14572,
32442,
12,
267,
283,
2405,
356,
5253,
63,
1457,
63,
1782,
14,
6158,
6464,
32442,
12,
267,
283,
4753,
356,
5253,
63,
1457,
63,
1782,
14,
6158,
12038,
32442,
12,
267,
283,
1569,
356,
5253,
63,
1457,
63,
1782,
14,
6158,
3491,
32442,
272,
789,
339,
11413,
63,
21520,
275,
1853,
63,
1782,
14,
32442,
2141,
8,
267,
791,
344,
356,
413,
12,
283,
842,
63,
2580,
356,
283,
3183,
13,
842,
297,
268,
283,
1782,
63,
354,
356,
1994,
2374,
15,
21624,
17,
297,
268,
283,
1365,
63,
466,
356,
283,
2500,
297,
268,
283,
6881,
63,
466,
356,
283,
1832,
297,
268,
283,
1807,
63,
265,
63,
20667,
356,
715,
12,
268,
283,
10409,
63,
908,
356,
283,
9286,
297,
268,
283,
4032,
63,
5610,
356,
283,
15873,
297,
268,
283,
2405,
63,
890,
356,
499,
12,
268,
283,
4930,
63,
1080,
356,
446,
17,
1552,
339,
11413,
63,
3090,
63,
21520,
275,
469,
267,
283,
1782,
63,
354,
356,
1994,
2374,
15,
21624,
17,
297,
267,
283,
9286,
63,
890,
356,
499,
12,
267,
283,
4032,
63,
5610,
356,
283,
15873,
936,
339,
11413,
63,
10000,
63,
3090,
63,
21520,
275,
469,
267,
283,
1782,
63,
354,
356,
1994,
2374,
15,
21624,
17,
297,
267,
283,
9286,
63,
890,
356,
499,
93,
339,
26288,
63,
21520,
275,
1853,
63,
1782,
14,
32442,
2141,
8,
267,
791,
344,
356,
499,
12,
283,
842,
63,
2580,
356,
283,
3183,
13,
842,
297,
268,
283,
1782,
63,
354,
356,
1994,
2374,
15,
83,
3833,
17,
297,
268,
283,
1365,
63,
466,
356,
283,
2500,
297,
268,
283,
6881,
63,
466,
356,
283,
1832,
297,
268,
283,
4032,
63,
5610,
356,
283,
15873,
297,
268,
283,
1782,
63,
466,
356,
283,
4032,
297,
268,
283,
2405,
63,
890,
356,
841,
12,
268,
283,
10409,
63,
908,
356,
283,
832,
20,
297,
268,
283,
1807,
63,
265,
63,
20667,
356,
715,
12,
268,
283,
4930,
63,
1080,
356,
446,
17,
1552,
339,
26288,
63,
3090,
63,
21520,
275,
469,
267,
283,
1782,
63,
354,
356,
1994,
2374,
15,
83,
3833,
17,
297,
267,
283,
890,
356,
841,
12,
267,
283,
1782,
63,
466,
356,
283,
4032,
297,
267,
283,
10409,
63,
908,
356,
283,
832,
20,
297,
267,
283,
4032,
63,
5610,
356,
283,
15873,
936,
339,
26288,
63,
10000,
63,
3090,
63,
21520,
275,
469,
267,
283,
1782,
63,
354,
356,
1994,
2374,
15,
83,
3833,
17,
297,
267,
283,
890,
356,
841,
12,
267,
283,
2065,
63,
354,
356,
283,
19562,
16,
297,
267,
283,
1507,
356,
378,
93,
339,
3301,
63,
21520,
275,
1853,
63,
1782,
14,
32442,
2141,
8,
267,
791,
344,
356,
650,
12,
283,
842,
63,
2580,
356,
283,
3183,
13,
842,
297,
268,
283,
1782,
63,
354,
356,
1994,
2374,
15,
19387,
17,
297,
268,
283,
1365,
63,
466,
356,
283,
2405,
297,
268,
283,
4032,
63,
5610,
356,
283,
15873,
297,
268,
283,
1782,
63,
466,
356,
283,
4032,
297,
268,
283,
2405,
63,
890,
356,
1695,
12,
268,
283,
6881,
63,
466,
356,
283,
2405,
297,
268,
283,
2405,
63,
344,
356,
283,
3183,
13,
2405,
13,
344,
13,
17,
297,
268,
283,
10409,
63,
908,
356,
283,
832,
20,
297,
268,
283,
2105,
63,
815,
356,
17137,
3183,
582,
298,
2105,
63,
815,
3570,
297,
268,
283,
1807,
63,
265,
63,
20667,
356,
756,
12,
268,
283,
4930,
63,
1080,
356,
378,
1552,
339,
3301,
63,
3090,
63,
21520,
275,
469,
267,
283,
3956,
63,
1782,
356,
1994,
2374,
15,
19387,
17,
297,
267,
283,
2105,
63,
815,
356,
2420,
3183,
582,
298,
2105,
63,
815,
6018,
267,
283,
1807,
63,
265,
63,
20667,
356,
756,
12,
267,
283,
4032,
63,
5610,
356,
283,
15873,
297,
267,
283,
1782,
63,
466,
356,
283,
4032,
297,
267,
283,
10409,
63,
908,
356,
283,
832,
20,
297,
267,
283,
4930,
63,
1080,
356,
378,
93,
339,
3301,
63,
10000,
63,
3090,
63,
21520,
275,
469,
267,
283,
3956,
63,
1782,
356,
1994,
2374,
15,
19387,
17,
297,
267,
283,
2105,
63,
815,
356,
2420,
3183,
582,
298,
2105,
63,
815,
6018,
267,
283,
1807,
63,
265,
63,
20667,
356,
756,
93,
339,
5740,
63,
21520,
275,
1853,
63,
1782,
14,
32442,
2141,
8,
267,
791,
344,
356,
841,
12,
283,
842,
63,
2580,
356,
283,
3183,
13,
842,
297,
268,
283,
1782,
63,
354,
356,
1994,
2374,
15,
19387,
18,
297,
268,
283,
1807,
63,
265,
63,
20667,
356,
715,
12
] | [
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
5913,
492,
1853,
63,
1782,
199,
504,
5913,
14,
28678,
492,
2986,
465,
406,
19966,
63,
1246,
199,
504,
5913,
492,
1067,
199,
504,
5913,
14,
8512,
14,
2330,
492,
18705,
199,
504,
5913,
492,
511,
199,
504,
5913,
14,
2219,
492,
31679,
199,
504,
5913,
14,
4549,
492,
1853,
63,
1782,
465,
5253,
63,
1457,
63,
1782,
199,
504,
5913,
14,
4549,
492,
5253,
199,
504,
5913,
14,
2405,
492,
13069,
421,
199,
533,
1379,
6158,
32442,
8,
396,
14,
32437,
304,
272,
5253,
63,
2888,
275,
469,
267,
283,
9286,
356,
5253,
63,
1457,
63,
1782,
14,
6158,
18385,
32442,
12,
267,
283,
19562,
356,
5253,
63,
1457,
63,
1782,
14,
6158,
14057,
14572,
32442,
12,
267,
283,
2405,
356,
5253,
63,
1457,
63,
1782,
14,
6158,
6464,
32442,
12,
267,
283,
4753,
356,
5253,
63,
1457,
63,
1782,
14,
6158,
12038,
32442,
12,
267,
283,
1569,
356,
5253,
63,
1457,
63,
1782,
14,
6158,
3491,
32442,
272,
789,
339,
11413,
63,
21520,
275,
1853,
63,
1782,
14,
32442,
2141,
8,
267,
791,
344,
356,
413,
12,
283,
842,
63,
2580,
356,
283,
3183,
13,
842,
297,
268,
283,
1782,
63,
354,
356,
1994,
2374,
15,
21624,
17,
297,
268,
283,
1365,
63,
466,
356,
283,
2500,
297,
268,
283,
6881,
63,
466,
356,
283,
1832,
297,
268,
283,
1807,
63,
265,
63,
20667,
356,
715,
12,
268,
283,
10409,
63,
908,
356,
283,
9286,
297,
268,
283,
4032,
63,
5610,
356,
283,
15873,
297,
268,
283,
2405,
63,
890,
356,
499,
12,
268,
283,
4930,
63,
1080,
356,
446,
17,
1552,
339,
11413,
63,
3090,
63,
21520,
275,
469,
267,
283,
1782,
63,
354,
356,
1994,
2374,
15,
21624,
17,
297,
267,
283,
9286,
63,
890,
356,
499,
12,
267,
283,
4032,
63,
5610,
356,
283,
15873,
936,
339,
11413,
63,
10000,
63,
3090,
63,
21520,
275,
469,
267,
283,
1782,
63,
354,
356,
1994,
2374,
15,
21624,
17,
297,
267,
283,
9286,
63,
890,
356,
499,
93,
339,
26288,
63,
21520,
275,
1853,
63,
1782,
14,
32442,
2141,
8,
267,
791,
344,
356,
499,
12,
283,
842,
63,
2580,
356,
283,
3183,
13,
842,
297,
268,
283,
1782,
63,
354,
356,
1994,
2374,
15,
83,
3833,
17,
297,
268,
283,
1365,
63,
466,
356,
283,
2500,
297,
268,
283,
6881,
63,
466,
356,
283,
1832,
297,
268,
283,
4032,
63,
5610,
356,
283,
15873,
297,
268,
283,
1782,
63,
466,
356,
283,
4032,
297,
268,
283,
2405,
63,
890,
356,
841,
12,
268,
283,
10409,
63,
908,
356,
283,
832,
20,
297,
268,
283,
1807,
63,
265,
63,
20667,
356,
715,
12,
268,
283,
4930,
63,
1080,
356,
446,
17,
1552,
339,
26288,
63,
3090,
63,
21520,
275,
469,
267,
283,
1782,
63,
354,
356,
1994,
2374,
15,
83,
3833,
17,
297,
267,
283,
890,
356,
841,
12,
267,
283,
1782,
63,
466,
356,
283,
4032,
297,
267,
283,
10409,
63,
908,
356,
283,
832,
20,
297,
267,
283,
4032,
63,
5610,
356,
283,
15873,
936,
339,
26288,
63,
10000,
63,
3090,
63,
21520,
275,
469,
267,
283,
1782,
63,
354,
356,
1994,
2374,
15,
83,
3833,
17,
297,
267,
283,
890,
356,
841,
12,
267,
283,
2065,
63,
354,
356,
283,
19562,
16,
297,
267,
283,
1507,
356,
378,
93,
339,
3301,
63,
21520,
275,
1853,
63,
1782,
14,
32442,
2141,
8,
267,
791,
344,
356,
650,
12,
283,
842,
63,
2580,
356,
283,
3183,
13,
842,
297,
268,
283,
1782,
63,
354,
356,
1994,
2374,
15,
19387,
17,
297,
268,
283,
1365,
63,
466,
356,
283,
2405,
297,
268,
283,
4032,
63,
5610,
356,
283,
15873,
297,
268,
283,
1782,
63,
466,
356,
283,
4032,
297,
268,
283,
2405,
63,
890,
356,
1695,
12,
268,
283,
6881,
63,
466,
356,
283,
2405,
297,
268,
283,
2405,
63,
344,
356,
283,
3183,
13,
2405,
13,
344,
13,
17,
297,
268,
283,
10409,
63,
908,
356,
283,
832,
20,
297,
268,
283,
2105,
63,
815,
356,
17137,
3183,
582,
298,
2105,
63,
815,
3570,
297,
268,
283,
1807,
63,
265,
63,
20667,
356,
756,
12,
268,
283,
4930,
63,
1080,
356,
378,
1552,
339,
3301,
63,
3090,
63,
21520,
275,
469,
267,
283,
3956,
63,
1782,
356,
1994,
2374,
15,
19387,
17,
297,
267,
283,
2105,
63,
815,
356,
2420,
3183,
582,
298,
2105,
63,
815,
6018,
267,
283,
1807,
63,
265,
63,
20667,
356,
756,
12,
267,
283,
4032,
63,
5610,
356,
283,
15873,
297,
267,
283,
1782,
63,
466,
356,
283,
4032,
297,
267,
283,
10409,
63,
908,
356,
283,
832,
20,
297,
267,
283,
4930,
63,
1080,
356,
378,
93,
339,
3301,
63,
10000,
63,
3090,
63,
21520,
275,
469,
267,
283,
3956,
63,
1782,
356,
1994,
2374,
15,
19387,
17,
297,
267,
283,
2105,
63,
815,
356,
2420,
3183,
582,
298,
2105,
63,
815,
6018,
267,
283,
1807,
63,
265,
63,
20667,
356,
756,
93,
339,
5740,
63,
21520,
275,
1853,
63,
1782,
14,
32442,
2141,
8,
267,
791,
344,
356,
841,
12,
283,
842,
63,
2580,
356,
283,
3183,
13,
842,
297,
268,
283,
1782,
63,
354,
356,
1994,
2374,
15,
19387,
18,
297,
268,
283,
1807,
63,
265,
63,
20667,
356,
715,
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,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.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.
# ==============================================================================
"""Init file, giving convenient access to all ndlstm ops."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
# pylint: disable=wildcard-import,g-importing-member
from tensorflow.contrib.ndlstm.python.lstm1d import *
from tensorflow.contrib.ndlstm.python.lstm2d import *
from tensorflow.contrib.ndlstm.python.misc import *
# pylint: enable=wildcard-import
| apache-2.0 | [
3,
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
9346,
570,
12,
15131,
22700,
2879,
370,
1006,
302,
5030,
270,
77,
4156,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
3,
4287,
26,
3507,
29,
16692,
13,
646,
12,
71,
13,
646,
316,
13,
1114,
199,
504,
3228,
14,
2828,
14,
977,
26652,
14,
1548,
14,
26652,
17,
68,
492,
627,
199,
504,
3228,
14,
2828,
14,
977,
26652,
14,
1548,
14,
26652,
18,
68,
492,
627,
199,
504,
3228,
14,
2828,
14,
977,
26652,
14,
1548,
14,
9923,
492,
627,
199,
3,
4287,
26,
4756,
29,
16692,
13,
646,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
1898,
7800,
710,
9134,
6642,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
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,
9346,
570,
12,
15131,
22700,
2879,
370,
1006,
302,
5030,
270,
77,
4156,
1041,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
4629,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
3,
4287,
26,
3507,
29,
16692,
13,
646,
12,
71,
13,
646,
316,
13,
1114,
199,
504,
3228,
14,
2828,
14,
977,
26652,
14,
1548,
14,
26652,
17,
68,
492,
627,
199,
504,
3228,
14,
2828,
14,
977,
26652,
14,
1548,
14,
26652,
18,
68,
492,
627,
199,
504,
3228,
14,
2828,
14,
977,
26652,
14,
1548,
14,
9923,
492,
627,
199,
3,
4287,
26,
4756,
29,
16692,
13,
646,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
tudarmstadt-lt/topicrawler | lt.lm/src/main/py/mr_ngram_count.py | 1 | 1297 | #!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
test:
cat data | map | sort | reduce
cat data | ./x.py -m | sort | ./x.py -r
hadoop jar /opt/cloudera/parcels/CDH/lib/hadoop-mapreduce/hadoop-streaming.jar \
-files x.py \
-mapper 'x.py -m' \
-reducer 'x.py -r' \
-input in \
-output out
@author: stevo
"""
from __future__ import print_function
from __future__ import division
import itertools as it
import sys
def readlines():
with sys.stdin as f:
for line in f:
if line.strip():
yield line
def mapper(lines):
for line in lines:
print('{}'.format(line.rstrip()))
def line2tuple(lines):
for line in lines:
splits = line.rstrip().split('\t')
yield splits
def reducer(lines, mincount=1):
for key, values in it.groupby(lines, lambda line : line.rstrip()):
num = reduce(lambda x, y: x + 1, values, 0)
if num >= mincount:
print('{}\t{}'.format(key, num))
if len(sys.argv) < 2:
raise Exception('specify mapper (-m) or reducer (-r) function')
t = sys.argv[1]
mincount = int(sys.argv[2]) if len(sys.argv) > 2 else 1
if '-m' == t:
mapper(readlines());
elif '-r' == t:
reducer(readlines(), mincount);
else:
raise Exception('specify mapper (-m) or reducer (-r) function') | apache-2.0 | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
199,
396,
26,
272,
6230,
666,
1204,
2341,
1204,
4069,
1204,
7114,
272,
6230,
666,
1204,
16605,
88,
14,
647,
446,
77,
1204,
4069,
1204,
16605,
88,
14,
647,
446,
82,
199,
199,
15449,
16290,
1182,
2992,
15,
1251,
3786,
345,
15,
462,
301,
478,
15,
7695,
40,
15,
773,
15,
15449,
13,
28658,
15,
15449,
13,
12076,
14,
7338,
971,
199,
13,
1725,
671,
14,
647,
971,
199,
13,
7153,
283,
88,
14,
647,
446,
77,
7,
971,
199,
13,
581,
947,
281,
283,
88,
14,
647,
446,
82,
7,
971,
199,
13,
1210,
315,
971,
199,
13,
1199,
734,
199,
199,
32,
2502,
26,
20345,
2392,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
4629,
199,
646,
7975,
465,
652,
199,
646,
984,
199,
199,
318,
1586,
1278,
837,
272,
543,
984,
14,
6626,
465,
289,
26,
267,
367,
1004,
315,
289,
26,
288,
340,
1004,
14,
1913,
837,
355,
1995,
1004,
199,
199,
318,
7796,
8,
1278,
304,
272,
367,
1004,
315,
2385,
26,
267,
870,
360,
11123,
908,
8,
604,
14,
6735,
4059,
199,
199,
318,
1004,
18,
2960,
8,
1278,
304,
272,
367,
1004,
315,
2385,
26,
267,
19115,
275,
1004,
14,
6735,
1252,
1294,
2258,
84,
358,
267,
1995,
19115,
199,
199,
318,
295,
7610,
8,
1278,
12,
1748,
835,
29,
17,
304,
272,
367,
790,
12,
1338,
315,
652,
14,
16968,
8,
1278,
12,
2400,
1004,
520,
1004,
14,
6735,
5109,
267,
1967,
275,
7114,
8,
2734,
671,
12,
612,
26,
671,
435,
413,
12,
1338,
12,
378,
9,
267,
340,
1967,
2356,
1748,
835,
26,
288,
870,
17519,
60,
84,
11123,
908,
8,
498,
12,
1967,
430,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
272,
746,
2186,
360,
26164,
7796,
5868,
77,
9,
503,
295,
7610,
5868,
82,
9,
805,
358,
199,
199,
84,
275,
984,
14,
3020,
59,
17,
61,
199,
827,
835,
275,
1109,
8,
1274,
14,
3020,
59,
18,
566,
340,
822,
8,
1274,
14,
3020,
9,
690,
499,
587,
413,
199,
692,
2475,
77,
7,
508,
307,
26,
272,
7796,
8,
9684,
30910,
199,
4164,
2475,
82,
7,
508,
307,
26,
272,
295,
7610,
8,
9684,
1062,
1748,
835,
2736,
199,
2836,
26,
272,
746,
2186,
360,
26164,
7796,
5868,
77,
9,
503,
295,
7610,
5868,
82,
9,
805,
358,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
199,
396,
26,
272,
6230,
666,
1204,
2341,
1204,
4069,
1204,
7114,
272,
6230,
666,
1204,
16605,
88,
14,
647,
446,
77,
1204,
4069,
1204,
16605,
88,
14,
647,
446,
82,
199,
199,
15449,
16290,
1182,
2992,
15,
1251,
3786,
345,
15,
462,
301,
478,
15,
7695,
40,
15,
773,
15,
15449,
13,
28658,
15,
15449,
13,
12076,
14,
7338,
971,
199,
13,
1725,
671,
14,
647,
971,
199,
13,
7153,
283,
88,
14,
647,
446,
77,
7,
971,
199,
13,
581,
947,
281,
283,
88,
14,
647,
446,
82,
7,
971,
199,
13,
1210,
315,
971,
199,
13,
1199,
734,
199,
199,
32,
2502,
26,
20345,
2392,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
4629,
199,
646,
7975,
465,
652,
199,
646,
984,
199,
199,
318,
1586,
1278,
837,
272,
543,
984,
14,
6626,
465,
289,
26,
267,
367,
1004,
315,
289,
26,
288,
340,
1004,
14,
1913,
837,
355,
1995,
1004,
199,
199,
318,
7796,
8,
1278,
304,
272,
367,
1004,
315,
2385,
26,
267,
870,
360,
11123,
908,
8,
604,
14,
6735,
4059,
199,
199,
318,
1004,
18,
2960,
8,
1278,
304,
272,
367,
1004,
315,
2385,
26,
267,
19115,
275,
1004,
14,
6735,
1252,
1294,
2258,
84,
358,
267,
1995,
19115,
199,
199,
318,
295,
7610,
8,
1278,
12,
1748,
835,
29,
17,
304,
272,
367,
790,
12,
1338,
315,
652,
14,
16968,
8,
1278,
12,
2400,
1004,
520,
1004,
14,
6735,
5109,
267,
1967,
275,
7114,
8,
2734,
671,
12,
612,
26,
671,
435,
413,
12,
1338,
12,
378,
9,
267,
340,
1967,
2356,
1748,
835,
26,
288,
870,
17519,
60,
84,
11123,
908,
8,
498,
12,
1967,
430,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
665,
499,
26,
272,
746,
2186,
360,
26164,
7796,
5868,
77,
9,
503,
295,
7610,
5868,
82,
9,
805,
358,
199,
199,
84,
275,
984,
14,
3020,
59,
17,
61,
199,
827,
835,
275,
1109,
8,
1274,
14,
3020,
59,
18,
566,
340,
822,
8,
1274,
14,
3020,
9,
690,
499,
587,
413,
199,
692,
2475,
77,
7,
508,
307,
26,
272,
7796,
8,
9684,
30910,
199,
4164,
2475,
82,
7,
508,
307,
26,
272,
295,
7610,
8,
9684,
1062,
1748,
835,
2736,
199,
2836,
26,
272,
746,
2186,
360,
26164,
7796,
5868,
77,
9,
503,
295,
7610,
5868,
82,
9,
805,
358,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Brocade-OpenSource/OpenStack-DNRM-Nova | nova/api/openstack/compute/contrib/migrations.py | 3 | 2622 | # vim: tabstop=4 shiftwidth=4 softtabstop=4
# 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 nova.api.openstack import extensions
from nova.api.openstack import wsgi
from nova.api.openstack import xmlutil
from nova import compute
XMLNS = "http://docs.openstack.org/compute/ext/migrations/api/v2.0"
ALIAS = "os-migrations"
def authorize(context, action_name):
action = 'migrations:%s' % action_name
extensions.extension_authorizer('compute', action)(context)
class MigrationsTemplate(xmlutil.TemplateBuilder):
def construct(self):
root = xmlutil.TemplateElement('migrations')
elem = xmlutil.SubTemplateElement(root, 'migration',
selector='migrations')
elem.set('id')
elem.set('source_node')
elem.set('dest_node')
elem.set('source_compute')
elem.set('dest_compute')
elem.set('dest_host')
elem.set('status')
elem.set('instance_uuid')
elem.set('old_instance_type_id')
elem.set('new_instance_type_id')
elem.set('created_at')
elem.set('updated_at')
return xmlutil.MasterTemplate(root, 1)
class MigrationsController(object):
"""Controller for accessing migrations in OpenStack API."""
def __init__(self):
self.compute_api = compute.API()
@wsgi.serializers(xml=MigrationsTemplate)
def index(self, req):
"""Return all migrations in progress."""
context = req.environ['nova.context']
authorize(context, "index")
migrations = self.compute_api.get_migrations(context, req.GET)
return {'migrations': migrations}
class Migrations(extensions.ExtensionDescriptor):
"""Provide data on migrations."""
name = "Migrations"
alias = ALIAS
namespace = XMLNS
updated = "2013-05-30T00:00:00+00:00"
def get_resources(self):
resources = []
resource = extensions.ResourceExtension('os-migrations',
MigrationsController())
resources.append(resource)
return resources
| apache-2.0 | [
3,
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
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,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
14,
1246,
14,
8512,
492,
2748,
1974,
199,
504,
5913,
492,
4526,
421,
199,
4317,
2709,
275,
298,
1014,
921,
4757,
14,
8512,
14,
1308,
15,
3357,
15,
832,
15,
7685,
15,
1246,
15,
86,
18,
14,
16,
2,
199,
12644,
275,
298,
736,
13,
7685,
2,
421,
199,
318,
20210,
8,
1100,
12,
1595,
63,
354,
304,
272,
1595,
275,
283,
7685,
2689,
83,
7,
450,
1595,
63,
354,
272,
5478,
14,
3435,
63,
2502,
1793,
360,
3357,
297,
1595,
5130,
1100,
9,
421,
199,
533,
28195,
3801,
4231,
8,
1652,
1974,
14,
4231,
6437,
304,
272,
347,
6982,
8,
277,
304,
267,
1738,
275,
2748,
1974,
14,
4231,
2162,
360,
7685,
358,
267,
6193,
275,
2748,
1974,
14,
2610,
4231,
2162,
8,
1231,
12,
283,
8998,
297,
5101,
9759,
534,
7685,
358,
267,
6193,
14,
409,
360,
344,
358,
267,
6193,
14,
409,
360,
1365,
63,
932,
358,
267,
6193,
14,
409,
360,
2614,
63,
932,
358,
267,
6193,
14,
409,
360,
1365,
63,
3357,
358,
267,
6193,
14,
409,
360,
2614,
63,
3357,
358,
267,
6193,
14,
409,
360,
2614,
63,
1102,
358,
267,
6193,
14,
409,
360,
1205,
358,
267,
6193,
14,
409,
360,
842,
63,
2580,
358,
267,
6193,
14,
409,
360,
1753,
63,
842,
63,
466,
63,
344,
358,
267,
6193,
14,
409,
360,
1222,
63,
842,
63,
466,
63,
344,
358,
267,
6193,
14,
409,
360,
3966,
63,
292,
358,
267,
6193,
14,
409,
360,
5334,
63,
292,
358,
398,
372,
2748,
1974,
14,
12288,
4231,
8,
1231,
12,
413,
9,
421,
199,
533,
28195,
3801,
7506,
8,
785,
304,
272,
408,
7506,
367,
18549,
6180,
315,
14260,
3261,
1041,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3357,
63,
1246,
275,
4526,
14,
3735,
342,
339,
768,
6508,
14,
12844,
8,
1652,
29,
19322,
3801,
4231,
9,
272,
347,
1478,
8,
277,
12,
2648,
304,
267,
408,
1767,
1006,
6180,
315,
6696,
1041,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
20210,
8,
1100,
12,
298,
1080,
531,
267,
6180,
275,
291,
14,
3357,
63,
1246,
14,
362,
63,
7685,
8,
1100,
12,
2648,
14,
2970,
9,
267,
372,
791,
7685,
356,
6180,
93,
421,
199,
533,
28195,
3801,
8,
5359,
14,
6382,
4311,
304,
272,
408,
25107,
666,
641,
6180,
1041,
272,
536,
275,
298,
19322,
3801,
2,
272,
5162,
275,
437,
2673,
1179,
272,
3231,
275,
4692,
2709,
272,
4588,
275,
298,
6965,
13,
1717,
13,
1216,
52,
383,
26,
383,
26,
383,
11,
383,
26,
383,
2,
339,
347,
664,
63,
4435,
8,
277,
304,
267,
5944,
275,
942,
267,
2073,
275,
5478,
14,
4031,
6382,
360,
736,
13,
7685,
297,
6059,
28195,
3801,
7506,
1012,
267,
5944,
14,
740,
8,
1927,
9,
267,
372,
5944,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
6695,
26,
20849,
29,
20,
20105,
29,
20,
25966,
29,
20,
199,
199,
3,
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,
199,
199,
504,
5913,
14,
1246,
14,
8512,
492,
5478,
199,
504,
5913,
14,
1246,
14,
8512,
492,
12464,
199,
504,
5913,
14,
1246,
14,
8512,
492,
2748,
1974,
199,
504,
5913,
492,
4526,
421,
199,
4317,
2709,
275,
298,
1014,
921,
4757,
14,
8512,
14,
1308,
15,
3357,
15,
832,
15,
7685,
15,
1246,
15,
86,
18,
14,
16,
2,
199,
12644,
275,
298,
736,
13,
7685,
2,
421,
199,
318,
20210,
8,
1100,
12,
1595,
63,
354,
304,
272,
1595,
275,
283,
7685,
2689,
83,
7,
450,
1595,
63,
354,
272,
5478,
14,
3435,
63,
2502,
1793,
360,
3357,
297,
1595,
5130,
1100,
9,
421,
199,
533,
28195,
3801,
4231,
8,
1652,
1974,
14,
4231,
6437,
304,
272,
347,
6982,
8,
277,
304,
267,
1738,
275,
2748,
1974,
14,
4231,
2162,
360,
7685,
358,
267,
6193,
275,
2748,
1974,
14,
2610,
4231,
2162,
8,
1231,
12,
283,
8998,
297,
5101,
9759,
534,
7685,
358,
267,
6193,
14,
409,
360,
344,
358,
267,
6193,
14,
409,
360,
1365,
63,
932,
358,
267,
6193,
14,
409,
360,
2614,
63,
932,
358,
267,
6193,
14,
409,
360,
1365,
63,
3357,
358,
267,
6193,
14,
409,
360,
2614,
63,
3357,
358,
267,
6193,
14,
409,
360,
2614,
63,
1102,
358,
267,
6193,
14,
409,
360,
1205,
358,
267,
6193,
14,
409,
360,
842,
63,
2580,
358,
267,
6193,
14,
409,
360,
1753,
63,
842,
63,
466,
63,
344,
358,
267,
6193,
14,
409,
360,
1222,
63,
842,
63,
466,
63,
344,
358,
267,
6193,
14,
409,
360,
3966,
63,
292,
358,
267,
6193,
14,
409,
360,
5334,
63,
292,
358,
398,
372,
2748,
1974,
14,
12288,
4231,
8,
1231,
12,
413,
9,
421,
199,
533,
28195,
3801,
7506,
8,
785,
304,
272,
408,
7506,
367,
18549,
6180,
315,
14260,
3261,
1041,
272,
347,
636,
826,
721,
277,
304,
267,
291,
14,
3357,
63,
1246,
275,
4526,
14,
3735,
342,
339,
768,
6508,
14,
12844,
8,
1652,
29,
19322,
3801,
4231,
9,
272,
347,
1478,
8,
277,
12,
2648,
304,
267,
408,
1767,
1006,
6180,
315,
6696,
1041,
267,
1067,
275,
2648,
14,
2314,
459,
6765,
14,
1100,
418,
267,
20210,
8,
1100,
12,
298,
1080,
531,
267,
6180,
275,
291,
14,
3357,
63,
1246,
14,
362,
63,
7685,
8,
1100,
12,
2648,
14,
2970,
9,
267,
372,
791,
7685,
356,
6180,
93,
421,
199,
533,
28195,
3801,
8,
5359,
14,
6382,
4311,
304,
272,
408,
25107,
666,
641,
6180,
1041,
272,
536,
275,
298,
19322,
3801,
2,
272,
5162,
275,
437,
2673,
1179,
272,
3231,
275,
4692,
2709,
272,
4588,
275,
298,
6965,
13,
1717,
13,
1216,
52,
383,
26,
383,
26,
383,
11,
383,
26,
383,
2,
339,
347,
664,
63,
4435,
8,
277,
304,
267,
5944,
275,
942,
267,
2073,
275,
5478,
14,
4031,
6382,
360,
736,
13,
7685,
297,
6059,
28195,
3801,
7506,
1012,
267,
5944,
14,
740,
8,
1927,
9,
267,
372,
5944,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
nirmeshk/oh-mainline | vendor/packages/python-social-auth/social/tests/backends/test_linkedin.py | 92 | 1050 | import json
from social.p3 import urlencode
from social.tests.backends.oauth import OAuth1Test, OAuth2Test
class BaseLinkedinTest(object):
user_data_url = 'https://api.linkedin.com/v1/people/~:' \
'(first-name,id,last-name)'
expected_username = 'FooBar'
access_token_body = json.dumps({
'access_token': 'foobar',
'token_type': 'bearer'
})
user_data_body = json.dumps({
'lastName': 'Bar',
'id': '1010101010',
'firstName': 'Foo'
})
def test_login(self):
self.do_login()
def test_partial_pipeline(self):
self.do_partial_pipeline()
class LinkedinOAuth1Test(BaseLinkedinTest, OAuth1Test):
backend_path = 'social.backends.linkedin.LinkedinOAuth'
request_token_body = urlencode({
'oauth_token_secret': 'foobar-secret',
'oauth_token': 'foobar',
'oauth_callback_confirmed': 'true'
})
class LinkedinOAuth2Test(BaseLinkedinTest, OAuth2Test):
backend_path = 'social.backends.linkedin.LinkedinOAuth2'
| agpl-3.0 | [
646,
2022,
199,
199,
504,
20295,
14,
80,
19,
492,
16511,
199,
199,
504,
20295,
14,
2219,
14,
7765,
14,
6126,
492,
11715,
17,
774,
12,
11715,
18,
774,
421,
199,
533,
3523,
26748,
262,
774,
8,
785,
304,
272,
922,
63,
576,
63,
633,
275,
283,
2859,
921,
1246,
14,
12751,
262,
14,
957,
15,
86,
17,
15,
13562,
22500,
4881,
971,
717,
8189,
2246,
13,
354,
12,
344,
12,
2019,
13,
354,
3171,
272,
1420,
63,
2473,
275,
283,
5686,
5281,
7,
272,
2879,
63,
1418,
63,
2030,
275,
2022,
14,
4180,
2561,
267,
283,
2732,
63,
1418,
356,
283,
9664,
297,
267,
283,
1418,
63,
466,
356,
283,
1235,
21462,
7,
272,
3828,
272,
922,
63,
576,
63,
2030,
275,
2022,
14,
4180,
2561,
267,
283,
2019,
985,
356,
283,
5281,
297,
267,
283,
344,
356,
283,
4893,
11502,
9523,
297,
267,
283,
2246,
985,
356,
283,
5686,
7,
272,
3828,
339,
347,
511,
63,
2886,
8,
277,
304,
267,
291,
14,
1117,
63,
2886,
342,
339,
347,
511,
63,
6672,
63,
7379,
8,
277,
304,
267,
291,
14,
1117,
63,
6672,
63,
7379,
342,
421,
199,
533,
10967,
379,
262,
12906,
17,
774,
8,
1563,
26748,
262,
774,
12,
11715,
17,
774,
304,
272,
4865,
63,
515,
275,
283,
13574,
14,
7765,
14,
12751,
262,
14,
26748,
262,
12906,
7,
272,
1056,
63,
1418,
63,
2030,
275,
16511,
2561,
267,
283,
6126,
63,
1418,
63,
4731,
356,
283,
9664,
13,
4731,
297,
267,
283,
6126,
63,
1418,
356,
283,
9664,
297,
267,
283,
6126,
63,
3058,
63,
16391,
356,
283,
2052,
7,
272,
3828,
421,
199,
533,
10967,
379,
262,
12906,
18,
774,
8,
1563,
26748,
262,
774,
12,
11715,
18,
774,
304,
272,
4865,
63,
515,
275,
283,
13574,
14,
7765,
14,
12751,
262,
14,
26748,
262,
12906,
18,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
2022,
199,
199,
504,
20295,
14,
80,
19,
492,
16511,
199,
199,
504,
20295,
14,
2219,
14,
7765,
14,
6126,
492,
11715,
17,
774,
12,
11715,
18,
774,
421,
199,
533,
3523,
26748,
262,
774,
8,
785,
304,
272,
922,
63,
576,
63,
633,
275,
283,
2859,
921,
1246,
14,
12751,
262,
14,
957,
15,
86,
17,
15,
13562,
22500,
4881,
971,
717,
8189,
2246,
13,
354,
12,
344,
12,
2019,
13,
354,
3171,
272,
1420,
63,
2473,
275,
283,
5686,
5281,
7,
272,
2879,
63,
1418,
63,
2030,
275,
2022,
14,
4180,
2561,
267,
283,
2732,
63,
1418,
356,
283,
9664,
297,
267,
283,
1418,
63,
466,
356,
283,
1235,
21462,
7,
272,
3828,
272,
922,
63,
576,
63,
2030,
275,
2022,
14,
4180,
2561,
267,
283,
2019,
985,
356,
283,
5281,
297,
267,
283,
344,
356,
283,
4893,
11502,
9523,
297,
267,
283,
2246,
985,
356,
283,
5686,
7,
272,
3828,
339,
347,
511,
63,
2886,
8,
277,
304,
267,
291,
14,
1117,
63,
2886,
342,
339,
347,
511,
63,
6672,
63,
7379,
8,
277,
304,
267,
291,
14,
1117,
63,
6672,
63,
7379,
342,
421,
199,
533,
10967,
379,
262,
12906,
17,
774,
8,
1563,
26748,
262,
774,
12,
11715,
17,
774,
304,
272,
4865,
63,
515,
275,
283,
13574,
14,
7765,
14,
12751,
262,
14,
26748,
262,
12906,
7,
272,
1056,
63,
1418,
63,
2030,
275,
16511,
2561,
267,
283,
6126,
63,
1418,
63,
4731,
356,
283,
9664,
13,
4731,
297,
267,
283,
6126,
63,
1418,
356,
283,
9664,
297,
267,
283,
6126,
63,
3058,
63,
16391,
356,
283,
2052,
7,
272,
3828,
421,
199,
533,
10967,
379,
262,
12906,
18,
774,
8,
1563,
26748,
262,
774,
12,
11715,
18,
774,
304,
272,
4865,
63,
515,
275,
283,
13574,
14,
7765,
14,
12751,
262,
14,
26748,
262,
12906,
18,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
ArcaniteSolutions/truffe2 | truffe2/truffe/management/commands/import_ndfs.py | 2 | 4367 | # -*- coding: utf-8 -*-
from django.contrib.contenttypes.models import ContentType
from django.core.management.base import BaseCommand, CommandError
from django.utils.timezone import now
from accounting_core.models import CostCenter, AccountingYear, Account
from accounting_tools.models import ExpenseClaim, ExpenseClaimFile, ExpenseClaimLine, ExpenseClaimLogging, LinkedInfo
from app.ldaputils import get_attrs_of_sciper
from users.models import TruffeUser
import json
import os
import sys
class Command(BaseCommand):
""" Requirements : files in /media/uploads/_generic/ExpenseClaim/"""
help = 'Import notes de frais'
def handle(self, *args, **options):
data = json.loads(sys.stdin.read())
root_user = TruffeUser.objects.get(username=179189)
expenseclaim_ct = ContentType.objects.get(app_label="accounting_tools", model="expenseclaim")
status_mapping = {'1': '0_draft', '2': '2_agep_validable', '3': '4_archived'}
for ndf_data in data['data']:
try:
ay = AccountingYear.objects.get(name=ndf_data['accounting_year__name'])
except:
print u"AccountingYear not found !!", ndf_data['accounting_year__name']
ay = None
if ay:
try:
costcenter = CostCenter.objects.get(account_number=ndf_data['costcenter__account_number'], accounting_year=ay)
except:
print u"CostCenter not found !!", ndf_data['costcenter__account_number']
costcenter = None
if costcenter:
try:
user = TruffeUser.objects.get(username=ndf_data['creator_username'])
except TruffeUser.DoesNotExist:
print "Creation of user {!r}".format(ndf_data['creator_username'])
user = TruffeUser(username=ndf_data['creator_username'], is_active=True)
user.last_name, user.first_name, user.email = get_attrs_of_sciper(ndf_data['creator_username'])
user.save()
except Exception as e:
print "user is root_user", e
user = root_user
ndf, created = ExpenseClaim.objects.get_or_create(costcenter=costcenter, accounting_year=ay, user=user, status=status_mapping[ndf_data['status']],
comment=ndf_data['commentaire'], name=ndf_data['name'], nb_proofs=ndf_data['nb_just'])
if created:
ExpenseClaimLogging(who=user, what='imported', object=ndf).save()
print "+ {!r}".format(ndf.name)
if ndf_data['linked_info']:
linked, created = LinkedInfo.objects.get_or_create(object_id=ndf.pk, content_type=expenseclaim_ct, user_pk=user.pk, **ndf_data['linked_info'])
if created:
print " (I) {!r} {!r}".format(linked.first_name, linked.last_name)
for line_data in ndf_data['lines']:
account = Account.objects.get(account_number=line_data['account__account_number'], accounting_year=ay)
__, created = ExpenseClaimLine.objects.get_or_create(expense_claim=ndf, label=line_data['name'], account=account, proof=line_data['just'],
order=line_data['order'], value=line_data['amount'], value_ttc=line_data['amount'], tva=0)
if created:
print " (+) {!r}".format(line_data['name'])
for file_data in ndf_data['uploads']:
if not os.path.isfile(os.path.join('media', 'uploads', '_generic', 'ExpenseClaim', file_data.split('/')[-1])):
print " (!) Missing file {}".format(file_data)
else:
__, created = ExpenseClaimFile.objects.get_or_create(uploader=user, object=ndf, file=os.path.join('uploads', '_generic', 'ExpenseClaim', file_data.split('/')[-1]), defaults={'upload_date': now()})
if created:
print " (L) {!r}".format(file_data)
| bsd-2-clause | [
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
504,
1639,
14,
1208,
14,
7145,
492,
3063,
199,
199,
504,
24772,
63,
1018,
14,
992,
492,
24681,
13551,
12,
9973,
316,
15731,
12,
9973,
199,
504,
24772,
63,
2537,
14,
992,
492,
7910,
677,
12086,
1017,
12,
7910,
677,
12086,
1017,
1173,
12,
7910,
677,
12086,
1017,
3049,
12,
7910,
677,
12086,
1017,
14054,
12,
10967,
379,
2354,
199,
504,
1145,
14,
9642,
1208,
492,
664,
63,
3288,
63,
1618,
63,
9907,
529,
199,
504,
4390,
14,
992,
492,
377,
6558,
2026,
1899,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
984,
421,
199,
533,
5817,
8,
25150,
304,
272,
408,
18513,
1470,
520,
1584,
315,
1182,
4603,
15,
21725,
15607,
6767,
15,
4527,
677,
12086,
1017,
15,
624,
339,
1720,
275,
283,
6295,
12681,
477,
28213,
374,
7,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
398,
666,
275,
2022,
14,
3640,
8,
1274,
14,
6626,
14,
739,
1012,
398,
1738,
63,
751,
275,
377,
6558,
2026,
1899,
14,
1462,
14,
362,
8,
2473,
29,
10699,
11370,
9,
267,
26963,
17904,
63,
319,
275,
14501,
14,
1462,
14,
362,
8,
571,
63,
1302,
628,
21609,
63,
2537,
401,
1402,
628,
16886,
17904,
531,
267,
2004,
63,
4745,
275,
791,
17,
356,
283,
16,
63,
7185,
297,
283,
18,
356,
283,
18,
63,
474,
80,
63,
1078,
461,
297,
283,
19,
356,
283,
20,
63,
1047,
12905,
936,
398,
367,
302,
1587,
63,
576,
315,
666,
459,
576,
2565,
288,
862,
26,
355,
282,
89,
275,
9973,
316,
15731,
14,
1462,
14,
362,
8,
354,
29,
977,
70,
63,
576,
459,
21609,
63,
3403,
363,
354,
1105,
288,
871,
26,
355,
870,
399,
2,
6009,
316,
15731,
440,
1911,
221,
3480,
401,
302,
1587,
63,
576,
459,
21609,
63,
3403,
363,
354,
418,
355,
282,
89,
275,
488,
953,
340,
282,
89,
26,
355,
862,
26,
490,
7918,
4218,
275,
24681,
13551,
14,
1462,
14,
362,
8,
2048,
63,
1955,
29,
977,
70,
63,
576,
459,
6336,
4218,
363,
2048,
63,
1955,
995,
24772,
63,
3403,
29,
1187,
9,
355,
871,
26,
490,
870,
399,
2,
15568,
13551,
440,
1911,
221,
3480,
401,
302,
1587,
63,
576,
459,
6336,
4218,
363,
2048,
63,
1955,
418,
490,
7918,
4218,
275,
488,
2234,
340,
7918,
4218,
26,
490,
862,
26,
717,
922,
275,
377,
6558,
2026,
1899,
14,
1462,
14,
362,
8,
2473,
29,
977,
70,
63,
576,
459,
9986,
63,
2473,
1105,
490,
871,
377,
6558,
2026,
1899,
14,
7400,
26,
717,
870,
298,
13921,
402,
922,
18776,
82,
5469,
908,
8,
977,
70,
63,
576,
459,
9986,
63,
2473,
1105,
717,
922,
275,
377,
6558,
2026,
1899,
8,
2473,
29,
977,
70,
63,
576,
459,
9986,
63,
2473,
995,
365,
63,
2682,
29,
549,
9,
717,
922,
14,
2019,
63,
354,
12,
922,
14,
2246,
63,
354,
12,
922,
14,
2123,
275,
664,
63,
3288,
63,
1618,
63,
9907,
529,
8,
977,
70,
63,
576,
459,
9986,
63,
2473,
1105,
717,
922,
14,
2117,
342,
490,
871,
2186,
465,
325,
26,
717,
870,
298,
751,
365,
1738,
63,
751,
401,
325,
717,
922,
275,
1738,
63,
751,
4951,
302,
1587,
12,
2737,
275,
7910,
677,
12086,
1017,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
6336,
4218,
29,
6336,
4218,
12,
24772,
63,
3403,
29,
1187,
12,
922,
29,
751,
12,
2004,
29,
1205,
63,
4745,
59,
977,
70,
63,
576,
459,
1205,
2157,
6684,
420,
3721,
29,
977,
70,
63,
576,
459,
3349,
65,
3621,
995,
536,
29,
977,
70,
63,
576,
459,
354,
995,
8526,
63,
496,
14105,
29,
977,
70,
63,
576,
459,
4994,
63,
4764,
1105,
4951,
340,
2737,
26,
717,
7910,
677,
12086,
1017,
14054,
8,
11345,
29,
751,
12,
4052,
534,
17932,
297,
909,
29,
977,
70,
680,
2117,
342,
717,
870,
7210,
18776,
82,
5469,
908,
8,
977,
70,
14,
354,
9,
4951,
340,
302,
1587,
63,
576,
459,
12751,
63,
815,
2565,
717,
10632,
12,
2737,
275,
10967,
379,
2354,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
785,
63,
344,
29,
977,
70,
14,
2051,
12,
1564,
63,
466,
29,
16886,
17904,
63,
319,
12,
922,
63,
2051,
29,
751,
14,
2051,
12,
1011,
977,
70,
63,
576,
459,
12751,
63,
815,
1105,
717,
340,
2737,
26,
1169,
870,
298,
221,
334,
41,
9,
18776,
82,
93,
18776,
82,
5469,
908,
8,
12751,
14,
2246,
63,
354,
12,
10632,
14,
2019,
63,
354,
9,
4951,
367,
1004,
63,
576,
315,
302,
1587,
63,
576,
459,
1278,
2565,
717,
2933,
275,
9973,
14,
1462,
14,
362,
8,
2048,
63,
1955,
29,
604,
63,
576,
459,
2048,
363,
2048,
63,
1955,
995,
24772,
63,
3403,
29,
1187,
9,
717,
636,
12,
2737,
275,
7910,
677,
12086,
1017,
3049,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
16886,
63,
17904,
29,
977,
70,
12,
1768,
29,
604,
63,
576,
459,
354,
995,
2933,
29,
2048,
12,
557,
1618,
29,
604,
63,
576,
459,
4764,
995,
6684,
3777,
1865,
29,
604,
63,
576,
459,
1648,
995,
574,
29,
604,
63,
576,
459,
4606,
995,
574,
63,
84,
3641,
29,
604,
63,
576,
459,
4606,
995,
307,
3042,
29,
16,
9,
717,
340,
2737,
26,
1169,
870,
298,
221,
334,
8771,
18776,
82,
5469,
908,
8,
604,
63,
576,
459,
354,
1105,
4951,
367,
570,
63,
576,
315,
302,
1587,
63,
576,
459,
21725,
2565,
717,
340,
440,
747,
14,
515,
14,
6292,
8,
736,
14,
515,
14,
904,
360,
4603,
297,
283,
21725,
297,
2513,
6767,
297,
283,
4527,
677,
12086,
1017,
297,
570,
63,
576,
14,
1294,
25804,
17,
18710,
1169,
870,
298,
257,
19452,
9,
15626,
570,
8352,
908,
8,
493,
63,
576,
9,
717,
587,
26,
1169,
636,
12,
2737,
275,
7910,
677,
12086,
1017,
1173,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
13671,
29,
751,
12,
909,
29,
977,
70,
12,
570,
29,
736,
14,
515,
14,
904,
360,
21725
] | [
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
504,
1639,
14,
2828,
14,
10778,
14,
992,
492,
14501,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
504,
1639,
14,
1208,
14,
7145,
492,
3063,
199,
199,
504,
24772,
63,
1018,
14,
992,
492,
24681,
13551,
12,
9973,
316,
15731,
12,
9973,
199,
504,
24772,
63,
2537,
14,
992,
492,
7910,
677,
12086,
1017,
12,
7910,
677,
12086,
1017,
1173,
12,
7910,
677,
12086,
1017,
3049,
12,
7910,
677,
12086,
1017,
14054,
12,
10967,
379,
2354,
199,
504,
1145,
14,
9642,
1208,
492,
664,
63,
3288,
63,
1618,
63,
9907,
529,
199,
504,
4390,
14,
992,
492,
377,
6558,
2026,
1899,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
984,
421,
199,
533,
5817,
8,
25150,
304,
272,
408,
18513,
1470,
520,
1584,
315,
1182,
4603,
15,
21725,
15607,
6767,
15,
4527,
677,
12086,
1017,
15,
624,
339,
1720,
275,
283,
6295,
12681,
477,
28213,
374,
7,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
398,
666,
275,
2022,
14,
3640,
8,
1274,
14,
6626,
14,
739,
1012,
398,
1738,
63,
751,
275,
377,
6558,
2026,
1899,
14,
1462,
14,
362,
8,
2473,
29,
10699,
11370,
9,
267,
26963,
17904,
63,
319,
275,
14501,
14,
1462,
14,
362,
8,
571,
63,
1302,
628,
21609,
63,
2537,
401,
1402,
628,
16886,
17904,
531,
267,
2004,
63,
4745,
275,
791,
17,
356,
283,
16,
63,
7185,
297,
283,
18,
356,
283,
18,
63,
474,
80,
63,
1078,
461,
297,
283,
19,
356,
283,
20,
63,
1047,
12905,
936,
398,
367,
302,
1587,
63,
576,
315,
666,
459,
576,
2565,
288,
862,
26,
355,
282,
89,
275,
9973,
316,
15731,
14,
1462,
14,
362,
8,
354,
29,
977,
70,
63,
576,
459,
21609,
63,
3403,
363,
354,
1105,
288,
871,
26,
355,
870,
399,
2,
6009,
316,
15731,
440,
1911,
221,
3480,
401,
302,
1587,
63,
576,
459,
21609,
63,
3403,
363,
354,
418,
355,
282,
89,
275,
488,
953,
340,
282,
89,
26,
355,
862,
26,
490,
7918,
4218,
275,
24681,
13551,
14,
1462,
14,
362,
8,
2048,
63,
1955,
29,
977,
70,
63,
576,
459,
6336,
4218,
363,
2048,
63,
1955,
995,
24772,
63,
3403,
29,
1187,
9,
355,
871,
26,
490,
870,
399,
2,
15568,
13551,
440,
1911,
221,
3480,
401,
302,
1587,
63,
576,
459,
6336,
4218,
363,
2048,
63,
1955,
418,
490,
7918,
4218,
275,
488,
2234,
340,
7918,
4218,
26,
490,
862,
26,
717,
922,
275,
377,
6558,
2026,
1899,
14,
1462,
14,
362,
8,
2473,
29,
977,
70,
63,
576,
459,
9986,
63,
2473,
1105,
490,
871,
377,
6558,
2026,
1899,
14,
7400,
26,
717,
870,
298,
13921,
402,
922,
18776,
82,
5469,
908,
8,
977,
70,
63,
576,
459,
9986,
63,
2473,
1105,
717,
922,
275,
377,
6558,
2026,
1899,
8,
2473,
29,
977,
70,
63,
576,
459,
9986,
63,
2473,
995,
365,
63,
2682,
29,
549,
9,
717,
922,
14,
2019,
63,
354,
12,
922,
14,
2246,
63,
354,
12,
922,
14,
2123,
275,
664,
63,
3288,
63,
1618,
63,
9907,
529,
8,
977,
70,
63,
576,
459,
9986,
63,
2473,
1105,
717,
922,
14,
2117,
342,
490,
871,
2186,
465,
325,
26,
717,
870,
298,
751,
365,
1738,
63,
751,
401,
325,
717,
922,
275,
1738,
63,
751,
4951,
302,
1587,
12,
2737,
275,
7910,
677,
12086,
1017,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
6336,
4218,
29,
6336,
4218,
12,
24772,
63,
3403,
29,
1187,
12,
922,
29,
751,
12,
2004,
29,
1205,
63,
4745,
59,
977,
70,
63,
576,
459,
1205,
2157,
6684,
420,
3721,
29,
977,
70,
63,
576,
459,
3349,
65,
3621,
995,
536,
29,
977,
70,
63,
576,
459,
354,
995,
8526,
63,
496,
14105,
29,
977,
70,
63,
576,
459,
4994,
63,
4764,
1105,
4951,
340,
2737,
26,
717,
7910,
677,
12086,
1017,
14054,
8,
11345,
29,
751,
12,
4052,
534,
17932,
297,
909,
29,
977,
70,
680,
2117,
342,
717,
870,
7210,
18776,
82,
5469,
908,
8,
977,
70,
14,
354,
9,
4951,
340,
302,
1587,
63,
576,
459,
12751,
63,
815,
2565,
717,
10632,
12,
2737,
275,
10967,
379,
2354,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
785,
63,
344,
29,
977,
70,
14,
2051,
12,
1564,
63,
466,
29,
16886,
17904,
63,
319,
12,
922,
63,
2051,
29,
751,
14,
2051,
12,
1011,
977,
70,
63,
576,
459,
12751,
63,
815,
1105,
717,
340,
2737,
26,
1169,
870,
298,
221,
334,
41,
9,
18776,
82,
93,
18776,
82,
5469,
908,
8,
12751,
14,
2246,
63,
354,
12,
10632,
14,
2019,
63,
354,
9,
4951,
367,
1004,
63,
576,
315,
302,
1587,
63,
576,
459,
1278,
2565,
717,
2933,
275,
9973,
14,
1462,
14,
362,
8,
2048,
63,
1955,
29,
604,
63,
576,
459,
2048,
363,
2048,
63,
1955,
995,
24772,
63,
3403,
29,
1187,
9,
717,
636,
12,
2737,
275,
7910,
677,
12086,
1017,
3049,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
16886,
63,
17904,
29,
977,
70,
12,
1768,
29,
604,
63,
576,
459,
354,
995,
2933,
29,
2048,
12,
557,
1618,
29,
604,
63,
576,
459,
4764,
995,
6684,
3777,
1865,
29,
604,
63,
576,
459,
1648,
995,
574,
29,
604,
63,
576,
459,
4606,
995,
574,
63,
84,
3641,
29,
604,
63,
576,
459,
4606,
995,
307,
3042,
29,
16,
9,
717,
340,
2737,
26,
1169,
870,
298,
221,
334,
8771,
18776,
82,
5469,
908,
8,
604,
63,
576,
459,
354,
1105,
4951,
367,
570,
63,
576,
315,
302,
1587,
63,
576,
459,
21725,
2565,
717,
340,
440,
747,
14,
515,
14,
6292,
8,
736,
14,
515,
14,
904,
360,
4603,
297,
283,
21725,
297,
2513,
6767,
297,
283,
4527,
677,
12086,
1017,
297,
570,
63,
576,
14,
1294,
25804,
17,
18710,
1169,
870,
298,
257,
19452,
9,
15626,
570,
8352,
908,
8,
493,
63,
576,
9,
717,
587,
26,
1169,
636,
12,
2737,
275,
7910,
677,
12086,
1017,
1173,
14,
1462,
14,
362,
63,
269,
63,
981,
8,
13671,
29,
751,
12,
909,
29,
977,
70,
12,
570,
29,
736,
14,
515,
14,
904,
360,
21725,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
pcsforeducation/incrowd | incrowd/notify/utils.py | 2 | 1296 | from __future__ import unicode_literals
import logging
from notify.models import Notification
logger = logging.getLogger(__name__)
def ping_filter(message, users, sending_user, notify_text, notify_type,
notify_id=None):
for user in users:
if username_in_message(message, user.username):
# Create notification
if user == sending_user:
continue
note = Notification(
text='{} {}: {}'.format(
sending_user.username, notify_text, message),
user=user,
from_user=sending_user,
type=notify_type,
identifier=notify_id)
note.save()
logger.info("Created notification for user {} from {}"
.format(note.user, note.from_user))
return message
def username_in_message(message, username):
message = message.lower()
username = username.lower()
# Check if @username in message. Edge case for username at the end of
# the message.
if '@' + username + ' ' in message.lower():
return True
try:
return (message.index('@' + username) ==
len(message.lower()) - len('@' + username))
except ValueError:
return False
| apache-2.0 | [
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2050,
199,
199,
504,
11705,
14,
992,
492,
23362,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
18249,
63,
1541,
8,
1188,
12,
4390,
12,
10209,
63,
751,
12,
11705,
63,
505,
12,
11705,
63,
466,
12,
355,
11705,
63,
344,
29,
403,
304,
272,
367,
922,
315,
4390,
26,
267,
340,
3434,
63,
262,
63,
1188,
8,
1188,
12,
922,
14,
2473,
304,
288,
327,
2790,
6955,
288,
340,
922,
508,
10209,
63,
751,
26,
355,
1980,
288,
5317,
275,
23362,
8,
355,
1318,
534,
2440,
24702,
9499,
908,
8,
490,
10209,
63,
751,
14,
2473,
12,
11705,
63,
505,
12,
1245,
395,
355,
922,
29,
751,
12,
355,
687,
63,
751,
29,
24450,
63,
751,
12,
355,
730,
29,
6814,
63,
466,
12,
355,
5148,
29,
6814,
63,
344,
9,
288,
5317,
14,
2117,
342,
288,
2512,
14,
815,
480,
10502,
6955,
367,
922,
1052,
687,
1052,
2,
717,
1275,
908,
8,
4610,
14,
751,
12,
5317,
14,
504,
63,
751,
430,
272,
372,
1245,
421,
199,
318,
3434,
63,
262,
63,
1188,
8,
1188,
12,
3434,
304,
272,
1245,
275,
1245,
14,
2325,
342,
272,
3434,
275,
3434,
14,
2325,
342,
272,
327,
2670,
340,
768,
2473,
315,
1245,
14,
25155,
1930,
367,
3434,
737,
314,
1284,
402,
272,
327,
314,
1245,
14,
272,
340,
22143,
435,
3434,
435,
283,
283,
315,
1245,
14,
2325,
837,
267,
372,
715,
272,
862,
26,
267,
372,
334,
1188,
14,
1080,
16591,
7,
435,
3434,
9,
508,
355,
822,
8,
1188,
14,
2325,
1012,
446,
822,
16591,
7,
435,
3434,
430,
272,
871,
1722,
26,
267,
372,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
2050,
199,
199,
504,
11705,
14,
992,
492,
23362,
421,
199,
2921,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
318,
18249,
63,
1541,
8,
1188,
12,
4390,
12,
10209,
63,
751,
12,
11705,
63,
505,
12,
11705,
63,
466,
12,
355,
11705,
63,
344,
29,
403,
304,
272,
367,
922,
315,
4390,
26,
267,
340,
3434,
63,
262,
63,
1188,
8,
1188,
12,
922,
14,
2473,
304,
288,
327,
2790,
6955,
288,
340,
922,
508,
10209,
63,
751,
26,
355,
1980,
288,
5317,
275,
23362,
8,
355,
1318,
534,
2440,
24702,
9499,
908,
8,
490,
10209,
63,
751,
14,
2473,
12,
11705,
63,
505,
12,
1245,
395,
355,
922,
29,
751,
12,
355,
687,
63,
751,
29,
24450,
63,
751,
12,
355,
730,
29,
6814,
63,
466,
12,
355,
5148,
29,
6814,
63,
344,
9,
288,
5317,
14,
2117,
342,
288,
2512,
14,
815,
480,
10502,
6955,
367,
922,
1052,
687,
1052,
2,
717,
1275,
908,
8,
4610,
14,
751,
12,
5317,
14,
504,
63,
751,
430,
272,
372,
1245,
421,
199,
318,
3434,
63,
262,
63,
1188,
8,
1188,
12,
3434,
304,
272,
1245,
275,
1245,
14,
2325,
342,
272,
3434,
275,
3434,
14,
2325,
342,
272,
327,
2670,
340,
768,
2473,
315,
1245,
14,
25155,
1930,
367,
3434,
737,
314,
1284,
402,
272,
327,
314,
1245,
14,
272,
340,
22143,
435,
3434,
435,
283,
283,
315,
1245,
14,
2325,
837,
267,
372,
715,
272,
862,
26,
267,
372,
334,
1188,
14,
1080,
16591,
7,
435,
3434,
9,
508,
355,
822,
8,
1188,
14,
2325,
1012,
446,
822,
16591,
7,
435,
3434,
430,
272,
871,
1722,
26,
267,
372,
756,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
Ziqi-Li/bknqgis | bokeh/bokeh/sphinxext/example_handler.py | 1 | 2905 | import sys
from ..application.handlers.code_runner import CodeRunner
from ..application.handlers.handler import Handler
from ..io import set_curdoc, curdoc
class ExampleHandler(Handler):
""" A stripped-down handler similar to CodeHandler but that does
some appropriate monkeypatching to
"""
_output_funcs = ['output_notebook', 'output_file', 'reset_output']
_io_funcs = ['show', 'save']
def __init__(self, source, filename):
super(ExampleHandler, self).__init__(self)
self._runner = CodeRunner(source, filename, [])
def modify_document(self, doc):
if self.failed:
return
module = self._runner.new_module()
sys.modules[module.__name__] = module
doc._modules.append(module)
old_doc = curdoc()
set_curdoc(doc)
old_io, old_doc = self._monkeypatch()
try:
self._runner.run(module, lambda: None)
finally:
self._unmonkeypatch(old_io, old_doc)
set_curdoc(old_doc)
def _monkeypatch(self):
def _pass(*args, **kw): pass
def _add_root(obj, *args, **kw):
from bokeh.io import curdoc
curdoc().add_root(obj)
def _curdoc(*args, **kw):
return curdoc()
# these functions are transitively imported from io into plotting,
# so we have to patch them all. Assumption is that no other patching
# has occurred, i.e. we can just save the funcs being patched once,
# from io, and use those as the originals to replace everywhere
import bokeh.io as io
import bokeh.plotting as p
mods = [io, p]
# TODO (bev) restore when bkcharts package is ready (but remove at 1.0 release)
# import bkcharts as c
# mods.append(c)
old_io = {}
for f in self._output_funcs + self._io_funcs:
old_io[f] = getattr(io, f)
for mod in mods:
for f in self._output_funcs:
setattr(mod, f, _pass)
for f in self._io_funcs:
setattr(mod, f, _add_root)
import bokeh.document as d
old_doc = d.Document
d.Document = _curdoc
return old_io, old_doc
def _unmonkeypatch(self, old_io, old_doc):
import bokeh.io as io
import bokeh.plotting as p
mods = [io, p]
# TODO (bev) restore when bkcharts package is ready (but remove at 1.0 release)
# import bkcharts as c
# mods.append(c)
for mod in mods:
for f in old_io:
setattr(mod, f, old_io[f])
import bokeh.document as d
d.Document = old_doc
@property
def failed(self):
return self._runner.failed
@property
def error(self):
return self._runner.error
@property
def error_detail(self):
return self._runner.error_detail
| gpl-2.0 | [
646,
984,
199,
199,
504,
2508,
3578,
14,
5586,
14,
600,
63,
5933,
492,
5495,
7446,
199,
504,
2508,
3578,
14,
5586,
14,
2232,
492,
18599,
199,
504,
2508,
2308,
492,
663,
63,
895,
1301,
12,
1094,
1301,
199,
199,
533,
5679,
2461,
8,
2461,
304,
272,
408,
437,
14489,
13,
2110,
3016,
8545,
370,
5495,
2461,
1325,
626,
1630,
272,
2005,
5827,
17309,
316,
370,
339,
408,
339,
485,
1199,
63,
9204,
275,
788,
1199,
63,
19174,
297,
283,
1199,
63,
493,
297,
283,
3958,
63,
1199,
418,
272,
485,
2308,
63,
9204,
275,
788,
2384,
297,
283,
2117,
418,
339,
347,
636,
826,
721,
277,
12,
1350,
12,
1788,
304,
267,
1613,
8,
9846,
2461,
12,
291,
2843,
826,
721,
277,
9,
267,
291,
423,
5933,
275,
5495,
7446,
8,
1365,
12,
1788,
12,
3073,
339,
347,
2811,
63,
3554,
8,
277,
12,
1382,
304,
267,
340,
291,
14,
4892,
26,
288,
372,
398,
859,
275,
291,
423,
5933,
14,
1222,
63,
578,
342,
398,
984,
14,
3112,
59,
578,
855,
354,
22705,
275,
859,
267,
1382,
423,
3112,
14,
740,
8,
578,
9,
398,
2269,
63,
1301,
275,
1094,
1301,
342,
267,
663,
63,
895,
1301,
8,
1301,
9,
398,
2269,
63,
2308,
12,
2269,
63,
1301,
275,
291,
423,
20372,
2068,
342,
398,
862,
26,
288,
291,
423,
5933,
14,
1065,
8,
578,
12,
2400,
26,
488,
9,
267,
3753,
26,
288,
291,
423,
324,
20372,
2068,
8,
1753,
63,
2308,
12,
2269,
63,
1301,
9,
288,
663,
63,
895,
1301,
8,
1753,
63,
1301,
9,
339,
347,
485,
20372,
2068,
8,
277,
304,
398,
347,
485,
1529,
2031,
589,
12,
1011,
829,
304,
986,
267,
347,
485,
525,
63,
1231,
8,
1113,
12,
627,
589,
12,
1011,
829,
304,
288,
687,
25214,
14,
2308,
492,
1094,
1301,
288,
1094,
1301,
1252,
525,
63,
1231,
8,
1113,
9,
267,
347,
485,
895,
1301,
2031,
589,
12,
1011,
829,
304,
288,
372,
1094,
1301,
342,
398,
327,
3520,
3423,
787,
7115,
338,
9462,
8439,
687,
5890,
1901,
25174,
12,
267,
327,
880,
781,
1172,
370,
3371,
3062,
1006,
14,
10829,
15052,
365,
626,
949,
1163,
3371,
316,
267,
327,
965,
8920,
12,
284,
14,
69,
14,
781,
883,
2951,
3354,
314,
18805,
3769,
19483,
5403,
12,
267,
327,
687,
5890,
12,
436,
675,
5204,
465,
314,
3379,
83,
370,
3350,
4036,
4509,
267,
492,
25214,
14,
2308,
465,
5890,
267,
492,
25214,
14,
2798,
1337,
465,
299,
267,
24496,
275,
359,
2308,
12,
299,
61,
398,
327,
3254,
334,
1235,
86,
9,
9066,
1380,
330,
75,
31522,
2559,
365,
10144,
334,
7911,
2813,
737,
413,
14,
16,
4683,
9,
267,
327,
492,
330,
75,
31522,
465,
286,
267,
327,
24496,
14,
740,
8,
67,
9,
398,
2269,
63,
2308,
275,
1052,
267,
367,
289,
315,
291,
423,
1199,
63,
9204,
435,
291,
423,
2308,
63,
9204,
26,
288,
2269,
63,
2308,
59,
70,
61,
275,
2519,
8,
2308,
12,
289,
9,
398,
367,
3413,
315,
24496,
26,
288,
367,
289,
315,
291,
423,
1199,
63,
9204,
26,
355,
5371,
8,
1494,
12,
289,
12,
485,
1529,
9,
288,
367,
289,
315,
291,
423,
2308,
63,
9204,
26,
355,
5371,
8,
1494,
12,
289,
12,
485,
525,
63,
1231,
9,
398,
492,
25214,
14,
3554,
465,
366,
267,
2269,
63,
1301,
275,
366,
14,
5564,
267,
366,
14,
5564,
275,
485,
895,
1301,
398,
372,
2269,
63,
2308,
12,
2269,
63,
1301,
339,
347,
485,
324,
20372,
2068,
8,
277,
12,
2269,
63,
2308,
12,
2269,
63,
1301,
304,
267,
492,
25214,
14,
2308,
465,
5890,
267,
492,
25214,
14,
2798,
1337,
465,
299,
267,
24496,
275,
359,
2308,
12,
299,
61,
398,
327,
3254,
334,
1235,
86,
9,
9066,
1380,
330,
75,
31522,
2559,
365,
10144,
334,
7911,
2813,
737,
413,
14,
16,
4683,
9,
267,
327,
492,
330,
75,
31522,
465,
286,
267,
327,
24496,
14,
740,
8,
67,
9,
398,
367,
3413,
315,
24496,
26,
288,
367,
289,
315,
2269,
63,
2308,
26,
355,
5371,
8,
1494,
12,
289,
12,
2269,
63,
2308,
59,
70,
566,
398,
492,
25214,
14,
3554,
465,
366,
267,
366,
14,
5564,
275,
2269,
63,
1301,
339,
768,
1829,
272,
347,
3405,
8,
277,
304,
267,
372,
291,
423,
5933,
14,
4892,
339,
768,
1829,
272,
347,
1125,
8,
277,
304,
267,
372,
291,
423,
5933,
14,
705,
339,
768,
1829,
272,
347,
1125,
63,
5506,
8,
277,
304,
267,
372,
291,
423,
5933,
14,
705,
63,
5506,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
984,
199,
199,
504,
2508,
3578,
14,
5586,
14,
600,
63,
5933,
492,
5495,
7446,
199,
504,
2508,
3578,
14,
5586,
14,
2232,
492,
18599,
199,
504,
2508,
2308,
492,
663,
63,
895,
1301,
12,
1094,
1301,
199,
199,
533,
5679,
2461,
8,
2461,
304,
272,
408,
437,
14489,
13,
2110,
3016,
8545,
370,
5495,
2461,
1325,
626,
1630,
272,
2005,
5827,
17309,
316,
370,
339,
408,
339,
485,
1199,
63,
9204,
275,
788,
1199,
63,
19174,
297,
283,
1199,
63,
493,
297,
283,
3958,
63,
1199,
418,
272,
485,
2308,
63,
9204,
275,
788,
2384,
297,
283,
2117,
418,
339,
347,
636,
826,
721,
277,
12,
1350,
12,
1788,
304,
267,
1613,
8,
9846,
2461,
12,
291,
2843,
826,
721,
277,
9,
267,
291,
423,
5933,
275,
5495,
7446,
8,
1365,
12,
1788,
12,
3073,
339,
347,
2811,
63,
3554,
8,
277,
12,
1382,
304,
267,
340,
291,
14,
4892,
26,
288,
372,
398,
859,
275,
291,
423,
5933,
14,
1222,
63,
578,
342,
398,
984,
14,
3112,
59,
578,
855,
354,
22705,
275,
859,
267,
1382,
423,
3112,
14,
740,
8,
578,
9,
398,
2269,
63,
1301,
275,
1094,
1301,
342,
267,
663,
63,
895,
1301,
8,
1301,
9,
398,
2269,
63,
2308,
12,
2269,
63,
1301,
275,
291,
423,
20372,
2068,
342,
398,
862,
26,
288,
291,
423,
5933,
14,
1065,
8,
578,
12,
2400,
26,
488,
9,
267,
3753,
26,
288,
291,
423,
324,
20372,
2068,
8,
1753,
63,
2308,
12,
2269,
63,
1301,
9,
288,
663,
63,
895,
1301,
8,
1753,
63,
1301,
9,
339,
347,
485,
20372,
2068,
8,
277,
304,
398,
347,
485,
1529,
2031,
589,
12,
1011,
829,
304,
986,
267,
347,
485,
525,
63,
1231,
8,
1113,
12,
627,
589,
12,
1011,
829,
304,
288,
687,
25214,
14,
2308,
492,
1094,
1301,
288,
1094,
1301,
1252,
525,
63,
1231,
8,
1113,
9,
267,
347,
485,
895,
1301,
2031,
589,
12,
1011,
829,
304,
288,
372,
1094,
1301,
342,
398,
327,
3520,
3423,
787,
7115,
338,
9462,
8439,
687,
5890,
1901,
25174,
12,
267,
327,
880,
781,
1172,
370,
3371,
3062,
1006,
14,
10829,
15052,
365,
626,
949,
1163,
3371,
316,
267,
327,
965,
8920,
12,
284,
14,
69,
14,
781,
883,
2951,
3354,
314,
18805,
3769,
19483,
5403,
12,
267,
327,
687,
5890,
12,
436,
675,
5204,
465,
314,
3379,
83,
370,
3350,
4036,
4509,
267,
492,
25214,
14,
2308,
465,
5890,
267,
492,
25214,
14,
2798,
1337,
465,
299,
267,
24496,
275,
359,
2308,
12,
299,
61,
398,
327,
3254,
334,
1235,
86,
9,
9066,
1380,
330,
75,
31522,
2559,
365,
10144,
334,
7911,
2813,
737,
413,
14,
16,
4683,
9,
267,
327,
492,
330,
75,
31522,
465,
286,
267,
327,
24496,
14,
740,
8,
67,
9,
398,
2269,
63,
2308,
275,
1052,
267,
367,
289,
315,
291,
423,
1199,
63,
9204,
435,
291,
423,
2308,
63,
9204,
26,
288,
2269,
63,
2308,
59,
70,
61,
275,
2519,
8,
2308,
12,
289,
9,
398,
367,
3413,
315,
24496,
26,
288,
367,
289,
315,
291,
423,
1199,
63,
9204,
26,
355,
5371,
8,
1494,
12,
289,
12,
485,
1529,
9,
288,
367,
289,
315,
291,
423,
2308,
63,
9204,
26,
355,
5371,
8,
1494,
12,
289,
12,
485,
525,
63,
1231,
9,
398,
492,
25214,
14,
3554,
465,
366,
267,
2269,
63,
1301,
275,
366,
14,
5564,
267,
366,
14,
5564,
275,
485,
895,
1301,
398,
372,
2269,
63,
2308,
12,
2269,
63,
1301,
339,
347,
485,
324,
20372,
2068,
8,
277,
12,
2269,
63,
2308,
12,
2269,
63,
1301,
304,
267,
492,
25214,
14,
2308,
465,
5890,
267,
492,
25214,
14,
2798,
1337,
465,
299,
267,
24496,
275,
359,
2308,
12,
299,
61,
398,
327,
3254,
334,
1235,
86,
9,
9066,
1380,
330,
75,
31522,
2559,
365,
10144,
334,
7911,
2813,
737,
413,
14,
16,
4683,
9,
267,
327,
492,
330,
75,
31522,
465,
286,
267,
327,
24496,
14,
740,
8,
67,
9,
398,
367,
3413,
315,
24496,
26,
288,
367,
289,
315,
2269,
63,
2308,
26,
355,
5371,
8,
1494,
12,
289,
12,
2269,
63,
2308,
59,
70,
566,
398,
492,
25214,
14,
3554,
465,
366,
267,
366,
14,
5564,
275,
2269,
63,
1301,
339,
768,
1829,
272,
347,
3405,
8,
277,
304,
267,
372,
291,
423,
5933,
14,
4892,
339,
768,
1829,
272,
347,
1125,
8,
277,
304,
267,
372,
291,
423,
5933,
14,
705,
339,
768,
1829,
272,
347,
1125,
63,
5506,
8,
277,
304,
267,
372,
291,
423,
5933,
14,
705,
63,
5506,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
BurningNetel/ctf-manager | CTFmanager/tests/views/event/test_event.py | 1 | 6138 | import json
from django.core.urlresolvers import reverse
from CTFmanager.tests.views.base import ViewTestCase
class EventPageAJAXJoinEventTest(ViewTestCase):
""" Tests that a user can join an event
A user should be able to join upcoming events.
And get a response without the page reloading
"""
def get_valid_event_join_post(self):
event = self.create_event()
response = self.client.post(reverse('event_join', args=[event.name]))
_json = json.loads(response.content.decode())
return _json, event
def test_POST_returns_expected_json_on_valid_post(self):
_json, event = self.get_valid_event_join_post()
self.assertEqual(200, _json['status_code'])
def test_POST_gives_correct_user_count(self):
_json, event = self.get_valid_event_join_post()
self.assertEqual(1, _json['members'])
def test_logout_POST_gives_401_and_negative(self):
self.client.logout()
_json, event = self.get_valid_event_join_post()
self.assertEqual(-1, _json['members'])
self.assertEqual(401, _json['status_code'])
def test_duplicate_POST_gives_304_and_negative(self):
_json, event = self.get_valid_event_join_post()
response = self.client.post(reverse('event_join', args=[event.name]))
_json = json.loads(response.content.decode())
self.assertEqual(-1, _json['members'])
self.assertEqual(304, _json['status_code'])
def test_valid_DELETE_gives_valid_json(self):
event = self.create_event_join_user()
response = self.client.delete(reverse('event_join', args=[event.name]))
_json = json.loads(response.content.decode())
self.assertEqual(200, _json['status_code'])
self.assertEqual(0, _json['members'])
def test_duplicate_DELETE_gives_304_and_negative(self):
event = self.create_event_join_user()
self.client.delete(reverse('event_join', args=[event.name]))
response = self.client.delete(reverse('event_join', args=[event.name]))
_json = json.loads(response.content.decode())
self.assertEqual(304, _json['status_code'])
self.assertEqual(-1, _json['members'])
def test_logout_then_DELTE_gives_401_and_negative(self):
event = self.create_event_join_user()
self.client.logout()
response = self.client.delete(reverse('event_join', args=[event.name]))
_json = json.loads(response.content.decode())
self.assertEqual(401, _json['status_code'])
self.assertEqual(-1, _json['members'])
def create_event_join_user(self):
event = self.create_event()
event.join(self.user)
return event
class EventPageTest(ViewTestCase):
def test_events_page_requires_authentication(self):
self.client.logout()
response = self.client.get(reverse('events'))
self.assertRedirects(response, reverse('login') + '?next=' + reverse('events'))
def test_events_page_renders_events_template(self):
response = self.client.get(reverse('events'))
self.assertTemplateUsed(response, 'event/events.html')
def test_events_page_contains_new_event_button(self):
response = self.client.get(reverse('events'))
expected = 'id="btn_add_event" href="/events/new/">Add Event</a>'
self.assertContains(response, expected)
def test_events_page_displays_only_upcoming_events(self):
event_future = self.create_event("hatCTF", True)
event_past = self.create_event("RuCTF_2015", False)
response = self.client.get(reverse('events'))
_event = response.context['events']
self.assertEqual(_event[0], event_future)
self.assertEqual(len(_event), 1)
self.assertNotEqual(_event[0], event_past)
def test_events_page_has_correct_headers(self):
response = self.client.get(reverse('events'))
expected = 'Upcoming Events'
expected2 = 'Archive'
self.assertContains(response, expected)
self.assertContains(response, expected2)
def test_empty_events_set_shows_correct_message(self):
response = self.client.get(reverse('events'))
expected = 'No upcoming events!'
self.assertContains(response, expected)
def test_events_page_display_archive(self):
event_past = self.create_event('past_event', False)
response = self.client.get(reverse('events'))
archive = response.context['archive']
self.assertContains(response, '<table id="table_archive"')
self.assertContains(response, event_past.name)
self.assertEqual(archive[0], event_past)
def test_events_page_displays_error_message_when_nothing_in_archive(self):
response = self.client.get(reverse('events'))
archive = response.context['archive']
self.assertEqual(len(archive), 0)
self.assertContains(response, 'No past events!')
def test_event_page_displays_event_members_count(self):
event = self.create_event()
response = self.client.get(reverse('events'))
self.assertContains(response, '0 Participating')
event.members.add(self.user)
event.save()
response = self.client.get(reverse('events'))
self.assertContains(response, '1 Participating')
def test_event_page_displays_correct_button_text(self):
event = self.create_event()
response = self.client.get(reverse('events'))
self.assertContains(response, 'Join</button>')
event.join(self.user)
response = self.client.get(reverse('events'))
self.assertContains(response, 'Leave</button>')
def test_event_page_shows_username_in_popup(self):
event = self.create_event()
response = self.client.get(reverse('events'))
self.assertContains(response, self.user.username, 1)
self.assertContains(response, 'Nobody has joined yet!')
event.join(self.user)
response = self.client.get(reverse('events'))
self.assertContains(response, self.user.username, 2)
self.assertNotContains(response, 'Nobody has joined yet!') | gpl-3.0 | [
646,
2022,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
199,
504,
445,
6145,
2609,
14,
2219,
14,
4196,
14,
1095,
492,
10935,
1746,
421,
199,
533,
6763,
3276,
31064,
9839,
13005,
2390,
774,
8,
2768,
1746,
304,
272,
408,
6496,
626,
282,
922,
883,
4263,
376,
1566,
272,
437,
922,
1077,
506,
7688,
370,
4263,
1536,
7909,
4474,
14,
272,
6061,
664,
282,
1177,
1928,
314,
2034,
295,
8786,
272,
408,
339,
347,
664,
63,
1078,
63,
1430,
63,
904,
63,
1932,
8,
277,
304,
267,
1566,
275,
291,
14,
981,
63,
1430,
342,
267,
1177,
275,
291,
14,
1258,
14,
1932,
8,
4471,
360,
1430,
63,
904,
297,
1249,
1524,
1430,
14,
354,
2459,
267,
485,
1001,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
14,
2708,
1012,
267,
372,
485,
1001,
12,
1566,
339,
347,
511,
63,
4030,
63,
5808,
63,
2062,
63,
1001,
63,
265,
63,
1078,
63,
1932,
8,
277,
304,
267,
485,
1001,
12,
1566,
275,
291,
14,
362,
63,
1078,
63,
1430,
63,
904,
63,
1932,
342,
267,
291,
14,
629,
8,
1840,
12,
485,
1001,
459,
1205,
63,
600,
1105,
339,
347,
511,
63,
4030,
63,
71,
7602,
63,
4525,
63,
751,
63,
835,
8,
277,
304,
267,
485,
1001,
12,
1566,
275,
291,
14,
362,
63,
1078,
63,
1430,
63,
904,
63,
1932,
342,
398,
291,
14,
629,
8,
17,
12,
485,
1001,
459,
6334,
1105,
339,
347,
511,
63,
11646,
63,
4030,
63,
71,
7602,
63,
8854,
63,
460,
63,
7371,
8,
277,
304,
267,
291,
14,
1258,
14,
11646,
342,
267,
485,
1001,
12,
1566,
275,
291,
14,
362,
63,
1078,
63,
1430,
63,
904,
63,
1932,
342,
398,
291,
14,
629,
2801,
17,
12,
485,
1001,
459,
6334,
1105,
267,
291,
14,
629,
8,
8854,
12,
485,
1001,
459,
1205,
63,
600,
1105,
339,
347,
511,
63,
11081,
63,
4030,
63,
71,
7602,
63,
8533,
63,
460,
63,
7371,
8,
277,
304,
267,
485,
1001,
12,
1566,
275,
291,
14,
362,
63,
1078,
63,
1430,
63,
904,
63,
1932,
342,
267,
1177,
275,
291,
14,
1258,
14,
1932,
8,
4471,
360,
1430,
63,
904,
297,
1249,
1524,
1430,
14,
354,
2459,
267,
485,
1001,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
14,
2708,
1012,
398,
291,
14,
629,
2801,
17,
12,
485,
1001,
459,
6334,
1105,
267,
291,
14,
629,
8,
8533,
12,
485,
1001,
459,
1205,
63,
600,
1105,
339,
347,
511,
63,
1078,
63,
7014,
63,
71,
7602,
63,
1078,
63,
1001,
8,
277,
304,
267,
1566,
275,
291,
14,
981,
63,
1430,
63,
904,
63,
751,
342,
267,
1177,
275,
291,
14,
1258,
14,
1807,
8,
4471,
360,
1430,
63,
904,
297,
1249,
1524,
1430,
14,
354,
2459,
267,
485,
1001,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
14,
2708,
1012,
398,
291,
14,
629,
8,
1840,
12,
485,
1001,
459,
1205,
63,
600,
1105,
267,
291,
14,
629,
8,
16,
12,
485,
1001,
459,
6334,
1105,
339,
347,
511,
63,
11081,
63,
7014,
63,
71,
7602,
63,
8533,
63,
460,
63,
7371,
8,
277,
304,
267,
1566,
275,
291,
14,
981,
63,
1430,
63,
904,
63,
751,
342,
267,
291,
14,
1258,
14,
1807,
8,
4471,
360,
1430,
63,
904,
297,
1249,
1524,
1430,
14,
354,
2459,
267,
1177,
275,
291,
14,
1258,
14,
1807,
8,
4471,
360,
1430,
63,
904,
297,
1249,
1524,
1430,
14,
354,
2459,
267,
485,
1001,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
14,
2708,
1012,
398,
291,
14,
629,
8,
8533,
12,
485,
1001,
459,
1205,
63,
600,
1105,
267,
291,
14,
629,
2801,
17,
12,
485,
1001,
459,
6334,
1105,
339,
347,
511,
63,
11646,
63,
12726,
63,
4424,
3727,
63,
71,
7602,
63,
8854,
63,
460,
63,
7371,
8,
277,
304,
267,
1566,
275,
291,
14,
981,
63,
1430,
63,
904,
63,
751,
342,
267,
291,
14,
1258,
14,
11646,
342,
267,
1177,
275,
291,
14,
1258,
14,
1807,
8,
4471,
360,
1430,
63,
904,
297,
1249,
1524,
1430,
14,
354,
2459,
267,
485,
1001,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
14,
2708,
1012,
398,
291,
14,
629,
8,
8854,
12,
485,
1001,
459,
1205,
63,
600,
1105,
267,
291,
14,
629,
2801,
17,
12,
485,
1001,
459,
6334,
1105,
339,
347,
1218,
63,
1430,
63,
904,
63,
751,
8,
277,
304,
267,
1566,
275,
291,
14,
981,
63,
1430,
342,
267,
1566,
14,
904,
8,
277,
14,
751,
9,
267,
372,
1566,
421,
199,
533,
6763,
3276,
774,
8,
2768,
1746,
304,
272,
347,
511,
63,
4368,
63,
1606,
63,
6537,
63,
11725,
8,
277,
304,
267,
291,
14,
1258,
14,
11646,
342,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
4471,
360,
4368,
1333,
267,
291,
14,
17466,
8,
1310,
12,
3837,
360,
2886,
358,
435,
8720,
2184,
534,
435,
3837,
360,
4368,
1333,
339,
347,
511,
63,
4368,
63,
1606,
63,
3352,
83,
63,
4368,
63,
1160,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
4471,
360,
4368,
1333,
267,
291,
14,
19661,
8,
1310,
12,
283,
1430,
15,
4368,
14,
1360,
358,
339,
347,
511,
63,
4368,
63,
1606,
63,
6134,
63,
1222,
63,
1430,
63,
3887,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
4471,
360,
4368,
1333,
267,
1420,
275,
283,
344,
628,
9633,
63,
525,
63,
1430,
2,
4369,
9555,
4368,
15,
1222,
26049,
1123,
6763,
1108,
65,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
9,
339,
347,
511,
63,
4368,
63,
1606,
63,
13654,
9316,
63,
2118,
63,
384,
7909,
63,
4368,
8,
277,
304,
267,
1566,
63,
2443,
275,
291,
14,
981,
63,
1430,
480,
8554,
1028,
38,
401,
715,
9,
267,
1566,
63,
18597,
275,
291,
14,
981,
63,
1430,
480,
50,
85,
1028,
38,
63,
7806,
401,
756,
9,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
4471,
360,
4368,
1333,
267,
485,
1430,
275,
1177,
14,
1100,
459,
4368,
418,
267,
291,
14,
629,
1547,
1430,
59,
16,
467,
1566,
63,
2443,
9,
267,
291,
14,
629,
8,
552,
1547,
1430,
395,
413,
9,
267,
291,
14,
7418
] | [
2022,
199,
199,
504,
1639,
14,
1018,
14,
16522,
492,
3837,
199,
199,
504,
445,
6145,
2609,
14,
2219,
14,
4196,
14,
1095,
492,
10935,
1746,
421,
199,
533,
6763,
3276,
31064,
9839,
13005,
2390,
774,
8,
2768,
1746,
304,
272,
408,
6496,
626,
282,
922,
883,
4263,
376,
1566,
272,
437,
922,
1077,
506,
7688,
370,
4263,
1536,
7909,
4474,
14,
272,
6061,
664,
282,
1177,
1928,
314,
2034,
295,
8786,
272,
408,
339,
347,
664,
63,
1078,
63,
1430,
63,
904,
63,
1932,
8,
277,
304,
267,
1566,
275,
291,
14,
981,
63,
1430,
342,
267,
1177,
275,
291,
14,
1258,
14,
1932,
8,
4471,
360,
1430,
63,
904,
297,
1249,
1524,
1430,
14,
354,
2459,
267,
485,
1001,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
14,
2708,
1012,
267,
372,
485,
1001,
12,
1566,
339,
347,
511,
63,
4030,
63,
5808,
63,
2062,
63,
1001,
63,
265,
63,
1078,
63,
1932,
8,
277,
304,
267,
485,
1001,
12,
1566,
275,
291,
14,
362,
63,
1078,
63,
1430,
63,
904,
63,
1932,
342,
267,
291,
14,
629,
8,
1840,
12,
485,
1001,
459,
1205,
63,
600,
1105,
339,
347,
511,
63,
4030,
63,
71,
7602,
63,
4525,
63,
751,
63,
835,
8,
277,
304,
267,
485,
1001,
12,
1566,
275,
291,
14,
362,
63,
1078,
63,
1430,
63,
904,
63,
1932,
342,
398,
291,
14,
629,
8,
17,
12,
485,
1001,
459,
6334,
1105,
339,
347,
511,
63,
11646,
63,
4030,
63,
71,
7602,
63,
8854,
63,
460,
63,
7371,
8,
277,
304,
267,
291,
14,
1258,
14,
11646,
342,
267,
485,
1001,
12,
1566,
275,
291,
14,
362,
63,
1078,
63,
1430,
63,
904,
63,
1932,
342,
398,
291,
14,
629,
2801,
17,
12,
485,
1001,
459,
6334,
1105,
267,
291,
14,
629,
8,
8854,
12,
485,
1001,
459,
1205,
63,
600,
1105,
339,
347,
511,
63,
11081,
63,
4030,
63,
71,
7602,
63,
8533,
63,
460,
63,
7371,
8,
277,
304,
267,
485,
1001,
12,
1566,
275,
291,
14,
362,
63,
1078,
63,
1430,
63,
904,
63,
1932,
342,
267,
1177,
275,
291,
14,
1258,
14,
1932,
8,
4471,
360,
1430,
63,
904,
297,
1249,
1524,
1430,
14,
354,
2459,
267,
485,
1001,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
14,
2708,
1012,
398,
291,
14,
629,
2801,
17,
12,
485,
1001,
459,
6334,
1105,
267,
291,
14,
629,
8,
8533,
12,
485,
1001,
459,
1205,
63,
600,
1105,
339,
347,
511,
63,
1078,
63,
7014,
63,
71,
7602,
63,
1078,
63,
1001,
8,
277,
304,
267,
1566,
275,
291,
14,
981,
63,
1430,
63,
904,
63,
751,
342,
267,
1177,
275,
291,
14,
1258,
14,
1807,
8,
4471,
360,
1430,
63,
904,
297,
1249,
1524,
1430,
14,
354,
2459,
267,
485,
1001,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
14,
2708,
1012,
398,
291,
14,
629,
8,
1840,
12,
485,
1001,
459,
1205,
63,
600,
1105,
267,
291,
14,
629,
8,
16,
12,
485,
1001,
459,
6334,
1105,
339,
347,
511,
63,
11081,
63,
7014,
63,
71,
7602,
63,
8533,
63,
460,
63,
7371,
8,
277,
304,
267,
1566,
275,
291,
14,
981,
63,
1430,
63,
904,
63,
751,
342,
267,
291,
14,
1258,
14,
1807,
8,
4471,
360,
1430,
63,
904,
297,
1249,
1524,
1430,
14,
354,
2459,
267,
1177,
275,
291,
14,
1258,
14,
1807,
8,
4471,
360,
1430,
63,
904,
297,
1249,
1524,
1430,
14,
354,
2459,
267,
485,
1001,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
14,
2708,
1012,
398,
291,
14,
629,
8,
8533,
12,
485,
1001,
459,
1205,
63,
600,
1105,
267,
291,
14,
629,
2801,
17,
12,
485,
1001,
459,
6334,
1105,
339,
347,
511,
63,
11646,
63,
12726,
63,
4424,
3727,
63,
71,
7602,
63,
8854,
63,
460,
63,
7371,
8,
277,
304,
267,
1566,
275,
291,
14,
981,
63,
1430,
63,
904,
63,
751,
342,
267,
291,
14,
1258,
14,
11646,
342,
267,
1177,
275,
291,
14,
1258,
14,
1807,
8,
4471,
360,
1430,
63,
904,
297,
1249,
1524,
1430,
14,
354,
2459,
267,
485,
1001,
275,
2022,
14,
3640,
8,
1310,
14,
1317,
14,
2708,
1012,
398,
291,
14,
629,
8,
8854,
12,
485,
1001,
459,
1205,
63,
600,
1105,
267,
291,
14,
629,
2801,
17,
12,
485,
1001,
459,
6334,
1105,
339,
347,
1218,
63,
1430,
63,
904,
63,
751,
8,
277,
304,
267,
1566,
275,
291,
14,
981,
63,
1430,
342,
267,
1566,
14,
904,
8,
277,
14,
751,
9,
267,
372,
1566,
421,
199,
533,
6763,
3276,
774,
8,
2768,
1746,
304,
272,
347,
511,
63,
4368,
63,
1606,
63,
6537,
63,
11725,
8,
277,
304,
267,
291,
14,
1258,
14,
11646,
342,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
4471,
360,
4368,
1333,
267,
291,
14,
17466,
8,
1310,
12,
3837,
360,
2886,
358,
435,
8720,
2184,
534,
435,
3837,
360,
4368,
1333,
339,
347,
511,
63,
4368,
63,
1606,
63,
3352,
83,
63,
4368,
63,
1160,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
4471,
360,
4368,
1333,
267,
291,
14,
19661,
8,
1310,
12,
283,
1430,
15,
4368,
14,
1360,
358,
339,
347,
511,
63,
4368,
63,
1606,
63,
6134,
63,
1222,
63,
1430,
63,
3887,
8,
277,
304,
267,
1177,
275,
291,
14,
1258,
14,
362,
8,
4471,
360,
4368,
1333,
267,
1420,
275,
283,
344,
628,
9633,
63,
525,
63,
1430,
2,
4369,
9555,
4368,
15,
1222,
26049,
1123,
6763,
1108,
65,
3524,
267,
291,
14,
9535,
8,
1310,
12,
1420,
9,
339,
347,
511,
63,
4368,
63,
1606,
63,
13654,
9316,
63,
2118,
63,
384,
7909,
63,
4368,
8,
277,
304,
267,
1566,
63,
2443,
275,
291,
14,
981,
63,
1430,
480,
8554,
1028,
38,
401,
715,
9,
267,
1566,
63,
18597,
275,
291,
14,
981,
63,
1430,
480,
50,
85,
1028,
38,
63,
7806,
401,
756,
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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
] |
crchemist/scioncc | src/pyon/core/test/test_thread.py | 2 | 3210 | #!/usr/bin/env python
__author__ = 'Adam R. Smith'
from pyon.core.thread import PyonThreadManager, PyonThread
from pyon.core.exception import ContainerError
from pyon.util.int_test import IonIntegrationTestCase
from pyon.util.unit_test import PyonTestCase
from unittest import SkipTest
from nose.plugins.attrib import attr
import time
@attr('UNIT', group='process')
class ProcessTest(PyonTestCase):
def setUp(self):
self.counter = 0
def increment(self, amount=1):
self.counter += amount
def test_proc(self):
self.counter = 0
proc = PyonThread(self.increment, 2)
proc.start()
self.assertEqual(self.counter, 0)
time.sleep(0.2)
proc.join()
self.assertGreaterEqual(self.counter, 2)
def test_supervisor(self):
self.counter = 0
sup = PyonThreadManager()
sup.start()
proc = sup.spawn(self.increment, amount=2)
self.assertEqual(self.counter, 0)
time.sleep(0.2)
sup.join_children()
self.assertGreaterEqual(self.counter, 2)
def test_supervisor_shutdown(self):
""" Test shutdown joining/forcing with timeouts. """
sup = PyonThreadManager()
sup.start()
import gevent
#Note: commented MM 7/2015. time.sleep seems not monkey-patched on Ubuntu?
#self.assertIs(time.sleep, gevent.hub.sleep)
# Test that it takes at least the given timeout to join_children, but not much more
proc_sleep_secs, proc_count = 0.01, 5
[sup.spawn(time.sleep, seconds=proc_sleep_secs) for i in xrange(5)]
elapsed = sup.shutdown(2*proc_sleep_secs)
# MM, 1/12: Ok, I loosened the timing boundaries. Do the tests still work?
# Enabled 0.2s of slack for all tests
self.assertLess(elapsed - proc_sleep_secs, 0.2)
# this could be trouble
self.assertLess(elapsed, 0.2 + proc_sleep_secs*3)
# Test that a small timeout forcibly shuts down without waiting
wait_secs = 0.0001
[sup.spawn(time.sleep, seconds=proc_sleep_secs) for i in xrange(5)]
elapsed = sup.shutdown(wait_secs)
self.assertLess(elapsed - wait_secs, 0.2)
# this could be trouble too
self.assertLess(elapsed, 0.2 + proc_sleep_secs)
# Test that no timeout waits until all finished
[sup.spawn(time.sleep, seconds=proc_sleep_secs) for i in xrange(5)]
elapsed = sup.shutdown()
self.assertLess(elapsed - proc_sleep_secs, 0.2)
def test_ensure_ready(self):
# GreenProcess by default will signal ready immediately, but we can still pass it through to make sure it's ok
sup = PyonThreadManager()
sup.start()
proc = sup.spawn(self.increment, amount=5)
sup.ensure_ready(proc)
self.assertEqual(self.counter, 5)
def test_ensure_ready_failed_proc(self):
# yes the error we print is intentional and annoying, sorry
def failboat():
self.increment(5, 1) # too many params, will fail
sup = PyonThreadManager()
sup.start()
proc = sup.spawn(failboat)
self.assertRaises(ContainerError, sup.ensure_ready, proc)
| bsd-2-clause | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
363,
2502,
363,
275,
283,
32408,
820,
14,
25924,
7,
421,
199,
504,
1134,
265,
14,
1018,
14,
2671,
492,
1611,
265,
4436,
2988,
12,
1611,
265,
4436,
199,
504,
1134,
265,
14,
1018,
14,
1971,
492,
15395,
547,
199,
504,
1134,
265,
14,
1974,
14,
442,
63,
396,
492,
473,
265,
20405,
1746,
199,
504,
1134,
265,
14,
1974,
14,
3248,
63,
396,
492,
1611,
265,
1746,
199,
504,
2882,
492,
18795,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
199,
646,
900,
199,
199,
32,
962,
360,
15505,
297,
1572,
534,
1412,
358,
199,
533,
7132,
774,
8,
2713,
265,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
339,
347,
11609,
8,
277,
12,
5982,
29,
17,
304,
267,
291,
14,
5337,
847,
5982,
339,
347,
511,
63,
4687,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
267,
6499,
275,
1611,
265,
4436,
8,
277,
14,
9728,
12,
499,
9,
267,
6499,
14,
928,
342,
267,
291,
14,
629,
8,
277,
14,
5337,
12,
378,
9,
267,
900,
14,
4532,
8,
16,
14,
18,
9,
267,
6499,
14,
904,
342,
267,
291,
14,
26875,
8,
277,
14,
5337,
12,
499,
9,
339,
347,
511,
63,
4792,
8286,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
267,
1029,
275,
1611,
265,
4436,
2988,
342,
267,
1029,
14,
928,
342,
267,
6499,
275,
1029,
14,
10212,
8,
277,
14,
9728,
12,
5982,
29,
18,
9,
267,
291,
14,
629,
8,
277,
14,
5337,
12,
378,
9,
267,
900,
14,
4532,
8,
16,
14,
18,
9,
267,
1029,
14,
904,
63,
3223,
342,
267,
291,
14,
26875,
8,
277,
14,
5337,
12,
499,
9,
339,
347,
511,
63,
4792,
8286,
63,
8831,
8,
277,
304,
267,
408,
1379,
12842,
4263,
316,
15,
509,
4477,
543,
25870,
14,
408,
267,
1029,
275,
1611,
265,
4436,
2988,
342,
267,
1029,
14,
928,
342,
398,
492,
23386,
267,
327,
7443,
26,
21804,
603,
45,
1520,
15,
7806,
14,
900,
14,
4532,
12237,
440,
14198,
13,
22631,
641,
31631,
31,
267,
327,
277,
14,
3436,
8,
521,
14,
4532,
12,
23386,
14,
16560,
14,
4532,
9,
398,
327,
1379,
626,
652,
6181,
737,
5210,
314,
1627,
2653,
370,
4263,
63,
3223,
12,
1325,
440,
8298,
1655,
267,
6499,
63,
4532,
63,
4855,
12,
6499,
63,
835,
275,
378,
14,
614,
12,
959,
267,
359,
1961,
14,
10212,
8,
521,
14,
4532,
12,
4696,
29,
4687,
63,
4532,
63,
4855,
9,
367,
284,
315,
4945,
8,
21,
1874,
267,
14439,
275,
1029,
14,
8831,
8,
18,
10,
4687,
63,
4532,
63,
4855,
9,
267,
327,
603,
45,
12,
413,
15,
713,
26,
20049,
12,
473,
560,
79,
2464,
379,
314,
20542,
18135,
14,
4226,
314,
2295,
5139,
1736,
31,
267,
327,
3447,
1909,
378,
14,
18,
83,
402,
29877,
367,
1006,
2295,
398,
291,
14,
15625,
8,
16691,
446,
6499,
63,
4532,
63,
4855,
12,
378,
14,
18,
9,
398,
327,
642,
4293,
506,
29616,
267,
291,
14,
15625,
8,
16691,
12,
378,
14,
18,
435,
6499,
63,
4532,
63,
4855,
10,
19,
9,
398,
327,
1379,
626,
282,
7425,
2653,
367,
559,
66,
590,
1033,
14608,
3224,
1928,
10923,
267,
3618,
63,
4855,
275,
378,
14,
4183,
267,
359,
1961,
14,
10212,
8,
521,
14,
4532,
12,
4696,
29,
4687,
63,
4532,
63,
4855,
9,
367,
284,
315,
4945,
8,
21,
1874,
267,
14439,
275,
1029,
14,
8831,
8,
2573,
63,
4855,
9,
267,
291,
14,
15625,
8,
16691,
446,
3618,
63,
4855,
12,
378,
14,
18,
9,
398,
327,
642,
4293,
506,
29616,
4634,
267,
291,
14,
15625,
8,
16691,
12,
378,
14,
18,
435,
6499,
63,
4532,
63,
4855,
9,
398,
327,
1379,
626,
949,
2653,
14442,
1405,
5133,
1006,
9158,
267,
359,
1961,
14,
10212,
8,
521,
14,
4532,
12,
4696,
29,
4687,
63,
4532,
63,
4855,
9,
367,
284,
315,
4945,
8,
21,
1874,
267,
14439,
275,
1029,
14,
8831,
342,
267,
291,
14,
15625,
8,
16691,
446,
6499,
63,
4532,
63,
4855,
12,
378,
14,
18,
9,
339,
347,
511,
63,
7505,
63,
2179,
8,
277,
304,
267,
327,
32585,
3498,
701,
849,
911,
4673,
10144,
9939,
12,
1325,
781,
883,
5139,
986,
652,
4012,
370,
1852,
3238,
652,
1159,
4112,
267,
1029,
275,
1611,
265,
4436,
2988,
342,
267,
1029,
14,
928,
342,
398,
6499,
275,
1029,
14,
10212,
8,
277,
14,
9728,
12,
5982,
29,
21,
9,
267,
1029,
14,
7505,
63,
2179,
8,
4687,
9,
398,
291,
14,
629,
8,
277,
14,
5337,
12,
959,
9,
339,
347,
511,
63,
7505,
63,
2179,
63,
4892,
63,
4687,
8,
277,
304,
267,
327,
9456,
314,
1125,
781,
870,
365,
25343,
279,
436,
22984,
22440,
12,
308,
21342,
398,
347,
2449,
656,
292,
837,
288,
291,
14,
9728,
8,
21,
12,
413,
9,
259,
327,
4634,
5002,
1862,
12,
911,
2449,
398,
1029,
275,
1611,
265,
4436,
2988,
342,
267,
1029,
14,
928,
342,
398,
6499,
275,
1029,
14,
10212,
8,
1633,
656,
292,
9,
267,
291,
14,
1855,
8,
4076,
547,
12,
1029,
14,
7505,
63,
2179,
12,
6499,
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
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
199,
363,
2502,
363,
275,
283,
32408,
820,
14,
25924,
7,
421,
199,
504,
1134,
265,
14,
1018,
14,
2671,
492,
1611,
265,
4436,
2988,
12,
1611,
265,
4436,
199,
504,
1134,
265,
14,
1018,
14,
1971,
492,
15395,
547,
199,
504,
1134,
265,
14,
1974,
14,
442,
63,
396,
492,
473,
265,
20405,
1746,
199,
504,
1134,
265,
14,
1974,
14,
3248,
63,
396,
492,
1611,
265,
1746,
199,
504,
2882,
492,
18795,
199,
504,
11354,
14,
5265,
14,
6640,
492,
1921,
199,
199,
646,
900,
199,
199,
32,
962,
360,
15505,
297,
1572,
534,
1412,
358,
199,
533,
7132,
774,
8,
2713,
265,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
339,
347,
11609,
8,
277,
12,
5982,
29,
17,
304,
267,
291,
14,
5337,
847,
5982,
339,
347,
511,
63,
4687,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
267,
6499,
275,
1611,
265,
4436,
8,
277,
14,
9728,
12,
499,
9,
267,
6499,
14,
928,
342,
267,
291,
14,
629,
8,
277,
14,
5337,
12,
378,
9,
267,
900,
14,
4532,
8,
16,
14,
18,
9,
267,
6499,
14,
904,
342,
267,
291,
14,
26875,
8,
277,
14,
5337,
12,
499,
9,
339,
347,
511,
63,
4792,
8286,
8,
277,
304,
267,
291,
14,
5337,
275,
378,
267,
1029,
275,
1611,
265,
4436,
2988,
342,
267,
1029,
14,
928,
342,
267,
6499,
275,
1029,
14,
10212,
8,
277,
14,
9728,
12,
5982,
29,
18,
9,
267,
291,
14,
629,
8,
277,
14,
5337,
12,
378,
9,
267,
900,
14,
4532,
8,
16,
14,
18,
9,
267,
1029,
14,
904,
63,
3223,
342,
267,
291,
14,
26875,
8,
277,
14,
5337,
12,
499,
9,
339,
347,
511,
63,
4792,
8286,
63,
8831,
8,
277,
304,
267,
408,
1379,
12842,
4263,
316,
15,
509,
4477,
543,
25870,
14,
408,
267,
1029,
275,
1611,
265,
4436,
2988,
342,
267,
1029,
14,
928,
342,
398,
492,
23386,
267,
327,
7443,
26,
21804,
603,
45,
1520,
15,
7806,
14,
900,
14,
4532,
12237,
440,
14198,
13,
22631,
641,
31631,
31,
267,
327,
277,
14,
3436,
8,
521,
14,
4532,
12,
23386,
14,
16560,
14,
4532,
9,
398,
327,
1379,
626,
652,
6181,
737,
5210,
314,
1627,
2653,
370,
4263,
63,
3223,
12,
1325,
440,
8298,
1655,
267,
6499,
63,
4532,
63,
4855,
12,
6499,
63,
835,
275,
378,
14,
614,
12,
959,
267,
359,
1961,
14,
10212,
8,
521,
14,
4532,
12,
4696,
29,
4687,
63,
4532,
63,
4855,
9,
367,
284,
315,
4945,
8,
21,
1874,
267,
14439,
275,
1029,
14,
8831,
8,
18,
10,
4687,
63,
4532,
63,
4855,
9,
267,
327,
603,
45,
12,
413,
15,
713,
26,
20049,
12,
473,
560,
79,
2464,
379,
314,
20542,
18135,
14,
4226,
314,
2295,
5139,
1736,
31,
267,
327,
3447,
1909,
378,
14,
18,
83,
402,
29877,
367,
1006,
2295,
398,
291,
14,
15625,
8,
16691,
446,
6499,
63,
4532,
63,
4855,
12,
378,
14,
18,
9,
398,
327,
642,
4293,
506,
29616,
267,
291,
14,
15625,
8,
16691,
12,
378,
14,
18,
435,
6499,
63,
4532,
63,
4855,
10,
19,
9,
398,
327,
1379,
626,
282,
7425,
2653,
367,
559,
66,
590,
1033,
14608,
3224,
1928,
10923,
267,
3618,
63,
4855,
275,
378,
14,
4183,
267,
359,
1961,
14,
10212,
8,
521,
14,
4532,
12,
4696,
29,
4687,
63,
4532,
63,
4855,
9,
367,
284,
315,
4945,
8,
21,
1874,
267,
14439,
275,
1029,
14,
8831,
8,
2573,
63,
4855,
9,
267,
291,
14,
15625,
8,
16691,
446,
3618,
63,
4855,
12,
378,
14,
18,
9,
398,
327,
642,
4293,
506,
29616,
4634,
267,
291,
14,
15625,
8,
16691,
12,
378,
14,
18,
435,
6499,
63,
4532,
63,
4855,
9,
398,
327,
1379,
626,
949,
2653,
14442,
1405,
5133,
1006,
9158,
267,
359,
1961,
14,
10212,
8,
521,
14,
4532,
12,
4696,
29,
4687,
63,
4532,
63,
4855,
9,
367,
284,
315,
4945,
8,
21,
1874,
267,
14439,
275,
1029,
14,
8831,
342,
267,
291,
14,
15625,
8,
16691,
446,
6499,
63,
4532,
63,
4855,
12,
378,
14,
18,
9,
339,
347,
511,
63,
7505,
63,
2179,
8,
277,
304,
267,
327,
32585,
3498,
701,
849,
911,
4673,
10144,
9939,
12,
1325,
781,
883,
5139,
986,
652,
4012,
370,
1852,
3238,
652,
1159,
4112,
267,
1029,
275,
1611,
265,
4436,
2988,
342,
267,
1029,
14,
928,
342,
398,
6499,
275,
1029,
14,
10212,
8,
277,
14,
9728,
12,
5982,
29,
21,
9,
267,
1029,
14,
7505,
63,
2179,
8,
4687,
9,
398,
291,
14,
629,
8,
277,
14,
5337,
12,
959,
9,
339,
347,
511,
63,
7505,
63,
2179,
63,
4892,
63,
4687,
8,
277,
304,
267,
327,
9456,
314,
1125,
781,
870,
365,
25343,
279,
436,
22984,
22440,
12,
308,
21342,
398,
347,
2449,
656,
292,
837,
288,
291,
14,
9728,
8,
21,
12,
413,
9,
259,
327,
4634,
5002,
1862,
12,
911,
2449,
398,
1029,
275,
1611,
265,
4436,
2988,
342,
267,
1029,
14,
928,
342,
398,
6499,
275,
1029,
14,
10212,
8,
1633,
656,
292,
9,
267,
291,
14,
1855,
8,
4076,
547,
12,
1029,
14,
7505,
63,
2179,
12,
6499,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sriprasanna/django-1.3.1 | django/utils/unittest/result.py | 570 | 6105 | """Test result object"""
import sys
import traceback
import unittest
from StringIO import StringIO
from django.utils.unittest import util
from django.utils.unittest.compatibility import wraps
__unittest = True
def failfast(method):
@wraps(method)
def inner(self, *args, **kw):
if getattr(self, 'failfast', False):
self.stop()
return method(self, *args, **kw)
return inner
STDOUT_LINE = '\nStdout:\n%s'
STDERR_LINE = '\nStderr:\n%s'
class TestResult(unittest.TestResult):
"""Holder for test result information.
Test results are automatically managed by the TestCase and TestSuite
classes, and do not need to be explicitly manipulated by writers of tests.
Each instance holds the total number of tests run, and collections of
failures and errors that occurred among those test runs. The collections
contain tuples of (testcase, exceptioninfo), where exceptioninfo is the
formatted traceback of the error that occurred.
"""
_previousTestClass = None
_moduleSetUpFailed = False
def __init__(self):
self.failfast = False
self.failures = []
self.errors = []
self.testsRun = 0
self.skipped = []
self.expectedFailures = []
self.unexpectedSuccesses = []
self.shouldStop = False
self.buffer = False
self._stdout_buffer = None
self._stderr_buffer = None
self._original_stdout = sys.stdout
self._original_stderr = sys.stderr
self._mirrorOutput = False
def startTest(self, test):
"Called when the given test is about to be run"
self.testsRun += 1
self._mirrorOutput = False
if self.buffer:
if self._stderr_buffer is None:
self._stderr_buffer = StringIO()
self._stdout_buffer = StringIO()
sys.stdout = self._stdout_buffer
sys.stderr = self._stderr_buffer
def startTestRun(self):
"""Called once before any tests are executed.
See startTest for a method called before each test.
"""
def stopTest(self, test):
"""Called when the given test has been run"""
if self.buffer:
if self._mirrorOutput:
output = sys.stdout.getvalue()
error = sys.stderr.getvalue()
if output:
if not output.endswith('\n'):
output += '\n'
self._original_stdout.write(STDOUT_LINE % output)
if error:
if not error.endswith('\n'):
error += '\n'
self._original_stderr.write(STDERR_LINE % error)
sys.stdout = self._original_stdout
sys.stderr = self._original_stderr
self._stdout_buffer.seek(0)
self._stdout_buffer.truncate()
self._stderr_buffer.seek(0)
self._stderr_buffer.truncate()
self._mirrorOutput = False
def stopTestRun(self):
"""Called once after all tests are executed.
See stopTest for a method called after each test.
"""
@failfast
def addError(self, test, err):
"""Called when an error has occurred. 'err' is a tuple of values as
returned by sys.exc_info().
"""
self.errors.append((test, self._exc_info_to_string(err, test)))
self._mirrorOutput = True
@failfast
def addFailure(self, test, err):
"""Called when an error has occurred. 'err' is a tuple of values as
returned by sys.exc_info()."""
self.failures.append((test, self._exc_info_to_string(err, test)))
self._mirrorOutput = True
def addSuccess(self, test):
"Called when a test has completed successfully"
pass
def addSkip(self, test, reason):
"""Called when a test is skipped."""
self.skipped.append((test, reason))
def addExpectedFailure(self, test, err):
"""Called when an expected failure/error occured."""
self.expectedFailures.append(
(test, self._exc_info_to_string(err, test)))
@failfast
def addUnexpectedSuccess(self, test):
"""Called when a test was expected to fail, but succeed."""
self.unexpectedSuccesses.append(test)
def wasSuccessful(self):
"Tells whether or not this result was a success"
return (len(self.failures) + len(self.errors) == 0)
def stop(self):
"Indicates that the tests should be aborted"
self.shouldStop = True
def _exc_info_to_string(self, err, test):
"""Converts a sys.exc_info()-style tuple of values into a string."""
exctype, value, tb = err
# Skip test runner traceback levels
while tb and self._is_relevant_tb_level(tb):
tb = tb.tb_next
if exctype is test.failureException:
# Skip assert*() traceback levels
length = self._count_relevant_tb_levels(tb)
msgLines = traceback.format_exception(exctype, value, tb, length)
else:
msgLines = traceback.format_exception(exctype, value, tb)
if self.buffer:
output = sys.stdout.getvalue()
error = sys.stderr.getvalue()
if output:
if not output.endswith('\n'):
output += '\n'
msgLines.append(STDOUT_LINE % output)
if error:
if not error.endswith('\n'):
error += '\n'
msgLines.append(STDERR_LINE % error)
return ''.join(msgLines)
def _is_relevant_tb_level(self, tb):
return '__unittest' in tb.tb_frame.f_globals
def _count_relevant_tb_levels(self, tb):
length = 0
while tb and not self._is_relevant_tb_level(tb):
length += 1
tb = tb.tb_next
return length
def __repr__(self):
return "<%s run=%i errors=%i failures=%i>" % \
(util.strclass(self.__class__), self.testsRun, len(self.errors),
len(self.failures))
| bsd-3-clause | [
624,
774,
754,
909,
624,
199,
199,
646,
984,
199,
646,
5190,
199,
646,
2882,
199,
199,
504,
5228,
492,
5228,
199,
199,
504,
1639,
14,
1208,
14,
2796,
492,
4884,
199,
504,
1639,
14,
1208,
14,
2796,
14,
15390,
492,
14018,
199,
199,
363,
2796,
275,
715,
199,
199,
318,
1433,
20803,
8,
765,
304,
272,
768,
13582,
8,
765,
9,
272,
347,
6506,
8,
277,
12,
627,
589,
12,
1011,
829,
304,
267,
340,
2519,
8,
277,
12,
283,
25829,
297,
756,
304,
288,
291,
14,
2379,
342,
267,
372,
1083,
8,
277,
12,
627,
589,
12,
1011,
829,
9,
272,
372,
6506,
421,
199,
13850,
63,
6174,
275,
1557,
78,
26080,
3427,
78,
5,
83,
7,
199,
18472,
2666,
63,
6174,
275,
1557,
78,
933,
2303,
3427,
78,
5,
83,
7,
199,
199,
533,
23795,
8,
2796,
14,
13120,
304,
272,
408,
22570,
367,
511,
754,
2556,
14,
339,
1379,
2058,
787,
5847,
12883,
701,
314,
7640,
436,
20979,
272,
3992,
12,
436,
886,
440,
1929,
370,
506,
7662,
13335,
8097,
701,
2211,
878,
402,
2295,
14,
339,
7048,
1256,
15164,
314,
3141,
1329,
402,
2295,
1255,
12,
436,
5055,
402,
272,
9081,
436,
2552,
626,
8920,
16885,
5204,
511,
7858,
14,
710,
5055,
272,
1395,
6346,
402,
334,
10847,
12,
1919,
815,
395,
2382,
1919,
815,
365,
314,
272,
7871,
5190,
402,
314,
1125,
626,
8920,
14,
272,
408,
272,
485,
6352,
22009,
275,
488,
272,
485,
578,
19845,
4276,
275,
756,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
25829,
275,
756,
267,
291,
14,
9968,
275,
942,
267,
291,
14,
2550,
275,
942,
267,
291,
14,
30680,
275,
378,
267,
291,
14,
11962,
275,
942,
267,
291,
14,
2062,
29415,
275,
942,
267,
291,
14,
8953,
51,
947,
5804,
275,
942,
267,
291,
14,
5626,
6293,
275,
756,
267,
291,
14,
2738,
275,
756,
267,
291,
423,
2703,
63,
2738,
275,
488,
267,
291,
423,
3083,
63,
2738,
275,
488,
267,
291,
423,
5043,
63,
2703,
275,
984,
14,
2703,
267,
291,
423,
5043,
63,
3083,
275,
984,
14,
3083,
267,
291,
423,
12324,
2959,
275,
756,
339,
347,
1343,
774,
8,
277,
12,
511,
304,
267,
298,
10474,
1380,
314,
1627,
511,
365,
3595,
370,
506,
1255,
2,
267,
291,
14,
30680,
847,
413,
267,
291,
423,
12324,
2959,
275,
756,
267,
340,
291,
14,
2738,
26,
288,
340,
291,
423,
3083,
63,
2738,
365,
488,
26,
355,
291,
423,
3083,
63,
2738,
275,
5228,
342,
355,
291,
423,
2703,
63,
2738,
275,
5228,
342,
288,
984,
14,
2703,
275,
291,
423,
2703,
63,
2738,
288,
984,
14,
3083,
275,
291,
423,
3083,
63,
2738,
339,
347,
1343,
21228,
8,
277,
304,
267,
408,
10474,
5403,
2544,
1263,
2295,
787,
7934,
14,
398,
1666,
1343,
774,
367,
282,
1083,
2797,
2544,
1924,
511,
14,
267,
408,
339,
347,
3631,
774,
8,
277,
12,
511,
304,
267,
408,
10474,
1380,
314,
1627,
511,
965,
2757,
1255,
624,
267,
340,
291,
14,
2738,
26,
288,
340,
291,
423,
12324,
2959,
26,
355,
1072,
275,
984,
14,
2703,
14,
7150,
342,
355,
1125,
275,
984,
14,
3083,
14,
7150,
342,
355,
340,
1072,
26,
490,
340,
440,
1072,
14,
4130,
2258,
78,
735,
717,
1072,
847,
1557,
78,
7,
490,
291,
423,
5043,
63,
2703,
14,
952,
8,
13850,
63,
6174,
450,
1072,
9,
355,
340,
1125,
26,
490,
340,
440,
1125,
14,
4130,
2258,
78,
735,
717,
1125,
847,
1557,
78,
7,
490,
291,
423,
5043,
63,
3083,
14,
952,
8,
18472,
2666,
63,
6174,
450,
1125,
9,
953,
984,
14,
2703,
275,
291,
423,
5043,
63,
2703,
288,
984,
14,
3083,
275,
291,
423,
5043,
63,
3083,
288,
291,
423,
2703,
63,
2738,
14,
5507,
8,
16,
9,
288,
291,
423,
2703,
63,
2738,
14,
12517,
342,
288,
291,
423,
3083,
63,
2738,
14,
5507,
8,
16,
9,
288,
291,
423,
3083,
63,
2738,
14,
12517,
342,
267,
291,
423,
12324,
2959,
275,
756,
2378,
347,
3631,
21228,
8,
277,
304,
267,
408,
10474,
5403,
2410,
1006,
2295,
787,
7934,
14,
398,
1666,
3631,
774,
367,
282,
1083,
2797,
2410,
1924,
511,
14,
267,
408,
339,
768,
25829,
272,
347,
1050,
547,
8,
277,
12,
511,
12,
2329,
304,
267,
408,
10474,
1380,
376,
1125,
965,
8920,
14,
283,
1508,
7,
365,
282,
2008,
402,
1338,
465,
267,
2138,
701,
984,
14,
2804,
63,
815,
1252,
267,
408,
267,
291,
14,
2550,
14,
740,
1332,
396,
12,
291,
423,
2804,
63,
815,
63,
475,
63,
875,
8,
1508,
12,
511,
1724,
267,
291,
423,
12324,
2959,
275,
715,
339,
768,
25829,
272,
347,
1050,
6782,
8,
277,
12,
511,
12,
2329,
304,
267,
408,
10474,
1380,
376,
1125,
965,
8920,
14,
283,
1508,
7,
365,
282,
2008,
402,
1338,
465,
267,
2138,
701,
984,
14,
2804,
63,
815,
20693,
267,
291,
14,
9968,
14,
740,
1332,
396,
12,
291,
423,
2804,
63,
815,
63,
475,
63,
875,
8,
1508,
12,
511,
1724,
267,
291,
423,
12324,
2959,
275,
715,
339,
347,
1050,
8300,
8,
277,
12,
511,
304,
267,
298,
10474,
1380,
282,
511,
965,
9709,
8792,
2,
267,
986,
339,
347,
1050,
7738,
8,
277,
12,
511,
12,
4499,
304,
267,
408,
10474,
1380,
282,
511,
365,
9645,
1041,
267,
291,
14,
11962,
14,
740,
1332,
396,
12,
4499,
430,
339,
347,
1050,
6964,
6782,
8,
277,
12,
511,
12,
2329,
304,
267,
408,
10474,
1380,
376,
1420,
5988,
15,
705,
28408,
1041,
267,
291,
14,
2062,
29415,
14,
740,
8,
288,
334,
396,
12,
291,
423,
2804,
63,
815,
63,
475,
63,
875,
8,
1508,
12,
511,
1724,
339,
768,
25829,
272,
347,
1050,
8708,
8300,
8,
277,
12,
511,
304,
267,
408,
10474,
1380,
282,
511,
1990,
1420,
370,
2449,
12,
1325,
17961,
1041,
267,
291,
14,
8953,
51,
947,
5804,
14,
740,
8,
396,
9,
339,
347,
1990,
20839,
8,
277,
304,
267,
298,
52,
6840,
3775,
503,
440,
642,
754,
1990,
282,
3182,
2,
267,
372,
334,
552,
8,
277,
14,
9968,
9,
435,
822,
8,
277,
14,
2550,
9,
508,
378,
9,
339,
347,
3631,
8,
277,
304,
267,
298
] | [
774,
754,
909,
624,
199,
199,
646,
984,
199,
646,
5190,
199,
646,
2882,
199,
199,
504,
5228,
492,
5228,
199,
199,
504,
1639,
14,
1208,
14,
2796,
492,
4884,
199,
504,
1639,
14,
1208,
14,
2796,
14,
15390,
492,
14018,
199,
199,
363,
2796,
275,
715,
199,
199,
318,
1433,
20803,
8,
765,
304,
272,
768,
13582,
8,
765,
9,
272,
347,
6506,
8,
277,
12,
627,
589,
12,
1011,
829,
304,
267,
340,
2519,
8,
277,
12,
283,
25829,
297,
756,
304,
288,
291,
14,
2379,
342,
267,
372,
1083,
8,
277,
12,
627,
589,
12,
1011,
829,
9,
272,
372,
6506,
421,
199,
13850,
63,
6174,
275,
1557,
78,
26080,
3427,
78,
5,
83,
7,
199,
18472,
2666,
63,
6174,
275,
1557,
78,
933,
2303,
3427,
78,
5,
83,
7,
199,
199,
533,
23795,
8,
2796,
14,
13120,
304,
272,
408,
22570,
367,
511,
754,
2556,
14,
339,
1379,
2058,
787,
5847,
12883,
701,
314,
7640,
436,
20979,
272,
3992,
12,
436,
886,
440,
1929,
370,
506,
7662,
13335,
8097,
701,
2211,
878,
402,
2295,
14,
339,
7048,
1256,
15164,
314,
3141,
1329,
402,
2295,
1255,
12,
436,
5055,
402,
272,
9081,
436,
2552,
626,
8920,
16885,
5204,
511,
7858,
14,
710,
5055,
272,
1395,
6346,
402,
334,
10847,
12,
1919,
815,
395,
2382,
1919,
815,
365,
314,
272,
7871,
5190,
402,
314,
1125,
626,
8920,
14,
272,
408,
272,
485,
6352,
22009,
275,
488,
272,
485,
578,
19845,
4276,
275,
756,
339,
347,
636,
826,
721,
277,
304,
267,
291,
14,
25829,
275,
756,
267,
291,
14,
9968,
275,
942,
267,
291,
14,
2550,
275,
942,
267,
291,
14,
30680,
275,
378,
267,
291,
14,
11962,
275,
942,
267,
291,
14,
2062,
29415,
275,
942,
267,
291,
14,
8953,
51,
947,
5804,
275,
942,
267,
291,
14,
5626,
6293,
275,
756,
267,
291,
14,
2738,
275,
756,
267,
291,
423,
2703,
63,
2738,
275,
488,
267,
291,
423,
3083,
63,
2738,
275,
488,
267,
291,
423,
5043,
63,
2703,
275,
984,
14,
2703,
267,
291,
423,
5043,
63,
3083,
275,
984,
14,
3083,
267,
291,
423,
12324,
2959,
275,
756,
339,
347,
1343,
774,
8,
277,
12,
511,
304,
267,
298,
10474,
1380,
314,
1627,
511,
365,
3595,
370,
506,
1255,
2,
267,
291,
14,
30680,
847,
413,
267,
291,
423,
12324,
2959,
275,
756,
267,
340,
291,
14,
2738,
26,
288,
340,
291,
423,
3083,
63,
2738,
365,
488,
26,
355,
291,
423,
3083,
63,
2738,
275,
5228,
342,
355,
291,
423,
2703,
63,
2738,
275,
5228,
342,
288,
984,
14,
2703,
275,
291,
423,
2703,
63,
2738,
288,
984,
14,
3083,
275,
291,
423,
3083,
63,
2738,
339,
347,
1343,
21228,
8,
277,
304,
267,
408,
10474,
5403,
2544,
1263,
2295,
787,
7934,
14,
398,
1666,
1343,
774,
367,
282,
1083,
2797,
2544,
1924,
511,
14,
267,
408,
339,
347,
3631,
774,
8,
277,
12,
511,
304,
267,
408,
10474,
1380,
314,
1627,
511,
965,
2757,
1255,
624,
267,
340,
291,
14,
2738,
26,
288,
340,
291,
423,
12324,
2959,
26,
355,
1072,
275,
984,
14,
2703,
14,
7150,
342,
355,
1125,
275,
984,
14,
3083,
14,
7150,
342,
355,
340,
1072,
26,
490,
340,
440,
1072,
14,
4130,
2258,
78,
735,
717,
1072,
847,
1557,
78,
7,
490,
291,
423,
5043,
63,
2703,
14,
952,
8,
13850,
63,
6174,
450,
1072,
9,
355,
340,
1125,
26,
490,
340,
440,
1125,
14,
4130,
2258,
78,
735,
717,
1125,
847,
1557,
78,
7,
490,
291,
423,
5043,
63,
3083,
14,
952,
8,
18472,
2666,
63,
6174,
450,
1125,
9,
953,
984,
14,
2703,
275,
291,
423,
5043,
63,
2703,
288,
984,
14,
3083,
275,
291,
423,
5043,
63,
3083,
288,
291,
423,
2703,
63,
2738,
14,
5507,
8,
16,
9,
288,
291,
423,
2703,
63,
2738,
14,
12517,
342,
288,
291,
423,
3083,
63,
2738,
14,
5507,
8,
16,
9,
288,
291,
423,
3083,
63,
2738,
14,
12517,
342,
267,
291,
423,
12324,
2959,
275,
756,
2378,
347,
3631,
21228,
8,
277,
304,
267,
408,
10474,
5403,
2410,
1006,
2295,
787,
7934,
14,
398,
1666,
3631,
774,
367,
282,
1083,
2797,
2410,
1924,
511,
14,
267,
408,
339,
768,
25829,
272,
347,
1050,
547,
8,
277,
12,
511,
12,
2329,
304,
267,
408,
10474,
1380,
376,
1125,
965,
8920,
14,
283,
1508,
7,
365,
282,
2008,
402,
1338,
465,
267,
2138,
701,
984,
14,
2804,
63,
815,
1252,
267,
408,
267,
291,
14,
2550,
14,
740,
1332,
396,
12,
291,
423,
2804,
63,
815,
63,
475,
63,
875,
8,
1508,
12,
511,
1724,
267,
291,
423,
12324,
2959,
275,
715,
339,
768,
25829,
272,
347,
1050,
6782,
8,
277,
12,
511,
12,
2329,
304,
267,
408,
10474,
1380,
376,
1125,
965,
8920,
14,
283,
1508,
7,
365,
282,
2008,
402,
1338,
465,
267,
2138,
701,
984,
14,
2804,
63,
815,
20693,
267,
291,
14,
9968,
14,
740,
1332,
396,
12,
291,
423,
2804,
63,
815,
63,
475,
63,
875,
8,
1508,
12,
511,
1724,
267,
291,
423,
12324,
2959,
275,
715,
339,
347,
1050,
8300,
8,
277,
12,
511,
304,
267,
298,
10474,
1380,
282,
511,
965,
9709,
8792,
2,
267,
986,
339,
347,
1050,
7738,
8,
277,
12,
511,
12,
4499,
304,
267,
408,
10474,
1380,
282,
511,
365,
9645,
1041,
267,
291,
14,
11962,
14,
740,
1332,
396,
12,
4499,
430,
339,
347,
1050,
6964,
6782,
8,
277,
12,
511,
12,
2329,
304,
267,
408,
10474,
1380,
376,
1420,
5988,
15,
705,
28408,
1041,
267,
291,
14,
2062,
29415,
14,
740,
8,
288,
334,
396,
12,
291,
423,
2804,
63,
815,
63,
475,
63,
875,
8,
1508,
12,
511,
1724,
339,
768,
25829,
272,
347,
1050,
8708,
8300,
8,
277,
12,
511,
304,
267,
408,
10474,
1380,
282,
511,
1990,
1420,
370,
2449,
12,
1325,
17961,
1041,
267,
291,
14,
8953,
51,
947,
5804,
14,
740,
8,
396,
9,
339,
347,
1990,
20839,
8,
277,
304,
267,
298,
52,
6840,
3775,
503,
440,
642,
754,
1990,
282,
3182,
2,
267,
372,
334,
552,
8,
277,
14,
9968,
9,
435,
822,
8,
277,
14,
2550,
9,
508,
378,
9,
339,
347,
3631,
8,
277,
304,
267,
298,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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1038 | # Wrapper for loading templates from eggs via pkg_resources.resource_string.
try:
from pkg_resources import resource_string
except ImportError:
resource_string = None
from django.template.base import TemplateDoesNotExist
from django.template.loader import BaseLoader
from django.conf import settings
class Loader(BaseLoader):
is_usable = resource_string is not None
def load_template_source(self, template_name, template_dirs=None):
"""
Loads templates from Python eggs via pkg_resource.resource_string.
For every installed app, it tries to get the resource (app, template_name).
"""
if resource_string is not None:
pkg_name = 'templates/' + template_name
for app in settings.INSTALLED_APPS:
try:
return (resource_string(app, pkg_name).decode(settings.FILE_CHARSET), 'egg:%s:%s' % (app, pkg_name))
except:
pass
raise TemplateDoesNotExist(template_name)
_loader = Loader()
| bsd-3-clause | [
3,
21947,
367,
8697,
7009,
687,
22151,
4799,
5496,
63,
4435,
14,
1927,
63,
875,
14,
199,
199,
893,
26,
272,
687,
5496,
63,
4435,
492,
2073,
63,
875,
199,
2590,
3545,
26,
272,
2073,
63,
875,
275,
488,
199,
199,
504,
1639,
14,
1160,
14,
1095,
492,
27193,
199,
504,
1639,
14,
1160,
14,
3422,
492,
3523,
5455,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
533,
22865,
8,
1563,
5455,
304,
272,
365,
63,
14418,
275,
2073,
63,
875,
365,
440,
488,
339,
347,
2248,
63,
1160,
63,
1365,
8,
277,
12,
1978,
63,
354,
12,
1978,
63,
3220,
29,
403,
304,
267,
408,
267,
30367,
7009,
687,
2018,
22151,
4799,
5496,
63,
1927,
14,
1927,
63,
875,
14,
398,
2104,
4036,
4903,
1145,
12,
652,
11275,
370,
664,
314,
2073,
334,
571,
12,
1978,
63,
354,
680,
267,
408,
267,
340,
2073,
63,
875,
365,
440,
488,
26,
288,
5496,
63,
354,
275,
283,
5876,
4805,
435,
1978,
63,
354,
288,
367,
1145,
315,
2202,
14,
15942,
63,
14219,
26,
355,
862,
26,
490,
372,
334,
1927,
63,
875,
8,
571,
12,
5496,
63,
354,
680,
2708,
8,
1751,
14,
3817,
63,
23969,
395,
283,
5799,
2689,
83,
2689,
83,
7,
450,
334,
571,
12,
5496,
63,
354,
430,
355,
871,
26,
490,
986,
267,
746,
27193,
8,
1160,
63,
354,
9,
199,
199,
63,
3422,
275,
22865,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] | [
21947,
367,
8697,
7009,
687,
22151,
4799,
5496,
63,
4435,
14,
1927,
63,
875,
14,
199,
199,
893,
26,
272,
687,
5496,
63,
4435,
492,
2073,
63,
875,
199,
2590,
3545,
26,
272,
2073,
63,
875,
275,
488,
199,
199,
504,
1639,
14,
1160,
14,
1095,
492,
27193,
199,
504,
1639,
14,
1160,
14,
3422,
492,
3523,
5455,
199,
504,
1639,
14,
2190,
492,
2202,
199,
199,
533,
22865,
8,
1563,
5455,
304,
272,
365,
63,
14418,
275,
2073,
63,
875,
365,
440,
488,
339,
347,
2248,
63,
1160,
63,
1365,
8,
277,
12,
1978,
63,
354,
12,
1978,
63,
3220,
29,
403,
304,
267,
408,
267,
30367,
7009,
687,
2018,
22151,
4799,
5496,
63,
1927,
14,
1927,
63,
875,
14,
398,
2104,
4036,
4903,
1145,
12,
652,
11275,
370,
664,
314,
2073,
334,
571,
12,
1978,
63,
354,
680,
267,
408,
267,
340,
2073,
63,
875,
365,
440,
488,
26,
288,
5496,
63,
354,
275,
283,
5876,
4805,
435,
1978,
63,
354,
288,
367,
1145,
315,
2202,
14,
15942,
63,
14219,
26,
355,
862,
26,
490,
372,
334,
1927,
63,
875,
8,
571,
12,
5496,
63,
354,
680,
2708,
8,
1751,
14,
3817,
63,
23969,
395,
283,
5799,
2689,
83,
2689,
83,
7,
450,
334,
571,
12,
5496,
63,
354,
430,
355,
871,
26,
490,
986,
267,
746,
27193,
8,
1160,
63,
354,
9,
199,
199,
63,
3422,
275,
22865,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
Allow2CEO/browser-ios | brave/node_modules/bloom-filter-cpp/vendor/depot_tools/third_party/gsutil/pkg_util.py | 51 | 2026 | #!/usr/bin/env python
# Utilities to facilitate maintaining one master list of package contents
# in MANIFEST.in and allow us to import that list into various packaging
# tools (e.g. rpmbuid and setup.py).
# Define the file in which we maintain package contents. Rather than
# hard-coding our package contents, to ease maintenance we read the
# manifest file to obtain the list of files and directories to include.
MANIFEST_IN = 'MANIFEST.in'
# Define input and output files for customizing the rpm package spec.
SPEC_IN = 'gsutil.spec.in'
SPEC_OUT = 'gsutil.spec'
# Root of rpmbuild tree for file enumeration in gsutil.spec file.
RPM_ROOT = '%{_datadir}/%{name}/'
def parse_manifest(files, dirs):
'''Parse contents of manifest file and append results to passed lists
of files and directories.
'''
f = open(MANIFEST_IN, 'r')
for line in f:
line = line.strip()
# Skip empty or comment lines.
if (len(line) <= 0) or (line[0] == '#'):
continue
tokens = line.split()
if len(tokens) >= 0:
if tokens[0] == 'include':
files.extend(tokens[1:])
elif tokens[0] == 'recursive-include' and tokens[2] == '*':
dirs.append(tokens[1])
else:
err = 'Unsupported type ' + tokens[0] + ' in ' + MANIFEST_IN + ' file.'
raise Exception(err)
f.close()
# When executed as a separate script, create a dynamically generated rpm
# spec file. Otherwise, when loaded as a module by another script, no
# specific actions are taken, other than making utility functions available
# to the loading script.
if __name__ == '__main__':
# Running as main so generate a new rpm spec file.
files = []
dirs = []
parse_manifest(files, dirs)
fin = open(SPEC_IN, 'r')
fout = open(SPEC_OUT, 'w')
for line in fin:
if line.strip() == '###FILES_GO_HERE###':
for file in files:
fout.write(RPM_ROOT + file + '\n')
for dir in dirs:
fout.write(RPM_ROOT + dir + '/\n')
else:
fout.write(line)
fout.close()
fin.close()
| mpl-2.0 | [
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
738,
17933,
370,
30242,
1051,
323,
11075,
316,
1373,
5288,
769,
402,
2559,
4072,
221,
199,
3,
315,
26688,
20649,
14,
262,
436,
2040,
2739,
370,
492,
626,
769,
1901,
7750,
27369,
221,
199,
3,
7249,
334,
69,
14,
71,
14,
21980,
464,
344,
436,
3272,
14,
647,
680,
199,
199,
3,
13930,
314,
570,
315,
1314,
781,
11075,
2559,
4072,
14,
3898,
728,
2419,
221,
199,
3,
7508,
13,
1523,
4154,
2559,
4072,
12,
370,
325,
482,
21964,
781,
1586,
314,
221,
199,
3,
7712,
570,
370,
3332,
314,
769,
402,
1584,
436,
6602,
370,
2387,
14,
199,
24067,
63,
568,
275,
283,
24067,
14,
262,
7,
199,
199,
3,
13930,
1324,
436,
1072,
1584,
367,
3537,
9147,
314,
21980,
2559,
3158,
14,
199,
24147,
63,
568,
275,
283,
458,
1974,
14,
1650,
14,
262,
7,
199,
24147,
63,
1877,
275,
283,
458,
1974,
14,
1650,
7,
199,
199,
3,
12826,
402,
21980,
1506,
3123,
367,
570,
28640,
315,
24986,
14,
1650,
570,
14,
199,
32067,
63,
5441,
275,
1543,
26975,
18259,
93,
3149,
91,
354,
93,
4805,
199,
199,
318,
2198,
63,
6418,
8,
1725,
12,
7606,
304,
523,
1449,
4003,
4072,
402,
7712,
570,
436,
5666,
2058,
370,
3032,
5548,
1362,
402,
1584,
436,
6602,
14,
523,
1449,
523,
289,
275,
1551,
8,
24067,
63,
568,
12,
283,
82,
358,
523,
367,
1004,
315,
289,
26,
272,
1004,
275,
1004,
14,
1913,
342,
272,
327,
8232,
2701,
503,
3721,
2385,
14,
272,
340,
334,
552,
8,
604,
9,
2695,
378,
9,
503,
334,
604,
59,
16,
61,
508,
3943,
735,
489,
1980,
272,
4645,
275,
1004,
14,
1294,
342,
272,
340,
822,
8,
4504,
9,
2356,
378,
26,
489,
340,
4645,
59,
16,
61,
508,
283,
2613,
356,
267,
1584,
14,
2880,
8,
4504,
59,
17,
5728,
489,
916,
4645,
59,
16,
61,
508,
283,
9931,
13,
2613,
7,
436,
4645,
59,
18,
61,
508,
22969,
267,
7606,
14,
740,
8,
4504,
59,
17,
566,
489,
587,
26,
267,
2329,
275,
283,
12647,
730,
283,
435,
4645,
59,
16,
61,
435,
283,
315,
283,
435,
26688,
20649,
63,
568,
435,
283,
570,
3530,
267,
746,
2186,
8,
1508,
9,
523,
289,
14,
1600,
342,
199,
199,
3,
3979,
7934,
465,
282,
7396,
2884,
12,
1218,
282,
18774,
4046,
21980,
221,
199,
3,
3158,
570,
14,
6630,
12,
1380,
6511,
465,
282,
859,
701,
4573,
2884,
12,
949,
199,
3,
2488,
5445,
787,
9394,
12,
1163,
2419,
10663,
11420,
3423,
2808,
199,
3,
370,
314,
8697,
2884,
14,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
327,
26848,
465,
2446,
880,
3550,
282,
892,
21980,
3158,
570,
14,
523,
1584,
275,
942,
523,
7606,
275,
942,
523,
2198,
63,
6418,
8,
1725,
12,
7606,
9,
523,
2583,
275,
1551,
8,
24147,
63,
568,
12,
283,
82,
358,
523,
17863,
275,
1551,
8,
24147,
63,
1877,
12,
283,
87,
358,
523,
367,
1004,
315,
2583,
26,
272,
340,
1004,
14,
1913,
342,
508,
283,
5680,
9472,
63,
13160,
63,
5293,
5680,
356,
489,
367,
570,
315,
1584,
26,
267,
17863,
14,
952,
8,
32067,
63,
5441,
435,
570,
435,
1557,
78,
358,
489,
367,
2935,
315,
7606,
26,
267,
17863,
14,
952,
8,
32067,
63,
5441,
435,
2935,
435,
1994,
60,
78,
358,
272,
587,
26,
489,
17863,
14,
952,
8,
604,
9,
523,
17863,
14,
1600,
342,
523,
2583,
14,
1600,
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
] | [
2647,
15,
1393,
15,
1813,
2366,
199,
199,
3,
738,
17933,
370,
30242,
1051,
323,
11075,
316,
1373,
5288,
769,
402,
2559,
4072,
221,
199,
3,
315,
26688,
20649,
14,
262,
436,
2040,
2739,
370,
492,
626,
769,
1901,
7750,
27369,
221,
199,
3,
7249,
334,
69,
14,
71,
14,
21980,
464,
344,
436,
3272,
14,
647,
680,
199,
199,
3,
13930,
314,
570,
315,
1314,
781,
11075,
2559,
4072,
14,
3898,
728,
2419,
221,
199,
3,
7508,
13,
1523,
4154,
2559,
4072,
12,
370,
325,
482,
21964,
781,
1586,
314,
221,
199,
3,
7712,
570,
370,
3332,
314,
769,
402,
1584,
436,
6602,
370,
2387,
14,
199,
24067,
63,
568,
275,
283,
24067,
14,
262,
7,
199,
199,
3,
13930,
1324,
436,
1072,
1584,
367,
3537,
9147,
314,
21980,
2559,
3158,
14,
199,
24147,
63,
568,
275,
283,
458,
1974,
14,
1650,
14,
262,
7,
199,
24147,
63,
1877,
275,
283,
458,
1974,
14,
1650,
7,
199,
199,
3,
12826,
402,
21980,
1506,
3123,
367,
570,
28640,
315,
24986,
14,
1650,
570,
14,
199,
32067,
63,
5441,
275,
1543,
26975,
18259,
93,
3149,
91,
354,
93,
4805,
199,
199,
318,
2198,
63,
6418,
8,
1725,
12,
7606,
304,
523,
1449,
4003,
4072,
402,
7712,
570,
436,
5666,
2058,
370,
3032,
5548,
1362,
402,
1584,
436,
6602,
14,
523,
1449,
523,
289,
275,
1551,
8,
24067,
63,
568,
12,
283,
82,
358,
523,
367,
1004,
315,
289,
26,
272,
1004,
275,
1004,
14,
1913,
342,
272,
327,
8232,
2701,
503,
3721,
2385,
14,
272,
340,
334,
552,
8,
604,
9,
2695,
378,
9,
503,
334,
604,
59,
16,
61,
508,
3943,
735,
489,
1980,
272,
4645,
275,
1004,
14,
1294,
342,
272,
340,
822,
8,
4504,
9,
2356,
378,
26,
489,
340,
4645,
59,
16,
61,
508,
283,
2613,
356,
267,
1584,
14,
2880,
8,
4504,
59,
17,
5728,
489,
916,
4645,
59,
16,
61,
508,
283,
9931,
13,
2613,
7,
436,
4645,
59,
18,
61,
508,
22969,
267,
7606,
14,
740,
8,
4504,
59,
17,
566,
489,
587,
26,
267,
2329,
275,
283,
12647,
730,
283,
435,
4645,
59,
16,
61,
435,
283,
315,
283,
435,
26688,
20649,
63,
568,
435,
283,
570,
3530,
267,
746,
2186,
8,
1508,
9,
523,
289,
14,
1600,
342,
199,
199,
3,
3979,
7934,
465,
282,
7396,
2884,
12,
1218,
282,
18774,
4046,
21980,
221,
199,
3,
3158,
570,
14,
6630,
12,
1380,
6511,
465,
282,
859,
701,
4573,
2884,
12,
949,
199,
3,
2488,
5445,
787,
9394,
12,
1163,
2419,
10663,
11420,
3423,
2808,
199,
3,
370,
314,
8697,
2884,
14,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
327,
26848,
465,
2446,
880,
3550,
282,
892,
21980,
3158,
570,
14,
523,
1584,
275,
942,
523,
7606,
275,
942,
523,
2198,
63,
6418,
8,
1725,
12,
7606,
9,
523,
2583,
275,
1551,
8,
24147,
63,
568,
12,
283,
82,
358,
523,
17863,
275,
1551,
8,
24147,
63,
1877,
12,
283,
87,
358,
523,
367,
1004,
315,
2583,
26,
272,
340,
1004,
14,
1913,
342,
508,
283,
5680,
9472,
63,
13160,
63,
5293,
5680,
356,
489,
367,
570,
315,
1584,
26,
267,
17863,
14,
952,
8,
32067,
63,
5441,
435,
570,
435,
1557,
78,
358,
489,
367,
2935,
315,
7606,
26,
267,
17863,
14,
952,
8,
32067,
63,
5441,
435,
2935,
435,
1994,
60,
78,
358,
272,
587,
26,
489,
17863,
14,
952,
8,
604,
9,
523,
17863,
14,
1600,
342,
523,
2583,
14,
1600,
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,
0
] | [
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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