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
|
|---|---|---|---|---|---|---|---|---|
efiop/dvc
|
tests/remotes/gdrive.py
|
1
|
3618
|
# pylint:disable=abstract-method
import json
import os
import uuid
from functools import partialmethod
import pytest
from funcy import cached_property, retry
from dvc.fs.gdrive import GDriveFileSystem
from dvc.path_info import CloudURLInfo
from dvc.utils import tmp_fname
from .base import Base
TEST_GDRIVE_REPO_BUCKET = "root"
def _gdrive_retry(func):
def should_retry(exc):
from googleapiclient.errors import HttpError
if not isinstance(exc, HttpError):
return False
if 500 <= exc.resp.status < 600:
return True
if exc.resp.status == 403:
try:
reason = json.loads(exc.content)["error"]["errors"][0][
"reason"
]
except (ValueError, LookupError):
return False
return reason in ["userRateLimitExceeded", "rateLimitExceeded"]
# 16 tries, start at 0.5s, multiply by golden ratio, cap at 20s
return retry(
16,
timeout=lambda a: min(0.5 * 1.618 ** a, 20),
filter_errors=should_retry,
)(func)
class GDrive(Base, CloudURLInfo):
@staticmethod
def should_test():
return bool(os.getenv(GDriveFileSystem.GDRIVE_CREDENTIALS_DATA))
@cached_property
def config(self):
tmp_path = tmp_fname()
with open(tmp_path, "w") as stream:
raw_credentials = os.getenv(
GDriveFileSystem.GDRIVE_CREDENTIALS_DATA
)
try:
credentials = json.loads(raw_credentials)
except ValueError:
credentials = {}
use_service_account = credentials.get("type") == "service_account"
stream.write(raw_credentials)
return {
"url": self.url,
"gdrive_service_account_json_file_path": tmp_path,
"gdrive_use_service_account": use_service_account,
}
@staticmethod
def _get_storagepath():
return TEST_GDRIVE_REPO_BUCKET + "/" + str(uuid.uuid4())
@staticmethod
def get_url():
# NOTE: `get_url` should always return new random url
return "gdrive://" + GDrive._get_storagepath()
@cached_property
def client(self):
try:
from gdrivefs import GoogleDriveFileSystem
except ImportError:
pytest.skip("gdrivefs is not installed")
return GoogleDriveFileSystem(
token="cache",
tokens_file=self.config["gdrive_service_account_json_file_path"],
service_account=self.config["gdrive_use_service_account"],
)
@_gdrive_retry
def mkdir(self, mode=0o777, parents=False, exist_ok=False):
if not self.client.exists(self.path):
self.client.mkdir(self.path)
@_gdrive_retry
def write_bytes(self, contents):
with self.client.open(self.path, mode="wb") as stream:
stream.write(contents)
@_gdrive_retry
def _read(self, mode):
with self.client.open(self.path, mode=mode) as stream:
return stream.read()
read_text = partialmethod(_read, mode="r")
read_bytes = partialmethod(_read, mode="rb")
@pytest.fixture
def gdrive(test_config, make_tmp_dir):
test_config.requires("gdrive")
if not GDrive.should_test():
pytest.skip("no gdrive")
# NOTE: temporary workaround
tmp_dir = make_tmp_dir("gdrive", dvc=True)
ret = GDrive(GDrive.get_url())
fs = GDriveFileSystem(
gdrive_credentials_tmp_dir=tmp_dir.dvc.tmp_dir, **ret.config
)
fs._gdrive_create_dir("root", fs.path_info.path)
yield ret
|
apache-2.0
|
[
3,
4287,
26,
5993,
29,
6198,
13,
765,
199,
646,
2022,
199,
646,
747,
199,
646,
5377,
199,
504,
9143,
492,
7417,
765,
199,
199,
646,
4613,
199,
504,
2562,
89,
492,
6328,
63,
1829,
12,
7269,
199,
199,
504,
366,
6737,
14,
2319,
14,
7136,
6053,
492,
598,
24276,
17521,
199,
504,
366,
6737,
14,
515,
63,
815,
492,
8142,
2632,
2354,
199,
504,
366,
6737,
14,
1208,
492,
3529,
63,
5252,
199,
199,
504,
1275,
1095,
492,
3523,
199,
199,
2864,
63,
39,
4564,
5399,
63,
20424,
63,
20156,
275,
298,
1231,
2,
421,
199,
318,
485,
7136,
6053,
63,
7154,
8,
1532,
304,
272,
347,
1077,
63,
7154,
8,
2804,
304,
267,
687,
6233,
25661,
14,
2550,
492,
4760,
547,
398,
340,
440,
1228,
8,
2804,
12,
4760,
547,
304,
288,
372,
756,
398,
340,
6891,
2695,
3178,
14,
4518,
14,
1205,
665,
11624,
26,
288,
372,
715,
398,
340,
3178,
14,
4518,
14,
1205,
508,
13269,
26,
288,
862,
26,
355,
4499,
275,
2022,
14,
3640,
8,
2804,
14,
1317,
26332,
705,
6611,
2550,
9210,
16,
1527,
490,
298,
5764,
2,
355,
1622,
288,
871,
334,
3393,
12,
19021,
304,
355,
372,
756,
953,
372,
4499,
315,
2097,
751,
6621,
8407,
24748,
401,
298,
1866,
8407,
24748,
937,
339,
327,
3193,
11275,
12,
1343,
737,
378,
14,
21,
83,
12,
21699,
701,
17631,
10463,
12,
4021,
737,
3388,
83,
272,
372,
7269,
8,
267,
3193,
12,
267,
2653,
29,
2734,
282,
26,
1748,
8,
16,
14,
21,
627,
413,
14,
31872,
1011,
282,
12,
3388,
395,
267,
2457,
63,
2550,
29,
5626,
63,
7154,
12,
272,
776,
8,
1532,
9,
421,
199,
533,
598,
24276,
8,
1563,
12,
8142,
2632,
2354,
304,
272,
768,
4639,
272,
347,
1077,
63,
396,
837,
267,
372,
2155,
8,
736,
14,
12959,
8,
39,
24276,
17521,
14,
39,
4564,
5399,
63,
30553,
8246,
51,
63,
3998,
430,
339,
768,
5245,
63,
1829,
272,
347,
1101,
8,
277,
304,
267,
3529,
63,
515,
275,
3529,
63,
5252,
342,
267,
543,
1551,
8,
2791,
63,
515,
12,
298,
87,
531,
465,
2547,
26,
288,
3066,
63,
6942,
275,
747,
14,
12959,
8,
355,
598,
24276,
17521,
14,
39,
4564,
5399,
63,
30553,
8246,
51,
63,
3998,
288,
776,
288,
862,
26,
355,
6235,
275,
2022,
14,
3640,
8,
1773,
63,
6942,
9,
288,
871,
1722,
26,
355,
6235,
275,
1052,
953,
675,
63,
1364,
63,
2048,
275,
6235,
14,
362,
480,
466,
531,
508,
298,
1364,
63,
2048,
2,
288,
2547,
14,
952,
8,
1773,
63,
6942,
9,
398,
372,
469,
288,
298,
633,
582,
291,
14,
633,
12,
288,
298,
7136,
6053,
63,
1364,
63,
2048,
63,
1001,
63,
493,
63,
515,
582,
3529,
63,
515,
12,
288,
298,
7136,
6053,
63,
1180,
63,
1364,
63,
2048,
582,
675,
63,
1364,
63,
2048,
12,
267,
789,
339,
768,
4639,
272,
347,
485,
362,
63,
3494,
515,
837,
267,
372,
7393,
63,
39,
4564,
5399,
63,
20424,
63,
20156,
435,
10609,
435,
620,
8,
2580,
14,
2580,
20,
1012,
339,
768,
4639,
272,
347,
664,
63,
633,
837,
267,
327,
6944,
26,
658,
362,
63,
633,
64,
1077,
3544,
372,
892,
2196,
1166,
267,
372,
298,
7136,
6053,
30443,
435,
598,
24276,
423,
362,
63,
3494,
515,
342,
339,
768,
5245,
63,
1829,
272,
347,
1890,
8,
277,
304,
267,
862,
26,
288,
687,
486,
9541,
2319,
492,
4475,
24276,
17521,
267,
871,
3545,
26,
288,
4613,
14,
2759,
480,
7136,
6053,
2319,
365,
440,
4903,
531,
398,
372,
4475,
24276,
17521,
8,
288,
1526,
628,
1637,
401,
288,
4645,
63,
493,
29,
277,
14,
888,
905,
7136,
6053,
63,
1364,
63,
2048,
63,
1001,
63,
493,
63,
515,
2255,
288,
2435,
63,
2048,
29,
277,
14,
888,
905,
7136,
6053,
63,
1180,
63,
1364,
63,
2048,
2255,
267,
776,
339,
19915,
7136,
6053,
63,
7154,
272,
347,
20366,
8,
277,
12,
818,
29,
16,
79,
11956,
12,
8623,
29,
797,
12,
2187,
63,
745,
29,
797,
304,
267,
340,
440,
291,
14,
1258,
14,
2444,
8,
277,
14,
515,
304,
288,
291,
14,
1258,
14,
8215,
8,
277,
14,
515,
9,
339,
19915,
7136,
6053,
63,
7154,
272,
347,
2218,
63,
2394,
8,
277,
12,
4072,
304,
267,
543,
291,
14,
1258,
14,
1490,
8,
277,
14,
515,
12,
818,
628,
6603,
531,
465,
2547,
26,
288,
2547,
14,
952,
8,
4407,
9,
339,
19915,
7136,
6053,
63,
7154,
272,
347,
485,
739,
8,
277,
12,
818,
304,
267,
543,
291,
14,
1258,
14,
1490,
8,
277,
14,
515,
12,
818,
29,
632,
9,
465,
2547,
26,
288,
372,
2547,
14,
739,
342,
339,
1586,
63,
505,
275,
7417,
765,
1547,
739,
12,
818,
628,
82,
531,
272,
1586,
63,
2394,
275,
7417,
765,
1547,
739,
12,
818,
628,
4848,
531,
421,
199,
32,
4462,
14,
5997,
199,
318,
486,
9541,
8,
396,
63,
888,
12,
1852,
63,
2791,
63,
694,
304,
272,
511,
63,
888,
14,
6537,
480,
7136,
6053,
531,
272,
340,
440,
598,
24276,
14,
5626,
63,
396,
837,
267,
4613,
14,
2759,
480,
889,
486,
9541,
531,
339,
327,
6944,
26,
7937,
18092,
272,
3529,
63,
694,
275,
1852,
63,
2791,
63,
694,
480,
7136,
6053,
401,
366,
6737,
29,
549,
9,
339,
2203,
275,
598,
24276,
8,
39,
24276,
14,
362,
63,
633,
1012,
272,
7449,
275,
598,
24276,
17521,
8,
267,
486,
9541,
63,
6942,
63,
2791,
63,
694,
29,
2791,
63,
694,
14,
68,
6737,
14,
2791,
63,
694,
12,
1011,
3292,
14,
888,
272,
776,
272,
7449,
423,
7136,
6053,
63,
981,
63,
694,
480,
1231,
401,
7449,
14,
515,
63,
815,
14,
515,
9,
272,
1995,
2203,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4287,
26,
5993,
29,
6198,
13,
765,
199,
646,
2022,
199,
646,
747,
199,
646,
5377,
199,
504,
9143,
492,
7417,
765,
199,
199,
646,
4613,
199,
504,
2562,
89,
492,
6328,
63,
1829,
12,
7269,
199,
199,
504,
366,
6737,
14,
2319,
14,
7136,
6053,
492,
598,
24276,
17521,
199,
504,
366,
6737,
14,
515,
63,
815,
492,
8142,
2632,
2354,
199,
504,
366,
6737,
14,
1208,
492,
3529,
63,
5252,
199,
199,
504,
1275,
1095,
492,
3523,
199,
199,
2864,
63,
39,
4564,
5399,
63,
20424,
63,
20156,
275,
298,
1231,
2,
421,
199,
318,
485,
7136,
6053,
63,
7154,
8,
1532,
304,
272,
347,
1077,
63,
7154,
8,
2804,
304,
267,
687,
6233,
25661,
14,
2550,
492,
4760,
547,
398,
340,
440,
1228,
8,
2804,
12,
4760,
547,
304,
288,
372,
756,
398,
340,
6891,
2695,
3178,
14,
4518,
14,
1205,
665,
11624,
26,
288,
372,
715,
398,
340,
3178,
14,
4518,
14,
1205,
508,
13269,
26,
288,
862,
26,
355,
4499,
275,
2022,
14,
3640,
8,
2804,
14,
1317,
26332,
705,
6611,
2550,
9210,
16,
1527,
490,
298,
5764,
2,
355,
1622,
288,
871,
334,
3393,
12,
19021,
304,
355,
372,
756,
953,
372,
4499,
315,
2097,
751,
6621,
8407,
24748,
401,
298,
1866,
8407,
24748,
937,
339,
327,
3193,
11275,
12,
1343,
737,
378,
14,
21,
83,
12,
21699,
701,
17631,
10463,
12,
4021,
737,
3388,
83,
272,
372,
7269,
8,
267,
3193,
12,
267,
2653,
29,
2734,
282,
26,
1748,
8,
16,
14,
21,
627,
413,
14,
31872,
1011,
282,
12,
3388,
395,
267,
2457,
63,
2550,
29,
5626,
63,
7154,
12,
272,
776,
8,
1532,
9,
421,
199,
533,
598,
24276,
8,
1563,
12,
8142,
2632,
2354,
304,
272,
768,
4639,
272,
347,
1077,
63,
396,
837,
267,
372,
2155,
8,
736,
14,
12959,
8,
39,
24276,
17521,
14,
39,
4564,
5399,
63,
30553,
8246,
51,
63,
3998,
430,
339,
768,
5245,
63,
1829,
272,
347,
1101,
8,
277,
304,
267,
3529,
63,
515,
275,
3529,
63,
5252,
342,
267,
543,
1551,
8,
2791,
63,
515,
12,
298,
87,
531,
465,
2547,
26,
288,
3066,
63,
6942,
275,
747,
14,
12959,
8,
355,
598,
24276,
17521,
14,
39,
4564,
5399,
63,
30553,
8246,
51,
63,
3998,
288,
776,
288,
862,
26,
355,
6235,
275,
2022,
14,
3640,
8,
1773,
63,
6942,
9,
288,
871,
1722,
26,
355,
6235,
275,
1052,
953,
675,
63,
1364,
63,
2048,
275,
6235,
14,
362,
480,
466,
531,
508,
298,
1364,
63,
2048,
2,
288,
2547,
14,
952,
8,
1773,
63,
6942,
9,
398,
372,
469,
288,
298,
633,
582,
291,
14,
633,
12,
288,
298,
7136,
6053,
63,
1364,
63,
2048,
63,
1001,
63,
493,
63,
515,
582,
3529,
63,
515,
12,
288,
298,
7136,
6053,
63,
1180,
63,
1364,
63,
2048,
582,
675,
63,
1364,
63,
2048,
12,
267,
789,
339,
768,
4639,
272,
347,
485,
362,
63,
3494,
515,
837,
267,
372,
7393,
63,
39,
4564,
5399,
63,
20424,
63,
20156,
435,
10609,
435,
620,
8,
2580,
14,
2580,
20,
1012,
339,
768,
4639,
272,
347,
664,
63,
633,
837,
267,
327,
6944,
26,
658,
362,
63,
633,
64,
1077,
3544,
372,
892,
2196,
1166,
267,
372,
298,
7136,
6053,
30443,
435,
598,
24276,
423,
362,
63,
3494,
515,
342,
339,
768,
5245,
63,
1829,
272,
347,
1890,
8,
277,
304,
267,
862,
26,
288,
687,
486,
9541,
2319,
492,
4475,
24276,
17521,
267,
871,
3545,
26,
288,
4613,
14,
2759,
480,
7136,
6053,
2319,
365,
440,
4903,
531,
398,
372,
4475,
24276,
17521,
8,
288,
1526,
628,
1637,
401,
288,
4645,
63,
493,
29,
277,
14,
888,
905,
7136,
6053,
63,
1364,
63,
2048,
63,
1001,
63,
493,
63,
515,
2255,
288,
2435,
63,
2048,
29,
277,
14,
888,
905,
7136,
6053,
63,
1180,
63,
1364,
63,
2048,
2255,
267,
776,
339,
19915,
7136,
6053,
63,
7154,
272,
347,
20366,
8,
277,
12,
818,
29,
16,
79,
11956,
12,
8623,
29,
797,
12,
2187,
63,
745,
29,
797,
304,
267,
340,
440,
291,
14,
1258,
14,
2444,
8,
277,
14,
515,
304,
288,
291,
14,
1258,
14,
8215,
8,
277,
14,
515,
9,
339,
19915,
7136,
6053,
63,
7154,
272,
347,
2218,
63,
2394,
8,
277,
12,
4072,
304,
267,
543,
291,
14,
1258,
14,
1490,
8,
277,
14,
515,
12,
818,
628,
6603,
531,
465,
2547,
26,
288,
2547,
14,
952,
8,
4407,
9,
339,
19915,
7136,
6053,
63,
7154,
272,
347,
485,
739,
8,
277,
12,
818,
304,
267,
543,
291,
14,
1258,
14,
1490,
8,
277,
14,
515,
12,
818,
29,
632,
9,
465,
2547,
26,
288,
372,
2547,
14,
739,
342,
339,
1586,
63,
505,
275,
7417,
765,
1547,
739,
12,
818,
628,
82,
531,
272,
1586,
63,
2394,
275,
7417,
765,
1547,
739,
12,
818,
628,
4848,
531,
421,
199,
32,
4462,
14,
5997,
199,
318,
486,
9541,
8,
396,
63,
888,
12,
1852,
63,
2791,
63,
694,
304,
272,
511,
63,
888,
14,
6537,
480,
7136,
6053,
531,
272,
340,
440,
598,
24276,
14,
5626,
63,
396,
837,
267,
4613,
14,
2759,
480,
889,
486,
9541,
531,
339,
327,
6944,
26,
7937,
18092,
272,
3529,
63,
694,
275,
1852,
63,
2791,
63,
694,
480,
7136,
6053,
401,
366,
6737,
29,
549,
9,
339,
2203,
275,
598,
24276,
8,
39,
24276,
14,
362,
63,
633,
1012,
272,
7449,
275,
598,
24276,
17521,
8,
267,
486,
9541,
63,
6942,
63,
2791,
63,
694,
29,
2791,
63,
694,
14,
68,
6737,
14,
2791,
63,
694,
12,
1011,
3292,
14,
888,
272,
776,
272,
7449,
423,
7136,
6053,
63,
981,
63,
694,
480,
1231,
401,
7449,
14,
515,
63,
815,
14,
515,
9,
272,
1995,
2203,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
nealtodd/django
|
tests/test_runner/test_discover_runner.py
|
210
|
6196
|
import os
from contextlib import contextmanager
from unittest import TestSuite, TextTestRunner, defaultTestLoader
from django.test import TestCase
from django.test.runner import DiscoverRunner
@contextmanager
def change_cwd(directory):
current_dir = os.path.abspath(os.path.dirname(__file__))
new_dir = os.path.join(current_dir, directory)
old_cwd = os.getcwd()
os.chdir(new_dir)
try:
yield
finally:
os.chdir(old_cwd)
class DiscoverRunnerTest(TestCase):
def test_dotted_test_module(self):
count = DiscoverRunner().build_suite(
["test_discovery_sample.tests_sample"],
).countTestCases()
self.assertEqual(count, 4)
def test_dotted_test_class_vanilla_unittest(self):
count = DiscoverRunner().build_suite(
["test_discovery_sample.tests_sample.TestVanillaUnittest"],
).countTestCases()
self.assertEqual(count, 1)
def test_dotted_test_class_django_testcase(self):
count = DiscoverRunner().build_suite(
["test_discovery_sample.tests_sample.TestDjangoTestCase"],
).countTestCases()
self.assertEqual(count, 1)
def test_dotted_test_method_django_testcase(self):
count = DiscoverRunner().build_suite(
["test_discovery_sample.tests_sample.TestDjangoTestCase.test_sample"],
).countTestCases()
self.assertEqual(count, 1)
def test_pattern(self):
count = DiscoverRunner(
pattern="*_tests.py",
).build_suite(["test_discovery_sample"]).countTestCases()
self.assertEqual(count, 1)
def test_file_path(self):
with change_cwd(".."):
count = DiscoverRunner().build_suite(
["test_discovery_sample/"],
).countTestCases()
self.assertEqual(count, 5)
def test_empty_label(self):
"""
If the test label is empty, discovery should happen on the current
working directory.
"""
with change_cwd("."):
suite = DiscoverRunner().build_suite([])
self.assertEqual(
suite._tests[0].id().split(".")[0],
os.path.basename(os.getcwd()),
)
def test_empty_test_case(self):
count = DiscoverRunner().build_suite(
["test_discovery_sample.tests_sample.EmptyTestCase"],
).countTestCases()
self.assertEqual(count, 0)
def test_discovery_on_package(self):
count = DiscoverRunner().build_suite(
["test_discovery_sample.tests"],
).countTestCases()
self.assertEqual(count, 1)
def test_ignore_adjacent(self):
"""
When given a dotted path to a module, unittest discovery searches
not just the module, but also the directory containing the module.
This results in tests from adjacent modules being run when they
should not. The discover runner avoids this behavior.
"""
count = DiscoverRunner().build_suite(
["test_discovery_sample.empty"],
).countTestCases()
self.assertEqual(count, 0)
def test_testcase_ordering(self):
with change_cwd(".."):
suite = DiscoverRunner().build_suite(["test_discovery_sample/"])
self.assertEqual(
suite._tests[0].__class__.__name__,
'TestDjangoTestCase',
msg="TestDjangoTestCase should be the first test case")
self.assertEqual(
suite._tests[1].__class__.__name__,
'TestZimpleTestCase',
msg="TestZimpleTestCase should be the second test case")
# All others can follow in unspecified order, including doctests
self.assertIn('DocTestCase', [t.__class__.__name__ for t in suite._tests[2:]])
def test_duplicates_ignored(self):
"""
Tests shouldn't be discovered twice when discovering on overlapping paths.
"""
base_app = 'gis_tests'
sub_app = 'gis_tests.geo3d'
with self.modify_settings(INSTALLED_APPS={'append': sub_app}):
single = DiscoverRunner().build_suite([base_app]).countTestCases()
dups = DiscoverRunner().build_suite([base_app, sub_app]).countTestCases()
self.assertEqual(single, dups)
def test_reverse(self):
"""
Reverse should reorder tests while maintaining the grouping specified
by ``DiscoverRunner.reorder_by``.
"""
runner = DiscoverRunner(reverse=True)
suite = runner.build_suite(
test_labels=('test_discovery_sample', 'test_discovery_sample2'))
self.assertIn('test_discovery_sample2', next(iter(suite)).id(),
msg="Test labels should be reversed.")
suite = runner.build_suite(test_labels=('test_discovery_sample2',))
suite = tuple(suite)
self.assertIn('DjangoCase', suite[0].id(),
msg="Test groups should not be reversed.")
self.assertIn('SimpleCase', suite[4].id(),
msg="Test groups order should be preserved.")
self.assertIn('DjangoCase2', suite[0].id(),
msg="Django test cases should be reversed.")
self.assertIn('SimpleCase2', suite[4].id(),
msg="Simple test cases should be reversed.")
self.assertIn('UnittestCase2', suite[8].id(),
msg="Unittest test cases should be reversed.")
self.assertIn('test_2', suite[0].id(),
msg="Methods of Django cases should be reversed.")
self.assertIn('test_2', suite[4].id(),
msg="Methods of simple cases should be reversed.")
self.assertIn('test_2', suite[8].id(),
msg="Methods of unittest cases should be reversed.")
def test_overrideable_test_suite(self):
self.assertEqual(DiscoverRunner().test_suite, TestSuite)
def test_overrideable_test_runner(self):
self.assertEqual(DiscoverRunner().test_runner, TextTestRunner)
def test_overrideable_test_loader(self):
self.assertEqual(DiscoverRunner().test_loader, defaultTestLoader)
|
bsd-3-clause
|
[
646,
747,
199,
504,
15502,
492,
27608,
199,
504,
2882,
492,
20979,
12,
4516,
13649,
12,
849,
15824,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
5933,
492,
5289,
5899,
7446,
421,
199,
32,
14237,
199,
318,
1570,
63,
6525,
8,
3619,
304,
272,
1453,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
272,
892,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1818,
63,
694,
12,
2082,
9,
272,
2269,
63,
6525,
275,
747,
14,
9458,
342,
272,
747,
14,
8563,
8,
1222,
63,
694,
9,
272,
862,
26,
267,
1995,
272,
3753,
26,
267,
747,
14,
8563,
8,
1753,
63,
6525,
9,
421,
199,
533,
5289,
5899,
7446,
774,
8,
1746,
304,
339,
347,
511,
63,
19404,
63,
396,
63,
578,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
2219,
63,
3271,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
841,
9,
339,
347,
511,
63,
19404,
63,
396,
63,
533,
63,
20662,
6165,
63,
2796,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
2219,
63,
3271,
14,
774,
54,
290,
6165,
1358,
1770,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
413,
9,
339,
347,
511,
63,
19404,
63,
396,
63,
533,
63,
1176,
63,
10847,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
2219,
63,
3271,
14,
774,
9323,
1746,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
413,
9,
339,
347,
511,
63,
19404,
63,
396,
63,
765,
63,
1176,
63,
10847,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
2219,
63,
3271,
14,
774,
9323,
1746,
14,
396,
63,
3271,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
413,
9,
339,
347,
511,
63,
3401,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
8,
288,
3851,
32103,
63,
2219,
14,
647,
401,
267,
7092,
1506,
63,
5768,
5234,
396,
63,
14859,
63,
3271,
29126,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
413,
9,
339,
347,
511,
63,
493,
63,
515,
8,
277,
304,
267,
543,
1570,
63,
6525,
480,
703,
2349,
288,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
355,
2097,
396,
63,
14859,
63,
3271,
15,
2255,
288,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
959,
9,
339,
347,
511,
63,
1667,
63,
1302,
8,
277,
304,
267,
408,
267,
982,
314,
511,
1768,
365,
2701,
12,
13172,
1077,
5992,
641,
314,
1453,
267,
6449,
2082,
14,
267,
408,
267,
543,
1570,
63,
6525,
480,
30946,
288,
5241,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
4157,
288,
291,
14,
629,
8,
355,
5241,
423,
2219,
59,
16,
1055,
344,
1252,
1294,
15857,
59,
16,
467,
355,
747,
14,
515,
14,
4846,
8,
736,
14,
9458,
4000,
288,
776,
339,
347,
511,
63,
1667,
63,
396,
63,
2546,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
2219,
63,
3271,
14,
4699,
1746,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
378,
9,
339,
347,
511,
63,
14859,
63,
265,
63,
2491,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
2219,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
413,
9,
339,
347,
511,
63,
4247,
63,
350,
17235,
8,
277,
304,
267,
408,
267,
3979,
1627,
282,
18947,
931,
370,
282,
859,
12,
2882,
13172,
21858,
267,
440,
2951,
314,
859,
12,
1325,
2597,
314,
2082,
3035,
314,
859,
14,
398,
961,
2058,
315,
2295,
687,
24113,
4621,
3769,
1255,
1380,
2985,
267,
1077,
440,
14,
710,
20131,
7876,
23674,
642,
5953,
14,
267,
408,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
1667,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
378,
9,
339,
347,
511,
63,
10847,
63,
7128,
8,
277,
304,
267,
543,
1570,
63,
6525,
480,
703,
2349,
288,
5241,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
5234,
396,
63,
14859,
63,
3271,
15,
3135,
288,
291,
14,
629,
8,
355,
5241,
423,
2219,
59,
16,
17979,
533,
4914,
354,
3108,
355,
283,
774,
9323,
1746,
297,
355,
1499,
628,
774,
9323,
1746,
1077,
506,
314,
1642,
511,
1930,
531,
288,
291,
14,
629,
8,
355,
5241,
423,
2219,
59,
17,
17979,
533,
4914,
354,
3108,
355,
283,
774,
58,
1729,
1746,
297,
355,
1499,
628,
774,
58,
1729,
1746,
1077,
506,
314,
3499,
511,
1930,
531,
288,
327,
2900,
11789,
883,
2035,
315,
21994,
1865,
12,
5893,
26721,
288,
291,
14,
4080,
360,
3768,
1746,
297,
359,
84,
855,
533,
4914,
354,
363,
367,
307,
315,
5241,
423,
2219,
59,
18,
2938,
566,
339,
347,
511,
63,
18563,
63,
11996,
8,
277,
304,
267,
408,
267,
6496,
9296,
1133,
506,
24983,
13373,
1380,
20131,
316,
641,
28281,
3792,
14,
267,
408,
267,
1300,
63,
571,
275,
283,
5668,
63,
2219,
7,
267,
1007,
63,
571,
275,
283,
5668,
63,
2219,
14,
6721,
19,
68,
7,
267,
543,
291,
14,
8951,
63,
1751,
8,
15942,
63,
14219,
3713,
740,
356,
1007,
63,
571,
22558,
288,
2849,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
779,
1095,
63,
571,
6575,
835,
19346,
342,
288,
11866,
83,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
779,
1095,
63,
571,
12,
1007,
63,
571,
6575,
835,
19346,
342,
267,
291,
14,
629,
8,
4780,
12,
11866,
83,
9,
339,
347,
511,
63,
4471,
8,
277,
304,
267,
408,
267,
22734,
1077,
32179,
2295,
1830,
11075,
316,
314,
17786
] |
[
747,
199,
504,
15502,
492,
27608,
199,
504,
2882,
492,
20979,
12,
4516,
13649,
12,
849,
15824,
199,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
396,
14,
5933,
492,
5289,
5899,
7446,
421,
199,
32,
14237,
199,
318,
1570,
63,
6525,
8,
3619,
304,
272,
1453,
63,
694,
275,
747,
14,
515,
14,
4832,
8,
736,
14,
515,
14,
3475,
3460,
493,
8964,
272,
892,
63,
694,
275,
747,
14,
515,
14,
904,
8,
1818,
63,
694,
12,
2082,
9,
272,
2269,
63,
6525,
275,
747,
14,
9458,
342,
272,
747,
14,
8563,
8,
1222,
63,
694,
9,
272,
862,
26,
267,
1995,
272,
3753,
26,
267,
747,
14,
8563,
8,
1753,
63,
6525,
9,
421,
199,
533,
5289,
5899,
7446,
774,
8,
1746,
304,
339,
347,
511,
63,
19404,
63,
396,
63,
578,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
2219,
63,
3271,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
841,
9,
339,
347,
511,
63,
19404,
63,
396,
63,
533,
63,
20662,
6165,
63,
2796,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
2219,
63,
3271,
14,
774,
54,
290,
6165,
1358,
1770,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
413,
9,
339,
347,
511,
63,
19404,
63,
396,
63,
533,
63,
1176,
63,
10847,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
2219,
63,
3271,
14,
774,
9323,
1746,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
413,
9,
339,
347,
511,
63,
19404,
63,
396,
63,
765,
63,
1176,
63,
10847,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
2219,
63,
3271,
14,
774,
9323,
1746,
14,
396,
63,
3271,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
413,
9,
339,
347,
511,
63,
3401,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
8,
288,
3851,
32103,
63,
2219,
14,
647,
401,
267,
7092,
1506,
63,
5768,
5234,
396,
63,
14859,
63,
3271,
29126,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
413,
9,
339,
347,
511,
63,
493,
63,
515,
8,
277,
304,
267,
543,
1570,
63,
6525,
480,
703,
2349,
288,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
355,
2097,
396,
63,
14859,
63,
3271,
15,
2255,
288,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
959,
9,
339,
347,
511,
63,
1667,
63,
1302,
8,
277,
304,
267,
408,
267,
982,
314,
511,
1768,
365,
2701,
12,
13172,
1077,
5992,
641,
314,
1453,
267,
6449,
2082,
14,
267,
408,
267,
543,
1570,
63,
6525,
480,
30946,
288,
5241,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
4157,
288,
291,
14,
629,
8,
355,
5241,
423,
2219,
59,
16,
1055,
344,
1252,
1294,
15857,
59,
16,
467,
355,
747,
14,
515,
14,
4846,
8,
736,
14,
9458,
4000,
288,
776,
339,
347,
511,
63,
1667,
63,
396,
63,
2546,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
2219,
63,
3271,
14,
4699,
1746,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
378,
9,
339,
347,
511,
63,
14859,
63,
265,
63,
2491,
8,
277,
304,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
2219,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
413,
9,
339,
347,
511,
63,
4247,
63,
350,
17235,
8,
277,
304,
267,
408,
267,
3979,
1627,
282,
18947,
931,
370,
282,
859,
12,
2882,
13172,
21858,
267,
440,
2951,
314,
859,
12,
1325,
2597,
314,
2082,
3035,
314,
859,
14,
398,
961,
2058,
315,
2295,
687,
24113,
4621,
3769,
1255,
1380,
2985,
267,
1077,
440,
14,
710,
20131,
7876,
23674,
642,
5953,
14,
267,
408,
267,
2338,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
8,
288,
2097,
396,
63,
14859,
63,
3271,
14,
1667,
2255,
267,
7092,
835,
19346,
342,
398,
291,
14,
629,
8,
835,
12,
378,
9,
339,
347,
511,
63,
10847,
63,
7128,
8,
277,
304,
267,
543,
1570,
63,
6525,
480,
703,
2349,
288,
5241,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
5234,
396,
63,
14859,
63,
3271,
15,
3135,
288,
291,
14,
629,
8,
355,
5241,
423,
2219,
59,
16,
17979,
533,
4914,
354,
3108,
355,
283,
774,
9323,
1746,
297,
355,
1499,
628,
774,
9323,
1746,
1077,
506,
314,
1642,
511,
1930,
531,
288,
291,
14,
629,
8,
355,
5241,
423,
2219,
59,
17,
17979,
533,
4914,
354,
3108,
355,
283,
774,
58,
1729,
1746,
297,
355,
1499,
628,
774,
58,
1729,
1746,
1077,
506,
314,
3499,
511,
1930,
531,
288,
327,
2900,
11789,
883,
2035,
315,
21994,
1865,
12,
5893,
26721,
288,
291,
14,
4080,
360,
3768,
1746,
297,
359,
84,
855,
533,
4914,
354,
363,
367,
307,
315,
5241,
423,
2219,
59,
18,
2938,
566,
339,
347,
511,
63,
18563,
63,
11996,
8,
277,
304,
267,
408,
267,
6496,
9296,
1133,
506,
24983,
13373,
1380,
20131,
316,
641,
28281,
3792,
14,
267,
408,
267,
1300,
63,
571,
275,
283,
5668,
63,
2219,
7,
267,
1007,
63,
571,
275,
283,
5668,
63,
2219,
14,
6721,
19,
68,
7,
267,
543,
291,
14,
8951,
63,
1751,
8,
15942,
63,
14219,
3713,
740,
356,
1007,
63,
571,
22558,
288,
2849,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
779,
1095,
63,
571,
6575,
835,
19346,
342,
288,
11866,
83,
275,
5289,
5899,
7446,
1252,
1506,
63,
5768,
779,
1095,
63,
571,
12,
1007,
63,
571,
6575,
835,
19346,
342,
267,
291,
14,
629,
8,
4780,
12,
11866,
83,
9,
339,
347,
511,
63,
4471,
8,
277,
304,
267,
408,
267,
22734,
1077,
32179,
2295,
1830,
11075,
316,
314,
17786,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
liuqr/edx-xiaodun
|
lms/djangoapps/certificates/management/commands/gen_cert_report.py
|
28
|
3498
|
from django.core.management.base import BaseCommand
from certificates.models import GeneratedCertificate
from django.contrib.auth.models import User
from optparse import make_option
from django.conf import settings
from xmodule.course_module import CourseDescriptor
from xmodule.modulestore.django import modulestore
from django.db.models import Count
class Command(BaseCommand):
help = """
Generate a certificate status report for all courses that have ended.
This command does not do anything other than report the current
certificate status.
generating - A request has been made to generate a certificate,
but it has not been generated yet.
regenerating - A request has been made to regenerate a certificate,
but it has not been generated yet.
deleting - A request has been made to delete a certificate.
deleted - The certificate has been deleted.
downloadable - The certificate is available for download.
notpassing - The student was graded but is not passing
"""
option_list = BaseCommand.option_list + (
make_option('-c', '--course',
metavar='COURSE_ID',
dest='course',
default=None,
help='Only generate for COURSE_ID'),
)
def _ended_courses(self):
for course_id in [course # all courses in COURSE_LISTINGS
for sub in settings.COURSE_LISTINGS
for course in settings.COURSE_LISTINGS[sub]]:
course_loc = CourseDescriptor.id_to_location(course_id)
course = modulestore().get_instance(course_id, course_loc)
if course.has_ended():
yield course_id
def handle(self, *args, **options):
# Find all courses that have ended
if options['course']:
ended_courses = [options['course']]
else:
ended_courses = self._ended_courses()
cert_data = {}
for course_id in ended_courses:
# find students who are enrolled
print "Looking up certificate states for {0}".format(course_id)
enrolled_students = User.objects.filter(
courseenrollment__course_id=course_id).prefetch_related(
"groups").order_by('username')
cert_data[course_id] = {'enrolled': enrolled_students.count()}
tallies = GeneratedCertificate.objects.filter(
course_id__exact=course_id).values('status').annotate(
dcount=Count('status'))
cert_data[course_id].update(
{status['status']: status['dcount']
for status in tallies})
# all states we have seen far all courses
status_headings = set(
[status for course in cert_data
for status in cert_data[course]])
# print the heading for the report
print "{:>20}".format("course ID"),
print ' '.join(["{:>12}".format(heading)
for heading in status_headings])
# print the report
for course_id in cert_data:
print "{0:>20}".format(course_id[0:18]),
for heading in status_headings:
if heading in cert_data[course_id]:
print "{:>12}".format(cert_data[course_id][heading]),
else:
print " " * 12,
print
|
agpl-3.0
|
[
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
504,
14512,
14,
992,
492,
17065,
11414,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
8691,
492,
1852,
63,
1422,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
9872,
14,
1972,
63,
578,
492,
5531,
4311,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
1639,
14,
697,
14,
992,
492,
14826,
421,
199,
533,
5817,
8,
25150,
304,
339,
1720,
275,
408,
339,
7958,
282,
5897,
2004,
3622,
367,
1006,
13588,
626,
1172,
22480,
14,
272,
961,
1414,
1630,
440,
886,
7003,
1163,
2419,
3622,
314,
1453,
272,
5897,
2004,
14,
339,
12999,
257,
446,
437,
1056,
965,
2757,
6326,
370,
3550,
282,
5897,
12,
673,
1325,
652,
965,
440,
2757,
4046,
5966,
14,
272,
1295,
727,
1958,
446,
437,
1056,
965,
2757,
6326,
370,
30943,
282,
5897,
12,
673,
1325,
652,
965,
440,
2757,
4046,
5966,
14,
272,
13794,
258,
446,
437,
1056,
965,
2757,
6326,
370,
3145,
282,
5897,
14,
339,
5463,
420,
446,
710,
5897,
965,
2757,
5463,
14,
272,
5235,
461,
446,
710,
5897,
365,
2808,
367,
5235,
14,
272,
440,
29436,
257,
446,
710,
6474,
1990,
1999,
770,
1325,
365,
440,
9476,
339,
408,
339,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
334,
267,
1852,
63,
1422,
3654,
67,
297,
2850,
1972,
297,
288,
8214,
534,
15552,
63,
998,
297,
288,
2053,
534,
1972,
297,
288,
849,
29,
403,
12,
288,
1720,
534,
5903,
3550,
367,
5099,
14302,
63,
998,
659,
267,
776,
339,
347,
485,
8960,
63,
11653,
8,
277,
304,
267,
367,
2518,
63,
344,
315,
359,
1972,
221,
327,
1006,
13588,
315,
5099,
14302,
63,
4924,
3881,
355,
367,
1007,
315,
2202,
14,
15552,
63,
4924,
3881,
490,
367,
2518,
315,
2202,
14,
15552,
63,
4924,
3881,
59,
954,
27589,
288,
2518,
63,
2102,
275,
5531,
4311,
14,
344,
63,
475,
63,
1985,
8,
1972,
63,
344,
9,
288,
2518,
275,
10996,
1252,
362,
63,
842,
8,
1972,
63,
344,
12,
2518,
63,
2102,
9,
288,
340,
2518,
14,
1989,
63,
8960,
837,
355,
1995,
2518,
63,
344,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
398,
327,
6668,
1006,
13588,
626,
1172,
22480,
398,
340,
1511,
459,
1972,
2565,
288,
22480,
63,
11653,
275,
359,
1419,
459,
1972,
6538,
267,
587,
26,
288,
22480,
63,
11653,
275,
291,
423,
8960,
63,
11653,
342,
398,
6250,
63,
576,
275,
1052,
398,
367,
2518,
63,
344,
315,
22480,
63,
11653,
26,
953,
327,
2342,
18557,
3963,
787,
26802,
288,
870,
298,
2041,
17967,
1536,
5897,
6363,
367,
469,
16,
5469,
908,
8,
1972,
63,
344,
9,
288,
26802,
63,
17921,
275,
2876,
14,
1462,
14,
1541,
8,
490,
2518,
12214,
363,
1972,
63,
344,
29,
1972,
63,
344,
680,
15576,
63,
2407,
8,
1169,
298,
2634,
3471,
1648,
63,
991,
360,
2473,
358,
288,
6250,
63,
576,
59,
1972,
63,
344,
61,
275,
791,
22428,
356,
26802,
63,
17921,
14,
835,
12737,
953,
307,
279,
6528,
275,
17065,
11414,
14,
1462,
14,
1541,
8,
717,
2518,
63,
344,
363,
7327,
29,
1972,
63,
344,
680,
1459,
360,
1205,
1959,
10898,
8,
1169,
366,
835,
29,
2353,
360,
1205,
1333,
288,
6250,
63,
576,
59,
1972,
63,
344,
1055,
873,
8,
490,
469,
1205,
459,
1205,
2565,
2004,
459,
68,
835,
418,
3147,
367,
2004,
315,
307,
279,
6528,
1552,
398,
327,
1006,
6363,
781,
1172,
6775,
12474,
1006,
13588,
267,
2004,
63,
2993,
780,
275,
663,
8,
355,
359,
1205,
367,
2518,
315,
6250,
63,
576,
490,
367,
2004,
315,
6250,
63,
576,
59,
1972,
3934,
398,
327,
870,
314,
16631,
367,
314,
3622,
267,
870,
5310,
26,
30,
1165,
5469,
908,
480,
1972,
2870,
1288,
267,
870,
283,
1987,
904,
5234,
28476,
30,
713,
5469,
908,
8,
13983,
9,
1169,
367,
16631,
315,
2004,
63,
2993,
780,
566,
398,
327,
870,
314,
3622,
267,
367,
2518,
63,
344,
315,
6250,
63,
576,
26,
288,
870,
5310,
16,
26,
30,
1165,
5469,
908,
8,
1972,
63,
344,
59,
16,
26,
1085,
2522,
288,
367,
16631,
315,
2004,
63,
2993,
780,
26,
355,
340,
16631,
315,
6250,
63,
576,
59,
1972,
63,
344,
2189,
490,
870,
5310,
26,
30,
713,
5469,
908,
8,
4736,
63,
576,
59,
1972,
63,
344,
1527,
13983,
2522,
355,
587,
26,
490,
870,
298,
298,
627,
3144,
12,
288,
870,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
199,
504,
14512,
14,
992,
492,
17065,
11414,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
8691,
492,
1852,
63,
1422,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
9872,
14,
1972,
63,
578,
492,
5531,
4311,
199,
504,
9872,
14,
10012,
14,
1176,
492,
10996,
199,
504,
1639,
14,
697,
14,
992,
492,
14826,
421,
199,
533,
5817,
8,
25150,
304,
339,
1720,
275,
408,
339,
7958,
282,
5897,
2004,
3622,
367,
1006,
13588,
626,
1172,
22480,
14,
272,
961,
1414,
1630,
440,
886,
7003,
1163,
2419,
3622,
314,
1453,
272,
5897,
2004,
14,
339,
12999,
257,
446,
437,
1056,
965,
2757,
6326,
370,
3550,
282,
5897,
12,
673,
1325,
652,
965,
440,
2757,
4046,
5966,
14,
272,
1295,
727,
1958,
446,
437,
1056,
965,
2757,
6326,
370,
30943,
282,
5897,
12,
673,
1325,
652,
965,
440,
2757,
4046,
5966,
14,
272,
13794,
258,
446,
437,
1056,
965,
2757,
6326,
370,
3145,
282,
5897,
14,
339,
5463,
420,
446,
710,
5897,
965,
2757,
5463,
14,
272,
5235,
461,
446,
710,
5897,
365,
2808,
367,
5235,
14,
272,
440,
29436,
257,
446,
710,
6474,
1990,
1999,
770,
1325,
365,
440,
9476,
339,
408,
339,
945,
63,
513,
275,
22239,
14,
1422,
63,
513,
435,
334,
267,
1852,
63,
1422,
3654,
67,
297,
2850,
1972,
297,
288,
8214,
534,
15552,
63,
998,
297,
288,
2053,
534,
1972,
297,
288,
849,
29,
403,
12,
288,
1720,
534,
5903,
3550,
367,
5099,
14302,
63,
998,
659,
267,
776,
339,
347,
485,
8960,
63,
11653,
8,
277,
304,
267,
367,
2518,
63,
344,
315,
359,
1972,
221,
327,
1006,
13588,
315,
5099,
14302,
63,
4924,
3881,
355,
367,
1007,
315,
2202,
14,
15552,
63,
4924,
3881,
490,
367,
2518,
315,
2202,
14,
15552,
63,
4924,
3881,
59,
954,
27589,
288,
2518,
63,
2102,
275,
5531,
4311,
14,
344,
63,
475,
63,
1985,
8,
1972,
63,
344,
9,
288,
2518,
275,
10996,
1252,
362,
63,
842,
8,
1972,
63,
344,
12,
2518,
63,
2102,
9,
288,
340,
2518,
14,
1989,
63,
8960,
837,
355,
1995,
2518,
63,
344,
339,
347,
2429,
8,
277,
12,
627,
589,
12,
1011,
1419,
304,
398,
327,
6668,
1006,
13588,
626,
1172,
22480,
398,
340,
1511,
459,
1972,
2565,
288,
22480,
63,
11653,
275,
359,
1419,
459,
1972,
6538,
267,
587,
26,
288,
22480,
63,
11653,
275,
291,
423,
8960,
63,
11653,
342,
398,
6250,
63,
576,
275,
1052,
398,
367,
2518,
63,
344,
315,
22480,
63,
11653,
26,
953,
327,
2342,
18557,
3963,
787,
26802,
288,
870,
298,
2041,
17967,
1536,
5897,
6363,
367,
469,
16,
5469,
908,
8,
1972,
63,
344,
9,
288,
26802,
63,
17921,
275,
2876,
14,
1462,
14,
1541,
8,
490,
2518,
12214,
363,
1972,
63,
344,
29,
1972,
63,
344,
680,
15576,
63,
2407,
8,
1169,
298,
2634,
3471,
1648,
63,
991,
360,
2473,
358,
288,
6250,
63,
576,
59,
1972,
63,
344,
61,
275,
791,
22428,
356,
26802,
63,
17921,
14,
835,
12737,
953,
307,
279,
6528,
275,
17065,
11414,
14,
1462,
14,
1541,
8,
717,
2518,
63,
344,
363,
7327,
29,
1972,
63,
344,
680,
1459,
360,
1205,
1959,
10898,
8,
1169,
366,
835,
29,
2353,
360,
1205,
1333,
288,
6250,
63,
576,
59,
1972,
63,
344,
1055,
873,
8,
490,
469,
1205,
459,
1205,
2565,
2004,
459,
68,
835,
418,
3147,
367,
2004,
315,
307,
279,
6528,
1552,
398,
327,
1006,
6363,
781,
1172,
6775,
12474,
1006,
13588,
267,
2004,
63,
2993,
780,
275,
663,
8,
355,
359,
1205,
367,
2518,
315,
6250,
63,
576,
490,
367,
2004,
315,
6250,
63,
576,
59,
1972,
3934,
398,
327,
870,
314,
16631,
367,
314,
3622,
267,
870,
5310,
26,
30,
1165,
5469,
908,
480,
1972,
2870,
1288,
267,
870,
283,
1987,
904,
5234,
28476,
30,
713,
5469,
908,
8,
13983,
9,
1169,
367,
16631,
315,
2004,
63,
2993,
780,
566,
398,
327,
870,
314,
3622,
267,
367,
2518,
63,
344,
315,
6250,
63,
576,
26,
288,
870,
5310,
16,
26,
30,
1165,
5469,
908,
8,
1972,
63,
344,
59,
16,
26,
1085,
2522,
288,
367,
16631,
315,
2004,
63,
2993,
780,
26,
355,
340,
16631,
315,
6250,
63,
576,
59,
1972,
63,
344,
2189,
490,
870,
5310,
26,
30,
713,
5469,
908,
8,
4736,
63,
576,
59,
1972,
63,
344,
1527,
13983,
2522,
355,
587,
26,
490,
870,
298,
298,
627,
3144,
12,
288,
870,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
protatremy/buildbot
|
master/buildbot/test/unit/test_db_builders.py
|
8
|
11032
|
# This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members
from __future__ import absolute_import
from __future__ import print_function
from twisted.internet import defer
from twisted.trial import unittest
from buildbot.db import builders
from buildbot.db import tags
from buildbot.test.fake import fakedb
from buildbot.test.fake import fakemaster
from buildbot.test.util import connector_component
from buildbot.test.util import interfaces
from buildbot.test.util import validation
def builderKey(builder):
return builder['id']
class Tests(interfaces.InterfaceTests):
# common sample data
builder_row = [
fakedb.Builder(id=7, name="some:builder"),
]
# tests
def test_signature_findBuilderId(self):
@self.assertArgSpecMatches(self.db.builders.findBuilderId)
def findBuilderId(self, name):
pass
def test_signature_addBuilderMaster(self):
@self.assertArgSpecMatches(self.db.builders.addBuilderMaster)
def addBuilderMaster(self, builderid=None, masterid=None):
pass
def test_signature_removeBuilderMaster(self):
@self.assertArgSpecMatches(self.db.builders.removeBuilderMaster)
def removeBuilderMaster(self, builderid=None, masterid=None):
pass
def test_signature_getBuilder(self):
@self.assertArgSpecMatches(self.db.builders.getBuilder)
def getBuilder(self, builderid):
pass
def test_signature_getBuilders(self):
@self.assertArgSpecMatches(self.db.builders.getBuilders)
def getBuilders(self, masterid=None):
pass
def test_signature_updateBuilderInfo(self):
@self.assertArgSpecMatches(self.db.builders.updateBuilderInfo)
def updateBuilderInfo(self, builderid, description, tags):
pass
@defer.inlineCallbacks
def test_updateBuilderInfo(self):
yield self.insertTestData([
fakedb.Builder(id=7, name='some:builder7'),
fakedb.Builder(id=8, name='some:builder8'),
])
yield self.db.builders.updateBuilderInfo(7, u'a string which describe the builder', [u'cat1', u'cat2'])
yield self.db.builders.updateBuilderInfo(8, u'a string which describe the builder', [])
builderdict7 = yield self.db.builders.getBuilder(7)
validation.verifyDbDict(self, 'builderdict', builderdict7)
builderdict7['tags'].sort() # order is unspecified
self.assertEqual(builderdict7,
dict(id=7, name='some:builder7', tags=['cat1', 'cat2'],
masterids=[], description='a string which describe the builder'))
builderdict8 = yield self.db.builders.getBuilder(8)
validation.verifyDbDict(self, 'builderdict', builderdict8)
self.assertEqual(builderdict8,
dict(id=8, name='some:builder8', tags=[],
masterids=[], description='a string which describe the builder'))
@defer.inlineCallbacks
def test_findBuilderId_new(self):
id = yield self.db.builders.findBuilderId('some:builder')
builderdict = yield self.db.builders.getBuilder(id)
self.assertEqual(builderdict,
dict(id=id, name='some:builder', tags=[],
masterids=[], description=None))
@defer.inlineCallbacks
def test_findBuilderId_exists(self):
yield self.insertTestData([
fakedb.Builder(id=7, name='some:builder'),
])
id = yield self.db.builders.findBuilderId('some:builder')
self.assertEqual(id, 7)
@defer.inlineCallbacks
def test_addBuilderMaster(self):
yield self.insertTestData([
fakedb.Builder(id=7),
fakedb.Master(id=9, name='abc'),
fakedb.Master(id=10, name='def'),
fakedb.BuilderMaster(builderid=7, masterid=10),
])
yield self.db.builders.addBuilderMaster(builderid=7, masterid=9)
builderdict = yield self.db.builders.getBuilder(7)
validation.verifyDbDict(self, 'builderdict', builderdict)
self.assertEqual(builderdict,
dict(id=7, name='some:builder', tags=[],
masterids=[9, 10], description=None))
@defer.inlineCallbacks
def test_addBuilderMaster_already_present(self):
yield self.insertTestData([
fakedb.Builder(id=7),
fakedb.Master(id=9, name='abc'),
fakedb.Master(id=10, name='def'),
fakedb.BuilderMaster(builderid=7, masterid=9),
])
yield self.db.builders.addBuilderMaster(builderid=7, masterid=9)
builderdict = yield self.db.builders.getBuilder(7)
validation.verifyDbDict(self, 'builderdict', builderdict)
self.assertEqual(builderdict,
dict(id=7, name='some:builder', tags=[],
masterids=[9], description=None))
@defer.inlineCallbacks
def test_removeBuilderMaster(self):
yield self.insertTestData([
fakedb.Builder(id=7),
fakedb.Master(id=9, name='some:master'),
fakedb.Master(id=10, name='other:master'),
fakedb.BuilderMaster(builderid=7, masterid=9),
fakedb.BuilderMaster(builderid=7, masterid=10),
])
yield self.db.builders.removeBuilderMaster(builderid=7, masterid=9)
builderdict = yield self.db.builders.getBuilder(7)
validation.verifyDbDict(self, 'builderdict', builderdict)
self.assertEqual(builderdict,
dict(id=7, name='some:builder', tags=[],
masterids=[10], description=None))
@defer.inlineCallbacks
def test_getBuilder_no_masters(self):
yield self.insertTestData([
fakedb.Builder(id=7, name='some:builder'),
])
builderdict = yield self.db.builders.getBuilder(7)
validation.verifyDbDict(self, 'builderdict', builderdict)
self.assertEqual(builderdict,
dict(id=7, name='some:builder', tags=[],
masterids=[], description=None))
@defer.inlineCallbacks
def test_getBuilder_with_masters(self):
yield self.insertTestData([
fakedb.Builder(id=7, name='some:builder'),
fakedb.Master(id=3, name='m1'),
fakedb.Master(id=4, name='m2'),
fakedb.BuilderMaster(builderid=7, masterid=3),
fakedb.BuilderMaster(builderid=7, masterid=4),
])
builderdict = yield self.db.builders.getBuilder(7)
validation.verifyDbDict(self, 'builderdict', builderdict)
self.assertEqual(builderdict,
dict(id=7, name='some:builder', tags=[],
masterids=[3, 4], description=None))
@defer.inlineCallbacks
def test_getBuilder_missing(self):
builderdict = yield self.db.builders.getBuilder(7)
self.assertEqual(builderdict, None)
@defer.inlineCallbacks
def test_getBuilders(self):
yield self.insertTestData([
fakedb.Builder(id=7, name='some:builder'),
fakedb.Builder(id=8, name='other:builder'),
fakedb.Builder(id=9, name='third:builder'),
fakedb.Master(id=3, name='m1'),
fakedb.Master(id=4, name='m2'),
fakedb.BuilderMaster(builderid=7, masterid=3),
fakedb.BuilderMaster(builderid=8, masterid=3),
fakedb.BuilderMaster(builderid=8, masterid=4),
])
builderlist = yield self.db.builders.getBuilders()
for builderdict in builderlist:
validation.verifyDbDict(self, 'builderdict', builderdict)
self.assertEqual(sorted(builderlist, key=builderKey), sorted([
dict(id=7, name='some:builder', masterids=[
3], tags=[], description=None),
dict(id=8, name='other:builder', masterids=[
3, 4], tags=[], description=None),
dict(id=9, name='third:builder',
masterids=[], tags=[], description=None),
], key=builderKey))
@defer.inlineCallbacks
def test_getBuilders_masterid(self):
yield self.insertTestData([
fakedb.Builder(id=7, name='some:builder'),
fakedb.Builder(id=8, name='other:builder'),
fakedb.Builder(id=9, name='third:builder'),
fakedb.Master(id=3, name='m1'),
fakedb.Master(id=4, name='m2'),
fakedb.BuilderMaster(builderid=7, masterid=3),
fakedb.BuilderMaster(builderid=8, masterid=3),
fakedb.BuilderMaster(builderid=8, masterid=4),
])
builderlist = yield self.db.builders.getBuilders(masterid=3)
for builderdict in builderlist:
validation.verifyDbDict(self, 'builderdict', builderdict)
self.assertEqual(sorted(builderlist, key=builderKey), sorted([
dict(id=7, name='some:builder', masterids=[
3], tags=[], description=None),
dict(id=8, name='other:builder', masterids=[
3, 4], tags=[], description=None),
], key=builderKey))
@defer.inlineCallbacks
def test_getBuilders_empty(self):
builderlist = yield self.db.builders.getBuilders()
self.assertEqual(sorted(builderlist), [])
class RealTests(Tests):
# tests that only "real" implementations will pass
pass
class TestFakeDB(unittest.TestCase, Tests):
def setUp(self):
self.master = fakemaster.make_master(wantDb=True, testcase=self)
self.db = self.master.db
self.db.checkForeignKeys = True
self.insertTestData = self.db.insertTestData
class TestRealDB(unittest.TestCase,
connector_component.ConnectorComponentMixin,
RealTests):
def setUp(self):
d = self.setUpConnectorComponent(
table_names=['builders', 'masters', 'builder_masters',
'builders_tags', 'tags'])
@d.addCallback
def finish_setup(_):
self.db.builders = builders.BuildersConnectorComponent(self.db)
self.db.tags = tags.TagsConnectorComponent(self.db)
self.master = self.db.master
self.master.db = self.db
return d
def tearDown(self):
return self.tearDownConnectorComponent()
|
gpl-2.0
|
[
3,
961,
570,
365,
1777,
402,
6516,
3018,
14,
221,
6516,
3018,
365,
2867,
2032,
26,
1265,
883,
199,
3,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
12,
1015,
499,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
199,
3,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
3,
1898,
6516,
3018,
11682,
14409,
83,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
7390,
14,
4901,
492,
10133,
199,
504,
7390,
14,
14443,
492,
2882,
199,
199,
504,
21306,
14,
697,
492,
27378,
199,
504,
21306,
14,
697,
492,
3762,
199,
504,
21306,
14,
396,
14,
3183,
492,
289,
16702,
66,
199,
504,
21306,
14,
396,
14,
3183,
492,
4026,
4133,
199,
504,
21306,
14,
396,
14,
1974,
492,
13252,
63,
3173,
199,
504,
21306,
14,
396,
14,
1974,
492,
8386,
199,
504,
21306,
14,
396,
14,
1974,
492,
6411,
421,
199,
318,
6545,
1197,
8,
5649,
304,
272,
372,
6545,
459,
344,
418,
421,
199,
533,
6496,
8,
7436,
14,
4267,
2925,
304,
339,
327,
2863,
2690,
666,
339,
6545,
63,
1143,
275,
359,
267,
289,
16702,
66,
14,
6437,
8,
344,
29,
23,
12,
536,
628,
3972,
26,
5649,
1288,
272,
1622,
339,
327,
2295,
339,
347,
511,
63,
5233,
63,
1623,
6437,
1304,
8,
277,
304,
267,
768,
277,
14,
479,
6373,
5307,
12962,
8,
277,
14,
697,
14,
20968,
14,
1623,
6437,
1304,
9,
267,
347,
2342,
6437,
1304,
8,
277,
12,
536,
304,
288,
986,
339,
347,
511,
63,
5233,
63,
525,
6437,
12288,
8,
277,
304,
267,
768,
277,
14,
479,
6373,
5307,
12962,
8,
277,
14,
697,
14,
20968,
14,
525,
6437,
12288,
9,
267,
347,
1050,
6437,
12288,
8,
277,
12,
1032,
24446,
1677,
29,
403,
12,
333,
9209,
1677,
29,
403,
304,
288,
986,
339,
347,
511,
63,
5233,
63,
2168,
6437,
12288,
8,
277,
304,
267,
768,
277,
14,
479,
6373,
5307,
12962,
8,
277,
14,
697,
14,
20968,
14,
2168,
6437,
12288,
9,
267,
347,
2813,
6437,
12288,
8,
277,
12,
1032,
24446,
1677,
29,
403,
12,
333,
9209,
1677,
29,
403,
304,
288,
986,
339,
347,
511,
63,
5233,
63,
362,
6437,
8,
277,
304,
267,
768,
277,
14,
479,
6373,
5307,
12962,
8,
277,
14,
697,
14,
20968,
14,
362,
6437,
9,
267,
347,
664,
6437,
8,
277,
12,
1032,
24446,
1677,
304,
288,
986,
339,
347,
511,
63,
5233,
63,
362,
6437,
83,
8,
277,
304,
267,
768,
277,
14,
479,
6373,
5307,
12962,
8,
277,
14,
697,
14,
20968,
14,
362,
6437,
83,
9,
267,
347,
664,
6437,
83,
8,
277,
12,
333,
9209,
1677,
29,
403,
304,
288,
986,
339,
347,
511,
63,
5233,
63,
873,
6437,
2354,
8,
277,
304,
267,
768,
277,
14,
479,
6373,
5307,
12962,
8,
277,
14,
697,
14,
20968,
14,
873,
6437,
2354,
9,
267,
347,
1678,
6437,
2354,
8,
277,
12,
1032,
24446,
1677,
12,
1369,
12,
3762,
304,
288,
986,
339,
768,
11610,
14,
24813,
272,
347,
511,
63,
873,
6437,
2354,
8,
277,
304,
267,
1995,
291,
14,
3176,
16550,
779,
288,
289,
16702,
66,
14,
6437,
8,
344,
29,
23,
12,
536,
534,
3972,
26,
5649,
23,
659,
288,
289,
16702,
66,
14,
6437,
8,
344,
29,
24,
12,
536,
534,
3972,
26,
5649,
24,
659,
267,
4794,
398,
1995,
291,
14,
697,
14,
20968,
14,
873,
6437,
2354,
8,
23,
12,
399,
7,
65,
1059,
1314,
13743,
314,
6545,
297,
359,
85,
7,
3385,
17,
297,
399,
7,
3385,
18,
1105,
267,
1995,
291,
14,
697,
14,
20968,
14,
873,
6437,
2354,
8,
24,
12,
399,
7,
65,
1059,
1314,
13743,
314,
6545,
297,
3073,
267,
6545,
807,
23,
275,
1995,
291,
14,
697,
14,
20968,
14,
362,
6437,
8,
23,
9,
267,
6411,
14,
4712,
8882,
2141,
8,
277,
12,
283,
5649,
807,
297,
6545,
807,
23,
9,
267,
6545,
807,
23,
459,
2969,
2278,
3191,
342,
221,
327,
1865,
365,
21994,
267,
291,
14,
629,
8,
5649,
807,
23,
12,
586,
1211,
8,
344,
29,
23,
12,
536,
534,
3972,
26,
5649,
23,
297,
3762,
2968,
3385,
17,
297,
283,
3385,
18,
995,
2892,
28065,
6236,
795,
6034,
1369,
534,
65,
1059,
1314,
13743,
314,
6545,
1333,
267,
6545,
807,
24,
275,
1995,
291,
14,
697,
14,
20968,
14,
362,
6437,
8,
24,
9,
267,
6411,
14,
4712,
8882,
2141,
8,
277,
12,
283,
5649,
807,
297,
6545,
807,
24,
9,
267,
291,
14,
629,
8,
5649,
807,
24,
12,
586,
1211,
8,
344,
29,
24,
12,
536,
534,
3972,
26,
5649,
24,
297,
3762,
6034,
2892,
28065,
6236,
795,
6034,
1369,
534,
65,
1059,
1314,
13743,
314,
6545,
1333,
339,
768,
11610,
14,
24813,
272,
347,
511,
63,
1623,
6437,
1304,
63,
1222,
8,
277,
304,
267,
1305,
275,
1995,
291,
14,
697,
14,
20968,
14,
1623,
6437,
1304,
360,
3972,
26,
5649,
358,
267,
6545,
807,
275,
1995,
291,
14,
697,
14,
20968,
14,
362,
6437,
8,
344,
9,
267,
291,
14,
629,
8,
5649,
807,
12,
586,
1211,
8,
344,
29,
344,
12,
536,
534,
3972,
26,
5649,
297,
3762,
6034,
2892,
28065,
6236,
795,
6034,
1369,
29,
403,
430,
339,
768,
11610,
14,
24813,
272,
347,
511,
63,
1623,
6437,
1304,
63,
2444,
8,
277,
304,
267,
1995,
291,
14,
3176,
16550,
779,
288,
289,
16702,
66,
14,
6437,
8,
344,
29,
23,
12,
536,
534,
3972,
26,
5649,
659,
267,
4794,
267,
1305,
275,
1995,
291,
14
] |
[
961,
570,
365,
1777,
402,
6516,
3018,
14,
221,
6516,
3018,
365,
2867,
2032,
26,
1265,
883,
199,
3,
3604,
652,
436,
15,
269,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
12,
1015,
499,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
1325,
2428,
199,
3,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
3169,
503,
3092,
199,
3,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
1696,
1684,
844,
367,
1655,
199,
3,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
3180,
543,
199,
3,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
2752,
12,
3277,
2020,
8026,
199,
3,
11236,
14259,
12,
12066,
11844,
12,
8226,
12,
4828,
11315,
13,
10067,
8217,
14,
199,
3,
199,
3,
1898,
6516,
3018,
11682,
14409,
83,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
504,
7390,
14,
4901,
492,
10133,
199,
504,
7390,
14,
14443,
492,
2882,
199,
199,
504,
21306,
14,
697,
492,
27378,
199,
504,
21306,
14,
697,
492,
3762,
199,
504,
21306,
14,
396,
14,
3183,
492,
289,
16702,
66,
199,
504,
21306,
14,
396,
14,
3183,
492,
4026,
4133,
199,
504,
21306,
14,
396,
14,
1974,
492,
13252,
63,
3173,
199,
504,
21306,
14,
396,
14,
1974,
492,
8386,
199,
504,
21306,
14,
396,
14,
1974,
492,
6411,
421,
199,
318,
6545,
1197,
8,
5649,
304,
272,
372,
6545,
459,
344,
418,
421,
199,
533,
6496,
8,
7436,
14,
4267,
2925,
304,
339,
327,
2863,
2690,
666,
339,
6545,
63,
1143,
275,
359,
267,
289,
16702,
66,
14,
6437,
8,
344,
29,
23,
12,
536,
628,
3972,
26,
5649,
1288,
272,
1622,
339,
327,
2295,
339,
347,
511,
63,
5233,
63,
1623,
6437,
1304,
8,
277,
304,
267,
768,
277,
14,
479,
6373,
5307,
12962,
8,
277,
14,
697,
14,
20968,
14,
1623,
6437,
1304,
9,
267,
347,
2342,
6437,
1304,
8,
277,
12,
536,
304,
288,
986,
339,
347,
511,
63,
5233,
63,
525,
6437,
12288,
8,
277,
304,
267,
768,
277,
14,
479,
6373,
5307,
12962,
8,
277,
14,
697,
14,
20968,
14,
525,
6437,
12288,
9,
267,
347,
1050,
6437,
12288,
8,
277,
12,
1032,
24446,
1677,
29,
403,
12,
333,
9209,
1677,
29,
403,
304,
288,
986,
339,
347,
511,
63,
5233,
63,
2168,
6437,
12288,
8,
277,
304,
267,
768,
277,
14,
479,
6373,
5307,
12962,
8,
277,
14,
697,
14,
20968,
14,
2168,
6437,
12288,
9,
267,
347,
2813,
6437,
12288,
8,
277,
12,
1032,
24446,
1677,
29,
403,
12,
333,
9209,
1677,
29,
403,
304,
288,
986,
339,
347,
511,
63,
5233,
63,
362,
6437,
8,
277,
304,
267,
768,
277,
14,
479,
6373,
5307,
12962,
8,
277,
14,
697,
14,
20968,
14,
362,
6437,
9,
267,
347,
664,
6437,
8,
277,
12,
1032,
24446,
1677,
304,
288,
986,
339,
347,
511,
63,
5233,
63,
362,
6437,
83,
8,
277,
304,
267,
768,
277,
14,
479,
6373,
5307,
12962,
8,
277,
14,
697,
14,
20968,
14,
362,
6437,
83,
9,
267,
347,
664,
6437,
83,
8,
277,
12,
333,
9209,
1677,
29,
403,
304,
288,
986,
339,
347,
511,
63,
5233,
63,
873,
6437,
2354,
8,
277,
304,
267,
768,
277,
14,
479,
6373,
5307,
12962,
8,
277,
14,
697,
14,
20968,
14,
873,
6437,
2354,
9,
267,
347,
1678,
6437,
2354,
8,
277,
12,
1032,
24446,
1677,
12,
1369,
12,
3762,
304,
288,
986,
339,
768,
11610,
14,
24813,
272,
347,
511,
63,
873,
6437,
2354,
8,
277,
304,
267,
1995,
291,
14,
3176,
16550,
779,
288,
289,
16702,
66,
14,
6437,
8,
344,
29,
23,
12,
536,
534,
3972,
26,
5649,
23,
659,
288,
289,
16702,
66,
14,
6437,
8,
344,
29,
24,
12,
536,
534,
3972,
26,
5649,
24,
659,
267,
4794,
398,
1995,
291,
14,
697,
14,
20968,
14,
873,
6437,
2354,
8,
23,
12,
399,
7,
65,
1059,
1314,
13743,
314,
6545,
297,
359,
85,
7,
3385,
17,
297,
399,
7,
3385,
18,
1105,
267,
1995,
291,
14,
697,
14,
20968,
14,
873,
6437,
2354,
8,
24,
12,
399,
7,
65,
1059,
1314,
13743,
314,
6545,
297,
3073,
267,
6545,
807,
23,
275,
1995,
291,
14,
697,
14,
20968,
14,
362,
6437,
8,
23,
9,
267,
6411,
14,
4712,
8882,
2141,
8,
277,
12,
283,
5649,
807,
297,
6545,
807,
23,
9,
267,
6545,
807,
23,
459,
2969,
2278,
3191,
342,
221,
327,
1865,
365,
21994,
267,
291,
14,
629,
8,
5649,
807,
23,
12,
586,
1211,
8,
344,
29,
23,
12,
536,
534,
3972,
26,
5649,
23,
297,
3762,
2968,
3385,
17,
297,
283,
3385,
18,
995,
2892,
28065,
6236,
795,
6034,
1369,
534,
65,
1059,
1314,
13743,
314,
6545,
1333,
267,
6545,
807,
24,
275,
1995,
291,
14,
697,
14,
20968,
14,
362,
6437,
8,
24,
9,
267,
6411,
14,
4712,
8882,
2141,
8,
277,
12,
283,
5649,
807,
297,
6545,
807,
24,
9,
267,
291,
14,
629,
8,
5649,
807,
24,
12,
586,
1211,
8,
344,
29,
24,
12,
536,
534,
3972,
26,
5649,
24,
297,
3762,
6034,
2892,
28065,
6236,
795,
6034,
1369,
534,
65,
1059,
1314,
13743,
314,
6545,
1333,
339,
768,
11610,
14,
24813,
272,
347,
511,
63,
1623,
6437,
1304,
63,
1222,
8,
277,
304,
267,
1305,
275,
1995,
291,
14,
697,
14,
20968,
14,
1623,
6437,
1304,
360,
3972,
26,
5649,
358,
267,
6545,
807,
275,
1995,
291,
14,
697,
14,
20968,
14,
362,
6437,
8,
344,
9,
267,
291,
14,
629,
8,
5649,
807,
12,
586,
1211,
8,
344,
29,
344,
12,
536,
534,
3972,
26,
5649,
297,
3762,
6034,
2892,
28065,
6236,
795,
6034,
1369,
29,
403,
430,
339,
768,
11610,
14,
24813,
272,
347,
511,
63,
1623,
6437,
1304,
63,
2444,
8,
277,
304,
267,
1995,
291,
14,
3176,
16550,
779,
288,
289,
16702,
66,
14,
6437,
8,
344,
29,
23,
12,
536,
534,
3972,
26,
5649,
659,
267,
4794,
267,
1305,
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,
1,
1,
1,
1,
1,
1
] |
smart-developerr/my-first-blog
|
Lib/site-packages/pip/_vendor/packaging/_structures.py
|
1152
|
1416
|
# This file is dual licensed under the terms of the Apache License, Version
# 2.0, and the BSD License. See the LICENSE file in the root of this repository
# for complete details.
from __future__ import absolute_import, division, print_function
class Infinity(object):
def __repr__(self):
return "Infinity"
def __hash__(self):
return hash(repr(self))
def __lt__(self, other):
return False
def __le__(self, other):
return False
def __eq__(self, other):
return isinstance(other, self.__class__)
def __ne__(self, other):
return not isinstance(other, self.__class__)
def __gt__(self, other):
return True
def __ge__(self, other):
return True
def __neg__(self):
return NegativeInfinity
Infinity = Infinity()
class NegativeInfinity(object):
def __repr__(self):
return "-Infinity"
def __hash__(self):
return hash(repr(self))
def __lt__(self, other):
return True
def __le__(self, other):
return True
def __eq__(self, other):
return isinstance(other, self.__class__)
def __ne__(self, other):
return not isinstance(other, self.__class__)
def __gt__(self, other):
return False
def __ge__(self, other):
return False
def __neg__(self):
return Infinity
NegativeInfinity = NegativeInfinity()
|
gpl-3.0
|
[
3,
961,
570,
365,
21164,
18233,
1334,
314,
2895,
402,
314,
3668,
844,
12,
3394,
199,
3,
499,
14,
16,
12,
436,
314,
6289,
844,
14,
1666,
314,
5113,
570,
315,
314,
1738,
402,
642,
7611,
199,
3,
367,
4890,
2436,
14,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
421,
199,
533,
1010,
9693,
8,
785,
304,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
298,
14660,
2,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
8705,
721,
277,
304,
267,
372,
32548,
14660,
199,
199,
14660,
275,
1010,
9693,
342,
421,
199,
533,
32548,
14660,
8,
785,
304,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3905,
14660,
2,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
8705,
721,
277,
304,
267,
372,
1010,
9693,
199,
199,
15562,
14660,
275,
32548,
14660,
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
] |
[
961,
570,
365,
21164,
18233,
1334,
314,
2895,
402,
314,
3668,
844,
12,
3394,
199,
3,
499,
14,
16,
12,
436,
314,
6289,
844,
14,
1666,
314,
5113,
570,
315,
314,
1738,
402,
642,
7611,
199,
3,
367,
4890,
2436,
14,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
421,
199,
533,
1010,
9693,
8,
785,
304,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
298,
14660,
2,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
8705,
721,
277,
304,
267,
372,
32548,
14660,
199,
199,
14660,
275,
1010,
9693,
342,
421,
199,
533,
32548,
14660,
8,
785,
304,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
3905,
14660,
2,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
2722,
8,
277,
430,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
274,
721,
277,
12,
1163,
304,
267,
372,
715,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
685,
721,
277,
12,
1163,
304,
267,
372,
440,
1228,
8,
1848,
12,
291,
855,
533,
3368,
339,
347,
636,
3308,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
303,
721,
277,
12,
1163,
304,
267,
372,
756,
339,
347,
636,
8705,
721,
277,
304,
267,
372,
1010,
9693,
199,
199,
15562,
14660,
275,
32548,
14660,
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,
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,
0,
0,
0,
0,
0,
0,
0
] |
ybellavance/python-for-android
|
python-modules/twisted/twisted/web/vhost.py
|
53
|
4382
|
# -*- test-case-name: twisted.web.
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
# See LICENSE for details.
"""
I am a virtual hosts implementation.
"""
# Twisted Imports
from twisted.python import roots
from twisted.web import resource
class VirtualHostCollection(roots.Homogenous):
"""Wrapper for virtual hosts collection.
This exists for configuration purposes.
"""
entityType = resource.Resource
def __init__(self, nvh):
self.nvh = nvh
def listStaticEntities(self):
return self.nvh.hosts.items()
def getStaticEntity(self, name):
return self.nvh.hosts.get(self)
def reallyPutEntity(self, name, entity):
self.nvh.addHost(name, entity)
def delEntity(self, name):
self.nvh.removeHost(name)
class NameVirtualHost(resource.Resource):
"""I am a resource which represents named virtual hosts.
"""
default = None
def __init__(self):
"""Initialize.
"""
resource.Resource.__init__(self)
self.hosts = {}
def listStaticEntities(self):
return resource.Resource.listStaticEntities(self) + [("Virtual Hosts", VirtualHostCollection(self))]
def getStaticEntity(self, name):
if name == "Virtual Hosts":
return VirtualHostCollection(self)
else:
return resource.Resource.getStaticEntity(self, name)
def addHost(self, name, resrc):
"""Add a host to this virtual host.
This will take a host named `name', and map it to a resource
`resrc'. For example, a setup for our virtual hosts would be::
nvh.addHost('divunal.com', divunalDirectory)
nvh.addHost('www.divunal.com', divunalDirectory)
nvh.addHost('twistedmatrix.com', twistedMatrixDirectory)
nvh.addHost('www.twistedmatrix.com', twistedMatrixDirectory)
"""
self.hosts[name] = resrc
def removeHost(self, name):
"""Remove a host."""
del self.hosts[name]
def _getResourceForRequest(self, request):
"""(Internal) Get the appropriate resource for the given host.
"""
hostHeader = request.getHeader('host')
if hostHeader == None:
return self.default or resource.NoResource()
else:
host = hostHeader.lower().split(':', 1)[0]
return (self.hosts.get(host, self.default)
or resource.NoResource("host %s not in vhost map" % repr(host)))
def render(self, request):
"""Implementation of resource.Resource's render method.
"""
resrc = self._getResourceForRequest(request)
return resrc.render(request)
def getChild(self, path, request):
"""Implementation of resource.Resource's getChild method.
"""
resrc = self._getResourceForRequest(request)
if resrc.isLeaf:
request.postpath.insert(0,request.prepath.pop(-1))
return resrc
else:
return resrc.getChildWithDefault(path, request)
class _HostResource(resource.Resource):
def getChild(self, path, request):
if ':' in path:
host, port = path.split(':', 1)
port = int(port)
else:
host, port = path, 80
request.setHost(host, port)
prefixLen = 3+request.isSecure()+4+len(path)+len(request.prepath[-3])
request.path = '/'+'/'.join(request.postpath)
request.uri = request.uri[prefixLen:]
del request.prepath[:3]
return request.site.getResourceFor(request)
class VHostMonsterResource(resource.Resource):
"""
Use this to be able to record the hostname and method (http vs. https)
in the URL without disturbing your web site. If you put this resource
in a URL http://foo.com/bar then requests to
http://foo.com/bar/http/baz.com/something will be equivalent to
http://foo.com/something, except that the hostname the request will
appear to be accessing will be "baz.com". So if "baz.com" is redirecting
all requests for to foo.com, while foo.com is inaccessible from the outside,
then redirect and url generation will work correctly
"""
def getChild(self, path, request):
if path == 'http':
request.isSecure = lambda: 0
elif path == 'https':
request.isSecure = lambda: 1
return _HostResource()
|
apache-2.0
|
[
3,
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
2520,
14,
199,
3,
1898,
334,
67,
9,
12521,
13,
8664,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
41,
8140,
282,
5791,
7057,
4514,
14,
199,
624,
199,
199,
3,
17078,
24339,
199,
504,
7390,
14,
1548,
492,
14361,
199,
504,
7390,
14,
2520,
492,
2073,
421,
199,
533,
13311,
4965,
7768,
8,
12065,
14,
17810,
573,
2268,
1785,
304,
272,
408,
4590,
367,
5791,
7057,
3245,
14,
339,
961,
3495,
367,
2897,
12901,
14,
272,
408,
272,
4642,
804,
275,
2073,
14,
4031,
339,
347,
636,
826,
721,
277,
12,
302,
20369,
304,
267,
291,
14,
15969,
72,
275,
302,
20369,
339,
347,
769,
9278,
24672,
8,
277,
304,
267,
372,
291,
14,
15969,
72,
14,
5146,
14,
1744,
342,
339,
347,
664,
9278,
7302,
8,
277,
12,
536,
304,
267,
372,
291,
14,
15969,
72,
14,
5146,
14,
362,
8,
277,
9,
339,
347,
7710,
18989,
7302,
8,
277,
12,
536,
12,
4642,
304,
267,
291,
14,
15969,
72,
14,
525,
4965,
8,
354,
12,
4642,
9,
339,
347,
2150,
7302,
8,
277,
12,
536,
304,
267,
291,
14,
15969,
72,
14,
2168,
4965,
8,
354,
9,
421,
199,
533,
2812,
8735,
4965,
8,
1927,
14,
4031,
304,
272,
408,
41,
8140,
282,
2073,
1314,
8469,
4310,
5791,
7057,
14,
272,
408,
339,
849,
275,
488,
339,
347,
636,
826,
721,
277,
304,
267,
408,
9345,
14,
267,
408,
267,
2073,
14,
4031,
855,
826,
721,
277,
9,
267,
291,
14,
5146,
275,
1052,
339,
347,
769,
9278,
24672,
8,
277,
304,
267,
372,
2073,
14,
4031,
14,
513,
9278,
24672,
8,
277,
9,
435,
10003,
8735,
10891,
83,
401,
13311,
4965,
7768,
8,
277,
10524,
339,
347,
664,
9278,
7302,
8,
277,
12,
536,
304,
267,
340,
536,
508,
298,
8735,
10891,
83,
582,
288,
372,
13311,
4965,
7768,
8,
277,
9,
267,
587,
26,
288,
372,
2073,
14,
4031,
14,
362,
9278,
7302,
8,
277,
12,
536,
9,
339,
347,
1050,
4965,
8,
277,
12,
536,
12,
522,
1195,
304,
267,
408,
1123,
282,
1591,
370,
642,
5791,
1591,
14,
398,
961,
911,
5452,
282,
1591,
4310,
658,
354,
297,
436,
2341,
652,
370,
282,
2073,
267,
658,
470,
1195,
1370,
221,
2104,
2893,
12,
282,
3272,
367,
4154,
5791,
7057,
3955,
506,
447,
953,
302,
20369,
14,
525,
4965,
360,
3015,
324,
279,
14,
957,
297,
9073,
324,
279,
6231,
9,
288,
302,
20369,
14,
525,
4965,
360,
1544,
14,
3015,
324,
279,
14,
957,
297,
9073,
324,
279,
6231,
9,
288,
302,
20369,
14,
525,
4965,
360,
12145,
3642,
14,
957,
297,
7390,
6443,
6231,
9,
288,
302,
20369,
14,
525,
4965,
360,
1544,
14,
12145,
3642,
14,
957,
297,
7390,
6443,
6231,
9,
267,
408,
267,
291,
14,
5146,
59,
354,
61,
275,
522,
1195,
339,
347,
2813,
4965,
8,
277,
12,
536,
304,
267,
408,
5587,
282,
1591,
1041,
267,
2150,
291,
14,
5146,
59,
354,
61,
339,
347,
485,
362,
4031,
1858,
2017,
8,
277,
12,
1056,
304,
267,
408,
8,
8405,
9,
2372,
314,
5827,
2073,
367,
314,
1627,
1591,
14,
267,
408,
267,
1591,
2567,
275,
1056,
14,
362,
2567,
360,
1102,
358,
267,
340,
1591,
2567,
508,
488,
26,
288,
372,
291,
14,
885,
503,
2073,
14,
1944,
4031,
342,
267,
587,
26,
288,
1591,
275,
1591,
2567,
14,
2325,
1252,
1294,
16451,
413,
2788,
16,
61,
267,
372,
334,
277,
14,
5146,
14,
362,
8,
1102,
12,
291,
14,
885,
9,
355,
503,
2073,
14,
1944,
4031,
480,
1102,
450,
83,
440,
315,
373,
1102,
2341,
2,
450,
4700,
8,
1102,
1724,
339,
347,
3795,
8,
277,
12,
1056,
304,
267,
408,
7921,
402,
2073,
14,
4031,
1159,
3795,
1083,
14,
267,
408,
267,
522,
1195,
275,
291,
423,
362,
4031,
1858,
2017,
8,
1069,
9,
267,
372,
522,
1195,
14,
3352,
8,
1069,
9,
339,
347,
664,
3493,
8,
277,
12,
931,
12,
1056,
304,
267,
408,
7921,
402,
2073,
14,
4031,
1159,
664,
3493,
1083,
14,
267,
408,
267,
522,
1195,
275,
291,
423,
362,
4031,
1858,
2017,
8,
1069,
9,
267,
340,
522,
1195,
14,
374,
20475,
26,
288,
1056,
14,
1932,
515,
14,
3176,
8,
16,
12,
1069,
14,
657,
515,
14,
1935,
2801,
17,
430,
288,
372,
522,
1195,
267,
587,
26,
288,
372,
522,
1195,
14,
26023,
3007,
2698,
8,
515,
12,
1056,
9,
199,
199,
533,
485,
4965,
4031,
8,
1927,
14,
4031,
304,
339,
347,
664,
3493,
8,
277,
12,
931,
12,
1056,
304,
267,
340,
10871,
315,
931,
26,
288,
1591,
12,
1844,
275,
931,
14,
1294,
16451,
413,
9,
288,
1844,
275,
1109,
8,
719,
9,
267,
587,
26,
288,
1591,
12,
1844,
275,
931,
12,
5939,
267,
1056,
14,
409,
4965,
8,
1102,
12,
1844,
9,
267,
2403,
3166,
275,
650,
11,
1069,
14,
374,
24117,
24543,
20,
11,
552,
8,
515,
6393,
552,
8,
1069,
14,
657,
515,
1988,
19,
566,
267,
1056,
14,
515,
275,
7324,
23164,
1370,
904,
8,
1069,
14,
1932,
515,
9,
267,
1056,
14,
2302,
275,
1056,
14,
2302,
59,
1861,
3166,
2938,
267,
2150,
1056,
14,
657,
515,
1491,
19,
61,
267,
372,
1056,
14,
2124,
14,
362,
4031,
1858,
8,
1069,
9,
421,
199,
533,
812,
4965,
45,
4654,
351,
4031,
8,
1927,
14,
4031,
304,
339,
408,
272,
3645,
642,
370,
506,
7688,
370,
2777,
314,
6246,
436,
1083,
334,
1014,
8118,
14,
4178,
9,
272,
315,
314,
2851,
1928,
2917,
300,
10911,
2195,
3330,
4770,
14,
982,
1265,
5324,
642,
2073,
272,
315,
282,
2851,
1455,
921,
1421,
14,
957,
15,
1700,
2066,
4145,
370,
272,
1455,
921,
1421,
14,
957,
15,
1700,
15,
1014,
15,
6185,
14,
957,
15,
10297,
911,
506,
7353,
370,
272,
1455,
921,
1421,
14,
957,
15,
10297,
12,
871,
626,
314,
6246,
314,
1056,
911,
272,
7468,
370,
506,
18549,
911,
506,
298,
6185,
14,
957,
1674,
2002,
340,
298,
6185,
14,
957,
2,
365,
4660,
316,
272,
1006,
4145,
367,
370,
3925,
14,
957,
12,
1830,
3925,
14,
957,
365,
315,
24669,
687,
314,
9682
] |
[
1882,
511,
13,
2546,
13,
354,
26,
7390,
14,
2520,
14,
199,
3,
1898,
334,
67,
9,
12521,
13,
8664,
17078,
8449,
26640,
14,
199,
3,
1666,
5113,
367,
2436,
14,
199,
199,
624,
199,
41,
8140,
282,
5791,
7057,
4514,
14,
199,
624,
199,
199,
3,
17078,
24339,
199,
504,
7390,
14,
1548,
492,
14361,
199,
504,
7390,
14,
2520,
492,
2073,
421,
199,
533,
13311,
4965,
7768,
8,
12065,
14,
17810,
573,
2268,
1785,
304,
272,
408,
4590,
367,
5791,
7057,
3245,
14,
339,
961,
3495,
367,
2897,
12901,
14,
272,
408,
272,
4642,
804,
275,
2073,
14,
4031,
339,
347,
636,
826,
721,
277,
12,
302,
20369,
304,
267,
291,
14,
15969,
72,
275,
302,
20369,
339,
347,
769,
9278,
24672,
8,
277,
304,
267,
372,
291,
14,
15969,
72,
14,
5146,
14,
1744,
342,
339,
347,
664,
9278,
7302,
8,
277,
12,
536,
304,
267,
372,
291,
14,
15969,
72,
14,
5146,
14,
362,
8,
277,
9,
339,
347,
7710,
18989,
7302,
8,
277,
12,
536,
12,
4642,
304,
267,
291,
14,
15969,
72,
14,
525,
4965,
8,
354,
12,
4642,
9,
339,
347,
2150,
7302,
8,
277,
12,
536,
304,
267,
291,
14,
15969,
72,
14,
2168,
4965,
8,
354,
9,
421,
199,
533,
2812,
8735,
4965,
8,
1927,
14,
4031,
304,
272,
408,
41,
8140,
282,
2073,
1314,
8469,
4310,
5791,
7057,
14,
272,
408,
339,
849,
275,
488,
339,
347,
636,
826,
721,
277,
304,
267,
408,
9345,
14,
267,
408,
267,
2073,
14,
4031,
855,
826,
721,
277,
9,
267,
291,
14,
5146,
275,
1052,
339,
347,
769,
9278,
24672,
8,
277,
304,
267,
372,
2073,
14,
4031,
14,
513,
9278,
24672,
8,
277,
9,
435,
10003,
8735,
10891,
83,
401,
13311,
4965,
7768,
8,
277,
10524,
339,
347,
664,
9278,
7302,
8,
277,
12,
536,
304,
267,
340,
536,
508,
298,
8735,
10891,
83,
582,
288,
372,
13311,
4965,
7768,
8,
277,
9,
267,
587,
26,
288,
372,
2073,
14,
4031,
14,
362,
9278,
7302,
8,
277,
12,
536,
9,
339,
347,
1050,
4965,
8,
277,
12,
536,
12,
522,
1195,
304,
267,
408,
1123,
282,
1591,
370,
642,
5791,
1591,
14,
398,
961,
911,
5452,
282,
1591,
4310,
658,
354,
297,
436,
2341,
652,
370,
282,
2073,
267,
658,
470,
1195,
1370,
221,
2104,
2893,
12,
282,
3272,
367,
4154,
5791,
7057,
3955,
506,
447,
953,
302,
20369,
14,
525,
4965,
360,
3015,
324,
279,
14,
957,
297,
9073,
324,
279,
6231,
9,
288,
302,
20369,
14,
525,
4965,
360,
1544,
14,
3015,
324,
279,
14,
957,
297,
9073,
324,
279,
6231,
9,
288,
302,
20369,
14,
525,
4965,
360,
12145,
3642,
14,
957,
297,
7390,
6443,
6231,
9,
288,
302,
20369,
14,
525,
4965,
360,
1544,
14,
12145,
3642,
14,
957,
297,
7390,
6443,
6231,
9,
267,
408,
267,
291,
14,
5146,
59,
354,
61,
275,
522,
1195,
339,
347,
2813,
4965,
8,
277,
12,
536,
304,
267,
408,
5587,
282,
1591,
1041,
267,
2150,
291,
14,
5146,
59,
354,
61,
339,
347,
485,
362,
4031,
1858,
2017,
8,
277,
12,
1056,
304,
267,
408,
8,
8405,
9,
2372,
314,
5827,
2073,
367,
314,
1627,
1591,
14,
267,
408,
267,
1591,
2567,
275,
1056,
14,
362,
2567,
360,
1102,
358,
267,
340,
1591,
2567,
508,
488,
26,
288,
372,
291,
14,
885,
503,
2073,
14,
1944,
4031,
342,
267,
587,
26,
288,
1591,
275,
1591,
2567,
14,
2325,
1252,
1294,
16451,
413,
2788,
16,
61,
267,
372,
334,
277,
14,
5146,
14,
362,
8,
1102,
12,
291,
14,
885,
9,
355,
503,
2073,
14,
1944,
4031,
480,
1102,
450,
83,
440,
315,
373,
1102,
2341,
2,
450,
4700,
8,
1102,
1724,
339,
347,
3795,
8,
277,
12,
1056,
304,
267,
408,
7921,
402,
2073,
14,
4031,
1159,
3795,
1083,
14,
267,
408,
267,
522,
1195,
275,
291,
423,
362,
4031,
1858,
2017,
8,
1069,
9,
267,
372,
522,
1195,
14,
3352,
8,
1069,
9,
339,
347,
664,
3493,
8,
277,
12,
931,
12,
1056,
304,
267,
408,
7921,
402,
2073,
14,
4031,
1159,
664,
3493,
1083,
14,
267,
408,
267,
522,
1195,
275,
291,
423,
362,
4031,
1858,
2017,
8,
1069,
9,
267,
340,
522,
1195,
14,
374,
20475,
26,
288,
1056,
14,
1932,
515,
14,
3176,
8,
16,
12,
1069,
14,
657,
515,
14,
1935,
2801,
17,
430,
288,
372,
522,
1195,
267,
587,
26,
288,
372,
522,
1195,
14,
26023,
3007,
2698,
8,
515,
12,
1056,
9,
199,
199,
533,
485,
4965,
4031,
8,
1927,
14,
4031,
304,
339,
347,
664,
3493,
8,
277,
12,
931,
12,
1056,
304,
267,
340,
10871,
315,
931,
26,
288,
1591,
12,
1844,
275,
931,
14,
1294,
16451,
413,
9,
288,
1844,
275,
1109,
8,
719,
9,
267,
587,
26,
288,
1591,
12,
1844,
275,
931,
12,
5939,
267,
1056,
14,
409,
4965,
8,
1102,
12,
1844,
9,
267,
2403,
3166,
275,
650,
11,
1069,
14,
374,
24117,
24543,
20,
11,
552,
8,
515,
6393,
552,
8,
1069,
14,
657,
515,
1988,
19,
566,
267,
1056,
14,
515,
275,
7324,
23164,
1370,
904,
8,
1069,
14,
1932,
515,
9,
267,
1056,
14,
2302,
275,
1056,
14,
2302,
59,
1861,
3166,
2938,
267,
2150,
1056,
14,
657,
515,
1491,
19,
61,
267,
372,
1056,
14,
2124,
14,
362,
4031,
1858,
8,
1069,
9,
421,
199,
533,
812,
4965,
45,
4654,
351,
4031,
8,
1927,
14,
4031,
304,
339,
408,
272,
3645,
642,
370,
506,
7688,
370,
2777,
314,
6246,
436,
1083,
334,
1014,
8118,
14,
4178,
9,
272,
315,
314,
2851,
1928,
2917,
300,
10911,
2195,
3330,
4770,
14,
982,
1265,
5324,
642,
2073,
272,
315,
282,
2851,
1455,
921,
1421,
14,
957,
15,
1700,
2066,
4145,
370,
272,
1455,
921,
1421,
14,
957,
15,
1700,
15,
1014,
15,
6185,
14,
957,
15,
10297,
911,
506,
7353,
370,
272,
1455,
921,
1421,
14,
957,
15,
10297,
12,
871,
626,
314,
6246,
314,
1056,
911,
272,
7468,
370,
506,
18549,
911,
506,
298,
6185,
14,
957,
1674,
2002,
340,
298,
6185,
14,
957,
2,
365,
4660,
316,
272,
1006,
4145,
367,
370,
3925,
14,
957,
12,
1830,
3925,
14,
957,
365,
315,
24669,
687,
314,
9682,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
todaychi/hue
|
desktop/core/ext-py/Paste-2.0.1/tests/test_util/test_quoting.py
|
47
|
1073
|
from paste.util import quoting
import six
import unittest
class TestQuoting(unittest.TestCase):
def test_html_unquote(self):
self.assertEqual(quoting.html_unquote(b'<hey you>'),
u'<hey\xa0you>')
self.assertEqual(quoting.html_unquote(b''),
u'')
self.assertEqual(quoting.html_unquote(b'&blahblah;'),
u'&blahblah;')
self.assertEqual(quoting.html_unquote(b'\xe1\x80\xa9'),
u'\u1029')
def test_html_quote(self):
self.assertEqual(quoting.html_quote(1),
'1')
self.assertEqual(quoting.html_quote(None),
'')
self.assertEqual(quoting.html_quote('<hey!>'),
'<hey!>')
if six.PY3:
self.assertEqual(quoting.html_quote(u'<\u1029>'),
u'<\u1029>')
else:
self.assertEqual(quoting.html_quote(u'<\u1029>'),
'<\xe1\x80\xa9>')
|
apache-2.0
|
[
504,
20901,
14,
1974,
492,
18593,
199,
646,
3816,
199,
646,
2882,
199,
199,
533,
1379,
2371,
15866,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
1360,
63,
12240,
8,
277,
304,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
12240,
8,
66,
21840,
4116,
27,
426,
89,
6,
10758,
27,
13297,
6,
3308,
27,
659,
586,
399,
7601,
426,
89,
60,
1800,
16,
13297,
5971,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
12240,
8,
66,
7,
659,
586,
399,
17483,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
12240,
8,
66,
21840,
12702,
12702,
27,
659,
586,
399,
21840,
12702,
12702,
10784,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
12240,
8,
66,
1154,
1845,
17,
60,
88,
1257,
60,
1800,
25,
659,
586,
399,
1154,
85,
709,
1398,
358,
339,
347,
511,
63,
1360,
63,
3513,
8,
277,
304,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
3513,
8,
17,
395,
586,
283,
17,
358,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
3513,
8,
403,
395,
586,
4074,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
3513,
4827,
426,
89,
1,
25642,
586,
7673,
4116,
27,
426,
89,
1,
6,
3308,
10784,
267,
340,
3816,
14,
4521,
19,
26,
288,
291,
14,
629,
8,
25272,
14,
1360,
63,
3513,
8,
85,
7601,
60,
85,
709,
1398,
25642,
2490,
399,
21840,
4116,
3779,
85,
709,
1398,
6,
3308,
10784,
267,
587,
26,
288,
291,
14,
629,
8,
25272,
14,
1360,
63,
3513,
8,
85,
7601,
60,
85,
709,
1398,
25642,
2490,
7673,
4116,
3779,
1845,
17,
60,
88,
1257,
60,
1800,
25,
6,
3308,
10784,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
20901,
14,
1974,
492,
18593,
199,
646,
3816,
199,
646,
2882,
199,
199,
533,
1379,
2371,
15866,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
1360,
63,
12240,
8,
277,
304,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
12240,
8,
66,
21840,
4116,
27,
426,
89,
6,
10758,
27,
13297,
6,
3308,
27,
659,
586,
399,
7601,
426,
89,
60,
1800,
16,
13297,
5971,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
12240,
8,
66,
7,
659,
586,
399,
17483,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
12240,
8,
66,
21840,
12702,
12702,
27,
659,
586,
399,
21840,
12702,
12702,
10784,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
12240,
8,
66,
1154,
1845,
17,
60,
88,
1257,
60,
1800,
25,
659,
586,
399,
1154,
85,
709,
1398,
358,
339,
347,
511,
63,
1360,
63,
3513,
8,
277,
304,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
3513,
8,
17,
395,
586,
283,
17,
358,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
3513,
8,
403,
395,
586,
4074,
267,
291,
14,
629,
8,
25272,
14,
1360,
63,
3513,
4827,
426,
89,
1,
25642,
586,
7673,
4116,
27,
426,
89,
1,
6,
3308,
10784,
267,
340,
3816,
14,
4521,
19,
26,
288,
291,
14,
629,
8,
25272,
14,
1360,
63,
3513,
8,
85,
7601,
60,
85,
709,
1398,
25642,
2490,
399,
21840,
4116,
3779,
85,
709,
1398,
6,
3308,
10784,
267,
587,
26,
288,
291,
14,
629,
8,
25272,
14,
1360,
63,
3513,
8,
85,
7601,
60,
85,
709,
1398,
25642,
2490,
7673,
4116,
3779,
1845,
17,
60,
88,
1257,
60,
1800,
25,
6,
3308,
10784,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0
] |
JGulbronson/rmc
|
analytics/stats.py
|
8
|
15642
|
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
# There's some code in this file that checks for whether a field has been rated
# incorrectly (eg. `if course_review.interest`). Also, there's very slow code
# that loads all records in a collection into memory that should be converted
# to Mongo queries.
# TODO(david): Clean up this file and fix all the issues. Until then, please be
# wary of what you use.
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
from collections import defaultdict
from datetime import datetime, timedelta
from mongoengine import Q
import csv
import rmc.models as m
import rmc.shared.util as _util
import sys
def truncate_datetime(dt):
return dt - timedelta(
hours=dt.hour,
minutes=dt.minute,
seconds=dt.second,
microseconds=dt.microsecond)
def generic_stats():
num_ucs = m.UserCourse.objects().count()
num_users = m.User.objects.count()
num_users_with_transcript = m.User.objects(
transcripts_imported__gt=0).count()
num_users_with_schedule = m.User.objects(
schedules_imported__gt=0).count()
num_course_reviews = m.UserCourse.objects(
course_review__comment__ne='').count()
num_professor_reviews = m.UserCourse.objects(
professor_review__comment__ne='').count()
num_courses = m.Course.objects.count()
# TODO(david): Make rating_fields a class method
num_course_ratings = 0
for rating in m.CourseReview().rating_fields():
query = {'course_review__%s__ne' % rating: None}
num_course_ratings += m.UserCourse.objects(**query).count()
num_professor_ratings = 0
for rating in m.ProfessorReview().rating_fields():
query = {'professor_review__%s__ne' % rating: None}
num_professor_ratings += m.UserCourse.objects(**query).count()
q = Q()
for rating in m.CourseReview().rating_fields():
q |= Q(**{'course_review__%s__ne' % rating: None})
for rating in m.ProfessorReview().rating_fields():
q |= Q(**{'professor_review__%s__ne' % rating: None})
q |= Q(course_review__comment__ne='')
q |= Q(professor_review__comment__ne='')
ucs_rated_reviewed = m.UserCourse.objects.filter(q)
num_ucs_rated_reviewed = ucs_rated_reviewed.count()
# Take intersection of all_course_ids and reviewed_course_ids just in case
rated_reviewed_course_ids = set(ucs_rated_reviewed.distinct('course_id'))
# TODO(mduan): Verify that # (rated_reviewed_course_ids - all_course_ids)
# is empty
num_courses_rated_reviewed = len(rated_reviewed_course_ids)
# Take intersection of all_course_ids and reviewed_course_ids just in case
rated_reviewed_user_ids = set(ucs_rated_reviewed.distinct('user_id'))
# TODO(mduan): Verify that (rated_reviewed_user_ids - all_course_ids)
# is empty
num_users_rated_reviewed = len(rated_reviewed_user_ids)
yesterday = datetime.now() - timedelta(hours=24)
signups = users_joined_after(yesterday)
result = {
'num_users': num_users,
'num_signups_today': signups,
'num_users_with_transcript': num_users_with_transcript,
'num_users_with_schedule': num_users_with_schedule,
'num_ratings': num_course_ratings + num_professor_ratings,
'num_reviews': num_course_reviews + num_professor_reviews,
'num_ucs': num_ucs,
'num_ucs_rated_reviewed': num_ucs_rated_reviewed,
'num_courses': num_courses,
'num_courses_rated_reviewed': num_courses_rated_reviewed,
'num_users_rated_reviewed': num_users_rated_reviewed,
'num_signups_start_time': yesterday,
'epoch': datetime.now(),
}
return result
# Inclusive
def users_joined_after(date=None):
if date is None:
date = datetime.now() - timedelta(hours=24)
return m.User.objects(join_date__gte=date).count()
# Exclusive
def users_joined_before(date=None):
if date is None:
date = datetime.now() - timedelta(hours=24)
return m.User.objects(join_date__lt=date).count()
def latest_reviews(n=5):
tups = []
recent_ucs_by_course = m.UserCourse.objects().order_by(
'-course_review__comment_date').limit(n)
recent_ucs_by_prof = m.UserCourse.objects().order_by(
'-prof_review__comment_date').limit(n)
for uc in (set(recent_ucs_by_course) | set(recent_ucs_by_prof)):
cr_date = uc.course_review.comment_date
pr_date = uc.professor_review.comment_date
if cr_date:
tups.append((cr_date, 'course_review', uc))
if pr_date:
tups.append((pr_date, 'professor_review', uc))
tups.sort(reverse=True)
result = []
for tup in tups:
date, rev_type, uc = tup
result.append({
'user_id': uc.user_id,
'course_id': uc.course_id,
'professor_id': uc.professor_id,
'text': getattr(uc, rev_type).comment,
'date': date,
'type': rev_type,
})
if len(result) == n:
break
return result
def reviews_given(user):
ucs = m.UserCourse.objects(user_id=user.id)
review_count = 0
for uc in ucs:
if uc.course_review.comment:
review_count += 1
if uc.professor_review.comment:
review_count += 1
return review_count
def ratings_given(user):
ucs = m.UserCourse.objects(user_id=user.id)
rating_count = 0
for uc in ucs:
cr = uc.course_review
if cr.interest:
rating_count += 1
if cr.easiness:
rating_count += 1
if cr.usefulness:
rating_count += 1
pr = uc.professor_review
if pr.clarity:
rating_count += 1
if pr.passion:
rating_count += 1
return rating_count
def print_users_rr_counts():
users = m.User.objects()
user_review_count = 0
user_rating_count = 0
total_reviews = 0
total_ratings = 0
for user in users:
num_review = reviews_given(user)
num_rating = ratings_given(user)
total_reviews += num_review
total_ratings += num_rating
if num_review > 0:
user_review_count += 1
if num_rating > 0:
user_rating_count += 1
print "Users who reviewed"
print user_review_count
print "Total reviews (course + prof)"
print total_reviews
print "Users who rated"
print user_rating_count
print "Total ratings (of any kind)"
print total_ratings
def print_all_user_names():
users = m.User.objects()
for user in users:
# TODO(Sandy): Add a get full name method on user
output = user.first_name + " " + user.last_name
print output.encode('UTF-8')
def print_courses_in_exam_but_not_course():
ecs = [e.course_id for e in m.Exam.objects()]
for c in ecs:
if len(m.Course.objects(id=c)) == 0:
print c
def print_exam_collection():
ecs = m.Exam.objects()
for e in sorted(ecs, key=lambda exam: exam.course_id):
e_dict = e.to_dict()
print e_dict
def print_program_names(users):
for user in users:
if user.program_name:
print user.program_name
def print_ratings_count_histogram():
'''
Print the count of ratings for each UserCourse for course/prof reviews
'''
ucs = m.UserCourse.objects()
cr_hist = []
pr_hist = []
for i in range(0, 4):
cr_hist.append(0)
for i in range(0, 3):
pr_hist.append(0)
for uc in ucs:
cr_count = 0
pr_count = 0
cr = uc.course_review
pr = uc.professor_review
if cr.interest:
cr_count += 1
if cr.easiness:
cr_count += 1
if cr.usefulness:
cr_count += 1
if pr.clarity:
pr_count += 1
if pr.passion:
pr_count += 1
cr_hist[cr_count] += 1
pr_hist[pr_count] += 1
print "UserCourse (Course Review) Rating Count Histogram"
print cr_hist
sanity_check_count = 0
for i in range(0, 4):
sanity_check_count += cr_hist[i]
print "Sum of indices for Course Reviews:"
print sanity_check_count
print "(Sanity) UserCourse (Prof Review) Rating Count Histogram"
print pr_hist
sanity_check_count = 0
for i in range(0, 3):
sanity_check_count += pr_hist[i]
print "(Sanity) Sum of indices for Prof Reviews:"
print sanity_check_count
def print_ratings_histogram():
'''
Prints a historgram of each rating.
TODO(Sandy): Don't hardcode rating names and indices. headache right now.
want sleep
'''
hist = {}
hist['i'] = 0
hist['e'] = 0
hist['u'] = 0
hist['c'] = 0
hist['p'] = 0
total_ratings_count = 0
ucs = m.UserCourse.objects()
for uc in ucs:
cr = uc.course_review
pr = uc.professor_review
if cr.interest:
hist['i'] += 1
total_ratings_count += 1
if cr.easiness:
hist['e'] += 1
total_ratings_count += 1
if cr.usefulness:
hist['u'] += 1
total_ratings_count += 1
if pr.clarity:
hist['c'] += 1
total_ratings_count += 1
if pr.passion:
hist['p'] += 1
total_ratings_count += 1
print "Ratings histogram"
print "Interest: %d" % hist['i']
print "Easiness: %d" % hist['e']
print "Usefulness: %d" % hist['u']
print "Clarity: %d" % hist['c']
print "Passion: %d" % hist['p']
print "(Sanity) Rating count"
print total_ratings_count
def has_user_taken_cid(user, course_id):
return course_id in user.course_ids
def users_who_took(course_id):
users = m.User.objects()
users_taken = []
for user in users:
if has_user_taken_cid(user, course_id):
users_taken.append(user)
return users_taken
def print_users_gender_count():
users = m.User.objects()
print users[0].gender
gender_counts = {
'male': 0,
'female': 0,
'none': 0,
}
for u in users:
if u.gender:
gender_counts[u.gender] += 1
else:
gender_counts['none'] += 1
print gender_counts
def reviews_after_date(day=truncate_datetime(datetime.now()),
print_result=False):
reviews = []
for uc in m.UserCourse.objects():
cr = uc.course_review
pr = uc.professor_review
if cr and cr.comment and cr.comment_date >= day:
reviews.append(cr.comment)
if print_result:
print cr.comment
if pr and pr.comment and pr.comment_date >= day:
reviews.append(pr.comment)
if print_result:
print pr.comment
return reviews
def review_length_hist(reviews, trunc=0, print_result=False):
hist = defaultdict(int)
for review in reviews:
length = len(review) % trunc if trunc else len(review)
hist[length] += 1
if print_result:
for key, val in iter(sorted(hist.items())):
length = (key + 1) * trunc if trunc else key
print "%d: %d" % (key, val)
return hist
def latest_review_date(user):
latest_date = None
for uc in user.get_user_courses():
crd = uc.course_review.comment_date
prd = uc.professor_review.comment_date
if not latest_date:
latest_date = crd
if crd and latest_date < crd:
latest_date = crd
if prd and latest_date < prd:
latest_date = prd
return latest_date
def unsafe_clear_schedule(user, term_id=_util.get_current_term_id()):
for usi in m.UserScheduleItem.objects(user_id=user.id, term_id=term_id):
usi.delete()
for uc in m.UserCourse.objects(user_id=user.id, term_id=term_id):
try:
user.course_history.remove(uc.id)
except ValueError:
print "Weird problem: UC (%s) doesn't exist" % (uc.id)
uc.delete()
user.schedules_imported = 0
user.save()
# Shorthands for common query operations
def ucs_for_cid(course_id):
return m.UserCourse.objects(course_id=course_id)
def cid(course_id):
return m.Course.objects.with_id(course_id)
def uid(user_id):
return m.User.objects.with_id(user_id)
# CSV dumps
# TODO(Sandy): Use dialect functionality of csv?
def ga_date(date_val):
return date_val.strftime('%Y-%m-%d')
def csv_user_growth(file_name='stats.tmp'):
signups = defaultdict(int)
transcripts = defaultdict(int)
for u in m.User.objects():
jd = u.join_date
jd = truncate_datetime(jd)
if u.has_course_history:
transcripts[jd] += 1
signups[jd] += 1
with open(file_name, 'w+') as csv_file:
writer = csv.writer(csv_file)
writer.writerow([
'Date',
'Users signed up',
'Users imported transcript',
])
for key, s_count in iter(sorted(signups.items())):
t_count = transcripts[key] if key in transcripts else 0
writer.writerow([ga_date(key), s_count, t_count])
csv_file.seek(0)
return csv_file.read()
def csv_review_growth(file_name='stats.tmp'):
reviews = defaultdict(int)
for uc in m.UserCourse.objects():
cr = uc.course_review
pr = uc.professor_review
if cr and cr.comment:
rd = cr.comment_date
rd = truncate_datetime(rd)
reviews[rd] += 1
if pr and pr.comment:
rd = pr.comment_date
rd = truncate_datetime(rd)
reviews[rd] += 1
with open(file_name, 'w+') as csv_file:
writer = csv.writer(csv_file)
writer.writerow(['Date', 'Reviews'])
for key, r_count in iter(sorted(reviews.items())):
writer.writerow([ga_date(key), r_count])
csv_file.seek(0)
return csv_file.read()
def csv_user_points(file_name='user_points.tmp'):
with open(file_name, 'w+') as csv_file:
writer = csv.writer(csv_file)
writer.writerow([
'User ID',
'Name',
'Program',
'Year',
'Points',
'Reviews written',
'Ratings given',
'Link',
])
for user in m.User.objects():
writer.writerow([
user.id,
user.name.encode('utf8'),
user.program_name,
user.get_latest_program_year_id(),
user.num_points,
reviews_given(user),
ratings_given(user),
"https://uwflow.com/profile/%s?as_oid=%s" % (user.id, user.id),
])
csv_file.seek(0)
return csv_file.read()
def generate_csvs():
csv_user_growth('user_growth.csv')
csv_review_growth('review_growth.csv')
# TODO(Sandy): Move to test/debugging file
def print_user_schedule_debug():
"""
A very light sanity check for backfilling schedule imports
Diff the results before and after parsing changes
"""
for user in m.User.objects():
items = user.get_all_schedule_items()
courses = set()
for i in items:
courses.add(i.course_id)
safe_name = user.name.encode('utf-8')
print "%s, %s, %d USIs, %d courses" % (
str(user.id), safe_name, len(items), len(courses))
# TODO(Sandy): More help info
def stats_help():
'''
Print help for stats module
'''
for val in dir(sys.modules[__name__]):
print val
|
mit
|
[
3,
221,
29290,
29290,
10312,
6386,
1,
199,
3,
6006,
1159,
2005,
1233,
315,
642,
570,
626,
5920,
367,
3775,
282,
901,
965,
2757,
519,
972,
199,
3,
22743,
334,
5902,
14,
658,
692,
2518,
63,
8578,
14,
18700,
14963,
6121,
12,
2337,
1159,
7437,
11999,
1233,
199,
3,
626,
14404,
1006,
5767,
315,
282,
3245,
1901,
4402,
626,
1077,
506,
6702,
199,
3,
370,
13503,
9212,
14,
199,
3,
3254,
8,
983,
5017,
304,
12762,
1536,
642,
570,
436,
5325,
1006,
314,
10876,
14,
1910,
2270,
2066,
12,
8749,
506,
199,
3,
258,
336,
695,
402,
4052,
1265,
675,
14,
199,
3,
221,
29290,
29290,
10312,
6386,
1,
421,
199,
504,
5055,
492,
10018,
199,
504,
2197,
492,
2197,
12,
6871,
199,
504,
18006,
3908,
492,
1413,
199,
646,
7392,
199,
646,
519,
5466,
14,
992,
465,
333,
199,
646,
519,
5466,
14,
5555,
14,
1974,
465,
485,
1974,
199,
646,
984,
421,
199,
318,
14547,
63,
2083,
8,
3583,
304,
272,
372,
4487,
446,
6871,
8,
288,
10857,
29,
3583,
14,
5180,
12,
288,
9395,
29,
3583,
14,
10698,
12,
288,
4696,
29,
3583,
14,
4375,
12,
288,
21574,
29,
3583,
14,
16627,
9,
421,
199,
318,
7809,
63,
3200,
837,
272,
1967,
63,
23880,
275,
333,
14,
1899,
6979,
14,
1462,
1252,
835,
342,
339,
1967,
63,
3707,
275,
333,
14,
1899,
14,
1462,
14,
835,
342,
272,
1967,
63,
3707,
63,
1045,
63,
21656,
275,
333,
14,
1899,
14,
1462,
8,
288,
7115,
6429,
63,
17932,
363,
3308,
29,
16,
680,
835,
342,
272,
1967,
63,
3707,
63,
1045,
63,
7211,
275,
333,
14,
1899,
14,
1462,
8,
288,
8732,
83,
63,
17932,
363,
3308,
29,
16,
680,
835,
342,
339,
1967,
63,
1972,
63,
24169,
275,
333,
14,
1899,
6979,
14,
1462,
8,
288,
2518,
63,
8578,
363,
3349,
363,
685,
534,
1959,
835,
342,
272,
1967,
63,
496,
771,
385,
269,
63,
24169,
275,
333,
14,
1899,
6979,
14,
1462,
8,
288,
557,
771,
385,
269,
63,
8578,
363,
3349,
363,
685,
534,
1959,
835,
342,
339,
1967,
63,
11653,
275,
333,
14,
6979,
14,
1462,
14,
835,
342,
339,
327,
3254,
8,
983,
5017,
304,
4155,
18360,
63,
955,
282,
1021,
1083,
272,
1967,
63,
1972,
63,
17565,
780,
275,
378,
272,
367,
18360,
315,
333,
14,
6979,
21000,
1252,
10417,
63,
955,
837,
267,
1827,
275,
791,
1972,
63,
8578,
363,
5,
83,
363,
685,
7,
450,
18360,
26,
488,
93,
267,
1967,
63,
1972,
63,
17565,
780,
847,
333,
14,
1899,
6979,
14,
1462,
3682,
1131,
680,
835,
342,
339,
1967,
63,
496,
771,
385,
269,
63,
17565,
780,
275,
378,
272,
367,
18360,
315,
333,
14,
919,
771,
385,
269,
21000,
1252,
10417,
63,
955,
837,
267,
1827,
275,
791,
496,
771,
385,
269,
63,
8578,
363,
5,
83,
363,
685,
7,
450,
18360,
26,
488,
93,
267,
1967,
63,
496,
771,
385,
269,
63,
17565,
780,
847,
333,
14,
1899,
6979,
14,
1462,
3682,
1131,
680,
835,
342,
339,
1894,
275,
1413,
342,
272,
367,
18360,
315,
333,
14,
6979,
21000,
1252,
10417,
63,
955,
837,
267,
1894,
8901,
1413,
3682,
1445,
1972,
63,
8578,
363,
5,
83,
363,
685,
7,
450,
18360,
26,
488,
1552,
272,
367,
18360,
315,
333,
14,
919,
771,
385,
269,
21000,
1252,
10417,
63,
955,
837,
267,
1894,
8901,
1413,
3682,
1445,
496,
771,
385,
269,
63,
8578,
363,
5,
83,
363,
685,
7,
450,
18360,
26,
488,
1552,
272,
1894,
8901,
1413,
8,
1972,
63,
8578,
363,
3349,
363,
685,
13275,
272,
1894,
8901,
1413,
8,
496,
771,
385,
269,
63,
8578,
363,
3349,
363,
685,
13275,
272,
27455,
63,
12601,
63,
8578,
379,
275,
333,
14,
1899,
6979,
14,
1462,
14,
1541,
8,
81,
9,
272,
1967,
63,
23880,
63,
12601,
63,
8578,
379,
275,
27455,
63,
12601,
63,
8578,
379,
14,
835,
342,
339,
327,
18146,
16223,
402,
1006,
63,
1972,
63,
1580,
436,
11248,
379,
63,
1972,
63,
1580,
2951,
315,
1930,
272,
519,
972,
63,
8578,
379,
63,
1972,
63,
1580,
275,
663,
8,
23880,
63,
12601,
63,
8578,
379,
14,
12926,
360,
1972,
63,
344,
1333,
272,
327,
3254,
8,
1064,
7856,
304,
7635,
626,
327,
334,
12601,
63,
8578,
379,
63,
1972,
63,
1580,
446,
1006,
63,
1972,
63,
1580,
9,
272,
327,
365,
2701,
272,
1967,
63,
11653,
63,
12601,
63,
8578,
379,
275,
822,
8,
12601,
63,
8578,
379,
63,
1972,
63,
1580,
9,
339,
327,
18146,
16223,
402,
1006,
63,
1972,
63,
1580,
436,
11248,
379,
63,
1972,
63,
1580,
2951,
315,
1930,
272,
519,
972,
63,
8578,
379,
63,
751,
63,
1580,
275,
663,
8,
23880,
63,
12601,
63,
8578,
379,
14,
12926,
360,
751,
63,
344,
1333,
272,
327,
3254,
8,
1064,
7856,
304,
7635,
626,
334,
12601,
63,
8578,
379,
63,
751,
63,
1580,
446,
1006,
63,
1972,
63,
1580,
9,
272,
327,
365,
2701,
272,
1967,
63,
3707,
63,
12601,
63,
8578,
379,
275,
822,
8,
12601,
63,
8578,
379,
63,
751,
63,
1580,
9,
339,
9456,
25297,
275,
2197,
14,
2131,
342,
446,
6871,
8,
8419,
29,
1194,
9,
272,
2070,
15203,
275,
4390,
63,
11806,
63,
4399,
8,
5066,
25297,
9,
339,
754,
275,
469,
267,
283,
1507,
63,
3707,
356,
1967,
63,
3707,
12,
267,
283,
1507,
63,
1037,
15203,
63,
8136,
356,
2070,
15203,
12,
267,
283,
1507,
63,
3707,
63,
1045,
63,
21656,
356,
1967,
63,
3707,
63,
1045,
63,
21656,
12,
267,
283,
1507,
63,
3707,
63,
1045,
63,
7211,
356,
1967,
63,
3707,
63,
1045,
63,
7211,
12,
267,
283,
1507,
63,
17565,
780,
356,
1967,
63,
1972,
63,
17565,
780,
435,
1967,
63,
496,
771,
385,
269,
63,
17565,
780,
12,
267,
283,
1507,
63,
24169,
356,
1967,
63,
1972,
63,
24169,
435,
1967,
63,
496,
771,
385,
269,
63,
24169,
12,
267,
283,
1507,
63,
23880,
356,
1967,
63,
23880,
12,
267,
283,
1507,
63,
23880,
63,
12601,
63,
8578,
379,
356,
1967,
63,
23880,
63,
12601,
63,
8578,
379,
12,
267,
283,
1507,
63,
11653,
356,
1967,
63,
11653,
12,
267,
283,
1507,
63,
11653,
63,
12601,
63,
8578,
379,
356,
1967,
63
] |
[
221,
29290,
29290,
10312,
6386,
1,
199,
3,
6006,
1159,
2005,
1233,
315,
642,
570,
626,
5920,
367,
3775,
282,
901,
965,
2757,
519,
972,
199,
3,
22743,
334,
5902,
14,
658,
692,
2518,
63,
8578,
14,
18700,
14963,
6121,
12,
2337,
1159,
7437,
11999,
1233,
199,
3,
626,
14404,
1006,
5767,
315,
282,
3245,
1901,
4402,
626,
1077,
506,
6702,
199,
3,
370,
13503,
9212,
14,
199,
3,
3254,
8,
983,
5017,
304,
12762,
1536,
642,
570,
436,
5325,
1006,
314,
10876,
14,
1910,
2270,
2066,
12,
8749,
506,
199,
3,
258,
336,
695,
402,
4052,
1265,
675,
14,
199,
3,
221,
29290,
29290,
10312,
6386,
1,
421,
199,
504,
5055,
492,
10018,
199,
504,
2197,
492,
2197,
12,
6871,
199,
504,
18006,
3908,
492,
1413,
199,
646,
7392,
199,
646,
519,
5466,
14,
992,
465,
333,
199,
646,
519,
5466,
14,
5555,
14,
1974,
465,
485,
1974,
199,
646,
984,
421,
199,
318,
14547,
63,
2083,
8,
3583,
304,
272,
372,
4487,
446,
6871,
8,
288,
10857,
29,
3583,
14,
5180,
12,
288,
9395,
29,
3583,
14,
10698,
12,
288,
4696,
29,
3583,
14,
4375,
12,
288,
21574,
29,
3583,
14,
16627,
9,
421,
199,
318,
7809,
63,
3200,
837,
272,
1967,
63,
23880,
275,
333,
14,
1899,
6979,
14,
1462,
1252,
835,
342,
339,
1967,
63,
3707,
275,
333,
14,
1899,
14,
1462,
14,
835,
342,
272,
1967,
63,
3707,
63,
1045,
63,
21656,
275,
333,
14,
1899,
14,
1462,
8,
288,
7115,
6429,
63,
17932,
363,
3308,
29,
16,
680,
835,
342,
272,
1967,
63,
3707,
63,
1045,
63,
7211,
275,
333,
14,
1899,
14,
1462,
8,
288,
8732,
83,
63,
17932,
363,
3308,
29,
16,
680,
835,
342,
339,
1967,
63,
1972,
63,
24169,
275,
333,
14,
1899,
6979,
14,
1462,
8,
288,
2518,
63,
8578,
363,
3349,
363,
685,
534,
1959,
835,
342,
272,
1967,
63,
496,
771,
385,
269,
63,
24169,
275,
333,
14,
1899,
6979,
14,
1462,
8,
288,
557,
771,
385,
269,
63,
8578,
363,
3349,
363,
685,
534,
1959,
835,
342,
339,
1967,
63,
11653,
275,
333,
14,
6979,
14,
1462,
14,
835,
342,
339,
327,
3254,
8,
983,
5017,
304,
4155,
18360,
63,
955,
282,
1021,
1083,
272,
1967,
63,
1972,
63,
17565,
780,
275,
378,
272,
367,
18360,
315,
333,
14,
6979,
21000,
1252,
10417,
63,
955,
837,
267,
1827,
275,
791,
1972,
63,
8578,
363,
5,
83,
363,
685,
7,
450,
18360,
26,
488,
93,
267,
1967,
63,
1972,
63,
17565,
780,
847,
333,
14,
1899,
6979,
14,
1462,
3682,
1131,
680,
835,
342,
339,
1967,
63,
496,
771,
385,
269,
63,
17565,
780,
275,
378,
272,
367,
18360,
315,
333,
14,
919,
771,
385,
269,
21000,
1252,
10417,
63,
955,
837,
267,
1827,
275,
791,
496,
771,
385,
269,
63,
8578,
363,
5,
83,
363,
685,
7,
450,
18360,
26,
488,
93,
267,
1967,
63,
496,
771,
385,
269,
63,
17565,
780,
847,
333,
14,
1899,
6979,
14,
1462,
3682,
1131,
680,
835,
342,
339,
1894,
275,
1413,
342,
272,
367,
18360,
315,
333,
14,
6979,
21000,
1252,
10417,
63,
955,
837,
267,
1894,
8901,
1413,
3682,
1445,
1972,
63,
8578,
363,
5,
83,
363,
685,
7,
450,
18360,
26,
488,
1552,
272,
367,
18360,
315,
333,
14,
919,
771,
385,
269,
21000,
1252,
10417,
63,
955,
837,
267,
1894,
8901,
1413,
3682,
1445,
496,
771,
385,
269,
63,
8578,
363,
5,
83,
363,
685,
7,
450,
18360,
26,
488,
1552,
272,
1894,
8901,
1413,
8,
1972,
63,
8578,
363,
3349,
363,
685,
13275,
272,
1894,
8901,
1413,
8,
496,
771,
385,
269,
63,
8578,
363,
3349,
363,
685,
13275,
272,
27455,
63,
12601,
63,
8578,
379,
275,
333,
14,
1899,
6979,
14,
1462,
14,
1541,
8,
81,
9,
272,
1967,
63,
23880,
63,
12601,
63,
8578,
379,
275,
27455,
63,
12601,
63,
8578,
379,
14,
835,
342,
339,
327,
18146,
16223,
402,
1006,
63,
1972,
63,
1580,
436,
11248,
379,
63,
1972,
63,
1580,
2951,
315,
1930,
272,
519,
972,
63,
8578,
379,
63,
1972,
63,
1580,
275,
663,
8,
23880,
63,
12601,
63,
8578,
379,
14,
12926,
360,
1972,
63,
344,
1333,
272,
327,
3254,
8,
1064,
7856,
304,
7635,
626,
327,
334,
12601,
63,
8578,
379,
63,
1972,
63,
1580,
446,
1006,
63,
1972,
63,
1580,
9,
272,
327,
365,
2701,
272,
1967,
63,
11653,
63,
12601,
63,
8578,
379,
275,
822,
8,
12601,
63,
8578,
379,
63,
1972,
63,
1580,
9,
339,
327,
18146,
16223,
402,
1006,
63,
1972,
63,
1580,
436,
11248,
379,
63,
1972,
63,
1580,
2951,
315,
1930,
272,
519,
972,
63,
8578,
379,
63,
751,
63,
1580,
275,
663,
8,
23880,
63,
12601,
63,
8578,
379,
14,
12926,
360,
751,
63,
344,
1333,
272,
327,
3254,
8,
1064,
7856,
304,
7635,
626,
334,
12601,
63,
8578,
379,
63,
751,
63,
1580,
446,
1006,
63,
1972,
63,
1580,
9,
272,
327,
365,
2701,
272,
1967,
63,
3707,
63,
12601,
63,
8578,
379,
275,
822,
8,
12601,
63,
8578,
379,
63,
751,
63,
1580,
9,
339,
9456,
25297,
275,
2197,
14,
2131,
342,
446,
6871,
8,
8419,
29,
1194,
9,
272,
2070,
15203,
275,
4390,
63,
11806,
63,
4399,
8,
5066,
25297,
9,
339,
754,
275,
469,
267,
283,
1507,
63,
3707,
356,
1967,
63,
3707,
12,
267,
283,
1507,
63,
1037,
15203,
63,
8136,
356,
2070,
15203,
12,
267,
283,
1507,
63,
3707,
63,
1045,
63,
21656,
356,
1967,
63,
3707,
63,
1045,
63,
21656,
12,
267,
283,
1507,
63,
3707,
63,
1045,
63,
7211,
356,
1967,
63,
3707,
63,
1045,
63,
7211,
12,
267,
283,
1507,
63,
17565,
780,
356,
1967,
63,
1972,
63,
17565,
780,
435,
1967,
63,
496,
771,
385,
269,
63,
17565,
780,
12,
267,
283,
1507,
63,
24169,
356,
1967,
63,
1972,
63,
24169,
435,
1967,
63,
496,
771,
385,
269,
63,
24169,
12,
267,
283,
1507,
63,
23880,
356,
1967,
63,
23880,
12,
267,
283,
1507,
63,
23880,
63,
12601,
63,
8578,
379,
356,
1967,
63,
23880,
63,
12601,
63,
8578,
379,
12,
267,
283,
1507,
63,
11653,
356,
1967,
63,
11653,
12,
267,
283,
1507,
63,
11653,
63,
12601,
63,
8578,
379,
356,
1967,
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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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
] |
aarose/togglwrapper
|
tests.py
|
1
|
26969
|
# -*- coding: utf-8 -*-
"""
tests
-----
Ensures that certain actions in the togglwrapper library result in certain
behaviours.
Uses the responses library to mock out the requests library, and loads fixtures
from ``fixtures/`` for the mock JSON response output.
"""
import json
import os
import unittest
import responses
from requests.exceptions import HTTPError
from togglwrapper import api
from togglwrapper.exceptions import AuthError
FAKE_TOKEN = 'fake_token_1'
FIXTURES_PATH = '%s/fixtures' % os.path.dirname(os.path.abspath(__file__))
class TestTogglBase(unittest.TestCase):
""" Class to establish utility methods for Test classes. """
api_token = FAKE_TOKEN
focus_class = None
def compile_full_url(self, id=None, ids=None, child_uri=None):
""" Compile a full URL from the base url. """
focus_class = self.focus_class
uri = focus_class._compile_uri(id=id, ids=ids, child_uri=child_uri)
return self.toggl.api_url + uri
def setUp(self):
self.toggl = api.Toggl(self.api_token)
def get_json(self, filename):
""" Return the JSON data in the .json file with the given filename. """
file_path = '{path}/{filename}.json'.format(path=FIXTURES_PATH,
filename=filename)
with open(file_path) as json_file:
json_dict = json.load(json_file)
json_file.close()
raw_json = json.dumps(json_dict)
return raw_json
def responses_add(self, method, filename=None, id=None, ids=None,
child_uri=None, status_code=200, content_type=''):
""" Adds a mock response for requests to a certain url. """
body = None
if filename is not None:
body = self.get_json(filename)
content_type = 'application/json'
responses.add(
getattr(responses, method),
self.compile_full_url(id=id, ids=ids, child_uri=child_uri),
body=body,
status=status_code,
content_type=content_type
)
class TestToggl(TestTogglBase):
""" Tests the main Toggl client Class. """
@responses.activate
def test_wrong_token(self):
""" Should raise exception when wrong API token is provided. """
full_url = self.toggl.api_url + self.toggl.User.uri
responses.add(responses.GET, full_url, status=403)
self.assertRaises(AuthError, self.toggl.User.get)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_failed_request(self):
""" Should raise an HTTPError with status code 404. """
full_url = self.toggl.api_url + self.toggl.TimeEntries.uri
responses.add(
responses.POST,
full_url,
body=self.get_json('failed_request'),
status=404,
)
wrong_data = {"time_entry": {
"description": "New time entry",
"created_with": "API example code"
}}
self.assertRaises(HTTPError, self.toggl.TimeEntries.create,
data=wrong_data)
# Ensure that the error message in the response is the exception reason
reason = json.loads(self.get_json('failed_request'))
try:
self.toggl.TimeEntries.create(data=wrong_data)
except HTTPError as e:
self.assertEqual(e.response.reason, reason)
else:
raise Exception('Reason was not correct.')
# Ensure that the mocked response was triggered twice
self.assertEqual(len(responses.calls), 2)
class TestClients(TestTogglBase):
focus_class = api.Clients
@responses.activate
def test_create(self):
""" Should create a new Client. """
self.responses_add('POST', filename='client_create')
create_data = {"client": {"name": "Very Big Company", "wid": 777}}
response = self.toggl.Clients.create(create_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_by_id(self):
""" Should get a specific Client by ID. """
inst_id = 1239455
self.responses_add('GET', filename='client_get', id=inst_id)
response = self.toggl.Clients.get(id=inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get(self):
""" Should get all Clients. """
self.responses_add('GET', filename='clients_get')
response = self.toggl.Clients.get()
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
""" Should update a Client. """
inst_id = 1239455
self.responses_add('PUT', filename='client_update', id=inst_id)
update_data = {
"client": {
"name": "Very Big Company",
"notes": "something about the client"
}
}
response = self.toggl.Clients.update(id=inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
""" Should delete a Client. """
inst_id = 1239455
self.responses_add('DELETE', id=inst_id)
response = self.toggl.Clients.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_projects_get(self):
""" Should get all active projects under the Client. """
inst_id = 1239455
self.responses_add(
'GET',
filename='client_projects_get',
id=inst_id,
child_uri='/projects'
)
response = self.toggl.Clients.get_projects(inst_id)
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
class TestDashboard(TestTogglBase):
focus_class = api.Dashboard
@responses.activate
def test_get(self):
""" Should get the dashboard info for a given Workspace. """
inst_id = 3134975
self.responses_add('GET', filename='dashboard', id=inst_id)
response = self.toggl.Dashboard.get(inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
class TestProjects(TestTogglBase):
focus_class = api.Projects
@responses.activate
def test_create(self):
""" Should create a new Project. """
self.responses_add('POST', filename='project_create')
project_data = {"project": {
"name": "An awesome project",
"wid": 777,
"template_id": 10237,
"is_private": True,
"cid": 123397
}}
response = self.toggl.Projects.create(project_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_by_id(self):
""" Should get a specific Project by ID. """
inst_id = 193838628
self.responses_add('GET', filename='project_get', id=inst_id)
response = self.toggl.Projects.get(inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
""" Should update a Project. """
inst_id = 193838628
self.responses_add('PUT', filename='project_update', id=inst_id)
update_data = {"project": {
"name": "Changed the name",
"is_private": False,
"cid": 123398,
"color": "6"
}}
response = self.toggl.Projects.update(id=inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
""" Should delete a Project. """
inst_id = 4692190
self.responses_add('DELETE', id=inst_id)
response = self.toggl.Projects.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_mass_delete(self):
""" Should delete multiple Projects. """
ids = [4692190, 4692192, 4692193]
self.responses_add('DELETE', ids=ids)
response = self.toggl.Projects.delete(ids=ids)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_project_users_get(self):
""" Should get Project Users under the Project. """
inst_id = 193838628
fixture_name = 'project_projectusers_get'
self.responses_add(
'GET',
filename=fixture_name,
id=inst_id,
child_uri='/project_users'
)
response = self.toggl.Projects.get_project_users(inst_id)
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_tasks_get(self):
""" Should get Tasks under the Project. """
inst_id = 777
self.responses_add(
'GET',
filename='project_tasks_get',
id=inst_id,
child_uri='/tasks'
)
response = self.toggl.Projects.get_tasks(inst_id)
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
class TestProjectUsers(TestTogglBase):
focus_class = api.ProjectUsers
@responses.activate
def test_create(self):
""" Should create a new ProjectUser. """
self.responses_add('POST', filename='projectuser_create')
create_data = {
"project_user": {
"pid": 777,
"uid": 123,
"rate": 4.0,
"manager": True
}
}
response = self.toggl.ProjectUsers.create(create_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
""" Should update a ProjectUser. """
inst_id = 4692190
self.responses_add('PUT', filename='projectuser_update', id=inst_id)
update_data = {
"project_user": {
"manager": False,
"rate": 15,
"fields": "fullname"
}
}
response = self.toggl.ProjectUsers.update(id=inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
""" Should delete a ProjectUser. """
inst_id = 4692190
self.responses_add('DELETE', id=inst_id)
response = self.toggl.ProjectUsers.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_mass_create(self):
""" Should create multiple new ProjectUsers. """
self.responses_add('POST', 'projectusers_create_multiple')
create_data = {"project_user": {
"pid": 777,
"uid": "1267998,29624,112047",
"rate": 4.0,
"manager": True,
"fields": "fullname"
}}
response = self.toggl.ProjectUsers.create(create_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_mass_update(self):
""" Should update multiple ProjectUsers. """
ids = (4692190, 4692192, 4692191)
self.responses_add('PUT', 'projectusers_update_multiple', ids=ids)
update_data = {
"project_user": {
"manager": False,
"rate": 15,
"fields": "fullname"
}
}
response = self.toggl.ProjectUsers.update(ids=ids, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_mass_delete(self):
""" Should delete multiple ProjectUsers. """
ids = (4692190, 4692192, 4692193)
self.responses_add('DELETE', ids=ids)
response = self.toggl.ProjectUsers.delete(ids=ids)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
class TestTags(TestTogglBase):
focus_class = api.Tags
@responses.activate
def test_create(self):
""" Should create a new Tag. """
self.responses_add('POST', filename='tag_create')
create_data = {"tag": {"name": "billed", "wid": 777}}
response = self.toggl.Tags.create(create_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
""" Should update a Tag. """
inst_id = 1239455
self.responses_add('PUT', filename='tag_update', id=inst_id)
update_data = {"tag": {"name": "not billed"}}
response = self.toggl.Tags.update(id=inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
""" Should delete a Tag. """
inst_id = 1239455
self.responses_add('DELETE', id=inst_id)
response = self.toggl.Tags.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
class TestTasks(TestTogglBase):
focus_class = api.Tasks
@responses.activate
def test_create(self):
""" Should create a new Task. """
self.responses_add('POST', filename='task_create')
create_data = {"task": {"name": "A new task", "pid": 777}}
response = self.toggl.Tasks.create(create_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_by_id(self):
""" Should get a Task. """
inst_id = 1335076912
self.responses_add('GET', filename='task_get', id=inst_id)
response = self.toggl.Tasks.get(inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
""" Should update a Task. """
inst_id = 1335076912
self.responses_add('PUT', filename='task_update', id=inst_id)
update_data = {
"task": {
"active": False,
"estimated_seconds": 3600,
"fields": "done_seconds,uname"
}
}
response = self.toggl.Tasks.update(id=inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
""" Should delete a Task. """
inst_id = 1335076912
self.responses_add('DELETE', id=inst_id)
response = self.toggl.Tasks.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_mass_update(self):
""" Should update multiple Tasks. """
ids = (1335076912, 1335076911)
self.responses_add('PUT', 'projectusers_update_multiple', ids=ids)
update_data = {"task": {
"active": False,
"fields": "done_seconds,uname"
}}
response = self.toggl.Tasks.update(ids=ids, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_mass_delete(self):
""" Should delete multiple Tasks. """
ids = (1335076912, 1335076911, 1335076910)
self.responses_add('DELETE', ids=ids)
response = self.toggl.Tasks.delete(ids=ids)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
class TestTimeEntries(TestTogglBase):
focus_class = api.TimeEntries
@responses.activate
def test_create(self):
""" Should create a new TimeEntry. """
self.responses_add('POST', filename='time_entry_create')
create_data = {"time_entry": {
"description": "Meeting with possible clients",
"tags": ["billed"],
"duration": 1200,
"start": "2013-03-05T07:58:58.000Z",
"pid": 123,
"created_with": "togglwrapper"
}}
response = self.toggl.TimeEntries.create(create_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_start(self):
""" Should start a TimeEntry. """
self.responses_add('POST', 'time_entry_start', child_uri='/start')
start_data = {"time_entry": {
"description": "Meeting with possible clients",
"tags": ["billed"],
"pid": 123,
"created_with": "togglwrapper"
}}
response = self.toggl.TimeEntries.start(start_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_stop(self):
""" Should stop a TimeEntry. """
inst_id = 436694100
self.responses_add(
'PUT',
filename='time_entry_stop',
id=inst_id,
child_uri='/stop'
)
response = self.toggl.TimeEntries.stop(inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_by_id(self):
""" Should get a TimeEntry. """
inst_id = 436694100
self.responses_add('GET', filename='time_entry_get', id=inst_id)
response = self.toggl.TimeEntries.get(id=inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_current(self):
""" Should get the current running TimeEntry. """
self.responses_add('GET', 'time_entry_current', child_uri='/current')
response = self.toggl.TimeEntries.get_current()
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_in_time_range(self):
""" Should get the TimeEntries started in a specific time range. """
self.responses_add('GET', filename='time_entries_get_in_range')
response = self.toggl.TimeEntries.get(
start_date='2013-03-10T15:42:46+02:00',
end_date='2013-03-12T15:42:46+02:00'
)
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
""" Should update a TimeEntry. """
inst_id = 436694100
self.responses_add('PUT', filename='time_entry_update', id=inst_id)
update_data = {"time_entry": {
"description": "Meeting with possible clients",
"tags": [""],
"duration": 1240,
"start": "2013-03-05T07:58:58.000Z",
"stop": "2013-03-05T08:58:58.000Z",
"duronly": True,
"pid": 123,
"billable": True
}}
response = self.toggl.TimeEntries.update(id=inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
""" Should delete a TimeEntry. """
inst_id = 1239455
self.responses_add('DELETE', id=inst_id)
response = self.toggl.TimeEntries.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_mass_update(self):
""" Should update multiple TimeEntries. """
ids = (436694100, 436694101)
self.responses_add('PUT', 'projectusers_update_multiple', ids=ids)
update_data = {"time_entry": {
"tags": ["billed", "productive"],
"tag_action": "add"
}}
response = self.toggl.TimeEntries.update(ids=ids, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
class TestUser(TestTogglBase):
focus_class = api.User
@responses.activate
def test_get(self):
""" Should successfully get the User associated with the token. """
self.responses_add('GET', filename='user_get')
response = self.toggl.User.get()
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_with_related_data(self):
""" Should get the User associated with the token and related data. """
self.responses_add('GET', filename='user_get_with_related_data')
response = self.toggl.User.get(related_data=True)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
""" Should update the User associated with the api token. """
self.responses_add('PUT', filename='user_update')
update_data = {"user": {"fullname": "John Smith"}}
response = self.toggl.User.update(update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
class TestWorkspaces(TestTogglBase):
focus_class = api.Workspaces
@responses.activate
def test_get(self):
""" Should successfully get an iterable of Workspaces. """
self.responses_add('GET', filename='workspaces_get')
response = self.toggl.Workspaces.get()
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_get_by_id(self):
""" Should successfully get a specific Workspace. """
inst_id = 3134975
self.responses_add('GET', filename='workspace_get', id=inst_id)
response = self.toggl.Workspaces.get(id=inst_id)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_update(self):
""" Should update a specific Workspace. """
inst_id = 3134975
self.responses_add('PUT', filename='workspace_update', id=inst_id)
update_data = {"workspace": {
"default_currency": "EUR",
"default_hourly_rate": 50,
"name": "John's ws",
"only_admins_may_create_projects": False,
"only_admins_see_billable_rates": True,
"rounding": 1,
"rounding_minutes": 60
}}
response = self.toggl.Workspaces.update(id=inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_users_get(self):
""" Should get Users under the Workspace. """
inst_id = 777
self.responses_add('GET', filename='workspace_users', id=inst_id,
child_uri='/users')
response = self.toggl.Workspaces.get_users(inst_id)
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_clients_get(self):
""" Should get Clients under the Workspace. """
inst_id = 777
self.responses_add('GET', filename='workspace_clients', id=inst_id,
child_uri='/clients')
response = self.toggl.Workspaces.get_clients(inst_id)
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_projects_get(self):
""" Should get Projects under the Workspace. """
inst_id = 777
self.responses_add('GET', 'workspace_projects', id=inst_id,
child_uri='/projects')
response = self.toggl.Workspaces.get_projects(inst_id)
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_tasks_get(self):
""" Should get Tasks under the Workspace. """
inst_id = 777
self.responses_add('GET', 'workspace_tasks', id=inst_id,
child_uri='/tasks')
response = self.toggl.Workspaces.get_tasks(inst_id)
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_tags_get(self):
""" Should get Tags under the Workspace. """
inst_id = 777
self.responses_add('GET', 'workspace_tags', id=inst_id,
child_uri='/tags')
response = self.toggl.Workspaces.get_tags(inst_id)
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_workspace_users_get(self):
""" Should get WorkspaceUsers under the Workspace. """
inst_id = 777
self.responses_add('GET', 'workspace_workspaceusers', id=inst_id,
child_uri='/workspace_users')
response = self.toggl.Workspaces.get_workspace_users(inst_id)
self.assertEqual(type(response), list)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_invite(self):
""" Should invite users to the given Workspace. """
inst_id = 777
self.responses_add('POST', 'workspace_invite', id=inst_id,
child_uri='/invite')
data = {"emails": ["john.doe@toggl.com", "Jane.Swift@toggl.com"]}
response = self.toggl.Workspaces.invite(inst_id, data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
class TestWorkspaceUsers(TestTogglBase):
focus_class = api.WorkspaceUsers
@responses.activate
def test_update(self):
""" Should update a specific WorkspaceUser. """
inst_id = 19012628
self.responses_add('PUT', filename='workspaceuser_update', id=inst_id)
update_data = {"workspace_user": {"admin": False}}
response = self.toggl.WorkspaceUsers.update(inst_id, data=update_data)
self.assertEqual(type(response), dict)
self.assertEqual(len(responses.calls), 1)
@responses.activate
def test_delete(self):
""" Should delete a specific WorkspaceUser. """
inst_id = 19012628
self.responses_add('DELETE', id=inst_id)
response = self.toggl.WorkspaceUsers.delete(inst_id)
self.assertTrue(response.ok)
self.assertEqual(len(responses.calls), 1)
if __name__ == '__main__' and __package__ is None:
__package__ = "toggl"
unittest.main()
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
2219,
199,
9858,
199,
199,
37,
561,
1482,
626,
9842,
5445,
315,
314,
370,
2721,
76,
5029,
3555,
754,
315,
9842,
199,
1235,
4425,
16363,
14,
199,
199,
21896,
314,
9320,
3555,
370,
1683,
734,
314,
4145,
3555,
12,
436,
14404,
15188,
199,
504,
1124,
8769,
15,
1040,
367,
314,
1683,
4840,
1177,
1072,
14,
199,
624,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
2882,
199,
199,
646,
9320,
199,
504,
4145,
14,
3924,
492,
15050,
421,
199,
504,
370,
2721,
76,
5029,
492,
2986,
199,
504,
370,
2721,
76,
5029,
14,
3924,
492,
3590,
547,
421,
199,
14623,
63,
8803,
275,
283,
3183,
63,
1418,
63,
17,
7,
199,
5192,
52,
10799,
63,
3243,
275,
1543,
83,
15,
8769,
7,
450,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
421,
199,
533,
1379,
52,
974,
3528,
1563,
8,
2796,
14,
1746,
304,
272,
408,
8089,
370,
16873,
11420,
3102,
367,
1379,
3992,
14,
408,
339,
2986,
63,
1418,
275,
25699,
63,
8803,
272,
16470,
63,
533,
275,
488,
339,
347,
6555,
63,
2861,
63,
633,
8,
277,
12,
1305,
29,
403,
12,
2762,
29,
403,
12,
1982,
63,
2302,
29,
403,
304,
267,
408,
24562,
282,
2615,
2851,
687,
314,
1300,
1166,
14,
408,
267,
16470,
63,
533,
275,
291,
14,
12283,
63,
533,
267,
5108,
275,
16470,
63,
533,
423,
2014,
63,
2302,
8,
344,
29,
344,
12,
2762,
29,
1580,
12,
1982,
63,
2302,
29,
1739,
63,
2302,
9,
267,
372,
291,
14,
475,
2721,
76,
14,
1246,
63,
633,
435,
5108,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
475,
2721,
76,
275,
2986,
14,
52,
974,
3528,
8,
277,
14,
1246,
63,
1418,
9,
339,
347,
664,
63,
1001,
8,
277,
12,
1788,
304,
267,
408,
1432,
314,
4840,
666,
315,
314,
1275,
1001,
570,
543,
314,
1627,
1788,
14,
408,
267,
570,
63,
515,
275,
5041,
515,
16152,
1501,
5565,
1001,
1370,
908,
8,
515,
29,
5192,
52,
10799,
63,
3243,
12,
8105,
1788,
29,
1501,
9,
267,
543,
1551,
8,
493,
63,
515,
9,
465,
2022,
63,
493,
26,
288,
2022,
63,
807,
275,
2022,
14,
912,
8,
1001,
63,
493,
9,
288,
2022,
63,
493,
14,
1600,
342,
267,
3066,
63,
1001,
275,
2022,
14,
4180,
8,
1001,
63,
807,
9,
267,
372,
3066,
63,
1001,
339,
347,
9320,
63,
525,
8,
277,
12,
1083,
12,
1788,
29,
403,
12,
1305,
29,
403,
12,
2762,
29,
403,
12,
1993,
1982,
63,
2302,
29,
403,
12,
2004,
63,
600,
29,
1840,
12,
1564,
63,
466,
9280,
267,
408,
15747,
282,
1683,
1177,
367,
4145,
370,
282,
9842,
1166,
14,
408,
267,
2396,
275,
488,
267,
340,
1788,
365,
440,
488,
26,
288,
2396,
275,
291,
14,
362,
63,
1001,
8,
1501,
9,
288,
1564,
63,
466,
275,
283,
3578,
15,
1001,
7,
398,
9320,
14,
525,
8,
288,
2519,
8,
10360,
12,
1083,
395,
288,
291,
14,
2014,
63,
2861,
63,
633,
8,
344,
29,
344,
12,
2762,
29,
1580,
12,
1982,
63,
2302,
29,
1739,
63,
2302,
395,
288,
2396,
29,
2030,
12,
288,
2004,
29,
1205,
63,
600,
12,
288,
1564,
63,
466,
29,
1317,
63,
466,
267,
776,
421,
199,
533,
1379,
52,
974,
3528,
8,
774,
52,
974,
3528,
1563,
304,
272,
408,
6496,
314,
2446,
377,
974,
3528,
1890,
8089,
14,
408,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
10603,
63,
1418,
8,
277,
304,
267,
408,
7719,
746,
1919,
1380,
6835,
3261,
1526,
365,
2741,
14,
408,
267,
2615,
63,
633,
275,
291,
14,
475,
2721,
76,
14,
1246,
63,
633,
435,
291,
14,
475,
2721,
76,
14,
1899,
14,
2302,
267,
9320,
14,
525,
8,
10360,
14,
2970,
12,
2615,
63,
633,
12,
2004,
29,
13353,
9,
267,
291,
14,
1855,
8,
2817,
547,
12,
291,
14,
475,
2721,
76,
14,
1899,
14,
362,
9,
267,
291,
14,
629,
8,
552,
8,
10360,
14,
5352,
395,
413,
9,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
4892,
63,
1069,
8,
277,
304,
267,
408,
7719,
746,
376,
15050,
543,
2004,
1233,
7901,
14,
408,
267,
2615,
63,
633,
275,
291,
14,
475,
2721,
76,
14,
1246,
63,
633,
435,
291,
14,
475,
2721,
76,
14,
1366,
17816,
14,
2302,
267,
9320,
14,
525,
8,
288,
9320,
14,
4030,
12,
288,
2615,
63,
633,
12,
288,
2396,
29,
277,
14,
362,
63,
1001,
360,
4892,
63,
1069,
659,
288,
2004,
29,
5188,
12,
267,
776,
267,
6835,
63,
576,
275,
2420,
521,
63,
2373,
582,
469,
288,
298,
1802,
582,
298,
4665,
900,
2397,
401,
288,
298,
3966,
63,
1045,
582,
298,
3735,
2893,
1233,
2,
267,
3586,
267,
291,
14,
1855,
8,
12815,
12,
291,
14,
475,
2721,
76,
14,
1366,
17816,
14,
981,
12,
2079,
666,
29,
10603,
63,
576,
9,
267,
327,
7523,
626,
314,
1125,
1245,
315,
314,
1177,
365,
314,
1919,
4499,
267,
4499,
275,
2022,
14,
3640,
8,
277,
14,
362,
63,
1001,
360,
4892,
63,
1069,
1333,
267,
862,
26,
288,
291,
14,
475,
2721,
76,
14,
1366,
17816,
14,
981,
8,
576,
29,
10603,
63,
576,
9,
267,
871,
15050,
465,
325,
26,
288,
291,
14,
629,
8,
69,
14,
1310,
14,
5764,
12,
4499,
9,
267,
587,
26,
288,
746,
2186,
360,
16148,
1990,
440,
3211,
2659,
398,
327,
7523,
626,
314,
16991,
1177,
1990,
15572,
13373,
267,
291,
14,
629,
8,
552,
8,
10360,
14,
5352,
395,
499,
9,
421,
199,
533,
1379,
3041,
83,
8,
774,
52,
974,
3528,
1563,
304,
272,
16470,
63,
533,
275,
2986,
14,
3041,
83,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
981,
8,
277,
304,
267,
408,
7719,
1218,
282,
892,
6810,
14,
408,
267,
291,
14,
10360,
63,
525,
360,
4030,
297,
1788,
534,
1258,
63,
981,
358,
267,
1218,
63,
576,
275,
2420,
1258,
582,
2420,
354,
582,
298,
54,
994,
13123,
15878,
401,
298,
19686,
582,
8375,
23,
4863,
267,
1177,
275,
291,
14,
475,
2721,
76,
14,
3041,
83,
14,
981,
8,
981,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
624,
199,
2219,
199,
9858,
199,
199,
37,
561,
1482,
626,
9842,
5445,
315,
314,
370,
2721,
76,
5029,
3555,
754,
315,
9842,
199,
1235,
4425,
16363,
14,
199,
199,
21896,
314,
9320,
3555,
370,
1683,
734,
314,
4145,
3555,
12,
436,
14404,
15188,
199,
504,
1124,
8769,
15,
1040,
367,
314,
1683,
4840,
1177,
1072,
14,
199,
624,
199,
199,
646,
2022,
199,
646,
747,
199,
646,
2882,
199,
199,
646,
9320,
199,
504,
4145,
14,
3924,
492,
15050,
421,
199,
504,
370,
2721,
76,
5029,
492,
2986,
199,
504,
370,
2721,
76,
5029,
14,
3924,
492,
3590,
547,
421,
199,
14623,
63,
8803,
275,
283,
3183,
63,
1418,
63,
17,
7,
199,
5192,
52,
10799,
63,
3243,
275,
1543,
83,
15,
8769,
7,
450,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
4832,
3460,
493,
8964,
421,
199,
533,
1379,
52,
974,
3528,
1563,
8,
2796,
14,
1746,
304,
272,
408,
8089,
370,
16873,
11420,
3102,
367,
1379,
3992,
14,
408,
339,
2986,
63,
1418,
275,
25699,
63,
8803,
272,
16470,
63,
533,
275,
488,
339,
347,
6555,
63,
2861,
63,
633,
8,
277,
12,
1305,
29,
403,
12,
2762,
29,
403,
12,
1982,
63,
2302,
29,
403,
304,
267,
408,
24562,
282,
2615,
2851,
687,
314,
1300,
1166,
14,
408,
267,
16470,
63,
533,
275,
291,
14,
12283,
63,
533,
267,
5108,
275,
16470,
63,
533,
423,
2014,
63,
2302,
8,
344,
29,
344,
12,
2762,
29,
1580,
12,
1982,
63,
2302,
29,
1739,
63,
2302,
9,
267,
372,
291,
14,
475,
2721,
76,
14,
1246,
63,
633,
435,
5108,
339,
347,
3613,
8,
277,
304,
267,
291,
14,
475,
2721,
76,
275,
2986,
14,
52,
974,
3528,
8,
277,
14,
1246,
63,
1418,
9,
339,
347,
664,
63,
1001,
8,
277,
12,
1788,
304,
267,
408,
1432,
314,
4840,
666,
315,
314,
1275,
1001,
570,
543,
314,
1627,
1788,
14,
408,
267,
570,
63,
515,
275,
5041,
515,
16152,
1501,
5565,
1001,
1370,
908,
8,
515,
29,
5192,
52,
10799,
63,
3243,
12,
8105,
1788,
29,
1501,
9,
267,
543,
1551,
8,
493,
63,
515,
9,
465,
2022,
63,
493,
26,
288,
2022,
63,
807,
275,
2022,
14,
912,
8,
1001,
63,
493,
9,
288,
2022,
63,
493,
14,
1600,
342,
267,
3066,
63,
1001,
275,
2022,
14,
4180,
8,
1001,
63,
807,
9,
267,
372,
3066,
63,
1001,
339,
347,
9320,
63,
525,
8,
277,
12,
1083,
12,
1788,
29,
403,
12,
1305,
29,
403,
12,
2762,
29,
403,
12,
1993,
1982,
63,
2302,
29,
403,
12,
2004,
63,
600,
29,
1840,
12,
1564,
63,
466,
9280,
267,
408,
15747,
282,
1683,
1177,
367,
4145,
370,
282,
9842,
1166,
14,
408,
267,
2396,
275,
488,
267,
340,
1788,
365,
440,
488,
26,
288,
2396,
275,
291,
14,
362,
63,
1001,
8,
1501,
9,
288,
1564,
63,
466,
275,
283,
3578,
15,
1001,
7,
398,
9320,
14,
525,
8,
288,
2519,
8,
10360,
12,
1083,
395,
288,
291,
14,
2014,
63,
2861,
63,
633,
8,
344,
29,
344,
12,
2762,
29,
1580,
12,
1982,
63,
2302,
29,
1739,
63,
2302,
395,
288,
2396,
29,
2030,
12,
288,
2004,
29,
1205,
63,
600,
12,
288,
1564,
63,
466,
29,
1317,
63,
466,
267,
776,
421,
199,
533,
1379,
52,
974,
3528,
8,
774,
52,
974,
3528,
1563,
304,
272,
408,
6496,
314,
2446,
377,
974,
3528,
1890,
8089,
14,
408,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
10603,
63,
1418,
8,
277,
304,
267,
408,
7719,
746,
1919,
1380,
6835,
3261,
1526,
365,
2741,
14,
408,
267,
2615,
63,
633,
275,
291,
14,
475,
2721,
76,
14,
1246,
63,
633,
435,
291,
14,
475,
2721,
76,
14,
1899,
14,
2302,
267,
9320,
14,
525,
8,
10360,
14,
2970,
12,
2615,
63,
633,
12,
2004,
29,
13353,
9,
267,
291,
14,
1855,
8,
2817,
547,
12,
291,
14,
475,
2721,
76,
14,
1899,
14,
362,
9,
267,
291,
14,
629,
8,
552,
8,
10360,
14,
5352,
395,
413,
9,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
4892,
63,
1069,
8,
277,
304,
267,
408,
7719,
746,
376,
15050,
543,
2004,
1233,
7901,
14,
408,
267,
2615,
63,
633,
275,
291,
14,
475,
2721,
76,
14,
1246,
63,
633,
435,
291,
14,
475,
2721,
76,
14,
1366,
17816,
14,
2302,
267,
9320,
14,
525,
8,
288,
9320,
14,
4030,
12,
288,
2615,
63,
633,
12,
288,
2396,
29,
277,
14,
362,
63,
1001,
360,
4892,
63,
1069,
659,
288,
2004,
29,
5188,
12,
267,
776,
267,
6835,
63,
576,
275,
2420,
521,
63,
2373,
582,
469,
288,
298,
1802,
582,
298,
4665,
900,
2397,
401,
288,
298,
3966,
63,
1045,
582,
298,
3735,
2893,
1233,
2,
267,
3586,
267,
291,
14,
1855,
8,
12815,
12,
291,
14,
475,
2721,
76,
14,
1366,
17816,
14,
981,
12,
2079,
666,
29,
10603,
63,
576,
9,
267,
327,
7523,
626,
314,
1125,
1245,
315,
314,
1177,
365,
314,
1919,
4499,
267,
4499,
275,
2022,
14,
3640,
8,
277,
14,
362,
63,
1001,
360,
4892,
63,
1069,
1333,
267,
862,
26,
288,
291,
14,
475,
2721,
76,
14,
1366,
17816,
14,
981,
8,
576,
29,
10603,
63,
576,
9,
267,
871,
15050,
465,
325,
26,
288,
291,
14,
629,
8,
69,
14,
1310,
14,
5764,
12,
4499,
9,
267,
587,
26,
288,
746,
2186,
360,
16148,
1990,
440,
3211,
2659,
398,
327,
7523,
626,
314,
16991,
1177,
1990,
15572,
13373,
267,
291,
14,
629,
8,
552,
8,
10360,
14,
5352,
395,
499,
9,
421,
199,
533,
1379,
3041,
83,
8,
774,
52,
974,
3528,
1563,
304,
272,
16470,
63,
533,
275,
2986,
14,
3041,
83,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
981,
8,
277,
304,
267,
408,
7719,
1218,
282,
892,
6810,
14,
408,
267,
291,
14,
10360,
63,
525,
360,
4030,
297,
1788,
534,
1258,
63,
981,
358,
267,
1218,
63,
576,
275,
2420,
1258,
582,
2420,
354,
582,
298,
54,
994,
13123,
15878,
401,
298,
19686,
582,
8375,
23,
4863,
267,
1177,
275,
291,
14,
475,
2721,
76,
14,
3041,
83,
14,
981,
8,
981,
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,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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
] |
40223102/w16b_test
|
static/Brython3.1.1-20150328-091302/Lib/browser/markdown.py
|
623
|
13060
|
# -*- coding: utf-8 -*-
try:
import _jsre as re
except:
import re
import random
import time
letters = 'abcdefghijklmnopqrstuvwxyz'
letters += letters.upper()+'0123456789'
class URL:
def __init__(self,src):
elts = src.split(maxsplit=1)
self.href = elts[0]
self.alt = ''
if len(elts)==2:
alt = elts[1]
if alt[0]=='"' and alt[-1]=='"':self.alt=alt[1:-1]
elif alt[0]=="'" and alt[-1]=="'":self.alt=alt[1:-1]
elif alt[0]=="(" and alt[-1]==")":self.alt=alt[1:-1]
class CodeBlock:
def __init__(self,line):
self.lines = [line]
if line.startswith("```") and len(line)>3:
self.info = line[3:]
else:
self.info = None
def to_html(self):
if self.lines[0].startswith("`"):
self.lines.pop(0)
res = escape('\n'.join(self.lines))
res = unmark(res)
_class = self.info or "marked"
res = '<pre class="%s">%s</pre>\n' %(_class, res)
return res,[]
class HtmlBlock:
def __init__(self, src):
self.src = src
def to_html(self):
return self.src
class Marked:
def __init__(self, line=''):
self.line = line
self.children = []
def to_html(self):
return apply_markdown(self.line)
# get references
refs = {}
ref_pattern = r"^\[(.*)\]:\s+(.*)"
def mark(src):
global refs
t0 = time.time()
refs = {}
# split source in sections
# sections can be :
# - a block-level HTML element (markdown syntax will not be processed)
# - a script
# - a span-level HTML tag (markdown syntax will be processed)
# - a code block
# normalise line feeds
src = src.replace('\r\n','\n')
# lines followed by dashes
src = re.sub(r'(.*?)\n=+\n', '\n# \\1\n', src)
src = re.sub(r'(.*?)\n-+\n', '\n## \\1\n', src)
lines = src.split('\n')+['']
i = bq = 0
ul = ol = 0
while i<len(lines):
# enclose lines starting by > in a blockquote
if lines[i].startswith('>'):
nb = 1
while nb<len(lines[i]) and lines[i][nb]=='>':
nb += 1
lines[i] = lines[i][nb:]
if nb>bq:
lines.insert(i,'<blockquote>'*(nb-bq))
i += 1
bq = nb
elif nb<bq:
lines.insert(i,'</blockquote>'*(bq-nb))
i += 1
bq = nb
elif bq>0:
lines.insert(i,'</blockquote>'*bq)
i += 1
bq = 0
# unordered lists
if lines[i].strip() and lines[i].lstrip()[0] in '-+*' \
and len(lines[i].lstrip())>1 \
and lines[i].lstrip()[1]==' ' \
and (i==0 or ul or not lines[i-1].strip()):
# line indentation indicates nesting level
nb = 1+len(lines[i])-len(lines[i].lstrip())
lines[i] = '<li>'+lines[i][nb:]
if nb>ul:
lines.insert(i,'<ul>'*(nb-ul))
i += 1
elif nb<ul:
lines.insert(i,'</ul>'*(ul-nb))
i += 1
ul = nb
elif ul and not lines[i].strip():
if i<len(lines)-1 and lines[i+1].strip() \
and not lines[i+1].startswith(' '):
nline = lines[i+1].lstrip()
if nline[0] in '-+*' and len(nline)>1 and nline[1]==' ':
pass
else:
lines.insert(i,'</ul>'*ul)
i += 1
ul = 0
# ordered lists
mo = re.search(r'^(\d+\.)',lines[i])
if mo:
if not ol:
lines.insert(i,'<ol>')
i += 1
lines[i] = '<li>'+lines[i][len(mo.groups()[0]):]
ol = 1
elif ol and not lines[i].strip() and i<len(lines)-1 \
and not lines[i+1].startswith(' ') \
and not re.search(r'^(\d+\.)',lines[i+1]):
lines.insert(i,'</ol>')
i += 1
ol = 0
i += 1
if ul:
lines.append('</ul>'*ul)
if ol:
lines.append('</ol>'*ol)
if bq:
lines.append('</blockquote>'*bq)
t1 = time.time()
#print('part 1', t1-t0)
sections = []
scripts = []
section = Marked()
i = 0
while i<len(lines):
line = lines[i]
if line.strip() and line.startswith(' '):
if isinstance(section,Marked) and section.line:
sections.append(section)
section = CodeBlock(line[4:])
j = i+1
while j<len(lines) and lines[j].startswith(' '):
section.lines.append(lines[j][4:])
j += 1
sections.append(section)
section = Marked()
i = j
continue
elif line.strip() and line.startswith("```"):
# fenced code blocks à la Github Flavoured Markdown
if isinstance(section,Marked) and section.line:
sections.append(section)
section = CodeBlock(line)
j = i+1
while j<len(lines) and not lines[j].startswith("```"):
section.lines.append(lines[j])
j += 1
sections.append(section)
section = Marked()
i = j+1
continue
elif line.lower().startswith('<script'):
if isinstance(section,Marked) and section.line:
sections.append(section)
section = Marked()
j = i+1
while j<len(lines):
if lines[j].lower().startswith('</script>'):
scripts.append('\n'.join(lines[i+1:j]))
for k in range(i,j+1):
lines[k] = ''
break
j += 1
i = j
continue
# atext header
elif line.startswith('#'):
level = 1
line = lines[i]
while level<len(line) and line[level]=='#' and level<=6:
level += 1
if not line[level+1:].strip():
if level==1:
i += 1
continue
else:
lines[i] = '<H%s>%s</H%s>\n' %(level-1,'#',level-1)
else:
lines[i] = '<H%s>%s</H%s>\n' %(level,line[level+1:],level)
else:
mo = re.search(ref_pattern,line)
if mo is not None:
if isinstance(section,Marked) and section.line:
sections.append(section)
section = Marked()
key = mo.groups()[0]
value = URL(mo.groups()[1])
refs[key.lower()] = value
else:
if not line.strip():
line = '<p></p>'
if section.line:
section.line += '\n'
section.line += line
i += 1
t2 = time.time()
#print('section 2', t2-t1)
if isinstance(section,Marked) and section.line:
sections.append(section)
res = ''
for section in sections:
mk,_scripts = section.to_html()
res += mk
scripts += _scripts
#print('end mark', time.time()-t2)
return res,scripts
def escape(czone):
czone = czone.replace('&','&')
czone = czone.replace('<','<')
czone = czone.replace('>','>')
czone = czone.replace('_','_')
czone = czone.replace('*','*')
return czone
def s_escape(mo):
# used in re.sub
czone = mo.string[mo.start():mo.end()]
return escape(czone)
def unmark(code_zone):
# convert _ to _ inside inline code
code_zone = code_zone.replace('_','_')
return code_zone
def s_unmark(mo):
# convert _ to _ inside inline code
code_zone = mo.string[mo.start():mo.end()]
code_zone = code_zone.replace('_','_')
return code_zone
def apply_markdown(src):
scripts = []
key = None
t0 = time.time()
i = 0
while i<len(src):
if src[i]=='[':
start_a = i+1
while True:
end_a = src.find(']',i)
if end_a == -1:
break
if src[end_a-1]=='\\':
i = end_a+1
else:
break
if end_a>-1 and src[start_a:end_a].find('\n')==-1:
link = src[start_a:end_a]
rest = src[end_a+1:].lstrip()
if rest and rest[0]=='(':
j = 0
while True:
end_href = rest.find(')',j)
if end_href == -1:
break
if rest[end_href-1]=='\\':
j = end_href+1
else:
break
if end_href>-1 and rest[:end_href].find('\n')==-1:
tag = '<a href="'+rest[1:end_href]+'">'+link+'</a>'
src = src[:start_a-1]+tag+rest[end_href+1:]
i = start_a+len(tag)
elif rest and rest[0]=='[':
j = 0
while True:
end_key = rest.find(']',j)
if end_key == -1:
break
if rest[end_key-1]=='\\':
j = end_key+1
else:
break
if end_key>-1 and rest[:end_key].find('\n')==-1:
if not key:
key = link
if key.lower() not in refs:
raise KeyError('unknown reference %s' %key)
url = refs[key.lower()]
tag = '<a href="'+url+'">'+link+'</a>'
src = src[:start_a-1]+tag+rest[end_key+1:]
i = start_a+len(tag)
i += 1
t1 = time.time()
#print('apply markdown 1', t1-t0)
# before applying the markup with _ and *, isolate HTML tags because
# they can contain these characters
# We replace them temporarily by a random string
rstr = ''.join(random.choice(letters) for i in range(16))
i = 0
state = None
start = -1
data = ''
tags = []
while i<len(src):
if src[i]=='<':
j = i+1
while j<len(src):
if src[j]=='"' or src[j]=="'":
if state==src[j] and src[j-1]!='\\':
state = None
j = start+len(data)+1
data = ''
elif state==None:
state = src[j]
start = j
else:
data += src[j]
elif src[j]=='>' and state is None:
tags.append(src[i:j+1])
src = src[:i]+rstr+src[j+1:]
i += len(rstr)
break
elif state=='"' or state=="'":
data += src[j]
elif src[j]=='\n':
# if a sign < is not followed by > in the same ligne, it
# is the sign "lesser than"
src = src[:i]+'<'+src[i+1:]
j=i+4
break
j += 1
elif src[i]=='`' and i>0 and src[i-1]!='\\':
# ignore the content of inline code
j = i+1
while j<len(src):
if src[j]=='`' and src[j-1]!='\\':
break
j += 1
i = j
i += 1
t2 = time.time()
#print('apply markdown 2', len(src), t2-t1)
# escape "<", ">", "&" and "_" in inline code
code_pattern = r'\`(.*?)\`'
src = re.sub(code_pattern,s_escape,src)
# replace escaped ` _ * by HTML characters
src = src.replace(r'\\`','`')
src = src.replace(r'\_','_')
src = src.replace(r'\*','*')
# emphasis
strong_patterns = [('STRONG',r'\*\*(.*?)\*\*'),('B',r'__(.*?)__')]
for tag,strong_pattern in strong_patterns:
src = re.sub(strong_pattern,r'<%s>\1</%s>' %(tag,tag),src)
em_patterns = [('EM',r'\*(.*?)\*'),('I',r'\_(.*?)\_')]
for tag,em_pattern in em_patterns:
src = re.sub(em_pattern,r'<%s>\1</%s>' %(tag,tag),src)
# inline code
code_pattern = r'\`(.*?)\`'
src = re.sub(code_pattern,r'<code>\1</code>',src)
# restore tags
while True:
pos = src.rfind(rstr)
if pos==-1:
break
repl = tags.pop()
src = src[:pos]+repl+src[pos+len(rstr):]
src = '<p>'+src+'</p>'
t3 = time.time()
#print('apply markdown 3', t3-t2)
return src,scripts
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
893,
26,
272,
492,
485,
3596,
264,
465,
295,
199,
2590,
26,
272,
492,
295,
199,
199,
646,
2196,
199,
646,
900,
199,
199,
16415,
275,
283,
23459,
7,
199,
16415,
847,
14435,
14,
4142,
342,
4786,
11371,
7,
199,
199,
533,
2851,
26,
272,
347,
636,
826,
721,
277,
12,
2164,
304,
267,
579,
1086,
275,
2928,
14,
1294,
8,
988,
1294,
29,
17,
9,
267,
291,
14,
6399,
275,
579,
1086,
59,
16,
61,
267,
291,
14,
4478,
275,
2125,
267,
340,
822,
8,
352,
1086,
12694,
18,
26,
288,
8791,
275,
579,
1086,
59,
17,
61,
288,
340,
8791,
59,
16,
19219,
30385,
436,
8791,
1988,
17,
19219,
4065,
356,
277,
14,
4478,
29,
4478,
59,
17,
6809,
17,
61,
288,
916,
8791,
59,
16,
61,
11800,
4065,
436,
8791,
1988,
17,
19219,
4507,
582,
277,
14,
4478,
29,
4478,
59,
17,
6809,
17,
61,
288,
916,
8791,
59,
16,
61,
11800,
480,
436,
8791,
1988,
17,
19219,
531,
582,
277,
14,
4478,
29,
4478,
59,
17,
6809,
17,
61,
268,
199,
533,
5495,
3142,
26,
272,
347,
636,
826,
721,
277,
12,
604,
304,
267,
291,
14,
1278,
275,
359,
604,
61,
267,
340,
1004,
14,
2460,
480,
1040,
22446,
436,
822,
8,
604,
13032,
19,
26,
288,
291,
14,
815,
275,
1004,
59,
19,
2938,
267,
587,
26,
288,
291,
14,
815,
275,
488,
2286,
347,
370,
63,
1360,
8,
277,
304,
267,
340,
291,
14,
1278,
59,
16,
1055,
2460,
32684,
2349,
288,
291,
14,
1278,
14,
1935,
8,
16,
9,
267,
522,
275,
4772,
2258,
78,
1370,
904,
8,
277,
14,
1278,
430,
267,
522,
275,
625,
1657,
8,
470,
9,
267,
485,
533,
275,
291,
14,
815,
503,
298,
17938,
2,
267,
522,
275,
2650,
657,
1021,
5961,
83,
14423,
83,
1108,
657,
3072,
78,
7,
450,
1547,
533,
12,
522,
9,
267,
372,
522,
12,
8607,
199,
199,
533,
20880,
3142,
26,
339,
347,
636,
826,
721,
277,
12,
2928,
304,
267,
291,
14,
2164,
275,
2928,
2286,
347,
370,
63,
1360,
8,
277,
304,
267,
372,
291,
14,
2164,
268,
199,
533,
7173,
379,
26,
272,
347,
636,
826,
721,
277,
12,
1004,
9280,
267,
291,
14,
604,
275,
1004,
267,
291,
14,
3223,
275,
942,
339,
347,
370,
63,
1360,
8,
277,
304,
267,
372,
4838,
63,
15653,
8,
277,
14,
604,
9,
268,
199,
3,
664,
6941,
199,
7655,
275,
1052,
199,
1121,
63,
3401,
275,
519,
2,
12773,
7528,
2795,
2862,
2189,
60,
83,
15622,
2795,
2924,
199,
199,
318,
2216,
8,
2164,
304,
339,
2288,
15749,
272,
307,
16,
275,
900,
14,
521,
342,
272,
15749,
275,
1052,
272,
327,
3715,
1350,
315,
10189,
272,
327,
10189,
883,
506,
520,
272,
327,
446,
282,
1853,
13,
1896,
4163,
1819,
334,
15653,
6302,
911,
440,
506,
7686,
9,
272,
327,
446,
282,
2884,
272,
327,
446,
282,
13598,
13,
1896,
4163,
1947,
334,
15653,
6302,
911,
506,
7686,
9,
272,
327,
446,
282,
1233,
1853,
2286,
327,
3293,
572,
1004,
22295,
272,
2928,
275,
2928,
14,
1814,
2258,
82,
60,
78,
297,
1154,
78,
358,
2286,
327,
2385,
9437,
701,
21106,
272,
2928,
275,
295,
14,
954,
8,
82,
6774,
6697,
2862,
78,
29,
7896,
78,
297,
1557,
78,
3,
8522,
17,
60,
78,
297,
2928,
9,
272,
2928,
275,
295,
14,
954,
8,
82,
6774,
6697,
2862,
78,
6793,
60,
78,
297,
1557,
78,
309,
8522,
17,
60,
78,
297,
2928,
9,
18407,
2385,
275,
2928,
14,
1294,
2258,
78,
358,
11,
459,
418,
2286,
284,
275,
330,
81,
275,
378,
272,
12581,
275,
9113,
275,
378,
2286,
1830,
284,
28,
552,
8,
1278,
304,
398,
327,
655,
1600,
2385,
6617,
701,
690,
315,
282,
1853,
3513,
267,
340,
2385,
59,
73,
1055,
2460,
16099,
735,
288,
8526,
275,
413,
288,
1830,
8526,
28,
552,
8,
1278,
59,
73,
566,
436,
2385,
59,
73,
1527,
4994,
22954,
30838,
355,
8526,
847,
413,
288,
2385,
59,
73,
61,
275,
2385,
59,
73,
1527,
4994,
2938,
288,
340,
8526,
30,
23907,
26,
355,
2385,
14,
3176,
8,
73,
2584,
28,
28623,
3524,
5830,
4994,
13,
23907,
430,
355,
284,
847,
413,
355,
330,
81,
275,
8526,
288,
916,
8526,
28,
23907,
26,
355,
2385,
14,
3176,
8,
73,
2584,
1108,
28623,
3524,
5830,
23907,
13,
4994,
430,
355,
284,
847,
413,
355,
330,
81,
275,
8526,
267,
916,
330,
81,
30,
16,
26,
288,
2385,
14,
3176,
8,
73,
2584,
1108,
28623,
3524,
10,
23907,
9,
288,
284,
847,
413,
288,
330,
81,
275,
378,
398,
327,
31716,
5548,
267,
340,
2385,
59,
73,
1055,
1913,
342,
436,
2385,
59,
73,
1055,
10124,
3430,
16,
61,
315,
2475,
11,
10223,
971,
288,
436,
822,
8,
1278,
59,
73,
1055,
10124,
1012,
30,
17,
971,
288,
436,
2385,
59,
73,
1055,
10124,
3430,
17,
22954,
283,
971,
288,
436,
334,
73,
389,
16,
503,
12581,
503,
440,
2385,
59,
73,
13,
17,
1055,
1913,
5109,
288,
327,
1004,
14311,
9126,
19500,
2166,
288,
8526,
275,
413,
11,
552,
8,
1278,
59,
73,
566,
13,
552,
8,
1278,
59,
73,
1055,
10124,
1012,
288,
2385,
59,
73,
61,
275,
2650,
317,
3524,
11,
1278,
59,
73,
1527,
4994,
2938,
288,
340,
8526,
30,
348,
26,
355,
2385,
14,
3176,
8,
73,
2584,
28,
348,
3524,
5830,
4994,
13,
348,
430,
355,
284,
847,
413,
288,
916,
8526,
28,
348,
26,
355,
2385,
14,
3176,
8,
73,
2584,
1108,
348,
3524,
5830,
348,
13,
4994,
430,
355,
284,
847,
413,
288,
12581,
275,
8526,
267,
916,
12581,
436,
440,
2385,
59,
73,
1055,
1913,
837,
288,
340,
284,
28,
552,
8,
1278,
7216,
17,
436,
2385,
59,
73,
11,
17,
1055,
1913,
342,
971,
355,
436,
440,
2385,
59,
73,
11,
17,
1055,
2460,
360,
18927,
490,
302,
604,
275,
2385,
59,
73,
11,
17,
1055,
10124,
342,
490,
340,
302,
604,
59,
16,
61,
315,
2475,
11,
10223,
436,
822,
8,
78,
604,
13032,
17,
436,
302,
604,
59,
17,
22954,
7596,
717,
986,
490,
587,
26,
717,
2385,
14,
3176,
8,
73,
2584
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
893,
26,
272,
492,
485,
3596,
264,
465,
295,
199,
2590,
26,
272,
492,
295,
199,
199,
646,
2196,
199,
646,
900,
199,
199,
16415,
275,
283,
23459,
7,
199,
16415,
847,
14435,
14,
4142,
342,
4786,
11371,
7,
199,
199,
533,
2851,
26,
272,
347,
636,
826,
721,
277,
12,
2164,
304,
267,
579,
1086,
275,
2928,
14,
1294,
8,
988,
1294,
29,
17,
9,
267,
291,
14,
6399,
275,
579,
1086,
59,
16,
61,
267,
291,
14,
4478,
275,
2125,
267,
340,
822,
8,
352,
1086,
12694,
18,
26,
288,
8791,
275,
579,
1086,
59,
17,
61,
288,
340,
8791,
59,
16,
19219,
30385,
436,
8791,
1988,
17,
19219,
4065,
356,
277,
14,
4478,
29,
4478,
59,
17,
6809,
17,
61,
288,
916,
8791,
59,
16,
61,
11800,
4065,
436,
8791,
1988,
17,
19219,
4507,
582,
277,
14,
4478,
29,
4478,
59,
17,
6809,
17,
61,
288,
916,
8791,
59,
16,
61,
11800,
480,
436,
8791,
1988,
17,
19219,
531,
582,
277,
14,
4478,
29,
4478,
59,
17,
6809,
17,
61,
268,
199,
533,
5495,
3142,
26,
272,
347,
636,
826,
721,
277,
12,
604,
304,
267,
291,
14,
1278,
275,
359,
604,
61,
267,
340,
1004,
14,
2460,
480,
1040,
22446,
436,
822,
8,
604,
13032,
19,
26,
288,
291,
14,
815,
275,
1004,
59,
19,
2938,
267,
587,
26,
288,
291,
14,
815,
275,
488,
2286,
347,
370,
63,
1360,
8,
277,
304,
267,
340,
291,
14,
1278,
59,
16,
1055,
2460,
32684,
2349,
288,
291,
14,
1278,
14,
1935,
8,
16,
9,
267,
522,
275,
4772,
2258,
78,
1370,
904,
8,
277,
14,
1278,
430,
267,
522,
275,
625,
1657,
8,
470,
9,
267,
485,
533,
275,
291,
14,
815,
503,
298,
17938,
2,
267,
522,
275,
2650,
657,
1021,
5961,
83,
14423,
83,
1108,
657,
3072,
78,
7,
450,
1547,
533,
12,
522,
9,
267,
372,
522,
12,
8607,
199,
199,
533,
20880,
3142,
26,
339,
347,
636,
826,
721,
277,
12,
2928,
304,
267,
291,
14,
2164,
275,
2928,
2286,
347,
370,
63,
1360,
8,
277,
304,
267,
372,
291,
14,
2164,
268,
199,
533,
7173,
379,
26,
272,
347,
636,
826,
721,
277,
12,
1004,
9280,
267,
291,
14,
604,
275,
1004,
267,
291,
14,
3223,
275,
942,
339,
347,
370,
63,
1360,
8,
277,
304,
267,
372,
4838,
63,
15653,
8,
277,
14,
604,
9,
268,
199,
3,
664,
6941,
199,
7655,
275,
1052,
199,
1121,
63,
3401,
275,
519,
2,
12773,
7528,
2795,
2862,
2189,
60,
83,
15622,
2795,
2924,
199,
199,
318,
2216,
8,
2164,
304,
339,
2288,
15749,
272,
307,
16,
275,
900,
14,
521,
342,
272,
15749,
275,
1052,
272,
327,
3715,
1350,
315,
10189,
272,
327,
10189,
883,
506,
520,
272,
327,
446,
282,
1853,
13,
1896,
4163,
1819,
334,
15653,
6302,
911,
440,
506,
7686,
9,
272,
327,
446,
282,
2884,
272,
327,
446,
282,
13598,
13,
1896,
4163,
1947,
334,
15653,
6302,
911,
506,
7686,
9,
272,
327,
446,
282,
1233,
1853,
2286,
327,
3293,
572,
1004,
22295,
272,
2928,
275,
2928,
14,
1814,
2258,
82,
60,
78,
297,
1154,
78,
358,
2286,
327,
2385,
9437,
701,
21106,
272,
2928,
275,
295,
14,
954,
8,
82,
6774,
6697,
2862,
78,
29,
7896,
78,
297,
1557,
78,
3,
8522,
17,
60,
78,
297,
2928,
9,
272,
2928,
275,
295,
14,
954,
8,
82,
6774,
6697,
2862,
78,
6793,
60,
78,
297,
1557,
78,
309,
8522,
17,
60,
78,
297,
2928,
9,
18407,
2385,
275,
2928,
14,
1294,
2258,
78,
358,
11,
459,
418,
2286,
284,
275,
330,
81,
275,
378,
272,
12581,
275,
9113,
275,
378,
2286,
1830,
284,
28,
552,
8,
1278,
304,
398,
327,
655,
1600,
2385,
6617,
701,
690,
315,
282,
1853,
3513,
267,
340,
2385,
59,
73,
1055,
2460,
16099,
735,
288,
8526,
275,
413,
288,
1830,
8526,
28,
552,
8,
1278,
59,
73,
566,
436,
2385,
59,
73,
1527,
4994,
22954,
30838,
355,
8526,
847,
413,
288,
2385,
59,
73,
61,
275,
2385,
59,
73,
1527,
4994,
2938,
288,
340,
8526,
30,
23907,
26,
355,
2385,
14,
3176,
8,
73,
2584,
28,
28623,
3524,
5830,
4994,
13,
23907,
430,
355,
284,
847,
413,
355,
330,
81,
275,
8526,
288,
916,
8526,
28,
23907,
26,
355,
2385,
14,
3176,
8,
73,
2584,
1108,
28623,
3524,
5830,
23907,
13,
4994,
430,
355,
284,
847,
413,
355,
330,
81,
275,
8526,
267,
916,
330,
81,
30,
16,
26,
288,
2385,
14,
3176,
8,
73,
2584,
1108,
28623,
3524,
10,
23907,
9,
288,
284,
847,
413,
288,
330,
81,
275,
378,
398,
327,
31716,
5548,
267,
340,
2385,
59,
73,
1055,
1913,
342,
436,
2385,
59,
73,
1055,
10124,
3430,
16,
61,
315,
2475,
11,
10223,
971,
288,
436,
822,
8,
1278,
59,
73,
1055,
10124,
1012,
30,
17,
971,
288,
436,
2385,
59,
73,
1055,
10124,
3430,
17,
22954,
283,
971,
288,
436,
334,
73,
389,
16,
503,
12581,
503,
440,
2385,
59,
73,
13,
17,
1055,
1913,
5109,
288,
327,
1004,
14311,
9126,
19500,
2166,
288,
8526,
275,
413,
11,
552,
8,
1278,
59,
73,
566,
13,
552,
8,
1278,
59,
73,
1055,
10124,
1012,
288,
2385,
59,
73,
61,
275,
2650,
317,
3524,
11,
1278,
59,
73,
1527,
4994,
2938,
288,
340,
8526,
30,
348,
26,
355,
2385,
14,
3176,
8,
73,
2584,
28,
348,
3524,
5830,
4994,
13,
348,
430,
355,
284,
847,
413,
288,
916,
8526,
28,
348,
26,
355,
2385,
14,
3176,
8,
73,
2584,
1108,
348,
3524,
5830,
348,
13,
4994,
430,
355,
284,
847,
413,
288,
12581,
275,
8526,
267,
916,
12581,
436,
440,
2385,
59,
73,
1055,
1913,
837,
288,
340,
284,
28,
552,
8,
1278,
7216,
17,
436,
2385,
59,
73,
11,
17,
1055,
1913,
342,
971,
355,
436,
440,
2385,
59,
73,
11,
17,
1055,
2460,
360,
18927,
490,
302,
604,
275,
2385,
59,
73,
11,
17,
1055,
10124,
342,
490,
340,
302,
604,
59,
16,
61,
315,
2475,
11,
10223,
436,
822,
8,
78,
604,
13032,
17,
436,
302,
604,
59,
17,
22954,
7596,
717,
986,
490,
587,
26,
717,
2385,
14,
3176,
8,
73,
2584,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
magfest/ubersystem
|
tests/uber/models/test_merch.py
|
1
|
9284
|
import pytest
from uber.config import c
from uber.models import Attendee
@pytest.fixture(autouse=True)
def donation_tier_fixture(monkeypatch):
shirt_level = 25
supporter_level = 85
monkeypatch.setattr(c, 'DONATION_TIERS', {
0: 'No thanks',
shirt_level: 'RedShirt',
55: 'Cruiser',
supporter_level: 'Supporter Package - Battleship',
205: 'Aircraft Carrier',
})
# [integer_enums]
monkeypatch.setattr(c, 'SHIRT_LEVEL', shirt_level)
monkeypatch.setattr(c, 'SUPPORTER_LEVEL', supporter_level)
monkeypatch.setattr(c, 'SHIRTS_PER_STAFFER', 3)
monkeypatch.setattr(c, 'STAFF_EVENT_SHIRT_OPTS', '[]')
class TestMerchAttrs:
def test_paid_for_a_shirt(self):
assert not Attendee(amount_extra=c.SHIRT_LEVEL - 1).paid_for_a_shirt
assert Attendee(amount_extra=c.SHIRT_LEVEL).paid_for_a_shirt
assert Attendee(amount_extra=c.SHIRT_LEVEL + 1).paid_for_a_shirt
def test_volunteer_event_shirt_eligible(self):
assert not Attendee().volunteer_event_shirt_eligible
assert Attendee(ribbon=c.VOLUNTEER_RIBBON).volunteer_event_shirt_eligible
assert not Attendee(badge_type=c.STAFF_BADGE).volunteer_event_shirt_eligible
assert not Attendee(ribbon=c.VOLUNTEER_RIBBON, badge_type=c.STAFF_BADGE).volunteer_event_shirt_eligible
def test_staff_event_shirt_eligible(self, monkeypatch):
monkeypatch.setattr(c, 'STAFF_EVENT_SHIRT_OPTS', 1)
assert Attendee(badge_type=c.STAFF_BADGE).volunteer_event_shirt_eligible
assert Attendee(badge_type=c.STAFF_BADGE, ribbon=c.VOLUNTEER_RIBBON).volunteer_event_shirt_eligible
def test_volunteer_event_shirt_earned(self, monkeypatch):
for (eligible, takes_shifts, worked_hours), expected in {
(False, False, 5): False,
(False, False, 6): False,
(False, True, 5): False,
(False, True, 6): False,
(True, False, 5): True,
(True, True, 5): False,
(True, False, 6): True,
(True, True, 6): True}.items():
monkeypatch.setattr(Attendee, 'takes_shifts', takes_shifts)
monkeypatch.setattr(Attendee, 'volunteer_event_shirt_eligible', eligible)
assert expected == Attendee(nonshift_hours=worked_hours).volunteer_event_shirt_earned
def test_num_event_shirts_owed(self, monkeypatch):
for paid, volunteer, replacement, owed in [
(False, False, 0, 0),
(False, True, 0, 1),
(True, False, 0, 1),
(True, True, 0, 2),
(False, False, 1, 1),
(False, True, 1, 2),
(True, False, 1, 2),
(True, True, 1, 3)]:
monkeypatch.setattr(Attendee, 'paid_for_a_shirt', paid)
monkeypatch.setattr(Attendee, 'volunteer_event_shirt_eligible', volunteer)
monkeypatch.setattr(Attendee, 'num_event_shirts', replacement)
assert owed == Attendee().num_event_shirts_owed
def test_num_staff_shirts_owed(self, monkeypatch):
for gets_shirt, replacement, expected in [
(False, 0, 0),
(False, 1, 0),
(True, 0, 3),
(True, 1, 2),
(True, 2, 1)]:
monkeypatch.setattr(Attendee, 'gets_staff_shirt', gets_shirt)
monkeypatch.setattr(Attendee, 'num_event_shirts', replacement)
assert expected == Attendee().num_staff_shirts_owed
def test_gets_staff_shirt(self):
assert not Attendee().gets_staff_shirt
assert Attendee(badge_type=c.STAFF_BADGE).gets_staff_shirt
def test_gets_any_kind_of_shirt(self, monkeypatch):
for staff, swag, expected in [
(False, 0, False),
(False, 1, True),
(True, 0, True),
(True, 1, True)]:
monkeypatch.setattr(Attendee, 'gets_staff_shirt', staff)
monkeypatch.setattr(Attendee, 'num_event_shirts_owed', swag)
assert expected == Attendee().gets_any_kind_of_shirt
def test_shirt_info_marked_event_shirtless(self, monkeypatch):
monkeypatch.setattr(c, 'SHIRTS_PER_STAFFER', 0)
for marked, gets_shirt, expected in [
(False, False, False),
(False, True, False),
(True, False, True),
(True, True, True)]:
monkeypatch.setattr(Attendee, 'shirt_size_marked', marked)
monkeypatch.setattr(Attendee, 'gets_staff_shirt', gets_shirt)
assert expected == Attendee(second_shirt=c.UNKNOWN).shirt_info_marked
def test_shirt_info_marked_before_deadline(self, monkeypatch):
monkeypatch.setattr(c, 'AFTER_SHIRT_DEADLINE', False)
for marked, gets_shirt, second_shirt, expected in [
(False, False, c.UNKNOWN, False),
(False, False, c.TWO_STAFF_SHIRTS, False),
(False, True, c.UNKNOWN, False),
(False, True, c.TWO_STAFF_SHIRTS, False),
(True, False, c.UNKNOWN, True),
(True, False, c.TWO_STAFF_SHIRTS, True),
(True, True, c.UNKNOWN, False),
(True, True, c.TWO_STAFF_SHIRTS, True)]:
monkeypatch.setattr(Attendee, 'shirt_size_marked', marked)
monkeypatch.setattr(Attendee, 'gets_staff_shirt', gets_shirt)
assert expected == Attendee(second_shirt=second_shirt).shirt_info_marked
def test_shirt_info_marked_after_deadline(self, monkeypatch):
monkeypatch.setattr(c, 'AFTER_SHIRT_DEADLINE', True)
for marked, gets_shirt, second_shirt, expected in [
(False, False, c.UNKNOWN, False),
(False, False, c.TWO_STAFF_SHIRTS, False),
(False, True, c.UNKNOWN, False),
(False, True, c.TWO_STAFF_SHIRTS, False),
(True, False, c.UNKNOWN, True),
(True, False, c.TWO_STAFF_SHIRTS, True),
(True, True, c.UNKNOWN, True),
(True, True, c.TWO_STAFF_SHIRTS, True)]:
monkeypatch.setattr(Attendee, 'shirt_size_marked', marked)
monkeypatch.setattr(Attendee, 'gets_staff_shirt', gets_shirt)
assert expected == Attendee(second_shirt=second_shirt).shirt_info_marked
class TestMerch:
@pytest.fixture(autouse=True)
def defaults(self, monkeypatch):
monkeypatch.setattr(c, 'SEPARATE_STAFF_MERCH', True)
attrs = [
'volunteer_event_shirt_eligible',
'paid_for_a_shirt',
'volunteer_event_shirt_earned',
'gets_staff_shirt']
for attr in attrs:
monkeypatch.setattr(Attendee, attr, False)
@pytest.fixture
def paid_for_a_shirt(self, monkeypatch):
setattr(Attendee, 'paid_for_a_shirt', True)
@pytest.fixture
def volunteer_event_shirt_eligible(self, monkeypatch):
monkeypatch.setattr(Attendee, 'volunteer_event_shirt_eligible', True)
@pytest.fixture
def volunteer_event_shirt_earned(self, monkeypatch):
setattr(Attendee, 'volunteer_event_shirt_earned', True)
@pytest.fixture
def gets_staff_shirt(self, monkeypatch):
setattr(Attendee, 'gets_staff_shirt', True)
def test_extra_merch(self):
assert 'foo' == Attendee(extra_merch='foo').merch
assert 'more' == Attendee(extra_merch='more').merch
def test_normal_kickins(self, monkeypatch):
monkeypatch.setattr(Attendee, 'merch_items', ['some', 'stuff'])
assert 'some and stuff' == Attendee().merch
def test_nested_kickins(self, monkeypatch):
monkeypatch.setattr(Attendee, 'merch_items', ['some', ['mildly', 'nested'], 'stuff'])
assert 'some and stuff' == Attendee().merch
def test_comma_and(self, monkeypatch):
monkeypatch.setattr(Attendee, 'merch_items', ['some', 'stuff', 'more'])
assert 'some, stuff, and more' == Attendee().merch
def test_info_packet(self):
assert '' == Attendee(staffing=True).merch
assert 'Staffer Info Packet' == Attendee(staffing=True).staff_merch
def test_staff_shirts(self, gets_staff_shirt):
assert 'tshirt' in Attendee().merch
assert '2 Staff Shirts' in Attendee().staff_merch
a = Attendee(second_shirt=c.TWO_STAFF_SHIRTS)
assert '' == a.merch
assert '3 Staff Shirts' in a.staff_merch
def test_volunteer(self, volunteer_event_shirt_eligible):
assert 'tshirt' in Attendee().merch and 'will be reported' in Attendee().merch
def test_paid_volunteer(self, paid_for_a_shirt, volunteer_event_shirt_eligible):
assert 'RedShirt' in Attendee(amount_extra=c.SHIRT_LEVEL).merch
assert '2nd tshirt' in Attendee(amount_extra=c.SHIRT_LEVEL).merch
def test_volunteer_worked(self, volunteer_event_shirt_eligible, volunteer_event_shirt_earned):
assert 'tshirt' in Attendee().merch
def test_two_swag_shirts(self, volunteer_event_shirt_eligible, volunteer_event_shirt_earned, paid_for_a_shirt):
assert 'RedShirt and a 2nd tshirt' == Attendee(amount_extra=c.SHIRT_LEVEL).merch
|
agpl-3.0
|
[
646,
4613,
199,
199,
504,
399,
605,
14,
888,
492,
286,
199,
504,
399,
605,
14,
992,
492,
2854,
724,
11192,
421,
199,
32,
4462,
14,
5997,
8,
6898,
7130,
29,
549,
9,
199,
318,
2793,
425,
63,
13949,
63,
5997,
8,
20372,
2068,
304,
272,
1033,
8401,
63,
1896,
275,
5661,
272,
4973,
3968,
63,
1896,
275,
16412,
339,
17309,
14,
10202,
8,
67,
12,
283,
36,
615,
2594,
63,
13247,
3960,
297,
469,
267,
378,
26,
283,
1944,
2419,
6080,
297,
267,
1033,
8401,
63,
1896,
26,
283,
10858,
2662,
8401,
297,
267,
12766,
26,
283,
17345,
1907,
332,
297,
267,
4973,
3968,
63,
1896,
26,
283,
17127,
3968,
15665,
446,
699,
29274,
3319,
297,
267,
24005,
26,
283,
33,
5958,
4800,
14243,
10742,
297,
272,
3828,
339,
327,
359,
4115,
63,
19921,
61,
272,
17309,
14,
10202,
8,
67,
12,
283,
3234,
3927,
52,
63,
11817,
297,
1033,
8401,
63,
1896,
9,
272,
17309,
14,
10202,
8,
67,
12,
283,
7380,
48,
726,
1157,
63,
11817,
297,
4973,
3968,
63,
1896,
9,
339,
17309,
14,
10202,
8,
67,
12,
283,
3234,
3927,
9730,
63,
4227,
63,
840,
25900,
540,
297,
650,
9,
272,
17309,
14,
10202,
8,
67,
12,
283,
840,
25900,
63,
8193,
63,
3234,
3927,
52,
63,
25636,
297,
6730,
10374,
421,
199,
533,
1379,
16797,
335,
21368,
26,
272,
347,
511,
63,
16555,
63,
509,
63,
65,
63,
609,
8401,
8,
277,
304,
267,
702,
440,
2854,
724,
11192,
8,
4606,
63,
2911,
29,
67,
14,
3234,
3927,
52,
63,
11817,
446,
413,
680,
16555,
63,
509,
63,
65,
63,
609,
8401,
267,
702,
2854,
724,
11192,
8,
4606,
63,
2911,
29,
67,
14,
3234,
3927,
52,
63,
11817,
680,
16555,
63,
509,
63,
65,
63,
609,
8401,
267,
702,
2854,
724,
11192,
8,
4606,
63,
2911,
29,
67,
14,
3234,
3927,
52,
63,
11817,
435,
413,
680,
16555,
63,
509,
63,
65,
63,
609,
8401,
339,
347,
511,
63,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
8,
277,
304,
267,
702,
440,
2854,
724,
11192,
1252,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
267,
702,
2854,
724,
11192,
8,
322,
2501,
265,
29,
67,
14,
12209,
1734,
3727,
540,
63,
50,
2100,
34,
615,
680,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
267,
702,
440,
2854,
724,
11192,
8,
18465,
63,
466,
29,
67,
14,
840,
25900,
63,
9439,
4962,
680,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
267,
702,
440,
2854,
724,
11192,
8,
322,
2501,
265,
29,
67,
14,
12209,
1734,
3727,
540,
63,
50,
2100,
34,
615,
12,
23122,
63,
466,
29,
67,
14,
840,
25900,
63,
9439,
4962,
680,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
339,
347,
511,
63,
7018,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
8,
277,
12,
17309,
304,
267,
17309,
14,
10202,
8,
67,
12,
283,
840,
25900,
63,
8193,
63,
3234,
3927,
52,
63,
25636,
297,
413,
9,
267,
702,
2854,
724,
11192,
8,
18465,
63,
466,
29,
67,
14,
840,
25900,
63,
9439,
4962,
680,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
267,
702,
2854,
724,
11192,
8,
18465,
63,
466,
29,
67,
14,
840,
25900,
63,
9439,
4962,
12,
8012,
2501,
265,
29,
67,
14,
12209,
1734,
3727,
540,
63,
50,
2100,
34,
615,
680,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
339,
347,
511,
63,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
69,
31772,
8,
277,
12,
17309,
304,
267,
367,
334,
18865,
28297,
12,
6181,
63,
26063,
1086,
12,
26731,
63,
8419,
395,
1420,
315,
469,
355,
334,
797,
12,
756,
12,
959,
304,
756,
12,
355,
334,
797,
12,
756,
12,
1227,
304,
756,
12,
355,
334,
797,
12,
715,
12,
959,
304,
756,
12,
355,
334,
797,
12,
715,
12,
1227,
304,
756,
12,
355,
334,
549,
12,
756,
12,
959,
304,
715,
12,
355,
334,
549,
12,
715,
12,
959,
304,
756,
12,
355,
334,
549,
12,
756,
12,
1227,
304,
715,
12,
355,
334,
549,
12,
715,
12,
1227,
304,
715,
5565,
1744,
837,
288,
17309,
14,
10202,
8,
1271,
724,
11192,
12,
283,
31613,
63,
26063,
1086,
297,
6181,
63,
26063,
1086,
9,
288,
17309,
14,
10202,
8,
1271,
724,
11192,
12,
283,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
297,
28214,
28297,
9,
288,
702,
1420,
508,
2854,
724,
11192,
8,
2865,
4723,
63,
8419,
29,
800,
379,
63,
8419,
680,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
69,
31772,
339,
347,
511,
63,
1507,
63,
1430,
63,
609,
723,
1086,
63,
583,
379,
8,
277,
12,
17309,
304,
267,
367,
30677,
12,
5236,
27929,
12,
8343,
12,
22182,
379,
315,
359,
355,
334,
797,
12,
756,
12,
378,
12,
378,
395,
355,
334,
797,
12,
715,
12,
378,
12,
413,
395,
355,
334,
549,
12,
756,
12,
378,
12,
413,
395,
355,
334,
549,
12,
715,
12,
378,
12,
499,
395,
355,
334,
797,
12,
756,
12,
413,
12,
413,
395,
355,
334,
797,
12,
715,
12,
413,
12,
499,
395,
355,
334,
549,
12,
756,
12,
413,
12,
499,
395,
355,
334,
549,
12,
715,
12,
413,
12,
650,
19532,
288,
17309,
14,
10202,
8,
1271,
724,
11192,
12,
283,
16555,
63,
509,
63,
65,
63,
609,
8401,
297,
30677,
9,
288,
17309,
14,
10202,
8,
1271,
724,
11192,
12,
283,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
297,
5236,
27929,
9,
288,
17309,
14,
10202,
8,
1271,
724,
11192,
12,
283,
1507,
63,
1430,
63,
609,
723,
1086,
297,
8343,
9,
288,
702,
22182,
379,
508,
2854,
724,
11192,
1252,
1507,
63,
1430,
63,
609,
723,
1086,
63,
583,
379,
339,
347,
511,
63,
1507,
63,
7018,
63,
609,
723,
1086,
63,
583,
379,
8,
277,
12,
17309,
304,
267,
367,
7545,
63,
609,
8401,
12,
8343,
12,
1420,
315,
359,
355,
334,
797,
12,
378,
12,
378,
395,
355,
334,
797,
12,
413,
12,
378,
395,
355,
334,
549,
12,
378,
12,
650,
395,
355,
334,
549,
12,
413,
12,
499,
395,
355
] |
[
4613,
199,
199,
504,
399,
605,
14,
888,
492,
286,
199,
504,
399,
605,
14,
992,
492,
2854,
724,
11192,
421,
199,
32,
4462,
14,
5997,
8,
6898,
7130,
29,
549,
9,
199,
318,
2793,
425,
63,
13949,
63,
5997,
8,
20372,
2068,
304,
272,
1033,
8401,
63,
1896,
275,
5661,
272,
4973,
3968,
63,
1896,
275,
16412,
339,
17309,
14,
10202,
8,
67,
12,
283,
36,
615,
2594,
63,
13247,
3960,
297,
469,
267,
378,
26,
283,
1944,
2419,
6080,
297,
267,
1033,
8401,
63,
1896,
26,
283,
10858,
2662,
8401,
297,
267,
12766,
26,
283,
17345,
1907,
332,
297,
267,
4973,
3968,
63,
1896,
26,
283,
17127,
3968,
15665,
446,
699,
29274,
3319,
297,
267,
24005,
26,
283,
33,
5958,
4800,
14243,
10742,
297,
272,
3828,
339,
327,
359,
4115,
63,
19921,
61,
272,
17309,
14,
10202,
8,
67,
12,
283,
3234,
3927,
52,
63,
11817,
297,
1033,
8401,
63,
1896,
9,
272,
17309,
14,
10202,
8,
67,
12,
283,
7380,
48,
726,
1157,
63,
11817,
297,
4973,
3968,
63,
1896,
9,
339,
17309,
14,
10202,
8,
67,
12,
283,
3234,
3927,
9730,
63,
4227,
63,
840,
25900,
540,
297,
650,
9,
272,
17309,
14,
10202,
8,
67,
12,
283,
840,
25900,
63,
8193,
63,
3234,
3927,
52,
63,
25636,
297,
6730,
10374,
421,
199,
533,
1379,
16797,
335,
21368,
26,
272,
347,
511,
63,
16555,
63,
509,
63,
65,
63,
609,
8401,
8,
277,
304,
267,
702,
440,
2854,
724,
11192,
8,
4606,
63,
2911,
29,
67,
14,
3234,
3927,
52,
63,
11817,
446,
413,
680,
16555,
63,
509,
63,
65,
63,
609,
8401,
267,
702,
2854,
724,
11192,
8,
4606,
63,
2911,
29,
67,
14,
3234,
3927,
52,
63,
11817,
680,
16555,
63,
509,
63,
65,
63,
609,
8401,
267,
702,
2854,
724,
11192,
8,
4606,
63,
2911,
29,
67,
14,
3234,
3927,
52,
63,
11817,
435,
413,
680,
16555,
63,
509,
63,
65,
63,
609,
8401,
339,
347,
511,
63,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
8,
277,
304,
267,
702,
440,
2854,
724,
11192,
1252,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
267,
702,
2854,
724,
11192,
8,
322,
2501,
265,
29,
67,
14,
12209,
1734,
3727,
540,
63,
50,
2100,
34,
615,
680,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
267,
702,
440,
2854,
724,
11192,
8,
18465,
63,
466,
29,
67,
14,
840,
25900,
63,
9439,
4962,
680,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
267,
702,
440,
2854,
724,
11192,
8,
322,
2501,
265,
29,
67,
14,
12209,
1734,
3727,
540,
63,
50,
2100,
34,
615,
12,
23122,
63,
466,
29,
67,
14,
840,
25900,
63,
9439,
4962,
680,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
339,
347,
511,
63,
7018,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
8,
277,
12,
17309,
304,
267,
17309,
14,
10202,
8,
67,
12,
283,
840,
25900,
63,
8193,
63,
3234,
3927,
52,
63,
25636,
297,
413,
9,
267,
702,
2854,
724,
11192,
8,
18465,
63,
466,
29,
67,
14,
840,
25900,
63,
9439,
4962,
680,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
267,
702,
2854,
724,
11192,
8,
18465,
63,
466,
29,
67,
14,
840,
25900,
63,
9439,
4962,
12,
8012,
2501,
265,
29,
67,
14,
12209,
1734,
3727,
540,
63,
50,
2100,
34,
615,
680,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
339,
347,
511,
63,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
69,
31772,
8,
277,
12,
17309,
304,
267,
367,
334,
18865,
28297,
12,
6181,
63,
26063,
1086,
12,
26731,
63,
8419,
395,
1420,
315,
469,
355,
334,
797,
12,
756,
12,
959,
304,
756,
12,
355,
334,
797,
12,
756,
12,
1227,
304,
756,
12,
355,
334,
797,
12,
715,
12,
959,
304,
756,
12,
355,
334,
797,
12,
715,
12,
1227,
304,
756,
12,
355,
334,
549,
12,
756,
12,
959,
304,
715,
12,
355,
334,
549,
12,
715,
12,
959,
304,
756,
12,
355,
334,
549,
12,
756,
12,
1227,
304,
715,
12,
355,
334,
549,
12,
715,
12,
1227,
304,
715,
5565,
1744,
837,
288,
17309,
14,
10202,
8,
1271,
724,
11192,
12,
283,
31613,
63,
26063,
1086,
297,
6181,
63,
26063,
1086,
9,
288,
17309,
14,
10202,
8,
1271,
724,
11192,
12,
283,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
297,
28214,
28297,
9,
288,
702,
1420,
508,
2854,
724,
11192,
8,
2865,
4723,
63,
8419,
29,
800,
379,
63,
8419,
680,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
69,
31772,
339,
347,
511,
63,
1507,
63,
1430,
63,
609,
723,
1086,
63,
583,
379,
8,
277,
12,
17309,
304,
267,
367,
30677,
12,
5236,
27929,
12,
8343,
12,
22182,
379,
315,
359,
355,
334,
797,
12,
756,
12,
378,
12,
378,
395,
355,
334,
797,
12,
715,
12,
378,
12,
413,
395,
355,
334,
549,
12,
756,
12,
378,
12,
413,
395,
355,
334,
549,
12,
715,
12,
378,
12,
499,
395,
355,
334,
797,
12,
756,
12,
413,
12,
413,
395,
355,
334,
797,
12,
715,
12,
413,
12,
499,
395,
355,
334,
549,
12,
756,
12,
413,
12,
499,
395,
355,
334,
549,
12,
715,
12,
413,
12,
650,
19532,
288,
17309,
14,
10202,
8,
1271,
724,
11192,
12,
283,
16555,
63,
509,
63,
65,
63,
609,
8401,
297,
30677,
9,
288,
17309,
14,
10202,
8,
1271,
724,
11192,
12,
283,
5650,
27929,
63,
1430,
63,
609,
8401,
63,
18865,
28297,
297,
5236,
27929,
9,
288,
17309,
14,
10202,
8,
1271,
724,
11192,
12,
283,
1507,
63,
1430,
63,
609,
723,
1086,
297,
8343,
9,
288,
702,
22182,
379,
508,
2854,
724,
11192,
1252,
1507,
63,
1430,
63,
609,
723,
1086,
63,
583,
379,
339,
347,
511,
63,
1507,
63,
7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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
] |
babycaseny/poedit
|
deps/boost/tools/build/src/util/__init__.py
|
12
|
4982
|
import bjam
import re
import types
from itertools import groupby
# Decorator the specifies bjam-side prototype for a Python function
def bjam_signature(s):
def wrap(f):
f.bjam_signature = s
return f
return wrap
def metatarget(f):
f.bjam_signature = (["name"], ["sources", "*"], ["requirements", "*"],
["default_build", "*"], ["usage_requirements", "*"])
return f
class cached(object):
def __init__(self, function):
self.function = function
self.cache = {}
def __call__(self, *args):
try:
return self.cache[args]
except KeyError:
v = self.function(*args)
self.cache[args] = v
return v
def __get__(self, instance, type):
return types.MethodType(self, instance, type)
def unquote(s):
if s and s[0] == '"' and s[-1] == '"':
return s[1:-1]
else:
return s
_extract_jamfile_and_rule = re.compile("(Jamfile<.*>)%(.*)")
def qualify_jam_action(action_name, context_module):
if action_name.startswith("###"):
# Callable exported from Python. Don't touch
return action_name
elif _extract_jamfile_and_rule.match(action_name):
# Rule is already in indirect format
return action_name
else:
ix = action_name.find('.')
if ix != -1 and action_name[:ix] == context_module:
return context_module + '%' + action_name[ix+1:]
return context_module + '%' + action_name
def set_jam_action(name, *args):
m = _extract_jamfile_and_rule.match(name)
if m:
args = ("set-update-action-in-module", m.group(1), m.group(2)) + args
else:
args = ("set-update-action", name) + args
return bjam.call(*args)
def call_jam_function(name, *args):
m = _extract_jamfile_and_rule.match(name)
if m:
args = ("call-in-module", m.group(1), m.group(2)) + args
return bjam.call(*args)
else:
return bjam.call(*((name,) + args))
__value_id = 0
__python_to_jam = {}
__jam_to_python = {}
def value_to_jam(value, methods=False):
"""Makes a token to refer to a Python value inside Jam language code.
The token is merely a string that can be passed around in Jam code and
eventually passed back. For example, we might want to pass PropertySet
instance to a tag function and it might eventually call back
to virtual_target.add_suffix_and_prefix, passing the same instance.
For values that are classes, we'll also make class methods callable
from Jam.
Note that this is necessary to make a bit more of existing Jamfiles work.
This trick should not be used to much, or else the performance benefits of
Python port will be eaten.
"""
global __value_id
r = __python_to_jam.get(value, None)
if r:
return r
exported_name = '###_' + str(__value_id)
__value_id = __value_id + 1
__python_to_jam[value] = exported_name
__jam_to_python[exported_name] = value
if methods and type(value) == types.InstanceType:
for field_name in dir(value):
field = getattr(value, field_name)
if callable(field) and not field_name.startswith("__"):
bjam.import_rule("", exported_name + "." + field_name, field)
return exported_name
def record_jam_to_value_mapping(jam_value, python_value):
__jam_to_python[jam_value] = python_value
def jam_to_value_maybe(jam_value):
if type(jam_value) == type(""):
return __jam_to_python.get(jam_value, jam_value)
else:
return jam_value
def stem(filename):
i = filename.find('.')
if i != -1:
return filename[0:i]
else:
return filename
def abbreviate_dashed(s):
"""Abbreviates each part of string that is delimited by a '-'."""
r = []
for part in s.split('-'):
r.append(abbreviate(part))
return '-'.join(r)
def abbreviate(s):
"""Apply a set of standard transformations to string to produce an
abbreviation no more than 4 characters long.
"""
if not s:
return ''
# check the cache
if s in abbreviate.abbreviations:
return abbreviate.abbreviations[s]
# anything less than 4 characters doesn't need
# an abbreviation
if len(s) < 4:
# update cache
abbreviate.abbreviations[s] = s
return s
# save the first character in case it's a vowel
s1 = s[0]
s2 = s[1:]
if s.endswith('ing'):
# strip off the 'ing'
s2 = s2[:-3]
# reduce all doubled characters to one
s2 = ''.join(c for c, _ in groupby(s2))
# remove all vowels
s2 = s2.translate(None, "AEIOUaeiou")
# shorten remaining consonants to 4 characters
# and add the first char back to the front
s2 = s1 + s2[:4]
# update cache
abbreviate.abbreviations[s] = s2
return s2
# maps key to its abbreviated form
abbreviate.abbreviations = {}
|
mit
|
[
199,
646,
330,
16997,
199,
646,
295,
199,
646,
2943,
199,
199,
504,
7975,
492,
20371,
421,
199,
3,
30684,
314,
9314,
330,
16997,
13,
2441,
19393,
367,
282,
2018,
805,
199,
318,
330,
16997,
63,
5233,
8,
83,
304,
339,
347,
4816,
8,
70,
304,
263,
267,
289,
14,
468,
455,
63,
5233,
275,
308,
267,
372,
289,
339,
372,
4816,
199,
199,
318,
7647,
292,
839,
8,
70,
304,
339,
289,
14,
468,
455,
63,
5233,
275,
334,
905,
354,
2255,
2097,
4553,
401,
8969,
2255,
2097,
7538,
401,
8969,
2255,
717,
2097,
885,
63,
1506,
401,
8969,
2255,
2097,
3807,
63,
7538,
401,
8969,
3135,
272,
372,
289,
199,
199,
533,
6328,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
805,
304,
267,
291,
14,
1593,
275,
805,
267,
291,
14,
1637,
275,
1052,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
304,
267,
862,
26,
288,
372,
291,
14,
1637,
59,
589,
61,
267,
871,
4067,
26,
288,
373,
275,
291,
14,
1593,
2031,
589,
9,
288,
291,
14,
1637,
59,
589,
61,
275,
373,
288,
372,
373,
339,
347,
636,
362,
721,
277,
12,
1256,
12,
730,
304,
267,
372,
2943,
14,
24674,
8,
277,
12,
1256,
12,
730,
9,
199,
199,
318,
14342,
8,
83,
304,
272,
340,
308,
436,
308,
59,
16,
61,
508,
14788,
436,
308,
1988,
17,
61,
508,
24536,
267,
372,
308,
59,
17,
6809,
17,
61,
272,
587,
26,
267,
372,
308,
199,
199,
63,
5005,
63,
16997,
493,
63,
460,
63,
2200,
275,
295,
14,
2014,
18353,
42,
455,
493,
28,
2795,
18956,
2840,
2795,
6320,
199,
199,
318,
6420,
2021,
63,
16997,
63,
1287,
8,
1287,
63,
354,
12,
1067,
63,
578,
304,
339,
340,
1595,
63,
354,
14,
2460,
480,
5680,
2349,
267,
327,
16975,
16629,
687,
2018,
14,
7529,
1133,
12943,
267,
372,
1595,
63,
354,
272,
916,
485,
5005,
63,
16997,
493,
63,
460,
63,
2200,
14,
1431,
8,
1287,
63,
354,
304,
267,
327,
11949,
365,
2575,
315,
19458,
1475,
267,
372,
1595,
63,
354,
272,
587,
26,
267,
20593,
275,
1595,
63,
354,
14,
1623,
7563,
267,
340,
20593,
1137,
446,
17,
436,
1595,
63,
354,
1491,
1148,
61,
508,
1067,
63,
578,
26,
288,
372,
1067,
63,
578,
435,
26386,
435,
1595,
63,
354,
59,
1148,
11,
17,
2938,
2728,
372,
1067,
63,
578,
435,
26386,
435,
1595,
63,
354,
260,
16872,
199,
318,
663,
63,
16997,
63,
1287,
8,
354,
12,
627,
589,
304,
339,
333,
275,
485,
5005,
63,
16997,
493,
63,
460,
63,
2200,
14,
1431,
8,
354,
9,
272,
340,
333,
26,
267,
1249,
275,
1689,
409,
13,
873,
13,
1287,
13,
262,
13,
578,
401,
333,
14,
923,
8,
17,
395,
333,
14,
923,
8,
18,
430,
435,
1249,
272,
587,
26,
267,
1249,
275,
1689,
409,
13,
873,
13,
1287,
401,
536,
9,
435,
1249,
339,
372,
330,
16997,
14,
1250,
2031,
589,
9,
421,
199,
318,
1240,
63,
16997,
63,
1593,
8,
354,
12,
627,
589,
304,
339,
333,
275,
485,
5005,
63,
16997,
493,
63,
460,
63,
2200,
14,
1431,
8,
354,
9,
272,
340,
333,
26,
267,
1249,
275,
1689,
1250,
13,
262,
13,
578,
401,
333,
14,
923,
8,
17,
395,
333,
14,
923,
8,
18,
430,
435,
1249,
267,
372,
330,
16997,
14,
1250,
2031,
589,
9,
272,
587,
26,
267,
372,
330,
16997,
14,
1250,
2031,
1332,
354,
4258,
435,
1249,
430,
199,
199,
363,
585,
63,
344,
275,
378,
199,
363,
1548,
63,
475,
63,
16997,
275,
1052,
199,
363,
16997,
63,
475,
63,
1548,
275,
1052,
199,
199,
318,
574,
63,
475,
63,
16997,
8,
585,
12,
3102,
29,
797,
304,
272,
408,
27142,
282,
1526,
370,
10618,
370,
282,
2018,
574,
6272,
1603,
455,
2637,
1233,
14,
339,
710,
1526,
365,
562,
264,
590,
282,
1059,
626,
883,
506,
3032,
6818,
315,
1603,
455,
1233,
436,
272,
21356,
3032,
1771,
14,
2104,
2893,
12,
781,
5594,
2934,
370,
986,
16158,
1084,
272,
1256,
370,
282,
1947,
805,
436,
652,
5594,
21356,
1240,
1771,
272,
370,
5791,
63,
1375,
14,
525,
63,
4511,
63,
460,
63,
1861,
12,
9476,
314,
2011,
1256,
14,
339,
2104,
1338,
626,
787,
3992,
12,
781,
7171,
2597,
1852,
1021,
3102,
4550,
272,
687,
1603,
455,
14,
339,
3390,
626,
642,
365,
5784,
370,
1852,
282,
4546,
1655,
402,
3411,
1603,
455,
1725,
1736,
14,
272,
961,
20907,
1077,
440,
506,
1202,
370,
8298,
12,
503,
587,
314,
10238,
22477,
14948,
402,
272,
2018,
1844,
911,
506,
325,
323,
78,
14,
272,
408,
339,
2288,
636,
585,
63,
344,
339,
519,
275,
636,
1548,
63,
475,
63,
16997,
14,
362,
8,
585,
12,
488,
9,
272,
340,
519,
26,
267,
372,
519,
339,
16629,
63,
354,
275,
283,
5680,
8650,
435,
620,
3460,
585,
63,
344,
9,
272,
636,
585,
63,
344,
275,
636,
585,
63,
344,
435,
413,
272,
636,
1548,
63,
475,
63,
16997,
59,
585,
61,
275,
16629,
63,
354,
272,
636,
16997,
63,
475,
63,
1548,
59,
23028,
63,
354,
61,
275,
574,
339,
340,
3102,
436,
730,
8,
585,
9,
508,
2943,
14,
3244,
804,
26,
267,
367,
901,
63,
354,
315,
2935,
8,
585,
304,
288,
901,
275,
2519,
8,
585,
12,
901,
63,
354,
9,
288,
340,
4550,
8,
698,
9,
436,
440,
901,
63,
354,
14,
2460,
16232,
2349,
355,
330,
16997,
14,
646,
63,
2200,
12398,
16629,
63,
354,
435,
14530,
435,
901,
63,
354,
12,
901,
9,
339,
372,
16629,
63,
354,
199,
199,
318,
2777,
63,
16997,
63,
475,
63,
585,
63,
4745,
8,
16997,
63,
585,
12,
2366,
63,
585,
304,
272,
636,
16997,
63,
475,
63,
1548,
59,
16997,
63,
585,
61,
275,
2366,
63,
585,
199,
199,
318,
1335,
455,
63,
475,
63,
585,
63,
11853,
8,
16997,
63,
585,
304,
339,
340,
730,
8,
16997,
63,
585,
9,
508,
730,
11986,
304,
267,
372,
636,
16997,
63,
475,
63,
1548,
14,
362,
8,
16997,
63,
585,
12,
1335,
455,
63,
585,
9,
272,
587,
26,
267,
372,
1335,
455,
63,
585,
199,
199,
318,
17408,
8,
1501,
304
] |
[
646,
330,
16997,
199,
646,
295,
199,
646,
2943,
199,
199,
504,
7975,
492,
20371,
421,
199,
3,
30684,
314,
9314,
330,
16997,
13,
2441,
19393,
367,
282,
2018,
805,
199,
318,
330,
16997,
63,
5233,
8,
83,
304,
339,
347,
4816,
8,
70,
304,
263,
267,
289,
14,
468,
455,
63,
5233,
275,
308,
267,
372,
289,
339,
372,
4816,
199,
199,
318,
7647,
292,
839,
8,
70,
304,
339,
289,
14,
468,
455,
63,
5233,
275,
334,
905,
354,
2255,
2097,
4553,
401,
8969,
2255,
2097,
7538,
401,
8969,
2255,
717,
2097,
885,
63,
1506,
401,
8969,
2255,
2097,
3807,
63,
7538,
401,
8969,
3135,
272,
372,
289,
199,
199,
533,
6328,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
805,
304,
267,
291,
14,
1593,
275,
805,
267,
291,
14,
1637,
275,
1052,
339,
347,
636,
1250,
721,
277,
12,
627,
589,
304,
267,
862,
26,
288,
372,
291,
14,
1637,
59,
589,
61,
267,
871,
4067,
26,
288,
373,
275,
291,
14,
1593,
2031,
589,
9,
288,
291,
14,
1637,
59,
589,
61,
275,
373,
288,
372,
373,
339,
347,
636,
362,
721,
277,
12,
1256,
12,
730,
304,
267,
372,
2943,
14,
24674,
8,
277,
12,
1256,
12,
730,
9,
199,
199,
318,
14342,
8,
83,
304,
272,
340,
308,
436,
308,
59,
16,
61,
508,
14788,
436,
308,
1988,
17,
61,
508,
24536,
267,
372,
308,
59,
17,
6809,
17,
61,
272,
587,
26,
267,
372,
308,
199,
199,
63,
5005,
63,
16997,
493,
63,
460,
63,
2200,
275,
295,
14,
2014,
18353,
42,
455,
493,
28,
2795,
18956,
2840,
2795,
6320,
199,
199,
318,
6420,
2021,
63,
16997,
63,
1287,
8,
1287,
63,
354,
12,
1067,
63,
578,
304,
339,
340,
1595,
63,
354,
14,
2460,
480,
5680,
2349,
267,
327,
16975,
16629,
687,
2018,
14,
7529,
1133,
12943,
267,
372,
1595,
63,
354,
272,
916,
485,
5005,
63,
16997,
493,
63,
460,
63,
2200,
14,
1431,
8,
1287,
63,
354,
304,
267,
327,
11949,
365,
2575,
315,
19458,
1475,
267,
372,
1595,
63,
354,
272,
587,
26,
267,
20593,
275,
1595,
63,
354,
14,
1623,
7563,
267,
340,
20593,
1137,
446,
17,
436,
1595,
63,
354,
1491,
1148,
61,
508,
1067,
63,
578,
26,
288,
372,
1067,
63,
578,
435,
26386,
435,
1595,
63,
354,
59,
1148,
11,
17,
2938,
2728,
372,
1067,
63,
578,
435,
26386,
435,
1595,
63,
354,
260,
16872,
199,
318,
663,
63,
16997,
63,
1287,
8,
354,
12,
627,
589,
304,
339,
333,
275,
485,
5005,
63,
16997,
493,
63,
460,
63,
2200,
14,
1431,
8,
354,
9,
272,
340,
333,
26,
267,
1249,
275,
1689,
409,
13,
873,
13,
1287,
13,
262,
13,
578,
401,
333,
14,
923,
8,
17,
395,
333,
14,
923,
8,
18,
430,
435,
1249,
272,
587,
26,
267,
1249,
275,
1689,
409,
13,
873,
13,
1287,
401,
536,
9,
435,
1249,
339,
372,
330,
16997,
14,
1250,
2031,
589,
9,
421,
199,
318,
1240,
63,
16997,
63,
1593,
8,
354,
12,
627,
589,
304,
339,
333,
275,
485,
5005,
63,
16997,
493,
63,
460,
63,
2200,
14,
1431,
8,
354,
9,
272,
340,
333,
26,
267,
1249,
275,
1689,
1250,
13,
262,
13,
578,
401,
333,
14,
923,
8,
17,
395,
333,
14,
923,
8,
18,
430,
435,
1249,
267,
372,
330,
16997,
14,
1250,
2031,
589,
9,
272,
587,
26,
267,
372,
330,
16997,
14,
1250,
2031,
1332,
354,
4258,
435,
1249,
430,
199,
199,
363,
585,
63,
344,
275,
378,
199,
363,
1548,
63,
475,
63,
16997,
275,
1052,
199,
363,
16997,
63,
475,
63,
1548,
275,
1052,
199,
199,
318,
574,
63,
475,
63,
16997,
8,
585,
12,
3102,
29,
797,
304,
272,
408,
27142,
282,
1526,
370,
10618,
370,
282,
2018,
574,
6272,
1603,
455,
2637,
1233,
14,
339,
710,
1526,
365,
562,
264,
590,
282,
1059,
626,
883,
506,
3032,
6818,
315,
1603,
455,
1233,
436,
272,
21356,
3032,
1771,
14,
2104,
2893,
12,
781,
5594,
2934,
370,
986,
16158,
1084,
272,
1256,
370,
282,
1947,
805,
436,
652,
5594,
21356,
1240,
1771,
272,
370,
5791,
63,
1375,
14,
525,
63,
4511,
63,
460,
63,
1861,
12,
9476,
314,
2011,
1256,
14,
339,
2104,
1338,
626,
787,
3992,
12,
781,
7171,
2597,
1852,
1021,
3102,
4550,
272,
687,
1603,
455,
14,
339,
3390,
626,
642,
365,
5784,
370,
1852,
282,
4546,
1655,
402,
3411,
1603,
455,
1725,
1736,
14,
272,
961,
20907,
1077,
440,
506,
1202,
370,
8298,
12,
503,
587,
314,
10238,
22477,
14948,
402,
272,
2018,
1844,
911,
506,
325,
323,
78,
14,
272,
408,
339,
2288,
636,
585,
63,
344,
339,
519,
275,
636,
1548,
63,
475,
63,
16997,
14,
362,
8,
585,
12,
488,
9,
272,
340,
519,
26,
267,
372,
519,
339,
16629,
63,
354,
275,
283,
5680,
8650,
435,
620,
3460,
585,
63,
344,
9,
272,
636,
585,
63,
344,
275,
636,
585,
63,
344,
435,
413,
272,
636,
1548,
63,
475,
63,
16997,
59,
585,
61,
275,
16629,
63,
354,
272,
636,
16997,
63,
475,
63,
1548,
59,
23028,
63,
354,
61,
275,
574,
339,
340,
3102,
436,
730,
8,
585,
9,
508,
2943,
14,
3244,
804,
26,
267,
367,
901,
63,
354,
315,
2935,
8,
585,
304,
288,
901,
275,
2519,
8,
585,
12,
901,
63,
354,
9,
288,
340,
4550,
8,
698,
9,
436,
440,
901,
63,
354,
14,
2460,
16232,
2349,
355,
330,
16997,
14,
646,
63,
2200,
12398,
16629,
63,
354,
435,
14530,
435,
901,
63,
354,
12,
901,
9,
339,
372,
16629,
63,
354,
199,
199,
318,
2777,
63,
16997,
63,
475,
63,
585,
63,
4745,
8,
16997,
63,
585,
12,
2366,
63,
585,
304,
272,
636,
16997,
63,
475,
63,
1548,
59,
16997,
63,
585,
61,
275,
2366,
63,
585,
199,
199,
318,
1335,
455,
63,
475,
63,
585,
63,
11853,
8,
16997,
63,
585,
304,
339,
340,
730,
8,
16997,
63,
585,
9,
508,
730,
11986,
304,
267,
372,
636,
16997,
63,
475,
63,
1548,
14,
362,
8,
16997,
63,
585,
12,
1335,
455,
63,
585,
9,
272,
587,
26,
267,
372,
1335,
455,
63,
585,
199,
199,
318,
17408,
8,
1501,
304,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
smunaut/gnuradio
|
gnuradio-runtime/examples/network/dial_tone_sink.py
|
58
|
2479
|
#!/usr/bin/env python
#
# Copyright 2006,2007,2010 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from gnuradio import gr, audio
from gnuradio import blocks
from gnuradio.eng_option import eng_option
from optparse import OptionParser
class dial_tone_sink(gr.top_block):
def __init__(self, host, port, pkt_size, sample_rate, eof):
gr.top_block.__init__(self, "dial_tone_sink")
udp = blocks.udp_source(gr.sizeof_float, host, port, pkt_size, eof=eof)
sink = audio.sink(sample_rate)
self.connect(udp, sink)
if __name__ == '__main__':
parser = OptionParser(option_class=eng_option)
parser.add_option("", "--host", type="string", default="0.0.0.0",
help="local host name (domain name or IP address)")
parser.add_option("", "--port", type="int", default=65500,
help="port value to listen to for connection")
parser.add_option("", "--packet-size", type="int", default=1472,
help="packet size.")
parser.add_option("-r", "--sample-rate", type="int", default=8000,
help="audio signal sample rate [default=%default]")
parser.add_option("", "--no-eof", action="store_true", default=False,
help="don't send EOF on disconnect")
(options, args) = parser.parse_args()
if len(args) != 0:
parser.print_help()
raise SystemExit, 1
# Create an instance of a hierarchical block
top_block = dial_tone_sink(options.host, options.port,
options.packet_size, options.sample_rate,
not options.no_eof)
try:
# Run forever
top_block.run()
except KeyboardInterrupt:
# Ctrl-C exits
pass
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8315,
12,
9488,
12,
6542,
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,
10491,
199,
504,
24526,
492,
5664,
199,
504,
24526,
14,
7420,
63,
1422,
492,
20171,
63,
1422,
199,
504,
8691,
492,
13491,
199,
199,
533,
487,
279,
63,
84,
368,
63,
11279,
8,
2587,
14,
2119,
63,
1457,
304,
272,
347,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
19927,
63,
890,
12,
2690,
63,
1866,
12,
29403,
304,
267,
7192,
14,
2119,
63,
1457,
855,
826,
721,
277,
12,
298,
328,
279,
63,
84,
368,
63,
11279,
531,
267,
18419,
275,
5664,
14,
15036,
63,
1365,
8,
2587,
14,
12590,
63,
1609,
12,
1591,
12,
1844,
12,
19927,
63,
890,
12,
29403,
29,
11670,
9,
267,
19241,
275,
10491,
14,
11279,
8,
3271,
63,
1866,
9,
267,
291,
14,
2242,
8,
15036,
12,
19241,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1798,
275,
13491,
8,
1422,
63,
533,
29,
7420,
63,
1422,
9,
272,
1798,
14,
525,
63,
1422,
12398,
4320,
1102,
401,
730,
628,
875,
401,
849,
628,
16,
14,
16,
14,
16,
14,
16,
401,
1993,
1720,
628,
1832,
1591,
536,
334,
2261,
536,
503,
3531,
2287,
6320,
272,
1798,
14,
525,
63,
1422,
12398,
4320,
719,
401,
730,
628,
442,
401,
849,
29,
10027,
383,
12,
1993,
1720,
628,
719,
574,
370,
6938,
370,
367,
1950,
531,
272,
1798,
14,
525,
63,
1422,
12398,
4320,
6253,
13,
890,
401,
730,
628,
442,
401,
849,
29,
1079,
2819,
12,
1993,
1720,
628,
6253,
1568,
2685,
272,
1798,
14,
525,
63,
1422,
6096,
82,
401,
4320,
3271,
13,
1866,
401,
730,
628,
442,
401,
849,
29,
15214,
12,
1993,
1720,
628,
8130,
4673,
2690,
6634,
359,
885,
2458,
885,
12523,
272,
1798,
14,
525,
63,
1422,
12398,
4320,
889,
13,
11670,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
1993,
1720,
628,
13196,
1133,
3222,
9027,
641,
17639,
531,
272,
334,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
272,
340,
822,
8,
589,
9,
1137,
378,
26,
267,
1798,
14,
1361,
63,
3437,
342,
267,
746,
14838,
12,
413,
339,
327,
2790,
376,
1256,
402,
282,
24787,
1853,
272,
2746,
63,
1457,
275,
487,
279,
63,
84,
368,
63,
11279,
8,
1419,
14,
1102,
12,
1511,
14,
719,
12,
3044,
1511,
14,
6253,
63,
890,
12,
1511,
14,
3271,
63,
1866,
12,
3044,
440,
1511,
14,
889,
63,
11670,
9,
339,
862,
26,
267,
327,
3378,
28688,
267,
2746,
63,
1457,
14,
1065,
342,
272,
871,
13483,
26,
267,
327,
445,
7245,
13,
35,
20100,
267,
986,
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
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
1898,
8315,
12,
9488,
12,
6542,
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,
10491,
199,
504,
24526,
492,
5664,
199,
504,
24526,
14,
7420,
63,
1422,
492,
20171,
63,
1422,
199,
504,
8691,
492,
13491,
199,
199,
533,
487,
279,
63,
84,
368,
63,
11279,
8,
2587,
14,
2119,
63,
1457,
304,
272,
347,
636,
826,
721,
277,
12,
1591,
12,
1844,
12,
19927,
63,
890,
12,
2690,
63,
1866,
12,
29403,
304,
267,
7192,
14,
2119,
63,
1457,
855,
826,
721,
277,
12,
298,
328,
279,
63,
84,
368,
63,
11279,
531,
267,
18419,
275,
5664,
14,
15036,
63,
1365,
8,
2587,
14,
12590,
63,
1609,
12,
1591,
12,
1844,
12,
19927,
63,
890,
12,
29403,
29,
11670,
9,
267,
19241,
275,
10491,
14,
11279,
8,
3271,
63,
1866,
9,
267,
291,
14,
2242,
8,
15036,
12,
19241,
9,
199,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
1798,
275,
13491,
8,
1422,
63,
533,
29,
7420,
63,
1422,
9,
272,
1798,
14,
525,
63,
1422,
12398,
4320,
1102,
401,
730,
628,
875,
401,
849,
628,
16,
14,
16,
14,
16,
14,
16,
401,
1993,
1720,
628,
1832,
1591,
536,
334,
2261,
536,
503,
3531,
2287,
6320,
272,
1798,
14,
525,
63,
1422,
12398,
4320,
719,
401,
730,
628,
442,
401,
849,
29,
10027,
383,
12,
1993,
1720,
628,
719,
574,
370,
6938,
370,
367,
1950,
531,
272,
1798,
14,
525,
63,
1422,
12398,
4320,
6253,
13,
890,
401,
730,
628,
442,
401,
849,
29,
1079,
2819,
12,
1993,
1720,
628,
6253,
1568,
2685,
272,
1798,
14,
525,
63,
1422,
6096,
82,
401,
4320,
3271,
13,
1866,
401,
730,
628,
442,
401,
849,
29,
15214,
12,
1993,
1720,
628,
8130,
4673,
2690,
6634,
359,
885,
2458,
885,
12523,
272,
1798,
14,
525,
63,
1422,
12398,
4320,
889,
13,
11670,
401,
1595,
628,
1617,
63,
2052,
401,
849,
29,
797,
12,
1993,
1720,
628,
13196,
1133,
3222,
9027,
641,
17639,
531,
272,
334,
1419,
12,
1249,
9,
275,
1798,
14,
1122,
63,
589,
342,
272,
340,
822,
8,
589,
9,
1137,
378,
26,
267,
1798,
14,
1361,
63,
3437,
342,
267,
746,
14838,
12,
413,
339,
327,
2790,
376,
1256,
402,
282,
24787,
1853,
272,
2746,
63,
1457,
275,
487,
279,
63,
84,
368,
63,
11279,
8,
1419,
14,
1102,
12,
1511,
14,
719,
12,
3044,
1511,
14,
6253,
63,
890,
12,
1511,
14,
3271,
63,
1866,
12,
3044,
440,
1511,
14,
889,
63,
11670,
9,
339,
862,
26,
267,
327,
3378,
28688,
267,
2746,
63,
1457,
14,
1065,
342,
272,
871,
13483,
26,
267,
327,
445,
7245,
13,
35,
20100,
267,
986,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sebi-hgdata/ansible
|
lib/ansible/runner/lookup_plugins/dict.py
|
166
|
1329
|
# (c) 2014, Kent R. Spillner <kspillner@acm.org>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
from ansible.utils import safe_eval
import ansible.utils as utils
import ansible.errors as errors
def flatten_hash_to_list(terms):
ret = []
for key in terms:
ret.append({'key': key, 'value': terms[key]})
return ret
class LookupModule(object):
def __init__(self, basedir=None, **kwargs):
self.basedir = basedir
def run(self, terms, inject=None, **kwargs):
terms = utils.listify_lookup_plugin_terms(terms, self.basedir, inject)
if not isinstance(terms, dict):
raise errors.AnsibleError("with_dict expects a dict")
return flatten_hash_to_list(terms)
|
gpl-3.0
|
[
3,
334,
67,
9,
6927,
12,
1804,
484,
820,
14,
8360,
778,
1372,
665,
75,
681,
778,
1372,
32,
645,
77,
14,
1308,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
3242,
14,
1208,
492,
5048,
63,
2579,
199,
646,
3242,
14,
1208,
465,
3778,
199,
646,
3242,
14,
2550,
465,
2552,
199,
199,
318,
9378,
63,
2227,
63,
475,
63,
513,
8,
9187,
304,
272,
2203,
275,
942,
272,
367,
790,
315,
2895,
26,
267,
2203,
14,
740,
3252,
498,
356,
790,
12,
283,
585,
356,
2895,
59,
498,
13412,
272,
372,
2203,
199,
199,
533,
12785,
2377,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
19380,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
12484,
275,
19380,
339,
347,
1255,
8,
277,
12,
2895,
12,
16182,
29,
403,
12,
1011,
958,
304,
267,
2895,
275,
3778,
14,
513,
2021,
63,
3892,
63,
2718,
63,
9187,
8,
9187,
12,
291,
14,
12484,
12,
16182,
9,
398,
340,
440,
1228,
8,
9187,
12,
1211,
304,
288,
746,
2552,
14,
29107,
480,
1045,
63,
807,
14292,
282,
1211,
531,
398,
372,
9378,
63,
2227,
63,
475,
63,
513,
8,
9187,
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
] |
[
334,
67,
9,
6927,
12,
1804,
484,
820,
14,
8360,
778,
1372,
665,
75,
681,
778,
1372,
32,
645,
77,
14,
1308,
30,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
2622,
199,
3,
199,
3,
2622,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
2622,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
3180,
543,
2622,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
504,
3242,
14,
1208,
492,
5048,
63,
2579,
199,
646,
3242,
14,
1208,
465,
3778,
199,
646,
3242,
14,
2550,
465,
2552,
199,
199,
318,
9378,
63,
2227,
63,
475,
63,
513,
8,
9187,
304,
272,
2203,
275,
942,
272,
367,
790,
315,
2895,
26,
267,
2203,
14,
740,
3252,
498,
356,
790,
12,
283,
585,
356,
2895,
59,
498,
13412,
272,
372,
2203,
199,
199,
533,
12785,
2377,
8,
785,
304,
339,
347,
636,
826,
721,
277,
12,
19380,
29,
403,
12,
1011,
958,
304,
267,
291,
14,
12484,
275,
19380,
339,
347,
1255,
8,
277,
12,
2895,
12,
16182,
29,
403,
12,
1011,
958,
304,
267,
2895,
275,
3778,
14,
513,
2021,
63,
3892,
63,
2718,
63,
9187,
8,
9187,
12,
291,
14,
12484,
12,
16182,
9,
398,
340,
440,
1228,
8,
9187,
12,
1211,
304,
288,
746,
2552,
14,
29107,
480,
1045,
63,
807,
14292,
282,
1211,
531,
398,
372,
9378,
63,
2227,
63,
475,
63,
513,
8,
9187,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mice-software/maus
|
tests/py_unit/test_docstore/_test_root_document_store/test_control_message.py
|
1
|
3246
|
# This file is part of MAUS: http://micewww.pp.rl.ac.uk/projects/maus
#
# MAUS 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.
#
# MAUS 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 MAUS. If not, see <http://www.gnu.org/licenses/>.
"""
Tests for control message
"""
import json
import unittest
from docstore.root_document_store import ControlMessage
class ControlMessageTest(unittest.TestCase): # pylint: disable=R0904
"""
Tests for the ControlMessage
"""
def setUp(self): # pylint: disable=C0103
"""
Setup the ControlMessage
"""
self.json_doc = {"class_name":"class", "function":"fnc",
"args":[1, 2, 3],
"keywd_args":{"1":1, "2":2}, "return_value":True,
"errors":{"error":"test"}, "acknowledge":True, "id":1}
def test_init(self):
"""
Test ControlMessage initialisation
"""
ctrl = ControlMessage()
self.assertEqual(ctrl.class_name, "")
self.assertEqual(ctrl.function, "")
self.assertEqual(ctrl.args, [])
self.assertEqual(ctrl.keywd_args, {})
self.assertEqual(ctrl.return_value, None)
self.assertEqual(ctrl.errors, {})
self.assertEqual(ctrl.acknowledge, None)
self.assertEqual(ctrl.data, [])
ctrl = ControlMessage("class", "fnc", [1, 2, 3], {"1":1, "2":2},
["a", "b"])
self.assertEqual(ctrl.class_name, "class")
self.assertEqual(ctrl.function, "fnc")
self.assertEqual(ctrl.args, [1, 2, 3])
self.assertEqual(ctrl.keywd_args, {"1":1, "2":2})
self.assertEqual(ctrl.return_value, None)
self.assertEqual(ctrl.errors, {})
self.assertEqual(ctrl.acknowledge, None)
self.assertEqual(ctrl.data, ["a", "b"])
def test_json_repr(self):
"""
Test ControlMessage json format (new_from_json_repr and json_repr
"""
ctrl = ControlMessage.new_from_json_repr(self.json_doc, ["a", "b"])
json_test = ctrl.json_repr()
err = json.dumps(json_test, indent=2)+"\n\n"+\
json.dumps(self.json_doc, indent=2)
self.assertEqual(json_test, self.json_doc, msg=err)
def test_new_from_root(self):
"""
Check that we can create a ROOT TMessage from ControlMessage
Due to the usual obscure, undocumented behaviour of ROOT, I can't parse
a ROOT TMessage back into a ControlMessage as the TMessage is in "Write
mode" and there doesnt seem to be any way to convert to "Read mode"
safely without sending the message.
"""
ctrl_ref = ControlMessage.new_from_json_repr(self.json_doc, [])
ctrl_ref.root_repr()
if __name__ == "__main__":
unittest.main()
|
gpl-3.0
|
[
3,
221,
961,
570,
365,
1777,
402,
4828,
1668,
26,
1455,
921,
77,
1885,
1544,
14,
802,
14,
4308,
14,
645,
14,
3210,
15,
6776,
15,
391,
527,
199,
3,
221,
199,
3,
221,
4828,
1668,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
221,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
221,
4828,
1668,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
3180,
543,
4828,
1668,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
2925,
367,
3304,
1245,
199,
624,
199,
199,
646,
2022,
199,
646,
2882,
199,
199,
504,
1382,
1617,
14,
1231,
63,
3554,
63,
1617,
492,
8612,
2209,
199,
199,
533,
8612,
2209,
774,
8,
2796,
14,
1746,
304,
327,
4287,
26,
3507,
29,
50,
1643,
966,
272,
408,
272,
6496,
367,
314,
8612,
2209,
272,
408,
272,
347,
3613,
8,
277,
304,
327,
4287,
26,
3507,
29,
35,
28399,
267,
408,
267,
12439,
314,
8612,
2209,
267,
408,
267,
291,
14,
1001,
63,
1301,
275,
2420,
533,
63,
354,
5122,
533,
401,
298,
1593,
5122,
2324,
67,
401,
15324,
298,
589,
19086,
17,
12,
499,
12,
650,
467,
490,
298,
498,
2989,
63,
589,
18517,
17,
582,
17,
12,
298,
18,
582,
18,
1386,
298,
1107,
63,
585,
582,
549,
12,
15324,
298,
2550,
18517,
705,
5122,
396,
6018,
298,
564,
23504,
582,
549,
12,
298,
344,
582,
17,
93,
339,
347,
511,
63,
826,
8,
277,
304,
267,
408,
267,
1379,
8612,
2209,
2536,
19914,
267,
408,
267,
15427,
275,
8612,
2209,
342,
267,
291,
14,
629,
8,
12476,
14,
533,
63,
354,
12,
6899,
267,
291,
14,
629,
8,
12476,
14,
1593,
12,
6899,
267,
291,
14,
629,
8,
12476,
14,
589,
12,
3073,
267,
291,
14,
629,
8,
12476,
14,
498,
2989,
63,
589,
12,
5009,
267,
291,
14,
629,
8,
12476,
14,
1107,
63,
585,
12,
488,
9,
267,
291,
14,
629,
8,
12476,
14,
2550,
12,
5009,
267,
291,
14,
629,
8,
12476,
14,
564,
23504,
12,
488,
9,
267,
291,
14,
629,
8,
12476,
14,
576,
12,
3073,
398,
15427,
275,
8612,
2209,
480,
533,
401,
298,
2324,
67,
401,
359,
17,
12,
499,
12,
650,
467,
2420,
17,
582,
17,
12,
298,
18,
582,
18,
1386,
2892,
2097,
65,
401,
298,
66,
3135,
267,
291,
14,
629,
8,
12476,
14,
533,
63,
354,
12,
298,
533,
531,
267,
291,
14,
629,
8,
12476,
14,
1593,
12,
298,
2324,
67,
531,
267,
291,
14,
629,
8,
12476,
14,
589,
12,
359,
17,
12,
499,
12,
650,
566,
267,
291,
14,
629,
8,
12476,
14,
498,
2989,
63,
589,
12,
2420,
17,
582,
17,
12,
298,
18,
582,
18,
1552,
267,
291,
14,
629,
8,
12476,
14,
1107,
63,
585,
12,
488,
9,
267,
291,
14,
629,
8,
12476,
14,
2550,
12,
5009,
267,
291,
14,
629,
8,
12476,
14,
564,
23504,
12,
488,
9,
267,
291,
14,
629,
8,
12476,
14,
576,
12,
2097,
65,
401,
298,
66,
3135,
339,
347,
511,
63,
1001,
63,
2722,
8,
277,
304,
267,
408,
267,
1379,
8612,
2209,
2022,
1475,
334,
1222,
63,
504,
63,
1001,
63,
2722,
436,
2022,
63,
2722,
267,
408,
267,
15427,
275,
8612,
2209,
14,
1222,
63,
504,
63,
1001,
63,
2722,
8,
277,
14,
1001,
63,
1301,
12,
2097,
65,
401,
298,
66,
3135,
267,
2022,
63,
396,
275,
15427,
14,
1001,
63,
2722,
342,
267,
2329,
275,
2022,
14,
4180,
8,
1001,
63,
396,
12,
4363,
29,
18,
6393,
3212,
78,
60,
78,
7709,
60,
1598,
2022,
14,
4180,
8,
277,
14,
1001,
63,
1301,
12,
4363,
29,
18,
9,
267,
291,
14,
629,
8,
1001,
63,
396,
12,
291,
14,
1001,
63,
1301,
12,
1499,
29,
1508,
9,
339,
347,
511,
63,
1222,
63,
504,
63,
1231,
8,
277,
304,
267,
408,
267,
2670,
626,
781,
883,
1218,
282,
16547,
377,
2209,
687,
8612,
2209,
398,
25855,
370,
314,
20195,
2607,
551,
608,
12,
625,
29383,
13942,
402,
16547,
12,
473,
883,
1133,
2198,
267,
282,
16547,
377,
2209,
1771,
1901,
282,
8612,
2209,
465,
314,
377,
2209,
365,
315,
298,
3534,
267,
818,
2,
436,
2337,
1630,
343,
17021,
370,
506,
1263,
4340,
370,
3957,
370,
298,
3284,
818,
2,
267,
19353,
1928,
10209,
314,
1245,
14,
4960,
408,
267,
15427,
63,
1121,
275,
8612,
2209,
14,
1222,
63,
504,
63,
1001,
63,
2722,
8,
277,
14,
1001,
63,
1301,
12,
3073,
267,
15427,
63,
1121,
14,
1231,
63,
2722,
342,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
221,
961,
570,
365,
1777,
402,
4828,
1668,
26,
1455,
921,
77,
1885,
1544,
14,
802,
14,
4308,
14,
645,
14,
3210,
15,
6776,
15,
391,
527,
199,
3,
221,
199,
3,
221,
4828,
1668,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
221,
652,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
3,
221,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
3,
221,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
221,
199,
3,
221,
4828,
1668,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
221,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
221,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
221,
1664,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
221,
199,
3,
221,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
1696,
1684,
844,
199,
3,
221,
3180,
543,
4828,
1668,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
624,
199,
2925,
367,
3304,
1245,
199,
624,
199,
199,
646,
2022,
199,
646,
2882,
199,
199,
504,
1382,
1617,
14,
1231,
63,
3554,
63,
1617,
492,
8612,
2209,
199,
199,
533,
8612,
2209,
774,
8,
2796,
14,
1746,
304,
327,
4287,
26,
3507,
29,
50,
1643,
966,
272,
408,
272,
6496,
367,
314,
8612,
2209,
272,
408,
272,
347,
3613,
8,
277,
304,
327,
4287,
26,
3507,
29,
35,
28399,
267,
408,
267,
12439,
314,
8612,
2209,
267,
408,
267,
291,
14,
1001,
63,
1301,
275,
2420,
533,
63,
354,
5122,
533,
401,
298,
1593,
5122,
2324,
67,
401,
15324,
298,
589,
19086,
17,
12,
499,
12,
650,
467,
490,
298,
498,
2989,
63,
589,
18517,
17,
582,
17,
12,
298,
18,
582,
18,
1386,
298,
1107,
63,
585,
582,
549,
12,
15324,
298,
2550,
18517,
705,
5122,
396,
6018,
298,
564,
23504,
582,
549,
12,
298,
344,
582,
17,
93,
339,
347,
511,
63,
826,
8,
277,
304,
267,
408,
267,
1379,
8612,
2209,
2536,
19914,
267,
408,
267,
15427,
275,
8612,
2209,
342,
267,
291,
14,
629,
8,
12476,
14,
533,
63,
354,
12,
6899,
267,
291,
14,
629,
8,
12476,
14,
1593,
12,
6899,
267,
291,
14,
629,
8,
12476,
14,
589,
12,
3073,
267,
291,
14,
629,
8,
12476,
14,
498,
2989,
63,
589,
12,
5009,
267,
291,
14,
629,
8,
12476,
14,
1107,
63,
585,
12,
488,
9,
267,
291,
14,
629,
8,
12476,
14,
2550,
12,
5009,
267,
291,
14,
629,
8,
12476,
14,
564,
23504,
12,
488,
9,
267,
291,
14,
629,
8,
12476,
14,
576,
12,
3073,
398,
15427,
275,
8612,
2209,
480,
533,
401,
298,
2324,
67,
401,
359,
17,
12,
499,
12,
650,
467,
2420,
17,
582,
17,
12,
298,
18,
582,
18,
1386,
2892,
2097,
65,
401,
298,
66,
3135,
267,
291,
14,
629,
8,
12476,
14,
533,
63,
354,
12,
298,
533,
531,
267,
291,
14,
629,
8,
12476,
14,
1593,
12,
298,
2324,
67,
531,
267,
291,
14,
629,
8,
12476,
14,
589,
12,
359,
17,
12,
499,
12,
650,
566,
267,
291,
14,
629,
8,
12476,
14,
498,
2989,
63,
589,
12,
2420,
17,
582,
17,
12,
298,
18,
582,
18,
1552,
267,
291,
14,
629,
8,
12476,
14,
1107,
63,
585,
12,
488,
9,
267,
291,
14,
629,
8,
12476,
14,
2550,
12,
5009,
267,
291,
14,
629,
8,
12476,
14,
564,
23504,
12,
488,
9,
267,
291,
14,
629,
8,
12476,
14,
576,
12,
2097,
65,
401,
298,
66,
3135,
339,
347,
511,
63,
1001,
63,
2722,
8,
277,
304,
267,
408,
267,
1379,
8612,
2209,
2022,
1475,
334,
1222,
63,
504,
63,
1001,
63,
2722,
436,
2022,
63,
2722,
267,
408,
267,
15427,
275,
8612,
2209,
14,
1222,
63,
504,
63,
1001,
63,
2722,
8,
277,
14,
1001,
63,
1301,
12,
2097,
65,
401,
298,
66,
3135,
267,
2022,
63,
396,
275,
15427,
14,
1001,
63,
2722,
342,
267,
2329,
275,
2022,
14,
4180,
8,
1001,
63,
396,
12,
4363,
29,
18,
6393,
3212,
78,
60,
78,
7709,
60,
1598,
2022,
14,
4180,
8,
277,
14,
1001,
63,
1301,
12,
4363,
29,
18,
9,
267,
291,
14,
629,
8,
1001,
63,
396,
12,
291,
14,
1001,
63,
1301,
12,
1499,
29,
1508,
9,
339,
347,
511,
63,
1222,
63,
504,
63,
1231,
8,
277,
304,
267,
408,
267,
2670,
626,
781,
883,
1218,
282,
16547,
377,
2209,
687,
8612,
2209,
398,
25855,
370,
314,
20195,
2607,
551,
608,
12,
625,
29383,
13942,
402,
16547,
12,
473,
883,
1133,
2198,
267,
282,
16547,
377,
2209,
1771,
1901,
282,
8612,
2209,
465,
314,
377,
2209,
365,
315,
298,
3534,
267,
818,
2,
436,
2337,
1630,
343,
17021,
370,
506,
1263,
4340,
370,
3957,
370,
298,
3284,
818,
2,
267,
19353,
1928,
10209,
314,
1245,
14,
4960,
408,
267,
15427,
63,
1121,
275,
8612,
2209,
14,
1222,
63,
504,
63,
1001,
63,
2722,
8,
277,
14,
1001,
63,
1301,
12,
3073,
267,
15427,
63,
1121,
14,
1231,
63,
2722,
342,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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"native" vim theme.
:copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
from pygments.style import Style
from pygments.token import Keyword, Name, Comment, String, Error, \
Number, Operator, Generic, Token, Whitespace
class NativeStyle(Style):
"""
Pygments version of the "native" vim theme.
"""
background_color = '#202020'
highlight_color = '#404040'
styles = {
Token: '#d0d0d0',
Whitespace: '#666666',
Comment: 'italic #999999',
Comment.Preproc: 'noitalic bold #cd2828',
Comment.Special: 'noitalic bold #e50808 bg:#520000',
Keyword: 'bold #6ab825',
Keyword.Pseudo: 'nobold',
Operator.Word: 'bold #6ab825',
String: '#ed9d13',
String.Other: '#ffa500',
Number: '#3677a9',
Name.Builtin: '#24909d',
Name.Variable: '#40ffff',
Name.Constant: '#40ffff',
Name.Class: 'underline #447fcf',
Name.Function: '#447fcf',
Name.Namespace: 'underline #447fcf',
Name.Exception: '#bbbbbb',
Name.Tag: 'bold #6ab825',
Name.Attribute: '#bbbbbb',
Name.Decorator: '#ffa500',
Generic.Heading: 'bold #ffffff',
Generic.Subheading: 'underline #ffffff',
Generic.Deleted: '#d22323',
Generic.Inserted: '#589819',
Generic.Error: '#d22323',
Generic.Emph: 'italic',
Generic.Strong: 'bold',
Generic.Prompt: '#aaaaaa',
Generic.Output: '#cccccc',
Generic.Traceback: '#d22323',
Error: 'bg:#e3d2d2 #a61717'
}
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12955,
14,
6106,
272,
18294,
2878,
1714,
339,
13277,
1015,
402,
3002,
298,
6106,
2,
6695,
8879,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7409,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
504,
13277,
14,
2487,
492,
19442,
199,
504,
13277,
14,
1418,
492,
6431,
12,
2812,
12,
6819,
12,
2624,
12,
4520,
12,
971,
1362,
4860,
12,
11013,
12,
8307,
12,
8767,
12,
24403,
421,
199,
533,
653,
1905,
6609,
8,
6609,
304,
272,
408,
272,
14493,
1015,
402,
314,
298,
6106,
2,
6695,
8879,
14,
272,
408,
339,
8020,
63,
2326,
275,
3943,
4999,
10173,
7,
272,
11850,
63,
2326,
275,
3943,
5188,
11189,
7,
339,
15725,
275,
469,
267,
8767,
26,
4519,
3943,
68,
16,
68,
16,
68,
16,
297,
267,
24403,
26,
260,
3943,
6997,
1272,
297,
398,
6819,
26,
3322,
283,
21843,
327,
20036,
297,
267,
6819,
14,
19285,
26,
259,
283,
889,
21843,
17268,
327,
2866,
1651,
1651,
297,
267,
6819,
14,
12246,
26,
259,
283,
889,
21843,
17268,
327,
69,
1400,
11292,
12994,
15596,
2528,
993,
297,
398,
6431,
26,
3322,
283,
9771,
327,
22,
371,
29208,
297,
267,
6431,
14,
23414,
26,
258,
283,
889,
9771,
297,
267,
11013,
14,
10155,
26,
420,
283,
9771,
327,
22,
371,
29208,
297,
398,
2624,
26,
3777,
3943,
379,
25,
68,
969,
297,
267,
2624,
14,
8632,
26,
755,
3943,
556,
65,
5783,
297,
398,
4860,
26,
3777,
3943,
1344,
1138,
65,
25,
297,
398,
2812,
14,
12306,
26,
755,
3943,
11032,
1643,
68,
297,
267,
2812,
14,
2773,
26,
420,
3943,
2167,
4717,
297,
267,
2812,
14,
9737,
26,
420,
3943,
2167,
4717,
297,
267,
2812,
14,
2543,
26,
260,
283,
24396,
327,
20773,
70,
2177,
297,
267,
2812,
14,
3481,
26,
420,
3943,
20773,
70,
2177,
297,
267,
2812,
14,
8814,
26,
258,
283,
24396,
327,
20773,
70,
2177,
297,
267,
2812,
14,
1726,
26,
258,
3943,
14923,
2501,
297,
267,
2812,
14,
1931,
26,
3698,
283,
9771,
327,
22,
371,
29208,
297,
267,
2812,
14,
1646,
26,
258,
3943,
14923,
2501,
297,
267,
2812,
14,
14946,
26,
258,
3943,
556,
65,
5783,
297,
398,
8307,
14,
23818,
26,
259,
283,
9771,
327,
12596,
297,
267,
8307,
14,
2610,
13983,
26,
283,
24396,
327,
12596,
297,
267,
8307,
14,
17735,
26,
259,
3943,
68,
1081,
13905,
297,
267,
8307,
14,
607,
9449,
26,
257,
3943,
21,
13176,
1167,
297,
267,
8307,
14,
547,
26,
420,
3943,
68,
1081,
13905,
297,
267,
8307,
14,
37,
311,
72,
26,
755,
283,
21843,
297,
267,
8307,
14,
2848,
951,
26,
258,
283,
9771,
297,
267,
8307,
14,
20430,
26,
258,
3943,
6000,
2158,
297,
267,
8307,
14,
2959,
26,
258,
3943,
13720,
2055,
297,
267,
8307,
14,
15905,
26,
221,
3943,
68,
1081,
13905,
297,
398,
4520,
26,
4519,
283,
6856,
15596,
69,
19,
68,
18,
68,
18,
327,
65,
28630,
1196,
7,
272,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12955,
14,
6106,
272,
18294,
2878,
1714,
339,
13277,
1015,
402,
3002,
298,
6106,
2,
6695,
8879,
14,
339,
520,
7307,
26,
1898,
8315,
13,
7409,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
199,
199,
504,
13277,
14,
2487,
492,
19442,
199,
504,
13277,
14,
1418,
492,
6431,
12,
2812,
12,
6819,
12,
2624,
12,
4520,
12,
971,
1362,
4860,
12,
11013,
12,
8307,
12,
8767,
12,
24403,
421,
199,
533,
653,
1905,
6609,
8,
6609,
304,
272,
408,
272,
14493,
1015,
402,
314,
298,
6106,
2,
6695,
8879,
14,
272,
408,
339,
8020,
63,
2326,
275,
3943,
4999,
10173,
7,
272,
11850,
63,
2326,
275,
3943,
5188,
11189,
7,
339,
15725,
275,
469,
267,
8767,
26,
4519,
3943,
68,
16,
68,
16,
68,
16,
297,
267,
24403,
26,
260,
3943,
6997,
1272,
297,
398,
6819,
26,
3322,
283,
21843,
327,
20036,
297,
267,
6819,
14,
19285,
26,
259,
283,
889,
21843,
17268,
327,
2866,
1651,
1651,
297,
267,
6819,
14,
12246,
26,
259,
283,
889,
21843,
17268,
327,
69,
1400,
11292,
12994,
15596,
2528,
993,
297,
398,
6431,
26,
3322,
283,
9771,
327,
22,
371,
29208,
297,
267,
6431,
14,
23414,
26,
258,
283,
889,
9771,
297,
267,
11013,
14,
10155,
26,
420,
283,
9771,
327,
22,
371,
29208,
297,
398,
2624,
26,
3777,
3943,
379,
25,
68,
969,
297,
267,
2624,
14,
8632,
26,
755,
3943,
556,
65,
5783,
297,
398,
4860,
26,
3777,
3943,
1344,
1138,
65,
25,
297,
398,
2812,
14,
12306,
26,
755,
3943,
11032,
1643,
68,
297,
267,
2812,
14,
2773,
26,
420,
3943,
2167,
4717,
297,
267,
2812,
14,
9737,
26,
420,
3943,
2167,
4717,
297,
267,
2812,
14,
2543,
26,
260,
283,
24396,
327,
20773,
70,
2177,
297,
267,
2812,
14,
3481,
26,
420,
3943,
20773,
70,
2177,
297,
267,
2812,
14,
8814,
26,
258,
283,
24396,
327,
20773,
70,
2177,
297,
267,
2812,
14,
1726,
26,
258,
3943,
14923,
2501,
297,
267,
2812,
14,
1931,
26,
3698,
283,
9771,
327,
22,
371,
29208,
297,
267,
2812,
14,
1646,
26,
258,
3943,
14923,
2501,
297,
267,
2812,
14,
14946,
26,
258,
3943,
556,
65,
5783,
297,
398,
8307,
14,
23818,
26,
259,
283,
9771,
327,
12596,
297,
267,
8307,
14,
2610,
13983,
26,
283,
24396,
327,
12596,
297,
267,
8307,
14,
17735,
26,
259,
3943,
68,
1081,
13905,
297,
267,
8307,
14,
607,
9449,
26,
257,
3943,
21,
13176,
1167,
297,
267,
8307,
14,
547,
26,
420,
3943,
68,
1081,
13905,
297,
267,
8307,
14,
37,
311,
72,
26,
755,
283,
21843,
297,
267,
8307,
14,
2848,
951,
26,
258,
283,
9771,
297,
267,
8307,
14,
20430,
26,
258,
3943,
6000,
2158,
297,
267,
8307,
14,
2959,
26,
258,
3943,
13720,
2055,
297,
267,
8307,
14,
15905,
26,
221,
3943,
68,
1081,
13905,
297,
398,
4520,
26,
4519,
283,
6856,
15596,
69,
19,
68,
18,
68,
18,
327,
65,
28630,
1196,
7,
272,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
jdjnovak/WaffleTalk
|
WaffleTalk/functions.py
|
1
|
2627
|
#!/usr/bin/python3
import random
GLOBAL_NULLS = "abcdefghijklmnopqrstuvwxyz"
def encrypt(message, key):
KEY = key.strip()
spacelessmessage = message.replace(" ","")
strippedmessage = spacelessmessage.strip()
WORK_MSG = strippedmessage.lower() #Use this as workable string
SORTED_KEY = sortKey(KEY)
NUM_NULLS = len(KEY) - (len(WORK_MSG) % len(KEY))
for i in range(NUM_NULLS):
randNum = int(random.random() * 26)
WORK_MSG += GLOBAL_NULLS[randNum]
'''
The number of characters in the message is made to be a
multiple of the number of characters in the KEY by adding
the null characters
Hence, Length of WORK_MSG / Length of Key will give one
the amount of rows added to the SORTED_KEY array
'''
for i in range(int(len(WORK_MSG) / len(KEY))):
for j in range(len(SORTED_KEY)):
SORTED_KEY[j].append(WORK_MSG[(i*len(KEY)) + j])
for i in range(len(SORTED_KEY)):
swapFirstTwo(SORTED_KEY[i])
SORTED_KEY = sorted(SORTED_KEY)
encryptedmessage = ""
for i in range(len(SORTED_KEY)):
for j in range(2, len(SORTED_KEY[0])):
encryptedmessage += str(SORTED_KEY[i][j])
encryptedmessage += " "
print(encryptedmessage)
return SORTED_KEY
def decrypt(message, key):
MSG = message
KEY_ARY = sortKey(key)
for subary in KEY_ARY:
swapFirstTwo(subary)
KEY_ARY = sorted(KEY_ARY)
ARY_IND = 0
for char in MSG:
if char == " ":
ARY_IND += 1
else:
KEY_ARY[ARY_IND].append(char)
for subary in KEY_ARY:
swapFirstTwo(subary)
KEY_ARY = sorted(KEY_ARY)
print_str = ""
for i in range(2, len(KEY_ARY[0])):
for j in range(len(KEY_ARY)):
print_str += KEY_ARY[j][i]
print_str += " "
print(print_str)
return KEY_ARY
def sortKey(key): #string -> multi-dim. array
tempkey = key
ary = []
# 1) Add each letter to the array, then
# sort the arrays based on alphabetical order
count = 0
while len(tempkey) > 0:
ary.append([tempkey[0], count])
count += 1
tempkey = tempkey[1:]
# 2) Swap the letters now so the numbers are first
for subary in ary:
swapFirstTwo(subary)
return ary
def unsortKey(sortedkey): # (MultiDim-array) -> Same array, but sorted
'''
TODO: Sort Key array based on integer value
i. if ARRAY[0][0] is the int, sort, else swapFirstTwo then sort
'''
def swapFirstTwo(array):
array[0], array[1] = array[1], array[0]
|
mit
|
[
3381,
2647,
15,
1393,
15,
1548,
19,
199,
199,
646,
2196,
199,
199,
13808,
63,
8084,
51,
275,
298,
23459,
2,
199,
199,
318,
14645,
8,
1188,
12,
790,
304,
272,
9301,
275,
790,
14,
1913,
342,
272,
4601,
2003,
1188,
275,
1245,
14,
1814,
480,
3872,
7230,
272,
14489,
1188,
275,
4601,
2003,
1188,
14,
1913,
342,
339,
29557,
43,
63,
9740,
275,
14489,
1188,
14,
2325,
342,
327,
6119,
642,
465,
1736,
461,
1059,
272,
428,
2596,
1149,
63,
3078,
275,
4069,
1197,
8,
3078,
9,
272,
11576,
63,
8084,
51,
275,
822,
8,
3078,
9,
446,
334,
552,
8,
8406,
63,
9740,
9,
450,
822,
8,
3078,
430,
339,
367,
284,
315,
1425,
8,
7125,
63,
8084,
51,
304,
267,
10261,
5667,
275,
1109,
8,
2355,
14,
2355,
342,
627,
7875,
9,
267,
29557,
43,
63,
9740,
847,
598,
12667,
63,
8084,
51,
59,
3759,
5667,
61,
339,
1449,
267,
710,
1329,
402,
4110,
315,
314,
1245,
365,
6326,
370,
506,
282,
4960,
3663,
402,
314,
1329,
402,
4110,
315,
314,
9301,
701,
7791,
267,
314,
2973,
4110,
398,
869,
4894,
12,
19893,
402,
29557,
43,
63,
9740,
1182,
19893,
402,
2606,
911,
8120,
1373,
267,
314,
5982,
402,
4730,
3483,
370,
314,
428,
2596,
1149,
63,
3078,
1625,
272,
1449,
272,
367,
284,
315,
1425,
8,
442,
8,
552,
8,
8406,
63,
9740,
9,
1182,
822,
8,
3078,
15206,
267,
367,
1335,
315,
1425,
8,
552,
8,
23447,
1149,
63,
3078,
2298,
288,
428,
2596,
1149,
63,
3078,
59,
74,
1055,
740,
8,
8406,
63,
9740,
7528,
73,
10,
552,
8,
3078,
430,
435,
1335,
566,
339,
367,
284,
315,
1425,
8,
552,
8,
23447,
1149,
63,
3078,
2298,
267,
11413,
7147,
11467,
8,
23447,
1149,
63,
3078,
59,
73,
566,
272,
428,
2596,
1149,
63,
3078,
275,
3355,
8,
23447,
1149,
63,
3078,
9,
339,
14862,
1188,
275,
3087,
272,
367,
284,
315,
1425,
8,
552,
8,
23447,
1149,
63,
3078,
2298,
267,
367,
1335,
315,
1425,
8,
18,
12,
822,
8,
23447,
1149,
63,
3078,
59,
16,
18710,
288,
14862,
1188,
847,
620,
8,
23447,
1149,
63,
3078,
59,
73,
1527,
74,
566,
267,
14862,
1188,
847,
298,
298,
2286,
870,
8,
15078,
1188,
9,
272,
372,
428,
2596,
1149,
63,
3078,
199,
199,
318,
20090,
8,
1188,
12,
790,
304,
272,
23620,
275,
1245,
272,
9301,
63,
4392,
275,
4069,
1197,
8,
498,
9,
272,
367,
1007,
695,
315,
9301,
63,
4392,
26,
267,
11413,
7147,
11467,
8,
954,
695,
9,
339,
9301,
63,
4392,
275,
3355,
8,
3078,
63,
4392,
9,
2286,
4160,
57,
63,
3192,
275,
378,
272,
367,
1495,
315,
23620,
26,
267,
340,
1495,
508,
298,
7244,
288,
4160,
57,
63,
3192,
847,
413,
267,
587,
26,
288,
9301,
63,
4392,
59,
4392,
63,
3192,
1055,
740,
8,
1560,
9,
339,
367,
1007,
695,
315,
9301,
63,
4392,
26,
267,
11413,
7147,
11467,
8,
954,
695,
9,
339,
9301,
63,
4392,
275,
3355,
8,
3078,
63,
4392,
9,
2286,
870,
63,
495,
275,
3087,
272,
367,
284,
315,
1425,
8,
18,
12,
822,
8,
3078,
63,
4392,
59,
16,
18710,
267,
367,
1335,
315,
1425,
8,
552,
8,
3078,
63,
4392,
2298,
288,
870,
63,
495,
847,
9301,
63,
4392,
59,
74,
1527,
73,
61,
288,
870,
63,
495,
847,
298,
298,
2286,
870,
8,
1361,
63,
495,
9,
272,
372,
9301,
63,
4392,
199,
199,
318,
4069,
1197,
8,
498,
304,
327,
875,
1035,
3510,
13,
3572,
14,
1625,
272,
2388,
498,
275,
790,
272,
601,
89,
275,
942,
339,
327,
413,
9,
2654,
1924,
8082,
370,
314,
1625,
12,
2066,
5591,
327,
259,
4069,
314,
6572,
4079,
641,
23331,
3294,
1865,
272,
2338,
275,
378,
272,
1830,
822,
8,
808,
498,
9,
690,
378,
26,
267,
601,
89,
14,
740,
779,
808,
498,
59,
16,
467,
2338,
566,
267,
2338,
847,
413,
267,
2388,
498,
275,
2388,
498,
59,
17,
2938,
339,
327,
499,
9,
16666,
439,
314,
14435,
3063,
880,
314,
5579,
787,
1642,
272,
367,
1007,
695,
315,
601,
89,
26,
267,
11413,
7147,
11467,
8,
954,
695,
9,
339,
372,
601,
89,
199,
199,
318,
625,
3191,
1197,
8,
5917,
498,
304,
327,
334,
3947,
19156,
13,
1144,
9,
1035,
14766,
1625,
12,
1325,
3355,
272,
1449,
5591,
3254,
26,
16722,
2606,
1625,
4079,
641,
3000,
574,
489,
284,
14,
340,
4160,
2847,
57,
59,
16,
1527,
16,
61,
365,
314,
1109,
12,
4069,
12,
587,
11413,
7147,
11467,
2066,
4069,
272,
1449,
199,
199,
318,
11413,
7147,
11467,
8,
1144,
304,
272,
1625,
59,
16,
467,
1625,
59,
17,
61,
275,
1625,
59,
17,
467,
1625,
59,
16,
61,
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
] |
[
2647,
15,
1393,
15,
1548,
19,
199,
199,
646,
2196,
199,
199,
13808,
63,
8084,
51,
275,
298,
23459,
2,
199,
199,
318,
14645,
8,
1188,
12,
790,
304,
272,
9301,
275,
790,
14,
1913,
342,
272,
4601,
2003,
1188,
275,
1245,
14,
1814,
480,
3872,
7230,
272,
14489,
1188,
275,
4601,
2003,
1188,
14,
1913,
342,
339,
29557,
43,
63,
9740,
275,
14489,
1188,
14,
2325,
342,
327,
6119,
642,
465,
1736,
461,
1059,
272,
428,
2596,
1149,
63,
3078,
275,
4069,
1197,
8,
3078,
9,
272,
11576,
63,
8084,
51,
275,
822,
8,
3078,
9,
446,
334,
552,
8,
8406,
63,
9740,
9,
450,
822,
8,
3078,
430,
339,
367,
284,
315,
1425,
8,
7125,
63,
8084,
51,
304,
267,
10261,
5667,
275,
1109,
8,
2355,
14,
2355,
342,
627,
7875,
9,
267,
29557,
43,
63,
9740,
847,
598,
12667,
63,
8084,
51,
59,
3759,
5667,
61,
339,
1449,
267,
710,
1329,
402,
4110,
315,
314,
1245,
365,
6326,
370,
506,
282,
4960,
3663,
402,
314,
1329,
402,
4110,
315,
314,
9301,
701,
7791,
267,
314,
2973,
4110,
398,
869,
4894,
12,
19893,
402,
29557,
43,
63,
9740,
1182,
19893,
402,
2606,
911,
8120,
1373,
267,
314,
5982,
402,
4730,
3483,
370,
314,
428,
2596,
1149,
63,
3078,
1625,
272,
1449,
272,
367,
284,
315,
1425,
8,
442,
8,
552,
8,
8406,
63,
9740,
9,
1182,
822,
8,
3078,
15206,
267,
367,
1335,
315,
1425,
8,
552,
8,
23447,
1149,
63,
3078,
2298,
288,
428,
2596,
1149,
63,
3078,
59,
74,
1055,
740,
8,
8406,
63,
9740,
7528,
73,
10,
552,
8,
3078,
430,
435,
1335,
566,
339,
367,
284,
315,
1425,
8,
552,
8,
23447,
1149,
63,
3078,
2298,
267,
11413,
7147,
11467,
8,
23447,
1149,
63,
3078,
59,
73,
566,
272,
428,
2596,
1149,
63,
3078,
275,
3355,
8,
23447,
1149,
63,
3078,
9,
339,
14862,
1188,
275,
3087,
272,
367,
284,
315,
1425,
8,
552,
8,
23447,
1149,
63,
3078,
2298,
267,
367,
1335,
315,
1425,
8,
18,
12,
822,
8,
23447,
1149,
63,
3078,
59,
16,
18710,
288,
14862,
1188,
847,
620,
8,
23447,
1149,
63,
3078,
59,
73,
1527,
74,
566,
267,
14862,
1188,
847,
298,
298,
2286,
870,
8,
15078,
1188,
9,
272,
372,
428,
2596,
1149,
63,
3078,
199,
199,
318,
20090,
8,
1188,
12,
790,
304,
272,
23620,
275,
1245,
272,
9301,
63,
4392,
275,
4069,
1197,
8,
498,
9,
272,
367,
1007,
695,
315,
9301,
63,
4392,
26,
267,
11413,
7147,
11467,
8,
954,
695,
9,
339,
9301,
63,
4392,
275,
3355,
8,
3078,
63,
4392,
9,
2286,
4160,
57,
63,
3192,
275,
378,
272,
367,
1495,
315,
23620,
26,
267,
340,
1495,
508,
298,
7244,
288,
4160,
57,
63,
3192,
847,
413,
267,
587,
26,
288,
9301,
63,
4392,
59,
4392,
63,
3192,
1055,
740,
8,
1560,
9,
339,
367,
1007,
695,
315,
9301,
63,
4392,
26,
267,
11413,
7147,
11467,
8,
954,
695,
9,
339,
9301,
63,
4392,
275,
3355,
8,
3078,
63,
4392,
9,
2286,
870,
63,
495,
275,
3087,
272,
367,
284,
315,
1425,
8,
18,
12,
822,
8,
3078,
63,
4392,
59,
16,
18710,
267,
367,
1335,
315,
1425,
8,
552,
8,
3078,
63,
4392,
2298,
288,
870,
63,
495,
847,
9301,
63,
4392,
59,
74,
1527,
73,
61,
288,
870,
63,
495,
847,
298,
298,
2286,
870,
8,
1361,
63,
495,
9,
272,
372,
9301,
63,
4392,
199,
199,
318,
4069,
1197,
8,
498,
304,
327,
875,
1035,
3510,
13,
3572,
14,
1625,
272,
2388,
498,
275,
790,
272,
601,
89,
275,
942,
339,
327,
413,
9,
2654,
1924,
8082,
370,
314,
1625,
12,
2066,
5591,
327,
259,
4069,
314,
6572,
4079,
641,
23331,
3294,
1865,
272,
2338,
275,
378,
272,
1830,
822,
8,
808,
498,
9,
690,
378,
26,
267,
601,
89,
14,
740,
779,
808,
498,
59,
16,
467,
2338,
566,
267,
2338,
847,
413,
267,
2388,
498,
275,
2388,
498,
59,
17,
2938,
339,
327,
499,
9,
16666,
439,
314,
14435,
3063,
880,
314,
5579,
787,
1642,
272,
367,
1007,
695,
315,
601,
89,
26,
267,
11413,
7147,
11467,
8,
954,
695,
9,
339,
372,
601,
89,
199,
199,
318,
625,
3191,
1197,
8,
5917,
498,
304,
327,
334,
3947,
19156,
13,
1144,
9,
1035,
14766,
1625,
12,
1325,
3355,
272,
1449,
5591,
3254,
26,
16722,
2606,
1625,
4079,
641,
3000,
574,
489,
284,
14,
340,
4160,
2847,
57,
59,
16,
1527,
16,
61,
365,
314,
1109,
12,
4069,
12,
587,
11413,
7147,
11467,
2066,
4069,
272,
1449,
199,
199,
318,
11413,
7147,
11467,
8,
1144,
304,
272,
1625,
59,
16,
467,
1625,
59,
17,
61,
275,
1625,
59,
17,
467,
1625,
59,
16,
61,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sarvesh-ranjan/swift
|
swift/common/middleware/x_profile/profile_model.py
|
2
|
10240
|
# Copyright (c) 2010-2012 OpenStack, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import glob
import json
import os
import pstats
import tempfile
import time
from swift import gettext_ as _
from swift.common.middleware.x_profile.exceptions import ODFLIBNotInstalled
ODFLIB_INSTALLED = True
try:
from odf.opendocument import OpenDocumentSpreadsheet
from odf.table import Table, TableRow, TableCell
from odf.text import P
except ImportError:
ODFLIB_INSTALLED = False
class Stats2(pstats.Stats):
def __init__(self, *args, **kwds):
pstats.Stats.__init__(self, *args, **kwds)
def func_to_dict(self, func):
return {'module': func[0], 'line': func[1], 'function': func[2]}
def func_std_string(self, func):
return pstats.func_std_string(func)
def to_json(self, *selection):
d = dict()
d['files'] = [f for f in self.files]
d['prim_calls'] = (self.prim_calls)
d['total_calls'] = (self.total_calls)
if hasattr(self, 'sort_type'):
d['sort_type'] = self.sort_type
else:
d['sort_type'] = 'random'
d['total_tt'] = (self.total_tt)
if self.fcn_list:
stat_list = self.fcn_list[:]
else:
stat_list = self.stats.keys()
for s in selection:
stat_list, __ = self.eval_print_amount(s, stat_list, '')
self.calc_callees()
function_calls = []
for func in stat_list:
cc, nc, tt, ct, callers = self.stats[func]
fdict = dict()
fdict.update(self.func_to_dict(func))
fdict.update({'cc': (cc), 'nc': (nc), 'tt': (tt),
'ct': (ct)})
if self.all_callees:
fdict.update({'callees': []})
for key in self.all_callees[func]:
cee = self.func_to_dict(key)
metric = self.all_callees[func][key]
# FIXME: eventlet profiler don't provide full list of
# the metrics
if type(metric) is tuple:
cc1, nc1, tt1, ct1 = metric
cee.update({'cc': cc1, 'nc': nc1, 'tt': tt1,
'ct': ct1})
else:
cee['nc'] = metric
fdict['callees'].append(cee)
cer = []
for caller in callers:
fd = self.func_to_dict(caller)
metric2 = callers[caller]
if isinstance(metric2, tuple):
cc2, nc2, tt2, ct2 = metric2
fd.update({'cc': cc2, 'nc': nc2, 'tt': tt2, 'ct': ct2})
else:
fd.update({'nc': metric2})
cer.append(fd)
fdict.update({'callers': cer})
function_calls.append(fdict)
d['stats'] = function_calls
return json.dumps(d, indent=2)
def to_csv(self, *selection):
if self.fcn_list:
stat_list = self.fcn_list[:]
order_text = "Ordered by: " + self.sort_type + '\r\n'
else:
stat_list = self.stats.keys()
order_text = "Random listing order was used\r\n"
for s in selection:
stat_list, __ = self.eval_print_amount(s, stat_list, '')
csv = '%d function calls (%d primitive calls) in %.6f seconds.' % (
self.total_calls, self.prim_calls, self.total_tt)
csv = csv + order_text + 'call count(nc), primitive call count(cc), \
total time(tt), time per call, \
cumulative time(ct), time per call, \
function\r\n'
for func in stat_list:
cc, nc, tt, ct, __ = self.stats[func]
tpc = '' if nc == 0 else '%3f' % (tt / nc)
cpc = '' if cc == 0 else '%3f' % (ct / cc)
fn = '%s:%d(%s)' % (func[0], func[1], func[2])
csv = csv + '%d,%d,%3f,%s,%3f,%s,%s\r\n' % (
nc, cc, tt, tpc, ct, cpc, fn)
return csv
def to_ods(self, *selection):
if not ODFLIB_INSTALLED:
raise ODFLIBNotInstalled(_('odfpy not installed.'))
if self.fcn_list:
stat_list = self.fcn_list[:]
order_text = " Ordered by: " + self.sort_type + '\n'
else:
stat_list = self.stats.keys()
order_text = " Random listing order was used\n"
for s in selection:
stat_list, __ = self.eval_print_amount(s, stat_list, '')
spreadsheet = OpenDocumentSpreadsheet()
table = Table(name="Profile")
for fn in self.files:
tcf = TableCell()
tcf.addElement(P(text=fn))
trf = TableRow()
trf.addElement(tcf)
table.addElement(trf)
tc_summary = TableCell()
summary_text = '%d function calls (%d primitive calls) in %.6f \
seconds' % (self.total_calls, self.prim_calls,
self.total_tt)
tc_summary.addElement(P(text=summary_text))
tr_summary = TableRow()
tr_summary.addElement(tc_summary)
table.addElement(tr_summary)
tc_order = TableCell()
tc_order.addElement(P(text=order_text))
tr_order = TableRow()
tr_order.addElement(tc_order)
table.addElement(tr_order)
tr_header = TableRow()
tc_cc = TableCell()
tc_cc.addElement(P(text='Total Call Count'))
tr_header.addElement(tc_cc)
tc_pc = TableCell()
tc_pc.addElement(P(text='Primitive Call Count'))
tr_header.addElement(tc_pc)
tc_tt = TableCell()
tc_tt.addElement(P(text='Total Time(seconds)'))
tr_header.addElement(tc_tt)
tc_pc = TableCell()
tc_pc.addElement(P(text='Time Per call(seconds)'))
tr_header.addElement(tc_pc)
tc_ct = TableCell()
tc_ct.addElement(P(text='Cumulative Time(seconds)'))
tr_header.addElement(tc_ct)
tc_pt = TableCell()
tc_pt.addElement(P(text='Cumulative Time per call(seconds)'))
tr_header.addElement(tc_pt)
tc_nfl = TableCell()
tc_nfl.addElement(P(text='filename:lineno(function)'))
tr_header.addElement(tc_nfl)
table.addElement(tr_header)
for func in stat_list:
cc, nc, tt, ct, __ = self.stats[func]
tr_header = TableRow()
tc_nc = TableCell()
tc_nc.addElement(P(text=nc))
tr_header.addElement(tc_nc)
tc_pc = TableCell()
tc_pc.addElement(P(text=cc))
tr_header.addElement(tc_pc)
tc_tt = TableCell()
tc_tt.addElement(P(text=tt))
tr_header.addElement(tc_tt)
tc_tpc = TableCell()
tc_tpc.addElement(P(text=(None if nc == 0 else float(tt) / nc)))
tr_header.addElement(tc_tpc)
tc_ct = TableCell()
tc_ct.addElement(P(text=ct))
tr_header.addElement(tc_ct)
tc_tpt = TableCell()
tc_tpt.addElement(P(text=(None if cc == 0 else float(ct) / cc)))
tr_header.addElement(tc_tpt)
tc_nfl = TableCell()
tc_nfl.addElement(P(text=func))
tr_header.addElement(tc_nfl)
table.addElement(tr_header)
spreadsheet.spreadsheet.addElement(table)
tmp_ods = tempfile.TemporaryFile()
spreadsheet.write(tmp_ods)
tmp_ods.seek(0)
data = tmp_ods.read()
os.close(tmp_ods)
return data
class ProfileLog(object):
def __init__(self, log_filename_prefix, dump_timestamp):
self.log_filename_prefix = log_filename_prefix
self.dump_timestamp = dump_timestamp
def get_all_pids(self):
profile_ids = [l.replace(self.log_filename_prefix, '') for l
in glob.glob(self.log_filename_prefix + '*')
if not l.endswith('.tmp')]
return sorted(profile_ids, reverse=True)
def get_logfiles(self, id_or_name):
# The first file with timestamp in the sorted log_files
# (PREFIX)(PROCESS_ID)-(TIMESTAMP)
if id_or_name in ['all']:
if self.dump_timestamp:
latest_dict = {}
for pid in self.get_all_pids():
[process_id, __] = pid.split('-')
if process_id not in latest_dict.keys():
latest_dict[process_id] = self.log_filename_prefix +\
pid
log_files = latest_dict.values()
else:
log_files = [l for l in glob.glob(self.log_filename_prefix
+ '*') if not l.endswith('.tmp')]
else:
pid = str(os.getpid()) if id_or_name in [None, '', 'current']\
else id_or_name
log_files = [l for l in glob.glob(self.log_filename_prefix +
pid + '*') if not l.endswith('.tmp')]
if len(log_files) > 0:
log_files = sorted(log_files, reverse=True)[0:1]
return log_files
def dump_profile(self, profiler, pid):
if self.log_filename_prefix:
pfn = self.log_filename_prefix + str(pid)
if self.dump_timestamp:
pfn = pfn + "-" + str(time.time())
tmpfn = pfn + ".tmp"
profiler.dump_stats(tmpfn)
os.rename(tmpfn, pfn)
return pfn
def clear(self, id_or_name):
log_files = self.get_logfiles(id_or_name)
for l in log_files:
os.path.exists(l) and os.remove(l)
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
7129,
13,
7409,
14260,
12,
20376,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
5739,
199,
646,
2022,
199,
646,
747,
199,
646,
299,
3200,
199,
646,
5549,
199,
646,
900,
199,
199,
504,
16275,
492,
9796,
63,
465,
485,
199,
504,
16275,
14,
2330,
14,
5754,
14,
88,
63,
2913,
14,
3924,
492,
593,
36,
3143,
2100,
1763,
21268,
421,
199,
22041,
3143,
2100,
63,
15942,
275,
715,
199,
893,
26,
272,
687,
312,
1587,
14,
411,
500,
679,
760,
492,
3232,
5564,
30693,
272,
687,
312,
1587,
14,
1224,
492,
6957,
12,
6957,
5810,
12,
6957,
8108,
272,
687,
312,
1587,
14,
505,
492,
510,
199,
2590,
3545,
26,
272,
593,
36,
3143,
2100,
63,
15942,
275,
756,
421,
199,
533,
29062,
18,
8,
80,
3200,
14,
8257,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
10340,
304,
267,
299,
3200,
14,
8257,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
10340,
9,
339,
347,
2562,
63,
475,
63,
807,
8,
277,
12,
2562,
304,
267,
372,
791,
578,
356,
2562,
59,
16,
467,
283,
604,
356,
2562,
59,
17,
467,
283,
1593,
356,
2562,
59,
18,
9420,
339,
347,
2562,
63,
1516,
63,
875,
8,
277,
12,
2562,
304,
267,
372,
299,
3200,
14,
1532,
63,
1516,
63,
875,
8,
1532,
9,
339,
347,
370,
63,
1001,
8,
277,
12,
627,
5592,
304,
267,
366,
275,
1211,
342,
267,
366,
459,
1725,
418,
275,
359,
70,
367,
289,
315,
291,
14,
1725,
61,
267,
366,
459,
31878,
63,
5352,
418,
275,
334,
277,
14,
31878,
63,
5352,
9,
267,
366,
459,
2923,
63,
5352,
418,
275,
334,
277,
14,
2923,
63,
5352,
9,
267,
340,
2688,
8,
277,
12,
283,
3191,
63,
466,
735,
288,
366,
459,
3191,
63,
466,
418,
275,
291,
14,
3191,
63,
466,
267,
587,
26,
288,
366,
459,
3191,
63,
466,
418,
275,
283,
2355,
7,
267,
366,
459,
2923,
63,
6215,
418,
275,
334,
277,
14,
2923,
63,
6215,
9,
267,
340,
291,
14,
26554,
63,
513,
26,
288,
5672,
63,
513,
275,
291,
14,
26554,
63,
513,
5873,
267,
587,
26,
288,
5672,
63,
513,
275,
291,
14,
3200,
14,
1612,
342,
267,
367,
308,
315,
7267,
26,
288,
5672,
63,
513,
12,
636,
275,
291,
14,
2579,
63,
1361,
63,
4606,
8,
83,
12,
5672,
63,
513,
12,
4074,
398,
291,
14,
8104,
63,
915,
274,
397,
342,
267,
805,
63,
5352,
275,
942,
267,
367,
2562,
315,
5672,
63,
513,
26,
288,
7429,
12,
12698,
12,
13638,
12,
9428,
12,
24194,
275,
291,
14,
3200,
59,
1532,
61,
288,
289,
807,
275,
1211,
342,
288,
289,
807,
14,
873,
8,
277,
14,
1532,
63,
475,
63,
807,
8,
1532,
430,
288,
289,
807,
14,
873,
3252,
2055,
356,
334,
2055,
395,
283,
7966,
356,
334,
7966,
395,
283,
6215,
356,
334,
6215,
395,
2079,
283,
319,
356,
334,
319,
11466,
288,
340,
291,
14,
452,
63,
915,
274,
397,
26,
355,
289,
807,
14,
873,
3252,
915,
274,
397,
356,
942,
1552,
355,
367,
790,
315,
291,
14,
452,
63,
915,
274,
397,
59,
1532,
2189,
490,
286,
1024,
275,
291,
14,
1532,
63,
475,
63,
807,
8,
498,
9,
490,
6370,
275,
291,
14,
452,
63,
915,
274,
397,
59,
1532,
1527,
498,
61,
490,
327,
7600,
26,
21819,
23173,
2793,
1133,
5647,
2615,
769,
402,
490,
327,
314,
7186,
490,
340,
730,
8,
5165,
9,
365,
2008,
26,
717,
7429,
17,
12,
12698,
17,
12,
13638,
17,
12,
9428,
17,
275,
6370,
717,
286,
1024,
14,
873,
3252,
2055,
356,
7429,
17,
12,
283,
7966,
356,
12698,
17,
12,
283,
6215,
356,
13638,
17,
12,
2511,
283,
319,
356,
9428,
17,
1552,
490,
587,
26,
717,
286,
1024,
459,
7966,
418,
275,
6370,
490,
289,
807,
459,
915,
274,
397,
2278,
740,
8,
29377,
9,
288,
3361,
275,
942,
288,
367,
8025,
315,
24194,
26,
355,
6111,
275,
291,
14,
1532,
63,
475,
63,
807,
8,
11219,
9,
355,
6370,
18,
275,
24194,
59,
11219,
61,
355,
340,
1228,
8,
5165,
18,
12,
2008,
304,
490,
7429,
18,
12,
12698,
18,
12,
13638,
18,
12,
9428,
18,
275,
6370,
18,
490,
6111,
14,
873,
3252,
2055,
356,
7429,
18,
12,
283,
7966,
356,
12698,
18,
12,
283,
6215,
356,
13638,
18,
12,
283,
319,
356,
9428,
18,
1552,
355,
587,
26,
490,
6111,
14,
873,
3252,
7966,
356,
6370,
18,
1552,
355,
3361,
14,
740,
8,
2592,
9,
288,
289,
807,
14,
873,
3252,
11219,
83,
356,
3361,
1552,
288,
805,
63,
5352,
14,
740,
8,
70,
807,
9,
267,
366,
459,
3200,
418,
275,
805,
63,
5352,
267,
372,
2022,
14,
4180,
8,
68,
12,
4363,
29,
18,
9,
339,
347,
370,
63,
4737,
8,
277,
12,
627,
5592,
304,
267,
340,
291,
14,
26554,
63,
513,
26,
288,
5672,
63,
513,
275,
291,
14,
26554,
63,
513,
5873,
288,
1865,
63,
505,
275,
298,
22567,
701,
26,
298,
435,
291,
14,
3191,
63,
466,
435,
1557,
82,
60,
78,
7,
267,
587,
26,
288,
5672,
63,
513,
275,
291,
14,
3200,
14,
1612,
342,
288,
1865,
63,
505,
275,
298,
3883,
13778,
1865,
1990,
1202,
60,
82,
60,
78,
2,
267,
367,
308,
315,
7267,
26,
288,
5672,
63,
513,
12,
636,
275,
291,
14,
2579,
63,
1361,
63
] |
[
1898,
334,
67,
9,
7129,
13,
7409,
14260,
12,
20376,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
259,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
199,
3,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
646,
5739,
199,
646,
2022,
199,
646,
747,
199,
646,
299,
3200,
199,
646,
5549,
199,
646,
900,
199,
199,
504,
16275,
492,
9796,
63,
465,
485,
199,
504,
16275,
14,
2330,
14,
5754,
14,
88,
63,
2913,
14,
3924,
492,
593,
36,
3143,
2100,
1763,
21268,
421,
199,
22041,
3143,
2100,
63,
15942,
275,
715,
199,
893,
26,
272,
687,
312,
1587,
14,
411,
500,
679,
760,
492,
3232,
5564,
30693,
272,
687,
312,
1587,
14,
1224,
492,
6957,
12,
6957,
5810,
12,
6957,
8108,
272,
687,
312,
1587,
14,
505,
492,
510,
199,
2590,
3545,
26,
272,
593,
36,
3143,
2100,
63,
15942,
275,
756,
421,
199,
533,
29062,
18,
8,
80,
3200,
14,
8257,
304,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
10340,
304,
267,
299,
3200,
14,
8257,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
10340,
9,
339,
347,
2562,
63,
475,
63,
807,
8,
277,
12,
2562,
304,
267,
372,
791,
578,
356,
2562,
59,
16,
467,
283,
604,
356,
2562,
59,
17,
467,
283,
1593,
356,
2562,
59,
18,
9420,
339,
347,
2562,
63,
1516,
63,
875,
8,
277,
12,
2562,
304,
267,
372,
299,
3200,
14,
1532,
63,
1516,
63,
875,
8,
1532,
9,
339,
347,
370,
63,
1001,
8,
277,
12,
627,
5592,
304,
267,
366,
275,
1211,
342,
267,
366,
459,
1725,
418,
275,
359,
70,
367,
289,
315,
291,
14,
1725,
61,
267,
366,
459,
31878,
63,
5352,
418,
275,
334,
277,
14,
31878,
63,
5352,
9,
267,
366,
459,
2923,
63,
5352,
418,
275,
334,
277,
14,
2923,
63,
5352,
9,
267,
340,
2688,
8,
277,
12,
283,
3191,
63,
466,
735,
288,
366,
459,
3191,
63,
466,
418,
275,
291,
14,
3191,
63,
466,
267,
587,
26,
288,
366,
459,
3191,
63,
466,
418,
275,
283,
2355,
7,
267,
366,
459,
2923,
63,
6215,
418,
275,
334,
277,
14,
2923,
63,
6215,
9,
267,
340,
291,
14,
26554,
63,
513,
26,
288,
5672,
63,
513,
275,
291,
14,
26554,
63,
513,
5873,
267,
587,
26,
288,
5672,
63,
513,
275,
291,
14,
3200,
14,
1612,
342,
267,
367,
308,
315,
7267,
26,
288,
5672,
63,
513,
12,
636,
275,
291,
14,
2579,
63,
1361,
63,
4606,
8,
83,
12,
5672,
63,
513,
12,
4074,
398,
291,
14,
8104,
63,
915,
274,
397,
342,
267,
805,
63,
5352,
275,
942,
267,
367,
2562,
315,
5672,
63,
513,
26,
288,
7429,
12,
12698,
12,
13638,
12,
9428,
12,
24194,
275,
291,
14,
3200,
59,
1532,
61,
288,
289,
807,
275,
1211,
342,
288,
289,
807,
14,
873,
8,
277,
14,
1532,
63,
475,
63,
807,
8,
1532,
430,
288,
289,
807,
14,
873,
3252,
2055,
356,
334,
2055,
395,
283,
7966,
356,
334,
7966,
395,
283,
6215,
356,
334,
6215,
395,
2079,
283,
319,
356,
334,
319,
11466,
288,
340,
291,
14,
452,
63,
915,
274,
397,
26,
355,
289,
807,
14,
873,
3252,
915,
274,
397,
356,
942,
1552,
355,
367,
790,
315,
291,
14,
452,
63,
915,
274,
397,
59,
1532,
2189,
490,
286,
1024,
275,
291,
14,
1532,
63,
475,
63,
807,
8,
498,
9,
490,
6370,
275,
291,
14,
452,
63,
915,
274,
397,
59,
1532,
1527,
498,
61,
490,
327,
7600,
26,
21819,
23173,
2793,
1133,
5647,
2615,
769,
402,
490,
327,
314,
7186,
490,
340,
730,
8,
5165,
9,
365,
2008,
26,
717,
7429,
17,
12,
12698,
17,
12,
13638,
17,
12,
9428,
17,
275,
6370,
717,
286,
1024,
14,
873,
3252,
2055,
356,
7429,
17,
12,
283,
7966,
356,
12698,
17,
12,
283,
6215,
356,
13638,
17,
12,
2511,
283,
319,
356,
9428,
17,
1552,
490,
587,
26,
717,
286,
1024,
459,
7966,
418,
275,
6370,
490,
289,
807,
459,
915,
274,
397,
2278,
740,
8,
29377,
9,
288,
3361,
275,
942,
288,
367,
8025,
315,
24194,
26,
355,
6111,
275,
291,
14,
1532,
63,
475,
63,
807,
8,
11219,
9,
355,
6370,
18,
275,
24194,
59,
11219,
61,
355,
340,
1228,
8,
5165,
18,
12,
2008,
304,
490,
7429,
18,
12,
12698,
18,
12,
13638,
18,
12,
9428,
18,
275,
6370,
18,
490,
6111,
14,
873,
3252,
2055,
356,
7429,
18,
12,
283,
7966,
356,
12698,
18,
12,
283,
6215,
356,
13638,
18,
12,
283,
319,
356,
9428,
18,
1552,
355,
587,
26,
490,
6111,
14,
873,
3252,
7966,
356,
6370,
18,
1552,
355,
3361,
14,
740,
8,
2592,
9,
288,
289,
807,
14,
873,
3252,
11219,
83,
356,
3361,
1552,
288,
805,
63,
5352,
14,
740,
8,
70,
807,
9,
267,
366,
459,
3200,
418,
275,
805,
63,
5352,
267,
372,
2022,
14,
4180,
8,
68,
12,
4363,
29,
18,
9,
339,
347,
370,
63,
4737,
8,
277,
12,
627,
5592,
304,
267,
340,
291,
14,
26554,
63,
513,
26,
288,
5672,
63,
513,
275,
291,
14,
26554,
63,
513,
5873,
288,
1865,
63,
505,
275,
298,
22567,
701,
26,
298,
435,
291,
14,
3191,
63,
466,
435,
1557,
82,
60,
78,
7,
267,
587,
26,
288,
5672,
63,
513,
275,
291,
14,
3200,
14,
1612,
342,
288,
1865,
63,
505,
275,
298,
3883,
13778,
1865,
1990,
1202,
60,
82,
60,
78,
2,
267,
367,
308,
315,
7267,
26,
288,
5672,
63,
513,
12,
636,
275,
291,
14,
2579,
63,
1361,
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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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
] |
Fale/ansible
|
test/units/module_utils/common/text/converters/test_container_to_bytes.py
|
71
|
3223
|
# -*- coding: utf-8 -*-
# Copyright 2019, Andrew Klychkov @Andersson007 <aaklychkov@mail.ru>
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)
from __future__ import absolute_import, division, print_function
__metaclass__ = type
import pytest
from ansible.module_utils.common.text.converters import container_to_bytes
DEFAULT_ENCODING = 'utf-8'
DEFAULT_ERR_HANDLER = 'surrogate_or_strict'
@pytest.mark.parametrize(
'test_input,expected',
[
({1: 1}, {1: 1}),
([1, 2], [1, 2]),
((1, 2), (1, 2)),
(1, 1),
(1.1, 1.1),
(b'str', b'str'),
(u'str', b'str'),
([u'str'], [b'str']),
((u'str'), (b'str')),
({u'str': u'str'}, {b'str': b'str'}),
]
)
@pytest.mark.parametrize('encoding', ['utf-8', 'latin1', 'shift_jis', 'big5', 'koi8_r'])
@pytest.mark.parametrize('errors', ['strict', 'surrogate_or_strict', 'surrogate_then_replace'])
def test_container_to_bytes(test_input, expected, encoding, errors):
"""Test for passing objects to container_to_bytes()."""
assert container_to_bytes(test_input, encoding=encoding, errors=errors) == expected
@pytest.mark.parametrize(
'test_input,expected',
[
({1: 1}, {1: 1}),
([1, 2], [1, 2]),
((1, 2), (1, 2)),
(1, 1),
(1.1, 1.1),
(True, True),
(None, None),
(u'str', u'str'.encode(DEFAULT_ENCODING)),
(u'くらとみ', u'くらとみ'.encode(DEFAULT_ENCODING)),
(u'café', u'café'.encode(DEFAULT_ENCODING)),
(b'str', u'str'.encode(DEFAULT_ENCODING)),
(u'str', u'str'.encode(DEFAULT_ENCODING)),
([u'str'], [u'str'.encode(DEFAULT_ENCODING)]),
((u'str'), (u'str'.encode(DEFAULT_ENCODING))),
({u'str': u'str'}, {u'str'.encode(DEFAULT_ENCODING): u'str'.encode(DEFAULT_ENCODING)}),
]
)
def test_container_to_bytes_default_encoding_err(test_input, expected):
"""
Test for passing objects to container_to_bytes(). Default encoding and errors
"""
assert container_to_bytes(test_input, encoding=DEFAULT_ENCODING,
errors=DEFAULT_ERR_HANDLER) == expected
@pytest.mark.parametrize(
'test_input,encoding',
[
(u'くらとみ', 'latin1'),
(u'café', 'shift_jis'),
]
)
@pytest.mark.parametrize('errors', ['surrogate_or_strict', 'strict'])
def test_container_to_bytes_incomp_chars_and_encod(test_input, encoding, errors):
"""
Test for passing incompatible characters and encodings container_to_bytes().
"""
with pytest.raises(UnicodeEncodeError, match="codec can't encode"):
container_to_bytes(test_input, encoding=encoding, errors=errors)
@pytest.mark.parametrize(
'test_input,encoding,expected',
[
(u'くらとみ', 'latin1', b'????'),
(u'café', 'shift_jis', b'caf?'),
]
)
def test_container_to_bytes_surrogate_then_replace(test_input, encoding, expected):
"""
Test for container_to_bytes() with surrogate_then_replace err handler.
"""
assert container_to_bytes(test_input, encoding=encoding,
errors='surrogate_then_replace') == expected
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
20312,
12,
6061,
5257,
1804,
590,
335,
7697,
86,
768,
2493,
424,
385,
265,
8255,
665,
65,
1151,
590,
335,
7697,
86,
32,
1198,
14,
6558,
30,
199,
3,
29094,
30200,
6289,
844,
334,
3239,
12378,
15,
11184,
30200,
63,
15746,
14,
2424,
503,
4178,
921,
16374,
14,
1308,
15,
2383,
15,
15400,
13,
18,
13,
16009,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
4613,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
14,
505,
14,
17911,
492,
3970,
63,
475,
63,
2394,
421,
199,
3472,
63,
16314,
275,
283,
1624,
13,
24,
7,
199,
3472,
63,
2666,
63,
30872,
275,
283,
16380,
63,
269,
63,
4768,
7,
421,
199,
32,
4462,
14,
1657,
14,
10396,
8,
272,
283,
396,
63,
1210,
12,
2062,
297,
272,
359,
267,
11459,
17,
26,
413,
1386,
469,
17,
26,
413,
8688,
267,
7287,
17,
12,
499,
467,
359,
17,
12,
499,
2522,
267,
3666,
17,
12,
499,
395,
334,
17,
12,
499,
1826,
267,
334,
17,
12,
413,
395,
267,
334,
17,
14,
17,
12,
413,
14,
17,
395,
267,
334,
66,
1159,
454,
297,
330,
1159,
454,
659,
267,
334,
85,
1159,
454,
297,
330,
1159,
454,
659,
267,
7287,
85,
1159,
454,
995,
359,
66,
1159,
454,
3815,
267,
3666,
85,
1159,
454,
659,
334,
66,
1159,
454,
3855,
267,
11459,
85,
1159,
454,
356,
399,
1159,
454,
2267,
469,
66,
1159,
454,
356,
330,
1159,
454,
1604,
272,
1622,
199,
9,
199,
32,
4462,
14,
1657,
14,
10396,
360,
2991,
297,
788,
1624,
13,
24,
297,
283,
10378,
17,
297,
283,
4723,
63,
18941,
297,
283,
5076,
21,
297,
283,
7697,
73,
24,
63,
82,
1105,
199,
32,
4462,
14,
1657,
14,
10396,
360,
2550,
297,
788,
4768,
297,
283,
16380,
63,
269,
63,
4768,
297,
283,
16380,
63,
12726,
63,
1814,
1105,
199,
318,
511,
63,
3600,
63,
475,
63,
2394,
8,
396,
63,
1210,
12,
1420,
12,
2644,
12,
2552,
304,
272,
408,
774,
367,
9476,
2251,
370,
3970,
63,
475,
63,
2394,
20693,
272,
702,
3970,
63,
475,
63,
2394,
8,
396,
63,
1210,
12,
2644,
29,
2991,
12,
2552,
29,
2550,
9,
508,
1420,
421,
199,
32,
4462,
14,
1657,
14,
10396,
8,
272,
283,
396,
63,
1210,
12,
2062,
297,
272,
359,
267,
11459,
17,
26,
413,
1386,
469,
17,
26,
413,
8688,
267,
7287,
17,
12,
499,
467,
359,
17,
12,
499,
2522,
267,
3666,
17,
12,
499,
395,
334,
17,
12,
499,
1826,
267,
334,
17,
12,
413,
395,
267,
334,
17,
14,
17,
12,
413,
14,
17,
395,
267,
334,
549,
12,
715,
395,
267,
334,
403,
12,
488,
395,
267,
334,
85,
1159,
454,
297,
399,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
1826,
267,
334,
85,
7,
4197,
238,
5573,
232,
29472,
4197,
124,
297,
399,
7,
4197,
238,
5573,
232,
29472,
4197,
124,
1370,
2143,
8,
3472,
63,
16314,
1826,
267,
334,
85,
7,
27956,
5741,
297,
399,
7,
27956,
5741,
1370,
2143,
8,
3472,
63,
16314,
1826,
267,
334,
66,
1159,
454,
297,
399,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
1826,
267,
334,
85,
1159,
454,
297,
399,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
1826,
267,
7287,
85,
1159,
454,
995,
359,
85,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
16636,
267,
3666,
85,
1159,
454,
659,
334,
85,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
11508,
267,
11459,
85,
1159,
454,
356,
399,
1159,
454,
2267,
469,
85,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
304,
399,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
6769,
395,
272,
1622,
199,
9,
199,
318,
511,
63,
3600,
63,
475,
63,
2394,
63,
885,
63,
2991,
63,
1508,
8,
396,
63,
1210,
12,
1420,
304,
272,
408,
272,
1379,
367,
9476,
2251,
370,
3970,
63,
475,
63,
2394,
1252,
3758,
2644,
436,
2552,
272,
408,
272,
702,
3970,
63,
475,
63,
2394,
8,
396,
63,
1210,
12,
2644,
29,
3472,
63,
16314,
12,
2892,
2552,
29,
3472,
63,
2666,
63,
30872,
9,
508,
1420,
421,
199,
32,
4462,
14,
1657,
14,
10396,
8,
272,
283,
396,
63,
1210,
12,
2991,
297,
272,
359,
267,
334,
85,
7,
4197,
238,
5573,
232,
29472,
4197,
124,
297,
283,
10378,
17,
659,
267,
334,
85,
7,
27956,
5741,
297,
283,
4723,
63,
18941,
659,
272,
1622,
199,
9,
199,
32,
4462,
14,
1657,
14,
10396,
360,
2550,
297,
788,
16380,
63,
269,
63,
4768,
297,
283,
4768,
1105,
199,
318,
511,
63,
3600,
63,
475,
63,
2394,
63,
262,
863,
63,
6574,
63,
460,
63,
287,
7889,
8,
396,
63,
1210,
12,
2644,
12,
2552,
304,
272,
408,
272,
1379,
367,
9476,
18457,
4110,
436,
14134,
3970,
63,
475,
63,
2394,
1252,
272,
408,
272,
543,
4613,
14,
3536,
8,
7087,
19994,
12,
1336,
628,
9276,
883,
1133,
3752,
2349,
267,
3970,
63,
475,
63,
2394,
8,
396,
63,
1210,
12,
2644,
29,
2991,
12,
2552,
29,
2550,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
8,
272,
283,
396,
63,
1210,
12,
2991,
12,
2062,
297,
272,
359,
267,
334,
85,
7,
4197,
238,
5573,
232,
29472,
4197,
124,
297,
283,
10378,
17,
297,
330,
7,
10674,
10674,
659,
267,
334,
85,
7,
27956,
5741,
297,
283,
4723,
63,
18941,
297,
330,
7,
27956,
31,
659,
272,
1622,
199,
9,
199,
318,
511,
63,
3600,
63,
475,
63,
2394,
63,
16380,
63,
12726,
63,
1814,
8,
396,
63,
1210,
12,
2644,
12,
1420,
304,
272,
408,
272,
1379,
367,
3970,
63,
475,
63,
2394,
342,
543,
6296,
13095,
63,
12726,
63,
1814,
2329,
3016,
14,
272,
408,
272,
702,
3970,
63,
475,
63,
2394,
8,
396,
63,
1210,
12,
2644,
29,
2991,
12,
2892,
2552,
534,
16380,
63,
12726,
63,
1814,
358,
508,
1420,
199,
32768,
32768,
32768,
32768,
32768,
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,
1898,
20312,
12,
6061,
5257,
1804,
590,
335,
7697,
86,
768,
2493,
424,
385,
265,
8255,
665,
65,
1151,
590,
335,
7697,
86,
32,
1198,
14,
6558,
30,
199,
3,
29094,
30200,
6289,
844,
334,
3239,
12378,
15,
11184,
30200,
63,
15746,
14,
2424,
503,
4178,
921,
16374,
14,
1308,
15,
2383,
15,
15400,
13,
18,
13,
16009,
9,
199,
199,
504,
636,
2443,
363,
492,
3679,
63,
646,
12,
4629,
12,
870,
63,
1593,
199,
363,
6577,
363,
275,
730,
199,
199,
646,
4613,
199,
199,
504,
3242,
14,
578,
63,
1208,
14,
2330,
14,
505,
14,
17911,
492,
3970,
63,
475,
63,
2394,
421,
199,
3472,
63,
16314,
275,
283,
1624,
13,
24,
7,
199,
3472,
63,
2666,
63,
30872,
275,
283,
16380,
63,
269,
63,
4768,
7,
421,
199,
32,
4462,
14,
1657,
14,
10396,
8,
272,
283,
396,
63,
1210,
12,
2062,
297,
272,
359,
267,
11459,
17,
26,
413,
1386,
469,
17,
26,
413,
8688,
267,
7287,
17,
12,
499,
467,
359,
17,
12,
499,
2522,
267,
3666,
17,
12,
499,
395,
334,
17,
12,
499,
1826,
267,
334,
17,
12,
413,
395,
267,
334,
17,
14,
17,
12,
413,
14,
17,
395,
267,
334,
66,
1159,
454,
297,
330,
1159,
454,
659,
267,
334,
85,
1159,
454,
297,
330,
1159,
454,
659,
267,
7287,
85,
1159,
454,
995,
359,
66,
1159,
454,
3815,
267,
3666,
85,
1159,
454,
659,
334,
66,
1159,
454,
3855,
267,
11459,
85,
1159,
454,
356,
399,
1159,
454,
2267,
469,
66,
1159,
454,
356,
330,
1159,
454,
1604,
272,
1622,
199,
9,
199,
32,
4462,
14,
1657,
14,
10396,
360,
2991,
297,
788,
1624,
13,
24,
297,
283,
10378,
17,
297,
283,
4723,
63,
18941,
297,
283,
5076,
21,
297,
283,
7697,
73,
24,
63,
82,
1105,
199,
32,
4462,
14,
1657,
14,
10396,
360,
2550,
297,
788,
4768,
297,
283,
16380,
63,
269,
63,
4768,
297,
283,
16380,
63,
12726,
63,
1814,
1105,
199,
318,
511,
63,
3600,
63,
475,
63,
2394,
8,
396,
63,
1210,
12,
1420,
12,
2644,
12,
2552,
304,
272,
408,
774,
367,
9476,
2251,
370,
3970,
63,
475,
63,
2394,
20693,
272,
702,
3970,
63,
475,
63,
2394,
8,
396,
63,
1210,
12,
2644,
29,
2991,
12,
2552,
29,
2550,
9,
508,
1420,
421,
199,
32,
4462,
14,
1657,
14,
10396,
8,
272,
283,
396,
63,
1210,
12,
2062,
297,
272,
359,
267,
11459,
17,
26,
413,
1386,
469,
17,
26,
413,
8688,
267,
7287,
17,
12,
499,
467,
359,
17,
12,
499,
2522,
267,
3666,
17,
12,
499,
395,
334,
17,
12,
499,
1826,
267,
334,
17,
12,
413,
395,
267,
334,
17,
14,
17,
12,
413,
14,
17,
395,
267,
334,
549,
12,
715,
395,
267,
334,
403,
12,
488,
395,
267,
334,
85,
1159,
454,
297,
399,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
1826,
267,
334,
85,
7,
4197,
238,
5573,
232,
29472,
4197,
124,
297,
399,
7,
4197,
238,
5573,
232,
29472,
4197,
124,
1370,
2143,
8,
3472,
63,
16314,
1826,
267,
334,
85,
7,
27956,
5741,
297,
399,
7,
27956,
5741,
1370,
2143,
8,
3472,
63,
16314,
1826,
267,
334,
66,
1159,
454,
297,
399,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
1826,
267,
334,
85,
1159,
454,
297,
399,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
1826,
267,
7287,
85,
1159,
454,
995,
359,
85,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
16636,
267,
3666,
85,
1159,
454,
659,
334,
85,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
11508,
267,
11459,
85,
1159,
454,
356,
399,
1159,
454,
2267,
469,
85,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
304,
399,
1159,
454,
1370,
2143,
8,
3472,
63,
16314,
6769,
395,
272,
1622,
199,
9,
199,
318,
511,
63,
3600,
63,
475,
63,
2394,
63,
885,
63,
2991,
63,
1508,
8,
396,
63,
1210,
12,
1420,
304,
272,
408,
272,
1379,
367,
9476,
2251,
370,
3970,
63,
475,
63,
2394,
1252,
3758,
2644,
436,
2552,
272,
408,
272,
702,
3970,
63,
475,
63,
2394,
8,
396,
63,
1210,
12,
2644,
29,
3472,
63,
16314,
12,
2892,
2552,
29,
3472,
63,
2666,
63,
30872,
9,
508,
1420,
421,
199,
32,
4462,
14,
1657,
14,
10396,
8,
272,
283,
396,
63,
1210,
12,
2991,
297,
272,
359,
267,
334,
85,
7,
4197,
238,
5573,
232,
29472,
4197,
124,
297,
283,
10378,
17,
659,
267,
334,
85,
7,
27956,
5741,
297,
283,
4723,
63,
18941,
659,
272,
1622,
199,
9,
199,
32,
4462,
14,
1657,
14,
10396,
360,
2550,
297,
788,
16380,
63,
269,
63,
4768,
297,
283,
4768,
1105,
199,
318,
511,
63,
3600,
63,
475,
63,
2394,
63,
262,
863,
63,
6574,
63,
460,
63,
287,
7889,
8,
396,
63,
1210,
12,
2644,
12,
2552,
304,
272,
408,
272,
1379,
367,
9476,
18457,
4110,
436,
14134,
3970,
63,
475,
63,
2394,
1252,
272,
408,
272,
543,
4613,
14,
3536,
8,
7087,
19994,
12,
1336,
628,
9276,
883,
1133,
3752,
2349,
267,
3970,
63,
475,
63,
2394,
8,
396,
63,
1210,
12,
2644,
29,
2991,
12,
2552,
29,
2550,
9,
421,
199,
32,
4462,
14,
1657,
14,
10396,
8,
272,
283,
396,
63,
1210,
12,
2991,
12,
2062,
297,
272,
359,
267,
334,
85,
7,
4197,
238,
5573,
232,
29472,
4197,
124,
297,
283,
10378,
17,
297,
330,
7,
10674,
10674,
659,
267,
334,
85,
7,
27956,
5741,
297,
283,
4723,
63,
18941,
297,
330,
7,
27956,
31,
659,
272,
1622,
199,
9,
199,
318,
511,
63,
3600,
63,
475,
63,
2394,
63,
16380,
63,
12726,
63,
1814,
8,
396,
63,
1210,
12,
2644,
12,
1420,
304,
272,
408,
272,
1379,
367,
3970,
63,
475,
63,
2394,
342,
543,
6296,
13095,
63,
12726,
63,
1814,
2329,
3016,
14,
272,
408,
272,
702,
3970,
63,
475,
63,
2394,
8,
396,
63,
1210,
12,
2644,
29,
2991,
12,
2892,
2552,
534,
16380,
63,
12726,
63,
1814,
358,
508,
1420,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
sqlalchemy/sqlalchemy
|
test/aaa_profiling/test_memusage.py
|
3
|
45648
|
import decimal
import gc
import itertools
import multiprocessing
import weakref
import sqlalchemy as sa
from sqlalchemy import ForeignKey
from sqlalchemy import inspect
from sqlalchemy import Integer
from sqlalchemy import MetaData
from sqlalchemy import select
from sqlalchemy import String
from sqlalchemy import testing
from sqlalchemy import Unicode
from sqlalchemy import util
from sqlalchemy.engine import result
from sqlalchemy.orm import aliased
from sqlalchemy.orm import clear_mappers
from sqlalchemy.orm import configure_mappers
from sqlalchemy.orm import create_session
from sqlalchemy.orm import join as orm_join
from sqlalchemy.orm import joinedload
from sqlalchemy.orm import Load
from sqlalchemy.orm import mapper
from sqlalchemy.orm import relationship
from sqlalchemy.orm import selectinload
from sqlalchemy.orm import Session
from sqlalchemy.orm import sessionmaker
from sqlalchemy.orm import subqueryload
from sqlalchemy.orm.session import _sessions
from sqlalchemy.processors import to_decimal_processor_factory
from sqlalchemy.processors import to_unicode_processor_factory
from sqlalchemy.sql import column
from sqlalchemy.sql import util as sql_util
from sqlalchemy.sql.visitors import cloned_traverse
from sqlalchemy.sql.visitors import replacement_traverse
from sqlalchemy.testing import engines
from sqlalchemy.testing import eq_
from sqlalchemy.testing import fixtures
from sqlalchemy.testing.fixtures import fixture_session
from sqlalchemy.testing.schema import Column
from sqlalchemy.testing.schema import Table
from sqlalchemy.testing.util import gc_collect
from ..orm import _fixtures
class A(fixtures.ComparableEntity):
pass
class B(fixtures.ComparableEntity):
pass
class ASub(A):
pass
def assert_cycles(expected=0):
def decorate(fn):
def go():
fn() # warmup, configure mappers, caches, etc.
gc_collect()
gc_collect()
gc_collect() # multiple calls seem to matter
# gc.set_debug(gc.DEBUG_COLLECTABLE)
try:
return fn() # run for real
finally:
unreachable = gc_collect()
assert unreachable <= expected
gc_collect()
return go
return decorate
def profile_memory(
maxtimes=250, assert_no_sessions=True, get_num_objects=None
):
def decorate(func):
# run the test N times. if length of gc.get_objects()
# keeps growing, assert false
def get_objects_skipping_sqlite_issue():
# pysqlite keeps adding weakref objects which only
# get reset after 220 iterations. We'd like to keep these
# tests under 50 iterations and ideally about ten, so
# just filter them out so that we get a "flatline" more quickly.
if testing.against("sqlite+pysqlite"):
return [
o
for o in gc.get_objects()
if not isinstance(o, weakref.ref)
]
else:
return gc.get_objects()
def profile(queue, func_args):
# give testing.db a brand new pool and don't
# touch the existing pool, since closing a socket
# in the subprocess can affect the parent
testing.db.pool = testing.db.pool.recreate()
gc_collect()
samples = []
max_ = 0
max_grew_for = 0
success = False
until_maxtimes = 0
try:
while True:
if until_maxtimes >= maxtimes // 5:
break
for x in range(5):
try:
func(*func_args)
except Exception as err:
queue.put(
(
"result",
False,
"Test raised an exception: %r" % err,
)
)
raise
gc_collect()
samples.append(
get_num_objects()
if get_num_objects is not None
else len(get_objects_skipping_sqlite_issue())
)
if assert_no_sessions:
assert len(_sessions) == 0, "%d sessions remain" % (
len(_sessions),
)
# queue.put(('samples', samples))
latest_max = max(samples[-5:])
if latest_max > max_:
queue.put(
(
"status",
"Max grew from %s to %s, max has "
"grown for %s samples"
% (max_, latest_max, max_grew_for),
)
)
max_ = latest_max
max_grew_for += 1
until_maxtimes += 1
continue
else:
queue.put(
(
"status",
"Max remained at %s, %s more attempts left"
% (max_, max_grew_for),
)
)
max_grew_for -= 1
if max_grew_for == 0:
success = True
break
except Exception as err:
queue.put(("result", False, "got exception: %s" % err))
else:
if not success:
queue.put(
(
"result",
False,
"Ran for a total of %d times, memory kept "
"growing: %r" % (maxtimes, samples),
)
)
else:
queue.put(("result", True, "success"))
def run_plain(*func_args):
import queue as _queue
q = _queue.Queue()
profile(q, func_args)
while True:
row = q.get()
typ = row[0]
if typ == "samples":
print("sample gc sizes:", row[1])
elif typ == "status":
print(row[1])
elif typ == "result":
break
else:
assert False, "can't parse row"
assert row[1], row[2]
# return run_plain
def run_in_process(*func_args):
queue = multiprocessing.Queue()
proc = multiprocessing.Process(
target=profile, args=(queue, func_args)
)
proc.start()
while True:
row = queue.get()
typ = row[0]
if typ == "samples":
print("sample gc sizes:", row[1])
elif typ == "status":
print(row[1])
elif typ == "result":
break
else:
assert False, "can't parse row"
proc.join()
assert row[1], row[2]
return run_in_process
return decorate
def assert_no_mappers():
clear_mappers()
gc_collect()
class EnsureZeroed(fixtures.ORMTest):
def setup_test(self):
_sessions.clear()
clear_mappers()
# enable query caching, however make the cache small so that
# the tests don't take too long. issues w/ caching include making
# sure sessions don't get stuck inside of it. However it will
# make tests like test_mapper_reset take a long time because mappers
# are very much a part of what's in the cache.
self.engine = engines.testing_engine(
options={"use_reaper": False, "query_cache_size": 10}
)
class MemUsageTest(EnsureZeroed):
__tags__ = ("memory_intensive",)
__requires__ = ("cpython", "no_windows")
def test_type_compile(self):
from sqlalchemy.dialects.sqlite.base import dialect as SQLiteDialect
cast = sa.cast(column("x"), sa.Integer)
@profile_memory()
def go():
dialect = SQLiteDialect()
cast.compile(dialect=dialect)
go()
@testing.requires.cextensions
def test_DecimalResultProcessor_init(self):
@profile_memory()
def go():
to_decimal_processor_factory({}, 10)
go()
@testing.requires.cextensions
def test_DecimalResultProcessor_process(self):
@profile_memory()
def go():
to_decimal_processor_factory(decimal.Decimal, 10)(1.2)
go()
@testing.requires.cextensions
def test_UnicodeResultProcessor_init(self):
@profile_memory()
def go():
to_unicode_processor_factory("utf8")
go()
@testing.requires.cextensions
def test_cycles_in_row(self):
tup = result.result_tuple(["a", "b", "c"])
@profile_memory()
def go():
obj = {"foo": {}}
obj["foo"]["bar"] = obj
row = tup([1, 2, obj])
obj["foo"]["row"] = row
del row
go()
def test_ad_hoc_types(self):
"""test storage of bind processors, result processors
in dialect-wide registry."""
from sqlalchemy.dialects import mysql, postgresql, sqlite
from sqlalchemy import types
eng = engines.testing_engine()
for args in (
(types.Integer,),
(types.String,),
(types.PickleType,),
(types.Enum, "a", "b", "c"),
(sqlite.DATETIME,),
(postgresql.ENUM, "a", "b", "c"),
(types.Interval,),
(postgresql.INTERVAL,),
(mysql.VARCHAR,),
):
@profile_memory()
def go():
type_ = args[0](*args[1:])
bp = type_._cached_bind_processor(eng.dialect)
rp = type_._cached_result_processor(eng.dialect, 0)
bp, rp # strong reference
go()
assert not eng.dialect._type_memos
@testing.fails()
def test_fixture_failure(self):
class Foo(object):
pass
stuff = []
@profile_memory(maxtimes=20)
def go():
stuff.extend(Foo() for i in range(100))
go()
class MemUsageWBackendTest(EnsureZeroed):
__tags__ = ("memory_intensive",)
__requires__ = "cpython", "memory_process_intensive", "no_asyncio"
__sparse_backend__ = True
# ensure a pure growing test trips the assertion
@testing.fails_if(lambda: True)
def test_fixture(self):
class Foo(object):
pass
x = []
@profile_memory(maxtimes=10)
def go():
x[-1:] = [Foo(), Foo(), Foo(), Foo(), Foo(), Foo()]
go()
def test_session(self):
metadata = MetaData()
table1 = Table(
"mytable",
metadata,
Column(
"col1",
Integer,
primary_key=True,
test_needs_autoincrement=True,
),
Column("col2", String(30)),
)
table2 = Table(
"mytable2",
metadata,
Column(
"col1",
Integer,
primary_key=True,
test_needs_autoincrement=True,
),
Column("col2", String(30)),
Column("col3", Integer, ForeignKey("mytable.col1")),
)
metadata.create_all(self.engine)
m1 = mapper(
A,
table1,
properties={
"bs": relationship(
B, cascade="all, delete", order_by=table2.c.col1
)
},
)
m2 = mapper(B, table2)
@profile_memory()
def go():
with Session(self.engine) as sess:
a1 = A(col2="a1")
a2 = A(col2="a2")
a3 = A(col2="a3")
a1.bs.append(B(col2="b1"))
a1.bs.append(B(col2="b2"))
a3.bs.append(B(col2="b3"))
for x in [a1, a2, a3]:
sess.add(x)
sess.commit()
alist = sess.query(A).order_by(A.col1).all()
eq_(
[
A(col2="a1", bs=[B(col2="b1"), B(col2="b2")]),
A(col2="a2", bs=[]),
A(col2="a3", bs=[B(col2="b3")]),
],
alist,
)
for a in alist:
sess.delete(a)
sess.commit()
go()
metadata.drop_all(self.engine)
del m1, m2
assert_no_mappers()
def test_sessionmaker(self):
@profile_memory()
def go():
sessmaker = sessionmaker(bind=self.engine)
sess = sessmaker()
r = sess.execute(select(1))
r.close()
sess.close()
del sess
del sessmaker
go()
@testing.emits_warning("Compiled statement cache for mapper.*")
@testing.emits_warning("Compiled statement cache for lazy loader.*")
@testing.crashes("sqlite", ":memory: connection not suitable here")
def test_orm_many_engines(self):
metadata = MetaData(self.engine)
table1 = Table(
"mytable",
metadata,
Column(
"col1",
Integer,
primary_key=True,
test_needs_autoincrement=True,
),
Column("col2", String(30)),
)
table2 = Table(
"mytable2",
metadata,
Column(
"col1",
Integer,
primary_key=True,
test_needs_autoincrement=True,
),
Column("col2", String(30)),
Column("col3", Integer, ForeignKey("mytable.col1")),
)
metadata.create_all()
m1 = mapper(
A,
table1,
properties={
"bs": relationship(
B, cascade="all, delete", order_by=table2.c.col1
)
},
_compiled_cache_size=50,
)
m2 = mapper(B, table2, _compiled_cache_size=50)
@profile_memory()
def go():
engine = engines.testing_engine(
options={
"logging_name": "FOO",
"pool_logging_name": "BAR",
"use_reaper": False,
}
)
with Session(engine) as sess:
a1 = A(col2="a1")
a2 = A(col2="a2")
a3 = A(col2="a3")
a1.bs.append(B(col2="b1"))
a1.bs.append(B(col2="b2"))
a3.bs.append(B(col2="b3"))
for x in [a1, a2, a3]:
sess.add(x)
sess.commit()
alist = sess.query(A).order_by(A.col1).all()
eq_(
[
A(col2="a1", bs=[B(col2="b1"), B(col2="b2")]),
A(col2="a2", bs=[]),
A(col2="a3", bs=[B(col2="b3")]),
],
alist,
)
for a in alist:
sess.delete(a)
sess.commit()
engine.dispose()
go()
metadata.drop_all()
del m1, m2
assert_no_mappers()
@testing.emits_warning("Compiled statement cache for.*")
def test_many_updates(self):
metadata = MetaData()
wide_table = Table(
"t",
metadata,
Column(
"id", Integer, primary_key=True, test_needs_autoincrement=True
),
*[Column("col%d" % i, Integer) for i in range(10)]
)
class Wide(object):
pass
mapper(Wide, wide_table, _compiled_cache_size=10)
metadata.create_all(self.engine)
with Session(self.engine) as session:
w1 = Wide()
session.add(w1)
session.commit()
del session
counter = [1]
@profile_memory()
def go():
with Session(self.engine) as session:
w1 = session.query(Wide).first()
x = counter[0]
dec = 10
while dec > 0:
# trying to count in binary here,
# works enough to trip the test case
if pow(2, dec) < x:
setattr(w1, "col%d" % dec, counter[0])
x -= pow(2, dec)
dec -= 1
session.commit()
counter[0] += 1
try:
go()
finally:
metadata.drop_all(self.engine)
@testing.requires.savepoints
def test_savepoints(self):
metadata = MetaData()
some_table = Table(
"t",
metadata,
Column(
"id", Integer, primary_key=True, test_needs_autoincrement=True
),
)
class SomeClass(object):
pass
mapper(SomeClass, some_table)
metadata.create_all(self.engine)
with Session(self.engine) as session:
target_strings = (
session.connection().dialect.identifier_preparer._strings
)
@profile_memory(
assert_no_sessions=False,
get_num_objects=lambda: len(target_strings),
)
def go():
with Session(self.engine) as session, session.begin():
sc = SomeClass()
session.add(sc)
with session.begin_nested():
session.query(SomeClass).first()
try:
go()
finally:
metadata.drop_all(self.engine)
@testing.crashes("mysql+cymysql", "blocking")
def test_unicode_warnings(self):
metadata = MetaData()
table1 = Table(
"mytable",
metadata,
Column(
"col1",
Integer,
primary_key=True,
test_needs_autoincrement=True,
),
Column("col2", Unicode(30)),
)
metadata.create_all(self.engine)
i = [1]
# the times here is cranked way up so that we can see
# pysqlite clearing out its internal buffer and allow
# the test to pass
@testing.emits_warning()
@profile_memory()
def go():
# execute with a non-unicode object. a warning is emitted,
# this warning shouldn't clog up memory.
with self.engine.connect() as conn:
conn.execute(
table1.select().where(table1.c.col2 == "foo%d" % i[0])
)
i[0] += 1
try:
go()
finally:
metadata.drop_all(self.engine)
def test_warnings_util(self):
counter = itertools.count()
import warnings
warnings.filterwarnings("ignore", "memusage warning.*")
@profile_memory()
def go():
util.warn_limited(
"memusage warning, param1: %s, param2: %s",
(next(counter), next(counter)),
)
go()
def test_mapper_reset(self):
metadata = MetaData()
table1 = Table(
"mytable",
metadata,
Column(
"col1",
Integer,
primary_key=True,
test_needs_autoincrement=True,
),
Column("col2", String(30)),
)
table2 = Table(
"mytable2",
metadata,
Column(
"col1",
Integer,
primary_key=True,
test_needs_autoincrement=True,
),
Column("col2", String(30)),
Column("col3", Integer, ForeignKey("mytable.col1")),
)
@profile_memory()
def go():
mapper(
A,
table1,
properties={"bs": relationship(B, order_by=table2.c.col1)},
)
mapper(B, table2)
sess = create_session(self.engine)
a1 = A(col2="a1")
a2 = A(col2="a2")
a3 = A(col2="a3")
a1.bs.append(B(col2="b1"))
a1.bs.append(B(col2="b2"))
a3.bs.append(B(col2="b3"))
for x in [a1, a2, a3]:
sess.add(x)
sess.flush()
sess.expunge_all()
alist = sess.query(A).order_by(A.col1).all()
eq_(
[
A(col2="a1", bs=[B(col2="b1"), B(col2="b2")]),
A(col2="a2", bs=[]),
A(col2="a3", bs=[B(col2="b3")]),
],
alist,
)
for a in alist:
sess.delete(a)
sess.flush()
sess.close()
clear_mappers()
metadata.create_all(self.engine)
try:
go()
finally:
metadata.drop_all(self.engine)
assert_no_mappers()
def test_alias_pathing(self):
metadata = MetaData()
a = Table(
"a",
metadata,
Column(
"id", Integer, primary_key=True, test_needs_autoincrement=True
),
Column("bid", Integer, ForeignKey("b.id")),
Column("type", String(30)),
)
asub = Table(
"asub",
metadata,
Column("id", Integer, ForeignKey("a.id"), primary_key=True),
Column("data", String(30)),
)
b = Table(
"b",
metadata,
Column(
"id", Integer, primary_key=True, test_needs_autoincrement=True
),
)
mapper(A, a, polymorphic_identity="a", polymorphic_on=a.c.type)
mapper(ASub, asub, inherits=A, polymorphic_identity="asub")
mapper(B, b, properties={"as_": relationship(A)})
metadata.create_all(self.engine)
sess = Session(self.engine)
a1 = ASub(data="a1")
a2 = ASub(data="a2")
a3 = ASub(data="a3")
b1 = B(as_=[a1, a2, a3])
sess.add(b1)
sess.commit()
del sess
# sqlite has a slow enough growth here
# that we have to run it more times to see the
# "dip" again
@profile_memory(maxtimes=120)
def go():
sess = Session(self.engine)
sess.query(B).options(subqueryload(B.as_.of_type(ASub))).all()
sess.close()
del sess
try:
go()
finally:
metadata.drop_all(self.engine)
clear_mappers()
def test_path_registry(self):
metadata = MetaData()
a = Table(
"a",
metadata,
Column("id", Integer, primary_key=True),
Column("foo", Integer),
Column("bar", Integer),
)
b = Table(
"b",
metadata,
Column("id", Integer, primary_key=True),
Column("a_id", ForeignKey("a.id")),
)
m1 = mapper(A, a, properties={"bs": relationship(B)})
mapper(B, b)
@profile_memory()
def go():
ma = sa.inspect(aliased(A))
m1._path_registry[m1.attrs.bs][ma][m1.attrs.bar]
go()
clear_mappers()
def test_with_inheritance(self):
metadata = MetaData()
table1 = Table(
"mytable",
metadata,
Column(
"col1",
Integer,
primary_key=True,
test_needs_autoincrement=True,
),
Column("col2", String(30)),
)
table2 = Table(
"mytable2",
metadata,
Column(
"col1",
Integer,
ForeignKey("mytable.col1"),
primary_key=True,
test_needs_autoincrement=True,
),
Column("col3", String(30)),
)
@profile_memory()
def go():
class A(fixtures.ComparableEntity):
pass
class B(A):
pass
mapper(
A,
table1,
polymorphic_on=table1.c.col2,
polymorphic_identity="a",
)
mapper(B, table2, inherits=A, polymorphic_identity="b")
sess = create_session(self.engine)
a1 = A()
a2 = A()
b1 = B(col3="b1")
b2 = B(col3="b2")
for x in [a1, a2, b1, b2]:
sess.add(x)
sess.flush()
sess.expunge_all()
alist = sess.query(A).order_by(A.col1).all()
eq_([A(), A(), B(col3="b1"), B(col3="b2")], alist)
for a in alist:
sess.delete(a)
sess.flush()
# don't need to clear_mappers()
del B
del A
metadata.create_all(self.engine)
try:
go()
finally:
metadata.drop_all(self.engine)
assert_no_mappers()
def test_with_manytomany(self):
metadata = MetaData()
table1 = Table(
"mytable",
metadata,
Column(
"col1",
Integer,
primary_key=True,
test_needs_autoincrement=True,
),
Column("col2", String(30)),
)
table2 = Table(
"mytable2",
metadata,
Column(
"col1",
Integer,
primary_key=True,
test_needs_autoincrement=True,
),
Column("col2", String(30)),
)
table3 = Table(
"t1tot2",
metadata,
Column("t1", Integer, ForeignKey("mytable.col1")),
Column("t2", Integer, ForeignKey("mytable2.col1")),
)
@profile_memory()
def go():
class A(fixtures.ComparableEntity):
pass
class B(fixtures.ComparableEntity):
pass
mapper(
A,
table1,
properties={
"bs": relationship(
B, secondary=table3, backref="as", order_by=table3.c.t1
)
},
)
mapper(B, table2)
sess = create_session(self.engine)
a1 = A(col2="a1")
a2 = A(col2="a2")
b1 = B(col2="b1")
b2 = B(col2="b2")
a1.bs.append(b1)
a2.bs.append(b2)
for x in [a1, a2]:
sess.add(x)
sess.flush()
sess.expunge_all()
alist = sess.query(A).order_by(A.col1).all()
eq_([A(bs=[B(col2="b1")]), A(bs=[B(col2="b2")])], alist)
for a in alist:
sess.delete(a)
sess.flush()
# mappers necessarily find themselves in the compiled cache,
# so to allow them to be GC'ed clear out the cache
self.engine.clear_compiled_cache()
del B
del A
metadata.create_all(self.engine)
try:
go()
finally:
metadata.drop_all(self.engine)
assert_no_mappers()
@testing.uses_deprecated()
def test_key_fallback_result(self):
m = MetaData()
e = self.engine
t = Table("t", m, Column("x", Integer), Column("y", Integer))
m.create_all(e)
e.execute(t.insert(), {"x": 1, "y": 1})
@profile_memory()
def go():
r = e.execute(t.alias().select())
for row in r:
row[t.c.x]
try:
go()
finally:
m.drop_all(e)
def test_many_discarded_relationships(self):
"""a use case that really isn't supported, nonetheless we can
guard against memleaks here so why not"""
m1 = MetaData()
t1 = Table("t1", m1, Column("id", Integer, primary_key=True))
t2 = Table(
"t2",
m1,
Column("id", Integer, primary_key=True),
Column("t1id", ForeignKey("t1.id")),
)
class T1(object):
pass
t1_mapper = mapper(T1, t1)
@testing.emits_warning()
@profile_memory()
def go():
class T2(object):
pass
t2_mapper = mapper(T2, t2)
t1_mapper.add_property("bar", relationship(t2_mapper))
s1 = Session(testing.db)
# this causes the path_registry to be invoked
s1.query(t1_mapper)._compile_context()
go()
# fails on newer versions of pysqlite due to unusual memory behavior
# in pysqlite itself. background at:
# https://thread.gmane.org/gmane.comp.python.db.pysqlite.user/2290
@testing.crashes("mysql+cymysql", "blocking")
def test_join_cache_deprecated_coercion(self):
metadata = MetaData()
table1 = Table(
"table1",
metadata,
Column(
"id", Integer, primary_key=True, test_needs_autoincrement=True
),
Column("data", String(30)),
)
table2 = Table(
"table2",
metadata,
Column(
"id", Integer, primary_key=True, test_needs_autoincrement=True
),
Column("data", String(30)),
Column("t1id", Integer, ForeignKey("table1.id")),
)
class Foo(object):
pass
class Bar(object):
pass
mapper(
Foo, table1, properties={"bars": relationship(mapper(Bar, table2))}
)
metadata.create_all(self.engine)
session = sessionmaker(self.engine)
@profile_memory()
def go():
s = table2.select()
sess = session()
with testing.expect_deprecated(
"Implicit coercion of SELECT and " "textual SELECT constructs"
):
sess.query(Foo).join(s, Foo.bars).all()
sess.rollback()
try:
go()
finally:
metadata.drop_all(self.engine)
@testing.crashes("mysql+cymysql", "blocking")
def test_join_cache(self):
metadata = MetaData()
table1 = Table(
"table1",
metadata,
Column(
"id", Integer, primary_key=True, test_needs_autoincrement=True
),
Column("data", String(30)),
)
table2 = Table(
"table2",
metadata,
Column(
"id", Integer, primary_key=True, test_needs_autoincrement=True
),
Column("data", String(30)),
Column("t1id", Integer, ForeignKey("table1.id")),
)
class Foo(object):
pass
class Bar(object):
pass
mapper(
Foo, table1, properties={"bars": relationship(mapper(Bar, table2))}
)
metadata.create_all(self.engine)
session = sessionmaker(self.engine)
@profile_memory()
def go():
s = table2.select().subquery()
sess = session()
sess.query(Foo).join(s, Foo.bars).all()
sess.rollback()
try:
go()
finally:
metadata.drop_all(self.engine)
class CycleTest(_fixtures.FixtureTest):
__tags__ = ("memory_intensive",)
__requires__ = ("cpython", "no_windows")
run_setup_mappers = "once"
run_inserts = "once"
run_deletes = None
@classmethod
def setup_mappers(cls):
cls._setup_stock_mapping()
def test_query(self):
User, Address = self.classes("User", "Address")
configure_mappers()
s = fixture_session()
@assert_cycles()
def go():
return s.query(User).all()
go()
def test_session_execute_orm(self):
User, Address = self.classes("User", "Address")
configure_mappers()
s = fixture_session()
@assert_cycles()
def go():
stmt = select(User)
s.execute(stmt)
go()
def test_cache_key(self):
User, Address = self.classes("User", "Address")
configure_mappers()
@assert_cycles()
def go():
stmt = select(User)
stmt._generate_cache_key()
go()
def test_proxied_attribute(self):
from sqlalchemy.ext import hybrid
users = self.tables.users
class Foo(object):
@hybrid.hybrid_property
def user_name(self):
return self.name
mapper(Foo, users)
# unfortunately there's a lot of cycles with an aliased()
# for now, however calling upon clause_element does not seem
# to make it worse which is what this was looking to test
@assert_cycles(69)
def go():
a1 = aliased(Foo)
a1.user_name.__clause_element__()
go()
def test_raise_from(self):
@assert_cycles()
def go():
try:
try:
raise KeyError("foo")
except KeyError as ke:
util.raise_(Exception("oops"), from_=ke)
except Exception as err: # noqa
pass
go()
def test_query_alias(self):
User, Address = self.classes("User", "Address")
configure_mappers()
s = fixture_session()
u1 = aliased(User)
@assert_cycles()
def go():
s.query(u1).all()
go()
def test_entity_path_w_aliased(self):
User, Address = self.classes("User", "Address")
configure_mappers()
@assert_cycles()
def go():
u1 = aliased(User)
inspect(u1)._path_registry[User.addresses.property]
go()
def test_orm_objects_from_query(self):
User, Address = self.classes("User", "Address")
configure_mappers()
s = fixture_session()
def generate():
objects = s.query(User).filter(User.id == 7).all()
gc_collect()
return objects
@assert_cycles()
def go():
generate()
go()
def test_orm_objects_from_query_w_selectinload(self):
User, Address = self.classes("User", "Address")
s = fixture_session()
def generate():
objects = s.query(User).options(selectinload(User.addresses)).all()
gc_collect()
return objects
@assert_cycles()
def go():
generate()
go()
def test_selectinload_option_unbound(self):
User, Address = self.classes("User", "Address")
@assert_cycles()
def go():
selectinload(User.addresses)
go()
def test_selectinload_option_bound(self):
User, Address = self.classes("User", "Address")
@assert_cycles()
def go():
Load(User).selectinload(User.addresses)
go()
def test_orm_path(self):
User, Address = self.classes("User", "Address")
@assert_cycles()
def go():
inspect(User)._path_registry[User.addresses.property][
inspect(Address)
]
go()
def test_joinedload_option_unbound(self):
User, Address = self.classes("User", "Address")
@assert_cycles()
def go():
joinedload(User.addresses)
go()
def test_joinedload_option_bound(self):
User, Address = self.classes("User", "Address")
@assert_cycles()
def go():
l1 = Load(User).joinedload(User.addresses)
l1._generate_cache_key()
go()
def test_orm_objects_from_query_w_joinedload(self):
User, Address = self.classes("User", "Address")
s = fixture_session()
def generate():
objects = s.query(User).options(joinedload(User.addresses)).all()
gc_collect()
return objects
@assert_cycles()
def go():
generate()
go()
def test_query_filtered(self):
User, Address = self.classes("User", "Address")
s = fixture_session()
@assert_cycles()
def go():
return s.query(User).filter(User.id == 7).all()
go()
def test_query_joins(self):
User, Address = self.classes("User", "Address")
s = fixture_session()
# cycles here are due to ClauseElement._cloned_set, others
# as of cache key
@assert_cycles(4)
def go():
s.query(User).join(User.addresses).all()
go()
def test_query_joinedload(self):
User, Address = self.classes("User", "Address")
s = fixture_session()
def generate():
s.query(User).options(joinedload(User.addresses)).all()
# cycles here are due to ClauseElement._cloned_set and Load.context,
# others as of cache key. The orm.instances() function now calls
# dispose() on both the context and the compiled state to try
# to reduce these cycles.
@assert_cycles(18)
def go():
generate()
go()
def test_plain_join(self):
users, addresses = self.tables("users", "addresses")
@assert_cycles()
def go():
str(users.join(addresses).compile(testing.db))
go()
def test_plain_join_select(self):
users, addresses = self.tables("users", "addresses")
# cycles here are due to ClauseElement._cloned_set, others
# as of cache key
@assert_cycles(7)
def go():
s = select(users).select_from(users.join(addresses))
state = s._compile_state_factory(s, s.compile(testing.db))
state.froms
go()
def test_orm_join(self):
User, Address = self.classes("User", "Address")
@assert_cycles()
def go():
str(orm_join(User, Address, User.addresses).compile(testing.db))
go()
def test_join_via_query_relationship(self):
User, Address = self.classes("User", "Address")
configure_mappers()
s = fixture_session()
@assert_cycles()
def go():
s.query(User).join(User.addresses)
go()
def test_join_via_query_to_entity(self):
User, Address = self.classes("User", "Address")
configure_mappers()
s = fixture_session()
@assert_cycles()
def go():
s.query(User).join(Address)
go()
def test_result_fetchone(self):
User, Address = self.classes("User", "Address")
configure_mappers()
s = fixture_session()
stmt = s.query(User).join(User.addresses).statement
@assert_cycles(4)
def go():
result = s.connection(mapper=User).execute(stmt)
while True:
row = result.fetchone()
if row is None:
break
go()
def test_result_fetchall(self):
User, Address = self.classes("User", "Address")
configure_mappers()
s = fixture_session()
stmt = s.query(User).join(User.addresses).statement
@assert_cycles(4)
def go():
result = s.execute(stmt)
rows = result.fetchall() # noqa
go()
def test_result_fetchmany(self):
User, Address = self.classes("User", "Address")
configure_mappers()
s = fixture_session()
stmt = s.query(User).join(User.addresses).statement
@assert_cycles(4)
def go():
result = s.execute(stmt)
for partition in result.partitions(3):
pass
go()
def test_result_fetchmany_unique(self):
User, Address = self.classes("User", "Address")
configure_mappers()
s = fixture_session()
stmt = s.query(User).join(User.addresses).statement
@assert_cycles(4)
def go():
result = s.execute(stmt)
for partition in result.unique().partitions(3):
pass
go()
def test_core_select_from_orm_query(self):
User, Address = self.classes("User", "Address")
configure_mappers()
s = fixture_session()
stmt = s.query(User).join(User.addresses).statement
# ORM query using future select for .statement is adding
# some ORMJoin cycles here during compilation. not worth trying to
# find it
@assert_cycles(4)
def go():
s.execute(stmt)
go()
def test_adapt_statement_replacement_traversal(self):
User, Address = self.classes("User", "Address")
statement = select(User).select_from(
orm_join(User, Address, User.addresses)
)
@assert_cycles()
def go():
replacement_traverse(statement, {}, lambda x: None)
go()
def test_adapt_statement_cloned_traversal(self):
User, Address = self.classes("User", "Address")
statement = select(User).select_from(
orm_join(User, Address, User.addresses)
)
@assert_cycles()
def go():
cloned_traverse(statement, {}, {})
go()
def test_column_adapter_lookup(self):
User, Address = self.classes("User", "Address")
u1 = aliased(User)
@assert_cycles()
def go():
adapter = sql_util.ColumnAdapter(inspect(u1).selectable)
adapter.columns[User.id]
go()
def test_orm_aliased(self):
User, Address = self.classes("User", "Address")
@assert_cycles()
def go():
u1 = aliased(User)
inspect(u1)
go()
@testing.fails()
def test_the_counter(self):
@assert_cycles()
def go():
x = []
x.append(x)
go()
def test_weak_sequence(self):
class Foo(object):
pass
f = Foo()
@assert_cycles()
def go():
util.WeakSequence([f])
go()
@testing.provide_metadata
def test_optimized_get(self):
from sqlalchemy.ext.declarative import declarative_base
Base = declarative_base(metadata=self.metadata)
class Employee(Base):
__tablename__ = "employee"
id = Column(
Integer, primary_key=True, test_needs_autoincrement=True
)
type = Column(String(10))
__mapper_args__ = {"polymorphic_on": type}
class Engineer(Employee):
__tablename__ = " engineer"
id = Column(ForeignKey("employee.id"), primary_key=True)
engineer_name = Column(String(50))
__mapper_args__ = {"polymorphic_identity": "engineer"}
Base.metadata.create_all(testing.db)
s = Session(testing.db)
s.add(Engineer(engineer_name="wally"))
s.commit()
s.close()
@assert_cycles()
def go():
e1 = s.query(Employee).first()
e1.engineer_name
go()
def test_visit_binary_product(self):
a, b, q, e, f, j, r = [column(chr_) for chr_ in "abqefjr"]
from sqlalchemy import and_, func
from sqlalchemy.sql.util import visit_binary_product
expr = and_((a + b) == q + func.sum(e + f), j == r)
def visit(expr, left, right):
pass
@assert_cycles()
def go():
visit_binary_product(visit, expr)
go()
def test_session_transaction(self):
@assert_cycles()
def go():
s = Session(testing.db)
s.connection()
s.close()
go()
def test_session_commit_rollback(self):
# this is enabled by #5074
@assert_cycles()
def go():
s = Session(testing.db)
s.connection()
s.commit()
go()
@assert_cycles()
def go():
s = Session(testing.db)
s.connection()
s.rollback()
go()
def test_session_multi_transaction(self):
@assert_cycles()
def go():
s = Session(testing.db)
assert s._transaction is None
s.connection()
s.close()
assert s._transaction is None
s.connection()
assert s._transaction is not None
s.close()
go()
|
mit
|
[
646,
6107,
199,
646,
9486,
199,
646,
7975,
199,
646,
12866,
199,
646,
13852,
199,
199,
646,
8335,
465,
2937,
199,
504,
8335,
492,
12718,
199,
504,
8335,
492,
6485,
199,
504,
8335,
492,
7225,
199,
504,
8335,
492,
24905,
199,
504,
8335,
492,
3504,
199,
504,
8335,
492,
2624,
199,
504,
8335,
492,
5343,
199,
504,
8335,
492,
6140,
199,
504,
8335,
492,
4884,
199,
504,
8335,
14,
3908,
492,
754,
199,
504,
8335,
14,
1025,
492,
26642,
199,
504,
8335,
14,
1025,
492,
5436,
63,
24469,
199,
504,
8335,
14,
1025,
492,
7908,
63,
24469,
199,
504,
8335,
14,
1025,
492,
1218,
63,
1730,
199,
504,
8335,
14,
1025,
492,
4263,
465,
9813,
63,
904,
199,
504,
8335,
14,
1025,
492,
16538,
912,
199,
504,
8335,
14,
1025,
492,
7190,
199,
504,
8335,
14,
1025,
492,
7796,
199,
504,
8335,
14,
1025,
492,
8931,
199,
504,
8335,
14,
1025,
492,
3504,
262,
912,
199,
504,
8335,
14,
1025,
492,
8596,
199,
504,
8335,
14,
1025,
492,
2351,
14367,
199,
504,
8335,
14,
1025,
492,
25935,
912,
199,
504,
8335,
14,
1025,
14,
1730,
492,
485,
11676,
199,
504,
8335,
14,
10547,
492,
370,
63,
6355,
63,
6459,
63,
3702,
199,
504,
8335,
14,
10547,
492,
370,
63,
2975,
63,
6459,
63,
3702,
199,
504,
8335,
14,
3009,
492,
2763,
199,
504,
8335,
14,
3009,
492,
4884,
465,
3875,
63,
1974,
199,
504,
8335,
14,
3009,
14,
5427,
1384,
492,
26210,
63,
23650,
199,
504,
8335,
14,
3009,
14,
5427,
1384,
492,
8343,
63,
23650,
199,
504,
8335,
14,
4776,
492,
28156,
199,
504,
8335,
14,
4776,
492,
3850,
63,
199,
504,
8335,
14,
4776,
492,
15188,
199,
504,
8335,
14,
4776,
14,
8769,
492,
10949,
63,
1730,
199,
504,
8335,
14,
4776,
14,
3629,
492,
4996,
199,
504,
8335,
14,
4776,
14,
3629,
492,
6957,
199,
504,
8335,
14,
4776,
14,
1974,
492,
9486,
63,
7112,
199,
504,
2508,
1025,
492,
485,
8769,
421,
199,
533,
437,
8,
8769,
14,
2404,
19816,
7302,
304,
272,
986,
421,
199,
533,
699,
8,
8769,
14,
2404,
19816,
7302,
304,
272,
986,
421,
199,
533,
437,
2610,
8,
33,
304,
272,
986,
421,
199,
318,
702,
63,
23356,
8,
2062,
29,
16,
304,
272,
347,
24774,
8,
2324,
304,
267,
347,
2621,
837,
288,
4325,
342,
221,
327,
20060,
384,
12,
7908,
7796,
83,
12,
18014,
12,
5423,
14,
953,
9486,
63,
7112,
342,
288,
9486,
63,
7112,
342,
288,
9486,
63,
7112,
342,
221,
327,
3663,
4882,
17021,
370,
17247,
953,
327,
9486,
14,
409,
63,
1757,
8,
9493,
14,
5287,
63,
23037,
2617,
9,
288,
862,
26,
355,
372,
4325,
342,
221,
327,
1255,
367,
3363,
288,
3753,
26,
355,
625,
15837,
275,
9486,
63,
7112,
342,
355,
702,
625,
15837,
2695,
1420,
355,
9486,
63,
7112,
342,
398,
372,
2621,
339,
372,
24774,
421,
199,
318,
4690,
63,
4844,
8,
272,
1390,
4508,
29,
7991,
12,
702,
63,
889,
63,
11676,
29,
549,
12,
664,
63,
1507,
63,
1462,
29,
403,
199,
304,
272,
347,
24774,
8,
1532,
304,
267,
327,
1255,
314,
511,
653,
5431,
14,
221,
340,
2582,
402,
9486,
14,
362,
63,
1462,
342,
267,
327,
18578,
20772,
316,
12,
702,
3055,
398,
347,
664,
63,
1462,
63,
27713,
63,
10659,
63,
5237,
837,
288,
327,
10382,
29498,
18578,
7791,
13852,
2251,
1314,
1454,
288,
327,
664,
5305,
2410,
25647,
10615,
14,
221,
2136,
5121,
2839,
370,
4215,
3520,
288,
327,
2295,
1334,
5238,
10615,
436,
9979,
1183,
3595,
16685,
12,
880,
288,
327,
2951,
2457,
3062,
734,
880,
626,
781,
664,
282,
298,
7088,
604,
2,
1655,
23661,
14,
953,
340,
5343,
14,
17777,
480,
10659,
11,
15983,
29498,
2349,
355,
372,
359,
490,
312,
490,
367,
312,
315,
9486,
14,
362,
63,
1462,
342,
490,
340,
440,
1228,
8,
79,
12,
13852,
14,
1121,
9,
355,
1622,
288,
587,
26,
355,
372,
9486,
14,
362,
63,
1462,
342,
398,
347,
4690,
8,
1825,
12,
2562,
63,
589,
304,
288,
327,
8120,
5343,
14,
697,
282,
32159,
892,
4203,
436,
2793,
1133,
288,
327,
12943,
314,
3411,
4203,
12,
3967,
11261,
282,
2838,
288,
327,
315,
314,
3873,
883,
12787,
314,
1676,
288,
5343,
14,
697,
14,
2293,
275,
5343,
14,
697,
14,
2293,
14,
264,
981,
342,
953,
9486,
63,
7112,
342,
288,
5845,
275,
942,
288,
1390,
63,
275,
378,
288,
1390,
63,
71,
5257,
63,
509,
275,
378,
288,
3182,
275,
756,
288,
5133,
63,
988,
4508,
275,
378,
288,
862,
26,
355,
1830,
715,
26,
490,
340,
5133,
63,
988,
4508,
2356,
1390,
4508,
5001,
959,
26,
717,
2059,
490,
367,
671,
315,
1425,
8,
21,
304,
717,
862,
26,
1169,
2562,
2031,
1532,
63,
589,
9,
717,
871,
2186,
465,
2329,
26,
1169,
4126,
14,
524,
8,
1816,
334,
2511,
298,
1099,
401,
2511,
756,
12,
2511,
298,
774,
4915,
376,
1919,
26,
450,
82,
2,
450,
2329,
12,
1816,
776,
1169,
776,
18008,
746,
9453,
9486,
63,
7112,
342,
9453,
5845,
14,
740,
8,
1169,
664,
63,
1507,
63,
1462,
342,
1169,
340,
664,
63,
1507,
63,
1462,
365,
440,
488,
1169,
587,
822,
8,
362,
63,
1462,
63,
27713,
63,
10659,
63,
5237,
1012,
717,
776,
4951,
340,
702,
63,
889,
63,
11676,
26,
717,
702,
822,
1547,
11676,
9,
508,
378,
12,
2071,
68,
12184,
5706,
2,
450,
334,
1169,
822,
1547,
11676,
395,
717,
776,
4951,
327,
4126,
14,
524,
4725,
3356,
297,
5845,
430,
4951,
8839,
63,
988,
275,
1390,
8,
3356,
1988,
21,
5728,
490,
340,
8839,
63,
988,
690,
1390,
10388,
717,
4126,
14,
524,
8,
1169,
334,
1816,
298,
1205,
401,
1816,
298,
4261,
486,
5257,
687,
450,
83,
370,
450,
83,
12,
1390,
965,
298,
1816,
298,
71,
18406,
367,
450,
83,
5845,
2,
1816,
450,
334,
988,
3131,
8839,
63,
988,
12,
1390,
63,
71,
5257,
63,
509,
395,
1169,
776,
717,
776,
717,
1390,
63,
275,
8839,
63,
988,
717,
1390,
63,
71,
5257,
63,
509,
847,
413,
717,
5133,
63,
988,
4508,
847,
413,
717,
1980,
490,
587,
26,
717,
4126,
14,
524,
8,
1169,
334,
1816,
298,
1205,
401,
1816
] |
[
6107,
199,
646,
9486,
199,
646,
7975,
199,
646,
12866,
199,
646,
13852,
199,
199,
646,
8335,
465,
2937,
199,
504,
8335,
492,
12718,
199,
504,
8335,
492,
6485,
199,
504,
8335,
492,
7225,
199,
504,
8335,
492,
24905,
199,
504,
8335,
492,
3504,
199,
504,
8335,
492,
2624,
199,
504,
8335,
492,
5343,
199,
504,
8335,
492,
6140,
199,
504,
8335,
492,
4884,
199,
504,
8335,
14,
3908,
492,
754,
199,
504,
8335,
14,
1025,
492,
26642,
199,
504,
8335,
14,
1025,
492,
5436,
63,
24469,
199,
504,
8335,
14,
1025,
492,
7908,
63,
24469,
199,
504,
8335,
14,
1025,
492,
1218,
63,
1730,
199,
504,
8335,
14,
1025,
492,
4263,
465,
9813,
63,
904,
199,
504,
8335,
14,
1025,
492,
16538,
912,
199,
504,
8335,
14,
1025,
492,
7190,
199,
504,
8335,
14,
1025,
492,
7796,
199,
504,
8335,
14,
1025,
492,
8931,
199,
504,
8335,
14,
1025,
492,
3504,
262,
912,
199,
504,
8335,
14,
1025,
492,
8596,
199,
504,
8335,
14,
1025,
492,
2351,
14367,
199,
504,
8335,
14,
1025,
492,
25935,
912,
199,
504,
8335,
14,
1025,
14,
1730,
492,
485,
11676,
199,
504,
8335,
14,
10547,
492,
370,
63,
6355,
63,
6459,
63,
3702,
199,
504,
8335,
14,
10547,
492,
370,
63,
2975,
63,
6459,
63,
3702,
199,
504,
8335,
14,
3009,
492,
2763,
199,
504,
8335,
14,
3009,
492,
4884,
465,
3875,
63,
1974,
199,
504,
8335,
14,
3009,
14,
5427,
1384,
492,
26210,
63,
23650,
199,
504,
8335,
14,
3009,
14,
5427,
1384,
492,
8343,
63,
23650,
199,
504,
8335,
14,
4776,
492,
28156,
199,
504,
8335,
14,
4776,
492,
3850,
63,
199,
504,
8335,
14,
4776,
492,
15188,
199,
504,
8335,
14,
4776,
14,
8769,
492,
10949,
63,
1730,
199,
504,
8335,
14,
4776,
14,
3629,
492,
4996,
199,
504,
8335,
14,
4776,
14,
3629,
492,
6957,
199,
504,
8335,
14,
4776,
14,
1974,
492,
9486,
63,
7112,
199,
504,
2508,
1025,
492,
485,
8769,
421,
199,
533,
437,
8,
8769,
14,
2404,
19816,
7302,
304,
272,
986,
421,
199,
533,
699,
8,
8769,
14,
2404,
19816,
7302,
304,
272,
986,
421,
199,
533,
437,
2610,
8,
33,
304,
272,
986,
421,
199,
318,
702,
63,
23356,
8,
2062,
29,
16,
304,
272,
347,
24774,
8,
2324,
304,
267,
347,
2621,
837,
288,
4325,
342,
221,
327,
20060,
384,
12,
7908,
7796,
83,
12,
18014,
12,
5423,
14,
953,
9486,
63,
7112,
342,
288,
9486,
63,
7112,
342,
288,
9486,
63,
7112,
342,
221,
327,
3663,
4882,
17021,
370,
17247,
953,
327,
9486,
14,
409,
63,
1757,
8,
9493,
14,
5287,
63,
23037,
2617,
9,
288,
862,
26,
355,
372,
4325,
342,
221,
327,
1255,
367,
3363,
288,
3753,
26,
355,
625,
15837,
275,
9486,
63,
7112,
342,
355,
702,
625,
15837,
2695,
1420,
355,
9486,
63,
7112,
342,
398,
372,
2621,
339,
372,
24774,
421,
199,
318,
4690,
63,
4844,
8,
272,
1390,
4508,
29,
7991,
12,
702,
63,
889,
63,
11676,
29,
549,
12,
664,
63,
1507,
63,
1462,
29,
403,
199,
304,
272,
347,
24774,
8,
1532,
304,
267,
327,
1255,
314,
511,
653,
5431,
14,
221,
340,
2582,
402,
9486,
14,
362,
63,
1462,
342,
267,
327,
18578,
20772,
316,
12,
702,
3055,
398,
347,
664,
63,
1462,
63,
27713,
63,
10659,
63,
5237,
837,
288,
327,
10382,
29498,
18578,
7791,
13852,
2251,
1314,
1454,
288,
327,
664,
5305,
2410,
25647,
10615,
14,
221,
2136,
5121,
2839,
370,
4215,
3520,
288,
327,
2295,
1334,
5238,
10615,
436,
9979,
1183,
3595,
16685,
12,
880,
288,
327,
2951,
2457,
3062,
734,
880,
626,
781,
664,
282,
298,
7088,
604,
2,
1655,
23661,
14,
953,
340,
5343,
14,
17777,
480,
10659,
11,
15983,
29498,
2349,
355,
372,
359,
490,
312,
490,
367,
312,
315,
9486,
14,
362,
63,
1462,
342,
490,
340,
440,
1228,
8,
79,
12,
13852,
14,
1121,
9,
355,
1622,
288,
587,
26,
355,
372,
9486,
14,
362,
63,
1462,
342,
398,
347,
4690,
8,
1825,
12,
2562,
63,
589,
304,
288,
327,
8120,
5343,
14,
697,
282,
32159,
892,
4203,
436,
2793,
1133,
288,
327,
12943,
314,
3411,
4203,
12,
3967,
11261,
282,
2838,
288,
327,
315,
314,
3873,
883,
12787,
314,
1676,
288,
5343,
14,
697,
14,
2293,
275,
5343,
14,
697,
14,
2293,
14,
264,
981,
342,
953,
9486,
63,
7112,
342,
288,
5845,
275,
942,
288,
1390,
63,
275,
378,
288,
1390,
63,
71,
5257,
63,
509,
275,
378,
288,
3182,
275,
756,
288,
5133,
63,
988,
4508,
275,
378,
288,
862,
26,
355,
1830,
715,
26,
490,
340,
5133,
63,
988,
4508,
2356,
1390,
4508,
5001,
959,
26,
717,
2059,
490,
367,
671,
315,
1425,
8,
21,
304,
717,
862,
26,
1169,
2562,
2031,
1532,
63,
589,
9,
717,
871,
2186,
465,
2329,
26,
1169,
4126,
14,
524,
8,
1816,
334,
2511,
298,
1099,
401,
2511,
756,
12,
2511,
298,
774,
4915,
376,
1919,
26,
450,
82,
2,
450,
2329,
12,
1816,
776,
1169,
776,
18008,
746,
9453,
9486,
63,
7112,
342,
9453,
5845,
14,
740,
8,
1169,
664,
63,
1507,
63,
1462,
342,
1169,
340,
664,
63,
1507,
63,
1462,
365,
440,
488,
1169,
587,
822,
8,
362,
63,
1462,
63,
27713,
63,
10659,
63,
5237,
1012,
717,
776,
4951,
340,
702,
63,
889,
63,
11676,
26,
717,
702,
822,
1547,
11676,
9,
508,
378,
12,
2071,
68,
12184,
5706,
2,
450,
334,
1169,
822,
1547,
11676,
395,
717,
776,
4951,
327,
4126,
14,
524,
4725,
3356,
297,
5845,
430,
4951,
8839,
63,
988,
275,
1390,
8,
3356,
1988,
21,
5728,
490,
340,
8839,
63,
988,
690,
1390,
10388,
717,
4126,
14,
524,
8,
1169,
334,
1816,
298,
1205,
401,
1816,
298,
4261,
486,
5257,
687,
450,
83,
370,
450,
83,
12,
1390,
965,
298,
1816,
298,
71,
18406,
367,
450,
83,
5845,
2,
1816,
450,
334,
988,
3131,
8839,
63,
988,
12,
1390,
63,
71,
5257,
63,
509,
395,
1169,
776,
717,
776,
717,
1390,
63,
275,
8839,
63,
988,
717,
1390,
63,
71,
5257,
63,
509,
847,
413,
717,
5133,
63,
988,
4508,
847,
413,
717,
1980,
490,
587,
26,
717,
4126,
14,
524,
8,
1169,
334,
1816,
298,
1205,
401,
1816,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
eranchetz/nupic
|
nupic/regions/PictureSensorExplorers/random.py
|
17
|
5518
|
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2013, Numenta, Inc. Unless you have an agreement
# with Numenta, Inc., for a separate license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
"""
This file defines RandomPictureExplorer, an explorer for
PictureSensor.
"""
# Third-party imports
import numpy
# Local imports
from nupic.regions.PictureSensor import PictureSensor
class RandomPictureExplorer(PictureSensor.PictureExplorer):
"""
Presents smoothly varying sequences of randomly selected
categories that sweep across the canvas at particular
velocities.
"""
@classmethod
def queryRelevantParams(klass):
"""
Returns a sequence of parameter names that are relevant to
the operation of the explorer.
May be extended or overridden by sub-classes as appropriate.
"""
return ( 'width', 'height',
'sweepOffMode', 'maxOffset',
'minVelocity', 'maxVelocity',
'minAngularPosn', 'maxAngularPosn',
'minAngularVelocity', 'maxAngularVelocity',
)
def initSequence(self, state, params):
"""
Create the state associated with a new sequence.
@param state: a dict containing the default values for new
sequence state. This dict will contain the following keys
(additional keys may be added by the method implementation):
catIndex - the 0-based index of the category
that will be used for the sequence;
posnX - the initial X position of the pattern's reference
point for the new sequence;
posnY - the initial Y position of the pattern's reference
point for the new sequence;
velocityX - the initial horizontal velocity of the
pattern's reference point for the new sequence;
velocityY - the initial vertical velocity of the
pattern's reference point for the new sequence;
angularPosn - the initial angular position (in degrees) of
the pattern for the new sequence;
angularVelocity - the initial angular velocity (in degrees
per iteration) of the pattern for the new sequence;
Must be overridden by sub-classes, and must not invoke this base class method.
"""
patternSize = state['patternSize']
slopX = (params['width'] - patternSize) // 2
slopY = (params['height'] - patternSize) // 2
if params['sweepOffMode']:
slopX = abs(slopX)
slopY = abs(slopY)
if params['maxOffset'] != -1:
slopX = min(abs(slopX), params['maxOffset'])
slopY = min(abs(slopY), params['maxOffset'])
posnX = self._rng.choice(xrange(-slopX, slopX + 1))
posnY = self._rng.choice(xrange(-slopY, slopY + 1))
velocityX = self._rng.choice([-1, +1]) \
* self._rng.choice(xrange(params['minVelocity'], params['maxVelocity'] + 1))
velocityY = self._rng.choice([-1, +1]) \
* self._rng.choice(xrange(params['minVelocity'], params['maxVelocity'] + 1))
# Choose a category random
catIndex = self._chooseCategory()
# Choose rotational params
angularPosn = params['minAngularPosn'] + self._rng.random() \
* (params['maxAngularPosn'] - params['minAngularPosn'])
angularVelocity = params['minAngularVelocity'] + self._rng.random() \
* (params['maxAngularVelocity'] - params['minAngularVelocity'])
# Make sure we don't allow stationary (no velocity)
if params['maxVelocity'] > 0:
if velocityX == 0 and velocityY == 0:
velocityX, velocityY = self._rng.choice(numpy.array(
[(-1, -1), (-1, 1), (1, -1), (1, 1)], dtype=int) \
* max(1, params['minVelocity']))
# Override default state
state['posnX'] = posnX
state['posnY'] = posnY
state['velocityX'] = velocityX
state['velocityY'] = velocityY
state['catIndex'] = catIndex
state['angularPosn'] = angularPosn
state['angularVelocity'] = angularVelocity
def updateSequence(self, state, params):
"""
Update the state associated with an existing sequence.
@param state: dict containing the
@returns: None
Must be overridden by sub-classes, and must not invoke this base class method.
"""
state['posnX'] += state['velocityX']
state['posnY'] += state['velocityY']
# Apply angular rotation (expressed in degrees)
angularPosn = state['angularPosn'] + state['angularVelocity']
rotations = angularPosn / 360.0
netRotations = rotations - round(rotations)
angularPosn = netRotations * 360.0
state['angularPosn'] = angularPosn
|
agpl-3.0
|
[
3,
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
6171,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
624,
199,
2765,
570,
7890,
9571,
29439,
4527,
22732,
12,
376,
15868,
3859,
367,
199,
29439,
10160,
14,
199,
624,
199,
199,
3,
31079,
13,
7522,
8925,
199,
646,
2680,
199,
199,
3,
10111,
8925,
199,
504,
26084,
14,
11963,
14,
29439,
10160,
492,
19835,
5722,
10160,
4388,
199,
533,
9571,
29439,
4527,
22732,
8,
29439,
10160,
14,
29439,
4527,
22732,
304,
523,
408,
523,
5543,
1150,
83,
19608,
590,
17083,
316,
8013,
402,
19311,
4895,
523,
9695,
626,
5584,
7840,
9371,
314,
10218,
737,
6770,
523,
11199,
320,
18207,
14,
523,
408,
819,
768,
3744,
523,
347,
1827,
497,
9723,
6007,
8,
11645,
304,
272,
408,
272,
1803,
282,
3414,
402,
2725,
1561,
626,
787,
12082,
370,
272,
314,
3439,
402,
314,
15868,
3859,
14,
339,
10162,
506,
9243,
503,
10087,
701,
1007,
13,
2888,
465,
5827,
14,
272,
408,
272,
372,
334,
283,
2063,
297,
283,
3333,
297,
1467,
283,
31701,
5195,
1385,
297,
283,
988,
6397,
297,
1467,
283,
827,
23213,
297,
283,
988,
23213,
297,
1467,
283,
827,
2493,
71,
2238,
6981,
78,
297,
283,
988,
2493,
71,
2238,
6981,
78,
297,
1467,
283,
827,
2493,
71,
2238,
23213,
297,
283,
988,
2493,
71,
2238,
23213,
297,
1779,
776,
819,
347,
4205,
5826,
8,
277,
12,
1174,
12,
1862,
304,
272,
408,
272,
2790,
314,
1174,
4568,
543,
282,
892,
3414,
14,
339,
768,
635,
1174,
26,
282,
1211,
3035,
314,
849,
1338,
367,
892,
1779,
3414,
1174,
14,
221,
961,
1211,
911,
1395,
314,
2569,
2883,
1779,
334,
8460,
2883,
1443,
506,
3483,
701,
314,
1083,
4514,
304,
1467,
6230,
2681,
446,
314,
378,
13,
6788,
1478,
402,
314,
4637,
717,
626,
911,
506,
1202,
367,
314,
3414,
27,
1467,
2086,
78,
56,
446,
314,
2536,
1323,
3421,
402,
314,
3851,
1159,
3659,
717,
2376,
367,
314,
892,
3414,
27,
1467,
2086,
78,
57,
446,
314,
2536,
1488,
3421,
402,
314,
3851,
1159,
3659,
717,
2376,
367,
314,
892,
3414,
27,
1467,
20508,
56,
446,
314,
2536,
17528,
20508,
402,
314,
717,
3851,
1159,
3659,
2376,
367,
314,
892,
3414,
27,
1467,
20508,
57,
446,
314,
2536,
13763,
20508,
402,
314,
717,
3851,
1159,
3659,
2376,
367,
314,
892,
3414,
27,
1467,
30921,
6981,
78,
446,
314,
2536,
30921,
3421,
334,
262,
14358,
9,
402,
717,
314,
3851,
367,
314,
892,
3414,
27,
1467,
30921,
23213,
446,
314,
2536,
30921,
20508,
334,
262,
14358,
717,
1126,
8494,
9,
402,
314,
3851,
367,
314,
892,
3414,
27,
339,
9498,
506,
10087,
701,
1007,
13,
2888,
12,
436,
1471,
440,
12677,
642,
1300,
1021,
1083,
14,
272,
408,
272,
3851,
2320,
275,
1174,
459,
3401,
2320,
418,
272,
308,
18630,
56,
275,
334,
1162,
459,
2063,
418,
221,
446,
3851,
2320,
9,
5001,
499,
272,
308,
18630,
57,
275,
334,
1162,
459,
3333,
418,
446,
3851,
2320,
9,
5001,
499,
272,
340,
1862,
459,
31701,
5195,
1385,
2565,
489,
308,
18630,
56,
275,
2853,
8,
83,
18630,
56,
9,
489,
308,
18630,
57,
275,
2853,
8,
83,
18630,
57,
9,
272,
340,
1862,
459,
988,
6397,
418,
1137,
446,
17,
26,
489,
308,
18630,
56,
275,
1748,
8,
2101,
8,
83,
18630,
56,
395,
1862,
459,
988,
6397,
1105,
489,
308,
18630,
57,
275,
1748,
8,
2101,
8,
83,
18630,
57,
395,
1862,
459,
988,
6397,
1105,
272,
2086,
78,
56,
275,
291,
423,
12686,
14,
5095,
8,
21120,
2801,
83,
18630,
56,
12,
308,
18630,
56,
435,
413,
430,
272,
2086,
78,
57,
275,
291,
423,
12686,
14,
5095,
8,
21120,
2801,
83,
18630,
57,
12,
308,
18630,
57,
435,
413,
430,
272,
20508,
56,
275,
291,
423,
12686,
14,
5095,
11468,
17,
12,
435,
17,
566,
971,
1598,
627,
291,
423,
12686,
14,
5095,
8,
21120,
8,
1162,
459,
827,
23213,
995,
1862,
459,
988,
23213,
418,
435,
413,
430,
272,
20508,
57,
275,
291,
423,
12686,
14,
5095,
11468,
17,
12,
435,
17,
566,
971,
1598,
627,
291,
423,
12686,
14,
5095,
8,
21120,
8,
1162,
459,
827,
23213,
995,
1862,
459,
988,
23213,
418,
435,
413,
430,
272,
327,
29826,
282,
4637,
2196,
272,
6230,
2681,
275,
291,
423,
16143,
7841,
342,
272,
327,
29826,
7513,
6279,
1862,
272,
30921,
6981,
78,
275,
1862,
459,
827,
2493,
71,
2238,
6981,
78,
418,
435,
291,
423,
12686,
14,
2355,
342,
971,
355,
627,
334,
1162,
459,
988,
2493,
71,
2238,
6981,
78,
418,
446,
1862,
459,
827,
2493,
71,
2238,
6981,
78,
1105,
272,
30921,
23213,
275,
1862,
459,
827,
2493,
71,
2238,
23213,
418,
435,
291,
423,
12686,
14,
2355,
342,
971,
355,
627,
334,
1162,
459,
988,
2493,
71,
2238,
23213,
418,
446,
1862,
459,
827,
2493,
71,
2238,
23213,
1105,
339,
327,
4155,
3238,
781,
2793,
1133,
2040,
16518,
695,
334,
889,
20508,
9,
272,
340,
1862,
459,
988,
23213,
418,
690,
378,
26,
489,
340,
20508,
56,
508,
378,
436,
20508,
57,
508,
378,
26,
267,
20508
] |
[
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
6171,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
624,
199,
2765,
570,
7890,
9571,
29439,
4527,
22732,
12,
376,
15868,
3859,
367,
199,
29439,
10160,
14,
199,
624,
199,
199,
3,
31079,
13,
7522,
8925,
199,
646,
2680,
199,
199,
3,
10111,
8925,
199,
504,
26084,
14,
11963,
14,
29439,
10160,
492,
19835,
5722,
10160,
4388,
199,
533,
9571,
29439,
4527,
22732,
8,
29439,
10160,
14,
29439,
4527,
22732,
304,
523,
408,
523,
5543,
1150,
83,
19608,
590,
17083,
316,
8013,
402,
19311,
4895,
523,
9695,
626,
5584,
7840,
9371,
314,
10218,
737,
6770,
523,
11199,
320,
18207,
14,
523,
408,
819,
768,
3744,
523,
347,
1827,
497,
9723,
6007,
8,
11645,
304,
272,
408,
272,
1803,
282,
3414,
402,
2725,
1561,
626,
787,
12082,
370,
272,
314,
3439,
402,
314,
15868,
3859,
14,
339,
10162,
506,
9243,
503,
10087,
701,
1007,
13,
2888,
465,
5827,
14,
272,
408,
272,
372,
334,
283,
2063,
297,
283,
3333,
297,
1467,
283,
31701,
5195,
1385,
297,
283,
988,
6397,
297,
1467,
283,
827,
23213,
297,
283,
988,
23213,
297,
1467,
283,
827,
2493,
71,
2238,
6981,
78,
297,
283,
988,
2493,
71,
2238,
6981,
78,
297,
1467,
283,
827,
2493,
71,
2238,
23213,
297,
283,
988,
2493,
71,
2238,
23213,
297,
1779,
776,
819,
347,
4205,
5826,
8,
277,
12,
1174,
12,
1862,
304,
272,
408,
272,
2790,
314,
1174,
4568,
543,
282,
892,
3414,
14,
339,
768,
635,
1174,
26,
282,
1211,
3035,
314,
849,
1338,
367,
892,
1779,
3414,
1174,
14,
221,
961,
1211,
911,
1395,
314,
2569,
2883,
1779,
334,
8460,
2883,
1443,
506,
3483,
701,
314,
1083,
4514,
304,
1467,
6230,
2681,
446,
314,
378,
13,
6788,
1478,
402,
314,
4637,
717,
626,
911,
506,
1202,
367,
314,
3414,
27,
1467,
2086,
78,
56,
446,
314,
2536,
1323,
3421,
402,
314,
3851,
1159,
3659,
717,
2376,
367,
314,
892,
3414,
27,
1467,
2086,
78,
57,
446,
314,
2536,
1488,
3421,
402,
314,
3851,
1159,
3659,
717,
2376,
367,
314,
892,
3414,
27,
1467,
20508,
56,
446,
314,
2536,
17528,
20508,
402,
314,
717,
3851,
1159,
3659,
2376,
367,
314,
892,
3414,
27,
1467,
20508,
57,
446,
314,
2536,
13763,
20508,
402,
314,
717,
3851,
1159,
3659,
2376,
367,
314,
892,
3414,
27,
1467,
30921,
6981,
78,
446,
314,
2536,
30921,
3421,
334,
262,
14358,
9,
402,
717,
314,
3851,
367,
314,
892,
3414,
27,
1467,
30921,
23213,
446,
314,
2536,
30921,
20508,
334,
262,
14358,
717,
1126,
8494,
9,
402,
314,
3851,
367,
314,
892,
3414,
27,
339,
9498,
506,
10087,
701,
1007,
13,
2888,
12,
436,
1471,
440,
12677,
642,
1300,
1021,
1083,
14,
272,
408,
272,
3851,
2320,
275,
1174,
459,
3401,
2320,
418,
272,
308,
18630,
56,
275,
334,
1162,
459,
2063,
418,
221,
446,
3851,
2320,
9,
5001,
499,
272,
308,
18630,
57,
275,
334,
1162,
459,
3333,
418,
446,
3851,
2320,
9,
5001,
499,
272,
340,
1862,
459,
31701,
5195,
1385,
2565,
489,
308,
18630,
56,
275,
2853,
8,
83,
18630,
56,
9,
489,
308,
18630,
57,
275,
2853,
8,
83,
18630,
57,
9,
272,
340,
1862,
459,
988,
6397,
418,
1137,
446,
17,
26,
489,
308,
18630,
56,
275,
1748,
8,
2101,
8,
83,
18630,
56,
395,
1862,
459,
988,
6397,
1105,
489,
308,
18630,
57,
275,
1748,
8,
2101,
8,
83,
18630,
57,
395,
1862,
459,
988,
6397,
1105,
272,
2086,
78,
56,
275,
291,
423,
12686,
14,
5095,
8,
21120,
2801,
83,
18630,
56,
12,
308,
18630,
56,
435,
413,
430,
272,
2086,
78,
57,
275,
291,
423,
12686,
14,
5095,
8,
21120,
2801,
83,
18630,
57,
12,
308,
18630,
57,
435,
413,
430,
272,
20508,
56,
275,
291,
423,
12686,
14,
5095,
11468,
17,
12,
435,
17,
566,
971,
1598,
627,
291,
423,
12686,
14,
5095,
8,
21120,
8,
1162,
459,
827,
23213,
995,
1862,
459,
988,
23213,
418,
435,
413,
430,
272,
20508,
57,
275,
291,
423,
12686,
14,
5095,
11468,
17,
12,
435,
17,
566,
971,
1598,
627,
291,
423,
12686,
14,
5095,
8,
21120,
8,
1162,
459,
827,
23213,
995,
1862,
459,
988,
23213,
418,
435,
413,
430,
272,
327,
29826,
282,
4637,
2196,
272,
6230,
2681,
275,
291,
423,
16143,
7841,
342,
272,
327,
29826,
7513,
6279,
1862,
272,
30921,
6981,
78,
275,
1862,
459,
827,
2493,
71,
2238,
6981,
78,
418,
435,
291,
423,
12686,
14,
2355,
342,
971,
355,
627,
334,
1162,
459,
988,
2493,
71,
2238,
6981,
78,
418,
446,
1862,
459,
827,
2493,
71,
2238,
6981,
78,
1105,
272,
30921,
23213,
275,
1862,
459,
827,
2493,
71,
2238,
23213,
418,
435,
291,
423,
12686,
14,
2355,
342,
971,
355,
627,
334,
1162,
459,
988,
2493,
71,
2238,
23213,
418,
446,
1862,
459,
827,
2493,
71,
2238,
23213,
1105,
339,
327,
4155,
3238,
781,
2793,
1133,
2040,
16518,
695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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
] |
UManPychron/pychron
|
docs/user_guide/operation/scripts/examples/argus/measurement/noise/jan_noise20_8_125.py
|
4
|
2291
|
#!Measurement
'''
baseline:
after: true
before: false
counts: 125
detector: H1
mass: 34.2
settling_time: 15.0
default_fits: average
equilibration:
eqtime: 1.0
inlet: R
inlet_delay: 3
outlet: O
use_extraction_eqtime: true
multicollect:
counts: 20
detector: H1
isotope: Ar40
peakcenter:
after: false
before: false
detector: H1
detectors:
- H1
- AX
- CDD
integration_time: 0.262144
isotope: Ar40
peakhop:
generate_ic_table: false
hops_name: ''
ncycles: 0
use_peak_hop: false
'''
ACTIVE_DETECTORS=('H2','H1','AX','L1','L2','CDD')
def main():
info('unknown measurement script')
activate_detectors(*ACTIVE_DETECTORS)
if mx.peakcenter.before:
peak_center(detector=mx.peakcenter.detector,isotope=mx.peakcenter.isotope)
if mx.baseline.before:
baselines(ncounts=mx.baseline.counts,mass=mx.baseline.mass, detector=mx.baseline.detector,
settling_time=mx.baseline.settling_time)
position_magnet(mx.multicollect.isotope, detector=mx.multicollect.detector)
#sniff the gas during equilibration
if mx.equilibration.use_extraction_eqtime:
eqt = eqtime
else:
eqt = mx.equilibration.eqtime
'''
Equilibrate is non-blocking so use a sniff or sleep as a placeholder
e.g sniff(<equilibration_time>) or sleep(<equilibration_time>)
'''
set_integration_time(1)
equilibrate(eqtime=eqt, inlet=mx.equilibration.inlet, outlet=mx.equilibration.outlet,
delay=mx.equilibration.inlet_delay)
set_time_zero()
sniff(eqt)
set_fits()
set_baseline_fits()
#multicollect on active detectors
multicollect(ncounts=mx.multicollect.counts)
if mx.baseline.after:
baselines(ncounts=mx.baseline.counts,mass=mx.baseline.mass, detector=mx.baseline.detector,
settling_time=mx.baseline.settling_time,
integration_time=8)
if mx.peakcenter.after:
activate_detectors(*mx.peakcenter.detectors, **{'peak_center':True})
peak_center(detector=mx.peakcenter.detector,isotope=mx.peakcenter.isotope,
integration_time=mx.peakcenter.integration_time)
if use_cdd_warming:
gosub('warm_cdd', argv=(mx.equilibration.outlet,))
info('finished measure script')
|
apache-2.0
|
[
3168,
18611,
434,
199,
2344,
199,
14232,
26,
523,
2410,
26,
2549,
523,
2544,
26,
3055,
523,
8242,
26,
19163,
523,
17842,
26,
869,
17,
523,
12250,
26,
8177,
14,
18,
523,
663,
32642,
63,
521,
26,
4114,
14,
16,
199,
885,
63,
14948,
26,
8095,
199,
69,
783,
773,
1754,
26,
523,
3850,
521,
26,
413,
14,
16,
523,
315,
2723,
26,
820,
523,
315,
2723,
63,
5814,
26,
650,
523,
734,
2723,
26,
593,
523,
675,
63,
24020,
63,
4077,
521,
26,
2549,
199,
3029,
7112,
26,
523,
8242,
26,
3388,
523,
17842,
26,
869,
17,
523,
365,
3459,
321,
26,
1952,
2167,
199,
8556,
4218,
26,
523,
2410,
26,
3055,
523,
2544,
26,
3055,
523,
17842,
26,
869,
17,
523,
17842,
83,
26,
523,
446,
869,
17,
523,
446,
437,
56,
523,
446,
445,
5745,
523,
13150,
63,
521,
26,
378,
14,
1479,
6886,
20,
523,
365,
3459,
321,
26,
1952,
2167,
199,
8556,
13376,
26,
523,
3550,
63,
530,
63,
1224,
26,
3055,
523,
394,
1483,
63,
354,
26,
2125,
523,
302,
23356,
26,
378,
523,
675,
63,
8556,
63,
13376,
26,
3055,
199,
2344,
199,
10401,
63,
17442,
3582,
4149,
7782,
40,
18,
1673,
40,
17,
1673,
9839,
1673,
44,
17,
1673,
44,
18,
1673,
35,
5745,
358,
199,
199,
318,
2446,
837,
272,
2256,
360,
5187,
18216,
2884,
358,
339,
15422,
63,
19401,
83,
2031,
10401,
63,
17442,
3582,
4149,
9,
2378,
340,
8728,
14,
8556,
4218,
14,
5182,
26,
267,
21441,
63,
4218,
8,
19401,
29,
9457,
14,
8556,
4218,
14,
19401,
12,
374,
3459,
321,
29,
9457,
14,
8556,
4218,
14,
374,
3459,
321,
9,
339,
340,
8728,
14,
14232,
14,
5182,
26,
267,
1300,
1278,
8,
78,
6851,
29,
9457,
14,
14232,
14,
6851,
12,
11535,
29,
9457,
14,
14232,
14,
11535,
12,
17842,
29,
9457,
14,
14232,
14,
19401,
12,
2116,
663,
32642,
63,
521,
29,
9457,
14,
14232,
14,
409,
32642,
63,
521,
9,
339,
3421,
63,
19902,
386,
8,
9457,
14,
3029,
7112,
14,
374,
3459,
321,
12,
17842,
29,
9457,
14,
3029,
7112,
14,
19401,
9,
339,
327,
5167,
15126,
314,
486,
305,
5309,
325,
783,
773,
1754,
272,
340,
8728,
14,
69,
783,
773,
1754,
14,
1180,
63,
24020,
63,
4077,
521,
26,
267,
3850,
84,
275,
3850,
521,
272,
587,
26,
267,
3850,
84,
275,
8728,
14,
69,
783,
773,
1754,
14,
4077,
521,
272,
1449,
272,
662,
783,
773,
1866,
365,
2222,
13,
13091,
880,
675,
282,
6895,
15126,
503,
9435,
465,
282,
10069,
272,
325,
14,
71,
6895,
15126,
27530,
69,
783,
773,
1754,
63,
521,
18956,
503,
9435,
27530,
69,
783,
773,
1754,
63,
521,
18956,
272,
1449,
272,
663,
63,
15092,
63,
521,
8,
17,
9,
339,
325,
783,
773,
1866,
8,
4077,
521,
29,
4077,
84,
12,
315,
2723,
29,
9457,
14,
69,
783,
773,
1754,
14,
262,
2723,
12,
734,
2723,
29,
9457,
14,
69,
783,
773,
1754,
14,
548,
2723,
12,
2049,
7339,
29,
9457,
14,
69,
783,
773,
1754,
14,
262,
2723,
63,
5814,
9,
339,
663,
63,
521,
63,
4262,
342,
339,
6895,
15126,
8,
4077,
84,
9,
272,
663,
63,
14948,
342,
272,
663,
63,
14232,
63,
14948,
342,
339,
327,
3029,
7112,
641,
4702,
17842,
83,
272,
3510,
7112,
8,
78,
6851,
29,
9457,
14,
3029,
7112,
14,
6851,
9,
339,
340,
8728,
14,
14232,
14,
4399,
26,
267,
1300,
1278,
8,
78,
6851,
29,
9457,
14,
14232,
14,
6851,
12,
11535,
29,
9457,
14,
14232,
14,
11535,
12,
17842,
29,
9457,
14,
14232,
14,
19401,
12,
2116,
663,
32642,
63,
521,
29,
9457,
14,
14232,
14,
409,
32642,
63,
521,
12,
2116,
13150,
63,
521,
29,
24,
9,
272,
340,
8728,
14,
8556,
4218,
14,
4399,
26,
267,
15422,
63,
19401,
83,
2031,
9457,
14,
8556,
4218,
14,
19401,
83,
12,
30653,
8556,
63,
4218,
356,
549,
1552,
267,
21441,
63,
4218,
8,
19401,
29,
9457,
14,
8556,
4218,
14,
19401,
12,
374,
3459,
321,
29,
9457,
14,
8556,
4218,
14,
374,
3459,
321,
12,
267,
13150,
63,
521,
29,
9457,
14,
8556,
4218,
14,
15092,
63,
521,
9,
339,
340,
675,
63,
67,
617,
63,
10669,
316,
26,
2126,
486,
736,
456,
360,
10669,
63,
67,
617,
297,
9238,
2687,
9457,
14,
69,
783,
773,
1754,
14,
548,
2723,
4641,
339,
2256,
360,
8669,
9775,
2884,
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
] |
[
18611,
434,
199,
2344,
199,
14232,
26,
523,
2410,
26,
2549,
523,
2544,
26,
3055,
523,
8242,
26,
19163,
523,
17842,
26,
869,
17,
523,
12250,
26,
8177,
14,
18,
523,
663,
32642,
63,
521,
26,
4114,
14,
16,
199,
885,
63,
14948,
26,
8095,
199,
69,
783,
773,
1754,
26,
523,
3850,
521,
26,
413,
14,
16,
523,
315,
2723,
26,
820,
523,
315,
2723,
63,
5814,
26,
650,
523,
734,
2723,
26,
593,
523,
675,
63,
24020,
63,
4077,
521,
26,
2549,
199,
3029,
7112,
26,
523,
8242,
26,
3388,
523,
17842,
26,
869,
17,
523,
365,
3459,
321,
26,
1952,
2167,
199,
8556,
4218,
26,
523,
2410,
26,
3055,
523,
2544,
26,
3055,
523,
17842,
26,
869,
17,
523,
17842,
83,
26,
523,
446,
869,
17,
523,
446,
437,
56,
523,
446,
445,
5745,
523,
13150,
63,
521,
26,
378,
14,
1479,
6886,
20,
523,
365,
3459,
321,
26,
1952,
2167,
199,
8556,
13376,
26,
523,
3550,
63,
530,
63,
1224,
26,
3055,
523,
394,
1483,
63,
354,
26,
2125,
523,
302,
23356,
26,
378,
523,
675,
63,
8556,
63,
13376,
26,
3055,
199,
2344,
199,
10401,
63,
17442,
3582,
4149,
7782,
40,
18,
1673,
40,
17,
1673,
9839,
1673,
44,
17,
1673,
44,
18,
1673,
35,
5745,
358,
199,
199,
318,
2446,
837,
272,
2256,
360,
5187,
18216,
2884,
358,
339,
15422,
63,
19401,
83,
2031,
10401,
63,
17442,
3582,
4149,
9,
2378,
340,
8728,
14,
8556,
4218,
14,
5182,
26,
267,
21441,
63,
4218,
8,
19401,
29,
9457,
14,
8556,
4218,
14,
19401,
12,
374,
3459,
321,
29,
9457,
14,
8556,
4218,
14,
374,
3459,
321,
9,
339,
340,
8728,
14,
14232,
14,
5182,
26,
267,
1300,
1278,
8,
78,
6851,
29,
9457,
14,
14232,
14,
6851,
12,
11535,
29,
9457,
14,
14232,
14,
11535,
12,
17842,
29,
9457,
14,
14232,
14,
19401,
12,
2116,
663,
32642,
63,
521,
29,
9457,
14,
14232,
14,
409,
32642,
63,
521,
9,
339,
3421,
63,
19902,
386,
8,
9457,
14,
3029,
7112,
14,
374,
3459,
321,
12,
17842,
29,
9457,
14,
3029,
7112,
14,
19401,
9,
339,
327,
5167,
15126,
314,
486,
305,
5309,
325,
783,
773,
1754,
272,
340,
8728,
14,
69,
783,
773,
1754,
14,
1180,
63,
24020,
63,
4077,
521,
26,
267,
3850,
84,
275,
3850,
521,
272,
587,
26,
267,
3850,
84,
275,
8728,
14,
69,
783,
773,
1754,
14,
4077,
521,
272,
1449,
272,
662,
783,
773,
1866,
365,
2222,
13,
13091,
880,
675,
282,
6895,
15126,
503,
9435,
465,
282,
10069,
272,
325,
14,
71,
6895,
15126,
27530,
69,
783,
773,
1754,
63,
521,
18956,
503,
9435,
27530,
69,
783,
773,
1754,
63,
521,
18956,
272,
1449,
272,
663,
63,
15092,
63,
521,
8,
17,
9,
339,
325,
783,
773,
1866,
8,
4077,
521,
29,
4077,
84,
12,
315,
2723,
29,
9457,
14,
69,
783,
773,
1754,
14,
262,
2723,
12,
734,
2723,
29,
9457,
14,
69,
783,
773,
1754,
14,
548,
2723,
12,
2049,
7339,
29,
9457,
14,
69,
783,
773,
1754,
14,
262,
2723,
63,
5814,
9,
339,
663,
63,
521,
63,
4262,
342,
339,
6895,
15126,
8,
4077,
84,
9,
272,
663,
63,
14948,
342,
272,
663,
63,
14232,
63,
14948,
342,
339,
327,
3029,
7112,
641,
4702,
17842,
83,
272,
3510,
7112,
8,
78,
6851,
29,
9457,
14,
3029,
7112,
14,
6851,
9,
339,
340,
8728,
14,
14232,
14,
4399,
26,
267,
1300,
1278,
8,
78,
6851,
29,
9457,
14,
14232,
14,
6851,
12,
11535,
29,
9457,
14,
14232,
14,
11535,
12,
17842,
29,
9457,
14,
14232,
14,
19401,
12,
2116,
663,
32642,
63,
521,
29,
9457,
14,
14232,
14,
409,
32642,
63,
521,
12,
2116,
13150,
63,
521,
29,
24,
9,
272,
340,
8728,
14,
8556,
4218,
14,
4399,
26,
267,
15422,
63,
19401,
83,
2031,
9457,
14,
8556,
4218,
14,
19401,
83,
12,
30653,
8556,
63,
4218,
356,
549,
1552,
267,
21441,
63,
4218,
8,
19401,
29,
9457,
14,
8556,
4218,
14,
19401,
12,
374,
3459,
321,
29,
9457,
14,
8556,
4218,
14,
374,
3459,
321,
12,
267,
13150,
63,
521,
29,
9457,
14,
8556,
4218,
14,
15092,
63,
521,
9,
339,
340,
675,
63,
67,
617,
63,
10669,
316,
26,
2126,
486,
736,
456,
360,
10669,
63,
67,
617,
297,
9238,
2687,
9457,
14,
69,
783,
773,
1754,
14,
548,
2723,
4641,
339,
2256,
360,
8669,
9775,
2884,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
asimonia/Flask-Task
|
views.py
|
1
|
1097
|
import sqlite3
from functools import wraps
from flask import Flask, flash, redirect, render_template, request, session, url_for
# config
app = Flask(__name__)
app.config.from_object('_config')
# helper functions
def connect_db():
return sqlite3.connect(app.config['DATABASE_PATH'])
def login_required(test):
@wraps(test)
def wrap(*args, **kwargs):
if 'logged_in' in session:
return test(*args, **kwargs)
else:
flash('You need to login first.')
return redirect(url_for('login'))
return wrap
# route handlers
@app.route('/logout/')
def logout():
session.pop('logged_in', None)
flash("Bye!")
return redirect(url_for('login'))
@app.route('/', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
if request.form['username'] != app.config['USERNAME'] \
or request.form['password'] != app.config['PASSWORD']:
error = 'Invalid Credentials. Please try again.'
return render_template('login.html', error=error)
else:
session['logged_in'] = True
flash("Welcome!")
return redirect(url_for('tasks'))
return render_template('login.html')
|
apache-2.0
|
[
646,
11723,
19,
199,
504,
9143,
492,
14018,
199,
199,
504,
7209,
492,
16704,
12,
14775,
12,
4660,
12,
3795,
63,
1160,
12,
1056,
12,
2351,
12,
1166,
63,
509,
4388,
199,
3,
1101,
199,
571,
275,
16704,
3460,
354,
3368,
199,
571,
14,
888,
14,
504,
63,
785,
6412,
888,
358,
421,
199,
3,
5922,
3423,
421,
199,
318,
4907,
63,
697,
837,
199,
198,
1107,
11723,
19,
14,
2242,
8,
571,
14,
888,
459,
17873,
63,
3243,
1105,
421,
199,
318,
4676,
63,
2427,
8,
396,
304,
199,
198,
32,
13582,
8,
396,
9,
199,
198,
318,
4816,
2031,
589,
12,
1011,
958,
304,
507,
198,
692,
283,
12419,
63,
262,
7,
315,
2351,
26,
686,
198,
1107,
511,
2031,
589,
12,
1011,
958,
9,
507,
198,
2836,
26,
686,
198,
11331,
360,
5556,
1929,
370,
4676,
1642,
2659,
686,
198,
1107,
4660,
8,
633,
63,
509,
360,
2886,
1333,
199,
198,
1107,
4816,
421,
199,
3,
7475,
8297,
199,
199,
32,
571,
14,
4449,
2336,
11646,
6217,
199,
318,
22079,
837,
199,
198,
1730,
14,
1935,
360,
12419,
63,
262,
297,
488,
9,
199,
198,
11331,
480,
2175,
69,
9124,
199,
198,
1107,
4660,
8,
633,
63,
509,
360,
2886,
1333,
421,
199,
32,
571,
14,
4449,
10998,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
318,
4676,
837,
199,
198,
692,
1056,
14,
765,
508,
283,
4030,
356,
507,
198,
692,
1056,
14,
964,
459,
2473,
418,
1137,
1145,
14,
888,
459,
11958,
418,
971,
686,
198,
269,
1056,
14,
964,
459,
2060,
418,
1137,
1145,
14,
888,
459,
9032,
2565,
686,
198,
705,
275,
283,
3364,
23934,
14,
7754,
862,
4020,
3530,
686,
198,
1107,
3795,
63,
1160,
360,
2886,
14,
1360,
297,
1125,
29,
705,
9,
507,
198,
2836,
26,
686,
198,
1730,
459,
12419,
63,
262,
418,
275,
715,
686,
198,
11331,
480,
24679,
9124,
686,
198,
1107,
4660,
8,
633,
63,
509,
360,
5054,
1333,
199,
198,
1107,
3795,
63,
1160,
360,
2886,
14,
1360,
358,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
11723,
19,
199,
504,
9143,
492,
14018,
199,
199,
504,
7209,
492,
16704,
12,
14775,
12,
4660,
12,
3795,
63,
1160,
12,
1056,
12,
2351,
12,
1166,
63,
509,
4388,
199,
3,
1101,
199,
571,
275,
16704,
3460,
354,
3368,
199,
571,
14,
888,
14,
504,
63,
785,
6412,
888,
358,
421,
199,
3,
5922,
3423,
421,
199,
318,
4907,
63,
697,
837,
199,
198,
1107,
11723,
19,
14,
2242,
8,
571,
14,
888,
459,
17873,
63,
3243,
1105,
421,
199,
318,
4676,
63,
2427,
8,
396,
304,
199,
198,
32,
13582,
8,
396,
9,
199,
198,
318,
4816,
2031,
589,
12,
1011,
958,
304,
507,
198,
692,
283,
12419,
63,
262,
7,
315,
2351,
26,
686,
198,
1107,
511,
2031,
589,
12,
1011,
958,
9,
507,
198,
2836,
26,
686,
198,
11331,
360,
5556,
1929,
370,
4676,
1642,
2659,
686,
198,
1107,
4660,
8,
633,
63,
509,
360,
2886,
1333,
199,
198,
1107,
4816,
421,
199,
3,
7475,
8297,
199,
199,
32,
571,
14,
4449,
2336,
11646,
6217,
199,
318,
22079,
837,
199,
198,
1730,
14,
1935,
360,
12419,
63,
262,
297,
488,
9,
199,
198,
11331,
480,
2175,
69,
9124,
199,
198,
1107,
4660,
8,
633,
63,
509,
360,
2886,
1333,
421,
199,
32,
571,
14,
4449,
10998,
3102,
2968,
2970,
297,
283,
4030,
1105,
199,
318,
4676,
837,
199,
198,
692,
1056,
14,
765,
508,
283,
4030,
356,
507,
198,
692,
1056,
14,
964,
459,
2473,
418,
1137,
1145,
14,
888,
459,
11958,
418,
971,
686,
198,
269,
1056,
14,
964,
459,
2060,
418,
1137,
1145,
14,
888,
459,
9032,
2565,
686,
198,
705,
275,
283,
3364,
23934,
14,
7754,
862,
4020,
3530,
686,
198,
1107,
3795,
63,
1160,
360,
2886,
14,
1360,
297,
1125,
29,
705,
9,
507,
198,
2836,
26,
686,
198,
1730,
459,
12419,
63,
262,
418,
275,
715,
686,
198,
11331,
480,
24679,
9124,
686,
198,
1107,
4660,
8,
633,
63,
509,
360,
5054,
1333,
199,
198,
1107,
3795,
63,
1160,
360,
2886,
14,
1360,
358,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
bzero/statsmodels
|
statsmodels/compat/scipy.py
|
31
|
6660
|
from __future__ import absolute_import
import numpy as np
def _bit_length_26(x):
if x == 0:
return 0
elif x == 1:
return 1
else:
return len(bin(x)) - 2
try:
from scipy.lib._version import NumpyVersion
except ImportError:
import re
from .python import string_types
class NumpyVersion():
"""Parse and compare numpy version strings.
Numpy has the following versioning scheme (numbers given are examples; they
can be >9) in principle):
- Released version: '1.8.0', '1.8.1', etc.
- Alpha: '1.8.0a1', '1.8.0a2', etc.
- Beta: '1.8.0b1', '1.8.0b2', etc.
- Release candidates: '1.8.0rc1', '1.8.0rc2', etc.
- Development versions: '1.8.0.dev-f1234afa' (git commit hash appended)
- Development versions after a1: '1.8.0a1.dev-f1234afa',
'1.8.0b2.dev-f1234afa',
'1.8.1rc1.dev-f1234afa', etc.
- Development versions (no git hash available): '1.8.0.dev-Unknown'
Comparing needs to be done against a valid version string or other
`NumpyVersion` instance.
Parameters
----------
vstring : str
Numpy version string (``np.__version__``).
Notes
-----
All dev versions of the same (pre-)release compare equal.
Examples
--------
>>> from scipy.lib._version import NumpyVersion
>>> if NumpyVersion(np.__version__) < '1.7.0':
... print('skip')
skip
>>> NumpyVersion('1.7') # raises ValueError, add ".0"
"""
def __init__(self, vstring):
self.vstring = vstring
ver_main = re.match(r'\d[.]\d+[.]\d+', vstring)
if not ver_main:
raise ValueError("Not a valid numpy version string")
self.version = ver_main.group()
self.major, self.minor, self.bugfix = [int(x) for x in
self.version.split('.')]
if len(vstring) == ver_main.end():
self.pre_release = 'final'
else:
alpha = re.match(r'a\d', vstring[ver_main.end():])
beta = re.match(r'b\d', vstring[ver_main.end():])
rc = re.match(r'rc\d', vstring[ver_main.end():])
pre_rel = [m for m in [alpha, beta, rc] if m is not None]
if pre_rel:
self.pre_release = pre_rel[0].group()
else:
self.pre_release = ''
self.is_devversion = bool(re.search(r'.dev-', vstring))
def _compare_version(self, other):
"""Compare major.minor.bugfix"""
if self.major == other.major:
if self.minor == other.minor:
if self.bugfix == other.bugfix:
vercmp = 0
elif self.bugfix > other.bugfix:
vercmp = 1
else:
vercmp = -1
elif self.minor > other.minor:
vercmp = 1
else:
vercmp = -1
elif self.major > other.major:
vercmp = 1
else:
vercmp = -1
return vercmp
def _compare_pre_release(self, other):
"""Compare alpha/beta/rc/final."""
if self.pre_release == other.pre_release:
vercmp = 0
elif self.pre_release == 'final':
vercmp = 1
elif other.pre_release == 'final':
vercmp = -1
elif self.pre_release > other.pre_release:
vercmp = 1
else:
vercmp = -1
return vercmp
def _compare(self, other):
if not isinstance(other, (string_types, NumpyVersion)):
raise ValueError("Invalid object to compare with NumpyVersion.")
if isinstance(other, string_types):
other = NumpyVersion(other)
vercmp = self._compare_version(other)
if vercmp == 0:
# Same x.y.z version, check for alpha/beta/rc
vercmp = self._compare_pre_release(other)
if vercmp == 0:
# Same version and same pre-release, check if dev version
if self.is_devversion is other.is_devversion:
vercmp = 0
elif self.is_devversion:
vercmp = -1
else:
vercmp = 1
return vercmp
def __lt__(self, other):
return self._compare(other) < 0
def __le__(self, other):
return self._compare(other) <= 0
def __eq__(self, other):
return self._compare(other) == 0
def __ne__(self, other):
return self._compare(other) != 0
def __gt__(self, other):
return self._compare(other) > 0
def __ge__(self, other):
return self._compare(other) >= 0
def __repr(self):
return "NumpyVersion(%s)" % self.vstring
def _next_regular(target):
"""
Find the next regular number greater than or equal to target.
Regular numbers are composites of the prime factors 2, 3, and 5.
Also known as 5-smooth numbers or Hamming numbers, these are the optimal
size for inputs to FFTPACK.
Target must be a positive integer.
"""
if target <= 6:
return target
# Quickly check if it's already a power of 2
if not (target & (target - 1)):
return target
match = float('inf') # Anything found will be smaller
p5 = 1
while p5 < target:
p35 = p5
while p35 < target:
# Ceiling integer division, avoiding conversion to float
# (quotient = ceil(target / p35))
quotient = -(-target // p35)
# Quickly find next power of 2 >= quotient
try:
p2 = 2 ** ((quotient - 1).bit_length())
except AttributeError:
# Fallback for Python <2.7
p2 = 2 ** _bit_length_26(quotient - 1)
N = p2 * p35
if N == target:
return N
elif N < match:
match = N
p35 *= 3
if p35 == target:
return p35
if p35 < match:
match = p35
p5 *= 5
if p5 == target:
return p5
if p5 < match:
match = p5
return match
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
2680,
465,
980,
421,
199,
318,
485,
2075,
63,
1267,
63,
1479,
8,
88,
304,
272,
340,
671,
508,
378,
26,
267,
372,
378,
272,
916,
671,
508,
413,
26,
267,
372,
413,
272,
587,
26,
267,
372,
822,
8,
1393,
8,
88,
430,
446,
499,
421,
199,
893,
26,
272,
687,
7026,
14,
773,
423,
1023,
492,
20535,
3353,
199,
2590,
3545,
26,
272,
492,
295,
272,
687,
1275,
1548,
492,
1059,
63,
1313,
339,
1021,
20535,
3353,
837,
267,
408,
4003,
436,
6540,
2680,
1015,
3326,
14,
398,
20535,
965,
314,
2569,
1015,
316,
5687,
334,
10548,
1627,
787,
7251,
27,
2985,
267,
883,
506,
690,
25,
9,
315,
5448,
10352,
274,
304,
398,
446,
17646,
68,
1015,
26,
283,
17,
14,
24,
14,
16,
297,
283,
17,
14,
24,
14,
17,
297,
5423,
14,
267,
446,
32657,
26,
283,
17,
14,
24,
14,
16,
65,
17,
297,
283,
17,
14,
24,
14,
16,
65,
18,
297,
5423,
14,
267,
446,
29521,
26,
283,
17,
14,
24,
14,
16,
66,
17,
297,
283,
17,
14,
24,
14,
16,
66,
18,
297,
5423,
14,
267,
446,
17646,
15101,
26,
283,
17,
14,
24,
14,
16,
1195,
17,
297,
283,
17,
14,
24,
14,
16,
1195,
18,
297,
5423,
14,
267,
446,
15290,
5459,
26,
283,
17,
14,
24,
14,
16,
14,
2374,
13,
70,
4321,
65,
667,
7,
334,
3187,
5532,
2631,
11544,
9,
267,
446,
15290,
5459,
2410,
282,
17,
26,
283,
17,
14,
24,
14,
16,
65,
17,
14,
2374,
13,
70,
4321,
65,
667,
297,
3147,
283,
17,
14,
24,
14,
16,
66,
18,
14,
2374,
13,
70,
4321,
65,
667,
297,
3147,
283,
17,
14,
24,
14,
17,
1195,
17,
14,
2374,
13,
70,
4321,
65,
667,
297,
5423,
14,
267,
446,
15290,
5459,
334,
889,
6135,
2631,
2808,
304,
283,
17,
14,
24,
14,
16,
14,
2374,
13,
5912,
7,
398,
3599,
9332,
4839,
370,
506,
4224,
6169,
282,
1686,
1015,
1059,
503,
1163,
267,
658,
25218,
3353,
64,
1256,
14,
398,
3897,
267,
4143,
267,
373,
875,
520,
620,
288,
20535,
1015,
1059,
15693,
1590,
855,
1023,
18762,
680,
398,
8144,
267,
9063,
267,
2900,
4866,
5459,
402,
314,
2011,
334,
657,
13,
9,
3221,
6540,
4472,
14,
398,
6058,
267,
3001,
267,
1306,
687,
7026,
14,
773,
423,
1023,
492,
20535,
3353,
267,
1306,
340,
20535,
3353,
8,
1590,
855,
1023,
3368,
665,
283,
17,
14,
23,
14,
16,
356,
267,
2263,
258,
870,
360,
2759,
358,
267,
3372,
398,
1306,
20535,
3353,
360,
17,
14,
23,
358,
221,
327,
6534,
1722,
12,
1050,
3680,
16,
2,
398,
408,
398,
347,
636,
826,
721,
277,
12,
373,
875,
304,
288,
291,
14,
86,
875,
275,
373,
875,
288,
809,
63,
973,
275,
295,
14,
1431,
8,
82,
1154,
68,
30352,
7272,
68,
21324,
14,
7272,
68,
7386,
373,
875,
9,
288,
340,
440,
809,
63,
973,
26,
355,
746,
1722,
480,
1763,
282,
1686,
2680,
1015,
1059,
531,
953,
291,
14,
1023,
275,
809,
63,
973,
14,
923,
342,
288,
291,
14,
8452,
12,
291,
14,
11067,
12,
291,
14,
1266,
970,
275,
359,
442,
8,
88,
9,
367,
671,
315,
8962,
291,
14,
1023,
14,
1294,
7563,
61,
288,
340,
822,
8,
86,
875,
9,
508,
809,
63,
973,
14,
500,
837,
355,
291,
14,
657,
63,
3221,
275,
283,
5094,
7,
288,
587,
26,
355,
5131,
275,
295,
14,
1431,
8,
82,
7,
65,
60,
68,
297,
373,
875,
59,
422,
63,
973,
14,
500,
837,
566,
355,
8201,
275,
295,
14,
1431,
8,
82,
7,
66,
60,
68,
297,
373,
875,
59,
422,
63,
973,
14,
500,
837,
566,
355,
4819,
275,
295,
14,
1431,
8,
82,
7,
1195,
60,
68,
297,
373,
875,
59,
422,
63,
973,
14,
500,
837,
566,
355,
876,
63,
3369,
275,
359,
77,
367,
333,
315,
359,
4468,
12,
8201,
12,
4819,
61,
340,
333,
365,
440,
488,
61,
355,
340,
876,
63,
3369,
26,
490,
291,
14,
657,
63,
3221,
275,
876,
63,
3369,
59,
16,
1055,
923,
342,
355,
587,
26,
490,
291,
14,
657,
63,
3221,
275,
2125,
953,
291,
14,
374,
63,
2374,
1023,
275,
2155,
8,
264,
14,
1733,
8,
82,
1370,
2374,
14382,
373,
875,
430,
398,
347,
485,
5785,
63,
1023,
8,
277,
12,
1163,
304,
288,
408,
16051,
12160,
14,
11067,
14,
1266,
970,
624,
288,
340,
291,
14,
8452,
508,
1163,
14,
8452,
26,
355,
340,
291,
14,
11067,
508,
1163,
14,
11067,
26,
490,
340,
291,
14,
1266,
970,
508,
1163,
14,
1266,
970,
26,
717,
809,
5730,
275,
378,
490,
916,
291,
14,
1266,
970,
690,
1163,
14,
1266,
970,
26,
717,
809,
5730,
275,
413,
490,
587,
26,
717,
809,
5730,
275,
446,
17,
355,
916,
291,
14,
11067,
690,
1163,
14,
11067,
26,
490,
809,
5730,
275,
413,
355,
587,
26,
490,
809,
5730,
275,
446,
17,
288,
916,
291,
14,
8452,
690,
1163,
14,
8452,
26,
355,
809,
5730,
275,
413,
288,
587,
26,
355,
809,
5730,
275,
446,
17,
953,
372,
809,
5730,
398,
347,
485,
5785,
63,
657,
63,
3221,
8,
277,
12,
1163,
304,
288,
408,
16051,
5131,
15,
5683,
15,
1195,
15,
5094,
1041,
288,
340,
291,
14,
657,
63,
3221,
508,
1163,
14,
657,
63,
3221,
26,
355,
809,
5730,
275,
378,
288,
916,
291,
14,
657,
63,
3221,
508,
283,
5094,
356,
355,
809,
5730,
275,
413,
288,
916,
1163,
14,
657,
63,
3221,
508,
283,
5094,
356,
355,
809,
5730,
275,
446,
17,
288,
916,
291,
14,
657,
63,
3221,
690,
1163,
14,
657,
63,
3221,
26,
355,
809,
5730,
275,
413,
288,
587,
26,
355,
809,
5730,
275,
446,
17,
953,
372,
809,
5730,
398,
347,
485,
5785,
8,
277,
12,
1163,
304,
288,
340,
440,
1228,
8,
1848,
12,
334,
875,
63,
1313,
12,
20535,
3353,
2298,
355,
746,
1722,
480,
3364,
909,
370,
6540,
543,
20535,
3353,
2685,
953,
340,
1228,
8,
1848,
12,
1059,
63,
1313,
304,
355,
1163,
275,
20535,
3353,
8,
1848,
9,
953,
809,
5730,
275,
291,
423,
5785
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
2680,
465,
980,
421,
199,
318,
485,
2075,
63,
1267,
63,
1479,
8,
88,
304,
272,
340,
671,
508,
378,
26,
267,
372,
378,
272,
916,
671,
508,
413,
26,
267,
372,
413,
272,
587,
26,
267,
372,
822,
8,
1393,
8,
88,
430,
446,
499,
421,
199,
893,
26,
272,
687,
7026,
14,
773,
423,
1023,
492,
20535,
3353,
199,
2590,
3545,
26,
272,
492,
295,
272,
687,
1275,
1548,
492,
1059,
63,
1313,
339,
1021,
20535,
3353,
837,
267,
408,
4003,
436,
6540,
2680,
1015,
3326,
14,
398,
20535,
965,
314,
2569,
1015,
316,
5687,
334,
10548,
1627,
787,
7251,
27,
2985,
267,
883,
506,
690,
25,
9,
315,
5448,
10352,
274,
304,
398,
446,
17646,
68,
1015,
26,
283,
17,
14,
24,
14,
16,
297,
283,
17,
14,
24,
14,
17,
297,
5423,
14,
267,
446,
32657,
26,
283,
17,
14,
24,
14,
16,
65,
17,
297,
283,
17,
14,
24,
14,
16,
65,
18,
297,
5423,
14,
267,
446,
29521,
26,
283,
17,
14,
24,
14,
16,
66,
17,
297,
283,
17,
14,
24,
14,
16,
66,
18,
297,
5423,
14,
267,
446,
17646,
15101,
26,
283,
17,
14,
24,
14,
16,
1195,
17,
297,
283,
17,
14,
24,
14,
16,
1195,
18,
297,
5423,
14,
267,
446,
15290,
5459,
26,
283,
17,
14,
24,
14,
16,
14,
2374,
13,
70,
4321,
65,
667,
7,
334,
3187,
5532,
2631,
11544,
9,
267,
446,
15290,
5459,
2410,
282,
17,
26,
283,
17,
14,
24,
14,
16,
65,
17,
14,
2374,
13,
70,
4321,
65,
667,
297,
3147,
283,
17,
14,
24,
14,
16,
66,
18,
14,
2374,
13,
70,
4321,
65,
667,
297,
3147,
283,
17,
14,
24,
14,
17,
1195,
17,
14,
2374,
13,
70,
4321,
65,
667,
297,
5423,
14,
267,
446,
15290,
5459,
334,
889,
6135,
2631,
2808,
304,
283,
17,
14,
24,
14,
16,
14,
2374,
13,
5912,
7,
398,
3599,
9332,
4839,
370,
506,
4224,
6169,
282,
1686,
1015,
1059,
503,
1163,
267,
658,
25218,
3353,
64,
1256,
14,
398,
3897,
267,
4143,
267,
373,
875,
520,
620,
288,
20535,
1015,
1059,
15693,
1590,
855,
1023,
18762,
680,
398,
8144,
267,
9063,
267,
2900,
4866,
5459,
402,
314,
2011,
334,
657,
13,
9,
3221,
6540,
4472,
14,
398,
6058,
267,
3001,
267,
1306,
687,
7026,
14,
773,
423,
1023,
492,
20535,
3353,
267,
1306,
340,
20535,
3353,
8,
1590,
855,
1023,
3368,
665,
283,
17,
14,
23,
14,
16,
356,
267,
2263,
258,
870,
360,
2759,
358,
267,
3372,
398,
1306,
20535,
3353,
360,
17,
14,
23,
358,
221,
327,
6534,
1722,
12,
1050,
3680,
16,
2,
398,
408,
398,
347,
636,
826,
721,
277,
12,
373,
875,
304,
288,
291,
14,
86,
875,
275,
373,
875,
288,
809,
63,
973,
275,
295,
14,
1431,
8,
82,
1154,
68,
30352,
7272,
68,
21324,
14,
7272,
68,
7386,
373,
875,
9,
288,
340,
440,
809,
63,
973,
26,
355,
746,
1722,
480,
1763,
282,
1686,
2680,
1015,
1059,
531,
953,
291,
14,
1023,
275,
809,
63,
973,
14,
923,
342,
288,
291,
14,
8452,
12,
291,
14,
11067,
12,
291,
14,
1266,
970,
275,
359,
442,
8,
88,
9,
367,
671,
315,
8962,
291,
14,
1023,
14,
1294,
7563,
61,
288,
340,
822,
8,
86,
875,
9,
508,
809,
63,
973,
14,
500,
837,
355,
291,
14,
657,
63,
3221,
275,
283,
5094,
7,
288,
587,
26,
355,
5131,
275,
295,
14,
1431,
8,
82,
7,
65,
60,
68,
297,
373,
875,
59,
422,
63,
973,
14,
500,
837,
566,
355,
8201,
275,
295,
14,
1431,
8,
82,
7,
66,
60,
68,
297,
373,
875,
59,
422,
63,
973,
14,
500,
837,
566,
355,
4819,
275,
295,
14,
1431,
8,
82,
7,
1195,
60,
68,
297,
373,
875,
59,
422,
63,
973,
14,
500,
837,
566,
355,
876,
63,
3369,
275,
359,
77,
367,
333,
315,
359,
4468,
12,
8201,
12,
4819,
61,
340,
333,
365,
440,
488,
61,
355,
340,
876,
63,
3369,
26,
490,
291,
14,
657,
63,
3221,
275,
876,
63,
3369,
59,
16,
1055,
923,
342,
355,
587,
26,
490,
291,
14,
657,
63,
3221,
275,
2125,
953,
291,
14,
374,
63,
2374,
1023,
275,
2155,
8,
264,
14,
1733,
8,
82,
1370,
2374,
14382,
373,
875,
430,
398,
347,
485,
5785,
63,
1023,
8,
277,
12,
1163,
304,
288,
408,
16051,
12160,
14,
11067,
14,
1266,
970,
624,
288,
340,
291,
14,
8452,
508,
1163,
14,
8452,
26,
355,
340,
291,
14,
11067,
508,
1163,
14,
11067,
26,
490,
340,
291,
14,
1266,
970,
508,
1163,
14,
1266,
970,
26,
717,
809,
5730,
275,
378,
490,
916,
291,
14,
1266,
970,
690,
1163,
14,
1266,
970,
26,
717,
809,
5730,
275,
413,
490,
587,
26,
717,
809,
5730,
275,
446,
17,
355,
916,
291,
14,
11067,
690,
1163,
14,
11067,
26,
490,
809,
5730,
275,
413,
355,
587,
26,
490,
809,
5730,
275,
446,
17,
288,
916,
291,
14,
8452,
690,
1163,
14,
8452,
26,
355,
809,
5730,
275,
413,
288,
587,
26,
355,
809,
5730,
275,
446,
17,
953,
372,
809,
5730,
398,
347,
485,
5785,
63,
657,
63,
3221,
8,
277,
12,
1163,
304,
288,
408,
16051,
5131,
15,
5683,
15,
1195,
15,
5094,
1041,
288,
340,
291,
14,
657,
63,
3221,
508,
1163,
14,
657,
63,
3221,
26,
355,
809,
5730,
275,
378,
288,
916,
291,
14,
657,
63,
3221,
508,
283,
5094,
356,
355,
809,
5730,
275,
413,
288,
916,
1163,
14,
657,
63,
3221,
508,
283,
5094,
356,
355,
809,
5730,
275,
446,
17,
288,
916,
291,
14,
657,
63,
3221,
690,
1163,
14,
657,
63,
3221,
26,
355,
809,
5730,
275,
413,
288,
587,
26,
355,
809,
5730,
275,
446,
17,
953,
372,
809,
5730,
398,
347,
485,
5785,
8,
277,
12,
1163,
304,
288,
340,
440,
1228,
8,
1848,
12,
334,
875,
63,
1313,
12,
20535,
3353,
2298,
355,
746,
1722,
480,
3364,
909,
370,
6540,
543,
20535,
3353,
2685,
953,
340,
1228,
8,
1848,
12,
1059,
63,
1313,
304,
355,
1163,
275,
20535,
3353,
8,
1848,
9,
953,
809,
5730,
275,
291,
423,
5785,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
FodT/t1-python
|
tests/test_deals.py
|
3
|
3119
|
from __future__ import absolute_import
import unittest
import responses
import requests
from .requests_patch import patched_extract_cookies_to_jar
from terminalone import T1
mock_credentials = {
'username': 'user',
'password': 'password',
'api_key': 'api_key',
}
API_BASE = 'api.mediamath.com'
requests.sessions.extract_cookies_to_jar = patched_extract_cookies_to_jar
requests.adapters.extract_cookies_to_jar = patched_extract_cookies_to_jar
class TestDeals(unittest.TestCase):
@responses.activate
def setUp(self):
"""set up test fixtures"""
with open('tests/fixtures/xml/session.xml') as f:
fixture = f.read()
responses.add(responses.POST, 'https://api.mediamath.com/api/v2.0/login',
body=fixture,
adding_headers={
'Set-Cookie': 'adama_session=1',
},
content_type='application/xml')
self.t1 = T1(auth_method='cookie',
api_base=API_BASE,
**mock_credentials)
@responses.activate
def test_collection(self):
with open('tests/fixtures/json/media_api_deal.json') as f:
fixture = f.read()
responses.add(responses.GET, 'https://api.mediamath.com/media/v1.0/deals/11111',
body=fixture,
content_type='application/json')
deal = self.t1.get('deals', 11111)
self.assertIsNone(deal.sub_supply_source_id)
@responses.activate
def test_generate_json(self):
with open('tests/fixtures/json/media_api_deal.json') as f:
fixture = f.read()
responses.add(responses.GET, 'https://api.mediamath.com/media/v1.0/deals/11111',
body=fixture,
content_type='application/json')
test_deal = self.t1.get('deals', 11111)
data = test_deal._validate_json_post(test_deal._init_properties)
self.assertEqual(data.get('start_datetime'), "2016-11-16T12:31:10+0000")
@responses.activate
def test_strategy_with_deals(self):
with open('tests/fixtures/json/strategy_with_deals.json') as f:
fixture = f.read()
responses.add(responses.GET, 'https://api.mediamath.com/api/v2.0/strategies/11111/deals',
body=fixture,
content_type='application/json')
strategy = self.t1.get('strategies', 11111, child='deals')
self.assertEqual(11111, strategy.deals[0].id)
self.assertEqual(22222, strategy.deals[1].id)
@responses.activate
def test_strategy_with_deals_xml(self):
with open('tests/fixtures/xml/strategy_with_deals.xml') as f:
fixture = f.read()
responses.add(responses.GET, 'https://api.mediamath.com/api/v2.0/strategies/11111/deals',
body=fixture,
content_type='application/xml')
strategy = self.t1.get('strategies', 11111, child='deals')
self.assertEqual(11111, strategy.deals[0].id)
self.assertEqual(22222, strategy.deals[1].id)
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
2882,
199,
646,
9320,
199,
646,
4145,
199,
504,
1275,
6615,
63,
2068,
492,
19483,
63,
5005,
63,
7792,
63,
475,
63,
7338,
199,
504,
5537,
10636,
492,
377,
17,
199,
199,
1805,
63,
6942,
275,
469,
272,
283,
2473,
356,
283,
751,
297,
272,
283,
2060,
356,
283,
2060,
297,
272,
283,
1246,
63,
498,
356,
283,
1246,
63,
498,
297,
199,
93,
199,
199,
3735,
63,
5825,
275,
283,
1246,
14,
4603,
3442,
14,
957,
7,
199,
199,
6615,
14,
11676,
14,
5005,
63,
7792,
63,
475,
63,
7338,
275,
19483,
63,
5005,
63,
7792,
63,
475,
63,
7338,
199,
6615,
14,
21680,
14,
5005,
63,
7792,
63,
475,
63,
7338,
275,
19483,
63,
5005,
63,
7792,
63,
475,
63,
7338,
421,
199,
533,
1379,
872,
2551,
8,
2796,
14,
1746,
304,
272,
768,
10360,
14,
8222,
272,
347,
3613,
8,
277,
304,
267,
408,
409,
1536,
511,
15188,
624,
267,
543,
1551,
360,
2219,
15,
8769,
15,
1652,
15,
1730,
14,
1652,
358,
465,
289,
26,
288,
10949,
275,
289,
14,
739,
342,
267,
9320,
14,
525,
8,
10360,
14,
4030,
12,
283,
2859,
921,
1246,
14,
4603,
3442,
14,
957,
15,
1246,
15,
86,
18,
14,
16,
15,
2886,
297,
1993,
2396,
29,
5997,
12,
1993,
7791,
63,
2139,
3126,
2079,
283,
1084,
13,
7810,
356,
283,
10641,
391,
63,
1730,
29,
17,
297,
1993,
1660,
1993,
1564,
63,
466,
534,
3578,
15,
1652,
358,
398,
291,
14,
84,
17,
275,
377,
17,
8,
1178,
63,
765,
534,
5306,
297,
2151,
2986,
63,
1095,
29,
3735,
63,
5825,
12,
2151,
1011,
1805,
63,
6942,
9,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
3627,
8,
277,
304,
267,
543,
1551,
360,
2219,
15,
8769,
15,
1001,
15,
4603,
63,
1246,
63,
21245,
14,
1001,
358,
465,
289,
26,
288,
10949,
275,
289,
14,
739,
342,
267,
9320,
14,
525,
8,
10360,
14,
2970,
12,
283,
2859,
921,
1246,
14,
4603,
3442,
14,
957,
15,
4603,
15,
86,
17,
14,
16,
15,
271,
2551,
15,
845,
6673,
297,
1993,
2396,
29,
5997,
12,
1993,
1564,
63,
466,
534,
3578,
15,
1001,
358,
267,
7962,
275,
291,
14,
84,
17,
14,
362,
360,
271,
2551,
297,
413,
6984,
9,
267,
291,
14,
7702,
8,
21245,
14,
954,
63,
8621,
590,
63,
1365,
63,
344,
9,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
4208,
63,
1001,
8,
277,
304,
398,
543,
1551,
360,
2219,
15,
8769,
15,
1001,
15,
4603,
63,
1246,
63,
21245,
14,
1001,
358,
465,
289,
26,
288,
10949,
275,
289,
14,
739,
342,
267,
9320,
14,
525,
8,
10360,
14,
2970,
12,
283,
2859,
921,
1246,
14,
4603,
3442,
14,
957,
15,
4603,
15,
86,
17,
14,
16,
15,
271,
2551,
15,
845,
6673,
297,
1993,
2396,
29,
5997,
12,
1993,
1564,
63,
466,
534,
3578,
15,
1001,
358,
267,
511,
63,
21245,
275,
291,
14,
84,
17,
14,
362,
360,
271,
2551,
297,
413,
6984,
9,
267,
666,
275,
511,
63,
21245,
423,
3502,
63,
1001,
63,
1932,
8,
396,
63,
21245,
423,
826,
63,
3282,
9,
267,
291,
14,
629,
8,
576,
14,
362,
360,
928,
63,
2083,
659,
298,
9261,
13,
845,
13,
975,
52,
713,
26,
2192,
26,
709,
11,
993,
531,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
8590,
63,
1045,
63,
271,
2551,
8,
277,
304,
267,
543,
1551,
360,
2219,
15,
8769,
15,
1001,
15,
8590,
63,
1045,
63,
271,
2551,
14,
1001,
358,
465,
289,
26,
288,
10949,
275,
289,
14,
739,
342,
267,
9320,
14,
525,
8,
10360,
14,
2970,
12,
283,
2859,
921,
1246,
14,
4603,
3442,
14,
957,
15,
1246,
15,
86,
18,
14,
16,
15,
20694,
1500,
15,
845,
6673,
15,
271,
2551,
297,
1993,
2396,
29,
5997,
12,
1993,
1564,
63,
466,
534,
3578,
15,
1001,
358,
267,
10054,
275,
291,
14,
84,
17,
14,
362,
360,
20694,
1500,
297,
413,
6984,
12,
1982,
534,
271,
2551,
358,
267,
291,
14,
629,
8,
845,
6673,
12,
10054,
14,
271,
2551,
59,
16,
1055,
344,
9,
267,
291,
14,
629,
8,
1081,
9485,
12,
10054,
14,
271,
2551,
59,
17,
1055,
344,
9,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
8590,
63,
1045,
63,
271,
2551,
63,
1652,
8,
277,
304,
267,
543,
1551,
360,
2219,
15,
8769,
15,
1652,
15,
8590,
63,
1045,
63,
271,
2551,
14,
1652,
358,
465,
289,
26,
288,
10949,
275,
289,
14,
739,
342,
267,
9320,
14,
525,
8,
10360,
14,
2970,
12,
283,
2859,
921,
1246,
14,
4603,
3442,
14,
957,
15,
1246,
15,
86,
18,
14,
16,
15,
20694,
1500,
15,
845,
6673,
15,
271,
2551,
297,
1993,
2396,
29,
5997,
12,
1993,
1564,
63,
466,
534,
3578,
15,
1652,
358,
267,
10054,
275,
291,
14,
84,
17,
14,
362,
360,
20694,
1500,
297,
413,
6984,
12,
1982,
534,
271,
2551,
358,
267,
291,
14,
629,
8,
845,
6673,
12,
10054,
14,
271,
2551,
59,
16,
1055,
344,
9,
267,
291,
14,
629,
8,
1081,
9485,
12,
10054,
14,
271,
2551,
59,
17,
1055,
344,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
646,
2882,
199,
646,
9320,
199,
646,
4145,
199,
504,
1275,
6615,
63,
2068,
492,
19483,
63,
5005,
63,
7792,
63,
475,
63,
7338,
199,
504,
5537,
10636,
492,
377,
17,
199,
199,
1805,
63,
6942,
275,
469,
272,
283,
2473,
356,
283,
751,
297,
272,
283,
2060,
356,
283,
2060,
297,
272,
283,
1246,
63,
498,
356,
283,
1246,
63,
498,
297,
199,
93,
199,
199,
3735,
63,
5825,
275,
283,
1246,
14,
4603,
3442,
14,
957,
7,
199,
199,
6615,
14,
11676,
14,
5005,
63,
7792,
63,
475,
63,
7338,
275,
19483,
63,
5005,
63,
7792,
63,
475,
63,
7338,
199,
6615,
14,
21680,
14,
5005,
63,
7792,
63,
475,
63,
7338,
275,
19483,
63,
5005,
63,
7792,
63,
475,
63,
7338,
421,
199,
533,
1379,
872,
2551,
8,
2796,
14,
1746,
304,
272,
768,
10360,
14,
8222,
272,
347,
3613,
8,
277,
304,
267,
408,
409,
1536,
511,
15188,
624,
267,
543,
1551,
360,
2219,
15,
8769,
15,
1652,
15,
1730,
14,
1652,
358,
465,
289,
26,
288,
10949,
275,
289,
14,
739,
342,
267,
9320,
14,
525,
8,
10360,
14,
4030,
12,
283,
2859,
921,
1246,
14,
4603,
3442,
14,
957,
15,
1246,
15,
86,
18,
14,
16,
15,
2886,
297,
1993,
2396,
29,
5997,
12,
1993,
7791,
63,
2139,
3126,
2079,
283,
1084,
13,
7810,
356,
283,
10641,
391,
63,
1730,
29,
17,
297,
1993,
1660,
1993,
1564,
63,
466,
534,
3578,
15,
1652,
358,
398,
291,
14,
84,
17,
275,
377,
17,
8,
1178,
63,
765,
534,
5306,
297,
2151,
2986,
63,
1095,
29,
3735,
63,
5825,
12,
2151,
1011,
1805,
63,
6942,
9,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
3627,
8,
277,
304,
267,
543,
1551,
360,
2219,
15,
8769,
15,
1001,
15,
4603,
63,
1246,
63,
21245,
14,
1001,
358,
465,
289,
26,
288,
10949,
275,
289,
14,
739,
342,
267,
9320,
14,
525,
8,
10360,
14,
2970,
12,
283,
2859,
921,
1246,
14,
4603,
3442,
14,
957,
15,
4603,
15,
86,
17,
14,
16,
15,
271,
2551,
15,
845,
6673,
297,
1993,
2396,
29,
5997,
12,
1993,
1564,
63,
466,
534,
3578,
15,
1001,
358,
267,
7962,
275,
291,
14,
84,
17,
14,
362,
360,
271,
2551,
297,
413,
6984,
9,
267,
291,
14,
7702,
8,
21245,
14,
954,
63,
8621,
590,
63,
1365,
63,
344,
9,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
4208,
63,
1001,
8,
277,
304,
398,
543,
1551,
360,
2219,
15,
8769,
15,
1001,
15,
4603,
63,
1246,
63,
21245,
14,
1001,
358,
465,
289,
26,
288,
10949,
275,
289,
14,
739,
342,
267,
9320,
14,
525,
8,
10360,
14,
2970,
12,
283,
2859,
921,
1246,
14,
4603,
3442,
14,
957,
15,
4603,
15,
86,
17,
14,
16,
15,
271,
2551,
15,
845,
6673,
297,
1993,
2396,
29,
5997,
12,
1993,
1564,
63,
466,
534,
3578,
15,
1001,
358,
267,
511,
63,
21245,
275,
291,
14,
84,
17,
14,
362,
360,
271,
2551,
297,
413,
6984,
9,
267,
666,
275,
511,
63,
21245,
423,
3502,
63,
1001,
63,
1932,
8,
396,
63,
21245,
423,
826,
63,
3282,
9,
267,
291,
14,
629,
8,
576,
14,
362,
360,
928,
63,
2083,
659,
298,
9261,
13,
845,
13,
975,
52,
713,
26,
2192,
26,
709,
11,
993,
531,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
8590,
63,
1045,
63,
271,
2551,
8,
277,
304,
267,
543,
1551,
360,
2219,
15,
8769,
15,
1001,
15,
8590,
63,
1045,
63,
271,
2551,
14,
1001,
358,
465,
289,
26,
288,
10949,
275,
289,
14,
739,
342,
267,
9320,
14,
525,
8,
10360,
14,
2970,
12,
283,
2859,
921,
1246,
14,
4603,
3442,
14,
957,
15,
1246,
15,
86,
18,
14,
16,
15,
20694,
1500,
15,
845,
6673,
15,
271,
2551,
297,
1993,
2396,
29,
5997,
12,
1993,
1564,
63,
466,
534,
3578,
15,
1001,
358,
267,
10054,
275,
291,
14,
84,
17,
14,
362,
360,
20694,
1500,
297,
413,
6984,
12,
1982,
534,
271,
2551,
358,
267,
291,
14,
629,
8,
845,
6673,
12,
10054,
14,
271,
2551,
59,
16,
1055,
344,
9,
267,
291,
14,
629,
8,
1081,
9485,
12,
10054,
14,
271,
2551,
59,
17,
1055,
344,
9,
339,
768,
10360,
14,
8222,
272,
347,
511,
63,
8590,
63,
1045,
63,
271,
2551,
63,
1652,
8,
277,
304,
267,
543,
1551,
360,
2219,
15,
8769,
15,
1652,
15,
8590,
63,
1045,
63,
271,
2551,
14,
1652,
358,
465,
289,
26,
288,
10949,
275,
289,
14,
739,
342,
267,
9320,
14,
525,
8,
10360,
14,
2970,
12,
283,
2859,
921,
1246,
14,
4603,
3442,
14,
957,
15,
1246,
15,
86,
18,
14,
16,
15,
20694,
1500,
15,
845,
6673,
15,
271,
2551,
297,
1993,
2396,
29,
5997,
12,
1993,
1564,
63,
466,
534,
3578,
15,
1652,
358,
267,
10054,
275,
291,
14,
84,
17,
14,
362,
360,
20694,
1500,
297,
413,
6984,
12,
1982,
534,
271,
2551,
358,
267,
291,
14,
629,
8,
845,
6673,
12,
10054,
14,
271,
2551,
59,
16,
1055,
344,
9,
267,
291,
14,
629,
8,
1081,
9485,
12,
10054,
14,
271,
2551,
59,
17,
1055,
344,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
Immortalin/python-for-android
|
python3-alpha/extra_modules/pyxmpp2/streamtls.py
|
46
|
11438
|
#
# (C) Copyright 2003-2011 Jacek Konieczny <jajcus@jajcus.net>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License Version
# 2.1 as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#
# pylint: disable-msg=W0201
"""TLS support for XMPP streams.
Normative reference:
- `RFC 6120 <http://xmpp.org/rfcs/rfc6120.html>`__
"""
__docformat__ = "restructuredtext en"
import logging
import ssl
from ssl import SSLError
from .etree import ElementTree
from .constants import TLS_QNP
from .streambase import FatalStreamError
from .exceptions import TLSNegotiationFailed
from .exceptions import JIDError
from .jid import JID
from .settings import XMPPSettings
from .streamevents import TLSConnectedEvent
from .interfaces import StreamFeatureHandler
from .interfaces import StreamFeatureHandled, StreamFeatureNotHandled
from .interfaces import stream_element_handler
from .interfaces import EventHandler, event_handler
STARTTLS_TAG = TLS_QNP + "starttls"
REQUIRED_TAG = TLS_QNP + "required"
PROCEED_TAG = TLS_QNP + "proceed"
FAILURE_TAG = TLS_QNP + "failure"
logger = logging.getLogger("pyxmpp2.streamtls")
class StreamTLSHandler(StreamFeatureHandler, EventHandler):
"""Handler for stream TLS support.
"""
def __init__(self, settings = None):
"""Initialize the TLS handler.
:Parameters:
- `settings`: settings for StartTLS.
:Types:
- `settings`: `XMPPSettings`
"""
if settings is None:
self.settings = XMPPSettings()
else:
self.settings = settings
self.stream = None
self.requested = False
self.tls_socket = None
def make_stream_tls_features(self, stream, features):
"""Update the <features/> element with StartTLS feature.
[receving entity only]
:Parameters:
- `features`: the <features/> element of the stream.
:Types:
- `features`: :etree:`ElementTree.Element`
:returns: update <features/> element.
:returntype: :etree:`ElementTree.Element`
"""
if self.stream and stream is not self.stream:
raise ValueError("Single StreamTLSHandler instance can handle"
" only one stream")
self.stream = stream
if self.settings["starttls"] and not stream.tls_established:
tls = ElementTree.SubElement(features, STARTTLS_TAG)
if self.settings["tls_require"]:
ElementTree.SubElement(tls, REQUIRED_TAG)
return features
def handle_stream_features(self, stream, features):
"""Process incoming StartTLS related element of <stream:features/>.
[initiating entity only]
"""
if self.stream and stream is not self.stream:
raise ValueError("Single StreamTLSHandler instance can handle"
" only one stream")
self.stream = stream
logger.debug(" tls: handling features")
element = features.find(STARTTLS_TAG)
if element is None:
logger.debug(" tls: no starttls feature found")
if self.settings["tls_require"]:
raise TLSNegotiationFailed("StartTLS required,"
" but not supported by peer")
return None
if len(features) == 1:
required = True
else:
required = element.find(REQUIRED_TAG) is not None
if stream.tls_established:
logger.warning("StartTLS offerred when already established")
return StreamFeatureNotHandled("StartTLS", mandatory = required)
if self.settings["starttls"]:
logger.debug("StartTLS negotiated")
self._request_tls()
return StreamFeatureHandled("StartTLS", mandatory = required)
else:
logger.debug(" tls: not enabled")
return StreamFeatureNotHandled("StartTLS", mandatory = required)
def _request_tls(self):
"""Request a TLS-encrypted connection.
[initiating entity only]"""
self.requested = True
element = ElementTree.Element(STARTTLS_TAG)
self.stream.write_element(element)
@stream_element_handler(FAILURE_TAG, "initiator")
def _process_tls_failure(self, stream, element):
"""Handle the <failure /> element.
"""
# pylint: disable-msg=R0201
_unused, _unused = stream, element
raise TLSNegotiationFailed("Peer failed to initialize TLS connection")
@stream_element_handler(PROCEED_TAG, "initiator")
def _process_tls_proceed(self, stream, element):
"""Handle the <proceed /> element.
"""
# pylint: disable-msg=W0613
if not self.requested:
logger.debug("Unexpected TLS element: {0!r}".format(element))
return False
logger.debug(" tls: <proceed/> received")
self.requested = False
self._make_tls_connection()
return True
@stream_element_handler(STARTTLS_TAG, "receiver")
def _process_tls_starttls(self, stream, element):
"""Handle <starttls/> element.
"""
# pylint: disable-msg=R0201
_unused, _unused = stream, element
raise FatalStreamError("TLS not implemented for the receiving side yet")
def _make_tls_connection(self):
"""Initiate TLS connection.
[initiating entity only]
"""
logger.debug("Preparing TLS connection")
if self.settings["tls_verify_peer"]:
cert_reqs = ssl.CERT_REQUIRED
else:
cert_reqs = ssl.CERT_NONE
self.stream.transport.starttls(
keyfile = self.settings["tls_key_file"],
certfile = self.settings["tls_cert_file"],
server_side = not self.stream.initiator,
cert_reqs = cert_reqs,
ssl_version = ssl.PROTOCOL_TLSv1,
ca_certs = self.settings["tls_cacert_file"],
do_handshake_on_connect = False,
)
@event_handler(TLSConnectedEvent)
def handle_tls_connected_event(self, event):
"""Verify the peer certificate on the `TLSConnectedEvent`.
"""
if self.settings["tls_verify_peer"]:
valid = self.settings["tls_verify_callback"](event.stream,
event.peer_certificate)
if not valid:
raise SSLError("Certificate verification failed")
event.stream.tls_established = True
with event.stream.lock:
event.stream._restart_stream() # pylint: disable-msg=W0212
@staticmethod
def is_certificate_valid(stream, cert):
"""Default certificate verification callback for TLS connections.
:Parameters:
- `cert`: certificate information, as returned by
:std:`ssl.SSLSocket.getpeercert`
:return: computed verification result."""
try:
logger.debug("tls_is_certificate_valid(cert = {0!r})".format(cert))
if not cert:
logger.warning("No TLS certificate information received.")
return False
valid_hostname_found = False
logger.debug(" tls: checking peer name in the certificate"
" should be: {0}".format(stream.peer))
if 'subject' in cert:
for rdns in cert['subject']:
for key, value in rdns:
if key != 'commonName':
continue
try:
value = JID(value)
except JIDError:
continue
if value == stream.peer:
logger.debug(" good commonName: {0}".format(value))
valid_hostname_found = True
else:
logger.debug(" {0} != {1}".format(value,
stream.peer))
if 'subjectAltName' in cert:
for key, value in cert['subjectAltName']:
if key != 'DNS':
continue
try:
value = JID(value)
except JIDError:
continue
if value == stream.peer:
logger.debug(" good subjectAltName({0}): {1}"
.format(key, value))
valid_hostname_found = True
else:
logger.debug(" {0} != {1}".format(value, stream.peer))
return valid_hostname_found
except:
logger.exception("Exception caught while checking a certificate")
raise
XMPPSettings.add_setting("starttls", type = bool, default = False,
basic = True,
cmdline_help = "Enable StartTLS negotiation",
doc = """Enable StartTLS negotiation."""
)
XMPPSettings.add_setting("tls_require", type = bool, default = False,
basic = True,
cmdline_help = "Require TLS stream encryption",
doc = """Require TLS stream encryption."""
)
XMPPSettings.add_setting("tls_verify_peer", type = bool, default = True,
basic = True,
cmdline_help = "Verify the peer certificate",
doc = """Verify the peer certificate."""
)
XMPPSettings.add_setting("tls_cert_file", type = str,
cmdline_help = "TLS certificate file",
doc = """Path to the TLS certificate file. The file should contain
the certificate, any immediate certificates needed and it may optionally
contain the private key. All in the PEM format, concatenated."""
)
XMPPSettings.add_setting("tls_key_file", type = str,
cmdline_help = "TLS certificate private key file",
doc = """Path to the TLS certificate private key file (in the PEM
format). Not needed if the key is included in the file pointed by the
:r:`tls_cert_file setting`."""
)
XMPPSettings.add_setting("tls_cacert_file", type = str, basic = True,
cmdline_help = "TLS CA certificates file",
doc = """Path to the TLS CA certificates file. The file should contain
the trusted CA certificates in the PEM format, concatenated."""
)
XMPPSettings.add_setting("tls_verify_callback", type = "callable",
default = StreamTLSHandler.is_certificate_valid,
doc = """A function to verify if a certificate is valid and if the
remote party presenting this certificate is authorized to use the stream.
The function must accept two arguments: a stream and the certificate
to verify."""
)
# vi: sts=4 et sw=4
|
apache-2.0
|
[
3,
199,
3,
334,
35,
9,
1898,
13004,
13,
8128,
1603,
7984,
75,
1804,
265,
73,
825,
90,
9745,
665,
3387,
22760,
527,
32,
3387,
22760,
527,
14,
846,
30,
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,
6401,
1696,
1684,
844,
3394,
199,
3,
499,
14,
17,
465,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
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,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
1227,
2194,
603,
405,
437,
432,
12,
445,
455,
9528,
12,
4828,
12497,
7491,
12,
8217,
14,
199,
3,
199,
3,
4287,
26,
3507,
13,
1328,
29,
55,
996,
614,
199,
199,
624,
10224,
2291,
367,
1323,
1658,
48,
13788,
14,
199,
199,
23008,
391,
857,
3659,
26,
523,
446,
658,
14468,
1227,
6708,
665,
1014,
921,
26608,
14,
1308,
15,
3941,
1259,
15,
8973,
22,
6708,
14,
1360,
8637,
363,
199,
624,
4388,
199,
363,
21841,
363,
275,
298,
26854,
655,
2,
199,
199,
646,
2050,
199,
646,
6149,
199,
199,
504,
6149,
492,
7799,
547,
199,
199,
504,
1275,
9464,
492,
13139,
199,
504,
1275,
5559,
492,
12213,
63,
49,
14970,
199,
504,
1275,
1745,
1095,
492,
481,
7539,
3296,
547,
199,
504,
1275,
3924,
492,
12213,
4698,
14727,
425,
4276,
199,
504,
1275,
3924,
492,
1603,
998,
547,
199,
504,
1275,
14203,
492,
1603,
998,
199,
504,
1275,
1751,
492,
1323,
1658,
48,
5268,
199,
504,
1275,
270,
19308,
782,
83,
492,
12213,
16382,
2390,
199,
199,
504,
1275,
7436,
492,
8271,
5968,
2461,
199,
504,
1275,
7436,
492,
8271,
5968,
5940,
68,
12,
8271,
5968,
1763,
5940,
68,
199,
504,
1275,
7436,
492,
2547,
63,
2108,
63,
2232,
199,
504,
1275,
7436,
492,
6763,
2461,
12,
1566,
63,
2232,
199,
199,
30302,
1481,
5296,
63,
6967,
275,
12213,
63,
49,
14970,
435,
298,
928,
9945,
2,
199,
12496,
63,
6967,
275,
12213,
63,
49,
14970,
435,
298,
2427,
2,
199,
2514,
2089,
1149,
63,
6967,
275,
12213,
63,
49,
14970,
435,
298,
496,
15648,
2,
199,
13989,
63,
6967,
275,
12213,
63,
49,
14970,
435,
298,
5328,
2,
268,
199,
2921,
275,
2050,
14,
5572,
480,
25579,
17901,
18,
14,
1745,
9945,
531,
199,
199,
533,
8271,
10224,
2461,
8,
3296,
5968,
2461,
12,
6763,
2461,
304,
272,
408,
2461,
367,
2547,
12213,
2291,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2202,
275,
488,
304,
267,
408,
9345,
314,
12213,
3016,
14,
398,
520,
5976,
26,
881,
446,
658,
1751,
8340,
2202,
367,
7707,
10224,
14,
267,
520,
4100,
26,
881,
446,
658,
1751,
8340,
658,
56,
1658,
48,
5268,
64,
267,
408,
267,
340,
2202,
365,
488,
26,
288,
291,
14,
1751,
275,
1323,
1658,
48,
5268,
342,
267,
587,
26,
288,
291,
14,
1751,
275,
2202,
267,
291,
14,
1745,
275,
488,
267,
291,
14,
11151,
275,
756,
267,
291,
14,
9945,
63,
3450,
275,
488,
339,
347,
1852,
63,
1745,
63,
9945,
63,
3179,
8,
277,
12,
2547,
12,
4534,
304,
267,
408,
4152,
314,
665,
3179,
3133,
1819,
543,
7707,
10224,
3878,
14,
398,
359,
264,
301,
4007,
4642,
1454,
61,
398,
520,
5976,
26,
288,
446,
658,
3179,
8340,
314,
665,
3179,
3133,
1819,
402,
314,
2547,
14,
267,
520,
4100,
26,
288,
446,
658,
3179,
8340,
520,
9464,
1705,
15325,
14,
2162,
64,
398,
520,
5808,
26,
1678,
665,
3179,
3133,
1819,
14,
267,
520,
3292,
300,
25116,
26,
520,
9464,
1705,
15325,
14,
2162,
64,
267,
408,
267,
340,
291,
14,
1745,
436,
2547,
365,
440,
291,
14,
1745,
26,
288,
746,
1722,
480,
7200,
8271,
10224,
2461,
1256,
883,
2429,
2,
14663,
298,
1454,
1373,
2547,
531,
267,
291,
14,
1745,
275,
2547,
267,
340,
291,
14,
1751,
905,
928,
9945,
937,
436,
440,
2547,
14,
9945,
63,
597,
13306,
379,
26,
288,
15142,
275,
13139,
14,
10571,
8,
3179,
12,
4384,
689,
1481,
5296,
63,
6967,
9,
288,
340,
291,
14,
1751,
905,
9945,
63,
4365,
6229,
355,
13139,
14,
10571,
8,
9945,
12,
25090,
63,
6967,
9,
267,
372,
4534,
339,
347,
2429,
63,
1745,
63,
3179,
8,
277,
12,
2547,
12,
4534,
304,
267,
408,
3498,
12467,
7707,
10224,
4048,
1819,
402,
665,
1745,
26,
3179,
4743,
398,
359,
14188,
1958,
4642,
1454,
61,
398,
408,
267,
340,
291,
14,
1745,
436,
2547,
365,
440,
291,
14,
1745,
26,
288,
746,
1722,
480,
7200,
8271,
10224,
2461,
1256,
883,
2429,
2,
14663,
298,
1454,
1373,
2547,
531,
267,
291,
14,
1745,
275,
2547,
267,
2512,
14,
1757,
480,
15142,
26,
7252,
4534,
531,
267,
1819,
275,
4534,
14,
1623,
8,
30302,
1481,
5296,
63,
6967,
9,
267,
340,
1819,
365,
488,
26,
288,
2512,
14,
1757,
480,
15142,
26,
949,
1343,
9945,
3878,
1911,
531,
288,
340,
291,
14,
1751,
905,
9945,
63,
4365,
6229,
355,
746,
12213,
4698,
14727,
425,
4276,
480,
3162,
10224,
1415,
4589,
6059,
298,
1325,
440,
3748,
701,
9104,
531,
288,
372,
488,
267,
340,
822,
8,
3179,
9,
508,
413,
26,
288,
1415,
275,
715,
267,
587,
26,
288,
1415,
275,
1819,
14,
1623,
8,
12496,
63,
6967,
9,
365,
440,
488,
267,
340,
2547,
14,
9945,
63,
597,
13306,
379,
26,
288,
2512,
14,
3764,
480,
3162,
10224,
2331,
7165,
1380,
2575,
23594,
531,
288,
372,
8271,
5968,
1763,
5940,
68,
480,
3162,
10224,
401,
15230,
275,
1415,
9,
10631,
340,
291,
14,
1751,
905,
928,
9945,
6229,
288,
2512,
14,
1757,
480,
3162,
10224,
29184,
972,
531,
288,
291,
423,
1069,
63,
9945,
342,
288,
372,
8271,
5968,
5940,
68,
480,
3162,
10224,
401,
15230,
275,
1415,
9,
267,
587,
26
] |
[
199,
3,
334,
35,
9,
1898,
13004,
13,
8128,
1603,
7984,
75,
1804,
265,
73,
825,
90,
9745,
665,
3387,
22760,
527,
32,
3387,
22760,
527,
14,
846,
30,
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,
6401,
1696,
1684,
844,
3394,
199,
3,
499,
14,
17,
465,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
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,
199,
3,
844,
3180,
543,
642,
2240,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
1227,
2194,
603,
405,
437,
432,
12,
445,
455,
9528,
12,
4828,
12497,
7491,
12,
8217,
14,
199,
3,
199,
3,
4287,
26,
3507,
13,
1328,
29,
55,
996,
614,
199,
199,
624,
10224,
2291,
367,
1323,
1658,
48,
13788,
14,
199,
199,
23008,
391,
857,
3659,
26,
523,
446,
658,
14468,
1227,
6708,
665,
1014,
921,
26608,
14,
1308,
15,
3941,
1259,
15,
8973,
22,
6708,
14,
1360,
8637,
363,
199,
624,
4388,
199,
363,
21841,
363,
275,
298,
26854,
655,
2,
199,
199,
646,
2050,
199,
646,
6149,
199,
199,
504,
6149,
492,
7799,
547,
199,
199,
504,
1275,
9464,
492,
13139,
199,
504,
1275,
5559,
492,
12213,
63,
49,
14970,
199,
504,
1275,
1745,
1095,
492,
481,
7539,
3296,
547,
199,
504,
1275,
3924,
492,
12213,
4698,
14727,
425,
4276,
199,
504,
1275,
3924,
492,
1603,
998,
547,
199,
504,
1275,
14203,
492,
1603,
998,
199,
504,
1275,
1751,
492,
1323,
1658,
48,
5268,
199,
504,
1275,
270,
19308,
782,
83,
492,
12213,
16382,
2390,
199,
199,
504,
1275,
7436,
492,
8271,
5968,
2461,
199,
504,
1275,
7436,
492,
8271,
5968,
5940,
68,
12,
8271,
5968,
1763,
5940,
68,
199,
504,
1275,
7436,
492,
2547,
63,
2108,
63,
2232,
199,
504,
1275,
7436,
492,
6763,
2461,
12,
1566,
63,
2232,
199,
199,
30302,
1481,
5296,
63,
6967,
275,
12213,
63,
49,
14970,
435,
298,
928,
9945,
2,
199,
12496,
63,
6967,
275,
12213,
63,
49,
14970,
435,
298,
2427,
2,
199,
2514,
2089,
1149,
63,
6967,
275,
12213,
63,
49,
14970,
435,
298,
496,
15648,
2,
199,
13989,
63,
6967,
275,
12213,
63,
49,
14970,
435,
298,
5328,
2,
268,
199,
2921,
275,
2050,
14,
5572,
480,
25579,
17901,
18,
14,
1745,
9945,
531,
199,
199,
533,
8271,
10224,
2461,
8,
3296,
5968,
2461,
12,
6763,
2461,
304,
272,
408,
2461,
367,
2547,
12213,
2291,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2202,
275,
488,
304,
267,
408,
9345,
314,
12213,
3016,
14,
398,
520,
5976,
26,
881,
446,
658,
1751,
8340,
2202,
367,
7707,
10224,
14,
267,
520,
4100,
26,
881,
446,
658,
1751,
8340,
658,
56,
1658,
48,
5268,
64,
267,
408,
267,
340,
2202,
365,
488,
26,
288,
291,
14,
1751,
275,
1323,
1658,
48,
5268,
342,
267,
587,
26,
288,
291,
14,
1751,
275,
2202,
267,
291,
14,
1745,
275,
488,
267,
291,
14,
11151,
275,
756,
267,
291,
14,
9945,
63,
3450,
275,
488,
339,
347,
1852,
63,
1745,
63,
9945,
63,
3179,
8,
277,
12,
2547,
12,
4534,
304,
267,
408,
4152,
314,
665,
3179,
3133,
1819,
543,
7707,
10224,
3878,
14,
398,
359,
264,
301,
4007,
4642,
1454,
61,
398,
520,
5976,
26,
288,
446,
658,
3179,
8340,
314,
665,
3179,
3133,
1819,
402,
314,
2547,
14,
267,
520,
4100,
26,
288,
446,
658,
3179,
8340,
520,
9464,
1705,
15325,
14,
2162,
64,
398,
520,
5808,
26,
1678,
665,
3179,
3133,
1819,
14,
267,
520,
3292,
300,
25116,
26,
520,
9464,
1705,
15325,
14,
2162,
64,
267,
408,
267,
340,
291,
14,
1745,
436,
2547,
365,
440,
291,
14,
1745,
26,
288,
746,
1722,
480,
7200,
8271,
10224,
2461,
1256,
883,
2429,
2,
14663,
298,
1454,
1373,
2547,
531,
267,
291,
14,
1745,
275,
2547,
267,
340,
291,
14,
1751,
905,
928,
9945,
937,
436,
440,
2547,
14,
9945,
63,
597,
13306,
379,
26,
288,
15142,
275,
13139,
14,
10571,
8,
3179,
12,
4384,
689,
1481,
5296,
63,
6967,
9,
288,
340,
291,
14,
1751,
905,
9945,
63,
4365,
6229,
355,
13139,
14,
10571,
8,
9945,
12,
25090,
63,
6967,
9,
267,
372,
4534,
339,
347,
2429,
63,
1745,
63,
3179,
8,
277,
12,
2547,
12,
4534,
304,
267,
408,
3498,
12467,
7707,
10224,
4048,
1819,
402,
665,
1745,
26,
3179,
4743,
398,
359,
14188,
1958,
4642,
1454,
61,
398,
408,
267,
340,
291,
14,
1745,
436,
2547,
365,
440,
291,
14,
1745,
26,
288,
746,
1722,
480,
7200,
8271,
10224,
2461,
1256,
883,
2429,
2,
14663,
298,
1454,
1373,
2547,
531,
267,
291,
14,
1745,
275,
2547,
267,
2512,
14,
1757,
480,
15142,
26,
7252,
4534,
531,
267,
1819,
275,
4534,
14,
1623,
8,
30302,
1481,
5296,
63,
6967,
9,
267,
340,
1819,
365,
488,
26,
288,
2512,
14,
1757,
480,
15142,
26,
949,
1343,
9945,
3878,
1911,
531,
288,
340,
291,
14,
1751,
905,
9945,
63,
4365,
6229,
355,
746,
12213,
4698,
14727,
425,
4276,
480,
3162,
10224,
1415,
4589,
6059,
298,
1325,
440,
3748,
701,
9104,
531,
288,
372,
488,
267,
340,
822,
8,
3179,
9,
508,
413,
26,
288,
1415,
275,
715,
267,
587,
26,
288,
1415,
275,
1819,
14,
1623,
8,
12496,
63,
6967,
9,
365,
440,
488,
267,
340,
2547,
14,
9945,
63,
597,
13306,
379,
26,
288,
2512,
14,
3764,
480,
3162,
10224,
2331,
7165,
1380,
2575,
23594,
531,
288,
372,
8271,
5968,
1763,
5940,
68,
480,
3162,
10224,
401,
15230,
275,
1415,
9,
10631,
340,
291,
14,
1751,
905,
928,
9945,
6229,
288,
2512,
14,
1757,
480,
3162,
10224,
29184,
972,
531,
288,
291,
423,
1069,
63,
9945,
342,
288,
372,
8271,
5968,
5940,
68,
480,
3162,
10224,
401,
15230,
275,
1415,
9,
267,
587,
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,
1,
1,
1,
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
] |
AppVentus/AvTime-client
|
packages/wakatime/wakatime/packages/pygments2/pygments/lexers/_phpbuiltins.py
|
274
|
122046
|
# -*- coding: utf-8 -*-
"""
pygments.lexers._phpbuiltins
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This file loads the function names and their modules from the
php webpage and generates itself.
Do not alter the MODULES dict by hand!
WARNING: the generation transfers quite much data over your
internet connection. don't run that at home, use
a server ;-)
:copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
:license: BSD, see LICENSE for details.
"""
MODULES = {'.NET': ['dotnet_load'],
'APC': ['apc_add',
'apc_bin_dump',
'apc_bin_dumpfile',
'apc_bin_load',
'apc_bin_loadfile',
'apc_cache_info',
'apc_cas',
'apc_clear_cache',
'apc_compile_file',
'apc_dec',
'apc_define_constants',
'apc_delete_file',
'apc_delete',
'apc_exists',
'apc_fetch',
'apc_inc',
'apc_load_constants',
'apc_sma_info',
'apc_store'],
'APD': ['apd_breakpoint',
'apd_callstack',
'apd_clunk',
'apd_continue',
'apd_croak',
'apd_dump_function_table',
'apd_dump_persistent_resources',
'apd_dump_regular_resources',
'apd_echo',
'apd_get_active_symbols',
'apd_set_pprof_trace',
'apd_set_session_trace_socket',
'apd_set_session_trace',
'apd_set_session',
'override_function',
'rename_function'],
'Aliases and deprecated Mysqli': ['mysqli_bind_param',
'mysqli_bind_result',
'mysqli_client_encoding',
'mysqli_connect',
'mysqli_disable_reads_from_master',
'mysqli_disable_rpl_parse',
'mysqli_enable_reads_from_master',
'mysqli_enable_rpl_parse',
'mysqli_escape_string',
'mysqli_execute',
'mysqli_fetch',
'mysqli_get_metadata',
'mysqli_master_query',
'mysqli_param_count',
'mysqli_report',
'mysqli_rpl_parse_enabled',
'mysqli_rpl_probe',
'mysqli_rpl_query_type',
'mysqli_send_long_data',
'mysqli_send_query',
'mysqli_set_opt',
'mysqli_slave_query'],
'Apache': ['apache_child_terminate',
'apache_get_modules',
'apache_get_version',
'apache_getenv',
'apache_lookup_uri',
'apache_note',
'apache_request_headers',
'apache_reset_timeout',
'apache_response_headers',
'apache_setenv',
'getallheaders',
'virtual'],
'Array': ['array_change_key_case',
'array_chunk',
'array_combine',
'array_count_values',
'array_diff_assoc',
'array_diff_key',
'array_diff_uassoc',
'array_diff_ukey',
'array_diff',
'array_fill_keys',
'array_fill',
'array_filter',
'array_flip',
'array_intersect_assoc',
'array_intersect_key',
'array_intersect_uassoc',
'array_intersect_ukey',
'array_intersect',
'array_key_exists',
'array_keys',
'array_map',
'array_merge_recursive',
'array_merge',
'array_multisort',
'array_pad',
'array_pop',
'array_product',
'array_push',
'array_rand',
'array_reduce',
'array_replace_recursive',
'array_replace',
'array_reverse',
'array_search',
'array_shift',
'array_slice',
'array_splice',
'array_sum',
'array_udiff_assoc',
'array_udiff_uassoc',
'array_udiff',
'array_uintersect_assoc',
'array_uintersect_uassoc',
'array_uintersect',
'array_unique',
'array_unshift',
'array_values',
'array_walk_recursive',
'array_walk',
'array',
'arsort',
'asort',
'compact',
'count',
'current',
'each',
'end',
'extract',
'in_array',
'key',
'krsort',
'ksort',
'list',
'natcasesort',
'natsort',
'next',
'pos',
'prev',
'range',
'reset',
'rsort',
'shuffle',
'sizeof',
'sort',
'uasort',
'uksort',
'usort'],
'BBCode': ['bbcode_add_element',
'bbcode_add_smiley',
'bbcode_create',
'bbcode_destroy',
'bbcode_parse',
'bbcode_set_arg_parser',
'bbcode_set_flags'],
'BC Math': ['bcadd',
'bccomp',
'bcdiv',
'bcmod',
'bcmul',
'bcpow',
'bcpowmod',
'bcscale',
'bcsqrt',
'bcsub'],
'Bzip2': ['bzclose',
'bzcompress',
'bzdecompress',
'bzerrno',
'bzerror',
'bzerrstr',
'bzflush',
'bzopen',
'bzread',
'bzwrite'],
'COM': ['com_addref',
'com_create_guid',
'com_event_sink',
'com_get_active_object',
'com_get',
'com_invoke',
'com_isenum',
'com_load_typelib',
'com_load',
'com_message_pump',
'com_print_typeinfo',
'com_propget',
'com_propput',
'com_propset',
'com_release',
'com_set',
'variant_abs',
'variant_add',
'variant_and',
'variant_cast',
'variant_cat',
'variant_cmp',
'variant_date_from_timestamp',
'variant_date_to_timestamp',
'variant_div',
'variant_eqv',
'variant_fix',
'variant_get_type',
'variant_idiv',
'variant_imp',
'variant_int',
'variant_mod',
'variant_mul',
'variant_neg',
'variant_not',
'variant_or',
'variant_pow',
'variant_round',
'variant_set_type',
'variant_set',
'variant_sub',
'variant_xor'],
'CUBRID': ['cubrid_affected_rows',
'cubrid_bind',
'cubrid_close_prepare',
'cubrid_close_request',
'cubrid_col_get',
'cubrid_col_size',
'cubrid_column_names',
'cubrid_column_types',
'cubrid_commit',
'cubrid_connect_with_url',
'cubrid_connect',
'cubrid_current_oid',
'cubrid_disconnect',
'cubrid_drop',
'cubrid_error_code_facility',
'cubrid_error_code',
'cubrid_error_msg',
'cubrid_execute',
'cubrid_fetch',
'cubrid_free_result',
'cubrid_get_charset',
'cubrid_get_class_name',
'cubrid_get_client_info',
'cubrid_get_db_parameter',
'cubrid_get_server_info',
'cubrid_get',
'cubrid_insert_id',
'cubrid_is_instance',
'cubrid_lob_close',
'cubrid_lob_export',
'cubrid_lob_get',
'cubrid_lob_send',
'cubrid_lob_size',
'cubrid_lock_read',
'cubrid_lock_write',
'cubrid_move_cursor',
'cubrid_num_cols',
'cubrid_num_rows',
'cubrid_prepare',
'cubrid_put',
'cubrid_rollback',
'cubrid_schema',
'cubrid_seq_drop',
'cubrid_seq_insert',
'cubrid_seq_put',
'cubrid_set_add',
'cubrid_set_drop',
'cubrid_version'],
'Cairo': ['cairo_create',
'cairo_font_face_get_type',
'cairo_font_face_status',
'cairo_font_options_create',
'cairo_font_options_equal',
'cairo_font_options_get_antialias',
'cairo_font_options_get_hint_metrics',
'cairo_font_options_get_hint_style',
'cairo_font_options_get_subpixel_order',
'cairo_font_options_hash',
'cairo_font_options_merge',
'cairo_font_options_set_antialias',
'cairo_font_options_set_hint_metrics',
'cairo_font_options_set_hint_style',
'cairo_font_options_set_subpixel_order',
'cairo_font_options_status',
'cairo_format_stride_for_width',
'cairo_image_surface_create_for_data',
'cairo_image_surface_create_from_png',
'cairo_image_surface_create',
'cairo_image_surface_get_data',
'cairo_image_surface_get_format',
'cairo_image_surface_get_height',
'cairo_image_surface_get_stride',
'cairo_image_surface_get_width',
'cairo_matrix_create_scale',
'cairo_matrix_create_translate',
'cairo_matrix_invert',
'cairo_matrix_multiply',
'cairo_matrix_rotate',
'cairo_matrix_transform_distance',
'cairo_matrix_transform_point',
'cairo_matrix_translate',
'cairo_pattern_add_color_stop_rgb',
'cairo_pattern_add_color_stop_rgba',
'cairo_pattern_create_for_surface',
'cairo_pattern_create_linear',
'cairo_pattern_create_radial',
'cairo_pattern_create_rgb',
'cairo_pattern_create_rgba',
'cairo_pattern_get_color_stop_count',
'cairo_pattern_get_color_stop_rgba',
'cairo_pattern_get_extend',
'cairo_pattern_get_filter',
'cairo_pattern_get_linear_points',
'cairo_pattern_get_matrix',
'cairo_pattern_get_radial_circles',
'cairo_pattern_get_rgba',
'cairo_pattern_get_surface',
'cairo_pattern_get_type',
'cairo_pattern_set_extend',
'cairo_pattern_set_filter',
'cairo_pattern_set_matrix',
'cairo_pattern_status',
'cairo_pdf_surface_create',
'cairo_pdf_surface_set_size',
'cairo_ps_get_levels',
'cairo_ps_level_to_string',
'cairo_ps_surface_create',
'cairo_ps_surface_dsc_begin_page_setup',
'cairo_ps_surface_dsc_begin_setup',
'cairo_ps_surface_dsc_comment',
'cairo_ps_surface_get_eps',
'cairo_ps_surface_restrict_to_level',
'cairo_ps_surface_set_eps',
'cairo_ps_surface_set_size',
'cairo_scaled_font_create',
'cairo_scaled_font_extents',
'cairo_scaled_font_get_ctm',
'cairo_scaled_font_get_font_face',
'cairo_scaled_font_get_font_matrix',
'cairo_scaled_font_get_font_options',
'cairo_scaled_font_get_scale_matrix',
'cairo_scaled_font_get_type',
'cairo_scaled_font_glyph_extents',
'cairo_scaled_font_status',
'cairo_scaled_font_text_extents',
'cairo_surface_copy_page',
'cairo_surface_create_similar',
'cairo_surface_finish',
'cairo_surface_flush',
'cairo_surface_get_content',
'cairo_surface_get_device_offset',
'cairo_surface_get_font_options',
'cairo_surface_get_type',
'cairo_surface_mark_dirty_rectangle',
'cairo_surface_mark_dirty',
'cairo_surface_set_device_offset',
'cairo_surface_set_fallback_resolution',
'cairo_surface_show_page',
'cairo_surface_status',
'cairo_surface_write_to_png',
'cairo_svg_surface_create',
'cairo_svg_surface_restrict_to_version',
'cairo_svg_version_to_string'],
'Calendar': ['cal_days_in_month',
'cal_from_jd',
'cal_info',
'cal_to_jd',
'easter_date',
'easter_days',
'FrenchToJD',
'GregorianToJD',
'JDDayOfWeek',
'JDMonthName',
'JDToFrench',
'JDToGregorian',
'jdtojewish',
'JDToJulian',
'jdtounix',
'JewishToJD',
'JulianToJD',
'unixtojd'],
'Classes/Object': ['call_user_method_array',
'call_user_method',
'class_alias',
'class_exists',
'get_called_class',
'get_class_methods',
'get_class_vars',
'get_class',
'get_declared_classes',
'get_declared_interfaces',
'get_object_vars',
'get_parent_class',
'interface_exists',
'is_a',
'is_subclass_of',
'method_exists',
'property_exists'],
'Classkit': ['classkit_import',
'classkit_method_add',
'classkit_method_copy',
'classkit_method_redefine',
'classkit_method_remove',
'classkit_method_rename'],
'Crack': ['crack_check',
'crack_closedict',
'crack_getlastmessage',
'crack_opendict'],
'Ctype': ['ctype_alnum',
'ctype_alpha',
'ctype_cntrl',
'ctype_digit',
'ctype_graph',
'ctype_lower',
'ctype_print',
'ctype_punct'],
'Cyrus': ['cyrus_authenticate',
'cyrus_bind',
'cyrus_close',
'cyrus_connect',
'cyrus_query',
'cyrus_unbind'],
'DB++': ['dbplus_add',
'dbplus_aql',
'dbplus_chdir',
'dbplus_close',
'dbplus_curr',
'dbplus_errcode',
'dbplus_errno',
'dbplus_find',
'dbplus_first',
'dbplus_flush',
'dbplus_freealllocks',
'dbplus_freelock',
'dbplus_freerlocks',
'dbplus_getlock',
'dbplus_getunique',
'dbplus_info',
'dbplus_last',
'dbplus_lockrel',
'dbplus_next',
'dbplus_open',
'dbplus_prev',
'dbplus_rchperm',
'dbplus_rcreate',
'dbplus_rcrtexact',
'dbplus_rcrtlike',
'dbplus_resolve',
'dbplus_restorepos',
'dbplus_rkeys',
'dbplus_ropen',
'dbplus_rquery',
'dbplus_rrename',
'dbplus_rsecindex',
'dbplus_runlink',
'dbplus_rzap',
'dbplus_savepos',
'dbplus_setindex',
'dbplus_setindexbynumber',
'dbplus_sql',
'dbplus_tcl',
'dbplus_tremove',
'dbplus_undo',
'dbplus_undoprepare',
'dbplus_unlockrel',
'dbplus_unselect',
'dbplus_update',
'dbplus_xlockrel',
'dbplus_xunlockrel'],
'DBA': ['dba_close',
'dba_delete',
'dba_exists',
'dba_fetch',
'dba_firstkey',
'dba_handlers',
'dba_insert',
'dba_key_split',
'dba_list',
'dba_nextkey',
'dba_open',
'dba_optimize',
'dba_popen',
'dba_replace',
'dba_sync'],
'DOM': ['dom_import_simplexml'],
'DOM XML (PHP 4)': ['domxml_new_doc',
'domxml_open_file',
'domxml_open_mem',
'domxml_version',
'domxml_xmltree',
'domxml_xslt_stylesheet_doc',
'domxml_xslt_stylesheet_file',
'domxml_xslt_stylesheet',
'domxml_xslt_version',
'xpath_eval_expression',
'xpath_eval',
'xpath_new_context',
'xpath_register_ns_auto',
'xpath_register_ns',
'xptr_eval',
'xptr_new_context'],
'Date/Time': ['checkdate',
'date_add',
'date_create_from_format',
'date_create',
'date_date_set',
'date_default_timezone_get',
'date_default_timezone_set',
'date_diff',
'date_format',
'date_get_last_errors',
'date_interval_create_from_date_string',
'date_interval_format',
'date_isodate_set',
'date_modify',
'date_offset_get',
'date_parse_from_format',
'date_parse',
'date_sub',
'date_sun_info',
'date_sunrise',
'date_sunset',
'date_time_set',
'date_timestamp_get',
'date_timestamp_set',
'date_timezone_get',
'date_timezone_set',
'date',
'getdate',
'gettimeofday',
'gmdate',
'gmmktime',
'gmstrftime',
'idate',
'localtime',
'microtime',
'mktime',
'strftime',
'strptime',
'strtotime',
'time',
'timezone_abbreviations_list',
'timezone_identifiers_list',
'timezone_location_get',
'timezone_name_from_abbr',
'timezone_name_get',
'timezone_offset_get',
'timezone_open',
'timezone_transitions_get',
'timezone_version_get'],
'Direct IO': ['dio_close', 'dio_fcntl', 'dio_open'],
'Directory': ['chdir',
'chroot',
'closedir',
'getcwd',
'opendir',
'readdir',
'rewinddir',
'scandir'],
'Enchant': ['enchant_broker_describe',
'enchant_broker_dict_exists',
'enchant_broker_free_dict',
'enchant_broker_free',
'enchant_broker_get_error',
'enchant_broker_init',
'enchant_broker_list_dicts',
'enchant_broker_request_dict',
'enchant_broker_request_pwl_dict',
'enchant_broker_set_ordering',
'enchant_dict_add_to_personal',
'enchant_dict_add_to_session',
'enchant_dict_check',
'enchant_dict_describe',
'enchant_dict_get_error',
'enchant_dict_is_in_session',
'enchant_dict_quick_check',
'enchant_dict_store_replacement',
'enchant_dict_suggest'],
'Error Handling': ['debug_backtrace',
'debug_print_backtrace',
'error_get_last',
'error_log',
'error_reporting',
'restore_error_handler',
'restore_exception_handler',
'set_error_handler',
'set_exception_handler',
'trigger_error',
'user_error'],
'Exif': ['exif_imagetype',
'exif_read_data',
'exif_tagname',
'exif_thumbnail',
'read_exif_data'],
'Expect': ['expect_expectl'],
'FAM': ['fam_cancel_monitor',
'fam_close',
'fam_monitor_collection',
'fam_monitor_directory',
'fam_monitor_file',
'fam_next_event',
'fam_open',
'fam_pending',
'fam_resume_monitor',
'fam_suspend_monitor'],
'FDF': ['fdf_add_doc_javascript',
'fdf_add_template',
'fdf_close',
'fdf_create',
'fdf_enum_values',
'fdf_errno',
'fdf_error',
'fdf_get_ap',
'fdf_get_attachment',
'fdf_get_encoding',
'fdf_get_file',
'fdf_get_flags',
'fdf_get_opt',
'fdf_get_status',
'fdf_get_value',
'fdf_get_version',
'fdf_header',
'fdf_next_field_name',
'fdf_open_string',
'fdf_open',
'fdf_remove_item',
'fdf_save_string',
'fdf_save',
'fdf_set_ap',
'fdf_set_encoding',
'fdf_set_file',
'fdf_set_flags',
'fdf_set_javascript_action',
'fdf_set_on_import_javascript',
'fdf_set_opt',
'fdf_set_status',
'fdf_set_submit_form_action',
'fdf_set_target_frame',
'fdf_set_value',
'fdf_set_version'],
'FTP': ['ftp_alloc',
'ftp_cdup',
'ftp_chdir',
'ftp_chmod',
'ftp_close',
'ftp_connect',
'ftp_delete',
'ftp_exec',
'ftp_fget',
'ftp_fput',
'ftp_get_option',
'ftp_get',
'ftp_login',
'ftp_mdtm',
'ftp_mkdir',
'ftp_nb_continue',
'ftp_nb_fget',
'ftp_nb_fput',
'ftp_nb_get',
'ftp_nb_put',
'ftp_nlist',
'ftp_pasv',
'ftp_put',
'ftp_pwd',
'ftp_quit',
'ftp_raw',
'ftp_rawlist',
'ftp_rename',
'ftp_rmdir',
'ftp_set_option',
'ftp_site',
'ftp_size',
'ftp_ssl_connect',
'ftp_systype'],
'Fileinfo': ['finfo_buffer',
'finfo_close',
'finfo_file',
'finfo_open',
'finfo_set_flags',
'mime_content_type'],
'Filesystem': ['basename',
'chgrp',
'chmod',
'chown',
'clearstatcache',
'copy',
'dirname',
'disk_free_space',
'disk_total_space',
'diskfreespace',
'fclose',
'feof',
'fflush',
'fgetc',
'fgetcsv',
'fgets',
'fgetss',
'file_exists',
'file_get_contents',
'file_put_contents',
'file',
'fileatime',
'filectime',
'filegroup',
'fileinode',
'filemtime',
'fileowner',
'fileperms',
'filesize',
'filetype',
'flock',
'fnmatch',
'fopen',
'fpassthru',
'fputcsv',
'fputs',
'fread',
'fscanf',
'fseek',
'fstat',
'ftell',
'ftruncate',
'fwrite',
'glob',
'is_dir',
'is_executable',
'is_file',
'is_link',
'is_readable',
'is_uploaded_file',
'is_writable',
'is_writeable',
'lchgrp',
'lchown',
'link',
'linkinfo',
'lstat',
'mkdir',
'move_uploaded_file',
'parse_ini_file',
'parse_ini_string',
'pathinfo',
'pclose',
'popen',
'readfile',
'readlink',
'realpath_cache_get',
'realpath_cache_size',
'realpath',
'rename',
'rewind',
'rmdir',
'set_file_buffer',
'stat',
'symlink',
'tempnam',
'tmpfile',
'touch',
'umask',
'unlink'],
'Filter': ['filter_has_var',
'filter_id',
'filter_input_array',
'filter_input',
'filter_list',
'filter_var_array',
'filter_var'],
'Firebird/InterBase': ['ibase_add_user',
'ibase_affected_rows',
'ibase_backup',
'ibase_blob_add',
'ibase_blob_cancel',
'ibase_blob_close',
'ibase_blob_create',
'ibase_blob_echo',
'ibase_blob_get',
'ibase_blob_import',
'ibase_blob_info',
'ibase_blob_open',
'ibase_close',
'ibase_commit_ret',
'ibase_commit',
'ibase_connect',
'ibase_db_info',
'ibase_delete_user',
'ibase_drop_db',
'ibase_errcode',
'ibase_errmsg',
'ibase_execute',
'ibase_fetch_assoc',
'ibase_fetch_object',
'ibase_fetch_row',
'ibase_field_info',
'ibase_free_event_handler',
'ibase_free_query',
'ibase_free_result',
'ibase_gen_id',
'ibase_maintain_db',
'ibase_modify_user',
'ibase_name_result',
'ibase_num_fields',
'ibase_num_params',
'ibase_param_info',
'ibase_pconnect',
'ibase_prepare',
'ibase_query',
'ibase_restore',
'ibase_rollback_ret',
'ibase_rollback',
'ibase_server_info',
'ibase_service_attach',
'ibase_service_detach',
'ibase_set_event_handler',
'ibase_timefmt',
'ibase_trans',
'ibase_wait_event'],
'FriBiDi': ['fribidi_log2vis'],
'FrontBase': ['fbsql_affected_rows',
'fbsql_autocommit',
'fbsql_blob_size',
'fbsql_change_user',
'fbsql_clob_size',
'fbsql_close',
'fbsql_commit',
'fbsql_connect',
'fbsql_create_blob',
'fbsql_create_clob',
'fbsql_create_db',
'fbsql_data_seek',
'fbsql_database_password',
'fbsql_database',
'fbsql_db_query',
'fbsql_db_status',
'fbsql_drop_db',
'fbsql_errno',
'fbsql_error',
'fbsql_fetch_array',
'fbsql_fetch_assoc',
'fbsql_fetch_field',
'fbsql_fetch_lengths',
'fbsql_fetch_object',
'fbsql_fetch_row',
'fbsql_field_flags',
'fbsql_field_len',
'fbsql_field_name',
'fbsql_field_seek',
'fbsql_field_table',
'fbsql_field_type',
'fbsql_free_result',
'fbsql_get_autostart_info',
'fbsql_hostname',
'fbsql_insert_id',
'fbsql_list_dbs',
'fbsql_list_fields',
'fbsql_list_tables',
'fbsql_next_result',
'fbsql_num_fields',
'fbsql_num_rows',
'fbsql_password',
'fbsql_pconnect',
'fbsql_query',
'fbsql_read_blob',
'fbsql_read_clob',
'fbsql_result',
'fbsql_rollback',
'fbsql_rows_fetched',
'fbsql_select_db',
'fbsql_set_characterset',
'fbsql_set_lob_mode',
'fbsql_set_password',
'fbsql_set_transaction',
'fbsql_start_db',
'fbsql_stop_db',
'fbsql_table_name',
'fbsql_tablename',
'fbsql_username',
'fbsql_warnings'],
'Function handling': ['call_user_func_array',
'call_user_func',
'create_function',
'forward_static_call_array',
'forward_static_call',
'func_get_arg',
'func_get_args',
'func_num_args',
'function_exists',
'get_defined_functions',
'register_shutdown_function',
'register_tick_function',
'unregister_tick_function'],
'GD and Image': ['gd_info',
'getimagesize',
'image_type_to_extension',
'image_type_to_mime_type'],
'GMP': ['gmp_abs',
'gmp_add',
'gmp_and',
'gmp_clrbit',
'gmp_cmp',
'gmp_com',
'gmp_div_q',
'gmp_div_qr',
'gmp_div_r',
'gmp_div',
'gmp_divexact',
'gmp_fact',
'gmp_gcd',
'gmp_gcdext',
'gmp_hamdist',
'gmp_init',
'gmp_intval',
'gmp_invert',
'gmp_jacobi',
'gmp_legendre',
'gmp_mod',
'gmp_mul',
'gmp_neg',
'gmp_nextprime',
'gmp_or',
'gmp_perfect_square',
'gmp_popcount',
'gmp_pow',
'gmp_powm',
'gmp_prob_prime',
'gmp_random',
'gmp_scan0',
'gmp_scan1',
'gmp_setbit',
'gmp_sign',
'gmp_sqrt',
'gmp_sqrtrem',
'gmp_strval',
'gmp_sub',
'gmp_testbit',
'gmp_xor'],
'GeoIP': ['geoip_continent_code_by_name',
'geoip_country_code_by_name',
'geoip_country_code3_by_name',
'geoip_country_name_by_name',
'geoip_database_info',
'geoip_db_avail',
'geoip_db_filename',
'geoip_db_get_all_info',
'geoip_id_by_name',
'geoip_isp_by_name',
'geoip_org_by_name',
'geoip_record_by_name',
'geoip_region_by_name',
'geoip_region_name_by_code',
'geoip_time_zone_by_country_and_region'],
'Gettext': ['bind_textdomain_codeset',
'bindtextdomain',
'dcgettext',
'dcngettext',
'dgettext',
'dngettext',
'gettext',
'ngettext',
'textdomain'],
'GnuPG': ['gnupg_adddecryptkey',
'gnupg_addencryptkey',
'gnupg_addsignkey',
'gnupg_cleardecryptkeys',
'gnupg_clearencryptkeys',
'gnupg_clearsignkeys',
'gnupg_decrypt',
'gnupg_decryptverify',
'gnupg_encrypt',
'gnupg_encryptsign',
'gnupg_export',
'gnupg_geterror',
'gnupg_getprotocol',
'gnupg_import',
'gnupg_init',
'gnupg_keyinfo',
'gnupg_setarmor',
'gnupg_seterrormode',
'gnupg_setsignmode',
'gnupg_sign',
'gnupg_verify'],
'Gopher': ['gopher_parsedir'],
'Grapheme': ['grapheme_extract',
'grapheme_stripos',
'grapheme_stristr',
'grapheme_strlen',
'grapheme_strpos',
'grapheme_strripos',
'grapheme_strrpos',
'grapheme_strstr',
'grapheme_substr'],
'Gupnp': ['gupnp_context_get_host_ip',
'gupnp_context_get_port',
'gupnp_context_get_subscription_timeout',
'gupnp_context_host_path',
'gupnp_context_new',
'gupnp_context_set_subscription_timeout',
'gupnp_context_timeout_add',
'gupnp_context_unhost_path',
'gupnp_control_point_browse_start',
'gupnp_control_point_browse_stop',
'gupnp_control_point_callback_set',
'gupnp_control_point_new',
'gupnp_device_action_callback_set',
'gupnp_device_info_get_service',
'gupnp_device_info_get',
'gupnp_root_device_get_available',
'gupnp_root_device_get_relative_location',
'gupnp_root_device_new',
'gupnp_root_device_set_available',
'gupnp_root_device_start',
'gupnp_root_device_stop',
'gupnp_service_action_get',
'gupnp_service_action_return_error',
'gupnp_service_action_return',
'gupnp_service_action_set',
'gupnp_service_freeze_notify',
'gupnp_service_info_get_introspection',
'gupnp_service_info_get',
'gupnp_service_introspection_get_state_variable',
'gupnp_service_notify',
'gupnp_service_proxy_action_get',
'gupnp_service_proxy_action_set',
'gupnp_service_proxy_add_notify',
'gupnp_service_proxy_callback_set',
'gupnp_service_proxy_get_subscribed',
'gupnp_service_proxy_remove_notify',
'gupnp_service_proxy_set_subscribed',
'gupnp_service_thaw_notify'],
'HTTP': ['http_cache_etag',
'http_cache_last_modified',
'http_chunked_decode',
'http_deflate',
'http_inflate',
'http_build_cookie',
'http_date',
'http_get_request_body_stream',
'http_get_request_body',
'http_get_request_headers',
'http_match_etag',
'http_match_modified',
'http_match_request_header',
'http_support',
'http_negotiate_charset',
'http_negotiate_content_type',
'http_negotiate_language',
'ob_deflatehandler',
'ob_etaghandler',
'ob_inflatehandler',
'http_parse_cookie',
'http_parse_headers',
'http_parse_message',
'http_parse_params',
'http_persistent_handles_clean',
'http_persistent_handles_count',
'http_persistent_handles_ident',
'http_get',
'http_head',
'http_post_data',
'http_post_fields',
'http_put_data',
'http_put_file',
'http_put_stream',
'http_request_body_encode',
'http_request_method_exists',
'http_request_method_name',
'http_request_method_register',
'http_request_method_unregister',
'http_request',
'http_redirect',
'http_send_content_disposition',
'http_send_content_type',
'http_send_data',
'http_send_file',
'http_send_last_modified',
'http_send_status',
'http_send_stream',
'http_throttle',
'http_build_str',
'http_build_url'],
'Hash': ['hash_algos',
'hash_copy',
'hash_file',
'hash_final',
'hash_hmac_file',
'hash_hmac',
'hash_init',
'hash_update_file',
'hash_update_stream',
'hash_update',
'hash'],
'Hyperwave': ['hw_Array2Objrec',
'hw_changeobject',
'hw_Children',
'hw_ChildrenObj',
'hw_Close',
'hw_Connect',
'hw_connection_info',
'hw_cp',
'hw_Deleteobject',
'hw_DocByAnchor',
'hw_DocByAnchorObj',
'hw_Document_Attributes',
'hw_Document_BodyTag',
'hw_Document_Content',
'hw_Document_SetContent',
'hw_Document_Size',
'hw_dummy',
'hw_EditText',
'hw_Error',
'hw_ErrorMsg',
'hw_Free_Document',
'hw_GetAnchors',
'hw_GetAnchorsObj',
'hw_GetAndLock',
'hw_GetChildColl',
'hw_GetChildCollObj',
'hw_GetChildDocColl',
'hw_GetChildDocCollObj',
'hw_GetObject',
'hw_GetObjectByQuery',
'hw_GetObjectByQueryColl',
'hw_GetObjectByQueryCollObj',
'hw_GetObjectByQueryObj',
'hw_GetParents',
'hw_GetParentsObj',
'hw_getrellink',
'hw_GetRemote',
'hw_getremotechildren',
'hw_GetSrcByDestObj',
'hw_GetText',
'hw_getusername',
'hw_Identify',
'hw_InCollections',
'hw_Info',
'hw_InsColl',
'hw_InsDoc',
'hw_insertanchors',
'hw_InsertDocument',
'hw_InsertObject',
'hw_mapid',
'hw_Modifyobject',
'hw_mv',
'hw_New_Document',
'hw_objrec2array',
'hw_Output_Document',
'hw_pConnect',
'hw_PipeDocument',
'hw_Root',
'hw_setlinkroot',
'hw_stat',
'hw_Unlock',
'hw_Who'],
'Hyperwave API': ['hw_api_attribute',
'hwapi_hgcsp',
'hw_api_content',
'hw_api_object'],
'IBM DB2': ['db2_autocommit',
'db2_bind_param',
'db2_client_info',
'db2_close',
'db2_column_privileges',
'db2_columns',
'db2_commit',
'db2_conn_error',
'db2_conn_errormsg',
'db2_connect',
'db2_cursor_type',
'db2_escape_string',
'db2_exec',
'db2_execute',
'db2_fetch_array',
'db2_fetch_assoc',
'db2_fetch_both',
'db2_fetch_object',
'db2_fetch_row',
'db2_field_display_size',
'db2_field_name',
'db2_field_num',
'db2_field_precision',
'db2_field_scale',
'db2_field_type',
'db2_field_width',
'db2_foreign_keys',
'db2_free_result',
'db2_free_stmt',
'db2_get_option',
'db2_last_insert_id'],
'ID3': ['id3_get_frame_long_name',
'id3_get_frame_short_name',
'id3_get_genre_id',
'id3_get_genre_list',
'id3_get_genre_name',
'id3_get_tag',
'id3_get_version',
'id3_remove_tag',
'id3_set_tag'],
'IDN': ['idn_to_ascii', 'idn_to_unicode', 'idn_to_utf8'],
'IIS': ['iis_add_server',
'iis_get_dir_security',
'iis_get_script_map',
'iis_get_server_by_comment',
'iis_get_server_by_path',
'iis_get_server_rights',
'iis_get_service_state',
'iis_remove_server',
'iis_set_app_settings',
'iis_set_dir_security',
'iis_set_script_map',
'iis_set_server_rights',
'iis_start_server',
'iis_start_service',
'iis_stop_server',
'iis_stop_service'],
'IMAP': ['imap_8bit',
'imap_alerts',
'imap_append',
'imap_base64',
'imap_binary',
'imap_body',
'imap_bodystruct',
'imap_check',
'imap_clearflag_full',
'imap_close',
'imap_createmailbox',
'imap_delete',
'imap_deletemailbox',
'imap_errors',
'imap_expunge',
'imap_fetch_overview',
'imap_fetchbody',
'imap_fetchheader',
'imap_fetchmime',
'imap_fetchstructure',
'imap_gc',
'imap_get_quota',
'imap_get_quotaroot',
'imap_getacl',
'imap_getmailboxes',
'imap_getsubscribed',
'imap_header',
'imap_headerinfo',
'imap_headers',
'imap_last_error',
'imap_list',
'imap_listmailbox',
'imap_listscan',
'imap_listsubscribed',
'imap_lsub',
'imap_mail_compose',
'imap_mail_copy',
'imap_mail_move',
'imap_mail',
'imap_mailboxmsginfo',
'imap_mime_header_decode',
'imap_msgno',
'imap_num_msg',
'imap_num_recent',
'imap_open',
'imap_ping',
'imap_qprint',
'imap_renamemailbox',
'imap_reopen',
'imap_rfc822_parse_adrlist',
'imap_rfc822_parse_headers',
'imap_rfc822_write_address',
'imap_savebody',
'imap_scanmailbox',
'imap_search',
'imap_set_quota',
'imap_setacl',
'imap_setflag_full',
'imap_sort',
'imap_status',
'imap_subscribe',
'imap_thread',
'imap_timeout',
'imap_uid',
'imap_undelete',
'imap_unsubscribe',
'imap_utf7_decode',
'imap_utf7_encode',
'imap_utf8'],
'Informix': ['ifx_affected_rows',
'ifx_blobinfile_mode',
'ifx_byteasvarchar',
'ifx_close',
'ifx_connect',
'ifx_copy_blob',
'ifx_create_blob',
'ifx_create_char',
'ifx_do',
'ifx_error',
'ifx_errormsg',
'ifx_fetch_row',
'ifx_fieldproperties',
'ifx_fieldtypes',
'ifx_free_blob',
'ifx_free_char',
'ifx_free_result',
'ifx_get_blob',
'ifx_get_char',
'ifx_getsqlca',
'ifx_htmltbl_result',
'ifx_nullformat',
'ifx_num_fields',
'ifx_num_rows',
'ifx_pconnect',
'ifx_prepare',
'ifx_query',
'ifx_textasvarchar',
'ifx_update_blob',
'ifx_update_char',
'ifxus_close_slob',
'ifxus_create_slob',
'ifxus_free_slob',
'ifxus_open_slob',
'ifxus_read_slob',
'ifxus_seek_slob',
'ifxus_tell_slob',
'ifxus_write_slob'],
'Ingres': ['ingres_autocommit_state',
'ingres_autocommit',
'ingres_charset',
'ingres_close',
'ingres_commit',
'ingres_connect',
'ingres_cursor',
'ingres_errno',
'ingres_error',
'ingres_errsqlstate',
'ingres_escape_string',
'ingres_execute',
'ingres_fetch_array',
'ingres_fetch_assoc',
'ingres_fetch_object',
'ingres_fetch_proc_return',
'ingres_fetch_row',
'ingres_field_length',
'ingres_field_name',
'ingres_field_nullable',
'ingres_field_precision',
'ingres_field_scale',
'ingres_field_type',
'ingres_free_result',
'ingres_next_error',
'ingres_num_fields',
'ingres_num_rows',
'ingres_pconnect',
'ingres_prepare',
'ingres_query',
'ingres_result_seek',
'ingres_rollback',
'ingres_set_environment',
'ingres_unbuffered_query'],
'Inotify': ['inotify_add_watch',
'inotify_init',
'inotify_queue_len',
'inotify_read',
'inotify_rm_watch'],
'JSON': ['json_decode', 'json_encode', 'json_last_error'],
'Java': ['java_last_exception_clear', 'java_last_exception_get'],
'Judy': ['judy_type', 'judy_version'],
'KADM5': ['kadm5_chpass_principal',
'kadm5_create_principal',
'kadm5_delete_principal',
'kadm5_destroy',
'kadm5_flush',
'kadm5_get_policies',
'kadm5_get_principal',
'kadm5_get_principals',
'kadm5_init_with_password',
'kadm5_modify_principal'],
'LDAP': ['ldap_8859_to_t61',
'ldap_add',
'ldap_bind',
'ldap_close',
'ldap_compare',
'ldap_connect',
'ldap_count_entries',
'ldap_delete',
'ldap_dn2ufn',
'ldap_err2str',
'ldap_errno',
'ldap_error',
'ldap_explode_dn',
'ldap_first_attribute',
'ldap_first_entry',
'ldap_first_reference',
'ldap_free_result',
'ldap_get_attributes',
'ldap_get_dn',
'ldap_get_entries',
'ldap_get_option',
'ldap_get_values_len',
'ldap_get_values',
'ldap_list',
'ldap_mod_add',
'ldap_mod_del',
'ldap_mod_replace',
'ldap_modify',
'ldap_next_attribute',
'ldap_next_entry',
'ldap_next_reference',
'ldap_parse_reference',
'ldap_parse_result',
'ldap_read',
'ldap_rename',
'ldap_sasl_bind',
'ldap_search',
'ldap_set_option',
'ldap_set_rebind_proc',
'ldap_sort',
'ldap_start_tls',
'ldap_t61_to_8859',
'ldap_unbind'],
'LZF': ['lzf_compress', 'lzf_decompress', 'lzf_optimized_for'],
'Libevent': ['event_add',
'event_base_free',
'event_base_loop',
'event_base_loopbreak',
'event_base_loopexit',
'event_base_new',
'event_base_priority_init',
'event_base_set',
'event_buffer_base_set',
'event_buffer_disable',
'event_buffer_enable',
'event_buffer_fd_set',
'event_buffer_free',
'event_buffer_new',
'event_buffer_priority_set',
'event_buffer_read',
'event_buffer_set_callback',
'event_buffer_timeout_set',
'event_buffer_watermark_set',
'event_buffer_write',
'event_del',
'event_free',
'event_new',
'event_set'],
'Lotus Notes': ['notes_body',
'notes_copy_db',
'notes_create_db',
'notes_create_note',
'notes_drop_db',
'notes_find_note',
'notes_header_info',
'notes_list_msgs',
'notes_mark_read',
'notes_mark_unread',
'notes_nav_create',
'notes_search',
'notes_unread',
'notes_version'],
'MCVE': ['m_checkstatus',
'm_completeauthorizations',
'm_connect',
'm_connectionerror',
'm_deletetrans',
'm_destroyconn',
'm_destroyengine',
'm_getcell',
'm_getcellbynum',
'm_getcommadelimited',
'm_getheader',
'm_initconn',
'm_initengine',
'm_iscommadelimited',
'm_maxconntimeout',
'm_monitor',
'm_numcolumns',
'm_numrows',
'm_parsecommadelimited',
'm_responsekeys'],
'Mail': ['ezmlm_hash', 'mail'],
'Mailparse': ['mailparse_determine_best_xfer_encoding',
'mailparse_msg_create',
'mailparse_msg_extract_part_file',
'mailparse_msg_extract_part',
'mailparse_msg_extract_whole_part_file',
'mailparse_msg_free',
'mailparse_msg_get_part_data',
'mailparse_msg_get_part',
'mailparse_msg_get_structure',
'mailparse_msg_parse_file',
'mailparse_msg_parse',
'mailparse_rfc822_parse_addresses',
'mailparse_stream_encode',
'mailparse_uudecode_all'],
'Math': ['abs',
'acos',
'acosh',
'asin',
'asinh',
'atan2',
'atan',
'atanh',
'base_convert',
'bindec',
'ceil',
'cos',
'cosh',
'decbin',
'dechex',
'decoct',
'deg2rad',
'exp',
'expm1'],
'MaxDB': ['maxdb_affected_rows',
'maxdb_autocommit',
'maxdb_bind_param',
'maxdb_bind_result',
'maxdb_change_user',
'maxdb_character_set_name',
'maxdb_client_encoding',
'maxdb_close_long_data',
'maxdb_close',
'maxdb_commit',
'maxdb_connect_errno',
'maxdb_connect_error',
'maxdb_connect',
'maxdb_data_seek',
'maxdb_debug',
'maxdb_disable_reads_from_master',
'maxdb_disable_rpl_parse',
'maxdb_dump_debug_info',
'maxdb_embedded_connect',
'maxdb_enable_reads_from_master',
'maxdb_enable_rpl_parse',
'maxdb_errno',
'maxdb_error',
'maxdb_escape_string',
'maxdb_execute',
'maxdb_fetch_array',
'maxdb_fetch_assoc',
'maxdb_fetch_field_direct',
'maxdb_fetch_field',
'maxdb_fetch_fields',
'maxdb_fetch_lengths',
'maxdb_fetch_object',
'maxdb_fetch_row',
'maxdb_fetch',
'maxdb_field_count',
'maxdb_field_seek',
'maxdb_field_tell',
'maxdb_free_result',
'maxdb_get_client_info',
'maxdb_get_client_version',
'maxdb_get_host_info',
'maxdb_get_metadata',
'maxdb_get_proto_info',
'maxdb_get_server_info',
'maxdb_get_server_version',
'maxdb_info',
'maxdb_init',
'maxdb_insert_id',
'maxdb_kill',
'maxdb_master_query',
'maxdb_more_results',
'maxdb_multi_query',
'maxdb_next_result',
'maxdb_num_fields',
'maxdb_num_rows',
'maxdb_options',
'maxdb_param_count',
'maxdb_ping',
'maxdb_prepare',
'maxdb_query',
'maxdb_real_connect',
'maxdb_real_escape_string',
'maxdb_real_query',
'maxdb_report',
'maxdb_rollback',
'maxdb_rpl_parse_enabled',
'maxdb_rpl_probe',
'maxdb_rpl_query_type',
'maxdb_select_db',
'maxdb_send_long_data',
'maxdb_send_query',
'maxdb_server_end',
'maxdb_server_init',
'maxdb_set_opt',
'maxdb_sqlstate',
'maxdb_ssl_set',
'maxdb_stat',
'maxdb_stmt_affected_rows'],
'Mcrypt': ['mcrypt_cbc',
'mcrypt_cfb',
'mcrypt_create_iv',
'mcrypt_decrypt',
'mcrypt_ecb',
'mcrypt_enc_get_algorithms_name',
'mcrypt_enc_get_block_size',
'mcrypt_enc_get_iv_size',
'mcrypt_enc_get_key_size',
'mcrypt_enc_get_modes_name',
'mcrypt_enc_get_supported_key_sizes',
'mcrypt_enc_is_block_algorithm_mode',
'mcrypt_enc_is_block_algorithm',
'mcrypt_enc_is_block_mode',
'mcrypt_enc_self_test',
'mcrypt_encrypt',
'mcrypt_generic_deinit',
'mcrypt_generic_end',
'mcrypt_generic_init',
'mcrypt_generic',
'mcrypt_get_block_size',
'mcrypt_get_cipher_name',
'mcrypt_get_iv_size',
'mcrypt_get_key_size',
'mcrypt_list_algorithms',
'mcrypt_list_modes',
'mcrypt_module_close',
'mcrypt_module_get_algo_block_size',
'mcrypt_module_get_algo_key_size',
'mcrypt_module_get_supported_key_sizes',
'mcrypt_module_is_block_algorithm_mode',
'mcrypt_module_is_block_algorithm',
'mcrypt_module_is_block_mode',
'mcrypt_module_open',
'mcrypt_module_self_test',
'mcrypt_ofb',
'mdecrypt_generic'],
'Memcache': ['memcache_debug'],
'Mhash': ['mhash_count',
'mhash_get_block_size',
'mhash_get_hash_name',
'mhash_keygen_s2k',
'mhash'],
'Ming': ['ming_keypress',
'ming_setcubicthreshold',
'ming_setscale',
'ming_setswfcompression',
'ming_useconstants',
'ming_useswfversion'],
'Misc.': ['connection_aborted',
'connection_status',
'connection_timeout',
'constant',
'define',
'defined',
'die',
'eval',
'exit',
'get_browser',
'__halt_compiler',
'highlight_file',
'highlight_string',
'ignore_user_abort',
'pack',
'php_check_syntax',
'php_strip_whitespace',
'show_source',
'sleep',
'sys_getloadavg',
'time_nanosleep',
'time_sleep_until',
'uniqid',
'unpack',
'usleep'],
'Mongo': ['bson_decode', 'bson_encode'],
'Msession': ['msession_connect',
'msession_count',
'msession_create',
'msession_destroy',
'msession_disconnect',
'msession_find',
'msession_get_array',
'msession_get_data',
'msession_get',
'msession_inc',
'msession_list',
'msession_listvar',
'msession_lock',
'msession_plugin',
'msession_randstr',
'msession_set_array',
'msession_set_data',
'msession_set',
'msession_timeout',
'msession_uniq',
'msession_unlock'],
'Mssql': ['mssql_bind',
'mssql_close',
'mssql_connect',
'mssql_data_seek',
'mssql_execute',
'mssql_fetch_array',
'mssql_fetch_assoc',
'mssql_fetch_batch',
'mssql_fetch_field',
'mssql_fetch_object',
'mssql_fetch_row',
'mssql_field_length',
'mssql_field_name',
'mssql_field_seek',
'mssql_field_type',
'mssql_free_result',
'mssql_free_statement',
'mssql_get_last_message',
'mssql_guid_string',
'mssql_init',
'mssql_min_error_severity',
'mssql_min_message_severity',
'mssql_next_result',
'mssql_num_fields',
'mssql_num_rows',
'mssql_pconnect',
'mssql_query',
'mssql_result',
'mssql_rows_affected',
'mssql_select_db'],
'Multibyte String': ['mb_check_encoding',
'mb_convert_case',
'mb_convert_encoding',
'mb_convert_kana',
'mb_convert_variables',
'mb_decode_mimeheader',
'mb_decode_numericentity',
'mb_detect_encoding',
'mb_detect_order',
'mb_encode_mimeheader',
'mb_encode_numericentity',
'mb_encoding_aliases',
'mb_ereg_match',
'mb_ereg_replace',
'mb_ereg_search_getpos',
'mb_ereg_search_getregs',
'mb_ereg_search_init',
'mb_ereg_search_pos',
'mb_ereg_search_regs',
'mb_ereg_search_setpos',
'mb_ereg_search',
'mb_ereg',
'mb_eregi_replace',
'mb_eregi',
'mb_get_info',
'mb_http_input',
'mb_http_output',
'mb_internal_encoding',
'mb_language',
'mb_list_encodings',
'mb_output_handler',
'mb_parse_str',
'mb_preferred_mime_name',
'mb_regex_encoding',
'mb_regex_set_options',
'mb_send_mail',
'mb_split',
'mb_strcut',
'mb_strimwidth',
'mb_stripos',
'mb_stristr',
'mb_strlen',
'mb_strpos',
'mb_strrchr',
'mb_strrichr',
'mb_strripos',
'mb_strrpos',
'mb_strstr',
'mb_strtolower',
'mb_strtoupper',
'mb_strwidth',
'mb_substitute_character',
'mb_substr_count',
'mb_substr'],
'MySQL': ['mysql_affected_rows',
'mysql_client_encoding',
'mysql_close',
'mysql_connect',
'mysql_create_db',
'mysql_data_seek',
'mysql_db_name',
'mysql_db_query',
'mysql_drop_db',
'mysql_errno',
'mysql_error',
'mysql_escape_string',
'mysql_fetch_array',
'mysql_fetch_assoc',
'mysql_fetch_field',
'mysql_fetch_lengths',
'mysql_fetch_object',
'mysql_fetch_row',
'mysql_field_flags',
'mysql_field_len',
'mysql_field_name',
'mysql_field_seek',
'mysql_field_table',
'mysql_field_type',
'mysql_free_result',
'mysql_get_client_info',
'mysql_get_host_info',
'mysql_get_proto_info',
'mysql_get_server_info',
'mysql_info',
'mysql_insert_id',
'mysql_list_dbs',
'mysql_list_fields',
'mysql_list_processes',
'mysql_list_tables',
'mysql_num_fields',
'mysql_num_rows',
'mysql_pconnect',
'mysql_ping',
'mysql_query',
'mysql_real_escape_string',
'mysql_result',
'mysql_select_db',
'mysql_set_charset',
'mysql_stat',
'mysql_tablename',
'mysql_thread_id',
'mysql_unbuffered_query'],
'NSAPI': ['nsapi_request_headers', 'nsapi_response_headers', 'nsapi_virtual'],
'Ncurses': ['ncurses_addch',
'ncurses_addchnstr',
'ncurses_addchstr',
'ncurses_addnstr',
'ncurses_addstr',
'ncurses_assume_default_colors',
'ncurses_attroff',
'ncurses_attron',
'ncurses_attrset',
'ncurses_baudrate',
'ncurses_beep',
'ncurses_bkgd',
'ncurses_bkgdset',
'ncurses_border',
'ncurses_bottom_panel',
'ncurses_can_change_color',
'ncurses_cbreak',
'ncurses_clear',
'ncurses_clrtobot',
'ncurses_clrtoeol',
'ncurses_color_content',
'ncurses_color_set',
'ncurses_curs_set',
'ncurses_def_prog_mode',
'ncurses_def_shell_mode',
'ncurses_define_key',
'ncurses_del_panel',
'ncurses_delay_output',
'ncurses_delch',
'ncurses_deleteln',
'ncurses_delwin',
'ncurses_doupdate',
'ncurses_echo',
'ncurses_echochar',
'ncurses_end',
'ncurses_erase',
'ncurses_erasechar',
'ncurses_filter',
'ncurses_flash',
'ncurses_flushinp',
'ncurses_getch',
'ncurses_getmaxyx',
'ncurses_getmouse',
'ncurses_getyx',
'ncurses_halfdelay',
'ncurses_has_colors',
'ncurses_has_ic',
'ncurses_has_il',
'ncurses_has_key',
'ncurses_hide_panel',
'ncurses_hline',
'ncurses_inch',
'ncurses_init_color',
'ncurses_init_pair',
'ncurses_init',
'ncurses_insch',
'ncurses_insdelln',
'ncurses_insertln',
'ncurses_insstr',
'ncurses_instr',
'ncurses_isendwin',
'ncurses_keyok',
'ncurses_keypad',
'ncurses_killchar',
'ncurses_longname',
'ncurses_meta',
'ncurses_mouse_trafo',
'ncurses_mouseinterval',
'ncurses_mousemask',
'ncurses_move_panel',
'ncurses_move',
'ncurses_mvaddch',
'ncurses_mvaddchnstr',
'ncurses_mvaddchstr',
'ncurses_mvaddnstr',
'ncurses_mvaddstr',
'ncurses_mvcur',
'ncurses_mvdelch',
'ncurses_mvgetch',
'ncurses_mvhline',
'ncurses_mvinch',
'ncurses_mvvline',
'ncurses_mvwaddstr',
'ncurses_napms',
'ncurses_new_panel',
'ncurses_newpad',
'ncurses_newwin',
'ncurses_nl',
'ncurses_nocbreak',
'ncurses_noecho',
'ncurses_nonl',
'ncurses_noqiflush',
'ncurses_noraw',
'ncurses_pair_content',
'ncurses_panel_above',
'ncurses_panel_below',
'ncurses_panel_window',
'ncurses_pnoutrefresh',
'ncurses_prefresh',
'ncurses_putp',
'ncurses_qiflush',
'ncurses_raw',
'ncurses_refresh',
'ncurses_replace_panel',
'ncurses_reset_prog_mode',
'ncurses_reset_shell_mode',
'ncurses_resetty',
'ncurses_savetty',
'ncurses_scr_dump',
'ncurses_scr_init',
'ncurses_scr_restore',
'ncurses_scr_set',
'ncurses_scrl',
'ncurses_show_panel',
'ncurses_slk_attr',
'ncurses_slk_attroff',
'ncurses_slk_attron',
'ncurses_slk_attrset',
'ncurses_slk_clear',
'ncurses_slk_color',
'ncurses_slk_init',
'ncurses_slk_noutrefresh',
'ncurses_slk_refresh',
'ncurses_slk_restore',
'ncurses_slk_set',
'ncurses_slk_touch',
'ncurses_standend',
'ncurses_standout',
'ncurses_start_color',
'ncurses_termattrs',
'ncurses_termname',
'ncurses_timeout',
'ncurses_top_panel',
'ncurses_typeahead',
'ncurses_ungetch',
'ncurses_ungetmouse',
'ncurses_update_panels',
'ncurses_use_default_colors',
'ncurses_use_env',
'ncurses_use_extended_names',
'ncurses_vidattr',
'ncurses_vline',
'ncurses_waddch',
'ncurses_waddstr',
'ncurses_wattroff',
'ncurses_wattron',
'ncurses_wattrset',
'ncurses_wborder',
'ncurses_wclear',
'ncurses_wcolor_set',
'ncurses_werase',
'ncurses_wgetch',
'ncurses_whline',
'ncurses_wmouse_trafo',
'ncurses_wmove',
'ncurses_wnoutrefresh',
'ncurses_wrefresh',
'ncurses_wstandend',
'ncurses_wstandout',
'ncurses_wvline'],
'Network': ['checkdnsrr',
'closelog',
'define_syslog_variables',
'dns_check_record',
'dns_get_mx',
'dns_get_record',
'fsockopen',
'gethostbyaddr',
'gethostbyname',
'gethostbynamel'],
'Newt': ['newt_bell',
'newt_button_bar',
'newt_button',
'newt_centered_window',
'newt_checkbox_get_value',
'newt_checkbox_set_flags',
'newt_checkbox_set_value',
'newt_checkbox_tree_add_item',
'newt_checkbox_tree_find_item',
'newt_checkbox_tree_get_current',
'newt_checkbox_tree_get_entry_value',
'newt_checkbox_tree_get_multi_selection',
'newt_checkbox_tree_get_selection',
'newt_checkbox_tree_multi',
'newt_checkbox_tree_set_current',
'newt_checkbox_tree_set_entry_value',
'newt_checkbox_tree_set_entry',
'newt_checkbox_tree_set_width',
'newt_checkbox_tree',
'newt_checkbox',
'newt_clear_key_buffer'],
'OAuth': ['oauth_get_sbs', 'oauth_urlencode'],
'OCI8': ['oci_bind_array_by_name',
'oci_bind_by_name',
'oci_cancel',
'oci_close',
'oci_commit',
'oci_connect',
'oci_define_by_name',
'oci_error',
'oci_execute',
'oci_fetch_all',
'oci_fetch_array',
'oci_fetch_assoc',
'oci_fetch_object',
'oci_fetch_row',
'oci_fetch',
'oci_field_is_null',
'oci_field_name',
'oci_field_precision',
'oci_field_scale',
'oci_field_size',
'oci_field_type_raw',
'oci_field_type',
'oci_free_statement',
'oci_internal_debug',
'oci_lob_copy',
'oci_lob_is_equal',
'oci_new_collection',
'oci_new_connect',
'oci_new_cursor',
'oci_new_descriptor',
'oci_num_fields',
'oci_num_rows',
'oci_parse',
'oci_password_change',
'oci_pconnect',
'oci_result',
'oci_rollback',
'oci_server_version',
'oci_set_action',
'oci_set_client_identifier',
'oci_set_client_info',
'oci_set_edition',
'oci_set_module_name',
'oci_set_prefetch',
'oci_statement_type'],
'ODBC': ['odbc_autocommit',
'odbc_binmode',
'odbc_close_all',
'odbc_close',
'odbc_columnprivileges',
'odbc_columns',
'odbc_commit',
'odbc_connect',
'odbc_cursor',
'odbc_data_source',
'odbc_do',
'odbc_error',
'odbc_errormsg',
'odbc_exec',
'odbc_execute',
'odbc_fetch_array',
'odbc_fetch_into',
'odbc_fetch_object',
'odbc_fetch_row',
'odbc_field_len',
'odbc_field_name',
'odbc_field_num',
'odbc_field_precision',
'odbc_field_scale',
'odbc_field_type',
'odbc_foreignkeys',
'odbc_free_result',
'odbc_gettypeinfo',
'odbc_longreadlen',
'odbc_next_result',
'odbc_num_fields',
'odbc_num_rows',
'odbc_pconnect',
'odbc_prepare',
'odbc_primarykeys',
'odbc_procedurecolumns',
'odbc_procedures',
'odbc_result_all',
'odbc_result',
'odbc_rollback',
'odbc_setoption',
'odbc_specialcolumns',
'odbc_statistics',
'odbc_tableprivileges',
'odbc_tables'],
'Object Aggregation': ['aggregate_info',
'aggregate_methods_by_list',
'aggregate_methods_by_regexp'],
'Object overloading': ['overload'],
'OpenAL': ['openal_buffer_create',
'openal_buffer_data',
'openal_buffer_destroy',
'openal_buffer_get',
'openal_buffer_loadwav',
'openal_context_create',
'openal_context_current',
'openal_context_destroy',
'openal_context_process',
'openal_context_suspend',
'openal_device_close',
'openal_device_open',
'openal_listener_get',
'openal_listener_set',
'openal_source_create',
'openal_source_destroy',
'openal_source_get',
'openal_source_pause',
'openal_source_play',
'openal_source_rewind',
'openal_source_set',
'openal_source_stop',
'openal_stream'],
'OpenSSL': ['openssl_csr_export_to_file',
'openssl_csr_export',
'openssl_csr_get_public_key',
'openssl_csr_get_subject',
'openssl_csr_new',
'openssl_csr_sign',
'openssl_decrypt',
'openssl_dh_compute_key',
'openssl_digest',
'openssl_encrypt',
'openssl_error_string',
'openssl_free_key',
'openssl_get_cipher_methods',
'openssl_get_md_methods',
'openssl_get_privatekey',
'openssl_get_publickey',
'openssl_open',
'openssl_pkcs12_export_to_file',
'openssl_pkcs12_export',
'openssl_pkcs12_read',
'openssl_pkcs7_decrypt',
'openssl_pkcs7_encrypt',
'openssl_pkcs7_sign',
'openssl_pkcs7_verify',
'openssl_pkey_export_to_file',
'openssl_pkey_export',
'openssl_pkey_free',
'openssl_pkey_get_details',
'openssl_pkey_get_private',
'openssl_pkey_get_public',
'openssl_pkey_new',
'openssl_private_decrypt',
'openssl_private_encrypt',
'openssl_public_decrypt',
'openssl_public_encrypt',
'openssl_random_pseudo_bytes',
'openssl_seal',
'openssl_sign',
'openssl_verify',
'openssl_x509_check_private_key',
'openssl_x509_checkpurpose',
'openssl_x509_export_to_file',
'openssl_x509_export',
'openssl_x509_free',
'openssl_x509_parse',
'openssl_x509_read'],
'Output Control': ['flush',
'ob_clean',
'ob_end_clean',
'ob_end_flush',
'ob_flush',
'ob_get_clean',
'ob_get_contents',
'ob_get_flush',
'ob_get_length',
'ob_get_level',
'ob_get_status',
'ob_gzhandler',
'ob_implicit_flush',
'ob_list_handlers',
'ob_start',
'output_add_rewrite_var',
'output_reset_rewrite_vars'],
'Ovrimos SQL': ['ovrimos_close',
'ovrimos_commit',
'ovrimos_connect',
'ovrimos_cursor',
'ovrimos_exec',
'ovrimos_execute',
'ovrimos_fetch_into',
'ovrimos_fetch_row',
'ovrimos_field_len',
'ovrimos_field_name',
'ovrimos_field_num',
'ovrimos_field_type',
'ovrimos_free_result',
'ovrimos_longreadlen',
'ovrimos_num_fields',
'ovrimos_num_rows',
'ovrimos_prepare',
'ovrimos_result_all',
'ovrimos_result',
'ovrimos_rollback'],
'PCNTL': ['pcntl_alarm',
'pcntl_exec',
'pcntl_fork',
'pcntl_getpriority',
'pcntl_setpriority',
'pcntl_signal_dispatch',
'pcntl_signal',
'pcntl_sigprocmask',
'pcntl_sigtimedwait',
'pcntl_sigwaitinfo',
'pcntl_wait',
'pcntl_waitpid',
'pcntl_wexitstatus',
'pcntl_wifexited',
'pcntl_wifsignaled',
'pcntl_wifstopped',
'pcntl_wstopsig',
'pcntl_wtermsig'],
'PCRE': ['preg_filter',
'preg_grep',
'preg_last_error',
'preg_match_all',
'preg_match',
'preg_quote',
'preg_replace_callback',
'preg_replace',
'preg_split'],
'PDF': ['PDF_activate_item',
'PDF_add_annotation',
'PDF_add_bookmark',
'PDF_add_launchlink',
'PDF_add_locallink',
'PDF_add_nameddest',
'PDF_add_note',
'PDF_add_outline',
'PDF_add_pdflink',
'PDF_add_table_cell',
'PDF_add_textflow',
'PDF_add_thumbnail',
'PDF_add_weblink',
'PDF_arc',
'PDF_arcn',
'PDF_attach_file',
'PDF_begin_document',
'PDF_begin_font',
'PDF_begin_glyph',
'PDF_begin_item',
'PDF_begin_layer',
'PDF_begin_page_ext',
'PDF_begin_page',
'PDF_begin_pattern',
'PDF_begin_template_ext',
'PDF_begin_template',
'PDF_circle',
'PDF_clip',
'PDF_close_image',
'PDF_close_pdi_page',
'PDF_close_pdi',
'PDF_close',
'PDF_closepath_fill_stroke',
'PDF_closepath_stroke',
'PDF_closepath',
'PDF_concat',
'PDF_continue_text',
'PDF_create_3dview',
'PDF_create_action',
'PDF_create_annotation',
'PDF_create_bookmark',
'PDF_create_field',
'PDF_create_fieldgroup',
'PDF_create_gstate',
'PDF_create_pvf',
'PDF_create_textflow',
'PDF_curveto',
'PDF_define_layer',
'PDF_delete_pvf',
'PDF_delete_table',
'PDF_delete_textflow',
'PDF_delete',
'PDF_encoding_set_char',
'PDF_end_document',
'PDF_end_font',
'PDF_end_glyph',
'PDF_end_item',
'PDF_end_layer',
'PDF_end_page_ext',
'PDF_end_page',
'PDF_end_pattern',
'PDF_end_template',
'PDF_endpath',
'PDF_fill_imageblock',
'PDF_fill_pdfblock',
'PDF_fill_stroke',
'PDF_fill_textblock',
'PDF_fill',
'PDF_findfont',
'PDF_fit_image',
'PDF_fit_pdi_page',
'PDF_fit_table',
'PDF_fit_textflow',
'PDF_fit_textline',
'PDF_get_apiname',
'PDF_get_buffer',
'PDF_get_errmsg',
'PDF_get_errnum',
'PDF_get_font',
'PDF_get_fontname',
'PDF_get_fontsize',
'PDF_get_image_height',
'PDF_get_image_width',
'PDF_get_majorversion',
'PDF_get_minorversion',
'PDF_get_parameter',
'PDF_get_pdi_parameter',
'PDF_get_pdi_value',
'PDF_get_value',
'PDF_info_font',
'PDF_info_matchbox',
'PDF_info_table',
'PDF_info_textflow',
'PDF_info_textline',
'PDF_initgraphics',
'PDF_lineto',
'PDF_load_3ddata',
'PDF_load_font',
'PDF_load_iccprofile',
'PDF_load_image',
'PDF_makespotcolor',
'PDF_moveto',
'PDF_new',
'PDF_open_ccitt',
'PDF_open_file',
'PDF_open_gif',
'PDF_open_image_file',
'PDF_open_image',
'PDF_open_jpeg',
'PDF_open_memory_image',
'PDF_open_pdi_document',
'PDF_open_pdi_page',
'PDF_open_pdi',
'PDF_open_tiff',
'PDF_pcos_get_number',
'PDF_pcos_get_stream',
'PDF_pcos_get_string',
'PDF_place_image',
'PDF_place_pdi_page',
'PDF_process_pdi',
'PDF_rect',
'PDF_restore',
'PDF_resume_page',
'PDF_rotate',
'PDF_save',
'PDF_scale',
'PDF_set_border_color',
'PDF_set_border_dash',
'PDF_set_border_style',
'PDF_set_char_spacing',
'PDF_set_duration',
'PDF_set_gstate',
'PDF_set_horiz_scaling',
'PDF_set_info_author',
'PDF_set_info_creator',
'PDF_set_info_keywords',
'PDF_set_info_subject',
'PDF_set_info_title',
'PDF_set_info',
'PDF_set_layer_dependency',
'PDF_set_leading',
'PDF_set_parameter',
'PDF_set_text_matrix',
'PDF_set_text_pos',
'PDF_set_text_rendering',
'PDF_set_text_rise',
'PDF_set_value',
'PDF_set_word_spacing',
'PDF_setcolor',
'PDF_setdash',
'PDF_setdashpattern',
'PDF_setflat',
'PDF_setfont',
'PDF_setgray_fill',
'PDF_setgray_stroke',
'PDF_setgray',
'PDF_setlinecap',
'PDF_setlinejoin',
'PDF_setlinewidth',
'PDF_setmatrix',
'PDF_setmiterlimit',
'PDF_setpolydash',
'PDF_setrgbcolor_fill',
'PDF_setrgbcolor_stroke',
'PDF_setrgbcolor',
'PDF_shading_pattern',
'PDF_shading',
'PDF_shfill',
'PDF_show_boxed',
'PDF_show_xy',
'PDF_show',
'PDF_skew',
'PDF_stringwidth',
'PDF_stroke',
'PDF_suspend_page',
'PDF_translate',
'PDF_utf16_to_utf8',
'PDF_utf32_to_utf16',
'PDF_utf8_to_utf16'],
'PHP Options/Info': ['assert_options',
'assert',
'dl',
'extension_loaded',
'gc_collect_cycles',
'gc_disable',
'gc_enable',
'gc_enabled',
'get_cfg_var',
'get_current_user',
'get_defined_constants',
'get_extension_funcs',
'get_include_path',
'get_included_files',
'get_loaded_extensions',
'get_magic_quotes_gpc',
'get_magic_quotes_runtime',
'get_required_files',
'getenv',
'getlastmod',
'getmygid',
'getmyinode',
'getmypid',
'getmyuid',
'getopt',
'getrusage',
'ini_alter',
'ini_get_all',
'ini_get',
'ini_restore',
'ini_set',
'magic_quotes_runtime',
'memory_get_peak_usage',
'memory_get_usage',
'php_ini_loaded_file',
'php_ini_scanned_files',
'php_logo_guid',
'php_sapi_name',
'php_uname',
'phpcredits',
'phpinfo',
'phpversion',
'putenv',
'restore_include_path',
'set_include_path',
'set_magic_quotes_runtime',
'set_time_limit',
'sys_get_temp_dir',
'version_compare',
'zend_logo_guid',
'zend_thread_id',
'zend_version'],
'POSIX': ['posix_access',
'posix_ctermid',
'posix_errno',
'posix_get_last_error',
'posix_getcwd',
'posix_getegid',
'posix_geteuid',
'posix_getgid',
'posix_getgrgid',
'posix_getgrnam',
'posix_getgroups',
'posix_getlogin',
'posix_getpgid',
'posix_getpgrp',
'posix_getpid',
'posix_getppid',
'posix_getpwnam',
'posix_getpwuid',
'posix_getrlimit',
'posix_getsid',
'posix_getuid',
'posix_initgroups',
'posix_isatty',
'posix_kill',
'posix_mkfifo',
'posix_mknod',
'posix_setegid',
'posix_seteuid',
'posix_setgid',
'posix_setpgid',
'posix_setsid',
'posix_setuid',
'posix_strerror',
'posix_times',
'posix_ttyname',
'posix_uname'],
'POSIX Regex': ['ereg_replace',
'ereg',
'eregi_replace',
'eregi',
'split',
'spliti',
'sql_regcase'],
'PS': ['ps_add_bookmark',
'ps_add_launchlink',
'ps_add_locallink',
'ps_add_note',
'ps_add_pdflink',
'ps_add_weblink',
'ps_arc',
'ps_arcn',
'ps_begin_page',
'ps_begin_pattern',
'ps_begin_template',
'ps_circle',
'ps_clip',
'ps_close_image',
'ps_close',
'ps_closepath_stroke',
'ps_closepath',
'ps_continue_text',
'ps_curveto',
'ps_delete',
'ps_end_page',
'ps_end_pattern',
'ps_end_template',
'ps_fill_stroke',
'ps_fill',
'ps_findfont',
'ps_get_buffer',
'ps_get_parameter',
'ps_get_value',
'ps_hyphenate',
'ps_include_file',
'ps_lineto',
'ps_makespotcolor',
'ps_moveto',
'ps_new',
'ps_open_file',
'ps_open_image_file',
'ps_open_image',
'ps_open_memory_image',
'ps_place_image',
'ps_rect',
'ps_restore',
'ps_rotate',
'ps_save',
'ps_scale',
'ps_set_border_color',
'ps_set_border_dash',
'ps_set_border_style',
'ps_set_info',
'ps_set_parameter',
'ps_set_text_pos',
'ps_set_value',
'ps_setcolor',
'ps_setdash',
'ps_setflat',
'ps_setfont',
'ps_setgray',
'ps_setlinecap',
'ps_setlinejoin',
'ps_setlinewidth',
'ps_setmiterlimit',
'ps_setoverprintmode',
'ps_setpolydash',
'ps_shading_pattern',
'ps_shading',
'ps_shfill',
'ps_show_boxed',
'ps_show_xy2',
'ps_show_xy',
'ps_show2',
'ps_show',
'ps_string_geometry',
'ps_stringwidth',
'ps_stroke',
'ps_symbol_name',
'ps_symbol_width',
'ps_symbol',
'ps_translate'],
'Paradox': ['px_close',
'px_create_fp',
'px_date2string',
'px_delete_record',
'px_delete',
'px_get_field',
'px_get_info',
'px_get_parameter',
'px_get_record',
'px_get_schema',
'px_get_value',
'px_insert_record',
'px_new',
'px_numfields',
'px_numrecords',
'px_open_fp',
'px_put_record',
'px_retrieve_record',
'px_set_blob_file',
'px_set_parameter',
'px_set_tablename',
'px_set_targetencoding',
'px_set_value',
'px_timestamp2string',
'px_update_record'],
'Parsekit': ['parsekit_compile_file',
'parsekit_compile_string',
'parsekit_func_arginfo'],
'PostgreSQL': ['pg_affected_rows',
'pg_cancel_query',
'pg_client_encoding',
'pg_close',
'pg_connect',
'pg_connection_busy',
'pg_connection_reset',
'pg_connection_status',
'pg_convert',
'pg_copy_from',
'pg_copy_to',
'pg_dbname',
'pg_delete',
'pg_end_copy',
'pg_escape_bytea',
'pg_escape_string',
'pg_execute',
'pg_fetch_all_columns',
'pg_fetch_all',
'pg_fetch_array',
'pg_fetch_assoc',
'pg_fetch_object',
'pg_fetch_result',
'pg_fetch_row',
'pg_field_is_null',
'pg_field_name',
'pg_field_num',
'pg_field_prtlen',
'pg_field_size',
'pg_field_table',
'pg_field_type_oid',
'pg_field_type',
'pg_free_result',
'pg_get_notify',
'pg_get_pid',
'pg_get_result',
'pg_host',
'pg_insert',
'pg_last_error',
'pg_last_notice',
'pg_last_oid',
'pg_lo_close',
'pg_lo_create',
'pg_lo_export',
'pg_lo_import',
'pg_lo_open',
'pg_lo_read_all',
'pg_lo_read',
'pg_lo_seek',
'pg_lo_tell',
'pg_lo_unlink',
'pg_lo_write',
'pg_meta_data',
'pg_num_fields',
'pg_num_rows',
'pg_options',
'pg_parameter_status',
'pg_pconnect',
'pg_ping',
'pg_port',
'pg_prepare'],
'Printer': ['printer_abort',
'printer_close',
'printer_create_brush',
'printer_create_dc',
'printer_create_font',
'printer_create_pen',
'printer_delete_brush',
'printer_delete_dc',
'printer_delete_font',
'printer_delete_pen',
'printer_draw_bmp',
'printer_draw_chord',
'printer_draw_elipse',
'printer_draw_line',
'printer_draw_pie',
'printer_draw_rectangle',
'printer_draw_roundrect',
'printer_draw_text',
'printer_end_doc',
'printer_end_page',
'printer_get_option',
'printer_list',
'printer_logical_fontheight',
'printer_open',
'printer_select_brush',
'printer_select_font',
'printer_select_pen',
'printer_set_option',
'printer_start_doc',
'printer_start_page',
'printer_write'],
'Program execution': ['escapeshellarg',
'escapeshellcmd',
'exec',
'passthru',
'proc_close',
'proc_get_status',
'proc_nice',
'proc_open',
'proc_terminate',
'shell_exec',
'system'],
'Pspell': ['pspell_add_to_personal',
'pspell_add_to_session',
'pspell_check',
'pspell_clear_session',
'pspell_config_create',
'pspell_config_data_dir',
'pspell_config_dict_dir',
'pspell_config_ignore',
'pspell_config_mode',
'pspell_config_personal',
'pspell_config_repl',
'pspell_config_runtogether',
'pspell_config_save_repl'],
'RPM Reader': ['rpm_close',
'rpm_get_tag',
'rpm_is_valid',
'rpm_open',
'rpm_version'],
'RRD': ['rrd_create',
'rrd_error',
'rrd_fetch',
'rrd_first',
'rrd_graph',
'rrd_info',
'rrd_last',
'rrd_lastupdate',
'rrd_restore',
'rrd_tune',
'rrd_update',
'rrd_xport'],
'Radius': ['radius_acct_open',
'radius_add_server',
'radius_auth_open',
'radius_close',
'radius_config',
'radius_create_request',
'radius_cvt_addr',
'radius_cvt_int',
'radius_cvt_string',
'radius_demangle_mppe_key',
'radius_demangle',
'radius_get_attr',
'radius_get_vendor_attr',
'radius_put_addr',
'radius_put_attr',
'radius_put_int',
'radius_put_string',
'radius_put_vendor_addr',
'radius_put_vendor_attr',
'radius_put_vendor_int',
'radius_put_vendor_string',
'radius_request_authenticator',
'radius_send_request',
'radius_server_secret',
'radius_strerror'],
'Rar': ['rar_wrapper_cache_stats'],
'Readline': ['readline_add_history',
'readline_callback_handler_install',
'readline_callback_handler_remove',
'readline_callback_read_char',
'readline_clear_history',
'readline_completion_function',
'readline_info',
'readline_list_history',
'readline_on_new_line',
'readline_read_history',
'readline_redisplay',
'readline_write_history',
'readline'],
'Recode': ['recode_file', 'recode_string', 'recode'],
'SNMP': ['snmp_get_quick_print',
'snmp_get_valueretrieval',
'snmp_read_mib',
'snmp_set_enum_print',
'snmp_set_oid_numeric_print',
'snmp_set_oid_output_format',
'snmp_set_quick_print',
'snmp_set_valueretrieval',
'snmp2_get',
'snmp2_getnext',
'snmp2_real_walk',
'snmp2_set',
'snmp2_walk',
'snmp3_get',
'snmp3_getnext',
'snmp3_real_walk',
'snmp3_set',
'snmp3_walk',
'snmpget',
'snmpgetnext',
'snmprealwalk',
'snmpset',
'snmpwalk',
'snmpwalkoid'],
'SOAP': ['is_soap_fault', 'use_soap_error_handler'],
'SPL': ['class_implements',
'class_parents',
'iterator_apply',
'iterator_count',
'iterator_to_array',
'spl_autoload_call',
'spl_autoload_extensions',
'spl_autoload_functions',
'spl_autoload_register',
'spl_autoload_unregister',
'spl_autoload',
'spl_classes',
'spl_object_hash'],
'SPPLUS': ['calcul_hmac', 'calculhmac', 'nthmac', 'signeurlpaiement'],
'SQLite': ['sqlite_array_query', 'sqlite_busy_timeout', 'sqlite_changes'],
'SSH2': ['ssh2_auth_hostbased_file',
'ssh2_auth_none',
'ssh2_auth_password',
'ssh2_auth_pubkey_file',
'ssh2_connect',
'ssh2_exec',
'ssh2_fetch_stream',
'ssh2_fingerprint',
'ssh2_methods_negotiated',
'ssh2_publickey_add',
'ssh2_publickey_init',
'ssh2_publickey_list',
'ssh2_publickey_remove',
'ssh2_scp_recv',
'ssh2_scp_send',
'ssh2_sftp_lstat',
'ssh2_sftp_mkdir',
'ssh2_sftp_readlink',
'ssh2_sftp_realpath',
'ssh2_sftp_rename',
'ssh2_sftp_rmdir',
'ssh2_sftp_stat',
'ssh2_sftp_symlink',
'ssh2_sftp_unlink',
'ssh2_sftp',
'ssh2_shell',
'ssh2_tunnel'],
'SVN': ['svn_add',
'svn_auth_get_parameter',
'svn_auth_set_parameter',
'svn_blame',
'svn_cat',
'svn_checkout',
'svn_cleanup',
'svn_client_version',
'svn_commit',
'svn_delete',
'svn_diff',
'svn_export',
'svn_fs_abort_txn',
'svn_fs_apply_text',
'svn_fs_begin_txn2',
'svn_fs_change_node_prop',
'svn_fs_check_path',
'svn_fs_contents_changed',
'svn_fs_copy',
'svn_fs_delete',
'svn_fs_dir_entries',
'svn_fs_file_contents',
'svn_fs_file_length',
'svn_fs_is_dir',
'svn_fs_is_file',
'svn_fs_make_dir',
'svn_fs_make_file',
'svn_fs_node_created_rev',
'svn_fs_node_prop',
'svn_fs_props_changed',
'svn_fs_revision_prop',
'svn_fs_revision_root',
'svn_fs_txn_root',
'svn_fs_youngest_rev',
'svn_import',
'svn_log',
'svn_ls',
'svn_mkdir',
'svn_repos_create',
'svn_repos_fs_begin_txn_for_commit',
'svn_repos_fs_commit_txn',
'svn_repos_fs',
'svn_repos_hotcopy',
'svn_repos_open',
'svn_repos_recover',
'svn_revert',
'svn_status',
'svn_update'],
'SWF': ['swf_actiongeturl',
'swf_actiongotoframe',
'swf_actiongotolabel',
'swf_actionnextframe',
'swf_actionplay',
'swf_actionprevframe',
'swf_actionsettarget',
'swf_actionstop',
'swf_actiontogglequality',
'swf_actionwaitforframe',
'swf_addbuttonrecord',
'swf_addcolor',
'swf_closefile',
'swf_definebitmap',
'swf_definefont',
'swf_defineline',
'swf_definepoly',
'swf_definerect',
'swf_definetext',
'swf_endbutton',
'swf_enddoaction',
'swf_endshape',
'swf_endsymbol',
'swf_fontsize',
'swf_fontslant',
'swf_fonttracking',
'swf_getbitmapinfo',
'swf_getfontinfo',
'swf_getframe',
'swf_labelframe',
'swf_lookat',
'swf_modifyobject',
'swf_mulcolor',
'swf_nextid',
'swf_oncondition',
'swf_openfile',
'swf_ortho2',
'swf_ortho',
'swf_perspective',
'swf_placeobject',
'swf_polarview',
'swf_popmatrix',
'swf_posround',
'swf_pushmatrix',
'swf_removeobject',
'swf_rotate',
'swf_scale',
'swf_setfont',
'swf_setframe',
'swf_shapearc',
'swf_shapecurveto3',
'swf_shapecurveto',
'swf_shapefillbitmapclip',
'swf_shapefillbitmaptile',
'swf_shapefilloff',
'swf_shapefillsolid',
'swf_shapelinesolid',
'swf_shapelineto',
'swf_shapemoveto',
'swf_showframe',
'swf_startbutton',
'swf_startdoaction',
'swf_startshape',
'swf_startsymbol',
'swf_textwidth',
'swf_translate',
'swf_viewport'],
'Semaphore': ['ftok',
'msg_get_queue',
'msg_queue_exists',
'msg_receive',
'msg_remove_queue',
'msg_send',
'msg_set_queue',
'msg_stat_queue',
'sem_acquire',
'sem_get',
'sem_release',
'sem_remove',
'shm_attach',
'shm_detach',
'shm_get_var',
'shm_has_var',
'shm_put_var',
'shm_remove_var',
'shm_remove'],
'Session': ['session_cache_expire',
'session_cache_limiter',
'session_commit',
'session_decode',
'session_destroy',
'session_encode',
'session_get_cookie_params',
'session_id',
'session_is_registered',
'session_module_name',
'session_name',
'session_regenerate_id',
'session_register',
'session_save_path',
'session_set_cookie_params',
'session_set_save_handler',
'session_start',
'session_unregister',
'session_unset',
'session_write_close'],
'Session PgSQL': ['session_pgsql_add_error',
'session_pgsql_get_error',
'session_pgsql_get_field',
'session_pgsql_reset',
'session_pgsql_set_field',
'session_pgsql_status'],
'Shared Memory': ['shmop_close',
'shmop_delete',
'shmop_open',
'shmop_read',
'shmop_size',
'shmop_write'],
'SimpleXML': ['simplexml_import_dom',
'simplexml_load_file',
'simplexml_load_string'],
'Socket': ['socket_accept',
'socket_bind',
'socket_clear_error',
'socket_close',
'socket_connect',
'socket_create_listen',
'socket_create_pair',
'socket_create',
'socket_get_option',
'socket_getpeername',
'socket_getsockname',
'socket_last_error',
'socket_listen',
'socket_read',
'socket_recv',
'socket_recvfrom',
'socket_select',
'socket_send',
'socket_sendto',
'socket_set_block',
'socket_set_nonblock',
'socket_set_option',
'socket_shutdown',
'socket_strerror',
'socket_write'],
'Solr': ['solr_get_version'],
'Statistic': ['stats_absolute_deviation',
'stats_cdf_beta',
'stats_cdf_binomial',
'stats_cdf_cauchy',
'stats_cdf_chisquare',
'stats_cdf_exponential',
'stats_cdf_f',
'stats_cdf_gamma',
'stats_cdf_laplace',
'stats_cdf_logistic',
'stats_cdf_negative_binomial',
'stats_cdf_noncentral_chisquare',
'stats_cdf_noncentral_f',
'stats_cdf_poisson',
'stats_cdf_t',
'stats_cdf_uniform',
'stats_cdf_weibull',
'stats_covariance',
'stats_den_uniform',
'stats_dens_beta',
'stats_dens_cauchy',
'stats_dens_chisquare',
'stats_dens_exponential',
'stats_dens_f',
'stats_dens_gamma',
'stats_dens_laplace',
'stats_dens_logistic',
'stats_dens_negative_binomial',
'stats_dens_normal',
'stats_dens_pmf_binomial',
'stats_dens_pmf_hypergeometric',
'stats_dens_pmf_poisson',
'stats_dens_t',
'stats_dens_weibull',
'stats_harmonic_mean',
'stats_kurtosis',
'stats_rand_gen_beta',
'stats_rand_gen_chisquare',
'stats_rand_gen_exponential',
'stats_rand_gen_f',
'stats_rand_gen_funiform',
'stats_rand_gen_gamma',
'stats_rand_gen_ibinomial_negative',
'stats_rand_gen_ibinomial',
'stats_rand_gen_int',
'stats_rand_gen_ipoisson',
'stats_rand_gen_iuniform',
'stats_rand_gen_noncenral_chisquare',
'stats_rand_gen_noncentral_f',
'stats_rand_gen_noncentral_t',
'stats_rand_gen_normal',
'stats_rand_gen_t',
'stats_rand_get_seeds',
'stats_rand_phrase_to_seeds',
'stats_rand_ranf',
'stats_rand_setall',
'stats_skew',
'stats_standard_deviation',
'stats_stat_binomial_coef',
'stats_stat_correlation',
'stats_stat_gennch',
'stats_stat_independent_t',
'stats_stat_innerproduct',
'stats_stat_noncentral_t',
'stats_stat_paired_t',
'stats_stat_percentile',
'stats_stat_powersum',
'stats_variance'],
'Stomp': ['stomp_connect_error', 'stomp_version'],
'Stream': ['set_socket_blocking',
'stream_bucket_append',
'stream_bucket_make_writeable',
'stream_bucket_new',
'stream_bucket_prepend',
'stream_context_create',
'stream_context_get_default',
'stream_context_get_options',
'stream_context_get_params',
'stream_context_set_default',
'stream_context_set_option',
'stream_context_set_params',
'stream_copy_to_stream',
'stream_encoding',
'stream_filter_append',
'stream_filter_prepend',
'stream_filter_register',
'stream_filter_remove',
'stream_get_contents',
'stream_get_filters',
'stream_get_line',
'stream_get_meta_data',
'stream_get_transports',
'stream_get_wrappers',
'stream_is_local',
'stream_notification_callback',
'stream_register_wrapper',
'stream_resolve_include_path',
'stream_select'],
'String': ['addcslashes',
'addslashes',
'bin2hex',
'chop',
'chr',
'chunk_split',
'convert_cyr_string',
'convert_uudecode',
'convert_uuencode',
'count_chars',
'crc32',
'crypt',
'echo',
'explode',
'fprintf',
'get_html_translation_table',
'hebrev',
'hebrevc',
'html_entity_decode',
'htmlentities',
'htmlspecialchars_decode',
'htmlspecialchars',
'implode',
'join',
'lcfirst',
'levenshtein',
'localeconv',
'ltrim',
'md5_file',
'md5',
'metaphone',
'money_format',
'nl_langinfo',
'nl2br',
'number_format',
'ord',
'parse_str',
'print',
'printf',
'quoted_printable_decode',
'quoted_printable_encode',
'quotemeta',
'rtrim',
'setlocale',
'sha1_file',
'sha1',
'similar_text',
'soundex',
'sprintf',
'sscanf',
'str_getcsv',
'str_ireplace',
'str_pad',
'str_repeat',
'str_replace',
'str_rot13',
'str_shuffle',
'str_split',
'str_word_count',
'strcasecmp',
'strchr',
'strcmp',
'strcoll',
'strcspn',
'strip_tags',
'stripcslashes',
'stripos',
'stripslashes',
'stristr',
'strlen',
'strnatcasecmp',
'strnatcmp',
'strncasecmp',
'strncmp',
'strpbrk',
'strpos',
'strrchr',
'strrev',
'strripos',
'strrpos',
'strspn'],
'Sybase': ['sybase_affected_rows',
'sybase_close',
'sybase_connect',
'sybase_data_seek',
'sybase_deadlock_retry_count',
'sybase_fetch_array',
'sybase_fetch_assoc',
'sybase_fetch_field',
'sybase_fetch_object',
'sybase_fetch_row',
'sybase_field_seek',
'sybase_free_result',
'sybase_get_last_message',
'sybase_min_client_severity',
'sybase_min_error_severity',
'sybase_min_message_severity',
'sybase_min_server_severity',
'sybase_num_fields',
'sybase_num_rows',
'sybase_pconnect',
'sybase_query',
'sybase_result',
'sybase_select_db',
'sybase_set_message_handler',
'sybase_unbuffered_query'],
'TCP': ['tcpwrap_check'],
'Tidy': ['ob_tidyhandler',
'tidy_access_count',
'tidy_config_count',
'tidy_error_count',
'tidy_get_error_buffer',
'tidy_get_output',
'tidy_load_config',
'tidy_reset_config',
'tidy_save_config',
'tidy_set_encoding',
'tidy_setopt',
'tidy_warning_count'],
'Tokenizer': ['token_get_all', 'token_name'],
'URL': ['base64_decode',
'base64_encode',
'get_headers',
'get_meta_tags',
'http_build_query',
'parse_url',
'rawurldecode',
'rawurlencode',
'urldecode',
'urlencode'],
'Variable handling': ['debug_zval_dump',
'doubleval',
'empty',
'floatval',
'get_defined_vars',
'get_resource_type',
'gettype',
'import_request_variables',
'intval',
'is_array',
'is_bool',
'is_callable',
'is_double',
'is_float',
'is_int',
'is_integer',
'is_long',
'is_null',
'is_numeric',
'is_object',
'is_real',
'is_resource',
'is_scalar',
'is_string',
'isset',
'print_r',
'serialize',
'settype',
'strval',
'unserialize',
'unset',
'var_dump',
'var_export'],
'W32api': ['w32api_deftype',
'w32api_init_dtype',
'w32api_invoke_function',
'w32api_register_function',
'w32api_set_call_method'],
'WDDX': ['wddx_add_vars',
'wddx_deserialize',
'wddx_packet_end',
'wddx_packet_start',
'wddx_serialize_value',
'wddx_serialize_vars',
'wddx_unserialize'],
'WinCache': ['wincache_fcache_fileinfo',
'wincache_fcache_meminfo',
'wincache_lock',
'wincache_ocache_fileinfo',
'wincache_ocache_meminfo',
'wincache_refresh_if_changed',
'wincache_rplist_fileinfo',
'wincache_rplist_meminfo',
'wincache_scache_info',
'wincache_scache_meminfo',
'wincache_ucache_add',
'wincache_ucache_cas',
'wincache_ucache_clear',
'wincache_ucache_dec',
'wincache_ucache_delete',
'wincache_ucache_exists',
'wincache_ucache_get',
'wincache_ucache_inc',
'wincache_ucache_info',
'wincache_ucache_meminfo',
'wincache_ucache_set',
'wincache_unlock'],
'XML Parser': ['utf8_decode'],
'XML-RPC': ['xmlrpc_decode_request',
'xmlrpc_decode',
'xmlrpc_encode_request',
'xmlrpc_encode',
'xmlrpc_get_type',
'xmlrpc_is_fault',
'xmlrpc_parse_method_descriptions',
'xmlrpc_server_add_introspection_data',
'xmlrpc_server_call_method',
'xmlrpc_server_create',
'xmlrpc_server_destroy',
'xmlrpc_server_register_introspection_callback',
'xmlrpc_server_register_method',
'xmlrpc_set_type'],
'XSLT (PHP4)': ['xslt_backend_info',
'xslt_backend_name',
'xslt_backend_version',
'xslt_create',
'xslt_errno',
'xslt_error',
'xslt_free',
'xslt_getopt',
'xslt_process',
'xslt_set_base',
'xslt_set_encoding',
'xslt_set_error_handler',
'xslt_set_log',
'xslt_set_object',
'xslt_set_sax_handler',
'xslt_set_sax_handlers',
'xslt_set_scheme_handler',
'xslt_set_scheme_handlers',
'xslt_setopt'],
'YAZ': ['yaz_addinfo',
'yaz_ccl_conf',
'yaz_ccl_parse',
'yaz_close',
'yaz_connect',
'yaz_database',
'yaz_element',
'yaz_errno',
'yaz_error',
'yaz_es_result',
'yaz_es',
'yaz_get_option',
'yaz_hits',
'yaz_itemorder',
'yaz_present',
'yaz_range',
'yaz_record',
'yaz_scan_result',
'yaz_scan',
'yaz_schema',
'yaz_search',
'yaz_set_option',
'yaz_sort',
'yaz_syntax',
'yaz_wait'],
'YP/NIS': ['yp_all',
'yp_cat',
'yp_err_string',
'yp_errno',
'yp_first',
'yp_get_default_domain',
'yp_master',
'yp_match',
'yp_next',
'yp_order'],
'Yaml': ['yaml_emit_file',
'yaml_emit',
'yaml_parse_file',
'yaml_parse_url',
'yaml_parse'],
'Zip': ['zip_close',
'zip_entry_close',
'zip_entry_compressedsize',
'zip_entry_compressionmethod',
'zip_entry_filesize',
'zip_entry_name',
'zip_entry_open',
'zip_entry_read',
'zip_open',
'zip_read'],
'Zlib': ['gzclose',
'gzcompress',
'gzdecode',
'gzdeflate',
'gzencode',
'gzeof',
'gzfile',
'gzgetc',
'gzgets',
'gzgetss',
'gzinflate',
'gzopen',
'gzpassthru',
'gzputs',
'gzread',
'gzrewind',
'gzseek',
'gztell',
'gzuncompress',
'gzwrite',
'readgzfile',
'zlib_get_coding_type'],
'bcompiler': ['bcompiler_load_exe',
'bcompiler_load',
'bcompiler_parse_class',
'bcompiler_read',
'bcompiler_write_class',
'bcompiler_write_constant',
'bcompiler_write_exe_footer',
'bcompiler_write_file',
'bcompiler_write_footer',
'bcompiler_write_function',
'bcompiler_write_functions_from_file',
'bcompiler_write_header',
'bcompiler_write_included_filename'],
'cURL': ['curl_close',
'curl_copy_handle',
'curl_errno',
'curl_error',
'curl_exec',
'curl_getinfo',
'curl_init',
'curl_multi_add_handle',
'curl_multi_close',
'curl_multi_exec',
'curl_multi_getcontent',
'curl_multi_info_read',
'curl_multi_init',
'curl_multi_remove_handle',
'curl_multi_select',
'curl_setopt_array',
'curl_setopt',
'curl_version'],
'chdb': ['chdb_create'],
'dBase': ['dbase_add_record',
'dbase_close',
'dbase_create',
'dbase_delete_record',
'dbase_get_header_info',
'dbase_get_record_with_names',
'dbase_get_record',
'dbase_numfields',
'dbase_numrecords',
'dbase_open',
'dbase_pack',
'dbase_replace_record'],
'dbx': ['dbx_close',
'dbx_compare',
'dbx_connect',
'dbx_error',
'dbx_escape_string',
'dbx_fetch_row'],
'filePro': ['filepro_fieldcount',
'filepro_fieldname',
'filepro_fieldtype',
'filepro_fieldwidth',
'filepro_retrieve',
'filepro_rowcount',
'filepro'],
'iconv': ['iconv_get_encoding',
'iconv_mime_decode_headers',
'iconv_mime_decode',
'iconv_mime_encode',
'iconv_set_encoding',
'iconv_strlen',
'iconv_strpos',
'iconv_strrpos',
'iconv_substr',
'iconv',
'ob_iconv_handler'],
'inclued': ['inclued_get_data'],
'intl': ['intl_error_name',
'intl_get_error_code',
'intl_get_error_message',
'intl_is_failure'],
'libxml': ['libxml_clear_errors',
'libxml_disable_entity_loader',
'libxml_get_errors',
'libxml_get_last_error',
'libxml_set_streams_context',
'libxml_use_internal_errors'],
'mSQL': ['msql_affected_rows',
'msql_close',
'msql_connect',
'msql_create_db',
'msql_createdb',
'msql_data_seek',
'msql_db_query',
'msql_dbname',
'msql_drop_db',
'msql_error',
'msql_fetch_array',
'msql_fetch_field',
'msql_fetch_object',
'msql_fetch_row',
'msql_field_flags',
'msql_field_len',
'msql_field_name',
'msql_field_seek',
'msql_field_table',
'msql_field_type',
'msql_fieldflags',
'msql_fieldlen',
'msql_fieldname',
'msql_fieldtable',
'msql_fieldtype',
'msql_free_result',
'msql_list_dbs',
'msql_list_fields',
'msql_list_tables',
'msql_num_fields',
'msql_num_rows',
'msql_numfields',
'msql_numrows',
'msql_pconnect',
'msql_query',
'msql_regcase',
'msql_result',
'msql_select_db',
'msql_tablename',
'msql'],
'mnoGoSearch': ['udm_add_search_limit',
'udm_alloc_agent_array',
'udm_alloc_agent',
'udm_api_version',
'udm_cat_list',
'udm_cat_path',
'udm_check_charset',
'udm_check_stored',
'udm_clear_search_limits',
'udm_close_stored',
'udm_crc32',
'udm_errno',
'udm_error',
'udm_find',
'udm_free_agent',
'udm_free_ispell_data',
'udm_free_res',
'udm_get_doc_count',
'udm_get_res_field',
'udm_get_res_param',
'udm_hash32',
'udm_load_ispell_data',
'udm_open_stored',
'udm_set_agent_param'],
'mqseries': ['mqseries_back',
'mqseries_begin',
'mqseries_close',
'mqseries_cmit',
'mqseries_conn',
'mqseries_connx',
'mqseries_disc',
'mqseries_get',
'mqseries_inq',
'mqseries_open',
'mqseries_put1',
'mqseries_put',
'mqseries_set',
'mqseries_strerror'],
'mysqlnd_qc': ['mysqlnd_qc_change_handler',
'mysqlnd_qc_clear_cache',
'mysqlnd_qc_get_cache_info',
'mysqlnd_qc_get_core_stats',
'mysqlnd_qc_get_handler',
'mysqlnd_qc_get_query_trace_log',
'mysqlnd_qc_set_user_handlers'],
'qtdom': ['qdom_error', 'qdom_tree'],
'runkit': ['runkit_class_adopt',
'runkit_class_emancipate',
'runkit_constant_add',
'runkit_constant_redefine',
'runkit_constant_remove',
'runkit_function_add',
'runkit_function_copy',
'runkit_function_redefine',
'runkit_function_remove',
'runkit_function_rename',
'runkit_import',
'runkit_lint_file',
'runkit_lint',
'runkit_method_add',
'runkit_method_copy',
'runkit_method_redefine',
'runkit_method_remove',
'runkit_method_rename',
'runkit_return_value_used',
'runkit_sandbox_output_handler',
'runkit_superglobals'],
'ssdeep': ['ssdeep_fuzzy_compare',
'ssdeep_fuzzy_hash_filename',
'ssdeep_fuzzy_hash'],
'vpopmail': ['vpopmail_add_alias_domain_ex',
'vpopmail_add_alias_domain',
'vpopmail_add_domain_ex',
'vpopmail_add_domain',
'vpopmail_add_user',
'vpopmail_alias_add',
'vpopmail_alias_del_domain',
'vpopmail_alias_del',
'vpopmail_alias_get_all',
'vpopmail_alias_get',
'vpopmail_auth_user',
'vpopmail_del_domain_ex',
'vpopmail_del_domain',
'vpopmail_del_user',
'vpopmail_error',
'vpopmail_passwd',
'vpopmail_set_user_quota'],
'win32ps': ['win32_ps_list_procs', 'win32_ps_stat_mem', 'win32_ps_stat_proc'],
'win32service': ['win32_continue_service',
'win32_create_service',
'win32_delete_service',
'win32_get_last_control_message',
'win32_pause_service',
'win32_query_service_status',
'win32_set_service_status',
'win32_start_service_ctrl_dispatcher',
'win32_start_service',
'win32_stop_service'],
'xattr': ['xattr_get',
'xattr_list',
'xattr_remove',
'xattr_set',
'xattr_supported'],
'xdiff': ['xdiff_file_bdiff_size',
'xdiff_file_bdiff',
'xdiff_file_bpatch',
'xdiff_file_diff_binary',
'xdiff_file_diff',
'xdiff_file_merge3',
'xdiff_file_patch_binary',
'xdiff_file_patch',
'xdiff_file_rabdiff',
'xdiff_string_bdiff_size',
'xdiff_string_bdiff',
'xdiff_string_bpatch',
'xdiff_string_diff_binary',
'xdiff_string_diff',
'xdiff_string_merge3',
'xdiff_string_patch_binary',
'xdiff_string_patch',
'xdiff_string_rabdiff']}
if __name__ == '__main__':
import glob
import os
import pprint
import re
import shutil
import tarfile
import urllib
PHP_MANUAL_URL = 'http://us3.php.net/distributions/manual/php_manual_en.tar.gz'
PHP_MANUAL_DIR = './php-chunked-xhtml/'
PHP_REFERENCE_GLOB = 'ref.*'
PHP_FUNCTION_RE = '<a href="function\..*?\.html">(.*?)</a>'
PHP_MODULE_RE = '<title>(.*?) Functions</title>'
def get_php_functions():
function_re = re.compile(PHP_FUNCTION_RE)
module_re = re.compile(PHP_MODULE_RE)
modules = {}
for file in get_php_references():
module = ''
for line in open(file):
if not module:
search = module_re.search(line)
if search:
module = search.group(1)
modules[module] = []
elif '<h2>Table of Contents</h2>' in line:
for match in function_re.finditer(line):
fn = match.group(1)
if '->' not in fn and '::' not in fn:
modules[module].append(fn)
# These are dummy manual pages, not actual functions
if module == 'PHP Options/Info':
modules[module].remove('main')
elif module == 'Filesystem':
modules[module].remove('delete')
if not modules[module]:
del modules[module]
break
return modules
def get_php_references():
download = urllib.urlretrieve(PHP_MANUAL_URL)
tar = tarfile.open(download[0])
tar.extractall()
tar.close()
for file in glob.glob("%s%s" % (PHP_MANUAL_DIR, PHP_REFERENCE_GLOB)):
yield file
os.remove(download[0])
def regenerate(filename, modules):
f = open(filename)
try:
content = f.read()
finally:
f.close()
header = content[:content.find('MODULES = {')]
footer = content[content.find("if __name__ == '__main__':"):]
f = open(filename, 'w')
f.write(header)
f.write('MODULES = %s\n\n' % pprint.pformat(modules))
f.write(footer)
f.close()
def run():
print '>> Downloading Function Index'
modules = get_php_functions()
total = sum(len(v) for v in modules.itervalues())
print '%d functions found' % total
regenerate(__file__, modules)
shutil.rmtree(PHP_MANUAL_DIR)
run()
|
bsd-3-clause
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
423,
8624,
10372,
272,
18294,
22935,
339,
961,
570,
14404,
314,
805,
1561,
436,
3932,
4621,
687,
314,
272,
3945,
80,
9248,
436,
12821,
6337,
14,
339,
4226,
440,
17355,
314,
30920,
24392,
1211,
701,
4926,
1,
339,
14750,
26,
314,
10152,
28183,
1192,
18794,
8298,
666,
1806,
2195,
1467,
21408,
1950,
14,
2793,
1133,
1255,
626,
737,
5629,
12,
675,
1467,
282,
1654,
8700,
13,
9,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
421,
199,
21194,
275,
791,
14,
7278,
356,
788,
3287,
846,
63,
912,
995,
199,
283,
1282,
35,
356,
788,
439,
67,
63,
525,
297,
268,
283,
439,
67,
63,
1393,
63,
2724,
297,
268,
283,
439,
67,
63,
1393,
63,
2724,
493,
297,
268,
283,
439,
67,
63,
1393,
63,
912,
297,
268,
283,
439,
67,
63,
1393,
63,
912,
493,
297,
268,
283,
439,
67,
63,
1637,
63,
815,
297,
268,
283,
439,
67,
63,
9765,
297,
268,
283,
439,
67,
63,
3584,
63,
1637,
297,
268,
283,
439,
67,
63,
2014,
63,
493,
297,
268,
283,
439,
67,
63,
7778,
297,
268,
283,
439,
67,
63,
4640,
63,
5559,
297,
268,
283,
439,
67,
63,
1807,
63,
493,
297,
268,
283,
439,
67,
63,
1807,
297,
268,
283,
439,
67,
63,
2444,
297,
268,
283,
439,
67,
63,
3535,
297,
268,
283,
439,
67,
63,
6559,
297,
268,
283,
439,
67,
63,
912,
63,
5559,
297,
268,
283,
439,
67,
63,
83,
391,
63,
815,
297,
268,
283,
439,
67,
63,
1617,
995,
199,
283,
1282,
36,
356,
788,
439,
68,
63,
20081,
297,
268,
283,
439,
68,
63,
1250,
2340,
297,
268,
283,
439,
68,
63,
429,
1778,
297,
268,
283,
439,
68,
63,
6958,
297,
268,
283,
439,
68,
63,
67,
293,
1151,
297,
268,
283,
439,
68,
63,
2724,
63,
1593,
63,
1224,
297,
268,
283,
439,
68,
63,
2724,
63,
18539,
63,
4435,
297,
268,
283,
439,
68,
63,
2724,
63,
7898,
63,
4435,
297,
268,
283,
439,
68,
63,
7878,
297,
268,
283,
439,
68,
63,
362,
63,
2682,
63,
7450,
297,
268,
283,
439,
68,
63,
409,
63,
80,
14979,
63,
3446,
297,
268,
283,
439,
68,
63,
409,
63,
1730,
63,
3446,
63,
3450,
297,
268,
283,
439,
68,
63,
409,
63,
1730,
63,
3446,
297,
268,
283,
439,
68,
63,
409,
63,
1730,
297,
268,
283,
4415,
63,
1593,
297,
268,
283,
8165,
63,
1593,
995,
199,
283,
6985,
3274,
436,
5906,
603,
588,
81,
317,
356,
788,
23726,
81,
317,
63,
3409,
63,
635,
297,
3521,
283,
23726,
81,
317,
63,
3409,
63,
1099,
297,
3521,
283,
23726,
81,
317,
63,
1258,
63,
2991,
297,
3521,
283,
23726,
81,
317,
63,
2242,
297,
3521,
283,
23726,
81,
317,
63,
5993,
63,
15656,
63,
504,
63,
4133,
297,
3521,
283,
23726,
81,
317,
63,
5993,
63,
82,
1168,
63,
1122,
297,
3521,
283,
23726,
81,
317,
63,
4296,
63,
15656,
63,
504,
63,
4133,
297,
3521,
283,
23726,
81,
317,
63,
4296,
63,
82,
1168,
63,
1122,
297,
3521,
283,
23726,
81,
317,
63,
3765,
63,
875,
297,
3521,
283,
23726,
81,
317,
63,
2526,
297,
3521,
283,
23726,
81,
317,
63,
3535,
297,
3521,
283,
23726,
81,
317,
63,
362,
63,
2343,
297,
3521,
283,
23726,
81,
317,
63,
4133,
63,
1131,
297,
3521,
283,
23726,
81,
317,
63,
635,
63,
835,
297,
3521,
283,
23726,
81,
317,
63,
3070,
297,
3521,
283,
23726,
81,
317,
63,
82,
1168,
63,
1122,
63,
3827,
297,
3521,
283,
23726,
81,
317,
63,
82,
1168,
63,
15944,
297,
3521,
283,
23726,
81,
317,
63,
82,
1168,
63,
1131,
63,
466,
297,
3521,
283,
23726,
81,
317,
63,
2254,
63,
2809,
63,
576,
297,
3521,
283,
23726,
81,
317,
63,
2254,
63,
1131,
297,
3521,
283,
23726,
81,
317,
63,
409,
63,
2992,
297,
3521,
283,
23726,
81,
317,
63,
12384,
63,
1131,
995,
199,
283,
28993,
356,
788,
3796,
63,
1739,
63,
14478,
297,
288,
283,
3796,
63,
362,
63,
3112,
297,
288,
283,
3796,
63,
362,
63,
1023,
297,
288,
283,
3796,
63,
12959,
297,
288,
283,
3796,
63,
3892,
63,
2302,
297,
288,
283,
3796,
63,
4610,
297,
288,
283,
3796,
63,
1069,
63,
2139,
297,
288,
283,
3796,
63,
3958,
63,
2593,
297,
288,
283,
3796,
63,
1310,
63,
2139,
297,
288,
283,
3796,
63,
261,
9072,
297,
288,
283,
362,
452,
2139,
297,
288,
283,
2065,
995,
199,
283,
3836,
356,
788,
1144,
63,
1461,
63,
498,
63,
2546,
297,
1779,
283,
1144,
63,
4604,
297,
1779,
283,
1144,
63,
13307,
297,
1779,
283,
1144,
63,
835,
63,
1459,
297,
1779,
283,
1144,
63,
3028,
63,
16824,
297,
1779,
283,
1144,
63,
3028,
63,
498,
297,
1779,
283,
1144,
63,
3028,
63,
85,
16824,
297,
1779,
283,
1144,
63,
3028,
63,
85,
498,
297,
1779,
283,
1144,
63,
3028,
297,
1779,
283,
1144,
63,
4498,
63,
1612,
297,
1779,
283,
1144,
63,
4498,
297,
1779,
283,
1144,
63,
1541,
297,
1779,
283,
1144,
63,
16114,
297,
1779,
283,
1144,
63,
23149,
63,
16824,
297,
1779,
283,
1144,
63,
23149,
63,
498,
297,
1779,
283,
1144,
63,
23149,
63,
85,
16824,
297,
1779,
283,
1144,
63,
23149,
63,
85,
498,
297,
1779,
283,
1144,
63,
23149,
297,
1779,
283,
1144,
63,
498,
63,
2444,
297,
1779,
283,
1144,
63,
1612,
297,
1779,
283,
1144,
63,
1130,
297,
1779,
283,
1144,
63,
5628,
63,
9931,
297,
1779,
283,
1144,
63,
5628,
297,
1779,
283,
1144,
63,
3029,
3191,
297,
1779,
283,
1144,
63,
6226,
297,
1779,
283,
1144,
63,
1935,
297,
1779,
283,
1144,
63,
2558,
297,
1779,
283,
1144,
63,
5335,
297,
1779,
283,
1144,
63,
3759,
297,
1779,
283,
1144,
63,
5270,
297,
1779,
283,
1144,
63,
1814,
63,
9931,
297,
1779,
283,
1144,
63,
1814,
297,
1779,
283,
1144,
63,
4471,
297,
1779,
283,
1144,
63,
1733,
297,
1779,
283,
1144,
63,
4723,
297,
1779,
283,
1144,
63,
5224,
297
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
272,
13277,
14,
12245,
423,
8624,
10372,
272,
18294,
22935,
339,
961,
570,
14404,
314,
805,
1561,
436,
3932,
4621,
687,
314,
272,
3945,
80,
9248,
436,
12821,
6337,
14,
339,
4226,
440,
17355,
314,
30920,
24392,
1211,
701,
4926,
1,
339,
14750,
26,
314,
10152,
28183,
1192,
18794,
8298,
666,
1806,
2195,
1467,
21408,
1950,
14,
2793,
1133,
1255,
626,
737,
5629,
12,
675,
1467,
282,
1654,
8700,
13,
9,
339,
520,
7307,
26,
1898,
8315,
13,
6965,
701,
314,
14493,
8099,
12,
1937,
10610,
14,
272,
520,
1682,
26,
6289,
12,
1937,
5113,
367,
2436,
14,
199,
624,
421,
199,
21194,
275,
791,
14,
7278,
356,
788,
3287,
846,
63,
912,
995,
199,
283,
1282,
35,
356,
788,
439,
67,
63,
525,
297,
268,
283,
439,
67,
63,
1393,
63,
2724,
297,
268,
283,
439,
67,
63,
1393,
63,
2724,
493,
297,
268,
283,
439,
67,
63,
1393,
63,
912,
297,
268,
283,
439,
67,
63,
1393,
63,
912,
493,
297,
268,
283,
439,
67,
63,
1637,
63,
815,
297,
268,
283,
439,
67,
63,
9765,
297,
268,
283,
439,
67,
63,
3584,
63,
1637,
297,
268,
283,
439,
67,
63,
2014,
63,
493,
297,
268,
283,
439,
67,
63,
7778,
297,
268,
283,
439,
67,
63,
4640,
63,
5559,
297,
268,
283,
439,
67,
63,
1807,
63,
493,
297,
268,
283,
439,
67,
63,
1807,
297,
268,
283,
439,
67,
63,
2444,
297,
268,
283,
439,
67,
63,
3535,
297,
268,
283,
439,
67,
63,
6559,
297,
268,
283,
439,
67,
63,
912,
63,
5559,
297,
268,
283,
439,
67,
63,
83,
391,
63,
815,
297,
268,
283,
439,
67,
63,
1617,
995,
199,
283,
1282,
36,
356,
788,
439,
68,
63,
20081,
297,
268,
283,
439,
68,
63,
1250,
2340,
297,
268,
283,
439,
68,
63,
429,
1778,
297,
268,
283,
439,
68,
63,
6958,
297,
268,
283,
439,
68,
63,
67,
293,
1151,
297,
268,
283,
439,
68,
63,
2724,
63,
1593,
63,
1224,
297,
268,
283,
439,
68,
63,
2724,
63,
18539,
63,
4435,
297,
268,
283,
439,
68,
63,
2724,
63,
7898,
63,
4435,
297,
268,
283,
439,
68,
63,
7878,
297,
268,
283,
439,
68,
63,
362,
63,
2682,
63,
7450,
297,
268,
283,
439,
68,
63,
409,
63,
80,
14979,
63,
3446,
297,
268,
283,
439,
68,
63,
409,
63,
1730,
63,
3446,
63,
3450,
297,
268,
283,
439,
68,
63,
409,
63,
1730,
63,
3446,
297,
268,
283,
439,
68,
63,
409,
63,
1730,
297,
268,
283,
4415,
63,
1593,
297,
268,
283,
8165,
63,
1593,
995,
199,
283,
6985,
3274,
436,
5906,
603,
588,
81,
317,
356,
788,
23726,
81,
317,
63,
3409,
63,
635,
297,
3521,
283,
23726,
81,
317,
63,
3409,
63,
1099,
297,
3521,
283,
23726,
81,
317,
63,
1258,
63,
2991,
297,
3521,
283,
23726,
81,
317,
63,
2242,
297,
3521,
283,
23726,
81,
317,
63,
5993,
63,
15656,
63,
504,
63,
4133,
297,
3521,
283,
23726,
81,
317,
63,
5993,
63,
82,
1168,
63,
1122,
297,
3521,
283,
23726,
81,
317,
63,
4296,
63,
15656,
63,
504,
63,
4133,
297,
3521,
283,
23726,
81,
317,
63,
4296,
63,
82,
1168,
63,
1122,
297,
3521,
283,
23726,
81,
317,
63,
3765,
63,
875,
297,
3521,
283,
23726,
81,
317,
63,
2526,
297,
3521,
283,
23726,
81,
317,
63,
3535,
297,
3521,
283,
23726,
81,
317,
63,
362,
63,
2343,
297,
3521,
283,
23726,
81,
317,
63,
4133,
63,
1131,
297,
3521,
283,
23726,
81,
317,
63,
635,
63,
835,
297,
3521,
283,
23726,
81,
317,
63,
3070,
297,
3521,
283,
23726,
81,
317,
63,
82,
1168,
63,
1122,
63,
3827,
297,
3521,
283,
23726,
81,
317,
63,
82,
1168,
63,
15944,
297,
3521,
283,
23726,
81,
317,
63,
82,
1168,
63,
1131,
63,
466,
297,
3521,
283,
23726,
81,
317,
63,
2254,
63,
2809,
63,
576,
297,
3521,
283,
23726,
81,
317,
63,
2254,
63,
1131,
297,
3521,
283,
23726,
81,
317,
63,
409,
63,
2992,
297,
3521,
283,
23726,
81,
317,
63,
12384,
63,
1131,
995,
199,
283,
28993,
356,
788,
3796,
63,
1739,
63,
14478,
297,
288,
283,
3796,
63,
362,
63,
3112,
297,
288,
283,
3796,
63,
362,
63,
1023,
297,
288,
283,
3796,
63,
12959,
297,
288,
283,
3796,
63,
3892,
63,
2302,
297,
288,
283,
3796,
63,
4610,
297,
288,
283,
3796,
63,
1069,
63,
2139,
297,
288,
283,
3796,
63,
3958,
63,
2593,
297,
288,
283,
3796,
63,
1310,
63,
2139,
297,
288,
283,
3796,
63,
261,
9072,
297,
288,
283,
362,
452,
2139,
297,
288,
283,
2065,
995,
199,
283,
3836,
356,
788,
1144,
63,
1461,
63,
498,
63,
2546,
297,
1779,
283,
1144,
63,
4604,
297,
1779,
283,
1144,
63,
13307,
297,
1779,
283,
1144,
63,
835,
63,
1459,
297,
1779,
283,
1144,
63,
3028,
63,
16824,
297,
1779,
283,
1144,
63,
3028,
63,
498,
297,
1779,
283,
1144,
63,
3028,
63,
85,
16824,
297,
1779,
283,
1144,
63,
3028,
63,
85,
498,
297,
1779,
283,
1144,
63,
3028,
297,
1779,
283,
1144,
63,
4498,
63,
1612,
297,
1779,
283,
1144,
63,
4498,
297,
1779,
283,
1144,
63,
1541,
297,
1779,
283,
1144,
63,
16114,
297,
1779,
283,
1144,
63,
23149,
63,
16824,
297,
1779,
283,
1144,
63,
23149,
63,
498,
297,
1779,
283,
1144,
63,
23149,
63,
85,
16824,
297,
1779,
283,
1144,
63,
23149,
63,
85,
498,
297,
1779,
283,
1144,
63,
23149,
297,
1779,
283,
1144,
63,
498,
63,
2444,
297,
1779,
283,
1144,
63,
1612,
297,
1779,
283,
1144,
63,
1130,
297,
1779,
283,
1144,
63,
5628,
63,
9931,
297,
1779,
283,
1144,
63,
5628,
297,
1779,
283,
1144,
63,
3029,
3191,
297,
1779,
283,
1144,
63,
6226,
297,
1779,
283,
1144,
63,
1935,
297,
1779,
283,
1144,
63,
2558,
297,
1779,
283,
1144,
63,
5335,
297,
1779,
283,
1144,
63,
3759,
297,
1779,
283,
1144,
63,
5270,
297,
1779,
283,
1144,
63,
1814,
63,
9931,
297,
1779,
283,
1144,
63,
1814,
297,
1779,
283,
1144,
63,
4471,
297,
1779,
283,
1144,
63,
1733,
297,
1779,
283,
1144,
63,
4723,
297,
1779,
283,
1144,
63,
5224,
297,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
xkmato/youtube-dl
|
youtube_dl/extractor/freesound.py
|
192
|
1392
|
from __future__ import unicode_literals
import re
from .common import InfoExtractor
class FreesoundIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?freesound\.org/people/([^/]+)/sounds/(?P<id>[^/]+)'
_TEST = {
'url': 'http://www.freesound.org/people/miklovan/sounds/194503/',
'md5': '12280ceb42c81f19a515c745eae07650',
'info_dict': {
'id': '194503',
'ext': 'mp3',
'title': 'gulls in the city.wav',
'uploader': 'miklovan',
'description': 'the sounds of seagulls in the city',
}
}
def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
music_id = mobj.group('id')
webpage = self._download_webpage(url, music_id)
title = self._html_search_regex(
r'<div id="single_sample_header">.*?<a href="#">(.+?)</a>',
webpage, 'music title', flags=re.DOTALL)
description = self._html_search_regex(
r'<div id="sound_description">(.*?)</div>', webpage, 'description',
fatal=False, flags=re.DOTALL)
return {
'id': music_id,
'title': title,
'url': self._og_search_property('audio', webpage, 'music url'),
'uploader': self._og_search_property('audio:artist', webpage, 'music uploader'),
'description': description,
}
|
unlicense
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
481,
5710,
1034,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
70,
5710,
1034,
4537,
1308,
15,
13562,
15,
7059,
15251,
2447,
14990,
83,
9448,
48,
28,
344,
26906,
3171,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
70,
5710,
1034,
14,
1308,
15,
13562,
15,
2664,
75,
320,
20662,
15,
14990,
83,
15,
10860,
15773,
3678,
267,
283,
1064,
21,
356,
283,
7507,
1257,
301,
66,
2260,
67,
2835,
70,
1167,
65,
28082,
67,
17007,
69,
3624,
21439,
1400,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
10860,
15773,
297,
288,
283,
832,
356,
283,
311,
19,
297,
288,
283,
1213,
356,
283,
71,
13072,
315,
314,
14492,
14,
19118,
297,
288,
283,
13671,
356,
283,
2664,
75,
320,
20662,
297,
288,
283,
1802,
356,
283,
1589,
20453,
83,
402,
542,
643,
13072,
315,
314,
14492,
297,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
30891,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
30891,
63,
344,
9,
267,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
3015,
1305,
628,
4780,
63,
3271,
63,
1291,
1743,
6697,
28,
65,
4369,
13476,
1743,
28149,
15939,
65,
4206,
288,
9248,
12,
283,
20544,
2538,
297,
3285,
29,
264,
14,
16504,
9,
267,
1369,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
3015,
1305,
628,
14990,
63,
1802,
1743,
17140,
15939,
3015,
4206,
9248,
12,
283,
1802,
297,
288,
14294,
29,
797,
12,
3285,
29,
264,
14,
16504,
9,
398,
372,
469,
288,
283,
344,
356,
30891,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
633,
356,
291,
423,
974,
63,
1733,
63,
1829,
360,
8130,
297,
9248,
12,
283,
20544,
1166,
659,
288,
283,
13671,
356,
291,
423,
974,
63,
1733,
63,
1829,
360,
8130,
26,
11215,
297,
9248,
12,
283,
20544,
25257,
659,
288,
283,
1802,
356,
1369,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
421,
199,
533,
481,
5710,
1034,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
1544,
20316,
70,
5710,
1034,
4537,
1308,
15,
13562,
15,
7059,
15251,
2447,
14990,
83,
9448,
48,
28,
344,
26906,
3171,
272,
485,
2864,
275,
469,
267,
283,
633,
356,
283,
1014,
921,
1544,
14,
70,
5710,
1034,
14,
1308,
15,
13562,
15,
2664,
75,
320,
20662,
15,
14990,
83,
15,
10860,
15773,
3678,
267,
283,
1064,
21,
356,
283,
7507,
1257,
301,
66,
2260,
67,
2835,
70,
1167,
65,
28082,
67,
17007,
69,
3624,
21439,
1400,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
10860,
15773,
297,
288,
283,
832,
356,
283,
311,
19,
297,
288,
283,
1213,
356,
283,
71,
13072,
315,
314,
14492,
14,
19118,
297,
288,
283,
13671,
356,
283,
2664,
75,
320,
20662,
297,
288,
283,
1802,
356,
283,
1589,
20453,
83,
402,
542,
643,
13072,
315,
314,
14492,
297,
267,
789,
272,
789,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
14208,
275,
295,
14,
1431,
8,
277,
423,
5600,
63,
2632,
12,
1166,
9,
267,
30891,
63,
344,
275,
14208,
14,
923,
360,
344,
358,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
633,
12,
30891,
63,
344,
9,
267,
2538,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
3015,
1305,
628,
4780,
63,
3271,
63,
1291,
1743,
6697,
28,
65,
4369,
13476,
1743,
28149,
15939,
65,
4206,
288,
9248,
12,
283,
20544,
2538,
297,
3285,
29,
264,
14,
16504,
9,
267,
1369,
275,
291,
423,
1360,
63,
1733,
63,
3821,
8,
288,
519,
7601,
3015,
1305,
628,
14990,
63,
1802,
1743,
17140,
15939,
3015,
4206,
9248,
12,
283,
1802,
297,
288,
14294,
29,
797,
12,
3285,
29,
264,
14,
16504,
9,
398,
372,
469,
288,
283,
344,
356,
30891,
63,
344,
12,
288,
283,
1213,
356,
2538,
12,
288,
283,
633,
356,
291,
423,
974,
63,
1733,
63,
1829,
360,
8130,
297,
9248,
12,
283,
20544,
1166,
659,
288,
283,
13671,
356,
291,
423,
974,
63,
1733,
63,
1829,
360,
8130,
26,
11215,
297,
9248,
12,
283,
20544,
25257,
659,
288,
283,
1802,
356,
1369,
12,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
matthew-brett/pymc
|
pymc/NormalApproximation.py
|
1
|
16647
|
# TODO: Test case for EM algorithm.
# TODO: Derivatives from the EM algorithm can't actually be used to compute the Hessian for the normal approx.
# Post-2.0-release:
# TODO: Think about what to do about int-valued stochastics.
# TODO: Allow constraints if fmin_l_bfgs_b is used.
__docformat__='reStructuredText'
__author__ = 'Anand Patil, anand.prabhakar.patil@gmail.com'
__all__ = ['NormApproxMu', 'NormApproxC', 'MAP', 'NormApprox']
from PyMCObjects import Stochastic, Potential
from Node import ZeroProbability
from Model import Model, Sampler
from numpy import zeros, inner, asmatrix, ndarray, reshape, shape, arange, matrix, where, diag, asarray, isnan, isinf, ravel, log, Inf
from numpy.random import normal
from numpy.linalg import solve
from utils import msqrt, check_type, round_array, logp_of_set
from copy import copy
try:
from scipy.optimize import fmin_ncg, fmin, fmin_powell, fmin_cg, fmin_bfgs, fmin_ncg, fmin_l_bfgs_b
from scipy import derivative
scipy_imported = True
except ImportError:
scipy_imported = False
class NormApproxMu(object):
"""
Returns the mean vector of some variables.
Usage: If p1 and p2 are array-valued stochastic variables and N is a
NormApprox or MAP object,
N.mu(p1,p2)
will give the approximate posterior mean of the ravelled, concatenated
values of p1 and p2.
"""
def __init__(self, owner):
self.owner = owner
def __getitem__(self, *stochastics):
if not self.owner.fitted:
raise ValueError, 'NormApprox object must be fitted before mu can be accessed.'
tot_len = 0
try:
for p in stochastics[0]:
pass
stochastic_tuple = stochastics[0]
except:
stochastic_tuple = stochastics
for p in stochastic_tuple:
tot_len += self.owner.stochastic_len[p]
mu = zeros(tot_len, dtype=float)
start_index = 0
for p in stochastic_tuple:
mu[start_index:(start_index + self.owner.stochastic_len[p])] = self.owner._mu[self.owner._slices[p]]
start_index += self.owner.stochastic_len[p]
return mu
class NormApproxC(object):
"""
Returns the covariance matrix of some variables.
Usage: If p1 and p2 are array-valued stochastic variables and N is a
NormApprox or MAP object,
N.C(p1,p2)
will give the approximate covariance matrix of the ravelled, concatenated
values of p1 and p2
"""
def __init__(self, owner):
self.owner = owner
def __getitem__(self, *stochastics):
if not self.owner.fitted:
raise ValueError, 'NormApprox object must be fitted before C can be accessed.'
tot_len = 0
try:
for p in stochastics[0]:
pass
stochastic_tuple = stochastics[0]
except:
stochastic_tuple = stochastics
for p in stochastic_tuple:
tot_len += self.owner.stochastic_len[p]
C = asmatrix(zeros((tot_len, tot_len)), dtype=float)
start_index1 = 0
for p1 in stochastic_tuple:
start_index2 = 0
for p2 in stochastic_tuple:
C[start_index1:(start_index1 + self.owner.stochastic_len[p1]), \
start_index2:(start_index2 + self.owner.stochastic_len[p2])] = \
self.owner._C[self.owner._slices[p1],self.owner._slices[p2]]
start_index2 += self.owner.stochastic_len[p2]
start_index1 += self.owner.stochastic_len[p1]
return C
class MAP(Model):
"""
N = MAP(input, eps=.001, diff_order = 5)
Sets all parameters to maximum a posteriori values.
Useful methods:
revert_to_max: Sets all stochastic variables to mean value under normal approximation
fit: Finds the normal approximation.
Useful attributes (after fit() is called):
logp: Returns the log-probability of the model
logp_at_max: Returns the maximum log-probability of the model
len: The number of free stochastic variables in the model ('k' in AIC and BIC)
data_len: The number of datapoints used ('n' in BIC)
AIC: Akaike's Information Criterion for the model
BIC: Bayesian Information Criterion for the model
:Arguments:
input: As for Model
eps: 'h' for computing numerical derivatives. May be a dictionary keyed by stochastic variable
as well as a scalar.
diff_order: The order of the approximation used to compute derivatives.
:SeeAlso: Model, EM, Sampler, scipy.optimize
"""
def __init__(self, input=None, eps=.001, diff_order = 5, verbose=None):
if not scipy_imported:
raise ImportError, 'Scipy must be installed to use NormApprox and MAP.'
Model.__init__(self, input, verbose=verbose)
# Allocate memory for internal traces and get stochastic slices
self._slices = {}
self.len = 0
self.stochastic_len = {}
self.fitted = False
self.stochastic_list = list(self.stochastics)
self.N_stochastics = len(self.stochastic_list)
self.stochastic_indices = []
self.stochastic_types = []
self.stochastic_type_dict = {}
for i in xrange(len(self.stochastic_list)):
stochastic = self.stochastic_list[i]
# Check types of all stochastics.
type_now = check_type(stochastic)[0]
self.stochastic_type_dict[stochastic] = type_now
if not type_now is float:
print "Warning: Stochastic " + stochastic.__name__ + "'s value is neither numerical nor array with " + \
"floating-point dtype. Recommend fitting method fmin (default)."
# Inspect shapes of all stochastics and create stochastic slices.
if isinstance(stochastic.value, ndarray):
self.stochastic_len[stochastic] = len(ravel(stochastic.value))
else:
self.stochastic_len[stochastic] = 1
self._slices[stochastic] = slice(self.len, self.len + self.stochastic_len[stochastic])
self.len += self.stochastic_len[stochastic]
# Record indices that correspond to each stochastic.
for j in range(len(ravel(stochastic.value))):
self.stochastic_indices.append((stochastic, j))
self.stochastic_types.append(type_now)
self.data_len = 0
for datum in self.observed_stochastics:
self.data_len += len(ravel(datum.value))
# Unpack step
self.eps = zeros(self.len,dtype=float)
if isinstance(eps,dict):
for stochastic in self.stochastics:
self.eps[self._slices[stochastic]] = eps[stochastic]
else:
self.eps[:] = eps
self.diff_order = diff_order
self._len_range = arange(self.len)
# Initialize gradient and Hessian matrix.
self.grad = zeros(self.len, dtype=float)
self.hess = asmatrix(zeros((self.len, self.len), dtype=float))
self._mu = None
# Initialize NormApproxMu object.
self.mu = NormApproxMu(self)
def func_for_diff(val, index):
"""
The function that gets passed to the derivatives.
"""
self[index] = val
return self.i_logp(index)
self.func_for_diff = func_for_diff
def fit(self, method = 'fmin', iterlim=1000, tol=.0001, verbose=0):
"""
N.fit(method='fmin', iterlim=1000, tol=.001):
Causes the normal approximation object to fit itself.
method: May be one of the following, from the scipy.optimize package:
-fmin_l_bfgs_b
-fmin_ncg
-fmin_cg
-fmin_powell
-fmin
"""
self.tol = tol
self.method = method
self.verbose = verbose
p = zeros(self.len,dtype=float)
for stochastic in self.stochastics:
p[self._slices[stochastic]] = ravel(stochastic.value)
if not self.method == 'newton':
if not scipy_imported:
raise ImportError, 'Scipy is required to use EM and NormApprox'
if self.verbose > 0:
def callback(p):
print 'Current log-probability : %f' %self.logp
else:
def callback(p):
pass
if self.method == 'fmin_ncg':
p=fmin_ncg( f = self.func,
x0 = p,
fprime = self.gradfunc,
fhess = self.hessfunc,
epsilon=self.eps,
maxiter=iterlim,
callback=callback,
avextol=tol,
disp=verbose)
elif self.method == 'fmin':
p=fmin( func = self.func,
x0=p,
callback=callback,
maxiter=iterlim,
ftol=tol,
disp=verbose)
elif self.method == 'fmin_powell':
p=fmin_powell( func = self.func,
x0=p,
callback=callback,
maxiter=iterlim,
ftol=tol,
disp=verbose)
elif self.method == 'fmin_cg':
p=fmin_cg( f = self.func, x0 = p,
fprime = self.gradfunc,
epsilon=self.eps,
callback=callback,
maxiter=iterlim,
gtol=tol,
disp=verbose)
elif self.method == 'fmin_l_bfgs_b':
p=fmin_l_bfgs_b(func = self.func,
x0 = p,
fprime = self.gradfunc,
epsilon = self.eps,
# callback=callback,
pgtol=tol,
iprint=verbose-1)[0]
else:
raise ValueError, 'Method unknown.'
self._set_stochastics(p)
self._mu = p
try:
self.logp_at_max = self.logp
except:
raise RuntimeError, 'Posterior probability optimization converged to value with zero probability.'
self.AIC = 2. * (self.len - self.logp_at_max) # 2k - 2 ln(L)
self.BIC = self.len * log(self.data_len) - 2. * self.logp_at_max # k ln(n) - 2 ln(L)
self.fitted = True
def func(self, p):
"""
The function that gets passed to the optimizers.
"""
self._set_stochastics(p)
try:
return -1. * self.logp
except ZeroProbability:
return Inf
def gradfunc(self, p):
"""
The gradient-computing function that gets passed to the optimizers,
if needed.
"""
self._set_stochastics(p)
for i in xrange(self.len):
self.grad[i] = self.diff(i)
return -1 * self.grad
def _set_stochastics(self, p):
for stochastic in self.stochastics:
if self.stochastic_type_dict[stochastic] is int:
stochastic.value = round_array(reshape(ravel(p)[self._slices[stochastic]],shape(stochastic.value)))
else:
stochastic.value = reshape(ravel(p)[self._slices[stochastic]],shape(stochastic.value))
def __setitem__(self, index, value):
p, i = self.stochastic_indices[index]
val = ravel(p.value).copy()
val[i] = value
p.value = reshape(val, shape(p.value))
def __getitem__(self, index):
p, i = self.stochastic_indices[index]
val = ravel(p.value)
return val[i]
def i_logp(self, index):
"""
Evaluates the log-probability of the Markov blanket of
a stochastic owning a particular index.
"""
all_relevant_stochastics = set()
p,i = self.stochastic_indices[index]
try:
return p.logp + logp_of_set(p.extended_children)
except ZeroProbability:
return -Inf
def diff(self, i, order=1):
"""
N.diff(i, order=1)
Derivative wrt index i to given order.
"""
old_val = copy(self[i])
d = derivative(func=self.func_for_diff, x0=old_val, dx=self.eps[i], n=order, args=[i], order=self.diff_order)
self[i] = old_val
return d
def diff2(self, i, j):
"""
N.diff2(i,j)
Mixed second derivative. Differentiates wrt both indices.
"""
old_val = copy(self[j])
if not self.stochastic_indices[i][0] in self.stochastic_indices[j][0].moral_neighbors:
return 0.
def diff_for_diff(val):
self[j] = val
return self.diff(i)
d = derivative(func=diff_for_diff, x0=old_val, dx=self.eps[j], n=1, order=self.diff_order)
self[j] = old_val
return d
def grad_and_hess(self):
"""
Computes self's gradient and Hessian. Used if the
optimization method for a NormApprox doesn't
use gradients and hessians, for instance fmin.
"""
for i in xrange(self.len):
di = self.diff(i)
self.grad[i] = di
self.hess[i,i] = self.diff(i,2)
if i < self.len - 1:
for j in xrange(i+1, self.len):
dij = self.diff2(i,j)
self.hess[i,j] = dij
self.hess[j,i] = dij
def hessfunc(self, p):
"""
The Hessian function that will be passed to the optimizer,
if needed.
"""
self._set_stochastics(p)
for i in xrange(self.len):
di = self.diff(i)
self.hess[i,i] = self.diff(i,2)
if i < self.len - 1:
for j in xrange(i+1, self.len):
dij = self.diff2(i,j)
self.hess[i,j] = dij
self.hess[j,i] = dij
return -1. * self.hess
def revert_to_max(self):
"""
N.revert_to_max()
Sets all N's stochastics to their MAP values.
"""
self._set_stochastics(self.mu)
class NormApprox(MAP, Sampler):
"""
N = NormApprox(input, db='ram', eps=.001, diff_order = 5, **kwds)
Normal approximation to the posterior of a model.
Useful methods:
draw: Draws values for all stochastic variables using normal approximation
revert_to_max: Sets all stochastic variables to mean value under normal approximation
fit: Finds the normal approximation.
Useful attributes (after fit() is called):
mu[p1, p2, ...]: Returns the posterior mean vector of stochastic variables p1, p2, ...
C[p1, p2, ...]: Returns the posterior covariance of stochastic variables p1, p2, ...
logp: Returns the log-probability of the model
logp_at_max: Returns the maximum log-probability of the model
len: The number of free stochastic variables in the model ('k' in AIC and BIC)
data_len: The number of datapoints used ('n' in BIC)
AIC: Akaike's Information Criterion for the model
BIC: Bayesian Information Criterion for the model
:Arguments:
input: As for Model
db: A database backend
eps: 'h' for computing numerical derivatives. May be a dictionary keyed by stochastic variable
as well as a scalar.
diff_order: The order of the approximation used to compute derivatives.
:SeeAlso: Model, EM, Sampler, scipy.optimize
"""
def __init__(self, input=None, db='ram', eps=.001, diff_order = 5, **kwds):
if not scipy_imported:
raise ImportError, 'Scipy must be installed to use NormApprox and MAP.'
MAP.__init__(self, input, eps, diff_order)
Sampler.__init__(self, input, db, reinit_model=False, **kwds)
self.C = NormApproxC(self)
def fit(self, *args, **kwargs):
MAP.fit(self, *args, **kwargs)
self.fitted = False
self.grad_and_hess()
self._C = -1. * self.hess.I
self._sig = msqrt(self._C).T
self.fitted = True
def draw(self):
"""
N.draw()
Sets all N's stochastics to random values drawn from
the normal approximation to the posterior.
"""
devs = normal(size=self._sig.shape[1])
p = inner(self._sig,devs) + self._mu
self._set_stochastics(p)
|
mit
|
[
3,
3254,
26,
1379,
1930,
367,
26512,
5563,
14,
199,
3,
3254,
26,
18674,
1003,
10661,
687,
314,
26512,
5563,
883,
1133,
5965,
506,
1202,
370,
4526,
314,
869,
21663,
367,
314,
3293,
14106,
14,
199,
199,
3,
7711,
13,
18,
14,
16,
13,
3221,
26,
199,
3,
3254,
26,
3868,
2292,
3595,
4052,
370,
886,
3595,
1109,
13,
16611,
26123,
335,
1810,
2932,
14,
199,
3,
3254,
26,
9812,
9565,
340,
289,
827,
63,
76,
63,
31372,
63,
66,
365,
1202,
14,
421,
199,
363,
21841,
363,
534,
264,
27486,
1872,
7,
199,
199,
363,
2502,
363,
275,
283,
2493,
460,
510,
2159,
76,
12,
376,
460,
14,
80,
14411,
72,
1151,
285,
14,
387,
2270,
32,
6799,
14,
957,
7,
199,
363,
452,
363,
275,
788,
15548,
13117,
8221,
16215,
297,
283,
15548,
25923,
8163,
297,
283,
5443,
297,
283,
15548,
13117,
8221,
418,
199,
199,
504,
1611,
45,
19561,
83,
492,
9785,
21913,
12,
4376,
9443,
199,
504,
5013,
492,
15708,
20122,
3616,
199,
504,
5822,
492,
5822,
12,
15227,
82,
199,
504,
2680,
492,
10136,
12,
6506,
12,
465,
3642,
12,
6800,
12,
21460,
12,
2215,
12,
20461,
12,
3634,
12,
2382,
12,
8348,
12,
24144,
12,
365,
4304,
12,
365,
4904,
12,
660,
1090,
12,
943,
12,
1010,
70,
199,
504,
2680,
14,
2355,
492,
3293,
199,
504,
2680,
14,
10096,
492,
14241,
199,
504,
3778,
492,
333,
5079,
12,
1104,
63,
466,
12,
6168,
63,
1144,
12,
943,
80,
63,
1618,
63,
409,
199,
504,
1331,
492,
1331,
199,
199,
893,
26,
272,
687,
7026,
14,
13416,
492,
289,
827,
63,
7966,
71,
12,
289,
827,
12,
289,
827,
63,
8278,
1697,
12,
289,
827,
63,
12595,
12,
289,
827,
63,
31372,
12,
289,
827,
63,
7966,
71,
12,
289,
827,
63,
76,
63,
31372,
63,
66,
272,
687,
7026,
492,
18883,
272,
7026,
63,
17932,
275,
715,
199,
2590,
3545,
26,
272,
7026,
63,
17932,
275,
756,
199,
199,
533,
20800,
13117,
8221,
16215,
8,
785,
304,
272,
408,
272,
1803,
314,
4615,
5477,
402,
2005,
2860,
14,
339,
11028,
26,
982,
299,
17,
436,
299,
18,
787,
1625,
13,
16611,
26123,
21913,
2860,
436,
653,
365,
282,
272,
20800,
13117,
8221,
503,
603,
1282,
909,
12,
339,
653,
14,
6553,
8,
80,
17,
12,
80,
18,
9,
339,
911,
8120,
314,
19917,
2086,
17514,
4615,
402,
314,
660,
1090,
1146,
12,
26271,
272,
1338,
402,
299,
17,
436,
299,
18,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
5771,
304,
267,
291,
14,
4597,
275,
5771,
339,
347,
636,
6095,
721,
277,
12,
627,
14308,
335,
1810,
2932,
304,
398,
340,
440,
291,
14,
4597,
14,
21903,
26,
288,
746,
1722,
12,
283,
15548,
13117,
8221,
909,
1471,
506,
26093,
2544,
8504,
883,
506,
13810,
3530,
398,
12657,
63,
552,
275,
378,
398,
862,
26,
288,
367,
299,
315,
26123,
335,
1810,
2932,
59,
16,
2189,
355,
986,
288,
26123,
21913,
63,
2960,
275,
26123,
335,
1810,
2932,
59,
16,
61,
267,
871,
26,
288,
26123,
21913,
63,
2960,
275,
26123,
335,
1810,
2932,
398,
367,
299,
315,
26123,
21913,
63,
2960,
26,
288,
12657,
63,
552,
847,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
61,
398,
8504,
275,
10136,
8,
13280,
63,
552,
12,
2152,
29,
1609,
9,
398,
1343,
63,
1080,
275,
378,
267,
367,
299,
315,
26123,
21913,
63,
2960,
26,
288,
8504,
59,
928,
63,
1080,
20334,
928,
63,
1080,
435,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
12457,
275,
291,
14,
4597,
423,
6553,
59,
277,
14,
4597,
423,
14865,
59,
80,
2677,
288,
1343,
63,
1080,
847,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
61,
398,
372,
8504,
421,
199,
533,
20800,
25923,
8163,
8,
785,
304,
272,
408,
272,
1803,
314,
13263,
3634,
402,
2005,
2860,
14,
339,
11028,
26,
982,
299,
17,
436,
299,
18,
787,
1625,
13,
16611,
26123,
21913,
2860,
436,
653,
365,
282,
272,
20800,
13117,
8221,
503,
603,
1282,
909,
12,
339,
653,
14,
35,
8,
80,
17,
12,
80,
18,
9,
339,
911,
8120,
314,
19917,
13263,
3634,
402,
314,
660,
1090,
1146,
12,
26271,
272,
1338,
402,
299,
17,
436,
299,
18,
272,
408,
272,
347,
636,
826,
721,
277,
12,
5771,
304,
267,
291,
14,
4597,
275,
5771,
339,
347,
636,
6095,
721,
277,
12,
627,
14308,
335,
1810,
2932,
304,
398,
340,
440,
291,
14,
4597,
14,
21903,
26,
288,
746,
1722,
12,
283,
15548,
13117,
8221,
909,
1471,
506,
26093,
2544,
445,
883,
506,
13810,
3530,
398,
12657,
63,
552,
275,
378,
398,
862,
26,
288,
367,
299,
315,
26123,
335,
1810,
2932,
59,
16,
2189,
355,
986,
288,
26123,
21913,
63,
2960,
275,
26123,
335,
1810,
2932,
59,
16,
61,
267,
871,
26,
288,
26123,
21913,
63,
2960,
275,
26123,
335,
1810,
2932,
398,
367,
299,
315,
26123,
21913,
63,
2960,
26,
288,
12657,
63,
552,
847,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
61,
398,
445,
275,
465,
3642,
8,
4250,
1332,
13280,
63,
552,
12,
12657,
63,
552,
1826,
2152,
29,
1609,
9,
398,
1343,
63,
1080,
17,
275,
378,
267,
367,
299,
17,
315,
26123,
21913,
63,
2960,
26,
288,
1343,
63,
1080,
18,
275,
378,
288,
367,
299,
18,
315,
26123,
21913,
63,
2960,
26,
355,
445,
59,
928,
63,
1080,
17,
20334,
928,
63,
1080,
17,
435,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
17,
2522,
971,
355,
1343,
63,
1080,
18,
20334,
928,
63,
1080,
18,
435,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
18,
12457,
275,
971,
355,
291,
14,
4597,
423,
35,
59,
277,
14,
4597,
423,
14865,
59,
80,
17,
467,
277,
14,
4597,
423,
14865,
59,
80,
18,
2677,
2234,
1343,
63,
1080,
18,
847,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
18,
61,
953,
1343,
63,
1080,
17,
847,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
17,
61,
398,
372,
445,
199,
199,
533,
603,
1282,
8,
1685,
304,
272,
408,
272,
653,
275,
603,
1282,
8,
1210,
12,
10245,
15856
] |
[
3254,
26,
1379,
1930,
367,
26512,
5563,
14,
199,
3,
3254,
26,
18674,
1003,
10661,
687,
314,
26512,
5563,
883,
1133,
5965,
506,
1202,
370,
4526,
314,
869,
21663,
367,
314,
3293,
14106,
14,
199,
199,
3,
7711,
13,
18,
14,
16,
13,
3221,
26,
199,
3,
3254,
26,
3868,
2292,
3595,
4052,
370,
886,
3595,
1109,
13,
16611,
26123,
335,
1810,
2932,
14,
199,
3,
3254,
26,
9812,
9565,
340,
289,
827,
63,
76,
63,
31372,
63,
66,
365,
1202,
14,
421,
199,
363,
21841,
363,
534,
264,
27486,
1872,
7,
199,
199,
363,
2502,
363,
275,
283,
2493,
460,
510,
2159,
76,
12,
376,
460,
14,
80,
14411,
72,
1151,
285,
14,
387,
2270,
32,
6799,
14,
957,
7,
199,
363,
452,
363,
275,
788,
15548,
13117,
8221,
16215,
297,
283,
15548,
25923,
8163,
297,
283,
5443,
297,
283,
15548,
13117,
8221,
418,
199,
199,
504,
1611,
45,
19561,
83,
492,
9785,
21913,
12,
4376,
9443,
199,
504,
5013,
492,
15708,
20122,
3616,
199,
504,
5822,
492,
5822,
12,
15227,
82,
199,
504,
2680,
492,
10136,
12,
6506,
12,
465,
3642,
12,
6800,
12,
21460,
12,
2215,
12,
20461,
12,
3634,
12,
2382,
12,
8348,
12,
24144,
12,
365,
4304,
12,
365,
4904,
12,
660,
1090,
12,
943,
12,
1010,
70,
199,
504,
2680,
14,
2355,
492,
3293,
199,
504,
2680,
14,
10096,
492,
14241,
199,
504,
3778,
492,
333,
5079,
12,
1104,
63,
466,
12,
6168,
63,
1144,
12,
943,
80,
63,
1618,
63,
409,
199,
504,
1331,
492,
1331,
199,
199,
893,
26,
272,
687,
7026,
14,
13416,
492,
289,
827,
63,
7966,
71,
12,
289,
827,
12,
289,
827,
63,
8278,
1697,
12,
289,
827,
63,
12595,
12,
289,
827,
63,
31372,
12,
289,
827,
63,
7966,
71,
12,
289,
827,
63,
76,
63,
31372,
63,
66,
272,
687,
7026,
492,
18883,
272,
7026,
63,
17932,
275,
715,
199,
2590,
3545,
26,
272,
7026,
63,
17932,
275,
756,
199,
199,
533,
20800,
13117,
8221,
16215,
8,
785,
304,
272,
408,
272,
1803,
314,
4615,
5477,
402,
2005,
2860,
14,
339,
11028,
26,
982,
299,
17,
436,
299,
18,
787,
1625,
13,
16611,
26123,
21913,
2860,
436,
653,
365,
282,
272,
20800,
13117,
8221,
503,
603,
1282,
909,
12,
339,
653,
14,
6553,
8,
80,
17,
12,
80,
18,
9,
339,
911,
8120,
314,
19917,
2086,
17514,
4615,
402,
314,
660,
1090,
1146,
12,
26271,
272,
1338,
402,
299,
17,
436,
299,
18,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
5771,
304,
267,
291,
14,
4597,
275,
5771,
339,
347,
636,
6095,
721,
277,
12,
627,
14308,
335,
1810,
2932,
304,
398,
340,
440,
291,
14,
4597,
14,
21903,
26,
288,
746,
1722,
12,
283,
15548,
13117,
8221,
909,
1471,
506,
26093,
2544,
8504,
883,
506,
13810,
3530,
398,
12657,
63,
552,
275,
378,
398,
862,
26,
288,
367,
299,
315,
26123,
335,
1810,
2932,
59,
16,
2189,
355,
986,
288,
26123,
21913,
63,
2960,
275,
26123,
335,
1810,
2932,
59,
16,
61,
267,
871,
26,
288,
26123,
21913,
63,
2960,
275,
26123,
335,
1810,
2932,
398,
367,
299,
315,
26123,
21913,
63,
2960,
26,
288,
12657,
63,
552,
847,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
61,
398,
8504,
275,
10136,
8,
13280,
63,
552,
12,
2152,
29,
1609,
9,
398,
1343,
63,
1080,
275,
378,
267,
367,
299,
315,
26123,
21913,
63,
2960,
26,
288,
8504,
59,
928,
63,
1080,
20334,
928,
63,
1080,
435,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
12457,
275,
291,
14,
4597,
423,
6553,
59,
277,
14,
4597,
423,
14865,
59,
80,
2677,
288,
1343,
63,
1080,
847,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
61,
398,
372,
8504,
421,
199,
533,
20800,
25923,
8163,
8,
785,
304,
272,
408,
272,
1803,
314,
13263,
3634,
402,
2005,
2860,
14,
339,
11028,
26,
982,
299,
17,
436,
299,
18,
787,
1625,
13,
16611,
26123,
21913,
2860,
436,
653,
365,
282,
272,
20800,
13117,
8221,
503,
603,
1282,
909,
12,
339,
653,
14,
35,
8,
80,
17,
12,
80,
18,
9,
339,
911,
8120,
314,
19917,
13263,
3634,
402,
314,
660,
1090,
1146,
12,
26271,
272,
1338,
402,
299,
17,
436,
299,
18,
272,
408,
272,
347,
636,
826,
721,
277,
12,
5771,
304,
267,
291,
14,
4597,
275,
5771,
339,
347,
636,
6095,
721,
277,
12,
627,
14308,
335,
1810,
2932,
304,
398,
340,
440,
291,
14,
4597,
14,
21903,
26,
288,
746,
1722,
12,
283,
15548,
13117,
8221,
909,
1471,
506,
26093,
2544,
445,
883,
506,
13810,
3530,
398,
12657,
63,
552,
275,
378,
398,
862,
26,
288,
367,
299,
315,
26123,
335,
1810,
2932,
59,
16,
2189,
355,
986,
288,
26123,
21913,
63,
2960,
275,
26123,
335,
1810,
2932,
59,
16,
61,
267,
871,
26,
288,
26123,
21913,
63,
2960,
275,
26123,
335,
1810,
2932,
398,
367,
299,
315,
26123,
21913,
63,
2960,
26,
288,
12657,
63,
552,
847,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
61,
398,
445,
275,
465,
3642,
8,
4250,
1332,
13280,
63,
552,
12,
12657,
63,
552,
1826,
2152,
29,
1609,
9,
398,
1343,
63,
1080,
17,
275,
378,
267,
367,
299,
17,
315,
26123,
21913,
63,
2960,
26,
288,
1343,
63,
1080,
18,
275,
378,
288,
367,
299,
18,
315,
26123,
21913,
63,
2960,
26,
355,
445,
59,
928,
63,
1080,
17,
20334,
928,
63,
1080,
17,
435,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
17,
2522,
971,
355,
1343,
63,
1080,
18,
20334,
928,
63,
1080,
18,
435,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
18,
12457,
275,
971,
355,
291,
14,
4597,
423,
35,
59,
277,
14,
4597,
423,
14865,
59,
80,
17,
467,
277,
14,
4597,
423,
14865,
59,
80,
18,
2677,
2234,
1343,
63,
1080,
18,
847,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
18,
61,
953,
1343,
63,
1080,
17,
847,
291,
14,
4597,
14,
14308,
21913,
63,
552,
59,
80,
17,
61,
398,
372,
445,
199,
199,
533,
603,
1282,
8,
1685,
304,
272,
408,
272,
653,
275,
603,
1282,
8,
1210,
12,
10245,
15856,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
Livit/Livit.Learn.EdX
|
common/lib/xmodule/xmodule/tests/xml/factories.py
|
40
|
5142
|
"""
Factories for generating edXML for testing XModule import
"""
import inspect
from fs.memoryfs import MemoryFS
from factory import Factory, lazy_attribute, post_generation, Sequence
from lxml import etree
from xblock.mixins import HierarchyMixin
from xmodule.modulestore.inheritance import InheritanceMixin
from xmodule.x_module import XModuleMixin
from xmodule.modulestore import only_xmodules
class XmlImportData(object):
"""
Class to capture all of the data needed to actually run an XML import,
so that the Factories have something to generate
"""
def __init__(self, xml_node, xml=None, course_id=None,
default_class=None, policy=None,
filesystem=None, parent=None,
xblock_mixins=(), xblock_select=None):
self._xml_node = xml_node
self._xml_string = xml
self.course_id = course_id
self.default_class = default_class
self.filesystem = filesystem
self.xblock_mixins = xblock_mixins
self.xblock_select = xblock_select
self.parent = parent
if policy is None:
self.policy = {}
else:
self.policy = policy
@property
def xml_string(self):
"""Return the stringified version of the generated xml"""
if self._xml_string is not None:
return self._xml_string
return etree.tostring(self._xml_node)
def __repr__(self):
return u"XmlImportData{!r}".format((
self._xml_node, self._xml_string, self.course_id,
self.default_class, self.policy,
self.filesystem, self.parent, self.xblock_mixins,
self.xblock_select,
))
# Extract all argument names used to construct XmlImportData objects,
# so that the factory doesn't treat them as XML attributes
XML_IMPORT_ARGS = inspect.getargspec(XmlImportData.__init__).args
class XmlImportFactory(Factory):
"""
Factory for generating XmlImportData's, which can hold all the data needed
to run an XModule XML import
"""
class Meta(object):
model = XmlImportData
filesystem = MemoryFS()
xblock_mixins = (InheritanceMixin, XModuleMixin, HierarchyMixin)
xblock_select = only_xmodules
url_name = Sequence(str)
attribs = {}
policy = {}
inline_xml = True
tag = 'unknown'
course_id = 'edX/xml_test_course/101'
@classmethod
def _adjust_kwargs(cls, **kwargs):
"""
Adjust the kwargs to be passed to the generated class.
Any kwargs that match :fun:`XmlImportData.__init__` will be passed
through. Any other unknown `kwargs` will be treated as XML attributes
:param tag: xml tag for the generated :class:`Element` node
:param text: (Optional) specifies the text of the generated :class:`Element`.
:param policy: (Optional) specifies data for the policy json file for this node
:type policy: dict
:param attribs: (Optional) specify attributes for the XML node
:type attribs: dict
"""
tag = kwargs.pop('tag', 'unknown')
kwargs['policy'] = {'{tag}/{url_name}'.format(tag=tag, url_name=kwargs['url_name']): kwargs['policy']}
kwargs['xml_node'].text = kwargs.pop('text', None)
kwargs['xml_node'].attrib.update(kwargs.pop('attribs', {}))
# Make sure that the xml_module doesn't try and open a file to find the contents
# of this node.
inline_xml = kwargs.pop('inline_xml')
if inline_xml:
kwargs['xml_node'].set('not_a_pointer', 'true')
for key in kwargs.keys():
if key not in XML_IMPORT_ARGS:
kwargs['xml_node'].set(key, kwargs.pop(key))
if not inline_xml:
kwargs['xml_node'].write(
kwargs['filesystem'].open(
'{}/{}.xml'.format(kwargs['tag'], kwargs['url_name'])
),
encoding='utf-8'
)
return kwargs
@lazy_attribute
def xml_node(self):
"""An :class:`xml.etree.Element`"""
return etree.Element(self.tag)
@post_generation
def parent(self, _create, extracted, **_):
"""Hook to merge this xml into a parent xml node"""
if extracted is None:
return
extracted._xml_node.append(self._xml_node) # pylint: disable=no-member, protected-access
extracted.policy.update(self.policy)
class CourseFactory(XmlImportFactory):
"""Factory for <course> nodes"""
tag = 'course'
name = '101'
static_asset_path = 'xml_test_course'
class ChapterFactory(XmlImportFactory):
"""Factory for <chapter> nodes"""
tag = 'chapter'
class SequenceFactory(XmlImportFactory):
"""Factory for <sequential> nodes"""
tag = 'sequential'
class VerticalFactory(XmlImportFactory):
"""Factory for <vertical> nodes"""
tag = 'vertical'
class ProblemFactory(XmlImportFactory):
"""Factory for <problem> nodes"""
tag = 'problem'
text = '<h1>Empty Problem!</h1>'
class HtmlFactory(XmlImportFactory):
"""Factory for <html> nodes"""
tag = 'html'
|
agpl-3.0
|
[
624,
199,
1906,
4253,
367,
12999,
3988,
4317,
367,
5343,
25656,
492,
199,
624,
199,
199,
646,
6485,
199,
199,
504,
7449,
14,
4844,
2319,
492,
15825,
7079,
199,
504,
6434,
492,
23616,
12,
9617,
63,
3215,
12,
2963,
63,
15043,
12,
10975,
199,
504,
14490,
492,
7559,
199,
199,
504,
12971,
14,
30192,
492,
869,
8641,
4256,
199,
504,
9872,
14,
10012,
14,
13136,
492,
27502,
554,
4256,
199,
504,
9872,
14,
88,
63,
578,
492,
25656,
4256,
199,
504,
9872,
14,
10012,
492,
1454,
63,
88,
3112,
421,
199,
533,
24881,
6295,
1451,
8,
785,
304,
272,
408,
272,
8089,
370,
12296,
1006,
402,
314,
666,
4346,
370,
5965,
1255,
376,
4692,
492,
12,
272,
880,
626,
314,
10859,
4253,
1172,
6020,
370,
3550,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2748,
63,
932,
12,
2748,
29,
403,
12,
2518,
63,
344,
29,
403,
12,
326,
849,
63,
533,
29,
403,
12,
4592,
29,
403,
12,
326,
10036,
29,
403,
12,
1676,
29,
403,
12,
326,
12971,
63,
30192,
16729,
12971,
63,
2416,
29,
403,
304,
398,
291,
423,
1652,
63,
932,
275,
2748,
63,
932,
267,
291,
423,
1652,
63,
875,
275,
2748,
267,
291,
14,
1972,
63,
344,
275,
2518,
63,
344,
267,
291,
14,
885,
63,
533,
275,
849,
63,
533,
267,
291,
14,
11381,
275,
10036,
267,
291,
14,
11283,
63,
30192,
275,
12971,
63,
30192,
267,
291,
14,
11283,
63,
2416,
275,
12971,
63,
2416,
267,
291,
14,
1708,
275,
1676,
398,
340,
4592,
365,
488,
26,
288,
291,
14,
3185,
275,
1052,
267,
587,
26,
288,
291,
14,
3185,
275,
4592,
339,
768,
1829,
272,
347,
2748,
63,
875,
8,
277,
304,
267,
408,
1767,
314,
1059,
4541,
1015,
402,
314,
4046,
2748,
624,
267,
340,
291,
423,
1652,
63,
875,
365,
440,
488,
26,
288,
372,
291,
423,
1652,
63,
875,
398,
372,
7559,
14,
14028,
8,
277,
423,
1652,
63,
932,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
399,
2,
8672,
6295,
1451,
91,
1,
82,
5469,
908,
1332,
288,
291,
423,
1652,
63,
932,
12,
291,
423,
1652,
63,
875,
12,
291,
14,
1972,
63,
344,
12,
288,
291,
14,
885,
63,
533,
12,
291,
14,
3185,
12,
288,
291,
14,
11381,
12,
291,
14,
1708,
12,
291,
14,
11283,
63,
30192,
12,
288,
291,
14,
11283,
63,
2416,
12,
267,
5082,
421,
199,
3,
12892,
1006,
1423,
1561,
1202,
370,
6982,
24881,
6295,
1451,
2251,
12,
199,
3,
880,
626,
314,
6434,
3181,
1133,
14312,
3062,
465,
4692,
3004,
199,
4317,
63,
17576,
63,
13990,
275,
6485,
14,
29836,
8,
8672,
6295,
1451,
855,
826,
28634,
589,
421,
199,
533,
24881,
6295,
2927,
8,
2927,
304,
272,
408,
272,
23616,
367,
12999,
24881,
6295,
1451,
1159,
12,
1314,
883,
10266,
1006,
314,
666,
4346,
272,
370,
1255,
376,
25656,
4692,
492,
272,
408,
272,
1021,
6288,
8,
785,
304,
267,
1402,
275,
24881,
6295,
1451,
339,
10036,
275,
15825,
7079,
342,
272,
12971,
63,
30192,
275,
334,
23542,
554,
4256,
12,
25656,
4256,
12,
869,
8641,
4256,
9,
272,
12971,
63,
2416,
275,
1454,
63,
88,
3112,
272,
1166,
63,
354,
275,
10975,
8,
495,
9,
272,
737,
19577,
275,
1052,
272,
4592,
275,
1052,
272,
8308,
63,
1652,
275,
715,
272,
1947,
275,
283,
5187,
7,
272,
2518,
63,
344,
275,
283,
24852,
15,
1652,
63,
396,
63,
1972,
15,
4893,
7,
339,
768,
3744,
272,
347,
485,
10917,
63,
958,
8,
1886,
12,
1011,
958,
304,
267,
408,
267,
26412,
314,
2074,
370,
506,
3032,
370,
314,
4046,
1021,
14,
398,
6184,
2074,
626,
1336,
520,
7036,
1705,
8672,
6295,
1451,
855,
826,
29341,
911,
506,
3032,
267,
4012,
14,
6184,
1163,
5809,
658,
958,
64,
911,
506,
10184,
465,
4692,
3004,
398,
520,
635,
1947,
26,
2748,
1947,
367,
314,
4046,
520,
533,
1705,
2162,
64,
1031,
267,
520,
635,
1318,
26,
334,
7012,
9,
9314,
314,
1318,
402,
314,
4046,
520,
533,
1705,
2162,
2313,
267,
520,
635,
4592,
26,
334,
7012,
9,
9314,
666,
367,
314,
4592,
2022,
570,
367,
642,
1031,
267,
520,
466,
4592,
26,
1211,
267,
520,
635,
737,
19577,
26,
334,
7012,
9,
4165,
3004,
367,
314,
4692,
1031,
267,
520,
466,
737,
19577,
26,
1211,
267,
408,
267,
1947,
275,
2074,
14,
1935,
360,
1450,
297,
283,
5187,
358,
267,
2074,
459,
3185,
418,
275,
791,
91,
1450,
16152,
633,
63,
354,
5285,
908,
8,
1450,
29,
1450,
12,
1166,
63,
354,
29,
958,
459,
633,
63,
354,
9090,
2074,
459,
3185,
12074,
398,
2074,
459,
1652,
63,
932,
2278,
505,
275,
2074,
14,
1935,
360,
505,
297,
488,
9,
398,
2074,
459,
1652,
63,
932,
2278,
6640,
14,
873,
8,
958,
14,
1935,
360,
30674,
297,
17003,
398,
327,
4155,
3238,
626,
314,
2748,
63,
578,
3181,
1133,
862,
436,
1551,
282,
570,
370,
2342,
314,
4072,
267,
327,
402,
642,
1031,
14,
267,
8308,
63,
1652,
275,
2074,
14,
1935,
360,
6460,
63,
1652,
358,
398,
340,
8308,
63,
1652,
26,
288,
2074,
459,
1652,
63,
932,
2278,
409,
360,
1397,
63,
65,
63,
3929,
297,
283,
2052,
358,
398,
367,
790,
315,
2074,
14,
1612,
837,
288,
340,
790,
440,
315,
4692,
63,
17576,
63,
13990,
26,
355,
2074,
459,
1652,
63,
932,
2278,
409,
8,
498,
12,
2074,
14,
1935,
8,
498,
430,
398,
340,
440,
8308,
63,
1652,
26,
288,
2074,
459,
1652,
63,
932,
2278,
952,
8,
355,
2074,
459,
11381,
2278,
1490,
8,
490,
9005,
14698,
14,
1652,
1370,
908,
8,
958,
459,
1450,
995,
2074,
459,
633,
63,
354,
1105,
355,
2318,
355,
2644,
534,
1624,
13,
24,
7,
288,
776,
398,
372,
2074,
339,
768,
6395,
63,
3215,
272,
347,
2748,
63,
932,
8,
277,
304,
267,
408,
2493,
520,
533,
1705,
1652,
14,
9464,
14,
2162,
64,
624,
267,
372,
7559,
14,
2162,
8,
277,
14,
1450,
9,
339,
768,
1932,
63,
15043,
272,
347,
1676,
8,
277,
12,
485,
981,
12,
12509,
12,
1011,
7822,
267,
408,
8481,
370,
5389,
642,
2748,
1901,
282,
1676,
2748,
1031,
624,
267,
340,
12509,
365,
488,
26,
288,
372
] |
[
199,
1906,
4253,
367,
12999,
3988,
4317,
367,
5343,
25656,
492,
199,
624,
199,
199,
646,
6485,
199,
199,
504,
7449,
14,
4844,
2319,
492,
15825,
7079,
199,
504,
6434,
492,
23616,
12,
9617,
63,
3215,
12,
2963,
63,
15043,
12,
10975,
199,
504,
14490,
492,
7559,
199,
199,
504,
12971,
14,
30192,
492,
869,
8641,
4256,
199,
504,
9872,
14,
10012,
14,
13136,
492,
27502,
554,
4256,
199,
504,
9872,
14,
88,
63,
578,
492,
25656,
4256,
199,
504,
9872,
14,
10012,
492,
1454,
63,
88,
3112,
421,
199,
533,
24881,
6295,
1451,
8,
785,
304,
272,
408,
272,
8089,
370,
12296,
1006,
402,
314,
666,
4346,
370,
5965,
1255,
376,
4692,
492,
12,
272,
880,
626,
314,
10859,
4253,
1172,
6020,
370,
3550,
272,
408,
272,
347,
636,
826,
721,
277,
12,
2748,
63,
932,
12,
2748,
29,
403,
12,
2518,
63,
344,
29,
403,
12,
326,
849,
63,
533,
29,
403,
12,
4592,
29,
403,
12,
326,
10036,
29,
403,
12,
1676,
29,
403,
12,
326,
12971,
63,
30192,
16729,
12971,
63,
2416,
29,
403,
304,
398,
291,
423,
1652,
63,
932,
275,
2748,
63,
932,
267,
291,
423,
1652,
63,
875,
275,
2748,
267,
291,
14,
1972,
63,
344,
275,
2518,
63,
344,
267,
291,
14,
885,
63,
533,
275,
849,
63,
533,
267,
291,
14,
11381,
275,
10036,
267,
291,
14,
11283,
63,
30192,
275,
12971,
63,
30192,
267,
291,
14,
11283,
63,
2416,
275,
12971,
63,
2416,
267,
291,
14,
1708,
275,
1676,
398,
340,
4592,
365,
488,
26,
288,
291,
14,
3185,
275,
1052,
267,
587,
26,
288,
291,
14,
3185,
275,
4592,
339,
768,
1829,
272,
347,
2748,
63,
875,
8,
277,
304,
267,
408,
1767,
314,
1059,
4541,
1015,
402,
314,
4046,
2748,
624,
267,
340,
291,
423,
1652,
63,
875,
365,
440,
488,
26,
288,
372,
291,
423,
1652,
63,
875,
398,
372,
7559,
14,
14028,
8,
277,
423,
1652,
63,
932,
9,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
399,
2,
8672,
6295,
1451,
91,
1,
82,
5469,
908,
1332,
288,
291,
423,
1652,
63,
932,
12,
291,
423,
1652,
63,
875,
12,
291,
14,
1972,
63,
344,
12,
288,
291,
14,
885,
63,
533,
12,
291,
14,
3185,
12,
288,
291,
14,
11381,
12,
291,
14,
1708,
12,
291,
14,
11283,
63,
30192,
12,
288,
291,
14,
11283,
63,
2416,
12,
267,
5082,
421,
199,
3,
12892,
1006,
1423,
1561,
1202,
370,
6982,
24881,
6295,
1451,
2251,
12,
199,
3,
880,
626,
314,
6434,
3181,
1133,
14312,
3062,
465,
4692,
3004,
199,
4317,
63,
17576,
63,
13990,
275,
6485,
14,
29836,
8,
8672,
6295,
1451,
855,
826,
28634,
589,
421,
199,
533,
24881,
6295,
2927,
8,
2927,
304,
272,
408,
272,
23616,
367,
12999,
24881,
6295,
1451,
1159,
12,
1314,
883,
10266,
1006,
314,
666,
4346,
272,
370,
1255,
376,
25656,
4692,
492,
272,
408,
272,
1021,
6288,
8,
785,
304,
267,
1402,
275,
24881,
6295,
1451,
339,
10036,
275,
15825,
7079,
342,
272,
12971,
63,
30192,
275,
334,
23542,
554,
4256,
12,
25656,
4256,
12,
869,
8641,
4256,
9,
272,
12971,
63,
2416,
275,
1454,
63,
88,
3112,
272,
1166,
63,
354,
275,
10975,
8,
495,
9,
272,
737,
19577,
275,
1052,
272,
4592,
275,
1052,
272,
8308,
63,
1652,
275,
715,
272,
1947,
275,
283,
5187,
7,
272,
2518,
63,
344,
275,
283,
24852,
15,
1652,
63,
396,
63,
1972,
15,
4893,
7,
339,
768,
3744,
272,
347,
485,
10917,
63,
958,
8,
1886,
12,
1011,
958,
304,
267,
408,
267,
26412,
314,
2074,
370,
506,
3032,
370,
314,
4046,
1021,
14,
398,
6184,
2074,
626,
1336,
520,
7036,
1705,
8672,
6295,
1451,
855,
826,
29341,
911,
506,
3032,
267,
4012,
14,
6184,
1163,
5809,
658,
958,
64,
911,
506,
10184,
465,
4692,
3004,
398,
520,
635,
1947,
26,
2748,
1947,
367,
314,
4046,
520,
533,
1705,
2162,
64,
1031,
267,
520,
635,
1318,
26,
334,
7012,
9,
9314,
314,
1318,
402,
314,
4046,
520,
533,
1705,
2162,
2313,
267,
520,
635,
4592,
26,
334,
7012,
9,
9314,
666,
367,
314,
4592,
2022,
570,
367,
642,
1031,
267,
520,
466,
4592,
26,
1211,
267,
520,
635,
737,
19577,
26,
334,
7012,
9,
4165,
3004,
367,
314,
4692,
1031,
267,
520,
466,
737,
19577,
26,
1211,
267,
408,
267,
1947,
275,
2074,
14,
1935,
360,
1450,
297,
283,
5187,
358,
267,
2074,
459,
3185,
418,
275,
791,
91,
1450,
16152,
633,
63,
354,
5285,
908,
8,
1450,
29,
1450,
12,
1166,
63,
354,
29,
958,
459,
633,
63,
354,
9090,
2074,
459,
3185,
12074,
398,
2074,
459,
1652,
63,
932,
2278,
505,
275,
2074,
14,
1935,
360,
505,
297,
488,
9,
398,
2074,
459,
1652,
63,
932,
2278,
6640,
14,
873,
8,
958,
14,
1935,
360,
30674,
297,
17003,
398,
327,
4155,
3238,
626,
314,
2748,
63,
578,
3181,
1133,
862,
436,
1551,
282,
570,
370,
2342,
314,
4072,
267,
327,
402,
642,
1031,
14,
267,
8308,
63,
1652,
275,
2074,
14,
1935,
360,
6460,
63,
1652,
358,
398,
340,
8308,
63,
1652,
26,
288,
2074,
459,
1652,
63,
932,
2278,
409,
360,
1397,
63,
65,
63,
3929,
297,
283,
2052,
358,
398,
367,
790,
315,
2074,
14,
1612,
837,
288,
340,
790,
440,
315,
4692,
63,
17576,
63,
13990,
26,
355,
2074,
459,
1652,
63,
932,
2278,
409,
8,
498,
12,
2074,
14,
1935,
8,
498,
430,
398,
340,
440,
8308,
63,
1652,
26,
288,
2074,
459,
1652,
63,
932,
2278,
952,
8,
355,
2074,
459,
11381,
2278,
1490,
8,
490,
9005,
14698,
14,
1652,
1370,
908,
8,
958,
459,
1450,
995,
2074,
459,
633,
63,
354,
1105,
355,
2318,
355,
2644,
534,
1624,
13,
24,
7,
288,
776,
398,
372,
2074,
339,
768,
6395,
63,
3215,
272,
347,
2748,
63,
932,
8,
277,
304,
267,
408,
2493,
520,
533,
1705,
1652,
14,
9464,
14,
2162,
64,
624,
267,
372,
7559,
14,
2162,
8,
277,
14,
1450,
9,
339,
768,
1932,
63,
15043,
272,
347,
1676,
8,
277,
12,
485,
981,
12,
12509,
12,
1011,
7822,
267,
408,
8481,
370,
5389,
642,
2748,
1901,
282,
1676,
2748,
1031,
624,
267,
340,
12509,
365,
488,
26,
288,
372,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
obnoxxx/samba
|
source3/script/tests/test_wbinfo_sids2xids_int.py
|
27
|
3214
|
#!/usr/bin/env python
import sys,os,subprocess
if len(sys.argv) != 3:
print "Usage: test_wbinfo_sids2xids_int.py wbinfo net"
sys.exit(1)
wbinfo = sys.argv[1]
netcmd = sys.argv[2]
def flush_cache():
os.system(netcmd + " cache flush")
def fill_cache(inids, idtype='gid'):
for inid in inids:
if inid is None:
continue
subprocess.Popen([wbinfo, '--%s-to-sid=%s' % (idtype, inid)],
stdout=subprocess.PIPE).communicate()
domain = subprocess.Popen([wbinfo, "--own-domain"],
stdout=subprocess.PIPE).communicate()[0].strip()
domsid = subprocess.Popen([wbinfo, "-n", domain + "/"],
stdout=subprocess.PIPE).communicate()[0]
domsid = domsid.split(' ')[0]
#print domain
#print domsid
sids=[ domsid + '-512', 'S-1-5-32-545', domsid + '-513' ]
flush_cache()
sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
stdout=subprocess.PIPE).communicate()[0].strip()
gids=[]
uids=[]
idtypes = []
for line in sids2xids.split('\n'):
result = line.split(' ')[2:]
idtypes.append(result[0])
gid = None
uid = None
if result[0] == 'gid':
gid = result[1]
elif result[0] == 'uid':
uid = result[1]
elif result[0] == 'uid/gid':
gid = result[1]
uid = result[1]
if gid == '-1':
gid = ''
gids.append(gid)
if uid == '-1':
uid = ''
uids.append(uid)
# Check the list produced by the sids-to-xids call with the
# singular variant (sid-to-xid) for each sid in turn.
def check_singular(sids, ids, idtype='gid'):
i = 0
for sid in sids:
if ids[i] is None:
continue
outid = subprocess.Popen([wbinfo, '--sid-to-%s' % idtype, sid],
stdout=subprocess.PIPE).communicate()[0].strip()
if outid != ids[i]:
print "Expected %s, got %s\n" % (outid, ids[i])
flush_cache()
sys.exit(1)
i += 1
# Check the list produced by the sids-to-xids call with the
# multiple variant (sid-to-xid) for each sid in turn.
def check_multiple(sids, idtypes):
sids2xids = subprocess.Popen([wbinfo, '--sids-to-unix-ids=' + ','.join(sids)],
stdout=subprocess.PIPE).communicate()[0].strip()
# print sids2xids
i = 0
for line in sids2xids.split('\n'):
result = line.split(' ')[2:]
if result[0] != idtypes[i]:
print "Expected %s, got %s\n" % (idtypes[i], result[0])
flush_cache()
sys.exit(1)
i += 1
# first round: with filled cache via sid-to-id
check_singular(sids, gids, 'gid')
check_singular(sids, uids, 'uid')
# second round: with empty cache
flush_cache()
check_singular(sids, gids, 'gid')
flush_cache()
check_singular(sids, uids, 'uid')
# third round: with filled cache via uid-to-sid
flush_cache()
fill_cache(uids, 'uid')
check_multiple(sids, idtypes)
# fourth round: with filled cache via gid-to-sid
flush_cache()
fill_cache(gids, 'gid')
check_multiple(sids, idtypes)
# flush the cache so any incorrect mappings don't break other tests
flush_cache()
sys.exit(0)
|
gpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
984,
12,
736,
12,
5781,
421,
199,
692,
822,
8,
1274,
14,
3020,
9,
1137,
650,
26,
272,
870,
298,
7692,
26,
511,
63,
6603,
815,
63,
338,
795,
18,
88,
1580,
63,
442,
14,
647,
336,
66,
815,
1851,
2,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
6603,
815,
275,
984,
14,
3020,
59,
17,
61,
199,
846,
1760,
275,
984,
14,
3020,
59,
18,
61,
199,
199,
318,
8976,
63,
1637,
837,
272,
747,
14,
2253,
8,
846,
1760,
435,
298,
2581,
8976,
531,
199,
199,
318,
5554,
63,
1637,
8,
262,
1580,
12,
1305,
466,
534,
8787,
735,
272,
367,
315,
344,
315,
315,
1580,
26,
267,
340,
315,
344,
365,
488,
26,
288,
1980,
267,
3873,
14,
7942,
779,
6603,
815,
12,
2850,
5,
83,
13,
475,
13,
4148,
2458,
83,
7,
450,
334,
344,
466,
12,
315,
344,
4360,
586,
3839,
29,
5781,
14,
6089,
680,
10664,
342,
199,
199,
2261,
275,
3873,
14,
7942,
779,
6603,
815,
12,
4320,
944,
13,
2261,
2255,
2079,
3839,
29,
5781,
14,
6089,
680,
10664,
3430,
16,
1055,
1913,
342,
199,
4556,
4148,
275,
3873,
14,
7942,
779,
6603,
815,
12,
3905,
78,
401,
2881,
435,
3286,
2255,
2079,
3839,
29,
5781,
14,
6089,
680,
10664,
3430,
16,
61,
199,
4556,
4148,
275,
8266,
4148,
14,
1294,
360,
27618,
16,
61,
199,
199,
3,
1361,
2881,
199,
3,
1361,
8266,
4148,
199,
199,
338,
795,
1524,
8266,
4148,
435,
2475,
7736,
297,
283,
51,
13,
17,
13,
21,
13,
708,
13,
16981,
297,
8266,
4148,
435,
2475,
27452,
7,
1622,
199,
199,
4939,
63,
1637,
342,
199,
199,
338,
795,
18,
88,
1580,
275,
3873,
14,
7942,
779,
6603,
815,
12,
2850,
338,
795,
13,
475,
13,
11864,
13,
1580,
534,
435,
221,
12814,
904,
8,
338,
795,
4360,
2490,
3839,
29,
5781,
14,
6089,
680,
10664,
3430,
16,
1055,
1913,
342,
199,
199,
71,
1580,
9811,
199,
27637,
9811,
199,
344,
1313,
275,
942,
199,
199,
509,
1004,
315,
308,
1580,
18,
88,
1580,
14,
1294,
2258,
78,
735,
272,
754,
275,
1004,
14,
1294,
360,
27618,
18,
2938,
272,
1305,
1313,
14,
740,
8,
1099,
59,
16,
566,
339,
15122,
275,
488,
272,
1747,
275,
488,
272,
340,
754,
59,
16,
61,
508,
283,
8787,
356,
267,
15122,
275,
754,
59,
17,
61,
272,
916,
754,
59,
16,
61,
508,
283,
1535,
356,
267,
1747,
275,
754,
59,
17,
61,
272,
916,
754,
59,
16,
61,
508,
283,
1535,
15,
8787,
356,
267,
15122,
275,
754,
59,
17,
61,
267,
1747,
275,
754,
59,
17,
61,
339,
340,
15122,
508,
2475,
17,
356,
267,
15122,
275,
2125,
272,
486,
1580,
14,
740,
8,
8787,
9,
339,
340,
1747,
508,
2475,
17,
356,
267,
1747,
275,
2125,
272,
399,
1580,
14,
740,
8,
1535,
9,
199,
199,
3,
2670,
314,
769,
13584,
701,
314,
308,
1580,
13,
475,
13,
88,
1580,
1240,
543,
314,
199,
3,
15823,
9854,
334,
4148,
13,
475,
13,
21352,
9,
367,
1924,
15764,
315,
7485,
14,
199,
318,
1104,
63,
17045,
8,
338,
795,
12,
2762,
12,
1305,
466,
534,
8787,
735,
272,
284,
275,
378,
272,
367,
15764,
315,
308,
1580,
26,
267,
340,
2762,
59,
73,
61,
365,
488,
26,
288,
1980,
398,
312,
935,
68,
275,
3873,
14,
7942,
779,
6603,
815,
12,
2850,
4148,
13,
475,
3295,
83,
7,
450,
1305,
466,
12,
15764,
467,
639,
3839,
29,
5781,
14,
6089,
680,
10664,
3430,
16,
1055,
1913,
342,
267,
340,
312,
935,
68,
1137,
2762,
59,
73,
2189,
288,
870,
298,
6964,
450,
83,
12,
4788,
450,
83,
60,
78,
2,
450,
334,
810,
5700,
12,
2762,
59,
73,
566,
288,
8976,
63,
1637,
342,
288,
984,
14,
2224,
8,
17,
9,
267,
284,
847,
413,
199,
199,
3,
2670,
314,
769,
13584,
701,
314,
308,
1580,
13,
475,
13,
88,
1580,
1240,
543,
314,
199,
3,
3663,
9854,
334,
4148,
13,
475,
13,
21352,
9,
367,
1924,
15764,
315,
7485,
14,
199,
318,
1104,
63,
6048,
8,
338,
795,
12,
1305,
1313,
304,
272,
308,
1580,
18,
88,
1580,
275,
3873,
14,
7942,
779,
6603,
815,
12,
2850,
338,
795,
13,
475,
13,
11864,
13,
1580,
534,
435,
221,
12814,
904,
8,
338,
795,
4360,
639,
3839,
29,
5781,
14,
6089,
680,
10664,
3430,
16,
1055,
1913,
342,
272,
327,
870,
308,
1580,
18,
88,
1580,
272,
284,
275,
378,
272,
367,
1004,
315,
308,
1580,
18,
88,
1580,
14,
1294,
2258,
78,
735,
267,
754,
275,
1004,
14,
1294,
360,
27618,
18,
2938,
398,
340,
754,
59,
16,
61,
1137,
1305,
1313,
59,
73,
2189,
288,
870,
298,
6964,
450,
83,
12,
4788,
450,
83,
60,
78,
2,
450,
334,
344,
1313,
59,
73,
467,
754,
59,
16,
566,
288,
8976,
63,
1637,
342,
288,
984,
14,
2224,
8,
17,
9,
267,
284,
847,
413,
199,
199,
3,
1642,
6168,
26,
543,
13457,
2581,
4799,
15764,
13,
475,
13,
344,
199,
1074,
63,
17045,
8,
338,
795,
12,
486,
1580,
12,
283,
8787,
358,
199,
1074,
63,
17045,
8,
338,
795,
12,
399,
1580,
12,
283,
1535,
358,
199,
199,
3,
3499,
6168,
26,
543,
2701,
2581,
199,
4939,
63,
1637,
342,
199,
1074,
63,
17045,
8,
338,
795,
12,
486,
1580,
12,
283,
8787,
358,
199,
4939,
63,
1637,
342,
199,
1074,
63,
17045,
8,
338,
795,
12,
399,
1580,
12,
283,
1535,
358,
199,
199,
3,
10919,
6168,
26,
543,
13457,
2581,
4799,
1747,
13,
475,
13,
4148,
199,
4939,
63,
1637,
342,
199,
4498,
63,
1637,
8,
27637,
12,
283,
1535,
358,
199,
1074,
63,
6048,
8,
338,
795,
12,
1305,
1313,
9,
199,
199,
3,
11648,
273,
6168,
26,
543,
13457,
2581,
4799,
15122,
13,
475,
13,
4148,
199,
4939,
63,
1637,
342,
199,
4498,
63,
1637,
8,
71,
1580,
12,
283,
8787,
358,
199,
1074,
63,
6048,
8,
338,
795,
12,
1305,
1313,
9,
199,
199,
3,
8976,
314,
2581,
880,
1263,
8927,
13546,
2793,
1133,
2059,
1163,
2295,
199,
4939,
63,
1637,
342,
199,
199,
1274,
14,
2224,
8,
16,
9,
199
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
199,
646,
984,
12,
736,
12,
5781,
421,
199,
692,
822,
8,
1274,
14,
3020,
9,
1137,
650,
26,
272,
870,
298,
7692,
26,
511,
63,
6603,
815,
63,
338,
795,
18,
88,
1580,
63,
442,
14,
647,
336,
66,
815,
1851,
2,
272,
984,
14,
2224,
8,
17,
9,
199,
199,
6603,
815,
275,
984,
14,
3020,
59,
17,
61,
199,
846,
1760,
275,
984,
14,
3020,
59,
18,
61,
199,
199,
318,
8976,
63,
1637,
837,
272,
747,
14,
2253,
8,
846,
1760,
435,
298,
2581,
8976,
531,
199,
199,
318,
5554,
63,
1637,
8,
262,
1580,
12,
1305,
466,
534,
8787,
735,
272,
367,
315,
344,
315,
315,
1580,
26,
267,
340,
315,
344,
365,
488,
26,
288,
1980,
267,
3873,
14,
7942,
779,
6603,
815,
12,
2850,
5,
83,
13,
475,
13,
4148,
2458,
83,
7,
450,
334,
344,
466,
12,
315,
344,
4360,
586,
3839,
29,
5781,
14,
6089,
680,
10664,
342,
199,
199,
2261,
275,
3873,
14,
7942,
779,
6603,
815,
12,
4320,
944,
13,
2261,
2255,
2079,
3839,
29,
5781,
14,
6089,
680,
10664,
3430,
16,
1055,
1913,
342,
199,
4556,
4148,
275,
3873,
14,
7942,
779,
6603,
815,
12,
3905,
78,
401,
2881,
435,
3286,
2255,
2079,
3839,
29,
5781,
14,
6089,
680,
10664,
3430,
16,
61,
199,
4556,
4148,
275,
8266,
4148,
14,
1294,
360,
27618,
16,
61,
199,
199,
3,
1361,
2881,
199,
3,
1361,
8266,
4148,
199,
199,
338,
795,
1524,
8266,
4148,
435,
2475,
7736,
297,
283,
51,
13,
17,
13,
21,
13,
708,
13,
16981,
297,
8266,
4148,
435,
2475,
27452,
7,
1622,
199,
199,
4939,
63,
1637,
342,
199,
199,
338,
795,
18,
88,
1580,
275,
3873,
14,
7942,
779,
6603,
815,
12,
2850,
338,
795,
13,
475,
13,
11864,
13,
1580,
534,
435,
221,
12814,
904,
8,
338,
795,
4360,
2490,
3839,
29,
5781,
14,
6089,
680,
10664,
3430,
16,
1055,
1913,
342,
199,
199,
71,
1580,
9811,
199,
27637,
9811,
199,
344,
1313,
275,
942,
199,
199,
509,
1004,
315,
308,
1580,
18,
88,
1580,
14,
1294,
2258,
78,
735,
272,
754,
275,
1004,
14,
1294,
360,
27618,
18,
2938,
272,
1305,
1313,
14,
740,
8,
1099,
59,
16,
566,
339,
15122,
275,
488,
272,
1747,
275,
488,
272,
340,
754,
59,
16,
61,
508,
283,
8787,
356,
267,
15122,
275,
754,
59,
17,
61,
272,
916,
754,
59,
16,
61,
508,
283,
1535,
356,
267,
1747,
275,
754,
59,
17,
61,
272,
916,
754,
59,
16,
61,
508,
283,
1535,
15,
8787,
356,
267,
15122,
275,
754,
59,
17,
61,
267,
1747,
275,
754,
59,
17,
61,
339,
340,
15122,
508,
2475,
17,
356,
267,
15122,
275,
2125,
272,
486,
1580,
14,
740,
8,
8787,
9,
339,
340,
1747,
508,
2475,
17,
356,
267,
1747,
275,
2125,
272,
399,
1580,
14,
740,
8,
1535,
9,
199,
199,
3,
2670,
314,
769,
13584,
701,
314,
308,
1580,
13,
475,
13,
88,
1580,
1240,
543,
314,
199,
3,
15823,
9854,
334,
4148,
13,
475,
13,
21352,
9,
367,
1924,
15764,
315,
7485,
14,
199,
318,
1104,
63,
17045,
8,
338,
795,
12,
2762,
12,
1305,
466,
534,
8787,
735,
272,
284,
275,
378,
272,
367,
15764,
315,
308,
1580,
26,
267,
340,
2762,
59,
73,
61,
365,
488,
26,
288,
1980,
398,
312,
935,
68,
275,
3873,
14,
7942,
779,
6603,
815,
12,
2850,
4148,
13,
475,
3295,
83,
7,
450,
1305,
466,
12,
15764,
467,
639,
3839,
29,
5781,
14,
6089,
680,
10664,
3430,
16,
1055,
1913,
342,
267,
340,
312,
935,
68,
1137,
2762,
59,
73,
2189,
288,
870,
298,
6964,
450,
83,
12,
4788,
450,
83,
60,
78,
2,
450,
334,
810,
5700,
12,
2762,
59,
73,
566,
288,
8976,
63,
1637,
342,
288,
984,
14,
2224,
8,
17,
9,
267,
284,
847,
413,
199,
199,
3,
2670,
314,
769,
13584,
701,
314,
308,
1580,
13,
475,
13,
88,
1580,
1240,
543,
314,
199,
3,
3663,
9854,
334,
4148,
13,
475,
13,
21352,
9,
367,
1924,
15764,
315,
7485,
14,
199,
318,
1104,
63,
6048,
8,
338,
795,
12,
1305,
1313,
304,
272,
308,
1580,
18,
88,
1580,
275,
3873,
14,
7942,
779,
6603,
815,
12,
2850,
338,
795,
13,
475,
13,
11864,
13,
1580,
534,
435,
221,
12814,
904,
8,
338,
795,
4360,
639,
3839,
29,
5781,
14,
6089,
680,
10664,
3430,
16,
1055,
1913,
342,
272,
327,
870,
308,
1580,
18,
88,
1580,
272,
284,
275,
378,
272,
367,
1004,
315,
308,
1580,
18,
88,
1580,
14,
1294,
2258,
78,
735,
267,
754,
275,
1004,
14,
1294,
360,
27618,
18,
2938,
398,
340,
754,
59,
16,
61,
1137,
1305,
1313,
59,
73,
2189,
288,
870,
298,
6964,
450,
83,
12,
4788,
450,
83,
60,
78,
2,
450,
334,
344,
1313,
59,
73,
467,
754,
59,
16,
566,
288,
8976,
63,
1637,
342,
288,
984,
14,
2224,
8,
17,
9,
267,
284,
847,
413,
199,
199,
3,
1642,
6168,
26,
543,
13457,
2581,
4799,
15764,
13,
475,
13,
344,
199,
1074,
63,
17045,
8,
338,
795,
12,
486,
1580,
12,
283,
8787,
358,
199,
1074,
63,
17045,
8,
338,
795,
12,
399,
1580,
12,
283,
1535,
358,
199,
199,
3,
3499,
6168,
26,
543,
2701,
2581,
199,
4939,
63,
1637,
342,
199,
1074,
63,
17045,
8,
338,
795,
12,
486,
1580,
12,
283,
8787,
358,
199,
4939,
63,
1637,
342,
199,
1074,
63,
17045,
8,
338,
795,
12,
399,
1580,
12,
283,
1535,
358,
199,
199,
3,
10919,
6168,
26,
543,
13457,
2581,
4799,
1747,
13,
475,
13,
4148,
199,
4939,
63,
1637,
342,
199,
4498,
63,
1637,
8,
27637,
12,
283,
1535,
358,
199,
1074,
63,
6048,
8,
338,
795,
12,
1305,
1313,
9,
199,
199,
3,
11648,
273,
6168,
26,
543,
13457,
2581,
4799,
15122,
13,
475,
13,
4148,
199,
4939,
63,
1637,
342,
199,
4498,
63,
1637,
8,
71,
1580,
12,
283,
8787,
358,
199,
1074,
63,
6048,
8,
338,
795,
12,
1305,
1313,
9,
199,
199,
3,
8976,
314,
2581,
880,
1263,
8927,
13546,
2793,
1133,
2059,
1163,
2295,
199,
4939,
63,
1637,
342,
199,
199,
1274,
14,
2224,
8,
16,
9,
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,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
lynnUg/django-registration-10
|
registration/models.py
|
1
|
10562
|
import datetime
import hashlib
import random
import re
from django.conf import settings
from django.contrib.auth.models import User
from django.db import models
from django.db import transaction
from django.template.loader import render_to_string
from django.utils.translation import ugettext_lazy as _
try:
from django.contrib.auth import get_user_model
User = get_user_model()
except ImportError:
from django.contrib.auth.models import User
try:
from django.utils.timezone import now as datetime_now
except ImportError:
datetime_now = datetime.datetime.now
SHA1_RE = re.compile('^[a-f0-9]{40}$')
class RegistrationManager(models.Manager):
"""
Custom manager for the ``RegistrationProfile`` model.
The methods defined here provide shortcuts for account creation
and activation (including generation and emailing of activation
keys), and for cleaning out expired inactive accounts.
"""
def activate_user(self, activation_key):
"""
Validate an activation key and activate the corresponding
``User`` if valid.
If the key is valid and has not expired, return the ``User``
after activating.
If the key is not valid or has expired, return ``False``.
If the key is valid but the ``User`` is already active,
return ``False``.
To prevent reactivation of an account which has been
deactivated by site administrators, the activation key is
reset to the string constant ``RegistrationProfile.ACTIVATED``
after successful activation.
"""
# Make sure the key we're trying conforms to the pattern of a
# SHA1 hash; if it doesn't, no point trying to look it up in
# the database.
if SHA1_RE.search(activation_key):
try:
profile = self.get(activation_key=activation_key)
except self.model.DoesNotExist:
return False
if not profile.activation_key_expired():
user = profile.user
user.is_active = True
user.save()
profile.activation_key = self.model.ACTIVATED
profile.save()
return user
return False
def create_inactive_user(self, username, email, password,
site, send_email=True):
"""
Create a new, inactive ``User``, generate a
``RegistrationProfile`` and email its activation key to the
``User``, returning the new ``User``.
By default, an activation email will be sent to the new
user. To disable this, pass ``send_email=False``.
"""
new_user = User.objects.create_user(username, email, password)
new_user.is_active = True
new_user.save()
registration_profile = self.create_profile(new_user)
#if send_email:
#registration_profile.send_activation_email(site)
return new_user
create_inactive_user = transaction.commit_on_success(create_inactive_user)
def create_profile(self, user):
"""
Create a ``RegistrationProfile`` for a given
``User``, and return the ``RegistrationProfile``.
The activation key for the ``RegistrationProfile`` will be a
SHA1 hash, generated from a combination of the ``User``'s
username and a random salt.
"""
salt = hashlib.sha1(str(random.random())).hexdigest()[:5]
username = user.username
if isinstance(username, unicode):
username = username.encode('utf-8')
activation_key = hashlib.sha1(salt+username).hexdigest()
return self.create(user=user,
activation_key=activation_key)
def delete_expired_users(self):
"""
Remove expired instances of ``RegistrationProfile`` and their
associated ``User``s.
Accounts to be deleted are identified by searching for
instances of ``RegistrationProfile`` with expired activation
keys, and then checking to see if their associated ``User``
instances have the field ``is_active`` set to ``False``; any
``User`` who is both inactive and has an expired activation
key will be deleted.
It is recommended that this method be executed regularly as
part of your routine site maintenance; this application
provides a custom management command which will call this
method, accessible as ``manage.py cleanupregistration``.
Regularly clearing out accounts which have never been
activated serves two useful purposes:
1. It alleviates the ocasional need to reset a
``RegistrationProfile`` and/or re-send an activation email
when a user does not receive or does not act upon the
initial activation email; since the account will be
deleted, the user will be able to simply re-register and
receive a new activation key.
2. It prevents the possibility of a malicious user registering
one or more accounts and never activating them (thus
denying the use of those usernames to anyone else); since
those accounts will be deleted, the usernames will become
available for use again.
If you have a troublesome ``User`` and wish to disable their
account while keeping it in the database, simply delete the
associated ``RegistrationProfile``; an inactive ``User`` which
does not have an associated ``RegistrationProfile`` will not
be deleted.
"""
for profile in self.all():
try:
if profile.activation_key_expired():
user = profile.user
if not user.is_active:
user.delete()
profile.delete()
except User.DoesNotExist:
profile.delete()
class RegistrationProfile(models.Model):
"""
A simple profile which stores an activation key for use during
user account registration.
Generally, you will not want to interact directly with instances
of this model; the provided manager includes methods
for creating and activating new accounts, as well as for cleaning
out accounts which have never been activated.
While it is possible to use this model as the value of the
``AUTH_PROFILE_MODULE`` setting, it's not recommended that you do
so. This model's sole purpose is to store data temporarily during
account registration and activation.
"""
ACTIVATED = u"ALREADY_ACTIVATED"
user = models.ForeignKey(User, unique=True, verbose_name=_('user'))
activation_key = models.CharField(_('activation key'), max_length=40)
objects = RegistrationManager()
class Meta:
verbose_name = _('registration profile')
verbose_name_plural = _('registration profiles')
def __unicode__(self):
return u"Registration information for %s" % self.user
def activation_key_expired(self):
"""
Determine whether this ``RegistrationProfile``'s activation
key has expired, returning a boolean -- ``True`` if the key
has expired.
Key expiration is determined by a two-step process:
1. If the user has already activated, the key will have been
reset to the string constant ``ACTIVATED``. Re-activating
is not permitted, and so this method returns ``True`` in
this case.
2. Otherwise, the date the user signed up is incremented by
the number of days specified in the setting
``ACCOUNT_ACTIVATION_DAYS`` (which should be the number of
days after signup during which a user is allowed to
activate their account); if the result is less than or
equal to the current date, the key has expired and this
method returns ``True``.
"""
expiration_date = datetime.timedelta(days=settings.ACCOUNT_ACTIVATION_DAYS)
return self.activation_key == self.ACTIVATED or \
(self.user.date_joined + expiration_date <= datetime_now())
activation_key_expired.boolean = True
def send_activation_email(self, site):
"""
Send an activation email to the user associated with this
``RegistrationProfile``.
The activation email will make use of two templates:
``registration/activation_email_subject.txt``
This template will be used for the subject line of the
email. Because it is used as the subject line of an email,
this template's output **must** be only a single line of
text; output longer than one line will be forcibly joined
into only a single line.
``registration/activation_email.txt``
This template will be used for the body of the email.
These templates will each receive the following context
variables:
``activation_key``
The activation key for the new account.
``expiration_days``
The number of days remaining during which the account may
be activated.
``site``
An object representing the site on which the user
registered; depending on whether ``django.contrib.sites``
is installed, this may be an instance of either
``django.contrib.sites.models.Site`` (if the sites
application is installed) or
``django.contrib.sites.models.RequestSite`` (if
not). Consult the documentation for the Django sites
framework for details regarding these objects' interfaces.
"""
ctx_dict = {'activation_key': self.activation_key,
'expiration_days': settings.ACCOUNT_ACTIVATION_DAYS,
'site': site}
subject = render_to_string('registration/activation_email_subject.txt',
ctx_dict)
# Email subject *must not* contain newlines
subject = ''.join(subject.splitlines())
message = render_to_string('registration/activation_email.txt',
ctx_dict)
self.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
|
bsd-3-clause
|
[
646,
2197,
199,
646,
8337,
199,
646,
2196,
199,
646,
295,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
697,
492,
6008,
199,
504,
1639,
14,
1160,
14,
3422,
492,
3795,
63,
475,
63,
875,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
893,
26,
272,
687,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
272,
2876,
275,
664,
63,
751,
63,
1238,
342,
199,
2590,
3545,
26,
272,
687,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
199,
893,
26,
272,
687,
1639,
14,
1208,
14,
7145,
492,
3063,
465,
2197,
63,
2131,
199,
2590,
3545,
26,
272,
2197,
63,
2131,
275,
2197,
14,
2083,
14,
2131,
421,
199,
8461,
17,
63,
907,
275,
295,
14,
2014,
9097,
59,
65,
13,
70,
16,
13,
25,
8194,
2167,
93,
9988,
421,
199,
533,
20764,
2988,
8,
992,
14,
2988,
304,
272,
408,
272,
8388,
5256,
367,
314,
1124,
11757,
5736,
1040,
1402,
14,
2286,
710,
3102,
3247,
2348,
5647,
3974,
12946,
367,
2933,
7143,
272,
436,
10361,
334,
15768,
10152,
436,
3031,
316,
402,
10361,
272,
2883,
395,
436,
367,
29579,
734,
14721,
21325,
12639,
14,
2286,
408,
272,
347,
15422,
63,
751,
8,
277,
12,
10361,
63,
498,
304,
267,
408,
267,
12134,
376,
10361,
790,
436,
15422,
314,
5226,
267,
1124,
1899,
1040,
340,
1686,
14,
2728,
982,
314,
790,
365,
1686,
436,
965,
440,
14721,
12,
372,
314,
1124,
1899,
1040,
267,
2410,
6633,
86,
1958,
14,
2728,
982,
314,
790,
365,
440,
1686,
503,
965,
14721,
12,
372,
1124,
797,
4345,
2728,
982,
314,
790,
365,
1686,
1325,
314,
1124,
1899,
1040,
365,
2575,
4702,
12,
267,
372,
1124,
797,
4345,
2728,
4005,
7981,
295,
12312,
402,
376,
2933,
1314,
965,
2757,
267,
477,
18218,
701,
4770,
4628,
3075,
2750,
12,
314,
10361,
790,
365,
267,
5305,
370,
314,
1059,
4413,
1124,
11757,
5736,
14,
20425,
6989,
1040,
267,
2410,
9512,
10361,
14,
398,
408,
267,
327,
4155,
3238,
314,
790,
781,
3984,
9936,
406,
3351,
370,
314,
3851,
402,
282,
267,
327,
12002,
17,
2631,
27,
340,
652,
3181,
1133,
12,
949,
2376,
9936,
370,
3648,
652,
1536,
315,
267,
327,
314,
3050,
14,
267,
340,
12002,
17,
63,
907,
14,
1733,
8,
12312,
63,
498,
304,
288,
862,
26,
355,
4690,
275,
291,
14,
362,
8,
12312,
63,
498,
29,
12312,
63,
498,
9,
288,
871,
291,
14,
1238,
14,
7400,
26,
355,
372,
756,
288,
340,
440,
4690,
14,
12312,
63,
498,
63,
16340,
837,
355,
922,
275,
4690,
14,
751,
355,
922,
14,
374,
63,
2682,
275,
715,
355,
922,
14,
2117,
342,
355,
4690,
14,
12312,
63,
498,
275,
291,
14,
1238,
14,
20425,
6989,
355,
4690,
14,
2117,
342,
355,
372,
922,
267,
372,
756,
2286,
347,
1218,
63,
16856,
63,
751,
8,
277,
12,
3434,
12,
3031,
12,
2505,
12,
2490,
4770,
12,
3222,
63,
2123,
29,
549,
304,
267,
408,
267,
2790,
282,
892,
12,
21325,
1124,
1899,
4542,
3550,
282,
267,
1124,
11757,
5736,
1040,
436,
3031,
2399,
10361,
790,
370,
314,
267,
1124,
1899,
4542,
8152,
314,
892,
1124,
1899,
4345,
398,
4885,
849,
12,
376,
10361,
3031,
911,
506,
4847,
370,
314,
892,
267,
922,
14,
4005,
3507,
642,
12,
986,
1124,
2254,
63,
2123,
29,
797,
4345,
2728,
408,
267,
892,
63,
751,
275,
2876,
14,
1462,
14,
981,
63,
751,
8,
2473,
12,
3031,
12,
2505,
9,
267,
892,
63,
751,
14,
374,
63,
2682,
275,
715,
267,
892,
63,
751,
14,
2117,
342,
398,
10991,
63,
2913,
275,
291,
14,
981,
63,
2913,
8,
1222,
63,
751,
9,
398,
327,
692,
3222,
63,
2123,
26,
288,
327,
8054,
63,
2913,
14,
2254,
63,
12312,
63,
2123,
8,
2124,
9,
398,
372,
892,
63,
751,
272,
1218,
63,
16856,
63,
751,
275,
6008,
14,
3543,
63,
265,
63,
3742,
8,
981,
63,
16856,
63,
751,
9,
339,
347,
1218,
63,
2913,
8,
277,
12,
922,
304,
267,
408,
267,
2790,
282,
1124,
11757,
5736,
1040,
367,
282,
1627,
267,
1124,
1899,
4542,
436,
372,
314,
1124,
11757,
5736,
4345,
2728,
710,
10361,
790,
367,
314,
1124,
11757,
5736,
1040,
911,
506,
282,
267,
12002,
17,
2631,
12,
4046,
687,
282,
14665,
402,
314,
1124,
1899,
1040,
7,
83,
267,
3434,
436,
282,
2196,
10105,
14,
2728,
408,
267,
10105,
275,
8337,
14,
4835,
17,
8,
495,
8,
2355,
14,
2355,
4059,
14,
11453,
20523,
21,
61,
267,
3434,
275,
922,
14,
2473,
267,
340,
1228,
8,
2473,
12,
2649,
304,
288,
3434,
275,
3434,
14,
2143,
360,
1624,
13,
24,
358,
267,
10361,
63,
498,
275,
8337,
14,
4835,
17,
8,
12597,
11,
2473,
680,
11453,
342,
267,
372,
291,
14,
981,
8,
751,
29,
751,
12,
2574,
10361,
63,
498,
29,
12312,
63,
498,
9,
5493,
347,
3145,
63,
16340,
63,
3707,
8,
277,
304,
267,
408,
267,
5852,
14721,
4454,
402,
1124,
11757,
5736,
1040,
436,
3932,
267,
4568,
1124,
1899,
1040,
83,
14,
2728,
4473,
6851,
370,
506,
5463,
787,
15836,
701,
18112,
367,
267,
4454,
402,
1124,
11757,
5736,
1040,
543,
14721,
10361,
267,
2883,
12,
436,
2066,
7907,
370,
1937,
340,
3932,
4568,
1124,
1899,
1040,
267,
4454,
1172,
314,
901,
1124,
374,
63,
2682,
1040,
663,
370,
1124,
797,
1040,
27,
1263,
267,
1124,
1899,
1040,
3963,
365,
3865,
21325,
436,
965,
376,
14721,
10361,
267,
790,
911,
506,
5463,
14,
2728,
2779,
365,
14318,
626,
642,
1083,
506,
7934,
5578,
590,
465,
267,
1777,
402,
2195,
12981,
4770,
21964,
27,
642,
4223,
267,
6571,
282,
3537,
10041,
1414,
1314,
911,
1240,
642,
267,
1083,
12,
17909,
465,
1124,
9053,
14,
647,
9058,
8054,
4345,
2728,
18528,
590,
5436,
316,
734,
12639,
1314,
1172,
7078,
2757,
267,
22225,
23739,
2877,
2997,
12901,
26,
2728,
413,
14,
2779,
27458,
433,
2335,
314,
4244,
305,
1636,
279,
1929,
370,
5305,
282,
1779,
1124,
11757,
5736,
1040,
436,
15,
269,
295,
13,
2254,
376,
10361,
3031,
1779,
1380,
282,
922
] |
[
2197,
199,
646,
8337,
199,
646,
2196,
199,
646,
295,
199,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
504,
1639,
14,
697,
492,
1709,
199,
504,
1639,
14,
697,
492,
6008,
199,
504,
1639,
14,
1160,
14,
3422,
492,
3795,
63,
475,
63,
875,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
893,
26,
272,
687,
1639,
14,
2828,
14,
1178,
492,
664,
63,
751,
63,
1238,
272,
2876,
275,
664,
63,
751,
63,
1238,
342,
199,
2590,
3545,
26,
272,
687,
1639,
14,
2828,
14,
1178,
14,
992,
492,
2876,
199,
199,
893,
26,
272,
687,
1639,
14,
1208,
14,
7145,
492,
3063,
465,
2197,
63,
2131,
199,
2590,
3545,
26,
272,
2197,
63,
2131,
275,
2197,
14,
2083,
14,
2131,
421,
199,
8461,
17,
63,
907,
275,
295,
14,
2014,
9097,
59,
65,
13,
70,
16,
13,
25,
8194,
2167,
93,
9988,
421,
199,
533,
20764,
2988,
8,
992,
14,
2988,
304,
272,
408,
272,
8388,
5256,
367,
314,
1124,
11757,
5736,
1040,
1402,
14,
2286,
710,
3102,
3247,
2348,
5647,
3974,
12946,
367,
2933,
7143,
272,
436,
10361,
334,
15768,
10152,
436,
3031,
316,
402,
10361,
272,
2883,
395,
436,
367,
29579,
734,
14721,
21325,
12639,
14,
2286,
408,
272,
347,
15422,
63,
751,
8,
277,
12,
10361,
63,
498,
304,
267,
408,
267,
12134,
376,
10361,
790,
436,
15422,
314,
5226,
267,
1124,
1899,
1040,
340,
1686,
14,
2728,
982,
314,
790,
365,
1686,
436,
965,
440,
14721,
12,
372,
314,
1124,
1899,
1040,
267,
2410,
6633,
86,
1958,
14,
2728,
982,
314,
790,
365,
440,
1686,
503,
965,
14721,
12,
372,
1124,
797,
4345,
2728,
982,
314,
790,
365,
1686,
1325,
314,
1124,
1899,
1040,
365,
2575,
4702,
12,
267,
372,
1124,
797,
4345,
2728,
4005,
7981,
295,
12312,
402,
376,
2933,
1314,
965,
2757,
267,
477,
18218,
701,
4770,
4628,
3075,
2750,
12,
314,
10361,
790,
365,
267,
5305,
370,
314,
1059,
4413,
1124,
11757,
5736,
14,
20425,
6989,
1040,
267,
2410,
9512,
10361,
14,
398,
408,
267,
327,
4155,
3238,
314,
790,
781,
3984,
9936,
406,
3351,
370,
314,
3851,
402,
282,
267,
327,
12002,
17,
2631,
27,
340,
652,
3181,
1133,
12,
949,
2376,
9936,
370,
3648,
652,
1536,
315,
267,
327,
314,
3050,
14,
267,
340,
12002,
17,
63,
907,
14,
1733,
8,
12312,
63,
498,
304,
288,
862,
26,
355,
4690,
275,
291,
14,
362,
8,
12312,
63,
498,
29,
12312,
63,
498,
9,
288,
871,
291,
14,
1238,
14,
7400,
26,
355,
372,
756,
288,
340,
440,
4690,
14,
12312,
63,
498,
63,
16340,
837,
355,
922,
275,
4690,
14,
751,
355,
922,
14,
374,
63,
2682,
275,
715,
355,
922,
14,
2117,
342,
355,
4690,
14,
12312,
63,
498,
275,
291,
14,
1238,
14,
20425,
6989,
355,
4690,
14,
2117,
342,
355,
372,
922,
267,
372,
756,
2286,
347,
1218,
63,
16856,
63,
751,
8,
277,
12,
3434,
12,
3031,
12,
2505,
12,
2490,
4770,
12,
3222,
63,
2123,
29,
549,
304,
267,
408,
267,
2790,
282,
892,
12,
21325,
1124,
1899,
4542,
3550,
282,
267,
1124,
11757,
5736,
1040,
436,
3031,
2399,
10361,
790,
370,
314,
267,
1124,
1899,
4542,
8152,
314,
892,
1124,
1899,
4345,
398,
4885,
849,
12,
376,
10361,
3031,
911,
506,
4847,
370,
314,
892,
267,
922,
14,
4005,
3507,
642,
12,
986,
1124,
2254,
63,
2123,
29,
797,
4345,
2728,
408,
267,
892,
63,
751,
275,
2876,
14,
1462,
14,
981,
63,
751,
8,
2473,
12,
3031,
12,
2505,
9,
267,
892,
63,
751,
14,
374,
63,
2682,
275,
715,
267,
892,
63,
751,
14,
2117,
342,
398,
10991,
63,
2913,
275,
291,
14,
981,
63,
2913,
8,
1222,
63,
751,
9,
398,
327,
692,
3222,
63,
2123,
26,
288,
327,
8054,
63,
2913,
14,
2254,
63,
12312,
63,
2123,
8,
2124,
9,
398,
372,
892,
63,
751,
272,
1218,
63,
16856,
63,
751,
275,
6008,
14,
3543,
63,
265,
63,
3742,
8,
981,
63,
16856,
63,
751,
9,
339,
347,
1218,
63,
2913,
8,
277,
12,
922,
304,
267,
408,
267,
2790,
282,
1124,
11757,
5736,
1040,
367,
282,
1627,
267,
1124,
1899,
4542,
436,
372,
314,
1124,
11757,
5736,
4345,
2728,
710,
10361,
790,
367,
314,
1124,
11757,
5736,
1040,
911,
506,
282,
267,
12002,
17,
2631,
12,
4046,
687,
282,
14665,
402,
314,
1124,
1899,
1040,
7,
83,
267,
3434,
436,
282,
2196,
10105,
14,
2728,
408,
267,
10105,
275,
8337,
14,
4835,
17,
8,
495,
8,
2355,
14,
2355,
4059,
14,
11453,
20523,
21,
61,
267,
3434,
275,
922,
14,
2473,
267,
340,
1228,
8,
2473,
12,
2649,
304,
288,
3434,
275,
3434,
14,
2143,
360,
1624,
13,
24,
358,
267,
10361,
63,
498,
275,
8337,
14,
4835,
17,
8,
12597,
11,
2473,
680,
11453,
342,
267,
372,
291,
14,
981,
8,
751,
29,
751,
12,
2574,
10361,
63,
498,
29,
12312,
63,
498,
9,
5493,
347,
3145,
63,
16340,
63,
3707,
8,
277,
304,
267,
408,
267,
5852,
14721,
4454,
402,
1124,
11757,
5736,
1040,
436,
3932,
267,
4568,
1124,
1899,
1040,
83,
14,
2728,
4473,
6851,
370,
506,
5463,
787,
15836,
701,
18112,
367,
267,
4454,
402,
1124,
11757,
5736,
1040,
543,
14721,
10361,
267,
2883,
12,
436,
2066,
7907,
370,
1937,
340,
3932,
4568,
1124,
1899,
1040,
267,
4454,
1172,
314,
901,
1124,
374,
63,
2682,
1040,
663,
370,
1124,
797,
1040,
27,
1263,
267,
1124,
1899,
1040,
3963,
365,
3865,
21325,
436,
965,
376,
14721,
10361,
267,
790,
911,
506,
5463,
14,
2728,
2779,
365,
14318,
626,
642,
1083,
506,
7934,
5578,
590,
465,
267,
1777,
402,
2195,
12981,
4770,
21964,
27,
642,
4223,
267,
6571,
282,
3537,
10041,
1414,
1314,
911,
1240,
642,
267,
1083,
12,
17909,
465,
1124,
9053,
14,
647,
9058,
8054,
4345,
2728,
18528,
590,
5436,
316,
734,
12639,
1314,
1172,
7078,
2757,
267,
22225,
23739,
2877,
2997,
12901,
26,
2728,
413,
14,
2779,
27458,
433,
2335,
314,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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
] |
hanicker/odoo
|
addons/product/wizard/__init__.py
|
452
|
1076
|
# -*- 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 product_price
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
646,
3336,
63,
4777,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
646,
3336,
63,
4777,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0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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
] |
basnijholt/holoviews
|
holoviews/tests/plotting/plotly/testcurveplot.py
|
2
|
2277
|
import numpy as np
from holoviews.element import Curve
from .testplot import TestPlotlyPlot
class TestCurvePlot(TestPlotlyPlot):
def test_curve_state(self):
curve = Curve([1, 2, 3])
state = self._get_plot_state(curve)
self.assertEqual(state['data'][0]['x'], np.array([0, 1, 2]))
self.assertEqual(state['data'][0]['y'], np.array([1, 2, 3]))
self.assertEqual(state['data'][0]['mode'], 'lines')
self.assertEqual(state['layout']['xaxis']['range'], [0, 2])
self.assertEqual(state['layout']['yaxis']['range'], [1, 3])
def test_curve_inverted(self):
curve = Curve([1, 2, 3]).options(invert_axes=True)
state = self._get_plot_state(curve)
self.assertEqual(state['data'][0]['x'], np.array([1, 2, 3]))
self.assertEqual(state['data'][0]['y'], np.array([0, 1, 2]))
self.assertEqual(state['data'][0]['mode'], 'lines')
self.assertEqual(state['layout']['xaxis']['range'], [1, 3])
self.assertEqual(state['layout']['yaxis']['range'], [0, 2])
self.assertEqual(state['layout']['xaxis']['title'], 'y')
self.assertEqual(state['layout']['yaxis']['title'], 'x')
def test_curve_interpolation(self):
curve = Curve([1, 2, 3]).options(interpolation='steps-mid')
state = self._get_plot_state(curve)
self.assertEqual(state['data'][0]['x'], np.array([0., 0.5, 0.5, 1.5, 1.5, 2.]))
self.assertEqual(state['data'][0]['y'], np.array([1, 1, 2, 2, 3, 3]))
def test_curve_color(self):
curve = Curve([1, 2, 3]).options(color='red')
state = self._get_plot_state(curve)
self.assertEqual(state['data'][0]['line']['color'], 'red')
def test_curve_color_mapping_error(self):
curve = Curve([1, 2, 3]).options(color='x')
with self.assertRaises(ValueError):
self._get_plot_state(curve)
def test_curve_dash(self):
curve = Curve([1, 2, 3]).options(dash='dash')
state = self._get_plot_state(curve)
self.assertEqual(state['data'][0]['line']['dash'], 'dash')
def test_curve_line_width(self):
curve = Curve([1, 2, 3]).options(line_width=5)
state = self._get_plot_state(curve)
self.assertEqual(state['data'][0]['line']['width'], 5)
|
bsd-3-clause
|
[
646,
2680,
465,
980,
199,
199,
504,
2636,
320,
4196,
14,
2108,
492,
7319,
432,
199,
199,
504,
1275,
396,
2798,
492,
1379,
10711,
590,
10711,
421,
199,
533,
1379,
20966,
10711,
8,
774,
10711,
590,
10711,
304,
339,
347,
511,
63,
11895,
63,
929,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
566,
267,
1174,
275,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
88,
995,
980,
14,
1144,
779,
16,
12,
413,
12,
499,
2459,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
89,
995,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
2459,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
632,
995,
283,
1278,
358,
267,
291,
14,
629,
8,
929,
459,
4209,
2545,
21854,
2545,
1842,
995,
359,
16,
12,
499,
566,
267,
291,
14,
629,
8,
929,
459,
4209,
2545,
23876,
2545,
1842,
995,
359,
17,
12,
650,
566,
339,
347,
511,
63,
11895,
63,
28019,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
6575,
1419,
8,
18957,
63,
6402,
29,
549,
9,
267,
1174,
275,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
88,
995,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
2459,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
89,
995,
980,
14,
1144,
779,
16,
12,
413,
12,
499,
2459,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
632,
995,
283,
1278,
358,
267,
291,
14,
629,
8,
929,
459,
4209,
2545,
21854,
2545,
1842,
995,
359,
17,
12,
650,
566,
267,
291,
14,
629,
8,
929,
459,
4209,
2545,
23876,
2545,
1842,
995,
359,
16,
12,
499,
566,
267,
291,
14,
629,
8,
929,
459,
4209,
2545,
21854,
2545,
1213,
995,
283,
89,
358,
267,
291,
14,
629,
8,
929,
459,
4209,
2545,
23876,
2545,
1213,
995,
283,
88,
358,
339,
347,
511,
63,
11895,
63,
21080,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
6575,
1419,
8,
21080,
534,
5895,
13,
8523,
358,
267,
1174,
275,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
88,
995,
980,
14,
1144,
779,
16,
2020,
378,
14,
21,
12,
378,
14,
21,
12,
413,
14,
21,
12,
413,
14,
21,
12,
499,
14,
2459,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
89,
995,
980,
14,
1144,
779,
17,
12,
413,
12,
499,
12,
499,
12,
650,
12,
650,
2459,
339,
347,
511,
63,
11895,
63,
2326,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
6575,
1419,
8,
2326,
534,
581,
358,
267,
1174,
275,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
604,
2545,
2326,
995,
283,
581,
358,
339,
347,
511,
63,
11895,
63,
2326,
63,
4745,
63,
705,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
6575,
1419,
8,
2326,
534,
88,
358,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
339,
347,
511,
63,
11895,
63,
6760,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
6575,
1419,
8,
6760,
534,
6760,
358,
267,
1174,
275,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
604,
2545,
6760,
995,
283,
6760,
358,
339,
347,
511,
63,
11895,
63,
604,
63,
2063,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
6575,
1419,
8,
604,
63,
2063,
29,
21,
9,
267,
1174,
275,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
604,
2545,
2063,
995,
959,
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
] |
[
2680,
465,
980,
199,
199,
504,
2636,
320,
4196,
14,
2108,
492,
7319,
432,
199,
199,
504,
1275,
396,
2798,
492,
1379,
10711,
590,
10711,
421,
199,
533,
1379,
20966,
10711,
8,
774,
10711,
590,
10711,
304,
339,
347,
511,
63,
11895,
63,
929,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
566,
267,
1174,
275,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
88,
995,
980,
14,
1144,
779,
16,
12,
413,
12,
499,
2459,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
89,
995,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
2459,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
632,
995,
283,
1278,
358,
267,
291,
14,
629,
8,
929,
459,
4209,
2545,
21854,
2545,
1842,
995,
359,
16,
12,
499,
566,
267,
291,
14,
629,
8,
929,
459,
4209,
2545,
23876,
2545,
1842,
995,
359,
17,
12,
650,
566,
339,
347,
511,
63,
11895,
63,
28019,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
6575,
1419,
8,
18957,
63,
6402,
29,
549,
9,
267,
1174,
275,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
88,
995,
980,
14,
1144,
779,
17,
12,
499,
12,
650,
2459,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
89,
995,
980,
14,
1144,
779,
16,
12,
413,
12,
499,
2459,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
632,
995,
283,
1278,
358,
267,
291,
14,
629,
8,
929,
459,
4209,
2545,
21854,
2545,
1842,
995,
359,
17,
12,
650,
566,
267,
291,
14,
629,
8,
929,
459,
4209,
2545,
23876,
2545,
1842,
995,
359,
16,
12,
499,
566,
267,
291,
14,
629,
8,
929,
459,
4209,
2545,
21854,
2545,
1213,
995,
283,
89,
358,
267,
291,
14,
629,
8,
929,
459,
4209,
2545,
23876,
2545,
1213,
995,
283,
88,
358,
339,
347,
511,
63,
11895,
63,
21080,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
6575,
1419,
8,
21080,
534,
5895,
13,
8523,
358,
267,
1174,
275,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
88,
995,
980,
14,
1144,
779,
16,
2020,
378,
14,
21,
12,
378,
14,
21,
12,
413,
14,
21,
12,
413,
14,
21,
12,
499,
14,
2459,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
89,
995,
980,
14,
1144,
779,
17,
12,
413,
12,
499,
12,
499,
12,
650,
12,
650,
2459,
339,
347,
511,
63,
11895,
63,
2326,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
6575,
1419,
8,
2326,
534,
581,
358,
267,
1174,
275,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
604,
2545,
2326,
995,
283,
581,
358,
339,
347,
511,
63,
11895,
63,
2326,
63,
4745,
63,
705,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
6575,
1419,
8,
2326,
534,
88,
358,
267,
543,
291,
14,
1855,
8,
3393,
304,
288,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
339,
347,
511,
63,
11895,
63,
6760,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
6575,
1419,
8,
6760,
534,
6760,
358,
267,
1174,
275,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
604,
2545,
6760,
995,
283,
6760,
358,
339,
347,
511,
63,
11895,
63,
604,
63,
2063,
8,
277,
304,
267,
15318,
275,
7319,
432,
779,
17,
12,
499,
12,
650,
6575,
1419,
8,
604,
63,
2063,
29,
21,
9,
267,
1174,
275,
291,
423,
362,
63,
2798,
63,
929,
8,
11895,
9,
267,
291,
14,
629,
8,
929,
459,
576,
3488,
16,
2733,
604,
2545,
2063,
995,
959,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jorik041/phantomjs
|
src/qt/qtwebkit/Tools/Scripts/webkitpy/tool/steps/reopenbugafterrollout.py
|
125
|
2205
|
# Copyright (C) 2010 Google Inc. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following disclaimer
# in the documentation and/or other materials provided with the
# distribution.
# * Neither the name of Google Inc. nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import logging
from webkitpy.tool.comments import bug_comment_from_commit_text
from webkitpy.tool.steps.abstractstep import AbstractStep
_log = logging.getLogger(__name__)
class ReopenBugAfterRollout(AbstractStep):
def run(self, state):
commit_comment = bug_comment_from_commit_text(self._tool.scm(), state["commit_text"])
comment_text = "Reverted r%s for reason:\n\n%s\n\n%s" % (state["revision"], state["reason"], commit_comment)
bug_id = state["bug_id"]
if not bug_id:
_log.info(comment_text)
_log.info("No bugs were updated.")
return
self._tool.bugs.reopen_bug(bug_id, comment_text)
|
bsd-3-clause
|
[
3,
1898,
334,
35,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
221,
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,
221,
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,
221,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2050,
199,
199,
504,
18007,
14,
3557,
14,
6223,
492,
6519,
63,
3349,
63,
504,
63,
3543,
63,
505,
199,
504,
18007,
14,
3557,
14,
5895,
14,
6198,
2926,
492,
11836,
7801,
199,
199,
63,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
799,
1490,
17545,
10881,
50,
393,
22316,
8,
8458,
7801,
304,
272,
347,
1255,
8,
277,
12,
1174,
304,
267,
5532,
63,
3349,
275,
6519,
63,
3349,
63,
504,
63,
3543,
63,
505,
8,
277,
423,
3557,
14,
17143,
1062,
1174,
905,
3543,
63,
505,
3135,
267,
3721,
63,
505,
275,
298,
497,
16542,
519,
5,
83,
367,
4499,
3427,
78,
60,
78,
5,
83,
60,
78,
60,
78,
5,
83,
2,
450,
334,
929,
905,
5792,
2255,
1174,
905,
5764,
2255,
5532,
63,
3349,
9,
398,
6519,
63,
344,
275,
1174,
905,
1266,
63,
344,
937,
267,
340,
440,
6519,
63,
344,
26,
288,
485,
793,
14,
815,
8,
3349,
63,
505,
9,
288,
485,
793,
14,
815,
480,
1944,
18227,
4898,
4588,
2685,
288,
372,
267,
291,
423,
3557,
14,
13017,
14,
264,
1490,
63,
1266,
8,
1266,
63,
344,
12,
3721,
63,
505,
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
] |
[
1898,
334,
35,
9,
7129,
4475,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
221,
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,
221,
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,
221,
199,
3,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
3,
298,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
3,
437,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
199,
3,
11489,
1549,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
199,
3,
8820,
12,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
199,
3,
5471,
2296,
12,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
199,
3,
7126,
12,
1549,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
199,
3,
9815,
1634,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
199,
3,
334,
6446,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
199,
3,
1634,
5749,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
199,
646,
2050,
199,
199,
504,
18007,
14,
3557,
14,
6223,
492,
6519,
63,
3349,
63,
504,
63,
3543,
63,
505,
199,
504,
18007,
14,
3557,
14,
5895,
14,
6198,
2926,
492,
11836,
7801,
199,
199,
63,
793,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
799,
1490,
17545,
10881,
50,
393,
22316,
8,
8458,
7801,
304,
272,
347,
1255,
8,
277,
12,
1174,
304,
267,
5532,
63,
3349,
275,
6519,
63,
3349,
63,
504,
63,
3543,
63,
505,
8,
277,
423,
3557,
14,
17143,
1062,
1174,
905,
3543,
63,
505,
3135,
267,
3721,
63,
505,
275,
298,
497,
16542,
519,
5,
83,
367,
4499,
3427,
78,
60,
78,
5,
83,
60,
78,
60,
78,
5,
83,
2,
450,
334,
929,
905,
5792,
2255,
1174,
905,
5764,
2255,
5532,
63,
3349,
9,
398,
6519,
63,
344,
275,
1174,
905,
1266,
63,
344,
937,
267,
340,
440,
6519,
63,
344,
26,
288,
485,
793,
14,
815,
8,
3349,
63,
505,
9,
288,
485,
793,
14,
815,
480,
1944,
18227,
4898,
4588,
2685,
288,
372,
267,
291,
423,
3557,
14,
13017,
14,
264,
1490,
63,
1266,
8,
1266,
63,
344,
12,
3721,
63,
505,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kisel/trex-core
|
scripts/external_libs/pyzmq-14.5.0/python2/ucs2/32bit/zmq/tests/test_imports.py
|
30
|
1742
|
# Copyright (C) PyZMQ Developers
# Distributed under the terms of the Modified BSD License.
import sys
from unittest import TestCase
class TestImports(TestCase):
"""Test Imports - the quickest test to ensure that we haven't
introduced version-incompatible syntax errors."""
def test_toplevel(self):
"""test toplevel import"""
import zmq
def test_core(self):
"""test core imports"""
from zmq import Context
from zmq import Socket
from zmq import Poller
from zmq import Frame
from zmq import constants
from zmq import device, proxy
from zmq import Stopwatch
from zmq import (
zmq_version,
zmq_version_info,
pyzmq_version,
pyzmq_version_info,
)
def test_devices(self):
"""test device imports"""
import zmq.devices
from zmq.devices import basedevice
from zmq.devices import monitoredqueue
from zmq.devices import monitoredqueuedevice
def test_log(self):
"""test log imports"""
import zmq.log
from zmq.log import handlers
def test_eventloop(self):
"""test eventloop imports"""
import zmq.eventloop
from zmq.eventloop import ioloop
from zmq.eventloop import zmqstream
from zmq.eventloop.minitornado.platform import auto
from zmq.eventloop.minitornado import ioloop
def test_utils(self):
"""test util imports"""
import zmq.utils
from zmq.utils import strtypes
from zmq.utils import jsonapi
def test_ssh(self):
"""test ssh imports"""
from zmq.ssh import tunnel
|
apache-2.0
|
[
3,
1898,
334,
35,
9,
1611,
58,
14449,
23493,
199,
3,
17484,
1334,
314,
2895,
402,
314,
22016,
6289,
844,
14,
199,
199,
646,
984,
199,
504,
2882,
492,
7640,
199,
199,
533,
1379,
32447,
8,
1746,
304,
272,
408,
774,
24339,
446,
314,
12530,
597,
511,
370,
4868,
626,
781,
19051,
1133,
272,
21399,
1015,
13,
31787,
6302,
2552,
1041,
2286,
347,
511,
63,
13517,
8,
277,
304,
267,
408,
396,
13836,
492,
624,
267,
492,
26633,
5493,
347,
511,
63,
1018,
8,
277,
304,
267,
408,
396,
6170,
8925,
624,
267,
687,
26633,
492,
9470,
267,
687,
26633,
492,
17766,
267,
687,
26633,
492,
8467,
1435,
267,
687,
26633,
492,
11726,
267,
687,
26633,
492,
5262,
267,
687,
26633,
492,
2243,
12,
4566,
267,
687,
26633,
492,
8015,
6821,
267,
687,
26633,
492,
334,
7205,
26633,
63,
1023,
12,
288,
26633,
63,
1023,
63,
815,
12,
288,
1134,
21290,
63,
1023,
12,
288,
1134,
21290,
63,
1023,
63,
815,
12,
267,
776,
2286,
347,
511,
63,
6410,
8,
277,
304,
267,
408,
396,
2243,
8925,
624,
267,
492,
26633,
14,
6410,
267,
687,
26633,
14,
6410,
492,
1300,
1782,
267,
687,
26633,
14,
6410,
492,
23821,
1825,
267,
687,
26633,
14,
6410,
492,
23821,
1825,
1782,
2286,
347,
511,
63,
793,
8,
277,
304,
267,
408,
396,
943,
8925,
624,
267,
492,
26633,
14,
793,
267,
687,
26633,
14,
793,
492,
8297,
2286,
347,
511,
63,
1430,
3813,
8,
277,
304,
267,
408,
396,
1566,
3813,
8925,
624,
267,
492,
26633,
14,
1430,
3813,
267,
687,
26633,
14,
1430,
3813,
492,
5890,
3813,
267,
687,
26633,
14,
1430,
3813,
492,
26633,
1745,
267,
687,
26633,
14,
1430,
3813,
14,
77,
826,
8622,
14,
3246,
492,
2599,
267,
687,
26633,
14,
1430,
3813,
14,
77,
826,
8622,
492,
5890,
3813,
2286,
347,
511,
63,
1208,
8,
277,
304,
267,
408,
396,
4884,
8925,
624,
267,
492,
26633,
14,
1208,
267,
687,
26633,
14,
1208,
492,
620,
1313,
267,
687,
26633,
14,
1208,
492,
2022,
1246,
2286,
347,
511,
63,
5510,
8,
277,
304,
267,
408,
396,
8635,
8925,
624,
267,
687,
26633,
14,
5510,
492,
21496,
1362,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1611,
58,
14449,
23493,
199,
3,
17484,
1334,
314,
2895,
402,
314,
22016,
6289,
844,
14,
199,
199,
646,
984,
199,
504,
2882,
492,
7640,
199,
199,
533,
1379,
32447,
8,
1746,
304,
272,
408,
774,
24339,
446,
314,
12530,
597,
511,
370,
4868,
626,
781,
19051,
1133,
272,
21399,
1015,
13,
31787,
6302,
2552,
1041,
2286,
347,
511,
63,
13517,
8,
277,
304,
267,
408,
396,
13836,
492,
624,
267,
492,
26633,
5493,
347,
511,
63,
1018,
8,
277,
304,
267,
408,
396,
6170,
8925,
624,
267,
687,
26633,
492,
9470,
267,
687,
26633,
492,
17766,
267,
687,
26633,
492,
8467,
1435,
267,
687,
26633,
492,
11726,
267,
687,
26633,
492,
5262,
267,
687,
26633,
492,
2243,
12,
4566,
267,
687,
26633,
492,
8015,
6821,
267,
687,
26633,
492,
334,
7205,
26633,
63,
1023,
12,
288,
26633,
63,
1023,
63,
815,
12,
288,
1134,
21290,
63,
1023,
12,
288,
1134,
21290,
63,
1023,
63,
815,
12,
267,
776,
2286,
347,
511,
63,
6410,
8,
277,
304,
267,
408,
396,
2243,
8925,
624,
267,
492,
26633,
14,
6410,
267,
687,
26633,
14,
6410,
492,
1300,
1782,
267,
687,
26633,
14,
6410,
492,
23821,
1825,
267,
687,
26633,
14,
6410,
492,
23821,
1825,
1782,
2286,
347,
511,
63,
793,
8,
277,
304,
267,
408,
396,
943,
8925,
624,
267,
492,
26633,
14,
793,
267,
687,
26633,
14,
793,
492,
8297,
2286,
347,
511,
63,
1430,
3813,
8,
277,
304,
267,
408,
396,
1566,
3813,
8925,
624,
267,
492,
26633,
14,
1430,
3813,
267,
687,
26633,
14,
1430,
3813,
492,
5890,
3813,
267,
687,
26633,
14,
1430,
3813,
492,
26633,
1745,
267,
687,
26633,
14,
1430,
3813,
14,
77,
826,
8622,
14,
3246,
492,
2599,
267,
687,
26633,
14,
1430,
3813,
14,
77,
826,
8622,
492,
5890,
3813,
2286,
347,
511,
63,
1208,
8,
277,
304,
267,
408,
396,
4884,
8925,
624,
267,
492,
26633,
14,
1208,
267,
687,
26633,
14,
1208,
492,
620,
1313,
267,
687,
26633,
14,
1208,
492,
2022,
1246,
2286,
347,
511,
63,
5510,
8,
277,
304,
267,
408,
396,
8635,
8925,
624,
267,
687,
26633,
14,
5510,
492,
21496,
1362,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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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
jseabold/scikit-learn
|
sklearn/manifold/tests/test_locally_linear.py
|
232
|
4761
|
from itertools import product
from nose.tools import assert_true
import numpy as np
from numpy.testing import assert_almost_equal, assert_array_almost_equal
from scipy import linalg
from sklearn import neighbors, manifold
from sklearn.manifold.locally_linear import barycenter_kneighbors_graph
from sklearn.utils.testing import assert_less
from sklearn.utils.testing import ignore_warnings
eigen_solvers = ['dense', 'arpack']
#----------------------------------------------------------------------
# Test utility routines
def test_barycenter_kneighbors_graph():
X = np.array([[0, 1], [1.01, 1.], [2, 0]])
A = barycenter_kneighbors_graph(X, 1)
assert_array_almost_equal(
A.toarray(),
[[0., 1., 0.],
[1., 0., 0.],
[0., 1., 0.]])
A = barycenter_kneighbors_graph(X, 2)
# check that columns sum to one
assert_array_almost_equal(np.sum(A.toarray(), 1), np.ones(3))
pred = np.dot(A.toarray(), X)
assert_less(linalg.norm(pred - X) / X.shape[0], 1)
#----------------------------------------------------------------------
# Test LLE by computing the reconstruction error on some manifolds.
def test_lle_simple_grid():
# note: ARPACK is numerically unstable, so this test will fail for
# some random seeds. We choose 2 because the tests pass.
rng = np.random.RandomState(2)
tol = 0.1
# grid of equidistant points in 2D, n_components = n_dim
X = np.array(list(product(range(5), repeat=2)))
X = X + 1e-10 * rng.uniform(size=X.shape)
n_components = 2
clf = manifold.LocallyLinearEmbedding(n_neighbors=5,
n_components=n_components,
random_state=rng)
tol = 0.1
N = barycenter_kneighbors_graph(X, clf.n_neighbors).toarray()
reconstruction_error = linalg.norm(np.dot(N, X) - X, 'fro')
assert_less(reconstruction_error, tol)
for solver in eigen_solvers:
clf.set_params(eigen_solver=solver)
clf.fit(X)
assert_true(clf.embedding_.shape[1] == n_components)
reconstruction_error = linalg.norm(
np.dot(N, clf.embedding_) - clf.embedding_, 'fro') ** 2
assert_less(reconstruction_error, tol)
assert_almost_equal(clf.reconstruction_error_,
reconstruction_error, decimal=1)
# re-embed a noisy version of X using the transform method
noise = rng.randn(*X.shape) / 100
X_reembedded = clf.transform(X + noise)
assert_less(linalg.norm(X_reembedded - clf.embedding_), tol)
def test_lle_manifold():
rng = np.random.RandomState(0)
# similar test on a slightly more complex manifold
X = np.array(list(product(np.arange(18), repeat=2)))
X = np.c_[X, X[:, 0] ** 2 / 18]
X = X + 1e-10 * rng.uniform(size=X.shape)
n_components = 2
for method in ["standard", "hessian", "modified", "ltsa"]:
clf = manifold.LocallyLinearEmbedding(n_neighbors=6,
n_components=n_components,
method=method, random_state=0)
tol = 1.5 if method == "standard" else 3
N = barycenter_kneighbors_graph(X, clf.n_neighbors).toarray()
reconstruction_error = linalg.norm(np.dot(N, X) - X)
assert_less(reconstruction_error, tol)
for solver in eigen_solvers:
clf.set_params(eigen_solver=solver)
clf.fit(X)
assert_true(clf.embedding_.shape[1] == n_components)
reconstruction_error = linalg.norm(
np.dot(N, clf.embedding_) - clf.embedding_, 'fro') ** 2
details = ("solver: %s, method: %s" % (solver, method))
assert_less(reconstruction_error, tol, msg=details)
assert_less(np.abs(clf.reconstruction_error_ -
reconstruction_error),
tol * reconstruction_error, msg=details)
def test_pipeline():
# check that LocallyLinearEmbedding works fine as a Pipeline
# only checks that no error is raised.
# TODO check that it actually does something useful
from sklearn import pipeline, datasets
X, y = datasets.make_blobs(random_state=0)
clf = pipeline.Pipeline(
[('filter', manifold.LocallyLinearEmbedding(random_state=0)),
('clf', neighbors.KNeighborsClassifier())])
clf.fit(X, y)
assert_less(.9, clf.score(X, y))
# Test the error raised when the weight matrix is singular
def test_singular_matrix():
from nose.tools import assert_raises
M = np.ones((10, 3))
f = ignore_warnings
assert_raises(ValueError, f(manifold.locally_linear_embedding),
M, 2, 1, method='standard', eigen_solver='arpack')
|
bsd-3-clause
|
[
504,
7975,
492,
3336,
199,
504,
11354,
14,
2537,
492,
702,
63,
2052,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
63,
4398,
63,
1452,
12,
702,
63,
1144,
63,
4398,
63,
1452,
199,
504,
7026,
492,
16727,
199,
199,
504,
6357,
492,
15845,
12,
2169,
32294,
199,
504,
6357,
14,
1237,
32294,
14,
31294,
63,
6676,
492,
330,
695,
4218,
63,
75,
11113,
63,
2180,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2003,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
199,
199,
19545,
63,
11263,
83,
275,
788,
7253,
297,
283,
285,
1389,
418,
421,
199,
7656,
8648,
199,
3,
1379,
11420,
14975,
199,
318,
511,
63,
66,
695,
4218,
63,
75,
11113,
63,
2180,
837,
272,
1323,
275,
980,
14,
1144,
4038,
16,
12,
413,
467,
359,
17,
14,
614,
12,
413,
8333,
359,
18,
12,
378,
3934,
339,
437,
275,
330,
695,
4218,
63,
75,
11113,
63,
2180,
8,
56,
12,
413,
9,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
267,
437,
14,
18993,
1062,
267,
3474,
16,
2020,
221,
413,
2020,
221,
378,
8333,
268,
359,
17,
2020,
221,
378,
2020,
221,
378,
8333,
268,
359,
16,
2020,
221,
413,
2020,
221,
378,
19450,
339,
437,
275,
330,
695,
4218,
63,
75,
11113,
63,
2180,
8,
56,
12,
499,
9,
272,
327,
1104,
626,
4362,
3089,
370,
1373,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
1838,
8,
33,
14,
18993,
1062,
413,
395,
980,
14,
4548,
8,
19,
430,
272,
8869,
275,
980,
14,
3287,
8,
33,
14,
18993,
1062,
1323,
9,
272,
702,
63,
2003,
8,
10096,
14,
4791,
8,
5991,
446,
1323,
9,
1182,
1323,
14,
1392,
59,
16,
467,
413,
9,
421,
199,
7656,
8648,
199,
3,
1379,
491,
906,
701,
17226,
314,
295,
12708,
1125,
641,
2005,
2169,
692,
8250,
14,
199,
199,
318,
511,
63,
76,
274,
63,
4129,
63,
3825,
837,
272,
327,
5317,
26,
4160,
6961,
365,
8950,
1183,
625,
11989,
12,
880,
642,
511,
911,
2449,
367,
272,
327,
755,
2005,
2196,
26825,
14,
221,
2136,
11496,
499,
2952,
314,
2295,
986,
14,
272,
9038,
275,
980,
14,
2355,
14,
15726,
8,
18,
9,
272,
9561,
275,
378,
14,
17,
339,
327,
6068,
402,
325,
783,
2686,
867,
4501,
315,
499,
36,
12,
302,
63,
4608,
275,
302,
63,
3572,
272,
1323,
275,
980,
14,
1144,
8,
513,
8,
2558,
8,
1842,
8,
21,
395,
11982,
29,
18,
1724,
272,
1323,
275,
1323,
435,
413,
69,
13,
709,
627,
9038,
14,
8830,
8,
890,
29,
56,
14,
1392,
9,
272,
302,
63,
4608,
275,
499,
272,
6975,
275,
2169,
32294,
14,
3040,
1183,
10608,
27907,
8,
78,
63,
11113,
29,
21,
12,
5101,
302,
63,
4608,
29,
78,
63,
4608,
12,
5101,
2196,
63,
929,
29,
12686,
9,
272,
9561,
275,
378,
14,
17,
339,
653,
275,
330,
695,
4218,
63,
75,
11113,
63,
2180,
8,
56,
12,
6975,
14,
78,
63,
11113,
680,
18993,
342,
272,
295,
12708,
63,
705,
275,
16727,
14,
4791,
8,
1590,
14,
3287,
8,
46,
12,
1323,
9,
446,
1323,
12,
283,
21775,
358,
272,
702,
63,
2003,
8,
264,
12708,
63,
705,
12,
9561,
9,
339,
367,
10196,
315,
11471,
63,
11263,
83,
26,
267,
6975,
14,
409,
63,
1162,
8,
19545,
63,
11263,
29,
11263,
9,
267,
6975,
14,
3269,
8,
56,
9,
267,
702,
63,
2052,
8,
9694,
14,
14275,
3754,
1392,
59,
17,
61,
508,
302,
63,
4608,
9,
267,
295,
12708,
63,
705,
275,
16727,
14,
4791,
8,
288,
980,
14,
3287,
8,
46,
12,
6975,
14,
14275,
4602,
446,
6975,
14,
14275,
3131,
283,
21775,
358,
1011,
499,
398,
702,
63,
2003,
8,
264,
12708,
63,
705,
12,
9561,
9,
267,
702,
63,
4398,
63,
1452,
8,
9694,
14,
264,
12708,
63,
705,
3131,
1169,
295,
12708,
63,
705,
12,
6107,
29,
17,
9,
339,
327,
295,
13,
6427,
282,
949,
19765,
1015,
402,
1323,
1808,
314,
5793,
1083,
272,
11145,
275,
9038,
14,
10843,
2031,
56,
14,
1392,
9,
1182,
2948,
272,
1323,
63,
850,
3665,
770,
275,
6975,
14,
4711,
8,
56,
435,
11145,
9,
272,
702,
63,
2003,
8,
10096,
14,
4791,
8,
56,
63,
850,
3665,
770,
446,
6975,
14,
14275,
29425,
9561,
9,
421,
199,
318,
511,
63,
76,
274,
63,
1237,
32294,
837,
272,
9038,
275,
980,
14,
2355,
14,
15726,
8,
16,
9,
272,
327,
8545,
511,
641,
282,
18023,
1655,
6114,
2169,
32294,
272,
1323,
275,
980,
14,
1144,
8,
513,
8,
2558,
8,
1590,
14,
5605,
8,
1085,
395,
11982,
29,
18,
1724,
272,
1323,
275,
980,
14,
67,
9925,
56,
12,
1323,
3981,
378,
61,
1011,
499,
1182,
6155,
61,
272,
1323,
275,
1323,
435,
413,
69,
13,
709,
627,
9038,
14,
8830,
8,
890,
29,
56,
14,
1392,
9,
272,
302,
63,
4608,
275,
499,
272,
367,
1083,
315,
2097,
6807,
401,
298,
72,
21663,
401,
298,
5540,
401,
298,
76,
1086,
65,
6229,
267,
6975,
275,
2169,
32294,
14,
3040,
1183,
10608,
27907,
8,
78,
63,
11113,
29,
22,
12,
6343,
302,
63,
4608,
29,
78,
63,
4608,
12,
6343,
1083,
29,
765,
12,
2196,
63,
929,
29,
16,
9,
267,
9561,
275,
413,
14,
21,
340,
1083,
508,
298,
6807,
2,
587,
650,
398,
653,
275,
330,
695,
4218,
63,
75,
11113,
63,
2180,
8,
56,
12,
6975,
14,
78,
63,
11113,
680,
18993,
342,
267,
295,
12708,
63,
705,
275,
16727,
14,
4791,
8,
1590,
14,
3287,
8,
46,
12,
1323,
9,
446,
1323,
9,
267,
702,
63,
2003,
8,
264,
12708,
63,
705,
12,
9561,
9,
398,
367,
10196,
315,
11471,
63,
11263,
83,
26,
288,
6975,
14,
409,
63,
1162,
8,
19545,
63,
11263,
29,
11263,
9,
288,
6975,
14,
3269,
8,
56,
9,
288,
702,
63,
2052,
8,
9694,
14,
14275,
3754,
1392,
59,
17,
61,
508,
302,
63,
4608,
9,
288,
295,
12708,
63,
705,
275,
16727,
14,
4791,
8,
355,
980,
14,
3287,
8,
46,
12,
6975,
14,
14275,
4602,
446,
6975,
14,
14275,
3131,
283,
21775,
358,
1011,
499,
288,
2436,
275
] |
[
7975,
492,
3336,
199,
504,
11354,
14,
2537,
492,
702,
63,
2052,
199,
199,
646,
2680,
465,
980,
199,
504,
2680,
14,
4776,
492,
702,
63,
4398,
63,
1452,
12,
702,
63,
1144,
63,
4398,
63,
1452,
199,
504,
7026,
492,
16727,
199,
199,
504,
6357,
492,
15845,
12,
2169,
32294,
199,
504,
6357,
14,
1237,
32294,
14,
31294,
63,
6676,
492,
330,
695,
4218,
63,
75,
11113,
63,
2180,
199,
504,
6357,
14,
1208,
14,
4776,
492,
702,
63,
2003,
199,
504,
6357,
14,
1208,
14,
4776,
492,
3686,
63,
5451,
199,
199,
19545,
63,
11263,
83,
275,
788,
7253,
297,
283,
285,
1389,
418,
421,
199,
7656,
8648,
199,
3,
1379,
11420,
14975,
199,
318,
511,
63,
66,
695,
4218,
63,
75,
11113,
63,
2180,
837,
272,
1323,
275,
980,
14,
1144,
4038,
16,
12,
413,
467,
359,
17,
14,
614,
12,
413,
8333,
359,
18,
12,
378,
3934,
339,
437,
275,
330,
695,
4218,
63,
75,
11113,
63,
2180,
8,
56,
12,
413,
9,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
267,
437,
14,
18993,
1062,
267,
3474,
16,
2020,
221,
413,
2020,
221,
378,
8333,
268,
359,
17,
2020,
221,
378,
2020,
221,
378,
8333,
268,
359,
16,
2020,
221,
413,
2020,
221,
378,
19450,
339,
437,
275,
330,
695,
4218,
63,
75,
11113,
63,
2180,
8,
56,
12,
499,
9,
272,
327,
1104,
626,
4362,
3089,
370,
1373,
272,
702,
63,
1144,
63,
4398,
63,
1452,
8,
1590,
14,
1838,
8,
33,
14,
18993,
1062,
413,
395,
980,
14,
4548,
8,
19,
430,
272,
8869,
275,
980,
14,
3287,
8,
33,
14,
18993,
1062,
1323,
9,
272,
702,
63,
2003,
8,
10096,
14,
4791,
8,
5991,
446,
1323,
9,
1182,
1323,
14,
1392,
59,
16,
467,
413,
9,
421,
199,
7656,
8648,
199,
3,
1379,
491,
906,
701,
17226,
314,
295,
12708,
1125,
641,
2005,
2169,
692,
8250,
14,
199,
199,
318,
511,
63,
76,
274,
63,
4129,
63,
3825,
837,
272,
327,
5317,
26,
4160,
6961,
365,
8950,
1183,
625,
11989,
12,
880,
642,
511,
911,
2449,
367,
272,
327,
755,
2005,
2196,
26825,
14,
221,
2136,
11496,
499,
2952,
314,
2295,
986,
14,
272,
9038,
275,
980,
14,
2355,
14,
15726,
8,
18,
9,
272,
9561,
275,
378,
14,
17,
339,
327,
6068,
402,
325,
783,
2686,
867,
4501,
315,
499,
36,
12,
302,
63,
4608,
275,
302,
63,
3572,
272,
1323,
275,
980,
14,
1144,
8,
513,
8,
2558,
8,
1842,
8,
21,
395,
11982,
29,
18,
1724,
272,
1323,
275,
1323,
435,
413,
69,
13,
709,
627,
9038,
14,
8830,
8,
890,
29,
56,
14,
1392,
9,
272,
302,
63,
4608,
275,
499,
272,
6975,
275,
2169,
32294,
14,
3040,
1183,
10608,
27907,
8,
78,
63,
11113,
29,
21,
12,
5101,
302,
63,
4608,
29,
78,
63,
4608,
12,
5101,
2196,
63,
929,
29,
12686,
9,
272,
9561,
275,
378,
14,
17,
339,
653,
275,
330,
695,
4218,
63,
75,
11113,
63,
2180,
8,
56,
12,
6975,
14,
78,
63,
11113,
680,
18993,
342,
272,
295,
12708,
63,
705,
275,
16727,
14,
4791,
8,
1590,
14,
3287,
8,
46,
12,
1323,
9,
446,
1323,
12,
283,
21775,
358,
272,
702,
63,
2003,
8,
264,
12708,
63,
705,
12,
9561,
9,
339,
367,
10196,
315,
11471,
63,
11263,
83,
26,
267,
6975,
14,
409,
63,
1162,
8,
19545,
63,
11263,
29,
11263,
9,
267,
6975,
14,
3269,
8,
56,
9,
267,
702,
63,
2052,
8,
9694,
14,
14275,
3754,
1392,
59,
17,
61,
508,
302,
63,
4608,
9,
267,
295,
12708,
63,
705,
275,
16727,
14,
4791,
8,
288,
980,
14,
3287,
8,
46,
12,
6975,
14,
14275,
4602,
446,
6975,
14,
14275,
3131,
283,
21775,
358,
1011,
499,
398,
702,
63,
2003,
8,
264,
12708,
63,
705,
12,
9561,
9,
267,
702,
63,
4398,
63,
1452,
8,
9694,
14,
264,
12708,
63,
705,
3131,
1169,
295,
12708,
63,
705,
12,
6107,
29,
17,
9,
339,
327,
295,
13,
6427,
282,
949,
19765,
1015,
402,
1323,
1808,
314,
5793,
1083,
272,
11145,
275,
9038,
14,
10843,
2031,
56,
14,
1392,
9,
1182,
2948,
272,
1323,
63,
850,
3665,
770,
275,
6975,
14,
4711,
8,
56,
435,
11145,
9,
272,
702,
63,
2003,
8,
10096,
14,
4791,
8,
56,
63,
850,
3665,
770,
446,
6975,
14,
14275,
29425,
9561,
9,
421,
199,
318,
511,
63,
76,
274,
63,
1237,
32294,
837,
272,
9038,
275,
980,
14,
2355,
14,
15726,
8,
16,
9,
272,
327,
8545,
511,
641,
282,
18023,
1655,
6114,
2169,
32294,
272,
1323,
275,
980,
14,
1144,
8,
513,
8,
2558,
8,
1590,
14,
5605,
8,
1085,
395,
11982,
29,
18,
1724,
272,
1323,
275,
980,
14,
67,
9925,
56,
12,
1323,
3981,
378,
61,
1011,
499,
1182,
6155,
61,
272,
1323,
275,
1323,
435,
413,
69,
13,
709,
627,
9038,
14,
8830,
8,
890,
29,
56,
14,
1392,
9,
272,
302,
63,
4608,
275,
499,
272,
367,
1083,
315,
2097,
6807,
401,
298,
72,
21663,
401,
298,
5540,
401,
298,
76,
1086,
65,
6229,
267,
6975,
275,
2169,
32294,
14,
3040,
1183,
10608,
27907,
8,
78,
63,
11113,
29,
22,
12,
6343,
302,
63,
4608,
29,
78,
63,
4608,
12,
6343,
1083,
29,
765,
12,
2196,
63,
929,
29,
16,
9,
267,
9561,
275,
413,
14,
21,
340,
1083,
508,
298,
6807,
2,
587,
650,
398,
653,
275,
330,
695,
4218,
63,
75,
11113,
63,
2180,
8,
56,
12,
6975,
14,
78,
63,
11113,
680,
18993,
342,
267,
295,
12708,
63,
705,
275,
16727,
14,
4791,
8,
1590,
14,
3287,
8,
46,
12,
1323,
9,
446,
1323,
9,
267,
702,
63,
2003,
8,
264,
12708,
63,
705,
12,
9561,
9,
398,
367,
10196,
315,
11471,
63,
11263,
83,
26,
288,
6975,
14,
409,
63,
1162,
8,
19545,
63,
11263,
29,
11263,
9,
288,
6975,
14,
3269,
8,
56,
9,
288,
702,
63,
2052,
8,
9694,
14,
14275,
3754,
1392,
59,
17,
61,
508,
302,
63,
4608,
9,
288,
295,
12708,
63,
705,
275,
16727,
14,
4791,
8,
355,
980,
14,
3287,
8,
46,
12,
6975,
14,
14275,
4602,
446,
6975,
14,
14275,
3131,
283,
21775,
358,
1011,
499,
288,
2436,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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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
] |
aarande/nexradaws
|
setup.py
|
1
|
1799
|
import setuptools
setuptools.setup(
name='nexradaws',
version='1.1',
packages=['nexradaws','nexradaws.resources'],
description= 'Query and download NEXRAD data from AWS S3 storage.',
long_description= '''This module is designed to allow you to query and download Nexrad
radar files from Amazon Web Services S3 Storage. The real-time feed and full historical archive of original
resolution (Level II) NEXRAD data, from June 1991 to present, is now freely available on Amazon S3 for anyone to use.
More information can be found here https://aws.amazon.com/public-datasets/nexrad/.
If pyart is installed nexradaws allows you to quickly get pyart objects of downloaded files.
nexradaws supports Python 2.7 and Python 3.6.
Github - https://github.com/aarande/nexradaws
PyPi - https://pypi.python.org/pypi/nexradaws
Docs - http://nexradaws.readthedocs.io/en/latest/
**Required dependencies**
* boto3
* pytz
* six
**Optional dependencies**
* pyart
**Install with pip**::
pip install nexradaws
**Version 1.1**
* Bug fix for varying filename extensions over the years (.gz .V06 etc). Thanks Nick Guy for the PR!''',
url='https://github.com/aarande/nexradaws',
license='MIT',
author='Aaron Anderson',
author_email='aaron.anderson74@yahoo.com',
keywords='weather,radar,nexrad,aws,amazon',
download_url='https://github.com/aarande/nexradaws/archive/1.1.tar.gz',
install_requires=['boto3','pytz','six'],
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Topic :: Scientific/Engineering :: Atmospheric Science',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
],
)
|
mit
|
[
646,
9116,
199,
199,
13623,
14,
2758,
8,
272,
536,
534,
14743,
345,
983,
3569,
297,
272,
1015,
534,
17,
14,
17,
297,
272,
6117,
2968,
14743,
345,
983,
3569,
1673,
14743,
345,
983,
3569,
14,
4435,
995,
272,
1369,
29,
283,
3227,
436,
5235,
653,
1438,
19662,
666,
687,
10168,
428,
19,
4887,
3130,
272,
1846,
63,
1802,
29,
1449,
2765,
859,
365,
19829,
370,
2040,
1265,
370,
1827,
436,
5235,
653,
476,
9525,
199,
345,
4460,
1584,
687,
14347,
6001,
21813,
428,
19,
10533,
14,
710,
3363,
13,
521,
4733,
436,
2615,
32530,
6359,
402,
3379,
199,
12588,
334,
4670,
473,
41,
9,
653,
1438,
19662,
666,
12,
687,
1603,
11474,
9013,
17,
370,
3451,
12,
365,
3063,
20673,
7742,
2808,
641,
14347,
428,
19,
367,
29165,
370,
675,
14,
199,
11053,
2556,
883,
506,
1911,
2348,
4178,
921,
7231,
14,
15144,
14,
957,
15,
3455,
13,
12281,
15,
14743,
9525,
8083,
199,
199,
3917,
1134,
580,
365,
4903,
22761,
345,
983,
3569,
6127,
1265,
370,
23661,
664,
1134,
580,
2251,
402,
13557,
1584,
14,
199,
199,
14743,
345,
983,
3569,
5171,
2018,
499,
14,
23,
436,
2018,
650,
14,
22,
14,
199,
199,
14772,
446,
4178,
921,
5031,
14,
957,
15,
65,
285,
290,
271,
15,
14743,
345,
983,
3569,
199,
199,
2713,
10542,
446,
4178,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
14743,
345,
983,
3569,
199,
199,
27858,
446,
1455,
921,
14743,
345,
983,
3569,
14,
25085,
14,
2308,
15,
287,
15,
7410,
15,
199,
199,
538,
8030,
5124,
538,
199,
199,
10,
6055,
19,
199,
10,
15444,
199,
10,
3816,
199,
199,
538,
7012,
5124,
538,
199,
199,
10,
1134,
580,
199,
199,
538,
8154,
543,
7305,
538,
447,
339,
7305,
3907,
22761,
345,
983,
3569,
199,
199,
538,
3353,
413,
14,
17,
538,
199,
10,
21605,
5325,
367,
17083,
316,
1788,
5478,
1806,
314,
17399,
17048,
6838,
1275,
54,
1690,
5423,
680,
3868,
25088,
653,
2000,
12436,
89,
367,
314,
12218,
1,
18108,
272,
1166,
534,
2859,
921,
5031,
14,
957,
15,
65,
285,
290,
271,
15,
14743,
345,
983,
3569,
297,
272,
4190,
534,
13965,
297,
272,
4132,
534,
33,
285,
265,
1626,
424,
834,
297,
272,
4132,
63,
2123,
534,
65,
285,
265,
14,
11438,
834,
1342,
32,
27231,
14,
957,
297,
272,
7681,
534,
23026,
12,
345,
4460,
12,
14743,
9525,
12,
7231,
12,
15144,
297,
272,
5235,
63,
633,
534,
2859,
921,
5031,
14,
957,
15,
65,
285,
290,
271,
15,
14743,
345,
983,
3569,
15,
6404,
15,
17,
14,
17,
14,
5369,
14,
6838,
297,
272,
3907,
63,
6537,
2968,
10914,
19,
1673,
21948,
1673,
4174,
995,
272,
19137,
1524,
267,
283,
23753,
9795,
3800,
959,
446,
24114,
15,
933,
461,
297,
267,
283,
23910,
23975,
3800,
27491,
15,
497,
1733,
297,
267,
283,
3761,
3800,
25718,
26330,
3800,
10697,
844,
297,
267,
283,
12157,
3800,
16578,
23509,
15,
8524,
15663,
3800,
2854,
573,
23286,
530,
27491,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
272,
2156,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
9116,
199,
199,
13623,
14,
2758,
8,
272,
536,
534,
14743,
345,
983,
3569,
297,
272,
1015,
534,
17,
14,
17,
297,
272,
6117,
2968,
14743,
345,
983,
3569,
1673,
14743,
345,
983,
3569,
14,
4435,
995,
272,
1369,
29,
283,
3227,
436,
5235,
653,
1438,
19662,
666,
687,
10168,
428,
19,
4887,
3130,
272,
1846,
63,
1802,
29,
1449,
2765,
859,
365,
19829,
370,
2040,
1265,
370,
1827,
436,
5235,
653,
476,
9525,
199,
345,
4460,
1584,
687,
14347,
6001,
21813,
428,
19,
10533,
14,
710,
3363,
13,
521,
4733,
436,
2615,
32530,
6359,
402,
3379,
199,
12588,
334,
4670,
473,
41,
9,
653,
1438,
19662,
666,
12,
687,
1603,
11474,
9013,
17,
370,
3451,
12,
365,
3063,
20673,
7742,
2808,
641,
14347,
428,
19,
367,
29165,
370,
675,
14,
199,
11053,
2556,
883,
506,
1911,
2348,
4178,
921,
7231,
14,
15144,
14,
957,
15,
3455,
13,
12281,
15,
14743,
9525,
8083,
199,
199,
3917,
1134,
580,
365,
4903,
22761,
345,
983,
3569,
6127,
1265,
370,
23661,
664,
1134,
580,
2251,
402,
13557,
1584,
14,
199,
199,
14743,
345,
983,
3569,
5171,
2018,
499,
14,
23,
436,
2018,
650,
14,
22,
14,
199,
199,
14772,
446,
4178,
921,
5031,
14,
957,
15,
65,
285,
290,
271,
15,
14743,
345,
983,
3569,
199,
199,
2713,
10542,
446,
4178,
921,
17343,
14,
1548,
14,
1308,
15,
17343,
15,
14743,
345,
983,
3569,
199,
199,
27858,
446,
1455,
921,
14743,
345,
983,
3569,
14,
25085,
14,
2308,
15,
287,
15,
7410,
15,
199,
199,
538,
8030,
5124,
538,
199,
199,
10,
6055,
19,
199,
10,
15444,
199,
10,
3816,
199,
199,
538,
7012,
5124,
538,
199,
199,
10,
1134,
580,
199,
199,
538,
8154,
543,
7305,
538,
447,
339,
7305,
3907,
22761,
345,
983,
3569,
199,
199,
538,
3353,
413,
14,
17,
538,
199,
10,
21605,
5325,
367,
17083,
316,
1788,
5478,
1806,
314,
17399,
17048,
6838,
1275,
54,
1690,
5423,
680,
3868,
25088,
653,
2000,
12436,
89,
367,
314,
12218,
1,
18108,
272,
1166,
534,
2859,
921,
5031,
14,
957,
15,
65,
285,
290,
271,
15,
14743,
345,
983,
3569,
297,
272,
4190,
534,
13965,
297,
272,
4132,
534,
33,
285,
265,
1626,
424,
834,
297,
272,
4132,
63,
2123,
534,
65,
285,
265,
14,
11438,
834,
1342,
32,
27231,
14,
957,
297,
272,
7681,
534,
23026,
12,
345,
4460,
12,
14743,
9525,
12,
7231,
12,
15144,
297,
272,
5235,
63,
633,
534,
2859,
921,
5031,
14,
957,
15,
65,
285,
290,
271,
15,
14743,
345,
983,
3569,
15,
6404,
15,
17,
14,
17,
14,
5369,
14,
6838,
297,
272,
3907,
63,
6537,
2968,
10914,
19,
1673,
21948,
1673,
4174,
995,
272,
19137,
1524,
267,
283,
23753,
9795,
3800,
959,
446,
24114,
15,
933,
461,
297,
267,
283,
23910,
23975,
3800,
27491,
15,
497,
1733,
297,
267,
283,
3761,
3800,
25718,
26330,
3800,
10697,
844,
297,
267,
283,
12157,
3800,
16578,
23509,
15,
8524,
15663,
3800,
2854,
573,
23286,
530,
27491,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
499,
14,
23,
297,
267,
283,
11411,
8466,
3800,
2018,
3800,
650,
297,
272,
2156,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
tonybaloney/st2
|
st2common/st2common/transport/__init__.py
|
10
|
1213
|
# Licensed to the StackStorm, Inc ('StackStorm') 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.
from st2common.transport import liveaction, actionexecutionstate, execution, publishers, reactor
from st2common.transport import bootstrap_utils, utils, connection_retry_wrapper
# TODO(manas) : Exchanges, Queues and RoutingKey design discussion pending.
__all__ = [
'liveaction',
'actionexecutionstate',
'execution',
'publishers',
'reactor',
'bootstrap_utils',
'utils',
'connection_retry_wrapper'
]
|
apache-2.0
|
[
3,
3909,
370,
314,
13894,
933,
1025,
12,
3277,
661,
4851,
933,
1025,
358,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
410,
18,
2330,
14,
5545,
492,
12166,
1287,
12,
1595,
9416,
929,
12,
6451,
12,
2780,
1192,
12,
9655,
199,
504,
410,
18,
2330,
14,
5545,
492,
15865,
63,
1208,
12,
3778,
12,
1950,
63,
7154,
63,
5029,
199,
199,
3,
3254,
8,
1237,
305,
9,
520,
1316,
6627,
12,
10703,
83,
436,
30790,
316,
1197,
12899,
16582,
9413,
14,
199,
199,
363,
452,
363,
275,
359,
272,
283,
6442,
1287,
297,
272,
283,
1287,
9416,
929,
297,
272,
283,
9416,
297,
272,
283,
4763,
1192,
297,
272,
283,
13544,
297,
272,
283,
11146,
63,
1208,
297,
272,
283,
1208,
297,
272,
283,
2105,
63,
7154,
63,
5029,
7,
199,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
3909,
370,
314,
13894,
933,
1025,
12,
3277,
661,
4851,
933,
1025,
358,
1334,
1373,
503,
1655,
199,
3,
11615,
4190,
14024,
14,
221,
1666,
314,
12840,
570,
1854,
543,
199,
3,
642,
1736,
367,
4722,
2556,
12602,
4248,
12715,
14,
199,
3,
710,
14857,
12378,
642,
570,
370,
2047,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
199,
3,
334,
1589,
298,
3761,
3547,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
199,
3,
314,
844,
14,
221,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
410,
18,
2330,
14,
5545,
492,
12166,
1287,
12,
1595,
9416,
929,
12,
6451,
12,
2780,
1192,
12,
9655,
199,
504,
410,
18,
2330,
14,
5545,
492,
15865,
63,
1208,
12,
3778,
12,
1950,
63,
7154,
63,
5029,
199,
199,
3,
3254,
8,
1237,
305,
9,
520,
1316,
6627,
12,
10703,
83,
436,
30790,
316,
1197,
12899,
16582,
9413,
14,
199,
199,
363,
452,
363,
275,
359,
272,
283,
6442,
1287,
297,
272,
283,
1287,
9416,
929,
297,
272,
283,
9416,
297,
272,
283,
4763,
1192,
297,
272,
283,
13544,
297,
272,
283,
11146,
63,
1208,
297,
272,
283,
1208,
297,
272,
283,
2105,
63,
7154,
63,
5029,
7,
199,
61,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
shyamalschandra/picochess
|
libs/requests/packages/chardet/langgreekmodel.py
|
2763
|
12628
|
######################## BEGIN LICENSE BLOCK ########################
# The Original Code is Mozilla Communicator client code.
#
# The Initial Developer of the Original Code is
# Netscape Communications Corporation.
# Portions created by the Initial Developer are Copyright (C) 1998
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
# Mark Pilgrim - port to Python
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
# 02110-1301 USA
######################### END LICENSE BLOCK #########################
# 255: Control characters that usually does not exist in any text
# 254: Carriage/Return
# 253: symbol (punctuation) that does not belong to word
# 252: 0 - 9
# Character Mapping Table:
Latin7_CharToOrderMap = (
255,255,255,255,255,255,255,255,255,255,254,255,255,254,255,255, # 00
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 10
253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253, # 20
252,252,252,252,252,252,252,252,252,252,253,253,253,253,253,253, # 30
253, 82,100,104, 94, 98,101,116,102,111,187,117, 92, 88,113, 85, # 40
79,118,105, 83, 67,114,119, 95, 99,109,188,253,253,253,253,253, # 50
253, 72, 70, 80, 81, 60, 96, 93, 89, 68,120, 97, 77, 86, 69, 55, # 60
78,115, 65, 66, 58, 76,106,103, 87,107,112,253,253,253,253,253, # 70
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 80
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 90
253,233, 90,253,253,253,253,253,253,253,253,253,253, 74,253,253, # a0
253,253,253,253,247,248, 61, 36, 46, 71, 73,253, 54,253,108,123, # b0
110, 31, 51, 43, 41, 34, 91, 40, 52, 47, 44, 53, 38, 49, 59, 39, # c0
35, 48,250, 37, 33, 45, 56, 50, 84, 57,120,121, 17, 18, 22, 15, # d0
124, 1, 29, 20, 21, 3, 32, 13, 25, 5, 11, 16, 10, 6, 30, 4, # e0
9, 8, 14, 7, 2, 12, 28, 23, 42, 24, 64, 75, 19, 26, 27,253, # f0
)
win1253_CharToOrderMap = (
255,255,255,255,255,255,255,255,255,255,254,255,255,254,255,255, # 00
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 10
253,253,253,253,253,253,253,253,253,253,253,253,253,253,253,253, # 20
252,252,252,252,252,252,252,252,252,252,253,253,253,253,253,253, # 30
253, 82,100,104, 94, 98,101,116,102,111,187,117, 92, 88,113, 85, # 40
79,118,105, 83, 67,114,119, 95, 99,109,188,253,253,253,253,253, # 50
253, 72, 70, 80, 81, 60, 96, 93, 89, 68,120, 97, 77, 86, 69, 55, # 60
78,115, 65, 66, 58, 76,106,103, 87,107,112,253,253,253,253,253, # 70
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 80
255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, # 90
253,233, 61,253,253,253,253,253,253,253,253,253,253, 74,253,253, # a0
253,253,253,253,247,253,253, 36, 46, 71, 73,253, 54,253,108,123, # b0
110, 31, 51, 43, 41, 34, 91, 40, 52, 47, 44, 53, 38, 49, 59, 39, # c0
35, 48,250, 37, 33, 45, 56, 50, 84, 57,120,121, 17, 18, 22, 15, # d0
124, 1, 29, 20, 21, 3, 32, 13, 25, 5, 11, 16, 10, 6, 30, 4, # e0
9, 8, 14, 7, 2, 12, 28, 23, 42, 24, 64, 75, 19, 26, 27,253, # f0
)
# Model Table:
# total sequences: 100%
# first 512 sequences: 98.2851%
# first 1024 sequences:1.7001%
# rest sequences: 0.0359%
# negative sequences: 0.0148%
GreekLangModel = (
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,3,2,2,3,3,3,3,3,3,3,3,1,3,3,3,0,2,2,3,3,0,3,0,3,2,0,3,3,3,0,
3,0,0,0,2,0,0,0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nglishLetter': False,
'charsetName': "ISO-8859-7"
}
Win1253GreekModel = {
'charToOrderMap': win1253_CharToOrderMap,
'precedenceMatrix': GreekLangModel,
'mTypicalPositiveRatio': 0.982851,
'keepEnglishLetter': False,
'charsetName': "windows-1253"
}
# flake8: noqa
|
gpl-3.0
|
[
6565,
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
3,
5450,
26,
8612,
4110,
626,
9987,
1630,
440,
2187,
315,
1263,
1318,
199,
3,
22540,
26,
14243,
25220,
15,
1767,
199,
3,
26727,
26,
5272,
334,
25181,
9,
626,
1630,
440,
13511,
370,
4349,
199,
3,
27210,
26,
378,
446,
1749,
199,
199,
3,
17660,
12340,
6957,
26,
199,
27317,
23,
63,
24516,
275,
334,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
221,
327,
8733,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
1616,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
3388,
199,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
4233,
199,
3781,
12,
18051,
12,
1960,
12,
6785,
12,
18729,
12,
16096,
12,
4893,
12,
7524,
12,
7759,
12,
6673,
12,
11775,
12,
7362,
12,
20140,
12,
10523,
12,
9225,
12,
16412,
12,
221,
327,
6335,
199,
13734,
12,
7906,
12,
7320,
12,
20582,
12,
13296,
12,
7636,
12,
7119,
12,
16102,
12,
8806,
12,
6996,
12,
11501,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
5238,
199,
3781,
12,
15323,
12,
10045,
12,
5939,
12,
19071,
12,
5212,
12,
15580,
12,
18969,
12,
17838,
12,
10851,
12,
6708,
12,
15997,
12,
8375,
12,
10300,
12,
14610,
12,
12766,
12,
221,
327,
5212,
199,
14679,
12,
7680,
12,
11738,
12,
14157,
12,
13713,
12,
14646,
12,
7357,
12,
8845,
12,
10513,
12,
7555,
12,
6094,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
10045,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
5939,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
9137,
199,
3781,
12,
10034,
12,
9137,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
9720,
12,
3781,
12,
3781,
12,
221,
327,
282,
16,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
11717,
12,
11242,
12,
17017,
12,
8780,
12,
12426,
12,
17245,
12,
18525,
12,
3781,
12,
13470,
12,
3781,
12,
8079,
12,
4288,
12,
221,
327,
330,
16,
199,
6019,
12,
7105,
12,
8026,
12,
11851,
12,
13385,
12,
8177,
12,
21358,
12,
6335,
12,
14589,
12,
10954,
12,
10868,
12,
13564,
12,
10448,
12,
12260,
12,
8155,
12,
10551,
12,
221,
327,
286,
16,
199,
8685,
12,
9615,
12,
7991,
12,
6877,
12,
9404,
12,
10416,
12,
12001,
12,
5238,
12,
8264,
12,
12699,
12,
6708,
12,
10753,
12,
5557,
12,
6155,
12,
6928,
12,
4114,
12,
221,
327,
366,
16,
199,
7214,
12,
221,
413,
12,
7349,
12,
3388,
12,
7829,
12,
221,
650,
12,
4337,
12,
4944,
12,
5661,
12,
221,
959,
12,
4119,
12,
3193,
12,
1616,
12,
221,
1227,
12,
4233,
12,
221,
841,
12,
221,
327,
325,
16,
523,
1749,
12,
221,
1695,
12,
4329,
12,
221,
1520,
12,
221,
499,
12,
3144,
12,
7294,
12,
6546,
12,
5685,
12,
5504,
12,
5049,
12,
13098,
12,
5851,
12,
7875,
12,
8087,
12,
3781,
12,
221,
327,
289,
16,
199,
9,
199,
199,
2676,
28452,
63,
24516,
275,
334,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
221,
327,
8733,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
1616,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
3388,
199,
6390,
12,
6390,
12
] |
[
16427,
5113,
8068,
11945,
199,
3,
710,
12769,
5495,
365,
17728,
13338,
707,
1890,
1233,
14,
199,
3,
199,
3,
710,
6026,
9607,
402,
314,
12769,
5495,
365,
199,
3,
20433,
18686,
11098,
14,
199,
3,
20825,
2737,
701,
314,
6026,
9607,
787,
1898,
334,
35,
9,
19960,
199,
3,
314,
6026,
9607,
14,
2900,
5924,
5702,
14,
199,
3,
199,
3,
17636,
8,
83,
304,
199,
3,
257,
7173,
19641,
446,
1844,
370,
2018,
199,
3,
199,
3,
961,
3555,
365,
2867,
2032,
27,
1265,
883,
3604,
652,
436,
15,
269,
199,
3,
2811,
652,
1334,
314,
2895,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
465,
3267,
701,
314,
2868,
2290,
2752,
27,
1902,
199,
3,
1015,
499,
14,
17,
402,
314,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
961,
3555,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
1664,
199,
3,
6401,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
6401,
1696,
1684,
199,
3,
844,
3180,
543,
642,
3555,
27,
340,
440,
12,
2218,
370,
314,
2868,
2290,
199,
3,
2752,
12,
3277,
2020,
8026,
11236,
1933,
12,
12066,
11844,
12,
8226,
12,
4828,
199,
3,
11315,
13,
10067,
221,
8217,
199,
19054,
7729,
5113,
8068,
21186,
199,
199,
3,
5450,
26,
8612,
4110,
626,
9987,
1630,
440,
2187,
315,
1263,
1318,
199,
3,
22540,
26,
14243,
25220,
15,
1767,
199,
3,
26727,
26,
5272,
334,
25181,
9,
626,
1630,
440,
13511,
370,
4349,
199,
3,
27210,
26,
378,
446,
1749,
199,
199,
3,
17660,
12340,
6957,
26,
199,
27317,
23,
63,
24516,
275,
334,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
221,
327,
8733,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
1616,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
3388,
199,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
6390,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
4233,
199,
3781,
12,
18051,
12,
1960,
12,
6785,
12,
18729,
12,
16096,
12,
4893,
12,
7524,
12,
7759,
12,
6673,
12,
11775,
12,
7362,
12,
20140,
12,
10523,
12,
9225,
12,
16412,
12,
221,
327,
6335,
199,
13734,
12,
7906,
12,
7320,
12,
20582,
12,
13296,
12,
7636,
12,
7119,
12,
16102,
12,
8806,
12,
6996,
12,
11501,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
5238,
199,
3781,
12,
15323,
12,
10045,
12,
5939,
12,
19071,
12,
5212,
12,
15580,
12,
18969,
12,
17838,
12,
10851,
12,
6708,
12,
15997,
12,
8375,
12,
10300,
12,
14610,
12,
12766,
12,
221,
327,
5212,
199,
14679,
12,
7680,
12,
11738,
12,
14157,
12,
13713,
12,
14646,
12,
7357,
12,
8845,
12,
10513,
12,
7555,
12,
6094,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
221,
327,
10045,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
5939,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
9137,
199,
3781,
12,
10034,
12,
9137,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
9720,
12,
3781,
12,
3781,
12,
221,
327,
282,
16,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
11717,
12,
11242,
12,
17017,
12,
8780,
12,
12426,
12,
17245,
12,
18525,
12,
3781,
12,
13470,
12,
3781,
12,
8079,
12,
4288,
12,
221,
327,
330,
16,
199,
6019,
12,
7105,
12,
8026,
12,
11851,
12,
13385,
12,
8177,
12,
21358,
12,
6335,
12,
14589,
12,
10954,
12,
10868,
12,
13564,
12,
10448,
12,
12260,
12,
8155,
12,
10551,
12,
221,
327,
286,
16,
199,
8685,
12,
9615,
12,
7991,
12,
6877,
12,
9404,
12,
10416,
12,
12001,
12,
5238,
12,
8264,
12,
12699,
12,
6708,
12,
10753,
12,
5557,
12,
6155,
12,
6928,
12,
4114,
12,
221,
327,
366,
16,
199,
7214,
12,
221,
413,
12,
7349,
12,
3388,
12,
7829,
12,
221,
650,
12,
4337,
12,
4944,
12,
5661,
12,
221,
959,
12,
4119,
12,
3193,
12,
1616,
12,
221,
1227,
12,
4233,
12,
221,
841,
12,
221,
327,
325,
16,
523,
1749,
12,
221,
1695,
12,
4329,
12,
221,
1520,
12,
221,
499,
12,
3144,
12,
7294,
12,
6546,
12,
5685,
12,
5504,
12,
5049,
12,
13098,
12,
5851,
12,
7875,
12,
8087,
12,
3781,
12,
221,
327,
289,
16,
199,
9,
199,
199,
2676,
28452,
63,
24516,
275,
334,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
8306,
12,
2299,
12,
2299,
12,
221,
327,
8733,
199,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
2299,
12,
221,
327,
1616,
199,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
3781,
12,
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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
DirtyPiece/dancestudio
|
Build/Tools/Python27/Lib/lib-tk/Tkdnd.py
|
198
|
11488
|
"""Drag-and-drop support for Tkinter.
This is very preliminary. I currently only support dnd *within* one
application, between different windows (or within the same window).
I an trying to make this as generic as possible -- not dependent on
the use of a particular widget or icon type, etc. I also hope that
this will work with Pmw.
To enable an object to be dragged, you must create an event binding
for it that starts the drag-and-drop process. Typically, you should
bind <ButtonPress> to a callback function that you write. The function
should call Tkdnd.dnd_start(source, event), where 'source' is the
object to be dragged, and 'event' is the event that invoked the call
(the argument to your callback function). Even though this is a class
instantiation, the returned instance should not be stored -- it will
be kept alive automatically for the duration of the drag-and-drop.
When a drag-and-drop is already in process for the Tk interpreter, the
call is *ignored*; this normally averts starting multiple simultaneous
dnd processes, e.g. because different button callbacks all
dnd_start().
The object is *not* necessarily a widget -- it can be any
application-specific object that is meaningful to potential
drag-and-drop targets.
Potential drag-and-drop targets are discovered as follows. Whenever
the mouse moves, and at the start and end of a drag-and-drop move, the
Tk widget directly under the mouse is inspected. This is the target
widget (not to be confused with the target object, yet to be
determined). If there is no target widget, there is no dnd target
object. If there is a target widget, and it has an attribute
dnd_accept, this should be a function (or any callable object). The
function is called as dnd_accept(source, event), where 'source' is the
object being dragged (the object passed to dnd_start() above), and
'event' is the most recent event object (generally a <Motion> event;
it can also be <ButtonPress> or <ButtonRelease>). If the dnd_accept()
function returns something other than None, this is the new dnd target
object. If dnd_accept() returns None, or if the target widget has no
dnd_accept attribute, the target widget's parent is considered as the
target widget, and the search for a target object is repeated from
there. If necessary, the search is repeated all the way up to the
root widget. If none of the target widgets can produce a target
object, there is no target object (the target object is None).
The target object thus produced, if any, is called the new target
object. It is compared with the old target object (or None, if there
was no old target widget). There are several cases ('source' is the
source object, and 'event' is the most recent event object):
- Both the old and new target objects are None. Nothing happens.
- The old and new target objects are the same object. Its method
dnd_motion(source, event) is called.
- The old target object was None, and the new target object is not
None. The new target object's method dnd_enter(source, event) is
called.
- The new target object is None, and the old target object is not
None. The old target object's method dnd_leave(source, event) is
called.
- The old and new target objects differ and neither is None. The old
target object's method dnd_leave(source, event), and then the new
target object's method dnd_enter(source, event) is called.
Once this is done, the new target object replaces the old one, and the
Tk mainloop proceeds. The return value of the methods mentioned above
is ignored; if they raise an exception, the normal exception handling
mechanisms take over.
The drag-and-drop processes can end in two ways: a final target object
is selected, or no final target object is selected. When a final
target object is selected, it will always have been notified of the
potential drop by a call to its dnd_enter() method, as described
above, and possibly one or more calls to its dnd_motion() method; its
dnd_leave() method has not been called since the last call to
dnd_enter(). The target is notified of the drop by a call to its
method dnd_commit(source, event).
If no final target object is selected, and there was an old target
object, its dnd_leave(source, event) method is called to complete the
dnd sequence.
Finally, the source object is notified that the drag-and-drop process
is over, by a call to source.dnd_end(target, event), specifying either
the selected target object, or None if no target object was selected.
The source object can use this to implement the commit action; this is
sometimes simpler than to do it in the target's dnd_commit(). The
target's dnd_commit() method could then simply be aliased to
dnd_leave().
At any time during a dnd sequence, the application can cancel the
sequence by calling the cancel() method on the object returned by
dnd_start(). This will call dnd_leave() if a target is currently
active; it will never call dnd_commit().
"""
import Tkinter
# The factory function
def dnd_start(source, event):
h = DndHandler(source, event)
if h.root:
return h
else:
return None
# The class that does the work
class DndHandler:
root = None
def __init__(self, source, event):
if event.num > 5:
return
root = event.widget._root()
try:
root.__dnd
return # Don't start recursive dnd
except AttributeError:
root.__dnd = self
self.root = root
self.source = source
self.target = None
self.initial_button = button = event.num
self.initial_widget = widget = event.widget
self.release_pattern = "<B%d-ButtonRelease-%d>" % (button, button)
self.save_cursor = widget['cursor'] or ""
widget.bind(self.release_pattern, self.on_release)
widget.bind("<Motion>", self.on_motion)
widget['cursor'] = "hand2"
def __del__(self):
root = self.root
self.root = None
if root:
try:
del root.__dnd
except AttributeError:
pass
def on_motion(self, event):
x, y = event.x_root, event.y_root
target_widget = self.initial_widget.winfo_containing(x, y)
source = self.source
new_target = None
while target_widget:
try:
attr = target_widget.dnd_accept
except AttributeError:
pass
else:
new_target = attr(source, event)
if new_target:
break
target_widget = target_widget.master
old_target = self.target
if old_target is new_target:
if old_target:
old_target.dnd_motion(source, event)
else:
if old_target:
self.target = None
old_target.dnd_leave(source, event)
if new_target:
new_target.dnd_enter(source, event)
self.target = new_target
def on_release(self, event):
self.finish(event, 1)
def cancel(self, event=None):
self.finish(event, 0)
def finish(self, event, commit=0):
target = self.target
source = self.source
widget = self.initial_widget
root = self.root
try:
del root.__dnd
self.initial_widget.unbind(self.release_pattern)
self.initial_widget.unbind("<Motion>")
widget['cursor'] = self.save_cursor
self.target = self.source = self.initial_widget = self.root = None
if target:
if commit:
target.dnd_commit(source, event)
else:
target.dnd_leave(source, event)
finally:
source.dnd_end(target, event)
# ----------------------------------------------------------------------
# The rest is here for testing and demonstration purposes only!
class Icon:
def __init__(self, name):
self.name = name
self.canvas = self.label = self.id = None
def attach(self, canvas, x=10, y=10):
if canvas is self.canvas:
self.canvas.coords(self.id, x, y)
return
if self.canvas:
self.detach()
if not canvas:
return
label = Tkinter.Label(canvas, text=self.name,
borderwidth=2, relief="raised")
id = canvas.create_window(x, y, window=label, anchor="nw")
self.canvas = canvas
self.label = label
self.id = id
label.bind("<ButtonPress>", self.press)
def detach(self):
canvas = self.canvas
if not canvas:
return
id = self.id
label = self.label
self.canvas = self.label = self.id = None
canvas.delete(id)
label.destroy()
def press(self, event):
if dnd_start(self, event):
# where the pointer is relative to the label widget:
self.x_off = event.x
self.y_off = event.y
# where the widget is relative to the canvas:
self.x_orig, self.y_orig = self.canvas.coords(self.id)
def move(self, event):
x, y = self.where(self.canvas, event)
self.canvas.coords(self.id, x, y)
def putback(self):
self.canvas.coords(self.id, self.x_orig, self.y_orig)
def where(self, canvas, event):
# where the corner of the canvas is relative to the screen:
x_org = canvas.winfo_rootx()
y_org = canvas.winfo_rooty()
# where the pointer is relative to the canvas widget:
x = event.x_root - x_org
y = event.y_root - y_org
# compensate for initial pointer offset
return x - self.x_off, y - self.y_off
def dnd_end(self, target, event):
pass
class Tester:
def __init__(self, root):
self.top = Tkinter.Toplevel(root)
self.canvas = Tkinter.Canvas(self.top, width=100, height=100)
self.canvas.pack(fill="both", expand=1)
self.canvas.dnd_accept = self.dnd_accept
def dnd_accept(self, source, event):
return self
def dnd_enter(self, source, event):
self.canvas.focus_set() # Show highlight border
x, y = source.where(self.canvas, event)
x1, y1, x2, y2 = source.canvas.bbox(source.id)
dx, dy = x2-x1, y2-y1
self.dndid = self.canvas.create_rectangle(x, y, x+dx, y+dy)
self.dnd_motion(source, event)
def dnd_motion(self, source, event):
x, y = source.where(self.canvas, event)
x1, y1, x2, y2 = self.canvas.bbox(self.dndid)
self.canvas.move(self.dndid, x-x1, y-y1)
def dnd_leave(self, source, event):
self.top.focus_set() # Hide highlight border
self.canvas.delete(self.dndid)
self.dndid = None
def dnd_commit(self, source, event):
self.dnd_leave(source, event)
x, y = source.where(self.canvas, event)
source.attach(self.canvas, x, y)
def test():
root = Tkinter.Tk()
root.geometry("+1+1")
Tkinter.Button(command=root.quit, text="Quit").pack()
t1 = Tester(root)
t1.top.geometry("+1+60")
t2 = Tester(root)
t2.top.geometry("+120+60")
t3 = Tester(root)
t3.top.geometry("+240+60")
i1 = Icon("ICON1")
i2 = Icon("ICON2")
i3 = Icon("ICON3")
i1.attach(t1.canvas)
i2.attach(t2.canvas)
i3.attach(t3.canvas)
root.mainloop()
if __name__ == '__main__':
test()
|
mit
|
[
624,
20287,
13,
460,
13,
4824,
2291,
367,
16826,
14,
199,
199,
2765,
365,
7437,
876,
13769,
695,
14,
221,
473,
5544,
1454,
2291,
366,
977,
627,
12541,
10,
1373,
199,
3578,
12,
3382,
3365,
10061,
334,
269,
4453,
314,
2011,
4353,
680,
199,
199,
41,
376,
9936,
370,
1852,
642,
465,
7809,
465,
3962,
1553,
440,
11410,
641,
199,
1589,
675,
402,
282,
6770,
3938,
503,
7016,
730,
12,
5423,
14,
221,
473,
2597,
3661,
626,
199,
3749,
911,
1736,
543,
510,
14716,
14,
199,
199,
1378,
4756,
376,
909,
370,
506,
18981,
3046,
12,
1265,
1471,
1218,
376,
1566,
11696,
199,
509,
652,
626,
9174,
314,
18981,
13,
460,
13,
4824,
2112,
14,
26914,
12,
1265,
1077,
199,
3409,
665,
4259,
14414,
30,
370,
282,
3233,
805,
626,
1265,
2218,
14,
710,
805,
199,
5626,
1240,
12435,
68,
977,
14,
68,
977,
63,
928,
8,
1365,
12,
1566,
395,
2382,
283,
1365,
7,
365,
314,
199,
785,
370,
506,
18981,
3046,
12,
436,
283,
1430,
7,
365,
314,
1566,
626,
10302,
314,
1240,
199,
8,
1589,
1423,
370,
2195,
3233,
805,
680,
221,
22207,
10617,
642,
365,
282,
1021,
199,
3615,
4466,
425,
12,
314,
2138,
1256,
1077,
440,
506,
5489,
1553,
652,
911,
199,
1235,
16204,
19708,
5847,
367,
314,
7373,
402,
314,
18981,
13,
460,
13,
4824,
14,
199,
199,
11423,
282,
18981,
13,
460,
13,
4824,
365,
2575,
315,
2112,
367,
314,
12435,
12693,
12,
314,
199,
1250,
365,
627,
11996,
10,
27,
642,
12252,
282,
21505,
6617,
3663,
27008,
199,
68,
977,
10358,
12,
325,
14,
71,
14,
2952,
3365,
5528,
13484,
1006,
199,
68,
977,
63,
928,
1252,
199,
199,
1918,
909,
365,
627,
1397,
10,
20513,
282,
3938,
1553,
652,
883,
506,
1263,
199,
3578,
13,
6100,
909,
626,
365,
26562,
370,
12330,
199,
14479,
13,
460,
13,
4824,
4545,
14,
199,
199,
1575,
9443,
18981,
13,
460,
13,
4824,
4545,
787,
24983,
465,
11924,
14,
221,
3979,
5907,
199,
1589,
12817,
14569,
12,
436,
737,
314,
1343,
436,
1284,
402,
282,
18981,
13,
460,
13,
4824,
4057,
12,
314,
199,
15189,
3938,
5370,
1334,
314,
12817,
365,
5261,
1043,
14,
221,
961,
365,
314,
1347,
199,
3440,
334,
1397,
370,
506,
3743,
2972,
543,
314,
1347,
909,
12,
5966,
370,
506,
199,
27248,
680,
221,
982,
2337,
365,
949,
1347,
3938,
12,
2337,
365,
949,
366,
977,
1347,
199,
785,
14,
221,
982,
2337,
365,
282,
1347,
3938,
12,
436,
652,
965,
376,
2225,
199,
68,
977,
63,
5694,
12,
642,
1077,
506,
282,
805,
334,
269,
1263,
4550,
909,
680,
221,
710,
199,
1593,
365,
2797,
465,
366,
977,
63,
5694,
8,
1365,
12,
1566,
395,
2382,
283,
1365,
7,
365,
314,
199,
785,
3769,
18981,
3046,
334,
1589,
909,
3032,
370,
366,
977,
63,
928,
342,
3432,
395,
436,
199,
7,
1430,
7,
365,
314,
4750,
8058,
1566,
909,
334,
2038,
1183,
282,
665,
24875,
30,
1566,
27,
199,
390,
883,
2597,
506,
665,
4259,
14414,
30,
503,
665,
4259,
9625,
10121,
221,
982,
314,
366,
977,
63,
5694,
342,
199,
1593,
2529,
6020,
1163,
2419,
488,
12,
642,
365,
314,
892,
366,
977,
1347,
199,
785,
14,
221,
982,
366,
977,
63,
5694,
342,
2529,
488,
12,
503,
340,
314,
1347,
3938,
965,
949,
199,
68,
977,
63,
5694,
2225,
12,
314,
1347,
3938,
1159,
1676,
365,
8652,
465,
314,
199,
1375,
3938,
12,
436,
314,
2754,
367,
282,
1347,
909,
365,
10877,
687,
199,
16990,
14,
221,
982,
5784,
12,
314,
2754,
365,
10877,
1006,
314,
4340,
1536,
370,
314,
199,
1231,
3938,
14,
221,
982,
7179,
402,
314,
1347,
11114,
883,
7389,
282,
1347,
199,
785,
12,
2337,
365,
949,
1347,
909,
334,
1589,
1347,
909,
365,
488,
680,
199,
199,
1918,
1347,
909,
12850,
13584,
12,
340,
1263,
12,
365,
2797,
314,
892,
1347,
199,
785,
14,
221,
2779,
365,
13524,
543,
314,
2269,
1347,
909,
334,
269,
488,
12,
340,
2337,
199,
10274,
949,
2269,
1347,
3938,
680,
221,
6006,
787,
9978,
5560,
661,
1365,
7,
365,
314,
199,
1365,
909,
12,
436,
283,
1430,
7,
365,
314,
4750,
8058,
1566,
909,
304,
199,
199,
13,
17650,
314,
2269,
436,
892,
1347,
2251,
787,
488,
14,
221,
20550,
10986,
14,
199,
199,
13,
710,
2269,
436,
892,
1347,
2251,
787,
314,
2011,
909,
14,
221,
22940,
1083,
199,
68,
977,
63,
15335,
8,
1365,
12,
1566,
9,
365,
2797,
14,
199,
199,
13,
710,
2269,
1347,
909,
1990,
488,
12,
436,
314,
892,
1347,
909,
365,
440,
199,
403,
14,
221,
710,
892,
1347,
909,
1159,
1083,
366,
977,
63,
4200,
8,
1365,
12,
1566,
9,
365,
199,
3527,
14,
199,
199,
13,
710,
892,
1347,
909,
365,
488,
12,
436,
314,
2269,
1347,
909,
365,
440,
199,
403,
14,
221,
710,
2269,
1347,
909,
1159,
1083,
366,
977,
63,
12422,
8,
1365,
12,
1566,
9,
365,
199,
3527,
14,
199,
199,
13,
710,
2269,
436,
892,
1347,
2251,
14460,
436,
15564,
365,
488,
14,
221,
710,
2269,
199,
1375,
909,
1159,
1083,
366,
977,
63,
12422,
8,
1365,
12,
1566,
395,
436,
2066,
314,
892,
199,
1375,
909,
1159,
1083,
366,
977,
63,
4200,
8,
1365,
12,
1566,
9,
365,
2797,
14,
199,
199,
25690,
642,
365,
4224,
12,
314,
892,
1347,
909,
19058,
314,
2269,
1373,
12,
436,
314,
199,
15189,
2446,
3813,
557,
301,
5923,
14,
221,
710,
372,
574,
402,
314,
3102,
26239,
3432,
199,
374,
5525,
27,
340,
2985,
746,
376,
1919,
12,
314,
3293,
1919,
7252,
199,
278,
10832,
706,
5452,
1806,
14,
199,
199,
1918,
18981,
13,
460,
13,
4824,
10358,
883,
1284,
315,
2877,
15217,
26,
282,
4242,
1347,
909,
199,
374,
4895,
12,
503,
949,
4242,
1347,
909,
365,
4895,
14,
221,
3979,
282,
4242,
199,
1375,
909,
365,
4895,
12,
652,
911,
3544,
1172,
2757,
29535,
402,
314,
199,
24668,
5978,
701,
282,
1240,
370,
2399,
366,
977,
63,
4200,
342,
1083,
12,
465,
11736,
199,
16181,
12,
436,
12570,
1373,
503,
1655,
4882,
370,
2399,
366,
977,
63,
15335,
342,
1083,
27,
2399,
199,
68,
977,
63,
12422,
342,
1083,
965,
440,
2757,
2797,
3967,
314,
2061
] |
[
20287,
13,
460,
13,
4824,
2291,
367,
16826,
14,
199,
199,
2765,
365,
7437,
876,
13769,
695,
14,
221,
473,
5544,
1454,
2291,
366,
977,
627,
12541,
10,
1373,
199,
3578,
12,
3382,
3365,
10061,
334,
269,
4453,
314,
2011,
4353,
680,
199,
199,
41,
376,
9936,
370,
1852,
642,
465,
7809,
465,
3962,
1553,
440,
11410,
641,
199,
1589,
675,
402,
282,
6770,
3938,
503,
7016,
730,
12,
5423,
14,
221,
473,
2597,
3661,
626,
199,
3749,
911,
1736,
543,
510,
14716,
14,
199,
199,
1378,
4756,
376,
909,
370,
506,
18981,
3046,
12,
1265,
1471,
1218,
376,
1566,
11696,
199,
509,
652,
626,
9174,
314,
18981,
13,
460,
13,
4824,
2112,
14,
26914,
12,
1265,
1077,
199,
3409,
665,
4259,
14414,
30,
370,
282,
3233,
805,
626,
1265,
2218,
14,
710,
805,
199,
5626,
1240,
12435,
68,
977,
14,
68,
977,
63,
928,
8,
1365,
12,
1566,
395,
2382,
283,
1365,
7,
365,
314,
199,
785,
370,
506,
18981,
3046,
12,
436,
283,
1430,
7,
365,
314,
1566,
626,
10302,
314,
1240,
199,
8,
1589,
1423,
370,
2195,
3233,
805,
680,
221,
22207,
10617,
642,
365,
282,
1021,
199,
3615,
4466,
425,
12,
314,
2138,
1256,
1077,
440,
506,
5489,
1553,
652,
911,
199,
1235,
16204,
19708,
5847,
367,
314,
7373,
402,
314,
18981,
13,
460,
13,
4824,
14,
199,
199,
11423,
282,
18981,
13,
460,
13,
4824,
365,
2575,
315,
2112,
367,
314,
12435,
12693,
12,
314,
199,
1250,
365,
627,
11996,
10,
27,
642,
12252,
282,
21505,
6617,
3663,
27008,
199,
68,
977,
10358,
12,
325,
14,
71,
14,
2952,
3365,
5528,
13484,
1006,
199,
68,
977,
63,
928,
1252,
199,
199,
1918,
909,
365,
627,
1397,
10,
20513,
282,
3938,
1553,
652,
883,
506,
1263,
199,
3578,
13,
6100,
909,
626,
365,
26562,
370,
12330,
199,
14479,
13,
460,
13,
4824,
4545,
14,
199,
199,
1575,
9443,
18981,
13,
460,
13,
4824,
4545,
787,
24983,
465,
11924,
14,
221,
3979,
5907,
199,
1589,
12817,
14569,
12,
436,
737,
314,
1343,
436,
1284,
402,
282,
18981,
13,
460,
13,
4824,
4057,
12,
314,
199,
15189,
3938,
5370,
1334,
314,
12817,
365,
5261,
1043,
14,
221,
961,
365,
314,
1347,
199,
3440,
334,
1397,
370,
506,
3743,
2972,
543,
314,
1347,
909,
12,
5966,
370,
506,
199,
27248,
680,
221,
982,
2337,
365,
949,
1347,
3938,
12,
2337,
365,
949,
366,
977,
1347,
199,
785,
14,
221,
982,
2337,
365,
282,
1347,
3938,
12,
436,
652,
965,
376,
2225,
199,
68,
977,
63,
5694,
12,
642,
1077,
506,
282,
805,
334,
269,
1263,
4550,
909,
680,
221,
710,
199,
1593,
365,
2797,
465,
366,
977,
63,
5694,
8,
1365,
12,
1566,
395,
2382,
283,
1365,
7,
365,
314,
199,
785,
3769,
18981,
3046,
334,
1589,
909,
3032,
370,
366,
977,
63,
928,
342,
3432,
395,
436,
199,
7,
1430,
7,
365,
314,
4750,
8058,
1566,
909,
334,
2038,
1183,
282,
665,
24875,
30,
1566,
27,
199,
390,
883,
2597,
506,
665,
4259,
14414,
30,
503,
665,
4259,
9625,
10121,
221,
982,
314,
366,
977,
63,
5694,
342,
199,
1593,
2529,
6020,
1163,
2419,
488,
12,
642,
365,
314,
892,
366,
977,
1347,
199,
785,
14,
221,
982,
366,
977,
63,
5694,
342,
2529,
488,
12,
503,
340,
314,
1347,
3938,
965,
949,
199,
68,
977,
63,
5694,
2225,
12,
314,
1347,
3938,
1159,
1676,
365,
8652,
465,
314,
199,
1375,
3938,
12,
436,
314,
2754,
367,
282,
1347,
909,
365,
10877,
687,
199,
16990,
14,
221,
982,
5784,
12,
314,
2754,
365,
10877,
1006,
314,
4340,
1536,
370,
314,
199,
1231,
3938,
14,
221,
982,
7179,
402,
314,
1347,
11114,
883,
7389,
282,
1347,
199,
785,
12,
2337,
365,
949,
1347,
909,
334,
1589,
1347,
909,
365,
488,
680,
199,
199,
1918,
1347,
909,
12850,
13584,
12,
340,
1263,
12,
365,
2797,
314,
892,
1347,
199,
785,
14,
221,
2779,
365,
13524,
543,
314,
2269,
1347,
909,
334,
269,
488,
12,
340,
2337,
199,
10274,
949,
2269,
1347,
3938,
680,
221,
6006,
787,
9978,
5560,
661,
1365,
7,
365,
314,
199,
1365,
909,
12,
436,
283,
1430,
7,
365,
314,
4750,
8058,
1566,
909,
304,
199,
199,
13,
17650,
314,
2269,
436,
892,
1347,
2251,
787,
488,
14,
221,
20550,
10986,
14,
199,
199,
13,
710,
2269,
436,
892,
1347,
2251,
787,
314,
2011,
909,
14,
221,
22940,
1083,
199,
68,
977,
63,
15335,
8,
1365,
12,
1566,
9,
365,
2797,
14,
199,
199,
13,
710,
2269,
1347,
909,
1990,
488,
12,
436,
314,
892,
1347,
909,
365,
440,
199,
403,
14,
221,
710,
892,
1347,
909,
1159,
1083,
366,
977,
63,
4200,
8,
1365,
12,
1566,
9,
365,
199,
3527,
14,
199,
199,
13,
710,
892,
1347,
909,
365,
488,
12,
436,
314,
2269,
1347,
909,
365,
440,
199,
403,
14,
221,
710,
2269,
1347,
909,
1159,
1083,
366,
977,
63,
12422,
8,
1365,
12,
1566,
9,
365,
199,
3527,
14,
199,
199,
13,
710,
2269,
436,
892,
1347,
2251,
14460,
436,
15564,
365,
488,
14,
221,
710,
2269,
199,
1375,
909,
1159,
1083,
366,
977,
63,
12422,
8,
1365,
12,
1566,
395,
436,
2066,
314,
892,
199,
1375,
909,
1159,
1083,
366,
977,
63,
4200,
8,
1365,
12,
1566,
9,
365,
2797,
14,
199,
199,
25690,
642,
365,
4224,
12,
314,
892,
1347,
909,
19058,
314,
2269,
1373,
12,
436,
314,
199,
15189,
2446,
3813,
557,
301,
5923,
14,
221,
710,
372,
574,
402,
314,
3102,
26239,
3432,
199,
374,
5525,
27,
340,
2985,
746,
376,
1919,
12,
314,
3293,
1919,
7252,
199,
278,
10832,
706,
5452,
1806,
14,
199,
199,
1918,
18981,
13,
460,
13,
4824,
10358,
883,
1284,
315,
2877,
15217,
26,
282,
4242,
1347,
909,
199,
374,
4895,
12,
503,
949,
4242,
1347,
909,
365,
4895,
14,
221,
3979,
282,
4242,
199,
1375,
909,
365,
4895,
12,
652,
911,
3544,
1172,
2757,
29535,
402,
314,
199,
24668,
5978,
701,
282,
1240,
370,
2399,
366,
977,
63,
4200,
342,
1083,
12,
465,
11736,
199,
16181,
12,
436,
12570,
1373,
503,
1655,
4882,
370,
2399,
366,
977,
63,
15335,
342,
1083,
27,
2399,
199,
68,
977,
63,
12422,
342,
1083,
965,
440,
2757,
2797,
3967,
314,
2061,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ruschelp/cortex-vfx
|
test/IECore/MeshPrimitiveImplicitSurfaceOp.py
|
12
|
2702
|
##########################################################################
#
# Copyright (c) 2008, Image Engine Design 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 Image Engine Design nor the names of any
# other contributors to this software may be used to endorse or
# promote products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
# IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
##########################################################################
import math
import unittest
from IECore import *
class TestMeshPrimitiveImplicitSurfaceOp( unittest.TestCase ) :
def test( self ) :
""" Test MeshPrimitiveImplicitSurfaceOp """
# Poly sphere of radius 1
m = Reader.create( "test/IECore/data/cobFiles/polySphereQuads.cob" ).read()
radius = 1.0
a = MeshPrimitiveImplicitSurfaceOp()
thresholds = [ -0.8, -0.5, -0.2, 0.0, 0.2, 0.5, 0.8 ]
maxAbsError = 0.2
for threshold in thresholds:
res = a(
resolution = V3i( 20, 20, 20 ),
bound = Box3f(
V3f( -2, -2, -2 ),
V3f( 2, 2, 2 )
),
threshold = threshold,
input = m
)
pData = res["P"].data
# It's now easy to establish how big the new sphere should be, from its original radius and
# the threshold
for p in pData:
self.assert_( math.fabs( p.length() - ( radius + threshold ) ) < maxAbsError )
if __name__ == "__main__":
unittest.main()
|
bsd-3-clause
|
[
26863,
199,
3,
199,
3,
221,
1898,
334,
67,
9,
9079,
12,
6047,
12580,
29410,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
221,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
221,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
221,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
258,
627,
11443,
314,
536,
402,
6047,
12580,
29410,
6590,
314,
1561,
402,
1263,
199,
3,
755,
1163,
8417,
370,
642,
2032,
1443,
506,
1202,
370,
10692,
503,
199,
3,
755,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
199,
3,
755,
5313,
4983,
14,
199,
3,
199,
3,
221,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
199,
3,
221,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
199,
3,
221,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
221,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
221,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
199,
3,
221,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
3,
221,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
221,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
3,
221,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
26863,
199,
199,
646,
3473,
199,
646,
2882,
199,
504,
14707,
492,
627,
4388,
199,
533,
1379,
12241,
22231,
8499,
3137,
16923,
4619,
8,
2882,
14,
1746,
776,
520,
421,
198,
318,
511,
8,
291,
776,
520,
507,
198,
624,
1379,
603,
10613,
22231,
8499,
3137,
16923,
4619,
408,
2742,
198,
3,
16869,
26941,
402,
9362,
413,
507,
198,
77,
275,
23099,
14,
981,
8,
298,
396,
15,
41,
13682,
15,
576,
15,
331,
66,
5535,
15,
6023,
22385,
2371,
9402,
14,
331,
66,
2,
7092,
739,
342,
507,
198,
8017,
275,
413,
14,
16,
2742,
198,
65,
275,
603,
10613,
22231,
8499,
3137,
16923,
4619,
342,
2742,
198,
22611,
275,
359,
446,
16,
14,
24,
12,
446,
16,
14,
21,
12,
446,
16,
14,
18,
12,
378,
14,
16,
12,
378,
14,
18,
12,
378,
14,
21,
12,
378,
14,
24,
1622,
2742,
198,
988,
15447,
547,
275,
378,
14,
18,
2742,
198,
509,
8765,
315,
22757,
26,
6319,
198,
470,
275,
282,
8,
1585,
198,
12588,
275,
812,
19,
73,
8,
3388,
12,
3388,
12,
3388,
2318,
1585,
198,
3556,
275,
20783,
19,
70,
8,
1871,
198,
54,
19,
70,
8,
446,
18,
12,
446,
18,
12,
446,
18,
2318,
1871,
198,
54,
19,
70,
8,
221,
499,
12,
221,
499,
12,
221,
499,
776,
1585,
198,
395,
1585,
198,
7227,
275,
8765,
12,
16737,
198,
1210,
275,
333,
686,
198,
9,
6319,
198,
80,
1451,
275,
522,
905,
48,
4140,
576,
6319,
198,
3,
2779,
1159,
3063,
8837,
370,
16873,
4212,
7282,
314,
892,
26941,
1077,
506,
12,
687,
2399,
3379,
9362,
436,
686,
198,
3,
314,
8765,
686,
198,
509,
299,
315,
299,
1451,
26,
1585,
198,
277,
14,
479,
2531,
3473,
14,
70,
2101,
8,
299,
14,
1267,
342,
446,
334,
9362,
435,
8765,
776,
776,
665,
1390,
15447,
547,
776,
6905,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
3,
199,
3,
221,
1898,
334,
67,
9,
9079,
12,
6047,
12580,
29410,
3277,
14,
2900,
4481,
4644,
14,
199,
3,
199,
3,
221,
10114,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
3,
221,
7100,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
3,
221,
7647,
26,
199,
3,
199,
3,
258,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
199,
3,
199,
3,
258,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
4248,
199,
3,
755,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
315,
314,
199,
3,
755,
3794,
436,
15,
269,
1163,
8418,
2741,
543,
314,
4084,
14,
199,
3,
199,
3,
258,
627,
11443,
314,
536,
402,
6047,
12580,
29410,
6590,
314,
1561,
402,
1263,
199,
3,
755,
1163,
8417,
370,
642,
2032,
1443,
506,
1202,
370,
10692,
503,
199,
3,
755,
10016,
7585,
7131,
687,
642,
2032,
1928,
2488,
6791,
199,
3,
755,
5313,
4983,
14,
199,
3,
199,
3,
221,
5749,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
298,
1179,
199,
3,
221,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
437,
3115,
199,
3,
221,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
3,
221,
6483,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
3,
221,
9836,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
3,
221,
9838,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
199,
3,
221,
9206,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
3,
221,
5603,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
3,
221,
9254,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
3,
221,
4141,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
14,
199,
3,
199,
26863,
199,
199,
646,
3473,
199,
646,
2882,
199,
504,
14707,
492,
627,
4388,
199,
533,
1379,
12241,
22231,
8499,
3137,
16923,
4619,
8,
2882,
14,
1746,
776,
520,
421,
198,
318,
511,
8,
291,
776,
520,
507,
198,
624,
1379,
603,
10613,
22231,
8499,
3137,
16923,
4619,
408,
2742,
198,
3,
16869,
26941,
402,
9362,
413,
507,
198,
77,
275,
23099,
14,
981,
8,
298,
396,
15,
41,
13682,
15,
576,
15,
331,
66,
5535,
15,
6023,
22385,
2371,
9402,
14,
331,
66,
2,
7092,
739,
342,
507,
198,
8017,
275,
413,
14,
16,
2742,
198,
65,
275,
603,
10613,
22231,
8499,
3137,
16923,
4619,
342,
2742,
198,
22611,
275,
359,
446,
16,
14,
24,
12,
446,
16,
14,
21,
12,
446,
16,
14,
18,
12,
378,
14,
16,
12,
378,
14,
18,
12,
378,
14,
21,
12,
378,
14,
24,
1622,
2742,
198,
988,
15447,
547,
275,
378,
14,
18,
2742,
198,
509,
8765,
315,
22757,
26,
6319,
198,
470,
275,
282,
8,
1585,
198,
12588,
275,
812,
19,
73,
8,
3388,
12,
3388,
12,
3388,
2318,
1585,
198,
3556,
275,
20783,
19,
70,
8,
1871,
198,
54,
19,
70,
8,
446,
18,
12,
446,
18,
12,
446,
18,
2318,
1871,
198,
54,
19,
70,
8,
221,
499,
12,
221,
499,
12,
221,
499,
776,
1585,
198,
395,
1585,
198,
7227,
275,
8765,
12,
16737,
198,
1210,
275,
333,
686,
198,
9,
6319,
198,
80,
1451,
275,
522,
905,
48,
4140,
576,
6319,
198,
3,
2779,
1159,
3063,
8837,
370,
16873,
4212,
7282,
314,
892,
26941,
1077,
506,
12,
687,
2399,
3379,
9362,
436,
686,
198,
3,
314,
8765,
686,
198,
509,
299,
315,
299,
1451,
26,
1585,
198,
277,
14,
479,
2531,
3473,
14,
70,
2101,
8,
299,
14,
1267,
342,
446,
334,
9362,
435,
8765,
776,
776,
665,
1390,
15447,
547,
776,
6905,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32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
0,
0,
0
] |
partofthething/home-assistant
|
homeassistant/components/atag/climate.py
|
16
|
3345
|
"""Initialization of ATAG One climate platform."""
from typing import List, Optional
from homeassistant.components.climate import ClimateEntity
from homeassistant.components.climate.const import (
CURRENT_HVAC_HEAT,
CURRENT_HVAC_IDLE,
HVAC_MODE_AUTO,
HVAC_MODE_HEAT,
PRESET_AWAY,
PRESET_BOOST,
SUPPORT_PRESET_MODE,
SUPPORT_TARGET_TEMPERATURE,
)
from homeassistant.const import ATTR_TEMPERATURE
from . import CLIMATE, DOMAIN, AtagEntity
PRESET_SCHEDULE = "Auto"
PRESET_MANUAL = "Manual"
PRESET_EXTEND = "Extend"
SUPPORT_PRESET = [
PRESET_MANUAL,
PRESET_SCHEDULE,
PRESET_EXTEND,
PRESET_AWAY,
PRESET_BOOST,
]
SUPPORT_FLAGS = SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE
HVAC_MODES = [HVAC_MODE_AUTO, HVAC_MODE_HEAT]
async def async_setup_entry(hass, entry, async_add_entities):
"""Load a config entry."""
coordinator = hass.data[DOMAIN][entry.entry_id]
async_add_entities([AtagThermostat(coordinator, CLIMATE)])
class AtagThermostat(AtagEntity, ClimateEntity):
"""Atag climate device."""
@property
def supported_features(self):
"""Return the list of supported features."""
return SUPPORT_FLAGS
@property
def hvac_mode(self) -> Optional[str]:
"""Return hvac operation ie. heat, cool mode."""
if self.coordinator.atag.climate.hvac_mode in HVAC_MODES:
return self.coordinator.atag.climate.hvac_mode
return None
@property
def hvac_modes(self) -> List[str]:
"""Return the list of available hvac operation modes."""
return HVAC_MODES
@property
def hvac_action(self) -> Optional[str]:
"""Return the current running hvac operation."""
if self.coordinator.atag.climate.status:
return CURRENT_HVAC_HEAT
return CURRENT_HVAC_IDLE
@property
def temperature_unit(self):
"""Return the unit of measurement."""
return self.coordinator.atag.climate.temp_unit
@property
def current_temperature(self) -> Optional[float]:
"""Return the current temperature."""
return self.coordinator.atag.climate.temperature
@property
def target_temperature(self) -> Optional[float]:
"""Return the temperature we try to reach."""
return self.coordinator.atag.climate.target_temperature
@property
def preset_mode(self) -> Optional[str]:
"""Return the current preset mode, e.g., auto, manual, fireplace, extend, etc."""
return self.coordinator.atag.climate.preset_mode
@property
def preset_modes(self) -> Optional[List[str]]:
"""Return a list of available preset modes."""
return SUPPORT_PRESET
async def async_set_temperature(self, **kwargs) -> None:
"""Set new target temperature."""
await self.coordinator.atag.climate.set_temp(kwargs.get(ATTR_TEMPERATURE))
self.async_write_ha_state()
async def async_set_hvac_mode(self, hvac_mode: str) -> None:
"""Set new target hvac mode."""
await self.coordinator.atag.climate.set_hvac_mode(hvac_mode)
self.async_write_ha_state()
async def async_set_preset_mode(self, preset_mode: str) -> None:
"""Set new preset mode."""
await self.coordinator.atag.climate.set_preset_mode(preset_mode)
self.async_write_ha_state()
|
mit
|
[
624,
5733,
2072,
402,
437,
6967,
7309,
286,
31583,
4298,
1041,
199,
504,
14090,
492,
3820,
12,
4879,
199,
199,
504,
8846,
14,
4608,
14,
2764,
17684,
492,
445,
31583,
7302,
199,
504,
8846,
14,
4608,
14,
2764,
17684,
14,
1297,
492,
334,
272,
27946,
63,
16566,
1348,
63,
1645,
619,
12,
272,
27946,
63,
16566,
1348,
63,
23715,
12,
272,
869,
26780,
63,
6963,
63,
13883,
12,
272,
869,
26780,
63,
6963,
63,
1645,
619,
12,
272,
510,
18066,
63,
15088,
3448,
12,
272,
510,
18066,
63,
3973,
47,
840,
12,
272,
13756,
63,
14956,
775,
63,
6963,
12,
272,
13756,
63,
9268,
63,
12510,
32559,
12,
199,
9,
199,
504,
8846,
14,
1297,
492,
10762,
63,
12510,
32559,
199,
199,
504,
1275,
492,
13354,
1469,
1951,
12,
15265,
12,
437,
1450,
7302,
199,
199,
14956,
775,
63,
27944,
26579,
275,
298,
3358,
2,
199,
14956,
775,
63,
6588,
13841,
275,
298,
22382,
2,
199,
14956,
775,
63,
2472,
3902,
275,
298,
30775,
2,
199,
10640,
63,
14956,
775,
275,
359,
272,
510,
18066,
63,
6588,
13841,
12,
272,
510,
18066,
63,
27944,
26579,
12,
272,
510,
18066,
63,
2472,
3902,
12,
272,
510,
18066,
63,
15088,
3448,
12,
272,
510,
18066,
63,
3973,
47,
840,
12,
199,
61,
199,
10640,
63,
4831,
275,
13756,
63,
9268,
63,
12510,
32559,
1204,
13756,
63,
14956,
775,
63,
6963,
199,
16566,
1348,
63,
31095,
275,
359,
16566,
1348,
63,
6963,
63,
13883,
12,
869,
26780,
63,
6963,
63,
1645,
619,
61,
421,
199,
4146,
347,
5316,
63,
2758,
63,
2373,
8,
5387,
12,
2397,
12,
5316,
63,
525,
63,
8327,
304,
272,
408,
6200,
282,
1101,
2397,
1041,
272,
29186,
275,
6298,
14,
576,
59,
7378,
1527,
2373,
14,
2373,
63,
344,
61,
272,
5316,
63,
525,
63,
8327,
779,
33,
1450,
31567,
21850,
8,
27380,
12,
13354,
1469,
1951,
3948,
421,
199,
533,
437,
1450,
31567,
21850,
8,
33,
1450,
7302,
12,
445,
31583,
7302,
304,
272,
408,
33,
1450,
286,
31583,
2243,
1041,
339,
768,
1829,
272,
347,
3748,
63,
3179,
8,
277,
304,
267,
408,
1767,
314,
769,
402,
3748,
4534,
1041,
267,
372,
13756,
63,
4831,
339,
768,
1829,
272,
347,
394,
15367,
63,
632,
8,
277,
9,
1035,
4879,
59,
495,
2189,
267,
408,
1767,
394,
15367,
3439,
13446,
14,
20408,
12,
32268,
818,
1041,
267,
340,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
72,
15367,
63,
632,
315,
869,
26780,
63,
31095,
26,
288,
372,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
72,
15367,
63,
632,
267,
372,
488,
339,
768,
1829,
272,
347,
394,
15367,
63,
10433,
8,
277,
9,
1035,
3820,
59,
495,
2189,
267,
408,
1767,
314,
769,
402,
2808,
394,
15367,
3439,
12404,
1041,
267,
372,
869,
26780,
63,
31095,
339,
768,
1829,
272,
347,
394,
15367,
63,
1287,
8,
277,
9,
1035,
4879,
59,
495,
2189,
267,
408,
1767,
314,
1453,
3879,
394,
15367,
3439,
1041,
267,
340,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
1205,
26,
288,
372,
27946,
63,
16566,
1348,
63,
1645,
619,
267,
372,
27946,
63,
16566,
1348,
63,
23715,
339,
768,
1829,
272,
347,
14843,
63,
3248,
8,
277,
304,
267,
408,
1767,
314,
4137,
402,
18216,
1041,
267,
372,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
808,
63,
3248,
339,
768,
1829,
272,
347,
1453,
63,
12954,
8,
277,
9,
1035,
4879,
59,
1609,
2189,
267,
408,
1767,
314,
1453,
14843,
1041,
267,
372,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
12954,
339,
768,
1829,
272,
347,
1347,
63,
12954,
8,
277,
9,
1035,
4879,
59,
1609,
2189,
267,
408,
1767,
314,
14843,
781,
862,
370,
12276,
1041,
267,
372,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
1375,
63,
12954,
339,
768,
1829,
272,
347,
876,
409,
63,
632,
8,
277,
9,
1035,
4879,
59,
495,
2189,
267,
408,
1767,
314,
1453,
876,
409,
818,
12,
325,
14,
71,
2020,
2599,
12,
8722,
12,
5883,
1814,
12,
12247,
12,
5423,
1041,
267,
372,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
25701,
63,
632,
339,
768,
1829,
272,
347,
876,
409,
63,
10433,
8,
277,
9,
1035,
4879,
59,
1296,
59,
495,
27589,
267,
408,
1767,
282,
769,
402,
2808,
876,
409,
12404,
1041,
267,
372,
13756,
63,
14956,
775,
339,
5316,
347,
5316,
63,
409,
63,
12954,
8,
277,
12,
1011,
958,
9,
1035,
488,
26,
267,
408,
1084,
892,
1347,
14843,
1041,
267,
5517,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
409,
63,
808,
8,
958,
14,
362,
8,
5280,
63,
12510,
32559,
430,
267,
291,
14,
4146,
63,
952,
63,
2411,
63,
929,
342,
339,
5316,
347,
5316,
63,
409,
63,
72,
15367,
63,
632,
8,
277,
12,
394,
15367,
63,
632,
26,
620,
9,
1035,
488,
26,
267,
408,
1084,
892,
1347,
394,
15367,
818,
1041,
267,
5517,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
409,
63,
72,
15367,
63,
632,
8,
72,
15367,
63,
632,
9,
267,
291,
14,
4146,
63,
952,
63,
2411,
63,
929,
342,
339,
5316,
347,
5316,
63,
409,
63,
25701,
63,
632,
8,
277,
12,
876,
409,
63,
632,
26,
620,
9,
1035,
488,
26,
267,
408,
1084,
892,
876,
409,
818,
1041,
267,
5517,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
409,
63,
25701,
63,
632,
8,
25701,
63,
632,
9,
267,
291,
14,
4146,
63,
952,
63,
2411,
63,
929,
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
] |
[
5733,
2072,
402,
437,
6967,
7309,
286,
31583,
4298,
1041,
199,
504,
14090,
492,
3820,
12,
4879,
199,
199,
504,
8846,
14,
4608,
14,
2764,
17684,
492,
445,
31583,
7302,
199,
504,
8846,
14,
4608,
14,
2764,
17684,
14,
1297,
492,
334,
272,
27946,
63,
16566,
1348,
63,
1645,
619,
12,
272,
27946,
63,
16566,
1348,
63,
23715,
12,
272,
869,
26780,
63,
6963,
63,
13883,
12,
272,
869,
26780,
63,
6963,
63,
1645,
619,
12,
272,
510,
18066,
63,
15088,
3448,
12,
272,
510,
18066,
63,
3973,
47,
840,
12,
272,
13756,
63,
14956,
775,
63,
6963,
12,
272,
13756,
63,
9268,
63,
12510,
32559,
12,
199,
9,
199,
504,
8846,
14,
1297,
492,
10762,
63,
12510,
32559,
199,
199,
504,
1275,
492,
13354,
1469,
1951,
12,
15265,
12,
437,
1450,
7302,
199,
199,
14956,
775,
63,
27944,
26579,
275,
298,
3358,
2,
199,
14956,
775,
63,
6588,
13841,
275,
298,
22382,
2,
199,
14956,
775,
63,
2472,
3902,
275,
298,
30775,
2,
199,
10640,
63,
14956,
775,
275,
359,
272,
510,
18066,
63,
6588,
13841,
12,
272,
510,
18066,
63,
27944,
26579,
12,
272,
510,
18066,
63,
2472,
3902,
12,
272,
510,
18066,
63,
15088,
3448,
12,
272,
510,
18066,
63,
3973,
47,
840,
12,
199,
61,
199,
10640,
63,
4831,
275,
13756,
63,
9268,
63,
12510,
32559,
1204,
13756,
63,
14956,
775,
63,
6963,
199,
16566,
1348,
63,
31095,
275,
359,
16566,
1348,
63,
6963,
63,
13883,
12,
869,
26780,
63,
6963,
63,
1645,
619,
61,
421,
199,
4146,
347,
5316,
63,
2758,
63,
2373,
8,
5387,
12,
2397,
12,
5316,
63,
525,
63,
8327,
304,
272,
408,
6200,
282,
1101,
2397,
1041,
272,
29186,
275,
6298,
14,
576,
59,
7378,
1527,
2373,
14,
2373,
63,
344,
61,
272,
5316,
63,
525,
63,
8327,
779,
33,
1450,
31567,
21850,
8,
27380,
12,
13354,
1469,
1951,
3948,
421,
199,
533,
437,
1450,
31567,
21850,
8,
33,
1450,
7302,
12,
445,
31583,
7302,
304,
272,
408,
33,
1450,
286,
31583,
2243,
1041,
339,
768,
1829,
272,
347,
3748,
63,
3179,
8,
277,
304,
267,
408,
1767,
314,
769,
402,
3748,
4534,
1041,
267,
372,
13756,
63,
4831,
339,
768,
1829,
272,
347,
394,
15367,
63,
632,
8,
277,
9,
1035,
4879,
59,
495,
2189,
267,
408,
1767,
394,
15367,
3439,
13446,
14,
20408,
12,
32268,
818,
1041,
267,
340,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
72,
15367,
63,
632,
315,
869,
26780,
63,
31095,
26,
288,
372,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
72,
15367,
63,
632,
267,
372,
488,
339,
768,
1829,
272,
347,
394,
15367,
63,
10433,
8,
277,
9,
1035,
3820,
59,
495,
2189,
267,
408,
1767,
314,
769,
402,
2808,
394,
15367,
3439,
12404,
1041,
267,
372,
869,
26780,
63,
31095,
339,
768,
1829,
272,
347,
394,
15367,
63,
1287,
8,
277,
9,
1035,
4879,
59,
495,
2189,
267,
408,
1767,
314,
1453,
3879,
394,
15367,
3439,
1041,
267,
340,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
1205,
26,
288,
372,
27946,
63,
16566,
1348,
63,
1645,
619,
267,
372,
27946,
63,
16566,
1348,
63,
23715,
339,
768,
1829,
272,
347,
14843,
63,
3248,
8,
277,
304,
267,
408,
1767,
314,
4137,
402,
18216,
1041,
267,
372,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
808,
63,
3248,
339,
768,
1829,
272,
347,
1453,
63,
12954,
8,
277,
9,
1035,
4879,
59,
1609,
2189,
267,
408,
1767,
314,
1453,
14843,
1041,
267,
372,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
12954,
339,
768,
1829,
272,
347,
1347,
63,
12954,
8,
277,
9,
1035,
4879,
59,
1609,
2189,
267,
408,
1767,
314,
14843,
781,
862,
370,
12276,
1041,
267,
372,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
1375,
63,
12954,
339,
768,
1829,
272,
347,
876,
409,
63,
632,
8,
277,
9,
1035,
4879,
59,
495,
2189,
267,
408,
1767,
314,
1453,
876,
409,
818,
12,
325,
14,
71,
2020,
2599,
12,
8722,
12,
5883,
1814,
12,
12247,
12,
5423,
1041,
267,
372,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
25701,
63,
632,
339,
768,
1829,
272,
347,
876,
409,
63,
10433,
8,
277,
9,
1035,
4879,
59,
1296,
59,
495,
27589,
267,
408,
1767,
282,
769,
402,
2808,
876,
409,
12404,
1041,
267,
372,
13756,
63,
14956,
775,
339,
5316,
347,
5316,
63,
409,
63,
12954,
8,
277,
12,
1011,
958,
9,
1035,
488,
26,
267,
408,
1084,
892,
1347,
14843,
1041,
267,
5517,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
409,
63,
808,
8,
958,
14,
362,
8,
5280,
63,
12510,
32559,
430,
267,
291,
14,
4146,
63,
952,
63,
2411,
63,
929,
342,
339,
5316,
347,
5316,
63,
409,
63,
72,
15367,
63,
632,
8,
277,
12,
394,
15367,
63,
632,
26,
620,
9,
1035,
488,
26,
267,
408,
1084,
892,
1347,
394,
15367,
818,
1041,
267,
5517,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
409,
63,
72,
15367,
63,
632,
8,
72,
15367,
63,
632,
9,
267,
291,
14,
4146,
63,
952,
63,
2411,
63,
929,
342,
339,
5316,
347,
5316,
63,
409,
63,
25701,
63,
632,
8,
277,
12,
876,
409,
63,
632,
26,
620,
9,
1035,
488,
26,
267,
408,
1084,
892,
876,
409,
818,
1041,
267,
5517,
291,
14,
27380,
14,
419,
71,
14,
2764,
17684,
14,
409,
63,
25701,
63,
632,
8,
25701,
63,
632,
9,
267,
291,
14,
4146,
63,
952,
63,
2411,
63,
929,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
meimz/linux
|
tools/perf/scripts/python/sctop.py
|
1996
|
2102
|
# system call top
# (c) 2010, Tom Zanussi <tzanussi@gmail.com>
# Licensed under the terms of the GNU GPL License version 2
#
# Periodically displays system-wide system call totals, broken down by
# syscall. If a [comm] arg is specified, only syscalls called by
# [comm] are displayed. If an [interval] arg is specified, the display
# will be refreshed every [interval] seconds. The default interval is
# 3 seconds.
import os, sys, thread, time
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 sctop.py [comm] [interval]\n";
for_comm = None
default_interval = 3
interval = default_interval
if len(sys.argv) > 3:
sys.exit(usage)
if len(sys.argv) > 2:
for_comm = sys.argv[1]
interval = int(sys.argv[2])
elif len(sys.argv) > 1:
try:
interval = int(sys.argv[1])
except ValueError:
for_comm = sys.argv[1]
interval = default_interval
syscalls = autodict()
def trace_begin():
thread.start_new_thread(print_syscall_totals, (interval,))
pass
def raw_syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
common_callchain, id, args):
if for_comm is not None:
if common_comm != for_comm:
return
try:
syscalls[id] += 1
except TypeError:
syscalls[id] = 1
def syscalls__sys_enter(event_name, context, common_cpu,
common_secs, common_nsecs, common_pid, common_comm,
id, args):
raw_syscalls__sys_enter(**locals())
def print_syscall_totals(interval):
while 1:
clear_term()
if for_comm is not None:
print "\nsyscall events for %s:\n\n" % (for_comm),
else:
print "\nsyscall events:\n\n",
print "%-40s %10s\n" % ("event", "count"),
print "%-40s %10s\n" % ("----------------------------------------", \
"----------"),
for id, val in sorted(syscalls.iteritems(), key = lambda(k, v): (v, k), \
reverse = True):
try:
print "%-40s %10d\n" % (syscall_name(id), val),
except TypeError:
pass
syscalls.clear()
time.sleep(interval)
|
gpl-2.0
|
[
3,
2656,
1240,
2746,
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,
3492,
11273,
1183,
17561,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
199,
3,
18901,
14,
221,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
199,
3,
359,
1404,
61,
787,
9080,
14,
982,
376,
359,
4284,
61,
1680,
365,
2013,
12,
314,
2929,
199,
3,
911,
506,
9236,
379,
4036,
359,
4284,
61,
4696,
14,
221,
710,
849,
6252,
365,
199,
3,
650,
4696,
14,
199,
199,
646,
747,
12,
984,
12,
2462,
12,
900,
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,
308,
319,
411,
14,
647,
359,
1404,
61,
359,
4284,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
885,
63,
4284,
275,
650,
199,
4284,
275,
849,
63,
4284,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
650,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
198,
4284,
275,
1109,
8,
1274,
14,
3020,
59,
18,
566,
199,
4164,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
4284,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
1722,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
507,
198,
4284,
275,
849,
63,
4284,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
2671,
14,
928,
63,
1222,
63,
2671,
8,
1361,
63,
19444,
63,
17552,
12,
334,
4284,
4641,
199,
198,
1529,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
2330,
63,
1250,
4429,
12,
1305,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
19473,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
1773,
63,
14507,
363,
1274,
63,
4200,
3682,
9350,
1012,
199,
199,
318,
870,
63,
19444,
63,
17552,
8,
4284,
304,
199,
198,
6710,
413,
26,
507,
198,
3584,
63,
5125,
342,
507,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
686,
198,
1361,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
507,
198,
2836,
26,
686,
198,
1361,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
2742,
198,
1361,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
507,
198,
1361,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
5264,
298,
9460,
1288,
2742,
198,
509,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
4671,
420,
3837,
275,
715,
304,
686,
198,
893,
26,
1585,
198,
1361,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
686,
198,
2590,
3146,
26,
1585,
198,
1529,
507,
198,
14507,
14,
3584,
342,
507,
198,
521,
14,
4532,
8,
4284,
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
] |
[
2656,
1240,
2746,
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,
3492,
11273,
1183,
17561,
2656,
13,
13062,
2656,
1240,
23576,
12,
10529,
3224,
701,
199,
3,
18901,
14,
221,
982,
282,
359,
1404,
61,
1680,
365,
2013,
12,
1454,
19473,
2797,
701,
199,
3,
359,
1404,
61,
787,
9080,
14,
982,
376,
359,
4284,
61,
1680,
365,
2013,
12,
314,
2929,
199,
3,
911,
506,
9236,
379,
4036,
359,
4284,
61,
4696,
14,
221,
710,
849,
6252,
365,
199,
3,
650,
4696,
14,
199,
199,
646,
747,
12,
984,
12,
2462,
12,
900,
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,
308,
319,
411,
14,
647,
359,
1404,
61,
359,
4284,
7272,
78,
11436,
199,
199,
509,
63,
1404,
275,
488,
199,
885,
63,
4284,
275,
650,
199,
4284,
275,
849,
63,
4284,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
650,
26,
199,
198,
1274,
14,
2224,
8,
3807,
9,
199,
199,
692,
822,
8,
1274,
14,
3020,
9,
690,
499,
26,
199,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
199,
198,
4284,
275,
1109,
8,
1274,
14,
3020,
59,
18,
566,
199,
4164,
822,
8,
1274,
14,
3020,
9,
690,
413,
26,
199,
198,
893,
26,
507,
198,
4284,
275,
1109,
8,
1274,
14,
3020,
59,
17,
566,
199,
198,
2590,
1722,
26,
507,
198,
509,
63,
1404,
275,
984,
14,
3020,
59,
17,
61,
507,
198,
4284,
275,
849,
63,
4284,
199,
199,
14507,
275,
27477,
342,
199,
199,
318,
3307,
63,
5037,
837,
199,
198,
2671,
14,
928,
63,
1222,
63,
2671,
8,
1361,
63,
19444,
63,
17552,
12,
334,
4284,
4641,
199,
198,
1529,
199,
199,
318,
3066,
63,
14507,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
2330,
63,
1250,
4429,
12,
1305,
12,
1249,
304,
199,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
507,
198,
692,
2863,
63,
1404,
1137,
367,
63,
1404,
26,
686,
198,
1107,
199,
198,
893,
26,
507,
198,
14507,
59,
344,
61,
847,
413,
199,
198,
2590,
3146,
26,
507,
198,
14507,
59,
344,
61,
275,
413,
199,
199,
318,
19473,
363,
1274,
63,
4200,
8,
1430,
63,
354,
12,
1067,
12,
2863,
63,
3541,
12,
199,
198,
2330,
63,
4855,
12,
2863,
63,
9618,
12,
2863,
63,
3150,
12,
2863,
63,
1404,
12,
199,
198,
344,
12,
1249,
304,
199,
198,
1773,
63,
14507,
363,
1274,
63,
4200,
3682,
9350,
1012,
199,
199,
318,
870,
63,
19444,
63,
17552,
8,
4284,
304,
199,
198,
6710,
413,
26,
507,
198,
3584,
63,
5125,
342,
507,
198,
692,
367,
63,
1404,
365,
440,
488,
26,
686,
198,
1361,
1867,
26605,
4474,
367,
450,
83,
3427,
78,
60,
78,
2,
450,
334,
509,
63,
1404,
395,
507,
198,
2836,
26,
686,
198,
1361,
1867,
26605,
4474,
3427,
78,
60,
78,
401,
2742,
198,
1361,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
1430,
401,
298,
835,
1288,
507,
198,
1361,
18301,
2167,
83,
221,
450,
709,
83,
60,
78,
2,
450,
1689,
32111,
401,
971,
5264,
298,
9460,
1288,
2742,
198,
509,
1305,
12,
1139,
315,
3355,
8,
14507,
14,
4611,
1062,
790,
275,
2400,
8,
75,
12,
373,
304,
334,
86,
12,
1022,
395,
971,
4671,
420,
3837,
275,
715,
304,
686,
198,
893,
26,
1585,
198,
1361,
18301,
2167,
83,
221,
450,
709,
68,
60,
78,
2,
450,
334,
19444,
63,
354,
8,
344,
395,
1139,
395,
686,
198,
2590,
3146,
26,
1585,
198,
1529,
507,
198,
14507,
14,
3584,
342,
507,
198,
521,
14,
4532,
8,
4284,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
EvaSDK/sqlalchemy
|
lib/sqlalchemy/orm/attributes.py
|
24
|
56510
|
# orm/attributes.py
# Copyright (C) 2005-2015 the SQLAlchemy authors and contributors
# <see AUTHORS file>
#
# This module is part of SQLAlchemy and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
"""Defines instrumentation for class attributes and their interaction
with instances.
This module is usually not directly visible to user applications, but
defines a large part of the ORM's interactivity.
"""
import operator
from .. import util, event, inspection
from . import interfaces, collections, exc as orm_exc
from .base import instance_state, instance_dict, manager_of_class
from .base import PASSIVE_NO_RESULT, ATTR_WAS_SET, ATTR_EMPTY, NO_VALUE,\
NEVER_SET, NO_CHANGE, CALLABLES_OK, SQL_OK, RELATED_OBJECT_OK,\
INIT_OK, NON_PERSISTENT_OK, LOAD_AGAINST_COMMITTED, PASSIVE_OFF,\
PASSIVE_RETURN_NEVER_SET, PASSIVE_NO_INITIALIZE, PASSIVE_NO_FETCH,\
PASSIVE_NO_FETCH_RELATED, PASSIVE_ONLY_PERSISTENT, NO_AUTOFLUSH
from .base import state_str, instance_str
@inspection._self_inspects
class QueryableAttribute(interfaces._MappedAttribute,
interfaces.InspectionAttr,
interfaces.PropComparator):
"""Base class for :term:`descriptor` objects that intercept
attribute events on behalf of a :class:`.MapperProperty`
object. The actual :class:`.MapperProperty` is accessible
via the :attr:`.QueryableAttribute.property`
attribute.
.. seealso::
:class:`.InstrumentedAttribute`
:class:`.MapperProperty`
:attr:`.Mapper.all_orm_descriptors`
:attr:`.Mapper.attrs`
"""
is_attribute = True
def __init__(self, class_, key, impl=None,
comparator=None, parententity=None,
of_type=None):
self.class_ = class_
self.key = key
self.impl = impl
self.comparator = comparator
self._parententity = parententity
self._of_type = of_type
manager = manager_of_class(class_)
# manager is None in the case of AliasedClass
if manager:
# propagate existing event listeners from
# immediate superclass
for base in manager._bases:
if key in base:
self.dispatch._update(base[key].dispatch)
@util.memoized_property
def _supports_population(self):
return self.impl.supports_population
def get_history(self, instance, passive=PASSIVE_OFF):
return self.impl.get_history(instance_state(instance),
instance_dict(instance), passive)
def __selectable__(self):
# TODO: conditionally attach this method based on clause_element ?
return self
@util.memoized_property
def info(self):
"""Return the 'info' dictionary for the underlying SQL element.
The behavior here is as follows:
* If the attribute is a column-mapped property, i.e.
:class:`.ColumnProperty`, which is mapped directly
to a schema-level :class:`.Column` object, this attribute
will return the :attr:`.SchemaItem.info` dictionary associated
with the core-level :class:`.Column` object.
* If the attribute is a :class:`.ColumnProperty` but is mapped to
any other kind of SQL expression other than a :class:`.Column`,
the attribute will refer to the :attr:`.MapperProperty.info`
dictionary associated directly with the :class:`.ColumnProperty`,
assuming the SQL expression itself does not have its own ``.info``
attribute (which should be the case, unless a user-defined SQL
construct has defined one).
* If the attribute refers to any other kind of
:class:`.MapperProperty`, including :class:`.RelationshipProperty`,
the attribute will refer to the :attr:`.MapperProperty.info`
dictionary associated with that :class:`.MapperProperty`.
* To access the :attr:`.MapperProperty.info` dictionary of the
:class:`.MapperProperty` unconditionally, including for a
:class:`.ColumnProperty` that's associated directly with a
:class:`.schema.Column`, the attribute can be referred to using
:attr:`.QueryableAttribute.property` attribute, as
``MyClass.someattribute.property.info``.
.. versionadded:: 0.8.0
.. seealso::
:attr:`.SchemaItem.info`
:attr:`.MapperProperty.info`
"""
return self.comparator.info
@util.memoized_property
def parent(self):
"""Return an inspection instance representing the parent.
This will be either an instance of :class:`.Mapper`
or :class:`.AliasedInsp`, depending upon the nature
of the parent entity which this attribute is associated
with.
"""
return inspection.inspect(self._parententity)
@property
def expression(self):
return self.comparator.__clause_element__()
def __clause_element__(self):
return self.comparator.__clause_element__()
def _query_clause_element(self):
"""like __clause_element__(), but called specifically
by :class:`.Query` to allow special behavior."""
return self.comparator._query_clause_element()
def adapt_to_entity(self, adapt_to_entity):
assert not self._of_type
return self.__class__(adapt_to_entity.entity,
self.key, impl=self.impl,
comparator=self.comparator.adapt_to_entity(
adapt_to_entity),
parententity=adapt_to_entity)
def of_type(self, cls):
return QueryableAttribute(
self.class_,
self.key,
self.impl,
self.comparator.of_type(cls),
self._parententity,
of_type=cls)
def label(self, name):
return self._query_clause_element().label(name)
def operate(self, op, *other, **kwargs):
return op(self.comparator, *other, **kwargs)
def reverse_operate(self, op, other, **kwargs):
return op(other, self.comparator, **kwargs)
def hasparent(self, state, optimistic=False):
return self.impl.hasparent(state, optimistic=optimistic) is not False
def __getattr__(self, key):
try:
return getattr(self.comparator, key)
except AttributeError:
raise AttributeError(
'Neither %r object nor %r object associated with %s '
'has an attribute %r' % (
type(self).__name__,
type(self.comparator).__name__,
self,
key)
)
def __str__(self):
return "%s.%s" % (self.class_.__name__, self.key)
@util.memoized_property
def property(self):
"""Return the :class:`.MapperProperty` associated with this
:class:`.QueryableAttribute`.
Return values here will commonly be instances of
:class:`.ColumnProperty` or :class:`.RelationshipProperty`.
"""
return self.comparator.property
class InstrumentedAttribute(QueryableAttribute):
"""Class bound instrumented attribute which adds basic
:term:`descriptor` methods.
See :class:`.QueryableAttribute` for a description of most features.
"""
def __set__(self, instance, value):
self.impl.set(instance_state(instance),
instance_dict(instance), value, None)
def __delete__(self, instance):
self.impl.delete(instance_state(instance), instance_dict(instance))
def __get__(self, instance, owner):
if instance is None:
return self
dict_ = instance_dict(instance)
if self._supports_population and self.key in dict_:
return dict_[self.key]
else:
return self.impl.get(instance_state(instance), dict_)
def create_proxied_attribute(descriptor):
"""Create an QueryableAttribute / user descriptor hybrid.
Returns a new QueryableAttribute type that delegates descriptor
behavior and getattr() to the given descriptor.
"""
# TODO: can move this to descriptor_props if the need for this
# function is removed from ext/hybrid.py
class Proxy(QueryableAttribute):
"""Presents the :class:`.QueryableAttribute` interface as a
proxy on top of a Python descriptor / :class:`.PropComparator`
combination.
"""
def __init__(self, class_, key, descriptor,
comparator,
adapt_to_entity=None, doc=None,
original_property=None):
self.class_ = class_
self.key = key
self.descriptor = descriptor
self.original_property = original_property
self._comparator = comparator
self._adapt_to_entity = adapt_to_entity
self.__doc__ = doc
@property
def property(self):
return self.comparator.property
@util.memoized_property
def comparator(self):
if util.callable(self._comparator):
self._comparator = self._comparator()
if self._adapt_to_entity:
self._comparator = self._comparator.adapt_to_entity(
self._adapt_to_entity)
return self._comparator
def adapt_to_entity(self, adapt_to_entity):
return self.__class__(adapt_to_entity.entity,
self.key,
self.descriptor,
self._comparator,
adapt_to_entity)
def __get__(self, instance, owner):
if instance is None:
return self
else:
return self.descriptor.__get__(instance, owner)
def __str__(self):
return "%s.%s" % (self.class_.__name__, self.key)
def __getattr__(self, attribute):
"""Delegate __getattr__ to the original descriptor and/or
comparator."""
try:
return getattr(descriptor, attribute)
except AttributeError:
try:
return getattr(self.comparator, attribute)
except AttributeError:
raise AttributeError(
'Neither %r object nor %r object associated with %s '
'has an attribute %r' % (
type(descriptor).__name__,
type(self.comparator).__name__,
self,
attribute)
)
Proxy.__name__ = type(descriptor).__name__ + 'Proxy'
util.monkeypatch_proxied_specials(Proxy, type(descriptor),
name='descriptor',
from_instance=descriptor)
return Proxy
OP_REMOVE = util.symbol("REMOVE")
OP_APPEND = util.symbol("APPEND")
OP_REPLACE = util.symbol("REPLACE")
class Event(object):
"""A token propagated throughout the course of a chain of attribute
events.
Serves as an indicator of the source of the event and also provides
a means of controlling propagation across a chain of attribute
operations.
The :class:`.Event` object is sent as the ``initiator`` argument
when dealing with the :meth:`.AttributeEvents.append`,
:meth:`.AttributeEvents.set`,
and :meth:`.AttributeEvents.remove` events.
The :class:`.Event` object is currently interpreted by the backref
event handlers, and is used to control the propagation of operations
across two mutually-dependent attributes.
.. versionadded:: 0.9.0
:var impl: The :class:`.AttributeImpl` which is the current event
initiator.
:var op: The symbol :attr:`.OP_APPEND`, :attr:`.OP_REMOVE` or
:attr:`.OP_REPLACE`, indicating the source operation.
"""
__slots__ = 'impl', 'op', 'parent_token'
def __init__(self, attribute_impl, op):
self.impl = attribute_impl
self.op = op
self.parent_token = self.impl.parent_token
def __eq__(self, other):
return isinstance(other, Event) and \
other.impl is self.impl and \
other.op == self.op
@property
def key(self):
return self.impl.key
def hasparent(self, state):
return self.impl.hasparent(state)
class AttributeImpl(object):
"""internal implementation for instrumented attributes."""
def __init__(self, class_, key,
callable_, dispatch, trackparent=False, extension=None,
compare_function=None, active_history=False,
parent_token=None, expire_missing=True,
send_modified_events=True,
**kwargs):
"""Construct an AttributeImpl.
\class_
associated class
key
string name of the attribute
\callable_
optional function which generates a callable based on a parent
instance, which produces the "default" values for a scalar or
collection attribute when it's first accessed, if not present
already.
trackparent
if True, attempt to track if an instance has a parent attached
to it via this attribute.
extension
a single or list of AttributeExtension object(s) which will
receive set/delete/append/remove/etc. events. Deprecated.
The event package is now used.
compare_function
a function that compares two values which are normally
assignable to this attribute.
active_history
indicates that get_history() should always return the "old" value,
even if it means executing a lazy callable upon attribute change.
parent_token
Usually references the MapperProperty, used as a key for
the hasparent() function to identify an "owning" attribute.
Allows multiple AttributeImpls to all match a single
owner attribute.
expire_missing
if False, don't add an "expiry" callable to this attribute
during state.expire_attributes(None), if no value is present
for this key.
send_modified_events
if False, the InstanceState._modified_event method will have no
effect; this means the attribute will never show up as changed in a
history entry.
"""
self.class_ = class_
self.key = key
self.callable_ = callable_
self.dispatch = dispatch
self.trackparent = trackparent
self.parent_token = parent_token or self
self.send_modified_events = send_modified_events
if compare_function is None:
self.is_equal = operator.eq
else:
self.is_equal = compare_function
# TODO: pass in the manager here
# instead of doing a lookup
attr = manager_of_class(class_)[key]
for ext in util.to_list(extension or []):
ext._adapt_listener(attr, ext)
if active_history:
self.dispatch._active_history = True
self.expire_missing = expire_missing
__slots__ = (
'class_', 'key', 'callable_', 'dispatch', 'trackparent',
'parent_token', 'send_modified_events', 'is_equal', 'expire_missing'
)
def __str__(self):
return "%s.%s" % (self.class_.__name__, self.key)
def _get_active_history(self):
"""Backwards compat for impl.active_history"""
return self.dispatch._active_history
def _set_active_history(self, value):
self.dispatch._active_history = value
active_history = property(_get_active_history, _set_active_history)
def hasparent(self, state, optimistic=False):
"""Return the boolean value of a `hasparent` flag attached to
the given state.
The `optimistic` flag determines what the default return value
should be if no `hasparent` flag can be located.
As this function is used to determine if an instance is an
*orphan*, instances that were loaded from storage should be
assumed to not be orphans, until a True/False value for this
flag is set.
An instance attribute that is loaded by a callable function
will also not have a `hasparent` flag.
"""
msg = "This AttributeImpl is not configured to track parents."
assert self.trackparent, msg
return state.parents.get(id(self.parent_token), optimistic) \
is not False
def sethasparent(self, state, parent_state, value):
"""Set a boolean flag on the given item corresponding to
whether or not it is attached to a parent object via the
attribute represented by this ``InstrumentedAttribute``.
"""
msg = "This AttributeImpl is not configured to track parents."
assert self.trackparent, msg
id_ = id(self.parent_token)
if value:
state.parents[id_] = parent_state
else:
if id_ in state.parents:
last_parent = state.parents[id_]
if last_parent is not False and \
last_parent.key != parent_state.key:
if last_parent.obj() is None:
raise orm_exc.StaleDataError(
"Removing state %s from parent "
"state %s along attribute '%s', "
"but the parent record "
"has gone stale, can't be sure this "
"is the most recent parent." %
(state_str(state),
state_str(parent_state),
self.key))
return
state.parents[id_] = False
def get_history(self, state, dict_, passive=PASSIVE_OFF):
raise NotImplementedError()
def get_all_pending(self, state, dict_, passive=PASSIVE_NO_INITIALIZE):
"""Return a list of tuples of (state, obj)
for all objects in this attribute's current state
+ history.
Only applies to object-based attributes.
This is an inlining of existing functionality
which roughly corresponds to:
get_state_history(
state,
key,
passive=PASSIVE_NO_INITIALIZE).sum()
"""
raise NotImplementedError()
def initialize(self, state, dict_):
"""Initialize the given state's attribute with an empty value."""
# As of 1.0, we don't actually set a value in
# dict_. This is so that the state of the object does not get
# modified without emitting the appropriate events.
return None
def get(self, state, dict_, passive=PASSIVE_OFF):
"""Retrieve a value from the given object.
If a callable is assembled on this object's attribute, and
passive is False, the callable will be executed and the
resulting value will be set as the new value for this attribute.
"""
if self.key in dict_:
return dict_[self.key]
else:
# if history present, don't load
key = self.key
if key not in state.committed_state or \
state.committed_state[key] is NEVER_SET:
if not passive & CALLABLES_OK:
return PASSIVE_NO_RESULT
if key in state.expired_attributes:
value = state._load_expired(state, passive)
elif key in state.callables:
callable_ = state.callables[key]
value = callable_(state, passive)
elif self.callable_:
value = self.callable_(state, passive)
else:
value = ATTR_EMPTY
if value is PASSIVE_NO_RESULT or value is NEVER_SET:
return value
elif value is ATTR_WAS_SET:
try:
return dict_[key]
except KeyError:
# TODO: no test coverage here.
raise KeyError(
"Deferred loader for attribute "
"%r failed to populate "
"correctly" % key)
elif value is not ATTR_EMPTY:
return self.set_committed_value(state, dict_, value)
if not passive & INIT_OK:
return NEVER_SET
else:
# Return a new, empty value
return self.initialize(state, dict_)
def append(self, state, dict_, value, initiator, passive=PASSIVE_OFF):
self.set(state, dict_, value, initiator, passive=passive)
def remove(self, state, dict_, value, initiator, passive=PASSIVE_OFF):
self.set(state, dict_, None, initiator,
passive=passive, check_old=value)
def pop(self, state, dict_, value, initiator, passive=PASSIVE_OFF):
self.set(state, dict_, None, initiator,
passive=passive, check_old=value, pop=True)
def set(self, state, dict_, value, initiator,
passive=PASSIVE_OFF, check_old=None, pop=False):
raise NotImplementedError()
def get_committed_value(self, state, dict_, passive=PASSIVE_OFF):
"""return the unchanged value of this attribute"""
if self.key in state.committed_state:
value = state.committed_state[self.key]
if value in (NO_VALUE, NEVER_SET):
return None
else:
return value
else:
return self.get(state, dict_, passive=passive)
def set_committed_value(self, state, dict_, value):
"""set an attribute value on the given instance and 'commit' it."""
dict_[self.key] = value
state._commit(dict_, [self.key])
return value
class ScalarAttributeImpl(AttributeImpl):
"""represents a scalar value-holding InstrumentedAttribute."""
accepts_scalar_loader = True
uses_objects = False
supports_population = True
collection = False
__slots__ = '_replace_token', '_append_token', '_remove_token'
def __init__(self, *arg, **kw):
super(ScalarAttributeImpl, self).__init__(*arg, **kw)
self._replace_token = self._append_token = None
self._remove_token = None
def _init_append_token(self):
self._replace_token = self._append_token = Event(self, OP_REPLACE)
return self._replace_token
_init_append_or_replace_token = _init_append_token
def _init_remove_token(self):
self._remove_token = Event(self, OP_REMOVE)
return self._remove_token
def delete(self, state, dict_):
# TODO: catch key errors, convert to attributeerror?
if self.dispatch._active_history:
old = self.get(state, dict_, PASSIVE_RETURN_NEVER_SET)
else:
old = dict_.get(self.key, NO_VALUE)
if self.dispatch.remove:
self.fire_remove_event(state, dict_, old, self._remove_token)
state._modified_event(dict_, self, old)
del dict_[self.key]
def get_history(self, state, dict_, passive=PASSIVE_OFF):
if self.key in dict_:
return History.from_scalar_attribute(self, state, dict_[self.key])
else:
if passive & INIT_OK:
passive ^= INIT_OK
current = self.get(state, dict_, passive=passive)
if current is PASSIVE_NO_RESULT:
return HISTORY_BLANK
else:
return History.from_scalar_attribute(self, state, current)
def set(self, state, dict_, value, initiator,
passive=PASSIVE_OFF, check_old=None, pop=False):
if self.dispatch._active_history:
old = self.get(state, dict_, PASSIVE_RETURN_NEVER_SET)
else:
old = dict_.get(self.key, NO_VALUE)
if self.dispatch.set:
value = self.fire_replace_event(state, dict_,
value, old, initiator)
state._modified_event(dict_, self, old)
dict_[self.key] = value
def fire_replace_event(self, state, dict_, value, previous, initiator):
for fn in self.dispatch.set:
value = fn(
state, value, previous,
initiator or self._replace_token or
self._init_append_or_replace_token())
return value
def fire_remove_event(self, state, dict_, value, initiator):
for fn in self.dispatch.remove:
fn(state, value,
initiator or self._remove_token or self._init_remove_token())
@property
def type(self):
self.property.columns[0].type
class ScalarObjectAttributeImpl(ScalarAttributeImpl):
"""represents a scalar-holding InstrumentedAttribute,
where the target object is also instrumented.
Adds events to delete/set operations.
"""
accepts_scalar_loader = False
uses_objects = True
supports_population = True
collection = False
__slots__ = ()
def delete(self, state, dict_):
old = self.get(state, dict_)
self.fire_remove_event(
state, dict_, old,
self._remove_token or self._init_remove_token())
del dict_[self.key]
def get_history(self, state, dict_, passive=PASSIVE_OFF):
if self.key in dict_:
return History.from_object_attribute(self, state, dict_[self.key])
else:
if passive & INIT_OK:
passive ^= INIT_OK
current = self.get(state, dict_, passive=passive)
if current is PASSIVE_NO_RESULT:
return HISTORY_BLANK
else:
return History.from_object_attribute(self, state, current)
def get_all_pending(self, state, dict_, passive=PASSIVE_NO_INITIALIZE):
if self.key in dict_:
current = dict_[self.key]
elif passive & CALLABLES_OK:
current = self.get(state, dict_, passive=passive)
else:
return []
# can't use __hash__(), can't use __eq__() here
if current is not None and \
current is not PASSIVE_NO_RESULT and \
current is not NEVER_SET:
ret = [(instance_state(current), current)]
else:
ret = [(None, None)]
if self.key in state.committed_state:
original = state.committed_state[self.key]
if original is not None and \
original is not PASSIVE_NO_RESULT and \
original is not NEVER_SET and \
original is not current:
ret.append((instance_state(original), original))
return ret
def set(self, state, dict_, value, initiator,
passive=PASSIVE_OFF, check_old=None, pop=False):
"""Set a value on the given InstanceState.
"""
if self.dispatch._active_history:
old = self.get(
state, dict_, passive=PASSIVE_ONLY_PERSISTENT | NO_AUTOFLUSH)
else:
old = self.get(state, dict_, passive=PASSIVE_NO_FETCH ^ INIT_OK)
if check_old is not None and \
old is not PASSIVE_NO_RESULT and \
check_old is not old:
if pop:
return
else:
raise ValueError(
"Object %s not associated with %s on attribute '%s'" % (
instance_str(check_old),
state_str(state),
self.key
))
value = self.fire_replace_event(state, dict_, value, old, initiator)
dict_[self.key] = value
def fire_remove_event(self, state, dict_, value, initiator):
if self.trackparent and value is not None:
self.sethasparent(instance_state(value), state, False)
for fn in self.dispatch.remove:
fn(state, value, initiator or
self._remove_token or self._init_remove_token())
state._modified_event(dict_, self, value)
def fire_replace_event(self, state, dict_, value, previous, initiator):
if self.trackparent:
if (previous is not value and
previous not in (None, PASSIVE_NO_RESULT, NEVER_SET)):
self.sethasparent(instance_state(previous), state, False)
for fn in self.dispatch.set:
value = fn(
state, value, previous, initiator or
self._replace_token or self._init_append_or_replace_token())
state._modified_event(dict_, self, previous)
if self.trackparent:
if value is not None:
self.sethasparent(instance_state(value), state, True)
return value
class CollectionAttributeImpl(AttributeImpl):
"""A collection-holding attribute that instruments changes in membership.
Only handles collections of instrumented objects.
InstrumentedCollectionAttribute holds an arbitrary, user-specified
container object (defaulting to a list) and brokers access to the
CollectionAdapter, a "view" onto that object that presents consistent bag
semantics to the orm layer independent of the user data implementation.
"""
accepts_scalar_loader = False
uses_objects = True
supports_population = True
collection = True
__slots__ = 'copy', 'collection_factory', '_append_token', '_remove_token'
def __init__(self, class_, key, callable_, dispatch,
typecallable=None, trackparent=False, extension=None,
copy_function=None, compare_function=None, **kwargs):
super(CollectionAttributeImpl, self).__init__(
class_,
key,
callable_, dispatch,
trackparent=trackparent,
extension=extension,
compare_function=compare_function,
**kwargs)
if copy_function is None:
copy_function = self.__copy
self.copy = copy_function
self.collection_factory = typecallable
self._append_token = None
self._remove_token = None
if getattr(self.collection_factory, "_sa_linker", None):
@event.listens_for(self, "init_collection")
def link(target, collection, collection_adapter):
collection._sa_linker(collection_adapter)
@event.listens_for(self, "dispose_collection")
def unlink(target, collection, collection_adapter):
collection._sa_linker(None)
def _init_append_token(self):
self._append_token = Event(self, OP_APPEND)
return self._append_token
def _init_remove_token(self):
self._remove_token = Event(self, OP_REMOVE)
return self._remove_token
def __copy(self, item):
return [y for y in collections.collection_adapter(item)]
def get_history(self, state, dict_, passive=PASSIVE_OFF):
current = self.get(state, dict_, passive=passive)
if current is PASSIVE_NO_RESULT:
return HISTORY_BLANK
else:
return History.from_collection(self, state, current)
def get_all_pending(self, state, dict_, passive=PASSIVE_NO_INITIALIZE):
# NOTE: passive is ignored here at the moment
if self.key not in dict_:
return []
current = dict_[self.key]
current = getattr(current, '_sa_adapter')
if self.key in state.committed_state:
original = state.committed_state[self.key]
if original not in (NO_VALUE, NEVER_SET):
current_states = [((c is not None) and
instance_state(c) or None, c)
for c in current]
original_states = [((c is not None) and
instance_state(c) or None, c)
for c in original]
current_set = dict(current_states)
original_set = dict(original_states)
return \
[(s, o) for s, o in current_states
if s not in original_set] + \
[(s, o) for s, o in current_states
if s in original_set] + \
[(s, o) for s, o in original_states
if s not in current_set]
return [(instance_state(o), o) for o in current]
def fire_append_event(self, state, dict_, value, initiator):
for fn in self.dispatch.append:
value = fn(
state, value,
initiator or self._append_token or self._init_append_token())
state._modified_event(dict_, self, NEVER_SET, True)
if self.trackparent and value is not None:
self.sethasparent(instance_state(value), state, True)
return value
def fire_pre_remove_event(self, state, dict_, initiator):
state._modified_event(dict_, self, NEVER_SET, True)
def fire_remove_event(self, state, dict_, value, initiator):
if self.trackparent and value is not None:
self.sethasparent(instance_state(value), state, False)
for fn in self.dispatch.remove:
fn(state, value,
initiator or self._remove_token or self._init_remove_token())
state._modified_event(dict_, self, NEVER_SET, True)
def delete(self, state, dict_):
if self.key not in dict_:
return
state._modified_event(dict_, self, NEVER_SET, True)
collection = self.get_collection(state, state.dict)
collection.clear_with_event()
# TODO: catch key errors, convert to attributeerror?
del dict_[self.key]
def initialize(self, state, dict_):
"""Initialize this attribute with an empty collection."""
_, user_data = self._initialize_collection(state)
dict_[self.key] = user_data
return user_data
def _initialize_collection(self, state):
adapter, collection = state.manager.initialize_collection(
self.key, state, self.collection_factory)
self.dispatch.init_collection(state, collection, adapter)
return adapter, collection
def append(self, state, dict_, value, initiator, passive=PASSIVE_OFF):
collection = self.get_collection(state, dict_, passive=passive)
if collection is PASSIVE_NO_RESULT:
value = self.fire_append_event(state, dict_, value, initiator)
assert self.key not in dict_, \
"Collection was loaded during event handling."
state._get_pending_mutation(self.key).append(value)
else:
collection.append_with_event(value, initiator)
def remove(self, state, dict_, value, initiator, passive=PASSIVE_OFF):
collection = self.get_collection(state, state.dict, passive=passive)
if collection is PASSIVE_NO_RESULT:
self.fire_remove_event(state, dict_, value, initiator)
assert self.key not in dict_, \
"Collection was loaded during event handling."
state._get_pending_mutation(self.key).remove(value)
else:
collection.remove_with_event(value, initiator)
def pop(self, state, dict_, value, initiator, passive=PASSIVE_OFF):
try:
# TODO: better solution here would be to add
# a "popper" role to collections.py to complement
# "remover".
self.remove(state, dict_, value, initiator, passive=passive)
except (ValueError, KeyError, IndexError):
pass
def set(self, state, dict_, value, initiator,
passive=PASSIVE_OFF, pop=False):
"""Set a value on the given object.
"""
self._set_iterable(
state, dict_, value,
lambda adapter, i: adapter.adapt_like_to_iterable(i))
def _set_iterable(self, state, dict_, iterable, adapter=None):
"""Set a collection value from an iterable of state-bearers.
``adapter`` is an optional callable invoked with a CollectionAdapter
and the iterable. Should return an iterable of state-bearing
instances suitable for appending via a CollectionAdapter. Can be used
for, e.g., adapting an incoming dictionary into an iterator of values
rather than keys.
"""
# pulling a new collection first so that an adaptation exception does
# not trigger a lazy load of the old collection.
new_collection, user_data = self._initialize_collection(state)
if adapter:
new_values = list(adapter(new_collection, iterable))
else:
new_values = list(iterable)
old = self.get(state, dict_, passive=PASSIVE_ONLY_PERSISTENT)
if old is PASSIVE_NO_RESULT:
old = self.initialize(state, dict_)
elif old is iterable:
# ignore re-assignment of the current collection, as happens
# implicitly with in-place operators (foo.collection |= other)
return
# place a copy of "old" in state.committed_state
state._modified_event(dict_, self, old, True)
old_collection = old._sa_adapter
dict_[self.key] = user_data
collections.bulk_replace(new_values, old_collection, new_collection)
del old._sa_adapter
self.dispatch.dispose_collection(state, old, old_collection)
def _invalidate_collection(self, collection):
adapter = getattr(collection, '_sa_adapter')
adapter.invalidated = True
def set_committed_value(self, state, dict_, value):
"""Set an attribute value on the given instance and 'commit' it."""
collection, user_data = self._initialize_collection(state)
if value:
collection.append_multiple_without_event(value)
state.dict[self.key] = user_data
state._commit(dict_, [self.key])
if self.key in state._pending_mutations:
# pending items exist. issue a modified event,
# add/remove new items.
state._modified_event(dict_, self, user_data, True)
pending = state._pending_mutations.pop(self.key)
added = pending.added_items
removed = pending.deleted_items
for item in added:
collection.append_without_event(item)
for item in removed:
collection.remove_without_event(item)
return user_data
def get_collection(self, state, dict_,
user_data=None, passive=PASSIVE_OFF):
"""Retrieve the CollectionAdapter associated with the given state.
Creates a new CollectionAdapter if one does not exist.
"""
if user_data is None:
user_data = self.get(state, dict_, passive=passive)
if user_data is PASSIVE_NO_RESULT:
return user_data
return getattr(user_data, '_sa_adapter')
def backref_listeners(attribute, key, uselist):
"""Apply listeners to synchronize a two-way relationship."""
# use easily recognizable names for stack traces
parent_token = attribute.impl.parent_token
parent_impl = attribute.impl
def _acceptable_key_err(child_state, initiator, child_impl):
raise ValueError(
"Bidirectional attribute conflict detected: "
'Passing object %s to attribute "%s" '
'triggers a modify event on attribute "%s" '
'via the backref "%s".' % (
state_str(child_state),
initiator.parent_token,
child_impl.parent_token,
attribute.impl.parent_token
)
)
def emit_backref_from_scalar_set_event(state, child, oldchild, initiator):
if oldchild is child:
return child
if oldchild is not None and \
oldchild is not PASSIVE_NO_RESULT and \
oldchild is not NEVER_SET:
# With lazy=None, there's no guarantee that the full collection is
# present when updating via a backref.
old_state, old_dict = instance_state(oldchild),\
instance_dict(oldchild)
impl = old_state.manager[key].impl
if initiator.impl is not impl or \
initiator.op not in (OP_REPLACE, OP_REMOVE):
impl.pop(old_state,
old_dict,
state.obj(),
parent_impl._append_token or
parent_impl._init_append_token(),
passive=PASSIVE_NO_FETCH)
if child is not None:
child_state, child_dict = instance_state(child),\
instance_dict(child)
child_impl = child_state.manager[key].impl
if initiator.parent_token is not parent_token and \
initiator.parent_token is not child_impl.parent_token:
_acceptable_key_err(state, initiator, child_impl)
elif initiator.impl is not child_impl or \
initiator.op not in (OP_APPEND, OP_REPLACE):
child_impl.append(
child_state,
child_dict,
state.obj(),
initiator,
passive=PASSIVE_NO_FETCH)
return child
def emit_backref_from_collection_append_event(state, child, initiator):
if child is None:
return
child_state, child_dict = instance_state(child), \
instance_dict(child)
child_impl = child_state.manager[key].impl
if initiator.parent_token is not parent_token and \
initiator.parent_token is not child_impl.parent_token:
_acceptable_key_err(state, initiator, child_impl)
elif initiator.impl is not child_impl or \
initiator.op not in (OP_APPEND, OP_REPLACE):
child_impl.append(
child_state,
child_dict,
state.obj(),
initiator,
passive=PASSIVE_NO_FETCH)
return child
def emit_backref_from_collection_remove_event(state, child, initiator):
if child is not None:
child_state, child_dict = instance_state(child),\
instance_dict(child)
child_impl = child_state.manager[key].impl
if initiator.impl is not child_impl or \
initiator.op not in (OP_REMOVE, OP_REPLACE):
child_impl.pop(
child_state,
child_dict,
state.obj(),
initiator,
passive=PASSIVE_NO_FETCH)
if uselist:
event.listen(attribute, "append",
emit_backref_from_collection_append_event,
retval=True, raw=True)
else:
event.listen(attribute, "set",
emit_backref_from_scalar_set_event,
retval=True, raw=True)
# TODO: need coverage in test/orm/ of remove event
event.listen(attribute, "remove",
emit_backref_from_collection_remove_event,
retval=True, raw=True)
_NO_HISTORY = util.symbol('NO_HISTORY')
_NO_STATE_SYMBOLS = frozenset([
id(PASSIVE_NO_RESULT),
id(NO_VALUE),
id(NEVER_SET)])
History = util.namedtuple("History", [
"added", "unchanged", "deleted"
])
class History(History):
"""A 3-tuple of added, unchanged and deleted values,
representing the changes which have occurred on an instrumented
attribute.
The easiest way to get a :class:`.History` object for a particular
attribute on an object is to use the :func:`.inspect` function::
from sqlalchemy import inspect
hist = inspect(myobject).attrs.myattribute.history
Each tuple member is an iterable sequence:
* ``added`` - the collection of items added to the attribute (the first
tuple element).
* ``unchanged`` - the collection of items that have not changed on the
attribute (the second tuple element).
* ``deleted`` - the collection of items that have been removed from the
attribute (the third tuple element).
"""
def __bool__(self):
return self != HISTORY_BLANK
__nonzero__ = __bool__
def empty(self):
"""Return True if this :class:`.History` has no changes
and no existing, unchanged state.
"""
return not bool(
(self.added or self.deleted)
or self.unchanged
)
def sum(self):
"""Return a collection of added + unchanged + deleted."""
return (self.added or []) +\
(self.unchanged or []) +\
(self.deleted or [])
def non_deleted(self):
"""Return a collection of added + unchanged."""
return (self.added or []) +\
(self.unchanged or [])
def non_added(self):
"""Return a collection of unchanged + deleted."""
return (self.unchanged or []) +\
(self.deleted or [])
def has_changes(self):
"""Return True if this :class:`.History` has changes."""
return bool(self.added or self.deleted)
def as_state(self):
return History(
[(c is not None)
and instance_state(c) or None
for c in self.added],
[(c is not None)
and instance_state(c) or None
for c in self.unchanged],
[(c is not None)
and instance_state(c) or None
for c in self.deleted],
)
@classmethod
def from_scalar_attribute(cls, attribute, state, current):
original = state.committed_state.get(attribute.key, _NO_HISTORY)
if original is _NO_HISTORY:
if current is NEVER_SET:
return cls((), (), ())
else:
return cls((), [current], ())
# don't let ClauseElement expressions here trip things up
elif attribute.is_equal(current, original) is True:
return cls((), [current], ())
else:
# current convention on native scalars is to not
# include information
# about missing previous value in "deleted", but
# we do include None, which helps in some primary
# key situations
if id(original) in _NO_STATE_SYMBOLS:
deleted = ()
else:
deleted = [original]
if current is NEVER_SET:
return cls((), (), deleted)
else:
return cls([current], (), deleted)
@classmethod
def from_object_attribute(cls, attribute, state, current):
original = state.committed_state.get(attribute.key, _NO_HISTORY)
if original is _NO_HISTORY:
if current is NO_VALUE or current is NEVER_SET:
return cls((), (), ())
else:
return cls((), [current], ())
elif current is original:
return cls((), [current], ())
else:
# current convention on related objects is to not
# include information
# about missing previous value in "deleted", and
# to also not include None - the dependency.py rules
# ignore the None in any case.
if id(original) in _NO_STATE_SYMBOLS or original is None:
deleted = ()
else:
deleted = [original]
if current is NO_VALUE or current is NEVER_SET:
return cls((), (), deleted)
else:
return cls([current], (), deleted)
@classmethod
def from_collection(cls, attribute, state, current):
original = state.committed_state.get(attribute.key, _NO_HISTORY)
if current is NO_VALUE or current is NEVER_SET:
return cls((), (), ())
current = getattr(current, '_sa_adapter')
if original in (NO_VALUE, NEVER_SET):
return cls(list(current), (), ())
elif original is _NO_HISTORY:
return cls((), list(current), ())
else:
current_states = [((c is not None) and instance_state(c)
or None, c)
for c in current
]
original_states = [((c is not None) and instance_state(c)
or None, c)
for c in original
]
current_set = dict(current_states)
original_set = dict(original_states)
return cls(
[o for s, o in current_states if s not in original_set],
[o for s, o in current_states if s in original_set],
[o for s, o in original_states if s not in current_set]
)
HISTORY_BLANK = History(None, None, None)
def get_history(obj, key, passive=PASSIVE_OFF):
"""Return a :class:`.History` record for the given object
and attribute key.
:param obj: an object whose class is instrumented by the
attributes package.
:param key: string attribute name.
:param passive: indicates loading behavior for the attribute
if the value is not already present. This is a
bitflag attribute, which defaults to the symbol
:attr:`.PASSIVE_OFF` indicating all necessary SQL
should be emitted.
"""
if passive is True:
util.warn_deprecated("Passing True for 'passive' is deprecated. "
"Use attributes.PASSIVE_NO_INITIALIZE")
passive = PASSIVE_NO_INITIALIZE
elif passive is False:
util.warn_deprecated("Passing False for 'passive' is "
"deprecated. Use attributes.PASSIVE_OFF")
passive = PASSIVE_OFF
return get_state_history(instance_state(obj), key, passive)
def get_state_history(state, key, passive=PASSIVE_OFF):
return state.get_history(key, passive)
def has_parent(cls, obj, key, optimistic=False):
"""TODO"""
manager = manager_of_class(cls)
state = instance_state(obj)
return manager.has_parent(state, key, optimistic)
def register_attribute(class_, key, **kw):
comparator = kw.pop('comparator', None)
parententity = kw.pop('parententity', None)
doc = kw.pop('doc', None)
desc = register_descriptor(class_, key,
comparator, parententity, doc=doc)
register_attribute_impl(class_, key, **kw)
return desc
def register_attribute_impl(class_, key,
uselist=False, callable_=None,
useobject=False,
impl_class=None, backref=None, **kw):
manager = manager_of_class(class_)
if uselist:
factory = kw.pop('typecallable', None)
typecallable = manager.instrument_collection_class(
key, factory or list)
else:
typecallable = kw.pop('typecallable', None)
dispatch = manager[key].dispatch
if impl_class:
impl = impl_class(class_, key, typecallable, dispatch, **kw)
elif uselist:
impl = CollectionAttributeImpl(class_, key, callable_, dispatch,
typecallable=typecallable, **kw)
elif useobject:
impl = ScalarObjectAttributeImpl(class_, key, callable_,
dispatch, **kw)
else:
impl = ScalarAttributeImpl(class_, key, callable_, dispatch, **kw)
manager[key].impl = impl
if backref:
backref_listeners(manager[key], backref, uselist)
manager.post_configure_attribute(key)
return manager[key]
def register_descriptor(class_, key, comparator=None,
parententity=None, doc=None):
manager = manager_of_class(class_)
descriptor = InstrumentedAttribute(class_, key, comparator=comparator,
parententity=parententity)
descriptor.__doc__ = doc
manager.instrument_attribute(key, descriptor)
return descriptor
def unregister_attribute(class_, key):
manager_of_class(class_).uninstrument_attribute(key)
def init_collection(obj, key):
"""Initialize a collection attribute and return the collection adapter.
This function is used to provide direct access to collection internals
for a previously unloaded attribute. e.g.::
collection_adapter = init_collection(someobject, 'elements')
for elem in values:
collection_adapter.append_without_event(elem)
For an easier way to do the above, see
:func:`~sqlalchemy.orm.attributes.set_committed_value`.
obj is an instrumented object instance. An InstanceState
is accepted directly for backwards compatibility but
this usage is deprecated.
"""
state = instance_state(obj)
dict_ = state.dict
return init_state_collection(state, dict_, key)
def init_state_collection(state, dict_, key):
"""Initialize a collection attribute and return the collection adapter."""
attr = state.manager[key].impl
user_data = attr.initialize(state, dict_)
return attr.get_collection(state, dict_, user_data)
def set_committed_value(instance, key, value):
"""Set the value of an attribute with no history events.
Cancels any previous history present. The value should be
a scalar value for scalar-holding attributes, or
an iterable for any collection-holding attribute.
This is the same underlying method used when a lazy loader
fires off and loads additional data from the database.
In particular, this method can be used by application code
which has loaded additional attributes or collections through
separate queries, which can then be attached to an instance
as though it were part of its original loaded state.
"""
state, dict_ = instance_state(instance), instance_dict(instance)
state.manager[key].impl.set_committed_value(state, dict_, value)
def set_attribute(instance, key, value):
"""Set the value of an attribute, firing history events.
This function may be used regardless of instrumentation
applied directly to the class, i.e. no descriptors are required.
Custom attribute management schemes will need to make usage
of this method to establish attribute state as understood
by SQLAlchemy.
"""
state, dict_ = instance_state(instance), instance_dict(instance)
state.manager[key].impl.set(state, dict_, value, None)
def get_attribute(instance, key):
"""Get the value of an attribute, firing any callables required.
This function may be used regardless of instrumentation
applied directly to the class, i.e. no descriptors are required.
Custom attribute management schemes will need to make usage
of this method to make usage of attribute state as understood
by SQLAlchemy.
"""
state, dict_ = instance_state(instance), instance_dict(instance)
return state.manager[key].impl.get(state, dict_)
def del_attribute(instance, key):
"""Delete the value of an attribute, firing history events.
This function may be used regardless of instrumentation
applied directly to the class, i.e. no descriptors are required.
Custom attribute management schemes will need to make usage
of this method to establish attribute state as understood
by SQLAlchemy.
"""
state, dict_ = instance_state(instance), instance_dict(instance)
state.manager[key].impl.delete(state, dict_)
def flag_modified(instance, key):
"""Mark an attribute on an instance as 'modified'.
This sets the 'modified' flag on the instance and
establishes an unconditional change event for the given attribute.
"""
state, dict_ = instance_state(instance), instance_dict(instance)
impl = state.manager[key].impl
state._modified_event(dict_, impl, NO_VALUE, force=True)
|
mit
|
[
3,
9813,
15,
2987,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
7806,
314,
14303,
11462,
436,
8417,
199,
3,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
23891,
14498,
425,
367,
1021,
3004,
436,
3932,
18752,
199,
1045,
4454,
14,
199,
199,
2765,
859,
365,
9987,
440,
5370,
8917,
370,
922,
13103,
12,
1325,
199,
14334,
282,
7031,
1777,
402,
314,
23383,
1159,
315,
2967,
67,
4191,
14,
421,
199,
624,
199,
199,
646,
4182,
199,
504,
2508,
492,
4884,
12,
1566,
12,
5261,
10303,
199,
504,
1275,
492,
8386,
12,
5055,
12,
3178,
465,
9813,
63,
2804,
199,
199,
504,
1275,
1095,
492,
1256,
63,
929,
12,
1256,
63,
807,
12,
5256,
63,
1618,
63,
533,
199,
199,
504,
1275,
1095,
492,
510,
26953,
63,
2826,
63,
9517,
12,
10762,
63,
55,
1179,
63,
3597,
12,
10762,
63,
13993,
12,
4825,
63,
7041,
4202,
272,
7110,
2111,
63,
3597,
12,
4825,
63,
16062,
12,
24251,
17041,
63,
3593,
12,
5385,
63,
3593,
12,
820,
2901,
6989,
63,
9868,
63,
3593,
4202,
272,
20199,
63,
3593,
12,
11214,
63,
4227,
29367,
1309,
63,
3593,
12,
3412,
1554,
63,
1254,
33,
7834,
63,
5378,
20779,
1149,
12,
510,
26953,
63,
7517,
4202,
272,
510,
26953,
63,
9677,
63,
6388,
2111,
63,
3597,
12,
510,
26953,
63,
2826,
63,
13768,
11025,
12,
510,
26953,
63,
2826,
63,
32097,
4202,
272,
510,
26953,
63,
2826,
63,
32097,
63,
13604,
6989,
12,
510,
26953,
63,
10452,
63,
4227,
29367,
1309,
12,
4825,
63,
13883,
32762,
199,
504,
1275,
1095,
492,
1174,
63,
495,
12,
1256,
63,
495,
421,
199,
32,
25098,
423,
277,
63,
10955,
83,
199,
533,
8133,
461,
1646,
8,
7436,
423,
20698,
1646,
12,
586,
8386,
14,
13962,
10303,
7144,
12,
586,
8386,
14,
9955,
26636,
304,
272,
408,
1563,
1021,
367,
520,
5125,
1705,
4120,
64,
2251,
626,
13926,
272,
2225,
4474,
641,
506,
10220,
402,
282,
520,
533,
5026,
11880,
3697,
64,
272,
909,
14,
221,
710,
3503,
520,
533,
5026,
11880,
3697,
64,
365,
17909,
272,
4799,
314,
520,
962,
5026,
3227,
461,
1646,
14,
1829,
64,
272,
2225,
14,
2378,
2508,
19352,
447,
398,
520,
533,
5026,
607,
495,
12546,
1646,
64,
398,
520,
533,
5026,
11880,
3697,
64,
398,
520,
962,
5026,
11880,
14,
452,
63,
1025,
63,
17752,
64,
398,
520,
962,
5026,
11880,
14,
3288,
64,
272,
408,
339,
365,
63,
3215,
275,
715,
339,
347,
636,
826,
721,
277,
12,
1021,
3131,
790,
12,
11512,
29,
403,
12,
326,
32138,
29,
403,
12,
13566,
724,
1701,
29,
403,
12,
326,
402,
63,
466,
29,
403,
304,
267,
291,
14,
533,
63,
275,
1021,
63,
267,
291,
14,
498,
275,
790,
267,
291,
14,
5472,
275,
11512,
267,
291,
14,
27417,
275,
32138,
267,
291,
423,
9575,
724,
1701,
275,
13566,
724,
1701,
267,
291,
423,
1618,
63,
466,
275,
402,
63,
466,
398,
5256,
275,
5256,
63,
1618,
63,
533,
8,
533,
4602,
267,
327,
5256,
365,
488,
315,
314,
1930,
402,
15170,
11185,
2543,
267,
340,
5256,
26,
288,
327,
19843,
3411,
1566,
19946,
687,
288,
327,
8569,
17035,
288,
367,
1300,
315,
5256,
423,
12087,
26,
355,
340,
790,
315,
1300,
26,
490,
291,
14,
6052,
423,
873,
8,
1095,
59,
498,
1055,
6052,
9,
339,
768,
1974,
14,
20457,
63,
1829,
272,
347,
485,
9823,
63,
16003,
8,
277,
304,
267,
372,
291,
14,
5472,
14,
9823,
63,
16003,
339,
347,
664,
63,
5570,
8,
277,
12,
1256,
12,
21010,
29,
29634,
63,
7517,
304,
267,
372,
291,
14,
5472,
14,
362,
63,
5570,
8,
842,
63,
929,
8,
842,
395,
3660,
1256,
63,
807,
8,
842,
395,
21010,
9,
339,
347,
636,
18837,
721,
277,
304,
267,
327,
3254,
26,
5558,
1183,
6554,
642,
1083,
4079,
641,
8502,
63,
2108,
5805,
267,
372,
291,
339,
768,
1974,
14,
20457,
63,
1829,
272,
347,
2256,
8,
277,
304,
267,
408,
1767,
314,
283,
815,
7,
2600,
367,
314,
8793,
5385,
1819,
14,
398,
710,
5953,
2348,
365,
465,
11924,
26,
398,
627,
982,
314,
2225,
365,
282,
2763,
13,
11663,
3324,
12,
284,
14,
69,
14,
881,
520,
533,
5026,
4547,
3697,
3559,
1314,
365,
9994,
5370,
881,
370,
282,
4177,
13,
1896,
520,
533,
5026,
4547,
64,
909,
12,
642,
2225,
881,
911,
372,
314,
520,
962,
5026,
6700,
2081,
14,
815,
64,
2600,
4568,
881,
543,
314,
6170,
13,
1896,
520,
533,
5026,
4547,
64,
909,
14,
398,
627,
982,
314,
2225,
365,
282,
520,
533,
5026,
4547,
3697,
64,
1325,
365,
9994,
370,
881,
1263,
1163,
4928,
402,
5385,
3965,
1163,
2419,
282,
520,
533,
5026,
4547,
3559,
881,
314,
2225,
911,
10618,
370,
314,
520,
962,
5026,
11880,
3697,
14,
815,
64,
881,
2600,
4568,
5370,
543,
314,
520,
533,
5026,
4547,
3697,
3559,
881,
18002,
314,
5385,
3965,
6337,
1630,
440,
1172,
2399,
5705,
21502,
815,
1040,
881,
2225,
334,
6777,
1077,
506,
314,
1930,
12,
7444,
282,
922,
13,
4037,
5385,
881,
6982,
965,
3247,
1373,
680,
398,
627,
982,
314,
2225,
15724,
370,
1263,
1163,
4928,
402,
881,
520,
533,
5026,
11880,
3697,
3559,
5893,
520,
533,
5026,
21096,
3697,
3559,
881,
314,
2225,
911,
10618,
370,
314,
520,
962,
5026,
11880,
3697,
14,
815,
64,
881,
2600,
4568,
543,
626,
520,
533,
5026,
11880,
3697,
2313,
398,
627,
4005,
2879,
314,
520,
962,
5026,
11880,
3697,
14,
815,
64,
2600,
402,
314,
881,
520,
533,
5026,
11880,
3697,
64,
625,
31565,
12,
5893,
367,
282,
881,
520,
533,
5026,
4547,
3697,
64,
626,
1159,
4568,
5370,
543,
282,
881,
520,
533,
5026,
3629,
14,
4547,
3559,
314,
2225,
883,
506,
25713,
370,
1808,
881,
520,
962,
5026,
3227,
461,
1646,
14,
1829,
64,
2225,
12,
465,
881,
1124,
5713,
2543,
14,
3972,
3215,
14,
1829,
14,
815,
4345,
398,
2508,
7445,
447,
378,
14,
24,
14,
16,
398,
2508,
19352,
447,
953,
520,
962,
5026,
6700,
2081,
14
] |
[
9813,
15,
2987,
14,
647,
199,
3,
1898,
334,
35,
9,
11811,
13,
7806,
314,
14303,
11462,
436,
8417,
199,
3,
665,
3239,
10610,
570,
30,
199,
3,
199,
3,
961,
859,
365,
1777,
402,
14303,
436,
365,
14286,
1334,
199,
3,
314,
10697,
844,
26,
1455,
921,
1544,
14,
16374,
14,
1308,
15,
2383,
15,
1147,
13,
1682,
14,
8624,
199,
199,
624,
23891,
14498,
425,
367,
1021,
3004,
436,
3932,
18752,
199,
1045,
4454,
14,
199,
199,
2765,
859,
365,
9987,
440,
5370,
8917,
370,
922,
13103,
12,
1325,
199,
14334,
282,
7031,
1777,
402,
314,
23383,
1159,
315,
2967,
67,
4191,
14,
421,
199,
624,
199,
199,
646,
4182,
199,
504,
2508,
492,
4884,
12,
1566,
12,
5261,
10303,
199,
504,
1275,
492,
8386,
12,
5055,
12,
3178,
465,
9813,
63,
2804,
199,
199,
504,
1275,
1095,
492,
1256,
63,
929,
12,
1256,
63,
807,
12,
5256,
63,
1618,
63,
533,
199,
199,
504,
1275,
1095,
492,
510,
26953,
63,
2826,
63,
9517,
12,
10762,
63,
55,
1179,
63,
3597,
12,
10762,
63,
13993,
12,
4825,
63,
7041,
4202,
272,
7110,
2111,
63,
3597,
12,
4825,
63,
16062,
12,
24251,
17041,
63,
3593,
12,
5385,
63,
3593,
12,
820,
2901,
6989,
63,
9868,
63,
3593,
4202,
272,
20199,
63,
3593,
12,
11214,
63,
4227,
29367,
1309,
63,
3593,
12,
3412,
1554,
63,
1254,
33,
7834,
63,
5378,
20779,
1149,
12,
510,
26953,
63,
7517,
4202,
272,
510,
26953,
63,
9677,
63,
6388,
2111,
63,
3597,
12,
510,
26953,
63,
2826,
63,
13768,
11025,
12,
510,
26953,
63,
2826,
63,
32097,
4202,
272,
510,
26953,
63,
2826,
63,
32097,
63,
13604,
6989,
12,
510,
26953,
63,
10452,
63,
4227,
29367,
1309,
12,
4825,
63,
13883,
32762,
199,
504,
1275,
1095,
492,
1174,
63,
495,
12,
1256,
63,
495,
421,
199,
32,
25098,
423,
277,
63,
10955,
83,
199,
533,
8133,
461,
1646,
8,
7436,
423,
20698,
1646,
12,
586,
8386,
14,
13962,
10303,
7144,
12,
586,
8386,
14,
9955,
26636,
304,
272,
408,
1563,
1021,
367,
520,
5125,
1705,
4120,
64,
2251,
626,
13926,
272,
2225,
4474,
641,
506,
10220,
402,
282,
520,
533,
5026,
11880,
3697,
64,
272,
909,
14,
221,
710,
3503,
520,
533,
5026,
11880,
3697,
64,
365,
17909,
272,
4799,
314,
520,
962,
5026,
3227,
461,
1646,
14,
1829,
64,
272,
2225,
14,
2378,
2508,
19352,
447,
398,
520,
533,
5026,
607,
495,
12546,
1646,
64,
398,
520,
533,
5026,
11880,
3697,
64,
398,
520,
962,
5026,
11880,
14,
452,
63,
1025,
63,
17752,
64,
398,
520,
962,
5026,
11880,
14,
3288,
64,
272,
408,
339,
365,
63,
3215,
275,
715,
339,
347,
636,
826,
721,
277,
12,
1021,
3131,
790,
12,
11512,
29,
403,
12,
326,
32138,
29,
403,
12,
13566,
724,
1701,
29,
403,
12,
326,
402,
63,
466,
29,
403,
304,
267,
291,
14,
533,
63,
275,
1021,
63,
267,
291,
14,
498,
275,
790,
267,
291,
14,
5472,
275,
11512,
267,
291,
14,
27417,
275,
32138,
267,
291,
423,
9575,
724,
1701,
275,
13566,
724,
1701,
267,
291,
423,
1618,
63,
466,
275,
402,
63,
466,
398,
5256,
275,
5256,
63,
1618,
63,
533,
8,
533,
4602,
267,
327,
5256,
365,
488,
315,
314,
1930,
402,
15170,
11185,
2543,
267,
340,
5256,
26,
288,
327,
19843,
3411,
1566,
19946,
687,
288,
327,
8569,
17035,
288,
367,
1300,
315,
5256,
423,
12087,
26,
355,
340,
790,
315,
1300,
26,
490,
291,
14,
6052,
423,
873,
8,
1095,
59,
498,
1055,
6052,
9,
339,
768,
1974,
14,
20457,
63,
1829,
272,
347,
485,
9823,
63,
16003,
8,
277,
304,
267,
372,
291,
14,
5472,
14,
9823,
63,
16003,
339,
347,
664,
63,
5570,
8,
277,
12,
1256,
12,
21010,
29,
29634,
63,
7517,
304,
267,
372,
291,
14,
5472,
14,
362,
63,
5570,
8,
842,
63,
929,
8,
842,
395,
3660,
1256,
63,
807,
8,
842,
395,
21010,
9,
339,
347,
636,
18837,
721,
277,
304,
267,
327,
3254,
26,
5558,
1183,
6554,
642,
1083,
4079,
641,
8502,
63,
2108,
5805,
267,
372,
291,
339,
768,
1974,
14,
20457,
63,
1829,
272,
347,
2256,
8,
277,
304,
267,
408,
1767,
314,
283,
815,
7,
2600,
367,
314,
8793,
5385,
1819,
14,
398,
710,
5953,
2348,
365,
465,
11924,
26,
398,
627,
982,
314,
2225,
365,
282,
2763,
13,
11663,
3324,
12,
284,
14,
69,
14,
881,
520,
533,
5026,
4547,
3697,
3559,
1314,
365,
9994,
5370,
881,
370,
282,
4177,
13,
1896,
520,
533,
5026,
4547,
64,
909,
12,
642,
2225,
881,
911,
372,
314,
520,
962,
5026,
6700,
2081,
14,
815,
64,
2600,
4568,
881,
543,
314,
6170,
13,
1896,
520,
533,
5026,
4547,
64,
909,
14,
398,
627,
982,
314,
2225,
365,
282,
520,
533,
5026,
4547,
3697,
64,
1325,
365,
9994,
370,
881,
1263,
1163,
4928,
402,
5385,
3965,
1163,
2419,
282,
520,
533,
5026,
4547,
3559,
881,
314,
2225,
911,
10618,
370,
314,
520,
962,
5026,
11880,
3697,
14,
815,
64,
881,
2600,
4568,
5370,
543,
314,
520,
533,
5026,
4547,
3697,
3559,
881,
18002,
314,
5385,
3965,
6337,
1630,
440,
1172,
2399,
5705,
21502,
815,
1040,
881,
2225,
334,
6777,
1077,
506,
314,
1930,
12,
7444,
282,
922,
13,
4037,
5385,
881,
6982,
965,
3247,
1373,
680,
398,
627,
982,
314,
2225,
15724,
370,
1263,
1163,
4928,
402,
881,
520,
533,
5026,
11880,
3697,
3559,
5893,
520,
533,
5026,
21096,
3697,
3559,
881,
314,
2225,
911,
10618,
370,
314,
520,
962,
5026,
11880,
3697,
14,
815,
64,
881,
2600,
4568,
543,
626,
520,
533,
5026,
11880,
3697,
2313,
398,
627,
4005,
2879,
314,
520,
962,
5026,
11880,
3697,
14,
815,
64,
2600,
402,
314,
881,
520,
533,
5026,
11880,
3697,
64,
625,
31565,
12,
5893,
367,
282,
881,
520,
533,
5026,
4547,
3697,
64,
626,
1159,
4568,
5370,
543,
282,
881,
520,
533,
5026,
3629,
14,
4547,
3559,
314,
2225,
883,
506,
25713,
370,
1808,
881,
520,
962,
5026,
3227,
461,
1646,
14,
1829,
64,
2225,
12,
465,
881,
1124,
5713,
2543,
14,
3972,
3215,
14,
1829,
14,
815,
4345,
398,
2508,
7445,
447,
378,
14,
24,
14,
16,
398,
2508,
19352,
447,
953,
520,
962,
5026,
6700,
2081,
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,
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
] |
benschulz/servo
|
tests/wpt/harness/wptrunner/executors/executorselenium.py
|
61
|
9570
|
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
import os
import socket
import sys
import threading
import time
import traceback
import urlparse
import uuid
from .base import (ExecutorException,
Protocol,
RefTestExecutor,
RefTestImplementation,
TestExecutor,
TestharnessExecutor,
testharness_result_converter,
reftest_result_converter,
strip_server)
from ..testrunner import Stop
here = os.path.join(os.path.split(__file__)[0])
webdriver = None
exceptions = None
extra_timeout = 5
def do_delayed_imports():
global webdriver
global exceptions
from selenium import webdriver
from selenium.common import exceptions
class SeleniumProtocol(Protocol):
def __init__(self, executor, browser, capabilities, **kwargs):
do_delayed_imports()
Protocol.__init__(self, executor, browser)
self.capabilities = capabilities
self.url = browser.webdriver_url
self.webdriver = None
def setup(self, runner):
"""Connect to browser via Selenium's WebDriver implementation."""
self.runner = runner
self.logger.debug("Connecting to Selenium on URL: %s" % self.url)
session_started = False
try:
self.webdriver = webdriver.Remote(
self.url, desired_capabilities=self.capabilities)
except:
self.logger.warning(
"Connecting to Selenium failed:\n%s" % traceback.format_exc())
else:
self.logger.debug("Selenium session started")
session_started = True
if not session_started:
self.logger.warning("Failed to connect to Selenium")
self.executor.runner.send_message("init_failed")
else:
try:
self.after_connect()
except:
print >> sys.stderr, traceback.format_exc()
self.logger.warning(
"Failed to connect to navigate initial page")
self.executor.runner.send_message("init_failed")
else:
self.executor.runner.send_message("init_succeeded")
def teardown(self):
self.logger.debug("Hanging up on Selenium session")
try:
self.webdriver.quit()
except:
pass
del self.webdriver
def is_alive(self):
try:
# Get a simple property over the connection
self.webdriver.current_window_handle
# TODO what exception?
except (socket.timeout, exceptions.ErrorInResponseException):
return False
return True
def after_connect(self):
self.load_runner("http")
def load_runner(self, protocol):
url = urlparse.urljoin(self.executor.server_url(protocol),
"/testharness_runner.html")
self.logger.debug("Loading %s" % url)
self.webdriver.get(url)
self.webdriver.execute_script("document.title = '%s'" %
threading.current_thread().name.replace("'", '"'))
def wait(self):
while True:
try:
self.webdriver.execute_async_script("");
except exceptions.TimeoutException:
pass
except (socket.timeout, exceptions.NoSuchWindowException,
exceptions.ErrorInResponseException, IOError):
break
except Exception as e:
self.logger.error(traceback.format_exc(e))
break
class SeleniumRun(object):
def __init__(self, func, webdriver, url, timeout):
self.func = func
self.result = None
self.webdriver = webdriver
self.url = url
self.timeout = timeout
self.result_flag = threading.Event()
def run(self):
timeout = self.timeout
try:
self.webdriver.set_script_timeout((timeout + extra_timeout) * 1000)
except exceptions.ErrorInResponseException:
self.logger.error("Lost webdriver connection")
return Stop
executor = threading.Thread(target=self._run)
executor.start()
flag = self.result_flag.wait(timeout + 2 * extra_timeout)
if self.result is None:
assert not flag
self.result = False, ("EXTERNAL-TIMEOUT", None)
return self.result
def _run(self):
try:
self.result = True, self.func(self.webdriver, self.url, self.timeout)
except exceptions.TimeoutException:
self.result = False, ("EXTERNAL-TIMEOUT", None)
except (socket.timeout, exceptions.ErrorInResponseException):
self.result = False, ("CRASH", None)
except Exception as e:
message = getattr(e, "message", "")
if message:
message += "\n"
message += traceback.format_exc(e)
self.result = False, ("ERROR", e)
finally:
self.result_flag.set()
class SeleniumTestharnessExecutor(TestharnessExecutor):
def __init__(self, browser, server_config, timeout_multiplier=1,
close_after_done=True, capabilities=None, debug_info=None):
"""Selenium-based executor for testharness.js tests"""
TestharnessExecutor.__init__(self, browser, server_config,
timeout_multiplier=timeout_multiplier,
debug_info=debug_info)
self.protocol = SeleniumProtocol(self, browser, capabilities)
with open(os.path.join(here, "testharness_webdriver.js")) as f:
self.script = f.read()
self.close_after_done = close_after_done
self.window_id = str(uuid.uuid4())
def is_alive(self):
return self.protocol.is_alive()
def on_protocol_change(self, new_protocol):
self.protocol.load_runner(new_protocol)
def do_test(self, test):
url = self.test_url(test)
success, data = SeleniumRun(self.do_testharness,
self.protocol.webdriver,
url,
test.timeout * self.timeout_multiplier).run()
if success:
return self.convert_result(test, data)
return (test.result_cls(*data), [])
def do_testharness(self, webdriver, url, timeout):
return webdriver.execute_async_script(
self.script % {"abs_url": url,
"url": strip_server(url),
"window_id": self.window_id,
"timeout_multiplier": self.timeout_multiplier,
"timeout": timeout * 1000})
class SeleniumRefTestExecutor(RefTestExecutor):
def __init__(self, browser, server_config, timeout_multiplier=1,
screenshot_cache=None, close_after_done=True,
debug_info=None, capabilities=None):
"""Selenium WebDriver-based executor for reftests"""
RefTestExecutor.__init__(self,
browser,
server_config,
screenshot_cache=screenshot_cache,
timeout_multiplier=timeout_multiplier,
debug_info=debug_info)
self.protocol = SeleniumProtocol(self, browser,
capabilities=capabilities)
self.implementation = RefTestImplementation(self)
self.close_after_done = close_after_done
self.has_window = False
with open(os.path.join(here, "reftest.js")) as f:
self.script = f.read()
with open(os.path.join(here, "reftest-wait_webdriver.js")) as f:
self.wait_script = f.read()
def is_alive(self):
return self.protocol.is_alive()
def do_test(self, test):
self.logger.info("Test requires OS-level window focus")
if self.close_after_done and self.has_window:
self.protocol.webdriver.close()
self.protocol.webdriver.switch_to_window(
self.protocol.webdriver.window_handles[-1])
self.has_window = False
if not self.has_window:
self.protocol.webdriver.execute_script(self.script)
self.protocol.webdriver.switch_to_window(
self.protocol.webdriver.window_handles[-1])
self.has_window = True
result = self.implementation.run_test(test)
return self.convert_result(test, result)
def screenshot(self, test, viewport_size, dpi):
# https://github.com/w3c/wptrunner/issues/166
assert viewport_size is None
assert dpi is None
return SeleniumRun(self._screenshot,
self.protocol.webdriver,
self.test_url(test),
test.timeout).run()
def _screenshot(self, webdriver, url, timeout):
webdriver.get(url)
webdriver.execute_async_script(self.wait_script)
screenshot = webdriver.get_screenshot_as_base64()
# strip off the data:img/png, part of the url
if screenshot.startswith("data:image/png;base64,"):
screenshot = screenshot.split(",", 1)[1]
return screenshot
|
mpl-2.0
|
[
3,
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
646,
747,
199,
646,
2838,
199,
646,
984,
199,
646,
5796,
199,
646,
900,
199,
646,
5190,
199,
646,
7097,
199,
646,
5377,
199,
199,
504,
1275,
1095,
492,
334,
16752,
1726,
12,
673,
11557,
12,
673,
15397,
774,
16752,
12,
673,
15397,
774,
7921,
12,
673,
1379,
16752,
12,
673,
1379,
23569,
16752,
12,
673,
511,
23569,
63,
1099,
63,
11256,
12,
673,
2984,
396,
63,
1099,
63,
11256,
12,
673,
6202,
63,
1000,
9,
199,
504,
2508,
396,
5933,
492,
8015,
421,
199,
1681,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
1294,
3460,
493,
363,
2788,
16,
566,
199,
199,
17946,
275,
488,
199,
3924,
275,
488,
199,
199,
2911,
63,
2593,
275,
959,
199,
199,
318,
886,
63,
21830,
63,
12775,
837,
272,
2288,
28094,
272,
2288,
4967,
272,
687,
19481,
492,
28094,
272,
687,
19481,
14,
2330,
492,
4967,
421,
199,
533,
3240,
9465,
3658,
8,
3658,
304,
272,
347,
636,
826,
721,
277,
12,
13270,
12,
7042,
12,
14918,
12,
1011,
958,
304,
267,
886,
63,
21830,
63,
12775,
342,
398,
11557,
855,
826,
721,
277,
12,
13270,
12,
7042,
9,
267,
291,
14,
10732,
275,
14918,
267,
291,
14,
633,
275,
7042,
14,
17946,
63,
633,
267,
291,
14,
17946,
275,
488,
339,
347,
3272,
8,
277,
12,
7876,
304,
267,
408,
8631,
370,
7042,
4799,
3240,
9465,
1159,
27104,
4514,
1041,
267,
291,
14,
5933,
275,
7876,
267,
291,
14,
2921,
14,
1757,
480,
32000,
370,
3240,
9465,
641,
2851,
26,
450,
83,
2,
450,
291,
14,
633,
9,
398,
2351,
63,
8924,
275,
756,
267,
862,
26,
288,
291,
14,
17946,
275,
28094,
14,
6713,
8,
355,
291,
14,
633,
12,
6387,
63,
10732,
29,
277,
14,
10732,
9,
267,
871,
26,
288,
291,
14,
2921,
14,
3764,
8,
355,
298,
32000,
370,
3240,
9465,
3405,
3427,
78,
5,
83,
2,
450,
5190,
14,
908,
63,
2804,
1012,
267,
587,
26,
288,
291,
14,
2921,
14,
1757,
480,
31315,
2351,
8239,
531,
288,
2351,
63,
8924,
275,
715,
398,
340,
440,
2351,
63,
8924,
26,
288,
291,
14,
2921,
14,
3764,
480,
4276,
370,
4907,
370,
3240,
9465,
531,
288,
291,
14,
13471,
14,
5933,
14,
2254,
63,
1188,
480,
826,
63,
4892,
531,
267,
587,
26,
288,
862,
26,
355,
291,
14,
4399,
63,
2242,
342,
288,
871,
26,
355,
870,
4331,
984,
14,
3083,
12,
5190,
14,
908,
63,
2804,
342,
355,
291,
14,
2921,
14,
3764,
8,
490,
298,
4276,
370,
4907,
370,
20850,
2536,
2034,
531,
355,
291,
14,
13471,
14,
5933,
14,
2254,
63,
1188,
480,
826,
63,
4892,
531,
288,
587,
26,
355,
291,
14,
13471,
14,
5933,
14,
2254,
63,
1188,
480,
826,
63,
20003,
531,
339,
347,
17558,
8,
277,
304,
267,
291,
14,
2921,
14,
1757,
480,
40,
8544,
1536,
641,
3240,
9465,
2351,
531,
267,
862,
26,
288,
291,
14,
17946,
14,
10589,
342,
267,
871,
26,
288,
986,
267,
2150,
291,
14,
17946,
339,
347,
365,
63,
9631,
8,
277,
304,
267,
862,
26,
288,
327,
2372,
282,
3486,
3324,
1806,
314,
1950,
288,
291,
14,
17946,
14,
1818,
63,
3806,
63,
2479,
267,
327,
3254,
4052,
1919,
31,
267,
871,
334,
3450,
14,
2593,
12,
4967,
14,
547,
607,
2364,
1726,
304,
288,
372,
756,
267,
372,
715,
339,
347,
2410,
63,
2242,
8,
277,
304,
267,
291,
14,
912,
63,
5933,
480,
1014,
531,
339,
347,
2248,
63,
5933,
8,
277,
12,
4113,
304,
267,
1166,
275,
7097,
14,
17755,
8,
277,
14,
13471,
14,
1000,
63,
633,
8,
3922,
395,
3044,
3286,
396,
23569,
63,
5933,
14,
1360,
531,
267,
291,
14,
2921,
14,
1757,
480,
19236,
450,
83,
2,
450,
1166,
9,
267,
291,
14,
17946,
14,
362,
8,
633,
9,
267,
291,
14,
17946,
14,
2526,
63,
1579,
480,
3554,
14,
1213,
275,
1543,
83,
4065,
450,
4228,
5796,
14,
1818,
63,
2671,
1252,
354,
14,
1814,
27769,
5522,
1333,
339,
347,
3618,
8,
277,
304,
267,
1830,
715,
26,
288,
862,
26,
355,
291,
14,
17946,
14,
2526,
63,
4146,
63,
1579,
11986,
2736,
288,
871,
4967,
14,
6372,
1726,
26,
355,
986,
288,
871,
334,
3450,
14,
2593,
12,
4967,
14,
30049,
4301,
1726,
12,
490,
4967,
14,
547,
607,
2364,
1726,
12,
5925,
304,
355,
2059,
288,
871,
2186,
465,
325,
26,
355,
291,
14,
2921,
14,
705,
8,
6894,
14,
908,
63,
2804,
8,
69,
430,
355,
2059,
421,
199,
533,
3240,
9465,
2540,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
2562,
12,
28094,
12,
1166,
12,
2653,
304,
267,
291,
14,
1532,
275,
2562,
267,
291,
14,
1099,
275,
488,
267,
291,
14,
17946,
275,
28094,
267,
291,
14,
633,
275,
1166,
267,
291,
14,
2593,
275,
2653,
267,
291,
14,
1099,
63,
4173,
275,
5796,
14,
2390,
342,
339,
347,
1255,
8,
277,
304,
267,
2653,
275,
291,
14,
2593,
398,
862,
26,
288,
291,
14,
17946,
14,
409,
63,
1579,
63,
2593,
1332,
2593,
435,
2402,
63,
2593,
9,
627,
5198,
9,
267,
871,
4967,
14,
547,
607,
2364,
1726,
26,
288,
291,
14,
2921,
14,
705,
480,
14074,
28094,
1950,
531,
288,
372,
8015,
398,
13270,
275,
5796,
14,
4436,
8,
1375,
29,
277,
423,
1065,
9,
267,
13270,
14,
928,
342,
398,
3305,
275,
291,
14,
1099,
63,
4173,
14,
2573,
8,
2593,
435,
499,
627,
2402,
63,
2593,
9,
267,
340,
291,
14,
1099,
365,
488,
26,
288,
702,
440,
3305,
288,
291,
14,
1099,
275,
756,
12,
1689,
21043,
13,
8899,
401,
488,
9,
398,
372,
291,
14,
1099,
339,
347,
485,
1065,
8,
277,
304,
267,
862,
26,
288,
291,
14,
1099,
275,
715,
12,
291,
14,
1532,
8,
277,
14,
17946,
12,
291,
14,
633,
12,
291,
14,
2593,
9,
267,
871
] |
[
961,
5800,
5495,
8204,
365,
5420,
370,
314,
2895,
402,
314,
17728,
1684,
199,
3,
844,
12,
373,
14,
499,
14,
16,
14,
982,
282,
1331,
402,
314,
28481,
1990,
440,
1854,
543,
642,
570,
12,
199,
3,
2047,
883,
3332,
1373,
737,
1455,
921,
12102,
14,
1308,
15,
3950,
15,
18,
14,
16,
8083,
199,
199,
646,
747,
199,
646,
2838,
199,
646,
984,
199,
646,
5796,
199,
646,
900,
199,
646,
5190,
199,
646,
7097,
199,
646,
5377,
199,
199,
504,
1275,
1095,
492,
334,
16752,
1726,
12,
673,
11557,
12,
673,
15397,
774,
16752,
12,
673,
15397,
774,
7921,
12,
673,
1379,
16752,
12,
673,
1379,
23569,
16752,
12,
673,
511,
23569,
63,
1099,
63,
11256,
12,
673,
2984,
396,
63,
1099,
63,
11256,
12,
673,
6202,
63,
1000,
9,
199,
504,
2508,
396,
5933,
492,
8015,
421,
199,
1681,
275,
747,
14,
515,
14,
904,
8,
736,
14,
515,
14,
1294,
3460,
493,
363,
2788,
16,
566,
199,
199,
17946,
275,
488,
199,
3924,
275,
488,
199,
199,
2911,
63,
2593,
275,
959,
199,
199,
318,
886,
63,
21830,
63,
12775,
837,
272,
2288,
28094,
272,
2288,
4967,
272,
687,
19481,
492,
28094,
272,
687,
19481,
14,
2330,
492,
4967,
421,
199,
533,
3240,
9465,
3658,
8,
3658,
304,
272,
347,
636,
826,
721,
277,
12,
13270,
12,
7042,
12,
14918,
12,
1011,
958,
304,
267,
886,
63,
21830,
63,
12775,
342,
398,
11557,
855,
826,
721,
277,
12,
13270,
12,
7042,
9,
267,
291,
14,
10732,
275,
14918,
267,
291,
14,
633,
275,
7042,
14,
17946,
63,
633,
267,
291,
14,
17946,
275,
488,
339,
347,
3272,
8,
277,
12,
7876,
304,
267,
408,
8631,
370,
7042,
4799,
3240,
9465,
1159,
27104,
4514,
1041,
267,
291,
14,
5933,
275,
7876,
267,
291,
14,
2921,
14,
1757,
480,
32000,
370,
3240,
9465,
641,
2851,
26,
450,
83,
2,
450,
291,
14,
633,
9,
398,
2351,
63,
8924,
275,
756,
267,
862,
26,
288,
291,
14,
17946,
275,
28094,
14,
6713,
8,
355,
291,
14,
633,
12,
6387,
63,
10732,
29,
277,
14,
10732,
9,
267,
871,
26,
288,
291,
14,
2921,
14,
3764,
8,
355,
298,
32000,
370,
3240,
9465,
3405,
3427,
78,
5,
83,
2,
450,
5190,
14,
908,
63,
2804,
1012,
267,
587,
26,
288,
291,
14,
2921,
14,
1757,
480,
31315,
2351,
8239,
531,
288,
2351,
63,
8924,
275,
715,
398,
340,
440,
2351,
63,
8924,
26,
288,
291,
14,
2921,
14,
3764,
480,
4276,
370,
4907,
370,
3240,
9465,
531,
288,
291,
14,
13471,
14,
5933,
14,
2254,
63,
1188,
480,
826,
63,
4892,
531,
267,
587,
26,
288,
862,
26,
355,
291,
14,
4399,
63,
2242,
342,
288,
871,
26,
355,
870,
4331,
984,
14,
3083,
12,
5190,
14,
908,
63,
2804,
342,
355,
291,
14,
2921,
14,
3764,
8,
490,
298,
4276,
370,
4907,
370,
20850,
2536,
2034,
531,
355,
291,
14,
13471,
14,
5933,
14,
2254,
63,
1188,
480,
826,
63,
4892,
531,
288,
587,
26,
355,
291,
14,
13471,
14,
5933,
14,
2254,
63,
1188,
480,
826,
63,
20003,
531,
339,
347,
17558,
8,
277,
304,
267,
291,
14,
2921,
14,
1757,
480,
40,
8544,
1536,
641,
3240,
9465,
2351,
531,
267,
862,
26,
288,
291,
14,
17946,
14,
10589,
342,
267,
871,
26,
288,
986,
267,
2150,
291,
14,
17946,
339,
347,
365,
63,
9631,
8,
277,
304,
267,
862,
26,
288,
327,
2372,
282,
3486,
3324,
1806,
314,
1950,
288,
291,
14,
17946,
14,
1818,
63,
3806,
63,
2479,
267,
327,
3254,
4052,
1919,
31,
267,
871,
334,
3450,
14,
2593,
12,
4967,
14,
547,
607,
2364,
1726,
304,
288,
372,
756,
267,
372,
715,
339,
347,
2410,
63,
2242,
8,
277,
304,
267,
291,
14,
912,
63,
5933,
480,
1014,
531,
339,
347,
2248,
63,
5933,
8,
277,
12,
4113,
304,
267,
1166,
275,
7097,
14,
17755,
8,
277,
14,
13471,
14,
1000,
63,
633,
8,
3922,
395,
3044,
3286,
396,
23569,
63,
5933,
14,
1360,
531,
267,
291,
14,
2921,
14,
1757,
480,
19236,
450,
83,
2,
450,
1166,
9,
267,
291,
14,
17946,
14,
362,
8,
633,
9,
267,
291,
14,
17946,
14,
2526,
63,
1579,
480,
3554,
14,
1213,
275,
1543,
83,
4065,
450,
4228,
5796,
14,
1818,
63,
2671,
1252,
354,
14,
1814,
27769,
5522,
1333,
339,
347,
3618,
8,
277,
304,
267,
1830,
715,
26,
288,
862,
26,
355,
291,
14,
17946,
14,
2526,
63,
4146,
63,
1579,
11986,
2736,
288,
871,
4967,
14,
6372,
1726,
26,
355,
986,
288,
871,
334,
3450,
14,
2593,
12,
4967,
14,
30049,
4301,
1726,
12,
490,
4967,
14,
547,
607,
2364,
1726,
12,
5925,
304,
355,
2059,
288,
871,
2186,
465,
325,
26,
355,
291,
14,
2921,
14,
705,
8,
6894,
14,
908,
63,
2804,
8,
69,
430,
355,
2059,
421,
199,
533,
3240,
9465,
2540,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
2562,
12,
28094,
12,
1166,
12,
2653,
304,
267,
291,
14,
1532,
275,
2562,
267,
291,
14,
1099,
275,
488,
267,
291,
14,
17946,
275,
28094,
267,
291,
14,
633,
275,
1166,
267,
291,
14,
2593,
275,
2653,
267,
291,
14,
1099,
63,
4173,
275,
5796,
14,
2390,
342,
339,
347,
1255,
8,
277,
304,
267,
2653,
275,
291,
14,
2593,
398,
862,
26,
288,
291,
14,
17946,
14,
409,
63,
1579,
63,
2593,
1332,
2593,
435,
2402,
63,
2593,
9,
627,
5198,
9,
267,
871,
4967,
14,
547,
607,
2364,
1726,
26,
288,
291,
14,
2921,
14,
705,
480,
14074,
28094,
1950,
531,
288,
372,
8015,
398,
13270,
275,
5796,
14,
4436,
8,
1375,
29,
277,
423,
1065,
9,
267,
13270,
14,
928,
342,
398,
3305,
275,
291,
14,
1099,
63,
4173,
14,
2573,
8,
2593,
435,
499,
627,
2402,
63,
2593,
9,
267,
340,
291,
14,
1099,
365,
488,
26,
288,
702,
440,
3305,
288,
291,
14,
1099,
275,
756,
12,
1689,
21043,
13,
8899,
401,
488,
9,
398,
372,
291,
14,
1099,
339,
347,
485,
1065,
8,
277,
304,
267,
862,
26,
288,
291,
14,
1099,
275,
715,
12,
291,
14,
1532,
8,
277,
14,
17946,
12,
291,
14,
633,
12,
291,
14,
2593,
9,
267,
871,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
scmallorca/primefactors-dojo
|
alearnaiz_joanmiralles/tests/prime_factors_test.py
|
1
|
1155
|
import unittest
from ..src.prime_factors import PrimeFactors
class PrimeFactorsTest(unittest.TestCase):
def test_generate_one__should_be_empty(self):
primes = PrimeFactors.generate(1)
assert len(primes) == 0
def test_generate_two__should_be_two(self):
number = 2
self.check_primes(number, 2)
def test_generate_three__should_be_three(self):
number = 3
self.check_primes(number, 3)
def test_generate_four__should_be_two(self):
number = 4
self.check_primes(number, 2)
def test_generate_six__should_be_two_and_three(self):
number = 6
self.check_primes(number, 2, 3)
def test_generate_eight__should_be_two(self):
number = 8
self.check_primes(number, 2)
def test_generate_fourty_two__should_be_two_three_seven(self):
number = 42
self.check_primes(number, 2, 3, 7)
def check_primes(self, number, *expected_primes):
actual_primes = PrimeFactors.generate(number)
assert len(expected_primes) == len(actual_primes)
for prime in expected_primes:
assert prime in actual_primes
|
mit
|
[
646,
2882,
199,
199,
504,
2508,
2164,
14,
12446,
63,
16125,
492,
8538,
278,
12666,
83,
421,
199,
533,
8538,
278,
12666,
26935,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
4208,
63,
368,
363,
5626,
63,
1235,
63,
1667,
8,
277,
304,
267,
1979,
6415,
275,
8538,
278,
12666,
83,
14,
4208,
8,
17,
9,
267,
702,
822,
8,
1359,
6415,
9,
508,
378,
339,
347,
511,
63,
4208,
63,
5601,
363,
5626,
63,
1235,
63,
5601,
8,
277,
304,
267,
1329,
275,
499,
267,
291,
14,
1074,
63,
1359,
6415,
8,
1955,
12,
499,
9,
339,
347,
511,
63,
4208,
63,
10480,
363,
5626,
63,
1235,
63,
10480,
8,
277,
304,
267,
1329,
275,
650,
267,
291,
14,
1074,
63,
1359,
6415,
8,
1955,
12,
650,
9,
339,
347,
511,
63,
4208,
63,
13672,
363,
5626,
63,
1235,
63,
5601,
8,
277,
304,
267,
1329,
275,
841,
267,
291,
14,
1074,
63,
1359,
6415,
8,
1955,
12,
499,
9,
339,
347,
511,
63,
4208,
63,
4174,
363,
5626,
63,
1235,
63,
5601,
63,
460,
63,
10480,
8,
277,
304,
267,
1329,
275,
1227,
267,
291,
14,
1074,
63,
1359,
6415,
8,
1955,
12,
499,
12,
650,
9,
339,
347,
511,
63,
4208,
63,
32579,
363,
5626,
63,
1235,
63,
5601,
8,
277,
304,
267,
1329,
275,
1695,
267,
291,
14,
1074,
63,
1359,
6415,
8,
1955,
12,
499,
9,
339,
347,
511,
63,
4208,
63,
13672,
369,
63,
5601,
363,
5626,
63,
1235,
63,
5601,
63,
10480,
63,
27346,
8,
277,
304,
267,
1329,
275,
5685,
267,
291,
14,
1074,
63,
1359,
6415,
8,
1955,
12,
499,
12,
650,
12,
1520,
9,
339,
347,
1104,
63,
1359,
6415,
8,
277,
12,
1329,
12,
627,
2062,
63,
1359,
6415,
304,
267,
3503,
63,
1359,
6415,
275,
8538,
278,
12666,
83,
14,
4208,
8,
1955,
9,
267,
702,
822,
8,
2062,
63,
1359,
6415,
9,
508,
822,
8,
6514,
63,
1359,
6415,
9,
267,
367,
21619,
315,
1420,
63,
1359,
6415,
26,
288,
702,
21619,
315,
3503,
63,
1359,
6415,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2882,
199,
199,
504,
2508,
2164,
14,
12446,
63,
16125,
492,
8538,
278,
12666,
83,
421,
199,
533,
8538,
278,
12666,
26935,
8,
2796,
14,
1746,
304,
339,
347,
511,
63,
4208,
63,
368,
363,
5626,
63,
1235,
63,
1667,
8,
277,
304,
267,
1979,
6415,
275,
8538,
278,
12666,
83,
14,
4208,
8,
17,
9,
267,
702,
822,
8,
1359,
6415,
9,
508,
378,
339,
347,
511,
63,
4208,
63,
5601,
363,
5626,
63,
1235,
63,
5601,
8,
277,
304,
267,
1329,
275,
499,
267,
291,
14,
1074,
63,
1359,
6415,
8,
1955,
12,
499,
9,
339,
347,
511,
63,
4208,
63,
10480,
363,
5626,
63,
1235,
63,
10480,
8,
277,
304,
267,
1329,
275,
650,
267,
291,
14,
1074,
63,
1359,
6415,
8,
1955,
12,
650,
9,
339,
347,
511,
63,
4208,
63,
13672,
363,
5626,
63,
1235,
63,
5601,
8,
277,
304,
267,
1329,
275,
841,
267,
291,
14,
1074,
63,
1359,
6415,
8,
1955,
12,
499,
9,
339,
347,
511,
63,
4208,
63,
4174,
363,
5626,
63,
1235,
63,
5601,
63,
460,
63,
10480,
8,
277,
304,
267,
1329,
275,
1227,
267,
291,
14,
1074,
63,
1359,
6415,
8,
1955,
12,
499,
12,
650,
9,
339,
347,
511,
63,
4208,
63,
32579,
363,
5626,
63,
1235,
63,
5601,
8,
277,
304,
267,
1329,
275,
1695,
267,
291,
14,
1074,
63,
1359,
6415,
8,
1955,
12,
499,
9,
339,
347,
511,
63,
4208,
63,
13672,
369,
63,
5601,
363,
5626,
63,
1235,
63,
5601,
63,
10480,
63,
27346,
8,
277,
304,
267,
1329,
275,
5685,
267,
291,
14,
1074,
63,
1359,
6415,
8,
1955,
12,
499,
12,
650,
12,
1520,
9,
339,
347,
1104,
63,
1359,
6415,
8,
277,
12,
1329,
12,
627,
2062,
63,
1359,
6415,
304,
267,
3503,
63,
1359,
6415,
275,
8538,
278,
12666,
83,
14,
4208,
8,
1955,
9,
267,
702,
822,
8,
2062,
63,
1359,
6415,
9,
508,
822,
8,
6514,
63,
1359,
6415,
9,
267,
367,
21619,
315,
1420,
63,
1359,
6415,
26,
288,
702,
21619,
315,
3503,
63,
1359,
6415,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
loretoparisi/pattern
|
pattern/server/cherrypy/cherrypy/lib/httputil.py
|
37
|
17721
|
"""HTTP library functions.
This module contains functions for building an HTTP application
framework: any one, not just one whose name starts with "Ch". ;) If you
reference any modules from some popular framework inside *this* module,
FuManChu will personally hang you up by your thumbs and submit you
to a public caning.
"""
from binascii import b2a_base64
from cherrypy._cpcompat import BaseHTTPRequestHandler, HTTPDate, ntob, ntou, reversed, sorted
from cherrypy._cpcompat import basestring, bytestr, iteritems, nativestr, unicodestr, unquote_qs
response_codes = BaseHTTPRequestHandler.responses.copy()
# From http://www.cherrypy.org/ticket/361
response_codes[500] = ('Internal Server Error',
'The server encountered an unexpected condition '
'which prevented it from fulfilling the request.')
response_codes[503] = ('Service Unavailable',
'The server is currently unable to handle the '
'request due to a temporary overloading or '
'maintenance of the server.')
import re
import urllib
def urljoin(*atoms):
"""Return the given path \*atoms, joined into a single URL.
This will correctly join a SCRIPT_NAME and PATH_INFO into the
original URL, even if either atom is blank.
"""
url = "/".join([x for x in atoms if x])
while "//" in url:
url = url.replace("//", "/")
# Special-case the final url of "", and return "/" instead.
return url or "/"
def urljoin_bytes(*atoms):
"""Return the given path *atoms, joined into a single URL.
This will correctly join a SCRIPT_NAME and PATH_INFO into the
original URL, even if either atom is blank.
"""
url = ntob("/").join([x for x in atoms if x])
while ntob("//") in url:
url = url.replace(ntob("//"), ntob("/"))
# Special-case the final url of "", and return "/" instead.
return url or ntob("/")
def protocol_from_http(protocol_str):
"""Return a protocol tuple from the given 'HTTP/x.y' string."""
return int(protocol_str[5]), int(protocol_str[7])
def get_ranges(headervalue, content_length):
"""Return a list of (start, stop) indices from a Range header, or None.
Each (start, stop) tuple will be composed of two ints, which are suitable
for use in a slicing operation. That is, the header "Range: bytes=3-6",
if applied against a Python string, is requesting resource[3:7]. This
function will return the list [(3, 7)].
If this function returns an empty list, you should return HTTP 416.
"""
if not headervalue:
return None
result = []
bytesunit, byteranges = headervalue.split("=", 1)
for brange in byteranges.split(","):
start, stop = [x.strip() for x in brange.split("-", 1)]
if start:
if not stop:
stop = content_length - 1
start, stop = int(start), int(stop)
if start >= content_length:
# From rfc 2616 sec 14.16:
# "If the server receives a request (other than one
# including an If-Range request-header field) with an
# unsatisfiable Range request-header field (that is,
# all of whose byte-range-spec values have a first-byte-pos
# value greater than the current length of the selected
# resource), it SHOULD return a response code of 416
# (Requested range not satisfiable)."
continue
if stop < start:
# From rfc 2616 sec 14.16:
# "If the server ignores a byte-range-spec because it
# is syntactically invalid, the server SHOULD treat
# the request as if the invalid Range header field
# did not exist. (Normally, this means return a 200
# response containing the full entity)."
return None
result.append((start, stop + 1))
else:
if not stop:
# See rfc quote above.
return None
# Negative subscript (last N bytes)
result.append((content_length - int(stop), content_length))
return result
class HeaderElement(object):
"""An element (with parameters) from an HTTP header's element list."""
def __init__(self, value, params=None):
self.value = value
if params is None:
params = {}
self.params = params
def __cmp__(self, other):
return cmp(self.value, other.value)
def __lt__(self, other):
return self.value < other.value
def __str__(self):
p = [";%s=%s" % (k, v) for k, v in iteritems(self.params)]
return str("%s%s" % (self.value, "".join(p)))
def __bytes__(self):
return ntob(self.__str__())
def __unicode__(self):
return ntou(self.__str__())
def parse(elementstr):
"""Transform 'token;key=val' to ('token', {'key': 'val'})."""
# Split the element into a value and parameters. The 'value' may
# be of the form, "token=token", but we don't split that here.
atoms = [x.strip() for x in elementstr.split(";") if x.strip()]
if not atoms:
initial_value = ''
else:
initial_value = atoms.pop(0).strip()
params = {}
for atom in atoms:
atom = [x.strip() for x in atom.split("=", 1) if x.strip()]
key = atom.pop(0)
if atom:
val = atom[0]
else:
val = ""
params[key] = val
return initial_value, params
parse = staticmethod(parse)
def from_str(cls, elementstr):
"""Construct an instance from a string of the form 'token;key=val'."""
ival, params = cls.parse(elementstr)
return cls(ival, params)
from_str = classmethod(from_str)
q_separator = re.compile(r'; *q *=')
class AcceptElement(HeaderElement):
"""An element (with parameters) from an Accept* header's element list.
AcceptElement objects are comparable; the more-preferred object will be
"less than" the less-preferred object. They are also therefore sortable;
if you sort a list of AcceptElement objects, they will be listed in
priority order; the most preferred value will be first. Yes, it should
have been the other way around, but it's too late to fix now.
"""
def from_str(cls, elementstr):
qvalue = None
# The first "q" parameter (if any) separates the initial
# media-range parameter(s) (if any) from the accept-params.
atoms = q_separator.split(elementstr, 1)
media_range = atoms.pop(0).strip()
if atoms:
# The qvalue for an Accept header can have extensions. The other
# headers cannot, but it's easier to parse them as if they did.
qvalue = HeaderElement.from_str(atoms[0].strip())
media_type, params = cls.parse(media_range)
if qvalue is not None:
params["q"] = qvalue
return cls(media_type, params)
from_str = classmethod(from_str)
def qvalue(self):
val = self.params.get("q", "1")
if isinstance(val, HeaderElement):
val = val.value
return float(val)
qvalue = property(qvalue, doc="The qvalue, or priority, of this value.")
def __cmp__(self, other):
diff = cmp(self.qvalue, other.qvalue)
if diff == 0:
diff = cmp(str(self), str(other))
return diff
def __lt__(self, other):
if self.qvalue == other.qvalue:
return str(self) < str(other)
else:
return self.qvalue < other.qvalue
def header_elements(fieldname, fieldvalue):
"""Return a sorted HeaderElement list from a comma-separated header string."""
if not fieldvalue:
return []
result = []
for element in fieldvalue.split(","):
if fieldname.startswith("Accept") or fieldname == 'TE':
hv = AcceptElement.from_str(element)
else:
hv = HeaderElement.from_str(element)
result.append(hv)
return list(reversed(sorted(result)))
def decode_TEXT(value):
r"""Decode :rfc:`2047` TEXT (e.g. "=?utf-8?q?f=C3=BCr?=" -> "f\xfcr")."""
try:
# Python 3
from email.header import decode_header
except ImportError:
from email.Header import decode_header
atoms = decode_header(value)
decodedvalue = ""
for atom, charset in atoms:
if charset is not None:
atom = atom.decode(charset)
decodedvalue += atom
return decodedvalue
def valid_status(status):
"""Return legal HTTP status Code, Reason-phrase and Message.
The status arg must be an int, or a str that begins with an int.
If status is an int, or a str and no reason-phrase is supplied,
a default reason-phrase will be provided.
"""
if not status:
status = 200
status = str(status)
parts = status.split(" ", 1)
if len(parts) == 1:
# No reason supplied.
code, = parts
reason = None
else:
code, reason = parts
reason = reason.strip()
try:
code = int(code)
except ValueError:
raise ValueError("Illegal response status from server "
"(%s is non-numeric)." % repr(code))
if code < 100 or code > 599:
raise ValueError("Illegal response status from server "
"(%s is out of range)." % repr(code))
if code not in response_codes:
# code is unknown but not illegal
default_reason, message = "", ""
else:
default_reason, message = response_codes[code]
if reason is None:
reason = default_reason
return code, reason, message
# NOTE: the parse_qs functions that follow are modified version of those
# in the python3.0 source - we need to pass through an encoding to the unquote
# method, but the default parse_qs function doesn't allow us to. These do.
def _parse_qs(qs, keep_blank_values=0, strict_parsing=0, encoding='utf-8'):
"""Parse a query given as a string argument.
Arguments:
qs: URL-encoded query string to be parsed
keep_blank_values: flag indicating whether blank values in
URL encoded queries should be treated as blank strings. A
true value indicates that blanks should be retained as blank
strings. The default false value indicates that blank values
are to be ignored and treated as if they were not included.
strict_parsing: flag indicating what to do with parsing errors. If
false (the default), errors are silently ignored. If true,
errors raise a ValueError exception.
Returns a dict, as G-d intended.
"""
pairs = [s2 for s1 in qs.split('&') for s2 in s1.split(';')]
d = {}
for name_value in pairs:
if not name_value and not strict_parsing:
continue
nv = name_value.split('=', 1)
if len(nv) != 2:
if strict_parsing:
raise ValueError("bad query field: %r" % (name_value,))
# Handle case of a control-name with no equal sign
if keep_blank_values:
nv.append('')
else:
continue
if len(nv[1]) or keep_blank_values:
name = unquote_qs(nv[0], encoding)
value = unquote_qs(nv[1], encoding)
if name in d:
if not isinstance(d[name], list):
d[name] = [d[name]]
d[name].append(value)
else:
d[name] = value
return d
image_map_pattern = re.compile(r"[0-9]+,[0-9]+")
def parse_query_string(query_string, keep_blank_values=True, encoding='utf-8'):
"""Build a params dictionary from a query_string.
Duplicate key/value pairs in the provided query_string will be
returned as {'key': [val1, val2, ...]}. Single key/values will
be returned as strings: {'key': 'value'}.
"""
if image_map_pattern.match(query_string):
# Server-side image map. Map the coords to 'x' and 'y'
# (like CGI::Request does).
pm = query_string.split(",")
pm = {'x': int(pm[0]), 'y': int(pm[1])}
else:
pm = _parse_qs(query_string, keep_blank_values, encoding=encoding)
return pm
class CaseInsensitiveDict(dict):
"""A case-insensitive dict subclass.
Each key is changed on entry to str(key).title().
"""
def __getitem__(self, key):
return dict.__getitem__(self, str(key).title())
def __setitem__(self, key, value):
dict.__setitem__(self, str(key).title(), value)
def __delitem__(self, key):
dict.__delitem__(self, str(key).title())
def __contains__(self, key):
return dict.__contains__(self, str(key).title())
def get(self, key, default=None):
return dict.get(self, str(key).title(), default)
if hasattr({}, 'has_key'):
def has_key(self, key):
return dict.has_key(self, str(key).title())
def update(self, E):
for k in E.keys():
self[str(k).title()] = E[k]
def fromkeys(cls, seq, value=None):
newdict = cls()
for k in seq:
newdict[str(k).title()] = value
return newdict
fromkeys = classmethod(fromkeys)
def setdefault(self, key, x=None):
key = str(key).title()
try:
return self[key]
except KeyError:
self[key] = x
return x
def pop(self, key, default):
return dict.pop(self, str(key).title(), default)
# TEXT = <any OCTET except CTLs, but including LWS>
#
# A CRLF is allowed in the definition of TEXT only as part of a header
# field continuation. It is expected that the folding LWS will be
# replaced with a single SP before interpretation of the TEXT value."
if nativestr == bytestr:
header_translate_table = ''.join([chr(i) for i in xrange(256)])
header_translate_deletechars = ''.join([chr(i) for i in xrange(32)]) + chr(127)
else:
header_translate_table = None
header_translate_deletechars = bytes(range(32)) + bytes([127])
class HeaderMap(CaseInsensitiveDict):
"""A dict subclass for HTTP request and response headers.
Each key is changed on entry to str(key).title(). This allows headers
to be case-insensitive and avoid duplicates.
Values are header values (decoded according to :rfc:`2047` if necessary).
"""
protocol=(1, 1)
encodings = ["ISO-8859-1"]
# Someday, when http-bis is done, this will probably get dropped
# since few servers, clients, or intermediaries do it. But until then,
# we're going to obey the spec as is.
# "Words of *TEXT MAY contain characters from character sets other than
# ISO-8859-1 only when encoded according to the rules of RFC 2047."
use_rfc_2047 = True
def elements(self, key):
"""Return a sorted list of HeaderElements for the given header."""
key = str(key).title()
value = self.get(key)
return header_elements(key, value)
def values(self, key):
"""Return a sorted list of HeaderElement.value for the given header."""
return [e.value for e in self.elements(key)]
def output(self):
"""Transform self into a list of (name, value) tuples."""
return list(self.encode_header_items(self.items()))
def encode_header_items(cls, header_items):
"""
Prepare the sequence of name, value tuples into a form suitable for
transmitting on the wire for HTTP.
"""
for k, v in header_items:
if isinstance(k, unicodestr):
k = cls.encode(k)
if not isinstance(v, basestring):
v = str(v)
if isinstance(v, unicodestr):
v = cls.encode(v)
# See header_translate_* constants above.
# Replace only if you really know what you're doing.
k = k.translate(header_translate_table, header_translate_deletechars)
v = v.translate(header_translate_table, header_translate_deletechars)
yield (k, v)
encode_header_items = classmethod(encode_header_items)
def encode(cls, v):
"""Return the given header name or value, encoded for HTTP output."""
for enc in cls.encodings:
try:
return v.encode(enc)
except UnicodeEncodeError:
continue
if cls.protocol == (1, 1) and cls.use_rfc_2047:
# Encode RFC-2047 TEXT
# (e.g. u"\u8200" -> "=?utf-8?b?6IiA?=").
# We do our own here instead of using the email module
# because we never want to fold lines--folding has
# been deprecated by the HTTP working group.
v = b2a_base64(v.encode('utf-8'))
return (ntob('=?utf-8?b?') + v.strip(ntob('\n')) + ntob('?='))
raise ValueError("Could not encode header part %r using "
"any of the encodings %r." %
(v, cls.encodings))
encode = classmethod(encode)
class Host(object):
"""An internet address.
name
Should be the client's host name. If not available (because no DNS
lookup is performed), the IP address should be used instead.
"""
ip = "0.0.0.0"
port = 80
name = "unknown.tld"
def __init__(self, ip, port, name=None):
self.ip = ip
self.port = port
if name is None:
name = ip
self.name = name
def __repr__(self):
return "httputil.Host(%r, %r, %r)" % (self.ip, self.port, self.name)
|
bsd-3-clause
|
[
624,
2856,
3555,
3423,
14,
199,
199,
2765,
859,
3509,
3423,
367,
10015,
376,
3101,
4223,
199,
4857,
26,
1263,
1373,
12,
440,
2951,
1373,
7447,
536,
9174,
543,
298,
1049,
1674,
8700,
9,
982,
1265,
199,
4443,
1263,
4621,
687,
2005,
4560,
2238,
10059,
6272,
627,
3749,
10,
859,
12,
199,
19590,
2395,
1049,
85,
911,
4954,
1183,
30084,
1265,
1536,
701,
2195,
294,
23135,
436,
11482,
1265,
199,
475,
282,
4575,
883,
316,
14,
199,
624,
199,
199,
504,
14755,
492,
330,
18,
65,
63,
1095,
772,
199,
504,
13397,
423,
1850,
5819,
492,
3523,
23518,
12,
3101,
2506,
12,
302,
475,
66,
12,
302,
475,
85,
12,
10822,
12,
3355,
199,
504,
13397,
423,
1850,
5819,
492,
7116,
12,
18792,
82,
12,
10849,
12,
5438,
495,
12,
2649,
495,
12,
14342,
63,
6177,
199,
1310,
63,
6021,
275,
3523,
23518,
14,
10360,
14,
1574,
342,
199,
199,
3,
11606,
1455,
921,
1544,
14,
23438,
14,
1308,
15,
9201,
15,
15702,
199,
1310,
63,
6021,
59,
5783,
61,
275,
661,
8405,
7146,
4520,
297,
1993,
283,
1918,
1654,
14556,
376,
10537,
5558,
283,
1993,
283,
6777,
876,
1856,
471,
652,
687,
15632,
276,
12687,
314,
1056,
2659,
199,
1310,
63,
6021,
59,
15773,
61,
275,
661,
3167,
1910,
4561,
297,
1993,
283,
1918,
1654,
365,
5544,
17329,
370,
2429,
314,
283,
1993,
283,
1069,
7037,
370,
282,
7937,
1806,
8786,
503,
283,
1993,
283,
19725,
402,
314,
1654,
2659,
199,
199,
646,
295,
199,
646,
4011,
4388,
199,
318,
20818,
2031,
11521,
304,
272,
408,
1767,
314,
1627,
931,
971,
10,
11521,
12,
16538,
1901,
282,
2849,
2851,
14,
339,
961,
911,
6657,
4263,
282,
30203,
63,
2339,
436,
15097,
63,
4531,
1901,
314,
272,
3379,
2851,
12,
2755,
340,
1902,
6222,
365,
4596,
14,
272,
408,
272,
1166,
275,
3286,
1674,
904,
779,
88,
367,
671,
315,
14503,
340,
671,
566,
272,
1830,
23057,
2,
315,
1166,
26,
267,
1166,
275,
1166,
14,
1814,
21816,
401,
3286,
531,
272,
327,
12568,
13,
2546,
314,
4242,
1166,
402,
4873,
436,
372,
10609,
3140,
14,
272,
372,
1166,
503,
10609,
199,
199,
318,
20818,
63,
2394,
2031,
11521,
304,
272,
408,
1767,
314,
1627,
931,
627,
11521,
12,
16538,
1901,
282,
2849,
2851,
14,
339,
961,
911,
6657,
4263,
282,
30203,
63,
2339,
436,
15097,
63,
4531,
1901,
314,
272,
3379,
2851,
12,
2755,
340,
1902,
6222,
365,
4596,
14,
272,
408,
272,
1166,
275,
302,
475,
66,
4769,
3471,
904,
779,
88,
367,
671,
315,
14503,
340,
671,
566,
272,
1830,
302,
475,
66,
21816,
531,
315,
1166,
26,
267,
1166,
275,
1166,
14,
1814,
8,
343,
2873,
21816,
1288,
302,
475,
66,
4769,
2237,
272,
327,
12568,
13,
2546,
314,
4242,
1166,
402,
4873,
436,
372,
10609,
3140,
14,
272,
372,
1166,
503,
302,
475,
66,
19031,
199,
199,
318,
4113,
63,
504,
63,
1014,
8,
3922,
63,
495,
304,
272,
408,
1767,
282,
4113,
2008,
687,
314,
1627,
283,
2856,
15,
88,
14,
89,
7,
1059,
1041,
272,
372,
1109,
8,
3922,
63,
495,
59,
21,
2522,
1109,
8,
3922,
63,
495,
59,
23,
566,
199,
199,
318,
664,
63,
8404,
8,
1291,
585,
12,
1564,
63,
1267,
304,
272,
408,
1767,
282,
769,
402,
334,
928,
12,
3631,
9,
4918,
687,
282,
13114,
1406,
12,
503,
488,
14,
339,
7048,
334,
928,
12,
3631,
9,
2008,
911,
506,
26356,
402,
2877,
14526,
12,
1314,
787,
11233,
272,
367,
675,
315,
282,
23647,
3439,
14,
10314,
365,
12,
314,
1406,
298,
4709,
26,
2783,
29,
19,
13,
22,
401,
272,
340,
6781,
6169,
282,
2018,
1059,
12,
365,
23502,
2073,
59,
19,
26,
23,
1055,
961,
272,
805,
911,
372,
314,
769,
3842,
19,
12,
1520,
22509,
339,
982,
642,
805,
2529,
376,
2701,
769,
12,
1265,
1077,
372,
3101,
841,
975,
14,
272,
408,
339,
340,
440,
1406,
585,
26,
267,
372,
488,
339,
754,
275,
942,
272,
2783,
3248,
12,
701,
351,
618,
83,
275,
1406,
585,
14,
1294,
480,
11107,
413,
9,
272,
367,
330,
1842,
315,
701,
351,
618,
83,
14,
1294,
8,
2266,
304,
267,
1343,
12,
3631,
275,
359,
88,
14,
1913,
342,
367,
671,
315,
330,
1842,
14,
1294,
6096,
401,
413,
1874,
267,
340,
1343,
26,
288,
340,
440,
3631,
26,
355,
3631,
275,
1564,
63,
1267,
446,
413,
288,
1343,
12,
3631,
275,
1109,
8,
928,
395,
1109,
8,
2379,
9,
288,
340,
1343,
2356,
1564,
63,
1267,
26,
355,
327,
11606,
18158,
7875,
975,
6513,
4329,
14,
975,
26,
355,
327,
298,
3917,
314,
1654,
23192,
282,
1056,
334,
1848,
2419,
1373,
355,
327,
5893,
376,
982,
13,
4709,
1056,
13,
1291,
901,
9,
543,
376,
355,
327,
625,
18270,
24183,
13114,
1056,
13,
1291,
901,
334,
9099,
365,
12,
355,
327,
1006,
402,
7447,
3696,
13,
1842,
13,
1650,
1338,
1172,
282,
1642,
13,
4414,
13,
1712,
355,
327,
574,
8932,
2419,
314,
1453,
2582,
402,
314,
4895,
355,
327,
2073,
395,
652,
428,
31909,
372,
282,
1177,
1233,
402,
841,
975,
355,
327,
334,
17935,
1425,
440,
13529,
24183,
17617,
355,
1980,
288,
340,
3631,
665,
1343,
26,
355,
327,
11606,
18158,
7875,
975,
6513,
4329,
14,
975,
26,
355,
327,
298,
3917,
314,
1654,
24010,
282,
3696,
13,
1842,
13,
1650,
2952,
652,
355,
327,
365,
1847,
343,
645,
17269,
3866,
12,
314,
1654,
428,
31909,
14312,
355,
327,
314,
1056,
465,
340,
314,
3866,
13114,
1406,
901,
355,
327,
8103,
440,
2187,
14,
334,
15548,
1183,
12,
642,
4910,
372,
282,
1926,
355,
327,
1177,
3035,
314,
2615,
4642,
17617,
355,
372,
488,
288,
754,
14,
740,
1332,
928,
12,
3631,
435,
413,
430,
267,
587,
26,
288,
340,
440,
3631,
26,
355,
327,
1666,
18158,
6313,
3432,
14,
355,
372,
488,
288,
327,
32548,
1007,
1579,
334,
2019,
653,
2783,
9,
288,
754,
14,
740,
1332,
1317,
63,
1267,
446,
1109,
8,
2379,
395,
1564,
63,
1267,
430,
339,
372,
754,
421,
199,
533,
10240,
2162,
8,
785,
304,
272,
408,
2493,
1819,
334,
1045,
2633,
9,
687,
376,
3101,
1406,
1159,
1819,
769,
1041,
339,
347,
636,
826,
721,
277,
12,
574,
12,
1862
] |
[
2856,
3555,
3423,
14,
199,
199,
2765,
859,
3509,
3423,
367,
10015,
376,
3101,
4223,
199,
4857,
26,
1263,
1373,
12,
440,
2951,
1373,
7447,
536,
9174,
543,
298,
1049,
1674,
8700,
9,
982,
1265,
199,
4443,
1263,
4621,
687,
2005,
4560,
2238,
10059,
6272,
627,
3749,
10,
859,
12,
199,
19590,
2395,
1049,
85,
911,
4954,
1183,
30084,
1265,
1536,
701,
2195,
294,
23135,
436,
11482,
1265,
199,
475,
282,
4575,
883,
316,
14,
199,
624,
199,
199,
504,
14755,
492,
330,
18,
65,
63,
1095,
772,
199,
504,
13397,
423,
1850,
5819,
492,
3523,
23518,
12,
3101,
2506,
12,
302,
475,
66,
12,
302,
475,
85,
12,
10822,
12,
3355,
199,
504,
13397,
423,
1850,
5819,
492,
7116,
12,
18792,
82,
12,
10849,
12,
5438,
495,
12,
2649,
495,
12,
14342,
63,
6177,
199,
1310,
63,
6021,
275,
3523,
23518,
14,
10360,
14,
1574,
342,
199,
199,
3,
11606,
1455,
921,
1544,
14,
23438,
14,
1308,
15,
9201,
15,
15702,
199,
1310,
63,
6021,
59,
5783,
61,
275,
661,
8405,
7146,
4520,
297,
1993,
283,
1918,
1654,
14556,
376,
10537,
5558,
283,
1993,
283,
6777,
876,
1856,
471,
652,
687,
15632,
276,
12687,
314,
1056,
2659,
199,
1310,
63,
6021,
59,
15773,
61,
275,
661,
3167,
1910,
4561,
297,
1993,
283,
1918,
1654,
365,
5544,
17329,
370,
2429,
314,
283,
1993,
283,
1069,
7037,
370,
282,
7937,
1806,
8786,
503,
283,
1993,
283,
19725,
402,
314,
1654,
2659,
199,
199,
646,
295,
199,
646,
4011,
4388,
199,
318,
20818,
2031,
11521,
304,
272,
408,
1767,
314,
1627,
931,
971,
10,
11521,
12,
16538,
1901,
282,
2849,
2851,
14,
339,
961,
911,
6657,
4263,
282,
30203,
63,
2339,
436,
15097,
63,
4531,
1901,
314,
272,
3379,
2851,
12,
2755,
340,
1902,
6222,
365,
4596,
14,
272,
408,
272,
1166,
275,
3286,
1674,
904,
779,
88,
367,
671,
315,
14503,
340,
671,
566,
272,
1830,
23057,
2,
315,
1166,
26,
267,
1166,
275,
1166,
14,
1814,
21816,
401,
3286,
531,
272,
327,
12568,
13,
2546,
314,
4242,
1166,
402,
4873,
436,
372,
10609,
3140,
14,
272,
372,
1166,
503,
10609,
199,
199,
318,
20818,
63,
2394,
2031,
11521,
304,
272,
408,
1767,
314,
1627,
931,
627,
11521,
12,
16538,
1901,
282,
2849,
2851,
14,
339,
961,
911,
6657,
4263,
282,
30203,
63,
2339,
436,
15097,
63,
4531,
1901,
314,
272,
3379,
2851,
12,
2755,
340,
1902,
6222,
365,
4596,
14,
272,
408,
272,
1166,
275,
302,
475,
66,
4769,
3471,
904,
779,
88,
367,
671,
315,
14503,
340,
671,
566,
272,
1830,
302,
475,
66,
21816,
531,
315,
1166,
26,
267,
1166,
275,
1166,
14,
1814,
8,
343,
2873,
21816,
1288,
302,
475,
66,
4769,
2237,
272,
327,
12568,
13,
2546,
314,
4242,
1166,
402,
4873,
436,
372,
10609,
3140,
14,
272,
372,
1166,
503,
302,
475,
66,
19031,
199,
199,
318,
4113,
63,
504,
63,
1014,
8,
3922,
63,
495,
304,
272,
408,
1767,
282,
4113,
2008,
687,
314,
1627,
283,
2856,
15,
88,
14,
89,
7,
1059,
1041,
272,
372,
1109,
8,
3922,
63,
495,
59,
21,
2522,
1109,
8,
3922,
63,
495,
59,
23,
566,
199,
199,
318,
664,
63,
8404,
8,
1291,
585,
12,
1564,
63,
1267,
304,
272,
408,
1767,
282,
769,
402,
334,
928,
12,
3631,
9,
4918,
687,
282,
13114,
1406,
12,
503,
488,
14,
339,
7048,
334,
928,
12,
3631,
9,
2008,
911,
506,
26356,
402,
2877,
14526,
12,
1314,
787,
11233,
272,
367,
675,
315,
282,
23647,
3439,
14,
10314,
365,
12,
314,
1406,
298,
4709,
26,
2783,
29,
19,
13,
22,
401,
272,
340,
6781,
6169,
282,
2018,
1059,
12,
365,
23502,
2073,
59,
19,
26,
23,
1055,
961,
272,
805,
911,
372,
314,
769,
3842,
19,
12,
1520,
22509,
339,
982,
642,
805,
2529,
376,
2701,
769,
12,
1265,
1077,
372,
3101,
841,
975,
14,
272,
408,
339,
340,
440,
1406,
585,
26,
267,
372,
488,
339,
754,
275,
942,
272,
2783,
3248,
12,
701,
351,
618,
83,
275,
1406,
585,
14,
1294,
480,
11107,
413,
9,
272,
367,
330,
1842,
315,
701,
351,
618,
83,
14,
1294,
8,
2266,
304,
267,
1343,
12,
3631,
275,
359,
88,
14,
1913,
342,
367,
671,
315,
330,
1842,
14,
1294,
6096,
401,
413,
1874,
267,
340,
1343,
26,
288,
340,
440,
3631,
26,
355,
3631,
275,
1564,
63,
1267,
446,
413,
288,
1343,
12,
3631,
275,
1109,
8,
928,
395,
1109,
8,
2379,
9,
288,
340,
1343,
2356,
1564,
63,
1267,
26,
355,
327,
11606,
18158,
7875,
975,
6513,
4329,
14,
975,
26,
355,
327,
298,
3917,
314,
1654,
23192,
282,
1056,
334,
1848,
2419,
1373,
355,
327,
5893,
376,
982,
13,
4709,
1056,
13,
1291,
901,
9,
543,
376,
355,
327,
625,
18270,
24183,
13114,
1056,
13,
1291,
901,
334,
9099,
365,
12,
355,
327,
1006,
402,
7447,
3696,
13,
1842,
13,
1650,
1338,
1172,
282,
1642,
13,
4414,
13,
1712,
355,
327,
574,
8932,
2419,
314,
1453,
2582,
402,
314,
4895,
355,
327,
2073,
395,
652,
428,
31909,
372,
282,
1177,
1233,
402,
841,
975,
355,
327,
334,
17935,
1425,
440,
13529,
24183,
17617,
355,
1980,
288,
340,
3631,
665,
1343,
26,
355,
327,
11606,
18158,
7875,
975,
6513,
4329,
14,
975,
26,
355,
327,
298,
3917,
314,
1654,
24010,
282,
3696,
13,
1842,
13,
1650,
2952,
652,
355,
327,
365,
1847,
343,
645,
17269,
3866,
12,
314,
1654,
428,
31909,
14312,
355,
327,
314,
1056,
465,
340,
314,
3866,
13114,
1406,
901,
355,
327,
8103,
440,
2187,
14,
334,
15548,
1183,
12,
642,
4910,
372,
282,
1926,
355,
327,
1177,
3035,
314,
2615,
4642,
17617,
355,
372,
488,
288,
754,
14,
740,
1332,
928,
12,
3631,
435,
413,
430,
267,
587,
26,
288,
340,
440,
3631,
26,
355,
327,
1666,
18158,
6313,
3432,
14,
355,
372,
488,
288,
327,
32548,
1007,
1579,
334,
2019,
653,
2783,
9,
288,
754,
14,
740,
1332,
1317,
63,
1267,
446,
1109,
8,
2379,
395,
1564,
63,
1267,
430,
339,
372,
754,
421,
199,
533,
10240,
2162,
8,
785,
304,
272,
408,
2493,
1819,
334,
1045,
2633,
9,
687,
376,
3101,
1406,
1159,
1819,
769,
1041,
339,
347,
636,
826,
721,
277,
12,
574,
12,
1862,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jazzmes/ryu
|
ryu/services/protocols/bgp/operator/commands/show/count.py
|
52
|
1840
|
import logging
from ryu.services.protocols.bgp.operator.command import Command
from ryu.services.protocols.bgp.operator.command import CommandsResponse
from ryu.services.protocols.bgp.operator.command import STATUS_ERROR
from ryu.services.protocols.bgp.operator.command import STATUS_OK
from ryu.services.protocols.bgp.operator.commands.responses import \
WrongParamResp
LOG = logging.getLogger('bgpspeaker.operator.commands.show.count')
class Count(Command):
help_msg = 'show counters'
param_help_msg = '<vpn-name> <route-family>{ipv4, ipv6}'
command = 'count'
cli_resp_line_template = 'BGP route count for VPN {0} is {1}\n'
def __init__(self, *args, **kwargs):
super(Count, self).__init__(*args, **kwargs)
self.subcommands = {
'all': self.All
}
def action(self, params):
if len(params) < 1:
return CommandsResponse(STATUS_ERROR, 'Not enough params')
else:
vrf_name = params[0]
if len(params) == 2:
vrf_rf = params[1]
else:
vrf_rf = 'ipv4'
from ryu.services.protocols.bgp.operator.internal_api import \
WrongParamError
try:
return CommandsResponse(
STATUS_OK,
self.api.count_single_vrf_routes(vrf_name, vrf_rf)
)
except WrongParamError as e:
return WrongParamResp(e)
class All(Command):
help_msg = 'shows number of routes for all VRFs'
command = 'all'
cli_resp_line_template = 'BGP route count for VPN {0} is {1}\n'
def action(self, params):
if len(params) > 0:
return WrongParamResp()
return CommandsResponse(STATUS_OK, self.api.count_all_vrf_routes())
|
apache-2.0
|
[
646,
2050,
199,
199,
504,
25494,
14,
5950,
14,
16541,
14,
10132,
14,
3856,
14,
1531,
492,
5817,
199,
504,
25494,
14,
5950,
14,
16541,
14,
10132,
14,
3856,
14,
1531,
492,
5817,
83,
2364,
199,
504,
25494,
14,
5950,
14,
16541,
14,
10132,
14,
3856,
14,
1531,
492,
18460,
63,
3170,
199,
504,
25494,
14,
5950,
14,
16541,
14,
10132,
14,
3856,
14,
1531,
492,
18460,
63,
3593,
199,
504,
25494,
14,
5950,
14,
16541,
14,
10132,
14,
3856,
14,
4405,
14,
10360,
492,
971,
272,
30801,
4098,
28797,
199,
199,
4947,
275,
2050,
14,
5572,
360,
6856,
1190,
19838,
14,
3856,
14,
4405,
14,
2384,
14,
835,
358,
421,
199,
533,
14826,
8,
3110,
304,
272,
1720,
63,
1328,
275,
283,
2384,
21272,
7,
272,
1215,
63,
3437,
63,
1328,
275,
2650,
9702,
13,
354,
30,
665,
4449,
13,
6606,
22266,
4774,
20,
12,
3278,
22,
6834,
272,
1414,
275,
283,
835,
7,
272,
5053,
63,
4518,
63,
604,
63,
1160,
275,
283,
27272,
7475,
2338,
367,
29057,
469,
16,
93,
365,
469,
17,
4988,
78,
7,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
2353,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
954,
4405,
275,
469,
288,
283,
452,
356,
291,
14,
2422,
267,
789,
339,
347,
1595,
8,
277,
12,
1862,
304,
267,
340,
822,
8,
1162,
9,
665,
413,
26,
288,
372,
5817,
83,
2364,
8,
6305,
63,
3170,
12,
283,
1763,
8321,
1862,
358,
267,
587,
26,
288,
15209,
63,
354,
275,
1862,
59,
16,
61,
288,
340,
822,
8,
1162,
9,
508,
499,
26,
355,
15209,
63,
3941,
275,
1862,
59,
17,
61,
288,
587,
26,
355,
15209,
63,
3941,
275,
283,
4774,
20,
7,
953,
687,
25494,
14,
5950,
14,
16541,
14,
10132,
14,
3856,
14,
4672,
63,
1246,
492,
971,
355,
30801,
4098,
547,
288,
862,
26,
355,
372,
5817,
83,
2364,
8,
490,
18460,
63,
3593,
12,
490,
291,
14,
1246,
14,
835,
63,
4780,
63,
11863,
63,
13243,
8,
11863,
63,
354,
12,
15209,
63,
3941,
9,
355,
776,
288,
871,
30801,
4098,
547,
465,
325,
26,
355,
372,
30801,
4098,
28797,
8,
69,
9,
339,
1021,
2900,
8,
3110,
304,
267,
1720,
63,
1328,
275,
283,
23866,
1329,
402,
15777,
367,
1006,
812,
11778,
83,
7,
267,
1414,
275,
283,
452,
7,
267,
5053,
63,
4518,
63,
604,
63,
1160,
275,
283,
27272,
7475,
2338,
367,
29057,
469,
16,
93,
365,
469,
17,
4988,
78,
7,
398,
347,
1595,
8,
277,
12,
1862,
304,
288,
340,
822,
8,
1162,
9,
690,
378,
26,
355,
372,
30801,
4098,
28797,
342,
288,
372,
5817,
83,
2364,
8,
6305,
63,
3593,
12,
291,
14,
1246,
14,
835,
63,
452,
63,
11863,
63,
13243,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2050,
199,
199,
504,
25494,
14,
5950,
14,
16541,
14,
10132,
14,
3856,
14,
1531,
492,
5817,
199,
504,
25494,
14,
5950,
14,
16541,
14,
10132,
14,
3856,
14,
1531,
492,
5817,
83,
2364,
199,
504,
25494,
14,
5950,
14,
16541,
14,
10132,
14,
3856,
14,
1531,
492,
18460,
63,
3170,
199,
504,
25494,
14,
5950,
14,
16541,
14,
10132,
14,
3856,
14,
1531,
492,
18460,
63,
3593,
199,
504,
25494,
14,
5950,
14,
16541,
14,
10132,
14,
3856,
14,
4405,
14,
10360,
492,
971,
272,
30801,
4098,
28797,
199,
199,
4947,
275,
2050,
14,
5572,
360,
6856,
1190,
19838,
14,
3856,
14,
4405,
14,
2384,
14,
835,
358,
421,
199,
533,
14826,
8,
3110,
304,
272,
1720,
63,
1328,
275,
283,
2384,
21272,
7,
272,
1215,
63,
3437,
63,
1328,
275,
2650,
9702,
13,
354,
30,
665,
4449,
13,
6606,
22266,
4774,
20,
12,
3278,
22,
6834,
272,
1414,
275,
283,
835,
7,
272,
5053,
63,
4518,
63,
604,
63,
1160,
275,
283,
27272,
7475,
2338,
367,
29057,
469,
16,
93,
365,
469,
17,
4988,
78,
7,
339,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
2353,
12,
291,
2843,
826,
9308,
589,
12,
1011,
958,
9,
267,
291,
14,
954,
4405,
275,
469,
288,
283,
452,
356,
291,
14,
2422,
267,
789,
339,
347,
1595,
8,
277,
12,
1862,
304,
267,
340,
822,
8,
1162,
9,
665,
413,
26,
288,
372,
5817,
83,
2364,
8,
6305,
63,
3170,
12,
283,
1763,
8321,
1862,
358,
267,
587,
26,
288,
15209,
63,
354,
275,
1862,
59,
16,
61,
288,
340,
822,
8,
1162,
9,
508,
499,
26,
355,
15209,
63,
3941,
275,
1862,
59,
17,
61,
288,
587,
26,
355,
15209,
63,
3941,
275,
283,
4774,
20,
7,
953,
687,
25494,
14,
5950,
14,
16541,
14,
10132,
14,
3856,
14,
4672,
63,
1246,
492,
971,
355,
30801,
4098,
547,
288,
862,
26,
355,
372,
5817,
83,
2364,
8,
490,
18460,
63,
3593,
12,
490,
291,
14,
1246,
14,
835,
63,
4780,
63,
11863,
63,
13243,
8,
11863,
63,
354,
12,
15209,
63,
3941,
9,
355,
776,
288,
871,
30801,
4098,
547,
465,
325,
26,
355,
372,
30801,
4098,
28797,
8,
69,
9,
339,
1021,
2900,
8,
3110,
304,
267,
1720,
63,
1328,
275,
283,
23866,
1329,
402,
15777,
367,
1006,
812,
11778,
83,
7,
267,
1414,
275,
283,
452,
7,
267,
5053,
63,
4518,
63,
604,
63,
1160,
275,
283,
27272,
7475,
2338,
367,
29057,
469,
16,
93,
365,
469,
17,
4988,
78,
7,
398,
347,
1595,
8,
277,
12,
1862,
304,
288,
340,
822,
8,
1162,
9,
690,
378,
26,
355,
372,
30801,
4098,
28797,
342,
288,
372,
5817,
83,
2364,
8,
6305,
63,
3593,
12,
291,
14,
1246,
14,
835,
63,
452,
63,
11863,
63,
13243,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
skudriashev/incubator-airflow
|
tests/contrib/sensors/test_jira_sensor_test.py
|
37
|
2886
|
# -*- coding: utf-8 -*-
#
# 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 unittest
import datetime
from mock import Mock
from mock import patch
from airflow import DAG, configuration
from airflow.contrib.sensors.jira_sensor import JiraTicketSensor
from airflow import models
from airflow.utils import db
DEFAULT_DATE = datetime.datetime(2017, 1, 1)
jira_client_mock = Mock(
name="jira_client_for_test"
)
minimal_test_ticket = {
"id": "911539",
"self": "https://sandbox.localhost/jira/rest/api/2/issue/911539",
"key": "TEST-1226",
"fields": {
"labels": [
"test-label-1",
"test-label-2"
],
"description": "this is a test description",
}
}
class TestJiraSensor(unittest.TestCase):
def setUp(self):
configuration.load_test_config()
args = {
'owner': 'airflow',
'start_date': DEFAULT_DATE
}
dag = DAG('test_dag_id', default_args=args)
self.dag = dag
db.merge_conn(
models.Connection(
conn_id='jira_default', conn_type='jira',
host='https://localhost/jira/', port=443,
extra='{"verify": "False", "project": "AIRFLOW"}'))
@patch("airflow.contrib.hooks.jira_hook.JIRA",
autospec=True, return_value=jira_client_mock)
def test_issue_label_set(self, jira_mock):
jira_mock.return_value.issue.return_value = minimal_test_ticket
ticket_label_sensor = JiraTicketSensor(task_id='search-ticket-test',
ticket_id='TEST-1226',
field_checker_func=
TestJiraSensor.field_checker_func,
timeout=518400,
poke_interval=10,
dag=self.dag)
ticket_label_sensor.run(start_date=DEFAULT_DATE,
end_date=DEFAULT_DATE, ignore_ti_state=True)
self.assertTrue(jira_mock.called)
self.assertTrue(jira_mock.return_value.issue.called)
@staticmethod
def field_checker_func(context, issue):
return "test-label-1" in issue['fields']['labels']
if __name__ == '__main__':
unittest.main()
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
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,
2882,
199,
646,
2197,
199,
504,
1683,
492,
4420,
199,
504,
1683,
492,
3371,
199,
199,
504,
16321,
492,
19666,
12,
2897,
199,
504,
16321,
14,
2828,
14,
22675,
14,
28097,
63,
8956,
492,
1603,
20936,
25813,
10160,
199,
504,
16321,
492,
1709,
199,
504,
16321,
14,
1208,
492,
1592,
199,
199,
3472,
63,
5390,
275,
2197,
14,
2083,
8,
10680,
12,
413,
12,
413,
9,
199,
28097,
63,
1258,
63,
1805,
275,
4420,
8,
267,
536,
628,
28097,
63,
1258,
63,
509,
63,
396,
2,
199,
9,
199,
199,
21508,
63,
396,
63,
9201,
275,
469,
272,
298,
344,
582,
298,
25,
7680,
1355,
401,
272,
298,
277,
582,
298,
2859,
921,
16647,
14,
5967,
15,
28097,
15,
3911,
15,
1246,
15,
18,
15,
5237,
15,
25,
7680,
1355,
401,
272,
298,
498,
582,
298,
2864,
13,
713,
1479,
401,
272,
298,
955,
582,
469,
267,
298,
3512,
582,
359,
288,
298,
396,
13,
1302,
13,
17,
401,
288,
298,
396,
13,
1302,
13,
18,
2,
267,
2156,
267,
298,
1802,
582,
298,
3749,
365,
282,
511,
1369,
401,
272,
789,
199,
93,
421,
199,
533,
1379,
16911,
345,
10160,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
2897,
14,
912,
63,
396,
63,
888,
342,
267,
1249,
275,
469,
288,
283,
4597,
356,
283,
15815,
297,
288,
283,
928,
63,
602,
356,
6186,
63,
5390,
267,
789,
267,
10158,
275,
19666,
360,
396,
63,
7406,
63,
344,
297,
849,
63,
589,
29,
589,
9,
267,
291,
14,
7406,
275,
10158,
267,
1592,
14,
5628,
63,
1631,
8,
355,
1709,
14,
3225,
8,
717,
2557,
63,
344,
534,
28097,
63,
885,
297,
2557,
63,
466,
534,
28097,
297,
717,
1591,
534,
2859,
921,
5967,
15,
28097,
3678,
1844,
29,
16284,
12,
717,
2402,
534,
6641,
4712,
582,
298,
797,
401,
298,
1715,
582,
298,
33,
3927,
17114,
3570,
1333,
339,
768,
2068,
480,
15815,
14,
2828,
14,
7922,
14,
28097,
63,
3664,
14,
32126,
2847,
401,
1779,
18052,
29,
549,
12,
372,
63,
585,
29,
28097,
63,
1258,
63,
1805,
9,
272,
347,
511,
63,
5237,
63,
1302,
63,
409,
8,
277,
12,
1335,
20936,
63,
1805,
304,
267,
1335,
20936,
63,
1805,
14,
1107,
63,
585,
14,
5237,
14,
1107,
63,
585,
275,
13460,
63,
396,
63,
9201,
398,
12052,
63,
1302,
63,
8956,
275,
1603,
20936,
25813,
10160,
8,
1765,
63,
344,
534,
1733,
13,
9201,
13,
396,
297,
6901,
12052,
63,
344,
534,
2864,
13,
713,
1479,
297,
6901,
901,
63,
6743,
63,
1532,
29,
6901,
1379,
16911,
345,
10160,
14,
698,
63,
6743,
63,
1532,
12,
6901,
2653,
29,
27015,
5303,
12,
6901,
1115,
415,
63,
4284,
29,
709,
12,
6901,
10158,
29,
277,
14,
7406,
9,
398,
12052,
63,
1302,
63,
8956,
14,
1065,
8,
928,
63,
602,
29,
3472,
63,
5390,
12,
1816,
1284,
63,
602,
29,
3472,
63,
5390,
12,
3686,
63,
280,
63,
929,
29,
549,
9,
398,
291,
14,
1815,
8,
28097,
63,
1805,
14,
3527,
9,
267,
291,
14,
1815,
8,
28097,
63,
1805,
14,
1107,
63,
585,
14,
5237,
14,
3527,
9,
339,
768,
4639,
272,
347,
901,
63,
6743,
63,
1532,
8,
1100,
12,
4976,
304,
267,
372,
298,
396,
13,
1302,
13,
17,
2,
315,
4976,
459,
955,
2545,
3512,
418,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
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,
2882,
199,
646,
2197,
199,
504,
1683,
492,
4420,
199,
504,
1683,
492,
3371,
199,
199,
504,
16321,
492,
19666,
12,
2897,
199,
504,
16321,
14,
2828,
14,
22675,
14,
28097,
63,
8956,
492,
1603,
20936,
25813,
10160,
199,
504,
16321,
492,
1709,
199,
504,
16321,
14,
1208,
492,
1592,
199,
199,
3472,
63,
5390,
275,
2197,
14,
2083,
8,
10680,
12,
413,
12,
413,
9,
199,
28097,
63,
1258,
63,
1805,
275,
4420,
8,
267,
536,
628,
28097,
63,
1258,
63,
509,
63,
396,
2,
199,
9,
199,
199,
21508,
63,
396,
63,
9201,
275,
469,
272,
298,
344,
582,
298,
25,
7680,
1355,
401,
272,
298,
277,
582,
298,
2859,
921,
16647,
14,
5967,
15,
28097,
15,
3911,
15,
1246,
15,
18,
15,
5237,
15,
25,
7680,
1355,
401,
272,
298,
498,
582,
298,
2864,
13,
713,
1479,
401,
272,
298,
955,
582,
469,
267,
298,
3512,
582,
359,
288,
298,
396,
13,
1302,
13,
17,
401,
288,
298,
396,
13,
1302,
13,
18,
2,
267,
2156,
267,
298,
1802,
582,
298,
3749,
365,
282,
511,
1369,
401,
272,
789,
199,
93,
421,
199,
533,
1379,
16911,
345,
10160,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
2897,
14,
912,
63,
396,
63,
888,
342,
267,
1249,
275,
469,
288,
283,
4597,
356,
283,
15815,
297,
288,
283,
928,
63,
602,
356,
6186,
63,
5390,
267,
789,
267,
10158,
275,
19666,
360,
396,
63,
7406,
63,
344,
297,
849,
63,
589,
29,
589,
9,
267,
291,
14,
7406,
275,
10158,
267,
1592,
14,
5628,
63,
1631,
8,
355,
1709,
14,
3225,
8,
717,
2557,
63,
344,
534,
28097,
63,
885,
297,
2557,
63,
466,
534,
28097,
297,
717,
1591,
534,
2859,
921,
5967,
15,
28097,
3678,
1844,
29,
16284,
12,
717,
2402,
534,
6641,
4712,
582,
298,
797,
401,
298,
1715,
582,
298,
33,
3927,
17114,
3570,
1333,
339,
768,
2068,
480,
15815,
14,
2828,
14,
7922,
14,
28097,
63,
3664,
14,
32126,
2847,
401,
1779,
18052,
29,
549,
12,
372,
63,
585,
29,
28097,
63,
1258,
63,
1805,
9,
272,
347,
511,
63,
5237,
63,
1302,
63,
409,
8,
277,
12,
1335,
20936,
63,
1805,
304,
267,
1335,
20936,
63,
1805,
14,
1107,
63,
585,
14,
5237,
14,
1107,
63,
585,
275,
13460,
63,
396,
63,
9201,
398,
12052,
63,
1302,
63,
8956,
275,
1603,
20936,
25813,
10160,
8,
1765,
63,
344,
534,
1733,
13,
9201,
13,
396,
297,
6901,
12052,
63,
344,
534,
2864,
13,
713,
1479,
297,
6901,
901,
63,
6743,
63,
1532,
29,
6901,
1379,
16911,
345,
10160,
14,
698,
63,
6743,
63,
1532,
12,
6901,
2653,
29,
27015,
5303,
12,
6901,
1115,
415,
63,
4284,
29,
709,
12,
6901,
10158,
29,
277,
14,
7406,
9,
398,
12052,
63,
1302,
63,
8956,
14,
1065,
8,
928,
63,
602,
29,
3472,
63,
5390,
12,
1816,
1284,
63,
602,
29,
3472,
63,
5390,
12,
3686,
63,
280,
63,
929,
29,
549,
9,
398,
291,
14,
1815,
8,
28097,
63,
1805,
14,
3527,
9,
267,
291,
14,
1815,
8,
28097,
63,
1805,
14,
1107,
63,
585,
14,
5237,
14,
3527,
9,
339,
768,
4639,
272,
347,
901,
63,
6743,
63,
1532,
8,
1100,
12,
4976,
304,
267,
372,
298,
396,
13,
1302,
13,
17,
2,
315,
4976,
459,
955,
2545,
3512,
418,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
teeple/pns_server
|
work/install/Python-2.7.4/Lib/test/test_file_eintr.py
|
95
|
10480
|
# Written to test interrupted system calls interfering with our many buffered
# IO implementations. http://bugs.python.org/issue12268
#
# This tests the '_io' module. Similar tests for Python 2.x's older
# default file I/O implementation exist within test_file2k.py.
#
# It was suggested that this code could be merged into test_io and the tests
# made to work using the same method as the existing signal tests in test_io.
# I was unable to get single process tests using alarm or setitimer that way
# to reproduce the EINTR problems. This process based test suite reproduces
# the problems prior to the issue12268 patch reliably on Linux and OSX.
# - gregory.p.smith
import os
import select
import signal
import subprocess
import sys
from test.test_support import run_unittest
import time
import unittest
# Test import all of the things we're about to try testing up front.
from _io import FileIO
@unittest.skipUnless(os.name == 'posix', 'tests requires a posix system.')
class TestFileIOSignalInterrupt(unittest.TestCase):
def setUp(self):
self._process = None
def tearDown(self):
if self._process and self._process.poll() is None:
try:
self._process.kill()
except OSError:
pass
def _generate_infile_setup_code(self):
"""Returns the infile = ... line of code for the reader process.
subclasseses should override this to test different IO objects.
"""
return ('import _io ;'
'infile = _io.FileIO(sys.stdin.fileno(), "rb")')
def fail_with_process_info(self, why, stdout=b'', stderr=b'',
communicate=True):
"""A common way to cleanup and fail with useful debug output.
Kills the process if it is still running, collects remaining output
and fails the test with an error message including the output.
Args:
why: Text to go after "Error from IO process" in the message.
stdout, stderr: standard output and error from the process so
far to include in the error message.
communicate: bool, when True we call communicate() on the process
after killing it to gather additional output.
"""
if self._process.poll() is None:
time.sleep(0.1) # give it time to finish printing the error.
try:
self._process.terminate() # Ensure it dies.
except OSError:
pass
if communicate:
stdout_end, stderr_end = self._process.communicate()
stdout += stdout_end
stderr += stderr_end
self.fail('Error from IO process %s:\nSTDOUT:\n%sSTDERR:\n%s\n' %
(why, stdout.decode(), stderr.decode()))
def _test_reading(self, data_to_write, read_and_verify_code):
"""Generic buffered read method test harness to validate EINTR behavior.
Also validates that Python signal handlers are run during the read.
Args:
data_to_write: String to write to the child process for reading
before sending it a signal, confirming the signal was handled,
writing a final newline and closing the infile pipe.
read_and_verify_code: Single "line" of code to read from a file
object named 'infile' and validate the result. This will be
executed as part of a python subprocess fed data_to_write.
"""
infile_setup_code = self._generate_infile_setup_code()
# Total pipe IO in this function is smaller than the minimum posix OS
# pipe buffer size of 512 bytes. No writer should block.
assert len(data_to_write) < 512, 'data_to_write must fit in pipe buf.'
# Start a subprocess to call our read method while handling a signal.
self._process = subprocess.Popen(
[sys.executable, '-u', '-c',
'import io, signal, sys ;'
'signal.signal(signal.SIGINT, '
'lambda s, f: sys.stderr.write("$\\n")) ;'
+ infile_setup_code + ' ;' +
'sys.stderr.write("Worm Sign!\\n") ;'
+ read_and_verify_code + ' ;' +
'infile.close()'
],
stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
# Wait for the signal handler to be installed.
worm_sign = self._process.stderr.read(len(b'Worm Sign!\n'))
if worm_sign != b'Worm Sign!\n': # See also, Dune by Frank Herbert.
self.fail_with_process_info('while awaiting a sign',
stderr=worm_sign)
self._process.stdin.write(data_to_write)
signals_sent = 0
rlist = []
# We don't know when the read_and_verify_code in our child is actually
# executing within the read system call we want to interrupt. This
# loop waits for a bit before sending the first signal to increase
# the likelihood of that. Implementations without correct EINTR
# and signal handling usually fail this test.
while not rlist:
rlist, _, _ = select.select([self._process.stderr], (), (), 0.05)
self._process.send_signal(signal.SIGINT)
signals_sent += 1
if signals_sent > 200:
self._process.kill()
self.fail('reader process failed to handle our signals.')
# This assumes anything unexpected that writes to stderr will also
# write a newline. That is true of the traceback printing code.
signal_line = self._process.stderr.readline()
if signal_line != b'$\n':
self.fail_with_process_info('while awaiting signal',
stderr=signal_line)
# We append a newline to our input so that a readline call can
# end on its own before the EOF is seen and so that we're testing
# the read call that was interrupted by a signal before the end of
# the data stream has been reached.
stdout, stderr = self._process.communicate(input=b'\n')
if self._process.returncode:
self.fail_with_process_info(
'exited rc=%d' % self._process.returncode,
stdout, stderr, communicate=False)
# PASS!
# String format for the read_and_verify_code used by read methods.
_READING_CODE_TEMPLATE = (
'got = infile.{read_method_name}() ;'
'expected = {expected!r} ;'
'assert got == expected, ('
'"{read_method_name} returned wrong data.\\n"'
'"got data %r\\nexpected %r" % (got, expected))'
)
def test_readline(self):
"""readline() must handle signals and not lose data."""
self._test_reading(
data_to_write=b'hello, world!',
read_and_verify_code=self._READING_CODE_TEMPLATE.format(
read_method_name='readline',
expected=b'hello, world!\n'))
def test_readlines(self):
"""readlines() must handle signals and not lose data."""
self._test_reading(
data_to_write=b'hello\nworld!',
read_and_verify_code=self._READING_CODE_TEMPLATE.format(
read_method_name='readlines',
expected=[b'hello\n', b'world!\n']))
def test_readall(self):
"""readall() must handle signals and not lose data."""
self._test_reading(
data_to_write=b'hello\nworld!',
read_and_verify_code=self._READING_CODE_TEMPLATE.format(
read_method_name='readall',
expected=b'hello\nworld!\n'))
# read() is the same thing as readall().
self._test_reading(
data_to_write=b'hello\nworld!',
read_and_verify_code=self._READING_CODE_TEMPLATE.format(
read_method_name='read',
expected=b'hello\nworld!\n'))
class TestBufferedIOSignalInterrupt(TestFileIOSignalInterrupt):
def _generate_infile_setup_code(self):
"""Returns the infile = ... line of code to make a BufferedReader."""
return ('infile = io.open(sys.stdin.fileno(), "rb") ;'
'import _io ;assert isinstance(infile, _io.BufferedReader)')
def test_readall(self):
"""BufferedReader.read() must handle signals and not lose data."""
self._test_reading(
data_to_write=b'hello\nworld!',
read_and_verify_code=self._READING_CODE_TEMPLATE.format(
read_method_name='read',
expected=b'hello\nworld!\n'))
class TestTextIOSignalInterrupt(TestFileIOSignalInterrupt):
def _generate_infile_setup_code(self):
"""Returns the infile = ... line of code to make a TextIOWrapper."""
return ('infile = io.open(sys.stdin.fileno(), "rt", newline=None) ;'
'import _io ;assert isinstance(infile, _io.TextIOWrapper)')
def test_readline(self):
"""readline() must handle signals and not lose data."""
self._test_reading(
data_to_write=b'hello, world!',
read_and_verify_code=self._READING_CODE_TEMPLATE.format(
read_method_name='readline',
expected='hello, world!\n'))
def test_readlines(self):
"""readlines() must handle signals and not lose data."""
self._test_reading(
data_to_write=b'hello\r\nworld!',
read_and_verify_code=self._READING_CODE_TEMPLATE.format(
read_method_name='readlines',
expected=['hello\n', 'world!\n']))
def test_readall(self):
"""read() must handle signals and not lose data."""
self._test_reading(
data_to_write=b'hello\nworld!',
read_and_verify_code=self._READING_CODE_TEMPLATE.format(
read_method_name='read',
expected="hello\nworld!\n"))
def test_main():
test_cases = [
tc for tc in globals().values()
if isinstance(tc, type) and issubclass(tc, unittest.TestCase)]
run_unittest(*test_cases)
if __name__ == '__main__':
test_main()
|
gpl-2.0
|
[
3,
27694,
370,
511,
31366,
2656,
4882,
1640,
2412,
316,
543,
4154,
5002,
20224,
199,
3,
5004,
12591,
14,
221,
1455,
921,
13017,
14,
1548,
14,
1308,
15,
5237,
713,
13731,
199,
3,
199,
3,
961,
2295,
314,
2513,
2308,
7,
859,
14,
221,
20046,
2295,
367,
2018,
499,
14,
88,
1159,
12731,
199,
3,
849,
570,
473,
15,
47,
4514,
2187,
4453,
511,
63,
493,
18,
75,
14,
647,
14,
199,
3,
199,
3,
2779,
1990,
25697,
626,
642,
1233,
4293,
506,
9545,
1901,
511,
63,
2308,
436,
314,
2295,
199,
3,
6326,
370,
1736,
1808,
314,
2011,
1083,
465,
314,
3411,
4673,
2295,
315,
511,
63,
2308,
14,
199,
3,
473,
1990,
17329,
370,
664,
2849,
2112,
2295,
1808,
17987,
503,
542,
280,
7414,
626,
4340,
199,
3,
370,
9172,
314,
662,
19652,
8826,
14,
221,
961,
2112,
4079,
511,
5241,
295,
24658,
199,
3,
314,
8826,
6791,
370,
314,
4976,
713,
13731,
3371,
16492,
6665,
641,
10130,
436,
32144,
14,
199,
3,
221,
446,
486,
1135,
1089,
14,
80,
14,
3300,
448,
199,
199,
646,
747,
199,
646,
3504,
199,
646,
4673,
199,
646,
3873,
199,
646,
984,
199,
504,
511,
14,
396,
63,
4058,
492,
1255,
63,
2796,
199,
646,
900,
199,
646,
2882,
199,
199,
3,
1379,
492,
1006,
402,
314,
7645,
781,
3984,
3595,
370,
862,
5343,
1536,
13738,
14,
199,
504,
485,
2308,
492,
3814,
2090,
421,
199,
32,
2796,
14,
11278,
8,
736,
14,
354,
508,
283,
9228,
297,
283,
2219,
5074,
282,
10694,
2656,
2659,
199,
533,
1379,
26126,
11274,
10647,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
423,
1412,
275,
488,
339,
347,
6766,
8,
277,
304,
267,
340,
291,
423,
1412,
436,
291,
423,
1412,
14,
6843,
342,
365,
488,
26,
288,
862,
26,
355,
291,
423,
1412,
14,
8997,
342,
288,
871,
6440,
26,
355,
986,
339,
347,
485,
4208,
63,
13880,
63,
2758,
63,
600,
8,
277,
304,
267,
408,
3407,
314,
14734,
275,
2263,
1004,
402,
1233,
367,
314,
7002,
2112,
14,
398,
1007,
429,
305,
261,
874,
1077,
4278,
642,
370,
511,
3365,
5004,
2251,
14,
267,
408,
267,
372,
661,
646,
485,
2308,
8700,
7,
355,
283,
13880,
275,
485,
2308,
14,
26126,
8,
1274,
14,
6626,
14,
9843,
1062,
298,
4848,
531,
358,
339,
347,
2449,
63,
1045,
63,
1412,
63,
815,
8,
277,
12,
10842,
12,
3839,
29,
66,
6448,
4635,
29,
66,
6448,
3044,
26808,
29,
549,
304,
267,
408,
33,
2863,
4340,
370,
9058,
436,
2449,
543,
2997,
3105,
1072,
14,
398,
1804,
15350,
314,
2112,
340,
652,
365,
5139,
3879,
12,
8775,
83,
7971,
1072,
267,
436,
6918,
314,
511,
543,
376,
1125,
1245,
5893,
314,
1072,
14,
398,
3033,
26,
288,
10842,
26,
4516,
370,
2621,
2410,
298,
547,
687,
5004,
2112,
2,
315,
314,
1245,
14,
288,
3839,
12,
4635,
26,
4465,
1072,
436,
1125,
687,
314,
2112,
880,
355,
12474,
370,
2387,
315,
314,
1125,
1245,
14,
288,
26808,
26,
2155,
12,
1380,
715,
781,
1240,
26808,
342,
641,
314,
2112,
355,
2410,
1022,
12687,
652,
370,
13082,
4722,
1072,
14,
267,
408,
267,
340,
291,
423,
1412,
14,
6843,
342,
365,
488,
26,
288,
900,
14,
4532,
8,
16,
14,
17,
9,
221,
327,
8120,
652,
900,
370,
9578,
16116,
314,
1125,
14,
288,
862,
26,
355,
291,
423,
1412,
14,
14478,
342,
221,
327,
7523,
652,
487,
397,
14,
288,
871,
6440,
26,
355,
986,
267,
340,
26808,
26,
288,
3839,
63,
500,
12,
4635,
63,
500,
275,
291,
423,
1412,
14,
10664,
342,
288,
3839,
847,
3839,
63,
500,
288,
4635,
847,
4635,
63,
500,
267,
291,
14,
1633,
360,
547,
687,
5004,
2112,
450,
83,
3427,
78,
13850,
3427,
78,
5,
83,
18472,
2666,
3427,
78,
5,
83,
60,
78,
7,
450,
2116,
334,
26460,
12,
3839,
14,
2708,
1062,
4635,
14,
2708,
4059,
339,
347,
485,
396,
63,
19332,
8,
277,
12,
666,
63,
475,
63,
952,
12,
1586,
63,
460,
63,
4712,
63,
600,
304,
267,
408,
9417,
20224,
1586,
1083,
511,
20458,
370,
4107,
662,
19652,
5953,
14,
398,
6121,
29280,
626,
2018,
4673,
8297,
787,
1255,
5309,
314,
1586,
14,
398,
3033,
26,
288,
666,
63,
475,
63,
952,
26,
2624,
370,
2218,
370,
314,
1982,
2112,
367,
7664,
355,
2544,
10209,
652,
282,
4673,
12,
12679,
316,
314,
4673,
1990,
8860,
12,
355,
3575,
282,
4242,
8057,
436,
11261,
314,
14734,
5200,
14,
288,
1586,
63,
460,
63,
4712,
63,
600,
26,
13050,
298,
604,
2,
402,
1233,
370,
1586,
687,
282,
570,
355,
909,
4310,
283,
13880,
7,
436,
4107,
314,
754,
14,
221,
961,
911,
506,
355,
7934,
465,
1777,
402,
282,
2366,
3873,
23036,
666,
63,
475,
63,
952,
14,
267,
408,
267,
14734,
63,
2758,
63,
600,
275,
291,
423,
4208,
63,
13880,
63,
2758,
63,
600,
342,
267,
327,
19271,
5200,
5004,
315,
642,
805,
365,
12700,
2419,
314,
7481,
10694,
4403,
267,
327,
5200,
3335,
1568,
402,
10574,
2783,
14,
221,
3091,
7060,
1077,
1853,
14,
267,
702,
822,
8,
576,
63,
475,
63,
952,
9,
665,
10574,
12,
283,
576,
63,
475,
63,
952,
1471,
5542,
315,
5200,
4123,
3530,
398,
327,
7707,
282,
3873,
370,
1240,
4154,
1586,
1083,
1830,
7252,
282,
4673,
14,
267,
291,
423,
1412,
275,
3873,
14,
7942,
8,
355,
359,
1274,
14,
5904,
12,
2475,
85,
297,
2475,
67,
297,
326,
283,
646,
5890,
12,
4673,
12,
984,
8700,
7,
326,
283,
4653,
14,
4653,
8,
4653,
14,
21223,
12,
283,
3044,
283,
2734,
308,
12,
289,
26,
984,
14,
3083,
14,
952,
21506,
1103,
78,
2237,
8700,
7,
326,
435,
14734,
63,
2758,
63,
600,
435,
283,
8700,
7,
435,
326,
283,
1274,
14,
3083,
14,
952,
480,
55,
1025,
6632,
1,
1103,
78,
531,
8700,
7,
326,
435,
1586,
63,
460,
63,
4712,
63,
600,
435,
283,
8700,
7,
435,
326,
283,
13880,
14,
1600,
11716,
355,
2156,
355,
9009,
29,
5781,
14,
6089,
12,
3839,
29,
5781,
14,
6089,
12,
355,
4635,
29,
5781,
14,
6089,
9,
398,
327,
13144,
367,
314,
4673,
3016,
370,
506,
4903,
14,
267
] |
[
27694,
370,
511,
31366,
2656,
4882,
1640,
2412,
316,
543,
4154,
5002,
20224,
199,
3,
5004,
12591,
14,
221,
1455,
921,
13017,
14,
1548,
14,
1308,
15,
5237,
713,
13731,
199,
3,
199,
3,
961,
2295,
314,
2513,
2308,
7,
859,
14,
221,
20046,
2295,
367,
2018,
499,
14,
88,
1159,
12731,
199,
3,
849,
570,
473,
15,
47,
4514,
2187,
4453,
511,
63,
493,
18,
75,
14,
647,
14,
199,
3,
199,
3,
2779,
1990,
25697,
626,
642,
1233,
4293,
506,
9545,
1901,
511,
63,
2308,
436,
314,
2295,
199,
3,
6326,
370,
1736,
1808,
314,
2011,
1083,
465,
314,
3411,
4673,
2295,
315,
511,
63,
2308,
14,
199,
3,
473,
1990,
17329,
370,
664,
2849,
2112,
2295,
1808,
17987,
503,
542,
280,
7414,
626,
4340,
199,
3,
370,
9172,
314,
662,
19652,
8826,
14,
221,
961,
2112,
4079,
511,
5241,
295,
24658,
199,
3,
314,
8826,
6791,
370,
314,
4976,
713,
13731,
3371,
16492,
6665,
641,
10130,
436,
32144,
14,
199,
3,
221,
446,
486,
1135,
1089,
14,
80,
14,
3300,
448,
199,
199,
646,
747,
199,
646,
3504,
199,
646,
4673,
199,
646,
3873,
199,
646,
984,
199,
504,
511,
14,
396,
63,
4058,
492,
1255,
63,
2796,
199,
646,
900,
199,
646,
2882,
199,
199,
3,
1379,
492,
1006,
402,
314,
7645,
781,
3984,
3595,
370,
862,
5343,
1536,
13738,
14,
199,
504,
485,
2308,
492,
3814,
2090,
421,
199,
32,
2796,
14,
11278,
8,
736,
14,
354,
508,
283,
9228,
297,
283,
2219,
5074,
282,
10694,
2656,
2659,
199,
533,
1379,
26126,
11274,
10647,
8,
2796,
14,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
291,
423,
1412,
275,
488,
339,
347,
6766,
8,
277,
304,
267,
340,
291,
423,
1412,
436,
291,
423,
1412,
14,
6843,
342,
365,
488,
26,
288,
862,
26,
355,
291,
423,
1412,
14,
8997,
342,
288,
871,
6440,
26,
355,
986,
339,
347,
485,
4208,
63,
13880,
63,
2758,
63,
600,
8,
277,
304,
267,
408,
3407,
314,
14734,
275,
2263,
1004,
402,
1233,
367,
314,
7002,
2112,
14,
398,
1007,
429,
305,
261,
874,
1077,
4278,
642,
370,
511,
3365,
5004,
2251,
14,
267,
408,
267,
372,
661,
646,
485,
2308,
8700,
7,
355,
283,
13880,
275,
485,
2308,
14,
26126,
8,
1274,
14,
6626,
14,
9843,
1062,
298,
4848,
531,
358,
339,
347,
2449,
63,
1045,
63,
1412,
63,
815,
8,
277,
12,
10842,
12,
3839,
29,
66,
6448,
4635,
29,
66,
6448,
3044,
26808,
29,
549,
304,
267,
408,
33,
2863,
4340,
370,
9058,
436,
2449,
543,
2997,
3105,
1072,
14,
398,
1804,
15350,
314,
2112,
340,
652,
365,
5139,
3879,
12,
8775,
83,
7971,
1072,
267,
436,
6918,
314,
511,
543,
376,
1125,
1245,
5893,
314,
1072,
14,
398,
3033,
26,
288,
10842,
26,
4516,
370,
2621,
2410,
298,
547,
687,
5004,
2112,
2,
315,
314,
1245,
14,
288,
3839,
12,
4635,
26,
4465,
1072,
436,
1125,
687,
314,
2112,
880,
355,
12474,
370,
2387,
315,
314,
1125,
1245,
14,
288,
26808,
26,
2155,
12,
1380,
715,
781,
1240,
26808,
342,
641,
314,
2112,
355,
2410,
1022,
12687,
652,
370,
13082,
4722,
1072,
14,
267,
408,
267,
340,
291,
423,
1412,
14,
6843,
342,
365,
488,
26,
288,
900,
14,
4532,
8,
16,
14,
17,
9,
221,
327,
8120,
652,
900,
370,
9578,
16116,
314,
1125,
14,
288,
862,
26,
355,
291,
423,
1412,
14,
14478,
342,
221,
327,
7523,
652,
487,
397,
14,
288,
871,
6440,
26,
355,
986,
267,
340,
26808,
26,
288,
3839,
63,
500,
12,
4635,
63,
500,
275,
291,
423,
1412,
14,
10664,
342,
288,
3839,
847,
3839,
63,
500,
288,
4635,
847,
4635,
63,
500,
267,
291,
14,
1633,
360,
547,
687,
5004,
2112,
450,
83,
3427,
78,
13850,
3427,
78,
5,
83,
18472,
2666,
3427,
78,
5,
83,
60,
78,
7,
450,
2116,
334,
26460,
12,
3839,
14,
2708,
1062,
4635,
14,
2708,
4059,
339,
347,
485,
396,
63,
19332,
8,
277,
12,
666,
63,
475,
63,
952,
12,
1586,
63,
460,
63,
4712,
63,
600,
304,
267,
408,
9417,
20224,
1586,
1083,
511,
20458,
370,
4107,
662,
19652,
5953,
14,
398,
6121,
29280,
626,
2018,
4673,
8297,
787,
1255,
5309,
314,
1586,
14,
398,
3033,
26,
288,
666,
63,
475,
63,
952,
26,
2624,
370,
2218,
370,
314,
1982,
2112,
367,
7664,
355,
2544,
10209,
652,
282,
4673,
12,
12679,
316,
314,
4673,
1990,
8860,
12,
355,
3575,
282,
4242,
8057,
436,
11261,
314,
14734,
5200,
14,
288,
1586,
63,
460,
63,
4712,
63,
600,
26,
13050,
298,
604,
2,
402,
1233,
370,
1586,
687,
282,
570,
355,
909,
4310,
283,
13880,
7,
436,
4107,
314,
754,
14,
221,
961,
911,
506,
355,
7934,
465,
1777,
402,
282,
2366,
3873,
23036,
666,
63,
475,
63,
952,
14,
267,
408,
267,
14734,
63,
2758,
63,
600,
275,
291,
423,
4208,
63,
13880,
63,
2758,
63,
600,
342,
267,
327,
19271,
5200,
5004,
315,
642,
805,
365,
12700,
2419,
314,
7481,
10694,
4403,
267,
327,
5200,
3335,
1568,
402,
10574,
2783,
14,
221,
3091,
7060,
1077,
1853,
14,
267,
702,
822,
8,
576,
63,
475,
63,
952,
9,
665,
10574,
12,
283,
576,
63,
475,
63,
952,
1471,
5542,
315,
5200,
4123,
3530,
398,
327,
7707,
282,
3873,
370,
1240,
4154,
1586,
1083,
1830,
7252,
282,
4673,
14,
267,
291,
423,
1412,
275,
3873,
14,
7942,
8,
355,
359,
1274,
14,
5904,
12,
2475,
85,
297,
2475,
67,
297,
326,
283,
646,
5890,
12,
4673,
12,
984,
8700,
7,
326,
283,
4653,
14,
4653,
8,
4653,
14,
21223,
12,
283,
3044,
283,
2734,
308,
12,
289,
26,
984,
14,
3083,
14,
952,
21506,
1103,
78,
2237,
8700,
7,
326,
435,
14734,
63,
2758,
63,
600,
435,
283,
8700,
7,
435,
326,
283,
1274,
14,
3083,
14,
952,
480,
55,
1025,
6632,
1,
1103,
78,
531,
8700,
7,
326,
435,
1586,
63,
460,
63,
4712,
63,
600,
435,
283,
8700,
7,
435,
326,
283,
13880,
14,
1600,
11716,
355,
2156,
355,
9009,
29,
5781,
14,
6089,
12,
3839,
29,
5781,
14,
6089,
12,
355,
4635,
29,
5781,
14,
6089,
9,
398,
327,
13144,
367,
314,
4673,
3016,
370,
506,
4903,
14,
267,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
jlegendary/youtube-dl
|
youtube_dl/extractor/imgur.py
|
54
|
3627
|
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..compat import compat_urlparse
from ..utils import (
int_or_none,
js_to_json,
mimetype2ext,
ExtractorError,
)
class ImgurIE(InfoExtractor):
_VALID_URL = r'https?://(?:i\.)?imgur\.com/(?P<id>[a-zA-Z0-9]+)'
_TESTS = [{
'url': 'https://i.imgur.com/A61SaA1.gifv',
'info_dict': {
'id': 'A61SaA1',
'ext': 'mp4',
'title': 're:Imgur GIF$|MRW gifv is up and running without any bugs$',
'description': 're:The origin of the Internet\'s most viral images$|The Internet\'s visual storytelling community\. Explore, share, and discuss the best visual stories the Internet has to offer\.$',
},
}, {
'url': 'https://imgur.com/A61SaA1',
'info_dict': {
'id': 'A61SaA1',
'ext': 'mp4',
'title': 're:Imgur GIF$|MRW gifv is up and running without any bugs$',
'description': 're:The origin of the Internet\'s most viral images$|The Internet\'s visual storytelling community\. Explore, share, and discuss the best visual stories the Internet has to offer\.$',
},
}]
def _real_extract(self, url):
video_id = self._match_id(url)
webpage = self._download_webpage(
compat_urlparse.urljoin(url, video_id), video_id)
width = int_or_none(self._search_regex(
r'<param name="width" value="([0-9]+)"',
webpage, 'width', fatal=False))
height = int_or_none(self._search_regex(
r'<param name="height" value="([0-9]+)"',
webpage, 'height', fatal=False))
video_elements = self._search_regex(
r'(?s)<div class="video-elements">(.*?)</div>',
webpage, 'video elements', default=None)
if not video_elements:
raise ExtractorError(
'No sources found for video %s. Maybe an image?' % video_id,
expected=True)
formats = []
for m in re.finditer(r'<source\s+src="(?P<src>[^"]+)"\s+type="(?P<type>[^"]+)"', video_elements):
formats.append({
'format_id': m.group('type').partition('/')[2],
'url': self._proto_relative_url(m.group('src')),
'ext': mimetype2ext(m.group('type')),
'acodec': 'none',
'width': width,
'height': height,
'http_headers': {
'User-Agent': 'youtube-dl (like wget)',
},
})
gif_json = self._search_regex(
r'(?s)var\s+videoItem\s*=\s*(\{.*?\})',
webpage, 'GIF code', fatal=False)
if gif_json:
gifd = self._parse_json(
gif_json, video_id, transform_source=js_to_json)
formats.append({
'format_id': 'gif',
'preference': -10,
'width': width,
'height': height,
'ext': 'gif',
'acodec': 'none',
'vcodec': 'gif',
'container': 'gif',
'url': self._proto_relative_url(gifd['gifUrl']),
'filesize': gifd.get('size'),
'http_headers': {
'User-Agent': 'youtube-dl (like wget)',
},
})
self._sort_formats(formats)
return {
'id': video_id,
'formats': formats,
'description': self._og_search_description(webpage),
'title': self._og_search_title(webpage),
}
|
unlicense
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
8434,
63,
10290,
199,
504,
2508,
1208,
492,
334,
272,
1109,
63,
269,
63,
3592,
12,
272,
8586,
63,
475,
63,
1001,
12,
272,
12200,
18,
832,
12,
272,
19783,
12,
199,
9,
421,
199,
533,
473,
6649,
300,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
73,
20316,
4060,
300,
4537,
957,
9448,
48,
28,
344,
9514,
65,
13,
6353,
13,
58,
16,
13,
25,
29716,
339,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
2859,
921,
73,
14,
4060,
300,
14,
957,
15,
33,
2976,
12226,
33,
17,
14,
14513,
86,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
33,
2976,
12226,
33,
17,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
264,
26,
27261,
300,
598,
4656,
31686,
22153,
55,
486,
692,
86,
365,
1536,
436,
3879,
1928,
1263,
18227,
4268,
288,
283,
1802,
356,
283,
264,
26,
1918,
6330,
402,
314,
22026,
3985,
83,
4750,
18291,
279,
5935,
31686,
1918,
22026,
3985,
83,
13104,
19222,
9974,
316,
23633,
4537,
7910,
28037,
12,
8663,
12,
436,
4339,
27678,
314,
5526,
13104,
410,
6112,
314,
22026,
965,
370,
19793,
4537,
4268,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
2859,
921,
4060,
300,
14,
957,
15,
33,
2976,
12226,
33,
17,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
33,
2976,
12226,
33,
17,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
264,
26,
27261,
300,
598,
4656,
31686,
22153,
55,
486,
692,
86,
365,
1536,
436,
3879,
1928,
1263,
18227,
4268,
288,
283,
1802,
356,
283,
264,
26,
1918,
6330,
402,
314,
22026,
3985,
83,
4750,
18291,
279,
5935,
31686,
1918,
22026,
3985,
83,
13104,
19222,
9974,
316,
23633,
4537,
7910,
28037,
12,
8663,
12,
436,
4339,
27678,
314,
5526,
13104,
410,
6112,
314,
22026,
965,
370,
19793,
4537,
4268,
267,
1660,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
288,
8434,
63,
10290,
14,
17755,
8,
633,
12,
3991,
63,
344,
395,
3991,
63,
344,
9,
398,
3462,
275,
1109,
63,
269,
63,
3592,
8,
277,
423,
1733,
63,
3821,
8,
288,
519,
7601,
635,
536,
628,
2063,
2,
574,
628,
779,
16,
13,
25,
2807,
32691,
288,
9248,
12,
283,
2063,
297,
14294,
29,
797,
430,
267,
4569,
275,
1109,
63,
269,
63,
3592,
8,
277,
423,
1733,
63,
3821,
8,
288,
519,
7601,
635,
536,
628,
3333,
2,
574,
628,
779,
16,
13,
25,
2807,
32691,
288,
9248,
12,
283,
3333,
297,
14294,
29,
797,
430,
398,
3991,
63,
5527,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
10120,
83,
21528,
3015,
1021,
628,
3722,
13,
5527,
1743,
17140,
15939,
3015,
4206,
288,
9248,
12,
283,
3722,
4008,
297,
849,
29,
403,
9,
267,
340,
440,
3991,
63,
5527,
26,
288,
746,
19783,
8,
355,
283,
1944,
5274,
1911,
367,
3991,
450,
83,
14,
23038,
376,
1834,
14069,
450,
3991,
63,
344,
12,
355,
1420,
29,
549,
9,
398,
6752,
275,
942,
267,
367,
333,
315,
295,
14,
19373,
8,
82,
7601,
1365,
60,
83,
11,
2164,
628,
2229,
48,
28,
2164,
13489,
937,
20415,
60,
83,
11,
466,
628,
2229,
48,
28,
466,
13489,
937,
20415,
297,
3991,
63,
5527,
304,
288,
6752,
14,
740,
2561,
355,
283,
908,
63,
344,
356,
333,
14,
923,
360,
466,
1959,
5312,
30746,
18,
467,
355,
283,
633,
356,
291,
423,
2625,
63,
6188,
63,
633,
8,
77,
14,
923,
360,
2164,
3855,
355,
283,
832,
356,
12200,
18,
832,
8,
77,
14,
923,
360,
466,
3855,
355,
283,
65,
9276,
356,
283,
3592,
297,
355,
283,
2063,
356,
3462,
12,
355,
283,
3333,
356,
4569,
12,
355,
283,
1014,
63,
2139,
356,
469,
490,
283,
1899,
13,
7788,
356,
283,
9788,
13,
5030,
334,
2930,
336,
362,
3196,
355,
1660,
288,
3828,
398,
486,
692,
63,
1001,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
10120,
83,
9,
1391,
60,
83,
11,
3722,
2081,
60,
83,
23440,
83,
22588,
91,
21040,
25583,
288,
9248,
12,
283,
39,
4656,
1233,
297,
14294,
29,
797,
9,
267,
340,
486,
692,
63,
1001,
26,
288,
486,
692,
68,
275,
291,
423,
1122,
63,
1001,
8,
355,
486,
692,
63,
1001,
12,
3991,
63,
344,
12,
5793,
63,
1365,
29,
3596,
63,
475,
63,
1001,
9,
288,
6752,
14,
740,
2561,
355,
283,
908,
63,
344,
356,
283,
14513,
297,
355,
283,
14994,
356,
446,
709,
12,
355,
283,
2063,
356,
3462,
12,
355,
283,
3333,
356,
4569,
12,
355,
283,
832,
356,
283,
14513,
297,
355,
283,
65,
9276,
356,
283,
3592,
297,
355,
283,
86,
9276,
356,
283,
14513,
297,
355,
283,
3600,
356,
283,
14513,
297,
355,
283,
633,
356,
291,
423,
2625,
63,
6188,
63,
633,
8,
14513,
68,
459,
14513,
6417,
3815,
355,
283,
19233,
356,
486,
692,
68,
14,
362,
360,
890,
659,
355,
283,
1014,
63,
2139,
356,
469,
490,
283,
1899,
13,
7788,
356,
283,
9788,
13,
5030,
334,
2930,
336,
362,
3196,
355,
1660,
288,
3828,
398,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
6321,
356,
6752,
12,
288,
283,
1802,
356,
291,
423,
974,
63,
1733,
63,
1802,
8,
12022,
395,
288,
283,
1213,
356,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
395,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
295,
199,
199,
504,
1275,
2330,
492,
21298,
199,
504,
2508,
5819,
492,
8434,
63,
10290,
199,
504,
2508,
1208,
492,
334,
272,
1109,
63,
269,
63,
3592,
12,
272,
8586,
63,
475,
63,
1001,
12,
272,
12200,
18,
832,
12,
272,
19783,
12,
199,
9,
421,
199,
533,
473,
6649,
300,
4332,
8,
18283,
304,
272,
485,
5600,
63,
2632,
275,
519,
7,
2859,
24524,
73,
20316,
4060,
300,
4537,
957,
9448,
48,
28,
344,
9514,
65,
13,
6353,
13,
58,
16,
13,
25,
29716,
339,
485,
7569,
275,
8910,
267,
283,
633,
356,
283,
2859,
921,
73,
14,
4060,
300,
14,
957,
15,
33,
2976,
12226,
33,
17,
14,
14513,
86,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
33,
2976,
12226,
33,
17,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
264,
26,
27261,
300,
598,
4656,
31686,
22153,
55,
486,
692,
86,
365,
1536,
436,
3879,
1928,
1263,
18227,
4268,
288,
283,
1802,
356,
283,
264,
26,
1918,
6330,
402,
314,
22026,
3985,
83,
4750,
18291,
279,
5935,
31686,
1918,
22026,
3985,
83,
13104,
19222,
9974,
316,
23633,
4537,
7910,
28037,
12,
8663,
12,
436,
4339,
27678,
314,
5526,
13104,
410,
6112,
314,
22026,
965,
370,
19793,
4537,
4268,
267,
1660,
272,
1660,
469,
267,
283,
633,
356,
283,
2859,
921,
4060,
300,
14,
957,
15,
33,
2976,
12226,
33,
17,
297,
267,
283,
815,
63,
807,
356,
469,
288,
283,
344,
356,
283,
33,
2976,
12226,
33,
17,
297,
288,
283,
832,
356,
283,
311,
20,
297,
288,
283,
1213,
356,
283,
264,
26,
27261,
300,
598,
4656,
31686,
22153,
55,
486,
692,
86,
365,
1536,
436,
3879,
1928,
1263,
18227,
4268,
288,
283,
1802,
356,
283,
264,
26,
1918,
6330,
402,
314,
22026,
3985,
83,
4750,
18291,
279,
5935,
31686,
1918,
22026,
3985,
83,
13104,
19222,
9974,
316,
23633,
4537,
7910,
28037,
12,
8663,
12,
436,
4339,
27678,
314,
5526,
13104,
410,
6112,
314,
22026,
965,
370,
19793,
4537,
4268,
267,
1660,
272,
14877,
339,
347,
485,
3093,
63,
5005,
8,
277,
12,
1166,
304,
267,
3991,
63,
344,
275,
291,
423,
1431,
63,
344,
8,
633,
9,
267,
9248,
275,
291,
423,
4249,
63,
12022,
8,
288,
8434,
63,
10290,
14,
17755,
8,
633,
12,
3991,
63,
344,
395,
3991,
63,
344,
9,
398,
3462,
275,
1109,
63,
269,
63,
3592,
8,
277,
423,
1733,
63,
3821,
8,
288,
519,
7601,
635,
536,
628,
2063,
2,
574,
628,
779,
16,
13,
25,
2807,
32691,
288,
9248,
12,
283,
2063,
297,
14294,
29,
797,
430,
267,
4569,
275,
1109,
63,
269,
63,
3592,
8,
277,
423,
1733,
63,
3821,
8,
288,
519,
7601,
635,
536,
628,
3333,
2,
574,
628,
779,
16,
13,
25,
2807,
32691,
288,
9248,
12,
283,
3333,
297,
14294,
29,
797,
430,
398,
3991,
63,
5527,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
10120,
83,
21528,
3015,
1021,
628,
3722,
13,
5527,
1743,
17140,
15939,
3015,
4206,
288,
9248,
12,
283,
3722,
4008,
297,
849,
29,
403,
9,
267,
340,
440,
3991,
63,
5527,
26,
288,
746,
19783,
8,
355,
283,
1944,
5274,
1911,
367,
3991,
450,
83,
14,
23038,
376,
1834,
14069,
450,
3991,
63,
344,
12,
355,
1420,
29,
549,
9,
398,
6752,
275,
942,
267,
367,
333,
315,
295,
14,
19373,
8,
82,
7601,
1365,
60,
83,
11,
2164,
628,
2229,
48,
28,
2164,
13489,
937,
20415,
60,
83,
11,
466,
628,
2229,
48,
28,
466,
13489,
937,
20415,
297,
3991,
63,
5527,
304,
288,
6752,
14,
740,
2561,
355,
283,
908,
63,
344,
356,
333,
14,
923,
360,
466,
1959,
5312,
30746,
18,
467,
355,
283,
633,
356,
291,
423,
2625,
63,
6188,
63,
633,
8,
77,
14,
923,
360,
2164,
3855,
355,
283,
832,
356,
12200,
18,
832,
8,
77,
14,
923,
360,
466,
3855,
355,
283,
65,
9276,
356,
283,
3592,
297,
355,
283,
2063,
356,
3462,
12,
355,
283,
3333,
356,
4569,
12,
355,
283,
1014,
63,
2139,
356,
469,
490,
283,
1899,
13,
7788,
356,
283,
9788,
13,
5030,
334,
2930,
336,
362,
3196,
355,
1660,
288,
3828,
398,
486,
692,
63,
1001,
275,
291,
423,
1733,
63,
3821,
8,
288,
519,
10120,
83,
9,
1391,
60,
83,
11,
3722,
2081,
60,
83,
23440,
83,
22588,
91,
21040,
25583,
288,
9248,
12,
283,
39,
4656,
1233,
297,
14294,
29,
797,
9,
267,
340,
486,
692,
63,
1001,
26,
288,
486,
692,
68,
275,
291,
423,
1122,
63,
1001,
8,
355,
486,
692,
63,
1001,
12,
3991,
63,
344,
12,
5793,
63,
1365,
29,
3596,
63,
475,
63,
1001,
9,
288,
6752,
14,
740,
2561,
355,
283,
908,
63,
344,
356,
283,
14513,
297,
355,
283,
14994,
356,
446,
709,
12,
355,
283,
2063,
356,
3462,
12,
355,
283,
3333,
356,
4569,
12,
355,
283,
832,
356,
283,
14513,
297,
355,
283,
65,
9276,
356,
283,
3592,
297,
355,
283,
86,
9276,
356,
283,
14513,
297,
355,
283,
3600,
356,
283,
14513,
297,
355,
283,
633,
356,
291,
423,
2625,
63,
6188,
63,
633,
8,
14513,
68,
459,
14513,
6417,
3815,
355,
283,
19233,
356,
486,
692,
68,
14,
362,
360,
890,
659,
355,
283,
1014,
63,
2139,
356,
469,
490,
283,
1899,
13,
7788,
356,
283,
9788,
13,
5030,
334,
2930,
336,
362,
3196,
355,
1660,
288,
3828,
398,
291,
423,
3191,
63,
6321,
8,
6321,
9,
398,
372,
469,
288,
283,
344,
356,
3991,
63,
344,
12,
288,
283,
6321,
356,
6752,
12,
288,
283,
1802,
356,
291,
423,
974,
63,
1733,
63,
1802,
8,
12022,
395,
288,
283,
1213,
356,
291,
423,
974,
63,
1733,
63,
1213,
8,
12022,
395,
267,
789,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
2013Commons/hue
|
desktop/core/ext-py/Django-1.4.5/tests/regressiontests/signing/tests.py
|
34
|
4197
|
import time
from django.core import signing
from django.test import TestCase
from django.utils.encoding import force_unicode
class TestSigner(TestCase):
def test_signature(self):
"signature() method should generate a signature"
signer = signing.Signer('predictable-secret')
signer2 = signing.Signer('predictable-secret2')
for s in (
'hello',
'3098247:529:087:',
u'\u2019'.encode('utf-8'),
):
self.assertEqual(
signer.signature(s),
signing.base64_hmac(signer.salt + 'signer', s,
'predictable-secret')
)
self.assertNotEqual(signer.signature(s), signer2.signature(s))
def test_signature_with_salt(self):
"signature(value, salt=...) should work"
signer = signing.Signer('predictable-secret', salt='extra-salt')
self.assertEqual(
signer.signature('hello'),
signing.base64_hmac('extra-salt' + 'signer',
'hello', 'predictable-secret'))
self.assertNotEqual(
signing.Signer('predictable-secret', salt='one').signature('hello'),
signing.Signer('predictable-secret', salt='two').signature('hello'))
def test_sign_unsign(self):
"sign/unsign should be reversible"
signer = signing.Signer('predictable-secret')
examples = (
'q;wjmbk;wkmb',
'3098247529087',
'3098247:529:087:',
'jkw osanteuh ,rcuh nthu aou oauh ,ud du',
u'\u2019',
)
for example in examples:
self.assertNotEqual(
force_unicode(example), force_unicode(signer.sign(example)))
self.assertEqual(example, signer.unsign(signer.sign(example)))
def unsign_detects_tampering(self):
"unsign should raise an exception if the value has been tampered with"
signer = signing.Signer('predictable-secret')
value = 'Another string'
signed_value = signer.sign(value)
transforms = (
lambda s: s.upper(),
lambda s: s + 'a',
lambda s: 'a' + s[1:],
lambda s: s.replace(':', ''),
)
self.assertEqual(value, signer.unsign(signed_value))
for transform in transforms:
self.assertRaises(
signing.BadSignature, signer.unsign, transform(signed_value))
def test_dumps_loads(self):
"dumps and loads be reversible for any JSON serializable object"
objects = (
['a', 'list'],
'a string',
u'a unicode string \u2019',
{'a': 'dictionary'},
)
for o in objects:
self.assertNotEqual(o, signing.dumps(o))
self.assertEqual(o, signing.loads(signing.dumps(o)))
def test_decode_detects_tampering(self):
"loads should raise exception for tampered objects"
transforms = (
lambda s: s.upper(),
lambda s: s + 'a',
lambda s: 'a' + s[1:],
lambda s: s.replace(':', ''),
)
value = {
'foo': 'bar',
'baz': 1,
}
encoded = signing.dumps(value)
self.assertEqual(value, signing.loads(encoded))
for transform in transforms:
self.assertRaises(
signing.BadSignature, signing.loads, transform(encoded))
class TestTimestampSigner(TestCase):
def test_timestamp_signer(self):
value = u'hello'
_time = time.time
time.time = lambda: 123456789
try:
signer = signing.TimestampSigner('predictable-key')
ts = signer.sign(value)
self.assertNotEqual(ts,
signing.Signer('predictable-key').sign(value))
self.assertEqual(signer.unsign(ts), value)
time.time = lambda: 123456800
self.assertEqual(signer.unsign(ts, max_age=12), value)
self.assertEqual(signer.unsign(ts, max_age=11), value)
self.assertRaises(
signing.SignatureExpired, signer.unsign, ts, max_age=10)
finally:
time.time = _time
|
apache-2.0
|
[
646,
900,
199,
199,
504,
1639,
14,
1018,
492,
18057,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
2975,
421,
199,
533,
1379,
4940,
281,
8,
1746,
304,
339,
347,
511,
63,
5233,
8,
277,
304,
267,
298,
5233,
342,
1083,
1077,
3550,
282,
4955,
2,
267,
24902,
275,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
358,
267,
24902,
18,
275,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
18,
358,
267,
367,
308,
315,
334,
288,
283,
5006,
297,
288,
283,
1216,
2905,
11717,
26,
28762,
26,
27563,
6536,
288,
399,
1154,
85,
14982,
1370,
2143,
360,
1624,
13,
24,
659,
267,
3461,
288,
291,
14,
629,
8,
355,
24902,
14,
5233,
8,
83,
395,
355,
18057,
14,
1095,
772,
63,
18537,
8,
25399,
14,
12597,
435,
283,
25399,
297,
308,
12,
490,
283,
6892,
461,
13,
4731,
358,
288,
776,
288,
291,
14,
7418,
8,
25399,
14,
5233,
8,
83,
395,
24902,
18,
14,
5233,
8,
83,
430,
339,
347,
511,
63,
5233,
63,
1045,
63,
12597,
8,
277,
304,
267,
298,
5233,
8,
585,
12,
10105,
29,
11965,
1077,
1736,
2,
267,
24902,
275,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
297,
10105,
534,
2911,
13,
12597,
358,
267,
291,
14,
629,
8,
288,
24902,
14,
5233,
360,
5006,
659,
355,
18057,
14,
1095,
772,
63,
18537,
360,
2911,
13,
12597,
7,
435,
283,
25399,
297,
355,
283,
5006,
297,
283,
6892,
461,
13,
4731,
1333,
267,
291,
14,
7418,
8,
288,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
297,
10105,
534,
368,
1959,
5233,
360,
5006,
659,
288,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
297,
10105,
534,
5601,
1959,
5233,
360,
5006,
1333,
339,
347,
511,
63,
1037,
63,
324,
1037,
8,
277,
304,
267,
298,
1037,
15,
324,
1037,
1077,
506,
29465,
1164,
2,
267,
24902,
275,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
358,
267,
7251,
275,
334,
288,
283,
81,
27,
87,
74,
887,
75,
27,
14947,
887,
297,
288,
283,
1216,
2905,
1194,
2194,
15117,
1555,
297,
288,
283,
1216,
2905,
11717,
26,
28762,
26,
27563,
6536,
288,
283,
74,
829,
747,
8949,
22451,
2360,
1195,
22451,
30564,
85,
282,
810,
312,
3844,
72,
2360,
1181,
15776,
297,
288,
399,
1154,
85,
14982,
297,
267,
776,
267,
367,
2893,
315,
7251,
26,
288,
291,
14,
7418,
8,
355,
3542,
63,
2975,
8,
2694,
395,
3542,
63,
2975,
8,
25399,
14,
1037,
8,
2694,
1724,
288,
291,
14,
629,
8,
2694,
12,
24902,
14,
324,
1037,
8,
25399,
14,
1037,
8,
2694,
1724,
339,
347,
625,
1037,
63,
271,
28853,
63,
502,
311,
15663,
8,
277,
304,
267,
298,
324,
1037,
1077,
746,
376,
1919,
340,
314,
574,
965,
2757,
3052,
311,
16179,
543,
2,
267,
24902,
275,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
358,
267,
574,
275,
283,
23296,
1059,
7,
267,
10514,
63,
585,
275,
24902,
14,
1037,
8,
585,
9,
267,
18501,
275,
334,
288,
2400,
308,
26,
308,
14,
4142,
1062,
288,
2400,
308,
26,
308,
435,
283,
65,
297,
288,
2400,
308,
26,
283,
65,
7,
435,
308,
59,
17,
8429,
288,
2400,
308,
26,
308,
14,
1814,
16451,
9929,
267,
776,
267,
291,
14,
629,
8,
585,
12,
24902,
14,
324,
1037,
8,
1737,
63,
585,
430,
267,
367,
5793,
315,
18501,
26,
288,
291,
14,
1855,
8,
355,
18057,
14,
5725,
10014,
12,
24902,
14,
324,
1037,
12,
5793,
8,
1737,
63,
585,
430,
339,
347,
511,
63,
4180,
63,
3640,
8,
277,
304,
267,
298,
4180,
436,
14404,
506,
29465,
1164,
367,
1263,
4840,
31244,
909,
2,
267,
2251,
275,
334,
288,
788,
65,
297,
283,
513,
995,
288,
283,
65,
1059,
297,
288,
399,
7,
65,
2649,
1059,
971,
85,
14982,
297,
288,
791,
65,
356,
283,
9086,
2267,
267,
776,
267,
367,
312,
315,
2251,
26,
288,
291,
14,
7418,
8,
79,
12,
18057,
14,
4180,
8,
79,
430,
288,
291,
14,
629,
8,
79,
12,
18057,
14,
3640,
8,
23238,
14,
4180,
8,
79,
1724,
339,
347,
511,
63,
2708,
63,
271,
28853,
63,
502,
311,
15663,
8,
277,
304,
267,
298,
3640,
1077,
746,
1919,
367,
3052,
311,
16179,
2251,
2,
267,
18501,
275,
334,
288,
2400,
308,
26,
308,
14,
4142,
1062,
288,
2400,
308,
26,
308,
435,
283,
65,
297,
288,
2400,
308,
26,
283,
65,
7,
435,
308,
59,
17,
8429,
288,
2400,
308,
26,
308,
14,
1814,
16451,
9929,
267,
776,
267,
574,
275,
469,
288,
283,
1421,
356,
283,
1700,
297,
288,
283,
6185,
356,
413,
12,
267,
789,
267,
5737,
275,
18057,
14,
4180,
8,
585,
9,
267,
291,
14,
629,
8,
585,
12,
18057,
14,
3640,
8,
8167,
430,
267,
367,
5793,
315,
18501,
26,
288,
291,
14,
1855,
8,
355,
18057,
14,
5725,
10014,
12,
18057,
14,
3640,
12,
5793,
8,
8167,
430,
199,
199,
533,
1379,
10239,
4940,
281,
8,
1746,
304,
339,
347,
511,
63,
3954,
63,
25399,
8,
277,
304,
267,
574,
275,
399,
7,
5006,
7,
267,
485,
521,
275,
900,
14,
521,
267,
900,
14,
521,
275,
2400,
26,
32695,
267,
862,
26,
288,
24902,
275,
18057,
14,
10239,
4940,
281,
360,
6892,
461,
13,
498,
358,
288,
6714,
275,
24902,
14,
1037,
8,
585,
9,
288,
291,
14,
7418,
8,
1086,
12,
355,
18057,
14,
4940,
281,
360,
6892,
461,
13,
498,
1959,
1037,
8,
585,
430,
953,
291,
14,
629,
8,
25399,
14,
324,
1037,
8,
1086,
395,
574,
9,
288,
900,
14,
521,
275,
2400,
26,
14763,
1367,
6718,
288,
291,
14,
629,
8,
25399,
14,
324,
1037,
8,
1086,
12,
1390,
63,
474,
29,
713,
395,
574,
9,
288,
291,
14,
629,
8,
25399,
14,
324,
1037,
8,
1086,
12,
1390,
63,
474,
29,
845,
395,
574,
9,
288,
291,
14,
1855,
8,
355,
18057,
14,
10014,
20898,
12,
24902,
14,
324,
1037,
12,
6714,
12,
1390,
63,
474,
29,
709,
9,
267,
3753,
26,
288,
900,
14,
521,
275,
485,
521,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
900,
199,
199,
504,
1639,
14,
1018,
492,
18057,
199,
504,
1639,
14,
396,
492,
7640,
199,
504,
1639,
14,
1208,
14,
2991,
492,
3542,
63,
2975,
421,
199,
533,
1379,
4940,
281,
8,
1746,
304,
339,
347,
511,
63,
5233,
8,
277,
304,
267,
298,
5233,
342,
1083,
1077,
3550,
282,
4955,
2,
267,
24902,
275,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
358,
267,
24902,
18,
275,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
18,
358,
267,
367,
308,
315,
334,
288,
283,
5006,
297,
288,
283,
1216,
2905,
11717,
26,
28762,
26,
27563,
6536,
288,
399,
1154,
85,
14982,
1370,
2143,
360,
1624,
13,
24,
659,
267,
3461,
288,
291,
14,
629,
8,
355,
24902,
14,
5233,
8,
83,
395,
355,
18057,
14,
1095,
772,
63,
18537,
8,
25399,
14,
12597,
435,
283,
25399,
297,
308,
12,
490,
283,
6892,
461,
13,
4731,
358,
288,
776,
288,
291,
14,
7418,
8,
25399,
14,
5233,
8,
83,
395,
24902,
18,
14,
5233,
8,
83,
430,
339,
347,
511,
63,
5233,
63,
1045,
63,
12597,
8,
277,
304,
267,
298,
5233,
8,
585,
12,
10105,
29,
11965,
1077,
1736,
2,
267,
24902,
275,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
297,
10105,
534,
2911,
13,
12597,
358,
267,
291,
14,
629,
8,
288,
24902,
14,
5233,
360,
5006,
659,
355,
18057,
14,
1095,
772,
63,
18537,
360,
2911,
13,
12597,
7,
435,
283,
25399,
297,
355,
283,
5006,
297,
283,
6892,
461,
13,
4731,
1333,
267,
291,
14,
7418,
8,
288,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
297,
10105,
534,
368,
1959,
5233,
360,
5006,
659,
288,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
297,
10105,
534,
5601,
1959,
5233,
360,
5006,
1333,
339,
347,
511,
63,
1037,
63,
324,
1037,
8,
277,
304,
267,
298,
1037,
15,
324,
1037,
1077,
506,
29465,
1164,
2,
267,
24902,
275,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
358,
267,
7251,
275,
334,
288,
283,
81,
27,
87,
74,
887,
75,
27,
14947,
887,
297,
288,
283,
1216,
2905,
1194,
2194,
15117,
1555,
297,
288,
283,
1216,
2905,
11717,
26,
28762,
26,
27563,
6536,
288,
283,
74,
829,
747,
8949,
22451,
2360,
1195,
22451,
30564,
85,
282,
810,
312,
3844,
72,
2360,
1181,
15776,
297,
288,
399,
1154,
85,
14982,
297,
267,
776,
267,
367,
2893,
315,
7251,
26,
288,
291,
14,
7418,
8,
355,
3542,
63,
2975,
8,
2694,
395,
3542,
63,
2975,
8,
25399,
14,
1037,
8,
2694,
1724,
288,
291,
14,
629,
8,
2694,
12,
24902,
14,
324,
1037,
8,
25399,
14,
1037,
8,
2694,
1724,
339,
347,
625,
1037,
63,
271,
28853,
63,
502,
311,
15663,
8,
277,
304,
267,
298,
324,
1037,
1077,
746,
376,
1919,
340,
314,
574,
965,
2757,
3052,
311,
16179,
543,
2,
267,
24902,
275,
18057,
14,
4940,
281,
360,
6892,
461,
13,
4731,
358,
267,
574,
275,
283,
23296,
1059,
7,
267,
10514,
63,
585,
275,
24902,
14,
1037,
8,
585,
9,
267,
18501,
275,
334,
288,
2400,
308,
26,
308,
14,
4142,
1062,
288,
2400,
308,
26,
308,
435,
283,
65,
297,
288,
2400,
308,
26,
283,
65,
7,
435,
308,
59,
17,
8429,
288,
2400,
308,
26,
308,
14,
1814,
16451,
9929,
267,
776,
267,
291,
14,
629,
8,
585,
12,
24902,
14,
324,
1037,
8,
1737,
63,
585,
430,
267,
367,
5793,
315,
18501,
26,
288,
291,
14,
1855,
8,
355,
18057,
14,
5725,
10014,
12,
24902,
14,
324,
1037,
12,
5793,
8,
1737,
63,
585,
430,
339,
347,
511,
63,
4180,
63,
3640,
8,
277,
304,
267,
298,
4180,
436,
14404,
506,
29465,
1164,
367,
1263,
4840,
31244,
909,
2,
267,
2251,
275,
334,
288,
788,
65,
297,
283,
513,
995,
288,
283,
65,
1059,
297,
288,
399,
7,
65,
2649,
1059,
971,
85,
14982,
297,
288,
791,
65,
356,
283,
9086,
2267,
267,
776,
267,
367,
312,
315,
2251,
26,
288,
291,
14,
7418,
8,
79,
12,
18057,
14,
4180,
8,
79,
430,
288,
291,
14,
629,
8,
79,
12,
18057,
14,
3640,
8,
23238,
14,
4180,
8,
79,
1724,
339,
347,
511,
63,
2708,
63,
271,
28853,
63,
502,
311,
15663,
8,
277,
304,
267,
298,
3640,
1077,
746,
1919,
367,
3052,
311,
16179,
2251,
2,
267,
18501,
275,
334,
288,
2400,
308,
26,
308,
14,
4142,
1062,
288,
2400,
308,
26,
308,
435,
283,
65,
297,
288,
2400,
308,
26,
283,
65,
7,
435,
308,
59,
17,
8429,
288,
2400,
308,
26,
308,
14,
1814,
16451,
9929,
267,
776,
267,
574,
275,
469,
288,
283,
1421,
356,
283,
1700,
297,
288,
283,
6185,
356,
413,
12,
267,
789,
267,
5737,
275,
18057,
14,
4180,
8,
585,
9,
267,
291,
14,
629,
8,
585,
12,
18057,
14,
3640,
8,
8167,
430,
267,
367,
5793,
315,
18501,
26,
288,
291,
14,
1855,
8,
355,
18057,
14,
5725,
10014,
12,
18057,
14,
3640,
12,
5793,
8,
8167,
430,
199,
199,
533,
1379,
10239,
4940,
281,
8,
1746,
304,
339,
347,
511,
63,
3954,
63,
25399,
8,
277,
304,
267,
574,
275,
399,
7,
5006,
7,
267,
485,
521,
275,
900,
14,
521,
267,
900,
14,
521,
275,
2400,
26,
32695,
267,
862,
26,
288,
24902,
275,
18057,
14,
10239,
4940,
281,
360,
6892,
461,
13,
498,
358,
288,
6714,
275,
24902,
14,
1037,
8,
585,
9,
288,
291,
14,
7418,
8,
1086,
12,
355,
18057,
14,
4940,
281,
360,
6892,
461,
13,
498,
1959,
1037,
8,
585,
430,
953,
291,
14,
629,
8,
25399,
14,
324,
1037,
8,
1086,
395,
574,
9,
288,
900,
14,
521,
275,
2400,
26,
14763,
1367,
6718,
288,
291,
14,
629,
8,
25399,
14,
324,
1037,
8,
1086,
12,
1390,
63,
474,
29,
713,
395,
574,
9,
288,
291,
14,
629,
8,
25399,
14,
324,
1037,
8,
1086,
12,
1390,
63,
474,
29,
845,
395,
574,
9,
288,
291,
14,
1855,
8,
355,
18057,
14,
10014,
20898,
12,
24902,
14,
324,
1037,
12,
6714,
12,
1390,
63,
474,
29,
709,
9,
267,
3753,
26,
288,
900,
14,
521,
275,
485,
521,
199,
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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1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ChrisCinelli/pgessays
|
env/lib/python2.7/site-packages/BeautifulSoup.py
|
218
|
79567
|
"""Beautiful Soup
Elixir and Tonic
"The Screen-Scraper's Friend"
http://www.crummy.com/software/BeautifulSoup/
Beautiful Soup parses a (possibly invalid) XML or HTML document into a
tree representation. It provides methods and Pythonic idioms that make
it easy to navigate, search, and modify the tree.
A well-formed XML/HTML document yields a well-formed data
structure. An ill-formed XML/HTML document yields a correspondingly
ill-formed data structure. If your document is only locally
well-formed, you can use this library to find and process the
well-formed part of it.
Beautiful Soup works with Python 2.2 and up. It has no external
dependencies, but you'll have more success at converting data to UTF-8
if you also install these three packages:
* chardet, for auto-detecting character encodings
http://chardet.feedparser.org/
* cjkcodecs and iconv_codec, which add more encodings to the ones supported
by stock Python.
http://cjkpython.i18n.org/
Beautiful Soup defines classes for two main parsing strategies:
* BeautifulStoneSoup, for parsing XML, SGML, or your domain-specific
language that kind of looks like XML.
* BeautifulSoup, for parsing run-of-the-mill HTML code, be it valid
or invalid. This class has web browser-like heuristics for
obtaining a sensible parse tree in the face of common HTML errors.
Beautiful Soup also defines a class (UnicodeDammit) for autodetecting
the encoding of an HTML or XML document, and converting it to
Unicode. Much of this code is taken from Mark Pilgrim's Universal Feed Parser.
For more than you ever wanted to know about Beautiful Soup, see the
documentation:
http://www.crummy.com/software/BeautifulSoup/documentation.html
Here, have some legalese:
Copyright (c) 2004-2010, Leonard Richardson
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution.
* Neither the name of the the Beautiful Soup Consortium and All
Night Kosher Bakery 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, DAMMIT.
"""
from __future__ import generators
__author__ = "Leonard Richardson (leonardr@segfault.org)"
__version__ = "3.2.1"
__copyright__ = "Copyright (c) 2004-2012 Leonard Richardson"
__license__ = "New-style BSD"
from sgmllib import SGMLParser, SGMLParseError
import codecs
import markupbase
import types
import re
import sgmllib
try:
from htmlentitydefs import name2codepoint
except ImportError:
name2codepoint = {}
try:
set
except NameError:
from sets import Set as set
#These hacks make Beautiful Soup able to parse XML with namespaces
sgmllib.tagfind = re.compile('[a-zA-Z][-_.:a-zA-Z0-9]*')
markupbase._declname_match = re.compile(r'[a-zA-Z][-_.:a-zA-Z0-9]*\s*').match
DEFAULT_OUTPUT_ENCODING = "utf-8"
def _match_css_class(str):
"""Build a RE to match the given CSS class."""
return re.compile(r"(^|.*\s)%s($|\s)" % str)
# First, the classes that represent markup elements.
class PageElement(object):
"""Contains the navigational information for some part of the page
(either a tag or a piece of text)"""
def _invert(h):
"Cheap function to invert a hash."
i = {}
for k,v in h.items():
i[v] = k
return i
XML_ENTITIES_TO_SPECIAL_CHARS = { "apos" : "'",
"quot" : '"',
"amp" : "&",
"lt" : "<",
"gt" : ">" }
XML_SPECIAL_CHARS_TO_ENTITIES = _invert(XML_ENTITIES_TO_SPECIAL_CHARS)
def setup(self, parent=None, previous=None):
"""Sets up the initial relations between this element and
other elements."""
self.parent = parent
self.previous = previous
self.next = None
self.previousSibling = None
self.nextSibling = None
if self.parent and self.parent.contents:
self.previousSibling = self.parent.contents[-1]
self.previousSibling.nextSibling = self
def replaceWith(self, replaceWith):
oldParent = self.parent
myIndex = self.parent.index(self)
if hasattr(replaceWith, "parent")\
and replaceWith.parent is self.parent:
# We're replacing this element with one of its siblings.
index = replaceWith.parent.index(replaceWith)
if index and index < myIndex:
# Furthermore, it comes before this element. That
# means that when we extract it, the index of this
# element will change.
myIndex = myIndex - 1
self.extract()
oldParent.insert(myIndex, replaceWith)
def replaceWithChildren(self):
myParent = self.parent
myIndex = self.parent.index(self)
self.extract()
reversedChildren = list(self.contents)
reversedChildren.reverse()
for child in reversedChildren:
myParent.insert(myIndex, child)
def extract(self):
"""Destructively rips this element out of the tree."""
if self.parent:
try:
del self.parent.contents[self.parent.index(self)]
except ValueError:
pass
#Find the two elements that would be next to each other if
#this element (and any children) hadn't been parsed. Connect
#the two.
lastChild = self._lastRecursiveChild()
nextElement = lastChild.next
if self.previous:
self.previous.next = nextElement
if nextElement:
nextElement.previous = self.previous
self.previous = None
lastChild.next = None
self.parent = None
if self.previousSibling:
self.previousSibling.nextSibling = self.nextSibling
if self.nextSibling:
self.nextSibling.previousSibling = self.previousSibling
self.previousSibling = self.nextSibling = None
return self
def _lastRecursiveChild(self):
"Finds the last element beneath this object to be parsed."
lastChild = self
while hasattr(lastChild, 'contents') and lastChild.contents:
lastChild = lastChild.contents[-1]
return lastChild
def insert(self, position, newChild):
if isinstance(newChild, basestring) \
and not isinstance(newChild, NavigableString):
newChild = NavigableString(newChild)
position = min(position, len(self.contents))
if hasattr(newChild, 'parent') and newChild.parent is not None:
# We're 'inserting' an element that's already one
# of this object's children.
if newChild.parent is self:
index = self.index(newChild)
if index > position:
# Furthermore we're moving it further down the
# list of this object's children. That means that
# when we extract this element, our target index
# will jump down one.
position = position - 1
newChild.extract()
newChild.parent = self
previousChild = None
if position == 0:
newChild.previousSibling = None
newChild.previous = self
else:
previousChild = self.contents[position-1]
newChild.previousSibling = previousChild
newChild.previousSibling.nextSibling = newChild
newChild.previous = previousChild._lastRecursiveChild()
if newChild.previous:
newChild.previous.next = newChild
newChildsLastElement = newChild._lastRecursiveChild()
if position >= len(self.contents):
newChild.nextSibling = None
parent = self
parentsNextSibling = None
while not parentsNextSibling:
parentsNextSibling = parent.nextSibling
parent = parent.parent
if not parent: # This is the last element in the document.
break
if parentsNextSibling:
newChildsLastElement.next = parentsNextSibling
else:
newChildsLastElement.next = None
else:
nextChild = self.contents[position]
newChild.nextSibling = nextChild
if newChild.nextSibling:
newChild.nextSibling.previousSibling = newChild
newChildsLastElement.next = nextChild
if newChildsLastElement.next:
newChildsLastElement.next.previous = newChildsLastElement
self.contents.insert(position, newChild)
def append(self, tag):
"""Appends the given tag to the contents of this tag."""
self.insert(len(self.contents), tag)
def findNext(self, name=None, attrs={}, text=None, **kwargs):
"""Returns the first item that matches the given criteria and
appears after this Tag in the document."""
return self._findOne(self.findAllNext, name, attrs, text, **kwargs)
def findAllNext(self, name=None, attrs={}, text=None, limit=None,
**kwargs):
"""Returns all items that match the given criteria and appear
after this Tag in the document."""
return self._findAll(name, attrs, text, limit, self.nextGenerator,
**kwargs)
def findNextSibling(self, name=None, attrs={}, text=None, **kwargs):
"""Returns the closest sibling to this Tag that matches the
given criteria and appears after this Tag in the document."""
return self._findOne(self.findNextSiblings, name, attrs, text,
**kwargs)
def findNextSiblings(self, name=None, attrs={}, text=None, limit=None,
**kwargs):
"""Returns the siblings of this Tag that match the given
criteria and appear after this Tag in the document."""
return self._findAll(name, attrs, text, limit,
self.nextSiblingGenerator, **kwargs)
fetchNextSiblings = findNextSiblings # Compatibility with pre-3.x
def findPrevious(self, name=None, attrs={}, text=None, **kwargs):
"""Returns the first item that matches the given criteria and
appears before this Tag in the document."""
return self._findOne(self.findAllPrevious, name, attrs, text, **kwargs)
def findAllPrevious(self, name=None, attrs={}, text=None, limit=None,
**kwargs):
"""Returns all items that match the given criteria and appear
before this Tag in the document."""
return self._findAll(name, attrs, text, limit, self.previousGenerator,
**kwargs)
fetchPrevious = findAllPrevious # Compatibility with pre-3.x
def findPreviousSibling(self, name=None, attrs={}, text=None, **kwargs):
"""Returns the closest sibling to this Tag that matches the
given criteria and appears before this Tag in the document."""
return self._findOne(self.findPreviousSiblings, name, attrs, text,
**kwargs)
def findPreviousSiblings(self, name=None, attrs={}, text=None,
limit=None, **kwargs):
"""Returns the siblings of this Tag that match the given
criteria and appear before this Tag in the document."""
return self._findAll(name, attrs, text, limit,
self.previousSiblingGenerator, **kwargs)
fetchPreviousSiblings = findPreviousSiblings # Compatibility with pre-3.x
def findParent(self, name=None, attrs={}, **kwargs):
"""Returns the closest parent of this Tag that matches the given
criteria."""
# NOTE: We can't use _findOne because findParents takes a different
# set of arguments.
r = None
l = self.findParents(name, attrs, 1)
if l:
r = l[0]
return r
def findParents(self, name=None, attrs={}, limit=None, **kwargs):
"""Returns the parents of this Tag that match the given
criteria."""
return self._findAll(name, attrs, None, limit, self.parentGenerator,
**kwargs)
fetchParents = findParents # Compatibility with pre-3.x
#These methods do the real heavy lifting.
def _findOne(self, method, name, attrs, text, **kwargs):
r = None
l = method(name, attrs, text, 1, **kwargs)
if l:
r = l[0]
return r
def _findAll(self, name, attrs, text, limit, generator, **kwargs):
"Iterates over a generator looking for things that match."
if isinstance(name, SoupStrainer):
strainer = name
# (Possibly) special case some findAll*(...) searches
elif text is None and not limit and not attrs and not kwargs:
# findAll*(True)
if name is True:
return [element for element in generator()
if isinstance(element, Tag)]
# findAll*('tag-name')
elif isinstance(name, basestring):
return [element for element in generator()
if isinstance(element, Tag) and
element.name == name]
else:
strainer = SoupStrainer(name, attrs, text, **kwargs)
# Build a SoupStrainer
else:
strainer = SoupStrainer(name, attrs, text, **kwargs)
results = ResultSet(strainer)
g = generator()
while True:
try:
i = g.next()
except StopIteration:
break
if i:
found = strainer.search(i)
if found:
results.append(found)
if limit and len(results) >= limit:
break
return results
#These Generators can be used to navigate starting from both
#NavigableStrings and Tags.
def nextGenerator(self):
i = self
while i is not None:
i = i.next
yield i
def nextSiblingGenerator(self):
i = self
while i is not None:
i = i.nextSibling
yield i
def previousGenerator(self):
i = self
while i is not None:
i = i.previous
yield i
def previousSiblingGenerator(self):
i = self
while i is not None:
i = i.previousSibling
yield i
def parentGenerator(self):
i = self
while i is not None:
i = i.parent
yield i
# Utility methods
def substituteEncoding(self, str, encoding=None):
encoding = encoding or "utf-8"
return str.replace("%SOUP-ENCODING%", encoding)
def toEncoding(self, s, encoding=None):
"""Encodes an object to a string in some encoding, or to Unicode.
."""
if isinstance(s, unicode):
if encoding:
s = s.encode(encoding)
elif isinstance(s, str):
if encoding:
s = s.encode(encoding)
else:
s = unicode(s)
else:
if encoding:
s = self.toEncoding(str(s), encoding)
else:
s = unicode(s)
return s
BARE_AMPERSAND_OR_BRACKET = re.compile("([<>]|"
+ "&(?!#\d+;|#x[0-9a-fA-F]+;|\w+;)"
+ ")")
def _sub_entity(self, x):
"""Used with a regular expression to substitute the
appropriate XML entity for an XML special character."""
return "&" + self.XML_SPECIAL_CHARS_TO_ENTITIES[x.group(0)[0]] + ";"
class NavigableString(unicode, PageElement):
def __new__(cls, value):
"""Create a new NavigableString.
When unpickling a NavigableString, this method is called with
the string in DEFAULT_OUTPUT_ENCODING. That encoding needs to be
passed in to the superclass's __new__ or the superclass won't know
how to handle non-ASCII characters.
"""
if isinstance(value, unicode):
return unicode.__new__(cls, value)
return unicode.__new__(cls, value, DEFAULT_OUTPUT_ENCODING)
def __getnewargs__(self):
return (NavigableString.__str__(self),)
def __getattr__(self, attr):
"""text.string gives you text. This is for backwards
compatibility for Navigable*String, but for CData* it lets you
get the string without the CData wrapper."""
if attr == 'string':
return self
else:
raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__.__name__, attr)
def __unicode__(self):
return str(self).decode(DEFAULT_OUTPUT_ENCODING)
def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING):
# Substitute outgoing XML entities.
data = self.BARE_AMPERSAND_OR_BRACKET.sub(self._sub_entity, self)
if encoding:
return data.encode(encoding)
else:
return data
class CData(NavigableString):
def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING):
return "<![CDATA[%s]]>" % NavigableString.__str__(self, encoding)
class ProcessingInstruction(NavigableString):
def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING):
output = self
if "%SOUP-ENCODING%" in output:
output = self.substituteEncoding(output, encoding)
return "<?%s?>" % self.toEncoding(output, encoding)
class Comment(NavigableString):
def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING):
return "<!--%s-->" % NavigableString.__str__(self, encoding)
class Declaration(NavigableString):
def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING):
return "<!%s>" % NavigableString.__str__(self, encoding)
class Tag(PageElement):
"""Represents a found HTML tag with its attributes and contents."""
def _convertEntities(self, match):
"""Used in a call to re.sub to replace HTML, XML, and numeric
entities with the appropriate Unicode characters. If HTML
entities are being converted, any unrecognized entities are
escaped."""
x = match.group(1)
if self.convertHTMLEntities and x in name2codepoint:
return unichr(name2codepoint[x])
elif x in self.XML_ENTITIES_TO_SPECIAL_CHARS:
if self.convertXMLEntities:
return self.XML_ENTITIES_TO_SPECIAL_CHARS[x]
else:
return u'&%s;' % x
elif len(x) > 0 and x[0] == '#':
# Handle numeric entities
if len(x) > 1 and x[1] == 'x':
return unichr(int(x[2:], 16))
else:
return unichr(int(x[1:]))
elif self.escapeUnrecognizedEntities:
return u'&%s;' % x
else:
return u'&%s;' % x
def __init__(self, parser, name, attrs=None, parent=None,
previous=None):
"Basic constructor."
# We don't actually store the parser object: that lets extracted
# chunks be garbage-collected
self.parserClass = parser.__class__
self.isSelfClosing = parser.isSelfClosingTag(name)
self.name = name
if attrs is None:
attrs = []
elif isinstance(attrs, dict):
attrs = attrs.items()
self.attrs = attrs
self.contents = []
self.setup(parent, previous)
self.hidden = False
self.containsSubstitutions = False
self.convertHTMLEntities = parser.convertHTMLEntities
self.convertXMLEntities = parser.convertXMLEntities
self.escapeUnrecognizedEntities = parser.escapeUnrecognizedEntities
# Convert any HTML, XML, or numeric entities in the attribute values.
convert = lambda(k, val): (k,
re.sub("&(#\d+|#x[0-9a-fA-F]+|\w+);",
self._convertEntities,
val))
self.attrs = map(convert, self.attrs)
def getString(self):
if (len(self.contents) == 1
and isinstance(self.contents[0], NavigableString)):
return self.contents[0]
def setString(self, string):
"""Replace the contents of the tag with a string"""
self.clear()
self.append(string)
string = property(getString, setString)
def getText(self, separator=u""):
if not len(self.contents):
return u""
stopNode = self._lastRecursiveChild().next
strings = []
current = self.contents[0]
while current is not stopNode:
if isinstance(current, NavigableString):
strings.append(current.strip())
current = current.next
return separator.join(strings)
text = property(getText)
def get(self, key, default=None):
"""Returns the value of the 'key' attribute for the tag, or
the value given for 'default' if it doesn't have that
attribute."""
return self._getAttrMap().get(key, default)
def clear(self):
"""Extract all children."""
for child in self.contents[:]:
child.extract()
def index(self, element):
for i, child in enumerate(self.contents):
if child is element:
return i
raise ValueError("Tag.index: element not in tag")
def has_key(self, key):
return self._getAttrMap().has_key(key)
def __getitem__(self, key):
"""tag[key] returns the value of the 'key' attribute for the tag,
and throws an exception if it's not there."""
return self._getAttrMap()[key]
def __iter__(self):
"Iterating over a tag iterates over its contents."
return iter(self.contents)
def __len__(self):
"The length of a tag is the length of its list of contents."
return len(self.contents)
def __contains__(self, x):
return x in self.contents
def __nonzero__(self):
"A tag is non-None even if it has no contents."
return True
def __setitem__(self, key, value):
"""Setting tag[key] sets the value of the 'key' attribute for the
tag."""
self._getAttrMap()
self.attrMap[key] = value
found = False
for i in range(0, len(self.attrs)):
if self.attrs[i][0] == key:
self.attrs[i] = (key, value)
found = True
if not found:
self.attrs.append((key, value))
self._getAttrMap()[key] = value
def __delitem__(self, key):
"Deleting tag[key] deletes all 'key' attributes for the tag."
for item in self.attrs:
if item[0] == key:
self.attrs.remove(item)
#We don't break because bad HTML can define the same
#attribute multiple times.
self._getAttrMap()
if self.attrMap.has_key(key):
del self.attrMap[key]
def __call__(self, *args, **kwargs):
"""Calling a tag like a function is the same as calling its
findAll() method. Eg. tag('a') returns a list of all the A tags
found within this tag."""
return apply(self.findAll, args, kwargs)
def __getattr__(self, tag):
#print "Getattr %s.%s" % (self.__class__, tag)
if len(tag) > 3 and tag.rfind('Tag') == len(tag)-3:
return self.find(tag[:-3])
elif tag.find('__') != 0:
return self.find(tag)
raise AttributeError, "'%s' object has no attribute '%s'" % (self.__class__, tag)
def __eq__(self, other):
"""Returns true iff this tag has the same name, the same attributes,
and the same contents (recursively) as the given tag.
NOTE: right now this will return false if two tags have the
same attributes in a different order. Should this be fixed?"""
if other is self:
return True
if not hasattr(other, 'name') or not hasattr(other, 'attrs') or not hasattr(other, 'contents') or self.name != other.name or self.attrs != other.attrs or len(self) != len(other):
return False
for i in range(0, len(self.contents)):
if self.contents[i] != other.contents[i]:
return False
return True
def __ne__(self, other):
"""Returns true iff this tag is not identical to the other tag,
as defined in __eq__."""
return not self == other
def __repr__(self, encoding=DEFAULT_OUTPUT_ENCODING):
"""Renders this tag as a string."""
return self.__str__(encoding)
def __unicode__(self):
return self.__str__(None)
def __str__(self, encoding=DEFAULT_OUTPUT_ENCODING,
prettyPrint=False, indentLevel=0):
"""Returns a string or Unicode representation of this tag and
its contents. To get Unicode, pass None for encoding.
NOTE: since Python's HTML parser consumes whitespace, this
method is not certain to reproduce the whitespace present in
the original string."""
encodedName = self.toEncoding(self.name, encoding)
attrs = []
if self.attrs:
for key, val in self.attrs:
fmt = '%s="%s"'
if isinstance(val, basestring):
if self.containsSubstitutions and '%SOUP-ENCODING%' in val:
val = self.substituteEncoding(val, encoding)
# The attribute value either:
#
# * Contains no embedded double quotes or single quotes.
# No problem: we enclose it in double quotes.
# * Contains embedded single quotes. No problem:
# double quotes work here too.
# * Contains embedded double quotes. No problem:
# we enclose it in single quotes.
# * Embeds both single _and_ double quotes. This
# can't happen naturally, but it can happen if
# you modify an attribute value after parsing
# the document. Now we have a bit of a
# problem. We solve it by enclosing the
# attribute in single quotes, and escaping any
# embedded single quotes to XML entities.
if '"' in val:
fmt = "%s='%s'"
if "'" in val:
# TODO: replace with apos when
# appropriate.
val = val.replace("'", "&squot;")
# Now we're okay w/r/t quotes. But the attribute
# value might also contain angle brackets, or
# ampersands that aren't part of entities. We need
# to escape those to XML entities too.
val = self.BARE_AMPERSAND_OR_BRACKET.sub(self._sub_entity, val)
attrs.append(fmt % (self.toEncoding(key, encoding),
self.toEncoding(val, encoding)))
close = ''
closeTag = ''
if self.isSelfClosing:
close = ' /'
else:
closeTag = '</%s>' % encodedName
indentTag, indentContents = 0, 0
if prettyPrint:
indentTag = indentLevel
space = (' ' * (indentTag-1))
indentContents = indentTag + 1
contents = self.renderContents(encoding, prettyPrint, indentContents)
if self.hidden:
s = contents
else:
s = []
attributeString = ''
if attrs:
attributeString = ' ' + ' '.join(attrs)
if prettyPrint:
s.append(space)
s.append('<%s%s%s>' % (encodedName, attributeString, close))
if prettyPrint:
s.append("\n")
s.append(contents)
if prettyPrint and contents and contents[-1] != "\n":
s.append("\n")
if prettyPrint and closeTag:
s.append(space)
s.append(closeTag)
if prettyPrint and closeTag and self.nextSibling:
s.append("\n")
s = ''.join(s)
return s
def decompose(self):
"""Recursively destroys the contents of this tree."""
self.extract()
if len(self.contents) == 0:
return
current = self.contents[0]
while current is not None:
next = current.next
if isinstance(current, Tag):
del current.contents[:]
current.parent = None
current.previous = None
current.previousSibling = None
current.next = None
current.nextSibling = None
current = next
def prettify(self, encoding=DEFAULT_OUTPUT_ENCODING):
return self.__str__(encoding, True)
def renderContents(self, encoding=DEFAULT_OUTPUT_ENCODING,
prettyPrint=False, indentLevel=0):
"""Renders the contents of this tag as a string in the given
encoding. If encoding is None, returns a Unicode string.."""
s=[]
for c in self:
text = None
if isinstance(c, NavigableString):
text = c.__str__(encoding)
elif isinstance(c, Tag):
s.append(c.__str__(encoding, prettyPrint, indentLevel))
if text and prettyPrint:
text = text.strip()
if text:
if prettyPrint:
s.append(" " * (indentLevel-1))
s.append(text)
if prettyPrint:
s.append("\n")
return ''.join(s)
#Soup methods
def find(self, name=None, attrs={}, recursive=True, text=None,
**kwargs):
"""Return only the first child of this Tag matching the given
criteria."""
r = None
l = self.findAll(name, attrs, recursive, text, 1, **kwargs)
if l:
r = l[0]
return r
findChild = find
def findAll(self, name=None, attrs={}, recursive=True, text=None,
limit=None, **kwargs):
"""Extracts a list of Tag objects that match the given
criteria. You can specify the name of the Tag and any
attributes you want the Tag to have.
The value of a key-value pair in the 'attrs' map can be a
string, a list of strings, a regular expression object, or a
callable that takes a string and returns whether or not the
string matches for some custom definition of 'matches'. The
same is true of the tag name."""
generator = self.recursiveChildGenerator
if not recursive:
generator = self.childGenerator
return self._findAll(name, attrs, text, limit, generator, **kwargs)
findChildren = findAll
# Pre-3.x compatibility methods
first = find
fetch = findAll
def fetchText(self, text=None, recursive=True, limit=None):
return self.findAll(text=text, recursive=recursive, limit=limit)
def firstText(self, text=None, recursive=True):
return self.find(text=text, recursive=recursive)
#Private methods
def _getAttrMap(self):
"""Initializes a map representation of this tag's attributes,
if not already initialized."""
if not getattr(self, 'attrMap'):
self.attrMap = {}
for (key, value) in self.attrs:
self.attrMap[key] = value
return self.attrMap
#Generator methods
def childGenerator(self):
# Just use the iterator from the contents
return iter(self.contents)
def recursiveChildGenerator(self):
if not len(self.contents):
raise StopIteration
stopNode = self._lastRecursiveChild().next
current = self.contents[0]
while current is not stopNode:
yield current
current = current.next
# Next, a couple classes to represent queries and their results.
class SoupStrainer:
"""Encapsulates a number of ways of matching a markup element (tag or
text)."""
def __init__(self, name=None, attrs={}, text=None, **kwargs):
self.name = name
if isinstance(attrs, basestring):
kwargs['class'] = _match_css_class(attrs)
attrs = None
if kwargs:
if attrs:
attrs = attrs.copy()
attrs.update(kwargs)
else:
attrs = kwargs
self.attrs = attrs
self.text = text
def __str__(self):
if self.text:
return self.text
else:
return "%s|%s" % (self.name, self.attrs)
def searchTag(self, markupName=None, markupAttrs={}):
found = None
markup = None
if isinstance(markupName, Tag):
markup = markupName
markupAttrs = markup
callFunctionWithTagData = callable(self.name) \
and not isinstance(markupName, Tag)
if (not self.name) \
or callFunctionWithTagData \
or (markup and self._matches(markup, self.name)) \
or (not markup and self._matches(markupName, self.name)):
if callFunctionWithTagData:
match = self.name(markupName, markupAttrs)
else:
match = True
markupAttrMap = None
for attr, matchAgainst in self.attrs.items():
if not markupAttrMap:
if hasattr(markupAttrs, 'get'):
markupAttrMap = markupAttrs
else:
markupAttrMap = {}
for k,v in markupAttrs:
markupAttrMap[k] = v
attrValue = markupAttrMap.get(attr)
if not self._matches(attrValue, matchAgainst):
match = False
break
if match:
if markup:
found = markup
else:
found = markupName
return found
def search(self, markup):
#print 'looking for %s in %s' % (self, markup)
found = None
# If given a list of items, scan it for a text element that
# matches.
if hasattr(markup, "__iter__") \
and not isinstance(markup, Tag):
for element in markup:
if isinstance(element, NavigableString) \
and self.search(element):
found = element
break
# If it's a Tag, make sure its name or attributes match.
# Don't bother with Tags if we're searching for text.
elif isinstance(markup, Tag):
if not self.text:
found = self.searchTag(markup)
# If it's text, make sure the text matches.
elif isinstance(markup, NavigableString) or \
isinstance(markup, basestring):
if self._matches(markup, self.text):
found = markup
else:
raise Exception, "I don't know how to match against a %s" \
% markup.__class__
return found
def _matches(self, markup, matchAgainst):
#print "Matching %s against %s" % (markup, matchAgainst)
result = False
if matchAgainst is True:
result = markup is not None
elif callable(matchAgainst):
result = matchAgainst(markup)
else:
#Custom match methods take the tag as an argument, but all
#other ways of matching match the tag name as a string.
if isinstance(markup, Tag):
markup = markup.name
if markup and not isinstance(markup, basestring):
markup = unicode(markup)
#Now we know that chunk is either a string, or None.
if hasattr(matchAgainst, 'match'):
# It's a regexp object.
result = markup and matchAgainst.search(markup)
elif hasattr(matchAgainst, '__iter__'): # list-like
result = markup in matchAgainst
elif hasattr(matchAgainst, 'items'):
result = markup.has_key(matchAgainst)
elif matchAgainst and isinstance(markup, basestring):
if isinstance(markup, unicode):
matchAgainst = unicode(matchAgainst)
else:
matchAgainst = str(matchAgainst)
if not result:
result = matchAgainst == markup
return result
class ResultSet(list):
"""A ResultSet is just a list that keeps track of the SoupStrainer
that created it."""
def __init__(self, source):
list.__init__([])
self.source = source
# Now, some helper functions.
def buildTagMap(default, *args):
"""Turns a list of maps, lists, or scalars into a single map.
Used to build the SELF_CLOSING_TAGS, NESTABLE_TAGS, and
NESTING_RESET_TAGS maps out of lists and partial maps."""
built = {}
for portion in args:
if hasattr(portion, 'items'):
#It's a map. Merge it.
for k,v in portion.items():
built[k] = v
elif hasattr(portion, '__iter__'): # is a list
#It's a list. Map each item to the default.
for k in portion:
built[k] = default
else:
#It's a scalar. Map it to the default.
built[portion] = default
return built
# Now, the parser classes.
class BeautifulStoneSoup(Tag, SGMLParser):
"""This class contains the basic parser and search code. It defines
a parser that knows nothing about tag behavior except for the
following:
You can't close a tag without closing all the tags it encloses.
That is, "<foo><bar></foo>" actually means
"<foo><bar></bar></foo>".
[Another possible explanation is "<foo><bar /></foo>", but since
this class defines no SELF_CLOSING_TAGS, it will never use that
explanation.]
This class is useful for parsing XML or made-up markup languages,
or when BeautifulSoup makes an assumption counter to what you were
expecting."""
SELF_CLOSING_TAGS = {}
NESTABLE_TAGS = {}
RESET_NESTING_TAGS = {}
QUOTE_TAGS = {}
PRESERVE_WHITESPACE_TAGS = []
MARKUP_MASSAGE = [(re.compile('(<[^<>]*)/>'),
lambda x: x.group(1) + ' />'),
(re.compile('<!\s+([^<>]*)>'),
lambda x: '<!' + x.group(1) + '>')
]
ROOT_TAG_NAME = u'[document]'
HTML_ENTITIES = "html"
XML_ENTITIES = "xml"
XHTML_ENTITIES = "xhtml"
# TODO: This only exists for backwards-compatibility
ALL_ENTITIES = XHTML_ENTITIES
# Used when determining whether a text node is all whitespace and
# can be replaced with a single space. A text node that contains
# fancy Unicode spaces (usually non-breaking) should be left
# alone.
STRIP_ASCII_SPACES = { 9: None, 10: None, 12: None, 13: None, 32: None, }
def __init__(self, markup="", parseOnlyThese=None, fromEncoding=None,
markupMassage=True, smartQuotesTo=XML_ENTITIES,
convertEntities=None, selfClosingTags=None, isHTML=False):
"""The Soup object is initialized as the 'root tag', and the
provided markup (which can be a string or a file-like object)
is fed into the underlying parser.
sgmllib will process most bad HTML, and the BeautifulSoup
class has some tricks for dealing with some HTML that kills
sgmllib, but Beautiful Soup can nonetheless choke or lose data
if your data uses self-closing tags or declarations
incorrectly.
By default, Beautiful Soup uses regexes to sanitize input,
avoiding the vast majority of these problems. If the problems
don't apply to you, pass in False for markupMassage, and
you'll get better performance.
The default parser massage techniques fix the two most common
instances of invalid HTML that choke sgmllib:
<br/> (No space between name of closing tag and tag close)
<! --Comment--> (Extraneous whitespace in declaration)
You can pass in a custom list of (RE object, replace method)
tuples to get Beautiful Soup to scrub your input the way you
want."""
self.parseOnlyThese = parseOnlyThese
self.fromEncoding = fromEncoding
self.smartQuotesTo = smartQuotesTo
self.convertEntities = convertEntities
# Set the rules for how we'll deal with the entities we
# encounter
if self.convertEntities:
# It doesn't make sense to convert encoded characters to
# entities even while you're converting entities to Unicode.
# Just convert it all to Unicode.
self.smartQuotesTo = None
if convertEntities == self.HTML_ENTITIES:
self.convertXMLEntities = False
self.convertHTMLEntities = True
self.escapeUnrecognizedEntities = True
elif convertEntities == self.XHTML_ENTITIES:
self.convertXMLEntities = True
self.convertHTMLEntities = True
self.escapeUnrecognizedEntities = False
elif convertEntities == self.XML_ENTITIES:
self.convertXMLEntities = True
self.convertHTMLEntities = False
self.escapeUnrecognizedEntities = False
else:
self.convertXMLEntities = False
self.convertHTMLEntities = False
self.escapeUnrecognizedEntities = False
self.instanceSelfClosingTags = buildTagMap(None, selfClosingTags)
SGMLParser.__init__(self)
if hasattr(markup, 'read'): # It's a file-type object.
markup = markup.read()
self.markup = markup
self.markupMassage = markupMassage
try:
self._feed(isHTML=isHTML)
except StopParsing:
pass
self.markup = None # The markup can now be GCed
def convert_charref(self, name):
"""This method fixes a bug in Python's SGMLParser."""
try:
n = int(name)
except ValueError:
return
if not 0 <= n <= 127 : # ASCII ends at 127, not 255
return
return self.convert_codepoint(n)
def _feed(self, inDocumentEncoding=None, isHTML=False):
# Convert the document to Unicode.
markup = self.markup
if isinstance(markup, unicode):
if not hasattr(self, 'originalEncoding'):
self.originalEncoding = None
else:
dammit = UnicodeDammit\
(markup, [self.fromEncoding, inDocumentEncoding],
smartQuotesTo=self.smartQuotesTo, isHTML=isHTML)
markup = dammit.unicode
self.originalEncoding = dammit.originalEncoding
self.declaredHTMLEncoding = dammit.declaredHTMLEncoding
if markup:
if self.markupMassage:
if not hasattr(self.markupMassage, "__iter__"):
self.markupMassage = self.MARKUP_MASSAGE
for fix, m in self.markupMassage:
markup = fix.sub(m, markup)
# TODO: We get rid of markupMassage so that the
# soup object can be deepcopied later on. Some
# Python installations can't copy regexes. If anyone
# was relying on the existence of markupMassage, this
# might cause problems.
del(self.markupMassage)
self.reset()
SGMLParser.feed(self, markup)
# Close out any unfinished strings and close all the open tags.
self.endData()
while self.currentTag.name != self.ROOT_TAG_NAME:
self.popTag()
def __getattr__(self, methodName):
"""This method routes method call requests to either the SGMLParser
superclass or the Tag superclass, depending on the method name."""
#print "__getattr__ called on %s.%s" % (self.__class__, methodName)
if methodName.startswith('start_') or methodName.startswith('end_') \
or methodName.startswith('do_'):
return SGMLParser.__getattr__(self, methodName)
elif not methodName.startswith('__'):
return Tag.__getattr__(self, methodName)
else:
raise AttributeError
def isSelfClosingTag(self, name):
"""Returns true iff the given string is the name of a
self-closing tag according to this parser."""
return self.SELF_CLOSING_TAGS.has_key(name) \
or self.instanceSelfClosingTags.has_key(name)
def reset(self):
Tag.__init__(self, self, self.ROOT_TAG_NAME)
self.hidden = 1
SGMLParser.reset(self)
self.currentData = []
self.currentTag = None
self.tagStack = []
self.quoteStack = []
self.pushTag(self)
def popTag(self):
tag = self.tagStack.pop()
#print "Pop", tag.name
if self.tagStack:
self.currentTag = self.tagStack[-1]
return self.currentTag
def pushTag(self, tag):
#print "Push", tag.name
if self.currentTag:
self.currentTag.contents.append(tag)
self.tagStack.append(tag)
self.currentTag = self.tagStack[-1]
def endData(self, containerClass=NavigableString):
if self.currentData:
currentData = u''.join(self.currentData)
if (currentData.translate(self.STRIP_ASCII_SPACES) == '' and
not set([tag.name for tag in self.tagStack]).intersection(
self.PRESERVE_WHITESPACE_TAGS)):
if '\n' in currentData:
currentData = '\n'
else:
currentData = ' '
self.currentData = []
if self.parseOnlyThese and len(self.tagStack) <= 1 and \
(not self.parseOnlyThese.text or \
not self.parseOnlyThese.search(currentData)):
return
o = containerClass(currentData)
o.setup(self.currentTag, self.previous)
if self.previous:
self.previous.next = o
self.previous = o
self.currentTag.contents.append(o)
def _popToTag(self, name, inclusivePop=True):
"""Pops the tag stack up to and including the most recent
instance of the given tag. If inclusivePop is false, pops the tag
stack up to but *not* including the most recent instqance of
the given tag."""
#print "Popping to %s" % name
if name == self.ROOT_TAG_NAME:
return
numPops = 0
mostRecentTag = None
for i in range(len(self.tagStack)-1, 0, -1):
if name == self.tagStack[i].name:
numPops = len(self.tagStack)-i
break
if not inclusivePop:
numPops = numPops - 1
for i in range(0, numPops):
mostRecentTag = self.popTag()
return mostRecentTag
def _smartPop(self, name):
"""We need to pop up to the previous tag of this type, unless
one of this tag's nesting reset triggers comes between this
tag and the previous tag of this type, OR unless this tag is a
generic nesting trigger and another generic nesting trigger
comes between this tag and the previous tag of this type.
Examples:
<p>Foo<b>Bar *<p>* should pop to 'p', not 'b'.
<p>Foo<table>Bar *<p>* should pop to 'table', not 'p'.
<p>Foo<table><tr>Bar *<p>* should pop to 'tr', not 'p'.
<li><ul><li> *<li>* should pop to 'ul', not the first 'li'.
<tr><table><tr> *<tr>* should pop to 'table', not the first 'tr'
<td><tr><td> *<td>* should pop to 'tr', not the first 'td'
"""
nestingResetTriggers = self.NESTABLE_TAGS.get(name)
isNestable = nestingResetTriggers != None
isResetNesting = self.RESET_NESTING_TAGS.has_key(name)
popTo = None
inclusive = True
for i in range(len(self.tagStack)-1, 0, -1):
p = self.tagStack[i]
if (not p or p.name == name) and not isNestable:
#Non-nestable tags get popped to the top or to their
#last occurance.
popTo = name
break
if (nestingResetTriggers is not None
and p.name in nestingResetTriggers) \
or (nestingResetTriggers is None and isResetNesting
and self.RESET_NESTING_TAGS.has_key(p.name)):
#If we encounter one of the nesting reset triggers
#peculiar to this tag, or we encounter another tag
#that causes nesting to reset, pop up to but not
#including that tag.
popTo = p.name
inclusive = False
break
p = p.parent
if popTo:
self._popToTag(popTo, inclusive)
def unknown_starttag(self, name, attrs, selfClosing=0):
#print "Start tag %s: %s" % (name, attrs)
if self.quoteStack:
#This is not a real tag.
#print "<%s> is not real!" % name
attrs = ''.join([' %s="%s"' % (x, y) for x, y in attrs])
self.handle_data('<%s%s>' % (name, attrs))
return
self.endData()
if not self.isSelfClosingTag(name) and not selfClosing:
self._smartPop(name)
if self.parseOnlyThese and len(self.tagStack) <= 1 \
and (self.parseOnlyThese.text or not self.parseOnlyThese.searchTag(name, attrs)):
return
tag = Tag(self, name, attrs, self.currentTag, self.previous)
if self.previous:
self.previous.next = tag
self.previous = tag
self.pushTag(tag)
if selfClosing or self.isSelfClosingTag(name):
self.popTag()
if name in self.QUOTE_TAGS:
#print "Beginning quote (%s)" % name
self.quoteStack.append(name)
self.literal = 1
return tag
def unknown_endtag(self, name):
#print "End tag %s" % name
if self.quoteStack and self.quoteStack[-1] != name:
#This is not a real end tag.
#print "</%s> is not real!" % name
self.handle_data('</%s>' % name)
return
self.endData()
self._popToTag(name)
if self.quoteStack and self.quoteStack[-1] == name:
self.quoteStack.pop()
self.literal = (len(self.quoteStack) > 0)
def handle_data(self, data):
self.currentData.append(data)
def _toStringSubclass(self, text, subclass):
"""Adds a certain piece of text to the tree as a NavigableString
subclass."""
self.endData()
self.handle_data(text)
self.endData(subclass)
def handle_pi(self, text):
"""Handle a processing instruction as a ProcessingInstruction
object, possibly one with a %SOUP-ENCODING% slot into which an
encoding will be plugged later."""
if text[:3] == "xml":
text = u"xml version='1.0' encoding='%SOUP-ENCODING%'"
self._toStringSubclass(text, ProcessingInstruction)
def handle_comment(self, text):
"Handle comments as Comment objects."
self._toStringSubclass(text, Comment)
def handle_charref(self, ref):
"Handle character references as data."
if self.convertEntities:
data = unichr(int(ref))
else:
data = '&#%s;' % ref
self.handle_data(data)
def handle_entityref(self, ref):
"""Handle entity references as data, possibly converting known
HTML and/or XML entity references to the corresponding Unicode
characters."""
data = None
if self.convertHTMLEntities:
try:
data = unichr(name2codepoint[ref])
except KeyError:
pass
if not data and self.convertXMLEntities:
data = self.XML_ENTITIES_TO_SPECIAL_CHARS.get(ref)
if not data and self.convertHTMLEntities and \
not self.XML_ENTITIES_TO_SPECIAL_CHARS.get(ref):
# TODO: We've got a problem here. We're told this is
# an entity reference, but it's not an XML entity
# reference or an HTML entity reference. Nonetheless,
# the logical thing to do is to pass it through as an
# unrecognized entity reference.
#
# Except: when the input is "&carol;" this function
# will be called with input "carol". When the input is
# "AT&T", this function will be called with input
# "T". We have no way of knowing whether a semicolon
# was present originally, so we don't know whether
# this is an unknown entity or just a misplaced
# ampersand.
#
# The more common case is a misplaced ampersand, so I
# escape the ampersand and omit the trailing semicolon.
data = "&%s" % ref
if not data:
# This case is different from the one above, because we
# haven't already gone through a supposedly comprehensive
# mapping of entities to Unicode characters. We might not
# have gone through any mapping at all. So the chances are
# very high that this is a real entity, and not a
# misplaced ampersand.
data = "&%s;" % ref
self.handle_data(data)
def handle_decl(self, data):
"Handle DOCTYPEs and the like as Declaration objects."
self._toStringSubclass(data, Declaration)
def parse_declaration(self, i):
"""Treat a bogus SGML declaration as raw data. Treat a CDATA
declaration as a CData object."""
j = None
if self.rawdata[i:i+9] == '<![CDATA[':
k = self.rawdata.find(']]>', i)
if k == -1:
k = len(self.rawdata)
data = self.rawdata[i+9:k]
j = k+3
self._toStringSubclass(data, CData)
else:
try:
j = SGMLParser.parse_declaration(self, i)
except SGMLParseError:
toHandle = self.rawdata[i:]
self.handle_data(toHandle)
j = i + len(toHandle)
return j
class BeautifulSoup(BeautifulStoneSoup):
"""This parser knows the following facts about HTML:
* Some tags have no closing tag and should be interpreted as being
closed as soon as they are encountered.
* The text inside some tags (ie. 'script') may contain tags which
are not really part of the document and which should be parsed
as text, not tags. If you want to parse the text as tags, you can
always fetch it and parse it explicitly.
* Tag nesting rules:
Most tags can't be nested at all. For instance, the occurance of
a <p> tag should implicitly close the previous <p> tag.
<p>Para1<p>Para2
should be transformed into:
<p>Para1</p><p>Para2
Some tags can be nested arbitrarily. For instance, the occurance
of a <blockquote> tag should _not_ implicitly close the previous
<blockquote> tag.
Alice said: <blockquote>Bob said: <blockquote>Blah
should NOT be transformed into:
Alice said: <blockquote>Bob said: </blockquote><blockquote>Blah
Some tags can be nested, but the nesting is reset by the
interposition of other tags. For instance, a <tr> tag should
implicitly close the previous <tr> tag within the same <table>,
but not close a <tr> tag in another table.
<table><tr>Blah<tr>Blah
should be transformed into:
<table><tr>Blah</tr><tr>Blah
but,
<tr>Blah<table><tr>Blah
should NOT be transformed into
<tr>Blah<table></tr><tr>Blah
Differing assumptions about tag nesting rules are a major source
of problems with the BeautifulSoup class. If BeautifulSoup is not
treating as nestable a tag your page author treats as nestable,
try ICantBelieveItsBeautifulSoup, MinimalSoup, or
BeautifulStoneSoup before writing your own subclass."""
def __init__(self, *args, **kwargs):
if not kwargs.has_key('smartQuotesTo'):
kwargs['smartQuotesTo'] = self.HTML_ENTITIES
kwargs['isHTML'] = True
BeautifulStoneSoup.__init__(self, *args, **kwargs)
SELF_CLOSING_TAGS = buildTagMap(None,
('br' , 'hr', 'input', 'img', 'meta',
'spacer', 'link', 'frame', 'base', 'col'))
PRESERVE_WHITESPACE_TAGS = set(['pre', 'textarea'])
QUOTE_TAGS = {'script' : None, 'textarea' : None}
#According to the HTML standard, each of these inline tags can
#contain another tag of the same type. Furthermore, it's common
#to actually use these tags this way.
NESTABLE_INLINE_TAGS = ('span', 'font', 'q', 'object', 'bdo', 'sub', 'sup',
'center')
#According to the HTML standard, these block tags can contain
#another tag of the same type. Furthermore, it's common
#to actually use these tags this way.
NESTABLE_BLOCK_TAGS = ('blockquote', 'div', 'fieldset', 'ins', 'del')
#Lists can contain other lists, but there are restrictions.
NESTABLE_LIST_TAGS = { 'ol' : [],
'ul' : [],
'li' : ['ul', 'ol'],
'dl' : [],
'dd' : ['dl'],
'dt' : ['dl'] }
#Tables can contain other tables, but there are restrictions.
NESTABLE_TABLE_TAGS = {'table' : [],
'tr' : ['table', 'tbody', 'tfoot', 'thead'],
'td' : ['tr'],
'th' : ['tr'],
'thead' : ['table'],
'tbody' : ['table'],
'tfoot' : ['table'],
}
NON_NESTABLE_BLOCK_TAGS = ('address', 'form', 'p', 'pre')
#If one of these tags is encountered, all tags up to the next tag of
#this type are popped.
RESET_NESTING_TAGS = buildTagMap(None, NESTABLE_BLOCK_TAGS, 'noscript',
NON_NESTABLE_BLOCK_TAGS,
NESTABLE_LIST_TAGS,
NESTABLE_TABLE_TAGS)
NESTABLE_TAGS = buildTagMap([], NESTABLE_INLINE_TAGS, NESTABLE_BLOCK_TAGS,
NESTABLE_LIST_TAGS, NESTABLE_TABLE_TAGS)
# Used to detect the charset in a META tag; see start_meta
CHARSET_RE = re.compile("((^|;)\s*charset=)([^;]*)", re.M)
def start_meta(self, attrs):
"""Beautiful Soup can detect a charset included in a META tag,
try to convert the document to that charset, and re-parse the
document from the beginning."""
httpEquiv = None
contentType = None
contentTypeIndex = None
tagNeedsEncodingSubstitution = False
for i in range(0, len(attrs)):
key, value = attrs[i]
key = key.lower()
if key == 'http-equiv':
httpEquiv = value
elif key == 'content':
contentType = value
contentTypeIndex = i
if httpEquiv and contentType: # It's an interesting meta tag.
match = self.CHARSET_RE.search(contentType)
if match:
if (self.declaredHTMLEncoding is not None or
self.originalEncoding == self.fromEncoding):
# An HTML encoding was sniffed while converting
# the document to Unicode, or an HTML encoding was
# sniffed during a previous pass through the
# document, or an encoding was specified
# explicitly and it worked. Rewrite the meta tag.
def rewrite(match):
return match.group(1) + "%SOUP-ENCODING%"
newAttr = self.CHARSET_RE.sub(rewrite, contentType)
attrs[contentTypeIndex] = (attrs[contentTypeIndex][0],
newAttr)
tagNeedsEncodingSubstitution = True
else:
# This is our first pass through the document.
# Go through it again with the encoding information.
newCharset = match.group(3)
if newCharset and newCharset != self.originalEncoding:
self.declaredHTMLEncoding = newCharset
self._feed(self.declaredHTMLEncoding)
raise StopParsing
pass
tag = self.unknown_starttag("meta", attrs)
if tag and tagNeedsEncodingSubstitution:
tag.containsSubstitutions = True
class StopParsing(Exception):
pass
class ICantBelieveItsBeautifulSoup(BeautifulSoup):
"""The BeautifulSoup class is oriented towards skipping over
common HTML errors like unclosed tags. However, sometimes it makes
errors of its own. For instance, consider this fragment:
<b>Foo<b>Bar</b></b>
This is perfectly valid (if bizarre) HTML. However, the
BeautifulSoup class will implicitly close the first b tag when it
encounters the second 'b'. It will think the author wrote
"<b>Foo<b>Bar", and didn't close the first 'b' tag, because
there's no real-world reason to bold something that's already
bold. When it encounters '</b></b>' it will close two more 'b'
tags, for a grand total of three tags closed instead of two. This
can throw off the rest of your document structure. The same is
true of a number of other tags, listed below.
It's much more common for someone to forget to close a 'b' tag
than to actually use nested 'b' tags, and the BeautifulSoup class
handles the common case. This class handles the not-co-common
case: where you can't believe someone wrote what they did, but
it's valid HTML and BeautifulSoup screwed up by assuming it
wouldn't be."""
I_CANT_BELIEVE_THEYRE_NESTABLE_INLINE_TAGS = \
('em', 'big', 'i', 'small', 'tt', 'abbr', 'acronym', 'strong',
'cite', 'code', 'dfn', 'kbd', 'samp', 'strong', 'var', 'b',
'big')
I_CANT_BELIEVE_THEYRE_NESTABLE_BLOCK_TAGS = ('noscript',)
NESTABLE_TAGS = buildTagMap([], BeautifulSoup.NESTABLE_TAGS,
I_CANT_BELIEVE_THEYRE_NESTABLE_BLOCK_TAGS,
I_CANT_BELIEVE_THEYRE_NESTABLE_INLINE_TAGS)
class MinimalSoup(BeautifulSoup):
"""The MinimalSoup class is for parsing HTML that contains
pathologically bad markup. It makes no assumptions about tag
nesting, but it does know which tags are self-closing, that
<script> tags contain Javascript and should not be parsed, that
META tags may contain encoding information, and so on.
This also makes it better for subclassing than BeautifulStoneSoup
or BeautifulSoup."""
RESET_NESTING_TAGS = buildTagMap('noscript')
NESTABLE_TAGS = {}
class BeautifulSOAP(BeautifulStoneSoup):
"""This class will push a tag with only a single string child into
the tag's parent as an attribute. The attribute's name is the tag
name, and the value is the string child. An example should give
the flavor of the change:
<foo><bar>baz</bar></foo>
=>
<foo bar="baz"><bar>baz</bar></foo>
You can then access fooTag['bar'] instead of fooTag.barTag.string.
This is, of course, useful for scraping structures that tend to
use subelements instead of attributes, such as SOAP messages. Note
that it modifies its input, so don't print the modified version
out.
I'm not sure how many people really want to use this class; let me
know if you do. Mainly I like the name."""
def popTag(self):
if len(self.tagStack) > 1:
tag = self.tagStack[-1]
parent = self.tagStack[-2]
parent._getAttrMap()
if (isinstance(tag, Tag) and len(tag.contents) == 1 and
isinstance(tag.contents[0], NavigableString) and
not parent.attrMap.has_key(tag.name)):
parent[tag.name] = tag.contents[0]
BeautifulStoneSoup.popTag(self)
#Enterprise class names! It has come to our attention that some people
#think the names of the Beautiful Soup parser classes are too silly
#and "unprofessional" for use in enterprise screen-scraping. We feel
#your pain! For such-minded folk, the Beautiful Soup Consortium And
#All-Night Kosher Bakery recommends renaming this file to
#"RobustParser.py" (or, in cases of extreme enterprisiness,
#"RobustParserBeanInterface.class") and using the following
#enterprise-friendly class aliases:
class RobustXMLParser(BeautifulStoneSoup):
pass
class RobustHTMLParser(BeautifulSoup):
pass
class RobustWackAssHTMLParser(ICantBelieveItsBeautifulSoup):
pass
class RobustInsanelyWackAssHTMLParser(MinimalSoup):
pass
class SimplifyingSOAPParser(BeautifulSOAP):
pass
######################################################
#
# Bonus library: Unicode, Dammit
#
# This class forces XML data into a standard format (usually to UTF-8
# or Unicode). It is heavily based on code from Mark Pilgrim's
# Universal Feed Parser. It does not rewrite the XML or HTML to
# reflect a new encoding: that happens in BeautifulStoneSoup.handle_pi
# (XML) and BeautifulSoup.start_meta (HTML).
# Autodetects character encodings.
# Download from http://chardet.feedparser.org/
try:
import chardet
# import chardet.constants
# chardet.constants._debug = 1
except ImportError:
chardet = None
# cjkcodecs and iconv_codec make Python know about more character encodings.
# Both are available from http://cjkpython.i18n.org/
# They're built in if you use Python 2.4.
try:
import cjkcodecs.aliases
except ImportError:
pass
try:
import iconv_codec
except ImportError:
pass
class UnicodeDammit:
"""A class for detecting the encoding of a *ML document and
converting it to a Unicode string. If the source encoding is
windows-1252, can replace MS smart quotes with their HTML or XML
equivalents."""
# This dictionary maps commonly seen values for "charset" in HTML
# meta tags to the corresponding Python codec names. It only covers
# values that aren't in Python's aliases and can't be determined
# by the heuristics in find_codec.
CHARSET_ALIASES = { "macintosh" : "mac-roman",
"x-sjis" : "shift-jis" }
def __init__(self, markup, overrideEncodings=[],
smartQuotesTo='xml', isHTML=False):
self.declaredHTMLEncoding = None
self.markup, documentEncoding, sniffedEncoding = \
self._detectEncoding(markup, isHTML)
self.smartQuotesTo = smartQuotesTo
self.triedEncodings = []
if markup == '' or isinstance(markup, unicode):
self.originalEncoding = None
self.unicode = unicode(markup)
return
u = None
for proposedEncoding in overrideEncodings:
u = self._convertFrom(proposedEncoding)
if u: break
if not u:
for proposedEncoding in (documentEncoding, sniffedEncoding):
u = self._convertFrom(proposedEncoding)
if u: break
# If no luck and we have auto-detection library, try that:
if not u and chardet and not isinstance(self.markup, unicode):
u = self._convertFrom(chardet.detect(self.markup)['encoding'])
# As a last resort, try utf-8 and windows-1252:
if not u:
for proposed_encoding in ("utf-8", "windows-1252"):
u = self._convertFrom(proposed_encoding)
if u: break
self.unicode = u
if not u: self.originalEncoding = None
def _subMSChar(self, orig):
"""Changes a MS smart quote character to an XML or HTML
entity."""
sub = self.MS_CHARS.get(orig)
if isinstance(sub, tuple):
if self.smartQuotesTo == 'xml':
sub = '&#x%s;' % sub[1]
else:
sub = '&%s;' % sub[0]
return sub
def _convertFrom(self, proposed):
proposed = self.find_codec(proposed)
if not proposed or proposed in self.triedEncodings:
return None
self.triedEncodings.append(proposed)
markup = self.markup
# Convert smart quotes to HTML if coming from an encoding
# that might have them.
if self.smartQuotesTo and proposed.lower() in("windows-1252",
"iso-8859-1",
"iso-8859-2"):
markup = re.compile("([\x80-\x9f])").sub \
(lambda(x): self._subMSChar(x.group(1)),
markup)
try:
# print "Trying to convert document to %s" % proposed
u = self._toUnicode(markup, proposed)
self.markup = u
self.originalEncoding = proposed
except Exception, e:
# print "That didn't work!"
# print e
return None
#print "Correct encoding: %s" % proposed
return self.markup
def _toUnicode(self, data, encoding):
'''Given a string and its encoding, decodes the string into Unicode.
%encoding is a string recognized by encodings.aliases'''
# strip Byte Order Mark (if present)
if (len(data) >= 4) and (data[:2] == '\xfe\xff') \
and (data[2:4] != '\x00\x00'):
encoding = 'utf-16be'
data = data[2:]
elif (len(data) >= 4) and (data[:2] == '\xff\xfe') \
and (data[2:4] != '\x00\x00'):
encoding = 'utf-16le'
data = data[2:]
elif data[:3] == '\xef\xbb\xbf':
encoding = 'utf-8'
data = data[3:]
elif data[:4] == '\x00\x00\xfe\xff':
encoding = 'utf-32be'
data = data[4:]
elif data[:4] == '\xff\xfe\x00\x00':
encoding = 'utf-32le'
data = data[4:]
newdata = unicode(data, encoding)
return newdata
def _detectEncoding(self, xml_data, isHTML=False):
"""Given a document, tries to detect its XML encoding."""
xml_encoding = sniffed_xml_encoding = None
try:
if xml_data[:4] == '\x4c\x6f\xa7\x94':
# EBCDIC
xml_data = self._ebcdic_to_ascii(xml_data)
elif xml_data[:4] == '\x00\x3c\x00\x3f':
# UTF-16BE
sniffed_xml_encoding = 'utf-16be'
xml_data = unicode(xml_data, 'utf-16be').encode('utf-8')
elif (len(xml_data) >= 4) and (xml_data[:2] == '\xfe\xff') \
and (xml_data[2:4] != '\x00\x00'):
# UTF-16BE with BOM
sniffed_xml_encoding = 'utf-16be'
xml_data = unicode(xml_data[2:], 'utf-16be').encode('utf-8')
elif xml_data[:4] == '\x3c\x00\x3f\x00':
# UTF-16LE
sniffed_xml_encoding = 'utf-16le'
xml_data = unicode(xml_data, 'utf-16le').encode('utf-8')
elif (len(xml_data) >= 4) and (xml_data[:2] == '\xff\xfe') and \
(xml_data[2:4] != '\x00\x00'):
# UTF-16LE with BOM
sniffed_xml_encoding = 'utf-16le'
xml_data = unicode(xml_data[2:], 'utf-16le').encode('utf-8')
elif xml_data[:4] == '\x00\x00\x00\x3c':
# UTF-32BE
sniffed_xml_encoding = 'utf-32be'
xml_data = unicode(xml_data, 'utf-32be').encode('utf-8')
elif xml_data[:4] == '\x3c\x00\x00\x00':
# UTF-32LE
sniffed_xml_encoding = 'utf-32le'
xml_data = unicode(xml_data, 'utf-32le').encode('utf-8')
elif xml_data[:4] == '\x00\x00\xfe\xff':
# UTF-32BE with BOM
sniffed_xml_encoding = 'utf-32be'
xml_data = unicode(xml_data[4:], 'utf-32be').encode('utf-8')
elif xml_data[:4] == '\xff\xfe\x00\x00':
# UTF-32LE with BOM
sniffed_xml_encoding = 'utf-32le'
xml_data = unicode(xml_data[4:], 'utf-32le').encode('utf-8')
elif xml_data[:3] == '\xef\xbb\xbf':
# UTF-8 with BOM
sniffed_xml_encoding = 'utf-8'
xml_data = unicode(xml_data[3:], 'utf-8').encode('utf-8')
else:
sniffed_xml_encoding = 'ascii'
pass
except:
xml_encoding_match = None
xml_encoding_match = re.compile(
'^<\?.*encoding=[\'"](.*?)[\'"].*\?>').match(xml_data)
if not xml_encoding_match and isHTML:
regexp = re.compile('<\s*meta[^>]+charset=([^>]*?)[;\'">]', re.I)
xml_encoding_match = regexp.search(xml_data)
if xml_encoding_match is not None:
xml_encoding = xml_encoding_match.groups()[0].lower()
if isHTML:
self.declaredHTMLEncoding = xml_encoding
if sniffed_xml_encoding and \
(xml_encoding in ('iso-10646-ucs-2', 'ucs-2', 'csunicode',
'iso-10646-ucs-4', 'ucs-4', 'csucs4',
'utf-16', 'utf-32', 'utf_16', 'utf_32',
'utf16', 'u16')):
xml_encoding = sniffed_xml_encoding
return xml_data, xml_encoding, sniffed_xml_encoding
def find_codec(self, charset):
return self._codec(self.CHARSET_ALIASES.get(charset, charset)) \
or (charset and self._codec(charset.replace("-", ""))) \
or (charset and self._codec(charset.replace("-", "_"))) \
or charset
def _codec(self, charset):
if not charset: return charset
codec = None
try:
codecs.lookup(charset)
codec = charset
except (LookupError, ValueError):
pass
return codec
EBCDIC_TO_ASCII_MAP = None
def _ebcdic_to_ascii(self, s):
c = self.__class__
if not c.EBCDIC_TO_ASCII_MAP:
emap = (0,1,2,3,156,9,134,127,151,141,142,11,12,13,14,15,
16,17,18,19,157,133,8,135,24,25,146,143,28,29,30,31,
128,129,130,131,132,10,23,27,136,137,138,139,140,5,6,7,
144,145,22,147,148,149,150,4,152,153,154,155,20,21,158,26,
32,160,161,162,163,164,165,166,167,168,91,46,60,40,43,33,
38,169,170,171,172,173,174,175,176,177,93,36,42,41,59,94,
45,47,178,179,180,181,182,183,184,185,124,44,37,95,62,63,
186,187,188,189,190,191,192,193,194,96,58,35,64,39,61,34,
195,97,98,99,100,101,102,103,104,105,196,197,198,199,200,
201,202,106,107,108,109,110,111,112,113,114,203,204,205,
206,207,208,209,126,115,116,117,118,119,120,121,122,210,
211,212,213,214,215,216,217,218,219,220,221,222,223,224,
225,226,227,228,229,230,231,123,65,66,67,68,69,70,71,72,
73,232,233,234,235,236,237,125,74,75,76,77,78,79,80,81,
82,238,239,240,241,242,243,92,159,83,84,85,86,87,88,89,
90,244,245,246,247,248,249,48,49,50,51,52,53,54,55,56,57,
250,251,252,253,254,255)
import string
c.EBCDIC_TO_ASCII_MAP = string.maketrans( \
''.join(map(chr, range(256))), ''.join(map(chr, emap)))
return s.translate(c.EBCDIC_TO_ASCII_MAP)
MS_CHARS = { '\x80' : ('euro', '20AC'),
'\x81' : ' ',
'\x82' : ('sbquo', '201A'),
'\x83' : ('fnof', '192'),
'\x84' : ('bdquo', '201E'),
'\x85' : ('hellip', '2026'),
'\x86' : ('dagger', '2020'),
'\x87' : ('Dagger', '2021'),
'\x88' : ('circ', '2C6'),
'\x89' : ('permil', '2030'),
'\x8A' : ('Scaron', '160'),
'\x8B' : ('lsaquo', '2039'),
'\x8C' : ('OElig', '152'),
'\x8D' : '?',
'\x8E' : ('#x17D', '17D'),
'\x8F' : '?',
'\x90' : '?',
'\x91' : ('lsquo', '2018'),
'\x92' : ('rsquo', '2019'),
'\x93' : ('ldquo', '201C'),
'\x94' : ('rdquo', '201D'),
'\x95' : ('bull', '2022'),
'\x96' : ('ndash', '2013'),
'\x97' : ('mdash', '2014'),
'\x98' : ('tilde', '2DC'),
'\x99' : ('trade', '2122'),
'\x9a' : ('scaron', '161'),
'\x9b' : ('rsaquo', '203A'),
'\x9c' : ('oelig', '153'),
'\x9d' : '?',
'\x9e' : ('#x17E', '17E'),
'\x9f' : ('Yuml', ''),}
#######################################################################
#By default, act as an HTML pretty-printer.
if __name__ == '__main__':
import sys
soup = BeautifulSoup(sys.stdin)
print soup.prettify()
|
bsd-2-clause
|
[
624,
30117,
28028,
199,
37,
20528,
723,
436,
377,
12732,
199,
2,
1918,
17804,
13,
7181,
345,
529,
1159,
481,
8528,
2,
199,
1014,
921,
1544,
14,
1556,
3323,
14,
957,
15,
15619,
15,
30117,
12341,
15,
199,
199,
30117,
28028,
19953,
282,
334,
19614,
3866,
9,
4692,
503,
4163,
2213,
1901,
282,
199,
2350,
6025,
14,
2779,
6571,
3102,
436,
2018,
530,
284,
328,
22491,
626,
1852,
199,
390,
8837,
370,
20850,
12,
2754,
12,
436,
2811,
314,
3123,
14,
199,
199,
33,
5521,
13,
6194,
4692,
15,
4943,
2213,
14801,
282,
5521,
13,
6194,
666,
199,
6976,
14,
1626,
22907,
13,
6194,
4692,
15,
4943,
2213,
14801,
282,
5226,
590,
199,
778,
13,
6194,
666,
5523,
14,
982,
2195,
2213,
365,
1454,
17738,
199,
20501,
13,
6194,
12,
1265,
883,
675,
642,
3555,
370,
2342,
436,
2112,
314,
199,
20501,
13,
6194,
1777,
402,
652,
14,
199,
199,
30117,
28028,
5419,
543,
2018,
499,
14,
18,
436,
1536,
14,
2779,
965,
949,
5957,
199,
5714,
12,
1325,
1265,
7171,
1172,
1655,
3182,
737,
13806,
666,
370,
9094,
13,
24,
199,
692,
1265,
2597,
3907,
3520,
7795,
6117,
26,
199,
199,
10,
28470,
12,
367,
2599,
13,
13552,
316,
4528,
14134,
523,
1455,
921,
1560,
9886,
14,
3871,
2087,
14,
1308,
15,
199,
10,
286,
17421,
8933,
436,
284,
5598,
63,
9276,
12,
1314,
1050,
1655,
14134,
370,
314,
7869,
3748,
523,
701,
10952,
2018,
14,
523,
1455,
921,
67,
17421,
1548,
14,
73,
1085,
78,
14,
1308,
15,
199,
199,
30117,
28028,
7890,
3992,
367,
2877,
2446,
6057,
32647,
26,
421,
627,
14562,
933,
368,
12341,
12,
367,
6057,
4692,
12,
18868,
1698,
12,
503,
2195,
2881,
13,
6100,
2043,
2637,
626,
4928,
402,
10734,
2839,
4692,
14,
421,
627,
17132,
12,
367,
6057,
1255,
13,
1618,
13,
1589,
13,
77,
778,
4163,
1233,
12,
506,
652,
1686,
2043,
503,
3866,
14,
961,
1021,
965,
3330,
7042,
13,
2930,
946,
300,
631,
2932,
367,
2043,
12408,
282,
27962,
2198,
3123,
315,
314,
8870,
402,
2863,
4163,
2552,
14,
199,
199,
30117,
28028,
2597,
7890,
282,
1021,
334,
7087,
36,
28980,
9,
367,
28537,
5302,
316,
199,
1589,
2644,
402,
376,
4163,
503,
4692,
2213,
12,
436,
13806,
652,
370,
199,
7087,
14,
603,
2133,
402,
642,
1233,
365,
9394,
687,
7173,
19641,
1159,
29347,
16261,
10191,
14,
199,
199,
1858,
1655,
2419,
1265,
14433,
13632,
370,
5715,
3595,
14562,
28028,
12,
1937,
314,
199,
9970,
26,
199,
1014,
921,
1544,
14,
1556,
3323,
14,
957,
15,
15619,
15,
30117,
12341,
15,
9970,
14,
1360,
199,
199,
21741,
12,
1172,
2005,
6768,
1895,
261,
26,
199,
199,
7384,
334,
67,
9,
8353,
13,
6542,
12,
7005,
265,
1005,
30846,
5596,
265,
199,
199,
2422,
4481,
4644,
14,
199,
199,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
20945,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
10207,
26,
819,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
272,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
819,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
272,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
272,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
272,
543,
314,
4084,
14,
819,
627,
11443,
314,
536,
402,
314,
314,
14562,
28028,
1448,
1509,
280,
453,
436,
2900,
272,
653,
1070,
1804,
22267,
281,
699,
1151,
994,
6590,
314,
1561,
402,
2399,
8417,
1443,
506,
272,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
272,
1928,
2488,
6791,
5313,
4983,
14,
199,
199,
24571,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
2,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
13387,
1149,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
33,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
1864,
1766,
6436,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
1438,
9776,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
6072,
3942,
4479,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
199,
2514,
9037,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
2673,
2477,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
6388,
9179,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
26734,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
12,
5179,
13965,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
16952,
199,
199,
363,
2502,
363,
275,
298,
2553,
265,
1005,
30846,
5596,
265,
334,
274,
265,
1005,
82,
32,
8359,
1879,
14,
1308,
2924,
199,
363,
1023,
363,
275,
298,
19,
14,
18,
14,
17,
2,
199,
363,
7307,
363,
275,
298,
7384,
334,
67,
9,
8353,
13,
7409,
7005,
265,
1005,
30846,
5596,
265,
2,
199,
363,
1682,
363,
275,
298,
4665,
13,
2487,
6289,
2,
199,
199,
504,
12578,
25598,
492,
18868,
1698,
2842,
12,
18868,
1698,
9123,
199,
646,
6010,
199,
646,
9189,
1095,
199,
646,
2943,
199,
646,
295,
199,
646,
12578,
25598,
199,
893,
26,
523,
687,
30010,
552,
1701,
8710,
492,
536,
18,
19300,
199,
2590,
3545,
26,
523,
536,
18,
19300,
275,
1052,
199,
893,
26,
272,
663,
199,
2590,
12746,
26,
272,
687,
5951,
492,
2494,
465,
663,
199,
199,
3,
20676,
11176,
83,
1852,
14562,
28028,
7688,
370,
2198,
4692,
543,
10747,
199,
1226,
25598,
14,
1450,
1623,
275,
295,
14,
2014,
11894,
65,
13,
6353,
13,
58,
15898,
3754,
26,
65,
13,
6353,
13,
58,
16,
13,
25,
3672,
358,
199,
10131,
1095,
423,
9427,
354,
63,
1431,
275,
295,
14,
2014,
8,
82,
3894,
65,
13,
6353,
13,
58,
15898,
3754,
26,
65,
13,
6353,
13,
58,
16,
13,
25,
25739,
83,
10,
1959,
1431,
199,
199,
3472,
63,
8414,
63,
16314,
275,
298,
1624,
13,
24,
2,
199,
199,
318,
485,
1431,
63,
3919,
63,
533,
8,
495,
304,
272,
408,
3425,
282,
5363,
370,
1336,
314,
1627
] |
[
30117,
28028,
199,
37,
20528,
723,
436,
377,
12732,
199,
2,
1918,
17804,
13,
7181,
345,
529,
1159,
481,
8528,
2,
199,
1014,
921,
1544,
14,
1556,
3323,
14,
957,
15,
15619,
15,
30117,
12341,
15,
199,
199,
30117,
28028,
19953,
282,
334,
19614,
3866,
9,
4692,
503,
4163,
2213,
1901,
282,
199,
2350,
6025,
14,
2779,
6571,
3102,
436,
2018,
530,
284,
328,
22491,
626,
1852,
199,
390,
8837,
370,
20850,
12,
2754,
12,
436,
2811,
314,
3123,
14,
199,
199,
33,
5521,
13,
6194,
4692,
15,
4943,
2213,
14801,
282,
5521,
13,
6194,
666,
199,
6976,
14,
1626,
22907,
13,
6194,
4692,
15,
4943,
2213,
14801,
282,
5226,
590,
199,
778,
13,
6194,
666,
5523,
14,
982,
2195,
2213,
365,
1454,
17738,
199,
20501,
13,
6194,
12,
1265,
883,
675,
642,
3555,
370,
2342,
436,
2112,
314,
199,
20501,
13,
6194,
1777,
402,
652,
14,
199,
199,
30117,
28028,
5419,
543,
2018,
499,
14,
18,
436,
1536,
14,
2779,
965,
949,
5957,
199,
5714,
12,
1325,
1265,
7171,
1172,
1655,
3182,
737,
13806,
666,
370,
9094,
13,
24,
199,
692,
1265,
2597,
3907,
3520,
7795,
6117,
26,
199,
199,
10,
28470,
12,
367,
2599,
13,
13552,
316,
4528,
14134,
523,
1455,
921,
1560,
9886,
14,
3871,
2087,
14,
1308,
15,
199,
10,
286,
17421,
8933,
436,
284,
5598,
63,
9276,
12,
1314,
1050,
1655,
14134,
370,
314,
7869,
3748,
523,
701,
10952,
2018,
14,
523,
1455,
921,
67,
17421,
1548,
14,
73,
1085,
78,
14,
1308,
15,
199,
199,
30117,
28028,
7890,
3992,
367,
2877,
2446,
6057,
32647,
26,
421,
627,
14562,
933,
368,
12341,
12,
367,
6057,
4692,
12,
18868,
1698,
12,
503,
2195,
2881,
13,
6100,
2043,
2637,
626,
4928,
402,
10734,
2839,
4692,
14,
421,
627,
17132,
12,
367,
6057,
1255,
13,
1618,
13,
1589,
13,
77,
778,
4163,
1233,
12,
506,
652,
1686,
2043,
503,
3866,
14,
961,
1021,
965,
3330,
7042,
13,
2930,
946,
300,
631,
2932,
367,
2043,
12408,
282,
27962,
2198,
3123,
315,
314,
8870,
402,
2863,
4163,
2552,
14,
199,
199,
30117,
28028,
2597,
7890,
282,
1021,
334,
7087,
36,
28980,
9,
367,
28537,
5302,
316,
199,
1589,
2644,
402,
376,
4163,
503,
4692,
2213,
12,
436,
13806,
652,
370,
199,
7087,
14,
603,
2133,
402,
642,
1233,
365,
9394,
687,
7173,
19641,
1159,
29347,
16261,
10191,
14,
199,
199,
1858,
1655,
2419,
1265,
14433,
13632,
370,
5715,
3595,
14562,
28028,
12,
1937,
314,
199,
9970,
26,
199,
1014,
921,
1544,
14,
1556,
3323,
14,
957,
15,
15619,
15,
30117,
12341,
15,
9970,
14,
1360,
199,
199,
21741,
12,
1172,
2005,
6768,
1895,
261,
26,
199,
199,
7384,
334,
67,
9,
8353,
13,
6542,
12,
7005,
265,
1005,
30846,
5596,
265,
199,
199,
2422,
4481,
4644,
14,
199,
199,
497,
4972,
436,
675,
315,
1350,
436,
3366,
4513,
12,
543,
503,
1928,
199,
20945,
12,
787,
8211,
2741,
626,
314,
2569,
3704,
787,
199,
10207,
26,
819,
627,
6823,
402,
1350,
1233,
1471,
8074,
314,
3432,
4248,
272,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
6450,
14,
819,
627,
6823,
315,
3366,
1824,
1471,
9172,
314,
3432,
272,
4248,
4245,
12,
642,
769,
402,
3704,
436,
314,
2569,
272,
6450,
315,
314,
3794,
436,
15,
269,
1163,
8418,
2741,
272,
543,
314,
4084,
14,
819,
627,
11443,
314,
536,
402,
314,
314,
14562,
28028,
1448,
1509,
280,
453,
436,
2900,
272,
653,
1070,
1804,
22267,
281,
699,
1151,
994,
6590,
314,
1561,
402,
2399,
8417,
1443,
506,
272,
1202,
370,
10692,
503,
10016,
7585,
7131,
687,
642,
2032,
272,
1928,
2488,
6791,
5313,
4983,
14,
199,
199,
24571,
4141,
2281,
7049,
6515,
2334,
5877,
8164,
2401,
6483,
199,
2,
1179,
2281,
2,
2401,
1821,
7168,
1549,
5292,
2990,
12,
6931,
12,
5400,
2845,
199,
13387,
1149,
2296,
12,
2334,
5292,
2990,
1634,
3169,
2401,
3092,
2381,
199,
33,
3115,
3104,
9315,
9706,
14,
1621,
4825,
6461,
7000,
2334,
5877,
11489,
1549,
199,
1864,
1766,
6436,
6262,
7024,
2381,
1821,
8703,
12,
9168,
12,
9716,
12,
8820,
12,
199,
1438,
9776,
12,
1549,
9110,
6736,
334,
6446,
12,
5400,
2845,
5471,
2296,
12,
199,
6072,
3942,
4479,
1634,
9103,
9764,
1549,
9714,
27,
9102,
1634,
4815,
12,
7126,
12,
1549,
199,
2514,
9037,
27,
1549,
9748,
9831,
9,
9802,
9817,
2401,
5258,
1821,
9815,
1634,
199,
2673,
2477,
12,
7061,
1621,
7066,
12,
9644,
5603,
12,
1549,
7056,
334,
6446,
199,
6388,
9179,
1549,
7334,
9,
7043,
1621,
1821,
9683,
5738,
1634,
2334,
4815,
1634,
5749,
199,
26734,
12,
9704,
8036,
9691,
1634,
2334,
9726,
1634,
9712,
9784,
12,
5179,
13965,
14,
199,
199,
624,
199,
504,
636,
2443,
363,
492,
16952,
199,
199,
363,
2502,
363,
275,
298,
2553,
265,
1005,
30846,
5596,
265,
334,
274,
265,
1005,
82,
32,
8359,
1879,
14,
1308,
2924,
199,
363,
1023,
363,
275,
298,
19,
14,
18,
14,
17,
2,
199,
363,
7307,
363,
275,
298,
7384,
334,
67,
9,
8353,
13,
7409,
7005,
265,
1005,
30846,
5596,
265,
2,
199,
363,
1682,
363,
275,
298,
4665,
13,
2487,
6289,
2,
199,
199,
504,
12578,
25598,
492,
18868,
1698,
2842,
12,
18868,
1698,
9123,
199,
646,
6010,
199,
646,
9189,
1095,
199,
646,
2943,
199,
646,
295,
199,
646,
12578,
25598,
199,
893,
26,
523,
687,
30010,
552,
1701,
8710,
492,
536,
18,
19300,
199,
2590,
3545,
26,
523,
536,
18,
19300,
275,
1052,
199,
893,
26,
272,
663,
199,
2590,
12746,
26,
272,
687,
5951,
492,
2494,
465,
663,
199,
199,
3,
20676,
11176,
83,
1852,
14562,
28028,
7688,
370,
2198,
4692,
543,
10747,
199,
1226,
25598,
14,
1450,
1623,
275,
295,
14,
2014,
11894,
65,
13,
6353,
13,
58,
15898,
3754,
26,
65,
13,
6353,
13,
58,
16,
13,
25,
3672,
358,
199,
10131,
1095,
423,
9427,
354,
63,
1431,
275,
295,
14,
2014,
8,
82,
3894,
65,
13,
6353,
13,
58,
15898,
3754,
26,
65,
13,
6353,
13,
58,
16,
13,
25,
25739,
83,
10,
1959,
1431,
199,
199,
3472,
63,
8414,
63,
16314,
275,
298,
1624,
13,
24,
2,
199,
199,
318,
485,
1431,
63,
3919,
63,
533,
8,
495,
304,
272,
408,
3425,
282,
5363,
370,
1336,
314,
1627,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wilsonianb/nacl_contracts
|
pynacl/log_tools.py
|
2
|
4476
|
#!/usr/bin/python
# Copyright (c) 2012 The Native Client Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Logging related tools."""
import logging
import os
import subprocess
import sys
# Module-level configuration
LOG_FH = None
VERBOSE = False
def SetupLogging(verbose, file_handle=None, quiet=False):
"""Set up python logging.
Args:
verbose: If True, log to stderr at DEBUG level and write subprocess output
to stdout. Otherwise log to stderr at INFO level and do not print
subprocess output unless there is an error.
file_handle: If not None, must be a file-like object. All log output will
be written at DEBUG level, and all subprocess output will be
written, regardless of whether there are errors.
quiet: If True, log to stderr at WARNING level only. Only valid if verbose
is False.
"""
# Since one of our handlers always wants debug, set the global level to debug.
logging.getLogger().setLevel(logging.DEBUG)
stderr_handler = logging.StreamHandler()
stderr_handler.setFormatter(
logging.Formatter(fmt='%(levelname)s: %(message)s'))
if verbose:
global VERBOSE
VERBOSE = True
stderr_handler.setLevel(logging.DEBUG)
elif quiet:
stderr_handler.setLevel(logging.WARN)
else:
stderr_handler.setLevel(logging.INFO)
logging.getLogger().addHandler(stderr_handler)
if file_handle:
global LOG_FH
file_handler = logging.StreamHandler(file_handle)
file_handler.setLevel(logging.DEBUG)
file_handler.setFormatter(
logging.Formatter(fmt='%(levelname)s: %(message)s'))
logging.getLogger().addHandler(file_handler)
LOG_FH = file_handle
def WriteToLog(text):
if VERBOSE:
sys.stdout.write(text)
if LOG_FH:
LOG_FH.write(text)
def CheckCall(command, stdout=None, **kwargs):
"""Modulate command output level based on logging level.
If a logging file handle is set, always emit all output to it.
If the log level is set at debug or lower, also emit all output to stdout.
Otherwise, only emit output on error.
Args:
command: Command to run.
stdout (optional): File name to redirect stdout to.
**kwargs: Keyword args.
"""
cwd = os.path.abspath(kwargs.get('cwd', os.getcwd()))
logging.info('Running: subprocess.check_call(%r, cwd=%r)' % (command, cwd))
if stdout is None:
# Interleave stdout and stderr together and log that.
p = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
**kwargs)
output = p.stdout
else:
p = subprocess.Popen(command,
stdout=open(stdout, 'w'),
stderr=subprocess.PIPE,
**kwargs)
output = p.stderr
# Capture the output as it comes and emit it immediately.
line = output.readline()
while line:
WriteToLog(line)
line = output.readline()
if p.wait() != 0:
raise subprocess.CalledProcessError(cmd=command, returncode=p.returncode)
# Flush stdout so it does not get interleaved with future log or buildbot
# output which goes to stderr.
sys.stdout.flush()
def CheckOutput(command, **kwargs):
"""Capture stdout from a command, while logging its stderr.
This is essentially subprocess.check_output, but stderr is
handled the same way as in log_tools.CheckCall.
Args:
command: Command to run.
**kwargs: Keyword args.
"""
cwd = os.path.abspath(kwargs.get('cwd', os.getcwd()))
logging.info('Running: subprocess.check_output(%r, cwd=%r)' % (command, cwd))
p = subprocess.Popen(command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
**kwargs)
# Assume the output will not be huge or take a long time to come, so it
# is viable to just consume it all synchronously before logging anything.
# TODO(mcgrathr): Shovel stderr bits asynchronously if that ever seems
# worth the hair.
stdout_text, stderr_text = p.communicate()
WriteToLog(stderr_text)
if p.wait() != 0:
raise subprocess.CalledProcessError(cmd=command, returncode=p.returncode)
# Flush stdout so it does not get interleaved with future log or buildbot
# output which goes to stderr.
sys.stdout.flush()
logging.info('Result: %r' % stdout_text)
return stdout_text
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
1898,
334,
67,
9,
6029,
710,
653,
1905,
6810,
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,
14054,
4048,
7249,
1041,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
3873,
199,
646,
984,
199,
199,
3,
5673,
13,
1896,
2897,
199,
4947,
63,
32259,
275,
488,
199,
16075,
275,
756,
199,
199,
318,
12439,
14054,
8,
3832,
12,
570,
63,
2479,
29,
403,
12,
11971,
29,
797,
304,
523,
408,
1084,
1536,
2366,
2050,
14,
819,
3033,
26,
272,
3376,
26,
982,
715,
12,
943,
370,
4635,
737,
10990,
2166,
436,
2218,
3873,
1072,
1467,
370,
3839,
14,
6630,
943,
370,
4635,
737,
24008,
2166,
436,
886,
440,
870,
1467,
3873,
1072,
7444,
2337,
365,
376,
1125,
14,
272,
570,
63,
2479,
26,
982,
440,
488,
12,
1471,
506,
282,
570,
13,
2930,
909,
14,
2900,
943,
1072,
911,
326,
506,
5313,
737,
10990,
2166,
12,
436,
1006,
3873,
1072,
911,
506,
326,
5313,
12,
15270,
402,
3775,
2337,
787,
2552,
14,
272,
11971,
26,
982,
715,
12,
943,
370,
4635,
737,
14750,
2166,
1454,
14,
5972,
1686,
340,
3376,
1779,
365,
756,
14,
523,
408,
523,
327,
9336,
1373,
402,
4154,
8297,
3544,
15061,
3105,
12,
663,
314,
2288,
2166,
370,
3105,
14,
523,
2050,
14,
5572,
1252,
13548,
8,
4806,
14,
5287,
9,
523,
4635,
63,
2232,
275,
2050,
14,
22482,
342,
523,
4635,
63,
2232,
14,
26076,
8,
489,
2050,
14,
7772,
8,
5045,
29342,
20056,
9,
83,
26,
2818,
1188,
9,
83,
1333,
523,
340,
3376,
26,
272,
2288,
12348,
14607,
272,
12348,
14607,
275,
715,
272,
4635,
63,
2232,
14,
13548,
8,
4806,
14,
5287,
9,
523,
916,
11971,
26,
272,
4635,
63,
2232,
14,
13548,
8,
4806,
14,
17449,
9,
523,
587,
26,
272,
4635,
63,
2232,
14,
13548,
8,
4806,
14,
4531,
9,
523,
2050,
14,
5572,
1252,
18826,
8,
3083,
63,
2232,
9,
819,
340,
570,
63,
2479,
26,
272,
2288,
5051,
63,
32259,
272,
570,
63,
2232,
275,
2050,
14,
22482,
8,
493,
63,
2479,
9,
272,
570,
63,
2232,
14,
13548,
8,
4806,
14,
5287,
9,
272,
570,
63,
2232,
14,
26076,
8,
267,
2050,
14,
7772,
8,
5045,
29342,
20056,
9,
83,
26,
2818,
1188,
9,
83,
1333,
272,
2050,
14,
5572,
1252,
18826,
8,
493,
63,
2232,
9,
272,
5051,
63,
32259,
275,
570,
63,
2479,
421,
199,
318,
6990,
1378,
2445,
8,
505,
304,
523,
340,
12348,
14607,
26,
272,
984,
14,
2703,
14,
952,
8,
505,
9,
523,
340,
5051,
63,
32259,
26,
272,
5051,
63,
32259,
14,
952,
8,
505,
9,
421,
199,
318,
2670,
2176,
8,
1531,
12,
3839,
29,
403,
12,
1011,
958,
304,
523,
408,
9871,
5434,
1414,
1072,
2166,
4079,
641,
2050,
2166,
14,
819,
982,
282,
2050,
570,
2429,
365,
663,
12,
3544,
8689,
1006,
1072,
370,
652,
14,
523,
982,
314,
943,
2166,
365,
663,
737,
3105,
503,
5117,
12,
2597,
8689,
1006,
1072,
370,
3839,
14,
523,
6630,
12,
1454,
8689,
1072,
641,
1125,
14,
523,
3033,
26,
272,
1414,
26,
5817,
370,
1255,
14,
272,
3839,
334,
4144,
304,
3814,
536,
370,
4660,
3839,
370,
14,
272,
1011,
958,
26,
6431,
1249,
14,
523,
408,
523,
8288,
275,
747,
14,
515,
14,
4832,
8,
958,
14,
362,
360,
6525,
297,
747,
14,
9458,
4059,
523,
2050,
14,
815,
360,
9602,
26,
3873,
14,
1074,
63,
1250,
4042,
82,
12,
8288,
2458,
82,
3171,
450,
334,
1531,
12,
8288,
430,
819,
340,
3839,
365,
488,
26,
272,
327,
6551,
12422,
3839,
436,
4635,
10451,
436,
943,
626,
14,
272,
299,
275,
3873,
14,
7942,
8,
1531,
12,
586,
3839,
29,
5781,
14,
6089,
12,
586,
4635,
29,
5781,
14,
13850,
12,
586,
1011,
958,
9,
272,
1072,
275,
299,
14,
2703,
523,
587,
26,
272,
299,
275,
3873,
14,
7942,
8,
1531,
12,
586,
3839,
29,
1490,
8,
2703,
12,
283,
87,
659,
586,
4635,
29,
5781,
14,
6089,
12,
586,
1011,
958,
9,
272,
1072,
275,
299,
14,
3083,
819,
327,
29828,
314,
1072,
465,
652,
12477,
436,
8689,
652,
9939,
14,
523,
1004,
275,
1072,
14,
6407,
342,
523,
1830,
1004,
26,
272,
6990,
1378,
2445,
8,
604,
9,
272,
1004,
275,
1072,
14,
6407,
342,
819,
340,
299,
14,
2573,
342,
1137,
378,
26,
272,
746,
3873,
14,
24691,
8,
1760,
29,
1531,
12,
17630,
29,
80,
14,
9913,
9,
819,
327,
11040,
2084,
3839,
880,
652,
1630,
440,
664,
1640,
274,
4292,
543,
6466,
943,
503,
21306,
523,
327,
1072,
1314,
13538,
370,
4635,
14,
523,
984,
14,
2703,
14,
4939,
342,
421,
199,
318,
2670,
2959,
8,
1531,
12,
1011,
958,
304,
523,
408,
16640,
3839,
687,
282,
1414,
12,
1830,
2050,
2399,
4635,
14,
819,
961,
365,
28891,
3873,
14,
1074,
63,
1199,
12,
1325,
4635,
365,
523,
8860,
314,
2011,
4340,
465,
315,
943,
63,
2537,
14,
1799,
2176,
14,
523,
3033,
26,
272,
1414,
26,
5817,
370,
1255,
14,
272,
1011,
958,
26,
6431,
1249,
14,
523,
408,
523,
8288,
275,
747,
14,
515,
14,
4832,
8,
958,
14,
362,
360,
6525,
297,
747,
14,
9458,
4059,
523,
2050,
14,
815,
360,
9602,
26,
3873,
14,
1074,
63,
1199,
4042,
82,
12,
8288,
2458,
82,
3171,
450,
334,
1531,
12,
8288,
430,
819,
299,
275,
3873,
14,
7942,
8,
1531,
12,
2432,
3839,
29,
5781,
14,
6089,
12,
2432,
4635,
29,
5781,
14,
6089,
12,
2432,
1011,
958,
9,
819,
327,
16269,
314,
1072,
911,
440,
506,
27791,
503,
5452,
282,
1846,
900,
370,
11492,
12,
880,
652,
523,
327,
365,
1321,
461,
370,
2951,
9451,
652,
1006,
24248,
590,
2544,
2050,
7003,
14,
523,
327,
3254,
8,
5466,
926,
28854,
304,
428,
526,
1090,
4635,
5821,
29914,
340,
626,
14433,
12237,
523,
327,
25235,
314,
394,
8387,
14,
523,
3839,
63,
505,
12,
4635,
63,
505,
275,
299,
14,
10664,
342,
819,
6990,
1378,
2445,
8,
3083,
63,
505,
9,
819,
340,
299,
14,
2573,
342,
1137
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
1898,
334,
67,
9,
6029,
710,
653,
1905,
6810,
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,
14054,
4048,
7249,
1041,
199,
199,
646,
2050,
199,
646,
747,
199,
646,
3873,
199,
646,
984,
199,
199,
3,
5673,
13,
1896,
2897,
199,
4947,
63,
32259,
275,
488,
199,
16075,
275,
756,
199,
199,
318,
12439,
14054,
8,
3832,
12,
570,
63,
2479,
29,
403,
12,
11971,
29,
797,
304,
523,
408,
1084,
1536,
2366,
2050,
14,
819,
3033,
26,
272,
3376,
26,
982,
715,
12,
943,
370,
4635,
737,
10990,
2166,
436,
2218,
3873,
1072,
1467,
370,
3839,
14,
6630,
943,
370,
4635,
737,
24008,
2166,
436,
886,
440,
870,
1467,
3873,
1072,
7444,
2337,
365,
376,
1125,
14,
272,
570,
63,
2479,
26,
982,
440,
488,
12,
1471,
506,
282,
570,
13,
2930,
909,
14,
2900,
943,
1072,
911,
326,
506,
5313,
737,
10990,
2166,
12,
436,
1006,
3873,
1072,
911,
506,
326,
5313,
12,
15270,
402,
3775,
2337,
787,
2552,
14,
272,
11971,
26,
982,
715,
12,
943,
370,
4635,
737,
14750,
2166,
1454,
14,
5972,
1686,
340,
3376,
1779,
365,
756,
14,
523,
408,
523,
327,
9336,
1373,
402,
4154,
8297,
3544,
15061,
3105,
12,
663,
314,
2288,
2166,
370,
3105,
14,
523,
2050,
14,
5572,
1252,
13548,
8,
4806,
14,
5287,
9,
523,
4635,
63,
2232,
275,
2050,
14,
22482,
342,
523,
4635,
63,
2232,
14,
26076,
8,
489,
2050,
14,
7772,
8,
5045,
29342,
20056,
9,
83,
26,
2818,
1188,
9,
83,
1333,
523,
340,
3376,
26,
272,
2288,
12348,
14607,
272,
12348,
14607,
275,
715,
272,
4635,
63,
2232,
14,
13548,
8,
4806,
14,
5287,
9,
523,
916,
11971,
26,
272,
4635,
63,
2232,
14,
13548,
8,
4806,
14,
17449,
9,
523,
587,
26,
272,
4635,
63,
2232,
14,
13548,
8,
4806,
14,
4531,
9,
523,
2050,
14,
5572,
1252,
18826,
8,
3083,
63,
2232,
9,
819,
340,
570,
63,
2479,
26,
272,
2288,
5051,
63,
32259,
272,
570,
63,
2232,
275,
2050,
14,
22482,
8,
493,
63,
2479,
9,
272,
570,
63,
2232,
14,
13548,
8,
4806,
14,
5287,
9,
272,
570,
63,
2232,
14,
26076,
8,
267,
2050,
14,
7772,
8,
5045,
29342,
20056,
9,
83,
26,
2818,
1188,
9,
83,
1333,
272,
2050,
14,
5572,
1252,
18826,
8,
493,
63,
2232,
9,
272,
5051,
63,
32259,
275,
570,
63,
2479,
421,
199,
318,
6990,
1378,
2445,
8,
505,
304,
523,
340,
12348,
14607,
26,
272,
984,
14,
2703,
14,
952,
8,
505,
9,
523,
340,
5051,
63,
32259,
26,
272,
5051,
63,
32259,
14,
952,
8,
505,
9,
421,
199,
318,
2670,
2176,
8,
1531,
12,
3839,
29,
403,
12,
1011,
958,
304,
523,
408,
9871,
5434,
1414,
1072,
2166,
4079,
641,
2050,
2166,
14,
819,
982,
282,
2050,
570,
2429,
365,
663,
12,
3544,
8689,
1006,
1072,
370,
652,
14,
523,
982,
314,
943,
2166,
365,
663,
737,
3105,
503,
5117,
12,
2597,
8689,
1006,
1072,
370,
3839,
14,
523,
6630,
12,
1454,
8689,
1072,
641,
1125,
14,
523,
3033,
26,
272,
1414,
26,
5817,
370,
1255,
14,
272,
3839,
334,
4144,
304,
3814,
536,
370,
4660,
3839,
370,
14,
272,
1011,
958,
26,
6431,
1249,
14,
523,
408,
523,
8288,
275,
747,
14,
515,
14,
4832,
8,
958,
14,
362,
360,
6525,
297,
747,
14,
9458,
4059,
523,
2050,
14,
815,
360,
9602,
26,
3873,
14,
1074,
63,
1250,
4042,
82,
12,
8288,
2458,
82,
3171,
450,
334,
1531,
12,
8288,
430,
819,
340,
3839,
365,
488,
26,
272,
327,
6551,
12422,
3839,
436,
4635,
10451,
436,
943,
626,
14,
272,
299,
275,
3873,
14,
7942,
8,
1531,
12,
586,
3839,
29,
5781,
14,
6089,
12,
586,
4635,
29,
5781,
14,
13850,
12,
586,
1011,
958,
9,
272,
1072,
275,
299,
14,
2703,
523,
587,
26,
272,
299,
275,
3873,
14,
7942,
8,
1531,
12,
586,
3839,
29,
1490,
8,
2703,
12,
283,
87,
659,
586,
4635,
29,
5781,
14,
6089,
12,
586,
1011,
958,
9,
272,
1072,
275,
299,
14,
3083,
819,
327,
29828,
314,
1072,
465,
652,
12477,
436,
8689,
652,
9939,
14,
523,
1004,
275,
1072,
14,
6407,
342,
523,
1830,
1004,
26,
272,
6990,
1378,
2445,
8,
604,
9,
272,
1004,
275,
1072,
14,
6407,
342,
819,
340,
299,
14,
2573,
342,
1137,
378,
26,
272,
746,
3873,
14,
24691,
8,
1760,
29,
1531,
12,
17630,
29,
80,
14,
9913,
9,
819,
327,
11040,
2084,
3839,
880,
652,
1630,
440,
664,
1640,
274,
4292,
543,
6466,
943,
503,
21306,
523,
327,
1072,
1314,
13538,
370,
4635,
14,
523,
984,
14,
2703,
14,
4939,
342,
421,
199,
318,
2670,
2959,
8,
1531,
12,
1011,
958,
304,
523,
408,
16640,
3839,
687,
282,
1414,
12,
1830,
2050,
2399,
4635,
14,
819,
961,
365,
28891,
3873,
14,
1074,
63,
1199,
12,
1325,
4635,
365,
523,
8860,
314,
2011,
4340,
465,
315,
943,
63,
2537,
14,
1799,
2176,
14,
523,
3033,
26,
272,
1414,
26,
5817,
370,
1255,
14,
272,
1011,
958,
26,
6431,
1249,
14,
523,
408,
523,
8288,
275,
747,
14,
515,
14,
4832,
8,
958,
14,
362,
360,
6525,
297,
747,
14,
9458,
4059,
523,
2050,
14,
815,
360,
9602,
26,
3873,
14,
1074,
63,
1199,
4042,
82,
12,
8288,
2458,
82,
3171,
450,
334,
1531,
12,
8288,
430,
819,
299,
275,
3873,
14,
7942,
8,
1531,
12,
2432,
3839,
29,
5781,
14,
6089,
12,
2432,
4635,
29,
5781,
14,
6089,
12,
2432,
1011,
958,
9,
819,
327,
16269,
314,
1072,
911,
440,
506,
27791,
503,
5452,
282,
1846,
900,
370,
11492,
12,
880,
652,
523,
327,
365,
1321,
461,
370,
2951,
9451,
652,
1006,
24248,
590,
2544,
2050,
7003,
14,
523,
327,
3254,
8,
5466,
926,
28854,
304,
428,
526,
1090,
4635,
5821,
29914,
340,
626,
14433,
12237,
523,
327,
25235,
314,
394,
8387,
14,
523,
3839,
63,
505,
12,
4635,
63,
505,
275,
299,
14,
10664,
342,
819,
6990,
1378,
2445,
8,
3083,
63,
505,
9,
819,
340,
299,
14,
2573,
342,
1137,
0
] |
[
1,
1,
1,
1,
1,
1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adowsocks/crypto/sodium.py
|
1032
|
3778
|
#!/usr/bin/env python
#
# 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
from ctypes import c_char_p, c_int, c_ulonglong, byref, \
create_string_buffer, c_void_p
from shadowsocks.crypto import util
__all__ = ['ciphers']
libsodium = None
loaded = False
buf_size = 2048
# for salsa20 and chacha20
BLOCK_SIZE = 64
def load_libsodium():
global loaded, libsodium, buf
libsodium = util.find_library('sodium', 'crypto_stream_salsa20_xor_ic',
'libsodium')
if libsodium is None:
raise Exception('libsodium not found')
libsodium.crypto_stream_salsa20_xor_ic.restype = c_int
libsodium.crypto_stream_salsa20_xor_ic.argtypes = (c_void_p, c_char_p,
c_ulonglong,
c_char_p, c_ulonglong,
c_char_p)
libsodium.crypto_stream_chacha20_xor_ic.restype = c_int
libsodium.crypto_stream_chacha20_xor_ic.argtypes = (c_void_p, c_char_p,
c_ulonglong,
c_char_p, c_ulonglong,
c_char_p)
buf = create_string_buffer(buf_size)
loaded = True
class SodiumCrypto(object):
def __init__(self, cipher_name, key, iv, op):
if not loaded:
load_libsodium()
self.key = key
self.iv = iv
self.key_ptr = c_char_p(key)
self.iv_ptr = c_char_p(iv)
if cipher_name == 'salsa20':
self.cipher = libsodium.crypto_stream_salsa20_xor_ic
elif cipher_name == 'chacha20':
self.cipher = libsodium.crypto_stream_chacha20_xor_ic
else:
raise Exception('Unknown cipher')
# byte counter, not block counter
self.counter = 0
def update(self, data):
global buf_size, buf
l = len(data)
# we can only prepend some padding to make the encryption align to
# blocks
padding = self.counter % BLOCK_SIZE
if buf_size < padding + l:
buf_size = (padding + l) * 2
buf = create_string_buffer(buf_size)
if padding:
data = (b'\0' * padding) + data
self.cipher(byref(buf), c_char_p(data), padding + l,
self.iv_ptr, int(self.counter / BLOCK_SIZE), self.key_ptr)
self.counter += l
# buf is copied to a str object when we access buf.raw
# strip off the padding
return buf.raw[padding:padding + l]
ciphers = {
'salsa20': (32, 8, SodiumCrypto),
'chacha20': (32, 8, SodiumCrypto),
}
def test_salsa20():
cipher = SodiumCrypto('salsa20', b'k' * 32, b'i' * 16, 1)
decipher = SodiumCrypto('salsa20', b'k' * 32, b'i' * 16, 0)
util.run_cipher(cipher, decipher)
def test_chacha20():
cipher = SodiumCrypto('chacha20', b'k' * 32, b'i' * 16, 1)
decipher = SodiumCrypto('chacha20', b'k' * 32, b'i' * 16, 0)
util.run_cipher(cipher, decipher)
if __name__ == '__main__':
test_chacha20()
test_salsa20()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
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,
504,
5577,
492,
286,
63,
1560,
63,
80,
12,
286,
63,
442,
12,
286,
63,
32020,
12,
15968,
12,
971,
272,
1218,
63,
875,
63,
2738,
12,
286,
63,
1647,
63,
80,
199,
199,
504,
15084,
21234,
14,
10316,
492,
4884,
199,
199,
363,
452,
363,
275,
788,
27426,
418,
199,
199,
773,
1152,
12980,
275,
488,
199,
4591,
275,
756,
199,
199,
1436,
63,
890,
275,
18427,
199,
199,
3,
367,
18641,
2231,
1165,
436,
682,
1225,
65,
1165,
199,
8475,
63,
4305,
275,
5049,
421,
199,
318,
2248,
63,
773,
1152,
12980,
837,
272,
2288,
6511,
12,
1973,
1152,
12980,
12,
4123,
339,
1973,
1152,
12980,
275,
4884,
14,
1623,
63,
4342,
360,
1152,
12980,
297,
283,
10316,
63,
1745,
63,
6327,
2231,
1165,
63,
15721,
63,
530,
297,
3303,
283,
773,
1152,
12980,
358,
272,
340,
1973,
1152,
12980,
365,
488,
26,
267,
746,
2186,
360,
773,
1152,
12980,
440,
1911,
358,
339,
1973,
1152,
12980,
14,
10316,
63,
1745,
63,
6327,
2231,
1165,
63,
15721,
63,
530,
14,
9990,
275,
286,
63,
442,
272,
1973,
1152,
12980,
14,
10316,
63,
1745,
63,
6327,
2231,
1165,
63,
15721,
63,
530,
14,
10025,
275,
334,
67,
63,
1647,
63,
80,
12,
286,
63,
1560,
63,
80,
12,
10940,
286,
63,
32020,
12,
10940,
286,
63,
1560,
63,
80,
12,
286,
63,
32020,
12,
10940,
286,
63,
1560,
63,
80,
9,
272,
1973,
1152,
12980,
14,
10316,
63,
1745,
63,
335,
1225,
65,
1165,
63,
15721,
63,
530,
14,
9990,
275,
286,
63,
442,
272,
1973,
1152,
12980,
14,
10316,
63,
1745,
63,
335,
1225,
65,
1165,
63,
15721,
63,
530,
14,
10025,
275,
334,
67,
63,
1647,
63,
80,
12,
286,
63,
1560,
63,
80,
12,
9144,
286,
63,
32020,
12,
9144,
286,
63,
1560,
63,
80,
12,
286,
63,
32020,
12,
9144,
286,
63,
1560,
63,
80,
9,
339,
4123,
275,
1218,
63,
875,
63,
2738,
8,
1436,
63,
890,
9,
272,
6511,
275,
715,
421,
199,
533,
2002,
12980,
17134,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
10830,
63,
354,
12,
790,
12,
18831,
12,
1687,
304,
267,
340,
440,
6511,
26,
288,
2248,
63,
773,
1152,
12980,
342,
267,
291,
14,
498,
275,
790,
267,
291,
14,
1003,
275,
18831,
267,
291,
14,
498,
63,
4695,
275,
286,
63,
1560,
63,
80,
8,
498,
9,
267,
291,
14,
1003,
63,
4695,
275,
286,
63,
1560,
63,
80,
8,
1003,
9,
267,
340,
10830,
63,
354,
508,
283,
6327,
2231,
1165,
356,
288,
291,
14,
9231,
275,
1973,
1152,
12980,
14,
10316,
63,
1745,
63,
6327,
2231,
1165,
63,
15721,
63,
530,
267,
916,
10830,
63,
354,
508,
283,
335,
1225,
65,
1165,
356,
288,
291,
14,
9231,
275,
1973,
1152,
12980,
14,
10316,
63,
1745,
63,
335,
1225,
65,
1165,
63,
15721,
63,
530,
267,
587,
26,
288,
746,
2186,
360,
5912,
10830,
358,
267,
327,
3696,
7055,
12,
440,
1853,
7055,
267,
291,
14,
5337,
275,
378,
339,
347,
1678,
8,
277,
12,
666,
304,
267,
2288,
4123,
63,
890,
12,
4123,
267,
634,
275,
822,
8,
576,
9,
398,
327,
781,
883,
1454,
18213,
2005,
6273,
370,
1852,
314,
14396,
6998,
370,
267,
327,
5664,
267,
6273,
275,
291,
14,
5337,
450,
8068,
63,
4305,
267,
340,
4123,
63,
890,
665,
6273,
435,
634,
26,
288,
4123,
63,
890,
275,
334,
8358,
435,
634,
9,
627,
499,
288,
4123,
275,
1218,
63,
875,
63,
2738,
8,
1436,
63,
890,
9,
398,
340,
6273,
26,
288,
666,
275,
334,
66,
1154,
16,
7,
627,
6273,
9,
435,
666,
267,
291,
14,
9231,
8,
20447,
8,
1436,
395,
286,
63,
1560,
63,
80,
8,
576,
395,
6273,
435,
634,
12,
490,
291,
14,
1003,
63,
4695,
12,
1109,
8,
277,
14,
5337,
1182,
8068,
63,
4305,
395,
291,
14,
498,
63,
4695,
9,
267,
291,
14,
5337,
847,
634,
267,
327,
4123,
365,
8876,
370,
282,
620,
909,
1380,
781,
2879,
4123,
14,
1773,
267,
327,
6202,
2331,
314,
6273,
267,
372,
4123,
14,
1773,
59,
8358,
26,
8358,
435,
634,
61,
421,
199,
27426,
275,
469,
272,
283,
6327,
2231,
1165,
356,
334,
708,
12,
1695,
12,
2002,
12980,
17134,
395,
272,
283,
335,
1225,
65,
1165,
356,
334,
708,
12,
1695,
12,
2002,
12980,
17134,
395,
199,
93,
421,
199,
318,
511,
63,
6327,
2231,
1165,
837,
272,
10830,
275,
2002,
12980,
17134,
360,
6327,
2231,
1165,
297,
330,
7,
75,
7,
627,
4337,
12,
330,
7,
73,
7,
627,
3193,
12,
413,
9,
272,
477,
9231,
275,
2002,
12980,
17134,
360,
6327,
2231,
1165,
297,
330,
7,
75,
7,
627,
4337,
12,
330,
7,
73,
7,
627,
3193,
12,
378,
9,
339,
4884,
14,
1065,
63,
9231,
8,
9231,
12,
477,
9231,
9,
421,
199,
318,
511,
63,
335,
1225,
65,
1165,
837,
339,
10830,
275,
2002,
12980,
17134,
360,
335,
1225,
65,
1165,
297,
330,
7,
75,
7,
627,
4337,
12,
330,
7,
73,
7,
627,
3193,
12,
413,
9,
272,
477,
9231,
275,
2002,
12980,
17134,
360,
335,
1225,
65,
1165,
297,
330,
7,
75,
7,
627,
4337,
12
] |
[
2647,
15,
1393,
15,
1813,
2366,
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,
504,
5577,
492,
286,
63,
1560,
63,
80,
12,
286,
63,
442,
12,
286,
63,
32020,
12,
15968,
12,
971,
272,
1218,
63,
875,
63,
2738,
12,
286,
63,
1647,
63,
80,
199,
199,
504,
15084,
21234,
14,
10316,
492,
4884,
199,
199,
363,
452,
363,
275,
788,
27426,
418,
199,
199,
773,
1152,
12980,
275,
488,
199,
4591,
275,
756,
199,
199,
1436,
63,
890,
275,
18427,
199,
199,
3,
367,
18641,
2231,
1165,
436,
682,
1225,
65,
1165,
199,
8475,
63,
4305,
275,
5049,
421,
199,
318,
2248,
63,
773,
1152,
12980,
837,
272,
2288,
6511,
12,
1973,
1152,
12980,
12,
4123,
339,
1973,
1152,
12980,
275,
4884,
14,
1623,
63,
4342,
360,
1152,
12980,
297,
283,
10316,
63,
1745,
63,
6327,
2231,
1165,
63,
15721,
63,
530,
297,
3303,
283,
773,
1152,
12980,
358,
272,
340,
1973,
1152,
12980,
365,
488,
26,
267,
746,
2186,
360,
773,
1152,
12980,
440,
1911,
358,
339,
1973,
1152,
12980,
14,
10316,
63,
1745,
63,
6327,
2231,
1165,
63,
15721,
63,
530,
14,
9990,
275,
286,
63,
442,
272,
1973,
1152,
12980,
14,
10316,
63,
1745,
63,
6327,
2231,
1165,
63,
15721,
63,
530,
14,
10025,
275,
334,
67,
63,
1647,
63,
80,
12,
286,
63,
1560,
63,
80,
12,
10940,
286,
63,
32020,
12,
10940,
286,
63,
1560,
63,
80,
12,
286,
63,
32020,
12,
10940,
286,
63,
1560,
63,
80,
9,
272,
1973,
1152,
12980,
14,
10316,
63,
1745,
63,
335,
1225,
65,
1165,
63,
15721,
63,
530,
14,
9990,
275,
286,
63,
442,
272,
1973,
1152,
12980,
14,
10316,
63,
1745,
63,
335,
1225,
65,
1165,
63,
15721,
63,
530,
14,
10025,
275,
334,
67,
63,
1647,
63,
80,
12,
286,
63,
1560,
63,
80,
12,
9144,
286,
63,
32020,
12,
9144,
286,
63,
1560,
63,
80,
12,
286,
63,
32020,
12,
9144,
286,
63,
1560,
63,
80,
9,
339,
4123,
275,
1218,
63,
875,
63,
2738,
8,
1436,
63,
890,
9,
272,
6511,
275,
715,
421,
199,
533,
2002,
12980,
17134,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
10830,
63,
354,
12,
790,
12,
18831,
12,
1687,
304,
267,
340,
440,
6511,
26,
288,
2248,
63,
773,
1152,
12980,
342,
267,
291,
14,
498,
275,
790,
267,
291,
14,
1003,
275,
18831,
267,
291,
14,
498,
63,
4695,
275,
286,
63,
1560,
63,
80,
8,
498,
9,
267,
291,
14,
1003,
63,
4695,
275,
286,
63,
1560,
63,
80,
8,
1003,
9,
267,
340,
10830,
63,
354,
508,
283,
6327,
2231,
1165,
356,
288,
291,
14,
9231,
275,
1973,
1152,
12980,
14,
10316,
63,
1745,
63,
6327,
2231,
1165,
63,
15721,
63,
530,
267,
916,
10830,
63,
354,
508,
283,
335,
1225,
65,
1165,
356,
288,
291,
14,
9231,
275,
1973,
1152,
12980,
14,
10316,
63,
1745,
63,
335,
1225,
65,
1165,
63,
15721,
63,
530,
267,
587,
26,
288,
746,
2186,
360,
5912,
10830,
358,
267,
327,
3696,
7055,
12,
440,
1853,
7055,
267,
291,
14,
5337,
275,
378,
339,
347,
1678,
8,
277,
12,
666,
304,
267,
2288,
4123,
63,
890,
12,
4123,
267,
634,
275,
822,
8,
576,
9,
398,
327,
781,
883,
1454,
18213,
2005,
6273,
370,
1852,
314,
14396,
6998,
370,
267,
327,
5664,
267,
6273,
275,
291,
14,
5337,
450,
8068,
63,
4305,
267,
340,
4123,
63,
890,
665,
6273,
435,
634,
26,
288,
4123,
63,
890,
275,
334,
8358,
435,
634,
9,
627,
499,
288,
4123,
275,
1218,
63,
875,
63,
2738,
8,
1436,
63,
890,
9,
398,
340,
6273,
26,
288,
666,
275,
334,
66,
1154,
16,
7,
627,
6273,
9,
435,
666,
267,
291,
14,
9231,
8,
20447,
8,
1436,
395,
286,
63,
1560,
63,
80,
8,
576,
395,
6273,
435,
634,
12,
490,
291,
14,
1003,
63,
4695,
12,
1109,
8,
277,
14,
5337,
1182,
8068,
63,
4305,
395,
291,
14,
498,
63,
4695,
9,
267,
291,
14,
5337,
847,
634,
267,
327,
4123,
365,
8876,
370,
282,
620,
909,
1380,
781,
2879,
4123,
14,
1773,
267,
327,
6202,
2331,
314,
6273,
267,
372,
4123,
14,
1773,
59,
8358,
26,
8358,
435,
634,
61,
421,
199,
27426,
275,
469,
272,
283,
6327,
2231,
1165,
356,
334,
708,
12,
1695,
12,
2002,
12980,
17134,
395,
272,
283,
335,
1225,
65,
1165,
356,
334,
708,
12,
1695,
12,
2002,
12980,
17134,
395,
199,
93,
421,
199,
318,
511,
63,
6327,
2231,
1165,
837,
272,
10830,
275,
2002,
12980,
17134,
360,
6327,
2231,
1165,
297,
330,
7,
75,
7,
627,
4337,
12,
330,
7,
73,
7,
627,
3193,
12,
413,
9,
272,
477,
9231,
275,
2002,
12980,
17134,
360,
6327,
2231,
1165,
297,
330,
7,
75,
7,
627,
4337,
12,
330,
7,
73,
7,
627,
3193,
12,
378,
9,
339,
4884,
14,
1065,
63,
9231,
8,
9231,
12,
477,
9231,
9,
421,
199,
318,
511,
63,
335,
1225,
65,
1165,
837,
339,
10830,
275,
2002,
12980,
17134,
360,
335,
1225,
65,
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
] |
mhbu50/frappe
|
frappe/patches/v5_2/change_checks_to_not_null.py
|
58
|
1267
|
from __future__ import unicode_literals
import frappe
from frappe.utils import cint
from frappe.model import default_fields
def execute():
for table in frappe.db.get_tables():
doctype = table[3:]
if frappe.db.exists("DocType", doctype):
fieldnames = [df["fieldname"] for df in
frappe.get_all("DocField", fields=["fieldname"], filters={"parent": doctype})]
custom_fieldnames = [df["fieldname"] for df in
frappe.get_all("Custom Field", fields=["fieldname"], filters={"dt": doctype})]
else:
fieldnames = custom_fieldnames = []
for column in frappe.db.sql("""desc `{0}`""".format(table), as_dict=True):
if column["Type"]=="int(1)":
fieldname = column["Field"]
# only change for defined fields, ignore old fields that don't exist in meta
if not (fieldname in default_fields or fieldname in fieldnames or fieldname in custom_fieldnames):
continue
# set 0
frappe.db.sql("""update `{table}` set `{column}`=0 where `{column}` is null"""\
.format(table=table, column=fieldname))
frappe.db.commit()
# change definition
frappe.db.sql_ddl("""alter table `{table}`
modify `{column}` int(1) not null default {default}"""\
.format(table=table, column=fieldname, default=cint(column["Default"])))
|
mit
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
14,
1208,
492,
286,
442,
199,
504,
6950,
14,
1238,
492,
849,
63,
955,
199,
199,
318,
5341,
837,
199,
198,
509,
1817,
315,
6950,
14,
697,
14,
362,
63,
5987,
837,
507,
198,
6356,
275,
1817,
59,
19,
2938,
507,
198,
692,
6950,
14,
697,
14,
2444,
480,
3768,
804,
401,
13265,
304,
686,
198,
698,
1247,
275,
359,
1587,
905,
13646,
937,
367,
4051,
315,
1585,
198,
9098,
14,
362,
63,
452,
480,
3768,
792,
401,
1504,
6270,
13646,
2255,
4766,
8871,
1708,
582,
13265,
1552,
61,
686,
198,
4229,
63,
698,
1247,
275,
359,
1587,
905,
13646,
937,
367,
4051,
315,
1585,
198,
9098,
14,
362,
63,
452,
480,
7223,
5024,
401,
1504,
6270,
13646,
2255,
4766,
8871,
3583,
582,
13265,
1552,
61,
2742,
198,
2836,
26,
686,
198,
698,
1247,
275,
3537,
63,
698,
1247,
275,
942,
2742,
198,
509,
2763,
315,
6950,
14,
697,
14,
3009,
4852,
3257,
658,
91,
16,
23485,
23045,
908,
8,
1224,
395,
465,
63,
807,
29,
549,
304,
686,
198,
692,
2763,
905,
804,
937,
11800,
442,
8,
17,
9,
582,
1585,
198,
13646,
275,
2763,
905,
792,
937,
16737,
198,
3,
1454,
1570,
367,
3247,
1504,
12,
3686,
2269,
1504,
626,
2793,
1133,
2187,
315,
3404,
1585,
198,
692,
440,
334,
13646,
315,
849,
63,
955,
503,
18887,
315,
901,
1247,
503,
18887,
315,
3537,
63,
698,
1247,
304,
1871,
198,
6958,
16737,
198,
3,
663,
378,
1585,
198,
9098,
14,
697,
14,
3009,
4852,
873,
658,
91,
1224,
23485,
663,
658,
91,
2301,
23485,
29,
16,
2382,
658,
91,
2301,
23485,
365,
2973,
19659,
1871,
198,
14,
908,
8,
1224,
29,
1224,
12,
2763,
29,
13646,
430,
1585,
198,
9098,
14,
697,
14,
3543,
342,
16737,
198,
3,
1570,
5492,
1585,
198,
9098,
14,
697,
14,
3009,
63,
17102,
4852,
11858,
1817,
658,
91,
1224,
23485,
1871,
198,
8951,
658,
91,
2301,
23485,
1109,
8,
17,
9,
440,
2973,
849,
469,
885,
93,
19659,
1871,
198,
14,
908,
8,
1224,
29,
1224,
12,
2763,
29,
13646,
12,
849,
29,
67,
442,
8,
2301,
905,
2698,
937,
1724,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
646,
6950,
199,
504,
6950,
14,
1208,
492,
286,
442,
199,
504,
6950,
14,
1238,
492,
849,
63,
955,
199,
199,
318,
5341,
837,
199,
198,
509,
1817,
315,
6950,
14,
697,
14,
362,
63,
5987,
837,
507,
198,
6356,
275,
1817,
59,
19,
2938,
507,
198,
692,
6950,
14,
697,
14,
2444,
480,
3768,
804,
401,
13265,
304,
686,
198,
698,
1247,
275,
359,
1587,
905,
13646,
937,
367,
4051,
315,
1585,
198,
9098,
14,
362,
63,
452,
480,
3768,
792,
401,
1504,
6270,
13646,
2255,
4766,
8871,
1708,
582,
13265,
1552,
61,
686,
198,
4229,
63,
698,
1247,
275,
359,
1587,
905,
13646,
937,
367,
4051,
315,
1585,
198,
9098,
14,
362,
63,
452,
480,
7223,
5024,
401,
1504,
6270,
13646,
2255,
4766,
8871,
3583,
582,
13265,
1552,
61,
2742,
198,
2836,
26,
686,
198,
698,
1247,
275,
3537,
63,
698,
1247,
275,
942,
2742,
198,
509,
2763,
315,
6950,
14,
697,
14,
3009,
4852,
3257,
658,
91,
16,
23485,
23045,
908,
8,
1224,
395,
465,
63,
807,
29,
549,
304,
686,
198,
692,
2763,
905,
804,
937,
11800,
442,
8,
17,
9,
582,
1585,
198,
13646,
275,
2763,
905,
792,
937,
16737,
198,
3,
1454,
1570,
367,
3247,
1504,
12,
3686,
2269,
1504,
626,
2793,
1133,
2187,
315,
3404,
1585,
198,
692,
440,
334,
13646,
315,
849,
63,
955,
503,
18887,
315,
901,
1247,
503,
18887,
315,
3537,
63,
698,
1247,
304,
1871,
198,
6958,
16737,
198,
3,
663,
378,
1585,
198,
9098,
14,
697,
14,
3009,
4852,
873,
658,
91,
1224,
23485,
663,
658,
91,
2301,
23485,
29,
16,
2382,
658,
91,
2301,
23485,
365,
2973,
19659,
1871,
198,
14,
908,
8,
1224,
29,
1224,
12,
2763,
29,
13646,
430,
1585,
198,
9098,
14,
697,
14,
3543,
342,
16737,
198,
3,
1570,
5492,
1585,
198,
9098,
14,
697,
14,
3009,
63,
17102,
4852,
11858,
1817,
658,
91,
1224,
23485,
1871,
198,
8951,
658,
91,
2301,
23485,
1109,
8,
17,
9,
440,
2973,
849,
469,
885,
93,
19659,
1871,
198,
14,
908,
8,
1224,
29,
1224,
12,
2763,
29,
13646,
12,
849,
29,
67,
442,
8,
2301,
905,
2698,
937,
1724,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
napalm-automation/napalm-base
|
napalm_base/clitools/cl_napalm_validate.py
|
2
|
1376
|
# -*- coding: utf-8 -*-
'''
NAPALM CLI Tools: validate
===========================
Validating deployments from the shell.
'''
# Python3 support
from __future__ import print_function
from __future__ import unicode_literals
# import helpers
from napalm_base import get_network_driver
from napalm_base.clitools.helpers import build_help
from napalm_base.clitools.helpers import configure_logging
from napalm_base.clitools.helpers import parse_optional_args
from napalm_base.clitools.helpers import warning
# stdlib
import sys
import json
import logging
logger = logging.getLogger('cl_napalm_validate.py')
warning()
def main():
args = build_help(validate=True)
configure_logging(logger, args.debug)
logger.debug('Getting driver for OS "{driver}"'.format(driver=args.vendor))
driver = get_network_driver(args.vendor)
optional_args = parse_optional_args(args.optional_args)
logger.debug('Connecting to device "{}" with user "{}" and optional_args={}'.format(
args.hostname, args.user, optional_args))
with driver(args.hostname, args.user, args.password, optional_args=optional_args) as device:
logger.debug('Generating compliance report')
print(json.dumps(device.compliance_report(args.validation_file), indent=4))
logger.debug('Closing session')
sys.exit(0)
if __name__ == '__main__':
main()
|
apache-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
2344,
199,
46,
1282,
748,
45,
14214,
23228,
26,
4107,
199,
1280,
21326,
199,
199,
3490,
1958,
12287,
1470,
687,
314,
5218,
14,
199,
2344,
199,
199,
3,
2018,
19,
2291,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
3,
492,
10897,
199,
504,
302,
439,
279,
77,
63,
1095,
492,
664,
63,
1200,
63,
3090,
199,
504,
302,
439,
279,
77,
63,
1095,
14,
2764,
2537,
14,
7546,
492,
1900,
63,
3437,
199,
504,
302,
439,
279,
77,
63,
1095,
14,
2764,
2537,
14,
7546,
492,
7908,
63,
4806,
199,
504,
302,
439,
279,
77,
63,
1095,
14,
2764,
2537,
14,
7546,
492,
2198,
63,
4144,
63,
589,
199,
504,
302,
439,
279,
77,
63,
1095,
14,
2764,
2537,
14,
7546,
492,
5721,
199,
199,
3,
26678,
199,
646,
984,
199,
646,
2022,
199,
646,
2050,
199,
199,
2921,
275,
2050,
14,
5572,
360,
429,
63,
2542,
279,
77,
63,
3502,
14,
647,
358,
199,
3764,
342,
421,
199,
318,
2446,
837,
272,
1249,
275,
1900,
63,
3437,
8,
3502,
29,
549,
9,
272,
7908,
63,
4806,
8,
2921,
12,
1249,
14,
1757,
9,
339,
2512,
14,
1757,
360,
28277,
5253,
367,
4403,
5310,
3090,
7063,
1370,
908,
8,
3090,
29,
589,
14,
9884,
430,
272,
5253,
275,
664,
63,
1200,
63,
3090,
8,
589,
14,
9884,
9,
339,
2716,
63,
589,
275,
2198,
63,
4144,
63,
589,
8,
589,
14,
4144,
63,
589,
9,
272,
2512,
14,
1757,
360,
32000,
370,
2243,
28168,
543,
922,
28168,
436,
2716,
63,
589,
27244,
908,
8,
326,
1249,
14,
4269,
12,
1249,
14,
751,
12,
2716,
63,
589,
430,
339,
543,
5253,
8,
589,
14,
4269,
12,
1249,
14,
751,
12,
1249,
14,
2060,
12,
2716,
63,
589,
29,
4144,
63,
589,
9,
465,
2243,
26,
267,
2512,
14,
1757,
360,
29244,
4151,
3622,
358,
267,
870,
8,
1001,
14,
4180,
8,
1782,
14,
863,
3636,
63,
3070,
8,
589,
14,
6136,
63,
493,
395,
4363,
29,
20,
430,
267,
2512,
14,
1757,
360,
18433,
2351,
358,
272,
984,
14,
2224,
8,
16,
9,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
2344,
199,
46,
1282,
748,
45,
14214,
23228,
26,
4107,
199,
1280,
21326,
199,
199,
3490,
1958,
12287,
1470,
687,
314,
5218,
14,
199,
2344,
199,
199,
3,
2018,
19,
2291,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
3,
492,
10897,
199,
504,
302,
439,
279,
77,
63,
1095,
492,
664,
63,
1200,
63,
3090,
199,
504,
302,
439,
279,
77,
63,
1095,
14,
2764,
2537,
14,
7546,
492,
1900,
63,
3437,
199,
504,
302,
439,
279,
77,
63,
1095,
14,
2764,
2537,
14,
7546,
492,
7908,
63,
4806,
199,
504,
302,
439,
279,
77,
63,
1095,
14,
2764,
2537,
14,
7546,
492,
2198,
63,
4144,
63,
589,
199,
504,
302,
439,
279,
77,
63,
1095,
14,
2764,
2537,
14,
7546,
492,
5721,
199,
199,
3,
26678,
199,
646,
984,
199,
646,
2022,
199,
646,
2050,
199,
199,
2921,
275,
2050,
14,
5572,
360,
429,
63,
2542,
279,
77,
63,
3502,
14,
647,
358,
199,
3764,
342,
421,
199,
318,
2446,
837,
272,
1249,
275,
1900,
63,
3437,
8,
3502,
29,
549,
9,
272,
7908,
63,
4806,
8,
2921,
12,
1249,
14,
1757,
9,
339,
2512,
14,
1757,
360,
28277,
5253,
367,
4403,
5310,
3090,
7063,
1370,
908,
8,
3090,
29,
589,
14,
9884,
430,
272,
5253,
275,
664,
63,
1200,
63,
3090,
8,
589,
14,
9884,
9,
339,
2716,
63,
589,
275,
2198,
63,
4144,
63,
589,
8,
589,
14,
4144,
63,
589,
9,
272,
2512,
14,
1757,
360,
32000,
370,
2243,
28168,
543,
922,
28168,
436,
2716,
63,
589,
27244,
908,
8,
326,
1249,
14,
4269,
12,
1249,
14,
751,
12,
2716,
63,
589,
430,
339,
543,
5253,
8,
589,
14,
4269,
12,
1249,
14,
751,
12,
1249,
14,
2060,
12,
2716,
63,
589,
29,
4144,
63,
589,
9,
465,
2243,
26,
267,
2512,
14,
1757,
360,
29244,
4151,
3622,
358,
267,
870,
8,
1001,
14,
4180,
8,
1782,
14,
863,
3636,
63,
3070,
8,
589,
14,
6136,
63,
493,
395,
4363,
29,
20,
430,
267,
2512,
14,
1757,
360,
18433,
2351,
358,
272,
984,
14,
2224,
8,
16,
9,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
dbbhattacharya/kitsune
|
vendor/packages/selenium/py/selenium/webdriver/support/select.py
|
44
|
8366
|
#!/usr/bin/python
#
# Copyright 2011 Software Freedom Conservancy.
#
# 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 selenium.webdriver.common.by import By
from selenium.common.exceptions import NoSuchElementException, UnexpectedTagNameException
class Select:
def __init__(self, webelement):
"""
Constructor. A check is made that the given element is, indeed, a SELECT tag. If it is not,
then an UnexpectedTagNameException is thrown.
:Args:
- webelement - element SELECT element to wrap
Example:
from selenium.webdriver.support.ui import Select \n
Select(driver.find_element_by_tag_name("select")).select_by_index(2)
"""
if webelement.tag_name.lower() != "select":
raise UnexpectedTagNameException(
"Select only works on <select> elements, not on <%s>" %
webelement.tag_name)
self._el = webelement
multi = self._el.get_attribute("multiple")
self.is_multiple = multi and multi != "false"
@property
def options(self):
"""Returns a list of all options belonging to this select tag"""
return self._el.find_elements(By.TAG_NAME, 'option')
@property
def all_selected_options(self):
"""Returns a list of all selected options belonging to this select tag"""
ret = []
for opt in self.options:
if opt.is_selected():
ret.append(opt)
return ret
@property
def first_selected_option(self):
"""The first selected option in this select tag (or the currently selected option in a
normal select)"""
for opt in self.options:
if opt.is_selected():
return opt
raise NoSuchElementException("No options are selected")
def select_by_value(self, value):
"""Select all options that have a value matching the argument. That is, when given "foo" this
would select an option like:
<option value="foo">Bar</option>
:Args:
- value - The value to match against
"""
css = "option[value =%s]" % self._escapeString(value)
opts = self._el.find_elements(By.CSS_SELECTOR, css)
matched = False
for opt in opts:
self._setSelected(opt)
if not self.is_multiple:
return
matched = True
if not matched:
raise NoSuchElementException("Cannot locate option with value: %s" % value)
def select_by_index(self, index):
"""Select the option at the given index. This is done by examing the "index" attribute of an
element, and not merely by counting.
:Args:
- index - The option at this index will be selected
"""
match = str(index)
matched = False
for opt in self.options:
if opt.get_attribute("index") == match:
self._setSelected(opt)
if not self.is_multiple:
return
matched = True
if not matched:
raise NoSuchElementException("Could not locate element with index %d" % index)
def select_by_visible_text(self, text):
"""Select all options that display text matching the argument. That is, when given "Bar" this
would select an option like:
<option value="foo">Bar</option>
:Args:
- text - The visible text to match against
"""
xpath = ".//option[normalize-space(.) = %s]" % self._escapeString(text)
opts = self._el.find_elements(By.XPATH, xpath)
matched = False
for opt in opts:
self._setSelected(opt)
if not self.is_multiple:
return
matched = True
if len(opts) == 0 and " " in text:
subStringWithoutSpace = self._get_longest_token(text)
if subStringWithoutSpace == "":
candidates = self.options
else:
xpath = ".//option[contains(.,%s)]" % self._escapeString(subStringWithoutSpace)
candidates = self._el.find_elements(By.XPATH, xpath)
for candidate in candidates:
if text == candidate.text:
self._setSelected(candidate)
if not self.is_multiple:
return
matched = True
if matched != True:
raise NoSuchElementException("Could not locate element with visible text: %s" % text)
def deselect_all(self):
"""Clear all selected entries. This is only valid when the SELECT supports multiple selections.
throws NotImplementedError If the SELECT does not support multiple selections
"""
if not self.is_multiple:
raise NotImplementedError("You may only deselect all options of a multi-select")
for opt in self.options:
self._unsetSelected(opt)
def deselect_by_value(self, value):
"""Deselect all options that have a value matching the argument. That is, when given "foo" this
would deselect an option like:
<option value="foo">Bar</option>
:Args:
- value - The value to match against
"""
if not self.is_multiple:
raise NotImplementedError("You may only deselect options of a multi-select")
css = "option[value = %s]" % self._escapeString(value)
opts = self._el.find_elements(By.CSS_SELECTOR, css)
for opt in opts:
self._unsetSelected(opt)
def deselect_by_index(self, index):
"""Deselect the option at the given index. This is done by examing the "index" attribute of an
element, and not merely by counting.
:Args:
- index - The option at this index will be deselected
"""
if not self.is_multiple:
raise NotImplementedError("You may only deselect options of a multi-select")
for opt in self.options:
if opt.get_attribute("index") == str(index):
self._unsetSelected(opt)
def deselect_by_visible_text(self, text):
"""Deselect all options that display text matching the argument. That is, when given "Bar" this
would deselect an option like:
<option value="foo">Bar</option>
:Args:
- text - The visible text to match against
"""
if not self.is_multiple:
raise NotImplementedError("You may only deselect options of a multi-select")
xpath = ".//option[normalize-space(.) = %s]" % self._escapeString(text)
opts = self._el.find_elements(By.XPATH, xpath)
for opt in opts:
self._unsetSelected(opt)
def _setSelected(self, option):
if not option.is_selected():
option.click()
def _unsetSelected(self, option):
if option.is_selected():
option.click()
def _escapeString(self, value):
if '"' in value and "'" in value:
substrings = value.split("\"")
result = ["concat("]
for substring in substrings:
result.append("\"%s\"" % substring)
result.append(", '\"', ")
result = result[0:-1]
if value.endswith('"'):
result.append(", '\"'")
return "".join(result) + ")"
if '"' in value:
return "'%s'" % value
return "\"%s\"" % value
def _get_longest_token(self, value):
items = value.split(" ")
longest = ""
for item in items:
if len(item) > len(longest):
longest = item
return longest
|
bsd-3-clause
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
7760,
2290,
481,
3798,
676,
1448,
7297,
9844,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
19481,
14,
17946,
14,
2330,
14,
991,
492,
4885,
199,
504,
19481,
14,
2330,
14,
3924,
492,
23798,
2162,
1726,
12,
25345,
12902,
1726,
199,
199,
533,
9496,
26,
339,
347,
636,
826,
721,
277,
12,
781,
1235,
968,
304,
267,
408,
267,
20297,
14,
437,
1104,
365,
6326,
626,
314,
1627,
1819,
365,
12,
31043,
379,
12,
282,
10468,
1947,
14,
982,
652,
365,
440,
12,
267,
2066,
376,
25345,
12902,
1726,
365,
14031,
14,
398,
520,
6213,
26,
268,
446,
781,
1235,
968,
446,
1819,
10468,
1819,
370,
4816,
2728,
5679,
26,
288,
687,
19481,
14,
17946,
14,
4058,
14,
1907,
492,
9496,
971,
78,
288,
9496,
8,
3090,
14,
1623,
63,
2108,
63,
991,
63,
1450,
63,
354,
480,
2416,
21688,
2416,
63,
991,
63,
1080,
8,
18,
9,
267,
408,
267,
340,
781,
1235,
968,
14,
1450,
63,
354,
14,
2325,
342,
1137,
298,
2416,
582,
288,
746,
25345,
12902,
1726,
8,
355,
298,
5446,
1454,
5419,
641,
665,
2416,
30,
4008,
12,
440,
641,
21808,
83,
4335,
450,
8892,
781,
1235,
968,
14,
1450,
63,
354,
9,
267,
291,
423,
352,
275,
781,
1235,
968,
267,
3510,
275,
291,
423,
352,
14,
362,
63,
3215,
480,
6048,
531,
267,
291,
14,
374,
63,
6048,
275,
3510,
436,
3510,
1137,
298,
3910,
2,
339,
768,
1829,
272,
347,
1511,
8,
277,
304,
267,
408,
3407,
282,
769,
402,
1006,
1511,
30226,
370,
642,
3504,
1947,
624,
267,
372,
291,
423,
352,
14,
1623,
63,
5527,
8,
2175,
14,
6967,
63,
2339,
12,
283,
1422,
358,
5493,
768,
1829,
272,
347,
1006,
63,
5511,
63,
1419,
8,
277,
304,
267,
408,
3407,
282,
769,
402,
1006,
4895,
1511,
30226,
370,
642,
3504,
1947,
624,
267,
2203,
275,
942,
267,
367,
2450,
315,
291,
14,
1419,
26,
288,
340,
2450,
14,
374,
63,
5511,
837,
355,
2203,
14,
740,
8,
2992,
9,
267,
372,
2203,
339,
768,
1829,
272,
347,
1642,
63,
5511,
63,
1422,
8,
277,
304,
267,
408,
1918,
1642,
4895,
945,
315,
642,
3504,
1947,
334,
269,
314,
5544,
4895,
945,
315,
282,
267,
3293,
3504,
9471,
267,
367,
2450,
315,
291,
14,
1419,
26,
288,
340,
2450,
14,
374,
63,
5511,
837,
355,
372,
2450,
267,
746,
23798,
2162,
1726,
480,
1944,
1511,
787,
4895,
531,
339,
347,
3504,
63,
991,
63,
585,
8,
277,
12,
574,
304,
267,
408,
5446,
1006,
1511,
626,
1172,
282,
574,
4877,
314,
1423,
14,
10314,
365,
12,
1380,
1627,
298,
1421,
2,
642,
1779,
3955,
3504,
376,
945,
2839,
26,
13596,
665,
1422,
574,
628,
1421,
1743,
5281,
1108,
1422,
30,
13596,
520,
6213,
26,
288,
446,
574,
446,
710,
574,
370,
1336,
6169,
1779,
408,
267,
11431,
275,
298,
1422,
59,
585,
275,
5,
83,
8480,
450,
291,
423,
3765,
1558,
8,
585,
9,
267,
3999,
275,
291,
423,
352,
14,
1623,
63,
5527,
8,
2175,
14,
14391,
63,
25691,
12,
11431,
9,
267,
7838,
275,
756,
267,
367,
2450,
315,
3999,
26,
288,
291,
423,
409,
12461,
8,
2992,
9,
288,
340,
440,
291,
14,
374,
63,
6048,
26,
355,
372,
288,
7838,
275,
715,
267,
340,
440,
7838,
26,
288,
746,
23798,
2162,
1726,
480,
6612,
16592,
945,
543,
574,
26,
450,
83,
2,
450,
574,
9,
339,
347,
3504,
63,
991,
63,
1080,
8,
277,
12,
1478,
304,
267,
408,
5446,
314,
945,
737,
314,
1627,
1478,
14,
961,
365,
4224,
701,
444,
9568,
314,
298,
1080,
2,
2225,
402,
376,
1779,
1819,
12,
436,
440,
562,
264,
590,
701,
23190,
14,
13596,
520,
6213,
26,
288,
446,
1478,
446,
710,
945,
737,
642,
1478,
911,
506,
4895,
221,
1779,
408,
267,
1336,
275,
620,
8,
1080,
9,
267,
7838,
275,
756,
267,
367,
2450,
315,
291,
14,
1419,
26,
288,
340,
2450,
14,
362,
63,
3215,
480,
1080,
531,
508,
1336,
26,
355,
291,
423,
409,
12461,
8,
2992,
9,
355,
340,
440,
291,
14,
374,
63,
6048,
26,
490,
372,
355,
7838,
275,
715,
267,
340,
440,
7838,
26,
288,
746,
23798,
2162,
1726,
480,
6531,
440,
16592,
1819,
543,
1478,
450,
68,
2,
450,
1478,
9,
339,
347,
3504,
63,
991,
63,
6604,
63,
505,
8,
277,
12,
1318,
304,
267,
408,
5446,
1006,
1511,
626,
2929,
1318,
4877,
314,
1423,
14,
10314,
365,
12,
1380,
1627,
298,
5281,
2,
642,
1779,
3955,
3504,
376,
945,
2839,
26,
1598,
288,
665,
1422,
574,
628,
1421,
1743,
5281,
1108,
1422,
30,
1598,
1779,
520,
6213,
26,
288,
446,
1318,
446,
710,
8917,
1318,
370,
1336,
6169,
1779,
408,
267,
14462,
275,
3680,
501,
1422,
59,
7721,
13,
2638,
8,
4959,
275,
450,
83,
8480,
450,
291,
423,
3765,
1558,
8,
505,
9,
267,
3999,
275,
291,
423,
352,
14,
1623,
63,
5527,
8,
2175,
14,
56,
3243,
12,
14462,
9,
267,
7838,
275,
756,
267,
367,
2450,
315,
3999,
26,
288,
291,
423,
409,
12461,
8,
2992,
9,
288,
340,
440,
291,
14,
374,
63,
6048,
26,
355,
372,
288,
7838,
275,
715,
398,
340,
822,
8,
3291,
9,
508,
378,
436,
298,
298,
315,
1318,
26,
288,
1007,
1558,
12450,
7643,
275,
291,
423,
362,
63,
20820,
63,
1418,
8,
505,
9,
288,
340,
1007,
1558,
12450,
7643,
508,
10812
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
7760,
2290,
481,
3798,
676,
1448,
7297,
9844,
14,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
504,
19481,
14,
17946,
14,
2330,
14,
991,
492,
4885,
199,
504,
19481,
14,
2330,
14,
3924,
492,
23798,
2162,
1726,
12,
25345,
12902,
1726,
199,
199,
533,
9496,
26,
339,
347,
636,
826,
721,
277,
12,
781,
1235,
968,
304,
267,
408,
267,
20297,
14,
437,
1104,
365,
6326,
626,
314,
1627,
1819,
365,
12,
31043,
379,
12,
282,
10468,
1947,
14,
982,
652,
365,
440,
12,
267,
2066,
376,
25345,
12902,
1726,
365,
14031,
14,
398,
520,
6213,
26,
268,
446,
781,
1235,
968,
446,
1819,
10468,
1819,
370,
4816,
2728,
5679,
26,
288,
687,
19481,
14,
17946,
14,
4058,
14,
1907,
492,
9496,
971,
78,
288,
9496,
8,
3090,
14,
1623,
63,
2108,
63,
991,
63,
1450,
63,
354,
480,
2416,
21688,
2416,
63,
991,
63,
1080,
8,
18,
9,
267,
408,
267,
340,
781,
1235,
968,
14,
1450,
63,
354,
14,
2325,
342,
1137,
298,
2416,
582,
288,
746,
25345,
12902,
1726,
8,
355,
298,
5446,
1454,
5419,
641,
665,
2416,
30,
4008,
12,
440,
641,
21808,
83,
4335,
450,
8892,
781,
1235,
968,
14,
1450,
63,
354,
9,
267,
291,
423,
352,
275,
781,
1235,
968,
267,
3510,
275,
291,
423,
352,
14,
362,
63,
3215,
480,
6048,
531,
267,
291,
14,
374,
63,
6048,
275,
3510,
436,
3510,
1137,
298,
3910,
2,
339,
768,
1829,
272,
347,
1511,
8,
277,
304,
267,
408,
3407,
282,
769,
402,
1006,
1511,
30226,
370,
642,
3504,
1947,
624,
267,
372,
291,
423,
352,
14,
1623,
63,
5527,
8,
2175,
14,
6967,
63,
2339,
12,
283,
1422,
358,
5493,
768,
1829,
272,
347,
1006,
63,
5511,
63,
1419,
8,
277,
304,
267,
408,
3407,
282,
769,
402,
1006,
4895,
1511,
30226,
370,
642,
3504,
1947,
624,
267,
2203,
275,
942,
267,
367,
2450,
315,
291,
14,
1419,
26,
288,
340,
2450,
14,
374,
63,
5511,
837,
355,
2203,
14,
740,
8,
2992,
9,
267,
372,
2203,
339,
768,
1829,
272,
347,
1642,
63,
5511,
63,
1422,
8,
277,
304,
267,
408,
1918,
1642,
4895,
945,
315,
642,
3504,
1947,
334,
269,
314,
5544,
4895,
945,
315,
282,
267,
3293,
3504,
9471,
267,
367,
2450,
315,
291,
14,
1419,
26,
288,
340,
2450,
14,
374,
63,
5511,
837,
355,
372,
2450,
267,
746,
23798,
2162,
1726,
480,
1944,
1511,
787,
4895,
531,
339,
347,
3504,
63,
991,
63,
585,
8,
277,
12,
574,
304,
267,
408,
5446,
1006,
1511,
626,
1172,
282,
574,
4877,
314,
1423,
14,
10314,
365,
12,
1380,
1627,
298,
1421,
2,
642,
1779,
3955,
3504,
376,
945,
2839,
26,
13596,
665,
1422,
574,
628,
1421,
1743,
5281,
1108,
1422,
30,
13596,
520,
6213,
26,
288,
446,
574,
446,
710,
574,
370,
1336,
6169,
1779,
408,
267,
11431,
275,
298,
1422,
59,
585,
275,
5,
83,
8480,
450,
291,
423,
3765,
1558,
8,
585,
9,
267,
3999,
275,
291,
423,
352,
14,
1623,
63,
5527,
8,
2175,
14,
14391,
63,
25691,
12,
11431,
9,
267,
7838,
275,
756,
267,
367,
2450,
315,
3999,
26,
288,
291,
423,
409,
12461,
8,
2992,
9,
288,
340,
440,
291,
14,
374,
63,
6048,
26,
355,
372,
288,
7838,
275,
715,
267,
340,
440,
7838,
26,
288,
746,
23798,
2162,
1726,
480,
6612,
16592,
945,
543,
574,
26,
450,
83,
2,
450,
574,
9,
339,
347,
3504,
63,
991,
63,
1080,
8,
277,
12,
1478,
304,
267,
408,
5446,
314,
945,
737,
314,
1627,
1478,
14,
961,
365,
4224,
701,
444,
9568,
314,
298,
1080,
2,
2225,
402,
376,
1779,
1819,
12,
436,
440,
562,
264,
590,
701,
23190,
14,
13596,
520,
6213,
26,
288,
446,
1478,
446,
710,
945,
737,
642,
1478,
911,
506,
4895,
221,
1779,
408,
267,
1336,
275,
620,
8,
1080,
9,
267,
7838,
275,
756,
267,
367,
2450,
315,
291,
14,
1419,
26,
288,
340,
2450,
14,
362,
63,
3215,
480,
1080,
531,
508,
1336,
26,
355,
291,
423,
409,
12461,
8,
2992,
9,
355,
340,
440,
291,
14,
374,
63,
6048,
26,
490,
372,
355,
7838,
275,
715,
267,
340,
440,
7838,
26,
288,
746,
23798,
2162,
1726,
480,
6531,
440,
16592,
1819,
543,
1478,
450,
68,
2,
450,
1478,
9,
339,
347,
3504,
63,
991,
63,
6604,
63,
505,
8,
277,
12,
1318,
304,
267,
408,
5446,
1006,
1511,
626,
2929,
1318,
4877,
314,
1423,
14,
10314,
365,
12,
1380,
1627,
298,
5281,
2,
642,
1779,
3955,
3504,
376,
945,
2839,
26,
1598,
288,
665,
1422,
574,
628,
1421,
1743,
5281,
1108,
1422,
30,
1598,
1779,
520,
6213,
26,
288,
446,
1318,
446,
710,
8917,
1318,
370,
1336,
6169,
1779,
408,
267,
14462,
275,
3680,
501,
1422,
59,
7721,
13,
2638,
8,
4959,
275,
450,
83,
8480,
450,
291,
423,
3765,
1558,
8,
505,
9,
267,
3999,
275,
291,
423,
352,
14,
1623,
63,
5527,
8,
2175,
14,
56,
3243,
12,
14462,
9,
267,
7838,
275,
756,
267,
367,
2450,
315,
3999,
26,
288,
291,
423,
409,
12461,
8,
2992,
9,
288,
340,
440,
291,
14,
374,
63,
6048,
26,
355,
372,
288,
7838,
275,
715,
398,
340,
822,
8,
3291,
9,
508,
378,
436,
298,
298,
315,
1318,
26,
288,
1007,
1558,
12450,
7643,
275,
291,
423,
362,
63,
20820,
63,
1418,
8,
505,
9,
288,
340,
1007,
1558,
12450,
7643,
508,
10812,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
bksim/chinese-translation
|
nltk/sem/relextract.py
|
5
|
14650
|
# Natural Language Toolkit: Relation Extraction
#
# Copyright (C) 2001-2012 NLTK Project
# Author: Ewan Klein <ewan@inf.ed.ac.uk>
# URL: <http://www.nltk.org/>
# For license information, see LICENSE.TXT
"""
Code for extracting relational triples from the ieer and conll2002 corpora.
Relations are stored internally as dictionaries ('reldicts').
The two serialization outputs are "rtuple" and "clause".
- An rtuple is a tuple of the form ``(subj, filler, obj)``,
where ``subj`` and ``obj`` are pairs of Named Entity mentions, and ``filler`` is the string of words
occurring between ``sub`` and ``obj`` (with no intervening NEs). Strings are printed via ``repr()`` to
circumvent locale variations in rendering utf-8 encoded strings.
- A clause is an atom of the form ``relsym(subjsym, objsym)``,
where the relation, subject and object have been canonicalized to single strings.
"""
# todo: get a more general solution to canonicalized symbols for clauses -- maybe use xmlcharrefs?
from __future__ import print_function
from collections import defaultdict
from string import join
import re
import htmlentitydefs
from itertools import ifilter
# Dictionary that associates corpora with NE classes
NE_CLASSES = {
'ieer': ['LOCATION', 'ORGANIZATION', 'PERSON', 'DURATION',
'DATE', 'CARDINAL', 'PERCENT', 'MONEY', 'MEASURE'],
'conll2002': ['LOC', 'PER', 'ORG'],
'ace': ['LOCATION', 'ORGANIZATION', 'PERSON', 'DURATION',
'DATE', 'CARDINAL', 'PERCENT', 'MONEY', 'MEASURE', 'FACILITY', 'GPE'],
}
# Allow abbreviated class labels
short2long = dict(LOC = 'LOCATION', ORG = 'ORGANIZATION', PER = 'PERSON')
long2short = dict(LOCATION ='LOC', ORGANIZATION = 'ORG', PERSON = 'PER')
def _expand(type):
"""
Expand an NE class name.
:type type: str
:rtype: str
"""
try:
return short2long[type]
except KeyError:
return type
def class_abbrev(type):
"""
Abbreviate an NE class name.
:type type: str
:rtype: str
"""
try:
return long2short[type]
except KeyError:
return type
def _join(lst, sep=' ', untag=False):
"""
Join a list into a string, turning tags tuples into tag strings or just words.
:param untag: if ``True``, omit the tag from tagged input strings.
:type lst: list
:rtype: str
"""
try:
return join(lst, sep=sep)
except TypeError:
if untag:
return join([tup[0] for tup in lst], sep=sep)
from nltk.tag import tuple2str
return join([tuple2str(tup) for tup in lst], sep=sep)
def descape_entity(m, defs=htmlentitydefs.entitydefs):
"""
Translate one entity to its ISO Latin value.
Inspired by example from effbot.org
"""
#s = 'mcglashan_&_sarrail'
#l = ['mcglashan', '&', 'sarrail']
#pattern = re.compile("&(\w+?);")
#new = list2sym(l)
#s = pattern.sub(descape_entity, s)
#print s, new
try:
return defs[m.group(1)]
except KeyError:
return m.group(0) # use as is
def list2sym(lst):
"""
Convert a list of strings into a canonical symbol.
:type lst: list
:return: a Unicode string without whitespace
:rtype: unicode
"""
sym = _join(lst, '_', untag=True)
sym = sym.lower()
ENT = re.compile("&(\w+?);")
sym = ENT.sub(descape_entity, sym)
sym = sym.replace('.', '')
return sym
def mk_pairs(tree):
"""
Group a chunk structure into a list of pairs of the form (list(str), ``Tree``)
In order to facilitate the construction of (``Tree``, string, ``Tree``) triples, this
identifies pairs whose first member is a list (possibly empty) of terminal
strings, and whose second member is a ``Tree`` of the form (NE_label, terminals).
:param tree: a chunk tree
:return: a list of pairs (list(str), ``Tree``)
:rtype: list of tuple
"""
from nltk.tree import Tree
pairs = []
pair = [[], None]
for dtr in tree:
if not isinstance(dtr, Tree):
pair[0].append(dtr)
else:
# dtr is a Tree
pair[1] = dtr
pairs.append(pair)
pair = [[], None]
return pairs
def mk_reldicts(pairs, window=5, trace=0):
"""
Converts the pairs generated by ``mk_pairs`` into a 'reldict': a dictionary which
stores information about the subject and object NEs plus the filler between them.
Additionally, a left and right context of length =< window are captured (within
a given input sentence).
:param pairs: a pair of list(str) and ``Tree``, as generated by
:param window: a threshold for the number of items to include in the left and right context
:type window: int
:return: 'relation' dictionaries whose keys are 'lcon', 'subjclass', 'subjtext', 'subjsym', 'filler', objclass', objtext', 'objsym' and 'rcon'
:rtype: list(defaultdict)
"""
result = []
while len(pairs) > 2:
reldict = defaultdict(str)
reldict['lcon'] = _join(pairs[0][0][-window:])
reldict['subjclass'] = pairs[0][1].node
reldict['subjtext'] = _join(pairs[0][1].leaves())
reldict['subjsym'] = list2sym(pairs[0][1].leaves())
reldict['filler'] = _join(pairs[1][0])
reldict['objclass'] = pairs[1][1].node
reldict['objtext'] = _join(pairs[1][1].leaves())
reldict['objsym'] = list2sym(pairs[1][1].leaves())
reldict['rcon'] = _join(pairs[2][0][:window])
if trace:
print("(rel(%s, %s)" % (reldict['subjclass'], reldict['objclass']))
result.append(reldict)
pairs = pairs[1:]
return result
def extract_rels(subjclass, objclass, doc, corpus='ace', pattern=None, window=10):
"""
Filter the output of ``mk_reldicts`` according to specified NE classes and a filler pattern.
The parameters ``subjclass`` and ``objclass`` can be used to restrict the
Named Entities to particular types (any of 'LOCATION', 'ORGANIZATION',
'PERSON', 'DURATION', 'DATE', 'CARDINAL', 'PERCENT', 'MONEY', 'MEASURE').
:param subjclass: the class of the subject Named Entity.
:type subjclass: str
:param objclass: the class of the object Named Entity.
:type objclass: str
:param doc: input document
:type doc: ieer document or a list of chunk trees
:param corpus: name of the corpus to take as input; possible values are
'ieer' and 'conll2002'
:type corpus: str
:param pattern: a regular expression for filtering the fillers of
retrieved triples.
:type pattern: SRE_Pattern
:param window: filters out fillers which exceed this threshold
:type window: int
:return: see ``mk_reldicts``
:rtype: list(defaultdict)
"""
if subjclass and subjclass not in NE_CLASSES[corpus]:
if _expand(subjclass) in NE_CLASSES[corpus]:
subjclass = _expand(subjclass)
else:
raise ValueError("your value for the subject type has not been recognized: %s" % subjclass)
if objclass and objclass not in NE_CLASSES[corpus]:
if _expand(objclass) in NE_CLASSES[corpus]:
objclass = _expand(objclass)
else:
raise ValueError("your value for the object type has not been recognized: %s" % objclass)
if corpus == 'ace' or corpus == 'conll2002':
pairs = mk_pairs(doc)
elif corpus == 'ieer':
pairs = mk_pairs(doc.text) + mk_pairs(doc.headline)
else:
raise ValueError("corpus type not recognized")
reldicts = mk_reldicts(pairs)
relfilter = lambda x: (x['subjclass'] == subjclass and
len(x['filler'].split()) <= window and
pattern.match(x['filler']) and
x['objclass'] == objclass)
return filter(relfilter, reldicts)
def show_raw_rtuple(reldict, lcon=False, rcon=False):
"""
Pretty print the reldict as an rtuple.
:param reldict: a relation dictionary
:type reldict: defaultdict
"""
items = [class_abbrev(reldict['subjclass']), reldict['subjtext'], reldict['filler'], class_abbrev(reldict['objclass']), reldict['objtext']]
format = '[%s: %r] %r [%s: %r]'
if lcon:
items = [reldict['lcon']] + items
format = '...%r)' + format
if rcon:
items.append(reldict['rcon'])
format = format + '(%r...'
printargs = tuple(items)
return format % printargs
def show_clause(reldict, relsym):
"""
Print the relation in clausal form.
:param reldict: a relation dictionary
:type reldict: defaultdict
:param relsym: a label for the relation
:type relsym: str
"""
items = (relsym, reldict['subjsym'], reldict['objsym'])
return "%s(%r, %r)" % items
#######################################################
# Demos of relation extraction with regular expressions
#######################################################
############################################
# Example of in(ORG, LOC)
############################################
def in_demo(trace=0, sql=True):
"""
Select pairs of organizations and locations whose mentions occur with an
intervening occurrence of the preposition "in".
If the sql parameter is set to True, then the entity pairs are loaded into
an in-memory database, and subsequently pulled out using an SQL "SELECT"
query.
"""
from nltk.corpus import ieer
if sql:
try:
import sqlite3
connection = sqlite3.connect(":memory:")
connection.text_factory = sqlite3.OptimizedUnicode
cur = connection.cursor()
cur.execute("""create table Locations
(OrgName text, LocationName text, DocID text)""")
except ImportError:
import warnings
warnings.warn("Cannot import sqlite; sql flag will be ignored.")
IN = re.compile(r'.*\bin\b(?!\b.+ing)')
print()
print("IEER: in(ORG, LOC) -- just the clauses:")
print("=" * 45)
for file in ieer.fileids():
for doc in ieer.parsed_docs(file):
if trace:
print(doc.docno)
print("=" * 15)
for rel in extract_rels('ORG', 'LOC', doc, corpus='ieer', pattern=IN):
print(show_clause(rel, relsym='IN'))
if sql:
try:
rtuple = (rel['subjtext'], rel['objtext'], doc.docno)
cur.execute("""insert into Locations
values (?, ?, ?)""", rtuple)
connection.commit()
except NameError:
pass
if sql:
try:
cur.execute("""select OrgName from Locations
where LocationName = 'Atlanta'""")
print()
print("Extract data from SQL table: ORGs in Atlanta")
print("-" * 15)
for row in cur:
print(row)
except NameError:
pass
############################################
# Example of has_role(PER, LOC)
############################################
def roles_demo(trace=0):
from nltk.corpus import ieer
roles = """
(.*( # assorted roles
analyst|
chair(wo)?man|
commissioner|
counsel|
director|
economist|
editor|
executive|
foreman|
governor|
head|
lawyer|
leader|
librarian).*)|
manager|
partner|
president|
producer|
professor|
researcher|
spokes(wo)?man|
writer|
,\sof\sthe?\s* # "X, of (the) Y"
"""
ROLES = re.compile(roles, re.VERBOSE)
print()
print("IEER: has_role(PER, ORG) -- raw rtuples:")
print("=" * 45)
for file in ieer.fileids():
for doc in ieer.parsed_docs(file):
lcon = rcon = False
if trace:
print(doc.docno)
print("=" * 15)
lcon = rcon = True
for rel in extract_rels('PER', 'ORG', doc, corpus='ieer', pattern=ROLES):
print(show_raw_rtuple(rel, lcon=lcon, rcon=rcon))
##############################################
### Show what's in the IEER Headlines
##############################################
def ieer_headlines():
from nltk.corpus import ieer
from nltk.tree import Tree
print("IEER: First 20 Headlines")
print("=" * 45)
trees = [doc.headline for file in ieer.fileids() for doc in ieer.parsed_docs(file)]
for tree in trees[:20]:
print()
print("%s:\n%s" % (doc.docno, tree))
#############################################
## Dutch CONLL2002: take_on_role(PER, ORG
#############################################
def conllned(trace=1):
"""
Find the copula+'van' relation ('of') in the Dutch tagged training corpus
from CoNLL 2002.
"""
from nltk.corpus import conll2002
vnv = """
(
is/V| # 3rd sing present and
was/V| # past forms of the verb zijn ('be')
werd/V| # and also present
wordt/V # past of worden ('become)
)
.* # followed by anything
van/Prep # followed by van ('of')
"""
VAN = re.compile(vnv, re.VERBOSE)
print()
print("Dutch CoNLL2002: van(PER, ORG) -- raw rtuples with context:")
print("=" * 45)
for doc in conll2002.chunked_sents('ned.train'):
lcon = rcon = False
if trace:
lcon = rcon = True
for rel in extract_rels('PER', 'ORG', doc, corpus='conll2002', pattern=VAN, window=10):
print(show_raw_rtuple(rel, lcon=True, rcon=True))
#############################################
## Spanish CONLL2002: (PER, ORG)
#############################################
def conllesp():
from nltk.corpus import conll2002
de = """
.*
(
de/SP|
del/SP
)
"""
DE = re.compile(de, re.VERBOSE)
print()
print("Spanish CoNLL2002: de(ORG, LOC) -- just the first 10 clauses:")
print("=" * 45)
rels = [rel for doc in conll2002.chunked_sents('esp.train')
for rel in extract_rels('ORG', 'LOC', doc, corpus='conll2002', pattern = DE)]
for r in rels[:10]: print(show_clause(r, relsym='DE'))
print()
def ne_chunked():
IN = re.compile(r'.*\bin\b(?!\b.+ing)')
rels = []
for sent in nltk.corpus.treebank.tagged_sents()[:100]:
sent = nltk.ne_chunk(sent)
print(extract_rels('ORG', 'LOC', sent, corpus='ace', pattern = IN))
if __name__ == '__main__':
import nltk
from nltk.sem import relextract
in_demo(trace=0)
roles_demo(trace=0)
conllned()
conllesp()
ieer_headlines()
|
apache-2.0
|
[
3,
653,
292,
4889,
8466,
15650,
6065,
26,
23230,
7255,
6156,
199,
3,
199,
3,
1898,
334,
35,
9,
12521,
13,
7409,
24719,
15263,
7290,
199,
3,
6529,
26,
662,
20444,
1804,
274,
262,
665,
546,
290,
32,
4904,
14,
379,
14,
645,
14,
3210,
30,
199,
3,
2851,
26,
665,
1014,
921,
1544,
14,
7530,
2663,
14,
1308,
3133,
199,
3,
2104,
4190,
2556,
12,
1937,
5113,
14,
17715,
199,
199,
624,
199,
3034,
367,
30137,
5850,
279,
31733,
687,
314,
13446,
281,
436,
406,
914,
15135,
1970,
7314,
65,
14,
199,
199,
5640,
1298,
787,
5489,
14448,
465,
11196,
661,
3369,
7892,
1959,
199,
199,
1918,
2877,
16953,
4704,
787,
298,
2591,
1363,
2,
436,
298,
8501,
1674,
199,
199,
13,
1626,
519,
2960,
365,
282,
2008,
402,
314,
1824,
15475,
954,
74,
12,
1794,
1435,
12,
1559,
28616,
523,
2382,
1124,
954,
74,
1040,
436,
1124,
1113,
1040,
787,
6342,
402,
16198,
17680,
12953,
852,
12,
436,
1124,
1289,
1435,
1040,
365,
314,
1059,
402,
5932,
523,
4781,
5985,
3382,
1124,
954,
1040,
436,
1124,
1113,
1040,
334,
1045,
949,
1640,
1856,
316,
7110,
83,
680,
24361,
787,
12487,
4799,
1124,
2722,
8497,
370,
523,
27027,
782,
5867,
4172,
1298,
315,
14066,
2774,
13,
24,
5737,
3326,
14,
199,
13,
437,
8502,
365,
376,
6222,
402,
314,
1824,
1124,
264,
478,
12828,
8,
954,
74,
3840,
12,
1559,
3840,
28616,
523,
2382,
314,
5850,
12,
5420,
436,
909,
1172,
2757,
11358,
1759,
370,
2849,
3326,
14,
199,
624,
199,
199,
3,
11386,
26,
664,
282,
1655,
8605,
8744,
370,
11358,
1759,
6698,
367,
25089,
1553,
11703,
675,
2748,
1560,
7655,
31,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
5055,
492,
10018,
199,
504,
1059,
492,
4263,
199,
646,
295,
199,
646,
30010,
552,
1701,
8710,
199,
504,
7975,
492,
284,
1541,
199,
199,
3,
11932,
626,
4035,
2335,
1970,
7314,
65,
543,
7110,
3992,
199,
6388,
63,
13748,
275,
469,
272,
283,
1873,
281,
356,
788,
16575,
297,
283,
25797,
879,
22800,
297,
283,
30973,
297,
283,
36,
15301,
297,
288,
283,
5390,
297,
283,
35,
7816,
13384,
297,
283,
4227,
17349,
297,
283,
45,
4817,
57,
297,
283,
31097,
3942,
995,
272,
283,
388,
914,
15135,
356,
788,
5752,
297,
283,
4227,
297,
283,
25797,
995,
272,
283,
7984,
356,
788,
16575,
297,
283,
25797,
879,
22800,
297,
283,
30973,
297,
283,
36,
15301,
297,
288,
283,
5390,
297,
283,
35,
7816,
13384,
297,
283,
4227,
17349,
297,
283,
45,
4817,
57,
297,
283,
31097,
3942,
297,
283,
38,
1348,
2273,
297,
283,
39,
1510,
995,
272,
789,
199,
199,
3,
9812,
2236,
23988,
972,
1021,
3628,
199,
3612,
18,
2809,
275,
1211,
8,
5752,
275,
283,
16575,
297,
1549,
39,
275,
283,
25797,
879,
22800,
297,
13873,
275,
283,
30973,
358,
199,
2809,
18,
3612,
275,
1211,
8,
16575,
275,
7,
5752,
297,
1549,
39,
879,
22800,
275,
283,
25797,
297,
13873,
3377,
275,
283,
4227,
358,
421,
199,
318,
485,
4441,
8,
466,
304,
272,
408,
272,
18890,
376,
7110,
1021,
536,
14,
272,
520,
466,
730,
26,
620,
272,
520,
4500,
26,
620,
272,
408,
272,
862,
26,
267,
372,
3974,
18,
2809,
59,
466,
61,
272,
871,
4067,
26,
267,
372,
730,
199,
199,
318,
1021,
63,
31349,
8,
466,
304,
272,
408,
272,
437,
2501,
264,
433,
323,
376,
7110,
1021,
536,
14,
272,
520,
466,
730,
26,
620,
272,
520,
4500,
26,
620,
272,
408,
272,
862,
26,
267,
372,
1846,
18,
3612,
59,
466,
61,
272,
871,
4067,
26,
267,
372,
730,
421,
199,
318,
485,
904,
8,
6916,
12,
7375,
534,
1656,
625,
1450,
29,
797,
304,
272,
408,
272,
25733,
282,
769,
1901,
282,
1059,
12,
7485,
316,
3762,
6346,
1901,
1947,
3326,
503,
2951,
5932,
14,
272,
520,
635,
625,
1450,
26,
340,
1124,
549,
4542,
19413,
314,
1947,
687,
20018,
1324,
3326,
14,
272,
520,
466,
9877,
26,
769,
272,
520,
4500,
26,
620,
272,
408,
272,
862,
26,
267,
372,
4263,
8,
6916,
12,
7375,
29,
4127,
9,
272,
871,
3146,
26,
267,
340,
625,
1450,
26,
288,
372,
4263,
779,
17034,
59,
16,
61,
367,
16477,
315,
9877,
467,
7375,
29,
4127,
9,
267,
687,
24706,
14,
1450,
492,
2008,
18,
495,
267,
372,
4263,
779,
2960,
18,
495,
8,
17034,
9,
367,
16477,
315,
9877,
467,
7375,
29,
4127,
9,
199,
199,
318,
477,
3588,
63,
4502,
8,
77,
12,
22603,
29,
15575,
552,
1701,
8710,
14,
4502,
8710,
304,
272,
408,
272,
25540,
1373,
4642,
370,
2399,
9055,
23864,
574,
14,
272,
12062,
1038,
581,
701,
2893,
687,
10783,
3018,
14,
1308,
2378,
408,
272,
327,
83,
275,
283,
5466,
3528,
1119,
290,
63,
6,
5282,
27,
63,
29637,
345,
382,
7,
272,
327,
76,
275,
788,
5466,
3528,
1119,
290,
297,
7673,
5282,
10805,
283,
29637,
345,
382,
418,
272,
327,
3401,
275,
295,
14,
2014,
22077,
2961,
87,
23778,
2736,
531,
272,
327,
1222,
275,
769,
18,
3840,
8,
76,
9,
272,
327,
83,
275,
3851,
14,
954,
8,
3257,
924,
63,
4502,
12,
308,
9,
272,
327,
1361,
308,
12,
892,
272,
862,
26,
267,
372,
22603,
59,
77,
14,
923,
8,
17,
1874,
339,
871,
4067,
26,
267,
372,
333,
14,
923,
8,
16,
9,
327,
675,
465,
365,
199,
199,
318,
769,
18,
3840,
8,
6916,
304,
272,
408,
272,
7905,
282,
769,
402,
3326,
1901,
282,
11358,
5272,
14,
272,
520,
466,
9877,
26,
769,
272,
520,
1107,
26,
282,
6140,
1059,
1928,
8139,
272,
520,
4500,
26,
2649,
272,
408,
272,
4678,
275,
485,
904,
8,
6916,
12,
25469,
625,
1450,
29,
549,
9,
272,
4678,
275,
4678,
14,
2325,
342,
272,
32526,
275,
295,
14,
2014,
22077,
2961,
87,
23778,
2736,
531,
272,
4678,
275,
32526,
14,
954,
8,
3257,
924,
63,
4502,
12,
4678,
9,
272,
4678,
275,
4678,
14,
1814,
14078,
4074,
272,
372,
4678,
199,
199,
318,
9199,
63,
7322,
8,
2350,
304,
272,
408,
272,
5611,
282,
3728,
5523,
1901,
282,
769,
402,
6342,
402,
314,
1824,
334,
513,
8,
495,
395,
1124,
3987,
16580,
339,
1010,
1865
] |
[
653,
292,
4889,
8466,
15650,
6065,
26,
23230,
7255,
6156,
199,
3,
199,
3,
1898,
334,
35,
9,
12521,
13,
7409,
24719,
15263,
7290,
199,
3,
6529,
26,
662,
20444,
1804,
274,
262,
665,
546,
290,
32,
4904,
14,
379,
14,
645,
14,
3210,
30,
199,
3,
2851,
26,
665,
1014,
921,
1544,
14,
7530,
2663,
14,
1308,
3133,
199,
3,
2104,
4190,
2556,
12,
1937,
5113,
14,
17715,
199,
199,
624,
199,
3034,
367,
30137,
5850,
279,
31733,
687,
314,
13446,
281,
436,
406,
914,
15135,
1970,
7314,
65,
14,
199,
199,
5640,
1298,
787,
5489,
14448,
465,
11196,
661,
3369,
7892,
1959,
199,
199,
1918,
2877,
16953,
4704,
787,
298,
2591,
1363,
2,
436,
298,
8501,
1674,
199,
199,
13,
1626,
519,
2960,
365,
282,
2008,
402,
314,
1824,
15475,
954,
74,
12,
1794,
1435,
12,
1559,
28616,
523,
2382,
1124,
954,
74,
1040,
436,
1124,
1113,
1040,
787,
6342,
402,
16198,
17680,
12953,
852,
12,
436,
1124,
1289,
1435,
1040,
365,
314,
1059,
402,
5932,
523,
4781,
5985,
3382,
1124,
954,
1040,
436,
1124,
1113,
1040,
334,
1045,
949,
1640,
1856,
316,
7110,
83,
680,
24361,
787,
12487,
4799,
1124,
2722,
8497,
370,
523,
27027,
782,
5867,
4172,
1298,
315,
14066,
2774,
13,
24,
5737,
3326,
14,
199,
13,
437,
8502,
365,
376,
6222,
402,
314,
1824,
1124,
264,
478,
12828,
8,
954,
74,
3840,
12,
1559,
3840,
28616,
523,
2382,
314,
5850,
12,
5420,
436,
909,
1172,
2757,
11358,
1759,
370,
2849,
3326,
14,
199,
624,
199,
199,
3,
11386,
26,
664,
282,
1655,
8605,
8744,
370,
11358,
1759,
6698,
367,
25089,
1553,
11703,
675,
2748,
1560,
7655,
31,
199,
199,
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
504,
5055,
492,
10018,
199,
504,
1059,
492,
4263,
199,
646,
295,
199,
646,
30010,
552,
1701,
8710,
199,
504,
7975,
492,
284,
1541,
199,
199,
3,
11932,
626,
4035,
2335,
1970,
7314,
65,
543,
7110,
3992,
199,
6388,
63,
13748,
275,
469,
272,
283,
1873,
281,
356,
788,
16575,
297,
283,
25797,
879,
22800,
297,
283,
30973,
297,
283,
36,
15301,
297,
288,
283,
5390,
297,
283,
35,
7816,
13384,
297,
283,
4227,
17349,
297,
283,
45,
4817,
57,
297,
283,
31097,
3942,
995,
272,
283,
388,
914,
15135,
356,
788,
5752,
297,
283,
4227,
297,
283,
25797,
995,
272,
283,
7984,
356,
788,
16575,
297,
283,
25797,
879,
22800,
297,
283,
30973,
297,
283,
36,
15301,
297,
288,
283,
5390,
297,
283,
35,
7816,
13384,
297,
283,
4227,
17349,
297,
283,
45,
4817,
57,
297,
283,
31097,
3942,
297,
283,
38,
1348,
2273,
297,
283,
39,
1510,
995,
272,
789,
199,
199,
3,
9812,
2236,
23988,
972,
1021,
3628,
199,
3612,
18,
2809,
275,
1211,
8,
5752,
275,
283,
16575,
297,
1549,
39,
275,
283,
25797,
879,
22800,
297,
13873,
275,
283,
30973,
358,
199,
2809,
18,
3612,
275,
1211,
8,
16575,
275,
7,
5752,
297,
1549,
39,
879,
22800,
275,
283,
25797,
297,
13873,
3377,
275,
283,
4227,
358,
421,
199,
318,
485,
4441,
8,
466,
304,
272,
408,
272,
18890,
376,
7110,
1021,
536,
14,
272,
520,
466,
730,
26,
620,
272,
520,
4500,
26,
620,
272,
408,
272,
862,
26,
267,
372,
3974,
18,
2809,
59,
466,
61,
272,
871,
4067,
26,
267,
372,
730,
199,
199,
318,
1021,
63,
31349,
8,
466,
304,
272,
408,
272,
437,
2501,
264,
433,
323,
376,
7110,
1021,
536,
14,
272,
520,
466,
730,
26,
620,
272,
520,
4500,
26,
620,
272,
408,
272,
862,
26,
267,
372,
1846,
18,
3612,
59,
466,
61,
272,
871,
4067,
26,
267,
372,
730,
421,
199,
318,
485,
904,
8,
6916,
12,
7375,
534,
1656,
625,
1450,
29,
797,
304,
272,
408,
272,
25733,
282,
769,
1901,
282,
1059,
12,
7485,
316,
3762,
6346,
1901,
1947,
3326,
503,
2951,
5932,
14,
272,
520,
635,
625,
1450,
26,
340,
1124,
549,
4542,
19413,
314,
1947,
687,
20018,
1324,
3326,
14,
272,
520,
466,
9877,
26,
769,
272,
520,
4500,
26,
620,
272,
408,
272,
862,
26,
267,
372,
4263,
8,
6916,
12,
7375,
29,
4127,
9,
272,
871,
3146,
26,
267,
340,
625,
1450,
26,
288,
372,
4263,
779,
17034,
59,
16,
61,
367,
16477,
315,
9877,
467,
7375,
29,
4127,
9,
267,
687,
24706,
14,
1450,
492,
2008,
18,
495,
267,
372,
4263,
779,
2960,
18,
495,
8,
17034,
9,
367,
16477,
315,
9877,
467,
7375,
29,
4127,
9,
199,
199,
318,
477,
3588,
63,
4502,
8,
77,
12,
22603,
29,
15575,
552,
1701,
8710,
14,
4502,
8710,
304,
272,
408,
272,
25540,
1373,
4642,
370,
2399,
9055,
23864,
574,
14,
272,
12062,
1038,
581,
701,
2893,
687,
10783,
3018,
14,
1308,
2378,
408,
272,
327,
83,
275,
283,
5466,
3528,
1119,
290,
63,
6,
5282,
27,
63,
29637,
345,
382,
7,
272,
327,
76,
275,
788,
5466,
3528,
1119,
290,
297,
7673,
5282,
10805,
283,
29637,
345,
382,
418,
272,
327,
3401,
275,
295,
14,
2014,
22077,
2961,
87,
23778,
2736,
531,
272,
327,
1222,
275,
769,
18,
3840,
8,
76,
9,
272,
327,
83,
275,
3851,
14,
954,
8,
3257,
924,
63,
4502,
12,
308,
9,
272,
327,
1361,
308,
12,
892,
272,
862,
26,
267,
372,
22603,
59,
77,
14,
923,
8,
17,
1874,
339,
871,
4067,
26,
267,
372,
333,
14,
923,
8,
16,
9,
327,
675,
465,
365,
199,
199,
318,
769,
18,
3840,
8,
6916,
304,
272,
408,
272,
7905,
282,
769,
402,
3326,
1901,
282,
11358,
5272,
14,
272,
520,
466,
9877,
26,
769,
272,
520,
1107,
26,
282,
6140,
1059,
1928,
8139,
272,
520,
4500,
26,
2649,
272,
408,
272,
4678,
275,
485,
904,
8,
6916,
12,
25469,
625,
1450,
29,
549,
9,
272,
4678,
275,
4678,
14,
2325,
342,
272,
32526,
275,
295,
14,
2014,
22077,
2961,
87,
23778,
2736,
531,
272,
4678,
275,
32526,
14,
954,
8,
3257,
924,
63,
4502,
12,
4678,
9,
272,
4678,
275,
4678,
14,
1814,
14078,
4074,
272,
372,
4678,
199,
199,
318,
9199,
63,
7322,
8,
2350,
304,
272,
408,
272,
5611,
282,
3728,
5523,
1901,
282,
769,
402,
6342,
402,
314,
1824,
334,
513,
8,
495,
395,
1124,
3987,
16580,
339,
1010,
1865,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mrGeen/cython
|
Cython/Compiler/UtilityCode.py
|
6
|
8783
|
from __future__ import absolute_import
from .TreeFragment import parse_from_strings, StringParseContext
from . import Symtab
from . import Naming
from . import Code
class NonManglingModuleScope(Symtab.ModuleScope):
cpp = False
def __init__(self, prefix, *args, **kw):
self.prefix = prefix
self.cython_scope = None
Symtab.ModuleScope.__init__(self, *args, **kw)
def add_imported_entry(self, name, entry, pos):
entry.used = True
return super(NonManglingModuleScope, self).add_imported_entry(
name, entry, pos)
def mangle(self, prefix, name=None):
if name:
if prefix in (Naming.typeobj_prefix, Naming.func_prefix, Naming.var_prefix, Naming.pyfunc_prefix):
# Functions, classes etc. gets a manually defined prefix easily
# manually callable instead (the one passed to CythonUtilityCode)
prefix = self.prefix
return "%s%s" % (prefix, name)
else:
return Symtab.ModuleScope.mangle(self, prefix)
class CythonUtilityCodeContext(StringParseContext):
scope = None
def find_module(self, module_name, relative_to=None, pos=None, need_pxd=True, absolute_fallback=True):
if relative_to:
raise AssertionError("Relative imports not supported in utility code.")
if module_name != self.module_name:
if module_name not in self.modules:
raise AssertionError("Only the cython cimport is supported.")
else:
return self.modules[module_name]
if self.scope is None:
self.scope = NonManglingModuleScope(
self.prefix, module_name, parent_module=None, context=self)
return self.scope
class CythonUtilityCode(Code.UtilityCodeBase):
"""
Utility code written in the Cython language itself.
The @cname decorator can set the cname for a function, method of cdef class.
Functions decorated with @cname('c_func_name') get the given cname.
For cdef classes the rules are as follows:
obj struct -> <cname>_obj
obj type ptr -> <cname>_type
methods -> <class_cname>_<method_cname>
For methods the cname decorator is optional, but without the decorator the
methods will not be prototyped. See Cython.Compiler.CythonScope and
tests/run/cythonscope.pyx for examples.
"""
is_cython_utility = True
def __init__(self, impl, name="__pyxutil", prefix="", requires=None,
file=None, from_scope=None, context=None, compiler_directives=None,
outer_module_scope=None):
# 1) We need to delay the parsing/processing, so that all modules can be
# imported without import loops
# 2) The same utility code object can be used for multiple source files;
# while the generated node trees can be altered in the compilation of a
# single file.
# Hence, delay any processing until later.
if context is not None:
impl = Code.sub_tempita(impl, context, file, name)
self.impl = impl
self.name = name
self.file = file
self.prefix = prefix
self.requires = requires or []
self.from_scope = from_scope
self.outer_module_scope = outer_module_scope
self.compiler_directives = compiler_directives
def __eq__(self, other):
if isinstance(other, CythonUtilityCode):
return self._equality_params() == other._equality_params()
else:
return False
def _equality_params(self):
outer_scope = self.outer_module_scope
while isinstance(outer_scope, NonManglingModuleScope):
outer_scope = outer_scope.outer_scope
return self.impl, outer_scope, self.compiler_directives
def __hash__(self):
return hash(self.impl)
def get_tree(self, entries_only=False, cython_scope=None):
from .AnalysedTreeTransforms import AutoTestDictTransform
# The AutoTestDictTransform creates the statement "__test__ = {}",
# which when copied into the main ModuleNode overwrites
# any __test__ in user code; not desired
excludes = [AutoTestDictTransform]
from . import Pipeline, ParseTreeTransforms
context = CythonUtilityCodeContext(
self.name, compiler_directives=self.compiler_directives)
context.prefix = self.prefix
context.cython_scope = cython_scope
#context = StringParseContext(self.name)
tree = parse_from_strings(
self.name, self.impl, context=context, allow_struct_enum_decorator=True)
pipeline = Pipeline.create_pipeline(context, 'pyx', exclude_classes=excludes)
if entries_only:
p = []
for t in pipeline:
p.append(t)
if isinstance(p, ParseTreeTransforms.AnalyseDeclarationsTransform):
break
pipeline = p
transform = ParseTreeTransforms.CnameDirectivesTransform(context)
# InterpretCompilerDirectives already does a cdef declarator check
#before = ParseTreeTransforms.DecoratorTransform
before = ParseTreeTransforms.InterpretCompilerDirectives
pipeline = Pipeline.insert_into_pipeline(pipeline, transform,
before=before)
if self.from_scope:
def scope_transform(module_node):
module_node.scope.merge_in(self.from_scope)
return module_node
transform = ParseTreeTransforms.AnalyseDeclarationsTransform
pipeline = Pipeline.insert_into_pipeline(pipeline, scope_transform,
before=transform)
for dep in self.requires:
if (isinstance(dep, CythonUtilityCode)
and hasattr(dep, 'tree')
and not cython_scope):
def scope_transform(module_node):
module_node.scope.merge_in(dep.tree.scope)
return module_node
transform = ParseTreeTransforms.AnalyseDeclarationsTransform
pipeline = Pipeline.insert_into_pipeline(pipeline, scope_transform,
before=transform)
if self.outer_module_scope:
# inject outer module between utility code module and builtin module
def scope_transform(module_node):
module_node.scope.outer_scope = self.outer_module_scope
return module_node
transform = ParseTreeTransforms.AnalyseDeclarationsTransform
pipeline = Pipeline.insert_into_pipeline(pipeline, scope_transform,
before=transform)
(err, tree) = Pipeline.run_pipeline(pipeline, tree, printtree=False)
assert not err, err
self.tree = tree
return tree
def put_code(self, output):
pass
@classmethod
def load_as_string(cls, util_code_name, from_file=None, **kwargs):
"""
Load a utility code as a string. Returns (proto, implementation)
"""
util = cls.load(util_code_name, from_file, **kwargs)
return util.proto, util.impl # keep line numbers => no lstrip()
def declare_in_scope(self, dest_scope, used=False, cython_scope=None,
whitelist=None):
"""
Declare all entries from the utility code in dest_scope. Code will only
be included for used entries. If module_name is given, declare the
type entries with that name.
"""
tree = self.get_tree(entries_only=True, cython_scope=cython_scope)
entries = tree.scope.entries
entries.pop('__name__')
entries.pop('__file__')
entries.pop('__builtins__')
entries.pop('__doc__')
for name, entry in entries.items():
entry.utility_code_definition = self
entry.used = used
original_scope = tree.scope
dest_scope.merge_in(original_scope, merge_unused=True,
whitelist=whitelist)
tree.scope = dest_scope
for dep in self.requires:
if dep.is_cython_utility:
dep.declare_in_scope(dest_scope)
return original_scope
def declare_declarations_in_scope(declaration_string, env, private_type=True,
*args, **kwargs):
"""
Declare some declarations given as Cython code in declaration_string
in scope env.
"""
CythonUtilityCode(declaration_string, *args, **kwargs).declare_in_scope(env)
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1275,
3987,
11080,
492,
2198,
63,
504,
63,
5465,
12,
2624,
4003,
2998,
199,
504,
1275,
492,
5515,
2037,
371,
199,
504,
1275,
492,
653,
9568,
199,
504,
1275,
492,
5495,
421,
199,
533,
10172,
45,
26896,
2377,
7812,
8,
4323,
2037,
371,
14,
2377,
7812,
304,
339,
7246,
275,
756,
339,
347,
636,
826,
721,
277,
12,
2403,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
1861,
275,
2403,
267,
291,
14,
20747,
63,
2645,
275,
488,
267,
5515,
2037,
371,
14,
2377,
7812,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
1050,
63,
17932,
63,
2373,
8,
277,
12,
536,
12,
2397,
12,
2086,
304,
267,
2397,
14,
2972,
275,
715,
267,
372,
1613,
8,
6932,
45,
26896,
2377,
7812,
12,
291,
680,
525,
63,
17932,
63,
2373,
8,
9144,
536,
12,
2397,
12,
2086,
9,
339,
347,
333,
4593,
8,
277,
12,
2403,
12,
536,
29,
403,
304,
267,
340,
536,
26,
288,
340,
2403,
315,
334,
46,
9568,
14,
466,
1113,
63,
1861,
12,
653,
9568,
14,
1532,
63,
1861,
12,
653,
9568,
14,
1391,
63,
1861,
12,
653,
9568,
14,
647,
1532,
63,
1861,
304,
355,
327,
17471,
12,
3992,
5423,
14,
7545,
282,
10250,
3247,
2403,
16174,
355,
327,
10250,
4550,
3140,
334,
1589,
1373,
3032,
370,
26741,
17505,
3034,
9,
355,
2403,
275,
291,
14,
1861,
288,
372,
2071,
83,
5,
83,
2,
450,
334,
1861,
12,
536,
9,
267,
587,
26,
288,
372,
5515,
2037,
371,
14,
2377,
7812,
14,
29602,
8,
277,
12,
2403,
9,
421,
199,
533,
26741,
17505,
3034,
2998,
8,
1558,
4003,
2998,
304,
272,
4194,
275,
488,
339,
347,
2342,
63,
578,
8,
277,
12,
859,
63,
354,
12,
3847,
63,
475,
29,
403,
12,
2086,
29,
403,
12,
1929,
63,
80,
2207,
29,
549,
12,
3679,
63,
10538,
29,
549,
304,
267,
340,
3847,
63,
475,
26,
288,
746,
9070,
480,
15277,
8925,
440,
3748,
315,
11420,
1233,
2685,
267,
340,
859,
63,
354,
1137,
291,
14,
578,
63,
354,
26,
288,
340,
859,
63,
354,
440,
315,
291,
14,
3112,
26,
355,
746,
9070,
480,
5903,
314,
29348,
286,
646,
365,
3748,
2685,
288,
587,
26,
355,
372,
291,
14,
3112,
59,
578,
63,
354,
61,
398,
340,
291,
14,
2645,
365,
488,
26,
288,
291,
14,
2645,
275,
10172,
45,
26896,
2377,
7812,
8,
355,
291,
14,
1861,
12,
859,
63,
354,
12,
1676,
63,
578,
29,
403,
12,
1067,
29,
277,
9,
398,
372,
291,
14,
2645,
421,
199,
533,
26741,
17505,
3034,
8,
3034,
14,
17505,
3034,
1563,
304,
272,
408,
272,
20511,
1233,
5313,
315,
314,
26741,
2637,
6337,
14,
339,
710,
768,
11690,
7531,
883,
663,
314,
22559,
367,
282,
805,
12,
1083,
402,
286,
318,
1021,
14,
272,
17471,
16225,
543,
768,
11690,
360,
67,
63,
1532,
63,
354,
358,
664,
314,
1627,
22559,
14,
339,
2104,
286,
318,
3992,
314,
4713,
787,
465,
11924,
26,
267,
1559,
2702,
420,
1035,
665,
11690,
30,
63,
1113,
267,
1559,
730,
12448,
259,
1035,
665,
11690,
30,
63,
466,
267,
3102,
260,
1035,
665,
533,
63,
11690,
30,
27718,
765,
63,
11690,
30,
339,
2104,
3102,
314,
22559,
7531,
365,
2716,
12,
1325,
1928,
314,
7531,
314,
272,
3102,
911,
440,
506,
19393,
68,
14,
1666,
26741,
14,
9131,
14,
9156,
898,
7812,
436,
272,
2295,
15,
1065,
15,
20747,
2645,
14,
25579,
367,
7251,
14,
272,
408,
339,
365,
63,
20747,
63,
16877,
275,
715,
339,
347,
636,
826,
721,
277,
12,
11512,
12,
536,
628,
363,
25579,
1974,
401,
2403,
8772,
5074,
29,
403,
12,
326,
570,
29,
403,
12,
687,
63,
2645,
29,
403,
12,
1067,
29,
403,
12,
6365,
63,
23216,
29,
403,
12,
326,
6890,
63,
578,
63,
2645,
29,
403,
304,
267,
327,
413,
9,
2136,
1929,
370,
7339,
314,
6057,
15,
6338,
12,
880,
626,
1006,
4621,
883,
506,
267,
327,
259,
8439,
1928,
492,
17222,
267,
327,
499,
9,
710,
2011,
11420,
1233,
909,
883,
506,
1202,
367,
3663,
1350,
1584,
27,
267,
327,
259,
1830,
314,
4046,
1031,
14416,
883,
506,
29815,
315,
314,
18653,
402,
282,
267,
327,
259,
2849,
570,
14,
267,
327,
869,
4894,
12,
7339,
1263,
6661,
5133,
2945,
14,
267,
340,
1067,
365,
440,
488,
26,
288,
11512,
275,
5495,
14,
954,
63,
808,
21492,
8,
5472,
12,
1067,
12,
570,
12,
536,
9,
267,
291,
14,
5472,
275,
11512,
267,
291,
14,
354,
275,
536,
267,
291,
14,
493,
275,
570,
267,
291,
14,
1861,
275,
2403,
267,
291,
14,
6537,
275,
5074,
503,
942,
267,
291,
14,
504,
63,
2645,
275,
687,
63,
2645,
267,
291,
14,
7837,
63,
578,
63,
2645,
275,
6890,
63,
578,
63,
2645,
267,
291,
14,
5772,
63,
23216,
275,
6365,
63,
23216,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
26741,
17505,
3034,
304,
288,
372,
291,
423,
20982,
63,
1162,
342,
508,
1163,
423,
20982,
63,
1162,
342,
267,
587,
26,
288,
372,
756,
339,
347,
485,
20982,
63,
1162,
8,
277,
304,
267,
6890,
63,
2645,
275,
291,
14,
7837,
63,
578,
63,
2645,
267,
1830,
1228,
8,
7837,
63,
2645,
12,
10172,
45,
26896,
2377,
7812,
304,
288,
6890,
63,
2645,
275,
6890,
63,
2645,
14,
7837,
63,
2645,
267,
372,
291,
14,
5472,
12,
6890,
63,
2645,
12,
291,
14,
5772,
63,
23216,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
14,
5472,
9,
339,
347,
664,
63,
2350,
8,
277,
12,
4811,
63,
2118,
29,
797,
12,
29348,
63,
2645,
29,
403,
304,
267,
687,
1275,
8014,
939,
3987,
3188,
3351,
492,
9195,
774,
2141,
6939,
267,
327,
710,
9195,
774,
2141,
6939,
8491,
314,
5164,
4396,
396,
363,
275,
1052,
401,
267,
327,
1314,
1380,
8876,
1901,
314,
2446,
5673,
1716,
1806,
16334,
267,
327,
1263,
636,
396,
363,
315,
922,
1233,
27,
440,
6387,
267,
23388,
275,
359,
3358,
774,
2141,
6939,
61,
398,
687,
1275,
492,
19090,
12,
6077,
3987,
3188,
3351,
267,
1067,
275,
26741
] |
[
636,
2443,
363,
492,
3679,
63,
646,
199,
199,
504,
1275,
3987,
11080,
492,
2198,
63,
504,
63,
5465,
12,
2624,
4003,
2998,
199,
504,
1275,
492,
5515,
2037,
371,
199,
504,
1275,
492,
653,
9568,
199,
504,
1275,
492,
5495,
421,
199,
533,
10172,
45,
26896,
2377,
7812,
8,
4323,
2037,
371,
14,
2377,
7812,
304,
339,
7246,
275,
756,
339,
347,
636,
826,
721,
277,
12,
2403,
12,
627,
589,
12,
1011,
829,
304,
267,
291,
14,
1861,
275,
2403,
267,
291,
14,
20747,
63,
2645,
275,
488,
267,
5515,
2037,
371,
14,
2377,
7812,
855,
826,
721,
277,
12,
627,
589,
12,
1011,
829,
9,
339,
347,
1050,
63,
17932,
63,
2373,
8,
277,
12,
536,
12,
2397,
12,
2086,
304,
267,
2397,
14,
2972,
275,
715,
267,
372,
1613,
8,
6932,
45,
26896,
2377,
7812,
12,
291,
680,
525,
63,
17932,
63,
2373,
8,
9144,
536,
12,
2397,
12,
2086,
9,
339,
347,
333,
4593,
8,
277,
12,
2403,
12,
536,
29,
403,
304,
267,
340,
536,
26,
288,
340,
2403,
315,
334,
46,
9568,
14,
466,
1113,
63,
1861,
12,
653,
9568,
14,
1532,
63,
1861,
12,
653,
9568,
14,
1391,
63,
1861,
12,
653,
9568,
14,
647,
1532,
63,
1861,
304,
355,
327,
17471,
12,
3992,
5423,
14,
7545,
282,
10250,
3247,
2403,
16174,
355,
327,
10250,
4550,
3140,
334,
1589,
1373,
3032,
370,
26741,
17505,
3034,
9,
355,
2403,
275,
291,
14,
1861,
288,
372,
2071,
83,
5,
83,
2,
450,
334,
1861,
12,
536,
9,
267,
587,
26,
288,
372,
5515,
2037,
371,
14,
2377,
7812,
14,
29602,
8,
277,
12,
2403,
9,
421,
199,
533,
26741,
17505,
3034,
2998,
8,
1558,
4003,
2998,
304,
272,
4194,
275,
488,
339,
347,
2342,
63,
578,
8,
277,
12,
859,
63,
354,
12,
3847,
63,
475,
29,
403,
12,
2086,
29,
403,
12,
1929,
63,
80,
2207,
29,
549,
12,
3679,
63,
10538,
29,
549,
304,
267,
340,
3847,
63,
475,
26,
288,
746,
9070,
480,
15277,
8925,
440,
3748,
315,
11420,
1233,
2685,
267,
340,
859,
63,
354,
1137,
291,
14,
578,
63,
354,
26,
288,
340,
859,
63,
354,
440,
315,
291,
14,
3112,
26,
355,
746,
9070,
480,
5903,
314,
29348,
286,
646,
365,
3748,
2685,
288,
587,
26,
355,
372,
291,
14,
3112,
59,
578,
63,
354,
61,
398,
340,
291,
14,
2645,
365,
488,
26,
288,
291,
14,
2645,
275,
10172,
45,
26896,
2377,
7812,
8,
355,
291,
14,
1861,
12,
859,
63,
354,
12,
1676,
63,
578,
29,
403,
12,
1067,
29,
277,
9,
398,
372,
291,
14,
2645,
421,
199,
533,
26741,
17505,
3034,
8,
3034,
14,
17505,
3034,
1563,
304,
272,
408,
272,
20511,
1233,
5313,
315,
314,
26741,
2637,
6337,
14,
339,
710,
768,
11690,
7531,
883,
663,
314,
22559,
367,
282,
805,
12,
1083,
402,
286,
318,
1021,
14,
272,
17471,
16225,
543,
768,
11690,
360,
67,
63,
1532,
63,
354,
358,
664,
314,
1627,
22559,
14,
339,
2104,
286,
318,
3992,
314,
4713,
787,
465,
11924,
26,
267,
1559,
2702,
420,
1035,
665,
11690,
30,
63,
1113,
267,
1559,
730,
12448,
259,
1035,
665,
11690,
30,
63,
466,
267,
3102,
260,
1035,
665,
533,
63,
11690,
30,
27718,
765,
63,
11690,
30,
339,
2104,
3102,
314,
22559,
7531,
365,
2716,
12,
1325,
1928,
314,
7531,
314,
272,
3102,
911,
440,
506,
19393,
68,
14,
1666,
26741,
14,
9131,
14,
9156,
898,
7812,
436,
272,
2295,
15,
1065,
15,
20747,
2645,
14,
25579,
367,
7251,
14,
272,
408,
339,
365,
63,
20747,
63,
16877,
275,
715,
339,
347,
636,
826,
721,
277,
12,
11512,
12,
536,
628,
363,
25579,
1974,
401,
2403,
8772,
5074,
29,
403,
12,
326,
570,
29,
403,
12,
687,
63,
2645,
29,
403,
12,
1067,
29,
403,
12,
6365,
63,
23216,
29,
403,
12,
326,
6890,
63,
578,
63,
2645,
29,
403,
304,
267,
327,
413,
9,
2136,
1929,
370,
7339,
314,
6057,
15,
6338,
12,
880,
626,
1006,
4621,
883,
506,
267,
327,
259,
8439,
1928,
492,
17222,
267,
327,
499,
9,
710,
2011,
11420,
1233,
909,
883,
506,
1202,
367,
3663,
1350,
1584,
27,
267,
327,
259,
1830,
314,
4046,
1031,
14416,
883,
506,
29815,
315,
314,
18653,
402,
282,
267,
327,
259,
2849,
570,
14,
267,
327,
869,
4894,
12,
7339,
1263,
6661,
5133,
2945,
14,
267,
340,
1067,
365,
440,
488,
26,
288,
11512,
275,
5495,
14,
954,
63,
808,
21492,
8,
5472,
12,
1067,
12,
570,
12,
536,
9,
267,
291,
14,
5472,
275,
11512,
267,
291,
14,
354,
275,
536,
267,
291,
14,
493,
275,
570,
267,
291,
14,
1861,
275,
2403,
267,
291,
14,
6537,
275,
5074,
503,
942,
267,
291,
14,
504,
63,
2645,
275,
687,
63,
2645,
267,
291,
14,
7837,
63,
578,
63,
2645,
275,
6890,
63,
578,
63,
2645,
267,
291,
14,
5772,
63,
23216,
275,
6365,
63,
23216,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
340,
1228,
8,
1848,
12,
26741,
17505,
3034,
304,
288,
372,
291,
423,
20982,
63,
1162,
342,
508,
1163,
423,
20982,
63,
1162,
342,
267,
587,
26,
288,
372,
756,
339,
347,
485,
20982,
63,
1162,
8,
277,
304,
267,
6890,
63,
2645,
275,
291,
14,
7837,
63,
578,
63,
2645,
267,
1830,
1228,
8,
7837,
63,
2645,
12,
10172,
45,
26896,
2377,
7812,
304,
288,
6890,
63,
2645,
275,
6890,
63,
2645,
14,
7837,
63,
2645,
267,
372,
291,
14,
5472,
12,
6890,
63,
2645,
12,
291,
14,
5772,
63,
23216,
339,
347,
636,
2227,
721,
277,
304,
267,
372,
2631,
8,
277,
14,
5472,
9,
339,
347,
664,
63,
2350,
8,
277,
12,
4811,
63,
2118,
29,
797,
12,
29348,
63,
2645,
29,
403,
304,
267,
687,
1275,
8014,
939,
3987,
3188,
3351,
492,
9195,
774,
2141,
6939,
267,
327,
710,
9195,
774,
2141,
6939,
8491,
314,
5164,
4396,
396,
363,
275,
1052,
401,
267,
327,
1314,
1380,
8876,
1901,
314,
2446,
5673,
1716,
1806,
16334,
267,
327,
1263,
636,
396,
363,
315,
922,
1233,
27,
440,
6387,
267,
23388,
275,
359,
3358,
774,
2141,
6939,
61,
398,
687,
1275,
492,
19090,
12,
6077,
3987,
3188,
3351,
267,
1067,
275,
26741,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
zenn1989/scoria-interlude
|
L2Jscoria-Game/data/scripts/quests/616_MagicalPowerOfFirePart2/__init__.py
|
1
|
6980
|
#Made by Emperorc
import sys
from com.l2scoria import Config
from com.l2scoria.gameserver.datatables.sql import SpawnTable
from com.l2scoria.gameserver.model.quest import State
from com.l2scoria.gameserver.model.quest import QuestState
from com.l2scoria.gameserver.model.quest.jython import QuestJython as JQuest
from com.l2scoria.gameserver.network.serverpackets import CreatureSay
from com.l2scoria.gameserver.util import Util
from java.lang import System
qn = "616_MagicalPowerOfFirePart2"
#NPC
Udan = 31379
Alter = 31558
#MOBS
Varka_Mobs = [ 21350, 21351, 21353, 21354, 21355, 21357, 21358, 21360, 21361, \
21362, 21369, 21370, 21364, 21365, 21366, 21368, 21371, 21372, 21373, 21374, 21375 ]
Nastron = 25306
#ITEMS
Totem2 = 7243
Fire_Heart = 7244
def FindTemplate (npcId) :
for spawn in SpawnTable.getInstance().getSpawnTable().values():
if spawn.getNpcid() == npcId:
npcinstance=spawn.getLastSpawn()
break
return npcinstance
def AutoChat(npc,text) :
chars = npc.getKnownList().getKnownPlayers().values().toArray()
if chars != None:
for pc in chars :
sm = CreatureSay(npc.getObjectId(), 0, npc.getName(), text)
pc.sendPacket(sm)
class Quest (JQuest) :
def __init__(self,id,name,descr): JQuest.__init__(self,id,name,descr)
def onAdvEvent (self, event, npc, player) :
st = player.getQuestState(qn)
if not st: return
cond = st.getInt("cond")
id = st.getInt("id")
Green_Totem = st.getQuestItemsCount(Totem2)
Heart = st.getQuestItemsCount(Fire_Heart)
htmltext = event
if event == "31379-04.htm" :
if st.getPlayer().getLevel() >= 75 and st.getPlayer().getAllianceWithVarkaKetra() <= -2 :
if Green_Totem :
st.set("cond","1")
st.set("id","1")
st.setState(STARTED)
st.playSound("ItemSound.quest_accept")
htmltext = "31379-04.htm"
else :
htmltext = "31379-02.htm"
st.exitQuest(1)
else :
htmltext = "31379-03.htm"
st.exitQuest(1)
elif event == "31379-08.htm" :
if Heart:
htmltext = "31379-08.htm"
st.takeItems(Fire_Heart,-1)
st.addExpAndSp(10000,0)
st.unset("id")
st.unset("cond")
st.playSound("ItemSound.quest_finish")
st.exitQuest(1)
else :
htmltext = "31379-09.htm"
elif event == "31558-02.htm" :
if Green_Totem :
time = self.loadGlobalQuestVar("killed")
if time.isdigit() :
if long(time) + 180 * 60000 > System.currentTimeMillis() :
return "The energy I felt at the altar is getting weaker."
self.deleteGlobalQuestVar("killed")
htmletext = "31558-02.htm" #TODO add lights from above
spawnedNpc = st.addSpawn(Nastron,142528,-82528,-6496)
st.takeItems(Totem2,1)
st.set("id","2")
npc.setBusy(True)
st.set("cond","2")
st.startQuestTimer("Soul of Fire Nastron has despawned",1200000,spawnedNpc)
AutoChat(spawnedNpc,"Hey! I'll kick your aarse!")#this is only a temp message until we find out what it actually is! string = 61050
else :
htmltext = "31558-04.htm"
elif event == "Soul of Fire Nastron has despawned" :
npc.reduceCurrentHp(9999999,npc)
st.unset("id")
st.unset("cond")
FindTemplate(Alter).setBusy(False)
st.exitQuest(1)
AutoChat(npc,"May the gods forever condemn you! Udan Mardui, your power weakens!") #this is only a temp message until we find out what it actually is! string = 61051
return htmltext
def onTalk (self, npc, player):
st = player.getQuestState(qn)
htmltext = "<html><body>You are either not carrying out your quest or don't meet the criteria.</body></html>"
if st :
npcId = npc.getNpcId()
cond = st.getInt("cond")
id = st.getInt("id")
Green_Totem = st.getQuestItemsCount(Totem2)
Heart = st.getQuestItemsCount(Fire_Heart)
if npcId == Udan :
if st.getState()== CREATED :
htmltext = "31379-01.htm"
elif id == 1 or id == 2 :
htmltext = "31379-05.htm"
elif id == 3:
if Heart :
htmltext = "31379-06.htm"
else :
htmltext = "31379-07.htm"
elif npcId == Alter :
if npc.isBusy() :
htmltext = "31558-03.htm"
else :
if id == 1 :
htmltext = "31558-01.htm"
elif id == 2 or id == 3 :
htmltext = "31558-05.htm"
return htmltext
def onKill(self,npc,player,isPet):
npcId = npc.getNpcId()
if npcId == Nastron :
self.saveGlobalQuestVar("killed", str(System.currentTimeMillis()))
FindTemplate(Alter).setBusy(False)
party = player.getParty()
if party :
for partyMember in party.getPartyMembers().toArray() :
pst = partyMember.getQuestState(qn)
if pst and Util.checkIfInRange(Config.ALT_PARTY_RANGE, player, partyMember, True) :
if pst.getInt("cond") >= 1 :
if pst.getInt("cond") == 1 :
pst.takeItems(Totem2,1)
if pst.getQuestItemsCount(Fire_Heart) < 1 :
pst.giveItems(Fire_Heart,1)
pst.playSound("ItemSound.quest_middle")
pst.set("cond","3")
pst.set("id","3")
if pst.getQuestTimer("Soul of Fire Nastron has despawned") :
pst.getQuestTimer("Soul of Fire Nastron has despawned").cancel()
else :
pst = player.getQuestState(qn)
if pst :
if pst.getInt("cond") >= 1 :
if pst.getInt("cond") == 1 :
pst.takeItems(Totem2,1)
if pst.getQuestItemsCount(Fire_Heart) < 1 :
pst.giveItems(Fire_Heart,1)
pst.playSound("ItemSound.quest_middle")
pst.set("cond","3")
pst.set("id","3")
if pst.getQuestTimer("Soul of Fire Nastron has despawned") :
pst.getQuestTimer("Soul of Fire Nastron has despawned").cancel()
elif npcId in Varka_Mobs :
st = player.getQuestState(qn)
if st :
if st.getQuestItemsCount(Fire_Heart) :
st.takeItems(Fire_Heart,-1)
st.unset("cond")
st.unset("id")
st.exitQuest(1)
return
QUEST = Quest(616,qn,"Magical Power of Fire - Part 2")
CREATED = State('Start', QUEST)
STARTED = State('Started', QUEST)
QUEST.setInitialState(CREATED)
QUEST.addStartNpc(Udan)
QUEST.addTalkId(Udan)
QUEST.addTalkId(Alter)
QUEST.addKillId(Nastron)
STARTED.addQuestDrop(Nastron,Fire_Heart,1)
for mobId in Varka_Mobs:
QUEST.addKillId(mobId)
|
gpl-3.0
|
[
3,
26973,
701,
662,
311,
281,
269,
67,
199,
646,
984,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
492,
4094,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
14,
5097,
1000,
14,
4616,
292,
5921,
14,
3009,
492,
17812,
3501,
3186,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
14,
5097,
1000,
14,
1238,
14,
613,
492,
8511,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
14,
5097,
1000,
14,
1238,
14,
613,
492,
1413,
5291,
2223,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
14,
5097,
1000,
14,
1238,
14,
613,
14,
27179,
492,
1413,
5291,
42,
11361,
465,
1603,
49,
5291,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
14,
5097,
1000,
14,
1200,
14,
1000,
18853,
492,
9750,
1463,
51,
1187,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
14,
5097,
1000,
14,
1974,
492,
21248,
199,
504,
12120,
14,
4159,
492,
6187,
199,
199,
15156,
275,
298,
26666,
63,
22745,
2652,
6921,
3466,
13081,
8416,
18,
2,
199,
199,
3,
46,
4222,
199,
53,
24863,
275,
650,
969,
1965,
199,
14364,
275,
650,
1046,
2010,
421,
199,
3,
2679,
11087,
199,
54,
1096,
65,
63,
3716,
1533,
275,
359,
499,
969,
1400,
12,
499,
969,
2869,
12,
499,
969,
2481,
12,
499,
969,
1477,
12,
499,
969,
1229,
12,
499,
969,
1641,
12,
499,
969,
2010,
12,
499,
969,
2259,
12,
499,
969,
2976,
12,
971,
199,
14271,
2789,
12,
499,
969,
1876,
12,
499,
969,
2760,
12,
499,
969,
772,
12,
499,
969,
2182,
12,
499,
969,
1272,
12,
499,
969,
2333,
12,
499,
969,
3172,
12,
499,
969,
2819,
12,
499,
969,
2898,
12,
499,
969,
1342,
12,
499,
969,
2194,
1622,
199,
8565,
495,
265,
275,
5661,
11363,
199,
199,
3,
10439,
51,
199,
1378,
563,
18,
275,
1520,
13440,
199,
13081,
63,
1966,
580,
275,
1520,
11603,
199,
199,
318,
6668,
4231,
334,
1590,
67,
1304,
9,
520,
272,
367,
15187,
315,
17812,
3501,
3186,
14,
29964,
1252,
362,
12739,
3501,
3186,
1252,
1459,
837,
267,
340,
15187,
14,
362,
46,
2352,
344,
342,
508,
980,
67,
1304,
26,
288,
980,
67,
842,
29,
10212,
14,
362,
6090,
12739,
3501,
342,
288,
2059,
272,
372,
980,
67,
842,
199,
199,
318,
9195,
21954,
8,
1590,
67,
12,
505,
9,
520,
272,
8365,
275,
980,
67,
14,
362,
24574,
1296,
1252,
362,
24574,
48,
4359,
1252,
1459,
1252,
475,
3836,
342,
272,
340,
8365,
1137,
488,
26,
2126,
367,
13171,
315,
8365,
520,
881,
4383,
275,
9750,
1463,
51,
1187,
8,
1590,
67,
14,
362,
1692,
1304,
1062,
378,
12,
980,
67,
14,
16405,
1062,
1318,
9,
881,
13171,
14,
2254,
2726,
8,
3300,
9,
199,
199,
533,
1413,
5291,
334,
42,
49,
5291,
9,
520,
421,
347,
636,
826,
721,
277,
12,
344,
12,
354,
12,
12113,
304,
1603,
49,
5291,
855,
826,
721,
277,
12,
344,
12,
354,
12,
12113,
9,
421,
347,
641,
2767,
86,
2390,
334,
277,
12,
1566,
12,
980,
67,
12,
7748,
9,
520,
2043,
410,
275,
7748,
14,
362,
49,
5291,
2223,
8,
15156,
9,
2043,
340,
440,
410,
26,
372,
2043,
9288,
275,
410,
14,
362,
3241,
480,
2067,
531,
2043,
1305,
275,
410,
14,
362,
3241,
480,
344,
531,
2043,
32585,
63,
1378,
563,
275,
410,
14,
362,
49,
5291,
7412,
2353,
8,
1378,
563,
18,
9,
2043,
5311,
580,
275,
410,
14,
362,
49,
5291,
7412,
2353,
8,
13081,
63,
1966,
580,
9,
2043,
3517,
505,
275,
1566,
2043,
340,
1566,
508,
298,
19455,
1965,
13,
966,
14,
15575,
2,
520,
2126,
340,
410,
14,
362,
10921,
1252,
362,
4670,
342,
2356,
13098,
436,
410,
14,
362,
10921,
1252,
362,
2439,
3636,
3007,
54,
1096,
65,
5018,
345,
342,
2695,
446,
18,
520,
1779,
340,
32585,
63,
1378,
563,
520,
355,
410,
14,
409,
480,
2067,
2266,
17,
531,
355,
410,
14,
409,
480,
344,
2266,
17,
531,
355,
410,
14,
409,
2223,
8,
32385,
9,
355,
410,
14,
2802,
18670,
480,
2081,
18670,
14,
613,
63,
5694,
531,
355,
3517,
505,
275,
298,
19455,
1965,
13,
966,
14,
15575,
2,
1779,
587,
520,
355,
3517,
505,
275,
298,
19455,
1965,
13,
996,
14,
15575,
2,
355,
410,
14,
2224,
49,
5291,
8,
17,
9,
2126,
587,
520,
1779,
3517,
505,
275,
298,
19455,
1965,
13,
1644,
14,
15575,
2,
1779,
410,
14,
2224,
49,
5291,
8,
17,
9,
2043,
916,
1566,
508,
298,
19455,
1965,
13,
2036,
14,
15575,
2,
520,
2126,
340,
5311,
580,
26,
1779,
3517,
505,
275,
298,
19455,
1965,
13,
2036,
14,
15575,
2,
1779,
410,
14,
11066,
7412,
8,
13081,
63,
1966,
580,
3057,
17,
9,
1779,
410,
14,
525,
4527,
3325,
5058,
8,
9943,
12,
16,
9,
1779,
410,
14,
16787,
480,
344,
531,
1779,
410,
14,
16787,
480,
2067,
531,
1779,
410,
14,
2802,
18670,
480,
2081,
18670,
14,
613,
63,
8192,
531,
1779,
410,
14,
2224,
49,
5291,
8,
17,
9,
2126,
587,
520,
1779,
3517,
505,
275,
298,
19455,
1965,
13,
1643,
14,
15575,
2,
8410,
916,
1566,
508,
298,
9927,
2010,
13,
996,
14,
15575,
2,
520,
2126,
340,
32585,
63,
1378,
563,
520,
268,
900,
275,
291,
14,
912,
7025,
49,
5291,
5894,
480,
75,
14535,
531,
268,
340,
900,
14,
13896,
342,
520,
1779,
340,
1846,
8,
521,
9,
435,
13576,
627,
1227,
993,
690,
6187,
14,
1818,
1366,
30145,
83,
342,
520,
1467,
372,
298,
1918,
12304,
473,
289,
15330,
737,
314,
741,
5369,
365,
10232,
9282,
281,
2122,
268,
291,
14,
1807,
7025,
49,
5291,
5894,
480,
75,
14535,
531,
268,
1243,
29198,
505,
275,
298,
9927,
2010,
13,
996,
14,
15575,
2,
257,
327,
11768,
1050,
10540,
83,
687,
3432,
268,
15187,
379,
46,
2352,
275,
410,
14,
525,
12739,
3501,
8,
8565,
495,
265,
12,
1079,
821,
1651,
3057,
29208,
1651,
3057,
772,
2534,
9,
268,
410,
14,
11066,
7412,
8,
1378,
563,
18,
12,
17,
9,
268,
410,
14,
409,
480,
344,
2266,
18,
531,
268,
980,
67,
14,
409,
28759,
8,
549,
9,
268,
410,
14,
409,
480,
2067,
2266,
18,
531,
268,
410,
14,
928,
49,
5291,
7929,
480
] |
[
26973,
701,
662,
311,
281,
269,
67,
199,
646,
984,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
492,
4094,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
14,
5097,
1000,
14,
4616,
292,
5921,
14,
3009,
492,
17812,
3501,
3186,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
14,
5097,
1000,
14,
1238,
14,
613,
492,
8511,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
14,
5097,
1000,
14,
1238,
14,
613,
492,
1413,
5291,
2223,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
14,
5097,
1000,
14,
1238,
14,
613,
14,
27179,
492,
1413,
5291,
42,
11361,
465,
1603,
49,
5291,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
14,
5097,
1000,
14,
1200,
14,
1000,
18853,
492,
9750,
1463,
51,
1187,
199,
504,
2414,
14,
76,
18,
551,
269,
4674,
14,
5097,
1000,
14,
1974,
492,
21248,
199,
504,
12120,
14,
4159,
492,
6187,
199,
199,
15156,
275,
298,
26666,
63,
22745,
2652,
6921,
3466,
13081,
8416,
18,
2,
199,
199,
3,
46,
4222,
199,
53,
24863,
275,
650,
969,
1965,
199,
14364,
275,
650,
1046,
2010,
421,
199,
3,
2679,
11087,
199,
54,
1096,
65,
63,
3716,
1533,
275,
359,
499,
969,
1400,
12,
499,
969,
2869,
12,
499,
969,
2481,
12,
499,
969,
1477,
12,
499,
969,
1229,
12,
499,
969,
1641,
12,
499,
969,
2010,
12,
499,
969,
2259,
12,
499,
969,
2976,
12,
971,
199,
14271,
2789,
12,
499,
969,
1876,
12,
499,
969,
2760,
12,
499,
969,
772,
12,
499,
969,
2182,
12,
499,
969,
1272,
12,
499,
969,
2333,
12,
499,
969,
3172,
12,
499,
969,
2819,
12,
499,
969,
2898,
12,
499,
969,
1342,
12,
499,
969,
2194,
1622,
199,
8565,
495,
265,
275,
5661,
11363,
199,
199,
3,
10439,
51,
199,
1378,
563,
18,
275,
1520,
13440,
199,
13081,
63,
1966,
580,
275,
1520,
11603,
199,
199,
318,
6668,
4231,
334,
1590,
67,
1304,
9,
520,
272,
367,
15187,
315,
17812,
3501,
3186,
14,
29964,
1252,
362,
12739,
3501,
3186,
1252,
1459,
837,
267,
340,
15187,
14,
362,
46,
2352,
344,
342,
508,
980,
67,
1304,
26,
288,
980,
67,
842,
29,
10212,
14,
362,
6090,
12739,
3501,
342,
288,
2059,
272,
372,
980,
67,
842,
199,
199,
318,
9195,
21954,
8,
1590,
67,
12,
505,
9,
520,
272,
8365,
275,
980,
67,
14,
362,
24574,
1296,
1252,
362,
24574,
48,
4359,
1252,
1459,
1252,
475,
3836,
342,
272,
340,
8365,
1137,
488,
26,
2126,
367,
13171,
315,
8365,
520,
881,
4383,
275,
9750,
1463,
51,
1187,
8,
1590,
67,
14,
362,
1692,
1304,
1062,
378,
12,
980,
67,
14,
16405,
1062,
1318,
9,
881,
13171,
14,
2254,
2726,
8,
3300,
9,
199,
199,
533,
1413,
5291,
334,
42,
49,
5291,
9,
520,
421,
347,
636,
826,
721,
277,
12,
344,
12,
354,
12,
12113,
304,
1603,
49,
5291,
855,
826,
721,
277,
12,
344,
12,
354,
12,
12113,
9,
421,
347,
641,
2767,
86,
2390,
334,
277,
12,
1566,
12,
980,
67,
12,
7748,
9,
520,
2043,
410,
275,
7748,
14,
362,
49,
5291,
2223,
8,
15156,
9,
2043,
340,
440,
410,
26,
372,
2043,
9288,
275,
410,
14,
362,
3241,
480,
2067,
531,
2043,
1305,
275,
410,
14,
362,
3241,
480,
344,
531,
2043,
32585,
63,
1378,
563,
275,
410,
14,
362,
49,
5291,
7412,
2353,
8,
1378,
563,
18,
9,
2043,
5311,
580,
275,
410,
14,
362,
49,
5291,
7412,
2353,
8,
13081,
63,
1966,
580,
9,
2043,
3517,
505,
275,
1566,
2043,
340,
1566,
508,
298,
19455,
1965,
13,
966,
14,
15575,
2,
520,
2126,
340,
410,
14,
362,
10921,
1252,
362,
4670,
342,
2356,
13098,
436,
410,
14,
362,
10921,
1252,
362,
2439,
3636,
3007,
54,
1096,
65,
5018,
345,
342,
2695,
446,
18,
520,
1779,
340,
32585,
63,
1378,
563,
520,
355,
410,
14,
409,
480,
2067,
2266,
17,
531,
355,
410,
14,
409,
480,
344,
2266,
17,
531,
355,
410,
14,
409,
2223,
8,
32385,
9,
355,
410,
14,
2802,
18670,
480,
2081,
18670,
14,
613,
63,
5694,
531,
355,
3517,
505,
275,
298,
19455,
1965,
13,
966,
14,
15575,
2,
1779,
587,
520,
355,
3517,
505,
275,
298,
19455,
1965,
13,
996,
14,
15575,
2,
355,
410,
14,
2224,
49,
5291,
8,
17,
9,
2126,
587,
520,
1779,
3517,
505,
275,
298,
19455,
1965,
13,
1644,
14,
15575,
2,
1779,
410,
14,
2224,
49,
5291,
8,
17,
9,
2043,
916,
1566,
508,
298,
19455,
1965,
13,
2036,
14,
15575,
2,
520,
2126,
340,
5311,
580,
26,
1779,
3517,
505,
275,
298,
19455,
1965,
13,
2036,
14,
15575,
2,
1779,
410,
14,
11066,
7412,
8,
13081,
63,
1966,
580,
3057,
17,
9,
1779,
410,
14,
525,
4527,
3325,
5058,
8,
9943,
12,
16,
9,
1779,
410,
14,
16787,
480,
344,
531,
1779,
410,
14,
16787,
480,
2067,
531,
1779,
410,
14,
2802,
18670,
480,
2081,
18670,
14,
613,
63,
8192,
531,
1779,
410,
14,
2224,
49,
5291,
8,
17,
9,
2126,
587,
520,
1779,
3517,
505,
275,
298,
19455,
1965,
13,
1643,
14,
15575,
2,
8410,
916,
1566,
508,
298,
9927,
2010,
13,
996,
14,
15575,
2,
520,
2126,
340,
32585,
63,
1378,
563,
520,
268,
900,
275,
291,
14,
912,
7025,
49,
5291,
5894,
480,
75,
14535,
531,
268,
340,
900,
14,
13896,
342,
520,
1779,
340,
1846,
8,
521,
9,
435,
13576,
627,
1227,
993,
690,
6187,
14,
1818,
1366,
30145,
83,
342,
520,
1467,
372,
298,
1918,
12304,
473,
289,
15330,
737,
314,
741,
5369,
365,
10232,
9282,
281,
2122,
268,
291,
14,
1807,
7025,
49,
5291,
5894,
480,
75,
14535,
531,
268,
1243,
29198,
505,
275,
298,
9927,
2010,
13,
996,
14,
15575,
2,
257,
327,
11768,
1050,
10540,
83,
687,
3432,
268,
15187,
379,
46,
2352,
275,
410,
14,
525,
12739,
3501,
8,
8565,
495,
265,
12,
1079,
821,
1651,
3057,
29208,
1651,
3057,
772,
2534,
9,
268,
410,
14,
11066,
7412,
8,
1378,
563,
18,
12,
17,
9,
268,
410,
14,
409,
480,
344,
2266,
18,
531,
268,
980,
67,
14,
409,
28759,
8,
549,
9,
268,
410,
14,
409,
480,
2067,
2266,
18,
531,
268,
410,
14,
928,
49,
5291,
7929,
480,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
wuga214/Django-Wuga
|
env/lib/python2.7/site-packages/django/core/management/commands/makemessages.py
|
48
|
26302
|
from __future__ import unicode_literals
import fnmatch
import glob
import io
import os
import re
import sys
from functools import total_ordering
from itertools import dropwhile
import django
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.files.temp import NamedTemporaryFile
from django.core.management.base import BaseCommand, CommandError
from django.core.management.utils import (
find_command, handle_extensions, popen_wrapper,
)
from django.utils._os import upath
from django.utils.encoding import DEFAULT_LOCALE_ENCODING, force_str
from django.utils.functional import cached_property
from django.utils.jslex import prepare_js_for_gettext
from django.utils.text import get_text_list
from django.utils.translation import templatize
plural_forms_re = re.compile(r'^(?P<value>"Plural-Forms.+?\\n")\s*$', re.MULTILINE | re.DOTALL)
STATUS_OK = 0
NO_LOCALE_DIR = object()
def check_programs(*programs):
for program in programs:
if find_command(program) is None:
raise CommandError(
"Can't find %s. Make sure you have GNU gettext tools 0.15 or "
"newer installed." % program
)
@total_ordering
class TranslatableFile(object):
def __init__(self, dirpath, file_name, locale_dir):
self.file = file_name
self.dirpath = dirpath
self.locale_dir = locale_dir
def __repr__(self):
return "<%s: %s>" % (
self.__class__.__name__,
os.sep.join([self.dirpath, self.file]),
)
def __eq__(self, other):
return self.path == other.path
def __lt__(self, other):
return self.path < other.path
@property
def path(self):
return os.path.join(self.dirpath, self.file)
class BuildFile(object):
"""
Represents the state of a translatable file during the build process.
"""
def __init__(self, command, domain, translatable):
self.command = command
self.domain = domain
self.translatable = translatable
@cached_property
def is_templatized(self):
if self.domain == 'djangojs':
return self.command.gettext_version < (0, 18, 3)
elif self.domain == 'django':
file_ext = os.path.splitext(self.translatable.file)[1]
return file_ext != '.py'
return False
@cached_property
def path(self):
return self.translatable.path
@cached_property
def work_path(self):
"""
Path to a file which is being fed into GNU gettext pipeline. This may
be either a translatable or its preprocessed version.
"""
if not self.is_templatized:
return self.path
extension = {
'djangojs': 'c',
'django': 'py',
}.get(self.domain)
filename = '%s.%s' % (self.translatable.file, extension)
return os.path.join(self.translatable.dirpath, filename)
def preprocess(self):
"""
Preprocess (if necessary) a translatable file before passing it to
xgettext GNU gettext utility.
"""
if not self.is_templatized:
return
encoding = settings.FILE_CHARSET if self.command.settings_available else 'utf-8'
with io.open(self.path, 'r', encoding=encoding) as fp:
src_data = fp.read()
if self.domain == 'djangojs':
content = prepare_js_for_gettext(src_data)
elif self.domain == 'django':
content = templatize(src_data, origin=self.path[2:], charset=encoding)
with io.open(self.work_path, 'w', encoding='utf-8') as fp:
fp.write(content)
def postprocess_messages(self, msgs):
"""
Postprocess messages generated by xgettext GNU gettext utility.
Transform paths as if these messages were generated from original
translatable files rather than from preprocessed versions.
"""
if not self.is_templatized:
return msgs
# Remove '.py' suffix
if os.name == 'nt':
# Preserve '.\' prefix on Windows to respect gettext behavior
old_path = self.work_path
new_path = self.path
else:
old_path = self.work_path[2:]
new_path = self.path[2:]
return re.sub(
r'^(#: .*)(' + re.escape(old_path) + r')',
lambda match: match.group().replace(old_path, new_path),
msgs,
flags=re.MULTILINE
)
def cleanup(self):
"""
Remove a preprocessed copy of a translatable file (if any).
"""
if self.is_templatized:
# This check is needed for the case of a symlinked file and its
# source being processed inside a single group (locale dir);
# removing either of those two removes both.
if os.path.exists(self.work_path):
os.unlink(self.work_path)
def normalize_eols(raw_contents):
"""
Take a block of raw text that will be passed through str.splitlines() to
get universal newlines treatment.
Return the resulting block of text with normalized `\n` EOL sequences ready
to be written to disk using current platform's native EOLs.
"""
lines_list = raw_contents.splitlines()
# Ensure last line has its EOL
if lines_list and lines_list[-1]:
lines_list.append('')
return '\n'.join(lines_list)
def write_pot_file(potfile, msgs):
"""
Write the :param potfile: POT file with the :param msgs: contents,
previously making sure its format is valid.
"""
pot_lines = msgs.splitlines()
if os.path.exists(potfile):
# Strip the header
lines = dropwhile(len, pot_lines)
else:
lines = []
found, header_read = False, False
for line in pot_lines:
if not found and not header_read:
found = True
line = line.replace('charset=CHARSET', 'charset=UTF-8')
if not line and not found:
header_read = True
lines.append(line)
msgs = '\n'.join(lines)
with io.open(potfile, 'a', encoding='utf-8') as fp:
fp.write(msgs)
class Command(BaseCommand):
help = (
"Runs over the entire source tree of the current directory and "
"pulls out all strings marked for translation. It creates (or updates) a message "
"file in the conf/locale (in the django tree) or locale (for projects and "
"applications) directory.\n\nYou must run this command with one of either the "
"--locale, --exclude, or --all options."
)
translatable_file_class = TranslatableFile
build_file_class = BuildFile
requires_system_checks = False
leave_locale_alone = True
msgmerge_options = ['-q', '--previous']
msguniq_options = ['--to-code=utf-8']
msgattrib_options = ['--no-obsolete']
xgettext_options = ['--from-code=UTF-8', '--add-comments=Translators']
def add_arguments(self, parser):
parser.add_argument(
'--locale', '-l', default=[], dest='locale', action='append',
help='Creates or updates the message files for the given locale(s) (e.g. pt_BR). '
'Can be used multiple times.',
)
parser.add_argument(
'--exclude', '-x', default=[], dest='exclude', action='append',
help='Locales to exclude. Default is none. Can be used multiple times.',
)
parser.add_argument(
'--domain', '-d', default='django', dest='domain',
help='The domain of the message files (default: "django").',
)
parser.add_argument(
'--all', '-a', action='store_true', dest='all', default=False,
help='Updates the message files for all existing locales.',
)
parser.add_argument(
'--extension', '-e', dest='extensions', action='append',
help='The file extension(s) to examine (default: "html,txt,py", or "js" '
'if the domain is "djangojs"). Separate multiple extensions with '
'commas, or use -e multiple times.',
)
parser.add_argument(
'--symlinks', '-s', action='store_true', dest='symlinks', default=False,
help='Follows symlinks to directories when examining source code '
'and templates for translation strings.',
)
parser.add_argument(
'--ignore', '-i', action='append', dest='ignore_patterns',
default=[], metavar='PATTERN',
help='Ignore files or directories matching this glob-style pattern. '
'Use multiple times to ignore more.',
)
parser.add_argument(
'--no-default-ignore', action='store_false', dest='use_default_ignore_patterns',
default=True, help="Don't ignore the common glob-style patterns 'CVS', '.*', '*~' and '*.pyc'.",
)
parser.add_argument(
'--no-wrap', action='store_true', dest='no_wrap',
default=False, help="Don't break long message lines into several lines.",
)
parser.add_argument(
'--no-location', action='store_true', dest='no_location',
default=False, help="Don't write '#: filename:line' lines.",
)
parser.add_argument(
'--no-obsolete', action='store_true', dest='no_obsolete',
default=False, help="Remove obsolete message strings.",
)
parser.add_argument(
'--keep-pot', action='store_true', dest='keep_pot',
default=False, help="Keep .pot file after making messages. Useful when debugging.",
)
def handle(self, *args, **options):
locale = options['locale']
exclude = options['exclude']
self.domain = options['domain']
self.verbosity = options['verbosity']
process_all = options['all']
extensions = options['extensions']
self.symlinks = options['symlinks']
ignore_patterns = options['ignore_patterns']
if options['use_default_ignore_patterns']:
ignore_patterns += ['CVS', '.*', '*~', '*.pyc']
self.ignore_patterns = list(set(ignore_patterns))
# Avoid messing with mutable class variables
if options['no_wrap']:
self.msgmerge_options = self.msgmerge_options[:] + ['--no-wrap']
self.msguniq_options = self.msguniq_options[:] + ['--no-wrap']
self.msgattrib_options = self.msgattrib_options[:] + ['--no-wrap']
self.xgettext_options = self.xgettext_options[:] + ['--no-wrap']
if options['no_location']:
self.msgmerge_options = self.msgmerge_options[:] + ['--no-location']
self.msguniq_options = self.msguniq_options[:] + ['--no-location']
self.msgattrib_options = self.msgattrib_options[:] + ['--no-location']
self.xgettext_options = self.xgettext_options[:] + ['--no-location']
self.no_obsolete = options['no_obsolete']
self.keep_pot = options['keep_pot']
if self.domain not in ('django', 'djangojs'):
raise CommandError("currently makemessages only supports domains "
"'django' and 'djangojs'")
if self.domain == 'djangojs':
exts = extensions if extensions else ['js']
else:
exts = extensions if extensions else ['html', 'txt', 'py']
self.extensions = handle_extensions(exts)
if (locale is None and not exclude and not process_all) or self.domain is None:
raise CommandError(
"Type '%s help %s' for usage information."
% (os.path.basename(sys.argv[0]), sys.argv[1])
)
if self.verbosity > 1:
self.stdout.write(
'examining files with the extensions: %s\n'
% get_text_list(list(self.extensions), 'and')
)
self.invoked_for_django = False
self.locale_paths = []
self.default_locale_path = None
if os.path.isdir(os.path.join('conf', 'locale')):
self.locale_paths = [os.path.abspath(os.path.join('conf', 'locale'))]
self.default_locale_path = self.locale_paths[0]
self.invoked_for_django = True
else:
if self.settings_available:
self.locale_paths.extend(settings.LOCALE_PATHS)
# Allow to run makemessages inside an app dir
if os.path.isdir('locale'):
self.locale_paths.append(os.path.abspath('locale'))
if self.locale_paths:
self.default_locale_path = self.locale_paths[0]
if not os.path.exists(self.default_locale_path):
os.makedirs(self.default_locale_path)
# Build locale list
locale_dirs = filter(os.path.isdir, glob.glob('%s/*' % self.default_locale_path))
all_locales = map(os.path.basename, locale_dirs)
# Account for excluded locales
if process_all:
locales = all_locales
else:
locales = locale or all_locales
locales = set(locales) - set(exclude)
if locales:
check_programs('msguniq', 'msgmerge', 'msgattrib')
check_programs('xgettext')
try:
potfiles = self.build_potfiles()
# Build po files for each selected locale
for locale in locales:
if self.verbosity > 0:
self.stdout.write("processing locale %s\n" % locale)
for potfile in potfiles:
self.write_po_file(potfile, locale)
finally:
if not self.keep_pot:
self.remove_potfiles()
@cached_property
def gettext_version(self):
# Gettext tools will output system-encoded bytestrings instead of UTF-8,
# when looking up the version. It's especially a problem on Windows.
out, err, status = popen_wrapper(
['xgettext', '--version'],
stdout_encoding=DEFAULT_LOCALE_ENCODING,
)
m = re.search(r'(\d+)\.(\d+)\.?(\d+)?', out)
if m:
return tuple(int(d) for d in m.groups() if d is not None)
else:
raise CommandError("Unable to get gettext version. Is it installed?")
@cached_property
def settings_available(self):
try:
settings.LOCALE_PATHS
except ImproperlyConfigured:
if self.verbosity > 1:
self.stderr.write("Running without configured settings.")
return False
return True
def build_potfiles(self):
"""
Build pot files and apply msguniq to them.
"""
file_list = self.find_files(".")
self.remove_potfiles()
self.process_files(file_list)
potfiles = []
for path in self.locale_paths:
potfile = os.path.join(path, '%s.pot' % str(self.domain))
if not os.path.exists(potfile):
continue
args = ['msguniq'] + self.msguniq_options + [potfile]
msgs, errors, status = popen_wrapper(args)
if errors:
if status != STATUS_OK:
raise CommandError(
"errors happened while running msguniq\n%s" % errors)
elif self.verbosity > 0:
self.stdout.write(errors)
msgs = normalize_eols(msgs)
with io.open(potfile, 'w', encoding='utf-8') as fp:
fp.write(msgs)
potfiles.append(potfile)
return potfiles
def remove_potfiles(self):
for path in self.locale_paths:
pot_path = os.path.join(path, '%s.pot' % str(self.domain))
if os.path.exists(pot_path):
os.unlink(pot_path)
def find_files(self, root):
"""
Helper method to get all files in the given root. Also check that there
is a matching locale dir for each file.
"""
def is_ignored(path, ignore_patterns):
"""
Check if the given path should be ignored or not.
"""
filename = os.path.basename(path)
def ignore(pattern):
return fnmatch.fnmatchcase(filename, pattern) or fnmatch.fnmatchcase(path, pattern)
return any(ignore(pattern) for pattern in ignore_patterns)
ignore_patterns = [os.path.normcase(p) for p in self.ignore_patterns]
dir_suffixes = {'%s*' % path_sep for path_sep in {'/', os.sep}}
norm_patterns = []
for p in ignore_patterns:
for dir_suffix in dir_suffixes:
if p.endswith(dir_suffix):
norm_patterns.append(p[:-len(dir_suffix)])
break
else:
norm_patterns.append(p)
all_files = []
ignored_roots = []
if self.settings_available:
ignored_roots = [os.path.normpath(p) for p in (settings.MEDIA_ROOT, settings.STATIC_ROOT) if p]
for dirpath, dirnames, filenames in os.walk(root, topdown=True, followlinks=self.symlinks):
for dirname in dirnames[:]:
if (is_ignored(os.path.normpath(os.path.join(dirpath, dirname)), norm_patterns) or
os.path.join(os.path.abspath(dirpath), dirname) in ignored_roots):
dirnames.remove(dirname)
if self.verbosity > 1:
self.stdout.write('ignoring directory %s\n' % dirname)
elif dirname == 'locale':
dirnames.remove(dirname)
self.locale_paths.insert(0, os.path.join(os.path.abspath(dirpath), dirname))
for filename in filenames:
file_path = os.path.normpath(os.path.join(dirpath, filename))
file_ext = os.path.splitext(filename)[1]
if file_ext not in self.extensions or is_ignored(file_path, self.ignore_patterns):
if self.verbosity > 1:
self.stdout.write('ignoring file %s in %s\n' % (filename, dirpath))
else:
locale_dir = None
for path in self.locale_paths:
if os.path.abspath(dirpath).startswith(os.path.dirname(path)):
locale_dir = path
break
if not locale_dir:
locale_dir = self.default_locale_path
if not locale_dir:
locale_dir = NO_LOCALE_DIR
all_files.append(self.translatable_file_class(dirpath, filename, locale_dir))
return sorted(all_files)
def process_files(self, file_list):
"""
Group translatable files by locale directory and run pot file build
process for each group.
"""
file_groups = {}
for translatable in file_list:
file_group = file_groups.setdefault(translatable.locale_dir, [])
file_group.append(translatable)
for locale_dir, files in file_groups.items():
self.process_locale_dir(locale_dir, files)
def process_locale_dir(self, locale_dir, files):
"""
Extract translatable literals from the specified files, creating or
updating the POT file for a given locale directory.
Uses the xgettext GNU gettext utility.
"""
build_files = []
for translatable in files:
if self.verbosity > 1:
self.stdout.write('processing file %s in %s\n' % (
translatable.file, translatable.dirpath
))
if self.domain not in ('djangojs', 'django'):
continue
build_file = self.build_file_class(self, self.domain, translatable)
try:
build_file.preprocess()
except UnicodeDecodeError as e:
self.stdout.write(
'UnicodeDecodeError: skipped file %s in %s (reason: %s)' % (
translatable.file, translatable.dirpath, e,
)
)
continue
build_files.append(build_file)
if self.domain == 'djangojs':
is_templatized = build_file.is_templatized
args = [
'xgettext',
'-d', self.domain,
'--language=%s' % ('C' if is_templatized else 'JavaScript',),
'--keyword=gettext_noop',
'--keyword=gettext_lazy',
'--keyword=ngettext_lazy:1,2',
'--keyword=pgettext:1c,2',
'--keyword=npgettext:1c,2,3',
'--output=-',
]
elif self.domain == 'django':
args = [
'xgettext',
'-d', self.domain,
'--language=Python',
'--keyword=gettext_noop',
'--keyword=gettext_lazy',
'--keyword=ngettext_lazy:1,2',
'--keyword=ugettext_noop',
'--keyword=ugettext_lazy',
'--keyword=ungettext_lazy:1,2',
'--keyword=pgettext:1c,2',
'--keyword=npgettext:1c,2,3',
'--keyword=pgettext_lazy:1c,2',
'--keyword=npgettext_lazy:1c,2,3',
'--output=-',
]
else:
return
input_files = [bf.work_path for bf in build_files]
with NamedTemporaryFile(mode='w+') as input_files_list:
input_files_list.write(force_str('\n'.join(input_files), encoding=DEFAULT_LOCALE_ENCODING))
input_files_list.flush()
args.extend(['--files-from', input_files_list.name])
args.extend(self.xgettext_options)
msgs, errors, status = popen_wrapper(args)
if errors:
if status != STATUS_OK:
for build_file in build_files:
build_file.cleanup()
raise CommandError(
'errors happened while running xgettext on %s\n%s' %
('\n'.join(input_files), errors)
)
elif self.verbosity > 0:
# Print warnings
self.stdout.write(errors)
if msgs:
if locale_dir is NO_LOCALE_DIR:
file_path = os.path.normpath(build_files[0].path)
raise CommandError(
'Unable to find a locale path to store translations for '
'file %s' % file_path
)
for build_file in build_files:
msgs = build_file.postprocess_messages(msgs)
potfile = os.path.join(locale_dir, '%s.pot' % str(self.domain))
write_pot_file(potfile, msgs)
for build_file in build_files:
build_file.cleanup()
def write_po_file(self, potfile, locale):
"""
Creates or updates the PO file for self.domain and :param locale:.
Uses contents of the existing :param potfile:.
Uses msgmerge, and msgattrib GNU gettext utilities.
"""
basedir = os.path.join(os.path.dirname(potfile), locale, 'LC_MESSAGES')
if not os.path.isdir(basedir):
os.makedirs(basedir)
pofile = os.path.join(basedir, '%s.po' % str(self.domain))
if os.path.exists(pofile):
args = ['msgmerge'] + self.msgmerge_options + [pofile, potfile]
msgs, errors, status = popen_wrapper(args)
if errors:
if status != STATUS_OK:
raise CommandError(
"errors happened while running msgmerge\n%s" % errors)
elif self.verbosity > 0:
self.stdout.write(errors)
else:
with io.open(potfile, 'r', encoding='utf-8') as fp:
msgs = fp.read()
if not self.invoked_for_django:
msgs = self.copy_plural_forms(msgs, locale)
msgs = normalize_eols(msgs)
msgs = msgs.replace(
"#. #-#-#-#-# %s.pot (PACKAGE VERSION) #-#-#-#-#\n" % self.domain, "")
with io.open(pofile, 'w', encoding='utf-8') as fp:
fp.write(msgs)
if self.no_obsolete:
args = ['msgattrib'] + self.msgattrib_options + ['-o', pofile, pofile]
msgs, errors, status = popen_wrapper(args)
if errors:
if status != STATUS_OK:
raise CommandError(
"errors happened while running msgattrib\n%s" % errors)
elif self.verbosity > 0:
self.stdout.write(errors)
def copy_plural_forms(self, msgs, locale):
"""
Copies plural forms header contents from a Django catalog of locale to
the msgs string, inserting it at the right place. msgs should be the
contents of a newly created .po file.
"""
django_dir = os.path.normpath(os.path.join(os.path.dirname(upath(django.__file__))))
if self.domain == 'djangojs':
domains = ('djangojs', 'django')
else:
domains = ('django',)
for domain in domains:
django_po = os.path.join(django_dir, 'conf', 'locale', locale, 'LC_MESSAGES', '%s.po' % domain)
if os.path.exists(django_po):
with io.open(django_po, 'r', encoding='utf-8') as fp:
m = plural_forms_re.search(fp.read())
if m:
plural_form_line = force_str(m.group('value'))
if self.verbosity > 1:
self.stdout.write("copying plural forms: %s\n" % plural_form_line)
lines = []
found = False
for line in msgs.splitlines():
if not found and (not line or plural_forms_re.search(line)):
line = plural_form_line
found = True
lines.append(line)
msgs = '\n'.join(lines)
break
return msgs
|
apache-2.0
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
15951,
199,
646,
5739,
199,
646,
5890,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
504,
9143,
492,
3141,
63,
7128,
199,
504,
7975,
492,
5978,
6710,
199,
199,
646,
1639,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
1725,
14,
808,
492,
31825,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1208,
492,
334,
272,
2342,
63,
1531,
12,
2429,
63,
5359,
12,
17758,
63,
5029,
12,
199,
9,
199,
504,
1639,
14,
1208,
423,
736,
492,
1536,
1619,
199,
504,
1639,
14,
1208,
14,
2991,
492,
6186,
63,
20828,
63,
16314,
12,
3542,
63,
495,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
199,
504,
1639,
14,
1208,
14,
3596,
3113,
492,
9275,
63,
3596,
63,
509,
63,
5152,
199,
504,
1639,
14,
1208,
14,
505,
492,
664,
63,
505,
63,
513,
199,
504,
1639,
14,
1208,
14,
6893,
492,
2388,
416,
30510,
199,
199,
10019,
63,
3351,
63,
264,
275,
295,
14,
2014,
8,
82,
24550,
48,
28,
585,
4335,
3714,
4889,
13,
26028,
11198,
1103,
78,
27681,
83,
32125,
295,
14,
16661,
1204,
295,
14,
16504,
9,
199,
6305,
63,
3593,
275,
378,
199,
2826,
63,
20828,
63,
3022,
275,
909,
342,
421,
199,
318,
1104,
63,
28464,
2031,
28464,
304,
272,
367,
2240,
315,
18572,
26,
267,
340,
2342,
63,
1531,
8,
6815,
9,
365,
488,
26,
288,
746,
14393,
8,
355,
298,
6049,
1133,
2342,
450,
83,
14,
4155,
3238,
1265,
1172,
1664,
9796,
7249,
378,
14,
1046,
503,
298,
355,
298,
1222,
281,
4903,
2122,
450,
2240,
288,
776,
421,
199,
32,
2923,
63,
7128,
199,
533,
6266,
25099,
1173,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
20648,
12,
570,
63,
354,
12,
5867,
63,
694,
304,
267,
291,
14,
493,
275,
570,
63,
354,
267,
291,
14,
17254,
275,
20648,
267,
291,
14,
5508,
63,
694,
275,
5867,
63,
694,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
26,
450,
83,
4335,
450,
334,
288,
291,
855,
533,
4914,
354,
3108,
288,
747,
14,
4127,
14,
904,
779,
277,
14,
17254,
12,
291,
14,
493,
2522,
267,
776,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
515,
508,
1163,
14,
515,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
515,
665,
1163,
14,
515,
339,
768,
1829,
272,
347,
931,
8,
277,
304,
267,
372,
747,
14,
515,
14,
904,
8,
277,
14,
17254,
12,
291,
14,
493,
9,
421,
199,
533,
6516,
1173,
8,
785,
304,
272,
408,
272,
21591,
314,
1174,
402,
282,
1752,
25099,
570,
5309,
314,
1900,
2112,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1414,
12,
2881,
12,
1752,
25099,
304,
267,
291,
14,
1531,
275,
1414,
267,
291,
14,
2261,
275,
2881,
267,
291,
14,
1515,
25099,
275,
1752,
25099,
339,
768,
5245,
63,
1829,
272,
347,
365,
63,
808,
416,
22927,
8,
277,
304,
267,
340,
291,
14,
2261,
508,
283,
1176,
3596,
356,
288,
372,
291,
14,
1531,
14,
5152,
63,
1023,
665,
334,
16,
12,
6155,
12,
650,
9,
267,
916,
291,
14,
2261,
508,
283,
1176,
356,
288,
570,
63,
832,
275,
747,
14,
515,
14,
7973,
8,
277,
14,
1515,
25099,
14,
493,
2788,
17,
61,
288,
372,
570,
63,
832,
1137,
1987,
647,
7,
267,
372,
756,
339,
768,
5245,
63,
1829,
272,
347,
931,
8,
277,
304,
267,
372,
291,
14,
1515,
25099,
14,
515,
339,
768,
5245,
63,
1829,
272,
347,
1736,
63,
515,
8,
277,
304,
267,
408,
267,
6912,
370,
282,
570,
1314,
365,
3769,
23036,
1901,
1664,
9796,
7679,
14,
961,
1443,
267,
506,
1902,
282,
1752,
25099,
503,
2399,
876,
7292,
1015,
14,
267,
408,
267,
340,
440,
291,
14,
374,
63,
808,
416,
22927,
26,
288,
372,
291,
14,
515,
267,
3329,
275,
469,
288,
283,
1176,
3596,
356,
283,
67,
297,
288,
283,
1176,
356,
283,
647,
297,
267,
789,
14,
362,
8,
277,
14,
2261,
9,
267,
1788,
275,
1543,
83,
4111,
83,
7,
450,
334,
277,
14,
1515,
25099,
14,
493,
12,
3329,
9,
267,
372,
747,
14,
515,
14,
904,
8,
277,
14,
1515,
25099,
14,
17254,
12,
1788,
9,
339,
347,
23351,
8,
277,
304,
267,
408,
267,
5543,
1412,
334,
692,
5784,
9,
282,
1752,
25099,
570,
2544,
9476,
652,
370,
267,
671,
5152,
1664,
9796,
11420,
14,
267,
408,
267,
340,
440,
291,
14,
374,
63,
808,
416,
22927,
26,
288,
372,
398,
2644,
275,
2202,
14,
3817,
63,
23969,
340,
291,
14,
1531,
14,
1751,
63,
4561,
587,
283,
1624,
13,
24,
7,
267,
543,
5890,
14,
1490,
8,
277,
14,
515,
12,
283,
82,
297,
2644,
29,
2991,
9,
465,
4090,
26,
288,
2928,
63,
576,
275,
4090,
14,
739,
342,
398,
340,
291,
14,
2261,
508,
283,
1176,
3596,
356,
288,
1564,
275,
9275,
63,
3596,
63,
509,
63,
5152,
8,
2164,
63,
576,
9,
267,
916,
291,
14,
2261,
508,
283,
1176,
356,
288,
1564,
275,
2388,
416,
30510,
8,
2164,
63,
576,
12,
6330,
29,
277,
14,
515,
59,
18,
8429,
5960,
29,
2991,
9,
398,
543,
5890,
14,
1490,
8,
277,
14,
800,
63,
515,
12,
283,
87,
297,
2644,
534,
1624,
13,
24,
358,
465,
4090,
26,
288,
4090,
14,
952,
8,
1317,
9,
339,
347,
2963,
1412,
63,
3431,
8,
277,
12,
17599,
304,
267,
408,
267,
7711,
1412,
3788,
4046,
701,
671,
5152,
1664,
9796,
11420,
14,
398,
19463,
3792,
465,
340,
3520,
3788,
4898,
4046,
687,
3379,
267,
1752,
25099,
1584,
7830,
2419,
687,
876,
7292,
5459,
14,
267,
408,
267,
340,
440,
291,
14,
374,
63,
808,
416,
22927,
26,
288,
372,
17599,
398,
327,
5852,
1987,
647,
7,
4739,
267,
340,
747,
14,
354,
508,
283,
343,
356,
288,
327,
5543,
4909,
1987,
3985,
2403,
641,
5417,
370,
14021,
9796,
5953,
288,
2269,
63,
515,
275
] |
[
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
15951,
199,
646,
5739,
199,
646,
5890,
199,
646,
747,
199,
646,
295,
199,
646,
984,
199,
504,
9143,
492,
3141,
63,
7128,
199,
504,
7975,
492,
5978,
6710,
199,
199,
646,
1639,
199,
504,
1639,
14,
2190,
492,
2202,
199,
504,
1639,
14,
1018,
14,
3924,
492,
11897,
199,
504,
1639,
14,
1018,
14,
1725,
14,
808,
492,
31825,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1095,
492,
22239,
12,
14393,
199,
504,
1639,
14,
1018,
14,
8110,
14,
1208,
492,
334,
272,
2342,
63,
1531,
12,
2429,
63,
5359,
12,
17758,
63,
5029,
12,
199,
9,
199,
504,
1639,
14,
1208,
423,
736,
492,
1536,
1619,
199,
504,
1639,
14,
1208,
14,
2991,
492,
6186,
63,
20828,
63,
16314,
12,
3542,
63,
495,
199,
504,
1639,
14,
1208,
14,
15481,
492,
6328,
63,
1829,
199,
504,
1639,
14,
1208,
14,
3596,
3113,
492,
9275,
63,
3596,
63,
509,
63,
5152,
199,
504,
1639,
14,
1208,
14,
505,
492,
664,
63,
505,
63,
513,
199,
504,
1639,
14,
1208,
14,
6893,
492,
2388,
416,
30510,
199,
199,
10019,
63,
3351,
63,
264,
275,
295,
14,
2014,
8,
82,
24550,
48,
28,
585,
4335,
3714,
4889,
13,
26028,
11198,
1103,
78,
27681,
83,
32125,
295,
14,
16661,
1204,
295,
14,
16504,
9,
199,
6305,
63,
3593,
275,
378,
199,
2826,
63,
20828,
63,
3022,
275,
909,
342,
421,
199,
318,
1104,
63,
28464,
2031,
28464,
304,
272,
367,
2240,
315,
18572,
26,
267,
340,
2342,
63,
1531,
8,
6815,
9,
365,
488,
26,
288,
746,
14393,
8,
355,
298,
6049,
1133,
2342,
450,
83,
14,
4155,
3238,
1265,
1172,
1664,
9796,
7249,
378,
14,
1046,
503,
298,
355,
298,
1222,
281,
4903,
2122,
450,
2240,
288,
776,
421,
199,
32,
2923,
63,
7128,
199,
533,
6266,
25099,
1173,
8,
785,
304,
272,
347,
636,
826,
721,
277,
12,
20648,
12,
570,
63,
354,
12,
5867,
63,
694,
304,
267,
291,
14,
493,
275,
570,
63,
354,
267,
291,
14,
17254,
275,
20648,
267,
291,
14,
5508,
63,
694,
275,
5867,
63,
694,
339,
347,
636,
2722,
721,
277,
304,
267,
372,
23054,
83,
26,
450,
83,
4335,
450,
334,
288,
291,
855,
533,
4914,
354,
3108,
288,
747,
14,
4127,
14,
904,
779,
277,
14,
17254,
12,
291,
14,
493,
2522,
267,
776,
339,
347,
636,
4077,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
515,
508,
1163,
14,
515,
339,
347,
636,
4116,
721,
277,
12,
1163,
304,
267,
372,
291,
14,
515,
665,
1163,
14,
515,
339,
768,
1829,
272,
347,
931,
8,
277,
304,
267,
372,
747,
14,
515,
14,
904,
8,
277,
14,
17254,
12,
291,
14,
493,
9,
421,
199,
533,
6516,
1173,
8,
785,
304,
272,
408,
272,
21591,
314,
1174,
402,
282,
1752,
25099,
570,
5309,
314,
1900,
2112,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
1414,
12,
2881,
12,
1752,
25099,
304,
267,
291,
14,
1531,
275,
1414,
267,
291,
14,
2261,
275,
2881,
267,
291,
14,
1515,
25099,
275,
1752,
25099,
339,
768,
5245,
63,
1829,
272,
347,
365,
63,
808,
416,
22927,
8,
277,
304,
267,
340,
291,
14,
2261,
508,
283,
1176,
3596,
356,
288,
372,
291,
14,
1531,
14,
5152,
63,
1023,
665,
334,
16,
12,
6155,
12,
650,
9,
267,
916,
291,
14,
2261,
508,
283,
1176,
356,
288,
570,
63,
832,
275,
747,
14,
515,
14,
7973,
8,
277,
14,
1515,
25099,
14,
493,
2788,
17,
61,
288,
372,
570,
63,
832,
1137,
1987,
647,
7,
267,
372,
756,
339,
768,
5245,
63,
1829,
272,
347,
931,
8,
277,
304,
267,
372,
291,
14,
1515,
25099,
14,
515,
339,
768,
5245,
63,
1829,
272,
347,
1736,
63,
515,
8,
277,
304,
267,
408,
267,
6912,
370,
282,
570,
1314,
365,
3769,
23036,
1901,
1664,
9796,
7679,
14,
961,
1443,
267,
506,
1902,
282,
1752,
25099,
503,
2399,
876,
7292,
1015,
14,
267,
408,
267,
340,
440,
291,
14,
374,
63,
808,
416,
22927,
26,
288,
372,
291,
14,
515,
267,
3329,
275,
469,
288,
283,
1176,
3596,
356,
283,
67,
297,
288,
283,
1176,
356,
283,
647,
297,
267,
789,
14,
362,
8,
277,
14,
2261,
9,
267,
1788,
275,
1543,
83,
4111,
83,
7,
450,
334,
277,
14,
1515,
25099,
14,
493,
12,
3329,
9,
267,
372,
747,
14,
515,
14,
904,
8,
277,
14,
1515,
25099,
14,
17254,
12,
1788,
9,
339,
347,
23351,
8,
277,
304,
267,
408,
267,
5543,
1412,
334,
692,
5784,
9,
282,
1752,
25099,
570,
2544,
9476,
652,
370,
267,
671,
5152,
1664,
9796,
11420,
14,
267,
408,
267,
340,
440,
291,
14,
374,
63,
808,
416,
22927,
26,
288,
372,
398,
2644,
275,
2202,
14,
3817,
63,
23969,
340,
291,
14,
1531,
14,
1751,
63,
4561,
587,
283,
1624,
13,
24,
7,
267,
543,
5890,
14,
1490,
8,
277,
14,
515,
12,
283,
82,
297,
2644,
29,
2991,
9,
465,
4090,
26,
288,
2928,
63,
576,
275,
4090,
14,
739,
342,
398,
340,
291,
14,
2261,
508,
283,
1176,
3596,
356,
288,
1564,
275,
9275,
63,
3596,
63,
509,
63,
5152,
8,
2164,
63,
576,
9,
267,
916,
291,
14,
2261,
508,
283,
1176,
356,
288,
1564,
275,
2388,
416,
30510,
8,
2164,
63,
576,
12,
6330,
29,
277,
14,
515,
59,
18,
8429,
5960,
29,
2991,
9,
398,
543,
5890,
14,
1490,
8,
277,
14,
800,
63,
515,
12,
283,
87,
297,
2644,
534,
1624,
13,
24,
358,
465,
4090,
26,
288,
4090,
14,
952,
8,
1317,
9,
339,
347,
2963,
1412,
63,
3431,
8,
277,
12,
17599,
304,
267,
408,
267,
7711,
1412,
3788,
4046,
701,
671,
5152,
1664,
9796,
11420,
14,
398,
19463,
3792,
465,
340,
3520,
3788,
4898,
4046,
687,
3379,
267,
1752,
25099,
1584,
7830,
2419,
687,
876,
7292,
5459,
14,
267,
408,
267,
340,
440,
291,
14,
374,
63,
808,
416,
22927,
26,
288,
372,
17599,
398,
327,
5852,
1987,
647,
7,
4739,
267,
340,
747,
14,
354,
508,
283,
343,
356,
288,
327,
5543,
4909,
1987,
3985,
2403,
641,
5417,
370,
14021,
9796,
5953,
288,
2269,
63,
515,
275,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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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
] |
wujinjun/TFbook
|
chapter5/models-master/syntaxnet/dragnn/tools/build_pip_package.py
|
2
|
2371
|
"""Builds a pip package suitable for redistribution.
Adapted from tensorflow/tools/pip_package/build_pip_package.sh. This might have
to change if Bazel changes how it modifies paths.
"""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import argparse
import glob
import os
import shutil
import subprocess
import sys
import tempfile
import dragnn
import tensorflow
def main():
cmd_args = argparse.ArgumentParser()
cmd_args.add_argument("--include-tensorflow", action="store_true")
cmd_args.add_argument("--output-dir", required=True)
args = cmd_args.parse_args()
if not os.path.isdir(args.output_dir):
raise EnvironmentError(
"Output directory {} doesn't exist".format(args.output_dir))
elif not args.output_dir.startswith("/"):
raise EnvironmentError("Please pass an absolute path to --output-dir.")
tmp_packaging = tempfile.mkdtemp()
runfiles, = (path for path in sys.path
if path.endswith("build_pip_package.runfiles"))
# Use the dragnn and tensorflow modules to resolve specific paths in the
# runfiles directory. Current Bazel puts dragnn in a __main__ subdirectory,
# for example.
lib_path = os.path.abspath(dragnn.__file__)
if runfiles not in lib_path:
raise EnvironmentError("WARNING: Unexpected PYTHONPATH set by Bazel :(")
base_dir = os.path.dirname(os.path.dirname(lib_path))
tensorflow_dir = os.path.dirname(tensorflow.__file__)
if runfiles not in tensorflow_dir:
raise EnvironmentError("WARNING: Unexpected tf PYTHONPATH set by Bazel :(")
# Copy the files.
subprocess.check_call([
"cp", "-r",
"--no-preserve=all", os.path.join(base_dir, "dragnn"), os.path.join(
base_dir, "syntaxnet"), tmp_packaging
])
if args.include_tensorflow:
subprocess.check_call(
["cp", "-r", "--no-preserve=all", tensorflow_dir, tmp_packaging])
shutil.copy(
os.path.join(base_dir, "dragnn/tools/oss_setup.py"),
os.path.join(tmp_packaging, "setup.py"))
subprocess.check_output(
["python", "setup.py", "bdist_wheel"], cwd=tmp_packaging)
wheel, = glob.glob("{}/*.whl".format(os.path.join(tmp_packaging, "dist")))
shutil.move(wheel, args.output_dir)
print(
"Wrote {}".format(os.path.join(args.output_dir, os.path.basename(wheel))))
if __name__ == "__main__":
main()
|
gpl-3.0
|
[
624,
27856,
282,
7305,
2559,
11233,
367,
295,
4972,
14,
199,
199,
2767,
18309,
687,
3228,
15,
2537,
15,
9983,
63,
2491,
15,
1506,
63,
9983,
63,
2491,
14,
609,
14,
961,
5594,
1172,
199,
475,
1570,
340,
699,
4651,
352,
4493,
4212,
652,
26473,
3792,
14,
199,
624,
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,
7534,
199,
646,
5739,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
646,
5549,
199,
199,
646,
366,
345,
784,
78,
199,
646,
3228,
421,
199,
318,
2446,
837,
523,
2088,
63,
589,
275,
7534,
14,
10730,
342,
523,
2088,
63,
589,
14,
525,
63,
2094,
6739,
2613,
13,
16008,
401,
1595,
628,
1617,
63,
2052,
531,
523,
2088,
63,
589,
14,
525,
63,
2094,
6739,
1199,
13,
694,
401,
1415,
29,
549,
9,
523,
1249,
275,
2088,
63,
589,
14,
1122,
63,
589,
342,
523,
340,
440,
747,
14,
515,
14,
6027,
8,
589,
14,
1199,
63,
694,
304,
272,
746,
25139,
8,
267,
298,
2959,
2082,
1052,
3181,
1133,
2187,
1674,
908,
8,
589,
14,
1199,
63,
694,
430,
523,
916,
440,
1249,
14,
1199,
63,
694,
14,
2460,
4769,
2349,
272,
746,
25139,
480,
8254,
986,
376,
3679,
931,
370,
1553,
1199,
13,
694,
2685,
819,
3529,
63,
27796,
275,
5549,
14,
11983,
342,
523,
1255,
1725,
12,
275,
334,
515,
367,
931,
315,
984,
14,
515,
2049,
340,
931,
14,
4130,
480,
1506,
63,
9983,
63,
2491,
14,
1065,
1725,
2237,
819,
327,
3645,
314,
366,
345,
784,
78,
436,
3228,
4621,
370,
7512,
2488,
3792,
315,
314,
523,
327,
1255,
1725,
2082,
14,
9338,
699,
4651,
352,
27000,
366,
345,
784,
78,
315,
282,
636,
973,
363,
25094,
12,
523,
327,
367,
2893,
14,
523,
1973,
63,
515,
275,
747,
14,
515,
14,
4832,
8,
28385,
784,
78,
855,
493,
3368,
523,
340,
1255,
1725,
440,
315,
1973,
63,
515,
26,
272,
746,
25139,
480,
9171,
26,
25345,
31176,
663,
701,
699,
4651,
352,
520,
480,
9,
523,
1300,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
773,
63,
515,
430,
523,
3228,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
16008,
855,
493,
3368,
523,
340,
1255,
1725,
440,
315,
3228,
63,
694,
26,
272,
746,
25139,
480,
9171,
26,
25345,
2833,
31176,
663,
701,
699,
4651,
352,
520,
480,
9,
819,
327,
11247,
314,
1584,
14,
523,
3873,
14,
1074,
63,
1250,
779,
489,
298,
1850,
401,
3905,
82,
401,
489,
4320,
889,
13,
17053,
29,
452,
401,
747,
14,
515,
14,
904,
8,
1095,
63,
694,
12,
298,
28385,
784,
78,
1288,
747,
14,
515,
14,
904,
8,
881,
1300,
63,
694,
12,
298,
7093,
846,
1288,
3529,
63,
27796,
523,
4794,
523,
340,
1249,
14,
2613,
63,
16008,
26,
272,
3873,
14,
1074,
63,
1250,
8,
267,
2097,
1850,
401,
3905,
82,
401,
4320,
889,
13,
17053,
29,
452,
401,
3228,
63,
694,
12,
3529,
63,
27796,
566,
523,
5145,
14,
1574,
8,
489,
747,
14,
515,
14,
904,
8,
1095,
63,
694,
12,
298,
28385,
784,
78,
15,
2537,
15,
26890,
63,
2758,
14,
647,
1288,
489,
747,
14,
515,
14,
904,
8,
2791,
63,
27796,
12,
298,
2758,
14,
647,
2237,
523,
3873,
14,
1074,
63,
1199,
8,
489,
2097,
1548,
401,
298,
2758,
14,
647,
401,
298,
17403,
63,
11798,
2255,
8288,
29,
2791,
63,
27796,
9,
523,
9989,
12,
275,
5739,
14,
6463,
20794,
20362,
2191,
76,
1674,
908,
8,
736,
14,
515,
14,
904,
8,
2791,
63,
27796,
12,
298,
2686,
13324,
819,
5145,
14,
1185,
8,
11798,
12,
1249,
14,
1199,
63,
694,
9,
523,
870,
8,
489,
298,
55,
22665,
8352,
908,
8,
736,
14,
515,
14,
904,
8,
589,
14,
1199,
63,
694,
12,
747,
14,
515,
14,
4846,
8,
11798,
7845,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
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
] |
[
27856,
282,
7305,
2559,
11233,
367,
295,
4972,
14,
199,
199,
2767,
18309,
687,
3228,
15,
2537,
15,
9983,
63,
2491,
15,
1506,
63,
9983,
63,
2491,
14,
609,
14,
961,
5594,
1172,
199,
475,
1570,
340,
699,
4651,
352,
4493,
4212,
652,
26473,
3792,
14,
199,
624,
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,
7534,
199,
646,
5739,
199,
646,
747,
199,
646,
5145,
199,
646,
3873,
199,
646,
984,
199,
646,
5549,
199,
199,
646,
366,
345,
784,
78,
199,
646,
3228,
421,
199,
318,
2446,
837,
523,
2088,
63,
589,
275,
7534,
14,
10730,
342,
523,
2088,
63,
589,
14,
525,
63,
2094,
6739,
2613,
13,
16008,
401,
1595,
628,
1617,
63,
2052,
531,
523,
2088,
63,
589,
14,
525,
63,
2094,
6739,
1199,
13,
694,
401,
1415,
29,
549,
9,
523,
1249,
275,
2088,
63,
589,
14,
1122,
63,
589,
342,
523,
340,
440,
747,
14,
515,
14,
6027,
8,
589,
14,
1199,
63,
694,
304,
272,
746,
25139,
8,
267,
298,
2959,
2082,
1052,
3181,
1133,
2187,
1674,
908,
8,
589,
14,
1199,
63,
694,
430,
523,
916,
440,
1249,
14,
1199,
63,
694,
14,
2460,
4769,
2349,
272,
746,
25139,
480,
8254,
986,
376,
3679,
931,
370,
1553,
1199,
13,
694,
2685,
819,
3529,
63,
27796,
275,
5549,
14,
11983,
342,
523,
1255,
1725,
12,
275,
334,
515,
367,
931,
315,
984,
14,
515,
2049,
340,
931,
14,
4130,
480,
1506,
63,
9983,
63,
2491,
14,
1065,
1725,
2237,
819,
327,
3645,
314,
366,
345,
784,
78,
436,
3228,
4621,
370,
7512,
2488,
3792,
315,
314,
523,
327,
1255,
1725,
2082,
14,
9338,
699,
4651,
352,
27000,
366,
345,
784,
78,
315,
282,
636,
973,
363,
25094,
12,
523,
327,
367,
2893,
14,
523,
1973,
63,
515,
275,
747,
14,
515,
14,
4832,
8,
28385,
784,
78,
855,
493,
3368,
523,
340,
1255,
1725,
440,
315,
1973,
63,
515,
26,
272,
746,
25139,
480,
9171,
26,
25345,
31176,
663,
701,
699,
4651,
352,
520,
480,
9,
523,
1300,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
736,
14,
515,
14,
3475,
8,
773,
63,
515,
430,
523,
3228,
63,
694,
275,
747,
14,
515,
14,
3475,
8,
16008,
855,
493,
3368,
523,
340,
1255,
1725,
440,
315,
3228,
63,
694,
26,
272,
746,
25139,
480,
9171,
26,
25345,
2833,
31176,
663,
701,
699,
4651,
352,
520,
480,
9,
819,
327,
11247,
314,
1584,
14,
523,
3873,
14,
1074,
63,
1250,
779,
489,
298,
1850,
401,
3905,
82,
401,
489,
4320,
889,
13,
17053,
29,
452,
401,
747,
14,
515,
14,
904,
8,
1095,
63,
694,
12,
298,
28385,
784,
78,
1288,
747,
14,
515,
14,
904,
8,
881,
1300,
63,
694,
12,
298,
7093,
846,
1288,
3529,
63,
27796,
523,
4794,
523,
340,
1249,
14,
2613,
63,
16008,
26,
272,
3873,
14,
1074,
63,
1250,
8,
267,
2097,
1850,
401,
3905,
82,
401,
4320,
889,
13,
17053,
29,
452,
401,
3228,
63,
694,
12,
3529,
63,
27796,
566,
523,
5145,
14,
1574,
8,
489,
747,
14,
515,
14,
904,
8,
1095,
63,
694,
12,
298,
28385,
784,
78,
15,
2537,
15,
26890,
63,
2758,
14,
647,
1288,
489,
747,
14,
515,
14,
904,
8,
2791,
63,
27796,
12,
298,
2758,
14,
647,
2237,
523,
3873,
14,
1074,
63,
1199,
8,
489,
2097,
1548,
401,
298,
2758,
14,
647,
401,
298,
17403,
63,
11798,
2255,
8288,
29,
2791,
63,
27796,
9,
523,
9989,
12,
275,
5739,
14,
6463,
20794,
20362,
2191,
76,
1674,
908,
8,
736,
14,
515,
14,
904,
8,
2791,
63,
27796,
12,
298,
2686,
13324,
819,
5145,
14,
1185,
8,
11798,
12,
1249,
14,
1199,
63,
694,
9,
523,
870,
8,
489,
298,
55,
22665,
8352,
908,
8,
736,
14,
515,
14,
904,
8,
589,
14,
1199,
63,
694,
12,
747,
14,
515,
14,
4846,
8,
11798,
7845,
421,
199,
692,
636,
354,
363,
508,
4396,
973,
5727,
523,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2014-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/>.
#
##############################################################################
from functools import partial
from openerp import SUPERUSER_ID
from openerp.osv import osv, fields
class report_paperformat(osv.Model):
_name = "report.paperformat"
_description = "Allows customization of a report."
_columns = {'name': fields.char('Name', required=True),
'default': fields.boolean('Default paper format ?'),
'format': fields.selection([('A0', 'A0 5 841 x 1189 mm'),
('A1', 'A1 6 594 x 841 mm'),
('A2', 'A2 7 420 x 594 mm'),
('A3', 'A3 8 297 x 420 mm'),
('A4', 'A4 0 210 x 297 mm, 8.26 x 11.69 inches'),
('A5', 'A5 9 148 x 210 mm'),
('A6', 'A6 10 105 x 148 mm'),
('A7', 'A7 11 74 x 105 mm'),
('A8', 'A8 12 52 x 74 mm'),
('A9', 'A9 13 37 x 52 mm'),
('B0', 'B0 14 1000 x 1414 mm'),
('B1', 'B1 15 707 x 1000 mm'),
('B2', 'B2 17 500 x 707 mm'),
('B3', 'B3 18 353 x 500 mm'),
('B4', 'B4 19 250 x 353 mm'),
('B5', 'B5 1 176 x 250 mm, 6.93 x 9.84 inches'),
('B6', 'B6 20 125 x 176 mm'),
('B7', 'B7 21 88 x 125 mm'),
('B8', 'B8 22 62 x 88 mm'),
('B9', 'B9 23 33 x 62 mm'),
('B10', ':B10 16 31 x 44 mm'),
('C5E', 'C5E 24 163 x 229 mm'),
('Comm10E', 'Comm10E 25 105 x 241 mm, U.S. '
'Common 10 Envelope'),
('DLE', 'DLE 26 110 x 220 mm'),
('Executive', 'Executive 4 7.5 x 10 inches, '
'190.5 x 254 mm'),
('Folio', 'Folio 27 210 x 330 mm'),
('Ledger', 'Ledger 28 431.8 x 279.4 mm'),
('Legal', 'Legal 3 8.5 x 14 inches, '
'215.9 x 355.6 mm'),
('Letter', 'Letter 2 8.5 x 11 inches, '
'215.9 x 279.4 mm'),
('Tabloid', 'Tabloid 29 279.4 x 431.8 mm'),
('custom', 'Custom')],
'Paper size',
help="Select Proper Paper size"),
'margin_top': fields.integer('Top Margin (mm)'),
'margin_bottom': fields.integer('Bottom Margin (mm)'),
'margin_left': fields.integer('Left Margin (mm)'),
'margin_right': fields.integer('Right Margin (mm)'),
'page_height': fields.integer('Page height (mm)'),
'page_width': fields.integer('Page width (mm)'),
'orientation': fields.selection([('Landscape', 'Landscape'),
('Portrait', 'Portrait')],
'Orientation'),
'header_line': fields.boolean('Display a header line'),
'header_spacing': fields.integer('Header spacing'),
'dpi': fields.integer('Output DPI', required=True),
'report_ids': fields.one2many('ir.actions.report.xml',
'paperformat_id',
'Associated reports',
help="Explicitly associated reports")
}
def _check_format_or_page(self, cr, uid, ids, context=None):
for paperformat in self.browse(cr, uid, ids, context=context):
if paperformat.format != 'custom' and (paperformat.page_width or paperformat.page_height):
return False
return True
_constraints = [
(_check_format_or_page, 'Error ! You cannot select a format AND speficic '
'page width/height.', ['format']),
]
_defaults = {
'format': 'A4',
'margin_top': 40,
'margin_bottom': 20,
'margin_left': 7,
'margin_right': 7,
'page_height': False,
'page_width': False,
'orientation': 'Landscape',
'header_line': False,
'header_spacing': 35,
'dpi': 90,
}
class res_company(osv.Model):
_inherit = 'res.company'
_columns = {'paperformat_id': fields.many2one('report.paperformat', 'Paper format')}
def init(self, cr):
# set a default paperformat based on rml one.
ref = partial(self.pool['ir.model.data'].xmlid_to_res_id, cr, SUPERUSER_ID)
ids = self.search(cr, SUPERUSER_ID, [('paperformat_id', '=', False)])
for company in self.browse(cr, SUPERUSER_ID, ids):
paperformat_id = {
'a4': ref('report.paperformat_euro'),
'us_letter': ref('report.paperformat_us'),
}.get(company.rml_paper_format) or ref('report.paperformat_euro')
if paperformat_id:
company.write({'paperformat_id': paperformat_id})
sup = super(res_company, self)
if hasattr(sup, 'init'):
sup.init(cr)
class ir_actions_report(osv.Model):
_inherit = 'ir.actions.report.xml'
def associated_view(self, cr, uid, ids, context):
"""Used in the ir.actions.report.xml form view in order to search naively after the view(s)
used in the rendering.
"""
try:
report_name = self.browse(cr, uid, ids[0], context).report_name
act_window_obj = self.pool.get('ir.actions.act_window')
view_action = act_window_obj.for_xml_id(cr, uid, 'base', 'action_ui_view', context=context)
view_action['domain'] = [('name', 'ilike', report_name.split('.')[1]), ('type', '=', 'qweb')]
return view_action
except:
return False
_columns = {'paperformat_id': fields.many2one('report.paperformat', 'Paper format')}
|
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,
6927,
13,
31982,
7653,
13950,
8642,
1014,
921,
1544,
14,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
9143,
492,
7417,
199,
199,
504,
5166,
492,
12824,
63,
998,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
421,
199,
533,
3622,
63,
10443,
908,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
298,
3070,
14,
10443,
908,
2,
272,
485,
1802,
275,
298,
19780,
32715,
402,
282,
3622,
2122,
339,
485,
3406,
275,
791,
354,
356,
1504,
14,
1560,
360,
985,
297,
1415,
29,
549,
395,
355,
283,
885,
356,
1504,
14,
4871,
360,
2698,
15220,
1475,
5805,
659,
355,
283,
908,
356,
1504,
14,
5592,
8318,
33,
16,
297,
283,
33,
16,
221,
959,
257,
8264,
17,
671,
413,
11370,
8562,
659,
4490,
661,
33,
17,
297,
283,
33,
17,
221,
1227,
257,
959,
2635,
671,
8264,
17,
8562,
659,
4490,
661,
33,
18,
297,
283,
33,
18,
221,
1520,
257,
841,
1165,
671,
959,
2635,
8562,
659,
4490,
661,
33,
19,
297,
283,
33,
19,
221,
1695,
257,
499,
2576,
671,
841,
1165,
8562,
659,
4490,
661,
33,
20,
297,
283,
33,
20,
221,
378,
257,
26160,
671,
499,
2576,
8562,
12,
1695,
14,
1479,
671,
4119,
14,
1876,
315,
12253,
659,
4490,
661,
33,
21,
297,
283,
33,
21,
221,
1749,
257,
30300,
671,
26160,
8562,
659,
4490,
661,
33,
22,
297,
283,
33,
22,
221,
1616,
221,
20462,
671,
30300,
8562,
659,
4490,
661,
33,
23,
297,
283,
33,
23,
221,
4119,
221,
9720,
671,
20462,
8562,
659,
4490,
661,
33,
24,
297,
283,
33,
24,
221,
3144,
221,
14589,
671,
9720,
8562,
659,
4490,
661,
33,
25,
297,
283,
33,
25,
221,
4944,
221,
6877,
671,
14589,
8562,
659,
4490,
661,
34,
16,
297,
283,
34,
16,
221,
4329,
221,
5198,
671,
4329,
1079,
8562,
659,
4490,
661,
34,
17,
297,
283,
34,
17,
221,
4114,
221,
1520,
1780,
671,
5198,
8562,
659,
4490,
661,
34,
18,
297,
283,
34,
18,
221,
5557,
221,
6891,
671,
1520,
1780,
8562,
659,
4490,
661,
34,
19,
297,
283,
34,
19,
221,
6155,
221,
650,
2481,
671,
6891,
8562,
659,
4490,
661,
34,
20,
297,
283,
34,
20,
221,
5851,
221,
16074,
671,
650,
2481,
8562,
659,
4490,
661,
34,
21,
297,
283,
34,
21,
221,
413,
257,
27827,
671,
16074,
8562,
12,
1227,
14,
3129,
671,
1749,
14,
1349,
315,
12253,
659,
4490,
661,
34,
22,
297,
283,
34,
22,
221,
3388,
221,
19163,
671,
27827,
8562,
659,
4490,
661,
34,
23,
297,
283,
34,
23,
221,
7829,
221,
10523,
671,
19163,
8562,
659,
4490,
661,
34,
24,
297,
283,
34,
24,
221,
6928,
221,
16202,
671,
10523,
8562,
659,
4490,
661,
34,
25,
297,
283,
34,
25,
221,
6546,
221,
9404,
671,
16202,
8562,
659,
4490,
661,
34,
709,
297,
7596,
34,
709,
259,
3193,
221,
7105,
671,
10868,
8562,
659,
4490,
661,
35,
21,
37,
297,
283,
35,
21,
37,
5504,
221,
24619,
671,
499,
1398,
8562,
659,
4490,
661,
5150,
709,
37,
297,
283,
5150,
709,
37,
5661,
221,
20462,
671,
499,
2953,
8562,
12,
738,
14,
51,
14,
283,
6163,
283,
7844,
1616,
29143,
659,
4490,
661,
36,
906,
297,
283,
36,
906,
7875,
16814,
671,
25647,
8562,
659,
4490,
661,
4858,
13441,
297,
283,
4858,
13441,
841,
257,
1520,
14,
21,
671,
1616,
315,
12253,
12,
283,
6163,
283,
12205,
14,
21,
671,
22540,
8562,
659,
4490,
661,
15563,
14437,
297,
283,
15563,
14437,
8087,
221,
26160,
671,
13540,
8562,
659,
4490,
661,
44,
379,
836,
297,
283,
44,
379,
836,
221,
7294,
221,
841,
2192,
14,
24,
671,
499,
1965,
14,
20,
8562,
659,
4490,
661,
13257,
279,
297,
283,
13257,
279,
259,
650,
257,
1695,
14,
21,
671,
4329,
315,
12253,
12,
283,
6163,
283,
7842,
14,
25,
671,
650,
1229,
14,
22,
8562,
659,
4490,
661,
23496,
297,
283,
23496,
499,
1695,
14,
21,
671,
4119,
315,
12253,
12,
283,
6163,
283,
7842,
14,
25,
671,
499,
1965,
14,
20,
8562,
659,
4490,
661,
7690,
320,
344,
297,
283,
7690,
320,
344,
7349,
499,
1965,
14,
20,
671,
841,
2192,
14,
24,
8562,
659,
4490,
661,
4229,
297,
283,
7223,
2665,
5644,
283,
48,
9804,
1568,
297,
5644,
1720,
628,
5446,
2165,
529,
510,
9804,
1568,
1288,
355,
283,
9650,
63,
2119,
356,
1504,
14,
4115,
360,
6105,
16794,
903,
334,
596,
11218,
355,
283,
9650,
63,
8305,
356,
1504,
14,
4115,
360,
22886,
16794,
903,
334,
596,
11218,
355,
283,
9650,
63,
3039,
356,
1504,
14,
4115,
360,
8185,
16794,
903,
334,
596,
11218,
355,
283,
9650,
63,
1019,
356,
1504,
14,
4115,
360,
9121,
16794,
903,
334,
596,
11218,
355,
283,
1606,
63,
3333,
356,
1504,
14,
4115,
360,
3276,
4569,
334,
596,
11218,
355,
283,
1606,
63,
2063,
356,
1504,
14,
4115,
360,
3276,
3462,
334,
596,
11218,
355,
283,
17001,
356,
1504,
14,
5592,
8318,
44,
460,
3588,
297,
283,
44,
460,
3588,
659,
1740,
661,
4313,
29179,
297,
283,
4313,
29179
] |
[
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,
6927,
13,
31982,
7653,
13950,
8642,
1014,
921,
1544,
14,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
9143,
492,
7417,
199,
199,
504,
5166,
492,
12824,
63,
998,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
421,
199,
533,
3622,
63,
10443,
908,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
298,
3070,
14,
10443,
908,
2,
272,
485,
1802,
275,
298,
19780,
32715,
402,
282,
3622,
2122,
339,
485,
3406,
275,
791,
354,
356,
1504,
14,
1560,
360,
985,
297,
1415,
29,
549,
395,
355,
283,
885,
356,
1504,
14,
4871,
360,
2698,
15220,
1475,
5805,
659,
355,
283,
908,
356,
1504,
14,
5592,
8318,
33,
16,
297,
283,
33,
16,
221,
959,
257,
8264,
17,
671,
413,
11370,
8562,
659,
4490,
661,
33,
17,
297,
283,
33,
17,
221,
1227,
257,
959,
2635,
671,
8264,
17,
8562,
659,
4490,
661,
33,
18,
297,
283,
33,
18,
221,
1520,
257,
841,
1165,
671,
959,
2635,
8562,
659,
4490,
661,
33,
19,
297,
283,
33,
19,
221,
1695,
257,
499,
2576,
671,
841,
1165,
8562,
659,
4490,
661,
33,
20,
297,
283,
33,
20,
221,
378,
257,
26160,
671,
499,
2576,
8562,
12,
1695,
14,
1479,
671,
4119,
14,
1876,
315,
12253,
659,
4490,
661,
33,
21,
297,
283,
33,
21,
221,
1749,
257,
30300,
671,
26160,
8562,
659,
4490,
661,
33,
22,
297,
283,
33,
22,
221,
1616,
221,
20462,
671,
30300,
8562,
659,
4490,
661,
33,
23,
297,
283,
33,
23,
221,
4119,
221,
9720,
671,
20462,
8562,
659,
4490,
661,
33,
24,
297,
283,
33,
24,
221,
3144,
221,
14589,
671,
9720,
8562,
659,
4490,
661,
33,
25,
297,
283,
33,
25,
221,
4944,
221,
6877,
671,
14589,
8562,
659,
4490,
661,
34,
16,
297,
283,
34,
16,
221,
4329,
221,
5198,
671,
4329,
1079,
8562,
659,
4490,
661,
34,
17,
297,
283,
34,
17,
221,
4114,
221,
1520,
1780,
671,
5198,
8562,
659,
4490,
661,
34,
18,
297,
283,
34,
18,
221,
5557,
221,
6891,
671,
1520,
1780,
8562,
659,
4490,
661,
34,
19,
297,
283,
34,
19,
221,
6155,
221,
650,
2481,
671,
6891,
8562,
659,
4490,
661,
34,
20,
297,
283,
34,
20,
221,
5851,
221,
16074,
671,
650,
2481,
8562,
659,
4490,
661,
34,
21,
297,
283,
34,
21,
221,
413,
257,
27827,
671,
16074,
8562,
12,
1227,
14,
3129,
671,
1749,
14,
1349,
315,
12253,
659,
4490,
661,
34,
22,
297,
283,
34,
22,
221,
3388,
221,
19163,
671,
27827,
8562,
659,
4490,
661,
34,
23,
297,
283,
34,
23,
221,
7829,
221,
10523,
671,
19163,
8562,
659,
4490,
661,
34,
24,
297,
283,
34,
24,
221,
6928,
221,
16202,
671,
10523,
8562,
659,
4490,
661,
34,
25,
297,
283,
34,
25,
221,
6546,
221,
9404,
671,
16202,
8562,
659,
4490,
661,
34,
709,
297,
7596,
34,
709,
259,
3193,
221,
7105,
671,
10868,
8562,
659,
4490,
661,
35,
21,
37,
297,
283,
35,
21,
37,
5504,
221,
24619,
671,
499,
1398,
8562,
659,
4490,
661,
5150,
709,
37,
297,
283,
5150,
709,
37,
5661,
221,
20462,
671,
499,
2953,
8562,
12,
738,
14,
51,
14,
283,
6163,
283,
7844,
1616,
29143,
659,
4490,
661,
36,
906,
297,
283,
36,
906,
7875,
16814,
671,
25647,
8562,
659,
4490,
661,
4858,
13441,
297,
283,
4858,
13441,
841,
257,
1520,
14,
21,
671,
1616,
315,
12253,
12,
283,
6163,
283,
12205,
14,
21,
671,
22540,
8562,
659,
4490,
661,
15563,
14437,
297,
283,
15563,
14437,
8087,
221,
26160,
671,
13540,
8562,
659,
4490,
661,
44,
379,
836,
297,
283,
44,
379,
836,
221,
7294,
221,
841,
2192,
14,
24,
671,
499,
1965,
14,
20,
8562,
659,
4490,
661,
13257,
279,
297,
283,
13257,
279,
259,
650,
257,
1695,
14,
21,
671,
4329,
315,
12253,
12,
283,
6163,
283,
7842,
14,
25,
671,
650,
1229,
14,
22,
8562,
659,
4490,
661,
23496,
297,
283,
23496,
499,
1695,
14,
21,
671,
4119,
315,
12253,
12,
283,
6163,
283,
7842,
14,
25,
671,
499,
1965,
14,
20,
8562,
659,
4490,
661,
7690,
320,
344,
297,
283,
7690,
320,
344,
7349,
499,
1965,
14,
20,
671,
841,
2192,
14,
24,
8562,
659,
4490,
661,
4229,
297,
283,
7223,
2665,
5644,
283,
48,
9804,
1568,
297,
5644,
1720,
628,
5446,
2165,
529,
510,
9804,
1568,
1288,
355,
283,
9650,
63,
2119,
356,
1504,
14,
4115,
360,
6105,
16794,
903,
334,
596,
11218,
355,
283,
9650,
63,
8305,
356,
1504,
14,
4115,
360,
22886,
16794,
903,
334,
596,
11218,
355,
283,
9650,
63,
3039,
356,
1504,
14,
4115,
360,
8185,
16794,
903,
334,
596,
11218,
355,
283,
9650,
63,
1019,
356,
1504,
14,
4115,
360,
9121,
16794,
903,
334,
596,
11218,
355,
283,
1606,
63,
3333,
356,
1504,
14,
4115,
360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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
] |
zapier/transformer
|
transformer/transforms/string/phone_number_extract_test.py
|
1
|
2330
|
import unittest
import phone_number_extract
class TestStringPhoneExtractTransform(unittest.TestCase):
def test_phoneextract(self):
transformer = phone_number_extract.StringPhoneExtractTransform()
# using the default regex - which is uni1
self.assertEqual(transformer.transform(""), "")
self.assertEqual(transformer.transform(None), "")
self.assertEqual(transformer.transform("This is a test without a phone number"), "")
self.assertEqual(transformer.transform("my phone number is 123-456-7890"), "123-456-7890")
self.assertEqual(transformer.transform("bob said to call him at and 321-0989."), "321-0989")
self.assertEqual(transformer.transform("The post office's number is (800) 777-9988 and it costs $53 a month"), "(800) 777-9988")
self.assertEqual(transformer.transform("Call bob at +66.81.234.5566 tomorrow at 2 PM"), "+66.81.234.5566")
#using NA
tests = [
# input, format, expected output
('this is a NA (999) 999-9999 here', 'na','(999) 999-9999'),
('this is not a NA 1-22-555-1212 here', 'na',''),
('fred', 'na','')
]
for input_text, regex, expected_output in tests:
self.assertEqual(expected_output, transformer.transform(input_text, regex=regex))
# using IN
tests = [
# input, format, expected output
('this is 543-3456 a IN (55)44-33-22-11 here', 'in','(55)44-33-22-11'),
('this to IN (55)44*33*22*11 here', 'in','(55)44*33*22*11'),
('this is a IN 999-999-9999 here', 'in',''),
('fred', 'in','')
]
for input_text, regex, expected_output in tests:
self.assertEqual(expected_output, transformer.transform(input_text, regex=regex))
# using UNI2
tests = [
# input, format, expected output
('this is 543-3456 a IN (55)44-33-22-11 here', 'uni2','543-3456'),
('this to IN (55)44*33*22*11 here', 'uni2','(55)44*33*22*11'),
('this is a IN 999-999-9999 here', 'uni2','999-999-9999'),
('fred', 'uni2','')
]
for input_text, regex, expected_output in tests:
self.assertEqual(expected_output, transformer.transform(input_text, regex=regex))
|
gpl-3.0
|
[
646,
2882,
199,
646,
14617,
63,
1955,
63,
5005,
199,
199,
533,
1379,
1558,
15199,
12147,
6939,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
9339,
5005,
8,
277,
304,
267,
21484,
275,
14617,
63,
1955,
63,
5005,
14,
1558,
15199,
12147,
6939,
342,
398,
327,
1808,
314,
849,
5163,
446,
1314,
365,
15439,
17,
267,
291,
14,
629,
8,
19754,
14,
4711,
11986,
395,
6899,
267,
291,
14,
629,
8,
19754,
14,
4711,
8,
403,
395,
6899,
267,
291,
14,
629,
8,
19754,
14,
4711,
480,
2765,
365,
282,
511,
1928,
282,
14617,
1329,
1288,
6899,
267,
291,
14,
629,
8,
19754,
14,
4711,
480,
1662,
14617,
1329,
365,
11869,
13,
11419,
13,
23,
13173,
1288,
298,
4288,
13,
11419,
13,
23,
13173,
531,
267,
291,
14,
629,
8,
19754,
14,
4711,
480,
7913,
25097,
370,
1240,
26457,
737,
436,
650,
2025,
13,
1643,
1407,
7651,
298,
12638,
13,
1643,
1407,
531,
267,
291,
14,
629,
8,
19754,
14,
4711,
480,
1918,
2963,
402,
13740,
1159,
1329,
365,
334,
6718,
9,
8375,
23,
13,
1020,
1299,
436,
652,
26819,
2672,
2481,
282,
5794,
1288,
7340,
6718,
9,
8375,
23,
13,
1020,
1299,
531,
267,
291,
14,
629,
8,
19754,
14,
4711,
480,
2176,
26961,
737,
435,
1272,
14,
2835,
14,
5533,
14,
1229,
1272,
370,
12416,
1143,
737,
499,
27320,
1288,
7210,
1272,
14,
2835,
14,
5533,
14,
1229,
1272,
531,
398,
327,
4941,
653,
33,
4960,
2295,
275,
359,
288,
327,
1324,
12,
1475,
12,
1420,
1072,
288,
661,
3749,
365,
282,
653,
33,
334,
5637,
9,
22291,
13,
5008,
2348,
297,
283,
3540,
1673,
8,
5637,
9,
22291,
13,
5008,
659,
288,
661,
3749,
365,
440,
282,
653,
33,
413,
13,
1081,
13,
15722,
13,
25481,
2348,
297,
283,
3540,
25936,
288,
661,
22980,
297,
283,
3540,
20944,
267,
1622,
398,
367,
1324,
63,
505,
12,
5163,
12,
1420,
63,
1199,
315,
2295,
26,
288,
291,
14,
629,
8,
2062,
63,
1199,
12,
21484,
14,
4711,
8,
1210,
63,
505,
12,
5163,
29,
3821,
430,
2728,
327,
1808,
1621,
267,
2295,
275,
359,
288,
327,
1324,
12,
1475,
12,
1420,
1072,
288,
661,
3749,
365,
959,
2824,
13,
1082,
1367,
282,
1621,
334,
1229,
9,
1602,
13,
1153,
13,
1081,
13,
845,
2348,
297,
283,
262,
1673,
8,
1229,
9,
1602,
13,
1153,
13,
1081,
13,
845,
659,
288,
661,
3749,
370,
1621,
334,
1229,
9,
1602,
10,
1153,
10,
1081,
10,
845,
2348,
297,
283,
262,
1673,
8,
1229,
9,
1602,
10,
1153,
10,
1081,
10,
845,
659,
288,
661,
3749,
365,
282,
1621,
22291,
13,
5637,
13,
5008,
2348,
297,
283,
262,
25936,
288,
661,
22980,
297,
283,
262,
20944,
267,
1622,
398,
367,
1324,
63,
505,
12,
5163,
12,
1420,
63,
1199,
315,
2295,
26,
288,
291,
14,
629,
8,
2062,
63,
1199,
12,
21484,
14,
4711,
8,
1210,
63,
505,
12,
5163,
29,
3821,
430,
398,
327,
1808,
6778,
41,
18,
267,
2295,
275,
359,
288,
327,
1324,
12,
1475,
12,
1420,
1072,
288,
661,
3749,
365,
959,
2824,
13,
1082,
1367,
282,
1621,
334,
1229,
9,
1602,
13,
1153,
13,
1081,
13,
845,
2348,
297,
283,
5411,
18,
1673,
20103,
13,
1082,
1367,
659,
288,
661,
3749,
370,
1621,
334,
1229,
9,
1602,
10,
1153,
10,
1081,
10,
845,
2348,
297,
283,
5411,
18,
1673,
8,
1229,
9,
1602,
10,
1153,
10,
1081,
10,
845,
659,
288,
661,
3749,
365,
282,
1621,
22291,
13,
5637,
13,
5008,
2348,
297,
283,
5411,
18,
1673,
5637,
13,
5637,
13,
5008,
659,
288,
661,
22980,
297,
283,
5411,
18,
20944,
267,
1622,
398,
367,
1324,
63,
505,
12,
5163,
12,
1420,
63,
1199,
315,
2295,
26,
288,
291,
14,
629,
8,
2062,
63,
1199,
12,
21484,
14,
4711,
8,
1210,
63,
505,
12,
5163,
29,
3821,
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
] |
[
2882,
199,
646,
14617,
63,
1955,
63,
5005,
199,
199,
533,
1379,
1558,
15199,
12147,
6939,
8,
2796,
14,
1746,
304,
272,
347,
511,
63,
9339,
5005,
8,
277,
304,
267,
21484,
275,
14617,
63,
1955,
63,
5005,
14,
1558,
15199,
12147,
6939,
342,
398,
327,
1808,
314,
849,
5163,
446,
1314,
365,
15439,
17,
267,
291,
14,
629,
8,
19754,
14,
4711,
11986,
395,
6899,
267,
291,
14,
629,
8,
19754,
14,
4711,
8,
403,
395,
6899,
267,
291,
14,
629,
8,
19754,
14,
4711,
480,
2765,
365,
282,
511,
1928,
282,
14617,
1329,
1288,
6899,
267,
291,
14,
629,
8,
19754,
14,
4711,
480,
1662,
14617,
1329,
365,
11869,
13,
11419,
13,
23,
13173,
1288,
298,
4288,
13,
11419,
13,
23,
13173,
531,
267,
291,
14,
629,
8,
19754,
14,
4711,
480,
7913,
25097,
370,
1240,
26457,
737,
436,
650,
2025,
13,
1643,
1407,
7651,
298,
12638,
13,
1643,
1407,
531,
267,
291,
14,
629,
8,
19754,
14,
4711,
480,
1918,
2963,
402,
13740,
1159,
1329,
365,
334,
6718,
9,
8375,
23,
13,
1020,
1299,
436,
652,
26819,
2672,
2481,
282,
5794,
1288,
7340,
6718,
9,
8375,
23,
13,
1020,
1299,
531,
267,
291,
14,
629,
8,
19754,
14,
4711,
480,
2176,
26961,
737,
435,
1272,
14,
2835,
14,
5533,
14,
1229,
1272,
370,
12416,
1143,
737,
499,
27320,
1288,
7210,
1272,
14,
2835,
14,
5533,
14,
1229,
1272,
531,
398,
327,
4941,
653,
33,
4960,
2295,
275,
359,
288,
327,
1324,
12,
1475,
12,
1420,
1072,
288,
661,
3749,
365,
282,
653,
33,
334,
5637,
9,
22291,
13,
5008,
2348,
297,
283,
3540,
1673,
8,
5637,
9,
22291,
13,
5008,
659,
288,
661,
3749,
365,
440,
282,
653,
33,
413,
13,
1081,
13,
15722,
13,
25481,
2348,
297,
283,
3540,
25936,
288,
661,
22980,
297,
283,
3540,
20944,
267,
1622,
398,
367,
1324,
63,
505,
12,
5163,
12,
1420,
63,
1199,
315,
2295,
26,
288,
291,
14,
629,
8,
2062,
63,
1199,
12,
21484,
14,
4711,
8,
1210,
63,
505,
12,
5163,
29,
3821,
430,
2728,
327,
1808,
1621,
267,
2295,
275,
359,
288,
327,
1324,
12,
1475,
12,
1420,
1072,
288,
661,
3749,
365,
959,
2824,
13,
1082,
1367,
282,
1621,
334,
1229,
9,
1602,
13,
1153,
13,
1081,
13,
845,
2348,
297,
283,
262,
1673,
8,
1229,
9,
1602,
13,
1153,
13,
1081,
13,
845,
659,
288,
661,
3749,
370,
1621,
334,
1229,
9,
1602,
10,
1153,
10,
1081,
10,
845,
2348,
297,
283,
262,
1673,
8,
1229,
9,
1602,
10,
1153,
10,
1081,
10,
845,
659,
288,
661,
3749,
365,
282,
1621,
22291,
13,
5637,
13,
5008,
2348,
297,
283,
262,
25936,
288,
661,
22980,
297,
283,
262,
20944,
267,
1622,
398,
367,
1324,
63,
505,
12,
5163,
12,
1420,
63,
1199,
315,
2295,
26,
288,
291,
14,
629,
8,
2062,
63,
1199,
12,
21484,
14,
4711,
8,
1210,
63,
505,
12,
5163,
29,
3821,
430,
398,
327,
1808,
6778,
41,
18,
267,
2295,
275,
359,
288,
327,
1324,
12,
1475,
12,
1420,
1072,
288,
661,
3749,
365,
959,
2824,
13,
1082,
1367,
282,
1621,
334,
1229,
9,
1602,
13,
1153,
13,
1081,
13,
845,
2348,
297,
283,
5411,
18,
1673,
20103,
13,
1082,
1367,
659,
288,
661,
3749,
370,
1621,
334,
1229,
9,
1602,
10,
1153,
10,
1081,
10,
845,
2348,
297,
283,
5411,
18,
1673,
8,
1229,
9,
1602,
10,
1153,
10,
1081,
10,
845,
659,
288,
661,
3749,
365,
282,
1621,
22291,
13,
5637,
13,
5008,
2348,
297,
283,
5411,
18,
1673,
5637,
13,
5637,
13,
5008,
659,
288,
661,
22980,
297,
283,
5411,
18,
20944,
267,
1622,
398,
367,
1324,
63,
505,
12,
5163,
12,
1420,
63,
1199,
315,
2295,
26,
288,
291,
14,
629,
8,
2062,
63,
1199,
12,
21484,
14,
4711,
8,
1210,
63,
505,
12,
5163,
29,
3821,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
kofron/bigcouch
|
couchjs/scons/scons-local-2.0.1/SCons/Tool/ar.py
|
61
|
2200
|
"""SCons.Tool.ar
Tool-specific initialization for ar (library archive).
There normally shouldn't be any need to import this module directly.
It will usually be imported through the generic SCons.Tool.Tool()
selection method.
"""
#
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010 The SCons Foundation
#
# 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.
#
__revision__ = "src/engine/SCons/Tool/ar.py 5134 2010/08/16 23:02:40 bdeegan"
import SCons.Defaults
import SCons.Tool
import SCons.Util
def generate(env):
"""Add Builders and construction variables for ar to an Environment."""
SCons.Tool.createStaticLibBuilder(env)
env['AR'] = 'ar'
env['ARFLAGS'] = SCons.Util.CLVar('rc')
env['ARCOM'] = '$AR $ARFLAGS $TARGET $SOURCES'
env['LIBPREFIX'] = 'lib'
env['LIBSUFFIX'] = '.a'
if env.Detect('ranlib'):
env['RANLIB'] = 'ranlib'
env['RANLIBFLAGS'] = SCons.Util.CLVar('')
env['RANLIBCOM'] = '$RANLIB $RANLIBFLAGS $TARGET'
def exists(env):
return env.Detect('ar')
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|
apache-2.0
|
[
624,
18521,
14,
5157,
14,
285,
199,
199,
5157,
13,
6100,
11097,
367,
601,
334,
4342,
6359,
680,
199,
199,
10924,
12252,
9296,
1133,
506,
1263,
1929,
370,
492,
642,
859,
5370,
14,
199,
7940,
911,
9987,
506,
8439,
4012,
314,
7809,
8218,
14,
5157,
14,
5157,
342,
199,
5592,
1083,
14,
199,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
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,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
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,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
5157,
15,
285,
14,
647,
959,
7582,
7129,
15,
2036,
15,
975,
6546,
26,
996,
26,
2167,
330,
271,
5902,
290,
2,
199,
199,
646,
8218,
14,
16986,
199,
646,
8218,
14,
5157,
199,
646,
8218,
14,
9562,
421,
199,
318,
3550,
8,
1813,
304,
272,
408,
1123,
19286,
83,
436,
14538,
2860,
367,
601,
370,
376,
9711,
1041,
272,
8218,
14,
5157,
14,
981,
9278,
4728,
6437,
8,
1813,
9,
339,
2589,
459,
689,
418,
3515,
275,
283,
285,
7,
272,
2589,
459,
689,
4831,
418,
258,
275,
8218,
14,
9562,
14,
1981,
5894,
360,
1195,
358,
272,
2589,
459,
689,
11265,
418,
755,
275,
4505,
689,
2672,
689,
4831,
2672,
9268,
2672,
25744,
7,
272,
2589,
459,
5617,
6351,
418,
257,
275,
283,
773,
7,
272,
2589,
459,
5617,
12273,
418,
257,
275,
1987,
65,
7,
339,
340,
2589,
14,
20064,
360,
1312,
773,
735,
267,
2589,
459,
27644,
5617,
418,
420,
275,
283,
1312,
773,
7,
267,
2589,
459,
27644,
5617,
4831,
418,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
267,
2589,
459,
27644,
5617,
11265,
418,
257,
275,
4505,
27644,
5617,
2672,
27644,
5617,
4831,
2672,
9268,
7,
199,
199,
318,
3495,
8,
1813,
304,
272,
372,
2589,
14,
20064,
360,
285,
358,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
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
] |
[
18521,
14,
5157,
14,
285,
199,
199,
5157,
13,
6100,
11097,
367,
601,
334,
4342,
6359,
680,
199,
199,
10924,
12252,
9296,
1133,
506,
1263,
1929,
370,
492,
642,
859,
5370,
14,
199,
7940,
911,
9987,
506,
8439,
4012,
314,
7809,
8218,
14,
5157,
14,
5157,
342,
199,
5592,
1083,
14,
199,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
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,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
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,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
3,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
5157,
15,
285,
14,
647,
959,
7582,
7129,
15,
2036,
15,
975,
6546,
26,
996,
26,
2167,
330,
271,
5902,
290,
2,
199,
199,
646,
8218,
14,
16986,
199,
646,
8218,
14,
5157,
199,
646,
8218,
14,
9562,
421,
199,
318,
3550,
8,
1813,
304,
272,
408,
1123,
19286,
83,
436,
14538,
2860,
367,
601,
370,
376,
9711,
1041,
272,
8218,
14,
5157,
14,
981,
9278,
4728,
6437,
8,
1813,
9,
339,
2589,
459,
689,
418,
3515,
275,
283,
285,
7,
272,
2589,
459,
689,
4831,
418,
258,
275,
8218,
14,
9562,
14,
1981,
5894,
360,
1195,
358,
272,
2589,
459,
689,
11265,
418,
755,
275,
4505,
689,
2672,
689,
4831,
2672,
9268,
2672,
25744,
7,
272,
2589,
459,
5617,
6351,
418,
257,
275,
283,
773,
7,
272,
2589,
459,
5617,
12273,
418,
257,
275,
1987,
65,
7,
339,
340,
2589,
14,
20064,
360,
1312,
773,
735,
267,
2589,
459,
27644,
5617,
418,
420,
275,
283,
1312,
773,
7,
267,
2589,
459,
27644,
5617,
4831,
418,
275,
8218,
14,
9562,
14,
1981,
5894,
8355,
267,
2589,
459,
27644,
5617,
11265,
418,
257,
275,
4505,
27644,
5617,
2672,
27644,
5617,
4831,
2672,
9268,
7,
199,
199,
318,
3495,
8,
1813,
304,
272,
372,
2589,
14,
20064,
360,
285,
358,
199,
199,
3,
10111,
17198,
26,
199,
3,
5174,
13,
2063,
26,
20,
199,
3,
4363,
13,
8741,
13,
632,
26,
20613,
199,
3,
9599,
26,
199,
3,
6695,
26,
663,
26414,
20849,
29,
20,
20105,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
badlogicmanpreet/nupic
|
src/nupic/frameworks/opf/two_gram_model.py
|
40
|
6927
|
# ----------------------------------------------------------------------
# Numenta Platform for Intelligent Computing (NuPIC)
# Copyright (C) 2013, Numenta, Inc. Unless you have an agreement
# with Numenta, Inc., for a separate license for this software code, the
# following terms and conditions apply:
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU Affero Public License for more details.
#
# You should have received a copy of the GNU Affero Public License
# along with this program. If not, see http://www.gnu.org/licenses.
#
# http://numenta.org/licenses/
# ----------------------------------------------------------------------
"""Module containing the two gram OPF model implementation. """
import collections
import itertools
from nupic import encoders
from nupic.data import fieldmeta
from nupic.frameworks.opf import model
from nupic.frameworks.opf import opfutils
from opfutils import InferenceType
class TwoGramModel(model.Model):
"""Two-gram benchmark model."""
def __init__(self, inferenceType=InferenceType.TemporalNextStep,
encoderParams=()):
""" Two-gram model constructor.
inferenceType: An opfutils.InferenceType value that specifies what type of
inference (i.e. TemporalNextStep, Classification, etc.)
encoders: Sequence of encoder params dictionaries.
"""
super(TwoGramModel, self).__init__(inferenceType)
self._logger = opfutils.initLogger(self)
self._reset = False
self._hashToValueDict = dict()
self._learningEnabled = True
self._encoder = encoders.MultiEncoder(encoderParams)
self._fieldNames = self._encoder.getScalarNames()
self._prevValues = [None] * len(self._fieldNames)
self._twoGramDicts = [dict() for _ in xrange(len(self._fieldNames))]
def run(self, inputRecord):
"""Run one iteration of this model.
Args:
inputRecord: A record object formatted according to
nupic.data.FileSource.getNext() result format.
Returns:
A ModelResult named tuple (see opfutils.py). The contents of
ModelResult.inferences depends on the specific inference type of this
model, which can be queried by getInferenceType().
TODO: Implement getInferenceType()?
"""
results = super(TwoGramModel, self).run(inputRecord)
# Set up the lists of values, defaults, and encoded values.
values = [inputRecord[k] for k in self._fieldNames]
defaults = ['' if type(v) == str else 0 for v in values]
inputFieldEncodings = self._encoder.encodeEachField(inputRecord)
inputBuckets = self._encoder.getBucketIndices(inputRecord)
results.sensorInput = opfutils.SensorInput(
dataRow=values, dataEncodings=inputFieldEncodings,
sequenceReset=int(self._reset))
# Keep track of the last value associated with each encoded value for that
# predictions can be returned in the original value format.
for value, bucket in itertools.izip(values, inputBuckets):
self._hashToValueDict[bucket] = value
# Update the two-gram dict if learning is enabled.
for bucket, prevValue, twoGramDict in itertools.izip(
inputBuckets, self._prevValues, self._twoGramDicts):
if self._learningEnabled and not self._reset:
if prevValue not in twoGramDict:
twoGramDict[prevValue] = collections.defaultdict(int)
twoGramDict[prevValue][bucket] += 1
# Populate the results.inferences dict with the predictions and encoded
# predictions.
predictions = []
encodedPredictions = []
for bucket, twoGramDict, default, fieldName in (
itertools.izip(inputBuckets, self._twoGramDicts, defaults,
self._fieldNames)):
if bucket in twoGramDict:
probabilities = twoGramDict[bucket].items()
prediction = self._hashToValueDict[
max(probabilities, key=lambda x: x[1])[0]]
predictions.append(prediction)
encodedPredictions.append(self._encoder.encodeField(fieldName,
prediction))
else:
predictions.append(default)
encodedPredictions.append(self._encoder.encodeField(fieldName,
default))
results.inferences = dict()
results.inferences[opfutils.InferenceElement.prediction] = predictions
results.inferences[opfutils.InferenceElement.encodings] = encodedPredictions
self._prevValues = inputBuckets
self._reset = False
return results
def finishLearning(self):
"""Places the model in a permanent "finished learning" mode.
Once called, the model will not be able to learn from subsequent input
records. Learning may not be resumed on a given instance of the model once
this is called as the implementation may optimize itself by pruning data
structures that are necessary for learning.
"""
self._learningEnabled = False
def setFieldStatistics(self,fieldStats):
"""
This method is used for the data source to communicate to the
model any statistics that it knows about the fields
Since the two-gram has no use for this information, this is a no-op
"""
pass
def getFieldInfo(self):
"""Returns the metadata specifying the format of the model's output.
The result may be different than the list of
nupic.data.fieldmeta.FieldMetaInfo objects supplied at initialization due
to the transcoding of some input fields into meta- fields, such as
datetime -> dayOfWeek, timeOfDay, etc.
"""
fieldTypes = self._encoder.getDecoderOutputFieldTypes()
assert len(self._fieldNames) == len(fieldTypes)
return tuple(fieldmeta.FieldMetaInfo(*args) for args in
itertools.izip(
self._fieldNames, fieldTypes,
itertools.repeat(fieldmeta.FieldMetaSpecial.none)))
def getRuntimeStats(self):
"""Get the runtime statistics specific to the model.
I.E. activeCellOverlapAvg
Returns:
A dict mapping statistic names to values.
"""
# TODO: Add debugging stats.
return dict()
def _getLogger(self):
"""Get the logger created by this subclass.
Returns:
A logging.Logger object. Should not be None.
"""
return self._logger
def resetSequenceStates(self):
"""Called to indicate the start of a new sequence.
The next call to run should not perform learning.
"""
self._reset = True
def __getstate__(self):
del self._logger
return self.__dict__
def __setstate__(self):
self._logger = opfutils.initLogger(self)
|
agpl-3.0
|
[
3,
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
6171,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
624,
2377,
3035,
314,
2877,
1999,
77,
9827,
38,
1402,
4514,
14,
408,
199,
199,
646,
5055,
199,
646,
7975,
199,
199,
504,
26084,
492,
10295,
83,
199,
504,
26084,
14,
576,
492,
901,
2024,
199,
504,
26084,
14,
32037,
14,
16893,
492,
1402,
199,
504,
26084,
14,
32037,
14,
16893,
492,
1687,
70,
1208,
199,
504,
1687,
70,
1208,
492,
1010,
1769,
804,
421,
199,
533,
16853,
5761,
77,
1685,
8,
1238,
14,
1685,
304,
523,
408,
11467,
13,
1679,
12338,
1402,
1041,
819,
347,
636,
826,
721,
277,
12,
17353,
804,
29,
29731,
804,
14,
6530,
19849,
5765,
7801,
12,
2049,
10295,
6007,
23603,
272,
408,
16853,
13,
1679,
1402,
3787,
14,
339,
17353,
804,
26,
1626,
1687,
70,
1208,
14,
29731,
804,
574,
626,
9314,
4052,
730,
402,
267,
17353,
334,
73,
14,
69,
14,
12540,
19849,
5765,
7801,
12,
8465,
7789,
12,
5423,
4959,
272,
10295,
83,
26,
10975,
402,
10295,
1862,
11196,
14,
272,
408,
272,
1613,
8,
11467,
5761,
77,
1685,
12,
291,
2843,
826,
721,
20580,
804,
9,
339,
291,
423,
2921,
275,
1687,
70,
1208,
14,
826,
4455,
8,
277,
9,
272,
291,
423,
3958,
275,
756,
272,
291,
423,
2227,
1378,
24811,
275,
1211,
342,
272,
291,
423,
10546,
6589,
275,
715,
272,
291,
423,
9347,
275,
10295,
83,
14,
3947,
6679,
8,
9347,
6007,
9,
272,
291,
423,
698,
5866,
275,
291,
423,
9347,
14,
362,
13090,
5866,
342,
272,
291,
423,
5701,
6550,
275,
359,
403,
61,
627,
822,
8,
277,
423,
698,
5866,
9,
272,
291,
423,
5601,
5761,
77,
27279,
275,
359,
807,
342,
367,
485,
315,
4945,
8,
552,
8,
277,
423,
698,
5866,
10524,
819,
347,
1255,
8,
277,
12,
1324,
5433,
304,
272,
408,
2540,
1373,
8494,
402,
642,
1402,
14,
339,
3033,
26,
489,
1324,
5433,
26,
437,
2777,
909,
7871,
7182,
370,
881,
26084,
14,
576,
14,
1173,
2980,
14,
362,
5765,
342,
754,
1475,
14,
339,
1803,
26,
489,
437,
5822,
2889,
4310,
2008,
334,
3239,
1687,
70,
1208,
14,
647,
680,
710,
4072,
402,
489,
5822,
2889,
14,
262,
4023,
8350,
641,
314,
2488,
17353,
730,
402,
642,
489,
1402,
12,
1314,
883,
506,
30081,
701,
664,
29731,
804,
1252,
489,
3254,
26,
22467,
664,
29731,
804,
342,
31,
272,
408,
272,
2058,
275,
1613,
8,
11467,
5761,
77,
1685,
12,
291,
680,
1065,
8,
1210,
5433,
9,
339,
327,
2494,
1536,
314,
5548,
402,
1338,
12,
4243,
12,
436,
5737,
1338,
14,
272,
1338,
275,
359,
1210,
5433,
59,
75,
61,
367,
1022,
315,
291,
423,
698,
5866,
61,
272,
4243,
275,
788,
7,
340,
730,
8,
86,
9,
508,
620,
587,
378,
367,
373,
315,
1338,
61,
272,
1324,
792,
30046,
275,
291,
423,
9347,
14,
2143,
22321,
792,
8,
1210,
5433,
9,
272,
1324,
12311,
83,
275,
291,
423,
9347,
14,
362,
12311,
18488,
8,
1210,
5433,
9,
339,
2058,
14,
8956,
3205,
275,
1687,
70,
1208,
14,
10160,
3205,
8,
267,
666,
5810,
29,
1459,
12,
666,
30046,
29,
1210,
792,
30046,
12,
267,
3414,
9637,
29,
442,
8,
277,
423,
3958,
430,
339,
327,
14797,
4426,
402,
314,
2061,
574,
4568,
543,
1924,
5737,
574,
367,
626,
272,
327,
7914,
883,
506,
2138,
315,
314,
3379,
574,
1475,
14,
272,
367,
574,
12,
5315,
315,
7975,
14,
565,
711,
8,
1459,
12,
1324,
12311,
83,
304,
489,
291,
423,
2227,
1378,
24811,
59,
4623,
61,
275,
574,
339,
327,
6162,
314,
2877,
13,
1679,
1211,
340,
9328,
365,
5223,
14,
272,
367,
5315,
12,
5071,
1110,
12,
2877,
5761,
77,
2141,
315,
7975,
14,
565,
711,
8,
267,
1324,
12311,
83,
12,
291,
423,
5701,
6550,
12,
291,
423,
5601,
5761,
77,
27279,
304,
489,
340,
291,
423,
10546,
6589,
436,
440,
291,
423,
3958,
26,
267,
340,
5071,
1110,
440,
315,
2877,
5761,
77,
2141,
26,
881,
2877,
5761,
77,
2141,
59,
5701,
1110,
61,
275,
5055,
14,
21501,
8,
442,
9,
267,
2877,
5761,
77,
2141,
59,
5701,
1110,
1527,
4623,
61,
847,
413,
339,
327,
31731,
314,
2058,
14,
262,
4023,
1211,
543,
314,
7914,
436,
5737,
272,
327,
7914,
14,
272,
7914,
275,
942,
272,
5737,
14730,
2452,
275,
942,
272,
367,
5315,
12,
2877,
5761,
77,
2141,
12,
849,
12,
901,
985,
315,
334,
267,
7975,
14,
565,
711,
8,
1210,
12311,
83,
12,
291,
423,
5601,
5761,
77,
27279,
12,
4243,
12,
2432,
291,
423,
698,
5866,
2298,
489,
340,
5315,
315,
2877,
5761,
77,
2141,
26,
267,
19555,
275,
2877,
5761,
77,
2141,
59,
4623,
1055,
1744,
342,
267,
12044,
275,
291,
423,
2227,
1378,
24811,
59,
288,
1390,
8,
27583,
12,
790,
29,
2734,
671,
26,
671,
59,
17,
11057,
16,
2677,
267,
7914,
14,
740,
8,
14845,
9,
267,
5737,
14730,
2452,
14,
740,
8,
277,
423,
9347,
14,
2143,
792,
8,
698,
985,
12,
14663,
12044,
430,
489,
587,
26,
267,
7914
] |
[
20359,
199,
3,
22783,
16078,
367,
8883,
24024,
27799,
334,
21988,
26769,
9,
199,
3,
1898,
334,
35,
9,
6171,
12,
22783,
12,
3277,
14,
221,
4158,
1265,
1172,
376,
25025,
199,
3,
543,
22783,
12,
3277,
2020,
367,
282,
7396,
4190,
367,
642,
2032,
1233,
12,
314,
199,
3,
2569,
2895,
436,
3704,
4838,
26,
199,
3,
199,
3,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1684,
844,
1015,
650,
465,
199,
3,
3267,
701,
314,
2868,
2290,
2752,
14,
199,
3,
199,
3,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
199,
3,
1666,
314,
1664,
4265,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1684,
844,
199,
3,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
1455,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
14,
199,
3,
199,
3,
1455,
921,
78,
18952,
14,
1308,
15,
2383,
15,
199,
3,
20359,
199,
199,
624,
2377,
3035,
314,
2877,
1999,
77,
9827,
38,
1402,
4514,
14,
408,
199,
199,
646,
5055,
199,
646,
7975,
199,
199,
504,
26084,
492,
10295,
83,
199,
504,
26084,
14,
576,
492,
901,
2024,
199,
504,
26084,
14,
32037,
14,
16893,
492,
1402,
199,
504,
26084,
14,
32037,
14,
16893,
492,
1687,
70,
1208,
199,
504,
1687,
70,
1208,
492,
1010,
1769,
804,
421,
199,
533,
16853,
5761,
77,
1685,
8,
1238,
14,
1685,
304,
523,
408,
11467,
13,
1679,
12338,
1402,
1041,
819,
347,
636,
826,
721,
277,
12,
17353,
804,
29,
29731,
804,
14,
6530,
19849,
5765,
7801,
12,
2049,
10295,
6007,
23603,
272,
408,
16853,
13,
1679,
1402,
3787,
14,
339,
17353,
804,
26,
1626,
1687,
70,
1208,
14,
29731,
804,
574,
626,
9314,
4052,
730,
402,
267,
17353,
334,
73,
14,
69,
14,
12540,
19849,
5765,
7801,
12,
8465,
7789,
12,
5423,
4959,
272,
10295,
83,
26,
10975,
402,
10295,
1862,
11196,
14,
272,
408,
272,
1613,
8,
11467,
5761,
77,
1685,
12,
291,
2843,
826,
721,
20580,
804,
9,
339,
291,
423,
2921,
275,
1687,
70,
1208,
14,
826,
4455,
8,
277,
9,
272,
291,
423,
3958,
275,
756,
272,
291,
423,
2227,
1378,
24811,
275,
1211,
342,
272,
291,
423,
10546,
6589,
275,
715,
272,
291,
423,
9347,
275,
10295,
83,
14,
3947,
6679,
8,
9347,
6007,
9,
272,
291,
423,
698,
5866,
275,
291,
423,
9347,
14,
362,
13090,
5866,
342,
272,
291,
423,
5701,
6550,
275,
359,
403,
61,
627,
822,
8,
277,
423,
698,
5866,
9,
272,
291,
423,
5601,
5761,
77,
27279,
275,
359,
807,
342,
367,
485,
315,
4945,
8,
552,
8,
277,
423,
698,
5866,
10524,
819,
347,
1255,
8,
277,
12,
1324,
5433,
304,
272,
408,
2540,
1373,
8494,
402,
642,
1402,
14,
339,
3033,
26,
489,
1324,
5433,
26,
437,
2777,
909,
7871,
7182,
370,
881,
26084,
14,
576,
14,
1173,
2980,
14,
362,
5765,
342,
754,
1475,
14,
339,
1803,
26,
489,
437,
5822,
2889,
4310,
2008,
334,
3239,
1687,
70,
1208,
14,
647,
680,
710,
4072,
402,
489,
5822,
2889,
14,
262,
4023,
8350,
641,
314,
2488,
17353,
730,
402,
642,
489,
1402,
12,
1314,
883,
506,
30081,
701,
664,
29731,
804,
1252,
489,
3254,
26,
22467,
664,
29731,
804,
342,
31,
272,
408,
272,
2058,
275,
1613,
8,
11467,
5761,
77,
1685,
12,
291,
680,
1065,
8,
1210,
5433,
9,
339,
327,
2494,
1536,
314,
5548,
402,
1338,
12,
4243,
12,
436,
5737,
1338,
14,
272,
1338,
275,
359,
1210,
5433,
59,
75,
61,
367,
1022,
315,
291,
423,
698,
5866,
61,
272,
4243,
275,
788,
7,
340,
730,
8,
86,
9,
508,
620,
587,
378,
367,
373,
315,
1338,
61,
272,
1324,
792,
30046,
275,
291,
423,
9347,
14,
2143,
22321,
792,
8,
1210,
5433,
9,
272,
1324,
12311,
83,
275,
291,
423,
9347,
14,
362,
12311,
18488,
8,
1210,
5433,
9,
339,
2058,
14,
8956,
3205,
275,
1687,
70,
1208,
14,
10160,
3205,
8,
267,
666,
5810,
29,
1459,
12,
666,
30046,
29,
1210,
792,
30046,
12,
267,
3414,
9637,
29,
442,
8,
277,
423,
3958,
430,
339,
327,
14797,
4426,
402,
314,
2061,
574,
4568,
543,
1924,
5737,
574,
367,
626,
272,
327,
7914,
883,
506,
2138,
315,
314,
3379,
574,
1475,
14,
272,
367,
574,
12,
5315,
315,
7975,
14,
565,
711,
8,
1459,
12,
1324,
12311,
83,
304,
489,
291,
423,
2227,
1378,
24811,
59,
4623,
61,
275,
574,
339,
327,
6162,
314,
2877,
13,
1679,
1211,
340,
9328,
365,
5223,
14,
272,
367,
5315,
12,
5071,
1110,
12,
2877,
5761,
77,
2141,
315,
7975,
14,
565,
711,
8,
267,
1324,
12311,
83,
12,
291,
423,
5701,
6550,
12,
291,
423,
5601,
5761,
77,
27279,
304,
489,
340,
291,
423,
10546,
6589,
436,
440,
291,
423,
3958,
26,
267,
340,
5071,
1110,
440,
315,
2877,
5761,
77,
2141,
26,
881,
2877,
5761,
77,
2141,
59,
5701,
1110,
61,
275,
5055,
14,
21501,
8,
442,
9,
267,
2877,
5761,
77,
2141,
59,
5701,
1110,
1527,
4623,
61,
847,
413,
339,
327,
31731,
314,
2058,
14,
262,
4023,
1211,
543,
314,
7914,
436,
5737,
272,
327,
7914,
14,
272,
7914,
275,
942,
272,
5737,
14730,
2452,
275,
942,
272,
367,
5315,
12,
2877,
5761,
77,
2141,
12,
849,
12,
901,
985,
315,
334,
267,
7975,
14,
565,
711,
8,
1210,
12311,
83,
12,
291,
423,
5601,
5761,
77,
27279,
12,
4243,
12,
2432,
291,
423,
698,
5866,
2298,
489,
340,
5315,
315,
2877,
5761,
77,
2141,
26,
267,
19555,
275,
2877,
5761,
77,
2141,
59,
4623,
1055,
1744,
342,
267,
12044,
275,
291,
423,
2227,
1378,
24811,
59,
288,
1390,
8,
27583,
12,
790,
29,
2734,
671,
26,
671,
59,
17,
11057,
16,
2677,
267,
7914,
14,
740,
8,
14845,
9,
267,
5737,
14730,
2452,
14,
740,
8,
277,
423,
9347,
14,
2143,
792,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
Enttoi/enttoi-client
|
gpio_output.py
|
3
|
1773
|
"""
Wrappers for OUTPUT devices connected to GPIO
"""
import threading
import RPi.GPIO as GPIO
class Led(object):
"""Represent LED as output"""
def __init__(self, pin):
self.pin = pin
GPIO.setup(self.pin, GPIO.OUT)
self.__blinking_frequency = -1 # indicates no blinking
self.__stop_blink_event = None
self.__thread = None
self.turn_off() # reset state
def turn_on(self):
"""turnes LED on"""
self.__ensure_not_blinking()
GPIO.output(self.pin, True)
def turn_off(self):
"""turnes LED off"""
self.__ensure_not_blinking()
GPIO.output(self.pin, False)
def blink_fast(self):
"""starts fast blinking of LED"""
self.blink(0.06)
def blink_slow(self):
"""starts slow blinking of LED"""
self.blink(0.5)
def blink(self, frequency):
"""starts blinking of LED"""
if self.__blinking_frequency == -1:
# no blinking currently => create worker for it
self.__stop_blink_event = threading.Event()
self.__thread = threading.Thread(target=self.__do_blinking)
self.__thread.daemon = True
self.__thread.start()
self.__blinking_frequency = frequency
def __do_blinking(self):
state = False
GPIO.output(self.pin, state)
while not self.__stop_blink_event.is_set():
state = not state
GPIO.output(self.pin, state)
self.__stop_blink_event.wait(self.__blinking_frequency)
def __ensure_not_blinking(self):
if self.__blinking_frequency == -1:
return
self.__stop_blink_event.set()
self.__thread.join()
self.__blinking_frequency = -1
|
mit
|
[
172,
120,
124,
624,
199,
4590,
83,
367,
18746,
7256,
8539,
370,
20899,
199,
624,
199,
646,
5796,
199,
646,
820,
10542,
14,
21071,
465,
20899,
421,
199,
533,
491,
379,
8,
785,
304,
272,
408,
10755,
491,
1149,
465,
1072,
624,
339,
347,
636,
826,
721,
277,
12,
10713,
304,
267,
291,
14,
7751,
275,
10713,
267,
20899,
14,
2758,
8,
277,
14,
7751,
12,
20899,
14,
1877,
9,
267,
291,
855,
24042,
316,
63,
11132,
275,
446,
17,
221,
327,
9126,
949,
330,
1073,
316,
267,
291,
855,
2379,
63,
24042,
63,
1430,
275,
488,
267,
291,
855,
2671,
275,
488,
267,
291,
14,
353,
63,
1997,
342,
221,
327,
5305,
1174,
339,
347,
7485,
63,
265,
8,
277,
304,
267,
408,
353,
397,
491,
1149,
641,
624,
398,
291,
855,
7505,
63,
1397,
63,
24042,
316,
342,
267,
20899,
14,
1199,
8,
277,
14,
7751,
12,
715,
9,
339,
347,
7485,
63,
1997,
8,
277,
304,
267,
408,
353,
397,
491,
1149,
2331,
624,
398,
291,
855,
7505,
63,
1397,
63,
24042,
316,
342,
267,
20899,
14,
1199,
8,
277,
14,
7751,
12,
756,
9,
339,
347,
330,
1073,
63,
7015,
8,
277,
304,
267,
408,
17116,
7377,
330,
1073,
316,
402,
491,
1149,
624,
398,
291,
14,
24042,
8,
16,
14,
1690,
9,
339,
347,
330,
1073,
63,
14362,
8,
277,
304,
267,
408,
17116,
11999,
330,
1073,
316,
402,
491,
1149,
624,
398,
291,
14,
24042,
8,
16,
14,
21,
9,
339,
347,
330,
1073,
8,
277,
12,
9857,
304,
267,
408,
17116,
330,
1073,
316,
402,
491,
1149,
624,
398,
340,
291,
855,
24042,
316,
63,
11132,
508,
446,
17,
26,
288,
327,
949,
330,
1073,
316,
5544,
9265,
1218,
7239,
367,
652,
288,
291,
855,
2379,
63,
24042,
63,
1430,
275,
5796,
14,
2390,
342,
288,
291,
855,
2671,
275,
5796,
14,
4436,
8,
1375,
29,
277,
855,
1117,
63,
24042,
316,
9,
288,
291,
855,
2671,
14,
10824,
275,
715,
288,
291,
855,
2671,
14,
928,
342,
398,
291,
855,
24042,
316,
63,
11132,
275,
9857,
339,
347,
636,
1117,
63,
24042,
316,
8,
277,
304,
267,
1174,
275,
756,
267,
20899,
14,
1199,
8,
277,
14,
7751,
12,
1174,
9,
398,
1830,
440,
291,
855,
2379,
63,
24042,
63,
1430,
14,
374,
63,
409,
837,
288,
1174,
275,
440,
1174,
288,
20899,
14,
1199,
8,
277,
14,
7751,
12,
1174,
9,
288,
291,
855,
2379,
63,
24042,
63,
1430,
14,
2573,
8,
277,
855,
24042,
316,
63,
11132,
9,
339,
347,
636,
7505,
63,
1397,
63,
24042,
316,
8,
277,
304,
267,
340,
291,
855,
24042,
316,
63,
11132,
508,
446,
17,
26,
288,
372,
398,
291,
855,
2379,
63,
24042,
63,
1430,
14,
409,
342,
267,
291,
855,
2671,
14,
904,
342,
267,
291,
855,
24042,
316,
63,
11132,
275,
446,
17,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
120,
124,
624,
199,
4590,
83,
367,
18746,
7256,
8539,
370,
20899,
199,
624,
199,
646,
5796,
199,
646,
820,
10542,
14,
21071,
465,
20899,
421,
199,
533,
491,
379,
8,
785,
304,
272,
408,
10755,
491,
1149,
465,
1072,
624,
339,
347,
636,
826,
721,
277,
12,
10713,
304,
267,
291,
14,
7751,
275,
10713,
267,
20899,
14,
2758,
8,
277,
14,
7751,
12,
20899,
14,
1877,
9,
267,
291,
855,
24042,
316,
63,
11132,
275,
446,
17,
221,
327,
9126,
949,
330,
1073,
316,
267,
291,
855,
2379,
63,
24042,
63,
1430,
275,
488,
267,
291,
855,
2671,
275,
488,
267,
291,
14,
353,
63,
1997,
342,
221,
327,
5305,
1174,
339,
347,
7485,
63,
265,
8,
277,
304,
267,
408,
353,
397,
491,
1149,
641,
624,
398,
291,
855,
7505,
63,
1397,
63,
24042,
316,
342,
267,
20899,
14,
1199,
8,
277,
14,
7751,
12,
715,
9,
339,
347,
7485,
63,
1997,
8,
277,
304,
267,
408,
353,
397,
491,
1149,
2331,
624,
398,
291,
855,
7505,
63,
1397,
63,
24042,
316,
342,
267,
20899,
14,
1199,
8,
277,
14,
7751,
12,
756,
9,
339,
347,
330,
1073,
63,
7015,
8,
277,
304,
267,
408,
17116,
7377,
330,
1073,
316,
402,
491,
1149,
624,
398,
291,
14,
24042,
8,
16,
14,
1690,
9,
339,
347,
330,
1073,
63,
14362,
8,
277,
304,
267,
408,
17116,
11999,
330,
1073,
316,
402,
491,
1149,
624,
398,
291,
14,
24042,
8,
16,
14,
21,
9,
339,
347,
330,
1073,
8,
277,
12,
9857,
304,
267,
408,
17116,
330,
1073,
316,
402,
491,
1149,
624,
398,
340,
291,
855,
24042,
316,
63,
11132,
508,
446,
17,
26,
288,
327,
949,
330,
1073,
316,
5544,
9265,
1218,
7239,
367,
652,
288,
291,
855,
2379,
63,
24042,
63,
1430,
275,
5796,
14,
2390,
342,
288,
291,
855,
2671,
275,
5796,
14,
4436,
8,
1375,
29,
277,
855,
1117,
63,
24042,
316,
9,
288,
291,
855,
2671,
14,
10824,
275,
715,
288,
291,
855,
2671,
14,
928,
342,
398,
291,
855,
24042,
316,
63,
11132,
275,
9857,
339,
347,
636,
1117,
63,
24042,
316,
8,
277,
304,
267,
1174,
275,
756,
267,
20899,
14,
1199,
8,
277,
14,
7751,
12,
1174,
9,
398,
1830,
440,
291,
855,
2379,
63,
24042,
63,
1430,
14,
374,
63,
409,
837,
288,
1174,
275,
440,
1174,
288,
20899,
14,
1199,
8,
277,
14,
7751,
12,
1174,
9,
288,
291,
855,
2379,
63,
24042,
63,
1430,
14,
2573,
8,
277,
855,
24042,
316,
63,
11132,
9,
339,
347,
636,
7505,
63,
1397,
63,
24042,
316,
8,
277,
304,
267,
340,
291,
855,
24042,
316,
63,
11132,
508,
446,
17,
26,
288,
372,
398,
291,
855,
2379,
63,
24042,
63,
1430,
14,
409,
342,
267,
291,
855,
2671,
14,
904,
342,
267,
291,
855,
24042,
316,
63,
11132,
275,
446,
17,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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
] |
bobisme/odoo
|
addons/im_livechat/im_livechat.py
|
36
|
11826
|
# -*- 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 random
import openerp
import openerp.addons.im_chat.im_chat
from openerp.osv import osv, fields
from openerp import tools
from openerp import http
from openerp.http import request
class im_livechat_channel(osv.Model):
_name = 'im_livechat.channel'
def _get_default_image(self, cr, uid, context=None):
image_path = openerp.modules.get_module_resource('im_livechat', 'static/src/img', 'default.png')
return tools.image_resize_image_big(open(image_path, 'rb').read().encode('base64'))
def _get_image(self, cr, uid, ids, name, args, context=None):
result = dict.fromkeys(ids, False)
for obj in self.browse(cr, uid, ids, context=context):
result[obj.id] = tools.image_get_resized_images(obj.image)
return result
def _set_image(self, cr, uid, id, name, value, args, context=None):
return self.write(cr, uid, [id], {'image': tools.image_resize_image_big(value)}, context=context)
def _are_you_inside(self, cr, uid, ids, name, arg, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
res[record.id] = False
for user in record.user_ids:
if user.id == uid:
res[record.id] = True
break
return res
def _script_external(self, cr, uid, ids, name, arg, context=None):
values = {
"url": self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url'),
"dbname":cr.dbname
}
res = {}
for record in self.browse(cr, uid, ids, context=context):
values["channel"] = record.id
res[record.id] = self.pool['ir.ui.view'].render(cr, uid, 'im_livechat.external_loader', values, context=context)
return res
def _script_internal(self, cr, uid, ids, name, arg, context=None):
values = {
"url": self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url'),
"dbname":cr.dbname
}
res = {}
for record in self.browse(cr, uid, ids, context=context):
values["channel"] = record.id
res[record.id] = self.pool['ir.ui.view'].render(cr, uid, 'im_livechat.internal_loader', values, context=context)
return res
def _web_page(self, cr, uid, ids, name, arg, context=None):
res = {}
for record in self.browse(cr, uid, ids, context=context):
res[record.id] = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url') + \
"/im_livechat/support/%s/%i" % (cr.dbname, record.id)
return res
_columns = {
'name': fields.char(string="Channel Name", size=200, required=True),
'user_ids': fields.many2many('res.users', 'im_livechat_channel_im_user', 'channel_id', 'user_id', string="Users"),
'are_you_inside': fields.function(_are_you_inside, type='boolean', string='Are you inside the matrix?', store=False),
'script_internal': fields.function(_script_internal, type='text', string='Script (internal)', store=False),
'script_external': fields.function(_script_external, type='text', string='Script (external)', store=False),
'web_page': fields.function(_web_page, type='char', string='Web Page', store=False),
'button_text': fields.char(string="Text of the Button"),
'input_placeholder': fields.char(string="Chat Input Placeholder"),
'default_message': fields.char(string="Welcome Message", help="This is an automated 'welcome' message that your visitor will see when they initiate a new chat session."),
# image: all image fields are base64 encoded and PIL-supported
'image': fields.binary("Photo",
help="This field holds the image used as photo for the group, limited to 1024x1024px."),
'image_medium': fields.function(_get_image, fnct_inv=_set_image,
string="Medium-sized photo", type="binary", multi="_get_image",
store={
'im_livechat.channel': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
},
help="Medium-sized photo of the group. It is automatically "\
"resized as a 128x128px image, with aspect ratio preserved. "\
"Use this field in form views or some kanban views."),
'image_small': fields.function(_get_image, fnct_inv=_set_image,
string="Small-sized photo", type="binary", multi="_get_image",
store={
'im_livechat.channel': (lambda self, cr, uid, ids, c={}: ids, ['image'], 10),
},
help="Small-sized photo of the group. It is automatically "\
"resized as a 64x64px image, with aspect ratio preserved. "\
"Use this field anywhere a small image is required."),
}
def _default_user_ids(self, cr, uid, context=None):
return [(6, 0, [uid])]
_defaults = {
'button_text': "Have a Question? Chat with us.",
'input_placeholder': "How may I help you?",
'default_message': '',
'user_ids': _default_user_ids,
'image': _get_default_image,
}
def get_available_users(self, cr, uid, channel_id, context=None):
""" get available user of a given channel """
channel = self.browse(cr, uid, channel_id, context=context)
users = []
for user_id in channel.user_ids:
if (user_id.im_status == 'online'):
users.append(user_id)
return users
def get_channel_session(self, cr, uid, channel_id, anonymous_name, context=None):
""" return a session given a channel : create on with a registered user, or return false otherwise """
# get the avalable user of the channel
users = self.get_available_users(cr, uid, channel_id, context=context)
if len(users) == 0:
return False
user_id = random.choice(users).id
# create the session, and add the link with the given channel
Session = self.pool["im_chat.session"]
newid = Session.create(cr, uid, {'user_ids': [(4, user_id)], 'channel_id': channel_id, 'anonymous_name' : anonymous_name}, context=context)
return Session.session_info(cr, uid, [newid], context=context)
def test_channel(self, cr, uid, channel, context=None):
if not channel:
return {}
return {
'url': self.browse(cr, uid, channel[0], context=context or {}).web_page,
'type': 'ir.actions.act_url'
}
def get_info_for_chat_src(self, cr, uid, channel, context=None):
url = self.pool.get('ir.config_parameter').get_param(cr, uid, 'web.base.url')
chan = self.browse(cr, uid, channel, context=context)
return {
"url": url,
'buttonText': chan.button_text,
'inputPlaceholder': chan.input_placeholder,
'defaultMessage': chan.default_message,
"channelName": chan.name,
}
def join(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'user_ids': [(4, uid)]})
return True
def quit(self, cr, uid, ids, context=None):
self.write(cr, uid, ids, {'user_ids': [(3, uid)]})
return True
class im_chat_session(osv.Model):
_inherit = 'im_chat.session'
def _get_fullname(self, cr, uid, ids, fields, arg, context=None):
""" built the complete name of the session """
result = {}
sessions = self.browse(cr, uid, ids, context=context)
for session in sessions:
names = []
for user in session.user_ids:
names.append(user.name)
if session.anonymous_name:
names.append(session.anonymous_name)
result[session.id] = ', '.join(names)
return result
_columns = {
'anonymous_name' : fields.char('Anonymous Name'),
'channel_id': fields.many2one("im_livechat.channel", "Channel"),
'fullname' : fields.function(_get_fullname, type="char", string="Complete name"),
}
def users_infos(self, cr, uid, ids, context=None):
""" add the anonymous user in the user of the session """
for session in self.browse(cr, uid, ids, context=context):
users_infos = super(im_chat_session, self).users_infos(cr, uid, ids, context=context)
if session.anonymous_name:
users_infos.append({'id' : False, 'name' : session.anonymous_name, 'im_status' : 'online'})
return users_infos
class LiveChatController(http.Controller):
@http.route('/im_livechat/support/<string:dbname>/<int:channel_id>', type='http', auth='none')
def support_page(self, dbname, channel_id, **kwargs):
registry, cr, uid, context = openerp.modules.registry.RegistryManager.get(dbname), request.cr, openerp.SUPERUSER_ID, request.context
info = registry.get('im_livechat.channel').get_info_for_chat_src(cr, uid, channel_id)
info["dbname"] = dbname
info["channel"] = channel_id
info["channel_name"] = registry.get('im_livechat.channel').read(cr, uid, channel_id, ['name'], context=context)["name"]
return request.render('im_livechat.support_page', info)
@http.route('/im_livechat/loader/<string:dbname>/<int:channel_id>', type='http', auth='none')
def loader(self, dbname, channel_id, **kwargs):
registry, cr, uid, context = openerp.modules.registry.RegistryManager.get(dbname), request.cr, openerp.SUPERUSER_ID, request.context
info = registry.get('im_livechat.channel').get_info_for_chat_src(cr, uid, channel_id)
info["dbname"] = dbname
info["channel"] = channel_id
info["username"] = kwargs.get("username", "Visitor")
return request.render('im_livechat.loader', info)
@http.route('/im_livechat/get_session', type="json", auth="none")
def get_session(self, channel_id, anonymous_name):
cr, uid, context, db = request.cr, request.uid or openerp.SUPERUSER_ID, request.context, request.db
reg = openerp.modules.registry.RegistryManager.get(db)
# if geoip, add the country name to the anonymous name
if hasattr(request, 'geoip'):
anonymous_name = anonymous_name + " ("+request.geoip.get('country_name', "")+")"
return reg.get("im_livechat.channel").get_channel_session(cr, uid, channel_id, anonymous_name, context=context)
@http.route('/im_livechat/available', type='json', auth="none")
def available(self, db, channel):
cr, uid, context, db = request.cr, request.uid or openerp.SUPERUSER_ID, request.context, request.db
reg = openerp.modules.registry.RegistryManager.get(db)
with reg.cursor() as cr:
return len(reg.get('im_livechat.channel').get_available_users(cr, uid, channel)) > 0
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
2196,
199,
646,
5166,
199,
646,
5166,
14,
10788,
14,
1017,
63,
10289,
14,
1017,
63,
10289,
199,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
504,
5166,
492,
7249,
199,
504,
5166,
492,
1455,
199,
504,
5166,
14,
1014,
492,
1056,
199,
199,
533,
3416,
63,
6442,
10289,
63,
2775,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
283,
1017,
63,
6442,
10289,
14,
2775,
7,
339,
347,
485,
362,
63,
885,
63,
1569,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
1834,
63,
515,
275,
5166,
14,
3112,
14,
362,
63,
578,
63,
1927,
360,
1017,
63,
6442,
10289,
297,
283,
1986,
15,
2164,
15,
4060,
297,
283,
885,
14,
4524,
358,
267,
372,
7249,
14,
1569,
63,
8709,
63,
1569,
63,
5076,
8,
1490,
8,
1569,
63,
515,
12,
283,
4848,
1959,
739,
1252,
2143,
360,
1095,
772,
1333,
272,
347,
485,
362,
63,
1569,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1249,
12,
1067,
29,
403,
304,
267,
754,
275,
1211,
14,
19164,
8,
1580,
12,
756,
9,
267,
367,
1559,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
754,
59,
1113,
14,
344,
61,
275,
7249,
14,
1569,
63,
362,
63,
264,
15308,
63,
4782,
8,
1113,
14,
1569,
9,
267,
372,
754,
272,
347,
485,
409,
63,
1569,
8,
277,
12,
2467,
12,
1747,
12,
1305,
12,
536,
12,
574,
12,
1249,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
952,
8,
1556,
12,
1747,
12,
359,
344,
467,
791,
1569,
356,
7249,
14,
1569,
63,
8709,
63,
1569,
63,
5076,
8,
585,
16658,
1067,
29,
1100,
9,
339,
347,
485,
1530,
63,
13297,
63,
17183,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1680,
12,
1067,
29,
403,
304,
267,
522,
275,
1052,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
522,
59,
3059,
14,
344,
61,
275,
756,
288,
367,
922,
315,
2777,
14,
751,
63,
1580,
26,
355,
340,
922,
14,
344,
508,
1747,
26,
490,
522,
59,
3059,
14,
344,
61,
275,
715,
490,
2059,
267,
372,
522,
339,
347,
485,
1579,
63,
5159,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1680,
12,
1067,
29,
403,
304,
267,
1338,
275,
469,
288,
298,
633,
582,
291,
14,
2293,
14,
362,
360,
723,
14,
888,
63,
5329,
1959,
362,
63,
635,
8,
1556,
12,
1747,
12,
283,
2520,
14,
1095,
14,
633,
659,
288,
298,
13238,
582,
1556,
14,
13238,
267,
789,
267,
522,
275,
1052,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
1338,
905,
2775,
937,
275,
2777,
14,
344,
288,
522,
59,
3059,
14,
344,
61,
275,
291,
14,
2293,
459,
723,
14,
1907,
14,
1345,
2278,
3352,
8,
1556,
12,
1747,
12,
283,
1017,
63,
6442,
10289,
14,
5159,
63,
3422,
297,
1338,
12,
1067,
29,
1100,
9,
267,
372,
522,
339,
347,
485,
1579,
63,
4672,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1680,
12,
1067,
29,
403,
304,
267,
1338,
275,
469,
288,
298,
633,
582,
291,
14,
2293,
14,
362,
360,
723,
14,
888,
63,
5329,
1959,
362,
63,
635,
8,
1556,
12,
1747,
12,
283,
2520,
14,
1095,
14,
633,
659,
288,
298,
13238,
582,
1556,
14,
13238,
267,
789,
267,
522,
275,
1052,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
1338,
905,
2775,
937,
275,
2777,
14,
344,
288,
522,
59,
3059,
14,
344,
61,
275,
291,
14,
2293,
459,
723,
14,
1907,
14,
1345,
2278,
3352,
8,
1556,
12,
1747,
12,
283,
1017,
63,
6442,
10289,
14,
4672,
63,
3422,
297,
1338,
12,
1067,
29,
1100,
9,
267,
372,
522,
339,
347,
485,
2520,
63,
1606,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1680,
12,
1067,
29,
403,
304,
267,
522,
275,
1052,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
522,
59,
3059,
14,
344,
61,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
888,
63,
5329,
1959,
362,
63,
635,
8,
1556,
12,
1747,
12,
283,
2520,
14,
1095,
14,
633,
358,
435,
971,
355,
3286,
1017,
63,
6442,
10289,
15,
4058,
3149,
83,
3149,
73,
2,
450,
334,
1556,
14,
13238,
12,
2777,
14,
344,
9,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
8,
875,
628,
5358,
2812,
401,
1568,
29,
1840,
12,
1415,
29,
549,
395,
267,
283,
751,
63,
1580,
356,
1504,
14,
3479,
18,
3479,
360,
470,
14,
3707,
297,
283,
1017,
63,
6442,
10289,
63,
2775,
63,
1017
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
646,
2196,
199,
646,
5166,
199,
646,
5166,
14,
10788,
14,
1017,
63,
10289,
14,
1017,
63,
10289,
199,
199,
504,
5166,
14,
4795,
492,
9506,
12,
1504,
199,
504,
5166,
492,
7249,
199,
504,
5166,
492,
1455,
199,
504,
5166,
14,
1014,
492,
1056,
199,
199,
533,
3416,
63,
6442,
10289,
63,
2775,
8,
4795,
14,
1685,
304,
272,
485,
354,
275,
283,
1017,
63,
6442,
10289,
14,
2775,
7,
339,
347,
485,
362,
63,
885,
63,
1569,
8,
277,
12,
2467,
12,
1747,
12,
1067,
29,
403,
304,
267,
1834,
63,
515,
275,
5166,
14,
3112,
14,
362,
63,
578,
63,
1927,
360,
1017,
63,
6442,
10289,
297,
283,
1986,
15,
2164,
15,
4060,
297,
283,
885,
14,
4524,
358,
267,
372,
7249,
14,
1569,
63,
8709,
63,
1569,
63,
5076,
8,
1490,
8,
1569,
63,
515,
12,
283,
4848,
1959,
739,
1252,
2143,
360,
1095,
772,
1333,
272,
347,
485,
362,
63,
1569,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1249,
12,
1067,
29,
403,
304,
267,
754,
275,
1211,
14,
19164,
8,
1580,
12,
756,
9,
267,
367,
1559,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
754,
59,
1113,
14,
344,
61,
275,
7249,
14,
1569,
63,
362,
63,
264,
15308,
63,
4782,
8,
1113,
14,
1569,
9,
267,
372,
754,
272,
347,
485,
409,
63,
1569,
8,
277,
12,
2467,
12,
1747,
12,
1305,
12,
536,
12,
574,
12,
1249,
12,
1067,
29,
403,
304,
267,
372,
291,
14,
952,
8,
1556,
12,
1747,
12,
359,
344,
467,
791,
1569,
356,
7249,
14,
1569,
63,
8709,
63,
1569,
63,
5076,
8,
585,
16658,
1067,
29,
1100,
9,
339,
347,
485,
1530,
63,
13297,
63,
17183,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1680,
12,
1067,
29,
403,
304,
267,
522,
275,
1052,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
522,
59,
3059,
14,
344,
61,
275,
756,
288,
367,
922,
315,
2777,
14,
751,
63,
1580,
26,
355,
340,
922,
14,
344,
508,
1747,
26,
490,
522,
59,
3059,
14,
344,
61,
275,
715,
490,
2059,
267,
372,
522,
339,
347,
485,
1579,
63,
5159,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1680,
12,
1067,
29,
403,
304,
267,
1338,
275,
469,
288,
298,
633,
582,
291,
14,
2293,
14,
362,
360,
723,
14,
888,
63,
5329,
1959,
362,
63,
635,
8,
1556,
12,
1747,
12,
283,
2520,
14,
1095,
14,
633,
659,
288,
298,
13238,
582,
1556,
14,
13238,
267,
789,
267,
522,
275,
1052,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
1338,
905,
2775,
937,
275,
2777,
14,
344,
288,
522,
59,
3059,
14,
344,
61,
275,
291,
14,
2293,
459,
723,
14,
1907,
14,
1345,
2278,
3352,
8,
1556,
12,
1747,
12,
283,
1017,
63,
6442,
10289,
14,
5159,
63,
3422,
297,
1338,
12,
1067,
29,
1100,
9,
267,
372,
522,
339,
347,
485,
1579,
63,
4672,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1680,
12,
1067,
29,
403,
304,
267,
1338,
275,
469,
288,
298,
633,
582,
291,
14,
2293,
14,
362,
360,
723,
14,
888,
63,
5329,
1959,
362,
63,
635,
8,
1556,
12,
1747,
12,
283,
2520,
14,
1095,
14,
633,
659,
288,
298,
13238,
582,
1556,
14,
13238,
267,
789,
267,
522,
275,
1052,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
1338,
905,
2775,
937,
275,
2777,
14,
344,
288,
522,
59,
3059,
14,
344,
61,
275,
291,
14,
2293,
459,
723,
14,
1907,
14,
1345,
2278,
3352,
8,
1556,
12,
1747,
12,
283,
1017,
63,
6442,
10289,
14,
4672,
63,
3422,
297,
1338,
12,
1067,
29,
1100,
9,
267,
372,
522,
339,
347,
485,
2520,
63,
1606,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
536,
12,
1680,
12,
1067,
29,
403,
304,
267,
522,
275,
1052,
267,
367,
2777,
315,
291,
14,
4570,
8,
1556,
12,
1747,
12,
2762,
12,
1067,
29,
1100,
304,
288,
522,
59,
3059,
14,
344,
61,
275,
291,
14,
2293,
14,
362,
360,
723,
14,
888,
63,
5329,
1959,
362,
63,
635,
8,
1556,
12,
1747,
12,
283,
2520,
14,
1095,
14,
633,
358,
435,
971,
355,
3286,
1017,
63,
6442,
10289,
15,
4058,
3149,
83,
3149,
73,
2,
450,
334,
1556,
14,
13238,
12,
2777,
14,
344,
9,
267,
372,
522,
339,
485,
3406,
275,
469,
267,
283,
354,
356,
1504,
14,
1560,
8,
875,
628,
5358,
2812,
401,
1568,
29,
1840,
12,
1415,
29,
549,
395,
267,
283,
751,
63,
1580,
356,
1504,
14,
3479,
18,
3479,
360,
470,
14,
3707,
297,
283,
1017,
63,
6442,
10289,
63,
2775,
63,
1017,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ucsb-seclab/dr_checker
|
helper_scripts/runner_scripts/components/entry_point_identifier.py
|
1
|
4615
|
from base_component import *
import os
class EntryPointIdentifier(Component):
"""
This component tries to find entry point functions from provided bitcode file and hdr file list.
"""
def __init__(self, value_dict):
ep_finder_bin = None
ep_config = None
llvm_bc_out = None
entry_point_out = None
if 'llvm_bc_out' in value_dict:
llvm_bc_out = value_dict['llvm_bc_out']
if 'ep_finder_bin' in value_dict:
ep_finder_bin = value_dict['ep_finder_bin']
if 'hdr_file_list' in value_dict:
ep_config = value_dict['hdr_file_list']
if 'entry_point_out' in value_dict:
entry_point_out = value_dict['entry_point_out']
self.ep_finder_bin = ep_finder_bin
self.ep_config_file = ep_config
self.llvm_bc_out = llvm_bc_out
self.entry_point_out = entry_point_out
def setup(self):
if not os.path.exists(self.llvm_bc_out) or not os.path.isdir(self.llvm_bc_out):
return "Provided LLVM Bitcode directory:" + str(self.llvm_bc_out) + " does not exist."
if not os.path.exists(self.ep_finder_bin):
return "Provided ep finder bin path:" + str(self.ep_finder_bin) + " does not exist."
if self.entry_point_out is None or os.path.isdir(self.entry_point_out):
return "Provided entry point out file path:" + str(self.entry_point_out) + " is invalid."
return None
def perform(self):
log_info("Running EntryPointIdentifier..")
ret_val = _generate_entry_points(self.ep_finder_bin, self.llvm_bc_out, self.entry_point_out,
entry_point_file=self.ep_config_file)
if ret_val:
log_success("Successfully generated all the possible entry points into file:", self.entry_point_out)
else:
log_error("EntryPointIdentifier failed.")
return ret_val
def get_name(self):
return "EntryPointIdentifier"
def is_critical(self):
# Yes, this is critical.
return True
BASE_FOLDER_NAME = "llvm_link_final"
FINAL_BC_FILE = "final_to_check.bc"
def _find_all_interesting_dirs(base_dir):
to_ret = []
check_p = os.path.join(base_dir, BASE_FOLDER_NAME)
if os.path.exists(check_p):
to_ret.append(check_p)
for curr_dir in os.listdir(base_dir):
curr_dir_fp = os.path.join(base_dir, curr_dir)
if os.path.isdir(curr_dir_fp):
child_dirs = _find_all_interesting_dirs(curr_dir_fp)
to_ret.extend(child_dirs)
return to_ret
def _process_entry_out(output_file, target_bc_file, analysis_funcs, out_cache):
fp = open(output_file, 'r')
all_lines = fp.readlines()
for curr_li in all_lines:
curr_li = curr_li.strip()
if curr_li:
if curr_li not in out_cache:
out_cache.append(curr_li)
analysis_funcs.append(curr_li + ':' + target_bc_file)
fp.close()
def _generate_entry_points(entry_point_bin, llvm_bin_out, out_analysis_script, entry_point_file=None):
# got all interesting dirs
interesting_dirs = _find_all_interesting_dirs(llvm_bin_out)
if os.path.exists(entry_point_file):
log_success("Entry point file present:" + entry_point_file)
else:
log_warning("No entry point file.")
out_analysis_funcs = []
out_analysis_cache = []
for curr_int_dir in interesting_dirs:
final_bc_file = os.path.join(curr_int_dir, FINAL_BC_FILE)
to_process_files = []
# good we found our final bc file
if os.path.exists(final_bc_file):
to_process_files.append(final_bc_file)
else:
for curr_fi in os.listdir(curr_int_dir):
to_process_files.append(os.path.join(curr_int_dir, curr_fi))
for curr_fi in to_process_files:
log_info("EntryPointIdentifier Processing:" + curr_fi)
entry_point_out = curr_fi + '.all_entries'
if os.path.exists(entry_point_file):
os.system(entry_point_bin + ' ' + curr_fi + ' ' + entry_point_out + ' ' +
entry_point_file + ' > /dev/null 2>&1')
else:
os.system(entry_point_bin + ' ' + curr_fi + ' ' + entry_point_out + ' > /dev/null 2>&1')
assert(os.path.exists(entry_point_out))
_process_entry_out(entry_point_out, curr_fi, out_analysis_funcs, out_analysis_cache)
fp = open(out_analysis_script, "w")
for curr_en in out_analysis_funcs:
fp.write(curr_en + "\n")
fp.close()
return True
|
bsd-2-clause
|
[
504,
1300,
63,
3173,
492,
627,
199,
646,
747,
421,
199,
533,
11855,
3428,
7544,
8,
7004,
304,
272,
408,
267,
961,
3931,
11275,
370,
2342,
2397,
2376,
3423,
687,
2741,
4546,
600,
570,
436,
15260,
570,
769,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
574,
63,
807,
304,
267,
5442,
63,
11681,
63,
1393,
275,
488,
267,
5442,
63,
888,
275,
488,
267,
18338,
2611,
63,
3776,
63,
548,
275,
488,
267,
2397,
63,
1403,
63,
548,
275,
488,
267,
340,
283,
29257,
63,
3776,
63,
548,
7,
315,
574,
63,
807,
26,
288,
18338,
2611,
63,
3776,
63,
548,
275,
574,
63,
807,
459,
29257,
63,
3776,
63,
548,
418,
267,
340,
283,
1545,
63,
11681,
63,
1393,
7,
315,
574,
63,
807,
26,
288,
5442,
63,
11681,
63,
1393,
275,
574,
63,
807,
459,
1545,
63,
11681,
63,
1393,
418,
267,
340,
283,
11244,
63,
493,
63,
513,
7,
315,
574,
63,
807,
26,
288,
5442,
63,
888,
275,
574,
63,
807,
459,
11244,
63,
493,
63,
513,
418,
267,
340,
283,
2373,
63,
1403,
63,
548,
7,
315,
574,
63,
807,
26,
288,
2397,
63,
1403,
63,
548,
275,
574,
63,
807,
459,
2373,
63,
1403,
63,
548,
418,
267,
291,
14,
1545,
63,
11681,
63,
1393,
275,
5442,
63,
11681,
63,
1393,
267,
291,
14,
1545,
63,
888,
63,
493,
275,
5442,
63,
888,
267,
291,
14,
29257,
63,
3776,
63,
548,
275,
18338,
2611,
63,
3776,
63,
548,
267,
291,
14,
2373,
63,
1403,
63,
548,
275,
2397,
63,
1403,
63,
548,
339,
347,
3272,
8,
277,
304,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
277,
14,
29257,
63,
3776,
63,
548,
9,
503,
440,
747,
14,
515,
14,
6027,
8,
277,
14,
29257,
63,
3776,
63,
548,
304,
288,
372,
298,
919,
11923,
491,
28631,
10199,
600,
2082,
5424,
435,
620,
8,
277,
14,
29257,
63,
3776,
63,
548,
9,
435,
298,
1630,
440,
2187,
2122,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
277,
14,
1545,
63,
11681,
63,
1393,
304,
288,
372,
298,
919,
11923,
5442,
11569,
2517,
931,
5424,
435,
620,
8,
277,
14,
1545,
63,
11681,
63,
1393,
9,
435,
298,
1630,
440,
2187,
2122,
267,
340,
291,
14,
2373,
63,
1403,
63,
548,
365,
488,
503,
747,
14,
515,
14,
6027,
8,
277,
14,
2373,
63,
1403,
63,
548,
304,
288,
372,
298,
919,
11923,
2397,
2376,
734,
570,
931,
5424,
435,
620,
8,
277,
14,
2373,
63,
1403,
63,
548,
9,
435,
298,
365,
3866,
2122,
267,
372,
488,
339,
347,
5147,
8,
277,
304,
267,
943,
63,
815,
480,
9602,
11855,
3428,
7544,
703,
531,
267,
2203,
63,
637,
275,
485,
4208,
63,
2373,
63,
3438,
8,
277,
14,
1545,
63,
11681,
63,
1393,
12,
291,
14,
29257,
63,
3776,
63,
548,
12,
291,
14,
2373,
63,
1403,
63,
548,
12,
1460,
2397,
63,
1403,
63,
493,
29,
277,
14,
1545,
63,
888,
63,
493,
9,
267,
340,
2203,
63,
637,
26,
288,
943,
63,
3742,
480,
25001,
4046,
1006,
314,
3962,
2397,
4501,
1901,
570,
6783,
291,
14,
2373,
63,
1403,
63,
548,
9,
267,
587,
26,
288,
943,
63,
705,
480,
30485,
7544,
3405,
2685,
267,
372,
2203,
63,
637,
339,
347,
664,
63,
354,
8,
277,
304,
267,
372,
298,
30485,
7544,
2,
339,
347,
365,
63,
13138,
8,
277,
304,
267,
327,
29715,
12,
642,
365,
19698,
14,
267,
372,
715,
421,
199,
5825,
63,
19041,
63,
2339,
275,
298,
29257,
63,
1073,
63,
5094,
2,
199,
29270,
63,
6265,
63,
3817,
275,
298,
5094,
63,
475,
63,
1074,
14,
3776,
2,
421,
199,
318,
485,
1623,
63,
452,
63,
30267,
63,
3220,
8,
1095,
63,
694,
304,
272,
370,
63,
3292,
275,
942,
272,
1104,
63,
80,
275,
747,
14,
515,
14,
904,
8,
1095,
63,
694,
12,
19721,
63,
19041,
63,
2339,
9,
272,
340,
747,
14,
515,
14,
2444,
8,
1074,
63,
80,
304,
267,
370,
63,
3292,
14,
740,
8,
1074,
63,
80,
9,
272,
367,
8230,
63,
694,
315,
747,
14,
7374,
8,
1095,
63,
694,
304,
267,
8230,
63,
694,
63,
3997,
275,
747,
14,
515,
14,
904,
8,
1095,
63,
694,
12,
8230,
63,
694,
9,
267,
340,
747,
14,
515,
14,
6027,
8,
9808,
63,
694,
63,
3997,
304,
288,
1982,
63,
3220,
275,
485,
1623,
63,
452,
63,
30267,
63,
3220,
8,
9808,
63,
694,
63,
3997,
9,
288,
370,
63,
3292,
14,
2880,
8,
1739,
63,
3220,
9,
272,
372,
370,
63,
3292,
421,
199,
318,
485,
1412,
63,
2373,
63,
548,
8,
1199,
63,
493,
12,
1347,
63,
3776,
63,
493,
12,
11284,
63,
9204,
12,
734,
63,
1637,
304,
272,
4090,
275,
1551,
8,
1199,
63,
493,
12,
283,
82,
358,
272,
1006,
63,
1278,
275,
4090,
14,
9684,
342,
272,
367,
8230,
63,
317,
315,
1006,
63,
1278,
26,
267,
8230,
63,
317,
275,
8230,
63,
317,
14,
1913,
342,
267,
340,
8230,
63,
317,
26,
288,
340,
8230,
63,
317,
440,
315,
734,
63,
1637,
26,
355,
734,
63,
1637,
14,
740,
8,
9808,
63,
317,
9,
355,
11284,
63,
9204,
14,
740,
8,
9808,
63,
317,
435,
10871,
435,
1347,
63,
3776,
63,
493,
9,
272,
4090,
14,
1600,
342,
421,
199,
318,
485,
4208,
63,
2373,
63,
3438,
8,
2373,
63,
1403,
63,
1393,
12,
18338,
2611,
63,
1393,
63,
548,
12,
734,
63,
10466,
63,
1579,
12,
2397,
63,
1403,
63,
493,
29,
403,
304,
339,
327,
4788,
1006,
19604,
7606,
272,
19604,
63,
3220,
275,
485,
1623,
63,
452,
63,
30267,
63,
3220,
8,
29257,
63,
1393,
63,
548,
9,
272,
340,
747,
14,
515,
14,
2444,
8,
2373,
63,
1403,
63,
493,
304,
267,
943,
63,
3742,
480,
3900,
2376,
570,
3451,
5424,
435,
2397,
63,
1403,
63,
493,
9,
272,
587,
26,
267,
943,
63,
3764,
480,
1944,
2397,
2376,
570,
2685,
272,
734,
63,
10466,
63,
9204,
275,
942,
272,
734,
63,
10466,
63,
1637,
275,
942,
272,
367,
8230,
63,
442,
63,
694,
315,
19604,
63,
3220,
26,
267,
4242,
63,
3776,
63,
493,
275,
747,
14,
515
] |
[
1300,
63,
3173,
492,
627,
199,
646,
747,
421,
199,
533,
11855,
3428,
7544,
8,
7004,
304,
272,
408,
267,
961,
3931,
11275,
370,
2342,
2397,
2376,
3423,
687,
2741,
4546,
600,
570,
436,
15260,
570,
769,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
574,
63,
807,
304,
267,
5442,
63,
11681,
63,
1393,
275,
488,
267,
5442,
63,
888,
275,
488,
267,
18338,
2611,
63,
3776,
63,
548,
275,
488,
267,
2397,
63,
1403,
63,
548,
275,
488,
267,
340,
283,
29257,
63,
3776,
63,
548,
7,
315,
574,
63,
807,
26,
288,
18338,
2611,
63,
3776,
63,
548,
275,
574,
63,
807,
459,
29257,
63,
3776,
63,
548,
418,
267,
340,
283,
1545,
63,
11681,
63,
1393,
7,
315,
574,
63,
807,
26,
288,
5442,
63,
11681,
63,
1393,
275,
574,
63,
807,
459,
1545,
63,
11681,
63,
1393,
418,
267,
340,
283,
11244,
63,
493,
63,
513,
7,
315,
574,
63,
807,
26,
288,
5442,
63,
888,
275,
574,
63,
807,
459,
11244,
63,
493,
63,
513,
418,
267,
340,
283,
2373,
63,
1403,
63,
548,
7,
315,
574,
63,
807,
26,
288,
2397,
63,
1403,
63,
548,
275,
574,
63,
807,
459,
2373,
63,
1403,
63,
548,
418,
267,
291,
14,
1545,
63,
11681,
63,
1393,
275,
5442,
63,
11681,
63,
1393,
267,
291,
14,
1545,
63,
888,
63,
493,
275,
5442,
63,
888,
267,
291,
14,
29257,
63,
3776,
63,
548,
275,
18338,
2611,
63,
3776,
63,
548,
267,
291,
14,
2373,
63,
1403,
63,
548,
275,
2397,
63,
1403,
63,
548,
339,
347,
3272,
8,
277,
304,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
277,
14,
29257,
63,
3776,
63,
548,
9,
503,
440,
747,
14,
515,
14,
6027,
8,
277,
14,
29257,
63,
3776,
63,
548,
304,
288,
372,
298,
919,
11923,
491,
28631,
10199,
600,
2082,
5424,
435,
620,
8,
277,
14,
29257,
63,
3776,
63,
548,
9,
435,
298,
1630,
440,
2187,
2122,
267,
340,
440,
747,
14,
515,
14,
2444,
8,
277,
14,
1545,
63,
11681,
63,
1393,
304,
288,
372,
298,
919,
11923,
5442,
11569,
2517,
931,
5424,
435,
620,
8,
277,
14,
1545,
63,
11681,
63,
1393,
9,
435,
298,
1630,
440,
2187,
2122,
267,
340,
291,
14,
2373,
63,
1403,
63,
548,
365,
488,
503,
747,
14,
515,
14,
6027,
8,
277,
14,
2373,
63,
1403,
63,
548,
304,
288,
372,
298,
919,
11923,
2397,
2376,
734,
570,
931,
5424,
435,
620,
8,
277,
14,
2373,
63,
1403,
63,
548,
9,
435,
298,
365,
3866,
2122,
267,
372,
488,
339,
347,
5147,
8,
277,
304,
267,
943,
63,
815,
480,
9602,
11855,
3428,
7544,
703,
531,
267,
2203,
63,
637,
275,
485,
4208,
63,
2373,
63,
3438,
8,
277,
14,
1545,
63,
11681,
63,
1393,
12,
291,
14,
29257,
63,
3776,
63,
548,
12,
291,
14,
2373,
63,
1403,
63,
548,
12,
1460,
2397,
63,
1403,
63,
493,
29,
277,
14,
1545,
63,
888,
63,
493,
9,
267,
340,
2203,
63,
637,
26,
288,
943,
63,
3742,
480,
25001,
4046,
1006,
314,
3962,
2397,
4501,
1901,
570,
6783,
291,
14,
2373,
63,
1403,
63,
548,
9,
267,
587,
26,
288,
943,
63,
705,
480,
30485,
7544,
3405,
2685,
267,
372,
2203,
63,
637,
339,
347,
664,
63,
354,
8,
277,
304,
267,
372,
298,
30485,
7544,
2,
339,
347,
365,
63,
13138,
8,
277,
304,
267,
327,
29715,
12,
642,
365,
19698,
14,
267,
372,
715,
421,
199,
5825,
63,
19041,
63,
2339,
275,
298,
29257,
63,
1073,
63,
5094,
2,
199,
29270,
63,
6265,
63,
3817,
275,
298,
5094,
63,
475,
63,
1074,
14,
3776,
2,
421,
199,
318,
485,
1623,
63,
452,
63,
30267,
63,
3220,
8,
1095,
63,
694,
304,
272,
370,
63,
3292,
275,
942,
272,
1104,
63,
80,
275,
747,
14,
515,
14,
904,
8,
1095,
63,
694,
12,
19721,
63,
19041,
63,
2339,
9,
272,
340,
747,
14,
515,
14,
2444,
8,
1074,
63,
80,
304,
267,
370,
63,
3292,
14,
740,
8,
1074,
63,
80,
9,
272,
367,
8230,
63,
694,
315,
747,
14,
7374,
8,
1095,
63,
694,
304,
267,
8230,
63,
694,
63,
3997,
275,
747,
14,
515,
14,
904,
8,
1095,
63,
694,
12,
8230,
63,
694,
9,
267,
340,
747,
14,
515,
14,
6027,
8,
9808,
63,
694,
63,
3997,
304,
288,
1982,
63,
3220,
275,
485,
1623,
63,
452,
63,
30267,
63,
3220,
8,
9808,
63,
694,
63,
3997,
9,
288,
370,
63,
3292,
14,
2880,
8,
1739,
63,
3220,
9,
272,
372,
370,
63,
3292,
421,
199,
318,
485,
1412,
63,
2373,
63,
548,
8,
1199,
63,
493,
12,
1347,
63,
3776,
63,
493,
12,
11284,
63,
9204,
12,
734,
63,
1637,
304,
272,
4090,
275,
1551,
8,
1199,
63,
493,
12,
283,
82,
358,
272,
1006,
63,
1278,
275,
4090,
14,
9684,
342,
272,
367,
8230,
63,
317,
315,
1006,
63,
1278,
26,
267,
8230,
63,
317,
275,
8230,
63,
317,
14,
1913,
342,
267,
340,
8230,
63,
317,
26,
288,
340,
8230,
63,
317,
440,
315,
734,
63,
1637,
26,
355,
734,
63,
1637,
14,
740,
8,
9808,
63,
317,
9,
355,
11284,
63,
9204,
14,
740,
8,
9808,
63,
317,
435,
10871,
435,
1347,
63,
3776,
63,
493,
9,
272,
4090,
14,
1600,
342,
421,
199,
318,
485,
4208,
63,
2373,
63,
3438,
8,
2373,
63,
1403,
63,
1393,
12,
18338,
2611,
63,
1393,
63,
548,
12,
734,
63,
10466,
63,
1579,
12,
2397,
63,
1403,
63,
493,
29,
403,
304,
339,
327,
4788,
1006,
19604,
7606,
272,
19604,
63,
3220,
275,
485,
1623,
63,
452,
63,
30267,
63,
3220,
8,
29257,
63,
1393,
63,
548,
9,
272,
340,
747,
14,
515,
14,
2444,
8,
2373,
63,
1403,
63,
493,
304,
267,
943,
63,
3742,
480,
3900,
2376,
570,
3451,
5424,
435,
2397,
63,
1403,
63,
493,
9,
272,
587,
26,
267,
943,
63,
3764,
480,
1944,
2397,
2376,
570,
2685,
272,
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
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1
] |
qianwenming/mapnik
|
scons/scons-local-2.3.1/SCons/Node/__init__.py
|
8
|
49617
|
"""SCons.Node
The Node package for the SCons software construction utility.
This is, in many ways, the heart of SCons.
A Node is where we encapsulate all of the dependency information about
any thing that SCons can build, or about any thing which SCons can use
to build some other thing. The canonical "thing," of course, is a file,
but a Node can also represent something remote (like a web page) or
something completely abstract (like an Alias).
Each specific type of "thing" is specifically represented by a subclass
of the Node base class: Node.FS.File for files, Node.Alias for aliases,
etc. Dependency information is kept here in the base class, and
information specific to files/aliases/etc. is in the subclass. The
goal, if we've done this correctly, is that any type of "thing" should
be able to depend on any other type of "thing."
"""
#
# Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 The SCons Foundation
#
# 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.
__revision__ = "src/engine/SCons/Node/__init__.py 2014/03/02 14:18:15 garyo"
import collections
import copy
from itertools import chain
import SCons.Debug
from SCons.Debug import logInstanceCreation
import SCons.Executor
import SCons.Memoize
import SCons.Util
from SCons.Debug import Trace
def classname(obj):
return str(obj.__class__).split('.')[-1]
# Set to false if we're doing a dry run. There's more than one of these
# little treats
do_store_info = True
# Node states
#
# These are in "priority" order, so that the maximum value for any
# child/dependency of a node represents the state of that node if
# it has no builder of its own. The canonical example is a file
# system directory, which is only up to date if all of its children
# were up to date.
no_state = 0
pending = 1
executing = 2
up_to_date = 3
executed = 4
failed = 5
StateString = {
0 : "no_state",
1 : "pending",
2 : "executing",
3 : "up_to_date",
4 : "executed",
5 : "failed",
}
# controls whether implicit dependencies are cached:
implicit_cache = 0
# controls whether implicit dep changes are ignored:
implicit_deps_unchanged = 0
# controls whether the cached implicit deps are ignored:
implicit_deps_changed = 0
# A variable that can be set to an interface-specific function be called
# to annotate a Node with information about its creation.
def do_nothing(node): pass
Annotate = do_nothing
# Gets set to 'True' if we're running in interactive mode. Is
# currently used to release parts of a target's info during
# clean builds and update runs (see release_target_info).
interactive = False
# Classes for signature info for Nodes.
class NodeInfoBase(object):
"""
The generic base class for signature information for a Node.
Node subclasses should subclass NodeInfoBase to provide their own
logic for dealing with their own Node-specific signature information.
"""
current_version_id = 1
def __init__(self, node=None):
# Create an object attribute from the class attribute so it ends up
# in the pickled data in the .sconsign file.
self._version_id = self.current_version_id
def update(self, node):
try:
field_list = self.field_list
except AttributeError:
return
for f in field_list:
try:
delattr(self, f)
except AttributeError:
pass
try:
func = getattr(node, 'get_' + f)
except AttributeError:
pass
else:
setattr(self, f, func())
def convert(self, node, val):
pass
def merge(self, other):
self.__dict__.update(other.__dict__)
def format(self, field_list=None, names=0):
if field_list is None:
try:
field_list = self.field_list
except AttributeError:
field_list = sorted(self.__dict__.keys())
fields = []
for field in field_list:
try:
f = getattr(self, field)
except AttributeError:
f = None
f = str(f)
if names:
f = field + ': ' + f
fields.append(f)
return fields
class BuildInfoBase(object):
"""
The generic base class for build information for a Node.
This is what gets stored in a .sconsign file for each target file.
It contains a NodeInfo instance for this node (signature information
that's specific to the type of Node) and direct attributes for the
generic build stuff we have to track: sources, explicit dependencies,
implicit dependencies, and action information.
"""
current_version_id = 1
def __init__(self, node=None):
# Create an object attribute from the class attribute so it ends up
# in the pickled data in the .sconsign file.
self._version_id = self.current_version_id
self.bsourcesigs = []
self.bdependsigs = []
self.bimplicitsigs = []
self.bactsig = None
def merge(self, other):
self.__dict__.update(other.__dict__)
class Node(object):
"""The base Node class, for entities that we know how to
build, or use to build other Nodes.
"""
if SCons.Memoize.use_memoizer:
__metaclass__ = SCons.Memoize.Memoized_Metaclass
memoizer_counters = []
class Attrs(object):
pass
def __init__(self):
if SCons.Debug.track_instances: logInstanceCreation(self, 'Node.Node')
# Note that we no longer explicitly initialize a self.builder
# attribute to None here. That's because the self.builder
# attribute may be created on-the-fly later by a subclass (the
# canonical example being a builder to fetch a file from a
# source code system like CVS or Subversion).
# Each list of children that we maintain is accompanied by a
# dictionary used to look up quickly whether a node is already
# present in the list. Empirical tests showed that it was
# fastest to maintain them as side-by-side Node attributes in
# this way, instead of wrapping up each list+dictionary pair in
# a class. (Of course, we could always still do that in the
# future if we had a good reason to...).
self.sources = [] # source files used to build node
self.sources_set = set()
self._specific_sources = False
self.depends = [] # explicit dependencies (from Depends)
self.depends_set = set()
self.ignore = [] # dependencies to ignore
self.ignore_set = set()
self.prerequisites = None
self.implicit = None # implicit (scanned) dependencies (None means not scanned yet)
self.waiting_parents = set()
self.waiting_s_e = set()
self.ref_count = 0
self.wkids = None # Kids yet to walk, when it's an array
self.env = None
self.state = no_state
self.precious = None
self.pseudo = False
self.noclean = 0
self.nocache = 0
self.cached = 0 # is this node pulled from cache?
self.always_build = None
self.includes = None
self.attributes = self.Attrs() # Generic place to stick information about the Node.
self.side_effect = 0 # true iff this node is a side effect
self.side_effects = [] # the side effects of building this target
self.linked = 0 # is this node linked to the variant directory?
self.clear_memoized_values()
# Let the interface in which the build engine is embedded
# annotate this Node with its own info (like a description of
# what line in what file created the node, for example).
Annotate(self)
def disambiguate(self, must_exist=None):
return self
def get_suffix(self):
return ''
memoizer_counters.append(SCons.Memoize.CountValue('get_build_env'))
def get_build_env(self):
"""Fetch the appropriate Environment to build this node.
"""
try:
return self._memo['get_build_env']
except KeyError:
pass
result = self.get_executor().get_build_env()
self._memo['get_build_env'] = result
return result
def get_build_scanner_path(self, scanner):
"""Fetch the appropriate scanner path for this node."""
return self.get_executor().get_build_scanner_path(scanner)
def set_executor(self, executor):
"""Set the action executor for this node."""
self.executor = executor
def get_executor(self, create=1):
"""Fetch the action executor for this node. Create one if
there isn't already one, and requested to do so."""
try:
executor = self.executor
except AttributeError:
if not create:
raise
try:
act = self.builder.action
except AttributeError:
executor = SCons.Executor.Null(targets=[self])
else:
executor = SCons.Executor.Executor(act,
self.env or self.builder.env,
[self.builder.overrides],
[self],
self.sources)
self.executor = executor
return executor
def executor_cleanup(self):
"""Let the executor clean up any cached information."""
try:
executor = self.get_executor(create=None)
except AttributeError:
pass
else:
if executor is not None:
executor.cleanup()
def reset_executor(self):
"Remove cached executor; forces recompute when needed."
try:
delattr(self, 'executor')
except AttributeError:
pass
def push_to_cache(self):
"""Try to push a node into a cache
"""
pass
def retrieve_from_cache(self):
"""Try to retrieve the node's content from a cache
This method is called from multiple threads in a parallel build,
so only do thread safe stuff here. Do thread unsafe stuff in
built().
Returns true if the node was successfully retrieved.
"""
return 0
#
# Taskmaster interface subsystem
#
def make_ready(self):
"""Get a Node ready for evaluation.
This is called before the Taskmaster decides if the Node is
up-to-date or not. Overriding this method allows for a Node
subclass to be disambiguated if necessary, or for an implicit
source builder to be attached.
"""
pass
def prepare(self):
"""Prepare for this Node to be built.
This is called after the Taskmaster has decided that the Node
is out-of-date and must be rebuilt, but before actually calling
the method to build the Node.
This default implementation checks that explicit or implicit
dependencies either exist or are derived, and initializes the
BuildInfo structure that will hold the information about how
this node is, uh, built.
(The existence of source files is checked separately by the
Executor, which aggregates checks for all of the targets built
by a specific action.)
Overriding this method allows for for a Node subclass to remove
the underlying file from the file system. Note that subclass
methods should call this base class method to get the child
check and the BuildInfo structure.
"""
if self.depends is not None:
for d in self.depends:
if d.missing():
msg = "Explicit dependency `%s' not found, needed by target `%s'."
raise SCons.Errors.StopError(msg % (d, self))
if self.implicit is not None:
for i in self.implicit:
if i.missing():
msg = "Implicit dependency `%s' not found, needed by target `%s'."
raise SCons.Errors.StopError(msg % (i, self))
self.binfo = self.get_binfo()
def build(self, **kw):
"""Actually build the node.
This is called by the Taskmaster after it's decided that the
Node is out-of-date and must be rebuilt, and after the prepare()
method has gotten everything, uh, prepared.
This method is called from multiple threads in a parallel build,
so only do thread safe stuff here. Do thread unsafe stuff
in built().
"""
try:
self.get_executor()(self, **kw)
except SCons.Errors.BuildError, e:
e.node = self
raise
def built(self):
"""Called just after this node is successfully built."""
# Clear the implicit dependency caches of any Nodes
# waiting for this Node to be built.
for parent in self.waiting_parents:
parent.implicit = None
self.clear()
if self.pseudo:
if self.exists():
raise SCons.Errors.UserError("Pseudo target " + str(self) + " must not exist")
else:
if not self.exists() and do_store_info:
SCons.Warnings.warn(SCons.Warnings.TargetNotBuiltWarning,
"Cannot find target " + str(self) + " after building")
self.ninfo.update(self)
def visited(self):
"""Called just after this node has been visited (with or
without a build)."""
try:
binfo = self.binfo
except AttributeError:
# Apparently this node doesn't need build info, so
# don't bother calculating or storing it.
pass
else:
self.ninfo.update(self)
self.store_info()
def release_target_info(self):
"""Called just after this node has been marked
up-to-date or was built completely.
This is where we try to release as many target node infos
as possible for clean builds and update runs, in order
to minimize the overall memory consumption.
By purging attributes that aren't needed any longer after
a Node (=File) got built, we don't have to care that much how
many KBytes a Node actually requires...as long as we free
the memory shortly afterwards.
@see: built() and File.release_target_info()
"""
pass
#
#
#
def add_to_waiting_s_e(self, node):
self.waiting_s_e.add(node)
def add_to_waiting_parents(self, node):
"""
Returns the number of nodes added to our waiting parents list:
1 if we add a unique waiting parent, 0 if not. (Note that the
returned values are intended to be used to increment a reference
count, so don't think you can "clean up" this function by using
True and False instead...)
"""
wp = self.waiting_parents
if node in wp:
return 0
wp.add(node)
return 1
def postprocess(self):
"""Clean up anything we don't need to hang onto after we've
been built."""
self.executor_cleanup()
self.waiting_parents = set()
def clear(self):
"""Completely clear a Node of all its cached state (so that it
can be re-evaluated by interfaces that do continuous integration
builds).
"""
# The del_binfo() call here isn't necessary for normal execution,
# but is for interactive mode, where we might rebuild the same
# target and need to start from scratch.
self.del_binfo()
self.clear_memoized_values()
self.ninfo = self.new_ninfo()
self.executor_cleanup()
try:
delattr(self, '_calculated_sig')
except AttributeError:
pass
self.includes = None
def clear_memoized_values(self):
self._memo = {}
def builder_set(self, builder):
self.builder = builder
try:
del self.executor
except AttributeError:
pass
def has_builder(self):
"""Return whether this Node has a builder or not.
In Boolean tests, this turns out to be a *lot* more efficient
than simply examining the builder attribute directly ("if
node.builder: ..."). When the builder attribute is examined
directly, it ends up calling __getattr__ for both the __len__
and __nonzero__ attributes on instances of our Builder Proxy
class(es), generating a bazillion extra calls and slowing
things down immensely.
"""
try:
b = self.builder
except AttributeError:
# There was no explicit builder for this Node, so initialize
# the self.builder attribute to None now.
b = self.builder = None
return b is not None
def set_explicit(self, is_explicit):
self.is_explicit = is_explicit
def has_explicit_builder(self):
"""Return whether this Node has an explicit builder
This allows an internal Builder created by SCons to be marked
non-explicit, so that it can be overridden by an explicit
builder that the user supplies (the canonical example being
directories)."""
try:
return self.is_explicit
except AttributeError:
self.is_explicit = None
return self.is_explicit
def get_builder(self, default_builder=None):
"""Return the set builder, or a specified default value"""
try:
return self.builder
except AttributeError:
return default_builder
multiple_side_effect_has_builder = has_builder
def is_derived(self):
"""
Returns true if this node is derived (i.e. built).
This should return true only for nodes whose path should be in
the variant directory when duplicate=0 and should contribute their build
signatures when they are used as source files to other derived files. For
example: source with source builders are not derived in this sense,
and hence should not return true.
"""
return self.has_builder() or self.side_effect
def alter_targets(self):
"""Return a list of alternate targets for this Node.
"""
return [], None
def get_found_includes(self, env, scanner, path):
"""Return the scanned include lines (implicit dependencies)
found in this node.
The default is no implicit dependencies. We expect this method
to be overridden by any subclass that can be scanned for
implicit dependencies.
"""
return []
def get_implicit_deps(self, env, scanner, path):
"""Return a list of implicit dependencies for this node.
This method exists to handle recursive invocation of the scanner
on the implicit dependencies returned by the scanner, if the
scanner's recursive flag says that we should.
"""
if not scanner:
return []
# Give the scanner a chance to select a more specific scanner
# for this Node.
#scanner = scanner.select(self)
nodes = [self]
seen = {}
seen[self] = 1
deps = []
while nodes:
n = nodes.pop(0)
d = [x for x in n.get_found_includes(env, scanner, path) if x not in seen]
if d:
deps.extend(d)
for n in d:
seen[n] = 1
nodes.extend(scanner.recurse_nodes(d))
return deps
def get_env_scanner(self, env, kw={}):
return env.get_scanner(self.scanner_key())
def get_target_scanner(self):
return self.builder.target_scanner
def get_source_scanner(self, node):
"""Fetch the source scanner for the specified node
NOTE: "self" is the target being built, "node" is
the source file for which we want to fetch the scanner.
Implies self.has_builder() is true; again, expect to only be
called from locations where this is already verified.
This function may be called very often; it attempts to cache
the scanner found to improve performance.
"""
scanner = None
try:
scanner = self.builder.source_scanner
except AttributeError:
pass
if not scanner:
# The builder didn't have an explicit scanner, so go look up
# a scanner from env['SCANNERS'] based on the node's scanner
# key (usually the file extension).
scanner = self.get_env_scanner(self.get_build_env())
if scanner:
scanner = scanner.select(node)
return scanner
def add_to_implicit(self, deps):
if not hasattr(self, 'implicit') or self.implicit is None:
self.implicit = []
self.implicit_set = set()
self._children_reset()
self._add_child(self.implicit, self.implicit_set, deps)
def scan(self):
"""Scan this node's dependents for implicit dependencies."""
# Don't bother scanning non-derived files, because we don't
# care what their dependencies are.
# Don't scan again, if we already have scanned.
if self.implicit is not None:
return
self.implicit = []
self.implicit_set = set()
self._children_reset()
if not self.has_builder():
return
build_env = self.get_build_env()
executor = self.get_executor()
# Here's where we implement --implicit-cache.
if implicit_cache and not implicit_deps_changed:
implicit = self.get_stored_implicit()
if implicit is not None:
# We now add the implicit dependencies returned from the
# stored .sconsign entry to have already been converted
# to Nodes for us. (We used to run them through a
# source_factory function here.)
# Update all of the targets with them. This
# essentially short-circuits an N*M scan of the
# sources for each individual target, which is a hell
# of a lot more efficient.
for tgt in executor.get_all_targets():
tgt.add_to_implicit(implicit)
if implicit_deps_unchanged or self.is_up_to_date():
return
# one of this node's sources has changed,
# so we must recalculate the implicit deps for all targets
for tgt in executor.get_all_targets():
tgt.implicit = []
tgt.implicit_set = set()
# Have the executor scan the sources.
executor.scan_sources(self.builder.source_scanner)
# If there's a target scanner, have the executor scan the target
# node itself and associated targets that might be built.
scanner = self.get_target_scanner()
if scanner:
executor.scan_targets(scanner)
def scanner_key(self):
return None
def select_scanner(self, scanner):
"""Selects a scanner for this Node.
This is a separate method so it can be overridden by Node
subclasses (specifically, Node.FS.Dir) that *must* use their
own Scanner and don't select one the Scanner.Selector that's
configured for the target.
"""
return scanner.select(self)
def env_set(self, env, safe=0):
if safe and self.env:
return
self.env = env
#
# SIGNATURE SUBSYSTEM
#
NodeInfo = NodeInfoBase
BuildInfo = BuildInfoBase
def new_ninfo(self):
ninfo = self.NodeInfo(self)
return ninfo
def get_ninfo(self):
try:
return self.ninfo
except AttributeError:
self.ninfo = self.new_ninfo()
return self.ninfo
def new_binfo(self):
binfo = self.BuildInfo(self)
return binfo
def get_binfo(self):
"""
Fetch a node's build information.
node - the node whose sources will be collected
cache - alternate node to use for the signature cache
returns - the build signature
This no longer handles the recursive descent of the
node's children's signatures. We expect that they're
already built and updated by someone else, if that's
what's wanted.
"""
try:
return self.binfo
except AttributeError:
pass
binfo = self.new_binfo()
self.binfo = binfo
executor = self.get_executor()
ignore_set = self.ignore_set
if self.has_builder():
binfo.bact = str(executor)
binfo.bactsig = SCons.Util.MD5signature(executor.get_contents())
if self._specific_sources:
sources = []
for s in self.sources:
if s not in ignore_set:
sources.append(s)
else:
sources = executor.get_unignored_sources(self, self.ignore)
seen = set()
bsources = []
bsourcesigs = []
for s in sources:
if not s in seen:
seen.add(s)
bsources.append(s)
bsourcesigs.append(s.get_ninfo())
binfo.bsources = bsources
binfo.bsourcesigs = bsourcesigs
depends = self.depends
dependsigs = []
for d in depends:
if d not in ignore_set:
dependsigs.append(d.get_ninfo())
binfo.bdepends = depends
binfo.bdependsigs = dependsigs
implicit = self.implicit or []
implicitsigs = []
for i in implicit:
if i not in ignore_set:
implicitsigs.append(i.get_ninfo())
binfo.bimplicit = implicit
binfo.bimplicitsigs = implicitsigs
return binfo
def del_binfo(self):
"""Delete the build info from this node."""
try:
delattr(self, 'binfo')
except AttributeError:
pass
def get_csig(self):
try:
return self.ninfo.csig
except AttributeError:
ninfo = self.get_ninfo()
ninfo.csig = SCons.Util.MD5signature(self.get_contents())
return self.ninfo.csig
def get_cachedir_csig(self):
return self.get_csig()
def store_info(self):
"""Make the build signature permanent (that is, store it in the
.sconsign file or equivalent)."""
pass
def do_not_store_info(self):
pass
def get_stored_info(self):
return None
def get_stored_implicit(self):
"""Fetch the stored implicit dependencies"""
return None
#
#
#
def set_precious(self, precious = 1):
"""Set the Node's precious value."""
self.precious = precious
def set_pseudo(self, pseudo = True):
"""Set the Node's precious value."""
self.pseudo = pseudo
def set_noclean(self, noclean = 1):
"""Set the Node's noclean value."""
# Make sure noclean is an integer so the --debug=stree
# output in Util.py can use it as an index.
self.noclean = noclean and 1 or 0
def set_nocache(self, nocache = 1):
"""Set the Node's nocache value."""
# Make sure nocache is an integer so the --debug=stree
# output in Util.py can use it as an index.
self.nocache = nocache and 1 or 0
def set_always_build(self, always_build = 1):
"""Set the Node's always_build value."""
self.always_build = always_build
def exists(self):
"""Does this node exists?"""
# All node exist by default:
return 1
def rexists(self):
"""Does this node exist locally or in a repositiory?"""
# There are no repositories by default:
return self.exists()
def missing(self):
return not self.is_derived() and \
not self.linked and \
not self.rexists()
def remove(self):
"""Remove this Node: no-op by default."""
return None
def add_dependency(self, depend):
"""Adds dependencies."""
try:
self._add_child(self.depends, self.depends_set, depend)
except TypeError, e:
e = e.args[0]
if SCons.Util.is_List(e):
s = list(map(str, e))
else:
s = str(e)
raise SCons.Errors.UserError("attempted to add a non-Node dependency to %s:\n\t%s is a %s, not a Node" % (str(self), s, type(e)))
def add_prerequisite(self, prerequisite):
"""Adds prerequisites"""
if self.prerequisites is None:
self.prerequisites = SCons.Util.UniqueList()
self.prerequisites.extend(prerequisite)
self._children_reset()
def add_ignore(self, depend):
"""Adds dependencies to ignore."""
try:
self._add_child(self.ignore, self.ignore_set, depend)
except TypeError, e:
e = e.args[0]
if SCons.Util.is_List(e):
s = list(map(str, e))
else:
s = str(e)
raise SCons.Errors.UserError("attempted to ignore a non-Node dependency of %s:\n\t%s is a %s, not a Node" % (str(self), s, type(e)))
def add_source(self, source):
"""Adds sources."""
if self._specific_sources:
return
try:
self._add_child(self.sources, self.sources_set, source)
except TypeError, e:
e = e.args[0]
if SCons.Util.is_List(e):
s = list(map(str, e))
else:
s = str(e)
raise SCons.Errors.UserError("attempted to add a non-Node as source of %s:\n\t%s is a %s, not a Node" % (str(self), s, type(e)))
def _add_child(self, collection, set, child):
"""Adds 'child' to 'collection', first checking 'set' to see if it's
already present."""
#if type(child) is not type([]):
# child = [child]
#for c in child:
# if not isinstance(c, Node):
# raise TypeError, c
added = None
for c in child:
if c not in set:
set.add(c)
collection.append(c)
added = 1
if added:
self._children_reset()
def set_specific_source(self, source):
self.add_source(source)
self._specific_sources = True
def add_wkid(self, wkid):
"""Add a node to the list of kids waiting to be evaluated"""
if self.wkids is not None:
self.wkids.append(wkid)
def _children_reset(self):
self.clear_memoized_values()
# We need to let the Executor clear out any calculated
# build info that it's cached so we can re-calculate it.
self.executor_cleanup()
memoizer_counters.append(SCons.Memoize.CountValue('_children_get'))
def _children_get(self):
try:
return self._memo['children_get']
except KeyError:
pass
# The return list may contain duplicate Nodes, especially in
# source trees where there are a lot of repeated #includes
# of a tangle of .h files. Profiling shows, however, that
# eliminating the duplicates with a brute-force approach that
# preserves the order (that is, something like:
#
# u = []
# for n in list:
# if n not in u:
# u.append(n)"
#
# takes more cycles than just letting the underlying methods
# hand back cached values if a Node's information is requested
# multiple times. (Other methods of removing duplicates, like
# using dictionary keys, lose the order, and the only ordered
# dictionary patterns I found all ended up using "not in"
# internally anyway...)
if self.ignore_set:
iter = chain.from_iterable(filter(None, [self.sources, self.depends, self.implicit]))
children = []
for i in iter:
if i not in self.ignore_set:
children.append(i)
else:
children = self.all_children(scan=0)
self._memo['children_get'] = children
return children
def all_children(self, scan=1):
"""Return a list of all the node's direct children."""
if scan:
self.scan()
# The return list may contain duplicate Nodes, especially in
# source trees where there are a lot of repeated #includes
# of a tangle of .h files. Profiling shows, however, that
# eliminating the duplicates with a brute-force approach that
# preserves the order (that is, something like:
#
# u = []
# for n in list:
# if n not in u:
# u.append(n)"
#
# takes more cycles than just letting the underlying methods
# hand back cached values if a Node's information is requested
# multiple times. (Other methods of removing duplicates, like
# using dictionary keys, lose the order, and the only ordered
# dictionary patterns I found all ended up using "not in"
# internally anyway...)
return list(chain.from_iterable(filter(None, [self.sources, self.depends, self.implicit])))
def children(self, scan=1):
"""Return a list of the node's direct children, minus those
that are ignored by this node."""
if scan:
self.scan()
return self._children_get()
def set_state(self, state):
self.state = state
def get_state(self):
return self.state
def state_has_changed(self, target, prev_ni):
return (self.state != SCons.Node.up_to_date)
def get_env(self):
env = self.env
if not env:
import SCons.Defaults
env = SCons.Defaults.DefaultEnvironment()
return env
def changed_since_last_build(self, target, prev_ni):
"""
Must be overridden in a specific subclass to return True if this
Node (a dependency) has changed since the last time it was used
to build the specified target. prev_ni is this Node's state (for
example, its file timestamp, length, maybe content signature)
as of the last time the target was built.
Note that this method is called through the dependency, not the
target, because a dependency Node must be able to use its own
logic to decide if it changed. For example, File Nodes need to
obey if we're configured to use timestamps, but Python Value Nodes
never use timestamps and always use the content. If this method
were called through the target, then each Node's implementation
of this method would have to have more complicated logic to
handle all the different Node types on which it might depend.
"""
raise NotImplementedError
def Decider(self, function):
SCons.Util.AddMethod(self, function, 'changed_since_last_build')
def changed(self, node=None, allowcache=False):
"""
Returns if the node is up-to-date with respect to the BuildInfo
stored last time it was built. The default behavior is to compare
it against our own previously stored BuildInfo, but the stored
BuildInfo from another Node (typically one in a Repository)
can be used instead.
Note that we now *always* check every dependency. We used to
short-circuit the check by returning as soon as we detected
any difference, but we now rely on checking every dependency
to make sure that any necessary Node information (for example,
the content signature of an #included .h file) is updated.
The allowcache option was added for supporting the early
release of the executor/builder structures, right after
a File target was built. When set to true, the return
value of this changed method gets cached for File nodes.
Like this, the executor isn't needed any longer for subsequent
calls to changed().
@see: FS.File.changed(), FS.File.release_target_info()
"""
t = 0
if t: Trace('changed(%s [%s], %s)' % (self, classname(self), node))
if node is None:
node = self
result = False
bi = node.get_stored_info().binfo
then = bi.bsourcesigs + bi.bdependsigs + bi.bimplicitsigs
children = self.children()
diff = len(children) - len(then)
if diff:
# The old and new dependency lists are different lengths.
# This always indicates that the Node must be rebuilt.
# We also extend the old dependency list with enough None
# entries to equal the new dependency list, for the benefit
# of the loop below that updates node information.
then.extend([None] * diff)
if t: Trace(': old %s new %s' % (len(then), len(children)))
result = True
for child, prev_ni in zip(children, then):
if child.changed_since_last_build(self, prev_ni):
if t: Trace(': %s changed' % child)
result = True
contents = self.get_executor().get_contents()
if self.has_builder():
import SCons.Util
newsig = SCons.Util.MD5signature(contents)
if bi.bactsig != newsig:
if t: Trace(': bactsig %s != newsig %s' % (bi.bactsig, newsig))
result = True
if not result:
if t: Trace(': up to date')
if t: Trace('\n')
return result
def is_up_to_date(self):
"""Default check for whether the Node is current: unknown Node
subtypes are always out of date, so they will always get built."""
return None
def children_are_up_to_date(self):
"""Alternate check for whether the Node is current: If all of
our children were up-to-date, then this Node was up-to-date, too.
The SCons.Node.Alias and SCons.Node.Python.Value subclasses
rebind their current() method to this method."""
# Allow the children to calculate their signatures.
self.binfo = self.get_binfo()
if self.always_build:
return None
state = 0
for kid in self.children(None):
s = kid.get_state()
if s and (not state or s > state):
state = s
return (state == 0 or state == SCons.Node.up_to_date)
def is_literal(self):
"""Always pass the string representation of a Node to
the command interpreter literally."""
return 1
def render_include_tree(self):
"""
Return a text representation, suitable for displaying to the
user, of the include tree for the sources of this node.
"""
if self.is_derived():
env = self.get_build_env()
if env:
for s in self.sources:
scanner = self.get_source_scanner(s)
if scanner:
path = self.get_build_scanner_path(scanner)
else:
path = None
def f(node, env=env, scanner=scanner, path=path):
return node.get_found_includes(env, scanner, path)
return SCons.Util.render_tree(s, f, 1)
else:
return None
def get_abspath(self):
"""
Return an absolute path to the Node. This will return simply
str(Node) by default, but for Node types that have a concept of
relative path, this might return something different.
"""
return str(self)
def for_signature(self):
"""
Return a string representation of the Node that will always
be the same for this particular Node, no matter what. This
is by contrast to the __str__() method, which might, for
instance, return a relative path for a file Node. The purpose
of this method is to generate a value to be used in signature
calculation for the command line used to build a target, and
we use this method instead of str() to avoid unnecessary
rebuilds. This method does not need to return something that
would actually work in a command line; it can return any kind of
nonsense, so long as it does not change.
"""
return str(self)
def get_string(self, for_signature):
"""This is a convenience function designed primarily to be
used in command generators (i.e., CommandGeneratorActions or
Environment variables that are callable), which are called
with a for_signature argument that is nonzero if the command
generator is being called to generate a signature for the
command line, which determines if we should rebuild or not.
Such command generators should use this method in preference
to str(Node) when converting a Node to a string, passing
in the for_signature parameter, such that we will call
Node.for_signature() or str(Node) properly, depending on whether
we are calculating a signature or actually constructing a
command line."""
if for_signature:
return self.for_signature()
return str(self)
def get_subst_proxy(self):
"""
This method is expected to return an object that will function
exactly like this Node, except that it implements any additional
special features that we would like to be in effect for
Environment variable substitution. The principle use is that
some Nodes would like to implement a __getattr__() method,
but putting that in the Node type itself has a tendency to kill
performance. We instead put it in a proxy and return it from
this method. It is legal for this method to return self
if no new functionality is needed for Environment substitution.
"""
return self
def explain(self):
if not self.exists():
return "building `%s' because it doesn't exist\n" % self
if self.always_build:
return "rebuilding `%s' because AlwaysBuild() is specified\n" % self
old = self.get_stored_info()
if old is None:
return None
old = old.binfo
old.prepare_dependencies()
try:
old_bkids = old.bsources + old.bdepends + old.bimplicit
old_bkidsigs = old.bsourcesigs + old.bdependsigs + old.bimplicitsigs
except AttributeError:
return "Cannot explain why `%s' is being rebuilt: No previous build information found\n" % self
new = self.get_binfo()
new_bkids = new.bsources + new.bdepends + new.bimplicit
new_bkidsigs = new.bsourcesigs + new.bdependsigs + new.bimplicitsigs
osig = dict(zip(old_bkids, old_bkidsigs))
nsig = dict(zip(new_bkids, new_bkidsigs))
# The sources and dependencies we'll want to report are all stored
# as relative paths to this target's directory, but we want to
# report them relative to the top-level SConstruct directory,
# so we only print them after running them through this lambda
# to turn them into the right relative Node and then return
# its string.
def stringify( s, E=self.dir.Entry ) :
if hasattr( s, 'dir' ) :
return str(E(s))
return str(s)
lines = []
removed = [x for x in old_bkids if not x in new_bkids]
if removed:
removed = list(map(stringify, removed))
fmt = "`%s' is no longer a dependency\n"
lines.extend([fmt % s for s in removed])
for k in new_bkids:
if not k in old_bkids:
lines.append("`%s' is a new dependency\n" % stringify(k))
elif k.changed_since_last_build(self, osig[k]):
lines.append("`%s' changed\n" % stringify(k))
if len(lines) == 0 and old_bkids != new_bkids:
lines.append("the dependency order changed:\n" +
"%sold: %s\n" % (' '*15, list(map(stringify, old_bkids))) +
"%snew: %s\n" % (' '*15, list(map(stringify, new_bkids))))
if len(lines) == 0:
def fmt_with_title(title, strlines):
lines = strlines.split('\n')
sep = '\n' + ' '*(15 + len(title))
return ' '*15 + title + sep.join(lines) + '\n'
if old.bactsig != new.bactsig:
if old.bact == new.bact:
lines.append("the contents of the build action changed\n" +
fmt_with_title('action: ', new.bact))
else:
lines.append("the build action changed:\n" +
fmt_with_title('old: ', old.bact) +
fmt_with_title('new: ', new.bact))
if len(lines) == 0:
return "rebuilding `%s' for unknown reasons\n" % self
preamble = "rebuilding `%s' because" % self
if len(lines) == 1:
return "%s %s" % (preamble, lines[0])
else:
lines = ["%s:\n" % preamble] + lines
return ( ' '*11).join(lines)
class NodeList(collections.UserList):
def __str__(self):
return str(list(map(str, self.data)))
def get_children(node, parent): return node.children()
def ignore_cycle(node, stack): pass
def do_nothing(node, parent): pass
class Walker(object):
"""An iterator for walking a Node tree.
This is depth-first, children are visited before the parent.
The Walker object can be initialized with any node, and
returns the next node on the descent with each get_next() call.
'kids_func' is an optional function that will be called to
get the children of a node instead of calling 'children'.
'cycle_func' is an optional function that will be called
when a cycle is detected.
This class does not get caught in node cycles caused, for example,
by C header file include loops.
"""
def __init__(self, node, kids_func=get_children,
cycle_func=ignore_cycle,
eval_func=do_nothing):
self.kids_func = kids_func
self.cycle_func = cycle_func
self.eval_func = eval_func
node.wkids = copy.copy(kids_func(node, None))
self.stack = [node]
self.history = {} # used to efficiently detect and avoid cycles
self.history[node] = None
def get_next(self):
"""Return the next node for this walk of the tree.
This function is intentionally iterative, not recursive,
to sidestep any issues of stack size limitations.
"""
while self.stack:
if self.stack[-1].wkids:
node = self.stack[-1].wkids.pop(0)
if not self.stack[-1].wkids:
self.stack[-1].wkids = None
if node in self.history:
self.cycle_func(node, self.stack)
else:
node.wkids = copy.copy(self.kids_func(node, self.stack[-1]))
self.stack.append(node)
self.history[node] = None
else:
node = self.stack.pop()
del self.history[node]
if node:
if self.stack:
parent = self.stack[-1]
else:
parent = None
self.eval_func(node, parent)
return node
return None
def is_done(self):
return not self.stack
arg2nodes_lookups = []
# Local Variables:
# tab-width:4
# indent-tabs-mode:nil
# End:
# vim: set expandtab tabstop=4 shiftwidth=4:
|
lgpl-2.1
|
[
624,
18521,
14,
1716,
199,
199,
1918,
5013,
2559,
367,
314,
8218,
2032,
14538,
11420,
14,
199,
199,
2765,
365,
12,
315,
5002,
15217,
12,
314,
946,
580,
402,
8218,
14,
199,
199,
33,
5013,
365,
2382,
781,
22667,
5434,
1006,
402,
314,
5936,
2556,
3595,
199,
1629,
8377,
626,
8218,
883,
1900,
12,
503,
3595,
1263,
8377,
1314,
8218,
883,
675,
199,
475,
1900,
2005,
1163,
8377,
14,
221,
710,
11358,
298,
2127,
4589,
402,
2518,
12,
365,
282,
570,
12,
199,
7911,
282,
5013,
883,
2597,
2954,
6020,
3982,
334,
2930,
282,
3330,
2034,
9,
503,
199,
10297,
14793,
9006,
334,
2930,
376,
24777,
680,
199,
199,
22321,
2488,
730,
402,
298,
2127,
2,
365,
22543,
11159,
701,
282,
5516,
199,
1618,
314,
5013,
1300,
1021,
26,
221,
5013,
14,
7079,
14,
1173,
367,
1584,
12,
5013,
14,
14149,
367,
5481,
12,
199,
6839,
14,
221,
22922,
2556,
365,
16204,
2348,
315,
314,
1300,
1021,
12,
436,
199,
11697,
2488,
370,
1584,
15,
8602,
15,
6839,
14,
365,
315,
314,
5516,
14,
221,
710,
199,
16117,
12,
340,
781,
9064,
4224,
642,
6657,
12,
365,
626,
1263,
730,
402,
298,
2127,
2,
1077,
199,
1235,
7688,
370,
11687,
641,
1263,
1163,
730,
402,
298,
2127,
2122,
199,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
12,
6029,
12,
6171,
12,
6927,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
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,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
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,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
1716,
22128,
826,
4343,
647,
221,
6927,
15,
1644,
15,
996,
4329,
26,
1085,
26,
1046,
486,
695,
79,
2,
199,
199,
646,
5055,
199,
646,
1331,
199,
504,
7975,
492,
6036,
199,
199,
646,
8218,
14,
7084,
199,
504,
8218,
14,
7084,
492,
943,
3244,
13921,
199,
646,
8218,
14,
16752,
199,
646,
8218,
14,
1352,
573,
794,
199,
646,
8218,
14,
9562,
199,
199,
504,
8218,
14,
7084,
492,
11680,
199,
199,
318,
15876,
8,
1113,
304,
272,
372,
620,
8,
1113,
855,
533,
28634,
1294,
29084,
17,
61,
199,
199,
3,
2494,
370,
3055,
340,
781,
3984,
9689,
282,
9951,
1255,
14,
6006,
1159,
1655,
2419,
1373,
402,
3520,
199,
3,
12050,
20991,
1956,
199,
1117,
63,
1617,
63,
815,
275,
715,
199,
199,
3,
5013,
6363,
199,
3,
199,
3,
5723,
787,
315,
298,
6693,
2,
1865,
12,
880,
626,
314,
5696,
574,
367,
1263,
199,
3,
1982,
15,
8575,
402,
282,
1031,
8469,
314,
1174,
402,
626,
1031,
340,
199,
3,
652,
965,
949,
6545,
402,
2399,
5705,
14,
221,
710,
11358,
2893,
365,
282,
570,
199,
3,
2656,
2082,
12,
1314,
365,
1454,
1536,
370,
1434,
340,
1006,
402,
2399,
4978,
199,
3,
4898,
1536,
370,
1434,
14,
199,
889,
63,
929,
275,
378,
199,
6455,
275,
413,
199,
23722,
275,
499,
199,
384,
63,
475,
63,
602,
275,
650,
199,
22564,
275,
841,
199,
4892,
275,
959,
199,
199,
2223,
1558,
275,
469,
272,
378,
520,
298,
889,
63,
929,
401,
272,
413,
520,
298,
6455,
401,
272,
499,
520,
298,
23722,
401,
272,
650,
520,
298,
384,
63,
475,
63,
602,
401,
272,
841,
520,
298,
22564,
401,
272,
959,
520,
298,
4892,
401,
199,
93,
199,
199,
3,
13467,
3775,
9227,
5124,
787,
6328,
26,
199,
11886,
63,
1637,
275,
378,
199,
199,
3,
13467,
3775,
9227,
2657,
4493,
787,
5525,
26,
199,
11886,
63,
5846,
63,
16914,
275,
378,
199,
199,
3,
13467,
3775,
314,
6328,
9227,
10140,
787,
5525,
26,
199,
11886,
63,
5846,
63,
2489,
275,
378,
199,
199,
3,
437,
1750,
626,
883,
506,
663,
370,
376,
3217,
13,
6100,
805,
506,
2797,
199,
3,
370,
28987,
282,
5013,
543,
2556,
3595,
2399,
7143,
14,
199,
318,
886,
63,
16323,
8,
932,
304,
986,
199,
199,
21761,
323,
275,
886,
63,
16323,
199,
199,
3,
14509,
663,
370,
283,
549,
7,
340,
781,
3984,
3879,
315,
12777,
818,
14,
6596,
199,
3,
5544,
1202,
370,
4683,
4184,
402,
282,
1347,
1159,
2256,
5309,
199,
3,
3633,
14723,
436,
1678,
7858,
334,
3239,
4683,
63,
1375,
63,
815,
680,
199,
13543,
275,
756,
199,
199,
3,
27939,
367,
4955,
2256,
367,
23836,
14,
199,
199,
533,
5013,
2354,
1563,
8,
785,
304,
272,
408,
272,
710,
7809,
1300,
1021,
367,
4955,
2556,
367,
282,
5013,
14,
339,
5013,
9180,
1077,
5516,
5013,
2354,
1563,
370,
5647,
3932,
5705,
272,
9661,
367,
23654,
543,
3932,
5705,
5013,
13,
6100,
4955,
2556,
14,
272,
408,
272,
1453,
63,
1023,
63,
344,
275,
413,
272,
347,
636,
826,
721,
277,
12,
1031,
29,
403,
304,
267,
327,
2790,
376,
909,
2225,
687,
314,
1021,
2225,
880,
652,
11187,
1536,
267,
327
] |
[
18521,
14,
1716,
199,
199,
1918,
5013,
2559,
367,
314,
8218,
2032,
14538,
11420,
14,
199,
199,
2765,
365,
12,
315,
5002,
15217,
12,
314,
946,
580,
402,
8218,
14,
199,
199,
33,
5013,
365,
2382,
781,
22667,
5434,
1006,
402,
314,
5936,
2556,
3595,
199,
1629,
8377,
626,
8218,
883,
1900,
12,
503,
3595,
1263,
8377,
1314,
8218,
883,
675,
199,
475,
1900,
2005,
1163,
8377,
14,
221,
710,
11358,
298,
2127,
4589,
402,
2518,
12,
365,
282,
570,
12,
199,
7911,
282,
5013,
883,
2597,
2954,
6020,
3982,
334,
2930,
282,
3330,
2034,
9,
503,
199,
10297,
14793,
9006,
334,
2930,
376,
24777,
680,
199,
199,
22321,
2488,
730,
402,
298,
2127,
2,
365,
22543,
11159,
701,
282,
5516,
199,
1618,
314,
5013,
1300,
1021,
26,
221,
5013,
14,
7079,
14,
1173,
367,
1584,
12,
5013,
14,
14149,
367,
5481,
12,
199,
6839,
14,
221,
22922,
2556,
365,
16204,
2348,
315,
314,
1300,
1021,
12,
436,
199,
11697,
2488,
370,
1584,
15,
8602,
15,
6839,
14,
365,
315,
314,
5516,
14,
221,
710,
199,
16117,
12,
340,
781,
9064,
4224,
642,
6657,
12,
365,
626,
1263,
730,
402,
298,
2127,
2,
1077,
199,
1235,
7688,
370,
11687,
641,
1263,
1163,
730,
402,
298,
2127,
2122,
199,
199,
624,
199,
199,
3,
199,
3,
1898,
334,
67,
9,
12521,
12,
14790,
12,
13004,
12,
8353,
12,
11811,
12,
8315,
12,
10219,
12,
9079,
12,
8937,
12,
7129,
12,
7760,
12,
6029,
12,
6171,
12,
6927,
710,
8218,
2752,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
199,
3,
282,
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,
199,
3,
11207,
12,
13473,
12,
436,
15,
269,
12743,
6866,
402,
314,
2290,
12,
436,
370,
199,
3,
11291,
12103,
370,
12676,
314,
2290,
365,
13985,
370,
886,
880,
12,
5420,
370,
199,
3,
314,
2569,
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,
199,
3,
3826,
12,
7168,
1549,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
199,
3,
2990,
1634,
3169,
12,
3092,
2381,
437,
3115,
3104,
2401,
199,
3,
13229,
14,
1621,
4825,
6461,
7000,
2334,
10610,
1549,
5877,
8164,
6262,
199,
3,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
5603,
12,
7061,
1621,
1261,
9612,
199,
3,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
5738,
1634,
1549,
1621,
11287,
199,
3,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
4141,
14,
199,
199,
363,
5792,
363,
275,
298,
2164,
15,
3908,
15,
18521,
15,
1716,
22128,
826,
4343,
647,
221,
6927,
15,
1644,
15,
996,
4329,
26,
1085,
26,
1046,
486,
695,
79,
2,
199,
199,
646,
5055,
199,
646,
1331,
199,
504,
7975,
492,
6036,
199,
199,
646,
8218,
14,
7084,
199,
504,
8218,
14,
7084,
492,
943,
3244,
13921,
199,
646,
8218,
14,
16752,
199,
646,
8218,
14,
1352,
573,
794,
199,
646,
8218,
14,
9562,
199,
199,
504,
8218,
14,
7084,
492,
11680,
199,
199,
318,
15876,
8,
1113,
304,
272,
372,
620,
8,
1113,
855,
533,
28634,
1294,
29084,
17,
61,
199,
199,
3,
2494,
370,
3055,
340,
781,
3984,
9689,
282,
9951,
1255,
14,
6006,
1159,
1655,
2419,
1373,
402,
3520,
199,
3,
12050,
20991,
1956,
199,
1117,
63,
1617,
63,
815,
275,
715,
199,
199,
3,
5013,
6363,
199,
3,
199,
3,
5723,
787,
315,
298,
6693,
2,
1865,
12,
880,
626,
314,
5696,
574,
367,
1263,
199,
3,
1982,
15,
8575,
402,
282,
1031,
8469,
314,
1174,
402,
626,
1031,
340,
199,
3,
652,
965,
949,
6545,
402,
2399,
5705,
14,
221,
710,
11358,
2893,
365,
282,
570,
199,
3,
2656,
2082,
12,
1314,
365,
1454,
1536,
370,
1434,
340,
1006,
402,
2399,
4978,
199,
3,
4898,
1536,
370,
1434,
14,
199,
889,
63,
929,
275,
378,
199,
6455,
275,
413,
199,
23722,
275,
499,
199,
384,
63,
475,
63,
602,
275,
650,
199,
22564,
275,
841,
199,
4892,
275,
959,
199,
199,
2223,
1558,
275,
469,
272,
378,
520,
298,
889,
63,
929,
401,
272,
413,
520,
298,
6455,
401,
272,
499,
520,
298,
23722,
401,
272,
650,
520,
298,
384,
63,
475,
63,
602,
401,
272,
841,
520,
298,
22564,
401,
272,
959,
520,
298,
4892,
401,
199,
93,
199,
199,
3,
13467,
3775,
9227,
5124,
787,
6328,
26,
199,
11886,
63,
1637,
275,
378,
199,
199,
3,
13467,
3775,
9227,
2657,
4493,
787,
5525,
26,
199,
11886,
63,
5846,
63,
16914,
275,
378,
199,
199,
3,
13467,
3775,
314,
6328,
9227,
10140,
787,
5525,
26,
199,
11886,
63,
5846,
63,
2489,
275,
378,
199,
199,
3,
437,
1750,
626,
883,
506,
663,
370,
376,
3217,
13,
6100,
805,
506,
2797,
199,
3,
370,
28987,
282,
5013,
543,
2556,
3595,
2399,
7143,
14,
199,
318,
886,
63,
16323,
8,
932,
304,
986,
199,
199,
21761,
323,
275,
886,
63,
16323,
199,
199,
3,
14509,
663,
370,
283,
549,
7,
340,
781,
3984,
3879,
315,
12777,
818,
14,
6596,
199,
3,
5544,
1202,
370,
4683,
4184,
402,
282,
1347,
1159,
2256,
5309,
199,
3,
3633,
14723,
436,
1678,
7858,
334,
3239,
4683,
63,
1375,
63,
815,
680,
199,
13543,
275,
756,
199,
199,
3,
27939,
367,
4955,
2256,
367,
23836,
14,
199,
199,
533,
5013,
2354,
1563,
8,
785,
304,
272,
408,
272,
710,
7809,
1300,
1021,
367,
4955,
2556,
367,
282,
5013,
14,
339,
5013,
9180,
1077,
5516,
5013,
2354,
1563,
370,
5647,
3932,
5705,
272,
9661,
367,
23654,
543,
3932,
5705,
5013,
13,
6100,
4955,
2556,
14,
272,
408,
272,
1453,
63,
1023,
63,
344,
275,
413,
272,
347,
636,
826,
721,
277,
12,
1031,
29,
403,
304,
267,
327,
2790,
376,
909,
2225,
687,
314,
1021,
2225,
880,
652,
11187,
1536,
267,
327,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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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
] |
kamyu104/LeetCode
|
Python/shortest-completing-word.py
|
2
|
2247
|
# Time: O(n)
# Space: O(1)
# Find the minimum length word from a given dictionary words,
# which has all the letters from the string licensePlate.
# Such a word is said to complete the given string licensePlate
#
# Here, for letters we ignore case.
# For example, "P" on the licensePlate still matches "p" on the word.
#
# It is guaranteed an answer exists.
# If there are multiple answers, return the one that occurs first in the array.
#
# The license plate might have the same letter occurring multiple times.
# For example, given a licensePlate of "PP",
# the word "pair" does not complete the licensePlate, but the word "supper" does.
#
# Example 1:
# Input: licensePlate = "1s3 PSt", words = ["step", "steps", "stripe", "stepple"]
# Output: "steps"
# Explanation: The smallest length word that contains the letters "S", "P", "S", and "T".
# Note that the answer is not "step", because the letter "s" must occur in the word twice.
# Also note that we ignored case for the purposes of comparing whether a letter exists in the word.
# Example 2:
# Input: licensePlate = "1s3 456", words = ["looks", "pest", "stew", "show"]
# Output: "pest"
# Explanation: There are 3 smallest length words that contains the letters "s".
# We return the one that occurred first.
# Note:
# - licensePlate will be a string with length in range [1, 7].
# - licensePlate will contain digits, spaces, or letters (uppercase or lowercase).
# - words will have a length in the range [10, 1000].
# - Every words[i] will consist of lowercase letters, and have length in range [1, 15].
import collections
class Solution(object):
def shortestCompletingWord(self, licensePlate, words):
"""
:type licensePlate: str
:type words: List[str]
:rtype: str
"""
def contains(counter1, w2):
c2 = collections.Counter(w2.lower())
c2.subtract(counter1)
return all(map(lambda x: x >= 0, c2.values()))
result = None
counter = collections.Counter(c.lower() for c in licensePlate if c.isalpha())
for word in words:
if (result is None or (len(word) < len(result))) and \
contains(counter, word):
result = word
return result
|
mit
|
[
3,
4703,
26,
221,
593,
8,
78,
9,
199,
3,
19326,
26,
593,
8,
17,
9,
199,
199,
3,
6668,
314,
7481,
2582,
4349,
687,
282,
1627,
2600,
5932,
12,
199,
3,
1314,
965,
1006,
314,
14435,
687,
314,
1059,
4190,
29020,
14,
199,
3,
32753,
282,
4349,
365,
25097,
370,
4890,
314,
1627,
1059,
4190,
29020,
199,
3,
199,
3,
11842,
12,
367,
14435,
781,
3686,
1930,
14,
199,
3,
2104,
2893,
12,
298,
48,
2,
641,
314,
4190,
29020,
5139,
4450,
298,
80,
2,
641,
314,
4349,
14,
199,
3,
199,
3,
2779,
365,
17334,
376,
6385,
3495,
14,
199,
3,
982,
2337,
787,
3663,
17133,
12,
372,
314,
1373,
626,
11058,
1642,
315,
314,
1625,
14,
199,
3,
199,
3,
710,
4190,
299,
750,
5594,
1172,
314,
2011,
8082,
4781,
5985,
3663,
5431,
14,
199,
3,
2104,
2893,
12,
1627,
282,
4190,
29020,
402,
298,
7701,
401,
199,
3,
314,
4349,
298,
3852,
2,
1630,
440,
4890,
314,
4190,
29020,
12,
1325,
314,
4349,
298,
1961,
529,
2,
1630,
14,
199,
3,
199,
3,
5679,
413,
26,
199,
3,
6924,
26,
4190,
29020,
275,
298,
17,
83,
19,
510,
933,
401,
5932,
275,
2097,
2926,
401,
298,
5895,
401,
298,
19025,
401,
298,
1597,
802,
274,
937,
199,
3,
7242,
26,
298,
5895,
2,
199,
3,
1316,
10304,
26,
710,
18604,
2582,
4349,
626,
3509,
314,
14435,
298,
51,
401,
298,
48,
401,
298,
51,
401,
436,
298,
52,
1674,
199,
3,
3390,
626,
314,
6385,
365,
440,
298,
2926,
401,
2952,
314,
8082,
298,
83,
2,
1471,
4781,
315,
314,
4349,
13373,
14,
199,
3,
6121,
5317,
626,
781,
5525,
1930,
367,
314,
12901,
402,
20234,
3775,
282,
8082,
3495,
315,
314,
4349,
14,
199,
3,
5679,
499,
26,
199,
3,
6924,
26,
4190,
29020,
275,
298,
17,
83,
19,
31944,
401,
5932,
275,
2097,
11660,
83,
401,
298,
321,
270,
401,
298,
1597,
87,
401,
298,
2384,
937,
199,
3,
7242,
26,
298,
321,
270,
2,
199,
3,
1316,
10304,
26,
6006,
787,
650,
18604,
2582,
5932,
626,
3509,
314,
14435,
298,
83,
1674,
199,
3,
2136,
372,
314,
1373,
626,
8920,
1642,
14,
199,
3,
3390,
26,
199,
3,
446,
4190,
29020,
911,
506,
282,
1059,
543,
2582,
315,
1425,
359,
17,
12,
1520,
1055,
199,
3,
446,
4190,
29020,
911,
1395,
7576,
12,
7883,
12,
503,
14435,
334,
26831,
503,
12141,
680,
199,
3,
446,
5932,
911,
1172,
282,
2582,
315,
314,
1425,
359,
709,
12,
5198,
1055,
199,
3,
446,
18414,
5932,
59,
73,
61,
911,
17568,
402,
12141,
14435,
12,
436,
1172,
2582,
315,
1425,
359,
17,
12,
4114,
1055,
199,
199,
646,
5055,
421,
199,
533,
9274,
8,
785,
304,
272,
347,
26564,
6600,
1337,
10155,
8,
277,
12,
4190,
29020,
12,
5932,
304,
267,
408,
267,
520,
466,
4190,
29020,
26,
620,
267,
520,
466,
5932,
26,
3820,
59,
495,
61,
267,
520,
4500,
26,
620,
267,
408,
267,
347,
3509,
8,
5337,
17,
12,
336,
18,
304,
288,
286,
18,
275,
5055,
14,
11348,
8,
87,
18,
14,
2325,
1012,
288,
286,
18,
14,
25719,
8,
5337,
17,
9,
288,
372,
1006,
8,
1130,
8,
2734,
671,
26,
671,
2356,
378,
12,
286,
18,
14,
1459,
4059,
398,
754,
275,
488,
267,
7055,
275,
5055,
14,
11348,
8,
67,
14,
2325,
342,
367,
286,
315,
4190,
29020,
340,
286,
14,
374,
4468,
1012,
267,
367,
4349,
315,
5932,
26,
288,
340,
334,
1099,
365,
488,
503,
334,
552,
8,
1027,
9,
665,
822,
8,
1099,
1724,
436,
971,
2049,
3509,
8,
5337,
12,
4349,
304,
355,
754,
275,
4349,
267,
372,
754,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
4703,
26,
221,
593,
8,
78,
9,
199,
3,
19326,
26,
593,
8,
17,
9,
199,
199,
3,
6668,
314,
7481,
2582,
4349,
687,
282,
1627,
2600,
5932,
12,
199,
3,
1314,
965,
1006,
314,
14435,
687,
314,
1059,
4190,
29020,
14,
199,
3,
32753,
282,
4349,
365,
25097,
370,
4890,
314,
1627,
1059,
4190,
29020,
199,
3,
199,
3,
11842,
12,
367,
14435,
781,
3686,
1930,
14,
199,
3,
2104,
2893,
12,
298,
48,
2,
641,
314,
4190,
29020,
5139,
4450,
298,
80,
2,
641,
314,
4349,
14,
199,
3,
199,
3,
2779,
365,
17334,
376,
6385,
3495,
14,
199,
3,
982,
2337,
787,
3663,
17133,
12,
372,
314,
1373,
626,
11058,
1642,
315,
314,
1625,
14,
199,
3,
199,
3,
710,
4190,
299,
750,
5594,
1172,
314,
2011,
8082,
4781,
5985,
3663,
5431,
14,
199,
3,
2104,
2893,
12,
1627,
282,
4190,
29020,
402,
298,
7701,
401,
199,
3,
314,
4349,
298,
3852,
2,
1630,
440,
4890,
314,
4190,
29020,
12,
1325,
314,
4349,
298,
1961,
529,
2,
1630,
14,
199,
3,
199,
3,
5679,
413,
26,
199,
3,
6924,
26,
4190,
29020,
275,
298,
17,
83,
19,
510,
933,
401,
5932,
275,
2097,
2926,
401,
298,
5895,
401,
298,
19025,
401,
298,
1597,
802,
274,
937,
199,
3,
7242,
26,
298,
5895,
2,
199,
3,
1316,
10304,
26,
710,
18604,
2582,
4349,
626,
3509,
314,
14435,
298,
51,
401,
298,
48,
401,
298,
51,
401,
436,
298,
52,
1674,
199,
3,
3390,
626,
314,
6385,
365,
440,
298,
2926,
401,
2952,
314,
8082,
298,
83,
2,
1471,
4781,
315,
314,
4349,
13373,
14,
199,
3,
6121,
5317,
626,
781,
5525,
1930,
367,
314,
12901,
402,
20234,
3775,
282,
8082,
3495,
315,
314,
4349,
14,
199,
3,
5679,
499,
26,
199,
3,
6924,
26,
4190,
29020,
275,
298,
17,
83,
19,
31944,
401,
5932,
275,
2097,
11660,
83,
401,
298,
321,
270,
401,
298,
1597,
87,
401,
298,
2384,
937,
199,
3,
7242,
26,
298,
321,
270,
2,
199,
3,
1316,
10304,
26,
6006,
787,
650,
18604,
2582,
5932,
626,
3509,
314,
14435,
298,
83,
1674,
199,
3,
2136,
372,
314,
1373,
626,
8920,
1642,
14,
199,
3,
3390,
26,
199,
3,
446,
4190,
29020,
911,
506,
282,
1059,
543,
2582,
315,
1425,
359,
17,
12,
1520,
1055,
199,
3,
446,
4190,
29020,
911,
1395,
7576,
12,
7883,
12,
503,
14435,
334,
26831,
503,
12141,
680,
199,
3,
446,
5932,
911,
1172,
282,
2582,
315,
314,
1425,
359,
709,
12,
5198,
1055,
199,
3,
446,
18414,
5932,
59,
73,
61,
911,
17568,
402,
12141,
14435,
12,
436,
1172,
2582,
315,
1425,
359,
17,
12,
4114,
1055,
199,
199,
646,
5055,
421,
199,
533,
9274,
8,
785,
304,
272,
347,
26564,
6600,
1337,
10155,
8,
277,
12,
4190,
29020,
12,
5932,
304,
267,
408,
267,
520,
466,
4190,
29020,
26,
620,
267,
520,
466,
5932,
26,
3820,
59,
495,
61,
267,
520,
4500,
26,
620,
267,
408,
267,
347,
3509,
8,
5337,
17,
12,
336,
18,
304,
288,
286,
18,
275,
5055,
14,
11348,
8,
87,
18,
14,
2325,
1012,
288,
286,
18,
14,
25719,
8,
5337,
17,
9,
288,
372,
1006,
8,
1130,
8,
2734,
671,
26,
671,
2356,
378,
12,
286,
18,
14,
1459,
4059,
398,
754,
275,
488,
267,
7055,
275,
5055,
14,
11348,
8,
67,
14,
2325,
342,
367,
286,
315,
4190,
29020,
340,
286,
14,
374,
4468,
1012,
267,
367,
4349,
315,
5932,
26,
288,
340,
334,
1099,
365,
488,
503,
334,
552,
8,
1027,
9,
665,
822,
8,
1099,
1724,
436,
971,
2049,
3509,
8,
5337,
12,
4349,
304,
355,
754,
275,
4349,
267,
372,
754,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jwoeifjoei/bot01
|
src/main.py
|
1
|
6502
|
# -*- coding: utf-8 -*-
# Copyright (c) 2016-2017 Marco Aceti <dev@marcoaceti.it>
#
# 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 json
import botogram
import botogram.objects.base
from mysql.connector import (connection)
import config
from .objects.callback import Callback
from .objects.user import User
from .updates import callback, messages
import re
def disconnectmysql(cursor,cnx):
emp_no = cursor.lastrowid
cnx.commit()
cursor.close()
cnx.close()
def connectmysql():
cnx = connection.MySQLConnection(user=config.usermariadb,
password=config.passwordmariadb,
host=config.hostmariadb,
database=config.databasemariadb)
cursor=cnx.cursor()
return cursor, cnx
class CallbackQuery(botogram.objects.base.BaseObject):
def __init__(self, update):
super().__init__(update)
required = {
"id": str,
"from": botogram.User,
"data": str,
}
optional = {
"inline_message_id": str,
"message": botogram.Message,
}
replace_keys = {
"from": "sender"
}
botogram.Update.optional["callback_query"] = CallbackQuery
bot = botogram.create(config.BOT_TOKEN)
@bot.command("start")
def start(chat, message):
u = User(message.sender)
u.state("home")
u.increaseStat('stats_command_start')
sender = message.sender
cursor, cnx = connectmysql()
cursor.execute("SELECT id_utentetg FROM info_utente WHERE id_utentetg='"+str(sender.id)+"'")
idsender=' '
for row in cursor.fetchall():
idsender=row[0]
if (str(sender.id)==str(idsender)):
_message="Ti sei già iscritto a questo bot, premi un tasto per continuare."
elif(idsender==' '):
cursor.execute('SELECT MAX(id_utente) FROM info_utente')
for row in cursor.fetchall():
idtelegram=1+int(row[0])
dati=(str(sender.id),str(idtelegram))
cursor.execute("INSERT INTO info_utente (id_utentetg,id_utente,posizione) VALUES (%s,%s,'0');",dati)
text_messagelog="#Avvio \nUtente: "+str(sender.name)+"\nUsername: @"+str(sender.username)+"\nId: "+str(sender.id)+"\nUserTag: #User"+str(sender.id)
querry="SELECT idchattg FROM chatsend WHERE tipo=0"
cursor.execute(querry)
for row in cursor.fetchall():
bot.chat(row[0]).send(text_messagelog,syntax="HTML")
else:
text_message="Errore Generale"
if(str(chat.type)!="private"):
text_message="Avviami in chat privata\n"+text_message
bot.api.call('sendMessage', {
'chat_id': chat.id, 'text': text_message, 'parse_mode': 'HTML', 'reply_markup':
json.dumps(
{'inline_keyboard': [
[{"text": "Avviami in privata", "url": "t.me/TorrentItaliaBot"}]
]}
)
})
else:
querry="SELECT ruolo FROM info_utente WHERE id_utentetg='"+str(u.id)+"'"
cursor.execute(querry)
for row in cursor.fetchall():
ruolo=int(row[0])
if(ruolo==1 or ruolo==2):
u.state("home-admin")
text = (
"bot del gruppo https://t.me/Utorrentitalia ancora in costruzione "
)
message =bot.api.call("sendMessage", {
"chat_id": chat.id, "text": text,
"parse_mode": "HTML", "reply_markup":
json.dumps(
{'inline_keyboard': [
[{"text": "help", "callback_data": "help"},
{"text":"gestione","callback_data":"gestione"}],
[{"text": "richiesta", "callback_data": "richiesta"},
{"text": "ℹ️ Altre informazioni", "callback_data": "info"}]
]}
)
})
print(message["result"]["message_id"])
else:
u.state("home")
text = (
"bot del gruppo https://t.me/Utorrentitalia ancora in costruzione "
)
message=bot.api.call("sendMessage", {
"chat_id": chat.id, "text": text,
"parse_mode": "HTML", "reply_markup":
json.dumps(
{'inline_keyboard': [
[{"text": "help", "callback_data": "help"},
{"text": "richiesta", "callback_data": "richiesta"}],
[{"text": "ℹ️ Altre informazioni", "callback_data": "info"}]
]}
)
})
print(message["result"]["message_id"])
disconnectmysql(cursor,cnx)
@bot.command("sendall")
def sendall_command(chat,message,args):
cursor, cnx = connectmysql()
sender = message.sender
if(str(sender.id)==str('28746630')):
querry="SELECT id_utentetg FROM info_utente"
cursor.execute(querry)
for row in cursor.fetchall():
bot.chat(row[0]).send(str(message.text)[9:],syntax="HTML")
@bot.process_message
def process_messages(message):
u = User(message.sender)
sender=message.sender
messages.process_messages(bot, message, u, sender)
def process_callback(__bot, __chains, update):
del (__bot, __chains) # Useless arguments from botogram
cb = Callback(update)
u = User(cb.sender)
u.increaseStat('stats_callback_count')
callback.process_callback(bot, update, u)
bot.register_update_processor("callback_query", process_callback)
|
mit
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
67,
9,
7800,
13,
10680,
16794,
331,
437,
301,
280,
665,
2374,
32,
4584,
331,
7984,
280,
14,
390,
30,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
646,
2022,
199,
646,
6055,
1679,
199,
646,
6055,
1679,
14,
1462,
14,
1095,
199,
504,
12896,
14,
11815,
492,
334,
2105,
9,
199,
646,
1101,
199,
504,
1275,
1462,
14,
3058,
492,
17555,
199,
504,
1275,
1462,
14,
751,
492,
2876,
199,
504,
1275,
7618,
492,
3233,
12,
3788,
199,
646,
295,
199,
199,
318,
17639,
8644,
8,
3937,
12,
6413,
88,
304,
272,
9052,
63,
889,
275,
3920,
14,
2019,
29450,
272,
286,
7343,
14,
3543,
342,
272,
3920,
14,
1600,
342,
272,
286,
7343,
14,
1600,
342,
199,
199,
318,
4907,
8644,
837,
272,
286,
7343,
275,
1950,
14,
20784,
3225,
8,
751,
29,
888,
14,
751,
77,
759,
13741,
12,
3303,
2505,
29,
888,
14,
2060,
77,
759,
13741,
12,
3303,
1591,
29,
888,
14,
1102,
77,
759,
13741,
12,
3303,
3050,
29,
888,
14,
4659,
77,
759,
13741,
9,
272,
3920,
29,
6413,
88,
14,
3937,
342,
272,
372,
3920,
12,
286,
7343,
199,
199,
533,
17555,
3227,
8,
10914,
1679,
14,
1462,
14,
1095,
14,
1563,
1692,
304,
272,
347,
636,
826,
721,
277,
12,
1678,
304,
267,
1613,
11027,
826,
721,
873,
9,
339,
1415,
275,
469,
267,
298,
344,
582,
620,
12,
267,
298,
504,
582,
6055,
1679,
14,
1899,
12,
267,
298,
576,
582,
620,
12,
272,
789,
272,
2716,
275,
469,
267,
298,
6460,
63,
1188,
63,
344,
582,
620,
12,
267,
298,
1188,
582,
6055,
1679,
14,
2209,
12,
272,
789,
272,
3350,
63,
1612,
275,
469,
267,
298,
504,
582,
298,
8114,
2,
272,
789,
199,
199,
10914,
1679,
14,
4152,
14,
4144,
905,
3058,
63,
1131,
937,
275,
17555,
3227,
199,
199,
3018,
275,
6055,
1679,
14,
981,
8,
888,
14,
11372,
63,
8803,
9,
421,
199,
32,
3018,
14,
1531,
480,
928,
531,
199,
318,
1343,
8,
10289,
12,
1245,
304,
272,
399,
275,
2876,
8,
1188,
14,
8114,
9,
272,
399,
14,
929,
480,
4219,
531,
272,
399,
14,
31687,
11232,
360,
3200,
63,
1531,
63,
928,
358,
272,
8904,
275,
1245,
14,
8114,
272,
3920,
12,
286,
7343,
275,
4907,
8644,
342,
272,
3920,
14,
2526,
480,
4859,
1305,
63,
85,
724,
10288,
71,
4442,
2256,
63,
85,
724,
266,
6038,
1305,
63,
85,
724,
10288,
71,
534,
7709,
495,
8,
8114,
14,
344,
6393,
4507,
531,
272,
1305,
8114,
534,
283,
272,
367,
1962,
315,
3920,
14,
10174,
837,
267,
1305,
8114,
29,
1143,
59,
16,
61,
272,
340,
334,
495,
8,
8114,
14,
344,
12694,
495,
8,
344,
8114,
2298,
267,
485,
1188,
628,
22731,
542,
73,
18895,
26482,
365,
29506,
475,
282,
221,
613,
79,
5888,
12,
876,
2664,
625,
307,
1810,
79,
1126,
9832,
1458,
264,
2122,
272,
916,
8,
344,
8114,
6803,
18927,
267,
3920,
14,
2526,
360,
4859,
9141,
8,
344,
63,
85,
724,
266,
9,
4442,
2256,
63,
85,
724,
266,
358,
267,
367,
1962,
315,
3920,
14,
10174,
837,
288,
1305,
15253,
1679,
29,
17,
11,
442,
8,
1143,
59,
16,
566,
267,
366,
2159,
2687,
495,
8,
8114,
14,
344,
395,
495,
8,
344,
15253,
1679,
430,
267,
3920,
14,
2526,
480,
10258,
12872,
2256,
63,
85,
724,
266,
334,
344,
63,
85,
724,
10288,
71,
12,
344,
63,
85,
724,
266,
12,
555,
5946,
26277,
9,
13992,
4366,
83,
8719,
83,
2584,
16,
11339,
401,
983,
280,
9,
398,
1318,
63,
1188,
793,
13476,
6651,
32052,
971,
78,
53,
724,
266,
26,
7210,
495,
8,
8114,
14,
354,
6393,
3212,
78,
13355,
26,
768,
7709,
495,
8,
8114,
14,
2473,
6393,
3212,
78,
1304,
26,
7210,
495,
8,
8114,
14,
344,
6393,
3212,
78,
1899,
1931,
26,
327,
1899,
7709,
495,
8,
8114,
14,
344,
9,
398,
26923,
651,
628,
4859,
1305,
335,
6796,
71,
4442,
21472,
2254,
6038,
3367,
555,
29,
16,
2,
267,
3920,
14,
2526,
8,
16891,
651,
9,
267,
367,
1962,
315,
3920,
14,
10174,
837,
288,
5888,
14,
10289,
8,
1143,
59,
16,
6575,
2254,
8,
505,
63,
1188,
793,
12,
7093,
628,
4943,
531,
339,
587,
26,
267,
1318,
63,
1188,
628,
539,
293,
264,
1464,
1895,
2,
272,
340,
8,
495,
8,
10289,
14,
466,
9,
1,
628,
4239,
2349,
267,
1318,
63,
1188,
628,
6651,
433,
13496,
315,
21472,
16254,
419,
60,
78,
7709,
505,
63,
1188,
267,
5888,
14,
1246,
14,
1250,
360,
2254,
2209,
297,
469,
267,
283,
10289,
63,
344,
356,
21472,
14,
344,
12,
283,
505,
356,
1318,
63,
1188,
12,
283,
1122,
63,
632,
356,
283,
4943,
297,
283,
8102,
63,
10131,
356,
267,
2022,
14,
4180,
8,
288,
791,
6460,
63
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
1898,
334,
67,
9,
7800,
13,
10680,
16794,
331,
437,
301,
280,
665,
2374,
32,
4584,
331,
7984,
280,
14,
390,
30,
199,
3,
199,
3,
8779,
365,
11882,
10009,
12,
2867,
402,
11204,
12,
370,
1263,
4954,
12408,
282,
1331,
199,
3,
402,
642,
2032,
436,
4568,
3794,
1584,
334,
1589,
298,
10337,
1288,
370,
7962,
199,
3,
315,
314,
2290,
1928,
10588,
12,
5893,
1928,
12305,
314,
4481,
199,
3,
370,
675,
12,
1331,
12,
2811,
12,
5389,
12,
2780,
12,
11207,
12,
13473,
12,
436,
15,
269,
12743,
199,
3,
6866,
402,
314,
2290,
12,
436,
370,
11291,
12103,
370,
12676,
314,
2290,
365,
199,
3,
13985,
370,
886,
880,
12,
5420,
370,
314,
2569,
3704,
26,
199,
3,
199,
3,
710,
3432,
4248,
4245,
436,
642,
4983,
4245,
10989,
506,
5120,
315,
1006,
199,
3,
6866,
503,
13393,
12468,
402,
314,
2290,
14,
199,
3,
199,
3,
2334,
4141,
2281,
7049,
298,
1179,
2281,
401,
2428,
3408,
1634,
1821,
3826,
12,
7168,
1549,
199,
3,
5292,
12,
6931,
5400,
2845,
5471,
2296,
2334,
2990,
1634,
3169,
12,
199,
3,
3092,
2381,
437,
3115,
3104,
2401,
13229,
14,
1621,
4825,
6461,
7000,
2334,
199,
3,
10610,
1549,
5877,
8164,
6262,
7024,
2381,
1821,
13140,
12,
6736,
1549,
5010,
199,
3,
5603,
12,
7061,
1621,
1261,
9612,
1634,
7066,
12,
7056,
1549,
7334,
12,
7043,
4442,
12,
199,
3,
5738,
1634,
1549,
1621,
11287,
1663,
2334,
4141,
1549,
2334,
4815,
1549,
5010,
13198,
1621,
2334,
199,
3,
4141,
14,
199,
199,
646,
2022,
199,
646,
6055,
1679,
199,
646,
6055,
1679,
14,
1462,
14,
1095,
199,
504,
12896,
14,
11815,
492,
334,
2105,
9,
199,
646,
1101,
199,
504,
1275,
1462,
14,
3058,
492,
17555,
199,
504,
1275,
1462,
14,
751,
492,
2876,
199,
504,
1275,
7618,
492,
3233,
12,
3788,
199,
646,
295,
199,
199,
318,
17639,
8644,
8,
3937,
12,
6413,
88,
304,
272,
9052,
63,
889,
275,
3920,
14,
2019,
29450,
272,
286,
7343,
14,
3543,
342,
272,
3920,
14,
1600,
342,
272,
286,
7343,
14,
1600,
342,
199,
199,
318,
4907,
8644,
837,
272,
286,
7343,
275,
1950,
14,
20784,
3225,
8,
751,
29,
888,
14,
751,
77,
759,
13741,
12,
3303,
2505,
29,
888,
14,
2060,
77,
759,
13741,
12,
3303,
1591,
29,
888,
14,
1102,
77,
759,
13741,
12,
3303,
3050,
29,
888,
14,
4659,
77,
759,
13741,
9,
272,
3920,
29,
6413,
88,
14,
3937,
342,
272,
372,
3920,
12,
286,
7343,
199,
199,
533,
17555,
3227,
8,
10914,
1679,
14,
1462,
14,
1095,
14,
1563,
1692,
304,
272,
347,
636,
826,
721,
277,
12,
1678,
304,
267,
1613,
11027,
826,
721,
873,
9,
339,
1415,
275,
469,
267,
298,
344,
582,
620,
12,
267,
298,
504,
582,
6055,
1679,
14,
1899,
12,
267,
298,
576,
582,
620,
12,
272,
789,
272,
2716,
275,
469,
267,
298,
6460,
63,
1188,
63,
344,
582,
620,
12,
267,
298,
1188,
582,
6055,
1679,
14,
2209,
12,
272,
789,
272,
3350,
63,
1612,
275,
469,
267,
298,
504,
582,
298,
8114,
2,
272,
789,
199,
199,
10914,
1679,
14,
4152,
14,
4144,
905,
3058,
63,
1131,
937,
275,
17555,
3227,
199,
199,
3018,
275,
6055,
1679,
14,
981,
8,
888,
14,
11372,
63,
8803,
9,
421,
199,
32,
3018,
14,
1531,
480,
928,
531,
199,
318,
1343,
8,
10289,
12,
1245,
304,
272,
399,
275,
2876,
8,
1188,
14,
8114,
9,
272,
399,
14,
929,
480,
4219,
531,
272,
399,
14,
31687,
11232,
360,
3200,
63,
1531,
63,
928,
358,
272,
8904,
275,
1245,
14,
8114,
272,
3920,
12,
286,
7343,
275,
4907,
8644,
342,
272,
3920,
14,
2526,
480,
4859,
1305,
63,
85,
724,
10288,
71,
4442,
2256,
63,
85,
724,
266,
6038,
1305,
63,
85,
724,
10288,
71,
534,
7709,
495,
8,
8114,
14,
344,
6393,
4507,
531,
272,
1305,
8114,
534,
283,
272,
367,
1962,
315,
3920,
14,
10174,
837,
267,
1305,
8114,
29,
1143,
59,
16,
61,
272,
340,
334,
495,
8,
8114,
14,
344,
12694,
495,
8,
344,
8114,
2298,
267,
485,
1188,
628,
22731,
542,
73,
18895,
26482,
365,
29506,
475,
282,
221,
613,
79,
5888,
12,
876,
2664,
625,
307,
1810,
79,
1126,
9832,
1458,
264,
2122,
272,
916,
8,
344,
8114,
6803,
18927,
267,
3920,
14,
2526,
360,
4859,
9141,
8,
344,
63,
85,
724,
266,
9,
4442,
2256,
63,
85,
724,
266,
358,
267,
367,
1962,
315,
3920,
14,
10174,
837,
288,
1305,
15253,
1679,
29,
17,
11,
442,
8,
1143,
59,
16,
566,
267,
366,
2159,
2687,
495,
8,
8114,
14,
344,
395,
495,
8,
344,
15253,
1679,
430,
267,
3920,
14,
2526,
480,
10258,
12872,
2256,
63,
85,
724,
266,
334,
344,
63,
85,
724,
10288,
71,
12,
344,
63,
85,
724,
266,
12,
555,
5946,
26277,
9,
13992,
4366,
83,
8719,
83,
2584,
16,
11339,
401,
983,
280,
9,
398,
1318,
63,
1188,
793,
13476,
6651,
32052,
971,
78,
53,
724,
266,
26,
7210,
495,
8,
8114,
14,
354,
6393,
3212,
78,
13355,
26,
768,
7709,
495,
8,
8114,
14,
2473,
6393,
3212,
78,
1304,
26,
7210,
495,
8,
8114,
14,
344,
6393,
3212,
78,
1899,
1931,
26,
327,
1899,
7709,
495,
8,
8114,
14,
344,
9,
398,
26923,
651,
628,
4859,
1305,
335,
6796,
71,
4442,
21472,
2254,
6038,
3367,
555,
29,
16,
2,
267,
3920,
14,
2526,
8,
16891,
651,
9,
267,
367,
1962,
315,
3920,
14,
10174,
837,
288,
5888,
14,
10289,
8,
1143,
59,
16,
6575,
2254,
8,
505,
63,
1188,
793,
12,
7093,
628,
4943,
531,
339,
587,
26,
267,
1318,
63,
1188,
628,
539,
293,
264,
1464,
1895,
2,
272,
340,
8,
495,
8,
10289,
14,
466,
9,
1,
628,
4239,
2349,
267,
1318,
63,
1188,
628,
6651,
433,
13496,
315,
21472,
16254,
419,
60,
78,
7709,
505,
63,
1188,
267,
5888,
14,
1246,
14,
1250,
360,
2254,
2209,
297,
469,
267,
283,
10289,
63,
344,
356,
21472,
14,
344,
12,
283,
505,
356,
1318,
63,
1188,
12,
283,
1122,
63,
632,
356,
283,
4943,
297,
283,
8102,
63,
10131,
356,
267,
2022,
14,
4180,
8,
288,
791,
6460,
63,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1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ePython.py
|
1
|
43520
|
# -*- coding: utf-8 -*-
# Copyright (c) 2007 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
#
"""
Module implementing the Python debugger interface for the debug server.
"""
from __future__ import unicode_literals
import sys
import os
import re
from PyQt5.QtCore import QObject, QTextCodec, QProcess, QProcessEnvironment, \
QTimer
from PyQt5.QtWidgets import QInputDialog
from E5Gui.E5Application import e5App
from E5Gui import E5MessageBox
from . import DebugProtocol
from . import DebugClientCapabilities
import Preferences
import Utilities
from eric6config import getConfig
ClientDefaultCapabilities = DebugClientCapabilities.HasAll
def getRegistryData():
"""
Module function to get characterising data for the debugger interface.
@return list of the following data. Client type (string), client
capabilities (integer), client type association (list of strings)
"""
exts = []
for ext in Preferences.getDebugger("PythonExtensions").split():
if ext.startswith("."):
exts.append(ext)
else:
exts.append(".{0}".format(ext))
if exts and Preferences.getDebugger("PythonInterpreter"):
return ["Python2", ClientDefaultCapabilities, exts]
else:
return ["", 0, []]
class DebuggerInterfacePython(QObject):
"""
Class implementing the Python debugger interface for the debug server.
"""
def __init__(self, debugServer, passive):
"""
Constructor
@param debugServer reference to the debug server (DebugServer)
@param passive flag indicating passive connection mode (boolean)
"""
super(DebuggerInterfacePython, self).__init__()
self.__isNetworked = True
self.__autoContinue = False
self.debugServer = debugServer
self.passive = passive
self.process = None
self.qsock = None
self.queue = []
# set default values for capabilities of clients
self.clientCapabilities = ClientDefaultCapabilities
# set translation function
self.translate = self.__identityTranslation
self.codec = QTextCodec.codecForName(
Preferences.getSystem("StringEncoding"))
self.__unicodeRe = re.compile(r"""\bu(["'])""")
if passive:
# set translation function
if Preferences.getDebugger("PathTranslation"):
self.translateRemote = \
Preferences.getDebugger("PathTranslationRemote")
self.translateLocal = \
Preferences.getDebugger("PathTranslationLocal")
self.translate = self.__remoteTranslation
else:
self.translate = self.__identityTranslation
# attribute to remember the name of the executed script
self.__scriptName = ""
def __identityTranslation(self, fn, remote2local=True):
"""
Private method to perform the identity path translation.
@param fn filename to be translated (string)
@param remote2local flag indicating the direction of translation
(False = local to remote, True = remote to local [default])
@return translated filename (string)
"""
return fn
def __remoteTranslation(self, fn, remote2local=True):
"""
Private method to perform the path translation.
@param fn filename to be translated (string)
@param remote2local flag indicating the direction of translation
(False = local to remote, True = remote to local [default])
@return translated filename (string)
"""
if remote2local:
return fn.replace(self.translateRemote, self.translateLocal)
else:
return fn.replace(self.translateLocal, self.translateRemote)
def __startProcess(self, program, arguments, environment=None):
"""
Private method to start the debugger client process.
@param program name of the executable to start (string)
@param arguments arguments to be passed to the program (list of string)
@param environment dictionary of environment settings to pass
(dict of string)
@return the process object (QProcess) or None
"""
proc = QProcess()
if environment is not None:
env = QProcessEnvironment()
for key, value in list(environment.items()):
env.insert(key, value)
proc.setProcessEnvironment(env)
args = []
for arg in arguments:
args.append(arg)
proc.start(program, args)
if not proc.waitForStarted(10000):
proc = None
return proc
def startRemote(self, port, runInConsole):
"""
Public method to start a remote Python interpreter.
@param port portnumber the debug server is listening on (integer)
@param runInConsole flag indicating to start the debugger in a
console window (boolean)
@return client process object (QProcess), a flag to indicate
a network connection (boolean) and the name of the interpreter
in case of a local execution (string)
"""
interpreter = Preferences.getDebugger("PythonInterpreter")
if interpreter == "":
E5MessageBox.critical(
None,
self.tr("Start Debugger"),
self.tr(
"""<p>No Python2 interpreter configured.</p>"""))
return None, False, ""
debugClientType = Preferences.getDebugger("DebugClientType")
if debugClientType == "standard":
debugClient = os.path.join(getConfig('ericDir'),
"DebugClients", "Python",
"DebugClient.py")
elif debugClientType == "threaded":
debugClient = os.path.join(getConfig('ericDir'),
"DebugClients", "Python",
"DebugClientThreads.py")
else:
debugClient = Preferences.getDebugger("DebugClient")
if debugClient == "":
debugClient = os.path.join(sys.path[0],
"DebugClients", "Python",
"DebugClient.py")
redirect = str(Preferences.getDebugger("PythonRedirect"))
noencoding = Preferences.getDebugger("PythonNoEncoding") and \
'--no-encoding' or ''
if Preferences.getDebugger("RemoteDbgEnabled"):
ipaddr = self.debugServer.getHostAddress(False)
rexec = Preferences.getDebugger("RemoteExecution")
rhost = Preferences.getDebugger("RemoteHost")
if rhost == "":
rhost = "localhost"
if rexec:
args = Utilities.parseOptionString(rexec) + \
[rhost, interpreter, os.path.abspath(debugClient),
noencoding, str(port), redirect, ipaddr]
args[0] = Utilities.getExecutablePath(args[0])
process = self.__startProcess(args[0], args[1:])
if process is None:
E5MessageBox.critical(
None,
self.tr("Start Debugger"),
self.tr(
"""<p>The debugger backend could not be"""
""" started.</p>"""))
# set translation function
if Preferences.getDebugger("PathTranslation"):
self.translateRemote = \
Preferences.getDebugger("PathTranslationRemote")
self.translateLocal = \
Preferences.getDebugger("PathTranslationLocal")
self.translate = self.__remoteTranslation
else:
self.translate = self.__identityTranslation
return process, self.__isNetworked, ""
# set translation function
self.translate = self.__identityTranslation
# setup the environment for the debugger
if Preferences.getDebugger("DebugEnvironmentReplace"):
clientEnv = {}
else:
clientEnv = os.environ.copy()
envlist = Utilities.parseEnvironmentString(
Preferences.getDebugger("DebugEnvironment"))
for el in envlist:
try:
key, value = el.split('=', 1)
if value.startswith('"') or value.startswith("'"):
value = value[1:-1]
clientEnv[str(key)] = str(value)
except ValueError:
pass
ipaddr = self.debugServer.getHostAddress(True)
if runInConsole or Preferences.getDebugger("ConsoleDbgEnabled"):
ccmd = Preferences.getDebugger("ConsoleDbgCommand")
if ccmd:
args = Utilities.parseOptionString(ccmd) + \
[interpreter, os.path.abspath(debugClient),
noencoding, str(port), '0', ipaddr]
args[0] = Utilities.getExecutablePath(args[0])
process = self.__startProcess(args[0], args[1:], clientEnv)
if process is None:
E5MessageBox.critical(
None,
self.tr("Start Debugger"),
self.tr(
"""<p>The debugger backend could not be"""
""" started.</p>"""))
return process, self.__isNetworked, interpreter
process = self.__startProcess(
interpreter,
[debugClient, noencoding, str(port), redirect, ipaddr],
clientEnv)
if process is None:
E5MessageBox.critical(
None,
self.tr("Start Debugger"),
self.tr(
"""<p>The debugger backend could not be started.</p>"""))
return process, self.__isNetworked, interpreter
def startRemoteForProject(self, port, runInConsole):
"""
Public method to start a remote Python interpreter for a project.
@param port portnumber the debug server is listening on (integer)
@param runInConsole flag indicating to start the debugger in a
console window (boolean)
@return client process object (QProcess), a flag to indicate
a network connection (boolean) and the name of the interpreter
in case of a local execution (string)
"""
project = e5App().getObject("Project")
if not project.isDebugPropertiesLoaded():
return None, self.__isNetworked, ""
# start debugger with project specific settings
interpreter = project.getDebugProperty("INTERPRETER")
debugClient = project.getDebugProperty("DEBUGCLIENT")
redirect = str(project.getDebugProperty("REDIRECT"))
noencoding = \
project.getDebugProperty("NOENCODING") and '--no-encoding' or ''
if project.getDebugProperty("REMOTEDEBUGGER"):
ipaddr = self.debugServer.getHostAddress(False)
rexec = project.getDebugProperty("REMOTECOMMAND")
rhost = project.getDebugProperty("REMOTEHOST")
if rhost == "":
rhost = "localhost"
if rexec:
args = Utilities.parseOptionString(rexec) + \
[rhost, interpreter, os.path.abspath(debugClient),
noencoding, str(port), redirect, ipaddr]
args[0] = Utilities.getExecutablePath(args[0])
process = self.__startProcess(args[0], args[1:])
if process is None:
E5MessageBox.critical(
None,
self.tr("Start Debugger"),
self.tr(
"""<p>The debugger backend could not be"""
""" started.</p>"""))
# set translation function
if project.getDebugProperty("PATHTRANSLATION"):
self.translateRemote = \
project.getDebugProperty("REMOTEPATH")
self.translateLocal = \
project.getDebugProperty("LOCALPATH")
self.translate = self.__remoteTranslation
else:
self.translate = self.__identityTranslation
return process, self.__isNetworked, ""
# set translation function
self.translate = self.__identityTranslation
# setup the environment for the debugger
if project.getDebugProperty("ENVIRONMENTOVERRIDE"):
clientEnv = {}
else:
clientEnv = os.environ.copy()
envlist = Utilities.parseEnvironmentString(
project.getDebugProperty("ENVIRONMENTSTRING"))
for el in envlist:
try:
key, value = el.split('=', 1)
if value.startswith('"') or value.startswith("'"):
value = value[1:-1]
clientEnv[str(key)] = str(value)
except ValueError:
pass
ipaddr = self.debugServer.getHostAddress(True)
if runInConsole or project.getDebugProperty("CONSOLEDEBUGGER"):
ccmd = project.getDebugProperty("CONSOLECOMMAND") or \
Preferences.getDebugger("ConsoleDbgCommand")
if ccmd:
args = Utilities.parseOptionString(ccmd) + \
[interpreter, os.path.abspath(debugClient),
noencoding, str(port), '0', ipaddr]
args[0] = Utilities.getExecutablePath(args[0])
process = self.__startProcess(args[0], args[1:], clientEnv)
if process is None:
E5MessageBox.critical(
None,
self.tr("Start Debugger"),
self.tr(
"""<p>The debugger backend could not be"""
""" started.</p>"""))
return process, self.__isNetworked, interpreter
process = self.__startProcess(
interpreter,
[debugClient, noencoding, str(port), redirect, ipaddr],
clientEnv)
if process is None:
E5MessageBox.critical(
None,
self.tr("Start Debugger"),
self.tr(
"""<p>The debugger backend could not be started.</p>"""))
return process, self.__isNetworked, interpreter
def getClientCapabilities(self):
"""
Public method to retrieve the debug clients capabilities.
@return debug client capabilities (integer)
"""
return self.clientCapabilities
def newConnection(self, sock):
"""
Public slot to handle a new connection.
@param sock reference to the socket object (QTcpSocket)
@return flag indicating success (boolean)
"""
# If we already have a connection, refuse this one. It will be closed
# automatically.
if self.qsock is not None:
return False
sock.disconnected.connect(self.debugServer.startClient)
sock.readyRead.connect(self.__parseClientLine)
self.qsock = sock
# Get the remote clients capabilities
self.remoteCapabilities()
return True
def flush(self):
"""
Public slot to flush the queue.
"""
# Send commands that were waiting for the connection.
for cmd in self.queue:
self.qsock.write(cmd.encode('utf8'))
self.queue = []
def shutdown(self):
"""
Public method to cleanly shut down.
It closes our socket and shuts down
the debug client. (Needed on Win OS)
"""
if self.qsock is None:
return
# do not want any slots called during shutdown
self.qsock.disconnected.disconnect(self.debugServer.startClient)
self.qsock.readyRead.disconnect(self.__parseClientLine)
# close down socket, and shut down client as well.
self.__sendCommand('{0}\n'.format(DebugProtocol.RequestShutdown))
self.qsock.flush()
self.qsock.close()
# reinitialize
self.qsock = None
self.queue = []
def isConnected(self):
"""
Public method to test, if a debug client has connected.
@return flag indicating the connection status (boolean)
"""
return self.qsock is not None
def remoteEnvironment(self, env):
"""
Public method to set the environment for a program to debug, run, ...
@param env environment settings (dictionary)
"""
self.__sendCommand('{0}{1}\n'.format(
DebugProtocol.RequestEnv, str(env)))
def remoteLoad(self, fn, argv, wd, traceInterpreter=False,
autoContinue=True, autoFork=False, forkChild=False):
"""
Public method to load a new program to debug.
@param fn the filename to debug (string)
@param argv the commandline arguments to pass to the program (string)
@param wd the working directory for the program (string)
@keyparam traceInterpreter flag indicating if the interpreter library
should be traced as well (boolean)
@keyparam autoContinue flag indicating, that the debugger should not
stop at the first executable line (boolean)
@keyparam autoFork flag indicating the automatic fork mode (boolean)
@keyparam forkChild flag indicating to debug the child after forking
(boolean)
"""
self.__autoContinue = autoContinue
self.__scriptName = os.path.abspath(fn)
wd = self.translate(wd, False)
fn = self.translate(os.path.abspath(fn), False)
self.__sendCommand('{0}{1}\n'.format(
DebugProtocol.RequestForkMode, repr((autoFork, forkChild))))
self.__sendCommand('{0}{1}|{2}|{3}|{4:d}\n'.format(
DebugProtocol.RequestLoad, wd, fn,
str(Utilities.parseOptionString(argv)),
traceInterpreter))
def remoteRun(self, fn, argv, wd, autoFork=False, forkChild=False):
"""
Public method to load a new program to run.
@param fn the filename to run (string)
@param argv the commandline arguments to pass to the program (string)
@param wd the working directory for the program (string)
@keyparam autoFork flag indicating the automatic fork mode (boolean)
@keyparam forkChild flag indicating to debug the child after forking
(boolean)
"""
self.__scriptName = os.path.abspath(fn)
wd = self.translate(wd, False)
fn = self.translate(os.path.abspath(fn), False)
self.__sendCommand('{0}{1}\n'.format(
DebugProtocol.RequestForkMode, repr((autoFork, forkChild))))
self.__sendCommand('{0}{1}|{2}|{3}\n'.format(
DebugProtocol.RequestRun, wd, fn,
str(Utilities.parseOptionString(argv))))
def remoteCoverage(self, fn, argv, wd, erase=False):
"""
Public method to load a new program to collect coverage data.
@param fn the filename to run (string)
@param argv the commandline arguments to pass to the program (string)
@param wd the working directory for the program (string)
@keyparam erase flag indicating that coverage info should be
cleared first (boolean)
"""
self.__scriptName = os.path.abspath(fn)
wd = self.translate(wd, False)
fn = self.translate(os.path.abspath(fn), False)
self.__sendCommand('{0}{1}@@{2}@@{3}@@{4:d}\n'.format(
DebugProtocol.RequestCoverage, wd, fn,
str(Utilities.parseOptionString(argv)), erase))
def remoteProfile(self, fn, argv, wd, erase=False):
"""
Public method to load a new program to collect profiling data.
@param fn the filename to run (string)
@param argv the commandline arguments to pass to the program (string)
@param wd the working directory for the program (string)
@keyparam erase flag indicating that timing info should be cleared
first (boolean)
"""
self.__scriptName = os.path.abspath(fn)
wd = self.translate(wd, False)
fn = self.translate(os.path.abspath(fn), False)
self.__sendCommand('{0}{1}|{2}|{3}|{4:d}\n'.format(
DebugProtocol.RequestProfile, wd, fn,
str(Utilities.parseOptionString(argv)), erase))
def remoteStatement(self, stmt):
"""
Public method to execute a Python statement.
@param stmt the Python statement to execute (string). It
should not have a trailing newline.
"""
self.__sendCommand('{0}\n'.format(stmt))
self.__sendCommand(DebugProtocol.RequestOK + '\n')
def remoteStep(self):
"""
Public method to single step the debugged program.
"""
self.__sendCommand(DebugProtocol.RequestStep + '\n')
def remoteStepOver(self):
"""
Public method to step over the debugged program.
"""
self.__sendCommand(DebugProtocol.RequestStepOver + '\n')
def remoteStepOut(self):
"""
Public method to step out the debugged program.
"""
self.__sendCommand(DebugProtocol.RequestStepOut + '\n')
def remoteStepQuit(self):
"""
Public method to stop the debugged program.
"""
self.__sendCommand(DebugProtocol.RequestStepQuit + '\n')
def remoteContinue(self, special=False):
"""
Public method to continue the debugged program.
@param special flag indicating a special continue operation (boolean)
"""
self.__sendCommand('{0}{1:d}\n'.format(
DebugProtocol.RequestContinue, special))
def remoteBreakpoint(self, fn, line, set, cond=None, temp=False):
"""
Public method to set or clear a breakpoint.
@param fn filename the breakpoint belongs to (string)
@param line linenumber of the breakpoint (int)
@param set flag indicating setting or resetting a breakpoint (boolean)
@param cond condition of the breakpoint (string)
@param temp flag indicating a temporary breakpoint (boolean)
"""
fn = self.translate(fn, False)
self.__sendCommand('{0}{1}@@{2:d}@@{3:d}@@{4:d}@@{5}\n'.format(
DebugProtocol.RequestBreak, fn, line, temp, set,
cond))
def remoteBreakpointEnable(self, fn, line, enable):
"""
Public method to enable or disable a breakpoint.
@param fn filename the breakpoint belongs to (string)
@param line linenumber of the breakpoint (int)
@param enable flag indicating enabling or disabling a breakpoint
(boolean)
"""
fn = self.translate(fn, False)
self.__sendCommand('{0}{1},{2:d},{3:d}\n'.format(
DebugProtocol.RequestBreakEnable, fn, line, enable))
def remoteBreakpointIgnore(self, fn, line, count):
"""
Public method to ignore a breakpoint the next couple of occurrences.
@param fn filename the breakpoint belongs to (string)
@param line linenumber of the breakpoint (int)
@param count number of occurrences to ignore (int)
"""
fn = self.translate(fn, False)
self.__sendCommand('{0}{1},{2:d},{3:d}\n'.format(
DebugProtocol.RequestBreakIgnore, fn, line, count))
def remoteWatchpoint(self, cond, set, temp=False):
"""
Public method to set or clear a watch expression.
@param cond expression of the watch expression (string)
@param set flag indicating setting or resetting a watch expression
(boolean)
@param temp flag indicating a temporary watch expression (boolean)
"""
# cond is combination of cond and special (s. watch expression viewer)
self.__sendCommand('{0}{1}@@{2:d}@@{3:d}\n'.format(
DebugProtocol.RequestWatch, cond, temp, set))
def remoteWatchpointEnable(self, cond, enable):
"""
Public method to enable or disable a watch expression.
@param cond expression of the watch expression (string)
@param enable flag indicating enabling or disabling a watch expression
(boolean)
"""
# cond is combination of cond and special (s. watch expression viewer)
self.__sendCommand('{0}{1},{2:d}\n'.format(
DebugProtocol.RequestWatchEnable, cond, enable))
def remoteWatchpointIgnore(self, cond, count):
"""
Public method to ignore a watch expression the next couple of
occurrences.
@param cond expression of the watch expression (string)
@param count number of occurrences to ignore (int)
"""
# cond is combination of cond and special (s. watch expression viewer)
self.__sendCommand('{0}{1},{2:d}\n'.format(
DebugProtocol.RequestWatchIgnore, cond, count))
def remoteRawInput(self, s):
"""
Public method to send the raw input to the debugged program.
@param s the raw input (string)
"""
self.__sendCommand(s + '\n')
def remoteThreadList(self):
"""
Public method to request the list of threads from the client.
"""
self.__sendCommand('{0}\n'.format(DebugProtocol.RequestThreadList))
def remoteSetThread(self, tid):
"""
Public method to request to set the given thread as current thread.
@param tid id of the thread (integer)
"""
self.__sendCommand('{0}{1:d}\n'.format(
DebugProtocol.RequestThreadSet, tid))
def remoteClientVariables(self, scope, filter, framenr=0):
"""
Public method to request the variables of the debugged program.
@param scope the scope of the variables (0 = local, 1 = global)
@param filter list of variable types to filter out (list of int)
@param framenr framenumber of the variables to retrieve (int)
"""
self.__sendCommand('{0}{1:d}, {2:d}, {3}\n'.format(
DebugProtocol.RequestVariables, framenr, scope, str(filter)))
def remoteClientVariable(self, scope, filter, var, framenr=0):
"""
Public method to request the variables of the debugged program.
@param scope the scope of the variables (0 = local, 1 = global)
@param filter list of variable types to filter out (list of int)
@param var list encoded name of variable to retrieve (string)
@param framenr framenumber of the variables to retrieve (int)
"""
self.__sendCommand('{0}{1}, {2:d}, {3:d}, {4}\n'.format(
DebugProtocol.RequestVariable, str(var), framenr, scope,
str(filter)))
def remoteClientSetFilter(self, scope, filter):
"""
Public method to set a variables filter list.
@param scope the scope of the variables (0 = local, 1 = global)
@param filter regexp string for variable names to filter out (string)
"""
self.__sendCommand('{0}{1:d}, "{2}"\n'.format(
DebugProtocol.RequestSetFilter, scope, filter))
def setCallTraceEnabled(self, on):
"""
Public method to set the call trace state.
@param on flag indicating to enable the call trace function (boolean)
"""
if on:
cmd = "on"
else:
cmd = "off"
self.__sendCommand('{0}{1}\n'.format(
DebugProtocol.RequestCallTrace, cmd))
def remoteEval(self, arg):
"""
Public method to evaluate arg in the current context of the debugged
program.
@param arg the arguments to evaluate (string)
"""
self.__sendCommand('{0}{1}\n'.format(DebugProtocol.RequestEval, arg))
def remoteExec(self, stmt):
"""
Public method to execute stmt in the current context of the debugged
program.
@param stmt statement to execute (string)
"""
self.__sendCommand('{0}{1}\n'.format(DebugProtocol.RequestExec, stmt))
def remoteBanner(self):
"""
Public slot to get the banner info of the remote client.
"""
self.__sendCommand(DebugProtocol.RequestBanner + '\n')
def remoteCapabilities(self):
"""
Public slot to get the debug clients capabilities.
"""
self.__sendCommand(DebugProtocol.RequestCapabilities + '\n')
def remoteCompletion(self, text):
"""
Public slot to get the a list of possible commandline completions
from the remote client.
@param text the text to be completed (string)
"""
self.__sendCommand("{0}{1}\n".format(
DebugProtocol.RequestCompletion, text))
def remoteUTPrepare(self, fn, tn, tfn, failed, cov, covname, coverase):
"""
Public method to prepare a new unittest run.
@param fn the filename to load (string)
@param tn the testname to load (string)
@param tfn the test function name to load tests from (string)
@param failed list of failed test, if only failed test should be run
(list of strings)
@param cov flag indicating collection of coverage data is requested
(boolean)
@param covname filename to be used to assemble the coverage caches
filename (string)
@param coverase flag indicating erasure of coverage data is requested
(boolean)
"""
self.__scriptName = os.path.abspath(fn)
fn = self.translate(os.path.abspath(fn), False)
self.__sendCommand('{0}{1}|{2}|{3}|{4}|{5:d}|{6}|{7:d}\n'.format(
DebugProtocol.RequestUTPrepare, fn, tn, tfn, str(failed),
cov, covname, coverase))
def remoteUTRun(self):
"""
Public method to start a unittest run.
"""
self.__sendCommand('{0}\n'.format(DebugProtocol.RequestUTRun))
def remoteUTStop(self):
"""
Public method to stop a unittest run.
"""
self.__sendCommand('{0}\n'.format(DebugProtocol.RequestUTStop))
def __askForkTo(self):
"""
Private method to ask the user which branch of a fork to follow.
"""
selections = [self.tr("Parent Process"),
self.tr("Child process")]
res, ok = QInputDialog.getItem(
None,
self.tr("Client forking"),
self.tr("Select the fork branch to follow."),
selections,
0, False)
if not ok or res == selections[0]:
self.__sendCommand(DebugProtocol.ResponseForkTo + 'parent\n')
else:
self.__sendCommand(DebugProtocol.ResponseForkTo + 'child\n')
def __parseClientLine(self):
"""
Private method to handle data from the client.
"""
while self.qsock and self.qsock.canReadLine():
qs = self.qsock.readLine()
if self.codec is not None:
line = self.codec.toUnicode(qs)
else:
line = bytes(qs).decode()
if line.endswith(DebugProtocol.EOT):
line = line[:-len(DebugProtocol.EOT)]
if not line:
continue
## print("Server: ", line) ##debug
eoc = line.find('<') + 1
# Deal with case where user has written directly to stdout
# or stderr, but not line terminated and we stepped over the
# write call, in that case the >line< will not be the first
# string read from the socket...
boc = line.find('>')
if boc > 0 and eoc > boc:
self.debugServer.signalClientOutput(line[:boc])
line = line[boc:]
eoc = line.find('<') + 1
boc = line.find('>')
if boc >= 0 and eoc > boc:
resp = line[boc:eoc]
evalArg = self.__unicodeRe.sub(r"\1", line[eoc:-1])
if resp == DebugProtocol.ResponseLine or \
resp == DebugProtocol.ResponseStack:
stack = eval(evalArg)
for s in stack:
s[0] = self.translate(s[0], True)
cf = stack[0]
if self.__autoContinue:
self.__autoContinue = False
QTimer.singleShot(0, self.remoteContinue)
else:
self.debugServer.signalClientLine(
cf[0], int(cf[1]),
resp == DebugProtocol.ResponseStack)
self.debugServer.signalClientStack(stack)
continue
if resp == DebugProtocol.CallTrace:
event, fromStr, toStr = line[eoc:-1].split("@@")
isCall = event.lower() == "c"
fromFile, fromLineno, fromFunc = fromStr.rsplit(":", 2)
toFile, toLineno, toFunc = toStr.rsplit(":", 2)
self.debugServer.signalClientCallTrace(isCall, fromFile,
fromLineno,
fromFunc,
toFile, toLineno,
toFunc)
continue
if resp == DebugProtocol.ResponseThreadList:
currentId, threadList = eval(evalArg)
self.debugServer.signalClientThreadList(
currentId, threadList)
continue
if resp == DebugProtocol.ResponseThreadSet:
self.debugServer.signalClientThreadSet()
continue
if resp == DebugProtocol.ResponseVariables:
vlist = eval(evalArg)
scope = vlist[0]
try:
variables = vlist[1:]
except IndexError:
variables = []
self.debugServer.signalClientVariables(scope, variables)
continue
if resp == DebugProtocol.ResponseVariable:
vlist = eval(evalArg)
scope = vlist[0]
try:
variables = vlist[1:]
except IndexError:
variables = []
self.debugServer.signalClientVariable(scope, variables)
continue
if resp == DebugProtocol.ResponseOK:
self.debugServer.signalClientStatement(False)
continue
if resp == DebugProtocol.ResponseContinue:
self.debugServer.signalClientStatement(True)
continue
if resp == DebugProtocol.ResponseException:
exc = self.translate(evalArg, True)
try:
exclist = eval(exc)
exctype = exclist[0]
excmessage = exclist[1]
stack = exclist[2:]
if stack and stack[0] and stack[0][0] == "<string>":
for stackEntry in stack:
if stackEntry[0] == "<string>":
stackEntry[0] = self.__scriptName
else:
break
except (IndexError, ValueError, SyntaxError):
exctype = None
excmessage = ''
stack = []
self.debugServer.signalClientException(
exctype, excmessage, stack)
continue
if resp == DebugProtocol.ResponseSyntax:
exc = self.translate(evalArg, True)
try:
message, (fn, ln, cn) = eval(exc)
if fn is None:
fn = ''
except (IndexError, ValueError):
message = None
fn = ''
ln = 0
cn = 0
if cn is None:
cn = 0
self.debugServer.signalClientSyntaxError(
message, fn, ln, cn)
continue
if resp == DebugProtocol.ResponseExit:
self.__scriptName = ""
self.debugServer.signalClientExit(evalArg)
continue
if resp == DebugProtocol.ResponseClearBreak:
fn, lineno = evalArg.split(',')
lineno = int(lineno)
fn = self.translate(fn, True)
self.debugServer.signalClientClearBreak(fn, lineno)
continue
if resp == DebugProtocol.ResponseBPConditionError:
fn, lineno = evalArg.split(',')
lineno = int(lineno)
fn = self.translate(fn, True)
self.debugServer.signalClientBreakConditionError(
fn, lineno)
continue
if resp == DebugProtocol.ResponseClearWatch:
self.debugServer.signalClientClearWatch(evalArg)
continue
if resp == DebugProtocol.ResponseWPConditionError:
self.debugServer.signalClientWatchConditionError(evalArg)
continue
if resp == DebugProtocol.ResponseRaw:
prompt, echo = eval(evalArg)
self.debugServer.signalClientRawInput(prompt, echo)
continue
if resp == DebugProtocol.ResponseBanner:
version, platform, dbgclient = eval(evalArg)
self.debugServer.signalClientBanner(
version, platform, dbgclient)
continue
if resp == DebugProtocol.ResponseCapabilities:
cap, clType = eval(evalArg)
self.clientCapabilities = cap
self.debugServer.signalClientCapabilities(cap, clType)
continue
if resp == DebugProtocol.ResponseCompletion:
clstring, text = evalArg.split('||')
cl = eval(clstring)
self.debugServer.signalClientCompletionList(cl, text)
continue
if resp == DebugProtocol.PassiveStartup:
fn, exc = evalArg.split('|')
exc = bool(exc)
fn = self.translate(fn, True)
self.debugServer.passiveStartUp(fn, exc)
continue
if resp == DebugProtocol.ResponseUTPrepared:
res, exc_type, exc_value = eval(evalArg)
self.debugServer.clientUtPrepared(res, exc_type, exc_value)
continue
if resp == DebugProtocol.ResponseUTStartTest:
testname, doc = eval(evalArg)
self.debugServer.clientUtStartTest(testname, doc)
continue
if resp == DebugProtocol.ResponseUTStopTest:
self.debugServer.clientUtStopTest()
continue
if resp == DebugProtocol.ResponseUTTestFailed:
testname, traceback, id = eval(evalArg)
self.debugServer.clientUtTestFailed(
testname, traceback, id)
continue
if resp == DebugProtocol.ResponseUTTestErrored:
testname, traceback, id = eval(evalArg)
self.debugServer.clientUtTestErrored(
testname, traceback, id)
continue
if resp == DebugProtocol.ResponseUTTestSkipped:
testname, reason, id = eval(line[eoc:-1])
self.debugServer.clientUtTestSkipped(testname, reason, id)
continue
if resp == DebugProtocol.ResponseUTTestFailedExpected:
testname, traceback, id = eval(line[eoc:-1])
self.debugServer.clientUtTestFailedExpected(
testname, traceback, id)
continue
if resp == DebugProtocol.ResponseUTTestSucceededUnexpected:
testname, id = eval(line[eoc:-1])
self.debugServer.clientUtTestSucceededUnexpected(
testname, id)
continue
if resp == DebugProtocol.ResponseUTFinished:
self.debugServer.clientUtFinished()
continue
if resp == DebugProtocol.RequestForkTo:
self.__askForkTo()
continue
self.debugServer.signalClientOutput(line)
def __sendCommand(self, cmd):
"""
Private method to send a single line command to the client.
@param cmd command to send to the debug client (string)
"""
if self.qsock is not None:
self.qsock.write(cmd.encode('utf8'))
else:
self.queue.append(cmd)
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
10219,
446,
6927,
577,
386,
6972,
28856,
287,
31983,
665,
271,
1118,
86,
32,
15130,
13,
1997,
287,
31983,
83,
14,
271,
30,
199,
3,
199,
199,
624,
199,
2377,
18234,
314,
2018,
14958,
3217,
367,
314,
3105,
1654,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
984,
199,
646,
747,
199,
646,
295,
199,
199,
504,
14084,
21,
14,
10901,
492,
1413,
1692,
12,
1413,
1872,
8818,
12,
1413,
3498,
12,
1413,
3498,
8263,
12,
971,
272,
1413,
7929,
199,
504,
14084,
21,
14,
29081,
492,
1413,
3205,
5619,
199,
199,
504,
662,
21,
4324,
14,
37,
21,
5039,
492,
325,
21,
2640,
199,
504,
662,
21,
4324,
492,
662,
21,
13695,
199,
199,
504,
1275,
492,
14245,
3658,
199,
504,
1275,
492,
14245,
3041,
17006,
199,
199,
646,
5543,
4023,
199,
646,
738,
17933,
199,
199,
504,
9266,
530,
22,
888,
492,
664,
2028,
421,
199,
3041,
2698,
17006,
275,
14245,
3041,
17006,
14,
6362,
2422,
16872,
199,
318,
664,
10899,
1451,
837,
272,
408,
272,
5673,
805,
370,
664,
2735,
6236,
1044,
666,
367,
314,
14958,
3217,
14,
2286,
768,
1107,
769,
402,
314,
2569,
666,
14,
6810,
730,
334,
875,
395,
1890,
267,
14918,
334,
4115,
395,
1890,
730,
20640,
334,
513,
402,
3326,
9,
272,
408,
272,
27688,
275,
942,
272,
367,
1599,
315,
5543,
4023,
14,
362,
31521,
480,
4718,
10597,
3471,
1294,
837,
267,
340,
1599,
14,
2460,
480,
30946,
288,
27688,
14,
740,
8,
832,
9,
267,
587,
26,
288,
27688,
14,
740,
9520,
91,
16,
5469,
908,
8,
832,
430,
2286,
340,
27688,
436,
5543,
4023,
14,
362,
31521,
480,
4718,
2620,
26499,
2349,
267,
372,
2097,
4718,
18,
401,
6810,
2698,
17006,
12,
27688,
61,
272,
587,
26,
267,
372,
359,
5151,
378,
12,
942,
61,
421,
199,
533,
14245,
836,
4267,
4718,
8,
32260,
304,
272,
408,
272,
8089,
18234,
314,
2018,
14958,
3217,
367,
314,
3105,
1654,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3105,
3120,
12,
21010,
304,
267,
408,
267,
20297,
2728,
768,
635,
3105,
3120,
3659,
370,
314,
3105,
1654,
334,
7084,
3120,
9,
267,
768,
635,
21010,
3305,
9297,
21010,
1950,
818,
334,
4871,
9,
267,
408,
267,
1613,
8,
31521,
4267,
4718,
12,
291,
2843,
826,
4533,
2728,
291,
855,
374,
4491,
379,
275,
715,
267,
291,
855,
2495,
24055,
275,
756,
2728,
291,
14,
1757,
3120,
275,
3105,
3120,
267,
291,
14,
25166,
275,
21010,
267,
291,
14,
1412,
275,
488,
2728,
291,
14,
81,
5096,
275,
488,
267,
291,
14,
1825,
275,
942,
2728,
327,
663,
849,
1338,
367,
14918,
402,
13431,
267,
291,
14,
1258,
17006,
275,
6810,
2698,
17006,
2728,
327,
663,
7761,
805,
267,
291,
14,
5275,
275,
291,
855,
5582,
18483,
2728,
291,
14,
9276,
275,
1413,
1872,
8818,
14,
9276,
1858,
985,
8,
288,
5543,
4023,
14,
362,
3989,
480,
1558,
7630,
2237,
2728,
291,
855,
2975,
497,
275,
295,
14,
2014,
8,
82,
19659,
464,
5234,
1105,
6141,
2728,
340,
21010,
26,
288,
327,
663,
7761,
805,
288,
340,
5543,
4023,
14,
362,
31521,
480,
2042,
18483,
2349,
355,
291,
14,
5275,
6713,
275,
971,
490,
5543,
4023,
14,
362,
31521,
480,
2042,
18483,
6713,
531,
355,
291,
14,
5275,
5339,
275,
971,
490,
5543,
4023,
14,
362,
31521,
480,
2042,
18483,
5339,
531,
355,
291,
14,
5275,
275,
291,
855,
3846,
18483,
288,
587,
26,
355,
291,
14,
5275,
275,
291,
855,
5582,
18483,
2728,
327,
2225,
370,
21027,
314,
536,
402,
314,
7934,
2884,
267,
291,
855,
1579,
985,
275,
3087,
339,
347,
636,
5582,
18483,
8,
277,
12,
4325,
12,
3982,
18,
1832,
29,
549,
304,
267,
408,
267,
18551,
1083,
370,
5147,
314,
8503,
931,
7761,
14,
2728,
768,
635,
4325,
1788,
370,
506,
14598,
334,
875,
9,
267,
768,
635,
3982,
18,
1832,
3305,
9297,
314,
7581,
402,
7761,
288,
334,
797,
275,
2257,
370,
3982,
12,
715,
275,
3982,
370,
2257,
359,
885,
566,
267,
768,
1107,
14598,
1788,
334,
875,
9,
267,
408,
267,
372,
4325,
5493,
347,
636,
3846,
18483,
8,
277,
12,
4325,
12,
3982,
18,
1832,
29,
549,
304,
267,
408,
267,
18551,
1083,
370,
5147,
314,
931,
7761,
14,
2728,
768,
635,
4325,
1788,
370,
506,
14598,
334,
875,
9,
267,
768,
635,
3982,
18,
1832,
3305,
9297,
314,
7581,
402,
7761,
288,
334,
797,
275,
2257,
370,
3982,
12,
715,
275,
3982,
370,
2257,
359,
885,
566,
267,
768,
1107,
14598,
1788,
334,
875,
9,
267,
408,
267,
340,
3982,
18,
1832,
26,
288,
372,
4325,
14,
1814,
8,
277,
14,
5275,
6713,
12,
291,
14,
5275,
5339,
9,
267,
587,
26,
288,
372,
4325,
14,
1814,
8,
277,
14,
5275,
5339,
12,
291,
14,
5275,
6713,
9,
5493,
347,
636,
928,
3498,
8,
277,
12,
2240,
12,
2368,
12,
3734,
29,
403,
304,
267,
408,
267,
18551,
1083,
370,
1343,
314,
14958,
1890,
2112,
14,
2728,
768,
635,
2240,
536,
402,
314,
7286,
370,
1343,
334,
875,
9,
267,
768,
635,
2368,
2368,
370,
506,
3032,
370,
314,
2240,
334,
513,
402,
1059,
9,
267,
768,
635,
3734,
2600,
402,
3734,
2202,
370,
986,
288,
334,
807,
402,
1059,
9,
267,
768,
1107,
314,
2112,
909,
334,
49,
3498,
9,
503,
488,
267,
408,
267,
6499,
275,
1413,
3498,
342,
267,
340,
3734,
365,
440,
488,
26,
288,
2589,
275,
1413,
3498,
8263,
342,
288,
367,
790,
12,
574,
315,
769,
8,
5418,
14,
1744,
5109,
355,
2589,
14,
3176,
8,
498,
12,
574,
9,
288,
6499,
14,
409,
3498,
8263,
8,
1813,
9,
267,
1249,
275,
942,
267,
367,
1680,
315,
2368,
26,
288,
1249,
14,
740,
8,
1273,
9,
267,
6499,
14,
928,
8,
6815,
12,
1249,
9,
267,
340,
440,
6499,
14,
2573,
1858,
21031,
8,
9943,
304,
288,
6499,
275,
488,
2728,
372,
6499,
5493,
347,
1343,
6713,
8,
277,
12,
1844,
12,
1255,
607,
9270,
304,
267,
408,
267,
1684,
1083,
370,
1343,
282,
3982,
2018,
12693,
14,
2728,
768,
635,
1844,
1844,
1955,
314
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
3,
1898,
334,
67,
9,
10219,
446,
6927,
577,
386,
6972,
28856,
287,
31983,
665,
271,
1118,
86,
32,
15130,
13,
1997,
287,
31983,
83,
14,
271,
30,
199,
3,
199,
199,
624,
199,
2377,
18234,
314,
2018,
14958,
3217,
367,
314,
3105,
1654,
14,
199,
624,
199,
199,
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
646,
984,
199,
646,
747,
199,
646,
295,
199,
199,
504,
14084,
21,
14,
10901,
492,
1413,
1692,
12,
1413,
1872,
8818,
12,
1413,
3498,
12,
1413,
3498,
8263,
12,
971,
272,
1413,
7929,
199,
504,
14084,
21,
14,
29081,
492,
1413,
3205,
5619,
199,
199,
504,
662,
21,
4324,
14,
37,
21,
5039,
492,
325,
21,
2640,
199,
504,
662,
21,
4324,
492,
662,
21,
13695,
199,
199,
504,
1275,
492,
14245,
3658,
199,
504,
1275,
492,
14245,
3041,
17006,
199,
199,
646,
5543,
4023,
199,
646,
738,
17933,
199,
199,
504,
9266,
530,
22,
888,
492,
664,
2028,
421,
199,
3041,
2698,
17006,
275,
14245,
3041,
17006,
14,
6362,
2422,
16872,
199,
318,
664,
10899,
1451,
837,
272,
408,
272,
5673,
805,
370,
664,
2735,
6236,
1044,
666,
367,
314,
14958,
3217,
14,
2286,
768,
1107,
769,
402,
314,
2569,
666,
14,
6810,
730,
334,
875,
395,
1890,
267,
14918,
334,
4115,
395,
1890,
730,
20640,
334,
513,
402,
3326,
9,
272,
408,
272,
27688,
275,
942,
272,
367,
1599,
315,
5543,
4023,
14,
362,
31521,
480,
4718,
10597,
3471,
1294,
837,
267,
340,
1599,
14,
2460,
480,
30946,
288,
27688,
14,
740,
8,
832,
9,
267,
587,
26,
288,
27688,
14,
740,
9520,
91,
16,
5469,
908,
8,
832,
430,
2286,
340,
27688,
436,
5543,
4023,
14,
362,
31521,
480,
4718,
2620,
26499,
2349,
267,
372,
2097,
4718,
18,
401,
6810,
2698,
17006,
12,
27688,
61,
272,
587,
26,
267,
372,
359,
5151,
378,
12,
942,
61,
421,
199,
533,
14245,
836,
4267,
4718,
8,
32260,
304,
272,
408,
272,
8089,
18234,
314,
2018,
14958,
3217,
367,
314,
3105,
1654,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3105,
3120,
12,
21010,
304,
267,
408,
267,
20297,
2728,
768,
635,
3105,
3120,
3659,
370,
314,
3105,
1654,
334,
7084,
3120,
9,
267,
768,
635,
21010,
3305,
9297,
21010,
1950,
818,
334,
4871,
9,
267,
408,
267,
1613,
8,
31521,
4267,
4718,
12,
291,
2843,
826,
4533,
2728,
291,
855,
374,
4491,
379,
275,
715,
267,
291,
855,
2495,
24055,
275,
756,
2728,
291,
14,
1757,
3120,
275,
3105,
3120,
267,
291,
14,
25166,
275,
21010,
267,
291,
14,
1412,
275,
488,
2728,
291,
14,
81,
5096,
275,
488,
267,
291,
14,
1825,
275,
942,
2728,
327,
663,
849,
1338,
367,
14918,
402,
13431,
267,
291,
14,
1258,
17006,
275,
6810,
2698,
17006,
2728,
327,
663,
7761,
805,
267,
291,
14,
5275,
275,
291,
855,
5582,
18483,
2728,
291,
14,
9276,
275,
1413,
1872,
8818,
14,
9276,
1858,
985,
8,
288,
5543,
4023,
14,
362,
3989,
480,
1558,
7630,
2237,
2728,
291,
855,
2975,
497,
275,
295,
14,
2014,
8,
82,
19659,
464,
5234,
1105,
6141,
2728,
340,
21010,
26,
288,
327,
663,
7761,
805,
288,
340,
5543,
4023,
14,
362,
31521,
480,
2042,
18483,
2349,
355,
291,
14,
5275,
6713,
275,
971,
490,
5543,
4023,
14,
362,
31521,
480,
2042,
18483,
6713,
531,
355,
291,
14,
5275,
5339,
275,
971,
490,
5543,
4023,
14,
362,
31521,
480,
2042,
18483,
5339,
531,
355,
291,
14,
5275,
275,
291,
855,
3846,
18483,
288,
587,
26,
355,
291,
14,
5275,
275,
291,
855,
5582,
18483,
2728,
327,
2225,
370,
21027,
314,
536,
402,
314,
7934,
2884,
267,
291,
855,
1579,
985,
275,
3087,
339,
347,
636,
5582,
18483,
8,
277,
12,
4325,
12,
3982,
18,
1832,
29,
549,
304,
267,
408,
267,
18551,
1083,
370,
5147,
314,
8503,
931,
7761,
14,
2728,
768,
635,
4325,
1788,
370,
506,
14598,
334,
875,
9,
267,
768,
635,
3982,
18,
1832,
3305,
9297,
314,
7581,
402,
7761,
288,
334,
797,
275,
2257,
370,
3982,
12,
715,
275,
3982,
370,
2257,
359,
885,
566,
267,
768,
1107,
14598,
1788,
334,
875,
9,
267,
408,
267,
372,
4325,
5493,
347,
636,
3846,
18483,
8,
277,
12,
4325,
12,
3982,
18,
1832,
29,
549,
304,
267,
408,
267,
18551,
1083,
370,
5147,
314,
931,
7761,
14,
2728,
768,
635,
4325,
1788,
370,
506,
14598,
334,
875,
9,
267,
768,
635,
3982,
18,
1832,
3305,
9297,
314,
7581,
402,
7761,
288,
334,
797,
275,
2257,
370,
3982,
12,
715,
275,
3982,
370,
2257,
359,
885,
566,
267,
768,
1107,
14598,
1788,
334,
875,
9,
267,
408,
267,
340,
3982,
18,
1832,
26,
288,
372,
4325,
14,
1814,
8,
277,
14,
5275,
6713,
12,
291,
14,
5275,
5339,
9,
267,
587,
26,
288,
372,
4325,
14,
1814,
8,
277,
14,
5275,
5339,
12,
291,
14,
5275,
6713,
9,
5493,
347,
636,
928,
3498,
8,
277,
12,
2240,
12,
2368,
12,
3734,
29,
403,
304,
267,
408,
267,
18551,
1083,
370,
1343,
314,
14958,
1890,
2112,
14,
2728,
768,
635,
2240,
536,
402,
314,
7286,
370,
1343,
334,
875,
9,
267,
768,
635,
2368,
2368,
370,
506,
3032,
370,
314,
2240,
334,
513,
402,
1059,
9,
267,
768,
635,
3734,
2600,
402,
3734,
2202,
370,
986,
288,
334,
807,
402,
1059,
9,
267,
768,
1107,
314,
2112,
909,
334,
49,
3498,
9,
503,
488,
267,
408,
267,
6499,
275,
1413,
3498,
342,
267,
340,
3734,
365,
440,
488,
26,
288,
2589,
275,
1413,
3498,
8263,
342,
288,
367,
790,
12,
574,
315,
769,
8,
5418,
14,
1744,
5109,
355,
2589,
14,
3176,
8,
498,
12,
574,
9,
288,
6499,
14,
409,
3498,
8263,
8,
1813,
9,
267,
1249,
275,
942,
267,
367,
1680,
315,
2368,
26,
288,
1249,
14,
740,
8,
1273,
9,
267,
6499,
14,
928,
8,
6815,
12,
1249,
9,
267,
340,
440,
6499,
14,
2573,
1858,
21031,
8,
9943,
304,
288,
6499,
275,
488,
2728,
372,
6499,
5493,
347,
1343,
6713,
8,
277,
12,
1844,
12,
1255,
607,
9270,
304,
267,
408,
267,
1684,
1083,
370,
1343,
282,
3982,
2018,
12693,
14,
2728,
768,
635,
1844,
1844,
1955,
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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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
] |
xzturn/tensorflow
|
tensorflow/python/keras/engine/training_utils_test.py
|
9
|
16566
|
# Copyright 2018 The TensorFlow Authors. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Tests for training utility functions."""
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import functools
import multiprocessing.pool
import time
from absl.testing import parameterized
import numpy as np
from tensorflow.python.data.ops import dataset_ops
from tensorflow.python.data.ops import readers
from tensorflow.python.eager import context
from tensorflow.python.framework import dtypes
from tensorflow.python.framework import tensor_util
from tensorflow.python.keras import backend
from tensorflow.python.keras import keras_parameterized
from tensorflow.python.keras import testing_utils
from tensorflow.python.keras.engine import training_utils
from tensorflow.python.keras.utils import tf_utils
from tensorflow.python.platform import test
from tensorflow.python.platform import tf_logging as logging
class ModelInputsTest(test.TestCase):
def test_single_thing(self):
a = np.ones(10)
model_inputs = training_utils.ModelInputs(a)
self.assertEqual(['input_1'], model_inputs.get_input_names())
vals = model_inputs.get_symbolic_inputs()
self.assertTrue(tensor_util.is_tensor(vals))
vals = model_inputs.get_symbolic_inputs(return_single_as_list=True)
self.assertEqual(1, len(vals))
self.assertTrue(tensor_util.is_tensor(vals[0]))
self.assertEqual(backend.floatx(), vals[0].dtype)
def test_single_thing_eager(self):
with context.eager_mode():
a = np.ones(10, dtype=np.int32)
model_inputs = training_utils.ModelInputs(a)
self.assertEqual(['input_1'], model_inputs.get_input_names())
val = model_inputs.get_symbolic_inputs()
self.assertTrue(tf_utils.is_symbolic_tensor(val))
vals = model_inputs.get_symbolic_inputs(return_single_as_list=True)
self.assertEqual(1, len(vals))
self.assertTrue(tf_utils.is_symbolic_tensor(vals[0]))
self.assertEqual(dtypes.int32, vals[0].dtype)
def test_list(self):
a = [np.ones(10), np.ones(20)]
model_inputs = training_utils.ModelInputs(a)
self.assertEqual(['input_1', 'input_2'], model_inputs.get_input_names())
vals = model_inputs.get_symbolic_inputs()
self.assertTrue(tensor_util.is_tensor(vals[0]))
self.assertTrue(tensor_util.is_tensor(vals[1]))
def test_list_eager(self):
with context.eager_mode():
a = [np.ones(10), np.ones(20)]
model_inputs = training_utils.ModelInputs(a)
self.assertEqual(['input_1', 'input_2'], model_inputs.get_input_names())
vals = model_inputs.get_symbolic_inputs()
self.assertTrue(tf_utils.is_symbolic_tensor(vals[0]))
self.assertTrue(tf_utils.is_symbolic_tensor(vals[1]))
def test_dict(self):
a = {'b': np.ones(10), 'a': np.ones(20)}
model_inputs = training_utils.ModelInputs(a)
self.assertEqual(['a', 'b'], model_inputs.get_input_names())
vals = model_inputs.get_symbolic_inputs()
self.assertTrue(tensor_util.is_tensor(vals['a']))
self.assertTrue(tensor_util.is_tensor(vals['b']))
def test_dict_eager(self):
with context.eager_mode():
a = {'b': np.ones(10), 'a': np.ones(20)}
model_inputs = training_utils.ModelInputs(a)
self.assertEqual(['a', 'b'], model_inputs.get_input_names())
vals = model_inputs.get_symbolic_inputs()
self.assertTrue(tf_utils.is_symbolic_tensor(vals['a']))
self.assertTrue(tf_utils.is_symbolic_tensor(vals['b']))
class DatasetUtilsTest(test.TestCase, parameterized.TestCase):
@parameterized.named_parameters(
# pylint: disable=g-long-lambda
('Batch', lambda: dataset_ops.Dataset.range(5).batch(2), ValueError),
('Cache', lambda: dataset_ops.Dataset.range(5).cache()),
('Concatenate', lambda: dataset_ops.Dataset.range(5).concatenate(
dataset_ops.Dataset.range(5))),
('FlatMap', lambda: dataset_ops.Dataset.range(5).flat_map(
lambda _: dataset_ops.Dataset.from_tensors(0)), ValueError),
('Filter', lambda: dataset_ops.Dataset.range(5).filter(lambda _: True)),
('FixedLengthRecordDatasetV2',
lambda: readers.FixedLengthRecordDatasetV2([], 42)),
('FromTensors', lambda: dataset_ops.Dataset.from_tensors(0)),
('FromTensorSlices',
lambda: dataset_ops.Dataset.from_tensor_slices([0, 0, 0])),
('Interleave', lambda: dataset_ops.Dataset.range(5).interleave(
lambda _: dataset_ops.Dataset.from_tensors(0), cycle_length=1),
ValueError),
('ParallelInterleave', lambda: dataset_ops.Dataset.range(5).interleave(
lambda _: dataset_ops.Dataset.from_tensors(0),
cycle_length=1,
num_parallel_calls=1), ValueError),
('Map', lambda: dataset_ops.Dataset.range(5).map(lambda x: x)),
('Options',
lambda: dataset_ops.Dataset.range(5).with_options(dataset_ops.Options())
),
('PaddedBatch', lambda: dataset_ops.Dataset.range(5).padded_batch(2, []),
ValueError),
('ParallelMap', lambda: dataset_ops.Dataset.range(5).map(
lambda x: x, num_parallel_calls=1)),
('Prefetch', lambda: dataset_ops.Dataset.range(5).prefetch(1)),
('Range', lambda: dataset_ops.Dataset.range(0)),
('Repeat', lambda: dataset_ops.Dataset.range(0).repeat(0)),
('Shuffle', lambda: dataset_ops.Dataset.range(5).shuffle(1)),
('Skip', lambda: dataset_ops.Dataset.range(5).skip(2)),
('Take', lambda: dataset_ops.Dataset.range(5).take(2)),
('TextLineDataset', lambda: readers.TextLineDatasetV2([])),
('TFRecordDataset', lambda: readers.TFRecordDatasetV2([])),
('Window', lambda: dataset_ops.Dataset.range(5).window(2), ValueError),
('Zip', lambda: dataset_ops.Dataset.zip(dataset_ops.Dataset.range(5))),
# pylint: enable=g-long-lambda
)
def test_assert_not_batched(self, dataset_fn, expected_error=None):
if expected_error is None:
training_utils.assert_not_batched(dataset_fn())
else:
with self.assertRaises(expected_error):
training_utils.assert_not_batched(dataset_fn())
@parameterized.named_parameters(
# pylint: disable=g-long-lambda
('Batch', lambda: dataset_ops.Dataset.range(5).batch(2)),
('Cache', lambda: dataset_ops.Dataset.range(5).cache()),
('Concatenate', lambda: dataset_ops.Dataset.range(5).concatenate(
dataset_ops.Dataset.range(5))),
('FlatMap', lambda: dataset_ops.Dataset.range(5).flat_map(
lambda _: dataset_ops.Dataset.from_tensors(0)), ValueError),
('Filter', lambda: dataset_ops.Dataset.range(5).filter(lambda _: True)),
('FixedLengthRecordDatasetV2',
lambda: readers.FixedLengthRecordDatasetV2([], 42)),
('FromTensors', lambda: dataset_ops.Dataset.from_tensors(0)),
('FromTensorSlices',
lambda: dataset_ops.Dataset.from_tensor_slices([0, 0, 0])),
('Interleave', lambda: dataset_ops.Dataset.range(5).interleave(
lambda _: dataset_ops.Dataset.from_tensors(0), cycle_length=1),
ValueError),
('Map', lambda: dataset_ops.Dataset.range(5).map(lambda x: x)),
('Options',
lambda: dataset_ops.Dataset.range(5).with_options(dataset_ops.Options())
),
('PaddedBatch', lambda: dataset_ops.Dataset.range(5).padded_batch(2, [])),
('ParallelInterleave', lambda: dataset_ops.Dataset.range(5).interleave(
lambda _: dataset_ops.Dataset.from_tensors(0),
cycle_length=1,
num_parallel_calls=1), ValueError),
('ParallelMap', lambda: dataset_ops.Dataset.range(5).map(
lambda x: x, num_parallel_calls=1)),
('Prefetch', lambda: dataset_ops.Dataset.range(5).prefetch(1)),
('Range', lambda: dataset_ops.Dataset.range(0)),
('Repeat', lambda: dataset_ops.Dataset.range(0).repeat(0)),
('Shuffle', lambda: dataset_ops.Dataset.range(5).shuffle(1), ValueError),
('Skip', lambda: dataset_ops.Dataset.range(5).skip(2)),
('Take', lambda: dataset_ops.Dataset.range(5).take(2)),
('TextLineDataset', lambda: readers.TextLineDatasetV2([])),
('TFRecordDataset', lambda: readers.TFRecordDatasetV2([])),
('Window', lambda: dataset_ops.Dataset.range(5).window(2)),
('Zip', lambda: dataset_ops.Dataset.zip(dataset_ops.Dataset.range(5))),
# pylint: enable=g-long-lambda
)
def test_assert_not_shuffled(self, dataset_fn, expected_error=None):
if expected_error is None:
training_utils.assert_not_shuffled(dataset_fn())
else:
with self.assertRaises(expected_error):
training_utils.assert_not_shuffled(dataset_fn())
def test_verify_dataset_shuffled(self):
dataset = dataset_ops.Dataset.range(5)
training_utils.assert_not_shuffled(dataset)
with test.mock.patch.object(logging, 'warning') as mock_log:
training_utils.verify_dataset_shuffled(dataset)
self.assertRegexpMatches(
str(mock_log.call_args),
'input dataset `x` is not shuffled.')
shuffled_dataset = dataset.shuffle(10)
training_utils.verify_dataset_shuffled(shuffled_dataset)
class StandardizeWeightsTest(keras_parameterized.TestCase):
def test_sample_weights(self):
y = np.array([0, 1, 0, 0, 2])
sample_weights = np.array([0.5, 1., 1., 0., 2.])
weights = training_utils.standardize_weights(y, sample_weights)
self.assertAllClose(weights, sample_weights)
def test_class_weights(self):
y = np.array([0, 1, 0, 0, 2])
class_weights = {0: 0.5, 1: 1., 2: 1.5}
weights = training_utils.standardize_weights(y, class_weight=class_weights)
self.assertAllClose(weights, np.array([0.5, 1., 0.5, 0.5, 1.5]))
def test_sample_weights_and_class_weights(self):
y = np.array([0, 1, 0, 0, 2])
sample_weights = np.array([0.5, 1., 1., 0., 2.])
class_weights = {0: 0.5, 1: 1., 2: 1.5}
weights = training_utils.standardize_weights(y, sample_weights,
class_weights)
expected = sample_weights * np.array([0.5, 1., 0.5, 0.5, 1.5])
self.assertAllClose(weights, expected)
def test_dataset_with_class_weight(self):
model = testing_utils.get_small_functional_mlp(1, 4, input_dim=3)
model.compile('rmsprop', 'mse')
inputs = np.zeros((10, 3), np.float32)
targets = np.zeros((10, 4), np.float32)
dataset = dataset_ops.Dataset.from_tensor_slices((inputs, targets))
dataset = dataset.repeat(100)
dataset = dataset.batch(10)
class_weight_np = np.array([0.25, 0.25, 0.25, 0.25])
class_weight = dict(enumerate(class_weight_np))
model.fit(
dataset,
epochs=1,
steps_per_epoch=2,
verbose=1,
class_weight=class_weight)
class MonitoredPool(multiprocessing.pool.ThreadPool):
def __init__(self, *args, **kwargs):
self._apply_counter = 0
self._func_wrapper = None
super(MonitoredPool, self).__init__(*args, **kwargs)
def apply_async(self, func, *args, **kwargs):
self._apply_counter += 1
if self._func_wrapper:
func = self._func_wrapper(func) # pylint: disable=not-callable
return super(MonitoredPool, self).apply_async(func, *args, **kwargs)
def add_sleep(f):
@functools.wraps(f)
def wrapped(*args, **kwargs):
time.sleep(1.)
return f(*args, **kwargs)
return wrapped
def cause_error(f):
@functools.wraps(f)
def wrapped(batch_element, batch_start, batch_end, is_finished): # pylint: disable=unused-argument
# Induce a TypeError during assignment.
return f(None, None, None, is_finished)
return wrapped
_TEST_DATA = np.array((
(3, 1, 3, 1, 2, 0, 3, 3, 1, 2),
(0, 1, 2, 1, 3, 0, 0, 1, 3, 0),
(3, 2, 1, 1, 1, 1, 1, 3, 2, 3),
(2, 2, 0, 1, 0, 3, 3, 2, 1, 1),
(3, 0, 3, 3, 3, 2, 1, 0, 0, 1),
(1, 0, 3, 3, 3, 2, 1, 2, 3, 1),))
class AggregationTest(keras_parameterized.TestCase):
def setUp(self):
super(AggregationTest, self).setUp()
self._old_pool = training_utils._COPY_POOL
self._old_threshold = training_utils.SliceAggregator._BINARY_SIZE_THRESHOLD
self._old_timeout = training_utils.SliceAggregator._MAX_COPY_SECONDS
training_utils._COPY_POOL = MonitoredPool(training_utils._COPY_THREADS)
def tearDown(self):
super(AggregationTest, self).tearDown()
training_utils._COPY_POOL = self._old_pool
training_utils.SliceAggregator._BINARY_SIZE_THRESHOLD = self._old_threshold
training_utils.SliceAggregator._MAX_COPY_SECONDS = self._old_timeout
def _run_with_steps(self):
aggregator = training_utils.OutputsAggregator(use_steps=True)
for i, batch in enumerate(np.array_split(_TEST_DATA, 4)):
if i == 0:
aggregator.create(batch)
aggregator.aggregate(batch)
assert len(aggregator.results) == 1
assert isinstance(aggregator.results[0], training_utils.ConcatAggregator)
aggregator.finalize()
return aggregator.results
def _run_without_steps(self):
aggregator = training_utils.OutputsAggregator(
use_steps=False, num_samples=6)
batch_start = 0
for i, batch in enumerate(np.array_split(_TEST_DATA, 4)):
if i == 0:
aggregator.create(batch)
batch_end = batch_start + batch.shape[0]
aggregator.aggregate(batch, batch_start, batch_end)
batch_start = batch_end
assert len(aggregator.results) == 1
assert isinstance(aggregator.results[0], training_utils.SliceAggregator)
aggregator.finalize()
return aggregator.results
def test_with_steps(self):
self.assertAllEqual(self._run_with_steps(), _TEST_DATA)
def test_without_steps(self):
self.assertAllEqual(self._run_without_steps(), _TEST_DATA)
def test_nested_aggregation(self):
aggregator = training_utils.OutputsAggregator(
use_steps=False, num_samples=6)
batches = np.array_split(_TEST_DATA, 4)
batch_start = 0
for i, batch in enumerate(zip(batches, batches)):
if i == 0:
aggregator.create(batch)
batch_end = batch_start + batch[0].shape[0]
aggregator.aggregate(batch, batch_start, batch_end)
batch_start = batch_end
assert len(aggregator.results) == 2
aggregator.finalize()
self.assertAllEqual(aggregator.results, (_TEST_DATA, _TEST_DATA))
def test_concat_single_batch(self):
aggregator = training_utils.OutputsAggregator(use_steps=True)
data = _TEST_DATA.copy()
aggregator.create(data)
assert len(aggregator.results) == 1
assert isinstance(aggregator.results[0], training_utils.ConcatAggregator)
aggregator.aggregate(data)
aggregator.finalize()
assert aggregator.results is data # No copy.
def test_slice_single_batch(self):
aggregator = training_utils.OutputsAggregator(
use_steps=False, num_samples=6)
data = _TEST_DATA.copy()
aggregator.create(data)
assert len(aggregator.results) == 1
assert isinstance(aggregator.results[0], training_utils.SliceAggregator)
aggregator.aggregate(data, 0, 6)
aggregator.finalize()
assert aggregator.results is data # No copy.
def test_async_copy(self):
training_utils.SliceAggregator._BINARY_SIZE_THRESHOLD = 15
self.assertAllEqual(self._run_without_steps(), _TEST_DATA)
# Two of the four batches will have 20 elements and two will have 10.
self.assertEqual(training_utils._COPY_POOL._apply_counter, 2)
def test_async_copy_timeout(self):
training_utils.SliceAggregator._BINARY_SIZE_THRESHOLD = 15
training_utils.SliceAggregator._MAX_COPY_SECONDS = 0.1
training_utils._COPY_POOL._func_wrapper = add_sleep
with self.assertRaisesRegexp(ValueError, 'Timed out waiting for copy'):
self._run_without_steps()
def test_async_copy_reraise(self):
training_utils.SliceAggregator._BINARY_SIZE_THRESHOLD = 15
training_utils.SliceAggregator._MAX_COPY_SECONDS = 1.
training_utils._COPY_POOL._func_wrapper = cause_error
with self.assertRaisesRegexp(TypeError, 'NoneType'):
self._run_without_steps()
if __name__ == '__main__':
test.main()
|
apache-2.0
|
[
3,
1898,
14894,
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,
6093,
11420,
3423,
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,
9143,
199,
646,
12866,
14,
2293,
199,
646,
900,
199,
199,
504,
2853,
76,
14,
4776,
492,
29526,
199,
646,
2680,
465,
980,
421,
199,
504,
3228,
14,
1548,
14,
576,
14,
1483,
492,
4789,
63,
1483,
199,
504,
3228,
14,
1548,
14,
576,
14,
1483,
492,
7002,
83,
199,
504,
3228,
14,
1548,
14,
10283,
492,
1067,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1974,
199,
504,
3228,
14,
1548,
14,
8811,
492,
4865,
199,
504,
3228,
14,
1548,
14,
8811,
492,
11708,
63,
25000,
199,
504,
3228,
14,
1548,
14,
8811,
492,
5343,
63,
1208,
199,
504,
3228,
14,
1548,
14,
8811,
14,
3908,
492,
6093,
63,
1208,
199,
504,
3228,
14,
1548,
14,
8811,
14,
1208,
492,
2833,
63,
1208,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
3246,
492,
2833,
63,
4806,
465,
2050,
421,
199,
533,
5822,
15124,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
4780,
63,
2127,
8,
277,
304,
272,
282,
275,
980,
14,
4548,
8,
709,
9,
272,
1402,
63,
3711,
275,
6093,
63,
1208,
14,
1685,
15124,
8,
65,
9,
272,
291,
14,
629,
2941,
1210,
63,
17,
995,
1402,
63,
3711,
14,
362,
63,
1210,
63,
1247,
1012,
272,
5322,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
342,
272,
291,
14,
1815,
8,
3128,
63,
1974,
14,
374,
63,
3128,
8,
3643,
430,
272,
5322,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
8,
1107,
63,
4780,
63,
305,
63,
513,
29,
549,
9,
272,
291,
14,
629,
8,
17,
12,
822,
8,
3643,
430,
272,
291,
14,
1815,
8,
3128,
63,
1974,
14,
374,
63,
3128,
8,
3643,
59,
16,
2459,
272,
291,
14,
629,
8,
4620,
14,
1609,
88,
1062,
5322,
59,
16,
1055,
2271,
9,
819,
347,
511,
63,
4780,
63,
2127,
63,
10283,
8,
277,
304,
272,
543,
1067,
14,
10283,
63,
632,
837,
489,
282,
275,
980,
14,
4548,
8,
709,
12,
2152,
29,
1590,
14,
442,
708,
9,
489,
1402,
63,
3711,
275,
6093,
63,
1208,
14,
1685,
15124,
8,
65,
9,
489,
291,
14,
629,
2941,
1210,
63,
17,
995,
1402,
63,
3711,
14,
362,
63,
1210,
63,
1247,
1012,
489,
1139,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
342,
489,
291,
14,
1815,
8,
3249,
63,
1208,
14,
374,
63,
22836,
63,
3128,
8,
637,
430,
489,
5322,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
8,
1107,
63,
4780,
63,
305,
63,
513,
29,
549,
9,
489,
291,
14,
629,
8,
17,
12,
822,
8,
3643,
430,
489,
291,
14,
1815,
8,
3249,
63,
1208,
14,
374,
63,
22836,
63,
3128,
8,
3643,
59,
16,
2459,
489,
291,
14,
629,
8,
5717,
14,
442,
708,
12,
5322,
59,
16,
1055,
2271,
9,
819,
347,
511,
63,
513,
8,
277,
304,
272,
282,
275,
359,
1590,
14,
4548,
8,
709,
395,
980,
14,
4548,
8,
1165,
1874,
272,
1402,
63,
3711,
275,
6093,
63,
1208,
14,
1685,
15124,
8,
65,
9,
272,
291,
14,
629,
2941,
1210,
63,
17,
297,
283,
1210,
63,
18,
995,
1402,
63,
3711,
14,
362,
63,
1210,
63,
1247,
1012,
272,
5322,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
342,
272,
291,
14,
1815,
8,
3128,
63,
1974,
14,
374,
63,
3128,
8,
3643,
59,
16,
2459,
272,
291,
14,
1815,
8,
3128,
63,
1974,
14,
374,
63,
3128,
8,
3643,
59,
17,
2459,
819,
347,
511,
63,
513,
63,
10283,
8,
277,
304,
272,
543,
1067,
14,
10283,
63,
632,
837,
489,
282,
275,
359,
1590,
14,
4548,
8,
709,
395,
980,
14,
4548,
8,
1165,
1874,
489,
1402,
63,
3711,
275,
6093,
63,
1208,
14,
1685,
15124,
8,
65,
9,
489,
291,
14,
629,
2941,
1210,
63,
17,
297,
283,
1210,
63,
18,
995,
1402,
63,
3711,
14,
362,
63,
1210,
63,
1247,
1012,
489,
5322,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
342,
489,
291,
14,
1815,
8,
3249,
63,
1208,
14,
374,
63,
22836,
63,
3128,
8,
3643,
59,
16,
2459,
489,
291,
14,
1815,
8,
3249,
63,
1208,
14,
374,
63,
22836,
63,
3128,
8,
3643,
59,
17,
2459,
819,
347,
511,
63,
807,
8,
277,
304,
272,
282,
275,
791,
66,
356,
980,
14,
4548,
8,
709,
395,
283,
65,
356,
980,
14,
4548,
8,
1165,
6769,
272,
1402,
63,
3711,
275,
6093,
63,
1208,
14,
1685,
15124,
8,
65,
9,
272,
291,
14,
629,
2941,
65,
297,
283,
66,
995,
1402,
63,
3711,
14,
362,
63,
1210,
63,
1247,
1012,
272,
5322,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
342,
272,
291,
14,
1815,
8,
3128,
63,
1974,
14,
374,
63,
3128,
8,
3643,
459,
65,
5156,
272,
291,
14,
1815,
8,
3128,
63,
1974,
14,
374,
63,
3128,
8,
3643,
459,
66,
5156,
819,
347,
511,
63,
807,
63,
10283,
8,
277,
304,
272,
543,
1067,
14,
10283,
63,
632
] |
[
1898,
14894,
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,
6093,
11420,
3423,
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,
9143,
199,
646,
12866,
14,
2293,
199,
646,
900,
199,
199,
504,
2853,
76,
14,
4776,
492,
29526,
199,
646,
2680,
465,
980,
421,
199,
504,
3228,
14,
1548,
14,
576,
14,
1483,
492,
4789,
63,
1483,
199,
504,
3228,
14,
1548,
14,
576,
14,
1483,
492,
7002,
83,
199,
504,
3228,
14,
1548,
14,
10283,
492,
1067,
199,
504,
3228,
14,
1548,
14,
4857,
492,
6674,
199,
504,
3228,
14,
1548,
14,
4857,
492,
2345,
63,
1974,
199,
504,
3228,
14,
1548,
14,
8811,
492,
4865,
199,
504,
3228,
14,
1548,
14,
8811,
492,
11708,
63,
25000,
199,
504,
3228,
14,
1548,
14,
8811,
492,
5343,
63,
1208,
199,
504,
3228,
14,
1548,
14,
8811,
14,
3908,
492,
6093,
63,
1208,
199,
504,
3228,
14,
1548,
14,
8811,
14,
1208,
492,
2833,
63,
1208,
199,
504,
3228,
14,
1548,
14,
3246,
492,
511,
199,
504,
3228,
14,
1548,
14,
3246,
492,
2833,
63,
4806,
465,
2050,
421,
199,
533,
5822,
15124,
774,
8,
396,
14,
1746,
304,
819,
347,
511,
63,
4780,
63,
2127,
8,
277,
304,
272,
282,
275,
980,
14,
4548,
8,
709,
9,
272,
1402,
63,
3711,
275,
6093,
63,
1208,
14,
1685,
15124,
8,
65,
9,
272,
291,
14,
629,
2941,
1210,
63,
17,
995,
1402,
63,
3711,
14,
362,
63,
1210,
63,
1247,
1012,
272,
5322,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
342,
272,
291,
14,
1815,
8,
3128,
63,
1974,
14,
374,
63,
3128,
8,
3643,
430,
272,
5322,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
8,
1107,
63,
4780,
63,
305,
63,
513,
29,
549,
9,
272,
291,
14,
629,
8,
17,
12,
822,
8,
3643,
430,
272,
291,
14,
1815,
8,
3128,
63,
1974,
14,
374,
63,
3128,
8,
3643,
59,
16,
2459,
272,
291,
14,
629,
8,
4620,
14,
1609,
88,
1062,
5322,
59,
16,
1055,
2271,
9,
819,
347,
511,
63,
4780,
63,
2127,
63,
10283,
8,
277,
304,
272,
543,
1067,
14,
10283,
63,
632,
837,
489,
282,
275,
980,
14,
4548,
8,
709,
12,
2152,
29,
1590,
14,
442,
708,
9,
489,
1402,
63,
3711,
275,
6093,
63,
1208,
14,
1685,
15124,
8,
65,
9,
489,
291,
14,
629,
2941,
1210,
63,
17,
995,
1402,
63,
3711,
14,
362,
63,
1210,
63,
1247,
1012,
489,
1139,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
342,
489,
291,
14,
1815,
8,
3249,
63,
1208,
14,
374,
63,
22836,
63,
3128,
8,
637,
430,
489,
5322,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
8,
1107,
63,
4780,
63,
305,
63,
513,
29,
549,
9,
489,
291,
14,
629,
8,
17,
12,
822,
8,
3643,
430,
489,
291,
14,
1815,
8,
3249,
63,
1208,
14,
374,
63,
22836,
63,
3128,
8,
3643,
59,
16,
2459,
489,
291,
14,
629,
8,
5717,
14,
442,
708,
12,
5322,
59,
16,
1055,
2271,
9,
819,
347,
511,
63,
513,
8,
277,
304,
272,
282,
275,
359,
1590,
14,
4548,
8,
709,
395,
980,
14,
4548,
8,
1165,
1874,
272,
1402,
63,
3711,
275,
6093,
63,
1208,
14,
1685,
15124,
8,
65,
9,
272,
291,
14,
629,
2941,
1210,
63,
17,
297,
283,
1210,
63,
18,
995,
1402,
63,
3711,
14,
362,
63,
1210,
63,
1247,
1012,
272,
5322,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
342,
272,
291,
14,
1815,
8,
3128,
63,
1974,
14,
374,
63,
3128,
8,
3643,
59,
16,
2459,
272,
291,
14,
1815,
8,
3128,
63,
1974,
14,
374,
63,
3128,
8,
3643,
59,
17,
2459,
819,
347,
511,
63,
513,
63,
10283,
8,
277,
304,
272,
543,
1067,
14,
10283,
63,
632,
837,
489,
282,
275,
359,
1590,
14,
4548,
8,
709,
395,
980,
14,
4548,
8,
1165,
1874,
489,
1402,
63,
3711,
275,
6093,
63,
1208,
14,
1685,
15124,
8,
65,
9,
489,
291,
14,
629,
2941,
1210,
63,
17,
297,
283,
1210,
63,
18,
995,
1402,
63,
3711,
14,
362,
63,
1210,
63,
1247,
1012,
489,
5322,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
342,
489,
291,
14,
1815,
8,
3249,
63,
1208,
14,
374,
63,
22836,
63,
3128,
8,
3643,
59,
16,
2459,
489,
291,
14,
1815,
8,
3249,
63,
1208,
14,
374,
63,
22836,
63,
3128,
8,
3643,
59,
17,
2459,
819,
347,
511,
63,
807,
8,
277,
304,
272,
282,
275,
791,
66,
356,
980,
14,
4548,
8,
709,
395,
283,
65,
356,
980,
14,
4548,
8,
1165,
6769,
272,
1402,
63,
3711,
275,
6093,
63,
1208,
14,
1685,
15124,
8,
65,
9,
272,
291,
14,
629,
2941,
65,
297,
283,
66,
995,
1402,
63,
3711,
14,
362,
63,
1210,
63,
1247,
1012,
272,
5322,
275,
1402,
63,
3711,
14,
362,
63,
22836,
63,
3711,
342,
272,
291,
14,
1815,
8,
3128,
63,
1974,
14,
374,
63,
3128,
8,
3643,
459,
65,
5156,
272,
291,
14,
1815,
8,
3128,
63,
1974,
14,
374,
63,
3128,
8,
3643,
459,
66,
5156,
819,
347,
511,
63,
807,
63,
10283,
8,
277,
304,
272,
543,
1067,
14,
10283,
63,
632,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
woprgit/p2pool-wopr
|
p2pool/util/datachunker.py
|
288
|
1407
|
import collections
class StringBuffer(object):
'Buffer manager with great worst-case behavior'
def __init__(self, data=''):
self.buf = collections.deque([data])
self.buf_len = len(data)
self.pos = 0
def __len__(self):
return self.buf_len - self.pos
def add(self, data):
self.buf.append(data)
self.buf_len += len(data)
def get(self, wants):
if self.buf_len - self.pos < wants:
raise IndexError('not enough data')
data = []
while wants:
seg = self.buf[0][self.pos:self.pos+wants]
self.pos += len(seg)
while self.buf and self.pos >= len(self.buf[0]):
x = self.buf.popleft()
self.buf_len -= len(x)
self.pos -= len(x)
data.append(seg)
wants -= len(seg)
return ''.join(data)
def _DataChunker(receiver):
wants = receiver.next()
buf = StringBuffer()
while True:
if len(buf) >= wants:
wants = receiver.send(buf.get(wants))
else:
buf.add((yield))
def DataChunker(receiver):
'''
Produces a function that accepts data that is input into a generator
(receiver) in response to the receiver yielding the size of data to wait on
'''
x = _DataChunker(receiver)
x.next()
return x.send
|
gpl-3.0
|
[
646,
5055,
199,
199,
533,
2624,
3299,
8,
785,
304,
272,
283,
3299,
5256,
543,
27254,
1319,
270,
13,
2546,
5953,
7,
2286,
347,
636,
826,
721,
277,
12,
666,
9280,
267,
291,
14,
1436,
275,
5055,
14,
22983,
779,
576,
566,
267,
291,
14,
1436,
63,
552,
275,
822,
8,
576,
9,
267,
291,
14,
1712,
275,
378,
2286,
347,
636,
552,
721,
277,
304,
267,
372,
291,
14,
1436,
63,
552,
446,
291,
14,
1712,
2286,
347,
1050,
8,
277,
12,
666,
304,
267,
291,
14,
1436,
14,
740,
8,
576,
9,
267,
291,
14,
1436,
63,
552,
847,
822,
8,
576,
9,
2286,
347,
664,
8,
277,
12,
15061,
304,
267,
340,
291,
14,
1436,
63,
552,
446,
291,
14,
1712,
665,
15061,
26,
288,
746,
7888,
360,
1397,
8321,
666,
358,
267,
666,
275,
942,
267,
1830,
15061,
26,
288,
8812,
275,
291,
14,
1436,
59,
16,
1527,
277,
14,
1712,
26,
277,
14,
1712,
11,
28789,
61,
288,
291,
14,
1712,
847,
822,
8,
8359,
9,
288,
1830,
291,
14,
1436,
436,
291,
14,
1712,
2356,
822,
8,
277,
14,
1436,
59,
16,
4682,
355,
671,
275,
291,
14,
1436,
14,
25704,
342,
355,
291,
14,
1436,
63,
552,
4862,
822,
8,
88,
9,
355,
291,
14,
1712,
4862,
822,
8,
88,
9,
7846,
666,
14,
740,
8,
8359,
9,
288,
15061,
4862,
822,
8,
8359,
9,
267,
372,
6522,
904,
8,
576,
9,
199,
199,
318,
485,
1451,
9856,
281,
8,
10244,
304,
272,
15061,
275,
13035,
14,
2184,
342,
272,
4123,
275,
2624,
3299,
342,
2286,
1830,
715,
26,
267,
340,
822,
8,
1436,
9,
2356,
15061,
26,
288,
15061,
275,
13035,
14,
2254,
8,
1436,
14,
362,
8,
28789,
430,
267,
587,
26,
288,
4123,
14,
525,
1332,
11481,
430,
199,
318,
3918,
9856,
281,
8,
10244,
304,
272,
1449,
272,
2165,
10569,
282,
805,
626,
11479,
666,
626,
365,
1324,
1901,
282,
4306,
272,
334,
10244,
9,
315,
1177,
370,
314,
13035,
32035,
314,
1568,
402,
666,
370,
3618,
641,
272,
1449,
272,
671,
275,
485,
1451,
9856,
281,
8,
10244,
9,
272,
671,
14,
2184,
342,
272,
372,
671,
14,
2254,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
5055,
199,
199,
533,
2624,
3299,
8,
785,
304,
272,
283,
3299,
5256,
543,
27254,
1319,
270,
13,
2546,
5953,
7,
2286,
347,
636,
826,
721,
277,
12,
666,
9280,
267,
291,
14,
1436,
275,
5055,
14,
22983,
779,
576,
566,
267,
291,
14,
1436,
63,
552,
275,
822,
8,
576,
9,
267,
291,
14,
1712,
275,
378,
2286,
347,
636,
552,
721,
277,
304,
267,
372,
291,
14,
1436,
63,
552,
446,
291,
14,
1712,
2286,
347,
1050,
8,
277,
12,
666,
304,
267,
291,
14,
1436,
14,
740,
8,
576,
9,
267,
291,
14,
1436,
63,
552,
847,
822,
8,
576,
9,
2286,
347,
664,
8,
277,
12,
15061,
304,
267,
340,
291,
14,
1436,
63,
552,
446,
291,
14,
1712,
665,
15061,
26,
288,
746,
7888,
360,
1397,
8321,
666,
358,
267,
666,
275,
942,
267,
1830,
15061,
26,
288,
8812,
275,
291,
14,
1436,
59,
16,
1527,
277,
14,
1712,
26,
277,
14,
1712,
11,
28789,
61,
288,
291,
14,
1712,
847,
822,
8,
8359,
9,
288,
1830,
291,
14,
1436,
436,
291,
14,
1712,
2356,
822,
8,
277,
14,
1436,
59,
16,
4682,
355,
671,
275,
291,
14,
1436,
14,
25704,
342,
355,
291,
14,
1436,
63,
552,
4862,
822,
8,
88,
9,
355,
291,
14,
1712,
4862,
822,
8,
88,
9,
7846,
666,
14,
740,
8,
8359,
9,
288,
15061,
4862,
822,
8,
8359,
9,
267,
372,
6522,
904,
8,
576,
9,
199,
199,
318,
485,
1451,
9856,
281,
8,
10244,
304,
272,
15061,
275,
13035,
14,
2184,
342,
272,
4123,
275,
2624,
3299,
342,
2286,
1830,
715,
26,
267,
340,
822,
8,
1436,
9,
2356,
15061,
26,
288,
15061,
275,
13035,
14,
2254,
8,
1436,
14,
362,
8,
28789,
430,
267,
587,
26,
288,
4123,
14,
525,
1332,
11481,
430,
199,
318,
3918,
9856,
281,
8,
10244,
304,
272,
1449,
272,
2165,
10569,
282,
805,
626,
11479,
666,
626,
365,
1324,
1901,
282,
4306,
272,
334,
10244,
9,
315,
1177,
370,
314,
13035,
32035,
314,
1568,
402,
666,
370,
3618,
641,
272,
1449,
272,
671,
275,
485,
1451,
9856,
281,
8,
10244,
9,
272,
671,
14,
2184,
342,
272,
372,
671,
14,
2254,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
jumpstarter-io/nova
|
nova/scheduler/filters/exact_ram_filter.py
|
26
|
1513
|
# Copyright (c) 2014 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.
from nova.openstack.common import log as logging
from nova.scheduler import filters
LOG = logging.getLogger(__name__)
class ExactRamFilter(filters.BaseHostFilter):
"""Exact RAM Filter."""
def host_passes(self, host_state, filter_properties):
"""Return True if host has the exact amount of RAM available."""
instance_type = filter_properties.get('instance_type')
requested_ram = instance_type['memory_mb']
if requested_ram != host_state.free_ram_mb:
LOG.debug("%(host_state)s does not have exactly "
"%(requested_ram)s MB usable RAM, it has "
"%(usable_ram)s.",
{'host_state': host_state,
'requested_ram': requested_ram,
'usable_ram': host_state.free_ram_mb})
return False
return True
|
apache-2.0
|
[
3,
1898,
334,
67,
9,
6927,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
5913,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
504,
5913,
14,
8874,
492,
4766,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
1316,
2442,
50,
455,
4131,
8,
4273,
14,
1563,
4965,
4131,
304,
272,
408,
29751,
30207,
9388,
1041,
339,
347,
1591,
63,
16027,
8,
277,
12,
1591,
63,
929,
12,
2457,
63,
3282,
304,
267,
408,
1767,
715,
340,
1591,
965,
314,
5835,
5982,
402,
30207,
2808,
1041,
267,
1256,
63,
466,
275,
2457,
63,
3282,
14,
362,
360,
842,
63,
466,
358,
267,
5839,
63,
5975,
275,
1256,
63,
466,
459,
4844,
63,
887,
418,
267,
340,
5839,
63,
5975,
1137,
1591,
63,
929,
14,
4624,
63,
5975,
63,
887,
26,
288,
5051,
14,
1757,
480,
2840,
1102,
63,
929,
9,
83,
1630,
440,
1172,
8840,
298,
1993,
11792,
11151,
63,
5975,
9,
83,
19487,
18025,
30207,
12,
652,
965,
298,
1993,
11792,
14418,
63,
5975,
9,
83,
4765,
1993,
791,
1102,
63,
929,
356,
1591,
63,
929,
12,
2432,
283,
11151,
63,
5975,
356,
5839,
63,
5975,
12,
2432,
283,
14418,
63,
5975,
356,
1591,
63,
929,
14,
4624,
63,
5975,
63,
887,
1552,
288,
372,
756,
398,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
334,
67,
9,
6927,
14260,
2752,
199,
3,
2900,
5924,
5702,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
504,
5913,
14,
8512,
14,
2330,
492,
943,
465,
2050,
199,
504,
5913,
14,
8874,
492,
4766,
199,
199,
4947,
275,
2050,
14,
5572,
3460,
354,
3368,
421,
199,
533,
1316,
2442,
50,
455,
4131,
8,
4273,
14,
1563,
4965,
4131,
304,
272,
408,
29751,
30207,
9388,
1041,
339,
347,
1591,
63,
16027,
8,
277,
12,
1591,
63,
929,
12,
2457,
63,
3282,
304,
267,
408,
1767,
715,
340,
1591,
965,
314,
5835,
5982,
402,
30207,
2808,
1041,
267,
1256,
63,
466,
275,
2457,
63,
3282,
14,
362,
360,
842,
63,
466,
358,
267,
5839,
63,
5975,
275,
1256,
63,
466,
459,
4844,
63,
887,
418,
267,
340,
5839,
63,
5975,
1137,
1591,
63,
929,
14,
4624,
63,
5975,
63,
887,
26,
288,
5051,
14,
1757,
480,
2840,
1102,
63,
929,
9,
83,
1630,
440,
1172,
8840,
298,
1993,
11792,
11151,
63,
5975,
9,
83,
19487,
18025,
30207,
12,
652,
965,
298,
1993,
11792,
14418,
63,
5975,
9,
83,
4765,
1993,
791,
1102,
63,
929,
356,
1591,
63,
929,
12,
2432,
283,
11151,
63,
5975,
356,
5839,
63,
5975,
12,
2432,
283,
14418,
63,
5975,
356,
1591,
63,
929,
14,
4624,
63,
5975,
63,
887,
1552,
288,
372,
756,
398,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
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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
] |
jschuecker/nest-simulator
|
pynest/examples/brunel_alpha_numpy.py
|
13
|
11715
|
# -*- coding: utf-8 -*-
#
# brunel_alpha_numpy.py
#
# This file is part of NEST.
#
# Copyright (C) 2004 The NEST Initiative
#
# NEST 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.
#
# NEST 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 NEST. If not, see <http://www.gnu.org/licenses/>.
'''
Random balanced network (alpha synapses) connected with NumPy
-------------------------------------------------------------
This script simulates an excitatory and an inhibitory population on
the basis of the network used in
Brunel N, Dynamics of Sparsely Connected Networks of Excitatory and
Inhibitory Spiking Neurons, Journal of Computational Neuroscience 8,
183-208 (2000).
In contrast to brunel-alpha-nest.py, this variant uses NumPy to draw
the random connections instead of NEST's builtin connection routines.
When connecting the network customary synapse models are used, which
allow for querying the number of created synapses. Using spike
detectors the average firing rates of the neurons in the populations
are established. The building as well as the simulation time of the
network are recorded.
'''
'''
Import all necessary modules for simulation, analysis and plotting.
Scipy should be imported before nest.
'''
from scipy.optimize import fsolve
import nest
import nest.raster_plot
import numpy
from numpy import exp
import time
'''
Definition of functions used in this example. First, define the
Lambert W function implemented in SLI. The second function
computes the maximum of the postsynaptic potential for a synaptic
input current of unit amplitude (1 pA) using the Lambert W
function. Thus function will later be used to calibrate the synaptic
weights.
'''
def LambertWm1(x):
nest.sli_push(x)
nest.sli_run('LambertWm1')
y = nest.sli_pop()
return y
def ComputePSPnorm(tauMem, CMem, tauSyn):
a = (tauMem / tauSyn)
b = (1.0 / tauSyn - 1.0 / tauMem)
# time of maximum
t_max = 1.0 / b * (-LambertWm1(-exp(-1.0 / a) / a) - 1.0 / a)
# maximum of PSP for current of unit amplitude
return (exp(1.0) / (tauSyn * CMem * b) *
((exp(-t_max / tauMem) - exp(-t_max / tauSyn)) / b -
t_max * exp(-t_max / tauSyn)))
nest.ResetKernel()
'''
Assigning the current time to a variable in order to determine the
build time of the network.
'''
startbuild = time.time()
'''
Assigning the simulation parameters to variables.
'''
dt = 0.1 # the resolution in ms
simtime = 1000.0 # Simulation time in ms
delay = 1.5 # synaptic delay in ms
'''
Definition of the parameters crucial for asynchronous irregular firing
of the neurons.
'''
g = 5.0 # ratio inhibitory weight/excitatory weight
eta = 2.0 # external rate relative to threshold rate
epsilon = 0.1 # connection probability
'''
Definition of the number of neurons in the network and the number of
neuron recorded from
'''
order = 2500
NE = 4 * order # number of excitatory neurons
NI = 1 * order # number of inhibitory neurons
N_neurons = NE + NI # number of neurons in total
N_rec = 50 # record from 50 neurons
'''
Definition of connectivity parameter
'''
CE = int(epsilon * NE) # number of excitatory synapses per neuron
CI = int(epsilon * NI) # number of inhibitory synapses per neuron
C_tot = int(CI + CE) # total number of synapses per neuron
'''
Initialization of the parameters of the integrate and fire neuron and
the synapses. The parameter of the neuron are stored in a dictionary.
The synaptic currents are normalized such that the amplitude of the
PSP is J.
'''
tauSyn = 0.5 # synaptic time constant in ms
tauMem = 20.0 # time constant of membrane potential in ms
CMem = 250.0 # capacitance of membrane in in pF
theta = 20.0 # membrane threshold potential in mV
neuron_params = {"C_m": CMem,
"tau_m": tauMem,
"tau_syn_ex": tauSyn,
"tau_syn_in": tauSyn,
"t_ref": 2.0,
"E_L": 0.0,
"V_reset": 0.0,
"V_m": 0.0,
"V_th": theta}
J = 0.1 # postsynaptic amplitude in mV
J_unit = ComputePSPnorm(tauMem, CMem, tauSyn)
J_ex = J / J_unit # amplitude of excitatory postsynaptic current
J_in = -g * J_ex # amplitude of inhibitory postsynaptic current
'''
Definition of threshold rate, which is the external rate needed to fix
the membrane potential around its threshold, the external firing rate
and the rate of the poisson generator which is multiplied by the
in-degree CE and converted to Hz by multiplication by 1000.
'''
nu_th = (theta * CMem) / (J_ex * CE * numpy.exp(1) * tauMem * tauSyn)
nu_ex = eta * nu_th
p_rate = 1000.0 * nu_ex * CE
'''
Configuration of the simulation kernel by the previously defined time
resolution used in the simulation. Setting "print_time" to True prints
the already processed simulation time as well as its percentage of the
total simulation time.
'''
nest.SetKernelStatus({"resolution": dt, "print_time": True,
"overwrite_files": True})
print("Building network")
'''
Configuration of the model `iaf_psc_alpha` and `poisson_generator`
using SetDefaults(). This function expects the model to be the
inserted as a string and the parameter to be specified in a
dictionary. All instances of theses models created after this point
will have the properties specified in the dictionary by default.
'''
nest.SetDefaults("iaf_psc_alpha", neuron_params)
nest.SetDefaults("poisson_generator", {"rate": p_rate})
'''
Creation of the nodes using `Create`. We store the returned handles in
variables for later reference. Here the excitatory and inhibitory, as
well as the poisson generator and two spike detectors. The spike
detectors will later be used to record excitatory and inhibitory
spikes.
'''
nodes_ex = nest.Create("iaf_psc_alpha", NE)
nodes_in = nest.Create("iaf_psc_alpha", NI)
noise = nest.Create("poisson_generator")
espikes = nest.Create("spike_detector")
ispikes = nest.Create("spike_detector")
'''
Configuration of the spike detectors recording excitatory and
inhibitory spikes using `SetStatus`, which expects a list of node
handles and a list of parameter dictionaries. Setting the variable
"to_file" to True ensures that the spikes will be recorded in a .gdf
file starting with the string assigned to label. Setting "withtime"
and "withgid" to True ensures that each spike is saved to file by
stating the gid of the spiking neuron and the spike time in one line.
'''
nest.SetStatus(espikes, [{"label": "brunel-py-ex",
"withtime": True,
"withgid": True,
"to_file": True}])
nest.SetStatus(ispikes, [{"label": "brunel-py-in",
"withtime": True,
"withgid": True,
"to_file": True}])
print("Connecting devices")
'''
Definition of a synapse using `CopyModel`, which expects the model
name of a pre-defined synapse, the name of the customary synapse and
an optional parameter dictionary. The parameters defined in the
dictionary will be the default parameter for the customary
synapse. Here we define one synapse for the excitatory and one for the
inhibitory connections giving the previously defined weights and equal
delays.
'''
nest.CopyModel("static_synapse", "excitatory",
{"weight": J_ex, "delay": delay})
nest.CopyModel("static_synapse", "inhibitory",
{"weight": J_in, "delay": delay})
'''
Connecting the previously defined poisson generator to the excitatory
and inhibitory neurons using the excitatory synapse. Since the poisson
generator is connected to all neurons in the population the default
rule ('all_to_all') of Connect() is used. The synaptic properties are
inserted via syn_spec which expects a dictionary when defining
multiple variables or a string when simply using a pre-defined
synapse.
'''
nest.Connect(noise, nodes_ex, syn_spec="excitatory")
nest.Connect(noise, nodes_in, syn_spec="excitatory")
'''
Connecting the first N_rec nodes of the excitatory and inhibitory
population to the associated spike detectors using excitatory
synapses. Here the same shortcut for the specification of the synapse
as defined above is used.
'''
nest.Connect(nodes_ex[:N_rec], espikes, syn_spec="excitatory")
nest.Connect(nodes_in[:N_rec], ispikes, syn_spec="excitatory")
print("Connecting network")
'''
Here, we create the connections from the excitatory neurons to all
other neurons. We exploit that the neurons have consecutive IDs,
running from 1,...,NE for the excitatory neurons and from
(NE+1),...,(NE+NI) for the inhibitory neurons.
'''
numpy.random.seed(1234)
sources_ex = numpy.random.randint(1, NE + 1, (N_neurons, CE))
sources_in = numpy.random.randint(NE + 1, N_neurons + 1, (N_neurons, CI))
'''
We now iterate over all neuron IDs, and connect the neuron to the
sources from our array. The first loop connects the excitatory neurons
and the second loop the inhibitory neurons.
'''
for n in range(N_neurons):
nest.Connect(list(sources_ex[n]), [n + 1], syn_spec="excitatory")
for n in range(N_neurons):
nest.Connect(list(sources_in[n]), [n + 1], syn_spec="inhibitory")
'''
Storage of the time point after the buildup of the network in a
variable.
'''
endbuild = time.time()
'''
Simulation of the network.
'''
print("Simulating")
nest.Simulate(simtime)
'''
Storage of the time point after the simulation of the network in a
variable.
'''
endsimulate = time.time()
'''
Reading out the total number of spikes received from the spike
detector connected to the excitatory population and the inhibitory
population.
'''
events_ex = nest.GetStatus(espikes, "n_events")[0]
events_in = nest.GetStatus(ispikes, "n_events")[0]
'''
Calculation of the average firing rate of the excitatory and the
inhibitory neurons by dividing the total number of recorded spikes by
the number of neurons recorded from and the simulation time. The
multiplication by 1000.0 converts the unit 1/ms to 1/s=Hz.
'''
rate_ex = events_ex / simtime * 1000.0 / N_rec
rate_in = events_in / simtime * 1000.0 / N_rec
'''
Reading out the number of connections established using the excitatory
and inhibitory synapse model. The numbers are summed up resulting in
the total number of synapses.
'''
num_synapses = (nest.GetDefaults("excitatory")["num_connections"] +
nest.GetDefaults("inhibitory")["num_connections"])
'''
Establishing the time it took to build and simulate the network by
taking the difference of the pre-defined time variables.
'''
build_time = endbuild - startbuild
sim_time = endsimulate - endbuild
'''
Printing the network properties, firing rates and building times.
'''
print("Brunel network simulation (Python)")
print("Number of neurons : {0}".format(N_neurons))
print("Number of synapses: {0}".format(num_synapses))
print(" Exitatory : {0}".format(int(CE * N_neurons) + N_neurons))
print(" Inhibitory : {0}".format(int(CI * N_neurons)))
print("Excitatory rate : %.2f Hz" % rate_ex)
print("Inhibitory rate : %.2f Hz" % rate_in)
print("Building time : %.2f s" % build_time)
print("Simulation time : %.2f s" % sim_time)
'''
Plot a raster of the excitatory neurons and a histogram.
'''
nest.raster_plot.from_device(espikes, hist=True)
|
gpl-2.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
330,
1065,
352,
63,
4468,
63,
4714,
14,
647,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28878,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
8353,
710,
28878,
21412,
1905,
199,
3,
199,
3,
28878,
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,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
28878,
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,
28878,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
2344,
199,
3883,
14094,
68,
2784,
334,
4468,
9560,
25036,
9,
8539,
543,
20602,
199,
6489,
8684,
199,
199,
2765,
2884,
4389,
15409,
376,
3178,
390,
8658,
436,
376,
315,
20215,
390,
1089,
16423,
641,
199,
1589,
5597,
402,
314,
2784,
1202,
315,
199,
199,
34,
1065,
352,
653,
12,
577,
4019,
2932,
402,
14531,
590,
1448,
4636,
17138,
402,
1316,
14422,
8658,
436,
199,
607,
20215,
390,
1089,
428,
1038,
17443,
5612,
32073,
12,
22142,
402,
3599,
337,
6279,
5612,
9129,
9907,
4894,
1695,
12,
199,
12363,
13,
10630,
334,
8269,
680,
199,
199,
607,
30347,
370,
330,
1065,
352,
13,
4468,
13,
15272,
14,
647,
12,
642,
9854,
4440,
20602,
370,
5954,
199,
1589,
2196,
6947,
3140,
402,
28878,
1159,
6762,
1950,
14975,
14,
199,
199,
11423,
18170,
314,
2784,
3537,
695,
9560,
19111,
1709,
787,
1202,
12,
1314,
199,
3306,
367,
27405,
314,
1329,
402,
2737,
9560,
25036,
14,
11719,
19441,
415,
199,
19401,
83,
314,
8095,
289,
16648,
24434,
402,
314,
1279,
32073,
315,
314,
4560,
21429,
199,
1530,
23594,
14,
710,
10015,
465,
5521,
465,
314,
17625,
900,
402,
314,
199,
1200,
787,
18894,
14,
199,
2344,
199,
199,
2344,
199,
6295,
1006,
5784,
4621,
367,
17625,
12,
11284,
436,
25174,
14,
199,
29231,
647,
1077,
506,
8439,
2544,
10715,
14,
199,
2344,
199,
199,
504,
7026,
14,
13416,
492,
7449,
3344,
199,
199,
646,
10715,
199,
646,
10715,
14,
20876,
63,
2798,
199,
199,
646,
2680,
199,
504,
2680,
492,
1437,
199,
199,
646,
900,
199,
199,
2344,
199,
10701,
402,
3423,
1202,
315,
642,
2893,
14,
7758,
12,
5627,
314,
199,
44,
455,
12504,
644,
805,
6366,
315,
428,
2673,
14,
710,
3499,
805,
199,
863,
3862,
314,
5696,
402,
314,
2963,
9466,
439,
764,
12330,
367,
282,
9560,
439,
764,
199,
1210,
1453,
402,
4137,
30727,
334,
17,
299,
33,
9,
1808,
314,
491,
455,
12504,
644,
199,
1593,
14,
20227,
805,
911,
2945,
506,
1202,
370,
12855,
1866,
314,
9560,
439,
764,
199,
4916,
14,
199,
2344,
421,
199,
318,
491,
455,
12504,
55,
77,
17,
8,
88,
304,
272,
10715,
14,
23766,
63,
5335,
8,
88,
9,
272,
10715,
14,
23766,
63,
1065,
360,
44,
455,
12504,
55,
77,
17,
358,
272,
612,
275,
10715,
14,
23766,
63,
1935,
342,
272,
372,
612,
421,
199,
318,
8354,
5067,
48,
4791,
8,
16656,
14169,
12,
445,
14169,
12,
19188,
17746,
304,
272,
282,
275,
334,
16656,
14169,
1182,
19188,
17746,
9,
272,
330,
275,
334,
17,
14,
16,
1182,
19188,
17746,
446,
413,
14,
16,
1182,
19188,
14169,
9,
339,
327,
900,
402,
5696,
272,
307,
63,
988,
275,
413,
14,
16,
1182,
330,
627,
5868,
44,
455,
12504,
55,
77,
17,
2801,
1474,
2801,
17,
14,
16,
1182,
282,
9,
1182,
282,
9,
446,
413,
14,
16,
1182,
282,
9,
339,
327,
5696,
402,
510,
5763,
367,
1453,
402,
4137,
30727,
272,
372,
334,
1474,
8,
17,
14,
16,
9,
1182,
334,
16656,
17746,
627,
445,
14169,
627,
330,
9,
627,
288,
3666,
1474,
2801,
84,
63,
988,
1182,
19188,
14169,
9,
446,
1437,
2801,
84,
63,
988,
1182,
19188,
17746,
430,
1182,
330,
446,
1467,
307,
63,
988,
627,
1437,
2801,
84,
63,
988,
1182,
19188,
17746,
1724,
199,
199,
15272,
14,
9637,
14127,
342,
199,
199,
2344,
199,
9595,
316,
314,
1453,
900,
370,
282,
1750,
315,
1865,
370,
6705,
314,
199,
1506,
900,
402,
314,
2784,
14,
199,
2344,
199,
199,
928,
1506,
275,
900,
14,
521,
342,
199,
199,
2344,
199,
9595,
316,
314,
17625,
2633,
370,
2860,
14,
199,
2344,
199,
199,
3583,
275,
378,
14,
17,
259,
327,
314,
12401,
315,
6605,
199,
5206,
521,
275,
5198,
14,
16,
221,
327,
10751,
5332,
900,
315,
6605,
199,
5814,
275,
413,
14,
21,
259,
327,
9560,
439,
764,
7339,
315,
6605,
199,
199,
2344,
199,
10701,
402,
314,
2633,
2467,
85,
7180,
367,
15608,
8190,
7898,
289,
16648,
199,
1618,
314,
1279,
32073,
14,
199,
2344,
199,
199,
71,
275,
959,
14,
16,
221,
327,
10463,
315,
20215,
390,
1089,
5401,
15,
2804,
390,
8658,
5401,
199,
1841,
275,
499,
14,
16,
221,
327,
5957,
6634,
3847,
370,
8765,
6634,
199,
15761,
275,
378,
14,
17,
221,
327,
1950,
12224,
199,
199,
2344,
199,
10701,
402,
314,
1329,
402,
1279,
32073,
315,
314,
2784,
436,
314,
1329,
402,
199,
32054,
18894,
687,
199,
2344,
199,
199,
1648,
275,
5661,
383,
199,
6388,
275,
841,
627,
1865,
221,
327,
1329,
402,
3178,
390,
8658,
1279,
32073,
199,
16730,
275,
413,
627,
1865,
221,
327,
1329,
402,
315,
20215,
390,
1089,
1279,
32073,
199,
46,
63,
685,
32073,
275,
7110,
435,
653,
41,
257,
327,
1329,
402,
1279,
32073,
315,
3141,
199,
46,
63,
2761,
275,
5238,
420,
327,
2777,
687,
5238,
1279,
32073,
199,
199,
2344,
199,
10701,
402,
20170,
2725,
199,
2344,
199,
199,
2089,
275,
1109,
8,
15761,
627,
7110,
9,
221,
327,
1329,
402,
3178,
390,
8658,
9560,
25036,
1126,
20242,
199
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
199,
3,
330,
1065,
352,
63,
4468,
63,
4714,
14,
647,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
28878,
14,
199,
3,
199,
3,
1898,
334,
35,
9,
8353,
710,
28878,
21412,
1905,
199,
3,
199,
3,
28878,
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,
499,
402,
314,
844,
12,
503,
199,
3,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
28878,
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,
28878,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
2344,
199,
3883,
14094,
68,
2784,
334,
4468,
9560,
25036,
9,
8539,
543,
20602,
199,
6489,
8684,
199,
199,
2765,
2884,
4389,
15409,
376,
3178,
390,
8658,
436,
376,
315,
20215,
390,
1089,
16423,
641,
199,
1589,
5597,
402,
314,
2784,
1202,
315,
199,
199,
34,
1065,
352,
653,
12,
577,
4019,
2932,
402,
14531,
590,
1448,
4636,
17138,
402,
1316,
14422,
8658,
436,
199,
607,
20215,
390,
1089,
428,
1038,
17443,
5612,
32073,
12,
22142,
402,
3599,
337,
6279,
5612,
9129,
9907,
4894,
1695,
12,
199,
12363,
13,
10630,
334,
8269,
680,
199,
199,
607,
30347,
370,
330,
1065,
352,
13,
4468,
13,
15272,
14,
647,
12,
642,
9854,
4440,
20602,
370,
5954,
199,
1589,
2196,
6947,
3140,
402,
28878,
1159,
6762,
1950,
14975,
14,
199,
199,
11423,
18170,
314,
2784,
3537,
695,
9560,
19111,
1709,
787,
1202,
12,
1314,
199,
3306,
367,
27405,
314,
1329,
402,
2737,
9560,
25036,
14,
11719,
19441,
415,
199,
19401,
83,
314,
8095,
289,
16648,
24434,
402,
314,
1279,
32073,
315,
314,
4560,
21429,
199,
1530,
23594,
14,
710,
10015,
465,
5521,
465,
314,
17625,
900,
402,
314,
199,
1200,
787,
18894,
14,
199,
2344,
199,
199,
2344,
199,
6295,
1006,
5784,
4621,
367,
17625,
12,
11284,
436,
25174,
14,
199,
29231,
647,
1077,
506,
8439,
2544,
10715,
14,
199,
2344,
199,
199,
504,
7026,
14,
13416,
492,
7449,
3344,
199,
199,
646,
10715,
199,
646,
10715,
14,
20876,
63,
2798,
199,
199,
646,
2680,
199,
504,
2680,
492,
1437,
199,
199,
646,
900,
199,
199,
2344,
199,
10701,
402,
3423,
1202,
315,
642,
2893,
14,
7758,
12,
5627,
314,
199,
44,
455,
12504,
644,
805,
6366,
315,
428,
2673,
14,
710,
3499,
805,
199,
863,
3862,
314,
5696,
402,
314,
2963,
9466,
439,
764,
12330,
367,
282,
9560,
439,
764,
199,
1210,
1453,
402,
4137,
30727,
334,
17,
299,
33,
9,
1808,
314,
491,
455,
12504,
644,
199,
1593,
14,
20227,
805,
911,
2945,
506,
1202,
370,
12855,
1866,
314,
9560,
439,
764,
199,
4916,
14,
199,
2344,
421,
199,
318,
491,
455,
12504,
55,
77,
17,
8,
88,
304,
272,
10715,
14,
23766,
63,
5335,
8,
88,
9,
272,
10715,
14,
23766,
63,
1065,
360,
44,
455,
12504,
55,
77,
17,
358,
272,
612,
275,
10715,
14,
23766,
63,
1935,
342,
272,
372,
612,
421,
199,
318,
8354,
5067,
48,
4791,
8,
16656,
14169,
12,
445,
14169,
12,
19188,
17746,
304,
272,
282,
275,
334,
16656,
14169,
1182,
19188,
17746,
9,
272,
330,
275,
334,
17,
14,
16,
1182,
19188,
17746,
446,
413,
14,
16,
1182,
19188,
14169,
9,
339,
327,
900,
402,
5696,
272,
307,
63,
988,
275,
413,
14,
16,
1182,
330,
627,
5868,
44,
455,
12504,
55,
77,
17,
2801,
1474,
2801,
17,
14,
16,
1182,
282,
9,
1182,
282,
9,
446,
413,
14,
16,
1182,
282,
9,
339,
327,
5696,
402,
510,
5763,
367,
1453,
402,
4137,
30727,
272,
372,
334,
1474,
8,
17,
14,
16,
9,
1182,
334,
16656,
17746,
627,
445,
14169,
627,
330,
9,
627,
288,
3666,
1474,
2801,
84,
63,
988,
1182,
19188,
14169,
9,
446,
1437,
2801,
84,
63,
988,
1182,
19188,
17746,
430,
1182,
330,
446,
1467,
307,
63,
988,
627,
1437,
2801,
84,
63,
988,
1182,
19188,
17746,
1724,
199,
199,
15272,
14,
9637,
14127,
342,
199,
199,
2344,
199,
9595,
316,
314,
1453,
900,
370,
282,
1750,
315,
1865,
370,
6705,
314,
199,
1506,
900,
402,
314,
2784,
14,
199,
2344,
199,
199,
928,
1506,
275,
900,
14,
521,
342,
199,
199,
2344,
199,
9595,
316,
314,
17625,
2633,
370,
2860,
14,
199,
2344,
199,
199,
3583,
275,
378,
14,
17,
259,
327,
314,
12401,
315,
6605,
199,
5206,
521,
275,
5198,
14,
16,
221,
327,
10751,
5332,
900,
315,
6605,
199,
5814,
275,
413,
14,
21,
259,
327,
9560,
439,
764,
7339,
315,
6605,
199,
199,
2344,
199,
10701,
402,
314,
2633,
2467,
85,
7180,
367,
15608,
8190,
7898,
289,
16648,
199,
1618,
314,
1279,
32073,
14,
199,
2344,
199,
199,
71,
275,
959,
14,
16,
221,
327,
10463,
315,
20215,
390,
1089,
5401,
15,
2804,
390,
8658,
5401,
199,
1841,
275,
499,
14,
16,
221,
327,
5957,
6634,
3847,
370,
8765,
6634,
199,
15761,
275,
378,
14,
17,
221,
327,
1950,
12224,
199,
199,
2344,
199,
10701,
402,
314,
1329,
402,
1279,
32073,
315,
314,
2784,
436,
314,
1329,
402,
199,
32054,
18894,
687,
199,
2344,
199,
199,
1648,
275,
5661,
383,
199,
6388,
275,
841,
627,
1865,
221,
327,
1329,
402,
3178,
390,
8658,
1279,
32073,
199,
16730,
275,
413,
627,
1865,
221,
327,
1329,
402,
315,
20215,
390,
1089,
1279,
32073,
199,
46,
63,
685,
32073,
275,
7110,
435,
653,
41,
257,
327,
1329,
402,
1279,
32073,
315,
3141,
199,
46,
63,
2761,
275,
5238,
420,
327,
2777,
687,
5238,
1279,
32073,
199,
199,
2344,
199,
10701,
402,
20170,
2725,
199,
2344,
199,
199,
2089,
275,
1109,
8,
15761,
627,
7110,
9,
221,
327,
1329,
402,
3178,
390,
8658,
9560,
25036,
1126,
20242,
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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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.
#
# ESPResSo 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 collections import OrderedDict
import inspect
import os
import re
import signal
from espressomd.utils import is_valid_type
try:
import cPickle as pickle
except ImportError:
import pickle
# Convenient Checkpointing for ESPResSo
class Checkpoint:
"""Checkpoint handling (reading and writing).
Parameters
----------
checkpoint_id : :obj:`str`
A string identifying a specific checkpoint.
checkpoint_path : :obj:`str`, optional
Path for reading and writing the checkpoint.
If not given, the CWD is used.
"""
def __init__(self, checkpoint_id=None, checkpoint_path="."):
# check if checkpoint_id is valid (only allow a-z A-Z 0-9 _ -)
if not isinstance(checkpoint_id, str) or bool(
re.compile(r"[^a-zA-Z0-9_\-]").search(checkpoint_id)):
raise ValueError("Invalid checkpoint id.")
if not isinstance(checkpoint_path, str):
raise ValueError("Invalid checkpoint path.")
self.checkpoint_objects = []
self.checkpoint_signals = []
frm = inspect.stack()[1]
self.calling_module = inspect.getmodule(frm[0])
checkpoint_path = os.path.join(checkpoint_path, checkpoint_id)
self.checkpoint_dir = os.path.realpath(checkpoint_path)
if not os.path.isdir(self.checkpoint_dir):
os.makedirs(self.checkpoint_dir)
# update checkpoint counter
self.counter = 0
while os.path.isfile(os.path.join(
self.checkpoint_dir, "{}.checkpoint".format(self.counter))):
self.counter += 1
# init signals
for signum in self.read_signals():
self.register_signal(signum)
def __getattr_submodule(self, obj, name, default):
"""
Generalization of getattr(). __getattr_submodule(object,
"name1.sub1.sub2", None) will return attribute sub2 if available
otherwise None.
"""
names = name.split('.')
for i in range(len(names) - 1):
obj = getattr(obj, names[i], default)
return getattr(obj, names[-1], default)
def __setattr_submodule(self, obj, name, value):
"""
Generalization of setattr(). __setattr_submodule(object,
"name1.sub1.sub2", value) will set attribute sub2 to value. Will raise
exception if parent modules do not exist.
"""
names = name.split('.')
for i in range(len(names) - 1):
obj = getattr(obj, names[i], None)
if obj is None:
raise Exception(
"Cannot set attribute of non existing submodules: {}\nCheck the order you registered objects for checkpointing.".format(name))
setattr(obj, names[-1], value)
def __hasattr_submodule(self, obj, name):
"""
Generalization of hasattr(). __hasattr_submodule(object,
"name1.sub1.sub2") will return True if submodule sub1 has the attribute
sub2.
"""
names = name.split('.')
for i in range(len(names) - 1):
obj = getattr(obj, names[i], None)
return hasattr(obj, names[-1])
def register(self, *args):
"""Register python objects for checkpointing.
Parameters
----------
args : list of :obj:`str`
Names of python objects to be registered for checkpointing.
"""
for a in args:
if not isinstance(a, str):
raise ValueError(
"The object that should be checkpointed is identified with its name given as a string.")
# if not a in dir(self.calling_module):
if not self.__hasattr_submodule(self.calling_module, a):
raise KeyError(
"The given object '{}' was not found in the current scope.".format(a))
if a in self.checkpoint_objects:
raise KeyError(
"The given object '{}' is already registered for checkpointing.".format(a))
self.checkpoint_objects.append(a)
def unregister(self, *args):
"""Unregister python objects for checkpointing.
Parameters
----------
args : list of :obj:`str`
Names of python objects to be unregistered for checkpointing.
"""
for a in args:
if not isinstance(a, str) or a not in self.checkpoint_objects:
raise KeyError(
"The given object '{}' was not registered for checkpointing yet.".format(a))
self.checkpoint_objects.remove(a)
def get_registered_objects(self):
"""
Returns a list of all object names that are registered for
checkpointing.
"""
return self.checkpoint_objects
def has_checkpoints(self):
"""Check for checkpoints.
Returns
-------
:obj:`bool`
``True`` if any checkpoints exist that match ``checkpoint_id`` and
``checkpoint_path`` otherwise ``False``.
"""
return self.counter > 0
def get_last_checkpoint_index(self):
"""
Returns the last index of the given checkpoint id. Will raise exception
if no checkpoints are found.
"""
if not self.has_checkpoints():
raise Exception(
"No checkpoints found. Cannot return index for last checkpoint.")
return self.counter - 1
def save(self, checkpoint_index=None):
"""
Saves all registered python objects in the given checkpoint directory
using cPickle.
"""
# get attributes of registered objects
checkpoint_data = OrderedDict()
for obj_name in self.checkpoint_objects:
checkpoint_data[obj_name] = self.__getattr_submodule(
self.calling_module, obj_name, None)
if checkpoint_index is None:
checkpoint_index = self.counter
filename = os.path.join(
self.checkpoint_dir, "{}.checkpoint".format(checkpoint_index))
tmpname = filename + ".__tmp__"
with open(tmpname, "wb") as checkpoint_file:
pickle.dump(checkpoint_data, checkpoint_file, -1)
os.rename(tmpname, filename)
def load(self, checkpoint_index=None):
"""
Loads the python objects using (c)Pickle and sets them in the calling
module.
Parameters
----------
checkpoint_index : :obj:`int`, optional
If not given, the last ``checkpoint_index`` will be used.
"""
if checkpoint_index is None:
checkpoint_index = self.get_last_checkpoint_index()
filename = os.path.join(
self.checkpoint_dir, "{}.checkpoint".format(checkpoint_index))
with open(filename, "rb") as f:
checkpoint_data = pickle.load(f)
for key in checkpoint_data:
self.__setattr_submodule(
self.calling_module, key, checkpoint_data[key])
self.checkpoint_objects.append(key)
def __signal_handler(self, signum, frame): # pylint: disable=unused-argument
"""
Will be called when a registered signal was sent.
"""
self.save()
exit(signum)
def read_signals(self):
"""
Reads all registered signals from the signal file and returns a list of
integers.
"""
if not os.path.isfile(os.path.join(self.checkpoint_dir, "signals")):
return []
with open(os.path.join(self.checkpoint_dir, "signals"), "r") as signal_file:
signals = signal_file.readline().strip().split()
signals = [int(i)
for i in signals] # will raise exception if signal file contains invalid entries
return signals
def __write_signal(self, signum=None):
"""Writes the given signal integer signum to the signal file.
"""
signum = int(signum)
if not is_valid_type(signum, int):
raise ValueError("Signal must be an integer number.")
signals = self.read_signals()
if signum not in signals:
signals.append(signum)
signals = " ".join(str(i) for i in signals)
with open(os.path.join(self.checkpoint_dir, "signals"), "w") as signal_file:
signal_file.write(signals)
def register_signal(self, signum=None):
"""Register a signal that will trigger the signal handler.
Parameters
----------
signum : :obj:`int`
Signal to be registered.
"""
if not is_valid_type(signum, int):
raise ValueError("Signal must be an integer number.")
if signum in self.checkpoint_signals:
raise KeyError(
"The signal {} is already registered for checkpointing.".format(signum))
signal.signal(signum, self.__signal_handler)
self.checkpoint_signals.append(signum)
self.__write_signal(signum)
|
gpl-3.0
|
[
3,
199,
3,
1898,
334,
35,
9,
6171,
13,
14982,
710,
31334,
1322,
5158,
2199,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
31334,
1322,
5158,
14,
199,
3,
199,
3,
31334,
1322,
5158,
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,
31334,
1322,
5158,
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,
504,
5055,
492,
8773,
199,
646,
6485,
199,
646,
747,
199,
646,
295,
199,
646,
4673,
199,
504,
9455,
2915,
676,
68,
14,
1208,
492,
365,
63,
1078,
63,
466,
199,
199,
893,
26,
272,
492,
17572,
465,
5927,
199,
2590,
3545,
26,
272,
492,
5927,
421,
199,
3,
1448,
1856,
6792,
2670,
1403,
316,
367,
31334,
1322,
5158,
199,
533,
2670,
1403,
26,
339,
408,
22005,
7252,
334,
19332,
436,
3575,
680,
339,
3897,
272,
4143,
272,
9997,
63,
344,
520,
520,
1113,
1705,
495,
64,
267,
437,
1059,
21119,
282,
2488,
9997,
14,
272,
9997,
63,
515,
520,
520,
1113,
1705,
495,
3559,
2716,
267,
6912,
367,
7664,
436,
3575,
314,
9997,
14,
267,
982,
440,
1627,
12,
314,
445,
16698,
365,
1202,
14,
339,
408,
339,
347,
636,
826,
721,
277,
12,
9997,
63,
344,
29,
403,
12,
9997,
63,
515,
628,
30946,
267,
327,
1104,
340,
9997,
63,
344,
365,
1686,
334,
2118,
2040,
282,
13,
90,
437,
13,
58,
378,
13,
25,
485,
446,
9,
267,
340,
440,
1228,
8,
10109,
63,
344,
12,
620,
9,
503,
2155,
8,
355,
295,
14,
2014,
8,
82,
2,
4735,
65,
13,
6353,
13,
58,
16,
13,
25,
63,
16185,
61,
3471,
1733,
8,
10109,
63,
344,
2298,
288,
746,
1722,
480,
3364,
9997,
1305,
2685,
398,
340,
440,
1228,
8,
10109,
63,
515,
12,
620,
304,
288,
746,
1722,
480,
3364,
9997,
931,
2685,
398,
291,
14,
10109,
63,
1462,
275,
942,
267,
291,
14,
10109,
63,
10458,
275,
942,
267,
289,
5682,
275,
6485,
14,
2340,
3430,
17,
61,
267,
291,
14,
25566,
63,
578,
275,
6485,
14,
362,
578,
8,
20095,
59,
16,
566,
398,
9997,
63,
515,
275,
747,
14,
515,
14,
904,
8,
10109,
63,
515,
12,
9997,
63,
344,
9,
267,
291,
14,
10109,
63,
694,
275,
747,
14,
515,
14,
11091,
8,
10109,
63,
515,
9,
398,
340,
440,
747,
14,
515,
14,
6027,
8,
277,
14,
10109,
63,
694,
304,
288,
747,
14,
8347,
8,
277,
14,
10109,
63,
694,
9,
398,
327,
1678,
9997,
7055,
267,
291,
14,
5337,
275,
378,
267,
1830,
747,
14,
515,
14,
6292,
8,
736,
14,
515,
14,
904,
8,
355,
291,
14,
10109,
63,
694,
12,
11491,
14,
10109,
1674,
908,
8,
277,
14,
5337,
15206,
288,
291,
14,
5337,
847,
413,
398,
327,
4205,
10166,
267,
367,
2070,
453,
315,
291,
14,
739,
63,
10458,
837,
288,
291,
14,
2683,
63,
4653,
8,
1037,
453,
9,
339,
347,
636,
5675,
63,
16229,
8,
277,
12,
1559,
12,
536,
12,
849,
304,
267,
408,
267,
1696,
2072,
402,
2519,
1252,
636,
5675,
63,
16229,
8,
785,
12,
267,
298,
354,
17,
14,
954,
17,
14,
954,
18,
401,
488,
9,
911,
372,
2225,
1007,
18,
340,
2808,
267,
4257,
488,
14,
398,
408,
267,
1561,
275,
536,
14,
1294,
7563,
398,
367,
284,
315,
1425,
8,
552,
8,
1247,
9,
446,
413,
304,
288,
1559,
275,
2519,
8,
1113,
12,
1561,
59,
73,
467,
849,
9,
398,
372,
2519,
8,
1113,
12,
1561,
1988,
17,
467,
849,
9,
339,
347,
636,
10202,
63,
16229,
8,
277,
12,
1559,
12,
536,
12,
574,
304,
267,
408,
267,
1696,
2072,
402,
5371,
1252,
636,
10202,
63,
16229,
8,
785,
12,
267,
298,
354,
17,
14,
954,
17,
14,
954,
18,
401,
574,
9,
911,
663,
2225,
1007,
18,
370,
574,
14,
12823,
746,
267,
1919,
340,
1676,
4621,
886,
440,
2187,
14,
398,
408,
267,
1561,
275,
536,
14,
1294,
7563,
267,
367,
284,
315,
1425,
8,
552,
8,
1247,
9,
446,
413,
304,
288,
1559,
275,
2519,
8,
1113,
12,
1561,
59,
73,
467,
488,
9,
398,
340,
1559,
365,
488,
26,
288,
746,
2186,
8,
355,
298,
6612,
663,
2225,
402,
2222,
3411,
29449,
26,
22902,
78,
1799,
314,
1865,
1265,
7264,
2251,
367,
9997,
316,
15848,
908,
8,
354,
430,
267,
5371,
8,
1113,
12,
1561,
1988,
17,
467,
574,
9,
339,
347,
636,
11161,
63,
16229,
8,
277,
12,
1559,
12,
536,
304,
267,
408,
267,
1696,
2072,
402,
2688,
1252,
636,
11161,
63,
16229,
8,
785,
12,
267,
298,
354,
17,
14,
954,
17,
14,
954,
18,
531,
911,
372,
715,
340,
22988,
1007,
17,
965,
314,
2225,
267,
1007,
18,
14,
398,
408,
267,
1561,
275,
536,
14,
1294,
7563,
267,
367,
284,
315,
1425,
8,
552,
8,
1247,
9,
446,
413,
304,
288,
1559,
275,
2519,
8,
1113,
12,
1561,
59,
73,
467,
488,
9,
398,
372,
2688,
8,
1113,
12,
1561,
1988,
17,
566,
339,
347,
2274,
8,
277,
12,
627,
589,
304,
267,
408,
7099,
2366,
2251,
367,
9997,
316,
14,
398,
3897,
267,
4143,
267,
1249,
520,
769,
402,
520,
1113,
1705,
495,
64,
288,
23923,
402,
2366,
2251,
370,
506,
7264,
367,
9997,
316,
14,
398,
408,
267,
367,
282,
315,
1249,
26,
288,
340,
440,
1228,
8,
65,
12,
620,
304,
355,
746,
1722,
8,
490,
298,
1918,
909,
626,
1077,
506,
1104,
555,
9082,
365,
15836,
543,
2399,
536,
1627,
465,
282
] |
[
199,
3,
1898,
334,
35,
9,
6171,
13,
14982,
710,
31334,
1322,
5158,
2199,
199,
3,
199,
3,
961,
570,
365,
1777,
402,
31334,
1322,
5158,
14,
199,
3,
199,
3,
31334,
1322,
5158,
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,
31334,
1322,
5158,
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,
504,
5055,
492,
8773,
199,
646,
6485,
199,
646,
747,
199,
646,
295,
199,
646,
4673,
199,
504,
9455,
2915,
676,
68,
14,
1208,
492,
365,
63,
1078,
63,
466,
199,
199,
893,
26,
272,
492,
17572,
465,
5927,
199,
2590,
3545,
26,
272,
492,
5927,
421,
199,
3,
1448,
1856,
6792,
2670,
1403,
316,
367,
31334,
1322,
5158,
199,
533,
2670,
1403,
26,
339,
408,
22005,
7252,
334,
19332,
436,
3575,
680,
339,
3897,
272,
4143,
272,
9997,
63,
344,
520,
520,
1113,
1705,
495,
64,
267,
437,
1059,
21119,
282,
2488,
9997,
14,
272,
9997,
63,
515,
520,
520,
1113,
1705,
495,
3559,
2716,
267,
6912,
367,
7664,
436,
3575,
314,
9997,
14,
267,
982,
440,
1627,
12,
314,
445,
16698,
365,
1202,
14,
339,
408,
339,
347,
636,
826,
721,
277,
12,
9997,
63,
344,
29,
403,
12,
9997,
63,
515,
628,
30946,
267,
327,
1104,
340,
9997,
63,
344,
365,
1686,
334,
2118,
2040,
282,
13,
90,
437,
13,
58,
378,
13,
25,
485,
446,
9,
267,
340,
440,
1228,
8,
10109,
63,
344,
12,
620,
9,
503,
2155,
8,
355,
295,
14,
2014,
8,
82,
2,
4735,
65,
13,
6353,
13,
58,
16,
13,
25,
63,
16185,
61,
3471,
1733,
8,
10109,
63,
344,
2298,
288,
746,
1722,
480,
3364,
9997,
1305,
2685,
398,
340,
440,
1228,
8,
10109,
63,
515,
12,
620,
304,
288,
746,
1722,
480,
3364,
9997,
931,
2685,
398,
291,
14,
10109,
63,
1462,
275,
942,
267,
291,
14,
10109,
63,
10458,
275,
942,
267,
289,
5682,
275,
6485,
14,
2340,
3430,
17,
61,
267,
291,
14,
25566,
63,
578,
275,
6485,
14,
362,
578,
8,
20095,
59,
16,
566,
398,
9997,
63,
515,
275,
747,
14,
515,
14,
904,
8,
10109,
63,
515,
12,
9997,
63,
344,
9,
267,
291,
14,
10109,
63,
694,
275,
747,
14,
515,
14,
11091,
8,
10109,
63,
515,
9,
398,
340,
440,
747,
14,
515,
14,
6027,
8,
277,
14,
10109,
63,
694,
304,
288,
747,
14,
8347,
8,
277,
14,
10109,
63,
694,
9,
398,
327,
1678,
9997,
7055,
267,
291,
14,
5337,
275,
378,
267,
1830,
747,
14,
515,
14,
6292,
8,
736,
14,
515,
14,
904,
8,
355,
291,
14,
10109,
63,
694,
12,
11491,
14,
10109,
1674,
908,
8,
277,
14,
5337,
15206,
288,
291,
14,
5337,
847,
413,
398,
327,
4205,
10166,
267,
367,
2070,
453,
315,
291,
14,
739,
63,
10458,
837,
288,
291,
14,
2683,
63,
4653,
8,
1037,
453,
9,
339,
347,
636,
5675,
63,
16229,
8,
277,
12,
1559,
12,
536,
12,
849,
304,
267,
408,
267,
1696,
2072,
402,
2519,
1252,
636,
5675,
63,
16229,
8,
785,
12,
267,
298,
354,
17,
14,
954,
17,
14,
954,
18,
401,
488,
9,
911,
372,
2225,
1007,
18,
340,
2808,
267,
4257,
488,
14,
398,
408,
267,
1561,
275,
536,
14,
1294,
7563,
398,
367,
284,
315,
1425,
8,
552,
8,
1247,
9,
446,
413,
304,
288,
1559,
275,
2519,
8,
1113,
12,
1561,
59,
73,
467,
849,
9,
398,
372,
2519,
8,
1113,
12,
1561,
1988,
17,
467,
849,
9,
339,
347,
636,
10202,
63,
16229,
8,
277,
12,
1559,
12,
536,
12,
574,
304,
267,
408,
267,
1696,
2072,
402,
5371,
1252,
636,
10202,
63,
16229,
8,
785,
12,
267,
298,
354,
17,
14,
954,
17,
14,
954,
18,
401,
574,
9,
911,
663,
2225,
1007,
18,
370,
574,
14,
12823,
746,
267,
1919,
340,
1676,
4621,
886,
440,
2187,
14,
398,
408,
267,
1561,
275,
536,
14,
1294,
7563,
267,
367,
284,
315,
1425,
8,
552,
8,
1247,
9,
446,
413,
304,
288,
1559,
275,
2519,
8,
1113,
12,
1561,
59,
73,
467,
488,
9,
398,
340,
1559,
365,
488,
26,
288,
746,
2186,
8,
355,
298,
6612,
663,
2225,
402,
2222,
3411,
29449,
26,
22902,
78,
1799,
314,
1865,
1265,
7264,
2251,
367,
9997,
316,
15848,
908,
8,
354,
430,
267,
5371,
8,
1113,
12,
1561,
1988,
17,
467,
574,
9,
339,
347,
636,
11161,
63,
16229,
8,
277,
12,
1559,
12,
536,
304,
267,
408,
267,
1696,
2072,
402,
2688,
1252,
636,
11161,
63,
16229,
8,
785,
12,
267,
298,
354,
17,
14,
954,
17,
14,
954,
18,
531,
911,
372,
715,
340,
22988,
1007,
17,
965,
314,
2225,
267,
1007,
18,
14,
398,
408,
267,
1561,
275,
536,
14,
1294,
7563,
267,
367,
284,
315,
1425,
8,
552,
8,
1247,
9,
446,
413,
304,
288,
1559,
275,
2519,
8,
1113,
12,
1561,
59,
73,
467,
488,
9,
398,
372,
2688,
8,
1113,
12,
1561,
1988,
17,
566,
339,
347,
2274,
8,
277,
12,
627,
589,
304,
267,
408,
7099,
2366,
2251,
367,
9997,
316,
14,
398,
3897,
267,
4143,
267,
1249,
520,
769,
402,
520,
1113,
1705,
495,
64,
288,
23923,
402,
2366,
2251,
370,
506,
7264,
367,
9997,
316,
14,
398,
408,
267,
367,
282,
315,
1249,
26,
288,
340,
440,
1228,
8,
65,
12,
620,
304,
355,
746,
1722,
8,
490,
298,
1918,
909,
626,
1077,
506,
1104,
555,
9082,
365,
15836,
543,
2399,
536,
1627,
465,
282,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
theshadowx/enigma2
|
tests/events.py
|
31
|
1652
|
import time
import tests
recorded_events = [ ]
def event(self, name, args, kwargs):
global recorded_events
print "*EVENT*", time.time(), self, name, args, kwargs
recorded_events.append((time.time(), self, name, args, kwargs))
def eventfnc(f):
name = f.__name__
def wrapper(self, *args, **kwargs):
event(self, name, args, kwargs)
return f(self, *args, **kwargs)
return wrapper
def get_events():
global recorded_events
r = recorded_events
recorded_events = [ ]
return r
def start_log():
global base_time
base_time = time.time()
def end_log(test_name):
global base_time
results = ""
for (t, self, method, args, kwargs) in get_events():
results += "%s T+%f: %s::%s(%s, *%s, *%s)\n" % (time.ctime(t), t - base_time, str(self.__class__), method, self, args, kwargs)
expected = None
try:
f = open(test_name + ".results", "rb")
expected = f.read()
f.close()
except:
print "NO TEST RESULT FOUND, creating new"
f = open(test_name + ".new_results", "wb")
f.write(results)
f.close()
print results
if expected is not None:
print "expected:"
if expected != results:
open(test_name + ".bogus_results", "wb").write(results)
raise tests.TestError("test data does not match")
else:
print "test compared ok"
else:
print "no test data to compare with."
def log(fnc, base_time = 0, test_name = "test", *args, **kwargs):
import fake_time
fake_time.setTime(base_time)
start_log()
try:
fnc(*args, **kwargs)
event(None, "test_completed", [], {"test_name": test_name})
except tests.TestError,c:
event(None, "test_failed", [], {"test_name": test_name, "reason": str(c)})
end_log(test_name)
|
gpl-2.0
|
[
646,
900,
199,
646,
2295,
199,
199,
264,
15402,
63,
4368,
275,
359,
1622,
199,
199,
318,
1566,
8,
277,
12,
536,
12,
1249,
12,
2074,
304,
199,
198,
2966,
18894,
63,
4368,
199,
198,
1361,
8969,
8193,
14421,
900,
14,
521,
1062,
291,
12,
536,
12,
1249,
12,
2074,
199,
198,
264,
15402,
63,
4368,
14,
740,
1332,
521,
14,
521,
1062,
291,
12,
536,
12,
1249,
12,
2074,
430,
199,
199,
318,
1566,
2324,
67,
8,
70,
304,
199,
198,
354,
275,
289,
855,
354,
363,
199,
198,
318,
4975,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
507,
198,
1430,
8,
277,
12,
536,
12,
1249,
12,
2074,
9,
507,
198,
1107,
289,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
199,
198,
1107,
4975,
199,
199,
318,
664,
63,
4368,
837,
199,
198,
2966,
18894,
63,
4368,
199,
198,
82,
275,
18894,
63,
4368,
199,
198,
264,
15402,
63,
4368,
275,
359,
1622,
199,
198,
1107,
519,
199,
199,
318,
1343,
63,
793,
837,
199,
198,
2966,
1300,
63,
521,
199,
198,
1095,
63,
521,
275,
900,
14,
521,
342,
199,
199,
318,
1284,
63,
793,
8,
396,
63,
354,
304,
199,
198,
2966,
1300,
63,
521,
8299,
198,
2604,
275,
3087,
8299,
198,
509,
334,
84,
12,
291,
12,
1083,
12,
1249,
12,
2074,
9,
315,
664,
63,
4368,
837,
507,
198,
2604,
847,
2071,
83,
377,
25389,
70,
26,
450,
83,
447,
5,
83,
4042,
83,
12,
627,
5,
83,
12,
627,
5,
83,
2862,
78,
2,
221,
450,
334,
521,
14,
20691,
8,
84,
395,
307,
446,
1300,
63,
521,
12,
620,
8,
277,
855,
533,
10139,
1083,
12,
291,
12,
1249,
12,
2074,
9,
421,
198,
2062,
275,
488,
421,
198,
893,
26,
507,
198,
70,
275,
1551,
8,
396,
63,
354,
435,
3680,
2604,
401,
298,
4848,
531,
507,
198,
2062,
275,
289,
14,
739,
342,
507,
198,
70,
14,
1600,
342,
199,
198,
2590,
26,
507,
198,
1361,
298,
2826,
7393,
20668,
481,
47,
6131,
12,
6425,
892,
2,
507,
198,
70,
275,
1551,
8,
396,
63,
354,
435,
3680,
1222,
63,
2604,
401,
298,
6603,
531,
507,
198,
70,
14,
952,
8,
2604,
9,
507,
198,
70,
14,
1600,
342,
8299,
198,
1361,
2058,
8299,
198,
692,
1420,
365,
440,
488,
26,
507,
198,
1361,
298,
2062,
5424,
507,
198,
692,
1420,
1137,
2058,
26,
686,
198,
1490,
8,
396,
63,
354,
435,
3680,
18665,
63,
2604,
401,
298,
6603,
3471,
952,
8,
2604,
9,
686,
198,
3730,
2295,
14,
774,
547,
480,
396,
666,
1630,
440,
1336,
531,
507,
198,
2836,
26,
686,
198,
1361,
298,
396,
13524,
4112,
2,
199,
198,
2836,
26,
507,
198,
1361,
298,
889,
511,
666,
370,
6540,
543,
2122,
199,
199,
318,
943,
8,
2324,
67,
12,
1300,
63,
521,
275,
378,
12,
511,
63,
354,
275,
298,
396,
401,
627,
589,
12,
1011,
958,
304,
199,
198,
646,
4026,
63,
521,
199,
198,
3183,
63,
521,
14,
409,
1366,
8,
1095,
63,
521,
9,
421,
198,
928,
63,
793,
342,
199,
198,
893,
26,
507,
198,
2324,
67,
2031,
589,
12,
1011,
958,
9,
507,
198,
1430,
8,
403,
12,
298,
396,
63,
12634,
401,
990,
2420,
396,
63,
354,
582,
511,
63,
354,
1552,
199,
198,
2590,
2295,
14,
774,
547,
12,
67,
26,
507,
198,
1430,
8,
403,
12,
298,
396,
63,
4892,
401,
990,
2420,
396,
63,
354,
582,
511,
63,
354,
12,
298,
5764,
582,
620,
8,
67,
11466,
199,
198,
500,
63,
793,
8,
396,
63,
354,
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
] |
[
900,
199,
646,
2295,
199,
199,
264,
15402,
63,
4368,
275,
359,
1622,
199,
199,
318,
1566,
8,
277,
12,
536,
12,
1249,
12,
2074,
304,
199,
198,
2966,
18894,
63,
4368,
199,
198,
1361,
8969,
8193,
14421,
900,
14,
521,
1062,
291,
12,
536,
12,
1249,
12,
2074,
199,
198,
264,
15402,
63,
4368,
14,
740,
1332,
521,
14,
521,
1062,
291,
12,
536,
12,
1249,
12,
2074,
430,
199,
199,
318,
1566,
2324,
67,
8,
70,
304,
199,
198,
354,
275,
289,
855,
354,
363,
199,
198,
318,
4975,
8,
277,
12,
627,
589,
12,
1011,
958,
304,
507,
198,
1430,
8,
277,
12,
536,
12,
1249,
12,
2074,
9,
507,
198,
1107,
289,
8,
277,
12,
627,
589,
12,
1011,
958,
9,
199,
198,
1107,
4975,
199,
199,
318,
664,
63,
4368,
837,
199,
198,
2966,
18894,
63,
4368,
199,
198,
82,
275,
18894,
63,
4368,
199,
198,
264,
15402,
63,
4368,
275,
359,
1622,
199,
198,
1107,
519,
199,
199,
318,
1343,
63,
793,
837,
199,
198,
2966,
1300,
63,
521,
199,
198,
1095,
63,
521,
275,
900,
14,
521,
342,
199,
199,
318,
1284,
63,
793,
8,
396,
63,
354,
304,
199,
198,
2966,
1300,
63,
521,
8299,
198,
2604,
275,
3087,
8299,
198,
509,
334,
84,
12,
291,
12,
1083,
12,
1249,
12,
2074,
9,
315,
664,
63,
4368,
837,
507,
198,
2604,
847,
2071,
83,
377,
25389,
70,
26,
450,
83,
447,
5,
83,
4042,
83,
12,
627,
5,
83,
12,
627,
5,
83,
2862,
78,
2,
221,
450,
334,
521,
14,
20691,
8,
84,
395,
307,
446,
1300,
63,
521,
12,
620,
8,
277,
855,
533,
10139,
1083,
12,
291,
12,
1249,
12,
2074,
9,
421,
198,
2062,
275,
488,
421,
198,
893,
26,
507,
198,
70,
275,
1551,
8,
396,
63,
354,
435,
3680,
2604,
401,
298,
4848,
531,
507,
198,
2062,
275,
289,
14,
739,
342,
507,
198,
70,
14,
1600,
342,
199,
198,
2590,
26,
507,
198,
1361,
298,
2826,
7393,
20668,
481,
47,
6131,
12,
6425,
892,
2,
507,
198,
70,
275,
1551,
8,
396,
63,
354,
435,
3680,
1222,
63,
2604,
401,
298,
6603,
531,
507,
198,
70,
14,
952,
8,
2604,
9,
507,
198,
70,
14,
1600,
342,
8299,
198,
1361,
2058,
8299,
198,
692,
1420,
365,
440,
488,
26,
507,
198,
1361,
298,
2062,
5424,
507,
198,
692,
1420,
1137,
2058,
26,
686,
198,
1490,
8,
396,
63,
354,
435,
3680,
18665,
63,
2604,
401,
298,
6603,
3471,
952,
8,
2604,
9,
686,
198,
3730,
2295,
14,
774,
547,
480,
396,
666,
1630,
440,
1336,
531,
507,
198,
2836,
26,
686,
198,
1361,
298,
396,
13524,
4112,
2,
199,
198,
2836,
26,
507,
198,
1361,
298,
889,
511,
666,
370,
6540,
543,
2122,
199,
199,
318,
943,
8,
2324,
67,
12,
1300,
63,
521,
275,
378,
12,
511,
63,
354,
275,
298,
396,
401,
627,
589,
12,
1011,
958,
304,
199,
198,
646,
4026,
63,
521,
199,
198,
3183,
63,
521,
14,
409,
1366,
8,
1095,
63,
521,
9,
421,
198,
928,
63,
793,
342,
199,
198,
893,
26,
507,
198,
2324,
67,
2031,
589,
12,
1011,
958,
9,
507,
198,
1430,
8,
403,
12,
298,
396,
63,
12634,
401,
990,
2420,
396,
63,
354,
582,
511,
63,
354,
1552,
199,
198,
2590,
2295,
14,
774,
547,
12,
67,
26,
507,
198,
1430,
8,
403,
12,
298,
396,
63,
4892,
401,
990,
2420,
396,
63,
354,
582,
511,
63,
354,
12,
298,
5764,
582,
620,
8,
67,
11466,
199,
198,
500,
63,
793,
8,
396,
63,
354,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
mattgrogan/ledmatrix
|
ledmatrix/components/viewport.py
|
1
|
1050
|
class Viewport_Mixin(object):
"""
Mixin to help move around the image
"""
def update(self):
"""
Call update to get fresh data.
"""
pass
def reset(self):
""" Reset the viewport """
self._position = (0, 0)
def set_position(self, xy):
self._position = xy
def move_left(self):
x, y = self._position
self.set_position((x + 1, y))
def crop(self, wh):
""" Crop at width and height """
w, h = wh
(left, top) = self._position
right = left + w
bottom = top + h
im = self.image.crop(box=(left, top, right, bottom))
im.load() # Force the crop
return im
@property
def is_finished(self):
x, y = self._position
return x >= self.image.size[0]
class Viewport_NoScroll_Mixin(Viewport_Mixin):
"""
This mixin provides the Viewport interface but does not scroll the image.
"""
def reset(self):
self._position = (0, 0)
def set_position(self, xy):
pass
def move_left(self):
pass
@property
def is_finished(self):
return True
|
mit
|
[
533,
10935,
719,
63,
4256,
8,
785,
304,
523,
408,
523,
28438,
370,
1720,
4057,
6818,
314,
1834,
523,
408,
819,
347,
1678,
8,
277,
304,
272,
408,
272,
6523,
1678,
370,
664,
17480,
666,
14,
272,
408,
339,
986,
819,
347,
5305,
8,
277,
304,
272,
408,
15510,
314,
2455,
719,
408,
339,
291,
423,
3124,
275,
334,
16,
12,
378,
9,
819,
347,
663,
63,
3124,
8,
277,
12,
13222,
304,
339,
291,
423,
3124,
275,
13222,
819,
347,
4057,
63,
3039,
8,
277,
304,
339,
671,
12,
612,
275,
291,
423,
3124,
272,
291,
14,
409,
63,
3124,
1332,
88,
435,
413,
12,
612,
430,
819,
347,
18366,
8,
277,
12,
704,
304,
272,
408,
445,
2675,
737,
3462,
436,
4569,
408,
339,
336,
12,
394,
275,
704,
339,
334,
3039,
12,
2746,
9,
275,
291,
423,
3124,
272,
2451,
275,
3602,
435,
336,
272,
9048,
275,
2746,
435,
394,
339,
3416,
275,
291,
14,
1569,
14,
15816,
8,
1977,
2687,
3039,
12,
2746,
12,
2451,
12,
9048,
430,
272,
3416,
14,
912,
342,
221,
327,
18771,
314,
18366,
272,
372,
3416,
819,
768,
1829,
523,
347,
365,
63,
8669,
8,
277,
304,
339,
671,
12,
612,
275,
291,
423,
3124,
272,
372,
671,
2356,
291,
14,
1569,
14,
890,
59,
16,
61,
421,
199,
533,
10935,
719,
63,
1944,
13127,
63,
4256,
8,
2768,
719,
63,
4256,
304,
523,
408,
523,
961,
20048,
6571,
314,
10935,
719,
3217,
1325,
1630,
440,
13704,
314,
1834,
14,
523,
408,
819,
347,
5305,
8,
277,
304,
272,
291,
423,
3124,
275,
334,
16,
12,
378,
9,
819,
347,
663,
63,
3124,
8,
277,
12,
13222,
304,
272,
986,
819,
347,
4057,
63,
3039,
8,
277,
304,
272,
986,
819,
768,
1829,
523,
347,
365,
63,
8669,
8,
277,
304,
272,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
10935,
719,
63,
4256,
8,
785,
304,
523,
408,
523,
28438,
370,
1720,
4057,
6818,
314,
1834,
523,
408,
819,
347,
1678,
8,
277,
304,
272,
408,
272,
6523,
1678,
370,
664,
17480,
666,
14,
272,
408,
339,
986,
819,
347,
5305,
8,
277,
304,
272,
408,
15510,
314,
2455,
719,
408,
339,
291,
423,
3124,
275,
334,
16,
12,
378,
9,
819,
347,
663,
63,
3124,
8,
277,
12,
13222,
304,
339,
291,
423,
3124,
275,
13222,
819,
347,
4057,
63,
3039,
8,
277,
304,
339,
671,
12,
612,
275,
291,
423,
3124,
272,
291,
14,
409,
63,
3124,
1332,
88,
435,
413,
12,
612,
430,
819,
347,
18366,
8,
277,
12,
704,
304,
272,
408,
445,
2675,
737,
3462,
436,
4569,
408,
339,
336,
12,
394,
275,
704,
339,
334,
3039,
12,
2746,
9,
275,
291,
423,
3124,
272,
2451,
275,
3602,
435,
336,
272,
9048,
275,
2746,
435,
394,
339,
3416,
275,
291,
14,
1569,
14,
15816,
8,
1977,
2687,
3039,
12,
2746,
12,
2451,
12,
9048,
430,
272,
3416,
14,
912,
342,
221,
327,
18771,
314,
18366,
272,
372,
3416,
819,
768,
1829,
523,
347,
365,
63,
8669,
8,
277,
304,
339,
671,
12,
612,
275,
291,
423,
3124,
272,
372,
671,
2356,
291,
14,
1569,
14,
890,
59,
16,
61,
421,
199,
533,
10935,
719,
63,
1944,
13127,
63,
4256,
8,
2768,
719,
63,
4256,
304,
523,
408,
523,
961,
20048,
6571,
314,
10935,
719,
3217,
1325,
1630,
440,
13704,
314,
1834,
14,
523,
408,
819,
347,
5305,
8,
277,
304,
272,
291,
423,
3124,
275,
334,
16,
12,
378,
9,
819,
347,
663,
63,
3124,
8,
277,
12,
13222,
304,
272,
986,
819,
347,
4057,
63,
3039,
8,
277,
304,
272,
986,
819,
768,
1829,
523,
347,
365,
63,
8669,
8,
277,
304,
272,
372,
715,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
yqm/sl4a
|
python-build/python-libs/gdata/tests/gdata_tests/apps/migration/service_test.py
|
89
|
2125
|
#!/usr/bin/python
#
# Copyright (C) 2008 Google
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Test for Email Migration service."""
__author__ = 'google-apps-apis@googlegroups.com'
import getpass
import gdata.apps.migration.service
import unittest
domain = ''
admin_email = ''
admin_password = ''
username = ''
MESS="""From: joe@blow.com
To: jane@doe.com
Date: Mon, 29 Sep 2008 20:00:34 -0500 (CDT)
Subject: %s
%s"""
class MigrationTest(unittest.TestCase):
"""Test for the MigrationService."""
def setUp(self):
self.ms = gdata.apps.migration.service.MigrationService(
email=admin_email, password=admin_password, domain=domain)
self.ms.ProgrammaticLogin()
def testImportMail(self):
self.ms.ImportMail(user_name=username,
mail_message=MESS%('Test subject', 'Test body'),
mail_item_properties=['IS_STARRED'],
mail_labels=['Test'])
def testBatch(self):
for i in xrange(1,10):
self.ms.AddBatchEntry(mail_message=MESS%('Test batch %d'%i, 'Test batch'),
mail_item_properties=['IS_INBOX'],
mail_labels=['Test', 'Batch'])
self.ms.SubmitBatch(user_name=username)
if __name__ == '__main__':
print("""Google Apps Email Migration Service Tests
NOTE: Please run these tests only with a test user account.
""")
domain = raw_input('Google Apps domain: ')
admin_email = '%s@%s' % (raw_input('Administrator username: '), domain)
admin_password = getpass.getpass('Administrator password: ')
username = raw_input('Test username: ')
unittest.main()
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
4475,
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,
367,
11426,
12090,
2435,
1041,
421,
199,
363,
2502,
363,
275,
283,
3098,
13,
5181,
13,
12662,
32,
3098,
2634,
14,
957,
7,
421,
199,
646,
18354,
199,
646,
11006,
14,
5181,
14,
8998,
14,
1364,
199,
646,
2882,
421,
199,
2261,
275,
2125,
199,
2113,
63,
2123,
275,
2125,
199,
2113,
63,
2060,
275,
2125,
199,
2473,
275,
2125,
199,
7388,
11916,
2532,
26,
5225,
69,
32,
66,
674,
14,
957,
199,
1378,
26,
1335,
5865,
32,
1117,
69,
14,
957,
199,
2506,
26,
10953,
12,
7349,
428,
1545,
9079,
3388,
26,
383,
26,
1082,
446,
1717,
383,
334,
35,
7438,
9,
199,
13528,
26,
450,
83,
199,
199,
5,
83,
624,
421,
199,
533,
12090,
774,
8,
2796,
14,
1746,
304,
523,
408,
774,
367,
314,
12090,
3167,
1041,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
706,
275,
11006,
14,
5181,
14,
8998,
14,
1364,
14,
9816,
3167,
8,
489,
3031,
29,
2113,
63,
2123,
12,
2505,
29,
2113,
63,
2060,
12,
2881,
29,
2261,
9,
272,
291,
14,
706,
14,
9184,
3889,
8880,
342,
8330,
347,
511,
6295,
13681,
8,
277,
304,
272,
291,
14,
706,
14,
6295,
13681,
8,
751,
63,
354,
29,
2473,
12,
2432,
6016,
63,
1188,
29,
7388,
5,
360,
774,
5420,
297,
283,
774,
2396,
659,
2432,
6016,
63,
1053,
63,
3282,
2968,
1311,
63,
30302,
7387,
995,
2432,
6016,
63,
3512,
2968,
774,
1105,
819,
347,
511,
8842,
8,
277,
304,
272,
367,
284,
315,
4945,
8,
17,
12,
709,
304,
489,
291,
14,
706,
14,
1123,
8842,
3900,
8,
1198,
63,
1188,
29,
7388,
5,
360,
774,
3522,
450,
68,
5956,
73,
12,
283,
774,
3522,
659,
1169,
6016,
63,
1053,
63,
3282,
2968,
1311,
63,
568,
15694,
995,
1169,
6016,
63,
3512,
2968,
774,
297,
283,
8842,
1105,
272,
291,
14,
706,
14,
17187,
8842,
8,
751,
63,
354,
29,
2473,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
870,
4852,
13266,
4693,
83,
11426,
12090,
7591,
6496,
199,
199,
19855,
26,
7754,
1255,
3520,
2295,
1454,
543,
282,
511,
922,
2933,
14,
199,
6141,
523,
2881,
275,
3066,
63,
1210,
360,
13266,
4693,
83,
2881,
26,
5320,
523,
4628,
63,
2123,
275,
1543,
83,
19437,
83,
7,
450,
334,
1773,
63,
1210,
360,
31972,
3434,
26,
17748,
2881,
9,
523,
4628,
63,
2060,
275,
18354,
14,
27481,
360,
31972,
2505,
26,
5320,
523,
3434,
275,
3066,
63,
1210,
360,
774,
3434,
26,
5320,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1548,
199,
3,
199,
3,
1898,
334,
35,
9,
9079,
4475,
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,
367,
11426,
12090,
2435,
1041,
421,
199,
363,
2502,
363,
275,
283,
3098,
13,
5181,
13,
12662,
32,
3098,
2634,
14,
957,
7,
421,
199,
646,
18354,
199,
646,
11006,
14,
5181,
14,
8998,
14,
1364,
199,
646,
2882,
421,
199,
2261,
275,
2125,
199,
2113,
63,
2123,
275,
2125,
199,
2113,
63,
2060,
275,
2125,
199,
2473,
275,
2125,
199,
7388,
11916,
2532,
26,
5225,
69,
32,
66,
674,
14,
957,
199,
1378,
26,
1335,
5865,
32,
1117,
69,
14,
957,
199,
2506,
26,
10953,
12,
7349,
428,
1545,
9079,
3388,
26,
383,
26,
1082,
446,
1717,
383,
334,
35,
7438,
9,
199,
13528,
26,
450,
83,
199,
199,
5,
83,
624,
421,
199,
533,
12090,
774,
8,
2796,
14,
1746,
304,
523,
408,
774,
367,
314,
12090,
3167,
1041,
819,
347,
3613,
8,
277,
304,
272,
291,
14,
706,
275,
11006,
14,
5181,
14,
8998,
14,
1364,
14,
9816,
3167,
8,
489,
3031,
29,
2113,
63,
2123,
12,
2505,
29,
2113,
63,
2060,
12,
2881,
29,
2261,
9,
272,
291,
14,
706,
14,
9184,
3889,
8880,
342,
8330,
347,
511,
6295,
13681,
8,
277,
304,
272,
291,
14,
706,
14,
6295,
13681,
8,
751,
63,
354,
29,
2473,
12,
2432,
6016,
63,
1188,
29,
7388,
5,
360,
774,
5420,
297,
283,
774,
2396,
659,
2432,
6016,
63,
1053,
63,
3282,
2968,
1311,
63,
30302,
7387,
995,
2432,
6016,
63,
3512,
2968,
774,
1105,
819,
347,
511,
8842,
8,
277,
304,
272,
367,
284,
315,
4945,
8,
17,
12,
709,
304,
489,
291,
14,
706,
14,
1123,
8842,
3900,
8,
1198,
63,
1188,
29,
7388,
5,
360,
774,
3522,
450,
68,
5956,
73,
12,
283,
774,
3522,
659,
1169,
6016,
63,
1053,
63,
3282,
2968,
1311,
63,
568,
15694,
995,
1169,
6016,
63,
3512,
2968,
774,
297,
283,
8842,
1105,
272,
291,
14,
706,
14,
17187,
8842,
8,
751,
63,
354,
29,
2473,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
523,
870,
4852,
13266,
4693,
83,
11426,
12090,
7591,
6496,
199,
199,
19855,
26,
7754,
1255,
3520,
2295,
1454,
543,
282,
511,
922,
2933,
14,
199,
6141,
523,
2881,
275,
3066,
63,
1210,
360,
13266,
4693,
83,
2881,
26,
5320,
523,
4628,
63,
2123,
275,
1543,
83,
19437,
83,
7,
450,
334,
1773,
63,
1210,
360,
31972,
3434,
26,
17748,
2881,
9,
523,
4628,
63,
2060,
275,
18354,
14,
27481,
360,
31972,
2505,
26,
5320,
523,
3434,
275,
3066,
63,
1210,
360,
774,
3434,
26,
5320,
523,
2882,
14,
973,
342,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
drogenlied/qudi
|
core/util/network.py
|
4
|
1048
|
# -*- coding: utf-8 -*-
"""
Check if something is a rpyc remote object and transfer it
Qudi 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.
Qudi 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 Qudi. If not, see <http://www.gnu.org/licenses/>.
Copyright (c) the Qudi Developers. See the COPYRIGHT.txt file at the
top-level directory of this distribution and at <https://github.com/Ulm-IQO/qudi/>
"""
import rpyc.core.netref
import rpyc.utils.classic
def netobtain(obj):
"""
"""
if isinstance(obj, rpyc.core.netref.BaseNetref):
return rpyc.utils.classic.obtain(obj)
else:
return obj
|
gpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
1799,
340,
6020,
365,
282,
519,
11357,
3982,
909,
436,
9307,
652,
199,
199,
2371,
328,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2371,
328,
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,
5843,
328,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
7384,
334,
67,
9,
314,
5843,
328,
23493,
14,
1666,
314,
5877,
14,
2424,
570,
737,
314,
199,
2119,
13,
1896,
2082,
402,
642,
4084,
436,
737,
665,
2859,
921,
5031,
14,
957,
15,
53,
14344,
13,
23559,
47,
15,
392,
328,
3133,
199,
624,
199,
199,
646,
519,
11357,
14,
1018,
14,
846,
1121,
199,
646,
519,
11357,
14,
1208,
14,
25140,
199,
199,
318,
1851,
2873,
877,
8,
1113,
304,
272,
408,
272,
408,
272,
340,
1228,
8,
1113,
12,
519,
11357,
14,
1018,
14,
846,
1121,
14,
1563,
2480,
1121,
304,
267,
372,
519,
11357,
14,
1208,
14,
25140,
14,
2873,
877,
8,
1113,
9,
272,
587,
26,
267,
372,
1559,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
624,
199,
1799,
340,
6020,
365,
282,
519,
11357,
3982,
909,
436,
9307,
652,
199,
199,
2371,
328,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
390,
1334,
314,
2895,
402,
314,
1664,
1696,
1684,
844,
465,
3267,
701,
199,
1589,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
844,
12,
503,
199,
8,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
199,
2371,
328,
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,
5843,
328,
14,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
199,
7384,
334,
67,
9,
314,
5843,
328,
23493,
14,
1666,
314,
5877,
14,
2424,
570,
737,
314,
199,
2119,
13,
1896,
2082,
402,
642,
4084,
436,
737,
665,
2859,
921,
5031,
14,
957,
15,
53,
14344,
13,
23559,
47,
15,
392,
328,
3133,
199,
624,
199,
199,
646,
519,
11357,
14,
1018,
14,
846,
1121,
199,
646,
519,
11357,
14,
1208,
14,
25140,
199,
199,
318,
1851,
2873,
877,
8,
1113,
304,
272,
408,
272,
408,
272,
340,
1228,
8,
1113,
12,
519,
11357,
14,
1018,
14,
846,
1121,
14,
1563,
2480,
1121,
304,
267,
372,
519,
11357,
14,
1208,
14,
25140,
14,
2873,
877,
8,
1113,
9,
272,
587,
26,
267,
372,
1559,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
the-dalee/gnome-2048
|
gui/controllers/theme_selection_controller.py
|
1
|
3718
|
from gi.repository import Gtk
import os
from properties import Directories, Properties
from model.themes import ThemeAttributes
class ThemeSelectionController(object):
def __init__(self):
self._builder = Gtk.Builder()
glade_file = os.path.join(Directories.APP_GLADES,
"theme_selection.glade")
self._builder.set_translation_domain(Properties.PACKAGE_NAME)
self._builder.add_from_file(glade_file)
self.window = self._builder.get_object("theme_selection_window")
self.theme_store = self._builder.get_object("theme_selection_store")
self.theme_selection = self._builder.get_object("treeview-selection")
self.themes = self.get_theme_dictionary()
self.theme_changed_observers = list()
self.theme_descr = self._builder.get_object("theme_description_label")
handlers = {
"cursor_changed": self.cursor_changed,
"close_button_clicked": self.close
}
self._builder.connect_signals(handlers)
def get_theme_dictionary(self):
global_themes = list()
user_themes = list()
try:
global_themes = [self.get_theme_attributes(os.path.join(Directories.APP_THEMES, name))
for name in os.listdir(Directories.APP_THEMES)
if os.path.isdir(
os.path.join(Directories.APP_THEMES, name))]
except Exception as e:
print(e)
global_themes = dict()
try:
user_themes = [self.get_theme_attributes(os.path.join(Directories.USER_THEMES, name))
for name in os.listdir(Directories.USER_THEMES)
if os.path.isdir(
os.path.join(Directories.USER_THEMES, name))]
except Exception as e:
print(e)
user_themes = dict()
return global_themes + user_themes
def get_theme_attributes(self, theme_path):
attributes = ThemeAttributes()
attributes.path = theme_path
json_path = os.path.join(theme_path, "attributes.json")
with open(json_path, 'r') as file:
json_string = file.read()
attributes.read_json_string(json_string)
return attributes
def show(self, cur_theme):
self.theme_store.clear()
for theme in self.themes:
iter = self.theme_store.append((theme.name, theme.path, theme))
if theme.path == cur_theme:
self.display_theme_info(theme)
self.theme_selection.select_iter(iter)
self.window.run()
self.window.hide()
def close(self, button):
self.window.hide()
def cursor_changed(self, tree_view):
(model, iter) = tree_view.get_selection().get_selected()
value = model.get_value(iter, 1)
theme = model.get_value(iter, 2)
self.display_theme_info(theme)
self.notify_theme_changed(value)
def display_theme_info(self, theme):
descr_text = ""
if theme.description:
descr_text = descr_text + theme.description + "\n\n";
if theme.license:
descr_text = descr_text + theme.license + "\n\n";
if theme.copyright:
descr_text = descr_text + theme.copyright;
self.theme_descr.set_text(descr_text)
def register_theme_changed(self, observer):
self.theme_changed_observers.append(observer)
def notify_theme_changed(self, file):
for o in self.theme_changed_observers:
o.theme_changed(file)
|
mit
|
[
504,
18895,
14,
8421,
492,
11424,
199,
646,
747,
199,
504,
4382,
492,
25596,
4253,
12,
19329,
199,
504,
1402,
14,
23900,
492,
23978,
5379,
421,
199,
533,
23978,
7713,
7506,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
5649,
275,
11424,
14,
6437,
342,
267,
486,
17236,
63,
493,
275,
747,
14,
515,
14,
904,
8,
13752,
14,
7121,
63,
2226,
1554,
654,
12,
3303,
298,
7915,
63,
5592,
14,
31589,
531,
267,
291,
423,
5649,
14,
409,
63,
6893,
63,
2261,
8,
8516,
14,
19265,
63,
2339,
9,
267,
291,
423,
5649,
14,
525,
63,
504,
63,
493,
8,
31589,
63,
493,
9,
2234,
267,
291,
14,
3806,
275,
291,
423,
5649,
14,
362,
63,
785,
480,
7915,
63,
5592,
63,
3806,
531,
267,
291,
14,
7915,
63,
1617,
275,
291,
423,
5649,
14,
362,
63,
785,
480,
7915,
63,
5592,
63,
1617,
531,
267,
291,
14,
7915,
63,
5592,
275,
291,
423,
5649,
14,
362,
63,
785,
480,
32440,
13,
5592,
531,
398,
291,
14,
23900,
275,
291,
14,
362,
63,
7915,
63,
9086,
342,
267,
291,
14,
7915,
63,
2489,
63,
2873,
5871,
275,
769,
342,
2728,
291,
14,
7915,
63,
12113,
275,
291,
423,
5649,
14,
362,
63,
785,
480,
7915,
63,
1802,
63,
1302,
531,
2728,
8297,
275,
469,
288,
298,
3937,
63,
2489,
582,
291,
14,
3937,
63,
2489,
12,
288,
298,
1600,
63,
3887,
63,
11276,
582,
291,
14,
1600,
288,
789,
267,
291,
423,
5649,
14,
2242,
63,
10458,
8,
5586,
9,
339,
347,
664,
63,
7915,
63,
9086,
8,
277,
304,
267,
2288,
63,
23900,
275,
769,
342,
267,
922,
63,
23900,
275,
769,
342,
398,
862,
26,
288,
2288,
63,
23900,
275,
359,
277,
14,
362,
63,
7915,
63,
2987,
8,
736,
14,
515,
14,
904,
8,
13752,
14,
7121,
63,
18061,
22076,
12,
536,
430,
2490,
367,
536,
315,
747,
14,
7374,
8,
13752,
14,
7121,
63,
18061,
22076,
9,
2490,
340,
747,
14,
515,
14,
6027,
8,
3147,
747,
14,
515,
14,
904,
8,
13752,
14,
7121,
63,
18061,
22076,
12,
536,
10524,
267,
871,
221,
2186,
465,
325,
26,
288,
870,
8,
69,
9,
288,
2288,
63,
23900,
275,
1211,
342,
398,
862,
26,
288,
922,
63,
23900,
275,
359,
277,
14,
362,
63,
7915,
63,
2987,
8,
736,
14,
515,
14,
904,
8,
13752,
14,
3791,
63,
18061,
22076,
12,
536,
430,
2574,
367,
536,
315,
747,
14,
7374,
8,
13752,
14,
3791,
63,
18061,
22076,
9,
2574,
340,
747,
14,
515,
14,
6027,
8,
3147,
747,
14,
515,
14,
904,
8,
13752,
14,
3791,
63,
18061,
22076,
12,
536,
10524,
267,
871,
2186,
465,
325,
26,
288,
870,
8,
69,
9,
288,
922,
63,
23900,
275,
1211,
342,
398,
372,
2288,
63,
23900,
435,
922,
63,
23900,
339,
347,
664,
63,
7915,
63,
2987,
8,
277,
12,
8879,
63,
515,
304,
267,
3004,
275,
23978,
5379,
342,
267,
3004,
14,
515,
275,
8879,
63,
515,
267,
2022,
63,
515,
275,
747,
14,
515,
14,
904,
8,
7915,
63,
515,
12,
298,
2987,
14,
1001,
531,
398,
543,
1551,
8,
1001,
63,
515,
12,
283,
82,
358,
465,
570,
26,
288,
2022,
63,
875,
275,
570,
14,
739,
342,
288,
3004,
14,
739,
63,
1001,
63,
875,
8,
1001,
63,
875,
9,
398,
372,
3004,
339,
347,
2498,
8,
277,
12,
1094,
63,
7915,
304,
267,
291,
14,
7915,
63,
1617,
14,
3584,
342,
267,
367,
8879,
315,
291,
14,
23900,
26,
288,
2740,
275,
291,
14,
7915,
63,
1617,
14,
740,
1332,
7915,
14,
354,
12,
8879,
14,
515,
12,
8879,
430,
288,
340,
8879,
14,
515,
508,
1094,
63,
7915,
26,
355,
291,
14,
2918,
63,
7915,
63,
815,
8,
7915,
9,
355,
291,
14,
7915,
63,
5592,
14,
2416,
63,
1661,
8,
1661,
9,
267,
291,
14,
3806,
14,
1065,
342,
267,
291,
14,
3806,
14,
8191,
342,
2286,
347,
4002,
8,
277,
12,
5528,
304,
267,
291,
14,
3806,
14,
8191,
342,
5493,
347,
3920,
63,
2489,
8,
277,
12,
3123,
63,
1345,
304,
267,
334,
1238,
12,
2740,
9,
275,
3123,
63,
1345,
14,
362,
63,
5592,
1252,
362,
63,
5511,
342,
267,
574,
275,
1402,
14,
362,
63,
585,
8,
1661,
12,
413,
9,
267,
8879,
275,
1402,
14,
362,
63,
585,
8,
1661,
12,
499,
9,
267,
291,
14,
2918,
63,
7915,
63,
815,
8,
7915,
9,
267,
291,
14,
6814,
63,
7915,
63,
2489,
8,
585,
9,
2286,
347,
2929,
63,
7915,
63,
815,
8,
277,
12,
8879,
304,
267,
16193,
63,
505,
275,
3087,
267,
340,
8879,
14,
1802,
26,
288,
16193,
63,
505,
275,
16193,
63,
505,
435,
8879,
14,
1802,
435,
1867,
78,
60,
78,
11436,
267,
340,
8879,
14,
1682,
26,
288,
16193,
63,
505,
275,
16193,
63,
505,
435,
8879,
14,
1682,
435,
1867,
78,
60,
78,
11436,
267,
340,
8879,
14,
7307,
26,
288,
16193,
63,
505,
275,
16193,
63,
505,
435,
8879,
14,
7307,
27,
267,
291,
14,
7915,
63,
12113,
14,
409,
63,
505,
8,
12113,
63,
505,
9,
268,
339,
347,
2274,
63,
7915,
63,
2489,
8,
277,
12,
27336,
304,
267,
291,
14,
7915,
63,
2489,
63,
2873,
5871,
14,
740,
8,
23968,
9,
339,
347,
11705,
63,
7915,
63,
2489,
8,
277,
12,
570,
304,
267,
367,
312,
315,
291,
14,
7915,
63,
2489,
63,
2873,
5871,
26,
288,
312,
14,
7915,
63,
2489,
8,
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
] |
[
18895,
14,
8421,
492,
11424,
199,
646,
747,
199,
504,
4382,
492,
25596,
4253,
12,
19329,
199,
504,
1402,
14,
23900,
492,
23978,
5379,
421,
199,
533,
23978,
7713,
7506,
8,
785,
304,
272,
347,
636,
826,
721,
277,
304,
267,
291,
423,
5649,
275,
11424,
14,
6437,
342,
267,
486,
17236,
63,
493,
275,
747,
14,
515,
14,
904,
8,
13752,
14,
7121,
63,
2226,
1554,
654,
12,
3303,
298,
7915,
63,
5592,
14,
31589,
531,
267,
291,
423,
5649,
14,
409,
63,
6893,
63,
2261,
8,
8516,
14,
19265,
63,
2339,
9,
267,
291,
423,
5649,
14,
525,
63,
504,
63,
493,
8,
31589,
63,
493,
9,
2234,
267,
291,
14,
3806,
275,
291,
423,
5649,
14,
362,
63,
785,
480,
7915,
63,
5592,
63,
3806,
531,
267,
291,
14,
7915,
63,
1617,
275,
291,
423,
5649,
14,
362,
63,
785,
480,
7915,
63,
5592,
63,
1617,
531,
267,
291,
14,
7915,
63,
5592,
275,
291,
423,
5649,
14,
362,
63,
785,
480,
32440,
13,
5592,
531,
398,
291,
14,
23900,
275,
291,
14,
362,
63,
7915,
63,
9086,
342,
267,
291,
14,
7915,
63,
2489,
63,
2873,
5871,
275,
769,
342,
2728,
291,
14,
7915,
63,
12113,
275,
291,
423,
5649,
14,
362,
63,
785,
480,
7915,
63,
1802,
63,
1302,
531,
2728,
8297,
275,
469,
288,
298,
3937,
63,
2489,
582,
291,
14,
3937,
63,
2489,
12,
288,
298,
1600,
63,
3887,
63,
11276,
582,
291,
14,
1600,
288,
789,
267,
291,
423,
5649,
14,
2242,
63,
10458,
8,
5586,
9,
339,
347,
664,
63,
7915,
63,
9086,
8,
277,
304,
267,
2288,
63,
23900,
275,
769,
342,
267,
922,
63,
23900,
275,
769,
342,
398,
862,
26,
288,
2288,
63,
23900,
275,
359,
277,
14,
362,
63,
7915,
63,
2987,
8,
736,
14,
515,
14,
904,
8,
13752,
14,
7121,
63,
18061,
22076,
12,
536,
430,
2490,
367,
536,
315,
747,
14,
7374,
8,
13752,
14,
7121,
63,
18061,
22076,
9,
2490,
340,
747,
14,
515,
14,
6027,
8,
3147,
747,
14,
515,
14,
904,
8,
13752,
14,
7121,
63,
18061,
22076,
12,
536,
10524,
267,
871,
221,
2186,
465,
325,
26,
288,
870,
8,
69,
9,
288,
2288,
63,
23900,
275,
1211,
342,
398,
862,
26,
288,
922,
63,
23900,
275,
359,
277,
14,
362,
63,
7915,
63,
2987,
8,
736,
14,
515,
14,
904,
8,
13752,
14,
3791,
63,
18061,
22076,
12,
536,
430,
2574,
367,
536,
315,
747,
14,
7374,
8,
13752,
14,
3791,
63,
18061,
22076,
9,
2574,
340,
747,
14,
515,
14,
6027,
8,
3147,
747,
14,
515,
14,
904,
8,
13752,
14,
3791,
63,
18061,
22076,
12,
536,
10524,
267,
871,
2186,
465,
325,
26,
288,
870,
8,
69,
9,
288,
922,
63,
23900,
275,
1211,
342,
398,
372,
2288,
63,
23900,
435,
922,
63,
23900,
339,
347,
664,
63,
7915,
63,
2987,
8,
277,
12,
8879,
63,
515,
304,
267,
3004,
275,
23978,
5379,
342,
267,
3004,
14,
515,
275,
8879,
63,
515,
267,
2022,
63,
515,
275,
747,
14,
515,
14,
904,
8,
7915,
63,
515,
12,
298,
2987,
14,
1001,
531,
398,
543,
1551,
8,
1001,
63,
515,
12,
283,
82,
358,
465,
570,
26,
288,
2022,
63,
875,
275,
570,
14,
739,
342,
288,
3004,
14,
739,
63,
1001,
63,
875,
8,
1001,
63,
875,
9,
398,
372,
3004,
339,
347,
2498,
8,
277,
12,
1094,
63,
7915,
304,
267,
291,
14,
7915,
63,
1617,
14,
3584,
342,
267,
367,
8879,
315,
291,
14,
23900,
26,
288,
2740,
275,
291,
14,
7915,
63,
1617,
14,
740,
1332,
7915,
14,
354,
12,
8879,
14,
515,
12,
8879,
430,
288,
340,
8879,
14,
515,
508,
1094,
63,
7915,
26,
355,
291,
14,
2918,
63,
7915,
63,
815,
8,
7915,
9,
355,
291,
14,
7915,
63,
5592,
14,
2416,
63,
1661,
8,
1661,
9,
267,
291,
14,
3806,
14,
1065,
342,
267,
291,
14,
3806,
14,
8191,
342,
2286,
347,
4002,
8,
277,
12,
5528,
304,
267,
291,
14,
3806,
14,
8191,
342,
5493,
347,
3920,
63,
2489,
8,
277,
12,
3123,
63,
1345,
304,
267,
334,
1238,
12,
2740,
9,
275,
3123,
63,
1345,
14,
362,
63,
5592,
1252,
362,
63,
5511,
342,
267,
574,
275,
1402,
14,
362,
63,
585,
8,
1661,
12,
413,
9,
267,
8879,
275,
1402,
14,
362,
63,
585,
8,
1661,
12,
499,
9,
267,
291,
14,
2918,
63,
7915,
63,
815,
8,
7915,
9,
267,
291,
14,
6814,
63,
7915,
63,
2489,
8,
585,
9,
2286,
347,
2929,
63,
7915,
63,
815,
8,
277,
12,
8879,
304,
267,
16193,
63,
505,
275,
3087,
267,
340,
8879,
14,
1802,
26,
288,
16193,
63,
505,
275,
16193,
63,
505,
435,
8879,
14,
1802,
435,
1867,
78,
60,
78,
11436,
267,
340,
8879,
14,
1682,
26,
288,
16193,
63,
505,
275,
16193,
63,
505,
435,
8879,
14,
1682,
435,
1867,
78,
60,
78,
11436,
267,
340,
8879,
14,
7307,
26,
288,
16193,
63,
505,
275,
16193,
63,
505,
435,
8879,
14,
7307,
27,
267,
291,
14,
7915,
63,
12113,
14,
409,
63,
505,
8,
12113,
63,
505,
9,
268,
339,
347,
2274,
63,
7915,
63,
2489,
8,
277,
12,
27336,
304,
267,
291,
14,
7915,
63,
2489,
63,
2873,
5871,
14,
740,
8,
23968,
9,
339,
347,
11705,
63,
7915,
63,
2489,
8,
277,
12,
570,
304,
267,
367,
312,
315,
291,
14,
7915,
63,
2489,
63,
2873,
5871,
26,
288,
312,
14,
7915,
63,
2489,
8,
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,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
SerCeMan/intellij-community
|
python/lib/Lib/site-packages/django/contrib/localflavor/sk/sk_districts.py
|
543
|
2453
|
"""
Slovak districts according to http://sk.wikipedia.org/wiki/Administrat%C3%ADvne_%C4%8Dlenenie_Slovenska
"""
from django.utils.translation import ugettext_lazy as _
DISTRICT_CHOICES = (
('BB', _('Banska Bystrica')),
('BS', _('Banska Stiavnica')),
('BJ', _('Bardejov')),
('BN', _('Banovce nad Bebravou')),
('BR', _('Brezno')),
('BA1', _('Bratislava I')),
('BA2', _('Bratislava II')),
('BA3', _('Bratislava III')),
('BA4', _('Bratislava IV')),
('BA5', _('Bratislava V')),
('BY', _('Bytca')),
('CA', _('Cadca')),
('DT', _('Detva')),
('DK', _('Dolny Kubin')),
('DS', _('Dunajska Streda')),
('GA', _('Galanta')),
('GL', _('Gelnica')),
('HC', _('Hlohovec')),
('HE', _('Humenne')),
('IL', _('Ilava')),
('KK', _('Kezmarok')),
('KN', _('Komarno')),
('KE1', _('Kosice I')),
('KE2', _('Kosice II')),
('KE3', _('Kosice III')),
('KE4', _('Kosice IV')),
('KEO', _('Kosice - okolie')),
('KA', _('Krupina')),
('KM', _('Kysucke Nove Mesto')),
('LV', _('Levice')),
('LE', _('Levoca')),
('LM', _('Liptovsky Mikulas')),
('LC', _('Lucenec')),
('MA', _('Malacky')),
('MT', _('Martin')),
('ML', _('Medzilaborce')),
('MI', _('Michalovce')),
('MY', _('Myjava')),
('NO', _('Namestovo')),
('NR', _('Nitra')),
('NM', _('Nove Mesto nad Vahom')),
('NZ', _('Nove Zamky')),
('PE', _('Partizanske')),
('PK', _('Pezinok')),
('PN', _('Piestany')),
('PT', _('Poltar')),
('PP', _('Poprad')),
('PB', _('Povazska Bystrica')),
('PO', _('Presov')),
('PD', _('Prievidza')),
('PU', _('Puchov')),
('RA', _('Revuca')),
('RS', _('Rimavska Sobota')),
('RV', _('Roznava')),
('RK', _('Ruzomberok')),
('SB', _('Sabinov')),
('SC', _('Senec')),
('SE', _('Senica')),
('SI', _('Skalica')),
('SV', _('Snina')),
('SO', _('Sobrance')),
('SN', _('Spisska Nova Ves')),
('SL', _('Stara Lubovna')),
('SP', _('Stropkov')),
('SK', _('Svidnik')),
('SA', _('Sala')),
('TO', _('Topolcany')),
('TV', _('Trebisov')),
('TN', _('Trencin')),
('TT', _('Trnava')),
('TR', _('Turcianske Teplice')),
('TS', _('Tvrdosin')),
('VK', _('Velky Krtis')),
('VT', _('Vranov nad Toplou')),
('ZM', _('Zlate Moravce')),
('ZV', _('Zvolen')),
('ZC', _('Zarnovica')),
('ZH', _('Ziar nad Hronom')),
('ZA', _('Zilina')),
)
|
apache-2.0
|
[
624,
199,
51,
32555,
1151,
487,
816,
3021,
7182,
370,
1455,
921,
1339,
14,
13961,
14,
1308,
15,
6797,
15,
4880,
3075,
292,
5,
35,
19,
5,
1554,
86,
685,
4970,
35,
20,
5,
24,
36,
552,
287,
1873,
63,
51,
320,
1856,
1339,
65,
199,
624,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
24580,
6196,
63,
16236,
275,
334,
272,
661,
5342,
297,
4018,
34,
796,
7351,
4885,
816,
696,
3855,
272,
661,
11087,
297,
4018,
34,
796,
7351,
428,
280,
1214,
12165,
65,
3855,
272,
661,
16262,
297,
4018,
5281,
271,
743,
86,
3855,
272,
661,
18273,
297,
4018,
34,
8143,
86,
301,
302,
350,
699,
2871,
345,
86,
810,
3855,
272,
661,
7184,
297,
4018,
34,
25409,
889,
3855,
272,
661,
4134,
17,
297,
4018,
17171,
16753,
416,
3042,
473,
3855,
272,
661,
4134,
18,
297,
4018,
17171,
16753,
416,
3042,
473,
41,
3855,
272,
661,
4134,
19,
297,
4018,
17171,
16753,
416,
3042,
473,
8921,
3855,
272,
661,
4134,
20,
297,
4018,
17171,
16753,
416,
3042,
27892,
3855,
272,
661,
4134,
21,
297,
4018,
17171,
16753,
416,
3042,
812,
3855,
272,
661,
8285,
297,
4018,
2175,
84,
696,
3855,
272,
661,
3263,
297,
4018,
35,
350,
696,
3855,
272,
661,
7438,
297,
4018,
21097,
3042,
3855,
272,
661,
10892,
297,
4018,
36,
393,
9745,
1804,
456,
262,
3855,
272,
661,
3177,
297,
4018,
36,
324,
9091,
1339,
65,
1933,
581,
65,
3855,
272,
661,
9741,
297,
4018,
39,
279,
290,
502,
3855,
272,
661,
2226,
297,
4018,
39,
352,
12165,
65,
3855,
272,
661,
28460,
297,
4018,
40,
320,
526,
6046,
3855,
272,
661,
1645,
297,
4018,
40,
11678,
685,
3855,
272,
661,
1193,
297,
4018,
41,
416,
3042,
3855,
272,
661,
27511,
297,
4018,
1136,
90,
4584,
745,
3855,
272,
661,
43,
46,
297,
4018,
43,
676,
285,
889,
3855,
272,
661,
2430,
17,
297,
4018,
31305,
338,
301,
473,
3855,
272,
661,
2430,
18,
297,
4018,
31305,
338,
301,
473,
41,
3855,
272,
661,
2430,
19,
297,
4018,
31305,
338,
301,
473,
8921,
3855,
272,
661,
2430,
20,
297,
4018,
31305,
338,
301,
27892,
3855,
272,
661,
2430,
47,
297,
4018,
31305,
338,
301,
446,
4112,
79,
21530,
3855,
272,
661,
19606,
297,
4018,
43,
5505,
13765,
3855,
272,
661,
43,
45,
297,
4018,
43,
588,
10112,
69,
3091,
432,
603,
597,
79,
3855,
272,
661,
18750,
297,
4018,
2553,
722,
3855,
272,
661,
906,
297,
4018,
17808,
679,
65,
3855,
272,
661,
25526,
297,
4018,
44,
711,
475,
86,
12267,
603,
3258,
32646,
3855,
272,
661,
7027,
297,
4018,
44,
947,
287,
825,
3855,
272,
661,
2054,
297,
4018,
31147,
564,
89,
3855,
272,
661,
5747,
297,
4018,
45,
26788,
3855,
272,
661,
1698,
297,
4018,
45,
379,
90,
24142,
269,
301,
3855,
272,
661,
10709,
297,
4018,
45,
1158,
279,
8822,
301,
3855,
272,
661,
12339,
297,
4018,
5713,
6138,
3855,
272,
661,
2826,
297,
4018,
985,
14308,
2392,
3855,
272,
661,
17774,
297,
4018,
46,
390,
345,
3855,
272,
661,
21942,
297,
4018,
1944,
432,
603,
597,
79,
302,
350,
812,
65,
526,
77,
3855,
272,
661,
19011,
297,
4018,
1944,
432,
3107,
455,
10562,
3855,
272,
661,
1510,
297,
4018,
1262,
280,
90,
796,
415,
3855,
272,
661,
8884,
297,
4018,
8070,
90,
262,
745,
3855,
272,
661,
9060,
297,
4018,
10542,
597,
1629,
3855,
272,
661,
4189,
297,
4018,
5858,
5369,
3855,
272,
661,
7701,
297,
4018,
9606,
9525,
3855,
272,
661,
13167,
297,
4018,
1575,
3042,
90,
1339,
65,
4885,
816,
696,
3855,
272,
661,
1512,
297,
4018,
48,
470,
8822,
3855,
272,
661,
11435,
297,
4018,
4562,
69,
5017,
8076,
3855,
272,
661,
6903,
297,
4018,
48,
2133,
8822,
3855,
272,
661,
2847,
297,
4018,
26176,
8667,
3855,
272,
661,
15062,
297,
4018,
28522,
10336,
1339,
65,
2002,
3018,
65,
3855,
272,
661,
28841,
297,
4018,
3863,
31591,
3812,
3855,
272,
661,
50,
43,
297,
4018,
50,
9494,
676,
605,
745,
3855,
272,
661,
12463,
297,
4018,
51,
371,
262,
8822,
3855,
272,
661,
5153,
297,
4018,
18569,
825,
3855,
272,
661,
899,
297,
4018,
18569,
24027,
3855,
272,
661,
2684,
297,
4018,
14194,
17999,
65,
3855,
272,
661,
4985,
297,
4018,
20821,
13765,
3855,
272,
661,
4118,
297,
4018,
51,
2873,
31331,
3855,
272,
661,
8199,
297,
4018,
5058,
374,
1339,
65,
28184,
812,
397,
3855,
272,
661,
4929,
297,
4018,
933,
17956,
491,
456,
8822,
3540,
3855,
272,
661,
5763,
297,
4018,
933,
293,
2051,
8822,
3855,
272,
661,
8656,
297,
4018,
51,
5017,
22998,
3855,
272,
661,
4251,
297,
4018,
51,
14774,
3855,
272,
661,
2566,
297,
4018,
6105,
393,
67,
1629,
3855,
272,
661,
12764,
297,
4018,
52,
264,
66,
4595,
86,
3855,
272,
661,
52,
46,
297,
4018,
52,
828,
67,
262,
3855,
272,
661,
1481,
297,
4018,
52,
11641,
3812,
3855,
272,
661,
1766,
297,
4018,
27438,
559,
796,
415,
377,
1545,
3037,
3855,
272,
661,
9730,
297,
4018,
52,
86,
6883,
736,
262,
3855,
272,
661,
19327,
297,
4018,
54,
352,
10562,
1804,
82,
16753,
3855,
272,
661,
8156,
297,
4018,
54,
1312,
8822,
302,
350,
14132,
320,
85,
3855,
272,
661,
58,
45,
297,
4018,
58,
750,
603,
269,
1214,
301,
3855,
272,
661,
58,
54,
297,
4018,
58,
2392,
552,
3855,
272,
661,
58,
35,
297,
4018,
58,
285,
889,
433,
696,
3855,
272,
661,
58,
40,
297,
4018,
22534,
285,
302,
350,
869,
2641,
676,
3855,
272,
661,
21959,
297,
4018,
58,
382,
13765,
3855,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
199,
51,
32555,
1151,
487,
816,
3021,
7182,
370,
1455,
921,
1339,
14,
13961,
14,
1308,
15,
6797,
15,
4880,
3075,
292,
5,
35,
19,
5,
1554,
86,
685,
4970,
35,
20,
5,
24,
36,
552,
287,
1873,
63,
51,
320,
1856,
1339,
65,
199,
624,
199,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
24580,
6196,
63,
16236,
275,
334,
272,
661,
5342,
297,
4018,
34,
796,
7351,
4885,
816,
696,
3855,
272,
661,
11087,
297,
4018,
34,
796,
7351,
428,
280,
1214,
12165,
65,
3855,
272,
661,
16262,
297,
4018,
5281,
271,
743,
86,
3855,
272,
661,
18273,
297,
4018,
34,
8143,
86,
301,
302,
350,
699,
2871,
345,
86,
810,
3855,
272,
661,
7184,
297,
4018,
34,
25409,
889,
3855,
272,
661,
4134,
17,
297,
4018,
17171,
16753,
416,
3042,
473,
3855,
272,
661,
4134,
18,
297,
4018,
17171,
16753,
416,
3042,
473,
41,
3855,
272,
661,
4134,
19,
297,
4018,
17171,
16753,
416,
3042,
473,
8921,
3855,
272,
661,
4134,
20,
297,
4018,
17171,
16753,
416,
3042,
27892,
3855,
272,
661,
4134,
21,
297,
4018,
17171,
16753,
416,
3042,
812,
3855,
272,
661,
8285,
297,
4018,
2175,
84,
696,
3855,
272,
661,
3263,
297,
4018,
35,
350,
696,
3855,
272,
661,
7438,
297,
4018,
21097,
3042,
3855,
272,
661,
10892,
297,
4018,
36,
393,
9745,
1804,
456,
262,
3855,
272,
661,
3177,
297,
4018,
36,
324,
9091,
1339,
65,
1933,
581,
65,
3855,
272,
661,
9741,
297,
4018,
39,
279,
290,
502,
3855,
272,
661,
2226,
297,
4018,
39,
352,
12165,
65,
3855,
272,
661,
28460,
297,
4018,
40,
320,
526,
6046,
3855,
272,
661,
1645,
297,
4018,
40,
11678,
685,
3855,
272,
661,
1193,
297,
4018,
41,
416,
3042,
3855,
272,
661,
27511,
297,
4018,
1136,
90,
4584,
745,
3855,
272,
661,
43,
46,
297,
4018,
43,
676,
285,
889,
3855,
272,
661,
2430,
17,
297,
4018,
31305,
338,
301,
473,
3855,
272,
661,
2430,
18,
297,
4018,
31305,
338,
301,
473,
41,
3855,
272,
661,
2430,
19,
297,
4018,
31305,
338,
301,
473,
8921,
3855,
272,
661,
2430,
20,
297,
4018,
31305,
338,
301,
27892,
3855,
272,
661,
2430,
47,
297,
4018,
31305,
338,
301,
446,
4112,
79,
21530,
3855,
272,
661,
19606,
297,
4018,
43,
5505,
13765,
3855,
272,
661,
43,
45,
297,
4018,
43,
588,
10112,
69,
3091,
432,
603,
597,
79,
3855,
272,
661,
18750,
297,
4018,
2553,
722,
3855,
272,
661,
906,
297,
4018,
17808,
679,
65,
3855,
272,
661,
25526,
297,
4018,
44,
711,
475,
86,
12267,
603,
3258,
32646,
3855,
272,
661,
7027,
297,
4018,
44,
947,
287,
825,
3855,
272,
661,
2054,
297,
4018,
31147,
564,
89,
3855,
272,
661,
5747,
297,
4018,
45,
26788,
3855,
272,
661,
1698,
297,
4018,
45,
379,
90,
24142,
269,
301,
3855,
272,
661,
10709,
297,
4018,
45,
1158,
279,
8822,
301,
3855,
272,
661,
12339,
297,
4018,
5713,
6138,
3855,
272,
661,
2826,
297,
4018,
985,
14308,
2392,
3855,
272,
661,
17774,
297,
4018,
46,
390,
345,
3855,
272,
661,
21942,
297,
4018,
1944,
432,
603,
597,
79,
302,
350,
812,
65,
526,
77,
3855,
272,
661,
19011,
297,
4018,
1944,
432,
3107,
455,
10562,
3855,
272,
661,
1510,
297,
4018,
1262,
280,
90,
796,
415,
3855,
272,
661,
8884,
297,
4018,
8070,
90,
262,
745,
3855,
272,
661,
9060,
297,
4018,
10542,
597,
1629,
3855,
272,
661,
4189,
297,
4018,
5858,
5369,
3855,
272,
661,
7701,
297,
4018,
9606,
9525,
3855,
272,
661,
13167,
297,
4018,
1575,
3042,
90,
1339,
65,
4885,
816,
696,
3855,
272,
661,
1512,
297,
4018,
48,
470,
8822,
3855,
272,
661,
11435,
297,
4018,
4562,
69,
5017,
8076,
3855,
272,
661,
6903,
297,
4018,
48,
2133,
8822,
3855,
272,
661,
2847,
297,
4018,
26176,
8667,
3855,
272,
661,
15062,
297,
4018,
28522,
10336,
1339,
65,
2002,
3018,
65,
3855,
272,
661,
28841,
297,
4018,
3863,
31591,
3812,
3855,
272,
661,
50,
43,
297,
4018,
50,
9494,
676,
605,
745,
3855,
272,
661,
12463,
297,
4018,
51,
371,
262,
8822,
3855,
272,
661,
5153,
297,
4018,
18569,
825,
3855,
272,
661,
899,
297,
4018,
18569,
24027,
3855,
272,
661,
2684,
297,
4018,
14194,
17999,
65,
3855,
272,
661,
4985,
297,
4018,
20821,
13765,
3855,
272,
661,
4118,
297,
4018,
51,
2873,
31331,
3855,
272,
661,
8199,
297,
4018,
5058,
374,
1339,
65,
28184,
812,
397,
3855,
272,
661,
4929,
297,
4018,
933,
17956,
491,
456,
8822,
3540,
3855,
272,
661,
5763,
297,
4018,
933,
293,
2051,
8822,
3855,
272,
661,
8656,
297,
4018,
51,
5017,
22998,
3855,
272,
661,
4251,
297,
4018,
51,
14774,
3855,
272,
661,
2566,
297,
4018,
6105,
393,
67,
1629,
3855,
272,
661,
12764,
297,
4018,
52,
264,
66,
4595,
86,
3855,
272,
661,
52,
46,
297,
4018,
52,
828,
67,
262,
3855,
272,
661,
1481,
297,
4018,
52,
11641,
3812,
3855,
272,
661,
1766,
297,
4018,
27438,
559,
796,
415,
377,
1545,
3037,
3855,
272,
661,
9730,
297,
4018,
52,
86,
6883,
736,
262,
3855,
272,
661,
19327,
297,
4018,
54,
352,
10562,
1804,
82,
16753,
3855,
272,
661,
8156,
297,
4018,
54,
1312,
8822,
302,
350,
14132,
320,
85,
3855,
272,
661,
58,
45,
297,
4018,
58,
750,
603,
269,
1214,
301,
3855,
272,
661,
58,
54,
297,
4018,
58,
2392,
552,
3855,
272,
661,
58,
35,
297,
4018,
58,
285,
889,
433,
696,
3855,
272,
661,
58,
40,
297,
4018,
22534,
285,
302,
350,
869,
2641,
676,
3855,
272,
661,
21959,
297,
4018,
58,
382,
13765,
3855,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768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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
] |
joelpinheiro/safebox-smartcard-auth
|
Client/veclient/lib/python2.7/site-packages/setuptools/site-patch.py
|
720
|
2389
|
def __boot():
import sys
import os
PYTHONPATH = os.environ.get('PYTHONPATH')
if PYTHONPATH is None or (sys.platform=='win32' and not PYTHONPATH):
PYTHONPATH = []
else:
PYTHONPATH = PYTHONPATH.split(os.pathsep)
pic = getattr(sys,'path_importer_cache',{})
stdpath = sys.path[len(PYTHONPATH):]
mydir = os.path.dirname(__file__)
#print "searching",stdpath,sys.path
for item in stdpath:
if item==mydir or not item:
continue # skip if current dir. on Windows, or my own directory
importer = pic.get(item)
if importer is not None:
loader = importer.find_module('site')
if loader is not None:
# This should actually reload the current module
loader.load_module('site')
break
else:
try:
import imp # Avoid import loop in Python >= 3.3
stream, path, descr = imp.find_module('site',[item])
except ImportError:
continue
if stream is None:
continue
try:
# This should actually reload the current module
imp.load_module('site',stream,path,descr)
finally:
stream.close()
break
else:
raise ImportError("Couldn't find the real 'site' module")
#print "loaded", __file__
known_paths = dict([(makepath(item)[1],1) for item in sys.path]) # 2.2 comp
oldpos = getattr(sys,'__egginsert',0) # save old insertion position
sys.__egginsert = 0 # and reset the current one
for item in PYTHONPATH:
addsitedir(item)
sys.__egginsert += oldpos # restore effective old position
d, nd = makepath(stdpath[0])
insert_at = None
new_path = []
for item in sys.path:
p, np = makepath(item)
if np==nd and insert_at is None:
# We've hit the first 'system' path entry, so added entries go here
insert_at = len(new_path)
if np in known_paths or insert_at is None:
new_path.append(item)
else:
# new path after the insert point, back-insert it
new_path.insert(insert_at, item)
insert_at += 1
sys.path[:] = new_path
if __name__=='site':
__boot()
del __boot
|
gpl-2.0
|
[
318,
636,
4930,
837,
272,
492,
984,
272,
492,
747,
272,
31176,
275,
747,
14,
2314,
14,
362,
360,
29266,
358,
272,
340,
31176,
365,
488,
503,
334,
1274,
14,
3246,
6803,
2676,
708,
7,
436,
440,
31176,
304,
267,
31176,
275,
942,
272,
587,
26,
267,
31176,
275,
31176,
14,
1294,
8,
736,
14,
17843,
9,
339,
26559,
275,
2519,
8,
1274,
2584,
515,
63,
12138,
63,
1637,
297,
91,
1552,
272,
2418,
515,
275,
984,
14,
515,
59,
552,
8,
29266,
15405,
272,
3002,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
272,
327,
1361,
298,
1733,
316,
401,
1516,
515,
12,
1274,
14,
515,
339,
367,
1242,
315,
2418,
515,
26,
267,
340,
1242,
389,
1662,
694,
503,
440,
1242,
26,
288,
1980,
259,
327,
3372,
340,
1453,
2935,
14,
641,
5417,
12,
503,
3002,
5705,
2082,
267,
13479,
275,
26559,
14,
362,
8,
1053,
9,
267,
340,
13479,
365,
440,
488,
26,
288,
5077,
275,
13479,
14,
1623,
63,
578,
360,
2124,
358,
288,
340,
5077,
365,
440,
488,
26,
355,
327,
961,
1077,
5965,
13101,
314,
1453,
859,
355,
5077,
14,
912,
63,
578,
360,
2124,
358,
355,
2059,
267,
587,
26,
288,
862,
26,
355,
492,
1742,
327,
19503,
492,
4438,
315,
2018,
2356,
650,
14,
19,
355,
2547,
12,
931,
12,
16193,
275,
1742,
14,
1623,
63,
578,
360,
2124,
23993,
1053,
566,
288,
871,
3545,
26,
355,
1980,
288,
340,
2547,
365,
488,
26,
355,
1980,
288,
862,
26,
355,
327,
961,
1077,
5965,
13101,
314,
1453,
859,
355,
1742,
14,
912,
63,
578,
360,
2124,
297,
1745,
12,
515,
12,
12113,
9,
288,
3753,
26,
355,
2547,
14,
1600,
342,
288,
2059,
272,
587,
26,
267,
746,
3545,
480,
20485,
1133,
2342,
314,
3363,
283,
2124,
7,
859,
531,
339,
327,
1361,
298,
4591,
401,
636,
493,
363,
339,
6040,
63,
3771,
275,
1211,
7694,
1875,
515,
8,
1053,
2788,
17,
467,
17,
9,
367,
1242,
315,
984,
14,
515,
566,
327,
499,
14,
18,
1013,
339,
2269,
1712,
275,
2519,
8,
1274,
2584,
363,
5902,
903,
407,
297,
16,
9,
257,
327,
3354,
2269,
22470,
3421,
272,
984,
855,
5902,
903,
407,
275,
378,
9326,
327,
436,
5305,
314,
1453,
1373,
339,
367,
1242,
315,
31176,
26,
267,
1050,
2124,
694,
8,
1053,
9,
339,
984,
855,
5902,
903,
407,
847,
2269,
1712,
3698,
327,
9066,
15826,
2269,
3421,
339,
366,
12,
5222,
275,
1852,
515,
8,
1516,
515,
59,
16,
566,
272,
5518,
63,
292,
275,
488,
272,
892,
63,
515,
275,
942,
339,
367,
1242,
315,
984,
14,
515,
26,
267,
299,
12,
980,
275,
1852,
515,
8,
1053,
9,
398,
340,
980,
389,
977,
436,
5518,
63,
292,
365,
488,
26,
288,
327,
2136,
9064,
9793,
314,
1642,
283,
2253,
7,
931,
2397,
12,
880,
3483,
4811,
2621,
2348,
288,
5518,
63,
292,
275,
822,
8,
1222,
63,
515,
9,
398,
340,
980,
315,
6040,
63,
3771,
503,
5518,
63,
292,
365,
488,
26,
288,
892,
63,
515,
14,
740,
8,
1053,
9,
267,
587,
26,
288,
327,
892,
931,
2410,
314,
5518,
2376,
12,
1771,
13,
3176,
652,
288,
892,
63,
515,
14,
3176,
8,
3176,
63,
292,
12,
1242,
9,
288,
5518,
63,
292,
847,
413,
339,
984,
14,
515,
5873,
275,
892,
63,
515,
199,
199,
692,
636,
354,
363,
6803,
2124,
356,
272,
636,
4930,
342,
272,
2150,
636,
4930,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
636,
4930,
837,
272,
492,
984,
272,
492,
747,
272,
31176,
275,
747,
14,
2314,
14,
362,
360,
29266,
358,
272,
340,
31176,
365,
488,
503,
334,
1274,
14,
3246,
6803,
2676,
708,
7,
436,
440,
31176,
304,
267,
31176,
275,
942,
272,
587,
26,
267,
31176,
275,
31176,
14,
1294,
8,
736,
14,
17843,
9,
339,
26559,
275,
2519,
8,
1274,
2584,
515,
63,
12138,
63,
1637,
297,
91,
1552,
272,
2418,
515,
275,
984,
14,
515,
59,
552,
8,
29266,
15405,
272,
3002,
694,
275,
747,
14,
515,
14,
3475,
3460,
493,
3368,
272,
327,
1361,
298,
1733,
316,
401,
1516,
515,
12,
1274,
14,
515,
339,
367,
1242,
315,
2418,
515,
26,
267,
340,
1242,
389,
1662,
694,
503,
440,
1242,
26,
288,
1980,
259,
327,
3372,
340,
1453,
2935,
14,
641,
5417,
12,
503,
3002,
5705,
2082,
267,
13479,
275,
26559,
14,
362,
8,
1053,
9,
267,
340,
13479,
365,
440,
488,
26,
288,
5077,
275,
13479,
14,
1623,
63,
578,
360,
2124,
358,
288,
340,
5077,
365,
440,
488,
26,
355,
327,
961,
1077,
5965,
13101,
314,
1453,
859,
355,
5077,
14,
912,
63,
578,
360,
2124,
358,
355,
2059,
267,
587,
26,
288,
862,
26,
355,
492,
1742,
327,
19503,
492,
4438,
315,
2018,
2356,
650,
14,
19,
355,
2547,
12,
931,
12,
16193,
275,
1742,
14,
1623,
63,
578,
360,
2124,
23993,
1053,
566,
288,
871,
3545,
26,
355,
1980,
288,
340,
2547,
365,
488,
26,
355,
1980,
288,
862,
26,
355,
327,
961,
1077,
5965,
13101,
314,
1453,
859,
355,
1742,
14,
912,
63,
578,
360,
2124,
297,
1745,
12,
515,
12,
12113,
9,
288,
3753,
26,
355,
2547,
14,
1600,
342,
288,
2059,
272,
587,
26,
267,
746,
3545,
480,
20485,
1133,
2342,
314,
3363,
283,
2124,
7,
859,
531,
339,
327,
1361,
298,
4591,
401,
636,
493,
363,
339,
6040,
63,
3771,
275,
1211,
7694,
1875,
515,
8,
1053,
2788,
17,
467,
17,
9,
367,
1242,
315,
984,
14,
515,
566,
327,
499,
14,
18,
1013,
339,
2269,
1712,
275,
2519,
8,
1274,
2584,
363,
5902,
903,
407,
297,
16,
9,
257,
327,
3354,
2269,
22470,
3421,
272,
984,
855,
5902,
903,
407,
275,
378,
9326,
327,
436,
5305,
314,
1453,
1373,
339,
367,
1242,
315,
31176,
26,
267,
1050,
2124,
694,
8,
1053,
9,
339,
984,
855,
5902,
903,
407,
847,
2269,
1712,
3698,
327,
9066,
15826,
2269,
3421,
339,
366,
12,
5222,
275,
1852,
515,
8,
1516,
515,
59,
16,
566,
272,
5518,
63,
292,
275,
488,
272,
892,
63,
515,
275,
942,
339,
367,
1242,
315,
984,
14,
515,
26,
267,
299,
12,
980,
275,
1852,
515,
8,
1053,
9,
398,
340,
980,
389,
977,
436,
5518,
63,
292,
365,
488,
26,
288,
327,
2136,
9064,
9793,
314,
1642,
283,
2253,
7,
931,
2397,
12,
880,
3483,
4811,
2621,
2348,
288,
5518,
63,
292,
275,
822,
8,
1222,
63,
515,
9,
398,
340,
980,
315,
6040,
63,
3771,
503,
5518,
63,
292,
365,
488,
26,
288,
892,
63,
515,
14,
740,
8,
1053,
9,
267,
587,
26,
288,
327,
892,
931,
2410,
314,
5518,
2376,
12,
1771,
13,
3176,
652,
288,
892,
63,
515,
14,
3176,
8,
3176,
63,
292,
12,
1242,
9,
288,
5518,
63,
292,
847,
413,
339,
984,
14,
515,
5873,
275,
892,
63,
515,
199,
199,
692,
636,
354,
363,
6803,
2124,
356,
272,
636,
4930,
342,
272,
2150,
636,
4930,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
wemanuel/smry
|
smry/server-auth/ls/google-cloud-sdk/platform/gsutil/third_party/boto/boto/cloudtrail/exceptions.py
|
127
|
2246
|
"""
Exceptions that are specific to the cloudtrail module.
"""
from boto.exception import BotoServerError
class InvalidSnsTopicNameException(BotoServerError):
"""
Raised when an invalid SNS topic name is passed to Cloudtrail.
"""
pass
class InvalidS3BucketNameException(BotoServerError):
"""
Raised when an invalid S3 bucket name is passed to Cloudtrail.
"""
pass
class TrailAlreadyExistsException(BotoServerError):
"""
Raised when the given trail name already exists.
"""
pass
class InsufficientSnsTopicPolicyException(BotoServerError):
"""
Raised when the SNS topic does not allow Cloudtrail to post
messages.
"""
pass
class InvalidTrailNameException(BotoServerError):
"""
Raised when the trail name is invalid.
"""
pass
class InternalErrorException(BotoServerError):
"""
Raised when there was an internal Cloudtrail error.
"""
pass
class TrailNotFoundException(BotoServerError):
"""
Raised when the given trail name is not found.
"""
pass
class S3BucketDoesNotExistException(BotoServerError):
"""
Raised when the given S3 bucket does not exist.
"""
pass
class TrailNotProvidedException(BotoServerError):
"""
Raised when no trail name was provided.
"""
pass
class InvalidS3PrefixException(BotoServerError):
"""
Raised when an invalid key prefix is given.
"""
pass
class MaximumNumberOfTrailsExceededException(BotoServerError):
"""
Raised when no more trails can be created.
"""
pass
class InsufficientS3BucketPolicyException(BotoServerError):
"""
Raised when the S3 bucket does not allow Cloudtrail to
write files into the prefix.
"""
pass
class InvalidMaxResultsException(BotoServerError):
pass
class InvalidTimeRangeException(BotoServerError):
pass
class InvalidLookupAttributesException(BotoServerError):
pass
class InvalidCloudWatchLogsLogGroupArnException(BotoServerError):
pass
class InvalidCloudWatchLogsRoleArnException(BotoServerError):
pass
class CloudWatchLogsDeliveryUnavailableException(BotoServerError):
pass
class InvalidNextTokenException(BotoServerError):
pass
|
apache-2.0
|
[
624,
199,
16836,
626,
787,
2488,
370,
314,
8002,
15732,
859,
14,
199,
624,
199,
504,
6055,
14,
1971,
492,
24411,
17692,
421,
199,
533,
6378,
51,
561,
12157,
985,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
376,
3866,
428,
2709,
7482,
536,
365,
3032,
370,
8142,
15732,
14,
272,
408,
272,
986,
421,
199,
533,
6378,
51,
19,
12311,
985,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
376,
3866,
428,
19,
5315,
536,
365,
3032,
370,
8142,
15732,
14,
272,
408,
272,
986,
421,
199,
533,
12643,
382,
16760,
7965,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
314,
1627,
27225,
536,
2575,
3495,
14,
272,
408,
272,
986,
421,
199,
533,
12062,
12983,
51,
561,
12157,
4845,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
314,
428,
2709,
7482,
1630,
440,
2040,
8142,
15732,
370,
2963,
272,
3788,
14,
272,
408,
272,
986,
421,
199,
533,
6378,
2437,
382,
985,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
314,
27225,
536,
365,
3866,
14,
272,
408,
272,
986,
421,
199,
533,
12624,
547,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
2337,
1990,
376,
5007,
8142,
15732,
1125,
14,
272,
408,
272,
986,
421,
199,
533,
12643,
382,
22646,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
314,
1627,
27225,
536,
365,
440,
1911,
14,
272,
408,
272,
986,
421,
199,
533,
428,
19,
12311,
7400,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
314,
1627,
428,
19,
5315,
1630,
440,
2187,
14,
272,
408,
272,
986,
421,
199,
533,
12643,
382,
1763,
919,
11923,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
949,
27225,
536,
1990,
2741,
14,
272,
408,
272,
986,
421,
199,
533,
6378,
51,
19,
4793,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
376,
3866,
790,
2403,
365,
1627,
14,
272,
408,
272,
986,
421,
199,
533,
14212,
16030,
2437,
17841,
24748,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
949,
1655,
1468,
17841,
883,
506,
2737,
14,
272,
408,
272,
986,
421,
199,
533,
12062,
12983,
51,
19,
12311,
4845,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
314,
428,
19,
5315,
1630,
440,
2040,
8142,
15732,
370,
272,
2218,
1584,
1901,
314,
2403,
14,
272,
408,
272,
986,
421,
199,
533,
6378,
4261,
6579,
1726,
8,
20380,
17692,
304,
272,
986,
421,
199,
533,
6378,
1366,
4709,
1726,
8,
20380,
17692,
304,
272,
986,
421,
199,
533,
6378,
7521,
5379,
1726,
8,
20380,
17692,
304,
272,
986,
421,
199,
533,
6378,
9089,
13978,
16333,
2445,
2448,
20498,
1726,
8,
20380,
17692,
304,
272,
986,
421,
199,
533,
6378,
9089,
13978,
16333,
7422,
20498,
1726,
8,
20380,
17692,
304,
272,
986,
421,
199,
533,
8142,
13978,
16333,
24640,
28049,
1726,
8,
20380,
17692,
304,
272,
986,
421,
199,
533,
6378,
5765,
3264,
1726,
8,
20380,
17692,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
16836,
626,
787,
2488,
370,
314,
8002,
15732,
859,
14,
199,
624,
199,
504,
6055,
14,
1971,
492,
24411,
17692,
421,
199,
533,
6378,
51,
561,
12157,
985,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
376,
3866,
428,
2709,
7482,
536,
365,
3032,
370,
8142,
15732,
14,
272,
408,
272,
986,
421,
199,
533,
6378,
51,
19,
12311,
985,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
376,
3866,
428,
19,
5315,
536,
365,
3032,
370,
8142,
15732,
14,
272,
408,
272,
986,
421,
199,
533,
12643,
382,
16760,
7965,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
314,
1627,
27225,
536,
2575,
3495,
14,
272,
408,
272,
986,
421,
199,
533,
12062,
12983,
51,
561,
12157,
4845,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
314,
428,
2709,
7482,
1630,
440,
2040,
8142,
15732,
370,
2963,
272,
3788,
14,
272,
408,
272,
986,
421,
199,
533,
6378,
2437,
382,
985,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
314,
27225,
536,
365,
3866,
14,
272,
408,
272,
986,
421,
199,
533,
12624,
547,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
2337,
1990,
376,
5007,
8142,
15732,
1125,
14,
272,
408,
272,
986,
421,
199,
533,
12643,
382,
22646,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
314,
1627,
27225,
536,
365,
440,
1911,
14,
272,
408,
272,
986,
421,
199,
533,
428,
19,
12311,
7400,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
314,
1627,
428,
19,
5315,
1630,
440,
2187,
14,
272,
408,
272,
986,
421,
199,
533,
12643,
382,
1763,
919,
11923,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
949,
27225,
536,
1990,
2741,
14,
272,
408,
272,
986,
421,
199,
533,
6378,
51,
19,
4793,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
376,
3866,
790,
2403,
365,
1627,
14,
272,
408,
272,
986,
421,
199,
533,
14212,
16030,
2437,
17841,
24748,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
949,
1655,
1468,
17841,
883,
506,
2737,
14,
272,
408,
272,
986,
421,
199,
533,
12062,
12983,
51,
19,
12311,
4845,
1726,
8,
20380,
17692,
304,
272,
408,
272,
24997,
1380,
314,
428,
19,
5315,
1630,
440,
2040,
8142,
15732,
370,
272,
2218,
1584,
1901,
314,
2403,
14,
272,
408,
272,
986,
421,
199,
533,
6378,
4261,
6579,
1726,
8,
20380,
17692,
304,
272,
986,
421,
199,
533,
6378,
1366,
4709,
1726,
8,
20380,
17692,
304,
272,
986,
421,
199,
533,
6378,
7521,
5379,
1726,
8,
20380,
17692,
304,
272,
986,
421,
199,
533,
6378,
9089,
13978,
16333,
2445,
2448,
20498,
1726,
8,
20380,
17692,
304,
272,
986,
421,
199,
533,
6378,
9089,
13978,
16333,
7422,
20498,
1726,
8,
20380,
17692,
304,
272,
986,
421,
199,
533,
8142,
13978,
16333,
24640,
28049,
1726,
8,
20380,
17692,
304,
272,
986,
421,
199,
533,
6378,
5765,
3264,
1726,
8,
20380,
17692,
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,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,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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
] |
hyvas/libgdx
|
extensions/gdx-freetype/jni/freetype-2.6.2/src/tools/docmaker/docbeauty.py
|
877
|
2642
|
#!/usr/bin/env python
#
# DocBeauty (c) 2003, 2004, 2008 David Turner <david@freetype.org>
#
# This program is used to beautify the documentation comments used
# in the FreeType 2 public headers.
#
from sources import *
from content import *
from utils import *
import utils
import sys, os, time, string, getopt
content_processor = ContentProcessor()
def beautify_block( block ):
if block.content:
content_processor.reset()
markups = content_processor.process_content( block.content )
text = []
first = 1
for markup in markups:
text.extend( markup.beautify( first ) )
first = 0
# now beautify the documentation "borders" themselves
lines = [" /*************************************************************************"]
for l in text:
lines.append( " *" + l )
lines.append( " */" )
block.lines = lines
def usage():
print "\nDocBeauty 0.1 Usage information\n"
print " docbeauty [options] file1 [file2 ...]\n"
print "using the following options:\n"
print " -h : print this page"
print " -b : backup original files with the 'orig' extension"
print ""
print " --backup : same as -b"
def main( argv ):
"""main program loop"""
global output_dir
try:
opts, args = getopt.getopt( sys.argv[1:], \
"hb", \
["help", "backup"] )
except getopt.GetoptError:
usage()
sys.exit( 2 )
if args == []:
usage()
sys.exit( 1 )
# process options
#
output_dir = None
do_backup = None
for opt in opts:
if opt[0] in ( "-h", "--help" ):
usage()
sys.exit( 0 )
if opt[0] in ( "-b", "--backup" ):
do_backup = 1
# create context and processor
source_processor = SourceProcessor()
# retrieve the list of files to process
file_list = make_file_list( args )
for filename in file_list:
source_processor.parse_file( filename )
for block in source_processor.blocks:
beautify_block( block )
new_name = filename + ".new"
ok = None
try:
file = open( new_name, "wt" )
for block in source_processor.blocks:
for line in block.lines:
file.write( line )
file.write( "\n" )
file.close()
except:
ok = 0
# if called from the command line
#
if __name__ == '__main__':
main( sys.argv )
# eof
|
apache-2.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
221,
5454,
3655,
6898,
89,
334,
67,
9,
13004,
12,
8353,
12,
9079,
20232,
16147,
281,
665,
983,
5017,
32,
4624,
466,
14,
1308,
30,
199,
3,
199,
3,
961,
2240,
365,
1202,
370,
506,
65,
935,
1399,
314,
3794,
6786,
1202,
199,
3,
315,
314,
2868,
804,
499,
4575,
2323,
14,
199,
3,
199,
199,
504,
5274,
492,
627,
199,
504,
1564,
492,
627,
199,
504,
3778,
257,
492,
627,
199,
199,
646,
3778,
199,
199,
646,
984,
12,
747,
12,
900,
12,
1059,
12,
12733,
421,
199,
1317,
63,
6459,
275,
6646,
10438,
342,
421,
199,
318,
221,
506,
65,
935,
1399,
63,
1457,
8,
1853,
3461,
272,
340,
1853,
14,
1317,
26,
267,
1564,
63,
6459,
14,
3958,
342,
398,
9189,
83,
275,
1564,
63,
6459,
14,
1412,
63,
1317,
8,
1853,
14,
1317,
776,
267,
1318,
259,
275,
942,
267,
1642,
257,
275,
413,
398,
367,
9189,
315,
9189,
83,
26,
288,
1318,
14,
2880,
8,
9189,
14,
30745,
935,
1399,
8,
1642,
776,
776,
288,
1642,
275,
378,
398,
327,
3063,
506,
65,
935,
1399,
314,
3794,
298,
8665,
83,
2,
17279,
267,
2385,
275,
2097,
1182,
14355,
10,
937,
267,
367,
634,
315,
1318,
26,
288,
2385,
14,
740,
8,
298,
221,
14390,
435,
634,
776,
267,
2385,
14,
740,
8,
298,
221,
627,
6687,
776,
398,
1853,
14,
1278,
275,
2385,
421,
199,
318,
221,
4503,
837,
272,
870,
1867,
78,
3768,
3655,
6898,
89,
378,
14,
17,
11028,
2556,
60,
78,
2,
272,
870,
298,
221,
1382,
1235,
6898,
89,
359,
1419,
61,
570,
17,
359,
493,
18,
2263,
7272,
78,
2,
272,
870,
298,
4941,
314,
2569,
1511,
3427,
78,
2,
272,
870,
298,
221,
446,
72,
520,
870,
642,
2034,
2,
272,
870,
298,
221,
446,
66,
520,
6902,
3379,
1584,
543,
314,
283,
2981,
7,
3329,
2,
272,
870,
3087,
272,
870,
298,
221,
1553,
5751,
520,
2011,
465,
446,
66,
2,
421,
199,
318,
221,
2446,
8,
9238,
3461,
272,
408,
973,
2240,
4438,
624,
339,
2288,
1072,
63,
694,
339,
862,
26,
267,
3999,
12,
1249,
275,
12733,
14,
18907,
8,
984,
14,
3020,
59,
17,
8429,
971,
2511,
298,
16168,
401,
260,
971,
2511,
2097,
3437,
401,
298,
5751,
937,
776,
272,
871,
12733,
14,
1002,
29368,
26,
267,
4503,
342,
267,
984,
14,
2224,
8,
499,
776,
339,
340,
1249,
508,
18410,
267,
4503,
342,
267,
984,
14,
2224,
8,
413,
776,
339,
327,
2112,
1511,
272,
327,
272,
1072,
63,
694,
275,
488,
272,
886,
63,
5751,
221,
275,
488,
339,
367,
2450,
315,
3999,
26,
267,
340,
2450,
59,
16,
61,
315,
334,
3905,
72,
401,
4320,
3437,
2,
3461,
288,
4503,
342,
288,
984,
14,
2224,
8,
378,
776,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
66,
401,
4320,
5751,
2,
3461,
288,
886,
63,
5751,
275,
413,
339,
327,
1218,
1067,
436,
12495,
272,
1350,
63,
6459,
275,
5800,
10438,
342,
339,
327,
8044,
314,
769,
402,
1584,
370,
2112,
272,
570,
63,
513,
275,
1852,
63,
493,
63,
513,
8,
1249,
776,
272,
367,
1788,
315,
570,
63,
513,
26,
267,
1350,
63,
6459,
14,
1122,
63,
493,
8,
1788,
776,
398,
367,
1853,
315,
1350,
63,
6459,
14,
4166,
26,
288,
506,
65,
935,
1399,
63,
1457,
8,
1853,
776,
398,
892,
63,
354,
275,
1788,
435,
3680,
1222,
2,
267,
4112,
755,
275,
488,
398,
862,
26,
288,
570,
275,
1551,
8,
892,
63,
354,
12,
298,
9115,
2,
776,
288,
367,
1853,
315,
1350,
63,
6459,
14,
4166,
26,
355,
367,
1004,
315,
1853,
14,
1278,
26,
490,
570,
14,
952,
8,
1004,
776,
490,
570,
14,
952,
8,
1867,
78,
2,
776,
288,
570,
14,
1600,
342,
267,
871,
26,
288,
4112,
275,
378,
421,
199,
3,
340,
2797,
687,
314,
1414,
1004,
199,
3,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
8,
984,
14,
3020,
776,
421,
199,
3,
29403,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
199,
3,
221,
5454,
3655,
6898,
89,
334,
67,
9,
13004,
12,
8353,
12,
9079,
20232,
16147,
281,
665,
983,
5017,
32,
4624,
466,
14,
1308,
30,
199,
3,
199,
3,
961,
2240,
365,
1202,
370,
506,
65,
935,
1399,
314,
3794,
6786,
1202,
199,
3,
315,
314,
2868,
804,
499,
4575,
2323,
14,
199,
3,
199,
199,
504,
5274,
492,
627,
199,
504,
1564,
492,
627,
199,
504,
3778,
257,
492,
627,
199,
199,
646,
3778,
199,
199,
646,
984,
12,
747,
12,
900,
12,
1059,
12,
12733,
421,
199,
1317,
63,
6459,
275,
6646,
10438,
342,
421,
199,
318,
221,
506,
65,
935,
1399,
63,
1457,
8,
1853,
3461,
272,
340,
1853,
14,
1317,
26,
267,
1564,
63,
6459,
14,
3958,
342,
398,
9189,
83,
275,
1564,
63,
6459,
14,
1412,
63,
1317,
8,
1853,
14,
1317,
776,
267,
1318,
259,
275,
942,
267,
1642,
257,
275,
413,
398,
367,
9189,
315,
9189,
83,
26,
288,
1318,
14,
2880,
8,
9189,
14,
30745,
935,
1399,
8,
1642,
776,
776,
288,
1642,
275,
378,
398,
327,
3063,
506,
65,
935,
1399,
314,
3794,
298,
8665,
83,
2,
17279,
267,
2385,
275,
2097,
1182,
14355,
10,
937,
267,
367,
634,
315,
1318,
26,
288,
2385,
14,
740,
8,
298,
221,
14390,
435,
634,
776,
267,
2385,
14,
740,
8,
298,
221,
627,
6687,
776,
398,
1853,
14,
1278,
275,
2385,
421,
199,
318,
221,
4503,
837,
272,
870,
1867,
78,
3768,
3655,
6898,
89,
378,
14,
17,
11028,
2556,
60,
78,
2,
272,
870,
298,
221,
1382,
1235,
6898,
89,
359,
1419,
61,
570,
17,
359,
493,
18,
2263,
7272,
78,
2,
272,
870,
298,
4941,
314,
2569,
1511,
3427,
78,
2,
272,
870,
298,
221,
446,
72,
520,
870,
642,
2034,
2,
272,
870,
298,
221,
446,
66,
520,
6902,
3379,
1584,
543,
314,
283,
2981,
7,
3329,
2,
272,
870,
3087,
272,
870,
298,
221,
1553,
5751,
520,
2011,
465,
446,
66,
2,
421,
199,
318,
221,
2446,
8,
9238,
3461,
272,
408,
973,
2240,
4438,
624,
339,
2288,
1072,
63,
694,
339,
862,
26,
267,
3999,
12,
1249,
275,
12733,
14,
18907,
8,
984,
14,
3020,
59,
17,
8429,
971,
2511,
298,
16168,
401,
260,
971,
2511,
2097,
3437,
401,
298,
5751,
937,
776,
272,
871,
12733,
14,
1002,
29368,
26,
267,
4503,
342,
267,
984,
14,
2224,
8,
499,
776,
339,
340,
1249,
508,
18410,
267,
4503,
342,
267,
984,
14,
2224,
8,
413,
776,
339,
327,
2112,
1511,
272,
327,
272,
1072,
63,
694,
275,
488,
272,
886,
63,
5751,
221,
275,
488,
339,
367,
2450,
315,
3999,
26,
267,
340,
2450,
59,
16,
61,
315,
334,
3905,
72,
401,
4320,
3437,
2,
3461,
288,
4503,
342,
288,
984,
14,
2224,
8,
378,
776,
398,
340,
2450,
59,
16,
61,
315,
334,
3905,
66,
401,
4320,
5751,
2,
3461,
288,
886,
63,
5751,
275,
413,
339,
327,
1218,
1067,
436,
12495,
272,
1350,
63,
6459,
275,
5800,
10438,
342,
339,
327,
8044,
314,
769,
402,
1584,
370,
2112,
272,
570,
63,
513,
275,
1852,
63,
493,
63,
513,
8,
1249,
776,
272,
367,
1788,
315,
570,
63,
513,
26,
267,
1350,
63,
6459,
14,
1122,
63,
493,
8,
1788,
776,
398,
367,
1853,
315,
1350,
63,
6459,
14,
4166,
26,
288,
506,
65,
935,
1399,
63,
1457,
8,
1853,
776,
398,
892,
63,
354,
275,
1788,
435,
3680,
1222,
2,
267,
4112,
755,
275,
488,
398,
862,
26,
288,
570,
275,
1551,
8,
892,
63,
354,
12,
298,
9115,
2,
776,
288,
367,
1853,
315,
1350,
63,
6459,
14,
4166,
26,
355,
367,
1004,
315,
1853,
14,
1278,
26,
490,
570,
14,
952,
8,
1004,
776,
490,
570,
14,
952,
8,
1867,
78,
2,
776,
288,
570,
14,
1600,
342,
267,
871,
26,
288,
4112,
275,
378,
421,
199,
3,
340,
2797,
687,
314,
1414,
1004,
199,
3,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
2446,
8,
984,
14,
3020,
776,
421,
199,
3,
29403,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
odoousers2014/odoo
|
addons/hr/res_config.py
|
4
|
3547
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Business Applications
# Copyright (C) 2004-2012 OpenERP S.A. (<http://openerp.com>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import fields, osv
class hr_config_settings(osv.osv_memory):
_name = 'hr.config.settings'
_inherit = 'res.config.settings'
_columns = {
'module_hr_timesheet_sheet': fields.boolean('Allow timesheets validation by managers',
help ="""This installs the module hr_timesheet_sheet."""),
'module_hr_attendance': fields.boolean('Install attendances feature',
help ="""This installs the module hr_attendance."""),
'module_hr_timesheet': fields.boolean('Manage timesheets',
help ="""This installs the module hr_timesheet."""),
'module_hr_holidays': fields.boolean('Manage holidays, leaves and allocation requests',
help ="""This installs the module hr_holidays."""),
'module_hr_expense': fields.boolean('Manage employees expenses',
help ="""This installs the module hr_expense."""),
'module_hr_recruitment': fields.boolean('Manage the recruitment process',
help ="""This installs the module hr_recruitment."""),
'module_hr_contract': fields.boolean('Record contracts per employee',
help ="""This installs the module hr_contract."""),
'module_hr_evaluation': fields.boolean('Organize employees periodic evaluation',
help ="""This installs the module hr_evaluation."""),
'module_hr_gamification': fields.boolean('Drive engagement with challenges and badges',
help ="""This installs the module hr_gamification."""),
'module_account_analytic_analysis': fields.boolean('Allow invoicing based on timesheets (the sale application will be installed)',
help ="""This installs the module account_analytic_analysis, which will install sales management too."""),
'module_hr_payroll': fields.boolean('Manage payroll',
help ="""This installs the module hr_payroll."""),
'module_website_hr_recruitment': fields.boolean('Publish jobs on your website',
help ="""This installs the module website_hr_recruitment"""),
}
def onchange_hr_timesheet(self, cr, uid, ids, timesheet, context=None):
""" module_hr_timesheet implies module_hr_attendance """
if timesheet:
return {'value': {'module_hr_attendance': True}}
return {}
def onchange_hr_attendance(self, cr, uid, ids, attendance, context=None):
""" module_hr_timesheet implies module_hr_attendance """
if not attendance:
return {'value': {'module_hr_timesheet': False}}
return {}
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
23813,
24636,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
7409,
7653,
428,
14,
33,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
16140,
63,
888,
63,
1751,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
283,
6271,
14,
888,
14,
1751,
7,
272,
485,
6486,
275,
283,
470,
14,
888,
14,
1751,
7,
339,
485,
3406,
275,
469,
267,
283,
578,
63,
6271,
63,
17739,
63,
5069,
356,
1504,
14,
4871,
360,
7852,
900,
24376,
6411,
701,
19680,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
17739,
63,
5069,
1041,
395,
267,
283,
578,
63,
6271,
63,
23985,
356,
1504,
14,
4871,
360,
8154,
737,
7169,
13236,
3878,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
23985,
1041,
395,
267,
283,
578,
63,
6271,
63,
17739,
356,
1504,
14,
4871,
360,
20588,
900,
24376,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
17739,
1041,
395,
267,
283,
578,
63,
6271,
63,
26131,
356,
1504,
14,
4871,
360,
20588,
26475,
4899,
12,
16733,
436,
18723,
4145,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
26131,
1041,
395,
267,
283,
578,
63,
6271,
63,
16886,
356,
1504,
14,
4871,
360,
20588,
9052,
18149,
26963,
83,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
16886,
1041,
395,
267,
283,
578,
63,
6271,
63,
264,
31365,
434,
356,
1504,
14,
4871,
360,
20588,
314,
295,
31365,
434,
2112,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
264,
31365,
434,
1041,
395,
267,
283,
578,
63,
6271,
63,
14624,
356,
1504,
14,
4871,
360,
5433,
18782,
3021,
1126,
15778,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
14624,
1041,
395,
267,
283,
578,
63,
6271,
63,
19154,
356,
1504,
14,
4871,
360,
11014,
290,
794,
9052,
18149,
18745,
11735,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
19154,
1041,
395,
267,
283,
578,
63,
6271,
63,
17740,
7313,
356,
1504,
14,
4871,
360,
24276,
20171,
4103,
543,
682,
30599,
436,
4875,
3389,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
17740,
7313,
1041,
395,
267,
283,
578,
63,
2048,
63,
9782,
63,
10466,
356,
1504,
14,
4871,
360,
7852,
315,
2392,
31713,
4079,
641,
900,
24376,
334,
1589,
13590,
4223,
911,
506,
4903,
3196,
288,
1720,
275,
624,
2765,
25801,
314,
859,
2933,
63,
9782,
63,
10466,
12,
1314,
911,
3907,
21702,
10041,
4634,
1041,
395,
267,
283,
578,
63,
6271,
63,
5989,
2827,
356,
1504,
14,
4871,
360,
20588,
8633,
2827,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
5989,
2827,
1041,
395,
267,
283,
578,
63,
7360,
63,
6271,
63,
264,
31365,
434,
356,
1504,
14,
4871,
360,
13956,
9643,
641,
2195,
10691,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
10691,
63,
6271,
63,
264,
31365,
434,
624,
395,
272,
789,
339,
347,
20258,
63,
6271,
63,
17739,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
900,
5069,
12,
1067,
29,
403,
304,
267,
408,
859,
63,
6271,
63,
17739,
22660,
859,
63,
6271,
63,
23985,
408,
267,
340,
900,
5069,
26,
288,
372,
791,
585,
356,
791,
578,
63,
6271,
63,
23985,
356,
715,
4863,
267,
372,
1052,
339,
347,
20258,
63,
6271,
63,
23985,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
737,
7169,
554,
12,
1067,
29,
403,
304,
267,
408,
859,
63,
6271,
63,
17739,
22660,
859,
63,
6271,
63,
23985,
408,
267,
340,
440,
737,
7169,
554,
26,
288,
372,
791,
585,
356,
791,
578,
63,
6271,
63,
17739,
356,
756,
4863,
267,
372,
1052,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
199,
3,
259,
7653,
12,
3232,
5800,
23813,
24636,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
7409,
7653,
428,
14,
33,
14,
8642,
1014,
921,
11267,
14,
957,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
199,
3,
199,
4605,
199,
199,
504,
5166,
14,
4795,
492,
1504,
12,
9506,
199,
199,
533,
16140,
63,
888,
63,
1751,
8,
4795,
14,
4795,
63,
4844,
304,
272,
485,
354,
275,
283,
6271,
14,
888,
14,
1751,
7,
272,
485,
6486,
275,
283,
470,
14,
888,
14,
1751,
7,
339,
485,
3406,
275,
469,
267,
283,
578,
63,
6271,
63,
17739,
63,
5069,
356,
1504,
14,
4871,
360,
7852,
900,
24376,
6411,
701,
19680,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
17739,
63,
5069,
1041,
395,
267,
283,
578,
63,
6271,
63,
23985,
356,
1504,
14,
4871,
360,
8154,
737,
7169,
13236,
3878,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
23985,
1041,
395,
267,
283,
578,
63,
6271,
63,
17739,
356,
1504,
14,
4871,
360,
20588,
900,
24376,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
17739,
1041,
395,
267,
283,
578,
63,
6271,
63,
26131,
356,
1504,
14,
4871,
360,
20588,
26475,
4899,
12,
16733,
436,
18723,
4145,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
26131,
1041,
395,
267,
283,
578,
63,
6271,
63,
16886,
356,
1504,
14,
4871,
360,
20588,
9052,
18149,
26963,
83,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
16886,
1041,
395,
267,
283,
578,
63,
6271,
63,
264,
31365,
434,
356,
1504,
14,
4871,
360,
20588,
314,
295,
31365,
434,
2112,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
264,
31365,
434,
1041,
395,
267,
283,
578,
63,
6271,
63,
14624,
356,
1504,
14,
4871,
360,
5433,
18782,
3021,
1126,
15778,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
14624,
1041,
395,
267,
283,
578,
63,
6271,
63,
19154,
356,
1504,
14,
4871,
360,
11014,
290,
794,
9052,
18149,
18745,
11735,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
19154,
1041,
395,
267,
283,
578,
63,
6271,
63,
17740,
7313,
356,
1504,
14,
4871,
360,
24276,
20171,
4103,
543,
682,
30599,
436,
4875,
3389,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
17740,
7313,
1041,
395,
267,
283,
578,
63,
2048,
63,
9782,
63,
10466,
356,
1504,
14,
4871,
360,
7852,
315,
2392,
31713,
4079,
641,
900,
24376,
334,
1589,
13590,
4223,
911,
506,
4903,
3196,
288,
1720,
275,
624,
2765,
25801,
314,
859,
2933,
63,
9782,
63,
10466,
12,
1314,
911,
3907,
21702,
10041,
4634,
1041,
395,
267,
283,
578,
63,
6271,
63,
5989,
2827,
356,
1504,
14,
4871,
360,
20588,
8633,
2827,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
16140,
63,
5989,
2827,
1041,
395,
267,
283,
578,
63,
7360,
63,
6271,
63,
264,
31365,
434,
356,
1504,
14,
4871,
360,
13956,
9643,
641,
2195,
10691,
297,
288,
1720,
275,
624,
2765,
25801,
314,
859,
10691,
63,
6271,
63,
264,
31365,
434,
624,
395,
272,
789,
339,
347,
20258,
63,
6271,
63,
17739,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
900,
5069,
12,
1067,
29,
403,
304,
267,
408,
859,
63,
6271,
63,
17739,
22660,
859,
63,
6271,
63,
23985,
408,
267,
340,
900,
5069,
26,
288,
372,
791,
585,
356,
791,
578,
63,
6271,
63,
23985,
356,
715,
4863,
267,
372,
1052,
339,
347,
20258,
63,
6271,
63,
23985,
8,
277,
12,
2467,
12,
1747,
12,
2762,
12,
737,
7169,
554,
12,
1067,
29,
403,
304,
267,
408,
859,
63,
6271,
63,
17739,
22660,
859,
63,
6271,
63,
23985,
408,
267,
340,
440,
737,
7169,
554,
26,
288,
372,
791,
585,
356,
791,
578,
63,
6271,
63,
17739,
356,
756,
4863,
267,
372,
1052,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
sepehr125/pybrain
|
pybrain/rl/environments/flexcube/viewer.py
|
25
|
10775
|
from __future__ import print_function
__author__ = 'Frank Sehnke, sehnke@in.tum.de'
#########################################################################
# OpenGL viewer for the FlexCube Environment
#
# The FlexCube Environment is a Mass-Spring-System composed of 8 mass points.
# These resemble a cube with flexible edges.
#
# This viewer uses an UDP connection found in tools/networking/udpconnection.py
#
# The viewer recieves the position matrix of the 8 masspoints and the center of gravity.
# With this information it renders a Glut based 3d visualization of teh FlexCube
#
# Options:
# - serverIP: The ip of the server to which the viewer should connect
# - ownIP: The IP of the computer running the viewer
# - port: The starting port (2 adjacent ports will be used)
#
# Saving the images is possible by setting self.savePics=True.
# Changing the point and angle of view is possible by using the mouse
# while button 1 or 2 pressed.
#
# Requirements: OpenGL
#
#########################################################################
from OpenGL.GLUT import * #@UnusedWildImport
from OpenGL.GL import * #@UnusedWildImport
from OpenGL.GLE import * #@UnusedWildImport
from OpenGL.GLU import * #@UnusedWildImport
from . import objects3d
from time import sleep
from scipy import ones, array
from pybrain.tools.networking.udpconnection import UDPClient
class FlexCubeRenderer(object):
#Options: ServerIP(default:localhost), OwnIP(default:localhost), Port(default:21560)
def __init__(self, servIP="127.0.0.1", ownIP="127.0.0.1", port="21560"):
self.oldScreenValues = None
self.view = 0
self.worldRadius = 400
# Start of mousepointer
self.lastx = 0
self.lasty = 15
self.lastz = 300
self.zDis = 1
# Start of cube
self.cube = [0.0, 0.0, 0.0]
self.bmpCount = 0
self.actCount = 0
self.calcPhysics = 0
self.newPic = 1
self.picCount = 0
self.target = array([80.0, 0.0, 0.0])
self.centerOfGrav = array([0.0, -2.0, 0.0])
self.points = ones((8, 3), float)
self.savePics = False
self.drawCounter = 0
self.fps = 25
self.dt = 1.0 / float(self.fps)
self.client = UDPClient(servIP, ownIP, port)
# If self.savePics=True this method saves the produced images
def saveTo(self, filename, format="JPEG"):
import Image # get PIL's functionality... @UnresolvedImport
width, height = 800, 600
glPixelStorei(GL_PACK_ALIGNMENT, 1)
data = glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE)
image = Image.fromstring("RGB", (width, height), data)
image = image.transpose(Image.FLIP_TOP_BOTTOM)
image.save(filename, format)
print(('Saved image to ', filename))
return image
# the render method containing the Glut mainloop
def _render(self):
# Call init: Parameter(Window Position -> x, y, height, width)
self.init_GL(self, 300, 300, 800, 600)
self.object = objects3d.Objects3D()
self.quad = gluNewQuadric()
glutMainLoop()
# The Glut idle function
def drawIdleScene(self):
#recive data from server and update the points of the cube
try:
self.points, self.centerOfGrav = eval(self.client.listen([self.points, self.centerOfGrav]))
except: pass
if self.points == "r":
self.target = array([80.0, 0.0, 0.0])
self.centerOfGrav = array([0.0, -2.0, 0.0])
self.points = ones((8, 3), float)
self.drawScene()
if self.savePics:
self.saveTo("./screenshots/image_jump" + repr(10000 + self.picCount) + ".jpg")
self.picCount += 1
else: sleep(self.dt)
def drawScene(self):
''' This methode describes the complete scene.'''
# clear the buffer
if self.zDis < 10: self.zDis += 0.25
if self.lastz > 200: self.lastz -= self.zDis
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glLoadIdentity()
# Point of view
glRotatef(self.lastx, 0.0, 1.0, 0.0)
glRotatef(self.lasty, 1.0, 0.0, 0.0)
#glRotatef(15, 0.0, 0.0, 1.0)
# direction of view is aimed to the center of gravity of the cube
glTranslatef(-self.centerOfGrav[0], -self.centerOfGrav[1] - 50.0, -self.centerOfGrav[2] - self.lastz)
#Objects
#Target Ball
glColor3f(1, 0.25, 0.25)
glPushMatrix()
glTranslate(self.target[0], 0.0, self.target[2])
glutSolidSphere(1.5, 8, 8)
glPopMatrix()
#Massstab
for lk in range(41):
if float(lk - 20) / 10.0 == (lk - 20) / 10:
glColor3f(0.75, 0.75, 0.75)
glPushMatrix()
glRotatef(90, 1, 0, 0)
glTranslate(self.worldRadius / 40.0 * float(lk) - self.worldRadius / 2.0, -40.0, -30)
quad = gluNewQuadric()
gluCylinder(quad, 2, 2, 60, 4, 1);
glPopMatrix()
else:
if float(lk - 20) / 5.0 == (lk - 20) / 5:
glColor3f(0.75, 0.75, 0.75)
glPushMatrix()
glRotatef(90, 1, 0, 0)
glTranslate(self.worldRadius / 40.0 * float(lk) - self.worldRadius / 2.0, -40.0, -15.0)
quad = gluNewQuadric()
gluCylinder(quad, 1, 1, 30, 4, 1);
glPopMatrix()
else:
glColor3f(0.75, 0.75, 0.75)
glPushMatrix()
glRotatef(90, 1, 0, 0)
glTranslate(self.worldRadius / 40.0 * float(lk) - self.worldRadius / 2.0, -40.0, -7.5)
quad = gluNewQuadric()
gluCylinder(quad, 0.5, 0.5, 15, 4, 1);
glPopMatrix()
#Mirror Center Ball
glColor3f(1, 1, 1)
glPushMatrix()
glTranslate(self.centerOfGrav[0], -self.centerOfGrav[1], self.centerOfGrav[2])
glutSolidSphere(1.5, 8, 8)
glPopMatrix()
#Mirror Cube
glEnable (GL_BLEND)
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glColor4f(0.5, 0.75, 0.5, 0.75)
glPushMatrix()
glTranslatef(0, -0.05, 0)
self.object.drawMirCreat(self.points, self.centerOfGrav)
glPopMatrix()
# Floor
tile = self.worldRadius / 40.0
glEnable (GL_BLEND)
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
for xF in range(40):
for yF in range(40):
if float(xF + yF) / 2.0 == (xF + yF) / 2: glColor3f(0.8, 0.8, 0.7)
else: glColor4f(0.8, 0.8, 0.8, 0.7)
glPushMatrix()
glTranslatef(0.0, -0.03, 0.0)
glBegin(GL_QUADS)
glNormal(0.0, 1.0, 0.0)
for i in range(2):
for k in range(2):
glVertex3f((i + xF - 20) * tile, 0.0, ((k ^ i) + yF - 20) * tile);
glEnd()
glPopMatrix()
#Center Ball
glColor3f(1, 1, 1)
glPushMatrix()
glTranslate(self.centerOfGrav[0], self.centerOfGrav[1], self.centerOfGrav[2])
glutSolidSphere(1.5, 8, 8)
glPopMatrix()
# Cube
glEnable (GL_BLEND)
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glColor4f(0.5, 0.75, 0.5, 0.75)
glPushMatrix()
self.object.drawCreature(self.points, self.centerOfGrav)
glPopMatrix()
glEnable (GL_BLEND)
glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
# Cubes shadow
glColor4f(0, 0, 0, 0.5)
glPushMatrix()
self.object.drawShadow(self.points, self.centerOfGrav)
glPopMatrix()
# swap the buffer
glutSwapBuffers()
def resizeScene(self, width, height):
'''Needed if window size changes.'''
if height == 0: # Prevent A Divide By Zero If The Window Is Too Small
height = 1
glViewport(0, 0, width, height) # Reset The Current Viewport And Perspective Transformation
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
gluPerspective(45.0, float(width) / float(height), 0.1, 700.0)
glMatrixMode(GL_MODELVIEW)
def activeMouse(self, x, y):
#Returns mouse coordinates while any mouse button is pressed.
# store the mouse coordinate
if self.mouseButton == GLUT_LEFT_BUTTON:
self.lastx = x - self.xOffset
self.lasty = y - self.yOffset
if self.mouseButton == GLUT_RIGHT_BUTTON:
self.lastz = y - self.zOffset
# redisplay
glutPostRedisplay()
def passiveMouse(self, x, y):
'''Returns mouse coordinates while no mouse button is pressed.'''
pass
def completeMouse(self, button, state, x, y):
#Returns mouse coordinates and which button was pressed resp. released.
self.mouseButton = button
if state == GLUT_DOWN:
self.xOffset = x - self.lastx
self.yOffset = y - self.lasty
self.zOffset = y - self.lastz
# redisplay
glutPostRedisplay()
#Initialise an OpenGL windows with the origin at x, y and size of height, width.
def init_GL(self, pyWorld, x, y, height, width):
# initialize GLUT
glutInit([])
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH)
glutInitWindowSize(height, width)
glutInitWindowPosition(x, y)
glutCreateWindow("The Curious Cube")
glClearDepth(1.0)
glEnable(GL_DEPTH_TEST)
glClearColor(0.0, 0.0, 0.0, 0.0)
glShadeModel(GL_SMOOTH)
glMatrixMode(GL_MODELVIEW)
# initialize lighting */
glLightfv(GL_LIGHT0, GL_DIFFUSE, [1, 1, 1, 1.0])
glLightModelfv(GL_LIGHT_MODEL_AMBIENT, [1.0, 1.0, 1.0, 1.0])
glEnable(GL_LIGHTING)
glEnable(GL_LIGHT0)
#
glColorMaterial(GL_FRONT, GL_DIFFUSE)
glEnable(GL_COLOR_MATERIAL)
# Automatic vector normalise
glEnable(GL_NORMALIZE)
### Instantiate the virtual world ###
glutDisplayFunc(pyWorld.drawScene)
glutMotionFunc(pyWorld.activeMouse)
glutMouseFunc(pyWorld.completeMouse)
glutReshapeFunc(pyWorld.resizeScene)
glutIdleFunc(pyWorld.drawIdleScene)
if __name__ == '__main__':
s = sys.argv[1:]
r = FlexCubeRenderer(*s)
r._render()
|
bsd-3-clause
|
[
504,
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
363,
2502,
363,
275,
283,
38,
4648,
3240,
6164,
415,
12,
542,
6164,
415,
32,
262,
14,
84,
453,
14,
271,
7,
199,
199,
3949,
3,
199,
3,
24374,
27354,
367,
314,
481,
3113,
25043,
9711,
221,
199,
3,
199,
3,
710,
481,
3113,
25043,
9711,
365,
282,
603,
405,
13,
51,
2700,
316,
13,
3989,
26356,
402,
1695,
12250,
4501,
14,
199,
3,
5723,
295,
8834,
282,
15681,
543,
26841,
8207,
14,
199,
3,
199,
3,
961,
27354,
4440,
376,
21802,
1950,
1911,
315,
7249,
15,
1200,
316,
15,
15036,
2105,
14,
647,
199,
3,
199,
3,
710,
27354,
295,
559,
69,
2310,
314,
3421,
3634,
402,
314,
1695,
12250,
3438,
436,
314,
8126,
402,
1999,
18936,
14,
199,
3,
8777,
642,
2556,
652,
3795,
83,
282,
598,
30562,
4079,
650,
68,
13104,
2072,
402,
1565,
72,
481,
3113,
25043,
199,
3,
199,
3,
8394,
26,
221,
199,
3,
446,
1654,
1772,
26,
710,
3384,
402,
314,
1654,
370,
1314,
314,
27354,
1077,
4907,
199,
3,
446,
5705,
1772,
26,
710,
3531,
402,
314,
24189,
3879,
314,
27354,
199,
3,
446,
1844,
26,
710,
6617,
1844,
334,
18,
24113,
8873,
911,
506,
1202,
9,
199,
3,
199,
3,
428,
5519,
314,
5935,
365,
3962,
701,
4260,
291,
14,
2117,
48,
2932,
29,
549,
14,
199,
3,
27854,
314,
2376,
436,
9324,
402,
2455,
365,
3962,
701,
1808,
314,
12817,
221,
199,
3,
1830,
5528,
413,
503,
499,
25167,
14,
199,
3,
221,
199,
3,
18513,
1470,
26,
24374,
199,
3,
199,
3949,
3,
199,
199,
504,
24374,
14,
2226,
934,
492,
627,
9213,
20782,
55,
668,
6295,
199,
504,
24374,
14,
2226,
492,
627,
9213,
20782,
55,
668,
6295,
199,
504,
24374,
14,
12827,
492,
627,
9213,
20782,
55,
668,
6295,
199,
504,
24374,
14,
20935,
492,
627,
9213,
20782,
55,
668,
6295,
199,
504,
1275,
492,
2251,
19,
68,
199,
504,
900,
492,
9435,
199,
504,
7026,
492,
7869,
12,
1625,
199,
504,
1134,
22246,
14,
2537,
14,
1200,
316,
14,
15036,
2105,
492,
21802,
3041,
199,
199,
533,
481,
3113,
25043,
11355,
8,
785,
304,
5591,
327,
4558,
26,
7146,
1772,
8,
885,
26,
5967,
395,
593,
3501,
1772,
8,
885,
26,
5967,
395,
10977,
8,
885,
26,
7842,
2259,
9,
272,
347,
636,
826,
721,
277,
12,
27415,
1772,
628,
4195,
14,
16,
14,
16,
14,
17,
401,
5705,
1772,
628,
4195,
14,
16,
14,
16,
14,
17,
401,
1844,
628,
7842,
2259,
2349,
267,
291,
14,
1753,
9616,
6550,
275,
488,
267,
291,
14,
1345,
275,
378,
267,
291,
14,
7617,
19800,
275,
8290,
2728,
327,
7707,
402,
12817,
3929,
4960,
291,
14,
2019,
88,
275,
378,
267,
291,
14,
2019,
89,
275,
4114,
267,
291,
14,
2019,
90,
275,
9601,
267,
291,
14,
90,
2825,
275,
413,
272,
267,
327,
7707,
402,
15681,
4960,
291,
14,
11477,
275,
359,
16,
14,
16,
12,
378,
14,
16,
12,
378,
14,
16,
61,
267,
291,
14,
22308,
2353,
275,
378,
267,
291,
14,
2442,
2353,
275,
378,
267,
291,
14,
8104,
6678,
17378,
275,
378,
267,
291,
14,
1222,
48,
530,
275,
413,
267,
291,
14,
12475,
2353,
275,
378,
267,
291,
14,
1375,
275,
1625,
779,
1257,
14,
16,
12,
378,
14,
16,
12,
378,
14,
16,
566,
2126,
267,
291,
14,
4218,
3466,
5761,
86,
275,
1625,
779,
16,
14,
16,
12,
446,
18,
14,
16,
12,
378,
14,
16,
566,
267,
291,
14,
3438,
275,
7869,
1332,
24,
12,
650,
395,
2069,
9,
267,
291,
14,
2117,
48,
2932,
275,
756,
267,
291,
14,
5485,
11348,
275,
378,
267,
291,
14,
24709,
275,
5661,
267,
291,
14,
3583,
275,
413,
14,
16,
1182,
2069,
8,
277,
14,
24709,
9,
398,
291,
14,
1258,
275,
21802,
3041,
8,
7297,
1772,
12,
5705,
1772,
12,
1844,
9,
339,
327,
982,
291,
14,
2117,
48,
2932,
29,
549,
642,
1083,
23050,
314,
13584,
5935,
755,
272,
347,
3354,
1378,
8,
277,
12,
1788,
12,
1475,
628,
28412,
2349,
267,
492,
6047,
327,
664,
14937,
1159,
9330,
1396,
768,
1358,
13697,
6295,
267,
3462,
12,
4569,
275,
23466,
12,
11624,
267,
6482,
14383,
5502,
73,
8,
2226,
63,
6961,
63,
15255,
4479,
12,
413,
9,
267,
666,
275,
6482,
3284,
29170,
8,
16,
12,
378,
12,
3462,
12,
4569,
12,
3563,
63,
12067,
12,
3563,
63,
30805,
63,
19714,
9,
267,
1834,
275,
6047,
14,
13521,
480,
12067,
401,
334,
2063,
12,
4569,
395,
666,
9,
267,
1834,
275,
1834,
14,
10483,
8,
3491,
14,
3143,
1772,
63,
11422,
63,
27838,
9,
267,
1834,
14,
2117,
8,
1501,
12,
1475,
9,
267,
870,
4725,
21969,
1834,
370,
1656,
1788,
430,
267,
372,
1834,
339,
327,
314,
3795,
1083,
3035,
314,
598,
30562,
2446,
3813,
272,
347,
485,
3352,
8,
277,
304,
267,
327,
6523,
4205,
26,
12009,
8,
4301,
15483,
1035,
671,
12,
612,
12,
4569,
12,
3462,
9,
267,
291,
14,
826,
63,
2226,
8,
277,
12,
9601,
12,
9601,
12,
23466,
12,
11624,
9,
27144,
291,
14,
785,
275,
2251,
19,
68,
14,
11188,
19,
36,
342,
267,
291,
14,
14567,
275,
6482,
85,
4665,
23053,
1567,
342,
267,
6482,
337,
6756,
7382,
342,
339,
327,
710,
598,
30562,
15072,
805,
272,
347,
5954,
21068,
14216,
8,
277,
304,
267,
327,
264,
559,
432,
666,
687,
1654,
436,
1678,
314,
4501,
402,
314,
15681,
267,
862,
26,
288,
291,
14,
3438,
12,
291,
14,
4218,
3466,
5761,
86,
275,
3468,
8,
277,
14,
1258,
14,
5859,
779,
277,
14,
3438,
12,
291,
14,
4218,
3466,
5761,
86,
2459,
267,
871,
26,
986,
267,
340,
291,
14,
3438,
508,
298,
82,
582,
288,
291,
14,
1375,
275,
1625,
779,
1257,
14,
16,
12,
378,
14,
16,
12,
378,
14,
16,
566,
288,
291,
14,
4218,
3466,
5761,
86,
275,
1625,
779,
16,
14,
16,
12,
446,
18,
14,
16,
12,
378,
14,
16,
566,
288,
291,
14,
3438,
275,
7869,
1332,
24,
12,
650,
395,
2069,
9,
267,
291,
14,
5485,
14216,
342,
267,
340,
291,
14,
2117,
48,
2932,
26,
288,
291,
14,
2117,
1378,
28615,
23269,
83,
15
] |
[
636,
2443,
363,
492,
870,
63,
1593,
199,
199,
363,
2502,
363,
275,
283,
38,
4648,
3240,
6164,
415,
12,
542,
6164,
415,
32,
262,
14,
84,
453,
14,
271,
7,
199,
199,
3949,
3,
199,
3,
24374,
27354,
367,
314,
481,
3113,
25043,
9711,
221,
199,
3,
199,
3,
710,
481,
3113,
25043,
9711,
365,
282,
603,
405,
13,
51,
2700,
316,
13,
3989,
26356,
402,
1695,
12250,
4501,
14,
199,
3,
5723,
295,
8834,
282,
15681,
543,
26841,
8207,
14,
199,
3,
199,
3,
961,
27354,
4440,
376,
21802,
1950,
1911,
315,
7249,
15,
1200,
316,
15,
15036,
2105,
14,
647,
199,
3,
199,
3,
710,
27354,
295,
559,
69,
2310,
314,
3421,
3634,
402,
314,
1695,
12250,
3438,
436,
314,
8126,
402,
1999,
18936,
14,
199,
3,
8777,
642,
2556,
652,
3795,
83,
282,
598,
30562,
4079,
650,
68,
13104,
2072,
402,
1565,
72,
481,
3113,
25043,
199,
3,
199,
3,
8394,
26,
221,
199,
3,
446,
1654,
1772,
26,
710,
3384,
402,
314,
1654,
370,
1314,
314,
27354,
1077,
4907,
199,
3,
446,
5705,
1772,
26,
710,
3531,
402,
314,
24189,
3879,
314,
27354,
199,
3,
446,
1844,
26,
710,
6617,
1844,
334,
18,
24113,
8873,
911,
506,
1202,
9,
199,
3,
199,
3,
428,
5519,
314,
5935,
365,
3962,
701,
4260,
291,
14,
2117,
48,
2932,
29,
549,
14,
199,
3,
27854,
314,
2376,
436,
9324,
402,
2455,
365,
3962,
701,
1808,
314,
12817,
221,
199,
3,
1830,
5528,
413,
503,
499,
25167,
14,
199,
3,
221,
199,
3,
18513,
1470,
26,
24374,
199,
3,
199,
3949,
3,
199,
199,
504,
24374,
14,
2226,
934,
492,
627,
9213,
20782,
55,
668,
6295,
199,
504,
24374,
14,
2226,
492,
627,
9213,
20782,
55,
668,
6295,
199,
504,
24374,
14,
12827,
492,
627,
9213,
20782,
55,
668,
6295,
199,
504,
24374,
14,
20935,
492,
627,
9213,
20782,
55,
668,
6295,
199,
504,
1275,
492,
2251,
19,
68,
199,
504,
900,
492,
9435,
199,
504,
7026,
492,
7869,
12,
1625,
199,
504,
1134,
22246,
14,
2537,
14,
1200,
316,
14,
15036,
2105,
492,
21802,
3041,
199,
199,
533,
481,
3113,
25043,
11355,
8,
785,
304,
5591,
327,
4558,
26,
7146,
1772,
8,
885,
26,
5967,
395,
593,
3501,
1772,
8,
885,
26,
5967,
395,
10977,
8,
885,
26,
7842,
2259,
9,
272,
347,
636,
826,
721,
277,
12,
27415,
1772,
628,
4195,
14,
16,
14,
16,
14,
17,
401,
5705,
1772,
628,
4195,
14,
16,
14,
16,
14,
17,
401,
1844,
628,
7842,
2259,
2349,
267,
291,
14,
1753,
9616,
6550,
275,
488,
267,
291,
14,
1345,
275,
378,
267,
291,
14,
7617,
19800,
275,
8290,
2728,
327,
7707,
402,
12817,
3929,
4960,
291,
14,
2019,
88,
275,
378,
267,
291,
14,
2019,
89,
275,
4114,
267,
291,
14,
2019,
90,
275,
9601,
267,
291,
14,
90,
2825,
275,
413,
272,
267,
327,
7707,
402,
15681,
4960,
291,
14,
11477,
275,
359,
16,
14,
16,
12,
378,
14,
16,
12,
378,
14,
16,
61,
267,
291,
14,
22308,
2353,
275,
378,
267,
291,
14,
2442,
2353,
275,
378,
267,
291,
14,
8104,
6678,
17378,
275,
378,
267,
291,
14,
1222,
48,
530,
275,
413,
267,
291,
14,
12475,
2353,
275,
378,
267,
291,
14,
1375,
275,
1625,
779,
1257,
14,
16,
12,
378,
14,
16,
12,
378,
14,
16,
566,
2126,
267,
291,
14,
4218,
3466,
5761,
86,
275,
1625,
779,
16,
14,
16,
12,
446,
18,
14,
16,
12,
378,
14,
16,
566,
267,
291,
14,
3438,
275,
7869,
1332,
24,
12,
650,
395,
2069,
9,
267,
291,
14,
2117,
48,
2932,
275,
756,
267,
291,
14,
5485,
11348,
275,
378,
267,
291,
14,
24709,
275,
5661,
267,
291,
14,
3583,
275,
413,
14,
16,
1182,
2069,
8,
277,
14,
24709,
9,
398,
291,
14,
1258,
275,
21802,
3041,
8,
7297,
1772,
12,
5705,
1772,
12,
1844,
9,
339,
327,
982,
291,
14,
2117,
48,
2932,
29,
549,
642,
1083,
23050,
314,
13584,
5935,
755,
272,
347,
3354,
1378,
8,
277,
12,
1788,
12,
1475,
628,
28412,
2349,
267,
492,
6047,
327,
664,
14937,
1159,
9330,
1396,
768,
1358,
13697,
6295,
267,
3462,
12,
4569,
275,
23466,
12,
11624,
267,
6482,
14383,
5502,
73,
8,
2226,
63,
6961,
63,
15255,
4479,
12,
413,
9,
267,
666,
275,
6482,
3284,
29170,
8,
16,
12,
378,
12,
3462,
12,
4569,
12,
3563,
63,
12067,
12,
3563,
63,
30805,
63,
19714,
9,
267,
1834,
275,
6047,
14,
13521,
480,
12067,
401,
334,
2063,
12,
4569,
395,
666,
9,
267,
1834,
275,
1834,
14,
10483,
8,
3491,
14,
3143,
1772,
63,
11422,
63,
27838,
9,
267,
1834,
14,
2117,
8,
1501,
12,
1475,
9,
267,
870,
4725,
21969,
1834,
370,
1656,
1788,
430,
267,
372,
1834,
339,
327,
314,
3795,
1083,
3035,
314,
598,
30562,
2446,
3813,
272,
347,
485,
3352,
8,
277,
304,
267,
327,
6523,
4205,
26,
12009,
8,
4301,
15483,
1035,
671,
12,
612,
12,
4569,
12,
3462,
9,
267,
291,
14,
826,
63,
2226,
8,
277,
12,
9601,
12,
9601,
12,
23466,
12,
11624,
9,
27144,
291,
14,
785,
275,
2251,
19,
68,
14,
11188,
19,
36,
342,
267,
291,
14,
14567,
275,
6482,
85,
4665,
23053,
1567,
342,
267,
6482,
337,
6756,
7382,
342,
339,
327,
710,
598,
30562,
15072,
805,
272,
347,
5954,
21068,
14216,
8,
277,
304,
267,
327,
264,
559,
432,
666,
687,
1654,
436,
1678,
314,
4501,
402,
314,
15681,
267,
862,
26,
288,
291,
14,
3438,
12,
291,
14,
4218,
3466,
5761,
86,
275,
3468,
8,
277,
14,
1258,
14,
5859,
779,
277,
14,
3438,
12,
291,
14,
4218,
3466,
5761,
86,
2459,
267,
871,
26,
986,
267,
340,
291,
14,
3438,
508,
298,
82,
582,
288,
291,
14,
1375,
275,
1625,
779,
1257,
14,
16,
12,
378,
14,
16,
12,
378,
14,
16,
566,
288,
291,
14,
4218,
3466,
5761,
86,
275,
1625,
779,
16,
14,
16,
12,
446,
18,
14,
16,
12,
378,
14,
16,
566,
288,
291,
14,
3438,
275,
7869,
1332,
24,
12,
650,
395,
2069,
9,
267,
291,
14,
5485,
14216,
342,
267,
340,
291,
14,
2117,
48,
2932,
26,
288,
291,
14,
2117,
1378,
28615,
23269,
83,
15,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
googleapis/google-cloud-php
|
Gaming/synth.py
|
2
|
2871
|
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This script is used to synthesize generated parts of this library."""
import synthtool as s
import synthtool.gcp as gcp
import logging
logging.basicConfig(level=logging.DEBUG)
gapic = gcp.GAPICBazel()
common = gcp.CommonTemplates()
library = gapic.php_library(
service='gaming',
version='v1',
bazel_target=f'//google/cloud/gaming/v1:google-cloud-gaming-v1-php',
)
# copy all src including partial veneer classes
s.move(library / 'src')
# copy proto files to src also
s.move(library / 'proto/src/Google/Cloud/Gaming', 'src/')
s.move(library / 'tests/')
# copy GPBMetadata file to metadata
s.move(library / 'proto/src/GPBMetadata/Google/Cloud/Gaming', 'metadata/')
# document and utilize apiEndpoint instead of serviceAddress
s.replace(
"**/Gapic/*GapicClient.php",
r"'serviceAddress' =>",
r"'apiEndpoint' =>")
s.replace(
"**/Gapic/*GapicClient.php",
r"@type string \$serviceAddress\n\s+\*\s+The address",
r"""@type string $serviceAddress
* **Deprecated**. This option will be removed in a future major release. Please
* utilize the `$apiEndpoint` option instead.
* @type string $apiEndpoint
* The address""")
s.replace(
"**/Gapic/*GapicClient.php",
r"\$transportConfig, and any \$serviceAddress",
r"$transportConfig, and any `$apiEndpoint`")
# fix year
s.replace(
'src/V1/**/*Client.php',
r'Copyright \d{4}',
r'Copyright 2020')
s.replace(
'tests/**/V1/*Test.php',
r'Copyright \d{4}',
r'Copyright 2020')
### [START] protoc backwards compatibility fixes
# roll back to private properties.
s.replace(
"src/**/V*/**/*.php",
r"Generated from protobuf field ([^\n]{0,})\n\s{5}\*/\n\s{4}protected \$",
r"""Generated from protobuf field \1
*/
private $""")
# prevent proto messages from being marked final
s.replace(
"src/**/V*/**/*.php",
r"final class",
r"class")
# Replace "Unwrapped" with "Value" for method names.
s.replace(
"src/**/V*/**/*.php",
r"public function ([s|g]\w{3,})Unwrapped",
r"public function \1Value"
)
### [END] protoc backwards compatibility fixes
# fix relative cloud.google.com links
s.replace(
"src/**/V*/**/*.php",
r"(.{0,})\]\((/.{0,})\)",
r"\1](https://cloud.google.com\2)"
)
|
apache-2.0
|
[
3,
1898,
25455,
4475,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
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,
2765,
2884,
365,
1202,
370,
9560,
1589,
890,
4046,
4184,
402,
642,
3555,
1041,
199,
199,
646,
9560,
273,
3557,
465,
308,
199,
646,
9560,
273,
3557,
14,
20622,
465,
22088,
199,
646,
2050,
199,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
5287,
9,
199,
199,
15046,
530,
275,
22088,
14,
39,
1282,
948,
19726,
352,
342,
199,
2330,
275,
22088,
14,
7844,
17969,
342,
199,
199,
4342,
275,
16301,
530,
14,
8624,
63,
4342,
8,
272,
2435,
534,
71,
9568,
297,
272,
1015,
534,
86,
17,
297,
272,
15507,
352,
63,
1375,
29,
70,
28866,
3098,
15,
4091,
15,
71,
9568,
15,
86,
17,
26,
3098,
13,
4091,
13,
71,
9568,
13,
86,
17,
13,
8624,
297,
199,
9,
199,
199,
3,
1331,
1006,
2928,
5893,
7417,
373,
6349,
281,
3992,
199,
83,
14,
1185,
8,
4342,
1182,
283,
2164,
358,
199,
199,
3,
1331,
4104,
1584,
370,
2928,
2597,
199,
83,
14,
1185,
8,
4342,
1182,
283,
2625,
15,
2164,
15,
13266,
15,
9089,
15,
39,
9568,
297,
283,
2164,
6217,
199,
83,
14,
1185,
8,
4342,
1182,
283,
2219,
6217,
199,
199,
3,
1331,
598,
13167,
5142,
570,
370,
3341,
199,
83,
14,
1185,
8,
4342,
1182,
283,
2625,
15,
2164,
15,
8225,
34,
5142,
15,
13266,
15,
9089,
15,
39,
9568,
297,
283,
2343,
6217,
199,
199,
3,
2213,
436,
7678,
13559,
2986,
11442,
3140,
402,
2435,
1476,
199,
83,
14,
1814,
8,
272,
298,
538,
15,
39,
20789,
6331,
39,
20789,
3041,
14,
8624,
401,
272,
519,
4507,
1364,
1476,
7,
275,
7166,
272,
519,
4507,
1246,
11442,
7,
9265,
531,
199,
83,
14,
1814,
8,
272,
298,
538,
15,
39,
20789,
6331,
39,
20789,
3041,
14,
8624,
401,
272,
519,
2,
32,
466,
1059,
971,
4,
1364,
1476,
60,
78,
60,
83,
7896,
7590,
83,
11,
1918,
2287,
401,
272,
519,
624,
32,
466,
1059,
2672,
1364,
1476,
1362,
627,
3698,
1011,
19727,
538,
14,
961,
945,
911,
506,
4829,
315,
282,
6466,
12160,
4683,
14,
7754,
1362,
627,
3698,
7678,
13559,
314,
658,
4,
1246,
11442,
64,
945,
3140,
14,
1362,
627,
258,
768,
466,
1059,
2672,
1246,
11442,
1362,
627,
3698,
710,
2287,
6141,
199,
83,
14,
1814,
8,
272,
298,
538,
15,
39,
20789,
6331,
39,
20789,
3041,
14,
8624,
401,
272,
519,
3212,
4,
5545,
2028,
12,
436,
1263,
971,
4,
1364,
1476,
401,
272,
519,
2,
4,
5545,
2028,
12,
436,
1263,
658,
4,
1246,
11442,
22446,
199,
199,
3,
5325,
5361,
199,
83,
14,
1814,
8,
272,
283,
2164,
15,
54,
17,
15,
538,
6331,
3041,
14,
8624,
297,
272,
519,
7,
7384,
971,
68,
91,
20,
7293,
272,
519,
7,
7384,
25455,
358,
199,
83,
14,
1814,
8,
272,
283,
2219,
15,
538,
15,
54,
17,
6331,
774,
14,
8624,
297,
272,
519,
7,
7384,
971,
68,
91,
20,
7293,
272,
519,
7,
7384,
25455,
358,
199,
199,
5680,
359,
7363,
61,
4104,
67,
8552,
7163,
25079,
199,
199,
3,
11848,
1771,
370,
5726,
4382,
14,
199,
83,
14,
1814,
8,
272,
298,
2164,
15,
538,
15,
54,
15870,
538,
20362,
8624,
401,
272,
519,
2,
12706,
687,
25886,
901,
334,
16045,
78,
8194,
16,
12,
30446,
78,
60,
83,
91,
21,
4988,
10,
6307,
78,
60,
83,
91,
20,
93,
6798,
971,
11918,
272,
519,
624,
12706,
687,
25886,
901,
971,
17,
1362,
11589,
272,
5726,
2672,
6141,
199,
199,
3,
7981,
4104,
3788,
687,
3769,
11584,
4242,
199,
83,
14,
1814,
8,
272,
298,
2164,
15,
538,
15,
54,
15870,
538,
20362,
8624,
401,
272,
519,
2,
5094,
1021,
401,
272,
519,
2,
533,
531,
199,
199,
3,
14402,
298,
1358,
9130,
2,
543,
298,
1110,
2,
367,
1083,
1561,
14,
199,
83,
14,
1814,
8,
272,
298,
2164,
15,
538,
15,
54,
15870,
538,
20362,
8624,
401,
272,
519,
2,
3455,
805,
7287,
83,
92,
71,
7272,
87,
91,
19,
12,
1552,
1358,
9130,
401,
272,
519,
2,
3455,
805,
971,
17,
1110,
2,
199,
9,
199,
199,
5680,
359,
3902,
61,
4104,
67,
8552,
7163,
25079,
199,
199,
3,
5325,
3847,
8002,
14,
3098,
14,
957,
6220,
199,
83,
14,
1814,
8,
272,
298,
2164,
15,
538,
15,
54,
15870,
538,
20362,
8624,
401,
272,
519,
2,
13417,
91,
16,
12,
30446,
7272,
1332,
8083,
91,
16,
12,
30446,
4186,
272,
519,
3212,
17,
8738,
2859,
921,
4091,
14,
3098,
14,
957,
60,
18,
2924,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1898,
25455,
4475,
20376,
199,
3,
199,
3,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
199,
3,
1265,
1443,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
199,
3,
2047,
1443,
3332,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
258,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
199,
3,
2428,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
199,
3,
1666,
314,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
199,
3,
4204,
1334,
314,
844,
14,
199,
199,
624,
2765,
2884,
365,
1202,
370,
9560,
1589,
890,
4046,
4184,
402,
642,
3555,
1041,
199,
199,
646,
9560,
273,
3557,
465,
308,
199,
646,
9560,
273,
3557,
14,
20622,
465,
22088,
199,
646,
2050,
199,
199,
4806,
14,
19602,
8,
1896,
29,
4806,
14,
5287,
9,
199,
199,
15046,
530,
275,
22088,
14,
39,
1282,
948,
19726,
352,
342,
199,
2330,
275,
22088,
14,
7844,
17969,
342,
199,
199,
4342,
275,
16301,
530,
14,
8624,
63,
4342,
8,
272,
2435,
534,
71,
9568,
297,
272,
1015,
534,
86,
17,
297,
272,
15507,
352,
63,
1375,
29,
70,
28866,
3098,
15,
4091,
15,
71,
9568,
15,
86,
17,
26,
3098,
13,
4091,
13,
71,
9568,
13,
86,
17,
13,
8624,
297,
199,
9,
199,
199,
3,
1331,
1006,
2928,
5893,
7417,
373,
6349,
281,
3992,
199,
83,
14,
1185,
8,
4342,
1182,
283,
2164,
358,
199,
199,
3,
1331,
4104,
1584,
370,
2928,
2597,
199,
83,
14,
1185,
8,
4342,
1182,
283,
2625,
15,
2164,
15,
13266,
15,
9089,
15,
39,
9568,
297,
283,
2164,
6217,
199,
83,
14,
1185,
8,
4342,
1182,
283,
2219,
6217,
199,
199,
3,
1331,
598,
13167,
5142,
570,
370,
3341,
199,
83,
14,
1185,
8,
4342,
1182,
283,
2625,
15,
2164,
15,
8225,
34,
5142,
15,
13266,
15,
9089,
15,
39,
9568,
297,
283,
2343,
6217,
199,
199,
3,
2213,
436,
7678,
13559,
2986,
11442,
3140,
402,
2435,
1476,
199,
83,
14,
1814,
8,
272,
298,
538,
15,
39,
20789,
6331,
39,
20789,
3041,
14,
8624,
401,
272,
519,
4507,
1364,
1476,
7,
275,
7166,
272,
519,
4507,
1246,
11442,
7,
9265,
531,
199,
83,
14,
1814,
8,
272,
298,
538,
15,
39,
20789,
6331,
39,
20789,
3041,
14,
8624,
401,
272,
519,
2,
32,
466,
1059,
971,
4,
1364,
1476,
60,
78,
60,
83,
7896,
7590,
83,
11,
1918,
2287,
401,
272,
519,
624,
32,
466,
1059,
2672,
1364,
1476,
1362,
627,
3698,
1011,
19727,
538,
14,
961,
945,
911,
506,
4829,
315,
282,
6466,
12160,
4683,
14,
7754,
1362,
627,
3698,
7678,
13559,
314,
658,
4,
1246,
11442,
64,
945,
3140,
14,
1362,
627,
258,
768,
466,
1059,
2672,
1246,
11442,
1362,
627,
3698,
710,
2287,
6141,
199,
83,
14,
1814,
8,
272,
298,
538,
15,
39,
20789,
6331,
39,
20789,
3041,
14,
8624,
401,
272,
519,
3212,
4,
5545,
2028,
12,
436,
1263,
971,
4,
1364,
1476,
401,
272,
519,
2,
4,
5545,
2028,
12,
436,
1263,
658,
4,
1246,
11442,
22446,
199,
199,
3,
5325,
5361,
199,
83,
14,
1814,
8,
272,
283,
2164,
15,
54,
17,
15,
538,
6331,
3041,
14,
8624,
297,
272,
519,
7,
7384,
971,
68,
91,
20,
7293,
272,
519,
7,
7384,
25455,
358,
199,
83,
14,
1814,
8,
272,
283,
2219,
15,
538,
15,
54,
17,
6331,
774,
14,
8624,
297,
272,
519,
7,
7384,
971,
68,
91,
20,
7293,
272,
519,
7,
7384,
25455,
358,
199,
199,
5680,
359,
7363,
61,
4104,
67,
8552,
7163,
25079,
199,
199,
3,
11848,
1771,
370,
5726,
4382,
14,
199,
83,
14,
1814,
8,
272,
298,
2164,
15,
538,
15,
54,
15870,
538,
20362,
8624,
401,
272,
519,
2,
12706,
687,
25886,
901,
334,
16045,
78,
8194,
16,
12,
30446,
78,
60,
83,
91,
21,
4988,
10,
6307,
78,
60,
83,
91,
20,
93,
6798,
971,
11918,
272,
519,
624,
12706,
687,
25886,
901,
971,
17,
1362,
11589,
272,
5726,
2672,
6141,
199,
199,
3,
7981,
4104,
3788,
687,
3769,
11584,
4242,
199,
83,
14,
1814,
8,
272,
298,
2164,
15,
538,
15,
54,
15870,
538,
20362,
8624,
401,
272,
519,
2,
5094,
1021,
401,
272,
519,
2,
533,
531,
199,
199,
3,
14402,
298,
1358,
9130,
2,
543,
298,
1110,
2,
367,
1083,
1561,
14,
199,
83,
14,
1814,
8,
272,
298,
2164,
15,
538,
15,
54,
15870,
538,
20362,
8624,
401,
272,
519,
2,
3455,
805,
7287,
83,
92,
71,
7272,
87,
91,
19,
12,
1552,
1358,
9130,
401,
272,
519,
2,
3455,
805,
971,
17,
1110,
2,
199,
9,
199,
199,
5680,
359,
3902,
61,
4104,
67,
8552,
7163,
25079,
199,
199,
3,
5325,
3847,
8002,
14,
3098,
14,
957,
6220,
199,
83,
14,
1814,
8,
272,
298,
2164,
15,
538,
15,
54,
15870,
538,
20362,
8624,
401,
272,
519,
2,
13417,
91,
16,
12,
30446,
7272,
1332,
8083,
91,
16,
12,
30446,
4186,
272,
519,
3212,
17,
8738,
2859,
921,
4091,
14,
3098,
14,
957,
60,
18,
2924,
199,
9,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
winndows/cinder
|
cinder/tests/unit/objects/test_volume_type.py
|
9
|
4317
|
# Copyright 2015 SimpliVity Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
import mock
from cinder import context
from cinder import objects
from cinder.tests.unit import fake_volume
from cinder.tests.unit import objects as test_objects
class TestVolumeType(test_objects.BaseObjectsTestCase):
def setUp(self):
super(TestVolumeType, self).setUp()
# NOTE (e0ne): base tests contains original RequestContext from
# oslo_context. We change it to our RequestContext implementation
# to have 'elevated' method
self.context = context.RequestContext(self.user_id, self.project_id,
is_admin=False)
@staticmethod
def _compare(test, db, obj):
for field, value in db.items():
test.assertEqual(db[field], obj[field])
@mock.patch('cinder.db.volume_type_get')
def test_get_by_id(self, volume_type_get):
db_volume_type = fake_volume.fake_db_volume_type()
volume_type_get.return_value = db_volume_type
volume_type = objects.VolumeType.get_by_id(self.context, '1')
self._compare(self, db_volume_type, volume_type)
@mock.patch('cinder.volume.volume_types.create')
def test_create(self, volume_type_create):
db_volume_type = fake_volume.fake_db_volume_type()
volume_type_create.return_value = db_volume_type
volume_type = objects.VolumeType(context=self.context)
volume_type.name = db_volume_type['name']
volume_type.extra_specs = db_volume_type['extra_specs']
volume_type.is_public = db_volume_type['is_public']
volume_type.projects = db_volume_type['projects']
volume_type.description = db_volume_type['description']
volume_type.create()
volume_type_create.assert_called_once_with(
self.context, db_volume_type['name'],
db_volume_type['extra_specs'], db_volume_type['is_public'],
db_volume_type['projects'], db_volume_type['description'])
@mock.patch('cinder.volume.volume_types.update')
def test_save(self, volume_type_update):
db_volume_type = fake_volume.fake_db_volume_type()
volume_type = objects.VolumeType._from_db_object(self.context,
objects.VolumeType(),
db_volume_type)
volume_type.description = 'foobar'
volume_type.save()
volume_type_update.assert_called_once_with(self.context,
volume_type.id,
volume_type.name,
volume_type.description)
@mock.patch('cinder.volume.volume_types.destroy')
def test_destroy(self, volume_type_destroy):
db_volume_type = fake_volume.fake_db_volume_type()
volume_type = objects.VolumeType._from_db_object(self.context,
objects.VolumeType(),
db_volume_type)
volume_type.destroy()
self.assertTrue(volume_type_destroy.called)
admin_context = volume_type_destroy.call_args[0][0]
self.assertTrue(admin_context.is_admin)
class TestVolumeTypeList(test_objects.BaseObjectsTestCase):
@mock.patch('cinder.volume.volume_types.get_all_types')
def test_get_all(self, get_all_types):
db_volume_type = fake_volume.fake_db_volume_type()
get_all_types.return_value = [db_volume_type]
volume_types = objects.VolumeTypeList.get_all(self.context)
self.assertEqual(1, len(volume_types))
TestVolumeType._compare(self, db_volume_type, volume_types[0])
|
apache-2.0
|
[
3,
259,
1898,
6900,
29094,
317,
54,
1209,
22304,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
199,
504,
13069,
492,
1067,
199,
504,
13069,
492,
2251,
199,
504,
13069,
14,
2219,
14,
3248,
492,
4026,
63,
2405,
199,
504,
13069,
14,
2219,
14,
3248,
492,
2251,
465,
511,
63,
1462,
421,
199,
533,
1379,
6464,
804,
8,
396,
63,
1462,
14,
1563,
11188,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
6464,
804,
12,
291,
680,
5996,
342,
267,
327,
6944,
334,
69,
16,
685,
304,
1300,
2295,
3509,
3379,
22538,
687,
267,
327,
11258,
63,
1100,
14,
2136,
1570,
652,
370,
4154,
22538,
4514,
267,
327,
370,
1172,
283,
32168,
7,
1083,
267,
291,
14,
1100,
275,
1067,
14,
17679,
8,
277,
14,
751,
63,
344,
12,
291,
14,
1715,
63,
344,
12,
6343,
365,
63,
2113,
29,
797,
9,
339,
768,
4639,
272,
347,
485,
5785,
8,
396,
12,
1592,
12,
1559,
304,
267,
367,
901,
12,
574,
315,
1592,
14,
1744,
837,
288,
511,
14,
629,
8,
697,
59,
698,
467,
1559,
59,
698,
566,
339,
768,
1805,
14,
2068,
360,
12372,
14,
697,
14,
2405,
63,
466,
63,
362,
358,
272,
347,
511,
63,
362,
63,
991,
63,
344,
8,
277,
12,
3301,
63,
466,
63,
362,
304,
267,
1592,
63,
2405,
63,
466,
275,
4026,
63,
2405,
14,
3183,
63,
697,
63,
2405,
63,
466,
342,
267,
3301,
63,
466,
63,
362,
14,
1107,
63,
585,
275,
1592,
63,
2405,
63,
466,
267,
3301,
63,
466,
275,
2251,
14,
6464,
804,
14,
362,
63,
991,
63,
344,
8,
277,
14,
1100,
12,
283,
17,
358,
267,
291,
423,
5785,
8,
277,
12,
1592,
63,
2405,
63,
466,
12,
3301,
63,
466,
9,
339,
768,
1805,
14,
2068,
360,
12372,
14,
2405,
14,
2405,
63,
1313,
14,
981,
358,
272,
347,
511,
63,
981,
8,
277,
12,
3301,
63,
466,
63,
981,
304,
267,
1592,
63,
2405,
63,
466,
275,
4026,
63,
2405,
14,
3183,
63,
697,
63,
2405,
63,
466,
342,
267,
3301,
63,
466,
63,
981,
14,
1107,
63,
585,
275,
1592,
63,
2405,
63,
466,
398,
3301,
63,
466,
275,
2251,
14,
6464,
804,
8,
1100,
29,
277,
14,
1100,
9,
267,
3301,
63,
466,
14,
354,
275,
1592,
63,
2405,
63,
466,
459,
354,
418,
267,
3301,
63,
466,
14,
2911,
63,
7273,
275,
1592,
63,
2405,
63,
466,
459,
2911,
63,
7273,
418,
267,
3301,
63,
466,
14,
374,
63,
3455,
275,
1592,
63,
2405,
63,
466,
459,
374,
63,
3455,
418,
267,
3301,
63,
466,
14,
6776,
275,
1592,
63,
2405,
63,
466,
459,
6776,
418,
267,
3301,
63,
466,
14,
1802,
275,
1592,
63,
2405,
63,
466,
459,
1802,
418,
267,
3301,
63,
466,
14,
981,
342,
398,
3301,
63,
466,
63,
981,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
288,
291,
14,
1100,
12,
1592,
63,
2405,
63,
466,
459,
354,
995,
288,
1592,
63,
2405,
63,
466,
459,
2911,
63,
7273,
995,
1592,
63,
2405,
63,
466,
459,
374,
63,
3455,
995,
288,
1592,
63,
2405,
63,
466,
459,
6776,
995,
1592,
63,
2405,
63,
466,
459,
1802,
1105,
339,
768,
1805,
14,
2068,
360,
12372,
14,
2405,
14,
2405,
63,
1313,
14,
873,
358,
272,
347,
511,
63,
2117,
8,
277,
12,
3301,
63,
466,
63,
873,
304,
267,
1592,
63,
2405,
63,
466,
275,
4026,
63,
2405,
14,
3183,
63,
697,
63,
2405,
63,
466,
342,
267,
3301,
63,
466,
275,
2251,
14,
6464,
804,
423,
504,
63,
697,
63,
785,
8,
277,
14,
1100,
12,
12740,
2251,
14,
6464,
804,
1062,
12740,
1592,
63,
2405,
63,
466,
9,
267,
3301,
63,
466,
14,
1802,
275,
283,
9664,
7,
267,
3301,
63,
466,
14,
2117,
342,
267,
3301,
63,
466,
63,
873,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
277,
14,
1100,
12,
8962,
3301,
63,
466,
14,
344,
12,
8962,
3301,
63,
466,
14,
354,
12,
8962,
3301,
63,
466,
14,
1802,
9,
339,
768,
1805,
14,
2068,
360,
12372,
14,
2405,
14,
2405,
63,
1313,
14,
7237,
358,
272,
347,
511,
63,
7237,
8,
277,
12,
3301,
63,
466,
63,
7237,
304,
267,
1592,
63,
2405,
63,
466,
275,
4026,
63,
2405,
14,
3183,
63,
697,
63,
2405,
63,
466,
342,
267,
3301,
63,
466,
275,
2251,
14,
6464,
804,
423,
504,
63,
697,
63,
785,
8,
277,
14,
1100,
12,
12740,
2251,
14,
6464,
804,
1062,
12740,
1592,
63,
2405,
63,
466,
9,
267,
3301,
63,
466,
14,
7237,
342,
267,
291,
14,
1815,
8,
2405,
63,
466,
63,
7237,
14,
3527,
9,
267,
4628,
63,
1100,
275,
3301,
63,
466,
63,
7237,
14,
1250,
63,
589,
59,
16,
1527,
16,
61,
267,
291,
14,
1815,
8,
2113,
63,
1100,
14,
374,
63,
2113,
9,
421,
199,
533,
1379,
6464,
804,
1296,
8,
396,
63,
1462,
14,
1563,
11188,
1746,
304,
272,
768,
1805,
14,
2068,
360,
12372,
14,
2405,
14,
2405,
63,
1313,
14,
362,
63,
452,
63,
1313,
358,
272,
347,
511,
63,
362,
63,
452,
8,
277,
12,
664,
63,
452,
63,
1313,
304,
267,
1592,
63,
2405,
63,
466,
275,
4026,
63,
2405,
14,
3183,
63,
697,
63,
2405,
63,
466,
342,
267,
664,
63,
452,
63,
1313,
14,
1107,
63,
585,
275,
359,
697,
63
] |
[
259,
1898,
6900,
29094,
317,
54,
1209,
22304,
14,
199,
3,
199,
3,
259,
3909,
1334,
314,
3668,
844,
12,
3394,
499,
14,
16,
334,
1589,
298,
3761,
3547,
1265,
1443,
199,
3,
259,
440,
675,
642,
570,
871,
315,
4151,
543,
314,
844,
14,
2047,
1443,
3332,
199,
3,
259,
282,
1331,
402,
314,
844,
737,
199,
3,
199,
3,
260,
1455,
921,
1544,
14,
3796,
14,
1308,
15,
2383,
15,
3961,
13,
18,
14,
16,
199,
3,
199,
3,
259,
4158,
1415,
701,
3964,
4179,
503,
4193,
370,
315,
3575,
12,
2032,
199,
3,
259,
1854,
1334,
314,
844,
365,
1854,
641,
376,
298,
1179,
2281,
2,
4207,
12,
2428,
199,
3,
259,
2990,
1549,
4217,
1634,
1821,
3826,
12,
1902,
4056,
503,
2478,
14,
1666,
314,
199,
3,
259,
844,
367,
314,
2488,
2637,
4210,
3443,
436,
4204,
199,
3,
259,
1334,
314,
844,
14,
199,
199,
646,
1683,
199,
199,
504,
13069,
492,
1067,
199,
504,
13069,
492,
2251,
199,
504,
13069,
14,
2219,
14,
3248,
492,
4026,
63,
2405,
199,
504,
13069,
14,
2219,
14,
3248,
492,
2251,
465,
511,
63,
1462,
421,
199,
533,
1379,
6464,
804,
8,
396,
63,
1462,
14,
1563,
11188,
1746,
304,
272,
347,
3613,
8,
277,
304,
267,
1613,
8,
774,
6464,
804,
12,
291,
680,
5996,
342,
267,
327,
6944,
334,
69,
16,
685,
304,
1300,
2295,
3509,
3379,
22538,
687,
267,
327,
11258,
63,
1100,
14,
2136,
1570,
652,
370,
4154,
22538,
4514,
267,
327,
370,
1172,
283,
32168,
7,
1083,
267,
291,
14,
1100,
275,
1067,
14,
17679,
8,
277,
14,
751,
63,
344,
12,
291,
14,
1715,
63,
344,
12,
6343,
365,
63,
2113,
29,
797,
9,
339,
768,
4639,
272,
347,
485,
5785,
8,
396,
12,
1592,
12,
1559,
304,
267,
367,
901,
12,
574,
315,
1592,
14,
1744,
837,
288,
511,
14,
629,
8,
697,
59,
698,
467,
1559,
59,
698,
566,
339,
768,
1805,
14,
2068,
360,
12372,
14,
697,
14,
2405,
63,
466,
63,
362,
358,
272,
347,
511,
63,
362,
63,
991,
63,
344,
8,
277,
12,
3301,
63,
466,
63,
362,
304,
267,
1592,
63,
2405,
63,
466,
275,
4026,
63,
2405,
14,
3183,
63,
697,
63,
2405,
63,
466,
342,
267,
3301,
63,
466,
63,
362,
14,
1107,
63,
585,
275,
1592,
63,
2405,
63,
466,
267,
3301,
63,
466,
275,
2251,
14,
6464,
804,
14,
362,
63,
991,
63,
344,
8,
277,
14,
1100,
12,
283,
17,
358,
267,
291,
423,
5785,
8,
277,
12,
1592,
63,
2405,
63,
466,
12,
3301,
63,
466,
9,
339,
768,
1805,
14,
2068,
360,
12372,
14,
2405,
14,
2405,
63,
1313,
14,
981,
358,
272,
347,
511,
63,
981,
8,
277,
12,
3301,
63,
466,
63,
981,
304,
267,
1592,
63,
2405,
63,
466,
275,
4026,
63,
2405,
14,
3183,
63,
697,
63,
2405,
63,
466,
342,
267,
3301,
63,
466,
63,
981,
14,
1107,
63,
585,
275,
1592,
63,
2405,
63,
466,
398,
3301,
63,
466,
275,
2251,
14,
6464,
804,
8,
1100,
29,
277,
14,
1100,
9,
267,
3301,
63,
466,
14,
354,
275,
1592,
63,
2405,
63,
466,
459,
354,
418,
267,
3301,
63,
466,
14,
2911,
63,
7273,
275,
1592,
63,
2405,
63,
466,
459,
2911,
63,
7273,
418,
267,
3301,
63,
466,
14,
374,
63,
3455,
275,
1592,
63,
2405,
63,
466,
459,
374,
63,
3455,
418,
267,
3301,
63,
466,
14,
6776,
275,
1592,
63,
2405,
63,
466,
459,
6776,
418,
267,
3301,
63,
466,
14,
1802,
275,
1592,
63,
2405,
63,
466,
459,
1802,
418,
267,
3301,
63,
466,
14,
981,
342,
398,
3301,
63,
466,
63,
981,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
288,
291,
14,
1100,
12,
1592,
63,
2405,
63,
466,
459,
354,
995,
288,
1592,
63,
2405,
63,
466,
459,
2911,
63,
7273,
995,
1592,
63,
2405,
63,
466,
459,
374,
63,
3455,
995,
288,
1592,
63,
2405,
63,
466,
459,
6776,
995,
1592,
63,
2405,
63,
466,
459,
1802,
1105,
339,
768,
1805,
14,
2068,
360,
12372,
14,
2405,
14,
2405,
63,
1313,
14,
873,
358,
272,
347,
511,
63,
2117,
8,
277,
12,
3301,
63,
466,
63,
873,
304,
267,
1592,
63,
2405,
63,
466,
275,
4026,
63,
2405,
14,
3183,
63,
697,
63,
2405,
63,
466,
342,
267,
3301,
63,
466,
275,
2251,
14,
6464,
804,
423,
504,
63,
697,
63,
785,
8,
277,
14,
1100,
12,
12740,
2251,
14,
6464,
804,
1062,
12740,
1592,
63,
2405,
63,
466,
9,
267,
3301,
63,
466,
14,
1802,
275,
283,
9664,
7,
267,
3301,
63,
466,
14,
2117,
342,
267,
3301,
63,
466,
63,
873,
14,
479,
63,
3527,
63,
5089,
63,
1045,
8,
277,
14,
1100,
12,
8962,
3301,
63,
466,
14,
344,
12,
8962,
3301,
63,
466,
14,
354,
12,
8962,
3301,
63,
466,
14,
1802,
9,
339,
768,
1805,
14,
2068,
360,
12372,
14,
2405,
14,
2405,
63,
1313,
14,
7237,
358,
272,
347,
511,
63,
7237,
8,
277,
12,
3301,
63,
466,
63,
7237,
304,
267,
1592,
63,
2405,
63,
466,
275,
4026,
63,
2405,
14,
3183,
63,
697,
63,
2405,
63,
466,
342,
267,
3301,
63,
466,
275,
2251,
14,
6464,
804,
423,
504,
63,
697,
63,
785,
8,
277,
14,
1100,
12,
12740,
2251,
14,
6464,
804,
1062,
12740,
1592,
63,
2405,
63,
466,
9,
267,
3301,
63,
466,
14,
7237,
342,
267,
291,
14,
1815,
8,
2405,
63,
466,
63,
7237,
14,
3527,
9,
267,
4628,
63,
1100,
275,
3301,
63,
466,
63,
7237,
14,
1250,
63,
589,
59,
16,
1527,
16,
61,
267,
291,
14,
1815,
8,
2113,
63,
1100,
14,
374,
63,
2113,
9,
421,
199,
533,
1379,
6464,
804,
1296,
8,
396,
63,
1462,
14,
1563,
11188,
1746,
304,
272,
768,
1805,
14,
2068,
360,
12372,
14,
2405,
14,
2405,
63,
1313,
14,
362,
63,
452,
63,
1313,
358,
272,
347,
511,
63,
362,
63,
452,
8,
277,
12,
664,
63,
452,
63,
1313,
304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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
] |
bratsche/Neutron-Drive
|
google_appengine/lib/django_1_3/django/contrib/localflavor/fi/forms.py
|
309
|
1803
|
"""
FI-specific Form helpers
"""
import re
from django.core.validators import EMPTY_VALUES
from django.forms import ValidationError
from django.forms.fields import Field, RegexField, Select
from django.utils.translation import ugettext_lazy as _
class FIZipCodeField(RegexField):
default_error_messages = {
'invalid': _('Enter a zip code in the format XXXXX.'),
}
def __init__(self, *args, **kwargs):
super(FIZipCodeField, self).__init__(r'^\d{5}$',
max_length=None, min_length=None, *args, **kwargs)
class FIMunicipalitySelect(Select):
"""
A Select widget that uses a list of Finnish municipalities as its choices.
"""
def __init__(self, attrs=None):
from fi_municipalities import MUNICIPALITY_CHOICES
super(FIMunicipalitySelect, self).__init__(attrs, choices=MUNICIPALITY_CHOICES)
class FISocialSecurityNumber(Field):
default_error_messages = {
'invalid': _('Enter a valid Finnish social security number.'),
}
def clean(self, value):
super(FISocialSecurityNumber, self).clean(value)
if value in EMPTY_VALUES:
return u''
checkmarks = "0123456789ABCDEFHJKLMNPRSTUVWXY"
result = re.match(r"""^
(?P<date>([0-2]\d|3[01])
(0\d|1[012])
(\d{2}))
[A+-]
(?P<serial>(\d{3}))
(?P<checksum>[%s])$""" % checkmarks, value, re.VERBOSE | re.IGNORECASE)
if not result:
raise ValidationError(self.error_messages['invalid'])
gd = result.groupdict()
checksum = int(gd['date'] + gd['serial'])
if checkmarks[checksum % len(checkmarks)] == gd['checksum'].upper():
return u'%s' % value.upper()
raise ValidationError(self.error_messages['invalid'])
|
bsd-3-clause
|
[
624,
199,
1976,
13,
6100,
8204,
10897,
199,
624,
199,
199,
646,
295,
199,
504,
1639,
14,
1018,
14,
11346,
492,
16589,
63,
15514,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
3351,
14,
955,
492,
5024,
12,
12939,
792,
12,
9496,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
533,
481,
5357,
711,
3034,
792,
8,
5103,
792,
304,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
4018,
8468,
282,
3482,
1233,
315,
314,
1475,
5787,
2483,
8038,
272,
789,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
1976,
8674,
3034,
792,
12,
291,
2843,
826,
721,
82,
15542,
68,
91,
21,
19204,
288,
1390,
63,
1267,
29,
403,
12,
1748,
63,
1267,
29,
403,
12,
627,
589,
12,
1011,
958,
9,
199,
199,
533,
481,
1469,
5209,
711,
6712,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
11711,
78,
2453,
333,
5209,
711,
10874,
1417,
465,
2399,
3415,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
687,
5883,
63,
77,
5209,
711,
10874,
1417,
492,
603,
11580,
1772,
748,
1922,
63,
16236,
267,
1613,
8,
38,
1469,
5209,
711,
6712,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
45,
11580,
1772,
748,
1922,
63,
16236,
9,
199,
199,
533,
481,
1311,
28748,
7676,
3259,
8,
792,
304,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
4018,
8468,
282,
1686,
11711,
78,
2453,
20295,
6391,
1329,
8038,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
1613,
8,
38,
1311,
28748,
7676,
3259,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
398,
1104,
10375,
275,
298,
11371,
18820,
22313,
14307,
16237,
3311,
840,
15110,
55,
8195,
2,
267,
754,
275,
295,
14,
1431,
8,
82,
624,
62,
288,
7558,
48,
28,
602,
30,
779,
16,
13,
18,
7272,
68,
92,
19,
59,
614,
566,
288,
334,
16,
60,
68,
92,
17,
59,
11533,
566,
288,
14749,
68,
91,
18,
12466,
288,
359,
33,
16341,
61,
288,
7558,
48,
28,
2171,
30,
2961,
68,
91,
19,
12466,
288,
7558,
48,
28,
8928,
9514,
5,
83,
566,
4,
624,
450,
1104,
10375,
12,
574,
12,
295,
14,
16075,
1204,
295,
14,
15434,
9,
267,
340,
440,
754,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
24714,
275,
754,
14,
20567,
342,
267,
9040,
275,
1109,
8,
7136,
459,
602,
418,
435,
24714,
459,
2171,
1105,
267,
340,
1104,
10375,
59,
8928,
450,
822,
8,
1074,
10375,
1874,
508,
24714,
459,
8928,
2278,
4142,
837,
288,
372,
399,
5956,
83,
7,
450,
574,
14,
4142,
342,
267,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
1976,
13,
6100,
8204,
10897,
199,
624,
199,
199,
646,
295,
199,
504,
1639,
14,
1018,
14,
11346,
492,
16589,
63,
15514,
199,
504,
1639,
14,
3351,
492,
8505,
199,
504,
1639,
14,
3351,
14,
955,
492,
5024,
12,
12939,
792,
12,
9496,
199,
504,
1639,
14,
1208,
14,
6893,
492,
10366,
63,
6395,
465,
485,
199,
199,
533,
481,
5357,
711,
3034,
792,
8,
5103,
792,
304,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
4018,
8468,
282,
3482,
1233,
315,
314,
1475,
5787,
2483,
8038,
272,
789,
272,
347,
636,
826,
721,
277,
12,
627,
589,
12,
1011,
958,
304,
267,
1613,
8,
1976,
8674,
3034,
792,
12,
291,
2843,
826,
721,
82,
15542,
68,
91,
21,
19204,
288,
1390,
63,
1267,
29,
403,
12,
1748,
63,
1267,
29,
403,
12,
627,
589,
12,
1011,
958,
9,
199,
199,
533,
481,
1469,
5209,
711,
6712,
5446,
8,
5446,
304,
272,
408,
272,
437,
9496,
3938,
626,
4440,
282,
769,
402,
11711,
78,
2453,
333,
5209,
711,
10874,
1417,
465,
2399,
3415,
14,
272,
408,
272,
347,
636,
826,
721,
277,
12,
3290,
29,
403,
304,
267,
687,
5883,
63,
77,
5209,
711,
10874,
1417,
492,
603,
11580,
1772,
748,
1922,
63,
16236,
267,
1613,
8,
38,
1469,
5209,
711,
6712,
5446,
12,
291,
2843,
826,
721,
3288,
12,
3415,
29,
45,
11580,
1772,
748,
1922,
63,
16236,
9,
199,
199,
533,
481,
1311,
28748,
7676,
3259,
8,
792,
304,
272,
849,
63,
705,
63,
3431,
275,
469,
267,
283,
3197,
356,
4018,
8468,
282,
1686,
11711,
78,
2453,
20295,
6391,
1329,
8038,
272,
789,
339,
347,
3633,
8,
277,
12,
574,
304,
267,
1613,
8,
38,
1311,
28748,
7676,
3259,
12,
291,
680,
3118,
8,
585,
9,
267,
340,
574,
315,
16589,
63,
15514,
26,
288,
372,
399,
891,
398,
1104,
10375,
275,
298,
11371,
18820,
22313,
14307,
16237,
3311,
840,
15110,
55,
8195,
2,
267,
754,
275,
295,
14,
1431,
8,
82,
624,
62,
288,
7558,
48,
28,
602,
30,
779,
16,
13,
18,
7272,
68,
92,
19,
59,
614,
566,
288,
334,
16,
60,
68,
92,
17,
59,
11533,
566,
288,
14749,
68,
91,
18,
12466,
288,
359,
33,
16341,
61,
288,
7558,
48,
28,
2171,
30,
2961,
68,
91,
19,
12466,
288,
7558,
48,
28,
8928,
9514,
5,
83,
566,
4,
624,
450,
1104,
10375,
12,
574,
12,
295,
14,
16075,
1204,
295,
14,
15434,
9,
267,
340,
440,
754,
26,
288,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
267,
24714,
275,
754,
14,
20567,
342,
267,
9040,
275,
1109,
8,
7136,
459,
602,
418,
435,
24714,
459,
2171,
1105,
267,
340,
1104,
10375,
59,
8928,
450,
822,
8,
1074,
10375,
1874,
508,
24714,
459,
8928,
2278,
4142,
837,
288,
372,
399,
5956,
83,
7,
450,
574,
14,
4142,
342,
267,
746,
8505,
8,
277,
14,
705,
63,
3431,
459,
3197,
1105,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
0x00f/pelican
|
pelican/tools/pelican_themes.py
|
1
|
7117
|
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import argparse
import os
import shutil
import sys
try:
import pelican
except:
err('Cannot import pelican.\nYou must install Pelican in order to run this script.', -1)
global _THEMES_PATH
_THEMES_PATH = os.path.join(
os.path.dirname(
os.path.abspath(
pelican.__file__
)
),
'themes'
)
__version__ = '0.2'
_BUILTIN_THEMES = ['simple', 'notmyidea']
def err(msg, die=None):
"""Print an error message and exits if an exit code is given"""
sys.stderr.write(str(msg) + '\n')
if die:
sys.exit((die if type(die) is int else 1))
def main():
"""Main function"""
parser = argparse.ArgumentParser(description="""Install themes for Pelican""")
excl= parser.add_mutually_exclusive_group()
excl.add_argument('-l', '--list', dest='action', action="store_const", const='list',
help="Show the themes already installed and exit")
excl.add_argument('-p', '--path', dest='action', action="store_const", const='path',
help="Show the themes path and exit")
excl.add_argument('-V', '--version', action='version', version='pelican-themes v{0}'.format(__version__),
help='Print the version of this script')
parser.add_argument('-i', '--install', dest='to_install', nargs='+', metavar="theme path",
help='The themes to install')
parser.add_argument('-r', '--remove', dest='to_remove', nargs='+', metavar="theme name",
help='The themes to remove')
parser.add_argument('-U', '--upgrade', dest='to_upgrade', nargs='+',
metavar="theme path", help='The themes to upgrade')
parser.add_argument('-s', '--symlink', dest='to_symlink', nargs='+', metavar="theme path",
help="Same as `--install', but create a symbolic link instead of copying the theme. Useful for theme development")
parser.add_argument('-c', '--clean', dest='clean', action="store_true",
help="Remove the broken symbolic links of the theme path")
parser.add_argument('-v', '--verbose', dest='verbose', action="store_true",
help="Verbose output")
args = parser.parse_args()
to_install = args.to_install or args.to_upgrade
to_sym = args.to_symlink or args.clean
if args.action:
if args.action is 'list':
list_themes(args.verbose)
elif args.action is 'path':
print(_THEMES_PATH)
elif to_install or args.to_remove or to_sym:
if args.to_remove:
if args.verbose:
print('Removing themes...')
for i in args.to_remove:
remove(i, v=args.verbose)
if args.to_install:
if args.verbose:
print('Installing themes...')
for i in args.to_install:
install(i, v=args.verbose)
if args.to_upgrade:
if args.verbose:
print('Upgrading themes...')
for i in args.to_upgrade:
install(i, v=args.verbose, u=True)
if args.to_symlink:
if args.verbose:
print('Linking themes...')
for i in args.to_symlink:
symlink(i, v=args.verbose)
if args.clean:
if args.verbose:
print('Cleaning the themes directory...')
clean(v=args.verbose)
else:
print('No argument given... exiting.')
def themes():
"""Returns the list of the themes"""
for i in os.listdir(_THEMES_PATH):
e = os.path.join(_THEMES_PATH, i)
if os.path.isdir(e):
if os.path.islink(e):
yield (e, os.readlink(e))
else:
yield (e, None)
def list_themes(v=False):
"""Display the list of the themes"""
for t, l in themes():
if not v:
t = os.path.basename(t)
if l:
if v:
print(t + (" (symbolic link to `" + l + "')"))
else:
print(t + '@')
else:
print(t)
def remove(theme_name, v=False):
"""Removes a theme"""
theme_name = theme_name.replace('/','')
target = os.path.join(_THEMES_PATH, theme_name)
if theme_name in _BUILTIN_THEMES:
err(theme_name + ' is a builtin theme.\nYou cannot remove a builtin theme with this script, remove it by hand if you want.')
elif os.path.islink(target):
if v:
print('Removing link `' + target + "'")
os.remove(target)
elif os.path.isdir(target):
if v:
print('Removing directory `' + target + "'")
shutil.rmtree(target)
elif os.path.exists(target):
err(target + ' : not a valid theme')
else:
err(target + ' : no such file or directory')
def install(path, v=False, u=False):
"""Installs a theme"""
if not os.path.exists(path):
err(path + ' : no such file or directory')
elif not os.path.isdir(path):
err(path + ' : not a directory')
else:
theme_name = os.path.basename(os.path.normpath(path))
theme_path = os.path.join(_THEMES_PATH, theme_name)
exists = os.path.exists(theme_path)
if exists and not u:
err(path + ' : already exists')
elif exists and u:
remove(theme_name, v)
install(path, v)
else:
if v:
print("Copying `{p}' to `{t}' ...".format(p=path, t=theme_path))
try:
shutil.copytree(path, theme_path)
except Exception, e:
err("Cannot copy `{p}' to `{t}':\n{e}".format(p=path, t=theme_path, e=str(e)))
def symlink(path, v=False):
"""Symbolically link a theme"""
if not os.path.exists(path):
err(path + ' : no such file or directory')
elif not os.path.isdir(path):
err(path + ' : not a directory')
else:
theme_name = os.path.basename(os.path.normpath(path))
theme_path = os.path.join(_THEMES_PATH, theme_name)
if os.path.exists(theme_path):
err(path + ' : already exists')
else:
if v:
print("Linking `{p}' to `{t}' ...".format(p=path, t=theme_path))
try:
os.symlink(path, theme_path)
except Exception, e:
err("Cannot link `{p}' to `{t}':\n{e}".format(p=path, t=theme_path, e=str(e)))
def is_broken_link(path):
"""Returns True if the path given as is a broken symlink"""
path = os.readlink(path)
return not os.path.exists(path)
def clean(v=False):
"""Removes the broken symbolic links"""
c=0
for path in os.listdir(_THEMES_PATH):
path = os.path.join(_THEMES_PATH, path)
if os.path.islink(path):
if is_broken_link(path):
if v:
print('Removing {0}'.format(path))
try:
os.remove(path)
except OSError, e:
print('Error: cannot remove {0}'.format(path))
else:
c+=1
print("\nRemoved {0} broken links".format(c))
|
agpl-3.0
|
[
3381,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
7534,
199,
646,
747,
199,
646,
5145,
199,
646,
984,
199,
199,
893,
26,
272,
492,
4837,
28091,
199,
2590,
26,
272,
2329,
360,
6612,
492,
4837,
28091,
3134,
78,
5556,
1471,
3907,
11379,
28091,
315,
1865,
370,
1255,
642,
2884,
3130,
446,
17,
9,
421,
199,
2966,
485,
18061,
22076,
63,
3243,
199,
63,
18061,
22076,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
272,
747,
14,
515,
14,
3475,
8,
267,
747,
14,
515,
14,
4832,
8,
288,
4837,
28091,
855,
493,
363,
272,
776,
272,
2318,
272,
283,
23900,
7,
199,
9,
199,
199,
363,
1023,
363,
275,
283,
16,
14,
18,
7,
199,
63,
18637,
20012,
63,
18061,
22076,
275,
788,
4129,
297,
283,
1397,
1662,
2655,
65,
418,
421,
199,
318,
2329,
8,
1328,
12,
18833,
29,
403,
304,
272,
408,
5375,
376,
1125,
1245,
436,
20100,
340,
376,
4458,
1233,
365,
1627,
624,
272,
984,
14,
3083,
14,
952,
8,
495,
8,
1328,
9,
435,
1557,
78,
358,
272,
340,
18833,
26,
267,
984,
14,
2224,
1332,
15130,
340,
730,
8,
15130,
9,
365,
1109,
587,
413,
430,
421,
199,
318,
2446,
837,
272,
408,
6756,
805,
624,
339,
1798,
275,
7534,
14,
10730,
8,
1802,
11916,
8154,
17915,
367,
11379,
28091,
6141,
339,
444,
429,
29,
1798,
14,
525,
63,
25024,
63,
12730,
63,
923,
342,
272,
444,
429,
14,
525,
63,
2094,
3654,
76,
297,
2850,
513,
297,
2053,
534,
1287,
297,
1595,
628,
1617,
63,
1297,
401,
950,
534,
513,
297,
267,
1720,
628,
6824,
314,
17915,
2575,
4903,
436,
4458,
531,
272,
444,
429,
14,
525,
63,
2094,
3654,
80,
297,
2850,
515,
297,
2053,
534,
1287,
297,
1595,
628,
1617,
63,
1297,
401,
950,
534,
515,
297,
267,
1720,
628,
6824,
314,
17915,
931,
436,
4458,
531,
272,
444,
429,
14,
525,
63,
2094,
3654,
54,
297,
2850,
1023,
297,
1595,
534,
1023,
297,
1015,
534,
321,
28091,
13,
23900,
373,
91,
16,
5285,
908,
3460,
1023,
10139,
267,
1720,
534,
5375,
314,
1015,
402,
642,
2884,
358,
2378,
1798,
14,
525,
63,
2094,
3654,
73,
297,
2850,
3174,
297,
2053,
534,
475,
63,
3174,
297,
9237,
534,
7386,
8214,
628,
7915,
931,
401,
267,
1720,
534,
1918,
17915,
370,
3907,
358,
272,
1798,
14,
525,
63,
2094,
3654,
82,
297,
2850,
2168,
297,
2053,
534,
475,
63,
2168,
297,
9237,
534,
7386,
8214,
628,
7915,
536,
401,
267,
1720,
534,
1918,
17915,
370,
2813,
358,
272,
1798,
14,
525,
63,
2094,
3654,
53,
297,
2850,
9375,
297,
2053,
534,
475,
63,
9375,
297,
9237,
534,
7386,
288,
8214,
628,
7915,
931,
401,
1720,
534,
1918,
17915,
370,
10754,
358,
272,
1798,
14,
525,
63,
2094,
3654,
83,
297,
2850,
13380,
297,
2053,
534,
475,
63,
13380,
297,
9237,
534,
7386,
8214,
628,
7915,
931,
401,
267,
1720,
628,
8479,
465,
658,
306,
3174,
297,
1325,
1218,
282,
13673,
2142,
3140,
402,
16743,
314,
8879,
14,
18491,
367,
8879,
16367,
531,
272,
1798,
14,
525,
63,
2094,
3654,
67,
297,
2850,
3118,
297,
2053,
534,
3118,
297,
1595,
628,
1617,
63,
2052,
401,
267,
1720,
628,
5587,
314,
10529,
13673,
6220,
402,
314,
8879,
931,
531,
2378,
1798,
14,
525,
63,
2094,
3654,
86,
297,
2850,
3832,
297,
2053,
534,
3832,
297,
1595,
628,
1617,
63,
2052,
401,
267,
1720,
628,
21879,
1072,
531,
2378,
1249,
275,
1798,
14,
1122,
63,
589,
342,
2286,
370,
63,
3174,
275,
1249,
14,
475,
63,
3174,
503,
1249,
14,
475,
63,
9375,
272,
370,
63,
3840,
275,
1249,
14,
475,
63,
13380,
503,
1249,
14,
3118,
2378,
340,
1249,
14,
1287,
26,
267,
340,
1249,
14,
1287,
365,
283,
513,
356,
288,
769,
63,
23900,
8,
589,
14,
3832,
9,
267,
916,
1249,
14,
1287,
365,
283,
515,
356,
288,
870,
1547,
18061,
22076,
63,
3243,
9,
272,
916,
370,
63,
3174,
503,
1249,
14,
475,
63,
2168,
503,
370,
63,
3840,
26,
267,
340,
1249,
14,
475,
63,
2168,
26,
288,
340,
1249,
14,
3832,
26,
355,
870,
360,
23420,
17915,
15103,
953,
367,
284,
315,
1249,
14,
475,
63,
2168,
26,
355,
2813,
8,
73,
12,
373,
29,
589,
14,
3832,
9,
398,
340,
1249,
14,
475,
63,
3174,
26,
288,
340,
1249,
14,
3832,
26,
355,
870,
360,
31376,
17915,
15103,
953,
367,
284,
315,
1249,
14,
475,
63,
3174,
26,
355,
3907,
8,
73,
12,
373,
29,
589,
14,
3832,
9,
398,
340,
1249,
14,
475,
63,
9375,
26,
288,
340,
1249,
14,
3832,
26,
355,
870,
360,
1721,
16050,
17915,
15103,
7846,
367,
284,
315,
1249,
14,
475,
63,
9375,
26,
355,
3907,
8,
73,
12,
373,
29,
589,
14,
3832,
12,
399,
29,
549,
9,
398,
340,
1249,
14,
475,
63,
13380,
26,
288,
340,
1249,
14,
3832,
26,
355,
870,
360,
3834,
316,
17915,
15103,
953,
367,
284,
315,
1249,
14,
475,
63,
13380,
26,
355,
15296,
8,
73,
12,
373,
29,
589,
14,
3832,
9,
398,
340,
1249,
14,
3118,
26,
288,
340,
1249,
14,
3832,
26,
355,
870,
360,
6580,
316,
314,
17915,
2082,
15103,
953,
3633,
8,
86,
29,
589,
14,
3832,
9,
272,
587,
26,
267,
870,
360,
1944,
1423,
1627,
1396,
24234,
2659,
421,
199,
318,
17915,
837,
272,
408,
3407,
314,
769,
402,
314,
17915,
624,
272,
367,
284,
315,
747,
14,
7374,
1547,
18061,
22076,
63,
3243,
304,
267,
325,
275,
747,
14,
515,
14,
904,
1547,
18061,
22076,
63,
3243,
12,
284,
9,
398,
340,
747,
14,
515,
14,
6027,
8,
69,
304,
288,
340,
747,
14,
515,
14,
20719,
8,
69,
304,
355,
1995,
334,
69,
12,
747,
14,
31654,
8,
69,
430,
288,
587,
26,
355,
1995,
334,
69,
12,
488,
9,
421,
199,
318,
769,
63,
23900,
8,
86,
29,
797,
304,
272,
408,
7687,
314,
769,
402,
314,
17915,
624,
272,
367,
307,
12,
634,
315,
17915,
837,
267,
340,
440,
373,
26,
288,
307,
275,
747,
14,
515,
14,
4846,
8,
84,
9,
267,
340,
634,
26,
288,
340,
373,
26,
355,
870,
8,
84,
435
] |
[
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
199,
646,
7534,
199,
646,
747,
199,
646,
5145,
199,
646,
984,
199,
199,
893,
26,
272,
492,
4837,
28091,
199,
2590,
26,
272,
2329,
360,
6612,
492,
4837,
28091,
3134,
78,
5556,
1471,
3907,
11379,
28091,
315,
1865,
370,
1255,
642,
2884,
3130,
446,
17,
9,
421,
199,
2966,
485,
18061,
22076,
63,
3243,
199,
63,
18061,
22076,
63,
3243,
275,
747,
14,
515,
14,
904,
8,
272,
747,
14,
515,
14,
3475,
8,
267,
747,
14,
515,
14,
4832,
8,
288,
4837,
28091,
855,
493,
363,
272,
776,
272,
2318,
272,
283,
23900,
7,
199,
9,
199,
199,
363,
1023,
363,
275,
283,
16,
14,
18,
7,
199,
63,
18637,
20012,
63,
18061,
22076,
275,
788,
4129,
297,
283,
1397,
1662,
2655,
65,
418,
421,
199,
318,
2329,
8,
1328,
12,
18833,
29,
403,
304,
272,
408,
5375,
376,
1125,
1245,
436,
20100,
340,
376,
4458,
1233,
365,
1627,
624,
272,
984,
14,
3083,
14,
952,
8,
495,
8,
1328,
9,
435,
1557,
78,
358,
272,
340,
18833,
26,
267,
984,
14,
2224,
1332,
15130,
340,
730,
8,
15130,
9,
365,
1109,
587,
413,
430,
421,
199,
318,
2446,
837,
272,
408,
6756,
805,
624,
339,
1798,
275,
7534,
14,
10730,
8,
1802,
11916,
8154,
17915,
367,
11379,
28091,
6141,
339,
444,
429,
29,
1798,
14,
525,
63,
25024,
63,
12730,
63,
923,
342,
272,
444,
429,
14,
525,
63,
2094,
3654,
76,
297,
2850,
513,
297,
2053,
534,
1287,
297,
1595,
628,
1617,
63,
1297,
401,
950,
534,
513,
297,
267,
1720,
628,
6824,
314,
17915,
2575,
4903,
436,
4458,
531,
272,
444,
429,
14,
525,
63,
2094,
3654,
80,
297,
2850,
515,
297,
2053,
534,
1287,
297,
1595,
628,
1617,
63,
1297,
401,
950,
534,
515,
297,
267,
1720,
628,
6824,
314,
17915,
931,
436,
4458,
531,
272,
444,
429,
14,
525,
63,
2094,
3654,
54,
297,
2850,
1023,
297,
1595,
534,
1023,
297,
1015,
534,
321,
28091,
13,
23900,
373,
91,
16,
5285,
908,
3460,
1023,
10139,
267,
1720,
534,
5375,
314,
1015,
402,
642,
2884,
358,
2378,
1798,
14,
525,
63,
2094,
3654,
73,
297,
2850,
3174,
297,
2053,
534,
475,
63,
3174,
297,
9237,
534,
7386,
8214,
628,
7915,
931,
401,
267,
1720,
534,
1918,
17915,
370,
3907,
358,
272,
1798,
14,
525,
63,
2094,
3654,
82,
297,
2850,
2168,
297,
2053,
534,
475,
63,
2168,
297,
9237,
534,
7386,
8214,
628,
7915,
536,
401,
267,
1720,
534,
1918,
17915,
370,
2813,
358,
272,
1798,
14,
525,
63,
2094,
3654,
53,
297,
2850,
9375,
297,
2053,
534,
475,
63,
9375,
297,
9237,
534,
7386,
288,
8214,
628,
7915,
931,
401,
1720,
534,
1918,
17915,
370,
10754,
358,
272,
1798,
14,
525,
63,
2094,
3654,
83,
297,
2850,
13380,
297,
2053,
534,
475,
63,
13380,
297,
9237,
534,
7386,
8214,
628,
7915,
931,
401,
267,
1720,
628,
8479,
465,
658,
306,
3174,
297,
1325,
1218,
282,
13673,
2142,
3140,
402,
16743,
314,
8879,
14,
18491,
367,
8879,
16367,
531,
272,
1798,
14,
525,
63,
2094,
3654,
67,
297,
2850,
3118,
297,
2053,
534,
3118,
297,
1595,
628,
1617,
63,
2052,
401,
267,
1720,
628,
5587,
314,
10529,
13673,
6220,
402,
314,
8879,
931,
531,
2378,
1798,
14,
525,
63,
2094,
3654,
86,
297,
2850,
3832,
297,
2053,
534,
3832,
297,
1595,
628,
1617,
63,
2052,
401,
267,
1720,
628,
21879,
1072,
531,
2378,
1249,
275,
1798,
14,
1122,
63,
589,
342,
2286,
370,
63,
3174,
275,
1249,
14,
475,
63,
3174,
503,
1249,
14,
475,
63,
9375,
272,
370,
63,
3840,
275,
1249,
14,
475,
63,
13380,
503,
1249,
14,
3118,
2378,
340,
1249,
14,
1287,
26,
267,
340,
1249,
14,
1287,
365,
283,
513,
356,
288,
769,
63,
23900,
8,
589,
14,
3832,
9,
267,
916,
1249,
14,
1287,
365,
283,
515,
356,
288,
870,
1547,
18061,
22076,
63,
3243,
9,
272,
916,
370,
63,
3174,
503,
1249,
14,
475,
63,
2168,
503,
370,
63,
3840,
26,
267,
340,
1249,
14,
475,
63,
2168,
26,
288,
340,
1249,
14,
3832,
26,
355,
870,
360,
23420,
17915,
15103,
953,
367,
284,
315,
1249,
14,
475,
63,
2168,
26,
355,
2813,
8,
73,
12,
373,
29,
589,
14,
3832,
9,
398,
340,
1249,
14,
475,
63,
3174,
26,
288,
340,
1249,
14,
3832,
26,
355,
870,
360,
31376,
17915,
15103,
953,
367,
284,
315,
1249,
14,
475,
63,
3174,
26,
355,
3907,
8,
73,
12,
373,
29,
589,
14,
3832,
9,
398,
340,
1249,
14,
475,
63,
9375,
26,
288,
340,
1249,
14,
3832,
26,
355,
870,
360,
1721,
16050,
17915,
15103,
7846,
367,
284,
315,
1249,
14,
475,
63,
9375,
26,
355,
3907,
8,
73,
12,
373,
29,
589,
14,
3832,
12,
399,
29,
549,
9,
398,
340,
1249,
14,
475,
63,
13380,
26,
288,
340,
1249,
14,
3832,
26,
355,
870,
360,
3834,
316,
17915,
15103,
953,
367,
284,
315,
1249,
14,
475,
63,
13380,
26,
355,
15296,
8,
73,
12,
373,
29,
589,
14,
3832,
9,
398,
340,
1249,
14,
3118,
26,
288,
340,
1249,
14,
3832,
26,
355,
870,
360,
6580,
316,
314,
17915,
2082,
15103,
953,
3633,
8,
86,
29,
589,
14,
3832,
9,
272,
587,
26,
267,
870,
360,
1944,
1423,
1627,
1396,
24234,
2659,
421,
199,
318,
17915,
837,
272,
408,
3407,
314,
769,
402,
314,
17915,
624,
272,
367,
284,
315,
747,
14,
7374,
1547,
18061,
22076,
63,
3243,
304,
267,
325,
275,
747,
14,
515,
14,
904,
1547,
18061,
22076,
63,
3243,
12,
284,
9,
398,
340,
747,
14,
515,
14,
6027,
8,
69,
304,
288,
340,
747,
14,
515,
14,
20719,
8,
69,
304,
355,
1995,
334,
69,
12,
747,
14,
31654,
8,
69,
430,
288,
587,
26,
355,
1995,
334,
69,
12,
488,
9,
421,
199,
318,
769,
63,
23900,
8,
86,
29,
797,
304,
272,
408,
7687,
314,
769,
402,
314,
17915,
624,
272,
367,
307,
12,
634,
315,
17915,
837,
267,
340,
440,
373,
26,
288,
307,
275,
747,
14,
515,
14,
4846,
8,
84,
9,
267,
340,
634,
26,
288,
340,
373,
26,
355,
870,
8,
84,
435,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
ishank08/scikit-learn
|
examples/applications/plot_stock_market.py
|
76
|
8522
|
"""
=======================================
Visualizing the stock market structure
=======================================
This example employs several unsupervised learning techniques to extract
the stock market structure from variations in historical quotes.
The quantity that we use is the daily variation in quote price: quotes
that are linked tend to cofluctuate during a day.
.. _stock_market:
Learning a graph structure
--------------------------
We use sparse inverse covariance estimation to find which quotes are
correlated conditionally on the others. Specifically, sparse inverse
covariance gives us a graph, that is a list of connection. For each
symbol, the symbols that it is connected too are those useful to explain
its fluctuations.
Clustering
----------
We use clustering to group together quotes that behave similarly. Here,
amongst the :ref:`various clustering techniques <clustering>` available
in the scikit-learn, we use :ref:`affinity_propagation` as it does
not enforce equal-size clusters, and it can choose automatically the
number of clusters from the data.
Note that this gives us a different indication than the graph, as the
graph reflects conditional relations between variables, while the
clustering reflects marginal properties: variables clustered together can
be considered as having a similar impact at the level of the full stock
market.
Embedding in 2D space
---------------------
For visualization purposes, we need to lay out the different symbols on a
2D canvas. For this we use :ref:`manifold` techniques to retrieve 2D
embedding.
Visualization
-------------
The output of the 3 models are combined in a 2D graph where nodes
represents the stocks and edges the:
- cluster labels are used to define the color of the nodes
- the sparse covariance model is used to display the strength of the edges
- the 2D embedding is used to position the nodes in the plan
This example has a fair amount of visualization-related code, as
visualization is crucial here to display the graph. One of the challenge
is to position the labels minimizing overlap. For this we use an
heuristic based on the direction of the nearest neighbor along each
axis.
"""
print(__doc__)
# Author: Gael Varoquaux gael.varoquaux@normalesup.org
# License: BSD 3 clause
import datetime
import numpy as np
import matplotlib.pyplot as plt
try:
from matplotlib.finance import quotes_historical_yahoo_ochl
except ImportError:
# quotes_historical_yahoo_ochl was named quotes_historical_yahoo before matplotlib 1.4
from matplotlib.finance import quotes_historical_yahoo as quotes_historical_yahoo_ochl
from matplotlib.collections import LineCollection
from sklearn import cluster, covariance, manifold
###############################################################################
# Retrieve the data from Internet
# Choose a time period reasonably calm (not too long ago so that we get
# high-tech firms, and before the 2008 crash)
d1 = datetime.datetime(2003, 1, 1)
d2 = datetime.datetime(2008, 1, 1)
# kraft symbol has now changed from KFT to MDLZ in yahoo
symbol_dict = {
'TOT': 'Total',
'XOM': 'Exxon',
'CVX': 'Chevron',
'COP': 'ConocoPhillips',
'VLO': 'Valero Energy',
'MSFT': 'Microsoft',
'IBM': 'IBM',
'TWX': 'Time Warner',
'CMCSA': 'Comcast',
'CVC': 'Cablevision',
'YHOO': 'Yahoo',
'DELL': 'Dell',
'HPQ': 'HP',
'AMZN': 'Amazon',
'TM': 'Toyota',
'CAJ': 'Canon',
'MTU': 'Mitsubishi',
'SNE': 'Sony',
'F': 'Ford',
'HMC': 'Honda',
'NAV': 'Navistar',
'NOC': 'Northrop Grumman',
'BA': 'Boeing',
'KO': 'Coca Cola',
'MMM': '3M',
'MCD': 'Mc Donalds',
'PEP': 'Pepsi',
'MDLZ': 'Kraft Foods',
'K': 'Kellogg',
'UN': 'Unilever',
'MAR': 'Marriott',
'PG': 'Procter Gamble',
'CL': 'Colgate-Palmolive',
'GE': 'General Electrics',
'WFC': 'Wells Fargo',
'JPM': 'JPMorgan Chase',
'AIG': 'AIG',
'AXP': 'American express',
'BAC': 'Bank of America',
'GS': 'Goldman Sachs',
'AAPL': 'Apple',
'SAP': 'SAP',
'CSCO': 'Cisco',
'TXN': 'Texas instruments',
'XRX': 'Xerox',
'LMT': 'Lookheed Martin',
'WMT': 'Wal-Mart',
'WBA': 'Walgreen',
'HD': 'Home Depot',
'GSK': 'GlaxoSmithKline',
'PFE': 'Pfizer',
'SNY': 'Sanofi-Aventis',
'NVS': 'Novartis',
'KMB': 'Kimberly-Clark',
'R': 'Ryder',
'GD': 'General Dynamics',
'RTN': 'Raytheon',
'CVS': 'CVS',
'CAT': 'Caterpillar',
'DD': 'DuPont de Nemours'}
symbols, names = np.array(list(symbol_dict.items())).T
quotes = [quotes_historical_yahoo_ochl(symbol, d1, d2, asobject=True)
for symbol in symbols]
open = np.array([q.open for q in quotes]).astype(np.float)
close = np.array([q.close for q in quotes]).astype(np.float)
# The daily variations of the quotes are what carry most information
variation = close - open
###############################################################################
# Learn a graphical structure from the correlations
edge_model = covariance.GraphLassoCV()
# standardize the time series: using correlations rather than covariance
# is more efficient for structure recovery
X = variation.copy().T
X /= X.std(axis=0)
edge_model.fit(X)
###############################################################################
# Cluster using affinity propagation
_, labels = cluster.affinity_propagation(edge_model.covariance_)
n_labels = labels.max()
for i in range(n_labels + 1):
print('Cluster %i: %s' % ((i + 1), ', '.join(names[labels == i])))
###############################################################################
# Find a low-dimension embedding for visualization: find the best position of
# the nodes (the stocks) on a 2D plane
# We use a dense eigen_solver to achieve reproducibility (arpack is
# initiated with random vectors that we don't control). In addition, we
# use a large number of neighbors to capture the large-scale structure.
node_position_model = manifold.LocallyLinearEmbedding(
n_components=2, eigen_solver='dense', n_neighbors=6)
embedding = node_position_model.fit_transform(X.T).T
###############################################################################
# Visualization
plt.figure(1, facecolor='w', figsize=(10, 8))
plt.clf()
ax = plt.axes([0., 0., 1., 1.])
plt.axis('off')
# Display a graph of the partial correlations
partial_correlations = edge_model.precision_.copy()
d = 1 / np.sqrt(np.diag(partial_correlations))
partial_correlations *= d
partial_correlations *= d[:, np.newaxis]
non_zero = (np.abs(np.triu(partial_correlations, k=1)) > 0.02)
# Plot the nodes using the coordinates of our embedding
plt.scatter(embedding[0], embedding[1], s=100 * d ** 2, c=labels,
cmap=plt.cm.spectral)
# Plot the edges
start_idx, end_idx = np.where(non_zero)
#a sequence of (*line0*, *line1*, *line2*), where::
# linen = (x0, y0), (x1, y1), ... (xm, ym)
segments = [[embedding[:, start], embedding[:, stop]]
for start, stop in zip(start_idx, end_idx)]
values = np.abs(partial_correlations[non_zero])
lc = LineCollection(segments,
zorder=0, cmap=plt.cm.hot_r,
norm=plt.Normalize(0, .7 * values.max()))
lc.set_array(values)
lc.set_linewidths(15 * values)
ax.add_collection(lc)
# Add a label to each node. The challenge here is that we want to
# position the labels to avoid overlap with other labels
for index, (name, label, (x, y)) in enumerate(
zip(names, labels, embedding.T)):
dx = x - embedding[0]
dx[index] = 1
dy = y - embedding[1]
dy[index] = 1
this_dx = dx[np.argmin(np.abs(dy))]
this_dy = dy[np.argmin(np.abs(dx))]
if this_dx > 0:
horizontalalignment = 'left'
x = x + .002
else:
horizontalalignment = 'right'
x = x - .002
if this_dy > 0:
verticalalignment = 'bottom'
y = y + .002
else:
verticalalignment = 'top'
y = y - .002
plt.text(x, y, name, size=10,
horizontalalignment=horizontalalignment,
verticalalignment=verticalalignment,
bbox=dict(facecolor='w',
edgecolor=plt.cm.spectral(label / float(n_labels)),
alpha=.6))
plt.xlim(embedding[0].min() - .15 * embedding[0].ptp(),
embedding[0].max() + .10 * embedding[0].ptp(),)
plt.ylim(embedding[1].min() - .03 * embedding[1].ptp(),
embedding[1].max() + .03 * embedding[1].ptp())
plt.show()
|
bsd-3-clause
|
[
624,
199,
2486,
18673,
199,
15039,
9147,
314,
10952,
26584,
5523,
199,
2486,
18673,
199,
199,
2765,
2893,
9052,
320,
588,
9978,
625,
4792,
17311,
9328,
32414,
83,
370,
5536,
199,
1589,
10952,
26584,
5523,
687,
4172,
1298,
315,
32530,
9344,
14,
199,
199,
1918,
12524,
626,
781,
675,
365,
314,
26122,
29844,
315,
6313,
8033,
26,
9344,
199,
9099,
787,
10632,
221,
7169,
370,
512,
2327,
918,
4767,
5309,
282,
5382,
14,
199,
199,
703,
485,
6088,
63,
22270,
26,
199,
199,
25519,
282,
3343,
5523,
199,
777,
9460,
199,
199,
6004,
675,
5178,
11484,
13263,
27156,
370,
2342,
1314,
9344,
787,
199,
989,
2407,
5558,
1183,
641,
314,
11789,
14,
30836,
12,
5178,
11484,
199,
15024,
10557,
2739,
282,
3343,
12,
626,
365,
282,
769,
402,
1950,
14,
2104,
1924,
199,
5155,
12,
314,
6698,
626,
652,
365,
8539,
4634,
787,
5204,
2997,
370,
27797,
199,
1405,
2717,
918,
18012,
14,
199,
199,
31174,
199,
9460,
199,
199,
6004,
675,
19454,
370,
1572,
10451,
9344,
626,
24062,
8545,
590,
14,
11842,
12,
199,
455,
951,
270,
314,
520,
1121,
1705,
3808,
1785,
19454,
32414,
83,
665,
25802,
8637,
2808,
199,
262,
314,
6276,
6065,
13,
4643,
12,
781,
675,
520,
1121,
1705,
15964,
63,
13535,
64,
465,
652,
1630,
199,
1397,
15814,
4472,
13,
890,
13865,
12,
436,
652,
883,
11496,
5847,
314,
199,
1955,
402,
13865,
687,
314,
666,
14,
199,
199,
7443,
626,
642,
10557,
2739,
282,
3365,
2539,
1063,
2419,
314,
3343,
12,
465,
314,
199,
2180,
16806,
83,
12303,
16109,
3382,
2860,
12,
1830,
314,
199,
25802,
16806,
83,
11042,
279,
4382,
26,
2860,
824,
527,
3014,
10451,
883,
199,
1235,
8652,
465,
9445,
282,
8545,
25568,
737,
314,
2166,
402,
314,
2615,
10952,
199,
22270,
14,
199,
199,
27907,
315,
499,
36,
4601,
199,
777,
9858,
199,
199,
1858,
13104,
2072,
12901,
12,
781,
1929,
370,
27305,
734,
314,
3365,
6698,
641,
282,
199,
18,
36,
10218,
14,
2104,
642,
781,
675,
520,
1121,
1705,
1237,
32294,
64,
32414,
83,
370,
8044,
499,
36,
199,
14275,
14,
421,
199,
15039,
2072,
199,
8684,
199,
199,
1918,
1072,
402,
314,
650,
1709,
787,
12149,
315,
282,
499,
36,
3343,
2382,
3380,
199,
13063,
83,
314,
10952,
83,
436,
8207,
314,
26,
199,
199,
13,
4350,
3628,
787,
1202,
370,
5627,
314,
3164,
402,
314,
3380,
199,
13,
314,
5178,
13263,
1402,
365,
1202,
370,
2929,
314,
410,
15796,
402,
314,
8207,
199,
13,
314,
499,
36,
12452,
365,
1202,
370,
3421,
314,
3380,
315,
314,
8683,
199,
199,
2765,
2893,
965,
282,
28092,
5982,
402,
13104,
2072,
13,
2407,
1233,
12,
465,
199,
16948,
2072,
365,
2467,
85,
7180,
2348,
370,
2929,
314,
3343,
14,
7309,
402,
314,
14929,
199,
374,
370,
3421,
314,
3628,
18790,
9147,
15145,
14,
2104,
642,
781,
675,
376,
199,
426,
20911,
4079,
641,
314,
7581,
402,
314,
17173,
15503,
3180,
1924,
199,
3127,
14,
199,
624,
199,
1361,
3460,
1301,
3368,
199,
199,
3,
6529,
26,
9647,
352,
21084,
79,
392,
10962,
486,
10643,
14,
1391,
79,
392,
10962,
32,
6505,
17667,
1961,
14,
1308,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
646,
2197,
199,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
893,
26,
1362,
687,
8027,
14,
2408,
554,
492,
9344,
63,
11141,
10611,
63,
27231,
63,
79,
335,
76,
199,
2590,
3545,
26,
1362,
327,
9344,
63,
11141,
10611,
63,
27231,
63,
79,
335,
76,
1990,
4310,
9344,
63,
11141,
10611,
63,
27231,
2544,
8027,
413,
14,
20,
1362,
687,
8027,
14,
2408,
554,
492,
9344,
63,
11141,
10611,
63,
27231,
465,
9344,
63,
11141,
10611,
63,
27231,
63,
79,
335,
76,
199,
504,
8027,
14,
7882,
492,
7030,
7768,
199,
504,
6357,
492,
4350,
12,
13263,
12,
2169,
32294,
199,
199,
11490,
199,
3,
13939,
314,
666,
687,
22026,
199,
199,
3,
29826,
282,
900,
6247,
4499,
6665,
3213,
77,
334,
1397,
4634,
1846,
20313,
880,
626,
781,
664,
199,
3,
4721,
13,
15970,
289,
723,
706,
12,
436,
2544,
314,
9079,
12420,
9,
199,
68,
17,
275,
2197,
14,
2083,
8,
17919,
12,
413,
12,
413,
9,
199,
68,
18,
275,
2197,
14,
2083,
8,
9300,
12,
413,
12,
413,
9,
199,
199,
3,
1022,
4800,
5272,
965,
3063,
2896,
687,
1804,
2161,
370,
603,
8045,
58,
315,
612,
65,
19112,
199,
5155,
63,
807,
275,
469,
272,
283,
14261,
356,
283,
7316,
297,
272,
283,
56,
7474,
356,
283,
920,
88,
265,
297,
272,
283,
12847,
56,
356,
283,
20335,
86,
2641,
297,
272,
283,
32324,
356,
283,
714,
79,
331,
5663,
8148,
1190,
297,
272,
283,
54,
1484,
356,
283,
54,
1895,
293,
662,
1372,
4312,
297,
272,
283,
3053,
2161,
356,
283,
12940,
297,
272,
283,
2100,
45,
356,
283,
2100,
45,
297,
272,
283,
16491,
56,
356,
283,
1366,
644,
1060,
281,
297,
272,
283,
9249,
3298,
33,
356,
283,
4373,
2931,
297,
272,
283,
35,
9454,
356,
283,
35,
461,
2317,
297,
272,
283,
57,
2979,
47,
356,
283,
28786,
19112,
297,
272,
283,
4424,
44,
356,
283,
36,
1697,
297,
272,
283,
18635,
49,
356,
283,
18635,
297,
272,
283,
1156,
58,
46,
356,
283,
33,
8872,
297,
272,
283,
20690,
356,
283,
1378,
89,
12041,
297,
272,
283,
3263,
42,
356,
283,
6049,
265,
297,
272,
283,
5747,
53,
356,
283,
45,
390,
954,
2453,
73,
297,
272,
283,
51,
6388,
356,
283,
51,
5220,
297,
272,
283,
38,
356,
283,
1858,
68,
297,
272,
283,
40,
7608,
356,
283,
40,
265,
983,
297,
272,
283,
46,
6087,
356,
283,
19617,
7848,
297,
272,
283,
2826,
35,
356,
283,
32066,
2675,
598,
28430,
1237,
297,
272,
283,
4134,
356,
283,
2208,
69,
316,
297,
272,
283,
24839,
356,
283,
35,
679,
65,
3626,
65,
297,
272,
283,
3218,
45,
356,
283,
19,
45,
297,
272,
283,
7608,
36,
356,
283,
45,
67,
7529,
279,
795,
297,
272,
283,
25633,
356,
283,
48,
1545,
338,
297,
272,
283,
5127,
44,
58,
356,
283,
43,
4800,
481,
23521,
83,
297,
272,
283,
43,
356,
283,
43,
352,
793,
71,
297,
272,
283,
1734,
356,
283
] |
[
199,
2486,
18673,
199,
15039,
9147,
314,
10952,
26584,
5523,
199,
2486,
18673,
199,
199,
2765,
2893,
9052,
320,
588,
9978,
625,
4792,
17311,
9328,
32414,
83,
370,
5536,
199,
1589,
10952,
26584,
5523,
687,
4172,
1298,
315,
32530,
9344,
14,
199,
199,
1918,
12524,
626,
781,
675,
365,
314,
26122,
29844,
315,
6313,
8033,
26,
9344,
199,
9099,
787,
10632,
221,
7169,
370,
512,
2327,
918,
4767,
5309,
282,
5382,
14,
199,
199,
703,
485,
6088,
63,
22270,
26,
199,
199,
25519,
282,
3343,
5523,
199,
777,
9460,
199,
199,
6004,
675,
5178,
11484,
13263,
27156,
370,
2342,
1314,
9344,
787,
199,
989,
2407,
5558,
1183,
641,
314,
11789,
14,
30836,
12,
5178,
11484,
199,
15024,
10557,
2739,
282,
3343,
12,
626,
365,
282,
769,
402,
1950,
14,
2104,
1924,
199,
5155,
12,
314,
6698,
626,
652,
365,
8539,
4634,
787,
5204,
2997,
370,
27797,
199,
1405,
2717,
918,
18012,
14,
199,
199,
31174,
199,
9460,
199,
199,
6004,
675,
19454,
370,
1572,
10451,
9344,
626,
24062,
8545,
590,
14,
11842,
12,
199,
455,
951,
270,
314,
520,
1121,
1705,
3808,
1785,
19454,
32414,
83,
665,
25802,
8637,
2808,
199,
262,
314,
6276,
6065,
13,
4643,
12,
781,
675,
520,
1121,
1705,
15964,
63,
13535,
64,
465,
652,
1630,
199,
1397,
15814,
4472,
13,
890,
13865,
12,
436,
652,
883,
11496,
5847,
314,
199,
1955,
402,
13865,
687,
314,
666,
14,
199,
199,
7443,
626,
642,
10557,
2739,
282,
3365,
2539,
1063,
2419,
314,
3343,
12,
465,
314,
199,
2180,
16806,
83,
12303,
16109,
3382,
2860,
12,
1830,
314,
199,
25802,
16806,
83,
11042,
279,
4382,
26,
2860,
824,
527,
3014,
10451,
883,
199,
1235,
8652,
465,
9445,
282,
8545,
25568,
737,
314,
2166,
402,
314,
2615,
10952,
199,
22270,
14,
199,
199,
27907,
315,
499,
36,
4601,
199,
777,
9858,
199,
199,
1858,
13104,
2072,
12901,
12,
781,
1929,
370,
27305,
734,
314,
3365,
6698,
641,
282,
199,
18,
36,
10218,
14,
2104,
642,
781,
675,
520,
1121,
1705,
1237,
32294,
64,
32414,
83,
370,
8044,
499,
36,
199,
14275,
14,
421,
199,
15039,
2072,
199,
8684,
199,
199,
1918,
1072,
402,
314,
650,
1709,
787,
12149,
315,
282,
499,
36,
3343,
2382,
3380,
199,
13063,
83,
314,
10952,
83,
436,
8207,
314,
26,
199,
199,
13,
4350,
3628,
787,
1202,
370,
5627,
314,
3164,
402,
314,
3380,
199,
13,
314,
5178,
13263,
1402,
365,
1202,
370,
2929,
314,
410,
15796,
402,
314,
8207,
199,
13,
314,
499,
36,
12452,
365,
1202,
370,
3421,
314,
3380,
315,
314,
8683,
199,
199,
2765,
2893,
965,
282,
28092,
5982,
402,
13104,
2072,
13,
2407,
1233,
12,
465,
199,
16948,
2072,
365,
2467,
85,
7180,
2348,
370,
2929,
314,
3343,
14,
7309,
402,
314,
14929,
199,
374,
370,
3421,
314,
3628,
18790,
9147,
15145,
14,
2104,
642,
781,
675,
376,
199,
426,
20911,
4079,
641,
314,
7581,
402,
314,
17173,
15503,
3180,
1924,
199,
3127,
14,
199,
624,
199,
1361,
3460,
1301,
3368,
199,
199,
3,
6529,
26,
9647,
352,
21084,
79,
392,
10962,
486,
10643,
14,
1391,
79,
392,
10962,
32,
6505,
17667,
1961,
14,
1308,
199,
3,
844,
26,
6289,
650,
8502,
199,
199,
646,
2197,
199,
199,
646,
2680,
465,
980,
199,
646,
8027,
14,
13563,
465,
4488,
199,
893,
26,
1362,
687,
8027,
14,
2408,
554,
492,
9344,
63,
11141,
10611,
63,
27231,
63,
79,
335,
76,
199,
2590,
3545,
26,
1362,
327,
9344,
63,
11141,
10611,
63,
27231,
63,
79,
335,
76,
1990,
4310,
9344,
63,
11141,
10611,
63,
27231,
2544,
8027,
413,
14,
20,
1362,
687,
8027,
14,
2408,
554,
492,
9344,
63,
11141,
10611,
63,
27231,
465,
9344,
63,
11141,
10611,
63,
27231,
63,
79,
335,
76,
199,
504,
8027,
14,
7882,
492,
7030,
7768,
199,
504,
6357,
492,
4350,
12,
13263,
12,
2169,
32294,
199,
199,
11490,
199,
3,
13939,
314,
666,
687,
22026,
199,
199,
3,
29826,
282,
900,
6247,
4499,
6665,
3213,
77,
334,
1397,
4634,
1846,
20313,
880,
626,
781,
664,
199,
3,
4721,
13,
15970,
289,
723,
706,
12,
436,
2544,
314,
9079,
12420,
9,
199,
68,
17,
275,
2197,
14,
2083,
8,
17919,
12,
413,
12,
413,
9,
199,
68,
18,
275,
2197,
14,
2083,
8,
9300,
12,
413,
12,
413,
9,
199,
199,
3,
1022,
4800,
5272,
965,
3063,
2896,
687,
1804,
2161,
370,
603,
8045,
58,
315,
612,
65,
19112,
199,
5155,
63,
807,
275,
469,
272,
283,
14261,
356,
283,
7316,
297,
272,
283,
56,
7474,
356,
283,
920,
88,
265,
297,
272,
283,
12847,
56,
356,
283,
20335,
86,
2641,
297,
272,
283,
32324,
356,
283,
714,
79,
331,
5663,
8148,
1190,
297,
272,
283,
54,
1484,
356,
283,
54,
1895,
293,
662,
1372,
4312,
297,
272,
283,
3053,
2161,
356,
283,
12940,
297,
272,
283,
2100,
45,
356,
283,
2100,
45,
297,
272,
283,
16491,
56,
356,
283,
1366,
644,
1060,
281,
297,
272,
283,
9249,
3298,
33,
356,
283,
4373,
2931,
297,
272,
283,
35,
9454,
356,
283,
35,
461,
2317,
297,
272,
283,
57,
2979,
47,
356,
283,
28786,
19112,
297,
272,
283,
4424,
44,
356,
283,
36,
1697,
297,
272,
283,
18635,
49,
356,
283,
18635,
297,
272,
283,
1156,
58,
46,
356,
283,
33,
8872,
297,
272,
283,
20690,
356,
283,
1378,
89,
12041,
297,
272,
283,
3263,
42,
356,
283,
6049,
265,
297,
272,
283,
5747,
53,
356,
283,
45,
390,
954,
2453,
73,
297,
272,
283,
51,
6388,
356,
283,
51,
5220,
297,
272,
283,
38,
356,
283,
1858,
68,
297,
272,
283,
40,
7608,
356,
283,
40,
265,
983,
297,
272,
283,
46,
6087,
356,
283,
19617,
7848,
297,
272,
283,
2826,
35,
356,
283,
32066,
2675,
598,
28430,
1237,
297,
272,
283,
4134,
356,
283,
2208,
69,
316,
297,
272,
283,
24839,
356,
283,
35,
679,
65,
3626,
65,
297,
272,
283,
3218,
45,
356,
283,
19,
45,
297,
272,
283,
7608,
36,
356,
283,
45,
67,
7529,
279,
795,
297,
272,
283,
25633,
356,
283,
48,
1545,
338,
297,
272,
283,
5127,
44,
58,
356,
283,
43,
4800,
481,
23521,
83,
297,
272,
283,
43,
356,
283,
43,
352,
793,
71,
297,
272,
283,
1734,
356,
283,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dagar/libpypa-test
|
tools/astdump.py
|
6
|
1070
|
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8
import ast
PADDING = ' '
def member_filter(item):
if item in ('col_offset', 'lineno'):
return False
return not item.startswith("_")
def print_ast(a, pad=''):
if isinstance(a, (list, tuple)):
print '['
for i in a:
print_ast(i, pad + PADDING)
print '%s]' % pad
elif isinstance(a, (basestring, int, float, long, complex)) or a is None:
print a
elif isinstance(a, (ast.Load, ast.Store, ast.AugLoad, ast.AugStore,
ast.Param, ast.Del)):
print a.__class__.__name__
else:
print '\n%s[%s]' % (pad, a.__class__.__name__)
items = [i for i in dir(a) if member_filter(i)]
for i in items:
print '%s%s- %s:' % (pad, PADDING, i),
print_ast(getattr(a, i), pad + PADDING)
# else:
# print a.__class__.__name__, [i for i in dir(a) if member_filter(i)]
if __name__ == '__main__':
import sys
print_ast(ast.parse(open(sys.argv[1], 'r').read()))
|
apache-2.0
|
[
3168,
1182,
2647,
15,
1393,
15,
1813,
2366,
199,
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
3,
6695,
26,
70,
10945,
29,
1624,
13,
24,
199,
199,
646,
6073,
199,
48,
9732,
1206,
275,
283,
259,
283,
421,
199,
318,
3653,
63,
1541,
8,
1053,
304,
272,
340,
1242,
315,
661,
761,
63,
2743,
297,
283,
3469,
735,
267,
372,
756,
272,
372,
440,
1242,
14,
2460,
11008,
531,
421,
199,
318,
870,
63,
1810,
8,
65,
12,
6567,
9280,
272,
340,
1228,
8,
65,
12,
334,
513,
12,
2008,
2298,
267,
870,
22640,
267,
367,
284,
315,
282,
26,
288,
870,
63,
1810,
8,
73,
12,
6567,
435,
510,
9732,
1206,
9,
267,
870,
1543,
83,
6616,
450,
6567,
272,
916,
1228,
8,
65,
12,
334,
17628,
12,
1109,
12,
2069,
12,
1846,
12,
6114,
430,
503,
282,
365,
488,
26,
267,
870,
282,
272,
916,
1228,
8,
65,
12,
334,
1810,
14,
6200,
12,
6073,
14,
5502,
12,
6073,
14,
21640,
6200,
12,
6073,
14,
21640,
5502,
12,
717,
6073,
14,
4098,
12,
6073,
14,
6994,
2298,
267,
870,
282,
855,
533,
4914,
354,
363,
272,
587,
26,
267,
870,
1557,
78,
5,
83,
9722,
83,
6616,
450,
334,
6226,
12,
282,
855,
533,
4914,
354,
3368,
267,
2974,
275,
359,
73,
367,
284,
315,
2935,
8,
65,
9,
340,
3653,
63,
1541,
8,
73,
1874,
267,
367,
284,
315,
2974,
26,
288,
870,
1543,
83,
5,
83,
13,
450,
83,
4881,
450,
334,
6226,
12,
510,
9732,
1206,
12,
284,
395,
288,
870,
63,
1810,
8,
5675,
8,
65,
12,
284,
395,
6567,
435,
510,
9732,
1206,
9,
199,
3,
259,
587,
26,
199,
3,
263,
870,
282,
855,
533,
4914,
354,
3108,
359,
73,
367,
284,
315,
2935,
8,
65,
9,
340,
3653,
63,
1541,
8,
73,
1874,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
984,
272,
870,
63,
1810,
8,
1810,
14,
1122,
8,
1490,
8,
1274,
14,
3020,
59,
17,
467,
283,
82,
1959,
739,
4059,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
6695,
26,
70,
10945,
29,
1624,
13,
24,
199,
199,
646,
6073,
199,
48,
9732,
1206,
275,
283,
259,
283,
421,
199,
318,
3653,
63,
1541,
8,
1053,
304,
272,
340,
1242,
315,
661,
761,
63,
2743,
297,
283,
3469,
735,
267,
372,
756,
272,
372,
440,
1242,
14,
2460,
11008,
531,
421,
199,
318,
870,
63,
1810,
8,
65,
12,
6567,
9280,
272,
340,
1228,
8,
65,
12,
334,
513,
12,
2008,
2298,
267,
870,
22640,
267,
367,
284,
315,
282,
26,
288,
870,
63,
1810,
8,
73,
12,
6567,
435,
510,
9732,
1206,
9,
267,
870,
1543,
83,
6616,
450,
6567,
272,
916,
1228,
8,
65,
12,
334,
17628,
12,
1109,
12,
2069,
12,
1846,
12,
6114,
430,
503,
282,
365,
488,
26,
267,
870,
282,
272,
916,
1228,
8,
65,
12,
334,
1810,
14,
6200,
12,
6073,
14,
5502,
12,
6073,
14,
21640,
6200,
12,
6073,
14,
21640,
5502,
12,
717,
6073,
14,
4098,
12,
6073,
14,
6994,
2298,
267,
870,
282,
855,
533,
4914,
354,
363,
272,
587,
26,
267,
870,
1557,
78,
5,
83,
9722,
83,
6616,
450,
334,
6226,
12,
282,
855,
533,
4914,
354,
3368,
267,
2974,
275,
359,
73,
367,
284,
315,
2935,
8,
65,
9,
340,
3653,
63,
1541,
8,
73,
1874,
267,
367,
284,
315,
2974,
26,
288,
870,
1543,
83,
5,
83,
13,
450,
83,
4881,
450,
334,
6226,
12,
510,
9732,
1206,
12,
284,
395,
288,
870,
63,
1810,
8,
5675,
8,
65,
12,
284,
395,
6567,
435,
510,
9732,
1206,
9,
199,
3,
259,
587,
26,
199,
3,
263,
870,
282,
855,
533,
4914,
354,
3108,
359,
73,
367,
284,
315,
2935,
8,
65,
9,
340,
3653,
63,
1541,
8,
73,
1874,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
492,
984,
272,
870,
63,
1810,
8,
1810,
14,
1122,
8,
1490,
8,
1274,
14,
3020,
59,
17,
467,
283,
82,
1959,
739,
4059,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1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0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0,
0
] |
MonicaHsu/truvaluation
|
venv/lib/python2.7/distutils/emxccompiler.py
|
250
|
11931
|
"""distutils.emxccompiler
Provides the EMXCCompiler class, a subclass of UnixCCompiler that
handles the EMX port of the GNU C compiler to OS/2.
"""
# issues:
#
# * OS/2 insists that DLLs can have names no longer than 8 characters
# We put export_symbols in a def-file, as though the DLL can have
# an arbitrary length name, but truncate the output filename.
#
# * only use OMF objects and use LINK386 as the linker (-Zomf)
#
# * always build for multithreading (-Zmt) as the accompanying OS/2 port
# of Python is only distributed with threads enabled.
#
# tested configurations:
#
# * EMX gcc 2.81/EMX 0.9d fix03
__revision__ = "$Id$"
import os,sys,copy
from distutils.ccompiler import gen_preprocess_options, gen_lib_options
from distutils.unixccompiler import UnixCCompiler
from distutils.file_util import write_file
from distutils.errors import DistutilsExecError, CompileError, UnknownFileError
from distutils import log
class EMXCCompiler (UnixCCompiler):
compiler_type = 'emx'
obj_extension = ".obj"
static_lib_extension = ".lib"
shared_lib_extension = ".dll"
static_lib_format = "%s%s"
shared_lib_format = "%s%s"
res_extension = ".res" # compiled resource file
exe_extension = ".exe"
def __init__ (self,
verbose=0,
dry_run=0,
force=0):
UnixCCompiler.__init__ (self, verbose, dry_run, force)
(status, details) = check_config_h()
self.debug_print("Python's GCC status: %s (details: %s)" %
(status, details))
if status is not CONFIG_H_OK:
self.warn(
"Python's pyconfig.h doesn't seem to support your compiler. " +
("Reason: %s." % details) +
"Compiling may fail because of undefined preprocessor macros.")
(self.gcc_version, self.ld_version) = \
get_versions()
self.debug_print(self.compiler_type + ": gcc %s, ld %s\n" %
(self.gcc_version,
self.ld_version) )
# Hard-code GCC because that's what this is all about.
# XXX optimization, warnings etc. should be customizable.
self.set_executables(compiler='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
compiler_so='gcc -Zomf -Zmt -O3 -fomit-frame-pointer -mprobe -Wall',
linker_exe='gcc -Zomf -Zmt -Zcrtdll',
linker_so='gcc -Zomf -Zmt -Zcrtdll -Zdll')
# want the gcc library statically linked (so that we don't have
# to distribute a version dependent on the compiler we have)
self.dll_libraries=["gcc"]
# __init__ ()
def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
if ext == '.rc':
# gcc requires '.rc' compiled to binary ('.res') files !!!
try:
self.spawn(["rc", "-r", src])
except DistutilsExecError, msg:
raise CompileError, msg
else: # for other files use the C-compiler
try:
self.spawn(self.compiler_so + cc_args + [src, '-o', obj] +
extra_postargs)
except DistutilsExecError, msg:
raise CompileError, msg
def link (self,
target_desc,
objects,
output_filename,
output_dir=None,
libraries=None,
library_dirs=None,
runtime_library_dirs=None,
export_symbols=None,
debug=0,
extra_preargs=None,
extra_postargs=None,
build_temp=None,
target_lang=None):
# use separate copies, so we can modify the lists
extra_preargs = copy.copy(extra_preargs or [])
libraries = copy.copy(libraries or [])
objects = copy.copy(objects or [])
# Additional libraries
libraries.extend(self.dll_libraries)
# handle export symbols by creating a def-file
# with executables this only works with gcc/ld as linker
if ((export_symbols is not None) and
(target_desc != self.EXECUTABLE)):
# (The linker doesn't do anything if output is up-to-date.
# So it would probably better to check if we really need this,
# but for this we had to insert some unchanged parts of
# UnixCCompiler, and this is not what we want.)
# we want to put some files in the same directory as the
# object files are, build_temp doesn't help much
# where are the object files
temp_dir = os.path.dirname(objects[0])
# name of dll to give the helper files the same base name
(dll_name, dll_extension) = os.path.splitext(
os.path.basename(output_filename))
# generate the filenames for these files
def_file = os.path.join(temp_dir, dll_name + ".def")
# Generate .def file
contents = [
"LIBRARY %s INITINSTANCE TERMINSTANCE" % \
os.path.splitext(os.path.basename(output_filename))[0],
"DATA MULTIPLE NONSHARED",
"EXPORTS"]
for sym in export_symbols:
contents.append(' "%s"' % sym)
self.execute(write_file, (def_file, contents),
"writing %s" % def_file)
# next add options for def-file and to creating import libraries
# for gcc/ld the def-file is specified as any other object files
objects.append(def_file)
#end: if ((export_symbols is not None) and
# (target_desc != self.EXECUTABLE or self.linker_dll == "gcc")):
# who wants symbols and a many times larger output file
# should explicitly switch the debug mode on
# otherwise we let dllwrap/ld strip the output file
# (On my machine: 10KB < stripped_file < ??100KB
# unstripped_file = stripped_file + XXX KB
# ( XXX=254 for a typical python extension))
if not debug:
extra_preargs.append("-s")
UnixCCompiler.link(self,
target_desc,
objects,
output_filename,
output_dir,
libraries,
library_dirs,
runtime_library_dirs,
None, # export_symbols, we do this in our def-file
debug,
extra_preargs,
extra_postargs,
build_temp,
target_lang)
# link ()
# -- Miscellaneous methods -----------------------------------------
# override the object_filenames method from CCompiler to
# support rc and res-files
def object_filenames (self,
source_filenames,
strip_dir=0,
output_dir=''):
if output_dir is None: output_dir = ''
obj_names = []
for src_name in source_filenames:
# use normcase to make sure '.rc' is really '.rc' and not '.RC'
(base, ext) = os.path.splitext (os.path.normcase(src_name))
if ext not in (self.src_extensions + ['.rc']):
raise UnknownFileError, \
"unknown file type '%s' (from '%s')" % \
(ext, src_name)
if strip_dir:
base = os.path.basename (base)
if ext == '.rc':
# these need to be compiled to object files
obj_names.append (os.path.join (output_dir,
base + self.res_extension))
else:
obj_names.append (os.path.join (output_dir,
base + self.obj_extension))
return obj_names
# object_filenames ()
# override the find_library_file method from UnixCCompiler
# to deal with file naming/searching differences
def find_library_file(self, dirs, lib, debug=0):
shortlib = '%s.lib' % lib
longlib = 'lib%s.lib' % lib # this form very rare
# get EMX's default library directory search path
try:
emx_dirs = os.environ['LIBRARY_PATH'].split(';')
except KeyError:
emx_dirs = []
for dir in dirs + emx_dirs:
shortlibp = os.path.join(dir, shortlib)
longlibp = os.path.join(dir, longlib)
if os.path.exists(shortlibp):
return shortlibp
elif os.path.exists(longlibp):
return longlibp
# Oops, didn't find it in *any* of 'dirs'
return None
# class EMXCCompiler
# Because these compilers aren't configured in Python's pyconfig.h file by
# default, we should at least warn the user if he is using a unmodified
# version.
CONFIG_H_OK = "ok"
CONFIG_H_NOTOK = "not ok"
CONFIG_H_UNCERTAIN = "uncertain"
def check_config_h():
"""Check if the current Python installation (specifically, pyconfig.h)
appears amenable to building extensions with GCC. Returns a tuple
(status, details), where 'status' is one of the following constants:
CONFIG_H_OK
all is well, go ahead and compile
CONFIG_H_NOTOK
doesn't look good
CONFIG_H_UNCERTAIN
not sure -- unable to read pyconfig.h
'details' is a human-readable string explaining the situation.
Note there are two ways to conclude "OK": either 'sys.version' contains
the string "GCC" (implying that this Python was built with GCC), or the
installed "pyconfig.h" contains the string "__GNUC__".
"""
# XXX since this function also checks sys.version, it's not strictly a
# "pyconfig.h" check -- should probably be renamed...
from distutils import sysconfig
import string
# if sys.version contains GCC then python was compiled with
# GCC, and the pyconfig.h file should be OK
if string.find(sys.version,"GCC") >= 0:
return (CONFIG_H_OK, "sys.version mentions 'GCC'")
fn = sysconfig.get_config_h_filename()
try:
# It would probably better to read single lines to search.
# But we do this only once, and it is fast enough
f = open(fn)
try:
s = f.read()
finally:
f.close()
except IOError, exc:
# if we can't read this file, we cannot say it is wrong
# the compiler will complain later about this file as missing
return (CONFIG_H_UNCERTAIN,
"couldn't read '%s': %s" % (fn, exc.strerror))
else:
# "pyconfig.h" contains an "#ifdef __GNUC__" or something similar
if string.find(s,"__GNUC__") >= 0:
return (CONFIG_H_OK, "'%s' mentions '__GNUC__'" % fn)
else:
return (CONFIG_H_NOTOK, "'%s' does not mention '__GNUC__'" % fn)
def get_versions():
""" Try to find out the versions of gcc and ld.
If not possible it returns None for it.
"""
from distutils.version import StrictVersion
from distutils.spawn import find_executable
import re
gcc_exe = find_executable('gcc')
if gcc_exe:
out = os.popen(gcc_exe + ' -dumpversion','r')
try:
out_string = out.read()
finally:
out.close()
result = re.search('(\d+\.\d+\.\d+)',out_string)
if result:
gcc_version = StrictVersion(result.group(1))
else:
gcc_version = None
else:
gcc_version = None
# EMX ld has no way of reporting version number, and we use GCC
# anyway - so we can link OMF DLLs
ld_version = None
return (gcc_version, ld_version)
|
mit
|
[
624,
13350,
14,
5633,
1812,
5772,
199,
199,
17473,
314,
662,
17401,
30926,
1021,
12,
282,
5516,
402,
13074,
30926,
626,
199,
16947,
314,
662,
17401,
1844,
402,
314,
1664,
445,
6365,
370,
4403,
15,
18,
14,
199,
624,
199,
199,
3,
10876,
26,
199,
3,
199,
3,
627,
4403,
15,
18,
315,
338,
10329,
626,
577,
4464,
83,
883,
1172,
1561,
949,
8088,
2419,
1695,
4110,
199,
3,
257,
2136,
5324,
4843,
63,
7450,
315,
282,
347,
13,
493,
12,
465,
10617,
314,
577,
4464,
883,
1172,
199,
3,
257,
376,
9697,
2582,
536,
12,
1325,
14547,
314,
1072,
1788,
14,
199,
3,
199,
3,
627,
1454,
675,
593,
13463,
2251,
436,
675,
19774,
8040,
465,
314,
17261,
5868,
58,
676,
70,
9,
199,
3,
199,
3,
627,
3544,
1900,
367,
3510,
12562,
5868,
58,
2037,
9,
465,
314,
23073,
4403,
15,
18,
1844,
199,
3,
257,
402,
2018,
365,
1454,
1854,
543,
7183,
5223,
14,
199,
3,
199,
3,
12470,
13422,
26,
199,
3,
199,
3,
627,
662,
17401,
19443,
499,
14,
2835,
15,
2769,
56,
378,
14,
25,
68,
5325,
1644,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
747,
12,
1274,
12,
1574,
199,
504,
7065,
14,
67,
5772,
492,
3805,
63,
17677,
63,
1419,
12,
3805,
63,
773,
63,
1419,
199,
504,
7065,
14,
11864,
67,
5772,
492,
13074,
30926,
199,
504,
7065,
14,
493,
63,
1974,
492,
2218,
63,
493,
199,
504,
7065,
14,
2550,
492,
12577,
4858,
547,
12,
24562,
547,
12,
14831,
25212,
199,
504,
7065,
492,
943,
199,
199,
533,
662,
17401,
30926,
334,
21607,
30926,
304,
339,
6365,
63,
466,
275,
283,
5633,
88,
7,
272,
1559,
63,
3435,
275,
3680,
1113,
2,
272,
2955,
63,
773,
63,
3435,
275,
3680,
773,
2,
272,
5709,
63,
773,
63,
3435,
275,
3680,
9259,
2,
272,
2955,
63,
773,
63,
908,
275,
2071,
83,
5,
83,
2,
272,
5709,
63,
773,
63,
908,
275,
2071,
83,
5,
83,
2,
272,
522,
63,
3435,
275,
3680,
470,
2,
420,
327,
10311,
2073,
570,
272,
14778,
63,
3435,
275,
3680,
5803,
2,
339,
347,
636,
826,
363,
334,
277,
12,
2116,
3376,
29,
16,
12,
2116,
9951,
63,
1065,
29,
16,
12,
2116,
3542,
29,
16,
304,
398,
13074,
30926,
855,
826,
363,
334,
277,
12,
3376,
12,
9951,
63,
1065,
12,
3542,
9,
398,
334,
1205,
12,
2436,
9,
275,
1104,
63,
888,
63,
72,
342,
267,
291,
14,
1757,
63,
1361,
480,
4718,
1159,
598,
2571,
2004,
26,
450,
83,
334,
5087,
26,
450,
83,
2924,
450,
586,
334,
1205,
12,
2436,
430,
267,
340,
2004,
365,
440,
15869,
63,
40,
63,
3593,
26,
288,
291,
14,
4050,
8,
355,
298,
4718,
1159,
1134,
888,
14,
72,
3181,
1133,
17021,
370,
2291,
2195,
6365,
14,
221,
298,
435,
355,
1689,
16148,
26,
450,
83,
2122,
450,
2436,
9,
435,
355,
298,
2404,
5662,
1443,
2449,
2952,
402,
10942,
22335,
16954,
2685,
398,
334,
277,
14,
13112,
63,
1023,
12,
291,
14,
1447,
63,
1023,
9,
275,
971,
288,
664,
63,
6234,
342,
267,
291,
14,
1757,
63,
1361,
8,
277,
14,
5772,
63,
466,
435,
7244,
19443,
450,
83,
12,
8827,
450,
83,
60,
78,
2,
450,
586,
334,
277,
14,
13112,
63,
1023,
12,
2079,
291,
14,
1447,
63,
1023,
9,
776,
398,
327,
22825,
13,
600,
598,
2571,
2952,
626,
1159,
4052,
642,
365,
1006,
3595,
14,
267,
327,
5787,
13712,
12,
3598,
5423,
14,
1077,
506,
3537,
14065,
14,
267,
291,
14,
409,
63,
5904,
83,
8,
5772,
534,
13112,
446,
58,
676,
70,
446,
58,
2037,
446,
47,
19,
446,
545,
1147,
13,
1943,
13,
3929,
446,
311,
293,
1235,
446,
18018,
297,
2490,
6365,
63,
1152,
534,
13112,
446,
58,
676,
70,
446,
58,
2037,
446,
47,
19,
446,
545,
1147,
13,
1943,
13,
3929,
446,
311,
293,
1235,
446,
18018,
297,
2490,
17261,
63,
5803,
534,
13112,
446,
58,
676,
70,
446,
58,
2037,
446,
58,
1556,
2076,
914,
297,
2490,
17261,
63,
1152,
534,
13112,
446,
58,
676,
70,
446,
58,
2037,
446,
58,
1556,
2076,
914,
446,
58,
9259,
358,
398,
327,
2934,
314,
19443,
3555,
2955,
1183,
10632,
334,
1152,
626,
781,
2793,
1133,
1172,
267,
327,
370,
11207,
282,
1015,
11410,
641,
314,
6365,
781,
1172,
9,
267,
291,
14,
9259,
63,
10159,
6270,
13112,
937,
339,
327,
636,
826,
363,
6248,
339,
347,
485,
2014,
8,
277,
12,
1559,
12,
2928,
12,
1599,
12,
7429,
63,
589,
12,
2402,
63,
32714,
12,
11618,
63,
3291,
304,
267,
340,
1599,
508,
1987,
1195,
356,
288,
327,
19443,
5074,
1987,
1195,
7,
10311,
370,
3366,
23500,
470,
358,
1584,
221,
21512,
288,
862,
26,
355,
291,
14,
10212,
5234,
1195,
401,
3905,
82,
401,
2928,
566,
288,
871,
12577,
4858,
547,
12,
1499,
26,
355,
746,
24562,
547,
12,
1499,
267,
587,
26,
327,
367,
1163,
1584,
675,
314,
445,
13,
5772,
288,
862,
26,
355,
291,
14,
10212,
8,
277,
14,
5772,
63,
1152,
435,
7429,
63,
589,
435,
359,
2164,
12,
2475,
79,
297,
1559,
61,
435,
2574,
2402,
63,
32714,
9,
288,
871,
12577,
4858,
547,
12,
1499,
26,
355,
746,
24562,
547,
12,
1499,
339,
347,
2142,
334,
277,
12,
1598,
1347,
63,
3257,
12,
1598,
2251,
12,
1598,
1072,
63,
1501,
12,
1598,
1072,
63,
694,
29,
403,
12,
1598,
8363,
29,
403,
12,
1598,
3555,
63,
3220,
29,
403,
12,
1598,
8836,
63,
4342,
63,
3220,
29,
403,
12,
1598,
4843,
63,
7450,
29,
403,
12,
1598,
3105,
29,
16,
12,
1598,
2402,
63,
657,
589,
29,
403,
12,
1598,
2402,
63,
32714,
29,
403,
12,
1598,
1900,
63,
808,
29,
403,
12,
1598,
1347,
63,
4159,
29,
403,
304,
398,
327,
675,
7396,
6866,
12,
880,
781,
883,
2811,
314,
5548,
267,
2402,
63,
657,
589,
275,
1331,
14,
1574,
8,
2911,
63,
657,
589,
503,
3073,
267,
8363,
275,
1331,
14,
1574,
8,
10159,
503,
3073,
267,
2251,
275,
1331,
14,
1574,
8,
1462,
503,
3073,
398,
327,
10961,
8363,
267,
8363,
14,
2880,
8,
277,
14,
9259,
63,
10159,
9,
398,
327,
2429,
4843
] |
[
13350,
14,
5633,
1812,
5772,
199,
199,
17473,
314,
662,
17401,
30926,
1021,
12,
282,
5516,
402,
13074,
30926,
626,
199,
16947,
314,
662,
17401,
1844,
402,
314,
1664,
445,
6365,
370,
4403,
15,
18,
14,
199,
624,
199,
199,
3,
10876,
26,
199,
3,
199,
3,
627,
4403,
15,
18,
315,
338,
10329,
626,
577,
4464,
83,
883,
1172,
1561,
949,
8088,
2419,
1695,
4110,
199,
3,
257,
2136,
5324,
4843,
63,
7450,
315,
282,
347,
13,
493,
12,
465,
10617,
314,
577,
4464,
883,
1172,
199,
3,
257,
376,
9697,
2582,
536,
12,
1325,
14547,
314,
1072,
1788,
14,
199,
3,
199,
3,
627,
1454,
675,
593,
13463,
2251,
436,
675,
19774,
8040,
465,
314,
17261,
5868,
58,
676,
70,
9,
199,
3,
199,
3,
627,
3544,
1900,
367,
3510,
12562,
5868,
58,
2037,
9,
465,
314,
23073,
4403,
15,
18,
1844,
199,
3,
257,
402,
2018,
365,
1454,
1854,
543,
7183,
5223,
14,
199,
3,
199,
3,
12470,
13422,
26,
199,
3,
199,
3,
627,
662,
17401,
19443,
499,
14,
2835,
15,
2769,
56,
378,
14,
25,
68,
5325,
1644,
199,
199,
363,
5792,
363,
275,
7880,
1304,
17351,
199,
199,
646,
747,
12,
1274,
12,
1574,
199,
504,
7065,
14,
67,
5772,
492,
3805,
63,
17677,
63,
1419,
12,
3805,
63,
773,
63,
1419,
199,
504,
7065,
14,
11864,
67,
5772,
492,
13074,
30926,
199,
504,
7065,
14,
493,
63,
1974,
492,
2218,
63,
493,
199,
504,
7065,
14,
2550,
492,
12577,
4858,
547,
12,
24562,
547,
12,
14831,
25212,
199,
504,
7065,
492,
943,
199,
199,
533,
662,
17401,
30926,
334,
21607,
30926,
304,
339,
6365,
63,
466,
275,
283,
5633,
88,
7,
272,
1559,
63,
3435,
275,
3680,
1113,
2,
272,
2955,
63,
773,
63,
3435,
275,
3680,
773,
2,
272,
5709,
63,
773,
63,
3435,
275,
3680,
9259,
2,
272,
2955,
63,
773,
63,
908,
275,
2071,
83,
5,
83,
2,
272,
5709,
63,
773,
63,
908,
275,
2071,
83,
5,
83,
2,
272,
522,
63,
3435,
275,
3680,
470,
2,
420,
327,
10311,
2073,
570,
272,
14778,
63,
3435,
275,
3680,
5803,
2,
339,
347,
636,
826,
363,
334,
277,
12,
2116,
3376,
29,
16,
12,
2116,
9951,
63,
1065,
29,
16,
12,
2116,
3542,
29,
16,
304,
398,
13074,
30926,
855,
826,
363,
334,
277,
12,
3376,
12,
9951,
63,
1065,
12,
3542,
9,
398,
334,
1205,
12,
2436,
9,
275,
1104,
63,
888,
63,
72,
342,
267,
291,
14,
1757,
63,
1361,
480,
4718,
1159,
598,
2571,
2004,
26,
450,
83,
334,
5087,
26,
450,
83,
2924,
450,
586,
334,
1205,
12,
2436,
430,
267,
340,
2004,
365,
440,
15869,
63,
40,
63,
3593,
26,
288,
291,
14,
4050,
8,
355,
298,
4718,
1159,
1134,
888,
14,
72,
3181,
1133,
17021,
370,
2291,
2195,
6365,
14,
221,
298,
435,
355,
1689,
16148,
26,
450,
83,
2122,
450,
2436,
9,
435,
355,
298,
2404,
5662,
1443,
2449,
2952,
402,
10942,
22335,
16954,
2685,
398,
334,
277,
14,
13112,
63,
1023,
12,
291,
14,
1447,
63,
1023,
9,
275,
971,
288,
664,
63,
6234,
342,
267,
291,
14,
1757,
63,
1361,
8,
277,
14,
5772,
63,
466,
435,
7244,
19443,
450,
83,
12,
8827,
450,
83,
60,
78,
2,
450,
586,
334,
277,
14,
13112,
63,
1023,
12,
2079,
291,
14,
1447,
63,
1023,
9,
776,
398,
327,
22825,
13,
600,
598,
2571,
2952,
626,
1159,
4052,
642,
365,
1006,
3595,
14,
267,
327,
5787,
13712,
12,
3598,
5423,
14,
1077,
506,
3537,
14065,
14,
267,
291,
14,
409,
63,
5904,
83,
8,
5772,
534,
13112,
446,
58,
676,
70,
446,
58,
2037,
446,
47,
19,
446,
545,
1147,
13,
1943,
13,
3929,
446,
311,
293,
1235,
446,
18018,
297,
2490,
6365,
63,
1152,
534,
13112,
446,
58,
676,
70,
446,
58,
2037,
446,
47,
19,
446,
545,
1147,
13,
1943,
13,
3929,
446,
311,
293,
1235,
446,
18018,
297,
2490,
17261,
63,
5803,
534,
13112,
446,
58,
676,
70,
446,
58,
2037,
446,
58,
1556,
2076,
914,
297,
2490,
17261,
63,
1152,
534,
13112,
446,
58,
676,
70,
446,
58,
2037,
446,
58,
1556,
2076,
914,
446,
58,
9259,
358,
398,
327,
2934,
314,
19443,
3555,
2955,
1183,
10632,
334,
1152,
626,
781,
2793,
1133,
1172,
267,
327,
370,
11207,
282,
1015,
11410,
641,
314,
6365,
781,
1172,
9,
267,
291,
14,
9259,
63,
10159,
6270,
13112,
937,
339,
327,
636,
826,
363,
6248,
339,
347,
485,
2014,
8,
277,
12,
1559,
12,
2928,
12,
1599,
12,
7429,
63,
589,
12,
2402,
63,
32714,
12,
11618,
63,
3291,
304,
267,
340,
1599,
508,
1987,
1195,
356,
288,
327,
19443,
5074,
1987,
1195,
7,
10311,
370,
3366,
23500,
470,
358,
1584,
221,
21512,
288,
862,
26,
355,
291,
14,
10212,
5234,
1195,
401,
3905,
82,
401,
2928,
566,
288,
871,
12577,
4858,
547,
12,
1499,
26,
355,
746,
24562,
547,
12,
1499,
267,
587,
26,
327,
367,
1163,
1584,
675,
314,
445,
13,
5772,
288,
862,
26,
355,
291,
14,
10212,
8,
277,
14,
5772,
63,
1152,
435,
7429,
63,
589,
435,
359,
2164,
12,
2475,
79,
297,
1559,
61,
435,
2574,
2402,
63,
32714,
9,
288,
871,
12577,
4858,
547,
12,
1499,
26,
355,
746,
24562,
547,
12,
1499,
339,
347,
2142,
334,
277,
12,
1598,
1347,
63,
3257,
12,
1598,
2251,
12,
1598,
1072,
63,
1501,
12,
1598,
1072,
63,
694,
29,
403,
12,
1598,
8363,
29,
403,
12,
1598,
3555,
63,
3220,
29,
403,
12,
1598,
8836,
63,
4342,
63,
3220,
29,
403,
12,
1598,
4843,
63,
7450,
29,
403,
12,
1598,
3105,
29,
16,
12,
1598,
2402,
63,
657,
589,
29,
403,
12,
1598,
2402,
63,
32714,
29,
403,
12,
1598,
1900,
63,
808,
29,
403,
12,
1598,
1347,
63,
4159,
29,
403,
304,
398,
327,
675,
7396,
6866,
12,
880,
781,
883,
2811,
314,
5548,
267,
2402,
63,
657,
589,
275,
1331,
14,
1574,
8,
2911,
63,
657,
589,
503,
3073,
267,
8363,
275,
1331,
14,
1574,
8,
10159,
503,
3073,
267,
2251,
275,
1331,
14,
1574,
8,
1462,
503,
3073,
398,
327,
10961,
8363,
267,
8363,
14,
2880,
8,
277,
14,
9259,
63,
10159,
9,
398,
327,
2429,
4843,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
fdvarela/odoo8
|
addons/mrp_operations/__init__.py
|
443
|
1091
|
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import mrp_operations
import report
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
agpl-3.0
|
[
3,
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
646,
333,
4599,
63,
8170,
199,
646,
3622,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768
] |
[
1882,
2803,
26,
2774,
13,
24,
1882,
199,
4605,
199,
3,
258,
199,
3,
259,
7653,
12,
3232,
5800,
8259,
9274,
199,
3,
259,
1898,
334,
35,
9,
8353,
13,
6542,
11947,
12361,
8642,
1014,
921,
9864,
14,
1235,
10121,
199,
3,
199,
3,
259,
961,
2240,
365,
2867,
2032,
26,
1265,
883,
3604,
652,
436,
15,
269,
2811,
199,
3,
259,
652,
1334,
314,
2895,
402,
314,
1664,
4265,
1696,
1684,
844,
465,
199,
3,
259,
3267,
701,
314,
2868,
2290,
2752,
12,
1902,
1015,
650,
402,
314,
199,
3,
259,
844,
12,
503,
334,
292,
2195,
945,
9,
1263,
2945,
1015,
14,
199,
3,
199,
3,
259,
961,
2240,
365,
1854,
315,
314,
3661,
626,
652,
911,
506,
2997,
12,
199,
3,
259,
1325,
2428,
1821,
3408,
27,
1928,
2755,
314,
2478,
3750,
402,
199,
3,
259,
3169,
503,
3092,
2381,
437,
3115,
3104,
14,
221,
1666,
314,
199,
3,
259,
1664,
4265,
1696,
1684,
844,
367,
1655,
2436,
14,
199,
3,
199,
3,
259,
2047,
1077,
1172,
3086,
282,
1331,
402,
314,
1664,
4265,
1696,
1684,
844,
199,
3,
259,
3180,
543,
642,
2240,
14,
221,
982,
440,
12,
1937,
665,
1014,
921,
1544,
14,
3689,
14,
1308,
15,
2383,
4743,
420,
199,
3,
199,
4605,
199,
199,
646,
333,
4599,
63,
8170,
199,
646,
3622,
199,
3,
6695,
26,
10379,
26,
10558,
26,
6492,
29,
20,
26,
10503,
29,
20,
26,
10425,
29,
20,
26,
421,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
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
] |
dnephin/pre-commit
|
pre_commit/clientlib/validate_config.py
|
4
|
2492
|
from __future__ import unicode_literals
from pre_commit.clientlib.validate_base import get_run_function
from pre_commit.clientlib.validate_base import get_validator
from pre_commit.clientlib.validate_base import is_regex_valid
from pre_commit.errors import FatalError
_LOCAL_HOOKS_MAGIC_REPO_STRING = 'local'
def is_local_hooks(repo_entry):
return repo_entry['repo'] == _LOCAL_HOOKS_MAGIC_REPO_STRING
class InvalidConfigError(FatalError):
pass
CONFIG_JSON_SCHEMA = {
'type': 'array',
'minItems': 1,
'items': {
'type': 'object',
'properties': {
'repo': {'type': 'string'},
'sha': {'type': 'string'},
'hooks': {
'type': 'array',
'minItems': 1,
'items': {
'type': 'object',
'properties': {
'id': {'type': 'string'},
'files': {'type': 'string'},
'exclude': {'type': 'string'},
'language_version': {'type': 'string'},
'args': {
'type': 'array',
'items': {'type': 'string'},
},
},
'required': ['id'],
}
}
},
'required': ['repo', 'hooks'],
}
}
def try_regex(repo, hook, value, field_name):
if not is_regex_valid(value):
raise InvalidConfigError(
'Invalid {0} regex at {1}, {2}: {3}'.format(
field_name, repo, hook, value,
)
)
def validate_config_extra(config):
for repo in config:
if is_local_hooks(repo):
if 'sha' in repo:
raise InvalidConfigError(
'"sha" property provided for local hooks'
)
elif 'sha' not in repo:
raise InvalidConfigError(
'Missing "sha" field for repository {0}'.format(repo['repo'])
)
for hook in repo['hooks']:
try_regex(repo, hook['id'], hook.get('files', ''), 'files')
try_regex(repo, hook['id'], hook.get('exclude', ''), 'exclude')
load_config = get_validator(
CONFIG_JSON_SCHEMA,
InvalidConfigError,
additional_validation_strategy=validate_config_extra,
)
run = get_run_function('Config filenames.', load_config, InvalidConfigError)
if __name__ == '__main__':
exit(run())
|
mit
|
[
504,
636,
2443,
363,
492,
2649,
63,
5955,
199,
199,
504,
876,
63,
3543,
14,
1258,
773,
14,
3502,
63,
1095,
492,
664,
63,
1065,
63,
1593,
199,
504,
876,
63,
3543,
14,
1258,
773,
14,
3502,
63,
1095,
492,
664,
63,
11034,
199,
504,
876,
63,
3543,
14,
1258,
773,
14,
3502,
63,
1095,
492,
365,
63,
3821,
63,
1078,
199,
504,
876,
63,
3543,
14,
2550,
492,
481,
7539,
547,
421,
199,
63,
7486,
63,
28706,
51,
63,
19973,
63,
20424,
63,
5353,
275,
283,
1832,
7,
421,
199,
318,
365,
63,
1832,
63,
7922,
8,
3417,
63,
2373,
304,
272,
372,
3831,
63,
2373,
459,
3417,
418,
508,
485,
7486,
63,
28706,
51,
63,
19973,
63,
20424,
63,
5353,
421,
199,
533,
6378,
2028,
547,
8,
19507,
547,
304,
272,
986,
421,
199,
5569,
63,
6243,
63,
10926,
275,
469,
272,
283,
466,
356,
283,
1144,
297,
272,
283,
827,
7412,
356,
413,
12,
272,
283,
1744,
356,
469,
267,
283,
466,
356,
283,
785,
297,
267,
283,
3282,
356,
469,
288,
283,
3417,
356,
791,
466,
356,
283,
875,
2267,
288,
283,
4835,
356,
791,
466,
356,
283,
875,
2267,
288,
283,
7922,
356,
469,
355,
283,
466,
356,
283,
1144,
297,
355,
283,
827,
7412,
356,
413,
12,
355,
283,
1744,
356,
469,
490,
283,
466,
356,
283,
785,
297,
490,
283,
3282,
356,
469,
717,
283,
344,
356,
791,
466,
356,
283,
875,
2267,
717,
283,
1725,
356,
791,
466,
356,
283,
875,
2267,
717,
283,
5473,
356,
791,
466,
356,
283,
875,
2267,
717,
283,
3671,
63,
1023,
356,
791,
466,
356,
283,
875,
2267,
717,
283,
589,
356,
469,
1169,
283,
466,
356,
283,
1144,
297,
1169,
283,
1744,
356,
791,
466,
356,
283,
875,
2267,
717,
1660,
490,
1660,
490,
283,
2427,
356,
788,
344,
995,
355,
789,
288,
789,
267,
1660,
267,
283,
2427,
356,
788,
3417,
297,
283,
7922,
995,
272,
789,
199,
93,
421,
199,
318,
862,
63,
3821,
8,
3417,
12,
5759,
12,
574,
12,
901,
63,
354,
304,
272,
340,
440,
365,
63,
3821,
63,
1078,
8,
585,
304,
267,
746,
6378,
2028,
547,
8,
288,
283,
3364,
469,
16,
93,
5163,
737,
469,
17,
1386,
469,
18,
9160,
469,
19,
5285,
908,
8,
355,
901,
63,
354,
12,
3831,
12,
5759,
12,
574,
12,
288,
776,
267,
776,
421,
199,
318,
4107,
63,
888,
63,
2911,
8,
888,
304,
272,
367,
3831,
315,
1101,
26,
267,
340,
365,
63,
1832,
63,
7922,
8,
3417,
304,
288,
340,
283,
4835,
7,
315,
3831,
26,
355,
746,
6378,
2028,
547,
8,
490,
5522,
4835,
2,
3324,
2741,
367,
2257,
12604,
7,
355,
776,
267,
916,
283,
4835,
7,
440,
315,
3831,
26,
288,
746,
6378,
2028,
547,
8,
355,
283,
7718,
298,
4835,
2,
901,
367,
7611,
469,
16,
5285,
908,
8,
3417,
459,
3417,
1105,
288,
776,
267,
367,
5759,
315,
3831,
459,
7922,
2565,
288,
862,
63,
3821,
8,
3417,
12,
5759,
459,
344,
995,
5759,
14,
362,
360,
1725,
297,
9929,
283,
1725,
358,
288,
862,
63,
3821,
8,
3417,
12,
5759,
459,
344,
995,
5759,
14,
362,
360,
5473,
297,
9929,
283,
5473,
358,
421,
199,
912,
63,
888,
275,
664,
63,
11034,
8,
272,
15869,
63,
6243,
63,
10926,
12,
272,
6378,
2028,
547,
12,
272,
4722,
63,
6136,
63,
8590,
29,
3502,
63,
888,
63,
2911,
12,
199,
9,
421,
199,
1065,
275,
664,
63,
1065,
63,
1593,
360,
2028,
6203,
3130,
2248,
63,
888,
12,
6378,
2028,
547,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
4458,
8,
1065,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
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,
876,
63,
3543,
14,
1258,
773,
14,
3502,
63,
1095,
492,
664,
63,
1065,
63,
1593,
199,
504,
876,
63,
3543,
14,
1258,
773,
14,
3502,
63,
1095,
492,
664,
63,
11034,
199,
504,
876,
63,
3543,
14,
1258,
773,
14,
3502,
63,
1095,
492,
365,
63,
3821,
63,
1078,
199,
504,
876,
63,
3543,
14,
2550,
492,
481,
7539,
547,
421,
199,
63,
7486,
63,
28706,
51,
63,
19973,
63,
20424,
63,
5353,
275,
283,
1832,
7,
421,
199,
318,
365,
63,
1832,
63,
7922,
8,
3417,
63,
2373,
304,
272,
372,
3831,
63,
2373,
459,
3417,
418,
508,
485,
7486,
63,
28706,
51,
63,
19973,
63,
20424,
63,
5353,
421,
199,
533,
6378,
2028,
547,
8,
19507,
547,
304,
272,
986,
421,
199,
5569,
63,
6243,
63,
10926,
275,
469,
272,
283,
466,
356,
283,
1144,
297,
272,
283,
827,
7412,
356,
413,
12,
272,
283,
1744,
356,
469,
267,
283,
466,
356,
283,
785,
297,
267,
283,
3282,
356,
469,
288,
283,
3417,
356,
791,
466,
356,
283,
875,
2267,
288,
283,
4835,
356,
791,
466,
356,
283,
875,
2267,
288,
283,
7922,
356,
469,
355,
283,
466,
356,
283,
1144,
297,
355,
283,
827,
7412,
356,
413,
12,
355,
283,
1744,
356,
469,
490,
283,
466,
356,
283,
785,
297,
490,
283,
3282,
356,
469,
717,
283,
344,
356,
791,
466,
356,
283,
875,
2267,
717,
283,
1725,
356,
791,
466,
356,
283,
875,
2267,
717,
283,
5473,
356,
791,
466,
356,
283,
875,
2267,
717,
283,
3671,
63,
1023,
356,
791,
466,
356,
283,
875,
2267,
717,
283,
589,
356,
469,
1169,
283,
466,
356,
283,
1144,
297,
1169,
283,
1744,
356,
791,
466,
356,
283,
875,
2267,
717,
1660,
490,
1660,
490,
283,
2427,
356,
788,
344,
995,
355,
789,
288,
789,
267,
1660,
267,
283,
2427,
356,
788,
3417,
297,
283,
7922,
995,
272,
789,
199,
93,
421,
199,
318,
862,
63,
3821,
8,
3417,
12,
5759,
12,
574,
12,
901,
63,
354,
304,
272,
340,
440,
365,
63,
3821,
63,
1078,
8,
585,
304,
267,
746,
6378,
2028,
547,
8,
288,
283,
3364,
469,
16,
93,
5163,
737,
469,
17,
1386,
469,
18,
9160,
469,
19,
5285,
908,
8,
355,
901,
63,
354,
12,
3831,
12,
5759,
12,
574,
12,
288,
776,
267,
776,
421,
199,
318,
4107,
63,
888,
63,
2911,
8,
888,
304,
272,
367,
3831,
315,
1101,
26,
267,
340,
365,
63,
1832,
63,
7922,
8,
3417,
304,
288,
340,
283,
4835,
7,
315,
3831,
26,
355,
746,
6378,
2028,
547,
8,
490,
5522,
4835,
2,
3324,
2741,
367,
2257,
12604,
7,
355,
776,
267,
916,
283,
4835,
7,
440,
315,
3831,
26,
288,
746,
6378,
2028,
547,
8,
355,
283,
7718,
298,
4835,
2,
901,
367,
7611,
469,
16,
5285,
908,
8,
3417,
459,
3417,
1105,
288,
776,
267,
367,
5759,
315,
3831,
459,
7922,
2565,
288,
862,
63,
3821,
8,
3417,
12,
5759,
459,
344,
995,
5759,
14,
362,
360,
1725,
297,
9929,
283,
1725,
358,
288,
862,
63,
3821,
8,
3417,
12,
5759,
459,
344,
995,
5759,
14,
362,
360,
5473,
297,
9929,
283,
5473,
358,
421,
199,
912,
63,
888,
275,
664,
63,
11034,
8,
272,
15869,
63,
6243,
63,
10926,
12,
272,
6378,
2028,
547,
12,
272,
4722,
63,
6136,
63,
8590,
29,
3502,
63,
888,
63,
2911,
12,
199,
9,
421,
199,
1065,
275,
664,
63,
1065,
63,
1593,
360,
2028,
6203,
3130,
2248,
63,
888,
12,
6378,
2028,
547,
9,
421,
199,
692,
636,
354,
363,
508,
2560,
973,
3706,
272,
4458,
8,
1065,
1012,
199,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
32768,
0
] |
[
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,
1,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